1 /******************************************************************************
2  *
3  *  Copyright (C) 2003-2013 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 
19 /******************************************************************************
20  *
21  *  This is the public interface file for BTA GATT.
22  *
23  ******************************************************************************/
24 
25 #ifndef BTA_GATT_API_H
26 #define BTA_GATT_API_H
27 
28 #include "bta_api.h"
29 #include "gatt_api.h"
30 #include "osi/include/list.h"
31 
32 #include <base/callback_forward.h>
33 #include <vector>
34 
35 using std::vector;
36 
37 #ifndef BTA_GATT_DEBUG
38 #define BTA_GATT_DEBUG false
39 #endif
40 
41 /*****************************************************************************
42  *  Constants and data types
43  ****************************************************************************/
44 /**************************
45  *  Common Definitions
46  **************************/
47 /* GATT ID */
48 typedef struct {
49   tBT_UUID uuid;   /* uuid of the attribute */
50   uint8_t inst_id; /* instance ID */
51 } __attribute__((packed)) tBTA_GATT_ID;
52 
53 /* Success code and error codes */
54 #define BTA_GATT_OK GATT_SUCCESS
55 #define BTA_GATT_INVALID_HANDLE GATT_INVALID_HANDLE             /* 0x0001 */
56 #define BTA_GATT_READ_NOT_PERMIT GATT_READ_NOT_PERMIT           /* 0x0002 */
57 #define BTA_GATT_WRITE_NOT_PERMIT GATT_WRITE_NOT_PERMIT         /* 0x0003 */
58 #define BTA_GATT_INVALID_PDU GATT_INVALID_PDU                   /* 0x0004 */
59 #define BTA_GATT_INSUF_AUTHENTICATION GATT_INSUF_AUTHENTICATION /* 0x0005 */
60 #define BTA_GATT_REQ_NOT_SUPPORTED GATT_REQ_NOT_SUPPORTED       /* 0x0006 */
61 #define BTA_GATT_INVALID_OFFSET GATT_INVALID_OFFSET             /* 0x0007 */
62 #define BTA_GATT_INSUF_AUTHORIZATION GATT_INSUF_AUTHORIZATION   /* 0x0008 */
63 #define BTA_GATT_PREPARE_Q_FULL GATT_PREPARE_Q_FULL             /* 0x0009 */
64 #define BTA_GATT_NOT_FOUND GATT_NOT_FOUND                       /* 0x000a */
65 #define BTA_GATT_NOT_LONG GATT_NOT_LONG                         /* 0x000b */
66 #define BTA_GATT_INSUF_KEY_SIZE GATT_INSUF_KEY_SIZE             /* 0x000c */
67 #define BTA_GATT_INVALID_ATTR_LEN GATT_INVALID_ATTR_LEN         /* 0x000d */
68 #define BTA_GATT_ERR_UNLIKELY GATT_ERR_UNLIKELY                 /* 0x000e */
69 #define BTA_GATT_INSUF_ENCRYPTION GATT_INSUF_ENCRYPTION         /* 0x000f */
70 #define BTA_GATT_UNSUPPORT_GRP_TYPE GATT_UNSUPPORT_GRP_TYPE     /* 0x0010 */
71 #define BTA_GATT_INSUF_RESOURCE GATT_INSUF_RESOURCE             /* 0x0011 */
72 
73 #define BTA_GATT_NO_RESOURCES GATT_NO_RESOURCES           /* 0x80 */
74 #define BTA_GATT_INTERNAL_ERROR GATT_INTERNAL_ERROR       /* 0x81 */
75 #define BTA_GATT_WRONG_STATE GATT_WRONG_STATE             /* 0x82 */
76 #define BTA_GATT_DB_FULL GATT_DB_FULL                     /* 0x83 */
77 #define BTA_GATT_BUSY GATT_BUSY                           /* 0x84 */
78 #define BTA_GATT_ERROR GATT_ERROR                         /* 0x85 */
79 #define BTA_GATT_CMD_STARTED GATT_CMD_STARTED             /* 0x86 */
80 #define BTA_GATT_ILLEGAL_PARAMETER GATT_ILLEGAL_PARAMETER /* 0x87 */
81 #define BTA_GATT_PENDING GATT_PENDING                     /* 0x88 */
82 #define BTA_GATT_AUTH_FAIL GATT_AUTH_FAIL                 /* 0x89 */
83 #define BTA_GATT_MORE GATT_MORE                           /* 0x8a */
84 #define BTA_GATT_INVALID_CFG GATT_INVALID_CFG             /* 0x8b */
85 #define BTA_GATT_SERVICE_STARTED GATT_SERVICE_STARTED     /* 0x8c */
86 #define BTA_GATT_ENCRYPED_MITM GATT_ENCRYPED_MITM         /* GATT_SUCCESS */
87 #define BTA_GATT_ENCRYPED_NO_MITM GATT_ENCRYPED_NO_MITM   /* 0x8d */
88 #define BTA_GATT_NOT_ENCRYPTED GATT_NOT_ENCRYPTED         /* 0x8e */
89 #define BTA_GATT_CONGESTED GATT_CONGESTED                 /* 0x8f */
90 
91 #define BTA_GATT_DUP_REG 0x90      /* 0x90 */
92 #define BTA_GATT_ALREADY_OPEN 0x91 /* 0x91 */
93 #define BTA_GATT_CANCEL 0x92       /* 0x92 */
94 
95 /* 0xE0 ~ 0xFC reserved for future use */
96 #define BTA_GATT_CCC_CFG_ERR                                              \
97   GATT_CCC_CFG_ERR /* 0xFD Client Characteristic Configuration Descriptor \
98                       Improperly Configured */
99 #define BTA_GATT_PRC_IN_PROGRESS \
100   GATT_PRC_IN_PROGRESS /* 0xFE Procedure Already in progress */
101 #define BTA_GATT_OUT_OF_RANGE \
102   GATT_OUT_OF_RANGE /* 0xFFAttribute value out of range */
103 
104 typedef uint8_t tBTA_GATT_STATUS;
105 
106 #define BTA_GATT_INVALID_CONN_ID GATT_INVALID_CONN_ID
107 
108 /* Client callback function events */
109 #define BTA_GATTC_DEREG_EVT 1        /* GATT client deregistered event */
110 #define BTA_GATTC_OPEN_EVT 2         /* GATTC open request status  event */
111 #define BTA_GATTC_CLOSE_EVT 5        /* GATTC  close request status event */
112 #define BTA_GATTC_SEARCH_CMPL_EVT 6  /* GATT discovery complete event */
113 #define BTA_GATTC_SEARCH_RES_EVT 7   /* GATT discovery result event */
114 #define BTA_GATTC_NOTIF_EVT 10       /* GATT attribute notification event */
115 #define BTA_GATTC_EXEC_EVT 12        /* execute write complete event */
116 #define BTA_GATTC_ACL_EVT 13         /* ACL up event */
117 #define BTA_GATTC_CANCEL_OPEN_EVT 14 /* cancel open event */
118 #define BTA_GATTC_SRVC_CHG_EVT 15    /* service change event */
119 #define BTA_GATTC_ENC_CMPL_CB_EVT 17 /* encryption complete callback event */
120 #define BTA_GATTC_CFG_MTU_EVT 18     /* configure MTU complete event */
121 #define BTA_GATTC_CONGEST_EVT 24     /* Congestion event */
122 #define BTA_GATTC_PHY_UPDATE_EVT 25  /* PHY change event */
123 #define BTA_GATTC_CONN_UPDATE_EVT 26 /* Connection parameters update event */
124 
125 typedef uint8_t tBTA_GATTC_EVT;
126 
127 typedef tGATT_IF tBTA_GATTC_IF;
128 
129 typedef struct {
130   uint16_t unit;  /* as UUIUD defined by SIG */
131   uint16_t descr; /* as UUID as defined by SIG */
132   tGATT_FORMAT format;
133   int8_t exp;
134   uint8_t name_spc; /* The name space of the description */
135 } tBTA_GATT_CHAR_PRES;
136 
137 #define BTA_GATT_CLT_CONFIG_NONE GATT_CLT_CONFIG_NONE /* 0x0000    */
138 #define BTA_GATT_CLT_CONFIG_NOTIFICATION \
139   GATT_CLT_CONFIG_NOTIFICATION                                    /* 0x0001 */
140 #define BTA_GATT_CLT_CONFIG_INDICATION GATT_CLT_CONFIG_INDICATION /* 0x0002 */
141 typedef uint16_t tBTA_GATT_CLT_CHAR_CONFIG;
142 
143 /* characteristic descriptor: server configuration value
144 */
145 #define BTA_GATT_SVR_CONFIG_NONE GATT_SVR_CONFIG_NONE           /* 0x0000 */
146 #define BTA_GATT_SVR_CONFIG_BROADCAST GATT_SVR_CONFIG_BROADCAST /*  0x0001 */
147 typedef uint16_t tBTA_GATT_SVR_CHAR_CONFIG;
148 
149 /* Characteristic Aggregate Format attribute value
150 */
151 #define BTA_GATT_AGGR_HANDLE_NUM_MAX 10
152 typedef struct {
153   uint8_t num_handle;
154   uint16_t handle_list[BTA_GATT_AGGR_HANDLE_NUM_MAX];
155 } tBTA_GATT_CHAR_AGGRE;
156 typedef tGATT_VALID_RANGE tBTA_GATT_VALID_RANGE;
157 
158 typedef struct {
159   uint16_t len;
160   uint8_t* p_value;
161 } tBTA_GATT_UNFMT;
162 
163 #define BTA_GATT_MAX_ATTR_LEN GATT_MAX_ATTR_LEN
164 
165 #define BTA_GATTC_TYPE_WRITE GATT_WRITE
166 #define BTA_GATTC_TYPE_WRITE_NO_RSP GATT_WRITE_NO_RSP
167 typedef uint8_t tBTA_GATTC_WRITE_TYPE;
168 
169 #define BTA_GATT_CONN_UNKNOWN 0
170 #define BTA_GATT_CONN_L2C_FAILURE \
171   GATT_CONN_L2C_FAILURE /* general l2cap resource failure */
172 #define BTA_GATT_CONN_TIMEOUT GATT_CONN_TIMEOUT /* 0x08 connection timeout  */
173 #define BTA_GATT_CONN_TERMINATE_PEER_USER \
174   GATT_CONN_TERMINATE_PEER_USER /* 0x13 connection terminate by peer user  */
175 #define BTA_GATT_CONN_TERMINATE_LOCAL_HOST \
176   GATT_CONN_TERMINATE_LOCAL_HOST /* 0x16 connectionterminated by local host */
177 #define BTA_GATT_CONN_FAIL_ESTABLISH \
178   GATT_CONN_FAIL_ESTABLISH /* 0x03E connection fail to establish  */
179 #define BTA_GATT_CONN_LMP_TIMEOUT \
180   GATT_CONN_LMP_TIMEOUT /* 0x22 connection fail for LMP response tout */
181 #define BTA_GATT_CONN_CANCEL \
182   GATT_CONN_CANCEL                /* 0x0100 L2CAP connection cancelled  */
183 #define BTA_GATT_CONN_NONE 0x0101 /* 0x0101 no connection to cancel  */
184 typedef uint16_t tBTA_GATT_REASON;
185 
186 #define BTA_GATTC_MULTI_MAX GATT_MAX_READ_MULTI_HANDLES
187 
188 typedef struct {
189   uint8_t num_attr;
190   uint16_t handles[BTA_GATTC_MULTI_MAX];
191 } tBTA_GATTC_MULTI;
192 
193 #define BTA_GATT_AUTH_REQ_NONE GATT_AUTH_REQ_NONE
194 #define BTA_GATT_AUTH_REQ_NO_MITM \
195   GATT_AUTH_REQ_NO_MITM /* unauthenticated encryption */
196 #define BTA_GATT_AUTH_REQ_MITM                   \
197   GATT_AUTH_REQ_MITM /* authenticated encryption \
198                         */
199 #define BTA_GATT_AUTH_REQ_SIGNED_NO_MITM GATT_AUTH_REQ_SIGNED_NO_MITM
200 #define BTA_GATT_AUTH_REQ_SIGNED_MITM GATT_AUTH_REQ_SIGNED_MITM
201 
202 typedef tGATT_AUTH_REQ tBTA_GATT_AUTH_REQ;
203 
204 enum {
205   BTA_GATTC_ATTR_TYPE_INCL_SRVC,
206   BTA_GATTC_ATTR_TYPE_CHAR,
207   BTA_GATTC_ATTR_TYPE_CHAR_DESCR,
208   BTA_GATTC_ATTR_TYPE_SRVC
209 };
210 typedef uint8_t tBTA_GATTC_ATTR_TYPE;
211 
212 typedef struct {
213   tBT_UUID uuid;
214   uint16_t s_handle;
215   uint16_t e_handle; /* used for service only */
216   uint8_t attr_type;
217   uint8_t id;
218   uint8_t prop;              /* used when attribute type is characteristic */
219   bool is_primary;           /* used when attribute type is service */
220   uint16_t incl_srvc_handle; /* used when attribute type is included service */
221 } tBTA_GATTC_NV_ATTR;
222 
223 /* callback data structure */
224 typedef struct {
225   tBTA_GATT_STATUS status;
226   tBTA_GATTC_IF client_if;
227   tBT_UUID app_uuid;
228 } tBTA_GATTC_REG;
229 
230 typedef struct {
231   uint16_t conn_id;
232   tBTA_GATT_STATUS status;
233   uint16_t handle;
234   uint16_t len;
235   uint8_t value[BTA_GATT_MAX_ATTR_LEN];
236 } tBTA_GATTC_READ;
237 
238 typedef struct {
239   uint16_t conn_id;
240   tBTA_GATT_STATUS status;
241   uint16_t handle;
242 } tBTA_GATTC_WRITE;
243 
244 typedef struct {
245   uint16_t conn_id;
246   tBTA_GATT_STATUS status;
247 } tBTA_GATTC_EXEC_CMPL;
248 
249 typedef struct {
250   uint16_t conn_id;
251   tBTA_GATT_STATUS status;
252 } tBTA_GATTC_SEARCH_CMPL;
253 
254 typedef struct {
255   uint16_t conn_id;
256   tBTA_GATT_ID service_uuid;
257 } tBTA_GATTC_SRVC_RES;
258 
259 typedef struct {
260   uint16_t conn_id;
261   tBTA_GATT_STATUS status;
262   uint16_t mtu;
263 } tBTA_GATTC_CFG_MTU;
264 
265 typedef struct {
266   tBTA_GATT_STATUS status;
267   uint16_t conn_id;
268   tBTA_GATTC_IF client_if;
269   BD_ADDR remote_bda;
270   tBTA_TRANSPORT transport;
271   uint16_t mtu;
272 } tBTA_GATTC_OPEN;
273 
274 typedef struct {
275   tBTA_GATT_STATUS status;
276   uint16_t conn_id;
277   tBTA_GATTC_IF client_if;
278   BD_ADDR remote_bda;
279   tBTA_GATT_REASON reason; /* disconnect reason code, not useful when connect
280                               event is reported */
281 } tBTA_GATTC_CLOSE;
282 
283 typedef struct {
284   uint16_t conn_id;
285   BD_ADDR bda;
286   uint16_t handle;
287   uint16_t len;
288   uint8_t value[BTA_GATT_MAX_ATTR_LEN];
289   bool is_notify;
290 } tBTA_GATTC_NOTIFY;
291 
292 typedef struct {
293   uint16_t conn_id;
294   bool congested; /* congestion indicator */
295 } tBTA_GATTC_CONGEST;
296 
297 typedef struct {
298   tBTA_GATT_STATUS status;
299   tBTA_GATTC_IF client_if;
300   uint16_t conn_id;
301   BD_ADDR remote_bda;
302 } tBTA_GATTC_OPEN_CLOSE;
303 
304 typedef struct {
305   tBTA_GATTC_IF client_if;
306   BD_ADDR remote_bda;
307 } tBTA_GATTC_ENC_CMPL_CB;
308 
309 typedef struct {
310   tBTA_GATTC_IF server_if;
311   uint16_t conn_id;
312   uint8_t tx_phy;
313   uint8_t rx_phy;
314   tBTA_GATT_STATUS status;
315 } tBTA_GATTC_PHY_UPDATE;
316 
317 typedef struct {
318   tBTA_GATTC_IF server_if;
319   uint16_t conn_id;
320   uint16_t interval;
321   uint16_t latency;
322   uint16_t timeout;
323   tBTA_GATT_STATUS status;
324 } tBTA_GATTC_CONN_UPDATE;
325 
326 typedef union {
327   tBTA_GATT_STATUS status;
328 
329   tBTA_GATTC_SEARCH_CMPL search_cmpl; /* discovery complete */
330   tBTA_GATTC_SRVC_RES srvc_res;       /* discovery result */
331   tBTA_GATTC_REG reg_oper;            /* registration data */
332   tBTA_GATTC_OPEN open;
333   tBTA_GATTC_CLOSE close;
334   tBTA_GATTC_READ read;           /* read attribute/descriptor data */
335   tBTA_GATTC_WRITE write;         /* write complete data */
336   tBTA_GATTC_EXEC_CMPL exec_cmpl; /*  execute complete */
337   tBTA_GATTC_NOTIFY notify;       /* notification/indication event data */
338   tBTA_GATTC_ENC_CMPL_CB enc_cmpl;
339   BD_ADDR remote_bda;         /* service change event */
340   tBTA_GATTC_CFG_MTU cfg_mtu; /* configure MTU operation */
341   tBTA_GATTC_CONGEST congest;
342   tBTA_GATTC_PHY_UPDATE phy_update;
343   tBTA_GATTC_CONN_UPDATE conn_update;
344 } tBTA_GATTC;
345 
346 /* GATTC enable callback function */
347 typedef void(tBTA_GATTC_ENB_CBACK)(tBTA_GATT_STATUS status);
348 
349 /* Client callback function */
350 typedef void(tBTA_GATTC_CBACK)(tBTA_GATTC_EVT event, tBTA_GATTC* p_data);
351 
352 /* GATT Server Data Structure */
353 /* Server callback function events */
354 #define BTA_GATTS_REG_EVT 0
355 #define BTA_GATTS_READ_CHARACTERISTIC_EVT \
356   GATTS_REQ_TYPE_READ_CHARACTERISTIC                                 /* 1 */
357 #define BTA_GATTS_READ_DESCRIPTOR_EVT GATTS_REQ_TYPE_READ_DESCRIPTOR /* 2 */
358 #define BTA_GATTS_WRITE_CHARACTERISTIC_EVT \
359   GATTS_REQ_TYPE_WRITE_CHARACTERISTIC                                  /* 3 */
360 #define BTA_GATTS_WRITE_DESCRIPTOR_EVT GATTS_REQ_TYPE_WRITE_DESCRIPTOR /* 4 */
361 #define BTA_GATTS_EXEC_WRITE_EVT GATTS_REQ_TYPE_WRITE_EXEC             /* 5 */
362 #define BTA_GATTS_MTU_EVT GATTS_REQ_TYPE_MTU                           /* 6 */
363 #define BTA_GATTS_CONF_EVT GATTS_REQ_TYPE_CONF                         /* 7 */
364 #define BTA_GATTS_DEREG_EVT 8
365 #define BTA_GATTS_DELELTE_EVT 11
366 #define BTA_GATTS_STOP_EVT 13
367 #define BTA_GATTS_CONNECT_EVT 14
368 #define BTA_GATTS_DISCONNECT_EVT 15
369 #define BTA_GATTS_OPEN_EVT 16
370 #define BTA_GATTS_CANCEL_OPEN_EVT 17
371 #define BTA_GATTS_CLOSE_EVT 18
372 #define BTA_GATTS_CONGEST_EVT 20
373 #define BTA_GATTS_PHY_UPDATE_EVT 21
374 #define BTA_GATTS_CONN_UPDATE_EVT 22
375 
376 typedef uint8_t tBTA_GATTS_EVT;
377 typedef tGATT_IF tBTA_GATTS_IF;
378 
379 /* Attribute permissions
380 */
381 #define BTA_GATT_PERM_READ GATT_PERM_READ /* bit 0 -  0x0001 */
382 #define BTA_GATT_PERM_READ_ENCRYPTED \
383   GATT_PERM_READ_ENCRYPTED /* bit 1 -  0x0002 */
384 #define BTA_GATT_PERM_READ_ENC_MITM \
385   GATT_PERM_READ_ENC_MITM                   /* bit 2 -  0x0004 */
386 #define BTA_GATT_PERM_WRITE GATT_PERM_WRITE /* bit 4 -  0x0010 */
387 #define BTA_GATT_PERM_WRITE_ENCRYPTED \
388   GATT_PERM_WRITE_ENCRYPTED /* bit 5 -  0x0020 */
389 #define BTA_GATT_PERM_WRITE_ENC_MITM \
390   GATT_PERM_WRITE_ENC_MITM /* bit 6 -  0x0040 */
391 #define BTA_GATT_PERM_WRITE_SIGNED          \
392   GATT_PERM_WRITE_SIGNED /* bit 7 -  0x0080 \
393                             */
394 #define BTA_GATT_PERM_WRITE_SIGNED_MITM \
395   GATT_PERM_WRITE_SIGNED_MITM /* bit 8 -  0x0100 */
396 typedef uint16_t tBTA_GATT_PERM;
397 
398 #define BTA_GATTS_INVALID_APP 0xff
399 
400 #define BTA_GATTS_INVALID_IF 0
401 
402 /* definition of characteristic properties */
403 #define BTA_GATT_CHAR_PROP_BIT_BROADCAST                                    \
404   GATT_CHAR_PROP_BIT_BROADCAST                                      /* 0x01 \
405                                                                        */
406 #define BTA_GATT_CHAR_PROP_BIT_READ GATT_CHAR_PROP_BIT_READ         /* 0x02 */
407 #define BTA_GATT_CHAR_PROP_BIT_WRITE_NR GATT_CHAR_PROP_BIT_WRITE_NR /* 0x04 */
408 #define BTA_GATT_CHAR_PROP_BIT_WRITE GATT_CHAR_PROP_BIT_WRITE       /* 0x08 */
409 #define BTA_GATT_CHAR_PROP_BIT_NOTIFY GATT_CHAR_PROP_BIT_NOTIFY     /* 0x10 */
410 #define BTA_GATT_CHAR_PROP_BIT_INDICATE GATT_CHAR_PROP_BIT_INDICATE /* 0x20 */
411 #define BTA_GATT_CHAR_PROP_BIT_AUTH GATT_CHAR_PROP_BIT_AUTH         /* 0x40 */
412 #define BTA_GATT_CHAR_PROP_BIT_EXT_PROP GATT_CHAR_PROP_BIT_EXT_PROP /* 0x80 */
413 typedef uint8_t tBTA_GATT_CHAR_PROP;
414 
415 #ifndef BTA_GATTC_CHAR_DESCR_MAX
416 #define BTA_GATTC_CHAR_DESCR_MAX 7
417 #endif
418 
419 /***********************  NV callback Data Definitions   **********************
420 */
421 typedef struct {
422   tBT_UUID app_uuid128;
423   tBT_UUID svc_uuid;
424   uint16_t svc_inst;
425   uint16_t s_handle;
426   uint16_t e_handle;
427   bool is_primary; /* primary service or secondary */
428 } tBTA_GATTS_HNDL_RANGE;
429 
430 #define BTA_GATTS_SRV_CHG_CMD_ADD_CLIENT GATTS_SRV_CHG_CMD_ADD_CLIENT
431 #define BTA_GATTS_SRV_CHG_CMD_UPDATE_CLIENT GATTS_SRV_CHG_CMD_UPDATE_CLIENT
432 #define BTA_GATTS_SRV_CHG_CMD_REMOVE_CLIENT GATTS_SRV_CHG_CMD_REMOVE_CLIENT
433 #define BTA_GATTS_SRV_CHG_CMD_READ_NUM_CLENTS GATTS_SRV_CHG_CMD_READ_NUM_CLENTS
434 #define BTA_GATTS_SRV_CHG_CMD_READ_CLENT GATTS_SRV_CHG_CMD_READ_CLENT
435 typedef tGATTS_SRV_CHG_CMD tBTA_GATTS_SRV_CHG_CMD;
436 
437 typedef tGATTS_SRV_CHG tBTA_GATTS_SRV_CHG;
438 typedef tGATTS_SRV_CHG_REQ tBTA_GATTS_SRV_CHG_REQ;
439 typedef tGATTS_SRV_CHG_RSP tBTA_GATTS_SRV_CHG_RSP;
440 
441 #define BTA_GATT_TRANSPORT_LE GATT_TRANSPORT_LE
442 #define BTA_GATT_TRANSPORT_BR_EDR GATT_TRANSPORT_BR_EDR
443 #define BTA_GATT_TRANSPORT_LE_BR_EDR GATT_TRANSPORT_LE_BR_EDR
444 typedef uint8_t tBTA_GATT_TRANSPORT;
445 
446 /* attribute value */
447 typedef tGATT_VALUE tBTA_GATT_VALUE;
448 
449 /* attribute response data */
450 typedef tGATTS_RSP tBTA_GATTS_RSP;
451 
452 /* attribute request data from the client */
453 #define BTA_GATT_PREP_WRITE_CANCEL 0x00
454 #define BTA_GATT_PREP_WRITE_EXEC 0x01
455 typedef tGATT_EXEC_FLAG tBTA_GATT_EXEC_FLAG;
456 
457 /* read request always based on UUID */
458 typedef tGATT_READ_REQ tTA_GBATT_READ_REQ;
459 
460 /* write request data */
461 typedef tGATT_WRITE_REQ tBTA_GATT_WRITE_REQ;
462 
463 /* callback data for server access request from client */
464 typedef tGATTS_DATA tBTA_GATTS_REQ_DATA;
465 
466 typedef struct {
467   tBTA_GATT_STATUS status;
468   BD_ADDR remote_bda;
469   uint32_t trans_id;
470   uint16_t conn_id;
471   tBTA_GATTS_REQ_DATA* p_data;
472 } tBTA_GATTS_REQ;
473 
474 typedef struct {
475   tBTA_GATTS_IF server_if;
476   tBTA_GATT_STATUS status;
477   tBT_UUID uuid;
478 } tBTA_GATTS_REG_OPER;
479 
480 typedef struct {
481   tBTA_GATTS_IF server_if;
482   uint16_t service_id;
483   uint16_t svc_instance;
484   bool is_primary;
485   tBTA_GATT_STATUS status;
486   tBT_UUID uuid;
487 } tBTA_GATTS_CREATE;
488 
489 typedef struct {
490   tBTA_GATTS_IF server_if;
491   uint16_t service_id;
492   tBTA_GATT_STATUS status;
493 } tBTA_GATTS_SRVC_OPER;
494 
495 typedef struct {
496   tBTA_GATTS_IF server_if;
497   BD_ADDR remote_bda;
498   uint16_t conn_id;
499   tBTA_GATT_REASON reason; /* report disconnect reason */
500   tBTA_GATT_TRANSPORT transport;
501 } tBTA_GATTS_CONN;
502 
503 typedef struct {
504   uint16_t conn_id;
505   bool congested; /* report channel congestion indicator */
506 } tBTA_GATTS_CONGEST;
507 
508 typedef struct {
509   uint16_t conn_id;        /* connection ID */
510   tBTA_GATT_STATUS status; /* notification/indication status */
511 } tBTA_GATTS_CONF;
512 
513 typedef struct {
514   tBTA_GATTS_IF server_if;
515   uint16_t conn_id;
516   uint8_t tx_phy;
517   uint8_t rx_phy;
518   tBTA_GATT_STATUS status;
519 } tBTA_GATTS_PHY_UPDATE;
520 
521 typedef struct {
522   tBTA_GATTS_IF server_if;
523   uint16_t conn_id;
524   uint16_t interval;
525   uint16_t latency;
526   uint16_t timeout;
527   tBTA_GATT_STATUS status;
528 } tBTA_GATTS_CONN_UPDATE;
529 
530 /* GATTS callback data */
531 typedef union {
532   tBTA_GATTS_REG_OPER reg_oper;
533   tBTA_GATTS_CREATE create;
534   tBTA_GATTS_SRVC_OPER srvc_oper;
535   tBTA_GATT_STATUS status; /* BTA_GATTS_LISTEN_EVT */
536   tBTA_GATTS_REQ req_data;
537   tBTA_GATTS_CONN conn;       /* BTA_GATTS_CONN_EVT */
538   tBTA_GATTS_CONGEST congest; /* BTA_GATTS_CONGEST_EVT callback data */
539   tBTA_GATTS_CONF confirm;    /* BTA_GATTS_CONF_EVT callback data */
540   tBTA_GATTS_PHY_UPDATE phy_update; /* BTA_GATTS_PHY_UPDATE_EVT callback data */
541   tBTA_GATTS_CONN_UPDATE
542       conn_update; /* BTA_GATTS_CONN_UPDATE_EVT callback data */
543 } tBTA_GATTS;
544 
545 /* GATTS enable callback function */
546 typedef void(tBTA_GATTS_ENB_CBACK)(tBTA_GATT_STATUS status);
547 
548 /* Server callback function */
549 typedef void(tBTA_GATTS_CBACK)(tBTA_GATTS_EVT event, tBTA_GATTS* p_data);
550 
551 typedef struct {
552   tBT_UUID uuid;
553   bool is_primary;
554   uint16_t handle;
555   uint16_t s_handle;
556   uint16_t e_handle;
557   list_t* characteristics; /* list of tBTA_GATTC_CHARACTERISTIC */
558   list_t* included_svc;    /* list of tBTA_GATTC_INCLUDED_SVC */
559 } __attribute__((packed, aligned(alignof(tBT_UUID)))) tBTA_GATTC_SERVICE;
560 
561 typedef struct {
562   tBT_UUID uuid;
563   uint16_t handle;
564   tBTA_GATT_CHAR_PROP properties;
565   tBTA_GATTC_SERVICE* service; /* owning service*/
566   list_t* descriptors;         /* list of tBTA_GATTC_DESCRIPTOR */
567 } __attribute__((packed, aligned(alignof(tBT_UUID)))) tBTA_GATTC_CHARACTERISTIC;
568 
569 typedef struct {
570   tBT_UUID uuid;
571   uint16_t handle;
572   tBTA_GATTC_CHARACTERISTIC* characteristic; /* owning characteristic */
573 } __attribute__((packed)) tBTA_GATTC_DESCRIPTOR;
574 
575 typedef struct {
576   tBT_UUID uuid;
577   uint16_t handle;
578   tBTA_GATTC_SERVICE* owning_service; /* owning service*/
579   tBTA_GATTC_SERVICE* included_service;
580 } __attribute__((packed)) tBTA_GATTC_INCLUDED_SVC;
581 
582 /*****************************************************************************
583  *  External Function Declarations
584  ****************************************************************************/
585 
586 /**************************
587  *  Client Functions
588  **************************/
589 
590 /*******************************************************************************
591  *
592  * Function         BTA_GATTC_Disable
593  *
594  * Description      This function is called to disable the GATTC module
595  *
596  * Parameters       None.
597  *
598  * Returns          None
599  *
600  ******************************************************************************/
601 extern void BTA_GATTC_Disable(void);
602 
603 using BtaAppRegisterCallback =
604     base::Callback<void(uint8_t /* app_id */, uint8_t /* status */)>;
605 
606 /**
607  * This function is called to register application callbacks with BTA GATTC
608  *module.
609  * p_client_cb - pointer to the application callback function.
610  **/
611 extern void BTA_GATTC_AppRegister(tBTA_GATTC_CBACK* p_client_cb,
612                                   BtaAppRegisterCallback cb);
613 
614 /*******************************************************************************
615  *
616  * Function         BTA_GATTC_AppDeregister
617  *
618  * Description      This function is called to deregister an application
619  *                  from BTA GATTC module.
620  *
621  * Parameters       client_if - client interface identifier.
622  *
623  * Returns          None
624  *
625  ******************************************************************************/
626 extern void BTA_GATTC_AppDeregister(tBTA_GATTC_IF client_if);
627 
628 /*******************************************************************************
629  *
630  * Function         BTA_GATTC_Open
631  *
632  * Description      Open a direct connection or add a background auto connection
633  *                  bd address
634  *
635  * Parameters       client_if: server interface.
636  *                  remote_bda: remote device BD address.
637  *                  is_direct: direct connection or background auto connection
638  *                  initiating_phys: LE PHY to use, optional
639  *
640  ******************************************************************************/
641 extern void BTA_GATTC_Open(tBTA_GATTC_IF client_if, BD_ADDR remote_bda,
642                            bool is_direct, tBTA_GATT_TRANSPORT transport,
643                            bool opportunistic);
644 extern void BTA_GATTC_Open(tBTA_GATTC_IF client_if, BD_ADDR remote_bda,
645                            bool is_direct, tBTA_GATT_TRANSPORT transport,
646                            bool opportunistic, uint8_t initiating_phys);
647 
648 /*******************************************************************************
649  *
650  * Function         BTA_GATTC_CancelOpen
651  *
652  * Description      Open a direct connection or add a background auto connection
653  *                  bd address
654  *
655  * Parameters       client_if: server interface.
656  *                  remote_bda: remote device BD address.
657  *                  is_direct: direct connection or background auto connection
658  *
659  * Returns          void
660  *
661  ******************************************************************************/
662 extern void BTA_GATTC_CancelOpen(tBTA_GATTC_IF client_if, BD_ADDR remote_bda,
663                                  bool is_direct);
664 
665 /*******************************************************************************
666  *
667  * Function         BTA_GATTC_Close
668  *
669  * Description      Close a connection to a GATT server.
670  *
671  * Parameters       conn_id: connectino ID to be closed.
672  *
673  * Returns          void
674  *
675  ******************************************************************************/
676 extern void BTA_GATTC_Close(uint16_t conn_id);
677 
678 /*******************************************************************************
679  *
680  * Function         BTA_GATTC_ServiceSearchRequest
681  *
682  * Description      This function is called to request a GATT service discovery
683  *                  on a GATT server. This function report service search result
684  *                  by a callback event, and followed by a service search
685  *                  complete event.
686  *
687  * Parameters       conn_id: connection ID.
688  *                  p_srvc_uuid: a UUID of the service application is interested
689  *                               in. If Null, discover for all services.
690  *
691  * Returns          None
692  *
693  ******************************************************************************/
694 extern void BTA_GATTC_ServiceSearchRequest(uint16_t conn_id,
695                                            tBT_UUID* p_srvc_uuid);
696 
697 /**
698  * This function is called to send "Find service by UUID" request. Used only for
699  * PTS tests.
700  */
701 extern void BTA_GATTC_DiscoverServiceByUuid(uint16_t conn_id,
702                                             tBT_UUID* p_srvc_uuid);
703 
704 /*******************************************************************************
705  *
706  * Function         BTA_GATTC_GetServices
707  *
708  * Description      This function is called to find the services on the given
709  *                  server.
710  *
711  * Parameters       conn_id: connection ID which identify the server.
712  *
713  * Returns          returns list_t of tBTA_GATTC_SERVICE or NULL.
714  *
715  ******************************************************************************/
716 extern const list_t* BTA_GATTC_GetServices(uint16_t conn_id);
717 
718 /*******************************************************************************
719  *
720  * Function         BTA_GATTC_GetCharacteristic
721  *
722  * Description      This function is called to find the characteristic on the
723  *                  given server.
724  *
725  * Parameters       conn_id: connection ID which identify the server.
726  *                  handle: characteristic handle
727  *
728  * Returns          returns pointer to tBTA_GATTC_CHARACTERISTIC or NULL.
729  *
730  ******************************************************************************/
731 extern const tBTA_GATTC_CHARACTERISTIC* BTA_GATTC_GetCharacteristic(
732     uint16_t conn_id, uint16_t handle);
733 
734 /*******************************************************************************
735  *
736  * Function         BTA_GATTC_GetDescriptor
737  *
738  * Description      This function is called to find the characteristic on the
739  *                  given server.
740  *
741  * Parameters       conn_id: connection ID which identify the server.
742  *                  handle: descriptor handle
743  *
744  * Returns          returns pointer to tBTA_GATTC_DESCRIPTOR or NULL.
745  *
746  ******************************************************************************/
747 extern const tBTA_GATTC_DESCRIPTOR* BTA_GATTC_GetDescriptor(uint16_t conn_id,
748                                                             uint16_t handle);
749 
750 /*******************************************************************************
751  *
752  * Function         BTA_GATTC_GetGattDb
753  *
754  * Description      This function is called to get gatt db.
755  *
756  * Parameters       conn_id: connection ID which identify the server.
757  *                  db: output parameter which will contain gatt db copy.
758  *                      Caller is responsible for freeing it.
759  *                  count: number of elements in db.
760  *
761  ******************************************************************************/
762 extern void BTA_GATTC_GetGattDb(uint16_t conn_id, uint16_t start_handle,
763                                 uint16_t end_handle, btgatt_db_element_t** db,
764                                 int* count);
765 
766 typedef void (*GATT_READ_OP_CB)(uint16_t conn_id, tGATT_STATUS status,
767                                 uint16_t handle, uint16_t len, uint8_t* value,
768                                 void* data);
769 typedef void (*GATT_WRITE_OP_CB)(uint16_t conn_id, tGATT_STATUS status,
770                                  uint16_t handle, void* data);
771 
772 /*******************************************************************************
773  *
774  * Function         BTA_GATTC_ReadCharacteristic
775  *
776  * Description      This function is called to read a characteristics value
777  *
778  * Parameters       conn_id - connectino ID.
779  *                  handle - characteritic handle to read.
780  *
781  * Returns          None
782  *
783  ******************************************************************************/
784 void BTA_GATTC_ReadCharacteristic(uint16_t conn_id, uint16_t handle,
785                                   tBTA_GATT_AUTH_REQ auth_req,
786                                   GATT_READ_OP_CB callback, void* cb_data);
787 
788 /**
789  * This function is called to read a value of characteristic with uuid equal to
790  * |uuid|
791  */
792 void BTA_GATTC_ReadUsingCharUuid(uint16_t conn_id, tBT_UUID uuid,
793                                  uint16_t s_handle, uint16_t e_handle,
794                                  tBTA_GATT_AUTH_REQ auth_req,
795                                  GATT_READ_OP_CB callback, void* cb_data);
796 
797 /*******************************************************************************
798  *
799  * Function         BTA_GATTC_ReadCharDescr
800  *
801  * Description      This function is called to read a descriptor value.
802  *
803  * Parameters       conn_id - connection ID.
804  *                  handle - descriptor handle to read.
805  *
806  * Returns          None
807  *
808  ******************************************************************************/
809 void BTA_GATTC_ReadCharDescr(uint16_t conn_id, uint16_t handle,
810                              tBTA_GATT_AUTH_REQ auth_req,
811                              GATT_READ_OP_CB callback, void* cb_data);
812 
813 /*******************************************************************************
814  *
815  * Function         BTA_GATTC_WriteCharValue
816  *
817  * Description      This function is called to write characteristic value.
818  *
819  * Parameters       conn_id - connection ID.
820  *                  handle - characteristic handle to write.
821  *                  write_type - type of write.
822  *                  value - the value to be written.
823  *
824  * Returns          None
825  *
826  ******************************************************************************/
827 void BTA_GATTC_WriteCharValue(uint16_t conn_id, uint16_t handle,
828                               tBTA_GATTC_WRITE_TYPE write_type,
829                               vector<uint8_t> value,
830                               tBTA_GATT_AUTH_REQ auth_req,
831                               GATT_WRITE_OP_CB callback, void* cb_data);
832 
833 /*******************************************************************************
834  *
835  * Function         BTA_GATTC_WriteCharDescr
836  *
837  * Description      This function is called to write descriptor value.
838  *
839  * Parameters       conn_id - connection ID
840  *                  handle - descriptor handle to write.
841  *                  value - the value to be written.
842  *
843  * Returns          None
844  *
845  ******************************************************************************/
846 void BTA_GATTC_WriteCharDescr(uint16_t conn_id, uint16_t handle,
847                               vector<uint8_t> value,
848                               tBTA_GATT_AUTH_REQ auth_req,
849                               GATT_WRITE_OP_CB callback, void* cb_data);
850 
851 /*******************************************************************************
852  *
853  * Function         BTA_GATTC_SendIndConfirm
854  *
855  * Description      This function is called to send handle value confirmation.
856  *
857  * Parameters       conn_id - connection ID.
858  *                  handle - characteristic handle to confirm.
859  *
860  * Returns          None
861  *
862  ******************************************************************************/
863 extern void BTA_GATTC_SendIndConfirm(uint16_t conn_id, uint16_t handle);
864 
865 /*******************************************************************************
866  *
867  * Function         BTA_GATTC_RegisterForNotifications
868  *
869  * Description      This function is called to register for notification of a
870  *                  service.
871  *
872  * Parameters       client_if - client interface.
873  *                  remote_bda - target GATT server.
874  *                  handle - GATT characteristic handle.
875  *
876  * Returns          OK if registration succeed, otherwise failed.
877  *
878  ******************************************************************************/
879 extern tBTA_GATT_STATUS BTA_GATTC_RegisterForNotifications(
880     tBTA_GATTC_IF client_if, const BD_ADDR remote_bda, uint16_t handle);
881 
882 /*******************************************************************************
883  *
884  * Function         BTA_GATTC_DeregisterForNotifications
885  *
886  * Description      This function is called to de-register for notification of a
887  *                  service.
888  *
889  * Parameters       client_if - client interface.
890  *                  remote_bda - target GATT server.
891  *                  handle - GATT characteristic handle.
892  *
893  * Returns          OK if deregistration succeed, otherwise failed.
894  *
895  ******************************************************************************/
896 extern tBTA_GATT_STATUS BTA_GATTC_DeregisterForNotifications(
897     tBTA_GATTC_IF client_if, const BD_ADDR remote_bda, uint16_t handle);
898 
899 /*******************************************************************************
900  *
901  * Function         BTA_GATTC_PrepareWrite
902  *
903  * Description      This function is called to prepare write a characteristic
904  *                  value.
905  *
906  * Parameters       conn_id - connection ID.
907  *                  handle - GATT characteritic handle.
908  *                  offset - offset of the write value.
909  *                  value - the value to be written.
910  *
911  * Returns          None
912  *
913  ******************************************************************************/
914 extern void BTA_GATTC_PrepareWrite(uint16_t conn_id, uint16_t handle,
915                                    uint16_t offset, vector<uint8_t> value,
916                                    tBTA_GATT_AUTH_REQ auth_req,
917                                    GATT_WRITE_OP_CB callback, void* cb_data);
918 
919 /*******************************************************************************
920  *
921  * Function         BTA_GATTC_ExecuteWrite
922  *
923  * Description      This function is called to execute write a prepare write
924  *                  sequence.
925  *
926  * Parameters       conn_id - connection ID.
927  *                    is_execute - execute or cancel.
928  *
929  * Returns          None
930  *
931  ******************************************************************************/
932 extern void BTA_GATTC_ExecuteWrite(uint16_t conn_id, bool is_execute);
933 
934 /*******************************************************************************
935  *
936  * Function         BTA_GATTC_ReadMultiple
937  *
938  * Description      This function is called to read multiple characteristic or
939  *                  characteristic descriptors.
940  *
941  * Parameters       conn_id - connectino ID.
942  *                    p_read_multi - read multiple parameters.
943  *
944  * Returns          None
945  *
946  ******************************************************************************/
947 extern void BTA_GATTC_ReadMultiple(uint16_t conn_id,
948                                    tBTA_GATTC_MULTI* p_read_multi,
949                                    tBTA_GATT_AUTH_REQ auth_req);
950 
951 /*******************************************************************************
952  *
953  * Function         BTA_GATTC_Refresh
954  *
955  * Description      Refresh the server cache of the remote device
956  *
957  * Parameters       remote_bda: remote device BD address.
958  *
959  * Returns          void
960  *
961  ******************************************************************************/
962 extern void BTA_GATTC_Refresh(const BD_ADDR remote_bda);
963 
964 /*******************************************************************************
965  *
966  * Function         BTA_GATTC_ConfigureMTU
967  *
968  * Description      Configure the MTU size in the GATT channel. This can be done
969  *                  only once per connection.
970  *
971  * Parameters       conn_id: connection ID.
972  *                  mtu: desired MTU size to use.
973  *
974  * Returns          void
975  *
976  ******************************************************************************/
977 extern void BTA_GATTC_ConfigureMTU(uint16_t conn_id, uint16_t mtu);
978 
979 /*******************************************************************************
980  *  BTA GATT Server API
981  ******************************************************************************/
982 
983 /*******************************************************************************
984  *
985  * Function         BTA_GATTS_Init
986  *
987  * Description      This function is called to initalize GATTS module
988  *
989  * Parameters       None
990  *
991  * Returns          None
992  *
993  ******************************************************************************/
994 extern void BTA_GATTS_Init();
995 
996 /*******************************************************************************
997  *
998  * Function         BTA_GATTS_Disable
999  *
1000  * Description      This function is called to disable GATTS module
1001  *
1002  * Parameters       None.
1003  *
1004  * Returns          None
1005  *
1006  ******************************************************************************/
1007 extern void BTA_GATTS_Disable(void);
1008 
1009 /*******************************************************************************
1010  *
1011  * Function         BTA_GATTS_AppRegister
1012  *
1013  * Description      This function is called to register application callbacks
1014  *                    with BTA GATTS module.
1015  *
1016  * Parameters       p_app_uuid - applicaiton UUID
1017  *                  p_cback - pointer to the application callback function.
1018  *
1019  * Returns          None
1020  *
1021  ******************************************************************************/
1022 extern void BTA_GATTS_AppRegister(tBT_UUID* p_app_uuid,
1023                                   tBTA_GATTS_CBACK* p_cback);
1024 
1025 /*******************************************************************************
1026  *
1027  * Function         BTA_GATTS_AppDeregister
1028  *
1029  * Description      De-register with BTA GATT Server.
1030  *
1031  * Parameters       server_if: server interface
1032  *
1033  * Returns          void
1034  *
1035  ******************************************************************************/
1036 extern void BTA_GATTS_AppDeregister(tBTA_GATTS_IF server_if);
1037 
1038 /*******************************************************************************
1039  *
1040  * Function         BTA_GATTS_AddService
1041  *
1042  * Description      Add the given |service| and all included elements to the
1043  *                  GATT database. a |BTA_GATTS_ADD_SRVC_EVT| is triggered to
1044  *                  report the status and attribute handles.
1045  *
1046  * Parameters       server_if: server interface.
1047  *                  service: pointer to vector describing service.
1048  *
1049  * Returns          Returns |BTA_GATT_OK| on success or |BTA_GATT_ERROR| if the
1050  *                  service cannot be added.
1051  *
1052  ******************************************************************************/
1053 extern uint16_t BTA_GATTS_AddService(tBTA_GATTS_IF server_if,
1054                                      vector<btgatt_db_element_t>& service);
1055 
1056 /*******************************************************************************
1057  *
1058  * Function         BTA_GATTS_DeleteService
1059  *
1060  * Description      This function is called to delete a service. When this is
1061  *                  done, a callback event BTA_GATTS_DELETE_EVT is report with
1062  *                  the status.
1063  *
1064  * Parameters       service_id: service_id to be deleted.
1065  *
1066  * Returns          returns none.
1067  *
1068  ******************************************************************************/
1069 extern void BTA_GATTS_DeleteService(uint16_t service_id);
1070 
1071 /*******************************************************************************
1072  *
1073  * Function         BTA_GATTS_StopService
1074  *
1075  * Description      This function is called to stop a service.
1076  *
1077  * Parameters       service_id - service to be topped.
1078  *
1079  * Returns          None
1080  *
1081  ******************************************************************************/
1082 extern void BTA_GATTS_StopService(uint16_t service_id);
1083 
1084 /*******************************************************************************
1085  *
1086  * Function         BTA_GATTS_HandleValueIndication
1087  *
1088  * Description      This function is called to read a characteristics
1089  *                  descriptor.
1090  *
1091  * Parameters       conn_id - connection identifier.
1092  *                  attr_id - attribute ID to indicate.
1093  *                  value - data to indicate.
1094  *                  need_confirm - if this indication expects a confirmation or
1095  *                                 not.
1096  *
1097  * Returns          None
1098  *
1099  ******************************************************************************/
1100 extern void BTA_GATTS_HandleValueIndication(uint16_t conn_id, uint16_t attr_id,
1101                                             vector<uint8_t> value,
1102                                             bool need_confirm);
1103 
1104 /*******************************************************************************
1105  *
1106  * Function         BTA_GATTS_SendRsp
1107  *
1108  * Description      This function is called to send a response to a request.
1109  *
1110  * Parameters       conn_id - connection identifier.
1111  *                  trans_id - transaction ID.
1112  *                  status - response status
1113  *                  p_msg - response data.
1114  *
1115  * Returns          None
1116  *
1117  ******************************************************************************/
1118 extern void BTA_GATTS_SendRsp(uint16_t conn_id, uint32_t trans_id,
1119                               tBTA_GATT_STATUS status, tBTA_GATTS_RSP* p_msg);
1120 
1121 /*******************************************************************************
1122  *
1123  * Function         BTA_GATTS_Open
1124  *
1125  * Description      Open a direct open connection or add a background auto
1126  *                  connection bd address
1127  *
1128  * Parameters       server_if: server interface.
1129  *                  remote_bda: remote device BD address.
1130  *                  is_direct: direct connection or background auto connection
1131  *
1132  * Returns          void
1133  *
1134  ******************************************************************************/
1135 extern void BTA_GATTS_Open(tBTA_GATTS_IF server_if, BD_ADDR remote_bda,
1136                            bool is_direct, tBTA_GATT_TRANSPORT transport);
1137 
1138 /*******************************************************************************
1139  *
1140  * Function         BTA_GATTS_CancelOpen
1141  *
1142  * Description      Cancel a direct open connection or remove a background auto
1143  *                  connection bd address
1144  *
1145  * Parameters       server_if: server interface.
1146  *                  remote_bda: remote device BD address.
1147  *                  is_direct: direct connection or background auto connection
1148  *
1149  * Returns          void
1150  *
1151  ******************************************************************************/
1152 extern void BTA_GATTS_CancelOpen(tBTA_GATTS_IF server_if, BD_ADDR remote_bda,
1153                                  bool is_direct);
1154 
1155 /*******************************************************************************
1156  *
1157  * Function         BTA_GATTS_Close
1158  *
1159  * Description      Close a connection  a remote device.
1160  *
1161  * Parameters       conn_id: connectino ID to be closed.
1162  *
1163  * Returns          void
1164  *
1165  ******************************************************************************/
1166 extern void BTA_GATTS_Close(uint16_t conn_id);
1167 
1168 #endif /* BTA_GATT_API_H */
1169