Skip to content

Commit 0de4c30

Browse files
cvinayakcarlescufi
authored andcommitted
Bluetooth: controller: Fix incorrect prev aux header flag access
Fix Extended Advertising PDU population from incorrectly populating new PDU when there is no common extended header flags being set in the previous PDU and or the new PDU. Signed-off-by: Vinayak Kariappa Chettimada <[email protected]>
1 parent cabcae2 commit 0de4c30

File tree

2 files changed

+49
-10
lines changed

2 files changed

+49
-10
lines changed

subsys/bluetooth/controller/ll_sw/ull_adv.c

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -672,10 +672,16 @@ uint8_t ll_adv_enable(uint8_t enable)
672672
#if defined(CONFIG_BT_CTLR_ADV_EXT)
673673
} else if (pdu_adv->type == PDU_ADV_TYPE_EXT_IND) {
674674
struct pdu_adv_com_ext_adv *pri_com_hdr;
675+
struct pdu_adv_ext_hdr pri_hdr_flags;
675676
struct pdu_adv_ext_hdr *pri_hdr;
676677

677678
pri_com_hdr = (void *)&pdu_adv->adv_ext_ind;
678679
pri_hdr = (void *)pri_com_hdr->ext_hdr_adv_data;
680+
if (pri_com_hdr->ext_hdr_len) {
681+
pri_hdr_flags = *pri_hdr;
682+
} else {
683+
*(uint8_t *)&pri_hdr_flags = 0U;
684+
}
679685

680686
if (pri_com_hdr->adv_mode & BT_HCI_LE_ADV_PROP_SCAN) {
681687
struct pdu_adv *sr = lll_adv_scan_rsp_peek(lll);
@@ -686,20 +692,26 @@ uint8_t ll_adv_enable(uint8_t enable)
686692
}
687693

688694
/* AdvA, fill here at enable */
689-
if (pri_hdr->adv_addr) {
695+
if (pri_hdr_flags.adv_addr) {
690696
pdu_adv_to_update = pdu_adv;
691697
#if (CONFIG_BT_CTLR_ADV_AUX_SET > 0)
692-
} else if (pri_hdr->aux_ptr) {
698+
} else if (pri_hdr_flags.aux_ptr) {
693699
struct pdu_adv_com_ext_adv *sec_com_hdr;
700+
struct pdu_adv_ext_hdr sec_hdr_flags;
694701
struct pdu_adv_ext_hdr *sec_hdr;
695702
struct pdu_adv *sec_pdu;
696703

697704
sec_pdu = lll_adv_aux_data_peek(lll->aux);
698705

699706
sec_com_hdr = (void *)&sec_pdu->adv_ext_ind;
700707
sec_hdr = (void *)sec_com_hdr->ext_hdr_adv_data;
708+
if (sec_com_hdr->ext_hdr_len) {
709+
sec_hdr_flags = *sec_hdr;
710+
} else {
711+
*(uint8_t *)&sec_hdr_flags = 0U;
712+
}
701713

702-
if (sec_hdr->adv_addr) {
714+
if (sec_hdr_flags.adv_addr) {
703715
pdu_adv_to_update = sec_pdu;
704716
}
705717
#endif /* (CONFIG_BT_CTLR_ADV_AUX_SET > 0) */
@@ -1659,10 +1671,19 @@ void ull_adv_done(struct node_rx_event_done *done)
16591671
const uint8_t *ull_adv_pdu_update_addrs(struct ll_adv_set *adv,
16601672
struct pdu_adv *pdu)
16611673
{
1674+
const uint8_t *adv_addr;
1675+
16621676
#if defined(CONFIG_BT_CTLR_ADV_EXT)
1663-
struct pdu_adv_ext_hdr *hdr = (void *)pdu->adv_ext_ind.ext_hdr_adv_data;
1677+
struct pdu_adv_com_ext_adv *com_hdr = (void *)&pdu->adv_ext_ind;
1678+
struct pdu_adv_ext_hdr *hdr = (void *)com_hdr->ext_hdr_adv_data;
1679+
struct pdu_adv_ext_hdr hdr_flags;
1680+
1681+
if (com_hdr->ext_hdr_len) {
1682+
hdr_flags = *hdr;
1683+
} else {
1684+
*(uint8_t *)&hdr_flags = 0U;
1685+
}
16641686
#endif
1665-
const uint8_t *adv_addr;
16661687

16671688
adv_addr = adva_update(adv, pdu);
16681689

@@ -1672,7 +1693,7 @@ const uint8_t *ull_adv_pdu_update_addrs(struct ll_adv_set *adv,
16721693
*/
16731694
if ((pdu->type == PDU_ADV_TYPE_DIRECT_IND) ||
16741695
#if defined(CONFIG_BT_CTLR_ADV_EXT)
1675-
((pdu->type == PDU_ADV_TYPE_EXT_IND) && hdr->tgt_addr) ||
1696+
((pdu->type == PDU_ADV_TYPE_EXT_IND) && hdr_flags.tgt_addr) ||
16761697
#endif
16771698
0) {
16781699
tgta_update(adv, pdu);
@@ -2117,12 +2138,21 @@ static inline uint8_t disable(uint8_t handle)
21172138
static inline uint8_t *adv_pdu_adva_get(struct pdu_adv *pdu)
21182139
{
21192140
#if defined(CONFIG_BT_CTLR_ADV_EXT)
2120-
struct pdu_adv_ext_hdr *hdr = (void *)pdu->adv_ext_ind.ext_hdr_adv_data;
2141+
struct pdu_adv_com_ext_adv *com_hdr = (void *)&pdu->adv_ext_ind;
2142+
struct pdu_adv_ext_hdr *hdr = (void *)com_hdr->ext_hdr_adv_data;
2143+
struct pdu_adv_ext_hdr hdr_flags;
2144+
2145+
if (com_hdr->ext_hdr_len) {
2146+
hdr_flags = *hdr;
2147+
} else {
2148+
*(uint8_t *)&hdr_flags = 0U;
2149+
}
21212150

21222151
/* All extended PDUs have AdvA at the same offset in common header */
21232152
if (pdu->type == PDU_ADV_TYPE_EXT_IND) {
2124-
LL_ASSERT(hdr->adv_addr);
2125-
return &pdu->adv_ext_ind.ext_hdr_adv_data[1];
2153+
LL_ASSERT(hdr_flags.adv_addr);
2154+
2155+
return &com_hdr->ext_hdr_adv_data[1];
21262156
}
21272157
#endif
21282158

subsys/bluetooth/controller/ll_sw/ull_adv_aux.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,11 @@ uint8_t ull_adv_aux_hdr_set_clear(struct ll_adv_set *adv,
477477

478478
pri_com_hdr_prev = (void *)&pri_pdu_prev->adv_ext_ind;
479479
pri_hdr = (void *)pri_com_hdr_prev->ext_hdr_adv_data;
480-
pri_hdr_prev = *pri_hdr;
480+
if (pri_com_hdr_prev->ext_hdr_len) {
481+
pri_hdr_prev = *pri_hdr;
482+
} else {
483+
*(uint8_t *)&pri_hdr_prev = 0U;
484+
}
481485
pri_dptr_prev = pri_hdr->data;
482486

483487
/* Advertising data are not supported by scannable instances */
@@ -701,6 +705,11 @@ uint8_t ull_adv_aux_hdr_set_clear(struct ll_adv_set *adv,
701705
/* Fill AdvData in secondary PDU */
702706
memmove(sec_dptr, ad_data, ad_len);
703707

708+
/* Early exit if no flags set */
709+
if (!sec_com_hdr->ext_hdr_len) {
710+
return 0;
711+
}
712+
704713
/* No ACAD in primary channel PDU */
705714
/* TODO: Fill ACAD in secondary channel PDU */
706715

0 commit comments

Comments
 (0)