blob: 5562d0ec1b1deb6069c735675bd8e33551de190b [file] [log] [blame]
The Android Open Source Project5738f832012-12-12 16:00:35 -08001/******************************************************************************
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
Scott James Remnant933926c2015-04-02 15:22:14 -070025#include <stddef.h>
The Android Open Source Project5738f832012-12-12 16:00:35 -080026#include "bta_api.h"
27#include "bta_sys.h"
28#include "bta_sys_int.h"
Pavlin Radoslavov258c2532015-09-27 20:59:05 -070029#include "bt_common.h"
Myles Watsond7ffd642016-10-27 10:27:36 -070030#include "osi/include/osi.h"
Mike J. Chen5cd8bff2014-01-31 18:16:59 -080031#include "utl.h"
The Android Open Source Project5738f832012-12-12 16:00:35 -080032
33/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -080034 *
35 * Function bta_sys_rm_register
36 *
37 * Description Called by BTA DM to register role management callbacks
38 *
39 *
40 * Returns void
41 *
42 ******************************************************************************/
The Android Open Source Project5738f832012-12-12 16:00:35 -080043void bta_sys_rm_register(tBTA_SYS_CONN_CBACK * p_cback)
44{
45 bta_sys_cb.prm_cb = p_cback;
46}
47
48
49/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -080050 *
51 * Function bta_sys_policy_register
52 *
53 * Description Called by BTA DM to register link policy change callbacks
54 *
55 *
56 * Returns void
57 *
58 ******************************************************************************/
The Android Open Source Project5738f832012-12-12 16:00:35 -080059void bta_sys_policy_register(tBTA_SYS_CONN_CBACK * p_cback)
60{
61 bta_sys_cb.p_policy_cb = p_cback;
62}
63
64/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -080065 *
66 * Function bta_sys_role_chg_register
67 *
68 * Description Called by BTA AV to register role change callbacks
69 *
70 *
71 * Returns void
72 *
73 ******************************************************************************/
The Android Open Source Project5738f832012-12-12 16:00:35 -080074void bta_sys_role_chg_register(tBTA_SYS_CONN_CBACK * p_cback)
75{
76 bta_sys_cb.p_role_cb = p_cback;
77}
78/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -080079 *
80 * Function bta_sys_ssr_cfg_register
81 *
82 * Description Called by BTA DM to register SSR configuration callback
83 *
84 *
85 * Returns void
86 *
87 ******************************************************************************/
The Android Open Source Project5738f832012-12-12 16:00:35 -080088#if (BTM_SSR_INCLUDED == TRUE)
89void bta_sys_ssr_cfg_register(tBTA_SYS_SSR_CFG_CBACK * p_cback)
90{
91 bta_sys_cb.p_ssr_cb = p_cback;
92}
93#endif
94/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -080095 *
96 * Function bta_sys_role_chg_register
97 *
98 * Description Called by BTA AV to register role change callbacks
99 *
100 *
101 * Returns void
102 *
103 ******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -0700104void bta_sys_notify_role_chg(BD_ADDR_PTR p_bda, uint8_t new_role, uint8_t hci_status)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800105{
106 if (bta_sys_cb.p_role_cb)
107 {
108 bta_sys_cb.p_role_cb(BTA_SYS_ROLE_CHANGE, new_role, hci_status, p_bda);
109 }
110}
111
112/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800113 *
114 * Function bta_sys_collision_register
115 *
116 * Description Called by any BTA module to register for collision event.
117 *
118 *
119 * Returns void
120 *
121 ******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -0700122void bta_sys_collision_register(uint8_t bta_id, tBTA_SYS_CONN_CBACK *p_cback)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800123{
Marie Janssene9e58ce2016-06-17 14:12:17 -0700124 uint8_t index;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800125
126 for (index = 0; index < MAX_COLLISION_REG; index++)
127 {
128 if ((bta_sys_cb.colli_reg.id[index] == bta_id) ||
129 (bta_sys_cb.colli_reg.id[index] == 0))
130 {
131 bta_sys_cb.colli_reg.id[index] = bta_id;
132 bta_sys_cb.colli_reg.p_coll_cback[index] = p_cback;
133 return;
134 }
135 }
136}
137
138/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800139 *
140 * Function bta_sys_notify_collision
141 *
142 * Description Called by BTA DM to notify collision event.
143 *
144 *
145 * Returns void
146 *
147 ******************************************************************************/
The Android Open Source Project5738f832012-12-12 16:00:35 -0800148void bta_sys_notify_collision (BD_ADDR_PTR p_bda)
149{
Marie Janssene9e58ce2016-06-17 14:12:17 -0700150 uint8_t index;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800151
152 for (index = 0; index < MAX_COLLISION_REG; index++)
153 {
154 if ((bta_sys_cb.colli_reg.id[index] != 0) &&
155 (bta_sys_cb.colli_reg.p_coll_cback[index] != NULL))
156 {
157 bta_sys_cb.colli_reg.p_coll_cback[index] (0, BTA_ID_SYS, 0, p_bda);
158 }
159 }
160}
161
162/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800163 *
164 * Function bta_sys_sco_register
165 *
166 * Description Called by BTA AV to register sco connection change callbacks
167 *
168 *
169 * Returns void
170 *
171 ******************************************************************************/
The Android Open Source Project5738f832012-12-12 16:00:35 -0800172void bta_sys_sco_register(tBTA_SYS_CONN_CBACK * p_cback)
173{
174 bta_sys_cb.p_sco_cb = p_cback;
175}
176
177/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800178 *
179 * Function bta_sys_pm_register
180 *
181 * Description Called by BTA DM to register power management callbacks
182 *
183 *
184 * Returns void
185 *
186 ******************************************************************************/
The Android Open Source Project5738f832012-12-12 16:00:35 -0800187void bta_sys_pm_register(tBTA_SYS_CONN_CBACK * p_cback)
188{
189 bta_sys_cb.ppm_cb = p_cback;
190}
191
192/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800193 *
194 * Function bta_sys_conn_open
195 *
196 * Description Called by BTA subsystems when a connection is made to
197 * the service
198 *
199 *
200 * Returns void
201 *
202 ******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -0700203void bta_sys_conn_open(uint8_t id, uint8_t app_id, BD_ADDR peer_addr)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800204{
205 if(bta_sys_cb.prm_cb)
206 {
207
208 bta_sys_cb.prm_cb(BTA_SYS_CONN_OPEN, id, app_id, peer_addr);
209
210 }
211
212 if(bta_sys_cb.ppm_cb)
213 {
214
215 bta_sys_cb.ppm_cb(BTA_SYS_CONN_OPEN, id, app_id, peer_addr);
216
217 }
218}
219
220
221
222/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800223 *
224 * Function bta_sys_conn_close
225 *
226 * Description Called by BTA subsystems when a connection to the service
227 * is closed
228 *
229 *
230 * Returns void
231 *
232 ******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -0700233void bta_sys_conn_close(uint8_t id, uint8_t app_id, BD_ADDR peer_addr)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800234{
235 if(bta_sys_cb.prm_cb)
236 {
237
238 bta_sys_cb.prm_cb(BTA_SYS_CONN_CLOSE, id, app_id, peer_addr);
239
240 }
241
242 if(bta_sys_cb.ppm_cb)
243 {
244
245 bta_sys_cb.ppm_cb(BTA_SYS_CONN_CLOSE, id, app_id, peer_addr);
246
247 }
248}
249
250
251/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800252 *
253 * Function bta_sys_app_open
254 *
255 * Description Called by BTA subsystems when application initiates connection
256 * to a peer device
257 *
258 *
259 * Returns void
260 *
261 ******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -0700262void bta_sys_app_open(uint8_t id, uint8_t app_id, BD_ADDR peer_addr)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800263{
264 if(bta_sys_cb.ppm_cb)
265 {
266 bta_sys_cb.ppm_cb(BTA_SYS_APP_OPEN, id, app_id, peer_addr);
267 }
268}
269
270
271
272/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800273 *
274 * Function bta_sys_app_close
275 *
276 * Description Called by BTA subsystems when application initiates close
277 * of connection to peer device
278 *
279 * Returns void
280 *
281 ******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -0700282void bta_sys_app_close(uint8_t id, uint8_t app_id, BD_ADDR peer_addr)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800283{
284 if(bta_sys_cb.ppm_cb)
285 {
286 bta_sys_cb.ppm_cb(BTA_SYS_APP_CLOSE, id, app_id, peer_addr);
287 }
288}
289
290
291/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800292 *
293 * Function bta_sys_sco_open
294 *
295 * Description Called by BTA subsystems when sco connection for that service
296 * is open
297 *
298 * Returns void
299 *
300 ******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -0700301void bta_sys_sco_open(uint8_t id, uint8_t app_id, BD_ADDR peer_addr)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800302{
303 /* AG triggers p_sco_cb by bta_sys_sco_use. */
304 if((id != BTA_ID_AG) && (bta_sys_cb.p_sco_cb))
305 {
306 /* without querying BTM_GetNumScoLinks() */
307 bta_sys_cb.p_sco_cb(BTA_SYS_SCO_OPEN, 1, app_id, peer_addr);
308 }
309
310 if(bta_sys_cb.ppm_cb)
311 {
312 bta_sys_cb.ppm_cb(BTA_SYS_SCO_OPEN, id, app_id, peer_addr);
313 }
314}
315
316/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800317 *
318 * Function bta_sys_sco_close
319 *
320 * Description Called by BTA subsystems when sco connection for that service
321 * is closed
322 *
323 * Returns void
324 *
325 ******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -0700326void bta_sys_sco_close(uint8_t id, uint8_t app_id, BD_ADDR peer_addr)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800327{
Marie Janssene9e58ce2016-06-17 14:12:17 -0700328 uint8_t num_sco_links;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800329
330 if((id != BTA_ID_AG) && (bta_sys_cb.p_sco_cb))
331 {
332 num_sco_links = BTM_GetNumScoLinks();
333 bta_sys_cb.p_sco_cb(BTA_SYS_SCO_CLOSE, num_sco_links, app_id, peer_addr);
334 }
335
336 if(bta_sys_cb.ppm_cb)
337 {
338 bta_sys_cb.ppm_cb(BTA_SYS_SCO_CLOSE, id, app_id, peer_addr);
339 }
340}
341
342/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800343 *
344 * Function bta_sys_sco_use
345 *
346 * Description Called by BTA subsystems when that service needs to use sco.
347 *
348 *
349 * Returns void
350 *
351 ******************************************************************************/
Myles Watsond35a6482016-10-27 08:52:16 -0700352void bta_sys_sco_use(UNUSED_ATTR uint8_t id, uint8_t app_id,
353 BD_ADDR peer_addr)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800354{
355 /* AV streaming need to be suspended before SCO is connected. */
356 if(bta_sys_cb.p_sco_cb)
357 {
358 /* without querying BTM_GetNumScoLinks() */
359 bta_sys_cb.p_sco_cb(BTA_SYS_SCO_OPEN, 1, app_id, peer_addr);
360 }
361}
362
363/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800364 *
365 * Function bta_sys_sco_unuse
366 *
367 * Description Called by BTA subsystems when sco connection for that service
368 * is no longer needed.
369 *
370 * Returns void
371 *
372 ******************************************************************************/
Myles Watsond35a6482016-10-27 08:52:16 -0700373void bta_sys_sco_unuse(UNUSED_ATTR uint8_t id, uint8_t app_id,
374 BD_ADDR peer_addr)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800375{
Marie Janssene9e58ce2016-06-17 14:12:17 -0700376 uint8_t num_sco_links;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800377
378 if((bta_sys_cb.p_sco_cb))
379 {
380 num_sco_links = BTM_GetNumScoLinks();
381 bta_sys_cb.p_sco_cb(BTA_SYS_SCO_CLOSE, num_sco_links, app_id, peer_addr);
382 }
383}
384/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800385 *
386 * Function bta_sys_chg_ssr_config
387 *
388 * Description Called by BTA subsystems to indicate that the given app SSR setting
389 * need to be changed.
390 *
391 * Returns void
392 *
393 ******************************************************************************/
The Android Open Source Project5738f832012-12-12 16:00:35 -0800394#if (BTM_SSR_INCLUDED == TRUE)
Marie Janssene9e58ce2016-06-17 14:12:17 -0700395void bta_sys_chg_ssr_config (uint8_t id, uint8_t app_id, uint16_t max_latency, uint16_t min_tout)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800396{
397 if(bta_sys_cb.p_ssr_cb)
398 {
399 bta_sys_cb.p_ssr_cb(id, app_id, max_latency, min_tout);
400 }
401}
402#endif
403/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800404 *
405 * Function bta_sys_set_policy
406 *
407 * Description Called by BTA subsystems to indicate that the given link
408 * policy to peer device should be set
409 *
410 * Returns void
411 *
412 ******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -0700413void bta_sys_set_policy (uint8_t id, uint8_t policy, BD_ADDR peer_addr)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800414{
415 if(bta_sys_cb.p_policy_cb)
416 {
417 bta_sys_cb.p_policy_cb(BTA_SYS_PLCY_SET, id, policy, peer_addr);
418 }
419}
420
421/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800422 *
423 * Function bta_sys_clear_policy
424 *
425 * Description Called by BTA subsystems to indicate that the given link
426 * policy to peer device should be clear
427 *
428 * Returns void
429 *
430 ******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -0700431void bta_sys_clear_policy (uint8_t id, uint8_t policy, BD_ADDR peer_addr)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800432{
433 if(bta_sys_cb.p_policy_cb)
434 {
435 bta_sys_cb.p_policy_cb(BTA_SYS_PLCY_CLR, id, policy, peer_addr);
436 }
437}
438
439/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800440 *
441 * Function bta_sys_set_default_policy
442 *
443 * Description Called by BTA subsystems to indicate that the given default
444 * link policy should be set
445 *
446 * Returns void
447 *
448 ******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -0700449void bta_sys_set_default_policy (uint8_t id, uint8_t policy)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800450{
451 if(bta_sys_cb.p_policy_cb)
452 {
453 bta_sys_cb.p_policy_cb(BTA_SYS_PLCY_DEF_SET, id, policy, NULL);
454 }
455}
456
457/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800458 *
459 * Function bta_sys_clear_default_policy
460 *
461 * Description Called by BTA subsystems to indicate that the given default
462 * link policy should be clear
463 *
464 * Returns void
465 *
466 ******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -0700467void bta_sys_clear_default_policy (uint8_t id, uint8_t policy)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800468{
469 if(bta_sys_cb.p_policy_cb)
470 {
471 bta_sys_cb.p_policy_cb(BTA_SYS_PLCY_DEF_CLR, id, policy, NULL);
472 }
473}
474
475/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800476 *
477 * Function bta_sys_idle
478 *
479 * Description Called by BTA subsystems to indicate that the connection to
480 * peer device is idle
481 *
482 * Returns void
483 *
484 ******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -0700485void bta_sys_idle(uint8_t id, uint8_t app_id, BD_ADDR peer_addr)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800486{
487
488 if(bta_sys_cb.prm_cb)
489 {
490
491 bta_sys_cb.prm_cb(BTA_SYS_CONN_IDLE, id, app_id, peer_addr);
492
493 }
494
495 if(bta_sys_cb.ppm_cb)
496 {
497
498 bta_sys_cb.ppm_cb(BTA_SYS_CONN_IDLE, id, app_id, peer_addr);
499 }
500}
501
502/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800503 *
504 * Function bta_sys_busy
505 *
506 * Description Called by BTA subsystems to indicate that the connection to
507 * peer device is busy
508 *
509 * Returns void
510 *
511 ******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -0700512void bta_sys_busy(uint8_t id, uint8_t app_id, BD_ADDR peer_addr)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800513{
514 if(bta_sys_cb.prm_cb)
515 {
516
517 bta_sys_cb.prm_cb(BTA_SYS_CONN_BUSY, id, app_id, peer_addr);
518
519 }
520
521 if(bta_sys_cb.ppm_cb)
522 {
523
524 bta_sys_cb.ppm_cb(BTA_SYS_CONN_BUSY, id, app_id, peer_addr);
525
526 }
527}
528
Chris Manton1e61ce12014-10-24 09:12:41 -0700529#if (BTA_EIR_CANNED_UUID_LIST != TRUE)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800530/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800531 *
532 * Function bta_sys_eir_register
533 *
534 * Description Called by BTA DM to register EIR utility function that can be
535 * used by the other BTA modules to add/remove UUID.
536 *
537 * Returns void
538 *
539 ******************************************************************************/
The Android Open Source Project5738f832012-12-12 16:00:35 -0800540void bta_sys_eir_register(tBTA_SYS_EIR_CBACK * p_cback)
541{
542 bta_sys_cb.eir_cb = p_cback;
543}
544
545/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800546 *
547 * Function bta_sys_add_uuid
548 *
549 * Description Called by BTA subsystems to indicate to DM that new service
550 * class UUID is added.
551 *
552 * Returns void
553 *
554 ******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -0700555void bta_sys_add_uuid(uint16_t uuid16)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800556{
557 if(bta_sys_cb.eir_cb)
558 {
Marie Janssene9e58ce2016-06-17 14:12:17 -0700559 bta_sys_cb.eir_cb(uuid16, true );
The Android Open Source Project5738f832012-12-12 16:00:35 -0800560 }
561}
562
563/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800564 *
565 * Function bta_sys_remove_uuid
566 *
567 * Description Called by BTA subsystems to indicate to DM that the service
568 * class UUID is removed.
569 *
570 * Returns void
571 *
572 ******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -0700573void bta_sys_remove_uuid(uint16_t uuid16)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800574{
575 if(bta_sys_cb.eir_cb)
576 {
Marie Janssene9e58ce2016-06-17 14:12:17 -0700577 bta_sys_cb.eir_cb(uuid16, false);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800578 }
579}
580#endif