Skip to content

extmod/nimble: Support pairing/bonding on the ESP32. #13258

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/library/bluetooth.rst
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ Pairing and bonding
and ``_IRQ_SET_SECRET`` events.

**Note:** This is currently only supported when using the NimBLE stack on
STM32 and Unix (not ESP32).
ESP32, STM32 and Unix.

.. method:: BLE.gap_pair(conn_handle, /)

Expand Down
24 changes: 13 additions & 11 deletions extmod/nimble/modbluetooth_nimble.c
Original file line number Diff line number Diff line change
Expand Up @@ -592,17 +592,6 @@ int mp_bluetooth_init(void) {

mp_bluetooth_nimble_ble_state = MP_BLUETOOTH_NIMBLE_BLE_STATE_STARTING;

ble_hs_cfg.reset_cb = reset_cb;
ble_hs_cfg.sync_cb = sync_cb;
ble_hs_cfg.gatts_register_cb = gatts_register_cb;
ble_hs_cfg.store_status_cb = ble_store_util_status_rr;

#if MICROPY_PY_BLUETOOTH_ENABLE_PAIRING_BONDING
ble_hs_cfg.store_read_cb = ble_secret_store_read;
ble_hs_cfg.store_write_cb = ble_secret_store_write;
ble_hs_cfg.store_delete_cb = ble_secret_store_delete;
#endif // MICROPY_PY_BLUETOOTH_ENABLE_PAIRING_BONDING

MP_STATE_PORT(bluetooth_nimble_root_pointers) = m_new0(mp_bluetooth_nimble_root_pointers_t, 1);
mp_bluetooth_gatts_db_create(&MP_STATE_PORT(bluetooth_nimble_root_pointers)->gatts_db);

Expand All @@ -622,6 +611,19 @@ int mp_bluetooth_init(void) {
DEBUG_printf("mp_bluetooth_init: nimble_port_init\n");
nimble_port_init();

ble_hs_cfg.reset_cb = reset_cb;
ble_hs_cfg.sync_cb = sync_cb;
ble_hs_cfg.gatts_register_cb = gatts_register_cb;
ble_hs_cfg.store_status_cb = ble_store_util_status_rr;

#if MICROPY_PY_BLUETOOTH_ENABLE_PAIRING_BONDING
ble_hs_cfg.sm_our_key_dist = BLE_SM_PAIR_KEY_DIST_ENC | BLE_SM_PAIR_KEY_DIST_ID | BLE_SM_PAIR_KEY_DIST_SIGN;
ble_hs_cfg.sm_their_key_dist = BLE_SM_PAIR_KEY_DIST_ENC | BLE_SM_PAIR_KEY_DIST_ID | BLE_SM_PAIR_KEY_DIST_SIGN;
ble_hs_cfg.store_read_cb = ble_secret_store_read;
ble_hs_cfg.store_write_cb = ble_secret_store_write;
ble_hs_cfg.store_delete_cb = ble_secret_store_delete;
#endif // MICROPY_PY_BLUETOOTH_ENABLE_PAIRING_BONDING

// Make sure that the HCI UART and event handling task is running.
mp_bluetooth_nimble_port_start();

Expand Down