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