developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 1 | #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 | |
developer | 9567a46 | 2022-11-17 20:42:05 +0800 | [diff] [blame] | 8 | static 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 | |
| 14 | static 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 | } |
developer | 4c2edbe | 2022-10-18 16:36:37 +0800 | [diff] [blame] | 19 | |
| 20 | static 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 | |
| 56 | int 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); |
developer | f634eab | 2023-01-13 15:23:06 +0800 | [diff] [blame] | 69 | return radioIndex; |
developer | 4c2edbe | 2022-10-18 16:36:37 +0800 | [diff] [blame] | 70 | } |
| 71 | |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 72 | void set_channel(wifi_radio_param *radio_param, char *channel) |
| 73 | { |
developer | ab98580 | 2022-10-07 09:42:31 +0800 | [diff] [blame] | 74 | if (strcmp(channel, "auto") == 0) { |
| 75 | radio_param->auto_channel = TRUE; |
| 76 | radio_param->channel = 0; |
| 77 | } else { |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 78 | radio_param->auto_channel = FALSE; |
developer | ab98580 | 2022-10-07 09:42:31 +0800 | [diff] [blame] | 79 | radio_param->channel = strtol(channel, NULL, 10); |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 80 | } |
developer | ab98580 | 2022-10-07 09:42:31 +0800 | [diff] [blame] | 81 | return; |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 82 | } |
| 83 | |
developer | 02a4a1b | 2022-10-06 17:16:43 +0800 | [diff] [blame] | 84 | void set_country(wifi_radio_param *radio_param, char *country) |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 85 | { |
| 86 | strcpy(radio_param->country, country); |
| 87 | } |
| 88 | |
developer | 02a4a1b | 2022-10-06 17:16:43 +0800 | [diff] [blame] | 89 | void set_band(wifi_radio_param *radio_param, char *band) |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 90 | { |
| 91 | strcpy(radio_param->band, band); |
| 92 | } |
| 93 | |
developer | 54afa2c | 2022-10-18 17:44:13 +0800 | [diff] [blame] | 94 | void 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 | |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 100 | void 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 | |
| 110 | void 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 | |
| 150 | void 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 | |
developer | 1e946fd | 2022-12-26 17:09:00 +0800 | [diff] [blame] | 158 | void set_rxant(wifi_radio_param *radio_param, char *mask) |
| 159 | { |
| 160 | radio_param->rxantenna = strtol(mask, NULL, 16); |
| 161 | } |
| 162 | |
| 163 | void set_txant(wifi_radio_param *radio_param, char *mask) |
| 164 | { |
| 165 | radio_param->txantenna = strtol(mask, NULL, 16); |
| 166 | } |
| 167 | |
developer | 223f598 | 2023-02-28 15:59:38 +0800 | [diff] [blame^] | 168 | void 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 | |
| 176 | void 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 | |
| 184 | void 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 | |
| 192 | void 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 | |
| 201 | void set_macfilter(wifi_intf_param *intf_param, char *macfilter) |
| 202 | { |
| 203 | strncpy(intf_param->macfilter, macfilter, 10); |
| 204 | } |
| 205 | |
| 206 | void set_maclist(wifi_intf_param *intf_param, char *maclist) |
| 207 | { |
| 208 | strncpy(intf_param->maclist, maclist, 512); |
| 209 | } |
| 210 | |
developer | c454873 | 2023-02-06 20:02:10 +0800 | [diff] [blame] | 211 | void set_htcoex(wifi_radio_param *radio_param, char *ht_coex) |
| 212 | { |
| 213 | radio_param->ht_coex = strtol(ht_coex, NULL, 10); |
| 214 | } |
| 215 | |
| 216 | void set_rts(wifi_radio_param *radio_param, char *rts) |
| 217 | { |
| 218 | radio_param->rtsThreshold = strtol(rts, NULL, 10); |
| 219 | } |
| 220 | |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 221 | void set_radionum(wifi_intf_param *intf_param, char *phy_name) |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 222 | { |
developer | 9567a46 | 2022-11-17 20:42:05 +0800 | [diff] [blame] | 223 | int radio_num = 0; |
| 224 | char *ptr = phy_name; |
developer | 4c2edbe | 2022-10-18 16:36:37 +0800 | [diff] [blame] | 225 | int phyId = 0; |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 226 | |
| 227 | while (*ptr) { |
| 228 | if (isdigit(*ptr)) { |
developer | 9567a46 | 2022-11-17 20:42:05 +0800 | [diff] [blame] | 229 | phyId = strtoul(ptr, NULL, 10); |
| 230 | radio_num = phy_index_to_radio(phyId); |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 231 | intf_param->radio_index = radio_num; |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 232 | break; |
| 233 | } |
| 234 | ptr++; |
| 235 | } |
| 236 | } |
| 237 | |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 238 | void set_ssid(wifi_intf_param *intf_param, char *ssid) |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 239 | { |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 240 | strncpy(intf_param->ssid, ssid, 32); |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 241 | } |
| 242 | |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 243 | void set_encryption(wifi_intf_param *intf_param, char *encryption_mode) |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 244 | { |
developer | 3ddad2f | 2022-10-13 13:33:57 +0800 | [diff] [blame] | 245 | if (strcmp(encryption_mode, "none") == 0) { |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 246 | intf_param->security.mode = wifi_security_mode_none; |
| 247 | intf_param->security.encr = wifi_encryption_none; |
developer | 3ddad2f | 2022-10-13 13:33:57 +0800 | [diff] [blame] | 248 | }else if(strncmp(encryption_mode, "psk2", 4) == 0){ |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 249 | intf_param->security.mode = wifi_security_mode_wpa2_personal; |
developer | 3ddad2f | 2022-10-13 13:33:57 +0800 | [diff] [blame] | 250 | }else if(strncmp(encryption_mode, "psk-",4) == 0){ |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 251 | intf_param->security.mode = wifi_security_mode_wpa_wpa2_personal; |
developer | 3ddad2f | 2022-10-13 13:33:57 +0800 | [diff] [blame] | 252 | }else if(strncmp(encryption_mode, "psk",3) == 0){ |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 253 | intf_param->security.mode = wifi_security_mode_wpa_personal; |
developer | 3ddad2f | 2022-10-13 13:33:57 +0800 | [diff] [blame] | 254 | }else if(strncmp(encryption_mode, "wpa2",4) == 0){ |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 255 | intf_param->security.mode = wifi_security_mode_wpa2_enterprise; |
developer | 3ddad2f | 2022-10-13 13:33:57 +0800 | [diff] [blame] | 256 | }else if(strncmp(encryption_mode, "wpa-",4) == 0){ |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 257 | intf_param->security.mode = wifi_security_mode_wpa_wpa2_enterprise; |
developer | 3ddad2f | 2022-10-13 13:33:57 +0800 | [diff] [blame] | 258 | }else if(strcmp(encryption_mode, "sae") == 0){ |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 259 | intf_param->security.mode = wifi_security_mode_wpa3_personal; |
developer | 3ddad2f | 2022-10-13 13:33:57 +0800 | [diff] [blame] | 260 | }else if(strcmp(encryption_mode, "wpa3") == 0){ |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 261 | intf_param->security.mode = wifi_security_mode_wpa3_enterprise; |
developer | 3ddad2f | 2022-10-13 13:33:57 +0800 | [diff] [blame] | 262 | }else if(strcmp(encryption_mode, "sae-mixed") == 0){ |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 263 | intf_param->security.mode = wifi_security_mode_wpa3_transition; |
developer | f634eab | 2023-01-13 15:23:06 +0800 | [diff] [blame] | 264 | }else if(strcmp(encryption_mode, "owe") == 0){ |
| 265 | intf_param->security.mode = wifi_security_mode_owe; |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 266 | } |
| 267 | |
developer | 3ddad2f | 2022-10-13 13:33:57 +0800 | [diff] [blame] | 268 | if(strstr(encryption_mode, "tkip") && (strstr(encryption_mode, "ccmp") || strstr(encryption_mode, "aes") )){ |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 269 | intf_param->security.encr = wifi_encryption_aes_tkip; |
developer | 3ddad2f | 2022-10-13 13:33:57 +0800 | [diff] [blame] | 270 | }else if (strstr(encryption_mode, "tkip")){ |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 271 | intf_param->security.encr = wifi_encryption_tkip; |
developer | 3ddad2f | 2022-10-13 13:33:57 +0800 | [diff] [blame] | 272 | }else{ |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 273 | intf_param->security.encr = wifi_encryption_aes; |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 274 | } |
developer | 3ddad2f | 2022-10-13 13:33:57 +0800 | [diff] [blame] | 275 | |
developer | f634eab | 2023-01-13 15:23:06 +0800 | [diff] [blame] | 276 | if(!strcmp(encryption_mode, "wpa3") || !strcmp(encryption_mode, "sae") || !strcmp(encryption_mode, "owe")){ |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 277 | intf_param->security.mfp = wifi_mfp_cfg_required; |
developer | 3ddad2f | 2022-10-13 13:33:57 +0800 | [diff] [blame] | 278 | }else if (!strcmp(encryption_mode, "sae-mixed")){ |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 279 | intf_param->security.mfp = wifi_mfp_cfg_optional; |
developer | 3ddad2f | 2022-10-13 13:33:57 +0800 | [diff] [blame] | 280 | }else{ |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 281 | intf_param->security.mfp = wifi_mfp_cfg_disabled; |
developer | 3ddad2f | 2022-10-13 13:33:57 +0800 | [diff] [blame] | 282 | } |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 283 | } |
| 284 | |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 285 | void set_key(wifi_intf_param *intf_param, char *key) |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 286 | { |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 287 | strncpy(intf_param->security.u.key.key, key, 64); |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 288 | } |
| 289 | |
developer | 2bcdef9 | 2022-12-13 16:19:09 +0800 | [diff] [blame] | 290 | void 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 | |
developer | b3f0066 | 2022-12-29 09:35:55 +0800 | [diff] [blame] | 297 | void 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 | |
developer | c454873 | 2023-02-06 20:02:10 +0800 | [diff] [blame] | 304 | void set_hidden(wifi_intf_param *intf_param, char *hidden) |
| 305 | { |
| 306 | intf_param->hidden = strtol(hidden, NULL, 10); |
| 307 | } |
| 308 | |
developer | 9567a46 | 2022-11-17 20:42:05 +0800 | [diff] [blame] | 309 | int set_interface_bssid(int phy_index, int offset, mac_address_t *bssid) |
developer | f9b2ef0 | 2022-10-14 10:07:58 +0800 | [diff] [blame] | 310 | { |
| 311 | FILE *f; |
| 312 | char mac_file[64] = {0}; |
| 313 | char mac_address[20] = {0}; |
developer | f9b2ef0 | 2022-10-14 10:07:58 +0800 | [diff] [blame] | 314 | |
developer | b97b549 | 2022-12-22 19:44:36 +0800 | [diff] [blame] | 315 | sprintf(mac_file, "/sys/class/ieee80211/phy%d/macaddress", phy_index); |
developer | f9b2ef0 | 2022-10-14 10:07:58 +0800 | [diff] [blame] | 316 | f = fopen(mac_file, "r"); |
| 317 | if (f == NULL) |
| 318 | return -1; |
| 319 | fgets(mac_address, 20, f); |
| 320 | fclose(f); |
| 321 | |
developer | 9567a46 | 2022-11-17 20:42:05 +0800 | [diff] [blame] | 322 | mac_addr_aton(&(*bssid)[0], mac_address); |
| 323 | (*bssid)[0] += offset*2; |
developer | f9b2ef0 | 2022-10-14 10:07:58 +0800 | [diff] [blame] | 324 | return 0; |
| 325 | } |
| 326 | |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 327 | void set_radio_param(wifi_radio_param radio_parameter) |
| 328 | { |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 329 | int ret = 0; |
developer | ab98580 | 2022-10-07 09:42:31 +0800 | [diff] [blame] | 330 | wifi_radio_operationParam_t operationParam = {0}; |
| 331 | |
developer | 4c2edbe | 2022-10-18 16:36:37 +0800 | [diff] [blame] | 332 | if(radio_parameter.radio_index == -1) |
| 333 | return; |
| 334 | |
developer | ab98580 | 2022-10-07 09:42:31 +0800 | [diff] [blame] | 335 | if (radio_parameter.disabled == TRUE) { |
| 336 | wifi_setRadioEnable(radio_parameter.radio_index, FALSE); |
| 337 | return; |
| 338 | } |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 339 | |
| 340 | fprintf(stderr, "Start setting radio\n"); |
developer | 1861581 | 2022-10-17 17:37:29 +0800 | [diff] [blame] | 341 | |
developer | 1e946fd | 2022-12-26 17:09:00 +0800 | [diff] [blame] | 342 | 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 | |
developer | 1861581 | 2022-10-17 17:37:29 +0800 | [diff] [blame] | 348 | // Get current radio setting |
developer | ab98580 | 2022-10-07 09:42:31 +0800 | [diff] [blame] | 349 | ret = wifi_getRadioOperatingParameters(radio_parameter.radio_index, &operationParam); |
| 350 | if (ret != RETURN_OK) |
| 351 | fprintf(stderr, "[Get OperatingParameters failed!!!]\n"); |
developer | 1861581 | 2022-10-17 17:37:29 +0800 | [diff] [blame] | 352 | operationParam.enable = TRUE; |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 353 | |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 354 | // Channel |
developer | ab98580 | 2022-10-07 09:42:31 +0800 | [diff] [blame] | 355 | operationParam.autoChannelEnabled = radio_parameter.auto_channel; |
| 356 | operationParam.channel = radio_parameter.channel; |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 357 | |
developer | ae3f841 | 2022-10-13 15:27:02 +0800 | [diff] [blame] | 358 | //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 | } |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 368 | |
| 369 | // htmode |
developer | ab98580 | 2022-10-07 09:42:31 +0800 | [diff] [blame] | 370 | unsigned int mode = 0; // enum wifi_ieee80211Variant_t |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 371 | if (strcmp(radio_parameter.band, "2g") == 0) { |
developer | ab98580 | 2022-10-07 09:42:31 +0800 | [diff] [blame] | 372 | mode |= WIFI_80211_VARIANT_B | WIFI_80211_VARIANT_G; |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 373 | if (strcmp(radio_parameter.htmode, "NOHT") == 0 || strcmp(radio_parameter.htmode, "NONE") == 0) |
| 374 | strcpy(radio_parameter.htmode, "11G"); |
| 375 | |
developer | ab98580 | 2022-10-07 09:42:31 +0800 | [diff] [blame] | 376 | if (strstr(radio_parameter.htmode, "HE") != NULL) |
| 377 | mode |= WIFI_80211_VARIANT_N | WIFI_80211_VARIANT_AX; |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 378 | |
developer | ab98580 | 2022-10-07 09:42:31 +0800 | [diff] [blame] | 379 | } else if (strcmp(radio_parameter.band, "5g") == 0) { |
| 380 | mode |= WIFI_80211_VARIANT_A; |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 381 | if (strcmp(radio_parameter.htmode, "NOHT") == 0 || strcmp(radio_parameter.htmode, "NONE") == 0) |
| 382 | strcpy(radio_parameter.htmode, "11A"); |
developer | ab98580 | 2022-10-07 09:42:31 +0800 | [diff] [blame] | 383 | |
| 384 | if (strstr(radio_parameter.htmode, "HE") != NULL) |
| 385 | mode |= WIFI_80211_VARIANT_N | WIFI_80211_VARIANT_AC | WIFI_80211_VARIANT_AX; |
developer | 4c2edbe | 2022-10-18 16:36:37 +0800 | [diff] [blame] | 386 | }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 | } |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 389 | |
| 390 | if (strstr(radio_parameter.htmode, "VHT") != NULL) |
developer | ab98580 | 2022-10-07 09:42:31 +0800 | [diff] [blame] | 391 | mode |= WIFI_80211_VARIANT_N | WIFI_80211_VARIANT_AC; |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 392 | else if (strstr(radio_parameter.htmode, "HT") != NULL && strstr(radio_parameter.htmode, "NO") == NULL) |
developer | ab98580 | 2022-10-07 09:42:31 +0800 | [diff] [blame] | 393 | mode |= WIFI_80211_VARIANT_N; |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 394 | |
developer | ab98580 | 2022-10-07 09:42:31 +0800 | [diff] [blame] | 395 | operationParam.variant = mode; |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 396 | |
developer | c454873 | 2023-02-06 20:02:10 +0800 | [diff] [blame] | 397 | // 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 | |
developer | ab98580 | 2022-10-07 09:42:31 +0800 | [diff] [blame] | 404 | // apply setting |
| 405 | ret = wifi_setRadioOperatingParameters(radio_parameter.radio_index, &operationParam); |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 406 | if (ret != RETURN_OK) |
developer | ab98580 | 2022-10-07 09:42:31 +0800 | [diff] [blame] | 407 | fprintf(stderr, "[Apply setting failed!!!]\n"); |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 408 | |
developer | b7f28c4 | 2022-11-07 16:58:17 +0800 | [diff] [blame] | 409 | // 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 | |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 432 | } |
| 433 | |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 434 | void set_ap_param(wifi_intf_param ap_param , wifi_vap_info_map_t *map) |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 435 | { |
| 436 | int ret = 0; |
developer | ab98580 | 2022-10-07 09:42:31 +0800 | [diff] [blame] | 437 | int vap_index_in_map = 0; |
developer | 9567a46 | 2022-11-17 20:42:05 +0800 | [diff] [blame] | 438 | int phy_index = 0; |
developer | 9feeaf1 | 2023-02-17 15:52:18 +0800 | [diff] [blame] | 439 | int key_len = 0; |
developer | ab98580 | 2022-10-07 09:42:31 +0800 | [diff] [blame] | 440 | wifi_vap_info_t vap_info = {0}; |
developer | 1861581 | 2022-10-17 17:37:29 +0800 | [diff] [blame] | 441 | BOOL radio_enable = FALSE; |
| 442 | |
developer | 41965b5 | 2022-10-19 17:40:23 +0800 | [diff] [blame] | 443 | if(ap_param.radio_index == -1) |
| 444 | return; |
| 445 | |
developer | 1861581 | 2022-10-17 17:37:29 +0800 | [diff] [blame] | 446 | wifi_getRadioEnable(ap_param.radio_index, &radio_enable); |
| 447 | if (radio_enable == FALSE) |
| 448 | return; |
developer | ab98580 | 2022-10-07 09:42:31 +0800 | [diff] [blame] | 449 | |
developer | 41965b5 | 2022-10-19 17:40:23 +0800 | [diff] [blame] | 450 | |
| 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; |
developer | ab98580 | 2022-10-07 09:42:31 +0800 | [diff] [blame] | 456 | } |
| 457 | } |
| 458 | |
developer | 41965b5 | 2022-10-19 17:40:23 +0800 | [diff] [blame] | 459 | |
developer | f9b2ef0 | 2022-10-14 10:07:58 +0800 | [diff] [blame] | 460 | fprintf(stderr, "Start setting ap\n"); |
| 461 | |
developer | 41965b5 | 2022-10-19 17:40:23 +0800 | [diff] [blame] | 462 | vap_info = map->vap_array[vap_index_in_map]; |
developer | f9b2ef0 | 2022-10-14 10:07:58 +0800 | [diff] [blame] | 463 | vap_info.u.bss_info.enabled = TRUE; |
developer | 9567a46 | 2022-11-17 20:42:05 +0800 | [diff] [blame] | 464 | 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) { |
developer | f9b2ef0 | 2022-10-14 10:07:58 +0800 | [diff] [blame] | 466 | fprintf(stderr, "Get mac address failed.\n"); |
developer | 9567a46 | 2022-11-17 20:42:05 +0800 | [diff] [blame] | 467 | return; |
developer | f9b2ef0 | 2022-10-14 10:07:58 +0800 | [diff] [blame] | 468 | } |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 469 | |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 470 | // SSID |
developer | ab98580 | 2022-10-07 09:42:31 +0800 | [diff] [blame] | 471 | strncpy(vap_info.u.bss_info.ssid, ap_param.ssid, 33); |
| 472 | vap_info.u.bss_info.ssid[32] = '\0'; |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 473 | |
developer | 2bcdef9 | 2022-12-13 16:19:09 +0800 | [diff] [blame] | 474 | // 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 | |
developer | 9feeaf1 | 2023-02-17 15:52:18 +0800 | [diff] [blame] | 480 | // 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 | |
developer | 3ddad2f | 2022-10-13 13:33:57 +0800 | [diff] [blame] | 492 | 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); |
developer | c454873 | 2023-02-06 20:02:10 +0800 | [diff] [blame] | 497 | |
| 498 | // hidden |
| 499 | vap_info.u.bss_info.showSsid = (ap_param.hidden ? 0 : 1); |
developer | 4c2edbe | 2022-10-18 16:36:37 +0800 | [diff] [blame] | 500 | |
developer | 223f598 | 2023-02-28 15:59:38 +0800 | [diff] [blame^] | 501 | // 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; |
developer | ab98580 | 2022-10-07 09:42:31 +0800 | [diff] [blame] | 561 | // Replace the setting with uci config |
developer | 41965b5 | 2022-10-19 17:40:23 +0800 | [diff] [blame] | 562 | map->vap_array[vap_index_in_map] = vap_info; |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 563 | } |
| 564 | |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 565 | void set_sta_param(wifi_intf_param sta_param) |
developer | 9567a46 | 2022-11-17 20:42:05 +0800 | [diff] [blame] | 566 | { |
| 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"); |
developer | f634eab | 2023-01-13 15:23:06 +0800 | [diff] [blame] | 587 | else if (sta_param.security.mode == wifi_security_mode_owe) |
| 588 | strcpy(key_mgmt, "OWE"); |
developer | 9567a46 | 2022-11-17 20:42:05 +0800 | [diff] [blame] | 589 | 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 | |
developer | b3f0066 | 2022-12-29 09:35:55 +0800 | [diff] [blame] | 606 | 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); |
developer | 9567a46 | 2022-11-17 20:42:05 +0800 | [diff] [blame] | 610 | |
| 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 | |
developer | 223f598 | 2023-02-28 15:59:38 +0800 | [diff] [blame^] | 624 | void 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 | |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 691 | int 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; |
developer | 4c2edbe | 2022-10-18 16:36:37 +0800 | [diff] [blame] | 700 | int apCount[3] = {0}; |
developer | 9567a46 | 2022-11-17 20:42:05 +0800 | [diff] [blame] | 701 | int staCount[3] = {0}; |
developer | 41965b5 | 2022-10-19 17:40:23 +0800 | [diff] [blame] | 702 | wifi_vap_info_map_t vap_map[3] = {0}; |
| 703 | int ret = 0; |
| 704 | int i = 0; |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 705 | |
| 706 | wifi_getMaxRadioNumber(&max_radio_num); |
| 707 | fprintf(stderr, "max radio number: %d\n", max_radio_num); |
developer | 41965b5 | 2022-10-19 17:40:23 +0800 | [diff] [blame] | 708 | 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 | } |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 715 | 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}; |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 726 | wifi_intf_param intf_param = {0}; |
developer | 4c2edbe | 2022-10-18 16:36:37 +0800 | [diff] [blame] | 727 | int phyId = 0; |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 728 | radio_param.radio_index = -1; |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 729 | intf_param.ap_index = -1; |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 730 | |
| 731 | if (strcmp(s->type, "wifi-device") == 0) { |
developer | 4c2edbe | 2022-10-18 16:36:37 +0800 | [diff] [blame] | 732 | sscanf(s->e.name, "radio%d", &phyId); |
| 733 | radio_param.radio_index = phy_index_to_radio(phyId); |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 734 | 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) { |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 737 | parsing_radio = FALSE; |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 738 | } |
| 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) |
developer | 54afa2c | 2022-10-18 17:44:13 +0800 | [diff] [blame] | 758 | set_noscan(&radio_param, op->v.string); |
developer | 1e946fd | 2022-12-26 17:09:00 +0800 | [diff] [blame] | 759 | 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); |
developer | c454873 | 2023-02-06 20:02:10 +0800 | [diff] [blame] | 763 | 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); |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 767 | else |
| 768 | fprintf(stderr, "[%s %s not set!]\n", op->e.name, op->v.string); |
| 769 | } else { |
| 770 | // parsing iface |
developer | 4c2edbe | 2022-10-18 16:36:37 +0800 | [diff] [blame] | 771 | if (strcmp(op->e.name, "device") == 0){ |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 772 | set_radionum(&intf_param, op->v.string); |
developer | 9567a46 | 2022-11-17 20:42:05 +0800 | [diff] [blame] | 773 | }else if (strcmp(op->e.name, "mode") == 0){ |
developer | b97b549 | 2022-12-22 19:44:36 +0800 | [diff] [blame] | 774 | intf_param.mac_offset = staCount[intf_param.radio_index] + apCount[intf_param.radio_index]; |
developer | 9567a46 | 2022-11-17 20:42:05 +0800 | [diff] [blame] | 775 | if (strncmp(op->v.string, "sta", 3) == 0) { |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 776 | 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); |
developer | 9567a46 | 2022-11-17 20:42:05 +0800 | [diff] [blame] | 780 | } else if (strncmp(op->v.string, "ap", 2) == 0) { |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 781 | 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); |
developer | 9567a46 | 2022-11-17 20:42:05 +0800 | [diff] [blame] | 785 | } |
developer | 4c2edbe | 2022-10-18 16:36:37 +0800 | [diff] [blame] | 786 | }else if (strcmp(op->e.name, "ssid") == 0){ |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 787 | set_ssid(&intf_param, op->v.string); |
developer | 4c2edbe | 2022-10-18 16:36:37 +0800 | [diff] [blame] | 788 | }else if (strcmp(op->e.name, "encryption") == 0){ |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 789 | set_encryption(&intf_param, op->v.string); |
developer | 4c2edbe | 2022-10-18 16:36:37 +0800 | [diff] [blame] | 790 | }else if (strcmp(op->e.name, "key") == 0){ |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 791 | set_key(&intf_param, op->v.string); |
developer | 2bcdef9 | 2022-12-13 16:19:09 +0800 | [diff] [blame] | 792 | }else if (strcmp(op->e.name, "ifname") == 0){ |
| 793 | set_ifname(&intf_param, op->v.string); |
developer | b3f0066 | 2022-12-29 09:35:55 +0800 | [diff] [blame] | 794 | }else if (strcmp(op->e.name, "wds") == 0){ |
| 795 | set_wds(&intf_param, op->v.string); |
developer | c454873 | 2023-02-06 20:02:10 +0800 | [diff] [blame] | 796 | }else if (strcmp(op->e.name, "hidden") == 0){ |
| 797 | set_hidden(&intf_param, op->v.string); |
developer | 223f598 | 2023-02-28 15:59:38 +0800 | [diff] [blame^] | 798 | }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); |
developer | 4c2edbe | 2022-10-18 16:36:37 +0800 | [diff] [blame] | 810 | }else{ |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 811 | fprintf(stderr, "[%s %s not set!]\n", op->e.name, op->v.string); |
developer | 223f598 | 2023-02-28 15:59:38 +0800 | [diff] [blame^] | 812 | } |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 813 | } |
| 814 | } |
| 815 | if (parsing_radio == TRUE) |
| 816 | set_radio_param(radio_param); |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 817 | else if (intf_param.sta_mode == TRUE) |
| 818 | set_sta_param(intf_param); |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 819 | else |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 820 | set_ap_param(intf_param, &vap_map[intf_param.radio_index]); |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 821 | } |
developer | 9567a46 | 2022-11-17 20:42:05 +0800 | [diff] [blame] | 822 | fprintf(stderr, "\n----- Start setting Vaps. -----\n"); |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 823 | |
developer | 41965b5 | 2022-10-19 17:40:23 +0800 | [diff] [blame] | 824 | 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 | } |
developer | 223f598 | 2023-02-28 15:59:38 +0800 | [diff] [blame^] | 829 | |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 830 | uci_unload(uci_ctx, uci_pkg); |
| 831 | uci_free_context(uci_ctx); |
| 832 | return RETURN_OK; |
| 833 | } |
| 834 | |
developer | 223f598 | 2023-02-28 15:59:38 +0800 | [diff] [blame^] | 835 | int 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 | |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 928 | int main(int argc, char **argv) |
| 929 | { |
developer | 223f598 | 2023-02-28 15:59:38 +0800 | [diff] [blame^] | 930 | 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"); |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 932 | return -1; |
| 933 | } |
developer | 223f598 | 2023-02-28 15:59:38 +0800 | [diff] [blame^] | 934 | if (strcmp(argv[1], "reload") == 0) |
| 935 | apply_uci_config(); |
| 936 | else if (strcmp(argv[1], "dump") == 0) |
| 937 | dump_wifi_status(); |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 938 | return 0; |
| 939 | } |