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 * Routes connection status callbacks from various sub systems to DM 22 * 23 ******************************************************************************/ 24 25 #include "bta_api.h" 26 #include "bta_sys.h" 27 #include "bta_sys_int.h" 28 #include "gki.h" 29 #include "utl.h" 30 31 /******************************************************************************* 32 ** 33 ** Function bta_sys_rm_register 34 ** 35 ** Description Called by BTA DM to register role management callbacks 36 ** 37 ** 38 ** Returns void 39 ** 40 *******************************************************************************/ 41 void bta_sys_rm_register(tBTA_SYS_CONN_CBACK * p_cback) 42 { 43 bta_sys_cb.prm_cb = p_cback; 44 } 45 46 47 /******************************************************************************* 48 ** 49 ** Function bta_sys_policy_register 50 ** 51 ** Description Called by BTA DM to register link policy change callbacks 52 ** 53 ** 54 ** Returns void 55 ** 56 *******************************************************************************/ 57 void bta_sys_policy_register(tBTA_SYS_CONN_CBACK * p_cback) 58 { 59 bta_sys_cb.p_policy_cb = p_cback; 60 } 61 62 /******************************************************************************* 63 ** 64 ** Function bta_sys_role_chg_register 65 ** 66 ** Description Called by BTA AV to register role change callbacks 67 ** 68 ** 69 ** Returns void 70 ** 71 *******************************************************************************/ 72 void bta_sys_role_chg_register(tBTA_SYS_CONN_CBACK * p_cback) 73 { 74 bta_sys_cb.p_role_cb = p_cback; 75 } 76 /******************************************************************************* 77 ** 78 ** Function bta_sys_ssr_cfg_register 79 ** 80 ** Description Called by BTA DM to register SSR configuration callback 81 ** 82 ** 83 ** Returns void 84 ** 85 *******************************************************************************/ 86 #if (BTM_SSR_INCLUDED == TRUE) 87 void bta_sys_ssr_cfg_register(tBTA_SYS_SSR_CFG_CBACK * p_cback) 88 { 89 bta_sys_cb.p_ssr_cb = p_cback; 90 } 91 #endif 92 /******************************************************************************* 93 ** 94 ** Function bta_sys_role_chg_register 95 ** 96 ** Description Called by BTA AV to register role change callbacks 97 ** 98 ** 99 ** Returns void 100 ** 101 *******************************************************************************/ 102 void bta_sys_notify_role_chg(BD_ADDR_PTR p_bda, UINT8 new_role, UINT8 hci_status) 103 { 104 if (bta_sys_cb.p_role_cb) 105 { 106 bta_sys_cb.p_role_cb(BTA_SYS_ROLE_CHANGE, new_role, hci_status, p_bda); 107 } 108 } 109 110 /******************************************************************************* 111 ** 112 ** Function bta_sys_collision_register 113 ** 114 ** Description Called by any BTA module to register for collision event. 115 ** 116 ** 117 ** Returns void 118 ** 119 *******************************************************************************/ 120 void bta_sys_collision_register(UINT8 bta_id, tBTA_SYS_CONN_CBACK *p_cback) 121 { 122 UINT8 index; 123 124 for (index = 0; index < MAX_COLLISION_REG; index++) 125 { 126 if ((bta_sys_cb.colli_reg.id[index] == bta_id) || 127 (bta_sys_cb.colli_reg.id[index] == 0)) 128 { 129 bta_sys_cb.colli_reg.id[index] = bta_id; 130 bta_sys_cb.colli_reg.p_coll_cback[index] = p_cback; 131 return; 132 } 133 } 134 } 135 136 /******************************************************************************* 137 ** 138 ** Function bta_sys_notify_collision 139 ** 140 ** Description Called by BTA DM to notify collision event. 141 ** 142 ** 143 ** Returns void 144 ** 145 *******************************************************************************/ 146 void bta_sys_notify_collision (BD_ADDR_PTR p_bda) 147 { 148 UINT8 index; 149 150 for (index = 0; index < MAX_COLLISION_REG; index++) 151 { 152 if ((bta_sys_cb.colli_reg.id[index] != 0) && 153 (bta_sys_cb.colli_reg.p_coll_cback[index] != NULL)) 154 { 155 bta_sys_cb.colli_reg.p_coll_cback[index] (0, BTA_ID_SYS, 0, p_bda); 156 } 157 } 158 } 159 160 /******************************************************************************* 161 ** 162 ** Function bta_sys_sco_register 163 ** 164 ** Description Called by BTA AV to register sco connection change callbacks 165 ** 166 ** 167 ** Returns void 168 ** 169 *******************************************************************************/ 170 void bta_sys_sco_register(tBTA_SYS_CONN_CBACK * p_cback) 171 { 172 bta_sys_cb.p_sco_cb = p_cback; 173 } 174 175 /******************************************************************************* 176 ** 177 ** Function bta_sys_pm_register 178 ** 179 ** Description Called by BTA DM to register power management callbacks 180 ** 181 ** 182 ** Returns void 183 ** 184 *******************************************************************************/ 185 void bta_sys_pm_register(tBTA_SYS_CONN_CBACK * p_cback) 186 { 187 bta_sys_cb.ppm_cb = p_cback; 188 } 189 190 /******************************************************************************* 191 ** 192 ** Function bta_sys_conn_open 193 ** 194 ** Description Called by BTA subsystems when a connection is made to 195 ** the service 196 ** 197 ** 198 ** Returns void 199 ** 200 *******************************************************************************/ 201 void bta_sys_conn_open(UINT8 id, UINT8 app_id, BD_ADDR peer_addr) 202 { 203 if(bta_sys_cb.prm_cb) 204 { 205 206 bta_sys_cb.prm_cb(BTA_SYS_CONN_OPEN, id, app_id, peer_addr); 207 208 } 209 210 if(bta_sys_cb.ppm_cb) 211 { 212 213 bta_sys_cb.ppm_cb(BTA_SYS_CONN_OPEN, id, app_id, peer_addr); 214 215 } 216 } 217 218 219 220 /******************************************************************************* 221 ** 222 ** Function bta_sys_conn_close 223 ** 224 ** Description Called by BTA subsystems when a connection to the service 225 ** is closed 226 ** 227 ** 228 ** Returns void 229 ** 230 *******************************************************************************/ 231 void bta_sys_conn_close(UINT8 id, UINT8 app_id, BD_ADDR peer_addr) 232 { 233 if(bta_sys_cb.prm_cb) 234 { 235 236 bta_sys_cb.prm_cb(BTA_SYS_CONN_CLOSE, id, app_id, peer_addr); 237 238 } 239 240 if(bta_sys_cb.ppm_cb) 241 { 242 243 bta_sys_cb.ppm_cb(BTA_SYS_CONN_CLOSE, id, app_id, peer_addr); 244 245 } 246 } 247 248 249 /******************************************************************************* 250 ** 251 ** Function bta_sys_app_open 252 ** 253 ** Description Called by BTA subsystems when application initiates connection 254 ** to a peer device 255 ** 256 ** 257 ** Returns void 258 ** 259 *******************************************************************************/ 260 void bta_sys_app_open(UINT8 id, UINT8 app_id, BD_ADDR peer_addr) 261 { 262 if(bta_sys_cb.ppm_cb) 263 { 264 bta_sys_cb.ppm_cb(BTA_SYS_APP_OPEN, id, app_id, peer_addr); 265 } 266 } 267 268 269 270 /******************************************************************************* 271 ** 272 ** Function bta_sys_app_close 273 ** 274 ** Description Called by BTA subsystems when application initiates close 275 ** of connection to peer device 276 ** 277 ** Returns void 278 ** 279 *******************************************************************************/ 280 void bta_sys_app_close(UINT8 id, UINT8 app_id, BD_ADDR peer_addr) 281 { 282 if(bta_sys_cb.ppm_cb) 283 { 284 bta_sys_cb.ppm_cb(BTA_SYS_APP_CLOSE, id, app_id, peer_addr); 285 } 286 } 287 288 289 /******************************************************************************* 290 ** 291 ** Function bta_sys_sco_open 292 ** 293 ** Description Called by BTA subsystems when sco connection for that service 294 ** is open 295 ** 296 ** Returns void 297 ** 298 *******************************************************************************/ 299 void bta_sys_sco_open(UINT8 id, UINT8 app_id, BD_ADDR peer_addr) 300 { 301 /* AG triggers p_sco_cb by bta_sys_sco_use. */ 302 if((id != BTA_ID_AG) && (bta_sys_cb.p_sco_cb)) 303 { 304 /* without querying BTM_GetNumScoLinks() */ 305 bta_sys_cb.p_sco_cb(BTA_SYS_SCO_OPEN, 1, app_id, peer_addr); 306 } 307 308 if(bta_sys_cb.ppm_cb) 309 { 310 bta_sys_cb.ppm_cb(BTA_SYS_SCO_OPEN, id, app_id, peer_addr); 311 } 312 } 313 314 /******************************************************************************* 315 ** 316 ** Function bta_sys_sco_close 317 ** 318 ** Description Called by BTA subsystems when sco connection for that service 319 ** is closed 320 ** 321 ** Returns void 322 ** 323 *******************************************************************************/ 324 void bta_sys_sco_close(UINT8 id, UINT8 app_id, BD_ADDR peer_addr) 325 { 326 UINT8 num_sco_links; 327 328 if((id != BTA_ID_AG) && (bta_sys_cb.p_sco_cb)) 329 { 330 num_sco_links = BTM_GetNumScoLinks(); 331 bta_sys_cb.p_sco_cb(BTA_SYS_SCO_CLOSE, num_sco_links, app_id, peer_addr); 332 } 333 334 if(bta_sys_cb.ppm_cb) 335 { 336 bta_sys_cb.ppm_cb(BTA_SYS_SCO_CLOSE, id, app_id, peer_addr); 337 } 338 } 339 340 /******************************************************************************* 341 ** 342 ** Function bta_sys_sco_use 343 ** 344 ** Description Called by BTA subsystems when that service needs to use sco. 345 ** 346 ** 347 ** Returns void 348 ** 349 *******************************************************************************/ 350 void bta_sys_sco_use(UINT8 id, UINT8 app_id, BD_ADDR peer_addr) 351 { 352 UNUSED(id); 353 354 /* AV streaming need to be suspended before SCO is connected. */ 355 if(bta_sys_cb.p_sco_cb) 356 { 357 /* without querying BTM_GetNumScoLinks() */ 358 bta_sys_cb.p_sco_cb(BTA_SYS_SCO_OPEN, 1, app_id, peer_addr); 359 } 360 } 361 362 /******************************************************************************* 363 ** 364 ** Function bta_sys_sco_unuse 365 ** 366 ** Description Called by BTA subsystems when sco connection for that service 367 ** is no longer needed. 368 ** 369 ** Returns void 370 ** 371 *******************************************************************************/ 372 void bta_sys_sco_unuse(UINT8 id, UINT8 app_id, BD_ADDR peer_addr) 373 { 374 UINT8 num_sco_links; 375 UNUSED(id); 376 377 if((bta_sys_cb.p_sco_cb)) 378 { 379 num_sco_links = BTM_GetNumScoLinks(); 380 bta_sys_cb.p_sco_cb(BTA_SYS_SCO_CLOSE, num_sco_links, app_id, peer_addr); 381 } 382 } 383 /******************************************************************************* 384 ** 385 ** Function bta_sys_chg_ssr_config 386 ** 387 ** Description Called by BTA subsystems to indicate that the given app SSR setting 388 ** need to be changed. 389 ** 390 ** Returns void 391 ** 392 *******************************************************************************/ 393 #if (BTM_SSR_INCLUDED == TRUE) 394 void bta_sys_chg_ssr_config (UINT8 id, UINT8 app_id, UINT16 max_latency, UINT16 min_tout) 395 { 396 if(bta_sys_cb.p_ssr_cb) 397 { 398 bta_sys_cb.p_ssr_cb(id, app_id, max_latency, min_tout); 399 } 400 } 401 #endif 402 /******************************************************************************* 403 ** 404 ** Function bta_sys_set_policy 405 ** 406 ** Description Called by BTA subsystems to indicate that the given link 407 ** policy to peer device should be set 408 ** 409 ** Returns void 410 ** 411 *******************************************************************************/ 412 void bta_sys_set_policy (UINT8 id, UINT8 policy, BD_ADDR peer_addr) 413 { 414 if(bta_sys_cb.p_policy_cb) 415 { 416 bta_sys_cb.p_policy_cb(BTA_SYS_PLCY_SET, id, policy, peer_addr); 417 } 418 } 419 420 /******************************************************************************* 421 ** 422 ** Function bta_sys_clear_policy 423 ** 424 ** Description Called by BTA subsystems to indicate that the given link 425 ** policy to peer device should be clear 426 ** 427 ** Returns void 428 ** 429 *******************************************************************************/ 430 void bta_sys_clear_policy (UINT8 id, UINT8 policy, BD_ADDR peer_addr) 431 { 432 if(bta_sys_cb.p_policy_cb) 433 { 434 bta_sys_cb.p_policy_cb(BTA_SYS_PLCY_CLR, id, policy, peer_addr); 435 } 436 } 437 438 /******************************************************************************* 439 ** 440 ** Function bta_sys_set_default_policy 441 ** 442 ** Description Called by BTA subsystems to indicate that the given default 443 ** link policy should be set 444 ** 445 ** Returns void 446 ** 447 *******************************************************************************/ 448 void bta_sys_set_default_policy (UINT8 id, UINT8 policy) 449 { 450 if(bta_sys_cb.p_policy_cb) 451 { 452 bta_sys_cb.p_policy_cb(BTA_SYS_PLCY_DEF_SET, id, policy, NULL); 453 } 454 } 455 456 /******************************************************************************* 457 ** 458 ** Function bta_sys_clear_default_policy 459 ** 460 ** Description Called by BTA subsystems to indicate that the given default 461 ** link policy should be clear 462 ** 463 ** Returns void 464 ** 465 *******************************************************************************/ 466 void bta_sys_clear_default_policy (UINT8 id, UINT8 policy) 467 { 468 if(bta_sys_cb.p_policy_cb) 469 { 470 bta_sys_cb.p_policy_cb(BTA_SYS_PLCY_DEF_CLR, id, policy, NULL); 471 } 472 } 473 474 /******************************************************************************* 475 ** 476 ** Function bta_sys_idle 477 ** 478 ** Description Called by BTA subsystems to indicate that the connection to 479 ** peer device is idle 480 ** 481 ** Returns void 482 ** 483 *******************************************************************************/ 484 void bta_sys_idle(UINT8 id, UINT8 app_id, BD_ADDR peer_addr) 485 { 486 487 if(bta_sys_cb.prm_cb) 488 { 489 490 bta_sys_cb.prm_cb(BTA_SYS_CONN_IDLE, id, app_id, peer_addr); 491 492 } 493 494 if(bta_sys_cb.ppm_cb) 495 { 496 497 bta_sys_cb.ppm_cb(BTA_SYS_CONN_IDLE, id, app_id, peer_addr); 498 } 499 } 500 501 /******************************************************************************* 502 ** 503 ** Function bta_sys_busy 504 ** 505 ** Description Called by BTA subsystems to indicate that the connection to 506 ** peer device is busy 507 ** 508 ** Returns void 509 ** 510 *******************************************************************************/ 511 void bta_sys_busy(UINT8 id, UINT8 app_id, BD_ADDR peer_addr) 512 { 513 if(bta_sys_cb.prm_cb) 514 { 515 516 bta_sys_cb.prm_cb(BTA_SYS_CONN_BUSY, id, app_id, peer_addr); 517 518 } 519 520 if(bta_sys_cb.ppm_cb) 521 { 522 523 bta_sys_cb.ppm_cb(BTA_SYS_CONN_BUSY, id, app_id, peer_addr); 524 525 } 526 } 527 528 #if ( BTM_EIR_SERVER_INCLUDED == TRUE )&&(BTA_EIR_CANNED_UUID_LIST != TRUE) 529 /******************************************************************************* 530 ** 531 ** Function bta_sys_eir_register 532 ** 533 ** Description Called by BTA DM to register EIR utility function that can be 534 ** used by the other BTA modules to add/remove UUID. 535 ** 536 ** Returns void 537 ** 538 *******************************************************************************/ 539 void bta_sys_eir_register(tBTA_SYS_EIR_CBACK * p_cback) 540 { 541 bta_sys_cb.eir_cb = p_cback; 542 } 543 544 /******************************************************************************* 545 ** 546 ** Function bta_sys_add_uuid 547 ** 548 ** Description Called by BTA subsystems to indicate to DM that new service 549 ** class UUID is added. 550 ** 551 ** Returns void 552 ** 553 *******************************************************************************/ 554 void bta_sys_add_uuid(UINT16 uuid16) 555 { 556 if(bta_sys_cb.eir_cb) 557 { 558 bta_sys_cb.eir_cb(uuid16, TRUE ); 559 } 560 } 561 562 /******************************************************************************* 563 ** 564 ** Function bta_sys_remove_uuid 565 ** 566 ** Description Called by BTA subsystems to indicate to DM that the service 567 ** class UUID is removed. 568 ** 569 ** Returns void 570 ** 571 *******************************************************************************/ 572 void bta_sys_remove_uuid(UINT16 uuid16) 573 { 574 if(bta_sys_cb.eir_cb) 575 { 576 bta_sys_cb.eir_cb(uuid16, FALSE); 577 } 578 } 579 #endif 580 581 /******************************************************************************* 582 ** 583 ** Function bta_sys_vs_hdl 584 ** 585 ** Description Called by BTA subsystems to execute a VS event handler function 586 ** 587 ** Returns void 588 ** 589 *******************************************************************************/ 590 BOOLEAN bta_sys_vs_hdl(UINT16 evt, void *p) 591 { 592 if (bta_sys_cb.p_vs_evt_hdlr) 593 return (*bta_sys_cb.p_vs_evt_hdlr)(evt, p); 594 595 return FALSE; 596 } 597 598