Skip to content

Commit

Permalink
nimble/ll: Fix offset calculation in BIGInfo
Browse files Browse the repository at this point in the history
Offset calculation in BIGInfo assumes BIG event start time is always
after AUX_SYNC_IND since BIG should be advanced to next event by the
time AUX_SYNC_IND is sent. However, if AUX_SYNC_IND is scheduled close
to BIG event this may not happend and thus calculated offset is invalid.

This makes sure that we always use BIG event after AUX_SYNC_IND to
calculate offset.
  • Loading branch information
andrzej-kaczmarek committed Oct 22, 2024
1 parent 80056c4 commit fd8d1b4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
1 change: 0 additions & 1 deletion nimble/controller/src/ble_ll_adv.c
Original file line number Diff line number Diff line change
Expand Up @@ -2216,7 +2216,6 @@ ble_ll_adv_sync_pdu_make(uint8_t *dptr, void *pducb_arg, uint8_t *hdr_byte)
sync->sch.start_time +
g_ble_ll_sched_offset_ticks,
sync->sch.remainder);
BLE_LL_ASSERT(biginfo_len > 0);

dptr += biginfo_len;
}
Expand Down
30 changes: 24 additions & 6 deletions nimble/controller/src/ble_ll_iso_big.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,20 +307,38 @@ ble_ll_iso_big_biginfo_copy(struct ble_ll_iso_big *big, uint8_t *dptr,
uint32_t base_ticks, uint8_t base_rem_us)
{
uint8_t *dptr_start;
uint32_t event_start;
uint8_t event_start_us;
uint64_t counter;
uint32_t offset_us;
uint32_t offset;
uint32_t d_ticks;
uint8_t d_rem_us;

dptr_start = dptr;
counter = big->bis_counter;

d_ticks = big->event_start - base_ticks;
d_rem_us = big->event_start_us;
ble_ll_tmr_sub(&d_ticks, &d_rem_us, base_rem_us);
event_start = big->event_start;
event_start_us = big->event_start_us;

/* Use next BIG event in case current one is before AUX_SYNC_IND. This can
* happen if AUX_SYNC_IND is scheduled right after BIG event and the BIG
* was not yet advanced to next event.
*/
if (event_start <= base_ticks) {
ble_ll_tmr_add(&event_start, &event_start_us, big->iso_interval * 1250);
counter++;
}

/* Drop BIGInfo if BIG event is still before AUX_SYNC_IND. This should not
* happen but better not send invalid offset.
*/
if (event_start <= base_ticks) {
return 0;
}

offset_us = ble_ll_tmr_t2u(event_start - base_ticks);
offset_us += event_start_us;
offset_us -= base_rem_us;

offset_us = ble_ll_tmr_t2u(d_ticks) + d_rem_us;
if (offset_us <= 600) {
counter += big->bn;
offset_us += big->iso_interval * 1250;
Expand Down

0 comments on commit fd8d1b4

Please sign in to comment.