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

Return error by “pm_device_identities_list_set”

52832 & s112 & sd6.0 & sdk15.0

If you have multiple pairings on the same host will return error by “pm_device_identities_list_set”

err_code = BLE_ERROR_GAP_DEVICE_IDENTITIES_DUPLICATE.

if I ignore this error seems no issue.

pm_conn_sec_config_t conn_sec_config = {.allow_repairing = true};  

  case PM_EVT_PEER_DATA_UPDATE_SUCCEEDED:
        {
            if (     p_evt->params.peer_data_update_succeeded.flash_changed
                 && (p_evt->params.peer_data_update_succeeded.data_id == PM_PEER_DATA_ID_BONDING))
            {
                NRF_LOG_INFO("New Bond, add the peer to the whitelist if possible");
                NRF_LOG_INFO("\tm_whitelist_peer_cnt %d, MAX_PEERS_WLIST %d",
                               m_whitelist_peer_cnt + 1,
                               BLE_GAP_WHITELIST_ADDR_MAX_COUNT);
               // Note: You should check on what kind of white list policy your application should use.

                if (m_whitelist_peer_cnt < BLE_GAP_WHITELIST_ADDR_MAX_COUNT)
                {
                    // Bonded to a new peer, add it to the whitelist.
                    m_whitelist_peers[m_whitelist_peer_cnt++] = m_peer_id;
                                                                                NRF_LOG_INFO(" new peer ID %d", m_peer_id);
                                                                                
                    // The whitelist has been modified, update it in the Peer Manager.
                    err_code = pm_whitelist_set(m_whitelist_peers, m_whitelist_peer_cnt);
                    APP_ERROR_CHECK(err_code);

                    err_code = pm_device_identities_list_set(m_whitelist_peers, m_whitelist_peer_cnt);
                    if (err_code != NRF_ERROR_NOT_SUPPORTED)
                    {
                        APP_ERROR_CHECK(err_code);
                    }
                }
            }
        } break;

  • Hi Tom,

    This error is actually from the softdevice:
    http://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.s112.api.v6.0.0%2Fgroup___b_l_e___g_a_p___f_u_n_c_t_i_o_n_s.html&anchor=ga16fa7a0ac608c4955a2e4feea7a10784 

    To avoid the error I suggest you add a check that the m_peer_id you want to add doesn't already exist in m_whitelist_peers[] before calling:

    m_whitelist_peers[m_whitelist_peer_cnt++] = m_peer_id; 

    Likely it is not a problem to ignore the BLE_ERROR_GAP_DEVICE_IDENTITIES_DUPLICATE, but I think it is better to have a check.

  • Hi Hung, 

    I am base on SDK example code ,  In fact the parameter {.allow_repairing  = false} is default;  If I twice pairing on same host that will reject pairing but this is no allow in my case . if i change {.allow_repairing = true} then repairing is ok  that whitelist_peers will add a same peer id ,so "pm_device_identities_list_set " return error .  System will remove pervious peer id when reset. 

     // Setup the device identies list.
     // Some SoftDevices do not support this feature.
     ret = pm_device_identities_list_set(m_whitelist_peers, m_whitelist_peer_cnt);

    You see , Some SoftDevices do not support this feature, so if i mask it will  have any risk ? or how to fix it?

  • You are right, the issue can be seen with the stock example if changing allow_repairing  = true. 

     

    That's why we suggested to do a check before this call m_whitelist_peers[m_whitelist_peer_cnt++] = m_peer_id; in PM_EVT_PEER_DATA_UPDATE_SUCCEEDED, to see if the m_peer_id isn't already exist in the list. This way, we avoid duplicate peer identity to be sent to pm_device_identities_list_set(). 

  • uint16_t conn_handle;
    					
    pm_conn_handle_get(m_peer_id, &conn_handle);
    						
    if(conn_handle == BLE_CONN_HANDLE_INVALID)
    {
    	// Bonded to a new peer, add it to the whitelist.
    	m_whitelist_peers[m_whitelist_peer_cnt++] = m_peer_id;
    	NRF_LOG_INFO(" new peer ID %d", m_peer_id);
    						
    	// The whitelist has been modified, update it in the Peer Manager.
    	err_code = pm_whitelist_set(m_whitelist_peers, m_whitelist_peer_cnt);
    	APP_ERROR_CHECK(err_code);
    
    	err_code = pm_device_identities_list_set(m_whitelist_peers, m_whitelist_peer_cnt);
    	if (err_code != NRF_ERROR_NOT_SUPPORTED)
    	{
    		APP_ERROR_CHECK(err_code);
    	}
    }

    Is this code right?

  • No, I don't think so. 

    The check I suggest is to have a loop to go through m_whitelist_peers[] array to check if there is any element inside that array is equal to m_peer_id. If not then you add it as a new node into to the array. Something like this: 

    already_added= false;
    
    for (uint8_t i = 0; i<m_whitelist_peer_cnt;i++)
    
    {
    
        if (m_whitelist_peers[i] = m_peer_id)
        {
            already_added= true;
            break;
        }
    }
            
    if (!already_added)
    {
       m_whitelist_peers[m_whitelist_peer_cnt++] = m_peer_id;
       err_code= pm_whitelist...
             

        

Related