I know that every BLE device must implement a GATT Server, and thus supports having a readable DeviceName
.
But is it possible to read from the Central before a connection is established?
I would like to implement a 'whitelist' of devices that a Peripheral is allowed to connect to, like the following:
DeviceName
, and accepts or rejects connection based on that name.A peripheral can expose its name in two ways; by including it in the advertising data and by having a Device Name GATT characteristic that can be read by a GATT client during a connection.
A central usually does not advertise, so the only way a peripheral can get a central's device name is through the Device Name GATT characteristic, while being connected.
So no, you can't read the central's name before connection. However, note that the GAP standard says this characteristic is only readable without authentication/authorization when the device is "discoverable". From the GAP chapter section 12.1:
The Device Name characteristic shall contain the name of the device as an UTF-8 string as defined in Section 3.2.2. When the device is discoverable, the Device Name characteristic value shall be readable without authentication or authorization. When the device is not discoverable, the Device Name Characteristic should not be readable without authentication or authorization. The Device Name characteristic value may be writable. If writable, authentication and authorization may be defined by a higher layer specification or be implementation specific.
As a side note, a connection does not imply that pairing is required. So it is possible that you can read the name before a pairing request, and allow/deny the pairing request based on the name if you would like to do that.