Skip to content

Commit

Permalink
[nrf fromtree] Bluetooth: Host: Add host support for Advertising Codi…
Browse files Browse the repository at this point in the history
…ng Selection

Extends the API for Advertising Coding Selection.

The API is extended to set the Advertising Coding Selection
(Host Support) bit. With this feature, the primary and
secondary PHY can now explicitly report S=2 or S=8 coding
in the extended advertising report. Previously, the report
only indicated LE Coded regardless of whether S=2 or S=8
data coding was used. The API now sets the host support bit
and ensures that the advertising PHY coding scheme is
conveyed to the application via the scan callback.

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]>
(cherry picked from commit dcbcbe824d079d76aac2dca29e14b50dd5bee7d3)
  • Loading branch information
Thomas-Deppe committed Feb 18, 2025
1 parent f083cf5 commit 1dba958
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 3 deletions.
10 changes: 9 additions & 1 deletion include/zephyr/bluetooth/gap.h
Original file line number Diff line number Diff line change
Expand Up @@ -747,8 +747,16 @@ enum {
BT_GAP_LE_PHY_1M = BIT(0),
/** LE 2M PHY */
BT_GAP_LE_PHY_2M = BIT(1),
/** LE Coded PHY */
/** LE Coded PHY, coding scheme not specified */
BT_GAP_LE_PHY_CODED = BIT(2),
/** LE Coded S=8 PHY. Only used for advertising reports
* when Kconfig BT_EXT_ADV_CODING_SELECTION is enabled.
*/
BT_GAP_LE_PHY_CODED_S8 = BIT(3),
/** LE Coded S=2 PHY. Only used for advertising reports
* when Kconfig BT_EXT_ADV_CODING_SELECTION is enabled.
*/
BT_GAP_LE_PHY_CODED_S2 = BIT(4),
};

/** Advertising PDU types */
Expand Down
8 changes: 8 additions & 0 deletions include/zephyr/bluetooth/hci_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -3203,6 +3203,14 @@ struct bt_hci_evt_le_phy_update_complete {
#define BT_HCI_LE_ADV_EVT_TYPE_DATA_STATUS_INCOMPLETE 2
#define BT_HCI_LE_ADV_EVT_TYPE_DATA_STATUS_RX_FAILED 0xFF

/* Advertising Coding Selection extended advertising report PHY values.
* Only used when Kconfig BT_EXT_ADV_CODING_SELECTION is enabled.
*/
#define BT_HCI_LE_ADV_EVT_PHY_1M 0x01
#define BT_HCI_LE_ADV_EVT_PHY_2M 0x02
#define BT_HCI_LE_ADV_EVT_PHY_CODED_S8 0x03
#define BT_HCI_LE_ADV_EVT_PHY_CODED_S2 0x04

struct bt_hci_evt_le_ext_advertising_info {
uint16_t evt_type;
bt_addr_le_t addr;
Expand Down
1 change: 1 addition & 0 deletions subsys/bluetooth/controller/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,7 @@ config BT_CTLR_ADV_PERIODIC_RSP
config BT_CTLR_ADV_EXT_CODING_SELECTION
bool "Advertising Coding Selection support"
depends on BT_CTLR_PHY_CODED && BT_CTLR_ADV_EXT_CODING_SELECTION_SUPPORT
select BT_CTLR_SET_HOST_FEATURE if BT_OBSERVER
default y if BT_EXT_ADV_CODING_SELECTION
help
Enable support for Bluetooth 6.0 Advertising Coding Selection
Expand Down
8 changes: 8 additions & 0 deletions subsys/bluetooth/host/hci_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -3682,6 +3682,14 @@ static int le_init(void)
}
}

if (IS_ENABLED(CONFIG_BT_EXT_ADV_CODING_SELECTION) &&
BT_FEAT_LE_ADV_CODING_SEL(bt_dev.le.features)) {
err = le_set_host_feature(BT_LE_FEAT_BIT_ADV_CODING_SEL_HOST, 1);
if (err) {
return err;
}
}

return le_set_event_mask();
}

Expand Down
33 changes: 31 additions & 2 deletions subsys/bluetooth/host/scan.c
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,28 @@ static uint8_t get_adv_type(uint8_t evt_type)
}
}

/* Convert Extended adv report PHY to GAP PHY */
static uint8_t get_ext_adv_coding_sel_phy(uint8_t hci_phy)
{
/* Converts from Extended adv report PHY to BT_GAP_LE_PHY_*
* When Advertising Coding Selection (Host Support) is enabled
* the controller will return the advertising coding scheme which
* can be S=2 or S=8 data coding.
*/
switch (hci_phy) {
case BT_HCI_LE_ADV_EVT_PHY_1M:
return BT_GAP_LE_PHY_1M;
case BT_HCI_LE_ADV_EVT_PHY_2M:
return BT_GAP_LE_PHY_2M;
case BT_HCI_LE_ADV_EVT_PHY_CODED_S8:
return BT_GAP_LE_PHY_CODED_S8;
case BT_HCI_LE_ADV_EVT_PHY_CODED_S2:
return BT_GAP_LE_PHY_CODED_S2;
default:
return 0;
}
}

/* Convert extended adv report evt_type field to adv props */
static uint16_t get_adv_props_extended(uint16_t evt_type)
{
Expand All @@ -755,8 +777,15 @@ static uint16_t get_adv_props_extended(uint16_t evt_type)
static void create_ext_adv_info(struct bt_hci_evt_le_ext_advertising_info const *const evt,
struct bt_le_scan_recv_info *const scan_info)
{
scan_info->primary_phy = bt_get_phy(evt->prim_phy);
scan_info->secondary_phy = bt_get_phy(evt->sec_phy);
if (IS_ENABLED(CONFIG_BT_EXT_ADV_CODING_SELECTION) &&
BT_FEAT_LE_ADV_CODING_SEL(bt_dev.le.features)) {
scan_info->primary_phy = get_ext_adv_coding_sel_phy(evt->prim_phy);
scan_info->secondary_phy = get_ext_adv_coding_sel_phy(evt->sec_phy);
} else {
scan_info->primary_phy = bt_get_phy(evt->prim_phy);
scan_info->secondary_phy = bt_get_phy(evt->sec_phy);
}

scan_info->tx_power = evt->tx_power;
scan_info->rssi = evt->rssi;
scan_info->sid = evt->sid;
Expand Down

0 comments on commit 1dba958

Please sign in to comment.