![]() |
Cordio Stack and Cordio Profiles
r2p3-02rel0
|
The profiles and services are interoperable components that are designed to Bluetooth profile and service specification requirements. The profiles and services are used in applications to implement particular profile and service features.
GATT Profiles:
GATT Services:
All service modules have equivalent API functions to add, remove, and configure the callbacks for a service. The generalized functions described in this section are applicable to all service modules.
Note that these generalized API functions are for illustration purposes only and not actually implemented in the code. The actual API functions for a service module are given in its interface file.
Add the attribute group for the service to the attribute database.
Syntax:
This function is typically called once at system startup to set up and initialize a service.
Add the attribute group for the service using the dynamic attribute database.
Syntax:
This function is typically called once at system startup to set up and initialize a service.
Remove the attribute group for the service from the attribute database.
Syntax:
The service will no longer be available to peer devices.
Register the attribute read and write attribute callback functions for a service. These callback functions will be executed an attribute configured to use callbacks in its settings is accessed by a peer device.
If a callback is not used it can be set to NULL.
Syntax:
Where:
The best way to understand a service is by walking through an example. This walkthrough uses the battery service in files svc_batt.h and svc_batt.c.
The battery service is a simple service with only a few attributes. A diagram of the attributes in the battery service is shown in Figure 2.
The battery service contains four attributes: The service declaration, battery level characteristic declaration, the battery level, and the battery level client characteristic configuration descriptor (CCCD).
The attribute handles for the service are defined in svc_batt.h. Macro BATT_START_HDL defines the start value for the handle range used by the service. The start handle must be set so it does not overlap with the handles of any other service used by an application. The enumeration that follows defines the handle value for each attribute.
Two macros are provided to simplify the configuration of read and write security permissions for the attributes of the service. The security permissions control whether encryption is required before an attribute can be read or written. The macros are in svc_batt.c.
By default, the read and write permissions for the service are set to the global read and write settings in Service Configuration.
A service implementation consists of ATT protocol layer data structures containing attribute data. The data structures are related as shown in Figure 3.
The group structure contains a pointer to an attribute array and the handle range of the attributes it references. The attribute array is an array of structures with each structure containing a UUID, data, length, and other information for the attribute.
Variables containing the value and length of each attribute are defined in svc_batt.c.
The value of the battery service declaration is the UUID for the battery service.
The value of the battery level characteristic declaration is a byte array with contents defined by the Bluetooth specification. It contains the properties, handle, and UUID of the battery level. The properties are configured to allow read and notification, as defined by the battery service specification.
The battery level value is a single byte as defined by the battery service specification.
The battery level CCCD is a 16-bit integer formatted as a little-endian byte array.
Note that the variables that cannot be changed are defined as const (to save RAM), while variables that can be changed, like the battery level and CCCD, are not const.
The attribute variables defined above are used to construct an attribute structure for each attribute. These structures are contained in an array of type attsAttr_t.
Note the following:
The group structure contains the attribute array and the handle start and end range for the service.