OSDN Git Service

Add connect request variants that do security
authorZach Johnson <zachoverflow@google.com>
Tue, 25 Aug 2020 21:34:13 +0000 (14:34 -0700)
committerZach Johnson <zachoverflow@google.com>
Tue, 25 Aug 2020 22:30:57 +0000 (15:30 -0700)
also use them in avct

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

stack/avct/avct_api.cc
stack/avct/avct_bcb_act.cc
stack/avct/avct_lcb_act.cc
stack/include/l2c_api.h
stack/l2cap/l2c_api.cc

index 06c2ff0..4b38e4b 100644 (file)
@@ -68,9 +68,6 @@ void AVCT_Register(uint16_t mtu, UNUSED_ATTR uint16_t mtu_br) {
                  true /* enable_snoop */, nullptr, avct_cb.mtu,
                  BTA_SEC_AUTHENTICATE);
 
-  BTM_SimpleSetSecurityLevel(BTM_SEC_SERVICE_AVCTP, BTA_SEC_AUTHENTICATE,
-                             AVCT_PSM);
-
   /* Include the browsing channel which uses eFCR */
   tL2CAP_ERTM_INFO ertm_info;
   ertm_info.preferred_mode = avct_l2c_br_fcr_opts_def.mode;
@@ -87,11 +84,6 @@ void AVCT_Register(uint16_t mtu, UNUSED_ATTR uint16_t mtu_br) {
                  true /*enable_snoop*/, &ertm_info, avct_cb.mtu_br,
                  BTA_SEC_AUTHENTICATE);
 
-  /* AVCTP browsing channel uses the same security service as AVCTP control
-   * channel */
-  BTM_SimpleSetSecurityLevel(BTM_SEC_SERVICE_AVCTP, BTA_SEC_AUTHENTICATE,
-                             AVCT_BR_PSM);
-
 #if defined(AVCT_INITIAL_TRACE_LEVEL)
   avct_cb.trace_level = AVCT_INITIAL_TRACE_LEVEL;
 #else
index 645b6e2..f208a52 100644 (file)
@@ -31,6 +31,7 @@
 #include "avct_int.h"
 #include "bt_target.h"
 #include "bt_utils.h"
+#include "bta/include/bta_api.h"
 #include "btm_api.h"
 #include "osi/include/osi.h"
 #include "stack/btm/btm_sec.h"
