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

peer manager whitelist trouble in central application

Hello,

I'm running a serialized application based on the SDK 10 and S130 v1 and I am in the process of porting the peer manager to the application µC.

Due to the fact, that the peer manager needs linear addressable read pointers and I am storing the peer data into an external SPI flash, I decided to port the peer_database.c module. Until now I thought it is working, because its possible to successfully bond to devices, and they are recognized as already bonded when reconnecting.

Now I try to use the peer manager to generate a whitelist for scanning with this code:

ble_gap_whitelist_t scanWhitelist;
ble_gap_addr_t* pWhitelistAddr[BLE_GAP_WHITELIST_ADDR_MAX_COUNT];
ble_gap_irk_t* pWhitelistIrk[BLE_GAP_WHITELIST_IRK_MAX_COUNT];
uint16_t peerId = PM_PEER_ID_INVALID;
    
/**< generate whitelist if not searching */
while (mode != SCANSEARCH)
{
    peerId = pm_next_peer_id_get(peerId);
    if (peerId == PM_PEER_ID_INVALID)
    {
        if (peerIdsNumber == 0)
            return;
        scanWhitelist.addr_count = BLE_GAP_WHITELIST_ADDR_MAX_COUNT;
        scanWhitelist.irk_count = BLE_GAP_WHITELIST_IRK_MAX_COUNT;
        scanWhitelist.pp_addrs = pWhitelistAddr;
        scanWhitelist.pp_irks = pWhitelistIrk;
        APP_ERROR_CHECK(pm_wlist_create(peerIds, peerIdsNumber, &scanWhitelist));
        break;
    }
    pm_peer_data_t peerData;
    peerData.length_words = sizeof(pm_peer_data_t)/4;
    APP_ERROR_CHECK(pm_peer_data_get(peerId, PM_PEER_DATA_ID_BONDING, &peerData));
    if (peerData.data.p_bonding_data->own_role == BLE_GAP_ROLE_CENTRAL)
        peerIds[peerIdsNumber++] = peerId;
}

The problem is, that the generated whitelist contains only the bonded devices, that hasn't been connected yet. As soon as a all bonded devices has been connected, the whitelist is empty. I tracked the problem down to the im_wlist_create() function. It seems that this function thinks, that these devices are still connected and therefore doesn't add them to the whitelist.

Now I am not sure if I'm using pm_wlist_create in the wrong way or if I forgot a function call or something else in the porting process. Any hints where to start searching?


Update:

I think I found the reason for this behavior. The id_manager uses some user_flag of the connection_state module to keep in touch of the actual connection state of the connected peers. But these flags are not reset when the device disconnects, so they keep their state until a new connection is made. Therefor the generated white list does not include these devices because the id manager thinks they are still connected.

In my opinion, either the corresponding flag should be cleared at a BLE_GAP_EVT_DISCONNECTED event, or the im_wlist_create() function should check the real connection state, too.

Related