summaryrefslogtreecommitdiff
path: root/extmod/nimble/modbluetooth_nimble.c
diff options
context:
space:
mode:
authorJim Mussared <jim.mussared@gmail.com>2020-08-17 10:53:00 +1000
committerDamien George <damien@micropython.org>2020-09-08 12:53:24 +1000
commit52a2ce45de353267776aaa25856c9d144653f142 (patch)
treef24d6c65b6c51e941208d731eb9f20612e59331b /extmod/nimble/modbluetooth_nimble.c
parent67d8139e2b4cbaba5c722feef4e5478ae647344d (diff)
extmod/modbluetooth: Allow using mp_hal_get_mac as a static address.
Generally a controller should either have its own public address hardcoded, or loaded by the driver (e.g. cywbt43). However, for a controller that has no public address where you still want a long-term stable address, this allows you to use a static address generated by the port. Typically on STM32 this will be an LAA, but a board might override this.
Diffstat (limited to 'extmod/nimble/modbluetooth_nimble.c')
-rw-r--r--extmod/nimble/modbluetooth_nimble.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/extmod/nimble/modbluetooth_nimble.c b/extmod/nimble/modbluetooth_nimble.c
index 1c782943a..4222f58fa 100644
--- a/extmod/nimble/modbluetooth_nimble.c
+++ b/extmod/nimble/modbluetooth_nimble.c
@@ -157,10 +157,22 @@ STATIC bool has_public_address(void) {
STATIC void set_random_address(bool nrpa) {
int rc;
(void)rc;
- DEBUG_printf("sync_cb: Generating random static address\n");
ble_addr_t addr;
- rc = ble_hs_id_gen_rnd(nrpa ? 1 : 0, &addr);
- assert(rc == 0);
+ #if MICROPY_BLUETOOTH_USE_MP_HAL_GET_MAC_STATIC_ADDRESS
+ if (!nrpa) {
+ DEBUG_printf("set_random_address: Generating static address using mp_hal_get_mac\n");
+ uint8_t hal_mac_addr[6];
+ mp_hal_get_mac(MP_HAL_MAC_BDADDR, hal_mac_addr);
+ addr = create_nimble_addr(BLE_ADDR_RANDOM, hal_mac_addr);
+ // Mark it as STATIC (not RPA or NRPA).
+ addr.val[5] |= 0xc0;
+ } else
+ #endif
+ {
+ DEBUG_printf("set_random_address: Generating random static address\n");
+ rc = ble_hs_id_gen_rnd(nrpa ? 1 : 0, &addr);
+ assert(rc == 0);
+ }
rc = ble_hs_id_set_rnd(addr.val);
assert(rc == 0);
rc = ble_hs_util_ensure_addr(1);