diff options
| author | Damien George | 2020-03-11 13:59:34 +1100 |
|---|---|---|
| committer | Damien George | 2020-03-11 14:02:13 +1100 |
| commit | 7bf62562cee7e5a01eb013447a0c3f4d3d271cab (patch) | |
| tree | 9a4e1c7be47aff4febc0660041bcad0a72f619de /extmod | |
| parent | dd0bc26e65734b8a4fafa3769008e92e2ec6645d (diff) | |
extmod/nimble: When getting BLE MAC try public address if random fails.
This is needed for BLE.config('mac') to work on esp32.
Diffstat (limited to 'extmod')
| -rw-r--r-- | extmod/nimble/modbluetooth_nimble.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/extmod/nimble/modbluetooth_nimble.c b/extmod/nimble/modbluetooth_nimble.c index fb8161e78..334a00b5e 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 |
