wlan: Remove kmalloc while parsing the beacon and probe resp.

While parsing the beacon and probe response, driver uses kmalloc
which may cause the MC thread to sleep in low memory resource.
Removed these kmalloc and replace them with vmalloc.
Also add the mac trace at start and end of the processing of
beacons.

CRs-Fixed: 815198
Change-Id: I93e0847c3a6a9281c0579aa565eede7d4fc799b1
diff --git a/CORE/MAC/src/pe/include/limTrace.h b/CORE/MAC/src/pe/include/limTrace.h
index 2e8726a..df234cb 100644
--- a/CORE/MAC/src/pe/include/limTrace.h
+++ b/CORE/MAC/src/pe/include/limTrace.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012-2013 The Linux Foundation. All rights reserved.
+ * Copyright (c) 2012-2015 The Linux Foundation. All rights reserved.
  *
  * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
  *
@@ -81,6 +81,7 @@
     TRACE_CODE_TX_CFG_MSG,
     TRACE_CODE_RX_CFG_MSG,
     TRACE_CODE_RX_MGMT_DROP,
+    TRACE_CODE_RX_MGMT_PROCESS,
 
     TRACE_CODE_TIMER_ACTIVATE,
     TRACE_CODE_TIMER_DEACTIVATE,
diff --git a/CORE/MAC/src/pe/lim/limProcessBeaconFrame.c b/CORE/MAC/src/pe/lim/limProcessBeaconFrame.c
index 8e48abc..de765b2 100644
--- a/CORE/MAC/src/pe/lim/limProcessBeaconFrame.c
+++ b/CORE/MAC/src/pe/lim/limProcessBeaconFrame.c
@@ -106,7 +106,7 @@
         || pMac->fScanOffload
         )
     {
-        pBeacon = vos_mem_malloc(sizeof(tSchBeaconStruct));
+        pBeacon = vos_mem_vmalloc(sizeof(tSchBeaconStruct));
         if ( NULL == pBeacon )
         {
             limLog(pMac, LOGE, FL("Unable to allocate memory in limProcessBeaconFrame") );
@@ -127,7 +127,7 @@
                (sirCompareMacAddr( psessionEntry->bssId, pHdr->sa)))
                 limParseBeaconForTim(pMac, (tANI_U8 *) pRxPacketInfo, psessionEntry);
 
-            vos_mem_free(pBeacon);
+            vos_mem_vfree(pBeacon);
             return;
         }
         /*during scanning, when any session is active, and beacon/Pr belongs to
@@ -191,7 +191,7 @@
              // STA in WT_JOIN_BEACON_STATE (IBSS)
             limCheckAndAnnounceJoinSuccess(pMac, pBeacon, pHdr,psessionEntry);
         } // if (pMac->lim.gLimMlmState == eLIM_MLM_WT_PROBE_RESP_STATE)
-        vos_mem_free(pBeacon);
+        vos_mem_vfree(pBeacon);
     } // if ((pMac->lim.gLimMlmState == eLIM_MLM_WT_PROBE_RESP_STATE) || ...
     else
     {
@@ -264,7 +264,7 @@
         (pMac->lim.gLimMlmState == eLIM_MLM_PASSIVE_SCAN_STATE) ||
         (pMac->lim.gLimMlmState == eLIM_MLM_LEARN_STATE))
     {
-        pBeacon = vos_mem_malloc(sizeof(tSchBeaconStruct));
+        pBeacon = vos_mem_vmalloc(sizeof(tSchBeaconStruct));
         if ( NULL == pBeacon )
         {
             limLog(pMac, LOGE, FL("Unable to allocate memory in limProcessBeaconFrameNoSession") );
@@ -276,7 +276,7 @@
             // Received wrongly formatted/invalid Beacon. Ignore and move on. 
             limLog(pMac, LOGW, FL("Received invalid Beacon in global MLM state %d"), pMac->lim.gLimMlmState);
             limPrintMlmState(pMac, LOGW,  pMac->lim.gLimMlmState);
-            vos_mem_free(pBeacon);
+            vos_mem_vfree(pBeacon);
             return;
         }
 
@@ -293,7 +293,7 @@
         else if (pMac->lim.gLimMlmState == eLIM_MLM_LEARN_STATE)
         {
         }  // end of eLIM_MLM_LEARN_STATE)       
-        vos_mem_free(pBeacon);
+        vos_mem_vfree(pBeacon);
     } // end of (eLIM_MLM_WT_PROBE_RESP_STATE) || (eLIM_MLM_PASSIVE_SCAN_STATE)
     else
     {
diff --git a/CORE/MAC/src/pe/lim/limProcessMessageQueue.c b/CORE/MAC/src/pe/lim/limProcessMessageQueue.c
index b8839db..cd5bb81 100644
--- a/CORE/MAC/src/pe/lim/limProcessMessageQueue.c
+++ b/CORE/MAC/src/pe/lim/limProcessMessageQueue.c
@@ -1386,7 +1386,7 @@
 #ifdef FEATURE_WLAN_TDLS_INTERNAL
                 tANI_U32    *pBD = NULL ;
 #endif 
-
+                MTRACE(macTrace(pMac, TRACE_CODE_RX_MGMT_PROCESS, 0, 0 );)
                 /* The original limMsg which we were deferring have the 
                  * bodyPointer point to 'BD' instead of 'Vos pkt'. If we don't make a copy
                  * of limMsg, then vos_pkt_peek_data will overwrite the limMsg->bodyPointer. 
@@ -1462,10 +1462,12 @@
                      * Asumption here is when Rx mgmt frame processing is done,
                      * voss packet could be freed here.
                      */
