From 7bf62562cee7e5a01eb013447a0c3f4d3d271cab Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 11 Mar 2020 13:59:34 +1100 Subject: extmod/nimble: When getting BLE MAC try public address if random fails. This is needed for BLE.config('mac') to work on esp32. --- extmod/nimble/modbluetooth_nimble.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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 -- cgit v1.2.3