• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
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     {
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 *******************************************************************************/
bta_sys_collision_register(UINT8 bta_id,tBTA_SYS_CONN_CBACK * p_cback)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 *******************************************************************************/
bta_sys_notify_collision(BD_ADDR_PTR p_bda)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 *******************************************************************************/
bta_sys_sco_register(tBTA_SYS_CONN_CBACK * p_cback)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 *******************************************************************************/
bta_sys_pm_register(tBTA_SYS_CONN_CBACK * p_cback)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 *******************************************************************************/
bta_sys_conn_open(UINT8 id,UINT8 app_id,BD_ADDR peer_addr)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 *******************************************************************************/
bta_sys_conn_close(UINT8 id,UINT8 app_id,BD_ADDR peer_addr)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 *******************************************************************************/
bta_sys_app_open(UINT8 id,UINT8 app_id,BD_ADDR peer_addr)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 *******************************************************************************/
bta_sys_app_close(UINT8 id,UINT8 app_id,BD_ADDR peer_addr)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 *******************************************************************************/
bta_sys_sco_open(UINT8 id,UINT8 app_id,BD_ADDR peer_addr)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 *******************************************************************************/
bta_sys_sco_close(UINT8 id,UINT8 app_id,BD_ADDR peer_addr)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 *******************************************************************************/
bta_sys_sco_use(UINT8 id,UINT8 app_id,BD_ADDR peer_addr)350 void bta_sys_sco_use(UINT8 id, UINT8 app_id, BD_ADDR peer_addr)
351 {
352     /* AV streaming need to be suspended before SCO is connected. */
353     if(bta_sys_cb.p_sco_cb)
354     {
355         /* without querying BTM_GetNumScoLinks() */
356         bta_sys_cb.p_sco_cb(BTA_SYS_SCO_OPEN, 1, app_id, peer_addr);
357     }
358 }
359 
360 /*******************************************************************************
361 **
362 ** Function         bta_sys_sco_unuse
363 **
364 ** Description      Called by BTA subsystems when sco connection for that service
365 **                  is no longer needed.
366 **
367 ** Returns          void
368 **
369 *******************************************************************************/
bta_sys_sco_unuse(UINT8 id,UINT8 app_id,BD_ADDR peer_addr)370 void bta_sys_sco_unuse(UINT8 id, UINT8 app_id, BD_ADDR peer_addr)
371 {
372     UINT8 num_sco_links;
373 
374     if((bta_sys_cb.p_sco_cb))
375     {
376         num_sco_links = BTM_GetNumScoLinks();
377         bta_sys_cb.p_sco_cb(BTA_SYS_SCO_CLOSE, num_sco_links, app_id, peer_addr);
378     }
379 }
380 /*******************************************************************************
381 **
382 ** Function         bta_sys_chg_ssr_config
383 **
384 ** Description      Called by BTA subsystems to indicate that the given app SSR setting
385 **                  need to be changed.
386 **
387 ** Returns          void
388 **
389 *******************************************************************************/
390 #if (BTM_SSR_INCLUDED == TRUE)
bta_sys_chg_ssr_config(UINT8 id,UINT8 app_id,UINT16 max_latency,UINT16 min_tout)391 void bta_sys_chg_ssr_config (UINT8 id, UINT8 app_id, UINT16 max_latency, UINT16 min_tout)
392 {
393     if(bta_sys_cb.p_ssr_cb)
394     {
395         bta_sys_cb.p_ssr_cb(id, app_id, max_latency, min_tout);
396     }
397 }
398 #endif
399 /*******************************************************************************
400 **
401 ** Function         bta_sys_set_policy
402 **
403 ** Description      Called by BTA subsystems to indicate that the given link
404 **                  policy to peer device should be set
405 **
406 ** Returns          void
407 **
408 *******************************************************************************/
bta_sys_set_policy(UINT8 id,UINT8 policy,BD_ADDR peer_addr)409 void bta_sys_set_policy (UINT8 id, UINT8 policy, BD_ADDR peer_addr)
410 {
411     if(bta_sys_cb.p_policy_cb)
412     {
413         bta_sys_cb.p_policy_cb(BTA_SYS_PLCY_SET, id, policy, peer_addr);
414     }
415 }
416 
417 /*******************************************************************************
418 **
419 ** Function         bta_sys_clear_policy
420 **
421 ** Description      Called by BTA subsystems to indicate that the given link
422 **                  policy to peer device should be clear
423 **
424 ** Returns          void
425 **
426 *******************************************************************************/
bta_sys_clear_policy(UINT8 id,UINT8 policy,BD_ADDR peer_addr)427 void bta_sys_clear_policy (UINT8 id, UINT8 policy, BD_ADDR peer_addr)
428 {
429     if(bta_sys_cb.p_policy_cb)
430     {
431         bta_sys_cb.p_policy_cb(BTA_SYS_PLCY_CLR, id, policy, peer_addr);
432     }
433 }
434 
435 /*******************************************************************************
436 **
437 ** Function         bta_sys_set_default_policy
438 **
439 ** Description      Called by BTA subsystems to indicate that the given default
440 **                  link policy should be set
441 **
442 ** Returns          void
443 **
444 *******************************************************************************/
bta_sys_set_default_policy(UINT8 id,UINT8 policy)445 void bta_sys_set_default_policy (UINT8 id, UINT8 policy)
446 {
447     if(bta_sys_cb.p_policy_cb)
448     {
449         bta_sys_cb.p_policy_cb(BTA_SYS_PLCY_DEF_SET, id, policy, NULL);
450     }
451 }
452 
453 /*******************************************************************************
454 **
455 ** Function         bta_sys_clear_default_policy
456 **
457 ** Description      Called by BTA subsystems to indicate that the given default
458 **                  link policy should be clear
459 **
460 ** Returns          void
461 **
462 *******************************************************************************/
bta_sys_clear_default_policy(UINT8 id,UINT8 policy)463 void bta_sys_clear_default_policy (UINT8 id, UINT8 policy)
464 {
465     if(bta_sys_cb.p_policy_cb)
466     {
467         bta_sys_cb.p_policy_cb(BTA_SYS_PLCY_DEF_CLR, id, policy, NULL);
468     }
469 }
470 
471 /*******************************************************************************
472 **
473 ** Function         bta_sys_idle
474 **
475 ** Description      Called by BTA subsystems to indicate that the connection to
476 **                  peer device is idle
477 **
478 ** Returns          void
479 **
480 *******************************************************************************/
bta_sys_idle(UINT8 id,UINT8 app_id,BD_ADDR peer_addr)481 void bta_sys_idle(UINT8 id, UINT8 app_id, BD_ADDR peer_addr)
482 {
483 
484     if(bta_sys_cb.prm_cb)
485     {
486 
487         bta_sys_cb.prm_cb(BTA_SYS_CONN_IDLE, id, app_id, peer_addr);
488 
489     }
490 
491     if(bta_sys_cb.ppm_cb)
492     {
493 
494         bta_sys_cb.ppm_cb(BTA_SYS_CONN_IDLE, id, app_id, peer_addr);
495     }
496 }
497 
498 /*******************************************************************************
499 **
500 ** Function         bta_sys_busy
501 **
502 ** Description      Called by BTA subsystems to indicate that the connection to
503 **                  peer device is busy
504 **
505 ** Returns          void
506 **
507 *******************************************************************************/
bta_sys_busy(UINT8 id,UINT8 app_id,BD_ADDR peer_addr)508 void bta_sys_busy(UINT8 id, UINT8 app_id, BD_ADDR peer_addr)
509 {
510     if(bta_sys_cb.prm_cb)
511     {
512 
513         bta_sys_cb.prm_cb(BTA_SYS_CONN_BUSY, id, app_id, peer_addr);
514 
515     }
516 
517     if(bta_sys_cb.ppm_cb)
518     {
519 
520         bta_sys_cb.ppm_cb(BTA_SYS_CONN_BUSY, id, app_id, peer_addr);
521 
522     }
523 }
524 
525 #if ( BTM_EIR_SERVER_INCLUDED == TRUE )&&(BTA_EIR_CANNED_UUID_LIST != TRUE)
526 /*******************************************************************************
527 **
528 ** Function         bta_sys_eir_register
529 **
530 ** Description      Called by BTA DM to register EIR utility function that can be
531 **                  used by the other BTA modules to add/remove UUID.
532 **
533 ** Returns          void
534 **
535 *******************************************************************************/
bta_sys_eir_register(tBTA_SYS_EIR_CBACK * p_cback)536 void bta_sys_eir_register(tBTA_SYS_EIR_CBACK * p_cback)
537 {
538     bta_sys_cb.eir_cb = p_cback;
539 }
540 
541 /*******************************************************************************
542 **
543 ** Function         bta_sys_add_uuid
544 **
545 ** Description      Called by BTA subsystems to indicate to DM that new service
546 **                  class UUID is added.
547 **
548 ** Returns          void
549 **
550 *******************************************************************************/
bta_sys_add_uuid(UINT16 uuid16)551 void bta_sys_add_uuid(UINT16 uuid16)
552 {
553     if(bta_sys_cb.eir_cb)
554     {
555         bta_sys_cb.eir_cb(uuid16, TRUE );
556     }
557 }
558 
559 /*******************************************************************************
560 **
561 ** Function         bta_sys_remove_uuid
562 **
563 ** Description      Called by BTA subsystems to indicate to DM that the service
564 **                  class UUID is removed.
565 **
566 ** Returns          void
567 **
568 *******************************************************************************/
bta_sys_remove_uuid(UINT16 uuid16)569 void bta_sys_remove_uuid(UINT16 uuid16)
570 {
571     if(bta_sys_cb.eir_cb)
572     {
573         bta_sys_cb.eir_cb(uuid16, FALSE);
574     }
575 }
576 #endif
577 
578