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

Proof of Concept with Pre-Bonded LTK (2)

I learned from the following support ticket link that for adding a pre-bonded LTK to the nRF52 bonding store, I can call pm_peer_new().

https://devzone.nordicsemi.com/f/nordic-q-a/47110/proof-of-concept-with-pre-bonded-ltk

I tried to do this at the end of pm_init(), but I get a system reset while calling pm_peer_new(). The system reset is happening somewhere around write_execute() in nrf_fstorage_sd.c:208. I don't know what the problem is. Obviously writing to the flash fails for some reason?

Below is my code that I inserted at the end of pm_init() from ble_app_bms.

  • Could someone please have a look at it and maybe give me a hint what could be wrong here?
  • How can I add a static bond/LTK to this example application?

    m_peer_rank_initialized = false;
    m_module_initialized    = true;

    // --> CODE INSERT BEGIN!
    // (From here on, this is code that is added to original pm_init() of Nordic ble_app_bms example)
    pm_peer_id_t peer_id;
    
    const ble_gap_id_key_t m_peer_ble_id = {
        .id_info ={
                .irk = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},},
        .id_addr_info = {
            .addr_type = BLE_GAP_ADDR_TYPE_RANDOM_STATIC,
            .addr = {0xC2, 0xDA, 0xB2, 0x78, 0xAE, 0xEA},}
    };
    const ble_gap_enc_key_t m_own_ltk = {
        .enc_info ={
            .ltk = {0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11},
            .lesc = 0x00,
            .auth = 0x00,
            .ltk_len = 0x10,
        },
        .master_id = {
            .ediv = 0xCB76,
            .rand = {0xC9,0x01,0x64,0xD4,0x30,0xC4,0x17,0x25},
        }
    };
          
    pm_peer_data_bonding_t peer_bonding_data;
    
    // Check if peer ID is already present in the bonding store
    peer_id = im_peer_id_get_by_master_id(&(m_own_ltk.master_id));
    if (peer_id == PM_PEER_ID_INVALID)
    {    
        // Add new peer to the bonding store
        peer_bonding_data.own_role = BLE_GAP_ROLE_PERIPH;
        peer_bonding_data.peer_ble_id = m_peer_ble_id;
        peer_bonding_data.own_ltk = m_own_ltk;
        
        err_code = pm_peer_new(&peer_id,&peer_bonding_data,NULL);
        APP_ERROR_CHECK(err_code);
        
        err_code = pm_peer_data_bonding_store(peer_id,&peer_bonding_data,NULL);
        APP_ERROR_CHECK(err_code);
    }  
    // --> CODE INSERT END!
    
    return NRF_SUCCESS;
}

Parents Reply Children
No Data
Related