sd_ble_gap_sec_params_reply() failed, errCode=0x8

I set static passkey to "123456" and enter "123456" in nRF Connect passkey request dialog. But sd_ble_gap_sec_params_reply() return 0x8 error code.

static void ble_evt_handler(ble_evt_t const* pBleEvt, void* pContext)
{
    ret_code_t errCode = NRF_SUCCESS;
    
    switch (pBleEvt->header.evt_id)
    {
        case BLE_GAP_EVT_CONNECTED:
        {
            NRF_LOG_INFO("Connected.");
            BLE_UART_SetState(BLE_NUS_STATE_CONNECT);
            errCode = bsp_indication_set(BSP_INDICATE_CONNECTED);
            if (errCode != NRF_SUCCESS) {
                NRF_LOG_WARNING("bsp_indication_set() failed, errCode=0x%x\n", errCode);
                return;
            }    

            m_cur_conn_handle = pBleEvt->evt.gap_evt.conn_handle;

            errCode = nrf_ble_qwr_conn_handle_assign(&m_qwr, m_cur_conn_handle);
            if (errCode != NRF_SUCCESS) {
                NRF_LOG_WARNING("nrf_ble_qwr_conn_handle_assign() failed, errCode=0x%x\n", errCode);
                return;
            }

            ble_gap_sec_params_t secParam;
            secParam.bond           = SEC_PARAM_BOND;
            secParam.mitm           = SEC_PARAM_MITM;
            errCode = sd_ble_gap_authenticate(m_cur_conn_handle, &secParam);
            if (errCode != NRF_SUCCESS) {
                NRF_LOG_WARNING("sd_ble_gap_authenticate() failed, errCode=0x%x\n", errCode);
                return;
            }
        }    
        break;

        case BLE_GAP_EVT_DISCONNECTED:
            if (fstorageGetState() == FSTORAGE_STATE_ERASED) {
                fstorageWaitUpdateRecordFinish();
            }
            NRF_LOG_INFO("Disconnected.");
            BLE_UART_SetState(BLE_NUS_STATE_DISCONNECT);
            m_cur_conn_handle = BLE_CONN_HANDLE_INVALID;
            break;

        case BLE_GAP_EVT_SEC_PARAMS_REQUEST:
            NRF_LOG_INFO("BLE_GAP_EVT_SEC_PARAMS_REQUEST\n");
            ble_gap_sec_params_t secParam;
            securityParametersGet(&secParam);
            errCode = sd_ble_gap_sec_params_reply(m_cur_conn_handle,
                                                  BLE_GAP_SEC_STATUS_SUCCESS,
                                                  &secParam,
                                                  NULL);
            if (errCode != NRF_SUCCESS) {
                NRF_LOG_WARNING("sd_ble_gap_sec_params_reply() failed, errCode=0x%x\n", errCode);
                return;
            }
            break;

        case BLE_GAP_EVT_AUTH_STATUS:
            NRF_LOG_INFO("BLE_GAP_EVT_AUTH_STATUS\n");
            if (pBleEvt->evt.gap_evt.params.auth_status.auth_status != BLE_GAP_SEC_STATUS_SUCCESS) {
                errCode = sd_ble_gap_disconnect(m_cur_conn_handle,
                                                BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
                if (errCode != NRF_SUCCESS) {
                    NRF_LOG_WARNING("sd_ble_gap_disconnect() failed, errCode=0x%x\n", errCode);
                    return;
                }
            }    
            break;

        default:
            // No implementation needed.
            break;
    }
}

log messages:

 0> <info> app: Version 1.0.0
 0>
 0> <info> app: ========| flash info |========
 0> <info> app: erase unit:   4096 bytes
 0> <info> app: program unit: 4 bytes
 0> <info> app: end address: 0x7FFFF
 0> <info> app: ==============================
 0> <info> app_timer: RTC: initialized.
 0> <debug> app: NOR_DATA_PERIOD=819
 0>
 0> <debug> app: NOR_RECORD_PERIOD=8192
 0>
 0> <info> app: bsp_button_longkey_handler 0.
 0> <warning> app: Battery volage 495mV is too low
 0>
 0> <warning> app: Battery volage 93mV is too low
 0>
 0> <warning> app: Battery volage 8mV is too low
 0>
 0> <warning> app: Battery volage 0mV is too low
 0>
 0> <debug> app: Battery volage 4058mV
 0>
 0> <info> app: POWER_ON.
 0> <info> app: External devices initializing start
 0> <info> app: External devices initializing finish
 0> <info> app: bsp_button_longkey_handler 1.
 0> <debug> nrf_ble_gatt: Requesting to update ATT MTU to 185 bytes on connection 0x0.
 0> <info> app: Connected.
 0> <debug> app: state=1
 0>
 0> <debug> nrf_ble_gatt: ATT MTU updated to 185 bytes on connection 0x0 (response).
 0> <info> app: BLE_GAP_EVT_SEC_PARAMS_REQUEST
 0>
 0> <warning> app: sd_ble_gap_sec_params_reply() failed, errCode=0x8
 0>
 0> <info> app: Connection secured: role: 1, conn_handle: 0x0, procedure: 2.
 0> <info> app: BLE_GAP_EVT_AUTH_STATUS

Parents
  • Hello,

    Error 0x08 means NRF_ERROR_INVALID_STATE, meaning that the other device has not requested a 6-digit passkey at this point in time, which is correct. 

    When two devices pair using a 6-digit passkey, one of the devices will provide/display this code, while the other device should enter what is provided/displayed. 

    If you didn't change anything in the file security_dispatcher.c (you should not change anything there), then you don't need to do anything else in the BLE_GAP_EVT_SEC_PARAMS_REQUEST event.

    One example that uses 6-digit passkeys (but not static) is the ble_app_gls example. You can see there that it doesn't do anything in the BLE_GAP_EVT_SEC_PARAMS_REQUEST event, other than printing something to the log.

    You can however, try to add the BLE_GAP_EVT_PASSKEY_DISPLAY event, and see if that triggers. Look at the implementation from ble_evt_handler in the ble_app_gls example.

    BR,

    Edvin

  • Thanks for your suggestion! I didn't change anything in the file security_dispatcher.c. And I have removed handling for BLE_GAP_EVT_SEC_PARAMS_REQUEST event.


    static void ble_evt_handler(ble_evt_t const* pBleEvt, void* pContext)
    {
        switch (pBleEvt->header.evt_id)
        {
            case BLE_GAP_EVT_SEC_PARAMS_REQUEST:
            {
                NRF_LOG_INFO("BLE_GAP_EVT_SEC_PARAMS_REQUEST\n");
            }
            break;
            ...
        }
    }

    log messages:
     0> <info> app: POWER_ON.
     0> <info> app: External devices initializing start
     0> <info> app: External devices initializing finish
     0> <info> app: bsp_button_longkey_handler 1.
     0> <debug> nrf_ble_gatt: Requesting to update ATT MTU to 185 bytes on connection 0x0.
     0> <info> app: Connected.
     0> <debug> app: state=1
     0>
     0> <debug> nrf_ble_gatt: ATT MTU updated to 185 bytes on connection 0x0 (response).
     0> <info> app: BLE_GAP_EVT_SEC_PARAMS_REQUEST
     0>
     0> <info> app: Connection secured: role: 1, conn_handle: 0x0, procedure: 2.
     0> <info> app: BLE_GAP_EVT_AUTH_STATUS
     0>

  • Good stuff,

    When you see the line "Connection secured: role: 1, conn_handle: 0x0, procedure: 2." which is printed from the event PM_EVT_CONN_SEC_SUCCEEDED in peer_manager_handler.c, it means that the link is encrypted. Role 1 means that peripheral, conn_handle is just the connection handle that is encrypted (only relevant if you have several concurrent connections), and procedure:2 means pairing. 

    Best regards,

    Edvin

Reply
  • Good stuff,

    When you see the line "Connection secured: role: 1, conn_handle: 0x0, procedure: 2." which is printed from the event PM_EVT_CONN_SEC_SUCCEEDED in peer_manager_handler.c, it means that the link is encrypted. Role 1 means that peripheral, conn_handle is just the connection handle that is encrypted (only relevant if you have several concurrent connections), and procedure:2 means pairing. 

    Best regards,

    Edvin

Children
No Data
Related