1

I have an android BLE client and an android BLE server.

After the initial connection, I want the server to allow only the previously connected client device to connect.

How to achieve this?

What I have considered so far:

1. Bond the devices via android Bluetooth settings

Is it possible to allow only bonded devices to connect to the server? If so, how?

2. Some sort of whitelist

  • Mac Address (problematic, as mac addresses are not static)
  • device name
  • IRK

Is it possible to implement such a whitelist? If so, how?

3. Only advertise for first connection

Only advertise for first connection, then remember the server device on the client side and try to connect to the server without advertising. This does not seem to work.

Thomas Morris
  • 794
  • 5
  • 26
heslegend
  • 86
  • 8

1 Answers1

0

Id recommend your second option. With ble to create a connection you scan devices and then after the scan you can make the GATT connection to them. So if you only want previously connected device to make this connection just filter then on the scan callback. As you can filter by MAC address. This can be done by storing your list of MAC addresses in the global settings so the data does not reset when the app reopens. Just add a list of strings with your devices and filter by that.

You will also need a one off state for the initial connection. So that if there are no entries in your list then scan freely without a filter.

Thomas Morris
  • 794
  • 5
  • 26
  • The problem with your solution is that I want the server to decide which devices are allowed to connect (only known devices). The ble scan is done by the client. – heslegend Aug 26 '20 at 10:21
  • So you want the device which is broadcasting that it wants to make a connection to determine if the devices should connect? – Thomas Morris Aug 26 '20 at 10:23
  • Yes. Consider two client devices and one server device in the same room. One client device was already connected to the server before, the other device was not. If now both clients try to connect to the server, the server should only allow the previously connected device to connect. – heslegend Aug 26 '20 at 10:33
  • So you want the advertising device to only allow a device to connect if it meets the criteria either initial scan or matched before? – Thomas Morris Aug 26 '20 at 10:35
  • Yes, and if two devices want to connect (one previously connected, one not), only the previously connected device should be allowed to connect. My idea was to have initial connection process (e.g. initial connect only if a "connect" button is pressed by the user). From then on, the user should not have to take action anymore and the advertising device should only let previously connected devices connect until the "connect" button is pressed again. – heslegend Aug 26 '20 at 11:06