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. |
Jouni Malinen | 9d7e31d | 2017-12-22 18:55:04 +0200 | [diff] [blame] | 4 | * Copyright (c) 2011-2017, Qualcomm Atheros, Inc. |
Jouni Malinen | c12ea4a | 2018-01-05 21:07:10 +0200 | [diff] [blame] | 5 | * Copyright (c) 2018, The Linux Foundation |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6 | * All Rights Reserved. |
| 7 | * Licensed under the Clear BSD license. See README for more details. |
| 8 | */ |
| 9 | |
| 10 | #include "sigma_dut.h" |
| 11 | #include <sys/ioctl.h> |
| 12 | #include <sys/stat.h> |
| 13 | #ifdef __linux__ |
Lior David | cc88b56 | 2017-01-03 18:52:09 +0200 | [diff] [blame] | 14 | #include <regex.h> |
| 15 | #include <dirent.h> |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 16 | #include <sys/time.h> |
| 17 | #include <netpacket/packet.h> |
| 18 | #include <linux/if_ether.h> |
| 19 | #ifdef ANDROID |
| 20 | #include <cutils/properties.h> |
| 21 | #include <android/log.h> |
| 22 | #include "keystore_get.h" |
| 23 | #else /* ANDROID */ |
| 24 | #include <ifaddrs.h> |
| 25 | #endif /* ANDROID */ |
| 26 | #include <netdb.h> |
| 27 | #endif /* __linux__ */ |
| 28 | #ifdef __QNXNTO__ |
| 29 | #include <net/if_dl.h> |
| 30 | #endif /* __QNXNTO__ */ |
| 31 | #include "wpa_ctrl.h" |
| 32 | #include "wpa_helpers.h" |
Amarnath Hullur Subramanyam | 9c381f5 | 2017-03-17 00:04:41 -0700 | [diff] [blame] | 33 | #include "miracast.h" |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 34 | |
| 35 | /* Temporary files for sta_send_addba */ |
| 36 | #define VI_QOS_TMP_FILE "/tmp/vi-qos.tmp" |
| 37 | #define VI_QOS_FILE "/tmp/vi-qos.txt" |
| 38 | #define VI_QOS_REFFILE "/etc/vi-qos.txt" |
| 39 | |
| 40 | /* |
| 41 | * MTU for Ethernet need to take into account 8-byte SNAP header |
| 42 | * to be added when encapsulating Ethernet frame into 802.11 |
| 43 | */ |
| 44 | #ifndef IEEE80211_MAX_DATA_LEN_DMG |
| 45 | #define IEEE80211_MAX_DATA_LEN_DMG 7920 |
| 46 | #endif |
| 47 | #ifndef IEEE80211_SNAP_LEN_DMG |
| 48 | #define IEEE80211_SNAP_LEN_DMG 8 |
| 49 | #endif |
| 50 | |
Ashwini Patil | 0040258 | 2017-04-13 12:29:39 +0530 | [diff] [blame] | 51 | #define NON_PREF_CH_LIST_SIZE 100 |
Ashwini Patil | 5acd738 | 2017-04-13 15:55:04 +0530 | [diff] [blame] | 52 | #define NEIGHBOR_REPORT_SIZE 1000 |
| 53 | #define DEFAULT_NEIGHBOR_BSSID_INFO "17" |
| 54 | #define DEFAULT_NEIGHBOR_PHY_TYPE "1" |
Ashwini Patil | 0040258 | 2017-04-13 12:29:39 +0530 | [diff] [blame] | 55 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 56 | extern char *sigma_wpas_ctrl; |
| 57 | extern char *sigma_cert_path; |
| 58 | extern enum driver_type wifi_chip_type; |
| 59 | extern char *sigma_radio_ifname[]; |
| 60 | |
Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 61 | #ifdef __linux__ |
| 62 | #define WIL_WMI_MAX_PAYLOAD 248 |
| 63 | #define WIL_WMI_BF_TRIG_CMDID 0x83a |
| 64 | |
| 65 | struct wil_wmi_header { |
| 66 | uint8_t mid; |
| 67 | uint8_t reserved; |
| 68 | uint16_t cmd; |
| 69 | uint32_t ts; |
| 70 | } __attribute__((packed)); |
| 71 | |
| 72 | enum wil_wmi_bf_trig_type { |
| 73 | WIL_WMI_SLS, |
| 74 | WIL_WMI_BRP_RX, |
| 75 | WIL_WMI_BRP_TX, |
| 76 | }; |
| 77 | |
| 78 | struct wil_wmi_bf_trig_cmd { |
| 79 | /* enum wil_wmi_bf_trig_type */ |
| 80 | uint32_t bf_type; |
| 81 | /* cid when type == WMI_BRP_RX */ |
| 82 | uint32_t sta_id; |
| 83 | uint32_t reserved; |
| 84 | /* mac address when type = WIL_WMI_SLS */ |
| 85 | uint8_t dest_mac[6]; |
| 86 | } __attribute__((packed)); |
| 87 | #endif /* __linux__ */ |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 88 | |
| 89 | #ifdef ANDROID |
| 90 | |
| 91 | static int add_ipv6_rule(struct sigma_dut *dut, const char *ifname); |
| 92 | |
| 93 | #define ANDROID_KEYSTORE_GET 'g' |
| 94 | #define ANDROID_KEYSTORE_GET_PUBKEY 'b' |
| 95 | |
| 96 | static int android_keystore_get(char cmd, const char *key, unsigned char *val) |
| 97 | { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 98 | /* Android 4.3 changed keystore design, so need to use keystore_get() */ |
| 99 | #ifndef KEYSTORE_MESSAGE_SIZE |
| 100 | #define KEYSTORE_MESSAGE_SIZE 65535 |
| 101 | #endif /* KEYSTORE_MESSAGE_SIZE */ |
| 102 | |
| 103 | ssize_t len; |
| 104 | uint8_t *value = NULL; |
| 105 | |
| 106 | __android_log_print(ANDROID_LOG_DEBUG, "sigma_dut", |
| 107 | "keystore command '%c' key '%s' --> keystore_get", |
| 108 | cmd, key); |
| 109 | |
| 110 | len = keystore_get(key, strlen(key), &value); |
| 111 | if (len < 0) { |
| 112 | __android_log_print(ANDROID_LOG_DEBUG, "sigma_dut", |
| 113 | "keystore_get() failed"); |
| 114 | return -1; |
| 115 | } |
| 116 | |
| 117 | if (len > KEYSTORE_MESSAGE_SIZE) |
| 118 | len = KEYSTORE_MESSAGE_SIZE; |
| 119 | memcpy(val, value, len); |
| 120 | free(value); |
| 121 | return len; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 122 | } |
| 123 | #endif /* ANDROID */ |
| 124 | |
| 125 | |
| 126 | int set_ps(const char *intf, struct sigma_dut *dut, int enabled) |
| 127 | { |
| 128 | #ifdef __linux__ |
| 129 | char buf[100]; |
| 130 | |
| 131 | if (wifi_chip_type == DRIVER_WCN) { |
| 132 | if (enabled) { |
| 133 | snprintf(buf, sizeof(buf), "iwpriv wlan0 dump 906"); |
Pradeep Reddy POTTETI | 625b370 | 2016-09-20 17:09:58 +0530 | [diff] [blame] | 134 | if (system(buf) != 0) |
| 135 | goto set_power_save; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 136 | } else { |
| 137 | snprintf(buf, sizeof(buf), "iwpriv wlan0 dump 905"); |
Pradeep Reddy POTTETI | 625b370 | 2016-09-20 17:09:58 +0530 | [diff] [blame] | 138 | if (system(buf) != 0) |
| 139 | goto set_power_save; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 140 | snprintf(buf, sizeof(buf), "iwpriv wlan0 dump 912"); |
Pradeep Reddy POTTETI | 625b370 | 2016-09-20 17:09:58 +0530 | [diff] [blame] | 141 | if (system(buf) != 0) |
| 142 | goto set_power_save; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | return 0; |
| 146 | } |
| 147 | |
Pradeep Reddy POTTETI | 625b370 | 2016-09-20 17:09:58 +0530 | [diff] [blame] | 148 | set_power_save: |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 149 | snprintf(buf, sizeof(buf), "./iw dev %s set power_save %s", |
| 150 | intf, enabled ? "on" : "off"); |
| 151 | if (system(buf) != 0) { |
| 152 | snprintf(buf, sizeof(buf), "iw dev %s set power_save %s", |
| 153 | intf, enabled ? "on" : "off"); |
Pradeep Reddy POTTETI | 625b370 | 2016-09-20 17:09:58 +0530 | [diff] [blame] | 154 | if (system(buf) != 0) { |
| 155 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 156 | "Failed to set power save %s", |
| 157 | enabled ? "on" : "off"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 158 | return -1; |
Pradeep Reddy POTTETI | 625b370 | 2016-09-20 17:09:58 +0530 | [diff] [blame] | 159 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | return 0; |
| 163 | #else /* __linux__ */ |
| 164 | return -1; |
| 165 | #endif /* __linux__ */ |
| 166 | } |
| 167 | |
| 168 | |
Lior David | cc88b56 | 2017-01-03 18:52:09 +0200 | [diff] [blame] | 169 | #ifdef __linux__ |
Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 170 | |
Lior David | cc88b56 | 2017-01-03 18:52:09 +0200 | [diff] [blame] | 171 | static int wil6210_get_debugfs_dir(struct sigma_dut *dut, char *path, |
| 172 | size_t len) |
| 173 | { |
| 174 | DIR *dir, *wil_dir; |
| 175 | struct dirent *entry; |
| 176 | int ret = -1; |
| 177 | const char *root_path = "/sys/kernel/debug/ieee80211"; |
| 178 | |
| 179 | dir = opendir(root_path); |
| 180 | if (!dir) |
| 181 | return -2; |
| 182 | |
| 183 | while ((entry = readdir(dir))) { |
| 184 | if (strcmp(entry->d_name, ".") == 0 || |
| 185 | strcmp(entry->d_name, "..") == 0) |
| 186 | continue; |
| 187 | |
| 188 | if (snprintf(path, len, "%s/%s/wil6210", |
| 189 | root_path, entry->d_name) >= (int) len) { |
| 190 | ret = -3; |
| 191 | break; |
| 192 | } |
| 193 | |
| 194 | wil_dir = opendir(path); |
| 195 | if (wil_dir) { |
| 196 | closedir(wil_dir); |
| 197 | ret = 0; |
| 198 | break; |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | closedir(dir); |
| 203 | return ret; |
| 204 | } |
Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 205 | |
| 206 | |
| 207 | static int wil6210_wmi_send(struct sigma_dut *dut, uint16_t command, |
| 208 | void *payload, uint16_t length) |
| 209 | { |
| 210 | struct { |
| 211 | struct wil_wmi_header hdr; |
| 212 | char payload[WIL_WMI_MAX_PAYLOAD]; |
| 213 | } __attribute__((packed)) cmd; |
| 214 | char buf[128], fname[128]; |
| 215 | size_t towrite, written; |
| 216 | FILE *f; |
| 217 | |
| 218 | if (length > WIL_WMI_MAX_PAYLOAD) { |
| 219 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 220 | "payload too large(%u, max %u)", |
| 221 | length, WIL_WMI_MAX_PAYLOAD); |
| 222 | return -1; |
| 223 | } |
| 224 | |
| 225 | memset(&cmd.hdr, 0, sizeof(cmd.hdr)); |
| 226 | cmd.hdr.cmd = command; |
| 227 | memcpy(cmd.payload, payload, length); |
| 228 | |
| 229 | if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) { |
| 230 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 231 | "failed to get wil6210 debugfs dir"); |
| 232 | return -1; |
| 233 | } |
| 234 | |
| 235 | snprintf(fname, sizeof(fname), "%s/wmi_send", buf); |
| 236 | f = fopen(fname, "wb"); |
| 237 | if (!f) { |
| 238 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 239 | "failed to open: %s", fname); |
| 240 | return -1; |
| 241 | } |
| 242 | |
| 243 | towrite = sizeof(cmd.hdr) + length; |
| 244 | written = fwrite(&cmd, 1, towrite, f); |
| 245 | fclose(f); |
| 246 | if (written != towrite) { |
| 247 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 248 | "failed to send wmi %u", command); |
| 249 | return -1; |
| 250 | } |
| 251 | |
| 252 | return 0; |
| 253 | } |
| 254 | |
| 255 | |
| 256 | static int wil6210_get_sta_info_field(struct sigma_dut *dut, const char *bssid, |
| 257 | const char *pattern, unsigned int *field) |
| 258 | { |
| 259 | char buf[128], fname[128]; |
| 260 | FILE *f; |
| 261 | regex_t re; |
| 262 | regmatch_t m[2]; |
| 263 | int rc, ret = -1; |
| 264 | |
| 265 | if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) { |
| 266 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 267 | "failed to get wil6210 debugfs dir"); |
| 268 | return -1; |
| 269 | } |
| 270 | |
| 271 | snprintf(fname, sizeof(fname), "%s/stations", buf); |
| 272 | f = fopen(fname, "r"); |
| 273 | if (!f) { |
| 274 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 275 | "failed to open: %s", fname); |
| 276 | return -1; |
| 277 | } |
| 278 | |
| 279 | if (regcomp(&re, pattern, REG_EXTENDED)) { |
| 280 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 281 | "regcomp failed: %s", pattern); |
| 282 | goto out; |
| 283 | } |
| 284 | |
| 285 | /* |
| 286 | * find the entry for the mac address |
| 287 | * line is of the form: [n] 11:22:33:44:55:66 state AID aid |
| 288 | */ |
| 289 | while (fgets(buf, sizeof(buf), f)) { |
| 290 | if (strcasestr(buf, bssid)) { |
| 291 | /* extract the field (CID/AID/state) */ |
| 292 | rc = regexec(&re, buf, 2, m, 0); |
| 293 | if (!rc && (m[1].rm_so >= 0)) { |
| 294 | buf[m[1].rm_eo] = 0; |
| 295 | *field = atoi(&buf[m[1].rm_so]); |
| 296 | ret = 0; |
| 297 | break; |
| 298 | } |
| 299 | } |
| 300 | } |
| 301 | |
| 302 | regfree(&re); |
| 303 | if (ret) |
| 304 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 305 | "could not extract field"); |
| 306 | |
| 307 | out: |
| 308 | fclose(f); |
| 309 | |
| 310 | return ret; |
| 311 | } |
| 312 | |
| 313 | |
| 314 | static int wil6210_get_cid(struct sigma_dut *dut, const char *bssid, |
| 315 | unsigned int *cid) |
| 316 | { |
| 317 | const char *pattern = "\\[([0-9]+)\\]"; |
| 318 | |
| 319 | return wil6210_get_sta_info_field(dut, bssid, pattern, cid); |
| 320 | } |
| 321 | |
| 322 | |
| 323 | static int wil6210_send_brp_rx(struct sigma_dut *dut, const char *mac, |
| 324 | int l_rx) |
| 325 | { |
Rakesh Sunki | 556237d | 2017-03-30 14:49:31 -0700 | [diff] [blame] | 326 | struct wil_wmi_bf_trig_cmd cmd; |
Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 327 | unsigned int cid; |
| 328 | |
Rakesh Sunki | 556237d | 2017-03-30 14:49:31 -0700 | [diff] [blame] | 329 | memset(&cmd, 0, sizeof(cmd)); |
| 330 | |
Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 331 | if (wil6210_get_cid(dut, mac, &cid)) |
| 332 | return -1; |
| 333 | |
| 334 | cmd.bf_type = WIL_WMI_BRP_RX; |
| 335 | cmd.sta_id = cid; |
| 336 | /* training length (l_rx) is ignored, FW always uses length 16 */ |
| 337 | return wil6210_wmi_send(dut, WIL_WMI_BF_TRIG_CMDID, |
| 338 | &cmd, sizeof(cmd)); |
| 339 | } |
| 340 | |
| 341 | |
| 342 | static int wil6210_send_sls(struct sigma_dut *dut, const char *mac) |
| 343 | { |
Rakesh Sunki | 556237d | 2017-03-30 14:49:31 -0700 | [diff] [blame] | 344 | struct wil_wmi_bf_trig_cmd cmd; |
| 345 | |
| 346 | memset(&cmd, 0, sizeof(cmd)); |
Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 347 | |
| 348 | if (parse_mac_address(dut, mac, (unsigned char *)&cmd.dest_mac)) |
| 349 | return -1; |
| 350 | |
| 351 | cmd.bf_type = WIL_WMI_SLS; |
| 352 | return wil6210_wmi_send(dut, WIL_WMI_BF_TRIG_CMDID, |
| 353 | &cmd, sizeof(cmd)); |
| 354 | } |
| 355 | |
Lior David | cc88b56 | 2017-01-03 18:52:09 +0200 | [diff] [blame] | 356 | #endif /* __linux__ */ |
| 357 | |
| 358 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 359 | static void static_ip_file(int proto, const char *addr, const char *mask, |
| 360 | const char *gw) |
| 361 | { |
| 362 | if (proto) { |
| 363 | FILE *f = fopen("static-ip", "w"); |
| 364 | if (f) { |
| 365 | fprintf(f, "%d %s %s %s\n", proto, addr, |
| 366 | mask ? mask : "N/A", |
| 367 | gw ? gw : "N/A"); |
| 368 | fclose(f); |
| 369 | } |
| 370 | } else { |
| 371 | unlink("static-ip"); |
| 372 | } |
| 373 | } |
| 374 | |
| 375 | |
| 376 | static int send_neighbor_request(struct sigma_dut *dut, const char *intf, |
| 377 | const char *ssid) |
| 378 | { |
| 379 | #ifdef __linux__ |
| 380 | char buf[100]; |
| 381 | |
| 382 | snprintf(buf, sizeof(buf), "iwpriv %s neighbor %s", |
| 383 | intf, ssid); |
| 384 | sigma_dut_print(dut, DUT_MSG_INFO, "Request: %s", buf); |
| 385 | |
| 386 | if (system(buf) != 0) { |
| 387 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 388 | "iwpriv neighbor request failed"); |
| 389 | return -1; |
| 390 | } |
| 391 | |
| 392 | sigma_dut_print(dut, DUT_MSG_INFO, "iwpriv neighbor request send"); |
| 393 | |
| 394 | return 0; |
| 395 | #else /* __linux__ */ |
| 396 | return -1; |
| 397 | #endif /* __linux__ */ |
| 398 | } |
| 399 | |
| 400 | |
| 401 | 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] | 402 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 403 | { |
Ashwini Patil | 5acd738 | 2017-04-13 15:55:04 +0530 | [diff] [blame] | 404 | const char *val; |
| 405 | int reason_code = 0; |
| 406 | char buf[1024]; |
| 407 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 408 | /* |
| 409 | * In the earlier builds we used WNM_QUERY and in later |
| 410 | * builds used WNM_BSS_QUERY. |
| 411 | */ |
| 412 | |
Ashwini Patil | 5acd738 | 2017-04-13 15:55:04 +0530 | [diff] [blame] | 413 | val = get_param(cmd, "BTMQuery_Reason_Code"); |
| 414 | if (val) |
| 415 | reason_code = atoi(val); |
| 416 | |
| 417 | val = get_param(cmd, "Cand_List"); |
| 418 | if (val && atoi(val) == 1 && dut->btm_query_cand_list) { |
| 419 | snprintf(buf, sizeof(buf), "WNM_BSS_QUERY %d%s", reason_code, |
| 420 | dut->btm_query_cand_list); |
| 421 | free(dut->btm_query_cand_list); |
| 422 | dut->btm_query_cand_list = NULL; |
| 423 | } else { |
| 424 | snprintf(buf, sizeof(buf), "WNM_BSS_QUERY %d", reason_code); |
| 425 | } |
| 426 | |
| 427 | if (wpa_command(intf, buf) != 0) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 428 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 429 | "transition management query failed"); |
| 430 | return -1; |
| 431 | } |
| 432 | |
| 433 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 434 | "transition management query sent"); |
| 435 | |
| 436 | return 0; |
| 437 | } |
| 438 | |
| 439 | |
| 440 | int is_ip_addr(const char *str) |
| 441 | { |
| 442 | const char *pos = str; |
| 443 | struct in_addr addr; |
| 444 | |
| 445 | while (*pos) { |
| 446 | if (*pos != '.' && (*pos < '0' || *pos > '9')) |
| 447 | return 0; |
| 448 | pos++; |
| 449 | } |
| 450 | |
| 451 | return inet_aton(str, &addr); |
| 452 | } |
| 453 | |
| 454 | |
| 455 | int is_ipv6_addr(const char *str) |
| 456 | { |
| 457 | struct sockaddr_in6 addr; |
| 458 | |
| 459 | return inet_pton(AF_INET6, str, &(addr.sin6_addr)); |
| 460 | } |
| 461 | |
| 462 | |
| 463 | int get_ip_config(struct sigma_dut *dut, const char *ifname, char *buf, |
| 464 | size_t buf_len) |
| 465 | { |
| 466 | char tmp[256], *pos, *pos2; |
| 467 | FILE *f; |
| 468 | char ip[16], mask[15], dns[16], sec_dns[16]; |
Sarvepalli, Rajesh Babu | a76c644 | 2016-03-18 20:34:26 +0530 | [diff] [blame] | 469 | const char *str_ps; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 470 | int is_dhcp = 0; |
| 471 | int s; |
| 472 | #ifdef ANDROID |
| 473 | char prop[PROPERTY_VALUE_MAX]; |
| 474 | #endif /* ANDROID */ |
| 475 | |
| 476 | ip[0] = '\0'; |
| 477 | mask[0] = '\0'; |
| 478 | dns[0] = '\0'; |
| 479 | sec_dns[0] = '\0'; |
| 480 | |
| 481 | s = socket(PF_INET, SOCK_DGRAM, 0); |
| 482 | if (s >= 0) { |
| 483 | struct ifreq ifr; |
| 484 | struct sockaddr_in saddr; |
| 485 | |
| 486 | memset(&ifr, 0, sizeof(ifr)); |
Peng Xu | b8fc5cc | 2017-05-10 17:27:28 -0700 | [diff] [blame] | 487 | strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 488 | if (ioctl(s, SIOCGIFADDR, &ifr) < 0) { |
| 489 | sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get " |
| 490 | "%s IP address: %s", |
| 491 | ifname, strerror(errno)); |
| 492 | } else { |
| 493 | memcpy(&saddr, &ifr.ifr_addr, |
| 494 | sizeof(struct sockaddr_in)); |
Peng Xu | b8fc5cc | 2017-05-10 17:27:28 -0700 | [diff] [blame] | 495 | strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip)); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | if (ioctl(s, SIOCGIFNETMASK, &ifr) == 0) { |
| 499 | memcpy(&saddr, &ifr.ifr_addr, |
| 500 | sizeof(struct sockaddr_in)); |
Peng Xu | b8fc5cc | 2017-05-10 17:27:28 -0700 | [diff] [blame] | 501 | strlcpy(mask, inet_ntoa(saddr.sin_addr), sizeof(mask)); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 502 | } |
| 503 | close(s); |
| 504 | } |
| 505 | |
| 506 | #ifdef ANDROID |
| 507 | snprintf(tmp, sizeof(tmp), "dhcp.%s.pid", ifname); |
| 508 | if (property_get(tmp, prop, NULL) != 0 && atoi(prop) > 0) { |
| 509 | snprintf(tmp, sizeof(tmp), "dhcp.%s.result", ifname); |
| 510 | if (property_get(tmp, prop, NULL) != 0 && |
| 511 | strcmp(prop, "ok") == 0) { |
| 512 | snprintf(tmp, sizeof(tmp), "dhcp.%s.ipaddress", |
| 513 | ifname); |
| 514 | if (property_get(tmp, prop, NULL) != 0 && |
| 515 | strcmp(ip, prop) == 0) |
| 516 | is_dhcp = 1; |
| 517 | } |
| 518 | } |
| 519 | |
| 520 | snprintf(tmp, sizeof(tmp), "dhcp.%s.dns1", ifname); |
Peng Xu | b8fc5cc | 2017-05-10 17:27:28 -0700 | [diff] [blame] | 521 | if (property_get(tmp, prop, NULL) != 0) |
| 522 | strlcpy(dns, prop, sizeof(dns)); |
| 523 | else if (property_get("net.dns1", prop, NULL) != 0) |
| 524 | strlcpy(dns, prop, sizeof(dns)); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 525 | |
| 526 | snprintf(tmp, sizeof(tmp), "dhcp.%s.dns2", ifname); |
Peng Xu | b8fc5cc | 2017-05-10 17:27:28 -0700 | [diff] [blame] | 527 | if (property_get(tmp, prop, NULL) != 0) |
| 528 | strlcpy(sec_dns, prop, sizeof(sec_dns)); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 529 | #else /* ANDROID */ |
| 530 | #ifdef __linux__ |
Sarvepalli, Rajesh Babu | a76c644 | 2016-03-18 20:34:26 +0530 | [diff] [blame] | 531 | if (get_driver_type() == DRIVER_OPENWRT) |
| 532 | str_ps = "ps -w"; |
| 533 | else |
| 534 | str_ps = "ps ax"; |
| 535 | snprintf(tmp, sizeof(tmp), |
| 536 | "%s | grep dhclient | grep -v grep | grep -q %s", |
| 537 | str_ps, ifname); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 538 | if (system(tmp) == 0) |
| 539 | is_dhcp = 1; |
| 540 | else { |
Sarvepalli, Rajesh Babu | a76c644 | 2016-03-18 20:34:26 +0530 | [diff] [blame] | 541 | snprintf(tmp, sizeof(tmp), |
| 542 | "%s | grep udhcpc | grep -v grep | grep -q %s", |
| 543 | str_ps, ifname); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 544 | if (system(tmp) == 0) |
| 545 | is_dhcp = 1; |
| 546 | else { |
Sarvepalli, Rajesh Babu | a76c644 | 2016-03-18 20:34:26 +0530 | [diff] [blame] | 547 | snprintf(tmp, sizeof(tmp), |
| 548 | "%s | grep dhcpcd | grep -v grep | grep -q %s", |
| 549 | str_ps, ifname); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 550 | if (system(tmp) == 0) |
| 551 | is_dhcp = 1; |
| 552 | } |
| 553 | } |
| 554 | #endif /* __linux__ */ |
| 555 | |
| 556 | f = fopen("/etc/resolv.conf", "r"); |
| 557 | if (f) { |
| 558 | while (fgets(tmp, sizeof(tmp), f)) { |
| 559 | if (strncmp(tmp, "nameserver", 10) != 0) |
| 560 | continue; |
| 561 | pos = tmp + 10; |
| 562 | while (*pos == ' ' || *pos == '\t') |
| 563 | pos++; |
| 564 | pos2 = pos; |
| 565 | while (*pos2) { |
| 566 | if (*pos2 == '\n' || *pos2 == '\r') { |
| 567 | *pos2 = '\0'; |
| 568 | break; |
| 569 | } |
| 570 | pos2++; |
| 571 | } |
Peng Xu | b8fc5cc | 2017-05-10 17:27:28 -0700 | [diff] [blame] | 572 | if (!dns[0]) |
| 573 | strlcpy(dns, pos, sizeof(dns)); |
| 574 | else if (!sec_dns[0]) |
| 575 | strlcpy(sec_dns, pos, sizeof(sec_dns)); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 576 | } |
| 577 | fclose(f); |
| 578 | } |
| 579 | #endif /* ANDROID */ |
| 580 | |
| 581 | snprintf(buf, buf_len, "dhcp,%d,ip,%s,mask,%s,primary-dns,%s", |
| 582 | is_dhcp, ip, mask, dns); |
| 583 | buf[buf_len - 1] = '\0'; |
| 584 | |
| 585 | return 0; |
| 586 | } |
| 587 | |
| 588 | |
| 589 | |
| 590 | |
| 591 | int get_ipv6_config(struct sigma_dut *dut, const char *ifname, char *buf, |
| 592 | size_t buf_len) |
| 593 | { |
| 594 | #ifdef __linux__ |
| 595 | #ifdef ANDROID |
| 596 | char cmd[200], result[1000], *pos, *end; |
| 597 | FILE *f; |
| 598 | size_t len; |
| 599 | |
| 600 | snprintf(cmd, sizeof(cmd), "ip addr show dev %s scope global", ifname); |
| 601 | f = popen(cmd, "r"); |
| 602 | if (f == NULL) |
| 603 | return -1; |
| 604 | len = fread(result, 1, sizeof(result) - 1, f); |
| 605 | pclose(f); |
| 606 | if (len == 0) |
| 607 | return -1; |
| 608 | result[len] = '\0'; |
| 609 | sigma_dut_print(dut, DUT_MSG_DEBUG, "%s result: %s\n", cmd, result); |
| 610 | |
| 611 | pos = strstr(result, "inet6 "); |
| 612 | if (pos == NULL) |
| 613 | return -1; |
| 614 | pos += 6; |
| 615 | end = strchr(pos, ' '); |
| 616 | if (end) |
| 617 | *end = '\0'; |
| 618 | end = strchr(pos, '/'); |
| 619 | if (end) |
| 620 | *end = '\0'; |
| 621 | snprintf(buf, buf_len, "ip,%s", pos); |
| 622 | buf[buf_len - 1] = '\0'; |
| 623 | return 0; |
| 624 | #else /* ANDROID */ |
| 625 | struct ifaddrs *ifaddr, *ifa; |
| 626 | int res, found = 0; |
| 627 | char host[NI_MAXHOST]; |
| 628 | |
| 629 | if (getifaddrs(&ifaddr) < 0) { |
| 630 | perror("getifaddrs"); |
| 631 | return -1; |
| 632 | } |
| 633 | |
| 634 | for (ifa = ifaddr; ifa; ifa = ifa->ifa_next) { |
| 635 | if (strcasecmp(ifname, ifa->ifa_name) != 0) |
| 636 | continue; |
| 637 | if (ifa->ifa_addr == NULL || |
| 638 | ifa->ifa_addr->sa_family != AF_INET6) |
| 639 | continue; |
| 640 | |
| 641 | res = getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in6), |
| 642 | host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST); |
| 643 | if (res != 0) { |
| 644 | sigma_dut_print(dut, DUT_MSG_DEBUG, "getnameinfo: %s", |
| 645 | gai_strerror(res)); |
| 646 | continue; |
| 647 | } |
| 648 | if (strncmp(host, "fe80::", 6) == 0) |
| 649 | continue; /* skip link-local */ |
| 650 | |
| 651 | sigma_dut_print(dut, DUT_MSG_DEBUG, "ifaddr: %s", host); |
| 652 | found = 1; |
| 653 | break; |
| 654 | } |
| 655 | |
| 656 | freeifaddrs(ifaddr); |
| 657 | |
| 658 | if (found) { |
| 659 | char *pos; |
| 660 | pos = strchr(host, '%'); |
| 661 | if (pos) |
| 662 | *pos = '\0'; |
| 663 | snprintf(buf, buf_len, "ip,%s", host); |
| 664 | buf[buf_len - 1] = '\0'; |
| 665 | return 0; |
| 666 | } |
| 667 | |
| 668 | #endif /* ANDROID */ |
| 669 | #endif /* __linux__ */ |
| 670 | return -1; |
| 671 | } |
| 672 | |
| 673 | |
| 674 | static int cmd_sta_get_ip_config(struct sigma_dut *dut, |
| 675 | struct sigma_conn *conn, |
| 676 | struct sigma_cmd *cmd) |
| 677 | { |
| 678 | const char *intf = get_param(cmd, "Interface"); |
| 679 | const char *ifname; |
| 680 | char buf[200]; |
| 681 | const char *val; |
| 682 | int type = 1; |
| 683 | |
| 684 | if (intf == NULL) |
| 685 | return -1; |
| 686 | |
| 687 | if (strcmp(intf, get_main_ifname()) == 0) |
| 688 | ifname = get_station_ifname(); |
| 689 | else |
| 690 | ifname = intf; |
| 691 | |
| 692 | /* |
| 693 | * UCC may assume the IP address to be available immediately after |
| 694 | * association without trying to run sta_get_ip_config multiple times. |
| 695 | * Sigma CAPI does not specify this command as a block command that |
| 696 | * would wait for the address to become available, but to pass tests |
| 697 | * more reliably, it looks like such a wait may be needed here. |
| 698 | */ |
| 699 | if (wait_ip_addr(dut, ifname, 15) < 0) { |
| 700 | sigma_dut_print(dut, DUT_MSG_INFO, "Could not get IP address " |
| 701 | "for sta_get_ip_config"); |
| 702 | /* |
| 703 | * Try to continue anyway since many UCC tests do not really |
| 704 | * care about the return value from here.. |
| 705 | */ |
| 706 | } |
| 707 | |
| 708 | val = get_param(cmd, "Type"); |
| 709 | if (val) |
| 710 | type = atoi(val); |
| 711 | if (type == 2 || dut->last_set_ip_config_ipv6) { |
| 712 | int i; |
| 713 | |
| 714 | /* |
| 715 | * Since we do not have proper wait for IPv6 addresses, use a |
| 716 | * fixed two second delay here as a workaround for UCC script |
| 717 | * assuming IPv6 address is available when this command returns. |
| 718 | * Some scripts did not use Type,2 properly for IPv6, so include |
| 719 | * also the cases where the previous sta_set_ip_config indicated |
| 720 | * use of IPv6. |
| 721 | */ |
| 722 | sigma_dut_print(dut, DUT_MSG_INFO, "Wait up to extra ten seconds in sta_get_ip_config for IPv6 address"); |
| 723 | for (i = 0; i < 10; i++) { |
| 724 | sleep(1); |
| 725 | if (get_ipv6_config(dut, ifname, buf, sizeof(buf)) == 0) |
| 726 | { |
| 727 | sigma_dut_print(dut, DUT_MSG_INFO, "Found IPv6 address"); |
| 728 | send_resp(dut, conn, SIGMA_COMPLETE, buf); |
| 729 | #ifdef ANDROID |
| 730 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 731 | "Adding IPv6 rule on Android"); |
| 732 | add_ipv6_rule(dut, intf); |
| 733 | #endif /* ANDROID */ |
| 734 | |
| 735 | return 0; |
| 736 | } |
| 737 | } |
| 738 | } |
| 739 | if (type == 1) { |
| 740 | if (get_ip_config(dut, ifname, buf, sizeof(buf)) < 0) |
| 741 | return -2; |
| 742 | } else if (type == 2) { |
| 743 | if (get_ipv6_config(dut, ifname, buf, sizeof(buf)) < 0) |
| 744 | return -2; |
| 745 | } else { |
| 746 | send_resp(dut, conn, SIGMA_ERROR, |
| 747 | "errorCode,Unsupported address type"); |
| 748 | return 0; |
| 749 | } |
| 750 | |
| 751 | send_resp(dut, conn, SIGMA_COMPLETE, buf); |
| 752 | return 0; |
| 753 | } |
| 754 | |
| 755 | |
| 756 | static void kill_dhcp_client(struct sigma_dut *dut, const char *ifname) |
| 757 | { |
| 758 | #ifdef __linux__ |
| 759 | char buf[200]; |
| 760 | char path[128]; |
| 761 | struct stat s; |
| 762 | |
| 763 | #ifdef ANDROID |
| 764 | snprintf(path, sizeof(path), "/data/misc/dhcp/dhcpcd-%s.pid", ifname); |
| 765 | #else /* ANDROID */ |
| 766 | snprintf(path, sizeof(path), "/var/run/dhclient-%s.pid", ifname); |
| 767 | #endif /* ANDROID */ |
| 768 | if (stat(path, &s) == 0) { |
| 769 | snprintf(buf, sizeof(buf), "kill `cat %s`", path); |
| 770 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 771 | "Kill previous DHCP client: %s", buf); |
| 772 | if (system(buf) != 0) |
| 773 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 774 | "Failed to kill DHCP client"); |
| 775 | unlink(path); |
| 776 | sleep(1); |
| 777 | } else { |
| 778 | snprintf(path, sizeof(path), "/var/run/dhcpcd-%s.pid", ifname); |
| 779 | |
| 780 | if (stat(path, &s) == 0) { |
| 781 | snprintf(buf, sizeof(buf), "kill `cat %s`", path); |
| 782 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 783 | "Kill previous DHCP client: %s", buf); |
| 784 | if (system(buf) != 0) |
| 785 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 786 | "Failed to kill DHCP client"); |
| 787 | unlink(path); |
| 788 | sleep(1); |
| 789 | } |
| 790 | } |
| 791 | #endif /* __linux__ */ |
| 792 | } |
| 793 | |
| 794 | |
| 795 | static int start_dhcp_client(struct sigma_dut *dut, const char *ifname) |
| 796 | { |
| 797 | #ifdef __linux__ |
| 798 | char buf[200]; |
| 799 | |
| 800 | #ifdef ANDROID |
Purushottam Kushwaha | 46d6426 | 2016-08-23 17:57:53 +0530 | [diff] [blame] | 801 | if (access("/system/bin/dhcpcd", F_OK) != -1) { |
| 802 | snprintf(buf, sizeof(buf), |
| 803 | "/system/bin/dhcpcd -b %s", ifname); |
| 804 | } else if (access("/system/bin/dhcptool", F_OK) != -1) { |
| 805 | snprintf(buf, sizeof(buf), "/system/bin/dhcptool %s &", ifname); |
| 806 | } else { |
| 807 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 808 | "DHCP client program missing"); |
| 809 | return 0; |
| 810 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 811 | #else /* ANDROID */ |
| 812 | snprintf(buf, sizeof(buf), |
| 813 | "dhclient -nw -pf /var/run/dhclient-%s.pid %s", |
| 814 | ifname, ifname); |
| 815 | #endif /* ANDROID */ |
| 816 | sigma_dut_print(dut, DUT_MSG_INFO, "Start DHCP client: %s", buf); |
| 817 | if (system(buf) != 0) { |
| 818 | snprintf(buf, sizeof(buf), "dhcpcd -t 0 %s &", ifname); |
| 819 | if (system(buf) != 0) { |
| 820 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 821 | "Failed to start DHCP client"); |
| 822 | #ifndef ANDROID |
| 823 | return -1; |
| 824 | #endif /* ANDROID */ |
| 825 | } |
| 826 | } |
| 827 | #endif /* __linux__ */ |
| 828 | |
| 829 | return 0; |
| 830 | } |
| 831 | |
| 832 | |
| 833 | static int clear_ip_addr(struct sigma_dut *dut, const char *ifname) |
| 834 | { |
| 835 | #ifdef __linux__ |
| 836 | char buf[200]; |
| 837 | |
| 838 | snprintf(buf, sizeof(buf), "ip addr flush dev %s", ifname); |
| 839 | if (system(buf) != 0) { |
| 840 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 841 | "Failed to clear IP addresses"); |
| 842 | return -1; |
| 843 | } |
| 844 | #endif /* __linux__ */ |
| 845 | |
| 846 | return 0; |
| 847 | } |
| 848 | |
| 849 | |
| 850 | #ifdef ANDROID |
| 851 | static int add_ipv6_rule(struct sigma_dut *dut, const char *ifname) |
| 852 | { |
| 853 | char cmd[200], *result, *pos; |
| 854 | FILE *fp; |
Pradeep Reddy POTTETI | f58a1fe | 2016-10-13 17:22:03 +0530 | [diff] [blame] | 855 | int tableid; |
| 856 | size_t len, result_len = 1000; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 857 | |
| 858 | snprintf(cmd, sizeof(cmd), "ip -6 route list table all | grep %s", |
| 859 | ifname); |
| 860 | fp = popen(cmd, "r"); |
| 861 | if (fp == NULL) |
| 862 | return -1; |
| 863 | |
| 864 | result = malloc(result_len); |
Pradeep Reddy POTTETI | 673d85c | 2016-07-26 19:08:07 +0530 | [diff] [blame] | 865 | if (result == NULL) { |
| 866 | fclose(fp); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 867 | return -1; |
Pradeep Reddy POTTETI | 673d85c | 2016-07-26 19:08:07 +0530 | [diff] [blame] | 868 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 869 | |
Pradeep Reddy POTTETI | f58a1fe | 2016-10-13 17:22:03 +0530 | [diff] [blame] | 870 | len = fread(result, 1, result_len - 1, fp); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 871 | fclose(fp); |
| 872 | |
| 873 | if (len == 0) { |
| 874 | free(result); |
| 875 | return -1; |
| 876 | } |
Pradeep Reddy POTTETI | f58a1fe | 2016-10-13 17:22:03 +0530 | [diff] [blame] | 877 | result[len] = '\0'; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 878 | |
| 879 | pos = strstr(result, "table "); |
| 880 | if (pos == NULL) { |
| 881 | free(result); |
| 882 | return -1; |
| 883 | } |
| 884 | |
| 885 | pos += strlen("table "); |
| 886 | tableid = atoi(pos); |
| 887 | if (tableid != 0) { |
| 888 | if (system("ip -6 rule del prio 22000") != 0) { |
| 889 | /* ignore any error */ |
| 890 | } |
| 891 | snprintf(cmd, sizeof(cmd), |
| 892 | "ip -6 rule add from all lookup %d prio 22000", |
| 893 | tableid); |
| 894 | if (system(cmd) != 0) { |
| 895 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 896 | "Failed to run %s", cmd); |
| 897 | free(result); |
| 898 | return -1; |
| 899 | } |
| 900 | } else { |
| 901 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 902 | "No Valid Table Id found %s", pos); |
| 903 | free(result); |
| 904 | return -1; |
| 905 | } |
| 906 | free(result); |
| 907 | |
| 908 | return 0; |
| 909 | } |
| 910 | #endif /* ANDROID */ |
| 911 | |
| 912 | |
| 913 | static int cmd_sta_set_ip_config(struct sigma_dut *dut, |
| 914 | struct sigma_conn *conn, |
| 915 | struct sigma_cmd *cmd) |
| 916 | { |
| 917 | const char *intf = get_param(cmd, "Interface"); |
| 918 | const char *ifname; |
| 919 | char buf[200]; |
| 920 | const char *val, *ip, *mask, *gw; |
| 921 | int type = 1; |
| 922 | |
| 923 | if (intf == NULL) |
| 924 | return -1; |
| 925 | |
| 926 | if (strcmp(intf, get_main_ifname()) == 0) |
| 927 | ifname = get_station_ifname(); |
| 928 | else |
| 929 | ifname = intf; |
| 930 | |
| 931 | if (if_nametoindex(ifname) == 0) { |
| 932 | send_resp(dut, conn, SIGMA_ERROR, |
| 933 | "ErrorCode,Unknown interface"); |
| 934 | return 0; |
| 935 | } |
| 936 | |
| 937 | val = get_param(cmd, "Type"); |
| 938 | if (val) { |
| 939 | type = atoi(val); |
| 940 | if (type != 1 && type != 2) { |
| 941 | send_resp(dut, conn, SIGMA_ERROR, |
| 942 | "ErrorCode,Unsupported address type"); |
| 943 | return 0; |
| 944 | } |
| 945 | } |
| 946 | |
| 947 | dut->last_set_ip_config_ipv6 = 0; |
| 948 | |
| 949 | val = get_param(cmd, "dhcp"); |
| 950 | if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "true") == 0)) { |
| 951 | static_ip_file(0, NULL, NULL, NULL); |
| 952 | #ifdef __linux__ |
| 953 | if (type == 2) { |
| 954 | dut->last_set_ip_config_ipv6 = 1; |
| 955 | sigma_dut_print(dut, DUT_MSG_INFO, "Using IPv6 " |
| 956 | "stateless address autoconfiguration"); |
| 957 | #ifdef ANDROID |
| 958 | /* |
| 959 | * This sleep is required as the assignment in case of |
| 960 | * Android is taking time and is done by the kernel. |
| 961 | * The subsequent ping for IPv6 is impacting HS20 test |
| 962 | * case. |
| 963 | */ |
| 964 | sleep(2); |
| 965 | add_ipv6_rule(dut, intf); |
| 966 | #endif /* ANDROID */ |
| 967 | /* Assume this happens by default */ |
| 968 | return 1; |
| 969 | } |
| 970 | |
| 971 | kill_dhcp_client(dut, ifname); |
| 972 | if (start_dhcp_client(dut, ifname) < 0) |
| 973 | return -2; |
| 974 | return 1; |
| 975 | #endif /* __linux__ */ |
| 976 | return -2; |
| 977 | } |
| 978 | |
| 979 | ip = get_param(cmd, "ip"); |
Pradeep Reddy POTTETI | b18c565 | 2016-01-18 12:45:37 +0530 | [diff] [blame] | 980 | if (!ip) { |
| 981 | send_resp(dut, conn, SIGMA_INVALID, |
| 982 | "ErrorCode,Missing IP address"); |
| 983 | return 0; |
| 984 | } |
| 985 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 986 | mask = get_param(cmd, "mask"); |
Pradeep Reddy POTTETI | b18c565 | 2016-01-18 12:45:37 +0530 | [diff] [blame] | 987 | if (!mask) { |
| 988 | send_resp(dut, conn, SIGMA_INVALID, |
| 989 | "ErrorCode,Missing subnet mask"); |
| 990 | return 0; |
| 991 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 992 | |
| 993 | if (type == 2) { |
| 994 | int net = atoi(mask); |
| 995 | |
| 996 | if ((net < 0 && net > 64) || !is_ipv6_addr(ip)) |
| 997 | return -1; |
| 998 | |
| 999 | if (dut->no_ip_addr_set) { |
| 1000 | snprintf(buf, sizeof(buf), |
| 1001 | "sysctl net.ipv6.conf.%s.disable_ipv6=1", |
| 1002 | ifname); |
| 1003 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 1004 | if (system(buf) != 0) { |
| 1005 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 1006 | "Failed to disable IPv6 address before association"); |
| 1007 | } |
| 1008 | } else { |
| 1009 | snprintf(buf, sizeof(buf), |
| 1010 | "ip -6 addr del %s/%s dev %s", |
| 1011 | ip, mask, ifname); |
| 1012 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 1013 | if (system(buf) != 0) { |
| 1014 | /* |
| 1015 | * This command may fail if the address being |
| 1016 | * deleted does not exist. Inaction here is |
| 1017 | * intentional. |
| 1018 | */ |
| 1019 | } |
| 1020 | |
| 1021 | snprintf(buf, sizeof(buf), |
| 1022 | "ip -6 addr add %s/%s dev %s", |
| 1023 | ip, mask, ifname); |
| 1024 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 1025 | if (system(buf) != 0) { |
| 1026 | send_resp(dut, conn, SIGMA_ERROR, |
| 1027 | "ErrorCode,Failed to set IPv6 address"); |
| 1028 | return 0; |
| 1029 | } |
| 1030 | } |
| 1031 | |
| 1032 | dut->last_set_ip_config_ipv6 = 1; |
| 1033 | static_ip_file(6, ip, mask, NULL); |
| 1034 | return 1; |
| 1035 | } else if (type == 1) { |
Pradeep Reddy POTTETI | b18c565 | 2016-01-18 12:45:37 +0530 | [diff] [blame] | 1036 | if (!is_ip_addr(ip) || !is_ip_addr(mask)) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1037 | return -1; |
| 1038 | } |
| 1039 | |
| 1040 | kill_dhcp_client(dut, ifname); |
| 1041 | |
| 1042 | if (!dut->no_ip_addr_set) { |
| 1043 | snprintf(buf, sizeof(buf), "ifconfig %s %s netmask %s", |
| 1044 | ifname, ip, mask); |
| 1045 | if (system(buf) != 0) { |
| 1046 | send_resp(dut, conn, SIGMA_ERROR, |
| 1047 | "ErrorCode,Failed to set IP address"); |
| 1048 | return 0; |
| 1049 | } |
| 1050 | } |
| 1051 | |
| 1052 | gw = get_param(cmd, "defaultGateway"); |
| 1053 | if (gw) { |
| 1054 | if (!is_ip_addr(gw)) |
| 1055 | return -1; |
| 1056 | snprintf(buf, sizeof(buf), "route add default gw %s", gw); |
| 1057 | if (!dut->no_ip_addr_set && system(buf) != 0) { |
| 1058 | snprintf(buf, sizeof(buf), "ip ro re default via %s", |
| 1059 | gw); |
| 1060 | if (system(buf) != 0) { |
| 1061 | send_resp(dut, conn, SIGMA_ERROR, |
| 1062 | "ErrorCode,Failed " |
| 1063 | "to set default gateway"); |
| 1064 | return 0; |
| 1065 | } |
| 1066 | } |
| 1067 | } |
| 1068 | |
| 1069 | val = get_param(cmd, "primary-dns"); |
| 1070 | if (val) { |
| 1071 | /* TODO */ |
| 1072 | sigma_dut_print(dut, DUT_MSG_INFO, "Ignored primary-dns %s " |
| 1073 | "setting", val); |
| 1074 | } |
| 1075 | |
| 1076 | val = get_param(cmd, "secondary-dns"); |
| 1077 | if (val) { |
| 1078 | /* TODO */ |
| 1079 | sigma_dut_print(dut, DUT_MSG_INFO, "Ignored secondary-dns %s " |
| 1080 | "setting", val); |
| 1081 | } |
| 1082 | |
| 1083 | static_ip_file(4, ip, mask, gw); |
| 1084 | |
| 1085 | return 1; |
| 1086 | } |
| 1087 | |
| 1088 | |
| 1089 | static int cmd_sta_get_info(struct sigma_dut *dut, struct sigma_conn *conn, |
| 1090 | struct sigma_cmd *cmd) |
| 1091 | { |
| 1092 | /* const char *intf = get_param(cmd, "Interface"); */ |
| 1093 | /* TODO: could report more details here */ |
| 1094 | send_resp(dut, conn, SIGMA_COMPLETE, "vendor,Atheros"); |
| 1095 | return 0; |
| 1096 | } |
| 1097 | |
| 1098 | |
| 1099 | static int cmd_sta_get_mac_address(struct sigma_dut *dut, |
| 1100 | struct sigma_conn *conn, |
| 1101 | struct sigma_cmd *cmd) |
| 1102 | { |
| 1103 | /* const char *intf = get_param(cmd, "Interface"); */ |
| 1104 | char addr[20], resp[50]; |
| 1105 | |
Ankita Bajaj | 0d5825b | 2017-10-25 16:20:17 +0530 | [diff] [blame] | 1106 | if (dut->dev_role == DEVROLE_STA_CFON) |
| 1107 | return sta_cfon_get_mac_address(dut, conn, cmd); |
| 1108 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1109 | if (get_wpa_status(get_station_ifname(), "address", addr, sizeof(addr)) |
| 1110 | < 0) |
| 1111 | return -2; |
| 1112 | |
| 1113 | snprintf(resp, sizeof(resp), "mac,%s", addr); |
| 1114 | send_resp(dut, conn, SIGMA_COMPLETE, resp); |
| 1115 | return 0; |
| 1116 | } |
| 1117 | |
| 1118 | |
| 1119 | static int cmd_sta_is_connected(struct sigma_dut *dut, struct sigma_conn *conn, |
| 1120 | struct sigma_cmd *cmd) |
| 1121 | { |
| 1122 | /* const char *intf = get_param(cmd, "Interface"); */ |
| 1123 | int connected = 0; |
| 1124 | char result[32]; |
| 1125 | if (get_wpa_status(get_station_ifname(), "wpa_state", result, |
| 1126 | sizeof(result)) < 0) { |
| 1127 | sigma_dut_print(dut, DUT_MSG_INFO, "Could not get interface " |
| 1128 | "%s status", get_station_ifname()); |
| 1129 | return -2; |
| 1130 | } |
| 1131 | |
| 1132 | sigma_dut_print(dut, DUT_MSG_DEBUG, "wpa_state=%s", result); |
| 1133 | if (strncmp(result, "COMPLETED", 9) == 0) |
| 1134 | connected = 1; |
| 1135 | |
| 1136 | if (connected) |
| 1137 | send_resp(dut, conn, SIGMA_COMPLETE, "connected,1"); |
| 1138 | else |
| 1139 | send_resp(dut, conn, SIGMA_COMPLETE, "connected,0"); |
| 1140 | |
| 1141 | return 0; |
| 1142 | } |
| 1143 | |
| 1144 | |
| 1145 | static int cmd_sta_verify_ip_connection(struct sigma_dut *dut, |
| 1146 | struct sigma_conn *conn, |
| 1147 | struct sigma_cmd *cmd) |
| 1148 | { |
| 1149 | /* const char *intf = get_param(cmd, "Interface"); */ |
| 1150 | const char *dst, *timeout; |
| 1151 | int wait_time = 90; |
| 1152 | char buf[100]; |
| 1153 | int res; |
| 1154 | |
| 1155 | dst = get_param(cmd, "destination"); |
| 1156 | if (dst == NULL || !is_ip_addr(dst)) |
| 1157 | return -1; |
| 1158 | |
| 1159 | timeout = get_param(cmd, "timeout"); |
| 1160 | if (timeout) { |
| 1161 | wait_time = atoi(timeout); |
| 1162 | if (wait_time < 1) |
| 1163 | wait_time = 1; |
| 1164 | } |
| 1165 | |
| 1166 | /* TODO: force renewal of IP lease if DHCP is enabled */ |
| 1167 | |
| 1168 | snprintf(buf, sizeof(buf), "ping %s -c 3 -W %d", dst, wait_time); |
| 1169 | res = system(buf); |
| 1170 | sigma_dut_print(dut, DUT_MSG_DEBUG, "ping returned: %d", res); |
| 1171 | if (res == 0) |
| 1172 | send_resp(dut, conn, SIGMA_COMPLETE, "connected,1"); |
| 1173 | else if (res == 256) |
| 1174 | send_resp(dut, conn, SIGMA_COMPLETE, "connected,0"); |
| 1175 | else |
| 1176 | return -2; |
| 1177 | |
| 1178 | return 0; |
| 1179 | } |
| 1180 | |
| 1181 | |
| 1182 | static int cmd_sta_get_bssid(struct sigma_dut *dut, struct sigma_conn *conn, |
| 1183 | struct sigma_cmd *cmd) |
| 1184 | { |
| 1185 | /* const char *intf = get_param(cmd, "Interface"); */ |
| 1186 | char bssid[20], resp[50]; |
| 1187 | |
| 1188 | if (get_wpa_status(get_station_ifname(), "bssid", bssid, sizeof(bssid)) |
| 1189 | < 0) |
Peng Xu | b8fc5cc | 2017-05-10 17:27:28 -0700 | [diff] [blame] | 1190 | strlcpy(bssid, "00:00:00:00:00:00", sizeof(bssid)); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1191 | |
| 1192 | snprintf(resp, sizeof(resp), "bssid,%s", bssid); |
| 1193 | send_resp(dut, conn, SIGMA_COMPLETE, resp); |
| 1194 | return 0; |
| 1195 | } |
| 1196 | |
| 1197 | |
| 1198 | #ifdef __SAMSUNG__ |
| 1199 | static int add_use_network(const char *ifname) |
| 1200 | { |
| 1201 | char buf[100]; |
| 1202 | |
| 1203 | snprintf(buf, sizeof(buf), "USE_NETWORK ON"); |
| 1204 | wpa_command(ifname, buf); |
| 1205 | return 0; |
| 1206 | } |
| 1207 | #endif /* __SAMSUNG__ */ |
| 1208 | |
| 1209 | |
| 1210 | static int add_network_common(struct sigma_dut *dut, struct sigma_conn *conn, |
| 1211 | const char *ifname, struct sigma_cmd *cmd) |
| 1212 | { |
| 1213 | const char *ssid = get_param(cmd, "ssid"); |
| 1214 | int id; |
| 1215 | const char *val; |
| 1216 | |
| 1217 | if (ssid == NULL) |
| 1218 | return -1; |
| 1219 | |
| 1220 | start_sta_mode(dut); |
| 1221 | |
| 1222 | #ifdef __SAMSUNG__ |
| 1223 | add_use_network(ifname); |
| 1224 | #endif /* __SAMSUNG__ */ |
| 1225 | |
| 1226 | id = add_network(ifname); |
| 1227 | if (id < 0) |
| 1228 | return -2; |
| 1229 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding network %d", id); |
| 1230 | |
| 1231 | if (set_network_quoted(ifname, id, "ssid", ssid) < 0) |
| 1232 | return -2; |
| 1233 | |
| 1234 | dut->infra_network_id = id; |
| 1235 | snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid); |
| 1236 | |
| 1237 | val = get_param(cmd, "program"); |
| 1238 | if (!val) |
| 1239 | val = get_param(cmd, "prog"); |
| 1240 | if (val && strcasecmp(val, "hs2") == 0) { |
| 1241 | char buf[100]; |
| 1242 | snprintf(buf, sizeof(buf), "ENABLE_NETWORK %d no-connect", id); |
| 1243 | wpa_command(ifname, buf); |
| 1244 | |
| 1245 | val = get_param(cmd, "prefer"); |
| 1246 | if (val && atoi(val) > 0) |
| 1247 | set_network(ifname, id, "priority", "1"); |
| 1248 | } |
| 1249 | |
| 1250 | return id; |
| 1251 | } |
| 1252 | |
| 1253 | |
| 1254 | static int cmd_sta_set_encryption(struct sigma_dut *dut, |
| 1255 | struct sigma_conn *conn, |
| 1256 | struct sigma_cmd *cmd) |
| 1257 | { |
| 1258 | const char *intf = get_param(cmd, "Interface"); |
| 1259 | const char *ssid = get_param(cmd, "ssid"); |
| 1260 | const char *type = get_param(cmd, "encpType"); |
| 1261 | const char *ifname; |
| 1262 | char buf[200]; |
| 1263 | int id; |
| 1264 | |
| 1265 | if (intf == NULL || ssid == NULL) |
| 1266 | return -1; |
| 1267 | |
| 1268 | if (strcmp(intf, get_main_ifname()) == 0) |
| 1269 | ifname = get_station_ifname(); |
| 1270 | else |
| 1271 | ifname = intf; |
| 1272 | |
| 1273 | id = add_network_common(dut, conn, ifname, cmd); |
| 1274 | if (id < 0) |
| 1275 | return id; |
| 1276 | |
| 1277 | if (set_network(ifname, id, "key_mgmt", "NONE") < 0) |
| 1278 | return -2; |
| 1279 | |
| 1280 | if (type && strcasecmp(type, "wep") == 0) { |
| 1281 | const char *val; |
| 1282 | int i; |
| 1283 | |
| 1284 | val = get_param(cmd, "activeKey"); |
| 1285 | if (val) { |
| 1286 | int keyid; |
| 1287 | keyid = atoi(val); |
| 1288 | if (keyid < 1 || keyid > 4) |
| 1289 | return -1; |
| 1290 | snprintf(buf, sizeof(buf), "%d", keyid - 1); |
| 1291 | if (set_network(ifname, id, "wep_tx_keyidx", buf) < 0) |
| 1292 | return -2; |
| 1293 | } |
| 1294 | |
| 1295 | for (i = 0; i < 4; i++) { |
| 1296 | snprintf(buf, sizeof(buf), "key%d", i + 1); |
| 1297 | val = get_param(cmd, buf); |
| 1298 | if (val == NULL) |
| 1299 | continue; |
| 1300 | snprintf(buf, sizeof(buf), "wep_key%d", i); |
| 1301 | if (set_network(ifname, id, buf, val) < 0) |
| 1302 | return -2; |
| 1303 | } |
| 1304 | } |
| 1305 | |
| 1306 | return 1; |
| 1307 | } |
| 1308 | |
| 1309 | |
| 1310 | static int set_wpa_common(struct sigma_dut *dut, struct sigma_conn *conn, |
| 1311 | const char *ifname, struct sigma_cmd *cmd) |
| 1312 | { |
| 1313 | const char *val; |
| 1314 | int id; |
Jouni Malinen | ad395a2 | 2017-09-01 21:13:46 +0300 | [diff] [blame] | 1315 | int cipher_set = 0; |
Jouni Malinen | 47dcc95 | 2017-10-09 16:43:24 +0300 | [diff] [blame] | 1316 | int owe; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1317 | |
| 1318 | id = add_network_common(dut, conn, ifname, cmd); |
| 1319 | if (id < 0) |
| 1320 | return id; |
| 1321 | |
Jouni Malinen | 47dcc95 | 2017-10-09 16:43:24 +0300 | [diff] [blame] | 1322 | val = get_param(cmd, "Type"); |
| 1323 | owe = val && strcasecmp(val, "OWE") == 0; |
| 1324 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1325 | val = get_param(cmd, "keyMgmtType"); |
Jouni Malinen | 47dcc95 | 2017-10-09 16:43:24 +0300 | [diff] [blame] | 1326 | if (!val && owe) |
| 1327 | val = "OWE"; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1328 | if (val == NULL) { |
| 1329 | send_resp(dut, conn, SIGMA_INVALID, "errorCode,Missing keyMgmtType"); |
| 1330 | return 0; |
| 1331 | } |
| 1332 | if (strcasecmp(val, "wpa") == 0 || |
| 1333 | strcasecmp(val, "wpa-psk") == 0) { |
| 1334 | if (set_network(ifname, id, "proto", "WPA") < 0) |
| 1335 | return -2; |
| 1336 | } else if (strcasecmp(val, "wpa2") == 0 || |
| 1337 | strcasecmp(val, "wpa2-psk") == 0 || |
| 1338 | strcasecmp(val, "wpa2-ft") == 0 || |
| 1339 | strcasecmp(val, "wpa2-sha256") == 0) { |
| 1340 | if (set_network(ifname, id, "proto", "WPA2") < 0) |
| 1341 | return -2; |
Pradeep Reddy POTTETI | 6d04b3b | 2016-11-15 14:51:26 +0530 | [diff] [blame] | 1342 | } else if (strcasecmp(val, "wpa2-wpa-psk") == 0 || |
| 1343 | strcasecmp(val, "wpa2-wpa-ent") == 0) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1344 | if (set_network(ifname, id, "proto", "WPA WPA2") < 0) |
| 1345 | return -2; |
Jouni Malinen | ad395a2 | 2017-09-01 21:13:46 +0300 | [diff] [blame] | 1346 | } else if (strcasecmp(val, "SuiteB") == 0) { |
| 1347 | if (set_network(ifname, id, "proto", "WPA2") < 0) |
| 1348 | return -2; |
Jouni Malinen | 47dcc95 | 2017-10-09 16:43:24 +0300 | [diff] [blame] | 1349 | } else if (strcasecmp(val, "OWE") == 0) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1350 | } else { |
| 1351 | send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized keyMgmtType value"); |
| 1352 | return 0; |
| 1353 | } |
| 1354 | |
| 1355 | val = get_param(cmd, "encpType"); |
Jouni Malinen | ad395a2 | 2017-09-01 21:13:46 +0300 | [diff] [blame] | 1356 | if (val) { |
| 1357 | cipher_set = 1; |
| 1358 | if (strcasecmp(val, "tkip") == 0) { |
| 1359 | if (set_network(ifname, id, "pairwise", "TKIP") < 0) |
| 1360 | return -2; |
| 1361 | } else if (strcasecmp(val, "aes-ccmp") == 0) { |
| 1362 | if (set_network(ifname, id, "pairwise", "CCMP") < 0) |
| 1363 | return -2; |
| 1364 | } else if (strcasecmp(val, "aes-ccmp-tkip") == 0) { |
| 1365 | if (set_network(ifname, id, "pairwise", |
| 1366 | "CCMP TKIP") < 0) |
| 1367 | return -2; |
| 1368 | } else if (strcasecmp(val, "aes-gcmp") == 0) { |
| 1369 | if (set_network(ifname, id, "pairwise", "GCMP") < 0) |
| 1370 | return -2; |
| 1371 | if (set_network(ifname, id, "group", "GCMP") < 0) |
| 1372 | return -2; |
| 1373 | } else { |
| 1374 | send_resp(dut, conn, SIGMA_ERROR, |
| 1375 | "errorCode,Unrecognized encpType value"); |
| 1376 | return 0; |
| 1377 | } |
| 1378 | } |
| 1379 | |
| 1380 | val = get_param(cmd, "PairwiseCipher"); |
| 1381 | if (val) { |
| 1382 | cipher_set = 1; |
| 1383 | /* TODO: Support space separated list */ |
| 1384 | if (strcasecmp(val, "AES-GCMP-256") == 0) { |
| 1385 | if (set_network(ifname, id, "pairwise", "GCMP-256") < 0) |
| 1386 | return -2; |
| 1387 | } else if (strcasecmp(val, "AES-CCMP-256") == 0) { |
| 1388 | if (set_network(ifname, id, "pairwise", |
| 1389 | "CCMP-256") < 0) |
| 1390 | return -2; |
| 1391 | } else if (strcasecmp(val, "AES-GCMP-128") == 0) { |
| 1392 | if (set_network(ifname, id, "pairwise", "GCMP") < 0) |
| 1393 | return -2; |
| 1394 | } else if (strcasecmp(val, "AES-CCMP-128") == 0) { |
| 1395 | if (set_network(ifname, id, "pairwise", "CCMP") < 0) |
| 1396 | return -2; |
| 1397 | } else { |
| 1398 | send_resp(dut, conn, SIGMA_ERROR, |
| 1399 | "errorCode,Unrecognized PairwiseCipher value"); |
| 1400 | return 0; |
| 1401 | } |
| 1402 | } |
| 1403 | |
Jouni Malinen | 47dcc95 | 2017-10-09 16:43:24 +0300 | [diff] [blame] | 1404 | if (!cipher_set && !owe) { |
Jouni Malinen | ad395a2 | 2017-09-01 21:13:46 +0300 | [diff] [blame] | 1405 | send_resp(dut, conn, SIGMA_ERROR, |
| 1406 | "errorCode,Missing encpType and PairwiseCipher"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1407 | return 0; |
| 1408 | } |
Jouni Malinen | ad395a2 | 2017-09-01 21:13:46 +0300 | [diff] [blame] | 1409 | |
| 1410 | val = get_param(cmd, "GroupCipher"); |
| 1411 | if (val) { |
| 1412 | if (strcasecmp(val, "AES-GCMP-256") == 0) { |
| 1413 | if (set_network(ifname, id, "group", "GCMP-256") < 0) |
| 1414 | return -2; |
| 1415 | } else if (strcasecmp(val, "AES-CCMP-256") == 0) { |
| 1416 | if (set_network(ifname, id, "group", "CCMP-256") < 0) |
| 1417 | return -2; |
| 1418 | } else if (strcasecmp(val, "AES-GCMP-128") == 0) { |
| 1419 | if (set_network(ifname, id, "group", "GCMP") < 0) |
| 1420 | return -2; |
| 1421 | } else if (strcasecmp(val, "AES-CCMP-128") == 0) { |
| 1422 | if (set_network(ifname, id, "group", "CCMP") < 0) |
| 1423 | return -2; |
| 1424 | } else { |
| 1425 | send_resp(dut, conn, SIGMA_ERROR, |
| 1426 | "errorCode,Unrecognized GroupCipher value"); |
| 1427 | return 0; |
| 1428 | } |
| 1429 | } |
| 1430 | |
Jouni Malinen | 7b23952 | 2017-09-14 21:37:18 +0300 | [diff] [blame] | 1431 | val = get_param(cmd, "GroupMgntCipher"); |
Jouni Malinen | ad395a2 | 2017-09-01 21:13:46 +0300 | [diff] [blame] | 1432 | if (val) { |
Jouni Malinen | e8898cb | 2017-09-26 17:55:26 +0300 | [diff] [blame] | 1433 | const char *cipher; |
| 1434 | |
| 1435 | if (strcasecmp(val, "BIP-GMAC-256") == 0) { |
| 1436 | cipher = "BIP-GMAC-256"; |
| 1437 | } else if (strcasecmp(val, "BIP-CMAC-256") == 0) { |
| 1438 | cipher = "BIP-CMAC-256"; |
| 1439 | } else if (strcasecmp(val, "BIP-GMAC-128") == 0) { |
| 1440 | cipher = "BIP-GMAC-128"; |
| 1441 | } else if (strcasecmp(val, "BIP-CMAC-128") == 0) { |
| 1442 | cipher = "AES-128-CMAC"; |
| 1443 | } else { |
| 1444 | send_resp(dut, conn, SIGMA_INVALID, |
| 1445 | "errorCode,Unsupported GroupMgntCipher"); |
| 1446 | return 0; |
| 1447 | } |
| 1448 | if (set_network(ifname, id, "group_mgmt", cipher) < 0) { |
| 1449 | send_resp(dut, conn, SIGMA_INVALID, |
| 1450 | "errorCode,Failed to set GroupMgntCipher"); |
| 1451 | return 0; |
| 1452 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1453 | } |
| 1454 | |
| 1455 | dut->sta_pmf = STA_PMF_DISABLED; |
vamsi krishna | f39bc1e | 2017-08-23 17:37:53 +0530 | [diff] [blame] | 1456 | |
| 1457 | if (dut->program == PROGRAM_OCE) { |
| 1458 | dut->sta_pmf = STA_PMF_OPTIONAL; |
| 1459 | if (set_network(ifname, id, "ieee80211w", "1") < 0) |
| 1460 | return -2; |
| 1461 | } |
| 1462 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1463 | val = get_param(cmd, "PMF"); |
| 1464 | if (val) { |
| 1465 | if (strcasecmp(val, "Required") == 0 || |
| 1466 | strcasecmp(val, "Forced_Required") == 0) { |
| 1467 | dut->sta_pmf = STA_PMF_REQUIRED; |
| 1468 | if (set_network(ifname, id, "ieee80211w", "2") < 0) |
| 1469 | return -2; |
| 1470 | } else if (strcasecmp(val, "Optional") == 0) { |
| 1471 | dut->sta_pmf = STA_PMF_OPTIONAL; |
| 1472 | if (set_network(ifname, id, "ieee80211w", "1") < 0) |
| 1473 | return -2; |
| 1474 | } else if (strcasecmp(val, "Disabled") == 0 || |
| 1475 | strcasecmp(val, "Forced_Disabled") == 0) { |
| 1476 | dut->sta_pmf = STA_PMF_DISABLED; |
| 1477 | } else { |
| 1478 | send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized PMF value"); |
| 1479 | return 0; |
| 1480 | } |
Jouni Malinen | 1287cd7 | 2018-01-04 17:08:01 +0200 | [diff] [blame] | 1481 | } else if (owe) { |
| 1482 | dut->sta_pmf = STA_PMF_REQUIRED; |
| 1483 | if (set_network(ifname, id, "ieee80211w", "2") < 0) |
| 1484 | return -2; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1485 | } |
| 1486 | |
| 1487 | return id; |
| 1488 | } |
| 1489 | |
| 1490 | |
| 1491 | static int cmd_sta_set_psk(struct sigma_dut *dut, struct sigma_conn *conn, |
| 1492 | struct sigma_cmd *cmd) |
| 1493 | { |
| 1494 | const char *intf = get_param(cmd, "Interface"); |
Jouni Malinen | 992a81e | 2017-08-22 13:57:47 +0300 | [diff] [blame] | 1495 | const char *type = get_param(cmd, "Type"); |
Jouni Malinen | 1287cd7 | 2018-01-04 17:08:01 +0200 | [diff] [blame] | 1496 | const char *pmf = get_param(cmd, "PMF"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1497 | const char *ifname, *val, *alg; |
| 1498 | int id; |
| 1499 | |
| 1500 | if (intf == NULL) |
| 1501 | return -1; |
| 1502 | |
| 1503 | if (strcmp(intf, get_main_ifname()) == 0) |
| 1504 | ifname = get_station_ifname(); |
| 1505 | else |
| 1506 | ifname = intf; |
| 1507 | |
| 1508 | id = set_wpa_common(dut, conn, ifname, cmd); |
| 1509 | if (id < 0) |
| 1510 | return id; |
| 1511 | |
| 1512 | val = get_param(cmd, "keyMgmtType"); |
| 1513 | alg = get_param(cmd, "micAlg"); |
| 1514 | |
Jouni Malinen | 992a81e | 2017-08-22 13:57:47 +0300 | [diff] [blame] | 1515 | if (type && strcasecmp(type, "SAE") == 0) { |
| 1516 | if (val && strcasecmp(val, "wpa2-ft") == 0) { |
| 1517 | if (set_network(ifname, id, "key_mgmt", "FT-SAE") < 0) |
| 1518 | return -2; |
| 1519 | } else { |
| 1520 | if (set_network(ifname, id, "key_mgmt", "SAE") < 0) |
| 1521 | return -2; |
| 1522 | } |
| 1523 | if (wpa_command(ifname, "SET sae_groups ") != 0) { |
| 1524 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 1525 | "Failed to clear sae_groups to default"); |
| 1526 | return -2; |
| 1527 | } |
Jouni Malinen | 1287cd7 | 2018-01-04 17:08:01 +0200 | [diff] [blame] | 1528 | if (!pmf) { |
| 1529 | dut->sta_pmf = STA_PMF_REQUIRED; |
| 1530 | if (set_network(ifname, id, "ieee80211w", "2") < 0) |
| 1531 | return -2; |
| 1532 | } |
Jouni Malinen | 0ab50f4 | 2017-08-31 01:34:59 +0300 | [diff] [blame] | 1533 | } else if (type && strcasecmp(type, "PSK-SAE") == 0) { |
| 1534 | if (val && strcasecmp(val, "wpa2-ft") == 0) { |
| 1535 | if (set_network(ifname, id, "key_mgmt", |
| 1536 | "FT-SAE FT-PSK") < 0) |
| 1537 | return -2; |
| 1538 | } else { |
| 1539 | if (set_network(ifname, id, "key_mgmt", |
| 1540 | "SAE WPA-PSK") < 0) |
| 1541 | return -2; |
| 1542 | } |
| 1543 | if (wpa_command(ifname, "SET sae_groups ") != 0) { |
| 1544 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 1545 | "Failed to clear sae_groups to default"); |
| 1546 | return -2; |
| 1547 | } |
Jouni Malinen | 1287cd7 | 2018-01-04 17:08:01 +0200 | [diff] [blame] | 1548 | if (!pmf) { |
| 1549 | dut->sta_pmf = STA_PMF_OPTIONAL; |
| 1550 | if (set_network(ifname, id, "ieee80211w", "1") < 0) |
| 1551 | return -2; |
| 1552 | } |
Jouni Malinen | 992a81e | 2017-08-22 13:57:47 +0300 | [diff] [blame] | 1553 | } else if (alg && strcasecmp(alg, "SHA-256") == 0) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1554 | if (set_network(ifname, id, "key_mgmt", "WPA-PSK-SHA256") < 0) |
| 1555 | return -2; |
| 1556 | } else if (alg && strcasecmp(alg, "SHA-1") == 0) { |
| 1557 | if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0) |
| 1558 | return -2; |
Ashwini Patil | 6dbf7b0 | 2017-03-20 13:42:11 +0530 | [diff] [blame] | 1559 | } else if (val && strcasecmp(val, "wpa2-ft") == 0) { |
| 1560 | if (set_network(ifname, id, "key_mgmt", "FT-PSK") < 0) |
| 1561 | return -2; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1562 | } else if ((val && strcasecmp(val, "wpa2-sha256") == 0) || |
| 1563 | dut->sta_pmf == STA_PMF_REQUIRED) { |
| 1564 | if (set_network(ifname, id, "key_mgmt", |
| 1565 | "WPA-PSK WPA-PSK-SHA256") < 0) |
| 1566 | return -2; |
| 1567 | } else if (dut->sta_pmf == STA_PMF_OPTIONAL) { |
| 1568 | if (set_network(ifname, id, "key_mgmt", |
| 1569 | "WPA-PSK WPA-PSK-SHA256") < 0) |
| 1570 | return -2; |
| 1571 | } else { |
| 1572 | if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0) |
| 1573 | return -2; |
| 1574 | } |
| 1575 | |
| 1576 | val = get_param(cmd, "passPhrase"); |
| 1577 | if (val == NULL) |
| 1578 | return -1; |
Jouni Malinen | 2126f42 | 2017-10-11 23:24:33 +0300 | [diff] [blame] | 1579 | if (type && strcasecmp(type, "SAE") == 0) { |
| 1580 | if (set_network_quoted(ifname, id, "sae_password", val) < 0) |
| 1581 | return -2; |
| 1582 | } else { |
| 1583 | if (set_network_quoted(ifname, id, "psk", val) < 0) |
| 1584 | return -2; |
| 1585 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1586 | |
Jouni Malinen | 992a81e | 2017-08-22 13:57:47 +0300 | [diff] [blame] | 1587 | val = get_param(cmd, "ECGroupID"); |
| 1588 | if (val) { |
| 1589 | char buf[50]; |
| 1590 | |
| 1591 | snprintf(buf, sizeof(buf), "SET sae_groups %u", atoi(val)); |
| 1592 | if (wpa_command(ifname, buf) != 0) { |
| 1593 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 1594 | "Failed to clear sae_groups"); |
| 1595 | return -2; |
| 1596 | } |
| 1597 | } |
| 1598 | |
Jouni Malinen | 6814313 | 2017-09-02 02:34:08 +0300 | [diff] [blame] | 1599 | val = get_param(cmd, "InvalidSAEElement"); |
| 1600 | if (val) { |
| 1601 | free(dut->sae_commit_override); |
| 1602 | dut->sae_commit_override = strdup(val); |
| 1603 | } |
| 1604 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1605 | return 1; |
| 1606 | } |
| 1607 | |
| 1608 | |
| 1609 | 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] | 1610 | const char *ifname, int username_identity, |
| 1611 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1612 | { |
vamsi krishna | f39bc1e | 2017-08-23 17:37:53 +0530 | [diff] [blame] | 1613 | const char *val, *alg, *akm; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1614 | int id; |
| 1615 | char buf[200]; |
| 1616 | #ifdef ANDROID |
| 1617 | unsigned char kvalue[KEYSTORE_MESSAGE_SIZE]; |
| 1618 | int length; |
| 1619 | #endif /* ANDROID */ |
| 1620 | |
| 1621 | id = set_wpa_common(dut, conn, ifname, cmd); |
| 1622 | if (id < 0) |
| 1623 | return id; |
| 1624 | |
| 1625 | val = get_param(cmd, "keyMgmtType"); |
| 1626 | alg = get_param(cmd, "micAlg"); |
vamsi krishna | f39bc1e | 2017-08-23 17:37:53 +0530 | [diff] [blame] | 1627 | akm = get_param(cmd, "AKMSuiteType"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1628 | |
Jouni Malinen | ad395a2 | 2017-09-01 21:13:46 +0300 | [diff] [blame] | 1629 | if (val && strcasecmp(val, "SuiteB") == 0) { |
| 1630 | if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SUITE-B-192") < |
| 1631 | 0) |
| 1632 | return -2; |
| 1633 | } else if (alg && strcasecmp(alg, "SHA-256") == 0) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1634 | if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SHA256") < 0) |
| 1635 | return -2; |
| 1636 | } else if (alg && strcasecmp(alg, "SHA-1") == 0) { |
| 1637 | if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0) |
| 1638 | return -2; |
| 1639 | } else if (val && strcasecmp(val, "wpa2-ft") == 0) { |
| 1640 | if (set_network(ifname, id, "key_mgmt", "FT-EAP") < 0) |
| 1641 | return -2; |
| 1642 | } else if ((val && strcasecmp(val, "wpa2-sha256") == 0) || |
| 1643 | dut->sta_pmf == STA_PMF_REQUIRED) { |
| 1644 | if (set_network(ifname, id, "key_mgmt", |
| 1645 | "WPA-EAP WPA-EAP-SHA256") < 0) |
| 1646 | return -2; |
vamsi krishna | f39bc1e | 2017-08-23 17:37:53 +0530 | [diff] [blame] | 1647 | } else if (akm && atoi(akm) == 14) { |
| 1648 | if (dut->sta_pmf == STA_PMF_OPTIONAL || |
| 1649 | dut->sta_pmf == STA_PMF_REQUIRED) { |
| 1650 | if (set_network(ifname, id, "key_mgmt", |
| 1651 | "WPA-EAP-SHA256 FILS-SHA256") < 0) |
| 1652 | return -2; |
| 1653 | } else { |
| 1654 | if (set_network(ifname, id, "key_mgmt", |
| 1655 | "WPA-EAP FILS-SHA256") < 0) |
| 1656 | return -2; |
| 1657 | } |
| 1658 | |
| 1659 | if (set_network(ifname, id, "erp", "1") < 0) |
| 1660 | return -2; |
| 1661 | } else if (akm && atoi(akm) == 15) { |
| 1662 | if (dut->sta_pmf == STA_PMF_OPTIONAL || |
| 1663 | dut->sta_pmf == STA_PMF_REQUIRED) { |
| 1664 | if (set_network(ifname, id, "key_mgmt", |
| 1665 | "WPA-EAP-SHA256 FILS-SHA384") < 0) |
| 1666 | return -2; |
| 1667 | } else { |
| 1668 | if (set_network(ifname, id, "key_mgmt", |
| 1669 | "WPA-EAP FILS-SHA384") < 0) |
| 1670 | return -2; |
| 1671 | } |
| 1672 | |
| 1673 | if (set_network(ifname, id, "erp", "1") < 0) |
| 1674 | return -2; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1675 | } else if (dut->sta_pmf == STA_PMF_OPTIONAL) { |
| 1676 | if (set_network(ifname, id, "key_mgmt", |
| 1677 | "WPA-EAP WPA-EAP-SHA256") < 0) |
| 1678 | return -2; |
| 1679 | } else { |
| 1680 | if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0) |
| 1681 | return -2; |
| 1682 | } |
| 1683 | |
| 1684 | val = get_param(cmd, "trustedRootCA"); |
| 1685 | if (val) { |
| 1686 | #ifdef ANDROID |
| 1687 | snprintf(buf, sizeof(buf), "CACERT_%s", val); |
| 1688 | length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, |
| 1689 | kvalue); |
| 1690 | if (length > 0) { |
| 1691 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 1692 | "Use Android keystore [%s]", buf); |
| 1693 | snprintf(buf, sizeof(buf), "keystore://CACERT_%s", |
| 1694 | val); |
| 1695 | goto ca_cert_selected; |
| 1696 | } |
| 1697 | #endif /* ANDROID */ |
| 1698 | |
| 1699 | snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val); |
| 1700 | #ifdef __linux__ |
| 1701 | if (!file_exists(buf)) { |
| 1702 | char msg[300]; |
| 1703 | snprintf(msg, sizeof(msg), "ErrorCode,trustedRootCA " |
| 1704 | "file (%s) not found", buf); |
| 1705 | send_resp(dut, conn, SIGMA_ERROR, msg); |
| 1706 | return -3; |
| 1707 | } |
| 1708 | #endif /* __linux__ */ |
| 1709 | #ifdef ANDROID |
| 1710 | ca_cert_selected: |
| 1711 | #endif /* ANDROID */ |
| 1712 | if (set_network_quoted(ifname, id, "ca_cert", buf) < 0) |
| 1713 | return -2; |
| 1714 | } |
| 1715 | |
Bala Krishna Bhamidipati | 73d7af0 | 2016-03-24 12:27:56 +0530 | [diff] [blame] | 1716 | if (username_identity) { |
| 1717 | val = get_param(cmd, "username"); |
| 1718 | if (val) { |
| 1719 | if (set_network_quoted(ifname, id, "identity", val) < 0) |
| 1720 | return -2; |
| 1721 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1722 | |
Bala Krishna Bhamidipati | 73d7af0 | 2016-03-24 12:27:56 +0530 | [diff] [blame] | 1723 | val = get_param(cmd, "password"); |
| 1724 | if (val) { |
| 1725 | if (set_network_quoted(ifname, id, "password", val) < 0) |
| 1726 | return -2; |
| 1727 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1728 | } |
| 1729 | |
| 1730 | return id; |
| 1731 | } |
| 1732 | |
| 1733 | |
Jouni Malinen | 5eabb2a | 2017-10-03 18:17:30 +0300 | [diff] [blame] | 1734 | static int set_tls_cipher(const char *ifname, int id, const char *cipher) |
| 1735 | { |
| 1736 | const char *val; |
| 1737 | |
| 1738 | if (!cipher) |
| 1739 | return 0; |
| 1740 | |
| 1741 | if (strcasecmp(cipher, "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384") == 0) |
| 1742 | val = "ECDHE-ECDSA-AES256-GCM-SHA384"; |
| 1743 | else if (strcasecmp(cipher, |
| 1744 | "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384") == 0) |
| 1745 | val = "ECDHE-RSA-AES256-GCM-SHA384"; |
| 1746 | else if (strcasecmp(cipher, "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384") == 0) |
| 1747 | val = "DHE-RSA-AES256-GCM-SHA384"; |
| 1748 | else if (strcasecmp(cipher, |
| 1749 | "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256") == 0) |
| 1750 | val = "ECDHE-ECDSA-AES128-GCM-SHA256"; |
| 1751 | else |
| 1752 | return -1; |
| 1753 | |
| 1754 | /* Need to clear phase1="tls_suiteb=1" to allow cipher enforcement */ |
| 1755 | set_network_quoted(ifname, id, "phase1", ""); |
| 1756 | |
| 1757 | return set_network_quoted(ifname, id, "openssl_ciphers", val); |
| 1758 | } |
| 1759 | |
| 1760 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1761 | static int cmd_sta_set_eaptls(struct sigma_dut *dut, struct sigma_conn *conn, |
| 1762 | struct sigma_cmd *cmd) |
| 1763 | { |
| 1764 | const char *intf = get_param(cmd, "Interface"); |
| 1765 | const char *ifname, *val; |
| 1766 | int id; |
| 1767 | char buf[200]; |
| 1768 | #ifdef ANDROID |
| 1769 | unsigned char kvalue[KEYSTORE_MESSAGE_SIZE]; |
| 1770 | int length; |
| 1771 | int jb_or_newer = 0; |
| 1772 | char prop[PROPERTY_VALUE_MAX]; |
| 1773 | #endif /* ANDROID */ |
| 1774 | |
| 1775 | if (intf == NULL) |
| 1776 | return -1; |
| 1777 | |
| 1778 | if (strcmp(intf, get_main_ifname()) == 0) |
| 1779 | ifname = get_station_ifname(); |
| 1780 | else |
| 1781 | ifname = intf; |
| 1782 | |
Bala Krishna Bhamidipati | 73d7af0 | 2016-03-24 12:27:56 +0530 | [diff] [blame] | 1783 | id = set_eap_common(dut, conn, ifname, 1, cmd); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1784 | if (id < 0) |
| 1785 | return id; |
| 1786 | |
| 1787 | if (set_network(ifname, id, "eap", "TLS") < 0) |
| 1788 | return -2; |
| 1789 | |
Pradeep Reddy POTTETI | 9f6c213 | 2016-05-05 16:28:19 +0530 | [diff] [blame] | 1790 | if (!get_param(cmd, "username") && |
| 1791 | set_network_quoted(ifname, id, "identity", |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1792 | "wifi-user@wifilabs.local") < 0) |
| 1793 | return -2; |
| 1794 | |
| 1795 | val = get_param(cmd, "clientCertificate"); |
| 1796 | if (val == NULL) |
| 1797 | return -1; |
| 1798 | #ifdef ANDROID |
| 1799 | snprintf(buf, sizeof(buf), "USRPKEY_%s", val); |
| 1800 | length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue); |
| 1801 | if (length < 0) { |
| 1802 | /* |
| 1803 | * JB started reporting keystore type mismatches, so retry with |
| 1804 | * the GET_PUBKEY command if the generic GET fails. |
| 1805 | */ |
| 1806 | length = android_keystore_get(ANDROID_KEYSTORE_GET_PUBKEY, |
| 1807 | buf, kvalue); |
| 1808 | } |
| 1809 | |
| 1810 | if (property_get("ro.build.version.release", prop, NULL) != 0) { |
| 1811 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Android release %s", prop); |
| 1812 | if (strncmp(prop, "4.0", 3) != 0) |
| 1813 | jb_or_newer = 1; |
| 1814 | } else |
| 1815 | jb_or_newer = 1; /* assume newer */ |
| 1816 | |
| 1817 | if (jb_or_newer && length > 0) { |
| 1818 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 1819 | "Use Android keystore [%s]", buf); |
| 1820 | if (set_network(ifname, id, "engine", "1") < 0) |
| 1821 | return -2; |
| 1822 | if (set_network_quoted(ifname, id, "engine_id", "keystore") < 0) |
| 1823 | return -2; |
| 1824 | snprintf(buf, sizeof(buf), "USRPKEY_%s", val); |
| 1825 | if (set_network_quoted(ifname, id, "key_id", buf) < 0) |
| 1826 | return -2; |
| 1827 | snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val); |
| 1828 | if (set_network_quoted(ifname, id, "client_cert", buf) < 0) |
| 1829 | return -2; |
| 1830 | return 1; |
| 1831 | } else if (length > 0) { |
| 1832 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 1833 | "Use Android keystore [%s]", buf); |
| 1834 | snprintf(buf, sizeof(buf), "keystore://USRPKEY_%s", val); |
| 1835 | if (set_network_quoted(ifname, id, "private_key", buf) < 0) |
| 1836 | return -2; |
| 1837 | snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val); |
| 1838 | if (set_network_quoted(ifname, id, "client_cert", buf) < 0) |
| 1839 | return -2; |
| 1840 | return 1; |
| 1841 | } |
| 1842 | #endif /* ANDROID */ |
| 1843 | |
| 1844 | snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val); |
| 1845 | #ifdef __linux__ |
| 1846 | if (!file_exists(buf)) { |
| 1847 | char msg[300]; |
| 1848 | snprintf(msg, sizeof(msg), "ErrorCode,clientCertificate file " |
| 1849 | "(%s) not found", buf); |
| 1850 | send_resp(dut, conn, SIGMA_ERROR, msg); |
| 1851 | return -3; |
| 1852 | } |
| 1853 | #endif /* __linux__ */ |
| 1854 | if (set_network_quoted(ifname, id, "private_key", buf) < 0) |
| 1855 | return -2; |
| 1856 | if (set_network_quoted(ifname, id, "client_cert", buf) < 0) |
| 1857 | return -2; |
| 1858 | |
| 1859 | if (set_network_quoted(ifname, id, "private_key_passwd", "wifi") < 0) |
| 1860 | return -2; |
| 1861 | |
Jouni Malinen | 5eabb2a | 2017-10-03 18:17:30 +0300 | [diff] [blame] | 1862 | val = get_param(cmd, "keyMgmtType"); |
| 1863 | if (val && strcasecmp(val, "SuiteB") == 0) { |
| 1864 | val = get_param(cmd, "CertType"); |
| 1865 | if (val && strcasecmp(val, "RSA") == 0) { |
| 1866 | if (set_network_quoted(ifname, id, "phase1", |
| 1867 | "tls_suiteb=1") < 0) |
| 1868 | return -2; |
| 1869 | } else { |
| 1870 | if (set_network_quoted(ifname, id, "openssl_ciphers", |
| 1871 | "SUITEB192") < 0) |
| 1872 | return -2; |
| 1873 | } |
| 1874 | |
| 1875 | val = get_param(cmd, "TLSCipher"); |
| 1876 | if (set_tls_cipher(ifname, id, val) < 0) { |
| 1877 | send_resp(dut, conn, SIGMA_ERROR, |
| 1878 | "ErrorCode,Unsupported TLSCipher value"); |
| 1879 | return -3; |
| 1880 | } |
| 1881 | } |
| 1882 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1883 | return 1; |
| 1884 | } |
| 1885 | |
| 1886 | |
| 1887 | static int cmd_sta_set_eapttls(struct sigma_dut *dut, struct sigma_conn *conn, |
| 1888 | struct sigma_cmd *cmd) |
| 1889 | { |
| 1890 | const char *intf = get_param(cmd, "Interface"); |
| 1891 | const char *ifname; |
| 1892 | int id; |
| 1893 | |
| 1894 | if (intf == NULL) |
| 1895 | return -1; |
| 1896 | |
| 1897 | if (strcmp(intf, get_main_ifname()) == 0) |
| 1898 | ifname = get_station_ifname(); |
| 1899 | else |
| 1900 | ifname = intf; |
| 1901 | |
Bala Krishna Bhamidipati | 73d7af0 | 2016-03-24 12:27:56 +0530 | [diff] [blame] | 1902 | id = set_eap_common(dut, conn, ifname, 1, cmd); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1903 | if (id < 0) |
| 1904 | return id; |
| 1905 | |
| 1906 | if (set_network(ifname, id, "eap", "TTLS") < 0) { |
| 1907 | send_resp(dut, conn, SIGMA_ERROR, |
| 1908 | "errorCode,Failed to set TTLS method"); |
| 1909 | return 0; |
| 1910 | } |
| 1911 | |
| 1912 | if (set_network_quoted(ifname, id, "phase2", "auth=MSCHAPV2") < 0) { |
| 1913 | send_resp(dut, conn, SIGMA_ERROR, |
| 1914 | "errorCode,Failed to set MSCHAPv2 for TTLS Phase 2"); |
| 1915 | return 0; |
| 1916 | } |
| 1917 | |
| 1918 | return 1; |
| 1919 | } |
| 1920 | |
| 1921 | |
| 1922 | static int cmd_sta_set_eapsim(struct sigma_dut *dut, struct sigma_conn *conn, |
| 1923 | struct sigma_cmd *cmd) |
| 1924 | { |
| 1925 | const char *intf = get_param(cmd, "Interface"); |
| 1926 | const char *ifname; |
| 1927 | int id; |
| 1928 | |
| 1929 | if (intf == NULL) |
| 1930 | return -1; |
| 1931 | |
| 1932 | if (strcmp(intf, get_main_ifname()) == 0) |
| 1933 | ifname = get_station_ifname(); |
| 1934 | else |
| 1935 | ifname = intf; |
| 1936 | |
Bala Krishna Bhamidipati | 73d7af0 | 2016-03-24 12:27:56 +0530 | [diff] [blame] | 1937 | id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1938 | if (id < 0) |
| 1939 | return id; |
| 1940 | |
| 1941 | if (set_network(ifname, id, "eap", "SIM") < 0) |
| 1942 | return -2; |
| 1943 | |
| 1944 | return 1; |
| 1945 | } |
| 1946 | |
| 1947 | |
| 1948 | static int cmd_sta_set_peap(struct sigma_dut *dut, struct sigma_conn *conn, |
| 1949 | struct sigma_cmd *cmd) |
| 1950 | { |
| 1951 | const char *intf = get_param(cmd, "Interface"); |
| 1952 | const char *ifname, *val; |
| 1953 | int id; |
| 1954 | char buf[100]; |
| 1955 | |
| 1956 | if (intf == NULL) |
| 1957 | return -1; |
| 1958 | |
| 1959 | if (strcmp(intf, get_main_ifname()) == 0) |
| 1960 | ifname = get_station_ifname(); |
| 1961 | else |
| 1962 | ifname = intf; |
| 1963 | |
Bala Krishna Bhamidipati | 73d7af0 | 2016-03-24 12:27:56 +0530 | [diff] [blame] | 1964 | id = set_eap_common(dut, conn, ifname, 1, cmd); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1965 | if (id < 0) |
| 1966 | return id; |
| 1967 | |
| 1968 | if (set_network(ifname, id, "eap", "PEAP") < 0) |
| 1969 | return -2; |
| 1970 | |
| 1971 | val = get_param(cmd, "innerEAP"); |
| 1972 | if (val) { |
| 1973 | if (strcasecmp(val, "MSCHAPv2") == 0) { |
| 1974 | if (set_network_quoted(ifname, id, "phase2", |
| 1975 | "auth=MSCHAPV2") < 0) |
| 1976 | return -2; |
| 1977 | } else if (strcasecmp(val, "GTC") == 0) { |
| 1978 | if (set_network_quoted(ifname, id, "phase2", |
| 1979 | "auth=GTC") < 0) |
| 1980 | return -2; |
| 1981 | } else |
| 1982 | return -1; |
| 1983 | } |
| 1984 | |
| 1985 | val = get_param(cmd, "peapVersion"); |
| 1986 | if (val) { |
| 1987 | int ver = atoi(val); |
| 1988 | if (ver < 0 || ver > 1) |
| 1989 | return -1; |
| 1990 | snprintf(buf, sizeof(buf), "peapver=%d", ver); |
| 1991 | if (set_network_quoted(ifname, id, "phase1", buf) < 0) |
| 1992 | return -2; |
| 1993 | } |
| 1994 | |
| 1995 | return 1; |
| 1996 | } |
| 1997 | |
| 1998 | |
| 1999 | static int cmd_sta_set_eapfast(struct sigma_dut *dut, struct sigma_conn *conn, |
| 2000 | struct sigma_cmd *cmd) |
| 2001 | { |
| 2002 | const char *intf = get_param(cmd, "Interface"); |
| 2003 | const char *ifname, *val; |
| 2004 | int id; |
| 2005 | char buf[100]; |
| 2006 | |
| 2007 | if (intf == NULL) |
| 2008 | return -1; |
| 2009 | |
| 2010 | if (strcmp(intf, get_main_ifname()) == 0) |
| 2011 | ifname = get_station_ifname(); |
| 2012 | else |
| 2013 | ifname = intf; |
| 2014 | |
Bala Krishna Bhamidipati | 73d7af0 | 2016-03-24 12:27:56 +0530 | [diff] [blame] | 2015 | id = set_eap_common(dut, conn, ifname, 1, cmd); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2016 | if (id < 0) |
| 2017 | return id; |
| 2018 | |
| 2019 | if (set_network(ifname, id, "eap", "FAST") < 0) |
| 2020 | return -2; |
| 2021 | |
| 2022 | val = get_param(cmd, "innerEAP"); |
| 2023 | if (val) { |
| 2024 | if (strcasecmp(val, "MSCHAPV2") == 0) { |
| 2025 | if (set_network_quoted(ifname, id, "phase2", |
| 2026 | "auth=MSCHAPV2") < 0) |
| 2027 | return -2; |
| 2028 | } else if (strcasecmp(val, "GTC") == 0) { |
| 2029 | if (set_network_quoted(ifname, id, "phase2", |
| 2030 | "auth=GTC") < 0) |
| 2031 | return -2; |
| 2032 | } else |
| 2033 | return -1; |
| 2034 | } |
| 2035 | |
| 2036 | val = get_param(cmd, "validateServer"); |
| 2037 | if (val) { |
| 2038 | /* TODO */ |
| 2039 | sigma_dut_print(dut, DUT_MSG_INFO, "Ignored EAP-FAST " |
| 2040 | "validateServer=%s", val); |
| 2041 | } |
| 2042 | |
| 2043 | val = get_param(cmd, "pacFile"); |
| 2044 | if (val) { |
| 2045 | snprintf(buf, sizeof(buf), "blob://%s", val); |
| 2046 | if (set_network_quoted(ifname, id, "pac_file", buf) < 0) |
| 2047 | return -2; |
| 2048 | } |
| 2049 | |
| 2050 | if (set_network_quoted(ifname, id, "phase1", "fast_provisioning=2") < |
| 2051 | 0) |
| 2052 | return -2; |
| 2053 | |
| 2054 | return 1; |
| 2055 | } |
| 2056 | |
| 2057 | |
| 2058 | static int cmd_sta_set_eapaka(struct sigma_dut *dut, struct sigma_conn *conn, |
| 2059 | struct sigma_cmd *cmd) |
| 2060 | { |
| 2061 | const char *intf = get_param(cmd, "Interface"); |
| 2062 | const char *ifname; |
| 2063 | int id; |
| 2064 | |
| 2065 | if (intf == NULL) |
| 2066 | return -1; |
| 2067 | |
| 2068 | if (strcmp(intf, get_main_ifname()) == 0) |
| 2069 | ifname = get_station_ifname(); |
| 2070 | else |
| 2071 | ifname = intf; |
| 2072 | |
Bala Krishna Bhamidipati | 73d7af0 | 2016-03-24 12:27:56 +0530 | [diff] [blame] | 2073 | id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2074 | if (id < 0) |
| 2075 | return id; |
| 2076 | |
| 2077 | if (set_network(ifname, id, "eap", "AKA") < 0) |
| 2078 | return -2; |
| 2079 | |
| 2080 | return 1; |
| 2081 | } |
| 2082 | |
| 2083 | |
| 2084 | static int cmd_sta_set_eapakaprime(struct sigma_dut *dut, |
| 2085 | struct sigma_conn *conn, |
| 2086 | struct sigma_cmd *cmd) |
| 2087 | { |
| 2088 | const char *intf = get_param(cmd, "Interface"); |
| 2089 | const char *ifname; |
| 2090 | int id; |
| 2091 | |
| 2092 | if (intf == NULL) |
| 2093 | return -1; |
| 2094 | |
| 2095 | if (strcmp(intf, get_main_ifname()) == 0) |
| 2096 | ifname = get_station_ifname(); |
| 2097 | else |
| 2098 | ifname = intf; |
| 2099 | |
Bala Krishna Bhamidipati | 73d7af0 | 2016-03-24 12:27:56 +0530 | [diff] [blame] | 2100 | id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2101 | if (id < 0) |
| 2102 | return id; |
| 2103 | |
| 2104 | if (set_network(ifname, id, "eap", "AKA'") < 0) |
| 2105 | return -2; |
| 2106 | |
| 2107 | return 1; |
| 2108 | } |
| 2109 | |
| 2110 | |
| 2111 | static int sta_set_open(struct sigma_dut *dut, struct sigma_conn *conn, |
| 2112 | struct sigma_cmd *cmd) |
| 2113 | { |
| 2114 | const char *intf = get_param(cmd, "Interface"); |
| 2115 | const char *ifname; |
| 2116 | int id; |
| 2117 | |
| 2118 | if (strcmp(intf, get_main_ifname()) == 0) |
| 2119 | ifname = get_station_ifname(); |
| 2120 | else |
| 2121 | ifname = intf; |
| 2122 | |
| 2123 | id = add_network_common(dut, conn, ifname, cmd); |
| 2124 | if (id < 0) |
| 2125 | return id; |
| 2126 | |
| 2127 | if (set_network(ifname, id, "key_mgmt", "NONE") < 0) |
| 2128 | return -2; |
| 2129 | |
| 2130 | return 1; |
| 2131 | } |
| 2132 | |
| 2133 | |
Jouni Malinen | 47dcc95 | 2017-10-09 16:43:24 +0300 | [diff] [blame] | 2134 | static int sta_set_owe(struct sigma_dut *dut, struct sigma_conn *conn, |
| 2135 | struct sigma_cmd *cmd) |
| 2136 | { |
| 2137 | const char *intf = get_param(cmd, "Interface"); |
| 2138 | const char *ifname, *val; |
| 2139 | int id; |
| 2140 | |
| 2141 | if (intf == NULL) |
| 2142 | return -1; |
| 2143 | |
| 2144 | if (strcmp(intf, get_main_ifname()) == 0) |
| 2145 | ifname = get_station_ifname(); |
| 2146 | else |
| 2147 | ifname = intf; |
| 2148 | |
| 2149 | id = set_wpa_common(dut, conn, ifname, cmd); |
| 2150 | if (id < 0) |
| 2151 | return id; |
| 2152 | |
| 2153 | if (set_network(ifname, id, "key_mgmt", "OWE") < 0) |
| 2154 | return -2; |
| 2155 | |
| 2156 | val = get_param(cmd, "ECGroupID"); |
Jouni Malinen | fac9cad | 2017-10-10 18:35:55 +0300 | [diff] [blame] | 2157 | if (val && strcmp(val, "0") == 0) { |
| 2158 | if (wpa_command(ifname, |
| 2159 | "VENDOR_ELEM_ADD 13 ff23200000783590fb7440e03d5b3b33911f86affdcc6b4411b707846ac4ff08ddc8831ccd") != 0) { |
| 2160 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 2161 | "Failed to set OWE DH Param element override"); |
| 2162 | return -2; |
| 2163 | } |
| 2164 | } else if (val && set_network(ifname, id, "owe_group", val) < 0) { |
Jouni Malinen | 47dcc95 | 2017-10-09 16:43:24 +0300 | [diff] [blame] | 2165 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 2166 | "Failed to clear owe_group"); |
| 2167 | return -2; |
| 2168 | } |
| 2169 | |
| 2170 | return 1; |
| 2171 | } |
| 2172 | |
| 2173 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2174 | static int cmd_sta_set_security(struct sigma_dut *dut, struct sigma_conn *conn, |
| 2175 | struct sigma_cmd *cmd) |
| 2176 | { |
| 2177 | const char *type = get_param(cmd, "Type"); |
| 2178 | |
| 2179 | if (type == NULL) { |
| 2180 | send_resp(dut, conn, SIGMA_ERROR, |
| 2181 | "ErrorCode,Missing Type argument"); |
| 2182 | return 0; |
| 2183 | } |
| 2184 | |
| 2185 | if (strcasecmp(type, "OPEN") == 0) |
| 2186 | return sta_set_open(dut, conn, cmd); |
Jouni Malinen | 47dcc95 | 2017-10-09 16:43:24 +0300 | [diff] [blame] | 2187 | if (strcasecmp(type, "OWE") == 0) |
| 2188 | return sta_set_owe(dut, conn, cmd); |
Jouni Malinen | 992a81e | 2017-08-22 13:57:47 +0300 | [diff] [blame] | 2189 | if (strcasecmp(type, "PSK") == 0 || |
Jouni Malinen | 0ab50f4 | 2017-08-31 01:34:59 +0300 | [diff] [blame] | 2190 | strcasecmp(type, "PSK-SAE") == 0 || |
Jouni Malinen | 992a81e | 2017-08-22 13:57:47 +0300 | [diff] [blame] | 2191 | strcasecmp(type, "SAE") == 0) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2192 | return cmd_sta_set_psk(dut, conn, cmd); |
| 2193 | if (strcasecmp(type, "EAPTLS") == 0) |
| 2194 | return cmd_sta_set_eaptls(dut, conn, cmd); |
| 2195 | if (strcasecmp(type, "EAPTTLS") == 0) |
| 2196 | return cmd_sta_set_eapttls(dut, conn, cmd); |
| 2197 | if (strcasecmp(type, "EAPPEAP") == 0) |
| 2198 | return cmd_sta_set_peap(dut, conn, cmd); |
| 2199 | if (strcasecmp(type, "EAPSIM") == 0) |
| 2200 | return cmd_sta_set_eapsim(dut, conn, cmd); |
| 2201 | if (strcasecmp(type, "EAPFAST") == 0) |
| 2202 | return cmd_sta_set_eapfast(dut, conn, cmd); |
| 2203 | if (strcasecmp(type, "EAPAKA") == 0) |
| 2204 | return cmd_sta_set_eapaka(dut, conn, cmd); |
| 2205 | if (strcasecmp(type, "EAPAKAPRIME") == 0) |
| 2206 | return cmd_sta_set_eapakaprime(dut, conn, cmd); |
| 2207 | |
| 2208 | send_resp(dut, conn, SIGMA_ERROR, |
| 2209 | "ErrorCode,Unsupported Type value"); |
| 2210 | return 0; |
| 2211 | } |
| 2212 | |
| 2213 | |
| 2214 | int ath6kl_client_uapsd(struct sigma_dut *dut, const char *intf, int uapsd) |
| 2215 | { |
| 2216 | #ifdef __linux__ |
| 2217 | /* special handling for ath6kl */ |
| 2218 | char path[128], fname[128], *pos; |
| 2219 | ssize_t res; |
| 2220 | FILE *f; |
| 2221 | |
| 2222 | snprintf(path, sizeof(path), "/sys/class/net/%s/phy80211", intf); |
| 2223 | res = readlink(path, path, sizeof(path)); |
| 2224 | if (res < 0) |
| 2225 | return 0; /* not ath6kl */ |
| 2226 | |
| 2227 | if (res >= (int) sizeof(path)) |
| 2228 | res = sizeof(path) - 1; |
| 2229 | path[res] = '\0'; |
| 2230 | pos = strrchr(path, '/'); |
| 2231 | if (pos == NULL) |
| 2232 | pos = path; |
| 2233 | else |
| 2234 | pos++; |
| 2235 | snprintf(fname, sizeof(fname), |
| 2236 | "/sys/kernel/debug/ieee80211/%s/ath6kl/" |
| 2237 | "create_qos", pos); |
| 2238 | if (!file_exists(fname)) |
| 2239 | return 0; /* not ath6kl */ |
| 2240 | |
| 2241 | if (uapsd) { |
| 2242 | f = fopen(fname, "w"); |
| 2243 | if (f == NULL) |
| 2244 | return -1; |
| 2245 | |
| 2246 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl create_qos"); |
| 2247 | fprintf(f, "4 2 2 1 2 9999999 9999999 9999999 7777777 0 4 " |
| 2248 | "45000 200 56789000 56789000 5678900 0 0 9999999 " |
| 2249 | "20000 0\n"); |
| 2250 | fclose(f); |
| 2251 | } else { |
| 2252 | snprintf(fname, sizeof(fname), |
| 2253 | "/sys/kernel/debug/ieee80211/%s/ath6kl/" |
| 2254 | "delete_qos", pos); |
| 2255 | |
| 2256 | f = fopen(fname, "w"); |
| 2257 | if (f == NULL) |
| 2258 | return -1; |
| 2259 | |
| 2260 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl delete_qos"); |
| 2261 | fprintf(f, "2 4\n"); |
| 2262 | fclose(f); |
| 2263 | } |
| 2264 | #endif /* __linux__ */ |
| 2265 | |
| 2266 | return 0; |
| 2267 | } |
| 2268 | |
| 2269 | |
| 2270 | static int cmd_sta_set_uapsd(struct sigma_dut *dut, struct sigma_conn *conn, |
| 2271 | struct sigma_cmd *cmd) |
| 2272 | { |
| 2273 | const char *intf = get_param(cmd, "Interface"); |
| 2274 | /* const char *ssid = get_param(cmd, "ssid"); */ |
| 2275 | const char *val; |
| 2276 | int max_sp_len = 4; |
| 2277 | int ac_be = 1, ac_bk = 1, ac_vi = 1, ac_vo = 1; |
| 2278 | char buf[100]; |
| 2279 | int ret1, ret2; |
| 2280 | |
| 2281 | val = get_param(cmd, "maxSPLength"); |
| 2282 | if (val) { |
| 2283 | max_sp_len = atoi(val); |
| 2284 | if (max_sp_len != 0 && max_sp_len != 1 && max_sp_len != 2 && |
| 2285 | max_sp_len != 4) |
| 2286 | return -1; |
| 2287 | } |
| 2288 | |
| 2289 | val = get_param(cmd, "acBE"); |
| 2290 | if (val) |
| 2291 | ac_be = atoi(val); |
| 2292 | |
| 2293 | val = get_param(cmd, "acBK"); |
| 2294 | if (val) |
| 2295 | ac_bk = atoi(val); |
| 2296 | |
| 2297 | val = get_param(cmd, "acVI"); |
| 2298 | if (val) |
| 2299 | ac_vi = atoi(val); |
| 2300 | |
| 2301 | val = get_param(cmd, "acVO"); |
| 2302 | if (val) |
| 2303 | ac_vo = atoi(val); |
| 2304 | |
| 2305 | dut->client_uapsd = ac_be || ac_bk || ac_vi || ac_vo; |
| 2306 | |
| 2307 | snprintf(buf, sizeof(buf), "P2P_SET client_apsd %d,%d,%d,%d;%d", |
| 2308 | ac_be, ac_bk, ac_vi, ac_vo, max_sp_len); |
| 2309 | ret1 = wpa_command(intf, buf); |
| 2310 | |
| 2311 | snprintf(buf, sizeof(buf), "SET uapsd %d,%d,%d,%d;%d", |
| 2312 | ac_be, ac_bk, ac_vi, ac_vo, max_sp_len); |
| 2313 | ret2 = wpa_command(intf, buf); |
| 2314 | |
| 2315 | if (ret1 && ret2) { |
| 2316 | sigma_dut_print(dut, DUT_MSG_INFO, "Failed to set client mode " |
| 2317 | "UAPSD parameters."); |
| 2318 | return -2; |
| 2319 | } |
| 2320 | |
| 2321 | if (ath6kl_client_uapsd(dut, intf, dut->client_uapsd) < 0) { |
| 2322 | send_resp(dut, conn, SIGMA_ERROR, |
| 2323 | "ErrorCode,Failed to set ath6kl QoS parameters"); |
| 2324 | return 0; |
| 2325 | } |
| 2326 | |
| 2327 | return 1; |
| 2328 | } |
| 2329 | |
| 2330 | |
| 2331 | static int cmd_sta_set_wmm(struct sigma_dut *dut, struct sigma_conn *conn, |
| 2332 | struct sigma_cmd *cmd) |
| 2333 | { |
| 2334 | char buf[1000]; |
| 2335 | const char *intf = get_param(cmd, "Interface"); |
| 2336 | const char *grp = get_param(cmd, "Group"); |
| 2337 | const char *act = get_param(cmd, "Action"); |
| 2338 | const char *tid = get_param(cmd, "Tid"); |
| 2339 | const char *dir = get_param(cmd, "Direction"); |
| 2340 | const char *psb = get_param(cmd, "Psb"); |
| 2341 | const char *up = get_param(cmd, "Up"); |
| 2342 | const char *fixed = get_param(cmd, "Fixed"); |
| 2343 | const char *size = get_param(cmd, "Size"); |
| 2344 | const char *msize = get_param(cmd, "Maxsize"); |
| 2345 | const char *minsi = get_param(cmd, "Min_srvc_intrvl"); |
| 2346 | const char *maxsi = get_param(cmd, "Max_srvc_intrvl"); |
| 2347 | const char *inact = get_param(cmd, "Inactivity"); |
| 2348 | const char *sus = get_param(cmd, "Suspension"); |
| 2349 | const char *mindr = get_param(cmd, "Mindatarate"); |
| 2350 | const char *meandr = get_param(cmd, "Meandatarate"); |
| 2351 | const char *peakdr = get_param(cmd, "Peakdatarate"); |
| 2352 | const char *phyrate = get_param(cmd, "Phyrate"); |
| 2353 | const char *burstsize = get_param(cmd, "Burstsize"); |
| 2354 | const char *sba = get_param(cmd, "Sba"); |
| 2355 | int direction; |
| 2356 | int handle; |
Peng Xu | 9331962 | 2017-10-04 17:58:16 -0700 | [diff] [blame] | 2357 | float sba_fv = 0; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2358 | int fixed_int; |
| 2359 | int psb_ts; |
| 2360 | |
| 2361 | if (intf == NULL || grp == NULL || act == NULL ) |
| 2362 | return -1; |
| 2363 | |
| 2364 | if (strcasecmp(act, "addts") == 0) { |
| 2365 | if (tid == NULL || dir == NULL || psb == NULL || |
| 2366 | up == NULL || fixed == NULL || size == NULL) |
| 2367 | return -1; |
| 2368 | |
| 2369 | /* |
| 2370 | * Note: Sigma CAPI spec lists uplink, downlink, and bidi as the |
| 2371 | * possible values, but WMM-AC and V-E test scripts use "UP, |
| 2372 | * "DOWN", and "BIDI". |
| 2373 | */ |
| 2374 | if (strcasecmp(dir, "uplink") == 0 || |
| 2375 | strcasecmp(dir, "up") == 0) { |
| 2376 | direction = 0; |
| 2377 | } else if (strcasecmp(dir, "downlink") == 0 || |
| 2378 | strcasecmp(dir, "down") == 0) { |
| 2379 | direction = 1; |
| 2380 | } else if (strcasecmp(dir, "bidi") == 0) { |
| 2381 | direction = 2; |
| 2382 | } else { |
| 2383 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 2384 | "Direction %s not supported", dir); |
| 2385 | return -1; |
| 2386 | } |
| 2387 | |
| 2388 | if (strcasecmp(psb, "legacy") == 0) { |
| 2389 | psb_ts = 0; |
| 2390 | } else if (strcasecmp(psb, "uapsd") == 0) { |
| 2391 | psb_ts = 1; |
| 2392 | } else { |
| 2393 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 2394 | "PSB %s not supported", psb); |
| 2395 | return -1; |
| 2396 | } |
| 2397 | |
| 2398 | if (atoi(tid) < 0 || atoi(tid) > 7) { |
| 2399 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 2400 | "TID %s not supported", tid); |
| 2401 | return -1; |
| 2402 | } |
| 2403 | |
| 2404 | if (strcasecmp(fixed, "true") == 0) { |
| 2405 | fixed_int = 1; |
| 2406 | } else { |
| 2407 | fixed_int = 0; |
| 2408 | } |
| 2409 | |
Peng Xu | 9331962 | 2017-10-04 17:58:16 -0700 | [diff] [blame] | 2410 | if (sba) |
| 2411 | sba_fv = atof(sba); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2412 | |
| 2413 | dut->dialog_token++; |
| 2414 | handle = 7000 + dut->dialog_token; |
| 2415 | |
| 2416 | /* |
| 2417 | * size: convert to hex |
| 2418 | * maxsi: convert to hex |
| 2419 | * mindr: convert to hex |
| 2420 | * meandr: convert to hex |
| 2421 | * peakdr: convert to hex |
| 2422 | * burstsize: convert to hex |
| 2423 | * phyrate: convert to hex |
| 2424 | * sba: convert to hex with modification |
| 2425 | * minsi: convert to integer |
| 2426 | * sus: convert to integer |
| 2427 | * inact: convert to integer |
| 2428 | * maxsi: convert to integer |
| 2429 | */ |
| 2430 | |
| 2431 | /* |
| 2432 | * The Nominal MSDU Size field is 2 octets long and contains an |
| 2433 | * unsigned integer that specifies the nominal size, in octets, |
| 2434 | * of MSDUs belonging to the traffic under this traffic |
| 2435 | * specification and is defined in Figure 16. If the Fixed |
| 2436 | * subfield is set to 1, then the size of the MSDU is fixed and |
| 2437 | * is indicated by the Size Subfield. If the Fixed subfield is |
| 2438 | * set to 0, then the size of the MSDU might not be fixed and |
| 2439 | * the Size indicates the nominal MSDU size. |
| 2440 | * |
| 2441 | * The Surplus Bandwidth Allowance Factor field is 2 octets long |
| 2442 | * and specifies the excess allocation of time (and bandwidth) |
| 2443 | * over and above the stated rates required to transport an MSDU |
| 2444 | * belonging to the traffic in this TSPEC. This field is |
| 2445 | * represented as an unsigned binary number with an implicit |
| 2446 | * binary point after the leftmost 3 bits. For example, an SBA |
| 2447 | * of 1.75 is represented as 0x3800. This field is included to |
| 2448 | * account for retransmissions. As such, the value of this field |
| 2449 | * must be greater than unity. |
| 2450 | */ |
| 2451 | |
| 2452 | snprintf(buf, sizeof(buf), |
| 2453 | "iwpriv %s addTspec %d %s %d %d %s 0x%X" |
| 2454 | " 0x%X 0x%X 0x%X" |
| 2455 | " 0x%X 0x%X 0x%X" |
| 2456 | " 0x%X %d %d %d %d" |
| 2457 | " %d %d", |
| 2458 | intf, handle, tid, direction, psb_ts, up, |
| 2459 | (unsigned int) ((fixed_int << 15) | atoi(size)), |
| 2460 | msize ? atoi(msize) : 0, |
| 2461 | mindr ? atoi(mindr) : 0, |
| 2462 | meandr ? atoi(meandr) : 0, |
| 2463 | peakdr ? atoi(peakdr) : 0, |
| 2464 | burstsize ? atoi(burstsize) : 0, |
| 2465 | phyrate ? atoi(phyrate) : 0, |
| 2466 | sba ? ((unsigned int) (((int) sba_fv << 13) | |
| 2467 | (int)((sba_fv - (int) sba_fv) * |
| 2468 | 8192))) : 0, |
| 2469 | minsi ? atoi(minsi) : 0, |
| 2470 | sus ? atoi(sus) : 0, |
| 2471 | 0, 0, |
| 2472 | inact ? atoi(inact) : 0, |
| 2473 | maxsi ? atoi(maxsi) : 0); |
| 2474 | |
| 2475 | if (system(buf) != 0) { |
| 2476 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 2477 | "iwpriv addtspec request failed"); |
| 2478 | send_resp(dut, conn, SIGMA_ERROR, |
| 2479 | "errorCode,Failed to execute addTspec command"); |
| 2480 | return 0; |
| 2481 | } |
| 2482 | |
| 2483 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 2484 | "iwpriv addtspec request send"); |
| 2485 | |
| 2486 | /* Mapping handle to a TID */ |
| 2487 | dut->tid_to_handle[atoi(tid)] = handle; |
| 2488 | } else if (strcasecmp(act, "delts") == 0) { |
| 2489 | if (tid == NULL) |
| 2490 | return -1; |
| 2491 | |
| 2492 | if (atoi(tid) < 0 || atoi(tid) > 7) { |
| 2493 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 2494 | "TID %s not supported", tid); |
| 2495 | send_resp(dut, conn, SIGMA_ERROR, |
| 2496 | "errorCode,Unsupported TID"); |
| 2497 | return 0; |
| 2498 | } |
| 2499 | |
| 2500 | handle = dut->tid_to_handle[atoi(tid)]; |
| 2501 | |
| 2502 | if (handle < 7000 || handle > 7255) { |
| 2503 | /* Invalid handle ie no mapping for that TID */ |
| 2504 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 2505 | "handle-> %d not found", handle); |
| 2506 | } |
| 2507 | |
| 2508 | snprintf(buf, sizeof(buf), "iwpriv %s delTspec %d", |
| 2509 | intf, handle); |
| 2510 | |
| 2511 | if (system(buf) != 0) { |
| 2512 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 2513 | "iwpriv deltspec request failed"); |
| 2514 | send_resp(dut, conn, SIGMA_ERROR, |
| 2515 | "errorCode,Failed to execute delTspec command"); |
| 2516 | return 0; |
| 2517 | } |
| 2518 | |
| 2519 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 2520 | "iwpriv deltspec request send"); |
| 2521 | |
| 2522 | dut->tid_to_handle[atoi(tid)] = 0; |
| 2523 | } else { |
| 2524 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 2525 | "Action type %s not supported", act); |
| 2526 | send_resp(dut, conn, SIGMA_ERROR, |
| 2527 | "errorCode,Unsupported Action"); |
| 2528 | return 0; |
| 2529 | } |
| 2530 | |
| 2531 | return 1; |
| 2532 | } |
| 2533 | |
| 2534 | |
vamsi krishna | 52e16f9 | 2017-08-29 12:37:34 +0530 | [diff] [blame] | 2535 | static int find_network(struct sigma_dut *dut, const char *ssid) |
| 2536 | { |
| 2537 | char list[4096]; |
| 2538 | char *pos; |
| 2539 | |
| 2540 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 2541 | "Search for profile based on SSID: '%s'", ssid); |
| 2542 | if (wpa_command_resp(get_station_ifname(), "LIST_NETWORKS", |
| 2543 | list, sizeof(list)) < 0) |
| 2544 | return -1; |
| 2545 | pos = strstr(list, ssid); |
| 2546 | if (!pos || pos == list || pos[-1] != '\t' || pos[strlen(ssid)] != '\t') |
| 2547 | return -1; |
| 2548 | |
| 2549 | while (pos > list && pos[-1] != '\n') |
| 2550 | pos--; |
| 2551 | dut->infra_network_id = atoi(pos); |
| 2552 | snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid); |
| 2553 | return 0; |
| 2554 | } |
| 2555 | |
| 2556 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2557 | static int cmd_sta_associate(struct sigma_dut *dut, struct sigma_conn *conn, |
| 2558 | struct sigma_cmd *cmd) |
| 2559 | { |
| 2560 | /* const char *intf = get_param(cmd, "Interface"); */ |
| 2561 | const char *ssid = get_param(cmd, "ssid"); |
| 2562 | const char *wps_param = get_param(cmd, "WPS"); |
| 2563 | const char *bssid = get_param(cmd, "bssid"); |
Jouni Malinen | 46a19b6 | 2017-06-23 14:31:27 +0300 | [diff] [blame] | 2564 | const char *chan = get_param(cmd, "channel"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2565 | int wps = 0; |
Jouni Malinen | 3c367e8 | 2017-06-23 17:01:47 +0300 | [diff] [blame] | 2566 | char buf[1000], extra[50]; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2567 | |
| 2568 | if (ssid == NULL) |
| 2569 | return -1; |
| 2570 | |
Jouni Malinen | 3c367e8 | 2017-06-23 17:01:47 +0300 | [diff] [blame] | 2571 | if (dut->rsne_override) { |
| 2572 | snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s", |
| 2573 | dut->rsne_override); |
| 2574 | if (wpa_command(get_station_ifname(), buf) < 0) { |
| 2575 | send_resp(dut, conn, SIGMA_ERROR, |
| 2576 | "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override"); |
| 2577 | return 0; |
| 2578 | } |
| 2579 | } |
| 2580 | |
Jouni Malinen | 6814313 | 2017-09-02 02:34:08 +0300 | [diff] [blame] | 2581 | if (dut->sae_commit_override) { |
| 2582 | snprintf(buf, sizeof(buf), "SET sae_commit_override %s", |
| 2583 | dut->sae_commit_override); |
| 2584 | if (wpa_command(get_station_ifname(), buf) < 0) { |
| 2585 | send_resp(dut, conn, SIGMA_ERROR, |
| 2586 | "ErrorCode,Failed to set SAE commit override"); |
| 2587 | return 0; |
| 2588 | } |
| 2589 | } |
| 2590 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2591 | if (wps_param && |
| 2592 | (strcmp(wps_param, "1") == 0 || strcasecmp(wps_param, "On") == 0)) |
| 2593 | wps = 1; |
| 2594 | |
| 2595 | if (wps) { |
| 2596 | if (dut->wps_method == WFA_CS_WPS_NOT_READY) { |
| 2597 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,WPS " |
| 2598 | "parameters not yet set"); |
| 2599 | return 0; |
| 2600 | } |
| 2601 | if (dut->wps_method == WFA_CS_WPS_PBC) { |
| 2602 | if (wpa_command(get_station_ifname(), "WPS_PBC") < 0) |
| 2603 | return -2; |
| 2604 | } else { |
| 2605 | snprintf(buf, sizeof(buf), "WPS_PIN any %s", |
| 2606 | dut->wps_pin); |
| 2607 | if (wpa_command(get_station_ifname(), buf) < 0) |
| 2608 | return -2; |
| 2609 | } |
| 2610 | } else { |
vamsi krishna | 52e16f9 | 2017-08-29 12:37:34 +0530 | [diff] [blame] | 2611 | if (strcmp(ssid, dut->infra_ssid) == 0) { |
| 2612 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 2613 | "sta_associate for the most recently added network"); |
| 2614 | } else if (find_network(dut, ssid) < 0) { |
| 2615 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 2616 | "sta_associate for a previously stored network profile"); |
| 2617 | send_resp(dut, conn, SIGMA_ERROR, |
| 2618 | "ErrorCode,Profile not found"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2619 | return 0; |
| 2620 | } |
| 2621 | |
| 2622 | if (bssid && |
| 2623 | set_network(get_station_ifname(), dut->infra_network_id, |
| 2624 | "bssid", bssid) < 0) { |
| 2625 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode," |
| 2626 | "Invalid bssid argument"); |
| 2627 | return 0; |
| 2628 | } |
| 2629 | |
Jouni Malinen | 46a19b6 | 2017-06-23 14:31:27 +0300 | [diff] [blame] | 2630 | extra[0] = '\0'; |
| 2631 | if (chan) |
| 2632 | snprintf(extra, sizeof(extra), " freq=%u", |
| 2633 | channel_to_freq(atoi(chan))); |
| 2634 | snprintf(buf, sizeof(buf), "SELECT_NETWORK %d%s", |
| 2635 | dut->infra_network_id, extra); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2636 | if (wpa_command(get_station_ifname(), buf) < 0) { |
| 2637 | sigma_dut_print(dut, DUT_MSG_INFO, "Failed to select " |
| 2638 | "network id %d on %s", |
| 2639 | dut->infra_network_id, |
| 2640 | get_station_ifname()); |
| 2641 | return -2; |
| 2642 | } |
| 2643 | } |
| 2644 | |
| 2645 | return 1; |
| 2646 | } |
| 2647 | |
| 2648 | |
| 2649 | static int run_hs20_osu(struct sigma_dut *dut, const char *params) |
| 2650 | { |
| 2651 | char buf[500], cmd[200]; |
| 2652 | int res; |
| 2653 | |
| 2654 | /* Use hs20-osu-client file at the current dir, if found; otherwise use |
| 2655 | * default path */ |
| 2656 | res = snprintf(cmd, sizeof(cmd), |
| 2657 | "%s -w \"%s\" -r hs20-osu-client.res %s%s -dddKt -f Logs/hs20-osu-client.txt", |
| 2658 | file_exists("./hs20-osu-client") ? |
| 2659 | "./hs20-osu-client" : "hs20-osu-client", |
| 2660 | sigma_wpas_ctrl, |
| 2661 | dut->summary_log ? "-s " : "", |
| 2662 | dut->summary_log ? dut->summary_log : ""); |
| 2663 | if (res < 0 || res >= (int) sizeof(cmd)) |
| 2664 | return -1; |
| 2665 | |
| 2666 | res = snprintf(buf, sizeof(buf), "%s %s", cmd, params); |
| 2667 | if (res < 0 || res >= (int) sizeof(buf)) |
| 2668 | return -1; |
| 2669 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 2670 | |
| 2671 | if (system(buf) != 0) { |
| 2672 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run: %s", buf); |
| 2673 | return -1; |
| 2674 | } |
| 2675 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 2676 | "Completed hs20-osu-client operation"); |
| 2677 | |
| 2678 | return 0; |
| 2679 | } |
| 2680 | |
| 2681 | |
| 2682 | static int download_ppsmo(struct sigma_dut *dut, |
| 2683 | struct sigma_conn *conn, |
| 2684 | const char *intf, |
| 2685 | struct sigma_cmd *cmd) |
| 2686 | { |
| 2687 | const char *name, *path, *val; |
| 2688 | char url[500], buf[600], fbuf[100]; |
| 2689 | char *fqdn = NULL; |
| 2690 | |
| 2691 | name = get_param(cmd, "FileName"); |
| 2692 | path = get_param(cmd, "FilePath"); |
| 2693 | if (name == NULL || path == NULL) |
| 2694 | return -1; |
| 2695 | |
| 2696 | if (strcasecmp(path, "VendorSpecific") == 0) { |
| 2697 | snprintf(url, sizeof(url), "PPS/%s", name); |
| 2698 | sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured PPS MO " |
| 2699 | "from the device (%s)", url); |
| 2700 | if (!file_exists(url)) { |
| 2701 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested " |
| 2702 | "PPS MO file does not exist"); |
| 2703 | return 0; |
| 2704 | } |
| 2705 | snprintf(buf, sizeof(buf), "cp %s pps-tnds.xml", url); |
| 2706 | if (system(buf) != 0) { |
| 2707 | send_resp(dut, conn, SIGMA_ERROR, |
| 2708 | "errorCode,Failed to copy PPS MO"); |
| 2709 | return 0; |
| 2710 | } |
| 2711 | } else if (strncasecmp(path, "http:", 5) != 0 && |
| 2712 | strncasecmp(path, "https:", 6) != 0) { |
| 2713 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode," |
| 2714 | "Unsupported FilePath value"); |
| 2715 | return 0; |
| 2716 | } else { |
| 2717 | snprintf(url, sizeof(url), "%s/%s", path, name); |
| 2718 | sigma_dut_print(dut, DUT_MSG_INFO, "Downloading PPS MO from %s", |
| 2719 | url); |
| 2720 | snprintf(buf, sizeof(buf), "wget -T 10 -t 3 -O pps-tnds.xml '%s'", url); |
| 2721 | remove("pps-tnds.xml"); |
| 2722 | if (system(buf) != 0) { |
| 2723 | send_resp(dut, conn, SIGMA_ERROR, |
| 2724 | "errorCode,Failed to download PPS MO"); |
| 2725 | return 0; |
| 2726 | } |
| 2727 | } |
| 2728 | |
| 2729 | if (run_hs20_osu(dut, "from_tnds pps-tnds.xml pps.xml") < 0) { |
| 2730 | send_resp(dut, conn, SIGMA_ERROR, |
| 2731 | "errorCode,Failed to parse downloaded PPSMO"); |
| 2732 | return 0; |
| 2733 | } |
| 2734 | unlink("pps-tnds.xml"); |
| 2735 | |
| 2736 | val = get_param(cmd, "managementTreeURI"); |
| 2737 | if (val) { |
| 2738 | const char *pos, *end; |
| 2739 | sigma_dut_print(dut, DUT_MSG_DEBUG, "managementTreeURI: %s", |
| 2740 | val); |
| 2741 | if (strncmp(val, "./Wi-Fi/", 8) != 0) { |
| 2742 | send_resp(dut, conn, SIGMA_ERROR, |
| 2743 | "errorCode,Invalid managementTreeURI prefix"); |
| 2744 | return 0; |
| 2745 | } |
| 2746 | pos = val + 8; |
| 2747 | end = strchr(pos, '/'); |
| 2748 | if (end == NULL || |
| 2749 | strcmp(end, "/PerProviderSubscription") != 0) { |
| 2750 | send_resp(dut, conn, SIGMA_ERROR, |
| 2751 | "errorCode,Invalid managementTreeURI postfix"); |
| 2752 | return 0; |
| 2753 | } |
| 2754 | if (end - pos >= (int) sizeof(fbuf)) { |
| 2755 | send_resp(dut, conn, SIGMA_ERROR, |
| 2756 | "errorCode,Too long FQDN in managementTreeURI"); |
| 2757 | return 0; |
| 2758 | } |
| 2759 | memcpy(fbuf, pos, end - pos); |
| 2760 | fbuf[end - pos] = '\0'; |
| 2761 | fqdn = fbuf; |
| 2762 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 2763 | "FQDN from managementTreeURI: %s", fqdn); |
| 2764 | } else if (run_hs20_osu(dut, "get_fqdn pps.xml") == 0) { |
| 2765 | FILE *f = fopen("pps-fqdn", "r"); |
| 2766 | if (f) { |
| 2767 | if (fgets(fbuf, sizeof(fbuf), f)) { |
| 2768 | fbuf[sizeof(fbuf) - 1] = '\0'; |
| 2769 | fqdn = fbuf; |
| 2770 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 2771 | "Use FQDN %s", fqdn); |
| 2772 | } |
| 2773 | fclose(f); |
| 2774 | } |
| 2775 | } |
| 2776 | |
| 2777 | if (fqdn == NULL) { |
| 2778 | send_resp(dut, conn, SIGMA_ERROR, |
| 2779 | "errorCode,No FQDN specified"); |
| 2780 | return 0; |
| 2781 | } |
| 2782 | |
| 2783 | mkdir("SP", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); |
| 2784 | snprintf(buf, sizeof(buf), "SP/%s", fqdn); |
| 2785 | mkdir(buf, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); |
| 2786 | |
| 2787 | snprintf(buf, sizeof(buf), "SP/%s/pps.xml", fqdn); |
| 2788 | if (rename("pps.xml", buf) < 0) { |
| 2789 | send_resp(dut, conn, SIGMA_ERROR, |
| 2790 | "errorCode,Could not move PPS MO"); |
| 2791 | return 0; |
| 2792 | } |
| 2793 | |
| 2794 | if (strcasecmp(path, "VendorSpecific") == 0) { |
| 2795 | snprintf(buf, sizeof(buf), "cp Certs/ca.pem SP/%s/ca.pem", |
| 2796 | fqdn); |
| 2797 | if (system(buf)) { |
| 2798 | send_resp(dut, conn, SIGMA_ERROR, |
| 2799 | "errorCode,Failed to copy OSU CA cert"); |
| 2800 | return 0; |
| 2801 | } |
| 2802 | |
| 2803 | snprintf(buf, sizeof(buf), |
| 2804 | "cp Certs/aaa-ca.pem SP/%s/aaa-ca.pem", |
| 2805 | fqdn); |
| 2806 | if (system(buf)) { |
| 2807 | send_resp(dut, conn, SIGMA_ERROR, |
| 2808 | "errorCode,Failed to copy AAA CA cert"); |
| 2809 | return 0; |
| 2810 | } |
| 2811 | } else { |
| 2812 | snprintf(buf, sizeof(buf), |
| 2813 | "dl_osu_ca SP/%s/pps.xml SP/%s/ca.pem", |
| 2814 | fqdn, fqdn); |
| 2815 | if (run_hs20_osu(dut, buf) < 0) { |
| 2816 | send_resp(dut, conn, SIGMA_ERROR, |
| 2817 | "errorCode,Failed to download OSU CA cert"); |
| 2818 | return 0; |
| 2819 | } |
| 2820 | |
| 2821 | snprintf(buf, sizeof(buf), |
| 2822 | "dl_aaa_ca SP/%s/pps.xml SP/%s/aaa-ca.pem", |
| 2823 | fqdn, fqdn); |
| 2824 | if (run_hs20_osu(dut, buf) < 0) { |
| 2825 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 2826 | "Failed to download AAA CA cert"); |
| 2827 | } |
| 2828 | } |
| 2829 | |
| 2830 | if (file_exists("next-client-cert.pem")) { |
| 2831 | snprintf(buf, sizeof(buf), "SP/%s/client-cert.pem", fqdn); |
| 2832 | if (rename("next-client-cert.pem", buf) < 0) { |
| 2833 | send_resp(dut, conn, SIGMA_ERROR, |
| 2834 | "errorCode,Could not move client certificate"); |
| 2835 | return 0; |
| 2836 | } |
| 2837 | } |
| 2838 | |
| 2839 | if (file_exists("next-client-key.pem")) { |
| 2840 | snprintf(buf, sizeof(buf), "SP/%s/client-key.pem", fqdn); |
| 2841 | if (rename("next-client-key.pem", buf) < 0) { |
| 2842 | send_resp(dut, conn, SIGMA_ERROR, |
| 2843 | "errorCode,Could not move client key"); |
| 2844 | return 0; |
| 2845 | } |
| 2846 | } |
| 2847 | |
| 2848 | snprintf(buf, sizeof(buf), "set_pps SP/%s/pps.xml", fqdn); |
| 2849 | if (run_hs20_osu(dut, buf) < 0) { |
| 2850 | send_resp(dut, conn, SIGMA_ERROR, |
| 2851 | "errorCode,Failed to configure credential from " |
| 2852 | "PPSMO"); |
| 2853 | return 0; |
| 2854 | } |
| 2855 | |
| 2856 | return 1; |
| 2857 | } |
| 2858 | |
| 2859 | |
| 2860 | static int download_cert(struct sigma_dut *dut, |
| 2861 | struct sigma_conn *conn, |
| 2862 | const char *intf, |
| 2863 | struct sigma_cmd *cmd) |
| 2864 | { |
| 2865 | const char *name, *path; |
| 2866 | char url[500], buf[600]; |
| 2867 | |
| 2868 | name = get_param(cmd, "FileName"); |
| 2869 | path = get_param(cmd, "FilePath"); |
| 2870 | if (name == NULL || path == NULL) |
| 2871 | return -1; |
| 2872 | |
| 2873 | if (strcasecmp(path, "VendorSpecific") == 0) { |
| 2874 | snprintf(url, sizeof(url), "Certs/%s-cert.pem", name); |
| 2875 | sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client " |
| 2876 | "certificate from the device (%s)", url); |
| 2877 | if (!file_exists(url)) { |
| 2878 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested " |
| 2879 | "certificate file does not exist"); |
| 2880 | return 0; |
| 2881 | } |
| 2882 | snprintf(buf, sizeof(buf), "cp %s next-client-cert.pem", url); |
| 2883 | if (system(buf) != 0) { |
| 2884 | send_resp(dut, conn, SIGMA_ERROR, |
| 2885 | "errorCode,Failed to copy client " |
| 2886 | "certificate"); |
| 2887 | return 0; |
| 2888 | } |
| 2889 | |
| 2890 | snprintf(url, sizeof(url), "Certs/%s-key.pem", name); |
| 2891 | sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client " |
| 2892 | "private key from the device (%s)", url); |
| 2893 | if (!file_exists(url)) { |
| 2894 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested " |
| 2895 | "private key file does not exist"); |
| 2896 | return 0; |
| 2897 | } |
| 2898 | snprintf(buf, sizeof(buf), "cp %s next-client-key.pem", url); |
| 2899 | if (system(buf) != 0) { |
| 2900 | send_resp(dut, conn, SIGMA_ERROR, |
| 2901 | "errorCode,Failed to copy client key"); |
| 2902 | return 0; |
| 2903 | } |
| 2904 | } else if (strncasecmp(path, "http:", 5) != 0 && |
| 2905 | strncasecmp(path, "https:", 6) != 0) { |
| 2906 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode," |
| 2907 | "Unsupported FilePath value"); |
| 2908 | return 0; |
| 2909 | } else { |
| 2910 | snprintf(url, sizeof(url), "%s/%s.pem", path, name); |
| 2911 | sigma_dut_print(dut, DUT_MSG_INFO, "Downloading client " |
| 2912 | "certificate/key from %s", url); |
| 2913 | snprintf(buf, sizeof(buf), |
| 2914 | "wget -T 10 -t 3 -O next-client-cert.pem '%s'", url); |
| 2915 | if (system(buf) != 0) { |
| 2916 | send_resp(dut, conn, SIGMA_ERROR, |
| 2917 | "errorCode,Failed to download client " |
| 2918 | "certificate"); |
| 2919 | return 0; |
| 2920 | } |
| 2921 | |
| 2922 | if (system("cp next-client-cert.pem next-client-key.pem") != 0) |
| 2923 | { |
| 2924 | send_resp(dut, conn, SIGMA_ERROR, |
| 2925 | "errorCode,Failed to copy client key"); |
| 2926 | return 0; |
| 2927 | } |
| 2928 | } |
| 2929 | |
| 2930 | return 1; |
| 2931 | } |
| 2932 | |
| 2933 | |
| 2934 | static int cmd_sta_preset_testparameters_hs2_r2(struct sigma_dut *dut, |
| 2935 | struct sigma_conn *conn, |
| 2936 | const char *intf, |
| 2937 | struct sigma_cmd *cmd) |
| 2938 | { |
| 2939 | const char *val; |
| 2940 | |
| 2941 | val = get_param(cmd, "FileType"); |
| 2942 | if (val && strcasecmp(val, "PPSMO") == 0) |
| 2943 | return download_ppsmo(dut, conn, intf, cmd); |
| 2944 | if (val && strcasecmp(val, "CERT") == 0) |
| 2945 | return download_cert(dut, conn, intf, cmd); |
| 2946 | if (val) { |
| 2947 | send_resp(dut, conn, SIGMA_ERROR, |
| 2948 | "ErrorCode,Unsupported FileType"); |
| 2949 | return 0; |
| 2950 | } |
| 2951 | |
| 2952 | return 1; |
| 2953 | } |
| 2954 | |
| 2955 | |
Ankita Bajaj | a2cb567 | 2017-10-25 16:08:28 +0530 | [diff] [blame] | 2956 | static int cmd_sta_preset_testparameters_oce(struct sigma_dut *dut, |
| 2957 | struct sigma_conn *conn, |
| 2958 | const char *intf, |
| 2959 | struct sigma_cmd *cmd) |
| 2960 | { |
| 2961 | const char *val; |
| 2962 | |
| 2963 | val = get_param(cmd, "OCESupport"); |
| 2964 | if (val && strcasecmp(val, "Disable") == 0) { |
| 2965 | if (wpa_command(intf, "SET oce 0") < 0) { |
| 2966 | send_resp(dut, conn, SIGMA_ERROR, |
| 2967 | "ErrorCode,Failed to disable OCE"); |
| 2968 | return 0; |
| 2969 | } |
| 2970 | } else if (val && strcasecmp(val, "Enable") == 0) { |
| 2971 | if (wpa_command(intf, "SET oce 1") < 0) { |
| 2972 | send_resp(dut, conn, SIGMA_ERROR, |
| 2973 | "ErrorCode,Failed to enable OCE"); |
| 2974 | return 0; |
| 2975 | } |
| 2976 | } |
| 2977 | |
vamsi krishna | a279949 | 2017-12-05 14:28:01 +0530 | [diff] [blame] | 2978 | val = get_param(cmd, "FILScap"); |
| 2979 | if (val && (atoi(val) == 1)) { |
| 2980 | if (wpa_command(intf, "SET disable_fils 0") < 0) { |
| 2981 | send_resp(dut, conn, SIGMA_ERROR, |
| 2982 | "ErrorCode,Failed to enable FILS"); |
| 2983 | return 0; |
| 2984 | } |
| 2985 | } else if (val && (atoi(val) == 0)) { |
| 2986 | if (wpa_command(intf, "SET disable_fils 1") < 0) { |
| 2987 | send_resp(dut, conn, SIGMA_ERROR, |
| 2988 | "ErrorCode,Failed to disable FILS"); |
| 2989 | return 0; |
| 2990 | } |
| 2991 | } |
| 2992 | |
Ankita Bajaj | a2cb567 | 2017-10-25 16:08:28 +0530 | [diff] [blame] | 2993 | return 1; |
| 2994 | } |
| 2995 | |
| 2996 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2997 | static void ath_sta_set_noack(struct sigma_dut *dut, const char *intf, |
| 2998 | const char *val) |
| 2999 | { |
| 3000 | int counter = 0; |
| 3001 | char token[50]; |
| 3002 | char *result; |
| 3003 | char buf[100]; |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 3004 | char *saveptr; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3005 | |
Peng Xu | b8fc5cc | 2017-05-10 17:27:28 -0700 | [diff] [blame] | 3006 | strlcpy(token, val, sizeof(token)); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3007 | token[sizeof(token) - 1] = '\0'; |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 3008 | result = strtok_r(token, ":", &saveptr); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3009 | while (result) { |
| 3010 | if (strcmp(result, "disable") == 0) { |
| 3011 | snprintf(buf, sizeof(buf), |
| 3012 | "iwpriv %s noackpolicy %d 1 0", |
| 3013 | intf, counter); |
| 3014 | } else { |
| 3015 | snprintf(buf, sizeof(buf), |
| 3016 | "iwpriv %s noackpolicy %d 1 1", |
| 3017 | intf, counter); |
| 3018 | } |
| 3019 | if (system(buf) != 0) { |
| 3020 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3021 | "iwpriv noackpolicy failed"); |
| 3022 | } |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 3023 | result = strtok_r(NULL, ":", &saveptr); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3024 | counter++; |
| 3025 | } |
| 3026 | } |
| 3027 | |
| 3028 | |
| 3029 | static void ath_sta_set_rts(struct sigma_dut *dut, const char *intf, |
| 3030 | const char *val) |
| 3031 | { |
| 3032 | char buf[100]; |
| 3033 | |
| 3034 | snprintf(buf, sizeof(buf), "iwconfig %s rts %s", intf, val); |
| 3035 | if (system(buf) != 0) { |
| 3036 | sigma_dut_print(dut, DUT_MSG_ERROR, "iwconfig RTS failed"); |
| 3037 | } |
| 3038 | } |
| 3039 | |
| 3040 | |
| 3041 | static void ath_sta_set_wmm(struct sigma_dut *dut, const char *intf, |
| 3042 | const char *val) |
| 3043 | { |
| 3044 | char buf[100]; |
| 3045 | |
| 3046 | if (strcasecmp(val, "off") == 0) { |
| 3047 | snprintf(buf, sizeof(buf), "iwpriv %s wmm 0", intf); |
| 3048 | if (system(buf) != 0) { |
| 3049 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3050 | "Failed to turn off WMM"); |
| 3051 | } |
| 3052 | } |
| 3053 | } |
| 3054 | |
| 3055 | |
| 3056 | static void ath_sta_set_sgi(struct sigma_dut *dut, const char *intf, |
| 3057 | const char *val) |
| 3058 | { |
| 3059 | char buf[100]; |
| 3060 | int sgi20; |
| 3061 | |
| 3062 | sgi20 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0; |
| 3063 | |
| 3064 | snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d", intf, sgi20); |
| 3065 | if (system(buf) != 0) |
| 3066 | sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv shortgi failed"); |
| 3067 | } |
| 3068 | |
| 3069 | |
| 3070 | static void ath_sta_set_11nrates(struct sigma_dut *dut, const char *intf, |
| 3071 | const char *val) |
| 3072 | { |
| 3073 | char buf[100]; |
Pradeep Reddy POTTETI | 67376b7 | 2016-10-25 20:08:17 +0530 | [diff] [blame] | 3074 | int rate_code, v; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3075 | |
| 3076 | /* Disable Tx Beam forming when using a fixed rate */ |
| 3077 | ath_disable_txbf(dut, intf); |
| 3078 | |
Pradeep Reddy POTTETI | 67376b7 | 2016-10-25 20:08:17 +0530 | [diff] [blame] | 3079 | v = atoi(val); |
| 3080 | if (v < 0 || v > 32) { |
| 3081 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3082 | "Invalid Fixed MCS rate: %d", v); |
| 3083 | return; |
| 3084 | } |
| 3085 | rate_code = 0x80 + v; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3086 | |
| 3087 | snprintf(buf, sizeof(buf), "iwpriv %s set11NRates 0x%x", |
| 3088 | intf, rate_code); |
| 3089 | if (system(buf) != 0) { |
| 3090 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3091 | "iwpriv set11NRates failed"); |
| 3092 | } |
| 3093 | |
| 3094 | /* Channel width gets messed up, fix this */ |
| 3095 | snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d", intf, dut->chwidth); |
| 3096 | if (system(buf) != 0) |
| 3097 | sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv chwidth failed"); |
| 3098 | } |
| 3099 | |
| 3100 | |
| 3101 | static void ath_sta_set_amsdu(struct sigma_dut *dut, const char *intf, |
| 3102 | const char *val) |
| 3103 | { |
| 3104 | char buf[60]; |
| 3105 | |
| 3106 | if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) |
| 3107 | snprintf(buf, sizeof(buf), "iwpriv %s amsdu 2", intf); |
| 3108 | else |
| 3109 | snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf); |
| 3110 | |
| 3111 | if (system(buf) != 0) |
| 3112 | sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv amsdu failed"); |
| 3113 | } |
| 3114 | |
| 3115 | |
Deepak Dhamdhere | 80356cb | 2016-03-28 16:48:32 -0700 | [diff] [blame] | 3116 | static int iwpriv_sta_set_ampdu(struct sigma_dut *dut, const char *intf, |
| 3117 | int ampdu) |
| 3118 | { |
| 3119 | char buf[60]; |
| 3120 | |
| 3121 | snprintf(buf, sizeof(buf), "iwpriv %s ampdu %d", intf, ampdu); |
| 3122 | if (system(buf) != 0) { |
| 3123 | sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv ampdu failed"); |
| 3124 | return -1; |
| 3125 | } |
| 3126 | |
| 3127 | return 0; |
| 3128 | } |
| 3129 | |
| 3130 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3131 | static void ath_sta_set_stbc(struct sigma_dut *dut, const char *intf, |
| 3132 | const char *val) |
| 3133 | { |
| 3134 | char buf[60]; |
| 3135 | |
| 3136 | snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc %s", intf, val); |
| 3137 | if (system(buf) != 0) { |
| 3138 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3139 | "iwpriv tx_stbc failed"); |
| 3140 | } |
| 3141 | |
| 3142 | snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc %s", intf, val); |
| 3143 | if (system(buf) != 0) { |
| 3144 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3145 | "iwpriv rx_stbc failed"); |
| 3146 | } |
| 3147 | } |
| 3148 | |
| 3149 | |
| 3150 | static int wcn_sta_set_cts_width(struct sigma_dut *dut, const char *intf, |
| 3151 | const char *val) |
| 3152 | { |
| 3153 | char buf[60]; |
| 3154 | |
Peng Xu | cc317ed | 2017-05-18 16:44:37 -0700 | [diff] [blame] | 3155 | if (strcmp(val, "160") == 0) { |
| 3156 | snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 5", intf); |
| 3157 | } else if (strcmp(val, "80") == 0) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3158 | snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf); |
| 3159 | } else if (strcmp(val, "40") == 0) { |
| 3160 | snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 2", intf); |
| 3161 | } else if (strcmp(val, "20") == 0) { |
| 3162 | snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 1", intf); |
| 3163 | } else if (strcasecmp(val, "Auto") == 0) { |
| 3164 | buf[0] = '\0'; |
| 3165 | } else { |
| 3166 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3167 | "WIDTH/CTS_WIDTH value not supported"); |
| 3168 | return -1; |
| 3169 | } |
| 3170 | |
| 3171 | if (buf[0] != '\0' && system(buf) != 0) { |
| 3172 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3173 | "Failed to set WIDTH/CTS_WIDTH"); |
| 3174 | return -1; |
| 3175 | } |
| 3176 | |
| 3177 | return 0; |
| 3178 | } |
| 3179 | |
| 3180 | |
| 3181 | int ath_set_width(struct sigma_dut *dut, struct sigma_conn *conn, |
| 3182 | const char *intf, const char *val) |
| 3183 | { |
| 3184 | char buf[60]; |
| 3185 | |
| 3186 | if (strcasecmp(val, "Auto") == 0) { |
| 3187 | snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf); |
| 3188 | dut->chwidth = 0; |
| 3189 | } else if (strcasecmp(val, "20") == 0) { |
| 3190 | snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf); |
| 3191 | dut->chwidth = 0; |
| 3192 | } else if (strcasecmp(val, "40") == 0) { |
| 3193 | snprintf(buf, sizeof(buf), "iwpriv %s chwidth 1", intf); |
| 3194 | dut->chwidth = 1; |
| 3195 | } else if (strcasecmp(val, "80") == 0) { |
| 3196 | snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf); |
| 3197 | dut->chwidth = 2; |
| 3198 | } else if (strcasecmp(val, "160") == 0) { |
| 3199 | snprintf(buf, sizeof(buf), "iwpriv %s chwidth 3", intf); |
| 3200 | dut->chwidth = 3; |
| 3201 | } else { |
| 3202 | send_resp(dut, conn, SIGMA_ERROR, |
| 3203 | "ErrorCode,WIDTH not supported"); |
| 3204 | return -1; |
| 3205 | } |
| 3206 | |
| 3207 | if (system(buf) != 0) { |
| 3208 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3209 | "iwpriv chwidth failed"); |
| 3210 | } |
| 3211 | |
| 3212 | return 0; |
| 3213 | } |
| 3214 | |
| 3215 | |
| 3216 | static int wcn_sta_set_sp_stream(struct sigma_dut *dut, const char *intf, |
| 3217 | const char *val) |
| 3218 | { |
| 3219 | char buf[60]; |
| 3220 | |
| 3221 | if (strcmp(val, "1SS") == 0) { |
| 3222 | snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf); |
| 3223 | } else if (strcmp(val, "2SS") == 0) { |
| 3224 | snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf); |
| 3225 | } else { |
| 3226 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3227 | "SP_STREAM value not supported"); |
| 3228 | return -1; |
| 3229 | } |
| 3230 | |
| 3231 | if (system(buf) != 0) { |
| 3232 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3233 | "Failed to set SP_STREAM"); |
| 3234 | return -1; |
| 3235 | } |
| 3236 | |
| 3237 | return 0; |
| 3238 | } |
| 3239 | |
| 3240 | |
Pradeep Reddy POTTETI | 4a1f6b3 | 2016-11-23 13:15:21 +0530 | [diff] [blame] | 3241 | static void wcn_sta_set_stbc(struct sigma_dut *dut, const char *intf, |
| 3242 | const char *val) |
| 3243 | { |
| 3244 | char buf[60]; |
| 3245 | |
| 3246 | snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc %s", intf, val); |
| 3247 | if (system(buf) != 0) |
| 3248 | sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv tx_stbc failed"); |
| 3249 | |
| 3250 | snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc %s", intf, val); |
| 3251 | if (system(buf) != 0) |
| 3252 | sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv rx_stbc failed"); |
| 3253 | } |
| 3254 | |
| 3255 | |
Ashwini Patil | 68d02cd | 2017-01-10 15:39:16 +0530 | [diff] [blame] | 3256 | static int mbo_set_cellular_data_capa(struct sigma_dut *dut, |
| 3257 | struct sigma_conn *conn, |
| 3258 | const char *intf, int capa) |
| 3259 | { |
| 3260 | char buf[32]; |
| 3261 | |
| 3262 | if (capa > 0 && capa < 4) { |
| 3263 | snprintf(buf, sizeof(buf), "SET mbo_cell_capa %d", capa); |
| 3264 | if (wpa_command(intf, buf) < 0) { |
| 3265 | send_resp(dut, conn, SIGMA_ERROR, |
| 3266 | "ErrorCode, Failed to set cellular data capability"); |
| 3267 | return 0; |
| 3268 | } |
| 3269 | return 1; |
| 3270 | } |
| 3271 | |
| 3272 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3273 | "Invalid Cellular data capability: %d", capa); |
| 3274 | send_resp(dut, conn, SIGMA_INVALID, |
| 3275 | "ErrorCode,Invalid cellular data capability"); |
| 3276 | return 0; |
| 3277 | } |
| 3278 | |
| 3279 | |
Ashwini Patil | 9183fdb | 2017-04-13 16:58:25 +0530 | [diff] [blame] | 3280 | static int mbo_set_roaming(struct sigma_dut *dut, struct sigma_conn *conn, |
| 3281 | const char *intf, const char *val) |
| 3282 | { |
| 3283 | if (strcasecmp(val, "Disable") == 0) { |
| 3284 | if (wpa_command(intf, "SET roaming 0") < 0) { |
| 3285 | send_resp(dut, conn, SIGMA_ERROR, |
| 3286 | "ErrorCode,Failed to disable roaming"); |
| 3287 | return 0; |
| 3288 | } |
| 3289 | return 1; |
| 3290 | } |
| 3291 | |
| 3292 | if (strcasecmp(val, "Enable") == 0) { |
| 3293 | if (wpa_command(intf, "SET roaming 1") < 0) { |
| 3294 | send_resp(dut, conn, SIGMA_ERROR, |
| 3295 | "ErrorCode,Failed to enable roaming"); |
| 3296 | return 0; |
| 3297 | } |
| 3298 | return 1; |
| 3299 | } |
| 3300 | |
| 3301 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3302 | "Invalid value provided for roaming: %s", val); |
| 3303 | send_resp(dut, conn, SIGMA_INVALID, |
| 3304 | "ErrorCode,Unknown value provided for Roaming"); |
| 3305 | return 0; |
| 3306 | } |
| 3307 | |
| 3308 | |
Ashwini Patil | a75de5a | 2017-04-13 16:35:05 +0530 | [diff] [blame] | 3309 | static int mbo_set_assoc_disallow(struct sigma_dut *dut, |
| 3310 | struct sigma_conn *conn, |
| 3311 | const char *intf, const char *val) |
| 3312 | { |
| 3313 | if (strcasecmp(val, "Disable") == 0) { |
| 3314 | if (wpa_command(intf, "SET ignore_assoc_disallow 1") < 0) { |
| 3315 | send_resp(dut, conn, SIGMA_ERROR, |
| 3316 | "ErrorCode,Failed to disable Assoc_disallow"); |
| 3317 | return 0; |
| 3318 | } |
| 3319 | return 1; |
| 3320 | } |
| 3321 | |
| 3322 | if (strcasecmp(val, "Enable") == 0) { |
| 3323 | if (wpa_command(intf, "SET ignore_assoc_disallow 0") < 0) { |
| 3324 | send_resp(dut, conn, SIGMA_ERROR, |
| 3325 | "ErrorCode,Failed to enable Assoc_disallow"); |
| 3326 | return 0; |
| 3327 | } |
| 3328 | return 1; |
| 3329 | } |
| 3330 | |
| 3331 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3332 | "Invalid value provided for Assoc_disallow: %s", val); |
| 3333 | send_resp(dut, conn, SIGMA_INVALID, |
| 3334 | "ErrorCode,Unknown value provided for Assoc_disallow"); |
| 3335 | return 0; |
| 3336 | } |
| 3337 | |
| 3338 | |
Ashwini Patil | c63161e | 2017-04-13 16:30:23 +0530 | [diff] [blame] | 3339 | static int mbo_set_bss_trans_req(struct sigma_dut *dut, struct sigma_conn *conn, |
| 3340 | const char *intf, const char *val) |
| 3341 | { |
| 3342 | if (strcasecmp(val, "Reject") == 0) { |
| 3343 | if (wpa_command(intf, "SET reject_btm_req_reason 1") < 0) { |
| 3344 | send_resp(dut, conn, SIGMA_ERROR, |
| 3345 | "ErrorCode,Failed to Reject BTM Request"); |
| 3346 | return 0; |
| 3347 | } |
| 3348 | return 1; |
| 3349 | } |
| 3350 | |
| 3351 | if (strcasecmp(val, "Accept") == 0) { |
| 3352 | if (wpa_command(intf, "SET reject_btm_req_reason 0") < 0) { |
| 3353 | send_resp(dut, conn, SIGMA_ERROR, |
| 3354 | "ErrorCode,Failed to Accept BTM Request"); |
| 3355 | return 0; |
| 3356 | } |
| 3357 | return 1; |
| 3358 | } |
| 3359 | |
| 3360 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3361 | "Invalid value provided for BSS_Transition: %s", val); |
| 3362 | send_resp(dut, conn, SIGMA_INVALID, |
| 3363 | "ErrorCode,Unknown value provided for BSS_Transition"); |
| 3364 | return 0; |
| 3365 | } |
| 3366 | |
| 3367 | |
Ashwini Patil | 0040258 | 2017-04-13 12:29:39 +0530 | [diff] [blame] | 3368 | static int mbo_set_non_pref_ch_list(struct sigma_dut *dut, |
| 3369 | struct sigma_conn *conn, |
| 3370 | const char *intf, |
| 3371 | struct sigma_cmd *cmd) |
| 3372 | { |
| 3373 | const char *ch, *pref, *op_class, *reason; |
| 3374 | char buf[120]; |
| 3375 | int len, ret; |
| 3376 | |
| 3377 | pref = get_param(cmd, "Ch_Pref"); |
| 3378 | if (!pref) |
| 3379 | return 1; |
| 3380 | |
| 3381 | if (strcasecmp(pref, "clear") == 0) { |
| 3382 | free(dut->non_pref_ch_list); |
| 3383 | dut->non_pref_ch_list = NULL; |
| 3384 | } else { |
| 3385 | op_class = get_param(cmd, "Ch_Op_Class"); |
| 3386 | if (!op_class) { |
| 3387 | send_resp(dut, conn, SIGMA_INVALID, |
| 3388 | "ErrorCode,Ch_Op_Class not provided"); |
| 3389 | return 0; |
| 3390 | } |
| 3391 | |
| 3392 | ch = get_param(cmd, "Ch_Pref_Num"); |
| 3393 | if (!ch) { |
| 3394 | send_resp(dut, conn, SIGMA_INVALID, |
| 3395 | "ErrorCode,Ch_Pref_Num not provided"); |
| 3396 | return 0; |
| 3397 | } |
| 3398 | |
| 3399 | reason = get_param(cmd, "Ch_Reason_Code"); |
| 3400 | if (!reason) { |
| 3401 | send_resp(dut, conn, SIGMA_INVALID, |
| 3402 | "ErrorCode,Ch_Reason_Code not provided"); |
| 3403 | return 0; |
| 3404 | } |
| 3405 | |
| 3406 | if (!dut->non_pref_ch_list) { |
| 3407 | dut->non_pref_ch_list = |
| 3408 | calloc(1, NON_PREF_CH_LIST_SIZE); |
| 3409 | if (!dut->non_pref_ch_list) { |
| 3410 | send_resp(dut, conn, SIGMA_ERROR, |
| 3411 | "ErrorCode,Failed to allocate memory for non_pref_ch_list"); |
| 3412 | return 0; |
| 3413 | } |
| 3414 | } |
| 3415 | len = strlen(dut->non_pref_ch_list); |
| 3416 | ret = snprintf(dut->non_pref_ch_list + len, |
| 3417 | NON_PREF_CH_LIST_SIZE - len, |
| 3418 | " %s:%s:%s:%s", op_class, ch, pref, reason); |
| 3419 | if (ret > 0 && ret < NON_PREF_CH_LIST_SIZE - len) { |
| 3420 | sigma_dut_print(dut, DUT_MSG_DEBUG, "non_pref_list: %s", |
| 3421 | dut->non_pref_ch_list); |
| 3422 | } else { |
| 3423 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3424 | "snprintf failed for non_pref_list, ret = %d", |
| 3425 | ret); |
| 3426 | send_resp(dut, conn, SIGMA_ERROR, |
| 3427 | "ErrorCode,snprintf failed"); |
| 3428 | free(dut->non_pref_ch_list); |
| 3429 | dut->non_pref_ch_list = NULL; |
| 3430 | return 0; |
| 3431 | } |
| 3432 | } |
| 3433 | |
| 3434 | ret = snprintf(buf, sizeof(buf), "SET non_pref_chan%s", |
| 3435 | dut->non_pref_ch_list ? dut->non_pref_ch_list : " "); |
| 3436 | if (ret < 0 || ret >= (int) sizeof(buf)) { |
| 3437 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 3438 | "snprintf failed for set non_pref_chan, ret: %d", |
| 3439 | ret); |
| 3440 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,snprint failed"); |
| 3441 | return 0; |
| 3442 | } |
| 3443 | |
| 3444 | if (wpa_command(intf, buf) < 0) { |
| 3445 | send_resp(dut, conn, SIGMA_ERROR, |
| 3446 | "ErrorCode,Failed to set non-preferred channel list"); |
| 3447 | return 0; |
| 3448 | } |
| 3449 | |
| 3450 | return 1; |
| 3451 | } |
| 3452 | |
| 3453 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3454 | static int cmd_sta_preset_testparameters(struct sigma_dut *dut, |
| 3455 | struct sigma_conn *conn, |
| 3456 | struct sigma_cmd *cmd) |
| 3457 | { |
| 3458 | const char *intf = get_param(cmd, "Interface"); |
| 3459 | const char *val; |
| 3460 | |
| 3461 | val = get_param(cmd, "Program"); |
Peng Xu | e9fa795 | 2017-05-09 15:59:49 -0700 | [diff] [blame] | 3462 | if (val && strcasecmp(val, "HS2-R2") == 0) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3463 | return cmd_sta_preset_testparameters_hs2_r2(dut, conn, intf, |
| 3464 | cmd); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3465 | |
priyadharshini gowthaman | d66913a | 2016-07-29 15:11:17 -0700 | [diff] [blame] | 3466 | if (val && strcasecmp(val, "LOC") == 0) |
| 3467 | return loc_cmd_sta_preset_testparameters(dut, conn, cmd); |
| 3468 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3469 | #ifdef ANDROID_NAN |
| 3470 | if (val && strcasecmp(val, "NAN") == 0) |
| 3471 | return nan_cmd_sta_preset_testparameters(dut, conn, cmd); |
| 3472 | #endif /* ANDROID_NAN */ |
Amarnath Hullur Subramanyam | 9c381f5 | 2017-03-17 00:04:41 -0700 | [diff] [blame] | 3473 | #ifdef MIRACAST |
| 3474 | if (val && (strcasecmp(val, "WFD") == 0 || |
| 3475 | strcasecmp(val, "DisplayR2") == 0)) |
| 3476 | return miracast_preset_testparameters(dut, conn, cmd); |
| 3477 | #endif /* MIRACAST */ |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3478 | |
Ashwini Patil | 68d02cd | 2017-01-10 15:39:16 +0530 | [diff] [blame] | 3479 | if (val && strcasecmp(val, "MBO") == 0) { |
| 3480 | val = get_param(cmd, "Cellular_Data_Cap"); |
| 3481 | if (val && |
| 3482 | mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0) |
| 3483 | return 0; |
Ashwini Patil | 0040258 | 2017-04-13 12:29:39 +0530 | [diff] [blame] | 3484 | |
| 3485 | val = get_param(cmd, "Ch_Pref"); |
| 3486 | if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0) |
| 3487 | return 0; |
| 3488 | |
Ashwini Patil | c63161e | 2017-04-13 16:30:23 +0530 | [diff] [blame] | 3489 | val = get_param(cmd, "BSS_Transition"); |
| 3490 | if (val && mbo_set_bss_trans_req(dut, conn, intf, val) == 0) |
| 3491 | return 0; |
| 3492 | |
Ashwini Patil | a75de5a | 2017-04-13 16:35:05 +0530 | [diff] [blame] | 3493 | val = get_param(cmd, "Assoc_Disallow"); |
| 3494 | if (val && mbo_set_assoc_disallow(dut, conn, intf, val) == 0) |
| 3495 | return 0; |
| 3496 | |
Ashwini Patil | 9183fdb | 2017-04-13 16:58:25 +0530 | [diff] [blame] | 3497 | val = get_param(cmd, "Roaming"); |
| 3498 | if (val && mbo_set_roaming(dut, conn, intf, val) == 0) |
| 3499 | return 0; |
| 3500 | |
Ashwini Patil | 68d02cd | 2017-01-10 15:39:16 +0530 | [diff] [blame] | 3501 | return 1; |
| 3502 | } |
| 3503 | |
Ankita Bajaj | a2cb567 | 2017-10-25 16:08:28 +0530 | [diff] [blame] | 3504 | if (val && strcasecmp(val, "OCE") == 0) |
| 3505 | return cmd_sta_preset_testparameters_oce(dut, conn, intf, cmd); |
| 3506 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3507 | #if 0 |
| 3508 | val = get_param(cmd, "Supplicant"); |
| 3509 | if (val && strcasecmp(val, "Default") != 0) { |
| 3510 | send_resp(dut, conn, SIGMA_ERROR, |
| 3511 | "ErrorCode,Only default(Vendor) supplicant " |
| 3512 | "supported"); |
| 3513 | return 0; |
| 3514 | } |
| 3515 | #endif |
| 3516 | |
| 3517 | val = get_param(cmd, "RTS"); |
| 3518 | if (val) { |
| 3519 | switch (get_driver_type()) { |
| 3520 | case DRIVER_ATHEROS: |
| 3521 | ath_sta_set_rts(dut, intf, val); |
| 3522 | break; |
| 3523 | default: |
| 3524 | #if 0 |
| 3525 | send_resp(dut, conn, SIGMA_ERROR, |
| 3526 | "ErrorCode,Setting RTS not supported"); |
| 3527 | return 0; |
| 3528 | #else |
| 3529 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 3530 | "Setting RTS not supported"); |
| 3531 | break; |
| 3532 | #endif |
| 3533 | } |
| 3534 | } |
| 3535 | |
| 3536 | #if 0 |
| 3537 | val = get_param(cmd, "FRGMNT"); |
| 3538 | if (val) { |
| 3539 | /* TODO */ |
| 3540 | send_resp(dut, conn, SIGMA_ERROR, |
| 3541 | "ErrorCode,Setting FRGMNT not supported"); |
| 3542 | return 0; |
| 3543 | } |
| 3544 | #endif |
| 3545 | |
| 3546 | #if 0 |
| 3547 | val = get_param(cmd, "Preamble"); |
| 3548 | if (val) { |
| 3549 | /* TODO: Long/Short */ |
| 3550 | send_resp(dut, conn, SIGMA_ERROR, |
| 3551 | "ErrorCode,Setting Preamble not supported"); |
| 3552 | return 0; |
| 3553 | } |
| 3554 | #endif |
| 3555 | |
| 3556 | val = get_param(cmd, "Mode"); |
| 3557 | if (val) { |
| 3558 | if (strcmp(val, "11b") == 0 || |
| 3559 | strcmp(val, "11g") == 0 || |
| 3560 | strcmp(val, "11a") == 0 || |
| 3561 | strcmp(val, "11n") == 0 || |
| 3562 | strcmp(val, "11ng") == 0 || |
| 3563 | strcmp(val, "11nl") == 0 || |
| 3564 | strcmp(val, "11nl(nabg)") == 0 || |
| 3565 | strcmp(val, "AC") == 0 || |
| 3566 | strcmp(val, "11AC") == 0 || |
| 3567 | strcmp(val, "11ac") == 0 || |
| 3568 | strcmp(val, "11na") == 0 || |
| 3569 | strcmp(val, "11an") == 0) { |
| 3570 | /* STA supports all modes by default */ |
| 3571 | } else { |
| 3572 | send_resp(dut, conn, SIGMA_ERROR, |
| 3573 | "ErrorCode,Setting Mode not supported"); |
| 3574 | return 0; |
| 3575 | } |
| 3576 | } |
| 3577 | |
| 3578 | val = get_param(cmd, "wmm"); |
| 3579 | if (val) { |
| 3580 | switch (get_driver_type()) { |
| 3581 | case DRIVER_ATHEROS: |
| 3582 | ath_sta_set_wmm(dut, intf, val); |
| 3583 | break; |
| 3584 | default: |
| 3585 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 3586 | "Setting wmm not supported"); |
| 3587 | break; |
| 3588 | } |
| 3589 | } |
| 3590 | |
| 3591 | val = get_param(cmd, "Powersave"); |
| 3592 | if (val) { |
| 3593 | if (strcmp(val, "0") == 0 || strcasecmp(val, "off") == 0) { |
| 3594 | if (wpa_command(get_station_ifname(), |
| 3595 | "P2P_SET ps 0") < 0) |
| 3596 | return -2; |
| 3597 | /* Make sure test modes are disabled */ |
| 3598 | wpa_command(get_station_ifname(), "P2P_SET ps 98"); |
| 3599 | wpa_command(get_station_ifname(), "P2P_SET ps 96"); |
| 3600 | } else if (strcmp(val, "1") == 0 || |
| 3601 | strcasecmp(val, "PSPoll") == 0 || |
| 3602 | strcasecmp(val, "on") == 0) { |
| 3603 | /* Disable default power save mode */ |
| 3604 | wpa_command(get_station_ifname(), "P2P_SET ps 0"); |
| 3605 | /* Enable PS-Poll test mode */ |
| 3606 | if (wpa_command(get_station_ifname(), |
| 3607 | "P2P_SET ps 97") < 0 || |
| 3608 | wpa_command(get_station_ifname(), |
| 3609 | "P2P_SET ps 99") < 0) |
| 3610 | return -2; |
| 3611 | } else if (strcmp(val, "2") == 0 || |
| 3612 | strcasecmp(val, "Fast") == 0) { |
| 3613 | /* TODO */ |
| 3614 | send_resp(dut, conn, SIGMA_ERROR, |
| 3615 | "ErrorCode,Powersave=Fast not supported"); |
| 3616 | return 0; |
| 3617 | } else if (strcmp(val, "3") == 0 || |
| 3618 | strcasecmp(val, "PSNonPoll") == 0) { |
| 3619 | /* Make sure test modes are disabled */ |
| 3620 | wpa_command(get_station_ifname(), "P2P_SET ps 98"); |
| 3621 | wpa_command(get_station_ifname(), "P2P_SET ps 96"); |
| 3622 | |
| 3623 | /* Enable default power save mode */ |
| 3624 | if (wpa_command(get_station_ifname(), |
| 3625 | "P2P_SET ps 1") < 0) |
| 3626 | return -2; |
| 3627 | } else |
| 3628 | return -1; |
| 3629 | } |
| 3630 | |
| 3631 | val = get_param(cmd, "NoAck"); |
| 3632 | if (val) { |
| 3633 | switch (get_driver_type()) { |
| 3634 | case DRIVER_ATHEROS: |
| 3635 | ath_sta_set_noack(dut, intf, val); |
| 3636 | break; |
| 3637 | default: |
| 3638 | send_resp(dut, conn, SIGMA_ERROR, |
| 3639 | "ErrorCode,Setting NoAck not supported"); |
| 3640 | return 0; |
| 3641 | } |
| 3642 | } |
| 3643 | |
| 3644 | val = get_param(cmd, "IgnoreChswitchProhibit"); |
| 3645 | if (val) { |
| 3646 | /* TODO: Enabled/disabled */ |
| 3647 | if (strcasecmp(val, "Enabled") == 0) { |
| 3648 | send_resp(dut, conn, SIGMA_ERROR, |
| 3649 | "ErrorCode,Enabling IgnoreChswitchProhibit " |
| 3650 | "not supported"); |
| 3651 | return 0; |
| 3652 | } |
| 3653 | } |
| 3654 | |
| 3655 | val = get_param(cmd, "TDLS"); |
| 3656 | if (val) { |
| 3657 | if (strcasecmp(val, "Disabled") == 0) { |
| 3658 | if (wpa_command(intf, "SET tdls_disabled 1")) { |
| 3659 | send_resp(dut, conn, SIGMA_ERROR, |
| 3660 | "ErrorCode,Failed to disable TDLS"); |
| 3661 | return 0; |
| 3662 | } |
| 3663 | } else if (strcasecmp(val, "Enabled") == 0) { |
| 3664 | if (wpa_command(intf, "SET tdls_disabled 0")) { |
| 3665 | send_resp(dut, conn, SIGMA_ERROR, |
| 3666 | "ErrorCode,Failed to enable TDLS"); |
| 3667 | return 0; |
| 3668 | } |
| 3669 | } else { |
| 3670 | send_resp(dut, conn, SIGMA_ERROR, |
| 3671 | "ErrorCode,Unsupported TDLS value"); |
| 3672 | return 0; |
| 3673 | } |
| 3674 | } |
| 3675 | |
| 3676 | val = get_param(cmd, "TDLSmode"); |
| 3677 | if (val) { |
| 3678 | if (strcasecmp(val, "Default") == 0) { |
| 3679 | wpa_command(intf, "SET tdls_testing 0"); |
| 3680 | } else if (strcasecmp(val, "APProhibit") == 0) { |
| 3681 | if (wpa_command(intf, "SET tdls_testing 0x400")) { |
| 3682 | send_resp(dut, conn, SIGMA_ERROR, |
| 3683 | "ErrorCode,Failed to enable ignore " |
| 3684 | "APProhibit TDLS mode"); |
| 3685 | return 0; |
| 3686 | } |
| 3687 | } else if (strcasecmp(val, "HiLoMac") == 0) { |
| 3688 | /* STA should respond with TDLS setup req for a TDLS |
| 3689 | * setup req */ |
| 3690 | if (wpa_command(intf, "SET tdls_testing 0x80")) { |
| 3691 | send_resp(dut, conn, SIGMA_ERROR, |
| 3692 | "ErrorCode,Failed to enable HiLoMac " |
| 3693 | "TDLS mode"); |
| 3694 | return 0; |
| 3695 | } |
| 3696 | } else if (strcasecmp(val, "WeakSecurity") == 0) { |
| 3697 | /* |
| 3698 | * Since all security modes are enabled by default when |
| 3699 | * Sigma control is used, there is no need to do |
| 3700 | * anything here. |
| 3701 | */ |
| 3702 | } else if (strcasecmp(val, "ExistLink") == 0) { |
| 3703 | /* |
| 3704 | * Since we allow new TDLS Setup Request even if there |
| 3705 | * is an existing link, nothing needs to be done for |
| 3706 | * this. |
| 3707 | */ |
| 3708 | } else { |
| 3709 | /* TODO: |
| 3710 | * ExistLink: STA should send TDLS setup req even if |
| 3711 | * direct link already exists |
| 3712 | */ |
| 3713 | send_resp(dut, conn, SIGMA_ERROR, |
| 3714 | "ErrorCode,Unsupported TDLSmode value"); |
| 3715 | return 0; |
| 3716 | } |
| 3717 | } |
| 3718 | |
| 3719 | val = get_param(cmd, "FakePubKey"); |
| 3720 | if (val && atoi(val) && wpa_command(intf, "SET wps_corrupt_pkhash 1")) { |
| 3721 | send_resp(dut, conn, SIGMA_ERROR, |
| 3722 | "ErrorCode,Failed to enable FakePubKey"); |
| 3723 | return 0; |
| 3724 | } |
| 3725 | |
| 3726 | return 1; |
| 3727 | } |
| 3728 | |
| 3729 | |
| 3730 | static const char * ath_get_radio_name(const char *radio_name) |
| 3731 | { |
| 3732 | if (radio_name == NULL) |
| 3733 | return "wifi0"; |
| 3734 | if (strcmp(radio_name, "wifi1") == 0) |
| 3735 | return "wifi1"; |
| 3736 | if (strcmp(radio_name, "wifi2") == 0) |
| 3737 | return "wifi2"; |
| 3738 | return "wifi0"; |
| 3739 | } |
| 3740 | |
| 3741 | |
| 3742 | static void ath_sta_set_txsp_stream(struct sigma_dut *dut, const char *intf, |
| 3743 | const char *val) |
| 3744 | { |
| 3745 | char buf[60]; |
| 3746 | unsigned int vht_mcsmap = 0; |
| 3747 | int txchainmask = 0; |
| 3748 | const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]); |
| 3749 | |
| 3750 | if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) { |
| 3751 | if (dut->testbed_flag_txsp == 1) { |
| 3752 | vht_mcsmap = 0xfffc; |
| 3753 | dut->testbed_flag_txsp = 0; |
| 3754 | } else { |
| 3755 | vht_mcsmap = 0xfffe; |
| 3756 | } |
| 3757 | txchainmask = 1; |
| 3758 | } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) { |
| 3759 | if (dut->testbed_flag_txsp == 1) { |
| 3760 | vht_mcsmap = 0xfff0; |
| 3761 | dut->testbed_flag_txsp = 0; |
| 3762 | } else { |
| 3763 | vht_mcsmap = 0xfffa; |
| 3764 | } |
| 3765 | txchainmask = 3; |
| 3766 | } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) { |
| 3767 | if (dut->testbed_flag_txsp == 1) { |
| 3768 | vht_mcsmap = 0xffc0; |
| 3769 | dut->testbed_flag_txsp = 0; |
| 3770 | } else { |
| 3771 | vht_mcsmap = 0xffea; |
| 3772 | } |
| 3773 | txchainmask = 7; |
| 3774 | } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) { |
| 3775 | if (dut->testbed_flag_txsp == 1) { |
| 3776 | vht_mcsmap = 0xff00; |
| 3777 | dut->testbed_flag_txsp = 0; |
| 3778 | } else { |
| 3779 | vht_mcsmap = 0xffaa; |
| 3780 | } |
| 3781 | txchainmask = 15; |
| 3782 | } else { |
| 3783 | if (dut->testbed_flag_txsp == 1) { |
| 3784 | vht_mcsmap = 0xffc0; |
| 3785 | dut->testbed_flag_txsp = 0; |
| 3786 | } else { |
| 3787 | vht_mcsmap = 0xffea; |
| 3788 | } |
| 3789 | } |
| 3790 | |
| 3791 | if (txchainmask) { |
| 3792 | snprintf(buf, sizeof(buf), "iwpriv %s txchainmask %d", |
| 3793 | basedev, txchainmask); |
| 3794 | if (system(buf) != 0) { |
| 3795 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3796 | "iwpriv txchainmask failed"); |
| 3797 | } |
| 3798 | } |
| 3799 | |
| 3800 | snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0x%04x", |
| 3801 | intf, vht_mcsmap); |
| 3802 | if (system(buf) != 0) { |
| 3803 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3804 | "iwpriv %s vht_mcsmap 0x%04x failed", |
| 3805 | intf, vht_mcsmap); |
| 3806 | } |
| 3807 | } |
| 3808 | |
| 3809 | |
| 3810 | static void ath_sta_set_rxsp_stream(struct sigma_dut *dut, const char *intf, |
| 3811 | const char *val) |
| 3812 | { |
| 3813 | char buf[60]; |
| 3814 | unsigned int vht_mcsmap = 0; |
| 3815 | int rxchainmask = 0; |
| 3816 | const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]); |
| 3817 | |
| 3818 | if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) { |
| 3819 | if (dut->testbed_flag_rxsp == 1) { |
| 3820 | vht_mcsmap = 0xfffc; |
| 3821 | dut->testbed_flag_rxsp = 0; |
| 3822 | } else { |
| 3823 | vht_mcsmap = 0xfffe; |
| 3824 | } |
| 3825 | rxchainmask = 1; |
| 3826 | } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) { |
| 3827 | if (dut->testbed_flag_rxsp == 1) { |
| 3828 | vht_mcsmap = 0xfff0; |
| 3829 | dut->testbed_flag_rxsp = 0; |
| 3830 | } else { |
| 3831 | vht_mcsmap = 0xfffa; |
| 3832 | } |
| 3833 | rxchainmask = 3; |
| 3834 | } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) { |
| 3835 | if (dut->testbed_flag_rxsp == 1) { |
| 3836 | vht_mcsmap = 0xffc0; |
| 3837 | dut->testbed_flag_rxsp = 0; |
| 3838 | } else { |
| 3839 | vht_mcsmap = 0xffea; |
| 3840 | } |
| 3841 | rxchainmask = 7; |
| 3842 | } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) { |
| 3843 | if (dut->testbed_flag_rxsp == 1) { |
| 3844 | vht_mcsmap = 0xff00; |
| 3845 | dut->testbed_flag_rxsp = 0; |
| 3846 | } else { |
| 3847 | vht_mcsmap = 0xffaa; |
| 3848 | } |
| 3849 | rxchainmask = 15; |
| 3850 | } else { |
| 3851 | if (dut->testbed_flag_rxsp == 1) { |
| 3852 | vht_mcsmap = 0xffc0; |
| 3853 | dut->testbed_flag_rxsp = 0; |
| 3854 | } else { |
| 3855 | vht_mcsmap = 0xffea; |
| 3856 | } |
| 3857 | } |
| 3858 | |
| 3859 | if (rxchainmask) { |
| 3860 | snprintf(buf, sizeof(buf), "iwpriv %s rxchainmask %d", |
| 3861 | basedev, rxchainmask); |
| 3862 | if (system(buf) != 0) { |
| 3863 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3864 | "iwpriv rxchainmask failed"); |
| 3865 | } |
| 3866 | } |
| 3867 | |
| 3868 | snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0x%04x", |
| 3869 | intf, vht_mcsmap); |
| 3870 | if (system(buf) != 0) { |
| 3871 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3872 | "iwpriv %s vht_mcsmap 0x%04x", |
| 3873 | intf, vht_mcsmap); |
| 3874 | } |
| 3875 | } |
| 3876 | |
| 3877 | |
| 3878 | void ath_set_zero_crc(struct sigma_dut *dut, const char *val) |
| 3879 | { |
| 3880 | if (strcasecmp(val, "enable") == 0) { |
| 3881 | if (system("athdiag --set --address=0x2a204 --and=0xbfffffff") |
| 3882 | != 0) { |
| 3883 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3884 | "Disable BB_VHTSIGB_CRC_CALC failed"); |
| 3885 | } |
| 3886 | |
| 3887 | if (system("athdiag --set --address=0x2a204 --or=0x80000000") |
| 3888 | != 0) { |
| 3889 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3890 | "Enable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed"); |
| 3891 | } |
| 3892 | } else { |
| 3893 | if (system("athdiag --set --address=0x2a204 --and=0x7fffffff") |
| 3894 | != 0) { |
| 3895 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3896 | "Disable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed"); |
| 3897 | } |
| 3898 | |
| 3899 | if (system("athdiag --set --address=0x2a204 --or=0x40000000") |
| 3900 | != 0) { |
| 3901 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3902 | "Enable BB_VHTSIGB_CRC_CALC failed"); |
| 3903 | } |
| 3904 | } |
| 3905 | } |
| 3906 | |
| 3907 | |
| 3908 | static int cmd_sta_set_wireless_common(const char *intf, struct sigma_dut *dut, |
| 3909 | struct sigma_conn *conn, |
| 3910 | struct sigma_cmd *cmd) |
| 3911 | { |
| 3912 | const char *val; |
| 3913 | int ampdu = -1; |
| 3914 | char buf[30]; |
| 3915 | |
| 3916 | val = get_param(cmd, "40_INTOLERANT"); |
| 3917 | if (val) { |
| 3918 | if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) { |
| 3919 | /* TODO: iwpriv ht40intol through wpa_supplicant */ |
| 3920 | send_resp(dut, conn, SIGMA_ERROR, |
| 3921 | "ErrorCode,40_INTOLERANT not supported"); |
| 3922 | return 0; |
| 3923 | } |
| 3924 | } |
| 3925 | |
| 3926 | val = get_param(cmd, "ADDBA_REJECT"); |
| 3927 | if (val) { |
| 3928 | if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) { |
| 3929 | /* reject any ADDBA with status "decline" */ |
| 3930 | ampdu = 0; |
| 3931 | } else { |
| 3932 | /* accept ADDBA */ |
| 3933 | ampdu = 1; |
| 3934 | } |
| 3935 | } |
| 3936 | |
| 3937 | val = get_param(cmd, "AMPDU"); |
| 3938 | if (val) { |
| 3939 | if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) { |
| 3940 | /* enable AMPDU Aggregation */ |
| 3941 | if (ampdu == 0) { |
| 3942 | send_resp(dut, conn, SIGMA_ERROR, |
| 3943 | "ErrorCode,Mismatch in " |
| 3944 | "addba_reject/ampdu - " |
| 3945 | "not supported"); |
| 3946 | return 0; |
| 3947 | } |
| 3948 | ampdu = 1; |
| 3949 | } else { |
| 3950 | /* disable AMPDU Aggregation */ |
| 3951 | if (ampdu == 1) { |
| 3952 | send_resp(dut, conn, SIGMA_ERROR, |
| 3953 | "ErrorCode,Mismatch in " |
| 3954 | "addba_reject/ampdu - " |
| 3955 | "not supported"); |
| 3956 | return 0; |
| 3957 | } |
| 3958 | ampdu = 0; |
| 3959 | } |
| 3960 | } |
| 3961 | |
| 3962 | if (ampdu >= 0) { |
| 3963 | sigma_dut_print(dut, DUT_MSG_DEBUG, "%s A-MPDU aggregation", |
| 3964 | ampdu ? "Enabling" : "Disabling"); |
| 3965 | snprintf(buf, sizeof(buf), "SET ampdu %d", ampdu); |
Deepak Dhamdhere | 80356cb | 2016-03-28 16:48:32 -0700 | [diff] [blame] | 3966 | if (wpa_command(intf, buf) < 0 && |
| 3967 | iwpriv_sta_set_ampdu(dut, intf, ampdu) < 0) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3968 | send_resp(dut, conn, SIGMA_ERROR, |
| 3969 | "ErrorCode,set aggr failed"); |
| 3970 | return 0; |
| 3971 | } |
| 3972 | } |
| 3973 | |
| 3974 | val = get_param(cmd, "AMSDU"); |
| 3975 | if (val) { |
| 3976 | switch (get_driver_type()) { |
| 3977 | case DRIVER_ATHEROS: |
| 3978 | ath_sta_set_amsdu(dut, intf, val); |
| 3979 | break; |
| 3980 | default: |
| 3981 | if (strcmp(val, "1") == 0 || |
| 3982 | strcasecmp(val, "Enable") == 0) { |
| 3983 | /* Enable AMSDU Aggregation */ |
| 3984 | send_resp(dut, conn, SIGMA_ERROR, |
| 3985 | "ErrorCode,AMSDU aggregation not supported"); |
| 3986 | return 0; |
| 3987 | } |
| 3988 | break; |
| 3989 | } |
| 3990 | } |
| 3991 | |
| 3992 | val = get_param(cmd, "STBC_RX"); |
| 3993 | if (val) { |
| 3994 | switch (get_driver_type()) { |
| 3995 | case DRIVER_ATHEROS: |
| 3996 | ath_sta_set_stbc(dut, intf, val); |
| 3997 | break; |
Pradeep Reddy POTTETI | 4a1f6b3 | 2016-11-23 13:15:21 +0530 | [diff] [blame] | 3998 | case DRIVER_WCN: |
| 3999 | wcn_sta_set_stbc(dut, intf, val); |
| 4000 | break; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4001 | default: |
| 4002 | send_resp(dut, conn, SIGMA_ERROR, |
| 4003 | "ErrorCode,STBC_RX not supported"); |
| 4004 | return 0; |
| 4005 | } |
| 4006 | } |
| 4007 | |
| 4008 | val = get_param(cmd, "WIDTH"); |
| 4009 | if (val) { |
| 4010 | switch (get_driver_type()) { |
| 4011 | case DRIVER_WCN: |
| 4012 | if (wcn_sta_set_cts_width(dut, intf, val) < 0) { |
| 4013 | send_resp(dut, conn, SIGMA_ERROR, |
| 4014 | "ErrorCode,Failed to set WIDTH"); |
| 4015 | return 0; |
| 4016 | } |
| 4017 | break; |
| 4018 | case DRIVER_ATHEROS: |
| 4019 | if (ath_set_width(dut, conn, intf, val) < 0) |
| 4020 | return 0; |
| 4021 | break; |
| 4022 | default: |
| 4023 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4024 | "Setting WIDTH not supported"); |
| 4025 | break; |
| 4026 | } |
| 4027 | } |
| 4028 | |
| 4029 | val = get_param(cmd, "SMPS"); |
| 4030 | if (val) { |
| 4031 | /* TODO: Dynamic/0, Static/1, No Limit/2 */ |
| 4032 | send_resp(dut, conn, SIGMA_ERROR, |
| 4033 | "ErrorCode,SMPS not supported"); |
| 4034 | return 0; |
| 4035 | } |
| 4036 | |
| 4037 | val = get_param(cmd, "TXSP_STREAM"); |
| 4038 | if (val) { |
| 4039 | switch (get_driver_type()) { |
| 4040 | case DRIVER_WCN: |
| 4041 | if (wcn_sta_set_sp_stream(dut, intf, val) < 0) { |
| 4042 | send_resp(dut, conn, SIGMA_ERROR, |
| 4043 | "ErrorCode,Failed to set TXSP_STREAM"); |
| 4044 | return 0; |
| 4045 | } |
| 4046 | break; |
| 4047 | case DRIVER_ATHEROS: |
| 4048 | ath_sta_set_txsp_stream(dut, intf, val); |
| 4049 | break; |
| 4050 | default: |
| 4051 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4052 | "Setting TXSP_STREAM not supported"); |
| 4053 | break; |
| 4054 | } |
| 4055 | } |
| 4056 | |
| 4057 | val = get_param(cmd, "RXSP_STREAM"); |
| 4058 | if (val) { |
| 4059 | switch (get_driver_type()) { |
| 4060 | case DRIVER_WCN: |
| 4061 | if (wcn_sta_set_sp_stream(dut, intf, val) < 0) { |
| 4062 | send_resp(dut, conn, SIGMA_ERROR, |
| 4063 | "ErrorCode,Failed to set RXSP_STREAM"); |
| 4064 | return 0; |
| 4065 | } |
| 4066 | break; |
| 4067 | case DRIVER_ATHEROS: |
| 4068 | ath_sta_set_rxsp_stream(dut, intf, val); |
| 4069 | break; |
| 4070 | default: |
| 4071 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4072 | "Setting RXSP_STREAM not supported"); |
| 4073 | break; |
| 4074 | } |
| 4075 | } |
| 4076 | |
| 4077 | val = get_param(cmd, "DYN_BW_SGNL"); |
| 4078 | if (val) { |
Priyadharshini Gowthaman | 818afef | 2015-11-09 13:28:15 -0800 | [diff] [blame] | 4079 | switch (get_driver_type()) { |
| 4080 | case DRIVER_WCN: |
Peng Xu | c59afd3 | 2016-11-21 15:01:11 -0800 | [diff] [blame] | 4081 | if (strcasecmp(val, "enable") == 0) { |
| 4082 | snprintf(buf, sizeof(buf), |
| 4083 | "iwpriv %s cwmenable 1", intf); |
| 4084 | if (system(buf) != 0) { |
| 4085 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4086 | "iwpriv cwmenable 1 failed"); |
| 4087 | return 0; |
| 4088 | } |
| 4089 | } else if (strcasecmp(val, "disable") == 0) { |
| 4090 | snprintf(buf, sizeof(buf), |
| 4091 | "iwpriv %s cwmenable 0", intf); |
| 4092 | if (system(buf) != 0) { |
| 4093 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4094 | "iwpriv cwmenable 0 failed"); |
| 4095 | return 0; |
| 4096 | } |
| 4097 | } else { |
| 4098 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4099 | "Unsupported DYN_BW_SGL"); |
| 4100 | } |
| 4101 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4102 | snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf); |
| 4103 | if (system(buf) != 0) { |
| 4104 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4105 | "Failed to set cts_cbw in DYN_BW_SGNL"); |
| 4106 | return 0; |
| 4107 | } |
Priyadharshini Gowthaman | 818afef | 2015-11-09 13:28:15 -0800 | [diff] [blame] | 4108 | break; |
| 4109 | case DRIVER_ATHEROS: |
priyadharshini gowthaman | e5e2517 | 2015-12-08 14:53:48 -0800 | [diff] [blame] | 4110 | novap_reset(dut, intf); |
Priyadharshini Gowthaman | 818afef | 2015-11-09 13:28:15 -0800 | [diff] [blame] | 4111 | ath_config_dyn_bw_sig(dut, intf, val); |
| 4112 | break; |
| 4113 | default: |
| 4114 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4115 | "Failed to set DYN_BW_SGNL"); |
| 4116 | break; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4117 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4118 | } |
| 4119 | |
| 4120 | val = get_param(cmd, "RTS_FORCE"); |
| 4121 | if (val) { |
priyadharshini gowthaman | e5e2517 | 2015-12-08 14:53:48 -0800 | [diff] [blame] | 4122 | novap_reset(dut, intf); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4123 | if (strcasecmp(val, "Enable") == 0) { |
| 4124 | snprintf(buf, sizeof(buf), "iwconfig %s rts 64", intf); |
Priyadharshini Gowthaman | abdb212 | 2015-11-17 11:52:19 +0200 | [diff] [blame] | 4125 | if (system(buf) != 0) { |
| 4126 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4127 | "Failed to set RTS_FORCE 64"); |
| 4128 | } |
priyadharshini gowthaman | 270870e | 2015-12-09 10:10:23 -0800 | [diff] [blame] | 4129 | snprintf(buf, sizeof(buf), |
| 4130 | "wifitool %s beeliner_fw_test 100 1", intf); |
| 4131 | if (system(buf) != 0) { |
| 4132 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4133 | "wifitool beeliner_fw_test 100 1 failed"); |
| 4134 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4135 | } else if (strcasecmp(val, "Disable") == 0) { |
| 4136 | snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", |
| 4137 | intf); |
Priyadharshini Gowthaman | abdb212 | 2015-11-17 11:52:19 +0200 | [diff] [blame] | 4138 | if (system(buf) != 0) { |
| 4139 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4140 | "Failed to set RTS_FORCE 2347"); |
| 4141 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4142 | } else { |
| 4143 | send_resp(dut, conn, SIGMA_ERROR, |
| 4144 | "ErrorCode,RTS_FORCE value not supported"); |
| 4145 | return 0; |
| 4146 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4147 | } |
| 4148 | |
| 4149 | val = get_param(cmd, "CTS_WIDTH"); |
| 4150 | if (val) { |
| 4151 | switch (get_driver_type()) { |
| 4152 | case DRIVER_WCN: |
| 4153 | if (wcn_sta_set_cts_width(dut, intf, val) < 0) { |
| 4154 | send_resp(dut, conn, SIGMA_ERROR, |
| 4155 | "ErrorCode,Failed to set CTS_WIDTH"); |
| 4156 | return 0; |
| 4157 | } |
| 4158 | break; |
| 4159 | case DRIVER_ATHEROS: |
| 4160 | ath_set_cts_width(dut, intf, val); |
| 4161 | break; |
| 4162 | default: |
| 4163 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4164 | "Setting CTS_WIDTH not supported"); |
| 4165 | break; |
| 4166 | } |
| 4167 | } |
| 4168 | |
| 4169 | val = get_param(cmd, "BW_SGNL"); |
| 4170 | if (val) { |
| 4171 | if (strcasecmp(val, "Enable") == 0) { |
| 4172 | snprintf(buf, sizeof(buf), "iwpriv %s cwmenable 1", |
| 4173 | intf); |
| 4174 | } else if (strcasecmp(val, "Disable") == 0) { |
| 4175 | /* TODO: Disable */ |
| 4176 | buf[0] = '\0'; |
| 4177 | } else { |
| 4178 | send_resp(dut, conn, SIGMA_ERROR, |
| 4179 | "ErrorCode,BW_SGNL value not supported"); |
| 4180 | return 0; |
| 4181 | } |
| 4182 | |
| 4183 | if (buf[0] != '\0' && system(buf) != 0) { |
| 4184 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4185 | "Failed to set BW_SGNL"); |
| 4186 | } |
| 4187 | } |
| 4188 | |
| 4189 | val = get_param(cmd, "Band"); |
| 4190 | if (val) { |
| 4191 | if (strcmp(val, "2.4") == 0 || strcmp(val, "5") == 0) { |
| 4192 | /* STA supports all bands by default */ |
| 4193 | } else { |
| 4194 | send_resp(dut, conn, SIGMA_ERROR, |
| 4195 | "ErrorCode,Unsupported Band"); |
| 4196 | return 0; |
| 4197 | } |
| 4198 | } |
| 4199 | |
| 4200 | val = get_param(cmd, "zero_crc"); |
| 4201 | if (val) { |
| 4202 | switch (get_driver_type()) { |
| 4203 | case DRIVER_ATHEROS: |
| 4204 | ath_set_zero_crc(dut, val); |
| 4205 | break; |
| 4206 | default: |
| 4207 | break; |
| 4208 | } |
| 4209 | } |
| 4210 | |
| 4211 | return 1; |
| 4212 | } |
| 4213 | |
| 4214 | |
| 4215 | static int sta_set_60g_common(struct sigma_dut *dut, struct sigma_conn *conn, |
| 4216 | struct sigma_cmd *cmd) |
| 4217 | { |
| 4218 | const char *val; |
| 4219 | char buf[100]; |
| 4220 | |
| 4221 | val = get_param(cmd, "MSDUSize"); |
| 4222 | if (val) { |
| 4223 | int mtu; |
| 4224 | |
| 4225 | dut->amsdu_size = atoi(val); |
| 4226 | if (dut->amsdu_size > IEEE80211_MAX_DATA_LEN_DMG || |
| 4227 | dut->amsdu_size < IEEE80211_SNAP_LEN_DMG) { |
| 4228 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4229 | "MSDUSize %d is above max %d or below min %d", |
| 4230 | dut->amsdu_size, |
| 4231 | IEEE80211_MAX_DATA_LEN_DMG, |
| 4232 | IEEE80211_SNAP_LEN_DMG); |
| 4233 | dut->amsdu_size = 0; |
| 4234 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; |
| 4235 | } |
| 4236 | |
| 4237 | mtu = dut->amsdu_size - IEEE80211_SNAP_LEN_DMG; |
| 4238 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 4239 | "Setting amsdu_size to %d", mtu); |
| 4240 | snprintf(buf, sizeof(buf), "ifconfig %s mtu %d", |
| 4241 | get_station_ifname(), mtu); |
| 4242 | |
| 4243 | if (system(buf) != 0) { |
| 4244 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s", |
| 4245 | buf); |
| 4246 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; |
| 4247 | } |
| 4248 | } |
| 4249 | |
| 4250 | val = get_param(cmd, "BAckRcvBuf"); |
| 4251 | if (val) { |
| 4252 | dut->back_rcv_buf = atoi(val); |
| 4253 | if (dut->back_rcv_buf == 0) { |
| 4254 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4255 | "Failed to convert %s or value is 0", |
| 4256 | val); |
| 4257 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; |
| 4258 | } |
| 4259 | |
| 4260 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 4261 | "Setting BAckRcvBuf to %s", val); |
| 4262 | } |
| 4263 | |
| 4264 | return SIGMA_DUT_SUCCESS_CALLER_SEND_STATUS; |
| 4265 | } |
| 4266 | |
| 4267 | |
| 4268 | static int sta_pcp_start(struct sigma_dut *dut, struct sigma_conn *conn, |
| 4269 | struct sigma_cmd *cmd) |
| 4270 | { |
| 4271 | int net_id; |
| 4272 | char *ifname; |
| 4273 | const char *val; |
| 4274 | char buf[100]; |
| 4275 | |
| 4276 | dut->mode = SIGMA_MODE_STATION; |
| 4277 | ifname = get_main_ifname(); |
| 4278 | if (wpa_command(ifname, "PING") != 0) { |
| 4279 | sigma_dut_print(dut, DUT_MSG_ERROR, "Supplicant not running"); |
| 4280 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; |
| 4281 | } |
| 4282 | |
| 4283 | wpa_command(ifname, "FLUSH"); |
| 4284 | net_id = add_network_common(dut, conn, ifname, cmd); |
| 4285 | if (net_id < 0) { |
| 4286 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add network"); |
| 4287 | return net_id; |
| 4288 | } |
| 4289 | |
| 4290 | /* TODO: mode=2 for the AP; in the future, replace for mode PCP */ |
| 4291 | if (set_network(ifname, net_id, "mode", "2") < 0) { |
| 4292 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4293 | "Failed to set supplicant network mode"); |
| 4294 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; |
| 4295 | } |
| 4296 | |
| 4297 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 4298 | "Supplicant set network with mode 2"); |
| 4299 | |
| 4300 | val = get_param(cmd, "Security"); |
| 4301 | if (val && strcasecmp(val, "OPEN") == 0) { |
| 4302 | dut->ap_key_mgmt = AP_OPEN; |
| 4303 | if (set_network(ifname, net_id, "key_mgmt", "NONE") < 0) { |
| 4304 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4305 | "Failed to set supplicant to %s security", |
| 4306 | val); |
| 4307 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; |
| 4308 | } |
| 4309 | } else if (val && strcasecmp(val, "WPA2-PSK") == 0) { |
| 4310 | dut->ap_key_mgmt = AP_WPA2_PSK; |
| 4311 | if (set_network(ifname, net_id, "key_mgmt", "WPA-PSK") < 0) { |
| 4312 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4313 | "Failed to set supplicant to %s security", |
| 4314 | val); |
| 4315 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; |
| 4316 | } |
| 4317 | |
| 4318 | if (set_network(ifname, net_id, "proto", "RSN") < 0) { |
| 4319 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4320 | "Failed to set supplicant to proto RSN"); |
| 4321 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; |
| 4322 | } |
| 4323 | } else if (val) { |
| 4324 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4325 | "Requested Security %s is not supported on 60GHz", |
| 4326 | val); |
| 4327 | return SIGMA_DUT_INVALID_CALLER_SEND_STATUS; |
| 4328 | } |
| 4329 | |
| 4330 | val = get_param(cmd, "Encrypt"); |
| 4331 | if (val && strcasecmp(val, "AES-GCMP") == 0) { |
| 4332 | if (set_network(ifname, net_id, "pairwise", "GCMP") < 0) { |
| 4333 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4334 | "Failed to set supplicant to pairwise GCMP"); |
| 4335 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; |
| 4336 | } |
| 4337 | if (set_network(ifname, net_id, "group", "GCMP") < 0) { |
| 4338 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4339 | "Failed to set supplicant to group GCMP"); |
| 4340 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; |
| 4341 | } |
| 4342 | } else if (val) { |
| 4343 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4344 | "Requested Encrypt %s is not supported on 60 GHz", |
| 4345 | val); |
| 4346 | return SIGMA_DUT_INVALID_CALLER_SEND_STATUS; |
| 4347 | } |
| 4348 | |
| 4349 | val = get_param(cmd, "PSK"); |
| 4350 | if (val && set_network_quoted(ifname, net_id, "psk", val) < 0) { |
| 4351 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set psk %s", |
| 4352 | val); |
| 4353 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; |
| 4354 | } |
| 4355 | |
| 4356 | /* Convert 60G channel to freq */ |
| 4357 | switch (dut->ap_channel) { |
| 4358 | case 1: |
| 4359 | val = "58320"; |
| 4360 | break; |
| 4361 | case 2: |
| 4362 | val = "60480"; |
| 4363 | break; |
| 4364 | case 3: |
| 4365 | val = "62640"; |
| 4366 | break; |
| 4367 | default: |
| 4368 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4369 | "Failed to configure channel %d. Not supported", |
| 4370 | dut->ap_channel); |
| 4371 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; |
| 4372 | } |
| 4373 | |
| 4374 | if (set_network(ifname, net_id, "frequency", val) < 0) { |
| 4375 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4376 | "Failed to set supplicant network frequency"); |
| 4377 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; |
| 4378 | } |
| 4379 | |
| 4380 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 4381 | "Supplicant set network with frequency"); |
| 4382 | |
| 4383 | snprintf(buf, sizeof(buf), "SELECT_NETWORK %d", net_id); |
| 4384 | if (wpa_command(ifname, buf) < 0) { |
| 4385 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 4386 | "Failed to select network id %d on %s", |
| 4387 | net_id, ifname); |
| 4388 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; |
| 4389 | } |
| 4390 | |
| 4391 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Selected network"); |
| 4392 | |
| 4393 | return SIGMA_DUT_SUCCESS_CALLER_SEND_STATUS; |
| 4394 | } |
| 4395 | |
| 4396 | |
Lior David | 67543f5 | 2017-01-03 19:04:22 +0200 | [diff] [blame] | 4397 | static int wil6210_set_abft_len(struct sigma_dut *dut, int abft_len) |
| 4398 | { |
| 4399 | char buf[128], fname[128]; |
| 4400 | FILE *f; |
| 4401 | |
| 4402 | if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) { |
| 4403 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4404 | "failed to get wil6210 debugfs dir"); |
| 4405 | return -1; |
| 4406 | } |
| 4407 | |
| 4408 | snprintf(fname, sizeof(fname), "%s/abft_len", buf); |
| 4409 | f = fopen(fname, "w"); |
| 4410 | if (!f) { |
| 4411 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4412 | "failed to open: %s", fname); |
| 4413 | return -1; |
| 4414 | } |
| 4415 | |
| 4416 | fprintf(f, "%d\n", abft_len); |
| 4417 | fclose(f); |
| 4418 | |
| 4419 | return 0; |
| 4420 | } |
| 4421 | |
| 4422 | |
| 4423 | static int sta_set_60g_abft_len(struct sigma_dut *dut, struct sigma_conn *conn, |
| 4424 | int abft_len) |
| 4425 | { |
| 4426 | switch (get_driver_type()) { |
| 4427 | case DRIVER_WIL6210: |
| 4428 | return wil6210_set_abft_len(dut, abft_len); |
| 4429 | default: |
| 4430 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4431 | "set abft_len not supported"); |
| 4432 | return -1; |
| 4433 | } |
| 4434 | } |
| 4435 | |
| 4436 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4437 | static int sta_set_60g_pcp(struct sigma_dut *dut, struct sigma_conn *conn, |
| 4438 | struct sigma_cmd *cmd) |
| 4439 | { |
| 4440 | const char *val; |
Lior David | 67543f5 | 2017-01-03 19:04:22 +0200 | [diff] [blame] | 4441 | unsigned int abft_len = 1; /* default is one slot */ |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4442 | |
| 4443 | if (dut->dev_role != DEVROLE_PCP) { |
| 4444 | send_resp(dut, conn, SIGMA_INVALID, |
| 4445 | "ErrorCode,Invalid DevRole"); |
| 4446 | return 0; |
| 4447 | } |
| 4448 | |
| 4449 | val = get_param(cmd, "SSID"); |
| 4450 | if (val) { |
| 4451 | if (strlen(val) > sizeof(dut->ap_ssid) - 1) { |
| 4452 | send_resp(dut, conn, SIGMA_INVALID, |
| 4453 | "ErrorCode,Invalid SSID"); |
| 4454 | return -1; |
| 4455 | } |
| 4456 | |
Peng Xu | b8fc5cc | 2017-05-10 17:27:28 -0700 | [diff] [blame] | 4457 | strlcpy(dut->ap_ssid, val, sizeof(dut->ap_ssid)); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4458 | } |
| 4459 | |
| 4460 | val = get_param(cmd, "CHANNEL"); |
| 4461 | if (val) { |
| 4462 | const char *pos; |
| 4463 | |
| 4464 | dut->ap_channel = atoi(val); |
| 4465 | pos = strchr(val, ';'); |
| 4466 | if (pos) { |
| 4467 | pos++; |
| 4468 | dut->ap_channel_1 = atoi(pos); |
| 4469 | } |
| 4470 | } |
| 4471 | |
| 4472 | switch (dut->ap_channel) { |
| 4473 | case 1: |
| 4474 | case 2: |
| 4475 | case 3: |
| 4476 | break; |
| 4477 | default: |
| 4478 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4479 | "Channel %d is not supported", dut->ap_channel); |
| 4480 | send_resp(dut, conn, SIGMA_ERROR, |
| 4481 | "Requested channel is not supported"); |
| 4482 | return -1; |
| 4483 | } |
| 4484 | |
| 4485 | val = get_param(cmd, "BCNINT"); |
| 4486 | if (val) |
| 4487 | dut->ap_bcnint = atoi(val); |
| 4488 | |
| 4489 | |
| 4490 | val = get_param(cmd, "ExtSchIE"); |
| 4491 | if (val) { |
| 4492 | send_resp(dut, conn, SIGMA_ERROR, |
| 4493 | "ErrorCode,ExtSchIE is not supported yet"); |
| 4494 | return -1; |
| 4495 | } |
| 4496 | |
| 4497 | val = get_param(cmd, "AllocType"); |
| 4498 | if (val) { |
| 4499 | send_resp(dut, conn, SIGMA_ERROR, |
| 4500 | "ErrorCode,AllocType is not supported yet"); |
| 4501 | return -1; |
| 4502 | } |
| 4503 | |
| 4504 | val = get_param(cmd, "PercentBI"); |
| 4505 | if (val) { |
| 4506 | send_resp(dut, conn, SIGMA_ERROR, |
| 4507 | "ErrorCode,PercentBI is not supported yet"); |
| 4508 | return -1; |
| 4509 | } |
| 4510 | |
| 4511 | val = get_param(cmd, "CBAPOnly"); |
| 4512 | if (val) { |
| 4513 | send_resp(dut, conn, SIGMA_ERROR, |
| 4514 | "ErrorCode,CBAPOnly is not supported yet"); |
| 4515 | return -1; |
| 4516 | } |
| 4517 | |
| 4518 | val = get_param(cmd, "AMPDU"); |
| 4519 | if (val) { |
| 4520 | if (strcasecmp(val, "Enable") == 0) |
| 4521 | dut->ap_ampdu = 1; |
| 4522 | else if (strcasecmp(val, "Disable") == 0) |
| 4523 | dut->ap_ampdu = 2; |
| 4524 | else { |
| 4525 | send_resp(dut, conn, SIGMA_ERROR, |
| 4526 | "ErrorCode,AMPDU value is not Enable nor Disabled"); |
| 4527 | return -1; |
| 4528 | } |
| 4529 | } |
| 4530 | |
| 4531 | val = get_param(cmd, "AMSDU"); |
| 4532 | if (val) { |
| 4533 | if (strcasecmp(val, "Enable") == 0) |
| 4534 | dut->ap_amsdu = 1; |
| 4535 | else if (strcasecmp(val, "Disable") == 0) |
| 4536 | dut->ap_amsdu = 2; |
| 4537 | } |
| 4538 | |
| 4539 | val = get_param(cmd, "NumMSDU"); |
| 4540 | if (val) { |
| 4541 | send_resp(dut, conn, SIGMA_ERROR, |
| 4542 | "ErrorCode, NumMSDU is not supported yet"); |
| 4543 | return -1; |
| 4544 | } |
| 4545 | |
| 4546 | val = get_param(cmd, "ABFTLRang"); |
| 4547 | if (val) { |
| 4548 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
Lior David | 67543f5 | 2017-01-03 19:04:22 +0200 | [diff] [blame] | 4549 | "ABFTLRang parameter %s", val); |
| 4550 | if (strcmp(val, "Gt1") == 0) |
| 4551 | abft_len = 2; /* 2 slots in this case */ |
| 4552 | } |
| 4553 | |
| 4554 | if (sta_set_60g_abft_len(dut, conn, abft_len)) { |
| 4555 | send_resp(dut, conn, SIGMA_ERROR, |
| 4556 | "ErrorCode, Can't set ABFT length"); |
| 4557 | return -1; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4558 | } |
| 4559 | |
| 4560 | if (sta_pcp_start(dut, conn, cmd) < 0) { |
| 4561 | send_resp(dut, conn, SIGMA_ERROR, |
| 4562 | "ErrorCode, Can't start PCP role"); |
| 4563 | return -1; |
| 4564 | } |
| 4565 | |
| 4566 | return sta_set_60g_common(dut, conn, cmd); |
| 4567 | } |
| 4568 | |
| 4569 | |
| 4570 | static int sta_set_60g_sta(struct sigma_dut *dut, struct sigma_conn *conn, |
| 4571 | struct sigma_cmd *cmd) |
| 4572 | { |
| 4573 | const char *val = get_param(cmd, "DiscoveryMode"); |
| 4574 | |
| 4575 | if (dut->dev_role != DEVROLE_STA) { |
| 4576 | send_resp(dut, conn, SIGMA_INVALID, |
| 4577 | "ErrorCode,Invalid DevRole"); |
| 4578 | return 0; |
| 4579 | } |
| 4580 | |
| 4581 | if (val) { |
| 4582 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Discovery: %s", val); |
| 4583 | /* Ignore Discovery mode till Driver expose API. */ |
| 4584 | #if 0 |
| 4585 | if (strcasecmp(val, "1") == 0) { |
| 4586 | send_resp(dut, conn, SIGMA_INVALID, |
| 4587 | "ErrorCode,DiscoveryMode 1 not supported"); |
| 4588 | return 0; |
| 4589 | } |
| 4590 | |
| 4591 | if (strcasecmp(val, "0") == 0) { |
| 4592 | /* OK */ |
| 4593 | } else { |
| 4594 | send_resp(dut, conn, SIGMA_INVALID, |
| 4595 | "ErrorCode,DiscoveryMode not supported"); |
| 4596 | return 0; |
| 4597 | } |
| 4598 | #endif |
| 4599 | } |
| 4600 | |
| 4601 | if (start_sta_mode(dut) != 0) |
| 4602 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; |
| 4603 | return sta_set_60g_common(dut, conn, cmd); |
| 4604 | } |
| 4605 | |
| 4606 | |
| 4607 | static int cmd_sta_disconnect(struct sigma_dut *dut, struct sigma_conn *conn, |
| 4608 | struct sigma_cmd *cmd) |
| 4609 | { |
| 4610 | const char *intf = get_param(cmd, "Interface"); |
vamsi krishna | d605c42 | 2017-09-20 14:56:31 +0530 | [diff] [blame] | 4611 | |
| 4612 | if (dut->program == PROGRAM_OCE) { |
| 4613 | wpa_command(intf, "DISCONNECT"); |
| 4614 | return 1; |
| 4615 | } |
| 4616 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4617 | disconnect_station(dut); |
| 4618 | /* Try to ignore old scan results to avoid HS 2.0R2 test case failures |
| 4619 | * due to cached results. */ |
| 4620 | wpa_command(intf, "SET ignore_old_scan_res 1"); |
| 4621 | wpa_command(intf, "BSS_FLUSH"); |
| 4622 | return 1; |
| 4623 | } |
| 4624 | |
| 4625 | |
| 4626 | static int cmd_sta_reassoc(struct sigma_dut *dut, struct sigma_conn *conn, |
| 4627 | struct sigma_cmd *cmd) |
| 4628 | { |
| 4629 | const char *intf = get_param(cmd, "Interface"); |
| 4630 | const char *bssid = get_param(cmd, "bssid"); |
| 4631 | const char *val = get_param(cmd, "CHANNEL"); |
| 4632 | struct wpa_ctrl *ctrl; |
| 4633 | char buf[100]; |
| 4634 | int res; |
| 4635 | int chan = 0; |
Ashwini Patil | 467efef | 2017-05-25 12:18:27 +0530 | [diff] [blame] | 4636 | int status = 0; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4637 | |
| 4638 | if (bssid == NULL) { |
| 4639 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing bssid " |
| 4640 | "argument"); |
| 4641 | return 0; |
| 4642 | } |
| 4643 | |
| 4644 | if (val) |
| 4645 | chan = atoi(val); |
| 4646 | |
| 4647 | if (wifi_chip_type != DRIVER_WCN && wifi_chip_type != DRIVER_AR6003) { |
| 4648 | /* The current network may be from sta_associate or |
| 4649 | * sta_hs2_associate |
| 4650 | */ |
| 4651 | if (set_network(intf, dut->infra_network_id, "bssid", bssid) < |
| 4652 | 0 || |
| 4653 | set_network(intf, 0, "bssid", bssid) < 0) |
| 4654 | return -2; |
| 4655 | } |
| 4656 | |
| 4657 | ctrl = open_wpa_mon(intf); |
| 4658 | if (ctrl == NULL) { |
| 4659 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open " |
| 4660 | "wpa_supplicant monitor connection"); |
| 4661 | return -1; |
| 4662 | } |
| 4663 | |
| 4664 | if (wifi_chip_type == DRIVER_WCN) { |
| 4665 | #ifdef ANDROID |
Ashwini Patil | 4c8158f | 2017-05-25 12:49:21 +0530 | [diff] [blame] | 4666 | if (chan) { |
| 4667 | unsigned int freq; |
| 4668 | |
| 4669 | freq = channel_to_freq(chan); |
| 4670 | if (!freq) { |
| 4671 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4672 | "Invalid channel number provided: %d", |
| 4673 | chan); |
| 4674 | send_resp(dut, conn, SIGMA_INVALID, |
| 4675 | "ErrorCode,Invalid channel number"); |
| 4676 | goto close_mon_conn; |
| 4677 | } |
| 4678 | res = snprintf(buf, sizeof(buf), |
| 4679 | "SCAN TYPE=ONLY freq=%d", freq); |
| 4680 | } else { |
| 4681 | res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY"); |
| 4682 | } |
| 4683 | if (res < 0 || res >= (int) sizeof(buf)) { |
| 4684 | send_resp(dut, conn, SIGMA_ERROR, |
| 4685 | "ErrorCode,snprintf failed"); |
| 4686 | goto close_mon_conn; |
| 4687 | } |
| 4688 | if (wpa_command(intf, buf) < 0) { |
| 4689 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 4690 | "Failed to start scan"); |
| 4691 | send_resp(dut, conn, SIGMA_ERROR, |
| 4692 | "ErrorCode,scan failed"); |
| 4693 | goto close_mon_conn; |
| 4694 | } |
| 4695 | |
| 4696 | res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS", |
| 4697 | buf, sizeof(buf)); |
| 4698 | if (res < 0) { |
| 4699 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 4700 | "Scan did not complete"); |
| 4701 | send_resp(dut, conn, SIGMA_ERROR, |
| 4702 | "ErrorCode,scan did not complete"); |
| 4703 | goto close_mon_conn; |
| 4704 | } |
| 4705 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4706 | if (set_network(intf, dut->infra_network_id, "bssid", "any") |
| 4707 | < 0) { |
| 4708 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set " |
| 4709 | "bssid to any during FASTREASSOC"); |
Ashwini Patil | 467efef | 2017-05-25 12:18:27 +0530 | [diff] [blame] | 4710 | status = -2; |
| 4711 | goto close_mon_conn; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4712 | } |
| 4713 | res = snprintf(buf, sizeof(buf), "DRIVER FASTREASSOC %s %d", |
| 4714 | bssid, chan); |
| 4715 | if (res > 0 && res < (int) sizeof(buf)) |
| 4716 | res = wpa_command(intf, buf); |
| 4717 | |
| 4718 | if (res < 0 || res >= (int) sizeof(buf)) { |
| 4719 | send_resp(dut, conn, SIGMA_ERROR, |
| 4720 | "errorCode,Failed to run DRIVER FASTREASSOC"); |
Ashwini Patil | 467efef | 2017-05-25 12:18:27 +0530 | [diff] [blame] | 4721 | goto close_mon_conn; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4722 | } |
| 4723 | #else /* ANDROID */ |
| 4724 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 4725 | "Reassoc using iwpriv - skip chan=%d info", |
| 4726 | chan); |
| 4727 | snprintf(buf, sizeof(buf), "iwpriv %s reassoc", intf); |
| 4728 | if (system(buf) != 0) { |
| 4729 | sigma_dut_print(dut, DUT_MSG_ERROR, "%s failed", buf); |
Ashwini Patil | 467efef | 2017-05-25 12:18:27 +0530 | [diff] [blame] | 4730 | status = -2; |
| 4731 | goto close_mon_conn; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4732 | } |
| 4733 | #endif /* ANDROID */ |
| 4734 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 4735 | "sta_reassoc: Run %s successful", buf); |
| 4736 | } else if (wpa_command(intf, "REASSOCIATE")) { |
| 4737 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to " |
| 4738 | "request reassociation"); |
Ashwini Patil | 467efef | 2017-05-25 12:18:27 +0530 | [diff] [blame] | 4739 | goto close_mon_conn; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4740 | } |
| 4741 | |
| 4742 | res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED", |
| 4743 | buf, sizeof(buf)); |
Ashwini Patil | 467efef | 2017-05-25 12:18:27 +0530 | [diff] [blame] | 4744 | if (res < 0) { |
| 4745 | sigma_dut_print(dut, DUT_MSG_INFO, "Connection did not complete"); |
| 4746 | status = -1; |
| 4747 | goto close_mon_conn; |
| 4748 | } |
| 4749 | status = 1; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4750 | |
Ashwini Patil | 467efef | 2017-05-25 12:18:27 +0530 | [diff] [blame] | 4751 | close_mon_conn: |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4752 | wpa_ctrl_detach(ctrl); |
| 4753 | wpa_ctrl_close(ctrl); |
Ashwini Patil | 467efef | 2017-05-25 12:18:27 +0530 | [diff] [blame] | 4754 | return status; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4755 | } |
| 4756 | |
| 4757 | |
| 4758 | static void hs2_clear_credentials(const char *intf) |
| 4759 | { |
| 4760 | wpa_command(intf, "REMOVE_CRED all"); |
| 4761 | } |
| 4762 | |
| 4763 | |
Lior David | cc88b56 | 2017-01-03 18:52:09 +0200 | [diff] [blame] | 4764 | #ifdef __linux__ |
| 4765 | static int wil6210_get_aid(struct sigma_dut *dut, const char *bssid, |
| 4766 | unsigned int *aid) |
| 4767 | { |
Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 4768 | const char *pattern = "AID[ \t]+([0-9]+)"; |
Lior David | cc88b56 | 2017-01-03 18:52:09 +0200 | [diff] [blame] | 4769 | |
Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 4770 | return wil6210_get_sta_info_field(dut, bssid, pattern, aid); |
Lior David | cc88b56 | 2017-01-03 18:52:09 +0200 | [diff] [blame] | 4771 | } |
| 4772 | #endif /* __linux__ */ |
| 4773 | |
| 4774 | |
| 4775 | static int sta_get_aid_60g(struct sigma_dut *dut, const char *bssid, |
| 4776 | unsigned int *aid) |
| 4777 | { |
| 4778 | switch (get_driver_type()) { |
| 4779 | #ifdef __linux__ |
| 4780 | case DRIVER_WIL6210: |
| 4781 | return wil6210_get_aid(dut, bssid, aid); |
| 4782 | #endif /* __linux__ */ |
| 4783 | default: |
| 4784 | sigma_dut_print(dut, DUT_MSG_ERROR, "get AID not supported"); |
| 4785 | return -1; |
| 4786 | } |
| 4787 | } |
| 4788 | |
| 4789 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4790 | static int sta_get_parameter_60g(struct sigma_dut *dut, struct sigma_conn *conn, |
| 4791 | struct sigma_cmd *cmd) |
| 4792 | { |
| 4793 | char buf[MAX_CMD_LEN]; |
| 4794 | char bss_list[MAX_CMD_LEN]; |
| 4795 | const char *parameter = get_param(cmd, "Parameter"); |
| 4796 | |
| 4797 | if (parameter == NULL) |
| 4798 | return -1; |
| 4799 | |
Lior David | cc88b56 | 2017-01-03 18:52:09 +0200 | [diff] [blame] | 4800 | if (strcasecmp(parameter, "AID") == 0) { |
| 4801 | unsigned int aid = 0; |
| 4802 | char bssid[20]; |
| 4803 | |
| 4804 | if (get_wpa_status(get_station_ifname(), "bssid", |
| 4805 | bssid, sizeof(bssid)) < 0) { |
| 4806 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4807 | "could not get bssid"); |
| 4808 | return -2; |
| 4809 | } |
| 4810 | |
| 4811 | if (sta_get_aid_60g(dut, bssid, &aid)) |
| 4812 | return -2; |
| 4813 | |
| 4814 | snprintf(buf, sizeof(buf), "aid,%d", aid); |
| 4815 | sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf); |
| 4816 | send_resp(dut, conn, SIGMA_COMPLETE, buf); |
| 4817 | return 0; |
| 4818 | } |
| 4819 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4820 | if (strcasecmp(parameter, "DiscoveredDevList") == 0) { |
| 4821 | char *bss_line; |
| 4822 | char *bss_id = NULL; |
| 4823 | const char *ifname = get_param(cmd, "Interface"); |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 4824 | char *saveptr; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4825 | |
| 4826 | if (ifname == NULL) { |
| 4827 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 4828 | "For get DiscoveredDevList need Interface name."); |
| 4829 | return -1; |
| 4830 | } |
| 4831 | |
| 4832 | /* |
| 4833 | * Use "BSS RANGE=ALL MASK=0x2" which provides a list |
| 4834 | * of BSSIDs in "bssid=<BSSID>\n" |
| 4835 | */ |
| 4836 | if (wpa_command_resp(ifname, "BSS RANGE=ALL MASK=0x2", |
| 4837 | bss_list, |
| 4838 | sizeof(bss_list)) < 0) { |
| 4839 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4840 | "Failed to get bss list"); |
| 4841 | return -1; |
| 4842 | } |
| 4843 | |
| 4844 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 4845 | "bss list for ifname:%s is:%s", |
| 4846 | ifname, bss_list); |
| 4847 | |
| 4848 | snprintf(buf, sizeof(buf), "DeviceList"); |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 4849 | bss_line = strtok_r(bss_list, "\n", &saveptr); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4850 | while (bss_line) { |
| 4851 | if (sscanf(bss_line, "bssid=%ms", &bss_id) > 0 && |
| 4852 | bss_id) { |
| 4853 | int len; |
| 4854 | |
| 4855 | len = snprintf(buf + strlen(buf), |
| 4856 | sizeof(buf) - strlen(buf), |
| 4857 | ",%s", bss_id); |
| 4858 | free(bss_id); |
| 4859 | bss_id = NULL; |
| 4860 | if (len < 0) { |
| 4861 | sigma_dut_print(dut, |
| 4862 | DUT_MSG_ERROR, |
| 4863 | "Failed to read BSSID"); |
| 4864 | send_resp(dut, conn, SIGMA_ERROR, |
| 4865 | "ErrorCode,Failed to read BSS ID"); |
| 4866 | return 0; |
| 4867 | } |
| 4868 | |
| 4869 | if ((size_t) len >= sizeof(buf) - strlen(buf)) { |
| 4870 | sigma_dut_print(dut, |
| 4871 | DUT_MSG_ERROR, |
| 4872 | "Response buf too small for list"); |
| 4873 | send_resp(dut, conn, |
| 4874 | SIGMA_ERROR, |
| 4875 | "ErrorCode,Response buf too small for list"); |
| 4876 | return 0; |
| 4877 | } |
| 4878 | } |
| 4879 | |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 4880 | bss_line = strtok_r(NULL, "\n", &saveptr); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4881 | } |
| 4882 | |
| 4883 | sigma_dut_print(dut, DUT_MSG_INFO, "DiscoveredDevList is %s", |
| 4884 | buf); |
| 4885 | send_resp(dut, conn, SIGMA_COMPLETE, buf); |
| 4886 | return 0; |
| 4887 | } |
| 4888 | |
| 4889 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter"); |
| 4890 | return 0; |
| 4891 | } |
| 4892 | |
| 4893 | |
| 4894 | static int cmd_sta_get_parameter(struct sigma_dut *dut, struct sigma_conn *conn, |
| 4895 | struct sigma_cmd *cmd) |
| 4896 | { |
| 4897 | const char *program = get_param(cmd, "Program"); |
| 4898 | |
| 4899 | if (program == NULL) |
| 4900 | return -1; |
| 4901 | |
| 4902 | if (strcasecmp(program, "P2PNFC") == 0) |
| 4903 | return p2p_cmd_sta_get_parameter(dut, conn, cmd); |
| 4904 | |
| 4905 | if (strcasecmp(program, "60ghz") == 0) |
| 4906 | return sta_get_parameter_60g(dut, conn, cmd); |
| 4907 | |
| 4908 | #ifdef ANDROID_NAN |
| 4909 | if (strcasecmp(program, "NAN") == 0) |
Amarnath Hullur Subramanyam | 1854ec6 | 2016-08-11 19:29:35 -0700 | [diff] [blame] | 4910 | return nan_cmd_sta_get_parameter(dut, conn, cmd); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4911 | #endif /* ANDROID_NAN */ |
| 4912 | |
Amarnath Hullur Subramanyam | 9c381f5 | 2017-03-17 00:04:41 -0700 | [diff] [blame] | 4913 | #ifdef MIRACAST |
| 4914 | if (strcasecmp(program, "WFD") == 0 || |
| 4915 | strcasecmp(program, "DisplayR2") == 0) |
| 4916 | return miracast_cmd_sta_get_parameter(dut, conn, cmd); |
| 4917 | #endif /* MIRACAST */ |
| 4918 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4919 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter"); |
| 4920 | return 0; |
| 4921 | } |
| 4922 | |
| 4923 | |
| 4924 | static void sta_reset_default_ath(struct sigma_dut *dut, const char *intf, |
| 4925 | const char *type) |
| 4926 | { |
| 4927 | char buf[100]; |
| 4928 | |
| 4929 | if (dut->program == PROGRAM_VHT) { |
| 4930 | snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf); |
| 4931 | if (system(buf) != 0) { |
| 4932 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4933 | "iwpriv %s chwidth failed", intf); |
| 4934 | } |
| 4935 | |
| 4936 | snprintf(buf, sizeof(buf), "iwpriv %s mode 11ACVHT80", intf); |
| 4937 | if (system(buf) != 0) { |
| 4938 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4939 | "iwpriv %s mode 11ACVHT80 failed", |
| 4940 | intf); |
| 4941 | } |
| 4942 | |
| 4943 | snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs -1", intf); |
| 4944 | if (system(buf) != 0) { |
| 4945 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4946 | "iwpriv %s vhtmcs -1 failed", intf); |
| 4947 | } |
| 4948 | } |
| 4949 | |
| 4950 | if (dut->program == PROGRAM_HT) { |
| 4951 | snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf); |
| 4952 | if (system(buf) != 0) { |
| 4953 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4954 | "iwpriv %s chwidth failed", intf); |
| 4955 | } |
| 4956 | |
| 4957 | snprintf(buf, sizeof(buf), "iwpriv %s mode 11naht40", intf); |
| 4958 | if (system(buf) != 0) { |
| 4959 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4960 | "iwpriv %s mode 11naht40 failed", |
| 4961 | intf); |
| 4962 | } |
| 4963 | |
| 4964 | snprintf(buf, sizeof(buf), "iwpriv %s set11NRates 0", intf); |
| 4965 | if (system(buf) != 0) { |
| 4966 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4967 | "iwpriv set11NRates failed"); |
| 4968 | } |
| 4969 | } |
| 4970 | |
| 4971 | if (dut->program == PROGRAM_VHT || dut->program == PROGRAM_HT) { |
| 4972 | snprintf(buf, sizeof(buf), "iwpriv %s powersave 0", intf); |
| 4973 | if (system(buf) != 0) { |
| 4974 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4975 | "disabling powersave failed"); |
| 4976 | } |
| 4977 | |
| 4978 | /* Reset CTS width */ |
| 4979 | snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 54 0", |
| 4980 | intf); |
| 4981 | if (system(buf) != 0) { |
| 4982 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4983 | "wifitool %s beeliner_fw_test 54 0 failed", |
| 4984 | intf); |
| 4985 | } |
| 4986 | |
| 4987 | /* Enable Dynamic Bandwidth signalling by default */ |
| 4988 | snprintf(buf, sizeof(buf), "iwpriv %s cwmenable 1", intf); |
| 4989 | if (system(buf) != 0) { |
| 4990 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4991 | "iwpriv %s cwmenable 1 failed", intf); |
| 4992 | } |
| 4993 | |
| 4994 | snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", intf); |
| 4995 | if (system(buf) != 0) { |
| 4996 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4997 | "iwpriv rts failed"); |
| 4998 | } |
| 4999 | } |
| 5000 | |
| 5001 | if (type && strcasecmp(type, "Testbed") == 0) { |
| 5002 | dut->testbed_flag_txsp = 1; |
| 5003 | dut->testbed_flag_rxsp = 1; |
| 5004 | /* STA has to set spatial stream to 2 per Appendix H */ |
| 5005 | snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0xfff0", intf); |
| 5006 | if (system(buf) != 0) { |
| 5007 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5008 | "iwpriv vht_mcsmap failed"); |
| 5009 | } |
| 5010 | |
| 5011 | /* Disable LDPC per Appendix H */ |
| 5012 | snprintf(buf, sizeof(buf), "iwpriv %s ldpc 0", intf); |
| 5013 | if (system(buf) != 0) { |
| 5014 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5015 | "iwpriv %s ldpc 0 failed", intf); |
| 5016 | } |
| 5017 | |
| 5018 | snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf); |
| 5019 | if (system(buf) != 0) { |
| 5020 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5021 | "iwpriv amsdu failed"); |
| 5022 | } |
| 5023 | |
| 5024 | /* TODO: Disable STBC 2x1 transmit and receive */ |
| 5025 | snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc 0", intf); |
| 5026 | if (system(buf) != 0) { |
| 5027 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5028 | "Disable tx_stbc 0 failed"); |
| 5029 | } |
| 5030 | |
| 5031 | snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc 0", intf); |
| 5032 | if (system(buf) != 0) { |
| 5033 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5034 | "Disable rx_stbc 0 failed"); |
| 5035 | } |
| 5036 | |
| 5037 | /* STA has to disable Short GI per Appendix H */ |
| 5038 | snprintf(buf, sizeof(buf), "iwpriv %s shortgi 0", intf); |
| 5039 | if (system(buf) != 0) { |
| 5040 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5041 | "iwpriv %s shortgi 0 failed", intf); |
| 5042 | } |
| 5043 | } |
| 5044 | |
| 5045 | if (type && strcasecmp(type, "DUT") == 0) { |
| 5046 | snprintf(buf, sizeof(buf), "iwpriv %s nss 3", intf); |
| 5047 | if (system(buf) != 0) { |
| 5048 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5049 | "iwpriv %s nss 3 failed", intf); |
| 5050 | } |
| 5051 | |
| 5052 | snprintf(buf, sizeof(buf), "iwpriv %s shortgi 1", intf); |
| 5053 | if (system(buf) != 0) { |
| 5054 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5055 | "iwpriv %s shortgi 1 failed", intf); |
| 5056 | } |
| 5057 | } |
| 5058 | } |
| 5059 | |
| 5060 | |
| 5061 | static int cmd_sta_reset_default(struct sigma_dut *dut, |
| 5062 | struct sigma_conn *conn, |
| 5063 | struct sigma_cmd *cmd) |
| 5064 | { |
| 5065 | int cmd_sta_p2p_reset(struct sigma_dut *dut, struct sigma_conn *conn, |
| 5066 | struct sigma_cmd *cmd); |
| 5067 | const char *intf = get_param(cmd, "Interface"); |
| 5068 | const char *type; |
Amarnath Hullur Subramanyam | 9c381f5 | 2017-03-17 00:04:41 -0700 | [diff] [blame] | 5069 | const char *program = get_param(cmd, "program"); |
Ankita Bajaj | 0d5825b | 2017-10-25 16:20:17 +0530 | [diff] [blame] | 5070 | const char *dev_role = get_param(cmd, "DevRole"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5071 | |
Amarnath Hullur Subramanyam | 9c381f5 | 2017-03-17 00:04:41 -0700 | [diff] [blame] | 5072 | if (!program) |
| 5073 | program = get_param(cmd, "prog"); |
| 5074 | dut->program = sigma_program_to_enum(program); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5075 | dut->device_type = STA_unknown; |
| 5076 | type = get_param(cmd, "type"); |
| 5077 | if (type && strcasecmp(type, "Testbed") == 0) |
| 5078 | dut->device_type = STA_testbed; |
| 5079 | if (type && strcasecmp(type, "DUT") == 0) |
| 5080 | dut->device_type = STA_dut; |
| 5081 | |
| 5082 | if (dut->program == PROGRAM_TDLS) { |
| 5083 | /* Clear TDLS testing mode */ |
| 5084 | wpa_command(intf, "SET tdls_disabled 0"); |
| 5085 | wpa_command(intf, "SET tdls_testing 0"); |
| 5086 | dut->no_tpk_expiration = 0; |
Pradeep Reddy POTTETI | 8ce2a23 | 2016-10-28 12:17:32 +0530 | [diff] [blame] | 5087 | if (get_driver_type() == DRIVER_WCN) { |
| 5088 | /* Enable the WCN driver in TDLS Explicit trigger mode |
| 5089 | */ |
| 5090 | wpa_command(intf, "SET tdls_external_control 0"); |
| 5091 | wpa_command(intf, "SET tdls_trigger_control 0"); |
| 5092 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5093 | } |
| 5094 | |
Amarnath Hullur Subramanyam | 9c381f5 | 2017-03-17 00:04:41 -0700 | [diff] [blame] | 5095 | #ifdef MIRACAST |
| 5096 | if (dut->program == PROGRAM_WFD || |
| 5097 | dut->program == PROGRAM_DISPLAYR2) |
| 5098 | miracast_sta_reset_default(dut, conn, cmd); |
| 5099 | #endif /* MIRACAST */ |
| 5100 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5101 | switch (get_driver_type()) { |
| 5102 | case DRIVER_ATHEROS: |
| 5103 | sta_reset_default_ath(dut, intf, type); |
| 5104 | break; |
| 5105 | default: |
| 5106 | break; |
| 5107 | } |
| 5108 | |
| 5109 | #ifdef ANDROID_NAN |
| 5110 | if (dut->program == PROGRAM_NAN) |
| 5111 | nan_cmd_sta_reset_default(dut, conn, cmd); |
| 5112 | #endif /* ANDROID_NAN */ |
| 5113 | |
| 5114 | if (dut->program == PROGRAM_HS2_R2) { |
| 5115 | unlink("SP/wi-fi.org/pps.xml"); |
| 5116 | if (system("rm -r SP/*") != 0) { |
| 5117 | } |
| 5118 | unlink("next-client-cert.pem"); |
| 5119 | unlink("next-client-key.pem"); |
| 5120 | } |
| 5121 | |
| 5122 | if (dut->program == PROGRAM_60GHZ) { |
| 5123 | const char *dev_role = get_param(cmd, "DevRole"); |
| 5124 | |
| 5125 | if (!dev_role) { |
| 5126 | send_resp(dut, conn, SIGMA_ERROR, |
| 5127 | "errorCode,Missing DevRole argument"); |
| 5128 | return 0; |
| 5129 | } |
| 5130 | |
| 5131 | if (strcasecmp(dev_role, "STA") == 0) |
| 5132 | dut->dev_role = DEVROLE_STA; |
| 5133 | else if (strcasecmp(dev_role, "PCP") == 0) |
| 5134 | dut->dev_role = DEVROLE_PCP; |
| 5135 | else { |
| 5136 | send_resp(dut, conn, SIGMA_ERROR, |
| 5137 | "errorCode,Unknown DevRole"); |
| 5138 | return 0; |
| 5139 | } |
| 5140 | |
| 5141 | if (dut->device_type == STA_unknown) { |
| 5142 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5143 | "Device type is not STA testbed or DUT"); |
| 5144 | send_resp(dut, conn, SIGMA_ERROR, |
| 5145 | "errorCode,Unknown device type"); |
| 5146 | return 0; |
| 5147 | } |
| 5148 | } |
| 5149 | |
| 5150 | wpa_command(intf, "WPS_ER_STOP"); |
| 5151 | wpa_command(intf, "FLUSH"); |
vamsi krishna | f39bc1e | 2017-08-23 17:37:53 +0530 | [diff] [blame] | 5152 | wpa_command(intf, "ERP_FLUSH"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5153 | wpa_command(intf, "SET radio_disabled 0"); |
| 5154 | |
| 5155 | if (dut->tmp_mac_addr && dut->set_macaddr) { |
| 5156 | dut->tmp_mac_addr = 0; |
| 5157 | if (system(dut->set_macaddr) != 0) { |
| 5158 | sigma_dut_print(dut, DUT_MSG_INFO, "Failed to clear " |
| 5159 | "temporary MAC address"); |
| 5160 | } |
| 5161 | } |
| 5162 | |
| 5163 | set_ps(intf, dut, 0); |
| 5164 | |
| 5165 | if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2) { |
| 5166 | wpa_command(intf, "SET interworking 1"); |
| 5167 | wpa_command(intf, "SET hs20 1"); |
| 5168 | } |
| 5169 | |
| 5170 | if (dut->program == PROGRAM_HS2_R2) { |
| 5171 | wpa_command(intf, "SET pmf 1"); |
| 5172 | } else { |
| 5173 | wpa_command(intf, "SET pmf 0"); |
| 5174 | } |
| 5175 | |
| 5176 | hs2_clear_credentials(intf); |
| 5177 | wpa_command(intf, "SET hessid 00:00:00:00:00:00"); |
| 5178 | wpa_command(intf, "SET access_network_type 15"); |
| 5179 | |
| 5180 | static_ip_file(0, NULL, NULL, NULL); |
| 5181 | kill_dhcp_client(dut, intf); |
| 5182 | clear_ip_addr(dut, intf); |
| 5183 | |
| 5184 | dut->er_oper_performed = 0; |
| 5185 | dut->er_oper_bssid[0] = '\0'; |
| 5186 | |
priyadharshini gowthaman | ad6cbba | 2016-10-04 10:39:58 -0700 | [diff] [blame] | 5187 | if (dut->program == PROGRAM_LOC) { |
| 5188 | /* Disable Interworking by default */ |
| 5189 | wpa_command(get_station_ifname(), "SET interworking 0"); |
| 5190 | } |
| 5191 | |
Ashwini Patil | 0040258 | 2017-04-13 12:29:39 +0530 | [diff] [blame] | 5192 | if (dut->program == PROGRAM_MBO) { |
| 5193 | free(dut->non_pref_ch_list); |
| 5194 | dut->non_pref_ch_list = NULL; |
Ashwini Patil | 5acd738 | 2017-04-13 15:55:04 +0530 | [diff] [blame] | 5195 | free(dut->btm_query_cand_list); |
| 5196 | dut->btm_query_cand_list = NULL; |
Ashwini Patil | c63161e | 2017-04-13 16:30:23 +0530 | [diff] [blame] | 5197 | wpa_command(intf, "SET reject_btm_req_reason 0"); |
Ashwini Patil | a75de5a | 2017-04-13 16:35:05 +0530 | [diff] [blame] | 5198 | wpa_command(intf, "SET ignore_assoc_disallow 0"); |
Ashwini Patil | d174f2c | 2017-04-13 16:49:46 +0530 | [diff] [blame] | 5199 | wpa_command(intf, "SET gas_address3 0"); |
Ashwini Patil | 9183fdb | 2017-04-13 16:58:25 +0530 | [diff] [blame] | 5200 | wpa_command(intf, "SET roaming 1"); |
Ashwini Patil | 0040258 | 2017-04-13 12:29:39 +0530 | [diff] [blame] | 5201 | } |
| 5202 | |
Jouni Malinen | 3c367e8 | 2017-06-23 17:01:47 +0300 | [diff] [blame] | 5203 | free(dut->rsne_override); |
| 5204 | dut->rsne_override = NULL; |
| 5205 | |
Jouni Malinen | 6814313 | 2017-09-02 02:34:08 +0300 | [diff] [blame] | 5206 | free(dut->sae_commit_override); |
| 5207 | dut->sae_commit_override = NULL; |
| 5208 | |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 5209 | dut->dpp_conf_id = -1; |
Jouni Malinen | b1dd21f | 2017-11-13 19:14:29 +0200 | [diff] [blame] | 5210 | free(dut->dpp_peer_uri); |
| 5211 | dut->dpp_peer_uri = NULL; |
Jouni Malinen | 63d5041 | 2017-11-24 11:55:38 +0200 | [diff] [blame] | 5212 | dut->dpp_local_bootstrap = -1; |
Jouni Malinen | 5011fb5 | 2017-12-05 21:00:15 +0200 | [diff] [blame] | 5213 | wpa_command(intf, "SET dpp_config_processing 2"); |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 5214 | |
Jouni Malinen | fac9cad | 2017-10-10 18:35:55 +0300 | [diff] [blame] | 5215 | wpa_command(intf, "VENDOR_ELEM_REMOVE 13 *"); |
| 5216 | |
vamsi krishna | a279949 | 2017-12-05 14:28:01 +0530 | [diff] [blame] | 5217 | if (dut->program == PROGRAM_OCE) { |
Ankita Bajaj | a2cb567 | 2017-10-25 16:08:28 +0530 | [diff] [blame] | 5218 | wpa_command(intf, "SET oce 1"); |
vamsi krishna | a279949 | 2017-12-05 14:28:01 +0530 | [diff] [blame] | 5219 | wpa_command(intf, "SET disable_fils 0"); |
| 5220 | } |
Ankita Bajaj | a2cb567 | 2017-10-25 16:08:28 +0530 | [diff] [blame] | 5221 | |
Ankita Bajaj | 0d5825b | 2017-10-25 16:20:17 +0530 | [diff] [blame] | 5222 | if (dev_role && strcasecmp(dev_role, "STA-CFON") == 0) { |
| 5223 | dut->dev_role = DEVROLE_STA_CFON; |
| 5224 | return sta_cfon_reset_default(dut, conn, cmd); |
| 5225 | } |
| 5226 | |
Priyadharshini Gowthaman | a7dfd49 | 2015-11-09 14:34:08 -0800 | [diff] [blame] | 5227 | if (dut->program != PROGRAM_VHT) |
| 5228 | return cmd_sta_p2p_reset(dut, conn, cmd); |
| 5229 | return 1; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5230 | } |
| 5231 | |
| 5232 | |
| 5233 | static int cmd_sta_get_events(struct sigma_dut *dut, struct sigma_conn *conn, |
| 5234 | struct sigma_cmd *cmd) |
| 5235 | { |
| 5236 | const char *program = get_param(cmd, "Program"); |
| 5237 | |
| 5238 | if (program == NULL) |
| 5239 | return -1; |
| 5240 | #ifdef ANDROID_NAN |
| 5241 | if (strcasecmp(program, "NAN") == 0) |
| 5242 | return nan_cmd_sta_get_events(dut, conn, cmd); |
| 5243 | #endif /* ANDROID_NAN */ |
| 5244 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter"); |
| 5245 | return 0; |
| 5246 | } |
| 5247 | |
| 5248 | |
| 5249 | static int cmd_sta_exec_action(struct sigma_dut *dut, struct sigma_conn *conn, |
| 5250 | struct sigma_cmd *cmd) |
| 5251 | { |
| 5252 | const char *program = get_param(cmd, "Prog"); |
| 5253 | |
| 5254 | if (program == NULL) |
| 5255 | return -1; |
| 5256 | #ifdef ANDROID_NAN |
| 5257 | if (strcasecmp(program, "NAN") == 0) |
| 5258 | return nan_cmd_sta_exec_action(dut, conn, cmd); |
| 5259 | #endif /* ANDROID_NAN */ |
priyadharshini gowthaman | d66913a | 2016-07-29 15:11:17 -0700 | [diff] [blame] | 5260 | if (strcasecmp(program, "Loc") == 0) |
| 5261 | return loc_cmd_sta_exec_action(dut, conn, cmd); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5262 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter"); |
| 5263 | return 0; |
| 5264 | } |
| 5265 | |
| 5266 | |
| 5267 | static int cmd_sta_set_11n(struct sigma_dut *dut, struct sigma_conn *conn, |
| 5268 | struct sigma_cmd *cmd) |
| 5269 | { |
| 5270 | const char *intf = get_param(cmd, "Interface"); |
| 5271 | const char *val, *mcs32, *rate; |
| 5272 | |
| 5273 | val = get_param(cmd, "GREENFIELD"); |
| 5274 | if (val) { |
| 5275 | if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) { |
| 5276 | /* Enable GD */ |
| 5277 | send_resp(dut, conn, SIGMA_ERROR, |
| 5278 | "ErrorCode,GF not supported"); |
| 5279 | return 0; |
| 5280 | } |
| 5281 | } |
| 5282 | |
| 5283 | val = get_param(cmd, "SGI20"); |
| 5284 | if (val) { |
| 5285 | switch (get_driver_type()) { |
| 5286 | case DRIVER_ATHEROS: |
| 5287 | ath_sta_set_sgi(dut, intf, val); |
| 5288 | break; |
| 5289 | default: |
| 5290 | send_resp(dut, conn, SIGMA_ERROR, |
| 5291 | "ErrorCode,SGI20 not supported"); |
| 5292 | return 0; |
| 5293 | } |
| 5294 | } |
| 5295 | |
| 5296 | mcs32 = get_param(cmd, "MCS32"); /* HT Duplicate Mode Enable/Disable */ |
| 5297 | rate = get_param(cmd, "MCS_FIXEDRATE"); /* Fixed MCS rate (0..31) */ |
| 5298 | if (mcs32 && rate) { |
| 5299 | /* TODO */ |
| 5300 | send_resp(dut, conn, SIGMA_ERROR, |
| 5301 | "ErrorCode,MCS32,MCS_FIXEDRATE not supported"); |
| 5302 | return 0; |
| 5303 | } else if (mcs32 && !rate) { |
| 5304 | /* TODO */ |
| 5305 | send_resp(dut, conn, SIGMA_ERROR, |
| 5306 | "ErrorCode,MCS32 not supported"); |
| 5307 | return 0; |
| 5308 | } else if (!mcs32 && rate) { |
| 5309 | switch (get_driver_type()) { |
| 5310 | case DRIVER_ATHEROS: |
priyadharshini gowthaman | e5e2517 | 2015-12-08 14:53:48 -0800 | [diff] [blame] | 5311 | novap_reset(dut, intf); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5312 | ath_sta_set_11nrates(dut, intf, rate); |
| 5313 | break; |
| 5314 | default: |
| 5315 | send_resp(dut, conn, SIGMA_ERROR, |
| 5316 | "ErrorCode,MCS32_FIXEDRATE not supported"); |
| 5317 | return 0; |
| 5318 | } |
| 5319 | } |
| 5320 | |
| 5321 | return cmd_sta_set_wireless_common(intf, dut, conn, cmd); |
| 5322 | } |
| 5323 | |
| 5324 | |
| 5325 | static int cmd_sta_set_wireless_vht(struct sigma_dut *dut, |
| 5326 | struct sigma_conn *conn, |
| 5327 | struct sigma_cmd *cmd) |
| 5328 | { |
| 5329 | const char *intf = get_param(cmd, "Interface"); |
| 5330 | const char *val; |
| 5331 | char buf[30]; |
| 5332 | int tkip = -1; |
| 5333 | int wep = -1; |
| 5334 | |
| 5335 | val = get_param(cmd, "SGI80"); |
| 5336 | if (val) { |
| 5337 | int sgi80; |
| 5338 | |
| 5339 | sgi80 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0; |
| 5340 | snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d", intf, sgi80); |
| 5341 | if (system(buf) != 0) { |
| 5342 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5343 | "iwpriv shortgi failed"); |
| 5344 | } |
| 5345 | } |
| 5346 | |
| 5347 | val = get_param(cmd, "TxBF"); |
| 5348 | if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) { |
| 5349 | snprintf(buf, sizeof(buf), "iwpriv %s vhtsubfee 1", intf); |
| 5350 | if (system(buf) != 0) { |
| 5351 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5352 | "iwpriv vhtsubfee failed"); |
| 5353 | } |
| 5354 | snprintf(buf, sizeof(buf), "iwpriv %s vhtsubfer 1", intf); |
| 5355 | if (system(buf) != 0) { |
| 5356 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5357 | "iwpriv vhtsubfer failed"); |
| 5358 | } |
| 5359 | } |
| 5360 | |
| 5361 | val = get_param(cmd, "MU_TxBF"); |
| 5362 | if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) { |
| 5363 | switch (get_driver_type()) { |
| 5364 | case DRIVER_ATHEROS: |
| 5365 | ath_sta_set_txsp_stream(dut, intf, "1SS"); |
| 5366 | ath_sta_set_rxsp_stream(dut, intf, "1SS"); |
| 5367 | case DRIVER_WCN: |
| 5368 | if (wcn_sta_set_sp_stream(dut, intf, "1SS") < 0) { |
| 5369 | send_resp(dut, conn, SIGMA_ERROR, |
| 5370 | "ErrorCode,Failed to set RX/TXSP_STREAM"); |
| 5371 | return 0; |
| 5372 | } |
| 5373 | default: |
| 5374 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5375 | "Setting SP_STREAM not supported"); |
| 5376 | break; |
| 5377 | } |
| 5378 | snprintf(buf, sizeof(buf), "iwpriv %s vhtmubfee 1", intf); |
| 5379 | if (system(buf) != 0) { |
| 5380 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5381 | "iwpriv vhtmubfee failed"); |
| 5382 | } |
| 5383 | snprintf(buf, sizeof(buf), "iwpriv %s vhtmubfer 1", intf); |
| 5384 | if (system(buf) != 0) { |
| 5385 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5386 | "iwpriv vhtmubfer failed"); |
| 5387 | } |
| 5388 | } |
| 5389 | |
| 5390 | val = get_param(cmd, "LDPC"); |
| 5391 | if (val) { |
| 5392 | int ldpc; |
| 5393 | |
| 5394 | ldpc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0; |
| 5395 | snprintf(buf, sizeof(buf), "iwpriv %s ldpc %d", intf, ldpc); |
| 5396 | if (system(buf) != 0) { |
| 5397 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5398 | "iwpriv ldpc failed"); |
| 5399 | } |
| 5400 | } |
| 5401 | |
| 5402 | val = get_param(cmd, "opt_md_notif_ie"); |
| 5403 | if (val) { |
| 5404 | char *result = NULL; |
| 5405 | char delim[] = ";"; |
| 5406 | char token[30]; |
| 5407 | int value, config_val = 0; |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 5408 | char *saveptr; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5409 | |
Peng Xu | b8fc5cc | 2017-05-10 17:27:28 -0700 | [diff] [blame] | 5410 | strlcpy(token, val, sizeof(token)); |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 5411 | result = strtok_r(token, delim, &saveptr); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5412 | |
| 5413 | /* Extract the NSS information */ |
| 5414 | if (result) { |
| 5415 | value = atoi(result); |
| 5416 | switch (value) { |
| 5417 | case 1: |
| 5418 | config_val = 1; |
| 5419 | break; |
| 5420 | case 2: |
| 5421 | config_val = 3; |
| 5422 | break; |
| 5423 | case 3: |
| 5424 | config_val = 7; |
| 5425 | break; |
| 5426 | case 4: |
| 5427 | config_val = 15; |
| 5428 | break; |
| 5429 | default: |
| 5430 | config_val = 3; |
| 5431 | break; |
| 5432 | } |
| 5433 | |
| 5434 | snprintf(buf, sizeof(buf), "iwpriv %s rxchainmask %d", |
| 5435 | intf, config_val); |
| 5436 | if (system(buf) != 0) { |
| 5437 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5438 | "iwpriv rxchainmask failed"); |
| 5439 | } |
| 5440 | |
| 5441 | snprintf(buf, sizeof(buf), "iwpriv %s txchainmask %d", |
| 5442 | intf, config_val); |
| 5443 | if (system(buf) != 0) { |
| 5444 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5445 | "iwpriv txchainmask failed"); |
| 5446 | } |
| 5447 | } |
| 5448 | |
| 5449 | /* Extract the channel width information */ |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 5450 | result = strtok_r(NULL, delim, &saveptr); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5451 | if (result) { |
| 5452 | value = atoi(result); |
| 5453 | switch (value) { |
| 5454 | case 20: |
| 5455 | config_val = 0; |
| 5456 | break; |
| 5457 | case 40: |
| 5458 | config_val = 1; |
| 5459 | break; |
| 5460 | case 80: |
| 5461 | config_val = 2; |
| 5462 | break; |
| 5463 | case 160: |
| 5464 | config_val = 3; |
| 5465 | break; |
| 5466 | default: |
| 5467 | config_val = 2; |
| 5468 | break; |
| 5469 | } |
| 5470 | |
| 5471 | dut->chwidth = config_val; |
| 5472 | |
| 5473 | snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d", |
| 5474 | intf, config_val); |
| 5475 | if (system(buf) != 0) { |
| 5476 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5477 | "iwpriv chwidth failed"); |
| 5478 | } |
| 5479 | } |
| 5480 | |
| 5481 | snprintf(buf, sizeof(buf), "iwpriv %s opmode_notify 1", intf); |
| 5482 | if (system(buf) != 0) { |
| 5483 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5484 | "iwpriv opmode_notify failed"); |
| 5485 | } |
| 5486 | } |
| 5487 | |
| 5488 | val = get_param(cmd, "nss_mcs_cap"); |
| 5489 | if (val) { |
| 5490 | int nss, mcs; |
| 5491 | char token[20]; |
| 5492 | char *result = NULL; |
| 5493 | unsigned int vht_mcsmap = 0; |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 5494 | char *saveptr; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5495 | |
Peng Xu | b8fc5cc | 2017-05-10 17:27:28 -0700 | [diff] [blame] | 5496 | strlcpy(token, val, sizeof(token)); |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 5497 | result = strtok_r(token, ";", &saveptr); |
Pradeep Reddy POTTETI | cd649a2 | 2016-01-29 12:55:59 +0530 | [diff] [blame] | 5498 | if (!result) { |
| 5499 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5500 | "VHT NSS not specified"); |
| 5501 | return 0; |
| 5502 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5503 | nss = atoi(result); |
| 5504 | |
| 5505 | snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss); |
| 5506 | if (system(buf) != 0) { |
| 5507 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5508 | "iwpriv nss failed"); |
| 5509 | } |
| 5510 | |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 5511 | result = strtok_r(NULL, ";", &saveptr); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5512 | if (result == NULL) { |
| 5513 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5514 | "VHTMCS NOT SPECIFIED!"); |
| 5515 | return 0; |
| 5516 | } |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 5517 | result = strtok_r(result, "-", &saveptr); |
| 5518 | result = strtok_r(NULL, "-", &saveptr); |
Pradeep Reddy POTTETI | cd649a2 | 2016-01-29 12:55:59 +0530 | [diff] [blame] | 5519 | if (!result) { |
| 5520 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5521 | "VHT MCS not specified"); |
| 5522 | return 0; |
| 5523 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5524 | mcs = atoi(result); |
| 5525 | |
| 5526 | snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs %d", intf, mcs); |
| 5527 | if (system(buf) != 0) { |
| 5528 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5529 | "iwpriv mcs failed"); |
| 5530 | } |
| 5531 | |
| 5532 | switch (nss) { |
| 5533 | case 1: |
| 5534 | switch (mcs) { |
| 5535 | case 7: |
| 5536 | vht_mcsmap = 0xfffc; |
| 5537 | break; |
| 5538 | case 8: |
| 5539 | vht_mcsmap = 0xfffd; |
| 5540 | break; |
| 5541 | case 9: |
| 5542 | vht_mcsmap = 0xfffe; |
| 5543 | break; |
| 5544 | default: |
| 5545 | vht_mcsmap = 0xfffe; |
| 5546 | break; |
| 5547 | } |
| 5548 | break; |
| 5549 | case 2: |
| 5550 | switch (mcs) { |
| 5551 | case 7: |
| 5552 | vht_mcsmap = 0xfff0; |
| 5553 | break; |
| 5554 | case 8: |
| 5555 | vht_mcsmap = 0xfff5; |
| 5556 | break; |
| 5557 | case 9: |
| 5558 | vht_mcsmap = 0xfffa; |
| 5559 | break; |
| 5560 | default: |
| 5561 | vht_mcsmap = 0xfffa; |
| 5562 | break; |
| 5563 | } |
| 5564 | break; |
| 5565 | case 3: |
| 5566 | switch (mcs) { |
| 5567 | case 7: |
| 5568 | vht_mcsmap = 0xffc0; |
| 5569 | break; |
| 5570 | case 8: |
| 5571 | vht_mcsmap = 0xffd5; |
| 5572 | break; |
| 5573 | case 9: |
| 5574 | vht_mcsmap = 0xffea; |
| 5575 | break; |
| 5576 | default: |
| 5577 | vht_mcsmap = 0xffea; |
| 5578 | break; |
| 5579 | } |
| 5580 | break; |
| 5581 | default: |
| 5582 | vht_mcsmap = 0xffea; |
| 5583 | break; |
| 5584 | } |
| 5585 | snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0x%04x", |
| 5586 | intf, vht_mcsmap); |
| 5587 | if (system(buf) != 0) { |
| 5588 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5589 | "iwpriv vht_mcsmap failed"); |
| 5590 | } |
| 5591 | } |
| 5592 | |
| 5593 | /* UNSUPPORTED: val = get_param(cmd, "Tx_lgi_rate"); */ |
| 5594 | |
| 5595 | val = get_param(cmd, "Vht_tkip"); |
| 5596 | if (val) |
| 5597 | tkip = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0; |
| 5598 | |
| 5599 | val = get_param(cmd, "Vht_wep"); |
| 5600 | if (val) |
| 5601 | wep = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0; |
| 5602 | |
| 5603 | if (tkip != -1 || wep != -1) { |
| 5604 | if ((tkip == 1 && wep != 0) || (wep == 1 && tkip != 0)) { |
| 5605 | snprintf(buf, sizeof(buf), "iwpriv %s htweptkip 1", |
| 5606 | intf); |
| 5607 | } else if ((tkip == 0 && wep != 1) || (wep == 0 && tkip != 1)) { |
| 5608 | snprintf(buf, sizeof(buf), "iwpriv %s htweptkip 0", |
| 5609 | intf); |
| 5610 | } else { |
| 5611 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5612 | "ErrorCode,mixed mode of VHT TKIP/WEP not supported"); |
| 5613 | return 0; |
| 5614 | } |
| 5615 | |
| 5616 | if (system(buf) != 0) { |
| 5617 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5618 | "iwpriv htweptkip failed"); |
| 5619 | } |
| 5620 | } |
| 5621 | |
| 5622 | val = get_param(cmd, "txBandwidth"); |
| 5623 | if (val) { |
| 5624 | switch (get_driver_type()) { |
| 5625 | case DRIVER_ATHEROS: |
| 5626 | if (ath_set_width(dut, conn, intf, val) < 0) { |
| 5627 | send_resp(dut, conn, SIGMA_ERROR, |
| 5628 | "ErrorCode,Failed to set txBandwidth"); |
| 5629 | return 0; |
| 5630 | } |
| 5631 | break; |
| 5632 | default: |
| 5633 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5634 | "Setting txBandwidth not supported"); |
| 5635 | break; |
| 5636 | } |
| 5637 | } |
| 5638 | |
| 5639 | return cmd_sta_set_wireless_common(intf, dut, conn, cmd); |
| 5640 | } |
| 5641 | |
| 5642 | |
| 5643 | static int sta_set_wireless_60g(struct sigma_dut *dut, |
| 5644 | struct sigma_conn *conn, |
| 5645 | struct sigma_cmd *cmd) |
| 5646 | { |
| 5647 | const char *dev_role = get_param(cmd, "DevRole"); |
| 5648 | |
| 5649 | if (!dev_role) { |
| 5650 | send_resp(dut, conn, SIGMA_INVALID, |
| 5651 | "ErrorCode,DevRole not specified"); |
| 5652 | return 0; |
| 5653 | } |
| 5654 | |
| 5655 | if (strcasecmp(dev_role, "PCP") == 0) |
| 5656 | return sta_set_60g_pcp(dut, conn, cmd); |
| 5657 | if (strcasecmp(dev_role, "STA") == 0) |
| 5658 | return sta_set_60g_sta(dut, conn, cmd); |
| 5659 | send_resp(dut, conn, SIGMA_INVALID, |
| 5660 | "ErrorCode,DevRole not supported"); |
| 5661 | return 0; |
| 5662 | } |
| 5663 | |
| 5664 | |
Ankita Bajaj | 0d5825b | 2017-10-25 16:20:17 +0530 | [diff] [blame] | 5665 | static int sta_set_wireless_oce(struct sigma_dut *dut, struct sigma_conn *conn, |
| 5666 | struct sigma_cmd *cmd) |
| 5667 | { |
| 5668 | int status; |
| 5669 | const char *intf = get_param(cmd, "Interface"); |
| 5670 | const char *val = get_param(cmd, "DevRole"); |
| 5671 | |
| 5672 | if (val && strcasecmp(val, "STA-CFON") == 0) { |
| 5673 | status = sta_cfon_set_wireless(dut, conn, cmd); |
| 5674 | if (status) |
| 5675 | return status; |
| 5676 | } |
| 5677 | return cmd_sta_set_wireless_common(intf, dut, conn, cmd); |
| 5678 | } |
| 5679 | |
| 5680 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5681 | static int cmd_sta_set_wireless(struct sigma_dut *dut, struct sigma_conn *conn, |
| 5682 | struct sigma_cmd *cmd) |
| 5683 | { |
| 5684 | const char *val; |
| 5685 | |
| 5686 | val = get_param(cmd, "Program"); |
| 5687 | if (val) { |
| 5688 | if (strcasecmp(val, "11n") == 0) |
| 5689 | return cmd_sta_set_11n(dut, conn, cmd); |
| 5690 | if (strcasecmp(val, "VHT") == 0) |
| 5691 | return cmd_sta_set_wireless_vht(dut, conn, cmd); |
| 5692 | if (strcasecmp(val, "60ghz") == 0) |
| 5693 | return sta_set_wireless_60g(dut, conn, cmd); |
Ankita Bajaj | 0d5825b | 2017-10-25 16:20:17 +0530 | [diff] [blame] | 5694 | if (strcasecmp(val, "OCE") == 0) |
| 5695 | return sta_set_wireless_oce(dut, conn, cmd); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5696 | send_resp(dut, conn, SIGMA_ERROR, |
| 5697 | "ErrorCode,Program value not supported"); |
| 5698 | } else { |
| 5699 | send_resp(dut, conn, SIGMA_ERROR, |
| 5700 | "ErrorCode,Program argument not available"); |
| 5701 | } |
| 5702 | |
| 5703 | return 0; |
| 5704 | } |
| 5705 | |
| 5706 | |
| 5707 | static void ath_sta_inject_frame(struct sigma_dut *dut, const char *intf, |
| 5708 | int tid) |
| 5709 | { |
| 5710 | char buf[100]; |
| 5711 | int tid_to_dscp [] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 }; |
| 5712 | |
Pradeep Reddy POTTETI | d31d132 | 2016-10-13 17:22:03 +0530 | [diff] [blame] | 5713 | if (tid < 0 || |
| 5714 | tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) { |
| 5715 | sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid); |
| 5716 | return; |
| 5717 | } |
| 5718 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5719 | /* |
| 5720 | * Two ways to ensure that addba request with a |
| 5721 | * non zero TID could be sent out. EV 117296 |
| 5722 | */ |
| 5723 | snprintf(buf, sizeof(buf), |
| 5724 | "ping -c 8 -Q %d `arp -a | grep wlan0 | awk '{print $2}' | tr -d '()'`", |
| 5725 | tid); |
| 5726 | if (system(buf) != 0) { |
| 5727 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5728 | "Ping did not send out"); |
| 5729 | } |
| 5730 | |
| 5731 | snprintf(buf, sizeof(buf), |
| 5732 | "iwconfig %s | grep Access | awk '{print $6}' > %s", |
| 5733 | intf, VI_QOS_TMP_FILE); |
| 5734 | if (system(buf) != 0) |
| 5735 | return; |
| 5736 | |
| 5737 | snprintf(buf, sizeof(buf), |
| 5738 | "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s", |
| 5739 | intf, VI_QOS_TMP_FILE); |
| 5740 | if (system(buf) != 0) |
| 5741 | sigma_dut_print(dut, DUT_MSG_ERROR, "HWaddr matching failed"); |
| 5742 | |
| 5743 | snprintf(buf,sizeof(buf), "sed -n '3,$p' %s >> %s", |
| 5744 | VI_QOS_REFFILE, VI_QOS_TMP_FILE); |
| 5745 | if (system(buf) != 0) { |
| 5746 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5747 | "VI_QOS_TEMP_FILE generation error failed"); |
| 5748 | } |
| 5749 | snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s", |
| 5750 | tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE); |
| 5751 | if (system(buf) != 0) { |
| 5752 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5753 | "VI_QOS_FILE generation failed"); |
| 5754 | } |
| 5755 | |
| 5756 | snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s", |
| 5757 | tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE); |
| 5758 | if (system(buf) != 0) { |
| 5759 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5760 | "VI_QOS_FILE generation failed"); |
| 5761 | } |
| 5762 | |
| 5763 | snprintf(buf, sizeof(buf), "ethinject %s %s", intf, VI_QOS_FILE); |
| 5764 | if (system(buf) != 0) { |
| 5765 | } |
| 5766 | } |
| 5767 | |
| 5768 | |
| 5769 | static int ath_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn, |
| 5770 | struct sigma_cmd *cmd) |
| 5771 | { |
| 5772 | const char *intf = get_param(cmd, "Interface"); |
| 5773 | const char *val; |
| 5774 | int tid = 0; |
| 5775 | char buf[100]; |
| 5776 | |
| 5777 | val = get_param(cmd, "TID"); |
| 5778 | if (val) { |
| 5779 | tid = atoi(val); |
| 5780 | if (tid) |
| 5781 | ath_sta_inject_frame(dut, intf, tid); |
| 5782 | } |
| 5783 | |
| 5784 | /* Command sequence for ADDBA request on Peregrine based devices */ |
| 5785 | snprintf(buf, sizeof(buf), "iwpriv %s setaddbaoper 1", intf); |
| 5786 | if (system(buf) != 0) { |
| 5787 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5788 | "iwpriv setaddbaoper failed"); |
| 5789 | } |
| 5790 | |
| 5791 | snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4", intf, tid); |
| 5792 | if (system(buf) != 0) { |
| 5793 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5794 | "wifitool senddelba failed"); |
| 5795 | } |
| 5796 | |
| 5797 | snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64", intf, tid); |
| 5798 | if (system(buf) != 0) { |
| 5799 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5800 | "wifitool sendaddba failed"); |
| 5801 | } |
| 5802 | |
| 5803 | /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */ |
| 5804 | |
| 5805 | return 1; |
| 5806 | } |
| 5807 | |
| 5808 | |
Lior David | 9981b51 | 2017-01-20 13:16:40 +0200 | [diff] [blame] | 5809 | #ifdef __linux__ |
| 5810 | |
| 5811 | static int wil6210_send_addba(struct sigma_dut *dut, const char *dest_mac, |
| 5812 | int agg_size) |
| 5813 | { |
| 5814 | char dir[128], buf[128]; |
| 5815 | FILE *f; |
| 5816 | regex_t re; |
| 5817 | regmatch_t m[2]; |
| 5818 | int rc, ret = -1, vring_id, found; |
| 5819 | |
| 5820 | if (wil6210_get_debugfs_dir(dut, dir, sizeof(dir))) { |
| 5821 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5822 | "failed to get wil6210 debugfs dir"); |
| 5823 | return -1; |
| 5824 | } |
| 5825 | |
| 5826 | snprintf(buf, sizeof(buf), "%s/vrings", dir); |
| 5827 | f = fopen(buf, "r"); |
| 5828 | if (!f) { |
| 5829 | sigma_dut_print(dut, DUT_MSG_ERROR, "failed to open: %s", buf); |
| 5830 | return -1; |
| 5831 | } |
| 5832 | |
| 5833 | if (regcomp(&re, "VRING tx_[ \t]*([0-9]+)", REG_EXTENDED)) { |
| 5834 | sigma_dut_print(dut, DUT_MSG_ERROR, "regcomp failed"); |
| 5835 | goto out; |
| 5836 | } |
| 5837 | |
| 5838 | /* find TX VRING for the mac address */ |
| 5839 | found = 0; |
| 5840 | while (fgets(buf, sizeof(buf), f)) { |
| 5841 | if (strcasestr(buf, dest_mac)) { |
| 5842 | found = 1; |
| 5843 | break; |
| 5844 | } |
| 5845 | } |
| 5846 | |
| 5847 | if (!found) { |
| 5848 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5849 | "no TX VRING for %s", dest_mac); |
| 5850 | goto out; |
| 5851 | } |
| 5852 | |
| 5853 | /* extract VRING ID, "VRING tx_<id> = {" */ |
| 5854 | if (!fgets(buf, sizeof(buf), f)) { |
| 5855 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5856 | "no VRING start line for %s", dest_mac); |
| 5857 | goto out; |
| 5858 | } |
| 5859 | |
| 5860 | rc = regexec(&re, buf, 2, m, 0); |
| 5861 | regfree(&re); |
| 5862 | if (rc || m[1].rm_so < 0) { |
| 5863 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5864 | "no VRING TX ID for %s", dest_mac); |
| 5865 | goto out; |
| 5866 | } |
| 5867 | buf[m[1].rm_eo] = 0; |
| 5868 | vring_id = atoi(&buf[m[1].rm_so]); |
| 5869 | |
| 5870 | /* send the addba command */ |
| 5871 | fclose(f); |
| 5872 | snprintf(buf, sizeof(buf), "%s/back", dir); |
| 5873 | f = fopen(buf, "w"); |
| 5874 | if (!f) { |
| 5875 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5876 | "failed to open: %s", buf); |
| 5877 | return -1; |
| 5878 | } |
| 5879 | |
| 5880 | fprintf(f, "add %d %d\n", vring_id, agg_size); |
| 5881 | |
| 5882 | ret = 0; |
| 5883 | |
| 5884 | out: |
| 5885 | fclose(f); |
| 5886 | |
| 5887 | return ret; |
| 5888 | } |
| 5889 | |
| 5890 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5891 | static int send_addba_60g(struct sigma_dut *dut, struct sigma_conn *conn, |
| 5892 | struct sigma_cmd *cmd) |
| 5893 | { |
| 5894 | const char *val; |
| 5895 | int tid = 0; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5896 | |
| 5897 | val = get_param(cmd, "TID"); |
| 5898 | if (val) { |
| 5899 | tid = atoi(val); |
| 5900 | if (tid != 0) { |
| 5901 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5902 | "Ignore TID %d for send_addba use TID 0 for 60g since only 0 required on TX", |
| 5903 | tid); |
| 5904 | } |
| 5905 | } |
| 5906 | |
| 5907 | val = get_param(cmd, "Dest_mac"); |
| 5908 | if (!val) { |
| 5909 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5910 | "Currently not supporting addba for 60G without Dest_mac"); |
| 5911 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; |
| 5912 | } |
| 5913 | |
Lior David | 9981b51 | 2017-01-20 13:16:40 +0200 | [diff] [blame] | 5914 | if (wil6210_send_addba(dut, val, dut->back_rcv_buf)) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5915 | return -1; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5916 | |
| 5917 | return 1; |
| 5918 | } |
| 5919 | |
Lior David | 9981b51 | 2017-01-20 13:16:40 +0200 | [diff] [blame] | 5920 | #endif /* __linux__ */ |
| 5921 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5922 | |
| 5923 | static int cmd_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn, |
| 5924 | struct sigma_cmd *cmd) |
| 5925 | { |
| 5926 | switch (get_driver_type()) { |
| 5927 | case DRIVER_ATHEROS: |
| 5928 | return ath_sta_send_addba(dut, conn, cmd); |
Lior David | 9981b51 | 2017-01-20 13:16:40 +0200 | [diff] [blame] | 5929 | #ifdef __linux__ |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5930 | case DRIVER_WIL6210: |
| 5931 | return send_addba_60g(dut, conn, cmd); |
Lior David | 9981b51 | 2017-01-20 13:16:40 +0200 | [diff] [blame] | 5932 | #endif /* __linux__ */ |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5933 | default: |
| 5934 | /* |
| 5935 | * There is no driver specific implementation for other drivers. |
| 5936 | * Ignore the command and report COMPLETE since the following |
| 5937 | * throughput test operation will end up sending ADDBA anyway. |
| 5938 | */ |
| 5939 | return 1; |
| 5940 | } |
| 5941 | } |
| 5942 | |
| 5943 | |
| 5944 | int inject_eth_frame(int s, const void *data, size_t len, |
| 5945 | unsigned short ethtype, char *dst, char *src) |
| 5946 | { |
| 5947 | struct iovec iov[4] = { |
| 5948 | { |
| 5949 | .iov_base = dst, |
| 5950 | .iov_len = ETH_ALEN, |
| 5951 | }, |
| 5952 | { |
| 5953 | .iov_base = src, |
| 5954 | .iov_len = ETH_ALEN, |
| 5955 | }, |
| 5956 | { |
| 5957 | .iov_base = ðtype, |
| 5958 | .iov_len = sizeof(unsigned short), |
| 5959 | }, |
| 5960 | { |
| 5961 | .iov_base = (void *) data, |
| 5962 | .iov_len = len, |
| 5963 | } |
| 5964 | }; |
| 5965 | struct msghdr msg = { |
| 5966 | .msg_name = NULL, |
| 5967 | .msg_namelen = 0, |
| 5968 | .msg_iov = iov, |
| 5969 | .msg_iovlen = 4, |
| 5970 | .msg_control = NULL, |
| 5971 | .msg_controllen = 0, |
| 5972 | .msg_flags = 0, |
| 5973 | }; |
| 5974 | |
| 5975 | return sendmsg(s, &msg, 0); |
| 5976 | } |
| 5977 | |
| 5978 | #if defined(__linux__) || defined(__QNXNTO__) |
| 5979 | |
| 5980 | int inject_frame(int s, const void *data, size_t len, int encrypt) |
| 5981 | { |
| 5982 | #define IEEE80211_RADIOTAP_F_WEP 0x04 |
| 5983 | #define IEEE80211_RADIOTAP_F_FRAG 0x08 |
| 5984 | unsigned char rtap_hdr[] = { |
| 5985 | 0x00, 0x00, /* radiotap version */ |
| 5986 | 0x0e, 0x00, /* radiotap length */ |
| 5987 | 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */ |
| 5988 | IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */ |
| 5989 | 0x00, /* padding */ |
| 5990 | 0x00, 0x00, /* RX and TX flags to indicate that */ |
| 5991 | 0x00, 0x00, /* this is the injected frame directly */ |
| 5992 | }; |
| 5993 | struct iovec iov[2] = { |
| 5994 | { |
| 5995 | .iov_base = &rtap_hdr, |
| 5996 | .iov_len = sizeof(rtap_hdr), |
| 5997 | }, |
| 5998 | { |
| 5999 | .iov_base = (void *) data, |
| 6000 | .iov_len = len, |
| 6001 | } |
| 6002 | }; |
| 6003 | struct msghdr msg = { |
| 6004 | .msg_name = NULL, |
| 6005 | .msg_namelen = 0, |
| 6006 | .msg_iov = iov, |
| 6007 | .msg_iovlen = 2, |
| 6008 | .msg_control = NULL, |
| 6009 | .msg_controllen = 0, |
| 6010 | .msg_flags = 0, |
| 6011 | }; |
| 6012 | |
| 6013 | if (encrypt) |
| 6014 | rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP; |
| 6015 | |
| 6016 | return sendmsg(s, &msg, 0); |
| 6017 | } |
| 6018 | |
| 6019 | |
| 6020 | int open_monitor(const char *ifname) |
| 6021 | { |
| 6022 | #ifdef __QNXNTO__ |
| 6023 | struct sockaddr_dl ll; |
| 6024 | int s; |
| 6025 | |
| 6026 | memset(&ll, 0, sizeof(ll)); |
| 6027 | ll.sdl_family = AF_LINK; |
| 6028 | ll.sdl_index = if_nametoindex(ifname); |
| 6029 | if (ll.sdl_index == 0) { |
| 6030 | perror("if_nametoindex"); |
| 6031 | return -1; |
| 6032 | } |
| 6033 | s = socket(PF_INET, SOCK_RAW, 0); |
| 6034 | #else /* __QNXNTO__ */ |
| 6035 | struct sockaddr_ll ll; |
| 6036 | int s; |
| 6037 | |
| 6038 | memset(&ll, 0, sizeof(ll)); |
| 6039 | ll.sll_family = AF_PACKET; |
| 6040 | ll.sll_ifindex = if_nametoindex(ifname); |
| 6041 | if (ll.sll_ifindex == 0) { |
| 6042 | perror("if_nametoindex"); |
| 6043 | return -1; |
| 6044 | } |
| 6045 | s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); |
| 6046 | #endif /* __QNXNTO__ */ |
| 6047 | if (s < 0) { |
| 6048 | perror("socket[PF_PACKET,SOCK_RAW]"); |
| 6049 | return -1; |
| 6050 | } |
| 6051 | |
| 6052 | if (bind(s, (struct sockaddr *) &ll, sizeof(ll)) < 0) { |
| 6053 | perror("monitor socket bind"); |
| 6054 | close(s); |
| 6055 | return -1; |
| 6056 | } |
| 6057 | |
| 6058 | return s; |
| 6059 | } |
| 6060 | |
| 6061 | |
| 6062 | static int hex2num(char c) |
| 6063 | { |
| 6064 | if (c >= '0' && c <= '9') |
| 6065 | return c - '0'; |
| 6066 | if (c >= 'a' && c <= 'f') |
| 6067 | return c - 'a' + 10; |
| 6068 | if (c >= 'A' && c <= 'F') |
| 6069 | return c - 'A' + 10; |
| 6070 | return -1; |
| 6071 | } |
| 6072 | |
| 6073 | |
| 6074 | int hwaddr_aton(const char *txt, unsigned char *addr) |
| 6075 | { |
| 6076 | int i; |
| 6077 | |
| 6078 | for (i = 0; i < 6; i++) { |
| 6079 | int a, b; |
| 6080 | |
| 6081 | a = hex2num(*txt++); |
| 6082 | if (a < 0) |
| 6083 | return -1; |
| 6084 | b = hex2num(*txt++); |
| 6085 | if (b < 0) |
| 6086 | return -1; |
| 6087 | *addr++ = (a << 4) | b; |
| 6088 | if (i < 5 && *txt++ != ':') |
| 6089 | return -1; |
| 6090 | } |
| 6091 | |
| 6092 | return 0; |
| 6093 | } |
| 6094 | |
| 6095 | #endif /* defined(__linux__) || defined(__QNXNTO__) */ |
| 6096 | |
| 6097 | enum send_frame_type { |
| 6098 | DISASSOC, DEAUTH, SAQUERY, AUTH, ASSOCREQ, REASSOCREQ, DLS_REQ |
| 6099 | }; |
| 6100 | enum send_frame_protection { |
| 6101 | CORRECT_KEY, INCORRECT_KEY, UNPROTECTED |
| 6102 | }; |
| 6103 | |
| 6104 | |
| 6105 | static int sta_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn, |
| 6106 | enum send_frame_type frame, |
| 6107 | enum send_frame_protection protected, |
| 6108 | const char *dest) |
| 6109 | { |
| 6110 | #ifdef __linux__ |
| 6111 | unsigned char buf[1000], *pos; |
| 6112 | int s, res; |
| 6113 | char bssid[20], addr[20]; |
| 6114 | char result[32], ssid[100]; |
| 6115 | size_t ssid_len; |
| 6116 | |
| 6117 | if (get_wpa_status(get_station_ifname(), "wpa_state", result, |
| 6118 | sizeof(result)) < 0 || |
| 6119 | strncmp(result, "COMPLETED", 9) != 0) { |
| 6120 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Not connected"); |
| 6121 | return 0; |
| 6122 | } |
| 6123 | |
| 6124 | if (get_wpa_status(get_station_ifname(), "bssid", bssid, sizeof(bssid)) |
| 6125 | < 0) { |
| 6126 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get " |
| 6127 | "current BSSID"); |
| 6128 | return 0; |
| 6129 | } |
| 6130 | |
| 6131 | if (get_wpa_status(get_station_ifname(), "address", addr, sizeof(addr)) |
| 6132 | < 0) { |
| 6133 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get " |
| 6134 | "own MAC address"); |
| 6135 | return 0; |
| 6136 | } |
| 6137 | |
| 6138 | if (get_wpa_status(get_station_ifname(), "ssid", ssid, sizeof(ssid)) |
| 6139 | < 0) { |
| 6140 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get " |
| 6141 | "current SSID"); |
| 6142 | return 0; |
| 6143 | } |
| 6144 | ssid_len = strlen(ssid); |
| 6145 | |
| 6146 | pos = buf; |
| 6147 | |
| 6148 | /* Frame Control */ |
| 6149 | switch (frame) { |
| 6150 | case DISASSOC: |
| 6151 | *pos++ = 0xa0; |
| 6152 | break; |
| 6153 | case DEAUTH: |
| 6154 | *pos++ = 0xc0; |
| 6155 | break; |
| 6156 | case SAQUERY: |
| 6157 | *pos++ = 0xd0; |
| 6158 | break; |
| 6159 | case AUTH: |
| 6160 | *pos++ = 0xb0; |
| 6161 | break; |
| 6162 | case ASSOCREQ: |
| 6163 | *pos++ = 0x00; |
| 6164 | break; |
| 6165 | case REASSOCREQ: |
| 6166 | *pos++ = 0x20; |
| 6167 | break; |
| 6168 | case DLS_REQ: |
| 6169 | *pos++ = 0xd0; |
| 6170 | break; |
| 6171 | } |
| 6172 | |
| 6173 | if (protected == INCORRECT_KEY) |
| 6174 | *pos++ = 0x40; /* Set Protected field to 1 */ |
| 6175 | else |
| 6176 | *pos++ = 0x00; |
| 6177 | |
| 6178 | /* Duration */ |
| 6179 | *pos++ = 0x00; |
| 6180 | *pos++ = 0x00; |
| 6181 | |
| 6182 | /* addr1 = DA (current AP) */ |
| 6183 | hwaddr_aton(bssid, pos); |
| 6184 | pos += 6; |
| 6185 | /* addr2 = SA (own address) */ |
| 6186 | hwaddr_aton(addr, pos); |
| 6187 | pos += 6; |
| 6188 | /* addr3 = BSSID (current AP) */ |
| 6189 | hwaddr_aton(bssid, pos); |
| 6190 | pos += 6; |
| 6191 | |
| 6192 | /* Seq# (to be filled by driver/mac80211) */ |
| 6193 | *pos++ = 0x00; |
| 6194 | *pos++ = 0x00; |
| 6195 | |
| 6196 | if (protected == INCORRECT_KEY) { |
| 6197 | /* CCMP parameters */ |
| 6198 | memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8); |
| 6199 | pos += 8; |
| 6200 | } |
| 6201 | |
| 6202 | if (protected == INCORRECT_KEY) { |
| 6203 | switch (frame) { |
| 6204 | case DEAUTH: |
| 6205 | /* Reason code (encrypted) */ |
| 6206 | memcpy(pos, "\xa7\x39", 2); |
| 6207 | pos += 2; |
| 6208 | break; |
| 6209 | case DISASSOC: |
| 6210 | /* Reason code (encrypted) */ |
| 6211 | memcpy(pos, "\xa7\x39", 2); |
| 6212 | pos += 2; |
| 6213 | break; |
| 6214 | case SAQUERY: |
| 6215 | /* Category|Action|TransID (encrypted) */ |
| 6216 | memcpy(pos, "\x6f\xbd\xe9\x4d", 4); |
| 6217 | pos += 4; |
| 6218 | break; |
| 6219 | default: |
| 6220 | return -1; |
| 6221 | } |
| 6222 | |
| 6223 | /* CCMP MIC */ |
| 6224 | memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8); |
| 6225 | pos += 8; |
| 6226 | } else { |
| 6227 | switch (frame) { |
| 6228 | case DEAUTH: |
| 6229 | /* reason code = 8 */ |
| 6230 | *pos++ = 0x08; |
| 6231 | *pos++ = 0x00; |
| 6232 | break; |
| 6233 | case DISASSOC: |
| 6234 | /* reason code = 8 */ |
| 6235 | *pos++ = 0x08; |
| 6236 | *pos++ = 0x00; |
| 6237 | break; |
| 6238 | case SAQUERY: |
| 6239 | /* Category - SA Query */ |
| 6240 | *pos++ = 0x08; |
| 6241 | /* SA query Action - Request */ |
| 6242 | *pos++ = 0x00; |
| 6243 | /* Transaction ID */ |
| 6244 | *pos++ = 0x12; |
| 6245 | *pos++ = 0x34; |
| 6246 | break; |
| 6247 | case AUTH: |
| 6248 | /* Auth Alg (Open) */ |
| 6249 | *pos++ = 0x00; |
| 6250 | *pos++ = 0x00; |
| 6251 | /* Seq# */ |
| 6252 | *pos++ = 0x01; |
| 6253 | *pos++ = 0x00; |
| 6254 | /* Status code */ |
| 6255 | *pos++ = 0x00; |
| 6256 | *pos++ = 0x00; |
| 6257 | break; |
| 6258 | case ASSOCREQ: |
| 6259 | /* Capability Information */ |
| 6260 | *pos++ = 0x31; |
| 6261 | *pos++ = 0x04; |
| 6262 | /* Listen Interval */ |
| 6263 | *pos++ = 0x0a; |
| 6264 | *pos++ = 0x00; |
| 6265 | /* SSID */ |
| 6266 | *pos++ = 0x00; |
| 6267 | *pos++ = ssid_len; |
| 6268 | memcpy(pos, ssid, ssid_len); |
| 6269 | pos += ssid_len; |
| 6270 | /* Supported Rates */ |
| 6271 | memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24", |
| 6272 | 10); |
| 6273 | pos += 10; |
| 6274 | /* Extended Supported Rates */ |
| 6275 | memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6); |
| 6276 | pos += 6; |
| 6277 | /* RSN */ |
| 6278 | memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00" |
| 6279 | "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0" |
| 6280 | "\x00\x00\x00\x00\x0f\xac\x06", 28); |
| 6281 | pos += 28; |
| 6282 | break; |
| 6283 | case REASSOCREQ: |
| 6284 | /* Capability Information */ |
| 6285 | *pos++ = 0x31; |
| 6286 | *pos++ = 0x04; |
| 6287 | /* Listen Interval */ |
| 6288 | *pos++ = 0x0a; |
| 6289 | *pos++ = 0x00; |
| 6290 | /* Current AP */ |
| 6291 | hwaddr_aton(bssid, pos); |
| 6292 | pos += 6; |
| 6293 | /* SSID */ |
| 6294 | *pos++ = 0x00; |
| 6295 | *pos++ = ssid_len; |
| 6296 | memcpy(pos, ssid, ssid_len); |
| 6297 | pos += ssid_len; |
| 6298 | /* Supported Rates */ |
| 6299 | memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24", |
| 6300 | 10); |
| 6301 | pos += 10; |
| 6302 | /* Extended Supported Rates */ |
| 6303 | memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6); |
| 6304 | pos += 6; |
| 6305 | /* RSN */ |
| 6306 | memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00" |
| 6307 | "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0" |
| 6308 | "\x00\x00\x00\x00\x0f\xac\x06", 28); |
| 6309 | pos += 28; |
| 6310 | break; |
| 6311 | case DLS_REQ: |
| 6312 | /* Category - DLS */ |
| 6313 | *pos++ = 0x02; |
| 6314 | /* DLS Action - Request */ |
| 6315 | *pos++ = 0x00; |
| 6316 | /* Destination MACAddress */ |
| 6317 | if (dest) |
| 6318 | hwaddr_aton(dest, pos); |
| 6319 | else |
| 6320 | memset(pos, 0, 6); |
| 6321 | pos += 6; |
| 6322 | /* Source MACAddress */ |
| 6323 | hwaddr_aton(addr, pos); |
| 6324 | pos += 6; |
| 6325 | /* Capability Information */ |
| 6326 | *pos++ = 0x10; /* Privacy */ |
| 6327 | *pos++ = 0x06; /* QoS */ |
| 6328 | /* DLS Timeout Value */ |
| 6329 | *pos++ = 0x00; |
| 6330 | *pos++ = 0x01; |
| 6331 | /* Supported rates */ |
| 6332 | *pos++ = 0x01; |
| 6333 | *pos++ = 0x08; |
| 6334 | *pos++ = 0x0c; /* 6 Mbps */ |
| 6335 | *pos++ = 0x12; /* 9 Mbps */ |
| 6336 | *pos++ = 0x18; /* 12 Mbps */ |
| 6337 | *pos++ = 0x24; /* 18 Mbps */ |
| 6338 | *pos++ = 0x30; /* 24 Mbps */ |
| 6339 | *pos++ = 0x48; /* 36 Mbps */ |
| 6340 | *pos++ = 0x60; /* 48 Mbps */ |
| 6341 | *pos++ = 0x6c; /* 54 Mbps */ |
| 6342 | /* TODO: Extended Supported Rates */ |
| 6343 | /* TODO: HT Capabilities */ |
| 6344 | break; |
| 6345 | } |
| 6346 | } |
| 6347 | |
| 6348 | s = open_monitor("sigmadut"); |
| 6349 | if (s < 0) { |
| 6350 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open " |
| 6351 | "monitor socket"); |
| 6352 | return 0; |
| 6353 | } |
| 6354 | |
| 6355 | res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY); |
| 6356 | if (res < 0) { |
| 6357 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to " |
| 6358 | "inject frame"); |
Pradeep Reddy POTTETI | 673d85c | 2016-07-26 19:08:07 +0530 | [diff] [blame] | 6359 | close(s); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6360 | return 0; |
| 6361 | } |
| 6362 | if (res < pos - buf) { |
| 6363 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Only partial " |
| 6364 | "frame sent"); |
Pradeep Reddy POTTETI | 673d85c | 2016-07-26 19:08:07 +0530 | [diff] [blame] | 6365 | close(s); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6366 | return 0; |
| 6367 | } |
| 6368 | |
| 6369 | close(s); |
| 6370 | |
| 6371 | return 1; |
| 6372 | #else /* __linux__ */ |
| 6373 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,sta_send_frame not " |
| 6374 | "yet supported"); |
| 6375 | return 0; |
| 6376 | #endif /* __linux__ */ |
| 6377 | } |
| 6378 | |
| 6379 | |
| 6380 | static int cmd_sta_send_frame_tdls(struct sigma_dut *dut, |
| 6381 | struct sigma_conn *conn, |
| 6382 | struct sigma_cmd *cmd) |
| 6383 | { |
| 6384 | const char *intf = get_param(cmd, "Interface"); |
| 6385 | const char *sta, *val; |
| 6386 | unsigned char addr[ETH_ALEN]; |
| 6387 | char buf[100]; |
| 6388 | |
| 6389 | sta = get_param(cmd, "peer"); |
| 6390 | if (sta == NULL) |
| 6391 | sta = get_param(cmd, "station"); |
| 6392 | if (sta == NULL) { |
| 6393 | send_resp(dut, conn, SIGMA_ERROR, |
| 6394 | "ErrorCode,Missing peer address"); |
| 6395 | return 0; |
| 6396 | } |
| 6397 | if (hwaddr_aton(sta, addr) < 0) { |
| 6398 | send_resp(dut, conn, SIGMA_ERROR, |
| 6399 | "ErrorCode,Invalid peer address"); |
| 6400 | return 0; |
| 6401 | } |
| 6402 | |
| 6403 | val = get_param(cmd, "type"); |
| 6404 | if (val == NULL) |
| 6405 | return -1; |
| 6406 | |
| 6407 | if (strcasecmp(val, "DISCOVERY") == 0) { |
| 6408 | snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", sta); |
| 6409 | if (wpa_command(intf, buf) < 0) { |
| 6410 | send_resp(dut, conn, SIGMA_ERROR, |
| 6411 | "ErrorCode,Failed to send TDLS discovery"); |
| 6412 | return 0; |
| 6413 | } |
| 6414 | return 1; |
| 6415 | } |
| 6416 | |
| 6417 | if (strcasecmp(val, "SETUP") == 0) { |
| 6418 | int status = 0, timeout = 0; |
| 6419 | |
| 6420 | val = get_param(cmd, "Status"); |
| 6421 | if (val) |
| 6422 | status = atoi(val); |
| 6423 | |
| 6424 | val = get_param(cmd, "Timeout"); |
| 6425 | if (val) |
| 6426 | timeout = atoi(val); |
| 6427 | |
| 6428 | if (status != 0 && status != 37) { |
| 6429 | send_resp(dut, conn, SIGMA_ERROR, |
| 6430 | "ErrorCode,Unsupported status value"); |
| 6431 | return 0; |
| 6432 | } |
| 6433 | |
| 6434 | if (timeout != 0 && timeout != 301) { |
| 6435 | send_resp(dut, conn, SIGMA_ERROR, |
| 6436 | "ErrorCode,Unsupported timeout value"); |
| 6437 | return 0; |
| 6438 | } |
| 6439 | |
| 6440 | if (status && timeout) { |
| 6441 | send_resp(dut, conn, SIGMA_ERROR, |
| 6442 | "ErrorCode,Unsupported timeout+status " |
| 6443 | "combination"); |
| 6444 | return 0; |
| 6445 | } |
| 6446 | |
| 6447 | if (status == 37 && |
| 6448 | wpa_command(intf, "SET tdls_testing 0x200")) { |
| 6449 | send_resp(dut, conn, SIGMA_ERROR, |
| 6450 | "ErrorCode,Failed to enable " |
| 6451 | "decline setup response test mode"); |
| 6452 | return 0; |
| 6453 | } |
| 6454 | |
| 6455 | if (timeout == 301) { |
| 6456 | int res; |
| 6457 | if (dut->no_tpk_expiration) |
| 6458 | res = wpa_command(intf, |
| 6459 | "SET tdls_testing 0x108"); |
| 6460 | else |
| 6461 | res = wpa_command(intf, |
| 6462 | "SET tdls_testing 0x8"); |
| 6463 | if (res) { |
| 6464 | send_resp(dut, conn, SIGMA_ERROR, |
| 6465 | "ErrorCode,Failed to set short TPK " |
| 6466 | "lifetime"); |
| 6467 | return 0; |
| 6468 | } |
| 6469 | } |
| 6470 | |
| 6471 | snprintf(buf, sizeof(buf), "TDLS_SETUP %s", sta); |
| 6472 | if (wpa_command(intf, buf) < 0) { |
| 6473 | send_resp(dut, conn, SIGMA_ERROR, |
| 6474 | "ErrorCode,Failed to send TDLS setup"); |
| 6475 | return 0; |
| 6476 | } |
| 6477 | return 1; |
| 6478 | } |
| 6479 | |
| 6480 | if (strcasecmp(val, "TEARDOWN") == 0) { |
| 6481 | snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", sta); |
| 6482 | if (wpa_command(intf, buf) < 0) { |
| 6483 | send_resp(dut, conn, SIGMA_ERROR, |
| 6484 | "ErrorCode,Failed to send TDLS teardown"); |
| 6485 | return 0; |
| 6486 | } |
| 6487 | return 1; |
| 6488 | } |
| 6489 | |
| 6490 | send_resp(dut, conn, SIGMA_ERROR, |
| 6491 | "ErrorCode,Unsupported TDLS frame"); |
| 6492 | return 0; |
| 6493 | } |
| 6494 | |
| 6495 | |
| 6496 | static int sta_ap_known(const char *ifname, const char *bssid) |
| 6497 | { |
| 6498 | char buf[4096]; |
| 6499 | |
| 6500 | snprintf(buf, sizeof(buf), "BSS %s", bssid); |
| 6501 | if (wpa_command_resp(ifname, buf, buf, sizeof(buf)) < 0) |
| 6502 | return 0; |
| 6503 | if (strncmp(buf, "id=", 3) != 0) |
| 6504 | return 0; |
| 6505 | return 1; |
| 6506 | } |
| 6507 | |
| 6508 | |
| 6509 | static int sta_scan_ap(struct sigma_dut *dut, const char *ifname, |
| 6510 | const char *bssid) |
| 6511 | { |
| 6512 | int res; |
| 6513 | struct wpa_ctrl *ctrl; |
| 6514 | char buf[256]; |
| 6515 | |
| 6516 | if (sta_ap_known(ifname, bssid)) |
| 6517 | return 0; |
| 6518 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 6519 | "AP not in BSS table - start scan"); |
| 6520 | |
| 6521 | ctrl = open_wpa_mon(ifname); |
| 6522 | if (ctrl == NULL) { |
| 6523 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open " |
| 6524 | "wpa_supplicant monitor connection"); |
| 6525 | return -1; |
| 6526 | } |
| 6527 | |
| 6528 | if (wpa_command(ifname, "SCAN") < 0) { |
| 6529 | sigma_dut_print(dut, DUT_MSG_INFO, "Failed to start scan"); |
| 6530 | wpa_ctrl_detach(ctrl); |
| 6531 | wpa_ctrl_close(ctrl); |
| 6532 | return -1; |
| 6533 | } |
| 6534 | |
| 6535 | res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS", |
| 6536 | buf, sizeof(buf)); |
| 6537 | |
| 6538 | wpa_ctrl_detach(ctrl); |
| 6539 | wpa_ctrl_close(ctrl); |
| 6540 | |
| 6541 | if (res < 0) { |
| 6542 | sigma_dut_print(dut, DUT_MSG_INFO, "Scan did not complete"); |
| 6543 | return -1; |
| 6544 | } |
| 6545 | |
| 6546 | if (sta_ap_known(ifname, bssid)) |
| 6547 | return 0; |
| 6548 | sigma_dut_print(dut, DUT_MSG_INFO, "AP not in BSS table"); |
| 6549 | return -1; |
| 6550 | } |
| 6551 | |
| 6552 | |
| 6553 | static int cmd_sta_send_frame_hs2_neighadv(struct sigma_dut *dut, |
| 6554 | struct sigma_conn *conn, |
| 6555 | struct sigma_cmd *cmd, |
| 6556 | const char *intf) |
| 6557 | { |
| 6558 | char buf[200]; |
| 6559 | |
| 6560 | snprintf(buf, sizeof(buf), "ndsend 2001:DB8::1 %s", intf); |
| 6561 | if (system(buf) != 0) { |
| 6562 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Failed to run " |
| 6563 | "ndsend"); |
| 6564 | return 0; |
| 6565 | } |
| 6566 | |
| 6567 | return 1; |
| 6568 | } |
| 6569 | |
| 6570 | |
| 6571 | static int cmd_sta_send_frame_hs2_neighsolreq(struct sigma_dut *dut, |
| 6572 | struct sigma_conn *conn, |
| 6573 | struct sigma_cmd *cmd, |
| 6574 | const char *intf) |
| 6575 | { |
| 6576 | char buf[200]; |
| 6577 | const char *ip = get_param(cmd, "SenderIP"); |
| 6578 | |
Peng Xu | 26b356d | 2017-10-04 17:58:16 -0700 | [diff] [blame] | 6579 | if (!ip) |
| 6580 | return 0; |
| 6581 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6582 | snprintf(buf, sizeof(buf), "ndisc6 -nm %s %s -r 4", ip, intf); |
| 6583 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 6584 | if (system(buf) == 0) { |
| 6585 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 6586 | "Neighbor Solicitation got a response " |
| 6587 | "for %s@%s", ip, intf); |
| 6588 | } |
| 6589 | |
| 6590 | return 1; |
| 6591 | } |
| 6592 | |
| 6593 | |
| 6594 | static int cmd_sta_send_frame_hs2_arpprobe(struct sigma_dut *dut, |
| 6595 | struct sigma_conn *conn, |
| 6596 | struct sigma_cmd *cmd, |
| 6597 | const char *ifname) |
| 6598 | { |
| 6599 | char buf[200]; |
| 6600 | const char *ip = get_param(cmd, "SenderIP"); |
| 6601 | |
| 6602 | if (ip == NULL) { |
| 6603 | send_resp(dut, conn, SIGMA_ERROR, |
| 6604 | "ErrorCode,Missing SenderIP parameter"); |
| 6605 | return 0; |
| 6606 | } |
| 6607 | snprintf(buf, sizeof(buf), "arping -I %s -D %s -c 4", ifname, ip); |
| 6608 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 6609 | if (system(buf) != 0) { |
| 6610 | sigma_dut_print(dut, DUT_MSG_INFO, "arping DAD got a response " |
| 6611 | "for %s@%s", ip, ifname); |
| 6612 | } |
| 6613 | |
| 6614 | return 1; |
| 6615 | } |
| 6616 | |
| 6617 | |
| 6618 | static int cmd_sta_send_frame_hs2_arpannounce(struct sigma_dut *dut, |
| 6619 | struct sigma_conn *conn, |
| 6620 | struct sigma_cmd *cmd, |
| 6621 | const char *ifname) |
| 6622 | { |
| 6623 | char buf[200]; |
| 6624 | char ip[16]; |
| 6625 | int s; |
Peng Xu | b375688 | 2017-10-04 14:39:09 -0700 | [diff] [blame] | 6626 | struct ifreq ifr; |
| 6627 | struct sockaddr_in saddr; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6628 | |
| 6629 | s = socket(PF_INET, SOCK_DGRAM, 0); |
Peng Xu | b375688 | 2017-10-04 14:39:09 -0700 | [diff] [blame] | 6630 | if (s < 0) { |
| 6631 | perror("socket"); |
| 6632 | return -1; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6633 | } |
| 6634 | |
Peng Xu | b375688 | 2017-10-04 14:39:09 -0700 | [diff] [blame] | 6635 | memset(&ifr, 0, sizeof(ifr)); |
| 6636 | strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); |
| 6637 | if (ioctl(s, SIOCGIFADDR, &ifr) < 0) { |
| 6638 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 6639 | "Failed to get %s IP address: %s", |
| 6640 | ifname, strerror(errno)); |
| 6641 | close(s); |
| 6642 | return -1; |
| 6643 | } |
| 6644 | close(s); |
| 6645 | |
| 6646 | memcpy(&saddr, &ifr.ifr_addr, sizeof(struct sockaddr_in)); |
| 6647 | strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip)); |
| 6648 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6649 | snprintf(buf, sizeof(buf), "arping -I %s -s %s %s -c 4", ifname, ip, |
| 6650 | ip); |
| 6651 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 6652 | if (system(buf) != 0) { |
| 6653 | } |
| 6654 | |
| 6655 | return 1; |
| 6656 | } |
| 6657 | |
| 6658 | |
| 6659 | static int cmd_sta_send_frame_hs2_arpreply(struct sigma_dut *dut, |
| 6660 | struct sigma_conn *conn, |
| 6661 | struct sigma_cmd *cmd, |
| 6662 | const char *ifname) |
| 6663 | { |
| 6664 | char buf[200], addr[20]; |
| 6665 | char dst[ETH_ALEN], src[ETH_ALEN]; |
| 6666 | short ethtype = htons(ETH_P_ARP); |
| 6667 | char *pos; |
| 6668 | int s, res; |
| 6669 | const char *val; |
| 6670 | struct sockaddr_in taddr; |
| 6671 | |
| 6672 | val = get_param(cmd, "dest"); |
| 6673 | if (val) |
| 6674 | hwaddr_aton(val, (unsigned char *) dst); |
| 6675 | |
| 6676 | val = get_param(cmd, "DestIP"); |
| 6677 | if (val) |
| 6678 | inet_aton(val, &taddr.sin_addr); |
Peng Xu | 151c9e1 | 2017-10-04 14:39:09 -0700 | [diff] [blame] | 6679 | else |
| 6680 | return -2; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6681 | |
| 6682 | if (get_wpa_status(get_station_ifname(), "address", addr, |
| 6683 | sizeof(addr)) < 0) |
| 6684 | return -2; |
| 6685 | hwaddr_aton(addr, (unsigned char *) src); |
| 6686 | |
| 6687 | pos = buf; |
| 6688 | *pos++ = 0x00; |
| 6689 | *pos++ = 0x01; |
| 6690 | *pos++ = 0x08; |
| 6691 | *pos++ = 0x00; |
| 6692 | *pos++ = 0x06; |
| 6693 | *pos++ = 0x04; |
| 6694 | *pos++ = 0x00; |
| 6695 | *pos++ = 0x02; |
| 6696 | memcpy(pos, src, ETH_ALEN); |
| 6697 | pos += ETH_ALEN; |
| 6698 | memcpy(pos, &taddr.sin_addr, 4); |
| 6699 | pos += 4; |
| 6700 | memcpy(pos, dst, ETH_ALEN); |
| 6701 | pos += ETH_ALEN; |
| 6702 | memcpy(pos, &taddr.sin_addr, 4); |
| 6703 | pos += 4; |
| 6704 | |
| 6705 | s = open_monitor(get_station_ifname()); |
| 6706 | if (s < 0) { |
| 6707 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open " |
| 6708 | "monitor socket"); |
| 6709 | return 0; |
| 6710 | } |
| 6711 | |
| 6712 | res = inject_eth_frame(s, buf, pos - buf, ethtype, dst, src); |
| 6713 | if (res < 0) { |
| 6714 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to " |
| 6715 | "inject frame"); |
Pradeep Reddy POTTETI | 673d85c | 2016-07-26 19:08:07 +0530 | [diff] [blame] | 6716 | close(s); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6717 | return 0; |
| 6718 | } |
| 6719 | |
| 6720 | close(s); |
| 6721 | |
| 6722 | return 1; |
| 6723 | } |
| 6724 | |
| 6725 | |
| 6726 | static int cmd_sta_send_frame_hs2_dls_req(struct sigma_dut *dut, |
| 6727 | struct sigma_conn *conn, |
| 6728 | struct sigma_cmd *cmd, |
| 6729 | const char *intf, const char *dest) |
| 6730 | { |
| 6731 | char buf[100]; |
| 6732 | |
| 6733 | if (if_nametoindex("sigmadut") == 0) { |
| 6734 | snprintf(buf, sizeof(buf), |
| 6735 | "iw dev %s interface add sigmadut type monitor", |
| 6736 | get_station_ifname()); |
| 6737 | if (system(buf) != 0 || |
| 6738 | if_nametoindex("sigmadut") == 0) { |
| 6739 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add " |
| 6740 | "monitor interface with '%s'", buf); |
| 6741 | return -2; |
| 6742 | } |
| 6743 | } |
| 6744 | |
| 6745 | if (system("ifconfig sigmadut up") != 0) { |
| 6746 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set " |
| 6747 | "monitor interface up"); |
| 6748 | return -2; |
| 6749 | } |
| 6750 | |
| 6751 | return sta_inject_frame(dut, conn, DLS_REQ, UNPROTECTED, dest); |
| 6752 | } |
| 6753 | |
| 6754 | |
| 6755 | static int cmd_sta_send_frame_hs2(struct sigma_dut *dut, |
| 6756 | struct sigma_conn *conn, |
| 6757 | struct sigma_cmd *cmd) |
| 6758 | { |
| 6759 | const char *intf = get_param(cmd, "Interface"); |
| 6760 | const char *dest = get_param(cmd, "Dest"); |
| 6761 | const char *type = get_param(cmd, "FrameName"); |
| 6762 | const char *val; |
| 6763 | char buf[200], *pos, *end; |
| 6764 | int count, count2; |
| 6765 | |
| 6766 | if (type == NULL) |
| 6767 | type = get_param(cmd, "Type"); |
| 6768 | |
| 6769 | if (intf == NULL || dest == NULL || type == NULL) |
| 6770 | return -1; |
| 6771 | |
| 6772 | if (strcasecmp(type, "NeighAdv") == 0) |
| 6773 | return cmd_sta_send_frame_hs2_neighadv(dut, conn, cmd, intf); |
| 6774 | |
| 6775 | if (strcasecmp(type, "NeighSolicitReq") == 0) |
| 6776 | return cmd_sta_send_frame_hs2_neighsolreq(dut, conn, cmd, intf); |
| 6777 | |
| 6778 | if (strcasecmp(type, "ARPProbe") == 0) |
| 6779 | return cmd_sta_send_frame_hs2_arpprobe(dut, conn, cmd, intf); |
| 6780 | |
| 6781 | if (strcasecmp(type, "ARPAnnounce") == 0) |
| 6782 | return cmd_sta_send_frame_hs2_arpannounce(dut, conn, cmd, intf); |
| 6783 | |
| 6784 | if (strcasecmp(type, "ARPReply") == 0) |
| 6785 | return cmd_sta_send_frame_hs2_arpreply(dut, conn, cmd, intf); |
| 6786 | |
| 6787 | if (strcasecmp(type, "DLS-request") == 0 || |
| 6788 | strcasecmp(type, "DLSrequest") == 0) |
| 6789 | return cmd_sta_send_frame_hs2_dls_req(dut, conn, cmd, intf, |
| 6790 | dest); |
| 6791 | |
| 6792 | if (strcasecmp(type, "ANQPQuery") != 0 && |
| 6793 | strcasecmp(type, "Query") != 0) { |
| 6794 | send_resp(dut, conn, SIGMA_ERROR, |
| 6795 | "ErrorCode,Unsupported HS 2.0 send frame type"); |
| 6796 | return 0; |
| 6797 | } |
| 6798 | |
| 6799 | if (sta_scan_ap(dut, intf, dest) < 0) { |
| 6800 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not find " |
| 6801 | "the requested AP"); |
| 6802 | return 0; |
| 6803 | } |
| 6804 | |
| 6805 | pos = buf; |
| 6806 | end = buf + sizeof(buf); |
| 6807 | count = 0; |
| 6808 | pos += snprintf(pos, end - pos, "ANQP_GET %s ", dest); |
| 6809 | |
| 6810 | val = get_param(cmd, "ANQP_CAP_LIST"); |
| 6811 | if (val && atoi(val)) { |
| 6812 | pos += snprintf(pos, end - pos, "%s257", count > 0 ? "," : ""); |
| 6813 | count++; |
| 6814 | } |
| 6815 | |
| 6816 | val = get_param(cmd, "VENUE_NAME"); |
| 6817 | if (val && atoi(val)) { |
| 6818 | pos += snprintf(pos, end - pos, "%s258", count > 0 ? "," : ""); |
| 6819 | count++; |
| 6820 | } |
| 6821 | |
| 6822 | val = get_param(cmd, "NETWORK_AUTH_TYPE"); |
| 6823 | if (val && atoi(val)) { |
| 6824 | pos += snprintf(pos, end - pos, "%s260", count > 0 ? "," : ""); |
| 6825 | count++; |
| 6826 | } |
| 6827 | |
| 6828 | val = get_param(cmd, "ROAMING_CONS"); |
| 6829 | if (val && atoi(val)) { |
| 6830 | pos += snprintf(pos, end - pos, "%s261", count > 0 ? "," : ""); |
| 6831 | count++; |
| 6832 | } |
| 6833 | |
| 6834 | val = get_param(cmd, "IP_ADDR_TYPE_AVAILABILITY"); |
| 6835 | if (val && atoi(val)) { |
| 6836 | pos += snprintf(pos, end - pos, "%s262", count > 0 ? "," : ""); |
| 6837 | count++; |
| 6838 | } |
| 6839 | |
| 6840 | val = get_param(cmd, "NAI_REALM_LIST"); |
| 6841 | if (val && atoi(val)) { |
| 6842 | pos += snprintf(pos, end - pos, "%s263", count > 0 ? "," : ""); |
| 6843 | count++; |
| 6844 | } |
| 6845 | |
| 6846 | val = get_param(cmd, "3GPP_INFO"); |
| 6847 | if (val && atoi(val)) { |
| 6848 | pos += snprintf(pos, end - pos, "%s264", count > 0 ? "," : ""); |
| 6849 | count++; |
| 6850 | } |
| 6851 | |
| 6852 | val = get_param(cmd, "DOMAIN_LIST"); |
| 6853 | if (val && atoi(val)) { |
| 6854 | pos += snprintf(pos, end - pos, "%s268", count > 0 ? "," : ""); |
| 6855 | count++; |
| 6856 | } |
| 6857 | |
| 6858 | if (count && wpa_command(intf, buf)) { |
| 6859 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,ANQP_GET failed"); |
| 6860 | return 0; |
| 6861 | } |
| 6862 | |
| 6863 | pos = buf; |
| 6864 | end = buf + sizeof(buf); |
| 6865 | count2 = 0; |
| 6866 | pos += snprintf(pos, end - pos, "HS20_ANQP_GET %s ", dest); |
| 6867 | |
| 6868 | val = get_param(cmd, "HS_CAP_LIST"); |
| 6869 | if (val && atoi(val)) { |
| 6870 | pos += snprintf(pos, end - pos, "%s2", count2 > 0 ? "," : ""); |
| 6871 | count2++; |
| 6872 | } |
| 6873 | |
| 6874 | val = get_param(cmd, "OPER_NAME"); |
| 6875 | if (val && atoi(val)) { |
| 6876 | pos += snprintf(pos, end - pos, "%s3", count2 > 0 ? "," : ""); |
| 6877 | count2++; |
| 6878 | } |
| 6879 | |
| 6880 | val = get_param(cmd, "WAN_METRICS"); |
| 6881 | if (!val) |
| 6882 | val = get_param(cmd, "WAN_MAT"); |
| 6883 | if (!val) |
| 6884 | val = get_param(cmd, "WAN_MET"); |
| 6885 | if (val && atoi(val)) { |
| 6886 | pos += snprintf(pos, end - pos, "%s4", count2 > 0 ? "," : ""); |
| 6887 | count2++; |
| 6888 | } |
| 6889 | |
| 6890 | val = get_param(cmd, "CONNECTION_CAPABILITY"); |
| 6891 | if (val && atoi(val)) { |
| 6892 | pos += snprintf(pos, end - pos, "%s5", count2 > 0 ? "," : ""); |
| 6893 | count2++; |
| 6894 | } |
| 6895 | |
| 6896 | val = get_param(cmd, "OP_CLASS"); |
| 6897 | if (val && atoi(val)) { |
| 6898 | pos += snprintf(pos, end - pos, "%s7", count2 > 0 ? "," : ""); |
| 6899 | count2++; |
| 6900 | } |
| 6901 | |
| 6902 | val = get_param(cmd, "OSU_PROVIDER_LIST"); |
| 6903 | if (val && atoi(val)) { |
| 6904 | pos += snprintf(pos, end - pos, "%s8", count2 > 0 ? "," : ""); |
| 6905 | count2++; |
| 6906 | } |
| 6907 | |
| 6908 | if (count && count2) { |
| 6909 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before sending out " |
| 6910 | "second query"); |
| 6911 | sleep(1); |
| 6912 | } |
| 6913 | |
| 6914 | if (count2 && wpa_command(intf, buf)) { |
| 6915 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,HS20_ANQP_GET " |
| 6916 | "failed"); |
| 6917 | return 0; |
| 6918 | } |
| 6919 | |
| 6920 | val = get_param(cmd, "NAI_HOME_REALM_LIST"); |
| 6921 | if (val) { |
| 6922 | if (count || count2) { |
| 6923 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before " |
| 6924 | "sending out second query"); |
| 6925 | sleep(1); |
| 6926 | } |
| 6927 | |
| 6928 | if (strcmp(val, "1") == 0) |
| 6929 | val = "mail.example.com"; |
| 6930 | snprintf(buf, end - pos, |
| 6931 | "HS20_GET_NAI_HOME_REALM_LIST %s realm=%s", |
| 6932 | dest, val); |
| 6933 | if (wpa_command(intf, buf)) { |
| 6934 | send_resp(dut, conn, SIGMA_ERROR, |
| 6935 | "ErrorCode,HS20_GET_NAI_HOME_REALM_LIST " |
| 6936 | "failed"); |
| 6937 | return 0; |
| 6938 | } |
| 6939 | } |
| 6940 | |
| 6941 | val = get_param(cmd, "ICON_REQUEST"); |
| 6942 | if (val) { |
| 6943 | if (count || count2) { |
| 6944 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before " |
| 6945 | "sending out second query"); |
| 6946 | sleep(1); |
| 6947 | } |
| 6948 | |
| 6949 | snprintf(buf, end - pos, |
| 6950 | "HS20_ICON_REQUEST %s %s", dest, val); |
| 6951 | if (wpa_command(intf, buf)) { |
| 6952 | send_resp(dut, conn, SIGMA_ERROR, |
| 6953 | "ErrorCode,HS20_ICON_REQUEST failed"); |
| 6954 | return 0; |
| 6955 | } |
| 6956 | } |
| 6957 | |
| 6958 | return 1; |
| 6959 | } |
| 6960 | |
| 6961 | |
| 6962 | static int ath_sta_send_frame_vht(struct sigma_dut *dut, |
| 6963 | struct sigma_conn *conn, |
| 6964 | struct sigma_cmd *cmd) |
| 6965 | { |
| 6966 | const char *val; |
| 6967 | char *ifname; |
| 6968 | char buf[100]; |
| 6969 | int chwidth, nss; |
| 6970 | |
| 6971 | val = get_param(cmd, "framename"); |
| 6972 | if (!val) |
| 6973 | return -1; |
| 6974 | sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val); |
| 6975 | |
| 6976 | /* Command sequence to generate Op mode notification */ |
| 6977 | if (val && strcasecmp(val, "Op_md_notif_frm") == 0) { |
| 6978 | ifname = get_station_ifname(); |
| 6979 | |
| 6980 | /* Disable STBC */ |
| 6981 | snprintf(buf, sizeof(buf), |
| 6982 | "iwpriv %s tx_stbc 0", ifname); |
| 6983 | if (system(buf) != 0) { |
| 6984 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6985 | "iwpriv tx_stbc 0 failed!"); |
| 6986 | } |
| 6987 | |
| 6988 | /* Extract Channel width */ |
| 6989 | val = get_param(cmd, "Channel_width"); |
| 6990 | if (val) { |
| 6991 | switch (atoi(val)) { |
| 6992 | case 20: |
| 6993 | chwidth = 0; |
| 6994 | break; |
| 6995 | case 40: |
| 6996 | chwidth = 1; |
| 6997 | break; |
| 6998 | case 80: |
| 6999 | chwidth = 2; |
| 7000 | break; |
| 7001 | case 160: |
| 7002 | chwidth = 3; |
| 7003 | break; |
| 7004 | default: |
| 7005 | chwidth = 2; |
| 7006 | break; |
| 7007 | } |
| 7008 | |
| 7009 | snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d", |
| 7010 | ifname, chwidth); |
| 7011 | if (system(buf) != 0) { |
| 7012 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7013 | "iwpriv chwidth failed!"); |
| 7014 | } |
| 7015 | } |
| 7016 | |
| 7017 | /* Extract NSS */ |
| 7018 | val = get_param(cmd, "NSS"); |
| 7019 | if (val) { |
| 7020 | switch (atoi(val)) { |
| 7021 | case 1: |
| 7022 | nss = 1; |
| 7023 | break; |
| 7024 | case 2: |
| 7025 | nss = 3; |
| 7026 | break; |
| 7027 | case 3: |
| 7028 | nss = 7; |
| 7029 | break; |
| 7030 | default: |
| 7031 | /* We do not support NSS > 3 */ |
| 7032 | nss = 3; |
| 7033 | break; |
| 7034 | } |
| 7035 | snprintf(buf, sizeof(buf), |
| 7036 | "iwpriv %s rxchainmask %d", ifname, nss); |
| 7037 | if (system(buf) != 0) { |
| 7038 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7039 | "iwpriv rxchainmask failed!"); |
| 7040 | } |
| 7041 | } |
| 7042 | |
| 7043 | /* Opmode notify */ |
| 7044 | snprintf(buf, sizeof(buf), "iwpriv %s opmode_notify 1", ifname); |
| 7045 | if (system(buf) != 0) { |
| 7046 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7047 | "iwpriv opmode_notify failed!"); |
| 7048 | } else { |
| 7049 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 7050 | "Sent out the notify frame!"); |
| 7051 | } |
| 7052 | } |
| 7053 | |
| 7054 | return 1; |
| 7055 | } |
| 7056 | |
| 7057 | |
| 7058 | static int cmd_sta_send_frame_vht(struct sigma_dut *dut, |
| 7059 | struct sigma_conn *conn, |
| 7060 | struct sigma_cmd *cmd) |
| 7061 | { |
| 7062 | switch (get_driver_type()) { |
| 7063 | case DRIVER_ATHEROS: |
| 7064 | return ath_sta_send_frame_vht(dut, conn, cmd); |
| 7065 | default: |
| 7066 | send_resp(dut, conn, SIGMA_ERROR, |
| 7067 | "errorCode,Unsupported sta_set_frame(VHT) with the current driver"); |
| 7068 | return 0; |
| 7069 | } |
| 7070 | } |
| 7071 | |
| 7072 | |
Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 7073 | #ifdef __linux__ |
| 7074 | int wil6210_send_frame_60g(struct sigma_dut *dut, struct sigma_conn *conn, |
| 7075 | struct sigma_cmd *cmd) |
| 7076 | { |
| 7077 | const char *frame_name = get_param(cmd, "framename"); |
| 7078 | const char *mac = get_param(cmd, "dest_mac"); |
| 7079 | |
| 7080 | if (!frame_name || !mac) { |
| 7081 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7082 | "framename and dest_mac must be provided"); |
| 7083 | return -1; |
| 7084 | } |
| 7085 | |
| 7086 | if (strcasecmp(frame_name, "brp") == 0) { |
| 7087 | const char *l_rx = get_param(cmd, "L-RX"); |
| 7088 | int l_rx_i; |
| 7089 | |
| 7090 | if (!l_rx) { |
| 7091 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7092 | "L-RX must be provided"); |
| 7093 | return -1; |
| 7094 | } |
| 7095 | l_rx_i = atoi(l_rx); |
| 7096 | |
| 7097 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 7098 | "dev_send_frame: BRP-RX, dest_mac %s, L-RX %s", |
| 7099 | mac, l_rx); |
| 7100 | if (l_rx_i != 16) { |
| 7101 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7102 | "unsupported L-RX: %s", l_rx); |
| 7103 | return -1; |
| 7104 | } |
| 7105 | |
| 7106 | if (wil6210_send_brp_rx(dut, mac, l_rx_i)) |
| 7107 | return -1; |
| 7108 | } else if (strcasecmp(frame_name, "ssw") == 0) { |
| 7109 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 7110 | "dev_send_frame: SLS, dest_mac %s", mac); |
| 7111 | if (wil6210_send_sls(dut, mac)) |
| 7112 | return -1; |
| 7113 | } else { |
| 7114 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7115 | "unsupported frame type: %s", frame_name); |
| 7116 | return -1; |
| 7117 | } |
| 7118 | |
| 7119 | return 1; |
| 7120 | } |
| 7121 | #endif /* __linux__ */ |
| 7122 | |
| 7123 | |
| 7124 | static int cmd_sta_send_frame_60g(struct sigma_dut *dut, |
| 7125 | struct sigma_conn *conn, |
| 7126 | struct sigma_cmd *cmd) |
| 7127 | { |
| 7128 | switch (get_driver_type()) { |
| 7129 | #ifdef __linux__ |
| 7130 | case DRIVER_WIL6210: |
| 7131 | return wil6210_send_frame_60g(dut, conn, cmd); |
| 7132 | #endif /* __linux__ */ |
| 7133 | default: |
| 7134 | send_resp(dut, conn, SIGMA_ERROR, |
| 7135 | "errorCode,Unsupported sta_set_frame(60G) with the current driver"); |
| 7136 | return 0; |
| 7137 | } |
| 7138 | } |
| 7139 | |
| 7140 | |
Ashwini Patil | db59b3c | 2017-04-13 15:19:23 +0530 | [diff] [blame] | 7141 | static int mbo_send_anqp_query(struct sigma_dut *dut, struct sigma_conn *conn, |
| 7142 | const char *intf, struct sigma_cmd *cmd) |
| 7143 | { |
| 7144 | const char *val, *addr; |
| 7145 | char buf[100]; |
| 7146 | |
| 7147 | addr = get_param(cmd, "DestMac"); |
| 7148 | if (!addr) { |
| 7149 | send_resp(dut, conn, SIGMA_INVALID, |
| 7150 | "ErrorCode,AP MAC address is missing"); |
| 7151 | return 0; |
| 7152 | } |
| 7153 | |
| 7154 | val = get_param(cmd, "ANQPQuery_ID"); |
| 7155 | if (!val) { |
| 7156 | send_resp(dut, conn, SIGMA_INVALID, |
| 7157 | "ErrorCode,Missing ANQPQuery_ID"); |
| 7158 | return 0; |
| 7159 | } |
| 7160 | |
| 7161 | if (strcasecmp(val, "NeighborReportReq") == 0) { |
| 7162 | snprintf(buf, sizeof(buf), "ANQP_GET %s 272", addr); |
| 7163 | } else if (strcasecmp(val, "QueryListWithCellPref") == 0) { |
| 7164 | snprintf(buf, sizeof(buf), "ANQP_GET %s 272,mbo:2", addr); |
| 7165 | } else { |
| 7166 | sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid ANQPQuery_ID: %s", |
| 7167 | val); |
| 7168 | send_resp(dut, conn, SIGMA_INVALID, |
| 7169 | "ErrorCode,Invalid ANQPQuery_ID"); |
| 7170 | return 0; |
| 7171 | } |
| 7172 | |
Ashwini Patil | d174f2c | 2017-04-13 16:49:46 +0530 | [diff] [blame] | 7173 | /* Set gas_address3 field to IEEE 802.11-2012 standard compliant form |
| 7174 | * (Address3 = Wildcard BSSID when sent to not-associated AP; |
| 7175 | * if associated, AP BSSID). |
| 7176 | */ |
| 7177 | if (wpa_command(intf, "SET gas_address3 1") < 0) { |
| 7178 | send_resp(dut, conn, SIGMA_ERROR, |
| 7179 | "ErrorCode,Failed to set gas_address3"); |
| 7180 | return 0; |
| 7181 | } |
| 7182 | |
Ashwini Patil | db59b3c | 2017-04-13 15:19:23 +0530 | [diff] [blame] | 7183 | if (wpa_command(intf, buf) < 0) { |
| 7184 | send_resp(dut, conn, SIGMA_ERROR, |
| 7185 | "ErrorCode,Failed to send ANQP query"); |
| 7186 | return 0; |
| 7187 | } |
| 7188 | |
| 7189 | return 1; |
| 7190 | } |
| 7191 | |
| 7192 | |
| 7193 | static int mbo_cmd_sta_send_frame(struct sigma_dut *dut, |
| 7194 | struct sigma_conn *conn, |
| 7195 | const char *intf, |
| 7196 | struct sigma_cmd *cmd) |
| 7197 | { |
| 7198 | const char *val = get_param(cmd, "FrameName"); |
| 7199 | |
| 7200 | if (val && strcasecmp(val, "ANQPQuery") == 0) |
| 7201 | return mbo_send_anqp_query(dut, conn, intf, cmd); |
| 7202 | |
| 7203 | return 2; |
| 7204 | } |
| 7205 | |
| 7206 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7207 | int cmd_sta_send_frame(struct sigma_dut *dut, struct sigma_conn *conn, |
| 7208 | struct sigma_cmd *cmd) |
| 7209 | { |
| 7210 | const char *intf = get_param(cmd, "Interface"); |
| 7211 | const char *val; |
| 7212 | enum send_frame_type frame; |
| 7213 | enum send_frame_protection protected; |
| 7214 | char buf[100]; |
| 7215 | unsigned char addr[ETH_ALEN]; |
| 7216 | int res; |
| 7217 | |
| 7218 | val = get_param(cmd, "program"); |
| 7219 | if (val == NULL) |
| 7220 | val = get_param(cmd, "frame"); |
| 7221 | if (val && strcasecmp(val, "TDLS") == 0) |
| 7222 | return cmd_sta_send_frame_tdls(dut, conn, cmd); |
| 7223 | if (val && (strcasecmp(val, "HS2") == 0 || |
| 7224 | strcasecmp(val, "HS2-R2") == 0)) |
| 7225 | return cmd_sta_send_frame_hs2(dut, conn, cmd); |
| 7226 | if (val && strcasecmp(val, "VHT") == 0) |
| 7227 | return cmd_sta_send_frame_vht(dut, conn, cmd); |
priyadharshini gowthaman | d66913a | 2016-07-29 15:11:17 -0700 | [diff] [blame] | 7228 | if (val && strcasecmp(val, "LOC") == 0) |
| 7229 | return loc_cmd_sta_send_frame(dut, conn, cmd); |
Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 7230 | if (val && strcasecmp(val, "60GHz") == 0) |
| 7231 | return cmd_sta_send_frame_60g(dut, conn, cmd); |
Ashwini Patil | db59b3c | 2017-04-13 15:19:23 +0530 | [diff] [blame] | 7232 | if (val && strcasecmp(val, "MBO") == 0) { |
| 7233 | res = mbo_cmd_sta_send_frame(dut, conn, intf, cmd); |
| 7234 | if (res != 2) |
| 7235 | return res; |
| 7236 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7237 | |
| 7238 | val = get_param(cmd, "TD_DISC"); |
| 7239 | if (val) { |
| 7240 | if (hwaddr_aton(val, addr) < 0) |
| 7241 | return -1; |
| 7242 | snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", val); |
| 7243 | if (wpa_command(intf, buf) < 0) { |
| 7244 | send_resp(dut, conn, SIGMA_ERROR, |
| 7245 | "ErrorCode,Failed to send TDLS discovery"); |
| 7246 | return 0; |
| 7247 | } |
| 7248 | return 1; |
| 7249 | } |
| 7250 | |
| 7251 | val = get_param(cmd, "TD_Setup"); |
| 7252 | if (val) { |
| 7253 | if (hwaddr_aton(val, addr) < 0) |
| 7254 | return -1; |
| 7255 | snprintf(buf, sizeof(buf), "TDLS_SETUP %s", val); |
| 7256 | if (wpa_command(intf, buf) < 0) { |
| 7257 | send_resp(dut, conn, SIGMA_ERROR, |
| 7258 | "ErrorCode,Failed to start TDLS setup"); |
| 7259 | return 0; |
| 7260 | } |
| 7261 | return 1; |
| 7262 | } |
| 7263 | |
| 7264 | val = get_param(cmd, "TD_TearDown"); |
| 7265 | if (val) { |
| 7266 | if (hwaddr_aton(val, addr) < 0) |
| 7267 | return -1; |
| 7268 | snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", val); |
| 7269 | if (wpa_command(intf, buf) < 0) { |
| 7270 | send_resp(dut, conn, SIGMA_ERROR, |
| 7271 | "ErrorCode,Failed to tear down TDLS link"); |
| 7272 | return 0; |
| 7273 | } |
| 7274 | return 1; |
| 7275 | } |
| 7276 | |
| 7277 | val = get_param(cmd, "TD_ChannelSwitch"); |
| 7278 | if (val) { |
| 7279 | /* TODO */ |
| 7280 | send_resp(dut, conn, SIGMA_ERROR, |
| 7281 | "ErrorCode,TD_ChannelSwitch not yet supported"); |
| 7282 | return 0; |
| 7283 | } |
| 7284 | |
| 7285 | val = get_param(cmd, "TD_NF"); |
| 7286 | if (val) { |
| 7287 | /* TODO */ |
| 7288 | send_resp(dut, conn, SIGMA_ERROR, |
| 7289 | "ErrorCode,TD_NF not yet supported"); |
| 7290 | return 0; |
| 7291 | } |
| 7292 | |
| 7293 | val = get_param(cmd, "PMFFrameType"); |
| 7294 | if (val == NULL) |
| 7295 | val = get_param(cmd, "FrameName"); |
| 7296 | if (val == NULL) |
| 7297 | val = get_param(cmd, "Type"); |
| 7298 | if (val == NULL) |
| 7299 | return -1; |
| 7300 | if (strcasecmp(val, "disassoc") == 0) |
| 7301 | frame = DISASSOC; |
| 7302 | else if (strcasecmp(val, "deauth") == 0) |
| 7303 | frame = DEAUTH; |
| 7304 | else if (strcasecmp(val, "saquery") == 0) |
| 7305 | frame = SAQUERY; |
| 7306 | else if (strcasecmp(val, "auth") == 0) |
| 7307 | frame = AUTH; |
| 7308 | else if (strcasecmp(val, "assocreq") == 0) |
| 7309 | frame = ASSOCREQ; |
| 7310 | else if (strcasecmp(val, "reassocreq") == 0) |
| 7311 | frame = REASSOCREQ; |
| 7312 | else if (strcasecmp(val, "neigreq") == 0) { |
| 7313 | sigma_dut_print(dut, DUT_MSG_INFO, "Got neighbor request"); |
| 7314 | |
| 7315 | val = get_param(cmd, "ssid"); |
| 7316 | if (val == NULL) |
| 7317 | return -1; |
| 7318 | |
| 7319 | res = send_neighbor_request(dut, intf, val); |
| 7320 | if (res) { |
| 7321 | send_resp(dut, conn, SIGMA_ERROR, "errorCode," |
| 7322 | "Failed to send neighbor report request"); |
| 7323 | return 0; |
| 7324 | } |
| 7325 | |
| 7326 | return 1; |
Ashwini Patil | 5acd738 | 2017-04-13 15:55:04 +0530 | [diff] [blame] | 7327 | } else if (strcasecmp(val, "transmgmtquery") == 0 || |
| 7328 | strcasecmp(val, "BTMQuery") == 0) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7329 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 7330 | "Got Transition Management Query"); |
| 7331 | |
Ashwini Patil | 5acd738 | 2017-04-13 15:55:04 +0530 | [diff] [blame] | 7332 | res = send_trans_mgmt_query(dut, intf, cmd); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7333 | if (res) { |
| 7334 | send_resp(dut, conn, SIGMA_ERROR, "errorCode," |
| 7335 | "Failed to send Transition Management Query"); |
| 7336 | return 0; |
| 7337 | } |
| 7338 | |
| 7339 | return 1; |
| 7340 | } else { |
| 7341 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported " |
| 7342 | "PMFFrameType"); |
| 7343 | return 0; |
| 7344 | } |
| 7345 | |
| 7346 | val = get_param(cmd, "PMFProtected"); |
| 7347 | if (val == NULL) |
| 7348 | val = get_param(cmd, "Protected"); |
| 7349 | if (val == NULL) |
| 7350 | return -1; |
| 7351 | if (strcasecmp(val, "Correct-key") == 0 || |
| 7352 | strcasecmp(val, "CorrectKey") == 0) |
| 7353 | protected = CORRECT_KEY; |
| 7354 | else if (strcasecmp(val, "IncorrectKey") == 0) |
| 7355 | protected = INCORRECT_KEY; |
| 7356 | else if (strcasecmp(val, "Unprotected") == 0) |
| 7357 | protected = UNPROTECTED; |
| 7358 | else { |
| 7359 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported " |
| 7360 | "PMFProtected"); |
| 7361 | return 0; |
| 7362 | } |
| 7363 | |
| 7364 | if (protected != UNPROTECTED && |
| 7365 | (frame == AUTH || frame == ASSOCREQ || frame == REASSOCREQ)) { |
| 7366 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Impossible " |
| 7367 | "PMFProtected for auth/assocreq/reassocreq"); |
| 7368 | return 0; |
| 7369 | } |
| 7370 | |
| 7371 | if (if_nametoindex("sigmadut") == 0) { |
| 7372 | snprintf(buf, sizeof(buf), |
| 7373 | "iw dev %s interface add sigmadut type monitor", |
| 7374 | get_station_ifname()); |
| 7375 | if (system(buf) != 0 || |
| 7376 | if_nametoindex("sigmadut") == 0) { |
| 7377 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add " |
| 7378 | "monitor interface with '%s'", buf); |
| 7379 | return -2; |
| 7380 | } |
| 7381 | } |
| 7382 | |
| 7383 | if (system("ifconfig sigmadut up") != 0) { |
| 7384 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set " |
| 7385 | "monitor interface up"); |
| 7386 | return -2; |
| 7387 | } |
| 7388 | |
| 7389 | return sta_inject_frame(dut, conn, frame, protected, NULL); |
| 7390 | } |
| 7391 | |
| 7392 | |
| 7393 | static int cmd_sta_set_parameter_hs2(struct sigma_dut *dut, |
| 7394 | struct sigma_conn *conn, |
| 7395 | struct sigma_cmd *cmd, |
| 7396 | const char *ifname) |
| 7397 | { |
| 7398 | char buf[200]; |
| 7399 | const char *val; |
| 7400 | |
| 7401 | val = get_param(cmd, "ClearARP"); |
| 7402 | if (val && atoi(val) == 1) { |
| 7403 | snprintf(buf, sizeof(buf), "ip neigh flush dev %s", ifname); |
| 7404 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 7405 | if (system(buf) != 0) { |
| 7406 | send_resp(dut, conn, SIGMA_ERROR, |
| 7407 | "errorCode,Failed to clear ARP cache"); |
| 7408 | return 0; |
| 7409 | } |
| 7410 | } |
| 7411 | |
| 7412 | return 1; |
| 7413 | } |
| 7414 | |
| 7415 | |
| 7416 | int cmd_sta_set_parameter(struct sigma_dut *dut, struct sigma_conn *conn, |
| 7417 | struct sigma_cmd *cmd) |
| 7418 | { |
| 7419 | const char *intf = get_param(cmd, "Interface"); |
| 7420 | const char *val; |
| 7421 | |
| 7422 | if (intf == NULL) |
| 7423 | return -1; |
| 7424 | |
| 7425 | val = get_param(cmd, "program"); |
| 7426 | if (val && (strcasecmp(val, "HS2") == 0 || |
| 7427 | strcasecmp(val, "HS2-R2") == 0)) |
| 7428 | return cmd_sta_set_parameter_hs2(dut, conn, cmd, intf); |
| 7429 | |
| 7430 | return -1; |
| 7431 | } |
| 7432 | |
| 7433 | |
| 7434 | static int cmd_sta_set_macaddr(struct sigma_dut *dut, struct sigma_conn *conn, |
| 7435 | struct sigma_cmd *cmd) |
| 7436 | { |
| 7437 | const char *intf = get_param(cmd, "Interface"); |
| 7438 | const char *mac = get_param(cmd, "MAC"); |
| 7439 | |
| 7440 | if (intf == NULL || mac == NULL) |
| 7441 | return -1; |
| 7442 | |
| 7443 | sigma_dut_print(dut, DUT_MSG_INFO, "Change local MAC address for " |
| 7444 | "interface %s to %s", intf, mac); |
| 7445 | |
| 7446 | if (dut->set_macaddr) { |
| 7447 | char buf[128]; |
| 7448 | int res; |
| 7449 | if (strcasecmp(mac, "default") == 0) { |
| 7450 | res = snprintf(buf, sizeof(buf), "%s", |
| 7451 | dut->set_macaddr); |
| 7452 | dut->tmp_mac_addr = 0; |
| 7453 | } else { |
| 7454 | res = snprintf(buf, sizeof(buf), "%s %s", |
| 7455 | dut->set_macaddr, mac); |
| 7456 | dut->tmp_mac_addr = 1; |
| 7457 | } |
| 7458 | if (res < 0 || res >= (int) sizeof(buf)) |
| 7459 | return -1; |
| 7460 | if (system(buf) != 0) { |
| 7461 | send_resp(dut, conn, SIGMA_ERROR, |
| 7462 | "errorCode,Failed to set MAC " |
| 7463 | "address"); |
| 7464 | return 0; |
| 7465 | } |
| 7466 | return 1; |
| 7467 | } |
| 7468 | |
| 7469 | if (strcasecmp(mac, "default") == 0) |
| 7470 | return 1; |
| 7471 | |
| 7472 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported " |
| 7473 | "command"); |
| 7474 | return 0; |
| 7475 | } |
| 7476 | |
| 7477 | |
| 7478 | static int iwpriv_tdlsoffchnmode(struct sigma_dut *dut, |
| 7479 | struct sigma_conn *conn, const char *intf, |
| 7480 | int val) |
| 7481 | { |
| 7482 | char buf[200]; |
| 7483 | int res; |
| 7484 | |
| 7485 | res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchnmode %d", |
| 7486 | intf, val); |
| 7487 | if (res < 0 || res >= (int) sizeof(buf)) |
| 7488 | return -1; |
| 7489 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 7490 | if (system(buf) != 0) { |
| 7491 | send_resp(dut, conn, SIGMA_ERROR, |
| 7492 | "errorCode,Failed to configure offchannel mode"); |
| 7493 | return 0; |
| 7494 | } |
| 7495 | |
| 7496 | return 1; |
| 7497 | } |
| 7498 | |
| 7499 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7500 | static int off_chan_val(enum sec_ch_offset off) |
| 7501 | { |
| 7502 | switch (off) { |
| 7503 | case SEC_CH_NO: |
| 7504 | return 0; |
| 7505 | case SEC_CH_40ABOVE: |
| 7506 | return 40; |
| 7507 | case SEC_CH_40BELOW: |
| 7508 | return -40; |
| 7509 | } |
| 7510 | |
| 7511 | return 0; |
| 7512 | } |
| 7513 | |
| 7514 | |
| 7515 | static int iwpriv_set_offchan(struct sigma_dut *dut, struct sigma_conn *conn, |
| 7516 | const char *intf, int off_ch_num, |
| 7517 | enum sec_ch_offset sec) |
| 7518 | { |
| 7519 | char buf[200]; |
| 7520 | int res; |
| 7521 | |
| 7522 | res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchan %d", |
| 7523 | intf, off_ch_num); |
| 7524 | if (res < 0 || res >= (int) sizeof(buf)) |
| 7525 | return -1; |
| 7526 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 7527 | if (system(buf) != 0) { |
| 7528 | send_resp(dut, conn, SIGMA_ERROR, |
| 7529 | "errorCode,Failed to set offchan"); |
| 7530 | return 0; |
| 7531 | } |
| 7532 | |
| 7533 | res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsecchnoffst %d", |
| 7534 | intf, off_chan_val(sec)); |
| 7535 | if (res < 0 || res >= (int) sizeof(buf)) |
| 7536 | return -1; |
| 7537 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 7538 | if (system(buf) != 0) { |
| 7539 | send_resp(dut, conn, SIGMA_ERROR, |
| 7540 | "errorCode,Failed to set sec chan offset"); |
| 7541 | return 0; |
| 7542 | } |
| 7543 | |
| 7544 | return 1; |
| 7545 | } |
| 7546 | |
| 7547 | |
| 7548 | static int tdls_set_offchannel_offset(struct sigma_dut *dut, |
| 7549 | struct sigma_conn *conn, |
| 7550 | const char *intf, int off_ch_num, |
| 7551 | enum sec_ch_offset sec) |
| 7552 | { |
| 7553 | char buf[200]; |
| 7554 | int res; |
| 7555 | |
| 7556 | res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNEL %d", |
| 7557 | off_ch_num); |
| 7558 | if (res < 0 || res >= (int) sizeof(buf)) |
| 7559 | return -1; |
| 7560 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 7561 | |
| 7562 | if (wpa_command(intf, buf) < 0) { |
| 7563 | send_resp(dut, conn, SIGMA_ERROR, |
| 7564 | "ErrorCode,Failed to set offchan"); |
| 7565 | return 0; |
| 7566 | } |
| 7567 | res = snprintf(buf, sizeof(buf), "DRIVER TDLSSECONDARYCHANNELOFFSET %d", |
| 7568 | off_chan_val(sec)); |
| 7569 | if (res < 0 || res >= (int) sizeof(buf)) |
| 7570 | return -1; |
| 7571 | |
| 7572 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 7573 | |
| 7574 | if (wpa_command(intf, buf) < 0) { |
| 7575 | send_resp(dut, conn, SIGMA_ERROR, |
| 7576 | "ErrorCode,Failed to set sec chan offset"); |
| 7577 | return 0; |
| 7578 | } |
| 7579 | |
| 7580 | return 1; |
| 7581 | } |
| 7582 | |
| 7583 | |
| 7584 | static int tdls_set_offchannel_mode(struct sigma_dut *dut, |
| 7585 | struct sigma_conn *conn, |
| 7586 | const char *intf, int val) |
| 7587 | { |
| 7588 | char buf[200]; |
| 7589 | int res; |
| 7590 | |
| 7591 | res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNELMODE %d", |
| 7592 | val); |
| 7593 | if (res < 0 || res >= (int) sizeof(buf)) |
| 7594 | return -1; |
| 7595 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 7596 | |
| 7597 | if (wpa_command(intf, buf) < 0) { |
| 7598 | send_resp(dut, conn, SIGMA_ERROR, |
| 7599 | "ErrorCode,Failed to configure offchannel mode"); |
| 7600 | return 0; |
| 7601 | } |
| 7602 | |
| 7603 | return 1; |
| 7604 | } |
| 7605 | |
| 7606 | |
| 7607 | static int cmd_sta_set_rfeature_tdls(const char *intf, struct sigma_dut *dut, |
| 7608 | struct sigma_conn *conn, |
| 7609 | struct sigma_cmd *cmd) |
| 7610 | { |
| 7611 | const char *val; |
| 7612 | enum { |
| 7613 | CHSM_NOT_SET, |
| 7614 | CHSM_ENABLE, |
| 7615 | CHSM_DISABLE, |
| 7616 | CHSM_REJREQ, |
| 7617 | CHSM_UNSOLRESP |
| 7618 | } chsm = CHSM_NOT_SET; |
| 7619 | int off_ch_num = -1; |
| 7620 | enum sec_ch_offset sec_ch = SEC_CH_NO; |
| 7621 | int res; |
| 7622 | |
| 7623 | val = get_param(cmd, "Uapsd"); |
| 7624 | if (val) { |
| 7625 | char buf[100]; |
| 7626 | if (strcasecmp(val, "Enable") == 0) |
| 7627 | snprintf(buf, sizeof(buf), "SET ps 99"); |
| 7628 | else if (strcasecmp(val, "Disable") == 0) |
| 7629 | snprintf(buf, sizeof(buf), "SET ps 98"); |
| 7630 | else { |
| 7631 | send_resp(dut, conn, SIGMA_ERROR, "errorCode," |
| 7632 | "Unsupported uapsd parameter value"); |
| 7633 | return 0; |
| 7634 | } |
| 7635 | if (wpa_command(intf, buf)) { |
| 7636 | send_resp(dut, conn, SIGMA_ERROR, |
| 7637 | "ErrorCode,Failed to change U-APSD " |
| 7638 | "powersave mode"); |
| 7639 | return 0; |
| 7640 | } |
| 7641 | } |
| 7642 | |
| 7643 | val = get_param(cmd, "TPKTIMER"); |
| 7644 | if (val && strcasecmp(val, "DISABLE") == 0) { |
| 7645 | if (wpa_command(intf, "SET tdls_testing 0x100")) { |
| 7646 | send_resp(dut, conn, SIGMA_ERROR, |
| 7647 | "ErrorCode,Failed to enable no TPK " |
| 7648 | "expiration test mode"); |
| 7649 | return 0; |
| 7650 | } |
| 7651 | dut->no_tpk_expiration = 1; |
| 7652 | } |
| 7653 | |
| 7654 | val = get_param(cmd, "ChSwitchMode"); |
| 7655 | if (val) { |
| 7656 | if (strcasecmp(val, "Enable") == 0 || |
| 7657 | strcasecmp(val, "Initiate") == 0) |
| 7658 | chsm = CHSM_ENABLE; |
| 7659 | else if (strcasecmp(val, "Disable") == 0 || |
| 7660 | strcasecmp(val, "passive") == 0) |
| 7661 | chsm = CHSM_DISABLE; |
| 7662 | else if (strcasecmp(val, "RejReq") == 0) |
| 7663 | chsm = CHSM_REJREQ; |
| 7664 | else if (strcasecmp(val, "UnSolResp") == 0) |
| 7665 | chsm = CHSM_UNSOLRESP; |
| 7666 | else { |
| 7667 | send_resp(dut, conn, SIGMA_ERROR, |
| 7668 | "ErrorCode,Unknown ChSwitchMode value"); |
| 7669 | return 0; |
| 7670 | } |
| 7671 | } |
| 7672 | |
| 7673 | val = get_param(cmd, "OffChNum"); |
| 7674 | if (val) { |
| 7675 | off_ch_num = atoi(val); |
| 7676 | if (off_ch_num == 0) { |
| 7677 | send_resp(dut, conn, SIGMA_ERROR, |
| 7678 | "ErrorCode,Invalid OffChNum"); |
| 7679 | return 0; |
| 7680 | } |
| 7681 | } |
| 7682 | |
| 7683 | val = get_param(cmd, "SecChOffset"); |
| 7684 | if (val) { |
| 7685 | if (strcmp(val, "20") == 0) |
| 7686 | sec_ch = SEC_CH_NO; |
| 7687 | else if (strcasecmp(val, "40above") == 0) |
| 7688 | sec_ch = SEC_CH_40ABOVE; |
| 7689 | else if (strcasecmp(val, "40below") == 0) |
| 7690 | sec_ch = SEC_CH_40BELOW; |
| 7691 | else { |
| 7692 | send_resp(dut, conn, SIGMA_ERROR, |
| 7693 | "ErrorCode,Unknown SecChOffset value"); |
| 7694 | return 0; |
| 7695 | } |
| 7696 | } |
| 7697 | |
| 7698 | if (chsm == CHSM_NOT_SET) { |
| 7699 | /* no offchannel changes requested */ |
| 7700 | return 1; |
| 7701 | } |
| 7702 | |
| 7703 | if (strcmp(intf, get_main_ifname()) != 0 && |
| 7704 | strcmp(intf, get_station_ifname()) != 0) { |
| 7705 | send_resp(dut, conn, SIGMA_ERROR, |
| 7706 | "ErrorCode,Unknown interface"); |
| 7707 | return 0; |
| 7708 | } |
| 7709 | |
| 7710 | switch (chsm) { |
| 7711 | case CHSM_NOT_SET: |
Jouni Malinen | 280f5ba | 2016-08-29 21:33:10 +0300 | [diff] [blame] | 7712 | res = 1; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7713 | break; |
| 7714 | case CHSM_ENABLE: |
| 7715 | if (off_ch_num < 0) { |
| 7716 | send_resp(dut, conn, SIGMA_ERROR, |
| 7717 | "ErrorCode,Missing OffChNum argument"); |
| 7718 | return 0; |
| 7719 | } |
| 7720 | if (wifi_chip_type == DRIVER_WCN) { |
| 7721 | res = tdls_set_offchannel_offset(dut, conn, intf, |
| 7722 | off_ch_num, sec_ch); |
| 7723 | } else { |
| 7724 | res = iwpriv_set_offchan(dut, conn, intf, off_ch_num, |
| 7725 | sec_ch); |
| 7726 | } |
| 7727 | if (res != 1) |
| 7728 | return res; |
| 7729 | if (wifi_chip_type == DRIVER_WCN) |
| 7730 | res = tdls_set_offchannel_mode(dut, conn, intf, 1); |
| 7731 | else |
| 7732 | res = iwpriv_tdlsoffchnmode(dut, conn, intf, 1); |
| 7733 | break; |
| 7734 | case CHSM_DISABLE: |
| 7735 | if (wifi_chip_type == DRIVER_WCN) |
| 7736 | res = tdls_set_offchannel_mode(dut, conn, intf, 2); |
| 7737 | else |
| 7738 | res = iwpriv_tdlsoffchnmode(dut, conn, intf, 2); |
| 7739 | break; |
| 7740 | case CHSM_REJREQ: |
| 7741 | if (wifi_chip_type == DRIVER_WCN) |
| 7742 | res = tdls_set_offchannel_mode(dut, conn, intf, 3); |
| 7743 | else |
| 7744 | res = iwpriv_tdlsoffchnmode(dut, conn, intf, 3); |
| 7745 | break; |
| 7746 | case CHSM_UNSOLRESP: |
| 7747 | if (off_ch_num < 0) { |
| 7748 | send_resp(dut, conn, SIGMA_ERROR, |
| 7749 | "ErrorCode,Missing OffChNum argument"); |
| 7750 | return 0; |
| 7751 | } |
| 7752 | if (wifi_chip_type == DRIVER_WCN) { |
| 7753 | res = tdls_set_offchannel_offset(dut, conn, intf, |
| 7754 | off_ch_num, sec_ch); |
| 7755 | } else { |
| 7756 | res = iwpriv_set_offchan(dut, conn, intf, off_ch_num, |
| 7757 | sec_ch); |
| 7758 | } |
| 7759 | if (res != 1) |
| 7760 | return res; |
| 7761 | if (wifi_chip_type == DRIVER_WCN) |
| 7762 | res = tdls_set_offchannel_mode(dut, conn, intf, 4); |
| 7763 | else |
| 7764 | res = iwpriv_tdlsoffchnmode(dut, conn, intf, 4); |
| 7765 | break; |
| 7766 | } |
| 7767 | |
| 7768 | return res; |
| 7769 | } |
| 7770 | |
| 7771 | |
| 7772 | static int ath_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut, |
| 7773 | struct sigma_conn *conn, |
| 7774 | struct sigma_cmd *cmd) |
| 7775 | { |
| 7776 | const char *val; |
| 7777 | char *token, *result; |
| 7778 | |
priyadharshini gowthaman | e5e2517 | 2015-12-08 14:53:48 -0800 | [diff] [blame] | 7779 | novap_reset(dut, intf); |
| 7780 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7781 | val = get_param(cmd, "nss_mcs_opt"); |
| 7782 | if (val) { |
| 7783 | /* String (nss_operating_mode; mcs_operating_mode) */ |
| 7784 | int nss, mcs; |
| 7785 | char buf[50]; |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 7786 | char *saveptr; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7787 | |
| 7788 | token = strdup(val); |
| 7789 | if (!token) |
| 7790 | return 0; |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 7791 | result = strtok_r(token, ";", &saveptr); |
Pradeep Reddy POTTETI | 41b8c54 | 2016-06-15 16:09:46 +0530 | [diff] [blame] | 7792 | if (!result) { |
| 7793 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7794 | "VHT NSS not specified"); |
| 7795 | goto failed; |
| 7796 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7797 | if (strcasecmp(result, "def") != 0) { |
| 7798 | nss = atoi(result); |
| 7799 | if (nss == 4) |
| 7800 | ath_disable_txbf(dut, intf); |
| 7801 | snprintf(buf, sizeof(buf), "iwpriv %s nss %d", |
| 7802 | intf, nss); |
| 7803 | if (system(buf) != 0) { |
| 7804 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7805 | "iwpriv nss failed"); |
| 7806 | goto failed; |
| 7807 | } |
| 7808 | } |
| 7809 | |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 7810 | result = strtok_r(NULL, ";", &saveptr); |
Pradeep Reddy POTTETI | 41b8c54 | 2016-06-15 16:09:46 +0530 | [diff] [blame] | 7811 | if (!result) { |
| 7812 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7813 | "VHT MCS not specified"); |
| 7814 | goto failed; |
| 7815 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7816 | if (strcasecmp(result, "def") == 0) { |
| 7817 | snprintf(buf, sizeof(buf), "iwpriv %s set11NRates 0", |
| 7818 | intf); |
| 7819 | if (system(buf) != 0) { |
| 7820 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7821 | "iwpriv set11NRates failed"); |
| 7822 | goto failed; |
| 7823 | } |
| 7824 | |
| 7825 | } else { |
| 7826 | mcs = atoi(result); |
| 7827 | snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs %d", |
| 7828 | intf, mcs); |
| 7829 | if (system(buf) != 0) { |
| 7830 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7831 | "iwpriv vhtmcs failed"); |
| 7832 | goto failed; |
| 7833 | } |
| 7834 | } |
| 7835 | /* Channel width gets messed up, fix this */ |
| 7836 | snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d", |
| 7837 | intf, dut->chwidth); |
| 7838 | if (system(buf) != 0) { |
| 7839 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7840 | "iwpriv chwidth failed"); |
| 7841 | } |
| 7842 | } |
| 7843 | |
| 7844 | return 1; |
| 7845 | failed: |
| 7846 | free(token); |
| 7847 | return 0; |
| 7848 | } |
| 7849 | |
| 7850 | |
| 7851 | static int cmd_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut, |
| 7852 | struct sigma_conn *conn, |
| 7853 | struct sigma_cmd *cmd) |
| 7854 | { |
| 7855 | switch (get_driver_type()) { |
| 7856 | case DRIVER_ATHEROS: |
| 7857 | return ath_sta_set_rfeature_vht(intf, dut, conn, cmd); |
| 7858 | default: |
| 7859 | send_resp(dut, conn, SIGMA_ERROR, |
| 7860 | "errorCode,Unsupported sta_set_rfeature(VHT) with the current driver"); |
| 7861 | return 0; |
| 7862 | } |
| 7863 | } |
| 7864 | |
| 7865 | |
Ashwini Patil | 5acd738 | 2017-04-13 15:55:04 +0530 | [diff] [blame] | 7866 | static int btm_query_candidate_list(struct sigma_dut *dut, |
| 7867 | struct sigma_conn *conn, |
| 7868 | struct sigma_cmd *cmd) |
| 7869 | { |
| 7870 | const char *bssid, *info, *op_class, *ch, *phy_type, *pref; |
| 7871 | int len, ret; |
| 7872 | char buf[10]; |
| 7873 | |
| 7874 | /* |
| 7875 | * Neighbor Report elements format: |
| 7876 | * neighbor=<BSSID>,<BSSID Information>,<Operating Class>, |
| 7877 | * <Channel Number>,<PHY Type>[,<hexdump of Optional Subelements>] |
| 7878 | * eg: neighbor=aa:bb:cc:dd:ee:ff,17,81,6,1,030101 |
| 7879 | */ |
| 7880 | |
| 7881 | bssid = get_param(cmd, "Nebor_BSSID"); |
| 7882 | if (!bssid) { |
| 7883 | send_resp(dut, conn, SIGMA_INVALID, |
| 7884 | "errorCode,Nebor_BSSID is missing"); |
| 7885 | return 0; |
| 7886 | } |
| 7887 | |
| 7888 | info = get_param(cmd, "Nebor_Bssid_Info"); |
| 7889 | if (!info) { |
| 7890 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 7891 | "Using default value for Nebor_Bssid_Info: %s", |
| 7892 | DEFAULT_NEIGHBOR_BSSID_INFO); |
| 7893 | info = DEFAULT_NEIGHBOR_BSSID_INFO; |
| 7894 | } |
| 7895 | |
| 7896 | op_class = get_param(cmd, "Nebor_Op_Class"); |
| 7897 | if (!op_class) { |
| 7898 | send_resp(dut, conn, SIGMA_INVALID, |
| 7899 | "errorCode,Nebor_Op_Class is missing"); |
| 7900 | return 0; |
| 7901 | } |
| 7902 | |
| 7903 | ch = get_param(cmd, "Nebor_Op_Ch"); |
| 7904 | if (!ch) { |
| 7905 | send_resp(dut, conn, SIGMA_INVALID, |
| 7906 | "errorCode,Nebor_Op_Ch is missing"); |
| 7907 | return 0; |
| 7908 | } |
| 7909 | |
| 7910 | phy_type = get_param(cmd, "Nebor_Phy_Type"); |
| 7911 | if (!phy_type) { |
| 7912 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 7913 | "Using default value for Nebor_Phy_Type: %s", |
| 7914 | DEFAULT_NEIGHBOR_PHY_TYPE); |
| 7915 | phy_type = DEFAULT_NEIGHBOR_PHY_TYPE; |
| 7916 | } |
| 7917 | |
| 7918 | /* Parse optional subelements */ |
| 7919 | buf[0] = '\0'; |
| 7920 | pref = get_param(cmd, "Nebor_Pref"); |
| 7921 | if (pref) { |
| 7922 | /* hexdump for preferrence subelement */ |
| 7923 | ret = snprintf(buf, sizeof(buf), ",0301%02x", atoi(pref)); |
| 7924 | if (ret < 0 || ret >= (int) sizeof(buf)) { |
| 7925 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7926 | "snprintf failed for optional subelement ret: %d", |
| 7927 | ret); |
| 7928 | send_resp(dut, conn, SIGMA_ERROR, |
| 7929 | "errorCode,snprintf failed for subelement"); |
| 7930 | return 0; |
| 7931 | } |
| 7932 | } |
| 7933 | |
| 7934 | if (!dut->btm_query_cand_list) { |
| 7935 | dut->btm_query_cand_list = calloc(1, NEIGHBOR_REPORT_SIZE); |
| 7936 | if (!dut->btm_query_cand_list) { |
| 7937 | send_resp(dut, conn, SIGMA_ERROR, |
| 7938 | "errorCode,Failed to allocate memory for btm_query_cand_list"); |
| 7939 | return 0; |
| 7940 | } |
| 7941 | } |
| 7942 | |
| 7943 | len = strlen(dut->btm_query_cand_list); |
| 7944 | ret = snprintf(dut->btm_query_cand_list + len, |
| 7945 | NEIGHBOR_REPORT_SIZE - len, " neighbor=%s,%s,%s,%s,%s%s", |
| 7946 | bssid, info, op_class, ch, phy_type, buf); |
| 7947 | if (ret < 0 || ret >= NEIGHBOR_REPORT_SIZE - len) { |
| 7948 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7949 | "snprintf failed for neighbor report list ret: %d", |
| 7950 | ret); |
| 7951 | send_resp(dut, conn, SIGMA_ERROR, |
| 7952 | "errorCode,snprintf failed for neighbor report"); |
| 7953 | free(dut->btm_query_cand_list); |
| 7954 | dut->btm_query_cand_list = NULL; |
| 7955 | return 0; |
| 7956 | } |
| 7957 | |
| 7958 | return 1; |
| 7959 | } |
| 7960 | |
| 7961 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7962 | static int cmd_sta_set_rfeature(struct sigma_dut *dut, struct sigma_conn *conn, |
| 7963 | struct sigma_cmd *cmd) |
| 7964 | { |
| 7965 | const char *intf = get_param(cmd, "Interface"); |
| 7966 | const char *prog = get_param(cmd, "Prog"); |
Ashwini Patil | 68d02cd | 2017-01-10 15:39:16 +0530 | [diff] [blame] | 7967 | const char *val; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7968 | |
| 7969 | if (intf == NULL || prog == NULL) |
| 7970 | return -1; |
| 7971 | |
Ashwini Patil | 5acd738 | 2017-04-13 15:55:04 +0530 | [diff] [blame] | 7972 | /* BSS Transition candidate list for BTM query */ |
| 7973 | val = get_param(cmd, "Nebor_BSSID"); |
| 7974 | if (val && btm_query_candidate_list(dut, conn, cmd) == 0) |
| 7975 | return 0; |
| 7976 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7977 | if (strcasecmp(prog, "TDLS") == 0) |
| 7978 | return cmd_sta_set_rfeature_tdls(intf, dut, conn, cmd); |
| 7979 | |
| 7980 | if (strcasecmp(prog, "VHT") == 0) |
| 7981 | return cmd_sta_set_rfeature_vht(intf, dut, conn, cmd); |
| 7982 | |
Ashwini Patil | 68d02cd | 2017-01-10 15:39:16 +0530 | [diff] [blame] | 7983 | if (strcasecmp(prog, "MBO") == 0) { |
| 7984 | val = get_param(cmd, "Cellular_Data_Cap"); |
| 7985 | if (val && |
| 7986 | mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0) |
| 7987 | return 0; |
Ashwini Patil | 0040258 | 2017-04-13 12:29:39 +0530 | [diff] [blame] | 7988 | |
| 7989 | val = get_param(cmd, "Ch_Pref"); |
| 7990 | if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0) |
| 7991 | return 0; |
| 7992 | |
Ashwini Patil | 68d02cd | 2017-01-10 15:39:16 +0530 | [diff] [blame] | 7993 | return 1; |
| 7994 | } |
| 7995 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7996 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported Prog"); |
| 7997 | return 0; |
| 7998 | } |
| 7999 | |
| 8000 | |
| 8001 | static int cmd_sta_set_radio(struct sigma_dut *dut, struct sigma_conn *conn, |
| 8002 | struct sigma_cmd *cmd) |
| 8003 | { |
| 8004 | const char *intf = get_param(cmd, "Interface"); |
| 8005 | const char *mode = get_param(cmd, "Mode"); |
| 8006 | int res; |
| 8007 | |
| 8008 | if (intf == NULL || mode == NULL) |
| 8009 | return -1; |
| 8010 | |
| 8011 | if (strcasecmp(mode, "On") == 0) |
| 8012 | res = wpa_command(intf, "SET radio_disabled 0"); |
| 8013 | else if (strcasecmp(mode, "Off") == 0) |
| 8014 | res = wpa_command(intf, "SET radio_disabled 1"); |
| 8015 | else |
| 8016 | return -1; |
| 8017 | |
| 8018 | if (res) { |
| 8019 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change " |
| 8020 | "radio mode"); |
| 8021 | return 0; |
| 8022 | } |
| 8023 | |
| 8024 | return 1; |
| 8025 | } |
| 8026 | |
| 8027 | |
| 8028 | static int cmd_sta_set_pwrsave(struct sigma_dut *dut, struct sigma_conn *conn, |
| 8029 | struct sigma_cmd *cmd) |
| 8030 | { |
| 8031 | const char *intf = get_param(cmd, "Interface"); |
| 8032 | const char *mode = get_param(cmd, "Mode"); |
| 8033 | int res; |
| 8034 | |
| 8035 | if (intf == NULL || mode == NULL) |
| 8036 | return -1; |
| 8037 | |
| 8038 | if (strcasecmp(mode, "On") == 0) |
| 8039 | res = set_ps(intf, dut, 1); |
| 8040 | else if (strcasecmp(mode, "Off") == 0) |
| 8041 | res = set_ps(intf, dut, 0); |
| 8042 | else |
| 8043 | return -1; |
| 8044 | |
| 8045 | if (res) { |
| 8046 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change " |
| 8047 | "power save mode"); |
| 8048 | return 0; |
| 8049 | } |
| 8050 | |
| 8051 | return 1; |
| 8052 | } |
| 8053 | |
| 8054 | |
| 8055 | static int cmd_sta_bssid_pool(struct sigma_dut *dut, struct sigma_conn *conn, |
| 8056 | struct sigma_cmd *cmd) |
| 8057 | { |
| 8058 | const char *intf = get_param(cmd, "Interface"); |
| 8059 | const char *val, *bssid; |
| 8060 | int res; |
| 8061 | char *buf; |
| 8062 | size_t buf_len; |
| 8063 | |
| 8064 | val = get_param(cmd, "BSSID_FILTER"); |
| 8065 | if (val == NULL) |
| 8066 | return -1; |
| 8067 | |
| 8068 | bssid = get_param(cmd, "BSSID_List"); |
| 8069 | if (atoi(val) == 0 || bssid == NULL) { |
| 8070 | /* Disable BSSID filter */ |
| 8071 | if (wpa_command(intf, "SET bssid_filter ")) { |
| 8072 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed " |
| 8073 | "to disable BSSID filter"); |
| 8074 | return 0; |
| 8075 | } |
| 8076 | |
| 8077 | return 1; |
| 8078 | } |
| 8079 | |
| 8080 | buf_len = 100 + strlen(bssid); |
| 8081 | buf = malloc(buf_len); |
| 8082 | if (buf == NULL) |
| 8083 | return -1; |
| 8084 | |
| 8085 | snprintf(buf, buf_len, "SET bssid_filter %s", bssid); |
| 8086 | res = wpa_command(intf, buf); |
| 8087 | free(buf); |
| 8088 | if (res) { |
| 8089 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to enable " |
| 8090 | "BSSID filter"); |
| 8091 | return 0; |
| 8092 | } |
| 8093 | |
| 8094 | return 1; |
| 8095 | } |
| 8096 | |
| 8097 | |
| 8098 | static int cmd_sta_reset_parm(struct sigma_dut *dut, struct sigma_conn *conn, |
| 8099 | struct sigma_cmd *cmd) |
| 8100 | { |
| 8101 | const char *intf = get_param(cmd, "Interface"); |
| 8102 | const char *val; |
| 8103 | |
| 8104 | /* TODO: ARP */ |
| 8105 | |
| 8106 | val = get_param(cmd, "HS2_CACHE_PROFILE"); |
| 8107 | if (val && strcasecmp(val, "All") == 0) |
| 8108 | hs2_clear_credentials(intf); |
| 8109 | |
| 8110 | return 1; |
| 8111 | } |
| 8112 | |
| 8113 | |
| 8114 | static int cmd_sta_get_key(struct sigma_dut *dut, struct sigma_conn *conn, |
| 8115 | struct sigma_cmd *cmd) |
| 8116 | { |
| 8117 | const char *intf = get_param(cmd, "Interface"); |
| 8118 | const char *key_type = get_param(cmd, "KeyType"); |
| 8119 | char buf[100], resp[200]; |
| 8120 | |
| 8121 | if (key_type == NULL) |
| 8122 | return -1; |
| 8123 | |
| 8124 | if (strcasecmp(key_type, "GTK") == 0) { |
| 8125 | if (wpa_command_resp(intf, "GET gtk", buf, sizeof(buf)) < 0 || |
| 8126 | strncmp(buf, "FAIL", 4) == 0) { |
| 8127 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could " |
| 8128 | "not fetch current GTK"); |
| 8129 | return 0; |
| 8130 | } |
| 8131 | snprintf(resp, sizeof(resp), "KeyValue,%s", buf); |
| 8132 | send_resp(dut, conn, SIGMA_COMPLETE, resp); |
| 8133 | return 0; |
| 8134 | } else { |
| 8135 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported " |
| 8136 | "KeyType"); |
| 8137 | return 0; |
| 8138 | } |
| 8139 | |
| 8140 | return 1; |
| 8141 | } |
| 8142 | |
| 8143 | |
| 8144 | static int hs2_set_policy(struct sigma_dut *dut) |
| 8145 | { |
| 8146 | #ifdef ANDROID |
| 8147 | system("ip rule del prio 23000"); |
| 8148 | if (system("ip rule add from all lookup main prio 23000") != 0) { |
| 8149 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8150 | "Failed to run:ip rule add from all lookup main prio"); |
| 8151 | return -1; |
| 8152 | } |
| 8153 | if (system("ip route flush cache") != 0) { |
| 8154 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8155 | "Failed to run ip route flush cache"); |
| 8156 | return -1; |
| 8157 | } |
| 8158 | return 1; |
| 8159 | #else /* ANDROID */ |
| 8160 | return 0; |
| 8161 | #endif /* ANDROID */ |
| 8162 | } |
| 8163 | |
| 8164 | |
| 8165 | static int cmd_sta_hs2_associate(struct sigma_dut *dut, |
| 8166 | struct sigma_conn *conn, |
| 8167 | struct sigma_cmd *cmd) |
| 8168 | { |
| 8169 | const char *intf = get_param(cmd, "Interface"); |
| 8170 | const char *val = get_param(cmd, "Ignore_blacklist"); |
| 8171 | struct wpa_ctrl *ctrl; |
| 8172 | int res; |
| 8173 | char bssid[20], ssid[40], resp[100], buf[100], blacklisted[100]; |
| 8174 | int tries = 0; |
| 8175 | int ignore_blacklist = 0; |
| 8176 | const char *events[] = { |
| 8177 | "CTRL-EVENT-CONNECTED", |
| 8178 | "INTERWORKING-BLACKLISTED", |
| 8179 | "INTERWORKING-NO-MATCH", |
| 8180 | NULL |
| 8181 | }; |
| 8182 | |
| 8183 | start_sta_mode(dut); |
| 8184 | |
| 8185 | blacklisted[0] = '\0'; |
| 8186 | if (val && atoi(val)) |
| 8187 | ignore_blacklist = 1; |
| 8188 | |
| 8189 | try_again: |
| 8190 | ctrl = open_wpa_mon(intf); |
| 8191 | if (ctrl == NULL) { |
| 8192 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open " |
| 8193 | "wpa_supplicant monitor connection"); |
| 8194 | return -2; |
| 8195 | } |
| 8196 | |
| 8197 | tries++; |
| 8198 | if (wpa_command(intf, "INTERWORKING_SELECT auto")) { |
| 8199 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start " |
| 8200 | "Interworking connection"); |
| 8201 | wpa_ctrl_detach(ctrl); |
| 8202 | wpa_ctrl_close(ctrl); |
| 8203 | return 0; |
| 8204 | } |
| 8205 | |
| 8206 | buf[0] = '\0'; |
| 8207 | while (1) { |
| 8208 | char *pos; |
| 8209 | res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf)); |
| 8210 | pos = strstr(buf, "INTERWORKING-BLACKLISTED"); |
| 8211 | if (!pos) |
| 8212 | break; |
| 8213 | pos += 25; |
| 8214 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Found blacklisted AP: %s", |
| 8215 | pos); |
| 8216 | if (!blacklisted[0]) |
| 8217 | memcpy(blacklisted, pos, strlen(pos) + 1); |
| 8218 | } |
| 8219 | |
| 8220 | if (ignore_blacklist && blacklisted[0]) { |
| 8221 | char *end; |
| 8222 | end = strchr(blacklisted, ' '); |
| 8223 | if (end) |
| 8224 | *end = '\0'; |
| 8225 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Try to connect to a blacklisted network: %s", |
| 8226 | blacklisted); |
| 8227 | snprintf(buf, sizeof(buf), "INTERWORKING_CONNECT %s", |
| 8228 | blacklisted); |
| 8229 | if (wpa_command(intf, buf)) { |
| 8230 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start Interworking connection to blacklisted network"); |
| 8231 | wpa_ctrl_detach(ctrl); |
| 8232 | wpa_ctrl_close(ctrl); |
| 8233 | return 0; |
| 8234 | } |
| 8235 | res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED", |
| 8236 | buf, sizeof(buf)); |
| 8237 | } |
| 8238 | |
| 8239 | wpa_ctrl_detach(ctrl); |
| 8240 | wpa_ctrl_close(ctrl); |
| 8241 | |
| 8242 | if (res < 0) { |
| 8243 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not " |
| 8244 | "connect"); |
| 8245 | return 0; |
| 8246 | } |
| 8247 | |
| 8248 | if (strstr(buf, "INTERWORKING-NO-MATCH") || |
| 8249 | strstr(buf, "INTERWORKING-BLACKLISTED")) { |
| 8250 | if (tries < 2) { |
| 8251 | sigma_dut_print(dut, DUT_MSG_INFO, "No match found - try again to verify no APs were missed in the scan"); |
| 8252 | goto try_again; |
| 8253 | } |
| 8254 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,No network with " |
| 8255 | "matching credentials found"); |
| 8256 | return 0; |
| 8257 | } |
| 8258 | |
| 8259 | if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 || |
| 8260 | get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) { |
| 8261 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not " |
| 8262 | "get current BSSID/SSID"); |
| 8263 | return 0; |
| 8264 | } |
| 8265 | |
| 8266 | snprintf(resp, sizeof(resp), "SSID,%s,BSSID,%s", ssid, bssid); |
| 8267 | send_resp(dut, conn, SIGMA_COMPLETE, resp); |
| 8268 | hs2_set_policy(dut); |
| 8269 | return 0; |
| 8270 | } |
| 8271 | |
| 8272 | |
| 8273 | static int sta_add_credential_uname_pwd(struct sigma_dut *dut, |
| 8274 | struct sigma_conn *conn, |
| 8275 | const char *ifname, |
| 8276 | struct sigma_cmd *cmd) |
| 8277 | { |
| 8278 | const char *val; |
| 8279 | int id; |
| 8280 | |
| 8281 | id = add_cred(ifname); |
| 8282 | if (id < 0) |
| 8283 | return -2; |
| 8284 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id); |
| 8285 | |
| 8286 | val = get_param(cmd, "prefer"); |
| 8287 | if (val && atoi(val) > 0) |
| 8288 | set_cred(ifname, id, "priority", "1"); |
| 8289 | |
| 8290 | val = get_param(cmd, "REALM"); |
| 8291 | if (val && set_cred_quoted(ifname, id, "realm", val) < 0) { |
| 8292 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set " |
| 8293 | "realm"); |
| 8294 | return 0; |
| 8295 | } |
| 8296 | |
| 8297 | val = get_param(cmd, "HOME_FQDN"); |
| 8298 | if (val && set_cred_quoted(ifname, id, "domain", val) < 0) { |
| 8299 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set " |
| 8300 | "home_fqdn"); |
| 8301 | return 0; |
| 8302 | } |
| 8303 | |
| 8304 | val = get_param(cmd, "Username"); |
| 8305 | if (val && set_cred_quoted(ifname, id, "username", val) < 0) { |
| 8306 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set " |
| 8307 | "username"); |
| 8308 | return 0; |
| 8309 | } |
| 8310 | |
| 8311 | val = get_param(cmd, "Password"); |
| 8312 | if (val && set_cred_quoted(ifname, id, "password", val) < 0) { |
| 8313 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set " |
| 8314 | "password"); |
| 8315 | return 0; |
| 8316 | } |
| 8317 | |
| 8318 | val = get_param(cmd, "ROOT_CA"); |
| 8319 | if (val) { |
| 8320 | char fname[200]; |
| 8321 | snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val); |
| 8322 | #ifdef __linux__ |
| 8323 | if (!file_exists(fname)) { |
| 8324 | char msg[300]; |
| 8325 | snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA " |
| 8326 | "file (%s) not found", fname); |
| 8327 | send_resp(dut, conn, SIGMA_ERROR, msg); |
| 8328 | return 0; |
| 8329 | } |
| 8330 | #endif /* __linux__ */ |
| 8331 | if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) { |
| 8332 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could " |
| 8333 | "not set root CA"); |
| 8334 | return 0; |
| 8335 | } |
| 8336 | } |
| 8337 | |
| 8338 | return 1; |
| 8339 | } |
| 8340 | |
| 8341 | |
| 8342 | static int update_devdetail_imsi(struct sigma_dut *dut, const char *imsi) |
| 8343 | { |
| 8344 | FILE *in, *out; |
| 8345 | char buf[500]; |
| 8346 | int found = 0; |
| 8347 | |
| 8348 | in = fopen("devdetail.xml", "r"); |
| 8349 | if (in == NULL) |
| 8350 | return -1; |
| 8351 | out = fopen("devdetail.xml.tmp", "w"); |
| 8352 | if (out == NULL) { |
| 8353 | fclose(in); |
| 8354 | return -1; |
| 8355 | } |
| 8356 | |
| 8357 | while (fgets(buf, sizeof(buf), in)) { |
| 8358 | char *pos = strstr(buf, "<IMSI>"); |
| 8359 | if (pos) { |
| 8360 | sigma_dut_print(dut, DUT_MSG_INFO, "Updated DevDetail IMSI to %s", |
| 8361 | imsi); |
| 8362 | pos += 6; |
| 8363 | *pos = '\0'; |
| 8364 | fprintf(out, "%s%s</IMSI>\n", buf, imsi); |
| 8365 | found++; |
| 8366 | } else { |
| 8367 | fprintf(out, "%s", buf); |
| 8368 | } |
| 8369 | } |
| 8370 | |
| 8371 | fclose(out); |
| 8372 | fclose(in); |
| 8373 | if (found) |
| 8374 | rename("devdetail.xml.tmp", "devdetail.xml"); |
| 8375 | else |
| 8376 | unlink("devdetail.xml.tmp"); |
| 8377 | |
| 8378 | return 0; |
| 8379 | } |
| 8380 | |
| 8381 | |
| 8382 | static int sta_add_credential_sim(struct sigma_dut *dut, |
| 8383 | struct sigma_conn *conn, |
| 8384 | const char *ifname, struct sigma_cmd *cmd) |
| 8385 | { |
| 8386 | const char *val, *imsi = NULL; |
| 8387 | int id; |
| 8388 | char buf[200]; |
| 8389 | int res; |
| 8390 | const char *pos; |
| 8391 | size_t mnc_len; |
| 8392 | char plmn_mcc[4]; |
| 8393 | char plmn_mnc[4]; |
| 8394 | |
| 8395 | id = add_cred(ifname); |
| 8396 | if (id < 0) |
| 8397 | return -2; |
| 8398 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id); |
| 8399 | |
| 8400 | val = get_param(cmd, "prefer"); |
| 8401 | if (val && atoi(val) > 0) |
| 8402 | set_cred(ifname, id, "priority", "1"); |
| 8403 | |
| 8404 | val = get_param(cmd, "PLMN_MCC"); |
| 8405 | if (val == NULL) { |
| 8406 | send_resp(dut, conn, SIGMA_ERROR, |
| 8407 | "errorCode,Missing PLMN_MCC"); |
| 8408 | return 0; |
| 8409 | } |
| 8410 | if (strlen(val) != 3) { |
| 8411 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MCC"); |
| 8412 | return 0; |
| 8413 | } |
| 8414 | snprintf(plmn_mcc, sizeof(plmn_mcc), "%s", val); |
| 8415 | |
| 8416 | val = get_param(cmd, "PLMN_MNC"); |
| 8417 | if (val == NULL) { |
| 8418 | send_resp(dut, conn, SIGMA_ERROR, |
| 8419 | "errorCode,Missing PLMN_MNC"); |
| 8420 | return 0; |
| 8421 | } |
| 8422 | if (strlen(val) != 2 && strlen(val) != 3) { |
| 8423 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MNC"); |
| 8424 | return 0; |
| 8425 | } |
| 8426 | snprintf(plmn_mnc, sizeof(plmn_mnc), "%s", val); |
| 8427 | |
| 8428 | val = get_param(cmd, "IMSI"); |
| 8429 | if (val == NULL) { |
| 8430 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing SIM " |
| 8431 | "IMSI"); |
| 8432 | return 0; |
| 8433 | } |
| 8434 | |
| 8435 | imsi = pos = val; |
| 8436 | |
| 8437 | if (strncmp(plmn_mcc, pos, 3) != 0) { |
| 8438 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,MCC mismatch"); |
| 8439 | return 0; |
| 8440 | } |
| 8441 | pos += 3; |
| 8442 | |
| 8443 | mnc_len = strlen(plmn_mnc); |
| 8444 | if (mnc_len < 2) { |
| 8445 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC not set"); |
| 8446 | return 0; |
| 8447 | } |
| 8448 | |
| 8449 | if (strncmp(plmn_mnc, pos, mnc_len) != 0) { |
| 8450 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC mismatch"); |
| 8451 | return 0; |
| 8452 | } |
| 8453 | pos += mnc_len; |
| 8454 | |
| 8455 | res = snprintf(buf, sizeof(buf), "%s%s-%s",plmn_mcc, plmn_mnc, pos); |
| 8456 | if (res < 0 || res >= (int) sizeof(buf)) |
| 8457 | return -1; |
| 8458 | if (set_cred_quoted(ifname, id, "imsi", buf) < 0) { |
| 8459 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could " |
| 8460 | "not set IMSI"); |
| 8461 | return 0; |
| 8462 | } |
| 8463 | |
| 8464 | val = get_param(cmd, "Password"); |
| 8465 | if (val && set_cred_quoted(ifname, id, "milenage", val) < 0) { |
| 8466 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could " |
| 8467 | "not set password"); |
| 8468 | return 0; |
| 8469 | } |
| 8470 | |
| 8471 | if (dut->program == PROGRAM_HS2_R2) { |
| 8472 | /* |
| 8473 | * Set provisioning_sp for the test cases where SIM/USIM |
| 8474 | * provisioning is used. |
| 8475 | */ |
| 8476 | if (val && set_cred_quoted(ifname, id, "provisioning_sp", |
| 8477 | "wi-fi.org") < 0) { |
| 8478 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could " |
| 8479 | "not set provisioning_sp"); |
| 8480 | return 0; |
| 8481 | } |
| 8482 | |
| 8483 | update_devdetail_imsi(dut, imsi); |
| 8484 | } |
| 8485 | |
| 8486 | return 1; |
| 8487 | } |
| 8488 | |
| 8489 | |
| 8490 | static int sta_add_credential_cert(struct sigma_dut *dut, |
| 8491 | struct sigma_conn *conn, |
| 8492 | const char *ifname, |
| 8493 | struct sigma_cmd *cmd) |
| 8494 | { |
| 8495 | const char *val; |
| 8496 | int id; |
| 8497 | |
| 8498 | id = add_cred(ifname); |
| 8499 | if (id < 0) |
| 8500 | return -2; |
| 8501 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id); |
| 8502 | |
| 8503 | val = get_param(cmd, "prefer"); |
| 8504 | if (val && atoi(val) > 0) |
| 8505 | set_cred(ifname, id, "priority", "1"); |
| 8506 | |
| 8507 | val = get_param(cmd, "REALM"); |
| 8508 | if (val && set_cred_quoted(ifname, id, "realm", val) < 0) { |
| 8509 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set " |
| 8510 | "realm"); |
| 8511 | return 0; |
| 8512 | } |
| 8513 | |
| 8514 | val = get_param(cmd, "HOME_FQDN"); |
| 8515 | if (val && set_cred_quoted(ifname, id, "domain", val) < 0) { |
| 8516 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set " |
| 8517 | "home_fqdn"); |
| 8518 | return 0; |
| 8519 | } |
| 8520 | |
| 8521 | val = get_param(cmd, "Username"); |
| 8522 | if (val && set_cred_quoted(ifname, id, "username", val) < 0) { |
| 8523 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set " |
| 8524 | "username"); |
| 8525 | return 0; |
| 8526 | } |
| 8527 | |
| 8528 | val = get_param(cmd, "clientCertificate"); |
| 8529 | if (val) { |
| 8530 | char fname[200]; |
| 8531 | snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val); |
| 8532 | #ifdef __linux__ |
| 8533 | if (!file_exists(fname)) { |
| 8534 | char msg[300]; |
| 8535 | snprintf(msg, sizeof(msg), |
| 8536 | "ErrorCode,clientCertificate " |
| 8537 | "file (%s) not found", fname); |
| 8538 | send_resp(dut, conn, SIGMA_ERROR, msg); |
| 8539 | return 0; |
| 8540 | } |
| 8541 | #endif /* __linux__ */ |
| 8542 | if (set_cred_quoted(ifname, id, "client_cert", fname) < 0) { |
| 8543 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could " |
| 8544 | "not set client_cert"); |
| 8545 | return 0; |
| 8546 | } |
| 8547 | if (set_cred_quoted(ifname, id, "private_key", fname) < 0) { |
| 8548 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could " |
| 8549 | "not set private_key"); |
| 8550 | return 0; |
| 8551 | } |
| 8552 | } |
| 8553 | |
| 8554 | val = get_param(cmd, "ROOT_CA"); |
| 8555 | if (val) { |
| 8556 | char fname[200]; |
| 8557 | snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val); |
| 8558 | #ifdef __linux__ |
| 8559 | if (!file_exists(fname)) { |
| 8560 | char msg[300]; |
| 8561 | snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA " |
| 8562 | "file (%s) not found", fname); |
| 8563 | send_resp(dut, conn, SIGMA_ERROR, msg); |
| 8564 | return 0; |
| 8565 | } |
| 8566 | #endif /* __linux__ */ |
| 8567 | if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) { |
| 8568 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could " |
| 8569 | "not set root CA"); |
| 8570 | return 0; |
| 8571 | } |
| 8572 | } |
| 8573 | |
| 8574 | return 1; |
| 8575 | } |
| 8576 | |
| 8577 | |
| 8578 | static int cmd_sta_add_credential(struct sigma_dut *dut, |
| 8579 | struct sigma_conn *conn, |
| 8580 | struct sigma_cmd *cmd) |
| 8581 | { |
| 8582 | const char *intf = get_param(cmd, "Interface"); |
| 8583 | const char *type; |
| 8584 | |
| 8585 | start_sta_mode(dut); |
| 8586 | |
| 8587 | type = get_param(cmd, "Type"); |
| 8588 | if (!type) |
| 8589 | return -1; |
| 8590 | |
| 8591 | if (strcasecmp(type, "uname_pwd") == 0) |
| 8592 | return sta_add_credential_uname_pwd(dut, conn, intf, cmd); |
| 8593 | |
| 8594 | if (strcasecmp(type, "sim") == 0) |
| 8595 | return sta_add_credential_sim(dut, conn, intf, cmd); |
| 8596 | |
| 8597 | if (strcasecmp(type, "cert") == 0) |
| 8598 | return sta_add_credential_cert(dut, conn, intf, cmd); |
| 8599 | |
| 8600 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported credential " |
| 8601 | "type"); |
| 8602 | return 0; |
| 8603 | } |
| 8604 | |
| 8605 | |
| 8606 | static int cmd_sta_scan(struct sigma_dut *dut, struct sigma_conn *conn, |
| 8607 | struct sigma_cmd *cmd) |
| 8608 | { |
| 8609 | const char *intf = get_param(cmd, "Interface"); |
vamsi krishna | 89ad8c6 | 2017-09-19 12:51:18 +0530 | [diff] [blame] | 8610 | const char *val, *bssid, *ssid; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8611 | char buf[100]; |
vamsi krishna | 89ad8c6 | 2017-09-19 12:51:18 +0530 | [diff] [blame] | 8612 | char ssid_hex[65]; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8613 | int res; |
| 8614 | |
| 8615 | val = get_param(cmd, "HESSID"); |
| 8616 | if (val) { |
| 8617 | res = snprintf(buf, sizeof(buf), "SET hessid %s", val); |
| 8618 | if (res < 0 || res >= (int) sizeof(buf)) |
| 8619 | return -1; |
| 8620 | wpa_command(intf, buf); |
| 8621 | } |
| 8622 | |
| 8623 | val = get_param(cmd, "ACCS_NET_TYPE"); |
| 8624 | if (val) { |
| 8625 | res = snprintf(buf, sizeof(buf), "SET access_network_type %s", |
| 8626 | val); |
| 8627 | if (res < 0 || res >= (int) sizeof(buf)) |
| 8628 | return -1; |
| 8629 | wpa_command(intf, buf); |
| 8630 | } |
| 8631 | |
vamsi krishna | 89ad8c6 | 2017-09-19 12:51:18 +0530 | [diff] [blame] | 8632 | bssid = get_param(cmd, "Bssid"); |
| 8633 | ssid = get_param(cmd, "Ssid"); |
| 8634 | |
| 8635 | if (ssid) { |
| 8636 | if (2 * strlen(ssid) >= sizeof(ssid_hex)) { |
| 8637 | send_resp(dut, conn, SIGMA_ERROR, |
| 8638 | "ErrorCode,Too long SSID"); |
| 8639 | return 0; |
| 8640 | } |
| 8641 | ascii2hexstr(ssid, ssid_hex); |
| 8642 | } |
| 8643 | |
| 8644 | res = snprintf(buf, sizeof(buf), "SCAN%s%s%s%s", |
| 8645 | bssid ? " bssid=": "", |
| 8646 | bssid ? bssid : "", |
| 8647 | ssid ? " ssid " : "", |
| 8648 | ssid ? ssid_hex : ""); |
| 8649 | if (res < 0 || res >= (int) sizeof(buf)) |
| 8650 | return -1; |
| 8651 | |
| 8652 | if (wpa_command(intf, buf)) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8653 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not start " |
| 8654 | "scan"); |
| 8655 | return 0; |
| 8656 | } |
| 8657 | |
| 8658 | return 1; |
| 8659 | } |
| 8660 | |
| 8661 | |
| 8662 | static int cmd_sta_set_systime(struct sigma_dut *dut, struct sigma_conn *conn, |
| 8663 | struct sigma_cmd *cmd) |
| 8664 | { |
| 8665 | #ifdef __linux__ |
| 8666 | struct timeval tv; |
| 8667 | struct tm tm; |
| 8668 | time_t t; |
| 8669 | const char *val; |
Pradeep Reddy POTTETI | 429c69e | 2016-10-13 17:22:03 +0530 | [diff] [blame] | 8670 | int v; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8671 | |
| 8672 | wpa_command(get_station_ifname(), "PMKSA_FLUSH"); |
| 8673 | |
| 8674 | memset(&tm, 0, sizeof(tm)); |
| 8675 | val = get_param(cmd, "seconds"); |
| 8676 | if (val) |
| 8677 | tm.tm_sec = atoi(val); |
| 8678 | val = get_param(cmd, "minutes"); |
| 8679 | if (val) |
| 8680 | tm.tm_min = atoi(val); |
| 8681 | val = get_param(cmd, "hours"); |
| 8682 | if (val) |
| 8683 | tm.tm_hour = atoi(val); |
| 8684 | val = get_param(cmd, "date"); |
| 8685 | if (val) |
| 8686 | tm.tm_mday = atoi(val); |
| 8687 | val = get_param(cmd, "month"); |
Pradeep Reddy POTTETI | 429c69e | 2016-10-13 17:22:03 +0530 | [diff] [blame] | 8688 | if (val) { |
| 8689 | v = atoi(val); |
| 8690 | if (v < 1 || v > 12) { |
| 8691 | send_resp(dut, conn, SIGMA_INVALID, |
| 8692 | "errorCode,Invalid month"); |
| 8693 | return 0; |
| 8694 | } |
| 8695 | tm.tm_mon = v - 1; |
| 8696 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8697 | val = get_param(cmd, "year"); |
| 8698 | if (val) { |
| 8699 | int year = atoi(val); |
| 8700 | #ifdef ANDROID |
| 8701 | if (year > 2035) |
| 8702 | year = 2035; /* years beyond 2035 not supported */ |
| 8703 | #endif /* ANDROID */ |
| 8704 | tm.tm_year = year - 1900; |
| 8705 | } |
| 8706 | t = mktime(&tm); |
| 8707 | if (t == (time_t) -1) { |
| 8708 | send_resp(dut, conn, SIGMA_ERROR, |
| 8709 | "errorCode,Invalid date or time"); |
| 8710 | return 0; |
| 8711 | } |
| 8712 | |
| 8713 | memset(&tv, 0, sizeof(tv)); |
| 8714 | tv.tv_sec = t; |
| 8715 | |
| 8716 | if (settimeofday(&tv, NULL) < 0) { |
| 8717 | sigma_dut_print(dut, DUT_MSG_INFO, "settimeofday failed: %s", |
| 8718 | strerror(errno)); |
| 8719 | send_resp(dut, conn, SIGMA_ERROR, |
| 8720 | "errorCode,Failed to set time"); |
| 8721 | return 0; |
| 8722 | } |
| 8723 | |
| 8724 | return 1; |
| 8725 | #endif /* __linux__ */ |
| 8726 | |
| 8727 | return -1; |
| 8728 | } |
| 8729 | |
| 8730 | |
| 8731 | static int cmd_sta_osu(struct sigma_dut *dut, struct sigma_conn *conn, |
| 8732 | struct sigma_cmd *cmd) |
| 8733 | { |
| 8734 | const char *intf = get_param(cmd, "Interface"); |
| 8735 | const char *name, *val; |
| 8736 | int prod_ess_assoc = 1; |
| 8737 | char buf[200], bssid[100], ssid[100]; |
| 8738 | int res; |
| 8739 | struct wpa_ctrl *ctrl; |
| 8740 | |
| 8741 | name = get_param(cmd, "osuFriendlyName"); |
| 8742 | |
| 8743 | val = get_param(cmd, "ProdESSAssoc"); |
| 8744 | if (val) |
| 8745 | prod_ess_assoc = atoi(val); |
| 8746 | |
| 8747 | kill_dhcp_client(dut, intf); |
| 8748 | if (start_dhcp_client(dut, intf) < 0) |
| 8749 | return -2; |
| 8750 | |
| 8751 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger OSU"); |
| 8752 | mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); |
| 8753 | res = snprintf(buf, sizeof(buf), |
| 8754 | "%s %s%s%s signup osu-ca.pem", |
| 8755 | prod_ess_assoc ? "" : "-N", |
| 8756 | name ? "-O'" : "", name ? name : "", |
| 8757 | name ? "'" : ""); |
| 8758 | |
Kanchanapally, Vidyullatha | 12b6676 | 2015-12-31 16:46:42 +0530 | [diff] [blame] | 8759 | hs2_set_policy(dut); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8760 | if (run_hs20_osu(dut, buf) < 0) { |
| 8761 | FILE *f; |
| 8762 | |
| 8763 | sigma_dut_print(dut, DUT_MSG_INFO, "Failed to complete OSU"); |
| 8764 | |
| 8765 | f = fopen("hs20-osu-client.res", "r"); |
| 8766 | if (f) { |
| 8767 | char resp[400], res[300], *pos; |
| 8768 | if (!fgets(res, sizeof(res), f)) |
| 8769 | res[0] = '\0'; |
| 8770 | pos = strchr(res, '\n'); |
| 8771 | if (pos) |
| 8772 | *pos = '\0'; |
| 8773 | fclose(f); |
| 8774 | sigma_dut_summary(dut, "hs20-osu-client provisioning failed: %s", |
| 8775 | res); |
| 8776 | snprintf(resp, sizeof(resp), "notify-send '%s'", res); |
| 8777 | if (system(resp) != 0) { |
| 8778 | } |
| 8779 | snprintf(resp, sizeof(resp), |
| 8780 | "SSID,,BSSID,,failureReason,%s", res); |
| 8781 | send_resp(dut, conn, SIGMA_COMPLETE, resp); |
| 8782 | return 0; |
| 8783 | } |
| 8784 | |
| 8785 | send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,"); |
| 8786 | return 0; |
| 8787 | } |
| 8788 | |
| 8789 | if (!prod_ess_assoc) |
| 8790 | goto report; |
| 8791 | |
| 8792 | ctrl = open_wpa_mon(intf); |
| 8793 | if (ctrl == NULL) { |
| 8794 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open " |
| 8795 | "wpa_supplicant monitor connection"); |
| 8796 | return -1; |
| 8797 | } |
| 8798 | |
| 8799 | res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED", |
| 8800 | buf, sizeof(buf)); |
| 8801 | |
| 8802 | wpa_ctrl_detach(ctrl); |
| 8803 | wpa_ctrl_close(ctrl); |
| 8804 | |
| 8805 | if (res < 0) { |
| 8806 | sigma_dut_print(dut, DUT_MSG_INFO, "Failed to connect to " |
| 8807 | "network after OSU"); |
| 8808 | send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,"); |
| 8809 | return 0; |
| 8810 | } |
| 8811 | |
| 8812 | report: |
| 8813 | if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 || |
| 8814 | get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) { |
| 8815 | sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get BSSID/SSID"); |
| 8816 | send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,"); |
| 8817 | return 0; |
| 8818 | } |
| 8819 | |
| 8820 | snprintf(buf, sizeof(buf), "SSID,%s,BSSID,%s", ssid, bssid); |
| 8821 | send_resp(dut, conn, SIGMA_COMPLETE, buf); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8822 | return 0; |
| 8823 | } |
| 8824 | |
| 8825 | |
| 8826 | static int cmd_sta_policy_update(struct sigma_dut *dut, struct sigma_conn *conn, |
| 8827 | struct sigma_cmd *cmd) |
| 8828 | { |
| 8829 | const char *val; |
| 8830 | int timeout = 120; |
| 8831 | |
| 8832 | val = get_param(cmd, "PolicyUpdate"); |
| 8833 | if (val == NULL || atoi(val) == 0) |
| 8834 | return 1; /* No operation requested */ |
| 8835 | |
| 8836 | val = get_param(cmd, "Timeout"); |
| 8837 | if (val) |
| 8838 | timeout = atoi(val); |
| 8839 | |
| 8840 | if (timeout) { |
| 8841 | /* TODO: time out the command and return |
| 8842 | * PolicyUpdateStatus,TIMEOUT if needed. */ |
| 8843 | } |
| 8844 | |
| 8845 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger policy update"); |
| 8846 | mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); |
| 8847 | if (run_hs20_osu(dut, "pol_upd fqdn=wi-fi.org") < 0) { |
| 8848 | send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,FAIL"); |
| 8849 | return 0; |
| 8850 | } |
| 8851 | |
| 8852 | send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,SUCCESS"); |
| 8853 | return 0; |
| 8854 | } |
| 8855 | |
| 8856 | |
| 8857 | static int cmd_sta_er_config(struct sigma_dut *dut, struct sigma_conn *conn, |
| 8858 | struct sigma_cmd *cmd) |
| 8859 | { |
| 8860 | struct wpa_ctrl *ctrl; |
| 8861 | const char *intf = get_param(cmd, "Interface"); |
| 8862 | const char *bssid = get_param(cmd, "Bssid"); |
| 8863 | const char *ssid = get_param(cmd, "SSID"); |
| 8864 | const char *security = get_param(cmd, "Security"); |
| 8865 | const char *passphrase = get_param(cmd, "Passphrase"); |
| 8866 | const char *pin = get_param(cmd, "PIN"); |
| 8867 | char buf[1000]; |
| 8868 | char ssid_hex[200], passphrase_hex[200]; |
| 8869 | const char *keymgmt, *cipher; |
| 8870 | |
| 8871 | if (intf == NULL) |
| 8872 | intf = get_main_ifname(); |
| 8873 | |
| 8874 | if (!bssid) { |
| 8875 | send_resp(dut, conn, SIGMA_ERROR, |
| 8876 | "ErrorCode,Missing Bssid argument"); |
| 8877 | return 0; |
| 8878 | } |
| 8879 | |
| 8880 | if (!ssid) { |
| 8881 | send_resp(dut, conn, SIGMA_ERROR, |
| 8882 | "ErrorCode,Missing SSID argument"); |
| 8883 | return 0; |
| 8884 | } |
| 8885 | |
| 8886 | if (!security) { |
| 8887 | send_resp(dut, conn, SIGMA_ERROR, |
| 8888 | "ErrorCode,Missing Security argument"); |
| 8889 | return 0; |
| 8890 | } |
| 8891 | |
| 8892 | if (!passphrase) { |
| 8893 | send_resp(dut, conn, SIGMA_ERROR, |
| 8894 | "ErrorCode,Missing Passphrase argument"); |
| 8895 | return 0; |
| 8896 | } |
| 8897 | |
| 8898 | if (!pin) { |
| 8899 | send_resp(dut, conn, SIGMA_ERROR, |
| 8900 | "ErrorCode,Missing PIN argument"); |
| 8901 | return 0; |
| 8902 | } |
| 8903 | |
vamsi krishna | 8c9c156 | 2017-05-12 15:51:46 +0530 | [diff] [blame] | 8904 | if (2 * strlen(ssid) >= sizeof(ssid_hex) || |
| 8905 | 2 * strlen(passphrase) >= sizeof(passphrase_hex)) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8906 | send_resp(dut, conn, SIGMA_ERROR, |
| 8907 | "ErrorCode,Too long SSID/passphrase"); |
| 8908 | return 0; |
| 8909 | } |
| 8910 | |
| 8911 | ctrl = open_wpa_mon(intf); |
| 8912 | if (ctrl == NULL) { |
| 8913 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open " |
| 8914 | "wpa_supplicant monitor connection"); |
| 8915 | return -2; |
| 8916 | } |
| 8917 | |
| 8918 | if (strcasecmp(security, "wpa2-psk") == 0) { |
| 8919 | keymgmt = "WPA2PSK"; |
| 8920 | cipher = "CCMP"; |
| 8921 | } else { |
| 8922 | wpa_ctrl_detach(ctrl); |
| 8923 | wpa_ctrl_close(ctrl); |
| 8924 | send_resp(dut, conn, SIGMA_ERROR, |
| 8925 | "ErrorCode,Unsupported Security value"); |
| 8926 | return 0; |
| 8927 | } |
| 8928 | |
| 8929 | ascii2hexstr(ssid, ssid_hex); |
| 8930 | ascii2hexstr(passphrase, passphrase_hex); |
| 8931 | snprintf(buf, sizeof(buf), "WPS_REG %s %s %s %s %s %s", |
| 8932 | bssid, pin, ssid_hex, keymgmt, cipher, passphrase_hex); |
| 8933 | |
| 8934 | if (wpa_command(intf, buf) < 0) { |
| 8935 | wpa_ctrl_detach(ctrl); |
| 8936 | wpa_ctrl_close(ctrl); |
| 8937 | send_resp(dut, conn, SIGMA_ERROR, |
| 8938 | "ErrorCode,Failed to start registrar"); |
| 8939 | return 0; |
| 8940 | } |
| 8941 | |
| 8942 | snprintf(dut->er_oper_bssid, sizeof(dut->er_oper_bssid), "%s", bssid); |
| 8943 | dut->er_oper_performed = 1; |
| 8944 | |
| 8945 | return wps_connection_event(dut, conn, ctrl, intf, 0); |
| 8946 | } |
| 8947 | |
| 8948 | |
| 8949 | static int cmd_sta_wps_connect_pw_token(struct sigma_dut *dut, |
| 8950 | struct sigma_conn *conn, |
| 8951 | struct sigma_cmd *cmd) |
| 8952 | { |
| 8953 | struct wpa_ctrl *ctrl; |
| 8954 | const char *intf = get_param(cmd, "Interface"); |
| 8955 | const char *bssid = get_param(cmd, "Bssid"); |
| 8956 | char buf[100]; |
| 8957 | |
| 8958 | if (!bssid) { |
| 8959 | send_resp(dut, conn, SIGMA_ERROR, |
| 8960 | "ErrorCode,Missing Bssid argument"); |
| 8961 | return 0; |
| 8962 | } |
| 8963 | |
| 8964 | ctrl = open_wpa_mon(intf); |
| 8965 | if (ctrl == NULL) { |
| 8966 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open " |
| 8967 | "wpa_supplicant monitor connection"); |
| 8968 | return -2; |
| 8969 | } |
| 8970 | |
| 8971 | snprintf(buf, sizeof(buf), "WPS_NFC %s", bssid); |
| 8972 | |
| 8973 | if (wpa_command(intf, buf) < 0) { |
| 8974 | wpa_ctrl_detach(ctrl); |
| 8975 | wpa_ctrl_close(ctrl); |
| 8976 | send_resp(dut, conn, SIGMA_ERROR, |
| 8977 | "ErrorCode,Failed to start registrar"); |
| 8978 | return 0; |
| 8979 | } |
| 8980 | |
| 8981 | return wps_connection_event(dut, conn, ctrl, intf, 0); |
| 8982 | } |
| 8983 | |
| 8984 | |
vamsi krishna | 9b14400 | 2017-09-20 13:28:13 +0530 | [diff] [blame] | 8985 | static int cmd_start_wps_registration(struct sigma_dut *dut, |
| 8986 | struct sigma_conn *conn, |
| 8987 | struct sigma_cmd *cmd) |
| 8988 | { |
| 8989 | struct wpa_ctrl *ctrl; |
| 8990 | const char *intf = get_param(cmd, "Interface"); |
| 8991 | const char *role, *method; |
| 8992 | int res; |
| 8993 | char buf[256]; |
| 8994 | const char *events[] = { |
| 8995 | "CTRL-EVENT-CONNECTED", |
| 8996 | "WPS-OVERLAP-DETECTED", |
| 8997 | "WPS-TIMEOUT", |
| 8998 | "WPS-FAIL", |
| 8999 | NULL |
| 9000 | }; |
| 9001 | |
| 9002 | ctrl = open_wpa_mon(intf); |
| 9003 | if (!ctrl) { |
| 9004 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 9005 | "Failed to open wpa_supplicant monitor connection"); |
| 9006 | return -2; |
| 9007 | } |
| 9008 | |
| 9009 | role = get_param(cmd, "WpsRole"); |
| 9010 | if (!role) { |
| 9011 | send_resp(dut, conn, SIGMA_INVALID, |
| 9012 | "ErrorCode,WpsRole not provided"); |
| 9013 | goto fail; |
| 9014 | } |
| 9015 | |
| 9016 | if (strcasecmp(role, "Enrollee") == 0) { |
| 9017 | method = get_param(cmd, "WpsConfigMethod"); |
| 9018 | if (!method) { |
| 9019 | send_resp(dut, conn, SIGMA_INVALID, |
| 9020 | "ErrorCode,WpsConfigMethod not provided"); |
| 9021 | goto fail; |
| 9022 | } |
| 9023 | if (strcasecmp(method, "PBC") == 0) { |
| 9024 | if (wpa_command(intf, "WPS_PBC") < 0) { |
| 9025 | send_resp(dut, conn, SIGMA_ERROR, |
| 9026 | "ErrorCode,Failed to enable PBC"); |
| 9027 | goto fail; |
| 9028 | } |
| 9029 | } else { |
| 9030 | /* TODO: PIN method */ |
| 9031 | send_resp(dut, conn, SIGMA_ERROR, |
| 9032 | "ErrorCode,Unsupported WpsConfigMethod value"); |
| 9033 | goto fail; |
| 9034 | } |
| 9035 | res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf)); |
| 9036 | if (res < 0) { |
| 9037 | send_resp(dut, conn, SIGMA_ERROR, |
| 9038 | "ErrorCode,WPS connection did not complete"); |
| 9039 | goto fail; |
| 9040 | } |
| 9041 | if (strstr(buf, "WPS-TIMEOUT")) { |
| 9042 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,NoPeer"); |
| 9043 | } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) { |
| 9044 | send_resp(dut, conn, SIGMA_ERROR, |
| 9045 | "ErrorCode,OverlapSession"); |
| 9046 | } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) { |
| 9047 | send_resp(dut, conn, SIGMA_COMPLETE, "Successful"); |
| 9048 | } else { |
| 9049 | send_resp(dut, conn, SIGMA_ERROR, |
| 9050 | "ErrorCode,WPS operation failed"); |
| 9051 | } |
| 9052 | } else { |
| 9053 | /* TODO: Registrar role */ |
| 9054 | send_resp(dut, conn, SIGMA_ERROR, |
| 9055 | "ErrorCode,Unsupported WpsRole value"); |
| 9056 | } |
| 9057 | |
| 9058 | fail: |
| 9059 | wpa_ctrl_detach(ctrl); |
| 9060 | wpa_ctrl_close(ctrl); |
| 9061 | return 0; |
| 9062 | } |
| 9063 | |
| 9064 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 9065 | static int req_intf(struct sigma_cmd *cmd) |
| 9066 | { |
| 9067 | return get_param(cmd, "interface") == NULL ? -1 : 0; |
| 9068 | } |
| 9069 | |
| 9070 | |
| 9071 | void sta_register_cmds(void) |
| 9072 | { |
| 9073 | sigma_dut_reg_cmd("sta_get_ip_config", req_intf, |
| 9074 | cmd_sta_get_ip_config); |
| 9075 | sigma_dut_reg_cmd("sta_set_ip_config", req_intf, |
| 9076 | cmd_sta_set_ip_config); |
| 9077 | sigma_dut_reg_cmd("sta_get_info", req_intf, cmd_sta_get_info); |
| 9078 | sigma_dut_reg_cmd("sta_get_mac_address", req_intf, |
| 9079 | cmd_sta_get_mac_address); |
| 9080 | sigma_dut_reg_cmd("sta_is_connected", req_intf, cmd_sta_is_connected); |
| 9081 | sigma_dut_reg_cmd("sta_verify_ip_connection", req_intf, |
| 9082 | cmd_sta_verify_ip_connection); |
| 9083 | sigma_dut_reg_cmd("sta_get_bssid", req_intf, cmd_sta_get_bssid); |
| 9084 | sigma_dut_reg_cmd("sta_set_encryption", req_intf, |
| 9085 | cmd_sta_set_encryption); |
| 9086 | sigma_dut_reg_cmd("sta_set_psk", req_intf, cmd_sta_set_psk); |
| 9087 | sigma_dut_reg_cmd("sta_set_eaptls", req_intf, cmd_sta_set_eaptls); |
| 9088 | sigma_dut_reg_cmd("sta_set_eapttls", req_intf, cmd_sta_set_eapttls); |
| 9089 | sigma_dut_reg_cmd("sta_set_eapsim", req_intf, cmd_sta_set_eapsim); |
| 9090 | sigma_dut_reg_cmd("sta_set_peap", req_intf, cmd_sta_set_peap); |
| 9091 | sigma_dut_reg_cmd("sta_set_eapfast", req_intf, cmd_sta_set_eapfast); |
| 9092 | sigma_dut_reg_cmd("sta_set_eapaka", req_intf, cmd_sta_set_eapaka); |
| 9093 | sigma_dut_reg_cmd("sta_set_eapakaprime", req_intf, |
| 9094 | cmd_sta_set_eapakaprime); |
| 9095 | sigma_dut_reg_cmd("sta_set_security", req_intf, cmd_sta_set_security); |
| 9096 | sigma_dut_reg_cmd("sta_set_uapsd", req_intf, cmd_sta_set_uapsd); |
| 9097 | /* TODO: sta_set_ibss */ |
| 9098 | /* TODO: sta_set_mode */ |
| 9099 | sigma_dut_reg_cmd("sta_set_wmm", req_intf, cmd_sta_set_wmm); |
| 9100 | sigma_dut_reg_cmd("sta_associate", req_intf, cmd_sta_associate); |
| 9101 | /* TODO: sta_up_load */ |
| 9102 | sigma_dut_reg_cmd("sta_preset_testparameters", req_intf, |
| 9103 | cmd_sta_preset_testparameters); |
| 9104 | /* TODO: sta_set_system */ |
| 9105 | sigma_dut_reg_cmd("sta_set_11n", req_intf, cmd_sta_set_11n); |
| 9106 | /* TODO: sta_set_rifs_test */ |
| 9107 | sigma_dut_reg_cmd("sta_set_wireless", req_intf, cmd_sta_set_wireless); |
| 9108 | sigma_dut_reg_cmd("sta_send_addba", req_intf, cmd_sta_send_addba); |
| 9109 | /* TODO: sta_send_coexist_mgmt */ |
| 9110 | sigma_dut_reg_cmd("sta_disconnect", req_intf, cmd_sta_disconnect); |
| 9111 | sigma_dut_reg_cmd("sta_reassoc", req_intf, cmd_sta_reassoc); |
| 9112 | sigma_dut_reg_cmd("sta_reassociate", req_intf, cmd_sta_reassoc); |
| 9113 | sigma_dut_reg_cmd("sta_reset_default", req_intf, |
| 9114 | cmd_sta_reset_default); |
| 9115 | sigma_dut_reg_cmd("sta_send_frame", req_intf, cmd_sta_send_frame); |
| 9116 | sigma_dut_reg_cmd("sta_set_macaddr", req_intf, cmd_sta_set_macaddr); |
| 9117 | sigma_dut_reg_cmd("sta_set_rfeature", req_intf, cmd_sta_set_rfeature); |
| 9118 | sigma_dut_reg_cmd("sta_set_radio", req_intf, cmd_sta_set_radio); |
| 9119 | sigma_dut_reg_cmd("sta_set_pwrsave", req_intf, cmd_sta_set_pwrsave); |
| 9120 | sigma_dut_reg_cmd("sta_bssid_pool", req_intf, cmd_sta_bssid_pool); |
| 9121 | sigma_dut_reg_cmd("sta_reset_parm", req_intf, cmd_sta_reset_parm); |
| 9122 | sigma_dut_reg_cmd("sta_get_key", req_intf, cmd_sta_get_key); |
| 9123 | sigma_dut_reg_cmd("sta_hs2_associate", req_intf, |
| 9124 | cmd_sta_hs2_associate); |
| 9125 | sigma_dut_reg_cmd("sta_add_credential", req_intf, |
| 9126 | cmd_sta_add_credential); |
| 9127 | sigma_dut_reg_cmd("sta_scan", req_intf, cmd_sta_scan); |
| 9128 | sigma_dut_reg_cmd("sta_set_systime", NULL, cmd_sta_set_systime); |
| 9129 | sigma_dut_reg_cmd("sta_osu", req_intf, cmd_sta_osu); |
| 9130 | sigma_dut_reg_cmd("sta_policy_update", req_intf, cmd_sta_policy_update); |
| 9131 | sigma_dut_reg_cmd("sta_er_config", NULL, cmd_sta_er_config); |
| 9132 | sigma_dut_reg_cmd("sta_wps_connect_pw_token", req_intf, |
| 9133 | cmd_sta_wps_connect_pw_token); |
| 9134 | sigma_dut_reg_cmd("sta_exec_action", req_intf, cmd_sta_exec_action); |
| 9135 | sigma_dut_reg_cmd("sta_get_events", req_intf, cmd_sta_get_events); |
| 9136 | 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] | 9137 | sigma_dut_reg_cmd("start_wps_registration", req_intf, |
| 9138 | cmd_start_wps_registration); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 9139 | } |