+                    MTRACE(macTrace(pMac, TRACE_CODE_RX_MGMT_PROCESS, 0, 3 );)
                     limDecrementPendingMgmtCount(pMac);
                     vos_pkt_return_packet(pVosPkt);
                 }
             }
+            MTRACE(macTrace(pMac, TRACE_CODE_RX_MGMT_PROCESS, 0, 4 );)
             break;
 
         case eWNI_SME_SCAN_REQ:
diff --git a/CORE/MAC/src/pe/lim/limProcessProbeRspFrame.c b/CORE/MAC/src/pe/lim/limProcessProbeRspFrame.c
index b90ee0e..528ce8b 100644
--- a/CORE/MAC/src/pe/lim/limProcessProbeRspFrame.c
+++ b/CORE/MAC/src/pe/lim/limProcessProbeRspFrame.c
@@ -127,7 +127,7 @@
                 psessionEntry->peSessionId);
 
 
-    pProbeRsp = vos_mem_malloc(sizeof(tSirProbeRespBeacon));
+    pProbeRsp = vos_mem_vmalloc(sizeof(tSirProbeRespBeacon));
     if ( NULL == pProbeRsp )
     {
         limLog(pMac, LOGE, FL("Unable to allocate memory in limProcessProbeRspFrame") );
@@ -151,7 +151,7 @@
    {
        if (limDeactivateMinChannelTimerDuringScan(pMac) != eSIR_SUCCESS)
        {
-           vos_mem_free(pProbeRsp);
+           vos_mem_vfree(pProbeRsp);
            return;
        }
    }
@@ -162,7 +162,7 @@
    {
        PELOG1(limLog(pMac, LOG1,
                  FL("Parse error ProbeResponse, length=%d"), frameLen);)
-       vos_mem_free(pProbeRsp);
+       vos_mem_vfree(pProbeRsp);
        return;
    }
 
@@ -212,7 +212,7 @@
             PELOG1(limLog(pMac, LOG1,
                FL("Parse error ProbeResponse, length=%d"),
                frameLen);)
-            vos_mem_free(pProbeRsp);
+            vos_mem_vfree(pProbeRsp);
             return;
         }
 
