/******************************************************************************* ** ** Function hidh_sec_check_complete_orig ** ** Description This function checks to see if security procedures are being ** carried out or not.. ** ** Returns void ** *******************************************************************************/ void hidh_sec_check_complete_orig (BD_ADDR bd_addr, void *p_ref_data, UINT8 res) { tHID_HOST_DEV_CTB *p_dev = (tHID_HOST_DEV_CTB *) p_ref_data; UINT8 dhandle; #if (HID_HOST_MAX_CONN_RETRY > 0) UINT32 cb_res = HID_ERR_AUTH_FAILED; #endif UINT32 reason; dhandle = ((UINT32)p_dev - (UINT32)&(hh_cb.devices[0]))/ sizeof(tHID_HOST_DEV_CTB); if( res == BTM_SUCCESS && p_dev->conn.conn_state == HID_CONN_STATE_SECURITY ) { HIDH_TRACE_EVENT0 ("HID-Host Originator security pass."); p_dev->conn.disc_reason = HID_SUCCESS; /* Authentication passed. Reset disc_reason (from HID_ERR_AUTH_FAILED) */ /* Check if L2CAP started the connection process for interrupt channel */ if ((p_dev->conn.intr_cid = L2CA_ConnectReq (HID_PSM_INTERRUPT, hh_cb.devices[dhandle].addr)) == 0) { HIDH_TRACE_WARNING0 ("HID-Host INTR Originate failed"); reason = HID_L2CAP_REQ_FAIL ; hidh_conn_disconnect (dhandle); hh_cb.callback( dhandle, hh_cb.devices[dhandle].addr, HID_HDEV_EVT_CLOSE, reason, NULL ) ; return; } else { /* Transition to the next appropriate state, waiting for connection confirm on control channel. */ p_dev->conn.conn_state = HID_CONN_STATE_CONNECTING_INTR; } } if( res != BTM_SUCCESS && p_dev->conn.conn_state == HID_CONN_STATE_SECURITY ) { #if (HID_HOST_MAX_CONN_RETRY > 0) if( res == BTM_DEVICE_TIMEOUT ) { if( p_dev->conn_tries <= HID_HOST_MAX_CONN_RETRY ) { hidh_conn_retry (dhandle); return; } else cb_res = HID_L2CAP_CONN_FAIL | HCI_ERR_PAGE_TIMEOUT ; } #endif p_dev->conn.disc_reason = HID_ERR_AUTH_FAILED; /* Save reason for disconnecting */ hidh_conn_disconnect(dhandle); } }
/******************************************************************************* ** ** Function hidh_sec_check_complete_orig ** ** Description This function checks to see if security procedures are being ** carried out or not.. ** ** Returns void ** *******************************************************************************/ void hidh_sec_check_complete_orig (BD_ADDR bd_addr, tBT_TRANSPORT transport, void *p_ref_data, UINT8 res) { tHID_HOST_DEV_CTB *p_dev = (tHID_HOST_DEV_CTB *) p_ref_data; UINT8 dhandle; UNUSED(bd_addr); UNUSED (transport); // TODO(armansito): This kind of math to determine a device handle is way // too dirty and unnecessary. Why can't |p_dev| store it's handle? dhandle = (PTR_TO_UINT(p_dev) - PTR_TO_UINT(&(hh_cb.devices[0])))/ sizeof(tHID_HOST_DEV_CTB); if( res == BTM_SUCCESS && p_dev->conn.conn_state == HID_CONN_STATE_SECURITY ) { HIDH_TRACE_EVENT ("HID-Host Originator security pass."); p_dev->conn.disc_reason = HID_SUCCESS; /* Authentication passed. Reset disc_reason (from HID_ERR_AUTH_FAILED) */ /* Transition to the next appropriate state, configuration */ p_dev->conn.conn_state = HID_CONN_STATE_CONFIG; L2CA_ConfigReq (p_dev->conn.ctrl_cid, &hh_cb.l2cap_cfg); HIDH_TRACE_EVENT ("HID-Host Got Control conn cnf, sent cfg req, CID: 0x%x", p_dev->conn.ctrl_cid); } if( res != BTM_SUCCESS && p_dev->conn.conn_state == HID_CONN_STATE_SECURITY ) { #if (HID_HOST_MAX_CONN_RETRY > 0) if( res == BTM_DEVICE_TIMEOUT ) { if( p_dev->conn_tries <= HID_HOST_MAX_CONN_RETRY ) { hidh_conn_retry (dhandle); return; } } #endif p_dev->conn.disc_reason = HID_ERR_AUTH_FAILED; /* Save reason for disconnecting */ hidh_conn_disconnect(dhandle); } }
/******************************************************************************* ** ** Function hidh_l2cif_connect_cfm ** ** Description This function handles the connect confirm events ** from L2CAP. This is the case when we are acting as a ** client and have sent a connect request. ** ** Returns void ** *******************************************************************************/ static void hidh_l2cif_connect_cfm (UINT16 l2cap_cid, UINT16 result) { UINT8 dhandle; tHID_CONN *p_hcon = NULL; UINT32 reason; tHID_HOST_DEV_CTB *p_dev = NULL; /* Find CCB based on CID, and verify we are in a state to accept this message */ if( (dhandle = find_conn_by_cid(l2cap_cid)) < HID_HOST_MAX_DEVICES ) { p_dev = &hh_cb.devices[dhandle]; p_hcon = &hh_cb.devices[dhandle].conn; } if ((p_hcon == NULL) || (!(p_hcon->conn_flags & HID_CONN_FLAGS_IS_ORIG)) || ((l2cap_cid == p_hcon->ctrl_cid) && (p_hcon->conn_state != HID_CONN_STATE_CONNECTING_CTRL)) || ((l2cap_cid == p_hcon->intr_cid) && (p_hcon->conn_state != HID_CONN_STATE_CONNECTING_INTR) && (p_hcon->conn_state != HID_CONN_STATE_DISCONNECTING))) { HIDH_TRACE_WARNING ("HID-Host Rcvd unexpected conn cnf, CID 0x%x ", l2cap_cid); return; } if (result != L2CAP_CONN_OK) { if (l2cap_cid == p_hcon->ctrl_cid) p_hcon->ctrl_cid = 0; else p_hcon->intr_cid = 0; hidh_conn_disconnect(dhandle); #if (HID_HOST_MAX_CONN_RETRY > 0) if( (hh_cb.devices[dhandle].conn_tries <= HID_HOST_MAX_CONN_RETRY) && (result == HCI_ERR_CONNECTION_TOUT || result == HCI_ERR_UNSPECIFIED || result == HCI_ERR_PAGE_TIMEOUT) ) { hidh_conn_retry(dhandle); } else #endif { reason = HID_L2CAP_CONN_FAIL | (UINT32) result ; HIDH_TRACE_WARNING ("HID-Host: l2cap connect failed, reason = %d", reason); hh_cb.callback( dhandle, hh_cb.devices[dhandle].addr, HID_HDEV_EVT_CLOSE, reason, NULL ) ; } return; } /* receive Control Channel connect confirmation */ if (l2cap_cid == p_hcon->ctrl_cid) { /* check security requirement */ p_hcon->conn_state = HID_CONN_STATE_SECURITY; p_hcon->disc_reason = HID_L2CAP_CONN_FAIL; /* In case disconnection occurs before security is completed, then set CLOSE_EVT reason code to "connection failure" */ if (!interop_addr_match(INTEROP_DISABLE_AUTH_FOR_HID_POINTING, (bt_bdaddr_t *)p_dev->addr)) { 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); } else { /* device is blacklisted, don't perform authentication */ hidh_sec_check_complete_orig(p_dev->addr, BT_TRANSPORT_BR_EDR, p_dev, BTM_SUCCESS); } } else { p_hcon->conn_state = HID_CONN_STATE_CONFIG; /* Send a Configuration Request. */ L2CA_ConfigReq (l2cap_cid, &hh_cb.l2cap_cfg); HIDH_TRACE_EVENT ("HID-Host got Interrupt conn cnf, sent cfg req, CID: 0x%x", l2cap_cid); } return; }