Hi, I want to use iOS to connect nRF82832 with passkey when connecting. I use pca10040_s132 with SDK 12.2.0.
Following is my procedure:
-
define security parameters:
#define SEC_PARAM_BOND 0 #define SEC_PARAM_MITM 1 #define SEC_PARAM_LESC 0 #define SEC_PARAM_KEYPRESS 0 #define SEC_PARAM_IO_CAPABILITIES BLE_GAP_IO_CAPS_DISPLAY_ONLY #define SEC_PARAM_OOB 0
-
define passkey and set it:
// this is global variables
#define STATIC_PASSKEY "123456"
static ble_opt_t m_static_pin_option;
uint8_t passkey[] = STATIC_PASSKEY;
// set passkey in gap_params_init()
m_static_pin_option.gap_opt.passkey.p_passkey = &passkey[0];
err_code = sd_ble_opt_set(BLE_GAP_OPT_PASSKEY, &m_static_pin_option);
APP_ERROR_CHECK(err_code);
- send pairing request and implemet pairing procedure
// add those cases in on_ble_evt()
case BLE_GAP_EVT_CONNECTED:
ble_gap_sec_params_t params;
params.bond = 0;
params.mitm = 1;
sd_ble_gap_authenticate(m_conn_handle,¶ms);
break;
case BLE_GAP_EVT_SEC_PARAMS_REQUEST:
// printf("receive pair request\n");
// resp_pair_request();
ble_gap_sec_params_t sec_params;
uint32_t err_code;
sec_param.bond = SEC_PARAM_BOND;
sec_param.mitm = SEC_PARAM_MITM;
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=sd_ble_gap_sec_params_reply(m_conn_handle,BLE_GAP_SEC_STATUS_SUCCESS,&sec_param,NULL);
APP_ERROR_CHECK(err_code);
break;
case BLE_GAP_EVT_AUTH_STATUS:
if(p_ble_evt->evt.gap_evt.params.auth_status.auth_status == BLE_GAP_SEC_STATUS_SUCCESS)
{
//printf("pair success\r\n");
// int s=0;
// s++;
}
else
{
sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
}
break;
Conclusion: When I use iOS and start connect, the pairing message shows sucessfully and I then enter the passkey "123456". But it fails after senconds with alert:"Timeout interrogating the peripheral". Actually I find "printf("pair success\r\n");" arrives with debugging. So It should be connected. I donnot know why it comes this error. Is there something wrong with my configuration? Is peer_manager_init() important? I comment this function as I donnot need bond. Thanks a lot!