| Airoha M0 BLE API 1.0.5.4

att_private.h
1 /******************************************************************************
2 Copyright (c) Airoha 2016 - All rights reserved
3
4 FILE NAME
5 att_private.h
6 DESCRIPTION
7 NOTES
8 ********************************************************************************/
9 #ifndef _ATT_PRIVATE_H_
10 #define _ATT_PRIVATE_H_
11
12 #include <stdint.h>
13 #include "bt.h"
14 #include "ble_att.h"
15
16 #define FEA_SUPPORT_ATT_CLIENT_ROLE (1)//(FALSE)//
17 #define FEA_SUPPORT_APP_GATT_EVENT (1)//(FALSE)//
18
19 // ATT packet offset=========================================================
20
21 #define ATT_L2CAP_OPCODE_OFFSET 0
22 #define ATT_PARAM_OFFSET (ATT_L2CAP_OPCODE_OFFSET+1)
23 #define ATT_L2CAP_PACKET_LENGTH(ptr) (gATT_ctl.currPduLen)
24
25 //end ATT packet offset======================================================
26
27 #define UUID_TYPE(a) (uint8_t)(a->uuid_t.type)
28 #define UUID_uint16_t(a) (uint16_t)(a->uuid_t.uuid.uuid16)
29 #define UUID_PTR(a) (uint8_t *)(a->uuid_t.uuid.addr)
30
31
32 #define ATT_R_PMT(p) ((p)&0x0F)
33 #define ATT_W_PMT(p) ((p)&0xF0)
34
35 // ATT Methods Opcode========================================================
36 #define ATT_ERROR_RSP 0x01
37 #define ATT_EXCHANGE_MTU_REQ 0x02
38 #define ATT_EXCHANGE_MTU_RSP 0x03
39 #define ATT_FIND_INFO_REQ 0x04
40 #define ATT_FIND_INFO_RSP 0x05
41 #define ATT_FIND_BY_TYPE_VALUE_REQ 0x06
42 #define ATT_FIND_BY_TYPE_VALUE_RSP 0x07
43 #define ATT_READ_BY_TYPE_REQ 0x08
44 #define ATT_READ_BY_TYPE_RSP 0x09
45 #define ATT_READ_REQ 0x0A
46 #define ATT_READ_RSP 0x0B
47 #define ATT_READ_BLOB_REQ 0x0C
48 #define ATT_READ_BLOB_RSP 0x0D
49 #define ATT_READ_MULTI_REQ 0x0E
50 #define ATT_READ_MULTI_RSP 0x0F
51 #define ATT_READ_BY_GRP_TYPE_REQ 0x10
52 #define ATT_READ_BY_GRP_TYPE_RSP 0x11
53 #define ATT_WRITE_REQ 0x12
54 #define ATT_WRITE_RSP 0x13
55 #define ATT_PREPARE_WRITE_REQ 0x16
56 #define ATT_PREPARE_WRITE_RSP 0x17
57 #define ATT_EXECUTE_WRITE_REQ 0x18
58 #define ATT_EXECUTE_WRITE_RSP 0x19
59 #define ATT_HANDLE_VALUE_NOTI 0x1B
60 #define ATT_HANDLE_VALUE_IND 0x1D
61 #define ATT_HANDLE_VALUE_CFM 0x1E
62 #define ATT_WRITE_CMD 0x52
63 #define ATT_SIGNED_WRITE_CMD 0xD2
64
65 typedef void(*fATT_HANDLER)(uint8_t*);
66 typedef void(*fGATT_HANDLER)(void);
67
68 //end ATT Methods Opcode======================================================
69
70 #define ATT_DEVICE_RX_MTU 115 // must between 23 and 245
71 #define MAX_ATT_VALUE_LENGTH 512
72 #define ATT_REPORT_HEADER_LEN 3 //[opcode:1][handle:2]
73
74 #define ATT_INVALID_INDEX 0x0000
75
76 #define L2CAP_CID_ATT 0x0004
77
78 //ATT PDU format==============================================================
79
80 #ifndef PACKED_STRUCT
81 #define PACKED_STRUCT __attribute__((packed))
82 #endif
83
84 #ifdef _MSC_VER
85 __pragma(pack(push, 1))
86 #define __attribute__(x)
87 #endif
88
89
90 typedef struct
91 {
92 uint8_t ReqOpcodeInErr;
93 uint8_t AttHandleInErr[2];
94 uint8_t ErrCode;
95 }PACKED_STRUCT ATT_ERR_RSP_T;
96
97 typedef struct
98 {
99 uint8_t clientRxMTU[2];
100 }PACKED_STRUCT ATT_EXCHANGE_MTU_REQ_T;
101
102 typedef struct
103 {
104 uint8_t serverRxMTU[2];
105 }PACKED_STRUCT ATT_EXCHANGE_MTU_RSP_T;
106
107 typedef struct
108 {
109 uint8_t startHandle[2];
110 uint8_t endHandle[2];
111 }PACKED_STRUCT ATT_FIND_INFO_REQ_T;
112
113 typedef struct
114 {
115 uint8_t format;
116 uint8_t pInfoData[ATT_DEVICE_RX_MTU-2];
117 }PACKED_STRUCT ATT_FIND_INFO_RSP_T;
118
119 typedef struct
120 {
121 uint8_t startHandle[2];
122 uint8_t endHandle[2];
123 uint8_t UUID[2];
124 uint8_t value; //ATT_MTU-7
125 }PACKED_STRUCT ATT_FIND_BY_TYPE_VALUE_REQ_T;
126
127
128 typedef struct
129 {
130 uint8_t pHdlList[ATT_DEVICE_RX_MTU-1];
131 } PACKED_STRUCT ATT_FIND_BY_TYPE_VALUE_RSP_T;
132
133 typedef struct
134 {
135 uint8_t startHandle[2];
136 uint8_t endHandle[2];
137 uint8_t UUID[2];
138 }PACKED_STRUCT ATT_READ_BY_TYPE_REQ_T;
139
140 typedef struct
141 {
142 uint8_t len;
143 uint8_t pDataList[ATT_DEVICE_RX_MTU-2];
144 }PACKED_STRUCT ATT_READ_BY_TYPE_RSP_T;
145
146 typedef struct
147 {
148 uint8_t handle[2];
149 }PACKED_STRUCT ATT_READ_REQ_T;
150
151 typedef struct
152 {
153 uint8_t value;
154 }PACKED_STRUCT ATT_READ_RSP_T;
155
156 typedef struct
157 {
158 uint8_t handle[2];
159 uint8_t offset[2];
160 }PACKED_STRUCT ATT_READ_BLOB_REQ_T;
161
162 typedef struct
163 {
164 uint8_t partOfValue;
165 }PACKED_STRUCT ATT_READ_BLOB_RSP_T;
166
167 typedef struct
168 {
169 uint8_t handle[ATT_DEVICE_RX_MTU-1];
170 }PACKED_STRUCT ATT_READ_MULTI_REQ_T;
171
172 typedef struct
173 {
174 uint8_t pSetOfValue[ATT_DEVICE_RX_MTU-1];
175 }PACKED_STRUCT ATT_READ_MULTI_RSP_T;
176
177 typedef struct
178 {
179 uint8_t startHandle[2];
180 uint8_t endHandle[2];
181 uint8_t type[2];
182 }PACKED_STRUCT ATT_READ_BY_GROUP_TYPE_REQ_T;
183
184 typedef struct
185 {
186 uint8_t Length;
187 uint8_t pAttDataList[ATT_DEVICE_RX_MTU-2];
188 }PACKED_STRUCT ATT_READ_BY_GROUP_TYPE_RSP_T;
189
190 typedef union
191 {
192 uint8_t pValue[1];
193 uint16_t CCCD;
194 }PACKED_STRUCT ATT_WRITEDATA_U;
195
196 typedef struct
197 {
198 uint8_t handle[2];
199 ATT_WRITEDATA_U uData;
200 }PACKED_STRUCT ATT_WRITE_REQ_T;
201
202 typedef struct
203 {
204 uint8_t opcode;
205 uint8_t handle[2];
206 uint8_t value;
207 }PACKED_STRUCT ATT_SIGNED_WRITE_CMD_T;
208
209 typedef struct
210 {
211 uint8_t handle[2];
212 uint8_t offset[2];
213 uint8_t pPartValue[1];
214 }PACKED_STRUCT ATT_PREPARE_WRITE_REQ_T;
215
216 typedef struct
217 {
218 uint8_t handle[2];
219 uint8_t offset[2];
220 uint8_t pPartValue[1];
221 }PACKED_STRUCT ATT_PREPARE_WRITE_RSP_T;
222
223 typedef struct
224 {
225 uint8_t handle[2];
226 uint8_t value;
227 }PACKED_STRUCT ATT_HANDLE_VALUE_REPORT_T;
228
229 typedef union
230 {
231 uint8_t msgBodyPtr[1];
232 ATT_ERR_RSP_T AttErrRsp;
233 ATT_PREPARE_WRITE_RSP_T AttPrepareWriteRsp;
234 ATT_HANDLE_VALUE_REPORT_T AttHandleValueReport;
235 ATT_EXCHANGE_MTU_REQ_T AttExchangeMtuReq;
236 ATT_EXCHANGE_MTU_RSP_T AttExchangeMtuRsp;
237 ATT_READ_BY_TYPE_REQ_T AttReadByTypeReq;
238 ATT_READ_BY_GROUP_TYPE_REQ_T AttReadByGrpTypeReq;
239 ATT_FIND_BY_TYPE_VALUE_REQ_T AttFindByTypeValueReq;
240 ATT_FIND_INFO_REQ_T AttFindInfoReq;
241 ATT_READ_REQ_T AttReadReq;
242 ATT_READ_BLOB_REQ_T AttReadBlobReq;
243 ATT_READ_MULTI_REQ_T AttReadMultiReq;
244 ATT_WRITE_REQ_T AttWrtieReq;
245 ATT_PREPARE_WRITE_REQ_T AttPrepareWriteReq;
246 }PACKED_STRUCT ATT_PDU_PARA;
247
248 #ifdef _MSC_VER
249 __pragma(pack(pop))
250 #undef __attribute__
251 #endif
252
253 typedef struct att_pwq_stru
254 {
255 struct att_pwq_stru * pNextPWQ;
256 uint16_t length;
257 uint16_t attidx;
258 uint16_t offset;
259 uint8_t pPartValue[1];
260 }ATT_PREPAREWRITEQUEUE_T;
261
262 #define ATT_SIGNWRITE_NEW_CMD 0
263 #define ATT_SIGNWRITE_VERIFYING 1
264 #define ATT_SIGNWRITE_VERIFIED 2
265
266 #ifdef _MSC_VER
267 __pragma(pack(push, 1))
268 #define __attribute__(x)
269 #endif
270
271 typedef struct
272 {
273 uint8_t *ATTRsvMemPtr;
274 uint16_t attMtu[MAX_NUM_LE_LINK];
275 INDI_CB indi_cb[MAX_NUM_LE_LINK];
276 uint16_t currPduLen;
277 uint8_t currPduLinkIdx;
278 uint8_t signWriteStatus;
279 }PACKED_STRUCT ATT_CTL_TYPE;
280
281 #ifdef _MSC_VER
282 __pragma(pack(pop))
283 #undef __attribute__
284 #endif
285
286 typedef enum
287 {
288 GATT_NONE = 0x0000,
289 GATT_PROC_OFFSET = 0xFF00,
290 GATT_EXCHANGE_MTU,
291 GATT_DISC_ALL_PRIMARY_SERVICES,
292 GATT_DISC_PRIMARY_SERVICE_BY_UUID,
293 GATT_FIND_INCLUDED_SERVICES,
294 GATT_DISC_ALL_CHARS,
295 GATT_DISC_CHARS_BY_UUID,
296 GATT_DISC_ALL_CHAR_DESCS,
297 GATT_READ_CHAR_VALUE,
298 GATT_READ_USING_CHAR_UUID,
299 GATT_READ_LONG_CHAR_VALUE,
300 GATT_READ_MULTI_CHAR_VALUES,
301 GATT_WRITE_NO_RSP,
302 GATT_SIGNED_WRITE_NO_RSP,
303 GATT_WRITE_CHAR_VALUE,
304 GATT_WRITE_LONG_CHAR_VALUE,
305 GATT_RELIABLE_WRITES,
306 GATT_READ_CHAR_DESC,
307 GATT_READ_LONG_CHAR_DESC,
308 GATT_WRITE_CHAR_DESC,
309 GATT_WRITE_LONG_CHAR_DESC,
310 }GATT_PROCEDURE_ENUM;
311
312 typedef struct
313 {
314 uint8_t length;
315 uint8_t pUUID[1];
316 }GATT_PROC_PARA_DISC_PRIMARY_SERVICE_BY_UUID;
317
318 #ifdef _MSC_VER
319 __pragma(pack(push, 1))
320 #define __attribute__(x)
321 #endif
322
323
324 typedef struct
325 {
326 uint8_t startHandle[2];
327 uint8_t endHandle[2];
328 }PACKED_STRUCT GATT_PROC_PARA_FIND_INCLUDED_SERVICES;
329
330 typedef struct
331 {
332 uint8_t startHandle[2];
333 uint8_t endHandle[2];
334 }PACKED_STRUCT GATT_PROC_PARA_DISC_ALL_CHARS;
335
336 typedef struct
337 {
338 uint8_t startHandle[2];
339 uint8_t endHandle[2];
340 uint8_t length;
341 uint8_t pUUID[16];
342 }PACKED_STRUCT GATT_PROC_PARA_DISC_CHARS_BY_UUID;
343
344 typedef struct
345 {
346 uint8_t startHandle[2];
347 uint8_t endHandle[2];
348 }PACKED_STRUCT GATT_PROC_PARA_DISC_ALL_CHAR_DESCS;
349
350 typedef struct
351 {
352 uint8_t handle[2];
353 }PACKED_STRUCT GATT_PROC_PARA_READ_CHAR_VALUE;
354
355 typedef struct
356 {
357 uint8_t startHandle[2];
358 uint8_t endHandle[2];
359 uint8_t length;
360 uint8_t pUUID[1];
361 }PACKED_STRUCT GATT_PROC_PARA_READ_USING_CHAR_UUID;
362
363 typedef struct
364 {
365 uint8_t handle[2];
366 uint8_t offset[2];
367 }PACKED_STRUCT GATT_PROC_PARA_READ_LONG_CHAR_VALUE;
368
369 typedef struct
370 {
371 uint8_t numOfHandle;
372 uint8_t pHandle[4];
373 }GATT_PROC_READ_MULTI_CHAR_VALUES;
374
375 typedef struct
376 {
377 uint8_t handle[2];
378 uint8_t valueLen;
379 uint8_t pValue[20];
380 }PACKED_STRUCT GATT_PROC_PARA_WRITE_NO_RSP;
381
382 typedef struct
383 {
384 uint8_t handle[2];
385 uint8_t valueLen;
386 uint8_t pValue[20];
387 }PACKED_STRUCT GATT_PROC_PARA_WRITE_CHAR_VALUE;
388
389 typedef struct
390 {
391 uint8_t handle[2];
392 uint8_t offset[2];
393 uint8_t valueLen[2];
394 uint8_t pValue[50];
395 }PACKED_STRUCT GATT_PROC_PARA_WRITE_LONG_CHAR_VALUE;
396
397 typedef struct
398 {
399 #define MAX_NUM_OF_REQ 5
400
401 uint8_t numOfReq;
402 uint8_t handle[MAX_NUM_OF_REQ*2];
403 uint8_t offset[MAX_NUM_OF_REQ*2];
404 uint8_t valueLen[MAX_NUM_OF_REQ*2];
405 uint8_t pValueBank[50];
406 }PACKED_STRUCT GATT_PROC_PARA_RELIABLE_WRITES;
407
408 typedef struct
409 {
410 uint8_t handle[2];
411 }PACKED_STRUCT GATT_PROC_PARA_READ_CHAR_DESC;
412
413 typedef struct
414 {
415 uint8_t handle[2];
416 uint8_t offset[2];
417 }PACKED_STRUCT GATT_PROC_PARA_READ_LONG_CHAR_DESC;
418
419 typedef struct
420 {
421 uint8_t handle[2];
422 uint8_t valueLen;
423 uint8_t pValue[20];
424 }PACKED_STRUCT GATT_PROC_PARA_WRITE_CHAR_DESC;
425
426 #ifdef _MSC_VER
427 __pragma(pack(pop))
428 #undef __attribute__
429 #endif
430
431 typedef void(*gatt_procedure_cb)(uint8_t * resp);
432
433 typedef struct
434 {
435 uint16_t connInProc; // only support one link in procedure
436 gatt_procedure_cb gatt_proc_cb;
437 }ATT_CLIENT_CTL_TYPE;
438
439 //End Global Variable========================================
440
441 /* GATT */
442 //GATT definition============================================
443 #define GATT_UUID_PRIM_SERVICE (uint16_t)0x2800
444 #define GATT_UUID_SND_SERVICE (uint16_t)0x2801
445 #define GATT_UUID_INCLUDE (uint16_t)0x2802
446 #define GATT_UUID_CHARACTERISTIC (uint16_t)0x2803
447
449 //PDU Templates:
451 #ifdef _MSC_VER
452 __pragma(pack(push, 1))
453 #define __attribute__(x)
454 #endif
455
456
457 typedef struct
458 {
459 uint8_t Opcode;
460 ATT_PDU_PARA Parameter;
461 }PACKED_STRUCT ATT_OUT_PKT_T;
462
466 #define UUID_B_016 0x02
467 #define UUID_B_128 0x10
468 #define UUID_B_032 0x04
469
470 typedef union {
471 uint8_t *addr;
472 uint16_t uuid16;
473 }PACKED_STRUCT UUID_U;
474
475 typedef struct {
476 UUID_U uuid;
477 uint8_t type;
478 }__attribute__((packed)) UUID_T;
479
480
481
509 typedef struct {
510 uint8_t * dataptr;
511 ATTCB CBfunc;
512 UUID_T uuid_t;
513 uint8_t permission;
514 uint16_t currentLen;
515 uint16_t maximumLen;
516 uint16_t handle;
517 } __attribute__((packed)) SDK_ATTRIBUTE;
518
519 #ifdef _MSC_VER
520 __pragma(pack(pop))
521 #undef __attribute__
522 #endif
523
524 extern SDK_ATTRIBUTE ** gATT_Server;
525 extern uint16_t ATT_SDK_SERVER_SIZE;
526 extern uint16_t ATT_DEFAULT_MTU_SIZE;
527
528 #endif
ATTCB
void(* ATTCB)(ATT_CB_TYPE type, uint8_t linkindex, uint16_t handle)
attribute value accessed call back function.
Definition: ble_att.h:111
SDK_ATTRIBUTE
Definition: att_private.h:509
INDI_CB
void(* INDI_CB)(uint8_t link_index)
characteristic value indication confirmed call back function.
Definition: ble_att.h:118
MAX_NUM_LE_LINK
#define MAX_NUM_LE_LINK
Maximal Link number.
Definition: bt_constants.h:52