Section 7.10

GATT

Full name: Generic Attribute Profile.

Definition

GATT, the Generic Attribute Profile, is the part of Bluetooth Low Energy (BLE) §7.1 that arranges a device’s attributes into services, characteristics and descriptors, and defines the procedures a client uses to discover and use them. Attributes are the numbered data items that ATT §7.9 (Attribute Protocol) reads and writes. A characteristic is one data value, such as a temperature, together with the attributes that describe it; a service groups the characteristics of one feature, such as heart-rate measurement. The Bluetooth Core Specification defines GATT [302].

The idea

A phone connects to a device it has never seen. It must find out what data the device offers, where each value sits in the attribute table, and what it may do with each value, without a manual written for that device. GATT’s answer is that the server describes itself inside its own table: special attributes called declarations mark where each service and each characteristic begins and state their types and supported operations. Any client can read these declarations, a step called discovery, and then use the values. Services defined by the Bluetooth standards have short assigned numbers, so a phone recognizes a Heart Rate service on any device.

A building directory is a fair picture. Each floor is a service, each door a characteristic, and the sign on each door lists what can be done there: read, write, or subscribe to news. The picture also separates two questions. The sign states what the door supports; whether a particular visitor may go in is decided by a guard who is not on the sign. In GATT, the sign is the characteristic’s properties, and the guard applies the attribute permissions.

How it works

The structure. A GATT server’s table is a sequence of attributes, each with a handle, a type and a value.

UUIDs. For types assigned by the Bluetooth Special Interest Group, the body that maintains the standard, GATT uses a 16-bit short form that stands for a full UUID built from a fixed pattern, the Bluetooth Base UUID: the Heart Rate service 0x180D stands for 0000180D-0000-1000-8000-00805F9B34FB. A vendor’s own service or characteristic uses a full 128-bit UUID, usually generated at random (UUID version 4, with 122 random bits) or derived from a name (UUID version 5). A version 5 UUID is computed from a namespace UUID and the name with SHA-1 (Secure Hash Algorithm §14.1 1), a cryptographic hash function §5.1, so the same name always gives the same UUID. RFC 9562 defines these versions [276]. A UUID is a name, not a secret.

Properties. The properties byte of a characteristic declaration lists the operations the characteristic supports, one bit each: 0x01 broadcast, 0x02 read, 0x04 write without response §7.13, 0x08 write, 0x10 notify, 0x20 indicate, 0x40 authenticated signed writes, and 0x80 extended properties, meaning that a further descriptor holds more bits. Any client can read the properties during discovery.

Permissions. Attribute permissions are rules that the server’s own software attaches to each attribute; ATT never transmits them. The specification divides them into four kinds:

Some implementations also offer a permission that demands a key made with LE Secure Connections §7.21 (LE stands for Low Energy), the stronger of the two BLE pairing families. Together, these requirements set the security level §7.33 the link must reach.

The check on every access. The server checks that the handle exists, that the access permission allows the operation, and that the link meets the encryption, key-size and authentication requirements; if authorization is required, it then asks the application. The first failed check produces an Error Response whose code names it: 0x02 Read Not Permitted or 0x03 Write Not Permitted, 0x0F Insufficient Encryption, 0x0C Encryption Key Size Too Short, 0x05 Insufficient Authentication, or 0x08 Insufficient Authorization. A client that receives a security code can pair or encrypt the link and try again.

Procedures. GATT names the sequences of ATT messages a client uses. Discovery comes first: Read By Group Type Requests for type 0x2800 find the primary services, Read By Type Requests for type 0x2803 find the characteristics within each service’s range of handles, and Find Information Requests find the descriptors. A client usually stores the result for a bonded device, one with which it has kept keys from an earlier pairing, and the server’s Service Changed characteristic tells such a client when the table has changed. The access procedures follow: read; write with a Write Request; write without response with a Write Command; long and reliable writes for values that do not fit one message; and notifications and indications, once switched on in the configuration descriptor.

Worked example

A vendor’s sensor holds the following hypothetical table; its 128-bit UUIDs are written here as names.

