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

Creating Whitelist with PM on Manually added peer (ERROR 0x12802 BLE_ERROR_GAP_INVALID_BLE_ADDR)

Hello,

I have the following problem. I want to create a whitelist using the PM on a manually added peer. 

I manually add a peer by adding its GAP address. 

ret_code_t peer_manager_add_new_peer(pm_peer_id_t *p_new_peer_id, ble_gap_addr_t *p_target_central_addr)
{
    ret_code_t err_code;
    
    pm_peer_data_bonding_t  new_peer_bonding_data;

    memset(&new_peer_bonding_data,0,sizeof(new_peer_bonding_data));
    new_peer_bonding_data.own_role = BLE_GAP_ROLE_PERIPH;
    new_peer_bonding_data.peer_ble_id.id_addr_info = *p_target_central_addr;    

    err_code = pm_peer_new(p_new_peer_id,&new_peer_bonding_data,NULL);
    return err_code;
}

Then I try to whitelist this peer with the following routine:

ret_code_t peer_manager_whitelist_set(void)
{
    ret_code_t err_code;

    // Fetch a list of peer IDs from Peer Manager and whitelist them.
    pm_peer_id_t peer_ids[8] = {PM_PEER_ID_INVALID};
    uint32_t     n_peer_ids  = 0;    
    pm_peer_id_t peer_id     = pm_next_peer_id_get(PM_PEER_ID_INVALID);
    while((peer_id != PM_PEER_ID_INVALID) && (n_peer_ids < 8))
    {
        peer_ids[n_peer_ids++] = peer_id;
        peer_id = pm_next_peer_id_get(peer_id);
    }
    // Whitelist peers.
    err_code = pm_whitelist_set(peer_ids, n_peer_ids);
    APP_ERROR_CHECK(err_code);

    return err_code;
}

But what I get is error 0x12802 - BLE_ERROR_GAP_INVALID_BLE_ADDR

Looking into the ID manager when the record for the added peer is read from Flash, it comes back completely wrong. The address is wrong and most importantly the address type.

What am I doing wrong? Is the manual addition of the peer with only its address wrong?

Thank you for your help

  • Hi, 

    Could you provide what you have in the p_target_central_addr ? How do you configure the address ? 

    Could you put some log inside the pm_peer_new() to check how the address is stored ? 

    What do you see when you read the peer's address out ?

    Do you have the number of peers fetched correctly ? 

  • Hello Hung, 

    Thanks for coming back. I am out of office. I will reply when back. 

    Thank you

  • Hello Hung,

    Sorry for the late reply. I am back in office now. 

    To your questions:

    Could you provide what you have in the p_target_central_addr ? How do you configure the address ? 

    This is done by an initialized ble_gap_addr_t variable. This will be changing based on what peer I would like to add in PM list. Check Initialization below.

    //Address structure of peer
    ble_gap_addr_t m_target_central_addr =
    {
        /* Possible values for addr_type:
           BLE_GAP_ADDR_TYPE_PUBLIC,
           BLE_GAP_ADDR_TYPE_RANDOM_STATIC,
           BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE,
           BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_NON_RESOLVABLE. */
        .addr_type = BLE_GAP_ADDR_TYPE_RANDOM_STATIC,
        .addr      = {0x08, 0x59, 0x29, 0x3a, 0xa3, 0xdd}
    };

    Could you put some log inside the pm_peer_new() to check how the address is stored ? 

    What exactly do you want to see? Where in the pm_peer_new() do you want the log?

    What do you see when you read the peer's address out ?

    The problem occurs inside the peers_id_keys_get() routine.

    I manage to reach the pds_peer_data_read() where data is read from flash for the first peer

    This is what is read out:

    the p_bonding_data are wrong. 

    Especially the addr_id_peer is 0x01 and add_type is 0x7F. Obviously the entire addr is wrong as well.

    The code fails in the following lines:

    uint8_t const addr_type = bond_data.peer_ble_id.id_addr_info.addr_type;

    if ((addr_type != BLE_GAP_ADDR_TYPE_PUBLIC) &&
    (addr_type != BLE_GAP_ADDR_TYPE_RANDOM_STATIC))
    {
    // The address shared by the peer during bonding can't be used for whitelisting.
    return BLE_ERROR_GAP_INVALID_BLE_ADDR;
    }

     

    Do you have the number of peers fetched correctly ?

    Yes. I am using pm_peer_count() and it returns 1

    Also I am using:

    ret_code = pm_peer_id_list(peer_ids,&peer_list_size,PM_PEER_ID_INVALID,PM_PEER_ID_LIST_ALL_ID );
    APP_ERROR_CHECK(ret_code);

    which return peer_list_size = 1 and peer_ids = 0x0000 for 1 peer

    Thank you for your help.

  • Hi Vasileios, 

    What I want to printout log or debug inside pm_peer_new() is to check until pds_peer_data_store() call, if all the information is correct. 

    You can also check in the flash if the correct address has been stored in flash. The peer manager should store the data at the top end of the flash (depends on the

    FDS_PHY_PAGES).

    If you check the flash and can find the expected address, then the problem could be with how we read the address out. 

    We have the ble_app_keyboard uses whitelist. You can use it as a reference. In that example we call pm_peer_id_list() with PM_PEER_ID_LIST_SKIP_NO_ID_ADDR skip. 

    You can step into the code of pm_peer_id_list and check which data you have after the call pds_peer_data_read(). 

  • Hello Hung,

    i added the following NRF_LOG_INFO just before pds_peer_data_store()

     NRF_LOG_INFO("Peer Data ID: %x",peer_data.data_id);
        NRF_LOG_INFO("Peer Data Length Words: %d",peer_data.length_words);
        NRF_LOG_INFO("Peer Bonding Data -> address id_peer: %x",peer_data.p_bonding_data->peer_ble_id.id_addr_info.addr_id_peer);
        NRF_LOG_INFO("Peer Bonding Data -> address type: %x",peer_data.p_bonding_data->peer_ble_id.id_addr_info.addr_type);
        
        NRF_LOG_INFO("Peer Bonding Data -> address[0] : %x",peer_data.p_bonding_data->peer_ble_id.id_addr_info.addr[0]);
        NRF_LOG_INFO("Peer Bonding Data -> address[1] : %x",peer_data.p_bonding_data->peer_ble_id.id_addr_info.addr[1]);
        NRF_LOG_INFO("Peer Bonding Data -> address[2] : %x",peer_data.p_bonding_data->peer_ble_id.id_addr_info.addr[2]);
        NRF_LOG_INFO("Peer Bonding Data -> address[3] : %x",peer_data.p_bonding_data->peer_ble_id.id_addr_info.addr[3]);
        NRF_LOG_INFO("Peer Bonding Data -> address[4] : %x",peer_data.p_bonding_data->peer_ble_id.id_addr_info.addr[4]);
        NRF_LOG_INFO("Peer Bonding Data -> address[5] : %x",peer_data.p_bonding_data->peer_ble_id.id_addr_info.addr[5]);
        

    The resulting LOG is:

    So it seems that the data is correct right before flash write. 

    I starting to suspect that it has to do with the Flash memory allocation. 

    I am using fstorage to store other application data and have reserved space for the bootloader and 8kbyte for application data. 

    Where exactly does the fds start to place data in flash? I am trying to locate it.

    Thanks.

Related