OSDN Git Service

HID: Handle collisions during incoming and outgoing connections
authorHemant Gupta <hemantg@codeaurora.org>
Fri, 11 Dec 2015 14:39:22 +0000 (20:09 +0530)
committerAndre Eisenbach <eisenbach@google.com>
Fri, 25 Mar 2016 20:10:20 +0000 (13:10 -0700)
- This patch handles cases when incoming HID connection is in progress, and
  there is an outgoing connection attempt from upper layers. This was leading
  to a case when ougoing connection would fail as connection was already in
  progress, which triggered cleanup of connection states, which was not proper
  leading to issues in future connection attempts, as disconnection during
  ongoing connection was not handled properly in existing code.

- Reset the incoming flags during open failure to prevent any possible issues
  during further outgoing connections.

Bug: 27852645
Change-Id: I6fb0c6156482d2da41ca0d2d280091d73c27f292

bta/hh/bta_hh_act.c

index 034ade5..f799e67 100644 (file)
@@ -443,20 +443,29 @@ void bta_hh_sdp_cmpl(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data)
             HID_HostSetSecurityLevel("", p_cb->sec_mask);
 
             /* open HID connection */
-            if ((ret = HID_HostOpenDev (p_cb->hid_handle)) != HID_SUCCESS)
+            ret = HID_HostOpenDev (p_cb->hid_handle);
+            APPL_TRACE_DEBUG ("%s: HID_HostOpenDev returned=%d", __func__, ret);
+            if (ret == HID_SUCCESS || ret == HID_ERR_ALREADY_CONN)
+            {
+                status = BTA_HH_OK;
+            }
+            else if (ret == HID_ERR_CONN_IN_PROCESS)
+            {
+                /* Connection already in progress, return from here, SDP
+                 * will be performed after connection is completed.
+                 */
+                APPL_TRACE_DEBUG ("%s: connection already in progress", __func__);
+                return;
+            }
+            else
             {
 #if BTA_HH_DEBUG
-                APPL_TRACE_DEBUG ("bta_hh_sdp_cmpl:  HID_HostOpenDev failed: \
-                    Status 0x%2X",ret);
+                APPL_TRACE_DEBUG ("%s: HID_HostOpenDev failed: Status 0x%2X", __func__, ret);
 #endif
                 /* open fail, remove device from management device list */
                 HID_HostRemoveDev( p_cb->hid_handle);
                 status = BTA_HH_ERR;
             }
-            else
-            {
-                status = BTA_HH_OK;
-            }
         }
         else /* incoming connection SDP finish */
         {
@@ -840,6 +849,9 @@ void bta_hh_open_failure(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data)
         bta_hh_disc_cmpl();
     }
 
+    /* Error in opening hid connection, reset flags */
+    p_cb->incoming_conn = FALSE;
+    p_cb->incoming_hid_handle = BTA_HH_INVALID_HANDLE;
 }
 
 /*******************************************************************************