LE: UPF 45 bug fixes

This change fixes the following issues:
- Second GATT-over-BR/EDR channel cannot be established when there
  already is an existing GATT-over-BR/EDR channel
- If encryption fails for an LE connection due to a missing key,
  the security state is not being cleared and blocks all further
  security processing
- When DM discovery of an LE Peripheral device fails with a
  connection timeout, no further discovery requests can be made
- GATT service discovery can get into endless loop when duplicate descriptor
  definitions are found on the remote device
- When GATT over BR/EDR fails, BTA does not give a connection
  callback to the application initiating the connection
- BR/EDR connection to remote platform does not generate API callbacks
- Stack crash discovered during UPF after remote disconnects
- The host is sending HCI disconnect to invalid HCI handle when
  SMP fails because of a connection timeout
- Possible race condition:
  If a disconnect is immediately followed by a connection complete,
  the connection complete cannot be processed in the BTA GATT state
  machine
- Write Complete event is not triggered for Prepare Write requests

Change-Id: I539cdedd68007818ff4f0d0213cee1c913f72d0f

Conflicts:
	bta/gatt/bta_gatts_act.c
diff --git a/stack/btm/btm_ble_gap.c b/stack/btm/btm_ble_gap.c
index 7cef5f2..387f661 100644
--- a/stack/btm/btm_ble_gap.c
+++ b/stack/btm/btm_ble_gap.c
@@ -363,8 +363,7 @@
 BOOLEAN BTM_BleUpdateBgConnDev(BOOLEAN add_remove, BD_ADDR   remote_bda)
 {
     BOOLEAN ret = TRUE;
-    UINT8   dev_wl_type = BTM_BLE_WL_INIT;
-
+    UINT8   dev_wl_type = 0;
     BTM_TRACE_EVENT0 (" BTM_BleUpdateBgConnDev");
 
     /* update white list */
@@ -2033,10 +2032,6 @@
         btm_ble_set_connectability ( btm_cb.ble_ctr_cb.inq_var.connectable_mode );
     }
 
-    /* if connection complete */
-    if (conn_cancel || link_role != HCI_ROLE_UNKNOWN)
-        btm_ble_set_conn_st(BLE_CONN_IDLE);
-
     if (btm_ble_get_conn_st() == BLE_CONN_IDLE)
     {
         if (!btm_send_pending_direct_conn())
@@ -2074,7 +2069,7 @@
     /* for background connection, reset connection params to be undefined */
     p_cb->scan_int = p_cb->scan_win = BTM_BLE_CONN_PARAM_UNDEF;
 
-    p_cb->inq_var.evt_type = BTM_BLE_UNKNOWN_EVT;
+    p_cb->inq_var.evt_type = BTM_BLE_NON_CONNECT_EVT;
 }
 
 #endif  /* BLE_INCLUDED */