blob: 1887acaf36759cf91066a6cffcaccf3b8000b455 [file] [log] [blame]
developer91f80742022-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
developer50614832022-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}
developer8d8d6302022-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);
developerc6a27322023-01-13 15:23:06 +080069 return radioIndex;
developer8d8d6302022-10-18 16:36:37 +080070}
71
developer91f80742022-10-04 15:20:18 +080072void set_channel(wifi_radio_param *radio_param, char *channel)
73{
developer63d72772022-10-07 09:42:31 +080074 if (strcmp(channel, "auto") == 0) {
75 radio_param->auto_channel = TRUE;
76 radio_param->channel = 0;
77 } else {
developer91f80742022-10-04 15:20:18 +080078 radio_param->auto_channel = FALSE;
developer63d72772022-10-07 09:42:31 +080079 radio_param->channel = strtol(channel, NULL, 10);
developer91f80742022-10-04 15:20:18 +080080 }
developer63d72772022-10-07 09:42:31 +080081 return;
developer91f80742022-10-04 15:20:18 +080082}
83
developer52c6ca22022-10-06 17:16:43 +080084void set_country(wifi_radio_param *radio_param, char *country)
developer91f80742022-10-04 15:20:18 +080085{
86 strcpy(radio_param->country, country);
87}
88
developer52c6ca22022-10-06 17:16:43 +080089void set_band(wifi_radio_param *radio_param, char *band)
developer91f80742022-10-04 15:20:18 +080090{
91 strcpy(radio_param->band, band);
92}
93
developer6feac682022-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
developer91f80742022-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
developer128f8aa2022-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
developera3ec58b2023-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
developer13ec7352023-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
developer465ca0c2022-11-25 14:30:05 +0800221void set_radionum(wifi_intf_param *intf_param, char *phy_name)
developer91f80742022-10-04 15:20:18 +0800222{
developer50614832022-11-17 20:42:05 +0800223 int radio_num = 0;
224 char *ptr = phy_name;
developer8d8d6302022-10-18 16:36:37 +0800225 int phyId = 0;
developer91f80742022-10-04 15:20:18 +0800226
227 while (*ptr) {
228 if (isdigit(*ptr)) {
developer50614832022-11-17 20:42:05 +0800229 phyId = strtoul(ptr, NULL, 10);
230 radio_num = phy_index_to_radio(phyId);
developer465ca0c2022-11-25 14:30:05 +0800231 intf_param->radio_index = radio_num;
developer91f80742022-10-04 15:20:18 +0800232 break;
233 }
234 ptr++;
235 }
236}
237
developer465ca0c2022-11-25 14:30:05 +0800238void set_ssid(wifi_intf_param *intf_param, char *ssid)
developer91f80742022-10-04 15:20:18 +0800239{
developer465ca0c2022-11-25 14:30:05 +0800240 strncpy(intf_param->ssid, ssid, 32);
developer91f80742022-10-04 15:20:18 +0800241}
242
developer465ca0c2022-11-25 14:30:05 +0800243void set_encryption(wifi_intf_param *intf_param, char *encryption_mode)
developer91f80742022-10-04 15:20:18 +0800244{
developerff378f22022-10-13 13:33:57 +0800245 if (strcmp(encryption_mode, "none") == 0) {
developer465ca0c2022-11-25 14:30:05 +0800246 intf_param->security.mode = wifi_security_mode_none;
247 intf_param->security.encr = wifi_encryption_none;
developerff378f22022-10-13 13:33:57 +0800248 }else if(strncmp(encryption_mode, "psk2", 4) == 0){
developer465ca0c2022-11-25 14:30:05 +0800249 intf_param->security.mode = wifi_security_mode_wpa2_personal;
developerff378f22022-10-13 13:33:57 +0800250 }else if(strncmp(encryption_mode, "psk-",4) == 0){
developer465ca0c2022-11-25 14:30:05 +0800251 intf_param->security.mode = wifi_security_mode_wpa_wpa2_personal;
developerff378f22022-10-13 13:33:57 +0800252 }else if(strncmp(encryption_mode, "psk",3) == 0){
developer465ca0c2022-11-25 14:30:05 +0800253 intf_param->security.mode = wifi_security_mode_wpa_personal;
developerff378f22022-10-13 13:33:57 +0800254 }else if(strncmp(encryption_mode, "wpa2",4) == 0){
developer465ca0c2022-11-25 14:30:05 +0800255 intf_param->security.mode = wifi_security_mode_wpa2_enterprise;
developerff378f22022-10-13 13:33:57 +0800256 }else if(strncmp(encryption_mode, "wpa-",4) == 0){
developer465ca0c2022-11-25 14:30:05 +0800257 intf_param->security.mode = wifi_security_mode_wpa_wpa2_enterprise;
developerff378f22022-10-13 13:33:57 +0800258 }else if(strcmp(encryption_mode, "sae") == 0){
developer465ca0c2022-11-25 14:30:05 +0800259 intf_param->security.mode = wifi_security_mode_wpa3_personal;
developerff378f22022-10-13 13:33:57 +0800260 }else if(strcmp(encryption_mode, "wpa3") == 0){
developer465ca0c2022-11-25 14:30:05 +0800261 intf_param->security.mode = wifi_security_mode_wpa3_enterprise;
developerff378f22022-10-13 13:33:57 +0800262 }else if(strcmp(encryption_mode, "sae-mixed") == 0){
developer465ca0c2022-11-25 14:30:05 +0800263 intf_param->security.mode = wifi_security_mode_wpa3_transition;
developerc6a27322023-01-13 15:23:06 +0800264 }else if(strcmp(encryption_mode, "owe") == 0){
265 intf_param->security.mode = wifi_security_mode_owe;
developer91f80742022-10-04 15:20:18 +0800266 }
267
developerff378f22022-10-13 13:33:57 +0800268 if(strstr(encryption_mode, "tkip") && (strstr(encryption_mode, "ccmp") || strstr(encryption_mode, "aes") )){
developer465ca0c2022-11-25 14:30:05 +0800269 intf_param->security.encr = wifi_encryption_aes_tkip;
developerff378f22022-10-13 13:33:57 +0800270 }else if (strstr(encryption_mode, "tkip")){
developer465ca0c2022-11-25 14:30:05 +0800271 intf_param->security.encr = wifi_encryption_tkip;
developerff378f22022-10-13 13:33:57 +0800272 }else{
developer465ca0c2022-11-25 14:30:05 +0800273 intf_param->security.encr = wifi_encryption_aes;
developer91f80742022-10-04 15:20:18 +0800274 }
developerff378f22022-10-13 13:33:57 +0800275
developerc6a27322023-01-13 15:23:06 +0800276 if(!strcmp(encryption_mode, "wpa3") || !strcmp(encryption_mode, "sae") || !strcmp(encryption_mode, "owe")){
developer465ca0c2022-11-25 14:30:05 +0800277 intf_param->security.mfp = wifi_mfp_cfg_required;
developerff378f22022-10-13 13:33:57 +0800278 }else if (!strcmp(encryption_mode, "sae-mixed")){
developer465ca0c2022-11-25 14:30:05 +0800279 intf_param->security.mfp = wifi_mfp_cfg_optional;
developerff378f22022-10-13 13:33:57 +0800280 }else{
developer465ca0c2022-11-25 14:30:05 +0800281 intf_param->security.mfp = wifi_mfp_cfg_disabled;
developerff378f22022-10-13 13:33:57 +0800282 }
developer91f80742022-10-04 15:20:18 +0800283}
284
developer465ca0c2022-11-25 14:30:05 +0800285void set_key(wifi_intf_param *intf_param, char *key)
developer91f80742022-10-04 15:20:18 +0800286{
developer465ca0c2022-11-25 14:30:05 +0800287 strncpy(intf_param->security.u.key.key, key, 64);
developer91f80742022-10-04 15:20:18 +0800288}
289
developer7ac3bd52022-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
developerb2123782022-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
developer13ec7352023-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
developer50614832022-11-17 20:42:05 +0800309int set_interface_bssid(int phy_index, int offset, mac_address_t *bssid)
developerf7e50b02022-10-14 10:07:58 +0800310{
311 FILE *f;
312 char mac_file[64] = {0};
313 char mac_address[20] = {0};
developerf7e50b02022-10-14 10:07:58 +0800314
developer1ac426a2022-12-22 19:44:36 +0800315 sprintf(mac_file, "/sys/class/ieee80211/phy%d/macaddress", phy_index);
developerf7e50b02022-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
developer50614832022-11-17 20:42:05 +0800322 mac_addr_aton(&(*bssid)[0], mac_address);
323 (*bssid)[0] += offset*2;
developerf7e50b02022-10-14 10:07:58 +0800324 return 0;
325}
326
developer91f80742022-10-04 15:20:18 +0800327void set_radio_param(wifi_radio_param radio_parameter)
328{
developer91f80742022-10-04 15:20:18 +0800329 int ret = 0;
developer63d72772022-10-07 09:42:31 +0800330 wifi_radio_operationParam_t operationParam = {0};
331
developer8d8d6302022-10-18 16:36:37 +0800332 if(radio_parameter.radio_index == -1)
333 return;
334
developer63d72772022-10-07 09:42:31 +0800335 if (radio_parameter.disabled == TRUE) {
336 wifi_setRadioEnable(radio_parameter.radio_index, FALSE);
337 return;
338 }
developer91f80742022-10-04 15:20:18 +0800339
340 fprintf(stderr, "Start setting radio\n");
developerbf812932022-10-17 17:37:29 +0800341
developer128f8aa2022-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
developerbf812932022-10-17 17:37:29 +0800348 // Get current radio setting
developer63d72772022-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");
developerbf812932022-10-17 17:37:29 +0800352 operationParam.enable = TRUE;
developer91f80742022-10-04 15:20:18 +0800353
developer91f80742022-10-04 15:20:18 +0800354 // Channel
developer63d72772022-10-07 09:42:31 +0800355 operationParam.autoChannelEnabled = radio_parameter.auto_channel;
356 operationParam.channel = radio_parameter.channel;
developer91f80742022-10-04 15:20:18 +0800357
developer25e07812022-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 }
developer91f80742022-10-04 15:20:18 +0800368
369 // htmode
developer63d72772022-10-07 09:42:31 +0800370 unsigned int mode = 0; // enum wifi_ieee80211Variant_t
developer91f80742022-10-04 15:20:18 +0800371 if (strcmp(radio_parameter.band, "2g") == 0) {
developer63d72772022-10-07 09:42:31 +0800372 mode |= WIFI_80211_VARIANT_B | WIFI_80211_VARIANT_G;
developer91f80742022-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
developer63d72772022-10-07 09:42:31 +0800376 if (strstr(radio_parameter.htmode, "HE") != NULL)
377 mode |= WIFI_80211_VARIANT_N | WIFI_80211_VARIANT_AX;
developer91f80742022-10-04 15:20:18 +0800378
developer63d72772022-10-07 09:42:31 +0800379 } else if (strcmp(radio_parameter.band, "5g") == 0) {
380 mode |= WIFI_80211_VARIANT_A;
developer91f80742022-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");
developer63d72772022-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;
developer8d8d6302022-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 }
developer91f80742022-10-04 15:20:18 +0800389
390 if (strstr(radio_parameter.htmode, "VHT") != NULL)
developer63d72772022-10-07 09:42:31 +0800391 mode |= WIFI_80211_VARIANT_N | WIFI_80211_VARIANT_AC;
developer91f80742022-10-04 15:20:18 +0800392 else if (strstr(radio_parameter.htmode, "HT") != NULL && strstr(radio_parameter.htmode, "NO") == NULL)
developer63d72772022-10-07 09:42:31 +0800393 mode |= WIFI_80211_VARIANT_N;
developer91f80742022-10-04 15:20:18 +0800394
developer63d72772022-10-07 09:42:31 +0800395 operationParam.variant = mode;
developer91f80742022-10-04 15:20:18 +0800396
developer13ec7352023-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
developer63d72772022-10-07 09:42:31 +0800404 // apply setting
405 ret = wifi_setRadioOperatingParameters(radio_parameter.radio_index, &operationParam);
developer91f80742022-10-04 15:20:18 +0800406 if (ret != RETURN_OK)
developer63d72772022-10-07 09:42:31 +0800407 fprintf(stderr, "[Apply setting failed!!!]\n");
developer91f80742022-10-04 15:20:18 +0800408
developerbb58a932022-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
developer91f80742022-10-04 15:20:18 +0800432}
433
developer465ca0c2022-11-25 14:30:05 +0800434void set_ap_param(wifi_intf_param ap_param , wifi_vap_info_map_t *map)
developer91f80742022-10-04 15:20:18 +0800435{
436 int ret = 0;
developer63d72772022-10-07 09:42:31 +0800437 int vap_index_in_map = 0;
developer50614832022-11-17 20:42:05 +0800438 int phy_index = 0;
developerbaf61262023-02-17 15:52:18 +0800439 int key_len = 0;
developer63d72772022-10-07 09:42:31 +0800440 wifi_vap_info_t vap_info = {0};
developerbf812932022-10-17 17:37:29 +0800441 BOOL radio_enable = FALSE;
442
developerff42a302022-10-19 17:40:23 +0800443 if(ap_param.radio_index == -1)
444 return;
445
developerbf812932022-10-17 17:37:29 +0800446 wifi_getRadioEnable(ap_param.radio_index, &radio_enable);
447 if (radio_enable == FALSE)
448 return;
developer63d72772022-10-07 09:42:31 +0800449
developerff42a302022-10-19 17:40:23 +0800450
451 // get the index of the map
developerd9bf1dd2023-02-22 15:49:20 +0800452 for (int i = 0; i < MAX_NUM_VAP_PER_RADIO; i++) {
developerff42a302022-10-19 17:40:23 +0800453 if (map->vap_array[i].vap_index == ap_param.ap_index) {
454 vap_index_in_map = i;
455 break;
developer63d72772022-10-07 09:42:31 +0800456 }
457 }
458
developerff42a302022-10-19 17:40:23 +0800459
developerd9bf1dd2023-02-22 15:49:20 +0800460 fprintf(stderr, "Start setting ap vap_index_in_map=%d\n", vap_index_in_map);
developerf7e50b02022-10-14 10:07:58 +0800461
developerff42a302022-10-19 17:40:23 +0800462 vap_info = map->vap_array[vap_index_in_map];
developerf7e50b02022-10-14 10:07:58 +0800463 vap_info.u.bss_info.enabled = TRUE;
developer50614832022-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) {
developerf7e50b02022-10-14 10:07:58 +0800466 fprintf(stderr, "Get mac address failed.\n");
developer50614832022-11-17 20:42:05 +0800467 return;
developerf7e50b02022-10-14 10:07:58 +0800468 }
developer91f80742022-10-04 15:20:18 +0800469
developer91f80742022-10-04 15:20:18 +0800470 // SSID
developer63d72772022-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';
developer91f80742022-10-04 15:20:18 +0800473
developer7ac3bd52022-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
developerbaf61262023-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
developerff378f22022-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);
developer13ec7352023-02-06 20:02:10 +0800497
498 // hidden
499 vap_info.u.bss_info.showSsid = (ap_param.hidden ? 0 : 1);
developer8d8d6302022-10-18 16:36:37 +0800500
developera3ec58b2023-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;
developer63d72772022-10-07 09:42:31 +0800561 // Replace the setting with uci config
developerff42a302022-10-19 17:40:23 +0800562 map->vap_array[vap_index_in_map] = vap_info;
developer91f80742022-10-04 15:20:18 +0800563}
564
developer465ca0c2022-11-25 14:30:05 +0800565void set_sta_param(wifi_intf_param sta_param)
developer50614832022-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");
developerc6a27322023-01-13 15:23:06 +0800587 else if (sta_param.security.mode == wifi_security_mode_owe)
588 strcpy(key_mgmt, "OWE");
developer50614832022-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
developerb2123782022-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);
developer50614832022-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
developera3ec58b2023-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
developer91f80742022-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;
developer8d8d6302022-10-18 16:36:37 +0800700 int apCount[3] = {0};
developer50614832022-11-17 20:42:05 +0800701 int staCount[3] = {0};
developerff42a302022-10-19 17:40:23 +0800702 wifi_vap_info_map_t vap_map[3] = {0};
703 int ret = 0;
developerd9bf1dd2023-02-22 15:49:20 +0800704 int i = 0, j = 0;
developer91f80742022-10-04 15:20:18 +0800705
706 wifi_getMaxRadioNumber(&max_radio_num);
707 fprintf(stderr, "max radio number: %d\n", max_radio_num);
developerff42a302022-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");
developerff42a302022-10-19 17:40:23 +0800712 }
developerd9bf1dd2023-02-22 15:49:20 +0800713
714 /*reset radio's ap number, ap number ++ by uci config */
715 vap_map[i].num_vaps = 0;
developerff42a302022-10-19 17:40:23 +0800716 }
developer91f80742022-10-04 15:20:18 +0800717 if (uci_load(uci_ctx, cfg_name, &uci_pkg) != UCI_OK) {
718 uci_free_context(uci_ctx);
719 fprintf(stderr, "%s: load uci failed.\n", __func__);
720 return RETURN_ERR;
721 }
722
723 uci_foreach_element(&uci_pkg->sections, e) {
724
725 struct uci_section *s = uci_to_section(e);
726 struct uci_element *option = NULL;
727 wifi_radio_param radio_param = {0};
developer465ca0c2022-11-25 14:30:05 +0800728 wifi_intf_param intf_param = {0};
developer8d8d6302022-10-18 16:36:37 +0800729 int phyId = 0;
developer91f80742022-10-04 15:20:18 +0800730 radio_param.radio_index = -1;
developer465ca0c2022-11-25 14:30:05 +0800731 intf_param.ap_index = -1;
developer91f80742022-10-04 15:20:18 +0800732
733 if (strcmp(s->type, "wifi-device") == 0) {
developer8d8d6302022-10-18 16:36:37 +0800734 sscanf(s->e.name, "radio%d", &phyId);
735 radio_param.radio_index = phy_index_to_radio(phyId);
developer91f80742022-10-04 15:20:18 +0800736 parsing_radio = TRUE;
737 fprintf(stderr, "\n----- Start parsing radio %d config. -----\n", radio_param.radio_index);
738 } else if (strcmp(s->type, "wifi-iface") == 0) {
developer91f80742022-10-04 15:20:18 +0800739 parsing_radio = FALSE;
developer91f80742022-10-04 15:20:18 +0800740 }
741
742 uci_foreach_element(&s->options, option) {
743
744 struct uci_option *op = uci_to_option(option);
745 if (parsing_radio == TRUE) {
746 // transform the type from input string and store the value in radio_param.
747 if (strcmp(op->e.name, "channel") == 0)
748 set_channel(&radio_param, op->v.string);
749 else if (strcmp(op->e.name, "hwmode") == 0)
750 set_hwmode(&radio_param, op->v.string);
751 else if (strcmp(op->e.name, "htmode") == 0)
752 set_htmode(&radio_param, op->v.string);
753 else if (strcmp(op->e.name, "disabled") == 0)
754 set_disable(&radio_param, op->v.string);
755 else if (strcmp(op->e.name, "band") == 0)
756 set_band(&radio_param, op->v.string);
757 else if (strcmp(op->e.name, "country") == 0)
758 set_country(&radio_param, op->v.string);
759 else if (strcmp(op->e.name, "noscan") == 0)
developer6feac682022-10-18 17:44:13 +0800760 set_noscan(&radio_param, op->v.string);
developer128f8aa2022-12-26 17:09:00 +0800761 else if (strcmp(op->e.name, "rxantenna") == 0)
762 set_rxant(&radio_param, op->v.string);
763 else if (strcmp(op->e.name, "txantenna") == 0)
764 set_txant(&radio_param, op->v.string);
developer13ec7352023-02-06 20:02:10 +0800765 else if (strcmp(op->e.name, "ht_coex") == 0)
766 set_htcoex(&radio_param, op->v.string);
767 else if (strcmp(op->e.name, "rts") == 0)
768 set_rts(&radio_param, op->v.string);
developer91f80742022-10-04 15:20:18 +0800769 else
770 fprintf(stderr, "[%s %s not set!]\n", op->e.name, op->v.string);
771 } else {
772 // parsing iface
developer8d8d6302022-10-18 16:36:37 +0800773 if (strcmp(op->e.name, "device") == 0){
developer465ca0c2022-11-25 14:30:05 +0800774 set_radionum(&intf_param, op->v.string);
developer50614832022-11-17 20:42:05 +0800775 }else if (strcmp(op->e.name, "mode") == 0){
developer1ac426a2022-12-22 19:44:36 +0800776 intf_param.mac_offset = staCount[intf_param.radio_index] + apCount[intf_param.radio_index];
developer50614832022-11-17 20:42:05 +0800777 if (strncmp(op->v.string, "sta", 3) == 0) {
developer465ca0c2022-11-25 14:30:05 +0800778 intf_param.sta_mode = TRUE;
779 intf_param.sta_index = intf_param.radio_index + staCount[intf_param.radio_index]*max_radio_num;
780 staCount[intf_param.radio_index] ++ ;
781 fprintf(stderr, "\n----- Start parsing sta %d config. -----\n", intf_param.sta_index);
developer50614832022-11-17 20:42:05 +0800782 } else if (strncmp(op->v.string, "ap", 2) == 0) {
developer465ca0c2022-11-25 14:30:05 +0800783 intf_param.sta_mode = FALSE;
784 intf_param.ap_index = intf_param.radio_index + apCount[intf_param.radio_index]*max_radio_num;
785 apCount[intf_param.radio_index] ++ ;
786 fprintf(stderr, "\n----- Start parsing ap %d config. -----\n", intf_param.ap_index);
developer50614832022-11-17 20:42:05 +0800787 }
developer8d8d6302022-10-18 16:36:37 +0800788 }else if (strcmp(op->e.name, "ssid") == 0){
developer465ca0c2022-11-25 14:30:05 +0800789 set_ssid(&intf_param, op->v.string);
developer8d8d6302022-10-18 16:36:37 +0800790 }else if (strcmp(op->e.name, "encryption") == 0){
developer465ca0c2022-11-25 14:30:05 +0800791 set_encryption(&intf_param, op->v.string);
developer8d8d6302022-10-18 16:36:37 +0800792 }else if (strcmp(op->e.name, "key") == 0){
developer465ca0c2022-11-25 14:30:05 +0800793 set_key(&intf_param, op->v.string);
developer7ac3bd52022-12-13 16:19:09 +0800794 }else if (strcmp(op->e.name, "ifname") == 0){
795 set_ifname(&intf_param, op->v.string);
developerb2123782022-12-29 09:35:55 +0800796 }else if (strcmp(op->e.name, "wds") == 0){
797 set_wds(&intf_param, op->v.string);
developer13ec7352023-02-06 20:02:10 +0800798 }else if (strcmp(op->e.name, "hidden") == 0){
799 set_hidden(&intf_param, op->v.string);
developera3ec58b2023-02-28 15:59:38 +0800800 }else if (strcmp(op->e.name, "igmpsn_enable") == 0){
801 set_igmpsn_enable(&intf_param, op->v.string);
802 }else if (strcmp(op->e.name, "wps_state") == 0){
803 set_wps_state(&intf_param, op->v.string);
804 }else if (strcmp(op->e.name, "wps_cancel") == 0){
805 set_wps_cancel(&intf_param, op->v.string);
806 }else if (strcmp(op->e.name, "wps_pushbutton") == 0){
807 set_wps_pushbutton(&intf_param, op->v.string);
808 }else if (strcmp(op->e.name, "macfilter") == 0){
809 set_macfilter(&intf_param, op->v.string);
810 }else if (strcmp(op->e.name, "maclist") == 0){
811 set_maclist(&intf_param, op->v.string);
developer8d8d6302022-10-18 16:36:37 +0800812 }else{
developer91f80742022-10-04 15:20:18 +0800813 fprintf(stderr, "[%s %s not set!]\n", op->e.name, op->v.string);
developera3ec58b2023-02-28 15:59:38 +0800814 }
developer91f80742022-10-04 15:20:18 +0800815 }
816 }
developerd9bf1dd2023-02-22 15:49:20 +0800817 if (parsing_radio == TRUE) {
818 char cmd[32] = {0};
819 char buf[32] = {0};
developer91f80742022-10-04 15:20:18 +0800820 set_radio_param(radio_param);
developerd9bf1dd2023-02-22 15:49:20 +0800821
822 /* sleep 3 to wait ifconfig up state update, workaround to avoid
823 disable ap interface fail. */
824 sprintf(cmd, "sleep 5");
825 _syscmd(cmd, buf, sizeof(buf));
826 }
developer465ca0c2022-11-25 14:30:05 +0800827 else if (intf_param.sta_mode == TRUE)
828 set_sta_param(intf_param);
developerd9bf1dd2023-02-22 15:49:20 +0800829 else {
developer465ca0c2022-11-25 14:30:05 +0800830 set_ap_param(intf_param, &vap_map[intf_param.radio_index]);
developerd9bf1dd2023-02-22 15:49:20 +0800831 vap_map[intf_param.radio_index].num_vaps++;
832 }
developer91f80742022-10-04 15:20:18 +0800833 }
developerd9bf1dd2023-02-22 15:49:20 +0800834
835 /* disable all interface, re-enable by UCI configuration */
836
837 fprintf(stderr, "\n----- Disable all interfaces. -----\n");
838
839 for (i = 0; i < max_radio_num; i++ ){
840 for(j = MAX_NUM_VAP_PER_RADIO - 1; j >= 0 ; j--) {
841 ret = wifi_setApEnable(i*max_radio_num+j, FALSE);
842 if (ret != RETURN_OK)
843 fprintf(stderr, "[disable ap %d failed!!!]\n", i*max_radio_num+j);
844 }
845 }
developer50614832022-11-17 20:42:05 +0800846 fprintf(stderr, "\n----- Start setting Vaps. -----\n");
developer91f80742022-10-04 15:20:18 +0800847
developerd9bf1dd2023-02-22 15:49:20 +0800848 for (i = 0; i < max_radio_num ;i++ ){
849
850 fprintf(stderr, "\n create Vap radio:%d num_vaps=%d.\n", i, vap_map[i].num_vaps);
developerff42a302022-10-19 17:40:23 +0800851 ret = wifi_createVAP(i, &vap_map[i]);
852 if (ret != RETURN_OK)
853 fprintf(stderr, "[Apply vap setting failed!!!]\n");
854 }
developera3ec58b2023-02-28 15:59:38 +0800855
developer91f80742022-10-04 15:20:18 +0800856 uci_unload(uci_ctx, uci_pkg);
857 uci_free_context(uci_ctx);
858 return RETURN_OK;
859}
860
developera3ec58b2023-02-28 15:59:38 +0800861int dump_wifi_status ()
862{
863
864 struct uci_context *uci_ctx = uci_alloc_context();
865 struct uci_package *uci_pkg = NULL;
866 struct uci_element *e;
867 // struct uci_section *s;
868 const char cfg_name[] = "wireless";
869 int max_radio_num = 0;
870 BOOL parsing_radio = FALSE;
871 int apCount[3] = {0};
872 int staCount[3] = {0};
873 wifi_vap_info_map_t vap_map[3] = {0};
874 int ret = 0;
875 int i = 0;
876
877 wifi_getMaxRadioNumber(&max_radio_num);
878 fprintf(stderr, "max radio number: %d\n", max_radio_num);
879 for (i = 0; i < max_radio_num ;i++ ){
880 ret = wifi_getRadioVapInfoMap(i, &vap_map[i]);
881 if (ret != RETURN_OK) { // if failed, we set assume this vap as the first vap.
882 fprintf(stderr, "[Get vap map failed!!!]\n");
883 vap_map[i].num_vaps = MAX_NUM_VAP_PER_RADIO;
884 }
885 }
886 if (uci_load(uci_ctx, cfg_name, &uci_pkg) != UCI_OK) {
887 uci_free_context(uci_ctx);
888 fprintf(stderr, "%s: load uci failed.\n", __func__);
889 return RETURN_ERR;
890 }
891
892 uci_foreach_element(&uci_pkg->sections, e) {
893
894 struct uci_section *s = uci_to_section(e);
895 struct uci_element *option = NULL;
896 wifi_radio_param radio_param = {0};
897 wifi_intf_param intf_param = {0};
898 int phyId = 0;
899 radio_param.radio_index = -1;
900 intf_param.ap_index = -1;
901
902 if (strcmp(s->type, "wifi-device") == 0) {
903 sscanf(s->e.name, "radio%d", &phyId);
904 radio_param.radio_index = phy_index_to_radio(phyId);
905 parsing_radio = TRUE;
906 fprintf(stderr, "\n----- Start show radio %d config. -----\n", radio_param.radio_index);
907 } else if (strcmp(s->type, "wifi-iface") == 0) {
908 parsing_radio = FALSE;
909 }
910
911 uci_foreach_element(&s->options, option) {
912
913 struct uci_option *op = uci_to_option(option);
914 if (parsing_radio == TRUE) {
915 // transform the type from input string and store the value in radio_param.
916 } else {
917 // parsing iface
918 if (strcmp(op->e.name, "device") == 0){
919 set_radionum(&intf_param, op->v.string);
920 }else if (strcmp(op->e.name, "mode") == 0){
921 intf_param.mac_offset = staCount[intf_param.radio_index] + apCount[intf_param.radio_index];
922 if (strncmp(op->v.string, "sta", 3) == 0) {
923 intf_param.sta_mode = TRUE;
924 intf_param.sta_index = intf_param.radio_index + staCount[intf_param.radio_index]*max_radio_num;
925 staCount[intf_param.radio_index] ++ ;
926 fprintf(stderr, "\n----- Start show sta %d config. -----\n", intf_param.sta_index);
927 } else if (strncmp(op->v.string, "ap", 2) == 0) {
928 intf_param.sta_mode = FALSE;
929 intf_param.ap_index = intf_param.radio_index + apCount[intf_param.radio_index]*max_radio_num;
930 apCount[intf_param.radio_index] ++ ;
931 fprintf(stderr, "\n----- Start show ap %d config. -----\n", intf_param.ap_index);
932 }
933 }
934 }
935 }
936 if (parsing_radio == TRUE)
937 printf("show radio params: \n");
938 // show_radio_param(radio_param);
939 else if (intf_param.sta_mode == TRUE)
940 printf("show sta params: \n");
941 // show_sta_param(intf_param);
942 else{
943 printf("show ap params: \n");
944 show_ap_param(intf_param, &vap_map[intf_param.radio_index]);
945 }
946 }
947
948 uci_unload(uci_ctx, uci_pkg);
949 uci_free_context(uci_ctx);
950 return RETURN_OK;
951
952}
953
developer91f80742022-10-04 15:20:18 +0800954int main(int argc, char **argv)
955{
developera3ec58b2023-02-28 15:59:38 +0800956 if (argc != 2 || (strcmp(argv[1], "reload") != 0 && strcmp(argv[1], "dump") != 0) ){
957 fprintf(stderr, "Usage: wifi reload/wifi dump.\nThis tool is only for RDKB MSP/SQC test.\n");
developer91f80742022-10-04 15:20:18 +0800958 return -1;
959 }
developera3ec58b2023-02-28 15:59:38 +0800960 if (strcmp(argv[1], "reload") == 0)
961 apply_uci_config();
962 else if (strcmp(argv[1], "dump") == 0)
963 dump_wifi_status();
developer91f80742022-10-04 15:20:18 +0800964 return 0;
965}