From 1eec682aeb9ca1f91cae7e5a5631f4e422a71c47 Mon Sep 17 00:00:00 2001 From: evilsocket Date: Fri, 29 Mar 2019 20:16:41 +0100 Subject: [PATCH] new: new ble.device parameter to set HCI index (closes #519) --- modules/ble/ble_recon.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/modules/ble/ble_recon.go b/modules/ble/ble_recon.go index afb2e216..d30bf03d 100644 --- a/modules/ble/ble_recon.go +++ b/modules/ble/ble_recon.go @@ -20,6 +20,7 @@ import ( type BLERecon struct { session.SessionModule + deviceId int gattDevice gatt.Device currDevice *network.BLEDevice writeUUID *gatt.UUID @@ -34,6 +35,7 @@ type BLERecon struct { func NewBLERecon(s *session.Session) *BLERecon { mod := &BLERecon{ SessionModule: session.NewSessionModule("ble.recon", s), + deviceId: -1, gattDevice: nil, quit: make(chan bool), done: make(chan bool), @@ -110,6 +112,10 @@ func NewBLERecon(s *session.Session) *BLERecon { 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 } @@ -142,11 +148,21 @@ func (mod *BLERecon) Configure() (err error) { if mod.Running() { return session.ErrAlreadyStarted(mod.Name()) } 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.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) return err }