Skip to content

Commit

Permalink
Merge branch 'feature/support_ble_53_host_feat_v5.1' into 'release/v5.1'
Browse files Browse the repository at this point in the history
Support BLE host feature for PTS (backport v5.1)

See merge request espressif/esp-idf!25645
  • Loading branch information
jack0c committed Sep 4, 2023
2 parents f0437b9 + b386080 commit 1b87f35
Show file tree
Hide file tree
Showing 42 changed files with 1,130 additions and 102 deletions.
7 changes: 7 additions & 0 deletions components/bt/host/bluedroid/Kconfig.in
Expand Up @@ -1143,3 +1143,10 @@ config BT_BLE_42_FEATURES_SUPPORTED
default n
help
This enables BLE 4.2 features.

config BT_BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER
bool "Enable BLE periodic advertising sync transfer feature"
depends on (BT_BLUEDROID_ENABLED && BT_BLE_50_FEATURES_SUPPORTED && SOC_ESP_NIMBLE_CONTROLLER)
default n
help
This enables BLE periodic advertising sync transfer feature
92 changes: 92 additions & 0 deletions components/bt/host/bluedroid/api/esp_gap_ble_api.c
Expand Up @@ -1370,3 +1370,95 @@ esp_err_t esp_ble_gap_prefer_ext_connect_params_set(esp_bd_addr_t addr,
}

#endif //#if (BLE_50_FEATURE_SUPPORT == TRUE)

#if (BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER == TRUE)
esp_err_t esp_ble_gap_periodic_adv_recv_enable(uint16_t sync_handle, uint8_t enable)
{
btc_msg_t msg;
btc_ble_5_gap_args_t arg;

ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);

msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GAP_BLE;
msg.act = BTC_GAP_BLE_PERIODIC_ADV_RECV_ENABLE;

arg.periodic_adv_recv_en.sync_handle = sync_handle;
arg.periodic_adv_recv_en.enable = enable;

return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_5_gap_args_t), NULL, NULL)
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}

esp_err_t esp_ble_gap_periodic_adv_sync_trans(esp_bd_addr_t addr, uint16_t service_data, uint16_t sync_handle)
{
btc_msg_t msg;
btc_ble_5_gap_args_t arg;

ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);

if (addr == NULL) {
return ESP_ERR_INVALID_ARG;
}

msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GAP_BLE;
msg.act = BTC_GAP_BLE_PERIODIC_ADV_SYNC_TRANS;

memcpy(arg.periodic_adv_sync_trans.addr, addr, sizeof(esp_bd_addr_t));
arg.periodic_adv_sync_trans.service_data = service_data;
arg.periodic_adv_sync_trans.sync_handle = sync_handle;

return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_5_gap_args_t), NULL, NULL)
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}

esp_err_t esp_ble_gap_periodic_adv_set_info_trans(esp_bd_addr_t addr, uint16_t service_data, uint8_t adv_handle)
{
btc_msg_t msg;
btc_ble_5_gap_args_t arg;

ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);

if (addr == NULL) {
return ESP_ERR_INVALID_ARG;
}

msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GAP_BLE;
msg.act = BTC_GAP_BLE_PERIODIC_ADV_SET_INFO_TRANS;

memcpy(arg.periodic_adv_set_info_trans.addr, addr, sizeof(esp_bd_addr_t));
arg.periodic_adv_set_info_trans.service_data = service_data;
arg.periodic_adv_set_info_trans.adv_handle = adv_handle;

return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_5_gap_args_t), NULL, NULL)
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}

esp_err_t esp_ble_gap_set_periodic_adv_sync_trans_params(esp_bd_addr_t addr, const esp_ble_gap_past_params_t *params)
{
btc_msg_t msg;
btc_ble_5_gap_args_t arg;

ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);

if (params == NULL) {
return ESP_ERR_INVALID_ARG;
}

msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GAP_BLE;
msg.act = BTC_GAP_BLE_SET_PERIODIC_ADV_SYNC_TRANS_PARAMS;

if (addr) {
memcpy(arg.set_periodic_adv_sync_trans_params.addr, addr, sizeof(esp_bd_addr_t));
} else {
memset(arg.set_periodic_adv_sync_trans_params.addr, 0, sizeof(esp_bd_addr_t));
}
memcpy(&arg.set_periodic_adv_sync_trans_params.params, params, sizeof(esp_ble_gap_past_params_t));

