Skip to content

Commit 0741f19

Browse files
committed
host/gap: improve API for legacy adv for EXT_ADV:=1
The possible combination of options when setting legacy_pdu:=1 in `struct ble_gap_ext_adv_params` was not obvious to API users. This commit improves the API by i) adding accoring documentation and ii) adding a validity check into ble_gap_ext_adv_params_tx().
1 parent 52d47ad commit 0741f19

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

nimble/host/include/host/ble_gap.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1160,7 +1160,19 @@ struct ble_gap_ext_adv_params {
11601160
/** If perform high-duty directed advertising */
11611161
unsigned int high_duty_directed:1;
11621162

1163-
/** If use legacy PDUs for advertising */
1163+
/** If use legacy PDUs for advertising.
1164+
*
1165+
* Valid combinations of the connectable, scannable, directed,
1166+
* high_duty_directed options with the legcy_pdu flag are:
1167+
* - IND -> legacy_pdu + connectable + scannable
1168+
* - LD_DIR -> legacy_pdu + connectable + directed
1169+
* - HD_DIR -> legacy_pdu + connectable + directed + high_duty_directed
1170+
* - SCAN -> legacy_pdu + scannable
1171+
* - NONCONN -> legacy_pdu
1172+
*
1173+
* Any other combination of these options combined with the legacy_pdu flag
1174+
* are invalid.
1175+
*/
11641176
unsigned int legacy_pdu:1;
11651177

11661178
/** If perform anonymous advertising */

nimble/host/src/ble_gap.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2692,15 +2692,28 @@ ble_gap_ext_adv_params_tx(uint8_t instance,
26922692
if (params->high_duty_directed) {
26932693
cmd.props |= BLE_HCI_LE_SET_EXT_ADV_PROP_HD_DIRECTED;
26942694
}
2695-
if (params->legacy_pdu) {
2696-
cmd.props |= BLE_HCI_LE_SET_EXT_ADV_PROP_LEGACY;
2697-
}
26982695
if (params->anonymous) {
26992696
cmd.props |= BLE_HCI_LE_SET_EXT_ADV_PROP_ANON_ADV;
27002697
}
27012698
if (params->include_tx_power) {
27022699
cmd.props |= BLE_HCI_LE_SET_EXT_ADV_PROP_INC_TX_PWR;
27032700
}
2701+
if (params->legacy_pdu) {
2702+
cmd.props |= BLE_HCI_LE_SET_EXT_ADV_PROP_LEGACY;
2703+
2704+
/* check right away if the applied configuration is valid before handing
2705+
* the command to the controller to improve error reporting */
2706+
switch (cmd.props) {
2707+
case BLE_HCI_LE_SET_EXT_ADV_PROP_LEGACY_IND:
2708+
case BLE_HCI_LE_SET_EXT_ADV_PROP_LEGACY_LD_DIR:
2709+
case BLE_HCI_LE_SET_EXT_ADV_PROP_LEGACY_HD_DIR:
2710+
case BLE_HCI_LE_SET_EXT_ADV_PROP_LEGACY_SCAN:
2711+
case BLE_HCI_LE_SET_EXT_ADV_PROP_LEGACY_NONCONN:
2712+
break;
2713+
default:
2714+
return BLE_HS_EINVAL;
2715+
}
2716+
}
27042717

27052718
/* Fill optional fields if application did not specify them. */
27062719
if (params->itvl_min == 0 && params->itvl_max == 0) {

0 commit comments

Comments
 (0)