This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

NRF51822 sdk 10.0After binding the connection fails

Hello, I now is in a problem.My equipment set up matching binding but after binding equipment connection will connection failure.If it is not binding, it can be the connection is successful. Could you tell me how to solve this problem this I should be. The following is part of the program

void init_keyset(void) {

keyset.keys_periph.p_enc_key = &my_enc_key;
keyset.keys_periph.p_id_key = NULL;
keyset.keys_periph.p_sign_key = NULL;

keyset.keys_central.p_enc_key = &my_enc_key_center;
keyset.keys_central.p_id_key = NULL;
keyset.keys_central.p_sign_key = NULL;      

}

static void resp_pair_request() {

uint32_t err_code; sec_params.bond = SEC_PARAM_BOND;
sec_params.mitm = SEC_PARAM_MITM;
sec_params.io_caps = SEC_PARAM_IO_CAPABILITIES;
sec_params.oob = SEC_PARAM_OOB;
sec_params.min_key_size = SEC_PARAM_MIN_KEY_SIZE;
sec_params.max_key_size = SEC_PARAM_MAX_KEY_SIZE;

sec_params.kdist_central.enc = 1;

sec_params.kdist_central.id = 0;

sec_params.kdist_central.sign = 0;

sec_params.kdist_periph.enc = 1;

sec_params.kdist_periph.id = 0;

sec_params.kdist_periph.sign = 0;

err_code= sd_ble_gap_sec_params_reply(m_conn_handle, BLE_GAP_SEC_STATUS_SUCCESS,&sec_params,&keyset); APP_ERROR_CHECK(err_code); }

static void on_ble_evt(ble_evt_t * p_ble_evt) {

uint32_t err_code;

switch (p_ble_evt->header.evt_id)
{
    case BLE_GAP_EVT_CONNECTED:
        LEDS_ON(CONNECTED_LED_PIN);
        LEDS_OFF(ADVERTISING_LED_PIN);
        m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
       init_keyset();
        err_code = app_button_enable();
        APP_ERROR_CHECK(err_code);
        break;

    case BLE_GAP_EVT_DISCONNECTED:
        LEDS_OFF(CONNECTED_LED_PIN);
        m_conn_handle = BLE_CONN_HANDLE_INVALID;

        err_code = app_button_disable();
        APP_ERROR_CHECK(err_code);

        advertising_start();
        break;

    case BLE_GAP_EVT_SEC_PARAMS_REQUEST:
        // Pairing not supported
        resp_pair_request();
        //APP_ERROR_CHECK(err_code);
        break;
	case BLE_GAP_EVT_PASSKEY_DISPLAY:
		 printf("show passkey: ");
        for ( int i = 0; i < 6; i++)
 {        while(app_uart_put(p_ble_evt->evt.gap_evt.params.\
        passkey_display.passkey[i]) != NRF_SUCCESS);
            }
        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;
    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
        {
        sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
        }
		 break;
		case BLE_GAP_EVT_SEC_INFO_REQUEST:
			
		 err_code = sd_ble_gap_sec_info_reply(m_conn_handle, &(my_enc_key.enc_info), NULL, NULL);
			break;
    default:
        break;
}

}

Related