OSDN Git Service

Convert gap_connections to new l2cap + security
authorZach Johnson <zachoverflow@google.com>
Wed, 26 Aug 2020 23:19:26 +0000 (16:19 -0700)
committerZach Johnson <zachoverflow@google.com>
Wed, 26 Aug 2020 23:19:54 +0000 (16:19 -0700)
Bug: 159815595
Tag: #refactor
Test: compile & verify basic functions working
Change-Id: I144bf8dada7ef5e56772d31676911990be135635

stack/gap/gap_conn.cc
stack/include/l2c_api.h
stack/l2cap/l2c_api.cc

index bd59da4..655e5c5 100644 (file)
@@ -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);
index d108804..300c5a6 100644 (file)
@@ -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);
 
 /*******************************************************************************
  *
index f4beec4..95439c5 100644 (file)
@@ -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);