Skip to content

Commit

Permalink
Merge branch 'feature/Add_apis_for_dtm_test' into 'master'
Browse files Browse the repository at this point in the history
Feature/add apis for direct test mode

See merge request espressif/esp-idf!25735
  • Loading branch information
Weijian-Espressif committed Sep 27, 2023
2 parents 66e720c + de148c3 commit 60961e9
Show file tree
Hide file tree
Showing 12 changed files with 580 additions and 3 deletions.
97 changes: 97 additions & 0 deletions components/bt/host/bluedroid/api/esp_gap_ble_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,103 @@ esp_err_t esp_gap_ble_set_authorization(esp_bd_addr_t bd_addr, bool authorize)
return ESP_FAIL;
}

#if (BLE_42_FEATURE_SUPPORT == TRUE)
esp_err_t esp_ble_dtm_tx_start(const esp_ble_dtm_tx_t *tx_params)
{
btc_msg_t msg = {0};
btc_ble_gap_args_t arg;

if (!tx_params) {
return ESP_ERR_INVALID_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_DTM_TX_START;

memcpy(&arg.dtm_tx_start, tx_params, sizeof(esp_ble_dtm_tx_t));

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

esp_err_t esp_ble_dtm_rx_start(const esp_ble_dtm_rx_t *rx_params)
{
btc_msg_t msg = {0};
btc_ble_gap_args_t arg;

if (!rx_params) {
return ESP_ERR_INVALID_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_DTM_RX_START;

memcpy(&arg.dtm_rx_start, rx_params, sizeof(esp_ble_dtm_rx_t));

return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
#endif // #if (BLE_42_FEATURE_SUPPORT == TRUE)

#if (BLE_50_FEATURE_SUPPORT == TRUE)
esp_err_t esp_ble_dtm_enh_tx_start(const esp_ble_dtm_enh_tx_t *tx_params)
{
btc_msg_t msg = {0};
btc_ble_gap_args_t arg;

if (!tx_params) {
return ESP_ERR_INVALID_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_DTM_ENH_TX_START;

memcpy(&arg.dtm_tx_start, tx_params, sizeof(esp_ble_dtm_enh_tx_t));

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

esp_err_t esp_ble_dtm_enh_rx_start(const esp_ble_dtm_enh_rx_t *rx_params)
{
btc_msg_t msg = {0};
btc_ble_gap_args_t arg;

if (!rx_params) {
return ESP_ERR_INVALID_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_DTM_ENH_RX_START;

memcpy(&arg.dtm_rx_start, rx_params, sizeof(esp_ble_dtm_enh_rx_t));

return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
#endif // #if (BLE_50_FEATURE_SUPPORT == TRUE)

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

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_DTM_STOP;

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

#if (BLE_50_FEATURE_SUPPORT == TRUE)

esp_err_t esp_ble_gap_read_phy(esp_bd_addr_t bd_addr)
Expand Down
133 changes: 133 additions & 0 deletions components/bt/host/bluedroid/api/include/api/esp_gap_ble_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ typedef enum {
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 */
// DTM
ESP_GAP_BLE_DTM_TEST_UPDATE_EVT, /*!< when direct test mode state changes, 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 @@ -339,7 +341,45 @@ typedef enum {
ESP_BLE_SM_MAX_PARAM,
} esp_ble_sm_param_t;

typedef enum {
/// DTM TX start event
DTM_TX_START_EVT = 0x00,
///DTM RX start event
DTM_RX_START_EVT,
///DTM test end event
DTM_TEST_STOP_EVT,
} esp_ble_dtm_update_evt_t;

typedef enum {
BLE_DTM_PKT_PAYLOAD_0x00, /*!< PRBS9 sequence ‘11111111100000111101...’ (in transmission order) as described in [Vol 6] Part F, Section 4.1.5 */
BLE_DTM_PKT_PAYLOAD_0x01, /*!< Repeated ‘11110000’ (in transmission order) sequence as described in [Vol 6] Part F, Section 4.1.5 */
BLE_DTM_PKT_PAYLOAD_0x02, /*!< Repeated ‘10101010’ (in transmission order) sequence as described in [Vol 6] Part F, Section 4.1.5 */
BLE_DTM_PKT_PAYLOAD_0x03, /*!< PRBS15 sequence as described in [Vol 6] Part F, Section 4.1.5 */
BLE_DTM_PKT_PAYLOAD_0x04, /*!< Repeated ‘11111111’ (in transmission order) sequence */
BLE_DTM_PKT_PAYLOAD_0x05, /*!< Repeated ‘00000000’ (in transmission order) sequence */
BLE_DTM_PKT_PAYLOAD_0x06, /*!< Repeated ‘00001111’ (in transmission order) sequence */
BLE_DTM_PKT_PAYLOAD_0x07, /*!< Repeated ‘01010101’ (in transmission order) sequence */
BLE_DTM_PKT_PAYLOAD_MAX, /*!< 0x08 ~ 0xFF, Reserved for future use */
} esp_ble_dtm_pkt_payload_t;

#if (BLE_42_FEATURE_SUPPORT == TRUE)
/**
* @brief DTM TX parameters
*/
typedef struct
{
uint8_t tx_channel; /*!< channel for sending test data, tx_channel = (Frequency -2402)/2, tx_channel range:0x00-0x27, Frequency range: 2402 MHz to 2480 MHz */
uint8_t len_of_data; /*!< length in bytes of payload data in each packet */
esp_ble_dtm_pkt_payload_t pkt_payload; /*!< packet payload type. value range: 0x00-0x07 */
} esp_ble_dtm_tx_t;
/**
* @brief DTM RX parameters
*/
typedef struct
{
uint8_t rx_channel; /*!< channel for test data reception, rx_channel = (Frequency -2402)/2, tx_channel range:0x00-0x27, Frequency range: 2402 MHz to 2480 MHz */
} esp_ble_dtm_rx_t;

/// Advertising parameters
typedef struct {
uint16_t adv_int_min; /*!< Minimum advertising interval for
Expand Down Expand Up @@ -918,6 +958,27 @@ typedef struct {
uint8_t adv_clk_accuracy; /*!< periodic advertising clock accuracy */
} esp_ble_gap_periodic_adv_sync_estab_t;

/**
* @brief DTM TX parameters
*/
typedef struct
{
uint8_t tx_channel; /*!< channel for sending test data, tx_channel = (Frequency -2402)/2, tx_channel range:0x00-0x27, Frequency range: 2402 MHz to 2480 MHz */
uint8_t len_of_data; /*!< length in bytes of payload data in each packet */
esp_ble_dtm_pkt_payload_t pkt_payload; /*!< packet payload type. value range: 0x00-0x07 */
esp_ble_gap_phy_t phy; /*!< the phy type used by the transmitter, coded phy with S=2:0x04 */
} esp_ble_dtm_enh_tx_t;

/**
* @brief DTM RX parameters
*/
typedef struct
{
uint8_t rx_channel; /*!< channel for test data reception, rx_channel = (Frequency -2402)/2, tx_channel range:0x00-0x27, Frequency range: 2402 MHz to 2480 MHz */
esp_ble_gap_phy_t phy; /*!< the phy type used by the receiver, 1M phy: 0x01, 2M phy:0x02, coded phy:0x03 */
uint8_t modulation_idx; /*!< modulation index, 0x00:standard modulation index, 0x01:stable modulation index */
} esp_ble_dtm_enh_rx_t;

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

#if (BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER == TRUE)
Expand Down Expand Up @@ -1381,6 +1442,14 @@ typedef union {
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)
/**
* @brief ESP_GAP_BLE_DTM_TEST_UPDATE_EVT
*/
struct ble_dtm_state_update_evt_param {
esp_bt_status_t status; /*!< Indicate DTM operation success status */
esp_ble_dtm_update_evt_t update_evt; /*!< DTM state change event, 0x00: DTM TX start, 0x01: DTM RX start, 0x02:DTM end */
uint16_t num_of_pkt; /*!< number of packets received, only valid if update_evt is DTM_TEST_STOP_EVT and shall be reported as 0 for a transmitter */
} dtm_state_update; /*!< Event parameter of ESP_GAP_BLE_DTM_TEST_UPDATE_EVT */
} esp_ble_gap_cb_param_t;

/**
Expand Down Expand Up @@ -2366,6 +2435,70 @@ 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)

#if (BLE_42_FEATURE_SUPPORT == TRUE)

/**
* @brief This function is used to start a test where the DUT generates reference packets
* at a fixed interval.
*
* @param[in] tx_params : DTM Transmitter parameters
*
* @return - ESP_OK : success
* - other : failed
*
*/
esp_err_t esp_ble_dtm_tx_start(const esp_ble_dtm_tx_t *tx_params);

/**
* @brief This function is used to start a test where the DUT receives test reference packets
* at a fixed interval.
*
* @param[in] rx_params : DTM Receiver parameters
*
* @return - ESP_OK : success
* - other : failed
*
*/
esp_err_t esp_ble_dtm_rx_start(const esp_ble_dtm_rx_t *rx_params);
#endif //#if (BLE_42_FEATURE_SUPPORT == TRUE)

#if (BLE_50_FEATURE_SUPPORT == TRUE)

/**
* @brief This function is used to start a test where the DUT generates reference packets
* at a fixed interval.
*
* @param[in] tx_params : DTM Transmitter parameters
*
* @return - ESP_OK : success
* - other : failed
*
*/
esp_err_t esp_ble_dtm_enh_tx_start(const esp_ble_dtm_enh_tx_t *tx_params);

/**
* @brief This function is used to start a test where the DUT receives test reference packets
* at a fixed interval.
*
* @param[in] rx_params : DTM Receiver parameters
*
* @return - ESP_OK : success
* - other : failed
*
*/
esp_err_t esp_ble_dtm_enh_rx_start(const esp_ble_dtm_enh_rx_t *rx_params);
#endif // #if (BLE_50_FEATURE_SUPPORT == TRUE)

/**
* @brief This function is used to stop any test which is in progress
*
*
* @return - ESP_OK : success
* - other : failed
*
*/
esp_err_t esp_ble_dtm_stop(void);

#ifdef __cplusplus
}
#endif
Expand Down
28 changes: 28 additions & 0 deletions components/bt/host/bluedroid/bta/dm/bta_dm_act.c
Original file line number Diff line number Diff line change
Expand Up @@ -5686,7 +5686,35 @@ void btm_dm_ble_multi_adv_disable(tBTA_DM_MSG *p_data)
p_data->ble_multi_adv_disable.inst_id, p_ref, BTA_FAILURE);
}
}

void bta_dm_ble_gap_dtm_tx_start(tBTA_DM_MSG *p_data)
{
BTM_BleTransmitterTest(p_data->dtm_tx_start.tx_channel, p_data->dtm_tx_start.len_of_data, p_data->dtm_tx_start.pkt_payload, p_data->dtm_tx_start.p_dtm_cmpl_cback);
}

void bta_dm_ble_gap_dtm_rx_start(tBTA_DM_MSG *p_data)
{
BTM_BleReceiverTest(p_data->dtm_rx_start.rx_channel, p_data->dtm_rx_start.p_dtm_cmpl_cback);
}

void bta_dm_ble_gap_dtm_stop(tBTA_DM_MSG *p_data)
{
BTM_BleTestEnd(p_data->dtm_stop.p_dtm_cmpl_cback);
}

#if (BLE_50_FEATURE_SUPPORT == TRUE)
void bta_dm_ble_gap_dtm_enhance_tx_start(tBTA_DM_MSG *p_data)
{
BTM_BleEnhancedTransmitterTest(p_data->dtm_enh_tx_start.tx_channel, p_data->dtm_enh_tx_start.len_of_data,
p_data->dtm_enh_tx_start.pkt_payload, p_data->dtm_enh_tx_start.phy, p_data->dtm_enh_tx_start.p_dtm_cmpl_cback);
}

void bta_dm_ble_gap_dtm_enhance_rx_start(tBTA_DM_MSG *p_data)
{
BTM_BleEnhancedReceiverTest(p_data->dtm_enh_rx_start.rx_channel, p_data->dtm_enh_rx_start.phy,
p_data->dtm_enh_rx_start.modulation_index, p_data->dtm_enh_rx_start.p_dtm_cmpl_cback);
}

void bta_dm_ble_gap_read_phy(tBTA_DM_MSG *p_data)
{
//tBTM_STATUS btm_status = 0;
Expand Down
76 changes: 76 additions & 0 deletions components/bt/host/bluedroid/bta/dm/bta_dm_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -2547,6 +2547,49 @@ void BTA_DmBleSetDataLength(BD_ADDR remote_device, UINT16 tx_data_length, tBTA_S
}
}

void BTA_DmBleDtmTxStart(uint8_t tx_channel, uint8_t len_of_data, uint8_t pkt_payload, tBTA_DTM_CMD_CMPL_CBACK *p_dtm_cmpl_cback)
{
tBTA_DM_API_BLE_DTM_TX_START *p_msg;

if ((p_msg = (tBTA_DM_API_BLE_DTM_TX_START *)osi_malloc(sizeof(tBTA_DM_API_BLE_DTM_TX_START)))
!= NULL) {
p_msg->hdr.event = BTA_DM_API_DTM_TX_START_EVT;
p_msg->tx_channel = tx_channel;
p_msg->len_of_data = len_of_data;
p_msg->pkt_payload = pkt_payload;
p_msg->p_dtm_cmpl_cback = p_dtm_cmpl_cback;

bta_sys_sendmsg(p_msg);
}
}

void BTA_DmBleDtmRxStart(uint8_t rx_channel, tBTA_DTM_CMD_CMPL_CBACK *p_dtm_cmpl_cback)
{
tBTA_DM_API_BLE_DTM_RX_START *p_msg;

if ((p_msg = (tBTA_DM_API_BLE_DTM_RX_START *)osi_malloc(sizeof(tBTA_DM_API_BLE_DTM_RX_START)))
!= NULL) {
p_msg->hdr.event = BTA_DM_API_DTM_RX_START_EVT;
p_msg->rx_channel= rx_channel;
p_msg->p_dtm_cmpl_cback = p_dtm_cmpl_cback;

bta_sys_sendmsg(p_msg);
}
}

void BTA_DmBleDtmStop(tBTA_DTM_CMD_CMPL_CBACK *p_dtm_cmpl_cback)
{
tBTA_DM_API_BLE_DTM_STOP *p_msg;

if ((p_msg = (tBTA_DM_API_BLE_DTM_STOP *)osi_malloc(sizeof(tBTA_DM_API_BLE_DTM_STOP)))
!= NULL) {
p_msg->hdr.event = BTA_DM_API_DTM_STOP_EVT;
p_msg->p_dtm_cmpl_cback = p_dtm_cmpl_cback;

bta_sys_sendmsg(p_msg);
}
}

#endif

/*******************************************************************************
Expand Down Expand Up @@ -3228,6 +3271,39 @@ void BTA_DmBleGapExtConnect(tBLE_ADDR_TYPE own_addr_type, const BD_ADDR peer_add

}

void BTA_DmBleDtmEnhTxStart(uint8_t tx_channel, uint8_t len_of_data, uint8_t pkt_payload, uint8_t phy, tBTA_DTM_CMD_CMPL_CBACK *p_dtm_cmpl_cback)
{
tBTA_DM_API_BLE_DTM_ENH_TX_START *p_msg;

if ((p_msg = (tBTA_DM_API_BLE_DTM_ENH_TX_START *)osi_malloc(sizeof(tBTA_DM_API_BLE_DTM_ENH_TX_START)))
!= NULL) {
p_msg->hdr.event = BTA_DM_API_DTM_ENH_TX_START_EVT;
p_msg->tx_channel = tx_channel;
p_msg->len_of_data = len_of_data;
p_msg->pkt_payload = pkt_payload;
p_msg->phy = phy;
p_msg->p_dtm_cmpl_cback = p_dtm_cmpl_cback;

bta_sys_sendmsg(p_msg);
}
}

void BTA_DmBleDtmEnhRxStart(uint8_t rx_channel, uint8_t phy, uint8_t modulation_index, tBTA_DTM_CMD_CMPL_CBACK *p_dtm_cmpl_cback)
{
tBTA_DM_API_BLE_DTM_ENH_RX_START *p_msg;

if ((p_msg = (tBTA_DM_API_BLE_DTM_ENH_RX_START *)osi_malloc(sizeof(tBTA_DM_API_BLE_DTM_ENH_RX_START)))
!= NULL) {
p_msg->hdr.event = BTA_DM_API_DTM_ENH_RX_START_EVT;
p_msg->rx_channel= rx_channel;
p_msg->phy = phy;
p_msg->modulation_index = modulation_index;
p_msg->p_dtm_cmpl_cback = p_dtm_cmpl_cback;

bta_sys_sendmsg(p_msg);
}
}

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

#if (BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER == TRUE)
Expand Down
Loading

0 comments on commit 60961e9

Please sign in to comment.