![]() |
nRF Connect SDK Bare Metal API 2.0.99
|
| uint32_t pm_conn_secure | ( | uint16_t | conn_handle, |
| bool | force_repairing ) |
#include <peer_manager.h>
Establish encryption on a connection, and optionally establish a bond.
This function attempts to secure the link that is specified by conn_handle. It uses the parameters that were previously provided in a call to pm_sec_params_set.
If the connection is a central connection, calling this function starts a security procedure on the link. If there are keys from a previous bonding procedure with this peer and the keys meet the security requirements in the currently active security parameters, the function attempts to establish encryption with the existing keys. If no key exists, the function attempts to perform pairing and bonding according to the currently active security parameters.
If the function completes successfully, a PM_EVT_CONN_SEC_START event is sent. The procedure might be queued, in which case the PM_EVT_CONN_SEC_START event is delayed until the procedure is initiated in the SoftDevice.
If the connection is a peripheral connection, the function sends a security request to the peer (central). It is up to the peer then to initiate pairing or encryption. If the peer ignores the request, a BLE_GAP_EVT_AUTH_STATUS event occurs with the status BLE_GAP_SEC_STATUS_TIMEOUT. Otherwise, the peer initiates security, in which case things happen as if the peer had initiated security itself. See PM_EVT_CONN_SEC_START for information about peer-initiated security.
| [in] | conn_handle | Connection handle of the link as provided by the SoftDevice. |
| [in] | force_repairing | Whether to force a pairing procedure even if there is an existing encryption key. This argument is relevant only for the central role. Recommended value: false. |
| NRF_SUCCESS | If the operation completed successfully. |
| NRF_ERROR_BUSY | If a security procedure is already in progress on the link, or if the link is disconnecting or disconnected. |
| NRF_ERROR_TIMEOUT | If there was an SMP time-out, so that no more security operations can be performed on this link. |
| BLE_ERROR_INVALID_CONN_HANDLE | If the connection handle is invalid. |
| NRF_ERROR_NOT_FOUND | If the security parameters have not been set, either by pm_sec_params_set or by pm_conn_sec_params_reply. |
| NRF_ERROR_INVALID_DATA | If the peer is bonded, but no LTK was found in the stored bonding data. Repairing was not requested. |
| NRF_ERROR_INVALID_STATE | If the Peer Manager is not initialized. |
| NRF_ERROR_INTERNAL | If an internal error occurred. |