wlan: Add Find AP feature

Add changes to handle find AP indication for find AP feature.
After getting this indication, host will disconnect from the
current AP since current AP is no more available.

DUT will connect to new found AP using supplicant once it
disconnects with current AP.

CRs-Fixed: 755225
Change-Id: I5e49c4f6424a8a8278bc681fb7481ebcd82d6628
diff --git a/CORE/MAC/src/include/sirParams.h b/CORE/MAC/src/include/sirParams.h
index 03f8a46..bac3ba8 100644
--- a/CORE/MAC/src/include/sirParams.h
+++ b/CORE/MAC/src/include/sirParams.h
@@ -789,6 +789,7 @@
 #endif /* MDNS_OFFLOAD */
 #ifdef WLAN_FEATURE_APFIND
 #define SIR_HAL_APFIND_SET_CMD             (SIR_HAL_ITC_MSG_TYPES_BEGIN + 299)
+#define SIR_HAL_AP_FIND_IND                (SIR_HAL_ITC_MSG_TYPES_BEGIN + 300)
 #endif/* WLAN_FEATURE_APFIND */
 
 #define SIR_HAL_MSG_TYPES_END              (SIR_HAL_MSG_TYPES_BEGIN + 0x1FF)
diff --git a/CORE/MAC/src/pe/include/limApi.h b/CORE/MAC/src/pe/include/limApi.h
index 5b869d3..88bca93 100644
--- a/CORE/MAC/src/pe/include/limApi.h
+++ b/CORE/MAC/src/pe/include/limApi.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012-2013 The Linux Foundation. All rights reserved.
+ * Copyright (c) 2011-2013, 2016 The Linux Foundation. All rights reserved.
  *
  * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
  *
@@ -191,6 +191,9 @@
 
 void limHandleLowRssiInd(tpAniSirGlobal pMac);
 void limHandleBmpsStatusInd(tpAniSirGlobal pMac);
+#ifdef WLAN_FEATURE_APFIND
+void limHandleAPFindInd(tpAniSirGlobal pMac);
+#endif
 void limHandleMissedBeaconInd(tpAniSirGlobal pMac, tpSirMsgQ pMsg);
 tMgmtFrmDropReason limIsPktCandidateForDrop(tpAniSirGlobal pMac, tANI_U8 *pRxPacketInfo, tANI_U32 subType);
 boolean limIsDeauthDiassocForDrop(tpAniSirGlobal pMac,
diff --git a/CORE/MAC/src/pe/include/limSession.h b/CORE/MAC/src/pe/include/limSession.h
index 7c049af..c55daee 100644
--- a/CORE/MAC/src/pe/include/limSession.h
+++ b/CORE/MAC/src/pe/include/limSession.h
@@ -421,6 +421,7 @@
 tpPESession peFindSessionByBssIdx(tpAniSirGlobal pMac,  tANI_U8 bssIdx);
 
 
+tANI_S8 limGetInfraSessionId(tpAniSirGlobal pMac);
 
 
 /*--------------------------------------------------------------------------
diff --git a/CORE/MAC/src/pe/lim/limApi.c b/CORE/MAC/src/pe/lim/limApi.c
index f49aa01..e2dd714 100644
--- a/CORE/MAC/src/pe/lim/limApi.c
+++ b/CORE/MAC/src/pe/lim/limApi.c
@@ -2160,6 +2160,21 @@
     return;
 }
 
+#ifdef WLAN_FEATURE_APFIND
+void limHandleAPFindInd(tpAniSirGlobal pMac)
+{
+    tANI_S8 pe_sessionid = -1;
+    /* Find STA connection session */
+    pe_sessionid = limGetInfraSessionId(pMac);
+    if (pe_sessionid != -1)
+        limTearDownLinkWithAp(pMac,
+                              pe_sessionid,
+                              eSIR_BEACON_MISSED);
+    else
+         limLog(pMac, LOGE,
+               FL("session id doesn't exist for infra"));
+}
+#endif
 
 /** -----------------------------------------------------------------
   \brief limHandleMissedBeaconInd() - handles missed beacon indication
diff --git a/CORE/MAC/src/pe/lim/limProcessMessageQueue.c b/CORE/MAC/src/pe/lim/limProcessMessageQueue.c
index 2e1d2af..3016bd0 100644
--- a/CORE/MAC/src/pe/lim/limProcessMessageQueue.c
+++ b/CORE/MAC/src/pe/lim/limProcessMessageQueue.c
@@ -1895,6 +1895,11 @@
             limHandleBmpsStatusInd(pMac);
             break;
 
+#ifdef WLAN_FEATURE_APFIND
+        case WDA_AP_FIND_IND:
+            limHandleAPFindInd(pMac);
+            break;
+#endif
         case WDA_MISSED_BEACON_IND:
             limHandleMissedBeaconInd(pMac, limMsg);
             vos_mem_free(limMsg->bodyptr);
diff --git a/CORE/MAC/src/pe/lim/limSession.c b/CORE/MAC/src/pe/lim/limSession.c
index 58b7571..cbd2e4d 100644
--- a/CORE/MAC/src/pe/lim/limSession.c
+++ b/CORE/MAC/src/pe/lim/limSession.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012-2014 The Linux Foundation. All rights reserved.
+ * Copyright (c) 2011-2014, 2016 The Linux Foundation. All rights reserved.
  *
  * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
  *
@@ -236,6 +236,20 @@
 
 }
 
+tANI_S8 limGetInfraSessionId(tpAniSirGlobal pMac)
+{
+    tANI_U8 i;
+    for (i = 0; i < pMac->lim.maxBssId; i++)
+    {
+        if ((pMac->lim.gpSession[i].valid) &&
+           (pMac->lim.gpSession[i].limSystemRole == eLIM_STA_ROLE))
+        {
+            return i;
+        }
+    }
+    limLog(pMac, LOG4, FL("Session lookup fails for infra mode"));
+    return -1;
+}
 
 /*--------------------------------------------------------------------------
   \brief peFindSessionByBssIdx() - looks up the PE session given the bssIdx.
diff --git a/CORE/WDA/inc/wlan_qct_wda.h b/CORE/WDA/inc/wlan_qct_wda.h
index a7dcbe5..1c67f7e 100644
--- a/CORE/WDA/inc/wlan_qct_wda.h
+++ b/CORE/WDA/inc/wlan_qct_wda.h
@@ -1375,6 +1375,7 @@
 
 #ifdef WLAN_FEATURE_APFIND
 #define WDA_APFIND_SET_CMD                    SIR_HAL_APFIND_SET_CMD
+#define WDA_AP_FIND_IND                       SIR_HAL_AP_FIND_IND
 #endif /* WLAN_FEATURE_APFIND */
 
 #define HAL_USE_BD_RATE2_FOR_MANAGEMENT_FRAME 0x40 // Bit 6 will be used to control BD rate for Management frames
