wlan: Use opclass to get the channel width from ECSA IE

In ECSA channel switch opclass is not used to get the channel
width. Use opclass to get the channel width from ECSA IE.

Change-Id: If6df70a693ec764bf662157fb7b9ef444a130473
CRs-Fixed: 2360835
diff --git a/CORE/MAC/src/pe/lim/limProcessTdls.c b/CORE/MAC/src/pe/lim/limProcessTdls.c
index 0fd0050..9bed290 100644
--- a/CORE/MAC/src/pe/lim/limProcessTdls.c
+++ b/CORE/MAC/src/pe/lim/limProcessTdls.c
@@ -3565,6 +3565,44 @@
     return offset;
 }
 
+offset_t lim_get_channel_width_from_opclass(tANI_U8 *country, tANI_U8 channel,
+                                            tANI_U8 peer_vht_capable,
+                                            tANI_U8 op_class)
+{
+    op_class_map_t *class;
+    tANI_U16 i = 0;
+    offset_t offset, max_allowed;
+
+    if (peer_vht_capable &&
+        IS_FEATURE_SUPPORTED_BY_FW(DOT11AC) &&
+        IS_FEATURE_SUPPORTED_BY_DRIVER(DOT11AC))
+        max_allowed = BW80;
+    else
+        max_allowed = BW40MINUS;
+
+    if (vos_mem_compare(country,"US", 2))
+        class = us_op_class;
+    else if (vos_mem_compare(country,"EU", 2))
+        class = euro_op_class;
+    else if (vos_mem_compare(country,"JP", 2))
+        class = japan_op_class;
+    else
+        class = global_op_class;
+
+    while (class->op_class) {
+        if (op_class == class->op_class) {
+            for (i = 0; (i < 25 && class->channels[i]); i++) {
+                 if (channel == class->channels[i]) {
+                     offset = class->offset;
+                     return (offset <= max_allowed) ? offset: BW20;
+                 }
+            }
+        }
+        class++;
+    }
+
+    return BW20;
+}
 
 tANI_U8 limGetOPClassFromChannel(tANI_U8 *country,
                                          tANI_U8 channel,
diff --git a/CORE/MAC/src/pe/lim/limUtils.c b/CORE/MAC/src/pe/lim/limUtils.c
index 547caff..e0f4560 100644
--- a/CORE/MAC/src/pe/lim/limUtils.c
+++ b/CORE/MAC/src/pe/lim/limUtils.c
@@ -2967,10 +2967,11 @@
    session->gLimChannelSwitch.secondarySubBand = PHY_SINGLE_CHANNEL_CENTERED;
    session->gLimWiderBWChannelSwitch.newChanWidth = 0;
 
-   ch_offset = limGetOffChMaxBwOffsetFromChannel(
-                       mac_ctx->scan.countryCodeCurrent,
-                       ecsa_req->new_channel,
-                       sta_ds->mlmStaContext.vhtCapability);
+   ch_offset =
+       lim_get_channel_width_from_opclass(mac_ctx->scan.countryCodeCurrent,
+                                          ecsa_req->new_channel,
+                                          sta_ds->mlmStaContext.vhtCapability,
+                                          ecsa_req->op_class);
    if (ch_offset == BW80) {
        session->gLimWiderBWChannelSwitch.newChanWidth =
                                   WNI_CFG_VHT_CHANNEL_WIDTH_80MHZ;
diff --git a/CORE/MAC/src/pe/lim/limUtils.h b/CORE/MAC/src/pe/lim/limUtils.h
index 5801f52..ed1f17a 100644
--- a/CORE/MAC/src/pe/lim/limUtils.h
+++ b/CORE/MAC/src/pe/lim/limUtils.h
@@ -572,9 +572,19 @@
 tANI_U8 limGetOPClassFromChannel(tANI_U8 *country,
                                  tANI_U8 channel,
                                  tANI_U8 offset);
-tANI_U8 limGetOffChMaxBwOffsetFromChannel(tANI_U8 *country,
-                                          tANI_U8 channel,
-                                          tANI_U8 peerVHTCapability);
+
+/**
+ * lim_get_channel_width_from_opclass() - get the channel offset for the opclass
+ * @country: current country code
+ * @channel: channel for which width is required
+ * @peer_vht_capable: if peer is VHT capable
+ * @op_class: Opclass provided
+ *
+ * Return: channel offset for the opclass
+ */
+offset_t lim_get_channel_width_from_opclass(tANI_U8 *country, tANI_U8 channel,
+                                            tANI_U8 peer_vht_capable,
+                                            tANI_U8 op_class);
 
 void limParseBeaconForTim(tpAniSirGlobal pMac, tANI_U8* pRxPacketInfo,
                           tpPESession psessionEntry);