bta_gattc_api.cc revision ebf5f477572aef8f59acd0796391a858d1ec290a
1/****************************************************************************** 2 * 3 * Copyright (C) 2010-2012 Broadcom Corporation 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at: 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 ******************************************************************************/ 18 19/****************************************************************************** 20 * 21 * This is the implementation of the API for GATT module of BTA. 22 * 23 ******************************************************************************/ 24 25#include "bt_target.h" 26 27#if (BTA_GATT_INCLUDED == TRUE) 28 29#include <string.h> 30#include "bt_common.h" 31#include "bta_sys.h" 32#include "bta_gatt_api.h" 33#include "bta_gattc_int.h" 34 35/***************************************************************************** 36** Constants 37*****************************************************************************/ 38 39static const tBTA_SYS_REG bta_gattc_reg = 40{ 41 bta_gattc_hdl_event, 42 BTA_GATTC_Disable 43}; 44 45 46/******************************************************************************* 47** 48** Function BTA_GATTC_Disable 49** 50** Description This function is called to disable GATTC module 51** 52** Parameters None. 53** 54** Returns None 55** 56*******************************************************************************/ 57void BTA_GATTC_Disable(void) 58{ 59 if (bta_sys_is_register(BTA_ID_GATTC) == false) 60 { 61 APPL_TRACE_WARNING("GATTC Module not enabled/already disabled"); 62 return; 63 } 64 65 BT_HDR *p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR)); 66 p_buf->event = BTA_GATTC_API_DISABLE_EVT; 67 68 bta_sys_sendmsg(p_buf); 69 bta_sys_deregister(BTA_ID_GATTC); 70} 71 72/******************************************************************************* 73** 74** Function BTA_GATTC_AppRegister 75** 76** Description This function is called to register application callbacks 77** with BTA GATTC module. 78** 79** Parameters p_app_uuid - applicaiton UUID 80** p_client_cb - pointer to the application callback function. 81** 82** Returns None 83** 84*******************************************************************************/ 85void BTA_GATTC_AppRegister(tBT_UUID *p_app_uuid, tBTA_GATTC_CBACK *p_client_cb) 86{ 87 tBTA_GATTC_API_REG *p_buf = 88 (tBTA_GATTC_API_REG *)osi_malloc(sizeof(tBTA_GATTC_API_REG)); 89 90 if (bta_sys_is_register(BTA_ID_GATTC) == false) 91 bta_sys_register(BTA_ID_GATTC, &bta_gattc_reg); 92 93 p_buf->hdr.event = BTA_GATTC_API_REG_EVT; 94 if (p_app_uuid != NULL) 95 memcpy(&p_buf->app_uuid, p_app_uuid, sizeof(tBT_UUID)); 96 p_buf->p_cback = p_client_cb; 97 98 bta_sys_sendmsg(p_buf); 99} 100 101/******************************************************************************* 102** 103** Function BTA_GATTC_AppDeregister 104** 105** Description This function is called to deregister an application 106** from BTA GATTC module. 107** 108** Parameters client_if - client interface identifier. 109** 110** Returns None 111** 112*******************************************************************************/ 113void BTA_GATTC_AppDeregister(tBTA_GATTC_IF client_if) 114{ 115 tBTA_GATTC_API_DEREG *p_buf = 116 (tBTA_GATTC_API_DEREG *)osi_malloc(sizeof(tBTA_GATTC_API_DEREG)); 117 118 p_buf->hdr.event = BTA_GATTC_API_DEREG_EVT; 119 p_buf->client_if = client_if; 120 121 bta_sys_sendmsg(p_buf); 122} 123 124/******************************************************************************* 125** 126** Function BTA_GATTC_Open 127** 128** Description Open a direct connection or add a background auto connection 129** bd address 130** 131** Parameters client_if: server interface. 132** remote_bda: remote device BD address. 133** is_direct: direct connection or background auto connection 134** transport: Transport to be used for GATT connection (BREDR/LE) 135** 136** Returns void 137** 138*******************************************************************************/ 139void BTA_GATTC_Open(tBTA_GATTC_IF client_if, BD_ADDR remote_bda, 140 bool is_direct, tBTA_GATT_TRANSPORT transport) 141{ 142 tBTA_GATTC_API_OPEN *p_buf = 143 (tBTA_GATTC_API_OPEN *) osi_malloc(sizeof(tBTA_GATTC_API_OPEN)); 144 145 p_buf->hdr.event = BTA_GATTC_API_OPEN_EVT; 146 p_buf->client_if = client_if; 147 p_buf->is_direct = is_direct; 148 p_buf->transport = transport; 149 memcpy(p_buf->remote_bda, remote_bda, BD_ADDR_LEN); 150 151 bta_sys_sendmsg(p_buf); 152} 153 154/******************************************************************************* 155** 156** Function BTA_GATTC_CancelOpen 157** 158** Description Cancel a direct open connection or remove a background auto connection 159** bd address 160** 161** Parameters client_if: server interface. 162** remote_bda: remote device BD address. 163** is_direct: direct connection or background auto connection 164** 165** Returns void 166** 167*******************************************************************************/ 168void BTA_GATTC_CancelOpen(tBTA_GATTC_IF client_if, BD_ADDR remote_bda, bool is_direct) 169{ 170 tBTA_GATTC_API_CANCEL_OPEN *p_buf = 171 (tBTA_GATTC_API_CANCEL_OPEN *)osi_malloc(sizeof(tBTA_GATTC_API_CANCEL_OPEN)); 172 173 p_buf->hdr.event = BTA_GATTC_API_CANCEL_OPEN_EVT; 174 p_buf->client_if = client_if; 175 p_buf->is_direct = is_direct; 176 memcpy(p_buf->remote_bda, remote_bda, BD_ADDR_LEN); 177 178 bta_sys_sendmsg(p_buf); 179} 180 181/******************************************************************************* 182** 183** Function BTA_GATTC_Close 184** 185** Description Close a connection to a GATT server. 186** 187** Parameters conn_id: connectino ID to be closed. 188** 189** Returns void 190** 191*******************************************************************************/ 192void BTA_GATTC_Close(uint16_t conn_id) 193{ 194 BT_HDR *p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR)); 195 196 p_buf->event = BTA_GATTC_API_CLOSE_EVT; 197 p_buf->layer_specific = conn_id; 198 199 bta_sys_sendmsg(p_buf); 200} 201 202/******************************************************************************* 203** 204** Function BTA_GATTC_ConfigureMTU 205** 206** Description Configure the MTU size in the GATT channel. This can be done 207** only once per connection. 208** 209** Parameters conn_id: connection ID. 210** mtu: desired MTU size to use. 211** 212** Returns void 213** 214*******************************************************************************/ 215void BTA_GATTC_ConfigureMTU (uint16_t conn_id, uint16_t mtu) 216{ 217 tBTA_GATTC_API_CFG_MTU *p_buf = 218 (tBTA_GATTC_API_CFG_MTU *)osi_malloc(sizeof(tBTA_GATTC_API_CFG_MTU)); 219 220 p_buf->hdr.event = BTA_GATTC_API_CFG_MTU_EVT; 221 p_buf->hdr.layer_specific = conn_id; 222 p_buf->mtu = mtu; 223 224 bta_sys_sendmsg(p_buf); 225} 226 227/******************************************************************************* 228** 229** Function BTA_GATTC_ServiceSearchRequest 230** 231** Description This function is called to request a GATT service discovery 232** on a GATT server. This function report service search result 233** by a callback event, and followed by a service search complete 234** event. 235** 236** Parameters conn_id: connection ID. 237** p_srvc_uuid: a UUID of the service application is interested in. 238** If Null, discover for all services. 239** 240** Returns None 241** 242*******************************************************************************/ 243void BTA_GATTC_ServiceSearchRequest (uint16_t conn_id, tBT_UUID *p_srvc_uuid) 244{ 245 const size_t len = sizeof(tBTA_GATTC_API_SEARCH) + sizeof(tBT_UUID); 246 tBTA_GATTC_API_SEARCH *p_buf = (tBTA_GATTC_API_SEARCH *)osi_calloc(len); 247 248 p_buf->hdr.event = BTA_GATTC_API_SEARCH_EVT; 249 p_buf->hdr.layer_specific = conn_id; 250 if (p_srvc_uuid) { 251 p_buf->p_srvc_uuid = (tBT_UUID *)(p_buf + 1); 252 memcpy(p_buf->p_srvc_uuid, p_srvc_uuid, sizeof(tBT_UUID)); 253 } else { 254 p_buf->p_srvc_uuid = NULL; 255 } 256 257 bta_sys_sendmsg(p_buf); 258} 259 260/******************************************************************************* 261** 262** Function BTA_GATTC_GetServices 263** 264** Description This function is called to find the services on the given server. 265** 266** Parameters conn_id: connection ID which identify the server. 267** 268** Returns returns list_t of tBTA_GATTC_SERVICE or NULL. 269** 270*******************************************************************************/ 271const list_t* BTA_GATTC_GetServices(uint16_t conn_id) { 272 return bta_gattc_get_services(conn_id); 273} 274 275/******************************************************************************* 276** 277** Function BTA_GATTC_GetCharacteristic 278** 279** Description This function is called to find the characteristic on the given server. 280** 281** Parameters conn_id - connection ID which identify the server. 282** handle - characteristic handle 283** 284** Returns returns pointer to tBTA_GATTC_CHARACTERISTIC or NULL. 285** 286*******************************************************************************/ 287const tBTA_GATTC_CHARACTERISTIC* BTA_GATTC_GetCharacteristic(uint16_t conn_id, uint16_t handle) { 288 return bta_gattc_get_characteristic(conn_id, handle); 289} 290 291/******************************************************************************* 292** 293** Function BTA_GATTC_GetDescriptor 294** 295** Description This function is called to find the characteristic on the given server. 296** 297** Parameters conn_id - connection ID which identify the server. 298** handle - descriptor handle 299** 300** Returns returns pointer to tBTA_GATTC_DESCRIPTOR or NULL. 301** 302*******************************************************************************/ 303const tBTA_GATTC_DESCRIPTOR* BTA_GATTC_GetDescriptor(uint16_t conn_id, uint16_t handle) { 304 return bta_gattc_get_descriptor(conn_id, handle); 305} 306 307/******************************************************************************* 308** 309** Function BTA_GATTC_GetGattDb 310** 311** Description This function is called to get the GATT database. 312** 313** Parameters conn_id: connection ID which identify the server. 314** db: output parameter which will contain the GATT database copy. 315** Caller is responsible for freeing it. 316** count: number of elements in database. 317** 318*******************************************************************************/ 319void BTA_GATTC_GetGattDb(uint16_t conn_id, uint16_t start_handle, uint16_t end_handle, 320 btgatt_db_element_t **db, int *count) 321{ 322 bta_gattc_get_gatt_db(conn_id, start_handle, end_handle, db, count); 323} 324 325/******************************************************************************* 326** 327** Function BTA_GATTC_ReadCharacteristic 328** 329** Description This function is called to read a characteristics value 330** 331** Parameters conn_id - connection ID. 332** handle - characteritic handle to read. 333** 334** Returns None 335** 336*******************************************************************************/ 337void BTA_GATTC_ReadCharacteristic(uint16_t conn_id, uint16_t handle, tBTA_GATT_AUTH_REQ auth_req, 338 GATT_READ_OP_CB callback, void* cb_data) 339{ 340 tBTA_GATTC_API_READ *p_buf = 341 (tBTA_GATTC_API_READ *)osi_calloc(sizeof(tBTA_GATTC_API_READ)); 342 343 p_buf->hdr.event = BTA_GATTC_API_READ_EVT; 344 p_buf->hdr.layer_specific = conn_id; 345 p_buf->auth_req = auth_req; 346 p_buf->handle = handle; 347 p_buf->read_cb = callback; 348 p_buf->read_cb_data = cb_data; 349 350 bta_sys_sendmsg(p_buf); 351} 352 353/******************************************************************************* 354** 355** Function BTA_GATTC_ReadCharDescr 356** 357** Description This function is called to read a descriptor value. 358** 359** Parameters conn_id - connection ID. 360** handle - descriptor handle to read. 361** 362** Returns None 363** 364*******************************************************************************/ 365void BTA_GATTC_ReadCharDescr(uint16_t conn_id, uint16_t handle, tBTA_GATT_AUTH_REQ auth_req, 366 GATT_READ_OP_CB callback, void* cb_data) 367{ 368 tBTA_GATTC_API_READ *p_buf = 369 (tBTA_GATTC_API_READ *)osi_calloc(sizeof(tBTA_GATTC_API_READ)); 370 371 p_buf->hdr.event = BTA_GATTC_API_READ_EVT; 372 p_buf->hdr.layer_specific = conn_id; 373 p_buf->auth_req = auth_req; 374 p_buf->handle = handle; 375 p_buf->read_cb = callback; 376 p_buf->read_cb_data = cb_data; 377 378 bta_sys_sendmsg(p_buf); 379} 380 381/******************************************************************************* 382** 383** Function BTA_GATTC_ReadMultiple 384** 385** Description This function is called to read multiple characteristic or 386** characteristic descriptors. 387** 388** Parameters conn_id - connectino ID. 389** p_read_multi - pointer to the read multiple parameter. 390** 391** Returns None 392** 393*******************************************************************************/ 394void BTA_GATTC_ReadMultiple(uint16_t conn_id, tBTA_GATTC_MULTI *p_read_multi, 395 tBTA_GATT_AUTH_REQ auth_req) 396{ 397 tBTA_GATTC_API_READ_MULTI *p_buf = 398 (tBTA_GATTC_API_READ_MULTI *)osi_calloc(sizeof(tBTA_GATTC_API_READ_MULTI)); 399 400 p_buf->hdr.event = BTA_GATTC_API_READ_MULTI_EVT; 401 p_buf->hdr.layer_specific = conn_id; 402 p_buf->auth_req = auth_req; 403 p_buf->num_attr = p_read_multi->num_attr; 404 405 if (p_buf->num_attr > 0) 406 memcpy(p_buf->handles, p_read_multi->handles, sizeof(uint16_t) * p_read_multi->num_attr); 407 408 bta_sys_sendmsg(p_buf); 409} 410 411/******************************************************************************* 412** 413** Function BTA_GATTC_WriteCharValue 414** 415** Description This function is called to write characteristic value. 416** 417** Parameters conn_id - connection ID. 418** handle - characteristic handle to write. 419** write_type - type of write. 420** value - the value to be written. 421** 422** Returns None 423** 424*******************************************************************************/ 425void BTA_GATTC_WriteCharValue ( uint16_t conn_id, 426 uint16_t handle, 427 tBTA_GATTC_WRITE_TYPE write_type, 428 std::vector<uint8_t> value, 429 tBTA_GATT_AUTH_REQ auth_req, 430 GATT_WRITE_OP_CB callback, 431 void* cb_data) 432{ 433 tBTA_GATTC_API_WRITE *p_buf = (tBTA_GATTC_API_WRITE *) 434 osi_calloc(sizeof(tBTA_GATTC_API_WRITE) + value.size()); 435 436 p_buf->hdr.event = BTA_GATTC_API_WRITE_EVT; 437 p_buf->hdr.layer_specific = conn_id; 438 p_buf->auth_req = auth_req; 439 p_buf->handle = handle; 440 p_buf->write_type = write_type; 441 p_buf->len = value.size(); 442 p_buf->write_cb = callback; 443 p_buf->write_cb_data = cb_data; 444 445 if (value.size() > 0) { 446 p_buf->p_value = (uint8_t *)(p_buf + 1); 447 memcpy(p_buf->p_value, value.data(), value.size()); 448 } 449 450 bta_sys_sendmsg(p_buf); 451} 452 453/******************************************************************************* 454** 455** Function BTA_GATTC_WriteCharDescr 456** 457** Description This function is called to write descriptor value. 458** 459** Parameters conn_id - connection ID 460** handle - descriptor hadle to write. 461** value - the value to be written. 462** 463** Returns None 464** 465*******************************************************************************/ 466void BTA_GATTC_WriteCharDescr (uint16_t conn_id, 467 uint16_t handle, 468 std::vector<uint8_t> value, 469 tBTA_GATT_AUTH_REQ auth_req, 470 GATT_WRITE_OP_CB callback, 471 void* cb_data) 472{ 473 tBTA_GATTC_API_WRITE *p_buf = (tBTA_GATTC_API_WRITE *) 474 osi_calloc(sizeof(tBTA_GATTC_API_WRITE) + value.size()); 475 476 p_buf->hdr.event = BTA_GATTC_API_WRITE_EVT; 477 p_buf->hdr.layer_specific = conn_id; 478 p_buf->auth_req = auth_req; 479 p_buf->handle = handle; 480 p_buf->write_type = BTA_GATTC_TYPE_WRITE; 481 p_buf->write_cb = callback; 482 p_buf->write_cb_data = cb_data; 483 484 if (value.size() != 0) { 485 p_buf->p_value = (uint8_t *)(p_buf + 1); 486 p_buf->len = value.size(); 487 memcpy(p_buf->p_value, value.data(), value.size()); 488 } 489 490 bta_sys_sendmsg(p_buf); 491} 492 493/******************************************************************************* 494** 495** Function BTA_GATTC_PrepareWrite 496** 497** Description This function is called to prepare write a characteristic value. 498** 499** Parameters conn_id - connection ID. 500** p_char_id - GATT characteritic ID of the service. 501** offset - offset of the write value. 502** value - the value to be written. 503** 504** Returns None 505** 506*******************************************************************************/ 507void BTA_GATTC_PrepareWrite (uint16_t conn_id, uint16_t handle, uint16_t offset, 508 std::vector<uint8_t> value, 509 tBTA_GATT_AUTH_REQ auth_req, 510 GATT_WRITE_OP_CB callback, void* cb_data) 511{ 512 tBTA_GATTC_API_WRITE *p_buf = 513 (tBTA_GATTC_API_WRITE *)osi_calloc(sizeof(tBTA_GATTC_API_WRITE) + value.size()); 514 515 p_buf->hdr.event = BTA_GATTC_API_WRITE_EVT; 516 p_buf->hdr.layer_specific = conn_id; 517 p_buf->auth_req = auth_req; 518 p_buf->handle = handle; 519 p_buf->write_cb = callback; 520 p_buf->write_cb_data = cb_data; 521 522 p_buf->write_type = BTA_GATTC_WRITE_PREPARE; 523 p_buf->offset = offset; 524 p_buf->len = value.size(); 525 526 if (value.size() > 0) { 527 p_buf->p_value = (uint8_t *)(p_buf + 1); 528 memcpy(p_buf->p_value, value.data(), value.size()); 529 } 530 531 bta_sys_sendmsg(p_buf); 532} 533 534/******************************************************************************* 535** 536** Function BTA_GATTC_ExecuteWrite 537** 538** Description This function is called to execute write a prepare write sequence. 539** 540** Parameters conn_id - connection ID. 541** is_execute - execute or cancel. 542** 543** Returns None 544** 545*******************************************************************************/ 546void BTA_GATTC_ExecuteWrite (uint16_t conn_id, bool is_execute) 547{ 548 tBTA_GATTC_API_EXEC *p_buf = 549 (tBTA_GATTC_API_EXEC *)osi_calloc(sizeof(tBTA_GATTC_API_EXEC)); 550 551 p_buf->hdr.event = BTA_GATTC_API_EXEC_EVT; 552 p_buf->hdr.layer_specific = conn_id; 553 p_buf->is_execute = is_execute; 554 555 bta_sys_sendmsg(p_buf); 556} 557 558/******************************************************************************* 559** 560** Function BTA_GATTC_SendIndConfirm 561** 562** Description This function is called to send handle value confirmation. 563** 564** Parameters conn_id - connection ID. 565** p_char_id - characteristic ID to confirm. 566** 567** Returns None 568** 569*******************************************************************************/ 570void BTA_GATTC_SendIndConfirm (uint16_t conn_id, uint16_t handle) 571{ 572 tBTA_GATTC_API_CONFIRM *p_buf = 573 (tBTA_GATTC_API_CONFIRM *)osi_calloc(sizeof(tBTA_GATTC_API_CONFIRM)); 574 575 APPL_TRACE_API("%s conn_id=%d handle=0x%04x", __func__, conn_id, handle); 576 577 p_buf->hdr.event = BTA_GATTC_API_CONFIRM_EVT; 578 p_buf->hdr.layer_specific = conn_id; 579 p_buf->handle = handle; 580 581 bta_sys_sendmsg(p_buf); 582} 583 584/******************************************************************************* 585** 586** Function BTA_GATTC_RegisterForNotifications 587** 588** Description This function is called to register for notification of a service. 589** 590** Parameters client_if - client interface. 591** bda - target GATT server. 592** handle - GATT characteristic handle. 593** 594** Returns OK if registration succeed, otherwise failed. 595** 596*******************************************************************************/ 597tBTA_GATT_STATUS BTA_GATTC_RegisterForNotifications (tBTA_GATTC_IF client_if, 598 const BD_ADDR bda, uint16_t handle) 599{ 600 tBTA_GATTC_RCB *p_clreg; 601 tBTA_GATT_STATUS status = BTA_GATT_ILLEGAL_PARAMETER; 602 uint8_t i; 603 604 if (!handle) 605 { 606 APPL_TRACE_ERROR("deregistration failed, handle is 0"); 607 return status; 608 } 609 610 if ((p_clreg = bta_gattc_cl_get_regcb(client_if)) != NULL) 611 { 612 for (i = 0; i < BTA_GATTC_NOTIF_REG_MAX; i ++) 613 { 614 if ( p_clreg->notif_reg[i].in_use && 615 !memcmp(p_clreg->notif_reg[i].remote_bda, bda, BD_ADDR_LEN) && 616 p_clreg->notif_reg[i].handle == handle) 617 { 618 APPL_TRACE_WARNING("notification already registered"); 619 status = BTA_GATT_OK; 620 break; 621 } 622 } 623 if (status != BTA_GATT_OK) 624 { 625 for (i = 0; i < BTA_GATTC_NOTIF_REG_MAX; i ++) 626 { 627 if (!p_clreg->notif_reg[i].in_use) 628 { 629 memset((void *)&p_clreg->notif_reg[i], 0, sizeof(tBTA_GATTC_NOTIF_REG)); 630 631 p_clreg->notif_reg[i].in_use = true; 632 memcpy(p_clreg->notif_reg[i].remote_bda, bda, BD_ADDR_LEN); 633 634 p_clreg->notif_reg[i].handle = handle; 635 status = BTA_GATT_OK; 636 break; 637 } 638 } 639 if (i == BTA_GATTC_NOTIF_REG_MAX) 640 { 641 status = BTA_GATT_NO_RESOURCES; 642 APPL_TRACE_ERROR("Max Notification Reached, registration failed."); 643 } 644 } 645 } 646 else 647 { 648 APPL_TRACE_ERROR("Client_if: %d Not Registered", client_if); 649 } 650 651 return status; 652} 653 654/******************************************************************************* 655** 656** Function BTA_GATTC_DeregisterForNotifications 657** 658** Description This function is called to de-register for notification of a servbice. 659** 660** Parameters client_if - client interface. 661** remote_bda - target GATT server. 662** handle - GATT characteristic handle. 663** 664** Returns OK if deregistration succeed, otherwise failed. 665** 666*******************************************************************************/ 667tBTA_GATT_STATUS BTA_GATTC_DeregisterForNotifications (tBTA_GATTC_IF client_if, 668 const BD_ADDR bda, uint16_t handle) 669{ 670 if (!handle) { 671 APPL_TRACE_ERROR("%s: deregistration failed, handle is 0", __func__); 672 return BTA_GATT_ILLEGAL_PARAMETER; 673 } 674 675 tBTA_GATTC_RCB *p_clreg = bta_gattc_cl_get_regcb(client_if); 676 if (p_clreg == NULL) { 677 APPL_TRACE_ERROR("%s client_if: %d not registered bd_addr:%02x:%02x:%02x:%02x:%02x:%02x", 678 __func__, client_if, bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]); 679 return BTA_GATT_ILLEGAL_PARAMETER; 680 } 681 682 for (int i = 0; i < BTA_GATTC_NOTIF_REG_MAX; i ++) { 683 if (p_clreg->notif_reg[i].in_use && 684 !memcmp(p_clreg->notif_reg[i].remote_bda, bda, BD_ADDR_LEN) && 685 p_clreg->notif_reg[i].handle == handle) { 686 APPL_TRACE_DEBUG("%s deregistered bd_addr:%02x:%02x:%02x:%02x:%02x:%02x", 687 __func__, bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]); 688 memset(&p_clreg->notif_reg[i], 0, sizeof(tBTA_GATTC_NOTIF_REG)); 689 return BTA_GATT_OK; 690 } 691 } 692 693 APPL_TRACE_ERROR("%s registration not found bd_addr:%02x:%02x:%02x:%02x:%02x:%02x", 694 __func__, bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]); 695 return BTA_GATT_ERROR; 696} 697 698/******************************************************************************* 699** 700** Function BTA_GATTC_Refresh 701** 702** Description Refresh the server cache of the remote device 703** 704** Parameters remote_bda: remote device BD address. 705** 706** Returns void 707** 708*******************************************************************************/ 709void BTA_GATTC_Refresh(const BD_ADDR remote_bda) 710{ 711 tBTA_GATTC_API_OPEN *p_buf = 712 (tBTA_GATTC_API_OPEN *)osi_malloc(sizeof(tBTA_GATTC_API_OPEN)); 713 714 p_buf->hdr.event = BTA_GATTC_API_REFRESH_EVT; 715 memcpy(p_buf->remote_bda, remote_bda, BD_ADDR_LEN); 716 717 bta_sys_sendmsg(p_buf); 718} 719 720/******************************************************************************* 721** 722** Function BTA_GATTC_Listen 723** 724** Description Start advertisement to listen for connection request for a GATT 725** client application. 726** 727** Parameters client_if: server interface. 728** start: to start or stop listening for connection 729** remote_bda: remote device BD address, if listen to all device 730** use NULL. 731** 732** Returns void 733** 734*******************************************************************************/ 735void BTA_GATTC_Listen(tBTA_GATTC_IF client_if, bool start, BD_ADDR_PTR target_bda) 736{ 737 tBTA_GATTC_API_LISTEN *p_buf = 738 (tBTA_GATTC_API_LISTEN *)osi_malloc(sizeof(tBTA_GATTC_API_LISTEN) + BD_ADDR_LEN); 739 740 p_buf->hdr.event = BTA_GATTC_API_LISTEN_EVT; 741 p_buf->client_if = client_if; 742 p_buf->start = start; 743 if (target_bda) { 744 p_buf->remote_bda = (uint8_t*)(p_buf + 1); 745 memcpy(p_buf->remote_bda, target_bda, BD_ADDR_LEN); 746 } else { 747 p_buf->remote_bda = NULL; 748 } 749 750 bta_sys_sendmsg(p_buf); 751} 752 753/******************************************************************************* 754** 755** Function BTA_GATTC_Broadcast 756** 757** Description Start broadcasting (non-connectable advertisements) 758** 759** Parameters client_if: client interface. 760** start: to start or stop listening for connection 761** 762** Returns void 763** 764*******************************************************************************/ 765void BTA_GATTC_Broadcast(tBTA_GATTC_IF client_if, bool start) 766{ 767 tBTA_GATTC_API_LISTEN *p_buf = 768 (tBTA_GATTC_API_LISTEN *)osi_malloc(sizeof(tBTA_GATTC_API_LISTEN) + BD_ADDR_LEN); 769 770 p_buf->hdr.event = BTA_GATTC_API_BROADCAST_EVT; 771 p_buf->client_if = client_if; 772 p_buf->start = start; 773 774 bta_sys_sendmsg(p_buf); 775} 776 777#endif /* BTA_GATT_INCLUDED */ 778