mirror of
https://github.com/bettercap/bettercap
synced 2025-08-14 10:46:57 -07:00
new: implemented ble.timeout and ble.ttl parameters (ref #560)
This commit is contained in:
parent
4cba4f9ff2
commit
8ec91c9206
2 changed files with 23 additions and 6 deletions
|
@ -26,7 +26,8 @@ type BLERecon struct {
|
|||
writeUUID *gatt.UUID
|
||||
writeData []byte
|
||||
connected bool
|
||||
connTimeout time.Duration
|
||||
connTimeout int
|
||||
devTTL int
|
||||
quit chan bool
|
||||
done chan bool
|
||||
selector *utils.ViewSelector
|
||||
|
@ -39,7 +40,8 @@ func NewBLERecon(s *session.Session) *BLERecon {
|
|||
gattDevice: nil,
|
||||
quit: make(chan bool),
|
||||
done: make(chan bool),
|
||||
connTimeout: time.Duration(5) * time.Second,
|
||||
connTimeout: 5,
|
||||
devTTL: 30,
|
||||
currDevice: nil,
|
||||
connected: false,
|
||||
}
|
||||
|
@ -116,6 +118,14 @@ func NewBLERecon(s *session.Session) *BLERecon {
|
|||
fmt.Sprintf("%d", mod.deviceId),
|
||||
"Index of the HCI device to use, -1 to autodetect."))
|
||||
|
||||
mod.AddParam(session.NewIntParameter("ble.timeout",
|
||||
fmt.Sprintf("%d", mod.connTimeout),
|
||||
"Connection timeout in seconds."))
|
||||
|
||||
mod.AddParam(session.NewIntParameter("ble.ttl",
|
||||
fmt.Sprintf("%d", mod.devTTL),
|
||||
"Seconds of inactivity for a device to be pruned."))
|
||||
|
||||
return mod
|
||||
}
|
||||
|
||||
|
@ -176,6 +186,12 @@ func (mod *BLERecon) Configure() (err error) {
|
|||
mod.gattDevice.Init(mod.onStateChanged)
|
||||
}
|
||||
|
||||
if err, mod.connTimeout = mod.IntParam("ble.timeout"); err != nil {
|
||||
return err
|
||||
} else if err, mod.devTTL = mod.IntParam("ble.ttl"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -221,7 +237,8 @@ func (mod *BLERecon) Stop() error {
|
|||
}
|
||||
|
||||
func (mod *BLERecon) pruner() {
|
||||
mod.Debug("started devices pruner ...")
|
||||
blePresentInterval := time.Duration(mod.devTTL) * time.Second
|
||||
mod.Debug("started devices pruner with ttl %s", blePresentInterval)
|
||||
|
||||
for mod.Running() {
|
||||
for _, dev := range mod.Session.BLE.Devices() {
|
||||
|
@ -262,7 +279,7 @@ func (mod *BLERecon) enumAllTheThings(mac string) error {
|
|||
mod.Info("connecting to %s ...", mac)
|
||||
|
||||
go func() {
|
||||
time.Sleep(mod.connTimeout)
|
||||
time.Sleep(time.Duration(mod.connTimeout) * time.Second)
|
||||
if mod.isEnumerating() && !mod.connected {
|
||||
mod.Warning("connection timeout")
|
||||
mod.Session.Events.Add("ble.connection.timeout", mod.currDevice)
|
||||
|
|
|
@ -15,8 +15,7 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
bleAliveInterval = time.Duration(5) * time.Second
|
||||
blePresentInterval = time.Duration(30) * time.Second
|
||||
bleAliveInterval = time.Duration(5) * time.Second
|
||||
)
|
||||
|
||||
func (mod *BLERecon) getRow(dev *network.BLEDevice, withName bool) []string {
|
||||
|
@ -27,6 +26,7 @@ func (mod *BLERecon) getRow(dev *network.BLEDevice, withName bool) []string {
|
|||
sinceSeen := time.Since(dev.LastSeen)
|
||||
lastSeen := dev.LastSeen.Format("15:04:05")
|
||||
|
||||
blePresentInterval := time.Duration(mod.devTTL) * time.Second
|
||||
if sinceSeen <= bleAliveInterval {
|
||||
lastSeen = tui.Bold(lastSeen)
|
||||
} else if sinceSeen > blePresentInterval {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue