Bluetooth Low Energy Host Stack  Rev. 4
API Reference Manual
GATT - Server APIs

Overview


 

Files

file  gatt_server_interface.h
 

Data Structures

struct  gattServerMtuChangedEvent_t
 
struct  gattServerAttributeWrittenEvent_t
 
struct  gattServerLongCharacteristicWrittenEvent_t
 
struct  gattServerCccdWrittenEvent_t
 
struct  gattServerAttributeReadEvent_t
 
struct  gattServerProcedureError_t
 
struct  gattServerEvent_t
 
union  gattServerEvent_t.eventData
 

Typedefs

typedef void(* gattServerCallback_t) (deviceId_t deviceId, gattServerEvent_t *pServerEvent)
 

Enumerations

enum  gattServerEventType_t {
  gEvtMtuChanged_c, gEvtHandleValueConfirmation_c, gEvtAttributeWritten_c, gEvtCharacteristicCccdWritten_c,
  gEvtAttributeWrittenWithoutResponse_c, gEvtError_c, gEvtLongCharacteristicWritten_c, gEvtAttributeRead_c
}
 
enum  gattServerProcedureType_t { gSendAttributeWrittenStatus_c, gSendAttributeReadStatus_c, gSendNotification_c, gSendIndication_c }
 

Functions

bleResult_t GattServer_Init (void)
 
bleResult_t GattServer_RegisterCallback (gattServerCallback_t callback)
 
bleResult_t GattServer_RegisterHandlesForWriteNotifications (uint8_t handleCount, uint16_t *aAttributeHandles)
 
bleResult_t GattServer_SendAttributeWrittenStatus (deviceId_t deviceId, uint16_t attributeHandle, uint8_t status)
 
bleResult_t GattServer_RegisterHandlesForReadNotifications (uint8_t handleCount, uint16_t *aAttributeHandles)
 
bleResult_t GattServer_SendAttributeReadStatus (deviceId_t deviceId, uint16_t attributeHandle, uint8_t status)
 
bleResult_t GattServer_SendNotification (deviceId_t deviceId, uint16_t handle)
 
bleResult_t GattServer_SendIndication (deviceId_t deviceId, uint16_t handle)
 
bleResult_t GattServer_SendInstantValueNotification (deviceId_t deviceId, uint16_t handle, uint16_t valueLength, uint8_t *aValue)
 
bleResult_t GattServer_SendInstantValueIndication (deviceId_t deviceId, uint16_t handle, uint16_t valueLength, uint8_t *aValue)
 

Data Structure Documentation

◆ gattServerMtuChangedEvent_t

struct gattServerMtuChangedEvent_t

GATT Server MTU Changed Event structure.

Data Fields
uint16_t newMtu Value of the agreed ATT_MTU for this connection.

◆ gattServerAttributeWrittenEvent_t

struct gattServerAttributeWrittenEvent_t

GATT Server Attribute Written Event structure.

Data Fields
uint16_t handle Handle of the attribute.
uint16_t cValueLength Length of the attribute value array.
uint8_t * aValue Attribute value array attempted to be written.

◆ gattServerLongCharacteristicWrittenEvent_t

struct gattServerLongCharacteristicWrittenEvent_t

GATT Server Long Characteristic Written Event structure.

Data Fields
uint16_t handle Handle of the Characteristic Value.
uint16_t cValueLength Length of the value written.
uint8_t * aValue Pointer to the attribute value in the database.

◆ gattServerCccdWrittenEvent_t

struct gattServerCccdWrittenEvent_t

GATT Server CCCD Written Event structure.

Data Fields
uint16_t handle Handle of the CCCD attribute.
gattCccdFlags_t newCccd New value of the CCCD.

◆ gattServerAttributeReadEvent_t

struct gattServerAttributeReadEvent_t

GATT Server Attribute Read Event structure.

Data Fields
uint16_t handle Handle of the attribute.

◆ gattServerProcedureError_t

struct gattServerProcedureError_t

Server-initiated procedure error structure.

Data Fields
gattServerProcedureType_t procedureType Procedure that generated error.
bleResult_t error Error generated.

◆ gattServerEvent_t

struct gattServerEvent_t

