Cordio Stack and Cordio Profiles  r2p3-02rel0
GATT Profiles and Services

Content

 Alert Notification Profile
 
 Battery Profile
 
 Blood Pressure Profile
 
 Cycling Power Profile
 
 Cycling Speed And Cadence Profile
 
 Device Information Profile
 
 Find Me Profile
 
 Gap Profile
 
 Gatt Profile
 
 Glucose Profile
 
 Human Interface Device Profile
 
 Heart Rate Profile
 
 Health Thermometer Profile
 
 Phone Alert Status Profile
 
 Pulse Oximeter Profile
 
 Running Speed And Cadence Profile
 
 Scan Parameter Profile
 
 Gyroscope Service Profile
 
 Temperature Service Profile
 
 Time Profile
 
 User Data Profile
 
 Uribeacon Configuration Profile
 
 Wireless Data Exchange Profile
 
 Arm Ltd Proprietary Profile
 
 Weight Scale Profile
 
 Alert-Related Service
 
 Battery Service
 
 Blood Pressure Service
 
 Service Configuration
 
 Service Constants
 
 Gatt And Gap Service
 
 Cycling Power Service
 
 Cycling Speed And Cadence Service
 
 Device Information Service
 
 Glucose Service
 
 Gyroscope Sensor Service
 
 Human Interface Device Service
 
 Heart Rate Service
 
 Health Thermometer Service
 
 Internet Profile Support Service
 
 Pulse Oximiter Service
 
 Proximity Service
 
 Running Speed And Cadence Service
 
 Scan Parameter Service
 
 Temperature Sensor Service
 
 Time-Related Service
 
 Uricfg Configuration Service
 
 Wireless Data Exchange Service
 
 Wp Service
 
 Weight Scale Service
 

Description

Introduction

diagram_gattprofiles.png
Figure 1. BLE Stack: GATT Profiles

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:

Service API

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.

SvcAddGroup()

Add the attribute group for the service to the attribute database.

Syntax:

void SvcAddGroup(void)

This function is typically called once at system startup to set up and initialize a service.

SvAddGroupDyn()

Add the attribute group for the service using the dynamic attribute database.

Syntax:

void *SvcAddGroupDyn(void)

This function is typically called once at system startup to set up and initialize a service.

SvcRemoveGroup()

Remove the attribute group for the service from the attribute database.

Syntax:

void SvcRemoveGroup(void)

The service will no longer be available to peer devices.

SvcCbackRegister()

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:

void SvcCbackRegister(attsReadCback_t readCback, attsWriteCback_t writeCback)

Where:

Service Example Walkthrough

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.

Service Overview

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.

diagram_gatt_battsvcattr.png
Figure 2. Battery Service Attributes

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).

Attribute Handles

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.

/* Battery Service */
#define BATT_START_HDL 0x60
#define BATT_END_HDL (BATT_MAX_HDL - 1)
/* Battery Service Handles */
enum
{
BATT_SVC_HDL = BATT_START_HDL, /* Battery service declaration */
BATT_LVL_CH_HDL, /* Battery level characteristic */
BATT_LVL_HDL, /* Battery level */
BATT_LVL_CH_CCC_HDL, /* Battery level CCCD */
};

Read and Write Permissions

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.

/*! Characteristic read permissions */
#ifndef BATT_SEC_PERMIT_READ
#define BATT_SEC_PERMIT_READ SVC_SEC_PERMIT_READ
#endif
/*! Characteristic write permissions */
#ifndef BATT_SEC_PERMIT_WRITE
#define BATT_SEC_PERMIT_WRITE SVC_SEC_PERMIT_WRITE
#endif

By default, the read and write permissions for the service are set to the global read and write settings in Service Configuration.

Data Structures

A service implementation consists of ATT protocol layer data structures containing attribute data. The data structures are related as shown in Figure 3.

diagram_gatt_svcdatastruct.png
Figure 3. Service Data Structures

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.

Attribute Variables

Variables containing the value and length of each attribute are defined in svc_batt.c.

/* Battery service declaration */
static const uint8_t battValSvc[] = {UINT16_TO_BYTES(ATT_UUID_BATTERY_SERVICE)};
static const uint16_t battLenSvc = sizeof(battValSvc);
/* Battery level characteristic */
static const uint8_t battValLvlCh[] = {ATT_PROP_READ | ATT_PROP_NOTIFY,
static const uint16_t battLenLvlCh = sizeof(battValLvlCh);
/* Battery level */
static uint8_t battValLvl[] = {0};
static const uint16_t battLenLvl = sizeof(battValLvl);
/* Battery level client characteristic configuration */
static uint8_t battValLvlChCcc[] = {UINT16_TO_BYTES(0x0000)};
static const uint16_t battLenLvlChCcc = sizeof(battValLvlChCcc);

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.

Attribute Array

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.

typedef struct
{
uint8_t const *pUuid; /*! Pointer to the attribute’s UUID */
uint8_t *pValue; /*! Pointer to the attribute’s value */
uint16_t *pLen; /*! Pointer to the length of the
attribute’s value */
uint16_t maxLen; /*! Maximum length of attribute’s value */
uint8_t settings; /*! Attribute settings */
uint8_t permissions; /*! Attribute permissions */
The attribute array for battery service is shown below.
static const attsAttr_t battList[] =
{
/* Service declaration */
{
(uint8_t *) battValSvc,
(uint16_t *) &battLenSvc,
sizeof(battValSvc),
0,
},
/* Characteristic declaration */
{
(uint8_t *) battValLvlCh,
(uint16_t *) &battLenLvlCh,
sizeof(battValLvlCh),
0,
},
/* Characteristic value */
{
battValLvl,
(uint16_t *) &battLenLvl,
sizeof(battValLvl),
BATT_SEC_PERMIT_READ
},
/* Characteristic CCC descriptor */
{
battValLvlChCcc,
(uint16_t *) &battLenLvlChCcc,
sizeof(battValLvlChCcc),
(ATTS_PERMIT_READ | BATT_SEC_PERMIT_WRITE)
}
};

Note the following:

Group Structure

The group structure contains the attribute array and the handle start and end range for the service.

/* Battery group structure */
static attsGroup_t svcBattGroup =
{
(attsAttr_t *) battList,
};