Skip to content

Commit c62a529

Browse files
anhmolteivindj-nordic
authored andcommitted
lib: peer_manager: add missing central functionality
Add missing central functionality for handling BLE event BLE_GAP_EVT_SEC_REQUEST from the SoftDevice. Signed-off-by: Andreas Moltumyr <[email protected]>
1 parent ef1d382 commit c62a529

File tree

1 file changed

+44
-35
lines changed

1 file changed

+44
-35
lines changed

lib/bluetooth/peer_manager/modules/security_dispatcher.c

Lines changed: 44 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,25 @@ static void sec_proc_start(uint16_t conn_handle, bool success, enum pm_conn_sec_
238238
}
239239
}
240240

241+
/**
242+
* @brief Function for initiating pairing as a central, or all security as a periheral.
243+
*
244+
* See @ref smd_link_secure and @ref sd_ble_gap_authenticate for more information.
245+
*/
246+
static uint32_t link_secure_authenticate(uint16_t conn_handle, ble_gap_sec_params_t *sec_params)
247+
{
248+
uint32_t err_code = sd_ble_gap_authenticate(conn_handle, sec_params);
249+
250+
if (err_code == NRF_ERROR_NO_MEM) {
251+
/* sd_ble_gap_authenticate() returned NRF_ERROR_NO_MEM. Too many other sec
252+
* procedures running.
253+
*/
254+
err_code = NRF_ERROR_BUSY;
255+
}
256+
257+
return err_code;
258+
}
259+
241260
#if defined(CONFIG_SOFTDEVICE_CENTRAL)
242261
/**
243262
* @brief Function for initiating encryption as a central. See @ref smd_link_secure for more
@@ -356,6 +375,20 @@ static void sec_request_process(const ble_gap_evt_t *gap_evt)
356375
#endif /* CONFIG_SOFTDEVICE_CENTRAL */
357376

358377
#ifdef BLE_GAP_ROLE_PERIPH
378+
/** @brief Function for asking the central to secure the link. See @ref smd_link_secure for more
379+
* info.
380+
*/
381+
static uint32_t link_secure_peripheral(uint16_t conn_handle, ble_gap_sec_params_t *sec_params)
382+
{
383+
uint32_t err_code = NRF_SUCCESS;
384+
385+
if (sec_params != NULL) {
386+
err_code = link_secure_authenticate(conn_handle, sec_params);
387+
}
388+
389+
return err_code;
390+
}
391+
359392
/** @brief Function for processing the @ref BLE_GAP_EVT_SEC_INFO_REQUEST event from the SoftDevice.
360393
*
361394
* @param[in] gap_evt The event from the SoftDevice.
@@ -868,41 +901,6 @@ uint32_t smd_params_reply(uint16_t conn_handle, ble_gap_sec_params_t *sec_params
868901
return err_code;
869902
}
870903

871-
/**
872-
* @brief Function for initiating pairing as a central, or all security as a periheral.
873-
*
874-
* See @ref smd_link_secure and @ref sd_ble_gap_authenticate for more information.
875-
*/
876-
static uint32_t link_secure_authenticate(uint16_t conn_handle, ble_gap_sec_params_t *sec_params)
877-
{
878-
uint32_t err_code = sd_ble_gap_authenticate(conn_handle, sec_params);
879-
880-
if (err_code == NRF_ERROR_NO_MEM) {
881-
/* sd_ble_gap_authenticate() returned NRF_ERROR_NO_MEM. Too many other sec
882-
* procedures running.
883-
*/
884-
err_code = NRF_ERROR_BUSY;
885-
}
886-
887-
return err_code;
888-
}
889-
890-
#ifdef BLE_GAP_ROLE_PERIPH
891-
/** @brief Function for asking the central to secure the link. See @ref smd_link_secure for more
892-
* info.
893-
*/
894-
static uint32_t link_secure_peripheral(uint16_t conn_handle, ble_gap_sec_params_t *sec_params)
895-
{
896-
uint32_t err_code = NRF_SUCCESS;
897-
898-
if (sec_params != NULL) {
899-
err_code = link_secure_authenticate(conn_handle, sec_params);
900-
}
901-
902-
return err_code;
903-
}
904-
#endif
905-
906904
uint32_t smd_link_secure(uint16_t conn_handle, ble_gap_sec_params_t *sec_params,
907905
bool force_repairing)
908906
{
@@ -911,6 +909,11 @@ uint32_t smd_link_secure(uint16_t conn_handle, ble_gap_sec_params_t *sec_params,
911909
uint8_t role = ble_conn_state_role(conn_handle);
912910

913911
switch (role) {
912+
#if defined(CONFIG_SOFTDEVICE_CENTRAL)
913+
case BLE_GAP_ROLE_CENTRAL:
914+
return link_secure_central(conn_handle, sec_params, force_repairing);
915+
#endif /* CONFIG_SOFTDEVICE_CENTRAL */
916+
914917
#ifdef BLE_GAP_ROLE_PERIPH
915918
case BLE_GAP_ROLE_PERIPH:
916919
return link_secure_peripheral(conn_handle, sec_params);
@@ -938,6 +941,12 @@ void smd_ble_evt_handler(const ble_evt_t *ble_evt)
938941
break;
939942
#endif /* BLE_GAP_ROLE_PERIPH */
940943

944+
#if defined(CONFIG_SOFTDEVICE_CENTRAL)
945+
case BLE_GAP_EVT_SEC_REQUEST:
946+
sec_request_process(&(ble_evt->evt.gap_evt));
947+
break;
948+
#endif /* CONFIG_SOFTDEVICE_CENTRAL */
949+
941950
case BLE_GAP_EVT_AUTH_STATUS:
942951
auth_status_process(&(ble_evt->evt.gap_evt));
943952
break;

0 commit comments

Comments
 (0)