• 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 <stddef.h>
26 #include "bta_api.h"
27 #include "bta_sys.h"
28 #include "bta_sys_int.h"
29 #include "gki.h"
30 #include "utl.h"
31 
32 /*******************************************************************************
33 **
34 ** Function         bta_sys_rm_register
35 **
36 ** Description      Called by BTA DM to register role management callbacks
37 **
38 **
39 ** Returns          void
40 **
41 *******************************************************************************/
bta_sys_rm_register(tBTA_SYS_CONN_CBACK * p_cback)42 void bta_sys_rm_register(tBTA_SYS_CONN_CBACK * p_cback)
43 {
44     bta_sys_cb.prm_cb = p_cback;
45 }
46 
47 
48 /*******************************************************************************
49 **
50 ** Function         bta_sys_policy_register
51 **
52 ** Description      Called by BTA DM to register link policy change callbacks
53 **
54 **
55 ** Returns          void
56 **
57 *******************************************************************************/
bta_sys_policy_register(tBTA_SYS_CONN_CBACK * p_cback)58 void bta_sys_policy_register(tBTA_SYS_CONN_CBACK * p_cback)
59 {
60     bta_sys_cb.p_policy_cb = p_cback;
61 }
62 
63 /*******************************************************************************
64 **
65 ** Function         bta_sys_role_chg_register
66 **
67 ** Description      Called by BTA AV to register role change callbacks
68 **
69 **
70 ** Returns          void
71 **
72 *******************************************************************************/
bta_sys_role_chg_register(tBTA_SYS_CONN_CBACK * p_cback)73 void bta_sys_role_chg_register(tBTA_SYS_CONN_CBACK * p_cback)
74 {
75     bta_sys_cb.p_role_cb = p_cback;
76 }
77 /*******************************************************************************
78 **
79 ** Function         bta_sys_ssr_cfg_register
80 **
81 ** Description      Called by BTA DM to register SSR configuration callback
82 **
83 **
84 ** Returns          void
85 **
86 *******************************************************************************/
87 #if (BTM_SSR_INCLUDED == TRUE)
bta_sys_ssr_cfg_register(tBTA_SYS_SSR_CFG_CBACK * p_cback)88 void bta_sys_ssr_cfg_register(tBTA_SYS_SSR_CFG_CBACK * p_cback)
89 {
90     bta_sys_cb.p_ssr_cb = p_cback;
91 }
92 #endif
93 /*******************************************************************************
94 **
95 ** Function         bta_sys_role_chg_register
96 **
97 ** Description      Called by BTA AV to register role change callbacks
98 **
99 **
100 ** Returns          void
101 **
102 *******************************************************************************/
bta_sys_notify_role_chg(BD_ADDR_PTR p_bda,UINT8 new_role,UINT8 hci_status)103 void bta_sys_notify_role_chg(BD_ADDR_PTR p_bda, UINT8 new_role, UINT8 hci_status)
104 {
105     if (bta_sys_cb.p_role_cb)
106     {
107         bta_sys_cb.p_role_cb(BTA_SYS_ROLE_CHANGE, new_role, hci_status, p_bda);
108     }
109 }
110 
111 /*******************************************************************************
112 **
113 ** Function         bta_sys_collision_register
114 **
115 ** Description      Called by any BTA module to register for collision event.
116 **
117 **
118 ** Returns          void
119 **
120 *******************************************************************************/
bta_sys_collision_register(UINT8 bta_id,tBTA_SYS_CONN_CBACK * p_cback)121 void bta_sys_collision_register(UINT8 bta_id, tBTA_SYS_CONN_CBACK *p_cback)
122 {
123     UINT8 index;
124 
125     for (index = 0; index < MAX_COLLISION_REG; index++)
126     {
127         if ((bta_sys_cb.colli_reg.id[index] == bta_id) ||
128             (bta_sys_cb.colli_reg.id[index] == 0))
129         {
130             bta_sys_cb.colli_reg.id[index] = bta_id;
131             bta_sys_cb.colli_reg.p_coll_cback[index] = p_cback;
132             return;
133         }
134     }
135 }
136 
137 /*******************************************************************************
138 **
139 ** Function         bta_sys_notify_collision
140 **
141 ** Description      Called by BTA DM to notify collision event.
142 **
143 **
144 ** Returns          void
145 **
146 *******************************************************************************/
bta_sys_notify_collision(BD_ADDR_PTR p_bda)147 void bta_sys_notify_collision (BD_ADDR_PTR p_bda)
148 {
149     UINT8 index;
150 
151     for (index = 0; index < MAX_COLLISION_REG; index++)
152     {
153         if ((bta_sys_cb.colli_reg.id[index] != 0) &&
154             (bta_sys_cb.colli_reg.p_coll_cback[index] != NULL))
155         {
156             bta_sys_cb.colli_reg.p_coll_cback[index] (0, BTA_ID_SYS, 0, p_bda);
157         }
158     }
159 }
160 
161 /*******************************************************************************
162 **
163 ** Function         bta_sys_sco_register
164 **
165 ** Description      Called by BTA AV to register sco connection change callbacks
166 **
167 **
168 ** Returns          void
169 **
170 *******************************************************************************/
bta_sys_sco_register(tBTA_SYS_CONN_CBACK * p_cback)171 void bta_sys_sco_register(tBTA_SYS_CONN_CBACK * p_cback)
172 {
173     bta_sys_cb.p_sco_cb = p_cback;
174 }
175 
176 /*******************************************************************************
177 **
178 ** Function         bta_sys_pm_register
179 **
180 ** Description      Called by BTA DM to register power management callbacks
181 **
182 **
183 ** Returns          void
184 **
185 *******************************************************************************/
bta_sys_pm_register(tBTA_SYS_CONN_CBACK * p_cback)186 void bta_sys_pm_register(tBTA_SYS_CONN_CBACK * p_cback)
187 {
188     bta_sys_cb.ppm_cb = p_cback;
189 }
190 
191 /*******************************************************************************
192 **
193 ** Function         bta_sys_conn_open
194 **
195 ** Description      Called by BTA subsystems when a connection is made to
196 **                  the service
197 **
198 **
199 ** Returns          void
200 **
201 *******************************************************************************/
bta_sys_conn_open(UINT8 id,UINT8 app_id,BD_ADDR peer_addr)202 void bta_sys_conn_open(UINT8 id, UINT8 app_id, BD_ADDR peer_addr)
203 {
204     if(bta_sys_cb.prm_cb)
205     {
206 
207         bta_sys_cb.prm_cb(BTA_SYS_CONN_OPEN, id, app_id, peer_addr);
208 
209     }
210 
211     if(bta_sys_cb.ppm_cb)
212     {
213 
214         bta_sys_cb.ppm_cb(BTA_SYS_CONN_OPEN, id, app_id, peer_addr);
215 
216     }
217 }
218 
219 
220 
221 /*******************************************************************************
222 **
223 ** Function         bta_sys_conn_close
224 **
225 ** Description      Called by BTA subsystems when a connection to the service
226 **                  is closed
227 **
228 **
229 ** Returns          void
230 **
231 *******************************************************************************/
bta_sys_conn_close(UINT8 id,UINT8 app_id,BD_ADDR peer_addr)232 void bta_sys_conn_close(UINT8 id, UINT8 app_id, BD_ADDR peer_addr)
233 {
234     if(bta_sys_cb.prm_cb)
235     {
236 
237         bta_sys_cb.prm_cb(BTA_SYS_CONN_CLOSE, id, app_id, peer_addr);
238 
239     }
240 
241     if(bta_sys_cb.ppm_cb)
242     {
243 
244         bta_sys_cb.ppm_cb(BTA_SYS_CONN_CLOSE, id, app_id, peer_addr);
245 
246     }
247 }
248 
249 
250 /*******************************************************************************
251 **
252 ** Function         bta_sys_app_open
253 **
254 ** Description      Called by BTA subsystems when application initiates connection
255 **                  to a peer device
256 **
257 **
258 ** Returns          void
259 **
260 *******************************************************************************/
bta_sys_app_open(UINT8 id,UINT8 app_id,BD_ADDR peer_addr)261 void bta_sys_app_open(UINT8 id, UINT8 app_id, BD_ADDR peer_addr)
262 {
263     if(bta_sys_cb.ppm_cb)
264     {
265         bta_sys_cb.ppm_cb(BTA_SYS_APP_OPEN, id, app_id, peer_addr);
266     }
267 }
268 
269 
270 
271 /*******************************************************************************
272 **
273 ** Function         bta_sys_app_close
274 **
275 ** Description      Called by BTA subsystems when application initiates close
276 **                  of connection to peer device
277 **
278 ** Returns          void
279 **
280 *******************************************************************************/
bta_sys_app_close(UINT8 id,UINT8 app_id,BD_ADDR peer_addr)281 void bta_sys_app_close(UINT8 id, UINT8 app_id, BD_ADDR peer_addr)
282 {
283     if(bta_sys_cb.ppm_cb)
284     {
285         bta_sys_cb.ppm_cb(BTA_SYS_APP_CLOSE, id, app_id, peer_addr);
286     }
287 }
288 
289 
290 /*******************************************************************************
291 **
292 ** Function         bta_sys_sco_open
293 **
294 ** Description      Called by BTA subsystems when sco connection for that service
295 **                  is open
296 **
297 ** Returns          void
298 **
299 *******************************************************************************/
bta_sys_sco_open(UINT8 id,UINT8 app_id,BD_ADDR peer_addr)300 void bta_sys_sco_open(UINT8 id, UINT8 app_id, BD_ADDR peer_addr)
301 {
302     /* AG triggers p_sco_cb by bta_sys_sco_use. */
303     if((id != BTA_ID_AG) && (bta_sys_cb.p_sco_cb))
304     {
305         /* without querying BTM_GetNumScoLinks() */
306         bta_sys_cb.p_sco_cb(BTA_SYS_SCO_OPEN, 1, app_id, peer_addr);
307     }
308 
309     if(bta_sys_cb.ppm_cb)
310     {
311         bta_sys_cb.ppm_cb(BTA_SYS_SCO_OPEN, id, app_id, peer_addr);
312     }
313 }
314 
315 /*******************************************************************************
316 **
317 ** Function         bta_sys_sco_close
318 **
319 ** Description      Called by BTA subsystems when sco connection for that service
320 **                  is closed
321 **
322 ** Returns          void
323 **
324 *******************************************************************************/
bta_sys_sco_close(UINT8 id,UINT8 app_id,BD_ADDR peer_addr)325 void bta_sys_sco_close(UINT8 id, UINT8 app_id, BD_ADDR peer_addr)
326 {
327     UINT8 num_sco_links;
328 
329     if((id != BTA_ID_AG) && (bta_sys_cb.p_sco_cb))
330     {
331         num_sco_links = BTM_GetNumScoLinks();
332         bta_sys_cb.p_sco_cb(BTA_SYS_SCO_CLOSE, num_sco_links, app_id, peer_addr);
333     }
334 
335     if(bta_sys_cb.ppm_cb)
336     {
337         bta_sys_cb.ppm_cb(BTA_SYS_SCO_CLOSE, id, app_id, peer_addr);
338     }
339 }
340 
341 /*******************************************************************************
342 **
343 ** Function         bta_sys_sco_use
344 **
345 ** Description      Called by BTA subsystems when that service needs to use sco.
346 **
347 **
348 ** Returns          void
349 **
350 *******************************************************************************/
bta_sys_sco_use(UINT8 id,UINT8 app_id,BD_ADDR peer_addr)351 void bta_sys_sco_use(UINT8 id, UINT8 app_id, BD_ADDR peer_addr)
352 {
353     UNUSED(id);
354 
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 /*******************************************************************************
364 **
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 *******************************************************************************/
bta_sys_sco_unuse(UINT8 id,UINT8 app_id,BD_ADDR peer_addr)373 void bta_sys_sco_unuse(UINT8 id, UINT8 app_id, BD_ADDR peer_addr)
374 {
375     UINT8 num_sco_links;
376     UNUSED(id);
377 
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 /*******************************************************************************
385 **
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 *******************************************************************************/
394 #if (BTM_SSR_INCLUDED == TRUE)
bta_sys_chg_ssr_config(UINT8 id,UINT8 app_id,UINT16 max_latency,UINT16 min_tout)395 void bta_sys_chg_ssr_config (UINT8 id, UINT8 app_id, UINT16 max_latency, UINT16 min_tout)
396 {
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 /*******************************************************************************
404 **
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 *******************************************************************************/
bta_sys_set_policy(UINT8 id,UINT8 policy,BD_ADDR peer_addr)413 void bta_sys_set_policy (UINT8 id, UINT8 policy, BD_ADDR peer_addr)
414 {
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 /*******************************************************************************
422 **
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 *******************************************************************************/
bta_sys_clear_policy(UINT8 id,UINT8 policy,BD_ADDR peer_addr)431 void bta_sys_clear_policy (UINT8 id, UINT8 policy, BD_ADDR peer_addr)
432 {
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 /*******************************************************************************
440 **
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 *******************************************************************************/
bta_sys_set_default_policy(UINT8 id,UINT8 policy)449 void bta_sys_set_default_policy (UINT8 id, UINT8 policy)
450 {
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 /*******************************************************************************
458 **
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 *******************************************************************************/
bta_sys_clear_default_policy(UINT8 id,UINT8 policy)467 void bta_sys_clear_default_policy (UINT8 id, UINT8 policy)
468 {
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 /*******************************************************************************
476 **
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 *******************************************************************************/
bta_sys_idle(UINT8 id,UINT8 app_id,BD_ADDR peer_addr)485 void bta_sys_idle(UINT8 id, UINT8 app_id, BD_ADDR peer_addr)
486 {
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 /*******************************************************************************
503 **
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 *******************************************************************************/
bta_sys_busy(UINT8 id,UINT8 app_id,BD_ADDR peer_addr)512 void bta_sys_busy(UINT8 id, UINT8 app_id, BD_ADDR peer_addr)
513 {
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 
529 #if (BTA_EIR_CANNED_UUID_LIST != TRUE)
530 /*******************************************************************************
531 **
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 *******************************************************************************/
bta_sys_eir_register(tBTA_SYS_EIR_CBACK * p_cback)540 void bta_sys_eir_register(tBTA_SYS_EIR_CBACK * p_cback)
541 {
542     bta_sys_cb.eir_cb = p_cback;
543 }
544 
545 /*******************************************************************************
546 **
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 *******************************************************************************/
bta_sys_add_uuid(UINT16 uuid16)555 void bta_sys_add_uuid(UINT16 uuid16)
556 {
557     if(bta_sys_cb.eir_cb)
558     {
559         bta_sys_cb.eir_cb(uuid16, TRUE );
560     }
561 }
562 
563 /*******************************************************************************
564 **
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 *******************************************************************************/
bta_sys_remove_uuid(UINT16 uuid16)573 void bta_sys_remove_uuid(UINT16 uuid16)
574 {
575     if(bta_sys_cb.eir_cb)
576     {
577         bta_sys_cb.eir_cb(uuid16, FALSE);
578     }
579 }
580 #endif
581 
582 /*******************************************************************************
583 **
584 ** Function         bta_sys_vs_hdl
585 **
586 ** Description      Called by BTA subsystems to execute a VS event handler function
587 **
588 ** Returns          void
589 **
590 *******************************************************************************/
bta_sys_vs_hdl(UINT16 evt,void * p)591 BOOLEAN bta_sys_vs_hdl(UINT16 evt, void *p)
592 {
593     if (bta_sys_cb.p_vs_evt_hdlr)
594         return (*bta_sys_cb.p_vs_evt_hdlr)(evt, p);
595 
596     return FALSE;
597 }
598 
599