Problem description:
When using 'Just works' pairing with LESC key exchange peer_manager doesn't allocate buffer for peer public key and doesn't pass own public key to sd_ble_gap_sec_params_reply
on BLE_GAP_EVT_SEC_PARAMS_REQUEST
. This results in softdevice throwing error code 10 which escalates to PM_EVT_ERROR_UNEXPECTED
resulting in assert.
Steps to reproduce:
Compile ble_app_multirole_lesc
example with following main.c. Connect to the board and try to pair.
Mitigation:
Apply following patch:
index 524a976..986d18b 100644
--- a/nRF5x_SDK12/components/ble/peer_manager/security_dispatcher.c
+++ b/nRF5x_SDK12/components/ble/peer_manager/security_dispatcher.c
@@ -596,7 +596,13 @@ ret_code_t smd_params_reply(uint16_t conn_handle,
}
else
{
- // Pairing only, no action needed.
+ //Pairing
+ if(p_sec_params->lesc) //LESC 'Just works' pairing
+ {
+ // Add own public key and buffer for peer public key to parameters passed to softdevice
+ sec_keyset.keys_own.p_pk = p_public_key;
+ sec_keyset.keys_peer.p_pk = &m_peer_pk;
+ }
}
if (err_code == NRF_SUCCESS)
This allows successful pairing and bonding in 'just works' mode with ECDH based key exchange.
I'd be grateful if someone with more knowledge of how peer_manager works internally looked at my modifications and made sure that it didn't broke anything.