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