developer | 91f8074 | 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 | 5061483 | 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 | 8d8d630 | 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 | c6a2732 | 2023-01-13 15:23:06 +0800 | [diff] [blame] | 69 | return radioIndex; |
developer | 8d8d630 | 2022-10-18 16:36:37 +0800 | [diff] [blame] | 70 | } |
| 71 | |
developer | 91f8074 | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 72 | void set_channel(wifi_radio_param *radio_param, char *channel) |
| 73 | { |
developer | 63d7277 | 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 | 91f8074 | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 78 | radio_param->auto_channel = FALSE; |
developer | 63d7277 | 2022-10-07 09:42:31 +0800 | [diff] [blame] | 79 | radio_param->channel = strtol(channel, NULL, 10); |
developer | 91f8074 | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 80 | } |
developer | 63d7277 | 2022-10-07 09:42:31 +0800 | [diff] [blame] | 81 | return; |
developer | 91f8074 | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 82 | } |
| 83 | |
developer | 52c6ca2 | 2022-10-06 17:16:43 +0800 | [diff] [blame] | 84 | void set_country(wifi_radio_param *radio_param, char *country) |
developer | 91f8074 | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 85 | { |
| 86 | strcpy(radio_param->country, country); |
| 87 | } |
| 88 | |
developer | 52c6ca2 | 2022-10-06 17:16:43 +0800 | [diff] [blame] | 89 | void set_band(wifi_radio_param *radio_param, char *band) |
developer | 91f8074 | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 90 | { |
| 91 | strcpy(radio_param->band, band); |
| 92 | } |
| 93 | |
developer | 6feac68 | 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 | 91f8074 | 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 | 128f8aa | 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 | 13ec735 | 2023-02-06 20:02:10 +0800 | [diff] [blame] | 168 | void set_htcoex(wifi_radio_param *radio_param, char *ht_coex) |
| 169 | { |
| 170 | radio_param->ht_coex = strtol(ht_coex, NULL, 10); |
| 171 | } |
| 172 | |
| 173 | void set_rts(wifi_radio_param *radio_param, char *rts) |
| 174 | { |
| 175 | radio_param->rtsThreshold = strtol(rts, NULL, 10); |
| 176 | } |
| 177 | |
developer | 465ca0c | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 178 | void set_radionum(wifi_intf_param *intf_param, char *phy_name) |
developer | 91f8074 | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 179 | { |
developer | 5061483 | 2022-11-17 20:42:05 +0800 | [diff] [blame] | 180 | int radio_num = 0; |
| 181 | char *ptr = phy_name; |
developer | 8d8d630 | 2022-10-18 16:36:37 +0800 | [diff] [blame] | 182 | int phyId = 0; |
developer | 91f8074 | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 183 | |
| 184 | while (*ptr) { |
| 185 | if (isdigit(*ptr)) { |
developer | 5061483 | 2022-11-17 20:42:05 +0800 | [diff] [blame] | 186 | phyId = strtoul(ptr, NULL, 10); |
| 187 | radio_num = phy_index_to_radio(phyId); |
developer | 465ca0c | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 188 | intf_param->radio_index = radio_num; |
developer | 91f8074 | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 189 | break; |
| 190 | } |
| 191 | ptr++; |
| 192 | } |
| 193 | } |
| 194 | |
developer | 465ca0c | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 195 | void set_ssid(wifi_intf_param *intf_param, char *ssid) |
developer | 91f8074 | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 196 | { |
developer | 465ca0c | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 197 | strncpy(intf_param->ssid, ssid, 32); |
developer | 91f8074 | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 198 | } |
| 199 | |
developer | 465ca0c | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 200 | void set_encryption(wifi_intf_param *intf_param, char *encryption_mode) |
developer | 91f8074 | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 201 | { |
developer | ff378f2 | 2022-10-13 13:33:57 +0800 | [diff] [blame] | 202 | if (strcmp(encryption_mode, "none") == 0) { |
developer | 465ca0c | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 203 | intf_param->security.mode = wifi_security_mode_none; |
| 204 | intf_param->security.encr = wifi_encryption_none; |
developer | ff378f2 | 2022-10-13 13:33:57 +0800 | [diff] [blame] | 205 | }else if(strncmp(encryption_mode, "psk2", 4) == 0){ |
developer | 465ca0c | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 206 | intf_param->security.mode = wifi_security_mode_wpa2_personal; |
developer | ff378f2 | 2022-10-13 13:33:57 +0800 | [diff] [blame] | 207 | }else if(strncmp(encryption_mode, "psk-",4) == 0){ |
developer | 465ca0c | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 208 | intf_param->security.mode = wifi_security_mode_wpa_wpa2_personal; |
developer | ff378f2 | 2022-10-13 13:33:57 +0800 | [diff] [blame] | 209 | }else if(strncmp(encryption_mode, "psk",3) == 0){ |
developer | 465ca0c | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 210 | intf_param->security.mode = wifi_security_mode_wpa_personal; |
developer | ff378f2 | 2022-10-13 13:33:57 +0800 | [diff] [blame] | 211 | }else if(strncmp(encryption_mode, "wpa2",4) == 0){ |
developer | 465ca0c | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 212 | intf_param->security.mode = wifi_security_mode_wpa2_enterprise; |
developer | ff378f2 | 2022-10-13 13:33:57 +0800 | [diff] [blame] | 213 | }else if(strncmp(encryption_mode, "wpa-",4) == 0){ |
developer | 465ca0c | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 214 | intf_param->security.mode = wifi_security_mode_wpa_wpa2_enterprise; |
developer | ff378f2 | 2022-10-13 13:33:57 +0800 | [diff] [blame] | 215 | }else if(strcmp(encryption_mode, "sae") == 0){ |
developer | 465ca0c | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 216 | intf_param->security.mode = wifi_security_mode_wpa3_personal; |
developer | ff378f2 | 2022-10-13 13:33:57 +0800 | [diff] [blame] | 217 | }else if(strcmp(encryption_mode, "wpa3") == 0){ |
developer | 465ca0c | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 218 | intf_param->security.mode = wifi_security_mode_wpa3_enterprise; |
developer | ff378f2 | 2022-10-13 13:33:57 +0800 | [diff] [blame] | 219 | }else if(strcmp(encryption_mode, "sae-mixed") == 0){ |
developer | 465ca0c | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 220 | intf_param->security.mode = wifi_security_mode_wpa3_transition; |
developer | c6a2732 | 2023-01-13 15:23:06 +0800 | [diff] [blame] | 221 | }else if(strcmp(encryption_mode, "owe") == 0){ |
| 222 | intf_param->security.mode = wifi_security_mode_owe; |
developer | 91f8074 | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 223 | } |
| 224 | |
developer | ff378f2 | 2022-10-13 13:33:57 +0800 | [diff] [blame] | 225 | if(strstr(encryption_mode, "tkip") && (strstr(encryption_mode, "ccmp") || strstr(encryption_mode, "aes") )){ |
developer | 465ca0c | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 226 | intf_param->security.encr = wifi_encryption_aes_tkip; |
developer | ff378f2 | 2022-10-13 13:33:57 +0800 | [diff] [blame] | 227 | }else if (strstr(encryption_mode, "tkip")){ |
developer | 465ca0c | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 228 | intf_param->security.encr = wifi_encryption_tkip; |
developer | ff378f2 | 2022-10-13 13:33:57 +0800 | [diff] [blame] | 229 | }else{ |
developer | 465ca0c | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 230 | intf_param->security.encr = wifi_encryption_aes; |
developer | 91f8074 | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 231 | } |
developer | ff378f2 | 2022-10-13 13:33:57 +0800 | [diff] [blame] | 232 | |
developer | c6a2732 | 2023-01-13 15:23:06 +0800 | [diff] [blame] | 233 | if(!strcmp(encryption_mode, "wpa3") || !strcmp(encryption_mode, "sae") || !strcmp(encryption_mode, "owe")){ |
developer | 465ca0c | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 234 | intf_param->security.mfp = wifi_mfp_cfg_required; |
developer | ff378f2 | 2022-10-13 13:33:57 +0800 | [diff] [blame] | 235 | }else if (!strcmp(encryption_mode, "sae-mixed")){ |
developer | 465ca0c | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 236 | intf_param->security.mfp = wifi_mfp_cfg_optional; |
developer | ff378f2 | 2022-10-13 13:33:57 +0800 | [diff] [blame] | 237 | }else{ |
developer | 465ca0c | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 238 | intf_param->security.mfp = wifi_mfp_cfg_disabled; |
developer | ff378f2 | 2022-10-13 13:33:57 +0800 | [diff] [blame] | 239 | } |
developer | 91f8074 | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 240 | } |
| 241 | |
developer | 465ca0c | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 242 | void set_key(wifi_intf_param *intf_param, char *key) |
developer | 91f8074 | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 243 | { |
developer | 465ca0c | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 244 | strncpy(intf_param->security.u.key.key, key, 64); |
developer | 91f8074 | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 245 | } |
| 246 | |
developer | 7ac3bd5 | 2022-12-13 16:19:09 +0800 | [diff] [blame] | 247 | void set_ifname(wifi_intf_param *intf_param, char *ifname) |
| 248 | { |
| 249 | if (strlen(ifname) > 15) |
| 250 | return; |
| 251 | strncpy(intf_param->ifname, ifname, strlen(ifname) + 1); |
| 252 | } |
| 253 | |
developer | b212378 | 2022-12-29 09:35:55 +0800 | [diff] [blame] | 254 | void set_wds(wifi_intf_param *intf_param, char *wds_enable) |
| 255 | { |
| 256 | intf_param->wds_mode = FALSE; |
| 257 | if (strncmp(wds_enable, "1", 1) == 0) |
| 258 | intf_param->wds_mode = TRUE; |
| 259 | } |
| 260 | |
developer | 13ec735 | 2023-02-06 20:02:10 +0800 | [diff] [blame] | 261 | void set_hidden(wifi_intf_param *intf_param, char *hidden) |
| 262 | { |
| 263 | intf_param->hidden = strtol(hidden, NULL, 10); |
| 264 | } |
| 265 | |
developer | 5061483 | 2022-11-17 20:42:05 +0800 | [diff] [blame] | 266 | int set_interface_bssid(int phy_index, int offset, mac_address_t *bssid) |
developer | f7e50b0 | 2022-10-14 10:07:58 +0800 | [diff] [blame] | 267 | { |
| 268 | FILE *f; |
| 269 | char mac_file[64] = {0}; |
| 270 | char mac_address[20] = {0}; |
developer | f7e50b0 | 2022-10-14 10:07:58 +0800 | [diff] [blame] | 271 | |
developer | 1ac426a | 2022-12-22 19:44:36 +0800 | [diff] [blame] | 272 | sprintf(mac_file, "/sys/class/ieee80211/phy%d/macaddress", phy_index); |
developer | f7e50b0 | 2022-10-14 10:07:58 +0800 | [diff] [blame] | 273 | f = fopen(mac_file, "r"); |
| 274 | if (f == NULL) |
| 275 | return -1; |
| 276 | fgets(mac_address, 20, f); |
| 277 | fclose(f); |
| 278 | |
developer | 5061483 | 2022-11-17 20:42:05 +0800 | [diff] [blame] | 279 | mac_addr_aton(&(*bssid)[0], mac_address); |
| 280 | (*bssid)[0] += offset*2; |
developer | f7e50b0 | 2022-10-14 10:07:58 +0800 | [diff] [blame] | 281 | return 0; |
| 282 | } |
| 283 | |
developer | 91f8074 | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 284 | void set_radio_param(wifi_radio_param radio_parameter) |
| 285 | { |
developer | 91f8074 | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 286 | int ret = 0; |
developer | 63d7277 | 2022-10-07 09:42:31 +0800 | [diff] [blame] | 287 | wifi_radio_operationParam_t operationParam = {0}; |
| 288 | |
developer | 8d8d630 | 2022-10-18 16:36:37 +0800 | [diff] [blame] | 289 | if(radio_parameter.radio_index == -1) |
| 290 | return; |
| 291 | |
developer | 63d7277 | 2022-10-07 09:42:31 +0800 | [diff] [blame] | 292 | if (radio_parameter.disabled == TRUE) { |
| 293 | wifi_setRadioEnable(radio_parameter.radio_index, FALSE); |
| 294 | return; |
| 295 | } |
developer | 91f8074 | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 296 | |
| 297 | fprintf(stderr, "Start setting radio\n"); |
developer | bf81293 | 2022-10-17 17:37:29 +0800 | [diff] [blame] | 298 | |
developer | 128f8aa | 2022-12-26 17:09:00 +0800 | [diff] [blame] | 299 | if (radio_parameter.txantenna != 0 && radio_parameter.txantenna == radio_parameter.rxantenna) { |
| 300 | ret = wifi_setRadioTxChainMask(radio_parameter.radio_index, radio_parameter.txantenna); |
| 301 | if (ret != RETURN_OK) |
| 302 | fprintf(stderr, "[Set Tx Chain mask failed!!!]\n"); |
| 303 | } |
| 304 | |
developer | bf81293 | 2022-10-17 17:37:29 +0800 | [diff] [blame] | 305 | // Get current radio setting |
developer | 63d7277 | 2022-10-07 09:42:31 +0800 | [diff] [blame] | 306 | ret = wifi_getRadioOperatingParameters(radio_parameter.radio_index, &operationParam); |
| 307 | if (ret != RETURN_OK) |
| 308 | fprintf(stderr, "[Get OperatingParameters failed!!!]\n"); |
developer | bf81293 | 2022-10-17 17:37:29 +0800 | [diff] [blame] | 309 | operationParam.enable = TRUE; |
developer | 91f8074 | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 310 | |
developer | 91f8074 | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 311 | // Channel |
developer | 63d7277 | 2022-10-07 09:42:31 +0800 | [diff] [blame] | 312 | operationParam.autoChannelEnabled = radio_parameter.auto_channel; |
| 313 | operationParam.channel = radio_parameter.channel; |
developer | 91f8074 | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 314 | |
developer | 25e0781 | 2022-10-13 15:27:02 +0800 | [diff] [blame] | 315 | //bandwidth |
| 316 | if (radio_parameter.bandwidth == 20){ |
| 317 | operationParam.channelWidth = WIFI_CHANNELBANDWIDTH_20MHZ; |
| 318 | }else if (radio_parameter.bandwidth == 40){ |
| 319 | operationParam.channelWidth = WIFI_CHANNELBANDWIDTH_40MHZ; |
| 320 | }else if (radio_parameter.bandwidth == 80){ |
| 321 | operationParam.channelWidth = WIFI_CHANNELBANDWIDTH_80MHZ; |
| 322 | }else if (radio_parameter.bandwidth == 160){ |
| 323 | operationParam.channelWidth = WIFI_CHANNELBANDWIDTH_160MHZ; |
| 324 | } |
developer | 91f8074 | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 325 | |
| 326 | // htmode |
developer | 63d7277 | 2022-10-07 09:42:31 +0800 | [diff] [blame] | 327 | unsigned int mode = 0; // enum wifi_ieee80211Variant_t |
developer | 91f8074 | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 328 | if (strcmp(radio_parameter.band, "2g") == 0) { |
developer | 63d7277 | 2022-10-07 09:42:31 +0800 | [diff] [blame] | 329 | mode |= WIFI_80211_VARIANT_B | WIFI_80211_VARIANT_G; |
developer | 91f8074 | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 330 | if (strcmp(radio_parameter.htmode, "NOHT") == 0 || strcmp(radio_parameter.htmode, "NONE") == 0) |
| 331 | strcpy(radio_parameter.htmode, "11G"); |
| 332 | |
developer | 63d7277 | 2022-10-07 09:42:31 +0800 | [diff] [blame] | 333 | if (strstr(radio_parameter.htmode, "HE") != NULL) |
| 334 | mode |= WIFI_80211_VARIANT_N | WIFI_80211_VARIANT_AX; |
developer | 91f8074 | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 335 | |
developer | 63d7277 | 2022-10-07 09:42:31 +0800 | [diff] [blame] | 336 | } else if (strcmp(radio_parameter.band, "5g") == 0) { |
| 337 | mode |= WIFI_80211_VARIANT_A; |
developer | 91f8074 | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 338 | if (strcmp(radio_parameter.htmode, "NOHT") == 0 || strcmp(radio_parameter.htmode, "NONE") == 0) |
| 339 | strcpy(radio_parameter.htmode, "11A"); |
developer | 63d7277 | 2022-10-07 09:42:31 +0800 | [diff] [blame] | 340 | |
| 341 | if (strstr(radio_parameter.htmode, "HE") != NULL) |
| 342 | mode |= WIFI_80211_VARIANT_N | WIFI_80211_VARIANT_AC | WIFI_80211_VARIANT_AX; |
developer | 8d8d630 | 2022-10-18 16:36:37 +0800 | [diff] [blame] | 343 | }else if (strcmp(radio_parameter.band, "6g") == 0) { |
| 344 | mode |= WIFI_80211_VARIANT_A | WIFI_80211_VARIANT_N | WIFI_80211_VARIANT_AC | WIFI_80211_VARIANT_AX;; |
| 345 | } |
developer | 91f8074 | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 346 | |
| 347 | if (strstr(radio_parameter.htmode, "VHT") != NULL) |
developer | 63d7277 | 2022-10-07 09:42:31 +0800 | [diff] [blame] | 348 | mode |= WIFI_80211_VARIANT_N | WIFI_80211_VARIANT_AC; |
developer | 91f8074 | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 349 | else if (strstr(radio_parameter.htmode, "HT") != NULL && strstr(radio_parameter.htmode, "NO") == NULL) |
developer | 63d7277 | 2022-10-07 09:42:31 +0800 | [diff] [blame] | 350 | mode |= WIFI_80211_VARIANT_N; |
developer | 91f8074 | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 351 | |
developer | 63d7277 | 2022-10-07 09:42:31 +0800 | [diff] [blame] | 352 | operationParam.variant = mode; |
developer | 91f8074 | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 353 | |
developer | 13ec735 | 2023-02-06 20:02:10 +0800 | [diff] [blame] | 354 | // rtsThreshold, zero means not set |
| 355 | if ((radio_parameter.rtsThreshold < 65535) && radio_parameter.rtsThreshold) |
| 356 | operationParam.rtsThreshold = radio_parameter.rtsThreshold; |
| 357 | |
| 358 | //ht_coex |
| 359 | operationParam.obssCoex = radio_parameter.ht_coex; |
| 360 | |
developer | 63d7277 | 2022-10-07 09:42:31 +0800 | [diff] [blame] | 361 | // apply setting |
| 362 | ret = wifi_setRadioOperatingParameters(radio_parameter.radio_index, &operationParam); |
developer | 91f8074 | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 363 | if (ret != RETURN_OK) |
developer | 63d7277 | 2022-10-07 09:42:31 +0800 | [diff] [blame] | 364 | fprintf(stderr, "[Apply setting failed!!!]\n"); |
developer | 91f8074 | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 365 | |
developer | bb58a93 | 2022-11-07 16:58:17 +0800 | [diff] [blame] | 366 | // Country |
| 367 | fprintf(stderr, "Set Country: %s\n", radio_parameter.country); |
| 368 | ret = wifi_setRadioCountryCode(radio_parameter.radio_index, radio_parameter.country); |
| 369 | if (ret != RETURN_OK) |
| 370 | fprintf(stderr, "[Set Country failed!!!]\n"); |
| 371 | ret = 0; |
| 372 | |
| 373 | // hwmode |
| 374 | fprintf(stderr, "Set hwmode: %s\n", radio_parameter.hwmode); |
| 375 | ret = wifi_setRadioHwMode(radio_parameter.radio_index, radio_parameter.hwmode); |
| 376 | if (ret != RETURN_OK) |
| 377 | fprintf(stderr, "[Set hwmode failed!!!]\n"); |
| 378 | ret = 0; |
| 379 | |
| 380 | // noscan |
| 381 | fprintf(stderr, "Set noscan: %s \n", radio_parameter.noscan); |
| 382 | if(strlen(radio_parameter.noscan)){ |
| 383 | ret = wifi_setNoscan(radio_parameter.radio_index, radio_parameter.noscan); |
| 384 | if (ret != RETURN_OK) |
| 385 | fprintf(stderr, "[Set noscan failed!!!]\n"); |
| 386 | } |
| 387 | ret = 0; |
| 388 | |
developer | 91f8074 | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 389 | } |
| 390 | |
developer | 465ca0c | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 391 | void set_ap_param(wifi_intf_param ap_param , wifi_vap_info_map_t *map) |
developer | 91f8074 | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 392 | { |
| 393 | int ret = 0; |
developer | 63d7277 | 2022-10-07 09:42:31 +0800 | [diff] [blame] | 394 | int vap_index_in_map = 0; |
developer | 5061483 | 2022-11-17 20:42:05 +0800 | [diff] [blame] | 395 | int phy_index = 0; |
developer | baf6126 | 2023-02-17 15:52:18 +0800 | [diff] [blame^] | 396 | int key_len = 0; |
developer | 63d7277 | 2022-10-07 09:42:31 +0800 | [diff] [blame] | 397 | wifi_vap_info_t vap_info = {0}; |
developer | bf81293 | 2022-10-17 17:37:29 +0800 | [diff] [blame] | 398 | BOOL radio_enable = FALSE; |
| 399 | |
developer | ff42a30 | 2022-10-19 17:40:23 +0800 | [diff] [blame] | 400 | if(ap_param.radio_index == -1) |
| 401 | return; |
| 402 | |
developer | bf81293 | 2022-10-17 17:37:29 +0800 | [diff] [blame] | 403 | wifi_getRadioEnable(ap_param.radio_index, &radio_enable); |
| 404 | if (radio_enable == FALSE) |
| 405 | return; |
developer | 63d7277 | 2022-10-07 09:42:31 +0800 | [diff] [blame] | 406 | |
developer | ff42a30 | 2022-10-19 17:40:23 +0800 | [diff] [blame] | 407 | |
| 408 | // get the index of the map |
| 409 | for (int i = 0; i < map->num_vaps; i++) { |
| 410 | if (map->vap_array[i].vap_index == ap_param.ap_index) { |
| 411 | vap_index_in_map = i; |
| 412 | break; |
developer | 63d7277 | 2022-10-07 09:42:31 +0800 | [diff] [blame] | 413 | } |
| 414 | } |
| 415 | |
developer | ff42a30 | 2022-10-19 17:40:23 +0800 | [diff] [blame] | 416 | |
developer | f7e50b0 | 2022-10-14 10:07:58 +0800 | [diff] [blame] | 417 | fprintf(stderr, "Start setting ap\n"); |
| 418 | |
developer | ff42a30 | 2022-10-19 17:40:23 +0800 | [diff] [blame] | 419 | vap_info = map->vap_array[vap_index_in_map]; |
developer | f7e50b0 | 2022-10-14 10:07:58 +0800 | [diff] [blame] | 420 | vap_info.u.bss_info.enabled = TRUE; |
developer | 5061483 | 2022-11-17 20:42:05 +0800 | [diff] [blame] | 421 | phy_index = radio_index_to_phy(vap_info.radio_index); |
| 422 | if (set_interface_bssid(phy_index, ap_param.mac_offset, &vap_info.u.bss_info.bssid) == -1) { |
developer | f7e50b0 | 2022-10-14 10:07:58 +0800 | [diff] [blame] | 423 | fprintf(stderr, "Get mac address failed.\n"); |
developer | 5061483 | 2022-11-17 20:42:05 +0800 | [diff] [blame] | 424 | return; |
developer | f7e50b0 | 2022-10-14 10:07:58 +0800 | [diff] [blame] | 425 | } |
developer | 91f8074 | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 426 | |
developer | 91f8074 | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 427 | // SSID |
developer | 63d7277 | 2022-10-07 09:42:31 +0800 | [diff] [blame] | 428 | strncpy(vap_info.u.bss_info.ssid, ap_param.ssid, 33); |
| 429 | vap_info.u.bss_info.ssid[32] = '\0'; |
developer | 91f8074 | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 430 | |
developer | 7ac3bd5 | 2022-12-13 16:19:09 +0800 | [diff] [blame] | 431 | // interface |
| 432 | if (strlen(ap_param.ifname) != 0) { |
| 433 | strncpy(vap_info.vap_name, ap_param.ifname, 16); |
| 434 | vap_info.vap_name[15] = "\0"; |
| 435 | } |
| 436 | |
developer | baf6126 | 2023-02-17 15:52:18 +0800 | [diff] [blame^] | 437 | // Security |
| 438 | if (ap_param.security.mode == wifi_security_mode_wpa3_personal || ap_param.security.mode == wifi_security_mode_wpa3_transition){ |
| 439 | // OpenWrt script only set psk, here we choose to set both psk and sae. |
| 440 | ap_param.security.u.key.type = wifi_security_key_type_psk_sae; |
| 441 | } else { |
| 442 | key_len = strlen(ap_param.security.u.key.key); |
| 443 | if (key_len == 64) |
| 444 | ap_param.security.u.key.type = wifi_security_key_type_psk; |
| 445 | else if (key_len >= 8 && key_len < 64) |
| 446 | ap_param.security.u.key.type = wifi_security_key_type_pass; |
| 447 | } |
| 448 | |
developer | ff378f2 | 2022-10-13 13:33:57 +0800 | [diff] [blame] | 449 | vap_info.u.bss_info.security.mode = ap_param.security.mode; |
| 450 | vap_info.u.bss_info.security.encr = ap_param.security.encr; |
| 451 | vap_info.u.bss_info.security.mfp = ap_param.security.mfp; |
| 452 | vap_info.u.bss_info.security.u.key.type = ap_param.security.u.key.type; |
| 453 | strncpy(vap_info.u.bss_info.security.u.key.key, ap_param.security.u.key.key, 64); |
developer | 13ec735 | 2023-02-06 20:02:10 +0800 | [diff] [blame] | 454 | |
| 455 | // hidden |
| 456 | vap_info.u.bss_info.showSsid = (ap_param.hidden ? 0 : 1); |
developer | 8d8d630 | 2022-10-18 16:36:37 +0800 | [diff] [blame] | 457 | |
developer | 63d7277 | 2022-10-07 09:42:31 +0800 | [diff] [blame] | 458 | // Replace the setting with uci config |
developer | ff42a30 | 2022-10-19 17:40:23 +0800 | [diff] [blame] | 459 | map->vap_array[vap_index_in_map] = vap_info; |
developer | 91f8074 | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 460 | } |
| 461 | |
developer | 465ca0c | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 462 | void set_sta_param(wifi_intf_param sta_param) |
developer | 5061483 | 2022-11-17 20:42:05 +0800 | [diff] [blame] | 463 | { |
| 464 | wifi_sta_network_t *sta = NULL; |
| 465 | mac_address_t sta_mac = {0}; |
| 466 | char sta_mac_str[20] = {0}; |
| 467 | char key_mgmt[16] = {0}; |
| 468 | char pairwise[16] = {0}; |
| 469 | int phy_index = 0; |
| 470 | |
| 471 | sta = calloc(1, sizeof(wifi_sta_network_t)); |
| 472 | |
| 473 | phy_index = radio_index_to_phy(sta_param.radio_index); |
| 474 | set_interface_bssid(phy_index, sta_param.mac_offset, &sta_mac); |
| 475 | mac_addr_ntoa(sta_mac_str, sta_mac); |
| 476 | snprintf(sta->ssid, 31, "%s", sta_param.ssid); |
| 477 | sta->ssid[31] = '\0'; |
| 478 | snprintf(sta->psk, 64, "%s", sta_param.password); |
| 479 | |
| 480 | if (sta_param.security.mode == wifi_security_mode_none) |
| 481 | strcpy(key_mgmt, "NONE"); |
| 482 | else if (sta_param.security.mode == wifi_security_mode_wpa3_personal) |
| 483 | strcpy(key_mgmt, "SAE"); |
developer | c6a2732 | 2023-01-13 15:23:06 +0800 | [diff] [blame] | 484 | else if (sta_param.security.mode == wifi_security_mode_owe) |
| 485 | strcpy(key_mgmt, "OWE"); |
developer | 5061483 | 2022-11-17 20:42:05 +0800 | [diff] [blame] | 486 | else |
| 487 | strcpy(key_mgmt, "WPA-PSK"); |
| 488 | snprintf(sta->key_mgmt, 64, "%s", key_mgmt); |
| 489 | |
| 490 | if (sta_param.security.encr == wifi_encryption_aes) |
| 491 | strcpy(pairwise, "CCMP"); |
| 492 | else if (sta_param.security.encr == wifi_encryption_tkip) |
| 493 | strcpy(pairwise, "TKIP"); |
| 494 | else |
| 495 | strcpy(pairwise, "CCMP TKIP"); |
| 496 | snprintf(sta->pairwise, 64, "%s", pairwise); |
| 497 | |
| 498 | if (strlen(sta_param.security.u.key.key) > 0) |
| 499 | strncpy(sta->psk, sta_param.security.u.key.key, 127); |
| 500 | sta->psk[127] = '\0'; |
| 501 | sta->psk_len = strlen(sta->psk); |
| 502 | |
developer | b212378 | 2022-12-29 09:35:55 +0800 | [diff] [blame] | 503 | if (sta_param.wds_mode == TRUE) |
| 504 | sta->flags |= WIFI_STA_NET_F_4ADDR_MULTI_AP; |
| 505 | |
| 506 | wifi_createSTAInterface(sta_param.sta_index, sta_mac_str, sta_param.wds_mode); |
developer | 5061483 | 2022-11-17 20:42:05 +0800 | [diff] [blame] | 507 | |
| 508 | if (wifi_setSTANetworks(sta_param.sta_index, &sta, 1, FALSE) == RETURN_ERR) { |
| 509 | fprintf(stderr, "Write to sta %d config file failed\n", sta_param.sta_index); |
| 510 | free(sta); |
| 511 | return; |
| 512 | } |
| 513 | free(sta); |
| 514 | |
| 515 | if (wifi_setSTAEnabled(sta_param.sta_index, TRUE) == RETURN_ERR) { |
| 516 | fprintf(stderr, "Enable station failed\n"); |
| 517 | return; |
| 518 | } |
| 519 | } |
| 520 | |
developer | 91f8074 | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 521 | int apply_uci_config () |
| 522 | { |
| 523 | struct uci_context *uci_ctx = uci_alloc_context(); |
| 524 | struct uci_package *uci_pkg = NULL; |
| 525 | struct uci_element *e; |
| 526 | // struct uci_section *s; |
| 527 | const char cfg_name[] = "wireless"; |
| 528 | int max_radio_num = 0; |
| 529 | BOOL parsing_radio = FALSE; |
developer | 8d8d630 | 2022-10-18 16:36:37 +0800 | [diff] [blame] | 530 | int apCount[3] = {0}; |
developer | 5061483 | 2022-11-17 20:42:05 +0800 | [diff] [blame] | 531 | int staCount[3] = {0}; |
developer | ff42a30 | 2022-10-19 17:40:23 +0800 | [diff] [blame] | 532 | wifi_vap_info_map_t vap_map[3] = {0}; |
| 533 | int ret = 0; |
| 534 | int i = 0; |
developer | 91f8074 | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 535 | |
| 536 | wifi_getMaxRadioNumber(&max_radio_num); |
| 537 | fprintf(stderr, "max radio number: %d\n", max_radio_num); |
developer | ff42a30 | 2022-10-19 17:40:23 +0800 | [diff] [blame] | 538 | for (i = 0; i < max_radio_num ;i++ ){ |
| 539 | ret = wifi_getRadioVapInfoMap(i, &vap_map[i]); |
| 540 | if (ret != RETURN_OK) { // if failed, we set assume this vap as the first vap. |
| 541 | fprintf(stderr, "[Get vap map failed!!!]\n"); |
| 542 | vap_map[i].num_vaps = MAX_NUM_VAP_PER_RADIO; |
| 543 | } |
| 544 | } |
developer | 91f8074 | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 545 | if (uci_load(uci_ctx, cfg_name, &uci_pkg) != UCI_OK) { |
| 546 | uci_free_context(uci_ctx); |
| 547 | fprintf(stderr, "%s: load uci failed.\n", __func__); |
| 548 | return RETURN_ERR; |
| 549 | } |
| 550 | |
| 551 | uci_foreach_element(&uci_pkg->sections, e) { |
| 552 | |
| 553 | struct uci_section *s = uci_to_section(e); |
| 554 | struct uci_element *option = NULL; |
| 555 | wifi_radio_param radio_param = {0}; |
developer | 465ca0c | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 556 | wifi_intf_param intf_param = {0}; |
developer | 8d8d630 | 2022-10-18 16:36:37 +0800 | [diff] [blame] | 557 | int phyId = 0; |
developer | 91f8074 | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 558 | radio_param.radio_index = -1; |
developer | 465ca0c | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 559 | intf_param.ap_index = -1; |
developer | 91f8074 | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 560 | |
| 561 | if (strcmp(s->type, "wifi-device") == 0) { |
developer | 8d8d630 | 2022-10-18 16:36:37 +0800 | [diff] [blame] | 562 | sscanf(s->e.name, "radio%d", &phyId); |
| 563 | radio_param.radio_index = phy_index_to_radio(phyId); |
developer | 91f8074 | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 564 | parsing_radio = TRUE; |
| 565 | fprintf(stderr, "\n----- Start parsing radio %d config. -----\n", radio_param.radio_index); |
| 566 | } else if (strcmp(s->type, "wifi-iface") == 0) { |
developer | 91f8074 | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 567 | parsing_radio = FALSE; |
developer | 91f8074 | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 568 | } |
| 569 | |
| 570 | uci_foreach_element(&s->options, option) { |
| 571 | |
| 572 | struct uci_option *op = uci_to_option(option); |
| 573 | if (parsing_radio == TRUE) { |
| 574 | // transform the type from input string and store the value in radio_param. |
| 575 | if (strcmp(op->e.name, "channel") == 0) |
| 576 | set_channel(&radio_param, op->v.string); |
| 577 | else if (strcmp(op->e.name, "hwmode") == 0) |
| 578 | set_hwmode(&radio_param, op->v.string); |
| 579 | else if (strcmp(op->e.name, "htmode") == 0) |
| 580 | set_htmode(&radio_param, op->v.string); |
| 581 | else if (strcmp(op->e.name, "disabled") == 0) |
| 582 | set_disable(&radio_param, op->v.string); |
| 583 | else if (strcmp(op->e.name, "band") == 0) |
| 584 | set_band(&radio_param, op->v.string); |
| 585 | else if (strcmp(op->e.name, "country") == 0) |
| 586 | set_country(&radio_param, op->v.string); |
| 587 | else if (strcmp(op->e.name, "noscan") == 0) |
developer | 6feac68 | 2022-10-18 17:44:13 +0800 | [diff] [blame] | 588 | set_noscan(&radio_param, op->v.string); |
developer | 128f8aa | 2022-12-26 17:09:00 +0800 | [diff] [blame] | 589 | else if (strcmp(op->e.name, "rxantenna") == 0) |
| 590 | set_rxant(&radio_param, op->v.string); |
| 591 | else if (strcmp(op->e.name, "txantenna") == 0) |
| 592 | set_txant(&radio_param, op->v.string); |
developer | 13ec735 | 2023-02-06 20:02:10 +0800 | [diff] [blame] | 593 | else if (strcmp(op->e.name, "ht_coex") == 0) |
| 594 | set_htcoex(&radio_param, op->v.string); |
| 595 | else if (strcmp(op->e.name, "rts") == 0) |
| 596 | set_rts(&radio_param, op->v.string); |
developer | 91f8074 | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 597 | else |
| 598 | fprintf(stderr, "[%s %s not set!]\n", op->e.name, op->v.string); |
| 599 | } else { |
| 600 | // parsing iface |
developer | 8d8d630 | 2022-10-18 16:36:37 +0800 | [diff] [blame] | 601 | if (strcmp(op->e.name, "device") == 0){ |
developer | 465ca0c | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 602 | set_radionum(&intf_param, op->v.string); |
developer | 5061483 | 2022-11-17 20:42:05 +0800 | [diff] [blame] | 603 | }else if (strcmp(op->e.name, "mode") == 0){ |
developer | 1ac426a | 2022-12-22 19:44:36 +0800 | [diff] [blame] | 604 | intf_param.mac_offset = staCount[intf_param.radio_index] + apCount[intf_param.radio_index]; |
developer | 5061483 | 2022-11-17 20:42:05 +0800 | [diff] [blame] | 605 | if (strncmp(op->v.string, "sta", 3) == 0) { |
developer | 465ca0c | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 606 | intf_param.sta_mode = TRUE; |
| 607 | intf_param.sta_index = intf_param.radio_index + staCount[intf_param.radio_index]*max_radio_num; |
| 608 | staCount[intf_param.radio_index] ++ ; |
| 609 | fprintf(stderr, "\n----- Start parsing sta %d config. -----\n", intf_param.sta_index); |
developer | 5061483 | 2022-11-17 20:42:05 +0800 | [diff] [blame] | 610 | } else if (strncmp(op->v.string, "ap", 2) == 0) { |
developer | 465ca0c | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 611 | intf_param.sta_mode = FALSE; |
| 612 | intf_param.ap_index = intf_param.radio_index + apCount[intf_param.radio_index]*max_radio_num; |
| 613 | apCount[intf_param.radio_index] ++ ; |
| 614 | fprintf(stderr, "\n----- Start parsing ap %d config. -----\n", intf_param.ap_index); |
developer | 5061483 | 2022-11-17 20:42:05 +0800 | [diff] [blame] | 615 | } |
developer | 8d8d630 | 2022-10-18 16:36:37 +0800 | [diff] [blame] | 616 | }else if (strcmp(op->e.name, "ssid") == 0){ |
developer | 465ca0c | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 617 | set_ssid(&intf_param, op->v.string); |
developer | 8d8d630 | 2022-10-18 16:36:37 +0800 | [diff] [blame] | 618 | }else if (strcmp(op->e.name, "encryption") == 0){ |
developer | 465ca0c | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 619 | set_encryption(&intf_param, op->v.string); |
developer | 8d8d630 | 2022-10-18 16:36:37 +0800 | [diff] [blame] | 620 | }else if (strcmp(op->e.name, "key") == 0){ |
developer | 465ca0c | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 621 | set_key(&intf_param, op->v.string); |
developer | 7ac3bd5 | 2022-12-13 16:19:09 +0800 | [diff] [blame] | 622 | }else if (strcmp(op->e.name, "ifname") == 0){ |
| 623 | set_ifname(&intf_param, op->v.string); |
developer | b212378 | 2022-12-29 09:35:55 +0800 | [diff] [blame] | 624 | }else if (strcmp(op->e.name, "wds") == 0){ |
| 625 | set_wds(&intf_param, op->v.string); |
developer | 13ec735 | 2023-02-06 20:02:10 +0800 | [diff] [blame] | 626 | }else if (strcmp(op->e.name, "hidden") == 0){ |
| 627 | set_hidden(&intf_param, op->v.string); |
developer | 8d8d630 | 2022-10-18 16:36:37 +0800 | [diff] [blame] | 628 | }else{ |
developer | 91f8074 | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 629 | fprintf(stderr, "[%s %s not set!]\n", op->e.name, op->v.string); |
developer | 8d8d630 | 2022-10-18 16:36:37 +0800 | [diff] [blame] | 630 | } |
developer | 91f8074 | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 631 | } |
| 632 | } |
| 633 | if (parsing_radio == TRUE) |
| 634 | set_radio_param(radio_param); |
developer | 465ca0c | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 635 | else if (intf_param.sta_mode == TRUE) |
| 636 | set_sta_param(intf_param); |
developer | 91f8074 | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 637 | else |
developer | 465ca0c | 2022-11-25 14:30:05 +0800 | [diff] [blame] | 638 | set_ap_param(intf_param, &vap_map[intf_param.radio_index]); |
developer | 91f8074 | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 639 | } |
developer | 5061483 | 2022-11-17 20:42:05 +0800 | [diff] [blame] | 640 | fprintf(stderr, "\n----- Start setting Vaps. -----\n"); |
developer | 91f8074 | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 641 | |
developer | ff42a30 | 2022-10-19 17:40:23 +0800 | [diff] [blame] | 642 | for (i = 0; i < max_radio_num ;i++ ){ |
| 643 | ret = wifi_createVAP(i, &vap_map[i]); |
| 644 | if (ret != RETURN_OK) |
| 645 | fprintf(stderr, "[Apply vap setting failed!!!]\n"); |
| 646 | } |
| 647 | |
developer | 91f8074 | 2022-10-04 15:20:18 +0800 | [diff] [blame] | 648 | uci_unload(uci_ctx, uci_pkg); |
| 649 | uci_free_context(uci_ctx); |
| 650 | return RETURN_OK; |
| 651 | } |
| 652 | |
| 653 | int main(int argc, char **argv) |
| 654 | { |
| 655 | if (argc != 2 || strcmp(argv[1], "reload") != 0) { |
| 656 | fprintf(stderr, "Usage: wifi reload.\nThis tool is only for RDKB MSP/SQC test.\n"); |
| 657 | return -1; |
| 658 | } |
| 659 | apply_uci_config(); |
| 660 | return 0; |
| 661 | } |