From d6e67468099ca228d1464b8033ba0c629e9a1557 Mon Sep 17 00:00:00 2001 From: evilsocket Date: Sun, 17 Mar 2019 13:36:59 +0100 Subject: [PATCH] fix: setting BLE device name once services are enumerated --- modules/ble/ble_show_services.go | 4 ++++ network/ble_device.go | 13 ++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/modules/ble/ble_show_services.go b/modules/ble/ble_show_services.go index bb1ffc86..ffff0cae 100644 --- a/modules/ble/ble_show_services.go +++ b/modules/ble/ble_show_services.go @@ -367,6 +367,10 @@ func (mod *BLERecon) showServices(p gatt.Peripheral, services []*gatt.Service) { data = parseRawData(raw) } + if ch.Name() == "Device Name" && data != "" && mod.currDevice.DeviceName == "" { + mod.currDevice.DeviceName = data + } + if multi == nil { char.Data = data rows = append(rows, []string{ diff --git a/network/ble_device.go b/network/ble_device.go index 1b363dd7..3cb115aa 100644 --- a/network/ble_device.go +++ b/network/ble_device.go @@ -28,6 +28,7 @@ type BLEService struct { type BLEDevice struct { LastSeen time.Time + DeviceName string Vendor string RSSI int Device gatt.Peripheral @@ -62,9 +63,15 @@ func NewBLEDevice(p gatt.Peripheral, a *gatt.Advertisement, rssi int) *BLEDevice } func (d *BLEDevice) Name() string { - name := d.Device.Name() - if name == "" && d.Advertisement != nil { - name = d.Advertisement.LocalName + // get the name if it's being set during services enumeration via 'Device Name' + name := d.DeviceName + if name == "" { + // get the name from the device + name := d.Device.Name() + if name == "" && d.Advertisement != nil { + // get the name from the advertisement data + name = d.Advertisement.LocalName + } } return name }