Decoding the properties: 0x0A is binary 00001010, bits 1 and 3, the sum of 0x02 and 0x08: read and write. 0x12 is binary 00010010, bits 1 and 4, the sum of 0x02 and 0x10: read and notify.

The server’s software gives Sampling Period these permissions, which no client can see: anyone may read it, and writing needs an encrypted link whose key came from authenticated pairing. A phone tries to set the period to 500 ms, which is 0x01F4.

  1. On an unencrypted link, the phone sends the Write Request 12 22 00 F4 01. The handle exists and is writable, but the link is not authenticated, so the server answers 01 12 22 00 05, an Error Response with code 0x05, Insufficient Authentication.

  2. The phone pairs with Just Works §7.22, a pairing method that asks the user nothing and therefore gives no protection against a man-in-the-middle. The link is now encrypted, but its key is unauthenticated, and the same request gets the same error.

  3. The phone pairs again with numeric comparison §7.24, in which the user confirms that both devices show the same six-digit number. The key is now authenticated; the same request succeeds, and the server answers 13, the Write Response.

The properties byte 0x0A said “write” in all three attempts. Only the state of the link, checked against the permissions, changed the result.

Stated precisely

An operation oo, a read or a write, by a client on attribute aa over link ℓ\ell succeeds only if all of the following hold:

  1. aa exists;

  2. the access permission of aa allows oo;

  3. if aa requires encryption for oo, then ℓ\ell is encrypted with a key at least as long as aa requires;

  4. if aa requires authentication for oo, then the key of ℓ\ell came from authenticated pairing;

  5. if aa requires authorization for oo, then the server’s application approves this client for oo.

The properties byte does not appear in this list. It is the server’s public statement of which procedures a client may attempt. Whether a server also rejects an operation that its properties do not list depends on the implementation; a well-built server keeps properties and permissions consistent, so that the question does not arise. Discovery rests on one more rule: GATT makes service and characteristic declarations readable without authentication or authorization, so any connected client can learn the structure and the properties of the table.

Limits and common mistakes

Properties are not access control. A properties byte that says “write” tells a client only that writing is offered.

A UUID is not a credential. Any device can advertise any UUID and copy another device’s whole table, so recognizing a service by its UUID says nothing about who built the device.

Permissions judge the link, not the data. A write that passes every permission came over an encrypted, authenticated link from a device the server has paired with; it does not show that an authorized author composed the bytes, because an app on a paired phone can write anything the link allows. Proof of authorship needs a check on the data itself, such as a message authentication code §5.7, as the Channel confidentiality versus object authenticity §7.34 entry explains.

GATT does not define how authorization decides. The authorization permission says only that the server’s application must be asked.

A Write Command that fails a permission check is discarded silently, because commands get no Error Response. And since permissions are never transmitted, a client learns them only from error codes, one failed attempt at a time.

Discovery takes time. Each step is one request and one response; on a connection whose connection interval §7.7 is 30 ms, a step often takes about one interval, so 20 steps take about 20×30=60020 \times 30 = 600 ms. This is why clients store the result for bonded devices.

Questions answered

How do a characteristic’s properties differ from its access permissions?

A characteristic’s properties are a public declaration of which operations it offers, while its access permissions are private rules that decide whether a particular request succeeds. The properties are one byte in the characteristic’s declaration in the GATT (Generic Attribute Profile) table, one bit per operation: read, write, write without response, notify, indicate and a few others. Any client can read them during discovery, before any security has been set up.

The permissions are attached to the characteristic’s attributes by the server’s software and are never transmitted. They state whether the value may be read or written at all, and under which conditions: an encrypted link, a minimum key size, a key from authenticated pairing, or approval by the server’s application. The server checks them on every access and refuses a failing request with an error code that names the missing condition, such as Insufficient Authentication. A characteristic whose properties say “write” can therefore still refuse a write from a client whose link is not secure enough, and even a permitted write proves only the state of the link, not who composed the data.

Related entries: GATT characteristic (§7.11), Security level (§7.33), Channel confidentiality versus object authenticity (§7.34), Authentication (§1.6), ATT (§7.9), Just Works (§7.22), Numeric comparison (§7.24). Further reading: [19, 91, 276, 302].