how to bonding BLE in 52832?

I try to bonding func using ble_app_gls example.

just connect is fine.

here is ble_evt handler

for trying connect bonding, I use pm_handler_secure_on_connection(p_ble_evt)

but here is occur error : pm_conn_secure() failed because conn_handle 0 is not a valid connection.

I check conn_state using ble_conn_state_status()

example is fine.

but my code, first event is return invalid, after second the state change connected.

Could you give me advice?

ps) If you know more better example for bonding, please attach url or doc.

static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
{
    ret_code_t err_code;

    ble_conn_state_status_t st;
    pm_handler_secure_on_connection(p_ble_evt);

    st = ble_conn_state_status(p_ble_evt->evt.gap_evt.conn_handle);
    NRF_LOG_INFO("CONNECT STATE = %x\n", st);

    if(p_ble_evt->header.evt_id == BLE_GAP_EVT_CONNECTED)
      pm_handler_secure_on_connection(p_ble_evt);
    

    switch (p_ble_evt->header.evt_id)
    {
        case BLE_GAP_EVT_CONNECTED:  

            NRF_LOG_INFO("BLE_GAP_EVT_CONNECTED\n");

            bsp_board_led_off(BSP_BOARD_LED_2);
            bsp_board_led_on(BSP_BOARD_LED_1);
            
            peer_id = PM_PEER_ID_INVALID;

            m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;

            err_code = nrf_ble_qwr_conn_handle_assign(&m_qwr, m_conn_handle);
            APP_ERROR_CHECK(err_code);           
            break;

Related