mirror of
https://github.com/bettercap/bettercap
synced 2025-08-20 05:23:19 -07:00
misc: small fix or general refactoring i did not bother commenting
This commit is contained in:
parent
d62090267e
commit
7f68d0d82c
4 changed files with 19 additions and 19 deletions
|
@ -8,19 +8,19 @@ import (
|
|||
)
|
||||
|
||||
func (mod *BLERecon) onStateChanged(dev gatt.Device, s gatt.State) {
|
||||
mod.Info("BLE state changed to %v", s)
|
||||
mod.Info("state changed to %v", s)
|
||||
|
||||
switch s {
|
||||
case gatt.StatePoweredOn:
|
||||
if mod.currDevice == nil {
|
||||
mod.Info("Starting BLE discovery ...")
|
||||
mod.Info("starting discovery ...")
|
||||
dev.Scan([]gatt.UUID{}, true)
|
||||
}
|
||||
case gatt.StatePoweredOff:
|
||||
mod.gattDevice = nil
|
||||
|
||||
default:
|
||||
mod.Warning("Unexpected BLE state: %v", s)
|
||||
mod.Warning("unexpected state: %v", s)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ func (mod *BLERecon) onPeriphDiscovered(p gatt.Peripheral, a *gatt.Advertisement
|
|||
func (mod *BLERecon) onPeriphDisconnected(p gatt.Peripheral, err error) {
|
||||
if mod.Running() {
|
||||
// restore scanning
|
||||
mod.Info("Device disconnected, restoring BLE discovery.")
|
||||
mod.Info("device disconnected, restoring discovery.")
|
||||
mod.setCurrentDevice(nil)
|
||||
mod.gattDevice.Scan([]gatt.UUID{}, true)
|
||||
}
|
||||
|
@ -39,31 +39,31 @@ func (mod *BLERecon) onPeriphDisconnected(p gatt.Peripheral, err error) {
|
|||
|
||||
func (mod *BLERecon) onPeriphConnected(p gatt.Peripheral, err error) {
|
||||
if err != nil {
|
||||
mod.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 mod.currDevice == nil {
|
||||
// timed out
|
||||
mod.Warning("Connected to %s but after the timeout :(", p.ID())
|
||||
mod.Warning("connected to %s but after the timeout :(", p.ID())
|
||||
return
|
||||
}
|
||||
|
||||
mod.connected = true
|
||||
|
||||
defer func(per gatt.Peripheral) {
|
||||
mod.Info("Disconnecting from %s ...", per.ID())
|
||||
mod.Info("disconnecting from %s ...", per.ID())
|
||||
per.Device().CancelConnection(per)
|
||||
}(p)
|
||||
|
||||
mod.Session.Events.Add("ble.device.connected", mod.currDevice)
|
||||
|
||||
if err := p.SetMTU(500); err != nil {
|
||||
mod.Warning("Failed to set MTU: %s", err)
|
||||
mod.Warning("failed to set MTU: %s", err)
|
||||
}
|
||||
|
||||
mod.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 {
|
||||
mod.Error("Error discovering services: %s", err)
|
||||
mod.Error("error discovering services: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue