wlan: Updating the scanlist based on the 11d info from AP

Updating the channel list from nv.bin based on the changed country code

CRs-Fixed: 449915
Change-Id: Ie29a278c52edc2d3448814459d41e58f4a288b02
diff --git a/CORE/SME/inc/csrInternal.h b/CORE/SME/inc/csrInternal.h
index d617d8c..f071385 100644
--- a/CORE/SME/inc/csrInternal.h
+++ b/CORE/SME/inc/csrInternal.h
@@ -1078,6 +1078,8 @@
 void csrScanResumeIMPS( tpAniSirGlobal pMac );
 
 eHalStatus csrInitGetChannels(tpAniSirGlobal pMac);
+// Getting the 5GHz Channel list
+eHalStatus csrGet5GChannels(tpAniSirGlobal pMac) ;
 
 eHalStatus csrSetModifyProfileFields(tpAniSirGlobal pMac, tANI_U32 sessionId,
                                      tCsrRoamModifyProfileFields *pModifyProfileFields);
diff --git a/CORE/SME/src/csr/csrApiRoam.c b/CORE/SME/src/csr/csrApiRoam.c
index af26251..03c004f 100644
--- a/CORE/SME/src/csr/csrApiRoam.c
+++ b/CORE/SME/src/csr/csrApiRoam.c
@@ -1871,6 +1871,49 @@
     }
     return status;
 }
