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