@@ -104,8 +105,6 @@ void avct_bcb_chnl_open(tAVCT_BCB* p_bcb, UNUSED_ATTR tAVCT_LCB_EVT* p_data) {
   tAVCT_LCB* p_lcb = avct_lcb_by_bcb(p_bcb);
   tL2CAP_ERTM_INFO ertm_info;
 
-  BTM_SetOutService(p_lcb->peer_addr, BTM_SEC_SERVICE_AVCTP_BROWSE, 0);
-
   /* Set the FCR options: Browsing channel mandates ERTM */
   ertm_info.preferred_mode = L2CAP_FCR_ERTM_MODE;
   ertm_info.allowed_modes = L2CAP_FCR_CHAN_OPT_ERTM;
@@ -116,8 +115,8 @@ void avct_bcb_chnl_open(tAVCT_BCB* p_bcb, UNUSED_ATTR tAVCT_LCB_EVT* p_data) {
 
   /* call l2cap connect req */
   p_bcb->ch_state = AVCT_CH_CONN;
-  p_bcb->ch_lcid =
-      L2CA_ErtmConnectReq(AVCT_BR_PSM, p_lcb->peer_addr, &ertm_info);
+  p_bcb->ch_lcid = L2CA_ErtmConnectReq2(AVCT_BR_PSM, p_lcb->peer_addr,
+                                        &ertm_info, BTA_SEC_AUTHENTICATE);
   if (p_bcb->ch_lcid == 0) {
     /* if connect req failed, send ourselves close event */
     tAVCT_LCB_EVT avct_lcb_evt;
index 56ec824..6e4dd4b 100644 (file)
@@ -29,6 +29,7 @@
 #include "bt_target.h"
 #include "bt_types.h"
 #include "bt_utils.h"
+#include "bta/include/bta_api.h"
 #include "btm_api.h"
 #include "osi/include/osi.h"
 #include "stack/btm/btm_sec.h"
@@ -174,10 +175,9 @@ static BT_HDR* avct_lcb_msg_asmbl(tAVCT_LCB* p_lcb, BT_HDR* p_buf) {
 void avct_lcb_chnl_open(tAVCT_LCB* p_lcb, UNUSED_ATTR tAVCT_LCB_EVT* p_data) {
   uint16_t result = AVCT_RESULT_FAIL;
 
-  BTM_SetOutService(p_lcb->peer_addr, BTM_SEC_SERVICE_AVCTP, 0);
-  /* call l2cap connect req */
   p_lcb->ch_state = AVCT_CH_CONN;
-  p_lcb->ch_lcid = L2CA_ConnectReq(AVCT_PSM, p_lcb->peer_addr);
+  p_lcb->ch_lcid =
+      L2CA_ConnectReq2(AVCT_PSM, p_lcb->peer_addr, BTA_SEC_AUTHENTICATE);
   if (p_lcb->ch_lcid == 0) {
     /* if connect req failed, send ourselves close event */
     tAVCT_LCB_EVT avct_lcb_evt;
index 78c6f81..d108804 100644 (file)
@@ -366,6 +366,8 @@ extern uint16_t L2CA_AllocateLePSM(void);
  ******************************************************************************/
 extern void L2CA_FreeLePSM(uint16_t psm);
 
+extern uint16_t L2CA_ConnectReq2(uint16_t psm, const RawAddress& p_bd_addr,
+                                 uint16_t sec_level);
 /*******************************************************************************
  *
  * Function         L2CA_ConnectReq
@@ -395,6 +397,10 @@ extern uint16_t L2CA_ConnectReq(uint16_t psm, const RawAddress& p_bd_addr);
 extern bool L2CA_ConnectRsp(const RawAddress& p_bd_addr, uint8_t id,
                             uint16_t lcid, uint16_t result, uint16_t status);
 
+uint16_t L2CA_ErtmConnectReq2(uint16_t psm, const RawAddress& p_bd_addr,
+                              tL2CAP_ERTM_INFO* p_ertm_info,
+                              uint16_t sec_level);
+
 /*******************************************************************************
  *
  * Function         L2CA_ErtmConnectReq
index 573c332..f4beec4 100644 (file)
@@ -292,6 +292,12 @@ void L2CA_FreeLePSM(uint16_t psm) {
   l2cb.le_dyn_psm_assigned[psm - LE_DYNAMIC_PSM_START] = false;
 }
 
+uint16_t L2CA_ConnectReq2(uint16_t psm, const RawAddress& p_bd_addr,
+                          uint16_t sec_level) {
+  BTM_SetSecurityLevel(true, "", 0, sec_level, psm, 0, 0);
+  return L2CA_ConnectReq(psm, p_bd_addr);
+}
+
 /*******************************************************************************
  *
  * Function         L2CA_ConnectReq
@@ -313,6 +319,13 @@ uint16_t L2CA_ConnectReq(uint16_t psm, const RawAddress& p_bd_addr) {
   return L2CA_ErtmConnectReq(psm, p_bd_addr, nullptr);
 }
 
+uint16_t L2CA_ErtmConnectReq2(uint16_t psm, const RawAddress& p_bd_addr,
+                              tL2CAP_ERTM_INFO* p_ertm_info,
+                              uint16_t sec_level) {
+  BTM_SetSecurityLevel(true, "", 0, sec_level, psm, 0, 0);
+  return L2CA_ErtmConnectReq(psm, p_bd_addr, p_ertm_info);
+}
+
 /*******************************************************************************
  *
  * Function         L2CA_ErtmConnectReq