I have one nRF52822 Ble. It has secure pairing mechanism. when i connect iphone, App trigger Pair dialog from iOS. and press pairing, then stop. i can follow nRF52822 code. after print pair success , it will disconect, disconnected.reason is 0x13. why?
static void on_ble_evt(ble_evt_t * p_ble_evt)
{
uint32_t err_code;
printf("evt id =======%x\r\n",p_ble_evt->header.evt_id);
switch (p_ble_evt->header.evt_id)
{
case BLE_GAP_EVT_CONNECTED:
printf("handle BLE_GAP_EVT_CONNECTED event in on_ble_evt()\r\n");
err_code = bsp_indication_set(BSP_INDICATE_CONNECTED);
APP_ERROR_CHECK(err_code);
m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
ble_gap_sec_params_t params;
params.bond = 0;
params.mitm = 0;
params.io_caps = 1;
sd_ble_gap_authenticate(m_conn_handle,¶ms);
break;
case BLE_GAP_EVT_DISCONNECTED:
printf("BLE_GAP_EVT_DISCONNECTED in on_ble_evt(), Reason: 0x%x\r\n", p_ble_evt->evt.gap_evt.params.disconnected.reason);
err_code = bsp_indication_set(BSP_INDICATE_IDLE);
APP_ERROR_CHECK(err_code);
m_conn_handle = BLE_CONN_HANDLE_INVALID;
break;
case BLE_GAP_EVT_SEC_PARAMS_REQUEST:
// Pairing not supported
ble_gap_sec_params_t sec_params;
printf("handle BLE_GAP_EVT_SEC_PARAMS_REQUEST in on_ble_evt()\r\n");
memset(&sec_params,0,sizeof(ble_gap_sec_params_t));
sec_params.bond = 0;
sec_params.io_caps = 1;
sec_params.max_key_size = 16;
sec_params.min_key_size = 7;
sec_params.oob = 0;
sec_params.mitm = 0;
err_code=sd_ble_gap_sec_params_reply(m_conn_handle,BLE_GAP_SEC_STATUS_SUCCESS,&sec_params,NULL);
APP_ERROR_CHECK(err_code);
// err_code = sd_ble_gap_sec_params_reply(m_conn_handle, BLE_GAP_SEC_STATUS_PAIRING_NOT_SUPP, NULL, 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");
}else{
printf("pair fail \r\n");
sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
}
break;
case BLE_GAP_EVT_CONN_SEC_UPDATE:
printf("handle BLE_GAP_EVT_CONN_SEC_UPDATE event in on_ble_evt()\r\n");
break;
case BLE_GATTS_EVT_SYS_ATTR_MISSING:
// No system attributes have been stored.
err_code = sd_ble_gatts_sys_attr_set(m_conn_handle, NULL, 0, 0);
APP_ERROR_CHECK(err_code);
break;
default:
// No implementation needed.
break;
}
}
this is all print main.......
QR code name:F13C7DA2AF5A
ble_stack_init() is done.......
device name of GAP = F13C7DA2AF5A
Message:10
handle BLE_GAP_EVT_CONNECTED event in ble_conn_params_on_ble_evt()
evt id =======10
handle BLE_GAP_EVT_CONNECTED event in on_ble_evt()
handle BLE_GAP_EVT_CONNECTED event in ble_nus_on_ble_evt()
handle BLE_GAP_EVT_CONNECTED event in on_ble_evt()
Message:13
evt id =======13
handle BLE_GAP_EVT_SEC_PARAMS_REQUEST in on_ble_evt()
Message:50
BLE_GATTS_EVT_WRITE event in ble_nus_on_ble_evt()
enter on_write()
p_nus->is_notification_enabled = true
evt id =======50
Message:18
evt id =======18
handle BLE_GAP_EVT_CONN_SEC_UPDATE event in on_ble_evt()
Message:17
evt id =======17
handle BLE_GAP_EVT_AUTH_STATUS event in on_ble_evt()
pair success
Message:11
evt id =======11
BLE_GAP_EVT_DISCONNECTED in on_ble_evt(), Reason: 0x13