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

Invalid whitelist created by peer manager in SDK11

Hi

I've implemented a peripheral with bonding support by the peer manager. Additionally the device should scan for bonded devices by using a whitelist. I used the function pm_whitelist_create to create the whitelist. The function succeeds but the scan doesn't find what I expected.

The first thing I had to find out is, that the function pm_whitelist_create (or better the called im_whitelist_create) doesn't include connected peers in the list. A note in the description to this function would have helped me here.

After this another unexpected behavior showed up. Lets say we have three bonded peers. If no peer is connected all three peers are added to the whitelist. If peer 0 is connected the whitelist will contain the addresses of peer 0 and 1 instead of the addresses of peer 1 and 2. The bug that causes this can be found in the function im_whitelist_create.

I've added comments in the code snipped for the two lines that need to be corrected:

            if (p_whitelist->pp_addrs != NULL &&
            peer_data.p_bonding_data->peer_id.id_addr_info.addr_type
                    != BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE &&
            peer_data.p_bonding_data->peer_id.id_addr_info.addr_type
                    != BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_NON_RESOLVABLE
        )
        {
            memcpy(m_im.whitelist_addrs[peer_index].addr,
                peer_data.p_bonding_data->peer_id.id_addr_info.addr,
                BLE_GAP_ADDR_LEN
            );
            m_im.whitelist_addrs[peer_index].addr_type =
                peer_data.p_bonding_data->peer_id.id_addr_info.addr_type;

            // ERROR: invalid array index! The pp_addrs array index should be "p_whitelist->addr_count" instead of "peer_index"
            p_whitelist->pp_addrs[peer_index] = &m_im.whitelist_addrs[peer_index];

            p_whitelist->addr_count++;
        }
        if (p_whitelist->pp_irks != NULL &&
            is_valid_irk(&(peer_data.p_bonding_data->peer_id.id_info))
        )
        {
            memcpy(m_im.whitelist_irks[peer_index].irk,
                peer_data.p_bonding_data->peer_id.id_info.irk,
                BLE_GAP_SEC_KEY_LEN
            );


            // ERROR: invalid array index! The pp_irks array index should be "p_whitelist->irk_count" instead of "peer_index"
            p_whitelist->pp_irks[peer_index] = &m_im.whitelist_irks[peer_index];


            p_whitelist->irk_count++;
            m_im.irk_whitelist_peer_ids[peer_index] = p_peer_ids[peer_index];
            m_im.n_irk_whitelist_peer_ids++;
        }

After fixing the two invalid array indices the function works as expected.

Regards Adrian

Related