Fix for p2p connection failure.

P2P connection was failing because of ASSOC_REJECT, this was because
GO was doing a channel switch due to station scan issued from APPS.
To address this, a timer of 10 sec is started after device starts
beaconing and scan is blocked during this period to avoid channel
switch.

CRs-Fixed: 489322
Change-Id: Id04a177e41fc1377762ef19554151d6985b2fc5a
diff --git a/CORE/HDD/inc/wlan_hdd_main.h b/CORE/HDD/inc/wlan_hdd_main.h
index 60304fa..3603dd8 100644
--- a/CORE/HDD/inc/wlan_hdd_main.h
+++ b/CORE/HDD/inc/wlan_hdd_main.h
@@ -998,7 +998,6 @@
     tANI_U16 connected_peer_count;
     tdls_scan_context_t tdls_scan_ctxt;
 #endif
-
     hdd_traffic_monitor_t traffic_monitor;
 
     /* MC/BC Filter state variable
@@ -1006,6 +1005,9 @@
      * configured
      * */
     v_U8_t configuredMcastBcastFilter;
+
+    vos_timer_t hdd_p2p_go_conn_is_in_progress;
+
 };
 
 
diff --git a/CORE/HDD/inc/wlan_hdd_p2p.h b/CORE/HDD/inc/wlan_hdd_p2p.h
index 8bc873d..b63b94e 100644
--- a/CORE/HDD/inc/wlan_hdd_p2p.h
+++ b/CORE/HDD/inc/wlan_hdd_p2p.h
@@ -55,6 +55,7 @@
 #define WAIT_CANCEL_REM_CHAN    1000
 #define WAIT_REM_CHAN_READY     1000
 #define WAIT_CHANGE_CHANNEL_FOR_OFFCHANNEL_TX 3000
+#define WAIT_TIME_FOR_P2PGO_CONNECTION 10000
 
 #define ACTION_FRAME_DEFAULT_WAIT 200
 
@@ -145,6 +146,8 @@
 void hdd_sendActionCnf( hdd_adapter_t *pAdapter, tANI_BOOLEAN actionSendSuccess );
 int wlan_hdd_check_remain_on_channel(hdd_adapter_t *pAdapter);
 void wlan_hdd_cancel_existing_remain_on_channel(hdd_adapter_t *pAdapter);
+void hdd_start_p2p_go_connection_in_progress_timer( hdd_adapter_t *pAdapter );
+v_VOID_t wlan_hdd_p2p_go_connection_in_progresscb (v_PVOID_t userData );
 
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
 int wlan_hdd_action( struct wiphy *wiphy, struct wireless_dev *wdev,
@@ -200,5 +203,4 @@
 int wlan_hdd_del_virtual_intf( struct wiphy *wiphy, struct net_device *dev );
 #endif
 
-
 #endif // __P2P_H
diff --git a/CORE/HDD/src/wlan_hdd_cfg80211.c b/CORE/HDD/src/wlan_hdd_cfg80211.c
index fbea7ed..4b7091f 100644
--- a/CORE/HDD/src/wlan_hdd_cfg80211.c
+++ b/CORE/HDD/src/wlan_hdd_cfg80211.c
@@ -2356,6 +2356,10 @@
 #endif
         status = wlan_hdd_cfg80211_start_bss(pAdapter, &params->beacon, params->ssid,
                                              params->ssid_len, params->hidden_ssid);
+        if (0 == status)
+        {
+            hdd_start_p2p_go_connection_in_progress_timer(pAdapter);
+        }
     }
 
     EXIT();
@@ -4309,6 +4313,14 @@
     v_U8_t staId = 0;
     v_U8_t *staMac = NULL;
 
+    if (VOS_TIMER_STATE_RUNNING ==
+                vos_timer_getCurrentState(&pHddCtx->hdd_p2p_go_conn_is_in_progress))
+    {
+        hddLog(VOS_TRACE_LEVEL_INFO,
+              "%s: Connection is in progress, Do not allow the scan", __func__);
+        return VOS_FALSE;
+    }
+
     status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
 
     while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
diff --git a/CORE/HDD/src/wlan_hdd_hostapd.c b/CORE/HDD/src/wlan_hdd_hostapd.c
index 91c3e24..17eb399 100644
--- a/CORE/HDD/src/wlan_hdd_hostapd.c
+++ b/CORE/HDD/src/wlan_hdd_hostapd.c
@@ -638,6 +638,11 @@
                 if (!VOS_IS_STATUS_SUCCESS(vos_status))
                    hddLog(LOGE, FL("Failed to start AP inactivity timer\n"));
             }
