misc: small fix or general refactoring i did not bother commenting

This commit is contained in:
evilsocket 2019-02-13 10:12:34 +01:00
commit 4eead7eafa
No known key found for this signature in database
GPG key ID: 1564D7F30393A456
58 changed files with 2052 additions and 2052 deletions

View file

@ -7,65 +7,65 @@ import (
"github.com/bettercap/gatt"
)
func (d *BLERecon) onStateChanged(dev gatt.Device, s gatt.State) {
d.Info("BLE state changed to %v", s)
func (mod *BLERecon) onStateChanged(dev gatt.Device, s gatt.State) {
mod.Info("BLE state changed to %v", s)
switch s {
case gatt.StatePoweredOn:
if d.currDevice == nil {
d.Info("Starting BLE discovery ...")
if mod.currDevice == nil {
mod.Info("Starting BLE discovery ...")
dev.Scan([]gatt.UUID{}, true)
}
case gatt.StatePoweredOff:
d.gattDevice = nil
mod.gattDevice = nil
default:
d.Warning("Unexpected BLE state: %v", s)
mod.Warning("Unexpected BLE state: %v", s)
}
}
func (d *BLERecon) onPeriphDiscovered(p gatt.Peripheral, a *gatt.Advertisement, rssi int) {
d.Session.BLE.AddIfNew(p.ID(), p, a, rssi)
func (mod *BLERecon) onPeriphDiscovered(p gatt.Peripheral, a *gatt.Advertisement, rssi int) {
mod.Session.BLE.AddIfNew(p.ID(), p, a, rssi)
}
func (d *BLERecon) onPeriphDisconnected(p gatt.Peripheral, err error) {
if d.Running() {
func (mod *BLERecon) onPeriphDisconnected(p gatt.Peripheral, err error) {
if mod.Running() {
// restore scanning
d.Info("Device disconnected, restoring BLE discovery.")
d.setCurrentDevice(nil)
d.gattDevice.Scan([]gatt.UUID{}, true)
mod.Info("Device disconnected, restoring BLE discovery.")
mod.setCurrentDevice(nil)
mod.gattDevice.Scan([]gatt.UUID{}, true)
}
}
func (d *BLERecon) onPeriphConnected(p gatt.Peripheral, err error) {
func (mod *BLERecon) onPeriphConnected(p gatt.Peripheral, err error) {
if err != nil {
d.Warning("Connected to %s but with error: %s", p.ID(), err)
mod.Warning("Connected to %s but with error: %s", p.ID(), err)
return
} else if d.currDevice == nil {
} else if mod.currDevice == nil {
// timed out
d.Warning("Connected to %s but after the timeout :(", p.ID())
mod.Warning("Connected to %s but after the timeout :(", p.ID())
return
}
d.connected = true
mod.connected = true
defer func(per gatt.Peripheral) {
d.Info("Disconnecting from %s ...", per.ID())
mod.Info("Disconnecting from %s ...", per.ID())
per.Device().CancelConnection(per)
}(p)
d.Session.Events.Add("ble.device.connected", d.currDevice)
mod.Session.Events.Add("ble.device.connected", mod.currDevice)
if err := p.SetMTU(500); err != nil {
d.Warning("Failed to set MTU: %s", err)
mod.Warning("Failed to set MTU: %s", err)
}
d.Info("Connected, enumerating all the things for %s!", p.ID())
mod.Info("Connected, enumerating all the things for %s!", p.ID())
services, err := p.DiscoverServices(nil)
if err != nil {
d.Error("Error discovering services: %s", err)
mod.Error("Error discovering services: %s", err)
return
}
d.showServices(p, services)
mod.showServices(p, services)
}