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