This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Whitelisting with pc-ble-driver 2.0, S132, API v3

Hello,

I develop a BLE central device based on nRF52 (with the newest connectivity firmware and SoftDevice with API v3) and the pc-ble-driver in version 2.0.

Since my device has to connect only known peripherals (previously bonded) I would like to set the whitelist before starting the scanning. Unfortunately, I encountered a problem while trying to set a whitelist which has more then one device.

This is my whitelist:

ble_gap_addr_t whitelist[2];    

// Print of whitelist (after proper bonding 2 devices)
// addresses shown as uint64_t instead of uint8_t array
whitelist[0].addr_id_peer = 0
whitelist[0].addr_type    = 1
whitelist[0].addr         = C4ACA49FC99C     
whitelist[1].addr_id_peer = 0
whitelist[1].addr_type    = 1
whitelist[1].addr         = F63A11DDD999

If I set a whitelist with only one device everything works great:

 // Set the whitelist with device 0 only
 ble_gap_addr_t const * p_whitelist = &whitelist[0];
 err_code = sd_ble_gap_whitelist_set(ble_adapter, &p_whitelist, 1); 
 if (err_code == NRF_SUCCESS)
   printf("Whitelist with device 0 only set successfully.\n");
 else
   printf("Whitelist with device 0 only can not be set. Error 0x%X.\n", err_code);
 // This works fine, returns NRF_SUCCESS

 // Set the whitelist with device 1 only
 ble_gap_addr_t const * p_whitelist = &whitelist[1];
 err_code = sd_ble_gap_whitelist_set(ble_adapter, &p_whitelist, 1); 
 if (err_code == NRF_SUCCESS)
   printf("Whitelist with device 1 only set successfully.\n");
 else
   printf("Whitelist with device 1 only can not be set. Error 0x%X.\n", err_code);
 // This also works fine, returns NRF_SUCCESS

If I try to set the whitelist with both devices I get the error 0x3202 BLE_ERROR_GAP_INVALID_BLE_ADDR

 // Set the whitelist with both devices
 ble_gap_addr_t const * p_whitelist = whitelist;
 err_code = sd_ble_gap_whitelist_set(ble_adapter, &p_whitelist, 2); 
 if (err_code == NRF_SUCCESS)
   printf("Whitelist with device 1 only set successfully.\n");
 else
   printf("Whitelist with device 1 only can not be set. Error 0x%X.\n", err_code);
 // This doesn't work, returns error 0x3202

Do you have any idea, what's going on?

Best regards,

Mike

  • FormerMember
    0 FormerMember

    In whitelist, I see that both added devices have an addr_peer_id of '0', but I would assume that your devices should have different addr_peer_id's. Could you double check what their correct addr_peer_id is?

    Update March 6th, 2017: When I test the below here, there is no error code when adding the whitelist. I have tested the code with a regular BLE project, not using pc_ble_driver. Could you test your whitelist code in a regular BLE example?

    static void add_whitelist(void) 
    {
    
    uint32_t err_code;
    
    ble_gap_addr_t  const *  whitelist[2];
    ble_gap_addr_t addr_1 = {
    			.addr_id_peer = 0,
    			.addr_type    = 2,
    			.addr         = {0xA2, 0xBD, 0x32, 0x40, 0x15, 0x47}
    		};
    
    ble_gap_addr_t addr_2 = {
    			.addr_id_peer = 0,
    			.addr_type    = 2,
    			.addr         = {0x2E, 0xE7, 0x4B, 0x55, 0x8B, 0x43}
    		};
    
    whitelist[0] = &addr_1;
    whitelist[1] = &addr_2;
    
    err_code = sd_ble_gap_whitelist_set(whitelist,2);	
    APP_ERROR_CHECK(err_code);
    		
    }
    
  • Parameters in the whitelist are copied form BLE_GAP_EVT_AUTH_STATUS events after bonding, so it seems that both came with addr_peer_id = 0.

    The addr_peer_id parameter is not clear to me. The documentation says that it is 'Reference to peer in device identities list (as set with sd_ble_gap_device_identities_set) when peer is using privacy.' but in the structure it is one bit width. So, I assume that it is just a flag if the device is present in the device identities list. Is it correct?

    BTW. I don't use identities list for now. I just wanted to use whitelist for filtering devices during scanning.

  • FormerMember
    0 FormerMember in reply to FormerMember

    I have updated my answer.

  • Following your example I have made it working. Instead of creating array of ble_gap_addr_t, I create array of pointers to ble_gap_addr_tand now it works. Thank you.

Related