wlan: Add AP Find feature

Add changes for find AP feature.

These changes gets "Find AP" params from HDD and sends it to FW
so that it can wake up the host if its finds the corresponding AP.

Change-Id: Ib843dc736a715de2a7ce8d5983359c6b49c37c86
CRs-Fixed: 755225
diff --git a/CORE/MAC/inc/sirApi.h b/CORE/MAC/inc/sirApi.h
index 6ad300d..5cc1b03 100644
--- a/CORE/MAC/inc/sirApi.h
+++ b/CORE/MAC/inc/sirApi.h
@@ -757,6 +757,13 @@
     tSirBssDescription  bssDescription;//Peer BSS description
 } tSirSmeStartBssRsp, *tpSirSmeStartBssRsp;
 
+#ifdef WLAN_FEATURE_APFIND
+struct hal_apfind_request
+{
+    tANI_U16 request_data_len;
+    tANI_U8 request_data[];
+};
+#endif
 
 typedef struct sSirChannelList
 {
diff --git a/CORE/MAC/src/include/sirParams.h b/CORE/MAC/src/include/sirParams.h
index 9d41e6c..03f8a46 100644
--- a/CORE/MAC/src/include/sirParams.h
+++ b/CORE/MAC/src/include/sirParams.h
@@ -787,6 +787,10 @@
 #define SIR_HAL_SET_MDNS_RESPONSE          (SIR_HAL_ITC_MSG_TYPES_BEGIN + 297)
 #define SIR_HAL_GET_MDNS_STATUS            (SIR_HAL_ITC_MSG_TYPES_BEGIN + 298)
 #endif /* MDNS_OFFLOAD */
+#ifdef WLAN_FEATURE_APFIND
+#define SIR_HAL_APFIND_SET_CMD             (SIR_HAL_ITC_MSG_TYPES_BEGIN + 299)
+#endif/* WLAN_FEATURE_APFIND */
+
 #define SIR_HAL_MSG_TYPES_END              (SIR_HAL_MSG_TYPES_BEGIN + 0x1FF)
 
 // CFG message types
diff --git a/CORE/SME/inc/sme_Api.h b/CORE/SME/inc/sme_Api.h
index 6ec4070..ba5185b 100644
--- a/CORE/SME/inc/sme_Api.h
+++ b/CORE/SME/inc/sme_Api.h
@@ -358,6 +358,15 @@
     eSME_ROAM_TRIGGER_MAX
 } tSmeFastRoamTrigger;
 
+#ifdef WLAN_FEATURE_APFIND
+struct sme_ap_find_request_req
+{
+    u_int16_t request_data_len;
+    const u_int8_t* request_data;
+};
+#endif /* WLAN_FEATURE_APFIND */
+
+
 /*------------------------------------------------------------------------- 
   Function declarations and documentation.
   ------------------------------------------------------------------------*/
@@ -3965,6 +3974,11 @@
 void sme_set_mgmt_frm_via_wq5(tHalHandle hHal,
         tANI_BOOLEAN sendMgmtPktViaWQ5);
 eHalStatus sme_update_cfg_int_param(tHalHandle hHal, tANI_U32 cfg_id);
+
+#ifdef WLAN_FEATURE_APFIND
+VOS_STATUS sme_apfind_set_cmd(struct sme_ap_find_request_req *input);
+#endif /* WLAN_FEATURE_APFIND */
+
 #ifdef SAP_AUTH_OFFLOAD
 /**
  * sme_set_sap_auth_offload() enable/disable SAP Auth Offload
diff --git a/CORE/SME/src/sme_common/sme_Api.c b/CORE/SME/src/sme_common/sme_Api.c
index 65edad4..ec9cb22 100644
--- a/CORE/SME/src/sme_common/sme_Api.c
+++ b/CORE/SME/src/sme_common/sme_Api.c
@@ -14853,3 +14853,49 @@
        }
        return status;
 }
+
+#ifdef WLAN_FEATURE_APFIND
+/**
+ * sme_apfind_set_cmd() - set apfind configuration to firmware
+ * @input: pointer to apfind request data.
+ *
+ * SME API to set APFIND configuations to firmware.
+ *
+ * Return: VOS_STATUS.
+ */
+VOS_STATUS sme_apfind_set_cmd(struct sme_ap_find_request_req *input)
+{
+    vos_msg_t msg;
+    struct hal_apfind_request *data;
+    size_t data_len;
+
+    data_len = sizeof(struct hal_apfind_request) + input->request_data_len;
+    data = vos_mem_malloc(data_len);
+
+    if (data == NULL) {
+        VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_ERROR,
+                FL("Memory allocation failure"));
+        return VOS_STATUS_E_NOMEM;
+    }
+
+    vos_mem_zero(data, data_len);
+    data->request_data_len = input->request_data_len;
+    if (input->request_data_len) {
+        vos_mem_copy(data->request_data,
+                input->request_data, input->request_data_len);
+    }
+
+    msg.type = WDA_APFIND_SET_CMD;
+    msg.reserved = 0;
+    msg.bodyptr = data;
+
+    if (VOS_STATUS_SUCCESS != vos_mq_post_message(VOS_MODULE_ID_WDA, &msg)) {
+        VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_ERROR,
+                FL("Not able to post WDA_APFIND_SET_CMD message to WDA"));
+        vos_mem_free(data);
+        return VOS_STATUS_E_FAILURE;
+    }
+
+    return VOS_STATUS_SUCCESS;
+}
+#endif /* WLAN_FEATURE_APFIND */
diff --git a/CORE/WDA/inc/wlan_qct_wda.h b/CORE/WDA/inc/wlan_qct_wda.h
index 5fab319..a7dcbe5 100644
--- a/CORE/WDA/inc/wlan_qct_wda.h
+++ b/CORE/WDA/inc/wlan_qct_wda.h
@@ -1373,6 +1373,10 @@
 #define WDA_SET_SAP_AUTH_OFL                  SIR_HAL_SET_SAP_AUTH_OFL
 #endif /* SAP_AUTH_OFFLOAD */
 
