| BlueNRG-1 BLE stack initialization

GATT database size guidelines

The present document guidelines are intended to help users of the BlueNRG-1 Bluetooth Lowe Energy (BLE) Stack Library to properly set the size of the GATT database according to the specific application profiles that the target application is going to implement.

# Number of GATT Service Records

- The service record is the base data structure used in the GATT database implementation to handle GATT services.
- The number of service records needed by the user application can be determined based on the number of services required by the specific profiles that the application implements.
- Notes:
  - GAP and GATT services are automatically added to the database during device initialization hence the total number of service records should be 2 plus the number of services strictly needed by the profiles
    - Future BLE library versions may remove or modify such automatic addition of service and characteristics.
  - This value is set through the BlueNRG_Stack_Initialization() API, BlueNRG_Stack_Initialization_t parameter, numAttrServ field .

# Number of GATT Attribute Records

- The attribute record is the base data structure used in the GATT database implementation to handle GATT attributes.
- The number of attribute records needed by the user application can be determined based on the number of characteristics and related descriptors required by the specific profiles that the application implements.
  - When a GATT characteristic is added to the database a minimum of 2 attribute records are needed: one for the characteristic declaration and one for the characteristic value. On top of this, additional records may be needed based on the characteristic properties, in particular:
    - If the characteristic has the notify or indicate property set, then one additional attribute record is needed.
    - If the characteristic has the broadcast property set, then one additional attribute record is needed.
    - If the characteristic has the extended property set, then one additional attribute record is needed.
  - In summary, one characteristic may need from 2 to 5 attribute records depending on the characteristic properties.
  - Certain characteristics and relative descriptors related to the GAP and GATT services are automatically added to the database during device initialization hence the total number of attribute records should be 9 plus the number of attributes strictly needed by the profiles
    - Future BLE library versions may remove or modify such automatic addition of service and characteristics
- Notes:
  - This value is set through the BlueNRG_Stack_Initialization() API, BlueNRG_Stack_Initialization_t parameter, numAttrRecord field.

# Size of the Value Array

- The value array is a memory area used to store attribute values. When the size of such memory area is calculated, the total occupancy of characteristics and description must be taken into account. In particular:
  - If the characteristic UUID is 16 bit, then 5 additional bytes are needed for characteristic declaration; if the characteristic UUID is 128 bit, then 19 additional bytes are needed for characteristic declaration
  - If the server configuration descriptor is added for a characteristic then 2 additional value bytes are needed
  - If the client configuration descriptor is added for a characteristic then 2 additional value bytes for each simultaneous connection are needed
  - If the extended properties is added for a characteristic then 2 additional value bytes are needed
- In summary, one characteristic may need from 5 to 25 additional storage bytes, on top of the characteristic value length.
- Notes:
  - This value is set through the BlueNRG_Stack_Initialization() API, BlueNRG_Stack_Initialization_t parameter, attrValueArrSize field .