mirror of
https://github.com/bettercap/bettercap
synced 2025-08-19 13:09:49 -07:00
new: new ble.device parameter to set HCI index (closes #519)
This commit is contained in:
parent
c3f0e3598b
commit
1eec682aeb
1 changed files with 18 additions and 2 deletions
|
@ -20,6 +20,7 @@ import (
|
||||||
|
|
||||||
type BLERecon struct {
|
type BLERecon struct {
|
||||||
session.SessionModule
|
session.SessionModule
|
||||||
|
deviceId int
|
||||||
gattDevice gatt.Device
|
gattDevice gatt.Device
|
||||||
currDevice *network.BLEDevice
|
currDevice *network.BLEDevice
|
||||||
writeUUID *gatt.UUID
|
writeUUID *gatt.UUID
|
||||||
|
@ -34,6 +35,7 @@ type BLERecon struct {
|
||||||
func NewBLERecon(s *session.Session) *BLERecon {
|
func NewBLERecon(s *session.Session) *BLERecon {
|
||||||
mod := &BLERecon{
|
mod := &BLERecon{
|
||||||
SessionModule: session.NewSessionModule("ble.recon", s),
|
SessionModule: session.NewSessionModule("ble.recon", s),
|
||||||
|
deviceId: -1,
|
||||||
gattDevice: nil,
|
gattDevice: nil,
|
||||||
quit: make(chan bool),
|
quit: make(chan bool),
|
||||||
done: make(chan bool),
|
done: make(chan bool),
|
||||||
|
@ -110,6 +112,10 @@ func NewBLERecon(s *session.Session) *BLERecon {
|
||||||
|
|
||||||
mod.AddHandler(write)
|
mod.AddHandler(write)
|
||||||
|
|
||||||
|
mod.AddParam(session.NewIntParameter("ble.device",
|
||||||
|
fmt.Sprintf("%d", mod.deviceId),
|
||||||
|
"Index of the HCI device to use, -1 to autodetect."))
|
||||||
|
|
||||||
return mod
|
return mod
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,11 +148,21 @@ func (mod *BLERecon) Configure() (err error) {
|
||||||
if mod.Running() {
|
if mod.Running() {
|
||||||
return session.ErrAlreadyStarted(mod.Name())
|
return session.ErrAlreadyStarted(mod.Name())
|
||||||
} else if mod.gattDevice == nil {
|
} else if mod.gattDevice == nil {
|
||||||
mod.Debug("initializing device ...")
|
if err, mod.deviceId = mod.IntParam("ble.device"); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
mod.Debug("initializing device (id:%d) ...", mod.deviceId)
|
||||||
|
|
||||||
golog.SetFlags(0)
|
golog.SetFlags(0)
|
||||||
golog.SetOutput(dummyWriter{mod})
|
golog.SetOutput(dummyWriter{mod})
|
||||||
if mod.gattDevice, err = gatt.NewDevice(defaultBLEClientOptions...); err != nil {
|
|
||||||
|
options := []gatt.Option{
|
||||||
|
gatt.LnxMaxConnections(255),
|
||||||
|
gatt.LnxDeviceID(mod.deviceId, true),
|
||||||
|
}
|
||||||
|
|
||||||
|
if mod.gattDevice, err = gatt.NewDevice(options...); err != nil {
|
||||||
mod.Debug("error while creating new gatt device: %v", err)
|
mod.Debug("error while creating new gatt device: %v", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue