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

sd_ble_gap_sec_params_reply() returns NRF_ERROR_INVALID_STATE

I have an nRF51822 application using the Soft Device 110. I want to perform bonding with a central without MITM protection. In my on_ble_evt() event handler, when the event ID is BLE_GAP_EVT_SEC_PARAMS_REQUEST, I reply in the same fashion as one of the example apps, like this:

        err_code = sd_ble_gap_sec_params_reply(m_conn_handle,
                                               BLE_GAP_SEC_STATUS_SUCCESS,
                                               &m_sec_params);
        APP_ERROR_CHECK(err_code);

The error_code is then 8, which is NRF_ERROR_INVALID_STATE.

The m_sec_params have earlier been set to these values:

#define SEC_PARAM_TIMEOUT                 30                                                /**< Timeout for Pairing Request or Security Request (in seconds). */
#define SEC_PARAM_BOND                    1                                                 /**< Perform bonding. */
#define SEC_PARAM_MITM                    0                                                 /**< Man In The Middle protection NOT required. */
#define SEC_PARAM_IO_CAPABILITIES         BLE_GAP_IO_CAPS_NONE                              /**< No I/O capabilities. */
#define SEC_PARAM_OOB                     0                                                 /**< Out Of Band data not available. */
#define SEC_PARAM_MIN_KEY_SIZE            7                                                 /**< Minimum encryption key size. */
#define SEC_PARAM_MAX_KEY_SIZE            16                                                /**< Maximum encryption key size. */

m_conn_handle has been set earlier on, when the BLE_GAP_EVT_CONNECTED event comes into the same handler, like this:

        m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;

I also know the connection event has happened, from my logs:

sd_app_evt_wait()
sd_app_evt_wait()
DM_EVT_CONNECTION
BLE_GAP_EVT_CONNECTED
sd_app_evt_wait()
DM_EVT_SECURITY_SETUP
BLE_GAP_EVT_SEC_PARAMS_REQUEST

How can I tell what's invalid about the state I'm in? The central is an Android app and is my code.

Parents
  • Hi Eliot,

    Carles is right that the response to BLE_GAP_EVT_SEC_PARAMS_REQUEST is handled in the device manager now and does not need to be handled in the application. And apologies that this is not documented well enough, we will try and improve this in future.

    Also, most examples in the SDK do not use MITM, only the glucose example as of today does. But to be specific, the heart rate example for both dev-kit and ev-kit do not use MITM. These could serve as reference.

    Hope this helps!

    Regards, Krishna

Reply
  • Hi Eliot,

    Carles is right that the response to BLE_GAP_EVT_SEC_PARAMS_REQUEST is handled in the device manager now and does not need to be handled in the application. And apologies that this is not documented well enough, we will try and improve this in future.

    Also, most examples in the SDK do not use MITM, only the glucose example as of today does. But to be specific, the heart rate example for both dev-kit and ev-kit do not use MITM. These could serve as reference.

    Hope this helps!

    Regards, Krishna

Children
Related