GATT Server Event structure: type + data.

Data Fields
gattServerEventType_t eventType Event type.
union gattServerEvent_t eventData Event data : selected according to event type.

◆ gattServerEvent_t.eventData

union gattServerEvent_t.eventData
Data Fields
gattServerMtuChangedEvent_t mtuChangedEvent For event type gEvtMtuChanged_c: the new value of the ATT_MTU.
gattServerAttributeWrittenEvent_t attributeWrittenEvent For event types gEvtAttributeWritten_c, gEvtAttributeWrittenWithoutResponse_c: handle and value of the attempted write.
gattServerCccdWrittenEvent_t charCccdWrittenEvent For event type gEvtCharacteristicCccdWritten_c: handle and value of the CCCD.
gattServerProcedureError_t procedureError For event type gEvtError_c: error that terminated a Server-initiated procedure.
gattServerLongCharacteristicWrittenEvent_t longCharWrittenEvent For event type gEvtLongCharacteristicWritten_c: handle and value.
gattServerAttributeReadEvent_t attributeReadEvent For event types gEvtAttributeRead_c: handle of the attempted read.

Typedef Documentation

◆ gattServerCallback_t

typedef void(* gattServerCallback_t) (deviceId_t deviceId, gattServerEvent_t *pServerEvent)

GATT Server Callback prototype.

Enumeration Type Documentation

◆ gattServerEventType_t

GATT Server Event type enumeration.

Enumerator
gEvtMtuChanged_c 

ATT_MTU was changed after the MTU exchange.

gEvtHandleValueConfirmation_c 

Received a Handle Value Confirmation from the Client.

gEvtAttributeWritten_c 

An attribute registered with GattServer_RegisterHandlesForWriteNotifications was written.

After receiving this event, application must call GattServer_SendAttributeWrittenStatus. Application must write the Attribute in the Database if it considers necessary.

gEvtCharacteristicCccdWritten_c 

A CCCD was written.

Application should save the CCCD value with Gap_SaveCccd.

gEvtAttributeWrittenWithoutResponse_c 

An attribute registered with GattServer_RegisterHandlesForWriteNotifications was written without response (with ATT Write Command).

Application must write the Attribute Value in the Database if it considers necessary.

gEvtError_c 

An error appeared during a Server-initiated procedure.

gEvtLongCharacteristicWritten_c 

A long characteristic was written.

gEvtAttributeRead_c 

An attribute registered with GattServer_RegisterHandlesForReadNotifications is being read.

After receiving this event, application must call GattServer_SendAttributeReadStatus.

◆ gattServerProcedureType_t

Server-initiated procedure type enumeration.

Enumerator
gSendAttributeWrittenStatus_c 

Procedure initiated by GattServer_SendAttributeWrittenStatus.

gSendAttributeReadStatus_c 

Procedure initiated by GattServer_SendAttributeReadStatus.

gSendNotification_c 

Procedure initiated by GattServer_SendNotification.

gSendIndication_c 

Procedure initiated by GattServer_SendIndication.

Function Documentation

◆ GattServer_Init()

bleResult_t GattServer_Init ( void  )


Initializes the GATT Server module.

Returns
gBleSuccess_c or error.
Remarks
Application does not need to call this function if Gatt_Init() is called.
This function executes synchronously.

◆ GattServer_RegisterCallback()

bleResult_t GattServer_RegisterCallback ( gattServerCallback_t  callback)


Installs an application callback for the GATT Server module.

Parameters
[in]callbackApplication-defined callback to be triggered by this module.
Returns
gBleSuccess_c or error.
Remarks
This function executes synchronously.

◆ GattServer_RegisterHandlesForWriteNotifications()

bleResult_t GattServer_RegisterHandlesForWriteNotifications ( uint8_t  handleCount,
uint16_t *  aAttributeHandles 
)


Registers the attribute handles that will be notified through the GATT Server callback when a GATT Client attempts to modify the attributes' values.

Parameters
[in]handleCountNumber of handles in array.
[in]aAttributeHandlesArray of handles.
Returns
gBleSuccess_c or error.
Remarks
The application is responsible for actually writing the new requested values in the GATT database. Service- and profile-specific control-point characteristics should have their value handles in this list so that the application may get notified when a GATT Client writes it.
This function executes synchronously.

