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

Block ble connection with other devices

Hi all, I am trying to block connection from other devices to my nrf51dk board, except some specific devices. I used whitelist but it seem like the peripheral only block the devices inside the whitelist not vice versa.

  Gap::Whitelist_t whitelist;
  whitelist.size = 2;
  whitelist.capacity = 2;
  BLEProtocol::Address_t peerAddr[2];
  peerAddr[0].type = BLEProtocol::AddressType::RANDOM_STATIC;
  peerAddr[0].address[5] = 0x30;
  peerAddr[0].address[4] = 0x75;
  peerAddr[0].address[3] = 0x12;
  peerAddr[0].address[2] = 0xa0;
  peerAddr[0].address[1] = 0x74;
  peerAddr[0].address[0] = 0x5a;  
  whitelist.addresses = peerAddr;
  ble.gap().setWhitelist(whitelist);	
  ble.gap().setAdvertisingPolicyMode(Gap::ADV_POLICY_FILTER_ALL_REQS);

I tried to use that format to whitelist my phone but at the end, my phone was blocked by the peripheral.

After that I think about using button to grant my phone permission to connect to the peripheral device by using sd_ble_gap_sec_params_reply to reply the BLE_GAP_EVT_SEC_PARAMS_REQUEST follow this but when I do that in a switch-case, the connection still established without permission (button press). So do anyone know how to control the sd_ble_gap_sec_params_reply or it is impossible to control it?

BTW I'm using S130 v2.0.

  • The peripheral blocks devices in the whitelist? I'm pretty sure that either it will not block any devices, or it will block devices that are not in the whitelist. Are you sure you smart phone is using the random static address type?

    The only way for a peripheral to block a connection is to use a whitelist. You can however protect your characteristic values by setting security level requirements on them. Then you need to pair before the central can access them.

  • My phone address isn't change after days so it definitely static and I think the whitelist problem is because of the mbed os I am using. I read the comments in gap.h and I found @experimental in the comments of whitelist related function. So that would be the reason. If it's like what you said that the only way for me to block the connection is by using whitelist then I think I could use the button to turn the whitelist on off to block the connection. Thanks for comment.

Related