1 /******************************************************************************
2 *
3 * Copyright 1999-2012 Broadcom Corporation
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 ******************************************************************************/
18 #ifndef GATT_API_H
19 #define GATT_API_H
20
21 #include <base/strings/stringprintf.h>
22 #include <string>
23
24 #include "bt_target.h"
25 #include "btm_ble_api.h"
26 #include "gattdefs.h"
27 #include "types/bt_transport.h"
28
29 /*****************************************************************************
30 * Constants
31 ****************************************************************************/
32 /* Success code and error codes */
33 typedef enum GattStatus : uint8_t {
34 GATT_SUCCESS = 0x00,
35 GATT_INVALID_HANDLE = 0x01,
36 GATT_READ_NOT_PERMIT = 0x02,
37 GATT_WRITE_NOT_PERMIT = 0x03,
38 GATT_INVALID_PDU = 0x04,
39 GATT_INSUF_AUTHENTICATION = 0x05,
40 GATT_REQ_NOT_SUPPORTED = 0x06,
41 GATT_INVALID_OFFSET = 0x07,
42 GATT_INSUF_AUTHORIZATION = 0x08,
43 GATT_PREPARE_Q_FULL = 0x09,
44 GATT_NOT_FOUND = 0x0a,
45 GATT_NOT_LONG = 0x0b,
46 GATT_INSUF_KEY_SIZE = 0x0c,
47 GATT_INVALID_ATTR_LEN = 0x0d,
48 GATT_ERR_UNLIKELY = 0x0e,
49 GATT_INSUF_ENCRYPTION = 0x0f,
50 GATT_UNSUPPORT_GRP_TYPE = 0x10,
51 GATT_INSUF_RESOURCE = 0x11,
52 GATT_DATABASE_OUT_OF_SYNC = 0x12,
53 GATT_VALUE_NOT_ALLOWED = 0x13,
54 GATT_ILLEGAL_PARAMETER = 0x87,
55 GATT_TOO_SHORT = 0x7f,
56 GATT_NO_RESOURCES = 0x80,
57 GATT_INTERNAL_ERROR = 0x81,
58 GATT_WRONG_STATE = 0x82,
59 GATT_DB_FULL = 0x83,
60 GATT_BUSY = 0x84,
61 GATT_ERROR = 0x85,
62 GATT_CMD_STARTED = 0x86,
63 GATT_PENDING = 0x88,
64 GATT_AUTH_FAIL = 0x89,
65 GATT_MORE = 0x8a,
66 GATT_INVALID_CFG = 0x8b,
67 GATT_SERVICE_STARTED = 0x8c,
68 GATT_ENCRYPED_MITM = GATT_SUCCESS,
69 GATT_ENCRYPED_NO_MITM = 0x8d,
70 GATT_NOT_ENCRYPTED = 0x8e,
71 GATT_CONGESTED = 0x8f,
72 GATT_DUP_REG = 0x90, /* 0x90 */
73 GATT_ALREADY_OPEN = 0x91, /* 0x91 */
74 GATT_CANCEL = 0x92, /* 0x92 */
75 /* = 0xE0 ~ 0xFC reserved for future use */
76
77 /* Client Characteristic Configuration Descriptor Improperly Configured */
78 GATT_CCC_CFG_ERR = 0xFD,
79 /* Procedure Already in progress */
80 GATT_PRC_IN_PROGRESS = 0xFE,
81 /* Attribute value out of range */
82 GATT_OUT_OF_RANGE = 0xFF,
83 } tGATT_STATUS;
84
85 typedef enum : uint8_t {
86 GATT_RSP_ERROR = 0x01,
87 GATT_REQ_MTU = 0x02,
88 GATT_RSP_MTU = 0x03,
89 GATT_REQ_FIND_INFO = 0x04,
90 GATT_RSP_FIND_INFO = 0x05,
91 GATT_REQ_FIND_TYPE_VALUE = 0x06,
92 GATT_RSP_FIND_TYPE_VALUE = 0x07,
93 GATT_REQ_READ_BY_TYPE = 0x08,
94 GATT_RSP_READ_BY_TYPE = 0x09,
95 GATT_REQ_READ = 0x0A,
96 GATT_RSP_READ = 0x0B,
97 GATT_REQ_READ_BLOB = 0x0C,
98 GATT_RSP_READ_BLOB = 0x0D,
99 GATT_REQ_READ_MULTI = 0x0E,
100 GATT_RSP_READ_MULTI = 0x0F,
101 GATT_REQ_READ_BY_GRP_TYPE = 0x10,
102 GATT_RSP_READ_BY_GRP_TYPE = 0x11,
103 /* 0001-0010 (write)*/
104 GATT_REQ_WRITE = 0x12,
105 GATT_RSP_WRITE = 0x13,
106 /* changed in V4.0 01001-0010(write cmd)*/
107 GATT_CMD_WRITE = 0x52,
108 GATT_REQ_PREPARE_WRITE = 0x16,
109 GATT_RSP_PREPARE_WRITE = 0x17,
110 GATT_REQ_EXEC_WRITE = 0x18,
111 GATT_RSP_EXEC_WRITE = 0x19,
112 GATT_HANDLE_VALUE_NOTIF = 0x1B,
113 GATT_HANDLE_VALUE_IND = 0x1D,
114 GATT_HANDLE_VALUE_CONF = 0x1E,
115
116 GATT_REQ_READ_MULTI_VAR = 0x20,
117 GATT_RSP_READ_MULTI_VAR = 0x21,
118 GATT_HANDLE_MULTI_VALUE_NOTIF = 0x23,
119
120 /* changed in V4.0 1101-0010 (signed write) see write cmd above*/
121 GATT_SIGN_CMD_WRITE = 0xD2,
122 /* 0x1E = 30 + 1 = 31*/
123 GATT_OP_CODE_MAX = (GATT_HANDLE_MULTI_VALUE_NOTIF + 1),
124 } tGATT_OP_CODE;
125
gatt_op_code_text(const tGATT_OP_CODE & op_code)126 inline std::string gatt_op_code_text(const tGATT_OP_CODE& op_code) {
127 switch (op_code) {
128 case GATT_RSP_ERROR:
129 return std::string("GATT_RSP_ERROR");
130 case GATT_REQ_MTU:
131 return std::string("GATT_REQ_MTU");
132 case GATT_RSP_MTU:
133 return std::string("GATT_RSP_MTU");
134 case GATT_REQ_FIND_INFO:
135 return std::string("GATT_REQ_FIND_INFO");
136 case GATT_RSP_FIND_INFO:
137 return std::string("GATT_RSP_FIND_INFO");
138 case GATT_REQ_FIND_TYPE_VALUE:
139 return std::string("GATT_REQ_FIND_TYPE_VALUE");
140 case GATT_RSP_FIND_TYPE_VALUE:
141 return std::string("GATT_RSP_FIND_TYPE_VALUE");
142 case GATT_REQ_READ_BY_TYPE:
143 return std::string("GATT_REQ_READ_BY_TYPE");
144 case GATT_RSP_READ_BY_TYPE:
145 return std::string("GATT_RSP_READ_BY_TYPE");
146 case GATT_REQ_READ:
147 return std::string("GATT_REQ_READ");
148 case GATT_RSP_READ:
149 return std::string("GATT_RSP_READ");
150 case GATT_REQ_READ_BLOB:
151 return std::string("GATT_REQ_READ_BLOB");
152 case GATT_RSP_READ_BLOB:
153 return std::string("GATT_RSP_READ_BLOB");
154 case GATT_REQ_READ_MULTI:
155 return std::string("GATT_REQ_READ_MULTI");
156 case GATT_RSP_READ_MULTI:
157 return std::string("GATT_RSP_READ_MULTI");
158 case GATT_REQ_READ_BY_GRP_TYPE:
159 return std::string("GATT_REQ_READ_BY_GRP_TYPE");
160 case GATT_RSP_READ_BY_GRP_TYPE:
161 return std::string("GATT_RSP_READ_BY_GRP_TYPE");
162 case GATT_REQ_WRITE:
163 return std::string("GATT_REQ_WRITE");
164 case GATT_RSP_WRITE:
165 return std::string("GATT_RSP_WRITE");
166 case GATT_CMD_WRITE:
167 return std::string("GATT_CMD_WRITE");
168 case GATT_REQ_PREPARE_WRITE:
169 return std::string("GATT_REQ_PREPARE_WRITE");
170 case GATT_RSP_PREPARE_WRITE:
171 return std::string("GATT_RSP_PREPARE_WRITE");
172 case GATT_REQ_EXEC_WRITE:
173 return std::string("GATT_REQ_EXEC_WRITE");
174 case GATT_RSP_EXEC_WRITE:
175 return std::string("GATT_RSP_EXEC_WRITE");
176 case GATT_HANDLE_VALUE_NOTIF:
177 return std::string("GATT_HANDLE_VALUE_NOTIF");
178 case GATT_HANDLE_VALUE_IND:
179 return std::string("GATT_HANDLE_VALUE_IND");
180 case GATT_HANDLE_VALUE_CONF:
181 return std::string("GATT_HANDLE_VALUE_CONF");
182 case GATT_REQ_READ_MULTI_VAR:
183 return std::string("GATT_REQ_READ_MULTI_VAR");
184 case GATT_RSP_READ_MULTI_VAR:
185 return std::string("GATT_RSP_READ_MULTI_VAR");
186 case GATT_HANDLE_MULTI_VALUE_NOTIF:
187 return std::string("GATT_HANDLE_MULTI_VALUE_NOTIF");
188 case GATT_SIGN_CMD_WRITE:
189 return std::string("GATT_SIGN_CMD_WRITE");
190 case GATT_OP_CODE_MAX:
191 return std::string("GATT_OP_CODE_MAX");
192 };
193 }
194
195 #define GATT_HANDLE_IS_VALID(x) ((x) != 0)
196
197 typedef enum : uint16_t {
198 GATT_CONN_OK = 0,
199 GATT_CONN_UNKNOWN = 0,
200 /* general L2cap failure */
201 GATT_CONN_L2C_FAILURE = 1,
202 /* 0x08 connection timeout */
203 GATT_CONN_TIMEOUT = HCI_ERR_CONNECTION_TOUT,
204 /* 0x13 connection terminate by peer user */
205 GATT_CONN_TERMINATE_PEER_USER = HCI_ERR_PEER_USER,
206 /* 0x16 connectionterminated by local host */
207 GATT_CONN_TERMINATE_LOCAL_HOST = HCI_ERR_CONN_CAUSE_LOCAL_HOST,
208 /* 0x22 connection fail for LMP response tout */
209 GATT_CONN_LMP_TIMEOUT = HCI_ERR_LMP_RESPONSE_TIMEOUT,
210
211 BTA_GATT_CONN_NONE = 0x0101, /* 0x0101 no connection to cancel */
212
213 } tGATT_DISCONN_REASON;
214
215 #define CASE_RETURN_TEXT(code) \
216 case code: \
217 return #code
218
gatt_disconnection_reason_text(const tGATT_DISCONN_REASON & reason)219 inline std::string gatt_disconnection_reason_text(
220 const tGATT_DISCONN_REASON& reason) {
221 switch (reason) {
222 CASE_RETURN_TEXT(GATT_CONN_OK);
223 CASE_RETURN_TEXT(GATT_CONN_L2C_FAILURE);
224 CASE_RETURN_TEXT(GATT_CONN_TIMEOUT);
225 CASE_RETURN_TEXT(GATT_CONN_TERMINATE_PEER_USER);
226 CASE_RETURN_TEXT(GATT_CONN_TERMINATE_LOCAL_HOST);
227 CASE_RETURN_TEXT(GATT_CONN_LMP_TIMEOUT);
228 CASE_RETURN_TEXT(BTA_GATT_CONN_NONE);
229 default:
230 return std::string("UNKNOWN[%hu]", reason);
231 }
232 }
233 #undef CASE_RETURN_TEXT
234
235 /* MAX GATT MTU size
236 */
237 #ifndef GATT_MAX_MTU_SIZE
238 #define GATT_MAX_MTU_SIZE 517
239 #endif
240
241 /* max legth of an attribute value
242 */
243 #ifndef GATT_MAX_ATTR_LEN
244 #define GATT_MAX_ATTR_LEN 600
245 #endif
246
247 /* default GATT MTU size over LE link
248 */
249 #define GATT_DEF_BLE_MTU_SIZE 23
250
251 /* invalid connection ID
252 */
253 #define GATT_INVALID_CONN_ID 0xFFFF
254
255 #ifndef GATT_CL_MAX_LCB
256 #define GATT_CL_MAX_LCB 22
257 #endif
258
259 /* GATT notification caching timer, default to be three seconds
260 */
261 #ifndef GATTC_NOTIF_TIMEOUT
262 #define GATTC_NOTIF_TIMEOUT 3
263 #endif
264
265 /*****************************************************************************
266 * GATT Structure Definition
267 ****************************************************************************/
268
269 /* Attribute permissions
270 */
271 #define GATT_PERM_READ (1 << 0) /* bit 0 */
272 #define GATT_PERM_READ_ENCRYPTED (1 << 1) /* bit 1 */
273 #define GATT_PERM_READ_ENC_MITM (1 << 2) /* bit 2 */
274 #define GATT_PERM_WRITE (1 << 4) /* bit 4 */
275 #define GATT_PERM_WRITE_ENCRYPTED (1 << 5) /* bit 5 */
276 #define GATT_PERM_WRITE_ENC_MITM (1 << 6) /* bit 6 */
277 #define GATT_PERM_WRITE_SIGNED (1 << 7) /* bit 7 */
278 #define GATT_PERM_WRITE_SIGNED_MITM (1 << 8) /* bit 8 */
279 typedef uint16_t tGATT_PERM;
280
281 /* the MS nibble of tGATT_PERM; key size 7=0; size 16=9 */
282 #define GATT_ENCRYPT_KEY_SIZE_MASK (0xF000)
283
284 #define GATT_READ_ALLOWED \
285 (GATT_PERM_READ | GATT_PERM_READ_ENCRYPTED | GATT_PERM_READ_ENC_MITM)
286 #define GATT_READ_AUTH_REQUIRED (GATT_PERM_READ_ENCRYPTED)
287 #define GATT_READ_MITM_REQUIRED (GATT_PERM_READ_ENC_MITM)
288 #define GATT_READ_ENCRYPTED_REQUIRED \
289 (GATT_PERM_READ_ENCRYPTED | GATT_PERM_READ_ENC_MITM)
290
291 #define GATT_WRITE_ALLOWED \
292 (GATT_PERM_WRITE | GATT_PERM_WRITE_ENCRYPTED | GATT_PERM_WRITE_ENC_MITM | \
293 GATT_PERM_WRITE_SIGNED | GATT_PERM_WRITE_SIGNED_MITM)
294
295 #define GATT_WRITE_AUTH_REQUIRED \
296 (GATT_PERM_WRITE_ENCRYPTED | GATT_PERM_WRITE_SIGNED)
297
298 #define GATT_WRITE_MITM_REQUIRED \
299 (GATT_PERM_WRITE_ENC_MITM | GATT_PERM_WRITE_SIGNED_MITM)
300
301 #define GATT_WRITE_ENCRYPTED_PERM \
302 (GATT_PERM_WRITE_ENCRYPTED | GATT_PERM_WRITE_ENC_MITM)
303
304 #define GATT_WRITE_SIGNED_PERM \
305 (GATT_PERM_WRITE_SIGNED | GATT_PERM_WRITE_SIGNED_MITM)
306
307 /* Characteristic properties
308 */
309 #define GATT_CHAR_PROP_BIT_BROADCAST (1 << 0)
310 #define GATT_CHAR_PROP_BIT_READ (1 << 1)
311 #define GATT_CHAR_PROP_BIT_WRITE_NR (1 << 2)
312 #define GATT_CHAR_PROP_BIT_WRITE (1 << 3)
313 #define GATT_CHAR_PROP_BIT_NOTIFY (1 << 4)
314 #define GATT_CHAR_PROP_BIT_INDICATE (1 << 5)
315 #define GATT_CHAR_PROP_BIT_AUTH (1 << 6)
316 #define GATT_CHAR_PROP_BIT_EXT_PROP (1 << 7)
317 typedef uint8_t tGATT_CHAR_PROP;
318
319 /* Format of the value of a characteristic. enumeration type
320 */
321 enum {
322 GATT_FORMAT_RES, /* rfu */
323 GATT_FORMAT_BOOL, /* 0x01 boolean */
324 GATT_FORMAT_2BITS, /* 0x02 2 bit */
325 GATT_FORMAT_NIBBLE, /* 0x03 nibble */
326 GATT_FORMAT_UINT8, /* 0x04 uint8 */
327 GATT_FORMAT_UINT12, /* 0x05 uint12 */
328 GATT_FORMAT_UINT16, /* 0x06 uint16 */
329 GATT_FORMAT_UINT24, /* 0x07 uint24 */
330 GATT_FORMAT_UINT32, /* 0x08 uint32 */
331 GATT_FORMAT_UINT48, /* 0x09 uint48 */
332 GATT_FORMAT_UINT64, /* 0x0a uint64 */
333 GATT_FORMAT_UINT128, /* 0x0B uint128 */
334 GATT_FORMAT_SINT8, /* 0x0C signed 8 bit integer */
335 GATT_FORMAT_SINT12, /* 0x0D signed 12 bit integer */
336 GATT_FORMAT_SINT16, /* 0x0E signed 16 bit integer */
337 GATT_FORMAT_SINT24, /* 0x0F signed 24 bit integer */
338 GATT_FORMAT_SINT32, /* 0x10 signed 32 bit integer */
339 GATT_FORMAT_SINT48, /* 0x11 signed 48 bit integer */
340 GATT_FORMAT_SINT64, /* 0x12 signed 64 bit integer */
341 GATT_FORMAT_SINT128, /* 0x13 signed 128 bit integer */
342 GATT_FORMAT_FLOAT32, /* 0x14 float 32 */
343 GATT_FORMAT_FLOAT64, /* 0x15 float 64*/
344 GATT_FORMAT_SFLOAT, /* 0x16 IEEE-11073 16 bit SFLOAT */
345 GATT_FORMAT_FLOAT, /* 0x17 IEEE-11073 32 bit SFLOAT */
346 GATT_FORMAT_DUINT16, /* 0x18 IEEE-20601 format */
347 GATT_FORMAT_UTF8S, /* 0x19 UTF-8 string */
348 GATT_FORMAT_UTF16S, /* 0x1a UTF-16 string */
349 GATT_FORMAT_STRUCT, /* 0x1b Opaque structure*/
350 GATT_FORMAT_MAX /* 0x1c or above reserved */
351 };
352 typedef uint8_t tGATT_FORMAT;
353
354 /* Characteristic Presentation Format Descriptor value
355 */
356 typedef struct {
357 uint16_t unit; /* as UUIUD defined by SIG */
358 uint16_t descr; /* as UUID as defined by SIG */
359 tGATT_FORMAT format;
360 int8_t exp;
361 uint8_t name_spc; /* The name space of the description */
362 } tGATT_CHAR_PRES;
363
364 /* Characteristic Report reference Descriptor format
365 */
366 typedef struct {
367 uint8_t rpt_id; /* report ID */
368 uint8_t rpt_type; /* report type */
369 } tGATT_CHAR_RPT_REF;
370
371 #define GATT_VALID_RANGE_MAX_SIZE 16
372 typedef struct {
373 uint8_t format;
374 uint16_t len;
375 uint8_t lower_range[GATT_VALID_RANGE_MAX_SIZE]; /* in little endian format */
376 uint8_t upper_range[GATT_VALID_RANGE_MAX_SIZE];
377 } tGATT_VALID_RANGE;
378
379 /* Characteristic Aggregate Format attribute value
380 */
381 #define GATT_AGGR_HANDLE_NUM_MAX 10
382 typedef struct {
383 uint8_t num_handle;
384 uint16_t handle_list[GATT_AGGR_HANDLE_NUM_MAX];
385 } tGATT_CHAR_AGGRE;
386
387 /* Characteristic descriptor: Extended Properties value
388 */
389 /* permits reliable writes of the Characteristic Value */
390 #define GATT_CHAR_BIT_REL_WRITE 0x0001
391 /* permits writes to the characteristic descriptor */
392 #define GATT_CHAR_BIT_WRITE_AUX 0x0002
393
394 /* characteristic descriptor: client configuration value
395 */
396 #define GATT_CLT_CONFIG_NONE 0x0000
397 #define GATT_CLT_CONFIG_NOTIFICATION 0x0001
398 #define GATT_CLT_CONFIG_INDICATION 0x0002
399
400 /* characteristic descriptor: server configuration value
401 */
402 #define GATT_SVR_CONFIG_NONE 0x0000
403 #define GATT_SVR_CONFIG_BROADCAST 0x0001
404 typedef uint16_t tGATT_SVR_CHAR_CONFIG;
405
406 /* Characteristic descriptor: Extended Properties value
407 */
408 /* permits reliable writes of the Characteristic Value */
409 #define GATT_CHAR_BIT_REL_WRITE 0x0001
410 /* permits writes to the characteristic descriptor */
411 #define GATT_CHAR_BIT_WRITE_AUX 0x0002
412
413 /* authentication requirement
414 */
415 #define GATT_AUTH_REQ_NONE 0
416 #define GATT_AUTH_REQ_NO_MITM 1 /* unauthenticated encryption */
417 #define GATT_AUTH_REQ_MITM 2 /* authenticated encryption */
418 #define GATT_AUTH_REQ_SIGNED_NO_MITM 3
419 #define GATT_AUTH_REQ_SIGNED_MITM 4
420 typedef uint8_t tGATT_AUTH_REQ;
421
422 /* Attribute Value structure
423 */
424 typedef struct {
425 uint16_t conn_id;
426 uint16_t handle; /* attribute handle */
427 uint16_t offset; /* attribute value offset, if no offfset is needed for the
428 command, ignore it */
429 uint16_t len; /* length of attribute value */
430 tGATT_AUTH_REQ auth_req; /* authentication request */
431 uint8_t value[GATT_MAX_ATTR_LEN]; /* the actual attribute value */
432 } tGATT_VALUE;
433
434 /* Union of the event data which is used in the server respond API to carry the
435 * server response information
436 */
437 typedef union {
438 /* data type member event */
439 tGATT_VALUE attr_value; /* READ, HANDLE_VALUE_IND, PREPARE_WRITE */
440 /* READ_BLOB, READ_BY_TYPE */
441 uint16_t handle; /* WRITE, WRITE_BLOB */
442
443 } tGATTS_RSP;
444
445 #define GATT_PREP_WRITE_CANCEL 0x00
446 #define GATT_PREP_WRITE_EXEC 0x01
447 typedef uint8_t tGATT_EXEC_FLAG;
448
449 /* read request always based on UUID */
450 typedef struct {
451 uint16_t handle;
452 uint16_t offset;
453 bool is_long;
454 bt_gatt_db_attribute_type_t
455 gatt_type; /* are we writing characteristic or descriptor */
456 } tGATT_READ_REQ;
457
458 /* write request data */
459 typedef struct {
460 uint16_t handle; /* attribute handle */
461 uint16_t offset; /* attribute value offset, if no offfset is needed for the
462 command, ignore it */
463 uint16_t len; /* length of attribute value */
464 uint8_t value[GATT_MAX_ATTR_LEN]; /* the actual attribute value */
465 bool need_rsp; /* need write response */
466 bool is_prep; /* is prepare write */
467 bt_gatt_db_attribute_type_t
468 gatt_type; /* are we writing characteristic or descriptor */
469 } tGATT_WRITE_REQ;
470
471 /* callback data for server access request from client */
472 typedef union {
473 tGATT_READ_REQ read_req; /* read request, read by Type, read blob */
474
475 tGATT_WRITE_REQ write_req; /* write */
476 /* prepare write */
477 /* write blob */
478 uint16_t handle; /* handle value confirmation */
479 uint16_t mtu; /* MTU exchange request */
480 tGATT_EXEC_FLAG exec_write; /* execute write */
481 } tGATTS_DATA;
482
483 typedef uint8_t tGATT_SERV_IF; /* GATT Service Interface */
484
485 enum {
486 GATTS_REQ_TYPE_READ_CHARACTERISTIC = 1, /* Char read request */
487 GATTS_REQ_TYPE_READ_DESCRIPTOR, /* Desc read request */
488 GATTS_REQ_TYPE_WRITE_CHARACTERISTIC, /* Char write request */
489 GATTS_REQ_TYPE_WRITE_DESCRIPTOR, /* Desc write request */
490 GATTS_REQ_TYPE_WRITE_EXEC, /* Execute write */
491 GATTS_REQ_TYPE_MTU, /* MTU exchange information */
492 GATTS_REQ_TYPE_CONF /* handle value confirmation */
493 };
494 typedef uint8_t tGATTS_REQ_TYPE;
495
496 /* Client Used Data Structure
497 */
498 /* definition of different discovery types */
499 typedef enum : uint8_t {
500 GATT_DISC_SRVC_ALL = 1, /* discover all services */
501 GATT_DISC_SRVC_BY_UUID, /* discover service of a special type */
502 GATT_DISC_INC_SRVC, /* discover the included service within a service */
503 GATT_DISC_CHAR, /* discover characteristics of a service with/without type
504 requirement */
505 GATT_DISC_CHAR_DSCPT, /* discover characteristic descriptors of a character */
506 GATT_DISC_MAX /* maximnun discover type */
507 } tGATT_DISC_TYPE;
508
509 /* GATT read type enumeration
510 */
511 enum {
512 GATT_READ_BY_TYPE = 1,
513 GATT_READ_BY_HANDLE,
514 GATT_READ_MULTIPLE,
515 GATT_READ_CHAR_VALUE,
516 GATT_READ_PARTIAL,
517 GATT_READ_MAX
518 };
519 typedef uint8_t tGATT_READ_TYPE;
520
521 /* Read By Type Request (GATT_READ_BY_TYPE) Data
522 */
523 typedef struct {
524 tGATT_AUTH_REQ auth_req;
525 uint16_t s_handle;
526 uint16_t e_handle;
527 bluetooth::Uuid uuid;
528 } tGATT_READ_BY_TYPE;
529
530 /* GATT_READ_MULTIPLE request data
531 */
532 #define GATT_MAX_READ_MULTI_HANDLES \
533 10 /* Max attributes to read in one request */
534 typedef struct {
535 tGATT_AUTH_REQ auth_req;
536 uint16_t num_handles; /* number of handles to read */
537 uint16_t handles[GATT_MAX_READ_MULTI_HANDLES]; /* handles list to be read */
538 bool variable_len;
539 } tGATT_READ_MULTI;
540
541 /* Read By Handle Request (GATT_READ_BY_HANDLE) data */
542 typedef struct {
543 tGATT_AUTH_REQ auth_req;
544 uint16_t handle;
545 } tGATT_READ_BY_HANDLE;
546
547 /* READ_BT_HANDLE_Request data */
548 typedef struct {
549 tGATT_AUTH_REQ auth_req;
550 uint16_t handle;
551 uint16_t offset;
552 } tGATT_READ_PARTIAL;
553
554 /* Read Request Data
555 */
556 typedef union {
557 tGATT_READ_BY_TYPE service;
558 tGATT_READ_BY_TYPE char_type; /* characterisitc type */
559 tGATT_READ_MULTI read_multiple;
560 tGATT_READ_BY_HANDLE by_handle;
561 tGATT_READ_PARTIAL partial;
562 } tGATT_READ_PARAM;
563
564 /* GATT write type enumeration */
565 enum { GATT_WRITE_NO_RSP = 1, GATT_WRITE, GATT_WRITE_PREPARE };
566 typedef uint8_t tGATT_WRITE_TYPE;
567
568 /* Client Operation Complete Callback Data
569 */
570 typedef union {
571 tGATT_VALUE att_value;
572 uint16_t mtu;
573 uint16_t handle;
574 uint16_t cid;
575 } tGATT_CL_COMPLETE;
576
577 /* GATT client operation type, used in client callback function
578 */
579 typedef enum : uint8_t {
580 GATTC_OPTYPE_NONE = 0,
581 GATTC_OPTYPE_DISCOVERY = 1,
582 GATTC_OPTYPE_READ = 2,
583 GATTC_OPTYPE_WRITE = 3,
584 GATTC_OPTYPE_EXE_WRITE = 4,
585 GATTC_OPTYPE_CONFIG = 5,
586 GATTC_OPTYPE_NOTIFICATION = 6,
587 GATTC_OPTYPE_INDICATION = 7,
588 } tGATTC_OPTYPE;
589
590 /* characteristic declaration
591 */
592 typedef struct {
593 tGATT_CHAR_PROP char_prop; /* characterisitc properties */
594 uint16_t val_handle; /* characteristic value attribute handle */
595 bluetooth::Uuid char_uuid; /* characteristic UUID type */
596 } tGATT_CHAR_DCLR_VAL;
597
598 /* primary service group data
599 */
600 typedef struct {
601 uint16_t e_handle; /* ending handle of the group */
602 bluetooth::Uuid service_type; /* group type */
603 } tGATT_GROUP_VALUE;
604
605 /* included service attribute value
606 */
607 typedef struct {
608 bluetooth::Uuid service_type; /* included service UUID */
609 uint16_t s_handle; /* starting handle */
610 uint16_t e_handle; /* ending handle */
611 } tGATT_INCL_SRVC;
612
613 typedef union {
614 tGATT_INCL_SRVC incl_service; /* include service value */
615 tGATT_GROUP_VALUE group_value; /* Service UUID type.
616 This field is used with GATT_DISC_SRVC_ALL
617 or GATT_DISC_SRVC_BY_UUID
618 type of discovery result callback. */
619
620 uint16_t handle; /* When used with GATT_DISC_INC_SRVC type discovery result,
621 it is the included service starting handle.*/
622
623 tGATT_CHAR_DCLR_VAL
624 dclr_value; /* Characteristic declaration value.
625 This field is used with GATT_DISC_CHAR type discovery.*/
626 } tGATT_DISC_VALUE;
627
628 /* discover result record
629 */
630 typedef struct {
631 bluetooth::Uuid type;
632 uint16_t handle;
633 tGATT_DISC_VALUE value;
634 } tGATT_DISC_RES;
635
636 #define GATT_LINK_IDLE_TIMEOUT_WHEN_NO_APP \
637 1 /* start a idle timer for this duration \
638 when no application need to use the link */
639
640 #define GATT_LINK_NO_IDLE_TIMEOUT 0xFFFF
641
642 #define GATT_INVALID_ACL_HANDLE 0xFFFF
643 /* discover result callback function */
644 typedef void(tGATT_DISC_RES_CB)(uint16_t conn_id, tGATT_DISC_TYPE disc_type,
645 tGATT_DISC_RES* p_data);
646
647 /* discover complete callback function */
648 typedef void(tGATT_DISC_CMPL_CB)(uint16_t conn_id, tGATT_DISC_TYPE disc_type,
649 tGATT_STATUS status);
650
651 /* Define a callback function for when read/write/disc/config operation is
652 * completed. */
653 typedef void(tGATT_CMPL_CBACK)(uint16_t conn_id, tGATTC_OPTYPE op,
654 tGATT_STATUS status, tGATT_CL_COMPLETE* p_data);
655
656 /* Define a callback function when an initialized connection is established. */
657 typedef void(tGATT_CONN_CBACK)(tGATT_IF gatt_if, const RawAddress& bda,
658 uint16_t conn_id, bool connected,
659 tGATT_DISCONN_REASON reason,
660 tBT_TRANSPORT transport);
661
662 /* attribute request callback for ATT server */
663 typedef void(tGATT_REQ_CBACK)(uint16_t conn_id, uint32_t trans_id,
664 tGATTS_REQ_TYPE type, tGATTS_DATA* p_data);
665
666 /* channel congestion/uncongestion callback */
667 typedef void(tGATT_CONGESTION_CBACK)(uint16_t conn_id, bool congested);
668
669 /* Define a callback function when encryption is established. */
670 typedef void(tGATT_ENC_CMPL_CB)(tGATT_IF gatt_if, const RawAddress& bda);
671
672 /* Define a callback function when phy is updated. */
673 typedef void(tGATT_PHY_UPDATE_CB)(tGATT_IF gatt_if, uint16_t conn_id,
674 uint8_t tx_phy, uint8_t rx_phy,
675 tGATT_STATUS status);
676
677 /* Define a callback function when connection parameters are updated */
678 typedef void(tGATT_CONN_UPDATE_CB)(tGATT_IF gatt_if, uint16_t conn_id,
679 uint16_t interval, uint16_t latency,
680 uint16_t timeout, tGATT_STATUS status);
681
682 /* Define the structure that applications use to register with
683 * GATT. This structure includes callback functions. All functions
684 * MUST be provided.
685 */
686 typedef struct {
687 tGATT_CONN_CBACK* p_conn_cb{nullptr};
688 tGATT_CMPL_CBACK* p_cmpl_cb{nullptr};
689 tGATT_DISC_RES_CB* p_disc_res_cb{nullptr};
690 tGATT_DISC_CMPL_CB* p_disc_cmpl_cb{nullptr};
691 tGATT_REQ_CBACK* p_req_cb{nullptr};
692 tGATT_ENC_CMPL_CB* p_enc_cmpl_cb{nullptr};
693 tGATT_CONGESTION_CBACK* p_congestion_cb{nullptr};
694 tGATT_PHY_UPDATE_CB* p_phy_update_cb{nullptr};
695 tGATT_CONN_UPDATE_CB* p_conn_update_cb{nullptr};
696 } tGATT_CBACK;
697
698 /***************** Start Handle Management Definitions *********************/
699
700 typedef struct {
701 bluetooth::Uuid app_uuid128;
702 bluetooth::Uuid svc_uuid;
703 uint16_t s_handle;
704 uint16_t e_handle;
705 bool is_primary; /* primary service or secondary */
706 } tGATTS_HNDL_RANGE;
707
708 #define GATTS_SRV_CHG_CMD_ADD_CLIENT 1
709 #define GATTS_SRV_CHG_CMD_UPDATE_CLIENT 2
710 #define GATTS_SRV_CHG_CMD_REMOVE_CLIENT 3
711 #define GATTS_SRV_CHG_CMD_READ_NUM_CLENTS 4
712 #define GATTS_SRV_CHG_CMD_READ_CLENT 5
713 typedef uint8_t tGATTS_SRV_CHG_CMD;
714
715 typedef struct {
716 RawAddress bda;
717 bool srv_changed;
718 } tGATTS_SRV_CHG;
719
720 typedef union {
721 tGATTS_SRV_CHG srv_chg;
722 uint8_t client_read_index; /* only used for sequential reading client srv chg
723 info */
724 } tGATTS_SRV_CHG_REQ;
725
726 typedef union {
727 tGATTS_SRV_CHG srv_chg;
728 uint8_t num_clients;
729 } tGATTS_SRV_CHG_RSP;
730
731 /* Attibute server handle ranges NV storage callback functions
732 */
733 typedef void(tGATTS_NV_SAVE_CBACK)(bool is_saved,
734 tGATTS_HNDL_RANGE* p_hndl_range);
735 typedef bool(tGATTS_NV_SRV_CHG_CBACK)(tGATTS_SRV_CHG_CMD cmd,
736 tGATTS_SRV_CHG_REQ* p_req,
737 tGATTS_SRV_CHG_RSP* p_rsp);
738
739 typedef struct {
740 tGATTS_NV_SAVE_CBACK* p_nv_save_callback;
741 tGATTS_NV_SRV_CHG_CBACK* p_srv_chg_callback;
742 } tGATT_APPL_INFO;
743
744 /******************** End Handle Management Definitions ********************/
745
746 /*******************************************************************************
747 * External Function Declarations
748 ******************************************************************************/
749
750 /******************************************************************************/
751 /* GATT Profile API Functions */
752 /******************************************************************************/
753 /* GATT Profile Server Functions */
754 /******************************************************************************/
755 /*******************************************************************************
756 *
757 * Function GATTS_AddHandleRange
758 *
759 * Description This function add the allocated handles range for the
760 * specified application UUID, service UUID and service
761 * instance
762 *
763 * Parameter p_hndl_range: pointer to allocated handles information
764 ******************************************************************************/
765
766 extern void GATTS_AddHandleRange(tGATTS_HNDL_RANGE* p_hndl_range);
767
768 /*******************************************************************************
769 *
770 * Function GATTS_NVRegister
771 *
772 * Description Application manager calls this function to register for
773 * NV save callback function. There can be one and only one
774 * NV save callback function.
775 *
776 * Parameter p_cb_info : callback informaiton
777 *
778 * Returns true if registered OK, else false
779 *
780 ******************************************************************************/
781 extern bool GATTS_NVRegister(tGATT_APPL_INFO* p_cb_info);
782
783 /*******************************************************************************
784 *
785 * Function BTA_GATTS_AddService
786 *
787 * Description Add a service. When service is ready, a callback
788 * event BTA_GATTS_ADD_SRVC_EVT is called to report status
789 * and handles to the profile.
790 *
791 * Parameters server_if: server interface.
792 * service: pointer array describing service.
793 * count: number of elements in service array.
794 *
795 * Returns on success GATT_SERVICE_STARTED is returned, and
796 * attribute_handle field inside service elements are filled.
797 * on error error status is returned.
798 *
799 ******************************************************************************/
800 extern tGATT_STATUS GATTS_AddService(tGATT_IF gatt_if,
801 btgatt_db_element_t* service, int count);
802
803 /*******************************************************************************
804 *
805 * Function GATTS_DeleteService
806 *
807 * Description This function is called to delete a service.
808 *
809 * Parameter gatt_if : application interface
810 * p_svc_uuid : service UUID
811 * svc_inst : instance of the service inside the
812 * application
813 *
814 * Returns true if operation succeed, else false
815 *
816 ******************************************************************************/
817 extern bool GATTS_DeleteService(tGATT_IF gatt_if, bluetooth::Uuid* p_svc_uuid,
818 uint16_t svc_inst);
819
820 /*******************************************************************************
821 *
822 * Function GATTS_StopService
823 *
824 * Description This function is called to stop a service
825 *
826 * Parameter service_handle : this is the start handle of a service
827 *
828 * Returns None.
829 *
830 ******************************************************************************/
831 extern void GATTS_StopService(uint16_t service_handle);
832
833 /*******************************************************************************
834 *
835 * Function GATTs_HandleValueIndication
836 *
837 * Description This function sends a handle value indication to a client.
838 *
839 * Parameter conn_id: connection identifier.
840 * attr_handle: Attribute handle of this handle value
841 * indication.
842 * val_len: Length of the indicated attribute value.
843 * p_val: Pointer to the indicated attribute value data.
844 *
845 * Returns GATT_SUCCESS if sucessfully sent or queued; otherwise error
846 * code.
847 *
848 ******************************************************************************/
849 extern tGATT_STATUS GATTS_HandleValueIndication(uint16_t conn_id,
850 uint16_t attr_handle,
851 uint16_t val_len,
852 uint8_t* p_val);
853
854 /*******************************************************************************
855 *
856 * Function GATTS_HandleValueNotification
857 *
858 * Description This function sends a handle value notification to a client.
859 *
860 * Parameter conn_id: connection identifier.
861 * attr_handle: Attribute handle of this handle value
862 * indication.
863 * val_len: Length of the indicated attribute value.
864 * p_val: Pointer to the indicated attribute value data.
865 *
866 * Returns GATT_SUCCESS if sucessfully sent; otherwise error code.
867 *
868 ******************************************************************************/
869 extern tGATT_STATUS GATTS_HandleValueNotification(uint16_t conn_id,
870 uint16_t attr_handle,
871 uint16_t val_len,
872 uint8_t* p_val);
873
874 /*******************************************************************************
875 *
876 * Function GATTS_SendRsp
877 *
878 * Description This function sends the server response to client.
879 *
880 * Parameter conn_id: connection identifier.
881 * trans_id: transaction id
882 * status: response status
883 * p_msg: pointer to message parameters structure.
884 *
885 * Returns GATT_SUCCESS if sucessfully sent; otherwise error code.
886 *
887 ******************************************************************************/
888 extern tGATT_STATUS GATTS_SendRsp(uint16_t conn_id, uint32_t trans_id,
889 tGATT_STATUS status, tGATTS_RSP* p_msg);
890
891 /******************************************************************************/
892 /* GATT Profile Client Functions */
893 /******************************************************************************/
894
895 /*******************************************************************************
896 *
897 * Function GATTC_ConfigureMTU
898 *
899 * Description This function is called to configure the ATT MTU size for
900 * a connection on an LE transport.
901 *
902 * Parameters conn_id: connection identifier.
903 * mtu - attribute MTU size..
904 *
905 * Returns GATT_SUCCESS if command started successfully.
906 *
907 ******************************************************************************/
908 extern tGATT_STATUS GATTC_ConfigureMTU(uint16_t conn_id, uint16_t mtu);
909
910 /*******************************************************************************
911 *
912 * Function GATTC_Discover
913 *
914 * Description This function is called to do a discovery procedure on ATT
915 * server.
916 *
917 * Parameters conn_id: connection identifier.
918 * disc_type:discovery type.
919 * start_handle and end_handle: range of handles for discovery
920 * uuid: uuid to discovery. set to Uuid::kEmpty for requests
921 * that don't need it
922 *
923 * Returns GATT_SUCCESS if command received/sent successfully.
924 *
925 ******************************************************************************/
926 extern tGATT_STATUS GATTC_Discover(uint16_t conn_id, tGATT_DISC_TYPE disc_type,
927 uint16_t start_handle, uint16_t end_handle,
928 const bluetooth::Uuid& uuid);
929 extern tGATT_STATUS GATTC_Discover(uint16_t conn_id, tGATT_DISC_TYPE disc_type,
930 uint16_t start_handle, uint16_t end_handle);
931
932 /*******************************************************************************
933 *
934 * Function GATTC_Read
935 *
936 * Description This function is called to read the value of an attribute
937 * from the server.
938 *
939 * Parameters conn_id: connection identifier.
940 * type - attribute read type.
941 * p_read - read operation parameters.
942 *
943 * Returns GATT_SUCCESS if command started successfully.
944 *
945 ******************************************************************************/
946 extern tGATT_STATUS GATTC_Read(uint16_t conn_id, tGATT_READ_TYPE type,
947 tGATT_READ_PARAM* p_read);
948
949 /*******************************************************************************
950 *
951 * Function GATTC_Write
952 *
953 * Description This function is called to read the value of an attribute
954 * from the server.
955 *
956 * Parameters conn_id: connection identifier.
957 * type - attribute write type.
958 * p_write - write operation parameters.
959 *
960 * Returns GATT_SUCCESS if command started successfully.
961 *
962 ******************************************************************************/
963 extern tGATT_STATUS GATTC_Write(uint16_t conn_id, tGATT_WRITE_TYPE type,
964 tGATT_VALUE* p_write);
965
966 /*******************************************************************************
967 *
968 * Function GATTC_ExecuteWrite
969 *
970 * Description This function is called to send an Execute write request to
971 * the server.
972 *
973 * Parameters conn_id: connection identifier.
974 * is_execute - to execute or cancel the prepare write
975 * request(s)
976 *
977 * Returns GATT_SUCCESS if command started successfully.
978 *
979 ******************************************************************************/
980 extern tGATT_STATUS GATTC_ExecuteWrite(uint16_t conn_id, bool is_execute);
981
982 /*******************************************************************************
983 *
984 * Function GATTC_SendHandleValueConfirm
985 *
986 * Description This function is called to send a handle value confirmation
987 * as response to a handle value notification from server.
988 *
989 * Parameters conn_id: connection identifier.
990 * handle: the handle of the attribute confirmation.
991 *
992 * Returns GATT_SUCCESS if command started successfully.
993 *
994 ******************************************************************************/
995 extern tGATT_STATUS GATTC_SendHandleValueConfirm(uint16_t conn_id,
996 uint16_t handle);
997
998 /*******************************************************************************
999 *
1000 * Function GATT_SetIdleTimeout
1001 *
1002 * Description This function (common to both client and server) sets the
1003 * idle timeout for a tansport connection
1004 *
1005 * Parameter bd_addr: target device bd address.
1006 * idle_tout: timeout value in seconds.
1007 * transport: trasnport option.
1008 *
1009 * Returns void
1010 *
1011 ******************************************************************************/
1012 extern void GATT_SetIdleTimeout(const RawAddress& bd_addr, uint16_t idle_tout,
1013 tBT_TRANSPORT transport);
1014
1015 /*******************************************************************************
1016 *
1017 * Function GATT_Register
1018 *
1019 * Description This function is called to register an application
1020 * with GATT
1021 *
1022 * Parameter p_app_uuid128: Application UUID
1023 * p_cb_info: callback functions.
1024 * eatt_support: set support for eatt
1025 *
1026 * Returns 0 for error, otherwise the index of the client registered
1027 * with GATT
1028 *
1029 ******************************************************************************/
1030 extern tGATT_IF GATT_Register(const bluetooth::Uuid& p_app_uuid128,
1031 const std::string name, tGATT_CBACK* p_cb_info,
1032 bool eatt_support);
1033
1034 /*******************************************************************************
1035 *
1036 * Function GATT_Deregister
1037 *
1038 * Description This function deregistered the application from GATT.
1039 *
1040 * Parameters gatt_if: applicaiton interface.
1041 *
1042 * Returns None.
1043 *
1044 ******************************************************************************/
1045 extern void GATT_Deregister(tGATT_IF gatt_if);
1046
1047 /*******************************************************************************
1048 *
1049 * Function GATT_StartIf
1050 *
1051 * Description This function is called after registration to start
1052 * receiving callbacks for registered interface. Function may
1053 * call back with connection status and queued notifications
1054 *
1055 * Parameter gatt_if: applicaiton interface.
1056 *
1057 * Returns None
1058 *
1059 ******************************************************************************/
1060 extern void GATT_StartIf(tGATT_IF gatt_if);
1061
1062 /*******************************************************************************
1063 *
1064 * Function GATT_Connect
1065 *
1066 * Description This function initiate a connecttion to a remote device on
1067 * GATT channel.
1068 *
1069 * Parameters gatt_if: applicaiton interface
1070 * bd_addr: peer device address.
1071 * is_direct: is a direct connection or a background auto
1072 * connection
1073 * transport : Physical transport for GATT connection
1074 * (BR/EDR or LE)
1075 * opportunistic: will not keep device connected if other apps
1076 * disconnect, will not update connected apps counter, when
1077 * disconnected won't cause physical disconnection.
1078 *
1079 * Returns true if connection started; else false
1080 *
1081 ******************************************************************************/
1082 extern bool GATT_Connect(tGATT_IF gatt_if, const RawAddress& bd_addr,
1083 bool is_direct, tBT_TRANSPORT transport,
1084 bool opportunistic);
1085 extern bool GATT_Connect(tGATT_IF gatt_if, const RawAddress& bd_addr,
1086 bool is_direct, tBT_TRANSPORT transport,
1087 bool opportunistic, uint8_t initiating_phys);
1088
1089 /*******************************************************************************
1090 *
1091 * Function GATT_CancelConnect
1092 *
1093 * Description Terminate the connection initiation to a remote device on a
1094 * GATT channel.
1095 *
1096 * Parameters gatt_if: client interface. If 0 used as unconditionally
1097 * disconnect, typically used for direct connection
1098 * cancellation.
1099 * bd_addr: peer device address.
1100 * is_direct: is a direct conenection or a background auto
1101 * connection
1102 *
1103 * Returns true if connection started; else false
1104 *
1105 ******************************************************************************/
1106 extern bool GATT_CancelConnect(tGATT_IF gatt_if, const RawAddress& bd_addr,
1107 bool is_direct);
1108
1109 /*******************************************************************************
1110 *
1111 * Function GATT_Disconnect
1112 *
1113 * Description Disconnect the GATT channel for this registered application.
1114 *
1115 * Parameters conn_id: connection identifier.
1116 *
1117 * Returns GATT_SUCCESS if disconnected.
1118 *
1119 ******************************************************************************/
1120 extern tGATT_STATUS GATT_Disconnect(uint16_t conn_id);
1121
1122 /*******************************************************************************
1123 *
1124 * Function GATT_GetConnectionInfor
1125 *
1126 * Description Use conn_id to find its associated BD address and
1127 * application interface
1128 *
1129 * Parameters conn_id: connection id (input)
1130 * p_gatt_if: applicaiton interface (output)
1131 * bd_addr: peer device address. (output)
1132 * transport : physical transport of the GATT connection
1133 * (BR/EDR or LE)
1134 *
1135 * Returns true the ligical link information is found for conn_id
1136 *
1137 ******************************************************************************/
1138 extern bool GATT_GetConnectionInfor(uint16_t conn_id, tGATT_IF* p_gatt_if,
1139 RawAddress& bd_addr,
1140 tBT_TRANSPORT* p_transport);
1141
1142 /*******************************************************************************
1143 *
1144 * Function GATT_GetConnIdIfConnected
1145 *
1146 * Description Find the conn_id if the logical link for a BD address
1147 * and application interface is connected
1148 *
1149 * Parameters gatt_if: applicaiton interface (input)
1150 * bd_addr: peer device address. (input)
1151 * p_conn_id: connection id (output)
1152 * transport : physical transport of the GATT connection
1153 * (BR/EDR or LE)
1154 *
1155 * Returns true the ligical link is connected
1156 *
1157 ******************************************************************************/
1158 extern bool GATT_GetConnIdIfConnected(tGATT_IF gatt_if,
1159 const RawAddress& bd_addr,
1160 uint16_t* p_conn_id,
1161 tBT_TRANSPORT transport);
1162
1163 /*******************************************************************************
1164 *
1165 * Function GATT_ConfigServiceChangeCCC
1166 *
1167 * Description Configure service change indication on remote device
1168 *
1169 * Returns None.
1170 *
1171 ******************************************************************************/
1172 extern void GATT_ConfigServiceChangeCCC(const RawAddress& remote_bda,
1173 bool enable, tBT_TRANSPORT transport);
1174
1175 // Enables the GATT profile on the device.
1176 // It clears out the control blocks, and registers with L2CAP.
1177 extern void gatt_init(void);
1178
1179 // Frees resources used by the GATT profile.
1180 extern void gatt_free(void);
1181
1182 // Link encryption complete notification for all encryption process
1183 // initiated outside GATT.
1184 extern void gatt_notify_enc_cmpl(const RawAddress& bd_addr);
1185
1186 /** Reset bg device list. If called after controller reset, set |after_reset| to
1187 * true, as there is no need to wipe controller acceptlist in this case. */
1188 extern void gatt_reset_bgdev_list(bool after_reset);
1189
1190 #endif /* GATT_API_H */
1191