Fixes random host disconnection after establishing connection

Host starts encryption twice when the remote device is
already paired. The host sends disconnect when the
second encryption attempt returns failure. This fix
avoids duplicate encryption attempt.

bug:11450719
Change-Id: I8ec5c4a953180ec17585aece757810421bc44aae
diff --git a/stack/btm/btm_ble.c b/stack/btm/btm_ble.c
index ad5663f..24fd197 100644
--- a/stack/btm/btm_ble.c
+++ b/stack/btm/btm_ble.c
@@ -1177,12 +1177,18 @@
         case BTM_BLE_SEC_ENCRYPT:
             if (link_role == BTM_ROLE_MASTER)
             {
-                /* start link layer encryption using the security info stored */
-                if (btm_ble_start_encrypt(bd_addr, FALSE, NULL))
-                {
-                    p_rec->sec_state = BTM_SEC_STATE_ENCRYPTING;
+                if(p_rec->sec_state == BTM_SEC_STATE_ENCRYPTING) {
+                    BTM_TRACE_DEBUG0 ("State is already encrypting::");
                     cmd = BTM_CMD_STARTED;
                 }
+                else {
+                    /* start link layer encryption using the security info stored */
+                    if (btm_ble_start_encrypt(bd_addr, FALSE, NULL))
+                    {
+                        p_rec->sec_state = BTM_SEC_STATE_ENCRYPTING;
+                        cmd = BTM_CMD_STARTED;
+                    }
+                }
                 break;
             }
             /* if salve role then fall through to call SMP_Pair below which will send a