+
+eHalStatus csrGet5GChannels(tpAniSirGlobal pMac)
+{
+    eHalStatus status = eHAL_STATUS_SUCCESS;
+    tANI_U8 num20MHzChannelsFound = 0;
+    VOS_STATUS vosStatus;
+    tANI_U8 num40MHzChannelsFound = 0;
+    tANI_U8 Index = 0;
+
+    vosStatus = vos_nv_get5GChannelListWithPower( pMac->scan.defaultPowerTable, &num20MHzChannelsFound,
+                                                  NULL, &num40MHzChannelsFound);
+    if ( (VOS_STATUS_SUCCESS != vosStatus) || (num20MHzChannelsFound == 0) )
+    {
+        smsLog( pMac, LOGE, FL("failed to get channels"));
+        status = eHAL_STATUS_FAILURE;
+    }
+    else
+    {
+        if ( num20MHzChannelsFound > WNI_CFG_VALID_CHANNEL_LIST_LEN )
+        {
+            num20MHzChannelsFound = WNI_CFG_VALID_CHANNEL_LIST_LEN;
+        }
+        pMac->scan.numChannelsDefault = num20MHzChannelsFound;
+        // Move the channel list to the global data
+        // structure -- this will be used as the scan list
+        for ( Index = 0; Index < num20MHzChannelsFound; Index++)
+        {
+           pMac->scan.base20MHzChannels.channelList[ Index ] = pMac->scan.defaultPowerTable[ Index ].chanId;
+        }
+        pMac->scan.base20MHzChannels.numChannels = num20MHzChannelsFound;
+        if ( num40MHzChannelsFound > WNI_CFG_VALID_CHANNEL_LIST_LEN )
+        {
+            num40MHzChannelsFound = WNI_CFG_VALID_CHANNEL_LIST_LEN;
+        }
+        for ( Index = 0; Index < num40MHzChannelsFound; Index++)
+        {
+            pMac->scan.base40MHzChannels.channelList[ Index ] = pMac->scan.defaultPowerTable40MHz[ Index ].chanId;
+        }
+        pMac->scan.base40MHzChannels.numChannels = num40MHzChannelsFound;
+    }
+    return status;
+}
+
 eHalStatus csrInitGetChannels(tpAniSirGlobal pMac)
 {
     eHalStatus status = eHAL_STATUS_SUCCESS;
diff --git a/CORE/SME/src/csr/csrApiScan.c b/CORE/SME/src/csr/csrApiScan.c
index 8cb0c64..0a9f39b 100644
--- a/CORE/SME/src/csr/csrApiScan.c
+++ b/CORE/SME/src/csr/csrApiScan.c
@@ -3508,7 +3508,6 @@
         {
             // else, we found channel info in the 2.4 GHz band.  If the 5.0 band is empty
             // set the 5.0 band info from the 2.4 country code.
-            if ( !csrLLIsListEmpty( &pMac->scan.channelPowerInfoList5G, LL_ACCESS_LOCK ) ) break;
             fPopulate5GBand = TRUE;
         }
         csrSaveChannelPowerForBand( pMac, fPopulate5GBand );
@@ -3734,6 +3733,12 @@
 
         // set the indicator of the channel where the country IE was found...
         pMac->scan.channelOf11dInfo = pSirBssDesc->channelId;
+        csrGetRegulatoryDomainForCountry(pMac, pIesLocal->Country.country, &domainId );
+        if ( domainId != pMac->scan.domainIdCurrent )
+        {
+            WDA_SetRegDomain(pMac, domainId);
+            csrGet5GChannels(pMac );
+        }
         // Populate both band channel lists based on what we found in the country information...
         csrSetOppositeBandChannelInfo( pMac );
         bMaxNumChn = WNI_CFG_VALID_CHANNEL_LIST_LEN;
diff --git a/CORE/VOSS/inc/vos_nvitem.h b/CORE/VOSS/inc/vos_nvitem.h
index b51a1a2..e4801b0 100644
--- a/CORE/VOSS/inc/vos_nvitem.h
+++ b/CORE/VOSS/inc/vos_nvitem.h
@@ -599,6 +599,23 @@
                                           );
 
 /**------------------------------------------------------------------------
+  \brief vos_nv_get5GChannelListWithPower() - function to return the list of
+          supported 5G channels with the power limit info too.
+  \param pChannels20MHz - list of 20 Mhz channels
+  \param pNum20MHzChannelsFound - number of 20 Mhz channels
+  \param pChannels40MHz - list of 20 Mhz channels
+  \param pNum40MHzChannelsFound - number of 20 Mhz channels
+  \return status of the NV read operation
+  \Note: 40Mhz not currently supported
+  \sa
+  -------------------------------------------------------------------------*/
+VOS_STATUS vos_nv_get5GChannelListWithPower(tChannelListWithPower *pChannels20MHz /*[NUM_LEGIT_RF_CHANNELS] */,
+                                          tANI_U8 *pNum20MHzChannelsFound,
+                                          tChannelListWithPower *pChannels40MHz /*[NUM_CHAN_BOND_CHANNELS] */,
+                                          tANI_U8 *pNum40MHzChannelsFound
+                                          );
+
+/**------------------------------------------------------------------------
 
   \brief vos_nv_open() - initialize the NV module
 
diff --git a/CORE/VOSS/src/vos_nvitem.c b/CORE/VOSS/src/vos_nvitem.c
index 1647de0..8547027 100644
--- a/CORE/VOSS/src/vos_nvitem.c
+++ b/CORE/VOSS/src/vos_nvitem.c
@@ -1591,7 +1591,48 @@
    }
    return status;
 }
-  
+
+VOS_STATUS vos_nv_get5GChannelListWithPower(tChannelListWithPower *channels20MHz /*[NUM_LEGIT_RF_CHANNELS] */,
+                                          tANI_U8 *num20MHzChannelsFound,
+                                          tChannelListWithPower *channels40MHz /*[NUM_CHAN_BOND_CHANNELS] */,
+                                          tANI_U8 *num40MHzChannelsFound
+                                          )
+{
+    VOS_STATUS status = VOS_STATUS_SUCCESS;
+    int i, count;
+
+
+    if ( channels20MHz && num20MHzChannelsFound )
+    {
+        count = 0;
+        for ( i = RF_CHAN_36; i <= RF_CHAN_165; i++ )
+        {
+            if ( regChannels[i].enabled )
+            {
+                channels20MHz[count].chanId = rfChannels[i].channelNum;
+                channels20MHz[count++].pwr  = regChannels[i].pwrLimit;
+            }
+        }
+        *num20MHzChannelsFound = (tANI_U8)count;
+    }
+
+    if ( channels40MHz && num40MHzChannelsFound )
+    {
+        count = 0;
+        //center channels for 5 Ghz 40 MHz channels
+        for ( i = RF_CHAN_BOND_38; i <= RF_CHAN_BOND_163; i++ )
+        {
+            if ( regChannels[i].enabled )
+            {
+                channels40MHz[count].chanId = rfChannels[i].channelNum;
+                channels40MHz[count++].pwr  = regChannels[i].pwrLimit;
+            }
+        }
+        *num40MHzChannelsFound = (tANI_U8)count;
+    }
+    return status;
+}
+
 /**------------------------------------------------------------------------
   \brief vos_nv_getChannelListWithPower() - function to return the list of
           supported channels with the power limit info too.