added bool and if logic to conrtol connections -- errors do not cause crashes now -- some connections still cause a hang

This commit is contained in:
freqyXin 2021-05-13 11:30:49 -07:00
parent 6461cbb62e
commit 006ffaa9b8
2 changed files with 45 additions and 28 deletions

@ -82,9 +82,11 @@ func (s *Scan) Start() error {
sublog = log.With().Int("Scan_ID", s.ID).Str("LocalName", lname).Str("MAC", addr).
Int16("RSSI", rssi).Logger()
//could add -t option to enable this feature for active tracking
// Skipping duplicate results
if lname == projVars.ScanList[result.Address.String()] {
return
//TODO flag for active tracking
}
// Upon finding new and valid info we update the time for last activity
@ -109,7 +111,7 @@ func (s *Scan) Start() error {
sublog.Debug().Str("UUID", svc.UUID).Msg("SERVICE_DISCOVERED")
}
if projVars.AttackMode == true {
if projVars.AttackMode == true /*changed to false for debug*/ {
////////////////////////////////////////////////////////////////////////
//var PreTargetHandling type
@ -121,52 +123,65 @@ func (s *Scan) Start() error {
projVars.ScanAdapter.SetConnectHandler(func(result bluetooth.Addresser, connected bool) {
connected = projVars.ConnectedToTarget
projVars.ConnectedToTarget = true
})
time.Sleep(20 * time.Millisecond)
//time.Sleep(20 * time.Millisecond)
TargetDevice, _ := projVars.ScanAdapter.Connect(result.Address, bluetooth.ConnectionParams{})
TargetDevice, err := projVars.ScanAdapter.Connect(result.Address, bluetooth.ConnectionParams{})
if err != nil {
log.Err(err).Msg("CONNECTION_ERROR")
}
var targetServices []bluetooth.DeviceService
if projVars.ConnectedToTarget == true {
var targetServices []bluetooth.DeviceService
time.Sleep(20 * time.Millisecond)
//time.Sleep(20 * time.Millisecond)
targetServices, _ = TargetDevice.DiscoverServices(nil)
buf := make([]byte, 255)
for _, srvcs := range targetServices {
charSer := eros.Service{
UUID: srvcs.String(),
targetServices, err = TargetDevice.DiscoverServices(nil)
if err != nil {
log.Debug().Err(err).Msg("DISCOVER_SERVICE_ERROR")
}
//time.Sleep(1 * time.Second)
buf := make([]byte, 255)
chars, _ := srvcs.DiscoverCharacteristics(nil)
dev.Services = append(dev.Services, charSer)
for _, char := range chars {
//dev.Services = append(dev.Services)
for _, srvcs := range targetServices {
charSer := eros.Service{
UUID: srvcs.String(),
}
//time.Sleep(1 * time.Second)
//if char.
chars, _ := srvcs.DiscoverCharacteristics(nil)
ReadPos, _ := char.Read(buf)
dev.Services = append(dev.Services, charSer)
for _, char := range chars {
sublog.Info().Str("UUID", char.UUID().String()).
Int("Bytes", ReadPos).Str("Value", string(buf[:ReadPos])).Msg("NEW_CHARACTERISTIC")
//dev.Services = append(dev.Services)
//println("Rawvalue = ", buf[i])
//time.Sleep(1 * time.Second)
//if char.
ReadPos, _ := char.Read(buf)
sublog.Info().Str("UUID", char.UUID().String()).
Int("Bytes", ReadPos).Str("Value", string(buf[:ReadPos])).Msg("NEW_CHARACTERISTIC")
//println("Rawvalue = ", buf[i])
}
sublog.Debug().Str("Connected and enumerated", charSer.UUID).Msg("CONNECTION_SUCCESSFUL")
}
sublog.Debug().Str("Connected and enumerated", charSer.UUID).Msg("CONNECTION_SUCCESSFUL")
TargetDevice.Disconnect()
//projVars.ScanAdapter.Enable()
projVars.ConnectedToTarget = false
}
TargetDevice.Disconnect()
//projVars.ScanAdapter.Enable()
}
//time.Sleep(5 * time.Second)

@ -19,6 +19,8 @@ var AdapterInUse = *&bluetooth.Adapter{}
var AttackMode bool = false
var ConnectedToTarget bool = false
//var SrvcUUIDList map[uint32]string
//hold the values for the initial ble scan results..