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/bta_api.h"
29 #include "stack/gatt_api.h"
30 #include "osi/list.h"
31 
32 #ifndef     BTA_GATT_INCLUDED
33 #define     BTA_GATT_INCLUDED     FALSE
34 #endif
35 
36 #if ((BLE_INCLUDED == FALSE) && (BTA_GATT_INCLUDED == TRUE))
37 #undef BTA_GATT_INCLUDED
38 #define BTA_GATT_INCLUDED        FALSE
39 #endif
40 
41 
42 #ifndef     BTA_GATT_DEBUG
43 #define     BTA_GATT_DEBUG       FALSE
44 #endif
45 
46 typedef enum {
47     BTGATT_DB_PRIMARY_SERVICE,
48     BTGATT_DB_SECONDARY_SERVICE,
49     BTGATT_DB_CHARACTERISTIC,
50     BTGATT_DB_DESCRIPTOR,
51     BTGATT_DB_INCLUDED_SERVICE,
52 }bt_gatt_db_attribute_type_t;
53 
54 typedef enum {
55     GATT_OP_GET_SVC_BY_UUID,
56     GATT_OP_GET_ALL_CHAR,
57     GATT_OP_GET_ALL_DESCRI,
58     GATT_OP_GET_CHAR_BY_UUID,
59     GATT_OP_GET_DESCRI_BY_UUID,
60     GATT_OP_GET_DESCRI_BY_HANDLE,
61     GATT_OP_GET_INCLUDE_SVC,
62 }bt_gatt_get_db_op_t;
63 
64 typedef struct {
65     bt_gatt_db_attribute_type_t type;
66     UINT16                      attribute_handle;
67     UINT16                      start_handle;
68     UINT16                      end_handle;
69     UINT16                      id;
70     UINT8                       properties;
71     bt_uuid_t                   uuid;
72 }btgatt_db_element_t;
73 
74 /*****************************************************************************
75 **  Constants and data types
76 *****************************************************************************/
77 /**************************
78 **  Common Definitions
79 ***************************/
80 /* GATT ID */
81 typedef struct {
82     tBT_UUID    uuid;           /* uuid of the attribute */
83     UINT8       inst_id;        /* instance ID */
84 } __attribute__((packed)) tBTA_GATT_ID;
85 
86 /* relate to ESP_GATT_xxx in esp_gatt_def.h */
87 /* Success code and error codes */
88 #define  BTA_GATT_OK                        GATT_SUCCESS
89 #define  BTA_GATT_INVALID_HANDLE            GATT_INVALID_HANDLE                /* 0x0001 */
90 #define  BTA_GATT_READ_NOT_PERMIT           GATT_READ_NOT_PERMIT               /* 0x0002 */
91 #define  BTA_GATT_WRITE_NOT_PERMIT          GATT_WRITE_NOT_PERMIT              /* 0x0003 */
92 #define  BTA_GATT_INVALID_PDU               GATT_INVALID_PDU                   /* 0x0004 */
93 #define  BTA_GATT_INSUF_AUTHENTICATION      GATT_INSUF_AUTHENTICATION          /* 0x0005 */
94 #define  BTA_GATT_REQ_NOT_SUPPORTED         GATT_REQ_NOT_SUPPORTED             /* 0x0006 */
95 #define  BTA_GATT_INVALID_OFFSET            GATT_INVALID_OFFSET                /* 0x0007 */
96 #define  BTA_GATT_INSUF_AUTHORIZATION       GATT_INSUF_AUTHORIZATION           /* 0x0008 */
97 #define  BTA_GATT_PREPARE_Q_FULL            GATT_PREPARE_Q_FULL                /* 0x0009 */
98 #define  BTA_GATT_NOT_FOUND                 GATT_NOT_FOUND                     /* 0x000a */
99 #define  BTA_GATT_NOT_LONG                  GATT_NOT_LONG                      /* 0x000b */
100 #define  BTA_GATT_INSUF_KEY_SIZE            GATT_INSUF_KEY_SIZE                /* 0x000c */
101 #define  BTA_GATT_INVALID_ATTR_LEN          GATT_INVALID_ATTR_LEN              /* 0x000d */
102 #define  BTA_GATT_ERR_UNLIKELY              GATT_ERR_UNLIKELY                  /* 0x000e */
103 #define  BTA_GATT_INSUF_ENCRYPTION          GATT_INSUF_ENCRYPTION              /* 0x000f */
104 #define  BTA_GATT_UNSUPPORT_GRP_TYPE        GATT_UNSUPPORT_GRP_TYPE            /* 0x0010 */
105 #define  BTA_GATT_INSUF_RESOURCE            GATT_INSUF_RESOURCE                /* 0x0011 */
106 
107 
108 #define  BTA_GATT_NO_RESOURCES              GATT_NO_RESOURCES                  /* 0x80 */
109 #define  BTA_GATT_INTERNAL_ERROR            GATT_INTERNAL_ERROR                /* 0x81 */
110 #define  BTA_GATT_WRONG_STATE               GATT_WRONG_STATE                   /* 0x82 */
111 #define  BTA_GATT_DB_FULL                   GATT_DB_FULL                       /* 0x83 */
112 #define  BTA_GATT_BUSY                      GATT_BUSY                          /* 0x84 */
113 #define  BTA_GATT_ERROR                     GATT_ERROR                         /* 0x85 */
114 #define  BTA_GATT_CMD_STARTED               GATT_CMD_STARTED                   /* 0x86 */
115 #define  BTA_GATT_ILLEGAL_PARAMETER         GATT_ILLEGAL_PARAMETER             /* 0x87 */
116 #define  BTA_GATT_PENDING                   GATT_PENDING                       /* 0x88 */
117 #define  BTA_GATT_AUTH_FAIL                 GATT_AUTH_FAIL                     /* 0x89 */
118 #define  BTA_GATT_MORE                      GATT_MORE                          /* 0x8a */
119 #define  BTA_GATT_INVALID_CFG               GATT_INVALID_CFG                   /* 0x8b */
120 #define  BTA_GATT_SERVICE_STARTED           GATT_SERVICE_STARTED               /* 0x8c */
121 #define  BTA_GATT_ENCRYPED_MITM             GATT_ENCRYPED_MITM                 /* GATT_SUCCESS */
122 #define  BTA_GATT_ENCRYPED_NO_MITM          GATT_ENCRYPED_NO_MITM              /* 0x8d */
123 #define  BTA_GATT_NOT_ENCRYPTED             GATT_NOT_ENCRYPTED                 /* 0x8e */
124 #define  BTA_GATT_CONGESTED                 GATT_CONGESTED                     /* 0x8f */
125 
126 #define  BTA_GATT_DUP_REG                   GATT_DUP_REG                       /* 0x90 */
127 #define  BTA_GATT_ALREADY_OPEN              GATT_ALREADY_OPEN                  /* 0x91 */
128 #define  BTA_GATT_CANCEL                    GATT_CANCEL                        /* 0x92 */
129 
130 /* 0xE0 ~ 0xFC reserved for future use */
131 #define  BTA_GATT_STACK_RSP                 GATT_STACK_RSP                    /* 0xE0 */
132 #define  BTA_GATT_APP_RSP                   GATT_APP_RSP                      /* 0xE1 */
133 //Error caused by customer application or stack bug
134 #define  BTA_GATT_UNKNOWN_ERROR             GATT_UNKNOWN_ERROR                /* 0XEF */
135                                              /* 0xE0 ~ 0xFC reserved for future use */
136 #define  BTA_GATT_CCC_CFG_ERR               GATT_CCC_CFG_ERR     /* 0xFD Client Characteristic Configuration Descriptor Improperly Configured */
137 #define  BTA_GATT_PRC_IN_PROGRESS           GATT_PRC_IN_PROGRESS /* 0xFE Procedure Already in progress */
138 #define  BTA_GATT_OUT_OF_RANGE              GATT_OUT_OF_RANGE    /* 0xFFAttribute value out of range */
139 
140 typedef UINT8 tBTA_GATT_STATUS;
141 
142 #define BTA_GATT_INVALID_CONN_ID   GATT_INVALID_CONN_ID
143 
144 
145 /* Client callback function events */
146 #define BTA_GATTC_REG_EVT               0   /* GATT client is registered. */
147 #define BTA_GATTC_DEREG_EVT             1   /* GATT client deregistered event */
148 #define BTA_GATTC_OPEN_EVT              2   /* GATTC open request status  event */
149 #define BTA_GATTC_READ_CHAR_EVT         3   /* GATT read characteristic event */
150 #define BTA_GATTC_WRITE_CHAR_EVT        4   /* GATT write characteristic or char descriptor event */
151 #define BTA_GATTC_CLOSE_EVT             5   /* GATTC  close request status event */
152 #define BTA_GATTC_SEARCH_CMPL_EVT       6   /* GATT discovery complete event */
153 #define BTA_GATTC_SEARCH_RES_EVT        7   /* GATT discovery result event */
154 #define BTA_GATTC_READ_DESCR_EVT        8   /* GATT read characteristic descriptor event */
155 #define BTA_GATTC_WRITE_DESCR_EVT       9   /* GATT write characteristic descriptor event */
156 #define BTA_GATTC_NOTIF_EVT             10  /* GATT attribute notification event */
157 #define BTA_GATTC_PREP_WRITE_EVT        11  /* GATT prepare write  event */
158 #define BTA_GATTC_EXEC_EVT              12  /* execute write complete event */
159 #define BTA_GATTC_ACL_EVT               13  /* ACL up event */
160 #define BTA_GATTC_CANCEL_OPEN_EVT       14  /* cancel open event */
161 #define BTA_GATTC_SRVC_CHG_EVT          15  /* service change event */
162 #define BTA_GATTC_LISTEN_EVT            16  /* listen event */
163 #define BTA_GATTC_ENC_CMPL_CB_EVT       17  /* encryption complete callback event */
164 #define BTA_GATTC_CFG_MTU_EVT           18  /* configure MTU complete event */
165 #define BTA_GATTC_ADV_DATA_EVT          19  /* ADV data event */
166 #define BTA_GATTC_MULT_ADV_ENB_EVT      20  /* Enable Multi ADV event */
167 #define BTA_GATTC_MULT_ADV_UPD_EVT      21  /* Update parameter event */
168 #define BTA_GATTC_MULT_ADV_DATA_EVT     22  /* Multi ADV data event */
169 #define BTA_GATTC_MULT_ADV_DIS_EVT      23  /* Disable Multi ADV event */
170 #define BTA_GATTC_CONGEST_EVT           24  /* Congestion event */
171 #define BTA_GATTC_BTH_SCAN_ENB_EVT      25 /* Enable batch scan event */
172 #define BTA_GATTC_BTH_SCAN_CFG_EVT      26 /* Config storage event */
173 #define BTA_GATTC_BTH_SCAN_RD_EVT       27 /* Batch scan reports read event */
174 #define BTA_GATTC_BTH_SCAN_THR_EVT      28 /* Batch scan threshold event */
175 #define BTA_GATTC_BTH_SCAN_PARAM_EVT    29 /* Batch scan param event */
176 #define BTA_GATTC_BTH_SCAN_DIS_EVT      30 /* Disable batch scan event */
177 #define BTA_GATTC_SCAN_FLT_CFG_EVT      31 /* Scan filter config event */
178 #define BTA_GATTC_SCAN_FLT_PARAM_EVT    32 /* Param filter event */
179 #define BTA_GATTC_SCAN_FLT_STATUS_EVT   33 /* Filter status event */
180 #define BTA_GATTC_ADV_VSC_EVT           34 /* ADV VSC event */
181 #define BTA_GATTC_CONNECT_EVT           35 /* GATTC CONNECT  event */
182 #define BTA_GATTC_DISCONNECT_EVT        36 /* GATTC DISCONNECT  event */
183 #define BTA_GATTC_READ_MULTIPLE_EVT     37 /* GATTC Read mutiple event */
184 #define BTA_GATTC_QUEUE_FULL_EVT        38 /* GATTC queue full event */
185 #define BTA_GATTC_ASSOC_EVT             39 /* GATTC association address event */
186 #define BTA_GATTC_GET_ADDR_LIST_EVT     40 /* GATTC get address list in the cache event */
187 #define BTA_GATTC_DIS_SRVC_CMPL_EVT     41 /* GATTC discover service complete */
188 
189 typedef UINT8 tBTA_GATTC_EVT;
190 
191 typedef tGATT_IF tBTA_GATTC_IF;
192 
193 typedef UINT8 tBTA_ADDR_TYPE;
194 
195 typedef struct {
196     UINT16              unit;       /* as UUIUD defined by SIG */
197     UINT16              descr;      /* as UUID as defined by SIG */
198     tGATT_FORMAT        format;
199     INT8                exp;
200     UINT8               name_spc;   /* The name space of the description */
201 } tBTA_GATT_CHAR_PRES;
202 
203 typedef struct {
204     UINT16             interval;
205     UINT16             latency;
206     UINT16             timeout;
207 } tBTA_GATT_CONN_PARAMS;
208 
209 #define BTA_GATT_CLT_CONFIG_NONE               GATT_CLT_CONFIG_NONE         /* 0x0000    */
210 #define BTA_GATT_CLT_CONFIG_NOTIFICATION       GATT_CLT_CONFIG_NOTIFICATION /* 0x0001 */
211 #define BTA_GATT_CLT_CONFIG_INDICATION         GATT_CLT_CONFIG_INDICATION   /* 0x0002 */
212 typedef UINT16  tBTA_GATT_CLT_CHAR_CONFIG;
213 
214 /* characteristic descriptor: server configuration value
215 */
216 #define BTA_GATT_SVR_CONFIG_NONE            GATT_SVR_CONFIG_NONE            /* 0x0000 */
217 #define BTA_GATT_SVR_CONFIG_BROADCAST       GATT_SVR_CONFIG_BROADCAST       /* 0x0001 */
218 typedef UINT16  tBTA_GATT_SVR_CHAR_CONFIG;
219 
220 /* Characteristic Aggregate Format attribute value
221 */
222 #define BTA_GATT_AGGR_HANDLE_NUM_MAX        10
223 typedef struct {
224     UINT8                   num_handle;
225     UINT16                  handle_list[BTA_GATT_AGGR_HANDLE_NUM_MAX];
226 } tBTA_GATT_CHAR_AGGRE;
227 typedef tGATT_VALID_RANGE           tBTA_GATT_VALID_RANGE;
228 
229 typedef struct {
230     UINT16  len;
231     UINT8   *p_value;
232 } tBTA_GATT_UNFMT;
233 
234 #define BTA_GATT_MAX_ATTR_LEN       GATT_MAX_ATTR_LEN
235 
236 #define BTA_GATTC_TYPE_WRITE             GATT_WRITE
237 #define BTA_GATTC_TYPE_WRITE_NO_RSP      GATT_WRITE_NO_RSP
238 typedef UINT8 tBTA_GATTC_WRITE_TYPE;
239 
240 /* relate to ESP_GATT_CONN_xxx in esp_gatt_defs.h */
241 #define BTA_GATT_CONN_UNKNOWN                   0
242 #define BTA_GATT_CONN_L2C_FAILURE               GATT_CONN_L2C_FAILURE         /* general l2cap resource failure */
243 #define BTA_GATT_CONN_TIMEOUT                   GATT_CONN_TIMEOUT             /* 0x08 connection timeout  */
244 #define BTA_GATT_CONN_TERMINATE_PEER_USER       GATT_CONN_TERMINATE_PEER_USER /* 0x13 connection terminate by peer user  */
245 #define BTA_GATT_CONN_TERMINATE_LOCAL_HOST      GATT_CONN_TERMINATE_LOCAL_HOST/* 0x16 connectionterminated by local host  */
246 #define BTA_GATT_CONN_FAIL_ESTABLISH            GATT_CONN_FAIL_ESTABLISH      /* 0x03E connection fail to establish  */
247 #define BTA_GATT_CONN_LMP_TIMEOUT               GATT_CONN_LMP_TIMEOUT          /* 0x22 connection fail for LMP response tout */
248 #define BTA_GATT_CONN_CANCEL                    GATT_CONN_CANCEL               /* 0x0100 L2CAP connection cancelled  */
249 #define BTA_GATT_CONN_NONE                      0x0101                          /* 0x0101 no connection to cancel  */
250 typedef UINT16 tBTA_GATT_REASON;
251 
252 typedef struct {
253     tBTA_GATT_ID        id;
254     BOOLEAN             is_primary;
255 } tBTA_GATT_SRVC_ID;
256 
257 
258 #define BTA_GATTC_MULTI_MAX    GATT_MAX_READ_MULTI_HANDLES
259 
260 typedef struct {
261     UINT8                       num_attr;
262     UINT16                      handles[BTA_GATTC_MULTI_MAX];
263 }tBTA_GATTC_MULTI;
264 
265 /* relate to ESP_GATT_xxx in esp_gatt_def.h */
266 #define BTA_GATT_AUTH_REQ_NONE           GATT_AUTH_REQ_NONE
267 #define BTA_GATT_AUTH_REQ_NO_MITM        GATT_AUTH_REQ_NO_MITM            /* unauthenticated encryption */
268 #define BTA_GATT_AUTH_REQ_MITM           GATT_AUTH_REQ_MITM               /* authenticated encryption */
269 #define BTA_GATT_AUTH_REQ_SIGNED_NO_MITM GATT_AUTH_REQ_SIGNED_NO_MITM
270 #define BTA_GATT_AUTH_REQ_SIGNED_MITM    GATT_AUTH_REQ_SIGNED_MITM
271 
272 typedef tGATT_AUTH_REQ tBTA_GATT_AUTH_REQ;
273 
274 enum {
275     BTA_GATTC_ATTR_TYPE_INCL_SRVC,
276     BTA_GATTC_ATTR_TYPE_CHAR,
277     BTA_GATTC_ATTR_TYPE_CHAR_DESCR,
278     BTA_GATTC_ATTR_TYPE_SRVC
279 };
280 typedef UINT8 tBTA_GATTC_ATTR_TYPE;
281 
282 
283 typedef struct {
284     tBT_UUID    uuid;
285     UINT16      s_handle;
286     UINT16      e_handle;   /* used for service only */
287     UINT8       attr_type;
288     UINT8       id;
289     UINT8       prop;       /* used when attribute type is characteristic */
290     BOOLEAN     is_primary; /* used when attribute type is service */
291     UINT16      incl_srvc_s_handle; /* used when attribute type is included service */
292     UINT16      incl_srvc_e_handle; /* used when attribute type is included service */
293 }tBTA_GATTC_NV_ATTR;
294 
295 /* callback data structure */
296 typedef struct {
297     tBTA_GATT_STATUS    status;
298     tBTA_GATTC_IF       client_if;
299     tBT_UUID            app_uuid;
300 }tBTA_GATTC_REG;
301 
302 typedef struct {
303     UINT16              conn_id;
304     tBTA_GATT_STATUS    status;
305     UINT16              handle;
306     tBTA_GATT_UNFMT  *p_value;
307 }tBTA_GATTC_READ;
308 
309 typedef struct {
310     UINT16              conn_id;
311     tBTA_GATT_STATUS    status;
312     UINT16              handle;
313     UINT16              offset;
314 }tBTA_GATTC_WRITE;
315 
316 typedef struct {
317     UINT16              conn_id;
318     tBTA_GATT_STATUS    status;
319 } tBTA_GATTC_EXEC_CMPL;
320 
321 typedef struct {
322     UINT16              conn_id;
323     tBTA_GATT_STATUS    status;
324     UINT8               searched_service_source;
325 } tBTA_GATTC_SEARCH_CMPL;
326 
327 typedef struct {
328     UINT16              conn_id;
329     tBTA_GATT_STATUS    status;
330 }tBTA_GATTC_DIS_CMPL;
331 
332 typedef struct {
333     UINT16              conn_id;
334     UINT16              start_handle;
335     UINT16              end_handle;
336     tBTA_GATT_ID        service_uuid;
337     bool                is_primary;
338 }tBTA_GATTC_SRVC_RES;
339 
340 typedef struct {
341     UINT16              conn_id;
342     tBTA_GATT_STATUS    status;
343     UINT16              mtu;
344 } tBTA_GATTC_CFG_MTU;
345 
346 typedef struct {
347     tBTA_GATT_STATUS    status;
348     UINT16              conn_id;
349     tBTA_GATTC_IF       client_if;
350     BD_ADDR             remote_bda;
351     tBTA_TRANSPORT      transport;
352     UINT16              mtu;
353 } tBTA_GATTC_OPEN;
354 
355 typedef struct {
356     tBTA_GATT_STATUS    status;
357     UINT16              conn_id;
358     tBTA_GATTC_IF       client_if;
359     BD_ADDR             remote_bda;
360     tBTA_GATT_REASON    reason;         /* disconnect reason code, not useful when connect event is reported */
361 } tBTA_GATTC_CLOSE;
362 
363 typedef struct {
364     UINT16              conn_id;
365     BD_ADDR             bda;
366     UINT16              handle;
367     UINT16              len;
368     UINT8               value[BTA_GATT_MAX_ATTR_LEN];
369     BOOLEAN             is_notify;
370 } tBTA_GATTC_NOTIFY;
371 
372 typedef struct {
373     UINT16 conn_id;
374     BOOLEAN congested; /* congestion indicator */
375 } tBTA_GATTC_CONGEST;
376 
377 typedef struct {
378     tBTA_GATT_STATUS status;
379     UINT16 conn_id;
380     BOOLEAN is_full;
381 } tBTA_GATTC_QUEUE_FULL;
382 
383 typedef struct {
384     tBTA_GATT_STATUS   status;
385     tBTA_GATTC_IF      client_if;
386 } tBTA_GATTC_SET_ASSOC;
387 
388 typedef struct {
389     tBTA_GATT_STATUS    status;
390     tBTA_GATTC_IF       client_if;
391     UINT8               num_addr;
392     BD_ADDR             *bda_list;
393 } tBTA_GATTC_GET_ADDR_LIST;
394 
395 typedef struct {
396     tBTA_GATT_STATUS        status;
397     tBTA_GATTC_IF           client_if;
398     UINT16                  conn_id;
399     BD_ADDR                 remote_bda;
400 } tBTA_GATTC_OPEN_CLOSE;
401 
402 typedef struct {
403     tBTA_GATTC_IF           client_if;
404     BD_ADDR                 remote_bda;
405 } tBTA_GATTC_ENC_CMPL_CB;
406 
407 typedef struct {
408     UINT16              conn_id;
409     UINT8               link_role;
410     tBTA_GATTC_IF       client_if;
411     BD_ADDR             remote_bda;
412     tBTA_GATT_CONN_PARAMS conn_params;
413 } tBTA_GATTC_CONNECT;
414 
415 typedef struct {
416     tGATT_DISCONN_REASON reason;
417     UINT16              conn_id;
418     tBTA_GATTC_IF       client_if;
419     BD_ADDR             remote_bda;
420 } tBTA_GATTC_DISCONNECT;
421 
422 typedef struct {
423     UINT16              conn_id;
424     BD_ADDR             remote_bda;
425 } tBTA_GATTC_SERVICE_CHANGE;
426 
427 typedef union {
428     tBTA_GATT_STATUS        status;
429     tBTA_GATTC_DIS_CMPL     dis_cmpl;    /* discovery complete */
430     tBTA_GATTC_SEARCH_CMPL  search_cmpl;    /* search complete */
431     tBTA_GATTC_SRVC_RES     srvc_res;       /* discovery result */
432     tBTA_GATTC_REG          reg_oper;       /* registration data */
433     tBTA_GATTC_OPEN         open;
434     tBTA_GATTC_CONNECT      connect;
435     tBTA_GATTC_CLOSE        close;
436     tBTA_GATTC_DISCONNECT   disconnect;
437     tBTA_GATTC_READ         read;           /* read attribute/descriptor data */
438     tBTA_GATTC_WRITE        write;          /* write complete data */
439     tBTA_GATTC_EXEC_CMPL    exec_cmpl;      /*  execute complete */
440     tBTA_GATTC_NOTIFY       notify;         /* notification/indication event data */
441     tBTA_GATTC_ENC_CMPL_CB  enc_cmpl;
442     tBTA_GATTC_CFG_MTU      cfg_mtu;        /* configure MTU operation */
443     tBTA_GATTC_CONGEST      congest;
444     tBTA_GATTC_QUEUE_FULL   queue_full;
445     tBTA_GATTC_SERVICE_CHANGE srvc_chg;     /* service change event */
446     tBTA_GATTC_SET_ASSOC    set_assoc;
447     tBTA_GATTC_GET_ADDR_LIST get_addr_list;
448 } tBTA_GATTC;
449 
450 /* GATTC enable callback function */
451 typedef void (tBTA_GATTC_ENB_CBACK)(tBTA_GATT_STATUS status);
452 
453 /* Client callback function */
454 typedef void (tBTA_GATTC_CBACK)(tBTA_GATTC_EVT event, tBTA_GATTC *p_data);
455 
456 /* GATT Server Data Structure */
457 /* Server callback function events */
458 #define BTA_GATTS_REG_EVT                               0
459 #define BTA_GATTS_READ_EVT                              GATTS_REQ_TYPE_READ         /* 1 */
460 #define BTA_GATTS_WRITE_EVT                             GATTS_REQ_TYPE_WRITE        /* 2 */
461 #define BTA_GATTS_EXEC_WRITE_EVT                        GATTS_REQ_TYPE_WRITE_EXEC   /* 3 */
462 #define BTA_GATTS_MTU_EVT                               GATTS_REQ_TYPE_MTU          /* 4 */
463 #define BTA_GATTS_CONF_EVT                              GATTS_REQ_TYPE_CONF         /* 5 */
464 #define BTA_GATTS_DEREG_EVT                             6
465 #define BTA_GATTS_CREATE_EVT                            7
466 #define BTA_GATTS_ADD_INCL_SRVC_EVT                     8
467 #define BTA_GATTS_ADD_CHAR_EVT                          9
468 #define BTA_GATTS_ADD_CHAR_DESCR_EVT                    10
469 #define BTA_GATTS_DELELTE_EVT                           11
470 #define BTA_GATTS_START_EVT                             12
471 #define BTA_GATTS_STOP_EVT                              13
472 #define BTA_GATTS_CONNECT_EVT                           14
473 #define BTA_GATTS_DISCONNECT_EVT                        15
474 #define BTA_GATTS_OPEN_EVT                              16
475 #define BTA_GATTS_CANCEL_OPEN_EVT                       17
476 #define BTA_GATTS_CLOSE_EVT                             18
477 #define BTA_GATTS_LISTEN_EVT                            19
478 #define BTA_GATTS_CONGEST_EVT                           20
479 #define BTA_GATTS_SET_ATTR_VAL_EVT                      23
480 #define BTA_GATTS_SEND_SERVICE_CHANGE_EVT               24
481 
482 typedef UINT8  tBTA_GATTS_EVT;
483 typedef tGATT_IF tBTA_GATTS_IF;
484 
485 /* Attribute permissions
486 */
487 #define BTA_GATT_PERM_READ              GATT_PERM_READ              /* bit 0 -  0x0001 */
488 #define BTA_GATT_PERM_READ_ENCRYPTED    GATT_PERM_READ_ENCRYPTED    /* bit 1 -  0x0002 */
489 #define BTA_GATT_PERM_READ_ENC_MITM     GATT_PERM_READ_ENC_MITM     /* bit 2 -  0x0004 */
490 #define BTA_GATT_PERM_WRITE             GATT_PERM_WRITE             /* bit 4 -  0x0010 */
491 #define BTA_GATT_PERM_WRITE_ENCRYPTED   GATT_PERM_WRITE_ENCRYPTED   /* bit 5 -  0x0020 */
492 #define BTA_GATT_PERM_WRITE_ENC_MITM    GATT_PERM_WRITE_ENC_MITM    /* bit 6 -  0x0040 */
493 #define BTA_GATT_PERM_WRITE_SIGNED      GATT_PERM_WRITE_SIGNED      /* bit 7 -  0x0080 */
494 #define BTA_GATT_PERM_WRITE_SIGNED_MITM GATT_PERM_WRITE_SIGNED_MITM /* bit 8 -  0x0100 */
495 #define BTA_GATT_PERM_READ_AUTHORIZATION GATT_PERM_READ_AUTHORIZATION /* bit 9 - 0x0200 */
496 #define BTA_GATT_PERM_WRITE_AUTHORIZATION GATT_PERM_WRITE_AUTHORIZATION /* bit 10 - 0x0400 */
497 typedef UINT16 tBTA_GATT_PERM;
498 typedef tGATT_ATTR_VAL tBTA_GATT_ATTR_VAL;
499 typedef tGATTS_ATTR_CONTROL tBTA_GATTS_ATTR_CONTROL;
500 
501 #define BTA_GATTS_INVALID_APP   0xff
502 
503 #define BTA_GATTS_INVALID_IF    0
504 
505 /* definition of characteristic properties */
506 #define BTA_GATT_CHAR_PROP_BIT_BROADCAST        GATT_CHAR_PROP_BIT_BROADCAST    /* 0x01 */
507 #define BTA_GATT_CHAR_PROP_BIT_READ             GATT_CHAR_PROP_BIT_READ         /* 0x02 */
508 #define BTA_GATT_CHAR_PROP_BIT_WRITE_NR         GATT_CHAR_PROP_BIT_WRITE_NR     /* 0x04 */
509 #define BTA_GATT_CHAR_PROP_BIT_WRITE            GATT_CHAR_PROP_BIT_WRITE        /* 0x08 */
510 #define BTA_GATT_CHAR_PROP_BIT_NOTIFY           GATT_CHAR_PROP_BIT_NOTIFY       /* 0x10 */
511 #define BTA_GATT_CHAR_PROP_BIT_INDICATE         GATT_CHAR_PROP_BIT_INDICATE     /* 0x20 */
512 #define BTA_GATT_CHAR_PROP_BIT_AUTH             GATT_CHAR_PROP_BIT_AUTH         /* 0x40 */
513 #define BTA_GATT_CHAR_PROP_BIT_EXT_PROP         GATT_CHAR_PROP_BIT_EXT_PROP     /* 0x80 */
514 typedef UINT8 tBTA_GATT_CHAR_PROP;
515 
516 #ifndef BTA_GATTC_CHAR_DESCR_MAX
517 #define BTA_GATTC_CHAR_DESCR_MAX        7
518 #endif
519 
520 /***********************  NV callback Data Definitions   **********************
521 */
522 typedef struct {
523     tBT_UUID app_uuid128;
524     tBT_UUID svc_uuid;
525     UINT16   svc_inst;
526     UINT16   s_handle;
527     UINT16   e_handle;
528     BOOLEAN  is_primary;      /* primary service or secondary */
529 } tBTA_GATTS_HNDL_RANGE;
530 
531 #define BTA_GATTS_SRV_CHG_CMD_ADD_CLIENT       GATTS_SRV_CHG_CMD_ADD_CLIENT
532 #define BTA_GATTS_SRV_CHG_CMD_UPDATE_CLIENT    GATTS_SRV_CHG_CMD_UPDATE_CLIENT
533 #define BTA_GATTS_SRV_CHG_CMD_REMOVE_CLIENT    GATTS_SRV_CHG_CMD_REMOVE_CLIENT
534 #define BTA_GATTS_SRV_CHG_CMD_READ_NUM_CLENTS  GATTS_SRV_CHG_CMD_READ_NUM_CLENTS
535 #define BTA_GATTS_SRV_CHG_CMD_READ_CLENT       GATTS_SRV_CHG_CMD_READ_CLENT
536 typedef tGATTS_SRV_CHG_CMD tBTA_GATTS_SRV_CHG_CMD;
537 
538 typedef tGATTS_SRV_CHG     tBTA_GATTS_SRV_CHG;
539 typedef tGATTS_SRV_CHG_REQ tBTA_GATTS_SRV_CHG_REQ;
540 typedef tGATTS_SRV_CHG_RSP tBTA_GATTS_SRV_CHG_RSP;
541 
542 #define BTA_GATT_TRANSPORT_LE           GATT_TRANSPORT_LE
543 #define BTA_GATT_TRANSPORT_BR_EDR       GATT_TRANSPORT_BR_EDR
544 #define BTA_GATT_TRANSPORT_LE_BR_EDR    GATT_TRANSPORT_LE_BR_EDR
545 typedef UINT8 tBTA_GATT_TRANSPORT;
546 
547 /* attribute value */
548 typedef tGATT_VALUE tBTA_GATT_VALUE;
549 
550 /* attribute response data */
551 typedef tGATTS_RSP tBTA_GATTS_RSP;
552 
553 /* relate to ESP_GATT_PREP_WRITE_xxx in esp_gatt_defs.h */
554 /* attribute request data from the client */
555 #define BTA_GATT_PREP_WRITE_CANCEL   0x00
556 #define BTA_GATT_PREP_WRITE_EXEC     0x01
557 typedef tGATT_EXEC_FLAG tBTA_GATT_EXEC_FLAG;
558 
559 /* read request always based on UUID */
560 typedef tGATT_READ_REQ tBTA_GATT_READ_REQ;
561 
562 /* write request data */
563 typedef tGATT_WRITE_REQ tBTA_GATT_WRITE_REQ;
564 
565 /* callback data for server access request from client */
566 typedef tGATTS_DATA tBTA_GATTS_REQ_DATA;
567 
568 typedef struct {
569     tBTA_GATT_STATUS    status;
570     BD_ADDR             remote_bda;
571     UINT32              trans_id;
572     UINT16              conn_id;
573     UINT16              handle;
574     tBTA_GATTS_REQ_DATA *p_data;
575     UINT16  data_len;
576     UINT8   *value;
577 } tBTA_GATTS_REQ;
578 
579 typedef struct {
580     tBTA_GATTS_IF       server_if;
581     tBTA_GATT_STATUS    status;
582     tBT_UUID            uuid;
583 }tBTA_GATTS_REG_OPER;
584 
585 
586 typedef struct {
587     tBTA_GATTS_IF       server_if;
588     UINT16              service_id;
589     UINT16              svc_instance;
590     BOOLEAN             is_primary;
591     tBTA_GATT_STATUS    status;
592     tBT_UUID            uuid;
593 }tBTA_GATTS_CREATE;
594 
595 typedef struct {
596     tBTA_GATTS_IF       server_if;
597     UINT16              service_id;
598     UINT16              attr_id;
599     tBTA_GATT_STATUS    status;
600     tBT_UUID            char_uuid;
601 }tBTA_GATTS_ADD_RESULT;
602 typedef struct{
603     tBTA_GATTS_IF       server_if;
604     UINT16              service_id;
605     UINT16              attr_id;
606     tBTA_GATT_STATUS    status;
607 }tBAT_GATTS_ATTR_VAL_RESULT;
608 
609 typedef struct {
610     tBTA_GATTS_IF       server_if;
611     UINT16              service_id;
612     tBTA_GATT_STATUS    status;
613 } tBTA_GATTS_SRVC_OPER;
614 
615 
616 typedef struct {
617     tBTA_GATTS_IF       server_if;
618     BD_ADDR             remote_bda;
619     UINT16              conn_id;
620     UINT8               link_role;
621     tBTA_GATT_REASON    reason; /* report disconnect reason */
622     tBTA_GATT_TRANSPORT transport;
623     tBTA_GATT_CONN_PARAMS conn_params;
624 } tBTA_GATTS_CONN;
625 
626 typedef struct {
627     UINT16 conn_id;
628     BOOLEAN congested; /* report channel congestion indicator */
629 } tBTA_GATTS_CONGEST;
630 
631 typedef struct {
632     UINT16 conn_id; /* connection ID */
633     tBTA_GATT_STATUS status; /* notification/indication status */
634 } tBTA_GATTS_CONF;
635 
636 typedef struct {
637     tBTA_GATT_STATUS    status;
638     UINT16              conn_id;    /* connection ID */
639 } tBTA_GATTS_CLOSE;
640 
641 typedef struct {
642     tBTA_GATT_STATUS    status;
643     tBTA_GATTS_IF       server_if;
644 } tBTA_GATTS_SERVICE_CHANGE;
645 
646 typedef struct {
647     tBTA_GATT_STATUS    status;
648     tBTA_GATTS_IF       server_if;
649 } tBTA_GATTS_OPEN;
650 
651 typedef struct {
652     tBTA_GATT_STATUS    status;
653     tBTA_GATTS_IF       server_if;
654 } tBTA_GATTS_CANCEL_OPEN;
655 /* GATTS callback data */
656 typedef union {
657     tBTA_GATTS_REG_OPER         reg_oper;
658     tBTA_GATTS_CREATE           create;
659     tBTA_GATTS_SRVC_OPER        srvc_oper;
660     tBTA_GATT_STATUS            status;         /* BTA_GATTS_LISTEN_EVT */
661     tBTA_GATTS_ADD_RESULT       add_result;     /* add included service: BTA_GATTS_ADD_INCL_SRVC_EVT
662                                                 add char : BTA_GATTS_ADD_CHAR_EVT
663                                                 add char descriptor: BTA_GATTS_ADD_CHAR_DESCR_EVT */
664     tBAT_GATTS_ATTR_VAL_RESULT  attr_val;
665     tBTA_GATTS_REQ              req_data;
666     tBTA_GATTS_CONN             conn;           /* BTA_GATTS_CONN_EVT */
667     tBTA_GATTS_CONGEST          congest;        /* BTA_GATTS_CONGEST_EVT callback data */
668     tBTA_GATTS_CONF             confirm;        /* BTA_GATTS_CONF_EVT callback data */
669     tBTA_GATTS_CLOSE            close;          /* BTA_GATTS_CLOSE_EVT callback data */
670     tBTA_GATTS_OPEN             open;           /* BTA_GATTS_OPEN_EVT callback data */
671     tBTA_GATTS_CANCEL_OPEN      cancel_open;    /* tBTA_GATTS_CANCEL_OPEN callback data */
672     tBTA_GATTS_SERVICE_CHANGE   service_change;
673 
674 } tBTA_GATTS;
675 
676 /* GATTC wait for service change ccc timer callback data */
677 typedef struct {
678     UINT16 conn_id;
679     BD_ADDR remote_bda;
680     UINT8 count;
681     UINT8 last_status;
682 }tBTA_GATTC_WAIT_CCC_TIMER;
683 
684 /* GATTS enable callback function */
685 typedef void (tBTA_GATTS_ENB_CBACK)(tBTA_GATT_STATUS status);
686 
687 /* Server callback function */
688 typedef void (tBTA_GATTS_CBACK)(tBTA_GATTS_EVT event,  tBTA_GATTS *p_data);
689 typedef struct
690 {
691     tBT_UUID                uuid;
692     BOOLEAN                 is_primary;
693     UINT16                  handle;
694     UINT16                  s_handle;
695     UINT16                  e_handle;
696     list_t                 *characteristics; /* list of tBTA_GATTC_CHARACTERISTIC */
697     list_t                 *included_svc; /* list of tBTA_GATTC_INCLUDED_SVC */
698 } __attribute__((packed)) tBTA_GATTC_SERVICE;
699 
700 typedef struct
701 {
702     tBT_UUID                uuid;
703     UINT16                  handle;
704     tBTA_GATT_CHAR_PROP     properties;
705     tBTA_GATTC_SERVICE     *service; /* owning service*/
706     list_t                 *descriptors; /* list of tBTA_GATTC_DESCRIPTOR */
707 } __attribute__((packed)) tBTA_GATTC_CHARACTERISTIC;
708 
709 typedef struct
710 {
711     tBT_UUID                    uuid;
712     UINT16                      handle;
713     tBTA_GATTC_CHARACTERISTIC  *characteristic; /* owning characteristic */
714 } __attribute__((packed)) tBTA_GATTC_DESCRIPTOR;
715 
716 typedef struct
717 {
718     tBT_UUID                uuid;
719     UINT16                  handle;
720     UINT16                  incl_srvc_s_handle;
721     UINT16                  incl_srvc_e_handle;
722     tBTA_GATTC_SERVICE     *owning_service; /* owning service*/
723     tBTA_GATTC_SERVICE     *included_service;
724 } __attribute__((packed)) tBTA_GATTC_INCLUDED_SVC;
725 
726 /*****************************************************************************
727 **  External Function Declarations
728 *****************************************************************************/
729 
730 #ifdef __cplusplus
731 extern "C"
732 {
733 #endif
734 
735 /**************************
736 **  Client Functions
737 ***************************/
738 
739 /*******************************************************************************
740 **
741 ** Function         BTA_GATTC_Disable
742 **
743 ** Description      This function is called to disable the GATTC module
744 **
745 ** Parameters       None.
746 **
747 ** Returns          None
748 **
749 *******************************************************************************/
750 extern void BTA_GATTC_Disable(void);
751 
752 /*******************************************************************************
753 **
754 ** Function         BTA_GATTC_AppRegister
755 **
756 ** Description      This function is called to register application callbacks
757 **                    with BTA GATTC module.
758 **
759 ** Parameters       p_app_uuid - application UUID
760 **                  p_client_cb - pointer to the application callback function.
761 **
762 ** Returns          None
763 **
764 *******************************************************************************/
765 extern void BTA_GATTC_AppRegister(tBT_UUID *p_app_uuid, tBTA_GATTC_CBACK *p_client_cb);
766 
767 /*******************************************************************************
768 **
769 ** Function         BTA_GATTC_AppDeregister
770 **
771 ** Description      This function is called to deregister an application
772 **                  from BTA GATTC module.
773 **
774 ** Parameters       client_if - client interface identifier.
775 **
776 ** Returns          None
777 **
778 *******************************************************************************/
779 extern void BTA_GATTC_AppDeregister (tBTA_GATTC_IF client_if);
780 
781 /*******************************************************************************
782 **
783 ** Function         BTA_GATTC_Open
784 **
785 ** Description      Open a direct connection or add a background auto connection
786 **                  bd address
787 **
788 ** Parameters       client_if: server interface.
789 **                  remote_bda: remote device BD address.
790 **                  remote_addr_type: remote device BD address type.
791 **                  is_direct: direct connection or background auto connection
792 **
793 ** Returns          void
794 **
795 *******************************************************************************/
796 extern void BTA_GATTC_Open(tBTA_GATTC_IF client_if, BD_ADDR remote_bda, tBTA_ADDR_TYPE remote_addr_type,
797                     BOOLEAN is_direct, tBTA_GATT_TRANSPORT transport, BOOLEAN is_aux);
798 
799 /*******************************************************************************
800 **
801 ** Function         BTA_GATTC_CancelOpen
802 **
803 ** Description      Open a direct connection or add a background auto connection
804 **                  bd address
805 **
806 ** Parameters       client_if: server interface.
807 **                  remote_bda: remote device BD address.
808 **                  is_direct: direct connection or background auto connection
809 **
810 ** Returns          void
811 **
812 *******************************************************************************/
813 extern void BTA_GATTC_CancelOpen(tBTA_GATTC_IF client_if, BD_ADDR remote_bda, BOOLEAN is_direct);
814 
815 /*******************************************************************************
816 **
817 ** Function         BTA_GATTC_Close
818 **
819 ** Description      Close a connection to a GATT server.
820 **
821 ** Parameters       conn_id: connection ID to be closed.
822 **
823 ** Returns          void
824 **
825 *******************************************************************************/
826 extern void BTA_GATTC_Close(UINT16 conn_id);
827 
828 /*******************************************************************************
829 **
830 ** Function         BTA_GATTC_ServiceSearchRequest
831 **
832 ** Description      This function is called to request a GATT service discovery
833 **                    on a GATT server. This function report service search result
834 **                  by a callback event, and followed by a service search complete
835 **                  event.
836 **
837 ** Parameters       conn_id: connection ID.
838 **                  p_srvc_uuid: a UUID of the service application is interested in.
839 **                              If Null, discover for all services.
840 **
841 ** Returns          None
842 **
843 *******************************************************************************/
844 extern void BTA_GATTC_ServiceSearchRequest(UINT16 conn_id, tBT_UUID *p_srvc_uuid);
845 
846 /*******************************************************************************
847 **
848 ** Function         BTA_GATTC_GetServices
849 **
850 ** Description      This function is called to find the services on the given server.
851 **
852 ** Parameters       conn_id: connection ID which identify the server.
853 **
854 ** Returns          returns list_t of tBTA_GATTC_SERVICE or NULL.
855 **
856 *******************************************************************************/
857 extern const list_t* BTA_GATTC_GetServices(UINT16 conn_id);
858 
859 /*******************************************************************************
860 **
861 ** Function         BTA_GATTC_GetCharacteristic
862 **
863 ** Description      This function is called to find the characteristic on the given server.
864 **
865 ** Parameters       conn_id: connection ID which identify the server.
866 **                  handle: characteristic handle
867 **
868 ** Returns          returns pointer to tBTA_GATTC_CHARACTERISTIC or NULL.
869 **
870 *******************************************************************************/
871 extern const tBTA_GATTC_CHARACTERISTIC* BTA_GATTC_GetCharacteristic(UINT16 conn_id, UINT16 handle);
872 
873 /*******************************************************************************
874 **
875 ** Function         BTA_GATTC_GetDescriptor
876 **
877 ** Description      This function is called to find the characteristic on the given server.
878 **
879 ** Parameters       conn_id: connection ID which identify the server.
880 **                  handle: descriptor handle
881 **
882 ** Returns          returns pointer to tBTA_GATTC_DESCRIPTOR or NULL.
883 **
884 *******************************************************************************/
885 extern const tBTA_GATTC_DESCRIPTOR* BTA_GATTC_GetDescriptor(UINT16 conn_id, UINT16 handle);
886 
887 extern void BTA_GATTC_GetServiceWithUUID(UINT16 conn_id, tBT_UUID *svc_uuid,
888                                          btgatt_db_element_t **db, UINT16 *count);
889 
890 extern void BTA_GATTC_GetAllChar(UINT16 conn_id, UINT16 start_handle, UINT16 end_handle,
891                                  btgatt_db_element_t **db, UINT16 *count);
892 
893 extern void BTA_GATTC_GetAllDescriptor(UINT16 conn_id, UINT16 char_handle,
894                                        btgatt_db_element_t **db, UINT16 *count);
895 
896 extern void BTA_GATTC_GetCharByUUID(UINT16 conn_id, UINT16 start_handle, UINT16 end_handle, tBT_UUID char_uuid,
897                                     btgatt_db_element_t **db, UINT16 *count);
898 
899 extern void BTA_GATTC_GetDescrByUUID(UINT16 conn_id, uint16_t start_handle, uint16_t end_handle,
900                                      tBT_UUID char_uuid, tBT_UUID descr_uuid,
901                                      btgatt_db_element_t **db, UINT16 *count);
902 
903 extern void BTA_GATTC_GetDescrByCharHandle(UINT16 conn_id, UINT16 char_handle, tBT_UUID descr_uuid,
904                                            btgatt_db_element_t **db, UINT16 *count);
905 
906 extern void BTA_GATTC_GetIncludeService(UINT16 conn_id, UINT16 start_handle, UINT16 end_handle,
907                                         tBT_UUID *incl_uuid, btgatt_db_element_t **db, UINT16 *count);
908 
909 extern void BTA_GATTC_GetDBSize(UINT16 conn_id, UINT16 start_handle, UINT16 end_handle, UINT16 *count);
910 
911 extern void BTA_GATTC_GetDBSizeByType(UINT16 conn_id, bt_gatt_db_attribute_type_t type,
912                                       UINT16 start_handle, UINT16 end_handle, UINT16 char_handle, UINT16 *count);
913 
914 /*******************************************************************************
915 **
916 ** Function         BTA_GATTC_GetGattDb
917 **
918 ** Description      This function is called to get gatt db.
919 **
920 ** Parameters       conn_id: connection ID which identify the server.
921 **                  db: output parameter which will contain gatt db copy.
922 **                      Caller is responsible for freeing it.
923 **                  count: number of elements in db.
924 **
925 *******************************************************************************/
926 extern void BTA_GATTC_GetGattDb(UINT16 conn_id, UINT16 start_handle, UINT16 end_handle,
927                                 btgatt_db_element_t **db, UINT16 *count);
928 
929 /*******************************************************************************
930 **
931 ** Function         BTA_GATTC_ReadCharacteristic
932 **
933 ** Description      This function is called to read a characteristics value
934 **
935 ** Parameters       conn_id - connectino ID.
936 **                  handle - characteritic handle to read.
937 **
938 ** Returns          None
939 **
940 *******************************************************************************/
941 void BTA_GATTC_ReadCharacteristic(UINT16 conn_id, UINT16 handle, tBTA_GATT_AUTH_REQ auth_req);
942 
943 /*******************************************************************************
944 **
945 ** Function         BTA_GATTC_Read_by_type
946 **
947 ** Description      This function is called to read a attribute value by uuid
948 **
949 ** Parameters       conn_id - connection ID.
950 **                  s_handle - start handle.
951 **                  e_handle - end hanle
952 **                  uuid - The attribute UUID.
953 **
954 ** Returns          None
955 **
956 *******************************************************************************/
957 void BTA_GATTC_Read_by_type(UINT16 conn_id, UINT16 s_handle,UINT16 e_handle, tBT_UUID *uuid, tBTA_GATT_AUTH_REQ auth_req);
958 
959 /*******************************************************************************
960 **
961 ** Function         BTA_GATTC_ReadCharDescr
962 **
963 ** Description      This function is called to read a descriptor value.
964 **
965 ** Parameters       conn_id - connection ID.
966 **                  handle - descriptor handle to read.
967 **
968 ** Returns          None
969 **
970 *******************************************************************************/
971 void BTA_GATTC_ReadCharDescr (UINT16 conn_id, UINT16 handle, tBTA_GATT_AUTH_REQ auth_req);
972 
973 /*******************************************************************************
974 **
975 ** Function         BTA_GATTC_WriteCharValue
976 **
977 ** Description      This function is called to write characteristic value.
978 **
979 ** Parameters       conn_id - connection ID.
980 **                  handle - characteristic handle to write.
981 **                  write_type - type of write.
982 **                  len: length of the data to be written.
983 **                  p_value - the value to be written.
984 **
985 ** Returns          None
986 **
987 *******************************************************************************/
988 void BTA_GATTC_WriteCharValue ( UINT16 conn_id,
989                                 UINT16 handle,
990                                 tBTA_GATTC_WRITE_TYPE  write_type,
991                                 UINT16 len,
992                                 UINT8 *p_value,
993                                 tBTA_GATT_AUTH_REQ auth_req);
994 
995 /*******************************************************************************
996 **
997 ** Function         BTA_GATTC_WriteCharDescr
998 **
999 ** Description      This function is called to write descriptor value.
1000 **
1001 ** Parameters       conn_id - connection ID
1002 **                  handle - descriptor handle to write.
1003 **                  write_type - type of write.
1004 **                  p_value - the value to be written.
1005 **
1006 ** Returns          None
1007 **
1008 *******************************************************************************/
1009 void BTA_GATTC_WriteCharDescr (UINT16 conn_id,
1010                                UINT16 handle,
1011                                tBTA_GATTC_WRITE_TYPE  write_type,
1012                                tBTA_GATT_UNFMT      *p_data,
1013                                tBTA_GATT_AUTH_REQ auth_req);
1014 
1015 /*******************************************************************************
1016 **
1017 ** Function         BTA_GATTC_SendIndConfirm
1018 **
1019 ** Description      This function is called to send handle value confirmation.
1020 **
1021 ** Parameters       conn_id - connection ID.
1022 **                  handle - characteristic handle to confirm.
1023 **
1024 ** Returns          None
1025 **
1026 *******************************************************************************/
1027 extern void BTA_GATTC_SendIndConfirm (UINT16 conn_id, UINT16 handle);
1028 
1029 /*******************************************************************************
1030 **
1031 ** Function         BTA_GATTC_RegisterForNotifications
1032 **
1033 ** Description      This function is called to register for notification of a service.
1034 **
1035 ** Parameters       client_if - client interface.
1036 **                  remote_bda - target GATT server.
1037 **                  handle - GATT characteristic handle.
1038 **
1039 ** Returns          OK if registration succeed, otherwise failed.
1040 **
1041 *******************************************************************************/
1042 extern tBTA_GATT_STATUS BTA_GATTC_RegisterForNotifications (tBTA_GATTC_IF      client_if,
1043                                                             BD_ADDR            remote_bda,
1044                                                             UINT16             handle);
1045 
1046 /*******************************************************************************
1047 **
1048 ** Function         BTA_GATTC_DeregisterForNotifications
1049 **
1050 ** Description      This function is called to de-register for notification of a servbice.
1051 **
1052 ** Parameters       client_if - client interface.
1053 **                  remote_bda - target GATT server.
1054 **                  handle - GATT characteristic handle.
1055 **
1056 ** Returns          OK if deregistration succeed, otherwise failed.
1057 **
1058 *******************************************************************************/
1059 extern tBTA_GATT_STATUS BTA_GATTC_DeregisterForNotifications (tBTA_GATTC_IF      client_if,
1060                                                               BD_ADDR            remote_bda,
1061                                                               UINT16             handle);
1062 
1063 /*******************************************************************************
1064 **
1065 ** Function         BTA_GATTC_PrepareWrite
1066 **
1067 ** Description      This function is called to prepare write a characteristic value.
1068 **
1069 ** Parameters       conn_id - connection ID.
1070 **                  handle - GATT characteritic handle.
1071 **                  offset - offset of the write value.
1072 **                  len - length of the data to be written.
1073 **                  p_value - the value to be written.
1074 **
1075 ** Returns          None
1076 **
1077 *******************************************************************************/
1078 extern void BTA_GATTC_PrepareWrite  (UINT16 conn_id,
1079                                      UINT16 handle,
1080                                      UINT16 offset,
1081                                      UINT16 len,
1082                                      UINT8 *p_value,
1083                                      tBTA_GATT_AUTH_REQ auth_req);
1084 
1085 /*******************************************************************************
1086 **
1087 ** Function         BTA_GATTC_PrepareWriteCharDescr
1088 **
1089 ** Description      This function is called to prepare write a characteristic descriptor value.
1090 **
1091 ** Parameters       conn_id - connection ID.
1092 **                  p_char_descr_id - GATT characteritic descriptor ID of the service.
1093 **                  offset - offset of the write value.
1094 **                  len: length of the data to be written.
1095 **                  p_value - the value to be written.
1096 **
1097 ** Returns          None
1098 **
1099 *******************************************************************************/
1100 extern void BTA_GATTC_PrepareWriteCharDescr  (UINT16 conn_id,
1101                                               UINT16 handle,
1102                                               UINT16 offset,
1103                                               tBTA_GATT_UNFMT   *p_data,
1104                                               tBTA_GATT_AUTH_REQ auth_req);
1105 /*******************************************************************************
1106 **
1107 ** Function         BTA_GATTC_ExecuteWrite
1108 **
1109 ** Description      This function is called to execute write a prepare write sequence.
1110 **
1111 ** Parameters       conn_id - connection ID.
1112 **                    is_execute - execute or cancel.
1113 **
1114 ** Returns          None
1115 **
1116 *******************************************************************************/
1117 extern void BTA_GATTC_ExecuteWrite  (UINT16 conn_id, BOOLEAN is_execute);
1118 
1119 /*******************************************************************************
1120 **
1121 ** Function         BTA_GATTC_ReadMultiple
1122 **
1123 ** Description      This function is called to read multiple characteristic or
1124 **                  characteristic descriptors.
1125 **
1126 ** Parameters       conn_id - connection ID.
1127 **                    p_read_multi - read multiple parameters.
1128 **
1129 ** Returns          None
1130 **
1131 *******************************************************************************/
1132 extern void BTA_GATTC_ReadMultiple(UINT16 conn_id, tBTA_GATTC_MULTI *p_read_multi,
1133                                    tBTA_GATT_AUTH_REQ auth_req);
1134 
1135 
1136 /*******************************************************************************
1137 **
1138 ** Function         BTA_GATTC_Refresh
1139 **
1140 ** Description      Refresh the server cache of the remote device
1141 **
1142 ** Parameters       remote_bda: remote device BD address.
1143 **                  erase_flash: delete cache from nvs flash
1144 **
1145 ** Returns          void
1146 **
1147 *******************************************************************************/
1148 extern void BTA_GATTC_Refresh(BD_ADDR remote_bda, bool erase_flash);
1149 
1150 extern void BTA_GATTC_CacheAssoc(tBTA_GATTC_IF client_if, BD_ADDR src_addr, BD_ADDR assoc_addr, BOOLEAN is_assoc);
1151 
1152 extern void BTA_GATTC_CacheGetAddrList(tBTA_GATTC_IF client_if);
1153 
1154 /*******************************************************************************
1155 **
1156 ** Function         BTA_GATTC_Clean
1157 **
1158 ** Description      Clean the server cache of the remote device
1159 **
1160 ** Parameters       remote_bda: remote device BD address.
1161 **
1162 ** Returns          void
1163 **
1164 *******************************************************************************/
1165 extern void BTA_GATTC_Clean(BD_ADDR remote_bda);
1166 
1167 /*******************************************************************************
1168 **
1169 ** Function         BTA_GATTC_Listen
1170 **
1171 ** Description      Start advertisement to listen for connection request.
1172 **
1173 ** Parameters       client_if: server interface.
1174 **                  start: to start or stop listening for connection
1175 **                  remote_bda: remote device BD address, if listen to all device
1176 **                              use NULL.
1177 **
1178 ** Returns          void
1179 **
1180 *******************************************************************************/
1181 extern void BTA_GATTC_Listen(tBTA_GATTC_IF client_if, BOOLEAN start, BD_ADDR_PTR target_bda);
1182 
1183 /*******************************************************************************
1184 **
1185 ** Function         BTA_GATTC_Broadcast
1186 **
1187 ** Description      Start broadcasting (non-connectable advertisements)
1188 **
1189 ** Parameters       client_if: client interface.
1190 **                  start: to start or stop listening for connection
1191 **
1192 ** Returns          void
1193 **
1194 *******************************************************************************/
1195 extern void BTA_GATTC_Broadcast(tBTA_GATTC_IF client_if, BOOLEAN start);
1196 
1197 
1198 /*******************************************************************************
1199 **
1200 ** Function         BTA_GATTC_ConfigureMTU
1201 **
1202 ** Description      Configure the MTU size in the GATT channel. This can be done
1203 **                  only once per connection.
1204 **
1205 ** Parameters       conn_id: connection ID.
1206 **
1207 **
1208 ** Returns          void
1209 **
1210 *******************************************************************************/
1211 extern void BTA_GATTC_ConfigureMTU (UINT16 conn_id);
1212 
1213 /*******************************************************************************
1214 **  BTA GATT Server API
1215 ********************************************************************************/
1216 
1217 /*******************************************************************************
1218 **
1219 ** Function         BTA_GATTS_Init
1220 **
1221 ** Description      This function is called to initalize GATTS module
1222 **
1223 ** Parameters       None
1224 **
1225 ** Returns          None
1226 **
1227 *******************************************************************************/
1228 extern void BTA_GATTS_Init(void);
1229 
1230 /*******************************************************************************
1231 **
1232 ** Function         BTA_GATTS_Disable
1233 **
1234 ** Description      This function is called to disable GATTS module
1235 **
1236 ** Parameters       None.
1237 **
1238 ** Returns          None
1239 **
1240 *******************************************************************************/
1241 extern void BTA_GATTS_Disable(void);
1242 
1243 /*******************************************************************************
1244 **
1245 ** Function         BTA_GATTS_AppRegister
1246 **
1247 ** Description      This function is called to register application callbacks
1248 **                    with BTA GATTS module.
1249 **
1250 ** Parameters       p_app_uuid - application UUID
1251 **                  p_cback - pointer to the application callback function.
1252 **
1253 ** Returns          None
1254 **
1255 *******************************************************************************/
1256 extern void BTA_GATTS_AppRegister(const tBT_UUID * p_app_uuid, tBTA_GATTS_CBACK *p_cback);
1257 
1258 
1259 /*******************************************************************************
1260 **
1261 ** Function         BTA_GATTS_AppDeregister
1262 **
1263 ** Description      De-register with BTA GATT Server.
1264 **
1265 ** Parameters       server_if: server interface
1266 **
1267 ** Returns          void
1268 **
1269 *******************************************************************************/
1270 extern void BTA_GATTS_AppDeregister(tBTA_GATTS_IF server_if);
1271 
1272 /*******************************************************************************
1273 **
1274 ** Function         BTA_GATTS_CreateService
1275 **
1276 ** Description      Create a service. When service creation is done, a callback
1277 **                  event BTA_GATTS_CREATE_EVT is called to report status
1278 **                  and service ID to the profile. The service ID obtained in
1279 **                  the callback function needs to be used when adding included
1280 **                  service and characteristics/descriptors into the service.
1281 **
1282 ** Parameters       server_if: server interface.
1283 **                  p_service_uuid: service UUID.
1284 **                  inst: instance ID number of this service.
1285 **                  num_handle: numble of handle requessted for this service.
1286 **                  is_primary: is this service a primary one or not.
1287 **
1288 ** Returns          void
1289 **
1290 *******************************************************************************/
1291 extern void BTA_GATTS_CreateService(tBTA_GATTS_IF server_if, const tBT_UUID * p_service_uuid,
1292                                     UINT8 inst, UINT16 num_handle, BOOLEAN is_primary);
1293 
1294 /*******************************************************************************
1295 **
1296 ** Function         BTA_GATTS_AddIncludeService
1297 **
1298 ** Description      This function is called to add an included service. After included
1299 **                  service is included, a callback event BTA_GATTS_ADD_INCL_SRVC_EVT
1300 **                  is reported the included service ID.
1301 **
1302 ** Parameters       service_id: service ID to which this included service is to
1303 **                              be added.
1304 **                  included_service_id: the service ID to be included.
1305 **
1306 ** Returns          void
1307 **
1308 *******************************************************************************/
1309 extern void BTA_GATTS_AddIncludeService(UINT16 service_id, UINT16 included_service_id);
1310 
1311 /*******************************************************************************
1312 **
1313 ** Function         BTA_GATTS_AddCharacteristic
1314 **
1315 ** Description      This function is called to add a characteristic into a service.
1316 **
1317 ** Parameters       service_id: service ID to which this included service is to
1318 **                              be added.
1319 **                  p_char_uuid : Characteristic UUID.
1320 **                  perm      : Characteristic value declaration attribute permission.
1321 **                  property  : Characteristic Properties
1322 **
1323 ** Returns          None
1324 **
1325 *******************************************************************************/
1326 extern void BTA_GATTS_AddCharacteristic (UINT16 service_id,  const tBT_UUID  * p_char_uuid,
1327                                   tBTA_GATT_PERM perm, tBTA_GATT_CHAR_PROP property, tGATT_ATTR_VAL *attr_val,
1328                                   tBTA_GATTS_ATTR_CONTROL *control);
1329 
1330 /*******************************************************************************
1331 **
1332 ** Function         BTA_GATTS_AddCharDescriptor
1333 **
1334 ** Description      This function is called to add characteristic descriptor. When
1335 **                  it's done, a callback event BTA_GATTS_ADD_DESCR_EVT is called
1336 **                  to report the status and an ID number for this descriptor.
1337 **
1338 ** Parameters       service_id: service ID to which this charatceristic descriptor is to
1339 **                              be added.
1340 **                  perm: descriptor access permission.
1341 **                  p_descr_uuid: descriptor UUID.
1342 **                  p_descr_params: descriptor value if it's read only descriptor.
1343 **
1344 ** Returns          returns status.
1345 **
1346 *******************************************************************************/
1347 extern void BTA_GATTS_AddCharDescriptor (UINT16 service_id,
1348                                   tBTA_GATT_PERM perm,
1349                                   const tBT_UUID  * p_descr_uuid, tBTA_GATT_ATTR_VAL *attr_val,
1350                                   tBTA_GATTS_ATTR_CONTROL *control);
1351 
1352 /*******************************************************************************
1353 **
1354 ** Function         BTA_GATTS_DeleteService
1355 **
1356 ** Description      This function is called to delete a service. When this is done,
1357 **                  a callback event BTA_GATTS_DELETE_EVT is report with the status.
1358 **
1359 ** Parameters       service_id: service_id to be deleted.
1360 **
1361 ** Returns          returns none.
1362 **
1363 *******************************************************************************/
1364 extern void  BTA_GATTS_DeleteService(UINT16 service_id);
1365 
1366 /*******************************************************************************
1367 **
1368 ** Function         BTA_GATTS_StartService
1369 **
1370 ** Description      This function is called to start a service.
1371 **
1372 ** Parameters       service_id: the service ID to be started.
1373 **                  sup_transport: supported transport.
1374 **
1375 ** Returns          None.
1376 **
1377 *******************************************************************************/
1378 extern void  BTA_GATTS_StartService(UINT16 service_id, tBTA_GATT_TRANSPORT sup_transport);
1379 
1380 /*******************************************************************************
1381 **
1382 ** Function         BTA_GATTS_StopService
1383 **
1384 ** Description      This function is called to stop a service.
1385 **
1386 ** Parameters       service_id - service to be topped.
1387 **
1388 ** Returns          None
1389 **
1390 *******************************************************************************/
1391 extern void BTA_GATTS_StopService(UINT16 service_id);
1392 
1393 /*******************************************************************************
1394 **
1395 ** Function         BTA_GATTS_HandleValueIndication
1396 **
1397 ** Description      This function is called to read a characteristics descriptor.
1398 **
1399 ** Parameters       conn_id - connection identifier.
1400 **                  attr_id - attribute ID to indicate.
1401 **                  data_len - indicate data length.
1402 **                  p_data: data to indicate.
1403 **                  need_confirm - if this indication expects a confirmation or not.
1404 **
1405 ** Returns          None
1406 **
1407 *******************************************************************************/
1408 extern void BTA_GATTS_HandleValueIndication (UINT16 conn_id, UINT16 attr_id,
1409                                              UINT16 data_len,
1410                                              UINT8 *p_data,
1411                                              BOOLEAN need_confirm);
1412 
1413 /*******************************************************************************
1414 **
1415 ** Function         BTA_GATTS_SendRsp
1416 **
1417 ** Description      This function is called to send a response to a request.
1418 **
1419 ** Parameters       conn_id - connection identifier.
1420 **                  trans_id - transaction ID.
1421 **                  status - response status
1422 **                  p_msg - response data.
1423 **
1424 ** Returns          None
1425 **
1426 *******************************************************************************/
1427 extern void BTA_GATTS_SendRsp (UINT16 conn_id, UINT32 trans_id,
1428                                tBTA_GATT_STATUS status, tBTA_GATTS_RSP *p_msg);
1429 
1430 
1431 
1432 /*******************************************************************************
1433 **
1434 ** Function         BTA_SetAttributeValue
1435 **
1436 ** Description      This function is called to set the attribute value in the gatt database
1437 **
1438 ** Parameters   attr_handle - the attribute value handle.
1439 **                      length - the value length which has been set to the attribute.
1440 **                      value - the pointer to the value
1441 **
1442 ** Returns          None
1443 **
1444 *******************************************************************************/
1445 extern void BTA_SetAttributeValue(UINT16 attr_handle, UINT16 length, UINT8 *value);
1446 
1447 
1448 /*******************************************************************************
1449 **
1450 ** Function         BTA_GetAttributeValue
1451 **
1452 ** Description      This function is called to get the attribute value in the gatt database
1453 **
1454 ** Parameters   attr_handle - the attribute value handle.
1455 **                      length - the value length which has been set to the attribute.
1456 **                      value - the pointer to the value
1457 **
1458 ** Returns          tBTA_GATT_STATUS
1459 **
1460 *******************************************************************************/
1461 extern tBTA_GATT_STATUS BTA_GetAttributeValue(UINT16 attr_handle, UINT16 *length, UINT8 **value);
1462 
1463 /*******************************************************************************
1464 **
1465 ** Function         BTA_GATTS_Open
1466 **
1467 ** Description      Open a direct open connection or add a background auto connection
1468 **                  bd address
1469 **
1470 ** Parameters       server_if: server interface.
1471 **                  remote_bda: remote device BD address.
1472 **                  is_direct: direct connection or background auto connection
1473 **
1474 ** Returns          void
1475 **
1476 *******************************************************************************/
1477 extern void BTA_GATTS_Open(tBTA_GATTS_IF server_if, BD_ADDR remote_bda,
1478                            BOOLEAN is_direct, tBTA_GATT_TRANSPORT transport);
1479 
1480 
1481 /*******************************************************************************
1482 **
1483 ** Function         BTA_GATTS_CancelOpen
1484 **
1485 ** Description      Cancel a direct open connection or remove a background auto connection
1486 **                  bd address
1487 **
1488 ** Parameters       server_if: server interface.
1489 **                  remote_bda: remote device BD address.
1490 **                  is_direct: direct connection or background auto connection
1491 **
1492 ** Returns          void
1493 **
1494 *******************************************************************************/
1495 extern void BTA_GATTS_CancelOpen(tBTA_GATTS_IF server_if, BD_ADDR remote_bda, BOOLEAN is_direct);
1496 
1497 
1498 /*******************************************************************************
1499 **
1500 ** Function         BTA_GATTS_Close
1501 **
1502 ** Description      Close a connection  a remote device.
1503 **
1504 ** Parameters       conn_id: connection ID to be closed.
1505 **
1506 ** Returns          void
1507 **
1508 *******************************************************************************/
1509 extern void BTA_GATTS_Close(UINT16 conn_id);
1510 
1511 /*******************************************************************************
1512 **
1513 ** Function         BTA_GATTS_SendServiceChangeIndication
1514 **
1515 ** Description     send a service change indication.
1516 **
1517 ** Returns          void
1518 **
1519 *******************************************************************************/
1520 
1521 void BTA_GATTS_SendServiceChangeIndication(tBTA_GATTS_IF server_if, BD_ADDR remote_bda);
1522 
1523 /*******************************************************************************
1524 **
1525 ** Function         BTA_GATTS_Listen
1526 **
1527 ** Description      Start advertisement to listen for connection request for a
1528 **                  GATT server
1529 **
1530 ** Parameters       server_if: server interface.
1531 **                  start: to start or stop listening for connection
1532 **                  remote_bda: remote device BD address, if listen to all device
1533 **                              use NULL.
1534 **
1535 ** Returns          void
1536 **
1537 *******************************************************************************/
1538 extern void BTA_GATTS_Listen(tBTA_GATTS_IF server_if, BOOLEAN start,
1539                              BD_ADDR_PTR target_bda);
1540 
1541 
1542 #ifdef __cplusplus
1543 
1544 }
1545 #endif
1546 
1547 
1548 #endif /* BTA_GATT_API_H */
1549