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

NRF_ERROR_INVALID_STATE received in response to BLE_GAP_EVT_SEC_INFO_REQUEST

Hi,

From the documentation for the sd_ble_gap_sec_info_reply() function, "This function is only used to reply to a BLE_GAP_EVT_SEC_INFO_REQUEST, calling it at other times will result in NRF_ERROR_INVALID_STATE."

Yet I get this when using the bond manager with SD 6.0 and SDK 5.2.

The bonded central has been saved successfully and when attempting to reconnect to the saved bonded central, I get the error in the function below

static void on_sec_info_request(ble_evt_t * p_ble_evt) { uint32_t err_code;

err_code = central_find_in_db(p_ble_evt->evt.gap_evt.params.sec_info_request.div);
if (err_code == NRF_SUCCESS)
{
    // Bond information has been found and loaded for security procedures. Reflect this in the
    // status variable
    m_bond_loaded = true;

    // Central found in the list of bonded central. Use the encryption info for this central.
    err_code = sd_ble_gap_sec_info_reply(m_conn_handle,
                                         &m_central.bond.auth_status.periph_keys.enc_info,
                                         NULL);
    if (err_code != NRF_SUCCESS)
    {
        m_bondmngr_config.error_handler(err_code);
    }

    // Do not set the sys_attr yet, should be set only when sec_update is successful.
}
else if (err_code == NRF_ERROR_NOT_FOUND)
{
    m_central.bond.central_id_info = p_ble_evt->evt.gap_evt.params.sec_info_request;

    // New central.
    err_code = sd_ble_gap_sec_info_reply(m_conn_handle, NULL, NULL);
    if (err_code != NRF_SUCCESS)
    {
        m_bondmngr_config.error_handler(err_code); <<--- err_code here is NRF_ERROR_INVALID_STATE or 8
    }
  • Hi David,

    From your comment in your code, it looks like the error code is thrown from the code piece that handles 'new central' (the code under else if (err_code == NRF_ERROR_NOT_FOUND)).

    Nevertheless, if the bond manager code was used 'as is', the function sd_ble_gap_sec_info_reply can never return that error code even for a 'new central'. Has the bond manager code been altered to suit your needs? Could you also double check (after disabling compiler optimizations, if any) if it is indeed that code line getting hit?

    Cheers, Balaji

  • No, the bond manager code has not been altered and there are no compiler optimizations. I've checked it multiple times and yes, the call sd_ble_gap_sec_info_reply() was made with a error result in the err_code == NRF_SUCCESS portion. (Above code comment was in the wrong location)

    The main application code was based on the ancs example. I disabled all the code pertaining to ANCS so that I could focus on the bond manager stuff.

    When the bond is set up for the first time, things go well.

    The problem only manifests itself when the central attempts to re-connect with the peripheral.

  • Hi David,

    It is a bit hard to understand what is going wrong here. It may help to have a look at your code (the changes you did to the ANCS app). So please raise a support case on this. If it is okay with you, you can share your code modifications in the support case. But before that could you please check if you have the same issue with other SDK applications that implement bonding? Eg) Proximity application? Also was this re-connect scenario working with the ANCS application before you started changing it?

    Cheers, Balaji

Related