Skip to content

Commit

Permalink
Merge branch 'test/ctrl_acl_u_pkt_type_v5.2' into 'release/v5.2'
Browse files Browse the repository at this point in the history
feat(bt/bluedroid): Added an API to specify data types for ACL-U traffic (v5.2)

See merge request espressif/esp-idf!27128
  • Loading branch information
jack0c committed Nov 22, 2023
2 parents 8495745 + 15b27b1 commit c23973d
Show file tree
Hide file tree
Showing 13 changed files with 292 additions and 4 deletions.
19 changes: 19 additions & 0 deletions components/bt/host/bluedroid/api/esp_gap_bt_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -475,4 +475,23 @@ esp_err_t esp_bt_gap_get_page_timeout(void)

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

esp_err_t esp_bt_gap_set_acl_pkt_types(esp_bd_addr_t remote_bda, uint16_t pkt_types)
{
btc_msg_t msg;
btc_gap_bt_args_t arg;

if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}

msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GAP_BT;
msg.act = BTC_GAP_BT_ACT_SET_ACL_PKT_TYPES;

memcpy(&arg.set_acl_pkt_types.bda, remote_bda, sizeof(bt_bdaddr_t));
arg.set_acl_pkt_types.pkt_types = pkt_types;
return (btc_transfer_context(&msg, &arg, sizeof(btc_gap_bt_args_t), NULL, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}

#endif /* #if BTC_GAP_BT_INCLUDED == TRUE */
51 changes: 50 additions & 1 deletion components/bt/host/bluedroid/api/include/api/esp_gap_bt_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,35 @@ typedef struct {

typedef uint8_t esp_bt_eir_type_t;


/* ACL Packet Types */
#define ESP_BT_ACL_PKT_TYPES_MASK_DM1 0x0008
#define ESP_BT_ACL_PKT_TYPES_MASK_DH1 0x0010
#define ESP_BT_ACL_PKT_TYPES_MASK_DM3 0x0400
#define ESP_BT_ACL_PKT_TYPES_MASK_DH3 0x0800
#define ESP_BT_ACL_PKT_TYPES_MASK_DM5 0x4000
#define ESP_BT_ACL_PKT_TYPES_MASK_DH5 0x8000
#define ESP_BT_ACL_PKT_TYPES_MASK_NO_2_DH1 0x0002
#define ESP_BT_ACL_PKT_TYPES_MASK_NO_3_DH1 0x0004
#define ESP_BT_ACL_PKT_TYPES_MASK_NO_2_DH3 0x0100
#define ESP_BT_ACL_PKT_TYPES_MASK_NO_3_DH3 0x0200
#define ESP_BT_ACL_PKT_TYPES_MASK_NO_2_DH5 0x1000
#define ESP_BT_ACL_PKT_TYPES_MASK_NO_3_DH5 0x2000

// DM1 cann not be disabled. All options are mandatory to include DM1.
#define ESP_BT_ACL_DM1_ONLY (ESP_BT_ACL_PKT_TYPES_MASK_DM1 | 0x330e) /* 0x330e */
#define ESP_BT_ACL_DH1_ONLY (ESP_BT_ACL_PKT_TYPES_MASK_DH1 | 0x330e) /* 0x331e */
#define ESP_BT_ACL_DM3_ONLY (ESP_BT_ACL_PKT_TYPES_MASK_DM3 | 0x330e) /* 0x370e */
#define ESP_BT_ACL_DH3_ONLY (ESP_BT_ACL_PKT_TYPES_MASK_DH3 | 0x330e) /* 0x3b0e */
#define ESP_BT_ACL_DM5_ONLY (ESP_BT_ACL_PKT_TYPES_MASK_DM5 | 0x330e) /* 0x730e */
#define ESP_BT_ACL_DH5_ONLY (ESP_BT_ACL_PKT_TYPES_MASK_DH5 | 0x330e) /* 0xb30e */
#define ESP_BT_ACL_2_DH1_ONLY (~ESP_BT_ACL_PKT_TYPES_MASK_NO_2_DH1 & 0x330e) /* 0x330c */
#define ESP_BT_ACL_3_DH1_ONLY (~ESP_BT_ACL_PKT_TYPES_MASK_NO_3_DH1 & 0x330e) /* 0x330a */
#define ESP_BT_ACL_2_DH3_ONLY (~ESP_BT_ACL_PKT_TYPES_MASK_NO_2_DH3 & 0x330e) /* 0x320e */
#define ESP_BT_ACL_3_DH3_ONLY (~ESP_BT_ACL_PKT_TYPES_MASK_NO_3_DH3 & 0x330e) /* 0x310e */
#define ESP_BT_ACL_2_DH5_ONLY (~ESP_BT_ACL_PKT_TYPES_MASK_NO_2_DH5 & 0x330e) /* 0x230e */
#define ESP_BT_ACL_3_DH5_ONLY (~ESP_BT_ACL_PKT_TYPES_MASK_NO_3_DH5 & 0x330e) /* 0x130e */

typedef uint16_t esp_bt_acl_pkt_type_t;

/* ESP_BT_EIR_FLAG bit definition */
#define ESP_BT_EIR_FLAG_LIMIT_DISC (0x01 << 0)
Expand Down Expand Up @@ -220,6 +248,7 @@ typedef enum {
ESP_BT_GAP_ACL_DISCONN_CMPL_STAT_EVT, /*!< ACL disconnection complete status event */
ESP_BT_GAP_SET_PAGE_TO_EVT, /*!< Set page timeout event */
ESP_BT_GAP_GET_PAGE_TO_EVT, /*!< Get page timeout event */
ESP_BT_GAP_ACL_PKT_TYPE_CHANGED_EVT, /*!< Set ACL packet types event */
ESP_BT_GAP_EVT_MAX,
} esp_bt_gap_cb_event_t;

Expand Down Expand Up @@ -394,6 +423,15 @@ typedef union {
uint16_t page_to; /*!< page_timeout value to be set, unit is 0.625ms. */
} get_page_timeout; /*!< get page timeout parameter struct */

/**
* @brief ESP_BT_GAP_ACL_PKT_TYPE_CHANGED_EVT
*/
struct set_acl_pkt_types_param {
esp_bt_status_t status; /*!< set ACL packet types status */
esp_bd_addr_t bda; /*!< remote bluetooth device address */
uint16_t pkt_types; /*!< packet types successfully set */
} set_acl_pkt_types; /*!< set ACL packet types parameter struct */

/**
* @brief ESP_BT_GAP_ACL_CONN_CMPL_STAT_EVT
*/
Expand Down Expand Up @@ -834,6 +872,17 @@ esp_err_t esp_bt_gap_set_page_timeout(uint16_t page_to);
*/
esp_err_t esp_bt_gap_get_page_timeout(void);

/**
* @brief Set ACL packet types
* An ESP_BT_GAP_SET_ACL_PPKT_TYPES_EVT event will reported to
* the APP layer.
*
* @return - ESP_OK: success
* - ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled
* - other: failed
*/
esp_err_t esp_bt_gap_set_acl_pkt_types(esp_bd_addr_t remote_bda, esp_bt_acl_pkt_type_t pkt_types);

#ifdef __cplusplus
}
#endif
Expand Down
22 changes: 22 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 @@ -874,6 +874,28 @@ void bta_dm_get_page_timeout (tBTA_DM_MSG *p_data)
{
BTM_ReadPageTimeout(p_data->get_page_timeout.get_page_to_cb);
}

/*******************************************************************************
**
** Function bta_dm_set_acl_pkt_types
**
** Description Sets ACL packet types
**
**
** Returns void
**
*******************************************************************************/
void bta_dm_set_acl_pkt_types (tBTA_DM_MSG *p_data)
{
if (p_data->set_acl_pkt_types.set_acl_pkt_types_cb != NULL) {
BTM_SetAclPktTypes(p_data->set_acl_pkt_types.rmt_addr,
p_data->set_acl_pkt_types.pkt_types,
p_data->set_acl_pkt_types.set_acl_pkt_types_cb);
} else {
APPL_TRACE_ERROR("%s(), the callback function can't be NULL.", __func__);
}
}

#endif
/*******************************************************************************
**
Expand Down
24 changes: 24 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 @@ -341,6 +341,30 @@ void BTA_DmGetPageTimeout(tBTM_CMPL_CB *p_cb)
bta_sys_sendmsg(p_msg);
}
}

/*******************************************************************************
**
** Function BTA_DmSetAclPktTypes
**
** Description This function sets the packet types used for ACL traffic.
**
**
** Returns void
**
*******************************************************************************/
void BTA_DmSetAclPktTypes(BD_ADDR remote_addr, UINT16 pkt_types, tBTM_CMPL_CB *p_cb)
{
tBTA_DM_API_SET_ACL_PKT_TYPES *p_msg;

if ((p_msg = (tBTA_DM_API_SET_ACL_PKT_TYPES *) osi_malloc(sizeof(tBTA_DM_API_SET_ACL_PKT_TYPES))) != NULL) {
p_msg->hdr.event = BTA_DM_API_SET_ACL_PKT_TYPES_EVT;
bdcpy(p_msg->rmt_addr, remote_addr);
p_msg->pkt_types = pkt_types;
p_msg->set_acl_pkt_types_cb = p_cb;

bta_sys_sendmsg(p_msg);
}
}
#endif /// CLASSIC_BT_INCLUDED == TRUE

#if (SDP_INCLUDED == TRUE)
Expand Down
1 change: 1 addition & 0 deletions components/bt/host/bluedroid/bta/dm/bta_dm_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const tBTA_DM_ACTION bta_dm_action[BTA_DM_MAX_EVT] = {
bta_dm_config_eir, /* BTA_DM_API_CONFIG_EIR_EVT */
bta_dm_set_page_timeout, /* BTA_DM_API_PAGE_TO_SET_EVT */
bta_dm_get_page_timeout, /* BTA_DM_API_PAGE_TO_GET_EVT */
bta_dm_set_acl_pkt_types, /* BTA_DM_API_SET_ACL_PKT_TYPES_EVT */
#endif
bta_dm_set_afh_channels, /* BTA_DM_API_SET_AFH_CHANNELS_EVT */
#if (SDP_INCLUDED == TRUE)
Expand Down
11 changes: 11 additions & 0 deletions components/bt/host/bluedroid/bta/dm/include/bta_dm_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ enum {
BTA_DM_API_CONFIG_EIR_EVT,
BTA_DM_API_PAGE_TO_SET_EVT,
BTA_DM_API_PAGE_TO_GET_EVT,
BTA_DM_API_SET_ACL_PKT_TYPES_EVT,
#endif
BTA_DM_API_SET_AFH_CHANNELS_EVT,
#if (SDP_INCLUDED == TRUE)
Expand Down Expand Up @@ -299,6 +300,14 @@ typedef struct {
tBTM_CMPL_CB *get_page_to_cb;
} tBTA_DM_API_PAGE_TO_GET;

/* data type for BTA_DM_API_SET_ACL_PKT_TYPES_EVT */
typedef struct {
BT_HDR hdr;
BD_ADDR rmt_addr;
UINT16 pkt_types;
tBTM_CMPL_CB *set_acl_pkt_types_cb;
} tBTA_DM_API_SET_ACL_PKT_TYPES;

/* data type for BTA_DM_API_GET_REMOTE_NAME_EVT */
typedef struct {
BT_HDR hdr;
Expand Down Expand Up @@ -1158,6 +1167,7 @@ typedef union {
tBTA_DM_API_SET_AFH_CHANNELS set_afh_channels;
tBTA_DM_API_PAGE_TO_SET set_page_timeout;
tBTA_DM_API_PAGE_TO_GET get_page_timeout;
tBTA_DM_API_SET_ACL_PKT_TYPES set_acl_pkt_types;
#if (SDP_INCLUDED == TRUE)
tBTA_DM_API_GET_REMOTE_NAME get_rmt_name;
#endif
Expand Down Expand Up @@ -1670,6 +1680,7 @@ extern void bta_dm_cfg_coex_status(tBTA_DM_MSG *p_data);
extern void bta_dm_config_eir (tBTA_DM_MSG *p_data);
extern void bta_dm_set_page_timeout (tBTA_DM_MSG *p_data);
extern void bta_dm_get_page_timeout (tBTA_DM_MSG *p_data);
extern void bta_dm_set_acl_pkt_types (tBTA_DM_MSG *p_data);
#endif
extern void bta_dm_set_afh_channels (tBTA_DM_MSG *p_data);
extern void bta_dm_read_rmt_name(tBTA_DM_MSG *p_data);
Expand Down
14 changes: 14 additions & 0 deletions components/bt/host/bluedroid/bta/include/bta/bta_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,8 @@ typedef tBTM_BLE_SET_CHANNELS_RESULTS tBTA_BLE_SET_CHANNELS_RESULTS;
typedef tBTM_SET_PAGE_TIMEOUT_RESULTS tBTA_SET_PAGE_TIMEOUT_RESULTS;
typedef tBTM_GET_PAGE_TIMEOUT_RESULTS tBTA_GET_PAGE_TIMEOUT_RESULTS;

typedef tBTM_SET_ACL_PKT_TYPES_RESULTS tBTA_SET_ACL_PKT_TYPES_RESULTS;

typedef tBTM_REMOTE_DEV_NAME tBTA_REMOTE_DEV_NAME;

/* advertising channel map */
Expand Down Expand Up @@ -1804,6 +1806,18 @@ void BTA_DmSetPageTimeout(UINT16 page_to, tBTM_CMPL_CB *p_cb);
*******************************************************************************/
void BTA_DmGetPageTimeout(tBTM_CMPL_CB *p_cb);

/*******************************************************************************
**
** Function BTA_DmSetAclPktTypes
**
** Description This function sets the packet types used for ACL traffic.
**
**
** Returns void
**
*******************************************************************************/
void BTA_DmSetAclPktTypes(BD_ADDR remote_addr, UINT16 pkt_types, tBTM_CMPL_CB *p_cb);

#if (BLE_INCLUDED == TRUE)
/*******************************************************************************
**
Expand Down
38 changes: 38 additions & 0 deletions components/bt/host/bluedroid/btc/profile/std/gap/btc_gap_bt.c
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,33 @@ static void btc_gap_get_page_timeout(void)
BTA_DmGetPageTimeout(btc_gap_bt_get_page_timeout_cmpl_callback);
}

static void btc_gap_bt_set_acl_pkt_types_cmpl_callback(void *p_data)
{
tBTA_SET_ACL_PKT_TYPES_RESULTS *result = (tBTA_SET_ACL_PKT_TYPES_RESULTS *)p_data;
esp_bt_gap_cb_param_t param;
bt_status_t ret;
btc_msg_t msg;
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_GAP_BT;
msg.act = BTC_GAP_BT_SET_ACL_PKT_TYPES_EVT;

param.set_acl_pkt_types.status = btc_btm_status_to_esp_status(result->status);
memcpy(param.set_acl_pkt_types.bda, result->rem_bda, sizeof(esp_bd_addr_t));
param.set_acl_pkt_types.pkt_types = result->pkt_types;

ret = btc_transfer_context(&msg, &param, sizeof(esp_bt_gap_cb_param_t), NULL, NULL);
if (ret != BT_STATUS_SUCCESS) {
BTC_TRACE_ERROR("%s btc_transfer_context failed\n", __func__);
}
}

static void btc_gap_set_acl_pkt_types(btc_gap_bt_args_t *arg)
{
BTA_DmSetAclPktTypes(arg->set_acl_pkt_types.bda.address,
arg->set_acl_pkt_types.pkt_types,
btc_gap_bt_set_acl_pkt_types_cmpl_callback);
}

static void btc_gap_bt_read_remote_name_cmpl_callback(void *p_data)
{
tBTA_REMOTE_DEV_NAME *result = (tBTA_REMOTE_DEV_NAME *)p_data;
Expand Down Expand Up @@ -844,6 +871,7 @@ void btc_gap_bt_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
case BTC_GAP_BT_ACT_SET_QOS:
case BTC_GAP_BT_ACT_SET_PAGE_TIMEOUT:
case BTC_GAP_BT_ACT_GET_PAGE_TIMEOUT:
case BTC_GAP_BT_ACT_SET_ACL_PKT_TYPES:
break;
case BTC_GAP_BT_ACT_PASSKEY_REPLY:
case BTC_GAP_BT_ACT_CONFIRM_REPLY:
Expand Down Expand Up @@ -910,6 +938,7 @@ void btc_gap_bt_arg_deep_free(btc_msg_t *msg)
case BTC_GAP_BT_ACT_SET_QOS:
case BTC_GAP_BT_ACT_SET_PAGE_TIMEOUT:
case BTC_GAP_BT_ACT_GET_PAGE_TIMEOUT:
case BTC_GAP_BT_ACT_SET_ACL_PKT_TYPES:
break;
case BTC_GAP_BT_ACT_PASSKEY_REPLY:
case BTC_GAP_BT_ACT_CONFIRM_REPLY:
Expand Down Expand Up @@ -1016,6 +1045,10 @@ void btc_gap_bt_call_handler(btc_msg_t *msg)
btc_gap_get_page_timeout();
break;
}
case BTC_GAP_BT_ACT_SET_ACL_PKT_TYPES: {
btc_gap_set_acl_pkt_types(arg);
break;
}
default:
break;
}
Expand Down Expand Up @@ -1060,6 +1093,7 @@ void btc_gap_bt_cb_deep_free(btc_msg_t *msg)
case BTC_GAP_BT_QOS_EVT:
case BTC_GAP_BT_SET_PAGE_TO_EVT:
case BTC_GAP_BT_GET_PAGE_TO_EVT:
case BTC_GAP_BT_SET_ACL_PKT_TYPES_EVT:
case BTC_GAP_BT_CFM_REQ_EVT:
case BTC_GAP_BT_KEY_NOTIF_EVT:
case BTC_GAP_BT_KEY_REQ_EVT:
Expand Down Expand Up @@ -1149,6 +1183,10 @@ void btc_gap_bt_cb_handler(btc_msg_t *msg)
btc_gap_bt_cb_to_app(ESP_BT_GAP_GET_PAGE_TO_EVT, (esp_bt_gap_cb_param_t *)msg->arg);
break;
}
case BTC_GAP_BT_SET_ACL_PKT_TYPES_EVT: {
btc_gap_bt_cb_to_app(ESP_BT_GAP_ACL_PKT_TYPE_CHANGED_EVT, (esp_bt_gap_cb_param_t *)msg->arg);
break;
}
default:
BTC_TRACE_ERROR("%s: Unhandled event (%d)!\n", __FUNCTION__, msg->act);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ typedef enum {
BTC_GAP_BT_QOS_EVT,
BTC_GAP_BT_SET_PAGE_TO_EVT,
BTC_GAP_BT_GET_PAGE_TO_EVT,
BTC_GAP_BT_SET_ACL_PKT_TYPES_EVT,
}btc_gap_bt_evt_t;

typedef enum {
Expand All @@ -55,6 +56,7 @@ typedef enum {
BTC_GAP_BT_ACT_SET_QOS,
BTC_GAP_BT_ACT_SET_PAGE_TIMEOUT,
BTC_GAP_BT_ACT_GET_PAGE_TIMEOUT,
BTC_GAP_BT_ACT_SET_ACL_PKT_TYPES,
} btc_gap_bt_act_t;

/* btc_bt_gap_args_t */
Expand Down Expand Up @@ -156,6 +158,12 @@ typedef union {
uint16_t page_to;
} set_page_to;

// BTC_GAP_BT_ACT_SET_ACL_PKT_TYPES
struct set_acl_pkt_types_args {
bt_bdaddr_t bda;
uint16_t pkt_types;
} set_acl_pkt_types;

} btc_gap_bt_args_t;

void btc_gap_bt_call_handler(btc_msg_t *msg);
Expand Down
Loading

0 comments on commit c23973d

Please sign in to comment.