Skip to content

Commit

Permalink
Merge branch 'test/bqb_test_bt_classic_l2cap' into 'master'
Browse files Browse the repository at this point in the history
feat(bt/bluedroid): Add flags for BQB auto test of L2CAP

Closes BT-3357

See merge request espressif/esp-idf!25621
  • Loading branch information
wmy-espressif committed Sep 25, 2023
2 parents d637880 + afc7cf4 commit 3b7a37f
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 10 deletions.
27 changes: 27 additions & 0 deletions components/bt/host/bluedroid/stack/l2cap/l2c_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -2137,6 +2137,33 @@ UINT8 L2CA_DataWrite (UINT16 cid, BT_HDR *p_data)
}
#endif ///CLASSIC_BT_INCLUDED == TRUE

/*******************************************************************************
**
** Function l2cap_bqb_write_data
**
** Description Call L2CA_DataWrite and write I-Frame data for BQB test.
**
** Returns None
**
*******************************************************************************/
#if (BT_CLASSIC_BQB_INCLUDED == TRUE)
void l2cap_bqb_write_data(UINT16 cid)
{
BT_HDR *p_buf;
uint8_t *p;

if ((p_buf = (BT_HDR *)osi_malloc(SDP_DATA_BUF_SIZE)) != NULL) {
p_buf->len = 30;
p_buf->offset = L2CAP_MIN_OFFSET;
p = (UINT8 *)(p_buf + 1) + p_buf->offset;
for(int i = 0 ; i < 10; i++) {
UINT8_TO_BE_STREAM(p, 0)
}
L2CA_DataWrite(cid, p_buf);
}
}
#endif /* BT_CLASSIC_BQB_INCLUDED */

/*******************************************************************************
**
** Function L2CA_SetChnlFlushability
Expand Down
28 changes: 28 additions & 0 deletions components/bt/host/bluedroid/stack/l2cap/l2c_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ tL2C_CB l2cb;
tL2C_CB *l2c_cb_ptr;
#endif

#if BT_CLASSIC_BQB_INCLUDED
static BOOLEAN s_l2cap_bqb_bad_cmd_len_rej_flag = FALSE;
#endif /* BT_CLASSIC_BQB_INCLUDED */

#if 0 //Unused
/*******************************************************************************
**
Expand Down Expand Up @@ -107,6 +111,24 @@ void l2c_bcst_msg( BT_HDR *p_buf, UINT16 psm )
}
#endif

/*******************************************************************************
**
** Function l2cap_bqb_bad_cmd_len_rej_ctrl
**
** Description Control rejecting L2CAP signaling PDUs with incorrect length
** for BQB test.
**
** Returns void
**
*******************************************************************************/
#if BT_CLASSIC_BQB_INCLUDED
void l2cap_bqb_bad_cmd_len_rej_ctrl(BOOLEAN enable)
{
s_l2cap_bqb_bad_cmd_len_rej_flag = enable;
}
#endif /* BT_CLASSIC_BQB_INCLUDED */


/*******************************************************************************
**
** Function l2c_rcv_acl_data
Expand Down Expand Up @@ -461,6 +483,12 @@ static void process_l2cap_cmd (tL2C_LCB *p_lcb, UINT8 *p, UINT16 pkt_len)
p_ccb->remote_cid = rcid;

l2c_csm_execute(p_ccb, L2CEVT_L2CAP_CONNECT_REQ, &con_info);
#if BT_CLASSIC_BQB_INCLUDED
// L2CAP/COS/CED/BI-02-C
if (s_l2cap_bqb_bad_cmd_len_rej_flag) {
l2cu_send_peer_cmd_reject (p_lcb, L2CAP_CMD_REJ_NOT_UNDERSTOOD, id, 0, 0);
}
#endif /* BT_CLASSIC_BQB_INCLUDED */
break;

case L2CAP_CMD_CONN_RSP:
Expand Down
17 changes: 15 additions & 2 deletions components/bt/host/bluedroid/stack/l2cap/l2c_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
#include "osi/allocator.h"
#include "osi/list.h"

