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

after bonding, when try reconnect, Failed to authenticate happen. how can I fix?

I try to bonding.

Using SDK 15.3. 0 and S332 Softdevice.

I successed bonding procedure used Peer manager.

after bonding, If I try to connect one more, nRF Connect app show Failed to authenticate (NRF_ERROR_INVALID_STATE).

however connection is still working.

1. If I use Peer Managere Module, which ble_gat_evt don't need to reply?(where is it in document that Info)

2.  

that is log.

<00> info> app: SoftDevice init END
00> 
<00> info> app: Timer INIT done
00> 
<00> info> app: Timer START done
00> 
<00> info> app: GAP PARAM INIT END
00> 
<00> info> app: GATT INIT END
00> 
<00> info> app: BLE ADVERTISING INIT END
00> 
<00> info> app: SERVICE INIT END
00> 
<00> info> app: CONN PARAM INIT END
00> 
<00> info> app: PEER MANAGER INIT END
00> 
<00> info> peer_manager_handler: All peers deleted.
<00> info> app: PM_EVT_PEERS_DELETE_SUCCEEDED 
00> 
<00> info> app: BLE_ADV_EVT_FAST
00> 
<00> info> app: BLE ADVERTISING START
00> 
<00> info> app: PEER DELETE END
00> 
<00> info> app: INIT SET END
00> 
<00> info> app: BLE_GAP_EVT_CONNECTED
00> 
<00> info> app: DEFUALT 13
00> 
<00> info> app: PM_EVT_CONN_SEC_START 
00> 
<00> info> app: PM_EVT_CONN_SEC_PARAMS_REQ 
00> 
<00> info> app: BLE_GAP_EVT_CONN_SEC_UPDATE   
00> 
<00> info> app: DEFUALT 19
00> 
<00> info> peer_manager_handler: Connection secured: role: Peripheral, conn_handle: 0, procedure: Bonding
<00> info> app: PM_EVT_CONN_SEC_SUCCEEDED 
00> 
<00> info> app: PM_EVT_PEER_DATA_UPDATE_SUCCEEDED 
00> 
<00> info> app: PM_EVT_PEER_DATA_UPDATE_SUCCEEDED 
00> 
<00> info> app: PM_EVT_PEER_DATA_UPDATE_SUCCEEDED 
00> 
<00> info> app: DEFUALT 35
00> 
<00> info> app: DEFUALT 36
00> 
<00> info> app: PM_EVT_PEER_DATA_UPDATE_SUCCEEDED 
00> 
<00> info> app: BLE_GAP_EVT_DISCONNECTED
00> 
<00> info> app: BLE_ADV_EVT_FAST
00> 
<00> info> app: BLE ADVERTISING START
00> 
<00> info> app: BLE_GAP_EVT_CONNECTED
00> 
<00> info> app: PM_EVT_CONN_SEC_PARAMS_REQ 
00> 
<00> info> app: PM_EVT_PEER_DATA_UPDATE_SUCCEEDED 
00> 
<00> info> app: PM_EVT_BONDED_PEER_CONNECTED 
00> 
<00> info> app: PM_EVT_LOCAL_DB_CACHE_APPLIED 
00> 
<00> info> app: BLE_GAP_EVT_SEC_INFO_REQUEST
00> 
<00> info> app: PM_EVT_CONN_SEC_START 
00> 
<00> warning> peer_manager_smd: sd_ble_gap_sec_info_reply() returned NRF_EROR_INVALID_STATE, which is anerror unless the link is disconnecting.
<00> info> app: BLE_GAP_EVT_CONN_SEC_UPDATE   
00> 
<00> info> peer_manager_handler: Connection secured: role: Peripheral, conn_handle: 0, procedure: Encryption
<00> info> app: PM_EVT_PEER_DATA_UPDATE_SUCCEEDED 
00> 
<00> info> app: PM_EVT_CONN_SEC_SUCCEEDED 
00> 

I think 