@@ -279,7 +279,7 @@
 
             if ( !vos_mem_compare(currentBssId, pHdr->bssId, sizeof(tSirMacAddr)) )
             {
-                vos_mem_free(pProbeRsp);
+                vos_mem_vfree(pProbeRsp);
                 return;
             }
 
@@ -357,7 +357,7 @@
                 limHandleIBSScoalescing(pMac, pProbeRsp, pRxPacketInfo,psessionEntry);
     } // if ((pMac->lim.gLimMlmState == eLIM_MLM_WT_PROBE_RESP_STATE) || ...
 
-    vos_mem_free(pProbeRsp);
+    vos_mem_vfree(pProbeRsp);
     // Ignore Probe Response frame in all other states
     return;
 } /*** end limProcessProbeRspFrame() ***/
@@ -371,7 +371,7 @@
     tpSirMacMgmtHdr         pHdr;
     tSirProbeRespBeacon    *pProbeRsp;
 
-    pProbeRsp = vos_mem_malloc(sizeof(tSirProbeRespBeacon));
+    pProbeRsp = vos_mem_vmalloc(sizeof(tSirProbeRespBeacon));
     if ( NULL == pProbeRsp )
     {
         limLog(pMac, LOGE, FL("Unable to allocate memory in limProcessProbeRspFrameNoSession") );
@@ -400,7 +400,7 @@
         {
             if (limDeactivateMinChannelTimerDuringScan(pMac) != eSIR_SUCCESS)
             {
-                vos_mem_free(pProbeRsp);
+                vos_mem_vfree(pProbeRsp);
                 return;
             }
         }
@@ -413,7 +413,7 @@
     {
        PELOG1(limLog(pMac, LOG1,FL("Parse error ProbeResponse, length=%d"),
               frameLen);)
-       vos_mem_free(pProbeRsp);
+       vos_mem_vfree(pProbeRsp);
        return;
     }
     /*  Since there is no psessionEntry, PE cannot be in the following states:
@@ -445,7 +445,7 @@
         if (sirConvertProbeFrame2Struct(pMac, pBody, frameLen, pProbeRsp) == eSIR_FAILURE)
         {
             limLog(pMac, LOG1, FL("Parse error ProbeResponse, length=%d\n"), frameLen);
-            vos_mem_free(pProbeRsp);
+            vos_mem_vfree(pProbeRsp);
             return;
         }
         limLog( pMac, LOG2, FL("Save this probe rsp in LFR cache"));
@@ -466,7 +466,7 @@
         {
             limLog(pMac, LOG1,
                     FL("Parse error ProbeResponse, length=%d\n"), frameLen);
-            vos_mem_free(pProbeRsp);
+            vos_mem_vfree(pProbeRsp);
             return;
         }
         limCheckAndAddBssDescription(pMac, pProbeRsp, pRxPacketInfo,
@@ -492,7 +492,7 @@
         if (sirConvertProbeFrame2Struct(pMac, pBody, frameLen, pProbeRsp) == eSIR_FAILURE)
         {
             limLog(pMac, LOG1, FL("Parse error ProbeResponse, length=%d"), frameLen);
-            vos_mem_free(pProbeRsp);
+            vos_mem_vfree(pProbeRsp);
             return;
         }
 
@@ -503,6 +503,6 @@
         {
         }
     } 
-    vos_mem_free(pProbeRsp);
+    vos_mem_vfree(pProbeRsp);
     return;
 } /*** end limProcessProbeRspFrameNew() ***/
diff --git a/CORE/MAC/src/pe/sch/schBeaconProcess.c b/CORE/MAC/src/pe/sch/schBeaconProcess.c
index 89bd716..3c30941 100644
--- a/CORE/MAC/src/pe/sch/schBeaconProcess.c
+++ b/CORE/MAC/src/pe/sch/schBeaconProcess.c
@@ -641,7 +641,7 @@
     /* Obtain the Max Tx power for the current regulatory  */
     regMax = cfgGetRegulatoryMaxTransmitPower( pMac, psessionEntry->currentOperChannel );
 #endif
-
+    MTRACE(macTrace(pMac, TRACE_CODE_RX_MGMT_PROCESS, 0, 2 );)
 #if defined WLAN_FEATURE_VOWIFI
     {
         tPowerdBm  localRRMConstraint = 0;
@@ -699,8 +699,8 @@
 
     if(beaconParams.paramChangeBitmap)
     {
-        PELOGW(schLog(pMac, LOGW, FL("Beacon for session[%d] got changed. "), psessionEntry->peSessionId);)
-        PELOGW(schLog(pMac, LOGW, FL("sending beacon param change bitmap: 0x%x "), beaconParams.paramChangeBitmap);)
+        schLog(pMac, LOGW, FL("Beacon for session[%d] got changed. "), psessionEntry->peSessionId);
+        schLog(pMac, LOGW, FL("sending beacon param change bitmap: 0x%x "), beaconParams.paramChangeBitmap);
         limSendBeaconParams(pMac, &beaconParams, psessionEntry);
     }
 
@@ -746,7 +746,7 @@
 
         return;
     }
-
+    MTRACE(macTrace(pMac, TRACE_CODE_RX_MGMT_PROCESS, 0, 1 );)
     if (beaconStruct.ssidPresent)
     {
         beaconStruct.ssId.ssId[beaconStruct.ssId.length] = 0;
diff --git a/CORE/SME/src/csr/csrApiScan.c b/CORE/SME/src/csr/csrApiScan.c
index 1586887..1edb558 100644
--- a/CORE/SME/src/csr/csrApiScan.c
+++ b/CORE/SME/src/csr/csrApiScan.c
@@ -8412,7 +8412,7 @@
 
 
    pParsedFrame =
-       (tpSirProbeRespBeacon)vos_mem_malloc(sizeof(tSirProbeRespBeacon));
+       (tpSirProbeRespBeacon)vos_mem_vmalloc(sizeof(tSirProbeRespBeacon));
 
    if (NULL == pParsedFrame)
    {
@@ -8425,7 +8425,7 @@
       smsLog(pMac, LOGE,
          FL("Not enough bytes in PNO indication probe resp frame! length=%d"),
          pPrefNetworkFoundInd->frameLength);
-      vos_mem_free(pParsedFrame);
+      vos_mem_vfree(pParsedFrame);
       return eHAL_STATUS_FAILURE;
    }
 
@@ -8438,7 +8438,7 @@
       smsLog(pMac, LOGE,
          FL("Parse error ProbeResponse, length=%d"),
          pPrefNetworkFoundInd->frameLength);
-      vos_mem_free(pParsedFrame);
+      vos_mem_vfree(pParsedFrame);
       return eHAL_STATUS_FAILURE;
    }
    //24 byte MAC header and 12 byte to ssid IE
@@ -8505,7 +8505,7 @@
    {
       smsLog(pMac, LOGE, FL(" sme_GetCfgValidChannels failed "));
       csrFreeScanResultEntry(pMac, pScanResult);
-      vos_mem_free(pParsedFrame);
+      vos_mem_vfree(pParsedFrame);
       return eHAL_STATUS_FAILURE;
    }
    /* Checking chhanelId with allowed channel list */
@@ -8526,7 +8526,7 @@
       smsLog(pMac, LOGW, FL(" prefered network found on invalid channel = %d"),
                                                          pBssDescr->channelId);
       csrFreeScanResultEntry(pMac, pScanResult);
-      vos_mem_free(pParsedFrame);
+      vos_mem_vfree(pParsedFrame);
       return eHAL_STATUS_FAILURE;
    }
 
