• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  *  Copyright 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 <base/functional/callback_forward.h>
29 #include <base/strings/stringprintf.h>
30 
31 #include <list>
32 #include <string>
33 #include <vector>
34 
35 #include "bta/gatt/database.h"
36 #include "stack/include/gatt_api.h"
37 #include "types/bluetooth/uuid.h"
38 #include "types/raw_address.h"
39 
40 #ifndef BTA_GATT_DEBUG
41 #define BTA_GATT_DEBUG false
42 #endif
43 
44 /*****************************************************************************
45  *  Constants and data types
46  ****************************************************************************/
47 /**************************
48  *  Common Definitions
49  **************************/
50 /* GATT ID */
51 typedef struct {
52   bluetooth::Uuid uuid; /* uuid of the attribute */
53   uint8_t inst_id;      /* instance ID */
54 } __attribute__((packed)) tBTA_GATT_ID;
55 
56 /* Client callback function events */
57 typedef enum : uint8_t {
58   BTA_GATTC_DEREG_EVT = 1,          /* GATT client deregistered event */
59   BTA_GATTC_OPEN_EVT = 2,           /* GATTC open request status  event */
60   BTA_GATTC_CLOSE_EVT = 5,          /* GATTC  close request status event */
61   BTA_GATTC_SEARCH_CMPL_EVT = 6,    /* GATT discovery complete event */
62   BTA_GATTC_SEARCH_RES_EVT = 7,     /* GATT discovery result event */
63   BTA_GATTC_SRVC_DISC_DONE_EVT = 8, /* GATT service discovery done event */
64   BTA_GATTC_NOTIF_EVT = 10,         /* GATT attribute notification event */
65   BTA_GATTC_EXEC_EVT = 12,          /* execute write complete event */
66   BTA_GATTC_ACL_EVT = 13,           /* ACL up event */
67   BTA_GATTC_CANCEL_OPEN_EVT = 14,   /* cancel open event */
68   BTA_GATTC_SRVC_CHG_EVT = 15,      /* service change event */
69   BTA_GATTC_ENC_CMPL_CB_EVT = 17,   /* encryption complete callback event */
70   BTA_GATTC_CFG_MTU_EVT = 18,       /* configure MTU complete event */
71   BTA_GATTC_CONGEST_EVT = 24,       /* Congestion event */
72   BTA_GATTC_PHY_UPDATE_EVT = 25,    /* PHY change event */
73   BTA_GATTC_CONN_UPDATE_EVT = 26,   /* Connection parameters update event */
74   BTA_GATTC_SUBRATE_CHG_EVT = 27,   /* Subrate Change event */
75 } tBTA_GATTC_EVT;
76 
77 #define CASE_RETURN_TEXT(code) \
78   case code:                   \
79     return #code
80 
gatt_client_event_text(const tBTA_GATTC_EVT & event)81 inline std::string gatt_client_event_text(const tBTA_GATTC_EVT& event) {
82   switch (event) {
83     CASE_RETURN_TEXT(BTA_GATTC_DEREG_EVT);
84     CASE_RETURN_TEXT(BTA_GATTC_OPEN_EVT);
85     CASE_RETURN_TEXT(BTA_GATTC_CLOSE_EVT);
86     CASE_RETURN_TEXT(BTA_GATTC_SEARCH_CMPL_EVT);
87     CASE_RETURN_TEXT(BTA_GATTC_SEARCH_RES_EVT);
88     CASE_RETURN_TEXT(BTA_GATTC_SRVC_DISC_DONE_EVT);
89     CASE_RETURN_TEXT(BTA_GATTC_NOTIF_EVT);
90     CASE_RETURN_TEXT(BTA_GATTC_EXEC_EVT);
91     CASE_RETURN_TEXT(BTA_GATTC_ACL_EVT);
92     CASE_RETURN_TEXT(BTA_GATTC_CANCEL_OPEN_EVT);
93     CASE_RETURN_TEXT(BTA_GATTC_SRVC_CHG_EVT);
94     CASE_RETURN_TEXT(BTA_GATTC_ENC_CMPL_CB_EVT);
95     CASE_RETURN_TEXT(BTA_GATTC_CFG_MTU_EVT);
96     CASE_RETURN_TEXT(BTA_GATTC_CONGEST_EVT);
97     CASE_RETURN_TEXT(BTA_GATTC_PHY_UPDATE_EVT);
98     CASE_RETURN_TEXT(BTA_GATTC_CONN_UPDATE_EVT);
99     CASE_RETURN_TEXT(BTA_GATTC_SUBRATE_CHG_EVT);
100     default:
101       return base::StringPrintf("UNKNOWN[%hhu]", event);
102   }
103 }
104 #undef CASE_RETURN_TEXT
105 
106 typedef struct {
107   uint16_t unit;  /* as UUIUD defined by SIG */
108   uint16_t descr; /* as UUID as defined by SIG */
109   tGATT_FORMAT format;
110   int8_t exp;
111   uint8_t name_spc; /* The name space of the description */
112 } tBTA_GATT_CHAR_PRES;
113 
114 /* Characteristic Aggregate Format attribute value
115  */
116 #define BTA_GATT_AGGR_HANDLE_NUM_MAX 10
117 typedef struct {
118   uint8_t num_handle;
119   uint16_t handle_list[BTA_GATT_AGGR_HANDLE_NUM_MAX];
120 } tBTA_GATT_CHAR_AGGRE;
121 
122 typedef struct {
123   uint16_t len;
124   uint8_t* p_value;
125 } tBTA_GATT_UNFMT;
126 
127 typedef struct {
128   uint8_t num_attr;
129   uint16_t handles[GATT_MAX_READ_MULTI_HANDLES];
130 } tBTA_GATTC_MULTI;
131 
132 /* callback data structure */
133 typedef struct {
134   tGATT_STATUS status;
135   tGATT_IF client_if;
136 } tBTA_GATTC_REG;
137 
138 typedef struct {
139   uint16_t conn_id;
140   tGATT_STATUS status;
141   uint16_t handle;
142   uint16_t len;
143   uint8_t value[GATT_MAX_ATTR_LEN];
144 } tBTA_GATTC_READ;
145 
146 typedef struct {
147   uint16_t conn_id;
148   tGATT_STATUS status;
149   uint16_t handle;
150 } tBTA_GATTC_WRITE;
151 
152 typedef struct {
153   uint16_t conn_id;
154   tGATT_STATUS status;
155 } tBTA_GATTC_EXEC_CMPL;
156 
157 typedef struct {
158   uint16_t conn_id;
159   tGATT_STATUS status;
160 } tBTA_GATTC_SEARCH_CMPL;
161 
162 typedef struct {
163   uint16_t conn_id;
164   tBTA_GATT_ID service_uuid;
165 } tBTA_GATTC_SRVC_RES;
166 
167 typedef struct {
168   uint16_t conn_id;
169   tGATT_STATUS status;
170   uint16_t mtu;
171 } tBTA_GATTC_CFG_MTU;
172 
173 typedef struct {
174   tGATT_STATUS status;
175   uint16_t conn_id;
176   tGATT_IF client_if;
177   RawAddress remote_bda;
178   tBT_TRANSPORT transport;
179   uint16_t mtu;
180 } tBTA_GATTC_OPEN;
181 
182 typedef struct {
183   uint16_t conn_id;
184   tGATT_STATUS status;
185   tGATT_IF client_if;
186   RawAddress remote_bda;
187   tGATT_DISCONN_REASON reason;
188 } tBTA_GATTC_CLOSE;
189 
190 typedef struct {
191   uint16_t conn_id;
192   RawAddress bda;
193   uint16_t handle;
194   uint16_t len;
195   uint8_t value[GATT_MAX_ATTR_LEN];
196   bool is_notify;
197   uint16_t cid;
198 } tBTA_GATTC_NOTIFY;
199 
200 typedef struct {
201   uint16_t conn_id;
202   bool congested; /* congestion indicator */
203 } tBTA_GATTC_CONGEST;
204 
205 typedef struct {
206   tGATT_STATUS status;
207   tGATT_IF client_if;
208   uint16_t conn_id;
209   RawAddress remote_bda;
210 } tBTA_GATTC_OPEN_CLOSE;
211 
212 typedef struct {
213   tGATT_IF client_if;
214   RawAddress remote_bda;
215 } tBTA_GATTC_ENC_CMPL_CB;
216 
217 typedef struct {
218   tGATT_IF server_if;
219   uint16_t conn_id;
220   uint8_t tx_phy;
221   uint8_t rx_phy;
222   tGATT_STATUS status;
223 } tBTA_GATTC_PHY_UPDATE;
224 
225 typedef struct {
226   tGATT_IF server_if;
227   uint16_t conn_id;
228   uint16_t interval;
229   uint16_t latency;
230   uint16_t timeout;
231   tGATT_STATUS status;
232 } tBTA_GATTC_CONN_UPDATE;
233 
234 typedef struct {
235   RawAddress remote_bda;
236   uint16_t conn_id;
237 } tBTA_GATTC_SERVICE_CHANGED;
238 
239 typedef struct {
240   tGATT_IF server_if;
241   uint16_t conn_id;
242   uint16_t subrate_factor;
243   uint16_t latency;
244   uint16_t cont_num;
245   uint16_t timeout;
246   tGATT_STATUS status;
247 } tBTA_GATTC_SUBRATE_CHG;
248 
249 typedef union {
250   tGATT_STATUS status;
251 
252   tBTA_GATTC_SEARCH_CMPL search_cmpl; /* discovery complete */
253   tBTA_GATTC_SRVC_RES srvc_res;       /* discovery result */
254   tBTA_GATTC_REG reg_oper;            /* registration data */
255   tBTA_GATTC_OPEN open;
256   tBTA_GATTC_CLOSE close;
257   tBTA_GATTC_READ read;           /* read attribute/descriptor data */
258   tBTA_GATTC_WRITE write;         /* write complete data */
259   tBTA_GATTC_EXEC_CMPL exec_cmpl; /*  execute complete */
260   tBTA_GATTC_NOTIFY notify;       /* notification/indication event data */
261   tBTA_GATTC_ENC_CMPL_CB enc_cmpl;
262   RawAddress remote_bda;      /* service change event */
263   tBTA_GATTC_CFG_MTU cfg_mtu; /* configure MTU operation */
264   tBTA_GATTC_CONGEST congest;
265   tBTA_GATTC_PHY_UPDATE phy_update;
266   tBTA_GATTC_CONN_UPDATE conn_update;
267   tBTA_GATTC_SERVICE_CHANGED service_changed;
268   tBTA_GATTC_SUBRATE_CHG subrate_chg;
269 } tBTA_GATTC;
270 
271 /* GATTC enable callback function */
272 typedef void(tBTA_GATTC_ENB_CBACK)(tGATT_STATUS status);
273 
274 /* Client callback function */
275 typedef void(tBTA_GATTC_CBACK)(tBTA_GATTC_EVT event, tBTA_GATTC* p_data);
276 
277 /* GATT Server Data Structure */
278 /* Server callback function events */
279 #define BTA_GATTS_REG_EVT 0
280 #define BTA_GATTS_READ_CHARACTERISTIC_EVT \
281   GATTS_REQ_TYPE_READ_CHARACTERISTIC                                 /* 1 */
282 #define BTA_GATTS_READ_DESCRIPTOR_EVT GATTS_REQ_TYPE_READ_DESCRIPTOR /* 2 */
283 #define BTA_GATTS_WRITE_CHARACTERISTIC_EVT \
284   GATTS_REQ_TYPE_WRITE_CHARACTERISTIC                                  /* 3 */
285 #define BTA_GATTS_WRITE_DESCRIPTOR_EVT GATTS_REQ_TYPE_WRITE_DESCRIPTOR /* 4 */
286 #define BTA_GATTS_EXEC_WRITE_EVT GATTS_REQ_TYPE_WRITE_EXEC             /* 5 */
287 #define BTA_GATTS_MTU_EVT GATTS_REQ_TYPE_MTU                           /* 6 */
288 #define BTA_GATTS_CONF_EVT GATTS_REQ_TYPE_CONF                         /* 7 */
289 #define BTA_GATTS_DEREG_EVT 8
290 #define BTA_GATTS_DELELTE_EVT 11
291 #define BTA_GATTS_STOP_EVT 13
292 #define BTA_GATTS_CONNECT_EVT 14
293 #define BTA_GATTS_DISCONNECT_EVT 15
294 #define BTA_GATTS_OPEN_EVT 16
295 #define BTA_GATTS_CANCEL_OPEN_EVT 17
296 #define BTA_GATTS_CLOSE_EVT 18
297 #define BTA_GATTS_CONGEST_EVT 20
298 #define BTA_GATTS_PHY_UPDATE_EVT 21
299 #define BTA_GATTS_CONN_UPDATE_EVT 22
300 #define BTA_GATTS_SUBRATE_CHG_EVT 23
301 
302 typedef uint8_t tBTA_GATTS_EVT;
303 
304 #define BTA_GATTS_INVALID_APP 0xff
305 
306 #define BTA_GATTS_INVALID_IF 0
307 
308 #ifndef BTA_GATTC_CHAR_DESCR_MAX
309 #define BTA_GATTC_CHAR_DESCR_MAX 7
310 #endif
311 
312 /***********************  NV callback Data Definitions   **********************
313  */
314 typedef struct {
315   bluetooth::Uuid app_uuid128;
316   bluetooth::Uuid svc_uuid;
317   uint16_t svc_inst;
318   uint16_t s_handle;
319   uint16_t e_handle;
320   bool is_primary; /* primary service or secondary */
321 } tBTA_GATTS_HNDL_RANGE;
322 
323 typedef struct {
324   tGATT_STATUS status;
325   RawAddress remote_bda;
326   uint32_t trans_id;
327   uint16_t conn_id;
328   tGATTS_DATA* p_data;
329 } tBTA_GATTS_REQ;
330 
331 typedef struct {
332   tGATT_IF server_if;
333   tGATT_STATUS status;
334   bluetooth::Uuid uuid;
335 } tBTA_GATTS_REG_OPER;
336 
337 typedef struct {
338   tGATT_IF server_if;
339   uint16_t service_id;
340   uint16_t svc_instance;
341   bool is_primary;
342   tGATT_STATUS status;
343   bluetooth::Uuid uuid;
344 } tBTA_GATTS_CREATE;
345 
346 typedef struct {
347   tGATT_IF server_if;
348   uint16_t service_id;
349   tGATT_STATUS status;
350 } tBTA_GATTS_SRVC_OPER;
351 
352 typedef struct {
353   tGATT_IF server_if;
354   RawAddress remote_bda;
355   uint16_t conn_id;
356   tBT_TRANSPORT transport;
357 } tBTA_GATTS_CONN;
358 
359 typedef struct {
360   uint16_t conn_id;
361   bool congested; /* report channel congestion indicator */
362 } tBTA_GATTS_CONGEST;
363 
364 typedef struct {
365   uint16_t conn_id;        /* connection ID */
366   tGATT_STATUS status;     /* notification/indication status */
367 } tBTA_GATTS_CONF;
368 
369 typedef struct {
370   tGATT_IF server_if;
371   uint16_t conn_id;
372   uint8_t tx_phy;
373   uint8_t rx_phy;
374   tGATT_STATUS status;
375 } tBTA_GATTS_PHY_UPDATE;
376 
377 typedef struct {
378   tGATT_IF server_if;
379   uint16_t conn_id;
380   uint16_t interval;
381   uint16_t latency;
382   uint16_t timeout;
383   tGATT_STATUS status;
384 } tBTA_GATTS_CONN_UPDATE;
385 
386 typedef struct {
387   tGATT_IF server_if;
388   uint16_t conn_id;
389   uint16_t subrate_factor;
390   uint16_t latency;
391   uint16_t cont_num;
392   uint16_t timeout;
393   tGATT_STATUS status;
394 } tBTA_GATTS_SUBRATE_CHG;
395 
396 /* GATTS callback data */
397 typedef union {
398   tBTA_GATTS_REG_OPER reg_oper;
399   tBTA_GATTS_CREATE create;
400   tBTA_GATTS_SRVC_OPER srvc_oper;
401   tGATT_STATUS status; /* BTA_GATTS_LISTEN_EVT */
402   tBTA_GATTS_REQ req_data;
403   tBTA_GATTS_CONN conn;             /* BTA_GATTS_CONN_EVT */
404   tBTA_GATTS_CONGEST congest;       /* BTA_GATTS_CONGEST_EVT callback data */
405   tBTA_GATTS_CONF confirm;          /* BTA_GATTS_CONF_EVT callback data */
406   tBTA_GATTS_PHY_UPDATE phy_update; /* BTA_GATTS_PHY_UPDATE_EVT callback data */
407   tBTA_GATTS_CONN_UPDATE
408       conn_update; /* BTA_GATTS_CONN_UPDATE_EVT callback data */
409   tBTA_GATTS_SUBRATE_CHG subrate_chg; /* BTA_GATTS_SUBRATE_CHG_EVT */
410 } tBTA_GATTS;
411 
412 /* GATTS enable callback function */
413 typedef void(tBTA_GATTS_ENB_CBACK)(tGATT_STATUS status);
414 
415 /* Server callback function */
416 typedef void(tBTA_GATTS_CBACK)(tBTA_GATTS_EVT event, tBTA_GATTS* p_data);
417 
418 /*****************************************************************************
419  *  External Function Declarations
420  ****************************************************************************/
421 
422 /**************************
423  *  Client Functions
424  **************************/
425 
426 /*******************************************************************************
427  *
428  * Function         BTA_GATTC_Disable
429  *
430  * Description      This function is called to disable the GATTC module
431  *
432  * Parameters       None.
433  *
434  * Returns          None
435  *
436  ******************************************************************************/
437 void BTA_GATTC_Disable(void);
438 
439 using BtaAppRegisterCallback =
440     base::Callback<void(uint8_t /* app_id */, uint8_t /* status */)>;
441 
442 /**
443  * This function is called to register application callbacks with BTA GATTC
444  *module.
445  * p_client_cb - pointer to the application callback function.
446  **/
447 void BTA_GATTC_AppRegister(tBTA_GATTC_CBACK* p_client_cb,
448                            BtaAppRegisterCallback cb, bool eatt_support);
449 
450 /*******************************************************************************
451  *
452  * Function         BTA_GATTC_AppDeregister
453  *
454  * Description      This function is called to deregister an application
455  *                  from BTA GATTC module.
456  *
457  * Parameters       client_if - client interface identifier.
458  *
459  * Returns          None
460  *
461  ******************************************************************************/
462 void BTA_GATTC_AppDeregister(tGATT_IF client_if);
463 
464 /*******************************************************************************
465  *
466  * Function         BTA_GATTC_Open
467  *
468  * Description      Open a direct connection or add a background auto connection
469  *                  bd address
470  *
471  * Parameters       client_if: server interface.
472  *                  remote_bda: remote device BD address.
473  *                  connection_type: connection type used for the peer device
474  *                  initiating_phys: LE PHY to use, optional
475  *
476  ******************************************************************************/
477 void BTA_GATTC_Open(tGATT_IF client_if, const RawAddress& remote_bda,
478                     tBTM_BLE_CONN_TYPE connection_type, bool opportunistic);
479 void BTA_GATTC_Open(tGATT_IF client_if, const RawAddress& remote_bda,
480                     tBTM_BLE_CONN_TYPE connection_type, tBT_TRANSPORT transport,
481                     bool opportunistic, uint8_t initiating_phys);
482 void BTA_GATTC_Open(tGATT_IF client_if, const RawAddress& remote_bda,
483                     tBLE_ADDR_TYPE addr_type,
484                     tBTM_BLE_CONN_TYPE connection_type, tBT_TRANSPORT transport,
485                     bool opportunistic, uint8_t initiating_phys);
486 
487 /*******************************************************************************
488  *
489  * Function         BTA_GATTC_CancelOpen
490  *
491  * Description      Open a direct connection or add a background auto connection
492  *                  bd address
493  *
494  * Parameters       client_if: server interface.
495  *                  remote_bda: remote device BD address.
496  *                  is_direct: direct connection or background auto connection
497  *
498  * Returns          void
499  *
500  ******************************************************************************/
501 void BTA_GATTC_CancelOpen(tGATT_IF client_if, const RawAddress& remote_bda,
502                           bool is_direct);
503 
504 /*******************************************************************************
505  *
506  * Function         BTA_GATTC_Close
507  *
508  * Description      Close a connection to a GATT server.
509  *
510  * Parameters       conn_id: connectino ID to be closed.
511  *
512  * Returns          void
513  *
514  ******************************************************************************/
515 void BTA_GATTC_Close(uint16_t conn_id);
516 
517 /*******************************************************************************
518  *
519  * Function         BTA_GATTC_ServiceSearchRequest
520  *
521  * Description      This function is called to request a GATT service discovery
522  *                  on a GATT server. This function report service search result
523  *                  by a callback event, and followed by a service search
524  *                  complete event.
525  *
526  * Parameters       conn_id: connection ID.
527  *                  p_srvc_uuid: a UUID of the service application is interested
528  *                               in. If Null, discover for all services.
529  *
530  * Returns          None
531  *
532  ******************************************************************************/
533 void BTA_GATTC_ServiceSearchRequest(uint16_t conn_id,
534                                     const bluetooth::Uuid* p_srvc_uuid);
535 
536 /**
537  * This function is called to send "Find service by UUID" request. Used only for
538  * PTS tests.
539  */
540 void BTA_GATTC_DiscoverServiceByUuid(uint16_t conn_id,
541                                      const bluetooth::Uuid& srvc_uuid);
542 
543 /*******************************************************************************
544  *
545  * Function         BTA_GATTC_GetServices
546  *
547  * Description      This function is called to find the services on the given
548  *                  server.
549  *
550  * Parameters       conn_id: connection ID which identify the server.
551  *
552  * Returns          returns list of gatt::Service or NULL.
553  *
554  ******************************************************************************/
555 const std::list<gatt::Service>* BTA_GATTC_GetServices(uint16_t conn_id);
556 
557 /*******************************************************************************
558  *
559  * Function         BTA_GATTC_GetCharacteristic
560  *
561  * Description      This function is called to find the characteristic on the
562  *                  given server.
563  *
564  * Parameters       conn_id: connection ID which identify the server.
565  *                  handle: characteristic handle
566  *
567  * Returns          returns pointer to gatt::Characteristic or NULL.
568  *
569  ******************************************************************************/
570 const gatt::Characteristic* BTA_GATTC_GetCharacteristic(uint16_t conn_id,
571                                                         uint16_t handle);
572 
573 /*******************************************************************************
574  *
575  * Function         BTA_GATTC_GetDescriptor
576  *
577  * Description      This function is called to find the characteristic on the
578  *                  given server.
579  *
580  * Parameters       conn_id: connection ID which identify the server.
581  *                  handle: descriptor handle
582  *
583  * Returns          returns pointer to gatt::Descriptor or NULL.
584  *
585  ******************************************************************************/
586 const gatt::Descriptor* BTA_GATTC_GetDescriptor(uint16_t conn_id,
587                                                 uint16_t handle);
588 
589 /* Return characteristic that owns descriptor with handle equal to |handle|, or
590  * NULL */
591 const gatt::Characteristic* BTA_GATTC_GetOwningCharacteristic(uint16_t conn_id,
592                                                               uint16_t handle);
593 
594 /* Return service that owns descriptor or characteristic with handle equal to
595  * |handle|, or NULL */
596 const gatt::Service* BTA_GATTC_GetOwningService(uint16_t conn_id,
597                                                 uint16_t handle);
598 
599 /*******************************************************************************
600  *
601  * Function         BTA_GATTC_GetGattDb
602  *
603  * Description      This function is called to get gatt db.
604  *
605  * Parameters       conn_id: connection ID which identify the server.
606  *                  db: output parameter which will contain gatt db copy.
607  *                      Caller is responsible for freeing it.
608  *                  count: number of elements in db.
609  *
610  ******************************************************************************/
611 void BTA_GATTC_GetGattDb(uint16_t conn_id, uint16_t start_handle,
612                          uint16_t end_handle, btgatt_db_element_t** db,
613                          int* count);
614 
615 typedef void (*GATT_READ_OP_CB)(uint16_t conn_id, tGATT_STATUS status,
616                                 uint16_t handle, uint16_t len, uint8_t* value,
617                                 void* data);
618 typedef void (*GATT_WRITE_OP_CB)(uint16_t conn_id, tGATT_STATUS status,
619                                  uint16_t handle, uint16_t len,
620                                  const uint8_t* value, void* data);
621 typedef void (*GATT_CONFIGURE_MTU_OP_CB)(uint16_t conn_id, tGATT_STATUS status,
622                                          void* data);
623 
624 /*******************************************************************************
625  *
626  * Function         BTA_GATTC_ReadCharacteristic
627  *
628  * Description      This function is called to read a characteristics value
629  *
630  * Parameters       conn_id - connectino ID.
631  *                  handle - characteritic handle to read.
632  *
633  * Returns          None
634  *
635  ******************************************************************************/
636 void BTA_GATTC_ReadCharacteristic(uint16_t conn_id, uint16_t handle,
637                                   tGATT_AUTH_REQ auth_req,
638                                   GATT_READ_OP_CB callback, void* cb_data);
639 
640 /**
641  * This function is called to read a value of characteristic with uuid equal to
642  * |uuid|
643  */
644 void BTA_GATTC_ReadUsingCharUuid(uint16_t conn_id, const bluetooth::Uuid& uuid,
645                                  uint16_t s_handle, uint16_t e_handle,
646                                  tGATT_AUTH_REQ auth_req,
647                                  GATT_READ_OP_CB callback, void* cb_data);
648 
649 /*******************************************************************************
650  *
651  * Function         BTA_GATTC_ReadCharDescr
652  *
653  * Description      This function is called to read a descriptor value.
654  *
655  * Parameters       conn_id - connection ID.
656  *                  handle - descriptor handle to read.
657  *
658  * Returns          None
659  *
660  ******************************************************************************/
661 void BTA_GATTC_ReadCharDescr(uint16_t conn_id, uint16_t handle,
662                              tGATT_AUTH_REQ auth_req, GATT_READ_OP_CB callback,
663                              void* cb_data);
664 
665 /*******************************************************************************
666  *
667  * Function         BTA_GATTC_WriteCharValue
668  *
669  * Description      This function is called to write characteristic value.
670  *
671  * Parameters       conn_id - connection ID.
672  *                  handle - characteristic handle to write.
673  *                  write_type - type of write.
674  *                  value - the value to be written.
675  *
676  * Returns          None
677  *
678  ******************************************************************************/
679 void BTA_GATTC_WriteCharValue(uint16_t conn_id, uint16_t handle,
680                               tGATT_WRITE_TYPE write_type,
681                               std::vector<uint8_t> value,
682                               tGATT_AUTH_REQ auth_req,
683                               GATT_WRITE_OP_CB callback, void* cb_data);
684 
685 /*******************************************************************************
686  *
687  * Function         BTA_GATTC_WriteCharDescr
688  *
689  * Description      This function is called to write descriptor value.
690  *
691  * Parameters       conn_id - connection ID
692  *                  handle - descriptor handle to write.
693  *                  value - the value to be written.
694  *
695  * Returns          None
696  *
697  ******************************************************************************/
698 void BTA_GATTC_WriteCharDescr(uint16_t conn_id, uint16_t handle,
699                               std::vector<uint8_t> value,
700                               tGATT_AUTH_REQ auth_req,
701                               GATT_WRITE_OP_CB callback, void* cb_data);
702 
703 /*******************************************************************************
704  *
705  * Function         BTA_GATTC_SendIndConfirm
706  *
707  * Description      This function is called to send handle value confirmation.
708  *
709  * Parameters       conn_id - connection ID.
710  *                  cid - channel id
711  *
712  * Returns          None
713  *
714  ******************************************************************************/
715 void BTA_GATTC_SendIndConfirm(uint16_t conn_id, uint16_t cid);
716 
717 /*******************************************************************************
718  *
719  * Function         BTA_GATTC_RegisterForNotifications
720  *
721  * Description      This function is called to register for notification of a
722  *                  service.
723  *
724  * Parameters       client_if - client interface.
725  *                  remote_bda - target GATT server.
726  *                  handle - GATT characteristic handle.
727  *
728  * Returns          OK if registration succeed, otherwise failed.
729  *
730  ******************************************************************************/
731 tGATT_STATUS BTA_GATTC_RegisterForNotifications(tGATT_IF client_if,
732                                                 const RawAddress& remote_bda,
733                                                 uint16_t handle);
734 
735 /*******************************************************************************
736  *
737  * Function         BTA_GATTC_DeregisterForNotifications
738  *
739  * Description      This function is called to de-register for notification of a
740  *                  service.
741  *
742  * Parameters       client_if - client interface.
743  *                  remote_bda - target GATT server.
744  *                  handle - GATT characteristic handle.
745  *
746  * Returns          OK if deregistration succeed, otherwise failed.
747  *
748  ******************************************************************************/
749 tGATT_STATUS BTA_GATTC_DeregisterForNotifications(tGATT_IF client_if,
750                                                   const RawAddress& remote_bda,
751                                                   uint16_t handle);
752 
753 /*******************************************************************************
754  *
755  * Function         BTA_GATTC_PrepareWrite
756  *
757  * Description      This function is called to prepare write a characteristic
758  *                  value.
759  *
760  * Parameters       conn_id - connection ID.
761  *                  handle - GATT characteritic handle.
762  *                  offset - offset of the write value.
763  *                  value - the value to be written.
764  *
765  * Returns          None
766  *
767  ******************************************************************************/
768 void BTA_GATTC_PrepareWrite(uint16_t conn_id, uint16_t handle, uint16_t offset,
769                             std::vector<uint8_t> value, tGATT_AUTH_REQ auth_req,
770                             GATT_WRITE_OP_CB callback, void* cb_data);
771 
772 /*******************************************************************************
773  *
774  * Function         BTA_GATTC_ExecuteWrite
775  *
776  * Description      This function is called to execute write a prepare write
777  *                  sequence.
778  *
779  * Parameters       conn_id - connection ID.
780  *                    is_execute - execute or cancel.
781  *
782  * Returns          None
783  *
784  ******************************************************************************/
785 void BTA_GATTC_ExecuteWrite(uint16_t conn_id, bool is_execute);
786 
787 /*******************************************************************************
788  *
789  * Function         BTA_GATTC_ReadMultiple
790  *
791  * Description      This function is called to read multiple characteristic or
792  *                  characteristic descriptors.
793  *
794  * Parameters       conn_id - connectino ID.
795  *                    p_read_multi - read multiple parameters.
796  *
797  * Returns          None
798  *
799  ******************************************************************************/
800 void BTA_GATTC_ReadMultiple(uint16_t conn_id, tBTA_GATTC_MULTI* p_read_multi,
801                             tGATT_AUTH_REQ auth_req);
802 
803 /*******************************************************************************
804  *
805  * Function         BTA_GATTC_Refresh
806  *
807  * Description      Refresh the server cache of the remote device
808  *
809  * Parameters       remote_bda: remote device BD address.
810  *
811  * Returns          void
812  *
813  ******************************************************************************/
814 void BTA_GATTC_Refresh(const RawAddress& remote_bda);
815 
816 /*******************************************************************************
817  *
818  * Function         BTA_GATTC_ConfigureMTU
819  *
820  * Description      Configure the MTU size in the GATT channel. This can be done
821  *                  only once per connection.
822  *
823  * Parameters       conn_id: connection ID.
824  *                  mtu: desired MTU size to use.
825  *
826  * Returns          void
827  *
828  ******************************************************************************/
829 void BTA_GATTC_ConfigureMTU(uint16_t conn_id, uint16_t mtu);
830 void BTA_GATTC_ConfigureMTU(uint16_t conn_id, uint16_t mtu,
831                             GATT_CONFIGURE_MTU_OP_CB callback, void* cb_data);
832 
833 /*******************************************************************************
834  *  BTA GATT Server API
835  ******************************************************************************/
836 
837 /*******************************************************************************
838  *
839  * Function         BTA_GATTS_Init
840  *
841  * Description      This function is called to initalize GATTS module
842  *
843  * Parameters       None
844  *
845  * Returns          None
846  *
847  ******************************************************************************/
848 void BTA_GATTS_Init();
849 
850 /*******************************************************************************
851  *
852  * Function         BTA_GATTS_Disable
853  *
854  * Description      This function is called to disable GATTS module
855  *
856  * Parameters       None.
857  *
858  * Returns          None
859  *
860  ******************************************************************************/
861 void BTA_GATTS_Disable(void);
862 
863 /*******************************************************************************
864  *
865  * Function         BTA_GATTS_AppRegister
866  *
867  * Description      This function is called to register application callbacks
868  *                    with BTA GATTS module.
869  *
870  * Parameters       p_app_uuid - applicaiton UUID
871  *                  p_cback - pointer to the application callback function.
872  *                  eatt_support: indicate eatt support.
873  *
874  * Returns          None
875  *
876  ******************************************************************************/
877 void BTA_GATTS_AppRegister(const bluetooth::Uuid& app_uuid,
878                            tBTA_GATTS_CBACK* p_cback, bool eatt_support);
879 
880 /*******************************************************************************
881  *
882  * Function         BTA_GATTS_AppDeregister
883  *
884  * Description      De-register with BTA GATT Server.
885  *
886  * Parameters       server_if: server interface
887  *
888  * Returns          void
889  *
890  ******************************************************************************/
891 void BTA_GATTS_AppDeregister(tGATT_IF server_if);
892 
893 /*******************************************************************************
894  *
895  * Function         BTA_GATTS_AddService
896  *
897  * Description      Add the given |service| and all included elements to the
898  *                  GATT database. a |BTA_GATTS_ADD_SRVC_EVT| is triggered to
899  *                  report the status and attribute handles.
900  *
901  * Parameters       server_if: server interface.
902  *                  service: pointer to vector describing service.
903  *
904  * Returns          Returns |GATT_SUCCESS| on success or |GATT_ERROR| if the
905  *                  service cannot be added.
906  *
907  ******************************************************************************/
908 typedef base::Callback<void(tGATT_STATUS status, int server_if,
909                             std::vector<btgatt_db_element_t> service)>
910     BTA_GATTS_AddServiceCb;
911 
912 void BTA_GATTS_AddService(tGATT_IF server_if,
913                           std::vector<btgatt_db_element_t> service,
914                           BTA_GATTS_AddServiceCb cb);
915 
916 /*******************************************************************************
917  *
918  * Function         BTA_GATTS_DeleteService
919  *
920  * Description      This function is called to delete a service. When this is
921  *                  done, a callback event BTA_GATTS_DELETE_EVT is report with
922  *                  the status.
923  *
924  * Parameters       service_id: service_id to be deleted.
925  *
926  * Returns          returns none.
927  *
928  ******************************************************************************/
929 void BTA_GATTS_DeleteService(uint16_t service_id);
930 
931 /*******************************************************************************
932  *
933  * Function         BTA_GATTS_StopService
934  *
935  * Description      This function is called to stop a service.
936  *
937  * Parameters       service_id - service to be topped.
938  *
939  * Returns          None
940  *
941  ******************************************************************************/
942 void BTA_GATTS_StopService(uint16_t service_id);
943 
944 /*******************************************************************************
945  *
946  * Function         BTA_GATTS_HandleValueIndication
947  *
948  * Description      This function is called to read a characteristics
949  *                  descriptor.
950  *
951  * Parameters       conn_id - connection identifier.
952  *                  attr_id - attribute ID to indicate.
953  *                  value - data to indicate.
954  *                  need_confirm - if this indication expects a confirmation or
955  *                                 not.
956  *
957  * Returns          None
958  *
959  ******************************************************************************/
960 void BTA_GATTS_HandleValueIndication(uint16_t conn_id, uint16_t attr_id,
961                                      std::vector<uint8_t> value,
962                                      bool need_confirm);
963 
964 /*******************************************************************************
965  *
966  * Function         BTA_GATTS_SendRsp
967  *
968  * Description      This function is called to send a response to a request.
969  *
970  * Parameters       conn_id - connection identifier.
971  *                  trans_id - transaction ID.
972  *                  status - response status
973  *                  p_msg - response data.
974  *
975  * Returns          None
976  *
977  ******************************************************************************/
978 void BTA_GATTS_SendRsp(uint16_t conn_id, uint32_t trans_id, tGATT_STATUS status,
979                        tGATTS_RSP* p_msg);
980 
981 /*******************************************************************************
982  *
983  * Function         BTA_GATTS_Open
984  *
985  * Description      Open a direct open connection or add a background auto
986  *                  connection bd address
987  *
988  * Parameters       server_if: server interface.
989  *                  remote_bda: remote device BD address.
990  *                  is_direct: direct connection or background auto connection
991  *
992  * Returns          void
993  *
994  ******************************************************************************/
995 void BTA_GATTS_Open(tGATT_IF server_if, const RawAddress& remote_bda,
996                     bool is_direct, tBT_TRANSPORT transport);
997 
998 /*******************************************************************************
999  *
1000  * Function         BTA_GATTS_CancelOpen
1001  *
1002  * Description      Cancel a direct open connection or remove a background auto
1003  *                  connection bd address
1004  *
1005  * Parameters       server_if: server interface.
1006  *                  remote_bda: remote device BD address.
1007  *                  is_direct: direct connection or background auto connection
1008  *
1009  * Returns          void
1010  *
1011  ******************************************************************************/
1012 void BTA_GATTS_CancelOpen(tGATT_IF server_if, const RawAddress& remote_bda,
1013                           bool is_direct);
1014 
1015 /*******************************************************************************
1016  *
1017  * Function         BTA_GATTS_Close
1018  *
1019  * Description      Close a connection  a remote device.
1020  *
1021  * Parameters       conn_id: connectino ID to be closed.
1022  *
1023  * Returns          void
1024  *
1025  ******************************************************************************/
1026 void BTA_GATTS_Close(uint16_t conn_id);
1027 
1028 // Adds bonded device for GATT server tracking service changes
1029 void BTA_GATTS_InitBonded(void);
1030 
1031 #endif /* BTA_GATT_API_H */
1032