I am attempting to add peer manager bonding and whitelisting to an existing app.
The app is simple, uses nordic uart services to pass 4 bytes of data between two embedded nrf52840 nodes, one as BLE periph, one as BLE central. It works fine using a basic BLE connection with SCAN_UUID_FILTER and SCAN_ADDR_FILTER, however I want to lock down the connection at manufacture, and bonding and single-entry whitelists at both ends seems the way to go.
My problem is that Bonding simply isn't happening when the connection is established, the peer manager just isn't getting events.
I copied pm code over from the heart rate examples ble_app_hrs and ble_app_hrs_c. My code at both ends is calling peer_manager_init(), as the examples, and my understanding is that this should cause connections to become bonded. But pm_evt_handler() just doesn't get called, at either end. When running the hrs examples (which bond just fine), I can see that the event handler (at both ends) gets BLE_GAP_EVT_LESC_DHKEY_REQUEST. But my app doesn't get this. Watching ble_evt_handler() I don't see any security-related events.
With debug logging enabled (NRF_LOG_DEFAULT_LEVEL & PM_LOG_LEVEL 4, at startup both ends do:-
<debug> nrf_ble_lesc: Initialized nrf_crypto.
<debug> nrf_ble_lesc: Initialized nrf_ble_lesc.
<debug> nrf_ble_lesc: Generating ECC key pair
Then when connecting I get at Periph:
<info> app: Connected
<debug> nrf_ble_gatt: Peer on connection 0x0 requested an ATT MTU of 247 bytes.
<debug> nrf_ble_gatt: Updating ATT MTU to 23 bytes (desired: 23) on connection 0x0.
<info> app: Data len is set to 0x14(20)
<debug> app: ATT MTU exchange completed. central 0x17 peripheral 0x17
<debug> nrf_ble_gatt: Peer on connection 0x0 requested a data length of 251 bytes.
<debug> nrf_ble_gatt: Updating data length to 27 on connection 0x0.
<debug> nrf_ble_gatt: Data length updated to 27 on connection 0x0.
<debug> nrf_ble_gatt: max_rx_octets: 27
<debug> nrf_ble_gatt: max_tx_octets: 27
<debug> nrf_ble_gatt: max_rx_time: 2120
<debug> nrf_ble_gatt: max_tx_time: 2120
<debug> app: ATT MTU exchange completed. central 0x17 peripheral 0x17
Central:
<info> app: BLE UART central started.
<debug> ble_scan: Scanning
<debug> nrf_ble_gq: GATTC Write Request
<debug> nrf_ble_gq: SD GATT procedure (1) succeeded on connection handle: 0.
<info> app: Connected to device with Nordic UART Service.
<debug> nrf_ble_gq: Processing the request queue...
<debug> nrf_ble_gq: Processing the request queue...
As you can see, nothing at all from peer_manager:...
Any suggestions on where I should be looking?
Using nrf52840, SES, SDK 17.0.2
Here's a link to my source code if it helps (forgive the rough edges). sble_1241.c is peripheral device, sble_1242.c is central. In both modules, init_ble() is called from main at startup.
https://www.dropbox.com/s/pr8ujjuo5vk9as4/sble_source_snap20210302A.zip