Bluetooth GATT attribute pools

GATT attribute pools can be used to dynamically create a service description, which can later be registered in the Zephyr GATT database.

Every GATT service is essentially a set of GATT attributes that are ordered in a particular way. There are different types of attributes that can be registered to create a service:

  • Primary Service attribute, containing service metadata
  • Characteristic attribute, containing characteristic metadata
  • CCC descriptor attribute, used for turning notifications for a characteristic on or off
  • Regular descriptor attribute, used for providing an additional description for a characteristic

The API of the GATT attribute pools module allows to register different types of GATT attributes listed above. After each registration, a part of the memory is reserved for each attribute. You can also unregister attributes that are no longer needed by using the module’s API. In this case, the previously reserved memory is released. This can be useful when you want to restructure your service by using the Service Changed feature that is supported by the Zephyr Bluetooth stack (see, for example, the GATT Human Interface Device (HID) Service).

Additionally, you can adjust the memory footprint of this module to your needs by changing the configuration options for the size of the module’s memory pool. If you are unsure about the proper values, print the module’s statistics to see how the pool utilization level is affected by the chosen configuration.

API documentation

group bt_gatt_pool

BLE GATT attribute pools.

Defines

BT_GATT_POOL_SVC_GET(_svc, _svc_uuid_init)

Register a primary service descriptor.

Parameters
  • _svc: GATT service descriptor.
  • _svc_uuid_init: Service UUID.

BT_GATT_POOL_CHRC_GET(_svc, _chrc_uuid_init, _char_props)

Register a characteristic descriptor.

Parameters
  • _svc: GATT service descriptor.
  • _chrc_uuid_init: Characteristic UUID.
  • _char_props: Properties of the characteristic.

BT_GATT_POOL_DESC_GET(_svc, _descriptor_init)

Register an attribute descriptor.

Parameters
  • _svc: GATT service descriptor.
  • _descriptor_init: Attribute descriptor.

BT_GATT_POOL_CCC_GET(_svc, _ccc_cfg, _ccc_cb)

Register a CCC descriptor.

Parameters
  • _svc: GATT service descriptor.
  • _ccc_cfg: CCC descriptor configuration.
  • _ccc_cb: CCC descriptor callback.

Functions

void bt_gatt_pool_svc_get(struct bt_gatt_service *svc, struct bt_uuid const *svc_uuid)

Take a primary service descriptor from the pool.

Parameters
  • svc: GATT service descriptor.
  • svc_uuid: Service UUID.

void bt_gatt_pool_svc_put(struct bt_gatt_attr const *attr)

Return a primary service descriptor to the pool.

Parameters
  • attr: Attribute describing the primary service to be returned.

void bt_gatt_pool_chrc_get(struct bt_gatt_service *svc, struct bt_gatt_chrc const *chrc)

Take a characteristic descriptor from the pool.

Parameters
  • svc: GATT service descriptor.
  • chrc: Characteristic descriptor.

void bt_gatt_pool_chrc_put(struct bt_gatt_attr const *attr)

Return a characteristic descriptor to the pool.

Parameters
  • attr: Attribute describing the characteristic to be returned.

void bt_gatt_pool_desc_get(struct bt_gatt_service *svc, struct bt_gatt_attr const *descriptor)

Take an attribute descriptor from the pool.

Parameters
  • svc: GATT service descriptor.
  • descriptor: Attribute descriptor.

void bt_gatt_pool_desc_put(struct bt_gatt_attr const *attr)

Return an attribute descriptor to the pool.

Parameters
  • attr: Attribute describing the descriptor to be returned.

void bt_gatt_pool_ccc_get(struct bt_gatt_service *svc, struct _bt_gatt_ccc const *ccc)

Take a CCC descriptor from the pool.

Parameters
  • svc: GATT service descriptor.
  • ccc: CCC descriptor.

void bt_gatt_pool_ccc_put(struct bt_gatt_attr const *attr)

Return a CCC descriptor to the pool.

Parameters
  • attr: Attribute describing the CCC descriptor to be returned.