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

NRF_ERROR_INVALID_STATE when calling dm_security_setup_req

Hi,

I am getting the NRF_ERROR_INVALID_STATE error when I call dm_security_setup_req in my security timer timeout handler. The function's description says I'll get this error "In case API is called without module initialization and/or application registration."

What exactly does this mean? What module hasn't been initialized yet? I recently refactored the ble_app_template example code.

Here is my security timer timeout handler:

static void sec_req_timeout_handler(void * p_peer_handle)
{
    uint32_t             err_code;
    dm_security_status_t status;

    if (((dm_handle_t *)p_peer_handle)->connection_id != DM_INVALID_ID)
    {
        err_code = dm_security_status_req((dm_handle_t *)p_peer_handle, &status);
        APP_ERROR_CHECK(err_code);

        // If the link is still not secured by the peer, initiate security procedure.
        if (status == NOT_ENCRYPTED)
        {
            err_code = dm_security_setup_req((dm_handle_t *)p_peer_handle);
            APP_ERROR_CHECK(err_code);    <--ERROR CODE 0x8 HERE
        }
    }
}

Here is the code that starts the timer:

void security_timer_start(dm_handle_t * p_peer_handle) {
  uint32_t err_code;
  err_code = app_timer_start(m_sec_req_timer_id, SECURITY_REQUEST_DELAY, p_peer_handle);
  APP_ERROR_CHECK(err_code);
}

static uint32_t device_manager_evt_handler(dm_handle_t const *p_handle,
    dm_event_t const *p_event,
    ret_code_t event_result) {

    APP_ERROR_CHECK(event_result);
    switch (p_event->event_id)
    {
        case DM_EVT_CONNECTION:
            m_peer_handle = (*p_handle);
            security_timer_start(&m_peer_handle);
            break;

        default:
            // No implementation needed.
            break;
    }

  return NRF_SUCCESS;
}

Thanks!

EDIT: I am properly initializing the device manager in my main method as given in the example code. Using a debugger I also confirmed that dm_init and dm_register both return NRF_SUCCESS before I get this error.

Parents Reply Children
No Data
Related