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

Commit fd7b785c authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "HIDH: Use l2cap to enforce security"

parents 9cbe1bb9 90bb4cf0
Loading
Loading
Loading
Loading
+4 −22
Original line number Diff line number Diff line
@@ -463,43 +463,25 @@ tHID_STATUS HID_HostCloseDev(uint8_t dev_handle) {

tHID_STATUS HID_HostSetSecurityLevel(const char serv_name[], uint8_t sec_lvl) {
  if (!BTM_SetSecurityLevel(false, serv_name, BTM_SEC_SERVICE_HIDH_SEC_CTRL,
                            sec_lvl, HID_PSM_CONTROL, BTM_SEC_PROTO_HID,
                            HID_SEC_CHN)) {
                            sec_lvl, HID_PSM_CONTROL, 0, 0)) {
    HIDH_TRACE_ERROR("Security Registration 1 failed");
    return (HID_ERR_NO_RESOURCES);
  }

  if (!BTM_SetSecurityLevel(true, serv_name, BTM_SEC_SERVICE_HIDH_SEC_CTRL,
                            sec_lvl, HID_PSM_CONTROL, BTM_SEC_PROTO_HID,
                            HID_SEC_CHN)) {
                            sec_lvl, HID_PSM_CONTROL, 0, 0)) {
    HIDH_TRACE_ERROR("Security Registration 2 failed");
    return (HID_ERR_NO_RESOURCES);
  }

  if (!BTM_SetSecurityLevel(false, serv_name, BTM_SEC_SERVICE_HIDH_NOSEC_CTRL,
                            BTM_SEC_NONE, HID_PSM_CONTROL, BTM_SEC_PROTO_HID,
                            HID_NOSEC_CHN)) {
    HIDH_TRACE_ERROR("Security Registration 3 failed");
    return (HID_ERR_NO_RESOURCES);
  }

  if (!BTM_SetSecurityLevel(true, serv_name, BTM_SEC_SERVICE_HIDH_NOSEC_CTRL,
                            BTM_SEC_NONE, HID_PSM_CONTROL, BTM_SEC_PROTO_HID,
                            HID_NOSEC_CHN)) {
    HIDH_TRACE_ERROR("Security Registration 4 failed");
    return (HID_ERR_NO_RESOURCES);
  }

  if (!BTM_SetSecurityLevel(true, serv_name, BTM_SEC_SERVICE_HIDH_INTR,
                            BTM_SEC_NONE, HID_PSM_INTERRUPT, BTM_SEC_PROTO_HID,
                            0)) {
                            BTM_SEC_NONE, HID_PSM_INTERRUPT, 0, 0)) {
    HIDH_TRACE_ERROR("Security Registration 5 failed");
    return (HID_ERR_NO_RESOURCES);
  }

  if (!BTM_SetSecurityLevel(false, serv_name, BTM_SEC_SERVICE_HIDH_INTR,
                            BTM_SEC_NONE, HID_PSM_INTERRUPT, BTM_SEC_PROTO_HID,
                            0)) {
                            BTM_SEC_NONE, HID_PSM_INTERRUPT, 0, 0)) {
    HIDH_TRACE_ERROR("Security Registration 6 failed");
    return (HID_ERR_NO_RESOURCES);
  }
+6 −12
Original line number Diff line number Diff line
@@ -261,14 +261,9 @@ static void hidh_l2cif_connect_ind(const RawAddress& bd_addr,
                                                  to 'connection failure' */

    p_hcon->conn_state = HID_CONN_STATE_SECURITY;
    if (btm_sec_mx_access_request(
            p_dev->addr, HID_PSM_CONTROL, false, BTM_SEC_PROTO_HID,
            (p_dev->attr_mask & HID_SEC_REQUIRED) ? HID_SEC_CHN : HID_NOSEC_CHN,
            &hidh_sec_check_complete_term, p_dev) == BTM_CMD_STARTED) {
      L2CA_ConnectRsp(bd_addr, l2cap_id, l2cap_cid, L2CAP_CONN_PENDING,
                      L2CAP_CONN_OK);
    }

    // Assume security check ok
    hidh_sec_check_complete_term(nullptr, BT_TRANSPORT_BR_EDR, p_dev,
                                 BTM_SUCCESS);
    return;
  }

@@ -428,10 +423,9 @@ static void hidh_l2cif_connect_cfm(uint16_t l2cap_cid, uint16_t result) {
                                                  then set CLOSE_EVT reason code
                                                  to "connection failure" */

    btm_sec_mx_access_request(
        p_dev->addr, HID_PSM_CONTROL, true, BTM_SEC_PROTO_HID,
        (p_dev->attr_mask & HID_SEC_REQUIRED) ? HID_SEC_CHN : HID_NOSEC_CHN,
        &hidh_sec_check_complete_orig, p_dev);
    // Assume security check ok
    hidh_sec_check_complete_orig(nullptr, BT_TRANSPORT_BR_EDR, p_dev,
                                 BTM_SUCCESS);
  } else {
    p_hcon->conn_state = HID_CONN_STATE_CONFIG;
    /* Send a Configuration Request. */