wlan: Reduce the stack size in the CORE Stack module.

Allocate dynamic memory and free the memory at the end of the function
or any error cases.

Change-Id: I0d1865e6741165e00e4231d1967fd5907a558da6
CR-Fixed: 397801
diff --git a/CORE/MAC/src/pe/lim/limFT.c b/CORE/MAC/src/pe/lim/limFT.c
index 50d1444..f181c2f 100644
--- a/CORE/MAC/src/pe/lim/limFT.c
+++ b/CORE/MAC/src/pe/lim/limFT.c
@@ -362,13 +362,20 @@
     tpAddBssParams pAddBssParams = NULL;
     tANI_U8 i;
     tANI_U8 chanWidthSupp = 0;
-    tSchBeaconStruct beaconStruct;
+    tSchBeaconStruct *pBeaconStruct;
 
+    if(eHAL_STATUS_SUCCESS != palAllocateMemory(pMac->hHdd, 
+                                                (void **)&pBeaconStruct, sizeof(tSchBeaconStruct)))
+    {
+        limLog(pMac, LOGE, FL("Unable to PAL allocate memory for creating ADD_BSS\n") );
+        return eSIR_MEM_ALLOC_FAILED;
+    }
 
     // Package SIR_HAL_ADD_BSS_REQ message parameters
     if( eHAL_STATUS_SUCCESS != palAllocateMemory( pMac->hHdd,
         (void **) &pAddBssParams, sizeof( tAddBssParams )))
     {
+        palFreeMemory(pMac->hHdd, pBeaconStruct);
         limLog( pMac, LOGP,
                 FL( "Unable to PAL allocate memory for creating ADD_BSS\n" ));
         return (eSIR_MEM_ALLOC_FAILED);
@@ -379,10 +386,10 @@
 
     limExtractApCapabilities( pMac,
         (tANI_U8 *) bssDescription->ieFields,
-        limGetIElenFromBssDescription( bssDescription ), &beaconStruct );
+        limGetIElenFromBssDescription( bssDescription ), pBeaconStruct );
 
     if (pMac->lim.gLimProtectionControl != WNI_CFG_FORCE_POLICY_PROTECTION_DISABLE)
-        limDecideStaProtectionOnAssoc(pMac, &beaconStruct, pftSessionEntry);
+        limDecideStaProtectionOnAssoc(pMac, pBeaconStruct, pftSessionEntry);
 
     palCopyMemory( pMac->hHdd, pAddBssParams->bssId, bssDescription->bssId,
         sizeof( tSirMacAddr ));
@@ -396,57 +403,57 @@
 
     pAddBssParams->beaconInterval = bssDescription->beaconInterval;
     
-    pAddBssParams->dtimPeriod = beaconStruct.tim.dtimPeriod;
+    pAddBssParams->dtimPeriod = pBeaconStruct->tim.dtimPeriod;
     pAddBssParams->updateBss = updateEntry;
 
 
-    pAddBssParams->cfParamSet.cfpCount = beaconStruct.cfParamSet.cfpCount;
-    pAddBssParams->cfParamSet.cfpPeriod = beaconStruct.cfParamSet.cfpPeriod;
-    pAddBssParams->cfParamSet.cfpMaxDuration = beaconStruct.cfParamSet.cfpMaxDuration;
-    pAddBssParams->cfParamSet.cfpDurRemaining = beaconStruct.cfParamSet.cfpDurRemaining;
+    pAddBssParams->cfParamSet.cfpCount = pBeaconStruct->cfParamSet.cfpCount;
+    pAddBssParams->cfParamSet.cfpPeriod = pBeaconStruct->cfParamSet.cfpPeriod;
+    pAddBssParams->cfParamSet.cfpMaxDuration = pBeaconStruct->cfParamSet.cfpMaxDuration;
+    pAddBssParams->cfParamSet.cfpDurRemaining = pBeaconStruct->cfParamSet.cfpDurRemaining;
 
 
-    pAddBssParams->rateSet.numRates = beaconStruct.supportedRates.numRates;
+    pAddBssParams->rateSet.numRates = pBeaconStruct->supportedRates.numRates;
     palCopyMemory( pMac->hHdd,  pAddBssParams->rateSet.rate,
-                   beaconStruct.supportedRates.rate, beaconStruct.supportedRates.numRates );
+                   pBeaconStruct->supportedRates.rate, pBeaconStruct->supportedRates.numRates );
 
     pAddBssParams->nwType = bssDescription->nwType;
     