@@ -8592,7 +8592,7 @@
    {
       smsLog(pMac, LOGE, FL("  Cannot parse IEs"));
       csrFreeScanResultEntry(pMac, pScanResult);
-      vos_mem_free(pParsedFrame);
+      vos_mem_vfree(pParsedFrame);
       return eHAL_STATUS_RESOURCES;
    }
 
@@ -8620,7 +8620,7 @@
        vos_mem_free(pIesLocal);
    }
 
-   vos_mem_free(pParsedFrame);
+   vos_mem_vfree(pParsedFrame);
 
    return eHAL_STATUS_SUCCESS;
 }
diff --git a/CORE/SYS/legacy/src/utils/src/parserApi.c b/CORE/SYS/legacy/src/utils/src/parserApi.c
index c3f7969..66b381e 100644
--- a/CORE/SYS/legacy/src/utils/src/parserApi.c
+++ b/CORE/SYS/legacy/src/utils/src/parserApi.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012-2014 The Linux Foundation. All rights reserved.
+ * Copyright (c) 2012-2015 The Linux Foundation. All rights reserved.
  *
  * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
  *
@@ -2088,7 +2088,7 @@
     // Ok, zero-init our [out] parameter,
     vos_mem_set( ( tANI_U8* )pProbeResp, sizeof(tSirProbeRespBeacon), 0 );
 
