@@ -4647,28 +4647,49 @@ static void le_per_adv_sync_established(struct net_buf *buf)
4647
4647
struct bt_le_per_adv_sync * pending_per_adv_sync ;
4648
4648
int err ;
4649
4649
4650
- err = bt_le_scan_update (false );
4650
+ pending_per_adv_sync = get_pending_per_adv_sync ( );
4651
4651
4652
- if (err ) {
4653
- BT_ERR ("Could not stop scan (%d)" , err );
4654
- }
4652
+ if (pending_per_adv_sync ) {
4653
+ atomic_clear_bit (pending_per_adv_sync -> flags ,
4654
+ BT_PER_ADV_SYNC_SYNCING );
4655
+ err = bt_le_scan_update (false);
4655
4656
4656
- if (evt -> status == BT_HCI_ERR_OP_CANCELLED_BY_HOST ) {
4657
- /* Cancelled locally, don't call CB */
4658
- return ;
4657
+ if (err ) {
4658
+ BT_ERR ( "Could not update scan (%d)" , err );
4659
+ }
4659
4660
}
4660
4661
4661
- pending_per_adv_sync = get_pending_per_adv_sync ();
4662
-
4663
4662
if (!pending_per_adv_sync ||
4664
4663
pending_per_adv_sync -> sid != evt -> sid ||
4665
4664
bt_addr_le_cmp (& pending_per_adv_sync -> addr , & evt -> adv_addr )) {
4665
+ struct bt_le_per_adv_sync_term_info term_info ;
4666
+
4666
4667
BT_ERR ("Unexpected per adv sync established event" );
4667
4668
per_adv_sync_terminate (sys_le16_to_cpu (evt -> handle ));
4669
+
4670
+ if (pending_per_adv_sync ) {
4671
+ /* Terminate the pending PA sync and notify app */
4672
+ term_info .addr = & pending_per_adv_sync -> addr ;
4673
+ term_info .sid = pending_per_adv_sync -> sid ;
4674
+
4675
+ /* Deleting before callback, so the caller will be able
4676
+ * to restart sync in the callback.
4677
+ */
4678
+ per_adv_sync_delete (pending_per_adv_sync );
4679
+
4680
+ if (pending_per_adv_sync -> cb &&
4681
+ pending_per_adv_sync -> cb -> term ) {
4682
+ pending_per_adv_sync -> cb -> term (
4683
+ pending_per_adv_sync , & term_info );
4684
+ }
4685
+ }
4668
4686
return ;
4669
4687
}
4670
4688
4671
- atomic_clear_bit (pending_per_adv_sync -> flags , BT_PER_ADV_SYNC_SYNCING );
4689
+ if (evt -> status == BT_HCI_ERR_OP_CANCELLED_BY_HOST ) {
4690
+ /* Cancelled locally, don't call CB */
4691
+ return ;
4692
+ }
4672
4693
4673
4694
atomic_set_bit (pending_per_adv_sync -> flags , BT_PER_ADV_SYNC_SYNCED );
4674
4695
0 commit comments