summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2020-03-11 13:59:34 +1100
committerDamien George <damien.p.george@gmail.com>2020-03-11 14:02:13 +1100
commit7bf62562cee7e5a01eb013447a0c3f4d3d271cab (patch)
tree9a4e1c7be47aff4febc0660041bcad0a72f619de
parentdd0bc26e65734b8a4fafa3769008e92e2ec6645d (diff)
downloadmicropython-7bf62562cee7e5a01eb013447a0c3f4d3d271cab.tar.gz
micropython-7bf62562cee7e5a01eb013447a0c3f4d3d271cab.zip
extmod/nimble: When getting BLE MAC try public address if random fails.
This is needed for BLE.config('mac') to work on esp32.
-rw-r--r--extmod/nimble/modbluetooth_nimble.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/extmod/nimble/modbluetooth_nimble.c b/extmod/nimble/modbluetooth_nimble.c
index fb8161e782..334a00b5e7 100644
--- a/extmod/nimble/modbluetooth_nimble.c
+++ b/extmod/nimble/modbluetooth_nimble.c
@@ -339,7 +339,14 @@ bool mp_bluetooth_is_active(void) {
void mp_bluetooth_get_device_addr(uint8_t *addr) {
#if MICROPY_PY_BLUETOOTH_RANDOM_ADDR
- ble_hs_id_copy_addr(BLE_ADDR_RANDOM, addr, NULL);
+ uint8_t addr_le[6];
+ int rc = ble_hs_id_copy_addr(BLE_ADDR_RANDOM, addr_le, NULL);
+ if (rc != 0) {
+ // Even with MICROPY_PY_BLUETOOTH_RANDOM_ADDR enabled the public address may
+ // be used instead, in which case there is no random address.
+ ble_hs_id_copy_addr(BLE_ADDR_PUBLIC, addr_le, NULL);
+ }
+ reverse_addr_byte_order(addr, addr_le);
#else
mp_hal_get_mac(MP_HAL_MAC_BDADDR, addr);
#endif