#if BT_SDP_BQB_INCLUDED
extern BOOLEAN l2cap_bqb_ertm_mode_included_flag;
#endif /* BT_SDP_BQB_INCLUDED */

/*******************************************************************************
**
** Function l2cu_allocate_lcb
Expand Down Expand Up @@ -1558,8 +1562,17 @@ tL2C_CCB *l2cu_allocate_ccb (tL2C_LCB *p_lcb, UINT16 cid)
#if (CLASSIC_BT_INCLUDED == TRUE)
l2c_fcr_free_timer (p_ccb);
#endif ///CLASSIC_BT_INCLUDED == TRUE
p_ccb->ertm_info.preferred_mode = L2CAP_FCR_BASIC_MODE; /* Default mode for channel is basic mode */
p_ccb->ertm_info.allowed_modes = L2CAP_FCR_CHAN_OPT_BASIC|L2CAP_FCR_CHAN_OPT_ERTM;

#if BT_CLASSIC_BQB_INCLUDED
if (l2cap_bqb_ertm_mode_included_flag) {
p_ccb->ertm_info.preferred_mode = L2CAP_FCR_ERTM_MODE;
p_ccb->ertm_info.allowed_modes = L2CAP_FCR_CHAN_OPT_ERTM;
} else
#endif /* BT_CLASSIC_BQB_INCLUDED */
{
p_ccb->ertm_info.preferred_mode = L2CAP_FCR_BASIC_MODE; /* Default mode for channel is basic mode */
p_ccb->ertm_info.allowed_modes = L2CAP_FCR_CHAN_OPT_BASIC|L2CAP_FCR_CHAN_OPT_ERTM;
}
p_ccb->ertm_info.fcr_rx_buf_size = L2CAP_FCR_RX_BUF_SIZE;
p_ccb->ertm_info.fcr_tx_buf_size = L2CAP_FCR_TX_BUF_SIZE;
p_ccb->ertm_info.user_rx_buf_size = L2CAP_USER_RX_BUF_SIZE;
Expand Down
6 changes: 4 additions & 2 deletions components/bt/host/bluedroid/stack/sdp/include/sdpint.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@
#define SDP_MAX_CONTINUATION_LEN 16 /* As per the spec */

/* Timeout definitions. */
#define SDP_INACT_TIMEOUT 30 /* Inactivity timeout */

#define SDP_INACT_TIMEOUT 30 /* Inactivity timeout */
#if BT_SDP_BQB_INCLUDED
#define SDP_BQB_INACT_TIMEOUT 90 /* Inactivity timeout for BQB test */
#endif /* BT_SDP_BQB_INCLUDED */

/* Define the Out-Flow default values. */
#define SDP_OFLOW_QOS_FLAG 0
Expand Down
90 changes: 84 additions & 6 deletions components/bt/host/bluedroid/stack/sdp/sdp_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,59 @@ static void sdp_disconnect_cfm (UINT16 l2cap_cid, UINT16 result);
#define sdp_disconnect_cfm NULL
#endif

#if BT_SDP_BQB_INCLUDED
static BOOLEAN s_sdp_bqb_disable_flag = FALSE;
static BOOLEAN s_sdp_bqb_inact_timeout_flag = FALSE;
BOOLEAN l2cap_bqb_ertm_mode_included_flag = FALSE;
#endif /* BT_SDP_BQB_INCLUDED */

/*******************************************************************************
**
** Function sdp_bqb_disable_ctrl
**
** Description Control the disable of bqb for SDP BQB test
**
** Returns void
**
*******************************************************************************/
#if BT_SDP_BQB_INCLUDED
void sdp_bqb_disable_ctrl(BOOLEAN enable)
{
s_sdp_bqb_disable_flag = enable;
}
#endif /* BT_SDP_BQB_INCLUDED */

/*******************************************************************************
**
** Function sdp_bqb_inact_timeout_ctrl
**
** Description Control the inactivity timeout for SDP BQB test
**
** Returns void
**
*******************************************************************************/
#if BT_SDP_BQB_INCLUDED
void sdp_bqb_inact_timeout_ctrl(BOOLEAN enable)
{
s_sdp_bqb_inact_timeout_flag = enable;
}
#endif /* BT_SDP_BQB_INCLUDED */