+#ifdef WLAN_FEATURE_APFIND
+#define WDA_APFIND_SET_CMD                    SIR_HAL_APFIND_SET_CMD
+#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
 
 #define halTxFrame(hHal, pFrmBuf, frmLen, frmType, txDir, tid, pCompFunc, pData, txFlag) \
diff --git a/CORE/WDA/src/wlan_qct_wda.c b/CORE/WDA/src/wlan_qct_wda.c
index 2f6a09b..03f6dca 100644
--- a/CORE/WDA/src/wlan_qct_wda.c
+++ b/CORE/WDA/src/wlan_qct_wda.c
@@ -15398,6 +15398,50 @@
 
 }
 
+#ifdef WLAN_FEATURE_APFIND
+/*
+ * FUNCTION: WDA_Process_apfind_set_cmd
+ * Forward AP find config request to WDI
+ */
+VOS_STATUS  WDA_Process_apfind_set_cmd(tWDA_CbContext *pWDA,
+        struct hal_apfind_request *ap_find_req)
+{
+    WDI_Status status;
+    struct WDI_APFind_cmd *wdi_ap_find_cmd;
+
+    VOS_TRACE( VOS_MODULE_ID_WDA, VOS_TRACE_LEVEL_ERROR,
+            "------> %s " ,__func__);
+    if (NULL == ap_find_req)
+    {
+        VOS_TRACE( VOS_MODULE_ID_WDA, VOS_TRACE_LEVEL_ERROR,
+                "%s: apfind_req info received NULL", __func__);
+        VOS_ASSERT(0) ;
+        return VOS_STATUS_E_FAULT;
+    }
+
+    wdi_ap_find_cmd = (struct WDI_APFind_cmd *)vos_mem_malloc(
+            sizeof(struct hal_apfind_request) + ap_find_req->request_data_len);
+
+    wdi_ap_find_cmd->data_len = ap_find_req->request_data_len;
+    vos_mem_copy(wdi_ap_find_cmd->data, ap_find_req->request_data,
+            ap_find_req->request_data_len);
+
+    status = WDI_process_ap_find_cmd(wdi_ap_find_cmd);
+    if (WDI_STATUS_PENDING == status) {
+        VOS_TRACE(VOS_MODULE_ID_WDA, VOS_TRACE_LEVEL_INFO,
+                FL("pending status received"));
+    } else if (WDI_STATUS_SUCCESS_SYNC != status &&
+            (WDI_STATUS_SUCCESS != status)) {
+
+        VOS_TRACE(VOS_MODULE_ID_WDA, VOS_TRACE_LEVEL_ERROR,
+                FL("Failure in process_sap_auth_offload API %d"), status);
+
+    }
+    vos_mem_free(wdi_ap_find_cmd);
+    return CONVERT_WDI2VOS_STATUS(status) ;
+}
+#endif
+
 /*
  * FUNCTION: WDA_ProcessTXFailMonitorInd
  * Forward TX Fail Monitor to WDI
@@ -17260,6 +17304,13 @@
          WDA_ProcessTLPauseInd(pWDA, pMsg->bodyval);
          break;
       }
+#ifdef WLAN_FEATURE_APFIND
+      case WDA_APFIND_SET_CMD:
+      {
+          WDA_Process_apfind_set_cmd(pWDA,
+                  (struct hal_apfind_request *)pMsg->bodyptr);
+      }
+#endif
 #ifdef SAP_AUTH_OFFLOAD
       case WDA_SET_SAP_AUTH_OFL:
       {
diff --git a/CORE/WDI/CP/inc/wlan_qct_wdi.h b/CORE/WDI/CP/inc/wlan_qct_wdi.h
index 952d920..d43f244 100644
--- a/CORE/WDI/CP/inc/wlan_qct_wdi.h
+++ b/CORE/WDI/CP/inc/wlan_qct_wdi.h
@@ -6584,6 +6584,14 @@
 } wdi_mdns_stats_rsp_param_t;
 #endif /* MDNS_OFFLOAD */
 