-    pAddBssParams->shortSlotTimeSupported = (tANI_U8)beaconStruct.capabilityInfo.shortSlotTime; 
+    pAddBssParams->shortSlotTimeSupported = (tANI_U8)pBeaconStruct->capabilityInfo.shortSlotTime; 
     pAddBssParams->llaCoexist = (tANI_U8) pftSessionEntry->beaconParams.llaCoexist;
     pAddBssParams->llbCoexist = (tANI_U8) pftSessionEntry->beaconParams.llbCoexist;
     pAddBssParams->llgCoexist = (tANI_U8) pftSessionEntry->beaconParams.llgCoexist;
     pAddBssParams->ht20Coexist = (tANI_U8) pftSessionEntry->beaconParams.ht20Coexist;
 
     // Use the advertised capabilities from the received beacon/PR
-    if (IS_DOT11_MODE_HT(pftSessionEntry->dot11mode) && ( beaconStruct.HTCaps.present ))
+    if (IS_DOT11_MODE_HT(pftSessionEntry->dot11mode) && ( pBeaconStruct->HTCaps.present ))
     {
-        pAddBssParams->htCapable = beaconStruct.HTCaps.present;
+        pAddBssParams->htCapable = pBeaconStruct->HTCaps.present;
 
-        if ( beaconStruct.HTInfo.present )
+        if ( pBeaconStruct->HTInfo.present )
         {
-            pAddBssParams->htOperMode = (tSirMacHTOperatingMode)beaconStruct.HTInfo.opMode;
-            pAddBssParams->dualCTSProtection = ( tANI_U8 ) beaconStruct.HTInfo.dualCTSProtection;
+            pAddBssParams->htOperMode = (tSirMacHTOperatingMode)pBeaconStruct->HTInfo.opMode;
+            pAddBssParams->dualCTSProtection = ( tANI_U8 ) pBeaconStruct->HTInfo.dualCTSProtection;
 
 #ifdef WLAN_SOFTAP_FEATURE
             chanWidthSupp = limGetHTCapability( pMac, eHT_SUPPORTED_CHANNEL_WIDTH_SET, pftSessionEntry);
 #else 
             chanWidthSupp = limGetHTCapability( pMac, eHT_SUPPORTED_CHANNEL_WIDTH_SET);
 #endif
-            if( (beaconStruct.HTCaps.supportedChannelWidthSet) &&
+            if( (pBeaconStruct->HTCaps.supportedChannelWidthSet) &&
                 (chanWidthSupp) )
             {
-                pAddBssParams->txChannelWidthSet = ( tANI_U8 ) beaconStruct.HTInfo.recommendedTxWidthSet;
-                pAddBssParams->currentExtChannel = beaconStruct.HTInfo.secondaryChannelOffset;
+                pAddBssParams->txChannelWidthSet = ( tANI_U8 ) pBeaconStruct->HTInfo.recommendedTxWidthSet;
+                pAddBssParams->currentExtChannel = pBeaconStruct->HTInfo.secondaryChannelOffset;
             }
             else
             {
                 pAddBssParams->txChannelWidthSet = WNI_CFG_CHANNEL_BONDING_MODE_DISABLE;
                 pAddBssParams->currentExtChannel = PHY_SINGLE_CHANNEL_CENTERED;
             }
-            pAddBssParams->llnNonGFCoexist = (tANI_U8)beaconStruct.HTInfo.nonGFDevicesPresent;
-            pAddBssParams->fLsigTXOPProtectionFullSupport = (tANI_U8)beaconStruct.HTInfo.lsigTXOPProtectionFullSupport;
-            pAddBssParams->fRIFSMode = beaconStruct.HTInfo.rifsMode;
+            pAddBssParams->llnNonGFCoexist = (tANI_U8)pBeaconStruct->HTInfo.nonGFDevicesPresent;
+            pAddBssParams->fLsigTXOPProtectionFullSupport = (tANI_U8)pBeaconStruct->HTInfo.lsigTXOPProtectionFullSupport;
+            pAddBssParams->fRIFSMode = pBeaconStruct->HTInfo.rifsMode;
         }
     }
 
@@ -471,40 +478,40 @@
         pAddBssParams->staContext.assocId = 0; // Is SMAC OK with this?
         pAddBssParams->staContext.uAPSD = 0;
         pAddBssParams->staContext.maxSPLen = 0;
-        pAddBssParams->staContext.shortPreambleSupported = (tANI_U8)beaconStruct.capabilityInfo.shortPreamble;
+        pAddBssParams->staContext.shortPreambleSupported = (tANI_U8)pBeaconStruct->capabilityInfo.shortPreamble;
         pAddBssParams->staContext.updateSta = updateEntry;
         pAddBssParams->staContext.encryptType = pftSessionEntry->encryptType;
 
-        if (IS_DOT11_MODE_HT(pftSessionEntry->dot11mode) && ( beaconStruct.HTCaps.present ))
+        if (IS_DOT11_MODE_HT(pftSessionEntry->dot11mode) && ( pBeaconStruct->HTCaps.present ))
         {
             pAddBssParams->staContext.us32MaxAmpduDuration = 0;
             pAddBssParams->staContext.htCapable = 1;
-            pAddBssParams->staContext.greenFieldCapable  = ( tANI_U8 ) beaconStruct.HTCaps.greenField;
-            pAddBssParams->staContext.lsigTxopProtection = ( tANI_U8 ) beaconStruct.HTCaps.lsigTXOPProtection;
-            if( (beaconStruct.HTCaps.supportedChannelWidthSet) &&
+            pAddBssParams->staContext.greenFieldCapable  = ( tANI_U8 ) pBeaconStruct->HTCaps.greenField;
+            pAddBssParams->staContext.lsigTxopProtection = ( tANI_U8 ) pBeaconStruct->HTCaps.lsigTXOPProtection;
+            if( (pBeaconStruct->HTCaps.supportedChannelWidthSet) &&
                 (chanWidthSupp) )
             {
-                pAddBssParams->staContext.txChannelWidthSet = ( tANI_U8 )beaconStruct.HTInfo.recommendedTxWidthSet;
+                pAddBssParams->staContext.txChannelWidthSet = ( tANI_U8 )pBeaconStruct->HTInfo.recommendedTxWidthSet;
             }
             else
             {
                 pAddBssParams->staContext.txChannelWidthSet = WNI_CFG_CHANNEL_BONDING_MODE_DISABLE;
             }                                                           
-            pAddBssParams->staContext.mimoPS             = (tSirMacHTMIMOPowerSaveState)beaconStruct.HTCaps.mimoPowerSave;
-            pAddBssParams->staContext.delBASupport       = ( tANI_U8 ) beaconStruct.HTCaps.delayedBA;
-            pAddBssParams->staContext.maxAmsduSize       = ( tANI_U8 ) beaconStruct.HTCaps.maximalAMSDUsize;
-            pAddBssParams->staContext.maxAmpduDensity    =             beaconStruct.HTCaps.mpduDensity;
-            pAddBssParams->staContext.fDsssCckMode40Mhz = (tANI_U8)beaconStruct.HTCaps.dsssCckMode40MHz;
-            pAddBssParams->staContext.fShortGI20Mhz = (tANI_U8)beaconStruct.HTCaps.shortGI20MHz;
-            pAddBssParams->staContext.fShortGI40Mhz = (tANI_U8)beaconStruct.HTCaps.shortGI40MHz;
-            pAddBssParams->staContext.maxAmpduSize= beaconStruct.HTCaps.maxRxAMPDUFactor;
+            pAddBssParams->staContext.mimoPS             = (tSirMacHTMIMOPowerSaveState)pBeaconStruct->HTCaps.mimoPowerSave;
+            pAddBssParams->staContext.delBASupport       = ( tANI_U8 ) pBeaconStruct->HTCaps.delayedBA;
+            pAddBssParams->staContext.maxAmsduSize       = ( tANI_U8 ) pBeaconStruct->HTCaps.maximalAMSDUsize;
+            pAddBssParams->staContext.maxAmpduDensity    =             pBeaconStruct->HTCaps.mpduDensity;
+            pAddBssParams->staContext.fDsssCckMode40Mhz = (tANI_U8)pBeaconStruct->HTCaps.dsssCckMode40MHz;
+            pAddBssParams->staContext.fShortGI20Mhz = (tANI_U8)pBeaconStruct->HTCaps.shortGI20MHz;
+            pAddBssParams->staContext.fShortGI40Mhz = (tANI_U8)pBeaconStruct->HTCaps.shortGI40MHz;
+            pAddBssParams->staContext.maxAmpduSize= pBeaconStruct->HTCaps.maxRxAMPDUFactor;
             
-            if( beaconStruct.HTInfo.present )
-                pAddBssParams->staContext.rifsMode = beaconStruct.HTInfo.rifsMode;
+            if( pBeaconStruct->HTInfo.present )
+                pAddBssParams->staContext.rifsMode = pBeaconStruct->HTInfo.rifsMode;
         }
 
-        if ((pftSessionEntry->limWmeEnabled && beaconStruct.wmeEdcaPresent) ||
-                (pftSessionEntry->limQosEnabled && beaconStruct.edcaPresent))
+        if ((pftSessionEntry->limWmeEnabled && pBeaconStruct->wmeEdcaPresent) ||
+                (pftSessionEntry->limQosEnabled && pBeaconStruct->edcaPresent))
             pAddBssParams->staContext.wmmEnabled = 1;
         else 
             pAddBssParams->staContext.wmmEnabled = 0;
@@ -512,8 +519,8 @@
         //Update the rates
 #ifdef WLAN_FEATURE_11AC
         limPopulateOwnRateSet(pMac, &pAddBssParams->staContext.supportedRates, 
-                             beaconStruct.HTCaps.supportedMCSSet, 
-                             false,pftSessionEntry,&beaconStruct.VHTCaps);
+                             pBeaconStruct->HTCaps.supportedMCSSet, 
+                             false,pftSessionEntry,&pBeaconStruct->VHTCaps);
 #else
         limPopulateOwnRateSet(pMac, &pAddBssParams->staContext.supportedRates, 
                                                     beaconStruct.HTCaps.supportedMCSSet, false,pftSessionEntry);
@@ -554,6 +561,7 @@
     limLog( pMac, LOGE, FL( "Saving SIR_HAL_ADD_BSS_REQ for pre-auth ap..." ));
 #endif
 
+    palFreeMemory(pMac->hHdd, pBeaconStruct);
     return 0;
 }
 
