From 740dc8795da5687e44085f2c45f41ce2cb5ea12d Mon Sep 17 00:00:00 2001 From: xiongweichao Date: Thu, 21 Apr 2022 14:37:49 +0800 Subject: [PATCH] rfcomm supports the use of ERTM --- .../common/include/common/bt_target.h | 25 +++++++++++++++ .../bt/host/bluedroid/stack/l2cap/l2c_utils.c | 2 +- .../bluedroid/stack/rfcomm/rfc_l2cap_if.c | 18 +++++++++-- .../host/bluedroid/stack/rfcomm/rfc_mx_fsm.c | 31 +++++++++++++++++-- 4 files changed, 70 insertions(+), 6 deletions(-) diff --git a/components/bt/host/bluedroid/common/include/common/bt_target.h b/components/bt/host/bluedroid/common/include/common/bt_target.h index 1373c2000b..a0c20840b1 100644 --- a/components/bt/host/bluedroid/common/include/common/bt_target.h +++ b/components/bt/host/bluedroid/common/include/common/bt_target.h @@ -1565,6 +1565,31 @@ #define PORT_CREDIT_RX_LOW 8 #endif +/* ERTM Tx window size */ +#ifndef RFC_FCR_OPT_TX_WINDOW_SIZE +#define RFC_FCR_OPT_TX_WINDOW_SIZE 20 +#endif + +/* ERTM Maximum transmissions before disconnecting */ +#ifndef RFC_FCR_OPT_MAX_TX_B4_DISCNT +#define RFC_FCR_OPT_MAX_TX_B4_DISCNT 20 +#endif + +/* ERTM Retransmission timeout (2 secs) */ +#ifndef RFC_FCR_OPT_RETX_TOUT +#define RFC_FCR_OPT_RETX_TOUT 2000 +#endif + +/* ERTM Monitor timeout (12 secs) */ +#ifndef RFC_FCR_OPT_MONITOR_TOUT +#define RFC_FCR_OPT_MONITOR_TOUT 12000 +#endif + +/* ERTM ERTM MPS segment size */ +#ifndef RFC_FCR_OPT_MAX_PDU_SIZE +#define RFC_FCR_OPT_MAX_PDU_SIZE 1010 +#endif + /****************************************************************************** ** ** OBEX diff --git a/components/bt/host/bluedroid/stack/l2cap/l2c_utils.c b/components/bt/host/bluedroid/stack/l2cap/l2c_utils.c index f77ab9ee71..059abe7be1 100644 --- a/components/bt/host/bluedroid/stack/l2cap/l2c_utils.c +++ b/components/bt/host/bluedroid/stack/l2cap/l2c_utils.c @@ -1559,7 +1559,7 @@ tL2C_CCB *l2cu_allocate_ccb (tL2C_LCB *p_lcb, UINT16 cid) 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; /* Default mode for channel is basic mode */ + p_ccb->ertm_info.allowed_modes = L2CAP_FCR_CHAN_OPT_BASIC|L2CAP_FCR_CHAN_OPT_BASIC; 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; diff --git a/components/bt/host/bluedroid/stack/rfcomm/rfc_l2cap_if.c b/components/bt/host/bluedroid/stack/rfcomm/rfc_l2cap_if.c index 5b2fff17d4..a30bf25cf4 100644 --- a/components/bt/host/bluedroid/stack/rfcomm/rfc_l2cap_if.c +++ b/components/bt/host/bluedroid/stack/rfcomm/rfc_l2cap_if.c @@ -36,6 +36,17 @@ #include "osi/mutex.h" #include "osi/alarm.h" #if (defined RFCOMM_INCLUDED && RFCOMM_INCLUDED == TRUE) + +static tL2CAP_ERTM_INFO rfc_l2c_etm_opt = +{ + L2CAP_FCR_ERTM_MODE, + L2CAP_FCR_CHAN_OPT_ERTM|L2CAP_FCR_CHAN_OPT_BASIC, /* Some devices do not support ERTM */ + L2CAP_USER_RX_BUF_SIZE, + L2CAP_USER_TX_BUF_SIZE, + L2CAP_FCR_RX_BUF_SIZE, + L2CAP_FCR_TX_BUF_SIZE +}; + /* ** Define Callback functions to be called by L2CAP */ @@ -117,7 +128,8 @@ void RFCOMM_ConnectInd (BD_ADDR bd_addr, UINT16 lcid, UINT16 psm, UINT8 id) } if (p_mcb == NULL) { - L2CA_ConnectRsp (bd_addr, id, lcid, L2CAP_CONN_NO_RESOURCES, 0); + // L2CA_ConnectRsp (bd_addr, id, lcid, L2CAP_CONN_NO_RESOURCES, 0); + L2CA_ErtmConnectRsp (bd_addr, id, lcid, L2CAP_CONN_NO_RESOURCES, 0, &rfc_l2c_etm_opt); return; } p_mcb->lcid = lcid; @@ -178,7 +190,9 @@ void RFCOMM_ConnectCnf (UINT16 lcid, UINT16 result) RFCOMM_TRACE_DEBUG ("RFCOMM_ConnectCnf peer gave up pending LCID(0x%x)", p_mcb->pending_lcid); /* Peer gave up his connection request, make sure cleaning up L2CAP channel */ - L2CA_ConnectRsp (p_mcb->bd_addr, p_mcb->pending_id, p_mcb->pending_lcid, L2CAP_CONN_NO_RESOURCES, 0); + // L2CA_ConnectRsp (p_mcb->bd_addr, p_mcb->pending_id, p_mcb->pending_lcid, L2CAP_CONN_NO_RESOURCES, 0); + L2CA_ErtmConnectRsp (p_mcb->bd_addr, p_mcb->pending_id, p_mcb->pending_lcid, L2CAP_CONN_NO_RESOURCES, 0, + &rfc_l2c_etm_opt); p_mcb->pending_lcid = 0; } diff --git a/components/bt/host/bluedroid/stack/rfcomm/rfc_mx_fsm.c b/components/bt/host/bluedroid/stack/rfcomm/rfc_mx_fsm.c index 4ed65fc945..8dc4d1af11 100644 --- a/components/bt/host/bluedroid/stack/rfcomm/rfc_mx_fsm.c +++ b/components/bt/host/bluedroid/stack/rfcomm/rfc_mx_fsm.c @@ -39,6 +39,25 @@ #define L2CAP_SUCCESS 0 #define L2CAP_ERROR 1 +static tL2CAP_ERTM_INFO rfc_l2c_etm_opt = +{ + L2CAP_FCR_ERTM_MODE, + L2CAP_FCR_CHAN_OPT_ERTM|L2CAP_FCR_CHAN_OPT_BASIC, /* Some devices do not support ERTM */ + L2CAP_USER_RX_BUF_SIZE, + L2CAP_USER_TX_BUF_SIZE, + L2CAP_FCR_RX_BUF_SIZE, + L2CAP_FCR_TX_BUF_SIZE +}; + +static tL2CAP_FCR_OPTS rfc_l2c_fcr_opts_def = +{ + L2CAP_FCR_ERTM_MODE, + RFC_FCR_OPT_TX_WINDOW_SIZE, /* Tx window size */ + RFC_FCR_OPT_MAX_TX_B4_DISCNT, /* Maximum transmissions before disconnecting */ + RFC_FCR_OPT_RETX_TOUT, /* Retransmission timeout (2 secs) */ + RFC_FCR_OPT_MONITOR_TOUT, /* Monitor timeout (12 secs) */ + RFC_FCR_OPT_MAX_PDU_SIZE /* MPS segment size */ +}; /********************************************************************************/ /* L O C A L F U N C T I O N P R O T O T Y P E S */ @@ -124,7 +143,8 @@ void rfc_mx_sm_state_idle (tRFC_MCB *p_mcb, UINT16 event, void *p_data) /* Initialize L2CAP MTU */ p_mcb->peer_l2cap_mtu = L2CAP_DEFAULT_MTU - RFCOMM_MIN_OFFSET - 1; - if ((p_mcb->lcid = L2CA_ConnectReq (BT_PSM_RFCOMM, p_mcb->bd_addr)) == 0) { + // if ((p_mcb->lcid = L2CA_ConnectReq (BT_PSM_RFCOMM, p_mcb->bd_addr)) == 0) { + if ((p_mcb->lcid = L2CA_ErtmConnectReq (BT_PSM_RFCOMM, p_mcb->bd_addr, &rfc_l2c_etm_opt)) == 0) { PORT_StartCnf (p_mcb, RFCOMM_ERROR); return; } @@ -144,7 +164,8 @@ void rfc_mx_sm_state_idle (tRFC_MCB *p_mcb, UINT16 event, void *p_data) case RFC_MX_EVENT_CONN_IND: rfc_timer_start (p_mcb, RFCOMM_CONN_TIMEOUT); - L2CA_ConnectRsp (p_mcb->bd_addr, *((UINT8 *)p_data), p_mcb->lcid, L2CAP_CONN_OK, 0); + // L2CA_ConnectRsp (p_mcb->bd_addr, *((UINT8 *)p_data), p_mcb->lcid, L2CAP_CONN_OK, 0); + L2CA_ErtmConnectRsp (p_mcb->bd_addr, *((UINT8 *)p_data), p_mcb->lcid, L2CAP_CONN_OK, 0, &rfc_l2c_etm_opt); rfc_mx_send_config_req (p_mcb); @@ -482,7 +503,8 @@ void rfc_mx_sm_state_disc_wait_ua (tRFC_MCB *p_mcb, UINT16 event, void *p_data) if (p_mcb->restart_required) { /* Start Request was received while disconnecting. Execute it again */ - if ((p_mcb->lcid = L2CA_ConnectReq (BT_PSM_RFCOMM, p_mcb->bd_addr)) == 0) { + // if ((p_mcb->lcid = L2CA_ConnectReq (BT_PSM_RFCOMM, p_mcb->bd_addr)) == 0) { + if ((p_mcb->lcid = L2CA_ErtmConnectReq (BT_PSM_RFCOMM, p_mcb->bd_addr, &rfc_l2c_etm_opt)) == 0) { PORT_StartCnf (p_mcb, RFCOMM_ERROR); return; } @@ -554,6 +576,9 @@ static void rfc_mx_send_config_req (tRFC_MCB *p_mcb) cfg.mtu_present = TRUE; cfg.mtu = L2CAP_MTU_SIZE; + cfg.fcr_present = TRUE; + cfg.fcr = rfc_l2c_fcr_opts_def; + /* Defaults set by memset cfg.flush_to_present = FALSE; cfg.qos_present = FALSE;