blob: 0de3011b6095913b89d6c779be3afc9ef31795e9 [file] [log] [blame]
developer402bf2a2022-10-04 15:20:18 +08001#include <stdio.h>
2#include <string.h>
3#include <stdlib.h>
4#include <ctype.h>
5#include <uci.h>
6#include "wifi-test-tool.h"
7
developer9567a462022-11-17 20:42:05 +08008static int mac_addr_aton(unsigned char *mac_addr, char *arg)
9{
10 sscanf(arg, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx", &mac_addr[0], &mac_addr[1], &mac_addr[2], &mac_addr[3], &mac_addr[4], &mac_addr[5]);
11 return 0;
12}
13
14static void mac_addr_ntoa(char *mac_addr, unsigned char *arg)
15{
16 snprintf(mac_addr, 20, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx", arg[0], arg[1],arg[2],arg[3],arg[4],arg[5]);
17 return;
18}
developer4c2edbe2022-10-18 16:36:37 +080019
20static int _syscmd(char *cmd, char *retBuf, int retBufSize)
21{
22 FILE *f;
23 char *ptr = retBuf;
24 int bufSize=retBufSize, bufbytes=0, readbytes=0, cmd_ret=0;
25
26
27 if((f = popen(cmd, "r")) == NULL) {
28 fprintf(stderr,"\npopen %s error\n", cmd);
29 return RETURN_ERR;
30 }
31
32 while(!feof(f))
33 {
34 *ptr = 0;
35 if(bufSize>=128) {
36 bufbytes=128;
37 } else {
38 bufbytes=bufSize-1;
39 }
40
41 fgets(ptr,bufbytes,f);
42 readbytes=strlen(ptr);
43
44 if(!readbytes)
45 break;
46
47 bufSize-=readbytes;
48 ptr += readbytes;
49 }
50 cmd_ret = pclose(f);
51 retBuf[retBufSize-1]=0;
52
53 return cmd_ret >> 8;
54}
55
56int phy_index_to_radio(int phyIndex)
57{
58 char cmd[128] = {0};
59 char buf[64] = {0};
60 int radioIndex = 0;
61 snprintf(cmd, sizeof(cmd), "ls /tmp | grep phy%d | cut -d '-' -f2 | tr -d '\n'", phyIndex);
62 _syscmd(cmd, buf, sizeof(buf));
63
64 if (strlen(buf) == 0 || strstr(buf, "wifi") == NULL) {
65 fprintf(stderr, "%s: failed to get wifi index\n", __func__);
66 return RETURN_ERR;
67 }
68 sscanf(buf, "wifi%d", &radioIndex);
developerf634eab2023-01-13 15:23:06 +080069 return radioIndex;
developer4c2edbe2022-10-18 16:36:37 +080070}
71
developer402bf2a2022-10-04 15:20:18 +080072void set_channel(wifi_radio_param *radio_param, char *channel)
73{
developerab985802022-10-07 09:42:31 +080074 if (strcmp(channel, "auto") == 0) {
75 radio_param->auto_channel = TRUE;
76 radio_param->channel = 0;
77 } else {
developer402bf2a2022-10-04 15:20:18 +080078 radio_param->auto_channel = FALSE;
developerab985802022-10-07 09:42:31 +080079 radio_param->channel = strtol(channel, NULL, 10);
developer402bf2a2022-10-04 15:20:18 +080080 }
developerab985802022-10-07 09:42:31 +080081 return;
developer402bf2a2022-10-04 15:20:18 +080082}
83
developer02a4a1b2022-10-06 17:16:43 +080084void set_country(wifi_radio_param *radio_param, char *country)
developer402bf2a2022-10-04 15:20:18 +080085{
86 strcpy(radio_param->country, country);
87}
88
developer02a4a1b2022-10-06 17:16:43 +080089void set_band(wifi_radio_param *radio_param, char *band)
developer402bf2a2022-10-04 15:20:18 +080090{
91 strcpy(radio_param->band, band);
92}
93
developer54afa2c2022-10-18 17:44:13 +080094void set_noscan(wifi_radio_param *radio_param, char *noscan)
95{
96 snprintf(radio_param->noscan, 2, "%s", noscan);
97 radio_param->noscan[1] = '\0';
98}
99
developer402bf2a2022-10-04 15:20:18 +0800100void set_hwmode(wifi_radio_param *radio_param, char *hwmode)
101{
102 if (strncmp(hwmode, "11a", 3) == 0)
103 strcpy(radio_param->hwmode, "a");
104 if (strncmp(hwmode, "11b", 3) == 0)
105 strcpy(radio_param->hwmode, "b");
106 if (strncmp(hwmode, "11g", 3) == 0)
107 strcpy(radio_param->hwmode, "g");
108}
109
110void set_htmode(wifi_radio_param *radio_param, char *htmode)
111{
112 char tmp[16] = {0};
113 char *ptr = htmode;
114 ULONG bandwidth = 0;
115 radio_param->bandwidth = 20;
116 while (*ptr) {
117 if (isdigit(*ptr)) {
118 bandwidth = strtoul(ptr, NULL, 10);
119 radio_param->bandwidth = bandwidth;
120 break;
121 }
122 ptr++;
123 }
124
125 // HT40 -> 11NGHT40PLUS
126 // VHT40+ -> 11ACVHT40PLUS
127 // HE80 -> 11AXHE80
128 if (strstr(htmode, "+") != NULL) {
129 strncpy(tmp, htmode, strlen(htmode) - 1);
130 strcat(tmp, "PLUS");
131 } else if (strstr(htmode, "-") != NULL) {
132 strncpy(tmp, htmode, strlen(htmode) - 1);
133 strcat(tmp, "MINUS");
134 } else
135 strcpy(tmp, htmode);
136
137
138 if (strstr(htmode, "VHT") != NULL) {
139 snprintf(radio_param->htmode, sizeof(radio_param->htmode), "11AC%s", tmp);
140 } else if (strstr(htmode, "HT") != NULL && strstr(htmode, "NO") == NULL) {
141 snprintf(radio_param->htmode, sizeof(radio_param->htmode), "11NG%s", tmp);
142 } else if (strstr(htmode, "HE") != NULL) {
143 snprintf(radio_param->htmode, sizeof(radio_param->htmode), "11AX%s", tmp);
144 } else { // NOHT or NONE should be parsed with the band, so just fill the original string.
145 strcpy(radio_param->htmode, tmp);
146 }
147
148}
149
150void set_disable(wifi_radio_param *radio_param, char *disable)
151{
152 if (strcmp(disable, "1") == 0)
153 radio_param->disabled = TRUE;
154 else
155 radio_param->disabled = FALSE;
156}
157
developer1e946fd2022-12-26 17:09:00 +0800158void set_rxant(wifi_radio_param *radio_param, char *mask)
159{
160 radio_param->rxantenna = strtol(mask, NULL, 16);
161}
162
163void set_txant(wifi_radio_param *radio_param, char *mask)
164{
165 radio_param->txantenna = strtol(mask, NULL, 16);
166}
167
developer223f5982023-02-28 15:59:38 +0800168void set_igmpsn_enable(wifi_intf_param *intf_param, char *enable)
169{
170 if (strcmp(enable, "1") == 0)
171 intf_param->igmpsn_enable = TRUE;
172 else
173 intf_param->igmpsn_enable = FALSE;
174}
175
176void set_wps_state(wifi_intf_param *intf_param, char *enable)
177{
178 if (strcmp(enable, "1") == 0)
179 intf_param->wps_state = TRUE;
180 else
181 intf_param->wps_state = FALSE;
182}
183
184void set_wps_cancel(wifi_intf_param *intf_param, char *enable)
185{
186 if (strcmp(enable, "1") == 0)
187 intf_param->wps_cancel = TRUE;
188 else
189 intf_param->wps_cancel = FALSE;
190}
191
192void set_wps_pushbutton(wifi_intf_param *intf_param, char *enable)
193{
194 if (strcmp(enable, "1") == 0)
195 intf_param->wps_pushbutton = TRUE;
196 else
197 intf_param->wps_pushbutton = FALSE;
198}
199
200
201void set_macfilter(wifi_intf_param *intf_param, char *macfilter)
202{
203 strncpy(intf_param->macfilter, macfilter, 10);
204}
205
206void set_maclist(wifi_intf_param *intf_param, char *maclist)
207{
208 strncpy(intf_param->maclist, maclist, 512);
209}
210
developerc4548732023-02-06 20:02:10 +0800211void set_htcoex(wifi_radio_param *radio_param, char *ht_coex)
212{
213 radio_param->ht_coex = strtol(ht_coex, NULL, 10);
214}
215
216void set_rts(wifi_radio_param *radio_param, char *rts)
217{
218 radio_param->rtsThreshold = strtol(rts, NULL, 10);
219}
220
developer1ac0e892022-11-25 14:30:05 +0800221void set_radionum(wifi_intf_param *intf_param, char *phy_name)
developer402bf2a2022-10-04 15:20:18 +0800222{
developer9567a462022-11-17 20:42:05 +0800223 int radio_num = 0;
224 char *ptr = phy_name;
developer4c2edbe2022-10-18 16:36:37 +0800225 int phyId = 0;
developer402bf2a2022-10-04 15:20:18 +0800226
227 while (*ptr) {
228 if (isdigit(*ptr)) {
developer9567a462022-11-17 20:42:05 +0800229 phyId = strtoul(ptr, NULL, 10);
230 radio_num = phy_index_to_radio(phyId);
developer1ac0e892022-11-25 14:30:05 +0800231 intf_param->radio_index = radio_num;
developer402bf2a2022-10-04 15:20:18 +0800232 break;
233 }
234 ptr++;
235 }
236}
237
developer1ac0e892022-11-25 14:30:05 +0800238void set_ssid(wifi_intf_param *intf_param, char *ssid)
developer402bf2a2022-10-04 15:20:18 +0800239{
developer1ac0e892022-11-25 14:30:05 +0800240 strncpy(intf_param->ssid, ssid, 32);
developer402bf2a2022-10-04 15:20:18 +0800241}
242
developer1ac0e892022-11-25 14:30:05 +0800243void set_encryption(wifi_intf_param *intf_param, char *encryption_mode)
developer402bf2a2022-10-04 15:20:18 +0800244{
developer3ddad2f2022-10-13 13:33:57 +0800245 if (strcmp(encryption_mode, "none") == 0) {
developer1ac0e892022-11-25 14:30:05 +0800246 intf_param->security.mode = wifi_security_mode_none;
247 intf_param->security.encr = wifi_encryption_none;
developer3ddad2f2022-10-13 13:33:57 +0800248 }else if(strncmp(encryption_mode, "psk2", 4) == 0){
developer1ac0e892022-11-25 14:30:05 +0800249 intf_param->security.mode = wifi_security_mode_wpa2_personal;
developer3ddad2f2022-10-13 13:33:57 +0800250 }else if(strncmp(encryption_mode, "psk-",4) == 0){
developer1ac0e892022-11-25 14:30:05 +0800251 intf_param->security.mode = wifi_security_mode_wpa_wpa2_personal;
developer3ddad2f2022-10-13 13:33:57 +0800252 }else if(strncmp(encryption_mode, "psk",3) == 0){
developer1ac0e892022-11-25 14:30:05 +0800253 intf_param->security.mode = wifi_security_mode_wpa_personal;
developer3ddad2f2022-10-13 13:33:57 +0800254 }else if(strncmp(encryption_mode, "wpa2",4) == 0){
developer1ac0e892022-11-25 14:30:05 +0800255 intf_param->security.mode = wifi_security_mode_wpa2_enterprise;
developer3ddad2f2022-10-13 13:33:57 +0800256 }else if(strncmp(encryption_mode, "wpa-",4) == 0){
developer1ac0e892022-11-25 14:30:05 +0800257 intf_param->security.mode = wifi_security_mode_wpa_wpa2_enterprise;
developer3ddad2f2022-10-13 13:33:57 +0800258 }else if(strcmp(encryption_mode, "sae") == 0){
developer1ac0e892022-11-25 14:30:05 +0800259 intf_param->security.mode = wifi_security_mode_wpa3_personal;
developer3ddad2f2022-10-13 13:33:57 +0800260 }else if(strcmp(encryption_mode, "wpa3") == 0){
developer1ac0e892022-11-25 14:30:05 +0800261 intf_param->security.mode = wifi_security_mode_wpa3_enterprise;
developer3ddad2f2022-10-13 13:33:57 +0800262 }else if(strcmp(encryption_mode, "sae-mixed") == 0){
developer1ac0e892022-11-25 14:30:05 +0800263 intf_param->security.mode = wifi_security_mode_wpa3_transition;
developerf634eab2023-01-13 15:23:06 +0800264 }else if(strcmp(encryption_mode, "owe") == 0){
265 intf_param->security.mode = wifi_security_mode_owe;
developer402bf2a2022-10-04 15:20:18 +0800266 }
267
developer3ddad2f2022-10-13 13:33:57 +0800268 if(strstr(encryption_mode, "tkip") && (strstr(encryption_mode, "ccmp") || strstr(encryption_mode, "aes") )){
developer1ac0e892022-11-25 14:30:05 +0800269 intf_param->security.encr = wifi_encryption_aes_tkip;
developer3ddad2f2022-10-13 13:33:57 +0800270 }else if (strstr(encryption_mode, "tkip")){
developer1ac0e892022-11-25 14:30:05 +0800271 intf_param->security.encr = wifi_encryption_tkip;
developer3ddad2f2022-10-13 13:33:57 +0800272 }else{
developer1ac0e892022-11-25 14:30:05 +0800273 intf_param->security.encr = wifi_encryption_aes;
developer402bf2a2022-10-04 15:20:18 +0800274 }
developer3ddad2f2022-10-13 13:33:57 +0800275
developerf634eab2023-01-13 15:23:06 +0800276 if(!strcmp(encryption_mode, "wpa3") || !strcmp(encryption_mode, "sae") || !strcmp(encryption_mode, "owe")){
developer1ac0e892022-11-25 14:30:05 +0800277 intf_param->security.mfp = wifi_mfp_cfg_required;
developer3ddad2f2022-10-13 13:33:57 +0800278 }else if (!strcmp(encryption_mode, "sae-mixed")){
developer1ac0e892022-11-25 14:30:05 +0800279 intf_param->security.mfp = wifi_mfp_cfg_optional;
developer3ddad2f2022-10-13 13:33:57 +0800280 }else{
developer1ac0e892022-11-25 14:30:05 +0800281 intf_param->security.mfp = wifi_mfp_cfg_disabled;
developer3ddad2f2022-10-13 13:33:57 +0800282 }
developer402bf2a2022-10-04 15:20:18 +0800283}
284
developer1ac0e892022-11-25 14:30:05 +0800285void set_key(wifi_intf_param *intf_param, char *key)
developer402bf2a2022-10-04 15:20:18 +0800286{
developer1ac0e892022-11-25 14:30:05 +0800287 strncpy(intf_param->security.u.key.key, key, 64);
developer402bf2a2022-10-04 15:20:18 +0800288}
289
developer2bcdef92022-12-13 16:19:09 +0800290void set_ifname(wifi_intf_param *intf_param, char *ifname)
291{
292 if (strlen(ifname) > 15)
293 return;
294 strncpy(intf_param->ifname, ifname, strlen(ifname) + 1);
295}
296
developerb3f00662022-12-29 09:35:55 +0800297void set_wds(wifi_intf_param *intf_param, char *wds_enable)
298{
299 intf_param->wds_mode = FALSE;
300 if (strncmp(wds_enable, "1", 1) == 0)
301 intf_param->wds_mode = TRUE;
302}
303
developerc4548732023-02-06 20:02:10 +0800304void set_hidden(wifi_intf_param *intf_param, char *hidden)
305{
306 intf_param->hidden = strtol(hidden, NULL, 10);
307}
308
developer9567a462022-11-17 20:42:05 +0800309int set_interface_bssid(int phy_index, int offset, mac_address_t *bssid)
developerf9b2ef02022-10-14 10:07:58 +0800310{
311 FILE *f;
312 char mac_file[64] = {0};
313 char mac_address[20] = {0};
developerf9b2ef02022-10-14 10:07:58 +0800314
developerb97b5492022-12-22 19:44:36 +0800315 sprintf(mac_file, "/sys/class/ieee80211/phy%d/macaddress", phy_index);
developerf9b2ef02022-10-14 10:07:58 +0800316 f = fopen(mac_file, "r");
317 if (f == NULL)
318 return -1;
319 fgets(mac_address, 20, f);
320 fclose(f);
321
developer9567a462022-11-17 20:42:05 +0800322 mac_addr_aton(&(*bssid)[0], mac_address);
323 (*bssid)[0] += offset*2;
developerf9b2ef02022-10-14 10:07:58 +0800324 return 0;
325}
326
developer402bf2a2022-10-04 15:20:18 +0800327void set_radio_param(wifi_radio_param radio_parameter)
328{
developer402bf2a2022-10-04 15:20:18 +0800329 int ret = 0;
developerab985802022-10-07 09:42:31 +0800330 wifi_radio_operationParam_t operationParam = {0};
331
developer4c2edbe2022-10-18 16:36:37 +0800332 if(radio_parameter.radio_index == -1)
333 return;
334
developerab985802022-10-07 09:42:31 +0800335 if (radio_parameter.disabled == TRUE) {
336 wifi_setRadioEnable(radio_parameter.radio_index, FALSE);
337 return;
338 }
developer402bf2a2022-10-04 15:20:18 +0800339
340 fprintf(stderr, "Start setting radio\n");
developer18615812022-10-17 17:37:29 +0800341
developer1e946fd2022-12-26 17:09:00 +0800342 if (radio_parameter.txantenna != 0 && radio_parameter.txantenna == radio_parameter.rxantenna) {
343 ret = wifi_setRadioTxChainMask(radio_parameter.radio_index, radio_parameter.txantenna);
344 if (ret != RETURN_OK)
345 fprintf(stderr, "[Set Tx Chain mask failed!!!]\n");
346 }
347
developer18615812022-10-17 17:37:29 +0800348 // Get current radio setting
developerab985802022-10-07 09:42:31 +0800349 ret = wifi_getRadioOperatingParameters(radio_parameter.radio_index, &operationParam);
350 if (ret != RETURN_OK)
351 fprintf(stderr, "[Get OperatingParameters failed!!!]\n");
developer18615812022-10-17 17:37:29 +0800352 operationParam.enable = TRUE;
developer402bf2a2022-10-04 15:20:18 +0800353
developer402bf2a2022-10-04 15:20:18 +0800354 // Channel
developerab985802022-10-07 09:42:31 +0800355 operationParam.autoChannelEnabled = radio_parameter.auto_channel;
356 operationParam.channel = radio_parameter.channel;
developer402bf2a2022-10-04 15:20:18 +0800357
developerae3f8412022-10-13 15:27:02 +0800358 //bandwidth
359 if (radio_parameter.bandwidth == 20){
360 operationParam.channelWidth = WIFI_CHANNELBANDWIDTH_20MHZ;
361 }else if (radio_parameter.bandwidth == 40){
362 operationParam.channelWidth = WIFI_CHANNELBANDWIDTH_40MHZ;
363 }else if (radio_parameter.bandwidth == 80){
364 operationParam.channelWidth = WIFI_CHANNELBANDWIDTH_80MHZ;
365 }else if (radio_parameter.bandwidth == 160){
366 operationParam.channelWidth = WIFI_CHANNELBANDWIDTH_160MHZ;
367 }
developer402bf2a2022-10-04 15:20:18 +0800368
369 // htmode
developerab985802022-10-07 09:42:31 +0800370 unsigned int mode = 0; // enum wifi_ieee80211Variant_t
developer402bf2a2022-10-04 15:20:18 +0800371 if (strcmp(radio_parameter.band, "2g") == 0) {
developerab985802022-10-07 09:42:31 +0800372 mode |= WIFI_80211_VARIANT_B | WIFI_80211_VARIANT_G;
developer402bf2a2022-10-04 15:20:18 +0800373 if (strcmp(radio_parameter.htmode, "NOHT") == 0 || strcmp(radio_parameter.htmode, "NONE") == 0)
374 strcpy(radio_parameter.htmode, "11G");
375
developerab985802022-10-07 09:42:31 +0800376 if (strstr(radio_parameter.htmode, "HE") != NULL)
377 mode |= WIFI_80211_VARIANT_N | WIFI_80211_VARIANT_AX;
developer402bf2a2022-10-04 15:20:18 +0800378
developerab985802022-10-07 09:42:31 +0800379 } else if (strcmp(radio_parameter.band, "5g") == 0) {
380 mode |= WIFI_80211_VARIANT_A;
developer402bf2a2022-10-04 15:20:18 +0800381 if (strcmp(radio_parameter.htmode, "NOHT") == 0 || strcmp(radio_parameter.htmode, "NONE") == 0)
382 strcpy(radio_parameter.htmode, "11A");
developerab985802022-10-07 09:42:31 +0800383
384 if (strstr(radio_parameter.htmode, "HE") != NULL)
385 mode |= WIFI_80211_VARIANT_N | WIFI_80211_VARIANT_AC | WIFI_80211_VARIANT_AX;
developer4c2edbe2022-10-18 16:36:37 +0800386 }else if (strcmp(radio_parameter.band, "6g") == 0) {
387 mode |= WIFI_80211_VARIANT_A | WIFI_80211_VARIANT_N | WIFI_80211_VARIANT_AC | WIFI_80211_VARIANT_AX;;
388 }
developer402bf2a2022-10-04 15:20:18 +0800389
390 if (strstr(radio_parameter.htmode, "VHT") != NULL)
developerab985802022-10-07 09:42:31 +0800391 mode |= WIFI_80211_VARIANT_N | WIFI_80211_VARIANT_AC;
developer402bf2a2022-10-04 15:20:18 +0800392 else if (strstr(radio_parameter.htmode, "HT") != NULL && strstr(radio_parameter.htmode, "NO") == NULL)
developerab985802022-10-07 09:42:31 +0800393 mode |= WIFI_80211_VARIANT_N;
developer402bf2a2022-10-04 15:20:18 +0800394
developerab985802022-10-07 09:42:31 +0800395 operationParam.variant = mode;
developer402bf2a2022-10-04 15:20:18 +0800396
developerc4548732023-02-06 20:02:10 +0800397 // rtsThreshold, zero means not set
398 if ((radio_parameter.rtsThreshold < 65535) && radio_parameter.rtsThreshold)
399 operationParam.rtsThreshold = radio_parameter.rtsThreshold;
400
401 //ht_coex
402 operationParam.obssCoex = radio_parameter.ht_coex;
403
developerab985802022-10-07 09:42:31 +0800404 // apply setting
405 ret = wifi_setRadioOperatingParameters(radio_parameter.radio_index, &operationParam);
developer402bf2a2022-10-04 15:20:18 +0800406 if (ret != RETURN_OK)
developerab985802022-10-07 09:42:31 +0800407 fprintf(stderr, "[Apply setting failed!!!]\n");
developer402bf2a2022-10-04 15:20:18 +0800408
developerb7f28c42022-11-07 16:58:17 +0800409 // Country
410 fprintf(stderr, "Set Country: %s\n", radio_parameter.country);
411 ret = wifi_setRadioCountryCode(radio_parameter.radio_index, radio_parameter.country);
412 if (ret != RETURN_OK)
413 fprintf(stderr, "[Set Country failed!!!]\n");
414 ret = 0;
415
416 // hwmode
417 fprintf(stderr, "Set hwmode: %s\n", radio_parameter.hwmode);
418 ret = wifi_setRadioHwMode(radio_parameter.radio_index, radio_parameter.hwmode);
419 if (ret != RETURN_OK)
420 fprintf(stderr, "[Set hwmode failed!!!]\n");
421 ret = 0;
422
423 // noscan
424 fprintf(stderr, "Set noscan: %s \n", radio_parameter.noscan);
425 if(strlen(radio_parameter.noscan)){
426 ret = wifi_setNoscan(radio_parameter.radio_index, radio_parameter.noscan);
427 if (ret != RETURN_OK)
428 fprintf(stderr, "[Set noscan failed!!!]\n");
429 }
430 ret = 0;
431
developer402bf2a2022-10-04 15:20:18 +0800432}
433
developer1ac0e892022-11-25 14:30:05 +0800434void set_ap_param(wifi_intf_param ap_param , wifi_vap_info_map_t *map)
developer402bf2a2022-10-04 15:20:18 +0800435{
436 int ret = 0;
developerab985802022-10-07 09:42:31 +0800437 int vap_index_in_map = 0;
developer9567a462022-11-17 20:42:05 +0800438 int phy_index = 0;
developer9feeaf12023-02-17 15:52:18 +0800439 int key_len = 0;
developerab985802022-10-07 09:42:31 +0800440 wifi_vap_info_t vap_info = {0};
developer18615812022-10-17 17:37:29 +0800441 BOOL radio_enable = FALSE;
442
developer41965b52022-10-19 17:40:23 +0800443 if(ap_param.radio_index == -1)
444 return;
445
developer18615812022-10-17 17:37:29 +0800446 wifi_getRadioEnable(ap_param.radio_index, &radio_enable);
447 if (radio_enable == FALSE)
448 return;
developerab985802022-10-07 09:42:31 +0800449
developer41965b52022-10-19 17:40:23 +0800450
451 // get the index of the map
452 for (int i = 0; i < map->num_vaps; i++) {
453 if (map->vap_array[i].vap_index == ap_param.ap_index) {
454 vap_index_in_map = i;
455 break;
developerab985802022-10-07 09:42:31 +0800456 }
457 }
458
developer41965b52022-10-19 17:40:23 +0800459
developerf9b2ef02022-10-14 10:07:58 +0800460 fprintf(stderr, "Start setting ap\n");
461
developer41965b52022-10-19 17:40:23 +0800462 vap_info = map->vap_array[vap_index_in_map];
developerf9b2ef02022-10-14 10:07:58 +0800463 vap_info.u.bss_info.enabled = TRUE;
developer9567a462022-11-17 20:42:05 +0800464 phy_index = radio_index_to_phy(vap_info.radio_index);
465 if (set_interface_bssid(phy_index, ap_param.mac_offset, &vap_info.u.bss_info.bssid) == -1) {
developerf9b2ef02022-10-14 10:07:58 +0800466 fprintf(stderr, "Get mac address failed.\n");
developer9567a462022-11-17 20:42:05 +0800467 return;
developerf9b2ef02022-10-14 10:07:58 +0800468 }
developer402bf2a2022-10-04 15:20:18 +0800469
developer402bf2a2022-10-04 15:20:18 +0800470 // SSID
developerab985802022-10-07 09:42:31 +0800471 strncpy(vap_info.u.bss_info.ssid, ap_param.ssid, 33);
472 vap_info.u.bss_info.ssid[32] = '\0';
developer402bf2a2022-10-04 15:20:18 +0800473
developer2bcdef92022-12-13 16:19:09 +0800474 // interface
475 if (strlen(ap_param.ifname) != 0) {
476 strncpy(vap_info.vap_name, ap_param.ifname, 16);
477 vap_info.vap_name[15] = "\0";
478 }
479
developer9feeaf12023-02-17 15:52:18 +0800480 // Security
481 if (ap_param.security.mode == wifi_security_mode_wpa3_personal || ap_param.security.mode == wifi_security_mode_wpa3_transition){
482 // OpenWrt script only set psk, here we choose to set both psk and sae.
483 ap_param.security.u.key.type = wifi_security_key_type_psk_sae;
484 } else {
485 key_len = strlen(ap_param.security.u.key.key);
486 if (key_len == 64)
487 ap_param.security.u.key.type = wifi_security_key_type_psk;
488 else if (key_len >= 8 && key_len < 64)
489 ap_param.security.u.key.type = wifi_security_key_type_pass;
490 }
491
developer3ddad2f2022-10-13 13:33:57 +0800492 vap_info.u.bss_info.security.mode = ap_param.security.mode;
493 vap_info.u.bss_info.security.encr = ap_param.security.encr;
494 vap_info.u.bss_info.security.mfp = ap_param.security.mfp;
495 vap_info.u.bss_info.security.u.key.type = ap_param.security.u.key.type;
496 strncpy(vap_info.u.bss_info.security.u.key.key, ap_param.security.u.key.key, 64);
developerc4548732023-02-06 20:02:10 +0800497
498 // hidden
499 vap_info.u.bss_info.showSsid = (ap_param.hidden ? 0 : 1);
developer4c2edbe2022-10-18 16:36:37 +0800500
developer223f5982023-02-28 15:59:38 +0800501 // igmpsn_enable
502 vap_info.u.bss_info.mcast2ucast = ap_param.igmpsn_enable;
503 fprintf(stderr, "Set igmpsn_enable: %d \n", ap_param.igmpsn_enable);
504
505 // wps_state
506 fprintf(stderr, "Set wps_state: %d \n", ap_param.wps_state);
507 ret = wifi_setApWpsEnable(ap_param.ap_index, ap_param.wps_state);
508 if (ret != RETURN_OK)
509 fprintf(stderr, "[Set wps_state failed!!!]\n");
510 ret = 0;
511
512 // wps_cancel
513 fprintf(stderr, "Set wps_cancel: %d \n", ap_param.wps_cancel);
514 if (ap_param.wps_cancel){
515 ret = wifi_cancelApWPS(ap_param.ap_index);
516 if (ret != RETURN_OK)
517 fprintf(stderr, "[Set wps_cancel failed!!!]\n");
518 ret = 0;
519 }
520
521 // wps_pushbutton
522 fprintf(stderr, "Set wps_pushbutton: %d \n", ap_param.wps_pushbutton);
523 if (ap_param.wps_pushbutton){
524 ret = wifi_setApWpsButtonPush(ap_param.ap_index);
525 if (ret != RETURN_OK)
526 fprintf(stderr, "[Set wps_pushbutton failed!!!]\n");
527 ret = 0;
528 }
529
530 // macfilter
531 if ((strcmp(ap_param.macfilter, "disable") == 0) || (strcmp(ap_param.macfilter, "\0") == 0) )
532 vap_info.u.bss_info.mac_filter_enable = false;
533 else if (strcmp(ap_param.macfilter, "deny") == 0){
534 vap_info.u.bss_info.mac_filter_enable = true;
535 vap_info.u.bss_info.mac_filter_mode = wifi_mac_filter_mode_black_list;
536 }
537 else if (strcmp(ap_param.macfilter, "allow") == 0){
538 vap_info.u.bss_info.mac_filter_enable = true;
539 vap_info.u.bss_info.mac_filter_mode = wifi_mac_filter_mode_white_list;
540 }
541 else
542 fprintf(stderr, "The macfilter tpye: %s is invalid!!!\n", ap_param.macfilter);
543 fprintf(stderr, "Set macfilter: %s \n", ap_param.macfilter);
544
545 // maclist
546 if ((strcmp(ap_param.macfilter, "\0") == 0)){
547 ret = wifi_delApAclDevices(ap_param.ap_index);
548 if (ret != RETURN_OK)
549 fprintf(stderr, "[Del all maclist failed!!!]\n");
550 ret = 0;
551 }
552 else{
553 ret = wifi_addApAclDevice(ap_param.ap_index, ap_param.maclist);
554 if (ret != RETURN_OK)
555 fprintf(stderr, "[Add maclist failed!!!]\n");
556 ret = 0;
557 }
558 fprintf(stderr, "Set maclist: %s \n", ap_param.maclist);
559
560 ret = 0;
developerab985802022-10-07 09:42:31 +0800561 // Replace the setting with uci config
developer41965b52022-10-19 17:40:23 +0800562 map->vap_array[vap_index_in_map] = vap_info;
developer402bf2a2022-10-04 15:20:18 +0800563}
564
developer1ac0e892022-11-25 14:30:05 +0800565void set_sta_param(wifi_intf_param sta_param)
developer9567a462022-11-17 20:42:05 +0800566{
567 wifi_sta_network_t *sta = NULL;
568 mac_address_t sta_mac = {0};
569 char sta_mac_str[20] = {0};
570 char key_mgmt[16] = {0};
571 char pairwise[16] = {0};
572 int phy_index = 0;
573
574 sta = calloc(1, sizeof(wifi_sta_network_t));
575
576 phy_index = radio_index_to_phy(sta_param.radio_index);
577 set_interface_bssid(phy_index, sta_param.mac_offset, &sta_mac);
578 mac_addr_ntoa(sta_mac_str, sta_mac);
579 snprintf(sta->ssid, 31, "%s", sta_param.ssid);
580 sta->ssid[31] = '\0';
581 snprintf(sta->psk, 64, "%s", sta_param.password);
582
583 if (sta_param.security.mode == wifi_security_mode_none)
584 strcpy(key_mgmt, "NONE");
585 else if (sta_param.security.mode == wifi_security_mode_wpa3_personal)
586 strcpy(key_mgmt, "SAE");
developerf634eab2023-01-13 15:23:06 +0800587 else if (sta_param.security.mode == wifi_security_mode_owe)
588 strcpy(key_mgmt, "OWE");
developer9567a462022-11-17 20:42:05 +0800589 else
590 strcpy(key_mgmt, "WPA-PSK");
591 snprintf(sta->key_mgmt, 64, "%s", key_mgmt);
592
593 if (sta_param.security.encr == wifi_encryption_aes)
594 strcpy(pairwise, "CCMP");
595 else if (sta_param.security.encr == wifi_encryption_tkip)
596 strcpy(pairwise, "TKIP");
597 else
598 strcpy(pairwise, "CCMP TKIP");
599 snprintf(sta->pairwise, 64, "%s", pairwise);
600
601 if (strlen(sta_param.security.u.key.key) > 0)
602 strncpy(sta->psk, sta_param.security.u.key.key, 127);
603 sta->psk[127] = '\0';
604 sta->psk_len = strlen(sta->psk);
605
developerb3f00662022-12-29 09:35:55 +0800606 if (sta_param.wds_mode == TRUE)
607 sta->flags |= WIFI_STA_NET_F_4ADDR_MULTI_AP;
608
609 wifi_createSTAInterface(sta_param.sta_index, sta_mac_str, sta_param.wds_mode);
developer9567a462022-11-17 20:42:05 +0800610
611 if (wifi_setSTANetworks(sta_param.sta_index, &sta, 1, FALSE) == RETURN_ERR) {
612 fprintf(stderr, "Write to sta %d config file failed\n", sta_param.sta_index);
613 free(sta);
614 return;
615 }
616 free(sta);
617
618 if (wifi_setSTAEnabled(sta_param.sta_index, TRUE) == RETURN_ERR) {
619 fprintf(stderr, "Enable station failed\n");
620 return;
621 }
622}
623
developer223f5982023-02-28 15:59:38 +0800624void show_ap_param(wifi_intf_param ap_param , wifi_vap_info_map_t *map)
625{
626 int ret = 0;
627 int vap_index_in_map = 0;
628 int phy_index = 0;
629 wifi_vap_info_t vap_info = {0};
630 BOOL radio_enable = FALSE;
631 BOOL wps_state = FALSE;
632 UINT buf_size = 1024;
633 char macArray[1024] = "";
634
635 if(ap_param.radio_index == -1)
636 return;
637
638 wifi_getRadioEnable(ap_param.radio_index, &radio_enable);
639 if (radio_enable == FALSE)
640 return;
641
642
643 // get the index of the map
644 for (int i = 0; i < map->num_vaps; i++) {
645 if (map->vap_array[i].vap_index == ap_param.ap_index) {
646 vap_index_in_map = i;
647 break;
648 }
649 }
650
651 vap_info = map->vap_array[vap_index_in_map];
652 vap_info.u.bss_info.enabled = TRUE;
653 phy_index = radio_index_to_phy(vap_info.radio_index);
654
655 // SSID
656 printf("wifi%d ssid: %s\n", ap_param.ap_index, vap_info.u.bss_info.ssid);
657
658 // igmpsn_enable
659 printf("wifi%d igmpsn_enable: %d\n", ap_param.ap_index, vap_info.u.bss_info.mcast2ucast);
660
661 // wps_state
662 ret = wifi_getApWpsEnable(ap_param.ap_index, &wps_state);
663 if (ret != RETURN_OK)
664 fprintf(stderr, "[Set wps_state failed!!!]\n");
665 else
666 printf("wifi%d wps_state: %d\n", ap_param.ap_index, wps_state);
667 ret = 0;
668
669 // macfilter
670 if (vap_info.u.bss_info.mac_filter_enable == FALSE)
671 printf("wifi%d macfilter: disable\n", ap_param.ap_index);
672 else if (vap_info.u.bss_info.mac_filter_mode = wifi_mac_filter_mode_white_list)
673 printf("wifi%d macfilter: allow\n", ap_param.ap_index);
674 else if (vap_info.u.bss_info.mac_filter_mode = wifi_mac_filter_mode_black_list)
675 printf("wifi%d macfilter: deny\n", ap_param.ap_index);
676
677 printf("daisy wifi%d macfilter: %d\n", ap_param.ap_index, vap_info.u.bss_info.mac_filter_enable);
678 printf("daisy wifi%d macfilter: %d\n", ap_param.ap_index, vap_info.u.bss_info.mac_filter_mode);
679
680 // maclist
681 printf("wifi%d maclist: \n", ap_param.ap_index);
682 ret = wifi_getApAclDevices(ap_param.ap_index, macArray, buf_size);
683 if (ret != RETURN_OK)
684 fprintf(stderr, "[Get maclist failed!!!]\n");
685 else
686 printf("%s \n", macArray);
687 ret = 0;
688
689}
690
developer402bf2a2022-10-04 15:20:18 +0800691int apply_uci_config ()
692{
693 struct uci_context *uci_ctx = uci_alloc_context();
694 struct uci_package *uci_pkg = NULL;
695 struct uci_element *e;
696 // struct uci_section *s;
697 const char cfg_name[] = "wireless";
698 int max_radio_num = 0;
699 BOOL parsing_radio = FALSE;
developer4c2edbe2022-10-18 16:36:37 +0800700 int apCount[3] = {0};
developer9567a462022-11-17 20:42:05 +0800701 int staCount[3] = {0};
developer41965b52022-10-19 17:40:23 +0800702 wifi_vap_info_map_t vap_map[3] = {0};
703 int ret = 0;
704 int i = 0;
developer402bf2a2022-10-04 15:20:18 +0800705
706 wifi_getMaxRadioNumber(&max_radio_num);
707 fprintf(stderr, "max radio number: %d\n", max_radio_num);
developer41965b52022-10-19 17:40:23 +0800708 for (i = 0; i < max_radio_num ;i++ ){
709 ret = wifi_getRadioVapInfoMap(i, &vap_map[i]);
710 if (ret != RETURN_OK) { // if failed, we set assume this vap as the first vap.
711 fprintf(stderr, "[Get vap map failed!!!]\n");
712 vap_map[i].num_vaps = MAX_NUM_VAP_PER_RADIO;
713 }
714 }
developer402bf2a2022-10-04 15:20:18 +0800715 if (uci_load(uci_ctx, cfg_name, &uci_pkg) != UCI_OK) {
716 uci_free_context(uci_ctx);
717 fprintf(stderr, "%s: load uci failed.\n", __func__);
718 return RETURN_ERR;
719 }
720
721 uci_foreach_element(&uci_pkg->sections, e) {
722
723 struct uci_section *s = uci_to_section(e);
724 struct uci_element *option = NULL;
725 wifi_radio_param radio_param = {0};
developer1ac0e892022-11-25 14:30:05 +0800726 wifi_intf_param intf_param = {0};
developer4c2edbe2022-10-18 16:36:37 +0800727 int phyId = 0;
developer402bf2a2022-10-04 15:20:18 +0800728 radio_param.radio_index = -1;
developer1ac0e892022-11-25 14:30:05 +0800729 intf_param.ap_index = -1;
developer402bf2a2022-10-04 15:20:18 +0800730
731 if (strcmp(s->type, "wifi-device") == 0) {
developer4c2edbe2022-10-18 16:36:37 +0800732 sscanf(s->e.name, "radio%d", &phyId);
733 radio_param.radio_index = phy_index_to_radio(phyId);
developer402bf2a2022-10-04 15:20:18 +0800734 parsing_radio = TRUE;
735 fprintf(stderr, "\n----- Start parsing radio %d config. -----\n", radio_param.radio_index);
736 } else if (strcmp(s->type, "wifi-iface") == 0) {
developer402bf2a2022-10-04 15:20:18 +0800737 parsing_radio = FALSE;
developer402bf2a2022-10-04 15:20:18 +0800738 }
739
740 uci_foreach_element(&s->options, option) {
741
742 struct uci_option *op = uci_to_option(option);
743 if (parsing_radio == TRUE) {
744 // transform the type from input string and store the value in radio_param.
745 if (strcmp(op->e.name, "channel") == 0)
746 set_channel(&radio_param, op->v.string);
747 else if (strcmp(op->e.name, "hwmode") == 0)
748 set_hwmode(&radio_param, op->v.string);
749 else if (strcmp(op->e.name, "htmode") == 0)
750 set_htmode(&radio_param, op->v.string);
751 else if (strcmp(op->e.name, "disabled") == 0)
752 set_disable(&radio_param, op->v.string);
753 else if (strcmp(op->e.name, "band") == 0)
754 set_band(&radio_param, op->v.string);
755 else if (strcmp(op->e.name, "country") == 0)
756 set_country(&radio_param, op->v.string);
757 else if (strcmp(op->e.name, "noscan") == 0)
developer54afa2c2022-10-18 17:44:13 +0800758 set_noscan(&radio_param, op->v.string);
developer1e946fd2022-12-26 17:09:00 +0800759 else if (strcmp(op->e.name, "rxantenna") == 0)
760 set_rxant(&radio_param, op->v.string);
761 else if (strcmp(op->e.name, "txantenna") == 0)
762 set_txant(&radio_param, op->v.string);
developerc4548732023-02-06 20:02:10 +0800763 else if (strcmp(op->e.name, "ht_coex") == 0)
764 set_htcoex(&radio_param, op->v.string);
765 else if (strcmp(op->e.name, "rts") == 0)
766 set_rts(&radio_param, op->v.string);
developer402bf2a2022-10-04 15:20:18 +0800767 else
768 fprintf(stderr, "[%s %s not set!]\n", op->e.name, op->v.string);
769 } else {
770 // parsing iface
developer4c2edbe2022-10-18 16:36:37 +0800771 if (strcmp(op->e.name, "device") == 0){
developer1ac0e892022-11-25 14:30:05 +0800772 set_radionum(&intf_param, op->v.string);
developer9567a462022-11-17 20:42:05 +0800773 }else if (strcmp(op->e.name, "mode") == 0){
developerb97b5492022-12-22 19:44:36 +0800774 intf_param.mac_offset = staCount[intf_param.radio_index] + apCount[intf_param.radio_index];
developer9567a462022-11-17 20:42:05 +0800775 if (strncmp(op->v.string, "sta", 3) == 0) {
developer1ac0e892022-11-25 14:30:05 +0800776 intf_param.sta_mode = TRUE;
777 intf_param.sta_index = intf_param.radio_index + staCount[intf_param.radio_index]*max_radio_num;
778 staCount[intf_param.radio_index] ++ ;
779 fprintf(stderr, "\n----- Start parsing sta %d config. -----\n", intf_param.sta_index);
developer9567a462022-11-17 20:42:05 +0800780 } else if (strncmp(op->v.string, "ap", 2) == 0) {
developer1ac0e892022-11-25 14:30:05 +0800781 intf_param.sta_mode = FALSE;
782 intf_param.ap_index = intf_param.radio_index + apCount[intf_param.radio_index]*max_radio_num;
783 apCount[intf_param.radio_index] ++ ;
784 fprintf(stderr, "\n----- Start parsing ap %d config. -----\n", intf_param.ap_index);
developer9567a462022-11-17 20:42:05 +0800785 }
developer4c2edbe2022-10-18 16:36:37 +0800786 }else if (strcmp(op->e.name, "ssid") == 0){
developer1ac0e892022-11-25 14:30:05 +0800787 set_ssid(&intf_param, op->v.string);
developer4c2edbe2022-10-18 16:36:37 +0800788 }else if (strcmp(op->e.name, "encryption") == 0){
developer1ac0e892022-11-25 14:30:05 +0800789 set_encryption(&intf_param, op->v.string);
developer4c2edbe2022-10-18 16:36:37 +0800790 }else if (strcmp(op->e.name, "key") == 0){
developer1ac0e892022-11-25 14:30:05 +0800791 set_key(&intf_param, op->v.string);
developer2bcdef92022-12-13 16:19:09 +0800792 }else if (strcmp(op->e.name, "ifname") == 0){
793 set_ifname(&intf_param, op->v.string);
developerb3f00662022-12-29 09:35:55 +0800794 }else if (strcmp(op->e.name, "wds") == 0){
795 set_wds(&intf_param, op->v.string);
developerc4548732023-02-06 20:02:10 +0800796 }else if (strcmp(op->e.name, "hidden") == 0){
797 set_hidden(&intf_param, op->v.string);
developer223f5982023-02-28 15:59:38 +0800798 }else if (strcmp(op->e.name, "igmpsn_enable") == 0){
799 set_igmpsn_enable(&intf_param, op->v.string);
800 }else if (strcmp(op->e.name, "wps_state") == 0){
801 set_wps_state(&intf_param, op->v.string);
802 }else if (strcmp(op->e.name, "wps_cancel") == 0){
803 set_wps_cancel(&intf_param, op->v.string);
804 }else if (strcmp(op->e.name, "wps_pushbutton") == 0){
805 set_wps_pushbutton(&intf_param, op->v.string);
806 }else if (strcmp(op->e.name, "macfilter") == 0){
807 set_macfilter(&intf_param, op->v.string);
808 }else if (strcmp(op->e.name, "maclist") == 0){
809 set_maclist(&intf_param, op->v.string);
developer4c2edbe2022-10-18 16:36:37 +0800810 }else{
developer402bf2a2022-10-04 15:20:18 +0800811 fprintf(stderr, "[%s %s not set!]\n", op->e.name, op->v.string);
developer223f5982023-02-28 15:59:38 +0800812 }
developer402bf2a2022-10-04 15:20:18 +0800813 }
814 }
815 if (parsing_radio == TRUE)
816 set_radio_param(radio_param);
developer1ac0e892022-11-25 14:30:05 +0800817 else if (intf_param.sta_mode == TRUE)
818 set_sta_param(intf_param);
developer402bf2a2022-10-04 15:20:18 +0800819 else
developer1ac0e892022-11-25 14:30:05 +0800820 set_ap_param(intf_param, &vap_map[intf_param.radio_index]);
developer402bf2a2022-10-04 15:20:18 +0800821 }
developer9567a462022-11-17 20:42:05 +0800822 fprintf(stderr, "\n----- Start setting Vaps. -----\n");
developer402bf2a2022-10-04 15:20:18 +0800823
developer41965b52022-10-19 17:40:23 +0800824 for (i = 0; i < max_radio_num ;i++ ){
825 ret = wifi_createVAP(i, &vap_map[i]);
826 if (ret != RETURN_OK)
827 fprintf(stderr, "[Apply vap setting failed!!!]\n");
828 }
developer223f5982023-02-28 15:59:38 +0800829
developer402bf2a2022-10-04 15:20:18 +0800830 uci_unload(uci_ctx, uci_pkg);
831 uci_free_context(uci_ctx);
832 return RETURN_OK;
833}
834
developer223f5982023-02-28 15:59:38 +0800835int dump_wifi_status ()
836{
837
838 struct uci_context *uci_ctx = uci_alloc_context();
839 struct uci_package *uci_pkg = NULL;
840 struct uci_element *e;
841 // struct uci_section *s;
842 const char cfg_name[] = "wireless";
843 int max_radio_num = 0;
844 BOOL parsing_radio = FALSE;
845 int apCount[3] = {0};
846 int staCount[3] = {0};
847 wifi_vap_info_map_t vap_map[3] = {0};
848 int ret = 0;
849 int i = 0;
850
851 wifi_getMaxRadioNumber(&max_radio_num);
852 fprintf(stderr, "max radio number: %d\n", max_radio_num);
853 for (i = 0; i < max_radio_num ;i++ ){
854 ret = wifi_getRadioVapInfoMap(i, &vap_map[i]);
855 if (ret != RETURN_OK) { // if failed, we set assume this vap as the first vap.
856 fprintf(stderr, "[Get vap map failed!!!]\n");
857 vap_map[i].num_vaps = MAX_NUM_VAP_PER_RADIO;
858 }
859 }
860 if (uci_load(uci_ctx, cfg_name, &uci_pkg) != UCI_OK) {
861 uci_free_context(uci_ctx);
862 fprintf(stderr, "%s: load uci failed.\n", __func__);
863 return RETURN_ERR;
864 }
865
866 uci_foreach_element(&uci_pkg->sections, e) {
867
868 struct uci_section *s = uci_to_section(e);
869 struct uci_element *option = NULL;
870 wifi_radio_param radio_param = {0};
871 wifi_intf_param intf_param = {0};
872 int phyId = 0;
873 radio_param.radio_index = -1;
874 intf_param.ap_index = -1;
875
876 if (strcmp(s->type, "wifi-device") == 0) {
877 sscanf(s->e.name, "radio%d", &phyId);
878 radio_param.radio_index = phy_index_to_radio(phyId);
879 parsing_radio = TRUE;
880 fprintf(stderr, "\n----- Start show radio %d config. -----\n", radio_param.radio_index);
881 } else if (strcmp(s->type, "wifi-iface") == 0) {
882 parsing_radio = FALSE;
883 }
884
885 uci_foreach_element(&s->options, option) {
886
887 struct uci_option *op = uci_to_option(option);
888 if (parsing_radio == TRUE) {
889 // transform the type from input string and store the value in radio_param.
890 } else {
891 // parsing iface
892 if (strcmp(op->e.name, "device") == 0){
893 set_radionum(&intf_param, op->v.string);
894 }else if (strcmp(op->e.name, "mode") == 0){
895 intf_param.mac_offset = staCount[intf_param.radio_index] + apCount[intf_param.radio_index];
896 if (strncmp(op->v.string, "sta", 3) == 0) {
897 intf_param.sta_mode = TRUE;
898 intf_param.sta_index = intf_param.radio_index + staCount[intf_param.radio_index]*max_radio_num;
899 staCount[intf_param.radio_index] ++ ;
900 fprintf(stderr, "\n----- Start show sta %d config. -----\n", intf_param.sta_index);
901 } else if (strncmp(op->v.string, "ap", 2) == 0) {
902 intf_param.sta_mode = FALSE;
903 intf_param.ap_index = intf_param.radio_index + apCount[intf_param.radio_index]*max_radio_num;
904 apCount[intf_param.radio_index] ++ ;
905 fprintf(stderr, "\n----- Start show ap %d config. -----\n", intf_param.ap_index);
906 }
907 }
908 }
909 }
910 if (parsing_radio == TRUE)
911 printf("show radio params: \n");
912 // show_radio_param(radio_param);
913 else if (intf_param.sta_mode == TRUE)
914 printf("show sta params: \n");
915 // show_sta_param(intf_param);
916 else{
917 printf("show ap params: \n");
918 show_ap_param(intf_param, &vap_map[intf_param.radio_index]);
919 }
920 }
921
922 uci_unload(uci_ctx, uci_pkg);
923 uci_free_context(uci_ctx);
924 return RETURN_OK;
925
926}
927
developer402bf2a2022-10-04 15:20:18 +0800928int main(int argc, char **argv)
929{
developer223f5982023-02-28 15:59:38 +0800930 if (argc != 2 || (strcmp(argv[1], "reload") != 0 && strcmp(argv[1], "dump") != 0) ){
931 fprintf(stderr, "Usage: wifi reload/wifi dump.\nThis tool is only for RDKB MSP/SQC test.\n");
developer402bf2a2022-10-04 15:20:18 +0800932 return -1;
933 }
developer223f5982023-02-28 15:59:38 +0800934 if (strcmp(argv[1], "reload") == 0)
935 apply_uci_config();
936 else if (strcmp(argv[1], "dump") == 0)
937 dump_wifi_status();
developer402bf2a2022-10-04 15:20:18 +0800938 return 0;
939}