BLE-Stack APIs  3.00.00
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
gattservapp.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2016, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 /*!*****************************************************************************
33  * @defgroup GATTServApp GATTServApp
34  * @brief This module implements the GATT Server App
35  * @{
36  * @file gattservapp.h
37  * @brief GATTServApp layer interface
38  */
39 
40 #ifndef GATTSERVAPP_H
41 #define GATTSERVAPP_H
42 
43 #ifdef __cplusplus
44 extern "C"
45 {
46 #endif
47 
48 /*********************************************************************
49  * INCLUDES
50  */
51 #include "bcomdef.h"
52 #include "osal.h"
53 
54 /*********************************************************************
55  * CONSTANTS
56  */
57 
66 #define GATT_CLIENT_CHAR_CFG_UPDATED_EVENT 0x00
67 
68 
75 #define GATT_PROP_BCAST 0x01
76 #define GATT_PROP_READ 0x02
77 #define GATT_PROP_WRITE_NO_RSP 0x04
78 #define GATT_PROP_WRITE 0x08
79 #define GATT_PROP_NOTIFY 0x10
80 #define GATT_PROP_INDICATE 0x20
81 #define GATT_PROP_AUTHEN 0x40
82 #define GATT_PROP_EXTENDED 0x80
83 
84 
90 #define GATT_EXT_PROP_RELIABLE_WRITE 0x0001
91 #define GATT_EXT_PROP_WRITABLE_AUX 0x0002
92 
93 
99 #define GATT_CLIENT_CFG_NOTIFY 0x0001
100 #define GATT_CLIENT_CFG_INDICATE 0x0002
101 
102 
108 #define GATT_SERV_CFG_BCAST 0x0001
109 
110 
112 #define GATT_CFG_NO_OPERATION 0x0000 // No operation
113 
118 #define GATT_FORMAT_BOOL 0x01
119 #define GATT_FORMAT_2BIT 0x02
120 #define GATT_FORMAT_NIBBLE 0x03
121 #define GATT_FORMAT_UINT8 0x04
122 #define GATT_FORMAT_UINT12 0x05
123 #define GATT_FORMAT_UINT16 0x06
124 #define GATT_FORMAT_UINT24 0x07
125 #define GATT_FORMAT_UINT32 0x08
126 #define GATT_FORMAT_UINT48 0x09
127 #define GATT_FORMAT_UINT64 0x0a
128 #define GATT_FORMAT_UINT128 0x0b
129 #define GATT_FORMAT_SINT8 0x0c
130 #define GATT_FORMAT_SINT12 0x0d
131 #define GATT_FORMAT_SINT16 0x0e
132 #define GATT_FORMAT_SINT24 0x0f
133 #define GATT_FORMAT_SINT32 0x10
134 #define GATT_FORMAT_SINT48 0x11
135 #define GATT_FORMAT_SINT64 0x12
136 #define GATT_FORMAT_SINT128 0x13
137 #define GATT_FORMAT_FLOAT32 0x14
138 #define GATT_FORMAT_FLOAT64 0x15
139 #define GATT_FORMAT_SFLOAT 0x16
140 #define GATT_FORMAT_FLOAT 0x17
141 #define GATT_FORMAT_DUINT16 0x18
142 #define GATT_FORMAT_UTF8S 0x19
143 #define GATT_FORMAT_UTF16S 0x1a
144 #define GATT_FORMAT_STRUCT 0x1b
145 
146 
151 #define GATT_NS_NONE 0x00
152 #define GATT_NS_BT_SIG 0x01
153 #define GATT_NS_BT_DESC_UNKNOWN 0x0000
154 
156 #define GATT_ALL_SERVICES 0xFFFFFFFF
158 
160 #define GATT_SERVICE 0x00000001
161 
163 #if defined ( TESTMODES )
164  // GATT Test Modes
165  #define GATT_TESTMODE_OFF 0 // Test mode off
166  #define GATT_TESTMODE_NO_RSP 1 // Ignore incoming request
167  #define GATT_TESTMODE_PREPARE_WRITE 2 // Forward Prepare Write Request right away
168  #define GATT_TESTMODE_MAX_MTU_SIZE 3 // Use Max ATT MTU size with Exchange MTU Rsp
169  #define GATT_TESTMODE_CORRUPT_PW_DATA 4 // Corrupt incoming Prepare Write Request data
170 #endif
171 
176 #define GATT_PARAM_NUM_PREPARE_WRITES 0 // RW uint8
177 
179 #define PTR_TYPE unsigned int *
182 
185 #define GATT_LOCAL_READ 0xFF
186 #define GATT_LOCAL_WRITE 0xFE
188 
191 /*********************************************************************
192  * VARIABLES
193  */
194 
195 /*********************************************************************
196  * MACROS
197  */
198 
200 #define GATT_NUM_ATTRS( attrs ) ( sizeof( attrs ) / sizeof( gattAttribute_t ) )
201 
203 #define GATT_SERVICE_HANDLE( attrs ) ( (attrs)[0].handle )
204 
206 #define GATT_INCLUDED_HANDLE( attrs, i ) ( *((uint16 *)((attrs)[(i)].pValue)) )
207 
209 #define GATT_CCC_TBL( pValue ) ( (gattCharCfg_t *)(*((PTR_TYPE)(pValue))) )
210 
211 /*********************************************************************
212  * TYPEDEFS
213  */
214 
250 typedef bStatus_t (*pfnGATTReadAttrCB_t)( uint16 connHandle, gattAttribute_t *pAttr,
251  uint8 *pValue, uint16 *pLen, uint16 offset,
252  uint16 maxLen, uint8 method );
253 
285 typedef bStatus_t (*pfnGATTWriteAttrCB_t)( uint16 connHandle, gattAttribute_t *pAttr,
286  uint8 *pValue, uint16 len, uint16 offset,
287  uint8 method );
299 typedef bStatus_t (*pfnGATTAuthorizeAttrCB_t)( uint16 connHandle, gattAttribute_t *pAttr,
300  uint8 opcode );
301 
308 typedef struct
310 {
311  uint8 format;
312  int8 exponent;
313  uint16 unit;
314  uint8 nameSpace;
315  uint16 desc;
317 
319 typedef struct
320 {
321  uint16 connHandle;
322  uint8 value;
323 } gattCharCfg_t;
324 
331 typedef struct
332 {
337 
339 typedef struct
340 {
342  uint16 connHandle;
343  uint8 method;
345 
352 typedef struct
353 {
355  uint16 connHandle;
356  uint8 method;
357  uint16 attrHandle;
358  uint16 value;
360 
361 
363 typedef struct
364 {
365  uint16 connHandle; // connection message was received on
366  attPrepareWriteReq_t *pPrepareWriteQ; // Prepare Write Request queue
368 
370 typedef struct
371 {
372  uint16 handle; // Service handle - assigned internally by GATT Server
373  CONST gattServiceCBs_t *pCBs; // Service callback function pointers
375 
377 typedef struct _serviceCBsList
378 {
379  struct _serviceCBsList *next; // pointer to next service callbacks record
380  gattServiceCBsInfo_t serviceInfo; // service handle/callbacks
382 
383 
384 /*********************************************************************
385  * VARIABLES
386  */
387 
390 
393 
396 /*********************************************************************
397  * API FUNCTIONS
398  */
399 
406 extern void GATTServApp_RegisterForMsg( uint8 taskID );
407 
424  uint16 numAttrs, uint8 encKeySize,
425  CONST gattServiceCBs_t *pServiceCBs );
426 
441 bStatus_t GATTServApp_DeregisterService( uint16 handle, gattAttribute_t **p2pAttrs );
442 
455  uint16 numAttrs, uint8 *pValue );
467 extern bStatus_t GATTServApp_AddService( uint32 services );
468 
478 extern bStatus_t GATTServApp_DelService( uint32 services );
479 
496 extern bStatus_t GATTServApp_SetParameter( uint8 param, uint8 len, void *pValue );
497 
510 extern bStatus_t GATTServApp_GetParameter( uint8 param, void *pValue );
511 
526 extern bStatus_t GATTServApp_UpdateCharCfg( uint16 connHandle, uint16 attrHandle, uint16 value );
527 
540 extern void GATTServApp_InitCharCfg( uint16 connHandle, gattCharCfg_t *charCfgTbl );
541 
557 extern uint16 GATTServApp_ReadCharCfg( uint16 connHandle, gattCharCfg_t *charCfgTbl );
558 
575 extern uint8 GATTServApp_WriteCharCfg( uint16 connHandle, gattCharCfg_t *charCfgTbl, uint16 value );
576 
595 extern bStatus_t GATTServApp_ProcessCCCWriteReq( uint16 connHandle, gattAttribute_t *pAttr,
596  uint8 *pValue, uint16 len, uint16 offset,
597  uint16 validCfg );
598 
617 extern bStatus_t GATTServApp_ProcessCharCfg( gattCharCfg_t *charCfgTbl, uint8 *pValue,
618  uint8 authenticated, gattAttribute_t *attrTbl,
619  uint16 numAttrs, uint8 taskId,
620  pfnGATTReadAttrCB_t pfnReadAttrCB );
621 
630 extern void GATTServApp_SendCCCUpdatedEvent( uint16 connHandle, uint16 attrHandle, uint16 value );
631 
645 extern bStatus_t GATTServApp_SendServiceChangedInd( uint16 connHandle, uint8 taskId );
646 
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 
681 extern uint8 GATTServApp_WriteAttr( uint16 connHandle, uint16 handle,
682  uint8 *pValue, uint16 len, uint16 offset,
683  uint8 method );
684 
698 extern bStatus_t GATTServApp_ReadRsp( uint16 connHandle, uint8 *pValue,
699  uint16 pLen, uint16 offset );
700 
707 extern void GATTServApp_SetParamValue( uint16 value );
708 
714 extern uint16 GATTServApp_GetParamValue( void );
715 
716 /*-------------------------------------------------------------------
717  * TASK API - These functions must only be called by OSAL.
718  */
719 
721 
732 extern void GATTServApp_Init( uint8 taskId );
733 
745 extern uint16 GATTServApp_ProcessEvent( uint8 taskId, uint16 events );
746 
756 extern pfnGATTAuthorizeAttrCB_t gattServApp_FindAuthorizeAttrCB( uint16 handle );
757 
768 extern bStatus_t gattServApp_EnqueuePrepareWriteReq( uint16 connHandle, attPrepareWriteReq_t *pReq );
769 
781 extern bStatus_t gattServApp_ProcessWriteLong( gattMsgEvent_t *pMsg, prepareWrites_t *pQueue, uint16 *pErrHandle );
782 
794 extern bStatus_t gattServApp_ProcessReliableWrites( gattMsgEvent_t *pMsg, prepareWrites_t *pQueue, uint16 *pErrHandle );
795 
809 extern bStatus_t gattServApp_buildReadByTypeRsp( uint16 connHandle, uint8 *pAttrValue, uint16 attrLen, uint16 attrHandle );
810 
820 extern prepareWrites_t *gattServApp_FindPrepareWriteQ( uint16 connHandle );
821 
832 extern uint8 gattServApp_IsWriteLong( attExecuteWriteReq_t *pReq, prepareWrites_t *pQueue );
833 
841 extern void gattServApp_ClearPrepareWriteQ( prepareWrites_t *pQueue );
842 
844 
845 /*********************************************************************
846 *********************************************************************/
847 
848 #ifdef __cplusplus
849 }
850 #endif
851 
852 #endif /* GATTSERVAPP_H */
853 
uint16 GATTServApp_GetParamValue(void)
Get a GATT Server Application Parameter value.
GATT Structure for Characteristic Presentation Format Value.
Definition: gattservapp.h:309
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:342
GATT Server App event header format.
Definition: gattservapp.h:339
void GATTServApp_SetParamValue(uint16 value)
Set a GATT Server Application Parameter value. Use this function to change the default GATT parameter...
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:335
Service callbacks list item.
Definition: gattservapp.h:377
void GATTServApp_SendCCCUpdatedEvent(uint16 connHandle, uint16 attrHandle, uint16 value)
Build and send the GATT_CLIENT_CHAR_CFG_UPDATED_EVENT to the application.
Structure to keep Prepare Write Requests for each Client.
Definition: gattservapp.h:363
bStatus_t GATTServApp_GetParameter(uint8 param, void *pValue)
Get a GATT Server parameter.
pfnGATTWriteAttrCB_t pfnWriteAttrCB
Write callback function pointer.
Definition: gattservapp.h:334
prepareWrites_t * prepareWritesTbl
Server Prepare Write table (one entry per each physical link)
GATT Structure to keep CBs information for each service being registered.
Definition: gattservapp.h:370
uint8 value
Characteristic configuration value for this client.
Definition: gattservapp.h:322
bStatus_t GATTServApp_AddService(uint32 services)
Add function for the GATT 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:250
pfnGATTReadAttrCB_t pfnReadAttrCB
Read callback function pointer.
Definition: gattservapp.h:333
uint8 format
Format of the value of this characteristic.
Definition: gattservapp.h:311
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:285
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.
uint8 GATTServApp_WriteAttr(uint16 connHandle, uint16 handle, uint8 *pValue, uint16 len, uint16 offset, uint8 method)
Write attribute data.
Structure for Client Characteristic Configuration.
Definition: gattservapp.h:319
osal_event_hdr_t hdr
GATT_SERV_MSG_EVENT and status.
Definition: gattservapp.h:341
uint16 connHandle
Client connection handle.
Definition: gattservapp.h:321
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. ...
void GATTServApp_InitCharCfg(uint16 connHandle, gattCharCfg_t *charCfgTbl)
Initialize the client characteristic configuration table.
uint16 value
attribute new value
Definition: gattservapp.h:358
uint16 connHandle
Connection message was received on.
Definition: gattservapp.h:355
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 attrHandle
attribute handle
Definition: gattservapp.h:357
serviceCBsList_t * serviceCBsList
Callbacks for services.
OSAL Event Header.
Definition: osal.h:110
GATT_CLIENT_CHAR_CFG_UPDATED_EVENT message format.
Definition: gattservapp.h:352
uint16 unit
Unit of this attribute as defined in the data dictionary.
Definition: gattservapp.h:313
uint8 nameSpace
Name space of the description.
Definition: gattservapp.h:314
struct _serviceCBsList serviceCBsList_t
Service callbacks list item.
GATT GATT_MSG_EVENT message format.
Definition: gatt.h:231
uint8 method
GATT type of command. Ref: GATT Server Message IDs.
Definition: gattservapp.h:343
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.
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:354
GATT Attribute format.
Definition: gatt.h:260
Status_t bStatus_t
BLE Generic Status return.
Definition: bcomdef.h:243
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:299
uint16 desc
Description of this attribute as defined in a higher layer profile.
Definition: gattservapp.h:315
Prepare Write Request format.
Definition: att.h:553
uint8 method
GATT_CLIENT_CHAR_CFG_UPDATED_EVENT.
Definition: gattservapp.h:356
int8 exponent
A sign integer which represents the exponent of an integer.
Definition: gattservapp.h:312
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:331
Execute Write Request format.
Definition: att.h:579
bStatus_t GATTServApp_DeregisterService(uint16 handle, gattAttribute_t **p2pAttrs)
Deregister a service's attribute list and callback functions from the GATT Server Application...
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 2016, Texas Instruments Incorporated