Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Sigma Control API DUT (station/AP) |
| 3 | * Copyright (c) 2010-2011, Atheros Communications, Inc. |
| 4 | * Copyright (c) 2011-2015, Qualcomm Atheros, Inc. |
| 5 | * All Rights Reserved. |
| 6 | * Licensed under the Clear BSD license. See README for more details. |
| 7 | */ |
| 8 | |
| 9 | #include "sigma_dut.h" |
| 10 | #include <sys/stat.h> |
| 11 | #include <sys/wait.h> |
| 12 | #include <sys/utsname.h> |
| 13 | #include <sys/ioctl.h> |
| 14 | #ifdef __linux__ |
| 15 | #include <dirent.h> |
| 16 | #include <string.h> |
| 17 | #include <sys/types.h> |
| 18 | #include <unistd.h> |
| 19 | #endif /* __linux__ */ |
| 20 | #ifdef __QNXNTO__ |
| 21 | #include <ifaddrs.h> |
| 22 | #include <net/if_dl.h> |
| 23 | #endif /* __QNXNTO__ */ |
| 24 | #include "wpa_helpers.h" |
| 25 | #ifdef ANDROID |
| 26 | #include <hardware_legacy/wifi.h> |
Pradeep Reddy POTTETI | a076c30 | 2016-05-16 13:36:07 +0530 | [diff] [blame] | 27 | #include <private/android_filesystem_config.h> |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 28 | #endif /* ANDROID */ |
| 29 | |
| 30 | /* Temporary files for ap_send_addba_req */ |
| 31 | #define VI_QOS_TMP_FILE "/tmp/vi-qos.tmp" |
| 32 | #define VI_QOS_FILE "/tmp/vi-qos.txt" |
| 33 | #define VI_QOS_REFFILE "/etc/vi-qos.txt" |
| 34 | |
| 35 | /* Configuration file name on Android */ |
| 36 | #ifndef ANDROID_CONFIG_FILE |
| 37 | #define ANDROID_CONFIG_FILE "/data/misc/wifi/hostapd.conf" |
| 38 | #endif /* ANDROID_CONFIG_FILE */ |
| 39 | /* Maximum length of the line in the configuration file */ |
| 40 | #define MAX_CONF_LINE_LEN (156) |
| 41 | |
| 42 | /* The following is taken from Hotspot 2.0 testplan Appendix B.1 */ |
| 43 | #define ANQP_VENUE_NAME_1 "02019c0002083d656e6757692d466920416c6c69616e63650a3239383920436f7070657220526f61640a53616e746120436c6172612c2043412039353035312c205553415b63686957692d4669e88194e79b9fe5ae9ee9aa8ce5aea40ae4ba8ce4b99de585abe4b99de5b9b4e5ba93e69f8fe8b7af0ae59ca3e5858be68b89e68b892c20e58aa0e588a9e7a68fe5b0bce4ba9a39353035312c20e7be8ee59bbd" |
| 44 | #define ANQP_VENUE_NAME_1_CHI "P\"\x63\x68\x69\x3a\x57\x69\x2d\x46\x69\xe8\x81\x94\xe7\x9b\x9f\xe5\xae\x9e\xe9\xaa\x8c\xe5\xae\xa4\\n\xe4\xba\x8c\xe4\xb9\x9d\xe5\x85\xab\xe4\xb9\x9d\xe5\xb9\xb4\xe5\xba\x93\xe6\x9f\x8f\xe8\xb7\xaf\\n\xe5\x9c\xa3\xe5\x85\x8b\xe6\x8b\x89\xe6\x8b\x89\x2c\x20\xe5\x8a\xa0\xe5\x88\xa9\xe7\xa6\x8f\xe5\xb0\xbc\xe4\xba\x9a\x39\x35\x30\x35\x31\x2c\x20\xe7\xbe\x8e\xe5\x9b\xbd\"" |
| 45 | #define ANQP_IP_ADDR_TYPE_1 "060101000c" |
| 46 | #define ANQP_HS20_OPERATOR_FRIENDLY_NAME_1 "dddd2700506f9a11030011656e6757692d466920416c6c69616e63650e63686957692d4669e88194e79b9f" |
| 47 | #define ANQP_HS20_WAN_METRICS_1 "dddd1300506f9a11040001c40900008001000000000000" |
| 48 | #define ANQP_HS20_CONNECTION_CAPABILITY_1 "dddd3200506f9a1105000100000006140001061600000650000106bb010106bb060006c4130011f4010111c413001194110132000001" |
| 49 | #define QOS_MAP_SET_1 "53,2,22,6,8,15,0,7,255,255,16,31,32,39,255,255,40,47,255,255" |
| 50 | #define QOS_MAP_SET_2 "8,15,0,7,255,255,16,31,32,39,255,255,40,47,48,63" |
| 51 | |
| 52 | extern char *sigma_main_ifname; |
| 53 | extern char *sigma_wpas_ctrl; |
| 54 | extern char *sigma_hapd_ctrl; |
| 55 | extern char *ap_inet_addr; |
| 56 | extern char *ap_inet_mask; |
| 57 | extern char *sigma_radio_ifname[]; |
| 58 | |
| 59 | static int cmd_ap_config_commit(struct sigma_dut *dut, struct sigma_conn *conn, |
| 60 | struct sigma_cmd *cmd); |
| 61 | static int ath_ap_start_hostapd(struct sigma_dut *dut); |
| 62 | static void ath_ap_set_params(struct sigma_dut *dut); |
| 63 | static int kill_process(struct sigma_dut *dut, char *proc_name, |
| 64 | unsigned char is_proc_instance_one, int sig); |
| 65 | |
| 66 | |
| 67 | static int cmd_ap_ca_version(struct sigma_dut *dut, struct sigma_conn *conn, |
| 68 | struct sigma_cmd *cmd) |
| 69 | { |
| 70 | /* const char *name = get_param(cmd, "NAME"); */ |
| 71 | send_resp(dut, conn, SIGMA_COMPLETE, "version,1.0"); |
| 72 | return 0; |
| 73 | } |
| 74 | |
| 75 | |
| 76 | static int get_hwaddr(const char *ifname, unsigned char *hwaddr) |
| 77 | { |
| 78 | #ifndef __QNXNTO__ |
| 79 | struct ifreq ifr; |
| 80 | int s; |
| 81 | |
| 82 | s = socket(AF_INET, SOCK_DGRAM, 0); |
| 83 | if (s < 0) |
| 84 | return -1; |
| 85 | memset(&ifr, 0, sizeof(ifr)); |
| 86 | strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); |
| 87 | if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) { |
| 88 | perror("ioctl"); |
| 89 | close(s); |
| 90 | return -1; |
| 91 | } |
| 92 | close(s); |
| 93 | memcpy(hwaddr, ifr.ifr_hwaddr.sa_data, 6); |
| 94 | #else /* __QNXNTO__ */ |
| 95 | struct ifaddrs *ifaddrshead = NULL; |
| 96 | int found = 0; |
| 97 | struct ifaddrs *temp_ifap = NULL; |
| 98 | struct sockaddr_dl *sdl = NULL; |
| 99 | |
| 100 | if (getifaddrs(&ifaddrshead) != 0) { |
| 101 | perror("getifaddrs failed"); |
| 102 | return -1; |
| 103 | } |
| 104 | |
| 105 | for (temp_ifap = ifaddrshead; ifaddrshead && !found; |
| 106 | ifaddrshead = ifaddrshead->ifa_next) { |
| 107 | if (ifaddrshead->ifa_addr->sa_family == AF_LINK && |
| 108 | strcmp(ifaddrshead->ifa_name, ifname) == 0) { |
| 109 | found = 1; |
| 110 | sdl = (struct sockaddr_dl *) ifaddrshead->ifa_addr; |
| 111 | if (sdl) |
| 112 | memcpy(hwaddr, LLADDR(sdl), sdl->sdl_alen); |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | if (temp_ifap) |
| 117 | freeifaddrs(temp_ifap); |
| 118 | |
| 119 | if (!found) { |
| 120 | perror("Failed to get the interface"); |
| 121 | return -1; |
| 122 | } |
| 123 | #endif /* __QNXNTO__ */ |
| 124 | return 0; |
| 125 | } |
| 126 | |
| 127 | |
| 128 | static void ath_ap_set_group_id(struct sigma_dut *dut, const char *ifname, |
| 129 | const char *val) |
| 130 | { |
| 131 | char buf[60]; |
| 132 | |
| 133 | snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 55 %d", |
| 134 | ifname, atoi(val)); |
| 135 | if (system(buf) != 0) { |
| 136 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 137 | "wifitool ap_group_id failed"); |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | |
| 142 | void ath_set_cts_width(struct sigma_dut *dut, const char *ifname, |
| 143 | const char *val) |
| 144 | { |
| 145 | char buf[60]; |
| 146 | |
| 147 | /* TODO: Enable support for other values */ |
| 148 | if (strcasecmp(val, "40") == 0) { |
| 149 | snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 54 1", |
| 150 | ifname); |
| 151 | if (system(buf) != 0) { |
| 152 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 153 | "wifitool cts_width failed"); |
| 154 | } |
Priyadharshini Gowthaman | 818afef | 2015-11-09 13:28:15 -0800 | [diff] [blame] | 155 | snprintf(buf, sizeof(buf), |
| 156 | "athdiag --set --address=0x10024 --val=0xd90b8a14"); |
| 157 | if (system(buf) != 0) { |
| 158 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 159 | "disabling phy restart failed"); |
| 160 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 161 | } else { |
| 162 | sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported CTS_WIDTH"); |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | |
Priyadharshini Gowthaman | 818afef | 2015-11-09 13:28:15 -0800 | [diff] [blame] | 167 | void ath_config_dyn_bw_sig(struct sigma_dut *dut, const char *ifname, |
| 168 | const char *val) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 169 | { |
| 170 | char buf[60]; |
| 171 | |
| 172 | if (strcasecmp(val, "enable") == 0) { |
| 173 | dut->ap_dyn_bw_sig = AP_DYN_BW_SGNL_ENABLED; |
| 174 | snprintf(buf, sizeof(buf), "iwpriv %s cwmenable 1", ifname); |
| 175 | if (system(buf) != 0) { |
| 176 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 177 | "iwpriv cwmenable 1 failed"); |
| 178 | } |
Priyadharshini Gowthaman | 818afef | 2015-11-09 13:28:15 -0800 | [diff] [blame] | 179 | snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 96 1", |
| 180 | ifname); |
| 181 | if (system(buf) != 0) { |
| 182 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 183 | "disabling RTS from rate control logic failed"); |
| 184 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 185 | } else if (strcasecmp(val, "disable") == 0) { |
| 186 | dut->ap_dyn_bw_sig = AP_DYN_BW_SGNL_DISABLED; |
| 187 | snprintf(buf, sizeof(buf), "iwpriv %s cwmenable 0", ifname); |
| 188 | if (system(buf) != 0) { |
| 189 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 190 | "iwpriv cwmenable 0 failed"); |
| 191 | } |
| 192 | } else { |
| 193 | sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported DYN_BW_SGL"); |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | |
| 198 | static void ath_config_rts_force(struct sigma_dut *dut, const char *ifname, |
| 199 | const char *val) |
| 200 | { |
| 201 | char buf[60]; |
| 202 | |
| 203 | if (strcasecmp(val, "enable") == 0) { |
| 204 | dut->ap_sig_rts = 1; |
| 205 | snprintf(buf, sizeof(buf), "iwconfig %s rts 64", ifname); |
| 206 | if (system(buf) != 0) { |
| 207 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 208 | "iwconfig rts 64 failed"); |
| 209 | } |
priyadharshini gowthaman | 270870e | 2015-12-09 10:10:23 -0800 | [diff] [blame] | 210 | snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 100 1", |
| 211 | ifname); |
| 212 | if (system(buf) != 0) { |
| 213 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 214 | "wifitool beeliner_fw_test 100 1 failed"); |
| 215 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 216 | } else if (strcasecmp(val, "disable") == 0) { |
| 217 | dut->ap_sig_rts = 2; |
| 218 | snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", ifname); |
| 219 | if (system(buf) != 0) { |
| 220 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 221 | "iwpriv rts 2347 failed"); |
| 222 | } |
| 223 | } else { |
| 224 | sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported RTS_FORCE"); |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | |
| 229 | static enum ap_mode get_mode(const char *str) |
| 230 | { |
| 231 | if (strcasecmp(str, "11a") == 0) |
| 232 | return AP_11a; |
| 233 | else if (strcasecmp(str, "11g") == 0) |
| 234 | return AP_11g; |
| 235 | else if (strcasecmp(str, "11b") == 0) |
| 236 | return AP_11b; |
| 237 | else if (strcasecmp(str, "11na") == 0) |
| 238 | return AP_11na; |
| 239 | else if (strcasecmp(str, "11ng") == 0) |
| 240 | return AP_11ng; |
| 241 | else if (strcasecmp(str, "11ac") == 0 || strcasecmp(str, "ac") == 0) |
| 242 | return AP_11ac; |
| 243 | else |
| 244 | return AP_inval; |
| 245 | } |
| 246 | |
| 247 | |
| 248 | static int run_hostapd_cli(struct sigma_dut *dut, char *buf) |
| 249 | { |
| 250 | char command[1000]; |
| 251 | const char *bin; |
| 252 | enum driver_type drv = get_driver_type(); |
| 253 | |
| 254 | if (file_exists("hostapd_cli")) |
| 255 | bin = "./hostapd_cli"; |
| 256 | else |
| 257 | bin = "hostapd_cli"; |
| 258 | |
| 259 | if (drv == DRIVER_OPENWRT && sigma_hapd_ctrl == NULL) { |
| 260 | sigma_hapd_ctrl = "/var/run/hostapd-wifi0"; |
| 261 | |
| 262 | if (sigma_radio_ifname[0] && |
| 263 | strcmp(sigma_radio_ifname[0], "wifi1") == 0) |
| 264 | sigma_hapd_ctrl = "/var/run/hostapd-wifi1"; |
| 265 | else if (sigma_radio_ifname[0] && |
| 266 | strcmp(sigma_radio_ifname[0], "wifi2") == 0) |
| 267 | sigma_hapd_ctrl = "/var/run/hostapd-wifi2"; |
| 268 | } |
| 269 | |
| 270 | if (sigma_hapd_ctrl) |
| 271 | snprintf(command, sizeof(command), "%s -p %s %s", |
| 272 | bin, sigma_hapd_ctrl, buf); |
| 273 | else |
| 274 | snprintf(command, sizeof(command), "%s %s", bin, buf); |
| 275 | return run_system(dut, command); |
| 276 | } |
| 277 | |
| 278 | |
priyadharshini gowthaman | 8e26ff4 | 2016-06-22 22:47:14 -0700 | [diff] [blame] | 279 | static int ath_set_lci_config(struct sigma_dut *dut, const char *val, |
| 280 | struct sigma_cmd *cmd) |
| 281 | { |
| 282 | FILE *f; |
| 283 | int i; |
| 284 | |
| 285 | f = fopen("/tmp/lci_cfg.txt", "w"); |
| 286 | if (!f) { |
| 287 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 288 | "Failed to open /tmp/lci_cfg.txt"); |
| 289 | return -1; |
| 290 | } |
| 291 | |
| 292 | for (i = 2; i < cmd->count; i++) |
| 293 | fprintf(f, "%s = %s \n", cmd->params[i], cmd->values[i]); |
| 294 | fprintf(f, "\n"); |
| 295 | fclose(f); |
| 296 | |
| 297 | return 0; |
| 298 | } |
| 299 | |
| 300 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 301 | static int cmd_ap_set_wireless(struct sigma_dut *dut, struct sigma_conn *conn, |
| 302 | struct sigma_cmd *cmd) |
| 303 | { |
| 304 | /* const char *name = get_param(cmd, "NAME"); */ |
| 305 | /* const char *ifname = get_param(cmd, "INTERFACE"); */ |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 306 | const char *val; |
| 307 | unsigned int wlan_tag = 1; |
| 308 | char *ifname = get_main_ifname(); |
| 309 | |
| 310 | val = get_param(cmd, "WLAN_TAG"); |
| 311 | if (val) { |
| 312 | wlan_tag = atoi(val); |
| 313 | if (wlan_tag != 1 && wlan_tag != 2) { |
| 314 | send_resp(dut, conn, SIGMA_INVALID, |
| 315 | "errorCode,Invalid WLAN_TAG"); |
| 316 | return 0; |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | val = get_param(cmd, "CountryCode"); |
| 321 | if (val) { |
| 322 | if (strlen(val) > sizeof(dut->ap_countrycode) - 1) |
| 323 | return -1; |
| 324 | snprintf(dut->ap_countrycode, sizeof(dut->ap_countrycode), |
| 325 | "%s", val); |
| 326 | } |
| 327 | |
Pradeep Reddy POTTETI | fba27db | 2015-11-20 16:42:22 +0530 | [diff] [blame] | 328 | val = get_param(cmd, "regulatory_mode"); |
| 329 | if (val) { |
| 330 | if (strcasecmp(val, "11d") == 0 || strcasecmp(val, "11h") == 0) |
| 331 | dut->ap_regulatory_mode = AP_80211D_MODE_ENABLED; |
| 332 | } |
| 333 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 334 | val = get_param(cmd, "SSID"); |
| 335 | if (val) { |
| 336 | if (strlen(val) > sizeof(dut->ap_ssid) - 1) |
| 337 | return -1; |
| 338 | |
| 339 | if (wlan_tag == 1) { |
| 340 | snprintf(dut->ap_ssid, |
| 341 | sizeof(dut->ap_ssid), "%s", val); |
| 342 | } else if (wlan_tag == 2) { |
| 343 | snprintf(dut->ap2_ssid, |
| 344 | sizeof(dut->ap2_ssid), "%s", val); |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | val = get_param(cmd, "CHANNEL"); |
| 349 | if (val) { |
| 350 | const char *pos; |
| 351 | dut->ap_channel = atoi(val); |
| 352 | pos = strchr(val, ';'); |
| 353 | if (pos) { |
| 354 | pos++; |
| 355 | dut->ap_channel_1 = atoi(pos); |
| 356 | } |
| 357 | } |
| 358 | |
Pradeep Reddy POTTETI | fba27db | 2015-11-20 16:42:22 +0530 | [diff] [blame] | 359 | /* Overwrite the AP channel with DFS channel if configured */ |
| 360 | val = get_param(cmd, "dfs_chan"); |
| 361 | if (val) { |
| 362 | dut->ap_channel = atoi(val); |
| 363 | } |
| 364 | |
| 365 | val = get_param(cmd, "dfs_mode"); |
| 366 | if (val) { |
| 367 | if (strcasecmp(val, "Enable") == 0) |
| 368 | dut->ap_dfs_mode = AP_DFS_MODE_ENABLED; |
| 369 | else if (strcasecmp(val, "Disable") == 0) |
| 370 | dut->ap_dfs_mode = AP_DFS_MODE_DISABLED; |
| 371 | else |
| 372 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 373 | "Unsupported dfs_mode value: %s", val); |
| 374 | } |
| 375 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 376 | val = get_param(cmd, "MODE"); |
| 377 | if (val) { |
| 378 | char *str, *pos; |
| 379 | |
| 380 | str = strdup(val); |
| 381 | if (str == NULL) |
| 382 | return -1; |
| 383 | pos = strchr(str, ';'); |
| 384 | if (pos) |
| 385 | *pos++ = '\0'; |
| 386 | |
| 387 | dut->ap_is_dual = 0; |
| 388 | dut->ap_mode = get_mode(str); |
| 389 | if (dut->ap_mode == AP_inval) { |
| 390 | send_resp(dut, conn, SIGMA_INVALID, |
| 391 | "errorCode,Unsupported MODE"); |
| 392 | free(str); |
| 393 | return 0; |
| 394 | } |
| 395 | if (dut->ap_mode == AP_11ac) |
| 396 | dut->ap_chwidth = AP_80; |
| 397 | |
| 398 | if (pos) { |
| 399 | dut->ap_mode_1 = get_mode(pos); |
| 400 | if (dut->ap_mode_1 == AP_inval) { |
| 401 | send_resp(dut, conn, SIGMA_INVALID, |
| 402 | "errorCode,Unsupported MODE"); |
| 403 | free(str); |
| 404 | return 0; |
| 405 | } |
| 406 | if (dut->ap_mode_1 == AP_11ac) |
| 407 | dut->ap_chwidth_1 = AP_80; |
| 408 | dut->ap_is_dual = 1; |
| 409 | } |
| 410 | |
| 411 | free(str); |
| 412 | } else if (dut->ap_mode == AP_inval) { |
| 413 | if (dut->ap_channel <= 11) |
| 414 | dut->ap_mode = AP_11ng; |
| 415 | else if (dut->program == PROGRAM_VHT) |
| 416 | dut->ap_mode = AP_11ac; |
| 417 | else |
| 418 | dut->ap_mode = AP_11na; |
| 419 | } |
| 420 | |
Pradeep Reddy POTTETI | 0d3db63 | 2016-03-11 15:21:11 +0530 | [diff] [blame] | 421 | val = get_param(cmd, "WME"); |
| 422 | if (val) { |
| 423 | if (strcasecmp(val, "on") == 0) |
| 424 | dut->ap_wme = AP_WME_ON; |
| 425 | else if (strcasecmp(val, "off") == 0) |
| 426 | dut->ap_wme = AP_WME_OFF; |
| 427 | else |
| 428 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 429 | "Unsupported WME value: %s", val); |
| 430 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 431 | |
| 432 | /* TODO: WMMPS */ |
| 433 | |
| 434 | val = get_param(cmd, "RTS"); |
| 435 | if (val) |
| 436 | dut->ap_rts = atoi(val); |
| 437 | |
| 438 | val = get_param(cmd, "FRGMNT"); |
| 439 | if (val) |
| 440 | dut->ap_frgmnt = atoi(val); |
| 441 | |
| 442 | /* TODO: PWRSAVE */ |
| 443 | |
| 444 | val = get_param(cmd, "BCNINT"); |
| 445 | if (val) |
| 446 | dut->ap_bcnint = atoi(val); |
| 447 | |
| 448 | val = get_param(cmd, "RADIO"); |
| 449 | if (val) { |
| 450 | if (strcasecmp(val, "on") == 0) { |
| 451 | enum driver_type drv = get_driver_type(); |
| 452 | if (drv == DRIVER_ATHEROS) |
| 453 | ath_ap_start_hostapd(dut); |
| 454 | else if (cmd_ap_config_commit(dut, conn, cmd) <= 0) |
| 455 | return 0; |
| 456 | } else if (strcasecmp(val, "off") == 0) { |
| 457 | if (kill_process(dut, "(hostapd)", 1, SIGTERM) == 0 || |
| 458 | system("killall hostapd") == 0) { |
| 459 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 460 | "Killed hostapd on radio,off"); |
| 461 | } |
| 462 | } else { |
| 463 | send_resp(dut, conn, SIGMA_INVALID, |
| 464 | "errorCode,Unsupported RADIO value"); |
| 465 | return 0; |
| 466 | } |
| 467 | } |
| 468 | |
| 469 | val = get_param(cmd, "P2PMgmtBit"); |
| 470 | if (val) |
| 471 | dut->ap_p2p_mgmt = atoi(val); |
| 472 | |
| 473 | /* TODO: ChannelUsage */ |
| 474 | |
| 475 | /* TODO: 40_INTOLERANT */ |
| 476 | |
| 477 | val = get_param(cmd, "ADDBA_REJECT"); |
| 478 | if (val) { |
| 479 | if (strcasecmp(val, "Enable") == 0) |
| 480 | dut->ap_addba_reject = 1; |
| 481 | else if (strcasecmp(val, "Disable") == 0) |
| 482 | dut->ap_addba_reject = 2; |
| 483 | } |
| 484 | |
| 485 | val = get_param(cmd, "AMPDU"); |
| 486 | if (val) { |
| 487 | if (strcasecmp(val, "Enable") == 0) |
| 488 | dut->ap_ampdu = 1; |
| 489 | else if (strcasecmp(val, "Disable") == 0) |
| 490 | dut->ap_ampdu = 2; |
| 491 | } |
| 492 | |
| 493 | val = get_param(cmd, "AMPDU_EXP"); |
| 494 | if (val) |
| 495 | dut->ap_ampdu_exp = atoi(val); |
| 496 | |
| 497 | val = get_param(cmd, "AMSDU"); |
| 498 | if (val) { |
| 499 | if (strcasecmp(val, "Enable") == 0) |
| 500 | dut->ap_amsdu = 1; |
| 501 | else if (strcasecmp(val, "Disable") == 0) |
| 502 | dut->ap_amsdu = 2; |
| 503 | } |
| 504 | |
| 505 | val = get_param(cmd, "NoAck"); |
| 506 | if (val) { |
| 507 | if (strcasecmp(val, "on") == 0) |
| 508 | dut->ap_noack = AP_NOACK_ENABLED; |
| 509 | else if (strcasecmp(val, "off") == 0) |
| 510 | dut->ap_noack = AP_NOACK_DISABLED; |
| 511 | } |
| 512 | |
| 513 | /* TODO: GREENFIELD */ |
| 514 | /* TODO: OFFSET */ |
| 515 | /* TODO: MCS_32 */ |
| 516 | |
| 517 | val = get_param(cmd, "MCS_FIXEDRATE"); |
| 518 | if (val) { |
| 519 | dut->ap_fixed_rate = 1; |
| 520 | dut->ap_mcs = atoi(val); |
| 521 | } |
| 522 | |
| 523 | val = get_param(cmd, "SPATIAL_RX_STREAM"); |
| 524 | if (val) { |
| 525 | if (strcasecmp(val, "1SS") == 0 || strcasecmp(val, "1") == 0) { |
| 526 | dut->ap_rx_streams = 1; |
| 527 | if (dut->device_type == AP_testbed) |
| 528 | dut->ap_vhtmcs_map = 0xfffc; |
| 529 | } else if (strcasecmp(val, "2SS") == 0 || |
| 530 | strcasecmp(val, "2") == 0) { |
| 531 | dut->ap_rx_streams = 2; |
| 532 | if (dut->device_type == AP_testbed) |
| 533 | dut->ap_vhtmcs_map = 0xfff0; |
| 534 | } else if (strcasecmp(val, "3SS") == 0 || |
| 535 | strcasecmp(val, "3") == 0) { |
| 536 | dut->ap_rx_streams = 3; |
| 537 | if (dut->device_type == AP_testbed) |
| 538 | dut->ap_vhtmcs_map = 0xffc0; |
| 539 | } else if (strcasecmp(val, "4SS") == 0 || |
| 540 | strcasecmp(val, "4") == 0) { |
| 541 | dut->ap_rx_streams = 4; |
| 542 | } |
| 543 | } |
| 544 | |
| 545 | val = get_param(cmd, "SPATIAL_TX_STREAM"); |
| 546 | if (val) { |
| 547 | if (strcasecmp(val, "1SS") == 0 || |
| 548 | strcasecmp(val, "1") == 0) { |
| 549 | dut->ap_tx_streams = 1; |
| 550 | if (dut->device_type == AP_testbed) |
| 551 | dut->ap_vhtmcs_map = 0xfffc; |
| 552 | } else if (strcasecmp(val, "2SS") == 0 || |
| 553 | strcasecmp(val, "2") == 0) { |
| 554 | dut->ap_tx_streams = 2; |
| 555 | if (dut->device_type == AP_testbed) |
| 556 | dut->ap_vhtmcs_map = 0xfff0; |
| 557 | } else if (strcasecmp(val, "3SS") == 0 || |
| 558 | strcasecmp(val, "3") == 0) { |
| 559 | dut->ap_tx_streams = 3; |
| 560 | if (dut->device_type == AP_testbed) |
| 561 | dut->ap_vhtmcs_map = 0xffc0; |
| 562 | } else if (strcasecmp(val, "4SS") == 0 || |
| 563 | strcasecmp(val, "4") == 0) { |
| 564 | dut->ap_tx_streams = 4; |
| 565 | } |
| 566 | } |
| 567 | |
| 568 | val = get_param(cmd, "nss_mcs_cap"); |
| 569 | if (val) { |
| 570 | int nss, mcs; |
| 571 | char token[20]; |
| 572 | char *result = NULL; |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 573 | char *saveptr; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 574 | |
| 575 | if (strlen(val) >= sizeof(token)) |
| 576 | return -1; |
| 577 | strcpy(token, val); |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 578 | result = strtok_r(token, ";", &saveptr); |
Pradeep Reddy POTTETI | 41b8c54 | 2016-06-15 16:09:46 +0530 | [diff] [blame] | 579 | if (!result) { |
| 580 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 581 | "VHT NSS not specified"); |
| 582 | return 0; |
| 583 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 584 | nss = atoi(result); |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 585 | result = strtok_r(NULL, ";", &saveptr); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 586 | if (result == NULL) { |
| 587 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 588 | "VHTMCS NOT SPECIFIED!"); |
| 589 | return 0; |
| 590 | } |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 591 | result = strtok_r(result, "-", &saveptr); |
| 592 | result = strtok_r(NULL, "-", &saveptr); |
Pradeep Reddy POTTETI | 41b8c54 | 2016-06-15 16:09:46 +0530 | [diff] [blame] | 593 | if (!result) { |
| 594 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 595 | "VHT MCS not specified"); |
| 596 | return 0; |
| 597 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 598 | mcs = atoi(result); |
| 599 | switch (nss) { |
| 600 | case 1: |
| 601 | switch (mcs) { |
| 602 | case 7: |
| 603 | dut->ap_vhtmcs_map = 0xfffc; |
| 604 | break; |
| 605 | case 8: |
| 606 | dut->ap_vhtmcs_map = 0xfffd; |
| 607 | break; |
| 608 | case 9: |
| 609 | dut->ap_vhtmcs_map = 0xfffe; |
| 610 | break; |
| 611 | default: |
| 612 | dut->ap_vhtmcs_map = 0xfffe; |
| 613 | break; |
| 614 | } |
| 615 | break; |
| 616 | case 2: |
| 617 | switch (mcs) { |
| 618 | case 7: |
| 619 | dut->ap_vhtmcs_map = 0xfff0; |
| 620 | break; |
| 621 | case 8: |
| 622 | dut->ap_vhtmcs_map = 0xfff5; |
| 623 | break; |
| 624 | case 9: |
| 625 | dut->ap_vhtmcs_map = 0xfffa; |
| 626 | break; |
| 627 | default: |
| 628 | dut->ap_vhtmcs_map = 0xfffa; |
| 629 | break; |
| 630 | } |
| 631 | break; |
| 632 | case 3: |
| 633 | switch (mcs) { |
| 634 | case 7: |
| 635 | dut->ap_vhtmcs_map = 0xffc0; |
| 636 | break; |
| 637 | case 8: |
| 638 | dut->ap_vhtmcs_map = 0xffd5; |
| 639 | break; |
| 640 | case 9: |
| 641 | dut->ap_vhtmcs_map = 0xffea; |
| 642 | break; |
| 643 | default: |
| 644 | dut->ap_vhtmcs_map = 0xffea; |
| 645 | break; |
| 646 | } |
| 647 | break; |
| 648 | default: |
| 649 | dut->ap_vhtmcs_map = 0xffea; |
| 650 | break; |
| 651 | } |
| 652 | } |
| 653 | |
| 654 | /* TODO: MPDU_MIN_START_SPACING */ |
| 655 | /* TODO: RIFS_TEST */ |
| 656 | /* TODO: SGI20 */ |
| 657 | |
| 658 | val = get_param(cmd, "STBC_TX"); |
| 659 | if (val) |
| 660 | dut->ap_tx_stbc = atoi(val); |
| 661 | |
| 662 | val = get_param(cmd, "WIDTH"); |
| 663 | if (val) { |
| 664 | if (strcasecmp(val, "20") == 0) |
| 665 | dut->ap_chwidth = AP_20; |
| 666 | else if (strcasecmp(val, "40") == 0) |
| 667 | dut->ap_chwidth = AP_40; |
| 668 | else if (strcasecmp(val, "80") == 0) |
| 669 | dut->ap_chwidth = AP_80; |
| 670 | else if (strcasecmp(val, "160") == 0) |
| 671 | dut->ap_chwidth = AP_160; |
| 672 | else if (strcasecmp(val, "Auto") == 0) |
| 673 | dut->ap_chwidth = AP_AUTO; |
| 674 | else { |
| 675 | send_resp(dut, conn, SIGMA_INVALID, |
| 676 | "errorCode,Unsupported WIDTH"); |
| 677 | return 0; |
| 678 | } |
| 679 | } |
| 680 | |
| 681 | /* TODO: WIDTH_SCAN */ |
| 682 | |
| 683 | val = get_param(cmd, "TDLSProhibit"); |
| 684 | dut->ap_tdls_prohibit = val && strcasecmp(val, "Enabled") == 0; |
| 685 | val = get_param(cmd, "TDLSChswitchProhibit"); |
| 686 | dut->ap_tdls_prohibit_chswitch = |
| 687 | val && strcasecmp(val, "Enabled") == 0; |
| 688 | val = get_param(cmd, "HS2"); |
| 689 | if (val && wlan_tag == 1) |
| 690 | dut->ap_hs2 = atoi(val); |
| 691 | val = get_param(cmd, "P2P_CROSS_CONNECT"); |
| 692 | if (val) |
| 693 | dut->ap_p2p_cross_connect = strcasecmp(val, "Enabled") == 0; |
| 694 | |
| 695 | val = get_param(cmd, "FakePubKey"); |
| 696 | dut->ap_fake_pkhash = val && atoi(val); |
| 697 | |
| 698 | val = get_param(cmd, "vht_tkip"); |
| 699 | dut->ap_allow_vht_tkip = val && strcasecmp(val, "Enable") == 0; |
| 700 | val = get_param(cmd, "vht_wep"); |
| 701 | dut->ap_allow_vht_wep = val && strcasecmp(val, "Enable") == 0; |
| 702 | |
| 703 | val = get_param(cmd, "Protect_mode"); |
| 704 | dut->ap_disable_protection = val && strcasecmp(val, "Disable") == 0; |
| 705 | |
| 706 | val = get_param(cmd, "DYN_BW_SGNL"); |
| 707 | if (val) { |
| 708 | switch (get_driver_type()) { |
| 709 | case DRIVER_OPENWRT: |
| 710 | switch (get_openwrt_driver_type()) { |
| 711 | case OPENWRT_DRIVER_ATHEROS: |
| 712 | ath_config_dyn_bw_sig(dut, ifname, val); |
| 713 | break; |
| 714 | default: |
| 715 | send_resp(dut, conn, SIGMA_ERROR, |
| 716 | "errorCode,Unsupported DYN_BW_SGNL with OpenWrt driver"); |
| 717 | return 0; |
| 718 | } |
| 719 | break; |
| 720 | default: |
| 721 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 722 | "Unsupported DYN_BW_SGL with the current driver"); |
| 723 | break; |
| 724 | } |
| 725 | } |
| 726 | |
| 727 | val = get_param(cmd, "SGI80"); |
| 728 | if (val) { |
| 729 | if (strcasecmp(val, "enable") == 0) |
| 730 | dut->ap_sgi80 = 1; |
| 731 | else if (strcasecmp(val, "disable") == 0) |
| 732 | dut->ap_sgi80 = 0; |
| 733 | else { |
| 734 | send_resp(dut, conn, SIGMA_INVALID, |
| 735 | "errorCode,Unsupported SGI80"); |
| 736 | return 0; |
| 737 | } |
| 738 | } |
| 739 | |
| 740 | val = get_param(cmd, "LDPC"); |
| 741 | if (val) { |
| 742 | if (strcasecmp(val, "enable") == 0) |
| 743 | dut->ap_ldpc = 1; |
| 744 | else if (strcasecmp(val, "disable") == 0) |
| 745 | dut->ap_ldpc = 2; |
| 746 | else { |
| 747 | send_resp(dut, conn, SIGMA_INVALID, |
| 748 | "errorCode,Unsupported LDPC"); |
| 749 | return 0; |
| 750 | } |
| 751 | } |
| 752 | |
| 753 | val = get_param(cmd, "BW_SGNL"); |
| 754 | if (val) { |
| 755 | /* |
| 756 | * With dynamic bandwidth signaling enabled we should see |
| 757 | * RTS if the threshold is met. |
| 758 | */ |
| 759 | if (strcasecmp(val, "enable") == 0) { |
| 760 | dut->ap_sig_rts = 1; |
| 761 | } else if (strcasecmp(val, "disable") == 0) { |
| 762 | dut->ap_sig_rts = 2; |
| 763 | } else { |
| 764 | send_resp(dut, conn, SIGMA_INVALID, |
| 765 | "errorCode,Unsupported BW_SGNL"); |
| 766 | return 0; |
| 767 | } |
| 768 | } |
| 769 | |
| 770 | val = get_param(cmd, "RTS_FORCE"); |
| 771 | if (val) { |
| 772 | switch (get_driver_type()) { |
| 773 | case DRIVER_OPENWRT: |
| 774 | switch (get_openwrt_driver_type()) { |
| 775 | case OPENWRT_DRIVER_ATHEROS: |
| 776 | ath_config_rts_force(dut, ifname, val); |
| 777 | break; |
| 778 | default: |
| 779 | send_resp(dut, conn, SIGMA_ERROR, |
| 780 | "errorCode,Unsupported RTS_FORCE with OpenWrt driver"); |
| 781 | return 0; |
| 782 | } |
| 783 | break; |
| 784 | default: |
| 785 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 786 | "Unsupported RTS_FORCE with the current driver"); |
| 787 | break; |
| 788 | } |
| 789 | } |
| 790 | |
| 791 | val = get_param(cmd, "Zero_crc"); |
| 792 | if (val) { |
| 793 | switch (get_driver_type()) { |
| 794 | case DRIVER_ATHEROS: |
| 795 | ath_set_zero_crc(dut, val); |
| 796 | break; |
| 797 | case DRIVER_OPENWRT: |
| 798 | switch (get_openwrt_driver_type()) { |
| 799 | case OPENWRT_DRIVER_ATHEROS: |
| 800 | ath_set_zero_crc(dut, val); |
| 801 | break; |
| 802 | default: |
| 803 | send_resp(dut, conn, SIGMA_ERROR, |
| 804 | "errorCode,Unsupported zero_crc with the current driver"); |
| 805 | return 0; |
| 806 | } |
| 807 | break; |
| 808 | default: |
| 809 | send_resp(dut, conn, SIGMA_ERROR, |
| 810 | "errorCode,Unsupported zero_crc with the current driver"); |
| 811 | return 0; |
| 812 | } |
| 813 | } |
| 814 | |
| 815 | val = get_param(cmd, "TxBF"); |
| 816 | if (val) |
| 817 | dut->ap_txBF = strcasecmp(val, "enable") == 0; |
| 818 | |
| 819 | val = get_param(cmd, "MU_TxBF"); |
| 820 | if (val) |
| 821 | dut->ap_mu_txBF = strcasecmp(val, "enable") == 0; |
| 822 | |
| 823 | /* UNSUPPORTED: tx_lgi_rate */ |
| 824 | |
| 825 | val = get_param(cmd, "wpsnfc"); |
| 826 | if (val) |
| 827 | dut->ap_wpsnfc = atoi(val); |
| 828 | |
| 829 | val = get_param(cmd, "GROUP_ID"); |
| 830 | if (val) { |
| 831 | switch (get_driver_type()) { |
| 832 | case DRIVER_OPENWRT: |
| 833 | switch (get_openwrt_driver_type()) { |
| 834 | case OPENWRT_DRIVER_ATHEROS: |
| 835 | ath_ap_set_group_id(dut, ifname, val); |
| 836 | break; |
| 837 | default: |
| 838 | send_resp(dut, conn, SIGMA_ERROR, |
| 839 | "errorCode,Unsupported group_id with the current driver"); |
| 840 | return 0; |
| 841 | } |
| 842 | break; |
| 843 | default: |
| 844 | send_resp(dut, conn, SIGMA_ERROR, |
| 845 | "errorCode,Unsupported group_id with the current driver"); |
| 846 | return 0; |
| 847 | } |
| 848 | } |
| 849 | |
| 850 | val = get_param(cmd, "CTS_WIDTH"); |
| 851 | if (val) { |
| 852 | switch (get_driver_type()) { |
| 853 | case DRIVER_OPENWRT: |
| 854 | switch (get_openwrt_driver_type()) { |
| 855 | case OPENWRT_DRIVER_ATHEROS: |
| 856 | ath_set_cts_width(dut, ifname, val); |
| 857 | break; |
| 858 | default: |
| 859 | send_resp(dut, conn, SIGMA_ERROR, |
| 860 | "errorCode,Unsupported cts_width with the current driver"); |
| 861 | return 0; |
| 862 | } |
| 863 | break; |
| 864 | default: |
| 865 | send_resp(dut, conn, SIGMA_ERROR, |
| 866 | "errorCode,Unsupported cts_width with the current driver"); |
| 867 | return 0; |
| 868 | } |
| 869 | } |
| 870 | |
priyadharshini gowthaman | 264d544 | 2016-02-25 15:52:22 -0800 | [diff] [blame] | 871 | val = get_param(cmd, "MU_NDPA_FrameFormat"); |
| 872 | if (val) |
| 873 | dut->ap_ndpa_frame = atoi(val); |
| 874 | |
priyadharshini gowthaman | c52fff8 | 2016-06-22 22:47:14 -0700 | [diff] [blame] | 875 | val = get_param(cmd, "interworking"); |
| 876 | if (val && strcmp(val, "1") == 0) |
| 877 | dut->ap_interworking = 1; |
| 878 | |
| 879 | val = get_param(cmd, "GAS_CB_DELAY"); |
| 880 | if (val) |
| 881 | dut->ap_gas_cb_delay = atoi(val); |
| 882 | |
priyadharshini gowthaman | 8e26ff4 | 2016-06-22 22:47:14 -0700 | [diff] [blame] | 883 | val = get_param(cmd, "LCI"); |
| 884 | if (val) { |
| 885 | if (strlen(val) > sizeof(dut->ap_val_lci) - 1) |
| 886 | return -1; |
| 887 | dut->ap_lci = 1; |
| 888 | snprintf(dut->ap_val_lci, sizeof(dut->ap_val_lci), "%s", val); |
| 889 | ath_set_lci_config(dut, val, cmd); |
| 890 | } |
| 891 | |
priyadharshini gowthaman | c2357bd | 2016-06-22 22:47:14 -0700 | [diff] [blame] | 892 | val = get_param(cmd, "InfoZ"); |
| 893 | if (val) { |
| 894 | if (strlen(val) > sizeof(dut->ap_infoz) - 1) |
| 895 | return -1; |
| 896 | snprintf(dut->ap_infoz, sizeof(dut->ap_infoz), "%s", val); |
| 897 | } |
| 898 | |
priyadharshini gowthaman | 8e26ff4 | 2016-06-22 22:47:14 -0700 | [diff] [blame] | 899 | val = get_param(cmd, "LocCivicAddr"); |
| 900 | if (val) { |
| 901 | if (strlen(val) > sizeof(dut->ap_val_lcr) - 1) |
| 902 | return -1; |
| 903 | dut->ap_lcr = 1; |
| 904 | snprintf(dut->ap_val_lcr, sizeof(dut->ap_val_lcr), "%s", val); |
| 905 | if (dut->ap_lci == 0) |
| 906 | ath_set_lci_config(dut, val, cmd); |
| 907 | } |
| 908 | |
| 909 | val = get_param(cmd, "NeighAPBSSID"); |
| 910 | if (val) { |
| 911 | if (dut->ap_neighap < 3) { |
| 912 | if (parse_mac_address( |
| 913 | dut, val, |
| 914 | dut->ap_val_neighap[dut->ap_neighap]) < 0) { |
| 915 | send_resp(dut, conn, SIGMA_INVALID, |
| 916 | "Failed to parse MAC address"); |
| 917 | return 0; |
| 918 | } |
| 919 | dut->ap_neighap++; |
| 920 | if (dut->ap_lci == 1) |
| 921 | dut->ap_scan = 1; |
| 922 | } |
| 923 | } |
| 924 | |
| 925 | val = get_param(cmd, "OpChannel"); |
| 926 | if (val) { |
| 927 | if (dut->ap_opchannel < 3) { |
| 928 | dut->ap_val_opchannel[dut->ap_opchannel] = atoi(val); |
| 929 | dut->ap_opchannel++; |
| 930 | } |
| 931 | } |
| 932 | |
priyadharshini gowthaman | c2357bd | 2016-06-22 22:47:14 -0700 | [diff] [blame] | 933 | val = get_param(cmd, "URI-FQDNdescriptor"); |
| 934 | if (val) { |
| 935 | if (strcasecmp(val, "HELD") == 0) { |
| 936 | dut->ap_fqdn_held = 1; |
| 937 | } else if (strcasecmp(val, "SUPL") == 0) { |
| 938 | dut->ap_fqdn_supl = 1; |
| 939 | } else { |
| 940 | send_resp(dut, conn, SIGMA_INVALID, |
| 941 | "errorCode,Unsupported URI-FQDNdescriptor"); |
| 942 | return 0; |
| 943 | } |
| 944 | } |
| 945 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 946 | return 1; |
| 947 | } |
| 948 | |
| 949 | |
| 950 | static void ath_inject_frame(struct sigma_dut *dut, const char *ifname, int tid) |
| 951 | { |
| 952 | char buf[256]; |
| 953 | int tid_to_dscp[] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 }; |
| 954 | |
Pradeep Reddy POTTETI | d31d132 | 2016-10-13 17:22:03 +0530 | [diff] [blame] | 955 | if (tid < 0 || |
| 956 | tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) { |
| 957 | sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid); |
| 958 | return; |
| 959 | } |
| 960 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 961 | snprintf(buf, sizeof(buf), |
| 962 | "wlanconfig %s list sta | grep : | cut -b 1-17 > %s", |
| 963 | ifname, VI_QOS_TMP_FILE); |
| 964 | if (system(buf) != 0) |
| 965 | return; |
| 966 | |
| 967 | snprintf(buf, sizeof(buf), |
| 968 | "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s", |
| 969 | ifname, VI_QOS_TMP_FILE); |
| 970 | if (system(buf) != 0) |
| 971 | sigma_dut_print(dut, DUT_MSG_ERROR, "Retrieve HWaddr failed"); |
| 972 | |
| 973 | snprintf(buf, sizeof(buf), "sed -n '3,$p' %s >> %s", |
| 974 | VI_QOS_REFFILE, VI_QOS_TMP_FILE); |
| 975 | if (system(buf) != 0) { |
| 976 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 977 | "Output redirection to VI_QOS_TMP_FILE failed"); |
| 978 | } |
| 979 | |
| 980 | snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s", |
| 981 | tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE); |
| 982 | if (system(buf) != 0) { |
| 983 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 984 | "Append TID to VI_QOS_FILE failed "); |
| 985 | } |
| 986 | |
| 987 | snprintf(buf, sizeof(buf), "ethinject %s %s", ifname, VI_QOS_FILE); |
| 988 | if (system(buf) != 0) |
| 989 | sigma_dut_print(dut, DUT_MSG_ERROR, "Ethinject frame failed"); |
| 990 | } |
| 991 | |
| 992 | |
| 993 | static int ath_ap_send_addba_req(struct sigma_dut *dut, struct sigma_conn *conn, |
| 994 | struct sigma_cmd *cmd) |
| 995 | { |
| 996 | const char *val; |
| 997 | char *ifname; |
| 998 | char buf[256]; |
| 999 | int tid = 0; |
| 1000 | |
| 1001 | ifname = get_main_ifname(); |
| 1002 | val = get_param(cmd, "TID"); |
| 1003 | if (val) { |
| 1004 | tid = atoi(val); |
| 1005 | if (tid) |
| 1006 | ath_inject_frame(dut, ifname, tid); |
| 1007 | } |
| 1008 | |
| 1009 | /* NOTE: This is the command sequence on Peregrine for ADDBA */ |
| 1010 | snprintf(buf, sizeof(buf), "iwpriv %s setaddbaoper 1", ifname); |
| 1011 | if (system(buf) != 0) { |
| 1012 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 1013 | "iwpriv setaddbaoper failed"); |
| 1014 | } |
| 1015 | |
| 1016 | snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4", |
| 1017 | ifname, tid); |
| 1018 | if (system(buf) != 0) { |
| 1019 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 1020 | "wifitool senddelba failed"); |
| 1021 | } |
| 1022 | |
| 1023 | snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64", |
| 1024 | ifname, tid); |
| 1025 | if (system(buf) != 0) { |
| 1026 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 1027 | "wifitool sendaddba failed"); |
| 1028 | } |
| 1029 | |
| 1030 | return 1; |
| 1031 | } |
| 1032 | |
| 1033 | |
Mohammed Shafi Shajakhan | a0535d4 | 2016-06-17 11:55:00 +0530 | [diff] [blame] | 1034 | static int ath10k_debug_enable_addba_req(struct sigma_dut *dut, int tid, |
| 1035 | const char *sta_mac, |
| 1036 | const char *dir_path) |
| 1037 | { |
| 1038 | DIR *dir; |
| 1039 | struct dirent *entry; |
| 1040 | char buf[128], path[128]; |
| 1041 | int ret = 0; |
| 1042 | |
| 1043 | dir = opendir(dir_path); |
| 1044 | if (!dir) |
| 1045 | return 0; |
| 1046 | |
| 1047 | while ((entry = readdir(dir))) { |
| 1048 | ret = 1; |
| 1049 | |
| 1050 | if (strcmp(entry->d_name, ".") == 0 || |
| 1051 | strcmp(entry->d_name, "..") == 0) |
| 1052 | continue; |
| 1053 | |
| 1054 | snprintf(path, sizeof(path) - 1, "%s/%s", |
| 1055 | dir_path, entry->d_name); |
| 1056 | path[sizeof(path) - 1] = 0; |
| 1057 | |
| 1058 | if (strcmp(entry->d_name, sta_mac) == 0) { |
| 1059 | snprintf(buf, sizeof(buf), "echo 1 > %s/aggr_mode", |
| 1060 | path); |
| 1061 | if (system(buf) != 0) { |
| 1062 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 1063 | "Failed to set aggr mode for ath10k"); |
| 1064 | } |
| 1065 | |
| 1066 | snprintf(buf, sizeof(buf), "echo %d 32 > %s/addba", |
| 1067 | tid, path); |
| 1068 | if (system(buf) != 0) { |
| 1069 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 1070 | "Failed to set addbareq for ath10k"); |
| 1071 | } |
| 1072 | |
| 1073 | break; |
| 1074 | } |
| 1075 | |
| 1076 | /* Recursively search subdirectories */ |
| 1077 | ath10k_debug_enable_addba_req(dut, tid, sta_mac, path); |
| 1078 | } |
| 1079 | |
| 1080 | closedir(dir); |
| 1081 | |
| 1082 | return ret; |
| 1083 | } |
| 1084 | |
| 1085 | |
| 1086 | static int ath10k_ap_send_addba_req(struct sigma_dut *dut, |
| 1087 | struct sigma_cmd *cmd) |
| 1088 | { |
| 1089 | const char *val; |
| 1090 | int tid = 0; |
| 1091 | |
| 1092 | val = get_param(cmd, "TID"); |
| 1093 | if (val) |
| 1094 | tid = atoi(val); |
| 1095 | |
| 1096 | val = get_param(cmd, "sta_mac_address"); |
| 1097 | if (!val) { |
| 1098 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 1099 | "Failed to parse station MAC address"); |
| 1100 | return 0; |
| 1101 | } |
| 1102 | |
| 1103 | return ath10k_debug_enable_addba_req(dut, tid, val, |
| 1104 | "/sys/kernel/debug/ieee80211"); |
| 1105 | } |
| 1106 | |
| 1107 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1108 | static int cmd_ap_send_addba_req(struct sigma_dut *dut, struct sigma_conn *conn, |
| 1109 | struct sigma_cmd *cmd) |
| 1110 | { |
| 1111 | /* const char *name = get_param(cmd, "NAME"); */ |
| 1112 | /* const char *ifname = get_param(cmd, "INTERFACE"); */ |
Mohammed Shafi Shajakhan | a0535d4 | 2016-06-17 11:55:00 +0530 | [diff] [blame] | 1113 | struct stat s; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1114 | |
| 1115 | switch (get_driver_type()) { |
| 1116 | case DRIVER_ATHEROS: |
| 1117 | return ath_ap_send_addba_req(dut, conn, cmd); |
| 1118 | case DRIVER_OPENWRT: |
| 1119 | switch (get_openwrt_driver_type()) { |
| 1120 | case OPENWRT_DRIVER_ATHEROS: |
| 1121 | return ath_ap_send_addba_req(dut, conn, cmd); |
| 1122 | default: |
| 1123 | send_resp(dut, conn, SIGMA_ERROR, |
| 1124 | "errorCode,ap_send_addba_req not supported with this driver"); |
| 1125 | return 0; |
| 1126 | } |
Pradeep Reddy POTTETI | fdb0491 | 2016-08-02 14:16:24 +0530 | [diff] [blame] | 1127 | case DRIVER_WCN: |
| 1128 | case DRIVER_LINUX_WCN: |
| 1129 | /* AP automatically sends ADDBA request after association. */ |
| 1130 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 1131 | "ap_send_addba_req command ignored"); |
| 1132 | return 1; |
Mohammed Shafi Shajakhan | a0535d4 | 2016-06-17 11:55:00 +0530 | [diff] [blame] | 1133 | case DRIVER_MAC80211: |
| 1134 | if (stat("/sys/module/ath10k_core", &s) == 0) |
| 1135 | return ath10k_ap_send_addba_req(dut, cmd); |
| 1136 | /* fall through */ |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1137 | default: |
| 1138 | send_resp(dut, conn, SIGMA_ERROR, |
| 1139 | "errorCode,ap_send_addba_req not supported with this driver"); |
| 1140 | return 0; |
| 1141 | } |
| 1142 | } |
| 1143 | |
| 1144 | |
| 1145 | static int cmd_ap_set_security(struct sigma_dut *dut, struct sigma_conn *conn, |
| 1146 | struct sigma_cmd *cmd) |
| 1147 | { |
| 1148 | /* const char *name = get_param(cmd, "NAME"); */ |
| 1149 | const char *val; |
| 1150 | unsigned int wlan_tag = 1; |
| 1151 | |
| 1152 | val = get_param(cmd, "WLAN_TAG"); |
| 1153 | if (val) |
| 1154 | wlan_tag = atoi(val); |
| 1155 | |
| 1156 | if (wlan_tag == 2) { |
| 1157 | val = get_param(cmd, "KEYMGNT"); |
| 1158 | if (val) { |
| 1159 | if (strcasecmp(val, "NONE") == 0) |
| 1160 | dut->ap2_key_mgmt = AP2_OPEN; |
| 1161 | else if (strcasecmp(val, "OSEN") == 0) |
| 1162 | dut->ap2_key_mgmt = AP2_OSEN; |
| 1163 | else { |
| 1164 | send_resp(dut, conn, SIGMA_INVALID, |
| 1165 | "errorCode,Unsupported KEYMGNT"); |
| 1166 | return 0; |
| 1167 | } |
| 1168 | return 1; |
| 1169 | } |
| 1170 | } |
| 1171 | |
| 1172 | val = get_param(cmd, "KEYMGNT"); |
| 1173 | if (val) { |
| 1174 | if (strcasecmp(val, "WPA2-PSK") == 0) { |
| 1175 | dut->ap_key_mgmt = AP_WPA2_PSK; |
| 1176 | dut->ap_cipher = AP_CCMP; |
| 1177 | } else if (strcasecmp(val, "WPA2-EAP") == 0 || |
| 1178 | strcasecmp(val, "WPA2-Ent") == 0) { |
| 1179 | dut->ap_key_mgmt = AP_WPA2_EAP; |
| 1180 | dut->ap_cipher = AP_CCMP; |
| 1181 | } else if (strcasecmp(val, "WPA-PSK") == 0) { |
| 1182 | dut->ap_key_mgmt = AP_WPA_PSK; |
| 1183 | dut->ap_cipher = AP_TKIP; |
| 1184 | } else if (strcasecmp(val, "WPA-EAP") == 0 || |
| 1185 | strcasecmp(val, "WPA-Ent") == 0) { |
| 1186 | dut->ap_key_mgmt = AP_WPA_EAP; |
| 1187 | dut->ap_cipher = AP_TKIP; |
| 1188 | } else if (strcasecmp(val, "WPA2-Mixed") == 0) { |
| 1189 | dut->ap_key_mgmt = AP_WPA2_EAP_MIXED; |
| 1190 | dut->ap_cipher = AP_CCMP_TKIP; |
| 1191 | } else if (strcasecmp(val, "WPA2-PSK-Mixed") == 0) { |
| 1192 | dut->ap_key_mgmt = AP_WPA2_PSK_MIXED; |
| 1193 | dut->ap_cipher = AP_CCMP_TKIP; |
| 1194 | } else if (strcasecmp(val, "NONE") == 0) { |
| 1195 | dut->ap_key_mgmt = AP_OPEN; |
| 1196 | dut->ap_cipher = AP_PLAIN; |
| 1197 | } else { |
| 1198 | send_resp(dut, conn, SIGMA_INVALID, |
| 1199 | "errorCode,Unsupported KEYMGNT"); |
| 1200 | return 0; |
| 1201 | } |
| 1202 | } |
| 1203 | |
| 1204 | val = get_param(cmd, "ENCRYPT"); |
| 1205 | if (val) { |
| 1206 | if (strcasecmp(val, "WEP") == 0) { |
| 1207 | dut->ap_cipher = AP_WEP; |
| 1208 | } else if (strcasecmp(val, "TKIP") == 0) { |
| 1209 | dut->ap_cipher = AP_TKIP; |
| 1210 | } else if (strcasecmp(val, "AES") == 0 || |
| 1211 | strcasecmp(val, "AES-CCMP") == 0) { |
| 1212 | dut->ap_cipher = AP_CCMP; |
| 1213 | } else { |
| 1214 | send_resp(dut, conn, SIGMA_INVALID, |
| 1215 | "errorCode,Unsupported ENCRYPT"); |
| 1216 | return 0; |
| 1217 | } |
| 1218 | } |
| 1219 | |
| 1220 | val = get_param(cmd, "WEPKEY"); |
| 1221 | if (val) { |
| 1222 | size_t len; |
| 1223 | if (dut->ap_cipher != AP_WEP) { |
| 1224 | send_resp(dut, conn, SIGMA_INVALID, |
| 1225 | "errorCode,Unexpected WEPKEY without WEP " |
| 1226 | "configuration"); |
| 1227 | return 0; |
| 1228 | } |
| 1229 | len = strlen(val); |
| 1230 | if (len != 10 && len != 26) { |
| 1231 | send_resp(dut, conn, SIGMA_INVALID, |
| 1232 | "errorCode,Unexpected WEPKEY length"); |
| 1233 | return 0; |
| 1234 | } |
| 1235 | snprintf(dut->ap_wepkey, sizeof(dut->ap_wepkey), "%s", val); |
| 1236 | } |
| 1237 | |
| 1238 | val = get_param(cmd, "PSK"); |
| 1239 | if (val) { |
| 1240 | if (strlen(val) > sizeof(dut->ap_passphrase) - 1) |
| 1241 | return -1; |
| 1242 | snprintf(dut->ap_passphrase, sizeof(dut->ap_passphrase), |
| 1243 | "%s", val); |
| 1244 | } |
| 1245 | |
| 1246 | val = get_param(cmd, "PMF"); |
| 1247 | if (val) { |
| 1248 | if (strcasecmp(val, "Disabled") == 0) { |
| 1249 | dut->ap_pmf = AP_PMF_DISABLED; |
| 1250 | } else if (strcasecmp(val, "Optional") == 0) { |
| 1251 | dut->ap_pmf = AP_PMF_OPTIONAL; |
| 1252 | } else if (strcasecmp(val, "Required") == 0) { |
| 1253 | dut->ap_pmf = AP_PMF_REQUIRED; |
| 1254 | } else { |
| 1255 | send_resp(dut, conn, SIGMA_INVALID, |
| 1256 | "errorCode,Unsupported PMF"); |
| 1257 | return 0; |
| 1258 | } |
| 1259 | } |
| 1260 | |
| 1261 | if (dut->ap_key_mgmt == AP_OPEN) { |
| 1262 | dut->ap_hs2 = 0; |
| 1263 | dut->ap_pmf = AP_PMF_DISABLED; |
| 1264 | } |
| 1265 | |
| 1266 | dut->ap_add_sha256 = 0; |
| 1267 | val = get_param(cmd, "SHA256AD"); |
| 1268 | if (val == NULL) |
| 1269 | val = get_param(cmd, "SHA256"); |
| 1270 | if (val) { |
| 1271 | if (strcasecmp(val, "Disabled") == 0) { |
| 1272 | } else if (strcasecmp(val, "Enabled") == 0) { |
| 1273 | dut->ap_add_sha256 = 1; |
| 1274 | } else { |
| 1275 | send_resp(dut, conn, SIGMA_INVALID, |
| 1276 | "errorCode,Unsupported PMF"); |
| 1277 | return 0; |
| 1278 | } |
| 1279 | } |
| 1280 | |
Sarvepalli, Rajesh Babu | 24dc7e4 | 2016-03-18 21:27:26 +0530 | [diff] [blame] | 1281 | val = get_param(cmd, "PreAuthentication"); |
| 1282 | if (val) { |
| 1283 | if (strcasecmp(val, "disabled") == 0) { |
| 1284 | dut->ap_rsn_preauth = 0; |
| 1285 | } else if (strcasecmp(val, "enabled") == 0) { |
| 1286 | dut->ap_rsn_preauth = 1; |
| 1287 | } else { |
| 1288 | send_resp(dut, conn, SIGMA_INVALID, |
| 1289 | "errorCode,Unsupported PreAuthentication value"); |
| 1290 | return 0; |
| 1291 | } |
| 1292 | } |
| 1293 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1294 | return 1; |
| 1295 | } |
| 1296 | |
| 1297 | |
| 1298 | static int cmd_ap_set_radius(struct sigma_dut *dut, struct sigma_conn *conn, |
| 1299 | struct sigma_cmd *cmd) |
| 1300 | { |
| 1301 | /* const char *name = get_param(cmd, "NAME"); */ |
| 1302 | const char *val; |
| 1303 | unsigned int wlan_tag = 1, radius_port = 0; |
| 1304 | char *radius_ipaddr = NULL, *radius_password = NULL; |
| 1305 | |
| 1306 | val = get_param(cmd, "WLAN_TAG"); |
| 1307 | if (val) { |
| 1308 | wlan_tag = atoi(val); |
| 1309 | if (wlan_tag != 1 && wlan_tag != 2) { |
| 1310 | send_resp(dut, conn, SIGMA_INVALID, |
| 1311 | "errorCode,Invalid WLAN_TAG"); |
| 1312 | return 0; |
| 1313 | } |
| 1314 | } |
| 1315 | |
| 1316 | val = get_param(cmd, "PORT"); |
| 1317 | if (val) |
| 1318 | radius_port = atoi(val); |
| 1319 | |
| 1320 | if (wlan_tag == 1) { |
| 1321 | if (radius_port) |
| 1322 | dut->ap_radius_port = radius_port; |
| 1323 | radius_ipaddr = dut->ap_radius_ipaddr; |
| 1324 | radius_password = dut->ap_radius_password; |
| 1325 | } else if (wlan_tag == 2) { |
| 1326 | if (radius_port) |
| 1327 | dut->ap2_radius_port = radius_port; |
| 1328 | radius_ipaddr = dut->ap2_radius_ipaddr; |
| 1329 | radius_password = dut->ap2_radius_password; |
| 1330 | } |
| 1331 | |
| 1332 | val = get_param(cmd, "IPADDR"); |
| 1333 | if (val) { |
| 1334 | if (strlen(val) > sizeof(dut->ap_radius_ipaddr) - 1) |
| 1335 | return -1; |
| 1336 | snprintf(radius_ipaddr, sizeof(dut->ap_radius_ipaddr), |
| 1337 | "%s", val); |
| 1338 | } |
| 1339 | |
| 1340 | val = get_param(cmd, "PASSWORD"); |
| 1341 | if (val) { |
| 1342 | if (strlen(val) > sizeof(dut->ap_radius_password) - 1) |
| 1343 | return -1; |
| 1344 | snprintf(radius_password, |
| 1345 | sizeof(dut->ap_radius_password), "%s", val); |
| 1346 | } |
| 1347 | |
| 1348 | return 1; |
| 1349 | } |
| 1350 | |
| 1351 | |
| 1352 | static void owrt_ap_set_radio(struct sigma_dut *dut, int id, |
| 1353 | const char *key, const char *val) |
| 1354 | { |
| 1355 | char buf[100]; |
| 1356 | |
| 1357 | if (val == NULL) { |
| 1358 | snprintf(buf, sizeof(buf), |
| 1359 | "uci delete wireless.wifi%d.%s", id, key); |
| 1360 | run_system(dut, buf); |
| 1361 | return; |
| 1362 | } |
| 1363 | |
| 1364 | snprintf(buf, sizeof(buf), "uci set wireless.wifi%d.%s=%s", |
| 1365 | id, key, val); |
| 1366 | run_system(dut, buf); |
| 1367 | } |
| 1368 | |
| 1369 | |
| 1370 | static void owrt_ap_set_list_radio(struct sigma_dut *dut, int id, |
| 1371 | const char *key, const char *val) |
| 1372 | { |
| 1373 | char buf[256]; |
| 1374 | |
| 1375 | if (val == NULL) { |
| 1376 | snprintf(buf, sizeof(buf), |
| 1377 | "uci del_list wireless.wifi%d.%s", id, key); |
| 1378 | run_system(dut, buf); |
| 1379 | return; |
| 1380 | } |
| 1381 | |
| 1382 | snprintf(buf, sizeof(buf), "uci add_list wireless.wifi%d.%s=%s", |
| 1383 | id, key, val); |
| 1384 | run_system(dut, buf); |
| 1385 | } |
| 1386 | |
| 1387 | |
| 1388 | static void owrt_ap_set_vap(struct sigma_dut *dut, int id, const char *key, |
| 1389 | const char *val) |
| 1390 | { |
| 1391 | char buf[256]; |
| 1392 | |
| 1393 | if (val == NULL) { |
| 1394 | snprintf(buf, sizeof(buf), |
| 1395 | "uci delete wireless.@wifi-iface[%d].%s", id, key); |
| 1396 | run_system(dut, buf); |
| 1397 | return; |
| 1398 | } |
| 1399 | |
| 1400 | snprintf(buf, sizeof(buf), "uci set wireless.@wifi-iface[%d].%s=%s", |
| 1401 | id, key, val); |
| 1402 | run_system(dut, buf); |
| 1403 | } |
| 1404 | |
| 1405 | |
| 1406 | static void owrt_ap_set_list_vap(struct sigma_dut *dut, int id, |
| 1407 | const char *key, const char *val) |
| 1408 | { |
priyadharshini gowthaman | 2323d0a | 2016-09-02 15:48:02 -0700 | [diff] [blame] | 1409 | char buf[1024]; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1410 | |
| 1411 | if (val == NULL) { |
| 1412 | snprintf(buf, sizeof(buf), |
| 1413 | "uci del_list wireless.@wifi-iface[%d].%s", id, key); |
| 1414 | run_system(dut, buf); |
| 1415 | return; |
| 1416 | } |
| 1417 | |
| 1418 | snprintf(buf, sizeof(buf), |
| 1419 | "uci add_list wireless.@wifi-iface[%d].%s=%s", |
| 1420 | id, key, val); |
| 1421 | run_system(dut, buf); |
| 1422 | } |
| 1423 | |
| 1424 | |
| 1425 | static void owrt_ap_add_vap(struct sigma_dut *dut, int id, const char *key, |
| 1426 | const char *val) |
| 1427 | { |
| 1428 | char buf[256]; |
| 1429 | |
| 1430 | if (val == NULL) { |
| 1431 | snprintf(buf, sizeof(buf), |
| 1432 | "uci delete wireless.@wifi-iface[%d].%s", id, key); |
| 1433 | run_system(dut, buf); |
| 1434 | return; |
| 1435 | } |
| 1436 | |
| 1437 | snprintf(buf, sizeof(buf), "uci add wireless wifi-iface"); |
| 1438 | run_system(dut, buf); |
| 1439 | snprintf(buf, sizeof(buf), "uci set wireless.@wifi-iface[%d].%s=%s", |
| 1440 | id, key, val); |
| 1441 | run_system(dut, buf); |
| 1442 | snprintf(buf, sizeof(buf), "uci set wireless.@wifi-iface[%d].%s=%s", |
| 1443 | id, "network", "lan"); |
| 1444 | run_system(dut, buf); |
| 1445 | snprintf(buf, sizeof(buf), "uci set wireless.@wifi-iface[%d].%s=%s", |
| 1446 | id, "mode", "ap"); |
| 1447 | run_system(dut, buf); |
| 1448 | snprintf(buf, sizeof(buf), "uci set wireless.@wifi-iface[%d].%s=%s", |
| 1449 | id, "encryption", "none"); |
| 1450 | run_system(dut, buf); |
| 1451 | } |
| 1452 | |
| 1453 | |
| 1454 | #define OPENWRT_MAX_NUM_RADIOS 3 |
| 1455 | static void owrt_ap_config_radio(struct sigma_dut *dut) |
| 1456 | { |
| 1457 | int radio_id[MAX_RADIO] = { 0, 1 }; |
| 1458 | int radio_count, radio_no; |
| 1459 | char buf[64]; |
| 1460 | |
| 1461 | for (radio_count = 0; radio_count < OPENWRT_MAX_NUM_RADIOS; |
| 1462 | radio_count++) { |
| 1463 | snprintf(buf, sizeof(buf), "%s%d", "wifi", radio_count); |
| 1464 | for (radio_no = 0; radio_no < MAX_RADIO; radio_no++) { |
| 1465 | if (!sigma_radio_ifname[radio_no] || |
| 1466 | strcmp(sigma_radio_ifname[radio_no], buf) != 0) |
| 1467 | continue; |
| 1468 | owrt_ap_set_radio(dut, radio_count, "disabled", "0"); |
| 1469 | owrt_ap_set_vap(dut, radio_count, "device", buf); |
| 1470 | radio_id[radio_no] = radio_count; |
| 1471 | } |
| 1472 | } |
| 1473 | |
| 1474 | /* Hardware mode (11a/b/g/n/ac) & HT mode selection */ |
| 1475 | switch (dut->ap_mode) { |
| 1476 | case AP_11g: |
| 1477 | owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11g"); |
| 1478 | break; |
| 1479 | case AP_11b: |
| 1480 | owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11b"); |
| 1481 | break; |
| 1482 | case AP_11ng: |
| 1483 | owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11ng"); |
| 1484 | owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT20"); |
| 1485 | break; |
| 1486 | case AP_11a: |
| 1487 | owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11a"); |
| 1488 | break; |
| 1489 | case AP_11na: |
| 1490 | owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11na"); |
| 1491 | owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT20"); |
| 1492 | break; |
| 1493 | case AP_11ac: |
| 1494 | owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11ac"); |
| 1495 | owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT80"); |
| 1496 | break; |
| 1497 | case AP_inval: |
| 1498 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 1499 | "MODE NOT SPECIFIED!"); |
| 1500 | return; |
| 1501 | default: |
| 1502 | owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11ng"); |
| 1503 | owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT20"); |
| 1504 | break; |
| 1505 | } |
| 1506 | |
| 1507 | if (dut->ap_is_dual) { |
| 1508 | /* Hardware mode (11a/b/g/n/ac) & HT mode selection */ |
| 1509 | switch (dut->ap_mode_1) { |
| 1510 | case AP_11g: |
| 1511 | owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11g"); |
| 1512 | break; |
| 1513 | case AP_11b: |
| 1514 | owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11b"); |
| 1515 | break; |
| 1516 | case AP_11ng: |
| 1517 | owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11ng"); |
| 1518 | owrt_ap_set_radio(dut, radio_id[1], "htmode", "HT20"); |
| 1519 | break; |
| 1520 | case AP_11a: |
| 1521 | owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11a"); |
| 1522 | break; |
| 1523 | case AP_11na: |
| 1524 | owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11na"); |
| 1525 | owrt_ap_set_radio(dut, radio_id[1], "htmode", "HT20"); |
| 1526 | break; |
| 1527 | case AP_11ac: |
| 1528 | owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11ac"); |
| 1529 | owrt_ap_set_radio(dut, radio_id[1], "htmode", "HT80"); |
| 1530 | break; |
| 1531 | case AP_inval: |
| 1532 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 1533 | "MODE NOT SPECIFIED!"); |
| 1534 | return; |
| 1535 | default: |
| 1536 | owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11ng"); |
| 1537 | owrt_ap_set_radio(dut, radio_id[1], "htmode", "HT20"); |
| 1538 | break; |
| 1539 | } |
| 1540 | |
| 1541 | } |
| 1542 | |
| 1543 | /* Channel */ |
| 1544 | snprintf(buf, sizeof(buf), "%d", dut->ap_channel); |
| 1545 | owrt_ap_set_radio(dut, radio_id[0], "channel", buf); |
| 1546 | |
| 1547 | switch (dut->ap_chwidth) { |
| 1548 | case AP_20: |
| 1549 | owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT20"); |
| 1550 | break; |
| 1551 | case AP_40: |
| 1552 | owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT40"); |
| 1553 | break; |
| 1554 | case AP_80: |
| 1555 | owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT80"); |
| 1556 | break; |
| 1557 | case AP_160: |
| 1558 | owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT160"); |
| 1559 | break; |
| 1560 | case AP_AUTO: |
| 1561 | default: |
| 1562 | break; |
| 1563 | } |
| 1564 | |
| 1565 | if (dut->ap_channel == 140 || dut->ap_channel == 144) { |
| 1566 | if (get_openwrt_driver_type() == OPENWRT_DRIVER_ATHEROS) |
| 1567 | owrt_ap_set_radio(dut, radio_id[0], "set_ch_144", "3"); |
| 1568 | } |
| 1569 | |
| 1570 | if (dut->ap_is_dual) { |
| 1571 | snprintf(buf, sizeof(buf), "%d", dut->ap_channel_1); |
| 1572 | owrt_ap_set_radio(dut, radio_id[1], "channel", buf); |
| 1573 | } |
| 1574 | |
| 1575 | if (dut->ap_countrycode[0]) { |
| 1576 | /* Country Code */ |
| 1577 | snprintf(buf, sizeof(buf), "%s", dut->ap_countrycode); |
| 1578 | owrt_ap_set_radio(dut, radio_id[0], "country", buf); |
| 1579 | } |
| 1580 | |
| 1581 | if (dut->ap_disable_protection == 1) { |
| 1582 | owrt_ap_set_list_radio(dut, radio_id[0], "aggr_burst", "'0 0'"); |
| 1583 | owrt_ap_set_list_radio(dut, radio_id[0], "aggr_burst", "'1 0'"); |
| 1584 | owrt_ap_set_list_radio(dut, radio_id[0], "aggr_burst", "'2 0'"); |
| 1585 | owrt_ap_set_list_radio(dut, radio_id[0], "aggr_burst", "'3 0'"); |
| 1586 | } |
| 1587 | } |
| 1588 | |
| 1589 | |
| 1590 | static int owrt_ap_config_vap_hs2(struct sigma_dut *dut, int vap_id) |
| 1591 | { |
| 1592 | char buf[256]; |
| 1593 | |
| 1594 | snprintf(buf, sizeof(buf), "%d", dut->ap_hs2); |
| 1595 | owrt_ap_set_vap(dut, vap_id, "hs20", buf); |
| 1596 | owrt_ap_set_vap(dut, vap_id, "qbssload", "1"); |
| 1597 | owrt_ap_set_vap(dut, vap_id, "hs20_deauth_req_timeout","3"); |
| 1598 | |
| 1599 | owrt_ap_set_list_vap(dut, vap_id, "hs20_oper_friendly_name", |
| 1600 | "'eng:Wi-Fi Alliance'"); |
| 1601 | |
| 1602 | owrt_ap_set_list_vap(dut, vap_id, "hs20_oper_friendly_name", |
| 1603 | "'chi:Wi-Fi\xe8\x81\x94\xe7\x9b\x9f'"); |
| 1604 | |
| 1605 | if (dut->ap_wan_metrics == 1) |
| 1606 | owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics", |
| 1607 | "'01:2500:384:0:0:10'"); |
| 1608 | else if (dut->ap_wan_metrics == 1) |
| 1609 | owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics", |
| 1610 | "'01:1500:384:20:20:10'"); |
| 1611 | else if (dut->ap_wan_metrics == 2) |
| 1612 | owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics", |
| 1613 | "'01:1500:384:20:20:10'"); |
| 1614 | else if (dut->ap_wan_metrics == 3) |
| 1615 | owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics", |
| 1616 | "'01:2000:1000:20:20:10'"); |
| 1617 | else if (dut->ap_wan_metrics == 4) |
| 1618 | owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics", |
| 1619 | "'01:8000:1000:20:20:10'"); |
| 1620 | else if (dut->ap_wan_metrics == 5) |
| 1621 | owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics", |
| 1622 | "'01:9000:5000:20:20:10'"); |
| 1623 | |
| 1624 | if (dut->ap_conn_capab == 1) { |
| 1625 | owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab", "'1:0:0'"); |
| 1626 | owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab", |
| 1627 | "'6:20:1'"); |
| 1628 | owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab", |
| 1629 | "'6:22:0'"); |
| 1630 | owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab", |
| 1631 | "'6:80:1'"); |
| 1632 | owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab", |
| 1633 | "'6:443:1'"); |
| 1634 | owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab", |
| 1635 | "'6:1723:0'"); |
| 1636 | owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab", |
| 1637 | "'6:5060:0'"); |
| 1638 | owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab", |
| 1639 | "'17:500:1'"); |
| 1640 | owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab", |
| 1641 | "'17:5060:0'"); |
| 1642 | owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab", |
| 1643 | "'17:4500:1'"); |
| 1644 | owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab", |
| 1645 | "'50:0:1'"); |
| 1646 | } else if (dut->ap_conn_capab == 2) { |
| 1647 | owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab", |
| 1648 | "'6:80:1'"); |
| 1649 | owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab", |
| 1650 | "'6:443:1'"); |
| 1651 | owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab", |
| 1652 | "'17:5060:1'"); |
| 1653 | owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab", |
| 1654 | "'6:5060:1'"); |
| 1655 | } else if (dut->ap_conn_capab == 3) { |
| 1656 | owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab", |
| 1657 | "'6:80:1'"); |
| 1658 | owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab", |
| 1659 | "'6:443:1'"); |
| 1660 | } |
| 1661 | |
| 1662 | if (dut->ap_oper_class == 1) |
| 1663 | snprintf(buf, sizeof(buf), "%s", "51"); |
| 1664 | else if (dut->ap_oper_class == 2) |
| 1665 | snprintf(buf, sizeof(buf), "%s", "73"); |
| 1666 | else if (dut->ap_oper_class == 3) |
| 1667 | snprintf(buf, sizeof(buf), "%s", "5173"); |
| 1668 | |
| 1669 | if (dut->ap_oper_class) |
| 1670 | owrt_ap_set_vap(dut, vap_id, "hs20_operating_class", buf); |
| 1671 | |
| 1672 | if (dut->ap_osu_provider_list) { |
| 1673 | char *osu_friendly_name = NULL; |
| 1674 | char *osu_icon = NULL; |
| 1675 | char *osu_ssid = NULL; |
| 1676 | char *osu_nai = NULL; |
| 1677 | char *osu_service_desc = NULL; |
| 1678 | char *hs20_icon_filename = NULL; |
| 1679 | char hs20_icon[150]; |
| 1680 | int osu_method; |
| 1681 | |
| 1682 | hs20_icon_filename = "icon_red_zxx.png"; |
| 1683 | if (dut->ap_osu_icon_tag == 2) |
| 1684 | hs20_icon_filename = "wifi-abgn-logo_270x73.png"; |
| 1685 | snprintf(hs20_icon, sizeof(hs20_icon), |
| 1686 | "'128:61:zxx:image/png:icon_red_zxx.png:/etc/ath/%s'", |
| 1687 | hs20_icon_filename); |
| 1688 | osu_icon = "icon_red_zxx.png"; |
| 1689 | osu_ssid = "OSU"; |
| 1690 | osu_friendly_name = "'kor:SP 빨강 테스트 전용'"; |
| 1691 | osu_service_desc = "'kor:테스트 목적으로 무료 서비스'"; |
| 1692 | osu_method = (dut->ap_osu_method[0] == 0xFF) ? 1 : |
| 1693 | dut->ap_osu_method[0]; |
| 1694 | |
| 1695 | if (strlen(dut->ap_osu_server_uri[0])) |
| 1696 | owrt_ap_set_list_vap(dut, vap_id, "osu_server_uri", |
| 1697 | dut->ap_osu_server_uri[0]); |
| 1698 | else |
| 1699 | owrt_ap_set_list_vap(dut, vap_id, "osu_server_uri", |
| 1700 | "'https://osu-server.r2-testbed.wi-fi.org/'"); |
| 1701 | switch (dut->ap_osu_provider_list) { |
| 1702 | case 1: |
| 1703 | case 101: |
| 1704 | owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name", |
| 1705 | "'eng:SP Red Test Only'"); |
| 1706 | owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc", |
| 1707 | "'eng:Free service for test purpose'"); |
| 1708 | owrt_ap_set_list_vap(dut, vap_id, "hs20_icon", |
| 1709 | hs20_icon); |
| 1710 | |
| 1711 | hs20_icon_filename = "icon_red_eng.png"; |
| 1712 | if (dut->ap_osu_icon_tag == 2) |
| 1713 | hs20_icon_filename = "wifi-abgn-logo_270x73.png"; |
| 1714 | |
| 1715 | snprintf(hs20_icon, sizeof(hs20_icon), |
| 1716 | "'160:76:eng:image/png:icon_red_eng.png:/etc/ath/%s'", |
| 1717 | hs20_icon_filename); |
| 1718 | owrt_ap_set_list_vap(dut, vap_id, "osu_icon", |
| 1719 | "icon_red_eng.png"); |
| 1720 | break; |
| 1721 | case 2: |
| 1722 | case 102: |
| 1723 | owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name", |
| 1724 | "'eng:Wireless Broadband Alliance'"); |
| 1725 | owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc", |
| 1726 | "'eng:Free service for test purpose'"); |
priyadharshini gowthaman | cc0e29c | 2016-10-17 11:48:59 +0300 | [diff] [blame] | 1727 | hs20_icon_filename = "icon_orange_zxx.png"; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1728 | if (dut->ap_osu_icon_tag == 2) |
| 1729 | hs20_icon_filename = "wifi-abgn-logo_270x73.png"; |
| 1730 | |
| 1731 | snprintf(hs20_icon, sizeof(hs20_icon), |
priyadharshini gowthaman | cc0e29c | 2016-10-17 11:48:59 +0300 | [diff] [blame] | 1732 | "'128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s'", |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1733 | hs20_icon_filename); |
priyadharshini gowthaman | cc0e29c | 2016-10-17 11:48:59 +0300 | [diff] [blame] | 1734 | osu_icon = "icon_orange_zxx.png"; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1735 | osu_friendly_name = "'kor:와이어리스 브로드밴드 얼라이언스'"; |
| 1736 | break; |
| 1737 | case 3: |
| 1738 | case 103: |
| 1739 | osu_friendly_name = "spa:SP Red Test Only"; |
| 1740 | osu_service_desc = "spa:Free service for test purpose"; |
| 1741 | break; |
| 1742 | case 4: |
| 1743 | case 104: |
| 1744 | owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name", |
priyadharshini gowthaman | cc0e29c | 2016-10-17 11:48:59 +0300 | [diff] [blame] | 1745 | "'eng:SP Orange Test Only'"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1746 | owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc", |
| 1747 | "'eng:Free service for test purpose'"); |
priyadharshini gowthaman | cc0e29c | 2016-10-17 11:48:59 +0300 | [diff] [blame] | 1748 | hs20_icon_filename = "icon_orange_eng.png"; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1749 | if (dut->ap_osu_icon_tag == 2) |
| 1750 | hs20_icon_filename = "wifi-abgn-logo_270x73.png"; |
| 1751 | |
| 1752 | snprintf(hs20_icon, sizeof(hs20_icon), |
priyadharshini gowthaman | cc0e29c | 2016-10-17 11:48:59 +0300 | [diff] [blame] | 1753 | "'160:76:eng:image/png:icon_orange_eng.png:/etc/ath/%s'", |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1754 | hs20_icon_filename); |
| 1755 | owrt_ap_set_list_vap(dut, vap_id, "hs20_icon", |
| 1756 | hs20_icon); |
| 1757 | osu_friendly_name = "'kor:SP 파랑 테스트 전용'"; |
| 1758 | |
priyadharshini gowthaman | cc0e29c | 2016-10-17 11:48:59 +0300 | [diff] [blame] | 1759 | hs20_icon_filename = "icon_orange_zxx.png"; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1760 | if (dut->ap_osu_icon_tag == 2) |
| 1761 | hs20_icon_filename = "wifi-abgn-logo_270x73.png"; |
| 1762 | |
| 1763 | snprintf(hs20_icon, sizeof(hs20_icon), |
priyadharshini gowthaman | cc0e29c | 2016-10-17 11:48:59 +0300 | [diff] [blame] | 1764 | "'128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s'", |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1765 | hs20_icon_filename); |
priyadharshini gowthaman | cc0e29c | 2016-10-17 11:48:59 +0300 | [diff] [blame] | 1766 | osu_icon = "icon_orange_zxx.png"; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1767 | break; |
| 1768 | case 5: |
| 1769 | case 105: |
| 1770 | owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name", |
priyadharshini gowthaman | cc0e29c | 2016-10-17 11:48:59 +0300 | [diff] [blame] | 1771 | "'eng:SP Orange Test Only'"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1772 | owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc", |
| 1773 | "'eng:Free service for test purpose'"); |
| 1774 | osu_friendly_name = "'kor:SP 파랑 테스트 전용'"; |
| 1775 | |
priyadharshini gowthaman | cc0e29c | 2016-10-17 11:48:59 +0300 | [diff] [blame] | 1776 | hs20_icon_filename = "icon_orange_zxx.png"; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1777 | if (dut->ap_osu_icon_tag == 2) |
| 1778 | hs20_icon_filename = "wifi-abgn-logo_270x73.png"; |
| 1779 | |
| 1780 | snprintf(hs20_icon, sizeof(hs20_icon), |
priyadharshini gowthaman | cc0e29c | 2016-10-17 11:48:59 +0300 | [diff] [blame] | 1781 | "'128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s'", |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1782 | hs20_icon_filename); |
priyadharshini gowthaman | cc0e29c | 2016-10-17 11:48:59 +0300 | [diff] [blame] | 1783 | osu_icon = "icon_orange_zxx.png"; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1784 | break; |
| 1785 | case 6: |
| 1786 | case 106: |
| 1787 | owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name", |
| 1788 | "'eng:SP Green Test Only'"); |
| 1789 | owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name", |
| 1790 | "'kor:SP 초록 테스트 전용'"); |
| 1791 | |
| 1792 | hs20_icon_filename = "icon_green_zxx.png"; |
| 1793 | if (dut->ap_osu_icon_tag == 2) |
| 1794 | hs20_icon_filename = "wifi-abgn-logo_270x73.png"; |
| 1795 | |
| 1796 | snprintf(hs20_icon, sizeof(hs20_icon), |
| 1797 | "'128:61:zxx:image/png:icon_green_zxx.png:/etc/ath/%s'", |
| 1798 | hs20_icon_filename); |
| 1799 | owrt_ap_set_list_vap(dut, vap_id, "hs20_icon", |
| 1800 | hs20_icon); |
| 1801 | |
| 1802 | owrt_ap_set_list_vap(dut, vap_id, "osu_icon", |
| 1803 | "'icon_green_zxx.png'"); |
| 1804 | osu_method = (dut->ap_osu_method[0] == 0xFF) ? 0 : |
| 1805 | dut->ap_osu_method[0]; |
| 1806 | |
| 1807 | snprintf(buf, sizeof(buf), "%d", osu_method); |
| 1808 | owrt_ap_set_vap(dut, vap_id, "osu_method_list", buf); |
| 1809 | |
| 1810 | if (strlen(dut->ap_osu_server_uri[1])) |
| 1811 | owrt_ap_set_list_vap(dut, vap_id, |
| 1812 | "osu_server_uri", |
| 1813 | dut->ap_osu_server_uri[1]); |
| 1814 | else |
| 1815 | owrt_ap_set_list_vap(dut, vap_id, |
| 1816 | "osu_server_uri", |
| 1817 | "'https://osu-server.r2-testbed.wi-fi.org/'"); |
| 1818 | |
| 1819 | owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name", |
| 1820 | "'eng:SP Orange Test Only'"); |
| 1821 | |
| 1822 | hs20_icon_filename = "icon_orange_zxx.png"; |
| 1823 | if (dut->ap_osu_icon_tag == 2) |
| 1824 | hs20_icon_filename = "wifi-abgn-logo_270x73.png"; |
| 1825 | |
| 1826 | snprintf(hs20_icon, sizeof(hs20_icon), |
| 1827 | "'128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s'", |
| 1828 | hs20_icon_filename); |
| 1829 | |
| 1830 | osu_icon = "icon_orange_zxx.png"; |
| 1831 | osu_friendly_name = "'kor:SP 오렌지 테스트 전용'"; |
| 1832 | osu_method = (dut->ap_osu_method[1] == 0xFF) ? 0 : |
| 1833 | dut->ap_osu_method[1]; |
| 1834 | osu_service_desc = NULL; |
| 1835 | break; |
| 1836 | case 7: |
| 1837 | case 107: |
| 1838 | owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name", |
priyadharshini gowthaman | cc0e29c | 2016-10-17 11:48:59 +0300 | [diff] [blame] | 1839 | "'eng:SP Green Test Only'"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1840 | owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc", |
| 1841 | "'eng:Free service for test purpose'"); |
| 1842 | |
priyadharshini gowthaman | cc0e29c | 2016-10-17 11:48:59 +0300 | [diff] [blame] | 1843 | hs20_icon_filename = "icon_green_eng.png"; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1844 | if (dut->ap_osu_icon_tag == 2) |
| 1845 | hs20_icon_filename = "wifi-abgn-logo_270x73.png"; |
| 1846 | |
| 1847 | snprintf(hs20_icon, sizeof(hs20_icon), |
priyadharshini gowthaman | cc0e29c | 2016-10-17 11:48:59 +0300 | [diff] [blame] | 1848 | "'160:76:eng:image/png:icon_green_eng.png:/etc/ath/%s'", |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1849 | hs20_icon_filename); |
| 1850 | owrt_ap_set_list_vap(dut, vap_id, "hs20_icon", |
| 1851 | hs20_icon); |
| 1852 | |
| 1853 | owrt_ap_set_list_vap(dut, vap_id, "osu_icon", |
priyadharshini gowthaman | cc0e29c | 2016-10-17 11:48:59 +0300 | [diff] [blame] | 1854 | "'icon_green_eng.png'"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1855 | osu_friendly_name = "'kor:SP 오렌지 테스트 전용'"; |
| 1856 | |
priyadharshini gowthaman | cc0e29c | 2016-10-17 11:48:59 +0300 | [diff] [blame] | 1857 | hs20_icon_filename = "icon_green_zxx.png"; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1858 | if (dut->ap_osu_icon_tag == 2) |
| 1859 | hs20_icon_filename = "wifi-abgn-logo_270x73.png"; |
| 1860 | |
| 1861 | snprintf(hs20_icon, sizeof(hs20_icon), |
priyadharshini gowthaman | cc0e29c | 2016-10-17 11:48:59 +0300 | [diff] [blame] | 1862 | "'128:61:zxx:image/png:icon_green_zxx.png:/etc/ath/%s'", |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1863 | hs20_icon_filename); |
priyadharshini gowthaman | cc0e29c | 2016-10-17 11:48:59 +0300 | [diff] [blame] | 1864 | osu_icon = "icon_green_zxx.png"; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1865 | break; |
| 1866 | case 8: |
| 1867 | case 108: |
| 1868 | owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name", |
| 1869 | "'eng:SP Red Test Only'"); |
| 1870 | owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc", |
| 1871 | "'eng:Free service for test purpose'"); |
| 1872 | osu_ssid = "OSU-Encrypted"; |
| 1873 | osu_nai = "'anonymous@hotspot.net'"; |
| 1874 | break; |
| 1875 | case 9: |
| 1876 | case 109: |
| 1877 | osu_ssid = "OSU-OSEN"; |
| 1878 | osu_nai = "'test-anonymous@wi-fi.org'"; |
| 1879 | osu_friendly_name = "'eng:SP Orange Test Only'"; |
| 1880 | hs20_icon_filename = "icon_orange_zxx.png"; |
| 1881 | if (dut->ap_osu_icon_tag == 2) |
| 1882 | hs20_icon_filename = "wifi-abgn-logo_270x73.png"; |
| 1883 | |
| 1884 | snprintf(hs20_icon, sizeof(hs20_icon), |
| 1885 | "'128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s'", |
| 1886 | hs20_icon_filename); |
| 1887 | osu_icon = "icon_orange_zxx.png"; |
| 1888 | osu_method = (dut->ap_osu_method[0] == 0xFF) ? 1 : |
| 1889 | dut->ap_osu_method[0]; |
| 1890 | osu_service_desc = NULL; |
| 1891 | break; |
| 1892 | default: |
| 1893 | break; |
| 1894 | } |
| 1895 | |
| 1896 | if (strlen(dut->ap_osu_ssid)) { |
| 1897 | if (strcmp(dut->ap2_ssid, dut->ap_osu_ssid) != 0 && |
| 1898 | strcmp(dut->ap2_ssid, osu_ssid) != 0) { |
| 1899 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 1900 | "OSU_SSID and WLAN_TAG2 SSID differ"); |
| 1901 | return -2; |
| 1902 | } |
| 1903 | |
| 1904 | snprintf(buf, sizeof(buf), "'\"%s\"'", |
| 1905 | dut->ap_osu_ssid); |
| 1906 | } else { |
| 1907 | snprintf(buf, sizeof(buf), "'\"%s\"'", osu_ssid); |
| 1908 | } |
| 1909 | |
| 1910 | owrt_ap_set_vap(dut, vap_id, "osu_ssid", buf); |
| 1911 | |
| 1912 | |
| 1913 | if (osu_friendly_name) |
| 1914 | owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name", |
| 1915 | osu_friendly_name); |
| 1916 | if (osu_service_desc) |
| 1917 | owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc", |
| 1918 | osu_service_desc); |
| 1919 | if (osu_nai) |
| 1920 | owrt_ap_set_vap(dut, vap_id, "osu_nai", osu_nai); |
| 1921 | |
| 1922 | owrt_ap_set_list_vap(dut, vap_id, "hs20_icon", hs20_icon); |
| 1923 | |
| 1924 | if (osu_icon) |
| 1925 | owrt_ap_set_list_vap(dut, vap_id, "osu_icon", |
| 1926 | osu_icon); |
| 1927 | |
| 1928 | if (dut->ap_osu_provider_list > 100) { |
| 1929 | owrt_ap_set_list_vap(dut, vap_id, "osu_method_list", |
| 1930 | "0"); |
| 1931 | } else { |
| 1932 | snprintf(buf, sizeof(buf), "%d", osu_method); |
| 1933 | owrt_ap_set_list_vap(dut, vap_id, "osu_method_list", |
| 1934 | buf); |
| 1935 | } |
| 1936 | } |
| 1937 | |
| 1938 | return 0; |
| 1939 | } |
| 1940 | |
| 1941 | |
| 1942 | static int owrt_ap_config_vap(struct sigma_dut *dut) |
| 1943 | { |
| 1944 | char buf[256], *temp; |
| 1945 | int vap_id = 0, vap_count, i; |
| 1946 | |
| 1947 | for (vap_count = 0; vap_count < OPENWRT_MAX_NUM_RADIOS; vap_count++) { |
| 1948 | snprintf(buf, sizeof(buf), "%s%d", "wifi", vap_count); |
| 1949 | |
| 1950 | for (vap_id = 0; vap_id < MAX_RADIO; vap_id++) { |
| 1951 | if (sigma_radio_ifname[vap_id] && |
| 1952 | strcmp(sigma_radio_ifname[vap_id], buf) == 0) |
| 1953 | break; |
| 1954 | } |
| 1955 | if (vap_id == MAX_RADIO) |
| 1956 | continue; |
| 1957 | |
| 1958 | /* Single VAP configuration */ |
| 1959 | if (!dut->ap_is_dual) |
| 1960 | vap_id = vap_count; |
| 1961 | |
| 1962 | if (strlen(dut->ap2_ssid)) { |
| 1963 | owrt_ap_add_vap(dut, vap_count + 1, "device", buf); |
| 1964 | /* SSID */ |
| 1965 | snprintf(buf, sizeof(buf), "\"%s\"", dut->ap2_ssid); |
| 1966 | owrt_ap_set_vap(dut, vap_count + 1, "ssid", buf); |
| 1967 | |
| 1968 | if (dut->ap2_key_mgmt == AP2_OSEN) { |
| 1969 | owrt_ap_set_vap(dut, vap_count + 1, |
| 1970 | "osen", "1"); |
| 1971 | snprintf(buf, sizeof(buf), "wpa2"); |
| 1972 | owrt_ap_set_vap(dut, vap_count + 1, |
| 1973 | "encryption", buf); |
| 1974 | snprintf(buf, sizeof(buf), "%s", |
| 1975 | dut->ap2_radius_ipaddr); |
| 1976 | owrt_ap_set_vap(dut, vap_count + 1, |
| 1977 | "auth_server", buf); |
| 1978 | snprintf(buf, sizeof(buf), "%d", |
| 1979 | dut->ap2_radius_port); |
| 1980 | owrt_ap_set_vap(dut, vap_count + 1, |
| 1981 | "auth_port", buf); |
| 1982 | snprintf(buf, sizeof(buf), "%s", |
| 1983 | dut->ap2_radius_password); |
| 1984 | owrt_ap_set_vap(dut, vap_count + 1, |
| 1985 | "auth_secret", buf); |
| 1986 | } |
| 1987 | } |
| 1988 | |
| 1989 | /* SSID */ |
| 1990 | snprintf(buf, sizeof(buf), "\"%s\"", dut->ap_ssid); |
| 1991 | owrt_ap_set_vap(dut, vap_count, "ssid", buf); |
| 1992 | |
| 1993 | /* Encryption */ |
| 1994 | switch (dut->ap_key_mgmt) { |
| 1995 | case AP_OPEN: |
| 1996 | if (dut->ap_cipher == AP_WEP) { |
| 1997 | owrt_ap_set_vap(dut, vap_count, "encryption", |
| 1998 | "wep-mixed"); |
| 1999 | owrt_ap_set_vap(dut, vap_count, "key", |
| 2000 | dut->ap_wepkey); |
| 2001 | } else { |
| 2002 | owrt_ap_set_vap(dut, vap_count, "encryption", |
| 2003 | "none"); |
| 2004 | } |
| 2005 | break; |
| 2006 | case AP_WPA2_PSK: |
| 2007 | case AP_WPA2_PSK_MIXED: |
| 2008 | case AP_WPA_PSK: |
| 2009 | if (dut->ap_key_mgmt == AP_WPA2_PSK) { |
| 2010 | snprintf(buf, sizeof(buf), "psk2"); |
| 2011 | } else if (dut->ap_key_mgmt == AP_WPA2_PSK_MIXED) { |
| 2012 | snprintf(buf, sizeof(buf), "psk-mixed"); |
| 2013 | } else { |
| 2014 | snprintf(buf, sizeof(buf), "psk"); |
| 2015 | } |
| 2016 | |
| 2017 | if (dut->ap_cipher == AP_CCMP_TKIP) { |
| 2018 | strncat(buf, "+ccmp+tkip", |
Jouni Malinen | 0a05d50 | 2016-08-29 21:34:13 +0300 | [diff] [blame] | 2019 | sizeof(buf) - strlen(buf) - 1); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2020 | } else if (dut->ap_cipher == AP_TKIP) { |
| 2021 | strncat(buf, "+tkip", |
Jouni Malinen | 0a05d50 | 2016-08-29 21:34:13 +0300 | [diff] [blame] | 2022 | sizeof(buf) - strlen(buf) - 1); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2023 | } else { |
| 2024 | strncat(buf, "+ccmp", |
Jouni Malinen | 0a05d50 | 2016-08-29 21:34:13 +0300 | [diff] [blame] | 2025 | sizeof(buf) - strlen(buf) - 1); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2026 | } |
| 2027 | |
| 2028 | owrt_ap_set_vap(dut, vap_count, "encryption", buf); |
| 2029 | snprintf(buf, sizeof(buf), "\"%s\"", |
| 2030 | dut->ap_passphrase); |
| 2031 | owrt_ap_set_vap(dut, vap_count, "key", buf); |
| 2032 | break; |
| 2033 | case AP_WPA2_EAP: |
| 2034 | case AP_WPA2_EAP_MIXED: |
| 2035 | case AP_WPA_EAP: |
| 2036 | if (dut->ap_key_mgmt == AP_WPA2_EAP) { |
| 2037 | snprintf(buf, sizeof(buf), "wpa2"); |
| 2038 | } else if (dut->ap_key_mgmt == AP_WPA2_EAP_MIXED) { |
| 2039 | snprintf(buf, sizeof(buf), "wpa-mixed"); |
| 2040 | } else { |
| 2041 | snprintf(buf, sizeof(buf), "wpa"); |
| 2042 | } |
| 2043 | |
| 2044 | if (dut->ap_cipher == AP_CCMP_TKIP) { |
Jouni Malinen | 0a05d50 | 2016-08-29 21:34:13 +0300 | [diff] [blame] | 2045 | strncat(buf, "+ccmp+tkip", |
| 2046 | sizeof(buf) - strlen(buf) - 1); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2047 | } else if (dut->ap_cipher == AP_TKIP) { |
Jouni Malinen | 0a05d50 | 2016-08-29 21:34:13 +0300 | [diff] [blame] | 2048 | strncat(buf, "+tkip", |
| 2049 | sizeof(buf) - strlen(buf) - 1); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2050 | } else { |
Jouni Malinen | 0a05d50 | 2016-08-29 21:34:13 +0300 | [diff] [blame] | 2051 | strncat(buf, "+ccmp", |
| 2052 | sizeof(buf) - strlen(buf) - 1); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2053 | } |
| 2054 | owrt_ap_set_vap(dut, vap_count, "encryption", buf); |
| 2055 | snprintf(buf, sizeof(buf), "%s", dut->ap_radius_ipaddr); |
| 2056 | owrt_ap_set_vap(dut, vap_count, "auth_server", buf); |
| 2057 | snprintf(buf, sizeof(buf), "%d", dut->ap_radius_port); |
| 2058 | owrt_ap_set_vap(dut, vap_count, "auth_port", buf); |
| 2059 | snprintf(buf, sizeof(buf), "%s", |
| 2060 | dut->ap_radius_password); |
| 2061 | owrt_ap_set_vap(dut, vap_count, "auth_secret", buf); |
| 2062 | break; |
| 2063 | } |
| 2064 | |
| 2065 | if (!dut->ap_is_dual) |
| 2066 | break; |
| 2067 | } |
| 2068 | |
| 2069 | if (dut->ap_is_dual) |
| 2070 | return 1; |
| 2071 | |
| 2072 | /* PMF */ |
| 2073 | snprintf(buf, sizeof(buf), "%d", dut->ap_pmf); |
| 2074 | owrt_ap_set_vap(dut, vap_id, "ieee80211w", buf); |
| 2075 | |
| 2076 | /* Add SHA256 */ |
| 2077 | snprintf(buf, sizeof(buf), "%d", dut->ap_add_sha256); |
| 2078 | owrt_ap_set_vap(dut, vap_id, "add_sha256", buf); |
| 2079 | |
Sarvepalli, Rajesh Babu | 24dc7e4 | 2016-03-18 21:27:26 +0530 | [diff] [blame] | 2080 | /* Enable RSN preauthentication, if asked to */ |
| 2081 | snprintf(buf, sizeof(buf), "%d", dut->ap_rsn_preauth); |
| 2082 | owrt_ap_set_vap(dut, vap_id, "rsn_preauth", buf); |
| 2083 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2084 | /* Hotspot 2.0 */ |
| 2085 | if (dut->ap_hs2) { |
| 2086 | int ret; |
| 2087 | |
| 2088 | ret = owrt_ap_config_vap_hs2(dut, vap_id); |
| 2089 | if (ret) |
| 2090 | return ret; |
| 2091 | } |
| 2092 | |
| 2093 | /* Interworking */ |
| 2094 | if (dut->ap_interworking) { |
| 2095 | snprintf(buf, sizeof(buf), "%d", dut->ap_access_net_type); |
| 2096 | owrt_ap_set_vap(dut, vap_id, "access_network_type", buf); |
| 2097 | snprintf(buf, sizeof(buf), "%d", dut->ap_internet); |
| 2098 | owrt_ap_set_vap(dut, vap_id, "internet", buf); |
| 2099 | snprintf(buf, sizeof(buf), "%d", dut->ap_venue_group); |
| 2100 | owrt_ap_set_vap(dut, vap_id, "venue_group", buf); |
| 2101 | snprintf(buf, sizeof(buf), "%d", dut->ap_venue_type); |
| 2102 | owrt_ap_set_vap(dut, vap_id, "venue_type", buf); |
| 2103 | snprintf(buf, sizeof(buf), "%s", dut->ap_hessid); |
| 2104 | owrt_ap_set_vap(dut, vap_id, "hessid", buf); |
| 2105 | |
| 2106 | if (dut->ap_gas_cb_delay > 0) { |
| 2107 | snprintf(buf, sizeof(buf), "%d", dut->ap_gas_cb_delay); |
| 2108 | owrt_ap_set_vap(dut, vap_id, "gas_comeback_delay", buf); |
| 2109 | } |
| 2110 | |
| 2111 | if (dut->ap_roaming_cons[0]) { |
| 2112 | char *rcons, *temp_ptr; |
| 2113 | |
| 2114 | rcons = strdup(dut->ap_roaming_cons); |
| 2115 | if (rcons == NULL) |
| 2116 | return 0; |
| 2117 | |
| 2118 | temp_ptr = strchr(rcons, ';'); |
| 2119 | |
| 2120 | if (temp_ptr) |
| 2121 | *temp_ptr++ = '\0'; |
| 2122 | |
| 2123 | owrt_ap_set_list_vap(dut, vap_id, "roaming_consortium", |
| 2124 | rcons); |
| 2125 | |
| 2126 | if (temp_ptr) |
| 2127 | owrt_ap_set_list_vap(dut, vap_id, |
| 2128 | "roaming_consortium", |
| 2129 | temp_ptr); |
| 2130 | |
| 2131 | free(rcons); |
| 2132 | } |
| 2133 | } |
| 2134 | |
| 2135 | if (dut->ap_venue_name) { |
| 2136 | owrt_ap_set_list_vap(dut, vap_id, "venue_name", |
| 2137 | "'P\"eng:Wi-Fi Alliance\\n2989 Copper Road\\nSanta Clara, CA 95051, USA\"'"); |
| 2138 | owrt_ap_set_list_vap(dut, vap_id, "venue_name", |
| 2139 | "\'"ANQP_VENUE_NAME_1_CHI"\'"); |
| 2140 | } |
| 2141 | |
| 2142 | if (dut->ap_net_auth_type == 1) { |
| 2143 | owrt_ap_set_vap(dut, vap_id, "network_auth_type", |
| 2144 | "'00https://tandc-server.wi-fi.org'"); |
| 2145 | } else if (dut->ap_net_auth_type == 2) { |
| 2146 | owrt_ap_set_vap(dut, vap_id, "network_auth_type", "'01'"); |
| 2147 | } |
| 2148 | |
| 2149 | if (dut->ap_nai_realm_list == 1) { |
| 2150 | owrt_ap_set_list_vap(dut, vap_id, "nai_realm", |
| 2151 | "'0,mail.example.com;cisco.com;wi-fi.org,21[2:4][5:7]'"); |
| 2152 | owrt_ap_set_list_vap(dut, vap_id, "nai_realm", |
| 2153 | "'0,wi-fi.org;example.com,13[5:6]'"); |
| 2154 | |
| 2155 | } else if (dut->ap_nai_realm_list == 2) { |
| 2156 | owrt_ap_set_list_vap(dut, vap_id, "nai_realm", |
| 2157 | "'0,wi-fi.org,21[2:4][5:7]'"); |
| 2158 | } else if (dut->ap_nai_realm_list == 3) { |
| 2159 | owrt_ap_set_list_vap(dut, vap_id, "nai_realm", |
| 2160 | "'0,cisco.com;wi-fi.org,21[2:4][5:7]'"); |
| 2161 | owrt_ap_set_list_vap(dut, vap_id, "nai_realm", |
| 2162 | "'0,wi-fi.org;example.com,13[5:6]'"); |
| 2163 | } else if (dut->ap_nai_realm_list == 4) { |
| 2164 | owrt_ap_set_list_vap(dut, vap_id, "nai_realm", |
| 2165 | "'0,mail.example.com,21[2:4][5:7],13[5:6]'"); |
| 2166 | } else if (dut->ap_nai_realm_list == 5) { |
| 2167 | owrt_ap_set_list_vap(dut, vap_id, "nai_realm", |
| 2168 | "'0,wi-fi.org;ruckuswireless.com,21[2:4][5:7]'"); |
| 2169 | } else if (dut->ap_nai_realm_list == 6) { |
| 2170 | owrt_ap_set_list_vap(dut, vap_id, "nai_realm", |
| 2171 | "'0,wi-fi.org;mail.example.com,21[2:4][5:7]'"); |
| 2172 | } else if (dut->ap_nai_realm_list == 7) { |
| 2173 | owrt_ap_set_list_vap(dut, vap_id, "nai_realm", |
| 2174 | "'0,wi-fi.org,13[5:6]'"); |
| 2175 | owrt_ap_set_list_vap(dut, vap_id, "nai_realm", |
| 2176 | "'0,wi-fi.org,21[2:4][5:7]'"); |
| 2177 | } |
| 2178 | |
| 2179 | if (dut->ap_domain_name_list[0]) |
| 2180 | owrt_ap_set_list_vap(dut, vap_id, "domain_name", |
| 2181 | dut->ap_domain_name_list); |
| 2182 | |
| 2183 | if (dut->ap_ip_addr_type_avail) |
| 2184 | owrt_ap_set_vap(dut, vap_id, "ipaddr_type_availability", |
| 2185 | "'0c'"); |
| 2186 | |
| 2187 | temp = buf; |
| 2188 | |
| 2189 | *temp++ = '\''; |
| 2190 | |
| 2191 | for (i = 0; dut->ap_plmn_mcc[i][0] && dut->ap_plmn_mnc[i][0]; i++) { |
| 2192 | if (i) |
| 2193 | *temp++ = ';'; |
| 2194 | |
| 2195 | snprintf(temp, |
| 2196 | sizeof(dut->ap_plmn_mcc[i]) + |
| 2197 | sizeof(dut->ap_plmn_mnc[i]) + 1, |
| 2198 | "%s,%s", |
| 2199 | dut->ap_plmn_mcc[i], |
| 2200 | dut->ap_plmn_mnc[i]); |
| 2201 | |
| 2202 | temp += strlen(dut->ap_plmn_mcc[i]) + |
| 2203 | strlen(dut->ap_plmn_mnc[i]) + 1; |
| 2204 | } |
| 2205 | |
| 2206 | *temp++ = '\''; |
| 2207 | *temp++ = '\0'; |
| 2208 | |
| 2209 | if (i) |
| 2210 | owrt_ap_set_vap(dut, vap_id, "anqp_3gpp_cell_net", buf); |
| 2211 | |
| 2212 | if (dut->ap_qos_map_set == 1) |
| 2213 | owrt_ap_set_vap(dut, vap_id, "qos_map_set", QOS_MAP_SET_1); |
| 2214 | else if (dut->ap_qos_map_set == 2) |
| 2215 | owrt_ap_set_vap(dut, vap_id, "qos_map_set", QOS_MAP_SET_2); |
| 2216 | |
| 2217 | /* Proxy-ARP */ |
| 2218 | snprintf(buf, sizeof(buf), "%d", dut->ap_proxy_arp); |
| 2219 | owrt_ap_set_vap(dut, vap_id, "proxyarp", buf); |
| 2220 | |
| 2221 | /* DGAF */ |
| 2222 | snprintf(buf, sizeof(buf), "%d", dut->ap_dgaf_disable); |
| 2223 | /* parse to hostapd */ |
| 2224 | owrt_ap_set_vap(dut, vap_id, "disable_dgaf", buf); |
| 2225 | /* parse to wifi driver */ |
| 2226 | owrt_ap_set_vap(dut, vap_id, "dgaf_disable", buf); |
| 2227 | |
| 2228 | /* HCBSSLoad */ |
| 2229 | if (dut->ap_bss_load) { |
| 2230 | unsigned int bssload = 0; |
| 2231 | |
| 2232 | if (dut->ap_bss_load == 1) { |
| 2233 | /* STA count: 1, CU: 50, AAC: 65535 */ |
| 2234 | bssload = 0x0132ffff; |
| 2235 | } else if (dut->ap_bss_load == 2) { |
| 2236 | /* STA count: 1, CU: 200, AAC: 65535 */ |
| 2237 | bssload = 0x01c8ffff; |
| 2238 | } else if (dut->ap_bss_load == 3) { |
| 2239 | /* STA count: 1, CU: 75, AAC: 65535 */ |
| 2240 | bssload = 0x014bffff; |
| 2241 | } |
| 2242 | |
| 2243 | snprintf(buf, sizeof(buf), "%d", bssload); |
| 2244 | owrt_ap_set_vap(dut, vap_id, "hcbssload", buf); |
| 2245 | } |
| 2246 | |
| 2247 | /* L2TIF */ |
| 2248 | if (dut->ap_l2tif) |
| 2249 | owrt_ap_set_vap(dut, vap_id, "l2tif", "1"); |
| 2250 | |
| 2251 | if (dut->ap_disable_protection == 1) |
| 2252 | owrt_ap_set_vap(dut, vap_id, "enablertscts", "0"); |
| 2253 | |
| 2254 | if (dut->ap_txBF) { |
| 2255 | owrt_ap_set_vap(dut, vap_id, "vhtsubfee", "1"); |
| 2256 | owrt_ap_set_vap(dut, vap_id, "vhtsubfer", "1"); |
| 2257 | } |
| 2258 | |
Mohammed Shafi Shajakhan | 061af00 | 2016-06-02 20:10:54 +0530 | [diff] [blame] | 2259 | if (dut->ap_mu_txBF) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2260 | owrt_ap_set_vap(dut, vap_id, "vhtmubfer", "1"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2261 | |
Vasanthakumar Pandurangan | 2b5431d | 2016-01-12 15:52:48 +0530 | [diff] [blame] | 2262 | if (dut->ap_tx_stbc) { |
| 2263 | /* STBC and beamforming are mutually exclusive features */ |
| 2264 | owrt_ap_set_vap(dut, vap_id, "implicitbf", "0"); |
| 2265 | } |
| 2266 | |
Priyadharshini Gowthaman | 8fb1504 | 2015-11-25 18:27:41 +0530 | [diff] [blame] | 2267 | /* enable dfsmode */ |
| 2268 | snprintf(buf, sizeof(buf), "%d", dut->ap_dfs_mode); |
| 2269 | owrt_ap_set_vap(dut, vap_id, "doth", buf); |
| 2270 | |
priyadharshini gowthaman | 2323d0a | 2016-09-02 15:48:02 -0700 | [diff] [blame] | 2271 | if (dut->program == PROGRAM_LOC && dut->ap_interworking) { |
| 2272 | char anqpval[1024]; |
| 2273 | |
| 2274 | owrt_ap_set_vap(dut, vap_id, "interworking", "1"); |
| 2275 | |
priyadharshini gowthaman | 2500f20 | 2016-10-13 17:13:55 -0700 | [diff] [blame] | 2276 | if (dut->ap_lci == 1 && strlen(dut->ap2_ssid) == 0) { |
priyadharshini gowthaman | 2323d0a | 2016-09-02 15:48:02 -0700 | [diff] [blame] | 2277 | sprintf(anqpval, "'265:0010%s%s060101'", |
| 2278 | dut->ap_val_lci, dut->ap_infoz); |
| 2279 | owrt_ap_set_list_vap(dut, vap_id, "anqp_elem", anqpval); |
| 2280 | } |
| 2281 | |
| 2282 | if (dut->ap_lcr == 1) { |
| 2283 | sprintf(anqpval, "'266:0000b2555302ae%s'", |
| 2284 | dut->ap_val_lcr); |
| 2285 | owrt_ap_set_list_vap(dut, vap_id, "anqp_elem", anqpval); |
| 2286 | } |
| 2287 | |
| 2288 | if (dut->ap_fqdn_held == 1 && dut->ap_fqdn_supl == 1) |
| 2289 | owrt_ap_set_list_vap(dut, vap_id, "anqp_elem", |
| 2290 | "'267:00110168656c642e6578616d706c652e636f6d0011027375706c2e6578616d706c652e636f6d'"); |
| 2291 | } |
| 2292 | |
priyadharshini gowthaman | b4e05fc | 2016-10-13 15:02:35 -0700 | [diff] [blame] | 2293 | if (dut->program == PROGRAM_MBO) { |
| 2294 | owrt_ap_set_vap(dut, vap_id, "interworking", "1"); |
| 2295 | owrt_ap_set_vap(dut, vap_id, "mbo", "1"); |
| 2296 | owrt_ap_set_vap(dut, vap_id, "rrm", "1"); |
| 2297 | owrt_ap_set_vap(dut, vap_id, "mbo_cellular_pref", "1"); |
| 2298 | |
| 2299 | owrt_ap_set_list_vap(dut, vap_id, "anqp_elem", |
| 2300 | "'272:34108cfdf0020df1f7000000733000030101'"); |
| 2301 | } |
| 2302 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2303 | return 1; |
| 2304 | } |
| 2305 | |
| 2306 | |
priyadharshini gowthaman | 2500f20 | 2016-10-13 17:13:55 -0700 | [diff] [blame] | 2307 | static int owrt_ap_config_vap_anqp(struct sigma_dut *dut) |
| 2308 | { |
| 2309 | char anqpval[1024]; |
| 2310 | unsigned char addr[6]; |
| 2311 | unsigned char addr2[6]; |
| 2312 | struct ifreq ifr; |
| 2313 | char *ifname; |
| 2314 | int s; |
| 2315 | int vap_id = 0; |
| 2316 | |
| 2317 | s = socket(AF_INET, SOCK_DGRAM, 0); |
| 2318 | if (s < 0) { |
| 2319 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open socket"); |
| 2320 | return -1; |
| 2321 | } |
| 2322 | |
| 2323 | memset(&ifr, 0, sizeof(ifr)); |
| 2324 | ifname = "ath0"; |
| 2325 | strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); |
| 2326 | if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) { |
| 2327 | perror("ioctl"); |
| 2328 | close(s); |
| 2329 | return -1; |
| 2330 | } |
| 2331 | memcpy(addr, ifr.ifr_hwaddr.sa_data, 6); |
| 2332 | |
| 2333 | memset(&ifr, 0, sizeof(ifr)); |
| 2334 | ifname = "ath01"; |
| 2335 | strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); |
| 2336 | if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) { |
| 2337 | perror("ioctl"); |
| 2338 | close(s); |
| 2339 | return -1; |
| 2340 | } |
| 2341 | close(s); |
| 2342 | memcpy(addr2, ifr.ifr_hwaddr.sa_data, 6); |
| 2343 | |
| 2344 | snprintf(anqpval, sizeof(anqpval), |
| 2345 | "'265:0010%s%s060101070d00%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x'", |
| 2346 | dut->ap_val_lci, dut->ap_infoz, |
| 2347 | addr[0], addr[1], addr[2], addr[3], addr[4], addr[5], |
| 2348 | addr2[0], addr2[1], addr2[2], addr2[3], addr2[4], addr2[5]); |
| 2349 | |
| 2350 | owrt_ap_set_list_vap(dut, vap_id, "anqp_elem", anqpval); |
| 2351 | return 0; |
| 2352 | } |
| 2353 | |
| 2354 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2355 | static int owrt_ap_post_config_commit(struct sigma_dut *dut, |
| 2356 | struct sigma_conn *conn, |
| 2357 | struct sigma_cmd *cmd) |
| 2358 | { |
| 2359 | if (dut->ap_key_mgmt != AP_OPEN) { |
| 2360 | /* allow some time for hostapd to start before returning |
| 2361 | * success */ |
| 2362 | usleep(500000); |
| 2363 | |
| 2364 | if (run_hostapd_cli(dut, "ping") != 0) { |
| 2365 | send_resp(dut, conn, SIGMA_ERROR, |
| 2366 | "errorCode,Failed to talk to hostapd"); |
| 2367 | return 0; |
| 2368 | } |
| 2369 | } |
| 2370 | |
| 2371 | if (get_openwrt_driver_type() == OPENWRT_DRIVER_ATHEROS) |
| 2372 | ath_ap_set_params(dut); |
| 2373 | |
| 2374 | /* Send response */ |
| 2375 | return 1; |
| 2376 | } |
| 2377 | |
| 2378 | |
| 2379 | static int cmd_owrt_ap_config_commit(struct sigma_dut *dut, |
| 2380 | struct sigma_conn *conn, |
| 2381 | struct sigma_cmd *cmd) |
| 2382 | { |
| 2383 | /* Stop the AP */ |
| 2384 | run_system(dut, "wifi down"); |
| 2385 | |
| 2386 | /* Reset the wireless configuration */ |
Mohammed Shafi Shajakhan | f789f82 | 2016-04-07 18:53:16 +0530 | [diff] [blame] | 2387 | run_system(dut, "rm -rf /etc/config/wireless"); |
| 2388 | switch (get_openwrt_driver_type()) { |
| 2389 | case OPENWRT_DRIVER_ATHEROS: |
| 2390 | run_system(dut, "wifi detect qcawifi > /etc/config/wireless"); |
| 2391 | break; |
| 2392 | default: |
| 2393 | run_system(dut, "wifi detect > /etc/config/wireless"); |
| 2394 | break; |
| 2395 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2396 | |
| 2397 | /* Configure Radio & VAP, commit the config */ |
| 2398 | owrt_ap_config_radio(dut); |
| 2399 | owrt_ap_config_vap(dut); |
| 2400 | run_system(dut, "uci commit"); |
| 2401 | |
| 2402 | /* Start AP */ |
| 2403 | run_system(dut, "wifi up"); |
| 2404 | |
priyadharshini gowthaman | 2500f20 | 2016-10-13 17:13:55 -0700 | [diff] [blame] | 2405 | if (dut->ap_lci == 1 && dut->ap_interworking && |
| 2406 | strlen(dut->ap2_ssid) > 0) { |
| 2407 | owrt_ap_config_vap_anqp(dut); |
| 2408 | run_system(dut, "uci commit"); |
| 2409 | run_system(dut, "wifi"); |
| 2410 | } |
| 2411 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2412 | return owrt_ap_post_config_commit(dut, conn, cmd); |
| 2413 | } |
| 2414 | |
| 2415 | |
| 2416 | static void cmd_owrt_ap_hs2_reset(struct sigma_dut *dut) |
| 2417 | { |
| 2418 | unsigned char bssid[6]; |
| 2419 | char buf[100]; |
| 2420 | char *ifname, *radio_name; |
| 2421 | int vap_id = 0; |
| 2422 | |
| 2423 | if (sigma_radio_ifname[0] && |
| 2424 | strcmp(sigma_radio_ifname[0], "wifi2") == 0) { |
| 2425 | ifname = "ath2"; |
| 2426 | radio_name = "wifi2"; |
| 2427 | vap_id = 2; |
| 2428 | } else if (sigma_radio_ifname[0] && |
| 2429 | strcmp(sigma_radio_ifname[0], "wifi1") == 0) { |
| 2430 | ifname = "ath1"; |
| 2431 | radio_name = "wifi1"; |
| 2432 | vap_id = 1; |
| 2433 | } else { |
| 2434 | ifname = "ath0"; |
| 2435 | radio_name = "wifi0"; |
| 2436 | vap_id = 0; |
| 2437 | } |
| 2438 | |
| 2439 | if (!get_hwaddr(ifname, bssid)) { |
| 2440 | snprintf(buf, sizeof(buf), "%s", bssid); |
| 2441 | owrt_ap_set_vap(dut, vap_id, "hessid", buf); |
| 2442 | snprintf(dut->ap_hessid, sizeof(dut->ap_hessid), |
| 2443 | "%02x:%02x:%02x:%02x:%02x:%02x", |
| 2444 | bssid[0], bssid[1], bssid[2], bssid[3], |
| 2445 | bssid[4], bssid[5]); |
| 2446 | } else { |
| 2447 | if (!get_hwaddr(radio_name, bssid)) { |
| 2448 | snprintf(buf, sizeof(buf), "%s", dut->ap_hessid); |
| 2449 | owrt_ap_set_vap(dut, vap_id, "hessid", buf); |
| 2450 | snprintf(dut->ap_hessid, sizeof(dut->ap_hessid), |
| 2451 | "%02x:%02x:%02x:%02x:%02x:%02x", |
| 2452 | bssid[0], bssid[1], bssid[2], bssid[3], |
| 2453 | bssid[4], bssid[5]); |
| 2454 | } else { |
| 2455 | /* Select & enable/disable radios */ |
| 2456 | if (sigma_radio_ifname[0] && |
| 2457 | strcmp(sigma_radio_ifname[0], "wifi2") == 0) { |
| 2458 | /* We want to use wifi2 */ |
| 2459 | owrt_ap_set_radio(dut, 0, "disabled", "1"); |
| 2460 | owrt_ap_set_radio(dut, 1, "disabled", "1"); |
| 2461 | owrt_ap_set_radio(dut, 2, "disabled", "0"); |
| 2462 | owrt_ap_set_vap(dut, vap_id, "device", "wifi2"); |
| 2463 | } else if (sigma_radio_ifname[0] && |
| 2464 | strcmp(sigma_radio_ifname[0], "wifi1") == 0) { |
| 2465 | /* We want to use wifi1 */ |
| 2466 | owrt_ap_set_radio(dut, 0, "disabled", "1"); |
| 2467 | owrt_ap_set_radio(dut, 1, "disabled", "0"); |
| 2468 | owrt_ap_set_vap(dut, vap_id, "device", "wifi1"); |
| 2469 | } else { |
| 2470 | /* We want to use wifi0 */ |
| 2471 | owrt_ap_set_radio(dut, 0, "disabled", "0"); |
| 2472 | owrt_ap_set_radio(dut, 1, "disabled", "1"); |
| 2473 | owrt_ap_set_vap(dut, vap_id, "device", "wifi0"); |
| 2474 | } |
| 2475 | |
| 2476 | run_system(dut, "uci commit"); |
| 2477 | run_system(dut, "wifi up"); |
| 2478 | |
| 2479 | if (!get_hwaddr(radio_name, bssid)) { |
| 2480 | snprintf(buf, sizeof(buf), "%s", |
| 2481 | dut->ap_hessid); |
| 2482 | owrt_ap_set_vap(dut, vap_id, "hessid", buf); |
| 2483 | snprintf(dut->ap_hessid, sizeof(dut->ap_hessid), |
| 2484 | "%02x:%02x:%02x:%02x:%02x:%02x", |
| 2485 | bssid[0], bssid[1], bssid[2], bssid[3], |
| 2486 | bssid[4], bssid[5]); |
| 2487 | } |
| 2488 | } |
| 2489 | } |
| 2490 | } |
| 2491 | |
| 2492 | |
| 2493 | static int cmd_ap_reboot(struct sigma_dut *dut, struct sigma_conn *conn, |
| 2494 | struct sigma_cmd *cmd) |
| 2495 | { |
| 2496 | switch (get_driver_type()) { |
| 2497 | case DRIVER_ATHEROS: |
| 2498 | run_system(dut, "apdown"); |
| 2499 | sleep(1); |
| 2500 | run_system(dut, "reboot"); |
| 2501 | break; |
| 2502 | case DRIVER_OPENWRT: |
| 2503 | run_system(dut, "wifi down"); |
| 2504 | sleep(1); |
| 2505 | run_system(dut, "reboot"); |
| 2506 | break; |
| 2507 | default: |
| 2508 | sigma_dut_print(dut, DUT_MSG_INFO, "Ignore ap_reboot command"); |
| 2509 | break; |
| 2510 | } |
| 2511 | |
| 2512 | return 1; |
| 2513 | } |
| 2514 | |
| 2515 | |
| 2516 | int ascii2hexstr(const char *str, char *hex) |
| 2517 | { |
| 2518 | int i, length; |
| 2519 | |
| 2520 | length = strlen(str); |
| 2521 | |
| 2522 | for (i = 0; i < length; i++) |
| 2523 | snprintf(hex + i * 2, 3, "%X", str[i]); |
| 2524 | |
| 2525 | hex[length * 2] = '\0'; |
| 2526 | return 1; |
| 2527 | } |
| 2528 | |
| 2529 | |
| 2530 | static int kill_process(struct sigma_dut *dut, char *proc_name, |
| 2531 | unsigned char is_proc_instance_one, int sig) |
| 2532 | { |
| 2533 | #ifdef __linux__ |
| 2534 | struct dirent *dp, *dp_in; |
| 2535 | const char *direc = "/proc/"; |
| 2536 | char buf[100]; |
| 2537 | DIR *dir = opendir(direc); |
| 2538 | DIR *dir_in; |
| 2539 | FILE *fp; |
| 2540 | char *pid, *temp; |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 2541 | char *saveptr; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2542 | |
| 2543 | if (dir == NULL) |
| 2544 | return -1; |
| 2545 | |
| 2546 | while ((dp = readdir(dir)) != NULL) { |
| 2547 | if (dp->d_type != DT_DIR) |
| 2548 | continue; |
| 2549 | |
| 2550 | snprintf(buf, sizeof(buf), "%s%s", direc, dp->d_name); |
| 2551 | dir_in = opendir(buf); |
| 2552 | if (dir_in == NULL) |
| 2553 | continue; |
| 2554 | dp_in = readdir(dir_in); |
| 2555 | closedir(dir_in); |
| 2556 | if (dp_in == NULL) |
| 2557 | continue; |
| 2558 | snprintf(buf, sizeof(buf), "%s%s/stat", direc, dp->d_name); |
| 2559 | fp = fopen(buf, "r"); |
| 2560 | if (fp == NULL) |
| 2561 | continue; |
| 2562 | if (fgets(buf, 100, fp) == NULL) |
| 2563 | buf[0] = '\0'; |
| 2564 | fclose(fp); |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 2565 | pid = strtok_r(buf, " ", &saveptr); |
| 2566 | temp = strtok_r(NULL, " ", &saveptr); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2567 | if (pid && temp && |
| 2568 | strncmp(temp, proc_name, strlen(proc_name)) == 0) { |
| 2569 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 2570 | "killing %s process with PID %s", |
| 2571 | proc_name, pid); |
| 2572 | snprintf(buf, sizeof(buf), "kill -%d %d", sig, |
| 2573 | atoi(pid)); |
| 2574 | run_system(dut, buf); |
| 2575 | if (is_proc_instance_one) |
| 2576 | break; |
| 2577 | } |
| 2578 | } |
| 2579 | |
| 2580 | closedir(dir); |
| 2581 | |
| 2582 | return 0; |
| 2583 | #else /* __linux__ */ |
| 2584 | return -1; |
| 2585 | #endif /* __linux__ */ |
| 2586 | } |
| 2587 | |
| 2588 | |
| 2589 | static int run_ndc(struct sigma_dut *dut, char *buf) |
| 2590 | { |
| 2591 | sigma_dut_print(dut, DUT_MSG_INFO, "CMD NDC:: %s", buf); |
| 2592 | sleep(2); |
| 2593 | return run_system(dut, buf); |
| 2594 | } |
| 2595 | |
| 2596 | |
| 2597 | static int sigma_write_cfg(struct sigma_dut *dut, const char *pfile, |
| 2598 | const char *field, const char *value) |
| 2599 | { |
| 2600 | FILE *fcfg, *ftmp; |
| 2601 | char buf[MAX_CONF_LINE_LEN + 1]; |
| 2602 | int len, found = 0, res; |
| 2603 | |
| 2604 | /* Open the configuration file */ |
| 2605 | fcfg = fopen(pfile, "r"); |
| 2606 | if (!fcfg) { |
| 2607 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 2608 | "Failed to open hostapd conf file"); |
| 2609 | return -1; |
| 2610 | } |
| 2611 | |
| 2612 | snprintf(buf, sizeof(buf), "%s~", pfile); |
| 2613 | /* Open a temporary file */ |
| 2614 | ftmp = fopen(buf, "w+"); |
| 2615 | if (!ftmp) { |
| 2616 | fclose(fcfg); |
| 2617 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 2618 | "Failed to open temp buf"); |
| 2619 | return -1; |
| 2620 | } |
| 2621 | |
| 2622 | /* Read the values from the configuration file */ |
| 2623 | len = strlen(field); |
| 2624 | while (fgets(buf, MAX_CONF_LINE_LEN, fcfg)) { |
| 2625 | char *pline = buf; |
| 2626 | |
| 2627 | /* commented line */ |
| 2628 | if (buf[0] == '#') |
| 2629 | pline++; |
| 2630 | |
| 2631 | /* Identify the configuration parameter to be updated */ |
| 2632 | if (!found && strncmp(pline, field, len) == 0 && |
| 2633 | pline[len] == '=') { |
| 2634 | snprintf(buf, sizeof(buf), "%s=%s\n", field, value); |
| 2635 | found = 1; |
| 2636 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 2637 | "Updated hostapd conf file"); |
| 2638 | } |
| 2639 | |
| 2640 | fprintf(ftmp, "%s", buf); |
| 2641 | } |
| 2642 | |
| 2643 | if (!found) { |
| 2644 | /* Configuration line not found */ |
| 2645 | /* Add the new line at the end of file */ |
| 2646 | fprintf(ftmp, "%s=%s\n", field, value); |
| 2647 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 2648 | "Adding a new line in hostapd conf file"); |
| 2649 | } |
| 2650 | |
| 2651 | fclose(fcfg); |
| 2652 | fclose(ftmp); |
| 2653 | |
| 2654 | snprintf(buf, sizeof(buf), "%s~", pfile); |
| 2655 | |
| 2656 | /* Restore the updated configuration file */ |
| 2657 | res = rename(buf, pfile); |
| 2658 | |
| 2659 | /* Remove the temporary file. Ignore the return value */ |
| 2660 | unlink(buf); |
| 2661 | |
| 2662 | /* chmod is needed because open() may not set permissions properly |
| 2663 | * depending on the current umask */ |
| 2664 | if (chmod(pfile, 0660) < 0) { |
| 2665 | unlink(pfile); |
| 2666 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 2667 | "Error changing permissions"); |
| 2668 | return -1; |
| 2669 | } |
| 2670 | |
| 2671 | if (res < 0) { |
| 2672 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 2673 | "Error restoring conf file"); |
| 2674 | return -1; |
| 2675 | } |
| 2676 | |
| 2677 | return 0; |
| 2678 | } |
| 2679 | |
| 2680 | |
| 2681 | static int cmd_wcn_ap_config_commit(struct sigma_dut *dut, |
| 2682 | struct sigma_conn *conn, |
| 2683 | struct sigma_cmd *cmd) |
| 2684 | { |
| 2685 | char buf[100]; |
| 2686 | struct stat s; |
| 2687 | int num_tries = 0, ret; |
| 2688 | |
| 2689 | kill_process(dut, "(netd)", 1, SIGKILL); |
| 2690 | |
| 2691 | while (num_tries < 10) { |
| 2692 | ret = run_ndc(dut, "ndc softap stopap"); |
| 2693 | num_tries++; |
| 2694 | if (WIFEXITED(ret)) |
| 2695 | ret = WEXITSTATUS(ret); |
| 2696 | /* On success, NDC exits with 0 */ |
| 2697 | if (ret == 0) |
| 2698 | break; |
| 2699 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 2700 | "Try No. %d: ndc softap stopap failed, exit code %d", |
| 2701 | num_tries, ret); |
| 2702 | } |
| 2703 | |
| 2704 | if (ret != 0) |
| 2705 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 2706 | "ndc softap stopap command failed for 10 times - giving up"); |
| 2707 | |
| 2708 | #ifdef ANDROID |
| 2709 | /* Unload/Load driver to cleanup the state of the driver */ |
| 2710 | wifi_unload_driver(); |
| 2711 | wifi_load_driver(); |
| 2712 | #else /* ANDROID */ |
| 2713 | run_ndc(dut, "ndc softap qccmd set enable_softap=0"); |
| 2714 | run_ndc(dut, "ndc softap qccmd set enable_softap=1"); |
| 2715 | #endif /* ANDROID */ |
| 2716 | |
| 2717 | switch (dut->ap_mode) { |
| 2718 | case AP_11g: |
| 2719 | run_ndc(dut, "ndc softap qccmd set hw_mode=g-only"); |
| 2720 | break; |
| 2721 | case AP_11b: |
| 2722 | run_ndc(dut, "ndc softap qccmd set hw_mode=b-only"); |
| 2723 | break; |
| 2724 | case AP_11ng: |
| 2725 | run_ndc(dut, "ndc softap qccmd set hw_mode=n"); |
| 2726 | break; |
| 2727 | case AP_11a: |
| 2728 | run_ndc(dut, "ndc softap qccmd set hw_mode=a-only"); |
| 2729 | break; |
| 2730 | case AP_11na: |
| 2731 | run_ndc(dut, "ndc softap qccmd set hw_mode=n"); |
| 2732 | break; |
| 2733 | case AP_11ac: |
| 2734 | run_ndc(dut, "ndc softap qccmd set hw_mode=ac"); |
| 2735 | break; |
| 2736 | default: |
| 2737 | break; |
| 2738 | } |
| 2739 | |
| 2740 | snprintf(buf, sizeof(buf), "ndc softap qccmd set channel=%d", |
| 2741 | dut->ap_channel); |
| 2742 | run_ndc(dut, buf); |
| 2743 | |
| 2744 | /* |
| 2745 | * ndc doesn't support double quotes as SSID string, so re-write |
| 2746 | * hostapd configuration file to update SSID. |
| 2747 | */ |
| 2748 | if (dut->ap_ssid[0] != '\0') |
| 2749 | sigma_write_cfg(dut, ANDROID_CONFIG_FILE, "ssid", dut->ap_ssid); |
| 2750 | |
| 2751 | switch (dut->ap_key_mgmt) { |
| 2752 | case AP_OPEN: |
| 2753 | if (dut->ap_cipher == AP_WEP) { |
| 2754 | run_ndc(dut, "ndc softap qccmd set security_mode=1"); |
| 2755 | snprintf(buf, sizeof(buf), |
| 2756 | "ndc softap qccmd set wep_key0=%s", |
| 2757 | dut->ap_wepkey); |
| 2758 | run_ndc(dut, buf); |
| 2759 | } else { |
| 2760 | run_ndc(dut, "ndc softap qccmd set security_mode=0"); |
| 2761 | } |
| 2762 | break; |
| 2763 | case AP_WPA2_PSK: |
| 2764 | case AP_WPA2_PSK_MIXED: |
| 2765 | case AP_WPA_PSK: |
| 2766 | if (dut->ap_key_mgmt == AP_WPA2_PSK) |
| 2767 | run_ndc(dut, "ndc softap qccmd set security_mode=3"); |
| 2768 | else if (dut->ap_key_mgmt == AP_WPA2_PSK_MIXED) |
| 2769 | run_ndc(dut, "ndc softap qccmd set security_mode=4"); |
| 2770 | else |
| 2771 | run_ndc(dut, "ndc softap qccmd set security_mode=2"); |
| 2772 | |
| 2773 | /* |
| 2774 | * ndc doesn't support some special characters as passphrase, |
| 2775 | * so re-write hostapd configuration file to update Passphrase. |
| 2776 | */ |
| 2777 | if (dut->ap_passphrase[0] != '\0') |
| 2778 | sigma_write_cfg(dut, ANDROID_CONFIG_FILE, |
| 2779 | "wpa_passphrase", dut->ap_passphrase); |
| 2780 | |
| 2781 | if (dut->ap_cipher == AP_CCMP_TKIP) |
| 2782 | run_ndc(dut, "ndc softap qccmd set wpa_pairwise=" |
| 2783 | "TKIP CCMP"); |
| 2784 | else if (dut->ap_cipher == AP_TKIP) |
| 2785 | run_ndc(dut, "ndc softap qccmd set wpa_pairwise=" |
| 2786 | "TKIP"); |
| 2787 | else |
| 2788 | run_ndc(dut, "ndc softap qccmd set wpa_pairwise=" |
| 2789 | "CCMP &"); |
| 2790 | break; |
| 2791 | case AP_WPA2_EAP: |
| 2792 | case AP_WPA2_EAP_MIXED: |
| 2793 | case AP_WPA_EAP: |
| 2794 | /* Not supported */ |
| 2795 | break; |
| 2796 | } |
| 2797 | |
| 2798 | switch (dut->ap_pmf) { |
| 2799 | case AP_PMF_DISABLED: |
| 2800 | run_ndc(dut, "ndc softap qccmd set ieee80211w=0"); |
| 2801 | break; |
| 2802 | case AP_PMF_OPTIONAL: |
| 2803 | run_ndc(dut, "ndc softap qccmd set ieee80211w=1"); |
| 2804 | if (dut->ap_add_sha256) |
| 2805 | run_ndc(dut, "ndc softap qccmd set wpa_key_mgmt=WPA-PSK WPA-PSK-SHA256"); |
| 2806 | else |
| 2807 | run_ndc(dut, "ndc softap qccmd set wpa_key_mgmt=WPA-PSK"); |
| 2808 | break; |
| 2809 | case AP_PMF_REQUIRED: |
| 2810 | run_ndc(dut, "ndc softap qccmd set ieee80211w=2"); |
| 2811 | run_ndc(dut, "ndc softap qccmd set wpa_key_mgmt=WPA-PSK-SHA256"); |
| 2812 | break; |
| 2813 | } |
| 2814 | |
| 2815 | if (dut->ap_countrycode[0]) { |
| 2816 | snprintf(buf, sizeof(buf), |
| 2817 | "ndc softap qccmd set country_code=%s", |
| 2818 | dut->ap_countrycode); |
| 2819 | run_ndc(dut, buf); |
| 2820 | } |
| 2821 | |
Pradeep Reddy POTTETI | fba27db | 2015-11-20 16:42:22 +0530 | [diff] [blame] | 2822 | if (dut->ap_regulatory_mode == AP_80211D_MODE_ENABLED) |
| 2823 | run_ndc(dut, "ndc softap qccmd set ieee80211d=1"); |
| 2824 | |
| 2825 | if (dut->ap_dfs_mode == AP_DFS_MODE_ENABLED) |
| 2826 | run_ndc(dut, "ndc softap qccmd set ieee80211h=1"); |
| 2827 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2828 | run_ndc(dut, "ndc softap startap"); |
| 2829 | |
| 2830 | snprintf(buf, sizeof(buf), "%s%s", sigma_wpas_ctrl, sigma_main_ifname); |
| 2831 | num_tries = 0; |
| 2832 | while (num_tries < 10 && (ret = stat(buf, &s) != 0)) { |
| 2833 | run_ndc(dut, "ndc softap stopap"); |
| 2834 | run_ndc(dut, "ndc softap startap"); |
| 2835 | num_tries++; |
| 2836 | } |
| 2837 | |
| 2838 | if (num_tries == 10) { |
| 2839 | sigma_dut_print(dut, DUT_MSG_INFO, "Tried 10 times with ctrl " |
| 2840 | "iface %s :: reboot the APDUT", buf); |
| 2841 | return ret; |
| 2842 | } |
| 2843 | |
| 2844 | sigma_dut_print(dut, DUT_MSG_INFO, "setting ip addr %s mask %s", |
| 2845 | ap_inet_addr, ap_inet_mask); |
| 2846 | snprintf(buf, sizeof(buf), "ifconfig %s %s netmask %s up", |
| 2847 | sigma_main_ifname, ap_inet_addr, ap_inet_mask); |
| 2848 | if (system(buf) != 0) { |
| 2849 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 2850 | "Failed to intialize the interface"); |
| 2851 | return -1; |
| 2852 | } |
| 2853 | |
| 2854 | return 1; |
| 2855 | } |
| 2856 | |
| 2857 | |
| 2858 | static int append_hostapd_conf_hs2(struct sigma_dut *dut, FILE *f) |
| 2859 | { |
| 2860 | fprintf(f, "hs20=1\nhs20_deauth_req_timeout=3\n" |
| 2861 | "disable_dgaf=%d\n", dut->ap_dgaf_disable); |
| 2862 | |
| 2863 | if (dut->ap_oper_name) { |
| 2864 | fprintf(f, "hs20_oper_friendly_name=eng:Wi-Fi Alliance\n"); |
| 2865 | fprintf(f, "hs20_oper_friendly_name=chi:Wi-Fi\xe8\x81\x94\xe7\x9b\x9f\n"); |
| 2866 | } |
| 2867 | |
| 2868 | if (dut->ap_wan_metrics == 1) |
| 2869 | fprintf(f, "hs20_wan_metrics=01:2500:384:0:0:10\n"); |
| 2870 | else if (dut->ap_wan_metrics == 2) |
| 2871 | fprintf(f, "hs20_wan_metrics=01:1500:384:20:20:10\n"); |
| 2872 | else if (dut->ap_wan_metrics == 3) |
| 2873 | fprintf(f, "hs20_wan_metrics=01:2000:1000:20:20:10\n"); |
| 2874 | else if (dut->ap_wan_metrics == 4) |
| 2875 | fprintf(f, "hs20_wan_metrics=01:8000:1000:20:20:10\n"); |
| 2876 | else if (dut->ap_wan_metrics == 5) |
| 2877 | fprintf(f, "hs20_wan_metrics=01:9000:5000:20:20:10\n"); |
| 2878 | |
| 2879 | if (dut->ap_conn_capab == 1) { |
| 2880 | fprintf(f, "hs20_conn_capab=1:0:0\n"); |
| 2881 | fprintf(f, "hs20_conn_capab=6:20:1\n"); |
| 2882 | fprintf(f, "hs20_conn_capab=6:22:0\n"); |
| 2883 | fprintf(f, "hs20_conn_capab=6:80:1\n"); |
| 2884 | fprintf(f, "hs20_conn_capab=6:443:1\n"); |
| 2885 | fprintf(f, "hs20_conn_capab=6:1723:0\n"); |
| 2886 | fprintf(f, "hs20_conn_capab=6:5060:0\n"); |
| 2887 | fprintf(f, "hs20_conn_capab=17:500:1\n"); |
| 2888 | fprintf(f, "hs20_conn_capab=17:5060:0\n"); |
| 2889 | fprintf(f, "hs20_conn_capab=17:4500:1\n"); |
| 2890 | fprintf(f, "hs20_conn_capab=50:0:1\n"); |
| 2891 | } else if (dut->ap_conn_capab == 2) { |
| 2892 | fprintf(f, "hs20_conn_capab=6:80:1\n"); |
| 2893 | fprintf(f, "hs20_conn_capab=6:443:1\n"); |
| 2894 | fprintf(f, "hs20_conn_capab=17:5060:1\n"); |
| 2895 | fprintf(f, "hs20_conn_capab=6:5060:1\n"); |
| 2896 | } else if (dut->ap_conn_capab == 3) { |
| 2897 | fprintf(f, "hs20_conn_capab=6:80:1\n"); |
| 2898 | fprintf(f, "hs20_conn_capab=6:443:1\n"); |
| 2899 | } else if (dut->ap_conn_capab == 4) { |
| 2900 | fprintf(f, "hs20_conn_capab=6:80:1\n"); |
| 2901 | fprintf(f, "hs20_conn_capab=6:443:1\n"); |
| 2902 | fprintf(f, "hs20_conn_capab=6:5060:1\n"); |
| 2903 | fprintf(f, "hs20_conn_capab=17:5060:1\n"); |
| 2904 | } |
| 2905 | |
| 2906 | if (dut->ap_oper_class == 1) |
| 2907 | fprintf(f, "hs20_operating_class=51\n"); |
| 2908 | else if (dut->ap_oper_class == 2) |
| 2909 | fprintf(f, "hs20_operating_class=73\n"); |
| 2910 | else if (dut->ap_oper_class == 3) |
| 2911 | fprintf(f, "hs20_operating_class=5173\n"); |
| 2912 | |
| 2913 | if (dut->ap_osu_provider_list) { |
| 2914 | char *osu_friendly_name = NULL; |
| 2915 | char *osu_icon = NULL; |
| 2916 | char *osu_ssid = NULL; |
| 2917 | char *osu_nai = NULL; |
| 2918 | char *osu_service_desc = NULL; |
| 2919 | char *hs20_icon_filename = NULL; |
| 2920 | char hs20_icon[150]; |
| 2921 | int osu_method; |
| 2922 | |
| 2923 | hs20_icon_filename = "icon_red_zxx.png"; |
| 2924 | if (dut->ap_osu_icon_tag == 2) |
| 2925 | hs20_icon_filename = "wifi-abgn-logo_270x73.png"; |
| 2926 | snprintf(hs20_icon, sizeof(hs20_icon), |
| 2927 | "128:61:zxx:image/png:icon_red_zxx.png:/etc/ath/%s", |
| 2928 | hs20_icon_filename); |
| 2929 | osu_icon = "icon_red_zxx.png"; |
| 2930 | osu_ssid = "OSU"; |
| 2931 | osu_friendly_name = "kor:SP 빨강 테스트 전용"; |
| 2932 | osu_service_desc = "kor:테스트 목적으로 무료 서비스"; |
| 2933 | osu_method = (dut->ap_osu_method[0] == 0xFF) ? 1 : dut->ap_osu_method[0]; |
| 2934 | |
| 2935 | if (strlen(dut->ap_osu_server_uri[0])) |
| 2936 | fprintf(f, "osu_server_uri=%s\n", dut->ap_osu_server_uri[0]); |
| 2937 | else |
| 2938 | fprintf(f, "osu_server_uri=https://osu-server.r2-testbed.wi-fi.org/\n"); |
| 2939 | |
| 2940 | switch (dut->ap_osu_provider_list) { |
| 2941 | case 1: |
| 2942 | case 101: |
| 2943 | fprintf(f, "osu_friendly_name=eng:SP Red Test Only\n"); |
| 2944 | fprintf(f, "osu_service_desc=eng:Free service for test purpose\n"); |
| 2945 | hs20_icon_filename = "icon_red_eng.png"; |
| 2946 | if (dut->ap_osu_icon_tag == 2) |
| 2947 | hs20_icon_filename = "wifi-abgn-logo_270x73.png"; |
| 2948 | fprintf(f, "hs20_icon=160:76:eng:image/png:icon_red_eng.png:/etc/ath/%s\n", |
| 2949 | hs20_icon_filename); |
| 2950 | fprintf(f, "osu_icon=icon_red_eng.png\n"); |
| 2951 | break; |
| 2952 | case 2: |
| 2953 | case 102: |
| 2954 | fprintf(f, "osu_friendly_name=eng:Wireless Broadband Alliance\n"); |
| 2955 | fprintf(f, "osu_service_desc=eng:Free service for test purpose\n"); |
| 2956 | hs20_icon_filename = "icon_orange_zxx.png"; |
| 2957 | if (dut->ap_osu_icon_tag == 2) |
| 2958 | hs20_icon_filename = "wifi-abgn-logo_270x73.png"; |
| 2959 | snprintf(hs20_icon, sizeof(hs20_icon), |
| 2960 | "128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s", |
| 2961 | hs20_icon_filename); |
| 2962 | osu_icon = "icon_orange_zxx.png"; |
| 2963 | osu_friendly_name = "kor:와이어리스 브로드밴드 얼라이언스"; |
| 2964 | break; |
| 2965 | case 3: |
| 2966 | case 103: |
| 2967 | osu_friendly_name = "spa:SP Red Test Only"; |
| 2968 | osu_service_desc = "spa:Free service for test purpose"; |
| 2969 | break; |
| 2970 | case 4: |
| 2971 | case 104: |
| 2972 | fprintf(f, "osu_friendly_name=eng:SP Orange Test Only\n"); |
| 2973 | fprintf(f, "osu_service_desc=eng:Free service for test purpose\n"); |
| 2974 | hs20_icon_filename = "icon_orange_eng.png"; |
| 2975 | if (dut->ap_osu_icon_tag == 2) |
| 2976 | hs20_icon_filename = "wifi-abgn-logo_270x73.png"; |
| 2977 | fprintf(f, "hs20_icon=160:76:eng:image/png:icon_orange_eng.png:/etc/ath/%s\n", |
| 2978 | hs20_icon_filename); |
| 2979 | fprintf(f, "osu_icon=icon_orange_eng.png\n"); |
| 2980 | osu_friendly_name = "kor:SP 오렌지 테스트 전용"; |
| 2981 | |
| 2982 | hs20_icon_filename = "icon_orange_zxx.png"; |
| 2983 | if (dut->ap_osu_icon_tag == 2) |
| 2984 | hs20_icon_filename = "wifi-abgn-logo_270x73.png"; |
| 2985 | snprintf(hs20_icon, sizeof(hs20_icon), |
| 2986 | "128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s", |
| 2987 | hs20_icon_filename); |
| 2988 | osu_icon = "icon_orange_zxx.png"; |
| 2989 | break; |
| 2990 | case 5: |
| 2991 | case 105: |
| 2992 | fprintf(f, "osu_friendly_name=eng:SP Orange Test Only\n"); |
| 2993 | fprintf(f, "osu_service_desc=eng:Free service for test purpose\n"); |
| 2994 | osu_friendly_name = "kor:SP 오렌지 테스트 전용"; |
| 2995 | hs20_icon_filename = "icon_orange_zxx.png"; |
| 2996 | if (dut->ap_osu_icon_tag == 2) |
| 2997 | hs20_icon_filename = "wifi-abgn-logo_270x73.png"; |
| 2998 | snprintf(hs20_icon, sizeof(hs20_icon), |
| 2999 | "128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s", |
| 3000 | hs20_icon_filename); |
| 3001 | osu_icon = "icon_orange_zxx.png"; |
| 3002 | break; |
| 3003 | case 6: |
| 3004 | case 106: |
| 3005 | fprintf(f, "osu_friendly_name=eng:SP Green Test Only\n"); |
| 3006 | fprintf(f, "osu_friendly_name=kor:SP 초록 테스트 전용\n"); |
| 3007 | hs20_icon_filename = "icon_green_zxx.png"; |
| 3008 | if (dut->ap_osu_icon_tag == 2) |
| 3009 | hs20_icon_filename = "wifi-abgn-logo_270x73.png"; |
| 3010 | fprintf(f, "hs20_icon=128:61:zxx:image/png:icon_green_zxx.png:/etc/ath/%s\n", |
| 3011 | hs20_icon_filename); |
| 3012 | fprintf(f, "osu_icon=icon_green_zxx.png\n"); |
| 3013 | osu_method = (dut->ap_osu_method[0] == 0xFF) ? 0 : dut->ap_osu_method[0]; |
| 3014 | fprintf(f, "osu_method_list=%d\n", osu_method); |
| 3015 | |
| 3016 | if (strlen(dut->ap_osu_server_uri[1])) |
| 3017 | fprintf(f, "osu_server_uri=%s\n", dut->ap_osu_server_uri[1]); |
| 3018 | else |
| 3019 | fprintf(f, "osu_server_uri=https://osu-server.r2-testbed.wi-fi.org/\n"); |
| 3020 | fprintf(f, "osu_friendly_name=eng:SP Orange Test Only\n"); |
| 3021 | hs20_icon_filename = "icon_orange_zxx.png"; |
| 3022 | if (dut->ap_osu_icon_tag == 2) |
| 3023 | hs20_icon_filename = "wifi-abgn-logo_270x73.png"; |
| 3024 | snprintf(hs20_icon, sizeof(hs20_icon), |
| 3025 | "128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s", |
| 3026 | hs20_icon_filename); |
| 3027 | osu_icon = "icon_orange_zxx.png"; |
| 3028 | osu_friendly_name = "kor:SP 오렌지 테스트 전용"; |
| 3029 | osu_method = (dut->ap_osu_method[1] == 0xFF) ? 0 : dut->ap_osu_method[1]; |
| 3030 | osu_service_desc = NULL; |
| 3031 | break; |
| 3032 | case 7: |
| 3033 | case 107: |
| 3034 | fprintf(f, "osu_friendly_name=eng:SP Green Test Only\n"); |
| 3035 | fprintf(f, "osu_service_desc=eng:Free service for test purpose\n"); |
| 3036 | hs20_icon_filename = "icon_green_eng.png"; |
| 3037 | if (dut->ap_osu_icon_tag == 2) |
| 3038 | hs20_icon_filename = "wifi-abgn-logo_270x73.png"; |
| 3039 | fprintf(f, "hs20_icon=160:76:eng:image/png:icon_green_eng.png:/etc/ath/%s\n", |
| 3040 | hs20_icon_filename); |
| 3041 | fprintf(f, "osu_icon=icon_green_eng.png\n"); |
| 3042 | osu_friendly_name = "kor:SP 초록 테스트 전용"; |
| 3043 | |
| 3044 | hs20_icon_filename = "icon_green_zxx.png"; |
| 3045 | if (dut->ap_osu_icon_tag == 2) |
| 3046 | hs20_icon_filename = "wifi-abgn-logo_270x73.png"; |
| 3047 | snprintf(hs20_icon, sizeof(hs20_icon), |
| 3048 | "128:61:zxx:image/png:icon_green_zxx.png:/etc/ath/%s", |
| 3049 | hs20_icon_filename); |
| 3050 | osu_icon = "icon_green_zxx.png"; |
| 3051 | break; |
| 3052 | case 8: |
| 3053 | case 108: |
| 3054 | fprintf(f, "osu_friendly_name=eng:SP Red Test Only\n"); |
| 3055 | fprintf(f, "osu_service_desc=eng:Free service for test purpose\n"); |
| 3056 | osu_ssid = "OSU-Encrypted"; |
| 3057 | osu_nai = "anonymous@hotspot.net"; |
| 3058 | break; |
| 3059 | case 9: |
| 3060 | case 109: |
| 3061 | osu_ssid = "OSU-OSEN"; |
| 3062 | osu_nai = "test-anonymous@wi-fi.org"; |
| 3063 | osu_friendly_name = "eng:SP Orange Test Only"; |
| 3064 | hs20_icon_filename = "icon_orange_zxx.png"; |
| 3065 | if (dut->ap_osu_icon_tag == 2) |
| 3066 | hs20_icon_filename = "wifi-abgn-logo_270x73.png"; |
| 3067 | snprintf(hs20_icon, sizeof(hs20_icon), |
| 3068 | "128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s", |
| 3069 | hs20_icon_filename); |
| 3070 | osu_icon = "icon_orange_zxx.png"; |
| 3071 | osu_method = (dut->ap_osu_method[0] == 0xFF) ? 1 : dut->ap_osu_method[0]; |
| 3072 | osu_service_desc = NULL; |
| 3073 | break; |
| 3074 | default: |
| 3075 | break; |
| 3076 | } |
| 3077 | |
| 3078 | if (strlen(dut->ap_osu_ssid)) { |
| 3079 | if (strcmp(dut->ap2_ssid, dut->ap_osu_ssid) && |
| 3080 | strcmp(dut->ap2_ssid, osu_ssid)) { |
| 3081 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3082 | "OSU_SSID and " |
| 3083 | "WLAN_TAG2 SSID differ"); |
| 3084 | return -2; |
| 3085 | } |
| 3086 | fprintf(f, "osu_ssid=\"%s\"\n", dut->ap_osu_ssid); |
| 3087 | } else |
| 3088 | fprintf(f, "osu_ssid=\"%s\"\n", osu_ssid); |
| 3089 | |
| 3090 | |
| 3091 | if (osu_friendly_name) |
| 3092 | fprintf(f, "osu_friendly_name=%s\n", osu_friendly_name); |
| 3093 | |
| 3094 | if (osu_service_desc) |
| 3095 | fprintf(f, "osu_service_desc=%s\n", osu_service_desc); |
| 3096 | |
| 3097 | if (osu_nai) |
| 3098 | fprintf(f, "osu_nai=%s\n", osu_nai); |
| 3099 | |
| 3100 | fprintf(f, "hs20_icon=%s\n", hs20_icon); |
| 3101 | |
| 3102 | if (osu_icon) |
| 3103 | fprintf(f, "osu_icon=%s\n", osu_icon); |
| 3104 | |
| 3105 | if (dut->ap_osu_provider_list > 100) |
| 3106 | fprintf(f, "osu_method_list=0\n"); |
| 3107 | else |
| 3108 | fprintf(f, "osu_method_list=%d\n", osu_method); |
| 3109 | } |
| 3110 | |
| 3111 | return 0; |
| 3112 | } |
| 3113 | |
| 3114 | |
| 3115 | static void write_ap_roaming_cons(FILE *f, const char *list) |
| 3116 | { |
| 3117 | char *buf, *pos, *end; |
| 3118 | |
| 3119 | if (list == NULL || list[0] == '\0') |
| 3120 | return; |
| 3121 | |
| 3122 | buf = strdup(list); |
| 3123 | if (buf == NULL) |
| 3124 | return; |
| 3125 | |
| 3126 | pos = buf; |
| 3127 | while (pos && *pos) { |
| 3128 | end = strchr(pos, ';'); |
| 3129 | if (end) |
| 3130 | *end++ = '\0'; |
| 3131 | fprintf(f, "roaming_consortium=%s\n", pos); |
| 3132 | pos = end; |
| 3133 | } |
| 3134 | |
| 3135 | free(buf); |
| 3136 | } |
| 3137 | |
| 3138 | |
| 3139 | static int append_hostapd_conf_interworking(struct sigma_dut *dut, FILE *f) |
| 3140 | { |
| 3141 | int i; |
| 3142 | char buf[100], *temp; |
| 3143 | |
| 3144 | if (dut->ap_gas_cb_delay > 0) |
| 3145 | fprintf(f, "gas_comeback_delay=%d\n", |
| 3146 | dut->ap_gas_cb_delay); |
| 3147 | |
| 3148 | fprintf(f, "interworking=1\n" |
| 3149 | "access_network_type=%d\n" |
| 3150 | "internet=%d\n" |
| 3151 | "asra=0\n" |
| 3152 | "esr=0\n" |
| 3153 | "uesa=0\n" |
| 3154 | "venue_group=%d\n" |
| 3155 | "venue_type=%d\n", |
| 3156 | dut->ap_access_net_type, |
| 3157 | dut->ap_internet, |
| 3158 | dut->ap_venue_group, |
| 3159 | dut->ap_venue_type); |
| 3160 | if (dut->ap_hessid[0]) |
| 3161 | fprintf(f, "hessid=%s\n", dut->ap_hessid); |
| 3162 | |
| 3163 | write_ap_roaming_cons(f, dut->ap_roaming_cons); |
| 3164 | |
| 3165 | if (dut->ap_venue_name) { |
| 3166 | fprintf(f, "venue_name=P\"eng:Wi-Fi Alliance\\n2989 Copper Road\\nSanta Clara, CA 95051, USA\"\n"); |
| 3167 | fprintf(f, "venue_name=%s\n", ANQP_VENUE_NAME_1_CHI); |
| 3168 | } |
| 3169 | |
| 3170 | if (dut->ap_net_auth_type == 1) |
| 3171 | fprintf(f, "network_auth_type=00https://tandc-server.wi-fi.org\n"); |
| 3172 | else if (dut->ap_net_auth_type == 2) |
| 3173 | fprintf(f, "network_auth_type=01\n"); |
| 3174 | |
| 3175 | if (dut->ap_nai_realm_list == 1) { |
| 3176 | fprintf(f, "nai_realm=0,mail.example.com;cisco.com;wi-fi.org,21[2:4][5:7]\n"); |
| 3177 | fprintf(f, "nai_realm=0,wi-fi.org;example.com,13[5:6]\n"); |
| 3178 | } else if (dut->ap_nai_realm_list == 2) { |
| 3179 | fprintf(f, "nai_realm=0,wi-fi.org,21[2:4][5:7]\n"); |
| 3180 | } else if (dut->ap_nai_realm_list == 3) { |
| 3181 | fprintf(f, "nai_realm=0,cisco.com;wi-fi.org,21[2:4][5:7]\n"); |
| 3182 | fprintf(f, "nai_realm=0,wi-fi.org;example.com,13[5:6]\n"); |
| 3183 | } else if (dut->ap_nai_realm_list == 4) { |
| 3184 | fprintf(f, "nai_realm=0,mail.example.com,21[2:4][5:7],13[5:6]\n"); |
| 3185 | } else if (dut->ap_nai_realm_list == 5) { |
| 3186 | fprintf(f, "nai_realm=0,wi-fi.org;ruckuswireless.com,21[2:4][5:7]\n"); |
| 3187 | } else if (dut->ap_nai_realm_list == 6) { |
| 3188 | fprintf(f, "nai_realm=0,wi-fi.org;mail.example.com,21[2:4][5:7]\n"); |
| 3189 | } else if (dut->ap_nai_realm_list == 7) { |
| 3190 | fprintf(f, "nai_realm=0,wi-fi.org,13[5:6]\n"); |
| 3191 | fprintf(f, "nai_realm=0,wi-fi.org,21[2:4][5:7]\n"); |
| 3192 | } |
| 3193 | |
| 3194 | if (dut->ap_domain_name_list[0]) { |
| 3195 | fprintf(f, "domain_name=%s\n", |
| 3196 | dut->ap_domain_name_list); |
| 3197 | } |
| 3198 | |
| 3199 | if (dut->ap_ip_addr_type_avail == 1) { |
| 3200 | fprintf(f, "ipaddr_type_availability=0c\n"); |
| 3201 | } |
| 3202 | |
| 3203 | temp = buf; |
| 3204 | for (i = 0; dut->ap_plmn_mcc[i][0] && dut->ap_plmn_mnc[i][0]; |
| 3205 | i++) { |
| 3206 | if (i) |
| 3207 | *temp++ = ';'; |
| 3208 | |
| 3209 | snprintf(temp, |
| 3210 | sizeof(dut->ap_plmn_mcc[i]) + |
| 3211 | sizeof(dut->ap_plmn_mnc[i]) + 1, |
| 3212 | "%s,%s", |
| 3213 | dut->ap_plmn_mcc[i], |
| 3214 | dut->ap_plmn_mnc[i]); |
| 3215 | |
| 3216 | temp += strlen(dut->ap_plmn_mcc[i]) + |
| 3217 | strlen(dut->ap_plmn_mnc[i]) + 1; |
| 3218 | } |
| 3219 | if (i) |
| 3220 | fprintf(f, "anqp_3gpp_cell_net=%s\n", buf); |
| 3221 | |
| 3222 | if (dut->ap_qos_map_set == 1) |
| 3223 | fprintf(f, "qos_map_set=%s\n", QOS_MAP_SET_1); |
| 3224 | else if (dut->ap_qos_map_set == 2) |
| 3225 | fprintf(f, "qos_map_set=%s\n", QOS_MAP_SET_2); |
| 3226 | |
| 3227 | return 0; |
| 3228 | } |
| 3229 | |
| 3230 | |
| 3231 | static int ath_ap_append_hostapd_conf(struct sigma_dut *dut) |
| 3232 | { |
| 3233 | FILE *f; |
| 3234 | |
| 3235 | if (kill_process(dut, "(hostapd)", 1, SIGTERM) == 0 || |
| 3236 | system("killall hostapd") == 0) { |
| 3237 | int i; |
| 3238 | |
| 3239 | /* Wait some time to allow hostapd to complete cleanup before |
| 3240 | * starting a new process */ |
| 3241 | for (i = 0; i < 10; i++) { |
| 3242 | usleep(500000); |
| 3243 | if (system("pidof hostapd") != 0) |
| 3244 | break; |
| 3245 | } |
| 3246 | } |
| 3247 | |
| 3248 | f = fopen("/tmp/secath0", "a"); |
| 3249 | if (f == NULL) |
| 3250 | return -2; |
| 3251 | |
| 3252 | if (dut->ap_hs2 && append_hostapd_conf_hs2(dut, f)) { |
| 3253 | fclose(f); |
| 3254 | return -2; |
| 3255 | } |
| 3256 | |
| 3257 | if (dut->ap_interworking && append_hostapd_conf_interworking(dut, f)) { |
| 3258 | fclose(f); |
| 3259 | return -2; |
| 3260 | } |
| 3261 | |
| 3262 | fflush(f); |
| 3263 | fclose(f); |
| 3264 | return ath_ap_start_hostapd(dut); |
| 3265 | } |
| 3266 | |
| 3267 | |
| 3268 | static int ath_ap_start_hostapd(struct sigma_dut *dut) |
| 3269 | { |
| 3270 | if (dut->ap2_key_mgmt == AP2_OSEN) |
| 3271 | run_system(dut, "hostapd -B /tmp/secath0 /tmp/secath1 -e /etc/wpa2/entropy"); |
| 3272 | else |
| 3273 | run_system(dut, "hostapd -B /tmp/secath0 -e /etc/wpa2/entropy"); |
| 3274 | |
| 3275 | return 0; |
| 3276 | } |
| 3277 | |
| 3278 | |
| 3279 | #define LE16(a) ((((a) & 0xff) << 8) | (((a) >> 8) & 0xff)) |
| 3280 | |
| 3281 | static int cmd_ath_ap_anqpserver_start(struct sigma_dut *dut) |
| 3282 | { |
| 3283 | FILE *f; |
| 3284 | int nai_realm = 0, domain_name = 0, oper_name = 0, venue_name = 0, |
| 3285 | wan_metrics = 0, conn_cap = 0, ipaddr_avail = 0, cell_net = 0; |
| 3286 | char buf[100]; |
| 3287 | int i; |
| 3288 | |
| 3289 | f = fopen("/root/anqpserver.conf", "w"); |
| 3290 | if (f == NULL) |
| 3291 | return -1; |
| 3292 | |
| 3293 | if (dut->ap_nai_realm_list == 1) { |
| 3294 | nai_realm = 1; |
| 3295 | fprintf(f, "dyn_nai_home_realm=encoding=00realm=mail.example.com;eap_method=15auth_id=02auth_val=04auth_id=05auth_val=07encoding=00realm=cisco.com;eap_method=15auth_id=02auth_val=04auth_id=05auth_val=07encoding=00realm=wi-fi.org;eap_method=15auth_id=02auth_val=04auth_id=05auth_val=07encoding=00realm=example.com;eap_method=0Dauth_id=05auth_val=06encoding=00realm=wi-fi.org;eap_method=0Dauth_id=05auth_val=06\n"); |
| 3296 | } else if (dut->ap_nai_realm_list == 2) { |
| 3297 | nai_realm = 1; |
| 3298 | fprintf(f, "dyn_nai_home_realm=encoding=00realm=wi-fi.org;eap_method=0Dauth_id=05auth_val=06\n"); |
| 3299 | } else if (dut->ap_nai_realm_list == 3) { |
| 3300 | nai_realm = 1; |
| 3301 | fprintf(f, "dyn_nai_home_realm=encoding=00realm=cisco.com;eap_method=15auth_id=02auth_val=04auth_id=05auth_val=07encoding=00realm=wi-fi.org;eap_method=15auth_id=02auth_val=04auth_id=05auth_val=07encoding=00realm=example.com;eap_method=0Dauth_id=05auth_val=06encoding=00realm=wi-fi.org;eap_method=0Dauth_id=05auth_val=06\n"); |
| 3302 | } else if (dut->ap_nai_realm_list == 4) { |
| 3303 | nai_realm = 1; |
| 3304 | fprintf(f, "dyn_nai_home_realm=encoding=00realm=mail.example.com;eap_method=15auth_id=02auth_val=04auth_id=05auth_val=07encoding=00realm=mail.example.com;eap_method=0Dauth_id=05auth_val=06\n"); |
| 3305 | } else |
| 3306 | sigma_dut_print(dut, DUT_MSG_INFO, "not setting nai_realm"); |
| 3307 | |
| 3308 | if (dut->ap_domain_name_list[0]) { |
| 3309 | char *next, *start, *dnbuf, *dn1, *anqp_dn; |
| 3310 | int len, dn_len_max; |
| 3311 | dnbuf = strdup(dut->ap_domain_name_list); |
Pradeep Reddy POTTETI | 673d85c | 2016-07-26 19:08:07 +0530 | [diff] [blame] | 3312 | if (dnbuf == NULL) { |
| 3313 | fclose(f); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3314 | return 0; |
Pradeep Reddy POTTETI | 673d85c | 2016-07-26 19:08:07 +0530 | [diff] [blame] | 3315 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3316 | |
| 3317 | len = strlen(dnbuf); |
| 3318 | dn_len_max = 50 + len*2; |
| 3319 | anqp_dn = malloc(dn_len_max); |
| 3320 | if (anqp_dn == NULL) { |
| 3321 | free(dnbuf); |
Pradeep Reddy POTTETI | 673d85c | 2016-07-26 19:08:07 +0530 | [diff] [blame] | 3322 | fclose(f); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3323 | return -1; |
| 3324 | } |
| 3325 | start = dnbuf; |
| 3326 | dn1 = anqp_dn; |
| 3327 | while (start && *start) { |
| 3328 | char *hexstr; |
| 3329 | |
| 3330 | next = strchr(start, ','); |
| 3331 | if (next) |
| 3332 | *next++ = '\0'; |
| 3333 | |
| 3334 | len = strlen(start); |
vamsi krishna | 2e88130 | 2016-05-25 15:02:39 +0530 | [diff] [blame] | 3335 | hexstr = malloc(len * 2 + 1); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3336 | if (hexstr == NULL) { |
| 3337 | free(dnbuf); |
| 3338 | free(anqp_dn); |
Pradeep Reddy POTTETI | 673d85c | 2016-07-26 19:08:07 +0530 | [diff] [blame] | 3339 | fclose(f); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3340 | return -1; |
| 3341 | } |
| 3342 | ascii2hexstr(start, hexstr); |
| 3343 | snprintf(dn1, dn_len_max, "%02x%s", len, hexstr); |
| 3344 | free(hexstr); |
| 3345 | dn1 += 2 + len * 2; |
| 3346 | dn_len_max -= 2 + len * 2; |
| 3347 | start = next; |
| 3348 | } |
| 3349 | free(dnbuf); |
| 3350 | if (dut->ap_gas_cb_delay) { |
| 3351 | fprintf(f, "dyn_domain_name=0c01%04x%s", |
| 3352 | LE16((unsigned int) strlen(anqp_dn)), anqp_dn); |
| 3353 | domain_name = 1; |
| 3354 | } else |
| 3355 | fprintf(f, "domain_name=0c01%04x%s", |
| 3356 | LE16((unsigned int) strlen(anqp_dn)), anqp_dn); |
| 3357 | free(anqp_dn); |
| 3358 | } else |
| 3359 | sigma_dut_print(dut, DUT_MSG_INFO, "not setting domain_name"); |
| 3360 | |
| 3361 | sigma_dut_print(dut, DUT_MSG_INFO, "not setting roaming_consortium"); |
| 3362 | |
| 3363 | if (dut->ap_oper_name) { |
| 3364 | if (dut->ap_gas_cb_delay) { |
| 3365 | fprintf(f, "dyn_oper_friendly_name=" |
| 3366 | ANQP_HS20_OPERATOR_FRIENDLY_NAME_1 "\n"); |
| 3367 | oper_name = 1; |
| 3368 | } else |
| 3369 | fprintf(f, "oper_friendly_name=" |
| 3370 | ANQP_HS20_OPERATOR_FRIENDLY_NAME_1 "\n"); |
| 3371 | } else |
| 3372 | sigma_dut_print(dut, DUT_MSG_INFO, "not setting oper_name"); |
| 3373 | |
| 3374 | if (dut->ap_venue_name) { |
| 3375 | if (dut->ap_gas_cb_delay) { |
| 3376 | fprintf(f, "dyn_venue_name=" ANQP_VENUE_NAME_1 "\n"); |
| 3377 | venue_name = 1; |
| 3378 | } else |
| 3379 | fprintf(f, "venue_name=" ANQP_VENUE_NAME_1 "\n"); |
| 3380 | } else |
| 3381 | sigma_dut_print(dut, DUT_MSG_ERROR, "not setting venue_name"); |
| 3382 | |
| 3383 | if (dut->ap_wan_metrics) { |
| 3384 | if (dut->ap_gas_cb_delay) { |
| 3385 | fprintf(f, "dyn_wan_metrics=" ANQP_HS20_WAN_METRICS_1 "\n"); |
| 3386 | wan_metrics = 1; |
| 3387 | } else |
| 3388 | fprintf(f, "wan_metrics=" ANQP_HS20_WAN_METRICS_1 |
| 3389 | "\n"); |
| 3390 | } else |
| 3391 | sigma_dut_print(dut, DUT_MSG_ERROR, "not setting wan_metrics"); |
| 3392 | |
| 3393 | if (dut->ap_conn_capab) { |
| 3394 | if (dut->ap_gas_cb_delay) { |
| 3395 | fprintf(f, "dyn_conn_capability=" |
| 3396 | ANQP_HS20_CONNECTION_CAPABILITY_1 "\n"); |
| 3397 | conn_cap = 1; |
| 3398 | } else |
| 3399 | fprintf(f, "conn_capability=" |
| 3400 | ANQP_HS20_CONNECTION_CAPABILITY_1 "\n"); |
| 3401 | } else |
| 3402 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3403 | "not setting conn_capability"); |
| 3404 | |
| 3405 | if (dut->ap_ip_addr_type_avail) { |
| 3406 | if (dut->ap_gas_cb_delay) { |
| 3407 | fprintf(f, "dyn_ipaddr_type=" ANQP_IP_ADDR_TYPE_1 |
| 3408 | "\n"); |
| 3409 | ipaddr_avail = 1; |
| 3410 | } else |
| 3411 | fprintf(f, "ipaddr_type=" ANQP_IP_ADDR_TYPE_1 "\n"); |
| 3412 | } else |
| 3413 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3414 | "not setting ipaddr_type_avail"); |
| 3415 | |
| 3416 | for (i = 0; dut->ap_plmn_mcc[i][0] && dut->ap_plmn_mnc[i][0]; i++) { |
| 3417 | snprintf(buf + i * 6, sizeof(buf) - i * 6, "%c%c%c%c%c%c", |
| 3418 | dut->ap_plmn_mcc[i][1], |
| 3419 | dut->ap_plmn_mcc[i][0], |
| 3420 | dut->ap_plmn_mnc[i][2] == '\0' ? |
| 3421 | 'f' : dut->ap_plmn_mnc[i][2], |
| 3422 | dut->ap_plmn_mcc[i][2], |
| 3423 | dut->ap_plmn_mnc[i][1], |
| 3424 | dut->ap_plmn_mnc[i][0]); |
| 3425 | } |
| 3426 | if (i) { |
| 3427 | uint16_t ie_len = (i * 3) + 5; |
| 3428 | if (dut->ap_gas_cb_delay) { |
| 3429 | fprintf(f, "dyn_cell_net=0801"); |
| 3430 | cell_net = 1; |
| 3431 | } else |
| 3432 | fprintf(f, "cell_net=0801"); |
| 3433 | fprintf(f, "%04x", LE16(ie_len)); |
| 3434 | fprintf(f, "00"); /* version */ |
| 3435 | fprintf(f, "%02x", (i * 3) + 3); /* user data hdr length */ |
| 3436 | fprintf(f, "00"); /* plmn list */ |
| 3437 | fprintf(f, "%02x", (i * 3) + 1); /* length of plmn list */ |
| 3438 | fprintf(f, "%02x", i); /* number of plmns */ |
| 3439 | fprintf(f, "%s\n", buf); /* plmns */ |
| 3440 | } else |
| 3441 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3442 | "not setting 3gpp_cellular_network"); |
| 3443 | |
| 3444 | if (nai_realm || domain_name || oper_name || venue_name || |
| 3445 | wan_metrics || conn_cap || ipaddr_avail || cell_net) { |
| 3446 | fprintf(f, "anqp_attach="); |
| 3447 | if (venue_name) |
| 3448 | fprintf(f, "00000104%4.4x", dut->ap_gas_cb_delay); |
| 3449 | if (nai_realm) |
| 3450 | fprintf(f, "00000107%4.4x", dut->ap_gas_cb_delay); |
| 3451 | if (cell_net) |
| 3452 | fprintf(f, "00000108%4.4x", dut->ap_gas_cb_delay); |
| 3453 | if (domain_name) |
| 3454 | fprintf(f, "0000010c%4.4x", dut->ap_gas_cb_delay); |
| 3455 | if (oper_name) |
| 3456 | fprintf(f, "00010003%4.4x", dut->ap_gas_cb_delay); |
| 3457 | if (wan_metrics) |
| 3458 | fprintf(f, "00010004%4.4x", dut->ap_gas_cb_delay); |
| 3459 | if (conn_cap) |
| 3460 | fprintf(f, "00010005%4.4x", dut->ap_gas_cb_delay); |
| 3461 | fprintf(f, "00010006%4.4x", dut->ap_gas_cb_delay); |
| 3462 | fprintf(f, "\n"); |
| 3463 | } |
| 3464 | |
| 3465 | fclose(f); |
| 3466 | |
| 3467 | run_system(dut, "anqpserver -i ath0 &"); |
| 3468 | if (!dut->ap_anqpserver_on) |
| 3469 | run_system(dut, "killall anqpserver"); |
| 3470 | |
| 3471 | return 1; |
| 3472 | } |
| 3473 | |
| 3474 | |
| 3475 | static void cmd_ath_ap_radio_config(struct sigma_dut *dut) |
| 3476 | { |
| 3477 | char buf[100]; |
| 3478 | |
| 3479 | run_system(dut, "cfg -a AP_STARTMODE=standard"); |
| 3480 | |
| 3481 | if (sigma_radio_ifname[0] && |
| 3482 | strcmp(sigma_radio_ifname[0], "wifi1") == 0) { |
| 3483 | run_system(dut, "cfg -a AP_RADIO_ID=1"); |
| 3484 | switch (dut->ap_mode) { |
| 3485 | case AP_11g: |
| 3486 | run_system(dut, "cfg -a AP_CHMODE_2=11G"); |
| 3487 | break; |
| 3488 | case AP_11b: |
| 3489 | run_system(dut, "cfg -a AP_CHMODE_2=11B"); |
| 3490 | break; |
| 3491 | case AP_11ng: |
| 3492 | run_system(dut, "cfg -a AP_CHMODE_2=11NGHT20"); |
| 3493 | break; |
| 3494 | case AP_11a: |
| 3495 | run_system(dut, "cfg -a AP_CHMODE_2=11A"); |
| 3496 | break; |
| 3497 | case AP_11na: |
| 3498 | run_system(dut, "cfg -a AP_CHMODE_2=11NAHT20"); |
| 3499 | break; |
| 3500 | case AP_11ac: |
| 3501 | run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT80"); |
| 3502 | break; |
| 3503 | default: |
| 3504 | run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT80"); |
| 3505 | break; |
| 3506 | } |
| 3507 | |
| 3508 | switch (dut->ap_rx_streams) { |
| 3509 | case 1: |
| 3510 | run_system(dut, "cfg -a RX_CHAINMASK_2=1"); |
| 3511 | break; |
| 3512 | case 2: |
| 3513 | run_system(dut, "cfg -a RX_CHAINMASK_2=3"); |
| 3514 | break; |
| 3515 | case 3: |
| 3516 | run_system(dut, "cfg -a RX_CHAINMASK_2=7"); |
| 3517 | break; |
| 3518 | } |
| 3519 | |
| 3520 | switch (dut->ap_tx_streams) { |
| 3521 | case 1: |
| 3522 | run_system(dut, "cfg -a TX_CHAINMASK_2=1"); |
| 3523 | break; |
| 3524 | case 2: |
| 3525 | run_system(dut, "cfg -a TX_CHAINMASK_2=3"); |
| 3526 | break; |
| 3527 | case 3: |
| 3528 | run_system(dut, "cfg -a TX_CHAINMASK_2=7"); |
| 3529 | break; |
| 3530 | } |
| 3531 | |
| 3532 | switch (dut->ap_chwidth) { |
| 3533 | case AP_20: |
| 3534 | run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT20"); |
| 3535 | break; |
| 3536 | case AP_40: |
| 3537 | run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT40"); |
| 3538 | break; |
| 3539 | case AP_80: |
| 3540 | run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT80"); |
| 3541 | break; |
| 3542 | case AP_160: |
| 3543 | case AP_AUTO: |
| 3544 | default: |
| 3545 | run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT80"); |
| 3546 | break; |
| 3547 | } |
| 3548 | |
| 3549 | if (dut->ap_tx_stbc) { |
| 3550 | run_system(dut, "cfg -a TX_STBC_2=1"); |
| 3551 | } |
| 3552 | |
| 3553 | snprintf(buf, sizeof(buf), "cfg -a AP_PRIMARY_CH_2=%d", |
| 3554 | dut->ap_channel); |
| 3555 | |
| 3556 | if (dut->ap_is_dual) { |
| 3557 | switch (dut->ap_mode_1) { |
| 3558 | case AP_11g: |
| 3559 | run_system(dut, "cfg -a AP_CHMODE=11G"); |
| 3560 | break; |
| 3561 | case AP_11b: |
| 3562 | run_system(dut, "cfg -a AP_CHMODE=11B"); |
| 3563 | break; |
| 3564 | case AP_11ng: |
| 3565 | run_system(dut, "cfg -a AP_CHMODE=11NGHT20"); |
| 3566 | break; |
| 3567 | case AP_11a: |
| 3568 | run_system(dut, "cfg -a AP_CHMODE=11A"); |
| 3569 | break; |
| 3570 | case AP_11na: |
| 3571 | run_system(dut, "cfg -a AP_CHMODE=11NAHT20"); |
| 3572 | break; |
| 3573 | case AP_11ac: |
| 3574 | run_system(dut, "cfg -a AP_CHMODE=11ACVHT80"); |
| 3575 | break; |
| 3576 | default: |
| 3577 | run_system(dut, "cfg -a AP_CHMODE=11NGHT20"); |
| 3578 | break; |
| 3579 | } |
| 3580 | snprintf(buf, sizeof(buf), "cfg -a AP_PRIMARY_CH=%d", |
| 3581 | dut->ap_channel_1); |
| 3582 | } |
| 3583 | run_system(dut, buf); |
| 3584 | } else { |
| 3585 | run_system(dut, "cfg -a AP_RADIO_ID=0"); |
| 3586 | switch (dut->ap_mode) { |
| 3587 | case AP_11g: |
| 3588 | run_system(dut, "cfg -a AP_CHMODE=11G"); |
| 3589 | break; |
| 3590 | case AP_11b: |
| 3591 | run_system(dut, "cfg -a AP_CHMODE=11B"); |
| 3592 | break; |
| 3593 | case AP_11ng: |
| 3594 | run_system(dut, "cfg -a AP_CHMODE=11NGHT20"); |
| 3595 | break; |
| 3596 | case AP_11a: |
| 3597 | run_system(dut, "cfg -a AP_CHMODE=11A"); |
| 3598 | break; |
| 3599 | case AP_11na: |
| 3600 | run_system(dut, "cfg -a AP_CHMODE=11NAHT20"); |
| 3601 | break; |
| 3602 | case AP_11ac: |
| 3603 | run_system(dut, "cfg -a AP_CHMODE=11ACVHT80"); |
| 3604 | break; |
| 3605 | default: |
| 3606 | run_system(dut, "cfg -a AP_CHMODE=11NGHT20"); |
| 3607 | break; |
| 3608 | } |
| 3609 | snprintf(buf, sizeof(buf), "cfg -a AP_PRIMARY_CH=%d", |
| 3610 | dut->ap_channel); |
| 3611 | run_system(dut, buf); |
| 3612 | } |
| 3613 | |
| 3614 | if (dut->ap_sgi80 == 1) { |
| 3615 | run_system(dut, "cfg -a SHORTGI=1"); |
| 3616 | run_system(dut, "cfg -a SHORTGI_2=1"); |
| 3617 | } else if (dut->ap_sgi80 == 0) { |
| 3618 | run_system(dut, "cfg -a SHORTGI=0"); |
| 3619 | run_system(dut, "cfg -a SHORTGI_2=0"); |
| 3620 | } |
| 3621 | |
| 3622 | if (dut->ap_ldpc == 1) |
| 3623 | run_system(dut, "cfg -a LDPC=1"); |
| 3624 | else if (dut->ap_ldpc == 2) |
| 3625 | run_system(dut, "cfg -a LDPC=0"); |
| 3626 | } |
| 3627 | |
| 3628 | |
| 3629 | void ath_disable_txbf(struct sigma_dut *dut, const char *intf) |
| 3630 | { |
| 3631 | char buf[50]; |
| 3632 | |
| 3633 | snprintf(buf, sizeof(buf), "iwpriv %s vhtsubfee 0", intf); |
| 3634 | if (system(buf) != 0) |
| 3635 | sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv vhtsubfee failed"); |
| 3636 | |
| 3637 | snprintf(buf, sizeof(buf), "iwpriv %s vhtsubfer 0", intf); |
| 3638 | if (system(buf) != 0) |
| 3639 | sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv vhtsubfer failed"); |
| 3640 | |
| 3641 | snprintf(buf, sizeof(buf), "iwpriv %s vhtmubfee 0", intf); |
| 3642 | if (system(buf) != 0) |
| 3643 | sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv vhtmubfee failed"); |
| 3644 | |
| 3645 | snprintf(buf, sizeof(buf), "iwpriv %s vhtmubfer 0", intf); |
| 3646 | if (system(buf) != 0) |
| 3647 | sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv vhtmubfer failed"); |
| 3648 | } |
| 3649 | |
| 3650 | |
| 3651 | static void ath_ap_set_params(struct sigma_dut *dut) |
| 3652 | { |
| 3653 | const char *basedev = "wifi1"; |
| 3654 | const char *ifname = dut->ap_is_dual ? "ath1" : "ath0"; |
| 3655 | int i; |
priyadharshini gowthaman | 8e26ff4 | 2016-06-22 22:47:14 -0700 | [diff] [blame] | 3656 | char buf[300]; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3657 | |
| 3658 | if (dut->ap_countrycode[0]) { |
| 3659 | snprintf(buf, sizeof(buf), "iwpriv %s setCountry %s", |
| 3660 | basedev, dut->ap_countrycode); |
| 3661 | if (system(buf) != 0) { |
| 3662 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3663 | "iwpriv setCountry failed"); |
| 3664 | } |
| 3665 | sigma_dut_print(dut, DUT_MSG_INFO, "Set countrycode"); |
| 3666 | } |
| 3667 | |
| 3668 | for (i = 0; i < NUM_AP_AC; i++) { |
| 3669 | if (dut->ap_qos[i].ac) { |
| 3670 | snprintf(buf, sizeof(buf), "iwpriv %s cwmin %d 0 %d", |
| 3671 | ifname, i, dut->ap_qos[i].cwmin); |
| 3672 | if (system(buf) != 0) { |
| 3673 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3674 | "iwpriv cwmin failed"); |
| 3675 | } |
| 3676 | |
| 3677 | snprintf(buf, sizeof(buf), "iwpriv %s cwmax %d 0 %d", |
| 3678 | ifname, i, dut->ap_qos[i].cwmax); |
| 3679 | if (system(buf) != 0) { |
| 3680 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3681 | "iwpriv cwmax failed"); |
| 3682 | } |
| 3683 | |
| 3684 | snprintf(buf, sizeof(buf), "iwpriv %s aifs %d 0 %d", |
| 3685 | ifname, i, dut->ap_qos[i].aifs); |
| 3686 | if (system(buf) != 0) { |
| 3687 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3688 | "iwpriv aifs failed"); |
| 3689 | } |
| 3690 | |
| 3691 | snprintf(buf, sizeof(buf), |
| 3692 | "iwpriv %s txoplimit %d 0 %d", |
| 3693 | ifname, i, dut->ap_qos[i].txop); |
| 3694 | if (system(buf) != 0) { |
| 3695 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3696 | "iwpriv txoplimit failed"); |
| 3697 | } |
| 3698 | |
| 3699 | snprintf(buf, sizeof(buf), "iwpriv %s acm %d 0 %d", |
| 3700 | ifname, i, dut->ap_qos[i].acm); |
| 3701 | if (system(buf) != 0) { |
| 3702 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3703 | "iwpriv acm failed"); |
| 3704 | } |
| 3705 | } |
| 3706 | } |
| 3707 | |
| 3708 | for (i = 0; i < NUM_AP_AC; i++) { |
| 3709 | if (dut->ap_sta_qos[i].ac) { |
| 3710 | snprintf(buf, sizeof(buf), "iwpriv %s cwmin %d 1 %d", |
| 3711 | ifname, i, dut->ap_sta_qos[i].cwmin); |
| 3712 | if (system(buf) != 0) { |
| 3713 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3714 | "iwpriv cwmin failed"); |
| 3715 | } |
| 3716 | |
| 3717 | snprintf(buf, sizeof(buf), "iwpriv %s cwmax %d 1 %d", |
| 3718 | ifname, i, dut->ap_sta_qos[i].cwmax); |
| 3719 | if (system(buf) != 0) { |
| 3720 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3721 | "iwpriv cwmax failed"); |
| 3722 | } |
| 3723 | |
| 3724 | snprintf(buf, sizeof(buf), "iwpriv %s aifs %d 1 %d", |
| 3725 | ifname, i, dut->ap_sta_qos[i].aifs); |
| 3726 | if (system(buf) != 0) { |
| 3727 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3728 | "iwpriv aifs failed"); |
| 3729 | } |
| 3730 | |
| 3731 | snprintf(buf, sizeof(buf), |
| 3732 | "iwpriv %s txoplimit %d 1 %d", |
| 3733 | ifname, i, dut->ap_sta_qos[i].txop); |
| 3734 | if (system(buf) != 0) { |
| 3735 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3736 | "iwpriv txoplimit failed"); |
| 3737 | } |
| 3738 | |
| 3739 | snprintf(buf, sizeof(buf), "iwpriv %s acm %d 1 %d", |
| 3740 | ifname, i, dut->ap_sta_qos[i].acm); |
| 3741 | if (system(buf) != 0) { |
| 3742 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3743 | "iwpriv acm failed"); |
| 3744 | } |
| 3745 | } |
| 3746 | } |
| 3747 | |
| 3748 | if (dut->ap_disable_protection == 1) { |
| 3749 | snprintf(buf, sizeof(buf), "iwpriv %s enablertscts 0", ifname); |
| 3750 | if (system(buf) != 0) { |
| 3751 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3752 | "iwpriv enablertscts failed"); |
| 3753 | } |
| 3754 | sigma_dut_print(dut, DUT_MSG_INFO, "Disabled rtscts"); |
| 3755 | } |
| 3756 | |
| 3757 | if (dut->ap_ldpc == 1) { |
| 3758 | snprintf(buf, sizeof(buf), "iwpriv %s ldpc 1", ifname); |
| 3759 | if (system(buf) != 0) { |
| 3760 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3761 | "iwpriv ldpc 1 failed"); |
| 3762 | } |
| 3763 | } else if (dut->ap_ldpc == 2) { |
| 3764 | snprintf(buf, sizeof(buf), "iwpriv %s ldpc 0", ifname); |
| 3765 | if (system(buf) != 0) { |
| 3766 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3767 | "iwpriv ldpc 0 failed"); |
| 3768 | } |
| 3769 | } |
| 3770 | |
| 3771 | if (dut->ap_ampdu == 1) { |
| 3772 | snprintf(buf, sizeof(buf), "iwpriv %s ampdu 1", ifname); |
| 3773 | if (system(buf) != 0) { |
| 3774 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3775 | "iwpriv ampdu 1 failed"); |
| 3776 | } |
| 3777 | } else if (dut->ap_ampdu == 2) { |
| 3778 | snprintf(buf, sizeof(buf), "iwpriv %s ampdu 0", ifname); |
| 3779 | if (system(buf) != 0) { |
| 3780 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3781 | "iwpriv ampdu 0 failed"); |
| 3782 | } |
| 3783 | } |
| 3784 | |
| 3785 | if (dut->ap_ampdu_exp) { |
| 3786 | if (dut->program == PROGRAM_VHT) { |
| 3787 | snprintf(buf, sizeof(buf), "iwpriv %s vhtmaxampdu %d", |
| 3788 | ifname, dut->ap_ampdu_exp); |
| 3789 | if (system(buf) != 0) { |
| 3790 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3791 | "iwpriv vhtmaxampdu failed"); |
| 3792 | } |
| 3793 | } else { |
| 3794 | /* 11N */ |
| 3795 | snprintf(buf, sizeof(buf), "iwpriv %s maxampdu %d", |
| 3796 | ifname, dut->ap_ampdu_exp); |
| 3797 | if (system(buf) != 0) { |
| 3798 | sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv maxampdu failed"); |
| 3799 | } |
| 3800 | } |
| 3801 | } |
| 3802 | |
| 3803 | if (dut->ap_noack == AP_NOACK_ENABLED) { |
| 3804 | snprintf(buf, sizeof(buf), "iwpriv %s noackpolicy 0 0 1", ifname); |
| 3805 | if (system(buf) != 0) { |
| 3806 | sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv noackpolicy 0 0 1 failed"); |
| 3807 | } |
| 3808 | snprintf(buf, sizeof(buf), "iwpriv %s noackpolicy 1 0 1", ifname); |
| 3809 | if (system(buf) != 0) { |
| 3810 | sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv noackpolicy 1 0 1 failed"); |
| 3811 | } |
| 3812 | snprintf(buf, sizeof(buf), "iwpriv %s noackpolicy 2 0 1", ifname); |
| 3813 | if (system(buf) != 0) { |
| 3814 | sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv noackpolicy 2 0 1 failed"); |
| 3815 | } |
| 3816 | snprintf(buf, sizeof(buf), "iwpriv %s noackpolicy 3 0 1", ifname); |
| 3817 | if (system(buf) != 0) { |
| 3818 | sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv noackpolicy 3 0 1 failed"); |
| 3819 | } |
| 3820 | } else if (dut->ap_noack == AP_NOACK_DISABLED) { |
| 3821 | snprintf(buf, sizeof(buf), "iwpriv %s noackpolicy 0 0 0", ifname); |
| 3822 | if (system(buf) != 0) { |
| 3823 | sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv noackpolicy 0 0 0 failed"); |
| 3824 | } |
| 3825 | snprintf(buf, sizeof(buf), "iwpriv %s noackpolicy 1 0 0", ifname); |
| 3826 | if (system(buf) != 0) { |
| 3827 | sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv noackpolicy 1 0 0 failed"); |
| 3828 | } |
| 3829 | snprintf(buf, sizeof(buf), "iwpriv %s noackpolicy 2 0 0", ifname); |
| 3830 | if (system(buf) != 0) { |
| 3831 | sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv noackpolicy 2 0 0 failed"); |
| 3832 | } |
| 3833 | snprintf(buf, sizeof(buf), "iwpriv %s noackpolicy 3 0 0", ifname); |
| 3834 | if (system(buf) != 0) { |
| 3835 | sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv noackpolicy 3 0 0 failed"); |
| 3836 | } |
| 3837 | } |
| 3838 | |
| 3839 | if (dut->device_type == AP_testbed && dut->ap_vhtmcs_map) { |
| 3840 | snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0x%04x", |
| 3841 | ifname, dut->ap_vhtmcs_map); |
| 3842 | if (system(buf) != 0) { |
| 3843 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3844 | "iwpriv vht_mcsmap failed"); |
| 3845 | } |
| 3846 | } |
| 3847 | |
| 3848 | if (dut->ap_amsdu == 1) { |
| 3849 | snprintf(buf, sizeof(buf), "iwpriv %s amsdu 2", ifname); |
| 3850 | if (system(buf) != 0) { |
| 3851 | sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv amsdu 2 failed"); |
| 3852 | } |
| 3853 | } else if (dut->ap_amsdu == 2) { |
| 3854 | snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", ifname); |
| 3855 | if (system(buf) != 0) { |
| 3856 | sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv amsdu 1 failed"); |
| 3857 | } |
| 3858 | } |
| 3859 | |
| 3860 | if (dut->ap_rx_amsdu == 1) { |
| 3861 | snprintf(buf, sizeof(buf), "iwpriv wifi1 rx_amsdu 1"); |
| 3862 | if (system(buf) != 0) { |
| 3863 | sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv rx_amsdu 1 failed"); |
| 3864 | } |
| 3865 | } else if (dut->ap_rx_amsdu == 2) { |
| 3866 | snprintf(buf, sizeof(buf), "iwpriv wifi1 rx_amsdu 0"); |
| 3867 | if (system(buf) != 0) { |
| 3868 | sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv rx_amsdu 0 failed"); |
| 3869 | } |
| 3870 | } |
| 3871 | |
| 3872 | /* Command sequence to generate single VHT AMSDU and MPDU */ |
| 3873 | if (dut->ap_addba_reject && dut->ap_ampdu == 2 && dut->ap_amsdu == 1) { |
| 3874 | snprintf(buf, sizeof(buf), "iwpriv %s setaddbaoper 1", ifname); |
| 3875 | if (system(buf) != 0) { |
| 3876 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3877 | "iwpriv setaddbaoper 1 failed"); |
| 3878 | } |
| 3879 | |
| 3880 | snprintf(buf, sizeof(buf), |
| 3881 | "wifitool %s senddelba 1 0 1 4", ifname); |
| 3882 | if (system(buf) != 0) { |
| 3883 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3884 | "wifitool senddelba failed"); |
| 3885 | } |
| 3886 | |
| 3887 | snprintf(buf, sizeof(buf), "wifitool %s sendsingleamsdu 1 0", |
| 3888 | ifname); |
| 3889 | if (system(buf) != 0) { |
| 3890 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3891 | "wifitool sendsingleamsdu failed"); |
| 3892 | } |
| 3893 | |
| 3894 | snprintf(buf, sizeof(buf), "iwpriv %s amsdu 10", ifname); |
| 3895 | if (system(buf) != 0) { |
| 3896 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3897 | "iwpriv amsdu failed"); |
| 3898 | } |
| 3899 | } |
| 3900 | |
| 3901 | if (dut->ap_mode == AP_11ac) { |
| 3902 | int chwidth, nss; |
| 3903 | |
| 3904 | switch (dut->ap_chwidth) { |
| 3905 | case AP_20: |
| 3906 | chwidth = 0; |
| 3907 | break; |
| 3908 | case AP_40: |
| 3909 | chwidth = 1; |
| 3910 | break; |
| 3911 | case AP_80: |
| 3912 | chwidth = 2; |
| 3913 | break; |
| 3914 | case AP_160: |
| 3915 | chwidth = 3; |
| 3916 | break; |
| 3917 | default: |
| 3918 | chwidth = 0; |
| 3919 | break; |
| 3920 | } |
| 3921 | |
| 3922 | switch (dut->ap_tx_streams) { |
| 3923 | case 1: |
| 3924 | nss = 1; |
| 3925 | break; |
| 3926 | case 2: |
| 3927 | nss = 2; |
| 3928 | break; |
| 3929 | case 3: |
| 3930 | nss = 3; |
| 3931 | break; |
| 3932 | case 4: |
| 3933 | nss = 4; |
| 3934 | break; |
| 3935 | default: |
| 3936 | nss = 3; |
| 3937 | break; |
| 3938 | } |
| 3939 | |
| 3940 | if (dut->ap_fixed_rate) { |
| 3941 | if (nss == 4) |
| 3942 | ath_disable_txbf(dut, ifname); |
| 3943 | |
| 3944 | /* Set the nss */ |
| 3945 | snprintf(buf, sizeof(buf), "iwpriv %s nss %d", |
| 3946 | ifname, nss); |
| 3947 | if (system(buf) != 0) { |
| 3948 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3949 | "iwpriv nss failed"); |
| 3950 | } |
| 3951 | |
| 3952 | /* Set the channel width */ |
| 3953 | snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d", |
| 3954 | ifname, chwidth); |
| 3955 | if (system(buf) != 0) { |
| 3956 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3957 | "iwpriv chwidth failed"); |
| 3958 | } |
| 3959 | |
| 3960 | /* Set the VHT MCS */ |
| 3961 | snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs %d", |
| 3962 | ifname, dut->ap_mcs); |
| 3963 | if (system(buf) != 0) { |
| 3964 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3965 | "iwpriv vhtmcs failed"); |
| 3966 | } |
| 3967 | } |
| 3968 | } |
| 3969 | |
| 3970 | if (dut->ap_dyn_bw_sig == AP_DYN_BW_SGNL_ENABLED) { |
| 3971 | snprintf(buf, sizeof(buf), "iwpriv %s cwmenable 1", ifname); |
| 3972 | if (system(buf) != 0) { |
| 3973 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3974 | "iwpriv cwmenable 1 failed"); |
| 3975 | } |
| 3976 | } else if (dut->ap_dyn_bw_sig == AP_DYN_BW_SGNL_DISABLED) { |
| 3977 | snprintf(buf, sizeof(buf), "iwpriv %s cwmenable 0", ifname); |
| 3978 | if (system(buf) != 0) { |
| 3979 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3980 | "iwpriv cwmenable 0 failed"); |
| 3981 | } |
| 3982 | } |
| 3983 | |
| 3984 | if (dut->ap_sig_rts == 1) { |
| 3985 | snprintf(buf, sizeof(buf), "iwconfig %s rts 64", ifname); |
| 3986 | if (system(buf) != 0) { |
| 3987 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3988 | "iwconfig rts 64 failed"); |
| 3989 | } |
| 3990 | } else if (dut->ap_sig_rts == 2) { |
| 3991 | snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", ifname); |
| 3992 | if (system(buf) != 0) { |
| 3993 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3994 | "iwpriv rts 2347 failed"); |
| 3995 | } |
| 3996 | } |
| 3997 | |
| 3998 | if (dut->ap_hs2) { |
| 3999 | snprintf(buf, sizeof(buf), "iwpriv %s qbssload 1", ifname); |
| 4000 | if (system(buf) != 0) { |
| 4001 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4002 | "iwpriv qbssload failed"); |
| 4003 | } |
| 4004 | sigma_dut_print(dut, DUT_MSG_INFO, "Enabled qbssload"); |
| 4005 | } |
| 4006 | |
| 4007 | if (dut->ap_bss_load && dut->ap_bss_load != -1) { |
| 4008 | unsigned int bssload = 0; |
| 4009 | |
| 4010 | if (dut->ap_bss_load == 1) { |
| 4011 | /* STA count: 1, CU: 50, AAC: 65535 */ |
| 4012 | bssload = 0x0132ffff; |
| 4013 | } else if (dut->ap_bss_load == 2) { |
| 4014 | /* STA count: 1, CU: 200, AAC: 65535 */ |
| 4015 | bssload = 0x01c8ffff; |
| 4016 | } else if (dut->ap_bss_load == 3) { |
| 4017 | /* STA count: 1, CU: 75, AAC: 65535 */ |
| 4018 | bssload = 0x014bffff; |
| 4019 | } |
| 4020 | |
| 4021 | snprintf(buf, sizeof(buf), "iwpriv %s hcbssload %u", |
| 4022 | ifname, bssload); |
| 4023 | if (system(buf) != 0) { |
| 4024 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4025 | "iwpriv hcbssload failed"); |
| 4026 | } |
| 4027 | } else if (dut->ap_bss_load == 0) { |
| 4028 | snprintf(buf, sizeof(buf), "iwpriv %s qbssload 0", ifname); |
| 4029 | if (system(buf) != 0) { |
| 4030 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4031 | "iwpriv qbssload failed"); |
| 4032 | } |
| 4033 | sigma_dut_print(dut, DUT_MSG_INFO, "Disabled qbssload"); |
| 4034 | } |
| 4035 | |
| 4036 | if (dut->ap_dgaf_disable) { |
| 4037 | snprintf(buf, sizeof(buf), "iwpriv %s dgaf_disable 1", ifname); |
| 4038 | if (system(buf) != 0) { |
| 4039 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4040 | "iwpriv dgaf_disable failed"); |
| 4041 | } |
| 4042 | sigma_dut_print(dut, DUT_MSG_INFO, "Enabled dgaf_disable"); |
| 4043 | } |
| 4044 | |
| 4045 | if (dut->ap_l2tif) { |
| 4046 | snprintf(buf, sizeof(buf), "iwpriv %s l2tif 1", ifname); |
| 4047 | if (system(buf) != 0) { |
| 4048 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4049 | "iwpriv l2tif failed"); |
| 4050 | } |
| 4051 | snprintf(buf, sizeof(buf), |
| 4052 | "echo 1 > /sys/class/net/br0/brif/ath0/hotspot_l2tif"); |
| 4053 | if (system(buf) != 0) |
| 4054 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4055 | "l2tif br failed"); |
| 4056 | |
| 4057 | snprintf(buf, sizeof(buf), |
| 4058 | "echo 1 > /sys/class/net/br0/brif/eth0/hotspot_wan"); |
| 4059 | if (system(buf) != 0) |
| 4060 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4061 | "l2tif brif failed"); |
| 4062 | sigma_dut_print(dut, DUT_MSG_INFO, "Enabled l2tif"); |
| 4063 | } |
priyadharshini gowthaman | 264d544 | 2016-02-25 15:52:22 -0800 | [diff] [blame] | 4064 | |
| 4065 | if (dut->ap_ndpa_frame == 0) { |
| 4066 | snprintf(buf, sizeof(buf), |
| 4067 | "wifitool %s beeliner_fw_test 117 192", ifname); |
| 4068 | if (system(buf) != 0) { |
| 4069 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4070 | "wifitool beeliner_fw_test 117 192 failed"); |
| 4071 | } |
| 4072 | snprintf(buf, sizeof(buf), |
| 4073 | "wifitool %s beeliner_fw_test 118 192", ifname); |
| 4074 | if (system(buf) != 0) { |
| 4075 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4076 | "wifitool beeliner_fw_test 117 192 failed"); |
| 4077 | } |
| 4078 | } else if (dut->ap_ndpa_frame == 1) { |
| 4079 | /* Driver default - no changes needed */ |
| 4080 | } else if (dut->ap_ndpa_frame == 2) { |
| 4081 | snprintf(buf, sizeof(buf), |
| 4082 | "wifitool %s beeliner_fw_test 115 1", ifname); |
| 4083 | if (system(buf) != 0) { |
| 4084 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4085 | "wifitool beeliner_fw_test 117 192 failed"); |
| 4086 | } |
| 4087 | snprintf(buf, sizeof(buf), |
| 4088 | "wifitool %s beeliner_fw_test 116 1", ifname); |
| 4089 | if (system(buf) != 0) { |
| 4090 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4091 | "wifitool beeliner_fw_test 117 192 failed"); |
| 4092 | } |
| 4093 | } |
priyadharshini gowthaman | 8e26ff4 | 2016-06-22 22:47:14 -0700 | [diff] [blame] | 4094 | |
| 4095 | if (dut->ap_rtt == 1) { |
| 4096 | snprintf(buf, sizeof(buf), "iwpriv %s enable_rtt 1", ifname); |
| 4097 | run_system(dut, buf); |
| 4098 | } |
| 4099 | |
| 4100 | if (dut->ap_lci == 1) { |
| 4101 | snprintf(buf, sizeof(buf), "iwpriv %s enable_lci 1", ifname); |
| 4102 | run_system(dut, buf); |
| 4103 | } |
| 4104 | |
| 4105 | if (dut->ap_lcr == 1) { |
| 4106 | snprintf(buf, sizeof(buf), "iwpriv %s enable_lcr 1", ifname); |
| 4107 | run_system(dut, buf); |
| 4108 | } |
| 4109 | |
| 4110 | if (dut->ap_rrm == 1) { |
| 4111 | snprintf(buf, sizeof(buf), "iwpriv %s rrm 1", ifname); |
| 4112 | run_system(dut, buf); |
| 4113 | } |
| 4114 | |
| 4115 | if (dut->ap_lci == 1 || dut->ap_lcr == 1) { |
| 4116 | run_system(dut, "wpc -l /tmp/lci_cfg.txt"); |
| 4117 | } |
| 4118 | |
| 4119 | if (dut->ap_neighap >= 1 && dut->ap_lci == 0) { |
| 4120 | FILE *f; |
| 4121 | |
| 4122 | f = fopen("/tmp/nbr_report.txt", "w"); |
| 4123 | if (!f) { |
| 4124 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4125 | "Failed to open /tmp/nbr_report.txt"); |
| 4126 | return; |
| 4127 | } |
| 4128 | |
| 4129 | fprintf(f, |
| 4130 | "ap_1 = 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x00 0x3c 0x00 0x00 0x80 0x%x 0x09 0x06 0x03 0x02 0x2a 0x00\n", |
| 4131 | dut->ap_val_neighap[0][0], dut->ap_val_neighap[0][1], |
| 4132 | dut->ap_val_neighap[0][2], dut->ap_val_neighap[0][3], |
| 4133 | dut->ap_val_neighap[0][4], dut->ap_val_neighap[0][5], |
| 4134 | dut->ap_val_opchannel[0]); |
| 4135 | fclose(f); |
| 4136 | |
| 4137 | f = fopen("/tmp/ftmrr.txt", "w"); |
| 4138 | if (!f) { |
| 4139 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4140 | "Failed to open /tmp/ftmrr.txt"); |
| 4141 | return; |
| 4142 | } |
| 4143 | |
| 4144 | fprintf(f, |
| 4145 | "ap_1 = 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x00 0x3c 0x00 0x00 0x80 0x%x 0x09 0x06 0x03 0x02 0x2a 0x00\n", |
| 4146 | dut->ap_val_neighap[0][0], dut->ap_val_neighap[0][1], |
| 4147 | dut->ap_val_neighap[0][2], dut->ap_val_neighap[0][3], |
| 4148 | dut->ap_val_neighap[0][4], dut->ap_val_neighap[0][5], |
| 4149 | dut->ap_val_opchannel[0]); |
| 4150 | fclose(f); |
| 4151 | } |
| 4152 | |
| 4153 | if (dut->ap_neighap >= 2 && dut->ap_lci == 0) { |
| 4154 | FILE *f; |
| 4155 | |
| 4156 | f = fopen("/tmp/nbr_report.txt", "a"); |
| 4157 | if (!f) { |
| 4158 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4159 | "Failed to open /tmp/nbr_report.txt"); |
| 4160 | return; |
| 4161 | } |
| 4162 | fprintf(f, |
| 4163 | "ap_2 = 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x00 0x3c 0x00 0x00 0x80 0x%x 0x09 0x06 0x03 0x02 0x6a 0x00\n", |
| 4164 | dut->ap_val_neighap[1][0], dut->ap_val_neighap[1][1], |
| 4165 | dut->ap_val_neighap[1][2], dut->ap_val_neighap[1][3], |
| 4166 | dut->ap_val_neighap[1][4], dut->ap_val_neighap[1][5], |
| 4167 | dut->ap_val_opchannel[1]); |
| 4168 | fclose(f); |
| 4169 | |
| 4170 | f = fopen("/tmp/ftmrr.txt", "a"); |
| 4171 | if (!f) { |
| 4172 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4173 | "Failed to open /tmp/ftmrr.txt"); |
| 4174 | return; |
| 4175 | } |
| 4176 | fprintf(f, |
| 4177 | "ap_2 = 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x00 0x3c 0x00 0x00 0x80 0x%x 0x09 0x06 0x03 0x02 0x6a 0x00\n", |
| 4178 | dut->ap_val_neighap[1][0], dut->ap_val_neighap[1][1], |
| 4179 | dut->ap_val_neighap[1][2], dut->ap_val_neighap[1][3], |
| 4180 | dut->ap_val_neighap[1][4], dut->ap_val_neighap[1][5], |
| 4181 | dut->ap_val_opchannel[1]); |
| 4182 | fclose(f); |
| 4183 | } |
| 4184 | |
| 4185 | if (dut->ap_neighap >= 3 && dut->ap_lci == 0) { |
| 4186 | FILE *f; |
| 4187 | |
| 4188 | f = fopen("/tmp/nbr_report.txt", "a"); |
| 4189 | if (!f) { |
| 4190 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4191 | "Failed to open /tmp/nbr_report.txt"); |
| 4192 | return; |
| 4193 | } |
| 4194 | |
| 4195 | fprintf(f, |
| 4196 | "ap_3 = 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x00 0x3c 0x00 0x00 0x80 0x%x 0x09 0x06 0x03 0x02 0x9b 0x00\n", |
| 4197 | dut->ap_val_neighap[2][0], dut->ap_val_neighap[2][1], |
| 4198 | dut->ap_val_neighap[2][2], dut->ap_val_neighap[2][3], |
| 4199 | dut->ap_val_neighap[2][4], dut->ap_val_neighap[2][5], |
| 4200 | dut->ap_val_opchannel[2]); |
| 4201 | fclose(f); |
| 4202 | |
| 4203 | f = fopen("/tmp/ftmrr.txt", "a"); |
| 4204 | if (!f) { |
| 4205 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4206 | "Failed to open /tmp/ftmrr.txt"); |
| 4207 | return; |
| 4208 | } |
| 4209 | |
| 4210 | fprintf(f, |
| 4211 | "ap_3 = 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x00 0x3c 0x00 0x00 0x80 0x%x 0x09 0x06 0x03 0x02 0x9b 0x00\n", |
| 4212 | dut->ap_val_neighap[2][0], dut->ap_val_neighap[2][1], |
| 4213 | dut->ap_val_neighap[2][2], dut->ap_val_neighap[2][3], |
| 4214 | dut->ap_val_neighap[2][4], dut->ap_val_neighap[2][5], |
| 4215 | dut->ap_val_opchannel[2]); |
| 4216 | fclose(f); |
| 4217 | } |
| 4218 | |
| 4219 | if (dut->ap_neighap) { |
| 4220 | snprintf(buf, sizeof(buf), "iwpriv %s enable_rtt 1", ifname); |
| 4221 | run_system(dut, buf); |
| 4222 | snprintf(buf, sizeof(buf), "iwpriv %s enable_lci 1", ifname); |
| 4223 | run_system(dut, buf); |
| 4224 | snprintf(buf, sizeof(buf), "iwpriv %s enable_lcr 1", ifname); |
| 4225 | run_system(dut, buf); |
| 4226 | snprintf(buf, sizeof(buf), "iwpriv %s rrm 1", ifname); |
| 4227 | run_system(dut, buf); |
| 4228 | } |
| 4229 | |
| 4230 | if (dut->ap_scan == 1) { |
| 4231 | snprintf(buf, sizeof(buf), "iwpriv %s scanentryage 600", |
| 4232 | ifname); |
| 4233 | run_system(dut, buf); |
| 4234 | snprintf(buf, sizeof(buf), "iwlist %s scan", ifname); |
| 4235 | run_system(dut, buf); |
| 4236 | } |
priyadharshini gowthaman | b4e05fc | 2016-10-13 15:02:35 -0700 | [diff] [blame] | 4237 | |
| 4238 | if (dut->ap_set_bssidpref) { |
| 4239 | snprintf(buf, sizeof(buf), |
| 4240 | "wifitool %s setbssidpref 00:00:00:00:00:00 0 00 00", |
| 4241 | ifname); |
| 4242 | if (system(buf) != 0) { |
| 4243 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4244 | "wifitool clear bssidpref failed"); |
| 4245 | } |
| 4246 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4247 | } |
| 4248 | |
| 4249 | |
| 4250 | static int cmd_ath_ap_config_commit(struct sigma_dut *dut, |
| 4251 | struct sigma_conn *conn, |
| 4252 | struct sigma_cmd *cmd) |
| 4253 | { |
| 4254 | /* const char *name = get_param(cmd, "NAME"); */ |
| 4255 | char buf[100]; |
| 4256 | struct stat s; |
| 4257 | const char *ifname = dut->ap_is_dual ? "ath1" : "ath0"; |
| 4258 | |
| 4259 | if (stat("/proc/athversion", &s) == 0) { |
| 4260 | sigma_dut_print(dut, DUT_MSG_INFO, "Run apdown"); |
| 4261 | run_system(dut, "apdown"); |
| 4262 | } |
| 4263 | |
| 4264 | cmd_ath_ap_radio_config(dut); |
| 4265 | |
| 4266 | snprintf(buf, sizeof(buf), "cfg -a 'AP_SSID=%s'", dut->ap_ssid); |
| 4267 | run_system(dut, buf); |
| 4268 | |
| 4269 | switch (dut->ap_key_mgmt) { |
| 4270 | case AP_OPEN: |
| 4271 | if (dut->ap_cipher == AP_WEP) { |
| 4272 | run_system(dut, "cfg -a AP_SECMODE=WEP"); |
| 4273 | run_system(dut, "cfg -a AP_SECFILE=NONE"); |
| 4274 | /* shared auth mode not supported */ |
| 4275 | run_system(dut, "cfg -a AP_WEP_MODE_0=1"); |
| 4276 | run_system(dut, "cfg -a AP_WEP_MODE_1=1"); |
| 4277 | snprintf(buf, sizeof(buf), |
| 4278 | "cfg -a WEP_RADIO_NUM0_KEY_1=%s", |
| 4279 | dut->ap_wepkey); |
| 4280 | run_system(dut, buf); |
| 4281 | snprintf(buf, sizeof(buf), |
| 4282 | "cfg -a WEP_RADIO_NUM1_KEY_1=%s", |
| 4283 | dut->ap_wepkey); |
| 4284 | run_system(dut, buf); |
| 4285 | } else { |
| 4286 | run_system(dut, "cfg -a AP_SECMODE=None"); |
| 4287 | } |
| 4288 | break; |
| 4289 | case AP_WPA2_PSK: |
| 4290 | case AP_WPA2_PSK_MIXED: |
| 4291 | case AP_WPA_PSK: |
| 4292 | if (dut->ap_key_mgmt == AP_WPA2_PSK) |
| 4293 | run_system(dut, "cfg -a AP_WPA=2"); |
| 4294 | else if (dut->ap_key_mgmt == AP_WPA2_PSK_MIXED) |
| 4295 | run_system(dut, "cfg -a AP_WPA=3"); |
| 4296 | else |
| 4297 | run_system(dut, "cfg -a AP_WPA=1"); |
| 4298 | run_system(dut, "cfg -a AP_SECMODE=WPA"); |
| 4299 | run_system(dut, "cfg -a AP_SECFILE=PSK"); |
| 4300 | snprintf(buf, sizeof(buf), "cfg -a 'PSK_KEY=%s'", |
| 4301 | dut->ap_passphrase); |
| 4302 | run_system(dut, buf); |
| 4303 | if (dut->ap_cipher == AP_CCMP_TKIP) |
| 4304 | run_system(dut, "cfg -a AP_CYPHER=\"CCMP TKIP\""); |
| 4305 | else if (dut->ap_cipher == AP_TKIP) |
| 4306 | run_system(dut, "cfg -a AP_CYPHER=TKIP"); |
| 4307 | else |
| 4308 | run_system(dut, "cfg -a AP_CYPHER=CCMP"); |
| 4309 | break; |
| 4310 | case AP_WPA2_EAP: |
| 4311 | case AP_WPA2_EAP_MIXED: |
| 4312 | case AP_WPA_EAP: |
| 4313 | if (dut->ap_key_mgmt == AP_WPA2_EAP) |
| 4314 | run_system(dut, "cfg -a AP_WPA=2"); |
| 4315 | else if (dut->ap_key_mgmt == AP_WPA2_EAP_MIXED) |
| 4316 | run_system(dut, "cfg -a AP_WPA=3"); |
| 4317 | else |
| 4318 | run_system(dut, "cfg -a AP_WPA=1"); |
| 4319 | run_system(dut, "cfg -a AP_SECMODE=WPA"); |
| 4320 | run_system(dut, "cfg -a AP_SECFILE=EAP"); |
| 4321 | if (dut->ap_cipher == AP_CCMP_TKIP) |
| 4322 | run_system(dut, "cfg -a AP_CYPHER=\"CCMP TKIP\""); |
| 4323 | else if (dut->ap_cipher == AP_TKIP) |
| 4324 | run_system(dut, "cfg -a AP_CYPHER=TKIP"); |
| 4325 | else |
| 4326 | run_system(dut, "cfg -a AP_CYPHER=CCMP"); |
| 4327 | snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_SERVER=%s", |
| 4328 | dut->ap_radius_ipaddr); |
| 4329 | run_system(dut, buf); |
| 4330 | snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_PORT=%d", |
| 4331 | dut->ap_radius_port); |
| 4332 | run_system(dut, buf); |
| 4333 | snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_SECRET=%s", |
| 4334 | dut->ap_radius_password); |
| 4335 | run_system(dut, buf); |
| 4336 | break; |
| 4337 | } |
| 4338 | |
| 4339 | if (dut->ap_is_dual) { |
| 4340 | /* ath1 settings in case of dual */ |
| 4341 | snprintf(buf, sizeof(buf), "cfg -a 'AP_SSID_2=%s'", |
| 4342 | dut->ap_ssid); |
| 4343 | run_system(dut, buf); |
| 4344 | |
| 4345 | switch (dut->ap_key_mgmt) { |
| 4346 | case AP_OPEN: |
| 4347 | if (dut->ap_cipher == AP_WEP) { |
| 4348 | run_system(dut, "cfg -a AP_SECMODE_2=WEP"); |
| 4349 | run_system(dut, "cfg -a AP_SECFILE_2=NONE"); |
| 4350 | /* shared auth mode not supported */ |
| 4351 | run_system(dut, "cfg -a AP_WEP_MODE_0=1"); |
| 4352 | run_system(dut, "cfg -a AP_WEP_MODE_1=1"); |
| 4353 | snprintf(buf, sizeof(buf), |
| 4354 | "cfg -a WEP_RADIO_NUM0_KEY_1=%s", |
| 4355 | dut->ap_wepkey); |
| 4356 | run_system(dut, buf); |
| 4357 | snprintf(buf, sizeof(buf), |
| 4358 | "cfg -a WEP_RADIO_NUM1_KEY_1=%s", |
| 4359 | dut->ap_wepkey); |
| 4360 | run_system(dut, buf); |
| 4361 | } else { |
| 4362 | run_system(dut, "cfg -a AP_SECMODE_2=None"); |
| 4363 | } |
| 4364 | break; |
| 4365 | case AP_WPA2_PSK: |
| 4366 | case AP_WPA2_PSK_MIXED: |
| 4367 | case AP_WPA_PSK: |
| 4368 | if (dut->ap_key_mgmt == AP_WPA2_PSK) |
| 4369 | run_system(dut, "cfg -a AP_WPA_2=2"); |
| 4370 | else if (dut->ap_key_mgmt == AP_WPA2_PSK_MIXED) |
| 4371 | run_system(dut, "cfg -a AP_WPA_2=3"); |
| 4372 | else |
| 4373 | run_system(dut, "cfg -a AP_WPA_2=1"); |
| 4374 | // run_system(dut, "cfg -a AP_WPA_2=2"); |
| 4375 | run_system(dut, "cfg -a AP_SECMODE_2=WPA"); |
| 4376 | run_system(dut, "cfg -a AP_SECFILE_2=PSK"); |
| 4377 | snprintf(buf, sizeof(buf), "cfg -a 'PSK_KEY_2=%s'", |
| 4378 | dut->ap_passphrase); |
| 4379 | run_system(dut, buf); |
| 4380 | if (dut->ap_cipher == AP_CCMP_TKIP) |
| 4381 | run_system(dut, "cfg -a AP_CYPHER_2=\"CCMP TKIP\""); |
| 4382 | else if (dut->ap_cipher == AP_TKIP) |
| 4383 | run_system(dut, "cfg -a AP_CYPHER_2=TKIP"); |
| 4384 | else |
| 4385 | run_system(dut, "cfg -a AP_CYPHER_2=CCMP"); |
| 4386 | break; |
| 4387 | case AP_WPA2_EAP: |
| 4388 | case AP_WPA2_EAP_MIXED: |
| 4389 | case AP_WPA_EAP: |
| 4390 | if (dut->ap_key_mgmt == AP_WPA2_EAP) |
| 4391 | run_system(dut, "cfg -a AP_WPA_2=2"); |
| 4392 | else if (dut->ap_key_mgmt == AP_WPA2_EAP_MIXED) |
| 4393 | run_system(dut, "cfg -a AP_WPA_2=3"); |
| 4394 | else |
| 4395 | run_system(dut, "cfg -a AP_WPA_2=1"); |
| 4396 | run_system(dut, "cfg -a AP_SECMODE_2=WPA"); |
| 4397 | run_system(dut, "cfg -a AP_SECFILE_2=EAP"); |
| 4398 | if (dut->ap_cipher == AP_CCMP_TKIP) |
| 4399 | run_system(dut, "cfg -a AP_CYPHER_2=\"CCMP TKIP\""); |
| 4400 | else if (dut->ap_cipher == AP_TKIP) |
| 4401 | run_system(dut, "cfg -a AP_CYPHER_2=TKIP"); |
| 4402 | else |
| 4403 | run_system(dut, "cfg -a AP_CYPHER_2=CCMP"); |
| 4404 | |
| 4405 | snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_SERVER_2=%s", |
| 4406 | dut->ap_radius_ipaddr); |
| 4407 | run_system(dut, buf); |
| 4408 | snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_PORT_2=%d", |
| 4409 | dut->ap_radius_port); |
| 4410 | run_system(dut, buf); |
| 4411 | snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_SECRET_2=%s", |
| 4412 | dut->ap_radius_password); |
| 4413 | run_system(dut, buf); |
| 4414 | break; |
| 4415 | } |
| 4416 | |
| 4417 | /* wifi0 settings in case of dual */ |
| 4418 | run_system(dut, "cfg -a AP_RADIO_ID=0"); |
| 4419 | run_system(dut, "cfg -a AP_PRIMARY_CH=6"); |
| 4420 | run_system(dut, "cfg -a AP_STARTMODE=dual"); |
| 4421 | run_system(dut, "cfg -a AP_CHMODE=11NGHT40PLUS"); |
| 4422 | run_system(dut, "cfg -a TX_CHAINMASK=7"); |
| 4423 | run_system(dut, "cfg -a RX_CHAINMASK=7"); |
| 4424 | } |
| 4425 | |
| 4426 | switch (dut->ap_pmf) { |
| 4427 | case AP_PMF_DISABLED: |
| 4428 | snprintf(buf, sizeof(buf), "cfg -a AP_PMF=0"); |
| 4429 | run_system(dut, buf); |
| 4430 | break; |
| 4431 | case AP_PMF_OPTIONAL: |
| 4432 | snprintf(buf, sizeof(buf), "cfg -a AP_PMF=1"); |
| 4433 | run_system(dut, buf); |
| 4434 | break; |
| 4435 | case AP_PMF_REQUIRED: |
| 4436 | snprintf(buf, sizeof(buf), "cfg -a AP_PMF=2"); |
| 4437 | run_system(dut, buf); |
| 4438 | break; |
| 4439 | } |
| 4440 | if (dut->ap_add_sha256) { |
| 4441 | snprintf(buf, sizeof(buf), "cfg -a AP_WPA_SHA256=1"); |
| 4442 | run_system(dut, buf); |
| 4443 | } else { |
| 4444 | snprintf(buf, sizeof(buf), "cfg -r AP_WPA_SHA256"); |
| 4445 | run_system(dut, buf); |
| 4446 | } |
| 4447 | |
| 4448 | if (dut->ap_hs2) |
| 4449 | run_system(dut, "cfg -a AP_HOTSPOT=1"); |
| 4450 | else |
| 4451 | run_system(dut, "cfg -r AP_HOTSPOT"); |
| 4452 | |
| 4453 | if (dut->ap_interworking) { |
| 4454 | snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_ANT=%d", |
| 4455 | dut->ap_access_net_type); |
| 4456 | run_system(dut, buf); |
| 4457 | snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_INTERNET=%d", |
| 4458 | dut->ap_internet); |
| 4459 | run_system(dut, buf); |
| 4460 | snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_VENUEGROUP=%d", |
| 4461 | dut->ap_venue_group); |
| 4462 | run_system(dut, buf); |
| 4463 | snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_VENUETYPE=%d", |
| 4464 | dut->ap_venue_type); |
| 4465 | run_system(dut, buf); |
| 4466 | snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_HESSID=%s", |
| 4467 | dut->ap_hessid); |
| 4468 | run_system(dut, buf); |
| 4469 | |
| 4470 | if (dut->ap_roaming_cons[0]) { |
| 4471 | char *second, *rc; |
| 4472 | rc = strdup(dut->ap_roaming_cons); |
| 4473 | if (rc == NULL) |
| 4474 | return 0; |
| 4475 | |
| 4476 | second = strchr(rc, ';'); |
| 4477 | if (second) |
| 4478 | *second++ = '\0'; |
| 4479 | |
| 4480 | snprintf(buf, sizeof(buf), |
| 4481 | "cfg -a AP_HOTSPOT_ROAMINGCONSORTIUM=%s", rc); |
| 4482 | run_system(dut, buf); |
| 4483 | |
| 4484 | if (second) { |
| 4485 | snprintf(buf, sizeof(buf), |
| 4486 | "cfg -a AP_HOTSPOT_ROAMINGCONSORTIUM2" |
| 4487 | "=%s", second); |
| 4488 | run_system(dut, buf); |
| 4489 | } |
| 4490 | free(rc); |
| 4491 | } else { |
| 4492 | run_system(dut, "cfg -r AP_HOTSPOT_ROAMINGCONSORTIUM"); |
| 4493 | run_system(dut, |
| 4494 | "cfg -r AP_HOTSPOT_ROAMINGCONSORTIUM2"); |
| 4495 | } |
| 4496 | } else { |
| 4497 | run_system(dut, "cfg -r AP_HOTSPOT_ANT"); |
| 4498 | run_system(dut, "cfg -r AP_HOTSPOT_INTERNET"); |
| 4499 | run_system(dut, "cfg -r AP_HOTSPOT_VENUEGROUP"); |
| 4500 | run_system(dut, "cfg -r AP_HOTSPOT_VENUETYPE"); |
| 4501 | run_system(dut, "cfg -r AP_HOTSPOT_HESSID"); |
| 4502 | run_system(dut, "cfg -r AP_HOTSPOT_ROAMINGCONSORTIUM"); |
| 4503 | run_system(dut, "cfg -r AP_HOTSPOT_ROAMINGCONSORTIUM2"); |
| 4504 | } |
| 4505 | |
| 4506 | if (dut->ap_proxy_arp) |
| 4507 | run_system(dut, "cfg -a IEEE80211V_PROXYARP=1"); |
| 4508 | else |
| 4509 | run_system(dut, "cfg -a IEEE80211V_PROXYARP=0"); |
| 4510 | if (dut->ap_dgaf_disable) |
| 4511 | run_system(dut, "cfg -a AP_HOTSPOT_DISABLE_DGAF=1"); |
| 4512 | else |
| 4513 | run_system(dut, "cfg -r AP_HOTSPOT_DISABLE_DGAF"); |
| 4514 | |
| 4515 | if (strlen(dut->ap2_ssid)) { |
| 4516 | snprintf(buf, sizeof(buf), |
| 4517 | "cfg -a AP_SSID_2=%s", dut->ap2_ssid); |
| 4518 | run_system(dut, buf); |
| 4519 | |
| 4520 | if (dut->ap2_key_mgmt == AP2_OSEN) { |
| 4521 | run_system(dut, "cfg -a AP_SECMODE_2=WPA"); |
| 4522 | run_system(dut, "cfg -a AP_SECFILE_2=OSEN"); |
| 4523 | |
| 4524 | snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_SERVER_2=%s", |
| 4525 | dut->ap2_radius_ipaddr); |
| 4526 | run_system(dut, buf); |
| 4527 | |
| 4528 | snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_PORT_2=%d", |
| 4529 | dut->ap2_radius_port); |
| 4530 | run_system(dut, buf); |
| 4531 | |
| 4532 | snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_SECRET_2=%s", |
| 4533 | dut->ap2_radius_password); |
| 4534 | run_system(dut, buf); |
| 4535 | } else { |
| 4536 | run_system(dut, "cfg -a AP_SECMODE_2=None"); |
| 4537 | run_system(dut, "cfg -r AP_AUTH_SERVER_2"); |
| 4538 | run_system(dut, "cfg -r AP_AUTH_PORT_2"); |
| 4539 | run_system(dut, "cfg -r AP_AUTH_SECRET_2"); |
| 4540 | } |
| 4541 | |
| 4542 | run_system(dut, "cfg -a AP_STARTMODE=multi"); |
| 4543 | } |
| 4544 | |
| 4545 | run_system(dut, "cfg -c"); |
| 4546 | |
| 4547 | sigma_dut_print(dut, DUT_MSG_INFO, "Starting AP"); |
| 4548 | if (system("apup") != 0) { |
| 4549 | /* to be debugged why apup returns error |
| 4550 | send_resp(dut, conn, SIGMA_ERROR, |
| 4551 | "errorCode,apup failed"); |
| 4552 | return 0; |
| 4553 | */ |
| 4554 | } |
| 4555 | sigma_dut_print(dut, DUT_MSG_INFO, "AP started"); |
| 4556 | |
| 4557 | if (dut->ap_key_mgmt != AP_OPEN) { |
| 4558 | int res; |
| 4559 | /* allow some time for hostapd to start before returning |
| 4560 | * success */ |
| 4561 | usleep(500000); |
| 4562 | if (run_hostapd_cli(dut, "ping") != 0) { |
| 4563 | send_resp(dut, conn, SIGMA_ERROR, |
| 4564 | "errorCode,Failed to talk to hostapd"); |
| 4565 | return 0; |
| 4566 | } |
| 4567 | |
| 4568 | if (dut->ap_hs2 && !dut->ap_anqpserver) { |
| 4569 | /* the cfg app doesn't like ";" in the variables */ |
| 4570 | res = ath_ap_append_hostapd_conf(dut); |
| 4571 | if (res < 0) |
| 4572 | return res; |
| 4573 | |
| 4574 | /* wait for hostapd to be ready */ |
| 4575 | usleep(500000); |
| 4576 | if (run_hostapd_cli(dut, "ping") != 0) { |
| 4577 | send_resp(dut, conn, SIGMA_ERROR, |
| 4578 | "errorCode,Failed to talk to " |
| 4579 | "hostapd"); |
| 4580 | return 0; |
| 4581 | } |
| 4582 | } |
| 4583 | } |
| 4584 | |
| 4585 | ath_ap_set_params(dut); |
| 4586 | |
| 4587 | if (dut->ap_anqpserver) |
| 4588 | return cmd_ath_ap_anqpserver_start(dut); |
| 4589 | |
| 4590 | if (dut->ap2_proxy_arp) |
| 4591 | run_system(dut, "iwpriv ath1 proxy_arp 1"); |
| 4592 | |
| 4593 | if (dut->ap_allow_vht_wep || dut->ap_allow_vht_tkip) { |
| 4594 | snprintf(buf, sizeof(buf), "iwpriv %s htweptkip 1", ifname); |
| 4595 | if (system(buf) != 0) { |
| 4596 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4597 | "iwpriv htweptkip failed"); |
| 4598 | } |
| 4599 | } |
| 4600 | |
| 4601 | return 1; |
| 4602 | } |
| 4603 | |
| 4604 | |
| 4605 | static int set_ebtables_proxy_arp(struct sigma_dut *dut, const char *chain, |
| 4606 | const char *ifname) |
| 4607 | { |
| 4608 | char buf[200]; |
| 4609 | |
| 4610 | if (!chain || !ifname) |
| 4611 | return -2; |
| 4612 | |
| 4613 | snprintf(buf, sizeof(buf), "ebtables -P %s ACCEPT", chain); |
| 4614 | if (system(buf) != 0) { |
| 4615 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4616 | "Failed to set ebtables rules, RULE-1, %s", |
| 4617 | chain); |
| 4618 | return -2; |
| 4619 | } |
| 4620 | |
| 4621 | snprintf(buf, sizeof(buf), |
| 4622 | "ebtables -A %s -p ARP -d Broadcast -o %s -j DROP", |
| 4623 | chain, ifname); |
| 4624 | if (system(buf) != 0) { |
| 4625 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4626 | "Failed to set ebtables rules, RULE-2, %s", |
| 4627 | chain); |
| 4628 | return -2; |
| 4629 | } |
| 4630 | |
| 4631 | snprintf(buf, sizeof(buf), |
| 4632 | "ebtables -A %s -d Multicast -p IPv6 --ip6-protocol ipv6-icmp --ip6-icmp-type neighbor-solicitation -o %s -j DROP", |
| 4633 | chain, ifname); |
| 4634 | if (system(buf) != 0) { |
| 4635 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4636 | "Failed to set ebtables rules, RULE-3, %s", |
| 4637 | chain); |
| 4638 | return -2; |
| 4639 | } |
| 4640 | |
| 4641 | snprintf(buf, sizeof(buf), |
| 4642 | "ebtables -A %s -d Multicast -p IPv6 --ip6-protocol ipv6-icmp --ip6-icmp-type neighbor-advertisement -o %s -j DROP", |
| 4643 | chain, ifname); |
| 4644 | if (system(buf) != 0) { |
| 4645 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4646 | "Failed to set ebtables rules, RULE-4, %s", |
| 4647 | chain); |
| 4648 | return -2; |
| 4649 | } |
| 4650 | |
| 4651 | return 0; |
| 4652 | } |
| 4653 | |
| 4654 | |
| 4655 | static int set_ebtables_disable_dgaf(struct sigma_dut *dut, |
| 4656 | const char *chain, |
| 4657 | const char *ifname) |
| 4658 | { |
| 4659 | char buf[200]; |
| 4660 | |
| 4661 | if (!chain || !ifname) |
| 4662 | return -2; |
| 4663 | |
| 4664 | snprintf(buf, sizeof(buf), "ebtables -P %s ACCEPT", chain); |
| 4665 | if (system(buf) != 0) { |
| 4666 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4667 | "Failed to set ebtables rules, RULE-5, %s", |
| 4668 | chain); |
| 4669 | return -2; |
| 4670 | } |
| 4671 | |
| 4672 | snprintf(buf, sizeof(buf), |
| 4673 | "ebtables -A %s -p ARP -d Broadcast -o %s -j DROP", |
| 4674 | chain, ifname); |
| 4675 | if (system(buf) != 0) { |
| 4676 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4677 | "Failed to set ebtables rules, RULE-6, %s", |
| 4678 | chain); |
| 4679 | return -2; |
| 4680 | } |
| 4681 | |
| 4682 | snprintf(buf, sizeof(buf), |
| 4683 | "ebtables -A %s -p IPv4 -d Multicast -o %s -j DROP", |
| 4684 | chain, ifname); |
| 4685 | if (system(buf) != 0) { |
| 4686 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4687 | "Failed to set ebtables rules, RULE-7, %s", |
| 4688 | chain); |
| 4689 | return -2; |
| 4690 | } |
| 4691 | |
| 4692 | snprintf(buf, sizeof(buf), |
| 4693 | "ebtables -A %s -p IPv6 -d Multicast -o %s -j DROP", |
| 4694 | chain, ifname); |
| 4695 | if (system(buf) != 0) { |
| 4696 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4697 | "Failed to set ebtables rules, RULE-8, %s", |
| 4698 | chain); |
| 4699 | return -2; |
| 4700 | } |
| 4701 | |
| 4702 | return 0; |
| 4703 | } |
| 4704 | |
| 4705 | |
| 4706 | static int check_channel(int channel) |
| 4707 | { |
| 4708 | int channel_list[] = { 36, 40, 44, 48, 52, 60, 64, 100, 104, 108, 112, |
| 4709 | 116, 120, 124, 128, 132, 140, 144, 149, 153, 157, |
| 4710 | 161, 165 }; |
| 4711 | int num_chan = sizeof(channel_list) / sizeof(int); |
| 4712 | int i; |
| 4713 | |
| 4714 | for (i = 0; i < num_chan; i++) { |
| 4715 | if (channel == channel_list[i]) |
| 4716 | return i; |
| 4717 | } |
| 4718 | |
| 4719 | return -1; |
| 4720 | } |
| 4721 | |
| 4722 | |
| 4723 | static int get_oper_centr_freq_seq_idx(int chwidth, int channel) |
| 4724 | { |
| 4725 | int ch_base; |
| 4726 | int period; |
| 4727 | |
| 4728 | if (check_channel(channel) < 0) |
| 4729 | return -1; |
| 4730 | |
| 4731 | if (channel >= 36 && channel <= 64) |
| 4732 | ch_base = 36; |
| 4733 | else if (channel >= 100 && channel <= 144) |
| 4734 | ch_base = 100; |
| 4735 | else |
| 4736 | ch_base = 149; |
| 4737 | |
| 4738 | period = channel % ch_base * 5 / chwidth; |
| 4739 | return ch_base + period * chwidth / 5 + (chwidth - 20) / 10; |
| 4740 | } |
| 4741 | |
| 4742 | |
| 4743 | static int is_ht40plus_chan(int chan) |
| 4744 | { |
| 4745 | return chan == 36 || chan == 44 || chan == 52 || chan == 60 || |
| 4746 | chan == 100 || chan == 108 || chan == 116 || chan == 124 || |
| 4747 | chan == 132 || chan == 149 || chan == 157; |
| 4748 | } |
| 4749 | |
| 4750 | |
| 4751 | static int is_ht40minus_chan(int chan) |
| 4752 | { |
| 4753 | return chan == 40 || chan == 48 || chan == 56 || chan == 64 || |
| 4754 | chan == 104 || chan == 112 || chan == 120 || chan == 128 || |
| 4755 | chan == 136 || chan == 153 || chan == 161; |
| 4756 | } |
| 4757 | |
| 4758 | |
| 4759 | static int cmd_ap_config_commit(struct sigma_dut *dut, struct sigma_conn *conn, |
| 4760 | struct sigma_cmd *cmd) |
| 4761 | { |
| 4762 | /* const char *name = get_param(cmd, "NAME"); */ |
| 4763 | FILE *f; |
| 4764 | const char *ifname; |
| 4765 | char buf[500]; |
| 4766 | char path[100]; |
| 4767 | enum driver_type drv; |
| 4768 | |
| 4769 | drv = get_driver_type(); |
| 4770 | |
| 4771 | if (dut->mode == SIGMA_MODE_STATION) { |
| 4772 | stop_sta_mode(dut); |
| 4773 | sleep(1); |
| 4774 | } |
| 4775 | |
| 4776 | if (dut->mode == SIGMA_MODE_SNIFFER && dut->sniffer_ifname) { |
| 4777 | snprintf(buf, sizeof(buf), "ifconfig %s down", |
| 4778 | dut->sniffer_ifname); |
| 4779 | if (system(buf) != 0) { |
| 4780 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 4781 | "Failed to run '%s'", buf); |
| 4782 | } |
| 4783 | snprintf(buf, sizeof(buf), "iw dev %s set type station", |
| 4784 | dut->sniffer_ifname); |
| 4785 | if (system(buf) != 0) { |
| 4786 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 4787 | "Failed to run '%s'", buf); |
| 4788 | } |
| 4789 | } |
| 4790 | |
| 4791 | dut->mode = SIGMA_MODE_AP; |
| 4792 | |
| 4793 | if (drv == DRIVER_ATHEROS) |
| 4794 | return cmd_ath_ap_config_commit(dut, conn, cmd); |
| 4795 | if (drv == DRIVER_WCN) |
| 4796 | return cmd_wcn_ap_config_commit(dut, conn, cmd); |
| 4797 | if (drv == DRIVER_OPENWRT) |
| 4798 | return cmd_owrt_ap_config_commit(dut, conn, cmd); |
| 4799 | |
| 4800 | f = fopen(SIGMA_TMPDIR "/sigma_dut-ap.conf", "w"); |
| 4801 | if (f == NULL) { |
| 4802 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4803 | "%s: Failed to open sigma_dut-ap.conf", |
| 4804 | __func__); |
| 4805 | return -2; |
| 4806 | } |
| 4807 | switch (dut->ap_mode) { |
| 4808 | case AP_11g: |
| 4809 | case AP_11b: |
| 4810 | case AP_11ng: |
Sreelakshmi Konamki | b692f10 | 2016-04-26 19:47:00 +0530 | [diff] [blame] | 4811 | ifname = (drv == DRIVER_MAC80211 || drv == DRIVER_LINUX_WCN) ? |
| 4812 | "wlan0" : "ath0"; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4813 | if (drv == DRIVER_QNXNTO && sigma_main_ifname) |
| 4814 | ifname = sigma_main_ifname; |
| 4815 | fprintf(f, "hw_mode=g\n"); |
| 4816 | break; |
| 4817 | case AP_11a: |
| 4818 | case AP_11na: |
| 4819 | case AP_11ac: |
| 4820 | if (drv == DRIVER_QNXNTO) { |
| 4821 | if (sigma_main_ifname) |
| 4822 | ifname = sigma_main_ifname; |
| 4823 | else |
| 4824 | ifname = "wlan0"; |
Sreelakshmi Konamki | b692f10 | 2016-04-26 19:47:00 +0530 | [diff] [blame] | 4825 | } else if (drv == DRIVER_MAC80211 || drv == DRIVER_LINUX_WCN) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4826 | if (if_nametoindex("wlan1") > 0) |
| 4827 | ifname = "wlan1"; |
| 4828 | else |
| 4829 | ifname = "wlan0"; |
| 4830 | } else { |
| 4831 | ifname = get_main_ifname(); |
| 4832 | } |
| 4833 | fprintf(f, "hw_mode=a\n"); |
| 4834 | break; |
| 4835 | default: |
| 4836 | fclose(f); |
| 4837 | return -1; |
| 4838 | } |
| 4839 | |
Sreelakshmi Konamki | b692f10 | 2016-04-26 19:47:00 +0530 | [diff] [blame] | 4840 | if (drv == DRIVER_MAC80211 || drv == DRIVER_LINUX_WCN) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4841 | fprintf(f, "driver=nl80211\n"); |
| 4842 | |
Sreelakshmi Konamki | b692f10 | 2016-04-26 19:47:00 +0530 | [diff] [blame] | 4843 | if ((drv == DRIVER_MAC80211 || drv == DRIVER_QNXNTO || |
| 4844 | drv == DRIVER_LINUX_WCN) && |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4845 | (dut->ap_mode == AP_11ng || dut->ap_mode == AP_11na)) { |
| 4846 | fprintf(f, "ieee80211n=1\n"); |
Mohammed Shafi Shajakhan | 31d8a15 | 2016-06-02 20:10:55 +0530 | [diff] [blame] | 4847 | fprintf(f, "ht_capab="); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4848 | if (dut->ap_mode == AP_11ng && dut->ap_chwidth == AP_40) { |
| 4849 | if (dut->ap_channel >= 1 && dut->ap_channel <= 7) |
Mohammed Shafi Shajakhan | 31d8a15 | 2016-06-02 20:10:55 +0530 | [diff] [blame] | 4850 | fprintf(f, "[HT40+]"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4851 | else if (dut->ap_channel >= 8 && dut->ap_channel <= 11) |
Mohammed Shafi Shajakhan | 31d8a15 | 2016-06-02 20:10:55 +0530 | [diff] [blame] | 4852 | fprintf(f, "[HT40-]"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4853 | } |
| 4854 | |
| 4855 | /* configure ht_capab based on channel width */ |
| 4856 | if (dut->ap_mode == AP_11na && |
| 4857 | (dut->ap_chwidth == AP_40 || |
| 4858 | (dut->ap_chwidth == AP_AUTO && |
| 4859 | dut->default_ap_chwidth == AP_40))) { |
| 4860 | if (is_ht40plus_chan(dut->ap_channel)) |
Mohammed Shafi Shajakhan | 31d8a15 | 2016-06-02 20:10:55 +0530 | [diff] [blame] | 4861 | fprintf(f, "[HT40+]"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4862 | else if (is_ht40minus_chan(dut->ap_channel)) |
Mohammed Shafi Shajakhan | 31d8a15 | 2016-06-02 20:10:55 +0530 | [diff] [blame] | 4863 | fprintf(f, "[HT40-]"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4864 | } |
Mohammed Shafi Shajakhan | 31d8a15 | 2016-06-02 20:10:55 +0530 | [diff] [blame] | 4865 | |
| 4866 | if (dut->ap_tx_stbc) |
| 4867 | fprintf(f, "[TX-STBC]"); |
| 4868 | |
| 4869 | fprintf(f, "\n"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4870 | } |
| 4871 | |
Sreelakshmi Konamki | b692f10 | 2016-04-26 19:47:00 +0530 | [diff] [blame] | 4872 | if ((drv == DRIVER_MAC80211 || drv == DRIVER_QNXNTO || |
| 4873 | drv == DRIVER_LINUX_WCN) && |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4874 | dut->ap_mode == AP_11ac) { |
| 4875 | fprintf(f, "ieee80211ac=1\n" |
| 4876 | "ieee80211n=1\n" |
| 4877 | "ht_capab=[HT40+]\n"); |
| 4878 | } |
| 4879 | |
Sreelakshmi Konamki | b692f10 | 2016-04-26 19:47:00 +0530 | [diff] [blame] | 4880 | if ((drv == DRIVER_MAC80211 || drv == DRIVER_QNXNTO || |
| 4881 | drv == DRIVER_LINUX_WCN) && |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4882 | (dut->ap_mode == AP_11ac || dut->ap_mode == AP_11na)) { |
| 4883 | if (dut->ap_countrycode[0]) { |
| 4884 | fprintf(f, "country_code=%s\n", dut->ap_countrycode); |
| 4885 | fprintf(f, "ieee80211d=1\n"); |
| 4886 | fprintf(f, "ieee80211h=1\n"); |
| 4887 | } |
| 4888 | } |
| 4889 | |
| 4890 | fprintf(f, "interface=%s\n", ifname); |
| 4891 | if (dut->bridge) |
| 4892 | fprintf(f, "bridge=%s\n", dut->bridge); |
| 4893 | fprintf(f, "channel=%d\n", dut->ap_channel); |
| 4894 | |
| 4895 | if (sigma_hapd_ctrl) |
| 4896 | fprintf(f, "ctrl_interface=%s\n", sigma_hapd_ctrl); |
| 4897 | else |
| 4898 | fprintf(f, "ctrl_interface=/var/run/hostapd\n"); |
| 4899 | |
| 4900 | if (dut->ap_ssid[0]) |
| 4901 | fprintf(f, "ssid=%s\n", dut->ap_ssid); |
| 4902 | else |
| 4903 | fprintf(f, "ssid=QCA AP OOB\n"); |
| 4904 | if (dut->ap_bcnint) |
| 4905 | fprintf(f, "beacon_int=%d\n", dut->ap_bcnint); |
| 4906 | |
| 4907 | switch (dut->ap_key_mgmt) { |
| 4908 | case AP_OPEN: |
| 4909 | if (dut->ap_cipher == AP_WEP) |
| 4910 | fprintf(f, "wep_key0=%s\n", dut->ap_wepkey); |
| 4911 | break; |
| 4912 | case AP_WPA2_PSK: |
| 4913 | case AP_WPA2_PSK_MIXED: |
| 4914 | case AP_WPA_PSK: |
| 4915 | if (dut->ap_key_mgmt == AP_WPA2_PSK) |
| 4916 | fprintf(f, "wpa=2\n"); |
| 4917 | else if (dut->ap_key_mgmt == AP_WPA2_PSK_MIXED) |
| 4918 | fprintf(f, "wpa=3\n"); |
| 4919 | else |
| 4920 | fprintf(f, "wpa=1\n"); |
| 4921 | fprintf(f, "wpa_key_mgmt=WPA-PSK\n"); |
| 4922 | switch (dut->ap_pmf) { |
| 4923 | case AP_PMF_DISABLED: |
| 4924 | fprintf(f, "wpa_key_mgmt=WPA-PSK%s\n", |
| 4925 | dut->ap_add_sha256 ? " WPA-PSK-SHA256" : ""); |
| 4926 | break; |
| 4927 | case AP_PMF_OPTIONAL: |
| 4928 | fprintf(f, "wpa_key_mgmt=WPA-PSK%s\n", |
| 4929 | dut->ap_add_sha256 ? " WPA-PSK-SHA256" : ""); |
| 4930 | break; |
| 4931 | case AP_PMF_REQUIRED: |
| 4932 | fprintf(f, "wpa_key_mgmt=WPA-PSK-SHA256\n"); |
| 4933 | break; |
| 4934 | } |
| 4935 | if (dut->ap_cipher == AP_CCMP_TKIP) |
| 4936 | fprintf(f, "wpa_pairwise=CCMP TKIP\n"); |
| 4937 | else if (dut->ap_cipher == AP_TKIP) |
| 4938 | fprintf(f, "wpa_pairwise=TKIP\n"); |
| 4939 | else |
| 4940 | fprintf(f, "wpa_pairwise=CCMP\n"); |
| 4941 | fprintf(f, "wpa_passphrase=%s\n", dut->ap_passphrase); |
| 4942 | break; |
| 4943 | case AP_WPA2_EAP: |
| 4944 | case AP_WPA2_EAP_MIXED: |
| 4945 | case AP_WPA_EAP: |
| 4946 | fprintf(f, "ieee8021x=1\n"); |
| 4947 | if (dut->ap_key_mgmt == AP_WPA2_EAP) |
| 4948 | fprintf(f, "wpa=2\n"); |
| 4949 | else if (dut->ap_key_mgmt == AP_WPA2_EAP_MIXED) |
| 4950 | fprintf(f, "wpa=3\n"); |
| 4951 | else |
| 4952 | fprintf(f, "wpa=1\n"); |
| 4953 | switch (dut->ap_pmf) { |
| 4954 | case AP_PMF_DISABLED: |
| 4955 | fprintf(f, "wpa_key_mgmt=WPA-EAP%s\n", |
| 4956 | dut->ap_add_sha256 ? " WPA-EAP-SHA256" : ""); |
| 4957 | break; |
| 4958 | case AP_PMF_OPTIONAL: |
| 4959 | fprintf(f, "wpa_key_mgmt=WPA-EAP%s\n", |
| 4960 | dut->ap_add_sha256 ? " WPA-EAP-SHA256" : ""); |
| 4961 | break; |
| 4962 | case AP_PMF_REQUIRED: |
| 4963 | fprintf(f, "wpa_key_mgmt=WPA-EAP-SHA256\n"); |
| 4964 | break; |
| 4965 | } |
| 4966 | if (dut->ap_cipher == AP_CCMP_TKIP) |
| 4967 | fprintf(f, "wpa_pairwise=CCMP TKIP\n"); |
| 4968 | else if (dut->ap_cipher == AP_TKIP) |
| 4969 | fprintf(f, "wpa_pairwise=TKIP\n"); |
| 4970 | else |
| 4971 | fprintf(f, "wpa_pairwise=CCMP\n"); |
| 4972 | fprintf(f, "auth_server_addr=%s\n", dut->ap_radius_ipaddr); |
| 4973 | if (dut->ap_radius_port) |
| 4974 | fprintf(f, "auth_server_port=%d\n", |
| 4975 | dut->ap_radius_port); |
| 4976 | fprintf(f, "auth_server_shared_secret=%s\n", |
| 4977 | dut->ap_radius_password); |
| 4978 | break; |
| 4979 | } |
| 4980 | |
| 4981 | switch (dut->ap_pmf) { |
| 4982 | case AP_PMF_DISABLED: |
| 4983 | break; |
| 4984 | case AP_PMF_OPTIONAL: |
| 4985 | fprintf(f, "ieee80211w=1\n"); |
| 4986 | break; |
| 4987 | case AP_PMF_REQUIRED: |
| 4988 | fprintf(f, "ieee80211w=2\n"); |
| 4989 | break; |
| 4990 | } |
| 4991 | |
| 4992 | if (dut->ap_p2p_mgmt) |
| 4993 | fprintf(f, "manage_p2p=1\n"); |
| 4994 | |
| 4995 | if (dut->ap_tdls_prohibit || dut->ap_l2tif) |
| 4996 | fprintf(f, "tdls_prohibit=1\n"); |
| 4997 | if (dut->ap_tdls_prohibit_chswitch || dut->ap_l2tif) |
| 4998 | fprintf(f, "tdls_prohibit_chan_switch=1\n"); |
| 4999 | if (dut->ap_p2p_cross_connect >= 0) { |
| 5000 | fprintf(f, "manage_p2p=1\n" |
| 5001 | "allow_cross_connection=%d\n", |
| 5002 | dut->ap_p2p_cross_connect); |
| 5003 | } |
| 5004 | |
| 5005 | if (dut->ap_l2tif || dut->ap_proxy_arp) { |
| 5006 | if (!dut->bridge) { |
| 5007 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5008 | "Bridge must be configured. Run with -b <brname>."); |
| 5009 | fclose(f); |
| 5010 | return -2; |
| 5011 | } |
| 5012 | fprintf(f, "ap_isolate=1\n"); |
| 5013 | } |
| 5014 | |
| 5015 | if (dut->ap_proxy_arp) |
| 5016 | fprintf(f, "proxy_arp=1\n"); |
| 5017 | |
Pradeep Reddy POTTETI | 0d3db63 | 2016-03-11 15:21:11 +0530 | [diff] [blame] | 5018 | if (dut->ap_wme) |
| 5019 | fprintf(f, "wmm_enabled=1\n"); |
| 5020 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5021 | if (dut->ap_hs2) { |
| 5022 | if (dut->ap_bss_load) { |
| 5023 | char *bss_load; |
| 5024 | |
| 5025 | switch (dut->ap_bss_load) { |
| 5026 | case -1: |
| 5027 | bss_load = "bss_load_update_period=10"; |
| 5028 | break; |
| 5029 | case 1: |
| 5030 | /* STA count: 1, CU: 50, AAC: 65535 */ |
| 5031 | bss_load = "bss_load_test=1:50:65535"; |
| 5032 | break; |
| 5033 | case 2: |
| 5034 | /* STA count: 1, CU: 200, AAC: 65535 */ |
| 5035 | bss_load = "bss_load_test=1:200:65535"; |
| 5036 | break; |
| 5037 | case 3: |
| 5038 | /* STA count: 1, CU: 75, AAC: 65535 */ |
| 5039 | bss_load = "bss_load_test=1:75:65535"; |
| 5040 | break; |
| 5041 | default: |
| 5042 | bss_load = NULL; |
| 5043 | break; |
| 5044 | } |
| 5045 | |
| 5046 | if (!bss_load) { |
| 5047 | fclose(f); |
| 5048 | return -2; |
| 5049 | } |
| 5050 | fprintf(f, "%s\n", bss_load); |
| 5051 | } |
| 5052 | |
| 5053 | if (append_hostapd_conf_hs2(dut, f)) { |
| 5054 | fclose(f); |
| 5055 | return -2; |
| 5056 | } |
| 5057 | } |
| 5058 | |
| 5059 | if (dut->ap_interworking && append_hostapd_conf_interworking(dut, f)) { |
| 5060 | fclose(f); |
| 5061 | return -2; |
| 5062 | } |
| 5063 | |
| 5064 | if (dut->ap_hs2 && strlen(dut->ap2_ssid)) { |
| 5065 | unsigned char bssid[6]; |
| 5066 | char ifname2[50]; |
| 5067 | |
Pradeep Reddy POTTETI | 673d85c | 2016-07-26 19:08:07 +0530 | [diff] [blame] | 5068 | if (get_hwaddr(ifname, bssid)) { |
| 5069 | fclose(f); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5070 | return -2; |
Pradeep Reddy POTTETI | 673d85c | 2016-07-26 19:08:07 +0530 | [diff] [blame] | 5071 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5072 | bssid[0] |= 0x02; |
| 5073 | |
| 5074 | snprintf(ifname2, sizeof(ifname2), "%s_1", ifname); |
| 5075 | fprintf(f, "bss=%s_1\n", ifname2); |
| 5076 | fprintf(f, "ssid=%s\n", dut->ap2_ssid); |
| 5077 | if (dut->bridge) |
| 5078 | fprintf(f, "bridge=%s\n", dut->bridge); |
| 5079 | fprintf(f, "bssid=%02x:%02x:%02x:%02x:%02x:%02x\n", |
| 5080 | bssid[0], bssid[1], bssid[2], bssid[3], |
| 5081 | bssid[4], bssid[5]); |
| 5082 | |
| 5083 | if (dut->ap2_key_mgmt == AP2_OSEN) { |
| 5084 | fprintf(f, "osen=1\n"); |
| 5085 | if (strlen(dut->ap2_radius_ipaddr)) |
| 5086 | fprintf(f, "auth_server_addr=%s\n", |
| 5087 | dut->ap2_radius_ipaddr); |
| 5088 | if (dut->ap2_radius_port) |
| 5089 | fprintf(f, "auth_server_port=%d\n", |
| 5090 | dut->ap2_radius_port); |
| 5091 | if (strlen(dut->ap2_radius_password)) |
| 5092 | fprintf(f, "auth_server_shared_secret=%s\n", |
| 5093 | dut->ap2_radius_password); |
| 5094 | } |
| 5095 | |
| 5096 | if (dut->ap2_proxy_arp) { |
| 5097 | if (!dut->bridge) { |
| 5098 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5099 | "Bridge must be configured. Run with -b <brname>."); |
| 5100 | fclose(f); |
| 5101 | return -2; |
| 5102 | } |
| 5103 | fprintf(f, "ap_isolate=1\n"); |
| 5104 | fprintf(f, "proxy_arp=1\n"); |
| 5105 | |
| 5106 | if (set_ebtables_proxy_arp(dut, "FORWARD", ifname2) || |
| 5107 | set_ebtables_proxy_arp(dut, "OUTPUT", ifname2)) { |
| 5108 | fclose(f); |
| 5109 | return -2; |
| 5110 | } |
| 5111 | |
| 5112 | } |
| 5113 | } |
| 5114 | |
| 5115 | if (dut->program == PROGRAM_WPS) { |
| 5116 | fprintf(f, "eap_server=1\n" |
| 5117 | "wps_state=1\n" |
| 5118 | "device_name=QCA AP\n" |
| 5119 | "manufacturer=QCA\n" |
| 5120 | "device_type=6-0050F204-1\n" |
| 5121 | "config_methods=label virtual_display " |
| 5122 | "virtual_push_button keypad%s\n" |
| 5123 | "ap_pin=12345670\n" |
| 5124 | "friendly_name=QCA Access Point\n" |
| 5125 | "upnp_iface=%s\n", |
| 5126 | dut->ap_wpsnfc ? " nfc_interface ext_nfc_token" : "", |
| 5127 | dut->bridge ? dut->bridge : ifname); |
| 5128 | } |
| 5129 | |
| 5130 | if (dut->program == PROGRAM_VHT) { |
| 5131 | int vht_oper_centr_freq_idx; |
| 5132 | |
| 5133 | if (check_channel(dut->ap_channel) < 0) { |
| 5134 | send_resp(dut, conn, SIGMA_INVALID, |
| 5135 | "errorCode,Invalid channel"); |
Pradeep Reddy POTTETI | 673d85c | 2016-07-26 19:08:07 +0530 | [diff] [blame] | 5136 | fclose(f); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5137 | return 0; |
| 5138 | } |
| 5139 | |
| 5140 | switch (dut->ap_chwidth) { |
| 5141 | case AP_20: |
| 5142 | dut->ap_vht_chwidth = AP_20_40_VHT_OPER_CHWIDTH; |
| 5143 | vht_oper_centr_freq_idx = |
| 5144 | get_oper_centr_freq_seq_idx(20, |
| 5145 | dut->ap_channel); |
| 5146 | break; |
| 5147 | case AP_40: |
| 5148 | dut->ap_vht_chwidth = AP_20_40_VHT_OPER_CHWIDTH; |
| 5149 | vht_oper_centr_freq_idx = |
| 5150 | get_oper_centr_freq_seq_idx(40, |
| 5151 | dut->ap_channel); |
| 5152 | break; |
| 5153 | case AP_80: |
| 5154 | dut->ap_vht_chwidth = AP_80_VHT_OPER_CHWIDTH; |
| 5155 | vht_oper_centr_freq_idx = |
| 5156 | get_oper_centr_freq_seq_idx(80, |
| 5157 | dut->ap_channel); |
| 5158 | break; |
| 5159 | case AP_160: |
| 5160 | dut->ap_vht_chwidth = AP_160_VHT_OPER_CHWIDTH; |
| 5161 | vht_oper_centr_freq_idx = |
| 5162 | get_oper_centr_freq_seq_idx(160, |
| 5163 | dut->ap_channel); |
| 5164 | break; |
| 5165 | default: |
| 5166 | dut->ap_vht_chwidth = VHT_DEFAULT_OPER_CHWIDTH; |
| 5167 | vht_oper_centr_freq_idx = |
| 5168 | get_oper_centr_freq_seq_idx(80, |
| 5169 | dut->ap_channel); |
| 5170 | break; |
| 5171 | } |
| 5172 | fprintf(f, "vht_oper_centr_freq_seg0_idx=%d\n", |
| 5173 | vht_oper_centr_freq_idx); |
| 5174 | fprintf(f, "vht_oper_chwidth=%d\n", dut->ap_vht_chwidth); |
| 5175 | |
| 5176 | if (dut->ap_sgi80 || dut->ap_txBF || dut->ap_ldpc || |
Mohammed Shafi Shajakhan | f3e68d9 | 2016-06-02 20:10:57 +0530 | [diff] [blame] | 5177 | dut->ap_tx_stbc || dut->ap_mu_txBF) { |
| 5178 | fprintf(f, "vht_capab=%s%s%s%s%s\n", |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5179 | dut->ap_sgi80 ? "[SHORT-GI-80]" : "", |
Mohammed Shafi Shajakhan | c039ce3 | 2016-06-02 20:10:58 +0530 | [diff] [blame] | 5180 | dut->ap_txBF ? |
Tamizh chelvam | 8312f6d | 2016-06-02 20:10:59 +0530 | [diff] [blame] | 5181 | "[SU-BEAMFORMER][SU-BEAMFORMEE][BF-ANTENNA-2][SOUNDING-DIMENSION-2]" : "", |
Pradeep Reddy POTTETI | 3d33e8b | 2016-09-02 13:05:43 +0530 | [diff] [blame] | 5182 | (dut->ap_ldpc == 1) ? "[RXLDPC]" : "", |
Mohammed Shafi Shajakhan | f3e68d9 | 2016-06-02 20:10:57 +0530 | [diff] [blame] | 5183 | dut->ap_tx_stbc ? "[TX-STBC-2BY1]" : "", |
| 5184 | dut->ap_mu_txBF ? "[MU-BEAMFORMER]" : ""); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5185 | } |
| 5186 | } |
| 5187 | |
| 5188 | fclose(f); |
| 5189 | #ifdef __QNXNTO__ |
| 5190 | if (system("slay hostapd") == 0) |
| 5191 | #else /* __QNXNTO__ */ |
| 5192 | if (kill_process(dut, "(hostapd)", 1, SIGTERM) == 0 || |
| 5193 | system("killall hostapd") == 0) |
| 5194 | #endif /* __QNXNTO__ */ |
| 5195 | { |
| 5196 | int i; |
| 5197 | /* Wait some time to allow hostapd to complete cleanup before |
| 5198 | * starting a new process */ |
| 5199 | for (i = 0; i < 10; i++) { |
| 5200 | usleep(500000); |
| 5201 | #ifdef __QNXNTO__ |
| 5202 | if (system("pidin | grep hostapd") != 0) |
| 5203 | break; |
| 5204 | #else /* __QNXNTO__ */ |
| 5205 | if (system("pidof hostapd") != 0) |
| 5206 | break; |
| 5207 | #endif /* __QNXNTO__ */ |
| 5208 | } |
| 5209 | } |
| 5210 | |
Pradeep Reddy POTTETI | a076c30 | 2016-05-16 13:36:07 +0530 | [diff] [blame] | 5211 | #ifdef ANDROID |
| 5212 | /* Set proper conf file permissions so that hostapd process |
| 5213 | * can access it. |
| 5214 | */ |
| 5215 | if (chmod(SIGMA_TMPDIR "/sigma_dut-ap.conf", |
| 5216 | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP) < 0) |
| 5217 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5218 | "Error changing permissions"); |
| 5219 | |
| 5220 | if (chown(SIGMA_TMPDIR "/sigma_dut-ap.conf", -1, AID_WIFI) < 0) |
| 5221 | sigma_dut_print(dut, DUT_MSG_ERROR, "Error changing groupid"); |
| 5222 | #endif /* ANDROID */ |
| 5223 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5224 | if (drv == DRIVER_QNXNTO) { |
| 5225 | snprintf(buf, sizeof(buf), |
Pradeep Reddy POTTETI | bf4a974 | 2016-02-04 12:32:30 +0530 | [diff] [blame] | 5226 | "hostapd -B %s%s %s%s" SIGMA_TMPDIR |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5227 | "/sigma_dut-ap.conf", |
| 5228 | dut->hostapd_debug_log ? "-ddKt -f " : "", |
| 5229 | dut->hostapd_debug_log ? dut->hostapd_debug_log : "", |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5230 | dut->hostapd_entropy_log ? " -e" : "", |
| 5231 | dut->hostapd_entropy_log ? dut->hostapd_entropy_log : |
| 5232 | ""); |
| 5233 | } else { |
| 5234 | /* |
| 5235 | * It looks like a monitor interface can cause some issues for |
| 5236 | * beaconing, so remove it (if injection was used) before |
| 5237 | * starting hostapd. |
| 5238 | */ |
| 5239 | if (if_nametoindex("sigmadut") > 0 && |
| 5240 | system("iw dev sigmadut del") != 0) |
| 5241 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to remove " |
| 5242 | "monitor interface"); |
| 5243 | |
| 5244 | snprintf(buf, sizeof(buf), "%shostapd -B%s%s%s%s " SIGMA_TMPDIR |
| 5245 | "/sigma_dut-ap.conf", |
| 5246 | file_exists("hostapd") ? "./" : "", |
| 5247 | dut->hostapd_debug_log ? " -ddKt -f" : "", |
| 5248 | dut->hostapd_debug_log ? dut->hostapd_debug_log : "", |
| 5249 | dut->hostapd_entropy_log ? " -e" : "", |
| 5250 | dut->hostapd_entropy_log ? dut->hostapd_entropy_log : |
| 5251 | ""); |
| 5252 | } |
| 5253 | |
| 5254 | if (system(buf) != 0) { |
| 5255 | send_resp(dut, conn, SIGMA_ERROR, |
| 5256 | "errorCode,Failed to start hostapd"); |
| 5257 | return 0; |
| 5258 | } |
| 5259 | |
| 5260 | /* allow some time for hostapd to start before returning success */ |
| 5261 | usleep(500000); |
| 5262 | if (run_hostapd_cli(dut, "ping") != 0) { |
| 5263 | send_resp(dut, conn, SIGMA_ERROR, |
| 5264 | "errorCode,Failed to talk to hostapd"); |
| 5265 | return 0; |
| 5266 | } |
| 5267 | |
| 5268 | if (dut->ap_l2tif) { |
| 5269 | snprintf(path, sizeof(path), |
| 5270 | "/sys/class/net/%s/brport/hairpin_mode", |
| 5271 | ifname); |
| 5272 | if (!file_exists(path)) { |
| 5273 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5274 | "%s must be binded to the bridge for L2TIF", |
| 5275 | ifname); |
| 5276 | return -2; |
| 5277 | } |
| 5278 | |
| 5279 | snprintf(buf, sizeof(buf), "echo 1 > %s", path); |
| 5280 | if (system(buf) != 0) { |
| 5281 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5282 | "Failed to enable hairpin_mode for L2TIF"); |
| 5283 | return -2; |
| 5284 | } |
| 5285 | |
| 5286 | snprintf(buf, sizeof(buf), "ebtables -P FORWARD ACCEPT"); |
| 5287 | if (system(buf) != 0) { |
| 5288 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5289 | "Failed to set ebtables rules, RULE-9"); |
| 5290 | return -2; |
| 5291 | } |
| 5292 | |
| 5293 | snprintf(buf, sizeof(buf), |
| 5294 | "ebtables -A FORWARD -p IPv4 --ip-proto icmp -i %s -j DROP", |
| 5295 | ifname); |
| 5296 | if (system(buf) != 0) { |
| 5297 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5298 | "Failed to set ebtables rules, RULE-11"); |
| 5299 | return -2; |
| 5300 | } |
| 5301 | } |
| 5302 | |
| 5303 | if (dut->ap_proxy_arp) { |
| 5304 | if (dut->ap_dgaf_disable) { |
| 5305 | if (set_ebtables_disable_dgaf(dut, "FORWARD", ifname) || |
| 5306 | set_ebtables_disable_dgaf(dut, "OUTPUT", ifname)) |
| 5307 | return -2; |
| 5308 | } else { |
| 5309 | if (set_ebtables_proxy_arp(dut, "FORWARD", ifname) || |
| 5310 | set_ebtables_proxy_arp(dut, "OUTPUT", ifname)) |
| 5311 | return -2; |
| 5312 | } |
| 5313 | |
| 5314 | /* For 4.5-(c) */ |
| 5315 | snprintf(buf, sizeof(buf), |
| 5316 | "ebtables -A FORWARD -p ARP --arp-opcode 2 -i %s -j DROP", |
| 5317 | ifname); |
| 5318 | if (system(buf) != 0) { |
| 5319 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5320 | "Failed to set ebtables rules, RULE-10"); |
| 5321 | return -2; |
| 5322 | } |
| 5323 | } |
| 5324 | |
| 5325 | if (dut->ap_tdls_prohibit || dut->ap_l2tif) { |
| 5326 | /* Drop TDLS frames */ |
| 5327 | snprintf(buf, sizeof(buf), |
| 5328 | "ebtables -A FORWARD -p 0x890d -i %s -j DROP", ifname); |
| 5329 | if (system(buf) != 0) { |
| 5330 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5331 | "Failed to set ebtables rules, RULE-13"); |
| 5332 | return -2; |
| 5333 | } |
| 5334 | } |
| 5335 | |
| 5336 | if (dut->ap_fake_pkhash && |
| 5337 | run_hostapd_cli(dut, "set wps_corrupt_pkhash 1") != 0) { |
| 5338 | send_resp(dut, conn, SIGMA_ERROR, |
| 5339 | "errorCode,Could not enable FakePubKey"); |
| 5340 | return 0; |
| 5341 | } |
| 5342 | |
| 5343 | return 1; |
| 5344 | } |
| 5345 | |
| 5346 | |
| 5347 | static void parse_qos_params(struct qos_params *qos, const char *cwmin, |
| 5348 | const char *cwmax, const char *aifs, |
| 5349 | const char *txop, const char *acm) |
| 5350 | { |
| 5351 | if (cwmin) { |
| 5352 | qos->ac = 1; |
| 5353 | qos->cwmin = atoi(cwmin); |
| 5354 | } |
| 5355 | |
| 5356 | if (cwmax) { |
| 5357 | qos->ac = 1; |
| 5358 | qos->cwmax = atoi(cwmax); |
| 5359 | } |
| 5360 | |
| 5361 | if (aifs) { |
| 5362 | qos->ac = 1; |
| 5363 | qos->aifs = atoi(aifs); |
| 5364 | } |
| 5365 | |
| 5366 | if (txop) { |
| 5367 | qos->ac = 1; |
| 5368 | qos->txop = atoi(txop) * 32; |
| 5369 | } |
| 5370 | |
| 5371 | if (acm) { |
| 5372 | qos->ac = 1; |
| 5373 | qos->acm = strcasecmp(acm, "on") == 0; |
| 5374 | } |
| 5375 | } |
| 5376 | |
| 5377 | |
| 5378 | static int cmd_ap_set_apqos(struct sigma_dut *dut, struct sigma_conn *conn, |
| 5379 | struct sigma_cmd *cmd) |
| 5380 | { |
| 5381 | /* TXOP: The values provided here for VHT5G only */ |
| 5382 | parse_qos_params(&dut->ap_qos[AP_AC_VO], get_param(cmd, "cwmin_VO"), |
| 5383 | get_param(cmd, "cwmax_VO"), get_param(cmd, "AIFS_VO"), |
| 5384 | get_param(cmd, "TXOP_VO"), get_param(cmd, "ACM_VO")); |
| 5385 | parse_qos_params(&dut->ap_qos[AP_AC_VI], get_param(cmd, "cwmin_VI"), |
| 5386 | get_param(cmd, "cwmax_VI"), get_param(cmd, "AIFS_VI"), |
| 5387 | get_param(cmd, "TXOP_VI"), get_param(cmd, "ACM_VI")); |
| 5388 | parse_qos_params(&dut->ap_qos[AP_AC_BE], get_param(cmd, "cwmin_BE"), |
| 5389 | get_param(cmd, "cwmax_BE"), get_param(cmd, "AIFS_BE"), |
| 5390 | get_param(cmd, "TXOP_BE"), get_param(cmd, "ACM_BE")); |
| 5391 | parse_qos_params(&dut->ap_qos[AP_AC_BK], get_param(cmd, "cwmin_BK"), |
| 5392 | get_param(cmd, "cwmax_BK"), get_param(cmd, "AIFS_BK"), |
| 5393 | get_param(cmd, "TXOP_BK"), get_param(cmd, "ACM_BK")); |
| 5394 | return 1; |
| 5395 | } |
| 5396 | |
| 5397 | |
| 5398 | static int cmd_ap_set_staqos(struct sigma_dut *dut, struct sigma_conn *conn, |
| 5399 | struct sigma_cmd *cmd) |
| 5400 | { |
| 5401 | parse_qos_params(&dut->ap_sta_qos[AP_AC_VO], get_param(cmd, "cwmin_VO"), |
| 5402 | get_param(cmd, "cwmax_VO"), get_param(cmd, "AIFS_VO"), |
| 5403 | get_param(cmd, "TXOP_VO"), get_param(cmd, "ACM_VO")); |
| 5404 | parse_qos_params(&dut->ap_sta_qos[AP_AC_VI], get_param(cmd, "cwmin_VI"), |
| 5405 | get_param(cmd, "cwmax_VI"), get_param(cmd, "AIFS_VI"), |
| 5406 | get_param(cmd, "TXOP_VI"), get_param(cmd, "ACM_VI")); |
| 5407 | parse_qos_params(&dut->ap_sta_qos[AP_AC_BE], get_param(cmd, "cwmin_BE"), |
| 5408 | get_param(cmd, "cwmax_BE"), get_param(cmd, "AIFS_BE"), |
| 5409 | get_param(cmd, "TXOP_BE"), get_param(cmd, "ACM_BE")); |
| 5410 | parse_qos_params(&dut->ap_sta_qos[AP_AC_BK], get_param(cmd, "cwmin_BK"), |
| 5411 | get_param(cmd, "cwmax_BK"), get_param(cmd, "AIFS_BK"), |
| 5412 | get_param(cmd, "TXOP_BK"), get_param(cmd, "ACM_BK")); |
| 5413 | return 1; |
| 5414 | } |
| 5415 | |
| 5416 | |
| 5417 | static void cmd_ath_ap_hs2_reset(struct sigma_dut *dut) |
| 5418 | { |
| 5419 | unsigned char bssid[6]; |
| 5420 | char buf[100]; |
| 5421 | run_system(dut, "cfg -a AP_SSID=\"Hotspot 2.0\""); |
| 5422 | run_system(dut, "cfg -a AP_PRIMARY_CH=1"); |
| 5423 | run_system(dut, "cfg -a AP_SECMODE=WPA"); |
| 5424 | run_system(dut, "cfg -a AP_SECFILE=EAP"); |
| 5425 | run_system(dut, "cfg -a AP_WPA=2"); |
| 5426 | run_system(dut, "cfg -a AP_CYPHER=CCMP"); |
| 5427 | run_system(dut, "cfg -a AP_HOTSPOT=1"); |
| 5428 | run_system(dut, "cfg -a AP_HOTSPOT_ANT=2"); |
| 5429 | run_system(dut, "cfg -a AP_HOTSPOT_INTERNET=0"); |
| 5430 | run_system(dut, "cfg -a AP_HOTSPOT_VENUEGROUP=2"); |
| 5431 | run_system(dut, "cfg -a AP_HOTSPOT_VENUETYPE=8"); |
| 5432 | run_system(dut, "cfg -a AP_HOTSPOT_ROAMINGCONSORTIUM=506f9a"); |
| 5433 | run_system(dut, "cfg -a AP_HOTSPOT_ROAMINGCONSORTIUM2=001bc504bd"); |
| 5434 | if (!get_hwaddr("ath0", bssid)) { |
| 5435 | snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_HESSID=" |
| 5436 | "%02x:%02x:%02x:%02x:%02x:%02x", |
| 5437 | bssid[0], bssid[1], bssid[2], bssid[3], |
| 5438 | bssid[4], bssid[5]); |
| 5439 | run_system(dut, buf); |
| 5440 | snprintf(dut->ap_hessid, sizeof(dut->ap_hessid), |
| 5441 | "%02x:%02x:%02x:%02x:%02x:%02x", |
| 5442 | bssid[0], bssid[1], bssid[2], bssid[3], |
| 5443 | bssid[4], bssid[5]); |
| 5444 | } else { |
| 5445 | if (!get_hwaddr("wifi0", bssid)) { |
| 5446 | snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_HESSID=" |
| 5447 | "%02x:%02x:%02x:%02x:%02x:%02x", |
| 5448 | bssid[0], bssid[1], bssid[2], bssid[3], |
| 5449 | bssid[4], bssid[5]); |
| 5450 | run_system(dut, buf); |
| 5451 | snprintf(dut->ap_hessid, sizeof(dut->ap_hessid), |
| 5452 | "%02x:%02x:%02x:%02x:%02x:%02x", |
| 5453 | bssid[0], bssid[1], bssid[2], bssid[3], |
| 5454 | bssid[4], bssid[5]); |
| 5455 | } else { |
| 5456 | /* load the driver and try again */ |
| 5457 | run_system(dut, "/etc/rc.d/rc.wlan up"); |
| 5458 | |
| 5459 | if (!get_hwaddr("wifi0", bssid)) { |
| 5460 | snprintf(buf, sizeof(buf), |
| 5461 | "cfg -a AP_HOTSPOT_HESSID=" |
| 5462 | "%02x:%02x:%02x:%02x:%02x:%02x", |
| 5463 | bssid[0], bssid[1], bssid[2], |
| 5464 | bssid[3], bssid[4], bssid[5]); |
| 5465 | run_system(dut, buf); |
| 5466 | snprintf(dut->ap_hessid, |
| 5467 | sizeof(dut->ap_hessid), |
| 5468 | "%02x:%02x:%02x:%02x:%02x:%02x", |
| 5469 | bssid[0], bssid[1], bssid[2], |
| 5470 | bssid[3], bssid[4], bssid[5]); |
| 5471 | } |
| 5472 | } |
| 5473 | } |
| 5474 | |
| 5475 | run_system(dut, "cfg -r AP_SSID_2"); |
| 5476 | run_system(dut, "cfg -c"); |
| 5477 | /* run_system(dut, "cfg -s"); */ |
| 5478 | } |
| 5479 | |
| 5480 | |
| 5481 | static void ath_reset_vht_defaults(struct sigma_dut *dut) |
| 5482 | { |
| 5483 | run_system(dut, "cfg -x"); |
| 5484 | run_system(dut, "cfg -a AP_RADIO_ID=1"); |
| 5485 | run_system(dut, "cfg -a AP_PRIMARY_CH_2=36"); |
| 5486 | run_system(dut, "cfg -a AP_STARTMODE=standard"); |
| 5487 | run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT80"); |
| 5488 | run_system(dut, "cfg -a TX_CHAINMASK_2=7"); |
| 5489 | run_system(dut, "cfg -a RX_CHAINMASK_2=7"); |
| 5490 | run_system(dut, "cfg -a ATH_countrycode=0x348"); |
| 5491 | /* NOTE: For Beeliner we have to turn off MU-MIMO */ |
| 5492 | if (system("rm /tmp/secath*") != 0) { |
| 5493 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5494 | "Failed to remove secath file"); |
| 5495 | } |
| 5496 | } |
| 5497 | |
| 5498 | |
| 5499 | static int cmd_ap_reset_default(struct sigma_dut *dut, struct sigma_conn *conn, |
| 5500 | struct sigma_cmd *cmd) |
| 5501 | { |
| 5502 | const char *type; |
Pradeep Reddy POTTETI | 83b8067 | 2016-09-02 13:01:44 +0530 | [diff] [blame] | 5503 | enum driver_type drv; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5504 | |
Pradeep Reddy POTTETI | 83b8067 | 2016-09-02 13:01:44 +0530 | [diff] [blame] | 5505 | drv = get_driver_type(); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5506 | dut->program = sigma_program_to_enum(get_param(cmd, "PROGRAM")); |
| 5507 | dut->device_type = AP_unknown; |
| 5508 | type = get_param(cmd, "type"); |
| 5509 | if (type && strcasecmp(type, "Testbed") == 0) |
| 5510 | dut->device_type = AP_testbed; |
| 5511 | if (type && strcasecmp(type, "DUT") == 0) |
| 5512 | dut->device_type = AP_dut; |
| 5513 | |
| 5514 | dut->ap_rts = 0; |
| 5515 | dut->ap_frgmnt = 0; |
| 5516 | dut->ap_bcnint = 0; |
| 5517 | dut->ap_key_mgmt = AP_OPEN; |
| 5518 | dut->ap_ssid[0] = '\0'; |
| 5519 | dut->ap_fake_pkhash = 0; |
| 5520 | memset(dut->ap_qos, 0, sizeof(dut->ap_qos)); |
| 5521 | memset(dut->ap_sta_qos, 0, sizeof(dut->ap_sta_qos)); |
| 5522 | dut->ap_addba_reject = 0; |
| 5523 | dut->ap_noack = AP_NOACK_NOT_SET; |
| 5524 | dut->ap_is_dual = 0; |
| 5525 | dut->ap_mode = AP_inval; |
| 5526 | dut->ap_mode_1 = AP_inval; |
| 5527 | |
| 5528 | dut->ap_allow_vht_wep = 0; |
| 5529 | dut->ap_allow_vht_tkip = 0; |
| 5530 | dut->ap_disable_protection = 0; |
| 5531 | memset(dut->ap_countrycode, 0, sizeof(dut->ap_countrycode)); |
| 5532 | dut->ap_dyn_bw_sig = AP_DYN_BW_SGNL_NOT_SET; |
| 5533 | dut->ap_ldpc = 0; |
| 5534 | dut->ap_sig_rts = 0; |
| 5535 | dut->ap_rx_amsdu = 0; |
| 5536 | dut->ap_txBF = 0; |
Mohammed Shafi Shajakhan | 495fdb2 | 2016-06-02 20:10:56 +0530 | [diff] [blame] | 5537 | dut->ap_mu_txBF = 0; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5538 | dut->ap_chwidth = AP_AUTO; |
| 5539 | |
Sarvepalli, Rajesh Babu | 24dc7e4 | 2016-03-18 21:27:26 +0530 | [diff] [blame] | 5540 | dut->ap_rsn_preauth = 0; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5541 | dut->ap_wpsnfc = 0; |
| 5542 | dut->ap_bss_load = -1; |
| 5543 | dut->ap_p2p_cross_connect = -1; |
| 5544 | |
Pradeep Reddy POTTETI | fba27db | 2015-11-20 16:42:22 +0530 | [diff] [blame] | 5545 | dut->ap_regulatory_mode = AP_80211D_MODE_DISABLED; |
| 5546 | dut->ap_dfs_mode = AP_DFS_MODE_DISABLED; |
| 5547 | |
Pradeep Reddy POTTETI | 0d3db63 | 2016-03-11 15:21:11 +0530 | [diff] [blame] | 5548 | if (dut->program == PROGRAM_HT || dut->program == PROGRAM_VHT) |
| 5549 | dut->ap_wme = AP_WME_ON; |
| 5550 | else |
| 5551 | dut->ap_wme = AP_WME_OFF; |
| 5552 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5553 | if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2) { |
| 5554 | int i; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5555 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5556 | if (drv == DRIVER_ATHEROS) |
| 5557 | cmd_ath_ap_hs2_reset(dut); |
| 5558 | else if (drv == DRIVER_OPENWRT) |
| 5559 | cmd_owrt_ap_hs2_reset(dut); |
| 5560 | |
| 5561 | dut->ap_interworking = 1; |
| 5562 | dut->ap_access_net_type = 2; |
| 5563 | dut->ap_internet = 0; |
| 5564 | dut->ap_venue_group = 2; |
| 5565 | dut->ap_venue_type = 8; |
| 5566 | dut->ap_domain_name_list[0] = '\0'; |
| 5567 | dut->ap_hs2 = 1; |
| 5568 | snprintf(dut->ap_roaming_cons, sizeof(dut->ap_roaming_cons), |
| 5569 | "506f9a;001bc504bd"); |
| 5570 | dut->ap_l2tif = 0; |
| 5571 | dut->ap_proxy_arp = 0; |
| 5572 | if (dut->bridge) { |
| 5573 | char buf[50]; |
| 5574 | |
| 5575 | snprintf(buf, sizeof(buf), "ip neigh flush dev %s", |
| 5576 | dut->bridge); |
| 5577 | if (system(buf) != 0) { |
| 5578 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 5579 | "%s ip neigh table flushing failed", |
| 5580 | dut->bridge); |
| 5581 | } |
| 5582 | |
| 5583 | snprintf(buf, sizeof(buf), "ebtables -F"); |
| 5584 | if (system(buf) != 0) { |
| 5585 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 5586 | "%s ebtables flushing failed", |
| 5587 | dut->bridge); |
| 5588 | } |
| 5589 | } |
| 5590 | dut->ap_dgaf_disable = 0; |
| 5591 | dut->ap_p2p_cross_connect = 0; |
| 5592 | dut->ap_gas_cb_delay = 0; |
| 5593 | dut->ap_nai_realm_list = 0; |
| 5594 | dut->ap_oper_name = 0; |
| 5595 | dut->ap_venue_name = 0; |
| 5596 | for (i = 0; i < 10; i++) { |
| 5597 | dut->ap_plmn_mcc[i][0] = '\0'; |
| 5598 | dut->ap_plmn_mnc[i][0] = '\0'; |
| 5599 | } |
| 5600 | dut->ap_wan_metrics = 0; |
| 5601 | dut->ap_conn_capab = 0; |
| 5602 | dut->ap_ip_addr_type_avail = 0; |
| 5603 | dut->ap_net_auth_type = 0; |
| 5604 | dut->ap_oper_class = 0; |
| 5605 | dut->ap_pmf = 0; |
| 5606 | dut->ap_add_sha256 = 0; |
| 5607 | } |
| 5608 | |
| 5609 | if (dut->program == PROGRAM_HS2_R2) { |
| 5610 | int i; |
| 5611 | const char hessid[] = "50:6f:9a:00:11:22"; |
| 5612 | |
| 5613 | memcpy(dut->ap_hessid, hessid, strlen(hessid) + 1); |
| 5614 | dut->ap_osu_ssid[0] = '\0'; |
| 5615 | dut->ap2_ssid[0] = '\0'; |
| 5616 | dut->ap_pmf = 1; |
| 5617 | dut->ap_osu_provider_list = 0; |
| 5618 | for (i = 0; i < 10; i++) { |
| 5619 | dut->ap_osu_server_uri[i][0] = '\0'; |
| 5620 | dut->ap_osu_method[i] = 0xFF; |
| 5621 | } |
| 5622 | dut->ap_qos_map_set = 0; |
| 5623 | dut->ap2_key_mgmt = AP2_OPEN; |
| 5624 | dut->ap2_proxy_arp = 0; |
| 5625 | dut->ap_osu_icon_tag = 0; |
| 5626 | } |
| 5627 | |
| 5628 | if (dut->program == PROGRAM_VHT) { |
| 5629 | /* Set up the defaults */ |
| 5630 | dut->ap_mode = AP_11ac; |
| 5631 | dut->ap_channel = 36; |
| 5632 | dut->ap_ampdu = 0; |
priyadharshini gowthaman | 264d544 | 2016-02-25 15:52:22 -0800 | [diff] [blame] | 5633 | dut->ap_ndpa_frame = 1; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5634 | if (dut->device_type == AP_testbed) { |
| 5635 | dut->ap_amsdu = 2; |
| 5636 | dut->ap_ldpc = 2; |
| 5637 | dut->ap_rx_amsdu = 2; |
| 5638 | dut->ap_sgi80 = 0; |
| 5639 | } else { |
| 5640 | dut->ap_amsdu = 1; |
Pradeep Reddy POTTETI | 83b8067 | 2016-09-02 13:01:44 +0530 | [diff] [blame] | 5641 | /* |
| 5642 | * As LDPC is optional, don't enable this by default |
| 5643 | * for LINUX-WCN driver. The ap_set_wireless command |
| 5644 | * can be used to enable LDPC, when needed. |
| 5645 | */ |
| 5646 | if (drv != DRIVER_LINUX_WCN) |
| 5647 | dut->ap_ldpc = 1; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5648 | dut->ap_rx_amsdu = 1; |
| 5649 | dut->ap_sgi80 = 1; |
| 5650 | } |
| 5651 | dut->ap_fixed_rate = 0; |
| 5652 | dut->ap_rx_streams = 3; |
| 5653 | dut->ap_tx_streams = 3; |
| 5654 | dut->ap_vhtmcs_map = 0; |
| 5655 | dut->ap_chwidth = AP_80; |
| 5656 | dut->ap_tx_stbc = 1; |
| 5657 | dut->ap_dyn_bw_sig = AP_DYN_BW_SGNL_ENABLED; |
Mohammed Shafi Shajakhan | bae7230 | 2016-03-02 11:56:23 +0530 | [diff] [blame] | 5658 | if (get_openwrt_driver_type() == OPENWRT_DRIVER_ATHEROS) |
| 5659 | dut->ap_dfs_mode = AP_DFS_MODE_ENABLED; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5660 | if (get_driver_type() == DRIVER_ATHEROS) |
| 5661 | ath_reset_vht_defaults(dut); |
| 5662 | } |
| 5663 | |
priyadharshini gowthaman | a27b5b6 | 2016-06-22 22:47:14 -0700 | [diff] [blame] | 5664 | if (dut->program == PROGRAM_LOC) { |
priyadharshini gowthaman | 8e26ff4 | 2016-06-22 22:47:14 -0700 | [diff] [blame] | 5665 | dut->ap_rrm = 1; |
| 5666 | dut->ap_rtt = 1; |
| 5667 | dut->ap_lci = 0; |
| 5668 | dut->ap_val_lci[0] = '\0'; |
priyadharshini gowthaman | c2357bd | 2016-06-22 22:47:14 -0700 | [diff] [blame] | 5669 | dut->ap_infoz[0] = '\0'; |
priyadharshini gowthaman | 8e26ff4 | 2016-06-22 22:47:14 -0700 | [diff] [blame] | 5670 | dut->ap_lcr = 0; |
| 5671 | dut->ap_val_lcr[0] = '\0'; |
| 5672 | dut->ap_neighap = 0; |
| 5673 | dut->ap_opchannel = 0; |
| 5674 | dut->ap_scan = 0; |
| 5675 | dut->ap2_ssid[0] = '\0'; |
priyadharshini gowthaman | c2357bd | 2016-06-22 22:47:14 -0700 | [diff] [blame] | 5676 | dut->ap_fqdn_held = 0; |
| 5677 | dut->ap_fqdn_supl = 0; |
priyadharshini gowthaman | c52fff8 | 2016-06-22 22:47:14 -0700 | [diff] [blame] | 5678 | dut->ap_interworking = 0; |
| 5679 | dut->ap_gas_cb_delay = 0; |
priyadharshini gowthaman | a27b5b6 | 2016-06-22 22:47:14 -0700 | [diff] [blame] | 5680 | dut->ap_msnt_type = 0; |
| 5681 | } |
| 5682 | |
priyadharshini gowthaman | b4e05fc | 2016-10-13 15:02:35 -0700 | [diff] [blame] | 5683 | if (dut->program == PROGRAM_MBO) { |
| 5684 | dut->ap_mbo = 1; |
| 5685 | dut->ap_interworking = 1; |
| 5686 | dut->ap_ne_class = 0; |
| 5687 | dut->ap_ne_op_ch = 0; |
| 5688 | dut->ap_set_bssidpref = 1; |
| 5689 | } |
| 5690 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5691 | if (kill_process(dut, "(hostapd)", 1, SIGTERM) == 0 || |
| 5692 | system("killall hostapd") == 0) { |
| 5693 | int i; |
| 5694 | /* Wait some time to allow hostapd to complete cleanup before |
| 5695 | * starting a new process */ |
| 5696 | for (i = 0; i < 10; i++) { |
| 5697 | usleep(500000); |
| 5698 | if (system("pidof hostapd") != 0) |
| 5699 | break; |
| 5700 | } |
| 5701 | } |
| 5702 | |
| 5703 | if (if_nametoindex("sigmadut") > 0 && |
| 5704 | system("iw dev sigmadut del") != 0) |
| 5705 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to remove " |
| 5706 | "monitor interface"); |
| 5707 | |
| 5708 | return 1; |
| 5709 | } |
| 5710 | |
| 5711 | |
| 5712 | static int cmd_ap_get_info(struct sigma_dut *dut, struct sigma_conn *conn, |
| 5713 | struct sigma_cmd *cmd) |
| 5714 | { |
| 5715 | /* const char *name = get_param(cmd, "NAME"); */ |
| 5716 | struct stat s; |
| 5717 | char resp[200]; |
| 5718 | FILE *f; |
| 5719 | enum driver_type drv = get_driver_type(); |
| 5720 | |
| 5721 | switch (drv) { |
| 5722 | case DRIVER_ATHEROS: { |
| 5723 | /* Atheros AP */ |
| 5724 | struct utsname uts; |
| 5725 | char *version, athver[100]; |
| 5726 | |
| 5727 | if (stat("/proc/athversion", &s) != 0) { |
| 5728 | if (system("/etc/rc.d/rc.wlan up") != 0) { |
| 5729 | } |
| 5730 | } |
| 5731 | |
| 5732 | athver[0] = '\0'; |
| 5733 | f = fopen("/proc/athversion", "r"); |
| 5734 | if (f) { |
| 5735 | if (fgets(athver, sizeof(athver), f)) { |
| 5736 | char *pos = strchr(athver, '\n'); |
| 5737 | if (pos) |
| 5738 | *pos = '\0'; |
| 5739 | } |
| 5740 | fclose(f); |
| 5741 | } |
| 5742 | |
| 5743 | if (uname(&uts) == 0) |
| 5744 | version = uts.release; |
| 5745 | else |
| 5746 | version = "Unknown"; |
| 5747 | |
| 5748 | if (if_nametoindex("ath1") > 0) |
| 5749 | snprintf(resp, sizeof(resp), "interface,ath0_24G " |
| 5750 | "ath1_5G,agent,1.0,version,%s/drv:%s", |
| 5751 | version, athver); |
| 5752 | else |
| 5753 | snprintf(resp, sizeof(resp), "interface,ath0_24G," |
| 5754 | "agent,1.0,version,%s/drv:%s", |
| 5755 | version, athver); |
| 5756 | |
| 5757 | send_resp(dut, conn, SIGMA_COMPLETE, resp); |
| 5758 | return 0; |
| 5759 | } |
Sreelakshmi Konamki | b692f10 | 2016-04-26 19:47:00 +0530 | [diff] [blame] | 5760 | case DRIVER_LINUX_WCN: |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5761 | case DRIVER_MAC80211: { |
| 5762 | struct utsname uts; |
| 5763 | char *version; |
| 5764 | |
| 5765 | if (uname(&uts) == 0) |
| 5766 | version = uts.release; |
| 5767 | else |
| 5768 | version = "Unknown"; |
| 5769 | |
| 5770 | if (if_nametoindex("wlan1") > 0) |
| 5771 | snprintf(resp, sizeof(resp), "interface,wlan0_24G " |
| 5772 | "wlan1_5G,agent,1.0,version,%s", version); |
| 5773 | else |
| 5774 | snprintf(resp, sizeof(resp), "interface,wlan0_any," |
| 5775 | "agent,1.0,version,%s", version); |
| 5776 | |
| 5777 | send_resp(dut, conn, SIGMA_COMPLETE, resp); |
| 5778 | return 0; |
| 5779 | } |
| 5780 | case DRIVER_QNXNTO: { |
| 5781 | struct utsname uts; |
| 5782 | char *version; |
| 5783 | |
| 5784 | if (uname(&uts) == 0) |
| 5785 | version = uts.release; |
| 5786 | else |
| 5787 | version = "Unknown"; |
| 5788 | snprintf(resp, sizeof(resp), |
| 5789 | "interface,%s_any,agent,1.0,version,%s", |
| 5790 | sigma_main_ifname ? sigma_main_ifname : "NA", |
| 5791 | version); |
| 5792 | send_resp(dut, conn, SIGMA_COMPLETE, resp); |
| 5793 | return 0; |
| 5794 | } |
| 5795 | case DRIVER_OPENWRT: { |
| 5796 | switch (get_openwrt_driver_type()) { |
| 5797 | case OPENWRT_DRIVER_ATHEROS: { |
| 5798 | struct utsname uts; |
| 5799 | char *version; |
| 5800 | |
| 5801 | if (uname(&uts) == 0) |
| 5802 | version = uts.release; |
| 5803 | else |
| 5804 | version = "Unknown"; |
| 5805 | |
| 5806 | if (if_nametoindex("ath1") > 0) |
| 5807 | snprintf(resp, sizeof(resp), |
| 5808 | "interface,ath0_5G ath1_24G,agent,1.0,version,%s", |
| 5809 | version); |
| 5810 | else |
| 5811 | snprintf(resp, sizeof(resp), |
| 5812 | "interface,ath0_any,agent,1.0,version,%s", |
| 5813 | version); |
| 5814 | |
| 5815 | send_resp(dut, conn, SIGMA_COMPLETE, resp); |
| 5816 | return 0; |
| 5817 | } |
| 5818 | default: |
| 5819 | send_resp(dut, conn, SIGMA_ERROR, |
| 5820 | "errorCode,Unsupported openwrt driver"); |
| 5821 | return 0; |
| 5822 | } |
| 5823 | } |
| 5824 | default: |
| 5825 | send_resp(dut, conn, SIGMA_ERROR, |
| 5826 | "errorCode,Unsupported driver"); |
| 5827 | return 0; |
| 5828 | } |
| 5829 | } |
| 5830 | |
| 5831 | |
| 5832 | static int cmd_ap_deauth_sta(struct sigma_dut *dut, struct sigma_conn *conn, |
| 5833 | struct sigma_cmd *cmd) |
| 5834 | { |
| 5835 | /* const char *name = get_param(cmd, "NAME"); */ |
| 5836 | /* const char *ifname = get_param(cmd, "INTERFACE"); */ |
| 5837 | const char *val; |
| 5838 | char buf[100]; |
| 5839 | |
| 5840 | val = get_param(cmd, "MinorCode"); |
| 5841 | if (val) { |
| 5842 | /* TODO: add support for P2P minor code */ |
| 5843 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,MinorCode not " |
| 5844 | "yet supported"); |
| 5845 | return 0; |
| 5846 | } |
| 5847 | |
| 5848 | val = get_param(cmd, "STA_MAC_ADDRESS"); |
| 5849 | if (val == NULL) |
| 5850 | return -1; |
| 5851 | snprintf(buf, sizeof(buf), "deauth %s", val); |
| 5852 | if (run_hostapd_cli(dut, buf) != 0) |
| 5853 | return -2; |
| 5854 | |
| 5855 | return 1; |
| 5856 | } |
| 5857 | |
| 5858 | |
| 5859 | #ifdef __linux__ |
| 5860 | int inject_frame(int s, const void *data, size_t len, int encrypt); |
| 5861 | int open_monitor(const char *ifname); |
| 5862 | int hwaddr_aton(const char *txt, unsigned char *addr); |
| 5863 | #endif /* __linux__ */ |
| 5864 | |
| 5865 | enum send_frame_type { |
| 5866 | DISASSOC, DEAUTH, SAQUERY |
| 5867 | }; |
| 5868 | enum send_frame_protection { |
| 5869 | CORRECT_KEY, INCORRECT_KEY, UNPROTECTED |
| 5870 | }; |
| 5871 | |
| 5872 | |
| 5873 | static int ap_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn, |
| 5874 | enum send_frame_type frame, |
| 5875 | enum send_frame_protection protected, |
| 5876 | const char *sta_addr) |
| 5877 | { |
| 5878 | #ifdef __linux__ |
| 5879 | unsigned char buf[1000], *pos; |
| 5880 | int s, res; |
| 5881 | unsigned char addr_sta[6], addr_own[6]; |
| 5882 | char *ifname; |
| 5883 | char cbuf[100]; |
| 5884 | struct ifreq ifr; |
| 5885 | |
| 5886 | if ((dut->ap_mode == AP_11a || dut->ap_mode == AP_11na || |
| 5887 | dut->ap_mode == AP_11ac) && |
| 5888 | if_nametoindex("wlan1") > 0) |
| 5889 | ifname = "wlan1"; |
| 5890 | else |
| 5891 | ifname = "wlan0"; |
| 5892 | |
| 5893 | if (hwaddr_aton(sta_addr, addr_sta) < 0) |
| 5894 | return -1; |
| 5895 | |
| 5896 | s = socket(AF_INET, SOCK_DGRAM, 0); |
| 5897 | if (s < 0) |
| 5898 | return -1; |
| 5899 | memset(&ifr, 0, sizeof(ifr)); |
| 5900 | strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); |
| 5901 | if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) { |
| 5902 | perror("ioctl"); |
| 5903 | close(s); |
| 5904 | return -1; |
| 5905 | } |
| 5906 | close(s); |
| 5907 | memcpy(addr_own, ifr.ifr_hwaddr.sa_data, 6); |
| 5908 | |
| 5909 | if (if_nametoindex("sigmadut") == 0) { |
| 5910 | snprintf(cbuf, sizeof(cbuf), |
| 5911 | "iw dev %s interface add sigmadut type monitor", |
| 5912 | ifname); |
| 5913 | if (system(cbuf) != 0 || |
| 5914 | if_nametoindex("sigmadut") == 0) { |
| 5915 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add " |
| 5916 | "monitor interface with '%s'", cbuf); |
| 5917 | return -2; |
| 5918 | } |
| 5919 | } |
| 5920 | |
| 5921 | if (system("ifconfig sigmadut up") != 0) { |
| 5922 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set " |
| 5923 | "monitor interface up"); |
| 5924 | return -2; |
| 5925 | } |
| 5926 | |
| 5927 | pos = buf; |
| 5928 | |
| 5929 | /* Frame Control */ |
| 5930 | switch (frame) { |
| 5931 | case DISASSOC: |
| 5932 | *pos++ = 0xa0; |
| 5933 | break; |
| 5934 | case DEAUTH: |
| 5935 | *pos++ = 0xc0; |
| 5936 | break; |
| 5937 | case SAQUERY: |
| 5938 | *pos++ = 0xd0; |
| 5939 | break; |
| 5940 | } |
| 5941 | |
| 5942 | if (protected == INCORRECT_KEY) |
| 5943 | *pos++ = 0x40; /* Set Protected field to 1 */ |
| 5944 | else |
| 5945 | *pos++ = 0x00; |
| 5946 | |
| 5947 | /* Duration */ |
| 5948 | *pos++ = 0x00; |
| 5949 | *pos++ = 0x00; |
| 5950 | |
| 5951 | /* addr1 = DA (station) */ |
| 5952 | memcpy(pos, addr_sta, 6); |
| 5953 | pos += 6; |
| 5954 | /* addr2 = SA (own address) */ |
| 5955 | memcpy(pos, addr_own, 6); |
| 5956 | pos += 6; |
| 5957 | /* addr3 = BSSID (own address) */ |
| 5958 | memcpy(pos, addr_own, 6); |
| 5959 | pos += 6; |
| 5960 | |
| 5961 | /* Seq# (to be filled by driver/mac80211) */ |
| 5962 | *pos++ = 0x00; |
| 5963 | *pos++ = 0x00; |
| 5964 | |
| 5965 | if (protected == INCORRECT_KEY) { |
| 5966 | /* CCMP parameters */ |
| 5967 | memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8); |
| 5968 | pos += 8; |
| 5969 | } |
| 5970 | |
| 5971 | if (protected == INCORRECT_KEY) { |
| 5972 | switch (frame) { |
| 5973 | case DEAUTH: |
| 5974 | /* Reason code (encrypted) */ |
| 5975 | memcpy(pos, "\xa7\x39", 2); |
| 5976 | pos += 2; |
| 5977 | break; |
| 5978 | case DISASSOC: |
| 5979 | /* Reason code (encrypted) */ |
| 5980 | memcpy(pos, "\xa7\x39", 2); |
| 5981 | pos += 2; |
| 5982 | break; |
| 5983 | case SAQUERY: |
| 5984 | /* Category|Action|TransID (encrypted) */ |
| 5985 | memcpy(pos, "\x6f\xbd\xe9\x4d", 4); |
| 5986 | pos += 4; |
| 5987 | break; |
| 5988 | default: |
| 5989 | return -1; |
| 5990 | } |
| 5991 | |
| 5992 | /* CCMP MIC */ |
| 5993 | memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8); |
| 5994 | pos += 8; |
| 5995 | } else { |
| 5996 | switch (frame) { |
| 5997 | case DEAUTH: |
| 5998 | /* reason code = 8 */ |
| 5999 | *pos++ = 0x08; |
| 6000 | *pos++ = 0x00; |
| 6001 | break; |
| 6002 | case DISASSOC: |
| 6003 | /* reason code = 8 */ |
| 6004 | *pos++ = 0x08; |
| 6005 | *pos++ = 0x00; |
| 6006 | break; |
| 6007 | case SAQUERY: |
| 6008 | /* Category - SA Query */ |
| 6009 | *pos++ = 0x08; |
| 6010 | /* SA query Action - Request */ |
| 6011 | *pos++ = 0x00; |
| 6012 | /* Transaction ID */ |
| 6013 | *pos++ = 0x12; |
| 6014 | *pos++ = 0x34; |
| 6015 | break; |
| 6016 | } |
| 6017 | } |
| 6018 | |
| 6019 | s = open_monitor("sigmadut"); |
| 6020 | if (s < 0) { |
| 6021 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open " |
| 6022 | "monitor socket"); |
| 6023 | return 0; |
| 6024 | } |
| 6025 | |
| 6026 | res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY); |
| 6027 | if (res < 0) { |
| 6028 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to " |
| 6029 | "inject frame"); |
Pradeep Reddy POTTETI | 673d85c | 2016-07-26 19:08:07 +0530 | [diff] [blame] | 6030 | close(s); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6031 | return 0; |
| 6032 | } |
| 6033 | if (res < pos - buf) { |
| 6034 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Only partial " |
| 6035 | "frame sent"); |
Pradeep Reddy POTTETI | 673d85c | 2016-07-26 19:08:07 +0530 | [diff] [blame] | 6036 | close(s); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6037 | return 0; |
| 6038 | } |
| 6039 | |
| 6040 | close(s); |
| 6041 | |
| 6042 | return 1; |
| 6043 | #else /* __linux__ */ |
| 6044 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,ap_send_frame not " |
| 6045 | "yet supported"); |
| 6046 | return 0; |
| 6047 | #endif /* __linux__ */ |
| 6048 | } |
| 6049 | |
| 6050 | |
| 6051 | int ap_send_frame_hs2(struct sigma_dut *dut, struct sigma_conn *conn, |
| 6052 | struct sigma_cmd *cmd) |
| 6053 | { |
| 6054 | const char *val, *dest; |
| 6055 | char buf[100]; |
| 6056 | |
| 6057 | val = get_param(cmd, "FrameName"); |
| 6058 | if (val == NULL) |
| 6059 | return -1; |
| 6060 | |
| 6061 | if (strcasecmp(val, "QoSMapConfigure") == 0) { |
| 6062 | dest = get_param(cmd, "Dest"); |
| 6063 | if (!dest) |
| 6064 | return -1; |
| 6065 | |
| 6066 | val = get_param(cmd, "QoS_MAP_SET"); |
| 6067 | if (val) { |
| 6068 | dut->ap_qos_map_set = atoi(val); |
| 6069 | sigma_dut_print(dut, DUT_MSG_INFO, "ap_qos_map_set %d", |
| 6070 | dut->ap_qos_map_set); |
| 6071 | } |
| 6072 | |
| 6073 | if (dut->ap_qos_map_set == 1) |
| 6074 | run_hostapd_cli(dut, "set_qos_map_set " QOS_MAP_SET_1); |
| 6075 | else if (dut->ap_qos_map_set == 2) |
| 6076 | run_hostapd_cli(dut, "set_qos_map_set " QOS_MAP_SET_2); |
| 6077 | |
| 6078 | snprintf(buf, sizeof(buf), "send_qos_map_conf %s", dest); |
| 6079 | if (run_hostapd_cli(dut, buf) != 0) |
| 6080 | return -1; |
| 6081 | } |
| 6082 | |
| 6083 | return 1; |
| 6084 | } |
| 6085 | |
| 6086 | |
| 6087 | static int ath_ap_send_frame_vht(struct sigma_dut *dut, struct sigma_conn *conn, |
| 6088 | struct sigma_cmd *cmd) |
| 6089 | { |
| 6090 | const char *val; |
| 6091 | char *ifname; |
| 6092 | char buf[100]; |
| 6093 | int chwidth, nss; |
| 6094 | |
| 6095 | val = get_param(cmd, "FrameName"); |
| 6096 | if (!val || strcasecmp(val, "op_md_notif_frm") != 0) { |
| 6097 | send_resp(dut, conn, SIGMA_ERROR, |
| 6098 | "errorCode,Unsupported FrameName"); |
| 6099 | return 0; |
| 6100 | } |
| 6101 | |
| 6102 | /* |
| 6103 | * Sequence of commands for Opmode notification on |
| 6104 | * Peregrine based products |
| 6105 | */ |
| 6106 | ifname = get_main_ifname(); |
| 6107 | |
| 6108 | /* Disable STBC */ |
| 6109 | snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc 0", ifname); |
| 6110 | if (system(buf) != 0) { |
| 6111 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6112 | "iwpriv tx_stbc 0 failed!"); |
| 6113 | } |
| 6114 | |
| 6115 | /* Check whether optional arg channel width was passed */ |
| 6116 | val = get_param(cmd, "Channel_width"); |
| 6117 | if (val) { |
| 6118 | switch (atoi(val)) { |
| 6119 | case 20: |
| 6120 | chwidth = 0; |
| 6121 | break; |
| 6122 | case 40: |
| 6123 | chwidth = 1; |
| 6124 | break; |
| 6125 | case 80: |
| 6126 | chwidth = 2; |
| 6127 | break; |
| 6128 | case 160: |
| 6129 | chwidth = 3; |
| 6130 | break; |
| 6131 | default: |
| 6132 | chwidth = 2; |
| 6133 | break; |
| 6134 | } |
| 6135 | snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d", |
| 6136 | ifname, chwidth); |
| 6137 | if (system(buf) != 0) { |
| 6138 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6139 | "iwpriv chwidth failed!"); |
| 6140 | } |
| 6141 | } |
| 6142 | |
| 6143 | /* Check whether optional arg NSS was passed */ |
| 6144 | val = get_param(cmd, "NSS"); |
| 6145 | if (val) { |
| 6146 | /* Convert nss to chainmask */ |
| 6147 | switch (atoi(val)) { |
| 6148 | case 1: |
| 6149 | nss = 1; |
| 6150 | break; |
| 6151 | case 2: |
| 6152 | nss = 3; |
| 6153 | break; |
| 6154 | case 3: |
| 6155 | nss = 7; |
| 6156 | break; |
| 6157 | default: |
| 6158 | /* We do not support NSS > 3 */ |
| 6159 | nss = 3; |
| 6160 | break; |
| 6161 | } |
| 6162 | snprintf(buf, sizeof(buf), "iwpriv %s rxchainmask %d", |
| 6163 | ifname, nss); |
| 6164 | if (system(buf) != 0) { |
| 6165 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6166 | "iwpriv rxchainmask failed!"); |
| 6167 | } |
| 6168 | } |
| 6169 | |
| 6170 | /* Send the opmode notification */ |
| 6171 | snprintf(buf, sizeof(buf), "iwpriv %s opmode_notify 1", ifname); |
| 6172 | if (system(buf) != 0) { |
| 6173 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6174 | "iwpriv opmode_notify failed!"); |
| 6175 | } |
| 6176 | |
| 6177 | return 1; |
| 6178 | } |
| 6179 | |
| 6180 | |
priyadharshini gowthaman | a27b5b6 | 2016-06-22 22:47:14 -0700 | [diff] [blame] | 6181 | static int ath_ap_send_frame_loc(struct sigma_dut *dut, struct sigma_conn *conn, |
| 6182 | struct sigma_cmd *cmd) |
| 6183 | { |
| 6184 | const char *val; |
| 6185 | FILE *f; |
priyadharshini gowthaman | a61badd | 2016-08-16 13:37:27 -0700 | [diff] [blame] | 6186 | int rand_int = 0; |
priyadharshini gowthaman | a27b5b6 | 2016-06-22 22:47:14 -0700 | [diff] [blame] | 6187 | |
| 6188 | val = get_param(cmd, "MsntType"); |
| 6189 | if (val) { |
| 6190 | if (dut->ap_msnt_type == 0) |
| 6191 | dut->ap_msnt_type = atoi(val); |
| 6192 | |
| 6193 | if (dut->ap_msnt_type != 5 && dut->ap_msnt_type != 2) { |
| 6194 | dut->ap_msnt_type = atoi(val); |
| 6195 | if (dut->ap_msnt_type == 1) { |
priyadharshini gowthaman | a61badd | 2016-08-16 13:37:27 -0700 | [diff] [blame] | 6196 | val = get_param(cmd, "RandInterval"); |
| 6197 | if (val) |
| 6198 | rand_int = atoi(val); |
priyadharshini gowthaman | a27b5b6 | 2016-06-22 22:47:14 -0700 | [diff] [blame] | 6199 | f = fopen("/tmp/ftmrr.txt", "a"); |
| 6200 | if (!f) { |
| 6201 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6202 | "Failed to open /tmp/ftmrr.txt"); |
| 6203 | return -1; |
| 6204 | } |
| 6205 | |
| 6206 | fprintf(f, "sta_mac = %s\n", cmd->values[3]); |
priyadharshini gowthaman | a61badd | 2016-08-16 13:37:27 -0700 | [diff] [blame] | 6207 | fprintf(f, "meas_type = 0x10\nrand_inter = 0x%x\nmin_ap_count = 0x%s\ndialogtoken = 0x1\nnum_repetitions = 0x0\nmeas_token = 0xf\nmeas_req_mode = 0x00\n", |
| 6208 | rand_int, cmd->values[7]); |
priyadharshini gowthaman | a27b5b6 | 2016-06-22 22:47:14 -0700 | [diff] [blame] | 6209 | fclose(f); |
| 6210 | dut->ap_msnt_type = 5; |
| 6211 | run_system(dut, "wpc -f /tmp/ftmrr.txt"); |
| 6212 | } |
| 6213 | } else if (dut->ap_msnt_type == 5) { |
| 6214 | run_system(dut, "wpc -f /tmp/ftmrr.txt"); |
| 6215 | } else if (dut->ap_msnt_type == 2) { |
| 6216 | f = fopen("/tmp/wru.txt", "w"); |
| 6217 | if (!f) { |
| 6218 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6219 | "Failed to open /tmp/wru.txt"); |
| 6220 | return -1; |
| 6221 | } |
| 6222 | |
| 6223 | fprintf(f, "sta_mac = %s\n", cmd->values[3]); |
| 6224 | fprintf(f, "meas_type = 0x08\ndialogtoken = 0x1\nnum_repetitions = 0x0\nmeas_token = 0x1\nmeas_req_mode = 0x00\nloc_subject = 0x01\n"); |
| 6225 | fclose(f); |
| 6226 | run_system(dut, "wpc -w /tmp/wru.txt"); |
| 6227 | } |
| 6228 | } |
| 6229 | return 1; |
| 6230 | } |
| 6231 | |
| 6232 | |
priyadharshini gowthaman | b4e05fc | 2016-10-13 15:02:35 -0700 | [diff] [blame] | 6233 | static int ath_ap_send_frame_mbo(struct sigma_dut *dut, struct sigma_conn *conn, |
| 6234 | struct sigma_cmd *cmd) |
| 6235 | { |
| 6236 | const char *val; |
| 6237 | char *ifname; |
| 6238 | char buf[100]; |
| 6239 | int disassoc_timer = 0; |
| 6240 | int apchanrpt = 0; |
| 6241 | int req_ssid = 0; |
| 6242 | |
| 6243 | ifname = get_main_ifname(); |
| 6244 | |
| 6245 | val = get_param(cmd, "FrameName"); |
| 6246 | if (!val) |
| 6247 | return -1; |
| 6248 | |
| 6249 | if (strcasecmp(val, "BTMReq") == 0) { |
| 6250 | val = get_param(cmd, "Disassoc_Timer"); |
| 6251 | if (val) |
| 6252 | disassoc_timer = atoi(val); |
| 6253 | snprintf(buf, sizeof(buf), |
| 6254 | "wifitool %s sendbstmreq %s %s %d 3 %d %d", |
| 6255 | ifname, cmd->values[3], cmd->values[5], disassoc_timer, |
| 6256 | dut->ap_btmreq_disassoc_imnt, dut->ap_btmreq_term_bit); |
| 6257 | if (system(buf) != 0) { |
| 6258 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6259 | "wifitool btmreq failed!"); |
| 6260 | } |
| 6261 | } else if (strcasecmp(val, "BcnRptReq") == 0) { |
| 6262 | val = get_param(cmd, "APChanRpt"); |
| 6263 | if (val) |
| 6264 | apchanrpt = atoi(val); |
| 6265 | val = get_param(cmd, "SSID"); |
| 6266 | req_ssid = strcasecmp(val, "") != 0; |
| 6267 | if (apchanrpt != 0) { |
| 6268 | snprintf(buf, sizeof(buf), |
| 6269 | "wifitool %s sendbcnrpt %s %s %s %s %s %s %d %s %s 1 1 %s", |
| 6270 | ifname, cmd->values[4], cmd->values[5], |
| 6271 | cmd->values[6], cmd->values[7], cmd->values[8], |
| 6272 | cmd->values[9], req_ssid, |
| 6273 | cmd->values[12], cmd->values[13], |
| 6274 | cmd->values[10]); |
| 6275 | if (system(buf) != 0) { |
| 6276 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6277 | "wifitool btmreq failed!"); |
| 6278 | } |
| 6279 | } else { |
| 6280 | snprintf(buf, sizeof(buf), |
| 6281 | "wifitool %s sendbcnrpt %s %s %s %s %s %s %d %s %s 1 0 %s", |
| 6282 | ifname, cmd->values[4], cmd->values[5], |
| 6283 | cmd->values[6], cmd->values[7], cmd->values[8], |
| 6284 | cmd->values[9], req_ssid, |
| 6285 | cmd->values[12], cmd->values[13], |
| 6286 | cmd->values[10]); |
| 6287 | if (system(buf) != 0) { |
| 6288 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6289 | "wifitool btmreq failed!"); |
| 6290 | } |
| 6291 | } |
| 6292 | } |
| 6293 | |
| 6294 | return 1; |
| 6295 | } |
| 6296 | |
| 6297 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6298 | static int ap_send_frame_vht(struct sigma_dut *dut, struct sigma_conn *conn, |
| 6299 | struct sigma_cmd *cmd) |
| 6300 | { |
| 6301 | switch (get_driver_type()) { |
| 6302 | case DRIVER_ATHEROS: |
| 6303 | return ath_ap_send_frame_vht(dut, conn, cmd); |
| 6304 | break; |
| 6305 | case DRIVER_OPENWRT: |
| 6306 | switch (get_openwrt_driver_type()) { |
| 6307 | case OPENWRT_DRIVER_ATHEROS: |
| 6308 | return ath_ap_send_frame_vht(dut, conn, cmd); |
| 6309 | default: |
| 6310 | send_resp(dut, conn, SIGMA_ERROR, |
| 6311 | "errorCode,Unsupported ap_send_frame with the current openwrt driver"); |
| 6312 | return 0; |
| 6313 | } |
| 6314 | default: |
| 6315 | send_resp(dut, conn, SIGMA_ERROR, |
| 6316 | "errorCode,Unsupported ap_send_frame with the current driver"); |
| 6317 | return 0; |
| 6318 | } |
| 6319 | } |
| 6320 | |
| 6321 | |
priyadharshini gowthaman | a27b5b6 | 2016-06-22 22:47:14 -0700 | [diff] [blame] | 6322 | static int ap_send_frame_loc(struct sigma_dut *dut, struct sigma_conn *conn, |
| 6323 | struct sigma_cmd *cmd) |
| 6324 | { |
| 6325 | switch (get_driver_type()) { |
| 6326 | case DRIVER_ATHEROS: |
| 6327 | return ath_ap_send_frame_loc(dut, conn, cmd); |
| 6328 | case DRIVER_OPENWRT: |
| 6329 | switch (get_openwrt_driver_type()) { |
| 6330 | case OPENWRT_DRIVER_ATHEROS: |
| 6331 | return ath_ap_send_frame_loc(dut, conn, cmd); |
| 6332 | default: |
| 6333 | send_resp(dut, conn, SIGMA_ERROR, |
| 6334 | "errorCode,Unsupported ap_send_frame_loc with the current openwrt driver"); |
| 6335 | return 0; |
| 6336 | } |
| 6337 | default: |
| 6338 | send_resp(dut, conn, SIGMA_ERROR, |
| 6339 | "errorCode,Unsupported ap_send_frame_loc with the current driver"); |
| 6340 | return 0; |
| 6341 | } |
| 6342 | } |
| 6343 | |
| 6344 | |
priyadharshini gowthaman | b4e05fc | 2016-10-13 15:02:35 -0700 | [diff] [blame] | 6345 | static int ap_send_frame_mbo(struct sigma_dut *dut, struct sigma_conn *conn, |
| 6346 | struct sigma_cmd *cmd) |
| 6347 | { |
| 6348 | switch (get_driver_type()) { |
| 6349 | case DRIVER_ATHEROS: |
| 6350 | return ath_ap_send_frame_mbo(dut, conn, cmd); |
| 6351 | case DRIVER_OPENWRT: |
| 6352 | switch (get_openwrt_driver_type()) { |
| 6353 | case OPENWRT_DRIVER_ATHEROS: |
| 6354 | return ath_ap_send_frame_mbo(dut, conn, cmd); |
| 6355 | default: |
| 6356 | send_resp(dut, conn, SIGMA_ERROR, |
| 6357 | "errorCode,Unsupported ap_send_frame with the current openwrt driver"); |
| 6358 | return 0; |
| 6359 | } |
| 6360 | default: |
| 6361 | send_resp(dut, conn, SIGMA_ERROR, |
| 6362 | "errorCode,Unsupported ap_send_frame with the current driver"); |
| 6363 | return 0; |
| 6364 | } |
| 6365 | } |
| 6366 | |
| 6367 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6368 | int cmd_ap_send_frame(struct sigma_dut *dut, struct sigma_conn *conn, |
| 6369 | struct sigma_cmd *cmd) |
| 6370 | { |
| 6371 | /* const char *name = get_param(cmd, "NAME"); */ |
| 6372 | /* const char *ifname = get_param(cmd, "INTERFACE"); */ |
| 6373 | const char *val; |
| 6374 | enum send_frame_type frame; |
| 6375 | enum send_frame_protection protected; |
| 6376 | char buf[100]; |
| 6377 | |
| 6378 | val = get_param(cmd, "Program"); |
| 6379 | if (val) { |
| 6380 | if (strcasecmp(val, "HS2") == 0 || |
| 6381 | strcasecmp(val, "HS2-R2") == 0) |
| 6382 | return ap_send_frame_hs2(dut, conn, cmd); |
| 6383 | if (strcasecmp(val, "VHT") == 0) |
| 6384 | return ap_send_frame_vht(dut, conn, cmd); |
priyadharshini gowthaman | a27b5b6 | 2016-06-22 22:47:14 -0700 | [diff] [blame] | 6385 | if (strcasecmp(val, "LOC") == 0) |
| 6386 | return ap_send_frame_loc(dut, conn, cmd); |
priyadharshini gowthaman | b4e05fc | 2016-10-13 15:02:35 -0700 | [diff] [blame] | 6387 | if (strcasecmp(val, "MBO") == 0) |
| 6388 | return ap_send_frame_mbo(dut, conn, cmd); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6389 | } |
| 6390 | |
| 6391 | val = get_param(cmd, "PMFFrameType"); |
| 6392 | if (val == NULL) |
| 6393 | val = get_param(cmd, "FrameName"); |
| 6394 | if (val == NULL) |
| 6395 | val = get_param(cmd, "Type"); |
| 6396 | if (val == NULL) |
| 6397 | return -1; |
| 6398 | if (strcasecmp(val, "disassoc") == 0) |
| 6399 | frame = DISASSOC; |
| 6400 | else if (strcasecmp(val, "deauth") == 0) |
| 6401 | frame = DEAUTH; |
| 6402 | else if (strcasecmp(val, "saquery") == 0) |
| 6403 | frame = SAQUERY; |
| 6404 | else { |
| 6405 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported " |
| 6406 | "PMFFrameType"); |
| 6407 | return 0; |
| 6408 | } |
| 6409 | |
| 6410 | val = get_param(cmd, "PMFProtected"); |
| 6411 | if (val == NULL) |
| 6412 | val = get_param(cmd, "Protected"); |
| 6413 | if (val == NULL) |
| 6414 | return -1; |
| 6415 | if (strcasecmp(val, "Correct-key") == 0 || |
| 6416 | strcasecmp(val, "CorrectKey") == 0) |
| 6417 | protected = CORRECT_KEY; |
| 6418 | else if (strcasecmp(val, "IncorrectKey") == 0) |
| 6419 | protected = INCORRECT_KEY; |
| 6420 | else if (strcasecmp(val, "Unprotected") == 0) |
| 6421 | protected = UNPROTECTED; |
| 6422 | else { |
| 6423 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported " |
| 6424 | "PMFProtected"); |
| 6425 | return 0; |
| 6426 | } |
| 6427 | |
| 6428 | val = get_param(cmd, "stationID"); |
| 6429 | if (val == NULL) |
| 6430 | return -1; |
| 6431 | |
| 6432 | if (protected == INCORRECT_KEY || |
| 6433 | (protected == UNPROTECTED && frame == SAQUERY)) |
| 6434 | return ap_inject_frame(dut, conn, frame, protected, val); |
| 6435 | |
| 6436 | switch (frame) { |
| 6437 | case DISASSOC: |
| 6438 | snprintf(buf, sizeof(buf), "disassoc %s test=%d", |
| 6439 | val, protected == CORRECT_KEY); |
| 6440 | break; |
| 6441 | case DEAUTH: |
| 6442 | snprintf(buf, sizeof(buf), "deauth %s test=%d", |
| 6443 | val, protected == CORRECT_KEY); |
| 6444 | break; |
| 6445 | case SAQUERY: |
| 6446 | snprintf(buf, sizeof(buf), "sa_query %s", val); |
| 6447 | break; |
| 6448 | } |
| 6449 | |
| 6450 | if (run_hostapd_cli(dut, buf) != 0) |
| 6451 | return -2; |
| 6452 | |
| 6453 | return 1; |
| 6454 | } |
| 6455 | |
| 6456 | |
| 6457 | static int cmd_ap_get_mac_address(struct sigma_dut *dut, |
| 6458 | struct sigma_conn *conn, |
| 6459 | struct sigma_cmd *cmd) |
| 6460 | { |
| 6461 | #if defined( __linux__) |
| 6462 | /* const char *name = get_param(cmd, "NAME"); */ |
| 6463 | /* const char *ifname = get_param(cmd, "INTERFACE"); */ |
| 6464 | char resp[50]; |
| 6465 | unsigned char addr[6]; |
| 6466 | char *ifname; |
| 6467 | struct ifreq ifr; |
| 6468 | int s; |
| 6469 | enum driver_type drv; |
| 6470 | |
| 6471 | drv = get_driver_type(); |
| 6472 | |
| 6473 | if (drv == DRIVER_ATHEROS) { |
| 6474 | if ((dut->ap_mode == AP_11a || dut->ap_mode == AP_11na || |
| 6475 | dut->ap_mode == AP_11ac) && |
| 6476 | if_nametoindex("ath1") > 0) |
| 6477 | ifname = "ath1"; |
| 6478 | else |
| 6479 | ifname = "ath0"; |
| 6480 | } else if (drv == DRIVER_OPENWRT) { |
| 6481 | if (sigma_radio_ifname[0] && |
| 6482 | strcmp(sigma_radio_ifname[0], "wifi2") == 0) |
| 6483 | ifname = "ath2"; |
| 6484 | else if (sigma_radio_ifname[0] && |
| 6485 | strcmp(sigma_radio_ifname[0], "wifi1") == 0) |
| 6486 | ifname = "ath1"; |
| 6487 | else |
| 6488 | ifname = "ath0"; |
| 6489 | } else { |
| 6490 | if ((dut->ap_mode == AP_11a || dut->ap_mode == AP_11na || |
| 6491 | dut->ap_mode == AP_11ac) && |
| 6492 | if_nametoindex("wlan1") > 0) |
| 6493 | ifname = "wlan1"; |
| 6494 | else |
| 6495 | ifname = "wlan0"; |
| 6496 | } |
| 6497 | |
| 6498 | s = socket(AF_INET, SOCK_DGRAM, 0); |
| 6499 | if (s < 0) |
| 6500 | return -1; |
| 6501 | memset(&ifr, 0, sizeof(ifr)); |
| 6502 | strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); |
| 6503 | if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) { |
| 6504 | perror("ioctl"); |
| 6505 | close(s); |
| 6506 | return -1; |
| 6507 | } |
| 6508 | close(s); |
| 6509 | memcpy(addr, ifr.ifr_hwaddr.sa_data, 6); |
| 6510 | |
| 6511 | snprintf(resp, sizeof(resp), "mac,%02x:%02x:%02x:%02x:%02x:%02x", |
| 6512 | addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]); |
| 6513 | send_resp(dut, conn, SIGMA_COMPLETE, resp); |
| 6514 | return 0; |
| 6515 | #elif defined( __QNXNTO__) |
| 6516 | char resp[50]; |
| 6517 | unsigned char addr[6]; |
| 6518 | |
| 6519 | if (!sigma_main_ifname) { |
| 6520 | send_resp(dut, conn, SIGMA_ERROR, "ifname is null"); |
| 6521 | return 0; |
| 6522 | } |
| 6523 | |
| 6524 | if (get_hwaddr(sigma_main_ifname, addr) != 0) { |
| 6525 | send_resp(dut, conn, SIGMA_ERROR, |
| 6526 | "errorCode,Failed to get address"); |
| 6527 | return 0; |
| 6528 | } |
| 6529 | snprintf(resp, sizeof(resp), "mac,%02x:%02x:%02x:%02x:%02x:%02x", |
| 6530 | addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]); |
| 6531 | send_resp(dut, conn, SIGMA_COMPLETE, resp); |
| 6532 | return 0; |
| 6533 | #else /* __linux__ */ |
| 6534 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,ap_get_mac_address not " |
| 6535 | "yet supported"); |
| 6536 | return 0; |
| 6537 | #endif /* __linux__ */ |
| 6538 | } |
| 6539 | |
| 6540 | |
| 6541 | static int cmd_ap_set_pmf(struct sigma_dut *dut, struct sigma_conn *conn, |
| 6542 | struct sigma_cmd *cmd) |
| 6543 | { |
| 6544 | /* |
| 6545 | * Ignore the command since the parameters are already handled through |
| 6546 | * ap_set_security. |
| 6547 | */ |
| 6548 | |
| 6549 | return 1; |
| 6550 | } |
| 6551 | |
| 6552 | |
| 6553 | static int cmd_ap_set_hs2(struct sigma_dut *dut, struct sigma_conn *conn, |
| 6554 | struct sigma_cmd *cmd) |
| 6555 | { |
| 6556 | /* const char *name = get_param(cmd, "NAME"); */ |
| 6557 | /* const char *ifname = get_param(cmd, "INTERFACE"); */ |
| 6558 | const char *val, *dest; |
| 6559 | char *pos, buf[100]; |
| 6560 | int i, wlan_tag = 1; |
| 6561 | |
| 6562 | sigma_dut_print(dut, DUT_MSG_INFO, "ap_set_hs2: Processing the " |
| 6563 | "following parameters"); |
| 6564 | for (i = 0; i < cmd->count; i++) { |
| 6565 | sigma_dut_print(dut, DUT_MSG_INFO, "%s %s", cmd->params[i], |
| 6566 | (cmd->values[i] ? cmd->values[i] : "NULL")); |
| 6567 | } |
| 6568 | |
| 6569 | val = get_param(cmd, "ICMPv4_ECHO"); |
| 6570 | if (val && atoi(val)) { |
| 6571 | snprintf(buf, sizeof(buf), "ebtables -F"); |
| 6572 | if (system(buf) != 0) { |
| 6573 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6574 | "Failed to set ebtables rules, RULE-12"); |
| 6575 | } |
| 6576 | return 1; |
| 6577 | } |
| 6578 | |
| 6579 | val = get_param(cmd, "WLAN_TAG"); |
| 6580 | if (val) { |
| 6581 | wlan_tag = atoi(val); |
| 6582 | if (wlan_tag != 1 && wlan_tag != 2) { |
| 6583 | send_resp(dut, conn, SIGMA_INVALID, |
| 6584 | "errorCode,Invalid WLAN_TAG"); |
| 6585 | return 0; |
| 6586 | } |
| 6587 | } |
| 6588 | |
| 6589 | if (wlan_tag == 2) { |
| 6590 | val = get_param(cmd, "PROXY_ARP"); |
| 6591 | if (val) |
| 6592 | dut->ap2_proxy_arp = atoi(val); |
| 6593 | return 1; |
| 6594 | } |
| 6595 | |
| 6596 | dest = get_param(cmd, "STA_MAC"); |
| 6597 | if (dest) { |
| 6598 | /* This is a special/ugly way of using this command. |
| 6599 | * If "Dest" MAC is included, assume that this command |
| 6600 | * is being issued after ap_config_commit for dynamically |
| 6601 | * setting the QoS Map Set. |
| 6602 | */ |
| 6603 | val = get_param(cmd, "QoS_MAP_SET"); |
| 6604 | if (val) { |
| 6605 | dut->ap_qos_map_set = atoi(val); |
| 6606 | sigma_dut_print(dut, DUT_MSG_INFO, "ap_qos_map_set %d", |
| 6607 | dut->ap_qos_map_set); |
| 6608 | } |
| 6609 | |
| 6610 | if (dut->ap_qos_map_set == 1) |
| 6611 | run_hostapd_cli(dut, "set_qos_map_set " QOS_MAP_SET_1); |
| 6612 | else if (dut->ap_qos_map_set == 2) |
| 6613 | run_hostapd_cli(dut, "set_qos_map_set " QOS_MAP_SET_2); |
| 6614 | |
| 6615 | snprintf(buf, sizeof(buf), "send_qos_map_conf %s", dest); |
| 6616 | if (run_hostapd_cli(dut, buf) != 0) |
| 6617 | return -1; |
| 6618 | } |
| 6619 | |
| 6620 | val = get_param(cmd, "DGAF_DISABLE"); |
| 6621 | if (val) |
| 6622 | dut->ap_dgaf_disable = atoi(val); |
| 6623 | |
| 6624 | dut->ap_interworking = 1; |
| 6625 | |
| 6626 | val = get_param(cmd, "INTERWORKING"); |
| 6627 | if (val == NULL) |
| 6628 | val = get_param(cmd, "INTERNETWORKING"); |
| 6629 | if (val != NULL && atoi(val) == 0) { |
| 6630 | dut->ap_interworking = 0; |
| 6631 | dut->ap_hs2 = 0; |
| 6632 | return 1; |
| 6633 | } |
| 6634 | |
| 6635 | val = get_param(cmd, "ACCS_NET_TYPE"); |
| 6636 | if (val) { |
| 6637 | if (strcasecmp(val, "Chargeable_Public_Network") == 0 || |
| 6638 | strcasecmp(val, "Chargable_Public_Network") == 0 || |
| 6639 | strcasecmp(val, "Chargable Public Network") == 0) |
| 6640 | dut->ap_access_net_type = 2; |
| 6641 | else |
| 6642 | dut->ap_access_net_type = atoi(val); |
| 6643 | } |
| 6644 | |
| 6645 | val = get_param(cmd, "INTERNET"); |
| 6646 | if (val) |
| 6647 | dut->ap_internet = atoi(val); |
| 6648 | |
| 6649 | val = get_param(cmd, "VENUE_GRP"); |
| 6650 | if (val) { |
| 6651 | if (strcasecmp(val, "Business") == 0) |
| 6652 | dut->ap_venue_group = 2; |
| 6653 | else |
| 6654 | dut->ap_venue_group = atoi(val); |
| 6655 | sigma_dut_print(dut, DUT_MSG_INFO, "ap_venue_name %d", |
| 6656 | dut->ap_venue_name); |
| 6657 | } |
| 6658 | |
| 6659 | val = get_param(cmd, "VENUE_TYPE"); |
| 6660 | if (val) { |
| 6661 | if (strcasecmp(val, "R&D") == 0) |
| 6662 | dut->ap_venue_type = 8; |
| 6663 | else |
| 6664 | dut->ap_venue_type = atoi(val); |
| 6665 | sigma_dut_print(dut, DUT_MSG_INFO, "ap_venue_type %d", |
| 6666 | dut->ap_venue_type); |
| 6667 | } |
| 6668 | |
| 6669 | val = get_param(cmd, "HESSID"); |
| 6670 | if (val) { |
| 6671 | if (strlen(val) >= sizeof(dut->ap_hessid)) { |
| 6672 | send_resp(dut, conn, SIGMA_ERROR, |
| 6673 | "errorCode,Invalid HESSID"); |
| 6674 | return 0; |
| 6675 | } |
| 6676 | snprintf(dut->ap_hessid, sizeof(dut->ap_hessid), "%s", val); |
| 6677 | sigma_dut_print(dut, DUT_MSG_INFO, "ap_hessid %s", |
| 6678 | dut->ap_hessid); |
| 6679 | } |
| 6680 | |
| 6681 | val = get_param(cmd, "ROAMING_CONS"); |
| 6682 | if (val) { |
| 6683 | if (strlen(val) >= sizeof(dut->ap_roaming_cons)) { |
| 6684 | send_resp(dut, conn, SIGMA_ERROR, |
| 6685 | "errorCode,Invalid ROAMING_CONS"); |
| 6686 | return 0; |
| 6687 | } |
| 6688 | if (strcasecmp(val, "Disabled") == 0) { |
| 6689 | dut->ap_roaming_cons[0] = '\0'; |
| 6690 | } else { |
| 6691 | snprintf(dut->ap_roaming_cons, |
| 6692 | sizeof(dut->ap_roaming_cons), "%s", val); |
| 6693 | } |
| 6694 | sigma_dut_print(dut, DUT_MSG_INFO, "ap_roaming_cons %s", |
| 6695 | dut->ap_roaming_cons); |
| 6696 | } |
| 6697 | |
| 6698 | val = get_param(cmd, "ANQP"); |
| 6699 | if (val) |
| 6700 | dut->ap_anqpserver_on = atoi(val); |
| 6701 | |
| 6702 | val = get_param(cmd, "NAI_REALM_LIST"); |
| 6703 | if (val) { |
| 6704 | dut->ap_nai_realm_list = atoi(val); |
| 6705 | sigma_dut_print(dut, DUT_MSG_INFO, "ap_nai_realm_list %d", |
| 6706 | dut->ap_nai_realm_list); |
| 6707 | } |
| 6708 | |
| 6709 | val = get_param(cmd, "3GPP_INFO"); |
| 6710 | if (val) { |
| 6711 | /* What kind of encoding format is used?! */ |
| 6712 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,3GPP_INFO " |
| 6713 | "not yet supported (contents not fully defined)"); |
| 6714 | return 0; |
| 6715 | } |
| 6716 | |
| 6717 | val = get_param(cmd, "DOMAIN_LIST"); |
| 6718 | if (val) { |
| 6719 | if (strlen(val) >= sizeof(dut->ap_domain_name_list)) { |
| 6720 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Too long " |
| 6721 | "DOMAIN_LIST"); |
| 6722 | return 0; |
| 6723 | } |
| 6724 | snprintf(dut->ap_domain_name_list, |
| 6725 | sizeof(dut->ap_domain_name_list), "%s", val); |
| 6726 | pos = dut->ap_domain_name_list; |
| 6727 | while (*pos) { |
| 6728 | if (*pos == ';') |
| 6729 | *pos = ','; |
| 6730 | pos++; |
| 6731 | } |
| 6732 | sigma_dut_print(dut, DUT_MSG_INFO, "ap_domain_name_list %s", |
| 6733 | dut->ap_domain_name_list); |
| 6734 | } |
| 6735 | |
| 6736 | val = get_param(cmd, "OPER_NAME"); |
| 6737 | if (val) { |
| 6738 | dut->ap_oper_name = atoi(val); |
| 6739 | sigma_dut_print(dut, DUT_MSG_INFO, "ap_oper_name %d", |
| 6740 | dut->ap_oper_name); |
| 6741 | } |
| 6742 | |
| 6743 | val = get_param(cmd, "VENUE_NAME"); |
| 6744 | if (val) { |
| 6745 | dut->ap_venue_name = atoi(val); |
| 6746 | sigma_dut_print(dut, DUT_MSG_INFO, "ap_venue_name %d", |
| 6747 | dut->ap_venue_name); |
| 6748 | } |
| 6749 | |
| 6750 | val = get_param(cmd, "GAS_CB_DELAY"); |
| 6751 | if (val) { |
| 6752 | dut->ap_gas_cb_delay = atoi(val); |
| 6753 | sigma_dut_print(dut, DUT_MSG_INFO, "ap_gas_cb_delay %d", |
| 6754 | dut->ap_gas_cb_delay); |
| 6755 | } |
| 6756 | |
| 6757 | val = get_param(cmd, "MIH"); |
| 6758 | if (val && atoi(val) > 0) { |
| 6759 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,MIH not " |
| 6760 | "supported"); |
| 6761 | return 0; |
| 6762 | } |
| 6763 | |
| 6764 | val = get_param(cmd, "L2_TRAFFIC_INSPECT"); |
| 6765 | if (val) { |
| 6766 | dut->ap_l2tif = atoi(val); |
| 6767 | sigma_dut_print(dut, DUT_MSG_INFO, "ap_l2tif %d", |
| 6768 | dut->ap_l2tif); |
| 6769 | } |
| 6770 | |
| 6771 | val = get_param(cmd, "BCST_UNCST"); |
| 6772 | if (val) { |
| 6773 | send_resp(dut, conn, SIGMA_ERROR, |
| 6774 | "errorCode,BCST_UNCST not yet supported"); |
| 6775 | return 0; |
| 6776 | } |
| 6777 | |
| 6778 | val = get_param(cmd, "PLMN_MCC"); |
| 6779 | if (val) { |
| 6780 | char mcc[100], *start, *end; |
| 6781 | int i = 0; |
| 6782 | if (strlen(val) >= sizeof(mcc)) { |
| 6783 | send_resp(dut, conn, SIGMA_ERROR, |
| 6784 | "errorCode,PLMN_MCC too long"); |
| 6785 | return 0; |
| 6786 | } |
| 6787 | strncpy(mcc, val, sizeof(mcc)); |
| 6788 | start = mcc; |
| 6789 | while ((end = strchr(start, ';'))) { |
| 6790 | /* process all except the last */ |
| 6791 | *end = '\0'; |
| 6792 | if (strlen(start) != 3) { |
| 6793 | send_resp(dut, conn, SIGMA_ERROR, |
| 6794 | "errorCode,Invalid PLMN_MCC"); |
| 6795 | return 0; |
| 6796 | } |
| 6797 | snprintf(dut->ap_plmn_mcc[i], |
| 6798 | sizeof(dut->ap_plmn_mcc[i]), "%s", start); |
| 6799 | sigma_dut_print(dut, DUT_MSG_INFO, "ap_plmn_mcc %s", |
| 6800 | dut->ap_plmn_mcc[i]); |
| 6801 | i++; |
| 6802 | start = end + 1; |
| 6803 | *end = ';'; |
| 6804 | } |
| 6805 | if (strlen(start) != 3) { |
| 6806 | send_resp(dut, conn, SIGMA_ERROR, |
| 6807 | "errorCode,Invalid PLMN_MCC"); |
| 6808 | return 0; |
| 6809 | } |
| 6810 | /* process last or only one */ |
| 6811 | snprintf(dut->ap_plmn_mcc[i], |
| 6812 | sizeof(dut->ap_plmn_mcc[i]), "%s", start); |
| 6813 | sigma_dut_print(dut, DUT_MSG_INFO, "ap_plmn_mcc %s", |
| 6814 | dut->ap_plmn_mcc[i]); |
| 6815 | } |
| 6816 | |
| 6817 | val = get_param(cmd, "PLMN_MNC"); |
| 6818 | if (val) { |
| 6819 | char mnc[100], *start, *end; |
| 6820 | int i = 0; |
| 6821 | if (strlen(val) >= sizeof(mnc)) { |
| 6822 | send_resp(dut, conn, SIGMA_ERROR, |
| 6823 | "errorCode,PLMN_MNC too long"); |
| 6824 | return 0; |
| 6825 | } |
| 6826 | strncpy(mnc, val, sizeof(mnc)); |
| 6827 | start = mnc; |
| 6828 | while ((end = strchr(start, ';'))) { |
| 6829 | *end = '\0'; |
| 6830 | if (strlen(start) != 2 && strlen(start) != 3) { |
| 6831 | send_resp(dut, conn, SIGMA_ERROR, |
| 6832 | "errorCode,Invalid PLMN_MNC"); |
| 6833 | return 0; |
| 6834 | } |
| 6835 | snprintf(dut->ap_plmn_mnc[i], |
| 6836 | sizeof(dut->ap_plmn_mnc[i]), "%s", start); |
| 6837 | sigma_dut_print(dut, DUT_MSG_INFO, "ap_plmn_mnc %s", |
| 6838 | dut->ap_plmn_mnc[i]); |
| 6839 | i++; |
| 6840 | start = end + 1; |
| 6841 | *end = ';'; |
| 6842 | } |
| 6843 | if (strlen(start) != 2 && strlen(start) != 3) { |
| 6844 | send_resp(dut, conn, SIGMA_ERROR, |
| 6845 | "errorCode,Invalid PLMN_MNC"); |
| 6846 | return 0; |
| 6847 | } |
| 6848 | snprintf(dut->ap_plmn_mnc[i], |
| 6849 | sizeof(dut->ap_plmn_mnc[i]), "%s", start); |
| 6850 | sigma_dut_print(dut, DUT_MSG_INFO, "ap_plmn_mnc %s", |
| 6851 | dut->ap_plmn_mnc[i]); |
| 6852 | } |
| 6853 | |
| 6854 | val = get_param(cmd, "PROXY_ARP"); |
| 6855 | if (val) { |
| 6856 | dut->ap_proxy_arp = atoi(val); |
| 6857 | sigma_dut_print(dut, DUT_MSG_INFO, "ap_proxy_arp %d", |
| 6858 | dut->ap_proxy_arp); |
| 6859 | } |
| 6860 | |
| 6861 | val = get_param(cmd, "WAN_METRICS"); |
| 6862 | if (val) { |
| 6863 | dut->ap_wan_metrics = atoi(val); |
| 6864 | sigma_dut_print(dut, DUT_MSG_INFO, "ap_wan_metrics %d", |
| 6865 | dut->ap_wan_metrics); |
| 6866 | } |
| 6867 | |
| 6868 | val = get_param(cmd, "CONN_CAP"); |
| 6869 | if (val) { |
| 6870 | dut->ap_conn_capab = atoi(val); |
| 6871 | sigma_dut_print(dut, DUT_MSG_INFO, "ap_conn_capab %d", |
| 6872 | dut->ap_conn_capab); |
| 6873 | } |
| 6874 | |
| 6875 | val = get_param(cmd, "IP_ADD_TYPE_AVAIL"); |
| 6876 | if (val) { |
| 6877 | dut->ap_ip_addr_type_avail = atoi(val); |
| 6878 | sigma_dut_print(dut, DUT_MSG_INFO, "ap_ip_addr_type_avail %d", |
| 6879 | dut->ap_ip_addr_type_avail); |
| 6880 | } |
| 6881 | |
| 6882 | val = get_param(cmd, "NET_AUTH_TYPE"); |
| 6883 | if (val) { |
| 6884 | dut->ap_net_auth_type = atoi(val); |
| 6885 | sigma_dut_print(dut, DUT_MSG_INFO, "ap_net_auth_type %d", |
| 6886 | dut->ap_net_auth_type); |
| 6887 | } |
| 6888 | |
| 6889 | val = get_param(cmd, "OP_CLASS"); |
| 6890 | if (val == NULL) |
| 6891 | val = get_param(cmd, "OPER_CLASS"); |
| 6892 | if (val) { |
| 6893 | dut->ap_oper_class = atoi(val); |
| 6894 | sigma_dut_print(dut, DUT_MSG_INFO, "ap_oper_class %d", |
| 6895 | dut->ap_oper_class); |
| 6896 | } |
| 6897 | |
| 6898 | val = get_param(cmd, "OSU_PROVIDER_LIST"); |
| 6899 | if (val) { |
| 6900 | dut->ap_osu_provider_list = atoi(val); |
| 6901 | sigma_dut_print(dut, DUT_MSG_INFO, "ap_osu_provider_list %d", |
| 6902 | dut->ap_osu_provider_list); |
| 6903 | } |
| 6904 | |
| 6905 | val = get_param(cmd, "OSU_SERVER_URI"); |
| 6906 | if (val) { |
| 6907 | i = 0; |
| 6908 | do { |
| 6909 | int len; |
| 6910 | const char *uri = val; |
| 6911 | val = strchr(val, ' '); |
| 6912 | len = val ? (val++ - uri) : (int) strlen(uri); |
| 6913 | if (len > 0 && len < 256) { |
| 6914 | memcpy(dut->ap_osu_server_uri[i], uri, len); |
| 6915 | dut->ap_osu_server_uri[i][len] = '\0'; |
| 6916 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 6917 | "ap_osu_server_uri[%d] %s", i, |
| 6918 | dut->ap_osu_server_uri[i]); |
| 6919 | } |
| 6920 | } while (val && ++i < 10); |
| 6921 | } |
| 6922 | |
| 6923 | val = get_param(cmd, "OSU_METHOD"); |
| 6924 | if (val) { |
| 6925 | i = 0; |
| 6926 | do { |
| 6927 | int len; |
| 6928 | const char *method = val; |
| 6929 | val = strchr(val, ' '); |
| 6930 | len = val ? (val++ - method) : (int) strlen(method); |
| 6931 | if (len > 0) { |
| 6932 | if (strncasecmp(method, "SOAP", len) == 0) |
| 6933 | dut->ap_osu_method[i] = 1; |
| 6934 | else if (strncasecmp(method, "OMADM", len) == 0) |
| 6935 | dut->ap_osu_method[i] = 0; |
| 6936 | else |
| 6937 | return -2; |
| 6938 | } |
| 6939 | } while (val && ++i < 10); |
| 6940 | } |
| 6941 | |
| 6942 | val = get_param(cmd, "OSU_SSID"); |
| 6943 | if (val) { |
| 6944 | if (strlen(val) > 0 && strlen(val) <= 32) { |
| 6945 | strncpy(dut->ap_osu_ssid, val, |
| 6946 | sizeof(dut->ap_osu_ssid)); |
| 6947 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 6948 | "ap_osu_ssid %s", |
| 6949 | dut->ap_osu_ssid); |
| 6950 | } |
| 6951 | } |
| 6952 | |
| 6953 | val = get_param(cmd, "OSU_ICON_TAG"); |
| 6954 | if (val) |
| 6955 | dut->ap_osu_icon_tag = atoi(val); |
| 6956 | |
| 6957 | val = get_param(cmd, "QoS_MAP_SET"); |
| 6958 | if (val) { |
| 6959 | dut->ap_qos_map_set = atoi(val); |
| 6960 | sigma_dut_print(dut, DUT_MSG_INFO, "ap_qos_map_set %d", |
| 6961 | dut->ap_qos_map_set); |
| 6962 | } |
| 6963 | |
| 6964 | val = get_param(cmd, "BSS_LOAD"); |
| 6965 | if (val) { |
| 6966 | dut->ap_bss_load = atoi(val); |
| 6967 | sigma_dut_print(dut, DUT_MSG_INFO, "ap_bss_load %d", |
| 6968 | dut->ap_bss_load); |
| 6969 | } |
| 6970 | |
| 6971 | return 1; |
| 6972 | } |
| 6973 | |
| 6974 | |
| 6975 | void nfc_status(struct sigma_dut *dut, const char *state, const char *oper) |
| 6976 | { |
| 6977 | char buf[100]; |
| 6978 | |
| 6979 | if (!file_exists("nfc-status")) |
| 6980 | return; |
| 6981 | |
| 6982 | snprintf(buf, sizeof(buf), "./nfc-status %s %s", state, oper); |
| 6983 | run_system(dut, buf); |
| 6984 | } |
| 6985 | |
| 6986 | |
| 6987 | static int run_nfc_command(struct sigma_dut *dut, const char *cmd, |
| 6988 | const char *info) |
| 6989 | { |
| 6990 | int res; |
| 6991 | |
| 6992 | printf("\n\n\n=====[ NFC operation ]=========================\n\n"); |
| 6993 | printf("%s\n\n", info); |
| 6994 | |
| 6995 | nfc_status(dut, "START", info); |
| 6996 | res = run_system(dut, cmd); |
| 6997 | nfc_status(dut, res ? "FAIL" : "SUCCESS", info); |
| 6998 | if (res) { |
| 6999 | sigma_dut_print(dut, DUT_MSG_INFO, "Failed to run '%s': %d", |
| 7000 | cmd, res); |
| 7001 | return res; |
| 7002 | } |
| 7003 | |
| 7004 | return 0; |
| 7005 | } |
| 7006 | |
| 7007 | |
| 7008 | static int ap_nfc_write_config_token(struct sigma_dut *dut, |
| 7009 | struct sigma_conn *conn, |
| 7010 | struct sigma_cmd *cmd) |
| 7011 | { |
| 7012 | int res; |
| 7013 | char buf[300]; |
| 7014 | |
| 7015 | run_system(dut, "killall wps-ap-nfc.py"); |
| 7016 | unlink("nfc-success"); |
| 7017 | snprintf(buf, sizeof(buf), |
| 7018 | "./wps-ap-nfc.py --no-wait %s%s --success nfc-success write-config", |
| 7019 | dut->summary_log ? "--summary " : "", |
| 7020 | dut->summary_log ? dut->summary_log : ""); |
| 7021 | res = run_nfc_command(dut, buf, |
| 7022 | "Touch NFC Tag to write WPS configuration token"); |
| 7023 | if (res || !file_exists("nfc-success")) { |
| 7024 | send_resp(dut, conn, SIGMA_ERROR, |
| 7025 | "ErrorCode,Failed to write tag"); |
| 7026 | return 0; |
| 7027 | } |
| 7028 | |
| 7029 | return 1; |
| 7030 | } |
| 7031 | |
| 7032 | |
| 7033 | static int ap_nfc_wps_read_passwd(struct sigma_dut *dut, |
| 7034 | struct sigma_conn *conn, |
| 7035 | struct sigma_cmd *cmd) |
| 7036 | { |
| 7037 | int res; |
| 7038 | char buf[300]; |
| 7039 | |
| 7040 | run_system(dut, "killall wps-ap-nfc.py"); |
| 7041 | |
| 7042 | unlink("nfc-success"); |
| 7043 | snprintf(buf, sizeof(buf), |
| 7044 | "./wps-ap-nfc.py -1 --no-wait %s%s --success nfc-success", |
| 7045 | dut->summary_log ? "--summary " : "", |
| 7046 | dut->summary_log ? dut->summary_log : ""); |
| 7047 | res = run_nfc_command(dut, buf, "Touch NFC Tag to read it"); |
| 7048 | if (res || !file_exists("nfc-success")) { |
| 7049 | send_resp(dut, conn, SIGMA_ERROR, |
| 7050 | "ErrorCode,Failed to read tag"); |
| 7051 | return 0; |
| 7052 | } |
| 7053 | |
| 7054 | return 1; |
| 7055 | } |
| 7056 | |
| 7057 | |
| 7058 | static int ap_nfc_write_password_token(struct sigma_dut *dut, |
| 7059 | struct sigma_conn *conn, |
| 7060 | struct sigma_cmd *cmd) |
| 7061 | { |
| 7062 | int res; |
| 7063 | char buf[300]; |
| 7064 | |
| 7065 | run_system(dut, "killall wps-ap-nfc.py"); |
| 7066 | unlink("nfc-success"); |
| 7067 | snprintf(buf, sizeof(buf), |
| 7068 | "./wps-ap-nfc.py --no-wait %s%s --success nfc-success write-password", |
| 7069 | dut->summary_log ? "--summary " : "", |
| 7070 | dut->summary_log ? dut->summary_log : ""); |
| 7071 | res = run_nfc_command(dut, buf, |
| 7072 | "Touch NFC Tag to write WPS password token"); |
| 7073 | if (res || !file_exists("nfc-success")) { |
| 7074 | send_resp(dut, conn, SIGMA_ERROR, |
| 7075 | "ErrorCode,Failed to write tag"); |
| 7076 | return 0; |
| 7077 | } |
| 7078 | |
| 7079 | if (run_hostapd_cli(dut, "wps_nfc_token enable") != 0) { |
| 7080 | send_resp(dut, conn, SIGMA_ERROR, |
| 7081 | "ErrorCode,Failed to enable NFC password token"); |
| 7082 | return 0; |
| 7083 | } |
| 7084 | |
| 7085 | return 1; |
| 7086 | } |
| 7087 | |
| 7088 | |
| 7089 | static int ap_nfc_wps_connection_handover(struct sigma_dut *dut, |
| 7090 | struct sigma_conn *conn, |
| 7091 | struct sigma_cmd *cmd) |
| 7092 | { |
| 7093 | int res; |
| 7094 | char buf[300]; |
| 7095 | |
| 7096 | run_system(dut, "killall wps-ap-nfc.py"); |
| 7097 | unlink("nfc-success"); |
| 7098 | snprintf(buf, sizeof(buf), |
| 7099 | "./wps-ap-nfc.py -1 --no-wait %s%s --success nfc-success", |
| 7100 | dut->summary_log ? "--summary " : "", |
| 7101 | dut->summary_log ? dut->summary_log : ""); |
| 7102 | res = run_nfc_command(dut, buf, |
| 7103 | "Touch NFC Device to respond to WPS connection handover"); |
| 7104 | if (res) { |
| 7105 | send_resp(dut, conn, SIGMA_ERROR, |
| 7106 | "ErrorCode,Failed to enable NFC for connection " |
| 7107 | "handover"); |
| 7108 | return 0; |
| 7109 | } |
| 7110 | if (!file_exists("nfc-success")) { |
| 7111 | send_resp(dut, conn, SIGMA_ERROR, |
| 7112 | "ErrorCode,Failed to complete NFC connection handover"); |
| 7113 | return 0; |
| 7114 | } |
| 7115 | |
| 7116 | return 1; |
| 7117 | } |
| 7118 | |
| 7119 | |
| 7120 | static int cmd_ap_nfc_action(struct sigma_dut *dut, struct sigma_conn *conn, |
| 7121 | struct sigma_cmd *cmd) |
| 7122 | { |
| 7123 | /* const char *name = get_param(cmd, "Name"); */ |
| 7124 | /* const char *intf = get_param(cmd, "Interface"); */ |
| 7125 | const char *oper = get_param(cmd, "Operation"); |
| 7126 | |
| 7127 | if (oper == NULL) |
| 7128 | return -1; |
| 7129 | |
| 7130 | if (strcasecmp(oper, "WRITE_CONFIG") == 0) |
| 7131 | return ap_nfc_write_config_token(dut, conn, cmd); |
| 7132 | if (strcasecmp(oper, "WRITE_PASSWD") == 0) |
| 7133 | return ap_nfc_write_password_token(dut, conn, cmd); |
| 7134 | if (strcasecmp(oper, "WPS_READ_PASSWD") == 0) |
| 7135 | return ap_nfc_wps_read_passwd(dut, conn, cmd); |
| 7136 | if (strcasecmp(oper, "WPS_CONN_HNDOVR") == 0) |
| 7137 | return ap_nfc_wps_connection_handover(dut, conn, cmd); |
| 7138 | |
| 7139 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported operation"); |
| 7140 | return 0; |
| 7141 | } |
| 7142 | |
| 7143 | |
| 7144 | static int cmd_ap_wps_read_pin(struct sigma_dut *dut, struct sigma_conn *conn, |
| 7145 | struct sigma_cmd *cmd) |
| 7146 | { |
| 7147 | char *pin = "12345670"; /* TODO: use random PIN */ |
| 7148 | char resp[100]; |
| 7149 | |
| 7150 | snprintf(resp, sizeof(resp), "PIN,%s", pin); |
| 7151 | send_resp(dut, conn, SIGMA_COMPLETE, resp); |
| 7152 | |
| 7153 | return 0; |
| 7154 | } |
| 7155 | |
| 7156 | |
| 7157 | static int ath_vht_op_mode_notif(struct sigma_dut *dut, const char *ifname, |
| 7158 | const char *val) |
| 7159 | { |
| 7160 | char *token, *result; |
| 7161 | int nss = 0, chwidth = 0; |
| 7162 | char buf[100]; |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 7163 | char *saveptr; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7164 | |
| 7165 | /* |
| 7166 | * The following commands should be invoked to generate |
| 7167 | * VHT op mode notification |
| 7168 | */ |
| 7169 | |
| 7170 | /* Extract the NSS info */ |
| 7171 | token = strdup(val); |
| 7172 | if (!token) |
| 7173 | return -1; |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 7174 | result = strtok_r(token, ";", &saveptr); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7175 | if (result) { |
| 7176 | int count = atoi(result); |
| 7177 | |
| 7178 | /* We do not support NSS > 3 */ |
| 7179 | if (count < 0 || count > 3) { |
| 7180 | free(token); |
| 7181 | return -1; |
| 7182 | } |
| 7183 | |
| 7184 | /* Convert nss to chainmask */ |
| 7185 | while (count--) |
| 7186 | nss = (nss << 1) | 1; |
| 7187 | |
| 7188 | snprintf(buf, sizeof(buf), "iwpriv %s rxchainmask %d", |
| 7189 | ifname, nss); |
| 7190 | if (system(buf) != 0) { |
| 7191 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7192 | "iwpriv wifi1 rxchainmask failed!"); |
| 7193 | } |
| 7194 | } |
| 7195 | |
| 7196 | /* Extract the Channel width info */ |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 7197 | result = strtok_r(NULL, ";", &saveptr); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7198 | if (result) { |
| 7199 | switch (atoi(result)) { |
| 7200 | case 20: |
| 7201 | chwidth = 0; |
| 7202 | break; |
| 7203 | case 40: |
| 7204 | chwidth = 1; |
| 7205 | break; |
| 7206 | case 80: |
| 7207 | chwidth = 2; |
| 7208 | break; |
| 7209 | case 160: |
| 7210 | chwidth = 3; |
| 7211 | break; |
| 7212 | default: |
| 7213 | chwidth = 2; |
| 7214 | break; |
| 7215 | } |
| 7216 | snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d", |
| 7217 | ifname, chwidth); |
| 7218 | if (system(buf) != 0) { |
| 7219 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7220 | "iwpriv chwidth failed!"); |
| 7221 | } |
| 7222 | } |
| 7223 | |
| 7224 | /* Send the opmode notification */ |
| 7225 | snprintf(buf, sizeof(buf), "iwpriv %s opmode_notify 1", ifname); |
| 7226 | if (system(buf) != 0) { |
| 7227 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7228 | "iwpriv opmode_notify failed!"); |
| 7229 | } |
| 7230 | free(token); |
| 7231 | |
| 7232 | return 0; |
| 7233 | } |
| 7234 | |
| 7235 | |
| 7236 | static int ath_vht_nss_mcs(struct sigma_dut *dut, const char *ifname, |
| 7237 | const char *val) |
| 7238 | { |
| 7239 | /* String (nss_operating_mode; mcs_operating_mode) */ |
| 7240 | int nss, mcs; |
| 7241 | char *token, *result; |
| 7242 | char buf[100]; |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 7243 | char *saveptr; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7244 | |
| 7245 | token = strdup(val); |
| 7246 | if (!token) |
| 7247 | return -1; |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 7248 | result = strtok_r(token, ";", &saveptr); |
Pradeep Reddy POTTETI | 41b8c54 | 2016-06-15 16:09:46 +0530 | [diff] [blame] | 7249 | if (!result) { |
| 7250 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7251 | "VHT NSS not specified"); |
| 7252 | goto end; |
| 7253 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7254 | if (strcasecmp(result, "def") != 0) { |
| 7255 | nss = atoi(result); |
| 7256 | |
| 7257 | if (nss == 4) |
| 7258 | ath_disable_txbf(dut, ifname); |
| 7259 | |
| 7260 | snprintf(buf, sizeof(buf), "iwpriv %s nss %d", ifname, nss); |
| 7261 | if (system(buf) != 0) { |
| 7262 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7263 | "iwpriv nss failed"); |
| 7264 | } |
| 7265 | } else { |
| 7266 | if (dut->device_type == AP_testbed && dut->ap_sgi80 == 1) { |
| 7267 | snprintf(buf, sizeof(buf), "iwpriv %s nss 1", ifname); |
| 7268 | if (system(buf) != 0) { |
| 7269 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7270 | "iwpriv nss failed"); |
| 7271 | } |
| 7272 | } |
| 7273 | } |
| 7274 | |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 7275 | result = strtok_r(NULL, ";", &saveptr); |
Pradeep Reddy POTTETI | 41b8c54 | 2016-06-15 16:09:46 +0530 | [diff] [blame] | 7276 | if (!result) { |
| 7277 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7278 | "VHT MCS not specified"); |
| 7279 | goto end; |
| 7280 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7281 | if (strcasecmp(result, "def") == 0) { |
| 7282 | if (dut->device_type == AP_testbed && dut->ap_sgi80 == 1) { |
| 7283 | snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs 7", |
| 7284 | ifname); |
| 7285 | if (system(buf) != 0) { |
| 7286 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7287 | "iwpriv vhtmcs failed"); |
| 7288 | } |
| 7289 | } else { |
| 7290 | snprintf(buf, sizeof(buf), |
| 7291 | "iwpriv %s set11NRates 0", ifname); |
| 7292 | if (system(buf) != 0) { |
| 7293 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7294 | "iwpriv set11NRates failed"); |
| 7295 | } |
| 7296 | } |
| 7297 | } else { |
| 7298 | mcs = atoi(result); |
| 7299 | snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs %d", ifname, mcs); |
| 7300 | if (system(buf) != 0) { |
| 7301 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7302 | "iwpriv vhtmcs failed"); |
| 7303 | } |
| 7304 | } |
| 7305 | |
Pradeep Reddy POTTETI | 41b8c54 | 2016-06-15 16:09:46 +0530 | [diff] [blame] | 7306 | end: |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7307 | free(token); |
| 7308 | return 0; |
| 7309 | } |
| 7310 | |
| 7311 | |
| 7312 | static int ath_vht_chnum_band(struct sigma_dut *dut, const char *ifname, |
| 7313 | const char *val) |
| 7314 | { |
| 7315 | char *token, *result; |
| 7316 | int channel = 36; |
| 7317 | int chwidth = 80; |
| 7318 | char buf[100]; |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 7319 | char *saveptr; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7320 | |
| 7321 | /* Extract the channel info */ |
| 7322 | token = strdup(val); |
| 7323 | if (!token) |
| 7324 | return -1; |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 7325 | result = strtok_r(token, ";", &saveptr); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7326 | if (result) |
| 7327 | channel = atoi(result); |
| 7328 | |
| 7329 | /* Extract the channel width info */ |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 7330 | result = strtok_r(NULL, ";", &saveptr); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7331 | if (result) |
| 7332 | chwidth = atoi(result); |
| 7333 | |
| 7334 | /* Issue the channel switch command */ |
| 7335 | snprintf(buf, sizeof(buf), "iwpriv %s doth_ch_chwidth %d 10 %d", |
| 7336 | ifname, channel, chwidth); |
| 7337 | if (system(buf) != 0) { |
| 7338 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7339 | "iwpriv doth_ch_chwidth failed!"); |
| 7340 | } |
| 7341 | |
| 7342 | free(token); |
| 7343 | return 0; |
| 7344 | } |
| 7345 | |
| 7346 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7347 | static int ath_ndpa_stainfo_mac(struct sigma_dut *dut, const char *ifname, |
| 7348 | const char *val) |
| 7349 | { |
| 7350 | char buf[80]; |
| 7351 | unsigned char mac_addr[6]; |
| 7352 | |
| 7353 | if (parse_mac_address(dut, val, mac_addr) < 0) |
| 7354 | return -1; |
| 7355 | |
| 7356 | snprintf(buf, sizeof(buf), |
| 7357 | "wifitool %s beeliner_fw_test 92 0x%02x%02x%02x%02x", |
| 7358 | ifname, mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3]); |
| 7359 | run_system(dut, buf); |
| 7360 | |
| 7361 | snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 93 0x%02x%02x", |
| 7362 | ifname, mac_addr[4], mac_addr[5]); |
| 7363 | run_system(dut, buf); |
| 7364 | |
| 7365 | snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 94 1", ifname); |
| 7366 | run_system(dut, buf); |
| 7367 | |
| 7368 | return 0; |
| 7369 | } |
| 7370 | |
| 7371 | |
priyadharshini gowthaman | e5e2517 | 2015-12-08 14:53:48 -0800 | [diff] [blame] | 7372 | void novap_reset(struct sigma_dut *dut, const char *ifname) |
Priyadharshini Gowthaman | 39beafa | 2015-11-09 14:11:25 -0800 | [diff] [blame] | 7373 | { |
| 7374 | char buf[60]; |
| 7375 | |
| 7376 | snprintf(buf, sizeof(buf), "iwpriv %s novap_reset 1", ifname); |
| 7377 | if (system(buf) != 0) { |
| 7378 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7379 | "disabling novap reset failed"); |
| 7380 | } |
| 7381 | } |
| 7382 | |
| 7383 | |
priyadharshini gowthaman | b4e05fc | 2016-10-13 15:02:35 -0700 | [diff] [blame] | 7384 | static void ath_set_assoc_disallow(struct sigma_dut *dut, const char *ifname, |
| 7385 | const char *val) |
| 7386 | { |
| 7387 | char buf[80]; |
| 7388 | |
| 7389 | if (strcasecmp(val, "enable") == 0) { |
| 7390 | snprintf(buf, sizeof(buf), "iwpriv %s mbo_asoc_dis 1", ifname); |
| 7391 | if (system(buf) != 0) { |
| 7392 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7393 | "iwpriv mbo_asoc_dis enable failed"); |
| 7394 | } |
| 7395 | } else if (strcasecmp(val, "disable") == 0) { |
| 7396 | snprintf(buf, sizeof(buf), "iwpriv %s mbo_asoc_dis 0", ifname); |
| 7397 | if (system(buf) != 0) { |
| 7398 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7399 | "iwpriv mbo_asoc_dis disable failed"); |
| 7400 | } |
| 7401 | } else { |
| 7402 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7403 | "Unsupported assoc_disallow"); |
| 7404 | } |
| 7405 | } |
| 7406 | |
| 7407 | |
| 7408 | static int ath_set_nebor_bssid(struct sigma_dut *dut, const char *ifname, |
| 7409 | const char *val) |
| 7410 | { |
| 7411 | char buf[80]; |
| 7412 | unsigned char mac_addr[6]; |
| 7413 | |
| 7414 | if (parse_mac_address(dut, val, mac_addr) < 0) |
| 7415 | return -1; |
| 7416 | |
| 7417 | if (dut->ap_set_bssidpref) { |
| 7418 | snprintf(buf, sizeof(buf), |
| 7419 | "wifitool %s setbssidpref 00:00:00:00:00:00 0 00 00", |
| 7420 | ifname); |
| 7421 | if (system(buf) != 0) { |
| 7422 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7423 | "wifitool clear bssidpref failed"); |
| 7424 | } |
| 7425 | } |
| 7426 | |
| 7427 | if (dut->ap_ne_class && dut->ap_ne_op_ch) { |
| 7428 | snprintf(buf, sizeof(buf), |
| 7429 | "wifitool %s setbssidpref %02x:%02x:%02x:%02x:%02x:%02x 1 %d %d", |
| 7430 | ifname, mac_addr[0], mac_addr[1], mac_addr[2], |
| 7431 | mac_addr[3], mac_addr[4], mac_addr[5], |
| 7432 | dut->ap_ne_class, dut->ap_ne_op_ch); |
| 7433 | if (system(buf) != 0) { |
| 7434 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7435 | "wifitool setbssidpref failed"); |
| 7436 | } |
| 7437 | dut->ap_set_bssidpref = 1; |
| 7438 | } |
| 7439 | |
| 7440 | return 0; |
| 7441 | } |
| 7442 | |
| 7443 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7444 | static int ath_ap_set_rfeature(struct sigma_dut *dut, struct sigma_conn *conn, |
| 7445 | struct sigma_cmd *cmd) |
| 7446 | { |
| 7447 | const char *val; |
| 7448 | char *ifname; |
| 7449 | |
| 7450 | ifname = get_main_ifname(); |
| 7451 | |
Priyadharshini Gowthaman | 39beafa | 2015-11-09 14:11:25 -0800 | [diff] [blame] | 7452 | /* Disable vap reset between the commands */ |
| 7453 | novap_reset(dut, ifname); |
| 7454 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7455 | val = get_param(cmd, "Opt_md_notif_ie"); |
| 7456 | if (val && ath_vht_op_mode_notif(dut, ifname, val) < 0) |
| 7457 | return -1; |
| 7458 | |
| 7459 | /* TODO: Optional arguments */ |
| 7460 | |
| 7461 | val = get_param(cmd, "nss_mcs_opt"); |
| 7462 | if (val && ath_vht_nss_mcs(dut, ifname, val) < 0) |
| 7463 | return -1; |
| 7464 | |
| 7465 | val = get_param(cmd, "chnum_band"); |
| 7466 | if (val && ath_vht_chnum_band(dut, ifname, val) < 0) |
| 7467 | return -1; |
| 7468 | |
| 7469 | val = get_param(cmd, "RTS_FORCE"); |
| 7470 | if (val) |
| 7471 | ath_config_rts_force(dut, ifname, val); |
| 7472 | |
| 7473 | val = get_param(cmd, "DYN_BW_SGNL"); |
| 7474 | if (val) |
| 7475 | ath_config_dyn_bw_sig(dut, ifname, val); |
| 7476 | |
| 7477 | val = get_param(cmd, "CTS_WIDTH"); |
| 7478 | if (val) |
| 7479 | ath_set_cts_width(dut, ifname, val); |
| 7480 | |
| 7481 | val = get_param(cmd, "Ndpa_stainfo_mac"); |
| 7482 | if (val && ath_ndpa_stainfo_mac(dut, ifname, val) < 0) |
| 7483 | return -1; |
| 7484 | |
| 7485 | val = get_param(cmd, "txBandwidth"); |
| 7486 | if (val && ath_set_width(dut, conn, ifname, val) < 0) |
| 7487 | return -1; |
| 7488 | |
priyadharshini gowthaman | b4e05fc | 2016-10-13 15:02:35 -0700 | [diff] [blame] | 7489 | val = get_param(cmd, "Assoc_Disallow"); |
| 7490 | if (val) |
| 7491 | ath_set_assoc_disallow(dut, ifname, val); |
| 7492 | |
| 7493 | val = get_param(cmd, "Nebor_Op_Class"); |
| 7494 | if (val) |
| 7495 | dut->ap_ne_class = atoi(val); |
| 7496 | |
| 7497 | val = get_param(cmd, "Nebor_Op_Ch"); |
| 7498 | if (val) |
| 7499 | dut->ap_ne_op_ch = atoi(val); |
| 7500 | |
| 7501 | val = get_param(cmd, "Nebor_BSSID"); |
| 7502 | if (val && ath_set_nebor_bssid(dut, ifname, val) < 0) |
| 7503 | return -1; |
| 7504 | |
| 7505 | val = get_param(cmd, "BTMReq_DisAssoc_Imnt"); |
| 7506 | if (val) |
| 7507 | dut->ap_btmreq_disassoc_imnt = atoi(val); |
| 7508 | |
| 7509 | val = get_param(cmd, "BTMReq_Term_Bit"); |
| 7510 | if (val) |
| 7511 | dut->ap_btmreq_term_bit = atoi(val); |
| 7512 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7513 | return 1; |
| 7514 | } |
| 7515 | |
| 7516 | |
Pradeep Reddy POTTETI | 88fd82c | 2016-03-14 12:20:18 +0530 | [diff] [blame] | 7517 | static int wcn_vht_chnum_band(struct sigma_dut *dut, const char *ifname, |
| 7518 | const char *val) |
| 7519 | { |
| 7520 | char *token, *result; |
| 7521 | int channel = 36; |
| 7522 | char buf[100]; |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 7523 | char *saveptr; |
Pradeep Reddy POTTETI | 88fd82c | 2016-03-14 12:20:18 +0530 | [diff] [blame] | 7524 | |
| 7525 | /* Extract the channel info */ |
| 7526 | token = strdup(val); |
| 7527 | if (!token) |
| 7528 | return -1; |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 7529 | result = strtok_r(token, ";", &saveptr); |
Pradeep Reddy POTTETI | 88fd82c | 2016-03-14 12:20:18 +0530 | [diff] [blame] | 7530 | if (result) |
| 7531 | channel = atoi(result); |
| 7532 | |
| 7533 | /* Issue the channel switch command */ |
| 7534 | snprintf(buf, sizeof(buf), "iwpriv %s setChanChange %d", |
| 7535 | ifname, channel); |
| 7536 | if (system(buf) != 0) { |
| 7537 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7538 | "iwpriv setChanChange failed!"); |
| 7539 | } |
| 7540 | |
| 7541 | free(token); |
| 7542 | return 0; |
| 7543 | } |
| 7544 | |
| 7545 | |
| 7546 | static int wcn_ap_set_rfeature(struct sigma_dut *dut, struct sigma_conn *conn, |
| 7547 | struct sigma_cmd *cmd) |
| 7548 | { |
| 7549 | const char *val; |
| 7550 | char *ifname; |
| 7551 | |
| 7552 | ifname = get_main_ifname(); |
| 7553 | |
| 7554 | val = get_param(cmd, "chnum_band"); |
| 7555 | if (val && wcn_vht_chnum_band(dut, ifname, val) < 0) |
| 7556 | return -1; |
| 7557 | |
| 7558 | return 1; |
| 7559 | } |
| 7560 | |
| 7561 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7562 | static int cmd_ap_set_rfeature(struct sigma_dut *dut, struct sigma_conn *conn, |
| 7563 | struct sigma_cmd *cmd) |
| 7564 | { |
| 7565 | /* const char *name = get_param(cmd, "NAME"); */ |
| 7566 | /* const char *type = get_param(cmd, "Type"); */ |
| 7567 | |
| 7568 | switch (get_driver_type()) { |
| 7569 | case DRIVER_ATHEROS: |
| 7570 | return ath_ap_set_rfeature(dut, conn, cmd); |
| 7571 | case DRIVER_OPENWRT: |
| 7572 | switch (get_openwrt_driver_type()) { |
| 7573 | case OPENWRT_DRIVER_ATHEROS: |
| 7574 | return ath_ap_set_rfeature(dut, conn, cmd); |
| 7575 | default: |
| 7576 | send_resp(dut, conn, SIGMA_ERROR, |
| 7577 | "errorCode,Unsupported ap_set_rfeature with the current openwrt driver"); |
| 7578 | return 0; |
| 7579 | } |
Sreelakshmi Konamki | 0e4fcf9 | 2016-04-26 19:55:01 +0530 | [diff] [blame] | 7580 | case DRIVER_LINUX_WCN: |
Pradeep Reddy POTTETI | 88fd82c | 2016-03-14 12:20:18 +0530 | [diff] [blame] | 7581 | case DRIVER_WCN: |
| 7582 | return wcn_ap_set_rfeature(dut, conn, cmd); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7583 | default: |
| 7584 | send_resp(dut, conn, SIGMA_ERROR, |
| 7585 | "errorCode,Unsupported ap_set_rfeature with the current driver"); |
| 7586 | return 0; |
| 7587 | } |
| 7588 | } |
| 7589 | |
| 7590 | |
| 7591 | static int cmd_accesspoint(struct sigma_dut *dut, struct sigma_conn *conn, |
| 7592 | struct sigma_cmd *cmd) |
| 7593 | { |
| 7594 | /* const char *name = get_param(cmd, "NAME"); */ |
| 7595 | return 1; |
| 7596 | } |
| 7597 | |
| 7598 | |
| 7599 | void ap_register_cmds(void) |
| 7600 | { |
| 7601 | sigma_dut_reg_cmd("ap_ca_version", NULL, cmd_ap_ca_version); |
| 7602 | sigma_dut_reg_cmd("ap_set_wireless", NULL, cmd_ap_set_wireless); |
| 7603 | sigma_dut_reg_cmd("ap_send_addba_req", NULL, cmd_ap_send_addba_req); |
| 7604 | sigma_dut_reg_cmd("ap_set_11n_wireless", NULL, cmd_ap_set_wireless); |
| 7605 | sigma_dut_reg_cmd("ap_set_11n", NULL, cmd_ap_set_wireless); |
| 7606 | sigma_dut_reg_cmd("ap_set_11d", NULL, cmd_ap_set_wireless); |
Pradeep Reddy POTTETI | fba27db | 2015-11-20 16:42:22 +0530 | [diff] [blame] | 7607 | sigma_dut_reg_cmd("ap_set_11h", NULL, cmd_ap_set_wireless); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7608 | sigma_dut_reg_cmd("ap_set_security", NULL, cmd_ap_set_security); |
| 7609 | sigma_dut_reg_cmd("ap_set_apqos", NULL, cmd_ap_set_apqos); |
| 7610 | sigma_dut_reg_cmd("ap_set_staqos", NULL, cmd_ap_set_staqos); |
| 7611 | sigma_dut_reg_cmd("ap_set_radius", NULL, cmd_ap_set_radius); |
| 7612 | sigma_dut_reg_cmd("ap_reboot", NULL, cmd_ap_reboot); |
| 7613 | sigma_dut_reg_cmd("ap_config_commit", NULL, cmd_ap_config_commit); |
| 7614 | sigma_dut_reg_cmd("ap_reset_default", NULL, cmd_ap_reset_default); |
| 7615 | sigma_dut_reg_cmd("ap_get_info", NULL, cmd_ap_get_info); |
| 7616 | sigma_dut_reg_cmd("ap_deauth_sta", NULL, cmd_ap_deauth_sta); |
| 7617 | sigma_dut_reg_cmd("ap_send_frame", NULL, cmd_ap_send_frame); |
| 7618 | sigma_dut_reg_cmd("ap_get_mac_address", NULL, cmd_ap_get_mac_address); |
| 7619 | sigma_dut_reg_cmd("ap_set_pmf", NULL, cmd_ap_set_pmf); |
| 7620 | sigma_dut_reg_cmd("ap_set_hs2", NULL, cmd_ap_set_hs2); |
| 7621 | sigma_dut_reg_cmd("ap_set_rfeature", NULL, cmd_ap_set_rfeature); |
| 7622 | sigma_dut_reg_cmd("ap_nfc_action", NULL, cmd_ap_nfc_action); |
| 7623 | sigma_dut_reg_cmd("ap_wps_read_pin", NULL, cmd_ap_wps_read_pin); |
| 7624 | sigma_dut_reg_cmd("AccessPoint", NULL, cmd_accesspoint); |
| 7625 | } |