/*******************************************************************************
**
** Function l2cap_bqb_ertm_mode_included_ctrl
**
** Description Control the L2CAP flow control and retransmissions mode for SDP BQB test
**
** Returns void
**
*******************************************************************************/
#if BT_SDP_BQB_INCLUDED
void l2cap_bqb_ertm_mode_included_ctrl(BOOLEAN enable)
{
l2cap_bqb_ertm_mode_included_flag = enable;
}
#endif /* BT_SDP_BQB_INCLUDED */

/*******************************************************************************
**
Expand All @@ -95,7 +148,17 @@ void sdp_init (void)
sdp_cb.l2cap_my_cfg.mtu = SDP_MTU_SIZE;
sdp_cb.l2cap_my_cfg.flush_to_present = TRUE;
sdp_cb.l2cap_my_cfg.flush_to = SDP_FLUSH_TO;

#if BT_SDP_BQB_INCLUDED
if (l2cap_bqb_ertm_mode_included_flag) {
sdp_cb.l2cap_my_cfg.fcr_present = TRUE;
sdp_cb.l2cap_my_cfg.fcr.mode = L2CAP_FCR_ERTM_MODE;
sdp_cb.l2cap_my_cfg.fcr.tx_win_sz = 8;
sdp_cb.l2cap_my_cfg.fcr.max_transmit = 0xff;
sdp_cb.l2cap_my_cfg.fcr.rtrans_tout = 2000;
sdp_cb.l2cap_my_cfg.fcr.mon_tout = 12000;
sdp_cb.l2cap_my_cfg.fcr.mps = 672;
}
#endif /* BT_SDP_BQB_INCLUDED */
sdp_cb.max_attr_list_size = SDP_MTU_SIZE - 16;
sdp_cb.max_recs_per_search = SDP_MAX_DISC_SERVER_RECS;

Expand Down Expand Up @@ -424,7 +487,15 @@ static void sdp_config_cfm (UINT16 l2cap_cid, tL2CAP_CFG_INFO *p_cfg)
} else
/* Start inactivity timer */
{
btu_start_timer (&p_ccb->timer_entry, BTU_TTYPE_SDP, SDP_INACT_TIMEOUT);
#if BT_SDP_BQB_INCLUDED
/* Change the timeout from 30s to 90s for BQB test */
if (s_sdp_bqb_inact_timeout_flag) {
btu_start_timer(&p_ccb->timer_entry, BTU_TTYPE_SDP, SDP_BQB_INACT_TIMEOUT);
} else
#endif /* BT_SDP_BQB_INCLUDED */
{
btu_start_timer(&p_ccb->timer_entry, BTU_TTYPE_SDP, SDP_INACT_TIMEOUT);
}
}
}
} else {
Expand Down Expand Up @@ -505,10 +576,17 @@ static void sdp_data_ind (UINT16 l2cap_cid, BT_HDR *p_msg)
/* Find CCB based on CID */
if ((p_ccb = sdpu_find_ccb_by_cid (l2cap_cid)) != NULL) {
if (p_ccb->con_state == SDP_STATE_CONNECTED) {
if (p_ccb->con_flags & SDP_FLAGS_IS_ORIG) {
sdp_disc_server_rsp (p_ccb, p_msg);
} else {
sdp_server_handle_client_req (p_ccb, p_msg);
#if BT_SDP_BQB_INCLUDED
/* Skip the following code in BQB test when the flag is true, since the PDU is reserved and
function sdp_server_handle_client_req will return error (sdpu_build_n_send_error) */
if (!s_sdp_bqb_disable_flag)
#endif /* BT_SDP_BQB_INCLUDED */
{
if (p_ccb->con_flags & SDP_FLAGS_IS_ORIG) {
sdp_disc_server_rsp(p_ccb, p_msg);
} else {
sdp_server_handle_client_req(p_ccb, p_msg);
}
}
} else {
SDP_TRACE_WARNING ("SDP - Ignored L2CAP data while in state: %d, CID: 0x%x\n",
Expand Down

0 comments on commit 3b7a37f

Please sign in to comment.