diff options
author | Jim Mussared <jim.mussared@gmail.com> | 2021-02-12 14:33:03 +1100 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2021-02-17 11:25:02 +1100 |
commit | 4005138882757ae536482c1d105b28c9869ab8ce (patch) | |
tree | 8eaf9e37d01fdc64df05feaa181d4ee77defdb1c /extmod/nimble/modbluetooth_nimble.c | |
parent | 236274f08fb51d36eba9cd0458483bd398bfed0a (diff) |
extmod/modbluetooth: Allow NimBLE to use Zephyr static address.
Zephyr controllers can be queried for a static address (computed from the
device ID). BlueKitchen already supports this, but make them both use the
same macro to enable the feature.
Diffstat (limited to 'extmod/nimble/modbluetooth_nimble.c')
-rw-r--r-- | extmod/nimble/modbluetooth_nimble.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/extmod/nimble/modbluetooth_nimble.c b/extmod/nimble/modbluetooth_nimble.c index 3910c599c..a0a3998c6 100644 --- a/extmod/nimble/modbluetooth_nimble.c +++ b/extmod/nimble/modbluetooth_nimble.c @@ -48,6 +48,11 @@ #include "nimble/host/src/ble_l2cap_priv.h" #endif +#if MICROPY_PY_BLUETOOTH_ENABLE_HCI_CMD || MICROPY_BLUETOOTH_USE_ZEPHYR_STATIC_ADDRESS +// For ble_hs_hci_cmd_tx +#include "nimble/host/src/ble_hs_hci_priv.h" +#endif + #ifndef MICROPY_PY_BLUETOOTH_DEFAULT_GAP_NAME #define MICROPY_PY_BLUETOOTH_DEFAULT_GAP_NAME "MPY NIMBLE" #endif @@ -179,6 +184,14 @@ STATIC void set_random_address(bool nrpa) { // Mark it as STATIC (not RPA or NRPA). addr.val[5] |= 0xc0; } else + #elif MICROPY_BLUETOOTH_USE_ZEPHYR_STATIC_ADDRESS + if (!nrpa) { + DEBUG_printf("set_random_address: Generating static address from Zephyr controller\n"); + uint8_t buf[23]; + rc = ble_hs_hci_cmd_tx(BLE_HCI_OP(BLE_HCI_OGF_VENDOR, 0x09), NULL, 0, buf, sizeof(buf)); + assert(rc == 0); + memcpy(addr.val, buf + 1, 6); + } else #endif { DEBUG_printf("set_random_address: Generating random static address\n"); @@ -1688,9 +1701,6 @@ int mp_bluetooth_l2cap_recvinto(uint16_t conn_handle, uint16_t cid, uint8_t *buf #if MICROPY_PY_BLUETOOTH_ENABLE_HCI_CMD -// For ble_hs_hci_cmd_tx -#include "nimble/host/src/ble_hs_hci_priv.h" - int mp_bluetooth_hci_cmd(uint16_t ogf, uint16_t ocf, const uint8_t *req, size_t req_len, uint8_t *resp, size_t resp_len, uint8_t *status) { int rc = ble_hs_hci_cmd_tx(BLE_HCI_OP(ogf, ocf), req, req_len, resp, resp_len); if (rc < BLE_HS_ERR_HCI_BASE || rc >= BLE_HS_ERR_HCI_BASE + 0x100) { |