Skip to content

Commit

Permalink
nimble/ll: Add set ext adv params v2 command
Browse files Browse the repository at this point in the history
This adds second version of Set Extended
Advertising Parameters command (7.8.53)
Introduced in Core Specification v5.4.
  • Loading branch information
m-gorecki committed Oct 2, 2024
1 parent b658f52 commit b41fb6c
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 0 deletions.
5 changes: 5 additions & 0 deletions nimble/controller/include/controller/ble_ll_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,11 @@ int ble_ll_adv_sync_big_remove(struct ble_ll_adv_sm *advsm,
struct ble_ll_iso_big *big);
#endif /* BLE_LL_ISO_BROADCASTER */

#if MYNEWT_VAL(BLE_VERSION) >= 54
int ble_ll_adv_ext_set_param_v2(const uint8_t *cmdbuf, uint8_t len,
uint8_t *rspbuf, uint8_t *rsplen);
#endif

/* Called to notify adv code about RPA rotation */
void ble_ll_adv_rpa_timeout(void);

Expand Down
50 changes: 50 additions & 0 deletions nimble/controller/src/ble_ll_adv.c
Original file line number Diff line number Diff line change
Expand Up @@ -3613,6 +3613,56 @@ ble_ll_adv_ext_set_param(const uint8_t *cmdbuf, uint8_t len,
return rc;
}

#if MYNEWT_VAL(BLE_VERSION) >= 54
static uint8_t
ble_ll_adv_ext_set_coded_opt(uint8_t phy_opt)
{
switch (phy_opt) {
case BLE_HCI_ADVERTISING_PH_OPT_S2_PREF:
case BLE_HCI_ADVERTISING_PH_OPT_S2_REQ:
return BLE_PHY_MODE_CODED_500KBPS;
case BLE_HCI_ADVERTISING_PH_OPT_NO_PREF:
case BLE_HCI_ADVERTISING_PH_OPT_S8_PREF:
case BLE_HCI_ADVERTISING_PH_OPT_S8_REQ:
return BLE_PHY_MODE_CODED_125KBPS;
default:
BLE_LL_ASSERT(0);
}
}

int
ble_ll_adv_ext_set_param_v2(const uint8_t *cmdbuf, uint8_t len,
uint8_t *rspbuf, uint8_t *rsplen)
{
const struct ble_hci_le_set_ext_adv_params_v2_cp *cmd = (const void *) cmdbuf;
struct ble_ll_adv_sm *advsm;
int rc;

if (len != sizeof(*cmd)) {
return BLE_ERR_INV_HCI_CMD_PARMS;
}

if ((cmd->pri_phy_opt > 4) || (cmd->sec_phy_opt > 4)) {
return BLE_ERR_INV_HCI_CMD_PARMS;
}

rc = ble_ll_adv_ext_set_param(cmdbuf, len - 2, rspbuf, rsplen);
if (rc != 0) {
return rc;
}

advsm = ble_ll_adv_sm_get(cmd->params_v1.adv_handle);
if ((cmd->params_v1.pri_phy == BLE_HCI_LE_PHY_CODED) && (cmd->pri_phy_opt)) {
advsm->pri_phy = ble_ll_adv_ext_set_coded_opt(cmd->pri_phy_opt);
}
if ((cmd->params_v1.sec_phy == BLE_HCI_LE_PHY_CODED) && (cmd->sec_phy_opt)) {
advsm->sec_phy = ble_ll_adv_ext_set_coded_opt(cmd->sec_phy_opt);
}

return rc;
}
#endif

int
ble_ll_adv_ext_set_adv_data(const uint8_t *cmdbuf, uint8_t cmdlen)
{
Expand Down
7 changes: 7 additions & 0 deletions nimble/controller/src/ble_ll_hci.c
Original file line number Diff line number Diff line change
Expand Up @@ -1317,6 +1317,13 @@ ble_ll_hci_le_cmd_proc(const uint8_t *cmdbuf, uint8_t len, uint16_t ocf,
rc = ble_ll_conn_hci_subrate_req(cmdbuf, len, rspbuf, rsplen);
break;
#endif
#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_EXT_ADV)
#if MYNEWT_VAL(BLE_VERSION) >= 54
case BLE_HCI_OCF_LE_SET_EXT_ADV_PARAM_V2:
rc = ble_ll_adv_ext_set_param_v2(cmdbuf, len, rspbuf, rsplen);
break;
#endif
#endif
#if MYNEWT_VAL(BLE_LL_CHANNEL_SOUNDING)
case BLE_HCI_OCF_LE_CS_RD_LOC_SUPP_CAP:
rc = ble_ll_cs_hci_rd_loc_supp_cap(rspbuf, rsplen);
Expand Down
3 changes: 3 additions & 0 deletions nimble/controller/src/ble_ll_hci_supp_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,9 @@ static const uint8_t octet_46 = OCTET(
BIT(0) /* HCI LE Set Default Subrate */
BIT(1) /* HCI LE Subrate Request */
#endif
#if MYNEWT_VAL(BLE_VERSION) >= 54
BIT(2) /* HCI LE Set Extended Advertising Parameters [v2] */
#endif
);

static const uint8_t g_ble_ll_hci_supp_cmds[64] = {
Expand Down
7 changes: 7 additions & 0 deletions nimble/include/nimble/hci_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -1637,6 +1637,13 @@ struct ble_hci_vs_set_local_irk_cp {
#define BLE_HCI_PRIVACY_NETWORK (0)
#define BLE_HCI_PRIVACY_DEVICE (1)

/* --- LE set advertising coded PHY options (OCF 0x007F) */
#define BLE_HCI_ADVERTISING_PH_OPT_NO_PREF 0x0
#define BLE_HCI_ADVERTISING_PH_OPT_S2_PREF 0x1
#define BLE_HCI_ADVERTISING_PH_OPT_S8_PREF 0x2
#define BLE_HCI_ADVERTISING_PH_OPT_S2_REQ 0x3
#define BLE_HCI_ADVERTISING_PH_OPT_S8_REQ 0x4

/* Event Codes */
#define BLE_HCI_EVCODE_INQUIRY_CMP (0x01)
#define BLE_HCI_EVCODE_INQUIRY_RESULT (0x02)
Expand Down

0 comments on commit b41fb6c

Please sign in to comment.