diff --git a/CORE/WDA/src/wlan_qct_wda.c b/CORE/WDA/src/wlan_qct_wda.c
index 03f6dca..22b00dc 100644
--- a/CORE/WDA/src/wlan_qct_wda.c
+++ b/CORE/WDA/src/wlan_qct_wda.c
@@ -17415,6 +17415,13 @@
          WDA_SendMsg(pWDA, WDA_MISSED_BEACON_IND, (void *)pMissBeacInd , 0) ;
          break ;
       }
+#ifdef WLAN_FEATURE_APFIND
+      case WDI_AP_FOUND_IND:
+      {
+         WDA_SendMsg(pWDA, WDA_AP_FIND_IND, NULL, 0) ;
+         break ;
+      }
+#endif
       case WDI_UNKNOWN_ADDR2_FRAME_RX_IND:
       {
          /* TODO: Decode Ind and send Ind to PE */
diff --git a/CORE/WDI/CP/inc/wlan_qct_wdi.h b/CORE/WDI/CP/inc/wlan_qct_wdi.h
index d43f244..fc3dfe7 100644
--- a/CORE/WDI/CP/inc/wlan_qct_wdi.h
+++ b/CORE/WDI/CP/inc/wlan_qct_wdi.h
@@ -431,6 +431,9 @@
 #ifdef FEATURE_OEM_DATA_SUPPORT
   WDI_START_OEM_DATA_RSP_IND_NEW,
 #endif
+#ifdef WLAN_FEATURE_APFIND
+  WDI_AP_FOUND_IND,
+#endif
   WDI_MAX_IND
 }WDI_LowLevelIndEnumType;
 
