wlan: Update the maximum transit power of an STA.

According to the spec, the local maximum transmit power for a channel
is defined as the maximum transmit powerlevel specified for the
channel in the Country element minus the local power constraint
specified for the channel in the Power Constraint element. This
fix updates the max transmit power according to the spec before
sending it to the FW.

Change-Id: I30c3ec5054651863cd200f92528b7dffa74403d1
CRS-Fixed: 679356
diff --git a/CORE/MAC/src/pe/lim/limPropExtsUtils.c b/CORE/MAC/src/pe/lim/limPropExtsUtils.c
index ddf0ee4..80510e1 100644
--- a/CORE/MAC/src/pe/lim/limPropExtsUtils.c
+++ b/CORE/MAC/src/pe/lim/limPropExtsUtils.c
@@ -53,6 +53,7 @@
 #include "limTrace.h"
 #include "limSession.h"
 #define LIM_GET_NOISE_MAX_TRY 5
+#define LIM_OPERATING_EXT_IDENTIFIER 201
 /**
  * limExtractApCapability()
  *
@@ -134,6 +135,37 @@
         // Extract the UAPSD flag from WMM Parameter element
         if (pBeaconStruct->wmeEdcaPresent)
             *uapsd = pBeaconStruct->edcaParams.qosInfo.uapsd;
+
+        /* Get MaxTxPwr from country IE if present.
+           If the channel number field has a positive  integer value less
+           than 201, then it contains a positive integer value that indicates
+           the lowest channel number in the subband */
+
+        if (pBeaconStruct->countryInfoPresent &&
+            pBeaconStruct->countryInfoParam.channelTransmitPower[0].channelNumber < LIM_OPERATING_EXT_IDENTIFIER )
+        {
+            int i;
+            tANI_U8 firstChannel =0, numChannels =0;
+            tANI_U8 channel = psessionEntry->currentOperChannel;
+
+            for (i=0; i < pBeaconStruct->countryInfoParam.numIntervals; ++i)
+            {
+                if (i >= COUNTRY_INFO_MAX_CHANNEL)
+                    break;
+
+                firstChannel = pBeaconStruct->countryInfoParam.channelTransmitPower[i].channelNumber;
+                numChannels = pBeaconStruct->countryInfoParam.channelTransmitPower[i].numChannel;
+
+                if ((channel >= firstChannel) &&
+                    (channel < (firstChannel + numChannels)))
+                    break;
+            }
+
+            if (i < pBeaconStruct->countryInfoParam.numIntervals && i < COUNTRY_INFO_MAX_CHANNEL)
+            {
+                *localConstraint = pBeaconStruct->countryInfoParam.channelTransmitPower[i].maxTransmitPower;
+            }
+        }
 #if defined FEATURE_WLAN_ESE
         /* If there is Power Constraint Element specifically,
          * adapt to it. Hence there is else condition check
@@ -145,22 +177,11 @@
         }
 #endif
         if (pBeaconStruct->powerConstraintPresent)
-#if 0
-        //Remove this check. This function is expected to return localPowerConsraints
-        //and it should just do that. Check for 11h enabled or not can be done at the caller
-#if defined WLAN_FEATURE_VOWIFI
-          && ( pMac->lim.gLim11hEnable
-           || pMac->rrm.rrmPEContext.rrmEnable
-#endif
-#endif
         {
-#if defined WLAN_FEATURE_VOWIFI 
-           *localConstraint -= pBeaconStruct->localPowerConstraint.localPowerConstraints;
-#else
-           localPowerConstraints = (tANI_U32)pBeaconStruct->localPowerConstraint.localPowerConstraints;
-#endif
+            *localConstraint -= pBeaconStruct->localPowerConstraint.localPowerConstraints;
         }
 #if !defined WLAN_FEATURE_VOWIFI
+        localPowerConstraints = (tANI_U32)pBeaconStruct->localPowerConstraint.localPowerConstraints;
         if (cfgSetInt(pMac, WNI_CFG_LOCAL_POWER_CONSTRAINT, localPowerConstraints) != eSIR_SUCCESS)
         {
             limLog(pMac, LOGP, FL("Could not update local power constraint to cfg."));