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/ioctl.h> |
| 11 | #include <sys/stat.h> |
| 12 | #ifdef __linux__ |
Lior David | cc88b56 | 2017-01-03 18:52:09 +0200 | [diff] [blame] | 13 | #include <regex.h> |
| 14 | #include <dirent.h> |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 15 | #include <sys/time.h> |
| 16 | #include <netpacket/packet.h> |
| 17 | #include <linux/if_ether.h> |
| 18 | #ifdef ANDROID |
| 19 | #include <cutils/properties.h> |
| 20 | #include <android/log.h> |
| 21 | #include "keystore_get.h" |
| 22 | #else /* ANDROID */ |
| 23 | #include <ifaddrs.h> |
| 24 | #endif /* ANDROID */ |
| 25 | #include <netdb.h> |
| 26 | #endif /* __linux__ */ |
| 27 | #ifdef __QNXNTO__ |
| 28 | #include <net/if_dl.h> |
| 29 | #endif /* __QNXNTO__ */ |
| 30 | #include "wpa_ctrl.h" |
| 31 | #include "wpa_helpers.h" |
Amarnath Hullur Subramanyam | 9c381f5 | 2017-03-17 00:04:41 -0700 | [diff] [blame] | 32 | #include "miracast.h" |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 33 | |
| 34 | /* Temporary files for sta_send_addba */ |
| 35 | #define VI_QOS_TMP_FILE "/tmp/vi-qos.tmp" |
| 36 | #define VI_QOS_FILE "/tmp/vi-qos.txt" |
| 37 | #define VI_QOS_REFFILE "/etc/vi-qos.txt" |
| 38 | |
| 39 | /* |
| 40 | * MTU for Ethernet need to take into account 8-byte SNAP header |
| 41 | * to be added when encapsulating Ethernet frame into 802.11 |
| 42 | */ |
| 43 | #ifndef IEEE80211_MAX_DATA_LEN_DMG |
| 44 | #define IEEE80211_MAX_DATA_LEN_DMG 7920 |
| 45 | #endif |
| 46 | #ifndef IEEE80211_SNAP_LEN_DMG |
| 47 | #define IEEE80211_SNAP_LEN_DMG 8 |
| 48 | #endif |
| 49 | |
Ashwini Patil | 0040258 | 2017-04-13 12:29:39 +0530 | [diff] [blame] | 50 | #define NON_PREF_CH_LIST_SIZE 100 |
Ashwini Patil | 5acd738 | 2017-04-13 15:55:04 +0530 | [diff] [blame] | 51 | #define NEIGHBOR_REPORT_SIZE 1000 |
| 52 | #define DEFAULT_NEIGHBOR_BSSID_INFO "17" |
| 53 | #define DEFAULT_NEIGHBOR_PHY_TYPE "1" |
Ashwini Patil | 0040258 | 2017-04-13 12:29:39 +0530 | [diff] [blame] | 54 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 55 | extern char *sigma_wpas_ctrl; |
| 56 | extern char *sigma_cert_path; |
| 57 | extern enum driver_type wifi_chip_type; |
| 58 | extern char *sigma_radio_ifname[]; |
| 59 | |
Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 60 | #ifdef __linux__ |
| 61 | #define WIL_WMI_MAX_PAYLOAD 248 |
| 62 | #define WIL_WMI_BF_TRIG_CMDID 0x83a |
| 63 | |
| 64 | struct wil_wmi_header { |
| 65 | uint8_t mid; |
| 66 | uint8_t reserved; |
| 67 | uint16_t cmd; |
| 68 | uint32_t ts; |
| 69 | } __attribute__((packed)); |
| 70 | |
| 71 | enum wil_wmi_bf_trig_type { |
| 72 | WIL_WMI_SLS, |
| 73 | WIL_WMI_BRP_RX, |
| 74 | WIL_WMI_BRP_TX, |
| 75 | }; |
| 76 | |
| 77 | struct wil_wmi_bf_trig_cmd { |
| 78 | /* enum wil_wmi_bf_trig_type */ |
| 79 | uint32_t bf_type; |
| 80 | /* cid when type == WMI_BRP_RX */ |
| 81 | uint32_t sta_id; |
| 82 | uint32_t reserved; |
| 83 | /* mac address when type = WIL_WMI_SLS */ |
| 84 | uint8_t dest_mac[6]; |
| 85 | } __attribute__((packed)); |
| 86 | #endif /* __linux__ */ |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 87 | |
| 88 | #ifdef ANDROID |
| 89 | |
| 90 | static int add_ipv6_rule(struct sigma_dut *dut, const char *ifname); |
| 91 | |
| 92 | #define ANDROID_KEYSTORE_GET 'g' |
| 93 | #define ANDROID_KEYSTORE_GET_PUBKEY 'b' |
| 94 | |
| 95 | static int android_keystore_get(char cmd, const char *key, unsigned char *val) |
| 96 | { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 97 | /* Android 4.3 changed keystore design, so need to use keystore_get() */ |
| 98 | #ifndef KEYSTORE_MESSAGE_SIZE |
| 99 | #define KEYSTORE_MESSAGE_SIZE 65535 |
| 100 | #endif /* KEYSTORE_MESSAGE_SIZE */ |
| 101 | |
| 102 | ssize_t len; |
| 103 | uint8_t *value = NULL; |
| 104 | |
| 105 | __android_log_print(ANDROID_LOG_DEBUG, "sigma_dut", |
| 106 | "keystore command '%c' key '%s' --> keystore_get", |
| 107 | cmd, key); |
| 108 | |
| 109 | len = keystore_get(key, strlen(key), &value); |
| 110 | if (len < 0) { |
| 111 | __android_log_print(ANDROID_LOG_DEBUG, "sigma_dut", |
| 112 | "keystore_get() failed"); |
| 113 | return -1; |
| 114 | } |
| 115 | |
| 116 | if (len > KEYSTORE_MESSAGE_SIZE) |
| 117 | len = KEYSTORE_MESSAGE_SIZE; |
| 118 | memcpy(val, value, len); |
| 119 | free(value); |
| 120 | return len; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 121 | } |
| 122 | #endif /* ANDROID */ |
| 123 | |
| 124 | |
| 125 | int set_ps(const char *intf, struct sigma_dut *dut, int enabled) |
| 126 | { |
| 127 | #ifdef __linux__ |
| 128 | char buf[100]; |
| 129 | |
| 130 | if (wifi_chip_type == DRIVER_WCN) { |
| 131 | if (enabled) { |
| 132 | snprintf(buf, sizeof(buf), "iwpriv wlan0 dump 906"); |
Pradeep Reddy POTTETI | 625b370 | 2016-09-20 17:09:58 +0530 | [diff] [blame] | 133 | if (system(buf) != 0) |
| 134 | goto set_power_save; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 135 | } else { |
| 136 | snprintf(buf, sizeof(buf), "iwpriv wlan0 dump 905"); |
Pradeep Reddy POTTETI | 625b370 | 2016-09-20 17:09:58 +0530 | [diff] [blame] | 137 | if (system(buf) != 0) |
| 138 | goto set_power_save; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 139 | snprintf(buf, sizeof(buf), "iwpriv wlan0 dump 912"); |
Pradeep Reddy POTTETI | 625b370 | 2016-09-20 17:09:58 +0530 | [diff] [blame] | 140 | if (system(buf) != 0) |
| 141 | goto set_power_save; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | return 0; |
| 145 | } |
| 146 | |
Pradeep Reddy POTTETI | 625b370 | 2016-09-20 17:09:58 +0530 | [diff] [blame] | 147 | set_power_save: |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 148 | snprintf(buf, sizeof(buf), "./iw dev %s set power_save %s", |
| 149 | intf, enabled ? "on" : "off"); |
| 150 | if (system(buf) != 0) { |
| 151 | snprintf(buf, sizeof(buf), "iw dev %s set power_save %s", |
| 152 | intf, enabled ? "on" : "off"); |
Pradeep Reddy POTTETI | 625b370 | 2016-09-20 17:09:58 +0530 | [diff] [blame] | 153 | if (system(buf) != 0) { |
| 154 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 155 | "Failed to set power save %s", |
| 156 | enabled ? "on" : "off"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 157 | return -1; |
Pradeep Reddy POTTETI | 625b370 | 2016-09-20 17:09:58 +0530 | [diff] [blame] | 158 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | return 0; |
| 162 | #else /* __linux__ */ |
| 163 | return -1; |
| 164 | #endif /* __linux__ */ |
| 165 | } |
| 166 | |
| 167 | |
Lior David | cc88b56 | 2017-01-03 18:52:09 +0200 | [diff] [blame] | 168 | #ifdef __linux__ |
Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 169 | |
Lior David | cc88b56 | 2017-01-03 18:52:09 +0200 | [diff] [blame] | 170 | static int wil6210_get_debugfs_dir(struct sigma_dut *dut, char *path, |
| 171 | size_t len) |
| 172 | { |
| 173 | DIR *dir, *wil_dir; |
| 174 | struct dirent *entry; |
| 175 | int ret = -1; |
| 176 | const char *root_path = "/sys/kernel/debug/ieee80211"; |
| 177 | |
| 178 | dir = opendir(root_path); |
| 179 | if (!dir) |
| 180 | return -2; |
| 181 | |
| 182 | while ((entry = readdir(dir))) { |
| 183 | if (strcmp(entry->d_name, ".") == 0 || |
| 184 | strcmp(entry->d_name, "..") == 0) |
| 185 | continue; |
| 186 | |
| 187 | if (snprintf(path, len, "%s/%s/wil6210", |
| 188 | root_path, entry->d_name) >= (int) len) { |
| 189 | ret = -3; |
| 190 | break; |
| 191 | } |
| 192 | |
| 193 | wil_dir = opendir(path); |
| 194 | if (wil_dir) { |
| 195 | closedir(wil_dir); |
| 196 | ret = 0; |
| 197 | break; |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | closedir(dir); |
| 202 | return ret; |
| 203 | } |
Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 204 | |
| 205 | |
| 206 | static int wil6210_wmi_send(struct sigma_dut *dut, uint16_t command, |
| 207 | void *payload, uint16_t length) |
| 208 | { |
| 209 | struct { |
| 210 | struct wil_wmi_header hdr; |
| 211 | char payload[WIL_WMI_MAX_PAYLOAD]; |
| 212 | } __attribute__((packed)) cmd; |
| 213 | char buf[128], fname[128]; |
| 214 | size_t towrite, written; |
| 215 | FILE *f; |
| 216 | |
| 217 | if (length > WIL_WMI_MAX_PAYLOAD) { |
| 218 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 219 | "payload too large(%u, max %u)", |
| 220 | length, WIL_WMI_MAX_PAYLOAD); |
| 221 | return -1; |
| 222 | } |
| 223 | |
| 224 | memset(&cmd.hdr, 0, sizeof(cmd.hdr)); |
| 225 | cmd.hdr.cmd = command; |
| 226 | memcpy(cmd.payload, payload, length); |
| 227 | |
| 228 | if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) { |
| 229 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 230 | "failed to get wil6210 debugfs dir"); |
| 231 | return -1; |
| 232 | } |
| 233 | |
| 234 | snprintf(fname, sizeof(fname), "%s/wmi_send", buf); |
| 235 | f = fopen(fname, "wb"); |
| 236 | if (!f) { |
| 237 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 238 | "failed to open: %s", fname); |
| 239 | return -1; |
| 240 | } |
| 241 | |
| 242 | towrite = sizeof(cmd.hdr) + length; |
| 243 | written = fwrite(&cmd, 1, towrite, f); |
| 244 | fclose(f); |
| 245 | if (written != towrite) { |
| 246 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 247 | "failed to send wmi %u", command); |
| 248 | return -1; |
| 249 | } |
| 250 | |
| 251 | return 0; |
| 252 | } |
| 253 | |
| 254 | |
| 255 | static int wil6210_get_sta_info_field(struct sigma_dut *dut, const char *bssid, |
| 256 | const char *pattern, unsigned int *field) |
| 257 | { |
| 258 | char buf[128], fname[128]; |
| 259 | FILE *f; |
| 260 | regex_t re; |
| 261 | regmatch_t m[2]; |
| 262 | int rc, ret = -1; |
| 263 | |
| 264 | if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) { |
| 265 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 266 | "failed to get wil6210 debugfs dir"); |
| 267 | return -1; |
| 268 | } |
| 269 | |
| 270 | snprintf(fname, sizeof(fname), "%s/stations", buf); |
| 271 | f = fopen(fname, "r"); |
| 272 | if (!f) { |
| 273 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 274 | "failed to open: %s", fname); |
| 275 | return -1; |
| 276 | } |
| 277 | |
| 278 | if (regcomp(&re, pattern, REG_EXTENDED)) { |
| 279 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 280 | "regcomp failed: %s", pattern); |
| 281 | goto out; |
| 282 | } |
| 283 | |
| 284 | /* |
| 285 | * find the entry for the mac address |
| 286 | * line is of the form: [n] 11:22:33:44:55:66 state AID aid |
| 287 | */ |
| 288 | while (fgets(buf, sizeof(buf), f)) { |
| 289 | if (strcasestr(buf, bssid)) { |
| 290 | /* extract the field (CID/AID/state) */ |
| 291 | rc = regexec(&re, buf, 2, m, 0); |
| 292 | if (!rc && (m[1].rm_so >= 0)) { |
| 293 | buf[m[1].rm_eo] = 0; |
| 294 | *field = atoi(&buf[m[1].rm_so]); |
| 295 | ret = 0; |
| 296 | break; |
| 297 | } |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | regfree(&re); |
| 302 | if (ret) |
| 303 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 304 | "could not extract field"); |
| 305 | |
| 306 | out: |
| 307 | fclose(f); |
| 308 | |
| 309 | return ret; |
| 310 | } |
| 311 | |
| 312 | |
| 313 | static int wil6210_get_cid(struct sigma_dut *dut, const char *bssid, |
| 314 | unsigned int *cid) |
| 315 | { |
| 316 | const char *pattern = "\\[([0-9]+)\\]"; |
| 317 | |
| 318 | return wil6210_get_sta_info_field(dut, bssid, pattern, cid); |
| 319 | } |
| 320 | |
| 321 | |
| 322 | static int wil6210_send_brp_rx(struct sigma_dut *dut, const char *mac, |
| 323 | int l_rx) |
| 324 | { |
Rakesh Sunki | 556237d | 2017-03-30 14:49:31 -0700 | [diff] [blame] | 325 | struct wil_wmi_bf_trig_cmd cmd; |
Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 326 | unsigned int cid; |
| 327 | |
Rakesh Sunki | 556237d | 2017-03-30 14:49:31 -0700 | [diff] [blame] | 328 | memset(&cmd, 0, sizeof(cmd)); |
| 329 | |
Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 330 | if (wil6210_get_cid(dut, mac, &cid)) |
| 331 | return -1; |
| 332 | |
| 333 | cmd.bf_type = WIL_WMI_BRP_RX; |
| 334 | cmd.sta_id = cid; |
| 335 | /* training length (l_rx) is ignored, FW always uses length 16 */ |
| 336 | return wil6210_wmi_send(dut, WIL_WMI_BF_TRIG_CMDID, |
| 337 | &cmd, sizeof(cmd)); |
| 338 | } |
| 339 | |
| 340 | |
| 341 | static int wil6210_send_sls(struct sigma_dut *dut, const char *mac) |
| 342 | { |
Rakesh Sunki | 556237d | 2017-03-30 14:49:31 -0700 | [diff] [blame] | 343 | struct wil_wmi_bf_trig_cmd cmd; |
| 344 | |
| 345 | memset(&cmd, 0, sizeof(cmd)); |
Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 346 | |
| 347 | if (parse_mac_address(dut, mac, (unsigned char *)&cmd.dest_mac)) |
| 348 | return -1; |
| 349 | |
| 350 | cmd.bf_type = WIL_WMI_SLS; |
| 351 | return wil6210_wmi_send(dut, WIL_WMI_BF_TRIG_CMDID, |
| 352 | &cmd, sizeof(cmd)); |
| 353 | } |
| 354 | |
Lior David | cc88b56 | 2017-01-03 18:52:09 +0200 | [diff] [blame] | 355 | #endif /* __linux__ */ |
| 356 | |
| 357 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 358 | static void static_ip_file(int proto, const char *addr, const char *mask, |
| 359 | const char *gw) |
| 360 | { |
| 361 | if (proto) { |
| 362 | FILE *f = fopen("static-ip", "w"); |
| 363 | if (f) { |
| 364 | fprintf(f, "%d %s %s %s\n", proto, addr, |
| 365 | mask ? mask : "N/A", |
| 366 | gw ? gw : "N/A"); |
| 367 | fclose(f); |
| 368 | } |
| 369 | } else { |
| 370 | unlink("static-ip"); |
| 371 | } |
| 372 | } |
| 373 | |
| 374 | |
| 375 | static int send_neighbor_request(struct sigma_dut *dut, const char *intf, |
| 376 | const char *ssid) |
| 377 | { |
| 378 | #ifdef __linux__ |
| 379 | char buf[100]; |
| 380 | |
| 381 | snprintf(buf, sizeof(buf), "iwpriv %s neighbor %s", |
| 382 | intf, ssid); |
| 383 | sigma_dut_print(dut, DUT_MSG_INFO, "Request: %s", buf); |
| 384 | |
| 385 | if (system(buf) != 0) { |
| 386 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 387 | "iwpriv neighbor request failed"); |
| 388 | return -1; |
| 389 | } |
| 390 | |
| 391 | sigma_dut_print(dut, DUT_MSG_INFO, "iwpriv neighbor request send"); |
| 392 | |
| 393 | return 0; |
| 394 | #else /* __linux__ */ |
| 395 | return -1; |
| 396 | #endif /* __linux__ */ |
| 397 | } |
| 398 | |
| 399 | |
| 400 | static int send_trans_mgmt_query(struct sigma_dut *dut, const char *intf, |
Ashwini Patil | 5acd738 | 2017-04-13 15:55:04 +0530 | [diff] [blame] | 401 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 402 | { |
Ashwini Patil | 5acd738 | 2017-04-13 15:55:04 +0530 | [diff] [blame] | 403 | const char *val; |
| 404 | int reason_code = 0; |
| 405 | char buf[1024]; |
| 406 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 407 | /* |
| 408 | * In the earlier builds we used WNM_QUERY and in later |
| 409 | * builds used WNM_BSS_QUERY. |
| 410 | */ |
| 411 | |
Ashwini Patil | 5acd738 | 2017-04-13 15:55:04 +0530 | [diff] [blame] | 412 | val = get_param(cmd, "BTMQuery_Reason_Code"); |
| 413 | if (val) |
| 414 | reason_code = atoi(val); |
| 415 | |
| 416 | val = get_param(cmd, "Cand_List"); |
| 417 | if (val && atoi(val) == 1 && dut->btm_query_cand_list) { |
| 418 | snprintf(buf, sizeof(buf), "WNM_BSS_QUERY %d%s", reason_code, |
| 419 | dut->btm_query_cand_list); |
| 420 | free(dut->btm_query_cand_list); |
| 421 | dut->btm_query_cand_list = NULL; |
| 422 | } else { |
| 423 | snprintf(buf, sizeof(buf), "WNM_BSS_QUERY %d", reason_code); |
| 424 | } |
| 425 | |
| 426 | if (wpa_command(intf, buf) != 0) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 427 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 428 | "transition management query failed"); |
| 429 | return -1; |
| 430 | } |
| 431 | |
| 432 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 433 | "transition management query sent"); |
| 434 | |
| 435 | return 0; |
| 436 | } |
| 437 | |
| 438 | |
| 439 | int is_ip_addr(const char *str) |
| 440 | { |
| 441 | const char *pos = str; |
| 442 | struct in_addr addr; |
| 443 | |
| 444 | while (*pos) { |
| 445 | if (*pos != '.' && (*pos < '0' || *pos > '9')) |
| 446 | return 0; |
| 447 | pos++; |
| 448 | } |
| 449 | |
| 450 | return inet_aton(str, &addr); |
| 451 | } |
| 452 | |
| 453 | |
| 454 | int is_ipv6_addr(const char *str) |
| 455 | { |
| 456 | struct sockaddr_in6 addr; |
| 457 | |
| 458 | return inet_pton(AF_INET6, str, &(addr.sin6_addr)); |
| 459 | } |
| 460 | |
| 461 | |
| 462 | int get_ip_config(struct sigma_dut *dut, const char *ifname, char *buf, |
| 463 | size_t buf_len) |
| 464 | { |
| 465 | char tmp[256], *pos, *pos2; |
| 466 | FILE *f; |
| 467 | char ip[16], mask[15], dns[16], sec_dns[16]; |
Sarvepalli, Rajesh Babu | a76c644 | 2016-03-18 20:34:26 +0530 | [diff] [blame] | 468 | const char *str_ps; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 469 | int is_dhcp = 0; |
| 470 | int s; |
| 471 | #ifdef ANDROID |
| 472 | char prop[PROPERTY_VALUE_MAX]; |
| 473 | #endif /* ANDROID */ |
| 474 | |
| 475 | ip[0] = '\0'; |
| 476 | mask[0] = '\0'; |
| 477 | dns[0] = '\0'; |
| 478 | sec_dns[0] = '\0'; |
| 479 | |
| 480 | s = socket(PF_INET, SOCK_DGRAM, 0); |
| 481 | if (s >= 0) { |
| 482 | struct ifreq ifr; |
| 483 | struct sockaddr_in saddr; |
| 484 | |
| 485 | memset(&ifr, 0, sizeof(ifr)); |
Peng Xu | b8fc5cc | 2017-05-10 17:27:28 -0700 | [diff] [blame] | 486 | strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 487 | if (ioctl(s, SIOCGIFADDR, &ifr) < 0) { |
| 488 | sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get " |
| 489 | "%s IP address: %s", |
| 490 | ifname, strerror(errno)); |
| 491 | } else { |
| 492 | memcpy(&saddr, &ifr.ifr_addr, |
| 493 | sizeof(struct sockaddr_in)); |
Peng Xu | b8fc5cc | 2017-05-10 17:27:28 -0700 | [diff] [blame] | 494 | strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip)); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | if (ioctl(s, SIOCGIFNETMASK, &ifr) == 0) { |
| 498 | memcpy(&saddr, &ifr.ifr_addr, |
| 499 | sizeof(struct sockaddr_in)); |
Peng Xu | b8fc5cc | 2017-05-10 17:27:28 -0700 | [diff] [blame] | 500 | strlcpy(mask, inet_ntoa(saddr.sin_addr), sizeof(mask)); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 501 | } |
| 502 | close(s); |
| 503 | } |
| 504 | |
| 505 | #ifdef ANDROID |
| 506 | snprintf(tmp, sizeof(tmp), "dhcp.%s.pid", ifname); |
| 507 | if (property_get(tmp, prop, NULL) != 0 && atoi(prop) > 0) { |
| 508 | snprintf(tmp, sizeof(tmp), "dhcp.%s.result", ifname); |
| 509 | if (property_get(tmp, prop, NULL) != 0 && |
| 510 | strcmp(prop, "ok") == 0) { |
| 511 | snprintf(tmp, sizeof(tmp), "dhcp.%s.ipaddress", |
| 512 | ifname); |
| 513 | if (property_get(tmp, prop, NULL) != 0 && |
| 514 | strcmp(ip, prop) == 0) |
| 515 | is_dhcp = 1; |
| 516 | } |
| 517 | } |
| 518 | |
| 519 | snprintf(tmp, sizeof(tmp), "dhcp.%s.dns1", ifname); |
Peng Xu | b8fc5cc | 2017-05-10 17:27:28 -0700 | [diff] [blame] | 520 | if (property_get(tmp, prop, NULL) != 0) |
| 521 | strlcpy(dns, prop, sizeof(dns)); |
| 522 | else if (property_get("net.dns1", prop, NULL) != 0) |
| 523 | strlcpy(dns, prop, sizeof(dns)); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 524 | |
| 525 | snprintf(tmp, sizeof(tmp), "dhcp.%s.dns2", ifname); |
Peng Xu | b8fc5cc | 2017-05-10 17:27:28 -0700 | [diff] [blame] | 526 | if (property_get(tmp, prop, NULL) != 0) |
| 527 | strlcpy(sec_dns, prop, sizeof(sec_dns)); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 528 | #else /* ANDROID */ |
| 529 | #ifdef __linux__ |
Sarvepalli, Rajesh Babu | a76c644 | 2016-03-18 20:34:26 +0530 | [diff] [blame] | 530 | if (get_driver_type() == DRIVER_OPENWRT) |
| 531 | str_ps = "ps -w"; |
| 532 | else |
| 533 | str_ps = "ps ax"; |
| 534 | snprintf(tmp, sizeof(tmp), |
| 535 | "%s | grep dhclient | grep -v grep | grep -q %s", |
| 536 | str_ps, ifname); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 537 | if (system(tmp) == 0) |
| 538 | is_dhcp = 1; |
| 539 | else { |
Sarvepalli, Rajesh Babu | a76c644 | 2016-03-18 20:34:26 +0530 | [diff] [blame] | 540 | snprintf(tmp, sizeof(tmp), |
| 541 | "%s | grep udhcpc | grep -v grep | grep -q %s", |
| 542 | str_ps, ifname); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 543 | if (system(tmp) == 0) |
| 544 | is_dhcp = 1; |
| 545 | else { |
Sarvepalli, Rajesh Babu | a76c644 | 2016-03-18 20:34:26 +0530 | [diff] [blame] | 546 | snprintf(tmp, sizeof(tmp), |
| 547 | "%s | grep dhcpcd | grep -v grep | grep -q %s", |
| 548 | str_ps, ifname); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 549 | if (system(tmp) == 0) |
| 550 | is_dhcp = 1; |
| 551 | } |
| 552 | } |
| 553 | #endif /* __linux__ */ |
| 554 | |
| 555 | f = fopen("/etc/resolv.conf", "r"); |
| 556 | if (f) { |
| 557 | while (fgets(tmp, sizeof(tmp), f)) { |
| 558 | if (strncmp(tmp, "nameserver", 10) != 0) |
| 559 | continue; |
| 560 | pos = tmp + 10; |
| 561 | while (*pos == ' ' || *pos == '\t') |
| 562 | pos++; |
| 563 | pos2 = pos; |
| 564 | while (*pos2) { |
| 565 | if (*pos2 == '\n' || *pos2 == '\r') { |
| 566 | *pos2 = '\0'; |
| 567 | break; |
| 568 | } |
| 569 | pos2++; |
| 570 | } |
Peng Xu | b8fc5cc | 2017-05-10 17:27:28 -0700 | [diff] [blame] | 571 | if (!dns[0]) |
| 572 | strlcpy(dns, pos, sizeof(dns)); |
| 573 | else if (!sec_dns[0]) |
| 574 | strlcpy(sec_dns, pos, sizeof(sec_dns)); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 575 | } |
| 576 | fclose(f); |
| 577 | } |
| 578 | #endif /* ANDROID */ |
| 579 | |
| 580 | snprintf(buf, buf_len, "dhcp,%d,ip,%s,mask,%s,primary-dns,%s", |
| 581 | is_dhcp, ip, mask, dns); |
| 582 | buf[buf_len - 1] = '\0'; |
| 583 | |
| 584 | return 0; |
| 585 | } |
| 586 | |
| 587 | |
| 588 | |
| 589 | |
| 590 | int get_ipv6_config(struct sigma_dut *dut, const char *ifname, char *buf, |
| 591 | size_t buf_len) |
| 592 | { |
| 593 | #ifdef __linux__ |
| 594 | #ifdef ANDROID |
| 595 | char cmd[200], result[1000], *pos, *end; |
| 596 | FILE *f; |
| 597 | size_t len; |
| 598 | |
| 599 | snprintf(cmd, sizeof(cmd), "ip addr show dev %s scope global", ifname); |
| 600 | f = popen(cmd, "r"); |
| 601 | if (f == NULL) |
| 602 | return -1; |
| 603 | len = fread(result, 1, sizeof(result) - 1, f); |
| 604 | pclose(f); |
| 605 | if (len == 0) |
| 606 | return -1; |
| 607 | result[len] = '\0'; |
| 608 | sigma_dut_print(dut, DUT_MSG_DEBUG, "%s result: %s\n", cmd, result); |
| 609 | |
| 610 | pos = strstr(result, "inet6 "); |
| 611 | if (pos == NULL) |
| 612 | return -1; |
| 613 | pos += 6; |
| 614 | end = strchr(pos, ' '); |
| 615 | if (end) |
| 616 | *end = '\0'; |
| 617 | end = strchr(pos, '/'); |
| 618 | if (end) |
| 619 | *end = '\0'; |
| 620 | snprintf(buf, buf_len, "ip,%s", pos); |
| 621 | buf[buf_len - 1] = '\0'; |
| 622 | return 0; |
| 623 | #else /* ANDROID */ |
| 624 | struct ifaddrs *ifaddr, *ifa; |
| 625 | int res, found = 0; |
| 626 | char host[NI_MAXHOST]; |
| 627 | |
| 628 | if (getifaddrs(&ifaddr) < 0) { |
| 629 | perror("getifaddrs"); |
| 630 | return -1; |
| 631 | } |
| 632 | |
| 633 | for (ifa = ifaddr; ifa; ifa = ifa->ifa_next) { |
| 634 | if (strcasecmp(ifname, ifa->ifa_name) != 0) |
| 635 | continue; |
| 636 | if (ifa->ifa_addr == NULL || |
| 637 | ifa->ifa_addr->sa_family != AF_INET6) |
| 638 | continue; |
| 639 | |
| 640 | res = getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in6), |
| 641 | host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST); |
| 642 | if (res != 0) { |
| 643 | sigma_dut_print(dut, DUT_MSG_DEBUG, "getnameinfo: %s", |
| 644 | gai_strerror(res)); |
| 645 | continue; |
| 646 | } |
| 647 | if (strncmp(host, "fe80::", 6) == 0) |
| 648 | continue; /* skip link-local */ |
| 649 | |
| 650 | sigma_dut_print(dut, DUT_MSG_DEBUG, "ifaddr: %s", host); |
| 651 | found = 1; |
| 652 | break; |
| 653 | } |
| 654 | |
| 655 | freeifaddrs(ifaddr); |
| 656 | |
| 657 | if (found) { |
| 658 | char *pos; |
| 659 | pos = strchr(host, '%'); |
| 660 | if (pos) |
| 661 | *pos = '\0'; |
| 662 | snprintf(buf, buf_len, "ip,%s", host); |
| 663 | buf[buf_len - 1] = '\0'; |
| 664 | return 0; |
| 665 | } |
| 666 | |
| 667 | #endif /* ANDROID */ |
| 668 | #endif /* __linux__ */ |
| 669 | return -1; |
| 670 | } |
| 671 | |
| 672 | |
| 673 | static int cmd_sta_get_ip_config(struct sigma_dut *dut, |
| 674 | struct sigma_conn *conn, |
| 675 | struct sigma_cmd *cmd) |
| 676 | { |
| 677 | const char *intf = get_param(cmd, "Interface"); |
| 678 | const char *ifname; |
| 679 | char buf[200]; |
| 680 | const char *val; |
| 681 | int type = 1; |
| 682 | |
| 683 | if (intf == NULL) |
| 684 | return -1; |
| 685 | |
| 686 | if (strcmp(intf, get_main_ifname()) == 0) |
| 687 | ifname = get_station_ifname(); |
| 688 | else |
| 689 | ifname = intf; |
| 690 | |
| 691 | /* |
| 692 | * UCC may assume the IP address to be available immediately after |
| 693 | * association without trying to run sta_get_ip_config multiple times. |
| 694 | * Sigma CAPI does not specify this command as a block command that |
| 695 | * would wait for the address to become available, but to pass tests |
| 696 | * more reliably, it looks like such a wait may be needed here. |
| 697 | */ |
| 698 | if (wait_ip_addr(dut, ifname, 15) < 0) { |
| 699 | sigma_dut_print(dut, DUT_MSG_INFO, "Could not get IP address " |
| 700 | "for sta_get_ip_config"); |
| 701 | /* |
| 702 | * Try to continue anyway since many UCC tests do not really |
| 703 | * care about the return value from here.. |
| 704 | */ |
| 705 | } |
| 706 | |
| 707 | val = get_param(cmd, "Type"); |
| 708 | if (val) |
| 709 | type = atoi(val); |
| 710 | if (type == 2 || dut->last_set_ip_config_ipv6) { |
| 711 | int i; |
| 712 | |
| 713 | /* |
| 714 | * Since we do not have proper wait for IPv6 addresses, use a |
| 715 | * fixed two second delay here as a workaround for UCC script |
| 716 | * assuming IPv6 address is available when this command returns. |
| 717 | * Some scripts did not use Type,2 properly for IPv6, so include |
| 718 | * also the cases where the previous sta_set_ip_config indicated |
| 719 | * use of IPv6. |
| 720 | */ |
| 721 | sigma_dut_print(dut, DUT_MSG_INFO, "Wait up to extra ten seconds in sta_get_ip_config for IPv6 address"); |
| 722 | for (i = 0; i < 10; i++) { |
| 723 | sleep(1); |
| 724 | if (get_ipv6_config(dut, ifname, buf, sizeof(buf)) == 0) |
| 725 | { |
| 726 | sigma_dut_print(dut, DUT_MSG_INFO, "Found IPv6 address"); |
| 727 | send_resp(dut, conn, SIGMA_COMPLETE, buf); |
| 728 | #ifdef ANDROID |
| 729 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 730 | "Adding IPv6 rule on Android"); |
| 731 | add_ipv6_rule(dut, intf); |
| 732 | #endif /* ANDROID */ |
| 733 | |
| 734 | return 0; |
| 735 | } |
| 736 | } |
| 737 | } |
| 738 | if (type == 1) { |
| 739 | if (get_ip_config(dut, ifname, buf, sizeof(buf)) < 0) |
| 740 | return -2; |
| 741 | } else if (type == 2) { |
| 742 | if (get_ipv6_config(dut, ifname, buf, sizeof(buf)) < 0) |
| 743 | return -2; |
| 744 | } else { |
| 745 | send_resp(dut, conn, SIGMA_ERROR, |
| 746 | "errorCode,Unsupported address type"); |
| 747 | return 0; |
| 748 | } |
| 749 | |
| 750 | send_resp(dut, conn, SIGMA_COMPLETE, buf); |
| 751 | return 0; |
| 752 | } |
| 753 | |
| 754 | |
| 755 | static void kill_dhcp_client(struct sigma_dut *dut, const char *ifname) |
| 756 | { |
| 757 | #ifdef __linux__ |
| 758 | char buf[200]; |
| 759 | char path[128]; |
| 760 | struct stat s; |
| 761 | |
| 762 | #ifdef ANDROID |
| 763 | snprintf(path, sizeof(path), "/data/misc/dhcp/dhcpcd-%s.pid", ifname); |
| 764 | #else /* ANDROID */ |
| 765 | snprintf(path, sizeof(path), "/var/run/dhclient-%s.pid", ifname); |
| 766 | #endif /* ANDROID */ |
| 767 | if (stat(path, &s) == 0) { |
| 768 | snprintf(buf, sizeof(buf), "kill `cat %s`", path); |
| 769 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 770 | "Kill previous DHCP client: %s", buf); |
| 771 | if (system(buf) != 0) |
| 772 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 773 | "Failed to kill DHCP client"); |
| 774 | unlink(path); |
| 775 | sleep(1); |
| 776 | } else { |
| 777 | snprintf(path, sizeof(path), "/var/run/dhcpcd-%s.pid", ifname); |
| 778 | |
| 779 | if (stat(path, &s) == 0) { |
| 780 | snprintf(buf, sizeof(buf), "kill `cat %s`", path); |
| 781 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 782 | "Kill previous DHCP client: %s", buf); |
| 783 | if (system(buf) != 0) |
| 784 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 785 | "Failed to kill DHCP client"); |
| 786 | unlink(path); |
| 787 | sleep(1); |
| 788 | } |
| 789 | } |
| 790 | #endif /* __linux__ */ |
| 791 | } |
| 792 | |
| 793 | |
| 794 | static int start_dhcp_client(struct sigma_dut *dut, const char *ifname) |
| 795 | { |
| 796 | #ifdef __linux__ |
| 797 | char buf[200]; |
| 798 | |
| 799 | #ifdef ANDROID |
Purushottam Kushwaha | 46d6426 | 2016-08-23 17:57:53 +0530 | [diff] [blame] | 800 | if (access("/system/bin/dhcpcd", F_OK) != -1) { |
| 801 | snprintf(buf, sizeof(buf), |
| 802 | "/system/bin/dhcpcd -b %s", ifname); |
| 803 | } else if (access("/system/bin/dhcptool", F_OK) != -1) { |
| 804 | snprintf(buf, sizeof(buf), "/system/bin/dhcptool %s &", ifname); |
| 805 | } else { |
| 806 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 807 | "DHCP client program missing"); |
| 808 | return 0; |
| 809 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 810 | #else /* ANDROID */ |
| 811 | snprintf(buf, sizeof(buf), |
| 812 | "dhclient -nw -pf /var/run/dhclient-%s.pid %s", |
| 813 | ifname, ifname); |
| 814 | #endif /* ANDROID */ |
| 815 | sigma_dut_print(dut, DUT_MSG_INFO, "Start DHCP client: %s", buf); |
| 816 | if (system(buf) != 0) { |
| 817 | snprintf(buf, sizeof(buf), "dhcpcd -t 0 %s &", ifname); |
| 818 | if (system(buf) != 0) { |
| 819 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 820 | "Failed to start DHCP client"); |
| 821 | #ifndef ANDROID |
| 822 | return -1; |
| 823 | #endif /* ANDROID */ |
| 824 | } |
| 825 | } |
| 826 | #endif /* __linux__ */ |
| 827 | |
| 828 | return 0; |
| 829 | } |
| 830 | |
| 831 | |
| 832 | static int clear_ip_addr(struct sigma_dut *dut, const char *ifname) |
| 833 | { |
| 834 | #ifdef __linux__ |
| 835 | char buf[200]; |
| 836 | |
| 837 | snprintf(buf, sizeof(buf), "ip addr flush dev %s", ifname); |
| 838 | if (system(buf) != 0) { |
| 839 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 840 | "Failed to clear IP addresses"); |
| 841 | return -1; |
| 842 | } |
| 843 | #endif /* __linux__ */ |
| 844 | |
| 845 | return 0; |
| 846 | } |
| 847 | |
| 848 | |
| 849 | #ifdef ANDROID |
| 850 | static int add_ipv6_rule(struct sigma_dut *dut, const char *ifname) |
| 851 | { |
| 852 | char cmd[200], *result, *pos; |
| 853 | FILE *fp; |
Pradeep Reddy POTTETI | f58a1fe | 2016-10-13 17:22:03 +0530 | [diff] [blame] | 854 | int tableid; |
| 855 | size_t len, result_len = 1000; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 856 | |
| 857 | snprintf(cmd, sizeof(cmd), "ip -6 route list table all | grep %s", |
| 858 | ifname); |
| 859 | fp = popen(cmd, "r"); |
| 860 | if (fp == NULL) |
| 861 | return -1; |
| 862 | |
| 863 | result = malloc(result_len); |
Pradeep Reddy POTTETI | 673d85c | 2016-07-26 19:08:07 +0530 | [diff] [blame] | 864 | if (result == NULL) { |
| 865 | fclose(fp); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 866 | return -1; |
Pradeep Reddy POTTETI | 673d85c | 2016-07-26 19:08:07 +0530 | [diff] [blame] | 867 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 868 | |
Pradeep Reddy POTTETI | f58a1fe | 2016-10-13 17:22:03 +0530 | [diff] [blame] | 869 | len = fread(result, 1, result_len - 1, fp); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 870 | fclose(fp); |
| 871 | |
| 872 | if (len == 0) { |
| 873 | free(result); |
| 874 | return -1; |
| 875 | } |
Pradeep Reddy POTTETI | f58a1fe | 2016-10-13 17:22:03 +0530 | [diff] [blame] | 876 | result[len] = '\0'; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 877 | |
| 878 | pos = strstr(result, "table "); |
| 879 | if (pos == NULL) { |
| 880 | free(result); |
| 881 | return -1; |
| 882 | } |
| 883 | |
| 884 | pos += strlen("table "); |
| 885 | tableid = atoi(pos); |
| 886 | if (tableid != 0) { |
| 887 | if (system("ip -6 rule del prio 22000") != 0) { |
| 888 | /* ignore any error */ |
| 889 | } |
| 890 | snprintf(cmd, sizeof(cmd), |
| 891 | "ip -6 rule add from all lookup %d prio 22000", |
| 892 | tableid); |
| 893 | if (system(cmd) != 0) { |
| 894 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 895 | "Failed to run %s", cmd); |
| 896 | free(result); |
| 897 | return -1; |
| 898 | } |
| 899 | } else { |
| 900 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 901 | "No Valid Table Id found %s", pos); |
| 902 | free(result); |
| 903 | return -1; |
| 904 | } |
| 905 | free(result); |
| 906 | |
| 907 | return 0; |
| 908 | } |
| 909 | #endif /* ANDROID */ |
| 910 | |
| 911 | |
| 912 | static int cmd_sta_set_ip_config(struct sigma_dut *dut, |
| 913 | struct sigma_conn *conn, |
| 914 | struct sigma_cmd *cmd) |
| 915 | { |
| 916 | const char *intf = get_param(cmd, "Interface"); |
| 917 | const char *ifname; |
| 918 | char buf[200]; |
| 919 | const char *val, *ip, *mask, *gw; |
| 920 | int type = 1; |
| 921 | |
| 922 | if (intf == NULL) |
| 923 | return -1; |
| 924 | |
| 925 | if (strcmp(intf, get_main_ifname()) == 0) |
| 926 | ifname = get_station_ifname(); |
| 927 | else |
| 928 | ifname = intf; |
| 929 | |
| 930 | if (if_nametoindex(ifname) == 0) { |
| 931 | send_resp(dut, conn, SIGMA_ERROR, |
| 932 | "ErrorCode,Unknown interface"); |
| 933 | return 0; |
| 934 | } |
| 935 | |
| 936 | val = get_param(cmd, "Type"); |
| 937 | if (val) { |
| 938 | type = atoi(val); |
| 939 | if (type != 1 && type != 2) { |
| 940 | send_resp(dut, conn, SIGMA_ERROR, |
| 941 | "ErrorCode,Unsupported address type"); |
| 942 | return 0; |
| 943 | } |
| 944 | } |
| 945 | |
| 946 | dut->last_set_ip_config_ipv6 = 0; |
| 947 | |
| 948 | val = get_param(cmd, "dhcp"); |
| 949 | if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "true") == 0)) { |
| 950 | static_ip_file(0, NULL, NULL, NULL); |
| 951 | #ifdef __linux__ |
| 952 | if (type == 2) { |
| 953 | dut->last_set_ip_config_ipv6 = 1; |
| 954 | sigma_dut_print(dut, DUT_MSG_INFO, "Using IPv6 " |
| 955 | "stateless address autoconfiguration"); |
| 956 | #ifdef ANDROID |
| 957 | /* |
| 958 | * This sleep is required as the assignment in case of |
| 959 | * Android is taking time and is done by the kernel. |
| 960 | * The subsequent ping for IPv6 is impacting HS20 test |
| 961 | * case. |
| 962 | */ |
| 963 | sleep(2); |
| 964 | add_ipv6_rule(dut, intf); |
| 965 | #endif /* ANDROID */ |
| 966 | /* Assume this happens by default */ |
| 967 | return 1; |
| 968 | } |
| 969 | |
| 970 | kill_dhcp_client(dut, ifname); |
| 971 | if (start_dhcp_client(dut, ifname) < 0) |
| 972 | return -2; |
| 973 | return 1; |
| 974 | #endif /* __linux__ */ |
| 975 | return -2; |
| 976 | } |
| 977 | |
| 978 | ip = get_param(cmd, "ip"); |
Pradeep Reddy POTTETI | b18c565 | 2016-01-18 12:45:37 +0530 | [diff] [blame] | 979 | if (!ip) { |
| 980 | send_resp(dut, conn, SIGMA_INVALID, |
| 981 | "ErrorCode,Missing IP address"); |
| 982 | return 0; |
| 983 | } |
| 984 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 985 | mask = get_param(cmd, "mask"); |
Pradeep Reddy POTTETI | b18c565 | 2016-01-18 12:45:37 +0530 | [diff] [blame] | 986 | if (!mask) { |
| 987 | send_resp(dut, conn, SIGMA_INVALID, |
| 988 | "ErrorCode,Missing subnet mask"); |
| 989 | return 0; |
| 990 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 991 | |
| 992 | if (type == 2) { |
| 993 | int net = atoi(mask); |
| 994 | |
| 995 | if ((net < 0 && net > 64) || !is_ipv6_addr(ip)) |
| 996 | return -1; |
| 997 | |
| 998 | if (dut->no_ip_addr_set) { |
| 999 | snprintf(buf, sizeof(buf), |
| 1000 | "sysctl net.ipv6.conf.%s.disable_ipv6=1", |
| 1001 | ifname); |
| 1002 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 1003 | if (system(buf) != 0) { |
| 1004 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 1005 | "Failed to disable IPv6 address before association"); |
| 1006 | } |
| 1007 | } else { |
| 1008 | snprintf(buf, sizeof(buf), |
| 1009 | "ip -6 addr del %s/%s dev %s", |
| 1010 | ip, mask, ifname); |
| 1011 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 1012 | if (system(buf) != 0) { |
| 1013 | /* |
| 1014 | * This command may fail if the address being |
| 1015 | * deleted does not exist. Inaction here is |
| 1016 | * intentional. |
| 1017 | */ |
| 1018 | } |
| 1019 | |
| 1020 | snprintf(buf, sizeof(buf), |
| 1021 | "ip -6 addr add %s/%s dev %s", |
| 1022 | ip, mask, ifname); |
| 1023 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 1024 | if (system(buf) != 0) { |
| 1025 | send_resp(dut, conn, SIGMA_ERROR, |
| 1026 | "ErrorCode,Failed to set IPv6 address"); |
| 1027 | return 0; |
| 1028 | } |
| 1029 | } |
| 1030 | |
| 1031 | dut->last_set_ip_config_ipv6 = 1; |
| 1032 | static_ip_file(6, ip, mask, NULL); |
| 1033 | return 1; |
| 1034 | } else if (type == 1) { |
Pradeep Reddy POTTETI | b18c565 | 2016-01-18 12:45:37 +0530 | [diff] [blame] | 1035 | if (!is_ip_addr(ip) || !is_ip_addr(mask)) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1036 | return -1; |
| 1037 | } |
| 1038 | |
| 1039 | kill_dhcp_client(dut, ifname); |
| 1040 | |
| 1041 | if (!dut->no_ip_addr_set) { |
| 1042 | snprintf(buf, sizeof(buf), "ifconfig %s %s netmask %s", |
| 1043 | ifname, ip, mask); |
| 1044 | if (system(buf) != 0) { |
| 1045 | send_resp(dut, conn, SIGMA_ERROR, |
| 1046 | "ErrorCode,Failed to set IP address"); |
| 1047 | return 0; |
| 1048 | } |
| 1049 | } |
| 1050 | |
| 1051 | gw = get_param(cmd, "defaultGateway"); |
| 1052 | if (gw) { |
| 1053 | if (!is_ip_addr(gw)) |
| 1054 | return -1; |
| 1055 | snprintf(buf, sizeof(buf), "route add default gw %s", gw); |
| 1056 | if (!dut->no_ip_addr_set && system(buf) != 0) { |
| 1057 | snprintf(buf, sizeof(buf), "ip ro re default via %s", |
| 1058 | gw); |
| 1059 | if (system(buf) != 0) { |
| 1060 | send_resp(dut, conn, SIGMA_ERROR, |
| 1061 | "ErrorCode,Failed " |
| 1062 | "to set default gateway"); |
| 1063 | return 0; |
| 1064 | } |
| 1065 | } |
| 1066 | } |
| 1067 | |
| 1068 | val = get_param(cmd, "primary-dns"); |
| 1069 | if (val) { |
| 1070 | /* TODO */ |
| 1071 | sigma_dut_print(dut, DUT_MSG_INFO, "Ignored primary-dns %s " |
| 1072 | "setting", val); |
| 1073 | } |
| 1074 | |
| 1075 | val = get_param(cmd, "secondary-dns"); |
| 1076 | if (val) { |
| 1077 | /* TODO */ |
| 1078 | sigma_dut_print(dut, DUT_MSG_INFO, "Ignored secondary-dns %s " |
| 1079 | "setting", val); |
| 1080 | } |
| 1081 | |
| 1082 | static_ip_file(4, ip, mask, gw); |
| 1083 | |
| 1084 | return 1; |
| 1085 | } |
| 1086 | |
| 1087 | |
| 1088 | static int cmd_sta_get_info(struct sigma_dut *dut, struct sigma_conn *conn, |
| 1089 | struct sigma_cmd *cmd) |
| 1090 | { |
| 1091 | /* const char *intf = get_param(cmd, "Interface"); */ |
| 1092 | /* TODO: could report more details here */ |
| 1093 | send_resp(dut, conn, SIGMA_COMPLETE, "vendor,Atheros"); |
| 1094 | return 0; |
| 1095 | } |
| 1096 | |
| 1097 | |
| 1098 | static int cmd_sta_get_mac_address(struct sigma_dut *dut, |
| 1099 | struct sigma_conn *conn, |
| 1100 | struct sigma_cmd *cmd) |
| 1101 | { |
| 1102 | /* const char *intf = get_param(cmd, "Interface"); */ |
| 1103 | char addr[20], resp[50]; |
| 1104 | |
Ankita Bajaj | 0d5825b | 2017-10-25 16:20:17 +0530 | [diff] [blame] | 1105 | if (dut->dev_role == DEVROLE_STA_CFON) |
| 1106 | return sta_cfon_get_mac_address(dut, conn, cmd); |
| 1107 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1108 | if (get_wpa_status(get_station_ifname(), "address", addr, sizeof(addr)) |
| 1109 | < 0) |
| 1110 | return -2; |
| 1111 | |
| 1112 | snprintf(resp, sizeof(resp), "mac,%s", addr); |
| 1113 | send_resp(dut, conn, SIGMA_COMPLETE, resp); |
| 1114 | return 0; |
| 1115 | } |
| 1116 | |
| 1117 | |
| 1118 | static int cmd_sta_is_connected(struct sigma_dut *dut, struct sigma_conn *conn, |
| 1119 | struct sigma_cmd *cmd) |
| 1120 | { |
| 1121 | /* const char *intf = get_param(cmd, "Interface"); */ |
| 1122 | int connected = 0; |
| 1123 | char result[32]; |
| 1124 | if (get_wpa_status(get_station_ifname(), "wpa_state", result, |
| 1125 | sizeof(result)) < 0) { |
| 1126 | sigma_dut_print(dut, DUT_MSG_INFO, "Could not get interface " |
| 1127 | "%s status", get_station_ifname()); |
| 1128 | return -2; |
| 1129 | } |
| 1130 | |
| 1131 | sigma_dut_print(dut, DUT_MSG_DEBUG, "wpa_state=%s", result); |
| 1132 | if (strncmp(result, "COMPLETED", 9) == 0) |
| 1133 | connected = 1; |
| 1134 | |
| 1135 | if (connected) |
| 1136 | send_resp(dut, conn, SIGMA_COMPLETE, "connected,1"); |
| 1137 | else |
| 1138 | send_resp(dut, conn, SIGMA_COMPLETE, "connected,0"); |
| 1139 | |
| 1140 | return 0; |
| 1141 | } |
| 1142 | |
| 1143 | |
| 1144 | static int cmd_sta_verify_ip_connection(struct sigma_dut *dut, |
| 1145 | struct sigma_conn *conn, |
| 1146 | struct sigma_cmd *cmd) |
| 1147 | { |
| 1148 | /* const char *intf = get_param(cmd, "Interface"); */ |
| 1149 | const char *dst, *timeout; |
| 1150 | int wait_time = 90; |
| 1151 | char buf[100]; |
| 1152 | int res; |
| 1153 | |
| 1154 | dst = get_param(cmd, "destination"); |
| 1155 | if (dst == NULL || !is_ip_addr(dst)) |
| 1156 | return -1; |
| 1157 | |
| 1158 | timeout = get_param(cmd, "timeout"); |
| 1159 | if (timeout) { |
| 1160 | wait_time = atoi(timeout); |
| 1161 | if (wait_time < 1) |
| 1162 | wait_time = 1; |
| 1163 | } |
| 1164 | |
| 1165 | /* TODO: force renewal of IP lease if DHCP is enabled */ |
| 1166 | |
| 1167 | snprintf(buf, sizeof(buf), "ping %s -c 3 -W %d", dst, wait_time); |
| 1168 | res = system(buf); |
| 1169 | sigma_dut_print(dut, DUT_MSG_DEBUG, "ping returned: %d", res); |
| 1170 | if (res == 0) |
| 1171 | send_resp(dut, conn, SIGMA_COMPLETE, "connected,1"); |
| 1172 | else if (res == 256) |
| 1173 | send_resp(dut, conn, SIGMA_COMPLETE, "connected,0"); |
| 1174 | else |
| 1175 | return -2; |
| 1176 | |
| 1177 | return 0; |
| 1178 | } |
| 1179 | |
| 1180 | |
| 1181 | static int cmd_sta_get_bssid(struct sigma_dut *dut, struct sigma_conn *conn, |
| 1182 | struct sigma_cmd *cmd) |
| 1183 | { |
| 1184 | /* const char *intf = get_param(cmd, "Interface"); */ |
| 1185 | char bssid[20], resp[50]; |
| 1186 | |
| 1187 | if (get_wpa_status(get_station_ifname(), "bssid", bssid, sizeof(bssid)) |
| 1188 | < 0) |
Peng Xu | b8fc5cc | 2017-05-10 17:27:28 -0700 | [diff] [blame] | 1189 | strlcpy(bssid, "00:00:00:00:00:00", sizeof(bssid)); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1190 | |
| 1191 | snprintf(resp, sizeof(resp), "bssid,%s", bssid); |
| 1192 | send_resp(dut, conn, SIGMA_COMPLETE, resp); |
| 1193 | return 0; |
| 1194 | } |
| 1195 | |
| 1196 | |
| 1197 | #ifdef __SAMSUNG__ |
| 1198 | static int add_use_network(const char *ifname) |
| 1199 | { |
| 1200 | char buf[100]; |
| 1201 | |
| 1202 | snprintf(buf, sizeof(buf), "USE_NETWORK ON"); |
| 1203 | wpa_command(ifname, buf); |
| 1204 | return 0; |
| 1205 | } |
| 1206 | #endif /* __SAMSUNG__ */ |
| 1207 | |
| 1208 | |
| 1209 | static int add_network_common(struct sigma_dut *dut, struct sigma_conn *conn, |
| 1210 | const char *ifname, struct sigma_cmd *cmd) |
| 1211 | { |
| 1212 | const char *ssid = get_param(cmd, "ssid"); |
| 1213 | int id; |
| 1214 | const char *val; |
| 1215 | |
| 1216 | if (ssid == NULL) |
| 1217 | return -1; |
| 1218 | |
| 1219 | start_sta_mode(dut); |
| 1220 | |
| 1221 | #ifdef __SAMSUNG__ |
| 1222 | add_use_network(ifname); |
| 1223 | #endif /* __SAMSUNG__ */ |
| 1224 | |
| 1225 | id = add_network(ifname); |
| 1226 | if (id < 0) |
| 1227 | return -2; |
| 1228 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding network %d", id); |
| 1229 | |
| 1230 | if (set_network_quoted(ifname, id, "ssid", ssid) < 0) |
| 1231 | return -2; |
| 1232 | |
| 1233 | dut->infra_network_id = id; |
| 1234 | snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid); |
| 1235 | |
| 1236 | val = get_param(cmd, "program"); |
| 1237 | if (!val) |
| 1238 | val = get_param(cmd, "prog"); |
| 1239 | if (val && strcasecmp(val, "hs2") == 0) { |
| 1240 | char buf[100]; |
| 1241 | snprintf(buf, sizeof(buf), "ENABLE_NETWORK %d no-connect", id); |
| 1242 | wpa_command(ifname, buf); |
| 1243 | |
| 1244 | val = get_param(cmd, "prefer"); |
| 1245 | if (val && atoi(val) > 0) |
| 1246 | set_network(ifname, id, "priority", "1"); |
| 1247 | } |
| 1248 | |
| 1249 | return id; |
| 1250 | } |
| 1251 | |
| 1252 | |
| 1253 | static int cmd_sta_set_encryption(struct sigma_dut *dut, |
| 1254 | struct sigma_conn *conn, |
| 1255 | struct sigma_cmd *cmd) |
| 1256 | { |
| 1257 | const char *intf = get_param(cmd, "Interface"); |
| 1258 | const char *ssid = get_param(cmd, "ssid"); |
| 1259 | const char *type = get_param(cmd, "encpType"); |
| 1260 | const char *ifname; |
| 1261 | char buf[200]; |
| 1262 | int id; |
| 1263 | |
| 1264 | if (intf == NULL || ssid == NULL) |
| 1265 | return -1; |
| 1266 | |
| 1267 | if (strcmp(intf, get_main_ifname()) == 0) |
| 1268 | ifname = get_station_ifname(); |
| 1269 | else |
| 1270 | ifname = intf; |
| 1271 | |
| 1272 | id = add_network_common(dut, conn, ifname, cmd); |
| 1273 | if (id < 0) |
| 1274 | return id; |
| 1275 | |
| 1276 | if (set_network(ifname, id, "key_mgmt", "NONE") < 0) |
| 1277 | return -2; |
| 1278 | |
| 1279 | if (type && strcasecmp(type, "wep") == 0) { |
| 1280 | const char *val; |
| 1281 | int i; |
| 1282 | |
| 1283 | val = get_param(cmd, "activeKey"); |
| 1284 | if (val) { |
| 1285 | int keyid; |
| 1286 | keyid = atoi(val); |
| 1287 | if (keyid < 1 || keyid > 4) |
| 1288 | return -1; |
| 1289 | snprintf(buf, sizeof(buf), "%d", keyid - 1); |
| 1290 | if (set_network(ifname, id, "wep_tx_keyidx", buf) < 0) |
| 1291 | return -2; |
| 1292 | } |
| 1293 | |
| 1294 | for (i = 0; i < 4; i++) { |
| 1295 | snprintf(buf, sizeof(buf), "key%d", i + 1); |
| 1296 | val = get_param(cmd, buf); |
| 1297 | if (val == NULL) |
| 1298 | continue; |
| 1299 | snprintf(buf, sizeof(buf), "wep_key%d", i); |
| 1300 | if (set_network(ifname, id, buf, val) < 0) |
| 1301 | return -2; |
| 1302 | } |
| 1303 | } |
| 1304 | |
| 1305 | return 1; |
| 1306 | } |
| 1307 | |
| 1308 | |
| 1309 | static int set_wpa_common(struct sigma_dut *dut, struct sigma_conn *conn, |
| 1310 | const char *ifname, struct sigma_cmd *cmd) |
| 1311 | { |
| 1312 | const char *val; |
| 1313 | int id; |
Jouni Malinen | ad395a2 | 2017-09-01 21:13:46 +0300 | [diff] [blame] | 1314 | int cipher_set = 0; |
Jouni Malinen | 47dcc95 | 2017-10-09 16:43:24 +0300 | [diff] [blame] | 1315 | int owe; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1316 | |
| 1317 | id = add_network_common(dut, conn, ifname, cmd); |
| 1318 | if (id < 0) |
| 1319 | return id; |
| 1320 | |
Jouni Malinen | 47dcc95 | 2017-10-09 16:43:24 +0300 | [diff] [blame] | 1321 | val = get_param(cmd, "Type"); |
| 1322 | owe = val && strcasecmp(val, "OWE") == 0; |
| 1323 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1324 | val = get_param(cmd, "keyMgmtType"); |
Jouni Malinen | 47dcc95 | 2017-10-09 16:43:24 +0300 | [diff] [blame] | 1325 | if (!val && owe) |
| 1326 | val = "OWE"; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1327 | if (val == NULL) { |
| 1328 | send_resp(dut, conn, SIGMA_INVALID, "errorCode,Missing keyMgmtType"); |
| 1329 | return 0; |
| 1330 | } |
| 1331 | if (strcasecmp(val, "wpa") == 0 || |
| 1332 | strcasecmp(val, "wpa-psk") == 0) { |
| 1333 | if (set_network(ifname, id, "proto", "WPA") < 0) |
| 1334 | return -2; |
| 1335 | } else if (strcasecmp(val, "wpa2") == 0 || |
| 1336 | strcasecmp(val, "wpa2-psk") == 0 || |
| 1337 | strcasecmp(val, "wpa2-ft") == 0 || |
| 1338 | strcasecmp(val, "wpa2-sha256") == 0) { |
| 1339 | if (set_network(ifname, id, "proto", "WPA2") < 0) |
| 1340 | return -2; |
Pradeep Reddy POTTETI | 6d04b3b | 2016-11-15 14:51:26 +0530 | [diff] [blame] | 1341 | } else if (strcasecmp(val, "wpa2-wpa-psk") == 0 || |
| 1342 | strcasecmp(val, "wpa2-wpa-ent") == 0) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1343 | if (set_network(ifname, id, "proto", "WPA WPA2") < 0) |
| 1344 | return -2; |
Jouni Malinen | ad395a2 | 2017-09-01 21:13:46 +0300 | [diff] [blame] | 1345 | } else if (strcasecmp(val, "SuiteB") == 0) { |
| 1346 | if (set_network(ifname, id, "proto", "WPA2") < 0) |
| 1347 | return -2; |
Jouni Malinen | 47dcc95 | 2017-10-09 16:43:24 +0300 | [diff] [blame] | 1348 | } else if (strcasecmp(val, "OWE") == 0) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1349 | } else { |
| 1350 | send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized keyMgmtType value"); |
| 1351 | return 0; |
| 1352 | } |
| 1353 | |
| 1354 | val = get_param(cmd, "encpType"); |
Jouni Malinen | ad395a2 | 2017-09-01 21:13:46 +0300 | [diff] [blame] | 1355 | if (val) { |
| 1356 | cipher_set = 1; |
| 1357 | if (strcasecmp(val, "tkip") == 0) { |
| 1358 | if (set_network(ifname, id, "pairwise", "TKIP") < 0) |
| 1359 | return -2; |
| 1360 | } else if (strcasecmp(val, "aes-ccmp") == 0) { |
| 1361 | if (set_network(ifname, id, "pairwise", "CCMP") < 0) |
| 1362 | return -2; |
| 1363 | } else if (strcasecmp(val, "aes-ccmp-tkip") == 0) { |
| 1364 | if (set_network(ifname, id, "pairwise", |
| 1365 | "CCMP TKIP") < 0) |
| 1366 | return -2; |
| 1367 | } else if (strcasecmp(val, "aes-gcmp") == 0) { |
| 1368 | if (set_network(ifname, id, "pairwise", "GCMP") < 0) |
| 1369 | return -2; |
| 1370 | if (set_network(ifname, id, "group", "GCMP") < 0) |
| 1371 | return -2; |
| 1372 | } else { |
| 1373 | send_resp(dut, conn, SIGMA_ERROR, |
| 1374 | "errorCode,Unrecognized encpType value"); |
| 1375 | return 0; |
| 1376 | } |
| 1377 | } |
| 1378 | |
| 1379 | val = get_param(cmd, "PairwiseCipher"); |
| 1380 | if (val) { |
| 1381 | cipher_set = 1; |
| 1382 | /* TODO: Support space separated list */ |
| 1383 | if (strcasecmp(val, "AES-GCMP-256") == 0) { |
| 1384 | if (set_network(ifname, id, "pairwise", "GCMP-256") < 0) |
| 1385 | return -2; |
| 1386 | } else if (strcasecmp(val, "AES-CCMP-256") == 0) { |
| 1387 | if (set_network(ifname, id, "pairwise", |
| 1388 | "CCMP-256") < 0) |
| 1389 | return -2; |
| 1390 | } else if (strcasecmp(val, "AES-GCMP-128") == 0) { |
| 1391 | if (set_network(ifname, id, "pairwise", "GCMP") < 0) |
| 1392 | return -2; |
| 1393 | } else if (strcasecmp(val, "AES-CCMP-128") == 0) { |
| 1394 | if (set_network(ifname, id, "pairwise", "CCMP") < 0) |
| 1395 | return -2; |
| 1396 | } else { |
| 1397 | send_resp(dut, conn, SIGMA_ERROR, |
| 1398 | "errorCode,Unrecognized PairwiseCipher value"); |
| 1399 | return 0; |
| 1400 | } |
| 1401 | } |
| 1402 | |
Jouni Malinen | 47dcc95 | 2017-10-09 16:43:24 +0300 | [diff] [blame] | 1403 | if (!cipher_set && !owe) { |
Jouni Malinen | ad395a2 | 2017-09-01 21:13:46 +0300 | [diff] [blame] | 1404 | send_resp(dut, conn, SIGMA_ERROR, |
| 1405 | "errorCode,Missing encpType and PairwiseCipher"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1406 | return 0; |
| 1407 | } |
Jouni Malinen | ad395a2 | 2017-09-01 21:13:46 +0300 | [diff] [blame] | 1408 | |
| 1409 | val = get_param(cmd, "GroupCipher"); |
| 1410 | if (val) { |
| 1411 | if (strcasecmp(val, "AES-GCMP-256") == 0) { |
| 1412 | if (set_network(ifname, id, "group", "GCMP-256") < 0) |
| 1413 | return -2; |
| 1414 | } else if (strcasecmp(val, "AES-CCMP-256") == 0) { |
| 1415 | if (set_network(ifname, id, "group", "CCMP-256") < 0) |
| 1416 | return -2; |
| 1417 | } else if (strcasecmp(val, "AES-GCMP-128") == 0) { |
| 1418 | if (set_network(ifname, id, "group", "GCMP") < 0) |
| 1419 | return -2; |
| 1420 | } else if (strcasecmp(val, "AES-CCMP-128") == 0) { |
| 1421 | if (set_network(ifname, id, "group", "CCMP") < 0) |
| 1422 | return -2; |
| 1423 | } else { |
| 1424 | send_resp(dut, conn, SIGMA_ERROR, |
| 1425 | "errorCode,Unrecognized GroupCipher value"); |
| 1426 | return 0; |
| 1427 | } |
| 1428 | } |
| 1429 | |
Jouni Malinen | 7b23952 | 2017-09-14 21:37:18 +0300 | [diff] [blame] | 1430 | val = get_param(cmd, "GroupMgntCipher"); |
Jouni Malinen | ad395a2 | 2017-09-01 21:13:46 +0300 | [diff] [blame] | 1431 | if (val) { |
Jouni Malinen | e8898cb | 2017-09-26 17:55:26 +0300 | [diff] [blame] | 1432 | const char *cipher; |
| 1433 | |
| 1434 | if (strcasecmp(val, "BIP-GMAC-256") == 0) { |
| 1435 | cipher = "BIP-GMAC-256"; |
| 1436 | } else if (strcasecmp(val, "BIP-CMAC-256") == 0) { |
| 1437 | cipher = "BIP-CMAC-256"; |
| 1438 | } else if (strcasecmp(val, "BIP-GMAC-128") == 0) { |
| 1439 | cipher = "BIP-GMAC-128"; |
| 1440 | } else if (strcasecmp(val, "BIP-CMAC-128") == 0) { |
| 1441 | cipher = "AES-128-CMAC"; |
| 1442 | } else { |
| 1443 | send_resp(dut, conn, SIGMA_INVALID, |
| 1444 | "errorCode,Unsupported GroupMgntCipher"); |
| 1445 | return 0; |
| 1446 | } |
| 1447 | if (set_network(ifname, id, "group_mgmt", cipher) < 0) { |
| 1448 | send_resp(dut, conn, SIGMA_INVALID, |
| 1449 | "errorCode,Failed to set GroupMgntCipher"); |
| 1450 | return 0; |
| 1451 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1452 | } |
| 1453 | |
| 1454 | dut->sta_pmf = STA_PMF_DISABLED; |
vamsi krishna | f39bc1e | 2017-08-23 17:37:53 +0530 | [diff] [blame] | 1455 | |
| 1456 | if (dut->program == PROGRAM_OCE) { |
| 1457 | dut->sta_pmf = STA_PMF_OPTIONAL; |
| 1458 | if (set_network(ifname, id, "ieee80211w", "1") < 0) |
| 1459 | return -2; |
| 1460 | } |
| 1461 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1462 | val = get_param(cmd, "PMF"); |
| 1463 | if (val) { |
| 1464 | if (strcasecmp(val, "Required") == 0 || |
| 1465 | strcasecmp(val, "Forced_Required") == 0) { |
| 1466 | dut->sta_pmf = STA_PMF_REQUIRED; |
| 1467 | if (set_network(ifname, id, "ieee80211w", "2") < 0) |
| 1468 | return -2; |
| 1469 | } else if (strcasecmp(val, "Optional") == 0) { |
| 1470 | dut->sta_pmf = STA_PMF_OPTIONAL; |
| 1471 | if (set_network(ifname, id, "ieee80211w", "1") < 0) |
| 1472 | return -2; |
| 1473 | } else if (strcasecmp(val, "Disabled") == 0 || |
| 1474 | strcasecmp(val, "Forced_Disabled") == 0) { |
| 1475 | dut->sta_pmf = STA_PMF_DISABLED; |
| 1476 | } else { |
| 1477 | send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized PMF value"); |
| 1478 | return 0; |
| 1479 | } |
| 1480 | } |
| 1481 | |
| 1482 | return id; |
| 1483 | } |
| 1484 | |
| 1485 | |
| 1486 | static int cmd_sta_set_psk(struct sigma_dut *dut, struct sigma_conn *conn, |
| 1487 | struct sigma_cmd *cmd) |
| 1488 | { |
| 1489 | const char *intf = get_param(cmd, "Interface"); |
Jouni Malinen | 992a81e | 2017-08-22 13:57:47 +0300 | [diff] [blame] | 1490 | const char *type = get_param(cmd, "Type"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1491 | const char *ifname, *val, *alg; |
| 1492 | int id; |
| 1493 | |
| 1494 | if (intf == NULL) |
| 1495 | return -1; |
| 1496 | |
| 1497 | if (strcmp(intf, get_main_ifname()) == 0) |
| 1498 | ifname = get_station_ifname(); |
| 1499 | else |
| 1500 | ifname = intf; |
| 1501 | |
| 1502 | id = set_wpa_common(dut, conn, ifname, cmd); |
| 1503 | if (id < 0) |
| 1504 | return id; |
| 1505 | |
| 1506 | val = get_param(cmd, "keyMgmtType"); |
| 1507 | alg = get_param(cmd, "micAlg"); |
| 1508 | |
Jouni Malinen | 992a81e | 2017-08-22 13:57:47 +0300 | [diff] [blame] | 1509 | if (type && strcasecmp(type, "SAE") == 0) { |
| 1510 | if (val && strcasecmp(val, "wpa2-ft") == 0) { |
| 1511 | if (set_network(ifname, id, "key_mgmt", "FT-SAE") < 0) |
| 1512 | return -2; |
| 1513 | } else { |
| 1514 | if (set_network(ifname, id, "key_mgmt", "SAE") < 0) |
| 1515 | return -2; |
| 1516 | } |
| 1517 | if (wpa_command(ifname, "SET sae_groups ") != 0) { |
| 1518 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 1519 | "Failed to clear sae_groups to default"); |
| 1520 | return -2; |
| 1521 | } |
Jouni Malinen | 0ab50f4 | 2017-08-31 01:34:59 +0300 | [diff] [blame] | 1522 | } else if (type && strcasecmp(type, "PSK-SAE") == 0) { |
| 1523 | if (val && strcasecmp(val, "wpa2-ft") == 0) { |
| 1524 | if (set_network(ifname, id, "key_mgmt", |
| 1525 | "FT-SAE FT-PSK") < 0) |
| 1526 | return -2; |
| 1527 | } else { |
| 1528 | if (set_network(ifname, id, "key_mgmt", |
| 1529 | "SAE WPA-PSK") < 0) |
| 1530 | return -2; |
| 1531 | } |
| 1532 | if (wpa_command(ifname, "SET sae_groups ") != 0) { |
| 1533 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 1534 | "Failed to clear sae_groups to default"); |
| 1535 | return -2; |
| 1536 | } |
Jouni Malinen | 992a81e | 2017-08-22 13:57:47 +0300 | [diff] [blame] | 1537 | } else if (alg && strcasecmp(alg, "SHA-256") == 0) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1538 | if (set_network(ifname, id, "key_mgmt", "WPA-PSK-SHA256") < 0) |
| 1539 | return -2; |
| 1540 | } else if (alg && strcasecmp(alg, "SHA-1") == 0) { |
| 1541 | if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0) |
| 1542 | return -2; |
Ashwini Patil | 6dbf7b0 | 2017-03-20 13:42:11 +0530 | [diff] [blame] | 1543 | } else if (val && strcasecmp(val, "wpa2-ft") == 0) { |
| 1544 | if (set_network(ifname, id, "key_mgmt", "FT-PSK") < 0) |
| 1545 | return -2; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1546 | } else if ((val && strcasecmp(val, "wpa2-sha256") == 0) || |
| 1547 | dut->sta_pmf == STA_PMF_REQUIRED) { |
| 1548 | if (set_network(ifname, id, "key_mgmt", |
| 1549 | "WPA-PSK WPA-PSK-SHA256") < 0) |
| 1550 | return -2; |
| 1551 | } else if (dut->sta_pmf == STA_PMF_OPTIONAL) { |
| 1552 | if (set_network(ifname, id, "key_mgmt", |
| 1553 | "WPA-PSK WPA-PSK-SHA256") < 0) |
| 1554 | return -2; |
| 1555 | } else { |
| 1556 | if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0) |
| 1557 | return -2; |
| 1558 | } |
| 1559 | |
| 1560 | val = get_param(cmd, "passPhrase"); |
| 1561 | if (val == NULL) |
| 1562 | return -1; |
Jouni Malinen | 2126f42 | 2017-10-11 23:24:33 +0300 | [diff] [blame] | 1563 | if (type && strcasecmp(type, "SAE") == 0) { |
| 1564 | if (set_network_quoted(ifname, id, "sae_password", val) < 0) |
| 1565 | return -2; |
| 1566 | } else { |
| 1567 | if (set_network_quoted(ifname, id, "psk", val) < 0) |
| 1568 | return -2; |
| 1569 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1570 | |
Jouni Malinen | 992a81e | 2017-08-22 13:57:47 +0300 | [diff] [blame] | 1571 | val = get_param(cmd, "ECGroupID"); |
| 1572 | if (val) { |
| 1573 | char buf[50]; |
| 1574 | |
| 1575 | snprintf(buf, sizeof(buf), "SET sae_groups %u", atoi(val)); |
| 1576 | if (wpa_command(ifname, buf) != 0) { |
| 1577 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 1578 | "Failed to clear sae_groups"); |
| 1579 | return -2; |
| 1580 | } |
| 1581 | } |
| 1582 | |
Jouni Malinen | 6814313 | 2017-09-02 02:34:08 +0300 | [diff] [blame] | 1583 | val = get_param(cmd, "InvalidSAEElement"); |
| 1584 | if (val) { |
| 1585 | free(dut->sae_commit_override); |
| 1586 | dut->sae_commit_override = strdup(val); |
| 1587 | } |
| 1588 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1589 | return 1; |
| 1590 | } |
| 1591 | |
| 1592 | |
| 1593 | static int set_eap_common(struct sigma_dut *dut, struct sigma_conn *conn, |
Bala Krishna Bhamidipati | 73d7af0 | 2016-03-24 12:27:56 +0530 | [diff] [blame] | 1594 | const char *ifname, int username_identity, |
| 1595 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1596 | { |
vamsi krishna | f39bc1e | 2017-08-23 17:37:53 +0530 | [diff] [blame] | 1597 | const char *val, *alg, *akm; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1598 | int id; |
| 1599 | char buf[200]; |
| 1600 | #ifdef ANDROID |
| 1601 | unsigned char kvalue[KEYSTORE_MESSAGE_SIZE]; |
| 1602 | int length; |
| 1603 | #endif /* ANDROID */ |
| 1604 | |
| 1605 | id = set_wpa_common(dut, conn, ifname, cmd); |
| 1606 | if (id < 0) |
| 1607 | return id; |
| 1608 | |
| 1609 | val = get_param(cmd, "keyMgmtType"); |
| 1610 | alg = get_param(cmd, "micAlg"); |
vamsi krishna | f39bc1e | 2017-08-23 17:37:53 +0530 | [diff] [blame] | 1611 | akm = get_param(cmd, "AKMSuiteType"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1612 | |
Jouni Malinen | ad395a2 | 2017-09-01 21:13:46 +0300 | [diff] [blame] | 1613 | if (val && strcasecmp(val, "SuiteB") == 0) { |
| 1614 | if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SUITE-B-192") < |
| 1615 | 0) |
| 1616 | return -2; |
| 1617 | } else if (alg && strcasecmp(alg, "SHA-256") == 0) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1618 | if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SHA256") < 0) |
| 1619 | return -2; |
| 1620 | } else if (alg && strcasecmp(alg, "SHA-1") == 0) { |
| 1621 | if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0) |
| 1622 | return -2; |
| 1623 | } else if (val && strcasecmp(val, "wpa2-ft") == 0) { |
| 1624 | if (set_network(ifname, id, "key_mgmt", "FT-EAP") < 0) |
| 1625 | return -2; |
| 1626 | } else if ((val && strcasecmp(val, "wpa2-sha256") == 0) || |
| 1627 | dut->sta_pmf == STA_PMF_REQUIRED) { |
| 1628 | if (set_network(ifname, id, "key_mgmt", |
| 1629 | "WPA-EAP WPA-EAP-SHA256") < 0) |
| 1630 | return -2; |
vamsi krishna | f39bc1e | 2017-08-23 17:37:53 +0530 | [diff] [blame] | 1631 | } else if (akm && atoi(akm) == 14) { |
| 1632 | if (dut->sta_pmf == STA_PMF_OPTIONAL || |
| 1633 | dut->sta_pmf == STA_PMF_REQUIRED) { |
| 1634 | if (set_network(ifname, id, "key_mgmt", |
| 1635 | "WPA-EAP-SHA256 FILS-SHA256") < 0) |
| 1636 | return -2; |
| 1637 | } else { |
| 1638 | if (set_network(ifname, id, "key_mgmt", |
| 1639 | "WPA-EAP FILS-SHA256") < 0) |
| 1640 | return -2; |
| 1641 | } |
| 1642 | |
| 1643 | if (set_network(ifname, id, "erp", "1") < 0) |
| 1644 | return -2; |
| 1645 | } else if (akm && atoi(akm) == 15) { |
| 1646 | if (dut->sta_pmf == STA_PMF_OPTIONAL || |
| 1647 | dut->sta_pmf == STA_PMF_REQUIRED) { |
| 1648 | if (set_network(ifname, id, "key_mgmt", |
| 1649 | "WPA-EAP-SHA256 FILS-SHA384") < 0) |
| 1650 | return -2; |
| 1651 | } else { |
| 1652 | if (set_network(ifname, id, "key_mgmt", |
| 1653 | "WPA-EAP FILS-SHA384") < 0) |
| 1654 | return -2; |
| 1655 | } |
| 1656 | |
| 1657 | if (set_network(ifname, id, "erp", "1") < 0) |
| 1658 | return -2; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1659 | } else if (dut->sta_pmf == STA_PMF_OPTIONAL) { |
| 1660 | if (set_network(ifname, id, "key_mgmt", |
| 1661 | "WPA-EAP WPA-EAP-SHA256") < 0) |
| 1662 | return -2; |
| 1663 | } else { |
| 1664 | if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0) |
| 1665 | return -2; |
| 1666 | } |
| 1667 | |
| 1668 | val = get_param(cmd, "trustedRootCA"); |
| 1669 | if (val) { |
| 1670 | #ifdef ANDROID |
| 1671 | snprintf(buf, sizeof(buf), "CACERT_%s", val); |
| 1672 | length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, |
| 1673 | kvalue); |
| 1674 | if (length > 0) { |
| 1675 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 1676 | "Use Android keystore [%s]", buf); |
| 1677 | snprintf(buf, sizeof(buf), "keystore://CACERT_%s", |
| 1678 | val); |
| 1679 | goto ca_cert_selected; |
| 1680 | } |
| 1681 | #endif /* ANDROID */ |
| 1682 | |
| 1683 | snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val); |
| 1684 | #ifdef __linux__ |
| 1685 | if (!file_exists(buf)) { |
| 1686 | char msg[300]; |
| 1687 | snprintf(msg, sizeof(msg), "ErrorCode,trustedRootCA " |
| 1688 | "file (%s) not found", buf); |
| 1689 | send_resp(dut, conn, SIGMA_ERROR, msg); |
| 1690 | return -3; |
| 1691 | } |
| 1692 | #endif /* __linux__ */ |
| 1693 | #ifdef ANDROID |
| 1694 | ca_cert_selected: |
| 1695 | #endif /* ANDROID */ |
| 1696 | if (set_network_quoted(ifname, id, "ca_cert", buf) < 0) |
| 1697 | return -2; |
| 1698 | } |
| 1699 | |
Bala Krishna Bhamidipati | 73d7af0 | 2016-03-24 12:27:56 +0530 | [diff] [blame] | 1700 | if (username_identity) { |
| 1701 | val = get_param(cmd, "username"); |
| 1702 | if (val) { |
| 1703 | if (set_network_quoted(ifname, id, "identity", val) < 0) |
| 1704 | return -2; |
| 1705 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1706 | |
Bala Krishna Bhamidipati | 73d7af0 | 2016-03-24 12:27:56 +0530 | [diff] [blame] | 1707 | val = get_param(cmd, "password"); |
| 1708 | if (val) { |
| 1709 | if (set_network_quoted(ifname, id, "password", val) < 0) |
| 1710 | return -2; |
| 1711 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1712 | } |
| 1713 | |
| 1714 | return id; |
| 1715 | } |
| 1716 | |
| 1717 | |
Jouni Malinen | 5eabb2a | 2017-10-03 18:17:30 +0300 | [diff] [blame] | 1718 | static int set_tls_cipher(const char *ifname, int id, const char *cipher) |
| 1719 | { |
| 1720 | const char *val; |
| 1721 | |
| 1722 | if (!cipher) |
| 1723 | return 0; |
| 1724 | |
| 1725 | if (strcasecmp(cipher, "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384") == 0) |
| 1726 | val = "ECDHE-ECDSA-AES256-GCM-SHA384"; |
| 1727 | else if (strcasecmp(cipher, |
| 1728 | "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384") == 0) |
| 1729 | val = "ECDHE-RSA-AES256-GCM-SHA384"; |
| 1730 | else if (strcasecmp(cipher, "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384") == 0) |
| 1731 | val = "DHE-RSA-AES256-GCM-SHA384"; |
| 1732 | else if (strcasecmp(cipher, |
| 1733 | "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256") == 0) |
| 1734 | val = "ECDHE-ECDSA-AES128-GCM-SHA256"; |
| 1735 | else |
| 1736 | return -1; |
| 1737 | |
| 1738 | /* Need to clear phase1="tls_suiteb=1" to allow cipher enforcement */ |
| 1739 | set_network_quoted(ifname, id, "phase1", ""); |
| 1740 | |
| 1741 | return set_network_quoted(ifname, id, "openssl_ciphers", val); |
| 1742 | } |
| 1743 | |
| 1744 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1745 | static int cmd_sta_set_eaptls(struct sigma_dut *dut, struct sigma_conn *conn, |
| 1746 | struct sigma_cmd *cmd) |
| 1747 | { |
| 1748 | const char *intf = get_param(cmd, "Interface"); |
| 1749 | const char *ifname, *val; |
| 1750 | int id; |
| 1751 | char buf[200]; |
| 1752 | #ifdef ANDROID |
| 1753 | unsigned char kvalue[KEYSTORE_MESSAGE_SIZE]; |
| 1754 | int length; |
| 1755 | int jb_or_newer = 0; |
| 1756 | char prop[PROPERTY_VALUE_MAX]; |
| 1757 | #endif /* ANDROID */ |
| 1758 | |
| 1759 | if (intf == NULL) |
| 1760 | return -1; |
| 1761 | |
| 1762 | if (strcmp(intf, get_main_ifname()) == 0) |
| 1763 | ifname = get_station_ifname(); |
| 1764 | else |
| 1765 | ifname = intf; |
| 1766 | |
Bala Krishna Bhamidipati | 73d7af0 | 2016-03-24 12:27:56 +0530 | [diff] [blame] | 1767 | id = set_eap_common(dut, conn, ifname, 1, cmd); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1768 | if (id < 0) |
| 1769 | return id; |
| 1770 | |
| 1771 | if (set_network(ifname, id, "eap", "TLS") < 0) |
| 1772 | return -2; |
| 1773 | |
Pradeep Reddy POTTETI | 9f6c213 | 2016-05-05 16:28:19 +0530 | [diff] [blame] | 1774 | if (!get_param(cmd, "username") && |
| 1775 | set_network_quoted(ifname, id, "identity", |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1776 | "wifi-user@wifilabs.local") < 0) |
| 1777 | return -2; |
| 1778 | |
| 1779 | val = get_param(cmd, "clientCertificate"); |
| 1780 | if (val == NULL) |
| 1781 | return -1; |
| 1782 | #ifdef ANDROID |
| 1783 | snprintf(buf, sizeof(buf), "USRPKEY_%s", val); |
| 1784 | length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue); |
| 1785 | if (length < 0) { |
| 1786 | /* |
| 1787 | * JB started reporting keystore type mismatches, so retry with |
| 1788 | * the GET_PUBKEY command if the generic GET fails. |
| 1789 | */ |
| 1790 | length = android_keystore_get(ANDROID_KEYSTORE_GET_PUBKEY, |
| 1791 | buf, kvalue); |
| 1792 | } |
| 1793 | |
| 1794 | if (property_get("ro.build.version.release", prop, NULL) != 0) { |
| 1795 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Android release %s", prop); |
| 1796 | if (strncmp(prop, "4.0", 3) != 0) |
| 1797 | jb_or_newer = 1; |
| 1798 | } else |
| 1799 | jb_or_newer = 1; /* assume newer */ |
| 1800 | |
| 1801 | if (jb_or_newer && length > 0) { |
| 1802 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 1803 | "Use Android keystore [%s]", buf); |
| 1804 | if (set_network(ifname, id, "engine", "1") < 0) |
| 1805 | return -2; |
| 1806 | if (set_network_quoted(ifname, id, "engine_id", "keystore") < 0) |
| 1807 | return -2; |
| 1808 | snprintf(buf, sizeof(buf), "USRPKEY_%s", val); |
| 1809 | if (set_network_quoted(ifname, id, "key_id", buf) < 0) |
| 1810 | return -2; |
| 1811 | snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val); |
| 1812 | if (set_network_quoted(ifname, id, "client_cert", buf) < 0) |
| 1813 | return -2; |
| 1814 | return 1; |
| 1815 | } else if (length > 0) { |
| 1816 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 1817 | "Use Android keystore [%s]", buf); |
| 1818 | snprintf(buf, sizeof(buf), "keystore://USRPKEY_%s", val); |
| 1819 | if (set_network_quoted(ifname, id, "private_key", buf) < 0) |
| 1820 | return -2; |
| 1821 | snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val); |
| 1822 | if (set_network_quoted(ifname, id, "client_cert", buf) < 0) |
| 1823 | return -2; |
| 1824 | return 1; |
| 1825 | } |
| 1826 | #endif /* ANDROID */ |
| 1827 | |
| 1828 | snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val); |
| 1829 | #ifdef __linux__ |
| 1830 | if (!file_exists(buf)) { |
| 1831 | char msg[300]; |
| 1832 | snprintf(msg, sizeof(msg), "ErrorCode,clientCertificate file " |
| 1833 | "(%s) not found", buf); |
| 1834 | send_resp(dut, conn, SIGMA_ERROR, msg); |
| 1835 | return -3; |
| 1836 | } |
| 1837 | #endif /* __linux__ */ |
| 1838 | if (set_network_quoted(ifname, id, "private_key", buf) < 0) |
| 1839 | return -2; |
| 1840 | if (set_network_quoted(ifname, id, "client_cert", buf) < 0) |
| 1841 | return -2; |
| 1842 | |
| 1843 | if (set_network_quoted(ifname, id, "private_key_passwd", "wifi") < 0) |
| 1844 | return -2; |
| 1845 | |
Jouni Malinen | 5eabb2a | 2017-10-03 18:17:30 +0300 | [diff] [blame] | 1846 | val = get_param(cmd, "keyMgmtType"); |
| 1847 | if (val && strcasecmp(val, "SuiteB") == 0) { |
| 1848 | val = get_param(cmd, "CertType"); |
| 1849 | if (val && strcasecmp(val, "RSA") == 0) { |
| 1850 | if (set_network_quoted(ifname, id, "phase1", |
| 1851 | "tls_suiteb=1") < 0) |
| 1852 | return -2; |
| 1853 | } else { |
| 1854 | if (set_network_quoted(ifname, id, "openssl_ciphers", |
| 1855 | "SUITEB192") < 0) |
| 1856 | return -2; |
| 1857 | } |
| 1858 | |
| 1859 | val = get_param(cmd, "TLSCipher"); |
| 1860 | if (set_tls_cipher(ifname, id, val) < 0) { |
| 1861 | send_resp(dut, conn, SIGMA_ERROR, |
| 1862 | "ErrorCode,Unsupported TLSCipher value"); |
| 1863 | return -3; |
| 1864 | } |
| 1865 | } |
| 1866 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1867 | return 1; |
| 1868 | } |
| 1869 | |
| 1870 | |
| 1871 | static int cmd_sta_set_eapttls(struct sigma_dut *dut, struct sigma_conn *conn, |
| 1872 | struct sigma_cmd *cmd) |
| 1873 | { |
| 1874 | const char *intf = get_param(cmd, "Interface"); |
| 1875 | const char *ifname; |
| 1876 | int id; |
| 1877 | |
| 1878 | if (intf == NULL) |
| 1879 | return -1; |
| 1880 | |
| 1881 | if (strcmp(intf, get_main_ifname()) == 0) |
| 1882 | ifname = get_station_ifname(); |
| 1883 | else |
| 1884 | ifname = intf; |
| 1885 | |
Bala Krishna Bhamidipati | 73d7af0 | 2016-03-24 12:27:56 +0530 | [diff] [blame] | 1886 | id = set_eap_common(dut, conn, ifname, 1, cmd); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1887 | if (id < 0) |
| 1888 | return id; |
| 1889 | |
| 1890 | if (set_network(ifname, id, "eap", "TTLS") < 0) { |
| 1891 | send_resp(dut, conn, SIGMA_ERROR, |
| 1892 | "errorCode,Failed to set TTLS method"); |
| 1893 | return 0; |
| 1894 | } |
| 1895 | |
| 1896 | if (set_network_quoted(ifname, id, "phase2", "auth=MSCHAPV2") < 0) { |
| 1897 | send_resp(dut, conn, SIGMA_ERROR, |
| 1898 | "errorCode,Failed to set MSCHAPv2 for TTLS Phase 2"); |
| 1899 | return 0; |
| 1900 | } |
| 1901 | |
| 1902 | return 1; |
| 1903 | } |
| 1904 | |
| 1905 | |
| 1906 | static int cmd_sta_set_eapsim(struct sigma_dut *dut, struct sigma_conn *conn, |
| 1907 | struct sigma_cmd *cmd) |
| 1908 | { |
| 1909 | const char *intf = get_param(cmd, "Interface"); |
| 1910 | const char *ifname; |
| 1911 | int id; |
| 1912 | |
| 1913 | if (intf == NULL) |
| 1914 | return -1; |
| 1915 | |
| 1916 | if (strcmp(intf, get_main_ifname()) == 0) |
| 1917 | ifname = get_station_ifname(); |
| 1918 | else |
| 1919 | ifname = intf; |
| 1920 | |
Bala Krishna Bhamidipati | 73d7af0 | 2016-03-24 12:27:56 +0530 | [diff] [blame] | 1921 | id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1922 | if (id < 0) |
| 1923 | return id; |
| 1924 | |
| 1925 | if (set_network(ifname, id, "eap", "SIM") < 0) |
| 1926 | return -2; |
| 1927 | |
| 1928 | return 1; |
| 1929 | } |
| 1930 | |
| 1931 | |
| 1932 | static int cmd_sta_set_peap(struct sigma_dut *dut, struct sigma_conn *conn, |
| 1933 | struct sigma_cmd *cmd) |
| 1934 | { |
| 1935 | const char *intf = get_param(cmd, "Interface"); |
| 1936 | const char *ifname, *val; |
| 1937 | int id; |
| 1938 | char buf[100]; |
| 1939 | |
| 1940 | if (intf == NULL) |
| 1941 | return -1; |
| 1942 | |
| 1943 | if (strcmp(intf, get_main_ifname()) == 0) |
| 1944 | ifname = get_station_ifname(); |
| 1945 | else |
| 1946 | ifname = intf; |
| 1947 | |
Bala Krishna Bhamidipati | 73d7af0 | 2016-03-24 12:27:56 +0530 | [diff] [blame] | 1948 | id = set_eap_common(dut, conn, ifname, 1, cmd); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1949 | if (id < 0) |
| 1950 | return id; |
| 1951 | |
| 1952 | if (set_network(ifname, id, "eap", "PEAP") < 0) |
| 1953 | return -2; |
| 1954 | |
| 1955 | val = get_param(cmd, "innerEAP"); |
| 1956 | if (val) { |
| 1957 | if (strcasecmp(val, "MSCHAPv2") == 0) { |
| 1958 | if (set_network_quoted(ifname, id, "phase2", |
| 1959 | "auth=MSCHAPV2") < 0) |
| 1960 | return -2; |
| 1961 | } else if (strcasecmp(val, "GTC") == 0) { |
| 1962 | if (set_network_quoted(ifname, id, "phase2", |
| 1963 | "auth=GTC") < 0) |
| 1964 | return -2; |
| 1965 | } else |
| 1966 | return -1; |
| 1967 | } |
| 1968 | |
| 1969 | val = get_param(cmd, "peapVersion"); |
| 1970 | if (val) { |
| 1971 | int ver = atoi(val); |
| 1972 | if (ver < 0 || ver > 1) |
| 1973 | return -1; |
| 1974 | snprintf(buf, sizeof(buf), "peapver=%d", ver); |
| 1975 | if (set_network_quoted(ifname, id, "phase1", buf) < 0) |
| 1976 | return -2; |
| 1977 | } |
| 1978 | |
| 1979 | return 1; |
| 1980 | } |
| 1981 | |
| 1982 | |
| 1983 | static int cmd_sta_set_eapfast(struct sigma_dut *dut, struct sigma_conn *conn, |
| 1984 | struct sigma_cmd *cmd) |
| 1985 | { |
| 1986 | const char *intf = get_param(cmd, "Interface"); |
| 1987 | const char *ifname, *val; |
| 1988 | int id; |
| 1989 | char buf[100]; |
| 1990 | |
| 1991 | if (intf == NULL) |
| 1992 | return -1; |
| 1993 | |
| 1994 | if (strcmp(intf, get_main_ifname()) == 0) |
| 1995 | ifname = get_station_ifname(); |
| 1996 | else |
| 1997 | ifname = intf; |
| 1998 | |
Bala Krishna Bhamidipati | 73d7af0 | 2016-03-24 12:27:56 +0530 | [diff] [blame] | 1999 | id = set_eap_common(dut, conn, ifname, 1, cmd); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2000 | if (id < 0) |
| 2001 | return id; |
| 2002 | |
| 2003 | if (set_network(ifname, id, "eap", "FAST") < 0) |
| 2004 | return -2; |
| 2005 | |
| 2006 | val = get_param(cmd, "innerEAP"); |
| 2007 | if (val) { |
| 2008 | if (strcasecmp(val, "MSCHAPV2") == 0) { |
| 2009 | if (set_network_quoted(ifname, id, "phase2", |
| 2010 | "auth=MSCHAPV2") < 0) |
| 2011 | return -2; |
| 2012 | } else if (strcasecmp(val, "GTC") == 0) { |
| 2013 | if (set_network_quoted(ifname, id, "phase2", |
| 2014 | "auth=GTC") < 0) |
| 2015 | return -2; |
| 2016 | } else |
| 2017 | return -1; |
| 2018 | } |
| 2019 | |
| 2020 | val = get_param(cmd, "validateServer"); |
| 2021 | if (val) { |
| 2022 | /* TODO */ |
| 2023 | sigma_dut_print(dut, DUT_MSG_INFO, "Ignored EAP-FAST " |
| 2024 | "validateServer=%s", val); |
| 2025 | } |
| 2026 | |
| 2027 | val = get_param(cmd, "pacFile"); |
| 2028 | if (val) { |
| 2029 | snprintf(buf, sizeof(buf), "blob://%s", val); |
| 2030 | if (set_network_quoted(ifname, id, "pac_file", buf) < 0) |
| 2031 | return -2; |
| 2032 | } |
| 2033 | |
| 2034 | if (set_network_quoted(ifname, id, "phase1", "fast_provisioning=2") < |
| 2035 | 0) |
| 2036 | return -2; |
| 2037 | |
| 2038 | return 1; |
| 2039 | } |
| 2040 | |
| 2041 | |
| 2042 | static int cmd_sta_set_eapaka(struct sigma_dut *dut, struct sigma_conn *conn, |
| 2043 | struct sigma_cmd *cmd) |
| 2044 | { |
| 2045 | const char *intf = get_param(cmd, "Interface"); |
| 2046 | const char *ifname; |
| 2047 | int id; |
| 2048 | |
| 2049 | if (intf == NULL) |
| 2050 | return -1; |
| 2051 | |
| 2052 | if (strcmp(intf, get_main_ifname()) == 0) |
| 2053 | ifname = get_station_ifname(); |
| 2054 | else |
| 2055 | ifname = intf; |
| 2056 | |
Bala Krishna Bhamidipati | 73d7af0 | 2016-03-24 12:27:56 +0530 | [diff] [blame] | 2057 | id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2058 | if (id < 0) |
| 2059 | return id; |
| 2060 | |
| 2061 | if (set_network(ifname, id, "eap", "AKA") < 0) |
| 2062 | return -2; |
| 2063 | |
| 2064 | return 1; |
| 2065 | } |
| 2066 | |
| 2067 | |
| 2068 | static int cmd_sta_set_eapakaprime(struct sigma_dut *dut, |
| 2069 | struct sigma_conn *conn, |
| 2070 | struct sigma_cmd *cmd) |
| 2071 | { |
| 2072 | const char *intf = get_param(cmd, "Interface"); |
| 2073 | const char *ifname; |
| 2074 | int id; |
| 2075 | |
| 2076 | if (intf == NULL) |
| 2077 | return -1; |
| 2078 | |
| 2079 | if (strcmp(intf, get_main_ifname()) == 0) |
| 2080 | ifname = get_station_ifname(); |
| 2081 | else |
| 2082 | ifname = intf; |
| 2083 | |
Bala Krishna Bhamidipati | 73d7af0 | 2016-03-24 12:27:56 +0530 | [diff] [blame] | 2084 | id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2085 | if (id < 0) |
| 2086 | return id; |
| 2087 | |
| 2088 | if (set_network(ifname, id, "eap", "AKA'") < 0) |
| 2089 | return -2; |
| 2090 | |
| 2091 | return 1; |
| 2092 | } |
| 2093 | |
| 2094 | |
| 2095 | static int sta_set_open(struct sigma_dut *dut, struct sigma_conn *conn, |
| 2096 | struct sigma_cmd *cmd) |
| 2097 | { |
| 2098 | const char *intf = get_param(cmd, "Interface"); |
| 2099 | const char *ifname; |
| 2100 | int id; |
| 2101 | |
| 2102 | if (strcmp(intf, get_main_ifname()) == 0) |
| 2103 | ifname = get_station_ifname(); |
| 2104 | else |
| 2105 | ifname = intf; |
| 2106 | |
| 2107 | id = add_network_common(dut, conn, ifname, cmd); |
| 2108 | if (id < 0) |
| 2109 | return id; |
| 2110 | |
| 2111 | if (set_network(ifname, id, "key_mgmt", "NONE") < 0) |
| 2112 | return -2; |
| 2113 | |
| 2114 | return 1; |
| 2115 | } |
| 2116 | |
| 2117 | |
Jouni Malinen | 47dcc95 | 2017-10-09 16:43:24 +0300 | [diff] [blame] | 2118 | static int sta_set_owe(struct sigma_dut *dut, struct sigma_conn *conn, |
| 2119 | struct sigma_cmd *cmd) |
| 2120 | { |
| 2121 | const char *intf = get_param(cmd, "Interface"); |
| 2122 | const char *ifname, *val; |
| 2123 | int id; |
| 2124 | |
| 2125 | if (intf == NULL) |
| 2126 | return -1; |
| 2127 | |
| 2128 | if (strcmp(intf, get_main_ifname()) == 0) |
| 2129 | ifname = get_station_ifname(); |
| 2130 | else |
| 2131 | ifname = intf; |
| 2132 | |
| 2133 | id = set_wpa_common(dut, conn, ifname, cmd); |
| 2134 | if (id < 0) |
| 2135 | return id; |
| 2136 | |
| 2137 | if (set_network(ifname, id, "key_mgmt", "OWE") < 0) |
| 2138 | return -2; |
| 2139 | |
| 2140 | val = get_param(cmd, "ECGroupID"); |
Jouni Malinen | fac9cad | 2017-10-10 18:35:55 +0300 | [diff] [blame] | 2141 | if (val && strcmp(val, "0") == 0) { |
| 2142 | if (wpa_command(ifname, |
| 2143 | "VENDOR_ELEM_ADD 13 ff23200000783590fb7440e03d5b3b33911f86affdcc6b4411b707846ac4ff08ddc8831ccd") != 0) { |
| 2144 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 2145 | "Failed to set OWE DH Param element override"); |
| 2146 | return -2; |
| 2147 | } |
| 2148 | } else if (val && set_network(ifname, id, "owe_group", val) < 0) { |
Jouni Malinen | 47dcc95 | 2017-10-09 16:43:24 +0300 | [diff] [blame] | 2149 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 2150 | "Failed to clear owe_group"); |
| 2151 | return -2; |
| 2152 | } |
| 2153 | |
| 2154 | return 1; |
| 2155 | } |
| 2156 | |
| 2157 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2158 | static int cmd_sta_set_security(struct sigma_dut *dut, struct sigma_conn *conn, |
| 2159 | struct sigma_cmd *cmd) |
| 2160 | { |
| 2161 | const char *type = get_param(cmd, "Type"); |
| 2162 | |
| 2163 | if (type == NULL) { |
| 2164 | send_resp(dut, conn, SIGMA_ERROR, |
| 2165 | "ErrorCode,Missing Type argument"); |
| 2166 | return 0; |
| 2167 | } |
| 2168 | |
| 2169 | if (strcasecmp(type, "OPEN") == 0) |
| 2170 | return sta_set_open(dut, conn, cmd); |
Jouni Malinen | 47dcc95 | 2017-10-09 16:43:24 +0300 | [diff] [blame] | 2171 | if (strcasecmp(type, "OWE") == 0) |
| 2172 | return sta_set_owe(dut, conn, cmd); |
Jouni Malinen | 992a81e | 2017-08-22 13:57:47 +0300 | [diff] [blame] | 2173 | if (strcasecmp(type, "PSK") == 0 || |
Jouni Malinen | 0ab50f4 | 2017-08-31 01:34:59 +0300 | [diff] [blame] | 2174 | strcasecmp(type, "PSK-SAE") == 0 || |
Jouni Malinen | 992a81e | 2017-08-22 13:57:47 +0300 | [diff] [blame] | 2175 | strcasecmp(type, "SAE") == 0) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2176 | return cmd_sta_set_psk(dut, conn, cmd); |
| 2177 | if (strcasecmp(type, "EAPTLS") == 0) |
| 2178 | return cmd_sta_set_eaptls(dut, conn, cmd); |
| 2179 | if (strcasecmp(type, "EAPTTLS") == 0) |
| 2180 | return cmd_sta_set_eapttls(dut, conn, cmd); |
| 2181 | if (strcasecmp(type, "EAPPEAP") == 0) |
| 2182 | return cmd_sta_set_peap(dut, conn, cmd); |
| 2183 | if (strcasecmp(type, "EAPSIM") == 0) |
| 2184 | return cmd_sta_set_eapsim(dut, conn, cmd); |
| 2185 | if (strcasecmp(type, "EAPFAST") == 0) |
| 2186 | return cmd_sta_set_eapfast(dut, conn, cmd); |
| 2187 | if (strcasecmp(type, "EAPAKA") == 0) |
| 2188 | return cmd_sta_set_eapaka(dut, conn, cmd); |
| 2189 | if (strcasecmp(type, "EAPAKAPRIME") == 0) |
| 2190 | return cmd_sta_set_eapakaprime(dut, conn, cmd); |
| 2191 | |
| 2192 | send_resp(dut, conn, SIGMA_ERROR, |
| 2193 | "ErrorCode,Unsupported Type value"); |
| 2194 | return 0; |
| 2195 | } |
| 2196 | |
| 2197 | |
| 2198 | int ath6kl_client_uapsd(struct sigma_dut *dut, const char *intf, int uapsd) |
| 2199 | { |
| 2200 | #ifdef __linux__ |
| 2201 | /* special handling for ath6kl */ |
| 2202 | char path[128], fname[128], *pos; |
| 2203 | ssize_t res; |
| 2204 | FILE *f; |
| 2205 | |
| 2206 | snprintf(path, sizeof(path), "/sys/class/net/%s/phy80211", intf); |
| 2207 | res = readlink(path, path, sizeof(path)); |
| 2208 | if (res < 0) |
| 2209 | return 0; /* not ath6kl */ |
| 2210 | |
| 2211 | if (res >= (int) sizeof(path)) |
| 2212 | res = sizeof(path) - 1; |
| 2213 | path[res] = '\0'; |
| 2214 | pos = strrchr(path, '/'); |
| 2215 | if (pos == NULL) |
| 2216 | pos = path; |
| 2217 | else |
| 2218 | pos++; |
| 2219 | snprintf(fname, sizeof(fname), |
| 2220 | "/sys/kernel/debug/ieee80211/%s/ath6kl/" |
| 2221 | "create_qos", pos); |
| 2222 | if (!file_exists(fname)) |
| 2223 | return 0; /* not ath6kl */ |
| 2224 | |
| 2225 | if (uapsd) { |
| 2226 | f = fopen(fname, "w"); |
| 2227 | if (f == NULL) |
| 2228 | return -1; |
| 2229 | |
| 2230 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl create_qos"); |
| 2231 | fprintf(f, "4 2 2 1 2 9999999 9999999 9999999 7777777 0 4 " |
| 2232 | "45000 200 56789000 56789000 5678900 0 0 9999999 " |
| 2233 | "20000 0\n"); |
| 2234 | fclose(f); |
| 2235 | } else { |
| 2236 | snprintf(fname, sizeof(fname), |
| 2237 | "/sys/kernel/debug/ieee80211/%s/ath6kl/" |
| 2238 | "delete_qos", pos); |
| 2239 | |
| 2240 | f = fopen(fname, "w"); |
| 2241 | if (f == NULL) |
| 2242 | return -1; |
| 2243 | |
| 2244 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl delete_qos"); |
| 2245 | fprintf(f, "2 4\n"); |
| 2246 | fclose(f); |
| 2247 | } |
| 2248 | #endif /* __linux__ */ |
| 2249 | |
| 2250 | return 0; |
| 2251 | } |
| 2252 | |
| 2253 | |
| 2254 | static int cmd_sta_set_uapsd(struct sigma_dut *dut, struct sigma_conn *conn, |
| 2255 | struct sigma_cmd *cmd) |
| 2256 | { |
| 2257 | const char *intf = get_param(cmd, "Interface"); |
| 2258 | /* const char *ssid = get_param(cmd, "ssid"); */ |
| 2259 | const char *val; |
| 2260 | int max_sp_len = 4; |
| 2261 | int ac_be = 1, ac_bk = 1, ac_vi = 1, ac_vo = 1; |
| 2262 | char buf[100]; |
| 2263 | int ret1, ret2; |
| 2264 | |
| 2265 | val = get_param(cmd, "maxSPLength"); |
| 2266 | if (val) { |
| 2267 | max_sp_len = atoi(val); |
| 2268 | if (max_sp_len != 0 && max_sp_len != 1 && max_sp_len != 2 && |
| 2269 | max_sp_len != 4) |
| 2270 | return -1; |
| 2271 | } |
| 2272 | |
| 2273 | val = get_param(cmd, "acBE"); |
| 2274 | if (val) |
| 2275 | ac_be = atoi(val); |
| 2276 | |
| 2277 | val = get_param(cmd, "acBK"); |
| 2278 | if (val) |
| 2279 | ac_bk = atoi(val); |
| 2280 | |
| 2281 | val = get_param(cmd, "acVI"); |
| 2282 | if (val) |
| 2283 | ac_vi = atoi(val); |
| 2284 | |
| 2285 | val = get_param(cmd, "acVO"); |
| 2286 | if (val) |
| 2287 | ac_vo = atoi(val); |
| 2288 | |
| 2289 | dut->client_uapsd = ac_be || ac_bk || ac_vi || ac_vo; |
| 2290 | |
| 2291 | snprintf(buf, sizeof(buf), "P2P_SET client_apsd %d,%d,%d,%d;%d", |
| 2292 | ac_be, ac_bk, ac_vi, ac_vo, max_sp_len); |
| 2293 | ret1 = wpa_command(intf, buf); |
| 2294 | |
| 2295 | snprintf(buf, sizeof(buf), "SET uapsd %d,%d,%d,%d;%d", |
| 2296 | ac_be, ac_bk, ac_vi, ac_vo, max_sp_len); |
| 2297 | ret2 = wpa_command(intf, buf); |
| 2298 | |
| 2299 | if (ret1 && ret2) { |
| 2300 | sigma_dut_print(dut, DUT_MSG_INFO, "Failed to set client mode " |
| 2301 | "UAPSD parameters."); |
| 2302 | return -2; |
| 2303 | } |
| 2304 | |
| 2305 | if (ath6kl_client_uapsd(dut, intf, dut->client_uapsd) < 0) { |
| 2306 | send_resp(dut, conn, SIGMA_ERROR, |
| 2307 | "ErrorCode,Failed to set ath6kl QoS parameters"); |
| 2308 | return 0; |
| 2309 | } |
| 2310 | |
| 2311 | return 1; |
| 2312 | } |
| 2313 | |
| 2314 | |
| 2315 | static int cmd_sta_set_wmm(struct sigma_dut *dut, struct sigma_conn *conn, |
| 2316 | struct sigma_cmd *cmd) |
| 2317 | { |
| 2318 | char buf[1000]; |
| 2319 | const char *intf = get_param(cmd, "Interface"); |
| 2320 | const char *grp = get_param(cmd, "Group"); |
| 2321 | const char *act = get_param(cmd, "Action"); |
| 2322 | const char *tid = get_param(cmd, "Tid"); |
| 2323 | const char *dir = get_param(cmd, "Direction"); |
| 2324 | const char *psb = get_param(cmd, "Psb"); |
| 2325 | const char *up = get_param(cmd, "Up"); |
| 2326 | const char *fixed = get_param(cmd, "Fixed"); |
| 2327 | const char *size = get_param(cmd, "Size"); |
| 2328 | const char *msize = get_param(cmd, "Maxsize"); |
| 2329 | const char *minsi = get_param(cmd, "Min_srvc_intrvl"); |
| 2330 | const char *maxsi = get_param(cmd, "Max_srvc_intrvl"); |
| 2331 | const char *inact = get_param(cmd, "Inactivity"); |
| 2332 | const char *sus = get_param(cmd, "Suspension"); |
| 2333 | const char *mindr = get_param(cmd, "Mindatarate"); |
| 2334 | const char *meandr = get_param(cmd, "Meandatarate"); |
| 2335 | const char *peakdr = get_param(cmd, "Peakdatarate"); |
| 2336 | const char *phyrate = get_param(cmd, "Phyrate"); |
| 2337 | const char *burstsize = get_param(cmd, "Burstsize"); |
| 2338 | const char *sba = get_param(cmd, "Sba"); |
| 2339 | int direction; |
| 2340 | int handle; |
Peng Xu | 9331962 | 2017-10-04 17:58:16 -0700 | [diff] [blame] | 2341 | float sba_fv = 0; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2342 | int fixed_int; |
| 2343 | int psb_ts; |
| 2344 | |
| 2345 | if (intf == NULL || grp == NULL || act == NULL ) |
| 2346 | return -1; |
| 2347 | |
| 2348 | if (strcasecmp(act, "addts") == 0) { |
| 2349 | if (tid == NULL || dir == NULL || psb == NULL || |
| 2350 | up == NULL || fixed == NULL || size == NULL) |
| 2351 | return -1; |
| 2352 | |
| 2353 | /* |
| 2354 | * Note: Sigma CAPI spec lists uplink, downlink, and bidi as the |
| 2355 | * possible values, but WMM-AC and V-E test scripts use "UP, |
| 2356 | * "DOWN", and "BIDI". |
| 2357 | */ |
| 2358 | if (strcasecmp(dir, "uplink") == 0 || |
| 2359 | strcasecmp(dir, "up") == 0) { |
| 2360 | direction = 0; |
| 2361 | } else if (strcasecmp(dir, "downlink") == 0 || |
| 2362 | strcasecmp(dir, "down") == 0) { |
| 2363 | direction = 1; |
| 2364 | } else if (strcasecmp(dir, "bidi") == 0) { |
| 2365 | direction = 2; |
| 2366 | } else { |
| 2367 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 2368 | "Direction %s not supported", dir); |
| 2369 | return -1; |
| 2370 | } |
| 2371 | |
| 2372 | if (strcasecmp(psb, "legacy") == 0) { |
| 2373 | psb_ts = 0; |
| 2374 | } else if (strcasecmp(psb, "uapsd") == 0) { |
| 2375 | psb_ts = 1; |
| 2376 | } else { |
| 2377 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 2378 | "PSB %s not supported", psb); |
| 2379 | return -1; |
| 2380 | } |
| 2381 | |
| 2382 | if (atoi(tid) < 0 || atoi(tid) > 7) { |
| 2383 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 2384 | "TID %s not supported", tid); |
| 2385 | return -1; |
| 2386 | } |
| 2387 | |
| 2388 | if (strcasecmp(fixed, "true") == 0) { |
| 2389 | fixed_int = 1; |
| 2390 | } else { |
| 2391 | fixed_int = 0; |
| 2392 | } |
| 2393 | |
Peng Xu | 9331962 | 2017-10-04 17:58:16 -0700 | [diff] [blame] | 2394 | if (sba) |
| 2395 | sba_fv = atof(sba); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2396 | |
| 2397 | dut->dialog_token++; |
| 2398 | handle = 7000 + dut->dialog_token; |
| 2399 | |
| 2400 | /* |
| 2401 | * size: convert to hex |
| 2402 | * maxsi: convert to hex |
| 2403 | * mindr: convert to hex |
| 2404 | * meandr: convert to hex |
| 2405 | * peakdr: convert to hex |
| 2406 | * burstsize: convert to hex |
| 2407 | * phyrate: convert to hex |
| 2408 | * sba: convert to hex with modification |
| 2409 | * minsi: convert to integer |
| 2410 | * sus: convert to integer |
| 2411 | * inact: convert to integer |
| 2412 | * maxsi: convert to integer |
| 2413 | */ |
| 2414 | |
| 2415 | /* |
| 2416 | * The Nominal MSDU Size field is 2 octets long and contains an |
| 2417 | * unsigned integer that specifies the nominal size, in octets, |
| 2418 | * of MSDUs belonging to the traffic under this traffic |
| 2419 | * specification and is defined in Figure 16. If the Fixed |
| 2420 | * subfield is set to 1, then the size of the MSDU is fixed and |
| 2421 | * is indicated by the Size Subfield. If the Fixed subfield is |
| 2422 | * set to 0, then the size of the MSDU might not be fixed and |
| 2423 | * the Size indicates the nominal MSDU size. |
| 2424 | * |
| 2425 | * The Surplus Bandwidth Allowance Factor field is 2 octets long |
| 2426 | * and specifies the excess allocation of time (and bandwidth) |
| 2427 | * over and above the stated rates required to transport an MSDU |
| 2428 | * belonging to the traffic in this TSPEC. This field is |
| 2429 | * represented as an unsigned binary number with an implicit |
| 2430 | * binary point after the leftmost 3 bits. For example, an SBA |
| 2431 | * of 1.75 is represented as 0x3800. This field is included to |
| 2432 | * account for retransmissions. As such, the value of this field |
| 2433 | * must be greater than unity. |
| 2434 | */ |
| 2435 | |
| 2436 | snprintf(buf, sizeof(buf), |
| 2437 | "iwpriv %s addTspec %d %s %d %d %s 0x%X" |
| 2438 | " 0x%X 0x%X 0x%X" |
| 2439 | " 0x%X 0x%X 0x%X" |
| 2440 | " 0x%X %d %d %d %d" |
| 2441 | " %d %d", |
| 2442 | intf, handle, tid, direction, psb_ts, up, |
| 2443 | (unsigned int) ((fixed_int << 15) | atoi(size)), |
| 2444 | msize ? atoi(msize) : 0, |
| 2445 | mindr ? atoi(mindr) : 0, |
| 2446 | meandr ? atoi(meandr) : 0, |
| 2447 | peakdr ? atoi(peakdr) : 0, |
| 2448 | burstsize ? atoi(burstsize) : 0, |
| 2449 | phyrate ? atoi(phyrate) : 0, |
| 2450 | sba ? ((unsigned int) (((int) sba_fv << 13) | |
| 2451 | (int)((sba_fv - (int) sba_fv) * |
| 2452 | 8192))) : 0, |
| 2453 | minsi ? atoi(minsi) : 0, |
| 2454 | sus ? atoi(sus) : 0, |
| 2455 | 0, 0, |
| 2456 | inact ? atoi(inact) : 0, |
| 2457 | maxsi ? atoi(maxsi) : 0); |
| 2458 | |
| 2459 | if (system(buf) != 0) { |
| 2460 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 2461 | "iwpriv addtspec request failed"); |
| 2462 | send_resp(dut, conn, SIGMA_ERROR, |
| 2463 | "errorCode,Failed to execute addTspec command"); |
| 2464 | return 0; |
| 2465 | } |
| 2466 | |
| 2467 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 2468 | "iwpriv addtspec request send"); |
| 2469 | |
| 2470 | /* Mapping handle to a TID */ |
| 2471 | dut->tid_to_handle[atoi(tid)] = handle; |
| 2472 | } else if (strcasecmp(act, "delts") == 0) { |
| 2473 | if (tid == NULL) |
| 2474 | return -1; |
| 2475 | |
| 2476 | if (atoi(tid) < 0 || atoi(tid) > 7) { |
| 2477 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 2478 | "TID %s not supported", tid); |
| 2479 | send_resp(dut, conn, SIGMA_ERROR, |
| 2480 | "errorCode,Unsupported TID"); |
| 2481 | return 0; |
| 2482 | } |
| 2483 | |
| 2484 | handle = dut->tid_to_handle[atoi(tid)]; |
| 2485 | |
| 2486 | if (handle < 7000 || handle > 7255) { |
| 2487 | /* Invalid handle ie no mapping for that TID */ |
| 2488 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 2489 | "handle-> %d not found", handle); |
| 2490 | } |
| 2491 | |
| 2492 | snprintf(buf, sizeof(buf), "iwpriv %s delTspec %d", |
| 2493 | intf, handle); |
| 2494 | |
| 2495 | if (system(buf) != 0) { |
| 2496 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 2497 | "iwpriv deltspec request failed"); |
| 2498 | send_resp(dut, conn, SIGMA_ERROR, |
| 2499 | "errorCode,Failed to execute delTspec command"); |
| 2500 | return 0; |
| 2501 | } |
| 2502 | |
| 2503 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 2504 | "iwpriv deltspec request send"); |
| 2505 | |
| 2506 | dut->tid_to_handle[atoi(tid)] = 0; |
| 2507 | } else { |
| 2508 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 2509 | "Action type %s not supported", act); |
| 2510 | send_resp(dut, conn, SIGMA_ERROR, |
| 2511 | "errorCode,Unsupported Action"); |
| 2512 | return 0; |
| 2513 | } |
| 2514 | |
| 2515 | return 1; |
| 2516 | } |
| 2517 | |
| 2518 | |
vamsi krishna | 52e16f9 | 2017-08-29 12:37:34 +0530 | [diff] [blame] | 2519 | static int find_network(struct sigma_dut *dut, const char *ssid) |
| 2520 | { |
| 2521 | char list[4096]; |
| 2522 | char *pos; |
| 2523 | |
| 2524 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 2525 | "Search for profile based on SSID: '%s'", ssid); |
| 2526 | if (wpa_command_resp(get_station_ifname(), "LIST_NETWORKS", |
| 2527 | list, sizeof(list)) < 0) |
| 2528 | return -1; |
| 2529 | pos = strstr(list, ssid); |
| 2530 | if (!pos || pos == list || pos[-1] != '\t' || pos[strlen(ssid)] != '\t') |
| 2531 | return -1; |
| 2532 | |
| 2533 | while (pos > list && pos[-1] != '\n') |
| 2534 | pos--; |
| 2535 | dut->infra_network_id = atoi(pos); |
| 2536 | snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid); |
| 2537 | return 0; |
| 2538 | } |
| 2539 | |
| 2540 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2541 | static int cmd_sta_associate(struct sigma_dut *dut, struct sigma_conn *conn, |
| 2542 | struct sigma_cmd *cmd) |
| 2543 | { |
| 2544 | /* const char *intf = get_param(cmd, "Interface"); */ |
| 2545 | const char *ssid = get_param(cmd, "ssid"); |
| 2546 | const char *wps_param = get_param(cmd, "WPS"); |
| 2547 | const char *bssid = get_param(cmd, "bssid"); |
Jouni Malinen | 46a19b6 | 2017-06-23 14:31:27 +0300 | [diff] [blame] | 2548 | const char *chan = get_param(cmd, "channel"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2549 | int wps = 0; |
Jouni Malinen | 3c367e8 | 2017-06-23 17:01:47 +0300 | [diff] [blame] | 2550 | char buf[1000], extra[50]; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2551 | |
| 2552 | if (ssid == NULL) |
| 2553 | return -1; |
| 2554 | |
Jouni Malinen | 3c367e8 | 2017-06-23 17:01:47 +0300 | [diff] [blame] | 2555 | if (dut->rsne_override) { |
| 2556 | snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s", |
| 2557 | dut->rsne_override); |
| 2558 | if (wpa_command(get_station_ifname(), buf) < 0) { |
| 2559 | send_resp(dut, conn, SIGMA_ERROR, |
| 2560 | "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override"); |
| 2561 | return 0; |
| 2562 | } |
| 2563 | } |
| 2564 | |
Jouni Malinen | 6814313 | 2017-09-02 02:34:08 +0300 | [diff] [blame] | 2565 | if (dut->sae_commit_override) { |
| 2566 | snprintf(buf, sizeof(buf), "SET sae_commit_override %s", |
| 2567 | dut->sae_commit_override); |
| 2568 | if (wpa_command(get_station_ifname(), buf) < 0) { |
| 2569 | send_resp(dut, conn, SIGMA_ERROR, |
| 2570 | "ErrorCode,Failed to set SAE commit override"); |
| 2571 | return 0; |
| 2572 | } |
| 2573 | } |
| 2574 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2575 | if (wps_param && |
| 2576 | (strcmp(wps_param, "1") == 0 || strcasecmp(wps_param, "On") == 0)) |
| 2577 | wps = 1; |
| 2578 | |
| 2579 | if (wps) { |
| 2580 | if (dut->wps_method == WFA_CS_WPS_NOT_READY) { |
| 2581 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,WPS " |
| 2582 | "parameters not yet set"); |
| 2583 | return 0; |
| 2584 | } |
| 2585 | if (dut->wps_method == WFA_CS_WPS_PBC) { |
| 2586 | if (wpa_command(get_station_ifname(), "WPS_PBC") < 0) |
| 2587 | return -2; |
| 2588 | } else { |
| 2589 | snprintf(buf, sizeof(buf), "WPS_PIN any %s", |
| 2590 | dut->wps_pin); |
| 2591 | if (wpa_command(get_station_ifname(), buf) < 0) |
| 2592 | return -2; |
| 2593 | } |
| 2594 | } else { |
vamsi krishna | 52e16f9 | 2017-08-29 12:37:34 +0530 | [diff] [blame] | 2595 | if (strcmp(ssid, dut->infra_ssid) == 0) { |
| 2596 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 2597 | "sta_associate for the most recently added network"); |
| 2598 | } else if (find_network(dut, ssid) < 0) { |
| 2599 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 2600 | "sta_associate for a previously stored network profile"); |
| 2601 | send_resp(dut, conn, SIGMA_ERROR, |
| 2602 | "ErrorCode,Profile not found"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2603 | return 0; |
| 2604 | } |
| 2605 | |
| 2606 | if (bssid && |
| 2607 | set_network(get_station_ifname(), dut->infra_network_id, |
| 2608 | "bssid", bssid) < 0) { |
| 2609 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode," |
| 2610 | "Invalid bssid argument"); |
| 2611 | return 0; |
| 2612 | } |
| 2613 | |
Jouni Malinen | 46a19b6 | 2017-06-23 14:31:27 +0300 | [diff] [blame] | 2614 | extra[0] = '\0'; |
| 2615 | if (chan) |
| 2616 | snprintf(extra, sizeof(extra), " freq=%u", |
| 2617 | channel_to_freq(atoi(chan))); |
| 2618 | snprintf(buf, sizeof(buf), "SELECT_NETWORK %d%s", |
| 2619 | dut->infra_network_id, extra); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2620 | if (wpa_command(get_station_ifname(), buf) < 0) { |
| 2621 | sigma_dut_print(dut, DUT_MSG_INFO, "Failed to select " |
| 2622 | "network id %d on %s", |
| 2623 | dut->infra_network_id, |
| 2624 | get_station_ifname()); |
| 2625 | return -2; |
| 2626 | } |
| 2627 | } |
| 2628 | |
| 2629 | return 1; |
| 2630 | } |
| 2631 | |
| 2632 | |
| 2633 | static int run_hs20_osu(struct sigma_dut *dut, const char *params) |
| 2634 | { |
| 2635 | char buf[500], cmd[200]; |
| 2636 | int res; |
| 2637 | |
| 2638 | /* Use hs20-osu-client file at the current dir, if found; otherwise use |
| 2639 | * default path */ |
| 2640 | res = snprintf(cmd, sizeof(cmd), |
| 2641 | "%s -w \"%s\" -r hs20-osu-client.res %s%s -dddKt -f Logs/hs20-osu-client.txt", |
| 2642 | file_exists("./hs20-osu-client") ? |
| 2643 | "./hs20-osu-client" : "hs20-osu-client", |
| 2644 | sigma_wpas_ctrl, |
| 2645 | dut->summary_log ? "-s " : "", |
| 2646 | dut->summary_log ? dut->summary_log : ""); |
| 2647 | if (res < 0 || res >= (int) sizeof(cmd)) |
| 2648 | return -1; |
| 2649 | |
| 2650 | res = snprintf(buf, sizeof(buf), "%s %s", cmd, params); |
| 2651 | if (res < 0 || res >= (int) sizeof(buf)) |
| 2652 | return -1; |
| 2653 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 2654 | |
| 2655 | if (system(buf) != 0) { |
| 2656 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run: %s", buf); |
| 2657 | return -1; |
| 2658 | } |
| 2659 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 2660 | "Completed hs20-osu-client operation"); |
| 2661 | |
| 2662 | return 0; |
| 2663 | } |
| 2664 | |
| 2665 | |
| 2666 | static int download_ppsmo(struct sigma_dut *dut, |
| 2667 | struct sigma_conn *conn, |
| 2668 | const char *intf, |
| 2669 | struct sigma_cmd *cmd) |
| 2670 | { |
| 2671 | const char *name, *path, *val; |
| 2672 | char url[500], buf[600], fbuf[100]; |
| 2673 | char *fqdn = NULL; |
| 2674 | |
| 2675 | name = get_param(cmd, "FileName"); |
| 2676 | path = get_param(cmd, "FilePath"); |
| 2677 | if (name == NULL || path == NULL) |
| 2678 | return -1; |
| 2679 | |
| 2680 | if (strcasecmp(path, "VendorSpecific") == 0) { |
| 2681 | snprintf(url, sizeof(url), "PPS/%s", name); |
| 2682 | sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured PPS MO " |
| 2683 | "from the device (%s)", url); |
| 2684 | if (!file_exists(url)) { |
| 2685 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested " |
| 2686 | "PPS MO file does not exist"); |
| 2687 | return 0; |
| 2688 | } |
| 2689 | snprintf(buf, sizeof(buf), "cp %s pps-tnds.xml", url); |
| 2690 | if (system(buf) != 0) { |
| 2691 | send_resp(dut, conn, SIGMA_ERROR, |
| 2692 | "errorCode,Failed to copy PPS MO"); |
| 2693 | return 0; |
| 2694 | } |
| 2695 | } else if (strncasecmp(path, "http:", 5) != 0 && |
| 2696 | strncasecmp(path, "https:", 6) != 0) { |
| 2697 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode," |
| 2698 | "Unsupported FilePath value"); |
| 2699 | return 0; |
| 2700 | } else { |
| 2701 | snprintf(url, sizeof(url), "%s/%s", path, name); |
| 2702 | sigma_dut_print(dut, DUT_MSG_INFO, "Downloading PPS MO from %s", |
| 2703 | url); |
| 2704 | snprintf(buf, sizeof(buf), "wget -T 10 -t 3 -O pps-tnds.xml '%s'", url); |
| 2705 | remove("pps-tnds.xml"); |
| 2706 | if (system(buf) != 0) { |
| 2707 | send_resp(dut, conn, SIGMA_ERROR, |
| 2708 | "errorCode,Failed to download PPS MO"); |
| 2709 | return 0; |
| 2710 | } |
| 2711 | } |
| 2712 | |
| 2713 | if (run_hs20_osu(dut, "from_tnds pps-tnds.xml pps.xml") < 0) { |
| 2714 | send_resp(dut, conn, SIGMA_ERROR, |
| 2715 | "errorCode,Failed to parse downloaded PPSMO"); |
| 2716 | return 0; |
| 2717 | } |
| 2718 | unlink("pps-tnds.xml"); |
| 2719 | |
| 2720 | val = get_param(cmd, "managementTreeURI"); |
| 2721 | if (val) { |
| 2722 | const char *pos, *end; |
| 2723 | sigma_dut_print(dut, DUT_MSG_DEBUG, "managementTreeURI: %s", |
| 2724 | val); |
| 2725 | if (strncmp(val, "./Wi-Fi/", 8) != 0) { |
| 2726 | send_resp(dut, conn, SIGMA_ERROR, |
| 2727 | "errorCode,Invalid managementTreeURI prefix"); |
| 2728 | return 0; |
| 2729 | } |
| 2730 | pos = val + 8; |
| 2731 | end = strchr(pos, '/'); |
| 2732 | if (end == NULL || |
| 2733 | strcmp(end, "/PerProviderSubscription") != 0) { |
| 2734 | send_resp(dut, conn, SIGMA_ERROR, |
| 2735 | "errorCode,Invalid managementTreeURI postfix"); |
| 2736 | return 0; |
| 2737 | } |
| 2738 | if (end - pos >= (int) sizeof(fbuf)) { |
| 2739 | send_resp(dut, conn, SIGMA_ERROR, |
| 2740 | "errorCode,Too long FQDN in managementTreeURI"); |
| 2741 | return 0; |
| 2742 | } |
| 2743 | memcpy(fbuf, pos, end - pos); |
| 2744 | fbuf[end - pos] = '\0'; |
| 2745 | fqdn = fbuf; |
| 2746 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 2747 | "FQDN from managementTreeURI: %s", fqdn); |
| 2748 | } else if (run_hs20_osu(dut, "get_fqdn pps.xml") == 0) { |
| 2749 | FILE *f = fopen("pps-fqdn", "r"); |
| 2750 | if (f) { |
| 2751 | if (fgets(fbuf, sizeof(fbuf), f)) { |
| 2752 | fbuf[sizeof(fbuf) - 1] = '\0'; |
| 2753 | fqdn = fbuf; |
| 2754 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 2755 | "Use FQDN %s", fqdn); |
| 2756 | } |
| 2757 | fclose(f); |
| 2758 | } |
| 2759 | } |
| 2760 | |
| 2761 | if (fqdn == NULL) { |
| 2762 | send_resp(dut, conn, SIGMA_ERROR, |
| 2763 | "errorCode,No FQDN specified"); |
| 2764 | return 0; |
| 2765 | } |
| 2766 | |
| 2767 | mkdir("SP", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); |
| 2768 | snprintf(buf, sizeof(buf), "SP/%s", fqdn); |
| 2769 | mkdir(buf, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); |
| 2770 | |
| 2771 | snprintf(buf, sizeof(buf), "SP/%s/pps.xml", fqdn); |
| 2772 | if (rename("pps.xml", buf) < 0) { |
| 2773 | send_resp(dut, conn, SIGMA_ERROR, |
| 2774 | "errorCode,Could not move PPS MO"); |
| 2775 | return 0; |
| 2776 | } |
| 2777 | |
| 2778 | if (strcasecmp(path, "VendorSpecific") == 0) { |
| 2779 | snprintf(buf, sizeof(buf), "cp Certs/ca.pem SP/%s/ca.pem", |
| 2780 | fqdn); |
| 2781 | if (system(buf)) { |
| 2782 | send_resp(dut, conn, SIGMA_ERROR, |
| 2783 | "errorCode,Failed to copy OSU CA cert"); |
| 2784 | return 0; |
| 2785 | } |
| 2786 | |
| 2787 | snprintf(buf, sizeof(buf), |
| 2788 | "cp Certs/aaa-ca.pem SP/%s/aaa-ca.pem", |
| 2789 | fqdn); |
| 2790 | if (system(buf)) { |
| 2791 | send_resp(dut, conn, SIGMA_ERROR, |
| 2792 | "errorCode,Failed to copy AAA CA cert"); |
| 2793 | return 0; |
| 2794 | } |
| 2795 | } else { |
| 2796 | snprintf(buf, sizeof(buf), |
| 2797 | "dl_osu_ca SP/%s/pps.xml SP/%s/ca.pem", |
| 2798 | fqdn, fqdn); |
| 2799 | if (run_hs20_osu(dut, buf) < 0) { |
| 2800 | send_resp(dut, conn, SIGMA_ERROR, |
| 2801 | "errorCode,Failed to download OSU CA cert"); |
| 2802 | return 0; |
| 2803 | } |
| 2804 | |
| 2805 | snprintf(buf, sizeof(buf), |
| 2806 | "dl_aaa_ca SP/%s/pps.xml SP/%s/aaa-ca.pem", |
| 2807 | fqdn, fqdn); |
| 2808 | if (run_hs20_osu(dut, buf) < 0) { |
| 2809 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 2810 | "Failed to download AAA CA cert"); |
| 2811 | } |
| 2812 | } |
| 2813 | |
| 2814 | if (file_exists("next-client-cert.pem")) { |
| 2815 | snprintf(buf, sizeof(buf), "SP/%s/client-cert.pem", fqdn); |
| 2816 | if (rename("next-client-cert.pem", buf) < 0) { |
| 2817 | send_resp(dut, conn, SIGMA_ERROR, |
| 2818 | "errorCode,Could not move client certificate"); |
| 2819 | return 0; |
| 2820 | } |
| 2821 | } |
| 2822 | |
| 2823 | if (file_exists("next-client-key.pem")) { |
| 2824 | snprintf(buf, sizeof(buf), "SP/%s/client-key.pem", fqdn); |
| 2825 | if (rename("next-client-key.pem", buf) < 0) { |
| 2826 | send_resp(dut, conn, SIGMA_ERROR, |
| 2827 | "errorCode,Could not move client key"); |
| 2828 | return 0; |
| 2829 | } |
| 2830 | } |
| 2831 | |
| 2832 | snprintf(buf, sizeof(buf), "set_pps SP/%s/pps.xml", fqdn); |
| 2833 | if (run_hs20_osu(dut, buf) < 0) { |
| 2834 | send_resp(dut, conn, SIGMA_ERROR, |
| 2835 | "errorCode,Failed to configure credential from " |
| 2836 | "PPSMO"); |
| 2837 | return 0; |
| 2838 | } |
| 2839 | |
| 2840 | return 1; |
| 2841 | } |
| 2842 | |
| 2843 | |
| 2844 | static int download_cert(struct sigma_dut *dut, |
| 2845 | struct sigma_conn *conn, |
| 2846 | const char *intf, |
| 2847 | struct sigma_cmd *cmd) |
| 2848 | { |
| 2849 | const char *name, *path; |
| 2850 | char url[500], buf[600]; |
| 2851 | |
| 2852 | name = get_param(cmd, "FileName"); |
| 2853 | path = get_param(cmd, "FilePath"); |
| 2854 | if (name == NULL || path == NULL) |
| 2855 | return -1; |
| 2856 | |
| 2857 | if (strcasecmp(path, "VendorSpecific") == 0) { |
| 2858 | snprintf(url, sizeof(url), "Certs/%s-cert.pem", name); |
| 2859 | sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client " |
| 2860 | "certificate from the device (%s)", url); |
| 2861 | if (!file_exists(url)) { |
| 2862 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested " |
| 2863 | "certificate file does not exist"); |
| 2864 | return 0; |
| 2865 | } |
| 2866 | snprintf(buf, sizeof(buf), "cp %s next-client-cert.pem", url); |
| 2867 | if (system(buf) != 0) { |
| 2868 | send_resp(dut, conn, SIGMA_ERROR, |
| 2869 | "errorCode,Failed to copy client " |
| 2870 | "certificate"); |
| 2871 | return 0; |
| 2872 | } |
| 2873 | |
| 2874 | snprintf(url, sizeof(url), "Certs/%s-key.pem", name); |
| 2875 | sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client " |
| 2876 | "private key from the device (%s)", url); |
| 2877 | if (!file_exists(url)) { |
| 2878 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested " |
| 2879 | "private key file does not exist"); |
| 2880 | return 0; |
| 2881 | } |
| 2882 | snprintf(buf, sizeof(buf), "cp %s next-client-key.pem", url); |
| 2883 | if (system(buf) != 0) { |
| 2884 | send_resp(dut, conn, SIGMA_ERROR, |
| 2885 | "errorCode,Failed to copy client key"); |
| 2886 | return 0; |
| 2887 | } |
| 2888 | } else if (strncasecmp(path, "http:", 5) != 0 && |
| 2889 | strncasecmp(path, "https:", 6) != 0) { |
| 2890 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode," |
| 2891 | "Unsupported FilePath value"); |
| 2892 | return 0; |
| 2893 | } else { |
| 2894 | snprintf(url, sizeof(url), "%s/%s.pem", path, name); |
| 2895 | sigma_dut_print(dut, DUT_MSG_INFO, "Downloading client " |
| 2896 | "certificate/key from %s", url); |
| 2897 | snprintf(buf, sizeof(buf), |
| 2898 | "wget -T 10 -t 3 -O next-client-cert.pem '%s'", url); |
| 2899 | if (system(buf) != 0) { |
| 2900 | send_resp(dut, conn, SIGMA_ERROR, |
| 2901 | "errorCode,Failed to download client " |
| 2902 | "certificate"); |
| 2903 | return 0; |
| 2904 | } |
| 2905 | |
| 2906 | if (system("cp next-client-cert.pem next-client-key.pem") != 0) |
| 2907 | { |
| 2908 | send_resp(dut, conn, SIGMA_ERROR, |
| 2909 | "errorCode,Failed to copy client key"); |
| 2910 | return 0; |
| 2911 | } |
| 2912 | } |
| 2913 | |
| 2914 | return 1; |
| 2915 | } |
| 2916 | |
| 2917 | |
| 2918 | static int cmd_sta_preset_testparameters_hs2_r2(struct sigma_dut *dut, |
| 2919 | struct sigma_conn *conn, |
| 2920 | const char *intf, |
| 2921 | struct sigma_cmd *cmd) |
| 2922 | { |
| 2923 | const char *val; |
| 2924 | |
| 2925 | val = get_param(cmd, "FileType"); |
| 2926 | if (val && strcasecmp(val, "PPSMO") == 0) |
| 2927 | return download_ppsmo(dut, conn, intf, cmd); |
| 2928 | if (val && strcasecmp(val, "CERT") == 0) |
| 2929 | return download_cert(dut, conn, intf, cmd); |
| 2930 | if (val) { |
| 2931 | send_resp(dut, conn, SIGMA_ERROR, |
| 2932 | "ErrorCode,Unsupported FileType"); |
| 2933 | return 0; |
| 2934 | } |
| 2935 | |
| 2936 | return 1; |
| 2937 | } |
| 2938 | |
| 2939 | |
Ankita Bajaj | a2cb567 | 2017-10-25 16:08:28 +0530 | [diff] [blame] | 2940 | static int cmd_sta_preset_testparameters_oce(struct sigma_dut *dut, |
| 2941 | struct sigma_conn *conn, |
| 2942 | const char *intf, |
| 2943 | struct sigma_cmd *cmd) |
| 2944 | { |
| 2945 | const char *val; |
| 2946 | |
| 2947 | val = get_param(cmd, "OCESupport"); |
| 2948 | if (val && strcasecmp(val, "Disable") == 0) { |
| 2949 | if (wpa_command(intf, "SET oce 0") < 0) { |
| 2950 | send_resp(dut, conn, SIGMA_ERROR, |
| 2951 | "ErrorCode,Failed to disable OCE"); |
| 2952 | return 0; |
| 2953 | } |
| 2954 | } else if (val && strcasecmp(val, "Enable") == 0) { |
| 2955 | if (wpa_command(intf, "SET oce 1") < 0) { |
| 2956 | send_resp(dut, conn, SIGMA_ERROR, |
| 2957 | "ErrorCode,Failed to enable OCE"); |
| 2958 | return 0; |
| 2959 | } |
| 2960 | } |
| 2961 | |
| 2962 | return 1; |
| 2963 | } |
| 2964 | |
| 2965 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2966 | static void ath_sta_set_noack(struct sigma_dut *dut, const char *intf, |
| 2967 | const char *val) |
| 2968 | { |
| 2969 | int counter = 0; |
| 2970 | char token[50]; |
| 2971 | char *result; |
| 2972 | char buf[100]; |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 2973 | char *saveptr; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2974 | |
Peng Xu | b8fc5cc | 2017-05-10 17:27:28 -0700 | [diff] [blame] | 2975 | strlcpy(token, val, sizeof(token)); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2976 | token[sizeof(token) - 1] = '\0'; |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 2977 | result = strtok_r(token, ":", &saveptr); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2978 | while (result) { |
| 2979 | if (strcmp(result, "disable") == 0) { |
| 2980 | snprintf(buf, sizeof(buf), |
| 2981 | "iwpriv %s noackpolicy %d 1 0", |
| 2982 | intf, counter); |
| 2983 | } else { |
| 2984 | snprintf(buf, sizeof(buf), |
| 2985 | "iwpriv %s noackpolicy %d 1 1", |
| 2986 | intf, counter); |
| 2987 | } |
| 2988 | if (system(buf) != 0) { |
| 2989 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 2990 | "iwpriv noackpolicy failed"); |
| 2991 | } |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 2992 | result = strtok_r(NULL, ":", &saveptr); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2993 | counter++; |
| 2994 | } |
| 2995 | } |
| 2996 | |
| 2997 | |
| 2998 | static void ath_sta_set_rts(struct sigma_dut *dut, const char *intf, |
| 2999 | const char *val) |
| 3000 | { |
| 3001 | char buf[100]; |
| 3002 | |
| 3003 | snprintf(buf, sizeof(buf), "iwconfig %s rts %s", intf, val); |
| 3004 | if (system(buf) != 0) { |
| 3005 | sigma_dut_print(dut, DUT_MSG_ERROR, "iwconfig RTS failed"); |
| 3006 | } |
| 3007 | } |
| 3008 | |
| 3009 | |
| 3010 | static void ath_sta_set_wmm(struct sigma_dut *dut, const char *intf, |
| 3011 | const char *val) |
| 3012 | { |
| 3013 | char buf[100]; |
| 3014 | |
| 3015 | if (strcasecmp(val, "off") == 0) { |
| 3016 | snprintf(buf, sizeof(buf), "iwpriv %s wmm 0", intf); |
| 3017 | if (system(buf) != 0) { |
| 3018 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3019 | "Failed to turn off WMM"); |
| 3020 | } |
| 3021 | } |
| 3022 | } |
| 3023 | |
| 3024 | |
| 3025 | static void ath_sta_set_sgi(struct sigma_dut *dut, const char *intf, |
| 3026 | const char *val) |
| 3027 | { |
| 3028 | char buf[100]; |
| 3029 | int sgi20; |
| 3030 | |
| 3031 | sgi20 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0; |
| 3032 | |
| 3033 | snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d", intf, sgi20); |
| 3034 | if (system(buf) != 0) |
| 3035 | sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv shortgi failed"); |
| 3036 | } |
| 3037 | |
| 3038 | |
| 3039 | static void ath_sta_set_11nrates(struct sigma_dut *dut, const char *intf, |
| 3040 | const char *val) |
| 3041 | { |
| 3042 | char buf[100]; |
Pradeep Reddy POTTETI | 67376b7 | 2016-10-25 20:08:17 +0530 | [diff] [blame] | 3043 | int rate_code, v; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3044 | |
| 3045 | /* Disable Tx Beam forming when using a fixed rate */ |
| 3046 | ath_disable_txbf(dut, intf); |
| 3047 | |
Pradeep Reddy POTTETI | 67376b7 | 2016-10-25 20:08:17 +0530 | [diff] [blame] | 3048 | v = atoi(val); |
| 3049 | if (v < 0 || v > 32) { |
| 3050 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3051 | "Invalid Fixed MCS rate: %d", v); |
| 3052 | return; |
| 3053 | } |
| 3054 | rate_code = 0x80 + v; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3055 | |
| 3056 | snprintf(buf, sizeof(buf), "iwpriv %s set11NRates 0x%x", |
| 3057 | intf, rate_code); |
| 3058 | if (system(buf) != 0) { |
| 3059 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3060 | "iwpriv set11NRates failed"); |
| 3061 | } |
| 3062 | |
| 3063 | /* Channel width gets messed up, fix this */ |
| 3064 | snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d", intf, dut->chwidth); |
| 3065 | if (system(buf) != 0) |
| 3066 | sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv chwidth failed"); |
| 3067 | } |
| 3068 | |
| 3069 | |
| 3070 | static void ath_sta_set_amsdu(struct sigma_dut *dut, const char *intf, |
| 3071 | const char *val) |
| 3072 | { |
| 3073 | char buf[60]; |
| 3074 | |
| 3075 | if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) |
| 3076 | snprintf(buf, sizeof(buf), "iwpriv %s amsdu 2", intf); |
| 3077 | else |
| 3078 | snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf); |
| 3079 | |
| 3080 | if (system(buf) != 0) |
| 3081 | sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv amsdu failed"); |
| 3082 | } |
| 3083 | |
| 3084 | |
Deepak Dhamdhere | 80356cb | 2016-03-28 16:48:32 -0700 | [diff] [blame] | 3085 | static int iwpriv_sta_set_ampdu(struct sigma_dut *dut, const char *intf, |
| 3086 | int ampdu) |
| 3087 | { |
| 3088 | char buf[60]; |
| 3089 | |
| 3090 | snprintf(buf, sizeof(buf), "iwpriv %s ampdu %d", intf, ampdu); |
| 3091 | if (system(buf) != 0) { |
| 3092 | sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv ampdu failed"); |
| 3093 | return -1; |
| 3094 | } |
| 3095 | |
| 3096 | return 0; |
| 3097 | } |
| 3098 | |
| 3099 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3100 | static void ath_sta_set_stbc(struct sigma_dut *dut, const char *intf, |
| 3101 | const char *val) |
| 3102 | { |
| 3103 | char buf[60]; |
| 3104 | |
| 3105 | snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc %s", intf, val); |
| 3106 | if (system(buf) != 0) { |
| 3107 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3108 | "iwpriv tx_stbc failed"); |
| 3109 | } |
| 3110 | |
| 3111 | snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc %s", intf, val); |
| 3112 | if (system(buf) != 0) { |
| 3113 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3114 | "iwpriv rx_stbc failed"); |
| 3115 | } |
| 3116 | } |
| 3117 | |
| 3118 | |
| 3119 | static int wcn_sta_set_cts_width(struct sigma_dut *dut, const char *intf, |
| 3120 | const char *val) |
| 3121 | { |
| 3122 | char buf[60]; |
| 3123 | |
Peng Xu | cc317ed | 2017-05-18 16:44:37 -0700 | [diff] [blame] | 3124 | if (strcmp(val, "160") == 0) { |
| 3125 | snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 5", intf); |
| 3126 | } else if (strcmp(val, "80") == 0) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3127 | snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf); |
| 3128 | } else if (strcmp(val, "40") == 0) { |
| 3129 | snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 2", intf); |
| 3130 | } else if (strcmp(val, "20") == 0) { |
| 3131 | snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 1", intf); |
| 3132 | } else if (strcasecmp(val, "Auto") == 0) { |
| 3133 | buf[0] = '\0'; |
| 3134 | } else { |
| 3135 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3136 | "WIDTH/CTS_WIDTH value not supported"); |
| 3137 | return -1; |
| 3138 | } |
| 3139 | |
| 3140 | if (buf[0] != '\0' && system(buf) != 0) { |
| 3141 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3142 | "Failed to set WIDTH/CTS_WIDTH"); |
| 3143 | return -1; |
| 3144 | } |
| 3145 | |
| 3146 | return 0; |
| 3147 | } |
| 3148 | |
| 3149 | |
| 3150 | int ath_set_width(struct sigma_dut *dut, struct sigma_conn *conn, |
| 3151 | const char *intf, const char *val) |
| 3152 | { |
| 3153 | char buf[60]; |
| 3154 | |
| 3155 | if (strcasecmp(val, "Auto") == 0) { |
| 3156 | snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf); |
| 3157 | dut->chwidth = 0; |
| 3158 | } else if (strcasecmp(val, "20") == 0) { |
| 3159 | snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf); |
| 3160 | dut->chwidth = 0; |
| 3161 | } else if (strcasecmp(val, "40") == 0) { |
| 3162 | snprintf(buf, sizeof(buf), "iwpriv %s chwidth 1", intf); |
| 3163 | dut->chwidth = 1; |
| 3164 | } else if (strcasecmp(val, "80") == 0) { |
| 3165 | snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf); |
| 3166 | dut->chwidth = 2; |
| 3167 | } else if (strcasecmp(val, "160") == 0) { |
| 3168 | snprintf(buf, sizeof(buf), "iwpriv %s chwidth 3", intf); |
| 3169 | dut->chwidth = 3; |
| 3170 | } else { |
| 3171 | send_resp(dut, conn, SIGMA_ERROR, |
| 3172 | "ErrorCode,WIDTH not supported"); |
| 3173 | return -1; |
| 3174 | } |
| 3175 | |
| 3176 | if (system(buf) != 0) { |
| 3177 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3178 | "iwpriv chwidth failed"); |
| 3179 | } |
| 3180 | |
| 3181 | return 0; |
| 3182 | } |
| 3183 | |
| 3184 | |
| 3185 | static int wcn_sta_set_sp_stream(struct sigma_dut *dut, const char *intf, |
| 3186 | const char *val) |
| 3187 | { |
| 3188 | char buf[60]; |
| 3189 | |
| 3190 | if (strcmp(val, "1SS") == 0) { |
| 3191 | snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf); |
| 3192 | } else if (strcmp(val, "2SS") == 0) { |
| 3193 | snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf); |
| 3194 | } else { |
| 3195 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3196 | "SP_STREAM value not supported"); |
| 3197 | return -1; |
| 3198 | } |
| 3199 | |
| 3200 | if (system(buf) != 0) { |
| 3201 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3202 | "Failed to set SP_STREAM"); |
| 3203 | return -1; |
| 3204 | } |
| 3205 | |
| 3206 | return 0; |
| 3207 | } |
| 3208 | |
| 3209 | |
Pradeep Reddy POTTETI | 4a1f6b3 | 2016-11-23 13:15:21 +0530 | [diff] [blame] | 3210 | static void wcn_sta_set_stbc(struct sigma_dut *dut, const char *intf, |
| 3211 | const char *val) |
| 3212 | { |
| 3213 | char buf[60]; |
| 3214 | |
| 3215 | snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc %s", intf, val); |
| 3216 | if (system(buf) != 0) |
| 3217 | sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv tx_stbc failed"); |
| 3218 | |
| 3219 | snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc %s", intf, val); |
| 3220 | if (system(buf) != 0) |
| 3221 | sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv rx_stbc failed"); |
| 3222 | } |
| 3223 | |
| 3224 | |
Ashwini Patil | 68d02cd | 2017-01-10 15:39:16 +0530 | [diff] [blame] | 3225 | static int mbo_set_cellular_data_capa(struct sigma_dut *dut, |
| 3226 | struct sigma_conn *conn, |
| 3227 | const char *intf, int capa) |
| 3228 | { |
| 3229 | char buf[32]; |
| 3230 | |
| 3231 | if (capa > 0 && capa < 4) { |
| 3232 | snprintf(buf, sizeof(buf), "SET mbo_cell_capa %d", capa); |
| 3233 | if (wpa_command(intf, buf) < 0) { |
| 3234 | send_resp(dut, conn, SIGMA_ERROR, |
| 3235 | "ErrorCode, Failed to set cellular data capability"); |
| 3236 | return 0; |
| 3237 | } |
| 3238 | return 1; |
| 3239 | } |
| 3240 | |
| 3241 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3242 | "Invalid Cellular data capability: %d", capa); |
| 3243 | send_resp(dut, conn, SIGMA_INVALID, |
| 3244 | "ErrorCode,Invalid cellular data capability"); |
| 3245 | return 0; |
| 3246 | } |
| 3247 | |
| 3248 | |
Ashwini Patil | 9183fdb | 2017-04-13 16:58:25 +0530 | [diff] [blame] | 3249 | static int mbo_set_roaming(struct sigma_dut *dut, struct sigma_conn *conn, |
| 3250 | const char *intf, const char *val) |
| 3251 | { |
| 3252 | if (strcasecmp(val, "Disable") == 0) { |
| 3253 | if (wpa_command(intf, "SET roaming 0") < 0) { |
| 3254 | send_resp(dut, conn, SIGMA_ERROR, |
| 3255 | "ErrorCode,Failed to disable roaming"); |
| 3256 | return 0; |
| 3257 | } |
| 3258 | return 1; |
| 3259 | } |
| 3260 | |
| 3261 | if (strcasecmp(val, "Enable") == 0) { |
| 3262 | if (wpa_command(intf, "SET roaming 1") < 0) { |
| 3263 | send_resp(dut, conn, SIGMA_ERROR, |
| 3264 | "ErrorCode,Failed to enable roaming"); |
| 3265 | return 0; |
| 3266 | } |
| 3267 | return 1; |
| 3268 | } |
| 3269 | |
| 3270 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3271 | "Invalid value provided for roaming: %s", val); |
| 3272 | send_resp(dut, conn, SIGMA_INVALID, |
| 3273 | "ErrorCode,Unknown value provided for Roaming"); |
| 3274 | return 0; |
| 3275 | } |
| 3276 | |
| 3277 | |
Ashwini Patil | a75de5a | 2017-04-13 16:35:05 +0530 | [diff] [blame] | 3278 | static int mbo_set_assoc_disallow(struct sigma_dut *dut, |
| 3279 | struct sigma_conn *conn, |
| 3280 | const char *intf, const char *val) |
| 3281 | { |
| 3282 | if (strcasecmp(val, "Disable") == 0) { |
| 3283 | if (wpa_command(intf, "SET ignore_assoc_disallow 1") < 0) { |
| 3284 | send_resp(dut, conn, SIGMA_ERROR, |
| 3285 | "ErrorCode,Failed to disable Assoc_disallow"); |
| 3286 | return 0; |
| 3287 | } |
| 3288 | return 1; |
| 3289 | } |
| 3290 | |
| 3291 | if (strcasecmp(val, "Enable") == 0) { |
| 3292 | if (wpa_command(intf, "SET ignore_assoc_disallow 0") < 0) { |
| 3293 | send_resp(dut, conn, SIGMA_ERROR, |
| 3294 | "ErrorCode,Failed to enable Assoc_disallow"); |
| 3295 | return 0; |
| 3296 | } |
| 3297 | return 1; |
| 3298 | } |
| 3299 | |
| 3300 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3301 | "Invalid value provided for Assoc_disallow: %s", val); |
| 3302 | send_resp(dut, conn, SIGMA_INVALID, |
| 3303 | "ErrorCode,Unknown value provided for Assoc_disallow"); |
| 3304 | return 0; |
| 3305 | } |
| 3306 | |
| 3307 | |
Ashwini Patil | c63161e | 2017-04-13 16:30:23 +0530 | [diff] [blame] | 3308 | static int mbo_set_bss_trans_req(struct sigma_dut *dut, struct sigma_conn *conn, |
| 3309 | const char *intf, const char *val) |
| 3310 | { |
| 3311 | if (strcasecmp(val, "Reject") == 0) { |
| 3312 | if (wpa_command(intf, "SET reject_btm_req_reason 1") < 0) { |
| 3313 | send_resp(dut, conn, SIGMA_ERROR, |
| 3314 | "ErrorCode,Failed to Reject BTM Request"); |
| 3315 | return 0; |
| 3316 | } |
| 3317 | return 1; |
| 3318 | } |
| 3319 | |
| 3320 | if (strcasecmp(val, "Accept") == 0) { |
| 3321 | if (wpa_command(intf, "SET reject_btm_req_reason 0") < 0) { |
| 3322 | send_resp(dut, conn, SIGMA_ERROR, |
| 3323 | "ErrorCode,Failed to Accept BTM Request"); |
| 3324 | return 0; |
| 3325 | } |
| 3326 | return 1; |
| 3327 | } |
| 3328 | |
| 3329 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3330 | "Invalid value provided for BSS_Transition: %s", val); |
| 3331 | send_resp(dut, conn, SIGMA_INVALID, |
| 3332 | "ErrorCode,Unknown value provided for BSS_Transition"); |
| 3333 | return 0; |
| 3334 | } |
| 3335 | |
| 3336 | |
Ashwini Patil | 0040258 | 2017-04-13 12:29:39 +0530 | [diff] [blame] | 3337 | static int mbo_set_non_pref_ch_list(struct sigma_dut *dut, |
| 3338 | struct sigma_conn *conn, |
| 3339 | const char *intf, |
| 3340 | struct sigma_cmd *cmd) |
| 3341 | { |
| 3342 | const char *ch, *pref, *op_class, *reason; |
| 3343 | char buf[120]; |
| 3344 | int len, ret; |
| 3345 | |
| 3346 | pref = get_param(cmd, "Ch_Pref"); |
| 3347 | if (!pref) |
| 3348 | return 1; |
| 3349 | |
| 3350 | if (strcasecmp(pref, "clear") == 0) { |
| 3351 | free(dut->non_pref_ch_list); |
| 3352 | dut->non_pref_ch_list = NULL; |
| 3353 | } else { |
| 3354 | op_class = get_param(cmd, "Ch_Op_Class"); |
| 3355 | if (!op_class) { |
| 3356 | send_resp(dut, conn, SIGMA_INVALID, |
| 3357 | "ErrorCode,Ch_Op_Class not provided"); |
| 3358 | return 0; |
| 3359 | } |
| 3360 | |
| 3361 | ch = get_param(cmd, "Ch_Pref_Num"); |
| 3362 | if (!ch) { |
| 3363 | send_resp(dut, conn, SIGMA_INVALID, |
| 3364 | "ErrorCode,Ch_Pref_Num not provided"); |
| 3365 | return 0; |
| 3366 | } |
| 3367 | |
| 3368 | reason = get_param(cmd, "Ch_Reason_Code"); |
| 3369 | if (!reason) { |
| 3370 | send_resp(dut, conn, SIGMA_INVALID, |
| 3371 | "ErrorCode,Ch_Reason_Code not provided"); |
| 3372 | return 0; |
| 3373 | } |
| 3374 | |
| 3375 | if (!dut->non_pref_ch_list) { |
| 3376 | dut->non_pref_ch_list = |
| 3377 | calloc(1, NON_PREF_CH_LIST_SIZE); |
| 3378 | if (!dut->non_pref_ch_list) { |
| 3379 | send_resp(dut, conn, SIGMA_ERROR, |
| 3380 | "ErrorCode,Failed to allocate memory for non_pref_ch_list"); |
| 3381 | return 0; |
| 3382 | } |
| 3383 | } |
| 3384 | len = strlen(dut->non_pref_ch_list); |
| 3385 | ret = snprintf(dut->non_pref_ch_list + len, |
| 3386 | NON_PREF_CH_LIST_SIZE - len, |
| 3387 | " %s:%s:%s:%s", op_class, ch, pref, reason); |
| 3388 | if (ret > 0 && ret < NON_PREF_CH_LIST_SIZE - len) { |
| 3389 | sigma_dut_print(dut, DUT_MSG_DEBUG, "non_pref_list: %s", |
| 3390 | dut->non_pref_ch_list); |
| 3391 | } else { |
| 3392 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3393 | "snprintf failed for non_pref_list, ret = %d", |
| 3394 | ret); |
| 3395 | send_resp(dut, conn, SIGMA_ERROR, |
| 3396 | "ErrorCode,snprintf failed"); |
| 3397 | free(dut->non_pref_ch_list); |
| 3398 | dut->non_pref_ch_list = NULL; |
| 3399 | return 0; |
| 3400 | } |
| 3401 | } |
| 3402 | |
| 3403 | ret = snprintf(buf, sizeof(buf), "SET non_pref_chan%s", |
| 3404 | dut->non_pref_ch_list ? dut->non_pref_ch_list : " "); |
| 3405 | if (ret < 0 || ret >= (int) sizeof(buf)) { |
| 3406 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 3407 | "snprintf failed for set non_pref_chan, ret: %d", |
| 3408 | ret); |
| 3409 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,snprint failed"); |
| 3410 | return 0; |
| 3411 | } |
| 3412 | |
| 3413 | if (wpa_command(intf, buf) < 0) { |
| 3414 | send_resp(dut, conn, SIGMA_ERROR, |
| 3415 | "ErrorCode,Failed to set non-preferred channel list"); |
| 3416 | return 0; |
| 3417 | } |
| 3418 | |
| 3419 | return 1; |
| 3420 | } |
| 3421 | |
| 3422 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3423 | static int cmd_sta_preset_testparameters(struct sigma_dut *dut, |
| 3424 | struct sigma_conn *conn, |
| 3425 | struct sigma_cmd *cmd) |
| 3426 | { |
| 3427 | const char *intf = get_param(cmd, "Interface"); |
| 3428 | const char *val; |
| 3429 | |
| 3430 | val = get_param(cmd, "Program"); |
Peng Xu | e9fa795 | 2017-05-09 15:59:49 -0700 | [diff] [blame] | 3431 | if (val && strcasecmp(val, "HS2-R2") == 0) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3432 | return cmd_sta_preset_testparameters_hs2_r2(dut, conn, intf, |
| 3433 | cmd); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3434 | |
priyadharshini gowthaman | d66913a | 2016-07-29 15:11:17 -0700 | [diff] [blame] | 3435 | if (val && strcasecmp(val, "LOC") == 0) |
| 3436 | return loc_cmd_sta_preset_testparameters(dut, conn, cmd); |
| 3437 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3438 | #ifdef ANDROID_NAN |
| 3439 | if (val && strcasecmp(val, "NAN") == 0) |
| 3440 | return nan_cmd_sta_preset_testparameters(dut, conn, cmd); |
| 3441 | #endif /* ANDROID_NAN */ |
Amarnath Hullur Subramanyam | 9c381f5 | 2017-03-17 00:04:41 -0700 | [diff] [blame] | 3442 | #ifdef MIRACAST |
| 3443 | if (val && (strcasecmp(val, "WFD") == 0 || |
| 3444 | strcasecmp(val, "DisplayR2") == 0)) |
| 3445 | return miracast_preset_testparameters(dut, conn, cmd); |
| 3446 | #endif /* MIRACAST */ |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3447 | |
Ashwini Patil | 68d02cd | 2017-01-10 15:39:16 +0530 | [diff] [blame] | 3448 | if (val && strcasecmp(val, "MBO") == 0) { |
| 3449 | val = get_param(cmd, "Cellular_Data_Cap"); |
| 3450 | if (val && |
| 3451 | mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0) |
| 3452 | return 0; |
Ashwini Patil | 0040258 | 2017-04-13 12:29:39 +0530 | [diff] [blame] | 3453 | |
| 3454 | val = get_param(cmd, "Ch_Pref"); |
| 3455 | if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0) |
| 3456 | return 0; |
| 3457 | |
Ashwini Patil | c63161e | 2017-04-13 16:30:23 +0530 | [diff] [blame] | 3458 | val = get_param(cmd, "BSS_Transition"); |
| 3459 | if (val && mbo_set_bss_trans_req(dut, conn, intf, val) == 0) |
| 3460 | return 0; |
| 3461 | |
Ashwini Patil | a75de5a | 2017-04-13 16:35:05 +0530 | [diff] [blame] | 3462 | val = get_param(cmd, "Assoc_Disallow"); |
| 3463 | if (val && mbo_set_assoc_disallow(dut, conn, intf, val) == 0) |
| 3464 | return 0; |
| 3465 | |
Ashwini Patil | 9183fdb | 2017-04-13 16:58:25 +0530 | [diff] [blame] | 3466 | val = get_param(cmd, "Roaming"); |
| 3467 | if (val && mbo_set_roaming(dut, conn, intf, val) == 0) |
| 3468 | return 0; |
| 3469 | |
Ashwini Patil | 68d02cd | 2017-01-10 15:39:16 +0530 | [diff] [blame] | 3470 | return 1; |
| 3471 | } |
| 3472 | |
Ankita Bajaj | a2cb567 | 2017-10-25 16:08:28 +0530 | [diff] [blame] | 3473 | if (val && strcasecmp(val, "OCE") == 0) |
| 3474 | return cmd_sta_preset_testparameters_oce(dut, conn, intf, cmd); |
| 3475 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3476 | #if 0 |
| 3477 | val = get_param(cmd, "Supplicant"); |
| 3478 | if (val && strcasecmp(val, "Default") != 0) { |
| 3479 | send_resp(dut, conn, SIGMA_ERROR, |
| 3480 | "ErrorCode,Only default(Vendor) supplicant " |
| 3481 | "supported"); |
| 3482 | return 0; |
| 3483 | } |
| 3484 | #endif |
| 3485 | |
| 3486 | val = get_param(cmd, "RTS"); |
| 3487 | if (val) { |
| 3488 | switch (get_driver_type()) { |
| 3489 | case DRIVER_ATHEROS: |
| 3490 | ath_sta_set_rts(dut, intf, val); |
| 3491 | break; |
| 3492 | default: |
| 3493 | #if 0 |
| 3494 | send_resp(dut, conn, SIGMA_ERROR, |
| 3495 | "ErrorCode,Setting RTS not supported"); |
| 3496 | return 0; |
| 3497 | #else |
| 3498 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 3499 | "Setting RTS not supported"); |
| 3500 | break; |
| 3501 | #endif |
| 3502 | } |
| 3503 | } |
| 3504 | |
| 3505 | #if 0 |
| 3506 | val = get_param(cmd, "FRGMNT"); |
| 3507 | if (val) { |
| 3508 | /* TODO */ |
| 3509 | send_resp(dut, conn, SIGMA_ERROR, |
| 3510 | "ErrorCode,Setting FRGMNT not supported"); |
| 3511 | return 0; |
| 3512 | } |
| 3513 | #endif |
| 3514 | |
| 3515 | #if 0 |
| 3516 | val = get_param(cmd, "Preamble"); |
| 3517 | if (val) { |
| 3518 | /* TODO: Long/Short */ |
| 3519 | send_resp(dut, conn, SIGMA_ERROR, |
| 3520 | "ErrorCode,Setting Preamble not supported"); |
| 3521 | return 0; |
| 3522 | } |
| 3523 | #endif |
| 3524 | |
| 3525 | val = get_param(cmd, "Mode"); |
| 3526 | if (val) { |
| 3527 | if (strcmp(val, "11b") == 0 || |
| 3528 | strcmp(val, "11g") == 0 || |
| 3529 | strcmp(val, "11a") == 0 || |
| 3530 | strcmp(val, "11n") == 0 || |
| 3531 | strcmp(val, "11ng") == 0 || |
| 3532 | strcmp(val, "11nl") == 0 || |
| 3533 | strcmp(val, "11nl(nabg)") == 0 || |
| 3534 | strcmp(val, "AC") == 0 || |
| 3535 | strcmp(val, "11AC") == 0 || |
| 3536 | strcmp(val, "11ac") == 0 || |
| 3537 | strcmp(val, "11na") == 0 || |
| 3538 | strcmp(val, "11an") == 0) { |
| 3539 | /* STA supports all modes by default */ |
| 3540 | } else { |
| 3541 | send_resp(dut, conn, SIGMA_ERROR, |
| 3542 | "ErrorCode,Setting Mode not supported"); |
| 3543 | return 0; |
| 3544 | } |
| 3545 | } |
| 3546 | |
| 3547 | val = get_param(cmd, "wmm"); |
| 3548 | if (val) { |
| 3549 | switch (get_driver_type()) { |
| 3550 | case DRIVER_ATHEROS: |
| 3551 | ath_sta_set_wmm(dut, intf, val); |
| 3552 | break; |
| 3553 | default: |
| 3554 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 3555 | "Setting wmm not supported"); |
| 3556 | break; |
| 3557 | } |
| 3558 | } |
| 3559 | |
| 3560 | val = get_param(cmd, "Powersave"); |
| 3561 | if (val) { |
| 3562 | if (strcmp(val, "0") == 0 || strcasecmp(val, "off") == 0) { |
| 3563 | if (wpa_command(get_station_ifname(), |
| 3564 | "P2P_SET ps 0") < 0) |
| 3565 | return -2; |
| 3566 | /* Make sure test modes are disabled */ |
| 3567 | wpa_command(get_station_ifname(), "P2P_SET ps 98"); |
| 3568 | wpa_command(get_station_ifname(), "P2P_SET ps 96"); |
| 3569 | } else if (strcmp(val, "1") == 0 || |
| 3570 | strcasecmp(val, "PSPoll") == 0 || |
| 3571 | strcasecmp(val, "on") == 0) { |
| 3572 | /* Disable default power save mode */ |
| 3573 | wpa_command(get_station_ifname(), "P2P_SET ps 0"); |
| 3574 | /* Enable PS-Poll test mode */ |
| 3575 | if (wpa_command(get_station_ifname(), |
| 3576 | "P2P_SET ps 97") < 0 || |
| 3577 | wpa_command(get_station_ifname(), |
| 3578 | "P2P_SET ps 99") < 0) |
| 3579 | return -2; |
| 3580 | } else if (strcmp(val, "2") == 0 || |
| 3581 | strcasecmp(val, "Fast") == 0) { |
| 3582 | /* TODO */ |
| 3583 | send_resp(dut, conn, SIGMA_ERROR, |
| 3584 | "ErrorCode,Powersave=Fast not supported"); |
| 3585 | return 0; |
| 3586 | } else if (strcmp(val, "3") == 0 || |
| 3587 | strcasecmp(val, "PSNonPoll") == 0) { |
| 3588 | /* Make sure test modes are disabled */ |
| 3589 | wpa_command(get_station_ifname(), "P2P_SET ps 98"); |
| 3590 | wpa_command(get_station_ifname(), "P2P_SET ps 96"); |
| 3591 | |
| 3592 | /* Enable default power save mode */ |
| 3593 | if (wpa_command(get_station_ifname(), |
| 3594 | "P2P_SET ps 1") < 0) |
| 3595 | return -2; |
| 3596 | } else |
| 3597 | return -1; |
| 3598 | } |
| 3599 | |
| 3600 | val = get_param(cmd, "NoAck"); |
| 3601 | if (val) { |
| 3602 | switch (get_driver_type()) { |
| 3603 | case DRIVER_ATHEROS: |
| 3604 | ath_sta_set_noack(dut, intf, val); |
| 3605 | break; |
| 3606 | default: |
| 3607 | send_resp(dut, conn, SIGMA_ERROR, |
| 3608 | "ErrorCode,Setting NoAck not supported"); |
| 3609 | return 0; |
| 3610 | } |
| 3611 | } |
| 3612 | |
| 3613 | val = get_param(cmd, "IgnoreChswitchProhibit"); |
| 3614 | if (val) { |
| 3615 | /* TODO: Enabled/disabled */ |
| 3616 | if (strcasecmp(val, "Enabled") == 0) { |
| 3617 | send_resp(dut, conn, SIGMA_ERROR, |
| 3618 | "ErrorCode,Enabling IgnoreChswitchProhibit " |
| 3619 | "not supported"); |
| 3620 | return 0; |
| 3621 | } |
| 3622 | } |
| 3623 | |
| 3624 | val = get_param(cmd, "TDLS"); |
| 3625 | if (val) { |
| 3626 | if (strcasecmp(val, "Disabled") == 0) { |
| 3627 | if (wpa_command(intf, "SET tdls_disabled 1")) { |
| 3628 | send_resp(dut, conn, SIGMA_ERROR, |
| 3629 | "ErrorCode,Failed to disable TDLS"); |
| 3630 | return 0; |
| 3631 | } |
| 3632 | } else if (strcasecmp(val, "Enabled") == 0) { |
| 3633 | if (wpa_command(intf, "SET tdls_disabled 0")) { |
| 3634 | send_resp(dut, conn, SIGMA_ERROR, |
| 3635 | "ErrorCode,Failed to enable TDLS"); |
| 3636 | return 0; |
| 3637 | } |
| 3638 | } else { |
| 3639 | send_resp(dut, conn, SIGMA_ERROR, |
| 3640 | "ErrorCode,Unsupported TDLS value"); |
| 3641 | return 0; |
| 3642 | } |
| 3643 | } |
| 3644 | |
| 3645 | val = get_param(cmd, "TDLSmode"); |
| 3646 | if (val) { |
| 3647 | if (strcasecmp(val, "Default") == 0) { |
| 3648 | wpa_command(intf, "SET tdls_testing 0"); |
| 3649 | } else if (strcasecmp(val, "APProhibit") == 0) { |
| 3650 | if (wpa_command(intf, "SET tdls_testing 0x400")) { |
| 3651 | send_resp(dut, conn, SIGMA_ERROR, |
| 3652 | "ErrorCode,Failed to enable ignore " |
| 3653 | "APProhibit TDLS mode"); |
| 3654 | return 0; |
| 3655 | } |
| 3656 | } else if (strcasecmp(val, "HiLoMac") == 0) { |
| 3657 | /* STA should respond with TDLS setup req for a TDLS |
| 3658 | * setup req */ |
| 3659 | if (wpa_command(intf, "SET tdls_testing 0x80")) { |
| 3660 | send_resp(dut, conn, SIGMA_ERROR, |
| 3661 | "ErrorCode,Failed to enable HiLoMac " |
| 3662 | "TDLS mode"); |
| 3663 | return 0; |
| 3664 | } |
| 3665 | } else if (strcasecmp(val, "WeakSecurity") == 0) { |
| 3666 | /* |
| 3667 | * Since all security modes are enabled by default when |
| 3668 | * Sigma control is used, there is no need to do |
| 3669 | * anything here. |
| 3670 | */ |
| 3671 | } else if (strcasecmp(val, "ExistLink") == 0) { |
| 3672 | /* |
| 3673 | * Since we allow new TDLS Setup Request even if there |
| 3674 | * is an existing link, nothing needs to be done for |
| 3675 | * this. |
| 3676 | */ |
| 3677 | } else { |
| 3678 | /* TODO: |
| 3679 | * ExistLink: STA should send TDLS setup req even if |
| 3680 | * direct link already exists |
| 3681 | */ |
| 3682 | send_resp(dut, conn, SIGMA_ERROR, |
| 3683 | "ErrorCode,Unsupported TDLSmode value"); |
| 3684 | return 0; |
| 3685 | } |
| 3686 | } |
| 3687 | |
| 3688 | val = get_param(cmd, "FakePubKey"); |
| 3689 | if (val && atoi(val) && wpa_command(intf, "SET wps_corrupt_pkhash 1")) { |
| 3690 | send_resp(dut, conn, SIGMA_ERROR, |
| 3691 | "ErrorCode,Failed to enable FakePubKey"); |
| 3692 | return 0; |
| 3693 | } |
| 3694 | |
| 3695 | return 1; |
| 3696 | } |
| 3697 | |
| 3698 | |
| 3699 | static const char * ath_get_radio_name(const char *radio_name) |
| 3700 | { |
| 3701 | if (radio_name == NULL) |
| 3702 | return "wifi0"; |
| 3703 | if (strcmp(radio_name, "wifi1") == 0) |
| 3704 | return "wifi1"; |
| 3705 | if (strcmp(radio_name, "wifi2") == 0) |
| 3706 | return "wifi2"; |
| 3707 | return "wifi0"; |
| 3708 | } |
| 3709 | |
| 3710 | |
| 3711 | static void ath_sta_set_txsp_stream(struct sigma_dut *dut, const char *intf, |
| 3712 | const char *val) |
| 3713 | { |
| 3714 | char buf[60]; |
| 3715 | unsigned int vht_mcsmap = 0; |
| 3716 | int txchainmask = 0; |
| 3717 | const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]); |
| 3718 | |
| 3719 | if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) { |
| 3720 | if (dut->testbed_flag_txsp == 1) { |
| 3721 | vht_mcsmap = 0xfffc; |
| 3722 | dut->testbed_flag_txsp = 0; |
| 3723 | } else { |
| 3724 | vht_mcsmap = 0xfffe; |
| 3725 | } |
| 3726 | txchainmask = 1; |
| 3727 | } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) { |
| 3728 | if (dut->testbed_flag_txsp == 1) { |
| 3729 | vht_mcsmap = 0xfff0; |
| 3730 | dut->testbed_flag_txsp = 0; |
| 3731 | } else { |
| 3732 | vht_mcsmap = 0xfffa; |
| 3733 | } |
| 3734 | txchainmask = 3; |
| 3735 | } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) { |
| 3736 | if (dut->testbed_flag_txsp == 1) { |
| 3737 | vht_mcsmap = 0xffc0; |
| 3738 | dut->testbed_flag_txsp = 0; |
| 3739 | } else { |
| 3740 | vht_mcsmap = 0xffea; |
| 3741 | } |
| 3742 | txchainmask = 7; |
| 3743 | } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) { |
| 3744 | if (dut->testbed_flag_txsp == 1) { |
| 3745 | vht_mcsmap = 0xff00; |
| 3746 | dut->testbed_flag_txsp = 0; |
| 3747 | } else { |
| 3748 | vht_mcsmap = 0xffaa; |
| 3749 | } |
| 3750 | txchainmask = 15; |
| 3751 | } else { |
| 3752 | if (dut->testbed_flag_txsp == 1) { |
| 3753 | vht_mcsmap = 0xffc0; |
| 3754 | dut->testbed_flag_txsp = 0; |
| 3755 | } else { |
| 3756 | vht_mcsmap = 0xffea; |
| 3757 | } |
| 3758 | } |
| 3759 | |
| 3760 | if (txchainmask) { |
| 3761 | snprintf(buf, sizeof(buf), "iwpriv %s txchainmask %d", |
| 3762 | basedev, txchainmask); |
| 3763 | if (system(buf) != 0) { |
| 3764 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3765 | "iwpriv txchainmask failed"); |
| 3766 | } |
| 3767 | } |
| 3768 | |
| 3769 | snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0x%04x", |
| 3770 | intf, vht_mcsmap); |
| 3771 | if (system(buf) != 0) { |
| 3772 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3773 | "iwpriv %s vht_mcsmap 0x%04x failed", |
| 3774 | intf, vht_mcsmap); |
| 3775 | } |
| 3776 | } |
| 3777 | |
| 3778 | |
| 3779 | static void ath_sta_set_rxsp_stream(struct sigma_dut *dut, const char *intf, |
| 3780 | const char *val) |
| 3781 | { |
| 3782 | char buf[60]; |
| 3783 | unsigned int vht_mcsmap = 0; |
| 3784 | int rxchainmask = 0; |
| 3785 | const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]); |
| 3786 | |
| 3787 | if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) { |
| 3788 | if (dut->testbed_flag_rxsp == 1) { |
| 3789 | vht_mcsmap = 0xfffc; |
| 3790 | dut->testbed_flag_rxsp = 0; |
| 3791 | } else { |
| 3792 | vht_mcsmap = 0xfffe; |
| 3793 | } |
| 3794 | rxchainmask = 1; |
| 3795 | } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) { |
| 3796 | if (dut->testbed_flag_rxsp == 1) { |
| 3797 | vht_mcsmap = 0xfff0; |
| 3798 | dut->testbed_flag_rxsp = 0; |
| 3799 | } else { |
| 3800 | vht_mcsmap = 0xfffa; |
| 3801 | } |
| 3802 | rxchainmask = 3; |
| 3803 | } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) { |
| 3804 | if (dut->testbed_flag_rxsp == 1) { |
| 3805 | vht_mcsmap = 0xffc0; |
| 3806 | dut->testbed_flag_rxsp = 0; |
| 3807 | } else { |
| 3808 | vht_mcsmap = 0xffea; |
| 3809 | } |
| 3810 | rxchainmask = 7; |
| 3811 | } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) { |
| 3812 | if (dut->testbed_flag_rxsp == 1) { |
| 3813 | vht_mcsmap = 0xff00; |
| 3814 | dut->testbed_flag_rxsp = 0; |
| 3815 | } else { |
| 3816 | vht_mcsmap = 0xffaa; |
| 3817 | } |
| 3818 | rxchainmask = 15; |
| 3819 | } else { |
| 3820 | if (dut->testbed_flag_rxsp == 1) { |
| 3821 | vht_mcsmap = 0xffc0; |
| 3822 | dut->testbed_flag_rxsp = 0; |
| 3823 | } else { |
| 3824 | vht_mcsmap = 0xffea; |
| 3825 | } |
| 3826 | } |
| 3827 | |
| 3828 | if (rxchainmask) { |
| 3829 | snprintf(buf, sizeof(buf), "iwpriv %s rxchainmask %d", |
| 3830 | basedev, rxchainmask); |
| 3831 | if (system(buf) != 0) { |
| 3832 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3833 | "iwpriv rxchainmask failed"); |
| 3834 | } |
| 3835 | } |
| 3836 | |
| 3837 | snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0x%04x", |
| 3838 | intf, vht_mcsmap); |
| 3839 | if (system(buf) != 0) { |
| 3840 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3841 | "iwpriv %s vht_mcsmap 0x%04x", |
| 3842 | intf, vht_mcsmap); |
| 3843 | } |
| 3844 | } |
| 3845 | |
| 3846 | |
| 3847 | void ath_set_zero_crc(struct sigma_dut *dut, const char *val) |
| 3848 | { |
| 3849 | if (strcasecmp(val, "enable") == 0) { |
| 3850 | if (system("athdiag --set --address=0x2a204 --and=0xbfffffff") |
| 3851 | != 0) { |
| 3852 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3853 | "Disable BB_VHTSIGB_CRC_CALC failed"); |
| 3854 | } |
| 3855 | |
| 3856 | if (system("athdiag --set --address=0x2a204 --or=0x80000000") |
| 3857 | != 0) { |
| 3858 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3859 | "Enable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed"); |
| 3860 | } |
| 3861 | } else { |
| 3862 | if (system("athdiag --set --address=0x2a204 --and=0x7fffffff") |
| 3863 | != 0) { |
| 3864 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3865 | "Disable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed"); |
| 3866 | } |
| 3867 | |
| 3868 | if (system("athdiag --set --address=0x2a204 --or=0x40000000") |
| 3869 | != 0) { |
| 3870 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3871 | "Enable BB_VHTSIGB_CRC_CALC failed"); |
| 3872 | } |
| 3873 | } |
| 3874 | } |
| 3875 | |
| 3876 | |
| 3877 | static int cmd_sta_set_wireless_common(const char *intf, struct sigma_dut *dut, |
| 3878 | struct sigma_conn *conn, |
| 3879 | struct sigma_cmd *cmd) |
| 3880 | { |
| 3881 | const char *val; |
| 3882 | int ampdu = -1; |
| 3883 | char buf[30]; |
| 3884 | |
| 3885 | val = get_param(cmd, "40_INTOLERANT"); |
| 3886 | if (val) { |
| 3887 | if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) { |
| 3888 | /* TODO: iwpriv ht40intol through wpa_supplicant */ |
| 3889 | send_resp(dut, conn, SIGMA_ERROR, |
| 3890 | "ErrorCode,40_INTOLERANT not supported"); |
| 3891 | return 0; |
| 3892 | } |
| 3893 | } |
| 3894 | |
| 3895 | val = get_param(cmd, "ADDBA_REJECT"); |
| 3896 | if (val) { |
| 3897 | if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) { |
| 3898 | /* reject any ADDBA with status "decline" */ |
| 3899 | ampdu = 0; |
| 3900 | } else { |
| 3901 | /* accept ADDBA */ |
| 3902 | ampdu = 1; |
| 3903 | } |
| 3904 | } |
| 3905 | |
| 3906 | val = get_param(cmd, "AMPDU"); |
| 3907 | if (val) { |
| 3908 | if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) { |
| 3909 | /* enable AMPDU Aggregation */ |
| 3910 | if (ampdu == 0) { |
| 3911 | send_resp(dut, conn, SIGMA_ERROR, |
| 3912 | "ErrorCode,Mismatch in " |
| 3913 | "addba_reject/ampdu - " |
| 3914 | "not supported"); |
| 3915 | return 0; |
| 3916 | } |
| 3917 | ampdu = 1; |
| 3918 | } else { |
| 3919 | /* disable AMPDU Aggregation */ |
| 3920 | if (ampdu == 1) { |
| 3921 | send_resp(dut, conn, SIGMA_ERROR, |
| 3922 | "ErrorCode,Mismatch in " |
| 3923 | "addba_reject/ampdu - " |
| 3924 | "not supported"); |
| 3925 | return 0; |
| 3926 | } |
| 3927 | ampdu = 0; |
| 3928 | } |
| 3929 | } |
| 3930 | |
| 3931 | if (ampdu >= 0) { |
| 3932 | sigma_dut_print(dut, DUT_MSG_DEBUG, "%s A-MPDU aggregation", |
| 3933 | ampdu ? "Enabling" : "Disabling"); |
| 3934 | snprintf(buf, sizeof(buf), "SET ampdu %d", ampdu); |
Deepak Dhamdhere | 80356cb | 2016-03-28 16:48:32 -0700 | [diff] [blame] | 3935 | if (wpa_command(intf, buf) < 0 && |
| 3936 | iwpriv_sta_set_ampdu(dut, intf, ampdu) < 0) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3937 | send_resp(dut, conn, SIGMA_ERROR, |
| 3938 | "ErrorCode,set aggr failed"); |
| 3939 | return 0; |
| 3940 | } |
| 3941 | } |
| 3942 | |
| 3943 | val = get_param(cmd, "AMSDU"); |
| 3944 | if (val) { |
| 3945 | switch (get_driver_type()) { |
| 3946 | case DRIVER_ATHEROS: |
| 3947 | ath_sta_set_amsdu(dut, intf, val); |
| 3948 | break; |
| 3949 | default: |
| 3950 | if (strcmp(val, "1") == 0 || |
| 3951 | strcasecmp(val, "Enable") == 0) { |
| 3952 | /* Enable AMSDU Aggregation */ |
| 3953 | send_resp(dut, conn, SIGMA_ERROR, |
| 3954 | "ErrorCode,AMSDU aggregation not supported"); |
| 3955 | return 0; |
| 3956 | } |
| 3957 | break; |
| 3958 | } |
| 3959 | } |
| 3960 | |
| 3961 | val = get_param(cmd, "STBC_RX"); |
| 3962 | if (val) { |
| 3963 | switch (get_driver_type()) { |
| 3964 | case DRIVER_ATHEROS: |
| 3965 | ath_sta_set_stbc(dut, intf, val); |
| 3966 | break; |
Pradeep Reddy POTTETI | 4a1f6b3 | 2016-11-23 13:15:21 +0530 | [diff] [blame] | 3967 | case DRIVER_WCN: |
| 3968 | wcn_sta_set_stbc(dut, intf, val); |
| 3969 | break; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3970 | default: |
| 3971 | send_resp(dut, conn, SIGMA_ERROR, |
| 3972 | "ErrorCode,STBC_RX not supported"); |
| 3973 | return 0; |
| 3974 | } |
| 3975 | } |
| 3976 | |
| 3977 | val = get_param(cmd, "WIDTH"); |
| 3978 | if (val) { |
| 3979 | switch (get_driver_type()) { |
| 3980 | case DRIVER_WCN: |
| 3981 | if (wcn_sta_set_cts_width(dut, intf, val) < 0) { |
| 3982 | send_resp(dut, conn, SIGMA_ERROR, |
| 3983 | "ErrorCode,Failed to set WIDTH"); |
| 3984 | return 0; |
| 3985 | } |
| 3986 | break; |
| 3987 | case DRIVER_ATHEROS: |
| 3988 | if (ath_set_width(dut, conn, intf, val) < 0) |
| 3989 | return 0; |
| 3990 | break; |
| 3991 | default: |
| 3992 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3993 | "Setting WIDTH not supported"); |
| 3994 | break; |
| 3995 | } |
| 3996 | } |
| 3997 | |
| 3998 | val = get_param(cmd, "SMPS"); |
| 3999 | if (val) { |
| 4000 | /* TODO: Dynamic/0, Static/1, No Limit/2 */ |
| 4001 | send_resp(dut, conn, SIGMA_ERROR, |
| 4002 | "ErrorCode,SMPS not supported"); |
| 4003 | return 0; |
| 4004 | } |
| 4005 | |
| 4006 | val = get_param(cmd, "TXSP_STREAM"); |
| 4007 | if (val) { |
| 4008 | switch (get_driver_type()) { |
| 4009 | case DRIVER_WCN: |
| 4010 | if (wcn_sta_set_sp_stream(dut, intf, val) < 0) { |
| 4011 | send_resp(dut, conn, SIGMA_ERROR, |
| 4012 | "ErrorCode,Failed to set TXSP_STREAM"); |
| 4013 | return 0; |
| 4014 | } |
| 4015 | break; |
| 4016 | case DRIVER_ATHEROS: |
| 4017 | ath_sta_set_txsp_stream(dut, intf, val); |
| 4018 | break; |
| 4019 | default: |
| 4020 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4021 | "Setting TXSP_STREAM not supported"); |
| 4022 | break; |
| 4023 | } |
| 4024 | } |
| 4025 | |
| 4026 | val = get_param(cmd, "RXSP_STREAM"); |
| 4027 | if (val) { |
| 4028 | switch (get_driver_type()) { |
| 4029 | case DRIVER_WCN: |
| 4030 | if (wcn_sta_set_sp_stream(dut, intf, val) < 0) { |
| 4031 | send_resp(dut, conn, SIGMA_ERROR, |
| 4032 | "ErrorCode,Failed to set RXSP_STREAM"); |
| 4033 | return 0; |
| 4034 | } |
| 4035 | break; |
| 4036 | case DRIVER_ATHEROS: |
| 4037 | ath_sta_set_rxsp_stream(dut, intf, val); |
| 4038 | break; |
| 4039 | default: |
| 4040 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4041 | "Setting RXSP_STREAM not supported"); |
| 4042 | break; |
| 4043 | } |
| 4044 | } |
| 4045 | |
| 4046 | val = get_param(cmd, "DYN_BW_SGNL"); |
| 4047 | if (val) { |
Priyadharshini Gowthaman | 818afef | 2015-11-09 13:28:15 -0800 | [diff] [blame] | 4048 | switch (get_driver_type()) { |
| 4049 | case DRIVER_WCN: |
Peng Xu | c59afd3 | 2016-11-21 15:01:11 -0800 | [diff] [blame] | 4050 | if (strcasecmp(val, "enable") == 0) { |
| 4051 | snprintf(buf, sizeof(buf), |
| 4052 | "iwpriv %s cwmenable 1", intf); |
| 4053 | if (system(buf) != 0) { |
| 4054 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4055 | "iwpriv cwmenable 1 failed"); |
| 4056 | return 0; |
| 4057 | } |
| 4058 | } else if (strcasecmp(val, "disable") == 0) { |
| 4059 | snprintf(buf, sizeof(buf), |
| 4060 | "iwpriv %s cwmenable 0", intf); |
| 4061 | if (system(buf) != 0) { |
| 4062 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4063 | "iwpriv cwmenable 0 failed"); |
| 4064 | return 0; |
| 4065 | } |
| 4066 | } else { |
| 4067 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4068 | "Unsupported DYN_BW_SGL"); |
| 4069 | } |
| 4070 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4071 | snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf); |
| 4072 | if (system(buf) != 0) { |
| 4073 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4074 | "Failed to set cts_cbw in DYN_BW_SGNL"); |
| 4075 | return 0; |
| 4076 | } |
Priyadharshini Gowthaman | 818afef | 2015-11-09 13:28:15 -0800 | [diff] [blame] | 4077 | break; |
| 4078 | case DRIVER_ATHEROS: |
priyadharshini gowthaman | e5e2517 | 2015-12-08 14:53:48 -0800 | [diff] [blame] | 4079 | novap_reset(dut, intf); |
Priyadharshini Gowthaman | 818afef | 2015-11-09 13:28:15 -0800 | [diff] [blame] | 4080 | ath_config_dyn_bw_sig(dut, intf, val); |
| 4081 | break; |
| 4082 | default: |
| 4083 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4084 | "Failed to set DYN_BW_SGNL"); |
| 4085 | break; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4086 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4087 | } |
| 4088 | |
| 4089 | val = get_param(cmd, "RTS_FORCE"); |
| 4090 | if (val) { |
priyadharshini gowthaman | e5e2517 | 2015-12-08 14:53:48 -0800 | [diff] [blame] | 4091 | novap_reset(dut, intf); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4092 | if (strcasecmp(val, "Enable") == 0) { |
| 4093 | snprintf(buf, sizeof(buf), "iwconfig %s rts 64", intf); |
Priyadharshini Gowthaman | abdb212 | 2015-11-17 11:52:19 +0200 | [diff] [blame] | 4094 | if (system(buf) != 0) { |
| 4095 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4096 | "Failed to set RTS_FORCE 64"); |
| 4097 | } |
priyadharshini gowthaman | 270870e | 2015-12-09 10:10:23 -0800 | [diff] [blame] | 4098 | snprintf(buf, sizeof(buf), |
| 4099 | "wifitool %s beeliner_fw_test 100 1", intf); |
| 4100 | if (system(buf) != 0) { |
| 4101 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4102 | "wifitool beeliner_fw_test 100 1 failed"); |
| 4103 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4104 | } else if (strcasecmp(val, "Disable") == 0) { |
| 4105 | snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", |
| 4106 | intf); |
Priyadharshini Gowthaman | abdb212 | 2015-11-17 11:52:19 +0200 | [diff] [blame] | 4107 | if (system(buf) != 0) { |
| 4108 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4109 | "Failed to set RTS_FORCE 2347"); |
| 4110 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4111 | } else { |
| 4112 | send_resp(dut, conn, SIGMA_ERROR, |
| 4113 | "ErrorCode,RTS_FORCE value not supported"); |
| 4114 | return 0; |
| 4115 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4116 | } |
| 4117 | |
| 4118 | val = get_param(cmd, "CTS_WIDTH"); |
| 4119 | if (val) { |
| 4120 | switch (get_driver_type()) { |
| 4121 | case DRIVER_WCN: |
| 4122 | if (wcn_sta_set_cts_width(dut, intf, val) < 0) { |
| 4123 | send_resp(dut, conn, SIGMA_ERROR, |
| 4124 | "ErrorCode,Failed to set CTS_WIDTH"); |
| 4125 | return 0; |
| 4126 | } |
| 4127 | break; |
| 4128 | case DRIVER_ATHEROS: |
| 4129 | ath_set_cts_width(dut, intf, val); |
| 4130 | break; |
| 4131 | default: |
| 4132 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4133 | "Setting CTS_WIDTH not supported"); |
| 4134 | break; |
| 4135 | } |
| 4136 | } |
| 4137 | |
| 4138 | val = get_param(cmd, "BW_SGNL"); |
| 4139 | if (val) { |
| 4140 | if (strcasecmp(val, "Enable") == 0) { |
| 4141 | snprintf(buf, sizeof(buf), "iwpriv %s cwmenable 1", |
| 4142 | intf); |
| 4143 | } else if (strcasecmp(val, "Disable") == 0) { |
| 4144 | /* TODO: Disable */ |
| 4145 | buf[0] = '\0'; |
| 4146 | } else { |
| 4147 | send_resp(dut, conn, SIGMA_ERROR, |
| 4148 | "ErrorCode,BW_SGNL value not supported"); |
| 4149 | return 0; |
| 4150 | } |
| 4151 | |
| 4152 | if (buf[0] != '\0' && system(buf) != 0) { |
| 4153 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4154 | "Failed to set BW_SGNL"); |
| 4155 | } |
| 4156 | } |
| 4157 | |
| 4158 | val = get_param(cmd, "Band"); |
| 4159 | if (val) { |
| 4160 | if (strcmp(val, "2.4") == 0 || strcmp(val, "5") == 0) { |
| 4161 | /* STA supports all bands by default */ |
| 4162 | } else { |
| 4163 | send_resp(dut, conn, SIGMA_ERROR, |
| 4164 | "ErrorCode,Unsupported Band"); |
| 4165 | return 0; |
| 4166 | } |
| 4167 | } |
| 4168 | |
| 4169 | val = get_param(cmd, "zero_crc"); |
| 4170 | if (val) { |
| 4171 | switch (get_driver_type()) { |
| 4172 | case DRIVER_ATHEROS: |
| 4173 | ath_set_zero_crc(dut, val); |
| 4174 | break; |
| 4175 | default: |
| 4176 | break; |
| 4177 | } |
| 4178 | } |
| 4179 | |
| 4180 | return 1; |
| 4181 | } |
| 4182 | |
| 4183 | |
| 4184 | static int sta_set_60g_common(struct sigma_dut *dut, struct sigma_conn *conn, |
| 4185 | struct sigma_cmd *cmd) |
| 4186 | { |
| 4187 | const char *val; |
| 4188 | char buf[100]; |
| 4189 | |
| 4190 | val = get_param(cmd, "MSDUSize"); |
| 4191 | if (val) { |
| 4192 | int mtu; |
| 4193 | |
| 4194 | dut->amsdu_size = atoi(val); |
| 4195 | if (dut->amsdu_size > IEEE80211_MAX_DATA_LEN_DMG || |
| 4196 | dut->amsdu_size < IEEE80211_SNAP_LEN_DMG) { |
| 4197 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4198 | "MSDUSize %d is above max %d or below min %d", |
| 4199 | dut->amsdu_size, |
| 4200 | IEEE80211_MAX_DATA_LEN_DMG, |
| 4201 | IEEE80211_SNAP_LEN_DMG); |
| 4202 | dut->amsdu_size = 0; |
| 4203 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; |
| 4204 | } |
| 4205 | |
| 4206 | mtu = dut->amsdu_size - IEEE80211_SNAP_LEN_DMG; |
| 4207 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 4208 | "Setting amsdu_size to %d", mtu); |
| 4209 | snprintf(buf, sizeof(buf), "ifconfig %s mtu %d", |
| 4210 | get_station_ifname(), mtu); |
| 4211 | |
| 4212 | if (system(buf) != 0) { |
| 4213 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s", |
| 4214 | buf); |
| 4215 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; |
| 4216 | } |
| 4217 | } |
| 4218 | |
| 4219 | val = get_param(cmd, "BAckRcvBuf"); |
| 4220 | if (val) { |
| 4221 | dut->back_rcv_buf = atoi(val); |
| 4222 | if (dut->back_rcv_buf == 0) { |
| 4223 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4224 | "Failed to convert %s or value is 0", |
| 4225 | val); |
| 4226 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; |
| 4227 | } |
| 4228 | |
| 4229 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 4230 | "Setting BAckRcvBuf to %s", val); |
| 4231 | } |
| 4232 | |
| 4233 | return SIGMA_DUT_SUCCESS_CALLER_SEND_STATUS; |
| 4234 | } |
| 4235 | |
| 4236 | |
| 4237 | static int sta_pcp_start(struct sigma_dut *dut, struct sigma_conn *conn, |
| 4238 | struct sigma_cmd *cmd) |
| 4239 | { |
| 4240 | int net_id; |
| 4241 | char *ifname; |
| 4242 | const char *val; |
| 4243 | char buf[100]; |
| 4244 | |
| 4245 | dut->mode = SIGMA_MODE_STATION; |
| 4246 | ifname = get_main_ifname(); |
| 4247 | if (wpa_command(ifname, "PING") != 0) { |
| 4248 | sigma_dut_print(dut, DUT_MSG_ERROR, "Supplicant not running"); |
| 4249 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; |
| 4250 | } |
| 4251 | |
| 4252 | wpa_command(ifname, "FLUSH"); |
| 4253 | net_id = add_network_common(dut, conn, ifname, cmd); |
| 4254 | if (net_id < 0) { |
| 4255 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add network"); |
| 4256 | return net_id; |
| 4257 | } |
| 4258 | |
| 4259 | /* TODO: mode=2 for the AP; in the future, replace for mode PCP */ |
| 4260 | if (set_network(ifname, net_id, "mode", "2") < 0) { |
| 4261 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4262 | "Failed to set supplicant network mode"); |
| 4263 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; |
| 4264 | } |
| 4265 | |
| 4266 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 4267 | "Supplicant set network with mode 2"); |
| 4268 | |
| 4269 | val = get_param(cmd, "Security"); |
| 4270 | if (val && strcasecmp(val, "OPEN") == 0) { |
| 4271 | dut->ap_key_mgmt = AP_OPEN; |
| 4272 | if (set_network(ifname, net_id, "key_mgmt", "NONE") < 0) { |
| 4273 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4274 | "Failed to set supplicant to %s security", |
| 4275 | val); |
| 4276 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; |
| 4277 | } |
| 4278 | } else if (val && strcasecmp(val, "WPA2-PSK") == 0) { |
| 4279 | dut->ap_key_mgmt = AP_WPA2_PSK; |
| 4280 | if (set_network(ifname, net_id, "key_mgmt", "WPA-PSK") < 0) { |
| 4281 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4282 | "Failed to set supplicant to %s security", |
| 4283 | val); |
| 4284 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; |
| 4285 | } |
| 4286 | |
| 4287 | if (set_network(ifname, net_id, "proto", "RSN") < 0) { |
| 4288 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4289 | "Failed to set supplicant to proto RSN"); |
| 4290 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; |
| 4291 | } |
| 4292 | } else if (val) { |
| 4293 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4294 | "Requested Security %s is not supported on 60GHz", |
| 4295 | val); |
| 4296 | return SIGMA_DUT_INVALID_CALLER_SEND_STATUS; |
| 4297 | } |
| 4298 | |
| 4299 | val = get_param(cmd, "Encrypt"); |
| 4300 | if (val && strcasecmp(val, "AES-GCMP") == 0) { |
| 4301 | if (set_network(ifname, net_id, "pairwise", "GCMP") < 0) { |
| 4302 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4303 | "Failed to set supplicant to pairwise GCMP"); |
| 4304 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; |
| 4305 | } |
| 4306 | if (set_network(ifname, net_id, "group", "GCMP") < 0) { |
| 4307 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4308 | "Failed to set supplicant to group GCMP"); |
| 4309 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; |
| 4310 | } |
| 4311 | } else if (val) { |
| 4312 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4313 | "Requested Encrypt %s is not supported on 60 GHz", |
| 4314 | val); |
| 4315 | return SIGMA_DUT_INVALID_CALLER_SEND_STATUS; |
| 4316 | } |
| 4317 | |
| 4318 | val = get_param(cmd, "PSK"); |
| 4319 | if (val && set_network_quoted(ifname, net_id, "psk", val) < 0) { |
| 4320 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set psk %s", |
| 4321 | val); |
| 4322 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; |
| 4323 | } |
| 4324 | |
| 4325 | /* Convert 60G channel to freq */ |
| 4326 | switch (dut->ap_channel) { |
| 4327 | case 1: |
| 4328 | val = "58320"; |
| 4329 | break; |
| 4330 | case 2: |
| 4331 | val = "60480"; |
| 4332 | break; |
| 4333 | case 3: |
| 4334 | val = "62640"; |
| 4335 | break; |
| 4336 | default: |
| 4337 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4338 | "Failed to configure channel %d. Not supported", |
| 4339 | dut->ap_channel); |
| 4340 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; |
| 4341 | } |
| 4342 | |
| 4343 | if (set_network(ifname, net_id, "frequency", val) < 0) { |
| 4344 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4345 | "Failed to set supplicant network frequency"); |
| 4346 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; |
| 4347 | } |
| 4348 | |
| 4349 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 4350 | "Supplicant set network with frequency"); |
| 4351 | |
| 4352 | snprintf(buf, sizeof(buf), "SELECT_NETWORK %d", net_id); |
| 4353 | if (wpa_command(ifname, buf) < 0) { |
| 4354 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 4355 | "Failed to select network id %d on %s", |
| 4356 | net_id, ifname); |
| 4357 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; |
| 4358 | } |
| 4359 | |
| 4360 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Selected network"); |
| 4361 | |
| 4362 | return SIGMA_DUT_SUCCESS_CALLER_SEND_STATUS; |
| 4363 | } |
| 4364 | |
| 4365 | |
Lior David | 67543f5 | 2017-01-03 19:04:22 +0200 | [diff] [blame] | 4366 | static int wil6210_set_abft_len(struct sigma_dut *dut, int abft_len) |
| 4367 | { |
| 4368 | char buf[128], fname[128]; |
| 4369 | FILE *f; |
| 4370 | |
| 4371 | if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) { |
| 4372 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4373 | "failed to get wil6210 debugfs dir"); |
| 4374 | return -1; |
| 4375 | } |
| 4376 | |
| 4377 | snprintf(fname, sizeof(fname), "%s/abft_len", buf); |
| 4378 | f = fopen(fname, "w"); |
| 4379 | if (!f) { |
| 4380 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4381 | "failed to open: %s", fname); |
| 4382 | return -1; |
| 4383 | } |
| 4384 | |
| 4385 | fprintf(f, "%d\n", abft_len); |
| 4386 | fclose(f); |
| 4387 | |
| 4388 | return 0; |
| 4389 | } |
| 4390 | |
| 4391 | |
| 4392 | static int sta_set_60g_abft_len(struct sigma_dut *dut, struct sigma_conn *conn, |
| 4393 | int abft_len) |
| 4394 | { |
| 4395 | switch (get_driver_type()) { |
| 4396 | case DRIVER_WIL6210: |
| 4397 | return wil6210_set_abft_len(dut, abft_len); |
| 4398 | default: |
| 4399 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4400 | "set abft_len not supported"); |
| 4401 | return -1; |
| 4402 | } |
| 4403 | } |
| 4404 | |
| 4405 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4406 | static int sta_set_60g_pcp(struct sigma_dut *dut, struct sigma_conn *conn, |
| 4407 | struct sigma_cmd *cmd) |
| 4408 | { |
| 4409 | const char *val; |
Lior David | 67543f5 | 2017-01-03 19:04:22 +0200 | [diff] [blame] | 4410 | unsigned int abft_len = 1; /* default is one slot */ |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4411 | |
| 4412 | if (dut->dev_role != DEVROLE_PCP) { |
| 4413 | send_resp(dut, conn, SIGMA_INVALID, |
| 4414 | "ErrorCode,Invalid DevRole"); |
| 4415 | return 0; |
| 4416 | } |
| 4417 | |
| 4418 | val = get_param(cmd, "SSID"); |
| 4419 | if (val) { |
| 4420 | if (strlen(val) > sizeof(dut->ap_ssid) - 1) { |
| 4421 | send_resp(dut, conn, SIGMA_INVALID, |
| 4422 | "ErrorCode,Invalid SSID"); |
| 4423 | return -1; |
| 4424 | } |
| 4425 | |
Peng Xu | b8fc5cc | 2017-05-10 17:27:28 -0700 | [diff] [blame] | 4426 | strlcpy(dut->ap_ssid, val, sizeof(dut->ap_ssid)); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4427 | } |
| 4428 | |
| 4429 | val = get_param(cmd, "CHANNEL"); |
| 4430 | if (val) { |
| 4431 | const char *pos; |
| 4432 | |
| 4433 | dut->ap_channel = atoi(val); |
| 4434 | pos = strchr(val, ';'); |
| 4435 | if (pos) { |
| 4436 | pos++; |
| 4437 | dut->ap_channel_1 = atoi(pos); |
| 4438 | } |
| 4439 | } |
| 4440 | |
| 4441 | switch (dut->ap_channel) { |
| 4442 | case 1: |
| 4443 | case 2: |
| 4444 | case 3: |
| 4445 | break; |
| 4446 | default: |
| 4447 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4448 | "Channel %d is not supported", dut->ap_channel); |
| 4449 | send_resp(dut, conn, SIGMA_ERROR, |
| 4450 | "Requested channel is not supported"); |
| 4451 | return -1; |
| 4452 | } |
| 4453 | |
| 4454 | val = get_param(cmd, "BCNINT"); |
| 4455 | if (val) |
| 4456 | dut->ap_bcnint = atoi(val); |
| 4457 | |
| 4458 | |
| 4459 | val = get_param(cmd, "ExtSchIE"); |
| 4460 | if (val) { |
| 4461 | send_resp(dut, conn, SIGMA_ERROR, |
| 4462 | "ErrorCode,ExtSchIE is not supported yet"); |
| 4463 | return -1; |
| 4464 | } |
| 4465 | |
| 4466 | val = get_param(cmd, "AllocType"); |
| 4467 | if (val) { |
| 4468 | send_resp(dut, conn, SIGMA_ERROR, |
| 4469 | "ErrorCode,AllocType is not supported yet"); |
| 4470 | return -1; |
| 4471 | } |
| 4472 | |
| 4473 | val = get_param(cmd, "PercentBI"); |
| 4474 | if (val) { |
| 4475 | send_resp(dut, conn, SIGMA_ERROR, |
| 4476 | "ErrorCode,PercentBI is not supported yet"); |
| 4477 | return -1; |
| 4478 | } |
| 4479 | |
| 4480 | val = get_param(cmd, "CBAPOnly"); |
| 4481 | if (val) { |
| 4482 | send_resp(dut, conn, SIGMA_ERROR, |
| 4483 | "ErrorCode,CBAPOnly is not supported yet"); |
| 4484 | return -1; |
| 4485 | } |
| 4486 | |
| 4487 | val = get_param(cmd, "AMPDU"); |
| 4488 | if (val) { |
| 4489 | if (strcasecmp(val, "Enable") == 0) |
| 4490 | dut->ap_ampdu = 1; |
| 4491 | else if (strcasecmp(val, "Disable") == 0) |
| 4492 | dut->ap_ampdu = 2; |
| 4493 | else { |
| 4494 | send_resp(dut, conn, SIGMA_ERROR, |
| 4495 | "ErrorCode,AMPDU value is not Enable nor Disabled"); |
| 4496 | return -1; |
| 4497 | } |
| 4498 | } |
| 4499 | |
| 4500 | val = get_param(cmd, "AMSDU"); |
| 4501 | if (val) { |
| 4502 | if (strcasecmp(val, "Enable") == 0) |
| 4503 | dut->ap_amsdu = 1; |
| 4504 | else if (strcasecmp(val, "Disable") == 0) |
| 4505 | dut->ap_amsdu = 2; |
| 4506 | } |
| 4507 | |
| 4508 | val = get_param(cmd, "NumMSDU"); |
| 4509 | if (val) { |
| 4510 | send_resp(dut, conn, SIGMA_ERROR, |
| 4511 | "ErrorCode, NumMSDU is not supported yet"); |
| 4512 | return -1; |
| 4513 | } |
| 4514 | |
| 4515 | val = get_param(cmd, "ABFTLRang"); |
| 4516 | if (val) { |
| 4517 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
Lior David | 67543f5 | 2017-01-03 19:04:22 +0200 | [diff] [blame] | 4518 | "ABFTLRang parameter %s", val); |
| 4519 | if (strcmp(val, "Gt1") == 0) |
| 4520 | abft_len = 2; /* 2 slots in this case */ |
| 4521 | } |
| 4522 | |
| 4523 | if (sta_set_60g_abft_len(dut, conn, abft_len)) { |
| 4524 | send_resp(dut, conn, SIGMA_ERROR, |
| 4525 | "ErrorCode, Can't set ABFT length"); |
| 4526 | return -1; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4527 | } |
| 4528 | |
| 4529 | if (sta_pcp_start(dut, conn, cmd) < 0) { |
| 4530 | send_resp(dut, conn, SIGMA_ERROR, |
| 4531 | "ErrorCode, Can't start PCP role"); |
| 4532 | return -1; |
| 4533 | } |
| 4534 | |
| 4535 | return sta_set_60g_common(dut, conn, cmd); |
| 4536 | } |
| 4537 | |
| 4538 | |
| 4539 | static int sta_set_60g_sta(struct sigma_dut *dut, struct sigma_conn *conn, |
| 4540 | struct sigma_cmd *cmd) |
| 4541 | { |
| 4542 | const char *val = get_param(cmd, "DiscoveryMode"); |
| 4543 | |
| 4544 | if (dut->dev_role != DEVROLE_STA) { |
| 4545 | send_resp(dut, conn, SIGMA_INVALID, |
| 4546 | "ErrorCode,Invalid DevRole"); |
| 4547 | return 0; |
| 4548 | } |
| 4549 | |
| 4550 | if (val) { |
| 4551 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Discovery: %s", val); |
| 4552 | /* Ignore Discovery mode till Driver expose API. */ |
| 4553 | #if 0 |
| 4554 | if (strcasecmp(val, "1") == 0) { |
| 4555 | send_resp(dut, conn, SIGMA_INVALID, |
| 4556 | "ErrorCode,DiscoveryMode 1 not supported"); |
| 4557 | return 0; |
| 4558 | } |
| 4559 | |
| 4560 | if (strcasecmp(val, "0") == 0) { |
| 4561 | /* OK */ |
| 4562 | } else { |
| 4563 | send_resp(dut, conn, SIGMA_INVALID, |
| 4564 | "ErrorCode,DiscoveryMode not supported"); |
| 4565 | return 0; |
| 4566 | } |
| 4567 | #endif |
| 4568 | } |
| 4569 | |
| 4570 | if (start_sta_mode(dut) != 0) |
| 4571 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; |
| 4572 | return sta_set_60g_common(dut, conn, cmd); |
| 4573 | } |
| 4574 | |
| 4575 | |
| 4576 | static int cmd_sta_disconnect(struct sigma_dut *dut, struct sigma_conn *conn, |
| 4577 | struct sigma_cmd *cmd) |
| 4578 | { |
| 4579 | const char *intf = get_param(cmd, "Interface"); |
vamsi krishna | d605c42 | 2017-09-20 14:56:31 +0530 | [diff] [blame] | 4580 | |
| 4581 | if (dut->program == PROGRAM_OCE) { |
| 4582 | wpa_command(intf, "DISCONNECT"); |
| 4583 | return 1; |
| 4584 | } |
| 4585 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4586 | disconnect_station(dut); |
| 4587 | /* Try to ignore old scan results to avoid HS 2.0R2 test case failures |
| 4588 | * due to cached results. */ |
| 4589 | wpa_command(intf, "SET ignore_old_scan_res 1"); |
| 4590 | wpa_command(intf, "BSS_FLUSH"); |
| 4591 | return 1; |
| 4592 | } |
| 4593 | |
| 4594 | |
| 4595 | static int cmd_sta_reassoc(struct sigma_dut *dut, struct sigma_conn *conn, |
| 4596 | struct sigma_cmd *cmd) |
| 4597 | { |
| 4598 | const char *intf = get_param(cmd, "Interface"); |
| 4599 | const char *bssid = get_param(cmd, "bssid"); |
| 4600 | const char *val = get_param(cmd, "CHANNEL"); |
| 4601 | struct wpa_ctrl *ctrl; |
| 4602 | char buf[100]; |
| 4603 | int res; |
| 4604 | int chan = 0; |
Ashwini Patil | 467efef | 2017-05-25 12:18:27 +0530 | [diff] [blame] | 4605 | int status = 0; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4606 | |
| 4607 | if (bssid == NULL) { |
| 4608 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing bssid " |
| 4609 | "argument"); |
| 4610 | return 0; |
| 4611 | } |
| 4612 | |
| 4613 | if (val) |
| 4614 | chan = atoi(val); |
| 4615 | |
| 4616 | if (wifi_chip_type != DRIVER_WCN && wifi_chip_type != DRIVER_AR6003) { |
| 4617 | /* The current network may be from sta_associate or |
| 4618 | * sta_hs2_associate |
| 4619 | */ |
| 4620 | if (set_network(intf, dut->infra_network_id, "bssid", bssid) < |
| 4621 | 0 || |
| 4622 | set_network(intf, 0, "bssid", bssid) < 0) |
| 4623 | return -2; |
| 4624 | } |
| 4625 | |
| 4626 | ctrl = open_wpa_mon(intf); |
| 4627 | if (ctrl == NULL) { |
| 4628 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open " |
| 4629 | "wpa_supplicant monitor connection"); |
| 4630 | return -1; |
| 4631 | } |
| 4632 | |
| 4633 | if (wifi_chip_type == DRIVER_WCN) { |
| 4634 | #ifdef ANDROID |
Ashwini Patil | 4c8158f | 2017-05-25 12:49:21 +0530 | [diff] [blame] | 4635 | if (chan) { |
| 4636 | unsigned int freq; |
| 4637 | |
| 4638 | freq = channel_to_freq(chan); |
| 4639 | if (!freq) { |
| 4640 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4641 | "Invalid channel number provided: %d", |
| 4642 | chan); |
| 4643 | send_resp(dut, conn, SIGMA_INVALID, |
| 4644 | "ErrorCode,Invalid channel number"); |
| 4645 | goto close_mon_conn; |
| 4646 | } |
| 4647 | res = snprintf(buf, sizeof(buf), |
| 4648 | "SCAN TYPE=ONLY freq=%d", freq); |
| 4649 | } else { |
| 4650 | res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY"); |
| 4651 | } |
| 4652 | if (res < 0 || res >= (int) sizeof(buf)) { |
| 4653 | send_resp(dut, conn, SIGMA_ERROR, |
| 4654 | "ErrorCode,snprintf failed"); |
| 4655 | goto close_mon_conn; |
| 4656 | } |
| 4657 | if (wpa_command(intf, buf) < 0) { |
| 4658 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 4659 | "Failed to start scan"); |
| 4660 | send_resp(dut, conn, SIGMA_ERROR, |
| 4661 | "ErrorCode,scan failed"); |
| 4662 | goto close_mon_conn; |
| 4663 | } |
| 4664 | |
| 4665 | res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS", |
| 4666 | buf, sizeof(buf)); |
| 4667 | if (res < 0) { |
| 4668 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 4669 | "Scan did not complete"); |
| 4670 | send_resp(dut, conn, SIGMA_ERROR, |
| 4671 | "ErrorCode,scan did not complete"); |
| 4672 | goto close_mon_conn; |
| 4673 | } |
| 4674 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4675 | if (set_network(intf, dut->infra_network_id, "bssid", "any") |
| 4676 | < 0) { |
| 4677 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set " |
| 4678 | "bssid to any during FASTREASSOC"); |
Ashwini Patil | 467efef | 2017-05-25 12:18:27 +0530 | [diff] [blame] | 4679 | status = -2; |
| 4680 | goto close_mon_conn; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4681 | } |
| 4682 | res = snprintf(buf, sizeof(buf), "DRIVER FASTREASSOC %s %d", |
| 4683 | bssid, chan); |
| 4684 | if (res > 0 && res < (int) sizeof(buf)) |
| 4685 | res = wpa_command(intf, buf); |
| 4686 | |
| 4687 | if (res < 0 || res >= (int) sizeof(buf)) { |
| 4688 | send_resp(dut, conn, SIGMA_ERROR, |
| 4689 | "errorCode,Failed to run DRIVER FASTREASSOC"); |
Ashwini Patil | 467efef | 2017-05-25 12:18:27 +0530 | [diff] [blame] | 4690 | goto close_mon_conn; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4691 | } |
| 4692 | #else /* ANDROID */ |
| 4693 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 4694 | "Reassoc using iwpriv - skip chan=%d info", |
| 4695 | chan); |
| 4696 | snprintf(buf, sizeof(buf), "iwpriv %s reassoc", intf); |
| 4697 | if (system(buf) != 0) { |
| 4698 | sigma_dut_print(dut, DUT_MSG_ERROR, "%s failed", buf); |
Ashwini Patil | 467efef | 2017-05-25 12:18:27 +0530 | [diff] [blame] | 4699 | status = -2; |
| 4700 | goto close_mon_conn; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4701 | } |
| 4702 | #endif /* ANDROID */ |
| 4703 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 4704 | "sta_reassoc: Run %s successful", buf); |
| 4705 | } else if (wpa_command(intf, "REASSOCIATE")) { |
| 4706 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to " |
| 4707 | "request reassociation"); |
Ashwini Patil | 467efef | 2017-05-25 12:18:27 +0530 | [diff] [blame] | 4708 | goto close_mon_conn; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4709 | } |
| 4710 | |
| 4711 | res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED", |
| 4712 | buf, sizeof(buf)); |
Ashwini Patil | 467efef | 2017-05-25 12:18:27 +0530 | [diff] [blame] | 4713 | if (res < 0) { |
| 4714 | sigma_dut_print(dut, DUT_MSG_INFO, "Connection did not complete"); |
| 4715 | status = -1; |
| 4716 | goto close_mon_conn; |
| 4717 | } |
| 4718 | status = 1; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4719 | |
Ashwini Patil | 467efef | 2017-05-25 12:18:27 +0530 | [diff] [blame] | 4720 | close_mon_conn: |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4721 | wpa_ctrl_detach(ctrl); |
| 4722 | wpa_ctrl_close(ctrl); |
Ashwini Patil | 467efef | 2017-05-25 12:18:27 +0530 | [diff] [blame] | 4723 | return status; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4724 | } |
| 4725 | |
| 4726 | |
| 4727 | static void hs2_clear_credentials(const char *intf) |
| 4728 | { |
| 4729 | wpa_command(intf, "REMOVE_CRED all"); |
| 4730 | } |
| 4731 | |
| 4732 | |
Lior David | cc88b56 | 2017-01-03 18:52:09 +0200 | [diff] [blame] | 4733 | #ifdef __linux__ |
| 4734 | static int wil6210_get_aid(struct sigma_dut *dut, const char *bssid, |
| 4735 | unsigned int *aid) |
| 4736 | { |
Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 4737 | const char *pattern = "AID[ \t]+([0-9]+)"; |
Lior David | cc88b56 | 2017-01-03 18:52:09 +0200 | [diff] [blame] | 4738 | |
Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 4739 | return wil6210_get_sta_info_field(dut, bssid, pattern, aid); |
Lior David | cc88b56 | 2017-01-03 18:52:09 +0200 | [diff] [blame] | 4740 | } |
| 4741 | #endif /* __linux__ */ |
| 4742 | |
| 4743 | |
| 4744 | static int sta_get_aid_60g(struct sigma_dut *dut, const char *bssid, |
| 4745 | unsigned int *aid) |
| 4746 | { |
| 4747 | switch (get_driver_type()) { |
| 4748 | #ifdef __linux__ |
| 4749 | case DRIVER_WIL6210: |
| 4750 | return wil6210_get_aid(dut, bssid, aid); |
| 4751 | #endif /* __linux__ */ |
| 4752 | default: |
| 4753 | sigma_dut_print(dut, DUT_MSG_ERROR, "get AID not supported"); |
| 4754 | return -1; |
| 4755 | } |
| 4756 | } |
| 4757 | |
| 4758 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4759 | static int sta_get_parameter_60g(struct sigma_dut *dut, struct sigma_conn *conn, |
| 4760 | struct sigma_cmd *cmd) |
| 4761 | { |
| 4762 | char buf[MAX_CMD_LEN]; |
| 4763 | char bss_list[MAX_CMD_LEN]; |
| 4764 | const char *parameter = get_param(cmd, "Parameter"); |
| 4765 | |
| 4766 | if (parameter == NULL) |
| 4767 | return -1; |
| 4768 | |
Lior David | cc88b56 | 2017-01-03 18:52:09 +0200 | [diff] [blame] | 4769 | if (strcasecmp(parameter, "AID") == 0) { |
| 4770 | unsigned int aid = 0; |
| 4771 | char bssid[20]; |
| 4772 | |
| 4773 | if (get_wpa_status(get_station_ifname(), "bssid", |
| 4774 | bssid, sizeof(bssid)) < 0) { |
| 4775 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4776 | "could not get bssid"); |
| 4777 | return -2; |
| 4778 | } |
| 4779 | |
| 4780 | if (sta_get_aid_60g(dut, bssid, &aid)) |
| 4781 | return -2; |
| 4782 | |
| 4783 | snprintf(buf, sizeof(buf), "aid,%d", aid); |
| 4784 | sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf); |
| 4785 | send_resp(dut, conn, SIGMA_COMPLETE, buf); |
| 4786 | return 0; |
| 4787 | } |
| 4788 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4789 | if (strcasecmp(parameter, "DiscoveredDevList") == 0) { |
| 4790 | char *bss_line; |
| 4791 | char *bss_id = NULL; |
| 4792 | const char *ifname = get_param(cmd, "Interface"); |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 4793 | char *saveptr; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4794 | |
| 4795 | if (ifname == NULL) { |
| 4796 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 4797 | "For get DiscoveredDevList need Interface name."); |
| 4798 | return -1; |
| 4799 | } |
| 4800 | |
| 4801 | /* |
| 4802 | * Use "BSS RANGE=ALL MASK=0x2" which provides a list |
| 4803 | * of BSSIDs in "bssid=<BSSID>\n" |
| 4804 | */ |
| 4805 | if (wpa_command_resp(ifname, "BSS RANGE=ALL MASK=0x2", |
| 4806 | bss_list, |
| 4807 | sizeof(bss_list)) < 0) { |
| 4808 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4809 | "Failed to get bss list"); |
| 4810 | return -1; |
| 4811 | } |
| 4812 | |
| 4813 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 4814 | "bss list for ifname:%s is:%s", |
| 4815 | ifname, bss_list); |
| 4816 | |
| 4817 | snprintf(buf, sizeof(buf), "DeviceList"); |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 4818 | bss_line = strtok_r(bss_list, "\n", &saveptr); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4819 | while (bss_line) { |
| 4820 | if (sscanf(bss_line, "bssid=%ms", &bss_id) > 0 && |
| 4821 | bss_id) { |
| 4822 | int len; |
| 4823 | |
| 4824 | len = snprintf(buf + strlen(buf), |
| 4825 | sizeof(buf) - strlen(buf), |
| 4826 | ",%s", bss_id); |
| 4827 | free(bss_id); |
| 4828 | bss_id = NULL; |
| 4829 | if (len < 0) { |
| 4830 | sigma_dut_print(dut, |
| 4831 | DUT_MSG_ERROR, |
| 4832 | "Failed to read BSSID"); |
| 4833 | send_resp(dut, conn, SIGMA_ERROR, |
| 4834 | "ErrorCode,Failed to read BSS ID"); |
| 4835 | return 0; |
| 4836 | } |
| 4837 | |
| 4838 | if ((size_t) len >= sizeof(buf) - strlen(buf)) { |
| 4839 | sigma_dut_print(dut, |
| 4840 | DUT_MSG_ERROR, |
| 4841 | "Response buf too small for list"); |
| 4842 | send_resp(dut, conn, |
| 4843 | SIGMA_ERROR, |
| 4844 | "ErrorCode,Response buf too small for list"); |
| 4845 | return 0; |
| 4846 | } |
| 4847 | } |
| 4848 | |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 4849 | bss_line = strtok_r(NULL, "\n", &saveptr); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4850 | } |
| 4851 | |
| 4852 | sigma_dut_print(dut, DUT_MSG_INFO, "DiscoveredDevList is %s", |
| 4853 | buf); |
| 4854 | send_resp(dut, conn, SIGMA_COMPLETE, buf); |
| 4855 | return 0; |
| 4856 | } |
| 4857 | |
| 4858 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter"); |
| 4859 | return 0; |
| 4860 | } |
| 4861 | |
| 4862 | |
| 4863 | static int cmd_sta_get_parameter(struct sigma_dut *dut, struct sigma_conn *conn, |
| 4864 | struct sigma_cmd *cmd) |
| 4865 | { |
| 4866 | const char *program = get_param(cmd, "Program"); |
| 4867 | |
| 4868 | if (program == NULL) |
| 4869 | return -1; |
| 4870 | |
| 4871 | if (strcasecmp(program, "P2PNFC") == 0) |
| 4872 | return p2p_cmd_sta_get_parameter(dut, conn, cmd); |
| 4873 | |
| 4874 | if (strcasecmp(program, "60ghz") == 0) |
| 4875 | return sta_get_parameter_60g(dut, conn, cmd); |
| 4876 | |
| 4877 | #ifdef ANDROID_NAN |
| 4878 | if (strcasecmp(program, "NAN") == 0) |
Amarnath Hullur Subramanyam | 1854ec6 | 2016-08-11 19:29:35 -0700 | [diff] [blame] | 4879 | return nan_cmd_sta_get_parameter(dut, conn, cmd); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4880 | #endif /* ANDROID_NAN */ |
| 4881 | |
Amarnath Hullur Subramanyam | 9c381f5 | 2017-03-17 00:04:41 -0700 | [diff] [blame] | 4882 | #ifdef MIRACAST |
| 4883 | if (strcasecmp(program, "WFD") == 0 || |
| 4884 | strcasecmp(program, "DisplayR2") == 0) |
| 4885 | return miracast_cmd_sta_get_parameter(dut, conn, cmd); |
| 4886 | #endif /* MIRACAST */ |
| 4887 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4888 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter"); |
| 4889 | return 0; |
| 4890 | } |
| 4891 | |
| 4892 | |
| 4893 | static void sta_reset_default_ath(struct sigma_dut *dut, const char *intf, |
| 4894 | const char *type) |
| 4895 | { |
| 4896 | char buf[100]; |
| 4897 | |
| 4898 | if (dut->program == PROGRAM_VHT) { |
| 4899 | snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf); |
| 4900 | if (system(buf) != 0) { |
| 4901 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4902 | "iwpriv %s chwidth failed", intf); |
| 4903 | } |
| 4904 | |
| 4905 | snprintf(buf, sizeof(buf), "iwpriv %s mode 11ACVHT80", intf); |
| 4906 | if (system(buf) != 0) { |
| 4907 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4908 | "iwpriv %s mode 11ACVHT80 failed", |
| 4909 | intf); |
| 4910 | } |
| 4911 | |
| 4912 | snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs -1", intf); |
| 4913 | if (system(buf) != 0) { |
| 4914 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4915 | "iwpriv %s vhtmcs -1 failed", intf); |
| 4916 | } |
| 4917 | } |
| 4918 | |
| 4919 | if (dut->program == PROGRAM_HT) { |
| 4920 | snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf); |
| 4921 | if (system(buf) != 0) { |
| 4922 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4923 | "iwpriv %s chwidth failed", intf); |
| 4924 | } |
| 4925 | |
| 4926 | snprintf(buf, sizeof(buf), "iwpriv %s mode 11naht40", intf); |
| 4927 | if (system(buf) != 0) { |
| 4928 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4929 | "iwpriv %s mode 11naht40 failed", |
| 4930 | intf); |
| 4931 | } |
| 4932 | |
| 4933 | snprintf(buf, sizeof(buf), "iwpriv %s set11NRates 0", intf); |
| 4934 | if (system(buf) != 0) { |
| 4935 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4936 | "iwpriv set11NRates failed"); |
| 4937 | } |
| 4938 | } |
| 4939 | |
| 4940 | if (dut->program == PROGRAM_VHT || dut->program == PROGRAM_HT) { |
| 4941 | snprintf(buf, sizeof(buf), "iwpriv %s powersave 0", intf); |
| 4942 | if (system(buf) != 0) { |
| 4943 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4944 | "disabling powersave failed"); |
| 4945 | } |
| 4946 | |
| 4947 | /* Reset CTS width */ |
| 4948 | snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 54 0", |
| 4949 | intf); |
| 4950 | if (system(buf) != 0) { |
| 4951 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4952 | "wifitool %s beeliner_fw_test 54 0 failed", |
| 4953 | intf); |
| 4954 | } |
| 4955 | |
| 4956 | /* Enable Dynamic Bandwidth signalling by default */ |
| 4957 | snprintf(buf, sizeof(buf), "iwpriv %s cwmenable 1", intf); |
| 4958 | if (system(buf) != 0) { |
| 4959 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4960 | "iwpriv %s cwmenable 1 failed", intf); |
| 4961 | } |
| 4962 | |
| 4963 | snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", intf); |
| 4964 | if (system(buf) != 0) { |
| 4965 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4966 | "iwpriv rts failed"); |
| 4967 | } |
| 4968 | } |
| 4969 | |
| 4970 | if (type && strcasecmp(type, "Testbed") == 0) { |
| 4971 | dut->testbed_flag_txsp = 1; |
| 4972 | dut->testbed_flag_rxsp = 1; |
| 4973 | /* STA has to set spatial stream to 2 per Appendix H */ |
| 4974 | snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0xfff0", intf); |
| 4975 | if (system(buf) != 0) { |
| 4976 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4977 | "iwpriv vht_mcsmap failed"); |
| 4978 | } |
| 4979 | |
| 4980 | /* Disable LDPC per Appendix H */ |
| 4981 | snprintf(buf, sizeof(buf), "iwpriv %s ldpc 0", intf); |
| 4982 | if (system(buf) != 0) { |
| 4983 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4984 | "iwpriv %s ldpc 0 failed", intf); |
| 4985 | } |
| 4986 | |
| 4987 | snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf); |
| 4988 | if (system(buf) != 0) { |
| 4989 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4990 | "iwpriv amsdu failed"); |
| 4991 | } |
| 4992 | |
| 4993 | /* TODO: Disable STBC 2x1 transmit and receive */ |
| 4994 | snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc 0", intf); |
| 4995 | if (system(buf) != 0) { |
| 4996 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4997 | "Disable tx_stbc 0 failed"); |
| 4998 | } |
| 4999 | |
| 5000 | snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc 0", intf); |
| 5001 | if (system(buf) != 0) { |
| 5002 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5003 | "Disable rx_stbc 0 failed"); |
| 5004 | } |
| 5005 | |
| 5006 | /* STA has to disable Short GI per Appendix H */ |
| 5007 | snprintf(buf, sizeof(buf), "iwpriv %s shortgi 0", intf); |
| 5008 | if (system(buf) != 0) { |
| 5009 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5010 | "iwpriv %s shortgi 0 failed", intf); |
| 5011 | } |
| 5012 | } |
| 5013 | |
| 5014 | if (type && strcasecmp(type, "DUT") == 0) { |
| 5015 | snprintf(buf, sizeof(buf), "iwpriv %s nss 3", intf); |
| 5016 | if (system(buf) != 0) { |
| 5017 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5018 | "iwpriv %s nss 3 failed", intf); |
| 5019 | } |
| 5020 | |
| 5021 | snprintf(buf, sizeof(buf), "iwpriv %s shortgi 1", intf); |
| 5022 | if (system(buf) != 0) { |
| 5023 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5024 | "iwpriv %s shortgi 1 failed", intf); |
| 5025 | } |
| 5026 | } |
| 5027 | } |
| 5028 | |
| 5029 | |
| 5030 | static int cmd_sta_reset_default(struct sigma_dut *dut, |
| 5031 | struct sigma_conn *conn, |
| 5032 | struct sigma_cmd *cmd) |
| 5033 | { |
| 5034 | int cmd_sta_p2p_reset(struct sigma_dut *dut, struct sigma_conn *conn, |
| 5035 | struct sigma_cmd *cmd); |
| 5036 | const char *intf = get_param(cmd, "Interface"); |
| 5037 | const char *type; |
Amarnath Hullur Subramanyam | 9c381f5 | 2017-03-17 00:04:41 -0700 | [diff] [blame] | 5038 | const char *program = get_param(cmd, "program"); |
Ankita Bajaj | 0d5825b | 2017-10-25 16:20:17 +0530 | [diff] [blame] | 5039 | const char *dev_role = get_param(cmd, "DevRole"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5040 | |
Amarnath Hullur Subramanyam | 9c381f5 | 2017-03-17 00:04:41 -0700 | [diff] [blame] | 5041 | if (!program) |
| 5042 | program = get_param(cmd, "prog"); |
| 5043 | dut->program = sigma_program_to_enum(program); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5044 | dut->device_type = STA_unknown; |
| 5045 | type = get_param(cmd, "type"); |
| 5046 | if (type && strcasecmp(type, "Testbed") == 0) |
| 5047 | dut->device_type = STA_testbed; |
| 5048 | if (type && strcasecmp(type, "DUT") == 0) |
| 5049 | dut->device_type = STA_dut; |
| 5050 | |
| 5051 | if (dut->program == PROGRAM_TDLS) { |
| 5052 | /* Clear TDLS testing mode */ |
| 5053 | wpa_command(intf, "SET tdls_disabled 0"); |
| 5054 | wpa_command(intf, "SET tdls_testing 0"); |
| 5055 | dut->no_tpk_expiration = 0; |
Pradeep Reddy POTTETI | 8ce2a23 | 2016-10-28 12:17:32 +0530 | [diff] [blame] | 5056 | if (get_driver_type() == DRIVER_WCN) { |
| 5057 | /* Enable the WCN driver in TDLS Explicit trigger mode |
| 5058 | */ |
| 5059 | wpa_command(intf, "SET tdls_external_control 0"); |
| 5060 | wpa_command(intf, "SET tdls_trigger_control 0"); |
| 5061 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5062 | } |
| 5063 | |
Amarnath Hullur Subramanyam | 9c381f5 | 2017-03-17 00:04:41 -0700 | [diff] [blame] | 5064 | #ifdef MIRACAST |
| 5065 | if (dut->program == PROGRAM_WFD || |
| 5066 | dut->program == PROGRAM_DISPLAYR2) |
| 5067 | miracast_sta_reset_default(dut, conn, cmd); |
| 5068 | #endif /* MIRACAST */ |
| 5069 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5070 | switch (get_driver_type()) { |
| 5071 | case DRIVER_ATHEROS: |
| 5072 | sta_reset_default_ath(dut, intf, type); |
| 5073 | break; |
| 5074 | default: |
| 5075 | break; |
| 5076 | } |
| 5077 | |
| 5078 | #ifdef ANDROID_NAN |
| 5079 | if (dut->program == PROGRAM_NAN) |
| 5080 | nan_cmd_sta_reset_default(dut, conn, cmd); |
| 5081 | #endif /* ANDROID_NAN */ |
| 5082 | |
| 5083 | if (dut->program == PROGRAM_HS2_R2) { |
| 5084 | unlink("SP/wi-fi.org/pps.xml"); |
| 5085 | if (system("rm -r SP/*") != 0) { |
| 5086 | } |
| 5087 | unlink("next-client-cert.pem"); |
| 5088 | unlink("next-client-key.pem"); |
| 5089 | } |
| 5090 | |
| 5091 | if (dut->program == PROGRAM_60GHZ) { |
| 5092 | const char *dev_role = get_param(cmd, "DevRole"); |
| 5093 | |
| 5094 | if (!dev_role) { |
| 5095 | send_resp(dut, conn, SIGMA_ERROR, |
| 5096 | "errorCode,Missing DevRole argument"); |
| 5097 | return 0; |
| 5098 | } |
| 5099 | |
| 5100 | if (strcasecmp(dev_role, "STA") == 0) |
| 5101 | dut->dev_role = DEVROLE_STA; |
| 5102 | else if (strcasecmp(dev_role, "PCP") == 0) |
| 5103 | dut->dev_role = DEVROLE_PCP; |
| 5104 | else { |
| 5105 | send_resp(dut, conn, SIGMA_ERROR, |
| 5106 | "errorCode,Unknown DevRole"); |
| 5107 | return 0; |
| 5108 | } |
| 5109 | |
| 5110 | if (dut->device_type == STA_unknown) { |
| 5111 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5112 | "Device type is not STA testbed or DUT"); |
| 5113 | send_resp(dut, conn, SIGMA_ERROR, |
| 5114 | "errorCode,Unknown device type"); |
| 5115 | return 0; |
| 5116 | } |
| 5117 | } |
| 5118 | |
| 5119 | wpa_command(intf, "WPS_ER_STOP"); |
| 5120 | wpa_command(intf, "FLUSH"); |
vamsi krishna | f39bc1e | 2017-08-23 17:37:53 +0530 | [diff] [blame] | 5121 | wpa_command(intf, "ERP_FLUSH"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5122 | wpa_command(intf, "SET radio_disabled 0"); |
| 5123 | |
| 5124 | if (dut->tmp_mac_addr && dut->set_macaddr) { |
| 5125 | dut->tmp_mac_addr = 0; |
| 5126 | if (system(dut->set_macaddr) != 0) { |
| 5127 | sigma_dut_print(dut, DUT_MSG_INFO, "Failed to clear " |
| 5128 | "temporary MAC address"); |
| 5129 | } |
| 5130 | } |
| 5131 | |
| 5132 | set_ps(intf, dut, 0); |
| 5133 | |
| 5134 | if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2) { |
| 5135 | wpa_command(intf, "SET interworking 1"); |
| 5136 | wpa_command(intf, "SET hs20 1"); |
| 5137 | } |
| 5138 | |
| 5139 | if (dut->program == PROGRAM_HS2_R2) { |
| 5140 | wpa_command(intf, "SET pmf 1"); |
| 5141 | } else { |
| 5142 | wpa_command(intf, "SET pmf 0"); |
| 5143 | } |
| 5144 | |
| 5145 | hs2_clear_credentials(intf); |
| 5146 | wpa_command(intf, "SET hessid 00:00:00:00:00:00"); |
| 5147 | wpa_command(intf, "SET access_network_type 15"); |
| 5148 | |
| 5149 | static_ip_file(0, NULL, NULL, NULL); |
| 5150 | kill_dhcp_client(dut, intf); |
| 5151 | clear_ip_addr(dut, intf); |
| 5152 | |
| 5153 | dut->er_oper_performed = 0; |
| 5154 | dut->er_oper_bssid[0] = '\0'; |
| 5155 | |
priyadharshini gowthaman | ad6cbba | 2016-10-04 10:39:58 -0700 | [diff] [blame] | 5156 | if (dut->program == PROGRAM_LOC) { |
| 5157 | /* Disable Interworking by default */ |
| 5158 | wpa_command(get_station_ifname(), "SET interworking 0"); |
| 5159 | } |
| 5160 | |
Ashwini Patil | 0040258 | 2017-04-13 12:29:39 +0530 | [diff] [blame] | 5161 | if (dut->program == PROGRAM_MBO) { |
| 5162 | free(dut->non_pref_ch_list); |
| 5163 | dut->non_pref_ch_list = NULL; |
Ashwini Patil | 5acd738 | 2017-04-13 15:55:04 +0530 | [diff] [blame] | 5164 | free(dut->btm_query_cand_list); |
| 5165 | dut->btm_query_cand_list = NULL; |
Ashwini Patil | c63161e | 2017-04-13 16:30:23 +0530 | [diff] [blame] | 5166 | wpa_command(intf, "SET reject_btm_req_reason 0"); |
Ashwini Patil | a75de5a | 2017-04-13 16:35:05 +0530 | [diff] [blame] | 5167 | wpa_command(intf, "SET ignore_assoc_disallow 0"); |
Ashwini Patil | d174f2c | 2017-04-13 16:49:46 +0530 | [diff] [blame] | 5168 | wpa_command(intf, "SET gas_address3 0"); |
Ashwini Patil | 9183fdb | 2017-04-13 16:58:25 +0530 | [diff] [blame] | 5169 | wpa_command(intf, "SET roaming 1"); |
Ashwini Patil | 0040258 | 2017-04-13 12:29:39 +0530 | [diff] [blame] | 5170 | } |
| 5171 | |
Jouni Malinen | 3c367e8 | 2017-06-23 17:01:47 +0300 | [diff] [blame] | 5172 | free(dut->rsne_override); |
| 5173 | dut->rsne_override = NULL; |
| 5174 | |
Jouni Malinen | 6814313 | 2017-09-02 02:34:08 +0300 | [diff] [blame] | 5175 | free(dut->sae_commit_override); |
| 5176 | dut->sae_commit_override = NULL; |
| 5177 | |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 5178 | dut->dpp_conf_id = -1; |
Jouni Malinen | b1dd21f | 2017-11-13 19:14:29 +0200 | [diff] [blame] | 5179 | free(dut->dpp_peer_uri); |
| 5180 | dut->dpp_peer_uri = NULL; |
Jouni Malinen | 63d5041 | 2017-11-24 11:55:38 +0200 | [diff] [blame] | 5181 | dut->dpp_local_bootstrap = -1; |
Jouni Malinen | 5011fb5 | 2017-12-05 21:00:15 +0200 | [diff] [blame] | 5182 | wpa_command(intf, "SET dpp_config_processing 2"); |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 5183 | |
Jouni Malinen | fac9cad | 2017-10-10 18:35:55 +0300 | [diff] [blame] | 5184 | wpa_command(intf, "VENDOR_ELEM_REMOVE 13 *"); |
| 5185 | |
Ankita Bajaj | a2cb567 | 2017-10-25 16:08:28 +0530 | [diff] [blame] | 5186 | if (dut->program == PROGRAM_OCE) |
| 5187 | wpa_command(intf, "SET oce 1"); |
| 5188 | |
Ankita Bajaj | 0d5825b | 2017-10-25 16:20:17 +0530 | [diff] [blame] | 5189 | if (dev_role && strcasecmp(dev_role, "STA-CFON") == 0) { |
| 5190 | dut->dev_role = DEVROLE_STA_CFON; |
| 5191 | return sta_cfon_reset_default(dut, conn, cmd); |
| 5192 | } |
| 5193 | |
Priyadharshini Gowthaman | a7dfd49 | 2015-11-09 14:34:08 -0800 | [diff] [blame] | 5194 | if (dut->program != PROGRAM_VHT) |
| 5195 | return cmd_sta_p2p_reset(dut, conn, cmd); |
| 5196 | return 1; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5197 | } |
| 5198 | |
| 5199 | |
| 5200 | static int cmd_sta_get_events(struct sigma_dut *dut, struct sigma_conn *conn, |
| 5201 | struct sigma_cmd *cmd) |
| 5202 | { |
| 5203 | const char *program = get_param(cmd, "Program"); |
| 5204 | |
| 5205 | if (program == NULL) |
| 5206 | return -1; |
| 5207 | #ifdef ANDROID_NAN |
| 5208 | if (strcasecmp(program, "NAN") == 0) |
| 5209 | return nan_cmd_sta_get_events(dut, conn, cmd); |
| 5210 | #endif /* ANDROID_NAN */ |
| 5211 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter"); |
| 5212 | return 0; |
| 5213 | } |
| 5214 | |
| 5215 | |
| 5216 | static int cmd_sta_exec_action(struct sigma_dut *dut, struct sigma_conn *conn, |
| 5217 | struct sigma_cmd *cmd) |
| 5218 | { |
| 5219 | const char *program = get_param(cmd, "Prog"); |
| 5220 | |
| 5221 | if (program == NULL) |
| 5222 | return -1; |
| 5223 | #ifdef ANDROID_NAN |
| 5224 | if (strcasecmp(program, "NAN") == 0) |
| 5225 | return nan_cmd_sta_exec_action(dut, conn, cmd); |
| 5226 | #endif /* ANDROID_NAN */ |
priyadharshini gowthaman | d66913a | 2016-07-29 15:11:17 -0700 | [diff] [blame] | 5227 | if (strcasecmp(program, "Loc") == 0) |
| 5228 | return loc_cmd_sta_exec_action(dut, conn, cmd); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5229 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter"); |
| 5230 | return 0; |
| 5231 | } |
| 5232 | |
| 5233 | |
| 5234 | static int cmd_sta_set_11n(struct sigma_dut *dut, struct sigma_conn *conn, |
| 5235 | struct sigma_cmd *cmd) |
| 5236 | { |
| 5237 | const char *intf = get_param(cmd, "Interface"); |
| 5238 | const char *val, *mcs32, *rate; |
| 5239 | |
| 5240 | val = get_param(cmd, "GREENFIELD"); |
| 5241 | if (val) { |
| 5242 | if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) { |
| 5243 | /* Enable GD */ |
| 5244 | send_resp(dut, conn, SIGMA_ERROR, |
| 5245 | "ErrorCode,GF not supported"); |
| 5246 | return 0; |
| 5247 | } |
| 5248 | } |
| 5249 | |
| 5250 | val = get_param(cmd, "SGI20"); |
| 5251 | if (val) { |
| 5252 | switch (get_driver_type()) { |
| 5253 | case DRIVER_ATHEROS: |
| 5254 | ath_sta_set_sgi(dut, intf, val); |
| 5255 | break; |
| 5256 | default: |
| 5257 | send_resp(dut, conn, SIGMA_ERROR, |
| 5258 | "ErrorCode,SGI20 not supported"); |
| 5259 | return 0; |
| 5260 | } |
| 5261 | } |
| 5262 | |
| 5263 | mcs32 = get_param(cmd, "MCS32"); /* HT Duplicate Mode Enable/Disable */ |
| 5264 | rate = get_param(cmd, "MCS_FIXEDRATE"); /* Fixed MCS rate (0..31) */ |
| 5265 | if (mcs32 && rate) { |
| 5266 | /* TODO */ |
| 5267 | send_resp(dut, conn, SIGMA_ERROR, |
| 5268 | "ErrorCode,MCS32,MCS_FIXEDRATE not supported"); |
| 5269 | return 0; |
| 5270 | } else if (mcs32 && !rate) { |
| 5271 | /* TODO */ |
| 5272 | send_resp(dut, conn, SIGMA_ERROR, |
| 5273 | "ErrorCode,MCS32 not supported"); |
| 5274 | return 0; |
| 5275 | } else if (!mcs32 && rate) { |
| 5276 | switch (get_driver_type()) { |
| 5277 | case DRIVER_ATHEROS: |
priyadharshini gowthaman | e5e2517 | 2015-12-08 14:53:48 -0800 | [diff] [blame] | 5278 | novap_reset(dut, intf); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5279 | ath_sta_set_11nrates(dut, intf, rate); |
| 5280 | break; |
| 5281 | default: |
| 5282 | send_resp(dut, conn, SIGMA_ERROR, |
| 5283 | "ErrorCode,MCS32_FIXEDRATE not supported"); |
| 5284 | return 0; |
| 5285 | } |
| 5286 | } |
| 5287 | |
| 5288 | return cmd_sta_set_wireless_common(intf, dut, conn, cmd); |
| 5289 | } |
| 5290 | |
| 5291 | |
| 5292 | static int cmd_sta_set_wireless_vht(struct sigma_dut *dut, |
| 5293 | struct sigma_conn *conn, |
| 5294 | struct sigma_cmd *cmd) |
| 5295 | { |
| 5296 | const char *intf = get_param(cmd, "Interface"); |
| 5297 | const char *val; |
| 5298 | char buf[30]; |
| 5299 | int tkip = -1; |
| 5300 | int wep = -1; |
| 5301 | |
| 5302 | val = get_param(cmd, "SGI80"); |
| 5303 | if (val) { |
| 5304 | int sgi80; |
| 5305 | |
| 5306 | sgi80 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0; |
| 5307 | snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d", intf, sgi80); |
| 5308 | if (system(buf) != 0) { |
| 5309 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5310 | "iwpriv shortgi failed"); |
| 5311 | } |
| 5312 | } |
| 5313 | |
| 5314 | val = get_param(cmd, "TxBF"); |
| 5315 | if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) { |
| 5316 | snprintf(buf, sizeof(buf), "iwpriv %s vhtsubfee 1", intf); |
| 5317 | if (system(buf) != 0) { |
| 5318 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5319 | "iwpriv vhtsubfee failed"); |
| 5320 | } |
| 5321 | snprintf(buf, sizeof(buf), "iwpriv %s vhtsubfer 1", intf); |
| 5322 | if (system(buf) != 0) { |
| 5323 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5324 | "iwpriv vhtsubfer failed"); |
| 5325 | } |
| 5326 | } |
| 5327 | |
| 5328 | val = get_param(cmd, "MU_TxBF"); |
| 5329 | if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) { |
| 5330 | switch (get_driver_type()) { |
| 5331 | case DRIVER_ATHEROS: |
| 5332 | ath_sta_set_txsp_stream(dut, intf, "1SS"); |
| 5333 | ath_sta_set_rxsp_stream(dut, intf, "1SS"); |
| 5334 | case DRIVER_WCN: |
| 5335 | if (wcn_sta_set_sp_stream(dut, intf, "1SS") < 0) { |
| 5336 | send_resp(dut, conn, SIGMA_ERROR, |
| 5337 | "ErrorCode,Failed to set RX/TXSP_STREAM"); |
| 5338 | return 0; |
| 5339 | } |
| 5340 | default: |
| 5341 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5342 | "Setting SP_STREAM not supported"); |
| 5343 | break; |
| 5344 | } |
| 5345 | snprintf(buf, sizeof(buf), "iwpriv %s vhtmubfee 1", intf); |
| 5346 | if (system(buf) != 0) { |
| 5347 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5348 | "iwpriv vhtmubfee failed"); |
| 5349 | } |
| 5350 | snprintf(buf, sizeof(buf), "iwpriv %s vhtmubfer 1", intf); |
| 5351 | if (system(buf) != 0) { |
| 5352 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5353 | "iwpriv vhtmubfer failed"); |
| 5354 | } |
| 5355 | } |
| 5356 | |
| 5357 | val = get_param(cmd, "LDPC"); |
| 5358 | if (val) { |
| 5359 | int ldpc; |
| 5360 | |
| 5361 | ldpc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0; |
| 5362 | snprintf(buf, sizeof(buf), "iwpriv %s ldpc %d", intf, ldpc); |
| 5363 | if (system(buf) != 0) { |
| 5364 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5365 | "iwpriv ldpc failed"); |
| 5366 | } |
| 5367 | } |
| 5368 | |
| 5369 | val = get_param(cmd, "opt_md_notif_ie"); |
| 5370 | if (val) { |
| 5371 | char *result = NULL; |
| 5372 | char delim[] = ";"; |
| 5373 | char token[30]; |
| 5374 | int value, config_val = 0; |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 5375 | char *saveptr; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5376 | |
Peng Xu | b8fc5cc | 2017-05-10 17:27:28 -0700 | [diff] [blame] | 5377 | strlcpy(token, val, sizeof(token)); |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 5378 | result = strtok_r(token, delim, &saveptr); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5379 | |
| 5380 | /* Extract the NSS information */ |
| 5381 | if (result) { |
| 5382 | value = atoi(result); |
| 5383 | switch (value) { |
| 5384 | case 1: |
| 5385 | config_val = 1; |
| 5386 | break; |
| 5387 | case 2: |
| 5388 | config_val = 3; |
| 5389 | break; |
| 5390 | case 3: |
| 5391 | config_val = 7; |
| 5392 | break; |
| 5393 | case 4: |
| 5394 | config_val = 15; |
| 5395 | break; |
| 5396 | default: |
| 5397 | config_val = 3; |
| 5398 | break; |
| 5399 | } |
| 5400 | |
| 5401 | snprintf(buf, sizeof(buf), "iwpriv %s rxchainmask %d", |
| 5402 | intf, config_val); |
| 5403 | if (system(buf) != 0) { |
| 5404 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5405 | "iwpriv rxchainmask failed"); |
| 5406 | } |
| 5407 | |
| 5408 | snprintf(buf, sizeof(buf), "iwpriv %s txchainmask %d", |
| 5409 | intf, config_val); |
| 5410 | if (system(buf) != 0) { |
| 5411 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5412 | "iwpriv txchainmask failed"); |
| 5413 | } |
| 5414 | } |
| 5415 | |
| 5416 | /* Extract the channel width information */ |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 5417 | result = strtok_r(NULL, delim, &saveptr); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5418 | if (result) { |
| 5419 | value = atoi(result); |
| 5420 | switch (value) { |
| 5421 | case 20: |
| 5422 | config_val = 0; |
| 5423 | break; |
| 5424 | case 40: |
| 5425 | config_val = 1; |
| 5426 | break; |
| 5427 | case 80: |
| 5428 | config_val = 2; |
| 5429 | break; |
| 5430 | case 160: |
| 5431 | config_val = 3; |
| 5432 | break; |
| 5433 | default: |
| 5434 | config_val = 2; |
| 5435 | break; |
| 5436 | } |
| 5437 | |
| 5438 | dut->chwidth = config_val; |
| 5439 | |
| 5440 | snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d", |
| 5441 | intf, config_val); |
| 5442 | if (system(buf) != 0) { |
| 5443 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5444 | "iwpriv chwidth failed"); |
| 5445 | } |
| 5446 | } |
| 5447 | |
| 5448 | snprintf(buf, sizeof(buf), "iwpriv %s opmode_notify 1", intf); |
| 5449 | if (system(buf) != 0) { |
| 5450 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5451 | "iwpriv opmode_notify failed"); |
| 5452 | } |
| 5453 | } |
| 5454 | |
| 5455 | val = get_param(cmd, "nss_mcs_cap"); |
| 5456 | if (val) { |
| 5457 | int nss, mcs; |
| 5458 | char token[20]; |
| 5459 | char *result = NULL; |
| 5460 | unsigned int vht_mcsmap = 0; |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 5461 | char *saveptr; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5462 | |
Peng Xu | b8fc5cc | 2017-05-10 17:27:28 -0700 | [diff] [blame] | 5463 | strlcpy(token, val, sizeof(token)); |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 5464 | result = strtok_r(token, ";", &saveptr); |
Pradeep Reddy POTTETI | cd649a2 | 2016-01-29 12:55:59 +0530 | [diff] [blame] | 5465 | if (!result) { |
| 5466 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5467 | "VHT NSS not specified"); |
| 5468 | return 0; |
| 5469 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5470 | nss = atoi(result); |
| 5471 | |
| 5472 | snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss); |
| 5473 | if (system(buf) != 0) { |
| 5474 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5475 | "iwpriv nss failed"); |
| 5476 | } |
| 5477 | |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 5478 | result = strtok_r(NULL, ";", &saveptr); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5479 | if (result == NULL) { |
| 5480 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5481 | "VHTMCS NOT SPECIFIED!"); |
| 5482 | return 0; |
| 5483 | } |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 5484 | result = strtok_r(result, "-", &saveptr); |
| 5485 | result = strtok_r(NULL, "-", &saveptr); |
Pradeep Reddy POTTETI | cd649a2 | 2016-01-29 12:55:59 +0530 | [diff] [blame] | 5486 | if (!result) { |
| 5487 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5488 | "VHT MCS not specified"); |
| 5489 | return 0; |
| 5490 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5491 | mcs = atoi(result); |
| 5492 | |
| 5493 | snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs %d", intf, mcs); |
| 5494 | if (system(buf) != 0) { |
| 5495 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5496 | "iwpriv mcs failed"); |
| 5497 | } |
| 5498 | |
| 5499 | switch (nss) { |
| 5500 | case 1: |
| 5501 | switch (mcs) { |
| 5502 | case 7: |
| 5503 | vht_mcsmap = 0xfffc; |
| 5504 | break; |
| 5505 | case 8: |
| 5506 | vht_mcsmap = 0xfffd; |
| 5507 | break; |
| 5508 | case 9: |
| 5509 | vht_mcsmap = 0xfffe; |
| 5510 | break; |
| 5511 | default: |
| 5512 | vht_mcsmap = 0xfffe; |
| 5513 | break; |
| 5514 | } |
| 5515 | break; |
| 5516 | case 2: |
| 5517 | switch (mcs) { |
| 5518 | case 7: |
| 5519 | vht_mcsmap = 0xfff0; |
| 5520 | break; |
| 5521 | case 8: |
| 5522 | vht_mcsmap = 0xfff5; |
| 5523 | break; |
| 5524 | case 9: |
| 5525 | vht_mcsmap = 0xfffa; |
| 5526 | break; |
| 5527 | default: |
| 5528 | vht_mcsmap = 0xfffa; |
| 5529 | break; |
| 5530 | } |
| 5531 | break; |
| 5532 | case 3: |
| 5533 | switch (mcs) { |
| 5534 | case 7: |
| 5535 | vht_mcsmap = 0xffc0; |
| 5536 | break; |
| 5537 | case 8: |
| 5538 | vht_mcsmap = 0xffd5; |
| 5539 | break; |
| 5540 | case 9: |
| 5541 | vht_mcsmap = 0xffea; |
| 5542 | break; |
| 5543 | default: |
| 5544 | vht_mcsmap = 0xffea; |
| 5545 | break; |
| 5546 | } |
| 5547 | break; |
| 5548 | default: |
| 5549 | vht_mcsmap = 0xffea; |
| 5550 | break; |
| 5551 | } |
| 5552 | snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0x%04x", |
| 5553 | intf, vht_mcsmap); |
| 5554 | if (system(buf) != 0) { |
| 5555 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5556 | "iwpriv vht_mcsmap failed"); |
| 5557 | } |
| 5558 | } |
| 5559 | |
| 5560 | /* UNSUPPORTED: val = get_param(cmd, "Tx_lgi_rate"); */ |
| 5561 | |
| 5562 | val = get_param(cmd, "Vht_tkip"); |
| 5563 | if (val) |
| 5564 | tkip = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0; |
| 5565 | |
| 5566 | val = get_param(cmd, "Vht_wep"); |
| 5567 | if (val) |
| 5568 | wep = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0; |
| 5569 | |
| 5570 | if (tkip != -1 || wep != -1) { |
| 5571 | if ((tkip == 1 && wep != 0) || (wep == 1 && tkip != 0)) { |
| 5572 | snprintf(buf, sizeof(buf), "iwpriv %s htweptkip 1", |
| 5573 | intf); |
| 5574 | } else if ((tkip == 0 && wep != 1) || (wep == 0 && tkip != 1)) { |
| 5575 | snprintf(buf, sizeof(buf), "iwpriv %s htweptkip 0", |
| 5576 | intf); |
| 5577 | } else { |
| 5578 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5579 | "ErrorCode,mixed mode of VHT TKIP/WEP not supported"); |
| 5580 | return 0; |
| 5581 | } |
| 5582 | |
| 5583 | if (system(buf) != 0) { |
| 5584 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5585 | "iwpriv htweptkip failed"); |
| 5586 | } |
| 5587 | } |
| 5588 | |
| 5589 | val = get_param(cmd, "txBandwidth"); |
| 5590 | if (val) { |
| 5591 | switch (get_driver_type()) { |
| 5592 | case DRIVER_ATHEROS: |
| 5593 | if (ath_set_width(dut, conn, intf, val) < 0) { |
| 5594 | send_resp(dut, conn, SIGMA_ERROR, |
| 5595 | "ErrorCode,Failed to set txBandwidth"); |
| 5596 | return 0; |
| 5597 | } |
| 5598 | break; |
| 5599 | default: |
| 5600 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5601 | "Setting txBandwidth not supported"); |
| 5602 | break; |
| 5603 | } |
| 5604 | } |
| 5605 | |
| 5606 | return cmd_sta_set_wireless_common(intf, dut, conn, cmd); |
| 5607 | } |
| 5608 | |
| 5609 | |
| 5610 | static int sta_set_wireless_60g(struct sigma_dut *dut, |
| 5611 | struct sigma_conn *conn, |
| 5612 | struct sigma_cmd *cmd) |
| 5613 | { |
| 5614 | const char *dev_role = get_param(cmd, "DevRole"); |
| 5615 | |
| 5616 | if (!dev_role) { |
| 5617 | send_resp(dut, conn, SIGMA_INVALID, |
| 5618 | "ErrorCode,DevRole not specified"); |
| 5619 | return 0; |
| 5620 | } |
| 5621 | |
| 5622 | if (strcasecmp(dev_role, "PCP") == 0) |
| 5623 | return sta_set_60g_pcp(dut, conn, cmd); |
| 5624 | if (strcasecmp(dev_role, "STA") == 0) |
| 5625 | return sta_set_60g_sta(dut, conn, cmd); |
| 5626 | send_resp(dut, conn, SIGMA_INVALID, |
| 5627 | "ErrorCode,DevRole not supported"); |
| 5628 | return 0; |
| 5629 | } |
| 5630 | |
| 5631 | |
Ankita Bajaj | 0d5825b | 2017-10-25 16:20:17 +0530 | [diff] [blame] | 5632 | static int sta_set_wireless_oce(struct sigma_dut *dut, struct sigma_conn *conn, |
| 5633 | struct sigma_cmd *cmd) |
| 5634 | { |
| 5635 | int status; |
| 5636 | const char *intf = get_param(cmd, "Interface"); |
| 5637 | const char *val = get_param(cmd, "DevRole"); |
| 5638 | |
| 5639 | if (val && strcasecmp(val, "STA-CFON") == 0) { |
| 5640 | status = sta_cfon_set_wireless(dut, conn, cmd); |
| 5641 | if (status) |
| 5642 | return status; |
| 5643 | } |
| 5644 | return cmd_sta_set_wireless_common(intf, dut, conn, cmd); |
| 5645 | } |
| 5646 | |
| 5647 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5648 | static int cmd_sta_set_wireless(struct sigma_dut *dut, struct sigma_conn *conn, |
| 5649 | struct sigma_cmd *cmd) |
| 5650 | { |
| 5651 | const char *val; |
| 5652 | |
| 5653 | val = get_param(cmd, "Program"); |
| 5654 | if (val) { |
| 5655 | if (strcasecmp(val, "11n") == 0) |
| 5656 | return cmd_sta_set_11n(dut, conn, cmd); |
| 5657 | if (strcasecmp(val, "VHT") == 0) |
| 5658 | return cmd_sta_set_wireless_vht(dut, conn, cmd); |
| 5659 | if (strcasecmp(val, "60ghz") == 0) |
| 5660 | return sta_set_wireless_60g(dut, conn, cmd); |
Ankita Bajaj | 0d5825b | 2017-10-25 16:20:17 +0530 | [diff] [blame] | 5661 | if (strcasecmp(val, "OCE") == 0) |
| 5662 | return sta_set_wireless_oce(dut, conn, cmd); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5663 | send_resp(dut, conn, SIGMA_ERROR, |
| 5664 | "ErrorCode,Program value not supported"); |
| 5665 | } else { |
| 5666 | send_resp(dut, conn, SIGMA_ERROR, |
| 5667 | "ErrorCode,Program argument not available"); |
| 5668 | } |
| 5669 | |
| 5670 | return 0; |
| 5671 | } |
| 5672 | |
| 5673 | |
| 5674 | static void ath_sta_inject_frame(struct sigma_dut *dut, const char *intf, |
| 5675 | int tid) |
| 5676 | { |
| 5677 | char buf[100]; |
| 5678 | int tid_to_dscp [] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 }; |
| 5679 | |
Pradeep Reddy POTTETI | d31d132 | 2016-10-13 17:22:03 +0530 | [diff] [blame] | 5680 | if (tid < 0 || |
| 5681 | tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) { |
| 5682 | sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid); |
| 5683 | return; |
| 5684 | } |
| 5685 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5686 | /* |
| 5687 | * Two ways to ensure that addba request with a |
| 5688 | * non zero TID could be sent out. EV 117296 |
| 5689 | */ |
| 5690 | snprintf(buf, sizeof(buf), |
| 5691 | "ping -c 8 -Q %d `arp -a | grep wlan0 | awk '{print $2}' | tr -d '()'`", |
| 5692 | tid); |
| 5693 | if (system(buf) != 0) { |
| 5694 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5695 | "Ping did not send out"); |
| 5696 | } |
| 5697 | |
| 5698 | snprintf(buf, sizeof(buf), |
| 5699 | "iwconfig %s | grep Access | awk '{print $6}' > %s", |
| 5700 | intf, VI_QOS_TMP_FILE); |
| 5701 | if (system(buf) != 0) |
| 5702 | return; |
| 5703 | |
| 5704 | snprintf(buf, sizeof(buf), |
| 5705 | "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s", |
| 5706 | intf, VI_QOS_TMP_FILE); |
| 5707 | if (system(buf) != 0) |
| 5708 | sigma_dut_print(dut, DUT_MSG_ERROR, "HWaddr matching failed"); |
| 5709 | |
| 5710 | snprintf(buf,sizeof(buf), "sed -n '3,$p' %s >> %s", |
| 5711 | VI_QOS_REFFILE, VI_QOS_TMP_FILE); |
| 5712 | if (system(buf) != 0) { |
| 5713 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5714 | "VI_QOS_TEMP_FILE generation error failed"); |
| 5715 | } |
| 5716 | snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s", |
| 5717 | tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE); |
| 5718 | if (system(buf) != 0) { |
| 5719 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5720 | "VI_QOS_FILE generation failed"); |
| 5721 | } |
| 5722 | |
| 5723 | snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s", |
| 5724 | tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE); |
| 5725 | if (system(buf) != 0) { |
| 5726 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5727 | "VI_QOS_FILE generation failed"); |
| 5728 | } |
| 5729 | |
| 5730 | snprintf(buf, sizeof(buf), "ethinject %s %s", intf, VI_QOS_FILE); |
| 5731 | if (system(buf) != 0) { |
| 5732 | } |
| 5733 | } |
| 5734 | |
| 5735 | |
| 5736 | static int ath_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn, |
| 5737 | struct sigma_cmd *cmd) |
| 5738 | { |
| 5739 | const char *intf = get_param(cmd, "Interface"); |
| 5740 | const char *val; |
| 5741 | int tid = 0; |
| 5742 | char buf[100]; |
| 5743 | |
| 5744 | val = get_param(cmd, "TID"); |
| 5745 | if (val) { |
| 5746 | tid = atoi(val); |
| 5747 | if (tid) |
| 5748 | ath_sta_inject_frame(dut, intf, tid); |
| 5749 | } |
| 5750 | |
| 5751 | /* Command sequence for ADDBA request on Peregrine based devices */ |
| 5752 | snprintf(buf, sizeof(buf), "iwpriv %s setaddbaoper 1", intf); |
| 5753 | if (system(buf) != 0) { |
| 5754 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5755 | "iwpriv setaddbaoper failed"); |
| 5756 | } |
| 5757 | |
| 5758 | snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4", intf, tid); |
| 5759 | if (system(buf) != 0) { |
| 5760 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5761 | "wifitool senddelba failed"); |
| 5762 | } |
| 5763 | |
| 5764 | snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64", intf, tid); |
| 5765 | if (system(buf) != 0) { |
| 5766 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5767 | "wifitool sendaddba failed"); |
| 5768 | } |
| 5769 | |
| 5770 | /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */ |
| 5771 | |
| 5772 | return 1; |
| 5773 | } |
| 5774 | |
| 5775 | |
Lior David | 9981b51 | 2017-01-20 13:16:40 +0200 | [diff] [blame] | 5776 | #ifdef __linux__ |
| 5777 | |
| 5778 | static int wil6210_send_addba(struct sigma_dut *dut, const char *dest_mac, |
| 5779 | int agg_size) |
| 5780 | { |
| 5781 | char dir[128], buf[128]; |
| 5782 | FILE *f; |
| 5783 | regex_t re; |
| 5784 | regmatch_t m[2]; |
| 5785 | int rc, ret = -1, vring_id, found; |
| 5786 | |
| 5787 | if (wil6210_get_debugfs_dir(dut, dir, sizeof(dir))) { |
| 5788 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5789 | "failed to get wil6210 debugfs dir"); |
| 5790 | return -1; |
| 5791 | } |
| 5792 | |
| 5793 | snprintf(buf, sizeof(buf), "%s/vrings", dir); |
| 5794 | f = fopen(buf, "r"); |
| 5795 | if (!f) { |
| 5796 | sigma_dut_print(dut, DUT_MSG_ERROR, "failed to open: %s", buf); |
| 5797 | return -1; |
| 5798 | } |
| 5799 | |
| 5800 | if (regcomp(&re, "VRING tx_[ \t]*([0-9]+)", REG_EXTENDED)) { |
| 5801 | sigma_dut_print(dut, DUT_MSG_ERROR, "regcomp failed"); |
| 5802 | goto out; |
| 5803 | } |
| 5804 | |
| 5805 | /* find TX VRING for the mac address */ |
| 5806 | found = 0; |
| 5807 | while (fgets(buf, sizeof(buf), f)) { |
| 5808 | if (strcasestr(buf, dest_mac)) { |
| 5809 | found = 1; |
| 5810 | break; |
| 5811 | } |
| 5812 | } |
| 5813 | |
| 5814 | if (!found) { |
| 5815 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5816 | "no TX VRING for %s", dest_mac); |
| 5817 | goto out; |
| 5818 | } |
| 5819 | |
| 5820 | /* extract VRING ID, "VRING tx_<id> = {" */ |
| 5821 | if (!fgets(buf, sizeof(buf), f)) { |
| 5822 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5823 | "no VRING start line for %s", dest_mac); |
| 5824 | goto out; |
| 5825 | } |
| 5826 | |
| 5827 | rc = regexec(&re, buf, 2, m, 0); |
| 5828 | regfree(&re); |
| 5829 | if (rc || m[1].rm_so < 0) { |
| 5830 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5831 | "no VRING TX ID for %s", dest_mac); |
| 5832 | goto out; |
| 5833 | } |
| 5834 | buf[m[1].rm_eo] = 0; |
| 5835 | vring_id = atoi(&buf[m[1].rm_so]); |
| 5836 | |
| 5837 | /* send the addba command */ |
| 5838 | fclose(f); |
| 5839 | snprintf(buf, sizeof(buf), "%s/back", dir); |
| 5840 | f = fopen(buf, "w"); |
| 5841 | if (!f) { |
| 5842 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5843 | "failed to open: %s", buf); |
| 5844 | return -1; |
| 5845 | } |
| 5846 | |
| 5847 | fprintf(f, "add %d %d\n", vring_id, agg_size); |
| 5848 | |
| 5849 | ret = 0; |
| 5850 | |
| 5851 | out: |
| 5852 | fclose(f); |
| 5853 | |
| 5854 | return ret; |
| 5855 | } |
| 5856 | |
| 5857 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5858 | static int send_addba_60g(struct sigma_dut *dut, struct sigma_conn *conn, |
| 5859 | struct sigma_cmd *cmd) |
| 5860 | { |
| 5861 | const char *val; |
| 5862 | int tid = 0; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5863 | |
| 5864 | val = get_param(cmd, "TID"); |
| 5865 | if (val) { |
| 5866 | tid = atoi(val); |
| 5867 | if (tid != 0) { |
| 5868 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5869 | "Ignore TID %d for send_addba use TID 0 for 60g since only 0 required on TX", |
| 5870 | tid); |
| 5871 | } |
| 5872 | } |
| 5873 | |
| 5874 | val = get_param(cmd, "Dest_mac"); |
| 5875 | if (!val) { |
| 5876 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5877 | "Currently not supporting addba for 60G without Dest_mac"); |
| 5878 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; |
| 5879 | } |
| 5880 | |
Lior David | 9981b51 | 2017-01-20 13:16:40 +0200 | [diff] [blame] | 5881 | if (wil6210_send_addba(dut, val, dut->back_rcv_buf)) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5882 | return -1; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5883 | |
| 5884 | return 1; |
| 5885 | } |
| 5886 | |
Lior David | 9981b51 | 2017-01-20 13:16:40 +0200 | [diff] [blame] | 5887 | #endif /* __linux__ */ |
| 5888 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5889 | |
| 5890 | static int cmd_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn, |
| 5891 | struct sigma_cmd *cmd) |
| 5892 | { |
| 5893 | switch (get_driver_type()) { |
| 5894 | case DRIVER_ATHEROS: |
| 5895 | return ath_sta_send_addba(dut, conn, cmd); |
Lior David | 9981b51 | 2017-01-20 13:16:40 +0200 | [diff] [blame] | 5896 | #ifdef __linux__ |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5897 | case DRIVER_WIL6210: |
| 5898 | return send_addba_60g(dut, conn, cmd); |
Lior David | 9981b51 | 2017-01-20 13:16:40 +0200 | [diff] [blame] | 5899 | #endif /* __linux__ */ |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5900 | default: |
| 5901 | /* |
| 5902 | * There is no driver specific implementation for other drivers. |
| 5903 | * Ignore the command and report COMPLETE since the following |
| 5904 | * throughput test operation will end up sending ADDBA anyway. |
| 5905 | */ |
| 5906 | return 1; |
| 5907 | } |
| 5908 | } |
| 5909 | |
| 5910 | |
| 5911 | int inject_eth_frame(int s, const void *data, size_t len, |
| 5912 | unsigned short ethtype, char *dst, char *src) |
| 5913 | { |
| 5914 | struct iovec iov[4] = { |
| 5915 | { |
| 5916 | .iov_base = dst, |
| 5917 | .iov_len = ETH_ALEN, |
| 5918 | }, |
| 5919 | { |
| 5920 | .iov_base = src, |
| 5921 | .iov_len = ETH_ALEN, |
| 5922 | }, |
| 5923 | { |
| 5924 | .iov_base = ðtype, |
| 5925 | .iov_len = sizeof(unsigned short), |
| 5926 | }, |
| 5927 | { |
| 5928 | .iov_base = (void *) data, |
| 5929 | .iov_len = len, |
| 5930 | } |
| 5931 | }; |
| 5932 | struct msghdr msg = { |
| 5933 | .msg_name = NULL, |
| 5934 | .msg_namelen = 0, |
| 5935 | .msg_iov = iov, |
| 5936 | .msg_iovlen = 4, |
| 5937 | .msg_control = NULL, |
| 5938 | .msg_controllen = 0, |
| 5939 | .msg_flags = 0, |
| 5940 | }; |
| 5941 | |
| 5942 | return sendmsg(s, &msg, 0); |
| 5943 | } |
| 5944 | |
| 5945 | #if defined(__linux__) || defined(__QNXNTO__) |
| 5946 | |
| 5947 | int inject_frame(int s, const void *data, size_t len, int encrypt) |
| 5948 | { |
| 5949 | #define IEEE80211_RADIOTAP_F_WEP 0x04 |
| 5950 | #define IEEE80211_RADIOTAP_F_FRAG 0x08 |
| 5951 | unsigned char rtap_hdr[] = { |
| 5952 | 0x00, 0x00, /* radiotap version */ |
| 5953 | 0x0e, 0x00, /* radiotap length */ |
| 5954 | 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */ |
| 5955 | IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */ |
| 5956 | 0x00, /* padding */ |
| 5957 | 0x00, 0x00, /* RX and TX flags to indicate that */ |
| 5958 | 0x00, 0x00, /* this is the injected frame directly */ |
| 5959 | }; |
| 5960 | struct iovec iov[2] = { |
| 5961 | { |
| 5962 | .iov_base = &rtap_hdr, |
| 5963 | .iov_len = sizeof(rtap_hdr), |
| 5964 | }, |
| 5965 | { |
| 5966 | .iov_base = (void *) data, |
| 5967 | .iov_len = len, |
| 5968 | } |
| 5969 | }; |
| 5970 | struct msghdr msg = { |
| 5971 | .msg_name = NULL, |
| 5972 | .msg_namelen = 0, |
| 5973 | .msg_iov = iov, |
| 5974 | .msg_iovlen = 2, |
| 5975 | .msg_control = NULL, |
| 5976 | .msg_controllen = 0, |
| 5977 | .msg_flags = 0, |
| 5978 | }; |
| 5979 | |
| 5980 | if (encrypt) |
| 5981 | rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP; |
| 5982 | |
| 5983 | return sendmsg(s, &msg, 0); |
| 5984 | } |
| 5985 | |
| 5986 | |
| 5987 | int open_monitor(const char *ifname) |
| 5988 | { |
| 5989 | #ifdef __QNXNTO__ |
| 5990 | struct sockaddr_dl ll; |
| 5991 | int s; |
| 5992 | |
| 5993 | memset(&ll, 0, sizeof(ll)); |
| 5994 | ll.sdl_family = AF_LINK; |
| 5995 | ll.sdl_index = if_nametoindex(ifname); |
| 5996 | if (ll.sdl_index == 0) { |
| 5997 | perror("if_nametoindex"); |
| 5998 | return -1; |
| 5999 | } |
| 6000 | s = socket(PF_INET, SOCK_RAW, 0); |
| 6001 | #else /* __QNXNTO__ */ |
| 6002 | struct sockaddr_ll ll; |
| 6003 | int s; |
| 6004 | |
| 6005 | memset(&ll, 0, sizeof(ll)); |
| 6006 | ll.sll_family = AF_PACKET; |
| 6007 | ll.sll_ifindex = if_nametoindex(ifname); |
| 6008 | if (ll.sll_ifindex == 0) { |
| 6009 | perror("if_nametoindex"); |
| 6010 | return -1; |
| 6011 | } |
| 6012 | s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); |
| 6013 | #endif /* __QNXNTO__ */ |
| 6014 | if (s < 0) { |
| 6015 | perror("socket[PF_PACKET,SOCK_RAW]"); |
| 6016 | return -1; |
| 6017 | } |
| 6018 | |
| 6019 | if (bind(s, (struct sockaddr *) &ll, sizeof(ll)) < 0) { |
| 6020 | perror("monitor socket bind"); |
| 6021 | close(s); |
| 6022 | return -1; |
| 6023 | } |
| 6024 | |
| 6025 | return s; |
| 6026 | } |
| 6027 | |
| 6028 | |
| 6029 | static int hex2num(char c) |
| 6030 | { |
| 6031 | if (c >= '0' && c <= '9') |
| 6032 | return c - '0'; |
| 6033 | if (c >= 'a' && c <= 'f') |
| 6034 | return c - 'a' + 10; |
| 6035 | if (c >= 'A' && c <= 'F') |
| 6036 | return c - 'A' + 10; |
| 6037 | return -1; |
| 6038 | } |
| 6039 | |
| 6040 | |
| 6041 | int hwaddr_aton(const char *txt, unsigned char *addr) |
| 6042 | { |
| 6043 | int i; |
| 6044 | |
| 6045 | for (i = 0; i < 6; i++) { |
| 6046 | int a, b; |
| 6047 | |
| 6048 | a = hex2num(*txt++); |
| 6049 | if (a < 0) |
| 6050 | return -1; |
| 6051 | b = hex2num(*txt++); |
| 6052 | if (b < 0) |
| 6053 | return -1; |
| 6054 | *addr++ = (a << 4) | b; |
| 6055 | if (i < 5 && *txt++ != ':') |
| 6056 | return -1; |
| 6057 | } |
| 6058 | |
| 6059 | return 0; |
| 6060 | } |
| 6061 | |
| 6062 | #endif /* defined(__linux__) || defined(__QNXNTO__) */ |
| 6063 | |
| 6064 | enum send_frame_type { |
| 6065 | DISASSOC, DEAUTH, SAQUERY, AUTH, ASSOCREQ, REASSOCREQ, DLS_REQ |
| 6066 | }; |
| 6067 | enum send_frame_protection { |
| 6068 | CORRECT_KEY, INCORRECT_KEY, UNPROTECTED |
| 6069 | }; |
| 6070 | |
| 6071 | |
| 6072 | static int sta_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn, |
| 6073 | enum send_frame_type frame, |
| 6074 | enum send_frame_protection protected, |
| 6075 | const char *dest) |
| 6076 | { |
| 6077 | #ifdef __linux__ |
| 6078 | unsigned char buf[1000], *pos; |
| 6079 | int s, res; |
| 6080 | char bssid[20], addr[20]; |
| 6081 | char result[32], ssid[100]; |
| 6082 | size_t ssid_len; |
| 6083 | |
| 6084 | if (get_wpa_status(get_station_ifname(), "wpa_state", result, |
| 6085 | sizeof(result)) < 0 || |
| 6086 | strncmp(result, "COMPLETED", 9) != 0) { |
| 6087 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Not connected"); |
| 6088 | return 0; |
| 6089 | } |
| 6090 | |
| 6091 | if (get_wpa_status(get_station_ifname(), "bssid", bssid, sizeof(bssid)) |
| 6092 | < 0) { |
| 6093 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get " |
| 6094 | "current BSSID"); |
| 6095 | return 0; |
| 6096 | } |
| 6097 | |
| 6098 | if (get_wpa_status(get_station_ifname(), "address", addr, sizeof(addr)) |
| 6099 | < 0) { |
| 6100 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get " |
| 6101 | "own MAC address"); |
| 6102 | return 0; |
| 6103 | } |
| 6104 | |
| 6105 | if (get_wpa_status(get_station_ifname(), "ssid", ssid, sizeof(ssid)) |
| 6106 | < 0) { |
| 6107 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get " |
| 6108 | "current SSID"); |
| 6109 | return 0; |
| 6110 | } |
| 6111 | ssid_len = strlen(ssid); |
| 6112 | |
| 6113 | pos = buf; |
| 6114 | |
| 6115 | /* Frame Control */ |
| 6116 | switch (frame) { |
| 6117 | case DISASSOC: |
| 6118 | *pos++ = 0xa0; |
| 6119 | break; |
| 6120 | case DEAUTH: |
| 6121 | *pos++ = 0xc0; |
| 6122 | break; |
| 6123 | case SAQUERY: |
| 6124 | *pos++ = 0xd0; |
| 6125 | break; |
| 6126 | case AUTH: |
| 6127 | *pos++ = 0xb0; |
| 6128 | break; |
| 6129 | case ASSOCREQ: |
| 6130 | *pos++ = 0x00; |
| 6131 | break; |
| 6132 | case REASSOCREQ: |
| 6133 | *pos++ = 0x20; |
| 6134 | break; |
| 6135 | case DLS_REQ: |
| 6136 | *pos++ = 0xd0; |
| 6137 | break; |
| 6138 | } |
| 6139 | |
| 6140 | if (protected == INCORRECT_KEY) |
| 6141 | *pos++ = 0x40; /* Set Protected field to 1 */ |
| 6142 | else |
| 6143 | *pos++ = 0x00; |
| 6144 | |
| 6145 | /* Duration */ |
| 6146 | *pos++ = 0x00; |
| 6147 | *pos++ = 0x00; |
| 6148 | |
| 6149 | /* addr1 = DA (current AP) */ |
| 6150 | hwaddr_aton(bssid, pos); |
| 6151 | pos += 6; |
| 6152 | /* addr2 = SA (own address) */ |
| 6153 | hwaddr_aton(addr, pos); |
| 6154 | pos += 6; |
| 6155 | /* addr3 = BSSID (current AP) */ |
| 6156 | hwaddr_aton(bssid, pos); |
| 6157 | pos += 6; |
| 6158 | |
| 6159 | /* Seq# (to be filled by driver/mac80211) */ |
| 6160 | *pos++ = 0x00; |
| 6161 | *pos++ = 0x00; |
| 6162 | |
| 6163 | if (protected == INCORRECT_KEY) { |
| 6164 | /* CCMP parameters */ |
| 6165 | memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8); |
| 6166 | pos += 8; |
| 6167 | } |
| 6168 | |
| 6169 | if (protected == INCORRECT_KEY) { |
| 6170 | switch (frame) { |
| 6171 | case DEAUTH: |
| 6172 | /* Reason code (encrypted) */ |
| 6173 | memcpy(pos, "\xa7\x39", 2); |
| 6174 | pos += 2; |
| 6175 | break; |
| 6176 | case DISASSOC: |
| 6177 | /* Reason code (encrypted) */ |
| 6178 | memcpy(pos, "\xa7\x39", 2); |
| 6179 | pos += 2; |
| 6180 | break; |
| 6181 | case SAQUERY: |
| 6182 | /* Category|Action|TransID (encrypted) */ |
| 6183 | memcpy(pos, "\x6f\xbd\xe9\x4d", 4); |
| 6184 | pos += 4; |
| 6185 | break; |
| 6186 | default: |
| 6187 | return -1; |
| 6188 | } |
| 6189 | |
| 6190 | /* CCMP MIC */ |
| 6191 | memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8); |
| 6192 | pos += 8; |
| 6193 | } else { |
| 6194 | switch (frame) { |
| 6195 | case DEAUTH: |
| 6196 | /* reason code = 8 */ |
| 6197 | *pos++ = 0x08; |
| 6198 | *pos++ = 0x00; |
| 6199 | break; |
| 6200 | case DISASSOC: |
| 6201 | /* reason code = 8 */ |
| 6202 | *pos++ = 0x08; |
| 6203 | *pos++ = 0x00; |
| 6204 | break; |
| 6205 | case SAQUERY: |
| 6206 | /* Category - SA Query */ |
| 6207 | *pos++ = 0x08; |
| 6208 | /* SA query Action - Request */ |
| 6209 | *pos++ = 0x00; |
| 6210 | /* Transaction ID */ |
| 6211 | *pos++ = 0x12; |
| 6212 | *pos++ = 0x34; |
| 6213 | break; |
| 6214 | case AUTH: |
| 6215 | /* Auth Alg (Open) */ |
| 6216 | *pos++ = 0x00; |
| 6217 | *pos++ = 0x00; |
| 6218 | /* Seq# */ |
| 6219 | *pos++ = 0x01; |
| 6220 | *pos++ = 0x00; |
| 6221 | /* Status code */ |
| 6222 | *pos++ = 0x00; |
| 6223 | *pos++ = 0x00; |
| 6224 | break; |
| 6225 | case ASSOCREQ: |
| 6226 | /* Capability Information */ |
| 6227 | *pos++ = 0x31; |
| 6228 | *pos++ = 0x04; |
| 6229 | /* Listen Interval */ |
| 6230 | *pos++ = 0x0a; |
| 6231 | *pos++ = 0x00; |
| 6232 | /* SSID */ |
| 6233 | *pos++ = 0x00; |
| 6234 | *pos++ = ssid_len; |
| 6235 | memcpy(pos, ssid, ssid_len); |
| 6236 | pos += ssid_len; |
| 6237 | /* Supported Rates */ |
| 6238 | memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24", |
| 6239 | 10); |
| 6240 | pos += 10; |
| 6241 | /* Extended Supported Rates */ |
| 6242 | memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6); |
| 6243 | pos += 6; |
| 6244 | /* RSN */ |
| 6245 | memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00" |
| 6246 | "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0" |
| 6247 | "\x00\x00\x00\x00\x0f\xac\x06", 28); |
| 6248 | pos += 28; |
| 6249 | break; |
| 6250 | case REASSOCREQ: |
| 6251 | /* Capability Information */ |
| 6252 | *pos++ = 0x31; |
| 6253 | *pos++ = 0x04; |
| 6254 | /* Listen Interval */ |
| 6255 | *pos++ = 0x0a; |
| 6256 | *pos++ = 0x00; |
| 6257 | /* Current AP */ |
| 6258 | hwaddr_aton(bssid, pos); |
| 6259 | pos += 6; |
| 6260 | /* SSID */ |
| 6261 | *pos++ = 0x00; |
| 6262 | *pos++ = ssid_len; |
| 6263 | memcpy(pos, ssid, ssid_len); |
| 6264 | pos += ssid_len; |
| 6265 | /* Supported Rates */ |
| 6266 | memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24", |
| 6267 | 10); |
| 6268 | pos += 10; |
| 6269 | /* Extended Supported Rates */ |
| 6270 | memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6); |
| 6271 | pos += 6; |
| 6272 | /* RSN */ |
| 6273 | memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00" |
| 6274 | "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0" |
| 6275 | "\x00\x00\x00\x00\x0f\xac\x06", 28); |
| 6276 | pos += 28; |
| 6277 | break; |
| 6278 | case DLS_REQ: |
| 6279 | /* Category - DLS */ |
| 6280 | *pos++ = 0x02; |
| 6281 | /* DLS Action - Request */ |
| 6282 | *pos++ = 0x00; |
| 6283 | /* Destination MACAddress */ |
| 6284 | if (dest) |
| 6285 | hwaddr_aton(dest, pos); |
| 6286 | else |
| 6287 | memset(pos, 0, 6); |
| 6288 | pos += 6; |
| 6289 | /* Source MACAddress */ |
| 6290 | hwaddr_aton(addr, pos); |
| 6291 | pos += 6; |
| 6292 | /* Capability Information */ |
| 6293 | *pos++ = 0x10; /* Privacy */ |
| 6294 | *pos++ = 0x06; /* QoS */ |
| 6295 | /* DLS Timeout Value */ |
| 6296 | *pos++ = 0x00; |
| 6297 | *pos++ = 0x01; |
| 6298 | /* Supported rates */ |
| 6299 | *pos++ = 0x01; |
| 6300 | *pos++ = 0x08; |
| 6301 | *pos++ = 0x0c; /* 6 Mbps */ |
| 6302 | *pos++ = 0x12; /* 9 Mbps */ |
| 6303 | *pos++ = 0x18; /* 12 Mbps */ |
| 6304 | *pos++ = 0x24; /* 18 Mbps */ |
| 6305 | *pos++ = 0x30; /* 24 Mbps */ |
| 6306 | *pos++ = 0x48; /* 36 Mbps */ |
| 6307 | *pos++ = 0x60; /* 48 Mbps */ |
| 6308 | *pos++ = 0x6c; /* 54 Mbps */ |
| 6309 | /* TODO: Extended Supported Rates */ |
| 6310 | /* TODO: HT Capabilities */ |
| 6311 | break; |
| 6312 | } |
| 6313 | } |
| 6314 | |
| 6315 | s = open_monitor("sigmadut"); |
| 6316 | if (s < 0) { |
| 6317 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open " |
| 6318 | "monitor socket"); |
| 6319 | return 0; |
| 6320 | } |
| 6321 | |
| 6322 | res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY); |
| 6323 | if (res < 0) { |
| 6324 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to " |
| 6325 | "inject frame"); |
Pradeep Reddy POTTETI | 673d85c | 2016-07-26 19:08:07 +0530 | [diff] [blame] | 6326 | close(s); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6327 | return 0; |
| 6328 | } |
| 6329 | if (res < pos - buf) { |
| 6330 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Only partial " |
| 6331 | "frame sent"); |
Pradeep Reddy POTTETI | 673d85c | 2016-07-26 19:08:07 +0530 | [diff] [blame] | 6332 | close(s); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6333 | return 0; |
| 6334 | } |
| 6335 | |
| 6336 | close(s); |
| 6337 | |
| 6338 | return 1; |
| 6339 | #else /* __linux__ */ |
| 6340 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,sta_send_frame not " |
| 6341 | "yet supported"); |
| 6342 | return 0; |
| 6343 | #endif /* __linux__ */ |
| 6344 | } |
| 6345 | |
| 6346 | |
| 6347 | static int cmd_sta_send_frame_tdls(struct sigma_dut *dut, |
| 6348 | struct sigma_conn *conn, |
| 6349 | struct sigma_cmd *cmd) |
| 6350 | { |
| 6351 | const char *intf = get_param(cmd, "Interface"); |
| 6352 | const char *sta, *val; |
| 6353 | unsigned char addr[ETH_ALEN]; |
| 6354 | char buf[100]; |
| 6355 | |
| 6356 | sta = get_param(cmd, "peer"); |
| 6357 | if (sta == NULL) |
| 6358 | sta = get_param(cmd, "station"); |
| 6359 | if (sta == NULL) { |
| 6360 | send_resp(dut, conn, SIGMA_ERROR, |
| 6361 | "ErrorCode,Missing peer address"); |
| 6362 | return 0; |
| 6363 | } |
| 6364 | if (hwaddr_aton(sta, addr) < 0) { |
| 6365 | send_resp(dut, conn, SIGMA_ERROR, |
| 6366 | "ErrorCode,Invalid peer address"); |
| 6367 | return 0; |
| 6368 | } |
| 6369 | |
| 6370 | val = get_param(cmd, "type"); |
| 6371 | if (val == NULL) |
| 6372 | return -1; |
| 6373 | |
| 6374 | if (strcasecmp(val, "DISCOVERY") == 0) { |
| 6375 | snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", sta); |
| 6376 | if (wpa_command(intf, buf) < 0) { |
| 6377 | send_resp(dut, conn, SIGMA_ERROR, |
| 6378 | "ErrorCode,Failed to send TDLS discovery"); |
| 6379 | return 0; |
| 6380 | } |
| 6381 | return 1; |
| 6382 | } |
| 6383 | |
| 6384 | if (strcasecmp(val, "SETUP") == 0) { |
| 6385 | int status = 0, timeout = 0; |
| 6386 | |
| 6387 | val = get_param(cmd, "Status"); |
| 6388 | if (val) |
| 6389 | status = atoi(val); |
| 6390 | |
| 6391 | val = get_param(cmd, "Timeout"); |
| 6392 | if (val) |
| 6393 | timeout = atoi(val); |
| 6394 | |
| 6395 | if (status != 0 && status != 37) { |
| 6396 | send_resp(dut, conn, SIGMA_ERROR, |
| 6397 | "ErrorCode,Unsupported status value"); |
| 6398 | return 0; |
| 6399 | } |
| 6400 | |
| 6401 | if (timeout != 0 && timeout != 301) { |
| 6402 | send_resp(dut, conn, SIGMA_ERROR, |
| 6403 | "ErrorCode,Unsupported timeout value"); |
| 6404 | return 0; |
| 6405 | } |
| 6406 | |
| 6407 | if (status && timeout) { |
| 6408 | send_resp(dut, conn, SIGMA_ERROR, |
| 6409 | "ErrorCode,Unsupported timeout+status " |
| 6410 | "combination"); |
| 6411 | return 0; |
| 6412 | } |
| 6413 | |
| 6414 | if (status == 37 && |
| 6415 | wpa_command(intf, "SET tdls_testing 0x200")) { |
| 6416 | send_resp(dut, conn, SIGMA_ERROR, |
| 6417 | "ErrorCode,Failed to enable " |
| 6418 | "decline setup response test mode"); |
| 6419 | return 0; |
| 6420 | } |
| 6421 | |
| 6422 | if (timeout == 301) { |
| 6423 | int res; |
| 6424 | if (dut->no_tpk_expiration) |
| 6425 | res = wpa_command(intf, |
| 6426 | "SET tdls_testing 0x108"); |
| 6427 | else |
| 6428 | res = wpa_command(intf, |
| 6429 | "SET tdls_testing 0x8"); |
| 6430 | if (res) { |
| 6431 | send_resp(dut, conn, SIGMA_ERROR, |
| 6432 | "ErrorCode,Failed to set short TPK " |
| 6433 | "lifetime"); |
| 6434 | return 0; |
| 6435 | } |
| 6436 | } |
| 6437 | |
| 6438 | snprintf(buf, sizeof(buf), "TDLS_SETUP %s", sta); |
| 6439 | if (wpa_command(intf, buf) < 0) { |
| 6440 | send_resp(dut, conn, SIGMA_ERROR, |
| 6441 | "ErrorCode,Failed to send TDLS setup"); |
| 6442 | return 0; |
| 6443 | } |
| 6444 | return 1; |
| 6445 | } |
| 6446 | |
| 6447 | if (strcasecmp(val, "TEARDOWN") == 0) { |
| 6448 | snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", sta); |
| 6449 | if (wpa_command(intf, buf) < 0) { |
| 6450 | send_resp(dut, conn, SIGMA_ERROR, |
| 6451 | "ErrorCode,Failed to send TDLS teardown"); |
| 6452 | return 0; |
| 6453 | } |
| 6454 | return 1; |
| 6455 | } |
| 6456 | |
| 6457 | send_resp(dut, conn, SIGMA_ERROR, |
| 6458 | "ErrorCode,Unsupported TDLS frame"); |
| 6459 | return 0; |
| 6460 | } |
| 6461 | |
| 6462 | |
| 6463 | static int sta_ap_known(const char *ifname, const char *bssid) |
| 6464 | { |
| 6465 | char buf[4096]; |
| 6466 | |
| 6467 | snprintf(buf, sizeof(buf), "BSS %s", bssid); |
| 6468 | if (wpa_command_resp(ifname, buf, buf, sizeof(buf)) < 0) |
| 6469 | return 0; |
| 6470 | if (strncmp(buf, "id=", 3) != 0) |
| 6471 | return 0; |
| 6472 | return 1; |
| 6473 | } |
| 6474 | |
| 6475 | |
| 6476 | static int sta_scan_ap(struct sigma_dut *dut, const char *ifname, |
| 6477 | const char *bssid) |
| 6478 | { |
| 6479 | int res; |
| 6480 | struct wpa_ctrl *ctrl; |
| 6481 | char buf[256]; |
| 6482 | |
| 6483 | if (sta_ap_known(ifname, bssid)) |
| 6484 | return 0; |
| 6485 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 6486 | "AP not in BSS table - start scan"); |
| 6487 | |
| 6488 | ctrl = open_wpa_mon(ifname); |
| 6489 | if (ctrl == NULL) { |
| 6490 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open " |
| 6491 | "wpa_supplicant monitor connection"); |
| 6492 | return -1; |
| 6493 | } |
| 6494 | |
| 6495 | if (wpa_command(ifname, "SCAN") < 0) { |
| 6496 | sigma_dut_print(dut, DUT_MSG_INFO, "Failed to start scan"); |
| 6497 | wpa_ctrl_detach(ctrl); |
| 6498 | wpa_ctrl_close(ctrl); |
| 6499 | return -1; |
| 6500 | } |
| 6501 | |
| 6502 | res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS", |
| 6503 | buf, sizeof(buf)); |
| 6504 | |
| 6505 | wpa_ctrl_detach(ctrl); |
| 6506 | wpa_ctrl_close(ctrl); |
| 6507 | |
| 6508 | if (res < 0) { |
| 6509 | sigma_dut_print(dut, DUT_MSG_INFO, "Scan did not complete"); |
| 6510 | return -1; |
| 6511 | } |
| 6512 | |
| 6513 | if (sta_ap_known(ifname, bssid)) |
| 6514 | return 0; |
| 6515 | sigma_dut_print(dut, DUT_MSG_INFO, "AP not in BSS table"); |
| 6516 | return -1; |
| 6517 | } |
| 6518 | |
| 6519 | |
| 6520 | static int cmd_sta_send_frame_hs2_neighadv(struct sigma_dut *dut, |
| 6521 | struct sigma_conn *conn, |
| 6522 | struct sigma_cmd *cmd, |
| 6523 | const char *intf) |
| 6524 | { |
| 6525 | char buf[200]; |
| 6526 | |
| 6527 | snprintf(buf, sizeof(buf), "ndsend 2001:DB8::1 %s", intf); |
| 6528 | if (system(buf) != 0) { |
| 6529 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Failed to run " |
| 6530 | "ndsend"); |
| 6531 | return 0; |
| 6532 | } |
| 6533 | |
| 6534 | return 1; |
| 6535 | } |
| 6536 | |
| 6537 | |
| 6538 | static int cmd_sta_send_frame_hs2_neighsolreq(struct sigma_dut *dut, |
| 6539 | struct sigma_conn *conn, |
| 6540 | struct sigma_cmd *cmd, |
| 6541 | const char *intf) |
| 6542 | { |
| 6543 | char buf[200]; |
| 6544 | const char *ip = get_param(cmd, "SenderIP"); |
| 6545 | |
Peng Xu | 26b356d | 2017-10-04 17:58:16 -0700 | [diff] [blame] | 6546 | if (!ip) |
| 6547 | return 0; |
| 6548 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6549 | snprintf(buf, sizeof(buf), "ndisc6 -nm %s %s -r 4", ip, intf); |
| 6550 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 6551 | if (system(buf) == 0) { |
| 6552 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 6553 | "Neighbor Solicitation got a response " |
| 6554 | "for %s@%s", ip, intf); |
| 6555 | } |
| 6556 | |
| 6557 | return 1; |
| 6558 | } |
| 6559 | |
| 6560 | |
| 6561 | static int cmd_sta_send_frame_hs2_arpprobe(struct sigma_dut *dut, |
| 6562 | struct sigma_conn *conn, |
| 6563 | struct sigma_cmd *cmd, |
| 6564 | const char *ifname) |
| 6565 | { |
| 6566 | char buf[200]; |
| 6567 | const char *ip = get_param(cmd, "SenderIP"); |
| 6568 | |
| 6569 | if (ip == NULL) { |
| 6570 | send_resp(dut, conn, SIGMA_ERROR, |
| 6571 | "ErrorCode,Missing SenderIP parameter"); |
| 6572 | return 0; |
| 6573 | } |
| 6574 | snprintf(buf, sizeof(buf), "arping -I %s -D %s -c 4", ifname, ip); |
| 6575 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 6576 | if (system(buf) != 0) { |
| 6577 | sigma_dut_print(dut, DUT_MSG_INFO, "arping DAD got a response " |
| 6578 | "for %s@%s", ip, ifname); |
| 6579 | } |
| 6580 | |
| 6581 | return 1; |
| 6582 | } |
| 6583 | |
| 6584 | |
| 6585 | static int cmd_sta_send_frame_hs2_arpannounce(struct sigma_dut *dut, |
| 6586 | struct sigma_conn *conn, |
| 6587 | struct sigma_cmd *cmd, |
| 6588 | const char *ifname) |
| 6589 | { |
| 6590 | char buf[200]; |
| 6591 | char ip[16]; |
| 6592 | int s; |
Peng Xu | b375688 | 2017-10-04 14:39:09 -0700 | [diff] [blame] | 6593 | struct ifreq ifr; |
| 6594 | struct sockaddr_in saddr; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6595 | |
| 6596 | s = socket(PF_INET, SOCK_DGRAM, 0); |
Peng Xu | b375688 | 2017-10-04 14:39:09 -0700 | [diff] [blame] | 6597 | if (s < 0) { |
| 6598 | perror("socket"); |
| 6599 | return -1; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6600 | } |
| 6601 | |
Peng Xu | b375688 | 2017-10-04 14:39:09 -0700 | [diff] [blame] | 6602 | memset(&ifr, 0, sizeof(ifr)); |
| 6603 | strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); |
| 6604 | if (ioctl(s, SIOCGIFADDR, &ifr) < 0) { |
| 6605 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 6606 | "Failed to get %s IP address: %s", |
| 6607 | ifname, strerror(errno)); |
| 6608 | close(s); |
| 6609 | return -1; |
| 6610 | } |
| 6611 | close(s); |
| 6612 | |
| 6613 | memcpy(&saddr, &ifr.ifr_addr, sizeof(struct sockaddr_in)); |
| 6614 | strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip)); |
| 6615 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6616 | snprintf(buf, sizeof(buf), "arping -I %s -s %s %s -c 4", ifname, ip, |
| 6617 | ip); |
| 6618 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 6619 | if (system(buf) != 0) { |
| 6620 | } |
| 6621 | |
| 6622 | return 1; |
| 6623 | } |
| 6624 | |
| 6625 | |
| 6626 | static int cmd_sta_send_frame_hs2_arpreply(struct sigma_dut *dut, |
| 6627 | struct sigma_conn *conn, |
| 6628 | struct sigma_cmd *cmd, |
| 6629 | const char *ifname) |
| 6630 | { |
| 6631 | char buf[200], addr[20]; |
| 6632 | char dst[ETH_ALEN], src[ETH_ALEN]; |
| 6633 | short ethtype = htons(ETH_P_ARP); |
| 6634 | char *pos; |
| 6635 | int s, res; |
| 6636 | const char *val; |
| 6637 | struct sockaddr_in taddr; |
| 6638 | |
| 6639 | val = get_param(cmd, "dest"); |
| 6640 | if (val) |
| 6641 | hwaddr_aton(val, (unsigned char *) dst); |
| 6642 | |
| 6643 | val = get_param(cmd, "DestIP"); |
| 6644 | if (val) |
| 6645 | inet_aton(val, &taddr.sin_addr); |
Peng Xu | 151c9e1 | 2017-10-04 14:39:09 -0700 | [diff] [blame] | 6646 | else |
| 6647 | return -2; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6648 | |
| 6649 | if (get_wpa_status(get_station_ifname(), "address", addr, |
| 6650 | sizeof(addr)) < 0) |
| 6651 | return -2; |
| 6652 | hwaddr_aton(addr, (unsigned char *) src); |
| 6653 | |
| 6654 | pos = buf; |
| 6655 | *pos++ = 0x00; |
| 6656 | *pos++ = 0x01; |
| 6657 | *pos++ = 0x08; |
| 6658 | *pos++ = 0x00; |
| 6659 | *pos++ = 0x06; |
| 6660 | *pos++ = 0x04; |
| 6661 | *pos++ = 0x00; |
| 6662 | *pos++ = 0x02; |
| 6663 | memcpy(pos, src, ETH_ALEN); |
| 6664 | pos += ETH_ALEN; |
| 6665 | memcpy(pos, &taddr.sin_addr, 4); |
| 6666 | pos += 4; |
| 6667 | memcpy(pos, dst, ETH_ALEN); |
| 6668 | pos += ETH_ALEN; |
| 6669 | memcpy(pos, &taddr.sin_addr, 4); |
| 6670 | pos += 4; |
| 6671 | |
| 6672 | s = open_monitor(get_station_ifname()); |
| 6673 | if (s < 0) { |
| 6674 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open " |
| 6675 | "monitor socket"); |
| 6676 | return 0; |
| 6677 | } |
| 6678 | |
| 6679 | res = inject_eth_frame(s, buf, pos - buf, ethtype, dst, src); |
| 6680 | if (res < 0) { |
| 6681 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to " |
| 6682 | "inject frame"); |
Pradeep Reddy POTTETI | 673d85c | 2016-07-26 19:08:07 +0530 | [diff] [blame] | 6683 | close(s); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6684 | return 0; |
| 6685 | } |
| 6686 | |
| 6687 | close(s); |
| 6688 | |
| 6689 | return 1; |
| 6690 | } |
| 6691 | |
| 6692 | |
| 6693 | static int cmd_sta_send_frame_hs2_dls_req(struct sigma_dut *dut, |
| 6694 | struct sigma_conn *conn, |
| 6695 | struct sigma_cmd *cmd, |
| 6696 | const char *intf, const char *dest) |
| 6697 | { |
| 6698 | char buf[100]; |
| 6699 | |
| 6700 | if (if_nametoindex("sigmadut") == 0) { |
| 6701 | snprintf(buf, sizeof(buf), |
| 6702 | "iw dev %s interface add sigmadut type monitor", |
| 6703 | get_station_ifname()); |
| 6704 | if (system(buf) != 0 || |
| 6705 | if_nametoindex("sigmadut") == 0) { |
| 6706 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add " |
| 6707 | "monitor interface with '%s'", buf); |
| 6708 | return -2; |
| 6709 | } |
| 6710 | } |
| 6711 | |
| 6712 | if (system("ifconfig sigmadut up") != 0) { |
| 6713 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set " |
| 6714 | "monitor interface up"); |
| 6715 | return -2; |
| 6716 | } |
| 6717 | |
| 6718 | return sta_inject_frame(dut, conn, DLS_REQ, UNPROTECTED, dest); |
| 6719 | } |
| 6720 | |
| 6721 | |
| 6722 | static int cmd_sta_send_frame_hs2(struct sigma_dut *dut, |
| 6723 | struct sigma_conn *conn, |
| 6724 | struct sigma_cmd *cmd) |
| 6725 | { |
| 6726 | const char *intf = get_param(cmd, "Interface"); |
| 6727 | const char *dest = get_param(cmd, "Dest"); |
| 6728 | const char *type = get_param(cmd, "FrameName"); |
| 6729 | const char *val; |
| 6730 | char buf[200], *pos, *end; |
| 6731 | int count, count2; |
| 6732 | |
| 6733 | if (type == NULL) |
| 6734 | type = get_param(cmd, "Type"); |
| 6735 | |
| 6736 | if (intf == NULL || dest == NULL || type == NULL) |
| 6737 | return -1; |
| 6738 | |
| 6739 | if (strcasecmp(type, "NeighAdv") == 0) |
| 6740 | return cmd_sta_send_frame_hs2_neighadv(dut, conn, cmd, intf); |
| 6741 | |
| 6742 | if (strcasecmp(type, "NeighSolicitReq") == 0) |
| 6743 | return cmd_sta_send_frame_hs2_neighsolreq(dut, conn, cmd, intf); |
| 6744 | |
| 6745 | if (strcasecmp(type, "ARPProbe") == 0) |
| 6746 | return cmd_sta_send_frame_hs2_arpprobe(dut, conn, cmd, intf); |
| 6747 | |
| 6748 | if (strcasecmp(type, "ARPAnnounce") == 0) |
| 6749 | return cmd_sta_send_frame_hs2_arpannounce(dut, conn, cmd, intf); |
| 6750 | |
| 6751 | if (strcasecmp(type, "ARPReply") == 0) |
| 6752 | return cmd_sta_send_frame_hs2_arpreply(dut, conn, cmd, intf); |
| 6753 | |
| 6754 | if (strcasecmp(type, "DLS-request") == 0 || |
| 6755 | strcasecmp(type, "DLSrequest") == 0) |
| 6756 | return cmd_sta_send_frame_hs2_dls_req(dut, conn, cmd, intf, |
| 6757 | dest); |
| 6758 | |
| 6759 | if (strcasecmp(type, "ANQPQuery") != 0 && |
| 6760 | strcasecmp(type, "Query") != 0) { |
| 6761 | send_resp(dut, conn, SIGMA_ERROR, |
| 6762 | "ErrorCode,Unsupported HS 2.0 send frame type"); |
| 6763 | return 0; |
| 6764 | } |
| 6765 | |
| 6766 | if (sta_scan_ap(dut, intf, dest) < 0) { |
| 6767 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not find " |
| 6768 | "the requested AP"); |
| 6769 | return 0; |
| 6770 | } |
| 6771 | |
| 6772 | pos = buf; |
| 6773 | end = buf + sizeof(buf); |
| 6774 | count = 0; |
| 6775 | pos += snprintf(pos, end - pos, "ANQP_GET %s ", dest); |
| 6776 | |
| 6777 | val = get_param(cmd, "ANQP_CAP_LIST"); |
| 6778 | if (val && atoi(val)) { |
| 6779 | pos += snprintf(pos, end - pos, "%s257", count > 0 ? "," : ""); |
| 6780 | count++; |
| 6781 | } |
| 6782 | |
| 6783 | val = get_param(cmd, "VENUE_NAME"); |
| 6784 | if (val && atoi(val)) { |
| 6785 | pos += snprintf(pos, end - pos, "%s258", count > 0 ? "," : ""); |
| 6786 | count++; |
| 6787 | } |
| 6788 | |
| 6789 | val = get_param(cmd, "NETWORK_AUTH_TYPE"); |
| 6790 | if (val && atoi(val)) { |
| 6791 | pos += snprintf(pos, end - pos, "%s260", count > 0 ? "," : ""); |
| 6792 | count++; |
| 6793 | } |
| 6794 | |
| 6795 | val = get_param(cmd, "ROAMING_CONS"); |
| 6796 | if (val && atoi(val)) { |
| 6797 | pos += snprintf(pos, end - pos, "%s261", count > 0 ? "," : ""); |
| 6798 | count++; |
| 6799 | } |
| 6800 | |
| 6801 | val = get_param(cmd, "IP_ADDR_TYPE_AVAILABILITY"); |
| 6802 | if (val && atoi(val)) { |
| 6803 | pos += snprintf(pos, end - pos, "%s262", count > 0 ? "," : ""); |
| 6804 | count++; |
| 6805 | } |
| 6806 | |
| 6807 | val = get_param(cmd, "NAI_REALM_LIST"); |
| 6808 | if (val && atoi(val)) { |
| 6809 | pos += snprintf(pos, end - pos, "%s263", count > 0 ? "," : ""); |
| 6810 | count++; |
| 6811 | } |
| 6812 | |
| 6813 | val = get_param(cmd, "3GPP_INFO"); |
| 6814 | if (val && atoi(val)) { |
| 6815 | pos += snprintf(pos, end - pos, "%s264", count > 0 ? "," : ""); |
| 6816 | count++; |
| 6817 | } |
| 6818 | |
| 6819 | val = get_param(cmd, "DOMAIN_LIST"); |
| 6820 | if (val && atoi(val)) { |
| 6821 | pos += snprintf(pos, end - pos, "%s268", count > 0 ? "," : ""); |
| 6822 | count++; |
| 6823 | } |
| 6824 | |
| 6825 | if (count && wpa_command(intf, buf)) { |
| 6826 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,ANQP_GET failed"); |
| 6827 | return 0; |
| 6828 | } |
| 6829 | |
| 6830 | pos = buf; |
| 6831 | end = buf + sizeof(buf); |
| 6832 | count2 = 0; |
| 6833 | pos += snprintf(pos, end - pos, "HS20_ANQP_GET %s ", dest); |
| 6834 | |
| 6835 | val = get_param(cmd, "HS_CAP_LIST"); |
| 6836 | if (val && atoi(val)) { |
| 6837 | pos += snprintf(pos, end - pos, "%s2", count2 > 0 ? "," : ""); |
| 6838 | count2++; |
| 6839 | } |
| 6840 | |
| 6841 | val = get_param(cmd, "OPER_NAME"); |
| 6842 | if (val && atoi(val)) { |
| 6843 | pos += snprintf(pos, end - pos, "%s3", count2 > 0 ? "," : ""); |
| 6844 | count2++; |
| 6845 | } |
| 6846 | |
| 6847 | val = get_param(cmd, "WAN_METRICS"); |
| 6848 | if (!val) |
| 6849 | val = get_param(cmd, "WAN_MAT"); |
| 6850 | if (!val) |
| 6851 | val = get_param(cmd, "WAN_MET"); |
| 6852 | if (val && atoi(val)) { |
| 6853 | pos += snprintf(pos, end - pos, "%s4", count2 > 0 ? "," : ""); |
| 6854 | count2++; |
| 6855 | } |
| 6856 | |
| 6857 | val = get_param(cmd, "CONNECTION_CAPABILITY"); |
| 6858 | if (val && atoi(val)) { |
| 6859 | pos += snprintf(pos, end - pos, "%s5", count2 > 0 ? "," : ""); |
| 6860 | count2++; |
| 6861 | } |
| 6862 | |
| 6863 | val = get_param(cmd, "OP_CLASS"); |
| 6864 | if (val && atoi(val)) { |
| 6865 | pos += snprintf(pos, end - pos, "%s7", count2 > 0 ? "," : ""); |
| 6866 | count2++; |
| 6867 | } |
| 6868 | |
| 6869 | val = get_param(cmd, "OSU_PROVIDER_LIST"); |
| 6870 | if (val && atoi(val)) { |
| 6871 | pos += snprintf(pos, end - pos, "%s8", count2 > 0 ? "," : ""); |
| 6872 | count2++; |
| 6873 | } |
| 6874 | |
| 6875 | if (count && count2) { |
| 6876 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before sending out " |
| 6877 | "second query"); |
| 6878 | sleep(1); |
| 6879 | } |
| 6880 | |
| 6881 | if (count2 && wpa_command(intf, buf)) { |
| 6882 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,HS20_ANQP_GET " |
| 6883 | "failed"); |
| 6884 | return 0; |
| 6885 | } |
| 6886 | |
| 6887 | val = get_param(cmd, "NAI_HOME_REALM_LIST"); |
| 6888 | if (val) { |
| 6889 | if (count || count2) { |
| 6890 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before " |
| 6891 | "sending out second query"); |
| 6892 | sleep(1); |
| 6893 | } |
| 6894 | |
| 6895 | if (strcmp(val, "1") == 0) |
| 6896 | val = "mail.example.com"; |
| 6897 | snprintf(buf, end - pos, |
| 6898 | "HS20_GET_NAI_HOME_REALM_LIST %s realm=%s", |
| 6899 | dest, val); |
| 6900 | if (wpa_command(intf, buf)) { |
| 6901 | send_resp(dut, conn, SIGMA_ERROR, |
| 6902 | "ErrorCode,HS20_GET_NAI_HOME_REALM_LIST " |
| 6903 | "failed"); |
| 6904 | return 0; |
| 6905 | } |
| 6906 | } |
| 6907 | |
| 6908 | val = get_param(cmd, "ICON_REQUEST"); |
| 6909 | if (val) { |
| 6910 | if (count || count2) { |
| 6911 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before " |
| 6912 | "sending out second query"); |
| 6913 | sleep(1); |
| 6914 | } |
| 6915 | |
| 6916 | snprintf(buf, end - pos, |
| 6917 | "HS20_ICON_REQUEST %s %s", dest, val); |
| 6918 | if (wpa_command(intf, buf)) { |
| 6919 | send_resp(dut, conn, SIGMA_ERROR, |
| 6920 | "ErrorCode,HS20_ICON_REQUEST failed"); |
| 6921 | return 0; |
| 6922 | } |
| 6923 | } |
| 6924 | |
| 6925 | return 1; |
| 6926 | } |
| 6927 | |
| 6928 | |
| 6929 | static int ath_sta_send_frame_vht(struct sigma_dut *dut, |
| 6930 | struct sigma_conn *conn, |
| 6931 | struct sigma_cmd *cmd) |
| 6932 | { |
| 6933 | const char *val; |
| 6934 | char *ifname; |
| 6935 | char buf[100]; |
| 6936 | int chwidth, nss; |
| 6937 | |
| 6938 | val = get_param(cmd, "framename"); |
| 6939 | if (!val) |
| 6940 | return -1; |
| 6941 | sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val); |
| 6942 | |
| 6943 | /* Command sequence to generate Op mode notification */ |
| 6944 | if (val && strcasecmp(val, "Op_md_notif_frm") == 0) { |
| 6945 | ifname = get_station_ifname(); |
| 6946 | |
| 6947 | /* Disable STBC */ |
| 6948 | snprintf(buf, sizeof(buf), |
| 6949 | "iwpriv %s tx_stbc 0", ifname); |
| 6950 | if (system(buf) != 0) { |
| 6951 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6952 | "iwpriv tx_stbc 0 failed!"); |
| 6953 | } |
| 6954 | |
| 6955 | /* Extract Channel width */ |
| 6956 | val = get_param(cmd, "Channel_width"); |
| 6957 | if (val) { |
| 6958 | switch (atoi(val)) { |
| 6959 | case 20: |
| 6960 | chwidth = 0; |
| 6961 | break; |
| 6962 | case 40: |
| 6963 | chwidth = 1; |
| 6964 | break; |
| 6965 | case 80: |
| 6966 | chwidth = 2; |
| 6967 | break; |
| 6968 | case 160: |
| 6969 | chwidth = 3; |
| 6970 | break; |
| 6971 | default: |
| 6972 | chwidth = 2; |
| 6973 | break; |
| 6974 | } |
| 6975 | |
| 6976 | snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d", |
| 6977 | ifname, chwidth); |
| 6978 | if (system(buf) != 0) { |
| 6979 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6980 | "iwpriv chwidth failed!"); |
| 6981 | } |
| 6982 | } |
| 6983 | |
| 6984 | /* Extract NSS */ |
| 6985 | val = get_param(cmd, "NSS"); |
| 6986 | if (val) { |
| 6987 | switch (atoi(val)) { |
| 6988 | case 1: |
| 6989 | nss = 1; |
| 6990 | break; |
| 6991 | case 2: |
| 6992 | nss = 3; |
| 6993 | break; |
| 6994 | case 3: |
| 6995 | nss = 7; |
| 6996 | break; |
| 6997 | default: |
| 6998 | /* We do not support NSS > 3 */ |
| 6999 | nss = 3; |
| 7000 | break; |
| 7001 | } |
| 7002 | snprintf(buf, sizeof(buf), |
| 7003 | "iwpriv %s rxchainmask %d", ifname, nss); |
| 7004 | if (system(buf) != 0) { |
| 7005 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7006 | "iwpriv rxchainmask failed!"); |
| 7007 | } |
| 7008 | } |
| 7009 | |
| 7010 | /* Opmode notify */ |
| 7011 | snprintf(buf, sizeof(buf), "iwpriv %s opmode_notify 1", ifname); |
| 7012 | if (system(buf) != 0) { |
| 7013 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7014 | "iwpriv opmode_notify failed!"); |
| 7015 | } else { |
| 7016 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 7017 | "Sent out the notify frame!"); |
| 7018 | } |
| 7019 | } |
| 7020 | |
| 7021 | return 1; |
| 7022 | } |
| 7023 | |
| 7024 | |
| 7025 | static int cmd_sta_send_frame_vht(struct sigma_dut *dut, |
| 7026 | struct sigma_conn *conn, |
| 7027 | struct sigma_cmd *cmd) |
| 7028 | { |
| 7029 | switch (get_driver_type()) { |
| 7030 | case DRIVER_ATHEROS: |
| 7031 | return ath_sta_send_frame_vht(dut, conn, cmd); |
| 7032 | default: |
| 7033 | send_resp(dut, conn, SIGMA_ERROR, |
| 7034 | "errorCode,Unsupported sta_set_frame(VHT) with the current driver"); |
| 7035 | return 0; |
| 7036 | } |
| 7037 | } |
| 7038 | |
| 7039 | |
Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 7040 | #ifdef __linux__ |
| 7041 | int wil6210_send_frame_60g(struct sigma_dut *dut, struct sigma_conn *conn, |
| 7042 | struct sigma_cmd *cmd) |
| 7043 | { |
| 7044 | const char *frame_name = get_param(cmd, "framename"); |
| 7045 | const char *mac = get_param(cmd, "dest_mac"); |
| 7046 | |
| 7047 | if (!frame_name || !mac) { |
| 7048 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7049 | "framename and dest_mac must be provided"); |
| 7050 | return -1; |
| 7051 | } |
| 7052 | |
| 7053 | if (strcasecmp(frame_name, "brp") == 0) { |
| 7054 | const char *l_rx = get_param(cmd, "L-RX"); |
| 7055 | int l_rx_i; |
| 7056 | |
| 7057 | if (!l_rx) { |
| 7058 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7059 | "L-RX must be provided"); |
| 7060 | return -1; |
| 7061 | } |
| 7062 | l_rx_i = atoi(l_rx); |
| 7063 | |
| 7064 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 7065 | "dev_send_frame: BRP-RX, dest_mac %s, L-RX %s", |
| 7066 | mac, l_rx); |
| 7067 | if (l_rx_i != 16) { |
| 7068 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7069 | "unsupported L-RX: %s", l_rx); |
| 7070 | return -1; |
| 7071 | } |
| 7072 | |
| 7073 | if (wil6210_send_brp_rx(dut, mac, l_rx_i)) |
| 7074 | return -1; |
| 7075 | } else if (strcasecmp(frame_name, "ssw") == 0) { |
| 7076 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 7077 | "dev_send_frame: SLS, dest_mac %s", mac); |
| 7078 | if (wil6210_send_sls(dut, mac)) |
| 7079 | return -1; |
| 7080 | } else { |
| 7081 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7082 | "unsupported frame type: %s", frame_name); |
| 7083 | return -1; |
| 7084 | } |
| 7085 | |
| 7086 | return 1; |
| 7087 | } |
| 7088 | #endif /* __linux__ */ |
| 7089 | |
| 7090 | |
| 7091 | static int cmd_sta_send_frame_60g(struct sigma_dut *dut, |
| 7092 | struct sigma_conn *conn, |
| 7093 | struct sigma_cmd *cmd) |
| 7094 | { |
| 7095 | switch (get_driver_type()) { |
| 7096 | #ifdef __linux__ |
| 7097 | case DRIVER_WIL6210: |
| 7098 | return wil6210_send_frame_60g(dut, conn, cmd); |
| 7099 | #endif /* __linux__ */ |
| 7100 | default: |
| 7101 | send_resp(dut, conn, SIGMA_ERROR, |
| 7102 | "errorCode,Unsupported sta_set_frame(60G) with the current driver"); |
| 7103 | return 0; |
| 7104 | } |
| 7105 | } |
| 7106 | |
| 7107 | |
Ashwini Patil | db59b3c | 2017-04-13 15:19:23 +0530 | [diff] [blame] | 7108 | static int mbo_send_anqp_query(struct sigma_dut *dut, struct sigma_conn *conn, |
| 7109 | const char *intf, struct sigma_cmd *cmd) |
| 7110 | { |
| 7111 | const char *val, *addr; |
| 7112 | char buf[100]; |
| 7113 | |
| 7114 | addr = get_param(cmd, "DestMac"); |
| 7115 | if (!addr) { |
| 7116 | send_resp(dut, conn, SIGMA_INVALID, |
| 7117 | "ErrorCode,AP MAC address is missing"); |
| 7118 | return 0; |
| 7119 | } |
| 7120 | |
| 7121 | val = get_param(cmd, "ANQPQuery_ID"); |
| 7122 | if (!val) { |
| 7123 | send_resp(dut, conn, SIGMA_INVALID, |
| 7124 | "ErrorCode,Missing ANQPQuery_ID"); |
| 7125 | return 0; |
| 7126 | } |
| 7127 | |
| 7128 | if (strcasecmp(val, "NeighborReportReq") == 0) { |
| 7129 | snprintf(buf, sizeof(buf), "ANQP_GET %s 272", addr); |
| 7130 | } else if (strcasecmp(val, "QueryListWithCellPref") == 0) { |
| 7131 | snprintf(buf, sizeof(buf), "ANQP_GET %s 272,mbo:2", addr); |
| 7132 | } else { |
| 7133 | sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid ANQPQuery_ID: %s", |
| 7134 | val); |
| 7135 | send_resp(dut, conn, SIGMA_INVALID, |
| 7136 | "ErrorCode,Invalid ANQPQuery_ID"); |
| 7137 | return 0; |
| 7138 | } |
| 7139 | |
Ashwini Patil | d174f2c | 2017-04-13 16:49:46 +0530 | [diff] [blame] | 7140 | /* Set gas_address3 field to IEEE 802.11-2012 standard compliant form |
| 7141 | * (Address3 = Wildcard BSSID when sent to not-associated AP; |
| 7142 | * if associated, AP BSSID). |
| 7143 | */ |
| 7144 | if (wpa_command(intf, "SET gas_address3 1") < 0) { |
| 7145 | send_resp(dut, conn, SIGMA_ERROR, |
| 7146 | "ErrorCode,Failed to set gas_address3"); |
| 7147 | return 0; |
| 7148 | } |
| 7149 | |
Ashwini Patil | db59b3c | 2017-04-13 15:19:23 +0530 | [diff] [blame] | 7150 | if (wpa_command(intf, buf) < 0) { |
| 7151 | send_resp(dut, conn, SIGMA_ERROR, |
| 7152 | "ErrorCode,Failed to send ANQP query"); |
| 7153 | return 0; |
| 7154 | } |
| 7155 | |
| 7156 | return 1; |
| 7157 | } |
| 7158 | |
| 7159 | |
| 7160 | static int mbo_cmd_sta_send_frame(struct sigma_dut *dut, |
| 7161 | struct sigma_conn *conn, |
| 7162 | const char *intf, |
| 7163 | struct sigma_cmd *cmd) |
| 7164 | { |
| 7165 | const char *val = get_param(cmd, "FrameName"); |
| 7166 | |
| 7167 | if (val && strcasecmp(val, "ANQPQuery") == 0) |
| 7168 | return mbo_send_anqp_query(dut, conn, intf, cmd); |
| 7169 | |
| 7170 | return 2; |
| 7171 | } |
| 7172 | |
| 7173 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7174 | int cmd_sta_send_frame(struct sigma_dut *dut, struct sigma_conn *conn, |
| 7175 | struct sigma_cmd *cmd) |
| 7176 | { |
| 7177 | const char *intf = get_param(cmd, "Interface"); |
| 7178 | const char *val; |
| 7179 | enum send_frame_type frame; |
| 7180 | enum send_frame_protection protected; |
| 7181 | char buf[100]; |
| 7182 | unsigned char addr[ETH_ALEN]; |
| 7183 | int res; |
| 7184 | |
| 7185 | val = get_param(cmd, "program"); |
| 7186 | if (val == NULL) |
| 7187 | val = get_param(cmd, "frame"); |
| 7188 | if (val && strcasecmp(val, "TDLS") == 0) |
| 7189 | return cmd_sta_send_frame_tdls(dut, conn, cmd); |
| 7190 | if (val && (strcasecmp(val, "HS2") == 0 || |
| 7191 | strcasecmp(val, "HS2-R2") == 0)) |
| 7192 | return cmd_sta_send_frame_hs2(dut, conn, cmd); |
| 7193 | if (val && strcasecmp(val, "VHT") == 0) |
| 7194 | return cmd_sta_send_frame_vht(dut, conn, cmd); |
priyadharshini gowthaman | d66913a | 2016-07-29 15:11:17 -0700 | [diff] [blame] | 7195 | if (val && strcasecmp(val, "LOC") == 0) |
| 7196 | return loc_cmd_sta_send_frame(dut, conn, cmd); |
Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 7197 | if (val && strcasecmp(val, "60GHz") == 0) |
| 7198 | return cmd_sta_send_frame_60g(dut, conn, cmd); |
Ashwini Patil | db59b3c | 2017-04-13 15:19:23 +0530 | [diff] [blame] | 7199 | if (val && strcasecmp(val, "MBO") == 0) { |
| 7200 | res = mbo_cmd_sta_send_frame(dut, conn, intf, cmd); |
| 7201 | if (res != 2) |
| 7202 | return res; |
| 7203 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7204 | |
| 7205 | val = get_param(cmd, "TD_DISC"); |
| 7206 | if (val) { |
| 7207 | if (hwaddr_aton(val, addr) < 0) |
| 7208 | return -1; |
| 7209 | snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", val); |
| 7210 | if (wpa_command(intf, buf) < 0) { |
| 7211 | send_resp(dut, conn, SIGMA_ERROR, |
| 7212 | "ErrorCode,Failed to send TDLS discovery"); |
| 7213 | return 0; |
| 7214 | } |
| 7215 | return 1; |
| 7216 | } |
| 7217 | |
| 7218 | val = get_param(cmd, "TD_Setup"); |
| 7219 | if (val) { |
| 7220 | if (hwaddr_aton(val, addr) < 0) |
| 7221 | return -1; |
| 7222 | snprintf(buf, sizeof(buf), "TDLS_SETUP %s", val); |
| 7223 | if (wpa_command(intf, buf) < 0) { |
| 7224 | send_resp(dut, conn, SIGMA_ERROR, |
| 7225 | "ErrorCode,Failed to start TDLS setup"); |
| 7226 | return 0; |
| 7227 | } |
| 7228 | return 1; |
| 7229 | } |
| 7230 | |
| 7231 | val = get_param(cmd, "TD_TearDown"); |
| 7232 | if (val) { |
| 7233 | if (hwaddr_aton(val, addr) < 0) |
| 7234 | return -1; |
| 7235 | snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", val); |
| 7236 | if (wpa_command(intf, buf) < 0) { |
| 7237 | send_resp(dut, conn, SIGMA_ERROR, |
| 7238 | "ErrorCode,Failed to tear down TDLS link"); |
| 7239 | return 0; |
| 7240 | } |
| 7241 | return 1; |
| 7242 | } |
| 7243 | |
| 7244 | val = get_param(cmd, "TD_ChannelSwitch"); |
| 7245 | if (val) { |
| 7246 | /* TODO */ |
| 7247 | send_resp(dut, conn, SIGMA_ERROR, |
| 7248 | "ErrorCode,TD_ChannelSwitch not yet supported"); |
| 7249 | return 0; |
| 7250 | } |
| 7251 | |
| 7252 | val = get_param(cmd, "TD_NF"); |
| 7253 | if (val) { |
| 7254 | /* TODO */ |
| 7255 | send_resp(dut, conn, SIGMA_ERROR, |
| 7256 | "ErrorCode,TD_NF not yet supported"); |
| 7257 | return 0; |
| 7258 | } |
| 7259 | |
| 7260 | val = get_param(cmd, "PMFFrameType"); |
| 7261 | if (val == NULL) |
| 7262 | val = get_param(cmd, "FrameName"); |
| 7263 | if (val == NULL) |
| 7264 | val = get_param(cmd, "Type"); |
| 7265 | if (val == NULL) |
| 7266 | return -1; |
| 7267 | if (strcasecmp(val, "disassoc") == 0) |
| 7268 | frame = DISASSOC; |
| 7269 | else if (strcasecmp(val, "deauth") == 0) |
| 7270 | frame = DEAUTH; |
| 7271 | else if (strcasecmp(val, "saquery") == 0) |
| 7272 | frame = SAQUERY; |
| 7273 | else if (strcasecmp(val, "auth") == 0) |
| 7274 | frame = AUTH; |
| 7275 | else if (strcasecmp(val, "assocreq") == 0) |
| 7276 | frame = ASSOCREQ; |
| 7277 | else if (strcasecmp(val, "reassocreq") == 0) |
| 7278 | frame = REASSOCREQ; |
| 7279 | else if (strcasecmp(val, "neigreq") == 0) { |
| 7280 | sigma_dut_print(dut, DUT_MSG_INFO, "Got neighbor request"); |
| 7281 | |
| 7282 | val = get_param(cmd, "ssid"); |
| 7283 | if (val == NULL) |
| 7284 | return -1; |
| 7285 | |
| 7286 | res = send_neighbor_request(dut, intf, val); |
| 7287 | if (res) { |
| 7288 | send_resp(dut, conn, SIGMA_ERROR, "errorCode," |
| 7289 | "Failed to send neighbor report request"); |
| 7290 | return 0; |
| 7291 | } |
| 7292 | |
| 7293 | return 1; |
Ashwini Patil | 5acd738 | 2017-04-13 15:55:04 +0530 | [diff] [blame] | 7294 | } else if (strcasecmp(val, "transmgmtquery") == 0 || |
| 7295 | strcasecmp(val, "BTMQuery") == 0) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7296 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 7297 | "Got Transition Management Query"); |
| 7298 | |
Ashwini Patil | 5acd738 | 2017-04-13 15:55:04 +0530 | [diff] [blame] | 7299 | res = send_trans_mgmt_query(dut, intf, cmd); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7300 | if (res) { |
| 7301 | send_resp(dut, conn, SIGMA_ERROR, "errorCode," |
| 7302 | "Failed to send Transition Management Query"); |
| 7303 | return 0; |
| 7304 | } |
| 7305 | |
| 7306 | return 1; |
| 7307 | } else { |
| 7308 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported " |
| 7309 | "PMFFrameType"); |
| 7310 | return 0; |
| 7311 | } |
| 7312 | |
| 7313 | val = get_param(cmd, "PMFProtected"); |
| 7314 | if (val == NULL) |
| 7315 | val = get_param(cmd, "Protected"); |
| 7316 | if (val == NULL) |
| 7317 | return -1; |
| 7318 | if (strcasecmp(val, "Correct-key") == 0 || |
| 7319 | strcasecmp(val, "CorrectKey") == 0) |
| 7320 | protected = CORRECT_KEY; |
| 7321 | else if (strcasecmp(val, "IncorrectKey") == 0) |
| 7322 | protected = INCORRECT_KEY; |
| 7323 | else if (strcasecmp(val, "Unprotected") == 0) |
| 7324 | protected = UNPROTECTED; |
| 7325 | else { |
| 7326 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported " |
| 7327 | "PMFProtected"); |
| 7328 | return 0; |
| 7329 | } |
| 7330 | |
| 7331 | if (protected != UNPROTECTED && |
| 7332 | (frame == AUTH || frame == ASSOCREQ || frame == REASSOCREQ)) { |
| 7333 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Impossible " |
| 7334 | "PMFProtected for auth/assocreq/reassocreq"); |
| 7335 | return 0; |
| 7336 | } |
| 7337 | |
| 7338 | if (if_nametoindex("sigmadut") == 0) { |
| 7339 | snprintf(buf, sizeof(buf), |
| 7340 | "iw dev %s interface add sigmadut type monitor", |
| 7341 | get_station_ifname()); |
| 7342 | if (system(buf) != 0 || |
| 7343 | if_nametoindex("sigmadut") == 0) { |
| 7344 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add " |
| 7345 | "monitor interface with '%s'", buf); |
| 7346 | return -2; |
| 7347 | } |
| 7348 | } |
| 7349 | |
| 7350 | if (system("ifconfig sigmadut up") != 0) { |
| 7351 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set " |
| 7352 | "monitor interface up"); |
| 7353 | return -2; |
| 7354 | } |
| 7355 | |
| 7356 | return sta_inject_frame(dut, conn, frame, protected, NULL); |
| 7357 | } |
| 7358 | |
| 7359 | |
| 7360 | static int cmd_sta_set_parameter_hs2(struct sigma_dut *dut, |
| 7361 | struct sigma_conn *conn, |
| 7362 | struct sigma_cmd *cmd, |
| 7363 | const char *ifname) |
| 7364 | { |
| 7365 | char buf[200]; |
| 7366 | const char *val; |
| 7367 | |
| 7368 | val = get_param(cmd, "ClearARP"); |
| 7369 | if (val && atoi(val) == 1) { |
| 7370 | snprintf(buf, sizeof(buf), "ip neigh flush dev %s", ifname); |
| 7371 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 7372 | if (system(buf) != 0) { |
| 7373 | send_resp(dut, conn, SIGMA_ERROR, |
| 7374 | "errorCode,Failed to clear ARP cache"); |
| 7375 | return 0; |
| 7376 | } |
| 7377 | } |
| 7378 | |
| 7379 | return 1; |
| 7380 | } |
| 7381 | |
| 7382 | |
| 7383 | int cmd_sta_set_parameter(struct sigma_dut *dut, struct sigma_conn *conn, |
| 7384 | struct sigma_cmd *cmd) |
| 7385 | { |
| 7386 | const char *intf = get_param(cmd, "Interface"); |
| 7387 | const char *val; |
| 7388 | |
| 7389 | if (intf == NULL) |
| 7390 | return -1; |
| 7391 | |
| 7392 | val = get_param(cmd, "program"); |
| 7393 | if (val && (strcasecmp(val, "HS2") == 0 || |
| 7394 | strcasecmp(val, "HS2-R2") == 0)) |
| 7395 | return cmd_sta_set_parameter_hs2(dut, conn, cmd, intf); |
| 7396 | |
| 7397 | return -1; |
| 7398 | } |
| 7399 | |
| 7400 | |
| 7401 | static int cmd_sta_set_macaddr(struct sigma_dut *dut, struct sigma_conn *conn, |
| 7402 | struct sigma_cmd *cmd) |
| 7403 | { |
| 7404 | const char *intf = get_param(cmd, "Interface"); |
| 7405 | const char *mac = get_param(cmd, "MAC"); |
| 7406 | |
| 7407 | if (intf == NULL || mac == NULL) |
| 7408 | return -1; |
| 7409 | |
| 7410 | sigma_dut_print(dut, DUT_MSG_INFO, "Change local MAC address for " |
| 7411 | "interface %s to %s", intf, mac); |
| 7412 | |
| 7413 | if (dut->set_macaddr) { |
| 7414 | char buf[128]; |
| 7415 | int res; |
| 7416 | if (strcasecmp(mac, "default") == 0) { |
| 7417 | res = snprintf(buf, sizeof(buf), "%s", |
| 7418 | dut->set_macaddr); |
| 7419 | dut->tmp_mac_addr = 0; |
| 7420 | } else { |
| 7421 | res = snprintf(buf, sizeof(buf), "%s %s", |
| 7422 | dut->set_macaddr, mac); |
| 7423 | dut->tmp_mac_addr = 1; |
| 7424 | } |
| 7425 | if (res < 0 || res >= (int) sizeof(buf)) |
| 7426 | return -1; |
| 7427 | if (system(buf) != 0) { |
| 7428 | send_resp(dut, conn, SIGMA_ERROR, |
| 7429 | "errorCode,Failed to set MAC " |
| 7430 | "address"); |
| 7431 | return 0; |
| 7432 | } |
| 7433 | return 1; |
| 7434 | } |
| 7435 | |
| 7436 | if (strcasecmp(mac, "default") == 0) |
| 7437 | return 1; |
| 7438 | |
| 7439 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported " |
| 7440 | "command"); |
| 7441 | return 0; |
| 7442 | } |
| 7443 | |
| 7444 | |
| 7445 | static int iwpriv_tdlsoffchnmode(struct sigma_dut *dut, |
| 7446 | struct sigma_conn *conn, const char *intf, |
| 7447 | int val) |
| 7448 | { |
| 7449 | char buf[200]; |
| 7450 | int res; |
| 7451 | |
| 7452 | res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchnmode %d", |
| 7453 | intf, val); |
| 7454 | if (res < 0 || res >= (int) sizeof(buf)) |
| 7455 | return -1; |
| 7456 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 7457 | if (system(buf) != 0) { |
| 7458 | send_resp(dut, conn, SIGMA_ERROR, |
| 7459 | "errorCode,Failed to configure offchannel mode"); |
| 7460 | return 0; |
| 7461 | } |
| 7462 | |
| 7463 | return 1; |
| 7464 | } |
| 7465 | |
| 7466 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7467 | static int off_chan_val(enum sec_ch_offset off) |
| 7468 | { |
| 7469 | switch (off) { |
| 7470 | case SEC_CH_NO: |
| 7471 | return 0; |
| 7472 | case SEC_CH_40ABOVE: |
| 7473 | return 40; |
| 7474 | case SEC_CH_40BELOW: |
| 7475 | return -40; |
| 7476 | } |
| 7477 | |
| 7478 | return 0; |
| 7479 | } |
| 7480 | |
| 7481 | |
| 7482 | static int iwpriv_set_offchan(struct sigma_dut *dut, struct sigma_conn *conn, |
| 7483 | const char *intf, int off_ch_num, |
| 7484 | enum sec_ch_offset sec) |
| 7485 | { |
| 7486 | char buf[200]; |
| 7487 | int res; |
| 7488 | |
| 7489 | res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchan %d", |
| 7490 | intf, off_ch_num); |
| 7491 | if (res < 0 || res >= (int) sizeof(buf)) |
| 7492 | return -1; |
| 7493 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 7494 | if (system(buf) != 0) { |
| 7495 | send_resp(dut, conn, SIGMA_ERROR, |
| 7496 | "errorCode,Failed to set offchan"); |
| 7497 | return 0; |
| 7498 | } |
| 7499 | |
| 7500 | res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsecchnoffst %d", |
| 7501 | intf, off_chan_val(sec)); |
| 7502 | if (res < 0 || res >= (int) sizeof(buf)) |
| 7503 | return -1; |
| 7504 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 7505 | if (system(buf) != 0) { |
| 7506 | send_resp(dut, conn, SIGMA_ERROR, |
| 7507 | "errorCode,Failed to set sec chan offset"); |
| 7508 | return 0; |
| 7509 | } |
| 7510 | |
| 7511 | return 1; |
| 7512 | } |
| 7513 | |
| 7514 | |
| 7515 | static int tdls_set_offchannel_offset(struct sigma_dut *dut, |
| 7516 | struct sigma_conn *conn, |
| 7517 | const char *intf, int off_ch_num, |
| 7518 | enum sec_ch_offset sec) |
| 7519 | { |
| 7520 | char buf[200]; |
| 7521 | int res; |
| 7522 | |
| 7523 | res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNEL %d", |
| 7524 | off_ch_num); |
| 7525 | if (res < 0 || res >= (int) sizeof(buf)) |
| 7526 | return -1; |
| 7527 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 7528 | |
| 7529 | if (wpa_command(intf, buf) < 0) { |
| 7530 | send_resp(dut, conn, SIGMA_ERROR, |
| 7531 | "ErrorCode,Failed to set offchan"); |
| 7532 | return 0; |
| 7533 | } |
| 7534 | res = snprintf(buf, sizeof(buf), "DRIVER TDLSSECONDARYCHANNELOFFSET %d", |
| 7535 | off_chan_val(sec)); |
| 7536 | if (res < 0 || res >= (int) sizeof(buf)) |
| 7537 | return -1; |
| 7538 | |
| 7539 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 7540 | |
| 7541 | if (wpa_command(intf, buf) < 0) { |
| 7542 | send_resp(dut, conn, SIGMA_ERROR, |
| 7543 | "ErrorCode,Failed to set sec chan offset"); |
| 7544 | return 0; |
| 7545 | } |
| 7546 | |
| 7547 | return 1; |
| 7548 | } |
| 7549 | |
| 7550 | |
| 7551 | static int tdls_set_offchannel_mode(struct sigma_dut *dut, |
| 7552 | struct sigma_conn *conn, |
| 7553 | const char *intf, int val) |
| 7554 | { |
| 7555 | char buf[200]; |
| 7556 | int res; |
| 7557 | |
| 7558 | res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNELMODE %d", |
| 7559 | val); |
| 7560 | if (res < 0 || res >= (int) sizeof(buf)) |
| 7561 | return -1; |
| 7562 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 7563 | |
| 7564 | if (wpa_command(intf, buf) < 0) { |
| 7565 | send_resp(dut, conn, SIGMA_ERROR, |
| 7566 | "ErrorCode,Failed to configure offchannel mode"); |
| 7567 | return 0; |
| 7568 | } |
| 7569 | |
| 7570 | return 1; |
| 7571 | } |
| 7572 | |
| 7573 | |
| 7574 | static int cmd_sta_set_rfeature_tdls(const char *intf, struct sigma_dut *dut, |
| 7575 | struct sigma_conn *conn, |
| 7576 | struct sigma_cmd *cmd) |
| 7577 | { |
| 7578 | const char *val; |
| 7579 | enum { |
| 7580 | CHSM_NOT_SET, |
| 7581 | CHSM_ENABLE, |
| 7582 | CHSM_DISABLE, |
| 7583 | CHSM_REJREQ, |
| 7584 | CHSM_UNSOLRESP |
| 7585 | } chsm = CHSM_NOT_SET; |
| 7586 | int off_ch_num = -1; |
| 7587 | enum sec_ch_offset sec_ch = SEC_CH_NO; |
| 7588 | int res; |
| 7589 | |
| 7590 | val = get_param(cmd, "Uapsd"); |
| 7591 | if (val) { |
| 7592 | char buf[100]; |
| 7593 | if (strcasecmp(val, "Enable") == 0) |
| 7594 | snprintf(buf, sizeof(buf), "SET ps 99"); |
| 7595 | else if (strcasecmp(val, "Disable") == 0) |
| 7596 | snprintf(buf, sizeof(buf), "SET ps 98"); |
| 7597 | else { |
| 7598 | send_resp(dut, conn, SIGMA_ERROR, "errorCode," |
| 7599 | "Unsupported uapsd parameter value"); |
| 7600 | return 0; |
| 7601 | } |
| 7602 | if (wpa_command(intf, buf)) { |
| 7603 | send_resp(dut, conn, SIGMA_ERROR, |
| 7604 | "ErrorCode,Failed to change U-APSD " |
| 7605 | "powersave mode"); |
| 7606 | return 0; |
| 7607 | } |
| 7608 | } |
| 7609 | |
| 7610 | val = get_param(cmd, "TPKTIMER"); |
| 7611 | if (val && strcasecmp(val, "DISABLE") == 0) { |
| 7612 | if (wpa_command(intf, "SET tdls_testing 0x100")) { |
| 7613 | send_resp(dut, conn, SIGMA_ERROR, |
| 7614 | "ErrorCode,Failed to enable no TPK " |
| 7615 | "expiration test mode"); |
| 7616 | return 0; |
| 7617 | } |
| 7618 | dut->no_tpk_expiration = 1; |
| 7619 | } |
| 7620 | |
| 7621 | val = get_param(cmd, "ChSwitchMode"); |
| 7622 | if (val) { |
| 7623 | if (strcasecmp(val, "Enable") == 0 || |
| 7624 | strcasecmp(val, "Initiate") == 0) |
| 7625 | chsm = CHSM_ENABLE; |
| 7626 | else if (strcasecmp(val, "Disable") == 0 || |
| 7627 | strcasecmp(val, "passive") == 0) |
| 7628 | chsm = CHSM_DISABLE; |
| 7629 | else if (strcasecmp(val, "RejReq") == 0) |
| 7630 | chsm = CHSM_REJREQ; |
| 7631 | else if (strcasecmp(val, "UnSolResp") == 0) |
| 7632 | chsm = CHSM_UNSOLRESP; |
| 7633 | else { |
| 7634 | send_resp(dut, conn, SIGMA_ERROR, |
| 7635 | "ErrorCode,Unknown ChSwitchMode value"); |
| 7636 | return 0; |
| 7637 | } |
| 7638 | } |
| 7639 | |
| 7640 | val = get_param(cmd, "OffChNum"); |
| 7641 | if (val) { |
| 7642 | off_ch_num = atoi(val); |
| 7643 | if (off_ch_num == 0) { |
| 7644 | send_resp(dut, conn, SIGMA_ERROR, |
| 7645 | "ErrorCode,Invalid OffChNum"); |
| 7646 | return 0; |
| 7647 | } |
| 7648 | } |
| 7649 | |
| 7650 | val = get_param(cmd, "SecChOffset"); |
| 7651 | if (val) { |
| 7652 | if (strcmp(val, "20") == 0) |
| 7653 | sec_ch = SEC_CH_NO; |
| 7654 | else if (strcasecmp(val, "40above") == 0) |
| 7655 | sec_ch = SEC_CH_40ABOVE; |
| 7656 | else if (strcasecmp(val, "40below") == 0) |
| 7657 | sec_ch = SEC_CH_40BELOW; |
| 7658 | else { |
| 7659 | send_resp(dut, conn, SIGMA_ERROR, |
| 7660 | "ErrorCode,Unknown SecChOffset value"); |
| 7661 | return 0; |
| 7662 | } |
| 7663 | } |
| 7664 | |
| 7665 | if (chsm == CHSM_NOT_SET) { |
| 7666 | /* no offchannel changes requested */ |
| 7667 | return 1; |
| 7668 | } |
| 7669 | |
| 7670 | if (strcmp(intf, get_main_ifname()) != 0 && |
| 7671 | strcmp(intf, get_station_ifname()) != 0) { |
| 7672 | send_resp(dut, conn, SIGMA_ERROR, |
| 7673 | "ErrorCode,Unknown interface"); |
| 7674 | return 0; |
| 7675 | } |
| 7676 | |
| 7677 | switch (chsm) { |
| 7678 | case CHSM_NOT_SET: |
Jouni Malinen | 280f5ba | 2016-08-29 21:33:10 +0300 | [diff] [blame] | 7679 | res = 1; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7680 | break; |
| 7681 | case CHSM_ENABLE: |
| 7682 | if (off_ch_num < 0) { |
| 7683 | send_resp(dut, conn, SIGMA_ERROR, |
| 7684 | "ErrorCode,Missing OffChNum argument"); |
| 7685 | return 0; |
| 7686 | } |
| 7687 | if (wifi_chip_type == DRIVER_WCN) { |
| 7688 | res = tdls_set_offchannel_offset(dut, conn, intf, |
| 7689 | off_ch_num, sec_ch); |
| 7690 | } else { |
| 7691 | res = iwpriv_set_offchan(dut, conn, intf, off_ch_num, |
| 7692 | sec_ch); |
| 7693 | } |
| 7694 | if (res != 1) |
| 7695 | return res; |
| 7696 | if (wifi_chip_type == DRIVER_WCN) |
| 7697 | res = tdls_set_offchannel_mode(dut, conn, intf, 1); |
| 7698 | else |
| 7699 | res = iwpriv_tdlsoffchnmode(dut, conn, intf, 1); |
| 7700 | break; |
| 7701 | case CHSM_DISABLE: |
| 7702 | if (wifi_chip_type == DRIVER_WCN) |
| 7703 | res = tdls_set_offchannel_mode(dut, conn, intf, 2); |
| 7704 | else |
| 7705 | res = iwpriv_tdlsoffchnmode(dut, conn, intf, 2); |
| 7706 | break; |
| 7707 | case CHSM_REJREQ: |
| 7708 | if (wifi_chip_type == DRIVER_WCN) |
| 7709 | res = tdls_set_offchannel_mode(dut, conn, intf, 3); |
| 7710 | else |
| 7711 | res = iwpriv_tdlsoffchnmode(dut, conn, intf, 3); |
| 7712 | break; |
| 7713 | case CHSM_UNSOLRESP: |
| 7714 | if (off_ch_num < 0) { |
| 7715 | send_resp(dut, conn, SIGMA_ERROR, |
| 7716 | "ErrorCode,Missing OffChNum argument"); |
| 7717 | return 0; |
| 7718 | } |
| 7719 | if (wifi_chip_type == DRIVER_WCN) { |
| 7720 | res = tdls_set_offchannel_offset(dut, conn, intf, |
| 7721 | off_ch_num, sec_ch); |
| 7722 | } else { |
| 7723 | res = iwpriv_set_offchan(dut, conn, intf, off_ch_num, |
| 7724 | sec_ch); |
| 7725 | } |
| 7726 | if (res != 1) |
| 7727 | return res; |
| 7728 | if (wifi_chip_type == DRIVER_WCN) |
| 7729 | res = tdls_set_offchannel_mode(dut, conn, intf, 4); |
| 7730 | else |
| 7731 | res = iwpriv_tdlsoffchnmode(dut, conn, intf, 4); |
| 7732 | break; |
| 7733 | } |
| 7734 | |
| 7735 | return res; |
| 7736 | } |
| 7737 | |
| 7738 | |
| 7739 | static int ath_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut, |
| 7740 | struct sigma_conn *conn, |
| 7741 | struct sigma_cmd *cmd) |
| 7742 | { |
| 7743 | const char *val; |
| 7744 | char *token, *result; |
| 7745 | |
priyadharshini gowthaman | e5e2517 | 2015-12-08 14:53:48 -0800 | [diff] [blame] | 7746 | novap_reset(dut, intf); |
| 7747 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7748 | val = get_param(cmd, "nss_mcs_opt"); |
| 7749 | if (val) { |
| 7750 | /* String (nss_operating_mode; mcs_operating_mode) */ |
| 7751 | int nss, mcs; |
| 7752 | char buf[50]; |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 7753 | char *saveptr; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7754 | |
| 7755 | token = strdup(val); |
| 7756 | if (!token) |
| 7757 | return 0; |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 7758 | result = strtok_r(token, ";", &saveptr); |
Pradeep Reddy POTTETI | 41b8c54 | 2016-06-15 16:09:46 +0530 | [diff] [blame] | 7759 | if (!result) { |
| 7760 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7761 | "VHT NSS not specified"); |
| 7762 | goto failed; |
| 7763 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7764 | if (strcasecmp(result, "def") != 0) { |
| 7765 | nss = atoi(result); |
| 7766 | if (nss == 4) |
| 7767 | ath_disable_txbf(dut, intf); |
| 7768 | snprintf(buf, sizeof(buf), "iwpriv %s nss %d", |
| 7769 | intf, nss); |
| 7770 | if (system(buf) != 0) { |
| 7771 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7772 | "iwpriv nss failed"); |
| 7773 | goto failed; |
| 7774 | } |
| 7775 | } |
| 7776 | |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 7777 | result = strtok_r(NULL, ";", &saveptr); |
Pradeep Reddy POTTETI | 41b8c54 | 2016-06-15 16:09:46 +0530 | [diff] [blame] | 7778 | if (!result) { |
| 7779 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7780 | "VHT MCS not specified"); |
| 7781 | goto failed; |
| 7782 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7783 | if (strcasecmp(result, "def") == 0) { |
| 7784 | snprintf(buf, sizeof(buf), "iwpriv %s set11NRates 0", |
| 7785 | intf); |
| 7786 | if (system(buf) != 0) { |
| 7787 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7788 | "iwpriv set11NRates failed"); |
| 7789 | goto failed; |
| 7790 | } |
| 7791 | |
| 7792 | } else { |
| 7793 | mcs = atoi(result); |
| 7794 | snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs %d", |
| 7795 | intf, mcs); |
| 7796 | if (system(buf) != 0) { |
| 7797 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7798 | "iwpriv vhtmcs failed"); |
| 7799 | goto failed; |
| 7800 | } |
| 7801 | } |
| 7802 | /* Channel width gets messed up, fix this */ |
| 7803 | snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d", |
| 7804 | intf, dut->chwidth); |
| 7805 | if (system(buf) != 0) { |
| 7806 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7807 | "iwpriv chwidth failed"); |
| 7808 | } |
| 7809 | } |
| 7810 | |
| 7811 | return 1; |
| 7812 | failed: |
| 7813 | free(token); |
| 7814 | return 0; |
| 7815 | } |
| 7816 | |
| 7817 | |
| 7818 | static int cmd_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut, |
| 7819 | struct sigma_conn *conn, |
| 7820 | struct sigma_cmd *cmd) |
| 7821 | { |
| 7822 | switch (get_driver_type()) { |
| 7823 | case DRIVER_ATHEROS: |
| 7824 | return ath_sta_set_rfeature_vht(intf, dut, conn, cmd); |
| 7825 | default: |
| 7826 | send_resp(dut, conn, SIGMA_ERROR, |
| 7827 | "errorCode,Unsupported sta_set_rfeature(VHT) with the current driver"); |
| 7828 | return 0; |
| 7829 | } |
| 7830 | } |
| 7831 | |
| 7832 | |
Ashwini Patil | 5acd738 | 2017-04-13 15:55:04 +0530 | [diff] [blame] | 7833 | static int btm_query_candidate_list(struct sigma_dut *dut, |
| 7834 | struct sigma_conn *conn, |
| 7835 | struct sigma_cmd *cmd) |
| 7836 | { |
| 7837 | const char *bssid, *info, *op_class, *ch, *phy_type, *pref; |
| 7838 | int len, ret; |
| 7839 | char buf[10]; |
| 7840 | |
| 7841 | /* |
| 7842 | * Neighbor Report elements format: |
| 7843 | * neighbor=<BSSID>,<BSSID Information>,<Operating Class>, |
| 7844 | * <Channel Number>,<PHY Type>[,<hexdump of Optional Subelements>] |
| 7845 | * eg: neighbor=aa:bb:cc:dd:ee:ff,17,81,6,1,030101 |
| 7846 | */ |
| 7847 | |
| 7848 | bssid = get_param(cmd, "Nebor_BSSID"); |
| 7849 | if (!bssid) { |
| 7850 | send_resp(dut, conn, SIGMA_INVALID, |
| 7851 | "errorCode,Nebor_BSSID is missing"); |
| 7852 | return 0; |
| 7853 | } |
| 7854 | |
| 7855 | info = get_param(cmd, "Nebor_Bssid_Info"); |
| 7856 | if (!info) { |
| 7857 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 7858 | "Using default value for Nebor_Bssid_Info: %s", |
| 7859 | DEFAULT_NEIGHBOR_BSSID_INFO); |
| 7860 | info = DEFAULT_NEIGHBOR_BSSID_INFO; |
| 7861 | } |
| 7862 | |
| 7863 | op_class = get_param(cmd, "Nebor_Op_Class"); |
| 7864 | if (!op_class) { |
| 7865 | send_resp(dut, conn, SIGMA_INVALID, |
| 7866 | "errorCode,Nebor_Op_Class is missing"); |
| 7867 | return 0; |
| 7868 | } |
| 7869 | |
| 7870 | ch = get_param(cmd, "Nebor_Op_Ch"); |
| 7871 | if (!ch) { |
| 7872 | send_resp(dut, conn, SIGMA_INVALID, |
| 7873 | "errorCode,Nebor_Op_Ch is missing"); |
| 7874 | return 0; |
| 7875 | } |
| 7876 | |
| 7877 | phy_type = get_param(cmd, "Nebor_Phy_Type"); |
| 7878 | if (!phy_type) { |
| 7879 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 7880 | "Using default value for Nebor_Phy_Type: %s", |
| 7881 | DEFAULT_NEIGHBOR_PHY_TYPE); |
| 7882 | phy_type = DEFAULT_NEIGHBOR_PHY_TYPE; |
| 7883 | } |
| 7884 | |
| 7885 | /* Parse optional subelements */ |
| 7886 | buf[0] = '\0'; |
| 7887 | pref = get_param(cmd, "Nebor_Pref"); |
| 7888 | if (pref) { |
| 7889 | /* hexdump for preferrence subelement */ |
| 7890 | ret = snprintf(buf, sizeof(buf), ",0301%02x", atoi(pref)); |
| 7891 | if (ret < 0 || ret >= (int) sizeof(buf)) { |
| 7892 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7893 | "snprintf failed for optional subelement ret: %d", |
| 7894 | ret); |
| 7895 | send_resp(dut, conn, SIGMA_ERROR, |
| 7896 | "errorCode,snprintf failed for subelement"); |
| 7897 | return 0; |
| 7898 | } |
| 7899 | } |
| 7900 | |
| 7901 | if (!dut->btm_query_cand_list) { |
| 7902 | dut->btm_query_cand_list = calloc(1, NEIGHBOR_REPORT_SIZE); |
| 7903 | if (!dut->btm_query_cand_list) { |
| 7904 | send_resp(dut, conn, SIGMA_ERROR, |
| 7905 | "errorCode,Failed to allocate memory for btm_query_cand_list"); |
| 7906 | return 0; |
| 7907 | } |
| 7908 | } |
| 7909 | |
| 7910 | len = strlen(dut->btm_query_cand_list); |
| 7911 | ret = snprintf(dut->btm_query_cand_list + len, |
| 7912 | NEIGHBOR_REPORT_SIZE - len, " neighbor=%s,%s,%s,%s,%s%s", |
| 7913 | bssid, info, op_class, ch, phy_type, buf); |
| 7914 | if (ret < 0 || ret >= NEIGHBOR_REPORT_SIZE - len) { |
| 7915 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7916 | "snprintf failed for neighbor report list ret: %d", |
| 7917 | ret); |
| 7918 | send_resp(dut, conn, SIGMA_ERROR, |
| 7919 | "errorCode,snprintf failed for neighbor report"); |
| 7920 | free(dut->btm_query_cand_list); |
| 7921 | dut->btm_query_cand_list = NULL; |
| 7922 | return 0; |
| 7923 | } |
| 7924 | |
| 7925 | return 1; |
| 7926 | } |
| 7927 | |
| 7928 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7929 | static int cmd_sta_set_rfeature(struct sigma_dut *dut, struct sigma_conn *conn, |
| 7930 | struct sigma_cmd *cmd) |
| 7931 | { |
| 7932 | const char *intf = get_param(cmd, "Interface"); |
| 7933 | const char *prog = get_param(cmd, "Prog"); |
Ashwini Patil | 68d02cd | 2017-01-10 15:39:16 +0530 | [diff] [blame] | 7934 | const char *val; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7935 | |
| 7936 | if (intf == NULL || prog == NULL) |
| 7937 | return -1; |
| 7938 | |
Ashwini Patil | 5acd738 | 2017-04-13 15:55:04 +0530 | [diff] [blame] | 7939 | /* BSS Transition candidate list for BTM query */ |
| 7940 | val = get_param(cmd, "Nebor_BSSID"); |
| 7941 | if (val && btm_query_candidate_list(dut, conn, cmd) == 0) |
| 7942 | return 0; |
| 7943 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7944 | if (strcasecmp(prog, "TDLS") == 0) |
| 7945 | return cmd_sta_set_rfeature_tdls(intf, dut, conn, cmd); |
| 7946 | |
| 7947 | if (strcasecmp(prog, "VHT") == 0) |
| 7948 | return cmd_sta_set_rfeature_vht(intf, dut, conn, cmd); |
| 7949 | |
Ashwini Patil | 68d02cd | 2017-01-10 15:39:16 +0530 | [diff] [blame] | 7950 | if (strcasecmp(prog, "MBO") == 0) { |
| 7951 | val = get_param(cmd, "Cellular_Data_Cap"); |
| 7952 | if (val && |
| 7953 | mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0) |
| 7954 | return 0; |
Ashwini Patil | 0040258 | 2017-04-13 12:29:39 +0530 | [diff] [blame] | 7955 | |
| 7956 | val = get_param(cmd, "Ch_Pref"); |
| 7957 | if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0) |
| 7958 | return 0; |
| 7959 | |
Ashwini Patil | 68d02cd | 2017-01-10 15:39:16 +0530 | [diff] [blame] | 7960 | return 1; |
| 7961 | } |
| 7962 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7963 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported Prog"); |
| 7964 | return 0; |
| 7965 | } |
| 7966 | |
| 7967 | |
| 7968 | static int cmd_sta_set_radio(struct sigma_dut *dut, struct sigma_conn *conn, |
| 7969 | struct sigma_cmd *cmd) |
| 7970 | { |
| 7971 | const char *intf = get_param(cmd, "Interface"); |
| 7972 | const char *mode = get_param(cmd, "Mode"); |
| 7973 | int res; |
| 7974 | |
| 7975 | if (intf == NULL || mode == NULL) |
| 7976 | return -1; |
| 7977 | |
| 7978 | if (strcasecmp(mode, "On") == 0) |
| 7979 | res = wpa_command(intf, "SET radio_disabled 0"); |
| 7980 | else if (strcasecmp(mode, "Off") == 0) |
| 7981 | res = wpa_command(intf, "SET radio_disabled 1"); |
| 7982 | else |
| 7983 | return -1; |
| 7984 | |
| 7985 | if (res) { |
| 7986 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change " |
| 7987 | "radio mode"); |
| 7988 | return 0; |
| 7989 | } |
| 7990 | |
| 7991 | return 1; |
| 7992 | } |
| 7993 | |
| 7994 | |
| 7995 | static int cmd_sta_set_pwrsave(struct sigma_dut *dut, struct sigma_conn *conn, |
| 7996 | struct sigma_cmd *cmd) |
| 7997 | { |
| 7998 | const char *intf = get_param(cmd, "Interface"); |
| 7999 | const char *mode = get_param(cmd, "Mode"); |
| 8000 | int res; |
| 8001 | |
| 8002 | if (intf == NULL || mode == NULL) |
| 8003 | return -1; |
| 8004 | |
| 8005 | if (strcasecmp(mode, "On") == 0) |
| 8006 | res = set_ps(intf, dut, 1); |
| 8007 | else if (strcasecmp(mode, "Off") == 0) |
| 8008 | res = set_ps(intf, dut, 0); |
| 8009 | else |
| 8010 | return -1; |
| 8011 | |
| 8012 | if (res) { |
| 8013 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change " |
| 8014 | "power save mode"); |
| 8015 | return 0; |
| 8016 | } |
| 8017 | |
| 8018 | return 1; |
| 8019 | } |
| 8020 | |
| 8021 | |
| 8022 | static int cmd_sta_bssid_pool(struct sigma_dut *dut, struct sigma_conn *conn, |
| 8023 | struct sigma_cmd *cmd) |
| 8024 | { |
| 8025 | const char *intf = get_param(cmd, "Interface"); |
| 8026 | const char *val, *bssid; |
| 8027 | int res; |
| 8028 | char *buf; |
| 8029 | size_t buf_len; |
| 8030 | |
| 8031 | val = get_param(cmd, "BSSID_FILTER"); |
| 8032 | if (val == NULL) |
| 8033 | return -1; |
| 8034 | |
| 8035 | bssid = get_param(cmd, "BSSID_List"); |
| 8036 | if (atoi(val) == 0 || bssid == NULL) { |
| 8037 | /* Disable BSSID filter */ |
| 8038 | if (wpa_command(intf, "SET bssid_filter ")) { |
| 8039 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed " |
| 8040 | "to disable BSSID filter"); |
| 8041 | return 0; |
| 8042 | } |
| 8043 | |
| 8044 | return 1; |
| 8045 | } |
| 8046 | |
| 8047 | buf_len = 100 + strlen(bssid); |
| 8048 | buf = malloc(buf_len); |
| 8049 | if (buf == NULL) |
| 8050 | return -1; |
| 8051 | |
| 8052 | snprintf(buf, buf_len, "SET bssid_filter %s", bssid); |
| 8053 | res = wpa_command(intf, buf); |
| 8054 | free(buf); |
| 8055 | if (res) { |
| 8056 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to enable " |
| 8057 | "BSSID filter"); |
| 8058 | return 0; |
| 8059 | } |
| 8060 | |
| 8061 | return 1; |
| 8062 | } |
| 8063 | |
| 8064 | |
| 8065 | static int cmd_sta_reset_parm(struct sigma_dut *dut, struct sigma_conn *conn, |
| 8066 | struct sigma_cmd *cmd) |
| 8067 | { |
| 8068 | const char *intf = get_param(cmd, "Interface"); |
| 8069 | const char *val; |
| 8070 | |
| 8071 | /* TODO: ARP */ |
| 8072 | |
| 8073 | val = get_param(cmd, "HS2_CACHE_PROFILE"); |
| 8074 | if (val && strcasecmp(val, "All") == 0) |
| 8075 | hs2_clear_credentials(intf); |
| 8076 | |
| 8077 | return 1; |
| 8078 | } |
| 8079 | |
| 8080 | |
| 8081 | static int cmd_sta_get_key(struct sigma_dut *dut, struct sigma_conn *conn, |
| 8082 | struct sigma_cmd *cmd) |
| 8083 | { |
| 8084 | const char *intf = get_param(cmd, "Interface"); |
| 8085 | const char *key_type = get_param(cmd, "KeyType"); |
| 8086 | char buf[100], resp[200]; |
| 8087 | |
| 8088 | if (key_type == NULL) |
| 8089 | return -1; |
| 8090 | |
| 8091 | if (strcasecmp(key_type, "GTK") == 0) { |
| 8092 | if (wpa_command_resp(intf, "GET gtk", buf, sizeof(buf)) < 0 || |
| 8093 | strncmp(buf, "FAIL", 4) == 0) { |
| 8094 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could " |
| 8095 | "not fetch current GTK"); |
| 8096 | return 0; |
| 8097 | } |
| 8098 | snprintf(resp, sizeof(resp), "KeyValue,%s", buf); |
| 8099 | send_resp(dut, conn, SIGMA_COMPLETE, resp); |
| 8100 | return 0; |
| 8101 | } else { |
| 8102 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported " |
| 8103 | "KeyType"); |
| 8104 | return 0; |
| 8105 | } |
| 8106 | |
| 8107 | return 1; |
| 8108 | } |
| 8109 | |
| 8110 | |
| 8111 | static int hs2_set_policy(struct sigma_dut *dut) |
| 8112 | { |
| 8113 | #ifdef ANDROID |
| 8114 | system("ip rule del prio 23000"); |
| 8115 | if (system("ip rule add from all lookup main prio 23000") != 0) { |
| 8116 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8117 | "Failed to run:ip rule add from all lookup main prio"); |
| 8118 | return -1; |
| 8119 | } |
| 8120 | if (system("ip route flush cache") != 0) { |
| 8121 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8122 | "Failed to run ip route flush cache"); |
| 8123 | return -1; |
| 8124 | } |
| 8125 | return 1; |
| 8126 | #else /* ANDROID */ |
| 8127 | return 0; |
| 8128 | #endif /* ANDROID */ |
| 8129 | } |
| 8130 | |
| 8131 | |
| 8132 | static int cmd_sta_hs2_associate(struct sigma_dut *dut, |
| 8133 | struct sigma_conn *conn, |
| 8134 | struct sigma_cmd *cmd) |
| 8135 | { |
| 8136 | const char *intf = get_param(cmd, "Interface"); |
| 8137 | const char *val = get_param(cmd, "Ignore_blacklist"); |
| 8138 | struct wpa_ctrl *ctrl; |
| 8139 | int res; |
| 8140 | char bssid[20], ssid[40], resp[100], buf[100], blacklisted[100]; |
| 8141 | int tries = 0; |
| 8142 | int ignore_blacklist = 0; |
| 8143 | const char *events[] = { |
| 8144 | "CTRL-EVENT-CONNECTED", |
| 8145 | "INTERWORKING-BLACKLISTED", |
| 8146 | "INTERWORKING-NO-MATCH", |
| 8147 | NULL |
| 8148 | }; |
| 8149 | |
| 8150 | start_sta_mode(dut); |
| 8151 | |
| 8152 | blacklisted[0] = '\0'; |
| 8153 | if (val && atoi(val)) |
| 8154 | ignore_blacklist = 1; |
| 8155 | |
| 8156 | try_again: |
| 8157 | ctrl = open_wpa_mon(intf); |
| 8158 | if (ctrl == NULL) { |
| 8159 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open " |
| 8160 | "wpa_supplicant monitor connection"); |
| 8161 | return -2; |
| 8162 | } |
| 8163 | |
| 8164 | tries++; |
| 8165 | if (wpa_command(intf, "INTERWORKING_SELECT auto")) { |
| 8166 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start " |
| 8167 | "Interworking connection"); |
| 8168 | wpa_ctrl_detach(ctrl); |
| 8169 | wpa_ctrl_close(ctrl); |
| 8170 | return 0; |
| 8171 | } |
| 8172 | |
| 8173 | buf[0] = '\0'; |
| 8174 | while (1) { |
| 8175 | char *pos; |
| 8176 | res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf)); |
| 8177 | pos = strstr(buf, "INTERWORKING-BLACKLISTED"); |
| 8178 | if (!pos) |
| 8179 | break; |
| 8180 | pos += 25; |
| 8181 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Found blacklisted AP: %s", |
| 8182 | pos); |
| 8183 | if (!blacklisted[0]) |
| 8184 | memcpy(blacklisted, pos, strlen(pos) + 1); |
| 8185 | } |
| 8186 | |
| 8187 | if (ignore_blacklist && blacklisted[0]) { |
| 8188 | char *end; |
| 8189 | end = strchr(blacklisted, ' '); |
| 8190 | if (end) |
| 8191 | *end = '\0'; |
| 8192 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Try to connect to a blacklisted network: %s", |
| 8193 | blacklisted); |
| 8194 | snprintf(buf, sizeof(buf), "INTERWORKING_CONNECT %s", |
| 8195 | blacklisted); |
| 8196 | if (wpa_command(intf, buf)) { |
| 8197 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start Interworking connection to blacklisted network"); |
| 8198 | wpa_ctrl_detach(ctrl); |
| 8199 | wpa_ctrl_close(ctrl); |
| 8200 | return 0; |
| 8201 | } |
| 8202 | res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED", |
| 8203 | buf, sizeof(buf)); |
| 8204 | } |
| 8205 | |
| 8206 | wpa_ctrl_detach(ctrl); |
| 8207 | wpa_ctrl_close(ctrl); |
| 8208 | |
| 8209 | if (res < 0) { |
| 8210 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not " |
| 8211 | "connect"); |
| 8212 | return 0; |
| 8213 | } |
| 8214 | |
| 8215 | if (strstr(buf, "INTERWORKING-NO-MATCH") || |
| 8216 | strstr(buf, "INTERWORKING-BLACKLISTED")) { |
| 8217 | if (tries < 2) { |
| 8218 | sigma_dut_print(dut, DUT_MSG_INFO, "No match found - try again to verify no APs were missed in the scan"); |
| 8219 | goto try_again; |
| 8220 | } |
| 8221 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,No network with " |
| 8222 | "matching credentials found"); |
| 8223 | return 0; |
| 8224 | } |
| 8225 | |
| 8226 | if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 || |
| 8227 | get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) { |
| 8228 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not " |
| 8229 | "get current BSSID/SSID"); |
| 8230 | return 0; |
| 8231 | } |
| 8232 | |
| 8233 | snprintf(resp, sizeof(resp), "SSID,%s,BSSID,%s", ssid, bssid); |
| 8234 | send_resp(dut, conn, SIGMA_COMPLETE, resp); |
| 8235 | hs2_set_policy(dut); |
| 8236 | return 0; |
| 8237 | } |
| 8238 | |
| 8239 | |
| 8240 | static int sta_add_credential_uname_pwd(struct sigma_dut *dut, |
| 8241 | struct sigma_conn *conn, |
| 8242 | const char *ifname, |
| 8243 | struct sigma_cmd *cmd) |
| 8244 | { |
| 8245 | const char *val; |
| 8246 | int id; |
| 8247 | |
| 8248 | id = add_cred(ifname); |
| 8249 | if (id < 0) |
| 8250 | return -2; |
| 8251 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id); |
| 8252 | |
| 8253 | val = get_param(cmd, "prefer"); |
| 8254 | if (val && atoi(val) > 0) |
| 8255 | set_cred(ifname, id, "priority", "1"); |
| 8256 | |
| 8257 | val = get_param(cmd, "REALM"); |
| 8258 | if (val && set_cred_quoted(ifname, id, "realm", val) < 0) { |
| 8259 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set " |
| 8260 | "realm"); |
| 8261 | return 0; |
| 8262 | } |
| 8263 | |
| 8264 | val = get_param(cmd, "HOME_FQDN"); |
| 8265 | if (val && set_cred_quoted(ifname, id, "domain", val) < 0) { |
| 8266 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set " |
| 8267 | "home_fqdn"); |
| 8268 | return 0; |
| 8269 | } |
| 8270 | |
| 8271 | val = get_param(cmd, "Username"); |
| 8272 | if (val && set_cred_quoted(ifname, id, "username", val) < 0) { |
| 8273 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set " |
| 8274 | "username"); |
| 8275 | return 0; |
| 8276 | } |
| 8277 | |
| 8278 | val = get_param(cmd, "Password"); |
| 8279 | if (val && set_cred_quoted(ifname, id, "password", val) < 0) { |
| 8280 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set " |
| 8281 | "password"); |
| 8282 | return 0; |
| 8283 | } |
| 8284 | |
| 8285 | val = get_param(cmd, "ROOT_CA"); |
| 8286 | if (val) { |
| 8287 | char fname[200]; |
| 8288 | snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val); |
| 8289 | #ifdef __linux__ |
| 8290 | if (!file_exists(fname)) { |
| 8291 | char msg[300]; |
| 8292 | snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA " |
| 8293 | "file (%s) not found", fname); |
| 8294 | send_resp(dut, conn, SIGMA_ERROR, msg); |
| 8295 | return 0; |
| 8296 | } |
| 8297 | #endif /* __linux__ */ |
| 8298 | if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) { |
| 8299 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could " |
| 8300 | "not set root CA"); |
| 8301 | return 0; |
| 8302 | } |
| 8303 | } |
| 8304 | |
| 8305 | return 1; |
| 8306 | } |
| 8307 | |
| 8308 | |
| 8309 | static int update_devdetail_imsi(struct sigma_dut *dut, const char *imsi) |
| 8310 | { |
| 8311 | FILE *in, *out; |
| 8312 | char buf[500]; |
| 8313 | int found = 0; |
| 8314 | |
| 8315 | in = fopen("devdetail.xml", "r"); |
| 8316 | if (in == NULL) |
| 8317 | return -1; |
| 8318 | out = fopen("devdetail.xml.tmp", "w"); |
| 8319 | if (out == NULL) { |
| 8320 | fclose(in); |
| 8321 | return -1; |
| 8322 | } |
| 8323 | |
| 8324 | while (fgets(buf, sizeof(buf), in)) { |
| 8325 | char *pos = strstr(buf, "<IMSI>"); |
| 8326 | if (pos) { |
| 8327 | sigma_dut_print(dut, DUT_MSG_INFO, "Updated DevDetail IMSI to %s", |
| 8328 | imsi); |
| 8329 | pos += 6; |
| 8330 | *pos = '\0'; |
| 8331 | fprintf(out, "%s%s</IMSI>\n", buf, imsi); |
| 8332 | found++; |
| 8333 | } else { |
| 8334 | fprintf(out, "%s", buf); |
| 8335 | } |
| 8336 | } |
| 8337 | |
| 8338 | fclose(out); |
| 8339 | fclose(in); |
| 8340 | if (found) |
| 8341 | rename("devdetail.xml.tmp", "devdetail.xml"); |
| 8342 | else |
| 8343 | unlink("devdetail.xml.tmp"); |
| 8344 | |
| 8345 | return 0; |
| 8346 | } |
| 8347 | |
| 8348 | |
| 8349 | static int sta_add_credential_sim(struct sigma_dut *dut, |
| 8350 | struct sigma_conn *conn, |
| 8351 | const char *ifname, struct sigma_cmd *cmd) |
| 8352 | { |
| 8353 | const char *val, *imsi = NULL; |
| 8354 | int id; |
| 8355 | char buf[200]; |
| 8356 | int res; |
| 8357 | const char *pos; |
| 8358 | size_t mnc_len; |
| 8359 | char plmn_mcc[4]; |
| 8360 | char plmn_mnc[4]; |
| 8361 | |
| 8362 | id = add_cred(ifname); |
| 8363 | if (id < 0) |
| 8364 | return -2; |
| 8365 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id); |
| 8366 | |
| 8367 | val = get_param(cmd, "prefer"); |
| 8368 | if (val && atoi(val) > 0) |
| 8369 | set_cred(ifname, id, "priority", "1"); |
| 8370 | |
| 8371 | val = get_param(cmd, "PLMN_MCC"); |
| 8372 | if (val == NULL) { |
| 8373 | send_resp(dut, conn, SIGMA_ERROR, |
| 8374 | "errorCode,Missing PLMN_MCC"); |
| 8375 | return 0; |
| 8376 | } |
| 8377 | if (strlen(val) != 3) { |
| 8378 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MCC"); |
| 8379 | return 0; |
| 8380 | } |
| 8381 | snprintf(plmn_mcc, sizeof(plmn_mcc), "%s", val); |
| 8382 | |
| 8383 | val = get_param(cmd, "PLMN_MNC"); |
| 8384 | if (val == NULL) { |
| 8385 | send_resp(dut, conn, SIGMA_ERROR, |
| 8386 | "errorCode,Missing PLMN_MNC"); |
| 8387 | return 0; |
| 8388 | } |
| 8389 | if (strlen(val) != 2 && strlen(val) != 3) { |
| 8390 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MNC"); |
| 8391 | return 0; |
| 8392 | } |
| 8393 | snprintf(plmn_mnc, sizeof(plmn_mnc), "%s", val); |
| 8394 | |
| 8395 | val = get_param(cmd, "IMSI"); |
| 8396 | if (val == NULL) { |
| 8397 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing SIM " |
| 8398 | "IMSI"); |
| 8399 | return 0; |
| 8400 | } |
| 8401 | |
| 8402 | imsi = pos = val; |
| 8403 | |
| 8404 | if (strncmp(plmn_mcc, pos, 3) != 0) { |
| 8405 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,MCC mismatch"); |
| 8406 | return 0; |
| 8407 | } |
| 8408 | pos += 3; |
| 8409 | |
| 8410 | mnc_len = strlen(plmn_mnc); |
| 8411 | if (mnc_len < 2) { |
| 8412 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC not set"); |
| 8413 | return 0; |
| 8414 | } |
| 8415 | |
| 8416 | if (strncmp(plmn_mnc, pos, mnc_len) != 0) { |
| 8417 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC mismatch"); |
| 8418 | return 0; |
| 8419 | } |
| 8420 | pos += mnc_len; |
| 8421 | |
| 8422 | res = snprintf(buf, sizeof(buf), "%s%s-%s",plmn_mcc, plmn_mnc, pos); |
| 8423 | if (res < 0 || res >= (int) sizeof(buf)) |
| 8424 | return -1; |
| 8425 | if (set_cred_quoted(ifname, id, "imsi", buf) < 0) { |
| 8426 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could " |
| 8427 | "not set IMSI"); |
| 8428 | return 0; |
| 8429 | } |
| 8430 | |
| 8431 | val = get_param(cmd, "Password"); |
| 8432 | if (val && set_cred_quoted(ifname, id, "milenage", val) < 0) { |
| 8433 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could " |
| 8434 | "not set password"); |
| 8435 | return 0; |
| 8436 | } |
| 8437 | |
| 8438 | if (dut->program == PROGRAM_HS2_R2) { |
| 8439 | /* |
| 8440 | * Set provisioning_sp for the test cases where SIM/USIM |
| 8441 | * provisioning is used. |
| 8442 | */ |
| 8443 | if (val && set_cred_quoted(ifname, id, "provisioning_sp", |
| 8444 | "wi-fi.org") < 0) { |
| 8445 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could " |
| 8446 | "not set provisioning_sp"); |
| 8447 | return 0; |
| 8448 | } |
| 8449 | |
| 8450 | update_devdetail_imsi(dut, imsi); |
| 8451 | } |
| 8452 | |
| 8453 | return 1; |
| 8454 | } |
| 8455 | |
| 8456 | |
| 8457 | static int sta_add_credential_cert(struct sigma_dut *dut, |
| 8458 | struct sigma_conn *conn, |
| 8459 | const char *ifname, |
| 8460 | struct sigma_cmd *cmd) |
| 8461 | { |
| 8462 | const char *val; |
| 8463 | int id; |
| 8464 | |
| 8465 | id = add_cred(ifname); |
| 8466 | if (id < 0) |
| 8467 | return -2; |
| 8468 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id); |
| 8469 | |
| 8470 | val = get_param(cmd, "prefer"); |
| 8471 | if (val && atoi(val) > 0) |
| 8472 | set_cred(ifname, id, "priority", "1"); |
| 8473 | |
| 8474 | val = get_param(cmd, "REALM"); |
| 8475 | if (val && set_cred_quoted(ifname, id, "realm", val) < 0) { |
| 8476 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set " |
| 8477 | "realm"); |
| 8478 | return 0; |
| 8479 | } |
| 8480 | |
| 8481 | val = get_param(cmd, "HOME_FQDN"); |
| 8482 | if (val && set_cred_quoted(ifname, id, "domain", val) < 0) { |
| 8483 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set " |
| 8484 | "home_fqdn"); |
| 8485 | return 0; |
| 8486 | } |
| 8487 | |
| 8488 | val = get_param(cmd, "Username"); |
| 8489 | if (val && set_cred_quoted(ifname, id, "username", val) < 0) { |
| 8490 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set " |
| 8491 | "username"); |
| 8492 | return 0; |
| 8493 | } |
| 8494 | |
| 8495 | val = get_param(cmd, "clientCertificate"); |
| 8496 | if (val) { |
| 8497 | char fname[200]; |
| 8498 | snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val); |
| 8499 | #ifdef __linux__ |
| 8500 | if (!file_exists(fname)) { |
| 8501 | char msg[300]; |
| 8502 | snprintf(msg, sizeof(msg), |
| 8503 | "ErrorCode,clientCertificate " |
| 8504 | "file (%s) not found", fname); |
| 8505 | send_resp(dut, conn, SIGMA_ERROR, msg); |
| 8506 | return 0; |
| 8507 | } |
| 8508 | #endif /* __linux__ */ |
| 8509 | if (set_cred_quoted(ifname, id, "client_cert", fname) < 0) { |
| 8510 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could " |
| 8511 | "not set client_cert"); |
| 8512 | return 0; |
| 8513 | } |
| 8514 | if (set_cred_quoted(ifname, id, "private_key", fname) < 0) { |
| 8515 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could " |
| 8516 | "not set private_key"); |
| 8517 | return 0; |
| 8518 | } |
| 8519 | } |
| 8520 | |
| 8521 | val = get_param(cmd, "ROOT_CA"); |
| 8522 | if (val) { |
| 8523 | char fname[200]; |
| 8524 | snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val); |
| 8525 | #ifdef __linux__ |
| 8526 | if (!file_exists(fname)) { |
| 8527 | char msg[300]; |
| 8528 | snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA " |
| 8529 | "file (%s) not found", fname); |
| 8530 | send_resp(dut, conn, SIGMA_ERROR, msg); |
| 8531 | return 0; |
| 8532 | } |
| 8533 | #endif /* __linux__ */ |
| 8534 | if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) { |
| 8535 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could " |
| 8536 | "not set root CA"); |
| 8537 | return 0; |
| 8538 | } |
| 8539 | } |
| 8540 | |
| 8541 | return 1; |
| 8542 | } |
| 8543 | |
| 8544 | |
| 8545 | static int cmd_sta_add_credential(struct sigma_dut *dut, |
| 8546 | struct sigma_conn *conn, |
| 8547 | struct sigma_cmd *cmd) |
| 8548 | { |
| 8549 | const char *intf = get_param(cmd, "Interface"); |
| 8550 | const char *type; |
| 8551 | |
| 8552 | start_sta_mode(dut); |
| 8553 | |
| 8554 | type = get_param(cmd, "Type"); |
| 8555 | if (!type) |
| 8556 | return -1; |
| 8557 | |
| 8558 | if (strcasecmp(type, "uname_pwd") == 0) |
| 8559 | return sta_add_credential_uname_pwd(dut, conn, intf, cmd); |
| 8560 | |
| 8561 | if (strcasecmp(type, "sim") == 0) |
| 8562 | return sta_add_credential_sim(dut, conn, intf, cmd); |
| 8563 | |
| 8564 | if (strcasecmp(type, "cert") == 0) |
| 8565 | return sta_add_credential_cert(dut, conn, intf, cmd); |
| 8566 | |
| 8567 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported credential " |
| 8568 | "type"); |
| 8569 | return 0; |
| 8570 | } |
| 8571 | |
| 8572 | |
| 8573 | static int cmd_sta_scan(struct sigma_dut *dut, struct sigma_conn *conn, |
| 8574 | struct sigma_cmd *cmd) |
| 8575 | { |
| 8576 | const char *intf = get_param(cmd, "Interface"); |
vamsi krishna | 89ad8c6 | 2017-09-19 12:51:18 +0530 | [diff] [blame] | 8577 | const char *val, *bssid, *ssid; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8578 | char buf[100]; |
vamsi krishna | 89ad8c6 | 2017-09-19 12:51:18 +0530 | [diff] [blame] | 8579 | char ssid_hex[65]; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8580 | int res; |
| 8581 | |
| 8582 | val = get_param(cmd, "HESSID"); |
| 8583 | if (val) { |
| 8584 | res = snprintf(buf, sizeof(buf), "SET hessid %s", val); |
| 8585 | if (res < 0 || res >= (int) sizeof(buf)) |
| 8586 | return -1; |
| 8587 | wpa_command(intf, buf); |
| 8588 | } |
| 8589 | |
| 8590 | val = get_param(cmd, "ACCS_NET_TYPE"); |
| 8591 | if (val) { |
| 8592 | res = snprintf(buf, sizeof(buf), "SET access_network_type %s", |
| 8593 | val); |
| 8594 | if (res < 0 || res >= (int) sizeof(buf)) |
| 8595 | return -1; |
| 8596 | wpa_command(intf, buf); |
| 8597 | } |
| 8598 | |
vamsi krishna | 89ad8c6 | 2017-09-19 12:51:18 +0530 | [diff] [blame] | 8599 | bssid = get_param(cmd, "Bssid"); |
| 8600 | ssid = get_param(cmd, "Ssid"); |
| 8601 | |
| 8602 | if (ssid) { |
| 8603 | if (2 * strlen(ssid) >= sizeof(ssid_hex)) { |
| 8604 | send_resp(dut, conn, SIGMA_ERROR, |
| 8605 | "ErrorCode,Too long SSID"); |
| 8606 | return 0; |
| 8607 | } |
| 8608 | ascii2hexstr(ssid, ssid_hex); |
| 8609 | } |
| 8610 | |
| 8611 | res = snprintf(buf, sizeof(buf), "SCAN%s%s%s%s", |
| 8612 | bssid ? " bssid=": "", |
| 8613 | bssid ? bssid : "", |
| 8614 | ssid ? " ssid " : "", |
| 8615 | ssid ? ssid_hex : ""); |
| 8616 | if (res < 0 || res >= (int) sizeof(buf)) |
| 8617 | return -1; |
| 8618 | |
| 8619 | if (wpa_command(intf, buf)) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8620 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not start " |
| 8621 | "scan"); |
| 8622 | return 0; |
| 8623 | } |
| 8624 | |
| 8625 | return 1; |
| 8626 | } |
| 8627 | |
| 8628 | |
| 8629 | static int cmd_sta_set_systime(struct sigma_dut *dut, struct sigma_conn *conn, |
| 8630 | struct sigma_cmd *cmd) |
| 8631 | { |
| 8632 | #ifdef __linux__ |
| 8633 | struct timeval tv; |
| 8634 | struct tm tm; |
| 8635 | time_t t; |
| 8636 | const char *val; |
Pradeep Reddy POTTETI | 429c69e | 2016-10-13 17:22:03 +0530 | [diff] [blame] | 8637 | int v; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8638 | |
| 8639 | wpa_command(get_station_ifname(), "PMKSA_FLUSH"); |
| 8640 | |
| 8641 | memset(&tm, 0, sizeof(tm)); |
| 8642 | val = get_param(cmd, "seconds"); |
| 8643 | if (val) |
| 8644 | tm.tm_sec = atoi(val); |
| 8645 | val = get_param(cmd, "minutes"); |
| 8646 | if (val) |
| 8647 | tm.tm_min = atoi(val); |
| 8648 | val = get_param(cmd, "hours"); |
| 8649 | if (val) |
| 8650 | tm.tm_hour = atoi(val); |
| 8651 | val = get_param(cmd, "date"); |
| 8652 | if (val) |
| 8653 | tm.tm_mday = atoi(val); |
| 8654 | val = get_param(cmd, "month"); |
Pradeep Reddy POTTETI | 429c69e | 2016-10-13 17:22:03 +0530 | [diff] [blame] | 8655 | if (val) { |
| 8656 | v = atoi(val); |
| 8657 | if (v < 1 || v > 12) { |
| 8658 | send_resp(dut, conn, SIGMA_INVALID, |
| 8659 | "errorCode,Invalid month"); |
| 8660 | return 0; |
| 8661 | } |
| 8662 | tm.tm_mon = v - 1; |
| 8663 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8664 | val = get_param(cmd, "year"); |
| 8665 | if (val) { |
| 8666 | int year = atoi(val); |
| 8667 | #ifdef ANDROID |
| 8668 | if (year > 2035) |
| 8669 | year = 2035; /* years beyond 2035 not supported */ |
| 8670 | #endif /* ANDROID */ |
| 8671 | tm.tm_year = year - 1900; |
| 8672 | } |
| 8673 | t = mktime(&tm); |
| 8674 | if (t == (time_t) -1) { |
| 8675 | send_resp(dut, conn, SIGMA_ERROR, |
| 8676 | "errorCode,Invalid date or time"); |
| 8677 | return 0; |
| 8678 | } |
| 8679 | |
| 8680 | memset(&tv, 0, sizeof(tv)); |
| 8681 | tv.tv_sec = t; |
| 8682 | |
| 8683 | if (settimeofday(&tv, NULL) < 0) { |
| 8684 | sigma_dut_print(dut, DUT_MSG_INFO, "settimeofday failed: %s", |
| 8685 | strerror(errno)); |
| 8686 | send_resp(dut, conn, SIGMA_ERROR, |
| 8687 | "errorCode,Failed to set time"); |
| 8688 | return 0; |
| 8689 | } |
| 8690 | |
| 8691 | return 1; |
| 8692 | #endif /* __linux__ */ |
| 8693 | |
| 8694 | return -1; |
| 8695 | } |
| 8696 | |
| 8697 | |
| 8698 | static int cmd_sta_osu(struct sigma_dut *dut, struct sigma_conn *conn, |
| 8699 | struct sigma_cmd *cmd) |
| 8700 | { |
| 8701 | const char *intf = get_param(cmd, "Interface"); |
| 8702 | const char *name, *val; |
| 8703 | int prod_ess_assoc = 1; |
| 8704 | char buf[200], bssid[100], ssid[100]; |
| 8705 | int res; |
| 8706 | struct wpa_ctrl *ctrl; |
| 8707 | |
| 8708 | name = get_param(cmd, "osuFriendlyName"); |
| 8709 | |
| 8710 | val = get_param(cmd, "ProdESSAssoc"); |
| 8711 | if (val) |
| 8712 | prod_ess_assoc = atoi(val); |
| 8713 | |
| 8714 | kill_dhcp_client(dut, intf); |
| 8715 | if (start_dhcp_client(dut, intf) < 0) |
| 8716 | return -2; |
| 8717 | |
| 8718 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger OSU"); |
| 8719 | mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); |
| 8720 | res = snprintf(buf, sizeof(buf), |
| 8721 | "%s %s%s%s signup osu-ca.pem", |
| 8722 | prod_ess_assoc ? "" : "-N", |
| 8723 | name ? "-O'" : "", name ? name : "", |
| 8724 | name ? "'" : ""); |
| 8725 | |
Kanchanapally, Vidyullatha | 12b6676 | 2015-12-31 16:46:42 +0530 | [diff] [blame] | 8726 | hs2_set_policy(dut); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8727 | if (run_hs20_osu(dut, buf) < 0) { |
| 8728 | FILE *f; |
| 8729 | |
| 8730 | sigma_dut_print(dut, DUT_MSG_INFO, "Failed to complete OSU"); |
| 8731 | |
| 8732 | f = fopen("hs20-osu-client.res", "r"); |
| 8733 | if (f) { |
| 8734 | char resp[400], res[300], *pos; |
| 8735 | if (!fgets(res, sizeof(res), f)) |
| 8736 | res[0] = '\0'; |
| 8737 | pos = strchr(res, '\n'); |
| 8738 | if (pos) |
| 8739 | *pos = '\0'; |
| 8740 | fclose(f); |
| 8741 | sigma_dut_summary(dut, "hs20-osu-client provisioning failed: %s", |
| 8742 | res); |
| 8743 | snprintf(resp, sizeof(resp), "notify-send '%s'", res); |
| 8744 | if (system(resp) != 0) { |
| 8745 | } |
| 8746 | snprintf(resp, sizeof(resp), |
| 8747 | "SSID,,BSSID,,failureReason,%s", res); |
| 8748 | send_resp(dut, conn, SIGMA_COMPLETE, resp); |
| 8749 | return 0; |
| 8750 | } |
| 8751 | |
| 8752 | send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,"); |
| 8753 | return 0; |
| 8754 | } |
| 8755 | |
| 8756 | if (!prod_ess_assoc) |
| 8757 | goto report; |
| 8758 | |
| 8759 | ctrl = open_wpa_mon(intf); |
| 8760 | if (ctrl == NULL) { |
| 8761 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open " |
| 8762 | "wpa_supplicant monitor connection"); |
| 8763 | return -1; |
| 8764 | } |
| 8765 | |
| 8766 | res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED", |
| 8767 | buf, sizeof(buf)); |
| 8768 | |
| 8769 | wpa_ctrl_detach(ctrl); |
| 8770 | wpa_ctrl_close(ctrl); |
| 8771 | |
| 8772 | if (res < 0) { |
| 8773 | sigma_dut_print(dut, DUT_MSG_INFO, "Failed to connect to " |
| 8774 | "network after OSU"); |
| 8775 | send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,"); |
| 8776 | return 0; |
| 8777 | } |
| 8778 | |
| 8779 | report: |
| 8780 | if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 || |
| 8781 | get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) { |
| 8782 | sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get BSSID/SSID"); |
| 8783 | send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,"); |
| 8784 | return 0; |
| 8785 | } |
| 8786 | |
| 8787 | snprintf(buf, sizeof(buf), "SSID,%s,BSSID,%s", ssid, bssid); |
| 8788 | send_resp(dut, conn, SIGMA_COMPLETE, buf); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8789 | return 0; |
| 8790 | } |
| 8791 | |
| 8792 | |
| 8793 | static int cmd_sta_policy_update(struct sigma_dut *dut, struct sigma_conn *conn, |
| 8794 | struct sigma_cmd *cmd) |
| 8795 | { |
| 8796 | const char *val; |
| 8797 | int timeout = 120; |
| 8798 | |
| 8799 | val = get_param(cmd, "PolicyUpdate"); |
| 8800 | if (val == NULL || atoi(val) == 0) |
| 8801 | return 1; /* No operation requested */ |
| 8802 | |
| 8803 | val = get_param(cmd, "Timeout"); |
| 8804 | if (val) |
| 8805 | timeout = atoi(val); |
| 8806 | |
| 8807 | if (timeout) { |
| 8808 | /* TODO: time out the command and return |
| 8809 | * PolicyUpdateStatus,TIMEOUT if needed. */ |
| 8810 | } |
| 8811 | |
| 8812 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger policy update"); |
| 8813 | mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); |
| 8814 | if (run_hs20_osu(dut, "pol_upd fqdn=wi-fi.org") < 0) { |
| 8815 | send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,FAIL"); |
| 8816 | return 0; |
| 8817 | } |
| 8818 | |
| 8819 | send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,SUCCESS"); |
| 8820 | return 0; |
| 8821 | } |
| 8822 | |
| 8823 | |
| 8824 | static int cmd_sta_er_config(struct sigma_dut *dut, struct sigma_conn *conn, |
| 8825 | struct sigma_cmd *cmd) |
| 8826 | { |
| 8827 | struct wpa_ctrl *ctrl; |
| 8828 | const char *intf = get_param(cmd, "Interface"); |
| 8829 | const char *bssid = get_param(cmd, "Bssid"); |
| 8830 | const char *ssid = get_param(cmd, "SSID"); |
| 8831 | const char *security = get_param(cmd, "Security"); |
| 8832 | const char *passphrase = get_param(cmd, "Passphrase"); |
| 8833 | const char *pin = get_param(cmd, "PIN"); |
| 8834 | char buf[1000]; |
| 8835 | char ssid_hex[200], passphrase_hex[200]; |
| 8836 | const char *keymgmt, *cipher; |
| 8837 | |
| 8838 | if (intf == NULL) |
| 8839 | intf = get_main_ifname(); |
| 8840 | |
| 8841 | if (!bssid) { |
| 8842 | send_resp(dut, conn, SIGMA_ERROR, |
| 8843 | "ErrorCode,Missing Bssid argument"); |
| 8844 | return 0; |
| 8845 | } |
| 8846 | |
| 8847 | if (!ssid) { |
| 8848 | send_resp(dut, conn, SIGMA_ERROR, |
| 8849 | "ErrorCode,Missing SSID argument"); |
| 8850 | return 0; |
| 8851 | } |
| 8852 | |
| 8853 | if (!security) { |
| 8854 | send_resp(dut, conn, SIGMA_ERROR, |
| 8855 | "ErrorCode,Missing Security argument"); |
| 8856 | return 0; |
| 8857 | } |
| 8858 | |
| 8859 | if (!passphrase) { |
| 8860 | send_resp(dut, conn, SIGMA_ERROR, |
| 8861 | "ErrorCode,Missing Passphrase argument"); |
| 8862 | return 0; |
| 8863 | } |
| 8864 | |
| 8865 | if (!pin) { |
| 8866 | send_resp(dut, conn, SIGMA_ERROR, |
| 8867 | "ErrorCode,Missing PIN argument"); |
| 8868 | return 0; |
| 8869 | } |
| 8870 | |
vamsi krishna | 8c9c156 | 2017-05-12 15:51:46 +0530 | [diff] [blame] | 8871 | if (2 * strlen(ssid) >= sizeof(ssid_hex) || |
| 8872 | 2 * strlen(passphrase) >= sizeof(passphrase_hex)) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8873 | send_resp(dut, conn, SIGMA_ERROR, |
| 8874 | "ErrorCode,Too long SSID/passphrase"); |
| 8875 | return 0; |
| 8876 | } |
| 8877 | |
| 8878 | ctrl = open_wpa_mon(intf); |
| 8879 | if (ctrl == NULL) { |
| 8880 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open " |
| 8881 | "wpa_supplicant monitor connection"); |
| 8882 | return -2; |
| 8883 | } |
| 8884 | |
| 8885 | if (strcasecmp(security, "wpa2-psk") == 0) { |
| 8886 | keymgmt = "WPA2PSK"; |
| 8887 | cipher = "CCMP"; |
| 8888 | } else { |
| 8889 | wpa_ctrl_detach(ctrl); |
| 8890 | wpa_ctrl_close(ctrl); |
| 8891 | send_resp(dut, conn, SIGMA_ERROR, |
| 8892 | "ErrorCode,Unsupported Security value"); |
| 8893 | return 0; |
| 8894 | } |
| 8895 | |
| 8896 | ascii2hexstr(ssid, ssid_hex); |
| 8897 | ascii2hexstr(passphrase, passphrase_hex); |
| 8898 | snprintf(buf, sizeof(buf), "WPS_REG %s %s %s %s %s %s", |
| 8899 | bssid, pin, ssid_hex, keymgmt, cipher, passphrase_hex); |
| 8900 | |
| 8901 | if (wpa_command(intf, buf) < 0) { |
| 8902 | wpa_ctrl_detach(ctrl); |
| 8903 | wpa_ctrl_close(ctrl); |
| 8904 | send_resp(dut, conn, SIGMA_ERROR, |
| 8905 | "ErrorCode,Failed to start registrar"); |
| 8906 | return 0; |
| 8907 | } |
| 8908 | |
| 8909 | snprintf(dut->er_oper_bssid, sizeof(dut->er_oper_bssid), "%s", bssid); |
| 8910 | dut->er_oper_performed = 1; |
| 8911 | |
| 8912 | return wps_connection_event(dut, conn, ctrl, intf, 0); |
| 8913 | } |
| 8914 | |
| 8915 | |
| 8916 | static int cmd_sta_wps_connect_pw_token(struct sigma_dut *dut, |
| 8917 | struct sigma_conn *conn, |
| 8918 | struct sigma_cmd *cmd) |
| 8919 | { |
| 8920 | struct wpa_ctrl *ctrl; |
| 8921 | const char *intf = get_param(cmd, "Interface"); |
| 8922 | const char *bssid = get_param(cmd, "Bssid"); |
| 8923 | char buf[100]; |
| 8924 | |
| 8925 | if (!bssid) { |
| 8926 | send_resp(dut, conn, SIGMA_ERROR, |
| 8927 | "ErrorCode,Missing Bssid argument"); |
| 8928 | return 0; |
| 8929 | } |
| 8930 | |
| 8931 | ctrl = open_wpa_mon(intf); |
| 8932 | if (ctrl == NULL) { |
| 8933 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open " |
| 8934 | "wpa_supplicant monitor connection"); |
| 8935 | return -2; |
| 8936 | } |
| 8937 | |
| 8938 | snprintf(buf, sizeof(buf), "WPS_NFC %s", bssid); |
| 8939 | |
| 8940 | if (wpa_command(intf, buf) < 0) { |
| 8941 | wpa_ctrl_detach(ctrl); |
| 8942 | wpa_ctrl_close(ctrl); |
| 8943 | send_resp(dut, conn, SIGMA_ERROR, |
| 8944 | "ErrorCode,Failed to start registrar"); |
| 8945 | return 0; |
| 8946 | } |
| 8947 | |
| 8948 | return wps_connection_event(dut, conn, ctrl, intf, 0); |
| 8949 | } |
| 8950 | |
| 8951 | |
vamsi krishna | 9b14400 | 2017-09-20 13:28:13 +0530 | [diff] [blame] | 8952 | static int cmd_start_wps_registration(struct sigma_dut *dut, |
| 8953 | struct sigma_conn *conn, |
| 8954 | struct sigma_cmd *cmd) |
| 8955 | { |
| 8956 | struct wpa_ctrl *ctrl; |
| 8957 | const char *intf = get_param(cmd, "Interface"); |
| 8958 | const char *role, *method; |
| 8959 | int res; |
| 8960 | char buf[256]; |
| 8961 | const char *events[] = { |
| 8962 | "CTRL-EVENT-CONNECTED", |
| 8963 | "WPS-OVERLAP-DETECTED", |
| 8964 | "WPS-TIMEOUT", |
| 8965 | "WPS-FAIL", |
| 8966 | NULL |
| 8967 | }; |
| 8968 | |
| 8969 | ctrl = open_wpa_mon(intf); |
| 8970 | if (!ctrl) { |
| 8971 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8972 | "Failed to open wpa_supplicant monitor connection"); |
| 8973 | return -2; |
| 8974 | } |
| 8975 | |
| 8976 | role = get_param(cmd, "WpsRole"); |
| 8977 | if (!role) { |
| 8978 | send_resp(dut, conn, SIGMA_INVALID, |
| 8979 | "ErrorCode,WpsRole not provided"); |
| 8980 | goto fail; |
| 8981 | } |
| 8982 | |
| 8983 | if (strcasecmp(role, "Enrollee") == 0) { |
| 8984 | method = get_param(cmd, "WpsConfigMethod"); |
| 8985 | if (!method) { |
| 8986 | send_resp(dut, conn, SIGMA_INVALID, |
| 8987 | "ErrorCode,WpsConfigMethod not provided"); |
| 8988 | goto fail; |
| 8989 | } |
| 8990 | if (strcasecmp(method, "PBC") == 0) { |
| 8991 | if (wpa_command(intf, "WPS_PBC") < 0) { |
| 8992 | send_resp(dut, conn, SIGMA_ERROR, |
| 8993 | "ErrorCode,Failed to enable PBC"); |
| 8994 | goto fail; |
| 8995 | } |
| 8996 | } else { |
| 8997 | /* TODO: PIN method */ |
| 8998 | send_resp(dut, conn, SIGMA_ERROR, |
| 8999 | "ErrorCode,Unsupported WpsConfigMethod value"); |
| 9000 | goto fail; |
| 9001 | } |
| 9002 | res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf)); |
| 9003 | if (res < 0) { |
| 9004 | send_resp(dut, conn, SIGMA_ERROR, |
| 9005 | "ErrorCode,WPS connection did not complete"); |
| 9006 | goto fail; |
| 9007 | } |
| 9008 | if (strstr(buf, "WPS-TIMEOUT")) { |
| 9009 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,NoPeer"); |
| 9010 | } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) { |
| 9011 | send_resp(dut, conn, SIGMA_ERROR, |
| 9012 | "ErrorCode,OverlapSession"); |
| 9013 | } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) { |
| 9014 | send_resp(dut, conn, SIGMA_COMPLETE, "Successful"); |
| 9015 | } else { |
| 9016 | send_resp(dut, conn, SIGMA_ERROR, |
| 9017 | "ErrorCode,WPS operation failed"); |
| 9018 | } |
| 9019 | } else { |
| 9020 | /* TODO: Registrar role */ |
| 9021 | send_resp(dut, conn, SIGMA_ERROR, |
| 9022 | "ErrorCode,Unsupported WpsRole value"); |
| 9023 | } |
| 9024 | |
| 9025 | fail: |
| 9026 | wpa_ctrl_detach(ctrl); |
| 9027 | wpa_ctrl_close(ctrl); |
| 9028 | return 0; |
| 9029 | } |
| 9030 | |
| 9031 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 9032 | static int req_intf(struct sigma_cmd *cmd) |
| 9033 | { |
| 9034 | return get_param(cmd, "interface") == NULL ? -1 : 0; |
| 9035 | } |
| 9036 | |
| 9037 | |
| 9038 | void sta_register_cmds(void) |
| 9039 | { |
| 9040 | sigma_dut_reg_cmd("sta_get_ip_config", req_intf, |
| 9041 | cmd_sta_get_ip_config); |
| 9042 | sigma_dut_reg_cmd("sta_set_ip_config", req_intf, |
| 9043 | cmd_sta_set_ip_config); |
| 9044 | sigma_dut_reg_cmd("sta_get_info", req_intf, cmd_sta_get_info); |
| 9045 | sigma_dut_reg_cmd("sta_get_mac_address", req_intf, |
| 9046 | cmd_sta_get_mac_address); |
| 9047 | sigma_dut_reg_cmd("sta_is_connected", req_intf, cmd_sta_is_connected); |
| 9048 | sigma_dut_reg_cmd("sta_verify_ip_connection", req_intf, |
| 9049 | cmd_sta_verify_ip_connection); |
| 9050 | sigma_dut_reg_cmd("sta_get_bssid", req_intf, cmd_sta_get_bssid); |
| 9051 | sigma_dut_reg_cmd("sta_set_encryption", req_intf, |
| 9052 | cmd_sta_set_encryption); |
| 9053 | sigma_dut_reg_cmd("sta_set_psk", req_intf, cmd_sta_set_psk); |
| 9054 | sigma_dut_reg_cmd("sta_set_eaptls", req_intf, cmd_sta_set_eaptls); |
| 9055 | sigma_dut_reg_cmd("sta_set_eapttls", req_intf, cmd_sta_set_eapttls); |
| 9056 | sigma_dut_reg_cmd("sta_set_eapsim", req_intf, cmd_sta_set_eapsim); |
| 9057 | sigma_dut_reg_cmd("sta_set_peap", req_intf, cmd_sta_set_peap); |
| 9058 | sigma_dut_reg_cmd("sta_set_eapfast", req_intf, cmd_sta_set_eapfast); |
| 9059 | sigma_dut_reg_cmd("sta_set_eapaka", req_intf, cmd_sta_set_eapaka); |
| 9060 | sigma_dut_reg_cmd("sta_set_eapakaprime", req_intf, |
| 9061 | cmd_sta_set_eapakaprime); |
| 9062 | sigma_dut_reg_cmd("sta_set_security", req_intf, cmd_sta_set_security); |
| 9063 | sigma_dut_reg_cmd("sta_set_uapsd", req_intf, cmd_sta_set_uapsd); |
| 9064 | /* TODO: sta_set_ibss */ |
| 9065 | /* TODO: sta_set_mode */ |
| 9066 | sigma_dut_reg_cmd("sta_set_wmm", req_intf, cmd_sta_set_wmm); |
| 9067 | sigma_dut_reg_cmd("sta_associate", req_intf, cmd_sta_associate); |
| 9068 | /* TODO: sta_up_load */ |
| 9069 | sigma_dut_reg_cmd("sta_preset_testparameters", req_intf, |
| 9070 | cmd_sta_preset_testparameters); |
| 9071 | /* TODO: sta_set_system */ |
| 9072 | sigma_dut_reg_cmd("sta_set_11n", req_intf, cmd_sta_set_11n); |
| 9073 | /* TODO: sta_set_rifs_test */ |
| 9074 | sigma_dut_reg_cmd("sta_set_wireless", req_intf, cmd_sta_set_wireless); |
| 9075 | sigma_dut_reg_cmd("sta_send_addba", req_intf, cmd_sta_send_addba); |
| 9076 | /* TODO: sta_send_coexist_mgmt */ |
| 9077 | sigma_dut_reg_cmd("sta_disconnect", req_intf, cmd_sta_disconnect); |
| 9078 | sigma_dut_reg_cmd("sta_reassoc", req_intf, cmd_sta_reassoc); |
| 9079 | sigma_dut_reg_cmd("sta_reassociate", req_intf, cmd_sta_reassoc); |
| 9080 | sigma_dut_reg_cmd("sta_reset_default", req_intf, |
| 9081 | cmd_sta_reset_default); |
| 9082 | sigma_dut_reg_cmd("sta_send_frame", req_intf, cmd_sta_send_frame); |
| 9083 | sigma_dut_reg_cmd("sta_set_macaddr", req_intf, cmd_sta_set_macaddr); |
| 9084 | sigma_dut_reg_cmd("sta_set_rfeature", req_intf, cmd_sta_set_rfeature); |
| 9085 | sigma_dut_reg_cmd("sta_set_radio", req_intf, cmd_sta_set_radio); |
| 9086 | sigma_dut_reg_cmd("sta_set_pwrsave", req_intf, cmd_sta_set_pwrsave); |
| 9087 | sigma_dut_reg_cmd("sta_bssid_pool", req_intf, cmd_sta_bssid_pool); |
| 9088 | sigma_dut_reg_cmd("sta_reset_parm", req_intf, cmd_sta_reset_parm); |
| 9089 | sigma_dut_reg_cmd("sta_get_key", req_intf, cmd_sta_get_key); |
| 9090 | sigma_dut_reg_cmd("sta_hs2_associate", req_intf, |
| 9091 | cmd_sta_hs2_associate); |
| 9092 | sigma_dut_reg_cmd("sta_add_credential", req_intf, |
| 9093 | cmd_sta_add_credential); |
| 9094 | sigma_dut_reg_cmd("sta_scan", req_intf, cmd_sta_scan); |
| 9095 | sigma_dut_reg_cmd("sta_set_systime", NULL, cmd_sta_set_systime); |
| 9096 | sigma_dut_reg_cmd("sta_osu", req_intf, cmd_sta_osu); |
| 9097 | sigma_dut_reg_cmd("sta_policy_update", req_intf, cmd_sta_policy_update); |
| 9098 | sigma_dut_reg_cmd("sta_er_config", NULL, cmd_sta_er_config); |
| 9099 | sigma_dut_reg_cmd("sta_wps_connect_pw_token", req_intf, |
| 9100 | cmd_sta_wps_connect_pw_token); |
| 9101 | sigma_dut_reg_cmd("sta_exec_action", req_intf, cmd_sta_exec_action); |
| 9102 | sigma_dut_reg_cmd("sta_get_events", req_intf, cmd_sta_get_events); |
| 9103 | sigma_dut_reg_cmd("sta_get_parameter", req_intf, cmd_sta_get_parameter); |
vamsi krishna | 9b14400 | 2017-09-20 13:28:13 +0530 | [diff] [blame] | 9104 | sigma_dut_reg_cmd("start_wps_registration", req_intf, |
| 9105 | cmd_start_wps_registration); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 9106 | } |