blob: 657ba172e6da1616d7ba58eb147374c645d6c252 [file] [log] [blame]
developer832578a2022-09-07 16:12:26 +08001From 47094ac819aba0809c899fe8ad1083b319617813 Mon Sep 17 00:00:00 2001
developer2fd57aa2022-08-17 14:43:10 +08002From: "Allen.Ye" <allen.ye@mediatek.com>
developer832578a2022-09-07 16:12:26 +08003Date: Thu, 8 Sep 2022 10:31:06 +0800
developer2fd57aa2022-08-17 14:43:10 +08004Subject: [PATCH] HAL: add get and set radio mode
5
6---
developer832578a2022-09-07 16:12:26 +08007 source/wifi/wifi_hal.c | 120 ++++++++++++++++++++++++++++++++++++++++-
8 1 file changed, 119 insertions(+), 1 deletion(-)
developer2fd57aa2022-08-17 14:43:10 +08009
10diff --git a/source/wifi/wifi_hal.c b/source/wifi/wifi_hal.c
developer832578a2022-09-07 16:12:26 +080011index fa1af2e..9e17de6 100644
developer2fd57aa2022-08-17 14:43:10 +080012--- a/source/wifi/wifi_hal.c
13+++ b/source/wifi/wifi_hal.c
developer832578a2022-09-07 16:12:26 +080014@@ -170,6 +170,15 @@ typedef enum
15 band_6 = 2,
16 } wifi_band;
17
18+typedef enum {
19+ WIFI_MODE_A = 0x01,
20+ WIFI_MODE_B = 0x02,
21+ WIFI_MODE_G = 0x04,
22+ WIFI_MODE_N = 0x08,
23+ WIFI_MODE_AC = 0x10,
24+ WIFI_MODE_AX = 0x20,
25+} wifi_ieee80211_Mode;
26+
27 #ifdef WIFI_HAL_VERSION_3
28
29 // Return number of elements in array
30@@ -1696,7 +1705,63 @@ INT wifi_getRadioStandard(INT radioIndex, CHAR *output_string, BOOL *gOnly, BOOL
developer2fd57aa2022-08-17 14:43:10 +080031 #endif
32 }
33
34-//Set the radio operating mode, and pure mode flag.
35+INT wifi_getRadioMode(INT radioIndex, CHAR *output_string, UINT *pureMode)
36+{
37+ char cmd[128] = {0};
38+ char buf[64] = {0};
39+ char config_file[64] = {0};
developer832578a2022-09-07 16:12:26 +080040+ wifi_band band;
developer2fd57aa2022-08-17 14:43:10 +080041+
42+ WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
43+ if(NULL == output_string || NULL == pureMode)
44+ return RETURN_ERR;
45+
46+ // grep all of the ieee80211 protocol config set to 1
47+ snprintf(config_file, sizeof(cmd), "%s%d.conf", CONFIG_PREFIX, radioIndex);
developer832578a2022-09-07 16:12:26 +080048+ snprintf(cmd, sizeof(cmd), "cat %s | grep -E\"^ieee.*=1\" | cut -d '=' -f1 | tr -d 'ieee80211'", config_file);
developer2fd57aa2022-08-17 14:43:10 +080049+ _syscmd(cmd, buf, sizeof(buf));
50+
developer832578a2022-09-07 16:12:26 +080051+ band = wifi_index_to_band(radioIndex);
developer2fd57aa2022-08-17 14:43:10 +080052+ // puremode is a bit map
53+ *pureMode = 0;
developer832578a2022-09-07 16:12:26 +080054+ if (band == band_2_4) {
developer2fd57aa2022-08-17 14:43:10 +080055+ strcat(output_string, "b,g");
developer832578a2022-09-07 16:12:26 +080056+ *pureMode |= WIFI_MODE_B | WIFI_MODE_G;
developer2fd57aa2022-08-17 14:43:10 +080057+ if (strstr(buf, "n") != NULL) {
58+ strcat(output_string, ",n");
developer832578a2022-09-07 16:12:26 +080059+ *pureMode |= WIFI_MODE_N;
developer2fd57aa2022-08-17 14:43:10 +080060+ }
61+ if (strstr(buf, "ax") != NULL) {
62+ strcat(output_string, ",ax");
developer832578a2022-09-07 16:12:26 +080063+ *pureMode |= WIFI_MODE_AX;
developer2fd57aa2022-08-17 14:43:10 +080064+ }
developer832578a2022-09-07 16:12:26 +080065+ } else if (band == band_5) {
developer2fd57aa2022-08-17 14:43:10 +080066+ strcat(output_string, "a");
developer832578a2022-09-07 16:12:26 +080067+ *pureMode |= WIFI_MODE_A;
developer2fd57aa2022-08-17 14:43:10 +080068+ if (strstr(buf, "n") != NULL) {
69+ strcat(output_string, ",n");
developer832578a2022-09-07 16:12:26 +080070+ *pureMode |= WIFI_MODE_N;
developer2fd57aa2022-08-17 14:43:10 +080071+ }
72+ if (strstr(buf, "ac") != NULL) {
73+ strcat(output_string, ",ac");
developer832578a2022-09-07 16:12:26 +080074+ *pureMode |= WIFI_MODE_AC;
developer2fd57aa2022-08-17 14:43:10 +080075+ }
76+ if (strstr(buf, "ax") != NULL) {
77+ strcat(output_string, ",ax");
developer832578a2022-09-07 16:12:26 +080078+ *pureMode |= WIFI_MODE_AX;
79+ }
80+ } else if (band == band_6) {
81+ if (strstr(buf, "ax") != NULL) {
82+ strcat(output_string, "ax");
83+ *pureMode |= WIFI_MODE_AX;
developer2fd57aa2022-08-17 14:43:10 +080084+ }
85+ }
86+
87+ WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
88+ return RETURN_OK;
89+}
90+
91+// Set the radio operating mode, and pure mode flag.
92 INT wifi_setRadioChannelMode(INT radioIndex, CHAR *channelMode, BOOL gOnlyFlag, BOOL nOnlyFlag, BOOL acOnlyFlag) //RDKB
93 {
developer832578a2022-09-07 16:12:26 +080094 WIFI_ENTRY_EXIT_DEBUG("Inside %s_%s_%d_%d:%d\n",__func__,channelMode,nOnlyFlag,gOnlyFlag,__LINE__);
95@@ -1791,6 +1856,59 @@ INT wifi_setRadioChannelMode(INT radioIndex, CHAR *channelMode, BOOL gOnlyFlag,
developer2fd57aa2022-08-17 14:43:10 +080096 return RETURN_OK;
97 }
98
99+// Set the radio operating mode, and pure mode flag.
100+INT wifi_setRadioMode(INT radioIndex, CHAR *channelMode, UINT pureMode)
101+{
102+ int num_hostapd_support_mode = 3; // n, ac, ax
103+ struct params list[num_hostapd_support_mode];
104+ char config_file[64] = {0};
105+ char bandwidth[16] = {0};
106+ int mode_check_bit = 1 << 3; // n mode
developer832578a2022-09-07 16:12:26 +0800107+ wifi_ieee80211_Mode mode = (wifi_ieee80211_Mode)pureMode;
developer2fd57aa2022-08-17 14:43:10 +0800108+
109+ WIFI_ENTRY_EXIT_DEBUG("Inside %s_%d:%d\n", __func__, channelMode, pureMode, __LINE__);
110+ // Set radio mode
111+ list[0].name = "ieee80211n";
112+ list[1].name = "ieee80211ac";
113+ list[2].name = "ieee80211ax";
114+ snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, radioIndex);
115+
116+ // check the bit map from n to ax, and set hostapd config
developer832578a2022-09-07 16:12:26 +0800117+ if (mode & WIFI_MODE_N)
118+ list[0].value = "1";
119+ else
120+ list[0].value = "0";
121+ if (mode & WIFI_MODE_AC)
122+ list[1].value = "1";
123+ else
124+ list[1].value = "0";
125+ if (mode & WIFI_MODE_AX)
126+ list[2].value = "1";
127+ else
128+ list[2].value = "0";
developer2fd57aa2022-08-17 14:43:10 +0800129+ wifi_hostapdWrite(config_file, list, num_hostapd_support_mode);
130+
developer832578a2022-09-07 16:12:26 +0800131+ if (channelMode == NULL || strlen(channelMode) == 0)
132+ return RETURN_OK;
developer2fd57aa2022-08-17 14:43:10 +0800133+ // Set bandwidth
developer832578a2022-09-07 16:12:26 +0800134+ if (strstr(channelMode, "40") != NULL)
developer2fd57aa2022-08-17 14:43:10 +0800135+ strcpy(bandwidth, "40MHz");
developer832578a2022-09-07 16:12:26 +0800136+ else if (strstr(channelMode, "80") != NULL)
developer2fd57aa2022-08-17 14:43:10 +0800137+ strcpy(bandwidth, "80MHz");
developer832578a2022-09-07 16:12:26 +0800138+ else if (strstr(channelMode, "160") != NULL)
developer2fd57aa2022-08-17 14:43:10 +0800139+ strcpy(bandwidth, "160MHz");
developer832578a2022-09-07 16:12:26 +0800140+ else // 11A, 11B, 11G....
developer2fd57aa2022-08-17 14:43:10 +0800141+ strcpy(bandwidth, "20MHz");
developer2fd57aa2022-08-17 14:43:10 +0800142+
143+ writeBandWidth(radioIndex, bandwidth);
144+ wifi_setRadioOperatingChannelBandwidth(radioIndex, bandwidth);
145+
146+ wifi_reloadAp(radioIndex);
147+ WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
148+
149+ return RETURN_OK;
150+}
151+
152 //Get the list of supported channel. eg: "1-11"
153 //The output_string is a max length 64 octet string that is allocated by the RDKB code. Implementations must ensure that strings are not longer than this.
154 INT wifi_getRadioPossibleChannels(INT radioIndex, CHAR *output_string) //RDKB
155--
1562.18.0
157