From 8ddee4d822712ae5760e093de4e0c7c715931b74 Mon Sep 17 00:00:00 2001 From: Hansong Zhang Date: Thu, 24 Sep 2020 17:50:55 -0700 Subject: [PATCH] L2CAP: Add a "required_remote_mtu" and store it For AVCT_BR and BNEP, we need a larger required remote mtu than minimal L2CAP MTU. So far we enforce this in profile service itself, but later we can let L2CAP module enforce this for us. Bug: 159815595 Tag: #refactor Test: compile & verify basic functions working Change-Id: I0b4bad4049636bcdc52615c000b1fff3acde360c --- stack/avct/avct_api.cc | 5 +++-- stack/avdt/avdt_api.cc | 2 +- stack/bnep/bnep_main.cc | 2 +- stack/gap/gap_conn.cc | 2 +- stack/gatt/gatt_main.cc | 2 +- stack/hid/hidd_conn.cc | 4 ++-- stack/hid/hidh_conn.cc | 2 +- stack/include/l2c_api.h | 5 +++-- stack/l2cap/l2c_api.cc | 15 +++++++++------ stack/l2cap/l2c_int.h | 3 ++- stack/rfcomm/rfc_l2cap_if.cc | 2 +- stack/sdp/sdp_main.cc | 2 +- stack/test/common/mock_l2cap_layer.cc | 2 +- 13 files changed, 27 insertions(+), 21 deletions(-) diff --git a/stack/avct/avct_api.cc b/stack/avct/avct_api.cc index 8f1729bed..ddbcab406 100644 --- a/stack/avct/avct_api.cc +++ b/stack/avct/avct_api.cc @@ -61,7 +61,7 @@ void AVCT_Register() { /* register PSM with L2CAP */ L2CA_Register2(AVCT_PSM, avct_l2c_appl, true /* enable_snoop */, nullptr, - kAvrcMtu, BTA_SEC_AUTHENTICATE); + kAvrcMtu, 0, BTA_SEC_AUTHENTICATE); /* Include the browsing channel which uses eFCR */ tL2CAP_ERTM_INFO ertm_info; @@ -72,7 +72,8 @@ void AVCT_Register() { ertm_info.fcr_tx_buf_size = BT_DEFAULT_BUFFER_SIZE; L2CA_Register2(AVCT_BR_PSM, avct_l2c_br_appl, true /*enable_snoop*/, - &ertm_info, kAvrcBrMtu, BTA_SEC_AUTHENTICATE); + &ertm_info, kAvrcBrMtu, AVCT_MIN_BROWSE_MTU, + BTA_SEC_AUTHENTICATE); #if defined(AVCT_INITIAL_TRACE_LEVEL) avct_cb.trace_level = AVCT_INITIAL_TRACE_LEVEL; diff --git a/stack/avdt/avdt_api.cc b/stack/avdt/avdt_api.cc index 539d474b3..3dcea1fc4 100644 --- a/stack/avdt/avdt_api.cc +++ b/stack/avdt/avdt_api.cc @@ -93,7 +93,7 @@ void avdt_scb_transport_channel_timer_timeout(void* data) { void AVDT_Register(AvdtpRcb* p_reg, tAVDT_CTRL_CBACK* p_cback) { /* register PSM with L2CAP */ L2CA_Register2(AVDT_PSM, avdt_l2c_appl, true /* enable_snoop */, nullptr, - kAvdtpMtu, BTA_SEC_AUTHENTICATE); + kAvdtpMtu, 0, BTA_SEC_AUTHENTICATE); /* initialize AVDTP data structures */ avdt_scb_init(); diff --git a/stack/bnep/bnep_main.cc b/stack/bnep/bnep_main.cc index d2f5785b1..46287eab2 100644 --- a/stack/bnep/bnep_main.cc +++ b/stack/bnep/bnep_main.cc @@ -92,7 +92,7 @@ tBNEP_RESULT bnep_register_with_l2cap(void) { /* Now, register with L2CAP */ if (!L2CA_Register2(BT_PSM_BNEP, bnep_cb.reg_info, false /* enable_snoop */, - nullptr, BNEP_MTU_SIZE, + nullptr, BNEP_MTU_SIZE, BNEP_MTU_SIZE, BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT)) { BNEP_TRACE_ERROR("BNEP - Registration failed"); return BNEP_SECURITY_FAIL; diff --git a/stack/gap/gap_conn.cc b/stack/gap/gap_conn.cc index 281d5fe0e..4d69f0800 100644 --- a/stack/gap/gap_conn.cc +++ b/stack/gap/gap_conn.cc @@ -241,7 +241,7 @@ uint16_t GAP_ConnOpen(const char* p_serv_name, uint8_t service_id, if (transport == BT_TRANSPORT_BR_EDR) { p_ccb->psm = L2CA_Register2(psm, conn.reg_info, false /* enable_snoop */, - &p_ccb->ertm_info, L2CAP_SDU_LENGTH_MAX, security); + &p_ccb->ertm_info, L2CAP_SDU_LENGTH_MAX, 0, security); if (p_ccb->psm == 0) { LOG(ERROR) << StringPrintf("%s: Failure registering PSM 0x%04x", __func__, psm); diff --git a/stack/gatt/gatt_main.cc b/stack/gatt/gatt_main.cc index 9a0d68dde..2a0f75ef9 100644 --- a/stack/gatt/gatt_main.cc +++ b/stack/gatt/gatt_main.cc @@ -114,7 +114,7 @@ void gatt_init(void) { /* Now, register with L2CAP for ATT PSM over BR/EDR */ if (!L2CA_Register2(BT_PSM_ATT, dyn_info, false /* enable_snoop */, nullptr, - GATT_MAX_MTU_SIZE, BTM_SEC_NONE)) { + GATT_MAX_MTU_SIZE, 0, BTM_SEC_NONE)) { LOG(ERROR) << "ATT Dynamic Registration failed"; } diff --git a/stack/hid/hidd_conn.cc b/stack/hid/hidd_conn.cc index 874ba33c4..e1480f07e 100644 --- a/stack/hid/hidd_conn.cc +++ b/stack/hid/hidd_conn.cc @@ -742,14 +742,14 @@ tHID_STATUS hidd_conn_reg(void) { hd_cb.l2cap_intr_cfg.mtu = HID_DEV_MTU_SIZE; if (!L2CA_Register2(HID_PSM_CONTROL, dev_reg_info, false /* enable_snoop */, - nullptr, HID_DEV_MTU_SIZE, + nullptr, HID_DEV_MTU_SIZE, 0, BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT)) { HIDD_TRACE_ERROR("HID Control (device) registration failed"); return (HID_ERR_L2CAP_FAILED); } if (!L2CA_Register2(HID_PSM_INTERRUPT, dev_reg_info, false /* enable_snoop */, - nullptr, HID_DEV_MTU_SIZE, + nullptr, HID_DEV_MTU_SIZE, 0, BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT)) { L2CA_Deregister(HID_PSM_CONTROL); HIDD_TRACE_ERROR("HID Interrupt (device) registration failed"); diff --git a/stack/hid/hidh_conn.cc b/stack/hid/hidh_conn.cc index 6d9527e8b..a6d2c83c2 100644 --- a/stack/hid/hidh_conn.cc +++ b/stack/hid/hidh_conn.cc @@ -92,7 +92,7 @@ tHID_STATUS hidh_conn_reg(void) { /* Now, register with L2CAP */ if (!L2CA_Register2(HID_PSM_INTERRUPT, hst_reg_info, false /* enable_snoop */, - nullptr, HID_HOST_MTU, + nullptr, HID_HOST_MTU, 0, BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT)) { L2CA_Deregister(HID_PSM_CONTROL); HIDH_TRACE_ERROR("HID-Host Interrupt Registration failed"); diff --git a/stack/include/l2c_api.h b/stack/include/l2c_api.h index a410c8126..1a75312d5 100644 --- a/stack/include/l2c_api.h +++ b/stack/include/l2c_api.h @@ -278,7 +278,8 @@ void l2c_free(); // Also does security for you uint16_t L2CA_Register2(uint16_t psm, const tL2CAP_APPL_INFO& p_cb_info, bool enable_snoop, tL2CAP_ERTM_INFO* p_ertm_info, - uint16_t required_mtu, uint16_t sec_level); + uint16_t my_mtu, uint16_t required_remote_mtu, + uint16_t sec_level); /******************************************************************************* * @@ -296,7 +297,7 @@ uint16_t L2CA_Register2(uint16_t psm, const tL2CAP_APPL_INFO& p_cb_info, ******************************************************************************/ extern uint16_t L2CA_Register(uint16_t psm, const tL2CAP_APPL_INFO& p_cb_info, bool enable_snoop, tL2CAP_ERTM_INFO* p_ertm_info, - uint16_t required_mtu); + uint16_t my_mtu, uint16_t required_remote_mtu); /******************************************************************************* * diff --git a/stack/l2cap/l2c_api.cc b/stack/l2cap/l2c_api.cc index 9033288c6..d3bce8268 100644 --- a/stack/l2cap/l2c_api.cc +++ b/stack/l2cap/l2c_api.cc @@ -44,9 +44,10 @@ using base::StringPrintf; uint16_t L2CA_Register2(uint16_t psm, const tL2CAP_APPL_INFO& p_cb_info, bool enable_snoop, tL2CAP_ERTM_INFO* p_ertm_info, - uint16_t required_mtu, uint16_t sec_level) { - auto ret = - L2CA_Register(psm, p_cb_info, enable_snoop, p_ertm_info, required_mtu); + uint16_t my_mtu, uint16_t required_remote_mtu, + uint16_t sec_level) { + auto ret = L2CA_Register(psm, p_cb_info, enable_snoop, p_ertm_info, my_mtu, + required_remote_mtu); BTM_SetSecurityLevel(false, "", 0, sec_level, psm, 0, 0); return ret; } @@ -67,10 +68,10 @@ uint16_t L2CA_Register2(uint16_t psm, const tL2CAP_APPL_INFO& p_cb_info, ******************************************************************************/ uint16_t L2CA_Register(uint16_t psm, const tL2CAP_APPL_INFO& p_cb_info, bool enable_snoop, tL2CAP_ERTM_INFO* p_ertm_info, - uint16_t required_mtu) { + uint16_t my_mtu, uint16_t required_remote_mtu) { if (bluetooth::shim::is_gd_shim_enabled()) { return bluetooth::shim::L2CA_Register(psm, p_cb_info, enable_snoop, - p_ertm_info, required_mtu); + p_ertm_info, my_mtu); } tL2C_RCB* p_rcb; @@ -122,7 +123,9 @@ uint16_t L2CA_Register(uint16_t psm, const tL2CAP_APPL_INFO& p_cb_info, p_rcb->api = p_cb_info; p_rcb->real_psm = psm; p_rcb->ertm_info = p_ertm_info == nullptr ? tL2CAP_ERTM_INFO{} : *p_ertm_info; - p_rcb->required_mtu = std::max(required_mtu, L2CAP_DEFAULT_MTU); + p_rcb->my_mtu = my_mtu; + p_rcb->required_remote_mtu = + std::max(required_remote_mtu, L2CAP_MIN_MTU); return (vpsm); } diff --git a/stack/l2cap/l2c_int.h b/stack/l2cap/l2c_int.h index cd5f2d98c..bcf1c2374 100644 --- a/stack/l2cap/l2c_int.h +++ b/stack/l2cap/l2c_int.h @@ -202,7 +202,8 @@ typedef struct { /* this is the real PSM that we need to connect to */ tL2CAP_APPL_INFO api; tL2CAP_ERTM_INFO ertm_info; - uint16_t required_mtu; + uint16_t my_mtu; + uint16_t required_remote_mtu; } tL2C_RCB; #define L2CAP_CBB_DEFAULT_DATA_RATE_BUFF_QUOTA 100 diff --git a/stack/rfcomm/rfc_l2cap_if.cc b/stack/rfcomm/rfc_l2cap_if.cc index e7bee2984..4fdcdf200 100644 --- a/stack/rfcomm/rfc_l2cap_if.cc +++ b/stack/rfcomm/rfc_l2cap_if.cc @@ -71,7 +71,7 @@ void rfcomm_l2cap_if_init(void) { p_l2c->pL2CA_TxComplete_Cb = NULL; L2CA_Register(BT_PSM_RFCOMM, rfc_cb.rfc.reg_info, true /* enable_snoop */, - nullptr, L2CAP_MTU_SIZE); + nullptr, L2CAP_MTU_SIZE, 0); } /******************************************************************************* diff --git a/stack/sdp/sdp_main.cc b/stack/sdp/sdp_main.cc index 52fe345ed..3622a0869 100644 --- a/stack/sdp/sdp_main.cc +++ b/stack/sdp/sdp_main.cc @@ -90,7 +90,7 @@ void sdp_init(void) { /* Now, register with L2CAP */ if (!L2CA_Register2(SDP_PSM, sdp_cb.reg_info, true /* enable_snoop */, - nullptr, SDP_MTU_SIZE, BTM_SEC_NONE)) { + nullptr, SDP_MTU_SIZE, 0, BTM_SEC_NONE)) { SDP_TRACE_ERROR("SDP Registration failed"); } } diff --git a/stack/test/common/mock_l2cap_layer.cc b/stack/test/common/mock_l2cap_layer.cc index a43a6bab5..33e864312 100644 --- a/stack/test/common/mock_l2cap_layer.cc +++ b/stack/test/common/mock_l2cap_layer.cc @@ -26,7 +26,7 @@ void bluetooth::l2cap::SetMockInterface( uint16_t L2CA_Register(uint16_t psm, const tL2CAP_APPL_INFO& p_cb_info, bool enable_snoop, tL2CAP_ERTM_INFO* p_ertm_info, - uint16_t required_mtu) { + uint16_t my_mtu, uint16_t required_remote_mtu) { VLOG(1) << __func__ << ": psm=" << psm << ", enable_snoop=" << enable_snoop; return l2cap_interface->Register(psm, p_cb_info, enable_snoop, p_ertm_info); } -- 2.11.0