+#ifdef WLAN_FEATURE_APFIND
+struct WDI_APFind_cmd
+{
+    wpt_uint32 data_len;
+    wpt_uint8 data[];
+};
+#endif
+
 /**
  * struct WDI_FwrMemDumpReqType - firmware memory dump request details.
 .*.@FWMemDumpReqCb - Associated Callback
@@ -12417,7 +12425,9 @@
 WDI_process_sap_auth_offload(
    struct WDI_sap_ofl_enable_params *sap_ofl_enable_cmd
 );
-
+#ifdef WLAN_FEATURE_APFIND
+WDI_Status WDI_process_ap_find_cmd(struct WDI_APFind_cmd *params);
+#endif
 #ifdef DHCP_SERVER_OFFLOAD
 WDI_Status
 wdi_process_dhcpserver_offload_req
diff --git a/CORE/WDI/CP/inc/wlan_qct_wdi_i.h b/CORE/WDI/CP/inc/wlan_qct_wdi_i.h
index a85761c..43b870f 100644
--- a/CORE/WDI/CP/inc/wlan_qct_wdi_i.h
+++ b/CORE/WDI/CP/inc/wlan_qct_wdi_i.h
@@ -567,7 +567,8 @@
   WDI_PROCESS_SAP_AUTH_OFFLOAD_IND = WDI_MAX_REQ +24,
 #endif
 
-  WDI_MAX_UMAC_IND = WDI_MAX_REQ + 25
+  WDI_SET_AP_FIND_IND = WDI_MAX_REQ + 25,
+  WDI_MAX_UMAC_IND = WDI_MAX_REQ + 26
 
 }WDI_RequestEnumType;
 
@@ -6780,6 +6781,20 @@
   WDI_EventInfoType *event_data
 );
 #endif /* MDNS_OFFLOAD */
-
+#ifdef WLAN_FEATURE_APFIND
+/**
+ *  WDI_ProcessApFindInd - Process AP find command command
+ *
+ *  @pWDICtx: pointer to the WLAN DAL context
+ *  @pEventData: pointer to the event information structure
+ *
+ */
+WDI_Status
+WDI_ProcessApFindInd
+(
+  WDI_ControlBlockType*  pWDICtx,
+  WDI_EventInfoType*     pEventData
+);
+#endif
 #endif /*WLAN_QCT_WDI_I_H*/
 
diff --git a/CORE/WDI/CP/src/wlan_qct_wdi.c b/CORE/WDI/CP/src/wlan_qct_wdi.c
index c8e8530..7f098a8 100644
--- a/CORE/WDI/CP/src/wlan_qct_wdi.c
+++ b/CORE/WDI/CP/src/wlan_qct_wdi.c
@@ -599,6 +599,9 @@
 #ifdef SAP_AUTH_OFFLOAD
   WDI_ProcessSapAuthOffloadInd,          /* WDI_PROCESS_SAP_AUTH_OFFLOAD_IND */
 #endif
+#ifdef WLAN_FEATURE_APFIND
+  WDI_ProcessApFindInd,                 /* WDI_SET_AP_FIND_IND */
+#endif
 };
 
 
@@ -1348,6 +1351,9 @@
     CASE_RETURN_STRING( WDI_MDNS_RESP_OFFLOAD_REQ );
     CASE_RETURN_STRING( WDI_MDNS_STATS_OFFLOAD_REQ );
 #endif /* MDNS_OFFLOAD */
+#ifdef WLAN_FEATURE_APFIND
+    CASE_RETURN_STRING( WDI_SET_AP_FIND_IND );
+#endif
     default:
         return "Unknown WDI MessageId";
   }
@@ -25002,6 +25008,8 @@
        return WLAN_HAL_MODIFY_ROAM_PARAMS_IND;
   case WDI_SET_ALLOWED_ACTION_FRAMES_IND:
        return WLAN_HAL_SET_ALLOWED_ACTION_FRAMES_IND;
