Skip to content

Commit

Permalink
nimble/ll: Add option to select location of AdvA in ext adv
Browse files Browse the repository at this point in the history
This adds syscfg to select location of AdvA in extended advertising
PDUs. If enabled, AdvA is put in AUX_ADV_IND instead of ADV_EXT_IND.

This is enabled by default to retain current behavior.
  • Loading branch information
andrzej-kaczmarek committed Oct 21, 2024
1 parent caad037 commit a5fa9d1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
33 changes: 29 additions & 4 deletions nimble/controller/src/ble_ll_adv.c
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@ ble_ll_adv_pdu_make(uint8_t *dptr, void *pducb_arg, uint8_t *hdr_byte)
uint8_t ext_hdr_len;
uint8_t ext_hdr_flags;
uint32_t offset;
bool has_adva;

advsm = pducb_arg;

Expand All @@ -581,8 +582,6 @@ ble_ll_adv_pdu_make(uint8_t *dptr, void *pducb_arg, uint8_t *hdr_byte)
/* only ADV_EXT_IND goes on primary advertising channels */
pdu_type = BLE_ADV_PDU_TYPE_ADV_EXT_IND;

*hdr_byte = pdu_type;

adv_mode = 0;
if (advsm->props & BLE_HCI_LE_SET_EXT_ADV_PROP_CONNECTABLE) {
adv_mode |= BLE_LL_EXT_ADV_MODE_CONN;
Expand All @@ -591,11 +590,19 @@ ble_ll_adv_pdu_make(uint8_t *dptr, void *pducb_arg, uint8_t *hdr_byte)
adv_mode |= BLE_LL_EXT_ADV_MODE_SCAN;
}

has_adva = !MYNEWT_VAL(BLE_LL_EXT_ADV_ADVA_IN_AUX) &&
!(advsm->props & BLE_HCI_LE_SET_EXT_ADV_PROP_ANON_ADV);

ext_hdr_len = BLE_LL_EXT_ADV_FLAGS_SIZE + BLE_LL_EXT_ADV_DATA_INFO_SIZE +
BLE_LL_EXT_ADV_AUX_PTR_SIZE;
ext_hdr_flags = (1 << BLE_LL_EXT_ADV_DATA_INFO_BIT) |
(1 << BLE_LL_EXT_ADV_AUX_PTR_BIT);

if (has_adva) {
ext_hdr_len += BLE_LL_EXT_ADV_ADVA_SIZE;
ext_hdr_flags |= (1 << BLE_LL_EXT_ADV_ADVA_BIT);
}

/* ext hdr len and adv mode */
dptr[0] = ext_hdr_len | (adv_mode << 6);
dptr += 1;
Expand All @@ -604,6 +611,15 @@ ble_ll_adv_pdu_make(uint8_t *dptr, void *pducb_arg, uint8_t *hdr_byte)
dptr[0] = ext_hdr_flags;
dptr += 1;

if (has_adva) {
/* AdvA */
if (advsm->flags & BLE_LL_ADV_SM_FLAG_TX_ADD) {
pdu_type |= BLE_ADV_PDU_HDR_TXADD_RAND;
}
memcpy(dptr, advsm->adva, BLE_LL_EXT_ADV_ADVA_SIZE);
dptr += BLE_LL_EXT_ADV_ADVA_SIZE;
}

/* ADI */
dptr[0] = advsm->adi & 0x00ff;
dptr[1] = advsm->adi >> 8;
Expand All @@ -619,6 +635,8 @@ ble_ll_adv_pdu_make(uint8_t *dptr, void *pducb_arg, uint8_t *hdr_byte)
ble_ll_adv_put_aux_ptr(AUX_CURRENT(advsm)->chan, advsm->sec_phy,
offset, dptr);

*hdr_byte = pdu_type;

return BLE_LL_EXT_ADV_HDR_LEN + ext_hdr_len;
}

Expand Down Expand Up @@ -1407,9 +1425,16 @@ ble_ll_adv_aux_calculate_payload(struct ble_ll_adv_sm *advsm, uint16_t props,
ext_hdr_len += BLE_LL_EXT_ADV_DATA_INFO_SIZE;
}

/* AdvA in 1st PDU, except for anonymous */
/* AdvA if:
* - 1st PDU
* - not anonymous
* - scannable/connectable or ADVA_IN_AUX selected
*/
if (first_pdu &&
!(props & BLE_HCI_LE_SET_EXT_ADV_PROP_ANON_ADV)) {
!(props & BLE_HCI_LE_SET_EXT_ADV_PROP_ANON_ADV) &&
((props & (BLE_HCI_LE_SET_EXT_ADV_PROP_CONNECTABLE |
BLE_HCI_LE_SET_EXT_ADV_PROP_SCANNABLE)) ||
MYNEWT_VAL(BLE_LL_EXT_ADV_ADVA_IN_AUX))) {
ext_hdr_flags |= (1 << BLE_LL_EXT_ADV_ADVA_BIT);
ext_hdr_len += BLE_LL_EXT_ADV_ADVA_SIZE;
}
Expand Down
5 changes: 5 additions & 0 deletions nimble/controller/syscfg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,11 @@ syscfg.defs:
like build optimisation, cache, clock speed etc.
value: 0

BLE_LL_EXT_ADV_ADVA_IN_AUX:
description: >
Put AdvA in AUX_ADV_IND instead of ADV_EXT_IND.
value: 1

BLE_LL_STACK_SIZE:
description: >
This is the stack size for LL task.
Expand Down

0 comments on commit a5fa9d1

Please sign in to comment.