From c64bff7bc5de96497382c32df0f59a6139d0de08 Mon Sep 17 00:00:00 2001 From: Zach Johnson Date: Wed, 26 Aug 2020 16:19:26 -0700 Subject: [PATCH] Convert gap_connections to new l2cap + security Bug: 159815595 Tag: #refactor Test: compile & verify basic functions working Change-Id: I144bf8dada7ef5e56772d31676911990be135635 --- stack/gap/gap_conn.cc | 21 ++++++++------------- stack/include/l2c_api.h | 6 ++++-- stack/l2cap/l2c_api.cc | 8 ++++++-- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/stack/gap/gap_conn.cc b/stack/gap/gap_conn.cc index bd59da457..655e5c575 100644 --- a/stack/gap/gap_conn.cc +++ b/stack/gap/gap_conn.cc @@ -244,8 +244,8 @@ uint16_t GAP_ConnOpen(const char* p_serv_name, uint8_t service_id, /* Register the PSM with L2CAP */ if (transport == BT_TRANSPORT_BR_EDR) { - p_ccb->psm = L2CA_Register(psm, &conn.reg_info, false /* enable_snoop */, - &p_ccb->ertm_info, L2CAP_MTU_SIZE); + p_ccb->psm = L2CA_Register2(psm, &conn.reg_info, false /* enable_snoop */, + &p_ccb->ertm_info, L2CAP_MTU_SIZE, security); if (p_ccb->psm == 0) { LOG(ERROR) << StringPrintf("%s: Failure registering PSM 0x%04x", __func__, psm); @@ -255,7 +255,8 @@ uint16_t GAP_ConnOpen(const char* p_serv_name, uint8_t service_id, } if (transport == BT_TRANSPORT_LE) { - p_ccb->psm = L2CA_RegisterLECoc(psm, (tL2CAP_APPL_INFO*)&conn.reg_info); + p_ccb->psm = + L2CA_RegisterLECoc(psm, (tL2CAP_APPL_INFO*)&conn.reg_info, security); if (p_ccb->psm == 0) { LOG(ERROR) << StringPrintf("%s: Failure registering PSM 0x%04x", __func__, psm); @@ -264,14 +265,6 @@ uint16_t GAP_ConnOpen(const char* p_serv_name, uint8_t service_id, } } - /* Register with Security Manager for the specific security level */ - if (!BTM_SetSecurityLevel((uint8_t)!is_server, p_serv_name, p_ccb->service_id, - security, p_ccb->psm, 0, 0)) { - LOG(ERROR) << "GAP_CONN - Security Error"; - gap_release_ccb(p_ccb); - return (GAP_INVALID_HANDLE); - } - /* optional FCR channel modes */ if (ertm_info != NULL) { p_ccb->ertm_info.allowed_modes = @@ -297,7 +290,8 @@ uint16_t GAP_ConnOpen(const char* p_serv_name, uint8_t service_id, /* Check if L2CAP started the connection process */ if (p_rem_bda && (transport == BT_TRANSPORT_BR_EDR)) { - cid = L2CA_ErtmConnectReq(p_ccb->psm, *p_rem_bda, &p_ccb->ertm_info); + cid = L2CA_ErtmConnectReq2(p_ccb->psm, *p_rem_bda, &p_ccb->ertm_info, + security); if (cid != 0) { p_ccb->connection_id = cid; return (p_ccb->gap_handle); @@ -305,7 +299,8 @@ uint16_t GAP_ConnOpen(const char* p_serv_name, uint8_t service_id, } if (p_rem_bda && (transport == BT_TRANSPORT_LE)) { - cid = L2CA_ConnectLECocReq(p_ccb->psm, *p_rem_bda, &p_ccb->local_coc_cfg); + cid = L2CA_ConnectLECocReq(p_ccb->psm, *p_rem_bda, &p_ccb->local_coc_cfg, + security); if (cid != 0) { p_ccb->connection_id = cid; return (p_ccb->gap_handle); diff --git a/stack/include/l2c_api.h b/stack/include/l2c_api.h index d1088042a..300c5a6d4 100644 --- a/stack/include/l2c_api.h +++ b/stack/include/l2c_api.h @@ -431,7 +431,8 @@ extern uint16_t L2CA_ErtmConnectReq(uint16_t psm, const RawAddress& p_bd_addr, * and BTM_SetSecurityLevel(). * ******************************************************************************/ -extern uint16_t L2CA_RegisterLECoc(uint16_t psm, tL2CAP_APPL_INFO* p_cb_info); +extern uint16_t L2CA_RegisterLECoc(uint16_t psm, tL2CAP_APPL_INFO* p_cb_info, + uint16_t sec_level); /******************************************************************************* * @@ -458,7 +459,8 @@ extern void L2CA_DeregisterLECoc(uint16_t psm); * ******************************************************************************/ extern uint16_t L2CA_ConnectLECocReq(uint16_t psm, const RawAddress& p_bd_addr, - tL2CAP_LE_CFG_INFO* p_cfg); + tL2CAP_LE_CFG_INFO* p_cfg, + uint16_t sec_level); /******************************************************************************* * diff --git a/stack/l2cap/l2c_api.cc b/stack/l2cap/l2c_api.cc index f4beec4ae..95439c55b 100644 --- a/stack/l2cap/l2c_api.cc +++ b/stack/l2cap/l2c_api.cc @@ -450,11 +450,13 @@ uint16_t L2CA_ErtmConnectReq(uint16_t psm, const RawAddress& p_bd_addr, * and L2CA_DeregisterLECoc() * ******************************************************************************/ -uint16_t L2CA_RegisterLECoc(uint16_t psm, tL2CAP_APPL_INFO* p_cb_info) { +uint16_t L2CA_RegisterLECoc(uint16_t psm, tL2CAP_APPL_INFO* p_cb_info, + uint16_t sec_level) { if (bluetooth::shim::is_gd_shim_enabled()) { return bluetooth::shim::L2CA_RegisterLECoc(psm, p_cb_info); } + BTM_SetSecurityLevel(false, "", 0, sec_level, psm, 0, 0); L2CAP_TRACE_API("%s called for LE PSM: 0x%04x", __func__, psm); /* Verify that the required callback info has been filled in @@ -568,11 +570,13 @@ void L2CA_DeregisterLECoc(uint16_t psm) { * ******************************************************************************/ uint16_t L2CA_ConnectLECocReq(uint16_t psm, const RawAddress& p_bd_addr, - tL2CAP_LE_CFG_INFO* p_cfg) { + tL2CAP_LE_CFG_INFO* p_cfg, uint16_t sec_level) { if (bluetooth::shim::is_gd_shim_enabled()) { return bluetooth::shim::L2CA_ConnectLECocReq(psm, p_bd_addr, p_cfg); } + BTM_SetSecurityLevel(true, "", 0, sec_level, psm, 0, 0); + VLOG(1) << __func__ << " BDA: " << p_bd_addr << StringPrintf(" PSM: 0x%04x", psm); -- 2.11.0