blob: 87d684a487d12b45a4b6d9265f31c2b5a0642d32 [file] [log] [blame]
developer6d902db2022-08-19 11:51:36 +08001From 9fe2a7b984e3b008bbb1605eb33f7937d43cf018 Mon Sep 17 00:00:00 2001
2From: "Allen.Ye" <allen.ye@mediatek.com>
3Date: Wed, 17 Aug 2022 09:55:10 +0800
4Subject: [PATCH] HAL: add get and set guard interval functions
5
6---
7 source/wifi/wifi_hal.c | 132 +++++++++++++++++++++++++++++++++++++++--
8 1 file changed, 128 insertions(+), 4 deletions(-)
9
10diff --git a/source/wifi/wifi_hal.c b/source/wifi/wifi_hal.c
11index dd5e8d4..19aa67e 100644
12--- a/source/wifi/wifi_hal.c
13+++ b/source/wifi/wifi_hal.c
14@@ -74,6 +74,7 @@ Licensed under the ISC license
15 #define SOCK_PREFIX "/var/run/hostapd/wifi"
16 #define VAP_STATUS_FILE "/tmp/vap-status"
17 #define ESSID_FILE "/tmp/essid"
18+#define GUARD_INTERVAL_FILE "/tmp/guard-interval"
19
20 #ifdef MTK_IMPL
21 #define DRIVER_2GHZ "mt7915e"
22@@ -2409,18 +2410,53 @@ INT wifi_setRadioExtChannel(INT radioIndex, CHAR *string) //Tr181 //AP only
23 //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.
24 INT wifi_getRadioGuardInterval(INT radioIndex, CHAR *output_string) //Tr181
25 {
26- //save config and apply instantly
27- if (NULL == output_string)
28+ wifi_guard_interval_t GI;
29+
30+ WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
31+
32+ if (output_string == NULL || wifi_getGuardInterval(radioIndex, &GI) == RETURN_ERR)
33 return RETURN_ERR;
34- snprintf(output_string, 64, "Auto");
35
36+ if (GI == wifi_guard_interval_400)
37+ strcpy(output_string, "400nsec");
38+ else if (GI == wifi_guard_interval_800)
39+ strcpy(output_string, "800nsec");
40+ else if (GI == wifi_guard_interval_1600)
41+ strcpy(output_string, "1600nsec");
42+ else if (GI == wifi_guard_interval_3200)
43+ strcpy(output_string, "3200nsec");
44+ else
45+ strcpy(output_string, "auto");
46+
47+ WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
48 return RETURN_OK;
49 }
50
51 //Set the guard interval value.
52 INT wifi_setRadioGuardInterval(INT radioIndex, CHAR *string) //Tr181
53 {
54- //Apply setting instantly
55+ wifi_guard_interval_t GI;
56+ int ret = 0;
57+
58+ WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
59+
60+ if (strcmp(string, "400nsec") == 0)
61+ GI = wifi_guard_interval_400;
62+ else if (strcmp(string , "800nsec") == 0 || strcmp(string, "auto") == 0)
63+ GI = wifi_guard_interval_800;
64+ else if (strcmp(string , "1600nsec") == 0)
65+ GI = wifi_guard_interval_1600;
66+ else if (strcmp(string , "3200nsec") == 0)
67+ GI = wifi_guard_interval_3200;
68+
69+ ret = wifi_setGuardInterval(radioIndex, GI);
70+
71+ if (ret == RETURN_ERR) {
72+ wifi_dbg_printf("%s: wifi_setGuardInterval return error\n", __func__);
73+ return RETURN_ERR;
74+ }
75+
76+ WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
77 return RETURN_OK;
78 }
79
80@@ -9456,6 +9492,94 @@ INT wifi_isZeroDFSSupported(UINT radioIndex, BOOL *supported)
81 return RETURN_OK;
82 }
83
84+INT wifi_setGuardInterval(INT radio_index, wifi_guard_interval_t guard_interval)
85+{
86+ char cmd[128] = {0};
87+ char buf[64] = {0};
88+ char band_str[8] = {0};
89+ char GI[8] = {0};
90+ int tmp = 0;
91+ BOOL ax_mode = FALSE;
92+ BOOL short_GI = FALSE;
93+ FILE *f = NULL;
94+ wifi_band band;
95+
96+ WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
97+
98+ if (wifi_getRadioMode(radio_index, buf, &tmp) == RETURN_ERR) {
99+ wifi_dbg_printf("%s: wifi_getRadioMode return error\n", __func__);
100+ return RETURN_ERR;
101+ }
102+ if (strstr(buf, "ax") != NULL)
103+ ax_mode = TRUE;
104+
105+ if (guard_interval == wifi_guard_interval_400 && ax_mode != TRUE) {
106+ short_GI = TRUE;
107+ strcpy(GI, "0.4");
108+ } else if (guard_interval == wifi_guard_interval_1600 && ax_mode == TRUE)
109+ strcpy(GI, "1.6");
110+ else if (guard_interval == wifi_guard_interval_3200 && ax_mode == TRUE)
111+ strcpy(GI, "3.2");
112+ else // default
113+ strcpy(GI, "0.8");
114+
115+ band = wifi_index_to_band(radio_index);
116+ if (band == band_2_4)
117+ strcpy(band_str, "2.4");
118+ else if (band == band_5)
119+ strcpy(band_str, "5");
120+ else if (band == band_6)
121+ strcpy(band_str, "6");
122+ else {
123+ wifi_dbg_printf("%s: invalid band\n");
124+ return RETURN_ERR;
125+ }
126+
127+ if (ax_mode == TRUE)
128+ snprintf(cmd, sizeof(cmd), "iw dev %s%d set bitrates he-gi-%s %s", AP_PREFIX, radio_index, band_str, GI);
129+ else
130+ snprintf(cmd, sizeof(cmd), "iw dev %s%d set bitrates %sgi-%s", AP_PREFIX, radio_index, (short_GI)?"s":"l", band_str);
131+ _syscmd(cmd, buf, sizeof(buf));
132+
133+ // Record GI for get GI function
134+ snprintf(buf, sizeof(buf), "%s%d.txt", GUARD_INTERVAL_FILE, radio_index);
135+ f = fopen(buf, "w");
136+ if (f != NULL) {
137+ fprintf(f, "%s", GI);
138+ }
139+ fclose(f);
140+ WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
141+ return RETURN_OK;
142+}
143+
144+INT wifi_getGuardInterval(INT radio_index, wifi_guard_interval_t *guard_interval)
145+{
146+ char buf[32] = {0};
147+ char cmd[64] = {0};
148+
149+ WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
150+
151+ if (guard_interval == NULL)
152+ return RETURN_ERR;
153+
154+ snprintf(cmd, sizeof(cmd), "cat %s%d.txt", GUARD_INTERVAL_FILE, radio_index);
155+ _syscmd(cmd, buf, sizeof(buf));
156+
157+ if (strcmp(buf, "0.4") == 0)
158+ *guard_interval = wifi_guard_interval_400;
159+ else if (strcmp(buf, "0.8") == 0)
160+ *guard_interval = wifi_guard_interval_800;
161+ else if (strcmp(buf, "1.6") == 0)
162+ *guard_interval = wifi_guard_interval_1600;
163+ else if (strcmp(buf, "3.2") == 0)
164+ *guard_interval = wifi_guard_interval_3200;
165+ else
166+ *guard_interval = wifi_guard_interval_auto;
167+
168+ WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
169+ return RETURN_OK;
170+}
171+
172 /* multi-psk support */
173 INT wifi_getMultiPskClientKey(INT apIndex, mac_address_t mac, wifi_key_multi_psk_t *key)
174 {
175--
1762.18.0
177