feat(ble/bluedroid): Add bluedroid host Advertising Coding Selection feature

This commit is contained in:
zhiweijian
2025-05-16 20:27:53 +08:00
parent 382174fdf0
commit cd156796d8
11 changed files with 196 additions and 39 deletions
+39 -32
View File
@@ -1302,7 +1302,7 @@ config BT_BLE_RPA_TIMEOUT
Default is 900 s (15 minutes). Range is 1 s to 1 hour (3600 s).
menuconfig BT_BLE_50_FEATURES_SUPPORTED
bool "Enable BLE 5.0 features(please disable BLE 4.2 if enable BLE 5.0)"
bool "Enable BLE 5.0 and above features(please disable BLE 4.2 if enable BLE 5.0)"
depends on (BT_BLE_ENABLED && ((BT_CONTROLLER_ENABLED && SOC_BLE_50_SUPPORTED) || BT_CONTROLLER_DISABLED))
default y
help
@@ -1366,37 +1366,6 @@ config BT_BLE_FEAT_CREATE_SYNC_ENH
help
Enable the create sync enhancements
menuconfig BT_BLE_42_FEATURES_SUPPORTED
bool "Enable BLE 4.2 features(please disable BLE 5.0 if enable BLE 4.2)"
depends on BT_BLE_ENABLED
default y if IDF_TARGET_ESP32
default n
help
This enables BLE 4.2 features.
This option is universally supported by all ESP chips with BLE capabilities.
BLE 4.2 and BLE 5.0 cannot be used simultaneously.
config BT_BLE_42_DTM_TEST_EN
bool "Enable BLE 4.2 DTM test"
depends on BT_BLE_42_FEATURES_SUPPORTED
default y
help
This enables BLE 4.2 direct test mode
config BT_BLE_42_ADV_EN
bool "Enable BLE 4.2 advertising"
depends on BT_BLE_42_FEATURES_SUPPORTED
default y
help
This enables BLE v4.2 advertising
config BT_BLE_42_SCAN_EN
bool "Enable BLE 4.2 scan"
depends on BT_BLE_42_FEATURES_SUPPORTED
default y
help
This enables BLE v4.2 scan
menuconfig BT_BLE_FEAT_ISO_EN
bool "Enable BLE 5.2 iso feature"
depends on (BT_BLE_50_FEATURES_SUPPORTED && ((BT_CONTROLLER_ENABLED && SOC_BLE_AUDIO_SUPPORTED) || BT_CONTROLLER_DISABLED)) # NOERROR
@@ -1516,6 +1485,44 @@ config BT_BLE_FEAT_PAWR_EN
help
Enable BLE Periodic Advertisement with Response(PAwR) feature
config BT_BLE_FEAT_ADV_CODING_SELECTION
bool "Enable Advertising Coding Selection"
depends on (BT_BLE_50_FEATURES_SUPPORTED && ((BT_CONTROLLER_ENABLED && SOC_BLE_ADV_CODING_SELECT_SUPPORTED) || BT_CONTROLLER_DISABLED)) # NOERROR
default n
help
Enable Advertising Coding Selection
menuconfig BT_BLE_42_FEATURES_SUPPORTED
bool "Enable BLE 4.2 features(please disable BLE 5.0 if enable BLE 4.2)"
depends on BT_BLE_ENABLED
default y if IDF_TARGET_ESP32
default n
help
This enables BLE 4.2 features.
This option is universally supported by all ESP chips with BLE capabilities.
BLE 4.2 and BLE 5.0 cannot be used simultaneously.
config BT_BLE_42_DTM_TEST_EN
bool "Enable BLE 4.2 DTM test"
depends on BT_BLE_42_FEATURES_SUPPORTED
default y
help
This enables BLE 4.2 direct test mode
config BT_BLE_42_ADV_EN
bool "Enable BLE 4.2 advertising"
depends on BT_BLE_42_FEATURES_SUPPORTED
default y
help
This enables BLE v4.2 advertising
config BT_BLE_42_SCAN_EN
bool "Enable BLE 4.2 scan"
depends on BT_BLE_42_FEATURES_SUPPORTED
default y
help
This enables BLE v4.2 scan
config BT_BLE_VENDOR_HCI_EN
bool "Enable BLE Vendor HCI command and event"
depends on BT_BLE_ENABLED
@@ -862,6 +862,12 @@ typedef uint8_t esp_ble_gap_all_phys_t;
#define ESP_BLE_GAP_PRI_PHY_CODED ESP_BLE_GAP_PHY_CODED /*!< Primary Phy is LE CODED */
typedef uint8_t esp_ble_gap_pri_phy_t; // primary phy
#define ESP_BLE_GAP_RPT_PHY_1M 1 /*!< Advertiser PHY is LE 1M */
#define ESP_BLE_GAP_RPT_PHY_2M 2 /*!< Advertiser PHY is LE 2M */
#define ESP_BLE_GAP_RPT_PHY_S8 3 /*!< If the Advertising Coding Selection feature bit is set: Advertising PHY is LE 125K Otherwise: Advertiser PHY is LE Coded */
#define ESP_BLE_GAP_RPT_PHY_S2 4 /*!< If the Advertising Coding Selection feature bit is set: Advertising PHY is LE 500K Otherwise: Reserved for future use */
typedef uint8_t esp_ble_gap_rpt_phy_t; // extended Advertising report phy
#define ESP_BLE_GAP_PHY_1M_PREF_MASK (1 << 0) /*!< The Host prefers use the LE1M transmitter or receiver PHY */
#define ESP_BLE_GAP_PHY_2M_PREF_MASK (1 << 1) /*!< The Host prefers use the LE2M transmitter or receiver PHY */
#define ESP_BLE_GAP_PHY_CODED_PREF_MASK (1 << 2) /*!< The Host prefers use the LE CODED transmitter or receiver PHY */
@@ -910,6 +916,21 @@ typedef uint8_t esp_ble_gap_adv_type_t;
/// max number of advertising sets to enable or disable
#define EXT_ADV_NUM_SETS_MAX (10) /*!< max evt instance num */
#if (CONFIG_BT_BLE_FEAT_ADV_CODING_SELECTION)
// The Host has no preferred or required coding when transmitting on the LE Coded PHY
#define ESP_BLE_ADV_PHY_OPTIONS_NO_PREFER_CODED (0x00)
// The Host prefers that S=2 coding be used when transmitting on the LE Coded PHY
#define ESP_BLE_ADV_PHY_OPTIONS_PREFER_CODED_S2 (0x01)
// The Host prefers that S=8 coding be used when transmitting on the LE Coded PHY
#define ESP_BLE_ADV_PHY_OPTIONS_PREFER_CODED_S8 (0x02)
// The Host requires that S=2 coding be used when transmitting on the LE Coded PHY
#define ESP_BLE_ADV_PHY_OPTIONS_REQUIRE_CODED_S2 (0x03)
// The Host requires that S=8 coding be used when transmitting on the LE Coded PHY
#define ESP_BLE_ADV_PHY_OPTIONS_REQUIRE_CODED_S8 (0x04)
typedef uint8_t esp_ble_gap_adv_phy_options_t;
#endif //(CONFIG_BT_BLE_FEAT_ADV_CODING_SELECTION)
/**
* @brief ext adv parameters
*/
@@ -928,6 +949,20 @@ typedef struct {
esp_ble_gap_phy_t secondary_phy; /*!< ext adv secondary phy */
uint8_t sid; /*!< ext adv sid */
bool scan_req_notif; /*!< ext adv scan request event notify */
#if (CONFIG_BT_BLE_FEAT_ADV_CODING_SELECTION)
esp_ble_gap_adv_phy_options_t primary_adv_phy_options; /*!<
0x00: The Host has no preferred or required coding when transmitting on the LE Coded PHY
0x01: The Host prefers that S=2 coding be used when transmitting on the LE Coded PHY
0x02: The Host prefers that S=8 coding be used when transmitting on the LE Coded PHY
0x03: The Host requires that S=2 coding be used when transmitting on the LE Coded PHY
0x04: The Host requires that S=8 coding be used when transmitting on the LE Coded PHY */
esp_ble_gap_adv_phy_options_t secondary_adv_phy_options; /*!<
0x00: The Host has no preferred or required coding when transmitting on the LE Coded PHY
0x01: The Host prefers that S=2 coding be used when transmitting on the LE Coded PHY
0x02: The Host prefers that S=8 coding be used when transmitting on the LE Coded PHY
0x03: The Host requires that S=2 coding be used when transmitting on the LE Coded PHY
0x04: The Host requires that S=8 coding be used when transmitting on the LE Coded PHY */
#endif // CONFIG_BT_BLE_FEAT_ADV_CODING_SELECTION
} esp_ble_gap_ext_adv_params_t;
/**
@@ -1040,8 +1075,28 @@ typedef struct {
esp_ble_gap_adv_type_t event_type; /*!< extend advertising type */
uint8_t addr_type; /*!< extend advertising address type */
esp_bd_addr_t addr; /*!< extend advertising address */
#if (CONFIG_BT_BLE_FEAT_PAWR_EN)
esp_ble_gap_rpt_phy_t primary_phy; /*!< extend advertising primary phy
0x01: Advertiser PHY is LE 1M
0x03: If the Advertising Coding Selection (Host Support) feature bit is set: Advertising PHY is LE Coded with S=8 data coding
Otherwise: Advertiser PHY is LE Coded
0x04: If the Advertising Coding Selection (Host Support) feature bit is set: Advertising PHY is LE Coded with S=2 data coding
Otherwise: Reserved for future use
*/
esp_ble_gap_rpt_phy_t secondly_phy; /*!< extend advertising secondary phy
0x00: No packets on the secondary advertising physical channel
0x01: Advertiser PHY is LE 1M
0x02: Advertiser PHY is LE 2M
0x03: If the Advertising Coding Selection (Host Support) feature bit is set: Advertising PHY is LE Coded with S=8 data coding
Otherwise: Advertiser PHY is LE Coded
0x04: If the Advertising Coding Selection (Host Support) feature bit is set: Advertising PHY is LE Coded with S=2 data coding
Otherwise: Reserved for future use
*/
#else
esp_ble_gap_pri_phy_t primary_phy; /*!< extend advertising primary phy */
esp_ble_gap_phy_t secondly_phy; /*!< extend advertising secondary phy */
#endif
uint8_t sid; /*!< extend advertising sid */
uint8_t tx_power; /*!< extend advertising tx power */
int8_t rssi; /*!< extend advertising rssi */
@@ -1573,6 +1573,10 @@ typedef struct {
tBTA_DM_BLE_GAP_PHY secondary_phy;
UINT8 sid;
BOOLEAN scan_req_notif;
#if (BT_BLE_FEAT_ADV_CODING_SELECTION == TRUE)
uint8_t primary_adv_phy_options;
uint8_t secondary_adv_phy_options;
#endif // (BT_BLE_FEAT_ADV_CODING_SELECTION == TRUE)
} tBTA_DM_BLE_GAP_EXT_ADV_PARAMS;
typedef struct {
@@ -2138,7 +2138,7 @@ void btc_gap_ble_cb_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
break;
#endif // (BT_BLE_FEAT_PAWR_EN == TRUE)
default:
BTC_TRACE_ERROR("%s, Unhandled deep copy %d\n", __func__, msg->act);
// BTC_TRACE_ERROR("%s, Unhandled deep copy %d\n", __func__, msg->act);
break;
}
}
@@ -2619,7 +2619,10 @@ void btc_gap_ble_call_handler(btc_msg_t *msg)
params.secondary_phy = arg_5->ext_adv_set_params.params.secondary_phy;
params.sid = arg_5->ext_adv_set_params.params.sid;
params.scan_req_notif = arg_5->ext_adv_set_params.params.scan_req_notif;
#if (BT_BLE_FEAT_ADV_CODING_SELECTION == TRUE)
params.primary_adv_phy_options = arg_5->ext_adv_set_params.params.primary_adv_phy_options;
params.secondary_adv_phy_options= arg_5->ext_adv_set_params.params.secondary_adv_phy_options;
#endif // (BT_BLE_FEAT_ADV_CODING_SELECTION == TRUE)
memcpy(params.peer_addr, arg_5->ext_adv_set_params.params.peer_addr, sizeof(BD_ADDR));
BTC_TRACE_DEBUG("BTC_GAP_BLE_SET_EXT_ADV_PARAMS");
@@ -370,6 +370,12 @@
#define UC_BT_BLE_FEAT_PAWR_EN FALSE
#endif
#ifdef CONFIG_BT_BLE_FEAT_ADV_CODING_SELECTION
#define UC_BT_BLE_FEAT_ADV_CODING_SELECTION CONFIG_BT_BLE_FEAT_ADV_CODING_SELECTION
#else
#define UC_BT_BLE_FEAT_ADV_CODING_SELECTION FALSE
#endif
#ifdef CONFIG_BT_BLE_VENDOR_HCI_EN
#define UC_BT_BLE_VENDOR_HCI_EN CONFIG_BT_BLE_VENDOR_HCI_EN
#else
@@ -421,6 +421,12 @@
#define BT_BLE_FEAT_PAWR_EN FALSE
#endif
#if (UC_BT_BLE_FEAT_ADV_CODING_SELECTION == TRUE)
#define BT_BLE_FEAT_ADV_CODING_SELECTION TRUE
#else
#define BT_BLE_FEAT_ADV_CODING_SELECTION FALSE
#endif
#if (UC_BT_BLE_VENDOR_HCI_EN == TRUE)
#define BLE_VENDOR_HCI_EN TRUE
#else
@@ -401,7 +401,18 @@ tBTM_STATUS BTM_BleSetExtendedAdvParams(UINT8 instance, tBTM_BLE_GAP_EXT_ADV_PAR
#else
btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type = params->own_addr_type;
#endif
#if (BT_BLE_FEAT_ADV_CODING_SELECTION == TRUE)
if ((err = btsnd_hcic_ble_set_ext_adv_params_v2(instance, params->type, params->interval_min, params->interval_max,
params->channel_map, params->own_addr_type, params->peer_addr_type,
params->peer_addr, params->filter_policy, params->tx_power,
params->primary_phy, params->max_skip,
params->secondary_phy, params->sid, params->scan_req_notif,
params->primary_adv_phy_options, params->secondary_adv_phy_options)) != HCI_SUCCESS) {
BTM_TRACE_ERROR("LE EA SetParams: cmd err=0x%x", err);
status = BTM_HCI_ERROR | err;
goto end;
}
#else
if ((err = btsnd_hcic_ble_set_ext_adv_params(instance, params->type, params->interval_min, params->interval_max,
params->channel_map, params->own_addr_type, params->peer_addr_type,
params->peer_addr, params->filter_policy, params->tx_power,
@@ -411,6 +422,7 @@ tBTM_STATUS BTM_BleSetExtendedAdvParams(UINT8 instance, tBTM_BLE_GAP_EXT_ADV_PAR
status = BTM_HCI_ERROR | err;
goto end;
}
#endif // (BT_BLE_FEAT_ADV_CODING_SELECTION == TRUE)
extend_adv_cb.inst[instance].configured = true;
@@ -692,7 +704,6 @@ tBTM_STATUS BTM_BlePeriodicAdvSetParams(UINT8 instance, tBTM_BLE_Periodic_Adv_Pa
tBTM_STATUS status = BTM_SUCCESS;
tHCI_STATUS err = HCI_SUCCESS;
tBTM_BLE_5_GAP_CB_PARAMS cb_params = {0};
//ext_adv_flag = true;
if (instance >= MAX_BLE_ADV_INSTANCE) {
status = BTM_ILLEGAL_VALUE;
@@ -1221,7 +1221,55 @@ UINT8 btsnd_hcic_ble_set_extend_rand_address(UINT8 adv_handle, BD_ADDR rand_addr
return btu_hcif_send_cmd_sync (LOCAL_BR_EDR_CONTROLLER_ID, p);
}
#if (BT_BLE_FEAT_ADV_CODING_SELECTION == TRUE)
UINT8 btsnd_hcic_ble_set_ext_adv_params_v2(UINT8 adv_handle, UINT16 properties, UINT32 interval_min,
UINT32 interval_max, UINT8 channel_map, UINT8 own_addr_type,
UINT8 peer_addr_type, BD_ADDR peer_addr,
UINT8 adv_filter_policy, INT8 adv_tx_power,
UINT8 primary_adv_phy, UINT8 secondary_adv_max_skip,
UINT8 secondary_adv_phy,
UINT8 adv_sid, UINT8 scan_req_ntf_enable,
UINT8 primary_adv_phy_options, UINT8 secondary_adv_phy_options)
{
BT_HDR *p;
UINT8 *pp;
HCI_TRACE_EVENT("%s, adv_handle = %d, properties = %d, interval_min = %d, interval_max = %d, channel_map = %d,\n\
own_addr_type = %d, peer_addr_type = %d, adv_filter_policy = %d,\n\
adv_tx_power = %d, primary_adv_phy = %d, secondary_adv_max_skip = %d, secondary_adv_phy = %d,\n\
adv_sid = %d, scan_req_ntf_enable = %d, primary_phy_options %d secondary_phy_options %d", __func__, adv_handle, properties, interval_min, interval_max,
channel_map, own_addr_type, peer_addr_type, adv_filter_policy, adv_tx_power,
primary_adv_phy, secondary_adv_max_skip, secondary_adv_phy, adv_sid, scan_req_ntf_enable,
primary_adv_phy_options, secondary_adv_phy_options);
HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_EXT_ADV_SET_PARAMS + 2);
UINT16_TO_STREAM(pp, HCI_BLE_SET_EXT_ADV_PARAM_V2);
UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_EXT_ADV_SET_PARAMS + 2);
UINT8_TO_STREAM(pp, adv_handle);
UINT16_TO_STREAM(pp, properties);
UINT24_TO_STREAM(pp, interval_min);
UINT24_TO_STREAM(pp, interval_max);
UINT8_TO_STREAM(pp, channel_map);
UINT8_TO_STREAM(pp, own_addr_type);
UINT8_TO_STREAM(pp, peer_addr_type);
BDADDR_TO_STREAM (pp, peer_addr);
UINT8_TO_STREAM(pp, adv_filter_policy);
INT8_TO_STREAM(pp, adv_tx_power);
UINT8_TO_STREAM(pp, primary_adv_phy);
UINT8_TO_STREAM(pp, secondary_adv_max_skip);
UINT8_TO_STREAM(pp, secondary_adv_phy);
UINT8_TO_STREAM(pp, adv_sid);
UINT8_TO_STREAM(pp, scan_req_ntf_enable);
UINT8_TO_STREAM(pp, primary_adv_phy_options);
UINT8_TO_STREAM(pp, secondary_adv_phy_options);
return btu_hcif_send_cmd_sync (LOCAL_BR_EDR_CONTROLLER_ID, p);
}
#else
UINT8 btsnd_hcic_ble_set_ext_adv_params(UINT8 adv_handle, UINT16 properties, UINT32 interval_min,
UINT32 interval_max, UINT8 channel_map, UINT8 own_addr_type,
UINT8 peer_addr_type, BD_ADDR peer_addr,
@@ -1264,8 +1312,7 @@ UINT8 btsnd_hcic_ble_set_ext_adv_params(UINT8 adv_handle, UINT16 properties, UIN
return btu_hcif_send_cmd_sync (LOCAL_BR_EDR_CONTROLLER_ID, p);
}
bool ext_adv_flag = false;
#endif // #if (BT_BLE_FEAT_ADV_CODING_SELECTION == TRUE)
UINT8 btsnd_hcic_ble_set_ext_adv_data(UINT8 adv_handle,
UINT8 operation, UINT8 fragment_prefrence,
@@ -1275,7 +1322,6 @@ UINT8 btsnd_hcic_ble_set_ext_adv_data(UINT8 adv_handle,
UINT8 *pp;
HCI_TRACE_EVENT("%s, adv_handle = %d, operation = %d, fragment_prefrence = %d,\
data_len = %d", __func__, adv_handle, operation, fragment_prefrence, data_len);
ext_adv_flag = true;
HCIC_BLE_CMD_CREATED(p, pp, data_len + 4);
UINT16_TO_STREAM(pp, HCI_BLE_SET_EXT_ADV_DATA);
@@ -781,6 +781,10 @@ typedef struct {
tBTM_BLE_GAP_PHY secondary_phy;
UINT8 sid;
BOOLEAN scan_req_notif;
#if (BT_BLE_FEAT_ADV_CODING_SELECTION == TRUE)
UINT8 primary_adv_phy_options;
UINT8 secondary_adv_phy_options;
#endif // (BT_BLE_FEAT_ADV_CODING_SELECTION == TRUE)
} tBTM_BLE_GAP_EXT_ADV_PARAMS;
typedef struct {
@@ -443,6 +443,10 @@
#define HCI_BLE_SUBRATE_REQUEST (0x007E | HCI_GRP_BLE_CMDS)
#endif // #if (BLE_FEAT_CONN_SUBRATING == TRUE)
#if (BT_BLE_FEAT_ADV_CODING_SELECTION == TRUE)
#define HCI_BLE_SET_EXT_ADV_PARAM_V2 (0x007F | HCI_GRP_BLE_CMDS)
#endif // (BT_BLE_FEAT_ADV_CODING_SELECTION == TRUE)
#if (BT_BLE_FEAT_PAWR_EN == TRUE)
#define HCI_BLE_SET_PERIOD_ADV_SUBEVT_DATA (0x0082 | HCI_GRP_BLE_CMDS)
#define HCI_BLE_SET_PERIOD_ADV_RSP_DATA (0x0083 | HCI_GRP_BLE_CMDS)
@@ -1265,4 +1265,15 @@ UINT8 btsnd_hcic_ble_set_periodic_adv_rsp_data(UINT16 sync_handle, UINT16 req_ev
UINT8 btsnd_hcic_ble_set_periodic_sync_subevt(UINT16 sync_handle, UINT16 periodic_adv_properties, UINT8 num_subevents_to_sync, UINT8 *subevt);
#endif // #if (BT_BLE_FEAT_PAWR_EN == TRUE)
#if (BT_BLE_FEAT_ADV_CODING_SELECTION == TRUE)
UINT8 btsnd_hcic_ble_set_ext_adv_params_v2(UINT8 adv_handle, UINT16 properties, UINT32 interval_min,
UINT32 interval_max, UINT8 channel_map, UINT8 own_addr_type,
UINT8 peer_addr_type, BD_ADDR peer_addr,
UINT8 adv_filter_policy, INT8 adv_tx_power,
UINT8 primary_adv_phy, UINT8 secondary_adv_max_skip,
UINT8 secondary_adv_phy,
UINT8 adv_sid, UINT8 scan_req_ntf_enable,
UINT8 primary_adv_phy_options, UINT8 secondary_adv_phy_options);
#endif // (BT_BLE_FEAT_ADV_CODING_SELECTION == TRUE)
#endif