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,17 +123,28 @@ 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")
}
if projVars.ConnectedToTarget == true {
var targetServices []bluetooth.DeviceService
time.Sleep(20 * time.Millisecond)
//time.Sleep(20 * time.Millisecond)
targetServices, _ = TargetDevice.DiscoverServices(nil)
targetServices, err = TargetDevice.DiscoverServices(nil)
if err != nil {
log.Debug().Err(err).Msg("DISCOVER_SERVICE_ERROR")
}
buf := make([]byte, 255)
@ -167,6 +180,8 @@ func (s *Scan) Start() error {
TargetDevice.Disconnect()
//projVars.ScanAdapter.Enable()
projVars.ConnectedToTarget = false
}
}
//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..