+            if (VOS_TIMER_STATE_RUNNING ==
+                    vos_timer_getCurrentState(&pHddCtx->hdd_p2p_go_conn_is_in_progress))
+            {
+                vos_timer_stop(&pHddCtx->hdd_p2p_go_conn_is_in_progress);
+            }
 #ifdef WLAN_OPEN_SOURCE
             if (wake_lock_active(&pHddCtx->sap_wake_lock))
             {
@@ -720,6 +725,11 @@
                         VOS_ASSERT(vos_timer_getCurrentState(&pHddApCtx->hdd_ap_inactivity_timer) == VOS_TIMER_STATE_STOPPED);
                 }
             }
+            if (VOS_TIMER_STATE_RUNNING ==
+                    vos_timer_getCurrentState(&pHddCtx->hdd_p2p_go_conn_is_in_progress))
+            {
+                vos_timer_stop(&pHddCtx->hdd_p2p_go_conn_is_in_progress);
+            }
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
             cfg80211_del_sta(dev,
                             (const u8 *)&pSapEvent->sapevt.sapStationDisassocCompleteEvent.staMac.bytes[0],
diff --git a/CORE/HDD/src/wlan_hdd_main.c b/CORE/HDD/src/wlan_hdd_main.c
index d8a5d9b..12ca67f 100644
--- a/CORE/HDD/src/wlan_hdd_main.c
+++ b/CORE/HDD/src/wlan_hdd_main.c
@@ -4872,6 +4872,21 @@
    // all scans will be cancelled.
    hdd_abort_mac_scan( pHddCtx );
 
+   //Stop the timer if already running
+   if (VOS_TIMER_STATE_RUNNING ==
+           vos_timer_getCurrentState(&pHddCtx->hdd_p2p_go_conn_is_in_progress))
+   {
+       vos_timer_stop(&pHddCtx->hdd_p2p_go_conn_is_in_progress);
+   }
+
+   // Destroy hdd_p2p_go_conn_is_in_progress timer
+   if (!VOS_IS_STATUS_SUCCESS(vos_timer_destroy(
+                         &pHddCtx->hdd_p2p_go_conn_is_in_progress)))
+   {
+       hddLog(VOS_TRACE_LEVEL_ERROR,
+           "%s: Cannot deallocate p2p connection timer", __func__);
+   }
+
    //Disable IMPS/BMPS as we do not want the device to enter any power
    //save mode during shutdown
    sme_DisablePowerSave(pHddCtx->hHal, ePMC_IDLE_MODE_POWER_SAVE);
@@ -5851,10 +5866,16 @@
 
    vos_set_load_unload_in_progress(VOS_MODULE_ID_VOSS, FALSE);
    hdd_allow_suspend();
-   
+
    // Initialize the restart logic
    wlan_hdd_restart_init(pHddCtx);
 
+   if (!VOS_IS_STATUS_SUCCESS( vos_timer_init( &pHddCtx->hdd_p2p_go_conn_is_in_progress,
+         VOS_TIMER_TYPE_SW, wlan_hdd_p2p_go_connection_in_progresscb, pAdapter) ) )
+   {
+       hddLog(VOS_TRACE_LEVEL_ERROR,
+           "%s: vos timer init failed for hdd_p2p_go_conn_is_in_progress", __func__);
+   }
    goto success;
 
 err_nl_srv:
diff --git a/CORE/HDD/src/wlan_hdd_p2p.c b/CORE/HDD/src/wlan_hdd_p2p.c
index 66d9c50..cd4855a 100644
--- a/CORE/HDD/src/wlan_hdd_p2p.c
+++ b/CORE/HDD/src/wlan_hdd_p2p.c
@@ -1686,6 +1686,33 @@
         netif_rx_ni( skb );
 
     /* Enable Queues which we have disabled earlier */
-    netif_tx_start_all_queues( pAdapter->dev ); 
+    netif_tx_start_all_queues( pAdapter->dev );
 
 }
+
+void hdd_start_p2p_go_connection_in_progress_timer( hdd_adapter_t *pAdapter )
+{
+
+    hdd_context_t *pHddCtx;
+    VOS_STATUS vos_status;
+
+    pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
+
+    if (WLAN_HDD_P2P_GO == pAdapter->device_mode)
+    {
+        vos_status = vos_timer_start(&pHddCtx->hdd_p2p_go_conn_is_in_progress,
+                        WAIT_TIME_FOR_P2PGO_CONNECTION);
+        if ( !VOS_IS_STATUS_SUCCESS(vos_status))
+        {
+             VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
+                  FL("Starting hdd_p2p_go_conn_is_in_progress timer failed %s"), __func__);
+        }
+    }
+}
+
+v_VOID_t wlan_hdd_p2p_go_connection_in_progresscb (v_PVOID_t userData )
+{
+     VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
+              "%s: Connection is in progress", __func__);
+}
+