@@ -70,8 +70,8 @@ static struct bt_bap_scan_delegator_mod_src_param mod_src_param;
7070
7171static void broadcast_sink_cleanup (struct bt_bap_broadcast_sink * sink );
7272
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 )
7575{
7676 const struct bt_bap_broadcast_sink * sink = user_data ;
7777
@@ -83,34 +83,35 @@ static bool find_recv_state_by_sink_cb(const struct bt_bap_scan_delegator_recv_s
8383 return false;
8484}
8585
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 )
8889{
89- struct bt_le_per_adv_sync * sync = user_data ;
90+ const struct bt_bap_broadcast_sink * sink = user_data ;
9091 struct bt_le_per_adv_sync_info sync_info ;
9192 int err ;
9293
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 );
9495 if (err != 0 ) {
9596 LOG_DBG ("Failed to get sync info: %d" , err );
9697
9798 return false;
9899 }
99100
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 ;
106107};
107108
108109static void update_recv_state_big_synced (const struct bt_bap_broadcast_sink * sink )
109110{
110111 const struct bt_bap_scan_delegator_recv_state * recv_state ;
111112 int err ;
112113
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 );
114115 if (recv_state == NULL ) {
115116 LOG_WRN ("Failed to find receive state for sink %p" , sink );
116117
@@ -156,7 +157,7 @@ static void update_recv_state_big_cleared(const struct bt_bap_broadcast_sink *si
156157 bool sink_is_streaming = false;
157158 int err ;
158159
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 );
160161 if (recv_state == NULL ) {
161162 /* This is likely due to the receive state being removed while we are BIG synced */
162163 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)
489490
490491 bt_addr_le_copy (& add_src_param .addr , & sync_info .addr );
491492 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 ;
492495 add_src_param .broadcast_id = sink -> broadcast_id ;
493496 /* Will be updated when we receive the BASE */
494497 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,
542545 const struct bt_bap_scan_delegator_recv_state * recv_state ;
543546 int err ;
544547
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 );
546549 if (recv_state == NULL ) {
547550 LOG_WRN ("Failed to find receive state for sink %p" , sink );
548551
@@ -745,12 +748,23 @@ static void pa_recv(struct bt_le_per_adv_sync *sync,
745748 bt_data_parse (buf , pa_decode_base , (void * )sink );
746749}
747750
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+
748761static void pa_term_cb (struct bt_le_per_adv_sync * sync ,
749762 const struct bt_le_per_adv_sync_term_info * info )
750763{
751764 struct bt_bap_broadcast_sink * sink = broadcast_sink_get_by_pa (sync );
752765
753766 if (sink != NULL ) {
767+ bt_bap_scan_delegator_set_pa_state (sink -> bass_src_id , BT_BAP_PA_STATE_NOT_SYNCED );
754768 sink -> pa_sync = NULL ;
755769 sink -> base_size = 0U ;
756770 }
@@ -763,7 +777,7 @@ static void update_recv_state_encryption(const struct bt_bap_broadcast_sink *sin
763777
764778 __ASSERT (sink -> big == NULL , "Encryption state shall not be updated while synced" );
765779
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 );
767781 if (recv_state == NULL ) {
768782 LOG_WRN ("Failed to find receive state for sink %p" , sink );
769783
@@ -1073,8 +1087,8 @@ int bt_bap_broadcast_sink_create(struct bt_le_per_adv_sync *pa_sync, uint32_t br
10731087 sink -> broadcast_id = broadcast_id ;
10741088 sink -> pa_sync = pa_sync ;
10751089
1076- recv_state = bt_bap_scan_delegator_find_state ( find_recv_state_by_pa_sync_cb ,
1077- (void * )pa_sync );
1090+ recv_state =
1091+ bt_bap_scan_delegator_find_state ( find_recv_state_by_sink_fields_cb , (void * )sink );
10781092 if (recv_state == NULL ) {
10791093 broadcast_sink_add_src (sink );
10801094 } else {
@@ -1088,8 +1102,26 @@ int bt_bap_broadcast_sink_create(struct bt_le_per_adv_sync *pa_sync, uint32_t br
10881102 }
10891103
10901104 sink -> bass_src_id = recv_state -> src_id ;
1105+ if (recv_state -> pa_sync_state != BT_BAP_PA_STATE_SYNCED ) {
1106+ int err ;
1107+
1108+ /* When a broadcast sink is created we always assume the PA sync provided is
1109+ * synced
1110+ */
1111+ err = bt_bap_scan_delegator_set_pa_state (sink -> bass_src_id ,
1112+ BT_BAP_PA_STATE_SYNCED );
1113+ if (err != 0 ) {
1114+ LOG_DBG ("Failed to set PA state: %d" , err );
1115+
1116+ broadcast_sink_cleanup (sink );
1117+
1118+ return err ;
1119+ }
1120+ }
1121+
10911122 atomic_set_bit (sink -> flags , BT_BAP_BROADCAST_SINK_FLAG_SRC_ID_VALID );
10921123 }
1124+
10931125 atomic_set_bit (sink -> flags , BT_BAP_BROADCAST_SINK_FLAG_INITIALIZED );
10941126
10951127 * out_sink = sink ;
@@ -1416,6 +1448,7 @@ int bt_bap_broadcast_sink_delete(struct bt_bap_broadcast_sink *sink)
14161448static int broadcast_sink_init (void )
14171449{
14181450 static struct bt_le_per_adv_sync_cb cb = {
1451+ .synced = pa_synced_cb ,
14191452 .recv = pa_recv ,
14201453 .biginfo = biginfo_recv ,
14211454 .term = pa_term_cb ,
0 commit comments