Skip to content

Commit

Permalink
Bluetooth: controller: Fix offset and offset units population
Browse files Browse the repository at this point in the history
Fix the auxiliary pointer and sync information offset and
offset unit population. Offsets are 13-bit value, use 300 us
offset unit when offset value using 30 us offset unit does
not fit in 13-bits.

Signed-off-by: Vinayak Kariappa Chettimada <[email protected]>
  • Loading branch information
cvinayak authored and carlescufi committed Oct 7, 2020
1 parent 56a7a46 commit 01006be
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
6 changes: 3 additions & 3 deletions subsys/bluetooth/controller/ll_sw/pdu.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@
/* Standard allows 2 us timing uncertainty inside the event */
#define EVENT_MAFS_MAX_US (EVENT_MAFS_US + 2)

/* SyncInfo field Sync Packet Offset Units field encoding */
#define SYNC_PKT_OFFS_UNIT_30_US 30
#define SYNC_PKT_OFFS_UNIT_300_US 300
/* Offset Units field encoding */
#define OFFS_UNIT_30_US 30
#define OFFS_UNIT_300_US 300

/*
* Macros to return correct Data Channel PDU time
Expand Down
28 changes: 18 additions & 10 deletions subsys/bluetooth/controller/ll_sw/ull_adv_aux.c
Original file line number Diff line number Diff line change
Expand Up @@ -754,15 +754,16 @@ void ull_adv_aux_ptr_fill(uint8_t **dptr, uint8_t phy_s)
struct pdu_adv_aux_ptr *aux_ptr;

*dptr -= sizeof(struct pdu_adv_aux_ptr);

/* NOTE: Aux Offset will be set in advertiser LLL event
*/
aux_ptr = (void *)*dptr;

/* FIXME: implementation defined */
aux_ptr->chan_idx = 0U;
aux_ptr->ca = 0U;

/* NOTE: Aux Offset will be set in advertiser LLL event
*/
aux_ptr->offs_units = 0U;
aux_ptr->offs = 0U;

aux_ptr->phy = find_lsb_set(phy_s) - 1;
}
Expand Down Expand Up @@ -903,6 +904,7 @@ struct pdu_adv_aux_ptr *ull_adv_aux_lll_offset_fill(uint32_t ticks_offset,
struct pdu_adv_com_ext_adv *pri_com_hdr;
struct pdu_adv_aux_ptr *aux;
struct pdu_adv_hdr *h;
uint32_t offs;
uint8_t *ptr;

pri_com_hdr = (void *)&pdu->adv_ext_ind;
Expand All @@ -918,9 +920,14 @@ struct pdu_adv_aux_ptr *ull_adv_aux_lll_offset_fill(uint32_t ticks_offset,
}

aux = (void *)ptr;
aux->offs = (HAL_TICKER_TICKS_TO_US(ticks_offset) - start_us) / 30;
if (aux->offs_units) {
aux->offs /= 10;
offs = HAL_TICKER_TICKS_TO_US(ticks_offset) - start_us;
offs = offs / OFFS_UNIT_30_US;
if (!!(offs >> 13)) {
aux->offs = offs / (OFFS_UNIT_300_US / OFFS_UNIT_30_US);
aux->offs_units = 1U;
} else {
aux->offs = offs;
aux->offs_units = 0U;
}

return aux;
Expand Down Expand Up @@ -960,12 +967,13 @@ static inline void sync_info_fill(struct lll_adv_sync *lll_sync,
struct pdu_adv_sync_info *si;

*dptr -= sizeof(*si);
si = (void *)*dptr;

sync = (void *)HDR_LLL2EVT(lll_sync);
/* NOTE: sync offset and offset unit filled by secondary prepare */
si->offs_units = 0U;
si->offs = 0U;

si = (void *)*dptr;
si->offs = 0U; /* NOTE: Filled by secondary prepare */
si->offs_units = 0U; /* TODO: implementation defined */
sync = (void *)HDR_LLL2EVT(lll_sync);
si->interval = sys_cpu_to_le16(sync->interval);
memcpy(si->sca_chm, lll_sync->data_chan_map,
sizeof(si->sca_chm));
Expand Down
9 changes: 6 additions & 3 deletions subsys/bluetooth/controller/ll_sw/ull_adv_sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -492,10 +492,13 @@ static inline void sync_info_offset_fill(struct pdu_adv_sync_info *si,
uint32_t offs;

offs = HAL_TICKER_TICKS_TO_US(ticks_offset) - start_us;
if (si->offs_units) {
si->offs = offs / SYNC_PKT_OFFS_UNIT_300_US;
offs = offs / OFFS_UNIT_30_US;
if (!!(offs >> 13)) {
si->offs = offs / (OFFS_UNIT_300_US / OFFS_UNIT_30_US);
si->offs_units = 1U;
} else {
si->offs = offs / SYNC_PKT_OFFS_UNIT_30_US;
si->offs = offs;
si->offs_units = 0U;
}
}

Expand Down

0 comments on commit 01006be

Please sign in to comment.