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

Commit cc9ae7e4 authored by Hansong Zhang's avatar Hansong Zhang
Browse files

HID Host: Clean up sec mask

Bug: 159815595
Tag: #refactor
Test: compile & verify basic functions working
Change-Id: Ib7d747de37343d8a7983cb3d7f24d472963aa9cf
parent 056c90a7
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
@@ -75,7 +75,7 @@ void bta_hh_api_enable(tBTA_HH_DATA* p_data) {

  memset(&bta_hh_cb, 0, sizeof(tBTA_HH_CB));

  HID_HostSetSecurityLevel("", p_data->api_enable.sec_mask);
  HID_HostSetSecurityLevel("");

  /* Register with L2CAP */
  if (HID_HostRegister(bta_hh_cback) == HID_SUCCESS) {
@@ -184,7 +184,7 @@ static void bta_hh_sdp_cback(uint16_t result, uint16_t attr_mask,
  /* make sure sdp succeeded and hh has not been disabled */
  if ((result == SDP_SUCCESS) && (p_cb != NULL)) {
    /* security is required for the connection, add attr_mask bit*/
    if (p_cb->sec_mask) attr_mask |= HID_SEC_REQUIRED;
    attr_mask |= HID_SEC_REQUIRED;

#if (BTA_HH_DEBUG == TRUE)
    APPL_TRACE_EVENT("%s: p_cb: %d result 0x%02x, attr_mask 0x%02x, handle %x",
@@ -312,7 +312,6 @@ void bta_hh_start_sdp(tBTA_HH_DEV_CB* p_cb, tBTA_HH_DATA* p_data) {
  tBTA_HH_STATUS status = BTA_HH_ERR_SDP;
  uint8_t hdl;

  p_cb->sec_mask = p_data->api_conn.sec_mask;
  p_cb->mode = p_data->api_conn.mode;
  bta_hh_cb.p_cur = p_cb;

@@ -415,7 +414,7 @@ void bta_hh_sdp_cmpl(tBTA_HH_DEV_CB* p_cb, tBTA_HH_DATA* p_data) {
    if (!p_cb->incoming_conn) {
      tHID_STATUS ret;
      /* set security level */
      HID_HostSetSecurityLevel("", p_cb->sec_mask);
      HID_HostSetSecurityLevel("");

      /* open HID connection */
      ret = HID_HostOpenDev(p_cb->hid_handle);
+0 −2
Original line number Diff line number Diff line
@@ -68,7 +68,6 @@ void BTA_HhEnable(tBTA_HH_CBACK* p_cback) {

  p_buf->hdr.event = BTA_HH_API_ENABLE_EVT;
  p_buf->p_cback = p_cback;
  p_buf->sec_mask = BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT;

  bta_sys_sendmsg(p_buf);
}
@@ -127,7 +126,6 @@ void BTA_HhOpen(const RawAddress& dev_bda) {

  p_buf->hdr.event = BTA_HH_API_OPEN_EVT;
  p_buf->hdr.layer_specific = BTA_HH_INVALID_HANDLE;
  p_buf->sec_mask = BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT;
  p_buf->mode = mode;
  p_buf->bd_addr = dev_bda;

+0 −3
Original line number Diff line number Diff line
@@ -108,7 +108,6 @@ typedef struct {
/* data type for BTA_HH_API_ENABLE_EVT */
typedef struct {
  BT_HDR hdr;
  uint8_t sec_mask;
  uint8_t service_name[BTA_SERVICE_NAME_LEN + 1];
  tBTA_HH_CBACK* p_cback;
} tBTA_HH_API_ENABLE;
@@ -116,7 +115,6 @@ typedef struct {
typedef struct {
  BT_HDR hdr;
  RawAddress bd_addr;
  uint8_t sec_mask;
  tBTA_HH_PROTO_MODE mode;
} tBTA_HH_API_CONN;

@@ -222,7 +220,6 @@ typedef struct {
  uint16_t w4_evt;                 /* W4_handshake event name */
  uint8_t index;                   /* index number referenced to handle index */
  uint8_t sub_class;               /* Cod sub class */
  uint8_t sec_mask;                /* security mask */
  uint8_t app_id;                  /* application ID for this connection */
  uint8_t hid_handle;          /* device handle : low 4 bits for regular HID:
                                  HID_HOST_MAX_DEVICES can not exceed 15;
+1 −5
Original line number Diff line number Diff line
@@ -1092,16 +1092,12 @@ void bta_hh_start_security(tBTA_HH_DEV_CB* p_cb,
                      NULL, BTM_BLE_SEC_ENCRYPT);
  }
  /* unbonded device, report security error here */
  else if (p_cb->sec_mask != BTA_SEC_NONE) {
  else {
    p_cb->status = BTA_HH_ERR_AUTH_FAILED;
    bta_hh_clear_service_cache(p_cb);
    BTM_SetEncryption(p_cb->addr, BT_TRANSPORT_LE, bta_hh_le_encrypt_cback,
                      NULL, BTM_BLE_SEC_ENCRYPT_NO_MITM);
  }
  /* otherwise let it go through */
  else {
    bta_hh_sm_execute(p_cb, BTA_HH_ENC_CMPL_EVT, NULL);
  }
}

/*******************************************************************************
+5 −2
Original line number Diff line number Diff line
@@ -463,8 +463,11 @@ tHID_STATUS HID_HostCloseDev(uint8_t dev_handle) {
  return hidh_conn_disconnect(dev_handle);
}

tHID_STATUS HID_HostSetSecurityLevel(const char serv_name[], uint8_t sec_lvl) {
  if (!BTM_SimpleSetSecurityLevel(BTM_SEC_SERVICE_HIDH_SEC_CTRL, sec_lvl,
tHID_STATUS HID_HostSetSecurityLevel(const char serv_name[]) {
  if (!BTM_SimpleSetSecurityLevel(BTM_SEC_SERVICE_HIDH_SEC_CTRL,
                                  BTM_SEC_IN_AUTHENTICATE | BTM_SEC_IN_ENCRYPT |
                                      BTM_SEC_OUT_AUTHENTICATE |
                                      BTM_SEC_OUT_ENCRYPT,
                                  HID_PSM_CONTROL)) {
    HIDH_TRACE_ERROR("Security Registration 1 failed");
    return (HID_ERR_NO_RESOURCES);
Loading