+  case WDI_SET_AP_FIND_IND:
+       return WLAN_HAL_QRF_AP_FIND_COMMAND;
 #ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
   case WDI_PER_ROAM_SCAN_OFFLOAD_REQ:
       return WLAN_HAL_SET_PER_ROAM_CONFIG_REQ;
@@ -39054,6 +39062,92 @@
 
 #endif
 
+#ifdef WLAN_FEATURE_APFIND
+WDI_Status WDI_ProcessApFindInd(WDI_ControlBlockType *pWDICtx,
+                                WDI_EventInfoType *pEventData)
+{
+  wpt_uint8*  pSendBuffer = NULL;
+  wpt_uint16  usDataOffset = 0;
+  wpt_uint16  usSendSize = 0;
+  struct WDI_APFind_cmd *pwdiapFindRequestInd;
+  tQRFPrefNetwListParams *phalAPFindRequestParam;
+  WDI_Status wdiStatus = WDI_STATUS_SUCCESS;
+  wpt_uint16 buffer_len = 0;
+
+  /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
+
+  WPAL_TRACE(eWLAN_MODULE_DAL_CTRL, eWLAN_PAL_TRACE_LEVEL_ERROR,
+          "%s", __func__);
+
+  /*-------------------------------------------------------------------------
+    Sanity check
+    ------------------------------------------------------------------------*/
+  if (( NULL == pEventData ) || ( NULL == pEventData->pEventData ))
+  {
+      WPAL_TRACE( eWLAN_MODULE_DAL_CTRL, eWLAN_PAL_TRACE_LEVEL_FATAL,
+              "%s: Invalid parameters", __func__);
+      WDI_ASSERT(0);
+      return WDI_STATUS_E_FAILURE;
+  }
+  pwdiapFindRequestInd = (struct WDI_APFind_cmd *)pEventData->pEventData;
+  if (pwdiapFindRequestInd->data_len)
+      buffer_len = sizeof(tQRFPrefNetwListParams);
+  /*-----------------------------------------------------------------------
+    Get message buffer
+    -----------------------------------------------------------------------*/
+  if (( WDI_STATUS_SUCCESS != WDI_GetMessageBuffer(pWDICtx,
+                  WDI_SET_AP_FIND_IND,
+                  buffer_len,
+                  &pSendBuffer, &usDataOffset, &usSendSize))||
+          ( usSendSize < (usDataOffset + sizeof(tQRFPrefNetwListParams) )))
+  {
+      WPAL_TRACE( eWLAN_MODULE_DAL_CTRL, eWLAN_PAL_TRACE_LEVEL_FATAL,
+              "Unable to get send buffer in QRF command %p ",
+              pEventData);
+      WDI_ASSERT(0);
+      return WDI_STATUS_E_FAILURE;
+  }
+  phalAPFindRequestParam =
+      (tQRFPrefNetwListParams *)(pSendBuffer + usDataOffset);
+
+  wpalMemoryCopy(phalAPFindRequestParam,
+                 &pwdiapFindRequestInd->data[0],
+                 pwdiapFindRequestInd->data_len);
+
+  pWDICtx->pReqStatusUserData = NULL;
+  pWDICtx->pfncRspCB = NULL;
+  /*-------------------------------------------------------------------------
+    Send WDI_SET_AP_FIND_IND Indication to HAL
+   -------------------------------------------------------------------------*/
+
+  wdiStatus =  WDI_SendIndication( pWDICtx, pSendBuffer, usSendSize);
+
+  return (wdiStatus != WDI_STATUS_SUCCESS) ? wdiStatus:WDI_STATUS_SUCCESS_SYNC;
+
+}
+
+WDI_Status WDI_process_ap_find_cmd(struct WDI_APFind_cmd *params)
+{
+  WDI_EventInfoType wdiEventData;
+
+  if (eWLAN_PAL_FALSE == gWDIInitialized)
+  {
+      WPAL_TRACE(eWLAN_MODULE_DAL_CTRL, eWLAN_PAL_TRACE_LEVEL_ERROR,
+              "WDI API call before module is initialized - Fail req");
+      return WDI_STATUS_E_NOT_ALLOWED;
+  }
+
+  wdiEventData.wdiRequest = WDI_SET_AP_FIND_IND;
+  wdiEventData.pEventData = params;
+  wdiEventData.uEventDataSize  = sizeof(*params);
+  wdiEventData.pCBfnc = NULL;
+  wdiEventData.pUserData = NULL;
+
+  return WDI_PostMainEvent(&gWDICb, WDI_REQUEST_EVENT, &wdiEventData);
+
+}
+#endif
+
 /**
  *  WDI_ProcessSetAllowedActionFramesInd() - Process Allowed action frames
  *                                   Indication message and post it to HAL