Generic Attribute Profile (GATT)

The GATT layer manages the service database providing APIs for service registration and attribute declaration.

The GATT Client initiates commands and requests towards the GATT Server, and can receive responses, indications and notifications sent by the server. It is enabled through the configuration option: CONFIG_BT_GATT_CLIENT

The GATT Server accepts incoming commands and requests from the GATT Client, and sends responses, indications and notifications to the client.

Services can be registered using the API which takes the struct that provides the list of attributes the service contains. The helper macro can be used to declare a service.

Attributes can be declared using the struct or using one of the helper macros:

Declares a Primary Service.

Declares a Secondary Service.

Declares a Include Service.

Declares a Characteristic.

Declares a Descriptor.

Declares an Attribute.

Declares a Client Characteristic Configuration.

Declares a Characteristic Extended Properties.

Declares a Characteristic User Format.

Each attribute contain a uuid, which describes their type, a read callback, a write callback and a set of permission. Both read and write callbacks can be set to NULL if the attribute permission don’t allow their respective operations.

Note

32-bit UUIDs are not supported in GATT. All 32-bit UUIDs shall be converted to 128-bit UUIDs when the UUID is contained in an ATT PDU.

Note

Attribute read and write callbacks are called directly from RX Thread thus it is not recommended to block for long periods of time in them.

Attribute value changes can be notified using API, alternatively there is where it is possible to pass a callback to be called when it is necessary to know the exact instant when the data has been transmitted over the air. Indications are supported by API.

Discover procedures can be initiated with the use of API which takes the struct which describes the type of discovery. The parameters also serves as a filter when setting the uuid field only attributes which matches will be discovered, in contrast setting it to NULL allows all attributes to be discovered.

Note

Caching discovered attributes is not supported.

Read procedures are supported by API which takes the struct as parameters. In the parameters one or more attributes can be set, though setting multiple handles requires the option: CONFIG_BT_GATT_READ_MULTIPLE

Write procedures are supported by API and takes struct as parameters. In case the write operation don’t require a response or APIs can be used, with the later working similarly to .

Subscriptions to notification and indication can be initiated with use of API which takes as parameters. Multiple subscriptions to the same attribute are supported so there could be multiple notify callback being triggered for the same attribute. Subscriptions can be removed with use of API.

Note

When subscriptions are removed notify callback is called with the data set to NULL.

API Reference

Generic Attribute Profile (GATT)

GATT Server

GATT Server APIs

GATT Client

GATT Client APIs