From 0741f19599f87e1818dd00182caae3c2c9343875 Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Tue, 14 Dec 2021 11:19:53 +0100 Subject: [PATCH] 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(). --- nimble/host/include/host/ble_gap.h | 14 +++++++++++++- nimble/host/src/ble_gap.c | 19 ++++++++++++++++--- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/nimble/host/include/host/ble_gap.h b/nimble/host/include/host/ble_gap.h index af9c978bc..63ae900da 100644 --- a/nimble/host/include/host/ble_gap.h +++ b/nimble/host/include/host/ble_gap.h @@ -1160,7 +1160,19 @@ struct ble_gap_ext_adv_params { /** If perform high-duty directed advertising */ unsigned int high_duty_directed:1; - /** If use legacy PDUs for advertising */ + /** If use legacy PDUs for advertising. + * + * Valid combinations of the connectable, scannable, directed, + * high_duty_directed options with the legcy_pdu flag are: + * - IND -> legacy_pdu + connectable + scannable + * - LD_DIR -> legacy_pdu + connectable + directed + * - HD_DIR -> legacy_pdu + connectable + directed + high_duty_directed + * - SCAN -> legacy_pdu + scannable + * - NONCONN -> legacy_pdu + * + * Any other combination of these options combined with the legacy_pdu flag + * are invalid. + */ unsigned int legacy_pdu:1; /** If perform anonymous advertising */ diff --git a/nimble/host/src/ble_gap.c b/nimble/host/src/ble_gap.c index 8f7e5ca60..3d8f3038a 100644 --- a/nimble/host/src/ble_gap.c +++ b/nimble/host/src/ble_gap.c @@ -2692,15 +2692,28 @@ ble_gap_ext_adv_params_tx(uint8_t instance, if (params->high_duty_directed) { cmd.props |= BLE_HCI_LE_SET_EXT_ADV_PROP_HD_DIRECTED; } - if (params->legacy_pdu) { - cmd.props |= BLE_HCI_LE_SET_EXT_ADV_PROP_LEGACY; - } if (params->anonymous) { cmd.props |= BLE_HCI_LE_SET_EXT_ADV_PROP_ANON_ADV; } if (params->include_tx_power) { cmd.props |= BLE_HCI_LE_SET_EXT_ADV_PROP_INC_TX_PWR; } + if (params->legacy_pdu) { + cmd.props |= BLE_HCI_LE_SET_EXT_ADV_PROP_LEGACY; + + /* check right away if the applied configuration is valid before handing + * the command to the controller to improve error reporting */ + switch (cmd.props) { + case BLE_HCI_LE_SET_EXT_ADV_PROP_LEGACY_IND: + case BLE_HCI_LE_SET_EXT_ADV_PROP_LEGACY_LD_DIR: + case BLE_HCI_LE_SET_EXT_ADV_PROP_LEGACY_HD_DIR: + case BLE_HCI_LE_SET_EXT_ADV_PROP_LEGACY_SCAN: + case BLE_HCI_LE_SET_EXT_ADV_PROP_LEGACY_NONCONN: + break; + default: + return BLE_HS_EINVAL; + } + } /* Fill optional fields if application did not specify them. */ if (params->itvl_min == 0 && params->itvl_max == 0) {