-    pr = vos_mem_malloc(sizeof(tDot11fProbeResponse));
+    pr = vos_mem_vmalloc(sizeof(tDot11fProbeResponse));
     if ( NULL == pr )
         status = eHAL_STATUS_FAILURE;
     else
@@ -2108,7 +2108,7 @@
         limLog(pMac, LOGE, FL("Failed to parse a Probe Response (0x%08x, %d bytes):\n"),
                   status, nFrame);
         PELOG2(sirDumpBuf(pMac, SIR_DBG_MODULE_ID, LOG2, pFrame, nFrame);)
-        vos_mem_free(pr);
+        vos_mem_vfree(pr);
         return eSIR_FAILURE;
     }
     else if ( DOT11F_WARNED( status ) )
@@ -2321,7 +2321,7 @@
         vos_mem_copy( &pProbeResp->VHTExtBssLoad, &pr->VHTExtBssLoad, sizeof( tDot11fIEVHTExtBssLoad) );
     }
 #endif
-    vos_mem_free(pr);
+    vos_mem_vfree(pr);
     return eSIR_SUCCESS;
 
 } // End sirConvertProbeFrame2Struct.
@@ -3442,7 +3442,7 @@
     // Zero-init our [out] parameter,
     vos_mem_set( ( tANI_U8* )pBeaconStruct, sizeof(tSirProbeRespBeacon), 0 );
 
-    pBeacon = vos_mem_malloc(sizeof(tDot11fBeacon));
+    pBeacon = vos_mem_vmalloc(sizeof(tDot11fBeacon));
     if ( NULL == pBeacon )
         status = eHAL_STATUS_FAILURE;
     else
@@ -3465,7 +3465,7 @@
         limLog(pMac, LOGE, FL("Failed to parse Beacon IEs (0x%08x, %d bytes):\n"),
                   status, nPayload);
         PELOG2(sirDumpBuf(pMac, SIR_DBG_MODULE_ID, LOG2, pPayload, nPayload);)
-        vos_mem_free(pBeacon);
+        vos_mem_vfree(pBeacon);
         return eSIR_FAILURE;
     }
     else if ( DOT11F_WARNED( status ) )
@@ -3725,7 +3725,7 @@
                      &pBeacon->OBSSScanParameters,
                      sizeof( tDot11fIEOBSSScanParameters));
     }
-    vos_mem_free(pBeacon);
+    vos_mem_vfree(pBeacon);
     return eSIR_SUCCESS;
 
 } // End sirConvertBeaconFrame2Struct.