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 |
developer | 02cc929 | 2023-02-24 18:01:27 +0800 | [diff] [blame] | 128 | // EHT320-1 -> 11BEEHT320-1 |
| 129 | if (strstr(htmode, "40+") != NULL) { |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 130 | strncpy(tmp, htmode, strlen(htmode) - 1); |
| 131 | strcat(tmp, "PLUS"); |
developer | 02cc929 | 2023-02-24 18:01:27 +0800 | [diff] [blame] | 132 | } else if (strstr(htmode, "40-") != NULL) { |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 133 | strncpy(tmp, htmode, strlen(htmode) - 1); |
| 134 | strcat(tmp, "MINUS"); |
| 135 | } else |
| 136 | strcpy(tmp, htmode); |
| 137 | |
| 138 | |
| 139 | if (strstr(htmode, "VHT") != NULL) { |
| 140 | snprintf(radio_param->htmode, sizeof(radio_param->htmode), "11AC%s", tmp); |
developer | 02cc929 | 2023-02-24 18:01:27 +0800 | [diff] [blame] | 141 | } else if (strstr(htmode, "EHT") != NULL) { |
| 142 | snprintf(radio_param->htmode, sizeof(radio_param->htmode), "11BE%s", tmp); |
| 143 | if (strstr(htmode, "320-1") != NULL) |
| 144 | radio_param->eht_320_conf = 1; |
| 145 | else if (strstr(htmode, "320") != NULL) // EHT320 or EHT320-2 |
| 146 | radio_param->eht_320_conf = 2; |
| 147 | else |
| 148 | radio_param->eht_320_conf = 0; |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 149 | } else if (strstr(htmode, "HT") != NULL && strstr(htmode, "NO") == NULL) { |
| 150 | snprintf(radio_param->htmode, sizeof(radio_param->htmode), "11NG%s", tmp); |
| 151 | } else if (strstr(htmode, "HE") != NULL) { |
| 152 | snprintf(radio_param->htmode, sizeof(radio_param->htmode), "11AX%s", tmp); |
| 153 | } else { // NOHT or NONE should be parsed with the band, so just fill the original string. |
| 154 | strcpy(radio_param->htmode, tmp); |
| 155 | } |
| 156 | |
| 157 | } |
| 158 | |
| 159 | void set_disable(wifi_radio_param *radio_param, char *disable) |
| 160 | { |
| 161 | if (strcmp(disable, "1") == 0) |
| 162 | radio_param->disabled = TRUE; |
| 163 | else |
| 164 | radio_param->disabled = FALSE; |
| 165 | } |
| 166 | |
developer | 1e946fd | 2022-12-26 17:09:00 +0800 | [diff] [blame] | 167 | void set_rxant(wifi_radio_param *radio_param, char *mask) |
| 168 | { |
| 169 | radio_param->rxantenna = strtol(mask, NULL, 16); |
| 170 | } |
| 171 | |
| 172 | void set_txant(wifi_radio_param *radio_param, char *mask) |
| 173 | { |
| 174 | radio_param->txantenna = strtol(mask, NULL, 16); |
| 175 | } |
| 176 | |
developer | 223f598 | 2023-02-28 15:59:38 +0800 | [diff] [blame] | 177 | void set_igmpsn_enable(wifi_intf_param *intf_param, char *enable) |
| 178 | { |
| 179 | if (strcmp(enable, "1") == 0) |
| 180 | intf_param->igmpsn_enable = TRUE; |
| 181 | else |
| 182 | intf_param->igmpsn_enable = FALSE; |
| 183 | } |
| 184 | |
developer | 0dff3a9 | 2023-03-17 15:08:42 +0800 | [diff] [blame] | 185 | void set_wps_state(wifi_intf_param *intf_param, char *wps_state) |
developer | 223f598 | 2023-02-28 15:59:38 +0800 | [diff] [blame] | 186 | { |
developer | 0dff3a9 | 2023-03-17 15:08:42 +0800 | [diff] [blame] | 187 | intf_param->wps_state = strtol(wps_state, NULL, 10); |
developer | 223f598 | 2023-02-28 15:59:38 +0800 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | void set_wps_cancel(wifi_intf_param *intf_param, char *enable) |
| 191 | { |
| 192 | if (strcmp(enable, "1") == 0) |
| 193 | intf_param->wps_cancel = TRUE; |
| 194 | else |
| 195 | intf_param->wps_cancel = FALSE; |
| 196 | } |
| 197 | |
| 198 | void set_wps_pushbutton(wifi_intf_param *intf_param, char *enable) |
| 199 | { |
| 200 | if (strcmp(enable, "1") == 0) |
| 201 | intf_param->wps_pushbutton = TRUE; |
| 202 | else |
| 203 | intf_param->wps_pushbutton = FALSE; |
| 204 | } |
| 205 | |
| 206 | |
| 207 | void set_macfilter(wifi_intf_param *intf_param, char *macfilter) |
| 208 | { |
| 209 | strncpy(intf_param->macfilter, macfilter, 10); |
| 210 | } |
| 211 | |
| 212 | void set_maclist(wifi_intf_param *intf_param, char *maclist) |
| 213 | { |
| 214 | strncpy(intf_param->maclist, maclist, 512); |
| 215 | } |
| 216 | |
developer | c454873 | 2023-02-06 20:02:10 +0800 | [diff] [blame] | 217 | void set_htcoex(wifi_radio_param *radio_param, char *ht_coex) |
| 218 | { |
| 219 | radio_param->ht_coex = strtol(ht_coex, NULL, 10); |
| 220 | } |
| 221 | |
| 222 | void set_rts(wifi_radio_param *radio_param, char *rts) |
| 223 | { |
| 224 | radio_param->rtsThreshold = strtol(rts, NULL, 10); |
| 225 | } |
| 226 | |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 227 | void set_radionum(wifi_intf_param *intf_param, char *phy_name) |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 228 | { |
developer | 9567a46 | 2022-11-17 20:42:05 +0800 | [diff] [blame] | 229 | int radio_num = 0; |
| 230 | char *ptr = phy_name; |
developer | 4c2edbe | 2022-10-18 16:36:37 +0800 | [diff] [blame] | 231 | int phyId = 0; |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 232 | |
| 233 | while (*ptr) { |
| 234 | if (isdigit(*ptr)) { |
developer | 9567a46 | 2022-11-17 20:42:05 +0800 | [diff] [blame] | 235 | phyId = strtoul(ptr, NULL, 10); |
| 236 | radio_num = phy_index_to_radio(phyId); |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 237 | intf_param->radio_index = radio_num; |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 238 | break; |
| 239 | } |
| 240 | ptr++; |
| 241 | } |
| 242 | } |
| 243 | |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 244 | void set_ssid(wifi_intf_param *intf_param, char *ssid) |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 245 | { |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 246 | strncpy(intf_param->ssid, ssid, 32); |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 247 | } |
| 248 | |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 249 | void set_encryption(wifi_intf_param *intf_param, char *encryption_mode) |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 250 | { |
developer | 3ddad2f | 2022-10-13 13:33:57 +0800 | [diff] [blame] | 251 | if (strcmp(encryption_mode, "none") == 0) { |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 252 | intf_param->security.mode = wifi_security_mode_none; |
| 253 | intf_param->security.encr = wifi_encryption_none; |
developer | 3ddad2f | 2022-10-13 13:33:57 +0800 | [diff] [blame] | 254 | }else if(strncmp(encryption_mode, "psk2", 4) == 0){ |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 255 | intf_param->security.mode = wifi_security_mode_wpa2_personal; |
developer | 3ddad2f | 2022-10-13 13:33:57 +0800 | [diff] [blame] | 256 | }else if(strncmp(encryption_mode, "psk-",4) == 0){ |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 257 | intf_param->security.mode = wifi_security_mode_wpa_wpa2_personal; |
developer | 3ddad2f | 2022-10-13 13:33:57 +0800 | [diff] [blame] | 258 | }else if(strncmp(encryption_mode, "psk",3) == 0){ |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 259 | intf_param->security.mode = wifi_security_mode_wpa_personal; |
developer | 3ddad2f | 2022-10-13 13:33:57 +0800 | [diff] [blame] | 260 | }else if(strncmp(encryption_mode, "wpa2",4) == 0){ |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 261 | intf_param->security.mode = wifi_security_mode_wpa2_enterprise; |
developer | 3ddad2f | 2022-10-13 13:33:57 +0800 | [diff] [blame] | 262 | }else if(strncmp(encryption_mode, "wpa-",4) == 0){ |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 263 | intf_param->security.mode = wifi_security_mode_wpa_wpa2_enterprise; |
developer | 3ddad2f | 2022-10-13 13:33:57 +0800 | [diff] [blame] | 264 | }else if(strcmp(encryption_mode, "sae") == 0){ |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 265 | intf_param->security.mode = wifi_security_mode_wpa3_personal; |
developer | 3ddad2f | 2022-10-13 13:33:57 +0800 | [diff] [blame] | 266 | }else if(strcmp(encryption_mode, "wpa3") == 0){ |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 267 | intf_param->security.mode = wifi_security_mode_wpa3_enterprise; |
developer | 3ddad2f | 2022-10-13 13:33:57 +0800 | [diff] [blame] | 268 | }else if(strcmp(encryption_mode, "sae-mixed") == 0){ |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 269 | intf_param->security.mode = wifi_security_mode_wpa3_transition; |
developer | f634eab | 2023-01-13 15:23:06 +0800 | [diff] [blame] | 270 | }else if(strcmp(encryption_mode, "owe") == 0){ |
developer | 53364a7 | 2023-04-24 10:59:12 +0800 | [diff] [blame] | 271 | intf_param->security.mode = wifi_security_mode_enhanced_open; |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 272 | } |
| 273 | |
developer | 3ddad2f | 2022-10-13 13:33:57 +0800 | [diff] [blame] | 274 | if(strstr(encryption_mode, "tkip") && (strstr(encryption_mode, "ccmp") || strstr(encryption_mode, "aes") )){ |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 275 | intf_param->security.encr = wifi_encryption_aes_tkip; |
developer | 3ddad2f | 2022-10-13 13:33:57 +0800 | [diff] [blame] | 276 | }else if (strstr(encryption_mode, "tkip")){ |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 277 | intf_param->security.encr = wifi_encryption_tkip; |
developer | 3ddad2f | 2022-10-13 13:33:57 +0800 | [diff] [blame] | 278 | }else{ |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 279 | intf_param->security.encr = wifi_encryption_aes; |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 280 | } |
developer | 3ddad2f | 2022-10-13 13:33:57 +0800 | [diff] [blame] | 281 | |
developer | f634eab | 2023-01-13 15:23:06 +0800 | [diff] [blame] | 282 | if(!strcmp(encryption_mode, "wpa3") || !strcmp(encryption_mode, "sae") || !strcmp(encryption_mode, "owe")){ |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 283 | intf_param->security.mfp = wifi_mfp_cfg_required; |
developer | 3ddad2f | 2022-10-13 13:33:57 +0800 | [diff] [blame] | 284 | }else if (!strcmp(encryption_mode, "sae-mixed")){ |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 285 | intf_param->security.mfp = wifi_mfp_cfg_optional; |
developer | 3ddad2f | 2022-10-13 13:33:57 +0800 | [diff] [blame] | 286 | }else{ |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 287 | intf_param->security.mfp = wifi_mfp_cfg_disabled; |
developer | 3ddad2f | 2022-10-13 13:33:57 +0800 | [diff] [blame] | 288 | } |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 289 | } |
| 290 | |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 291 | void set_key(wifi_intf_param *intf_param, char *key) |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 292 | { |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 293 | strncpy(intf_param->security.u.key.key, key, 64); |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 294 | } |
| 295 | |
developer | 2bcdef9 | 2022-12-13 16:19:09 +0800 | [diff] [blame] | 296 | void set_ifname(wifi_intf_param *intf_param, char *ifname) |
| 297 | { |
| 298 | if (strlen(ifname) > 15) |
| 299 | return; |
| 300 | strncpy(intf_param->ifname, ifname, strlen(ifname) + 1); |
| 301 | } |
| 302 | |
developer | b3f0066 | 2022-12-29 09:35:55 +0800 | [diff] [blame] | 303 | void set_wds(wifi_intf_param *intf_param, char *wds_enable) |
| 304 | { |
| 305 | intf_param->wds_mode = FALSE; |
| 306 | if (strncmp(wds_enable, "1", 1) == 0) |
| 307 | intf_param->wds_mode = TRUE; |
| 308 | } |
| 309 | |
developer | c454873 | 2023-02-06 20:02:10 +0800 | [diff] [blame] | 310 | void set_hidden(wifi_intf_param *intf_param, char *hidden) |
| 311 | { |
| 312 | intf_param->hidden = strtol(hidden, NULL, 10); |
| 313 | } |
| 314 | |
developer | 9567a46 | 2022-11-17 20:42:05 +0800 | [diff] [blame] | 315 | int set_interface_bssid(int phy_index, int offset, mac_address_t *bssid) |
developer | f9b2ef0 | 2022-10-14 10:07:58 +0800 | [diff] [blame] | 316 | { |
| 317 | FILE *f; |
| 318 | char mac_file[64] = {0}; |
| 319 | char mac_address[20] = {0}; |
developer | f9b2ef0 | 2022-10-14 10:07:58 +0800 | [diff] [blame] | 320 | |
developer | b97b549 | 2022-12-22 19:44:36 +0800 | [diff] [blame] | 321 | sprintf(mac_file, "/sys/class/ieee80211/phy%d/macaddress", phy_index); |
developer | f9b2ef0 | 2022-10-14 10:07:58 +0800 | [diff] [blame] | 322 | f = fopen(mac_file, "r"); |
| 323 | if (f == NULL) |
| 324 | return -1; |
| 325 | fgets(mac_address, 20, f); |
| 326 | fclose(f); |
| 327 | |
developer | 9567a46 | 2022-11-17 20:42:05 +0800 | [diff] [blame] | 328 | mac_addr_aton(&(*bssid)[0], mac_address); |
| 329 | (*bssid)[0] += offset*2; |
developer | f9b2ef0 | 2022-10-14 10:07:58 +0800 | [diff] [blame] | 330 | return 0; |
| 331 | } |
| 332 | |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 333 | void set_radio_param(wifi_radio_param radio_parameter) |
| 334 | { |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 335 | int ret = 0; |
developer | ab98580 | 2022-10-07 09:42:31 +0800 | [diff] [blame] | 336 | wifi_radio_operationParam_t operationParam = {0}; |
| 337 | |
developer | 4c2edbe | 2022-10-18 16:36:37 +0800 | [diff] [blame] | 338 | if(radio_parameter.radio_index == -1) |
| 339 | return; |
| 340 | |
developer | ab98580 | 2022-10-07 09:42:31 +0800 | [diff] [blame] | 341 | if (radio_parameter.disabled == TRUE) { |
| 342 | wifi_setRadioEnable(radio_parameter.radio_index, FALSE); |
| 343 | return; |
| 344 | } |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 345 | |
| 346 | fprintf(stderr, "Start setting radio\n"); |
developer | 1861581 | 2022-10-17 17:37:29 +0800 | [diff] [blame] | 347 | |
developer | 1e946fd | 2022-12-26 17:09:00 +0800 | [diff] [blame] | 348 | if (radio_parameter.txantenna != 0 && radio_parameter.txantenna == radio_parameter.rxantenna) { |
| 349 | ret = wifi_setRadioTxChainMask(radio_parameter.radio_index, radio_parameter.txantenna); |
| 350 | if (ret != RETURN_OK) |
| 351 | fprintf(stderr, "[Set Tx Chain mask failed!!!]\n"); |
| 352 | } |
| 353 | |
developer | 1861581 | 2022-10-17 17:37:29 +0800 | [diff] [blame] | 354 | // Get current radio setting |
developer | ab98580 | 2022-10-07 09:42:31 +0800 | [diff] [blame] | 355 | ret = wifi_getRadioOperatingParameters(radio_parameter.radio_index, &operationParam); |
| 356 | if (ret != RETURN_OK) |
| 357 | fprintf(stderr, "[Get OperatingParameters failed!!!]\n"); |
developer | 1861581 | 2022-10-17 17:37:29 +0800 | [diff] [blame] | 358 | operationParam.enable = TRUE; |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 359 | |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 360 | // Channel |
developer | ab98580 | 2022-10-07 09:42:31 +0800 | [diff] [blame] | 361 | operationParam.autoChannelEnabled = radio_parameter.auto_channel; |
| 362 | operationParam.channel = radio_parameter.channel; |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 363 | |
developer | 02cc929 | 2023-02-24 18:01:27 +0800 | [diff] [blame] | 364 | // bandwidth |
developer | ae3f841 | 2022-10-13 15:27:02 +0800 | [diff] [blame] | 365 | if (radio_parameter.bandwidth == 20){ |
| 366 | operationParam.channelWidth = WIFI_CHANNELBANDWIDTH_20MHZ; |
| 367 | }else if (radio_parameter.bandwidth == 40){ |
| 368 | operationParam.channelWidth = WIFI_CHANNELBANDWIDTH_40MHZ; |
| 369 | }else if (radio_parameter.bandwidth == 80){ |
| 370 | operationParam.channelWidth = WIFI_CHANNELBANDWIDTH_80MHZ; |
| 371 | }else if (radio_parameter.bandwidth == 160){ |
| 372 | operationParam.channelWidth = WIFI_CHANNELBANDWIDTH_160MHZ; |
developer | 02cc929 | 2023-02-24 18:01:27 +0800 | [diff] [blame] | 373 | }else if (radio_parameter.bandwidth == 320){ |
| 374 | if ((radio_parameter.eht_320_conf == 1 || radio_parameter.channel <= 29) && radio_parameter.channel < 193) |
| 375 | operationParam.channelWidth = WIFI_CHANNELBANDWIDTH_320_1MHZ; |
| 376 | else if (radio_parameter.eht_320_conf == 2 || radio_parameter.channel >= 193) |
| 377 | operationParam.channelWidth = WIFI_CHANNELBANDWIDTH_320_2MHZ; |
| 378 | else |
| 379 | fprintf(stderr, "[Set EHT 320 bandwidth error with conf %d!!!]\n", radio_parameter.eht_320_conf); |
developer | ae3f841 | 2022-10-13 15:27:02 +0800 | [diff] [blame] | 380 | } |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 381 | |
| 382 | // htmode |
developer | ab98580 | 2022-10-07 09:42:31 +0800 | [diff] [blame] | 383 | unsigned int mode = 0; // enum wifi_ieee80211Variant_t |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 384 | if (strcmp(radio_parameter.band, "2g") == 0) { |
developer | ab98580 | 2022-10-07 09:42:31 +0800 | [diff] [blame] | 385 | mode |= WIFI_80211_VARIANT_B | WIFI_80211_VARIANT_G; |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 386 | if (strcmp(radio_parameter.htmode, "NOHT") == 0 || strcmp(radio_parameter.htmode, "NONE") == 0) |
| 387 | strcpy(radio_parameter.htmode, "11G"); |
developer | 02cc929 | 2023-02-24 18:01:27 +0800 | [diff] [blame] | 388 | else if (strstr(radio_parameter.htmode, "HE") != NULL) |
developer | ab98580 | 2022-10-07 09:42:31 +0800 | [diff] [blame] | 389 | mode |= WIFI_80211_VARIANT_N | WIFI_80211_VARIANT_AX; |
developer | 02cc929 | 2023-02-24 18:01:27 +0800 | [diff] [blame] | 390 | else if (strstr(radio_parameter.htmode, "EHT") != NULL) |
| 391 | mode |= WIFI_80211_VARIANT_N | WIFI_80211_VARIANT_AX | WIFI_80211_VARIANT_BE; |
| 392 | else if (strstr(radio_parameter.htmode, "HT") != NULL) |
| 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 | } else if (strcmp(radio_parameter.band, "5g") == 0) { |
| 396 | mode |= WIFI_80211_VARIANT_A; |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 397 | if (strcmp(radio_parameter.htmode, "NOHT") == 0 || strcmp(radio_parameter.htmode, "NONE") == 0) |
| 398 | strcpy(radio_parameter.htmode, "11A"); |
developer | 02cc929 | 2023-02-24 18:01:27 +0800 | [diff] [blame] | 399 | else if (strstr(radio_parameter.htmode, "VHT") != NULL) |
| 400 | mode |= WIFI_80211_VARIANT_N | WIFI_80211_VARIANT_AC; |
| 401 | else if (strstr(radio_parameter.htmode, "HE") != NULL) |
developer | ab98580 | 2022-10-07 09:42:31 +0800 | [diff] [blame] | 402 | mode |= WIFI_80211_VARIANT_N | WIFI_80211_VARIANT_AC | WIFI_80211_VARIANT_AX; |
developer | 02cc929 | 2023-02-24 18:01:27 +0800 | [diff] [blame] | 403 | else if (strstr(radio_parameter.htmode, "EHT") != NULL) |
| 404 | mode |= WIFI_80211_VARIANT_N | WIFI_80211_VARIANT_AC | WIFI_80211_VARIANT_AX | WIFI_80211_VARIANT_BE; |
| 405 | else if (strstr(radio_parameter.htmode, "HT") != NULL) |
| 406 | mode |= WIFI_80211_VARIANT_N; |
| 407 | } else if (strcmp(radio_parameter.band, "6g") == 0) { |
| 408 | mode |= WIFI_80211_VARIANT_AX; |
| 409 | if (strstr(radio_parameter.htmode, "EHT") != NULL) |
| 410 | mode |= WIFI_80211_VARIANT_BE; |
| 411 | } |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 412 | |
developer | ab98580 | 2022-10-07 09:42:31 +0800 | [diff] [blame] | 413 | operationParam.variant = mode; |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 414 | |
developer | c454873 | 2023-02-06 20:02:10 +0800 | [diff] [blame] | 415 | // rtsThreshold, zero means not set |
| 416 | if ((radio_parameter.rtsThreshold < 65535) && radio_parameter.rtsThreshold) |
| 417 | operationParam.rtsThreshold = radio_parameter.rtsThreshold; |
| 418 | |
| 419 | //ht_coex |
| 420 | operationParam.obssCoex = radio_parameter.ht_coex; |
| 421 | |
developer | ab98580 | 2022-10-07 09:42:31 +0800 | [diff] [blame] | 422 | // apply setting |
| 423 | ret = wifi_setRadioOperatingParameters(radio_parameter.radio_index, &operationParam); |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 424 | if (ret != RETURN_OK) |
developer | ab98580 | 2022-10-07 09:42:31 +0800 | [diff] [blame] | 425 | fprintf(stderr, "[Apply setting failed!!!]\n"); |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 426 | |
developer | b7f28c4 | 2022-11-07 16:58:17 +0800 | [diff] [blame] | 427 | // Country |
| 428 | fprintf(stderr, "Set Country: %s\n", radio_parameter.country); |
| 429 | ret = wifi_setRadioCountryCode(radio_parameter.radio_index, radio_parameter.country); |
| 430 | if (ret != RETURN_OK) |
| 431 | fprintf(stderr, "[Set Country failed!!!]\n"); |
| 432 | ret = 0; |
| 433 | |
| 434 | // hwmode |
| 435 | fprintf(stderr, "Set hwmode: %s\n", radio_parameter.hwmode); |
| 436 | ret = wifi_setRadioHwMode(radio_parameter.radio_index, radio_parameter.hwmode); |
| 437 | if (ret != RETURN_OK) |
| 438 | fprintf(stderr, "[Set hwmode failed!!!]\n"); |
| 439 | ret = 0; |
| 440 | |
| 441 | // noscan |
| 442 | fprintf(stderr, "Set noscan: %s \n", radio_parameter.noscan); |
| 443 | if(strlen(radio_parameter.noscan)){ |
| 444 | ret = wifi_setNoscan(radio_parameter.radio_index, radio_parameter.noscan); |
| 445 | if (ret != RETURN_OK) |
| 446 | fprintf(stderr, "[Set noscan failed!!!]\n"); |
| 447 | } |
| 448 | ret = 0; |
| 449 | |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 450 | } |
| 451 | |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 452 | 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] | 453 | { |
| 454 | int ret = 0; |
developer | ab98580 | 2022-10-07 09:42:31 +0800 | [diff] [blame] | 455 | int vap_index_in_map = 0; |
developer | 9567a46 | 2022-11-17 20:42:05 +0800 | [diff] [blame] | 456 | int phy_index = 0; |
developer | 9feeaf1 | 2023-02-17 15:52:18 +0800 | [diff] [blame] | 457 | int key_len = 0; |
developer | ab98580 | 2022-10-07 09:42:31 +0800 | [diff] [blame] | 458 | wifi_vap_info_t vap_info = {0}; |
developer | 1861581 | 2022-10-17 17:37:29 +0800 | [diff] [blame] | 459 | BOOL radio_enable = FALSE; |
developer | 0dff3a9 | 2023-03-17 15:08:42 +0800 | [diff] [blame] | 460 | char *maclist; |
developer | 1861581 | 2022-10-17 17:37:29 +0800 | [diff] [blame] | 461 | |
developer | 41965b5 | 2022-10-19 17:40:23 +0800 | [diff] [blame] | 462 | if(ap_param.radio_index == -1) |
| 463 | return; |
| 464 | |
developer | 1861581 | 2022-10-17 17:37:29 +0800 | [diff] [blame] | 465 | wifi_getRadioEnable(ap_param.radio_index, &radio_enable); |
| 466 | if (radio_enable == FALSE) |
| 467 | return; |
developer | ab98580 | 2022-10-07 09:42:31 +0800 | [diff] [blame] | 468 | |
developer | 41965b5 | 2022-10-19 17:40:23 +0800 | [diff] [blame] | 469 | |
| 470 | // get the index of the map |
developer | 5f8ef5c | 2023-02-22 15:49:20 +0800 | [diff] [blame] | 471 | for (int i = 0; i < MAX_NUM_VAP_PER_RADIO; i++) { |
developer | 41965b5 | 2022-10-19 17:40:23 +0800 | [diff] [blame] | 472 | if (map->vap_array[i].vap_index == ap_param.ap_index) { |
| 473 | vap_index_in_map = i; |
| 474 | break; |
developer | ab98580 | 2022-10-07 09:42:31 +0800 | [diff] [blame] | 475 | } |
| 476 | } |
| 477 | |
developer | 41965b5 | 2022-10-19 17:40:23 +0800 | [diff] [blame] | 478 | |
developer | 5f8ef5c | 2023-02-22 15:49:20 +0800 | [diff] [blame] | 479 | fprintf(stderr, "Start setting ap vap_index_in_map=%d\n", vap_index_in_map); |
developer | f9b2ef0 | 2022-10-14 10:07:58 +0800 | [diff] [blame] | 480 | |
developer | 41965b5 | 2022-10-19 17:40:23 +0800 | [diff] [blame] | 481 | vap_info = map->vap_array[vap_index_in_map]; |
developer | f9b2ef0 | 2022-10-14 10:07:58 +0800 | [diff] [blame] | 482 | vap_info.u.bss_info.enabled = TRUE; |
developer | 9567a46 | 2022-11-17 20:42:05 +0800 | [diff] [blame] | 483 | phy_index = radio_index_to_phy(vap_info.radio_index); |
| 484 | 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] | 485 | fprintf(stderr, "Get mac address failed.\n"); |
developer | 9567a46 | 2022-11-17 20:42:05 +0800 | [diff] [blame] | 486 | return; |
developer | f9b2ef0 | 2022-10-14 10:07:58 +0800 | [diff] [blame] | 487 | } |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 488 | |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 489 | // SSID |
developer | ab98580 | 2022-10-07 09:42:31 +0800 | [diff] [blame] | 490 | strncpy(vap_info.u.bss_info.ssid, ap_param.ssid, 33); |
| 491 | vap_info.u.bss_info.ssid[32] = '\0'; |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 492 | |
developer | 2bcdef9 | 2022-12-13 16:19:09 +0800 | [diff] [blame] | 493 | // interface |
| 494 | if (strlen(ap_param.ifname) != 0) { |
| 495 | strncpy(vap_info.vap_name, ap_param.ifname, 16); |
developer | 53364a7 | 2023-04-24 10:59:12 +0800 | [diff] [blame] | 496 | vap_info.vap_name[15] = '\0'; |
developer | 2bcdef9 | 2022-12-13 16:19:09 +0800 | [diff] [blame] | 497 | } |
| 498 | |
developer | 9feeaf1 | 2023-02-17 15:52:18 +0800 | [diff] [blame] | 499 | // Security |
| 500 | if (ap_param.security.mode == wifi_security_mode_wpa3_personal || ap_param.security.mode == wifi_security_mode_wpa3_transition){ |
| 501 | // OpenWrt script only set psk, here we choose to set both psk and sae. |
| 502 | ap_param.security.u.key.type = wifi_security_key_type_psk_sae; |
| 503 | } else { |
| 504 | key_len = strlen(ap_param.security.u.key.key); |
| 505 | if (key_len == 64) |
| 506 | ap_param.security.u.key.type = wifi_security_key_type_psk; |
| 507 | else if (key_len >= 8 && key_len < 64) |
| 508 | ap_param.security.u.key.type = wifi_security_key_type_pass; |
| 509 | } |
| 510 | |
developer | 3ddad2f | 2022-10-13 13:33:57 +0800 | [diff] [blame] | 511 | vap_info.u.bss_info.security.mode = ap_param.security.mode; |
| 512 | vap_info.u.bss_info.security.encr = ap_param.security.encr; |
| 513 | vap_info.u.bss_info.security.mfp = ap_param.security.mfp; |
| 514 | vap_info.u.bss_info.security.u.key.type = ap_param.security.u.key.type; |
| 515 | 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] | 516 | |
| 517 | // hidden |
| 518 | vap_info.u.bss_info.showSsid = (ap_param.hidden ? 0 : 1); |
developer | 4c2edbe | 2022-10-18 16:36:37 +0800 | [diff] [blame] | 519 | |
developer | 223f598 | 2023-02-28 15:59:38 +0800 | [diff] [blame] | 520 | // igmpsn_enable |
| 521 | vap_info.u.bss_info.mcast2ucast = ap_param.igmpsn_enable; |
| 522 | fprintf(stderr, "Set igmpsn_enable: %d \n", ap_param.igmpsn_enable); |
| 523 | |
| 524 | // wps_state |
| 525 | fprintf(stderr, "Set wps_state: %d \n", ap_param.wps_state); |
developer | 0dff3a9 | 2023-03-17 15:08:42 +0800 | [diff] [blame] | 526 | if (ap_param.wps_state == 2) |
| 527 | ret = wifi_setApWpsEnable(ap_param.ap_index, 1); |
| 528 | else |
| 529 | ret = wifi_setApWpsEnable(ap_param.ap_index, 0); |
developer | 223f598 | 2023-02-28 15:59:38 +0800 | [diff] [blame] | 530 | if (ret != RETURN_OK) |
| 531 | fprintf(stderr, "[Set wps_state failed!!!]\n"); |
| 532 | ret = 0; |
| 533 | |
developer | 223f598 | 2023-02-28 15:59:38 +0800 | [diff] [blame] | 534 | // macfilter |
developer | 0dff3a9 | 2023-03-17 15:08:42 +0800 | [diff] [blame] | 535 | fprintf(stderr, "Set macfilter: %s \n", ap_param.macfilter); |
developer | 223f598 | 2023-02-28 15:59:38 +0800 | [diff] [blame] | 536 | if ((strcmp(ap_param.macfilter, "disable") == 0) || (strcmp(ap_param.macfilter, "\0") == 0) ) |
| 537 | vap_info.u.bss_info.mac_filter_enable = false; |
| 538 | else if (strcmp(ap_param.macfilter, "deny") == 0){ |
| 539 | vap_info.u.bss_info.mac_filter_enable = true; |
| 540 | vap_info.u.bss_info.mac_filter_mode = wifi_mac_filter_mode_black_list; |
| 541 | } |
| 542 | else if (strcmp(ap_param.macfilter, "allow") == 0){ |
| 543 | vap_info.u.bss_info.mac_filter_enable = true; |
| 544 | vap_info.u.bss_info.mac_filter_mode = wifi_mac_filter_mode_white_list; |
| 545 | } |
| 546 | else |
| 547 | fprintf(stderr, "The macfilter tpye: %s is invalid!!!\n", ap_param.macfilter); |
developer | 223f598 | 2023-02-28 15:59:38 +0800 | [diff] [blame] | 548 | |
| 549 | // maclist |
developer | 0dff3a9 | 2023-03-17 15:08:42 +0800 | [diff] [blame] | 550 | fprintf(stderr, "Set maclist: %s \n", ap_param.maclist); |
| 551 | if ((strlen(ap_param.maclist) == 0)){ |
developer | 223f598 | 2023-02-28 15:59:38 +0800 | [diff] [blame] | 552 | ret = wifi_delApAclDevices(ap_param.ap_index); |
| 553 | if (ret != RETURN_OK) |
| 554 | fprintf(stderr, "[Del all maclist failed!!!]\n"); |
| 555 | ret = 0; |
developer | 0dff3a9 | 2023-03-17 15:08:42 +0800 | [diff] [blame] | 556 | } |
developer | a982e8f | 2023-03-09 15:47:10 +0800 | [diff] [blame] | 557 | else if (strcmp(ap_param.macfilter, "allow") == 0) { |
developer | 0dff3a9 | 2023-03-17 15:08:42 +0800 | [diff] [blame] | 558 | maclist = strtok(ap_param.maclist, ";"); |
| 559 | while (maclist != NULL) |
| 560 | { |
| 561 | ret = wifi_addApAclDevice(ap_param.ap_index, maclist); |
| 562 | if (ret != RETURN_OK) |
| 563 | fprintf(stderr, "[Add maclist failed!!!]\n"); |
| 564 | ret = 0; |
| 565 | maclist = strtok(NULL, ";"); |
developer | 223f598 | 2023-02-28 15:59:38 +0800 | [diff] [blame] | 566 | } |
developer | 0dff3a9 | 2023-03-17 15:08:42 +0800 | [diff] [blame] | 567 | } |
developer | a982e8f | 2023-03-09 15:47:10 +0800 | [diff] [blame] | 568 | else if (strcmp(ap_param.macfilter, "deny") == 0) { |
developer | 0dff3a9 | 2023-03-17 15:08:42 +0800 | [diff] [blame] | 569 | maclist = strtok(ap_param.maclist, ";"); |
| 570 | while (maclist != NULL) |
| 571 | { |
| 572 | ret = wifi_addApDenyAclDevice(ap_param.ap_index, maclist); |
| 573 | if (ret != RETURN_OK) |
| 574 | fprintf(stderr, "[Add maclist failed!!!]\n"); |
| 575 | ret = 0; |
| 576 | maclist = strtok(NULL, ";"); |
developer | a982e8f | 2023-03-09 15:47:10 +0800 | [diff] [blame] | 577 | } |
developer | 0dff3a9 | 2023-03-17 15:08:42 +0800 | [diff] [blame] | 578 | } |
developer | 223f598 | 2023-02-28 15:59:38 +0800 | [diff] [blame] | 579 | |
| 580 | ret = 0; |
developer | ab98580 | 2022-10-07 09:42:31 +0800 | [diff] [blame] | 581 | // Replace the setting with uci config |
developer | 41965b5 | 2022-10-19 17:40:23 +0800 | [diff] [blame] | 582 | map->vap_array[vap_index_in_map] = vap_info; |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 583 | } |
| 584 | |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 585 | void set_sta_param(wifi_intf_param sta_param) |
developer | 9567a46 | 2022-11-17 20:42:05 +0800 | [diff] [blame] | 586 | { |
| 587 | wifi_sta_network_t *sta = NULL; |
| 588 | mac_address_t sta_mac = {0}; |
| 589 | char sta_mac_str[20] = {0}; |
| 590 | char key_mgmt[16] = {0}; |
| 591 | char pairwise[16] = {0}; |
| 592 | int phy_index = 0; |
| 593 | |
| 594 | sta = calloc(1, sizeof(wifi_sta_network_t)); |
| 595 | |
| 596 | phy_index = radio_index_to_phy(sta_param.radio_index); |
| 597 | set_interface_bssid(phy_index, sta_param.mac_offset, &sta_mac); |
| 598 | mac_addr_ntoa(sta_mac_str, sta_mac); |
| 599 | snprintf(sta->ssid, 31, "%s", sta_param.ssid); |
| 600 | sta->ssid[31] = '\0'; |
| 601 | snprintf(sta->psk, 64, "%s", sta_param.password); |
| 602 | |
| 603 | if (sta_param.security.mode == wifi_security_mode_none) |
| 604 | strcpy(key_mgmt, "NONE"); |
| 605 | else if (sta_param.security.mode == wifi_security_mode_wpa3_personal) |
| 606 | strcpy(key_mgmt, "SAE"); |
developer | 53364a7 | 2023-04-24 10:59:12 +0800 | [diff] [blame] | 607 | else if (sta_param.security.mode == wifi_security_mode_enhanced_open) |
developer | f634eab | 2023-01-13 15:23:06 +0800 | [diff] [blame] | 608 | strcpy(key_mgmt, "OWE"); |
developer | 9567a46 | 2022-11-17 20:42:05 +0800 | [diff] [blame] | 609 | else |
| 610 | strcpy(key_mgmt, "WPA-PSK"); |
| 611 | snprintf(sta->key_mgmt, 64, "%s", key_mgmt); |
| 612 | |
| 613 | if (sta_param.security.encr == wifi_encryption_aes) |
| 614 | strcpy(pairwise, "CCMP"); |
| 615 | else if (sta_param.security.encr == wifi_encryption_tkip) |
| 616 | strcpy(pairwise, "TKIP"); |
| 617 | else |
| 618 | strcpy(pairwise, "CCMP TKIP"); |
| 619 | snprintf(sta->pairwise, 64, "%s", pairwise); |
| 620 | |
| 621 | if (strlen(sta_param.security.u.key.key) > 0) |
| 622 | strncpy(sta->psk, sta_param.security.u.key.key, 127); |
| 623 | sta->psk[127] = '\0'; |
| 624 | sta->psk_len = strlen(sta->psk); |
| 625 | |
developer | b3f0066 | 2022-12-29 09:35:55 +0800 | [diff] [blame] | 626 | if (sta_param.wds_mode == TRUE) |
| 627 | sta->flags |= WIFI_STA_NET_F_4ADDR_MULTI_AP; |
| 628 | |
| 629 | wifi_createSTAInterface(sta_param.sta_index, sta_mac_str, sta_param.wds_mode); |
developer | 9567a46 | 2022-11-17 20:42:05 +0800 | [diff] [blame] | 630 | |
| 631 | if (wifi_setSTANetworks(sta_param.sta_index, &sta, 1, FALSE) == RETURN_ERR) { |
| 632 | fprintf(stderr, "Write to sta %d config file failed\n", sta_param.sta_index); |
| 633 | free(sta); |
| 634 | return; |
| 635 | } |
| 636 | free(sta); |
| 637 | |
| 638 | if (wifi_setSTAEnabled(sta_param.sta_index, TRUE) == RETURN_ERR) { |
| 639 | fprintf(stderr, "Enable station failed\n"); |
| 640 | return; |
| 641 | } |
| 642 | } |
| 643 | |
developer | 223f598 | 2023-02-28 15:59:38 +0800 | [diff] [blame] | 644 | void show_ap_param(wifi_intf_param ap_param , wifi_vap_info_map_t *map) |
| 645 | { |
| 646 | int ret = 0; |
developer | a982e8f | 2023-03-09 15:47:10 +0800 | [diff] [blame] | 647 | int filter_mode = 0; |
developer | 223f598 | 2023-02-28 15:59:38 +0800 | [diff] [blame] | 648 | int vap_index_in_map = 0; |
| 649 | int phy_index = 0; |
| 650 | wifi_vap_info_t vap_info = {0}; |
| 651 | BOOL radio_enable = FALSE; |
| 652 | BOOL wps_state = FALSE; |
developer | a982e8f | 2023-03-09 15:47:10 +0800 | [diff] [blame] | 653 | BOOL igmpsn_state = FALSE; |
developer | 223f598 | 2023-02-28 15:59:38 +0800 | [diff] [blame] | 654 | UINT buf_size = 1024; |
| 655 | char macArray[1024] = ""; |
| 656 | |
| 657 | if(ap_param.radio_index == -1) |
| 658 | return; |
| 659 | |
| 660 | wifi_getRadioEnable(ap_param.radio_index, &radio_enable); |
| 661 | if (radio_enable == FALSE) |
| 662 | return; |
| 663 | |
| 664 | |
| 665 | // get the index of the map |
| 666 | for (int i = 0; i < map->num_vaps; i++) { |
| 667 | if (map->vap_array[i].vap_index == ap_param.ap_index) { |
| 668 | vap_index_in_map = i; |
| 669 | break; |
| 670 | } |
| 671 | } |
| 672 | |
| 673 | vap_info = map->vap_array[vap_index_in_map]; |
| 674 | vap_info.u.bss_info.enabled = TRUE; |
| 675 | phy_index = radio_index_to_phy(vap_info.radio_index); |
| 676 | |
| 677 | // SSID |
| 678 | printf("wifi%d ssid: %s\n", ap_param.ap_index, vap_info.u.bss_info.ssid); |
| 679 | |
developer | 0dff3a9 | 2023-03-17 15:08:42 +0800 | [diff] [blame] | 680 | // igmpsn_enable |
developer | a982e8f | 2023-03-09 15:47:10 +0800 | [diff] [blame] | 681 | ret = wifi_getRadioIGMPSnoopingEnable(ap_param.radio_index, &igmpsn_state); |
| 682 | if (ret != RETURN_OK) |
| 683 | fprintf(stderr, "[Get igmpsn_state failed!!!]\n"); |
| 684 | else |
| 685 | printf("wifi%d igmpsn_state: %d\n", ap_param.ap_index, igmpsn_state); |
| 686 | ret = 0; |
developer | 223f598 | 2023-02-28 15:59:38 +0800 | [diff] [blame] | 687 | |
| 688 | // wps_state |
| 689 | ret = wifi_getApWpsEnable(ap_param.ap_index, &wps_state); |
| 690 | if (ret != RETURN_OK) |
developer | a982e8f | 2023-03-09 15:47:10 +0800 | [diff] [blame] | 691 | fprintf(stderr, "[Get wps_state failed!!!]\n"); |
developer | 223f598 | 2023-02-28 15:59:38 +0800 | [diff] [blame] | 692 | else |
| 693 | printf("wifi%d wps_state: %d\n", ap_param.ap_index, wps_state); |
| 694 | ret = 0; |
| 695 | |
| 696 | // macfilter |
developer | a982e8f | 2023-03-09 15:47:10 +0800 | [diff] [blame] | 697 | ret = wifi_getApMacAddressControlMode(ap_param.ap_index, &filter_mode); |
| 698 | if (ret != RETURN_OK) |
| 699 | fprintf(stderr, "[Get macfilter failed!!!]\n"); |
| 700 | else{ |
| 701 | if (filter_mode == 0) |
| 702 | printf("wifi%d macfilter: disable\n", ap_param.ap_index); |
| 703 | else if (filter_mode == 1) |
| 704 | printf("wifi%d macfilter: allow\n", ap_param.ap_index); |
| 705 | else if (filter_mode == 2) |
| 706 | printf("wifi%d macfilter: deny\n", ap_param.ap_index); |
| 707 | } |
| 708 | ret = 0; |
developer | 223f598 | 2023-02-28 15:59:38 +0800 | [diff] [blame] | 709 | |
| 710 | // maclist |
| 711 | printf("wifi%d maclist: \n", ap_param.ap_index); |
developer | a982e8f | 2023-03-09 15:47:10 +0800 | [diff] [blame] | 712 | if (filter_mode == 0) |
| 713 | printf("wifi%d macfilter is disable\n", ap_param.ap_index); |
| 714 | else if (filter_mode == 1){ |
| 715 | ret = wifi_getApAclDevices(ap_param.ap_index, macArray, buf_size); |
| 716 | if (ret != RETURN_OK) |
| 717 | fprintf(stderr, "[Get maclist failed!!!]\n"); |
| 718 | else |
| 719 | printf("%s \n", macArray); |
| 720 | ret = 0; |
| 721 | } |
| 722 | else if (filter_mode == 2){ |
| 723 | ret = wifi_getApDenyAclDevices(ap_param.ap_index, macArray, buf_size); |
| 724 | if (ret != RETURN_OK) |
| 725 | fprintf(stderr, "[Get maclist failed!!!]\n"); |
| 726 | else |
| 727 | printf("%s \n", macArray); |
| 728 | ret = 0; |
| 729 | } |
developer | 223f598 | 2023-02-28 15:59:38 +0800 | [diff] [blame] | 730 | |
| 731 | } |
| 732 | |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 733 | int apply_uci_config () |
| 734 | { |
| 735 | struct uci_context *uci_ctx = uci_alloc_context(); |
| 736 | struct uci_package *uci_pkg = NULL; |
| 737 | struct uci_element *e; |
| 738 | // struct uci_section *s; |
| 739 | const char cfg_name[] = "wireless"; |
| 740 | int max_radio_num = 0; |
| 741 | BOOL parsing_radio = FALSE; |
developer | 4c2edbe | 2022-10-18 16:36:37 +0800 | [diff] [blame] | 742 | int apCount[3] = {0}; |
developer | 9567a46 | 2022-11-17 20:42:05 +0800 | [diff] [blame] | 743 | int staCount[3] = {0}; |
developer | 41965b5 | 2022-10-19 17:40:23 +0800 | [diff] [blame] | 744 | wifi_vap_info_map_t vap_map[3] = {0}; |
| 745 | int ret = 0; |
developer | 5f8ef5c | 2023-02-22 15:49:20 +0800 | [diff] [blame] | 746 | int i = 0, j = 0; |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 747 | |
| 748 | wifi_getMaxRadioNumber(&max_radio_num); |
| 749 | fprintf(stderr, "max radio number: %d\n", max_radio_num); |
developer | 41965b5 | 2022-10-19 17:40:23 +0800 | [diff] [blame] | 750 | for (i = 0; i < max_radio_num ;i++ ){ |
| 751 | ret = wifi_getRadioVapInfoMap(i, &vap_map[i]); |
| 752 | if (ret != RETURN_OK) { // if failed, we set assume this vap as the first vap. |
| 753 | fprintf(stderr, "[Get vap map failed!!!]\n"); |
developer | 41965b5 | 2022-10-19 17:40:23 +0800 | [diff] [blame] | 754 | } |
developer | 5f8ef5c | 2023-02-22 15:49:20 +0800 | [diff] [blame] | 755 | |
| 756 | /*reset radio's ap number, ap number ++ by uci config */ |
| 757 | vap_map[i].num_vaps = 0; |
developer | 41965b5 | 2022-10-19 17:40:23 +0800 | [diff] [blame] | 758 | } |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 759 | if (uci_load(uci_ctx, cfg_name, &uci_pkg) != UCI_OK) { |
| 760 | uci_free_context(uci_ctx); |
| 761 | fprintf(stderr, "%s: load uci failed.\n", __func__); |
| 762 | return RETURN_ERR; |
| 763 | } |
| 764 | |
| 765 | uci_foreach_element(&uci_pkg->sections, e) { |
| 766 | |
| 767 | struct uci_section *s = uci_to_section(e); |
| 768 | struct uci_element *option = NULL; |
| 769 | wifi_radio_param radio_param = {0}; |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 770 | wifi_intf_param intf_param = {0}; |
developer | 4c2edbe | 2022-10-18 16:36:37 +0800 | [diff] [blame] | 771 | int phyId = 0; |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 772 | radio_param.radio_index = -1; |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 773 | intf_param.ap_index = -1; |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 774 | |
| 775 | if (strcmp(s->type, "wifi-device") == 0) { |
developer | 4c2edbe | 2022-10-18 16:36:37 +0800 | [diff] [blame] | 776 | sscanf(s->e.name, "radio%d", &phyId); |
| 777 | radio_param.radio_index = phy_index_to_radio(phyId); |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 778 | parsing_radio = TRUE; |
| 779 | fprintf(stderr, "\n----- Start parsing radio %d config. -----\n", radio_param.radio_index); |
| 780 | } else if (strcmp(s->type, "wifi-iface") == 0) { |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 781 | parsing_radio = FALSE; |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 782 | } |
| 783 | |
| 784 | uci_foreach_element(&s->options, option) { |
| 785 | |
| 786 | struct uci_option *op = uci_to_option(option); |
| 787 | if (parsing_radio == TRUE) { |
| 788 | // transform the type from input string and store the value in radio_param. |
| 789 | if (strcmp(op->e.name, "channel") == 0) |
| 790 | set_channel(&radio_param, op->v.string); |
| 791 | else if (strcmp(op->e.name, "hwmode") == 0) |
| 792 | set_hwmode(&radio_param, op->v.string); |
| 793 | else if (strcmp(op->e.name, "htmode") == 0) |
| 794 | set_htmode(&radio_param, op->v.string); |
| 795 | else if (strcmp(op->e.name, "disabled") == 0) |
| 796 | set_disable(&radio_param, op->v.string); |
| 797 | else if (strcmp(op->e.name, "band") == 0) |
| 798 | set_band(&radio_param, op->v.string); |
| 799 | else if (strcmp(op->e.name, "country") == 0) |
| 800 | set_country(&radio_param, op->v.string); |
| 801 | else if (strcmp(op->e.name, "noscan") == 0) |
developer | 54afa2c | 2022-10-18 17:44:13 +0800 | [diff] [blame] | 802 | set_noscan(&radio_param, op->v.string); |
developer | 1e946fd | 2022-12-26 17:09:00 +0800 | [diff] [blame] | 803 | else if (strcmp(op->e.name, "rxantenna") == 0) |
| 804 | set_rxant(&radio_param, op->v.string); |
| 805 | else if (strcmp(op->e.name, "txantenna") == 0) |
| 806 | set_txant(&radio_param, op->v.string); |
developer | c454873 | 2023-02-06 20:02:10 +0800 | [diff] [blame] | 807 | else if (strcmp(op->e.name, "ht_coex") == 0) |
| 808 | set_htcoex(&radio_param, op->v.string); |
| 809 | else if (strcmp(op->e.name, "rts") == 0) |
| 810 | set_rts(&radio_param, op->v.string); |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 811 | else |
| 812 | fprintf(stderr, "[%s %s not set!]\n", op->e.name, op->v.string); |
| 813 | } else { |
| 814 | // parsing iface |
developer | 4c2edbe | 2022-10-18 16:36:37 +0800 | [diff] [blame] | 815 | if (strcmp(op->e.name, "device") == 0){ |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 816 | set_radionum(&intf_param, op->v.string); |
developer | 9567a46 | 2022-11-17 20:42:05 +0800 | [diff] [blame] | 817 | }else if (strcmp(op->e.name, "mode") == 0){ |
developer | b97b549 | 2022-12-22 19:44:36 +0800 | [diff] [blame] | 818 | 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] | 819 | if (strncmp(op->v.string, "sta", 3) == 0) { |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 820 | intf_param.sta_mode = TRUE; |
| 821 | intf_param.sta_index = intf_param.radio_index + staCount[intf_param.radio_index]*max_radio_num; |
| 822 | staCount[intf_param.radio_index] ++ ; |
| 823 | fprintf(stderr, "\n----- Start parsing sta %d config. -----\n", intf_param.sta_index); |
developer | 9567a46 | 2022-11-17 20:42:05 +0800 | [diff] [blame] | 824 | } else if (strncmp(op->v.string, "ap", 2) == 0) { |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 825 | intf_param.sta_mode = FALSE; |
| 826 | intf_param.ap_index = intf_param.radio_index + apCount[intf_param.radio_index]*max_radio_num; |
| 827 | apCount[intf_param.radio_index] ++ ; |
| 828 | fprintf(stderr, "\n----- Start parsing ap %d config. -----\n", intf_param.ap_index); |
developer | 9567a46 | 2022-11-17 20:42:05 +0800 | [diff] [blame] | 829 | } |
developer | 4c2edbe | 2022-10-18 16:36:37 +0800 | [diff] [blame] | 830 | }else if (strcmp(op->e.name, "ssid") == 0){ |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 831 | set_ssid(&intf_param, op->v.string); |
developer | 4c2edbe | 2022-10-18 16:36:37 +0800 | [diff] [blame] | 832 | }else if (strcmp(op->e.name, "encryption") == 0){ |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 833 | set_encryption(&intf_param, op->v.string); |
developer | 4c2edbe | 2022-10-18 16:36:37 +0800 | [diff] [blame] | 834 | }else if (strcmp(op->e.name, "key") == 0){ |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 835 | set_key(&intf_param, op->v.string); |
developer | 2bcdef9 | 2022-12-13 16:19:09 +0800 | [diff] [blame] | 836 | }else if (strcmp(op->e.name, "ifname") == 0){ |
| 837 | set_ifname(&intf_param, op->v.string); |
developer | b3f0066 | 2022-12-29 09:35:55 +0800 | [diff] [blame] | 838 | }else if (strcmp(op->e.name, "wds") == 0){ |
| 839 | set_wds(&intf_param, op->v.string); |
developer | c454873 | 2023-02-06 20:02:10 +0800 | [diff] [blame] | 840 | }else if (strcmp(op->e.name, "hidden") == 0){ |
| 841 | set_hidden(&intf_param, op->v.string); |
developer | 223f598 | 2023-02-28 15:59:38 +0800 | [diff] [blame] | 842 | }else if (strcmp(op->e.name, "igmpsn_enable") == 0){ |
| 843 | set_igmpsn_enable(&intf_param, op->v.string); |
| 844 | }else if (strcmp(op->e.name, "wps_state") == 0){ |
| 845 | set_wps_state(&intf_param, op->v.string); |
developer | 223f598 | 2023-02-28 15:59:38 +0800 | [diff] [blame] | 846 | }else if (strcmp(op->e.name, "macfilter") == 0){ |
| 847 | set_macfilter(&intf_param, op->v.string); |
| 848 | }else if (strcmp(op->e.name, "maclist") == 0){ |
| 849 | set_maclist(&intf_param, op->v.string); |
developer | 4c2edbe | 2022-10-18 16:36:37 +0800 | [diff] [blame] | 850 | }else{ |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 851 | fprintf(stderr, "[%s %s not set!]\n", op->e.name, op->v.string); |
developer | 223f598 | 2023-02-28 15:59:38 +0800 | [diff] [blame] | 852 | } |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 853 | } |
| 854 | } |
developer | 5f8ef5c | 2023-02-22 15:49:20 +0800 | [diff] [blame] | 855 | if (parsing_radio == TRUE) { |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 856 | set_radio_param(radio_param); |
developer | 5f8ef5c | 2023-02-22 15:49:20 +0800 | [diff] [blame] | 857 | } |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 858 | else if (intf_param.sta_mode == TRUE) |
| 859 | set_sta_param(intf_param); |
developer | 5f8ef5c | 2023-02-22 15:49:20 +0800 | [diff] [blame] | 860 | else { |
developer | 1ac0e89 | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 861 | set_ap_param(intf_param, &vap_map[intf_param.radio_index]); |
developer | 5f8ef5c | 2023-02-22 15:49:20 +0800 | [diff] [blame] | 862 | vap_map[intf_param.radio_index].num_vaps++; |
| 863 | } |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 864 | } |
developer | 5f8ef5c | 2023-02-22 15:49:20 +0800 | [diff] [blame] | 865 | |
| 866 | /* disable all interface, re-enable by UCI configuration */ |
| 867 | |
| 868 | fprintf(stderr, "\n----- Disable all interfaces. -----\n"); |
| 869 | |
| 870 | for (i = 0; i < max_radio_num; i++ ){ |
developer | 0148a3d | 2023-03-08 09:29:34 +0800 | [diff] [blame] | 871 | for(j = max_radio_num*(MAX_NUM_VAP_PER_RADIO-1) + i; j >= 0; j -= max_radio_num) { |
| 872 | ret = wifi_setApEnable(j, FALSE); |
developer | 5f8ef5c | 2023-02-22 15:49:20 +0800 | [diff] [blame] | 873 | if (ret != RETURN_OK) |
developer | 0148a3d | 2023-03-08 09:29:34 +0800 | [diff] [blame] | 874 | fprintf(stderr, "[disable ap %d failed!!!]\n", j); |
| 875 | else |
| 876 | fprintf(stderr, "[disable ap %d success.]\n", j); |
developer | 5f8ef5c | 2023-02-22 15:49:20 +0800 | [diff] [blame] | 877 | } |
| 878 | } |
developer | 9567a46 | 2022-11-17 20:42:05 +0800 | [diff] [blame] | 879 | fprintf(stderr, "\n----- Start setting Vaps. -----\n"); |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 880 | |
developer | 5f8ef5c | 2023-02-22 15:49:20 +0800 | [diff] [blame] | 881 | for (i = 0; i < max_radio_num ;i++ ){ |
| 882 | |
| 883 | fprintf(stderr, "\n create Vap radio:%d num_vaps=%d.\n", i, vap_map[i].num_vaps); |
developer | 41965b5 | 2022-10-19 17:40:23 +0800 | [diff] [blame] | 884 | ret = wifi_createVAP(i, &vap_map[i]); |
| 885 | if (ret != RETURN_OK) |
| 886 | fprintf(stderr, "[Apply vap setting failed!!!]\n"); |
| 887 | } |
developer | 223f598 | 2023-02-28 15:59:38 +0800 | [diff] [blame] | 888 | |
developer | 0dff3a9 | 2023-03-17 15:08:42 +0800 | [diff] [blame] | 889 | for (i = 0; i < 3 ;i++ ){ |
| 890 | apCount[i] = 0; |
| 891 | staCount[i] = 0; |
| 892 | } |
| 893 | |
| 894 | uci_foreach_element(&uci_pkg->sections, e) { |
| 895 | |
| 896 | struct uci_section *s = uci_to_section(e); |
| 897 | struct uci_element *option = NULL; |
| 898 | wifi_radio_param radio_param = {0}; |
| 899 | wifi_intf_param intf_param = {0}; |
| 900 | int phyId = 0; |
| 901 | radio_param.radio_index = -1; |
| 902 | intf_param.ap_index = -1; |
| 903 | |
| 904 | if (strcmp(s->type, "wifi-iface") == 0) { |
| 905 | uci_foreach_element(&s->options, option) { |
| 906 | |
| 907 | struct uci_option *op = uci_to_option(option); |
| 908 | { |
| 909 | // parsing iface |
| 910 | if (strcmp(op->e.name, "device") == 0){ |
| 911 | set_radionum(&intf_param, op->v.string); |
| 912 | }else if (strcmp(op->e.name, "mode") == 0){ |
| 913 | intf_param.mac_offset = staCount[intf_param.radio_index] + apCount[intf_param.radio_index]; |
| 914 | if (strncmp(op->v.string, "sta", 3) == 0) { |
| 915 | intf_param.sta_mode = TRUE; |
| 916 | intf_param.sta_index = intf_param.radio_index + staCount[intf_param.radio_index]*max_radio_num; |
| 917 | staCount[intf_param.radio_index] ++ ; |
| 918 | fprintf(stderr, "\n----- Start parsing sta %d config. -----\n", intf_param.sta_index); |
| 919 | } else if (strncmp(op->v.string, "ap", 2) == 0) { |
| 920 | intf_param.sta_mode = FALSE; |
| 921 | intf_param.ap_index = intf_param.radio_index + apCount[intf_param.radio_index]*max_radio_num; |
| 922 | apCount[intf_param.radio_index] ++ ; |
| 923 | fprintf(stderr, "\n----- Start parsing ap %d config. -----\n", intf_param.ap_index); |
| 924 | } |
| 925 | }else if (strcmp(op->e.name, "wps_cancel") == 0){ |
| 926 | set_wps_cancel(&intf_param, op->v.string); |
| 927 | }else if (strcmp(op->e.name, "wps_pushbutton") == 0){ |
| 928 | set_wps_pushbutton(&intf_param, op->v.string); |
| 929 | } |
| 930 | } |
| 931 | } |
| 932 | |
| 933 | // wps_cancel |
| 934 | fprintf(stderr, "Set wps_cancel: %d \n", intf_param.wps_cancel); |
| 935 | if (intf_param.wps_cancel){ |
| 936 | ret = wifi_cancelApWPS(intf_param.ap_index); |
| 937 | if (ret != RETURN_OK) |
| 938 | fprintf(stderr, "[Set wps_cancel failed!!!]\n"); |
| 939 | ret = 0; |
| 940 | } |
| 941 | |
| 942 | // wps_pushbutton |
| 943 | fprintf(stderr, "Set wps_pushbutton: %d \n", intf_param.wps_pushbutton); |
| 944 | if (intf_param.wps_pushbutton){ |
| 945 | ret = wifi_setApWpsButtonPush(intf_param.ap_index); |
| 946 | if (ret != RETURN_OK) |
| 947 | fprintf(stderr, "[Set wps_pushbutton failed!!!]\n"); |
| 948 | ret = 0; |
| 949 | } |
| 950 | } |
| 951 | } |
| 952 | |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 953 | uci_unload(uci_ctx, uci_pkg); |
| 954 | uci_free_context(uci_ctx); |
| 955 | return RETURN_OK; |
| 956 | } |
| 957 | |
developer | 223f598 | 2023-02-28 15:59:38 +0800 | [diff] [blame] | 958 | int dump_wifi_status () |
| 959 | { |
| 960 | |
| 961 | struct uci_context *uci_ctx = uci_alloc_context(); |
| 962 | struct uci_package *uci_pkg = NULL; |
| 963 | struct uci_element *e; |
| 964 | // struct uci_section *s; |
| 965 | const char cfg_name[] = "wireless"; |
| 966 | int max_radio_num = 0; |
| 967 | BOOL parsing_radio = FALSE; |
| 968 | int apCount[3] = {0}; |
| 969 | int staCount[3] = {0}; |
| 970 | wifi_vap_info_map_t vap_map[3] = {0}; |
| 971 | int ret = 0; |
| 972 | int i = 0; |
| 973 | |
| 974 | wifi_getMaxRadioNumber(&max_radio_num); |
| 975 | fprintf(stderr, "max radio number: %d\n", max_radio_num); |
| 976 | for (i = 0; i < max_radio_num ;i++ ){ |
| 977 | ret = wifi_getRadioVapInfoMap(i, &vap_map[i]); |
| 978 | if (ret != RETURN_OK) { // if failed, we set assume this vap as the first vap. |
| 979 | fprintf(stderr, "[Get vap map failed!!!]\n"); |
| 980 | vap_map[i].num_vaps = MAX_NUM_VAP_PER_RADIO; |
| 981 | } |
| 982 | } |
| 983 | if (uci_load(uci_ctx, cfg_name, &uci_pkg) != UCI_OK) { |
| 984 | uci_free_context(uci_ctx); |
| 985 | fprintf(stderr, "%s: load uci failed.\n", __func__); |
| 986 | return RETURN_ERR; |
| 987 | } |
| 988 | |
| 989 | uci_foreach_element(&uci_pkg->sections, e) { |
| 990 | |
| 991 | struct uci_section *s = uci_to_section(e); |
| 992 | struct uci_element *option = NULL; |
| 993 | wifi_radio_param radio_param = {0}; |
| 994 | wifi_intf_param intf_param = {0}; |
| 995 | int phyId = 0; |
| 996 | radio_param.radio_index = -1; |
| 997 | intf_param.ap_index = -1; |
| 998 | |
| 999 | if (strcmp(s->type, "wifi-device") == 0) { |
| 1000 | sscanf(s->e.name, "radio%d", &phyId); |
| 1001 | radio_param.radio_index = phy_index_to_radio(phyId); |
| 1002 | parsing_radio = TRUE; |
| 1003 | fprintf(stderr, "\n----- Start show radio %d config. -----\n", radio_param.radio_index); |
| 1004 | } else if (strcmp(s->type, "wifi-iface") == 0) { |
| 1005 | parsing_radio = FALSE; |
| 1006 | } |
| 1007 | |
| 1008 | uci_foreach_element(&s->options, option) { |
| 1009 | |
| 1010 | struct uci_option *op = uci_to_option(option); |
| 1011 | if (parsing_radio == TRUE) { |
| 1012 | // transform the type from input string and store the value in radio_param. |
| 1013 | } else { |
| 1014 | // parsing iface |
| 1015 | if (strcmp(op->e.name, "device") == 0){ |
| 1016 | set_radionum(&intf_param, op->v.string); |
| 1017 | }else if (strcmp(op->e.name, "mode") == 0){ |
| 1018 | intf_param.mac_offset = staCount[intf_param.radio_index] + apCount[intf_param.radio_index]; |
| 1019 | if (strncmp(op->v.string, "sta", 3) == 0) { |
| 1020 | intf_param.sta_mode = TRUE; |
| 1021 | intf_param.sta_index = intf_param.radio_index + staCount[intf_param.radio_index]*max_radio_num; |
| 1022 | staCount[intf_param.radio_index] ++ ; |
| 1023 | fprintf(stderr, "\n----- Start show sta %d config. -----\n", intf_param.sta_index); |
| 1024 | } else if (strncmp(op->v.string, "ap", 2) == 0) { |
| 1025 | intf_param.sta_mode = FALSE; |
| 1026 | intf_param.ap_index = intf_param.radio_index + apCount[intf_param.radio_index]*max_radio_num; |
| 1027 | apCount[intf_param.radio_index] ++ ; |
| 1028 | fprintf(stderr, "\n----- Start show ap %d config. -----\n", intf_param.ap_index); |
| 1029 | } |
| 1030 | } |
| 1031 | } |
| 1032 | } |
| 1033 | if (parsing_radio == TRUE) |
| 1034 | printf("show radio params: \n"); |
| 1035 | // show_radio_param(radio_param); |
| 1036 | else if (intf_param.sta_mode == TRUE) |
| 1037 | printf("show sta params: \n"); |
| 1038 | // show_sta_param(intf_param); |
| 1039 | else{ |
| 1040 | printf("show ap params: \n"); |
| 1041 | show_ap_param(intf_param, &vap_map[intf_param.radio_index]); |
| 1042 | } |
| 1043 | } |
| 1044 | |
| 1045 | uci_unload(uci_ctx, uci_pkg); |
| 1046 | uci_free_context(uci_ctx); |
| 1047 | return RETURN_OK; |
| 1048 | |
| 1049 | } |
| 1050 | |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 1051 | int main(int argc, char **argv) |
| 1052 | { |
developer | 223f598 | 2023-02-28 15:59:38 +0800 | [diff] [blame] | 1053 | if (argc != 2 || (strcmp(argv[1], "reload") != 0 && strcmp(argv[1], "dump") != 0) ){ |
| 1054 | 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] | 1055 | return -1; |
| 1056 | } |
developer | 223f598 | 2023-02-28 15:59:38 +0800 | [diff] [blame] | 1057 | if (strcmp(argv[1], "reload") == 0) |
| 1058 | apply_uci_config(); |
| 1059 | else if (strcmp(argv[1], "dump") == 0) |
| 1060 | dump_wifi_status(); |
developer | 402bf2a | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 1061 | return 0; |
| 1062 | } |