char enumeration is working

This commit is contained in:
freqyXin 2021-05-12 13:27:30 -07:00
parent 67553f5ba1
commit 548d5d3d73
3 changed files with 75 additions and 29 deletions

@ -1,5 +1,7 @@
package blueStuff
import "tinygo.org/x/bluetooth"
//controls connections to found devices to get service characteristics
//TODO: disable the scan adapter, enable the attack adapter (this step pmight not be needed)
@ -7,14 +9,12 @@ package blueStuff
// once connected, for list of service characteristics and check for read / write for each
// loog all of this to eros
/*
func pathways(target) {
func pathways(target bluetooth.ScanResult) {
println("Discovery")
device, err := projVars.ScanAdapter.Connect(bluetooth.ScanResult.Address, bluetooth.ConnectionParams{})
//device, err := projVars.ScanAdapter.Connect(bluetooth.ScanResult.Address, bluetooth.ConnectionParams{})
//srvcs, err := projVars.ScanAdapter.
}
*/

@ -10,15 +10,27 @@ package eros
import (
"encoding/json"
"time"
//"errors"
"github.com/prologic/bitcask"
)
type Permissions struct {
Read string
Write string
}
type Characteristic struct {
Name string
UUID string
Permissions []Permissions
}
// Device will hold details about the discoverd device
type Device struct {
Name string
MAC string
RSSInow int16
Name string
MAC string
RSSInow int16
RSSIhist map[time.Time]int16
// Services - see Service struct
@ -34,6 +46,8 @@ type Service struct {
Name string
UUID string
Category string
Characteristic []Characteristic
}
// deviceDb will hold details about devices discovered

@ -4,11 +4,13 @@ import (
"protomolecule/src/dust"
"protomolecule/src/eros"
projVars "protomolecule/src/vars"
"strconv"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"time"
"tinygo.org/x/bluetooth"
)
@ -18,10 +20,10 @@ type Meta struct {
}
type Scan struct {
ID int
Started time.Time
ID int
Started time.Time
Activity time.Time
Devices []eros.Device
Devices []eros.Device
}
func (mgr *Meta) NewScan() int {
@ -30,11 +32,11 @@ func (mgr *Meta) NewScan() int {
if mgr.Count <= 0 {
newid = 0
} else {
newid = mgr.Count+1
newid = mgr.Count + 1
}
mgr.Scans[newid] = &Scan{
ID: newid,
ID: newid,
Started: time.Now(),
}
@ -77,7 +79,7 @@ func (s *Scan) Start() error {
var sublog zerolog.Logger
sublog = log.With().Int("Scan_ID", s.ID).Str("LocalName", lname).Str("MAC", addr).
Int16("RSSI", rssi).Logger()
Int16("RSSI", rssi).Logger()
// Skipping duplicate results
if lname == projVars.ScanList[result.Address.String()] {
@ -88,9 +90,9 @@ func (s *Scan) Start() error {
s.Activity = time.Now()
// Initialize a Device struct to hold the incoming data for future serialization
dev := &eros.Device {
Name: lname,
MAC: addr,
dev := &eros.Device{
Name: lname,
MAC: addr,
RSSInow: rssi,
}
@ -106,6 +108,48 @@ func (s *Scan) Start() error {
sublog.Debug().Str("UUID", svc.UUID).Msg("SERVICE_DISCOVERED")
}
////////////////////////////////////////////////////////////////////////
//var PreTargetHandling type
// var TargetDeviceService *bluetooth.DeviceService
// var TargetDeviceServiceChar *bluetooth.DeviceCharacteristic
//Attempt to connect -- This should be put in bluestuff once its working
time.Sleep(10 * time.Second)
projVars.ScanAdapter.SetConnectHandler(func(result bluetooth.Addresser, connected bool) {
})
TargetDevice, _ := projVars.ScanAdapter.Connect(result.Address, bluetooth.ConnectionParams{})
var targetServices []bluetooth.DeviceService
targetServices, _ = TargetDevice.DiscoverServices(nil)
buf := make([]byte, 255)
for _, srvcs := range targetServices {
charSer := eros.Service{
UUID: srvcs.String(),
}
chars, _ := srvcs.DiscoverCharacteristics(nil)
dev.Services = append(dev.Services, charSer)
for _, char := range chars {
//dev.Services = append(dev.Services, )
println(char.UUID().String())
ReadPos, _ := char.Read(buf)
println("data bytes", strconv.Itoa(ReadPos))
println("vale = ", string(buf[:ReadPos]))
}
sublog.Debug().Str("Connected and enumerated", charSer.UUID).Msg("Yay!")
}
// Append our defined device to the list of devices in the Scan struct
s.Devices = append(s.Devices, *dev)
@ -113,7 +157,6 @@ func (s *Scan) Start() error {
sublog.Debug().Msg("Storing data with Eros")
eros.Remember(*dev)
// simple eros test
fromEros, err := eros.Recall(addr)
if err != nil {
@ -121,28 +164,17 @@ func (s *Scan) Start() error {
}
log.Info().Interface("Device", fromEros).Msg("EROS_RECALL")
//TODO: normalize this with the newly created ScanMgr
//TODO: create localname fort devices that dont broadcast one * dust.OhNameMeZaddy() *
projVars.ScanList[result.Address.String()] = result.LocalName()
////////////////////////////////////////////////////////////////////////
//Attempt to connect -- This should be put in bluestuff once its working
/*
scanAdapter.SetConnectHandler(func(result bluetooth.Addresser, connected bool) {
scanAdapter.Connect(result, bluetooth.ConnectionParams{})
})
*/
//projVars.ScanAdapter.Connect(result.Address, bluetooth.ConnectionParams{})
//projVars.InitResults = append( projVars.ScanList[result.Address.String()], 1)
//TODO: stop scan and call bluestuff func and pass it the local name value ***********
//scanAdapter.Scan()
})
//projVars.C <- result