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:
parent
6461cbb62e
commit
006ffaa9b8
@ -82,9 +82,11 @@ func (s *Scan) Start() error {
|
|||||||
sublog = log.With().Int("Scan_ID", s.ID).Str("LocalName", lname).Str("MAC", addr).
|
sublog = log.With().Int("Scan_ID", s.ID).Str("LocalName", lname).Str("MAC", addr).
|
||||||
Int16("RSSI", rssi).Logger()
|
Int16("RSSI", rssi).Logger()
|
||||||
|
|
||||||
|
//could add -t option to enable this feature for active tracking
|
||||||
// Skipping duplicate results
|
// Skipping duplicate results
|
||||||
if lname == projVars.ScanList[result.Address.String()] {
|
if lname == projVars.ScanList[result.Address.String()] {
|
||||||
return
|
return
|
||||||
|
//TODO flag for active tracking
|
||||||
}
|
}
|
||||||
|
|
||||||
// Upon finding new and valid info we update the time for last activity
|
// 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")
|
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
|
//var PreTargetHandling type
|
||||||
|
|
||||||
@ -121,52 +123,65 @@ func (s *Scan) Start() error {
|
|||||||
|
|
||||||
projVars.ScanAdapter.SetConnectHandler(func(result bluetooth.Addresser, connected bool) {
|
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)
|
targetServices, err = TargetDevice.DiscoverServices(nil)
|
||||||
|
if err != nil {
|
||||||
buf := make([]byte, 255)
|
log.Debug().Err(err).Msg("DISCOVER_SERVICE_ERROR")
|
||||||
|
|
||||||
for _, srvcs := range targetServices {
|
|
||||||
charSer := eros.Service{
|
|
||||||
UUID: srvcs.String(),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//time.Sleep(1 * time.Second)
|
buf := make([]byte, 255)
|
||||||
|
|
||||||
chars, _ := srvcs.DiscoverCharacteristics(nil)
|
for _, srvcs := range targetServices {
|
||||||
|
charSer := eros.Service{
|
||||||
dev.Services = append(dev.Services, charSer)
|
UUID: srvcs.String(),
|
||||||
for _, char := range chars {
|
}
|
||||||
|
|
||||||
//dev.Services = append(dev.Services)
|
|
||||||
|
|
||||||
//time.Sleep(1 * time.Second)
|
//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()).
|
//dev.Services = append(dev.Services)
|
||||||
Int("Bytes", ReadPos).Str("Value", string(buf[:ReadPos])).Msg("NEW_CHARACTERISTIC")
|
|
||||||
|
|
||||||
//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)
|
//time.Sleep(5 * time.Second)
|
||||||
|
|
||||||
|
@ -19,6 +19,8 @@ var AdapterInUse = *&bluetooth.Adapter{}
|
|||||||
|
|
||||||
var AttackMode bool = false
|
var AttackMode bool = false
|
||||||
|
|
||||||
|
var ConnectedToTarget bool = false
|
||||||
|
|
||||||
//var SrvcUUIDList map[uint32]string
|
//var SrvcUUIDList map[uint32]string
|
||||||
|
|
||||||
//hold the values for the initial ble scan results..
|
//hold the values for the initial ble scan results..
|
||||||
|
Loading…
Reference in New Issue
Block a user