bta_gatts_act.cc revision 8af480e24549ba51a3f6858d9d9af504715e0bea
1/****************************************************************************** 2 * 3 * Copyright (C) 2003-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 file contains the GATT Server action functions for the state 22 * machine. 23 * 24 ******************************************************************************/ 25 26 27#include "bt_target.h" 28 29#if (BTA_GATT_INCLUDED == TRUE) 30 31#include "utl.h" 32#include "bt_common.h" 33#include "bta_sys.h" 34#include "bta_gatts_int.h" 35#include "bta_gatts_co.h" 36#include "btm_ble_api.h" 37#include "btif/include/btif_debug_conn.h" 38#include "osi/include/osi.h" 39#include <string.h> 40 41static void bta_gatts_nv_save_cback(bool is_saved, tGATTS_HNDL_RANGE *p_hndl_range); 42static bool bta_gatts_nv_srv_chg_cback(tGATTS_SRV_CHG_CMD cmd, tGATTS_SRV_CHG_REQ *p_req, 43 tGATTS_SRV_CHG_RSP *p_rsp); 44 45static void bta_gatts_conn_cback (tGATT_IF gatt_if, BD_ADDR bda, uint16_t conn_id, 46 bool connected, tGATT_DISCONN_REASON reason, 47 tGATT_TRANSPORT transport); 48static void bta_gatts_send_request_cback (uint16_t conn_id, 49 uint32_t trans_id, 50 tGATTS_REQ_TYPE req_type, tGATTS_DATA *p_data); 51static void bta_gatts_cong_cback (uint16_t conn_id, bool congested); 52 53static tGATT_CBACK bta_gatts_cback = 54{ 55 bta_gatts_conn_cback, 56 NULL, 57 NULL, 58 NULL, 59 bta_gatts_send_request_cback, 60 NULL, 61 bta_gatts_cong_cback 62}; 63 64tGATT_APPL_INFO bta_gatts_nv_cback = 65{ 66 bta_gatts_nv_save_cback, 67 bta_gatts_nv_srv_chg_cback 68}; 69 70/******************************************************************************* 71 * 72 * Function bta_gatts_nv_save_cback 73 * 74 * Description NV save callback function. 75 * 76 * Parameter is_add: true is to add a handle range; otherwise is to delete. 77 * Returns none. 78 * 79 ******************************************************************************/ 80static void bta_gatts_nv_save_cback(bool is_add, tGATTS_HNDL_RANGE *p_hndl_range) 81{ 82 bta_gatts_co_update_handle_range(is_add, (tBTA_GATTS_HNDL_RANGE *)p_hndl_range); 83} 84 85 86/******************************************************************************* 87 * 88 * Function bta_gatts_nv_srv_chg_cback 89 * 90 * Description NV save callback function. 91 * 92 * Parameter is_add: true is to add a handle range; otherwise is to delete. 93 * Returns none. 94 * 95 ******************************************************************************/ 96static bool bta_gatts_nv_srv_chg_cback(tGATTS_SRV_CHG_CMD cmd, 97 tGATTS_SRV_CHG_REQ *p_req, tGATTS_SRV_CHG_RSP *p_rsp) 98{ 99 return bta_gatts_co_srv_chg((tBTA_GATTS_SRV_CHG_CMD) cmd, 100 (tBTA_GATTS_SRV_CHG_REQ *) p_req, 101 (tBTA_GATTS_SRV_CHG_RSP *) p_rsp); 102} 103 104 105/******************************************************************************* 106 * 107 * Function bta_gatts_enable 108 * 109 * Description enable BTA GATTS module. 110 * 111 * Returns none. 112 * 113 ******************************************************************************/ 114void bta_gatts_enable(tBTA_GATTS_CB *p_cb) 115{ 116 uint8_t index=0; 117 tBTA_GATTS_HNDL_RANGE handle_range; 118 119 if (p_cb->enabled) 120 { 121 APPL_TRACE_DEBUG("GATTS already enabled."); 122 } 123 else 124 { 125 memset(p_cb, 0, sizeof(tBTA_GATTS_CB)); 126 127 p_cb->enabled = true; 128 129 while ( bta_gatts_co_load_handle_range(index, &handle_range)) 130 { 131 GATTS_AddHandleRange((tGATTS_HNDL_RANGE *)&handle_range); 132 memset(&handle_range, 0, sizeof(tGATTS_HNDL_RANGE)); 133 index++; 134 } 135 136 APPL_TRACE_DEBUG("bta_gatts_enable: num of handle range added=%d", index); 137 138 if (!GATTS_NVRegister(&bta_gatts_nv_cback)) 139 { 140 APPL_TRACE_ERROR("BTA GATTS NV register failed."); 141 } 142 } 143} 144 145/******************************************************************************* 146 * 147 * Function bta_gatts_api_disable 148 * 149 * Description disable BTA GATTS module. 150 * 151 * Returns none. 152 * 153 ******************************************************************************/ 154void bta_gatts_api_disable(tBTA_GATTS_CB *p_cb) 155{ 156 uint8_t i; 157 158 if (p_cb->enabled) 159 { 160 for (i = 0; i < BTA_GATTS_MAX_APP_NUM; i ++) 161 { 162 if (p_cb->rcb[i].in_use) 163 { 164 GATT_Deregister(p_cb->rcb[i].gatt_if); 165 } 166 } 167 memset(p_cb, 0, sizeof(tBTA_GATTS_CB)); 168 } 169 else 170 { 171 APPL_TRACE_ERROR("GATTS not enabled"); 172 } 173} 174 175/******************************************************************************* 176 * 177 * Function bta_gatts_register 178 * 179 * Description register an application. 180 * 181 * Returns none. 182 * 183 ******************************************************************************/ 184void bta_gatts_register(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg) 185{ 186 tBTA_GATTS cb_data; 187 tBTA_GATT_STATUS status = BTA_GATT_OK; 188 uint8_t i, first_unuse = 0xff; 189 190 if (p_cb->enabled == false) 191 { 192 bta_gatts_enable(p_cb); 193 } 194 195 for (i = 0; i < BTA_GATTS_MAX_APP_NUM; i ++) 196 { 197 if (p_cb->rcb[i].in_use) 198 { 199 if (bta_gatts_uuid_compare(p_cb->rcb[i].app_uuid, p_msg->api_reg.app_uuid)) 200 { 201 APPL_TRACE_ERROR("application already registered."); 202 status = BTA_GATT_DUP_REG; 203 break; 204 } 205 } 206 } 207 208 if (status == BTA_GATT_OK) 209 { 210 for (i = 0; i < BTA_GATTS_MAX_APP_NUM; i ++) 211 { 212 if (first_unuse == 0xff && !p_cb->rcb[i].in_use) 213 { 214 first_unuse = i; 215 break; 216 } 217 } 218 219 cb_data.reg_oper.server_if = BTA_GATTS_INVALID_IF; 220 memcpy(&cb_data.reg_oper.uuid, &p_msg->api_reg.app_uuid, sizeof(tBT_UUID)); 221 if (first_unuse != 0xff) 222 { 223 APPL_TRACE_ERROR("register application first_unuse rcb_idx = %d", first_unuse); 224 225 p_cb->rcb[first_unuse].in_use = true; 226 p_cb->rcb[first_unuse].p_cback = p_msg->api_reg.p_cback; 227 memcpy(&p_cb->rcb[first_unuse].app_uuid, &p_msg->api_reg.app_uuid, sizeof(tBT_UUID)); 228 cb_data.reg_oper.server_if = 229 p_cb->rcb[first_unuse].gatt_if = 230 GATT_Register(&p_msg->api_reg.app_uuid, &bta_gatts_cback); 231 if ( !p_cb->rcb[first_unuse].gatt_if) { 232 status = BTA_GATT_NO_RESOURCES; 233 } else { 234 tBTA_GATTS_INT_START_IF *p_buf = 235 (tBTA_GATTS_INT_START_IF *)osi_malloc(sizeof(tBTA_GATTS_INT_START_IF)); 236 p_buf->hdr.event = BTA_GATTS_INT_START_IF_EVT; 237 p_buf->server_if = p_cb->rcb[first_unuse].gatt_if; 238 239 bta_sys_sendmsg(p_buf); 240 } 241 } else { 242 status = BTA_GATT_NO_RESOURCES; 243 } 244 245 } 246 cb_data.reg_oper.status = status; 247 if (p_msg->api_reg.p_cback) 248 (*p_msg->api_reg.p_cback)(BTA_GATTS_REG_EVT, &cb_data); 249} 250 251 252/******************************************************************************* 253 * 254 * Function bta_gatts_start_if 255 * 256 * Description start an application interface. 257 * 258 * Returns none. 259 * 260 ******************************************************************************/ 261void bta_gatts_start_if(UNUSED_ATTR tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg) 262{ 263 if (bta_gatts_find_app_rcb_by_app_if(p_msg->int_start_if.server_if)) 264 { 265 GATT_StartIf(p_msg->int_start_if.server_if); 266 } 267 else 268 { 269 APPL_TRACE_ERROR("Unable to start app.: Unknown interface =%d", 270 p_msg->int_start_if.server_if ); 271 } 272} 273/******************************************************************************* 274 * 275 * Function bta_gatts_deregister 276 * 277 * Description deregister an application. 278 * 279 * Returns none. 280 * 281 ******************************************************************************/ 282void bta_gatts_deregister(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg) 283{ 284 tBTA_GATT_STATUS status = BTA_GATT_ERROR; 285 tBTA_GATTS_CBACK *p_cback = NULL; 286 uint8_t i; 287 tBTA_GATTS cb_data; 288 289 cb_data.reg_oper.server_if = p_msg->api_dereg.server_if; 290 cb_data.reg_oper.status = status; 291 292 for (i = 0; i < BTA_GATTS_MAX_APP_NUM; i ++) 293 { 294 if (p_cb->rcb[i].in_use && p_cb->rcb[i].gatt_if == p_msg->api_dereg.server_if) 295 { 296 p_cback = p_cb->rcb[i].p_cback; 297 status = BTA_GATT_OK; 298 299 /* deregister the app */ 300 GATT_Deregister(p_cb->rcb[i].gatt_if); 301 302 /* reset cb */ 303 memset(&p_cb->rcb[i], 0, sizeof(tBTA_GATTS_RCB)); 304 cb_data.reg_oper.status = status; 305 break; 306 } 307 } 308 309 if (p_cback) 310 { 311 (*p_cback)(BTA_GATTS_DEREG_EVT, &cb_data); 312 } 313 else 314 { 315 APPL_TRACE_ERROR("application not registered."); 316 } 317} 318 319/******************************************************************************* 320 * 321 * Function bta_gatts_delete_service 322 * 323 * Description action function to delete a service. 324 * 325 * Returns none. 326 * 327 ******************************************************************************/ 328void bta_gatts_delete_service(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA * p_msg) 329{ 330 tBTA_GATTS_RCB *p_rcb = &bta_gatts_cb.rcb[p_srvc_cb->rcb_idx]; 331 tBTA_GATTS cb_data; 332 333 cb_data.srvc_oper.server_if = p_rcb->gatt_if; 334 // cb_data.srvc_oper.service_id = p_msg->api_add_incl_srvc.hdr.layer_specific; 335 336 if (GATTS_DeleteService(p_rcb->gatt_if, 337 &p_srvc_cb->service_uuid, 338 p_srvc_cb->service_id)) 339 { 340 cb_data.srvc_oper.status = BTA_GATT_OK; 341 memset(p_srvc_cb, 0, sizeof(tBTA_GATTS_SRVC_CB)); 342 } 343 else 344 { 345 cb_data.srvc_oper.status = BTA_GATT_ERROR; 346 } 347 348 if (p_rcb->p_cback) 349 (*p_rcb->p_cback)(BTA_GATTS_DELELTE_EVT, &cb_data); 350 351} 352 353/******************************************************************************* 354 * 355 * Function bta_gatts_stop_service 356 * 357 * Description action function to stop a service. 358 * 359 * Returns none. 360 * 361 ******************************************************************************/ 362void bta_gatts_stop_service(tBTA_GATTS_SRVC_CB *p_srvc_cb, 363 UNUSED_ATTR tBTA_GATTS_DATA *p_msg) 364{ 365 tBTA_GATTS_RCB *p_rcb = &bta_gatts_cb.rcb[p_srvc_cb->rcb_idx]; 366 tBTA_GATTS cb_data; 367 368 GATTS_StopService(p_srvc_cb->service_id); 369 cb_data.srvc_oper.server_if = p_rcb->gatt_if; 370 cb_data.srvc_oper.service_id = p_srvc_cb->service_id; 371 cb_data.srvc_oper.status = BTA_GATT_OK; 372 APPL_TRACE_ERROR("bta_gatts_stop_service service_id= %d", p_srvc_cb->service_id); 373 374 if (p_rcb->p_cback) 375 (*p_rcb->p_cback)(BTA_GATTS_STOP_EVT, &cb_data); 376 377} 378/******************************************************************************* 379 * 380 * Function bta_gatts_send_rsp 381 * 382 * Description GATTS send response. 383 * 384 * Returns none. 385 * 386 ******************************************************************************/ 387void bta_gatts_send_rsp (UNUSED_ATTR tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA * p_msg) 388{ 389 if (GATTS_SendRsp (p_msg->api_rsp.hdr.layer_specific, 390 p_msg->api_rsp.trans_id, 391 p_msg->api_rsp.status, 392 (tGATTS_RSP *)p_msg->api_rsp.p_rsp) != GATT_SUCCESS) 393 { 394 APPL_TRACE_ERROR("Sending response failed"); 395 } 396 397} 398/******************************************************************************* 399 * 400 * Function bta_gatts_indicate_handle 401 * 402 * Description GATTS send handle value indication or notification. 403 * 404 * Returns none. 405 * 406 ******************************************************************************/ 407void bta_gatts_indicate_handle (tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA * p_msg) 408{ 409 tBTA_GATTS_SRVC_CB *p_srvc_cb; 410 tBTA_GATTS_RCB *p_rcb = NULL; 411 tBTA_GATT_STATUS status = BTA_GATT_ILLEGAL_PARAMETER; 412 tGATT_IF gatt_if; 413 BD_ADDR remote_bda; 414 tBTA_TRANSPORT transport; 415 tBTA_GATTS cb_data; 416 417 p_srvc_cb = bta_gatts_find_srvc_cb_by_attr_id (p_cb, p_msg->api_indicate.attr_id); 418 419 if (p_srvc_cb ) 420 { 421 if (GATT_GetConnectionInfor(p_msg->api_indicate.hdr.layer_specific, 422 &gatt_if, remote_bda, &transport)) 423 { 424 p_rcb = bta_gatts_find_app_rcb_by_app_if(gatt_if); 425 426 if (p_msg->api_indicate.need_confirm) 427 428 status = GATTS_HandleValueIndication (p_msg->api_indicate.hdr.layer_specific, 429 p_msg->api_indicate.attr_id, 430 p_msg->api_indicate.len, 431 p_msg->api_indicate.value); 432 else 433 status = GATTS_HandleValueNotification (p_msg->api_indicate.hdr.layer_specific, 434 p_msg->api_indicate.attr_id, 435 p_msg->api_indicate.len, 436 p_msg->api_indicate.value); 437 438 /* if over BR_EDR, inform PM for mode change */ 439 if (transport == BTA_TRANSPORT_BR_EDR) 440 { 441 bta_sys_busy(BTA_ID_GATTS, BTA_ALL_APP_ID, remote_bda); 442 bta_sys_idle(BTA_ID_GATTS, BTA_ALL_APP_ID, remote_bda); 443 } 444 } 445 else 446 { 447 APPL_TRACE_ERROR("Unknown connection ID: %d fail sending notification", 448 p_msg->api_indicate.hdr.layer_specific); 449 } 450 451 if ((status != GATT_SUCCESS || !p_msg->api_indicate.need_confirm) && 452 p_rcb && p_cb->rcb[p_srvc_cb->rcb_idx].p_cback) 453 { 454 cb_data.req_data.status = status; 455 cb_data.req_data.conn_id = p_msg->api_indicate.hdr.layer_specific; 456 457 (*p_rcb->p_cback)(BTA_GATTS_CONF_EVT, &cb_data); 458 } 459 } 460 else 461 { 462 APPL_TRACE_ERROR("Not an registered servce attribute ID: 0x%04x", 463 p_msg->api_indicate.attr_id); 464 } 465} 466 467 468/******************************************************************************* 469 * 470 * Function bta_gatts_open 471 * 472 * Description 473 * 474 * Returns none. 475 * 476 ******************************************************************************/ 477void bta_gatts_open (UNUSED_ATTR tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA * p_msg) 478{ 479 tBTA_GATTS_RCB *p_rcb=NULL; 480 tBTA_GATT_STATUS status= BTA_GATT_ERROR; 481 uint16_t conn_id; 482 483 if ((p_rcb = bta_gatts_find_app_rcb_by_app_if(p_msg->api_open.server_if)) != NULL) 484 { 485 /* should always get the connection ID */ 486 if (GATT_Connect(p_rcb->gatt_if, p_msg->api_open.remote_bda, 487 p_msg->api_open.is_direct, p_msg->api_open.transport, false)) 488 { 489 status = BTA_GATT_OK; 490 491 if (GATT_GetConnIdIfConnected(p_rcb->gatt_if, p_msg->api_open.remote_bda, 492 &conn_id, p_msg->api_open.transport)) 493 { 494 status = BTA_GATT_ALREADY_OPEN; 495 } 496 } 497 } 498 else 499 { 500 APPL_TRACE_ERROR("Inavlide server_if=%d", p_msg->api_open.server_if); 501 } 502 503 if (p_rcb && p_rcb->p_cback) 504 (*p_rcb->p_cback)(BTA_GATTS_OPEN_EVT, (tBTA_GATTS *)&status); 505 506} 507/******************************************************************************* 508 * 509 * Function bta_gatts_cancel_open 510 * 511 * Description 512 * 513 * Returns none. 514 * 515 ******************************************************************************/ 516void bta_gatts_cancel_open (UNUSED_ATTR tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA * p_msg) 517{ 518 tBTA_GATTS_RCB *p_rcb; 519 tBTA_GATT_STATUS status= BTA_GATT_ERROR; 520 521 if ((p_rcb = bta_gatts_find_app_rcb_by_app_if(p_msg->api_cancel_open.server_if)) != NULL) 522 { 523 if (!GATT_CancelConnect(p_rcb->gatt_if, p_msg->api_cancel_open.remote_bda, 524 p_msg->api_cancel_open.is_direct)) 525 { 526 APPL_TRACE_ERROR("bta_gatts_cancel_open failed for open request"); 527 } 528 else 529 { 530 status= BTA_GATT_OK; 531 } 532 } 533 else 534 { 535 APPL_TRACE_ERROR("Inavlide server_if=%d", p_msg->api_cancel_open.server_if); 536 } 537 538 if (p_rcb && p_rcb->p_cback) 539 (*p_rcb->p_cback)(BTA_GATTS_CANCEL_OPEN_EVT, (tBTA_GATTS *)&status); 540} 541/******************************************************************************* 542 * 543 * Function bta_gatts_close 544 * 545 * Description 546 * 547 * Returns none. 548 * 549 ******************************************************************************/ 550void bta_gatts_close (UNUSED_ATTR tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA * p_msg) 551{ 552 tBTA_GATTS_RCB *p_rcb; 553 tBTA_GATT_STATUS status= BTA_GATT_ERROR; 554 tGATT_IF gatt_if; 555 BD_ADDR remote_bda; 556 tBTA_GATT_TRANSPORT transport; 557 558 if (GATT_GetConnectionInfor(p_msg->hdr.layer_specific, &gatt_if, remote_bda, &transport)) 559 { 560 if (GATT_Disconnect(p_msg->hdr.layer_specific) != GATT_SUCCESS) 561 { 562 APPL_TRACE_ERROR("bta_gatts_close fail conn_id=%d", p_msg->hdr.layer_specific); 563 } 564 else 565 { 566 status= BTA_GATT_OK; 567 } 568 569 p_rcb = bta_gatts_find_app_rcb_by_app_if(gatt_if); 570 571 if (p_rcb && p_rcb->p_cback) 572 { 573 if (transport == BTA_TRANSPORT_BR_EDR) 574 bta_sys_conn_close( BTA_ID_GATTS ,BTA_ALL_APP_ID, remote_bda); 575 576 (*p_rcb->p_cback)(BTA_GATTS_CLOSE_EVT, (tBTA_GATTS *)&status); 577 } 578 } 579 else 580 { 581 APPL_TRACE_ERROR("Unknown connection ID: %d", p_msg->hdr.layer_specific); 582 } 583 584} 585 586/******************************************************************************* 587 * 588 * Function bta_gatts_request_cback 589 * 590 * Description GATTS attribute request callback. 591 * 592 * Returns none. 593 * 594 ******************************************************************************/ 595static void bta_gatts_send_request_cback (uint16_t conn_id, 596 uint32_t trans_id, 597 tGATTS_REQ_TYPE req_type, tGATTS_DATA *p_data) 598{ 599 tBTA_GATTS cb_data; 600 tBTA_GATTS_RCB *p_rcb; 601 tGATT_IF gatt_if; 602 tBTA_GATT_TRANSPORT transport; 603 604 memset(&cb_data, 0 , sizeof(tBTA_GATTS)); 605 606 if (GATT_GetConnectionInfor(conn_id, &gatt_if, cb_data.req_data.remote_bda, &transport)) 607 { 608 p_rcb = bta_gatts_find_app_rcb_by_app_if(gatt_if); 609 610 APPL_TRACE_DEBUG("%s: conn_id=%d trans_id=%d req_type=%d", 611 __func__, conn_id, trans_id, req_type); 612 613 if (p_rcb && p_rcb->p_cback) 614 { 615 /* if over BR_EDR, inform PM for mode change */ 616 if (transport == BTA_TRANSPORT_BR_EDR) 617 { 618 bta_sys_busy(BTA_ID_GATTS, BTA_ALL_APP_ID, cb_data.req_data.remote_bda); 619 bta_sys_idle(BTA_ID_GATTS, BTA_ALL_APP_ID, cb_data.req_data.remote_bda); 620 } 621 622 cb_data.req_data.conn_id = conn_id; 623 cb_data.req_data.trans_id = trans_id; 624 cb_data.req_data.p_data = (tBTA_GATTS_REQ_DATA *)p_data; 625 626 (*p_rcb->p_cback)(req_type, &cb_data); 627 } 628 else 629 { 630 APPL_TRACE_ERROR("connection request on gatt_if[%d] is not interested", gatt_if); 631 } 632 } 633 else 634 { 635 APPL_TRACE_ERROR("request received on unknown connectino ID: %d", conn_id); 636 } 637} 638 639/******************************************************************************* 640 * 641 * Function bta_gatts_conn_cback 642 * 643 * Description connection callback. 644 * 645 * Returns none. 646 * 647 ******************************************************************************/ 648static void bta_gatts_conn_cback (tGATT_IF gatt_if, BD_ADDR bda, uint16_t conn_id, 649 bool connected, tGATT_DISCONN_REASON reason, 650 tGATT_TRANSPORT transport) 651{ 652 tBTA_GATTS cb_data; 653 uint8_t evt = connected ? BTA_GATTS_CONNECT_EVT: BTA_GATTS_DISCONNECT_EVT; 654 tBTA_GATTS_RCB *p_reg; 655 656 APPL_TRACE_DEBUG ("bta_gatts_conn_cback gatt_if=%d conn_id=%d connected=%d reason = 0x%04d", 657 gatt_if, conn_id, connected, reason); 658 APPL_TRACE_DEBUG("bta_gatts_conn_cback bda :%02x-%02x-%02x-%02x-%02x-%02x ", 659 bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]); 660 661 bt_bdaddr_t bdaddr; 662 bdcpy(bdaddr.address, bda); 663 if (connected) 664 btif_debug_conn_state(bdaddr, BTIF_DEBUG_CONNECTED, GATT_CONN_UNKNOWN); 665 else 666 btif_debug_conn_state(bdaddr, BTIF_DEBUG_DISCONNECTED, reason); 667 668 p_reg = bta_gatts_find_app_rcb_by_app_if(gatt_if); 669 670 if (p_reg && p_reg->p_cback) 671 { 672 /* there is no RM for GATT */ 673 if (transport == BTA_TRANSPORT_BR_EDR) 674 { 675 if (connected) 676 bta_sys_conn_open(BTA_ID_GATTS, BTA_ALL_APP_ID, bda); 677 else 678 bta_sys_conn_close( BTA_ID_GATTS ,BTA_ALL_APP_ID, bda); 679 } 680 681 cb_data.conn.conn_id = conn_id; 682 cb_data.conn.server_if = gatt_if; 683 cb_data.conn.reason = reason; 684 cb_data.conn.transport = transport; 685 memcpy(cb_data.conn.remote_bda, bda, BD_ADDR_LEN); 686 (*p_reg->p_cback)(evt, &cb_data); 687 } 688 else 689 { 690 APPL_TRACE_ERROR("bta_gatts_conn_cback server_if=%d not found",gatt_if); 691 } 692} 693 694/******************************************************************************* 695 * 696 * Function bta_gatts_cong_cback 697 * 698 * Description congestion callback. 699 * 700 * Returns none. 701 * 702 ******************************************************************************/ 703static void bta_gatts_cong_cback (uint16_t conn_id, bool congested) 704{ 705 tBTA_GATTS_RCB *p_rcb; 706 tGATT_IF gatt_if; 707 tBTA_GATT_TRANSPORT transport; 708 tBTA_GATTS cb_data; 709 710 if (GATT_GetConnectionInfor(conn_id, &gatt_if, cb_data.req_data.remote_bda, &transport)) 711 { 712 p_rcb = bta_gatts_find_app_rcb_by_app_if(gatt_if); 713 714 if (p_rcb && p_rcb->p_cback) 715 { 716 cb_data.congest.conn_id = conn_id; 717 cb_data.congest.congested = congested; 718 719 (*p_rcb->p_cback)(BTA_GATTS_CONGEST_EVT, &cb_data); 720 } 721 } 722} 723#endif /* BTA_GATT_INCLUDED */ 724