[rdk-b][mt7986][wifi-hal][Refactor RadioMode]

[Description]
Refactor get and set RadioMode with enum and add tri-band supported.

[Release-log]
N/A

Change-Id: I9be3e1d804e0df3cc753ca17c9e0126a85ea1981
diff --git a/recipes-ccsp/hal/hal-wifi-patches/0037-HAL-add-get-and-set-radio-mode.patch b/recipes-ccsp/hal/hal-wifi-patches/0037-HAL-add-get-and-set-radio-mode.patch
index 3c97aee..657ba17 100644
--- a/recipes-ccsp/hal/hal-wifi-patches/0037-HAL-add-get-and-set-radio-mode.patch
+++ b/recipes-ccsp/hal/hal-wifi-patches/0037-HAL-add-get-and-set-radio-mode.patch
@@ -1,17 +1,33 @@
-From f3ddc9ecc94827f7d4e0884d57afed1878aebc69 Mon Sep 17 00:00:00 2001
+From 47094ac819aba0809c899fe8ad1083b319617813 Mon Sep 17 00:00:00 2001
 From: "Allen.Ye" <allen.ye@mediatek.com>
-Date: Wed, 17 Aug 2022 14:30:27 +0800
+Date: Thu, 8 Sep 2022 10:31:06 +0800
 Subject: [PATCH] HAL: add get and set radio mode
 
 ---
- source/wifi/wifi_hal.c | 135 ++++++++++++++++++++++++++++++++++++++++-
- 1 file changed, 133 insertions(+), 2 deletions(-)
+ source/wifi/wifi_hal.c | 120 ++++++++++++++++++++++++++++++++++++++++-
+ 1 file changed, 119 insertions(+), 1 deletion(-)
 
 diff --git a/source/wifi/wifi_hal.c b/source/wifi/wifi_hal.c
-index 1d7833d..b4628c9 100644
+index fa1af2e..9e17de6 100644
 --- a/source/wifi/wifi_hal.c
 +++ b/source/wifi/wifi_hal.c
-@@ -1526,10 +1526,59 @@ INT wifi_getRadioStandard(INT radioIndex, CHAR *output_string, BOOL *gOnly, BOOL
+@@ -170,6 +170,15 @@ typedef enum
+     band_6 = 2,
+ } wifi_band;
+ 
++typedef enum {
++    WIFI_MODE_A = 0x01,
++    WIFI_MODE_B = 0x02,
++    WIFI_MODE_G = 0x04,
++    WIFI_MODE_N = 0x08,
++    WIFI_MODE_AC = 0x10,
++    WIFI_MODE_AX = 0x20,
++} wifi_ieee80211_Mode;
++
+ #ifdef WIFI_HAL_VERSION_3
+ 
+ // Return number of elements in array
+@@ -1696,7 +1705,63 @@ INT wifi_getRadioStandard(INT radioIndex, CHAR *output_string, BOOL *gOnly, BOOL
  #endif
  }
  
@@ -21,6 +37,7 @@
 +    char cmd[128] = {0};
 +    char buf[64] = {0};
 +    char config_file[64] = {0};
++    wifi_band band;
 +
 +    WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
 +    if(NULL == output_string || NULL == pureMode)
@@ -28,36 +45,42 @@
 +
 +    // grep all of the ieee80211 protocol config set to 1
 +    snprintf(config_file, sizeof(cmd), "%s%d.conf", CONFIG_PREFIX, radioIndex);
-+    snprintf(cmd, sizeof(cmd), "cat %s | grep -E\"ieee.*=1\" | cut -d '=' -f1 | tr -d 'ieee80211'", config_file);
++    snprintf(cmd, sizeof(cmd), "cat %s | grep -E\"^ieee.*=1\" | cut -d '=' -f1 | tr -d 'ieee80211'", config_file);
 +    _syscmd(cmd, buf, sizeof(buf));
 +
++    band = wifi_index_to_band(radioIndex);
 +    // puremode is a bit map
 +    *pureMode = 0;
