@@ -101,9 +101,6 @@ int bt_cap_commander_discover(struct bt_conn *conn)
101
101
}
102
102
103
103
#if defined(CONFIG_BT_BAP_BROADCAST_ASSISTANT )
104
- static struct bt_bap_broadcast_assistant_cb broadcast_assistant_cb ;
105
- static bool broadcast_assistant_cb_registered ;
106
-
107
104
static void
108
105
copy_broadcast_reception_start_param (struct bt_bap_broadcast_assistant_add_src_param * add_src_param ,
109
106
struct cap_broadcast_reception_start * start_param )
@@ -172,22 +169,6 @@ static void cap_commander_broadcast_assistant_add_src_cb(struct bt_conn *conn, i
172
169
}
173
170
}
174
171
175
- static int cap_commander_register_broadcast_assistant_cb (void )
176
- {
177
- int err ;
178
-
179
- err = bt_bap_broadcast_assistant_register_cb (& broadcast_assistant_cb );
180
- if (err != 0 ) {
181
- LOG_DBG ("Failed to register broadcast assistant callbacks: %d" , err );
182
-
183
- return - ENOEXEC ;
184
- }
185
-
186
- broadcast_assistant_cb_registered = true;
187
-
188
- return 0 ;
189
- }
190
-
191
172
static bool valid_broadcast_reception_start_param (
192
173
const struct bt_cap_commander_broadcast_reception_start_param * param )
193
174
{
@@ -335,11 +316,7 @@ int cap_commander_broadcast_reception_start(
335
316
struct bt_conn * conn ;
336
317
int err ;
337
318
338
- broadcast_assistant_cb .add_src = cap_commander_broadcast_assistant_add_src_cb ;
339
- if (!broadcast_assistant_cb_registered ) {
340
- err = cap_commander_register_broadcast_assistant_cb ();
341
- __ASSERT (err == 0 , "Failed to register broadcast assistant callbacks: %d" , err );
342
- }
319
+ cap_commander_register_broadcast_assistant_callbacks ();
343
320
344
321
bt_cap_common_set_proc (BT_CAP_COMMON_PROC_TYPE_BROADCAST_RECEPTION_START , param -> count );
345
322
@@ -356,8 +333,6 @@ int cap_commander_broadcast_reception_start(
356
333
if (member_conn == NULL ) {
357
334
LOG_DBG ("Invalid param->members[%zu]" , i );
358
335
359
- bt_cap_common_clear_active_proc ();
360
-
361
336
return - EINVAL ;
362
337
}
363
338
@@ -389,8 +364,6 @@ int cap_commander_broadcast_reception_start(
389
364
if (err != 0 ) {
390
365
LOG_DBG ("Failed to start broadcast reception for conn %p: %d" , (void * )conn , err );
391
366
392
- bt_cap_common_clear_active_proc ();
393
-
394
367
return - ENOEXEC ;
395
368
}
396
369
@@ -400,6 +373,8 @@ int cap_commander_broadcast_reception_start(
400
373
int bt_cap_commander_broadcast_reception_start (
401
374
const struct bt_cap_commander_broadcast_reception_start_param * param )
402
375
{
376
+ int err ;
377
+
403
378
if (!valid_broadcast_reception_start_param (param )) {
404
379
return - EINVAL ;
405
380
}
@@ -410,7 +385,12 @@ int bt_cap_commander_broadcast_reception_start(
410
385
return - EBUSY ;
411
386
}
412
387
413
- return cap_commander_broadcast_reception_start (param );
388
+ err = cap_commander_broadcast_reception_start (param );
389
+ if (err != 0 ) {
390
+ bt_cap_common_clear_active_proc ();
391
+ }
392
+
393
+ return err ;
414
394
}
415
395
416
396
static void
@@ -436,6 +416,10 @@ static void cap_commander_broadcast_assistant_recv_state_cb(
436
416
return ;
437
417
}
438
418
419
+ if (IS_ENABLED (CONFIG_BT_CAP_HANDOVER ) && bt_cap_common_handover_is_active ()) {
420
+ bt_cap_handover_receive_state_updated (conn , state );
421
+ }
422
+
439
423
if (bt_cap_common_conn_in_active_proc (conn ) &&
440
424
active_proc -> proc_type == BT_CAP_COMMON_PROC_TYPE_BROADCAST_RECEPTION_STOP ) {
441
425
@@ -539,7 +523,7 @@ static void cap_commander_broadcast_assistant_mod_src_cb(struct bt_conn *conn, i
539
523
}
540
524
}
541
525
542
- static bool valid_broadcast_reception_stop_param (
526
+ bool bt_cap_commander_valid_broadcast_reception_stop_param (
543
527
const struct bt_cap_commander_broadcast_reception_stop_param * param )
544
528
{
545
529
CHECKIF (param == NULL ) {
@@ -607,7 +591,7 @@ static bool valid_broadcast_reception_stop_param(
607
591
return true;
608
592
}
609
593
610
- int bt_cap_commander_broadcast_reception_stop (
594
+ int cap_commander_broadcast_reception_stop (
611
595
const struct bt_cap_commander_broadcast_reception_stop_param * param )
612
596
{
613
597
struct bt_bap_broadcast_assistant_mod_src_param mod_src_param = {0 };
@@ -616,23 +600,7 @@ int bt_cap_commander_broadcast_reception_stop(
616
600
struct bt_conn * conn ;
617
601
int err ;
618
602
619
- if (!valid_broadcast_reception_stop_param (param )) {
620
- return - EINVAL ;
621
- }
622
-
623
- if (bt_cap_common_test_and_set_proc_active ()) {
624
- LOG_DBG ("A CAP procedure is already in progress" );
625
-
626
- return - EBUSY ;
627
- }
628
-
629
- broadcast_assistant_cb .mod_src = cap_commander_broadcast_assistant_mod_src_cb ;
630
- broadcast_assistant_cb .rem_src = cap_commander_broadcast_assistant_rem_src_cb ;
631
- broadcast_assistant_cb .recv_state = cap_commander_broadcast_assistant_recv_state_cb ;
632
- if (!broadcast_assistant_cb_registered ) {
633
- err = cap_commander_register_broadcast_assistant_cb ();
634
- __ASSERT (err == 0 , "Failed to register broadcast assistant callbacks: %d" , err );
635
- }
603
+ cap_commander_register_broadcast_assistant_callbacks ();
636
604
637
605
bt_cap_common_set_proc (BT_CAP_COMMON_PROC_TYPE_BROADCAST_RECEPTION_STOP , param -> count );
638
606
@@ -649,8 +617,6 @@ int bt_cap_commander_broadcast_reception_stop(
649
617
if (member_conn == NULL ) {
650
618
LOG_DBG ("Invalid param->member[%zu]" , i );
651
619
652
- bt_cap_common_clear_active_proc ();
653
-
654
620
return - EINVAL ;
655
621
}
656
622
@@ -678,14 +644,35 @@ int bt_cap_commander_broadcast_reception_stop(
678
644
if (err != 0 ) {
679
645
LOG_DBG ("Failed to stop broadcast reception for conn %p: %d" , (void * )conn , err );
680
646
681
- bt_cap_common_clear_active_proc ();
682
-
683
647
return - ENOEXEC ;
684
648
}
685
649
686
650
return 0 ;
687
651
}
688
652
653
+ int bt_cap_commander_broadcast_reception_stop (
654
+ const struct bt_cap_commander_broadcast_reception_stop_param * param )
655
+ {
656
+ int err ;
657
+
658
+ if (!bt_cap_commander_valid_broadcast_reception_stop_param (param )) {
659
+ return - EINVAL ;
660
+ }
661
+
662
+ if (bt_cap_common_test_and_set_proc_active ()) {
663
+ LOG_DBG ("A CAP procedure is already in progress" );
664
+
665
+ return - EBUSY ;
666
+ }
667
+
668
+ err = cap_commander_broadcast_reception_stop (param );
669
+ if (err != 0 ) {
670
+ bt_cap_common_clear_active_proc ();
671
+ }
672
+
673
+ return err ;
674
+ }
675
+
689
676
static void cap_commander_broadcast_assistant_set_broadcast_code_cb (struct bt_conn * conn , int err )
690
677
{
691
678
struct bt_cap_common_proc * active_proc = bt_cap_common_get_active_proc ();
@@ -811,12 +798,7 @@ int bt_cap_commander_distribute_broadcast_code(
811
798
return - EBUSY ;
812
799
}
813
800
814
- broadcast_assistant_cb .broadcast_code =
815
- cap_commander_broadcast_assistant_set_broadcast_code_cb ;
816
- if (!broadcast_assistant_cb_registered ) {
817
- err = cap_commander_register_broadcast_assistant_cb ();
818
- __ASSERT (err == 0 , "Failed to register broadcast assistant callbacks: %d" , err );
819
- }
801
+ cap_commander_register_broadcast_assistant_callbacks ();
820
802
821
803
bt_cap_common_set_proc (BT_CAP_COMMON_PROC_TYPE_DISTRIBUTE_BROADCAST_CODE , param -> count );
822
804
@@ -870,6 +852,26 @@ int bt_cap_commander_distribute_broadcast_code(
870
852
return 0 ;
871
853
}
872
854
855
+ void cap_commander_register_broadcast_assistant_callbacks (void )
856
+ {
857
+ static bool broadcast_assistant_cb_registered ;
858
+
859
+ if (!broadcast_assistant_cb_registered ) {
860
+ static struct bt_bap_broadcast_assistant_cb broadcast_assistant_cb = {
861
+ .add_src = cap_commander_broadcast_assistant_add_src_cb ,
862
+ .mod_src = cap_commander_broadcast_assistant_mod_src_cb ,
863
+ .rem_src = cap_commander_broadcast_assistant_rem_src_cb ,
864
+ .recv_state = cap_commander_broadcast_assistant_recv_state_cb ,
865
+ .broadcast_code = cap_commander_broadcast_assistant_set_broadcast_code_cb ,
866
+ };
867
+ int err ;
868
+
869
+ err = bt_bap_broadcast_assistant_register_cb (& broadcast_assistant_cb );
870
+ __ASSERT (err == 0 , "Failed to register broadcast assistant callbacks: %d" , err );
871
+
872
+ broadcast_assistant_cb_registered = true;
873
+ }
874
+ }
873
875
#endif /* CONFIG_BT_BAP_BROADCAST_ASSISTANT */
874
876
875
877
static void cap_commander_proc_complete (void )
@@ -884,13 +886,30 @@ static void cap_commander_proc_complete(void)
884
886
proc_type = active_proc -> proc_type ;
885
887
886
888
if (IS_ENABLED (CONFIG_BT_CAP_HANDOVER ) && bt_cap_common_handover_is_active ()) {
887
- /* Complete handover procedure. At this point we do not know if the remote
888
- * device will attempt to use PAST or scan for itself, so it's best to leave
889
- * this up to the application layer
890
- */
891
- __ASSERT_NO_MSG (proc_type == BT_CAP_COMMON_PROC_TYPE_BROADCAST_RECEPTION_START );
889
+ if (proc_type == BT_CAP_COMMON_PROC_TYPE_BROADCAST_RECEPTION_START ) {
890
+ /* Complete unicast to broadcast handover procedure. At this point we do not
891
+ * know if the remote device will attempt to use PAST or scan for itself, so
892
+ * it's best to leave this up to the application layer
893
+ */
894
+
895
+ bt_cap_handover_complete ();
896
+ } else if (proc_type == BT_CAP_COMMON_PROC_TYPE_BROADCAST_RECEPTION_STOP ) {
897
+ if (err != 0 ) {
898
+ bt_cap_handover_complete ();
899
+ } else {
900
+ /* We've successfully stopped broadcast reception on all the
901
+ * acceptors. We can now stop and delete the broadcast source before
902
+ * starting the unicast audio
903
+ */
904
+ err = bt_cap_handover_broadcast_reception_stopped ();
905
+ if (err != 0 ) {
906
+ bt_cap_handover_complete ();
907
+ }
908
+ }
909
+ } else {
910
+ __ASSERT (false, "invalid proc_type %d" , proc_type );
911
+ }
892
912
893
- bt_cap_handover_proc_complete ();
894
913
return ;
895
914
}
896
915
0 commit comments