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

Peer Manager central device issue

Hello,

I am trying to implement the Peer Manager for bonding and pairing on my central device (nrf52840 Dongle) using SDK 15.3. I based my project off of the ble_app_uart_c example, which did not have peer manager capabilities, but I have added the required libraries to allow me to use it. In addition to the dongle, I am also using a nrf52832 board to act as a peripheral device.

For the code on the devices, I have essentially copied the peer_manager_init and pm_evt_handler functions from the ble_app_hrs and ble _app_hrs_c applications. When I run it, I see that the central device connects to my peripheral and discovers and connects to the NUS service. I then see that the pm_evt_handler function catches events PM_EVT_CONN_SEC_PARAMS_REQ, PM_EVT_CONN_SEC_START, and PM_EVT_SLAVE_SECURITY_REQ, after which the dongle crashes and the peripheral consequently disconnects. 

I believe that the problem lies on the dongle side because I am able to interact with the peripheral normally using the nrf Connect app. I am having a hard time debugging the issue further because the ble connection times out and changes the behavior during the debugging. Any help would be much appreciated.

Here are the relevant snippets of code from the dongle:

#define BLE_SEC_PARAM_BOND            1
#define BLE_SEC_PARAM_MITM            0
#define BLE_SEC_PARAM_LESC            1
#define BLE_SEC_PARAM_KEYPRESS        0
#define BLE_SEC_PARAM_IO_CAPS         0
#define BLE_SEC_PARAM_OOB             0
#define BLE_SEC_PARAM_MIN_KEY_SIZE    7
#define BLE_SEC_PARAM_MAX_KEY_SIZE    16
#define BLE_SEC_PARAM_KDIST_OWN_ENC   1
#define BLE_SEC_PARAM_KDIST_OWN_ID    1
#define BLE_SEC_PARAM_KDIST_PEER_ENC  1
#define BLE_SEC_PARAM_KDIST_PEER_ID   1

static void pm_evt_handler(pm_evt_t const * p_evt)
{
    pm_handler_on_pm_evt(p_evt);
    pm_handler_flash_clean(p_evt);

    NRF_LOG_INFO("Event ID: %d", p_evt->evt_id);

    switch (p_evt->evt_id)
    {
        case PM_EVT_PEERS_DELETE_SUCCEEDED:
            // Bonds are deleted. Start scanning.
            scan_start();
            break;
        
        case PM_EVT_SLAVE_SECURITY_REQ:
            NRF_LOG_INFO("Slave security req.");
            break;

        default:
            break;
    }
}

void peer_manager_init(void)
{
    ble_gap_sec_params_t sec_params;
    ret_code_t           err_code;

    err_code = pm_init();
    APP_ERROR_CHECK(err_code);
    memset(&sec_params, 0, sizeof(ble_gap_sec_params_t));

    // Security parameters to be used for peripheral security procedures.
    sec_params.bond           = BLE_SEC_PARAM_BOND;
    sec_params.mitm           = BLE_SEC_PARAM_MITM;
    sec_params.lesc           = BLE_SEC_PARAM_LESC;
    sec_params.keypress       = BLE_SEC_PARAM_KEYPRESS;
    sec_params.io_caps        = BLE_SEC_PARAM_IO_CAPS;
    sec_params.oob            = BLE_SEC_PARAM_OOB;
    sec_params.min_key_size   = BLE_SEC_PARAM_MIN_KEY_SIZE;
    sec_params.max_key_size   = BLE_SEC_PARAM_MAX_KEY_SIZE;
    sec_params.kdist_own.enc  = BLE_SEC_PARAM_KDIST_OWN_ENC;
    sec_params.kdist_own.id   = BLE_SEC_PARAM_KDIST_OWN_ID;
    sec_params.kdist_peer.enc = BLE_SEC_PARAM_KDIST_PEER_ENC;
    sec_params.kdist_peer.id  = BLE_SEC_PARAM_KDIST_PEER_ID;

    err_code = pm_sec_params_set(&sec_params);
    APP_ERROR_CHECK(err_code);

    err_code = pm_register(pm_evt_handler);
    APP_ERROR_CHECK(err_code);
}

static void idle_state_handle(void)
{
    ret_code_t err_code;
    err_code = nrf_ble_lesc_request_handler();
    APP_ERROR_CHECK(err_code);

    nrf_cli_process(&m_cli_cdc_acm);

    if (NRF_LOG_PROCESS() == false)
    {
        
        nrf_pwr_mgmt_run();
    }
}

Parents Reply Children
No Data
Related