@@ -571,12 +579,21 @@
     tANI_U8          sessionId;
     tPowerdBm        localPowerConstraint;
     tPowerdBm        regMax;
-    tSchBeaconStruct beaconStruct;
+    tSchBeaconStruct *pBeaconStruct;
+
+    if(eHAL_STATUS_SUCCESS != palAllocateMemory(pMac->hHdd, 
+                                                (void **)&pBeaconStruct, sizeof(tSchBeaconStruct)))
+    {
+        limLog(pMac, LOGE, FL("Unable to PAL allocate memory for creating limFillFTSession\n") );
+        return NULL;
+    }
+
 
     if((pftSessionEntry = peCreateSession(pMac, pbssDescription->bssId,
         &sessionId, pMac->lim.maxStation)) == NULL)
     {
         limLog(pMac, LOGE, FL("Session Can not be created for pre-auth 11R AP\n"));
+        palFreeMemory(pMac->hHdd, pBeaconStruct);
         return NULL;
     }
         
@@ -603,19 +620,19 @@
     limExtractApCapabilities( pMac,
                             (tANI_U8 *) pbssDescription->ieFields,
                             limGetIElenFromBssDescription( pbssDescription ),
-                            &beaconStruct );
+                            pBeaconStruct );
 
-    pftSessionEntry->rateSet.numRates = beaconStruct.supportedRates.numRates;
+    pftSessionEntry->rateSet.numRates = pBeaconStruct->supportedRates.numRates;
     palCopyMemory( pMac->hHdd,  pftSessionEntry->rateSet.rate,
-        beaconStruct.supportedRates.rate, beaconStruct.supportedRates.numRates );
+        pBeaconStruct->supportedRates.rate, pBeaconStruct->supportedRates.numRates );
 
-    pftSessionEntry->extRateSet.numRates = beaconStruct.extendedRates.numRates;
+    pftSessionEntry->extRateSet.numRates = pBeaconStruct->extendedRates.numRates;
     palCopyMemory(pMac->hHdd, pftSessionEntry->extRateSet.rate, 
-        beaconStruct.extendedRates.rate, pftSessionEntry->extRateSet.numRates);
+        pBeaconStruct->extendedRates.rate, pftSessionEntry->extRateSet.numRates);
 
 
-    pftSessionEntry->ssId.length = beaconStruct.ssId.length;
-    palCopyMemory( pMac->hHdd, pftSessionEntry->ssId.ssId, beaconStruct.ssId.ssId,
+    pftSessionEntry->ssId.length = pBeaconStruct->ssId.length;
+    palCopyMemory( pMac->hHdd, pftSessionEntry->ssId.ssId, pBeaconStruct->ssId.ssId,
         pftSessionEntry->ssId.length);
 
 
@@ -688,6 +705,7 @@
        __FUNCTION__, pftSessionEntry->peSessionId);)
 #endif
 
+    palFreeMemory(pMac->hHdd, pBeaconStruct);
     return pftSessionEntry;
 }