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