1 /******************************************************************************
2  *
3  *  Copyright (C) 2003-2012 Broadcom Corporation
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at:
8  *
9  *  http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  ******************************************************************************/
18 
19 /******************************************************************************
20  *
21  *  This is the private file for the file transfer client (FTC).
22  *
23  ******************************************************************************/
24 #ifndef BTA_GATTC_INT_H
25 #define BTA_GATTC_INT_H
26 
27 #include "common/bt_target.h"
28 #include "bta/bta_sys.h"
29 #include "bta/bta_gatt_api.h"
30 #include "bta/bta_gattc_ci.h"
31 #include "bta/bta_gattc_co.h"
32 #include "osi/fixed_queue.h"
33 #include "osi/mutex.h"
34 
35 /*****************************************************************************
36 **  Constants and data types
37 *****************************************************************************/
38 enum {
39     BTA_GATTC_API_OPEN_EVT   = BTA_SYS_EVT_START(BTA_ID_GATTC),
40     BTA_GATTC_INT_OPEN_FAIL_EVT,
41     BTA_GATTC_API_CANCEL_OPEN_EVT,
42     BTA_GATTC_INT_CANCEL_OPEN_OK_EVT,
43 
44     BTA_GATTC_API_READ_EVT,
45     BTA_GATTC_API_WRITE_EVT,
46     BTA_GATTC_API_EXEC_EVT,
47     BTA_GATTC_API_CFG_MTU_EVT,
48 
49     BTA_GATTC_API_CLOSE_EVT,
50 
51     BTA_GATTC_API_SEARCH_EVT,
52     BTA_GATTC_API_CONFIRM_EVT,
53     BTA_GATTC_API_READ_MULTI_EVT,
54     BTA_GATTC_API_REFRESH_EVT,
55     BTA_GATTC_API_CACHE_CLEAN_EVT,
56 
57     BTA_GATTC_INT_CONN_EVT,
58     BTA_GATTC_INT_DISCOVER_EVT,
59     BTA_GATTC_DISCOVER_CMPL_EVT,
60     BTA_GATTC_OP_CMPL_EVT,
61     BTA_GATTC_INT_DISCONN_EVT,
62 
63     BTA_GATTC_API_READ_BY_TYPE_EVT,
64 
65     BTA_GATTC_INT_START_IF_EVT,
66     BTA_GATTC_API_REG_EVT,
67     BTA_GATTC_API_DEREG_EVT,
68     BTA_GATTC_API_LISTEN_EVT,
69     BTA_GATTC_API_BROADCAST_EVT,
70     BTA_GATTC_API_DISABLE_EVT,
71     BTA_GATTC_ENC_CMPL_EVT,
72     BTA_GATTC_API_CACHE_ASSOC_EVT,
73     BTA_GATTC_API_CACHE_GET_ADDR_LIST_EVT,
74 };
75 typedef UINT16 tBTA_GATTC_INT_EVT;
76 
77 #define BTA_GATTC_SERVICE_CHANGED_LEN    4
78 
79 typedef enum {
80     BTA_GATTC_SERVICE_INFO_FROM_REMOTE_DEVICE         = 0,
81     BTA_GATTC_SERVICE_INFO_FROM_NVS_FLASH             = 1,
82     BTA_GATTC_SERVICE_INFO_FROM_UNKNOWN               = 2,
83 } tBTA_SERVICE_SOURCE_t;
84 
85 /* max client application GATTC can support */
86 #ifndef     BTA_GATTC_CL_MAX
87 #if (GATT_MAX_PHY_CHANNEL > 3)
88     #define     BTA_GATTC_CL_MAX    GATT_MAX_PHY_CHANNEL
89 #else
90     #define     BTA_GATTC_CL_MAX    3 // The origin value is 10
91 #endif
92 #endif
93 
94 /* max known devices GATTC can support */
95 #ifndef     BTA_GATTC_KNOWN_SR_MAX
96 #if (GATT_MAX_PHY_CHANNEL > 3)
97     #define     BTA_GATTC_KNOWN_SR_MAX    GATT_MAX_PHY_CHANNEL
98 #else
99     #define     BTA_GATTC_KNOWN_SR_MAX    3 // The origin value is 10
100 #endif
101 #endif
102 
103 #define BTA_GATTC_CONN_MAX      GATT_MAX_PHY_CHANNEL
104 
105 #ifndef BTA_GATTC_CLCB_MAX
106 #define BTA_GATTC_CLCB_MAX      GATT_CL_MAX_LCB
107 #endif
108 
109 #define BTA_GATTC_WRITE_PREPARE          GATT_WRITE_PREPARE
110 #define BTA_GATTC_INVALID_HANDLE         0
111 
112 /* internal strucutre for GATTC register API  */
113 typedef struct {
114     BT_HDR                  hdr;
115     tBT_UUID                app_uuid;
116     tBTA_GATTC_CBACK        *p_cback;
117 } tBTA_GATTC_API_REG;
118 
119 typedef struct {
120     BT_HDR                  hdr;
121     tBTA_GATTC_IF           client_if;
122 } tBTA_GATTC_INT_START_IF;
123 
124 typedef tBTA_GATTC_INT_START_IF tBTA_GATTC_API_DEREG;
125 typedef tBTA_GATTC_INT_START_IF tBTA_GATTC_INT_DEREG;
126 
127 typedef struct {
128     BT_HDR                  hdr;
129     BD_ADDR                 remote_bda;
130     tBTA_ADDR_TYPE          remote_addr_type;
131     tBTA_GATTC_IF           client_if;
132     BOOLEAN                 is_direct;
133     BOOLEAN                 is_aux;
134     tBTA_TRANSPORT          transport;
135 } tBTA_GATTC_API_OPEN;
136 
137 typedef tBTA_GATTC_API_OPEN tBTA_GATTC_API_CANCEL_OPEN;
138 
139 typedef struct {
140     BT_HDR                  hdr;
141     tBTA_GATT_AUTH_REQ      auth_req;
142     UINT16                  handle;
143     UINT16                  s_handle;
144     UINT16                  e_handle;
145     tBT_UUID                uuid;
146     tBTA_GATTC_EVT          cmpl_evt;
147 } tBTA_GATTC_API_READ;
148 
149 typedef struct {
150     BT_HDR                  hdr;
151     tBTA_GATT_AUTH_REQ      auth_req;
152     UINT16                  handle;
153     tBTA_GATTC_EVT          cmpl_evt;
154     tBTA_GATTC_WRITE_TYPE   write_type;
155     UINT16                  offset;
156     UINT16                  len;
157     UINT8                   *p_value;
158 } tBTA_GATTC_API_WRITE;
159 
160 typedef struct {
161     BT_HDR                  hdr;
162     BOOLEAN                 is_execute;
163 } tBTA_GATTC_API_EXEC;
164 
165 typedef struct {
166     BT_HDR                  hdr;
167     UINT16                  handle;
168 } tBTA_GATTC_API_CONFIRM;
169 
170 typedef tGATT_CL_COMPLETE tBTA_GATTC_CMPL;
171 
172 typedef struct {
173     BT_HDR                  hdr;
174     UINT8                   op_code;
175     tGATT_STATUS            status;
176     tBTA_GATTC_CMPL         *p_cmpl;
177 } tBTA_GATTC_OP_CMPL;
178 
179 typedef struct {
180     BT_HDR              hdr;
181     tBT_UUID            *p_srvc_uuid;
182 } tBTA_GATTC_API_SEARCH;
183 
184 typedef struct {
185     BT_HDR                  hdr;
186     tBTA_GATT_AUTH_REQ      auth_req;
187     UINT8                   num_attr;
188     UINT16                  handles[GATT_MAX_READ_MULTI_HANDLES];
189     tBTA_GATTC_EVT          cmpl_evt;
190 }tBTA_GATTC_API_READ_MULTI;
191 
192 typedef struct {
193     BT_HDR                  hdr;
194     BD_ADDR_PTR             remote_bda;
195     tBTA_GATTC_IF           client_if;
196     BOOLEAN                 start;
197 } tBTA_GATTC_API_LISTEN;
198 
199 
200 typedef struct {
201     BT_HDR              hdr;
202 } tBTA_GATTC_API_CFG_MTU;
203 
204 typedef struct {
205     BT_HDR             hdr;
206     tBTA_GATTC_IF      client_if;
207     BD_ADDR            src_addr;
208     BD_ADDR            assoc_addr;
209     BOOLEAN            is_assoc;
210 } tBTA_GATTC_API_CACHE_ASSOC;
211 
212 typedef struct {
213     BT_HDR             hdr;
214     tBTA_GATTC_IF      client_if;
215 } tBTA_GATTC_API_GET_ADDR;
216 
217 typedef struct {
218     BT_HDR                  hdr;
219     BD_ADDR                 remote_bda;
220     tBTA_GATTC_IF           client_if;
221     UINT8                   role;
222     tBT_TRANSPORT           transport;
223     tGATT_DISCONN_REASON    reason;
224     BOOLEAN                 already_connect;
225     tBTA_GATT_CONN_PARAMS   conn_params;
226 } tBTA_GATTC_INT_CONN;
227 
228 typedef struct {
229     BT_HDR                  hdr;
230     BD_ADDR                 remote_bda;
231     tBTA_GATTC_IF           client_if;
232 } tBTA_GATTC_ENC_CMPL;
233 
234 typedef union {
235     BT_HDR                      hdr;
236     tBTA_GATTC_API_REG          api_reg;
237     tBTA_GATTC_API_DEREG        api_dereg;
238     tBTA_GATTC_API_OPEN         api_conn;
239     tBTA_GATTC_API_CANCEL_OPEN  api_cancel_conn;
240     tBTA_GATTC_API_READ         api_read;
241     tBTA_GATTC_API_SEARCH       api_search;
242     tBTA_GATTC_API_WRITE        api_write;
243     tBTA_GATTC_API_CONFIRM      api_confirm;
244     tBTA_GATTC_API_EXEC         api_exec;
245     tBTA_GATTC_API_READ_MULTI   api_read_multi;
246     tBTA_GATTC_API_CFG_MTU      api_mtu;
247     tBTA_GATTC_API_CACHE_ASSOC  api_assoc;
248     tBTA_GATTC_API_GET_ADDR     api_get_addr;
249     tBTA_GATTC_OP_CMPL          op_cmpl;
250     tBTA_GATTC_INT_CONN         int_conn;
251     tBTA_GATTC_ENC_CMPL         enc_cmpl;
252 
253     tBTA_GATTC_INT_START_IF     int_start_if;
254     tBTA_GATTC_INT_DEREG        int_dereg;
255     /* if peripheral role is supported */
256     tBTA_GATTC_API_LISTEN       api_listen;
257 
258 } tBTA_GATTC_DATA;
259 
260 
261 /* GATT server cache on the client */
262 typedef struct {
263     tBT_UUID            uuid;
264     UINT16              s_handle;
265     UINT16              e_handle;
266     // this field is set only for characteristic
267     UINT16              char_decl_handle;
268     BOOLEAN             is_primary;
269     tBTA_GATT_CHAR_PROP property;
270 } tBTA_GATTC_ATTR_REC;
271 
272 
273 #define BTA_GATTC_MAX_CACHE_CHAR    40
274 #define BTA_GATTC_ATTR_LIST_SIZE    (BTA_GATTC_MAX_CACHE_CHAR * sizeof(tBTA_GATTC_ATTR_REC))
275 
276 #ifndef BTA_GATTC_CACHE_SRVR_SIZE
277 #define BTA_GATTC_CACHE_SRVR_SIZE   600
278 #endif
279 
280 enum {
281     BTA_GATTC_IDLE_ST = 0,      /* Idle  */
282     BTA_GATTC_W4_CONN_ST,       /* Wait for connection -  (optional) */
283     BTA_GATTC_CONN_ST,          /* connected state */
284     BTA_GATTC_DISCOVER_ST       /* discover is in progress */
285 };
286 typedef UINT8 tBTA_GATTC_STATE;
287 
288 typedef struct {
289     BOOLEAN             in_use;
290     BD_ADDR             server_bda;
291     BOOLEAN             connected;
292 
293 #define BTA_GATTC_SERV_IDLE     0
294 #define BTA_GATTC_SERV_LOAD     1
295 #define BTA_GATTC_SERV_SAVE     2
296 #define BTA_GATTC_SERV_DISC     3
297 #define BTA_GATTC_SERV_DISC_ACT 4
298 
299     UINT8               state;
300 
301     list_t              *p_srvc_cache;  /* list of tBTA_GATTC_SERVICE */
302     UINT8               update_count;   /* indication received */
303     UINT8               num_clcb;       /* number of associated CLCB */
304 
305 
306     tBTA_GATTC_ATTR_REC *p_srvc_list;
307     UINT8               cur_srvc_idx;
308     UINT8               cur_char_idx;
309     UINT8               next_avail_idx;
310     UINT8               total_srvc;
311     UINT8               total_char;
312     UINT16              total_attr;
313     UINT8               srvc_hdl_chg;   /* service handle change indication pending */
314     UINT16              attr_index;     /* cahce NV saving/loading attribute index */
315 
316     UINT16              mtu;
317     bool                update_incl_srvc;
318 } tBTA_GATTC_SERV;
319 
320 #ifndef BTA_GATTC_NOTIF_REG_MAX
321 #define BTA_GATTC_NOTIF_REG_MAX     7//15
322 #endif
323 
324 typedef struct {
325     BOOLEAN             in_use;
326     BD_ADDR             remote_bda;
327     UINT16              handle;
328 }tBTA_GATTC_NOTIF_REG;
329 
330 typedef struct {
331     tBTA_GATTC_CBACK        *p_cback;
332     BOOLEAN                 in_use;
333     tBTA_GATTC_IF           client_if;      /* client interface with BTE stack for this application */
334     UINT8                   num_clcb;       /* number of associated CLCB */
335     BOOLEAN                 dereg_pending;
336     tBT_UUID                app_uuid;
337     tBTA_GATTC_NOTIF_REG    notif_reg[BTA_GATTC_NOTIF_REG_MAX];
338 } tBTA_GATTC_RCB;
339 
340 /* client channel is a mapping between a BTA client(cl_id) and a remote BD address */
341 typedef struct {
342     UINT16              bta_conn_id;    /* client channel ID, unique for clcb */
343     BD_ADDR             bda;
344     tBTA_TRANSPORT      transport;      /* channel transport */
345     tBTA_GATTC_RCB      *p_rcb;         /* pointer to the registration CB */
346     tBTA_GATTC_SERV     *p_srcb;    /* server cache CB */
347     tBTA_GATTC_DATA     *p_q_cmd;   /* command in queue waiting for execution */
348     list_t              *p_cmd_list; /* The list to store the command to be sent */
349     BOOLEAN             is_full;     /* The gattc command queue is full or not */
350 #define BTA_GATTC_NO_SCHEDULE       0
351 #define BTA_GATTC_DISC_WAITING      0x01
352 #define BTA_GATTC_REQ_WAITING       0x10
353 
354     UINT8               auto_update; /* auto update is waiting */
355     BOOLEAN             disc_active;
356     BOOLEAN             in_use;
357     tBTA_GATTC_STATE    state;
358     tBTA_GATT_STATUS    status;
359     UINT16              reason;
360     UINT8               searched_service_source;
361 } tBTA_GATTC_CLCB;
362 
363 /* background connection tracking information */
364 #if GATT_MAX_APPS <= 8
365 typedef UINT8 tBTA_GATTC_CIF_MASK ;
366 #elif GATT_MAX_APPS <= 16
367 typedef UINT16 tBTA_GATTC_CIF_MASK;
368 #elif GATT_MAX_APPS <= 32
369 typedef UINT32 tBTA_GATTC_CIF_MASK;
370 #endif
371 
372 typedef struct {
373     BOOLEAN                 in_use;
374     BD_ADDR                 remote_bda;
375     tBTA_GATTC_CIF_MASK     cif_mask;
376     tBTA_GATTC_CIF_MASK     cif_adv_mask;
377 
378 } tBTA_GATTC_BG_TCK;
379 
380 typedef struct {
381     BOOLEAN             in_use;
382     BD_ADDR             remote_bda;
383     UINT16              svc_change_descr_handle;
384     BOOLEAN             write_remote_svc_change_ccc_done;
385 } tBTA_GATTC_CONN;
386 
387 enum {
388     BTA_GATTC_STATE_DISABLED,
389     BTA_GATTC_STATE_ENABLING,
390     BTA_GATTC_STATE_ENABLED,
391     BTA_GATTC_STATE_DISABLING
392 };
393 
394 typedef struct {
395     UINT8               state;
396     tBTA_GATTC_CONN     conn_track[BTA_GATTC_CONN_MAX];
397     tBTA_GATTC_BG_TCK   bg_track[BTA_GATTC_KNOWN_SR_MAX];
398     tBTA_GATTC_RCB      cl_rcb[BTA_GATTC_CL_MAX];
399 
400     tBTA_GATTC_CLCB     clcb[BTA_GATTC_CLCB_MAX];
401     tBTA_GATTC_SERV     known_server[BTA_GATTC_KNOWN_SR_MAX];
402 }tBTA_GATTC_CB;
403 
404 typedef enum {
405     SERVICE_CHANGE_CCC_WRITTEN_SUCCESS = 0,
406     SERVICE_CHANGE_CACHE_NOT_FOUND,
407     SERVICE_CHANGE_SERVICE_NOT_FOUND,
408     SERVICE_CHANGE_CHAR_NOT_FOUND,
409     SERVICE_CHANGE_CCC_NOT_FOUND,
410     SERVICE_CHANGE_WRITE_CCC_FAILED
411 }tBTA_GATTC_FIND_SERVICE_CB;
412 
413 
414 /*****************************************************************************
415 **  Global data
416 *****************************************************************************/
417 
418 /* GATTC control block */
419 #if BTA_DYNAMIC_MEMORY == FALSE
420 extern tBTA_GATTC_CB  bta_gattc_cb;
421 #else
422 extern tBTA_GATTC_CB *bta_gattc_cb_ptr;
423 #define bta_gattc_cb (*bta_gattc_cb_ptr)
424 #endif
425 
426 /*****************************************************************************
427 **  Function prototypes
428 *****************************************************************************/
429 extern BOOLEAN bta_gattc_hdl_event(BT_HDR *p_msg);
430 extern BOOLEAN bta_gattc_sm_execute(tBTA_GATTC_CLCB *p_clcb, UINT16 event, tBTA_GATTC_DATA *p_data);
431 
432 /* function processed outside SM */
433 extern void bta_gattc_disable(tBTA_GATTC_CB *p_cb);
434 extern void bta_gattc_register(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_data);
435 extern void bta_gattc_start_if(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_data);
436 extern void bta_gattc_process_api_open (tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_msg);
437 extern void bta_gattc_process_api_open_cancel (tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_msg);
438 extern void bta_gattc_deregister(tBTA_GATTC_CB *p_cb, tBTA_GATTC_RCB  *p_clreg);
439 extern void bta_gattc_process_enc_cmpl(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_msg);
440 
441 /* function within state machine */
442 extern void bta_gattc_open(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data);
443 extern void bta_gattc_open_fail(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data);
444 extern void bta_gattc_open_error(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data);
445 
446 extern void bta_gattc_cancel_open(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data);
447 extern void bta_gattc_cancel_open_ok(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data);
448 extern void bta_gattc_cancel_open_error(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data);
449 
450 extern void bta_gattc_conn(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data);
451 extern void bta_gattc_conncback(tBTA_GATTC_RCB *p_rcb, tBTA_GATTC_DATA *p_data);
452 extern void bta_gattc_disconncback(tBTA_GATTC_RCB *p_rcb, tBTA_GATTC_DATA *p_data);
453 extern void bta_gattc_close(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data);
454 extern void bta_gattc_close_fail(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data);
455 extern void bta_gattc_disc_close(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data);
456 
457 extern void bta_gattc_start_discover(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data);
458 extern void bta_gattc_disc_cmpl(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data);
459 extern void bta_gattc_read(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data);
460 extern void bta_gattc_read_by_type(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data);
461 extern void bta_gattc_write(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data);
462 extern void bta_gattc_op_cmpl(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data);
463 extern void bta_gattc_q_cmd(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data);
464 extern void bta_gattc_free_command_data(tBTA_GATTC_CLCB *p_clcb);
465 extern void bta_gattc_search(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data);
466 extern void bta_gattc_fail(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data);
467 extern void bta_gattc_confirm(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data);
468 extern void bta_gattc_execute(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data);
469 extern void bta_gattc_read_multi(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data);
470 extern void bta_gattc_ci_open(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data);
471 extern void bta_gattc_ci_close(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data);
472 extern void bta_gattc_ignore_op_cmpl(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data);
473 extern void bta_gattc_restart_discover(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_msg);
474 extern void bta_gattc_init_bk_conn(tBTA_GATTC_API_OPEN *p_data, tBTA_GATTC_RCB *p_clreg);
475 extern void bta_gattc_cancel_bk_conn(tBTA_GATTC_API_CANCEL_OPEN *p_data);
476 extern void bta_gattc_send_open_cback( tBTA_GATTC_RCB *p_clreg, tBTA_GATT_STATUS status,
477                                        BD_ADDR remote_bda, UINT16 conn_id, tBTA_TRANSPORT transport,  UINT16 mtu);
478 extern void bta_gattc_send_connect_cback( tBTA_GATTC_RCB *p_clreg, BD_ADDR remote_bda, UINT16 conn_id, tBTA_GATT_CONN_PARAMS conn_params, UINT8 link_role);
479 extern void bta_gattc_send_disconnect_cback( tBTA_GATTC_RCB *p_clreg, tGATT_DISCONN_REASON reason,
480                                 BD_ADDR remote_bda, UINT16 conn_id);
481 extern void bta_gattc_process_api_refresh(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_msg);
482 extern void bta_gattc_process_api_cache_clean(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_msg);
483 extern void bta_gattc_process_api_cache_assoc(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_msg);
484 extern void bta_gattc_process_api_cache_get_addr_list(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_msg);
485 extern void bta_gattc_cfg_mtu(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data);
486 #if BLE_INCLUDED == TRUE
487 extern void bta_gattc_listen(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_msg);
488 extern void bta_gattc_broadcast(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_msg);
489 #endif
490 /* utility functions */
491 extern tBTA_GATTC_CLCB *bta_gattc_find_clcb_by_cif (UINT8 client_if, BD_ADDR remote_bda, tBTA_TRANSPORT transport);
492 extern tBTA_GATTC_CLCB *bta_gattc_find_clcb_by_conn_id (UINT16 conn_id);
493 extern tBTA_GATTC_CLCB *bta_gattc_clcb_alloc(tBTA_GATTC_IF client_if, BD_ADDR remote_bda, tBTA_TRANSPORT transport);
494 extern void bta_gattc_clcb_dealloc(tBTA_GATTC_CLCB *p_clcb);
495 extern tBTA_GATTC_CLCB *bta_gattc_find_alloc_clcb(tBTA_GATTC_IF client_if, BD_ADDR remote_bda, tBTA_TRANSPORT transport);
496 extern tBTA_GATTC_RCB *bta_gattc_cl_get_regcb(UINT8 client_if);
497 extern tBTA_GATTC_SERV *bta_gattc_find_srcb(BD_ADDR bda);
498 extern tBTA_GATTC_SERV *bta_gattc_srcb_alloc(BD_ADDR bda);
499 extern tBTA_GATTC_SERV *bta_gattc_find_scb_by_cid (UINT16 conn_id);
500 extern tBTA_GATTC_CLCB *bta_gattc_find_int_conn_clcb(tBTA_GATTC_DATA *p_msg);
501 extern tBTA_GATTC_CLCB *bta_gattc_find_int_disconn_clcb(tBTA_GATTC_DATA *p_msg);
502 
503 extern BOOLEAN bta_gattc_enqueue(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data);
504 
505 extern BOOLEAN bta_gattc_uuid_compare (const tBT_UUID *p_src, const tBT_UUID *p_tar, BOOLEAN is_precise);
506 extern BOOLEAN bta_gattc_check_notif_registry(tBTA_GATTC_RCB  *p_clreg, tBTA_GATTC_SERV *p_srcb, tBTA_GATTC_NOTIFY  *p_notify);
507 extern BOOLEAN bta_gattc_mark_bg_conn (tBTA_GATTC_IF client_if,  BD_ADDR_PTR remote_bda, BOOLEAN add, BOOLEAN is_listen);
508 extern BOOLEAN bta_gattc_check_bg_conn (tBTA_GATTC_IF client_if,  BD_ADDR remote_bda, UINT8 role);
509 extern UINT8 bta_gattc_num_reg_app(void);
510 extern void bta_gattc_clear_notif_registration(tBTA_GATTC_SERV *p_srcb, UINT16 conn_id, UINT16 start_handle, UINT16 end_handle);
511 extern void bta_gattc_clear_notif_registration_by_bda(tBTA_GATTC_RCB *p_clrcb, BD_ADDR remote_bda);
512 extern tBTA_GATTC_SERV * bta_gattc_find_srvr_cache(BD_ADDR bda);
513 
514 /* discovery functions */
515 extern void bta_gattc_disc_res_cback (UINT16 conn_id, tGATT_DISC_TYPE disc_type, tGATT_DISC_RES *p_data);
516 extern void bta_gattc_disc_cmpl_cback (UINT16 conn_id, tGATT_DISC_TYPE disc_type, tGATT_STATUS status);
517 extern tBTA_GATT_STATUS bta_gattc_discover_procedure(UINT16 conn_id, tBTA_GATTC_SERV *p_server_cb, UINT8 disc_type);
518 extern tBTA_GATT_STATUS bta_gattc_discover_pri_service(UINT16 conn_id, tBTA_GATTC_SERV *p_server_cb, UINT8 disc_type);
519 extern void bta_gattc_search_service(tBTA_GATTC_CLCB *p_clcb, tBT_UUID *p_uuid);
520 extern const list_t* bta_gattc_get_services(UINT16 conn_id);
521 extern const tBTA_GATTC_SERVICE* bta_gattc_get_service_for_handle(UINT16 conn_id, UINT16 handle);
522 tBTA_GATTC_CHARACTERISTIC*  bta_gattc_get_characteristic_srcb(tBTA_GATTC_SERV *p_srcb, UINT16 handle);
523 extern tBTA_GATTC_CHARACTERISTIC* bta_gattc_get_characteristic(UINT16 conn_id, UINT16 handle);
524 extern tBTA_GATTC_DESCRIPTOR* bta_gattc_get_descriptor(UINT16 conn_id, UINT16 handle);
525 extern void bta_gattc_get_db_size_handle(UINT16 conn_id, UINT16 start_handle, UINT16 end_handle, UINT16 *count);
526 extern void bta_gattc_get_db_size_with_type_handle(UINT16 conn_id, bt_gatt_db_attribute_type_t type,
527                                                    UINT16 start_handle, UINT16 end_handle, UINT16 char_handle, UINT16 *count);
528 extern void bta_gattc_get_service_with_uuid(UINT16 conn_id, tBT_UUID *svc_uuid,
529                                             btgatt_db_element_t **svc_db,
530                                             UINT16 *count);
531 
532 extern void bta_gattc_get_db_with_opration(UINT16 conn_id,
533                                                       bt_gatt_get_db_op_t op,
534                                                       UINT16 char_handle,
535                                                       tBT_UUID *incl_uuid,
536                                                       tBT_UUID *char_uuid,
537                                                       tBT_UUID *descr_uuid,
538                                                       UINT16 start_handle, UINT16 end_handle,
539                                                       btgatt_db_element_t **char_db,
540                                                       UINT16 *count);
541 
542 extern void bta_gattc_get_gatt_db(UINT16 conn_id, UINT16 start_handle, UINT16 end_handle, btgatt_db_element_t **db, UINT16 *count);
543 
544 extern tBTA_GATT_STATUS bta_gattc_init_cache(tBTA_GATTC_SERV *p_srvc_cb);
545 extern void bta_gattc_rebuild_cache(tBTA_GATTC_SERV *p_srcv, UINT16 num_attr, tBTA_GATTC_NV_ATTR *attr);
546 extern void bta_gattc_cache_save(tBTA_GATTC_SERV *p_srvc_cb, UINT16 conn_id);
547 extern void bta_gattc_reset_discover_st(tBTA_GATTC_SERV *p_srcb, tBTA_GATT_STATUS status);
548 
549 extern tBTA_GATTC_CONN *bta_gattc_conn_alloc(BD_ADDR remote_bda);
550 extern tBTA_GATTC_CONN *bta_gattc_conn_find(BD_ADDR remote_bda);
551 extern tBTA_GATTC_CONN *bta_gattc_conn_find_alloc(BD_ADDR remote_bda);
552 extern BOOLEAN bta_gattc_conn_dealloc(BD_ADDR remote_bda);
553 
554 extern bool bta_gattc_cache_load(tBTA_GATTC_CLCB *p_clcb);
555 extern void bta_gattc_cache_reset(BD_ADDR server_bda);
556 extern void bta_gattc_deinit(void);
557 
558 #endif /* BTA_GATTC_INT_H */
559