mirror of
https://github.com/bettercap/bettercap
synced 2025-08-20 21:43:18 -07:00
misc: each module now has its own tagged logging
This commit is contained in:
parent
9003be56ca
commit
9cd4e380fb
47 changed files with 343 additions and 349 deletions
|
@ -10,7 +10,6 @@ import (
|
|||
golog "log"
|
||||
"time"
|
||||
|
||||
"github.com/bettercap/bettercap/log"
|
||||
"github.com/bettercap/bettercap/network"
|
||||
"github.com/bettercap/bettercap/session"
|
||||
|
||||
|
@ -110,7 +109,7 @@ func (d *BLERecon) Configure() (err error) {
|
|||
if d.Running() {
|
||||
return session.ErrAlreadyStarted
|
||||
} else if d.gattDevice == nil {
|
||||
log.Info("Initializing BLE device ...")
|
||||
d.Info("Initializing BLE device ...")
|
||||
|
||||
// hey Paypal GATT library, could you please just STFU?!
|
||||
golog.SetOutput(ioutil.Discard)
|
||||
|
@ -140,7 +139,7 @@ func (d *BLERecon) Start() error {
|
|||
|
||||
<-d.quit
|
||||
|
||||
log.Info("Stopping BLE scan ...")
|
||||
d.Info("Stopping BLE scan ...")
|
||||
|
||||
d.gattDevice.StopScanning()
|
||||
|
||||
|
@ -156,7 +155,7 @@ func (d *BLERecon) Stop() error {
|
|||
}
|
||||
|
||||
func (d *BLERecon) pruner() {
|
||||
log.Debug("Started BLE devices pruner ...")
|
||||
d.Debug("Started BLE devices pruner ...")
|
||||
|
||||
for d.Running() {
|
||||
for _, dev := range d.Session.BLE.Devices() {
|
||||
|
@ -193,7 +192,7 @@ func (d *BLERecon) enumAllTheThings(mac string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
log.Info("Connecting to %s ...", mac)
|
||||
d.Info("Connecting to %s ...", mac)
|
||||
|
||||
go func() {
|
||||
time.Sleep(d.connTimeout)
|
||||
|
|
|
@ -4,25 +4,23 @@
|
|||
package ble
|
||||
|
||||
import (
|
||||
"github.com/bettercap/bettercap/log"
|
||||
|
||||
"github.com/bettercap/gatt"
|
||||
)
|
||||
|
||||
func (d *BLERecon) onStateChanged(dev gatt.Device, s gatt.State) {
|
||||
log.Info("BLE state changed to %v", s)
|
||||
d.Info("BLE state changed to %v", s)
|
||||
|
||||
switch s {
|
||||
case gatt.StatePoweredOn:
|
||||
if d.currDevice == nil {
|
||||
log.Info("Starting BLE discovery ...")
|
||||
d.Info("Starting BLE discovery ...")
|
||||
dev.Scan([]gatt.UUID{}, true)
|
||||
}
|
||||
case gatt.StatePoweredOff:
|
||||
d.gattDevice = nil
|
||||
|
||||
default:
|
||||
log.Warning("Unexpected BLE state: %v", s)
|
||||
d.Warning("Unexpected BLE state: %v", s)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -33,7 +31,7 @@ func (d *BLERecon) onPeriphDiscovered(p gatt.Peripheral, a *gatt.Advertisement,
|
|||
func (d *BLERecon) onPeriphDisconnected(p gatt.Peripheral, err error) {
|
||||
if d.Running() {
|
||||
// restore scanning
|
||||
log.Info("Device disconnected, restoring BLE discovery.")
|
||||
d.Info("Device disconnected, restoring BLE discovery.")
|
||||
d.setCurrentDevice(nil)
|
||||
d.gattDevice.Scan([]gatt.UUID{}, true)
|
||||
}
|
||||
|
@ -41,31 +39,31 @@ func (d *BLERecon) onPeriphDisconnected(p gatt.Peripheral, err error) {
|
|||
|
||||
func (d *BLERecon) onPeriphConnected(p gatt.Peripheral, err error) {
|
||||
if err != nil {
|
||||
log.Warning("Connected to %s but with error: %s", p.ID(), err)
|
||||
d.Warning("Connected to %s but with error: %s", p.ID(), err)
|
||||
return
|
||||
} else if d.currDevice == nil {
|
||||
// timed out
|
||||
log.Warning("Connected to %s but after the timeout :(", p.ID())
|
||||
d.Warning("Connected to %s but after the timeout :(", p.ID())
|
||||
return
|
||||
}
|
||||
|
||||
d.connected = true
|
||||
|
||||
defer func(per gatt.Peripheral) {
|
||||
log.Info("Disconnecting from %s ...", per.ID())
|
||||
d.Info("Disconnecting from %s ...", per.ID())
|
||||
per.Device().CancelConnection(per)
|
||||
}(p)
|
||||
|
||||
d.Session.Events.Add("ble.device.connected", d.currDevice)
|
||||
|
||||
if err := p.SetMTU(500); err != nil {
|
||||
log.Warning("Failed to set MTU: %s", err)
|
||||
d.Warning("Failed to set MTU: %s", err)
|
||||
}
|
||||
|
||||
log.Info("Connected, enumerating all the things for %s!", p.ID())
|
||||
d.Info("Connected, enumerating all the things for %s!", p.ID())
|
||||
services, err := p.DiscoverServices(nil)
|
||||
if err != nil {
|
||||
log.Error("Error discovering services: %s", err)
|
||||
d.Error("Error discovering services: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,6 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/bettercap/bettercap/log"
|
||||
"github.com/bettercap/bettercap/network"
|
||||
|
||||
"github.com/bettercap/gatt"
|
||||
|
@ -153,7 +152,7 @@ func (d *BLERecon) showServices(p gatt.Peripheral, services []*gatt.Service) {
|
|||
|
||||
chars, err := p.DiscoverCharacteristics(nil, svc)
|
||||
if err != nil {
|
||||
log.Error("Error while enumerating chars for service %s: %s", svc.UUID(), err)
|
||||
d.Error("Error while enumerating chars for service %s: %s", svc.UUID(), err)
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -172,14 +171,14 @@ func (d *BLERecon) showServices(p gatt.Peripheral, services []*gatt.Service) {
|
|||
if wantsToWrite && d.writeUUID.Equal(ch.UUID()) {
|
||||
foundToWrite = true
|
||||
if isWritable {
|
||||
log.Info("Writing %d bytes to characteristics %s ...", len(d.writeData), d.writeUUID)
|
||||
d.Info("Writing %d bytes to characteristics %s ...", len(d.writeData), d.writeUUID)
|
||||
} else {
|
||||
log.Warning("Attempt to write %d bytes to non writable characteristics %s ...", len(d.writeData), d.writeUUID)
|
||||
d.Warning("Attempt to write %d bytes to non writable characteristics %s ...", len(d.writeData), d.writeUUID)
|
||||
}
|
||||
|
||||
err := p.WriteCharacteristic(ch, d.writeData, !withResponse)
|
||||
if err != nil {
|
||||
log.Error("Error while writing: %s", err)
|
||||
d.Error("Error while writing: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -205,7 +204,7 @@ func (d *BLERecon) showServices(p gatt.Peripheral, services []*gatt.Service) {
|
|||
}
|
||||
|
||||
if wantsToWrite && !foundToWrite {
|
||||
log.Error("Writable characteristics %s not found.", d.writeUUID)
|
||||
d.Error("Writable characteristics %s not found.", d.writeUUID)
|
||||
} else {
|
||||
tui.Table(os.Stdout, columns, rows)
|
||||
d.Session.Refresh()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue