OSDN Git Service

iso: Fix handling same sequence number
authorJakub Tyszkowski <jakub.tyszkowski@codecoup.pl>
Mon, 4 Jan 2021 14:06:13 +0000 (15:06 +0100)
committerJakub Pawlowski <jpawlowski@google.com>
Wed, 27 Jan 2021 12:10:33 +0000 (12:10 +0000)
When calculating the sequence number it may happen that we
compute the same value as for previous packet. If that happens
we manually increment the value by one. This was a problem when
yet another packet comes in a short interval and calculated seq.
number is still the same. Our calcualted seq. number for current
packet can now be lower than the previos one (after the previous
one was manually incremented). This resulted in wrongly calculated
packet lost counter dropping below 0.

Tag: #feature
Bug: 159786353
Sponsor: jpawlowski@
Test: atest --host net_test_btm_iso

Change-Id: I7d726ef292e85851af6383bfc8f4bcf125ccbf54

stack/btm/btm_iso_impl.h
stack/test/btm_iso_test.cc

index 42b7167..c0b6a1c 100644 (file)
@@ -630,7 +630,8 @@ struct iso_impl {
     uint32_t ts = bluetooth::common::time_get_os_boottime_us();
     uint32_t new_calc_seq_nb =
         (ts - iso->sync_info.first_sync_ts) / iso->sdu_itv;
-    if (new_calc_seq_nb == iso->sync_info.seq_nb) ++new_calc_seq_nb;
+    if (new_calc_seq_nb <= iso->sync_info.seq_nb)
+      new_calc_seq_nb = iso->sync_info.seq_nb + 1;
 
     if (iso->sync_info.seq_nb == 0) {
       evt.evt_lost = 0;
index f5598dc..f09370e 100644 (file)
@@ -2176,3 +2176,27 @@ TEST_F(IsoManagerTest, HandleDisconnectDisconnectedCig) {
   handle = volatile_test_cig_create_cmpl_evt_.conn_handles[1];
   IsoManager::GetInstance()->HandleDisconnect(handle, 16);
 }
+
+TEST_F(IsoManagerTest, HandleIsoDataSameSeqNb) {
+  IsoManager::GetInstance()->CreateCig(
+      volatile_test_cig_create_cmpl_evt_.cig_id, kDefaultCigParams);
+
+  auto handle = volatile_test_cig_create_cmpl_evt_.conn_handles[0];
+  IsoManager::GetInstance()->EstablishCis({{{handle, 1}}});
+
+  EXPECT_CALL(
+      *cig_callbacks_,
+      OnCisEvent(bluetooth::hci::iso_manager::kIsoEventCisDataAvailable, _))
+      .Times(2);
+
+  std::vector<uint8_t> dummy_msg(18);
+  uint8_t* p = dummy_msg.data();
+  UINT16_TO_STREAM(p, BT_EVT_TO_BTU_HCI_ISO);
+  UINT16_TO_STREAM(p, 10);  // .len
+  UINT16_TO_STREAM(p, 0);   // .offset
+  UINT16_TO_STREAM(p, 0);   // .layer_specific
+  UINT16_TO_STREAM(p, handle);
+
+  IsoManager::GetInstance()->HandleIsoData(dummy_msg.data());
+  IsoManager::GetInstance()->HandleIsoData(dummy_msg.data());
+}