OSDN Git Service

Add L2CA_Register2, which does security for you
authorZach Johnson <zachoverflow@google.com>
Tue, 25 Aug 2020 17:51:10 +0000 (10:51 -0700)
committerZach Johnson <zachoverflow@google.com>
Tue, 25 Aug 2020 22:30:57 +0000 (15:30 -0700)
start using it in a few places

Bug: 159815595
Tag: #refactor
Test: compile & verify basic functions working
Change-Id: I667eb86e0011376412eb0ab8800cdaed140cf3b3

stack/avct/avct_api.cc
stack/hid/hidd_conn.cc
stack/include/l2c_api.h
stack/l2cap/l2c_api.cc
stack/sdp/sdp_main.cc

index 72f9aae..06c2ff0 100644 (file)
@@ -64,8 +64,9 @@ void AVCT_Register(uint16_t mtu, UNUSED_ATTR uint16_t mtu_br) {
   avct_cb.mtu = mtu;
 
   /* register PSM with L2CAP */
-  L2CA_Register(AVCT_PSM, (tL2CAP_APPL_INFO*)&avct_l2c_appl,
-                true /* enable_snoop */, nullptr, avct_cb.mtu);
+  L2CA_Register2(AVCT_PSM, (tL2CAP_APPL_INFO*)&avct_l2c_appl,
+                 true /* enable_snoop */, nullptr, avct_cb.mtu,
+                 BTA_SEC_AUTHENTICATE);
 
   BTM_SimpleSetSecurityLevel(BTM_SEC_SERVICE_AVCTP, BTA_SEC_AUTHENTICATE,
                              AVCT_PSM);
@@ -82,8 +83,9 @@ void AVCT_Register(uint16_t mtu, UNUSED_ATTR uint16_t mtu_br) {
   if (mtu_br < AVCT_MIN_BROWSE_MTU) mtu_br = AVCT_MIN_BROWSE_MTU;
   avct_cb.mtu_br = mtu_br;
 
-  L2CA_Register(AVCT_BR_PSM, (tL2CAP_APPL_INFO*)&avct_l2c_br_appl,
-                true /*enable_snoop*/, &ertm_info, avct_cb.mtu_br);
+  L2CA_Register2(AVCT_BR_PSM, (tL2CAP_APPL_INFO*)&avct_l2c_br_appl,
+                 true /*enable_snoop*/, &ertm_info, avct_cb.mtu_br,
+                 BTA_SEC_AUTHENTICATE);
 
   /* AVCTP browsing channel uses the same security service as AVCTP control
    * channel */
index aded84e..f51f839 100644 (file)
@@ -772,15 +772,16 @@ tHID_STATUS hidd_conn_reg(void) {
     return (HID_ERR_NO_RESOURCES);
   }
 
-  if (!L2CA_Register(HID_PSM_CONTROL, (tL2CAP_APPL_INFO*)&dev_reg_info,
-                     false /* enable_snoop */, nullptr, hd_cb.l2cap_cfg.mtu)) {
+  if (!L2CA_Register2(HID_PSM_CONTROL, (tL2CAP_APPL_INFO*)&dev_reg_info,
+                      false /* enable_snoop */, nullptr, hd_cb.l2cap_cfg.mtu,
+                      BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT)) {
     HIDD_TRACE_ERROR("HID Control (device) registration failed");
     return (HID_ERR_L2CAP_FAILED);
   }
 
-  if (!L2CA_Register(HID_PSM_INTERRUPT, (tL2CAP_APPL_INFO*)&dev_reg_info,
-                     false /* enable_snoop */, nullptr,
-                     hd_cb.l2cap_intr_cfg.mtu)) {
+  if (!L2CA_Register2(HID_PSM_INTERRUPT, (tL2CAP_APPL_INFO*)&dev_reg_info,
+                      false /* enable_snoop */, nullptr,
+                      hd_cb.l2cap_intr_cfg.mtu, BTM_SEC_NONE)) {
     L2CA_Deregister(HID_PSM_CONTROL);
     HIDD_TRACE_ERROR("HID Interrupt (device) registration failed");
     return (HID_ERR_L2CAP_FAILED);
index 04a4bb6..78c6f81 100644 (file)
@@ -296,6 +296,11 @@ void l2c_free();
  *  External Function Declarations
  ****************************************************************************/
 
+// Also does security for you
+uint16_t L2CA_Register2(uint16_t psm, tL2CAP_APPL_INFO* p_cb_info,
+                        bool enable_snoop, tL2CAP_ERTM_INFO* p_ertm_info,
+                        uint16_t required_mtu, uint16_t sec_level);
+
 /*******************************************************************************
  *
  * Function         L2CA_Register
index 4837895..573c332 100644 (file)
@@ -29,6 +29,7 @@
 #include <cstdint>
 #include <string>
 
+#include "btm_sec.h"
 #include "device/include/controller.h"  // TODO Remove
 #include "main/shim/l2c_api.h"
 #include "main/shim/shim.h"
@@ -41,6 +42,15 @@ void btsnd_hcic_enhanced_flush(uint16_t handle,
 
 using base::StringPrintf;
 
+uint16_t L2CA_Register2(uint16_t psm, 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);
+  BTM_SetSecurityLevel(false, "", 0, sec_level, psm, 0, 0);
+  return ret;
+}
+
 /*******************************************************************************
  *
  * Function         L2CA_Register
index 416ce40..f32c708 100644 (file)
@@ -106,8 +106,8 @@ void sdp_init(void) {
   sdp_cb.reg_info.pL2CA_TxComplete_Cb = NULL;
 
   /* Now, register with L2CAP */
-  if (!L2CA_Register(SDP_PSM, &sdp_cb.reg_info, true /* enable_snoop */,
-                     nullptr, sdp_cb.l2cap_my_cfg.mtu)) {
+  if (!L2CA_Register2(SDP_PSM, &sdp_cb.reg_info, true /* enable_snoop */,
+                      nullptr, sdp_cb.l2cap_my_cfg.mtu, BTM_SEC_NONE)) {
     SDP_TRACE_ERROR("SDP Registration failed");
   }
 }