BlueNRG-MS only allow known device to connect

331 views Asked by At

I have a BLE peripheral with the STM BlueNRG-MS chip. I use the bluenrg API. The peripheral should be generally discoverable, but only known devices should be allowed to connect.

I thought I can achieve this by checking the bdaddr of the central device in the EVT_LE_CONN_COMPLETE callback and depending on whether the address is known or not, I'll allow the connection. In addition I would have a pairing mode where I accept all incomming connection requests and would add new central devices to the list of known devices.

  case EVT_LE_CONN_COMPLETE:
    {
      evt_le_connection_complete *cc = (void *)evt->data;
      /*TODO: check if peer address is listed or if HMI accepts new pairing
       * If in pairing mode, add device to the list and accept connection, otherwise
       * go through list and if not found, refuse connection.*/
      if(acceptNewPairing){
          LOG("CR from %d:%d:%d:%d:%d:%d", cc->peer_bdaddr[0], cc->peer_bdaddr[1], cc->peer_bdaddr[2], cc->peer_bdaddr[3], cc->peer_bdaddr[4], cc->peer_bdaddr[5]);
          GAP_ConnectionComplete_CB(cc->peer_bdaddr, cc->handle);         
      }
  }
  break;

My problem is that the bdaddr is not constant but changes after a certain time, so I don't regonize the central device. How can I overcome this problem? What is the proper way to implement this feature that most known bluetooth devices offer?

Update:
It seems that the behavior can be achieved using the function

hci_le_add_device_to_white_list(uint8_t bdaddr_type, tBDAddr bdaddr);

After that, the device is discoverable even if I set the discoverability to WHITE_LIST_FOR_ALL. My problem now is that the whitelist doesn't seem to be persistent, if I do a reboot of the device I have to go to pairing mode again in order to see it. Does someone know how I can save the whitelist?

What does aci_gap_configure_whitelist() do? Because if I call this function, it seems like my whitelist gets wipped out.

Update2:
In the STM Document PM0257 (sec. 3.10.1) I found a reference to what looks like to be the procedure I'm looking for. So I consider this a step forward. The problem is that the referenced function aci_gap_add_device_to_resolving_list doesn't exist in my bluenrg API. Any idea what I should use instead?

1

There are 1 answers

0
po.pe On BEST ANSWER

Issue has been solved by using the WHITE_LIST_FOR_ONLY_SCAN property for the aci_gap_set_discoverable() function while only bonded devices should be able to connect.