Skip to content

Commit 6dcd7c0

Browse files
committed
Bluetooth: Host: Add advertising state to bt_le_ext_adv_info
The bt_le_ext_adv_info struct has been extended to also contain the advertising and periodic advertising states. Additionally, the function verifies the input to avoid NULL pointer access, and the addr field is more properly documented. Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
1 parent 179045e commit 6dcd7c0

File tree

3 files changed

+69
-3
lines changed

3 files changed

+69
-3
lines changed

include/zephyr/bluetooth/bluetooth.h

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1714,6 +1714,27 @@ int bt_le_ext_adv_delete(struct bt_le_ext_adv *adv);
17141714
*/
17151715
uint8_t bt_le_ext_adv_get_index(struct bt_le_ext_adv *adv);
17161716

1717+
/** Advertising states. */
1718+
enum bt_le_ext_adv_state {
1719+
/** The advertising set has been created but not enabled. */
1720+
BT_LE_EXT_ADV_STATE_DISABLED,
1721+
1722+
/** The advertising set is enabled. */
1723+
BT_LE_EXT_ADV_STATE_ENABLED,
1724+
};
1725+
1726+
/** Periodic Advertising states. */
1727+
enum bt_le_per_adv_state {
1728+
/** Not configured for periodic advertising. */
1729+
BT_LE_PER_ADV_STATE_NONE,
1730+
1731+
/** The advertising set has been configured for periodic advertising, but is not enabled. */
1732+
BT_LE_PER_ADV_STATE_DISABLED,
1733+
1734+
/** Periodic advertising is enabled. */
1735+
BT_LE_PER_ADV_STATE_ENABLED,
1736+
};
1737+
17171738
/** @brief Advertising set info structure. */
17181739
struct bt_le_ext_adv_info {
17191740
/** Local identity handle. */
@@ -1724,15 +1745,22 @@ struct bt_le_ext_adv_info {
17241745

17251746
/** Current local advertising address used. */
17261747
const bt_addr_le_t *addr;
1748+
1749+
/** Extended advertising state. */
1750+
enum bt_le_ext_adv_state ext_adv_state;
1751+
1752+
/** Periodic advertising state. */
1753+
enum bt_le_per_adv_state per_adv_state;
17271754
};
17281755

17291756
/**
17301757
* @brief Get advertising set info
17311758
*
17321759
* @param adv Advertising set object
1733-
* @param info Advertising set info object
1760+
* @param info Advertising set info object. The values in this object are only valid on success.
17341761
*
1735-
* @return Zero on success or (negative) error code on failure.
1762+
* @retval 0 Success.
1763+
* @retval -EINVAL @p adv is not valid advertising set or @p info is NULL.
17361764
*/
17371765
int bt_le_ext_adv_get_info(const struct bt_le_ext_adv *adv,
17381766
struct bt_le_ext_adv_info *info);

subsys/bluetooth/host/adv.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,10 +1592,43 @@ void bt_le_adv_resume(void)
15921592
int bt_le_ext_adv_get_info(const struct bt_le_ext_adv *adv,
15931593
struct bt_le_ext_adv_info *info)
15941594
{
1595+
if (!IS_ARRAY_ELEMENT(adv_pool, adv)) {
1596+
LOG_DBG("adv %p is a valid pointer from bt_le_ext_adv_create", adv);
1597+
return -EINVAL;
1598+
}
1599+
1600+
if (!atomic_test_bit(adv->flags, BT_ADV_CREATED)) {
1601+
LOG_DBG("Advertising set %p is not created", adv);
1602+
return -EINVAL;
1603+
}
1604+
1605+
if (info == NULL) {
1606+
LOG_DBG("info is NULL");
1607+
return -EINVAL;
1608+
}
1609+
15951610
info->id = adv->id;
15961611
info->tx_power = adv->tx_power;
15971612
info->addr = &adv->random_addr;
15981613

1614+
if (atomic_test_bit(adv->flags, BT_ADV_ENABLED)) {
1615+
info->ext_adv_state = BT_LE_EXT_ADV_STATE_ENABLED;
1616+
} else {
1617+
info->ext_adv_state = BT_LE_EXT_ADV_STATE_DISABLED;
1618+
}
1619+
1620+
if (IS_ENABLED(CONFIG_BT_PER_ADV)) {
1621+
if (atomic_test_bit(adv->flags, BT_PER_ADV_ENABLED)) {
1622+
info->per_adv_state = BT_LE_PER_ADV_STATE_ENABLED;
1623+
} else if (atomic_test_bit(adv->flags, BT_PER_ADV_PARAMS_SET)) {
1624+
info->per_adv_state = BT_LE_PER_ADV_STATE_DISABLED;
1625+
} else {
1626+
info->per_adv_state = BT_LE_PER_ADV_STATE_NONE;
1627+
}
1628+
} else {
1629+
info->per_adv_state = BT_LE_PER_ADV_STATE_NONE;
1630+
}
1631+
15991632
return 0;
16001633
}
16011634

subsys/bluetooth/host/shell/bt.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2571,14 +2571,19 @@ static int cmd_adv_info(const struct shell *sh, size_t argc, char *argv[])
25712571

25722572
err = bt_le_ext_adv_get_info(adv, &info);
25732573
if (err) {
2574-
shell_error(sh, "OOB data failed");
2574+
shell_error(sh, "Failed to get advertising set info: %d", err);
25752575
return err;
25762576
}
25772577

25782578
shell_print(sh, "Advertiser[%d] %p", selected_adv, adv);
25792579
shell_print(sh, "Id: %d, TX power: %d dBm", info.id, info.tx_power);
2580+
shell_print(sh, "Adv state: %d", info.ext_adv_state);
25802581
print_le_addr("Address", info.addr);
25812582

2583+
if (IS_ENABLED(CONFIG_BT_PER_ADV)) {
2584+
shell_print(sh, "Per Adv state: %d", info.per_adv_state);
2585+
}
2586+
25822587
return 0;
25832588
}
25842589

0 commit comments

Comments
 (0)