blob: 3c97aeef18ee4b1d04f585bcaf7d2873423bae06 [file] [log] [blame]
developer2fd57aa2022-08-17 14:43:10 +08001From f3ddc9ecc94827f7d4e0884d57afed1878aebc69 Mon Sep 17 00:00:00 2001
2From: "Allen.Ye" <allen.ye@mediatek.com>
3Date: Wed, 17 Aug 2022 14:30:27 +0800
4Subject: [PATCH] HAL: add get and set radio mode
5
6---
7 source/wifi/wifi_hal.c | 135 ++++++++++++++++++++++++++++++++++++++++-
8 1 file changed, 133 insertions(+), 2 deletions(-)
9
10diff --git a/source/wifi/wifi_hal.c b/source/wifi/wifi_hal.c
11index 1d7833d..b4628c9 100644
12--- a/source/wifi/wifi_hal.c
13+++ b/source/wifi/wifi_hal.c
14@@ -1526,10 +1526,59 @@ INT wifi_getRadioStandard(INT radioIndex, CHAR *output_string, BOOL *gOnly, BOOL
15 #endif
16 }
17
18-//Set the radio operating mode, and pure mode flag.
19+INT wifi_getRadioMode(INT radioIndex, CHAR *output_string, UINT *pureMode)
20+{
21+ char cmd[128] = {0};
22+ char buf[64] = {0};
23+ char config_file[64] = {0};
24+
25+ WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
26+ if(NULL == output_string || NULL == pureMode)
27+ return RETURN_ERR;
28+
29+ // grep all of the ieee80211 protocol config set to 1
30+ snprintf(config_file, sizeof(cmd), "%s%d.conf", CONFIG_PREFIX, radioIndex);
31+ snprintf(cmd, sizeof(cmd), "cat %s | grep -E\"ieee.*=1\" | cut -d '=' -f1 | tr -d 'ieee80211'", config_file);
32+ _syscmd(cmd, buf, sizeof(buf));
33+
34+ // puremode is a bit map
35+ *pureMode = 0;
36+ if (radioIndex == 0) {
37+ strcat(output_string, "b,g");
38+ *pureMode |= 4;
39+ if (strstr(buf, "n") != NULL) {
40+ strcat(output_string, ",n");
41+ *pureMode |= 8;
42+ }
43+ if (strstr(buf, "ax") != NULL) {
44+ strcat(output_string, ",ax");
45+ *pureMode |= 32;
46+ }
47+ } else if (radioIndex == 1) {
48+ strcat(output_string, "a");
49+ *pureMode |= 1;
50+ if (strstr(buf, "n") != NULL) {
51+ strcat(output_string, ",n");
52+ *pureMode |= 8;
53+ }
54+ if (strstr(buf, "ac") != NULL) {
55+ strcat(output_string, ",ac");
56+ *pureMode |= 16;
57+ }
58+ if (strstr(buf, "ax") != NULL) {
59+ strcat(output_string, ",ax");
60+ *pureMode |= 32;
61+ }
62+ }
63+
64+ WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
65+ return RETURN_OK;
66+}
67+
68+// Set the radio operating mode, and pure mode flag.
69 INT wifi_setRadioChannelMode(INT radioIndex, CHAR *channelMode, BOOL gOnlyFlag, BOOL nOnlyFlag, BOOL acOnlyFlag) //RDKB
70 {
71- WIFI_ENTRY_EXIT_DEBUG("Inside %s_%s_%d_%d:%d\n",__func__,channelMode,nOnlyFlag,gOnlyFlag,__LINE__);
72+ WIFI_ENTRY_EXIT_DEBUG("Inside %s_%s_%d_%d:%d\n",__func__,channelMode,nOnlyFlag,gOnlyFlag,__LINE__);
73 if (strcmp (channelMode,"11A") == 0)
74 {
75 writeBandWidth(radioIndex,"20MHz");
76@@ -1621,6 +1670,88 @@ INT wifi_setRadioChannelMode(INT radioIndex, CHAR *channelMode, BOOL gOnlyFlag,
77 return RETURN_OK;
78 }
79
80+// Set the radio operating mode, and pure mode flag.
81+INT wifi_setRadioMode(INT radioIndex, CHAR *channelMode, UINT pureMode)
82+{
83+ int num_hostapd_support_mode = 3; // n, ac, ax
84+ struct params list[num_hostapd_support_mode];
85+ char config_file[64] = {0};
86+ char bandwidth[16] = {0};
87+ int mode_check_bit = 1 << 3; // n mode
88+
89+ WIFI_ENTRY_EXIT_DEBUG("Inside %s_%d:%d\n", __func__, channelMode, pureMode, __LINE__);
90+ // Set radio mode
91+ list[0].name = "ieee80211n";
92+ list[1].name = "ieee80211ac";
93+ list[2].name = "ieee80211ax";
94+ snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, radioIndex);
95+
96+ // check the bit map from n to ax, and set hostapd config
97+ for(int i = 0; i < num_hostapd_support_mode; i++) {
98+ if (pureMode & mode_check_bit)
99+ list[i].value = "1";
100+ else
101+ list[i].value = "0";
102+ mode_check_bit = mode_check_bit << 1;
103+ }
104+ wifi_hostapdWrite(config_file, list, num_hostapd_support_mode);
105+
106+ // Set bandwidth
107+ // 5G
108+ if (strcmp (channelMode,"11A") == 0)
109+ strcpy(bandwidth, "20MHz");
110+ else if (strcmp (channelMode,"11NAHT20") == 0)
111+ strcpy(bandwidth, "20MHz");
112+ else if (strcmp (channelMode,"11NAHT40PLUS") == 0)
113+ strcpy(bandwidth, "40MHz");
114+ else if (strcmp (channelMode,"11NAHT40MINUS") == 0)
115+ strcpy(bandwidth, "40MHz");
116+ else if (strcmp (channelMode,"11ACVHT20") == 0)
117+ strcpy(bandwidth, "20MHz");
118+ else if (strcmp (channelMode,"11ACVHT40PLUS") == 0)
119+ strcpy(bandwidth, "40MHz");
120+ else if (strcmp (channelMode,"11ACVHT40MINUS") == 0)
121+ strcpy(bandwidth, "40MHz");
122+ else if (strcmp (channelMode,"11ACVHT80") == 0)
123+ strcpy(bandwidth, "80MHz");
124+ else if (strcmp (channelMode,"11ACVHT160") == 0)
125+ strcpy(bandwidth, "160MHz");
126+ else if (strcmp (channelMode,"11AXHE80") == 0)
127+ strcpy(bandwidth, "80MHz");
128+ else if (strcmp (channelMode,"11AXHE160") == 0)
129+ strcpy(bandwidth, "160MHz");
130+ // 2.4G
131+ else if (strcmp (channelMode,"11B") == 0)
132+ strcpy(bandwidth, "20MHz");
133+ else if (strcmp (channelMode,"11G") == 0)
134+ strcpy(bandwidth, "20MHz");
135+ else if (strcmp (channelMode,"11NGHT20") == 0)
136+ strcpy(bandwidth, "20MHz");
137+ else if (strcmp (channelMode,"11NGHT40PLUS") == 0)
138+ strcpy(bandwidth, "40MHz");
139+ else if (strcmp (channelMode,"11NGHT40MINUS") == 0)
140+ strcpy(bandwidth, "40MHz");
141+ else if (strcmp (channelMode,"11AXHE20") == 0)
142+ strcpy(bandwidth, "20MHz");
143+ else if (strcmp (channelMode,"11AXHE40PLUS") == 0)
144+ strcpy(bandwidth, "40MHz");
145+ else if (strcmp (channelMode,"11AXHE40MINUS") == 0)
146+ strcpy(bandwidth, "40MHz");
147+ else
148+ {
149+ wifi_dbg_printf("%s: input parameter channelMode format error\n", __func__);
150+ return RETURN_ERR;
151+ }
152+
153+ writeBandWidth(radioIndex, bandwidth);
154+ wifi_setRadioOperatingChannelBandwidth(radioIndex, bandwidth);
155+
156+ wifi_reloadAp(radioIndex);
157+ WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
158+
159+ return RETURN_OK;
160+}
161+
162 //Get the list of supported channel. eg: "1-11"
163 //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.
164 INT wifi_getRadioPossibleChannels(INT radioIndex, CHAR *output_string) //RDKB
165--
1662.18.0
167