diff --git a/CORE/WDI/CP/inc/wlan_qct_wdi_i.h b/CORE/WDI/CP/inc/wlan_qct_wdi_i.h
index 43b870f..0f01a78 100644
--- a/CORE/WDI/CP/inc/wlan_qct_wdi_i.h
+++ b/CORE/WDI/CP/inc/wlan_qct_wdi_i.h
@@ -977,6 +977,9 @@
   WDI_HAL_RSSI_BREACHED_IND          = WDI_HAL_IND_MIN + 32,
   WDI_HAL_START_OEM_DATA_RSP_IND_NEW = WDI_HAL_IND_MIN + 33,
   WDI_ANTENNA_DIVERSITY_SELECTION_RSP = WDI_HAL_IND_MIN + 34,
+#ifdef WLAN_FEATURE_APFIND
+  WDI_HAL_QRF_PREF_NETWORK_FOUND_IND = WDI_HAL_IND_MIN + 35,
+#endif
   WDI_MAX_RESP
 }WDI_ResponseEnumType; 
 
@@ -5929,6 +5932,15 @@
 );
 #endif /* FEATURE_WLAN_LPHB */
 
+#ifdef WLAN_FEATURE_APFIND
+WDI_Status
+WDI_ProcessQRFPrefNetworkFoundInd
+(
+  WDI_ControlBlockType*  pWDICtx,
+  WDI_EventInfoType*     pEventData
+);
+#endif
+
 /**
  @brief Process Rate Update Indication and post it to HAL
 
diff --git a/CORE/WDI/CP/src/wlan_qct_wdi.c b/CORE/WDI/CP/src/wlan_qct_wdi.c
index 7f098a8..1938155 100644
--- a/CORE/WDI/CP/src/wlan_qct_wdi.c
+++ b/CORE/WDI/CP/src/wlan_qct_wdi.c
@@ -984,6 +984,11 @@
   NULL,
 #endif
   WDI_ProcessGetCurrentAntennaIndexRsp,     /* WDI_ANTENNA_DIVERSITY_SELECTION_RSP */
+#ifdef WLAN_FEATURE_APFIND
+  WDI_ProcessQRFPrefNetworkFoundInd,   /* WDI_HAL_QRF_PREF_NETWORK_FOUND_IND */
+#else
+  NULL,
+#endif
 };
 
 
@@ -25417,6 +25422,10 @@
   case WLAN_HAL_MDNS_STATS_OFFLOAD_RSP:
        return WDI_MDNS_STATS_OFFLOAD_RSP;
 #endif /* MDNS_OFFLOAD */
+#ifdef WLAN_FEATURE_APFIND
+  case WLAN_HAL_QRF_PREF_NETW_FOUND_IND:
+    return WDI_HAL_QRF_PREF_NETWORK_FOUND_IND;
+#endif
   default:
     return eDRIVER_TYPE_MAX;
   }
@@ -27704,6 +27713,51 @@
 }/* WDI_ProcessPERRoamScanTriggerRsp  */
 #endif
 
+#ifdef WLAN_FEATURE_APFIND
+/**
+ @brief Process QRF Preferred Network Found Indication function
+
+ @param  pWDICtx:         pointer to the WLAN DAL context
+         pEventData:      pointer to the event information structure
+
+ @see
+ @return Result of the function call
+*/
+WDI_Status
+WDI_ProcessQRFPrefNetworkFoundInd
+(
+  WDI_ControlBlockType*  pWDICtx,
+  WDI_EventInfoType*     pEventData
+)
+{
+  WDI_LowLevelIndType   wdiInd;
+
+  WPAL_TRACE(eWLAN_MODULE_DAL_CTRL, eWLAN_PAL_TRACE_LEVEL_ERROR,
+  "%s:%d Enter", __func__, __LINE__);
+
+  /*-------------------------------------------------------------------------
+    Sanity check
+  -------------------------------------------------------------------------*/
+  if (NULL == pWDICtx)
+  {
+     WPAL_TRACE( eWLAN_MODULE_DAL_CTRL, eWLAN_PAL_TRACE_LEVEL_WARN,
+                 "%s: Invalid parameters", __func__);
+     WDI_ASSERT( 0 );
+     return WDI_STATUS_E_FAILURE;
+  }
+
+  /*Fill in the indication parameters*/
+  wdiInd.wdiIndicationType = WDI_AP_FOUND_IND;
+  if ( pWDICtx->wdiLowLevelIndCB )
+  {
+    /*Notify UMAC*/
+    pWDICtx->wdiLowLevelIndCB( &wdiInd, pWDICtx->pIndUserData );
+  }
+
+  return WDI_STATUS_SUCCESS;
+}
+#endif
+
 /**
  @brief Process Update Scan Params function