Hi,
There are two things that can happen when I test paired bindings:(Test environment SDK_17.1,nrf52832, Android system,Add a paired binding in the ble_app_uart example,keil development)
The first kind: after binding, the host deletes the binding, and the slave machine does not delete, so the test has no problem
Type 2: After binding, delete the binding from the host.
#define SEC_PARAM_BOND 1 /**< Perform bonding. */
#define SEC_PARAM_MITM 0 /**< Man In The Middle protection not required. */
#define SEC_PARAM_LESC 0 /**< LE Secure Connections not enabled. */
#define SEC_PARAM_KEYPRESS 0 /**< Keypress notifications not enabled. */
#define SEC_PARAM_IO_CAPABILITIES BLE_GAP_IO_CAPS_NONE /**< No I/O capabilities. */
#define SEC_PARAM_OOB 0 /**< Out Of Band data not available. */
#define SEC_PARAM_MIN_KEY_SIZE 7 /**< Minimum encryption key size. */
#define SEC_PARAM_MAX_KEY_SIZE 16
static void peer_manager_init(void)
{
ret_code_t err_code;
err_code = pm_init();
APP_ERROR_CHECK(err_code);
memset(&sec_param, 0, sizeof(ble_gap_sec_params_t));
sec_param.bond = SEC_PARAM_BOND;
sec_param.mitm = SEC_PARAM_MITM;
sec_param.lesc = SEC_PARAM_LESC;
sec_param.keypress = SEC_PARAM_KEYPRESS; /* */
sec_param.io_caps = SEC_PARAM_IO_CAPABILITIES;
sec_param.oob = SEC_PARAM_OOB;
sec_param.min_key_size = SEC_PARAM_MIN_KEY_SIZE; /* */
sec_param.max_key_size = SEC_PARAM_MAX_KEY_SIZE; /* */
sec_param.kdist_own.enc = 1;
sec_param.kdist_own.id = 1;
sec_param.kdist_peer.enc = 1;
sec_param.kdist_peer.id = 1;
err_code = pm_sec_params_set(&sec_param);
APP_ERROR_CHECK(err_code);
err_code = pm_register(pm_evt_handler);
APP_ERROR_CHECK(err_code);
}
Steps:
1.Add the slave key loss handler to pm_evt_handler
case PM_EVT_CONN_SEC_FAILED:
{
if (p_evt->params.conn_sec_failed.procedure == PM_CONN_SEC_PROCEDURE_ENCRYPTION &&
p_evt->params.conn_sec_failed.error == PM_CONN_SEC_ERROR_PIN_OR_KEY_MISSING)
{
// Local device lost bond info, don't disconnect and wait for re-bond
NRF_LOG_INFO("Loss of binding information\n");
NRF_LOG_INFO("The connection failed because the slave lost its LTK\r\n");
err_code = pm_conn_secure(p_evt->conn_handle,true);
if(err_code != NRF_ERROR_BUSY)
{
NRF_LOG_ERROR("Re-pairing failed due to: %d",err_code);
}
NRF_LOG_INFO("The security connection is re-established\n");
}
else
{
sd_ble_gap_disconnect(p_evt->conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
}
}
break;
2.Download the program and bind it to your phone
3.Long press button 4 of nrf52832_DK to delete the binding information.
4.After deleting the binding information of the slave machine, for the first time, the mobile phone clicked on the connection and was directly connected, and the NUS service could be used to send and receive data.
5.After disconnecting. The second time, clicking Connect triggers the pairing binding process
nrf connect test symptom:
I would like to ask how the first connection after the binding is removed from the machine will be reminded of the pairing message instead of the direct connection. Is this possible? If so, how should I add the code?
The following is my project, the protocol stack is s132, using KEIL for development, if necessary can be copied to SDK_17.1 directly run.
Looking forward to your reply!
Best regards, stars