@@ -70,8 +70,8 @@ static struct bt_bap_scan_delegator_mod_src_param mod_src_param;
70
70
71
71
static void broadcast_sink_cleanup (struct bt_bap_broadcast_sink * sink );
72
72
73
- static bool find_recv_state_by_sink_cb (const struct bt_bap_scan_delegator_recv_state * recv_state ,
74
- void * user_data )
73
+ static bool find_recv_state_by_src_id_cb (const struct bt_bap_scan_delegator_recv_state * recv_state ,
74
+ void * user_data )
75
75
{
76
76
const struct bt_bap_broadcast_sink * sink = user_data ;
77
77
@@ -83,34 +83,35 @@ static bool find_recv_state_by_sink_cb(const struct bt_bap_scan_delegator_recv_s
83
83
return false;
84
84
}
85
85
86
- static bool find_recv_state_by_pa_sync_cb (const struct bt_bap_scan_delegator_recv_state * recv_state ,
87
- void * user_data )
86
+ static bool
87
+ find_recv_state_by_sink_fields_cb (const struct bt_bap_scan_delegator_recv_state * recv_state ,
88
+ void * user_data )
88
89
{
89
- struct bt_le_per_adv_sync * sync = user_data ;
90
+ const struct bt_bap_broadcast_sink * sink = user_data ;
90
91
struct bt_le_per_adv_sync_info sync_info ;
91
92
int err ;
92
93
93
- err = bt_le_per_adv_sync_get_info (sync , & sync_info );
94
+ err = bt_le_per_adv_sync_get_info (sink -> pa_sync , & sync_info );
94
95
if (err != 0 ) {
95
96
LOG_DBG ("Failed to get sync info: %d" , err );
96
97
97
98
return false;
98
99
}
99
100
100
- if ( bt_addr_le_eq ( & recv_state -> addr , & sync_info . addr ) &&
101
- recv_state -> adv_sid == sync_info . sid ) {
102
- return true;
103
- }
104
-
105
- return false ;
101
+ /* BAP 6.5.4 states that the combined Source_Address_Type, Source_Adv_SID, and Broadcast_ID
102
+ * fields are what makes a receive state unique.
103
+ */
104
+ return recv_state -> addr . type == sync_info . addr . type &&
105
+ recv_state -> adv_sid == sync_info . sid &&
106
+ recv_state -> broadcast_id == sink -> broadcast_id ;
106
107
};
107
108
108
109
static void update_recv_state_big_synced (const struct bt_bap_broadcast_sink * sink )
109
110
{
110
111
const struct bt_bap_scan_delegator_recv_state * recv_state ;
111
112
int err ;
112
113
113
- recv_state = bt_bap_scan_delegator_find_state (find_recv_state_by_sink_cb , (void * )sink );
114
+ recv_state = bt_bap_scan_delegator_find_state (find_recv_state_by_src_id_cb , (void * )sink );
114
115
if (recv_state == NULL ) {
115
116
LOG_WRN ("Failed to find receive state for sink %p" , sink );
116
117
@@ -156,7 +157,7 @@ static void update_recv_state_big_cleared(const struct bt_bap_broadcast_sink *si
156
157
bool sink_is_streaming = false;
157
158
int err ;
158
159
159
- recv_state = bt_bap_scan_delegator_find_state (find_recv_state_by_sink_cb , (void * )sink );
160
+ recv_state = bt_bap_scan_delegator_find_state (find_recv_state_by_src_id_cb , (void * )sink );
160
161
if (recv_state == NULL ) {
161
162
/* This is likely due to the receive state being removed while we are BIG synced */
162
163
LOG_DBG ("Could not find receive state for sink %p" , sink );
@@ -489,6 +490,8 @@ static void broadcast_sink_add_src(struct bt_bap_broadcast_sink *sink)
489
490
490
491
bt_addr_le_copy (& add_src_param .addr , & sync_info .addr );
491
492
add_src_param .sid = sync_info .sid ;
493
+ /* When a broadcast sink is created we always assume the PA sync provided is synced */
494
+ add_src_param .pa_state = BT_BAP_PA_STATE_SYNCED ;
492
495
add_src_param .broadcast_id = sink -> broadcast_id ;
493
496
/* Will be updated when we receive the BASE */
494
497
add_src_param .encrypt_state = BT_BAP_BIG_ENC_STATE_NO_ENC ;
@@ -542,7 +545,7 @@ static void update_recv_state_base(const struct bt_bap_broadcast_sink *sink,
542
545
const struct bt_bap_scan_delegator_recv_state * recv_state ;
543
546
int err ;
544
547
545
- recv_state = bt_bap_scan_delegator_find_state (find_recv_state_by_sink_cb , (void * )sink );
548
+ recv_state = bt_bap_scan_delegator_find_state (find_recv_state_by_src_id_cb , (void * )sink );
546
549
if (recv_state == NULL ) {
547
550
LOG_WRN ("Failed to find receive state for sink %p" , sink );
548
551
@@ -745,12 +748,23 @@ static void pa_recv(struct bt_le_per_adv_sync *sync,
745
748
bt_data_parse (buf , pa_decode_base , (void * )sink );
746
749
}
747
750
751
+ static void pa_synced_cb (struct bt_le_per_adv_sync * sync ,
752
+ struct bt_le_per_adv_sync_synced_info * info )
753
+ {
754
+ struct bt_bap_broadcast_sink * sink = broadcast_sink_get_by_pa (sync );
755
+
756
+ if (sink != NULL ) {
757
+ bt_bap_scan_delegator_set_pa_state (sink -> bass_src_id , BT_BAP_PA_STATE_SYNCED );
758
+ }
759
+ }
760
+
748
761
static void pa_term_cb (struct bt_le_per_adv_sync * sync ,
749
762
const struct bt_le_per_adv_sync_term_info * info )
750
763
{
751
764
struct bt_bap_broadcast_sink * sink = broadcast_sink_get_by_pa (sync );
752
765
753
766
if (sink != NULL ) {
767
+ bt_bap_scan_delegator_set_pa_state (sink -> bass_src_id , BT_BAP_PA_STATE_NOT_SYNCED );
754
768
sink -> pa_sync = NULL ;
755
769
sink -> base_size = 0U ;
756
770
}
@@ -763,7 +777,7 @@ static void update_recv_state_encryption(const struct bt_bap_broadcast_sink *sin
763
777
764
778
__ASSERT (sink -> big == NULL , "Encryption state shall not be updated while synced" );
765
779
766
- recv_state = bt_bap_scan_delegator_find_state (find_recv_state_by_sink_cb , (void * )sink );
780
+ recv_state = bt_bap_scan_delegator_find_state (find_recv_state_by_src_id_cb , (void * )sink );
767
781
if (recv_state == NULL ) {
768
782
LOG_WRN ("Failed to find receive state for sink %p" , sink );
769
783
@@ -1044,6 +1058,7 @@ int bt_bap_broadcast_sink_create(struct bt_le_per_adv_sync *pa_sync, uint32_t br
1044
1058
{
1045
1059
const struct bt_bap_scan_delegator_recv_state * recv_state ;
1046
1060
struct bt_bap_broadcast_sink * sink ;
1061
+ int err ;
1047
1062
1048
1063
CHECKIF (pa_sync == NULL ) {
1049
1064
LOG_DBG ("pa_sync is NULL" );
@@ -1073,8 +1088,8 @@ int bt_bap_broadcast_sink_create(struct bt_le_per_adv_sync *pa_sync, uint32_t br
1073
1088
sink -> broadcast_id = broadcast_id ;
1074
1089
sink -> pa_sync = pa_sync ;
1075
1090
1076
- recv_state = bt_bap_scan_delegator_find_state ( find_recv_state_by_pa_sync_cb ,
1077
- (void * )pa_sync );
1091
+ recv_state =
1092
+ bt_bap_scan_delegator_find_state ( find_recv_state_by_sink_fields_cb , (void * )sink );
1078
1093
if (recv_state == NULL ) {
1079
1094
broadcast_sink_add_src (sink );
1080
1095
} else {
@@ -1088,8 +1103,24 @@ int bt_bap_broadcast_sink_create(struct bt_le_per_adv_sync *pa_sync, uint32_t br
1088
1103
}
1089
1104
1090
1105
sink -> bass_src_id = recv_state -> src_id ;
1106
+ if (recv_state -> pa_sync_state != BT_BAP_PA_STATE_SYNCED ) {
1107
+ /* When a broadcast sink is created we always assume the PA sync provided is
1108
+ * synced
1109
+ */
1110
+ err = bt_bap_scan_delegator_set_pa_state (sink -> bass_src_id ,
1111
+ BT_BAP_PA_STATE_SYNCED );
1112
+ if (err != 0 ) {
1113
+ LOG_DBG ("Failed to set PA state: %d" , err );
1114
+
1115
+ broadcast_sink_cleanup (sink );
1116
+
1117
+ return err ;
1118
+ }
1119
+ }
1120
+
1091
1121
atomic_set_bit (sink -> flags , BT_BAP_BROADCAST_SINK_FLAG_SRC_ID_VALID );
1092
1122
}
1123
+
1093
1124
atomic_set_bit (sink -> flags , BT_BAP_BROADCAST_SINK_FLAG_INITIALIZED );
1094
1125
1095
1126
* out_sink = sink ;
@@ -1432,6 +1463,7 @@ int bt_bap_broadcast_sink_delete(struct bt_bap_broadcast_sink *sink)
1432
1463
static int broadcast_sink_init (void )
1433
1464
{
1434
1465
static struct bt_le_per_adv_sync_cb cb = {
1466
+ .synced = pa_synced_cb ,
1435
1467
.recv = pa_recv ,
1436
1468
.biginfo = biginfo_recv ,
1437
1469
.term = pa_term_cb ,
0 commit comments