Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit de7e3ad5 authored by Jakub Tyszkowski's avatar Jakub Tyszkowski Committed by Jakub Pawlowski
Browse files

iso: Fix handling same sequence number

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
parent 72bccfac
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -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;
+24 −0
Original line number Diff line number Diff line
@@ -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());
}