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

Commit b5db0221 authored by Hemant Gupta's avatar Hemant Gupta Committed by Andre Eisenbach
Browse files

HID: Handle collisions during incoming and outgoing connections

- 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.

Change-Id: I6fb0c6156482d2da41ca0d2d280091d73c27f292
parent 7fb9fbae
Loading
Loading
Loading
Loading
+19 −7
Original line number Diff line number Diff line
@@ -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;
}

/*******************************************************************************