feat(ble/bluedroid): add auto-setting for is_aux parameter in esp_ble_gattc_enh_open

(cherry picked from commit 1a9f2af505)

Co-authored-by: zhanghaipeng <zhanghaipeng@espressif.com>
This commit is contained in:
Zhang Hai Peng
2026-06-02 10:23:21 +08:00
parent 80f881409e
commit ea19ba3af4
4 changed files with 49 additions and 7 deletions
@@ -93,7 +93,7 @@ esp_err_t esp_ble_gattc_enh_open(esp_gatt_if_t gattc_if, esp_ble_gatt_creat_conn
memcpy(arg.open.remote_bda, creat_conn_params->remote_bda, ESP_BD_ADDR_LEN);
arg.open.remote_addr_type = creat_conn_params->remote_addr_type;
arg.open.is_direct = creat_conn_params->is_direct;
arg.open.is_aux= creat_conn_params->is_aux;
arg.open.is_aux = creat_conn_params->is_aux;
#if (BT_BLE_FEAT_PAWR_EN == TRUE)
arg.open.is_pawr_synced = false;
arg.open.adv_handle = 0xFF;
@@ -687,7 +687,17 @@ typedef struct {
esp_bd_addr_t remote_bda; /*!< The Bluetooth address of the remote device */
esp_ble_addr_type_t remote_addr_type; /*!< Address type of the remote device */
bool is_direct; /*!< Direct connection or background auto connection(by now, background auto connection is not supported */
bool is_aux; /*!< Set to true for BLE 5.0 or higher to enable auxiliary connections; set to false for BLE 4.2 or lower. */
bool is_aux; /*!< Determines whether to use BLE 5.0 or BLE 4.2 create connection interface.
- If set to true, the BLE 5.0 interface (extended connection) will be used.
- If set to false, the BLE 4.2 interface (legacy connection) will be used.
- Note: When connecting to a legacy advertising device using BLE 5.0 interface, is_aux should be set to true.
- Auto-setting (handled in L2CAP layer): The system will automatically set this parameter based on the enabled BLE features:
* If only BLE 4.2 feature is enabled, is_aux will be automatically set to false.
* If only BLE 5.0 feature is enabled, is_aux will be automatically set to true.
* If both BLE 4.2 and BLE 5.0 features are enabled (not recommended), the stack will automatically
infer whether to use BLE 5.0 or BLE 4.2 interface based on previously used APIs.
Otherwise, the user-specified value will be used.
- Note: It is strongly recommended NOT to enable both BLE 4.2 and BLE 5.0 features simultaneously. */
esp_ble_addr_type_t own_addr_type; /*!< Specifies the address type used in the connection request. Set to 0xFF if the address type is unknown. */
esp_ble_phy_mask_t phy_mask; /*!< Indicates which PHY connection parameters will be used. When is_aux is false, only the connection params for 1M PHY can be specified */
const esp_ble_conn_params_t *phy_1m_conn_params; /*!< Connection parameters for the LE 1M PHY */
@@ -334,10 +334,22 @@ esp_err_t esp_ble_gattc_app_unregister(esp_gatt_if_t gattc_if);
*
* @note
* 1. Do not enable `BT_BLE_42_FEATURES_SUPPORTED` and `BT_BLE_50_FEATURES_SUPPORTED` in the menuconfig simultaneously.
* 1. The function always triggers `ESP_GATTC_CONNECT_EVT` and `ESP_GATTC_OPEN_EVT`.
* 2. When the device acts as GATT server, besides the above two events, this function triggers `ESP_GATTS_CONNECT_EVT` as well.
* 3. This function will establish an ACL connection as a Central and a virtual connection as a GATT Client. If the ACL connection already exists, it will create a virtual connection only.
* 2. The function always triggers `ESP_GATTC_CONNECT_EVT` and `ESP_GATTC_OPEN_EVT`.
* 3. When the device acts as GATT server, besides the above two events, this function triggers `ESP_GATTS_CONNECT_EVT` as well.
* 4. This function will establish an ACL connection as a Central and a virtual connection as a GATT Client. If the ACL connection already exists, it will create a virtual connection only.
* 5. The `is_aux` parameter in `esp_gatt_creat_conn_params_t` determines which connection interface to use:
* - If `is_aux` is true, the BLE 5.0 extended connection interface will be used.
* - If `is_aux` is false, the BLE 4.2 interface (legacy connection) will be used.
* - When connecting to a legacy advertising device using BLE 5.0 interface, `is_aux` should be set to true.
* 6. Auto-setting of `is_aux` parameter (handled in L2CAP layer):
* - If only BLE 4.2 feature is enabled, `is_aux` will be automatically set to false.
* - If only BLE 5.0 feature is enabled, `is_aux` will be automatically set to true.
* - If both BLE 4.2 and BLE 5.0 features are enabled (not recommended):
* * The stack will automatically infer whether to use BLE 5.0 or BLE 4.2 interface
* based on previously used APIs.
* * Otherwise, the user-specified value will be used.
* - Note: It is strongly recommended NOT to enable both BLE 4.2 and BLE 5.0 features
* simultaneously in menuconfig.
*
* @param[in] gattc_if: GATT client access interface.
* @param[in] esp_gatt_create_conn: Pointer to the structure containing connection parameters.
@@ -1034,7 +1034,27 @@ BOOLEAN l2cble_init_direct_conn (tL2C_LCB *p_lcb)
}
}
if (!p_lcb->is_aux) {
// Auto-set is_aux based on BLE feature support
bool is_aux = p_lcb->is_aux;
#if (BLE_42_FEATURE_SUPPORT == TRUE) && (BLE_50_FEATURE_SUPPORT == FALSE)
if (is_aux) {
L2CAP_TRACE_WARNING("is_aux auto-set to false (BLE 4.2 only)");
is_aux = false;
}
#elif (BLE_42_FEATURE_SUPPORT == FALSE) && (BLE_50_FEATURE_SUPPORT == TRUE)
if (!is_aux) {
L2CAP_TRACE_WARNING("is_aux auto-set to true (BLE 5.0 only)");
is_aux = true;
}
#else
extern bool btm_ble_inter_get(void);
if (btm_ble_inter_get() && (!is_aux)) {
L2CAP_TRACE_WARNING("is_aux auto-set to true (BLE 5.0 API used)");
is_aux = true;
}
#endif
if (!is_aux) {
if (!btsnd_hcic_ble_create_ll_conn (scan_int, /* UINT16 scan_int */
scan_win, /* UINT16 scan_win */
FALSE, /* UINT8 white_list */