BLE_GAP_EVT_SEC_INFO_REQUEST is occurred my code is

 case BLE_GAP_EVT_SEC_INFO_REQUEST:
            NRF_LOG_INFO("BLE_GAP_EVT_SEC_INFO_REQUEST\n");

            pm_peer_id_t peer_id;
            err_code = pm_peer_id_get(p_ble_evt->evt.gap_evt.conn_handle, &peer_id);
            APP_ERROR_CHECK(err_code);

            pm_peer_data_bonding_t bonding_data;
            err_code = pm_peer_data_bonding_load(peer_id, &bonding_data);
            APP_ERROR_CHECK(err_code);

            err_code = sd_ble_gap_sec_info_reply(p_ble_evt->evt.gap_evt.conn_handle, &bonding_data.own_ltk.enc_info, &bonding_data.peer_ble_id.id_info, NULL);
            APP_ERROR_CHECK(err_code);
            break;

I load data and reply sd_ble_gap_sec_info_reply.

Don't I need reply that?

Thank you in advance.

 

  • Hello,

    There are several handlers that handles the different SoftDevice events. One of them is smd_ble_evt_handler() in security_dispatcher.c. This one calls:

    sec_info_request_process() in the BLE_GAP_EVT_SEC_INFO_REQUEST event. This function will also call:

    sd_ble_gap_sec_info_reply(), and print:

            NRF_LOG_WARNING("sd_ble_gap_sec_info_reply() returned NRF_EROR_INVALID_STATE, which is an"\
                            "error unless the link is disconnecting.");

    if it returns NRF_ERROR_INVALID_STATE.

    My guess is that since it is called twice (once where you implemented it, and once in the security_dispatcher.c), one of them will return NRF_ERROR_INVALID_STATE.

    What happens if you remove your call to sd_ble_gap_sec_info_reply()?

  • if remove, sd_ble_gap_sec_info_reply error log is removed , but nRF Connect still occurred same error

  • 2047.log.pcapng

    using Sniffer , upload file.

    after reconnect, it shows Encrypted packet decrypted incorrectly.

    one more question. 

    in file log, 

    No.4000, Sent Pairing Request part,

    on Initiator key Distribution,

    Why Id Key(IRK) is false?

    I set only bonding, not use LESC , etc..

    static void peer_manager_init()
    {    
        ret_code_t  err_code;
    
        err_code = pm_init();
        APP_ERROR_CHECK(err_code);
        //memset(&whitelist, PM_PEER_ID_INVALID, sizeof(whitelist));
        memset(&sec_param, 0, sizeof(sec_param));
    
        // Security parameters to be used for all security procedures.
        sec_param.bond           = SEC_PARAM_BOND;
        sec_param.mitm           = SEC_PARAM_MITM;
        sec_param.lesc           = SEC_PARAM_LESC;
        sec_param.keypress       = SEC_PARAM_KEYPRESS;
        sec_param.io_caps        = SEC_PARAM_IO_CAPABILITIES;
        sec_param.oob            = SEC_PARAM_OOB;
        sec_param.min_key_size   = SEC_PARAM_MIN_KEY_SIZE;
        sec_param.max_key_size   = SEC_PARAM_MAX_KEY_SIZE;
        sec_param.kdist_own.enc  = 1;
        sec_param.kdist_own.id   = 1;
        sec_param.kdist_peer.enc = 1;
        sec_param.kdist_peer.id  = 1;
    
        err_code = pm_sec_params_set(&sec_param); 
        // Until this function is called, all bonding procedures that are initiated by the peer are rejected.
        APP_ERROR_CHECK(err_code);        
    
        err_code = pm_register(pm_evt_handler);
        APP_ERROR_CHECK(err_code);
    
        NRF_LOG_INFO("PEER MANAGER INIT END\n");
    
        err_code = pm_peers_delete();
        APP_ERROR_CHECK(err_code);
        
        NRF_LOG_INFO("PEER DELETE END\n");
    }

    I set 

    sec_param.kdist_own.id = 1;
    sec_param.kdist_peer.id = 1;

    is it not set about irk?

    Thank you

  •         case PM_EVT_CONN_SEC_CONFIG_REQ:
            {
                pm_conn_sec_config_t conn_sec_config = {.allow_repairing = true};
                pm_conn_sec_config_reply(p_evt->conn_handle, &conn_sec_config);
            } break;

    Does that allow the device to pair again?

    BR,
    Edvin

  • I didn't allow that. after changed to allow, error is still occurred

Related