return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_5_gap_args_t), NULL, NULL)
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
#endif //#if (BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER == TRUE)
35 changes: 35 additions & 0 deletions components/bt/host/bluedroid/api/esp_gattc_api.c
Expand Up @@ -447,6 +447,41 @@ esp_err_t esp_ble_gattc_read_multiple(esp_gatt_if_t gattc_if,
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}

esp_err_t esp_ble_gattc_read_multiple_variable(esp_gatt_if_t gattc_if,
uint16_t conn_id, esp_gattc_multi_t *read_multi,
esp_gatt_auth_req_t auth_req)
{
btc_msg_t msg = {0};
btc_ble_gattc_args_t arg;

ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);

tGATT_TCB *p_tcb = gatt_get_tcb_by_idx(conn_id);
if (!gatt_check_connection_state_by_tcb(p_tcb)) {
LOG_WARN("%s, The connection not created.", __func__);
return ESP_ERR_INVALID_STATE;
}

if (L2CA_CheckIsCongest(L2CAP_ATT_CID, p_tcb->peer_bda)) {
LOG_DEBUG("%s, the l2cap chanel is congest.", __func__);
return ESP_FAIL;
}

msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
msg.act = BTC_GATTC_ACT_READ_MULTIPLE_VARIABLE_CHAR;
arg.read_multiple.conn_id = BTC_GATT_CREATE_CONN_ID(gattc_if, conn_id);
arg.read_multiple.num_attr = read_multi->num_attr;
arg.read_multiple.auth_req = auth_req;

if (read_multi->num_attr > 0) {
memcpy(arg.read_multiple.handles, read_multi->handles, sizeof(uint16_t)*read_multi->num_attr);
} else {
LOG_ERROR("%s(), the num_attr should not be 0.", __func__);
return ESP_FAIL;
}
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}

