TI BLE Stack API Documentation  2.03.09
gattservapp.h
1 /******************************************************************************
2 
3  @file gattservapp.h
4 
5  @brief This file contains the GATT Server Application (GATTServApp)
6  definitions and prototypes.<BR><BR>
7 
8  \image html HighLevelGATTServApp.PNG
9 
10  <BR> <h2>Functional
11  Description</h2> <p>The
12  GATT Server Application (GATTServApp) provides the following
13  abilities:</p> <ul> <li><b>Service
14  Registration</b> - This API is used to register a service's attribute
15  list and callback functions with the GATT Server Application.</li>
16  <li><b>Service Deregistration</b> - This API is used to deregister a
17  service's attribute list and callback functions from the GATT Server
18  Application.</li> <li><b>GATT Service Addition</b> - This API is the
19  add function for the GATT Service. It registers the GATT Service's
20  attribute list and callback functions with the GATT Server
21  Application.</li> <li><b>GATT Service Deletion</b> - This API is the
22  delete function for the GATT Service. It deregisters the GATT Service's
23  attribute list and callback functions from the GATT Server
24  Application.</li> </ul><BR>
25 
26  <h2>Service Attribute List</h2> <p>A profile may support one or more
27  services. Each of the services may support characteristics or
28  references to other services. Each characteristic contains a value and
29  may contain optional descriptors. The service, characteristic,
30  characteristic value and descriptors are all stored as attributes on
31  the server. The service attribute list to be registered with the GATT
32  Server must start with a Service attribute followed by all the
33  attributes associated with that Service attribute. </p><BR><BR
34  </p><BR><BR>
35 
36  \image html GATTAttributeList.PNG
37 
38  <BR> <h2>Service
39  Callback Functions</h2> <p>The encoding of each attribute value is
40  defined in the applicable profile. The
41  GATT Server doesn't directly access the attribute value for reading or
42  writing. It uses the Read and Write callback functions provided by the
43  registering profile to execute the incoming Attribute Protocol (ATT)
44  Read and Write request respectively. </p><BR><BR><BR><BR><BR><BR
45  </p><BR><BR><BR><BR><BR><BR>
46 
47  Group: WCS, BTS
48  $Target Device: DEVICES $
49 
50  ******************************************************************************
51  $License: BSD3 2009 $
52  ******************************************************************************
53  $Release Name: PACKAGE NAME $
54  $Release Date: PACKAGE RELEASE DATE $
55  *****************************************************************************/
56 
57 #ifndef GATTSERVAPP_H
58 #define GATTSERVAPP_H
59 
60 #ifdef __cplusplus
61 extern "C"
62 {
63 #endif
64 
65 /*********************************************************************
66  * INCLUDES
67  */
68 #include "bcomdef.h"
69 #include "osal.h"
70 
71 /*********************************************************************
72  * CONSTANTS
73  */
74 
79 #define GATT_CLIENT_CHAR_CFG_UPDATED_EVENT 0x00
80 
81 
88 #define GATT_PROP_BCAST 0x01
89 #define GATT_PROP_READ 0x02
90 #define GATT_PROP_WRITE_NO_RSP 0x04
91 #define GATT_PROP_WRITE 0x08
92 #define GATT_PROP_NOTIFY 0x10
93 #define GATT_PROP_INDICATE 0x20
94 #define GATT_PROP_AUTHEN 0x40
95 #define GATT_PROP_EXTENDED 0x80
96 
97 
103 #define GATT_EXT_PROP_RELIABLE_WRITE 0x0001
104 #define GATT_EXT_PROP_WRITABLE_AUX 0x0002
105 
106 
112 #define GATT_CLIENT_CFG_NOTIFY 0x0001
113 #define GATT_CLIENT_CFG_INDICATE 0x0002
114 
115 
121 #define GATT_SERV_CFG_BCAST 0x0001
122 
123 
125 #define GATT_CFG_NO_OPERATION 0x0000 // No operation
126 
131 #define GATT_FORMAT_BOOL 0x01
132 #define GATT_FORMAT_2BIT 0x02
133 #define GATT_FORMAT_NIBBLE 0x03
134 #define GATT_FORMAT_UINT8 0x04
135 #define GATT_FORMAT_UINT12 0x05
136 #define GATT_FORMAT_UINT16 0x06
137 #define GATT_FORMAT_UINT24 0x07
138 #define GATT_FORMAT_UINT32 0x08
139 #define GATT_FORMAT_UINT48 0x09
140 #define GATT_FORMAT_UINT64 0x0a
141 #define GATT_FORMAT_UINT128 0x0b
142 #define GATT_FORMAT_SINT8 0x0c
143 #define GATT_FORMAT_SINT12 0x0d
144 #define GATT_FORMAT_SINT16 0x0e
145 #define GATT_FORMAT_SINT24 0x0f
146 #define GATT_FORMAT_SINT32 0x10
147 #define GATT_FORMAT_SINT48 0x11
148 #define GATT_FORMAT_SINT64 0x12
149 #define GATT_FORMAT_SINT128 0x13
150 #define GATT_FORMAT_FLOAT32 0x14
151 #define GATT_FORMAT_FLOAT64 0x15
152 #define GATT_FORMAT_SFLOAT 0x16
153 #define GATT_FORMAT_FLOAT 0x17
154 #define GATT_FORMAT_DUINT16 0x18
155 #define GATT_FORMAT_UTF8S 0x19
156 #define GATT_FORMAT_UTF16S 0x1a
157 #define GATT_FORMAT_STRUCT 0x1b
158 
159 
165 #define GATT_NS_NONE 0x00
166 #define GATT_NS_BT_SIG 0x01
167 
168 
174 #define GATT_NS_BT_DESC_UNKNOWN 0x0000
175 
176 
178 // All profile services bit fields
179 #define GATT_ALL_SERVICES 0xFFFFFFFF
180 
181 // GATT Services bit fields
182 #define GATT_SERVICE 0x00000001
183 
184 #if defined ( TESTMODES )
185  // GATT Test Modes
186  #define GATT_TESTMODE_OFF 0 // Test mode off
187  #define GATT_TESTMODE_NO_RSP 1 // Ignore incoming request
188  #define GATT_TESTMODE_PREPARE_WRITE 2 // Forward Prepare Write Request right away
189  #define GATT_TESTMODE_MAX_MTU_SIZE 3 // Use Max ATT MTU size with Exchange MTU Rsp
190  #define GATT_TESTMODE_CORRUPT_PW_DATA 4 // Corrupt incoming Prepare Write Request data
191 #endif
192 
193 // GATT Server Parameters
194 #define GATT_PARAM_NUM_PREPARE_WRITES 0 // RW uint8
195 
196 // To make the size of the pointer type be platform/compiler independent
197 #define PTR_TYPE unsigned int *
198 
199 // GATT local read or write operation
200 #define GATT_LOCAL_READ 0xFF
201 #define GATT_LOCAL_WRITE 0xFE
202 
203 /*********************************************************************
204  * VARIABLES
205  */
206 
207 /*********************************************************************
208  * MACROS
209  */
210 
211 // The number of attribute records in a given attribute table
212 #define GATT_NUM_ATTRS( attrs ) ( sizeof( attrs ) / sizeof( gattAttribute_t ) )
213 
214 // The handle of a service is the handle of the first attribute
215 #define GATT_SERVICE_HANDLE( attrs ) ( (attrs)[0].handle )
216 
217 // The handle of the first included service (i = 1) is the value of the second attribute
218 #define GATT_INCLUDED_HANDLE( attrs, i ) ( *((uint16 *)((attrs)[(i)].pValue)) )
219 
220 // Client Characteristic Configuration table (from CCC attribute value pointer)
221 #define GATT_CCC_TBL( pValue ) ( (gattCharCfg_t *)(*((PTR_TYPE)(pValue))) )
222 
223 /*********************************************************************
224  * TYPEDEFS
225  */
226 
261 typedef bStatus_t (*pfnGATTReadAttrCB_t)( uint16 connHandle, gattAttribute_t *pAttr,
262  uint8 *pValue, uint16 *pLen, uint16 offset,
263  uint16 maxLen, uint8 method );
295 typedef bStatus_t (*pfnGATTWriteAttrCB_t)( uint16 connHandle, gattAttribute_t *pAttr,
296  uint8 *pValue, uint16 len, uint16 offset,
297  uint8 method );
309 typedef bStatus_t (*pfnGATTAuthorizeAttrCB_t)( uint16 connHandle, gattAttribute_t *pAttr,
310  uint8 opcode );
318 typedef struct
319 {
320  uint8 format;
321  int8 exponent;
322  uint16 unit;
323  uint8 nameSpace;
324  uint16 desc;
326 
330 typedef struct
331 {
332  uint16 connHandle;
333  uint8 value;
334 } gattCharCfg_t;
335 
340 typedef struct
341 {
346 
350 typedef struct
351 {
353  uint16 connHandle;
354  uint8 method;
356 
361 typedef struct
362 {
364  uint16 connHandle;
365  uint8 method;
366  uint16 attrHandle;
367  uint16 value;
369 
370 
371 // Structure to keep Prepare Write Requests for each Client
372 typedef struct
373 {
374  uint16 connHandle; // connection message was received on
375  attPrepareWriteReq_t *pPrepareWriteQ; // Prepare Write Request queue
377 
378 // GATT Structure to keep CBs information for each service being registered
379 typedef struct
380 {
381  uint16 handle; // Service handle - assigned internally by GATT Server
382  CONST gattServiceCBs_t *pCBs; // Service callback function pointers
384 
385 // Service callbacks list item
386 typedef struct _serviceCBsList
387 {
388  struct _serviceCBsList *next; // pointer to next service callbacks record
389  gattServiceCBsInfo_t serviceInfo; // service handle/callbacks
391 
392 /*********************************************************************
393  * VARIABLES
394  */
395 
396 // Server Prepare Write table (one entry per each physical link)
397 extern prepareWrites_t *prepareWritesTbl;
398 
399 // Callbacks for services
400 extern serviceCBsList_t *serviceCBsList;
401 
402 /*********************************************************************
403  * API FUNCTIONS
404  */
405 
420 extern void GATTServApp_RegisterForMsg( uint8 taskID );
421 
438  uint16 numAttrs, uint8 encKeySize,
439  CONST gattServiceCBs_t *pServiceCBs );
453 bStatus_t GATTServApp_DeregisterService( uint16 handle, gattAttribute_t **p2pAttrs );
454 
466  uint16 numAttrs, uint8 *pValue );
478 extern bStatus_t GATTServApp_AddService( uint32 services );
479 
489 extern bStatus_t GATTServApp_DelService( uint32 services );
490 
507 extern bStatus_t GATTServApp_SetParameter( uint8 param, uint8 len, void *pValue );
508 
521 extern bStatus_t GATTServApp_GetParameter( uint8 param, void *pValue );
522 
536 extern bStatus_t GATTServApp_UpdateCharCfg( uint16 connHandle, uint16 attrHandle, uint16 value );
537 
551 extern void GATTServApp_InitCharCfg( uint16 connHandle, gattCharCfg_t *charCfgTbl );
552 
567 extern uint16 GATTServApp_ReadCharCfg( uint16 connHandle, gattCharCfg_t *charCfgTbl );
568 
584 extern uint8 GATTServApp_WriteCharCfg( uint16 connHandle, gattCharCfg_t *charCfgTbl, uint16 value );
585 
599 extern bStatus_t GATTServApp_ProcessCCCWriteReq( uint16 connHandle, gattAttribute_t *pAttr,
600  uint8 *pValue, uint16 len, uint16 offset,
601  uint16 validCfg );
602 
616 extern bStatus_t GATTServApp_ProcessCharCfg( gattCharCfg_t *charCfgTbl, uint8 *pValue,
617  uint8 authenticated, gattAttribute_t *attrTbl,
618  uint16 numAttrs, uint8 taskId,
619  pfnGATTReadAttrCB_t pfnReadAttrCB );
620 
631 extern void GATTServApp_SendCCCUpdatedEvent( uint16 connHandle, uint16 attrHandle, uint16 value );
632 
646 extern bStatus_t GATTServApp_SendServiceChangedInd( uint16 connHandle, uint8 taskId );
647 
664 extern uint8 GATTServApp_ReadAttr( uint16 connHandle, gattAttribute_t *pAttr,
665  uint16 service, uint8 *pValue, uint16 *pLen,
666  uint16 offset, uint16 maxLen, uint8 method );
667 
680 extern uint8 GATTServApp_WriteAttr( uint16 connHandle, uint16 handle,
681  uint8 *pValue, uint16 len, uint16 offset,
682  uint8 method );
683 
697 extern bStatus_t GATTServApp_ReadRsp( uint16 connHandle, uint8 *pValue,
698  uint16 pLen, uint16 offset );
699 
712 extern void GATTServApp_SetParamValue( uint16 value );
713 
721 extern uint16 GATTServApp_GetParamValue( void );
722 
723 /*-------------------------------------------------------------------
724  * TASK API - These functions must only be called by OSAL.
725  */
726 
737 extern void GATTServApp_Init( uint8 taskId );
738 
752 extern uint16 GATTServApp_ProcessEvent( uint8 taskId, uint16 events );
753 
763 extern pfnGATTAuthorizeAttrCB_t gattServApp_FindAuthorizeAttrCB( uint16 handle );
764 
775 extern bStatus_t gattServApp_EnqueuePrepareWriteReq( uint16 connHandle, attPrepareWriteReq_t *pReq );
776 
788 extern bStatus_t gattServApp_ProcessWriteLong( gattMsgEvent_t *pMsg, prepareWrites_t *pQueue, uint16 *pErrHandle );
789 
801 extern bStatus_t gattServApp_ProcessReliableWrites( gattMsgEvent_t *pMsg, prepareWrites_t *pQueue, uint16 *pErrHandle );
802 
816 extern bStatus_t gattServApp_buildReadByTypeRsp( uint16 connHandle, uint8 *pAttrValue, uint16 attrLen, uint16 attrHandle );
817 
827 extern prepareWrites_t *gattServApp_FindPrepareWriteQ( uint16 connHandle );
828 
839 extern uint8 gattServApp_IsWriteLong( attExecuteWriteReq_t *pReq, prepareWrites_t *pQueue );
840 
850 extern void gattServApp_ClearPrepareWriteQ( prepareWrites_t *pQueue );
851 
852 /*********************************************************************
853 *********************************************************************/
854 
855 #ifdef __cplusplus
856 }
857 #endif
858 
859 #endif /* GATTSERVAPP_H */
uint8 GATTServApp_WriteCharCfg(uint16 connHandle, gattCharCfg_t *charCfgTbl, uint16 value)
Write the client characteristic configuration for a given client.
uint8 nameSpace
Name space of the description.
Definition: gattservapp.h:323
Definition: gattservapp.h:386
pfnGATTWriteAttrCB_t pfnWriteAttrCB
Write callback function pointer.
Definition: gattservapp.h:343
uint8 GATTServApp_ReadAttr(uint16 connHandle, gattAttribute_t *pAttr, uint16 service, uint8 *pValue, uint16 *pLen, uint16 offset, uint16 maxLen, uint8 method)
Read an attribute. If the format of the attribute value is unknown to GATT Server, use the callback function provided by the Service.
bStatus_t(* pfnGATTReadAttrCB_t)(uint16 connHandle, gattAttribute_t *pAttr, uint8 *pValue, uint16 *pLen, uint16 offset, uint16 maxLen, uint8 method)
Callback function prototype to read an attribute value.
Definition: gattservapp.h:261
osal_event_hdr_t hdr
GATT_SERV_MSG_EVENT and status.
Definition: gattservapp.h:363
int8 exponent
A sign integer which represents the exponent of an integer.
Definition: gattservapp.h:321
Definition: gattservapp.h:372
bStatus_t(* pfnGATTWriteAttrCB_t)(uint16 connHandle, gattAttribute_t *pAttr, uint8 *pValue, uint16 len, uint16 offset, uint8 method)
Callback function prototype to write an attribute value.
Definition: gattservapp.h:295
bStatus_t GATTServApp_ProcessCharCfg(gattCharCfg_t *charCfgTbl, uint8 *pValue, uint8 authenticated, gattAttribute_t *attrTbl, uint16 numAttrs, uint8 taskId, pfnGATTReadAttrCB_t pfnReadAttrCB)
Process Client Characteristic Configuration change.
bStatus_t GATTServApp_DeregisterService(uint16 handle, gattAttribute_t **p2pAttrs)
Deregister a service&#39;s attribute list and callback functions from the GATT Server Application...
Definition: gattservapp.h:340
bStatus_t GATTServApp_RegisterService(gattAttribute_t *pAttrs, uint16 numAttrs, uint8 encKeySize, CONST gattServiceCBs_t *pServiceCBs)
Register a service&#39;s attribute list and callback functions with the GATT Server Application.
gattAttribute_t * GATTServApp_FindAttr(gattAttribute_t *pAttrTbl, uint16 numAttrs, uint8 *pValue)
Find the attribute record within a service attribute table for a given attribute value pointer...
uint8 value
Characteristic configuration value for this client.
Definition: gattservapp.h:333
Definition: gattservapp.h:379
void GATTServApp_InitCharCfg(uint16 connHandle, gattCharCfg_t *charCfgTbl)
Initialize the client characteristic configuration table.
uint16 connHandle
Connection message was received on.
Definition: gattservapp.h:364
uint8 method
GATT_CLIENT_CHAR_CFG_UPDATED_EVENT.
Definition: gattservapp.h:365
bStatus_t(* pfnGATTAuthorizeAttrCB_t)(uint16 connHandle, gattAttribute_t *pAttr, uint8 opcode)
Callback function prototype to authorize a Read or Write operation on a given attribute.
Definition: gattservapp.h:309
uint8 format
Format of the value of this characteristic.
Definition: gattservapp.h:320
void GATTServApp_RegisterForMsg(uint8 taskID)
Register your task ID to receive event messages from the GATT Server Application. ...
uint16 connHandle
Connection message was received on.
Definition: gattservapp.h:353
uint16 attrHandle
attribute handle
Definition: gattservapp.h:366
bStatus_t GATTServApp_SendServiceChangedInd(uint16 connHandle, uint8 taskId)
Send out a Service Changed Indication.
uint16 desc
Description of this attribute as defined in a higher layer profile.
Definition: gattservapp.h:324
Definition: gattservapp.h:330
pfnGATTReadAttrCB_t pfnReadAttrCB
Read callback function pointer.
Definition: gattservapp.h:342
uint16 GATTServApp_ReadCharCfg(uint16 connHandle, gattCharCfg_t *charCfgTbl)
Read the client characteristic configuration for a given client.
osal_event_hdr_t hdr
GATT_SERV_MSG_EVENT and status.
Definition: gattservapp.h:352
bStatus_t GATTServApp_DelService(uint32 services)
Delete function for the GATT Service.
Status_t bStatus_t
BLE Generic Status return: BLE Default BLE Status Values.
Definition: bcomdef.h:244
Definition: gattservapp.h:318
bStatus_t GATTServApp_SetParameter(uint8 param, uint8 len, void *pValue)
Set a GATT Server parameter.
bStatus_t GATTServApp_ReadRsp(uint16 connHandle, uint8 *pValue, uint16 pLen, uint16 offset)
If a service returns blePending to the read attribute call back invoked from GATTServApp, the service can later respond to with the value to be read using this API.
Definition: gattservapp.h:361
uint8 GATTServApp_WriteAttr(uint16 connHandle, uint16 handle, uint8 *pValue, uint16 len, uint16 offset, uint8 method)
Write attribute data.
bStatus_t GATTServApp_AddService(uint32 services)
Add function for the GATT Service.
Definition: osal.h:89
bStatus_t GATTServApp_ProcessCCCWriteReq(uint16 connHandle, gattAttribute_t *pAttr, uint8 *pValue, uint16 len, uint16 offset, uint16 validCfg)
Process the client characteristic configuration write request for a given client. ...
Definition: gattservapp.h:350
uint8 method
GATT type of command. Ref: GATT Server Message IDs.
Definition: gattservapp.h:354
uint16 value
attribute new value
Definition: gattservapp.h:367
bStatus_t GATTServApp_UpdateCharCfg(uint16 connHandle, uint16 attrHandle, uint16 value)
Update the Client Characteristic Configuration for a given Client.
Definition: att.h:560
uint16 connHandle
Client connection handle.
Definition: gattservapp.h:332
Definition: gatt.h:244
pfnGATTAuthorizeAttrCB_t pfnAuthorizeAttrCB
Authorization callback function pointer.
Definition: gattservapp.h:344
void GATTServApp_SendCCCUpdatedEvent(uint16 connHandle, uint16 attrHandle, uint16 value)
Build and send the GATT_CLIENT_CHAR_CFG_UPDATED_EVENT to the application.
bStatus_t GATTServApp_GetParameter(uint8 param, void *pValue)
Get a GATT Server parameter.
uint16 unit
Unit of this attribute as defined in the data dictionary.
Definition: gattservapp.h:322
Definition: gatt.h:224
Definition: att.h:538