◆ GattServer_SendAttributeWrittenStatus()

bleResult_t GattServer_SendAttributeWrittenStatus ( deviceId_t  deviceId,
uint16_t  attributeHandle,
uint8_t  status 
)


Responds to an intercepted attribute write operation.

Parameters
[in]deviceIdThe device ID of the connected peer.
[in]attributeHandleThe attribute handle that was written.
[in]statusThe status of the write operation. If this parameter is equal to gAttErrCodeNoError_c then an ATT Write Response will be sent to the peer. Else an ATT Error Response with the provided status will be sent to the peer.
Remarks
This function must be called by the application when receiving the gEvtAttributeWritten_c Server event. The status value may contain application- or profile-defined error codes.

◆ GattServer_RegisterHandlesForReadNotifications()

bleResult_t GattServer_RegisterHandlesForReadNotifications ( uint8_t  handleCount,
uint16_t *  aAttributeHandles 
)


Registers the attribute handles that will be notified through the GATT Server callback when a GATT Client attempts to read the attributes' values.

Parameters
[in]handleCountNumber of handles in array.
[in]aAttributeHandlesArray of handles.
Returns
gBleSuccess_c or error.
Remarks
The application may modify the attribute's value in the GATT Database before sending the response with GattServer_SendAttributeReadStatus.
This function executes synchronously.

◆ GattServer_SendAttributeReadStatus()

bleResult_t GattServer_SendAttributeReadStatus ( deviceId_t  deviceId,
uint16_t  attributeHandle,
uint8_t  status 
)


Responds to an intercepted attribute read operation.

Parameters
[in]deviceIdThe device ID of the connected peer.
[in]attributeHandleThe attribute handle that was being read.
[in]statusThe status of the read operation. If this parameter is equal to gAttErrCodeNoError_c then an ATT Read Response will be sent to the peer containing the attribute value from the GATT Database. Else an ATT Error Response with the provided status will be sent to the peer.
Remarks
This function must be called by the application when receiving the gEvtAttributeRead_c Server event. The status value may contain application- or profile-defined error codes.

◆ GattServer_SendNotification()

bleResult_t GattServer_SendNotification ( deviceId_t  deviceId,
uint16_t  handle 
)


Sends a notification to a peer GATT Client using the Characteristic Value from the GATT Database.

Parameters
[in]deviceIdThe device ID of the connected peer.
[in]handleHandle of the Value of the Characteristic to be notified.
Returns
gBleSuccess_c or error.

◆ GattServer_SendIndication()

bleResult_t GattServer_SendIndication ( deviceId_t  deviceId,
uint16_t  handle 
)


Sends an indication to a peer GATT Client using the Characteristic Value from the GATT Database.

Parameters
[in]deviceIdThe device ID of the connected peer.
[in]handleHandle of the Value of the Characteristic to be indicated.
Returns
gBleSuccess_c or error.

◆ GattServer_SendInstantValueNotification()

bleResult_t GattServer_SendInstantValueNotification ( deviceId_t  deviceId,
uint16_t  handle,
uint16_t  valueLength,
uint8_t *  aValue 
)


Sends a notification to a peer GATT Client with data given as parameter, ignoring the GATT Database.

Parameters
[in]deviceIdThe device ID of the connected peer.
[in]handleHandle of the Value of the Characteristic to be notified.
[in]valueLengthLength of data to be notified.
[in]aValueData to be notified.
Returns
gBleSuccess_c or error.

◆ GattServer_SendInstantValueIndication()

bleResult_t GattServer_SendInstantValueIndication ( deviceId_t  deviceId,
uint16_t  handle,
uint16_t  valueLength,
uint8_t *  aValue 
)


Sends an indication to a peer GATT Client with data given as parameter, ignoring the GATT Database.

Parameters
[in]deviceIdThe device ID of the connected peer.
[in]handleHandle of the Value of the Characteristic to be indicated.
[in]valueLengthLength of data to be indicated.
[in]aValueData to be indicated.
Returns
gBleSuccess_c or error.