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

Bonding. Why ltk changed at every reconnection?

Hi, I have done the bonding and saving context to flash. As an example I used ble_app_template. I cutted all redundant code and limited to single bond for simplicity. In my code I save next:

 - m_connection_table (I changed it a little bit)
 - m_peer_table 
 - m_bond_table (i.e. ble_gap_enc_key_t, LTK)

At device startup I load m_peer_table to know what peer address I'm waiting to connect. Advertice Than after peer connect I load m_bond_table with presaved LTK. At BLE_GAP_EVT_SEC_PARAMS_REQUEST peer central gives:

ble_evt->evt.gap_evt.params.sec_params_request.peer_params.kdist_periph.enc   - 1
  ble_evt->evt.gap_evt.params.sec_params_request.peer_params.kdist_central.id     - 0
  ble_evt->evt.gap_evt.params.sec_params_request.peer_params.kdist_periph.sign   - 1
  ble_evt->evt.gap_evt.params.sec_params_request.peer_params.bond   - 1

My local setup is

m_sec_params.kdist_periph.enc   = 1;
m_sec_params.kdist_periph.id    = 0;
m_sec_params.kdist_periph.sign  = 0; //Not supported yet

At BLE_GAP_EVT_CONN_SEC_UPDATE Established Mode 0x01, Level 0x02 - so link is encrpted.Here I apply service context.

At BLE_GAP_EVT_AUTH_STATUS if bond successfull I save context to nonvolatile memory. But here the LTK is different whan I sent as reply to BLE_GAP_EVT_SEC_PARAMS_REQUEST.

After host disconnected I save all context similar to at BLE_GAP_EVT_AUTH_STATUS event.

As I understand LTK have to be constant for long time, so why it changes at each reconnection? It seem that I repeat bonding procedure each time at connection because I do not receive BLE_GAP_EVT_SEC_INFO_REQUEST at reconnect as stated here [https://devzone.nordicsemi.com/documentation/nrf51/4.4.0/html/group___b_o_n_d_e_d___m_a_s_t_e_r.html] or here [https://devzone.nordicsemi.com/documentation/nrf51/6.0.0/s110/html/a00824.html]

Parents
    • I tested on Win8.1 and it works, on Nexus7 doesn't. The test case was the next:
    1. bonding

    2. disconnection from host by switching off bluetooth or removing the BLE dongle.

    3. On periperal wthite list become working and after switching on bluetooth on central, it connects and in one case rebonds with new LTK, in other case using previous bond.

    When I receive BLE_GAP_EVT_DISCONNECTED the ble_evt->evt.gap_evt.params.disconnected.reason is BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION for Nexus7 and BLE_HCI_CONNECTION_TIMEOUT for Win8.1. Could this parameter be connected with described issue?


    I think I found. In Android code each time I connected the method called

    device.createBond();
    

    Now it changed to and seems to work properly, but it not always define bond status correctly(((

    if (device.getBondState() != BluetoothDevice.BOND_BONDED) {
        device.createBond();
    } 
    
  • It is a bit strange that you get BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION for the Nexus 7 if you turn off Bluetooth in settings, but I don't think this is the root of the issue. If you can, please do a sniffer trace.

Reply Children
No Data
Related