Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Private vs public addresses in Bluetooth low energy on Android

A Bluetooth low energy device is uniquely identified by it's address (in the Android API they call this the MAC address and denote it as colon separated hex values e.g. 11:aa:22:bb:33:cc).

But to uniquely identify a BLE address you need to know if it's a public or a private address. In essence, 49 bits are necessary to identify an address, not 48.

Random addresses can be either static random, non-resolvable private or resolvable private and these types are separated by a bit pattern in the two most significant bytes (11, 00 and 10 respectively).

But I don't see anywhere that you can separate public and random addresses just by looking at the 48 bits in the address.

So how does this work in the Android API? How do they know what device to connect to when they don't know if the address you've specified are public or random?

The API in question is for instance the getRemoteDevice function. It says:

Valid Bluetooth hardware addresses must be upper case, in a format such as "00:11:22:33:AA:BB". The helper checkBluetoothAddress(String) is available to validate a Bluetooth address.  A BluetoothDevice will always be returned for a valid hardware address, even if this adapter has never seen that device. 

So you give the function 48 bits of data and there is no way to tell it if the address is public or private. This means the device is not uniquely identified.

like image 333
Vegar Westerlund Avatar asked May 05 '14 11:05

Vegar Westerlund


People also ask

Does Bluetooth Low Energy require location?

Location Permission is mandatory on Android Yes, we were as surprised as you are. Bluetooth is required to setup, update and sync your FitBark device. In 2019, Android made it mandatory for any app to have location permissions in order to work with Bluetooth devices.

What is resolvable private address Bluetooth?

The Resolvable Private Address (RPA) is the backbone for privacy in BLE devices. An RPA is an address that's generated using a random number and the secret Identity Resolving Key (IRK). This IRK is shared between two devices at the time of pairing and stored in the device's internal memory during bonding.

When would you use Bluetooth Low Energy?

Bluetooth can handle a lot of data but quickly consumes battery life and costs a lot more. Bluetooth Low Energy is used for applications that do not need to exchange large amounts of data and can run on battery power for years at a cheaper cost.


2 Answers

Since nobody else seems to have an answer to offer I started testing on my own.

I tried making an app that creates a device from a string representation of an address and tried setting up my device with the 48 bit address alternating the public or private bit to see what the Android stack does.

private final BluetoothGattCallback leGattCallback = new BluetoothGattCallback() {     @Override     public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {         if (newState == BluetoothProfile.STATE_CONNECTED) {             Log.i("Fisken", "Gatt connected " + gatt.getDevice().getAddress() + " status " + status);             if (status != BluetoothGatt.GATT_SUCCESS) {                 Log.w("Fisken", "Disconnect and close");                 gatt.disconnect();                 gatt.close();             }         } else if (newState == BluetoothProfile.STATE_DISCONNECTED) {             Log.i("Fisken", "Gatt disconnected " + gatt.getDevice().getAddress() + " status " + status);             if (status != BluetoothGatt.GATT_SUCCESS) {                 Log.w("Fisken", "Disconnect and close");                 gatt.disconnect();             }             gatt.close();         }     } };  BluetoothAdapter mBluetoothAdapter = ((BluetoothManager)getSystemService(Context.BLUETOOTH_SERVICE)).getAdapter(); BluetoothDevice d = mBluetoothAdapter.getRemoteDevice("FF:55:44:33:22:11"); d.connectGatt(this, false, leGattCallback); 

With this code, if I start my BLE peripheral with a random address everything works as expected. However, if I try running it with the same address with the public bit set, logcat says "Gatt connected", but that's just not true. And I'm never able to disconnect.

Update: I did some more testing to figure this out. The onConnectionStateChange event I get is just the connection attempt timing out. The status is set to either 133 (if I get STATE_CONNECTED) or 257 (if I get a STATE_DISCONNECTED) and I've seen both. In either case I should (and now do in the sample code) cancel the connection attempt and close the client.

I've also found out that if I do a scan first, so that the device I'm trying to connect to have been seen recently and then do a connect based solely on the device mac address then I am able to connect to both random and public addresses without any trouble.

So this seems to be a bug/and or missing feature in the Android API. It does not allow you to connect to a public address without first having scanned for it. It does however work for random addresses.

like image 71
Vegar Westerlund Avatar answered Oct 12 '22 23:10

Vegar Westerlund


It is possible to guess if the address is public or random, though it will not work in every case.

As you say above, in case of a random address, both MSB are either 00xx, 01xx or 11xx... so if it is 10xx, then it is a public address (from a company whose OUI starts with 8,9, A or B)

Also, the number of registered OUI is very limited compared to what is existing, so by searching the potential OUI in the IEEE database, a matching result will probably mean a public adress.

Registered OUI count: ~20500, so 0.12% out of 2^24 bits and 0.48% out of 2^22 bits.

Without the IEEE database, it is possible to rely on the fact that the first LSB of a OUI is always 0, and the second LSB is almost always 0 (actually, it should be always 0 as these addresses are universally administered).

Also, other statiscal analysis can be used: for instance, 60% of the OUI start with 00. On the other hand, a non resolvable private address, has only a probability of 1.66% to start with 00 (with uniform random generator).

like image 29
calandoa Avatar answered Oct 13 '22 01:10

calandoa