Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4e73fcdb authored by Zach Johnson's avatar Zach Johnson Committed by Automerger Merge Worker
Browse files

Add L2CA_Register2, which does security for you am: d511b666

Original change: https://android-review.googlesource.com/c/platform/system/bt/+/1410831

Change-Id: Ie446005c34cfd9b023b39c220807c53aff2f8e1c
parents aca70a45 d511b666
Loading
Loading
Loading
Loading
+6 −4
Original line number Original line Diff line number Diff line
@@ -64,8 +64,9 @@ void AVCT_Register(uint16_t mtu, UNUSED_ATTR uint16_t mtu_br) {
  avct_cb.mtu = mtu;
  avct_cb.mtu = mtu;


  /* register PSM with L2CAP */
  /* register PSM with L2CAP */
  L2CA_Register(AVCT_PSM, (tL2CAP_APPL_INFO*)&avct_l2c_appl,
  L2CA_Register2(AVCT_PSM, (tL2CAP_APPL_INFO*)&avct_l2c_appl,
                true /* enable_snoop */, nullptr, avct_cb.mtu);
                 true /* enable_snoop */, nullptr, avct_cb.mtu,
                 BTA_SEC_AUTHENTICATE);


  BTM_SimpleSetSecurityLevel(BTM_SEC_SERVICE_AVCTP, BTA_SEC_AUTHENTICATE,
  BTM_SimpleSetSecurityLevel(BTM_SEC_SERVICE_AVCTP, BTA_SEC_AUTHENTICATE,
                             AVCT_PSM);
                             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;
  if (mtu_br < AVCT_MIN_BROWSE_MTU) mtu_br = AVCT_MIN_BROWSE_MTU;
  avct_cb.mtu_br = mtu_br;
  avct_cb.mtu_br = mtu_br;


  L2CA_Register(AVCT_BR_PSM, (tL2CAP_APPL_INFO*)&avct_l2c_br_appl,
  L2CA_Register2(AVCT_BR_PSM, (tL2CAP_APPL_INFO*)&avct_l2c_br_appl,
                true /*enable_snoop*/, &ertm_info, avct_cb.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
  /* AVCTP browsing channel uses the same security service as AVCTP control
   * channel */
   * channel */
+6 −5
Original line number Original line Diff line number Diff line
@@ -772,15 +772,16 @@ tHID_STATUS hidd_conn_reg(void) {
    return (HID_ERR_NO_RESOURCES);
    return (HID_ERR_NO_RESOURCES);
  }
  }


  if (!L2CA_Register(HID_PSM_CONTROL, (tL2CAP_APPL_INFO*)&dev_reg_info,
  if (!L2CA_Register2(HID_PSM_CONTROL, (tL2CAP_APPL_INFO*)&dev_reg_info,
                     false /* enable_snoop */, nullptr, hd_cb.l2cap_cfg.mtu)) {
                      false /* enable_snoop */, nullptr, hd_cb.l2cap_cfg.mtu,
                      BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT)) {
    HIDD_TRACE_ERROR("HID Control (device) registration failed");
    HIDD_TRACE_ERROR("HID Control (device) registration failed");
    return (HID_ERR_L2CAP_FAILED);
    return (HID_ERR_L2CAP_FAILED);
  }
  }


  if (!L2CA_Register(HID_PSM_INTERRUPT, (tL2CAP_APPL_INFO*)&dev_reg_info,
  if (!L2CA_Register2(HID_PSM_INTERRUPT, (tL2CAP_APPL_INFO*)&dev_reg_info,
                      false /* enable_snoop */, nullptr,
                      false /* enable_snoop */, nullptr,
                     hd_cb.l2cap_intr_cfg.mtu)) {
                      hd_cb.l2cap_intr_cfg.mtu, BTM_SEC_NONE)) {
    L2CA_Deregister(HID_PSM_CONTROL);
    L2CA_Deregister(HID_PSM_CONTROL);
    HIDD_TRACE_ERROR("HID Interrupt (device) registration failed");
    HIDD_TRACE_ERROR("HID Interrupt (device) registration failed");
    return (HID_ERR_L2CAP_FAILED);
    return (HID_ERR_L2CAP_FAILED);
+5 −0
Original line number Original line Diff line number Diff line
@@ -296,6 +296,11 @@ void l2c_free();
 *  External Function Declarations
 *  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
 * Function         L2CA_Register
+10 −0
Original line number Original line Diff line number Diff line
@@ -29,6 +29,7 @@
#include <cstdint>
#include <cstdint>
#include <string>
#include <string>


#include "btm_sec.h"
#include "device/include/controller.h"  // TODO Remove
#include "device/include/controller.h"  // TODO Remove
#include "main/shim/l2c_api.h"
#include "main/shim/l2c_api.h"
#include "main/shim/shim.h"
#include "main/shim/shim.h"
@@ -41,6 +42,15 @@ void btsnd_hcic_enhanced_flush(uint16_t handle,


using base::StringPrintf;
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
 * Function         L2CA_Register
+2 −2
Original line number Original line Diff line number Diff line
@@ -106,8 +106,8 @@ void sdp_init(void) {
  sdp_cb.reg_info.pL2CA_TxComplete_Cb = NULL;
  sdp_cb.reg_info.pL2CA_TxComplete_Cb = NULL;


  /* Now, register with L2CAP */
  /* Now, register with L2CAP */
  if (!L2CA_Register(SDP_PSM, &sdp_cb.reg_info, true /* enable_snoop */,
  if (!L2CA_Register2(SDP_PSM, &sdp_cb.reg_info, true /* enable_snoop */,
                     nullptr, sdp_cb.l2cap_my_cfg.mtu)) {
                      nullptr, sdp_cb.l2cap_my_cfg.mtu, BTM_SEC_NONE)) {
    SDP_TRACE_ERROR("SDP Registration failed");
    SDP_TRACE_ERROR("SDP Registration failed");
  }
  }
}
}