-+    if (radioIndex == 0) {
++    if (band == band_2_4) {
 +        strcat(output_string, "b,g");
-+        *pureMode |= 4;
++        *pureMode |= WIFI_MODE_B | WIFI_MODE_G;
 +        if (strstr(buf, "n") != NULL) {
 +            strcat(output_string, ",n");
-+            *pureMode |= 8;
++            *pureMode |= WIFI_MODE_N;
 +        }
 +        if (strstr(buf, "ax") != NULL) {
 +            strcat(output_string, ",ax");
-+            *pureMode |= 32;
++            *pureMode |= WIFI_MODE_AX;
 +        }
-+    } else if (radioIndex == 1) {
++    } else if (band == band_5) {
 +        strcat(output_string, "a");
-+        *pureMode |= 1;
++        *pureMode |= WIFI_MODE_A;
 +        if (strstr(buf, "n") != NULL) {
 +            strcat(output_string, ",n");
-+            *pureMode |= 8;
++            *pureMode |= WIFI_MODE_N;
 +        }
 +        if (strstr(buf, "ac") != NULL) {
 +            strcat(output_string, ",ac");
-+            *pureMode |= 16;
++            *pureMode |= WIFI_MODE_AC;
 +        }
 +        if (strstr(buf, "ax") != NULL) {
 +            strcat(output_string, ",ax");
-+            *pureMode |= 32;
++            *pureMode |= WIFI_MODE_AX;
++        }
++    } else if (band == band_6) {
++        if (strstr(buf, "ax") != NULL) {
++            strcat(output_string, "ax");
++            *pureMode |= WIFI_MODE_AX;
 +        }
 +    }
 +
@@ -68,12 +91,8 @@
 +// Set the radio operating mode, and pure mode flag.
  INT wifi_setRadioChannelMode(INT radioIndex, CHAR *channelMode, BOOL gOnlyFlag, BOOL nOnlyFlag, BOOL acOnlyFlag)	//RDKB
  {
--    WIFI_ENTRY_EXIT_DEBUG("Inside %s_%s_%d_%d:%d\n",__func__,channelMode,nOnlyFlag,gOnlyFlag,__LINE__);  
-+    WIFI_ENTRY_EXIT_DEBUG("Inside %s_%s_%d_%d:%d\n",__func__,channelMode,nOnlyFlag,gOnlyFlag,__LINE__);
-     if (strcmp (channelMode,"11A") == 0)
-     {
-         writeBandWidth(radioIndex,"20MHz");
-@@ -1621,6 +1670,88 @@ INT wifi_setRadioChannelMode(INT radioIndex, CHAR *channelMode, BOOL gOnlyFlag,
+     WIFI_ENTRY_EXIT_DEBUG("Inside %s_%s_%d_%d:%d\n",__func__,channelMode,nOnlyFlag,gOnlyFlag,__LINE__);  
+@@ -1791,6 +1856,59 @@ INT wifi_setRadioChannelMode(INT radioIndex, CHAR *channelMode, BOOL gOnlyFlag,
      return RETURN_OK;
  }
  
@@ -85,6 +104,7 @@
 +    char config_file[64] = {0};
 +    char bandwidth[16] = {0};
 +    int mode_check_bit = 1 << 3;    // n mode
++    wifi_ieee80211_Mode mode = (wifi_ieee80211_Mode)pureMode;
 +
 +    WIFI_ENTRY_EXIT_DEBUG("Inside %s_%d:%d\n", __func__, channelMode, pureMode, __LINE__);
 +    // Set radio mode
@@ -94,61 +114,31 @@
 +    snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, radioIndex);
 +
 +    // check the bit map from n to ax, and set hostapd config
-+    for(int i = 0; i < num_hostapd_support_mode; i++) {
-+        if (pureMode & mode_check_bit)
-+            list[i].value = "1";
-+        else
-+            list[i].value = "0";
-+        mode_check_bit = mode_check_bit << 1;
-+    }
++    if (mode & WIFI_MODE_N)
++        list[0].value = "1";
++    else
++        list[0].value = "0";
++    if (mode & WIFI_MODE_AC)
++        list[1].value = "1";
++    else
++        list[1].value = "0";
++    if (mode & WIFI_MODE_AX)
++        list[2].value = "1";
++    else
++        list[2].value = "0";
 +    wifi_hostapdWrite(config_file, list, num_hostapd_support_mode);
 +
++    if (channelMode == NULL || strlen(channelMode) == 0)
++        return RETURN_OK;
 +    // Set bandwidth
-+    // 5G
-+    if (strcmp (channelMode,"11A") == 0)
-+        strcpy(bandwidth, "20MHz");
-+    else if (strcmp (channelMode,"11NAHT20") == 0)
-+        strcpy(bandwidth, "20MHz");
-+    else if (strcmp (channelMode,"11NAHT40PLUS") == 0)
++    if (strstr(channelMode, "40") != NULL)
 +        strcpy(bandwidth, "40MHz");
-+    else if (strcmp (channelMode,"11NAHT40MINUS") == 0)
-+        strcpy(bandwidth, "40MHz");
-+    else if (strcmp (channelMode,"11ACVHT20") == 0)
-+        strcpy(bandwidth, "20MHz");
-+    else if (strcmp (channelMode,"11ACVHT40PLUS") == 0)
-+        strcpy(bandwidth, "40MHz");
-+    else if (strcmp (channelMode,"11ACVHT40MINUS") == 0)
-+        strcpy(bandwidth, "40MHz");
-+    else if (strcmp (channelMode,"11ACVHT80") == 0)
-+        strcpy(bandwidth, "80MHz");
-+    else if (strcmp (channelMode,"11ACVHT160") == 0)
-+        strcpy(bandwidth, "160MHz");
-+    else if (strcmp (channelMode,"11AXHE80") == 0)
++    else if (strstr(channelMode, "80") != NULL)
 +        strcpy(bandwidth, "80MHz");
-+    else if (strcmp (channelMode,"11AXHE160") == 0)
++    else if (strstr(channelMode, "160") != NULL)
 +        strcpy(bandwidth, "160MHz");
-+    // 2.4G
-+    else if (strcmp (channelMode,"11B") == 0)
++    else    // 11A, 11B, 11G....
 +        strcpy(bandwidth, "20MHz");
-+    else if (strcmp (channelMode,"11G") == 0)
-+        strcpy(bandwidth, "20MHz");
-+    else if (strcmp (channelMode,"11NGHT20") == 0)
-+        strcpy(bandwidth, "20MHz");
-+    else if (strcmp (channelMode,"11NGHT40PLUS") == 0)
-+        strcpy(bandwidth, "40MHz");
-+    else if (strcmp (channelMode,"11NGHT40MINUS") == 0)
-+        strcpy(bandwidth, "40MHz");
-+    else if (strcmp (channelMode,"11AXHE20") == 0)
-+        strcpy(bandwidth, "20MHz");
-+    else if (strcmp (channelMode,"11AXHE40PLUS") == 0)
-+        strcpy(bandwidth, "40MHz");
-+    else if (strcmp (channelMode,"11AXHE40MINUS") == 0)
-+        strcpy(bandwidth, "40MHz");
-+    else
-+    {
-+        wifi_dbg_printf("%s: input parameter channelMode format error\n", __func__);
-+        return RETURN_ERR;
-+    }
 +
 +    writeBandWidth(radioIndex, bandwidth);
 +    wifi_setRadioOperatingChannelBandwidth(radioIndex, bandwidth);