GATT server introduction
1. Description
A GATT server is part of the Bluetooth Low Energy (BLE) protocol stack, specifically responsible for providing data and services to a GATT client. GATT stands for Generic Attribute Profile, and it defines how data is organised and exchanged between BLE devices.
2. A high-level example of a GATT server structure:
2.1. GATT server (profile)
This is the highest architectural level of a GATT server. It is a collection of all attributes (GATT services, characteristics and descriptors).
2.2 GATT service
A GATT service is a collection of related characteristics. Each service is identified by a UUID. No GATT operations can be performed on services; all operations occur on characteristics and descriptors.
GATT service occupies one attribute.
2.3 GATT characteristic
GATT characteristics are data elements provided by a service. Each characteristic has a value and properties (operations), such as read, write, and notify. A UUID is also used for identification.
A characteristic encompasses two attributes, as it includes both characteristic declaration and characteristic value attributes.
2.4 GATT descriptors
GATT descriptors are optional attributes that belong to characteristics and provide additional information about them. The most commonly used variant is the Client Characteristic Configuration Descriptor (CCCD), which allows subscriptions to a characteristic for notifications or indications.
Each descriptor occupies one attribute.
3. BLE GATT server characteristic operations
3.1 GATT client operations
Read - Reads the characteristic value.
Write - Writes a value to a characteristic.
Write no response - Writes to a characteristic value does not expect an acknowledgement from the GATT server.
3.2 GATT server operations
Notify - Sends a notification to the GATT client about a change in characteristic value.
Indicate - Sends an indication to the GATT client about a change in characteristic value. Expects an acknowledgement from the GATT client.
4. Security
Bluetooth connections are more secure than traditional BLE advertising. Not only it requires a connection between the devices, but also different security levels with authentication and encryption are available to setup.
Bluetooth has 4 core security levels for connections:
Security level | Authentication | Encryption | MITM protection | Description |
|---|---|---|---|---|
Level 1 | None | None | No | No security (unauthenticated, unencrypted connection) |
Level 2 | None | Yes | No | Encrypted, but without authentication (e.g., Just Works pairing) |
Level 3 | Yes | Yes | Yes | Authenticated pairing with encryption (e.g., Passkey, Numeric Comparison) |
Level 4 | Yes (LE Secure Connections) | Yes | Yes | Strongest BLE security with authenticated LE Secure Connections |
Utilizing a passkey does not inherently ensure security. It is advisable to avoid transmitting sensitive data via Bluetooth unless supplementary security measures are implemented to protect the data.