gatt-service.h
4.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#ifndef GATT_SERVICE_H
#define GATT_SERVICE_H
/*********************************************************************
* MACROS
*/
// The number of attribute records in a given attribute table
#define GATT_NUM_ATTRS( attrs ) ( sizeof( attrs ) / sizeof( gattAttribute_t ) )
// The handle of a service is the handle of the first attribute
#define GATT_SERVICE_HANDLE( attrs ) ( (attrs)[0].handle )
// The handle of the first included service (i = 1) is the value of the second attribute
#define GATT_INCLUDED_HANDLE( attrs, i ) ( *((uint16 *)((attrs)[(i)].pValue)) )
/*********************************************************************
* TYPEDEFS
*/
#define bStatus_t bool
#define INVALID_CONNHANDLE 0xFFFF
#define SUCCESS 0x00
#define FAILURE 0x01
#define MAX_GATT_SERVICES 0x0C
/**
* @defgroup GATT_SERV_APP_CB_API GATT Server App Callback API Functions
*
* @{
*/
/**
* @brief Callback function prototype to read an attribute value.
*
* @param pConn - connection chan request was received on
* @param pAttr - pointer to attribute
* @param pValue - pointer to data to be read (to be returned)
* @param pLen - length of data (to be returned)
* @param offset - offset of the first octet to be read
* @param maxLen - maximum length of data to be read
*
* @return SUCCESS: Read was successfully.<BR>
* Error, otherwise: ref ATT_ERR_CODE_DEFINES.<BR>
*/
typedef bStatus_t (*pfnGATTReadAttrCB_t)( GAttrib *pConn, gattAttribute_t *pAttr,
uint8_t *pValue, uint8_t *pLen, uint16_t offset,
uint8_t maxLen );
/**
* @brief Callback function prototype to write an attribute value.
*
* @param pConn - connection chan request was received on
* @param pAttr - pointer to attribute
* @param pValue - pointer to data to be written
* @param pLen - length of data
* @param offset - offset of the first octet to be written
*
* @return SUCCESS: Write was successfully.<BR>
* Error, otherwise: ref ATT_ERR_CODE_DEFINES.<BR>
*/
typedef bStatus_t (*pfnGATTWriteAttrCB_t)( GAttrib *pConn, gattAttribute_t *pAttr,
uint8_t *pValue, uint8_t len, uint16_t offset );
/**
* @brief Callback function prototype to authorize a Read or Write operation
* on a given attribute.
*
* @param pConn - connection chan request was received on
* @param pAttr - pointer to attribute
* @param opcode - request opcode (ATT_READ_REQ or ATT_WRITE_REQ)
*
* @return SUCCESS: Operation authorized.<BR>
* ATT_ERR_INSUFFICIENT_AUTHOR: Authorization required.<BR>
*/
typedef bStatus_t (*pfnGATTAuthorizeAttrCB_t)( GAttrib *pConn, gattAttribute_t *pAttr,
uint8_t opcode );
typedef void (*GAttribServiceStart)(void);
typedef void (*GAttribServiceStop)(void);
//added by Optek
//typedef void (*GDestroyNotify)(gpointer user_data);
/**
* GATT Structure for service callback functions - must be setup by the application
* and used when GATTServApp_RegisterService() is called.
*/
typedef struct
{
GAttribServiceStart pfnAttrServiceStart; //BLE conn
GAttribServiceStop pfnAttrServiceStop; //BLE disconn
pfnGATTReadAttrCB_t pfnReadAttrCB; //!< Read callback function pointer
pfnGATTWriteAttrCB_t pfnWriteAttrCB; //!< Write callback function pointer
pfnGATTAuthorizeAttrCB_t pfnAuthorizeAttrCB; //!< Authorization callback function pointer
} gattServiceCBs_t;
typedef struct
{
gattAttribute_t *pGattAttribute;
uint16_t startHandle;
uint16_t numAttrs;
gattServiceCBs_t *pfnServiceCB;
} gattService_t;
extern gattService_t gattService[MAX_GATT_SERVICES];
/**
* @brief Initialize the client characteristic configuration table.
*
* Note: Each client has its own instantiation of the Client
* Characteristic Configuration. Reads/Writes of the Client
* Characteristic Configuration only only affect the
* configuration of that client.
*
* @param connHandle - connection handle (0xFFFF for all connections).
* @param charCfgTbl - client characteristic configuration table.
*
* @return none
*/
extern void GATTServApp_InitCharCfg( uint16_t connHandle, gattCharCfg_t *charCfgTbl );
/**
* @brief Register a service's attribute list and callback functions with
* the GATT Server Application.
*
* @param pAttrs - Array of attribute records to be registered
* @param numAttrs - Number of attributes in array
* @param pServiceCBs - Service callback function pointers
*
* @return SUCCESS: Service registered successfully.<BR>
* INVALIDPARAMETER: Invalid service field.<BR>
* FAILURE: Not enough attribute handles available.<BR>
* bleMemAllocError: Memory allocation error occurred.<BR>
*/
extern bStatus_t GATTServApp_RegisterService( gattAttribute_t *pAttrs, uint16_t numAttrs,
gattServiceCBs_t *pServiceCBs );
#endif