TI BLE5-Stack API Documentation  9.12.00
gattservapp.h
Go to the documentation of this file.
1 /******************************************************************************
2 
3  Group: WCS, BTS
4  $Target Device: DEVICES $
5 
6  ******************************************************************************
7  $License: TI_TEXT 2009 $
8  ******************************************************************************
9  $Release Name: PACKAGE NAME $
10  $Release Date: PACKAGE RELEASE DATE $
11  *****************************************************************************/
12 
21 #ifndef GATTSERVAPP_H
22 #define GATTSERVAPP_H
23 
24 #ifdef __cplusplus
25 extern "C"
26 {
27 #endif
28 
29 /*********************************************************************
30  * INCLUDES
31  */
34 
35 /*********************************************************************
36  * CONSTANTS
37  */
38 
49 #define GATT_CLIENT_CHAR_CFG_UPDATED_EVENT 0x00
50 
51 
59 #define GATT_PROP_BCAST 0x01
60 #define GATT_PROP_READ 0x02
61 #define GATT_PROP_WRITE_NO_RSP 0x04
62 #define GATT_PROP_WRITE 0x08
63 #define GATT_PROP_NOTIFY 0x10
64 #define GATT_PROP_INDICATE 0x20
65 #define GATT_PROP_AUTHEN 0x40
66 #define GATT_PROP_EXTENDED 0x80
67 
68 
75 #define GATT_EXT_PROP_RELIABLE_WRITE 0x0001
76 #define GATT_EXT_PROP_WRITABLE_AUX 0x0002
77 
78 
85 #define GATT_CLIENT_CFG_NOTIFY 0x0001
86 #define GATT_CLIENT_CFG_INDICATE 0x0002
87 
88 
95 #define GATT_SERV_CFG_BCAST 0x0001
96 
97 
99 #define GATT_CFG_NO_OPERATION 0x0000
100 
101 
106 #define GATT_FORMAT_BOOL 0x01
107 #define GATT_FORMAT_2BIT 0x02
108 #define GATT_FORMAT_NIBBLE 0x03
109 #define GATT_FORMAT_UINT8 0x04
110 #define GATT_FORMAT_UINT12 0x05
111 #define GATT_FORMAT_UINT16 0x06
112 #define GATT_FORMAT_UINT24 0x07
113 #define GATT_FORMAT_UINT32 0x08
114 #define GATT_FORMAT_UINT48 0x09
115 #define GATT_FORMAT_UINT64 0x0a
116 #define GATT_FORMAT_UINT128 0x0b
117 #define GATT_FORMAT_SINT8 0x0c
118 #define GATT_FORMAT_SINT12 0x0d
119 #define GATT_FORMAT_SINT16 0x0e
120 #define GATT_FORMAT_SINT24 0x0f
121 #define GATT_FORMAT_SINT32 0x10
122 #define GATT_FORMAT_SINT48 0x11
123 #define GATT_FORMAT_SINT64 0x12
124 #define GATT_FORMAT_SINT128 0x13
125 #define GATT_FORMAT_FLOAT32 0x14
126 #define GATT_FORMAT_FLOAT64 0x15
127 #define GATT_FORMAT_SFLOAT 0x16
128 #define GATT_FORMAT_FLOAT 0x17
129 #define GATT_FORMAT_DUINT16 0x18
130 #define GATT_FORMAT_UTF8S 0x19
131 #define GATT_FORMAT_UTF16S 0x1a
132 #define GATT_FORMAT_STRUCT 0x1b
133 
134 
140 #define GATT_NS_NONE 0x00
141 #define GATT_NS_BT_SIG 0x01
142 #define GATT_NS_BT_DESC_UNKNOWN 0x0000
143 
145 #define GATT_ALL_SERVICES 0xFFFFFFFF
147 
149 #define GATT_SERVICE 0x00000001
150 
152 #if defined ( TESTMODES )
153  // GATT Test Modes
154  #define GATT_TESTMODE_OFF 0 // Test mode off
155  #define GATT_TESTMODE_NO_RSP 1 // Ignore incoming request
156  #define GATT_TESTMODE_PREPARE_WRITE 2 // Forward Prepare Write Request right away
157  #define GATT_TESTMODE_MAX_MTU_SIZE 3 // Use Max ATT MTU size with Exchange MTU Rsp
158  #define GATT_TESTMODE_CORRUPT_PW_DATA 4 // Corrupt incoming Prepare Write Request data
159 #endif
160 
166 #define GATT_PARAM_NUM_PREPARE_WRITES 0
167 
169 #define PTR_TYPE unsigned int *
172 
175 #define GATT_LOCAL_READ 0xFF
176 #define GATT_LOCAL_WRITE 0xFE
178 
181 /*********************************************************************
182  * VARIABLES
183  */
184 
185 /*********************************************************************
186  * MACROS
187  */
188 
190 #define GATT_NUM_ATTRS( attrs ) ( sizeof( attrs ) / sizeof( gattAttribute_t ) )
191 
193 #define GATT_SERVICE_HANDLE( attrs ) ( (attrs)[0].handle )
194 
196 #define GATT_INCLUDED_HANDLE( attrs, i ) ( *((uint16 *)((attrs)[(i)].pValue)) )
197 
199 #define GATT_CCC_TBL( pValue ) ( (gattCharCfg_t *)(*((PTR_TYPE)(pValue))) )
200 
202 #define GATT_ATT_BT_UUID_TYPE(type) {ATT_BT_UUID_SIZE,type}
203 
205 #define GATT_ATT_UUID_TYPE(type) {ATT_UUID_SIZE,type}
206 
208 #define GATT_BT_UUID(name, UUID) uint8 name[ATT_BT_UUID_SIZE] =\
209 {\
210  LO_UINT16(UUID), HI_UINT16(UUID)\
211 }
212 
214 #define GATT_UUID(name, UUID) const uint8 name[ATT_UUID_SIZE] =\
215 {\
216  TI_BASE_UUID_128(UUID)\
217 }
218 
220 #define GATT_BT_ATT(type, permission, value)\
221 {\
222  GATT_ATT_BT_UUID_TYPE(type),\
223  permission,\
224  0,\
225  value\
226 }
227 
229 #define GATT_ATT(type, permission, value)\
230 {\
231  GATT_ATT_UUID_TYPE(type),\
232  permission,\
233  0,\
234  value\
235 }
236 
237 /*********************************************************************
238  * TYPEDEFS
239  */
240 
277 typedef bStatus_t (*pfnGATTReadAttrCB_t)( uint16 connHandle, gattAttribute_t *pAttr,
278  uint8 *pValue, uint16 *pLen, uint16 offset,
279  uint16 maxLen, uint8 method );
280 
312 typedef bStatus_t (*pfnGATTWriteAttrCB_t)( uint16 connHandle, gattAttribute_t *pAttr,
313  uint8 *pValue, uint16 len, uint16 offset,
314  uint8 method );
326 typedef bStatus_t (*pfnGATTAuthorizeAttrCB_t)( uint16 connHandle, gattAttribute_t *pAttr,
327  uint8 opcode );
328 
336 typedef struct
338 {
339  uint8 format;
340  int8 exponent;
341  uint16 unit;
342  uint8 nameSpace;
343  uint16 desc;
345 
347 typedef struct
348 {
349  uint16 connHandle;
350  uint8 value;
351 } gattCharCfg_t;
352 
359 typedef struct
360 {
365 
367 typedef struct
368 {
370  uint16 connHandle;
371  uint8 method;
373 
380 typedef struct
381 {
383  uint16 connHandle;
384  uint8 method;
385  uint16 attrHandle;
386  uint16 value;
388 
389 
391 typedef struct
392 {
393  uint16 connHandle;
396 
398 typedef struct
399 {
400  uint16 handle;
403 
405 typedef struct _serviceCBsList
406 {
410 
411 
412 /*********************************************************************
413  * VARIABLES
414  */
415 
418 /*********************************************************************
419  * API FUNCTIONS
420  */
421 
428 extern void GATTServApp_RegisterForMsg( uint8 taskID );
429 
446  uint16 numAttrs, uint8 encKeySize,
447  const gattServiceCBs_t *pServiceCBs );
448 
463 bStatus_t GATTServApp_DeregisterService( uint16 handle, gattAttribute_t **p2pAttrs );
464 
477  uint16 numAttrs, uint8 *pValue );
489 extern bStatus_t GATTServApp_AddService( uint32 services );
490 
500 extern bStatus_t GATTServApp_DelService( uint32 services );
501 
518 extern bStatus_t GATTServApp_SetParameter( uint8 param, uint8 len, void *pValue );
519 
532 extern bStatus_t GATTServApp_GetParameter( uint8 param, void *pValue );
533 
548 extern bStatus_t GATTServApp_UpdateCharCfg( uint16 connHandle, uint16 attrHandle, uint16 value );
549 
562 extern void GATTServApp_InitCharCfg( uint16 connHandle, gattCharCfg_t *charCfgTbl );
563 
579 extern uint16 GATTServApp_ReadCharCfg( uint16 connHandle, gattCharCfg_t *charCfgTbl );
580 
597 extern uint8 GATTServApp_WriteCharCfg( uint16 connHandle, gattCharCfg_t *charCfgTbl, uint16 value );
598 
617 extern bStatus_t GATTServApp_ProcessCCCWriteReq( uint16 connHandle, gattAttribute_t *pAttr,
618  uint8 *pValue, uint16 len, uint16 offset,
619  uint16 validCfg );
620 
639 extern bStatus_t GATTServApp_ProcessCharCfg( gattCharCfg_t *charCfgTbl, uint8 *pValue,
640  uint8 authenticated, gattAttribute_t *attrTbl,
641  uint16 numAttrs, uint8 taskId,
642  pfnGATTReadAttrCB_t pfnReadAttrCB );
643 
652 extern void GATTServApp_SendCCCUpdatedEvent( uint16 connHandle, uint16 attrHandle, uint16 value );
653 
667 extern bStatus_t GATTServApp_SendServiceChangedInd( uint16 connHandle, uint8 taskId );
668 
686 extern uint8 GATTServApp_ReadAttr( uint16 connHandle, gattAttribute_t *pAttr,
687  uint16 service, uint8 *pValue, uint16 *pLen,
688  uint16 offset, uint16 maxLen, uint8 method );
689 
703 extern uint8 GATTServApp_WriteAttr( uint16 connHandle, uint16 handle,
704  uint8 *pValue, uint16 len, uint16 offset,
705  uint8 method );
706 
720 extern bStatus_t GATTServApp_ReadRsp( uint16 connHandle, uint8 *pValue,
721  uint16 pLen, uint16 attrHandle );
722 
723 #if defined ( TESTMODES )
724 
730 extern void GATTServApp_SetParamValue( uint16 value );
731 
737 extern uint16 GATTServApp_GetParamValue( void );
738 #endif
739 
740 /*-------------------------------------------------------------------
741  * TASK API - These functions must only be called by OSAL.
742  */
743 
745 
756 extern void GATTServApp_Init( uint8 taskId, uint8_t cfg_GATTServApp_att_delayed_req, uint8_t cfg_gapBond_gatt_no_service_changed, uint8_t cfg_gatt_max_num_prepare_writes );
757 
769 extern uint32 GATTServApp_ProcessEvent( uint8 taskId, uint32 events );
770 
780 extern pfnGATTAuthorizeAttrCB_t gattServApp_FindAuthorizeAttrCB( uint16 handle );
781 
782 
795 extern bStatus_t gattServApp_EnqueueReTx( uint16 connHandle, uint8 method,
796  gattMsg_t *pMsg );
797 
799 
800 /*********************************************************************
801 *********************************************************************/
802 
803 #ifdef __cplusplus
804 }
805 #endif
806 
807 #endif /* GATTSERVAPP_H */
808 
GATT Structure for Characteristic Presentation Format Value.
Definition: gattservapp.h:337
This API allows the software components in the Z-Stack to be written independently of the specifics o...
uint16 connHandle
Connection message was received on.
Definition: gattservapp.h:370
gattServiceCBsInfo_t serviceInfo
service handle/callbacks
Definition: gattservapp.h:408
GATT Server App event header format.
Definition: gattservapp.h:367
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...
pfnGATTAuthorizeAttrCB_t pfnAuthorizeAttrCB
Authorization callback function pointer.
Definition: gattservapp.h:363
Service callbacks list item.
Definition: gattservapp.h:405
void GATTServApp_SendCCCUpdatedEvent(uint16 connHandle, uint16 attrHandle, uint16 value)
Build and send the GATT_CLIENT_CHAR_CFG_UPDATED_EVENT to the application.
uint16 handle
Service handle - assigned internally by GATT Server.
Definition: gattservapp.h:400
Structure to keep Prepare Write Requests for each Client.
Definition: gattservapp.h:391
bStatus_t GATTServApp_GetParameter(uint8 param, void *pValue)
Get a GATT Server parameter.
pfnGATTWriteAttrCB_t pfnWriteAttrCB
Write callback function pointer.
Definition: gattservapp.h:362
GATT Structure to keep CBs information for each service being registered.
Definition: gattservapp.h:398
uint8 value
Characteristic configuration value for this client.
Definition: gattservapp.h:350
bStatus_t GATTServApp_AddService(uint32 services)
Add function for the GATT Service.
pfnGATTReadAttrCB_t pfnReadAttrCB
Read callback function pointer.
Definition: gattservapp.h:361
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:277
uint8 format
Format of the value of this characteristic.
Definition: gattservapp.h:339
GATT Message format.
Definition: gatt.h:170
uint8 GATTServApp_WriteAttr(uint16 connHandle, uint16 handle, uint8 *pValue, uint16 len, uint16 offset, uint8 method)
Write attribute data.
struct _serviceCBsList * next
pointer to next service callbacks record
Definition: gattservapp.h:407
Structure for Client Characteristic Configuration.
Definition: gattservapp.h:347
osal_event_hdr_t hdr
GATT_SERV_MSG_EVENT and status.
Definition: gattservapp.h:369
uint16 connHandle
Client connection handle.
Definition: gattservapp.h:349
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.
uint16 GATTServApp_ReadCharCfg(uint16 connHandle, gattCharCfg_t *charCfgTbl)
Read the client characteristic configuration for a given client.
void GATTServApp_RegisterForMsg(uint8 taskID)
Register your task ID to receive event messages from the GATT Server Application. ...
attPrepareWriteReq_t * pPrepareWriteQ
Prepare Write Request queue.
Definition: gattservapp.h:394
bStatus_t GATTServApp_ReadRsp(uint16 connHandle, uint8 *pValue, uint16 pLen, uint16 attrHandle)
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.
void GATTServApp_InitCharCfg(uint16 connHandle, gattCharCfg_t *charCfgTbl)
Initialize the client characteristic configuration table.
uint16 value
attribute new value
Definition: gattservapp.h:386
uint16 connHandle
Connection message was received on.
Definition: gattservapp.h:383
bStatus_t GATTServApp_RegisterService(gattAttribute_t *pAttrs, uint16 numAttrs, uint8 encKeySize, const gattServiceCBs_t *pServiceCBs)
Register a service's attribute list and callback functions with the GATT Server Application.
Type definitions and macros for BLE stack.
bStatus_t GATTServApp_SetParameter(uint8 param, uint8 len, void *pValue)
Set a GATT Server parameter.
bStatus_t GATTServApp_SendServiceChangedInd(uint16 connHandle, uint8 taskId)
Send out a Service Changed Indication.
bStatus_t GATTServApp_DelService(uint32 services)
Delete function for the GATT Service.
uint16 connHandle
connection message was received on
Definition: gattservapp.h:393
uint16 attrHandle
attribute handle
Definition: gattservapp.h:385
OSAL Event Header.
Definition: osal.h:124
GATT_CLIENT_CHAR_CFG_UPDATED_EVENT message format.
Definition: gattservapp.h:380
uint16 unit
Unit of this attribute as defined in the data dictionary.
Definition: gattservapp.h:341
uint8 nameSpace
Name space of the description.
Definition: gattservapp.h:342
struct _serviceCBsList serviceCBsList_t
Service callbacks list item.
uint8 method
GATT type of command. Ref: GATT Server Message IDs.
Definition: gattservapp.h:371
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. ...
osal_event_hdr_t hdr
GATT_SERV_MSG_EVENT and status.
Definition: gattservapp.h:382
GATT Attribute format.
Definition: gatt.h:245
const gattServiceCBs_t * pCBs
Service callback function pointers.
Definition: gattservapp.h:401
uint16 desc
Description of this attribute as defined in a higher layer profile.
Definition: gattservapp.h:343
Prepare Write Request format.
Definition: att.h:566
uint8 method
GATT_CLIENT_CHAR_CFG_UPDATED_EVENT.
Definition: gattservapp.h:384
int8 exponent
A sign integer which represents the exponent of an integer.
Definition: gattservapp.h:340
uint8_t bStatus_t
BLE Generic Status return.
Definition: bcomdef.h:246
bStatus_t GATTServApp_UpdateCharCfg(uint16 connHandle, uint16 attrHandle, uint16 value)
Update the Client Characteristic Configuration for a given Client.
uint8 GATTServApp_WriteCharCfg(uint16 connHandle, gattCharCfg_t *charCfgTbl, uint16 value)
Write the client characteristic configuration for a given client.
GATT Structure for service callback functions.
Definition: gattservapp.h:359
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:326
bStatus_t GATTServApp_DeregisterService(uint16 handle, gattAttribute_t **p2pAttrs)
Deregister a service's attribute list and callback functions from the GATT Server Application...
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:312
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.
© Copyright 1995-2025, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale