Skip to content

Commit f3bdd2b

Browse files
Thomas-Deppekartben
authored andcommitted
Bluetooth: Host: Add support for Advertising Coding Selection
Adds API for Advertising Coding Selection. Introduces two new advertising options to configure the advertiser's requirement concerning coding scheme when LE Coded PHY is configured. While the Bluetooth v6.0 specification makes a distinction betweeen preferred and required advertising PHY options, a simplification is made to only expose the required PHY options. Inline with how LE Coded PHY is implemented; this API will set both the primary and secondary advertising PHY's to the same coding scheme. The support is enabled by CONFIG_BT_EXT_ADV_CODING_SELECTION, and requires a controller that selects CONFIG_BT_CTLR_ADV_EXT_CODING_SELECTION_SUPPORT. Signed-off-by: Thomas Deppe <[email protected]>
1 parent 39dcdcd commit f3bdd2b

File tree

7 files changed

+133
-5
lines changed

7 files changed

+133
-5
lines changed

include/zephyr/bluetooth/bluetooth.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,40 @@ enum {
784784
* @note Mutually exclusive with BT_LE_ADV_OPT_USE_IDENTITY.
785785
*/
786786
BT_LE_ADV_OPT_USE_NRPA = BIT(19),
787+
788+
/**
789+
* @brief Configures the advertiser to use the S=2 coding scheme for
790+
* LE Coded PHY.
791+
*
792+
* Sets the advertiser's required coding scheme to S=2, which is one
793+
* of the coding options available for LE Coded PHY. The S=2 coding
794+
* scheme offers higher data rates compared to S=8, with a trade-off
795+
* of reduced range. The coding scheme will only be set if both the
796+
* primary and secondary advertising channels indicate LE Coded Phy.
797+
* Additionally, the Controller must support the LE Feature Advertising
798+
* Coding Selection. If these conditions are not met, it will default to
799+
* no required coding scheme.
800+
*
801+
* @note Requires @kconfig{BT_EXT_ADV_CODING_SELECTION}
802+
*/
803+
BT_LE_ADV_OPT_REQUIRE_S2_CODING = BIT(20),
804+
805+
/**
806+
* @brief Configures the advertiser to use the S=8 coding scheme for
807+
* LE Coded PHY.
808+
*
809+
* Sets the advertiser's required coding scheme to S=8, which is one
810+
* of the coding options available for LE Coded PHY. The S=8 coding
811+
* scheme offers increased range compared to S=2, with a trade-off
812+
* of lower data rates. The coding scheme will only be set if both the
813+
* primary and secondary advertising channels indicate LE Coded Phy.
814+
* Additionally, the Controller must support the LE Feature Advertising
815+
* Coding Selection. If these conditions are not met, it will default to
816+
* no required coding scheme.
817+
*
818+
* @note Requires @kconfig{BT_EXT_ADV_CODING_SELECTION}
819+
*/
820+
BT_LE_ADV_OPT_REQUIRE_S8_CODING = BIT(21),
787821
};
788822

789823
/** LE Advertising Parameters. */

include/zephyr/bluetooth/hci_types.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ struct bt_hci_cmd_hdr {
198198
#define BT_LE_FEAT_BIT_CONN_SUBRATING 37
199199
#define BT_LE_FEAT_BIT_CONN_SUBRATING_HOST_SUPP 38
200200
#define BT_LE_FEAT_BIT_CHANNEL_CLASSIFICATION 39
201+
#define BT_LE_FEAT_BIT_ADV_CODING_SEL 40
202+
#define BT_LE_FEAT_BIT_ADV_CODING_SEL_HOST 41
201203

202204
#define BT_LE_FEAT_BIT_PAWR_ADVERTISER 43
203205
#define BT_LE_FEAT_BIT_PAWR_SCANNER 44
@@ -268,6 +270,10 @@ struct bt_hci_cmd_hdr {
268270
BT_LE_FEAT_BIT_CONN_SUBRATING_HOST_SUPP)
269271
#define BT_FEAT_LE_CHANNEL_CLASSIFICATION(feat) BT_LE_FEAT_TEST(feat, \
270272
BT_LE_FEAT_BIT_CHANNEL_CLASSIFICATION)
273+
#define BT_FEAT_LE_ADV_CODING_SEL(feat) BT_LE_FEAT_TEST(feat, \
274+
BT_LE_FEAT_BIT_ADV_CODING_SEL)
275+
#define BT_FEAT_LE_ADV_CODING_SEL_HOST(feat) BT_LE_FEAT_TEST(feat, \
276+
BT_LE_FEAT_BIT_ADV_CODING_SEL_HOST)
271277
#define BT_FEAT_LE_PAWR_ADVERTISER(feat) BT_LE_FEAT_TEST(feat, \
272278
BT_LE_FEAT_BIT_PAWR_ADVERTISER)
273279
#define BT_FEAT_LE_PAWR_SCANNER(feat) BT_LE_FEAT_TEST(feat, \
@@ -1538,6 +1544,30 @@ struct bt_hci_rp_le_set_ext_adv_param {
15381544
int8_t tx_power;
15391545
} __packed;
15401546

1547+
#define BT_HCI_LE_ADV_PHY_OPTION_NO_REQUIRED 0x00
1548+
#define BT_HCI_LE_ADV_PHY_OPTION_REQUIRE_S2 0x03
1549+
#define BT_HCI_LE_ADV_PHY_OPTION_REQUIRE_S8 0x04
1550+
1551+
#define BT_HCI_OP_LE_SET_EXT_ADV_PARAM_V2 BT_OP(BT_OGF_LE, 0x007F) /* 0x207F */
1552+
struct bt_hci_cp_le_set_ext_adv_param_v2 {
1553+
uint8_t handle;
1554+
uint16_t props;
1555+
uint8_t prim_min_interval[3];
1556+
uint8_t prim_max_interval[3];
1557+
uint8_t prim_channel_map;
1558+
uint8_t own_addr_type;
1559+
bt_addr_le_t peer_addr;
1560+
uint8_t filter_policy;
1561+
int8_t tx_power;
1562+
uint8_t prim_adv_phy;
1563+
uint8_t sec_adv_max_skip;
1564+
uint8_t sec_adv_phy;
1565+
uint8_t sid;
1566+
uint8_t scan_req_notify_enable;
1567+
uint8_t prim_adv_phy_opt;
1568+
uint8_t sec_adv_phy_opt;
1569+
} __packed;
1570+
15411571
#define BT_HCI_LE_EXT_ADV_OP_INTERM_FRAG 0x00
15421572
#define BT_HCI_LE_EXT_ADV_OP_FIRST_FRAG 0x01
15431573
#define BT_HCI_LE_EXT_ADV_OP_LAST_FRAG 0x02

subsys/bluetooth/Kconfig.adv

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ config BT_PER_ADV_SYNC_RSP
6868
Select this to enable Periodic Advertising with Responses Sync
6969
API support.
7070

71+
config BT_EXT_ADV_CODING_SELECTION
72+
bool "Advertising Coding Selection support"
73+
depends on !HAS_BT_CTLR || BT_CTLR_PHY_CODED
74+
help
75+
Select this to enable Advertising Coding Selection API support.
76+
This allows the Host to indicate their strict requirement
77+
concerning coding scheme when using Extended Advertising.
78+
7179
if BT_PER_ADV_SYNC
7280

7381
config BT_PER_ADV_SYNC_MAX

subsys/bluetooth/controller/Kconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ config BT_CTLR_PHY_CODED_SUPPORT
4545
config BT_CTLR_ADV_EXT_SUPPORT
4646
bool
4747

48+
config BT_CTLR_ADV_EXT_CODING_SELECTION_SUPPORT
49+
depends on BT_CTLR_PHY_CODED_SUPPORT
50+
bool
51+
4852
config BT_CTLR_ADV_PERIODIC_SUPPORT
4953
depends on BT_CTLR_ADV_EXT_SUPPORT
5054
bool
@@ -780,6 +784,14 @@ config BT_CTLR_ADV_PERIODIC_RSP
780784
Enable support for Bluetooth 5.4 LE Periodic Advertising with
781785
Responses in the Controller.
782786

787+
config BT_CTLR_ADV_EXT_CODING_SELECTION
788+
bool "Advertising Coding Selection support"
789+
depends on BT_CTLR_PHY_CODED && BT_CTLR_ADV_EXT_CODING_SELECTION_SUPPORT
790+
default y if BT_EXT_ADV_CODING_SELECTION
791+
help
792+
Enable support for Bluetooth 6.0 Advertising Coding Selection
793+
in the Controller.
794+
783795
if BT_CTLR_ADV_PERIODIC
784796

785797
config BT_CTLR_ADV_PERIODIC_ADI_SUPPORT

subsys/bluetooth/host/adv.c

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,20 +1121,32 @@ static int le_ext_adv_param_set(struct bt_le_ext_adv *adv,
11211121
const struct bt_le_adv_param *param,
11221122
bool has_scan_data)
11231123
{
1124-
struct bt_hci_cp_le_set_ext_adv_param *cp;
1124+
struct bt_hci_cp_le_set_ext_adv_param_v2 *cp;
1125+
1126+
uint16_t opcode;
1127+
uint16_t size;
11251128
bool dir_adv = param->peer != NULL, scannable;
11261129
struct net_buf *buf, *rsp;
11271130
int err;
11281131
enum adv_name_type name_type;
11291132
uint16_t props = 0;
11301133

1131-
buf = bt_hci_cmd_create(BT_HCI_OP_LE_SET_EXT_ADV_PARAM, sizeof(*cp));
1134+
if (IS_ENABLED(CONFIG_BT_EXT_ADV_CODING_SELECTION) &&
1135+
BT_FEAT_LE_ADV_CODING_SEL(bt_dev.le.features)) {
1136+
opcode = BT_HCI_OP_LE_SET_EXT_ADV_PARAM_V2;
1137+
size = sizeof(struct bt_hci_cp_le_set_ext_adv_param_v2);
1138+
} else {
1139+
opcode = BT_HCI_OP_LE_SET_EXT_ADV_PARAM;
1140+
size = sizeof(struct bt_hci_cp_le_set_ext_adv_param);
1141+
}
1142+
1143+
buf = bt_hci_cmd_create(opcode, size);
11321144
if (!buf) {
11331145
return -ENOBUFS;
11341146
}
11351147

1136-
cp = net_buf_add(buf, sizeof(*cp));
1137-
(void)memset(cp, 0, sizeof(*cp));
1148+
cp = net_buf_add(buf, size);
1149+
(void)memset(cp, 0, size);
11381150

11391151
adv->options = param->options;
11401152

@@ -1171,6 +1183,22 @@ static int le_ext_adv_param_set(struct bt_le_ext_adv *adv,
11711183
if (param->options & BT_LE_ADV_OPT_CODED) {
11721184
cp->prim_adv_phy = BT_HCI_LE_PHY_CODED;
11731185
cp->sec_adv_phy = BT_HCI_LE_PHY_CODED;
1186+
1187+
if (IS_ENABLED(CONFIG_BT_EXT_ADV_CODING_SELECTION) &&
1188+
opcode == BT_HCI_OP_LE_SET_EXT_ADV_PARAM_V2) {
1189+
uint8_t adv_phy_opt;
1190+
1191+
if (param->options & BT_LE_ADV_OPT_REQUIRE_S8_CODING) {
1192+
adv_phy_opt = BT_HCI_LE_ADV_PHY_OPTION_REQUIRE_S8;
1193+
} else if (param->options & BT_LE_ADV_OPT_REQUIRE_S2_CODING) {
1194+
adv_phy_opt = BT_HCI_LE_ADV_PHY_OPTION_REQUIRE_S2;
1195+
} else {
1196+
adv_phy_opt = BT_HCI_LE_ADV_PHY_OPTION_NO_REQUIRED;
1197+
}
1198+
1199+
cp->prim_adv_phy_opt = adv_phy_opt;
1200+
cp->sec_adv_phy_opt = adv_phy_opt;
1201+
}
11741202
}
11751203

11761204
if (!(param->options & BT_LE_ADV_OPT_EXT_ADV)) {
@@ -1222,7 +1250,7 @@ static int le_ext_adv_param_set(struct bt_le_ext_adv *adv,
12221250
cp->sec_adv_max_skip = param->secondary_max_skip;
12231251

12241252
cp->props = sys_cpu_to_le16(props);
1225-
err = bt_hci_cmd_send_sync(BT_HCI_OP_LE_SET_EXT_ADV_PARAM, buf, &rsp);
1253+
err = bt_hci_cmd_send_sync(opcode, buf, &rsp);
12261254
if (err) {
12271255
return err;
12281256
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CONFIG_BT=y
2+
CONFIG_BT_BROADCASTER=y
3+
CONFIG_BT_PERIPHERAL=y
4+
CONFIG_BT_OBSERVER=y
5+
CONFIG_BT_CENTRAL=y
6+
CONFIG_BT_EXT_ADV=y
7+
CONFIG_BT_CTLR_PHY_CODED=y
8+
CONFIG_BT_EXT_ADV_CODING_SELECTION=y
9+
CONFIG_ZTEST=y

tests/bluetooth/init/testcase.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,3 +349,10 @@ tests:
349349
- CONFIG_BT_RECV_WORKQ_BT=y
350350
platform_allow:
351351
- nrf52840dk/nrf52840
352+
bluetooth.init.test_host_6_x:
353+
extra_args: CONF_FILE=prj_host_6_x.conf
354+
platform_allow:
355+
- qemu_cortex_m3
356+
- nrf52840dk/nrf52840
357+
integration_platforms:
358+
- nrf52840dk/nrf52840

0 commit comments

Comments
 (0)