Serialize remote version query over LE

Some devices (ex. Nexus Player remote) do not take well to having the
remote version queried while a remote feature request is also sent and
subsequently fail encryption.

This patch serializes the query of the remote version and requires both
remote features and the remote version to be read before calling a
connection established.

Bug: 25357767
Change-Id: Ie70eea241b47b81778d8e0df47f3a8f376316932
diff --git a/stack/btm/btm_acl.c b/stack/btm/btm_acl.c
index 05f665b..b09f91b 100644
--- a/stack/btm/btm_acl.c
+++ b/stack/btm/btm_acl.c
@@ -268,8 +268,8 @@
             if (transport == BT_TRANSPORT_BR_EDR)
             {
                 btsnd_hcic_read_rmt_clk_offset (p->hci_handle);
+                btsnd_hcic_rmt_ver_req (p->hci_handle);
             }
-            btsnd_hcic_rmt_ver_req (p->hci_handle);
             p_dev_rec = btm_find_dev_by_handle (hci_handle);
 
 #if (BLE_INCLUDED == TRUE)
@@ -911,21 +911,25 @@
     UINT16            handle;
     int               xx;
     BTM_TRACE_DEBUG ("btm_read_remote_version_complete");
-    STREAM_TO_UINT8  (status, p);
-    if (status == HCI_SUCCESS)
-    {
-        STREAM_TO_UINT16 (handle, p);
 
-        /* Look up the connection by handle and copy features */
-        for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, p_acl_cb++)
+    STREAM_TO_UINT8  (status, p);
+    STREAM_TO_UINT16 (handle, p);
+
+    /* Look up the connection by handle and copy features */
+    for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, p_acl_cb++)
+    {
+        if ((p_acl_cb->in_use) && (p_acl_cb->hci_handle == handle))
         {
-            if ((p_acl_cb->in_use) && (p_acl_cb->hci_handle == handle))
+            if (status == HCI_SUCCESS)
             {
                 STREAM_TO_UINT8  (p_acl_cb->lmp_version, p);
                 STREAM_TO_UINT16 (p_acl_cb->manufacturer, p);
                 STREAM_TO_UINT16 (p_acl_cb->lmp_subversion, p);
-                break;
             }
+
+            if (p_acl_cb->transport == BT_TRANSPORT_LE)
+                l2cble_notify_le_connection (p_acl_cb->remote_addr);
+            break;
         }
     }
 }
diff --git a/stack/btm/btm_ble_gap.c b/stack/btm/btm_ble_gap.c
index f841148..3b85fbb 100644
--- a/stack/btm/btm_ble_gap.c
+++ b/stack/btm/btm_ble_gap.c
@@ -3215,8 +3215,7 @@
             if ((p_acl_cb->in_use) && (p_acl_cb->hci_handle == handle))
             {
                 STREAM_TO_ARRAY(p_acl_cb->peer_le_features, p, BD_FEATURES_LEN);
-                /*notify link up here */
-                l2cble_notify_le_connection (p_acl_cb->remote_addr);
+                btsnd_hcic_rmt_ver_req (p_acl_cb->hci_handle);
                 break;
             }
         }
diff --git a/stack/smp/smp_act.c b/stack/smp/smp_act.c
index 2423cad..0196261 100644
--- a/stack/smp/smp_act.c
+++ b/stack/smp/smp_act.c
@@ -190,6 +190,7 @@
                             (const bt_bdaddr_t *)&p_cb->pairing_bda))
                     {
                         p_cb->loc_auth_req &= ~SMP_KP_SUPPORT_BIT;
+                        p_cb->loc_auth_req &= ~SMP_SC_SUPPORT_BIT;
                         p_cb->local_i_key &= ~SMP_SEC_KEY_TYPE_LK;
                         p_cb->local_r_key &= ~SMP_SEC_KEY_TYPE_LK;
                     }