esp_err_t esp_ble_gattc_read_char_descr (esp_gatt_if_t gattc_if,
uint16_t conn_id, uint16_t handle,
Expand Down
13 changes: 13 additions & 0 deletions components/bt/host/bluedroid/api/esp_gatts_api.c
Expand Up @@ -421,4 +421,17 @@ static esp_err_t esp_ble_gatts_add_char_desc_param_check(esp_attr_value_t *char_
return ESP_OK;
}

esp_err_t esp_ble_gatts_show_local_database(void)
{
btc_msg_t msg = {0};

ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);

msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTS;
msg.act = BTC_GATTS_ACT_SHOW_LOCAL_DATABASE;

return (btc_transfer_context(&msg, NULL, 0, NULL, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}

#endif ///GATTS_INCLUDED
124 changes: 124 additions & 0 deletions components/bt/host/bluedroid/api/include/api/esp_gap_ble_api.h
Expand Up @@ -202,6 +202,12 @@ typedef enum {
ESP_GAP_BLE_SC_OOB_REQ_EVT, /*!< Secure Connection OOB request event */
ESP_GAP_BLE_SC_CR_LOC_OOB_EVT, /*!< Secure Connection create OOB data complete event */
ESP_GAP_BLE_GET_DEV_NAME_COMPLETE_EVT, /*!< When getting BT device name complete, the event comes */
//BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER
ESP_GAP_BLE_PERIODIC_ADV_RECV_ENABLE_COMPLETE_EVT, /*!< when set periodic advertising receive enable complete, the event comes */
ESP_GAP_BLE_PERIODIC_ADV_SYNC_TRANS_COMPLETE_EVT, /*!< when periodic advertising sync transfer complete, the event comes */
ESP_GAP_BLE_PERIODIC_ADV_SET_INFO_TRANS_COMPLETE_EVT, /*!< when periodic advertising set info transfer complete, the event comes */
ESP_GAP_BLE_SET_PAST_PARAMS_COMPLETE_EVT, /*!< when set periodic advertising sync transfer params complete, the event comes */
ESP_GAP_BLE_PERIODIC_ADV_SYNC_TRANS_RECV_EVT, /*!< when periodic advertising sync transfer received, the event comes */
ESP_GAP_BLE_EVT_MAX, /*!< when maximum advertising event complete, the event comes */
} esp_gap_ble_cb_event_t;

Expand Down Expand Up @@ -910,6 +916,25 @@ typedef struct {

#endif //#if (BLE_50_FEATURE_SUPPORT == TRUE)

#if (BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER == TRUE)
/// Periodic advertising sync trans mode
#define ESP_BLE_GAP_PAST_MODE_NO_SYNC_EVT (0x00) /*!< No attempt is made to sync and no periodic adv sync transfer received event */
#define ESP_BLE_GAP_PAST_MODE_NO_REPORT_EVT (0x01) /*!< An periodic adv sync transfer received event and no periodic adv report events */
#define ESP_BLE_GAP_PAST_MODE_DUP_FILTER_DISABLED (0x02) /*!< Periodic adv report events will be enabled with duplicate filtering disabled */
#define ESP_BLE_GAP_PAST_MODE_DUP_FILTER_ENABLED (0x03) /*!< Periodic adv report events will be enabled with duplicate filtering enabled */
typedef uint8_t esp_ble_gap_past_mode_t;

/**
* @brief periodic adv sync transfer parameters
*/
typedef struct {
esp_ble_gap_past_mode_t mode; /*!< periodic advertising sync transfer mode */
uint16_t skip; /*!< the number of periodic advertising packets that can be skipped */
uint16_t sync_timeout; /*!< synchronization timeout for the periodic advertising train */
uint8_t cte_type; /*!< periodic advertising sync transfer CET type */
} esp_ble_gap_past_params_t;
#endif // #if (BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER == TRUE)

/**
* @brief Gap callback parameters union
*/
Expand Down Expand Up @@ -1308,6 +1333,50 @@ typedef union {
esp_ble_gap_periodic_adv_report_t params; /*!< periodic advertising report parameters */
} period_adv_report; /*!< Event parameter of ESP_GAP_BLE_PERIODIC_ADV_REPORT_EVT */
#endif // #if (BLE_50_FEATURE_SUPPORT == TRUE)
#if (BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER == TRUE)
/**
* @brief ESP_GAP_BLE_PERIODIC_ADV_RECV_ENABLE_COMPLETE_EVT
*/
struct ble_periodic_adv_recv_enable_cmpl_param {
esp_bt_status_t status; /*!< Set periodic advertising receive enable status */
} period_adv_recv_enable; /*!< Event parameter of ESP_GAP_BLE_PERIODIC_ADV_RECV_ENABLE_COMPLETE_EVT */
/**
* @brief ESP_GAP_BLE_PERIODIC_ADV_SYNC_TRANS_COMPLETE_EVT
*/
struct ble_periodic_adv_sync_trans_cmpl_param {
esp_bt_status_t status; /*!< Periodic advertising sync transfer status */
esp_bd_addr_t bda; /*!< The remote device address */
} period_adv_sync_trans; /*!< Event parameter of ESP_GAP_BLE_PERIODIC_ADV_SYNC_TRANS_COMPLETE_EVT */
/**
* @brief ESP_GAP_BLE_PERIODIC_ADV_SET_INFO_TRANS_COMPLETE_EVT
*/
struct ble_periodic_adv_set_info_trans_cmpl_param {
esp_bt_status_t status; /*!< Periodic advertising set info transfer status */
esp_bd_addr_t bda; /*!< The remote device address */
} period_adv_set_info_trans; /*!< Event parameter of ESP_GAP_BLE_PERIODIC_ADV_SET_INFO_TRANS_COMPLETE_EVT */
/**
* @brief ESP_GAP_BLE_SET_PAST_PARAMS_COMPLETE_EVT
*/
struct ble_set_past_params_cmpl_param {
esp_bt_status_t status; /*!< Set periodic advertising sync transfer params status */
esp_bd_addr_t bda; /*!< The remote device address */
} set_past_params; /*!< Event parameter of ESP_GAP_BLE_SET_PAST_PARAMS_COMPLETE_EVT */
/**
* @brief ESP_GAP_BLE_PERIODIC_ADV_SYNC_TRANS_RECV_EVT
*/
struct ble_periodic_adv_sync_trans_recv_param {
esp_bt_status_t status; /*!< Periodic advertising sync transfer received status */
esp_bd_addr_t bda; /*!< The remote device address */
uint16_t service_data; /*!< The value provided by the peer device */
uint16_t sync_handle; /*!< Periodic advertising sync handle */
uint8_t adv_sid; /*!< Periodic advertising set id */
uint8_t adv_addr_type; /*!< Periodic advertiser address type */
esp_bd_addr_t adv_addr; /*!< Periodic advertiser address */
esp_ble_gap_phy_t adv_phy; /*!< Periodic advertising PHY */
uint16_t adv_interval; /*!< Periodic advertising interval */
uint8_t adv_clk_accuracy; /*!< Periodic advertising clock accuracy */
} past_received; /*!< Event parameter of ESP_GAP_BLE_PERIODIC_ADV_SYNC_TRANS_RECV_EVT */
#endif // #if (BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER == TRUE)
} esp_ble_gap_cb_param_t;

/**
Expand Down Expand Up @@ -2197,6 +2266,61 @@ esp_err_t esp_ble_gap_prefer_ext_connect_params_set(esp_bd_addr_t addr,

#endif //#if (BLE_50_FEATURE_SUPPORT == TRUE)

#if (BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER == TRUE)
/**
* @brief This function is used to set periodic advertising receive enable
*
* @param[in] sync_handle : Handle of periodic advertising sync
* @param[in] enable : Determines whether reporting and duplicate filtering are enabled or disabled
*
* @return - ESP_OK : success
* - other : failed
*
*/
esp_err_t esp_ble_gap_periodic_adv_recv_enable(uint16_t sync_handle, uint8_t enable);

/**
* @brief This function is used to transfer periodic advertising sync
*
* @param[in] addr : Peer device address
* @param[in] service_data : Service data used by Host
* @param[in] sync_handle : Handle of periodic advertising sync
*
* @return - ESP_OK : success
* - other : failed
*
*/
esp_err_t esp_ble_gap_periodic_adv_sync_trans(esp_bd_addr_t addr,
uint16_t service_data, uint16_t sync_handle);

/**
* @brief This function is used to transfer periodic advertising set info
*
* @param[in] addr : Peer device address
* @param[in] service_data : Service data used by Host
* @param[in] adv_handle : Handle of advertising set
*
* @return - ESP_OK : success
* - other : failed
*
*/
esp_err_t esp_ble_gap_periodic_adv_set_info_trans(esp_bd_addr_t addr,
uint16_t service_data, uint8_t adv_handle);

/**
* @brief This function is used to set periodic advertising sync transfer params
*
* @param[in] addr : Peer device address
* @param[in] params : Params of periodic advertising sync transfer
*
* @return - ESP_OK : success
* - other : failed
*
*/
esp_err_t esp_ble_gap_set_periodic_adv_sync_trans_params(esp_bd_addr_t addr,
const esp_ble_gap_past_params_t *params);
#endif //#if (BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER == TRUE)

#ifdef __cplusplus
}
#endif
Expand Down
18 changes: 18 additions & 0 deletions components/bt/host/bluedroid/api/include/api/esp_gattc_api.h
Expand Up @@ -60,6 +60,7 @@ typedef enum {
ESP_GATTC_SET_ASSOC_EVT = 44, /*!< When the ble gattc set the associated address complete, the event comes */
ESP_GATTC_GET_ADDR_LIST_EVT = 45, /*!< When the ble get gattc address list in cache finish, the event comes */
ESP_GATTC_DIS_SRVC_CMPL_EVT = 46, /*!< When the ble discover service complete, the event comes */
ESP_GATTC_READ_MULTI_VAR_EVT = 47, /*!< When read multiple variable characteristic complete, the event comes */
} esp_gattc_cb_event_t;


Expand Down Expand Up @@ -651,6 +652,23 @@ esp_err_t esp_ble_gattc_read_multiple(esp_gatt_if_t gattc_if,
uint16_t conn_id, esp_gattc_multi_t *read_multi,
esp_gatt_auth_req_t auth_req);

/**
* @brief This function is called to read multiple variable length characteristic or
* characteristic descriptors.
*
* @param[in] gattc_if: Gatt client access interface.
* @param[in] conn_id : connection ID.
* @param[in] read_multi : pointer to the read multiple parameter.
* @param[in] auth_req : authenticate request type
*
* @return
* - ESP_OK: success
* - other: failed
*
*/
esp_err_t esp_ble_gattc_read_multiple_variable(esp_gatt_if_t gattc_if,
uint16_t conn_id, esp_gattc_multi_t *read_multi,
esp_gatt_auth_req_t auth_req);

/**
* @brief This function is called to read a characteristics descriptor.
Expand Down
10 changes: 10 additions & 0 deletions components/bt/host/bluedroid/api/include/api/esp_gatts_api.h
Expand Up @@ -572,6 +572,16 @@ esp_err_t esp_ble_gatts_close(esp_gatt_if_t gatts_if, uint16_t conn_id);
*/
esp_err_t esp_ble_gatts_send_service_change_indication(esp_gatt_if_t gatts_if, esp_bd_addr_t remote_bda);

/**
* @brief Print local database (GATT service table)
*
* @return
* - ESP_OK : success
* - other : failed
*
*/
esp_err_t esp_ble_gatts_show_local_database(void);

#ifdef __cplusplus
}
#endif
Expand Down

0 comments on commit 1b87f35

Please sign in to comment.