Changing BLE Attribute Size at Runtime - KBA219049

Version: **

 

Question:

How do you change a BLE attribute size at runtime?

 

Answer:

Characteristics with a variable length are useful because you do not need to expose additional data that is not relevant. cyBle_gattDB is an array of the CYBLE_GATTS_DB_T structure, which defines the handle, permissions, container size (maximum length), and full (16-bit) or partial (128-bit) UUID.

 

The attribute size can be changed by writing the cyBle_gattDB[] array as follows, after CYBLE_EVT_STACK_ON:

 

cyBle_gattDB[CYBLE_CUSTOM_SERVICE_CUSTOM_CHARACTERISTIC_CHAR_HANDLE-
1u].attValue.attFormatValue.attGenericValLen->actualLength= X;

 

where X is the length of the attribute.

 

Notes:

 

  • The attribute size can be decreased but cannot increase beyond the default size set in the BLE Component.
  • The actual length of an attribute can be retrieved by using the following macro:
      CYBLE_GATT_DB_ATTR_GET_ATTR_GEN_LEN (Handle – 1u);