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> |
Jouni Malinen | 8290520 | 2018-04-29 17:20:10 +0300 | [diff] [blame] | 13 | #include <sys/wait.h> |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 14 | #ifdef __linux__ |
Lior David | cc88b56 | 2017-01-03 18:52:09 +0200 | [diff] [blame] | 15 | #include <regex.h> |
| 16 | #include <dirent.h> |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 17 | #include <sys/time.h> |
| 18 | #include <netpacket/packet.h> |
| 19 | #include <linux/if_ether.h> |
| 20 | #ifdef ANDROID |
| 21 | #include <cutils/properties.h> |
| 22 | #include <android/log.h> |
| 23 | #include "keystore_get.h" |
| 24 | #else /* ANDROID */ |
| 25 | #include <ifaddrs.h> |
| 26 | #endif /* ANDROID */ |
| 27 | #include <netdb.h> |
| 28 | #endif /* __linux__ */ |
| 29 | #ifdef __QNXNTO__ |
| 30 | #include <net/if_dl.h> |
| 31 | #endif /* __QNXNTO__ */ |
| 32 | #include "wpa_ctrl.h" |
| 33 | #include "wpa_helpers.h" |
Amarnath Hullur Subramanyam | 9c381f5 | 2017-03-17 00:04:41 -0700 | [diff] [blame] | 34 | #include "miracast.h" |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 35 | |
| 36 | /* Temporary files for sta_send_addba */ |
| 37 | #define VI_QOS_TMP_FILE "/tmp/vi-qos.tmp" |
| 38 | #define VI_QOS_FILE "/tmp/vi-qos.txt" |
| 39 | #define VI_QOS_REFFILE "/etc/vi-qos.txt" |
| 40 | |
| 41 | /* |
| 42 | * MTU for Ethernet need to take into account 8-byte SNAP header |
| 43 | * to be added when encapsulating Ethernet frame into 802.11 |
| 44 | */ |
| 45 | #ifndef IEEE80211_MAX_DATA_LEN_DMG |
| 46 | #define IEEE80211_MAX_DATA_LEN_DMG 7920 |
| 47 | #endif |
| 48 | #ifndef IEEE80211_SNAP_LEN_DMG |
| 49 | #define IEEE80211_SNAP_LEN_DMG 8 |
| 50 | #endif |
| 51 | |
Ashwini Patil | 0040258 | 2017-04-13 12:29:39 +0530 | [diff] [blame] | 52 | #define NON_PREF_CH_LIST_SIZE 100 |
Ashwini Patil | 5acd738 | 2017-04-13 15:55:04 +0530 | [diff] [blame] | 53 | #define NEIGHBOR_REPORT_SIZE 1000 |
| 54 | #define DEFAULT_NEIGHBOR_BSSID_INFO "17" |
| 55 | #define DEFAULT_NEIGHBOR_PHY_TYPE "1" |
Ashwini Patil | 0040258 | 2017-04-13 12:29:39 +0530 | [diff] [blame] | 56 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 57 | extern char *sigma_wpas_ctrl; |
| 58 | extern char *sigma_cert_path; |
| 59 | extern enum driver_type wifi_chip_type; |
| 60 | extern char *sigma_radio_ifname[]; |
| 61 | |
Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 62 | #ifdef __linux__ |
| 63 | #define WIL_WMI_MAX_PAYLOAD 248 |
| 64 | #define WIL_WMI_BF_TRIG_CMDID 0x83a |
| 65 | |
| 66 | struct wil_wmi_header { |
| 67 | uint8_t mid; |
| 68 | uint8_t reserved; |
| 69 | uint16_t cmd; |
| 70 | uint32_t ts; |
| 71 | } __attribute__((packed)); |
| 72 | |
| 73 | enum wil_wmi_bf_trig_type { |
| 74 | WIL_WMI_SLS, |
| 75 | WIL_WMI_BRP_RX, |
| 76 | WIL_WMI_BRP_TX, |
| 77 | }; |
| 78 | |
| 79 | struct wil_wmi_bf_trig_cmd { |
| 80 | /* enum wil_wmi_bf_trig_type */ |
| 81 | uint32_t bf_type; |
| 82 | /* cid when type == WMI_BRP_RX */ |
| 83 | uint32_t sta_id; |
| 84 | uint32_t reserved; |
| 85 | /* mac address when type = WIL_WMI_SLS */ |
| 86 | uint8_t dest_mac[6]; |
| 87 | } __attribute__((packed)); |
| 88 | #endif /* __linux__ */ |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 89 | |
| 90 | #ifdef ANDROID |
| 91 | |
| 92 | static int add_ipv6_rule(struct sigma_dut *dut, const char *ifname); |
| 93 | |
| 94 | #define ANDROID_KEYSTORE_GET 'g' |
| 95 | #define ANDROID_KEYSTORE_GET_PUBKEY 'b' |
| 96 | |
| 97 | static int android_keystore_get(char cmd, const char *key, unsigned char *val) |
| 98 | { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 99 | /* Android 4.3 changed keystore design, so need to use keystore_get() */ |
| 100 | #ifndef KEYSTORE_MESSAGE_SIZE |
| 101 | #define KEYSTORE_MESSAGE_SIZE 65535 |
| 102 | #endif /* KEYSTORE_MESSAGE_SIZE */ |
| 103 | |
| 104 | ssize_t len; |
| 105 | uint8_t *value = NULL; |
| 106 | |
| 107 | __android_log_print(ANDROID_LOG_DEBUG, "sigma_dut", |
| 108 | "keystore command '%c' key '%s' --> keystore_get", |
| 109 | cmd, key); |
| 110 | |
| 111 | len = keystore_get(key, strlen(key), &value); |
| 112 | if (len < 0) { |
| 113 | __android_log_print(ANDROID_LOG_DEBUG, "sigma_dut", |
| 114 | "keystore_get() failed"); |
| 115 | return -1; |
| 116 | } |
| 117 | |
| 118 | if (len > KEYSTORE_MESSAGE_SIZE) |
| 119 | len = KEYSTORE_MESSAGE_SIZE; |
| 120 | memcpy(val, value, len); |
| 121 | free(value); |
| 122 | return len; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 123 | } |
| 124 | #endif /* ANDROID */ |
| 125 | |
| 126 | |
| 127 | int set_ps(const char *intf, struct sigma_dut *dut, int enabled) |
| 128 | { |
| 129 | #ifdef __linux__ |
| 130 | char buf[100]; |
| 131 | |
| 132 | if (wifi_chip_type == DRIVER_WCN) { |
| 133 | if (enabled) { |
| 134 | snprintf(buf, sizeof(buf), "iwpriv wlan0 dump 906"); |
Pradeep Reddy POTTETI | 625b370 | 2016-09-20 17:09:58 +0530 | [diff] [blame] | 135 | if (system(buf) != 0) |
| 136 | goto set_power_save; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 137 | } else { |
| 138 | snprintf(buf, sizeof(buf), "iwpriv wlan0 dump 905"); |
Pradeep Reddy POTTETI | 625b370 | 2016-09-20 17:09:58 +0530 | [diff] [blame] | 139 | if (system(buf) != 0) |
| 140 | goto set_power_save; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 141 | snprintf(buf, sizeof(buf), "iwpriv wlan0 dump 912"); |
Pradeep Reddy POTTETI | 625b370 | 2016-09-20 17:09:58 +0530 | [diff] [blame] | 142 | if (system(buf) != 0) |
| 143 | goto set_power_save; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | return 0; |
| 147 | } |
| 148 | |
Pradeep Reddy POTTETI | 625b370 | 2016-09-20 17:09:58 +0530 | [diff] [blame] | 149 | set_power_save: |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 150 | snprintf(buf, sizeof(buf), "./iw dev %s set power_save %s", |
| 151 | intf, enabled ? "on" : "off"); |
| 152 | if (system(buf) != 0) { |
| 153 | snprintf(buf, sizeof(buf), "iw dev %s set power_save %s", |
| 154 | intf, enabled ? "on" : "off"); |
Pradeep Reddy POTTETI | 625b370 | 2016-09-20 17:09:58 +0530 | [diff] [blame] | 155 | if (system(buf) != 0) { |
| 156 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 157 | "Failed to set power save %s", |
| 158 | enabled ? "on" : "off"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 159 | return -1; |
Pradeep Reddy POTTETI | 625b370 | 2016-09-20 17:09:58 +0530 | [diff] [blame] | 160 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | return 0; |
| 164 | #else /* __linux__ */ |
| 165 | return -1; |
| 166 | #endif /* __linux__ */ |
| 167 | } |
| 168 | |
| 169 | |
Lior David | cc88b56 | 2017-01-03 18:52:09 +0200 | [diff] [blame] | 170 | #ifdef __linux__ |
Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 171 | |
Lior David | cc88b56 | 2017-01-03 18:52:09 +0200 | [diff] [blame] | 172 | static int wil6210_get_debugfs_dir(struct sigma_dut *dut, char *path, |
| 173 | size_t len) |
| 174 | { |
| 175 | DIR *dir, *wil_dir; |
| 176 | struct dirent *entry; |
| 177 | int ret = -1; |
| 178 | const char *root_path = "/sys/kernel/debug/ieee80211"; |
| 179 | |
| 180 | dir = opendir(root_path); |
| 181 | if (!dir) |
| 182 | return -2; |
| 183 | |
| 184 | while ((entry = readdir(dir))) { |
| 185 | if (strcmp(entry->d_name, ".") == 0 || |
| 186 | strcmp(entry->d_name, "..") == 0) |
| 187 | continue; |
| 188 | |
| 189 | if (snprintf(path, len, "%s/%s/wil6210", |
| 190 | root_path, entry->d_name) >= (int) len) { |
| 191 | ret = -3; |
| 192 | break; |
| 193 | } |
| 194 | |
| 195 | wil_dir = opendir(path); |
| 196 | if (wil_dir) { |
| 197 | closedir(wil_dir); |
| 198 | ret = 0; |
| 199 | break; |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | closedir(dir); |
| 204 | return ret; |
| 205 | } |
Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 206 | |
| 207 | |
| 208 | static int wil6210_wmi_send(struct sigma_dut *dut, uint16_t command, |
| 209 | void *payload, uint16_t length) |
| 210 | { |
| 211 | struct { |
| 212 | struct wil_wmi_header hdr; |
| 213 | char payload[WIL_WMI_MAX_PAYLOAD]; |
| 214 | } __attribute__((packed)) cmd; |
| 215 | char buf[128], fname[128]; |
| 216 | size_t towrite, written; |
| 217 | FILE *f; |
| 218 | |
| 219 | if (length > WIL_WMI_MAX_PAYLOAD) { |
| 220 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 221 | "payload too large(%u, max %u)", |
| 222 | length, WIL_WMI_MAX_PAYLOAD); |
| 223 | return -1; |
| 224 | } |
| 225 | |
| 226 | memset(&cmd.hdr, 0, sizeof(cmd.hdr)); |
| 227 | cmd.hdr.cmd = command; |
| 228 | memcpy(cmd.payload, payload, length); |
| 229 | |
| 230 | if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) { |
| 231 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 232 | "failed to get wil6210 debugfs dir"); |
| 233 | return -1; |
| 234 | } |
| 235 | |
| 236 | snprintf(fname, sizeof(fname), "%s/wmi_send", buf); |
| 237 | f = fopen(fname, "wb"); |
| 238 | if (!f) { |
| 239 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 240 | "failed to open: %s", fname); |
| 241 | return -1; |
| 242 | } |
| 243 | |
| 244 | towrite = sizeof(cmd.hdr) + length; |
| 245 | written = fwrite(&cmd, 1, towrite, f); |
| 246 | fclose(f); |
| 247 | if (written != towrite) { |
| 248 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 249 | "failed to send wmi %u", command); |
| 250 | return -1; |
| 251 | } |
| 252 | |
| 253 | return 0; |
| 254 | } |
| 255 | |
| 256 | |
| 257 | static int wil6210_get_sta_info_field(struct sigma_dut *dut, const char *bssid, |
| 258 | const char *pattern, unsigned int *field) |
| 259 | { |
| 260 | char buf[128], fname[128]; |
| 261 | FILE *f; |
| 262 | regex_t re; |
| 263 | regmatch_t m[2]; |
| 264 | int rc, ret = -1; |
| 265 | |
| 266 | if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) { |
| 267 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 268 | "failed to get wil6210 debugfs dir"); |
| 269 | return -1; |
| 270 | } |
| 271 | |
| 272 | snprintf(fname, sizeof(fname), "%s/stations", buf); |
| 273 | f = fopen(fname, "r"); |
| 274 | if (!f) { |
| 275 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 276 | "failed to open: %s", fname); |
| 277 | return -1; |
| 278 | } |
| 279 | |
| 280 | if (regcomp(&re, pattern, REG_EXTENDED)) { |
| 281 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 282 | "regcomp failed: %s", pattern); |
| 283 | goto out; |
| 284 | } |
| 285 | |
| 286 | /* |
| 287 | * find the entry for the mac address |
| 288 | * line is of the form: [n] 11:22:33:44:55:66 state AID aid |
| 289 | */ |
| 290 | while (fgets(buf, sizeof(buf), f)) { |
| 291 | if (strcasestr(buf, bssid)) { |
| 292 | /* extract the field (CID/AID/state) */ |
| 293 | rc = regexec(&re, buf, 2, m, 0); |
| 294 | if (!rc && (m[1].rm_so >= 0)) { |
| 295 | buf[m[1].rm_eo] = 0; |
| 296 | *field = atoi(&buf[m[1].rm_so]); |
| 297 | ret = 0; |
| 298 | break; |
| 299 | } |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | regfree(&re); |
| 304 | if (ret) |
| 305 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 306 | "could not extract field"); |
| 307 | |
| 308 | out: |
| 309 | fclose(f); |
| 310 | |
| 311 | return ret; |
| 312 | } |
| 313 | |
| 314 | |
| 315 | static int wil6210_get_cid(struct sigma_dut *dut, const char *bssid, |
| 316 | unsigned int *cid) |
| 317 | { |
| 318 | const char *pattern = "\\[([0-9]+)\\]"; |
| 319 | |
| 320 | return wil6210_get_sta_info_field(dut, bssid, pattern, cid); |
| 321 | } |
| 322 | |
| 323 | |
| 324 | static int wil6210_send_brp_rx(struct sigma_dut *dut, const char *mac, |
| 325 | int l_rx) |
| 326 | { |
Rakesh Sunki | 556237d | 2017-03-30 14:49:31 -0700 | [diff] [blame] | 327 | struct wil_wmi_bf_trig_cmd cmd; |
Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 328 | unsigned int cid; |
| 329 | |
Rakesh Sunki | 556237d | 2017-03-30 14:49:31 -0700 | [diff] [blame] | 330 | memset(&cmd, 0, sizeof(cmd)); |
| 331 | |
Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 332 | if (wil6210_get_cid(dut, mac, &cid)) |
| 333 | return -1; |
| 334 | |
| 335 | cmd.bf_type = WIL_WMI_BRP_RX; |
| 336 | cmd.sta_id = cid; |
| 337 | /* training length (l_rx) is ignored, FW always uses length 16 */ |
| 338 | return wil6210_wmi_send(dut, WIL_WMI_BF_TRIG_CMDID, |
| 339 | &cmd, sizeof(cmd)); |
| 340 | } |
| 341 | |
| 342 | |
| 343 | static int wil6210_send_sls(struct sigma_dut *dut, const char *mac) |
| 344 | { |
Rakesh Sunki | 556237d | 2017-03-30 14:49:31 -0700 | [diff] [blame] | 345 | struct wil_wmi_bf_trig_cmd cmd; |
| 346 | |
| 347 | memset(&cmd, 0, sizeof(cmd)); |
Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 348 | |
| 349 | if (parse_mac_address(dut, mac, (unsigned char *)&cmd.dest_mac)) |
| 350 | return -1; |
| 351 | |
| 352 | cmd.bf_type = WIL_WMI_SLS; |
| 353 | return wil6210_wmi_send(dut, WIL_WMI_BF_TRIG_CMDID, |
| 354 | &cmd, sizeof(cmd)); |
| 355 | } |
| 356 | |
Lior David | cc88b56 | 2017-01-03 18:52:09 +0200 | [diff] [blame] | 357 | #endif /* __linux__ */ |
| 358 | |
| 359 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 360 | static void static_ip_file(int proto, const char *addr, const char *mask, |
| 361 | const char *gw) |
| 362 | { |
| 363 | if (proto) { |
| 364 | FILE *f = fopen("static-ip", "w"); |
| 365 | if (f) { |
| 366 | fprintf(f, "%d %s %s %s\n", proto, addr, |
| 367 | mask ? mask : "N/A", |
| 368 | gw ? gw : "N/A"); |
| 369 | fclose(f); |
| 370 | } |
| 371 | } else { |
| 372 | unlink("static-ip"); |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | |
| 377 | static int send_neighbor_request(struct sigma_dut *dut, const char *intf, |
| 378 | const char *ssid) |
| 379 | { |
| 380 | #ifdef __linux__ |
| 381 | char buf[100]; |
| 382 | |
| 383 | snprintf(buf, sizeof(buf), "iwpriv %s neighbor %s", |
| 384 | intf, ssid); |
| 385 | sigma_dut_print(dut, DUT_MSG_INFO, "Request: %s", buf); |
| 386 | |
| 387 | if (system(buf) != 0) { |
| 388 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 389 | "iwpriv neighbor request failed"); |
| 390 | return -1; |
| 391 | } |
| 392 | |
| 393 | sigma_dut_print(dut, DUT_MSG_INFO, "iwpriv neighbor request send"); |
| 394 | |
| 395 | return 0; |
| 396 | #else /* __linux__ */ |
| 397 | return -1; |
| 398 | #endif /* __linux__ */ |
| 399 | } |
| 400 | |
| 401 | |
| 402 | 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] | 403 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 404 | { |
Ashwini Patil | 5acd738 | 2017-04-13 15:55:04 +0530 | [diff] [blame] | 405 | const char *val; |
| 406 | int reason_code = 0; |
| 407 | char buf[1024]; |
| 408 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 409 | /* |
| 410 | * In the earlier builds we used WNM_QUERY and in later |
| 411 | * builds used WNM_BSS_QUERY. |
| 412 | */ |
| 413 | |
Ashwini Patil | 5acd738 | 2017-04-13 15:55:04 +0530 | [diff] [blame] | 414 | val = get_param(cmd, "BTMQuery_Reason_Code"); |
| 415 | if (val) |
| 416 | reason_code = atoi(val); |
| 417 | |
| 418 | val = get_param(cmd, "Cand_List"); |
| 419 | if (val && atoi(val) == 1 && dut->btm_query_cand_list) { |
| 420 | snprintf(buf, sizeof(buf), "WNM_BSS_QUERY %d%s", reason_code, |
| 421 | dut->btm_query_cand_list); |
| 422 | free(dut->btm_query_cand_list); |
| 423 | dut->btm_query_cand_list = NULL; |
| 424 | } else { |
| 425 | snprintf(buf, sizeof(buf), "WNM_BSS_QUERY %d", reason_code); |
| 426 | } |
| 427 | |
| 428 | if (wpa_command(intf, buf) != 0) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 429 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 430 | "transition management query failed"); |
| 431 | return -1; |
| 432 | } |
| 433 | |
| 434 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 435 | "transition management query sent"); |
| 436 | |
| 437 | return 0; |
| 438 | } |
| 439 | |
| 440 | |
| 441 | int is_ip_addr(const char *str) |
| 442 | { |
| 443 | const char *pos = str; |
| 444 | struct in_addr addr; |
| 445 | |
| 446 | while (*pos) { |
| 447 | if (*pos != '.' && (*pos < '0' || *pos > '9')) |
| 448 | return 0; |
| 449 | pos++; |
| 450 | } |
| 451 | |
| 452 | return inet_aton(str, &addr); |
| 453 | } |
| 454 | |
| 455 | |
| 456 | int is_ipv6_addr(const char *str) |
| 457 | { |
| 458 | struct sockaddr_in6 addr; |
| 459 | |
| 460 | return inet_pton(AF_INET6, str, &(addr.sin6_addr)); |
| 461 | } |
| 462 | |
| 463 | |
| 464 | int get_ip_config(struct sigma_dut *dut, const char *ifname, char *buf, |
| 465 | size_t buf_len) |
| 466 | { |
vamsi krishna | a11d073 | 2018-05-16 12:19:48 +0530 | [diff] [blame] | 467 | char tmp[256]; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 468 | char ip[16], mask[15], dns[16], sec_dns[16]; |
| 469 | int is_dhcp = 0; |
| 470 | int s; |
| 471 | #ifdef ANDROID |
| 472 | char prop[PROPERTY_VALUE_MAX]; |
vamsi krishna | a11d073 | 2018-05-16 12:19:48 +0530 | [diff] [blame] | 473 | #else /* ANDROID */ |
| 474 | FILE *f; |
| 475 | #ifdef __linux__ |
| 476 | const char *str_ps; |
| 477 | #endif /* __linux__ */ |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 478 | #endif /* ANDROID */ |
| 479 | |
| 480 | ip[0] = '\0'; |
| 481 | mask[0] = '\0'; |
| 482 | dns[0] = '\0'; |
| 483 | sec_dns[0] = '\0'; |
| 484 | |
| 485 | s = socket(PF_INET, SOCK_DGRAM, 0); |
| 486 | if (s >= 0) { |
| 487 | struct ifreq ifr; |
| 488 | struct sockaddr_in saddr; |
| 489 | |
| 490 | memset(&ifr, 0, sizeof(ifr)); |
Peng Xu | b8fc5cc | 2017-05-10 17:27:28 -0700 | [diff] [blame] | 491 | strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 492 | if (ioctl(s, SIOCGIFADDR, &ifr) < 0) { |
| 493 | sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get " |
| 494 | "%s IP address: %s", |
| 495 | ifname, strerror(errno)); |
| 496 | } else { |
| 497 | memcpy(&saddr, &ifr.ifr_addr, |
| 498 | sizeof(struct sockaddr_in)); |
Peng Xu | b8fc5cc | 2017-05-10 17:27:28 -0700 | [diff] [blame] | 499 | strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip)); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | if (ioctl(s, SIOCGIFNETMASK, &ifr) == 0) { |
| 503 | memcpy(&saddr, &ifr.ifr_addr, |
| 504 | sizeof(struct sockaddr_in)); |
Peng Xu | b8fc5cc | 2017-05-10 17:27:28 -0700 | [diff] [blame] | 505 | strlcpy(mask, inet_ntoa(saddr.sin_addr), sizeof(mask)); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 506 | } |
| 507 | close(s); |
| 508 | } |
| 509 | |
| 510 | #ifdef ANDROID |
| 511 | snprintf(tmp, sizeof(tmp), "dhcp.%s.pid", ifname); |
| 512 | if (property_get(tmp, prop, NULL) != 0 && atoi(prop) > 0) { |
| 513 | snprintf(tmp, sizeof(tmp), "dhcp.%s.result", ifname); |
| 514 | if (property_get(tmp, prop, NULL) != 0 && |
| 515 | strcmp(prop, "ok") == 0) { |
| 516 | snprintf(tmp, sizeof(tmp), "dhcp.%s.ipaddress", |
| 517 | ifname); |
| 518 | if (property_get(tmp, prop, NULL) != 0 && |
| 519 | strcmp(ip, prop) == 0) |
| 520 | is_dhcp = 1; |
| 521 | } |
| 522 | } |
| 523 | |
| 524 | snprintf(tmp, sizeof(tmp), "dhcp.%s.dns1", ifname); |
Peng Xu | b8fc5cc | 2017-05-10 17:27:28 -0700 | [diff] [blame] | 525 | if (property_get(tmp, prop, NULL) != 0) |
| 526 | strlcpy(dns, prop, sizeof(dns)); |
| 527 | else if (property_get("net.dns1", prop, NULL) != 0) |
| 528 | strlcpy(dns, prop, sizeof(dns)); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 529 | |
| 530 | snprintf(tmp, sizeof(tmp), "dhcp.%s.dns2", ifname); |
Peng Xu | b8fc5cc | 2017-05-10 17:27:28 -0700 | [diff] [blame] | 531 | if (property_get(tmp, prop, NULL) != 0) |
| 532 | strlcpy(sec_dns, prop, sizeof(sec_dns)); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 533 | #else /* ANDROID */ |
| 534 | #ifdef __linux__ |
Sarvepalli, Rajesh Babu | a76c644 | 2016-03-18 20:34:26 +0530 | [diff] [blame] | 535 | if (get_driver_type() == DRIVER_OPENWRT) |
| 536 | str_ps = "ps -w"; |
| 537 | else |
| 538 | str_ps = "ps ax"; |
| 539 | snprintf(tmp, sizeof(tmp), |
| 540 | "%s | grep dhclient | grep -v grep | grep -q %s", |
| 541 | str_ps, ifname); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 542 | if (system(tmp) == 0) |
| 543 | is_dhcp = 1; |
| 544 | else { |
Sarvepalli, Rajesh Babu | a76c644 | 2016-03-18 20:34:26 +0530 | [diff] [blame] | 545 | snprintf(tmp, sizeof(tmp), |
| 546 | "%s | grep udhcpc | grep -v grep | grep -q %s", |
| 547 | str_ps, ifname); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 548 | if (system(tmp) == 0) |
| 549 | is_dhcp = 1; |
| 550 | else { |
Sarvepalli, Rajesh Babu | a76c644 | 2016-03-18 20:34:26 +0530 | [diff] [blame] | 551 | snprintf(tmp, sizeof(tmp), |
| 552 | "%s | grep dhcpcd | grep -v grep | grep -q %s", |
| 553 | str_ps, ifname); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 554 | if (system(tmp) == 0) |
| 555 | is_dhcp = 1; |
| 556 | } |
| 557 | } |
| 558 | #endif /* __linux__ */ |
| 559 | |
| 560 | f = fopen("/etc/resolv.conf", "r"); |
| 561 | if (f) { |
vamsi krishna | a11d073 | 2018-05-16 12:19:48 +0530 | [diff] [blame] | 562 | char *pos, *pos2; |
| 563 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 564 | while (fgets(tmp, sizeof(tmp), f)) { |
| 565 | if (strncmp(tmp, "nameserver", 10) != 0) |
| 566 | continue; |
| 567 | pos = tmp + 10; |
| 568 | while (*pos == ' ' || *pos == '\t') |
| 569 | pos++; |
| 570 | pos2 = pos; |
| 571 | while (*pos2) { |
| 572 | if (*pos2 == '\n' || *pos2 == '\r') { |
| 573 | *pos2 = '\0'; |
| 574 | break; |
| 575 | } |
| 576 | pos2++; |
| 577 | } |
Peng Xu | b8fc5cc | 2017-05-10 17:27:28 -0700 | [diff] [blame] | 578 | if (!dns[0]) |
| 579 | strlcpy(dns, pos, sizeof(dns)); |
| 580 | else if (!sec_dns[0]) |
| 581 | strlcpy(sec_dns, pos, sizeof(sec_dns)); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 582 | } |
| 583 | fclose(f); |
| 584 | } |
| 585 | #endif /* ANDROID */ |
| 586 | |
| 587 | snprintf(buf, buf_len, "dhcp,%d,ip,%s,mask,%s,primary-dns,%s", |
| 588 | is_dhcp, ip, mask, dns); |
| 589 | buf[buf_len - 1] = '\0'; |
| 590 | |
| 591 | return 0; |
| 592 | } |
| 593 | |
| 594 | |
| 595 | |
| 596 | |
| 597 | int get_ipv6_config(struct sigma_dut *dut, const char *ifname, char *buf, |
| 598 | size_t buf_len) |
| 599 | { |
| 600 | #ifdef __linux__ |
| 601 | #ifdef ANDROID |
| 602 | char cmd[200], result[1000], *pos, *end; |
| 603 | FILE *f; |
| 604 | size_t len; |
| 605 | |
| 606 | snprintf(cmd, sizeof(cmd), "ip addr show dev %s scope global", ifname); |
| 607 | f = popen(cmd, "r"); |
| 608 | if (f == NULL) |
| 609 | return -1; |
| 610 | len = fread(result, 1, sizeof(result) - 1, f); |
| 611 | pclose(f); |
| 612 | if (len == 0) |
| 613 | return -1; |
| 614 | result[len] = '\0'; |
| 615 | sigma_dut_print(dut, DUT_MSG_DEBUG, "%s result: %s\n", cmd, result); |
| 616 | |
| 617 | pos = strstr(result, "inet6 "); |
| 618 | if (pos == NULL) |
| 619 | return -1; |
| 620 | pos += 6; |
| 621 | end = strchr(pos, ' '); |
| 622 | if (end) |
| 623 | *end = '\0'; |
| 624 | end = strchr(pos, '/'); |
| 625 | if (end) |
| 626 | *end = '\0'; |
| 627 | snprintf(buf, buf_len, "ip,%s", pos); |
| 628 | buf[buf_len - 1] = '\0'; |
| 629 | return 0; |
| 630 | #else /* ANDROID */ |
| 631 | struct ifaddrs *ifaddr, *ifa; |
| 632 | int res, found = 0; |
| 633 | char host[NI_MAXHOST]; |
| 634 | |
| 635 | if (getifaddrs(&ifaddr) < 0) { |
| 636 | perror("getifaddrs"); |
| 637 | return -1; |
| 638 | } |
| 639 | |
| 640 | for (ifa = ifaddr; ifa; ifa = ifa->ifa_next) { |
| 641 | if (strcasecmp(ifname, ifa->ifa_name) != 0) |
| 642 | continue; |
| 643 | if (ifa->ifa_addr == NULL || |
| 644 | ifa->ifa_addr->sa_family != AF_INET6) |
| 645 | continue; |
| 646 | |
| 647 | res = getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in6), |
| 648 | host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST); |
| 649 | if (res != 0) { |
| 650 | sigma_dut_print(dut, DUT_MSG_DEBUG, "getnameinfo: %s", |
| 651 | gai_strerror(res)); |
| 652 | continue; |
| 653 | } |
| 654 | if (strncmp(host, "fe80::", 6) == 0) |
| 655 | continue; /* skip link-local */ |
| 656 | |
| 657 | sigma_dut_print(dut, DUT_MSG_DEBUG, "ifaddr: %s", host); |
| 658 | found = 1; |
| 659 | break; |
| 660 | } |
| 661 | |
| 662 | freeifaddrs(ifaddr); |
| 663 | |
| 664 | if (found) { |
| 665 | char *pos; |
| 666 | pos = strchr(host, '%'); |
| 667 | if (pos) |
| 668 | *pos = '\0'; |
| 669 | snprintf(buf, buf_len, "ip,%s", host); |
| 670 | buf[buf_len - 1] = '\0'; |
| 671 | return 0; |
| 672 | } |
| 673 | |
| 674 | #endif /* ANDROID */ |
| 675 | #endif /* __linux__ */ |
| 676 | return -1; |
| 677 | } |
| 678 | |
| 679 | |
| 680 | static int cmd_sta_get_ip_config(struct sigma_dut *dut, |
| 681 | struct sigma_conn *conn, |
| 682 | struct sigma_cmd *cmd) |
| 683 | { |
| 684 | const char *intf = get_param(cmd, "Interface"); |
| 685 | const char *ifname; |
| 686 | char buf[200]; |
| 687 | const char *val; |
| 688 | int type = 1; |
| 689 | |
| 690 | if (intf == NULL) |
| 691 | return -1; |
| 692 | |
| 693 | if (strcmp(intf, get_main_ifname()) == 0) |
| 694 | ifname = get_station_ifname(); |
| 695 | else |
| 696 | ifname = intf; |
| 697 | |
| 698 | /* |
| 699 | * UCC may assume the IP address to be available immediately after |
| 700 | * association without trying to run sta_get_ip_config multiple times. |
| 701 | * Sigma CAPI does not specify this command as a block command that |
| 702 | * would wait for the address to become available, but to pass tests |
| 703 | * more reliably, it looks like such a wait may be needed here. |
| 704 | */ |
| 705 | if (wait_ip_addr(dut, ifname, 15) < 0) { |
| 706 | sigma_dut_print(dut, DUT_MSG_INFO, "Could not get IP address " |
| 707 | "for sta_get_ip_config"); |
| 708 | /* |
| 709 | * Try to continue anyway since many UCC tests do not really |
| 710 | * care about the return value from here.. |
| 711 | */ |
| 712 | } |
| 713 | |
| 714 | val = get_param(cmd, "Type"); |
| 715 | if (val) |
| 716 | type = atoi(val); |
| 717 | if (type == 2 || dut->last_set_ip_config_ipv6) { |
| 718 | int i; |
| 719 | |
| 720 | /* |
| 721 | * Since we do not have proper wait for IPv6 addresses, use a |
| 722 | * fixed two second delay here as a workaround for UCC script |
| 723 | * assuming IPv6 address is available when this command returns. |
| 724 | * Some scripts did not use Type,2 properly for IPv6, so include |
| 725 | * also the cases where the previous sta_set_ip_config indicated |
| 726 | * use of IPv6. |
| 727 | */ |
| 728 | sigma_dut_print(dut, DUT_MSG_INFO, "Wait up to extra ten seconds in sta_get_ip_config for IPv6 address"); |
| 729 | for (i = 0; i < 10; i++) { |
| 730 | sleep(1); |
| 731 | if (get_ipv6_config(dut, ifname, buf, sizeof(buf)) == 0) |
| 732 | { |
| 733 | sigma_dut_print(dut, DUT_MSG_INFO, "Found IPv6 address"); |
| 734 | send_resp(dut, conn, SIGMA_COMPLETE, buf); |
| 735 | #ifdef ANDROID |
| 736 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 737 | "Adding IPv6 rule on Android"); |
| 738 | add_ipv6_rule(dut, intf); |
| 739 | #endif /* ANDROID */ |
| 740 | |
| 741 | return 0; |
| 742 | } |
| 743 | } |
| 744 | } |
| 745 | if (type == 1) { |
| 746 | if (get_ip_config(dut, ifname, buf, sizeof(buf)) < 0) |
| 747 | return -2; |
| 748 | } else if (type == 2) { |
| 749 | if (get_ipv6_config(dut, ifname, buf, sizeof(buf)) < 0) |
| 750 | return -2; |
| 751 | } else { |
| 752 | send_resp(dut, conn, SIGMA_ERROR, |
| 753 | "errorCode,Unsupported address type"); |
| 754 | return 0; |
| 755 | } |
| 756 | |
| 757 | send_resp(dut, conn, SIGMA_COMPLETE, buf); |
| 758 | return 0; |
| 759 | } |
| 760 | |
| 761 | |
| 762 | static void kill_dhcp_client(struct sigma_dut *dut, const char *ifname) |
| 763 | { |
| 764 | #ifdef __linux__ |
| 765 | char buf[200]; |
| 766 | char path[128]; |
| 767 | struct stat s; |
| 768 | |
| 769 | #ifdef ANDROID |
| 770 | snprintf(path, sizeof(path), "/data/misc/dhcp/dhcpcd-%s.pid", ifname); |
| 771 | #else /* ANDROID */ |
| 772 | snprintf(path, sizeof(path), "/var/run/dhclient-%s.pid", ifname); |
| 773 | #endif /* ANDROID */ |
| 774 | if (stat(path, &s) == 0) { |
| 775 | snprintf(buf, sizeof(buf), "kill `cat %s`", path); |
| 776 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 777 | "Kill previous DHCP client: %s", buf); |
| 778 | if (system(buf) != 0) |
| 779 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 780 | "Failed to kill DHCP client"); |
| 781 | unlink(path); |
| 782 | sleep(1); |
| 783 | } else { |
| 784 | snprintf(path, sizeof(path), "/var/run/dhcpcd-%s.pid", ifname); |
| 785 | |
| 786 | if (stat(path, &s) == 0) { |
| 787 | snprintf(buf, sizeof(buf), "kill `cat %s`", path); |
| 788 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 789 | "Kill previous DHCP client: %s", buf); |
| 790 | if (system(buf) != 0) |
| 791 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 792 | "Failed to kill DHCP client"); |
| 793 | unlink(path); |
| 794 | sleep(1); |
| 795 | } |
| 796 | } |
| 797 | #endif /* __linux__ */ |
| 798 | } |
| 799 | |
| 800 | |
| 801 | static int start_dhcp_client(struct sigma_dut *dut, const char *ifname) |
| 802 | { |
| 803 | #ifdef __linux__ |
| 804 | char buf[200]; |
| 805 | |
| 806 | #ifdef ANDROID |
Purushottam Kushwaha | 46d6426 | 2016-08-23 17:57:53 +0530 | [diff] [blame] | 807 | if (access("/system/bin/dhcpcd", F_OK) != -1) { |
| 808 | snprintf(buf, sizeof(buf), |
| 809 | "/system/bin/dhcpcd -b %s", ifname); |
| 810 | } else if (access("/system/bin/dhcptool", F_OK) != -1) { |
| 811 | snprintf(buf, sizeof(buf), "/system/bin/dhcptool %s &", ifname); |
| 812 | } else { |
| 813 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 814 | "DHCP client program missing"); |
| 815 | return 0; |
| 816 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 817 | #else /* ANDROID */ |
| 818 | snprintf(buf, sizeof(buf), |
| 819 | "dhclient -nw -pf /var/run/dhclient-%s.pid %s", |
| 820 | ifname, ifname); |
| 821 | #endif /* ANDROID */ |
| 822 | sigma_dut_print(dut, DUT_MSG_INFO, "Start DHCP client: %s", buf); |
| 823 | if (system(buf) != 0) { |
| 824 | snprintf(buf, sizeof(buf), "dhcpcd -t 0 %s &", ifname); |
| 825 | if (system(buf) != 0) { |
| 826 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 827 | "Failed to start DHCP client"); |
| 828 | #ifndef ANDROID |
| 829 | return -1; |
| 830 | #endif /* ANDROID */ |
| 831 | } |
| 832 | } |
| 833 | #endif /* __linux__ */ |
| 834 | |
| 835 | return 0; |
| 836 | } |
| 837 | |
| 838 | |
| 839 | static int clear_ip_addr(struct sigma_dut *dut, const char *ifname) |
| 840 | { |
| 841 | #ifdef __linux__ |
| 842 | char buf[200]; |
| 843 | |
| 844 | snprintf(buf, sizeof(buf), "ip addr flush dev %s", ifname); |
| 845 | if (system(buf) != 0) { |
| 846 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 847 | "Failed to clear IP addresses"); |
| 848 | return -1; |
| 849 | } |
| 850 | #endif /* __linux__ */ |
| 851 | |
| 852 | return 0; |
| 853 | } |
| 854 | |
| 855 | |
| 856 | #ifdef ANDROID |
| 857 | static int add_ipv6_rule(struct sigma_dut *dut, const char *ifname) |
| 858 | { |
| 859 | char cmd[200], *result, *pos; |
| 860 | FILE *fp; |
Pradeep Reddy POTTETI | f58a1fe | 2016-10-13 17:22:03 +0530 | [diff] [blame] | 861 | int tableid; |
| 862 | size_t len, result_len = 1000; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 863 | |
| 864 | snprintf(cmd, sizeof(cmd), "ip -6 route list table all | grep %s", |
| 865 | ifname); |
| 866 | fp = popen(cmd, "r"); |
| 867 | if (fp == NULL) |
| 868 | return -1; |
| 869 | |
| 870 | result = malloc(result_len); |
Pradeep Reddy POTTETI | 673d85c | 2016-07-26 19:08:07 +0530 | [diff] [blame] | 871 | if (result == NULL) { |
| 872 | fclose(fp); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 873 | return -1; |
Pradeep Reddy POTTETI | 673d85c | 2016-07-26 19:08:07 +0530 | [diff] [blame] | 874 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 875 | |
Pradeep Reddy POTTETI | f58a1fe | 2016-10-13 17:22:03 +0530 | [diff] [blame] | 876 | len = fread(result, 1, result_len - 1, fp); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 877 | fclose(fp); |
| 878 | |
| 879 | if (len == 0) { |
| 880 | free(result); |
| 881 | return -1; |
| 882 | } |
Pradeep Reddy POTTETI | f58a1fe | 2016-10-13 17:22:03 +0530 | [diff] [blame] | 883 | result[len] = '\0'; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 884 | |
| 885 | pos = strstr(result, "table "); |
| 886 | if (pos == NULL) { |
| 887 | free(result); |
| 888 | return -1; |
| 889 | } |
| 890 | |
| 891 | pos += strlen("table "); |
| 892 | tableid = atoi(pos); |
| 893 | if (tableid != 0) { |
| 894 | if (system("ip -6 rule del prio 22000") != 0) { |
| 895 | /* ignore any error */ |
| 896 | } |
| 897 | snprintf(cmd, sizeof(cmd), |
| 898 | "ip -6 rule add from all lookup %d prio 22000", |
| 899 | tableid); |
| 900 | if (system(cmd) != 0) { |
| 901 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 902 | "Failed to run %s", cmd); |
| 903 | free(result); |
| 904 | return -1; |
| 905 | } |
| 906 | } else { |
| 907 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 908 | "No Valid Table Id found %s", pos); |
| 909 | free(result); |
| 910 | return -1; |
| 911 | } |
| 912 | free(result); |
| 913 | |
| 914 | return 0; |
| 915 | } |
| 916 | #endif /* ANDROID */ |
| 917 | |
| 918 | |
Ankita Bajaj | 1bde794 | 2018-01-09 19:15:01 +0530 | [diff] [blame] | 919 | int set_ipv4_addr(struct sigma_dut *dut, const char *ifname, |
| 920 | const char *ip, const char *mask) |
| 921 | { |
| 922 | char buf[200]; |
| 923 | |
| 924 | snprintf(buf, sizeof(buf), "ifconfig %s %s netmask %s", |
| 925 | ifname, ip, mask); |
| 926 | return system(buf) == 0; |
| 927 | } |
| 928 | |
| 929 | |
| 930 | int set_ipv4_gw(struct sigma_dut *dut, const char *gw) |
| 931 | { |
| 932 | char buf[200]; |
| 933 | |
| 934 | if (!is_ip_addr(gw)) { |
| 935 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Invalid gw addr - %s", gw); |
| 936 | return -1; |
| 937 | } |
| 938 | |
| 939 | snprintf(buf, sizeof(buf), "route add default gw %s", gw); |
| 940 | if (!dut->no_ip_addr_set && system(buf) != 0) { |
| 941 | snprintf(buf, sizeof(buf), "ip ro re default via %s", |
| 942 | gw); |
| 943 | if (system(buf) != 0) |
| 944 | return 0; |
| 945 | } |
| 946 | |
| 947 | return 1; |
| 948 | } |
| 949 | |
| 950 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 951 | static int cmd_sta_set_ip_config(struct sigma_dut *dut, |
| 952 | struct sigma_conn *conn, |
| 953 | struct sigma_cmd *cmd) |
| 954 | { |
| 955 | const char *intf = get_param(cmd, "Interface"); |
| 956 | const char *ifname; |
| 957 | char buf[200]; |
| 958 | const char *val, *ip, *mask, *gw; |
| 959 | int type = 1; |
| 960 | |
| 961 | if (intf == NULL) |
| 962 | return -1; |
| 963 | |
| 964 | if (strcmp(intf, get_main_ifname()) == 0) |
| 965 | ifname = get_station_ifname(); |
| 966 | else |
| 967 | ifname = intf; |
| 968 | |
| 969 | if (if_nametoindex(ifname) == 0) { |
| 970 | send_resp(dut, conn, SIGMA_ERROR, |
| 971 | "ErrorCode,Unknown interface"); |
| 972 | return 0; |
| 973 | } |
| 974 | |
| 975 | val = get_param(cmd, "Type"); |
| 976 | if (val) { |
| 977 | type = atoi(val); |
Ankita Bajaj | 1bde794 | 2018-01-09 19:15:01 +0530 | [diff] [blame] | 978 | if (type < 1 || type > 3) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 979 | send_resp(dut, conn, SIGMA_ERROR, |
| 980 | "ErrorCode,Unsupported address type"); |
| 981 | return 0; |
| 982 | } |
| 983 | } |
| 984 | |
| 985 | dut->last_set_ip_config_ipv6 = 0; |
| 986 | |
| 987 | val = get_param(cmd, "dhcp"); |
| 988 | if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "true") == 0)) { |
| 989 | static_ip_file(0, NULL, NULL, NULL); |
| 990 | #ifdef __linux__ |
| 991 | if (type == 2) { |
| 992 | dut->last_set_ip_config_ipv6 = 1; |
| 993 | sigma_dut_print(dut, DUT_MSG_INFO, "Using IPv6 " |
| 994 | "stateless address autoconfiguration"); |
| 995 | #ifdef ANDROID |
| 996 | /* |
| 997 | * This sleep is required as the assignment in case of |
| 998 | * Android is taking time and is done by the kernel. |
| 999 | * The subsequent ping for IPv6 is impacting HS20 test |
| 1000 | * case. |
| 1001 | */ |
| 1002 | sleep(2); |
| 1003 | add_ipv6_rule(dut, intf); |
| 1004 | #endif /* ANDROID */ |
| 1005 | /* Assume this happens by default */ |
| 1006 | return 1; |
| 1007 | } |
Ankita Bajaj | 1bde794 | 2018-01-09 19:15:01 +0530 | [diff] [blame] | 1008 | if (type != 3) { |
| 1009 | kill_dhcp_client(dut, ifname); |
| 1010 | if (start_dhcp_client(dut, ifname) < 0) |
| 1011 | return -2; |
| 1012 | } else { |
| 1013 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 1014 | "Using FILS HLP DHCPv4 Rapid Commit"); |
| 1015 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1016 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1017 | return 1; |
| 1018 | #endif /* __linux__ */ |
| 1019 | return -2; |
| 1020 | } |
| 1021 | |
| 1022 | ip = get_param(cmd, "ip"); |
Pradeep Reddy POTTETI | b18c565 | 2016-01-18 12:45:37 +0530 | [diff] [blame] | 1023 | if (!ip) { |
| 1024 | send_resp(dut, conn, SIGMA_INVALID, |
| 1025 | "ErrorCode,Missing IP address"); |
| 1026 | return 0; |
| 1027 | } |
| 1028 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1029 | mask = get_param(cmd, "mask"); |
Pradeep Reddy POTTETI | b18c565 | 2016-01-18 12:45:37 +0530 | [diff] [blame] | 1030 | if (!mask) { |
| 1031 | send_resp(dut, conn, SIGMA_INVALID, |
| 1032 | "ErrorCode,Missing subnet mask"); |
| 1033 | return 0; |
| 1034 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1035 | |
| 1036 | if (type == 2) { |
| 1037 | int net = atoi(mask); |
| 1038 | |
| 1039 | if ((net < 0 && net > 64) || !is_ipv6_addr(ip)) |
| 1040 | return -1; |
| 1041 | |
| 1042 | if (dut->no_ip_addr_set) { |
| 1043 | snprintf(buf, sizeof(buf), |
| 1044 | "sysctl net.ipv6.conf.%s.disable_ipv6=1", |
| 1045 | ifname); |
| 1046 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 1047 | if (system(buf) != 0) { |
| 1048 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 1049 | "Failed to disable IPv6 address before association"); |
| 1050 | } |
| 1051 | } else { |
| 1052 | snprintf(buf, sizeof(buf), |
| 1053 | "ip -6 addr del %s/%s dev %s", |
| 1054 | ip, mask, ifname); |
| 1055 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 1056 | if (system(buf) != 0) { |
| 1057 | /* |
| 1058 | * This command may fail if the address being |
| 1059 | * deleted does not exist. Inaction here is |
| 1060 | * intentional. |
| 1061 | */ |
| 1062 | } |
| 1063 | |
| 1064 | snprintf(buf, sizeof(buf), |
| 1065 | "ip -6 addr add %s/%s dev %s", |
| 1066 | ip, mask, ifname); |
| 1067 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 1068 | if (system(buf) != 0) { |
| 1069 | send_resp(dut, conn, SIGMA_ERROR, |
| 1070 | "ErrorCode,Failed to set IPv6 address"); |
| 1071 | return 0; |
| 1072 | } |
| 1073 | } |
| 1074 | |
| 1075 | dut->last_set_ip_config_ipv6 = 1; |
| 1076 | static_ip_file(6, ip, mask, NULL); |
| 1077 | return 1; |
| 1078 | } else if (type == 1) { |
Pradeep Reddy POTTETI | b18c565 | 2016-01-18 12:45:37 +0530 | [diff] [blame] | 1079 | if (!is_ip_addr(ip) || !is_ip_addr(mask)) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1080 | return -1; |
| 1081 | } |
| 1082 | |
| 1083 | kill_dhcp_client(dut, ifname); |
| 1084 | |
| 1085 | if (!dut->no_ip_addr_set) { |
Ankita Bajaj | 1bde794 | 2018-01-09 19:15:01 +0530 | [diff] [blame] | 1086 | if (!set_ipv4_addr(dut, ifname, ip, mask)) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1087 | send_resp(dut, conn, SIGMA_ERROR, |
| 1088 | "ErrorCode,Failed to set IP address"); |
| 1089 | return 0; |
| 1090 | } |
| 1091 | } |
| 1092 | |
| 1093 | gw = get_param(cmd, "defaultGateway"); |
| 1094 | if (gw) { |
Ankita Bajaj | 1bde794 | 2018-01-09 19:15:01 +0530 | [diff] [blame] | 1095 | if (set_ipv4_gw(dut, gw) < 1) { |
| 1096 | send_resp(dut, conn, SIGMA_ERROR, |
| 1097 | "ErrorCode,Failed to set default gateway"); |
| 1098 | return 0; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1099 | } |
| 1100 | } |
| 1101 | |
| 1102 | val = get_param(cmd, "primary-dns"); |
| 1103 | if (val) { |
| 1104 | /* TODO */ |
| 1105 | sigma_dut_print(dut, DUT_MSG_INFO, "Ignored primary-dns %s " |
| 1106 | "setting", val); |
| 1107 | } |
| 1108 | |
| 1109 | val = get_param(cmd, "secondary-dns"); |
| 1110 | if (val) { |
| 1111 | /* TODO */ |
| 1112 | sigma_dut_print(dut, DUT_MSG_INFO, "Ignored secondary-dns %s " |
| 1113 | "setting", val); |
| 1114 | } |
| 1115 | |
| 1116 | static_ip_file(4, ip, mask, gw); |
| 1117 | |
| 1118 | return 1; |
| 1119 | } |
| 1120 | |
| 1121 | |
| 1122 | static int cmd_sta_get_info(struct sigma_dut *dut, struct sigma_conn *conn, |
| 1123 | struct sigma_cmd *cmd) |
| 1124 | { |
| 1125 | /* const char *intf = get_param(cmd, "Interface"); */ |
| 1126 | /* TODO: could report more details here */ |
| 1127 | send_resp(dut, conn, SIGMA_COMPLETE, "vendor,Atheros"); |
| 1128 | return 0; |
| 1129 | } |
| 1130 | |
| 1131 | |
| 1132 | static int cmd_sta_get_mac_address(struct sigma_dut *dut, |
| 1133 | struct sigma_conn *conn, |
| 1134 | struct sigma_cmd *cmd) |
| 1135 | { |
| 1136 | /* const char *intf = get_param(cmd, "Interface"); */ |
| 1137 | char addr[20], resp[50]; |
| 1138 | |
Ankita Bajaj | 0d5825b | 2017-10-25 16:20:17 +0530 | [diff] [blame] | 1139 | if (dut->dev_role == DEVROLE_STA_CFON) |
| 1140 | return sta_cfon_get_mac_address(dut, conn, cmd); |
| 1141 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1142 | if (get_wpa_status(get_station_ifname(), "address", addr, sizeof(addr)) |
| 1143 | < 0) |
| 1144 | return -2; |
| 1145 | |
| 1146 | snprintf(resp, sizeof(resp), "mac,%s", addr); |
| 1147 | send_resp(dut, conn, SIGMA_COMPLETE, resp); |
| 1148 | return 0; |
| 1149 | } |
| 1150 | |
| 1151 | |
| 1152 | static int cmd_sta_is_connected(struct sigma_dut *dut, struct sigma_conn *conn, |
| 1153 | struct sigma_cmd *cmd) |
| 1154 | { |
| 1155 | /* const char *intf = get_param(cmd, "Interface"); */ |
| 1156 | int connected = 0; |
| 1157 | char result[32]; |
| 1158 | if (get_wpa_status(get_station_ifname(), "wpa_state", result, |
| 1159 | sizeof(result)) < 0) { |
| 1160 | sigma_dut_print(dut, DUT_MSG_INFO, "Could not get interface " |
| 1161 | "%s status", get_station_ifname()); |
| 1162 | return -2; |
| 1163 | } |
| 1164 | |
| 1165 | sigma_dut_print(dut, DUT_MSG_DEBUG, "wpa_state=%s", result); |
| 1166 | if (strncmp(result, "COMPLETED", 9) == 0) |
| 1167 | connected = 1; |
| 1168 | |
| 1169 | if (connected) |
| 1170 | send_resp(dut, conn, SIGMA_COMPLETE, "connected,1"); |
| 1171 | else |
| 1172 | send_resp(dut, conn, SIGMA_COMPLETE, "connected,0"); |
| 1173 | |
| 1174 | return 0; |
| 1175 | } |
| 1176 | |
| 1177 | |
| 1178 | static int cmd_sta_verify_ip_connection(struct sigma_dut *dut, |
| 1179 | struct sigma_conn *conn, |
| 1180 | struct sigma_cmd *cmd) |
| 1181 | { |
| 1182 | /* const char *intf = get_param(cmd, "Interface"); */ |
| 1183 | const char *dst, *timeout; |
| 1184 | int wait_time = 90; |
| 1185 | char buf[100]; |
| 1186 | int res; |
| 1187 | |
| 1188 | dst = get_param(cmd, "destination"); |
| 1189 | if (dst == NULL || !is_ip_addr(dst)) |
| 1190 | return -1; |
| 1191 | |
| 1192 | timeout = get_param(cmd, "timeout"); |
| 1193 | if (timeout) { |
| 1194 | wait_time = atoi(timeout); |
| 1195 | if (wait_time < 1) |
| 1196 | wait_time = 1; |
| 1197 | } |
| 1198 | |
| 1199 | /* TODO: force renewal of IP lease if DHCP is enabled */ |
| 1200 | |
| 1201 | snprintf(buf, sizeof(buf), "ping %s -c 3 -W %d", dst, wait_time); |
| 1202 | res = system(buf); |
| 1203 | sigma_dut_print(dut, DUT_MSG_DEBUG, "ping returned: %d", res); |
| 1204 | if (res == 0) |
| 1205 | send_resp(dut, conn, SIGMA_COMPLETE, "connected,1"); |
| 1206 | else if (res == 256) |
| 1207 | send_resp(dut, conn, SIGMA_COMPLETE, "connected,0"); |
| 1208 | else |
| 1209 | return -2; |
| 1210 | |
| 1211 | return 0; |
| 1212 | } |
| 1213 | |
| 1214 | |
| 1215 | static int cmd_sta_get_bssid(struct sigma_dut *dut, struct sigma_conn *conn, |
| 1216 | struct sigma_cmd *cmd) |
| 1217 | { |
| 1218 | /* const char *intf = get_param(cmd, "Interface"); */ |
| 1219 | char bssid[20], resp[50]; |
| 1220 | |
| 1221 | if (get_wpa_status(get_station_ifname(), "bssid", bssid, sizeof(bssid)) |
| 1222 | < 0) |
Peng Xu | b8fc5cc | 2017-05-10 17:27:28 -0700 | [diff] [blame] | 1223 | strlcpy(bssid, "00:00:00:00:00:00", sizeof(bssid)); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1224 | |
| 1225 | snprintf(resp, sizeof(resp), "bssid,%s", bssid); |
| 1226 | send_resp(dut, conn, SIGMA_COMPLETE, resp); |
| 1227 | return 0; |
| 1228 | } |
| 1229 | |
| 1230 | |
| 1231 | #ifdef __SAMSUNG__ |
| 1232 | static int add_use_network(const char *ifname) |
| 1233 | { |
| 1234 | char buf[100]; |
| 1235 | |
| 1236 | snprintf(buf, sizeof(buf), "USE_NETWORK ON"); |
| 1237 | wpa_command(ifname, buf); |
| 1238 | return 0; |
| 1239 | } |
| 1240 | #endif /* __SAMSUNG__ */ |
| 1241 | |
| 1242 | |
| 1243 | static int add_network_common(struct sigma_dut *dut, struct sigma_conn *conn, |
| 1244 | const char *ifname, struct sigma_cmd *cmd) |
| 1245 | { |
| 1246 | const char *ssid = get_param(cmd, "ssid"); |
| 1247 | int id; |
| 1248 | const char *val; |
| 1249 | |
| 1250 | if (ssid == NULL) |
| 1251 | return -1; |
| 1252 | |
| 1253 | start_sta_mode(dut); |
| 1254 | |
| 1255 | #ifdef __SAMSUNG__ |
| 1256 | add_use_network(ifname); |
| 1257 | #endif /* __SAMSUNG__ */ |
| 1258 | |
| 1259 | id = add_network(ifname); |
| 1260 | if (id < 0) |
| 1261 | return -2; |
| 1262 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding network %d", id); |
| 1263 | |
| 1264 | if (set_network_quoted(ifname, id, "ssid", ssid) < 0) |
| 1265 | return -2; |
| 1266 | |
| 1267 | dut->infra_network_id = id; |
| 1268 | snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid); |
| 1269 | |
| 1270 | val = get_param(cmd, "program"); |
| 1271 | if (!val) |
| 1272 | val = get_param(cmd, "prog"); |
| 1273 | if (val && strcasecmp(val, "hs2") == 0) { |
| 1274 | char buf[100]; |
| 1275 | snprintf(buf, sizeof(buf), "ENABLE_NETWORK %d no-connect", id); |
| 1276 | wpa_command(ifname, buf); |
| 1277 | |
| 1278 | val = get_param(cmd, "prefer"); |
| 1279 | if (val && atoi(val) > 0) |
| 1280 | set_network(ifname, id, "priority", "1"); |
| 1281 | } |
| 1282 | |
| 1283 | return id; |
| 1284 | } |
| 1285 | |
| 1286 | |
| 1287 | static int cmd_sta_set_encryption(struct sigma_dut *dut, |
| 1288 | struct sigma_conn *conn, |
| 1289 | struct sigma_cmd *cmd) |
| 1290 | { |
| 1291 | const char *intf = get_param(cmd, "Interface"); |
| 1292 | const char *ssid = get_param(cmd, "ssid"); |
| 1293 | const char *type = get_param(cmd, "encpType"); |
| 1294 | const char *ifname; |
| 1295 | char buf[200]; |
| 1296 | int id; |
| 1297 | |
| 1298 | if (intf == NULL || ssid == NULL) |
| 1299 | return -1; |
| 1300 | |
| 1301 | if (strcmp(intf, get_main_ifname()) == 0) |
| 1302 | ifname = get_station_ifname(); |
| 1303 | else |
| 1304 | ifname = intf; |
| 1305 | |
| 1306 | id = add_network_common(dut, conn, ifname, cmd); |
| 1307 | if (id < 0) |
| 1308 | return id; |
| 1309 | |
| 1310 | if (set_network(ifname, id, "key_mgmt", "NONE") < 0) |
| 1311 | return -2; |
| 1312 | |
| 1313 | if (type && strcasecmp(type, "wep") == 0) { |
| 1314 | const char *val; |
| 1315 | int i; |
| 1316 | |
| 1317 | val = get_param(cmd, "activeKey"); |
| 1318 | if (val) { |
| 1319 | int keyid; |
| 1320 | keyid = atoi(val); |
| 1321 | if (keyid < 1 || keyid > 4) |
| 1322 | return -1; |
| 1323 | snprintf(buf, sizeof(buf), "%d", keyid - 1); |
| 1324 | if (set_network(ifname, id, "wep_tx_keyidx", buf) < 0) |
| 1325 | return -2; |
| 1326 | } |
| 1327 | |
| 1328 | for (i = 0; i < 4; i++) { |
| 1329 | snprintf(buf, sizeof(buf), "key%d", i + 1); |
| 1330 | val = get_param(cmd, buf); |
| 1331 | if (val == NULL) |
| 1332 | continue; |
| 1333 | snprintf(buf, sizeof(buf), "wep_key%d", i); |
| 1334 | if (set_network(ifname, id, buf, val) < 0) |
| 1335 | return -2; |
| 1336 | } |
| 1337 | } |
| 1338 | |
| 1339 | return 1; |
| 1340 | } |
| 1341 | |
| 1342 | |
| 1343 | static int set_wpa_common(struct sigma_dut *dut, struct sigma_conn *conn, |
| 1344 | const char *ifname, struct sigma_cmd *cmd) |
| 1345 | { |
| 1346 | const char *val; |
| 1347 | int id; |
Jouni Malinen | ad395a2 | 2017-09-01 21:13:46 +0300 | [diff] [blame] | 1348 | int cipher_set = 0; |
Jouni Malinen | 47dcc95 | 2017-10-09 16:43:24 +0300 | [diff] [blame] | 1349 | int owe; |
Sunil Dutt | c75a1e6 | 2018-01-11 20:47:50 +0530 | [diff] [blame] | 1350 | int suite_b = 0; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1351 | |
| 1352 | id = add_network_common(dut, conn, ifname, cmd); |
| 1353 | if (id < 0) |
| 1354 | return id; |
| 1355 | |
Jouni Malinen | 47dcc95 | 2017-10-09 16:43:24 +0300 | [diff] [blame] | 1356 | val = get_param(cmd, "Type"); |
| 1357 | owe = val && strcasecmp(val, "OWE") == 0; |
| 1358 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1359 | val = get_param(cmd, "keyMgmtType"); |
Jouni Malinen | 47dcc95 | 2017-10-09 16:43:24 +0300 | [diff] [blame] | 1360 | if (!val && owe) |
| 1361 | val = "OWE"; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1362 | if (val == NULL) { |
| 1363 | send_resp(dut, conn, SIGMA_INVALID, "errorCode,Missing keyMgmtType"); |
| 1364 | return 0; |
| 1365 | } |
| 1366 | if (strcasecmp(val, "wpa") == 0 || |
| 1367 | strcasecmp(val, "wpa-psk") == 0) { |
| 1368 | if (set_network(ifname, id, "proto", "WPA") < 0) |
| 1369 | return -2; |
| 1370 | } else if (strcasecmp(val, "wpa2") == 0 || |
| 1371 | strcasecmp(val, "wpa2-psk") == 0 || |
| 1372 | strcasecmp(val, "wpa2-ft") == 0 || |
| 1373 | strcasecmp(val, "wpa2-sha256") == 0) { |
| 1374 | if (set_network(ifname, id, "proto", "WPA2") < 0) |
| 1375 | return -2; |
Pradeep Reddy POTTETI | 6d04b3b | 2016-11-15 14:51:26 +0530 | [diff] [blame] | 1376 | } else if (strcasecmp(val, "wpa2-wpa-psk") == 0 || |
| 1377 | strcasecmp(val, "wpa2-wpa-ent") == 0) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1378 | if (set_network(ifname, id, "proto", "WPA WPA2") < 0) |
| 1379 | return -2; |
Jouni Malinen | ad395a2 | 2017-09-01 21:13:46 +0300 | [diff] [blame] | 1380 | } else if (strcasecmp(val, "SuiteB") == 0) { |
Sunil Dutt | c75a1e6 | 2018-01-11 20:47:50 +0530 | [diff] [blame] | 1381 | suite_b = 1; |
Jouni Malinen | ad395a2 | 2017-09-01 21:13:46 +0300 | [diff] [blame] | 1382 | if (set_network(ifname, id, "proto", "WPA2") < 0) |
| 1383 | return -2; |
Jouni Malinen | 47dcc95 | 2017-10-09 16:43:24 +0300 | [diff] [blame] | 1384 | } else if (strcasecmp(val, "OWE") == 0) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1385 | } else { |
| 1386 | send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized keyMgmtType value"); |
| 1387 | return 0; |
| 1388 | } |
| 1389 | |
| 1390 | val = get_param(cmd, "encpType"); |
Jouni Malinen | ad395a2 | 2017-09-01 21:13:46 +0300 | [diff] [blame] | 1391 | if (val) { |
| 1392 | cipher_set = 1; |
| 1393 | if (strcasecmp(val, "tkip") == 0) { |
| 1394 | if (set_network(ifname, id, "pairwise", "TKIP") < 0) |
| 1395 | return -2; |
| 1396 | } else if (strcasecmp(val, "aes-ccmp") == 0) { |
| 1397 | if (set_network(ifname, id, "pairwise", "CCMP") < 0) |
| 1398 | return -2; |
| 1399 | } else if (strcasecmp(val, "aes-ccmp-tkip") == 0) { |
| 1400 | if (set_network(ifname, id, "pairwise", |
| 1401 | "CCMP TKIP") < 0) |
| 1402 | return -2; |
| 1403 | } else if (strcasecmp(val, "aes-gcmp") == 0) { |
| 1404 | if (set_network(ifname, id, "pairwise", "GCMP") < 0) |
| 1405 | return -2; |
| 1406 | if (set_network(ifname, id, "group", "GCMP") < 0) |
| 1407 | return -2; |
| 1408 | } else { |
| 1409 | send_resp(dut, conn, SIGMA_ERROR, |
| 1410 | "errorCode,Unrecognized encpType value"); |
| 1411 | return 0; |
| 1412 | } |
| 1413 | } |
| 1414 | |
| 1415 | val = get_param(cmd, "PairwiseCipher"); |
| 1416 | if (val) { |
| 1417 | cipher_set = 1; |
| 1418 | /* TODO: Support space separated list */ |
| 1419 | if (strcasecmp(val, "AES-GCMP-256") == 0) { |
| 1420 | if (set_network(ifname, id, "pairwise", "GCMP-256") < 0) |
| 1421 | return -2; |
| 1422 | } else if (strcasecmp(val, "AES-CCMP-256") == 0) { |
| 1423 | if (set_network(ifname, id, "pairwise", |
| 1424 | "CCMP-256") < 0) |
| 1425 | return -2; |
| 1426 | } else if (strcasecmp(val, "AES-GCMP-128") == 0) { |
| 1427 | if (set_network(ifname, id, "pairwise", "GCMP") < 0) |
| 1428 | return -2; |
| 1429 | } else if (strcasecmp(val, "AES-CCMP-128") == 0) { |
| 1430 | if (set_network(ifname, id, "pairwise", "CCMP") < 0) |
| 1431 | return -2; |
| 1432 | } else { |
| 1433 | send_resp(dut, conn, SIGMA_ERROR, |
| 1434 | "errorCode,Unrecognized PairwiseCipher value"); |
| 1435 | return 0; |
| 1436 | } |
| 1437 | } |
| 1438 | |
Jouni Malinen | 47dcc95 | 2017-10-09 16:43:24 +0300 | [diff] [blame] | 1439 | if (!cipher_set && !owe) { |
Jouni Malinen | ad395a2 | 2017-09-01 21:13:46 +0300 | [diff] [blame] | 1440 | send_resp(dut, conn, SIGMA_ERROR, |
| 1441 | "errorCode,Missing encpType and PairwiseCipher"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1442 | return 0; |
| 1443 | } |
Jouni Malinen | ad395a2 | 2017-09-01 21:13:46 +0300 | [diff] [blame] | 1444 | |
| 1445 | val = get_param(cmd, "GroupCipher"); |
| 1446 | if (val) { |
| 1447 | if (strcasecmp(val, "AES-GCMP-256") == 0) { |
| 1448 | if (set_network(ifname, id, "group", "GCMP-256") < 0) |
| 1449 | return -2; |
| 1450 | } else if (strcasecmp(val, "AES-CCMP-256") == 0) { |
| 1451 | if (set_network(ifname, id, "group", "CCMP-256") < 0) |
| 1452 | return -2; |
| 1453 | } else if (strcasecmp(val, "AES-GCMP-128") == 0) { |
| 1454 | if (set_network(ifname, id, "group", "GCMP") < 0) |
| 1455 | return -2; |
| 1456 | } else if (strcasecmp(val, "AES-CCMP-128") == 0) { |
| 1457 | if (set_network(ifname, id, "group", "CCMP") < 0) |
| 1458 | return -2; |
| 1459 | } else { |
| 1460 | send_resp(dut, conn, SIGMA_ERROR, |
| 1461 | "errorCode,Unrecognized GroupCipher value"); |
| 1462 | return 0; |
| 1463 | } |
| 1464 | } |
| 1465 | |
Jouni Malinen | 7b23952 | 2017-09-14 21:37:18 +0300 | [diff] [blame] | 1466 | val = get_param(cmd, "GroupMgntCipher"); |
Jouni Malinen | ad395a2 | 2017-09-01 21:13:46 +0300 | [diff] [blame] | 1467 | if (val) { |
Jouni Malinen | e8898cb | 2017-09-26 17:55:26 +0300 | [diff] [blame] | 1468 | const char *cipher; |
| 1469 | |
| 1470 | if (strcasecmp(val, "BIP-GMAC-256") == 0) { |
| 1471 | cipher = "BIP-GMAC-256"; |
| 1472 | } else if (strcasecmp(val, "BIP-CMAC-256") == 0) { |
| 1473 | cipher = "BIP-CMAC-256"; |
| 1474 | } else if (strcasecmp(val, "BIP-GMAC-128") == 0) { |
| 1475 | cipher = "BIP-GMAC-128"; |
| 1476 | } else if (strcasecmp(val, "BIP-CMAC-128") == 0) { |
| 1477 | cipher = "AES-128-CMAC"; |
| 1478 | } else { |
| 1479 | send_resp(dut, conn, SIGMA_INVALID, |
| 1480 | "errorCode,Unsupported GroupMgntCipher"); |
| 1481 | return 0; |
| 1482 | } |
| 1483 | if (set_network(ifname, id, "group_mgmt", cipher) < 0) { |
| 1484 | send_resp(dut, conn, SIGMA_INVALID, |
| 1485 | "errorCode,Failed to set GroupMgntCipher"); |
| 1486 | return 0; |
| 1487 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1488 | } |
| 1489 | |
| 1490 | dut->sta_pmf = STA_PMF_DISABLED; |
vamsi krishna | f39bc1e | 2017-08-23 17:37:53 +0530 | [diff] [blame] | 1491 | |
| 1492 | if (dut->program == PROGRAM_OCE) { |
| 1493 | dut->sta_pmf = STA_PMF_OPTIONAL; |
| 1494 | if (set_network(ifname, id, "ieee80211w", "1") < 0) |
| 1495 | return -2; |
| 1496 | } |
| 1497 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1498 | val = get_param(cmd, "PMF"); |
| 1499 | if (val) { |
| 1500 | if (strcasecmp(val, "Required") == 0 || |
| 1501 | strcasecmp(val, "Forced_Required") == 0) { |
| 1502 | dut->sta_pmf = STA_PMF_REQUIRED; |
| 1503 | if (set_network(ifname, id, "ieee80211w", "2") < 0) |
| 1504 | return -2; |
| 1505 | } else if (strcasecmp(val, "Optional") == 0) { |
| 1506 | dut->sta_pmf = STA_PMF_OPTIONAL; |
| 1507 | if (set_network(ifname, id, "ieee80211w", "1") < 0) |
| 1508 | return -2; |
| 1509 | } else if (strcasecmp(val, "Disabled") == 0 || |
| 1510 | strcasecmp(val, "Forced_Disabled") == 0) { |
| 1511 | dut->sta_pmf = STA_PMF_DISABLED; |
| 1512 | } else { |
| 1513 | send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized PMF value"); |
| 1514 | return 0; |
| 1515 | } |
Sunil Dutt | c75a1e6 | 2018-01-11 20:47:50 +0530 | [diff] [blame] | 1516 | } else if (owe || suite_b) { |
Jouni Malinen | 1287cd7 | 2018-01-04 17:08:01 +0200 | [diff] [blame] | 1517 | dut->sta_pmf = STA_PMF_REQUIRED; |
| 1518 | if (set_network(ifname, id, "ieee80211w", "2") < 0) |
| 1519 | return -2; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1520 | } |
| 1521 | |
| 1522 | return id; |
| 1523 | } |
| 1524 | |
| 1525 | |
| 1526 | static int cmd_sta_set_psk(struct sigma_dut *dut, struct sigma_conn *conn, |
| 1527 | struct sigma_cmd *cmd) |
| 1528 | { |
| 1529 | const char *intf = get_param(cmd, "Interface"); |
Jouni Malinen | 992a81e | 2017-08-22 13:57:47 +0300 | [diff] [blame] | 1530 | const char *type = get_param(cmd, "Type"); |
Jouni Malinen | 1287cd7 | 2018-01-04 17:08:01 +0200 | [diff] [blame] | 1531 | const char *pmf = get_param(cmd, "PMF"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1532 | const char *ifname, *val, *alg; |
| 1533 | int id; |
| 1534 | |
| 1535 | if (intf == NULL) |
| 1536 | return -1; |
| 1537 | |
| 1538 | if (strcmp(intf, get_main_ifname()) == 0) |
| 1539 | ifname = get_station_ifname(); |
| 1540 | else |
| 1541 | ifname = intf; |
| 1542 | |
| 1543 | id = set_wpa_common(dut, conn, ifname, cmd); |
| 1544 | if (id < 0) |
| 1545 | return id; |
| 1546 | |
| 1547 | val = get_param(cmd, "keyMgmtType"); |
| 1548 | alg = get_param(cmd, "micAlg"); |
| 1549 | |
Jouni Malinen | 992a81e | 2017-08-22 13:57:47 +0300 | [diff] [blame] | 1550 | if (type && strcasecmp(type, "SAE") == 0) { |
| 1551 | if (val && strcasecmp(val, "wpa2-ft") == 0) { |
| 1552 | if (set_network(ifname, id, "key_mgmt", "FT-SAE") < 0) |
| 1553 | return -2; |
| 1554 | } else { |
| 1555 | if (set_network(ifname, id, "key_mgmt", "SAE") < 0) |
| 1556 | return -2; |
| 1557 | } |
| 1558 | if (wpa_command(ifname, "SET sae_groups ") != 0) { |
| 1559 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 1560 | "Failed to clear sae_groups to default"); |
| 1561 | return -2; |
| 1562 | } |
Jouni Malinen | 1287cd7 | 2018-01-04 17:08:01 +0200 | [diff] [blame] | 1563 | if (!pmf) { |
| 1564 | dut->sta_pmf = STA_PMF_REQUIRED; |
| 1565 | if (set_network(ifname, id, "ieee80211w", "2") < 0) |
| 1566 | return -2; |
| 1567 | } |
Jouni Malinen | 0ab50f4 | 2017-08-31 01:34:59 +0300 | [diff] [blame] | 1568 | } else if (type && strcasecmp(type, "PSK-SAE") == 0) { |
| 1569 | if (val && strcasecmp(val, "wpa2-ft") == 0) { |
| 1570 | if (set_network(ifname, id, "key_mgmt", |
| 1571 | "FT-SAE FT-PSK") < 0) |
| 1572 | return -2; |
| 1573 | } else { |
| 1574 | if (set_network(ifname, id, "key_mgmt", |
| 1575 | "SAE WPA-PSK") < 0) |
| 1576 | return -2; |
| 1577 | } |
| 1578 | if (wpa_command(ifname, "SET sae_groups ") != 0) { |
| 1579 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 1580 | "Failed to clear sae_groups to default"); |
| 1581 | return -2; |
| 1582 | } |
Jouni Malinen | 1287cd7 | 2018-01-04 17:08:01 +0200 | [diff] [blame] | 1583 | if (!pmf) { |
| 1584 | dut->sta_pmf = STA_PMF_OPTIONAL; |
| 1585 | if (set_network(ifname, id, "ieee80211w", "1") < 0) |
| 1586 | return -2; |
| 1587 | } |
Jouni Malinen | 992a81e | 2017-08-22 13:57:47 +0300 | [diff] [blame] | 1588 | } else if (alg && strcasecmp(alg, "SHA-256") == 0) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1589 | if (set_network(ifname, id, "key_mgmt", "WPA-PSK-SHA256") < 0) |
| 1590 | return -2; |
| 1591 | } else if (alg && strcasecmp(alg, "SHA-1") == 0) { |
| 1592 | if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0) |
| 1593 | return -2; |
Ashwini Patil | 6dbf7b0 | 2017-03-20 13:42:11 +0530 | [diff] [blame] | 1594 | } else if (val && strcasecmp(val, "wpa2-ft") == 0) { |
| 1595 | if (set_network(ifname, id, "key_mgmt", "FT-PSK") < 0) |
| 1596 | return -2; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1597 | } else if ((val && strcasecmp(val, "wpa2-sha256") == 0) || |
| 1598 | dut->sta_pmf == STA_PMF_REQUIRED) { |
| 1599 | if (set_network(ifname, id, "key_mgmt", |
| 1600 | "WPA-PSK WPA-PSK-SHA256") < 0) |
| 1601 | return -2; |
| 1602 | } else if (dut->sta_pmf == STA_PMF_OPTIONAL) { |
| 1603 | if (set_network(ifname, id, "key_mgmt", |
| 1604 | "WPA-PSK WPA-PSK-SHA256") < 0) |
| 1605 | return -2; |
| 1606 | } else { |
| 1607 | if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0) |
| 1608 | return -2; |
| 1609 | } |
| 1610 | |
| 1611 | val = get_param(cmd, "passPhrase"); |
| 1612 | if (val == NULL) |
| 1613 | return -1; |
Jouni Malinen | 2126f42 | 2017-10-11 23:24:33 +0300 | [diff] [blame] | 1614 | if (type && strcasecmp(type, "SAE") == 0) { |
| 1615 | if (set_network_quoted(ifname, id, "sae_password", val) < 0) |
| 1616 | return -2; |
| 1617 | } else { |
| 1618 | if (set_network_quoted(ifname, id, "psk", val) < 0) |
| 1619 | return -2; |
| 1620 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1621 | |
Jouni Malinen | 992a81e | 2017-08-22 13:57:47 +0300 | [diff] [blame] | 1622 | val = get_param(cmd, "ECGroupID"); |
| 1623 | if (val) { |
| 1624 | char buf[50]; |
| 1625 | |
| 1626 | snprintf(buf, sizeof(buf), "SET sae_groups %u", atoi(val)); |
| 1627 | if (wpa_command(ifname, buf) != 0) { |
| 1628 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 1629 | "Failed to clear sae_groups"); |
| 1630 | return -2; |
| 1631 | } |
| 1632 | } |
| 1633 | |
Jouni Malinen | 6814313 | 2017-09-02 02:34:08 +0300 | [diff] [blame] | 1634 | val = get_param(cmd, "InvalidSAEElement"); |
| 1635 | if (val) { |
| 1636 | free(dut->sae_commit_override); |
| 1637 | dut->sae_commit_override = strdup(val); |
| 1638 | } |
| 1639 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1640 | return 1; |
| 1641 | } |
| 1642 | |
| 1643 | |
| 1644 | 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] | 1645 | const char *ifname, int username_identity, |
| 1646 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1647 | { |
vamsi krishna | f39bc1e | 2017-08-23 17:37:53 +0530 | [diff] [blame] | 1648 | const char *val, *alg, *akm; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1649 | int id; |
| 1650 | char buf[200]; |
| 1651 | #ifdef ANDROID |
| 1652 | unsigned char kvalue[KEYSTORE_MESSAGE_SIZE]; |
| 1653 | int length; |
| 1654 | #endif /* ANDROID */ |
| 1655 | |
| 1656 | id = set_wpa_common(dut, conn, ifname, cmd); |
| 1657 | if (id < 0) |
| 1658 | return id; |
| 1659 | |
| 1660 | val = get_param(cmd, "keyMgmtType"); |
| 1661 | alg = get_param(cmd, "micAlg"); |
vamsi krishna | f39bc1e | 2017-08-23 17:37:53 +0530 | [diff] [blame] | 1662 | akm = get_param(cmd, "AKMSuiteType"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1663 | |
Jouni Malinen | ad395a2 | 2017-09-01 21:13:46 +0300 | [diff] [blame] | 1664 | if (val && strcasecmp(val, "SuiteB") == 0) { |
| 1665 | if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SUITE-B-192") < |
| 1666 | 0) |
| 1667 | return -2; |
| 1668 | } else if (alg && strcasecmp(alg, "SHA-256") == 0) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1669 | if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SHA256") < 0) |
| 1670 | return -2; |
| 1671 | } else if (alg && strcasecmp(alg, "SHA-1") == 0) { |
| 1672 | if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0) |
| 1673 | return -2; |
| 1674 | } else if (val && strcasecmp(val, "wpa2-ft") == 0) { |
| 1675 | if (set_network(ifname, id, "key_mgmt", "FT-EAP") < 0) |
| 1676 | return -2; |
| 1677 | } else if ((val && strcasecmp(val, "wpa2-sha256") == 0) || |
| 1678 | dut->sta_pmf == STA_PMF_REQUIRED) { |
| 1679 | if (set_network(ifname, id, "key_mgmt", |
| 1680 | "WPA-EAP WPA-EAP-SHA256") < 0) |
| 1681 | return -2; |
vamsi krishna | f39bc1e | 2017-08-23 17:37:53 +0530 | [diff] [blame] | 1682 | } else if (akm && atoi(akm) == 14) { |
| 1683 | if (dut->sta_pmf == STA_PMF_OPTIONAL || |
| 1684 | dut->sta_pmf == STA_PMF_REQUIRED) { |
| 1685 | if (set_network(ifname, id, "key_mgmt", |
| 1686 | "WPA-EAP-SHA256 FILS-SHA256") < 0) |
| 1687 | return -2; |
| 1688 | } else { |
| 1689 | if (set_network(ifname, id, "key_mgmt", |
| 1690 | "WPA-EAP FILS-SHA256") < 0) |
| 1691 | return -2; |
| 1692 | } |
| 1693 | |
| 1694 | if (set_network(ifname, id, "erp", "1") < 0) |
| 1695 | return -2; |
| 1696 | } else if (akm && atoi(akm) == 15) { |
| 1697 | if (dut->sta_pmf == STA_PMF_OPTIONAL || |
| 1698 | dut->sta_pmf == STA_PMF_REQUIRED) { |
| 1699 | if (set_network(ifname, id, "key_mgmt", |
| 1700 | "WPA-EAP-SHA256 FILS-SHA384") < 0) |
| 1701 | return -2; |
| 1702 | } else { |
| 1703 | if (set_network(ifname, id, "key_mgmt", |
| 1704 | "WPA-EAP FILS-SHA384") < 0) |
| 1705 | return -2; |
| 1706 | } |
| 1707 | |
| 1708 | if (set_network(ifname, id, "erp", "1") < 0) |
| 1709 | return -2; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1710 | } else if (dut->sta_pmf == STA_PMF_OPTIONAL) { |
| 1711 | if (set_network(ifname, id, "key_mgmt", |
| 1712 | "WPA-EAP WPA-EAP-SHA256") < 0) |
| 1713 | return -2; |
| 1714 | } else { |
| 1715 | if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0) |
| 1716 | return -2; |
| 1717 | } |
| 1718 | |
| 1719 | val = get_param(cmd, "trustedRootCA"); |
| 1720 | if (val) { |
| 1721 | #ifdef ANDROID |
| 1722 | snprintf(buf, sizeof(buf), "CACERT_%s", val); |
| 1723 | length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, |
| 1724 | kvalue); |
| 1725 | if (length > 0) { |
| 1726 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 1727 | "Use Android keystore [%s]", buf); |
| 1728 | snprintf(buf, sizeof(buf), "keystore://CACERT_%s", |
| 1729 | val); |
| 1730 | goto ca_cert_selected; |
| 1731 | } |
| 1732 | #endif /* ANDROID */ |
| 1733 | |
| 1734 | snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val); |
| 1735 | #ifdef __linux__ |
| 1736 | if (!file_exists(buf)) { |
| 1737 | char msg[300]; |
| 1738 | snprintf(msg, sizeof(msg), "ErrorCode,trustedRootCA " |
| 1739 | "file (%s) not found", buf); |
| 1740 | send_resp(dut, conn, SIGMA_ERROR, msg); |
| 1741 | return -3; |
| 1742 | } |
| 1743 | #endif /* __linux__ */ |
| 1744 | #ifdef ANDROID |
| 1745 | ca_cert_selected: |
| 1746 | #endif /* ANDROID */ |
| 1747 | if (set_network_quoted(ifname, id, "ca_cert", buf) < 0) |
| 1748 | return -2; |
| 1749 | } |
| 1750 | |
Bala Krishna Bhamidipati | 73d7af0 | 2016-03-24 12:27:56 +0530 | [diff] [blame] | 1751 | if (username_identity) { |
| 1752 | val = get_param(cmd, "username"); |
| 1753 | if (val) { |
| 1754 | if (set_network_quoted(ifname, id, "identity", val) < 0) |
| 1755 | return -2; |
| 1756 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1757 | |
Bala Krishna Bhamidipati | 73d7af0 | 2016-03-24 12:27:56 +0530 | [diff] [blame] | 1758 | val = get_param(cmd, "password"); |
| 1759 | if (val) { |
| 1760 | if (set_network_quoted(ifname, id, "password", val) < 0) |
| 1761 | return -2; |
| 1762 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1763 | } |
| 1764 | |
| 1765 | return id; |
| 1766 | } |
| 1767 | |
| 1768 | |
Jouni Malinen | 5eabb2a | 2017-10-03 18:17:30 +0300 | [diff] [blame] | 1769 | static int set_tls_cipher(const char *ifname, int id, const char *cipher) |
| 1770 | { |
| 1771 | const char *val; |
| 1772 | |
| 1773 | if (!cipher) |
| 1774 | return 0; |
| 1775 | |
| 1776 | if (strcasecmp(cipher, "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384") == 0) |
| 1777 | val = "ECDHE-ECDSA-AES256-GCM-SHA384"; |
| 1778 | else if (strcasecmp(cipher, |
| 1779 | "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384") == 0) |
| 1780 | val = "ECDHE-RSA-AES256-GCM-SHA384"; |
| 1781 | else if (strcasecmp(cipher, "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384") == 0) |
| 1782 | val = "DHE-RSA-AES256-GCM-SHA384"; |
| 1783 | else if (strcasecmp(cipher, |
| 1784 | "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256") == 0) |
| 1785 | val = "ECDHE-ECDSA-AES128-GCM-SHA256"; |
| 1786 | else |
| 1787 | return -1; |
| 1788 | |
| 1789 | /* Need to clear phase1="tls_suiteb=1" to allow cipher enforcement */ |
| 1790 | set_network_quoted(ifname, id, "phase1", ""); |
| 1791 | |
| 1792 | return set_network_quoted(ifname, id, "openssl_ciphers", val); |
| 1793 | } |
| 1794 | |
| 1795 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1796 | static int cmd_sta_set_eaptls(struct sigma_dut *dut, struct sigma_conn *conn, |
| 1797 | struct sigma_cmd *cmd) |
| 1798 | { |
| 1799 | const char *intf = get_param(cmd, "Interface"); |
| 1800 | const char *ifname, *val; |
| 1801 | int id; |
| 1802 | char buf[200]; |
| 1803 | #ifdef ANDROID |
| 1804 | unsigned char kvalue[KEYSTORE_MESSAGE_SIZE]; |
| 1805 | int length; |
| 1806 | int jb_or_newer = 0; |
| 1807 | char prop[PROPERTY_VALUE_MAX]; |
| 1808 | #endif /* ANDROID */ |
| 1809 | |
| 1810 | if (intf == NULL) |
| 1811 | return -1; |
| 1812 | |
| 1813 | if (strcmp(intf, get_main_ifname()) == 0) |
| 1814 | ifname = get_station_ifname(); |
| 1815 | else |
| 1816 | ifname = intf; |
| 1817 | |
Bala Krishna Bhamidipati | 73d7af0 | 2016-03-24 12:27:56 +0530 | [diff] [blame] | 1818 | id = set_eap_common(dut, conn, ifname, 1, cmd); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1819 | if (id < 0) |
| 1820 | return id; |
| 1821 | |
| 1822 | if (set_network(ifname, id, "eap", "TLS") < 0) |
| 1823 | return -2; |
| 1824 | |
Pradeep Reddy POTTETI | 9f6c213 | 2016-05-05 16:28:19 +0530 | [diff] [blame] | 1825 | if (!get_param(cmd, "username") && |
| 1826 | set_network_quoted(ifname, id, "identity", |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1827 | "wifi-user@wifilabs.local") < 0) |
| 1828 | return -2; |
| 1829 | |
| 1830 | val = get_param(cmd, "clientCertificate"); |
| 1831 | if (val == NULL) |
| 1832 | return -1; |
| 1833 | #ifdef ANDROID |
| 1834 | snprintf(buf, sizeof(buf), "USRPKEY_%s", val); |
| 1835 | length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue); |
| 1836 | if (length < 0) { |
| 1837 | /* |
| 1838 | * JB started reporting keystore type mismatches, so retry with |
| 1839 | * the GET_PUBKEY command if the generic GET fails. |
| 1840 | */ |
| 1841 | length = android_keystore_get(ANDROID_KEYSTORE_GET_PUBKEY, |
| 1842 | buf, kvalue); |
| 1843 | } |
| 1844 | |
| 1845 | if (property_get("ro.build.version.release", prop, NULL) != 0) { |
| 1846 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Android release %s", prop); |
| 1847 | if (strncmp(prop, "4.0", 3) != 0) |
| 1848 | jb_or_newer = 1; |
| 1849 | } else |
| 1850 | jb_or_newer = 1; /* assume newer */ |
| 1851 | |
| 1852 | if (jb_or_newer && length > 0) { |
| 1853 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 1854 | "Use Android keystore [%s]", buf); |
| 1855 | if (set_network(ifname, id, "engine", "1") < 0) |
| 1856 | return -2; |
| 1857 | if (set_network_quoted(ifname, id, "engine_id", "keystore") < 0) |
| 1858 | return -2; |
| 1859 | snprintf(buf, sizeof(buf), "USRPKEY_%s", val); |
| 1860 | if (set_network_quoted(ifname, id, "key_id", buf) < 0) |
| 1861 | return -2; |
| 1862 | snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val); |
| 1863 | if (set_network_quoted(ifname, id, "client_cert", buf) < 0) |
| 1864 | return -2; |
| 1865 | return 1; |
| 1866 | } else if (length > 0) { |
| 1867 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 1868 | "Use Android keystore [%s]", buf); |
| 1869 | snprintf(buf, sizeof(buf), "keystore://USRPKEY_%s", val); |
| 1870 | if (set_network_quoted(ifname, id, "private_key", buf) < 0) |
| 1871 | return -2; |
| 1872 | snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val); |
| 1873 | if (set_network_quoted(ifname, id, "client_cert", buf) < 0) |
| 1874 | return -2; |
| 1875 | return 1; |
| 1876 | } |
| 1877 | #endif /* ANDROID */ |
| 1878 | |
| 1879 | snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val); |
| 1880 | #ifdef __linux__ |
| 1881 | if (!file_exists(buf)) { |
| 1882 | char msg[300]; |
| 1883 | snprintf(msg, sizeof(msg), "ErrorCode,clientCertificate file " |
| 1884 | "(%s) not found", buf); |
| 1885 | send_resp(dut, conn, SIGMA_ERROR, msg); |
| 1886 | return -3; |
| 1887 | } |
| 1888 | #endif /* __linux__ */ |
| 1889 | if (set_network_quoted(ifname, id, "private_key", buf) < 0) |
| 1890 | return -2; |
| 1891 | if (set_network_quoted(ifname, id, "client_cert", buf) < 0) |
| 1892 | return -2; |
| 1893 | |
| 1894 | if (set_network_quoted(ifname, id, "private_key_passwd", "wifi") < 0) |
| 1895 | return -2; |
| 1896 | |
Jouni Malinen | 5eabb2a | 2017-10-03 18:17:30 +0300 | [diff] [blame] | 1897 | val = get_param(cmd, "keyMgmtType"); |
| 1898 | if (val && strcasecmp(val, "SuiteB") == 0) { |
| 1899 | val = get_param(cmd, "CertType"); |
| 1900 | if (val && strcasecmp(val, "RSA") == 0) { |
| 1901 | if (set_network_quoted(ifname, id, "phase1", |
| 1902 | "tls_suiteb=1") < 0) |
| 1903 | return -2; |
| 1904 | } else { |
| 1905 | if (set_network_quoted(ifname, id, "openssl_ciphers", |
| 1906 | "SUITEB192") < 0) |
| 1907 | return -2; |
| 1908 | } |
| 1909 | |
| 1910 | val = get_param(cmd, "TLSCipher"); |
| 1911 | if (set_tls_cipher(ifname, id, val) < 0) { |
| 1912 | send_resp(dut, conn, SIGMA_ERROR, |
| 1913 | "ErrorCode,Unsupported TLSCipher value"); |
| 1914 | return -3; |
| 1915 | } |
| 1916 | } |
| 1917 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1918 | return 1; |
| 1919 | } |
| 1920 | |
| 1921 | |
| 1922 | static int cmd_sta_set_eapttls(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, 1, 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", "TTLS") < 0) { |
| 1942 | send_resp(dut, conn, SIGMA_ERROR, |
| 1943 | "errorCode,Failed to set TTLS method"); |
| 1944 | return 0; |
| 1945 | } |
| 1946 | |
| 1947 | if (set_network_quoted(ifname, id, "phase2", "auth=MSCHAPV2") < 0) { |
| 1948 | send_resp(dut, conn, SIGMA_ERROR, |
| 1949 | "errorCode,Failed to set MSCHAPv2 for TTLS Phase 2"); |
| 1950 | return 0; |
| 1951 | } |
| 1952 | |
| 1953 | return 1; |
| 1954 | } |
| 1955 | |
| 1956 | |
| 1957 | static int cmd_sta_set_eapsim(struct sigma_dut *dut, struct sigma_conn *conn, |
| 1958 | struct sigma_cmd *cmd) |
| 1959 | { |
| 1960 | const char *intf = get_param(cmd, "Interface"); |
| 1961 | const char *ifname; |
| 1962 | int id; |
| 1963 | |
| 1964 | if (intf == NULL) |
| 1965 | return -1; |
| 1966 | |
| 1967 | if (strcmp(intf, get_main_ifname()) == 0) |
| 1968 | ifname = get_station_ifname(); |
| 1969 | else |
| 1970 | ifname = intf; |
| 1971 | |
Bala Krishna Bhamidipati | 73d7af0 | 2016-03-24 12:27:56 +0530 | [diff] [blame] | 1972 | id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1973 | if (id < 0) |
| 1974 | return id; |
| 1975 | |
| 1976 | if (set_network(ifname, id, "eap", "SIM") < 0) |
| 1977 | return -2; |
| 1978 | |
| 1979 | return 1; |
| 1980 | } |
| 1981 | |
| 1982 | |
| 1983 | static int cmd_sta_set_peap(struct sigma_dut *dut, struct sigma_conn *conn, |
| 1984 | struct sigma_cmd *cmd) |
| 1985 | { |
| 1986 | const char *intf = get_param(cmd, "Interface"); |
| 1987 | const char *ifname, *val; |
| 1988 | int id; |
| 1989 | char buf[100]; |
| 1990 | |
| 1991 | if (intf == NULL) |
| 1992 | return -1; |
| 1993 | |
| 1994 | if (strcmp(intf, get_main_ifname()) == 0) |
| 1995 | ifname = get_station_ifname(); |
| 1996 | else |
| 1997 | ifname = intf; |
| 1998 | |
Bala Krishna Bhamidipati | 73d7af0 | 2016-03-24 12:27:56 +0530 | [diff] [blame] | 1999 | id = set_eap_common(dut, conn, ifname, 1, cmd); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2000 | if (id < 0) |
| 2001 | return id; |
| 2002 | |
| 2003 | if (set_network(ifname, id, "eap", "PEAP") < 0) |
| 2004 | return -2; |
| 2005 | |
| 2006 | val = get_param(cmd, "innerEAP"); |
| 2007 | if (val) { |
| 2008 | if (strcasecmp(val, "MSCHAPv2") == 0) { |
| 2009 | if (set_network_quoted(ifname, id, "phase2", |
| 2010 | "auth=MSCHAPV2") < 0) |
| 2011 | return -2; |
| 2012 | } else if (strcasecmp(val, "GTC") == 0) { |
| 2013 | if (set_network_quoted(ifname, id, "phase2", |
| 2014 | "auth=GTC") < 0) |
| 2015 | return -2; |
| 2016 | } else |
| 2017 | return -1; |
| 2018 | } |
| 2019 | |
| 2020 | val = get_param(cmd, "peapVersion"); |
| 2021 | if (val) { |
| 2022 | int ver = atoi(val); |
| 2023 | if (ver < 0 || ver > 1) |
| 2024 | return -1; |
| 2025 | snprintf(buf, sizeof(buf), "peapver=%d", ver); |
| 2026 | if (set_network_quoted(ifname, id, "phase1", buf) < 0) |
| 2027 | return -2; |
| 2028 | } |
| 2029 | |
| 2030 | return 1; |
| 2031 | } |
| 2032 | |
| 2033 | |
| 2034 | static int cmd_sta_set_eapfast(struct sigma_dut *dut, struct sigma_conn *conn, |
| 2035 | struct sigma_cmd *cmd) |
| 2036 | { |
| 2037 | const char *intf = get_param(cmd, "Interface"); |
| 2038 | const char *ifname, *val; |
| 2039 | int id; |
| 2040 | char buf[100]; |
| 2041 | |
| 2042 | if (intf == NULL) |
| 2043 | return -1; |
| 2044 | |
| 2045 | if (strcmp(intf, get_main_ifname()) == 0) |
| 2046 | ifname = get_station_ifname(); |
| 2047 | else |
| 2048 | ifname = intf; |
| 2049 | |
Bala Krishna Bhamidipati | 73d7af0 | 2016-03-24 12:27:56 +0530 | [diff] [blame] | 2050 | id = set_eap_common(dut, conn, ifname, 1, cmd); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2051 | if (id < 0) |
| 2052 | return id; |
| 2053 | |
| 2054 | if (set_network(ifname, id, "eap", "FAST") < 0) |
| 2055 | return -2; |
| 2056 | |
| 2057 | val = get_param(cmd, "innerEAP"); |
| 2058 | if (val) { |
| 2059 | if (strcasecmp(val, "MSCHAPV2") == 0) { |
| 2060 | if (set_network_quoted(ifname, id, "phase2", |
| 2061 | "auth=MSCHAPV2") < 0) |
| 2062 | return -2; |
| 2063 | } else if (strcasecmp(val, "GTC") == 0) { |
| 2064 | if (set_network_quoted(ifname, id, "phase2", |
| 2065 | "auth=GTC") < 0) |
| 2066 | return -2; |
| 2067 | } else |
| 2068 | return -1; |
| 2069 | } |
| 2070 | |
| 2071 | val = get_param(cmd, "validateServer"); |
| 2072 | if (val) { |
| 2073 | /* TODO */ |
| 2074 | sigma_dut_print(dut, DUT_MSG_INFO, "Ignored EAP-FAST " |
| 2075 | "validateServer=%s", val); |
| 2076 | } |
| 2077 | |
| 2078 | val = get_param(cmd, "pacFile"); |
| 2079 | if (val) { |
| 2080 | snprintf(buf, sizeof(buf), "blob://%s", val); |
| 2081 | if (set_network_quoted(ifname, id, "pac_file", buf) < 0) |
| 2082 | return -2; |
| 2083 | } |
| 2084 | |
| 2085 | if (set_network_quoted(ifname, id, "phase1", "fast_provisioning=2") < |
| 2086 | 0) |
| 2087 | return -2; |
| 2088 | |
| 2089 | return 1; |
| 2090 | } |
| 2091 | |
| 2092 | |
| 2093 | static int cmd_sta_set_eapaka(struct sigma_dut *dut, struct sigma_conn *conn, |
| 2094 | struct sigma_cmd *cmd) |
| 2095 | { |
| 2096 | const char *intf = get_param(cmd, "Interface"); |
| 2097 | const char *ifname; |
| 2098 | int id; |
| 2099 | |
| 2100 | if (intf == NULL) |
| 2101 | return -1; |
| 2102 | |
| 2103 | if (strcmp(intf, get_main_ifname()) == 0) |
| 2104 | ifname = get_station_ifname(); |
| 2105 | else |
| 2106 | ifname = intf; |
| 2107 | |
Bala Krishna Bhamidipati | 73d7af0 | 2016-03-24 12:27:56 +0530 | [diff] [blame] | 2108 | id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2109 | if (id < 0) |
| 2110 | return id; |
| 2111 | |
| 2112 | if (set_network(ifname, id, "eap", "AKA") < 0) |
| 2113 | return -2; |
| 2114 | |
| 2115 | return 1; |
| 2116 | } |
| 2117 | |
| 2118 | |
| 2119 | static int cmd_sta_set_eapakaprime(struct sigma_dut *dut, |
| 2120 | struct sigma_conn *conn, |
| 2121 | struct sigma_cmd *cmd) |
| 2122 | { |
| 2123 | const char *intf = get_param(cmd, "Interface"); |
| 2124 | const char *ifname; |
| 2125 | int id; |
| 2126 | |
| 2127 | if (intf == NULL) |
| 2128 | return -1; |
| 2129 | |
| 2130 | if (strcmp(intf, get_main_ifname()) == 0) |
| 2131 | ifname = get_station_ifname(); |
| 2132 | else |
| 2133 | ifname = intf; |
| 2134 | |
Bala Krishna Bhamidipati | 73d7af0 | 2016-03-24 12:27:56 +0530 | [diff] [blame] | 2135 | id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2136 | if (id < 0) |
| 2137 | return id; |
| 2138 | |
| 2139 | if (set_network(ifname, id, "eap", "AKA'") < 0) |
| 2140 | return -2; |
| 2141 | |
| 2142 | return 1; |
| 2143 | } |
| 2144 | |
| 2145 | |
| 2146 | static int sta_set_open(struct sigma_dut *dut, struct sigma_conn *conn, |
| 2147 | struct sigma_cmd *cmd) |
| 2148 | { |
| 2149 | const char *intf = get_param(cmd, "Interface"); |
| 2150 | const char *ifname; |
| 2151 | int id; |
| 2152 | |
| 2153 | if (strcmp(intf, get_main_ifname()) == 0) |
| 2154 | ifname = get_station_ifname(); |
| 2155 | else |
| 2156 | ifname = intf; |
| 2157 | |
| 2158 | id = add_network_common(dut, conn, ifname, cmd); |
| 2159 | if (id < 0) |
| 2160 | return id; |
| 2161 | |
| 2162 | if (set_network(ifname, id, "key_mgmt", "NONE") < 0) |
| 2163 | return -2; |
| 2164 | |
| 2165 | return 1; |
| 2166 | } |
| 2167 | |
| 2168 | |
Jouni Malinen | 47dcc95 | 2017-10-09 16:43:24 +0300 | [diff] [blame] | 2169 | static int sta_set_owe(struct sigma_dut *dut, struct sigma_conn *conn, |
| 2170 | struct sigma_cmd *cmd) |
| 2171 | { |
| 2172 | const char *intf = get_param(cmd, "Interface"); |
| 2173 | const char *ifname, *val; |
| 2174 | int id; |
| 2175 | |
| 2176 | if (intf == NULL) |
| 2177 | return -1; |
| 2178 | |
| 2179 | if (strcmp(intf, get_main_ifname()) == 0) |
| 2180 | ifname = get_station_ifname(); |
| 2181 | else |
| 2182 | ifname = intf; |
| 2183 | |
| 2184 | id = set_wpa_common(dut, conn, ifname, cmd); |
| 2185 | if (id < 0) |
| 2186 | return id; |
| 2187 | |
| 2188 | if (set_network(ifname, id, "key_mgmt", "OWE") < 0) |
| 2189 | return -2; |
| 2190 | |
| 2191 | val = get_param(cmd, "ECGroupID"); |
Jouni Malinen | fac9cad | 2017-10-10 18:35:55 +0300 | [diff] [blame] | 2192 | if (val && strcmp(val, "0") == 0) { |
| 2193 | if (wpa_command(ifname, |
| 2194 | "VENDOR_ELEM_ADD 13 ff23200000783590fb7440e03d5b3b33911f86affdcc6b4411b707846ac4ff08ddc8831ccd") != 0) { |
| 2195 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 2196 | "Failed to set OWE DH Param element override"); |
| 2197 | return -2; |
| 2198 | } |
| 2199 | } else if (val && set_network(ifname, id, "owe_group", val) < 0) { |
Jouni Malinen | 47dcc95 | 2017-10-09 16:43:24 +0300 | [diff] [blame] | 2200 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 2201 | "Failed to clear owe_group"); |
| 2202 | return -2; |
| 2203 | } |
| 2204 | |
| 2205 | return 1; |
| 2206 | } |
| 2207 | |
| 2208 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2209 | static int cmd_sta_set_security(struct sigma_dut *dut, struct sigma_conn *conn, |
| 2210 | struct sigma_cmd *cmd) |
| 2211 | { |
| 2212 | const char *type = get_param(cmd, "Type"); |
| 2213 | |
| 2214 | if (type == NULL) { |
| 2215 | send_resp(dut, conn, SIGMA_ERROR, |
| 2216 | "ErrorCode,Missing Type argument"); |
| 2217 | return 0; |
| 2218 | } |
| 2219 | |
| 2220 | if (strcasecmp(type, "OPEN") == 0) |
| 2221 | return sta_set_open(dut, conn, cmd); |
Jouni Malinen | 47dcc95 | 2017-10-09 16:43:24 +0300 | [diff] [blame] | 2222 | if (strcasecmp(type, "OWE") == 0) |
| 2223 | return sta_set_owe(dut, conn, cmd); |
Jouni Malinen | 992a81e | 2017-08-22 13:57:47 +0300 | [diff] [blame] | 2224 | if (strcasecmp(type, "PSK") == 0 || |
Jouni Malinen | 0ab50f4 | 2017-08-31 01:34:59 +0300 | [diff] [blame] | 2225 | strcasecmp(type, "PSK-SAE") == 0 || |
Jouni Malinen | 992a81e | 2017-08-22 13:57:47 +0300 | [diff] [blame] | 2226 | strcasecmp(type, "SAE") == 0) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2227 | return cmd_sta_set_psk(dut, conn, cmd); |
| 2228 | if (strcasecmp(type, "EAPTLS") == 0) |
| 2229 | return cmd_sta_set_eaptls(dut, conn, cmd); |
| 2230 | if (strcasecmp(type, "EAPTTLS") == 0) |
| 2231 | return cmd_sta_set_eapttls(dut, conn, cmd); |
| 2232 | if (strcasecmp(type, "EAPPEAP") == 0) |
| 2233 | return cmd_sta_set_peap(dut, conn, cmd); |
| 2234 | if (strcasecmp(type, "EAPSIM") == 0) |
| 2235 | return cmd_sta_set_eapsim(dut, conn, cmd); |
| 2236 | if (strcasecmp(type, "EAPFAST") == 0) |
| 2237 | return cmd_sta_set_eapfast(dut, conn, cmd); |
| 2238 | if (strcasecmp(type, "EAPAKA") == 0) |
| 2239 | return cmd_sta_set_eapaka(dut, conn, cmd); |
| 2240 | if (strcasecmp(type, "EAPAKAPRIME") == 0) |
| 2241 | return cmd_sta_set_eapakaprime(dut, conn, cmd); |
Amarnath Hullur Subramanyam | 81b11cd | 2018-01-30 19:07:17 -0800 | [diff] [blame] | 2242 | if (strcasecmp(type, "wep") == 0) |
| 2243 | return cmd_sta_set_encryption(dut, conn, cmd); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2244 | |
| 2245 | send_resp(dut, conn, SIGMA_ERROR, |
| 2246 | "ErrorCode,Unsupported Type value"); |
| 2247 | return 0; |
| 2248 | } |
| 2249 | |
| 2250 | |
| 2251 | int ath6kl_client_uapsd(struct sigma_dut *dut, const char *intf, int uapsd) |
| 2252 | { |
| 2253 | #ifdef __linux__ |
| 2254 | /* special handling for ath6kl */ |
| 2255 | char path[128], fname[128], *pos; |
| 2256 | ssize_t res; |
| 2257 | FILE *f; |
| 2258 | |
| 2259 | snprintf(path, sizeof(path), "/sys/class/net/%s/phy80211", intf); |
| 2260 | res = readlink(path, path, sizeof(path)); |
| 2261 | if (res < 0) |
| 2262 | return 0; /* not ath6kl */ |
| 2263 | |
| 2264 | if (res >= (int) sizeof(path)) |
| 2265 | res = sizeof(path) - 1; |
| 2266 | path[res] = '\0'; |
| 2267 | pos = strrchr(path, '/'); |
| 2268 | if (pos == NULL) |
| 2269 | pos = path; |
| 2270 | else |
| 2271 | pos++; |
| 2272 | snprintf(fname, sizeof(fname), |
| 2273 | "/sys/kernel/debug/ieee80211/%s/ath6kl/" |
| 2274 | "create_qos", pos); |
| 2275 | if (!file_exists(fname)) |
| 2276 | return 0; /* not ath6kl */ |
| 2277 | |
| 2278 | if (uapsd) { |
| 2279 | f = fopen(fname, "w"); |
| 2280 | if (f == NULL) |
| 2281 | return -1; |
| 2282 | |
| 2283 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl create_qos"); |
| 2284 | fprintf(f, "4 2 2 1 2 9999999 9999999 9999999 7777777 0 4 " |
| 2285 | "45000 200 56789000 56789000 5678900 0 0 9999999 " |
| 2286 | "20000 0\n"); |
| 2287 | fclose(f); |
| 2288 | } else { |
| 2289 | snprintf(fname, sizeof(fname), |
| 2290 | "/sys/kernel/debug/ieee80211/%s/ath6kl/" |
| 2291 | "delete_qos", pos); |
| 2292 | |
| 2293 | f = fopen(fname, "w"); |
| 2294 | if (f == NULL) |
| 2295 | return -1; |
| 2296 | |
| 2297 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl delete_qos"); |
| 2298 | fprintf(f, "2 4\n"); |
| 2299 | fclose(f); |
| 2300 | } |
| 2301 | #endif /* __linux__ */ |
| 2302 | |
| 2303 | return 0; |
| 2304 | } |
| 2305 | |
| 2306 | |
| 2307 | static int cmd_sta_set_uapsd(struct sigma_dut *dut, struct sigma_conn *conn, |
| 2308 | struct sigma_cmd *cmd) |
| 2309 | { |
| 2310 | const char *intf = get_param(cmd, "Interface"); |
| 2311 | /* const char *ssid = get_param(cmd, "ssid"); */ |
| 2312 | const char *val; |
| 2313 | int max_sp_len = 4; |
| 2314 | int ac_be = 1, ac_bk = 1, ac_vi = 1, ac_vo = 1; |
| 2315 | char buf[100]; |
| 2316 | int ret1, ret2; |
| 2317 | |
| 2318 | val = get_param(cmd, "maxSPLength"); |
| 2319 | if (val) { |
| 2320 | max_sp_len = atoi(val); |
| 2321 | if (max_sp_len != 0 && max_sp_len != 1 && max_sp_len != 2 && |
| 2322 | max_sp_len != 4) |
| 2323 | return -1; |
| 2324 | } |
| 2325 | |
| 2326 | val = get_param(cmd, "acBE"); |
| 2327 | if (val) |
| 2328 | ac_be = atoi(val); |
| 2329 | |
| 2330 | val = get_param(cmd, "acBK"); |
| 2331 | if (val) |
| 2332 | ac_bk = atoi(val); |
| 2333 | |
| 2334 | val = get_param(cmd, "acVI"); |
| 2335 | if (val) |
| 2336 | ac_vi = atoi(val); |
| 2337 | |
| 2338 | val = get_param(cmd, "acVO"); |
| 2339 | if (val) |
| 2340 | ac_vo = atoi(val); |
| 2341 | |
| 2342 | dut->client_uapsd = ac_be || ac_bk || ac_vi || ac_vo; |
| 2343 | |
| 2344 | snprintf(buf, sizeof(buf), "P2P_SET client_apsd %d,%d,%d,%d;%d", |
| 2345 | ac_be, ac_bk, ac_vi, ac_vo, max_sp_len); |
| 2346 | ret1 = wpa_command(intf, buf); |
| 2347 | |
| 2348 | snprintf(buf, sizeof(buf), "SET uapsd %d,%d,%d,%d;%d", |
| 2349 | ac_be, ac_bk, ac_vi, ac_vo, max_sp_len); |
| 2350 | ret2 = wpa_command(intf, buf); |
| 2351 | |
| 2352 | if (ret1 && ret2) { |
| 2353 | sigma_dut_print(dut, DUT_MSG_INFO, "Failed to set client mode " |
| 2354 | "UAPSD parameters."); |
| 2355 | return -2; |
| 2356 | } |
| 2357 | |
| 2358 | if (ath6kl_client_uapsd(dut, intf, dut->client_uapsd) < 0) { |
| 2359 | send_resp(dut, conn, SIGMA_ERROR, |
| 2360 | "ErrorCode,Failed to set ath6kl QoS parameters"); |
| 2361 | return 0; |
| 2362 | } |
| 2363 | |
| 2364 | return 1; |
| 2365 | } |
| 2366 | |
| 2367 | |
| 2368 | static int cmd_sta_set_wmm(struct sigma_dut *dut, struct sigma_conn *conn, |
| 2369 | struct sigma_cmd *cmd) |
| 2370 | { |
| 2371 | char buf[1000]; |
| 2372 | const char *intf = get_param(cmd, "Interface"); |
| 2373 | const char *grp = get_param(cmd, "Group"); |
| 2374 | const char *act = get_param(cmd, "Action"); |
| 2375 | const char *tid = get_param(cmd, "Tid"); |
| 2376 | const char *dir = get_param(cmd, "Direction"); |
| 2377 | const char *psb = get_param(cmd, "Psb"); |
| 2378 | const char *up = get_param(cmd, "Up"); |
| 2379 | const char *fixed = get_param(cmd, "Fixed"); |
| 2380 | const char *size = get_param(cmd, "Size"); |
| 2381 | const char *msize = get_param(cmd, "Maxsize"); |
| 2382 | const char *minsi = get_param(cmd, "Min_srvc_intrvl"); |
| 2383 | const char *maxsi = get_param(cmd, "Max_srvc_intrvl"); |
| 2384 | const char *inact = get_param(cmd, "Inactivity"); |
| 2385 | const char *sus = get_param(cmd, "Suspension"); |
| 2386 | const char *mindr = get_param(cmd, "Mindatarate"); |
| 2387 | const char *meandr = get_param(cmd, "Meandatarate"); |
| 2388 | const char *peakdr = get_param(cmd, "Peakdatarate"); |
| 2389 | const char *phyrate = get_param(cmd, "Phyrate"); |
| 2390 | const char *burstsize = get_param(cmd, "Burstsize"); |
| 2391 | const char *sba = get_param(cmd, "Sba"); |
| 2392 | int direction; |
| 2393 | int handle; |
Peng Xu | 9331962 | 2017-10-04 17:58:16 -0700 | [diff] [blame] | 2394 | float sba_fv = 0; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2395 | int fixed_int; |
| 2396 | int psb_ts; |
| 2397 | |
| 2398 | if (intf == NULL || grp == NULL || act == NULL ) |
| 2399 | return -1; |
| 2400 | |
| 2401 | if (strcasecmp(act, "addts") == 0) { |
| 2402 | if (tid == NULL || dir == NULL || psb == NULL || |
| 2403 | up == NULL || fixed == NULL || size == NULL) |
| 2404 | return -1; |
| 2405 | |
| 2406 | /* |
| 2407 | * Note: Sigma CAPI spec lists uplink, downlink, and bidi as the |
| 2408 | * possible values, but WMM-AC and V-E test scripts use "UP, |
| 2409 | * "DOWN", and "BIDI". |
| 2410 | */ |
| 2411 | if (strcasecmp(dir, "uplink") == 0 || |
| 2412 | strcasecmp(dir, "up") == 0) { |
| 2413 | direction = 0; |
| 2414 | } else if (strcasecmp(dir, "downlink") == 0 || |
| 2415 | strcasecmp(dir, "down") == 0) { |
| 2416 | direction = 1; |
| 2417 | } else if (strcasecmp(dir, "bidi") == 0) { |
| 2418 | direction = 2; |
| 2419 | } else { |
| 2420 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 2421 | "Direction %s not supported", dir); |
| 2422 | return -1; |
| 2423 | } |
| 2424 | |
| 2425 | if (strcasecmp(psb, "legacy") == 0) { |
| 2426 | psb_ts = 0; |
| 2427 | } else if (strcasecmp(psb, "uapsd") == 0) { |
| 2428 | psb_ts = 1; |
| 2429 | } else { |
| 2430 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 2431 | "PSB %s not supported", psb); |
| 2432 | return -1; |
| 2433 | } |
| 2434 | |
| 2435 | if (atoi(tid) < 0 || atoi(tid) > 7) { |
| 2436 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 2437 | "TID %s not supported", tid); |
| 2438 | return -1; |
| 2439 | } |
| 2440 | |
| 2441 | if (strcasecmp(fixed, "true") == 0) { |
| 2442 | fixed_int = 1; |
| 2443 | } else { |
| 2444 | fixed_int = 0; |
| 2445 | } |
| 2446 | |
Peng Xu | 9331962 | 2017-10-04 17:58:16 -0700 | [diff] [blame] | 2447 | if (sba) |
| 2448 | sba_fv = atof(sba); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2449 | |
| 2450 | dut->dialog_token++; |
| 2451 | handle = 7000 + dut->dialog_token; |
| 2452 | |
| 2453 | /* |
| 2454 | * size: convert to hex |
| 2455 | * maxsi: convert to hex |
| 2456 | * mindr: convert to hex |
| 2457 | * meandr: convert to hex |
| 2458 | * peakdr: convert to hex |
| 2459 | * burstsize: convert to hex |
| 2460 | * phyrate: convert to hex |
| 2461 | * sba: convert to hex with modification |
| 2462 | * minsi: convert to integer |
| 2463 | * sus: convert to integer |
| 2464 | * inact: convert to integer |
| 2465 | * maxsi: convert to integer |
| 2466 | */ |
| 2467 | |
| 2468 | /* |
| 2469 | * The Nominal MSDU Size field is 2 octets long and contains an |
| 2470 | * unsigned integer that specifies the nominal size, in octets, |
| 2471 | * of MSDUs belonging to the traffic under this traffic |
| 2472 | * specification and is defined in Figure 16. If the Fixed |
| 2473 | * subfield is set to 1, then the size of the MSDU is fixed and |
| 2474 | * is indicated by the Size Subfield. If the Fixed subfield is |
| 2475 | * set to 0, then the size of the MSDU might not be fixed and |
| 2476 | * the Size indicates the nominal MSDU size. |
| 2477 | * |
| 2478 | * The Surplus Bandwidth Allowance Factor field is 2 octets long |
| 2479 | * and specifies the excess allocation of time (and bandwidth) |
| 2480 | * over and above the stated rates required to transport an MSDU |
| 2481 | * belonging to the traffic in this TSPEC. This field is |
| 2482 | * represented as an unsigned binary number with an implicit |
| 2483 | * binary point after the leftmost 3 bits. For example, an SBA |
| 2484 | * of 1.75 is represented as 0x3800. This field is included to |
| 2485 | * account for retransmissions. As such, the value of this field |
| 2486 | * must be greater than unity. |
| 2487 | */ |
| 2488 | |
| 2489 | snprintf(buf, sizeof(buf), |
| 2490 | "iwpriv %s addTspec %d %s %d %d %s 0x%X" |
| 2491 | " 0x%X 0x%X 0x%X" |
| 2492 | " 0x%X 0x%X 0x%X" |
| 2493 | " 0x%X %d %d %d %d" |
| 2494 | " %d %d", |
| 2495 | intf, handle, tid, direction, psb_ts, up, |
| 2496 | (unsigned int) ((fixed_int << 15) | atoi(size)), |
| 2497 | msize ? atoi(msize) : 0, |
| 2498 | mindr ? atoi(mindr) : 0, |
| 2499 | meandr ? atoi(meandr) : 0, |
| 2500 | peakdr ? atoi(peakdr) : 0, |
| 2501 | burstsize ? atoi(burstsize) : 0, |
| 2502 | phyrate ? atoi(phyrate) : 0, |
| 2503 | sba ? ((unsigned int) (((int) sba_fv << 13) | |
| 2504 | (int)((sba_fv - (int) sba_fv) * |
| 2505 | 8192))) : 0, |
| 2506 | minsi ? atoi(minsi) : 0, |
| 2507 | sus ? atoi(sus) : 0, |
| 2508 | 0, 0, |
| 2509 | inact ? atoi(inact) : 0, |
| 2510 | maxsi ? atoi(maxsi) : 0); |
| 2511 | |
| 2512 | if (system(buf) != 0) { |
| 2513 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 2514 | "iwpriv addtspec request failed"); |
| 2515 | send_resp(dut, conn, SIGMA_ERROR, |
| 2516 | "errorCode,Failed to execute addTspec command"); |
| 2517 | return 0; |
| 2518 | } |
| 2519 | |
| 2520 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 2521 | "iwpriv addtspec request send"); |
| 2522 | |
| 2523 | /* Mapping handle to a TID */ |
| 2524 | dut->tid_to_handle[atoi(tid)] = handle; |
| 2525 | } else if (strcasecmp(act, "delts") == 0) { |
| 2526 | if (tid == NULL) |
| 2527 | return -1; |
| 2528 | |
| 2529 | if (atoi(tid) < 0 || atoi(tid) > 7) { |
| 2530 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 2531 | "TID %s not supported", tid); |
| 2532 | send_resp(dut, conn, SIGMA_ERROR, |
| 2533 | "errorCode,Unsupported TID"); |
| 2534 | return 0; |
| 2535 | } |
| 2536 | |
| 2537 | handle = dut->tid_to_handle[atoi(tid)]; |
| 2538 | |
| 2539 | if (handle < 7000 || handle > 7255) { |
| 2540 | /* Invalid handle ie no mapping for that TID */ |
| 2541 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 2542 | "handle-> %d not found", handle); |
| 2543 | } |
| 2544 | |
| 2545 | snprintf(buf, sizeof(buf), "iwpriv %s delTspec %d", |
| 2546 | intf, handle); |
| 2547 | |
| 2548 | if (system(buf) != 0) { |
| 2549 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 2550 | "iwpriv deltspec request failed"); |
| 2551 | send_resp(dut, conn, SIGMA_ERROR, |
| 2552 | "errorCode,Failed to execute delTspec command"); |
| 2553 | return 0; |
| 2554 | } |
| 2555 | |
| 2556 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 2557 | "iwpriv deltspec request send"); |
| 2558 | |
| 2559 | dut->tid_to_handle[atoi(tid)] = 0; |
| 2560 | } else { |
| 2561 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 2562 | "Action type %s not supported", act); |
| 2563 | send_resp(dut, conn, SIGMA_ERROR, |
| 2564 | "errorCode,Unsupported Action"); |
| 2565 | return 0; |
| 2566 | } |
| 2567 | |
| 2568 | return 1; |
| 2569 | } |
| 2570 | |
| 2571 | |
vamsi krishna | 52e16f9 | 2017-08-29 12:37:34 +0530 | [diff] [blame] | 2572 | static int find_network(struct sigma_dut *dut, const char *ssid) |
| 2573 | { |
| 2574 | char list[4096]; |
| 2575 | char *pos; |
| 2576 | |
| 2577 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 2578 | "Search for profile based on SSID: '%s'", ssid); |
| 2579 | if (wpa_command_resp(get_station_ifname(), "LIST_NETWORKS", |
| 2580 | list, sizeof(list)) < 0) |
| 2581 | return -1; |
| 2582 | pos = strstr(list, ssid); |
| 2583 | if (!pos || pos == list || pos[-1] != '\t' || pos[strlen(ssid)] != '\t') |
| 2584 | return -1; |
| 2585 | |
| 2586 | while (pos > list && pos[-1] != '\n') |
| 2587 | pos--; |
| 2588 | dut->infra_network_id = atoi(pos); |
| 2589 | snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid); |
| 2590 | return 0; |
| 2591 | } |
| 2592 | |
| 2593 | |
Sunil Dutt | 4459508 | 2018-02-12 19:41:45 +0530 | [diff] [blame] | 2594 | #ifdef NL80211_SUPPORT |
| 2595 | static int sta_config_rsnie(struct sigma_dut *dut, int val) |
| 2596 | { |
| 2597 | struct nl_msg *msg; |
| 2598 | int ret; |
| 2599 | struct nlattr *params; |
| 2600 | int ifindex; |
| 2601 | |
| 2602 | ifindex = if_nametoindex("wlan0"); |
| 2603 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 2604 | NL80211_CMD_VENDOR)) || |
| 2605 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 2606 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 2607 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 2608 | QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) || |
| 2609 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 2610 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE, val)) { |
| 2611 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 2612 | "%s: err in adding vendor_cmd and vendor_data", |
| 2613 | __func__); |
| 2614 | nlmsg_free(msg); |
| 2615 | return -1; |
| 2616 | } |
| 2617 | nla_nest_end(msg, params); |
| 2618 | |
| 2619 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 2620 | if (ret) { |
| 2621 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 2622 | "%s: err in send_and_recv_msgs, ret=%d", |
| 2623 | __func__, ret); |
| 2624 | return ret; |
| 2625 | } |
| 2626 | |
| 2627 | return 0; |
| 2628 | } |
| 2629 | #endif /* NL80211_SUPPORT */ |
| 2630 | |
| 2631 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2632 | static int cmd_sta_associate(struct sigma_dut *dut, struct sigma_conn *conn, |
| 2633 | struct sigma_cmd *cmd) |
| 2634 | { |
| 2635 | /* const char *intf = get_param(cmd, "Interface"); */ |
| 2636 | const char *ssid = get_param(cmd, "ssid"); |
| 2637 | const char *wps_param = get_param(cmd, "WPS"); |
| 2638 | const char *bssid = get_param(cmd, "bssid"); |
Jouni Malinen | 46a19b6 | 2017-06-23 14:31:27 +0300 | [diff] [blame] | 2639 | const char *chan = get_param(cmd, "channel"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2640 | int wps = 0; |
Jouni Malinen | 3c367e8 | 2017-06-23 17:01:47 +0300 | [diff] [blame] | 2641 | char buf[1000], extra[50]; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2642 | |
| 2643 | if (ssid == NULL) |
| 2644 | return -1; |
| 2645 | |
Jouni Malinen | 3c367e8 | 2017-06-23 17:01:47 +0300 | [diff] [blame] | 2646 | if (dut->rsne_override) { |
Sunil Dutt | 4459508 | 2018-02-12 19:41:45 +0530 | [diff] [blame] | 2647 | #ifdef NL80211_SUPPORT |
| 2648 | if (get_driver_type() == DRIVER_WCN) { |
| 2649 | sta_config_rsnie(dut, 1); |
| 2650 | dut->config_rsnie = 1; |
| 2651 | } |
| 2652 | #endif /* NL80211_SUPPORT */ |
Jouni Malinen | 3c367e8 | 2017-06-23 17:01:47 +0300 | [diff] [blame] | 2653 | snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s", |
| 2654 | dut->rsne_override); |
| 2655 | if (wpa_command(get_station_ifname(), buf) < 0) { |
| 2656 | send_resp(dut, conn, SIGMA_ERROR, |
| 2657 | "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override"); |
| 2658 | return 0; |
| 2659 | } |
| 2660 | } |
| 2661 | |
Jouni Malinen | 6814313 | 2017-09-02 02:34:08 +0300 | [diff] [blame] | 2662 | if (dut->sae_commit_override) { |
| 2663 | snprintf(buf, sizeof(buf), "SET sae_commit_override %s", |
| 2664 | dut->sae_commit_override); |
| 2665 | if (wpa_command(get_station_ifname(), buf) < 0) { |
| 2666 | send_resp(dut, conn, SIGMA_ERROR, |
| 2667 | "ErrorCode,Failed to set SAE commit override"); |
| 2668 | return 0; |
| 2669 | } |
| 2670 | } |
Ankita Bajaj | 1bde794 | 2018-01-09 19:15:01 +0530 | [diff] [blame] | 2671 | #ifdef ANDROID |
| 2672 | if (dut->fils_hlp) |
| 2673 | process_fils_hlp(dut); |
| 2674 | #endif /* ANDROID */ |
Jouni Malinen | 6814313 | 2017-09-02 02:34:08 +0300 | [diff] [blame] | 2675 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2676 | if (wps_param && |
| 2677 | (strcmp(wps_param, "1") == 0 || strcasecmp(wps_param, "On") == 0)) |
| 2678 | wps = 1; |
| 2679 | |
| 2680 | if (wps) { |
| 2681 | if (dut->wps_method == WFA_CS_WPS_NOT_READY) { |
| 2682 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,WPS " |
| 2683 | "parameters not yet set"); |
| 2684 | return 0; |
| 2685 | } |
| 2686 | if (dut->wps_method == WFA_CS_WPS_PBC) { |
| 2687 | if (wpa_command(get_station_ifname(), "WPS_PBC") < 0) |
| 2688 | return -2; |
| 2689 | } else { |
| 2690 | snprintf(buf, sizeof(buf), "WPS_PIN any %s", |
| 2691 | dut->wps_pin); |
| 2692 | if (wpa_command(get_station_ifname(), buf) < 0) |
| 2693 | return -2; |
| 2694 | } |
| 2695 | } else { |
vamsi krishna | 52e16f9 | 2017-08-29 12:37:34 +0530 | [diff] [blame] | 2696 | if (strcmp(ssid, dut->infra_ssid) == 0) { |
| 2697 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 2698 | "sta_associate for the most recently added network"); |
| 2699 | } else if (find_network(dut, ssid) < 0) { |
| 2700 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 2701 | "sta_associate for a previously stored network profile"); |
| 2702 | send_resp(dut, conn, SIGMA_ERROR, |
| 2703 | "ErrorCode,Profile not found"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2704 | return 0; |
| 2705 | } |
| 2706 | |
| 2707 | if (bssid && |
| 2708 | set_network(get_station_ifname(), dut->infra_network_id, |
| 2709 | "bssid", bssid) < 0) { |
| 2710 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode," |
| 2711 | "Invalid bssid argument"); |
| 2712 | return 0; |
| 2713 | } |
| 2714 | |
Jouni Malinen | 46a19b6 | 2017-06-23 14:31:27 +0300 | [diff] [blame] | 2715 | extra[0] = '\0'; |
| 2716 | if (chan) |
| 2717 | snprintf(extra, sizeof(extra), " freq=%u", |
| 2718 | channel_to_freq(atoi(chan))); |
| 2719 | snprintf(buf, sizeof(buf), "SELECT_NETWORK %d%s", |
| 2720 | dut->infra_network_id, extra); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2721 | if (wpa_command(get_station_ifname(), buf) < 0) { |
| 2722 | sigma_dut_print(dut, DUT_MSG_INFO, "Failed to select " |
| 2723 | "network id %d on %s", |
| 2724 | dut->infra_network_id, |
| 2725 | get_station_ifname()); |
| 2726 | return -2; |
| 2727 | } |
| 2728 | } |
| 2729 | |
| 2730 | return 1; |
| 2731 | } |
| 2732 | |
| 2733 | |
| 2734 | static int run_hs20_osu(struct sigma_dut *dut, const char *params) |
| 2735 | { |
| 2736 | char buf[500], cmd[200]; |
| 2737 | int res; |
| 2738 | |
| 2739 | /* Use hs20-osu-client file at the current dir, if found; otherwise use |
| 2740 | * default path */ |
| 2741 | res = snprintf(cmd, sizeof(cmd), |
| 2742 | "%s -w \"%s\" -r hs20-osu-client.res %s%s -dddKt -f Logs/hs20-osu-client.txt", |
| 2743 | file_exists("./hs20-osu-client") ? |
| 2744 | "./hs20-osu-client" : "hs20-osu-client", |
| 2745 | sigma_wpas_ctrl, |
| 2746 | dut->summary_log ? "-s " : "", |
| 2747 | dut->summary_log ? dut->summary_log : ""); |
| 2748 | if (res < 0 || res >= (int) sizeof(cmd)) |
| 2749 | return -1; |
| 2750 | |
| 2751 | res = snprintf(buf, sizeof(buf), "%s %s", cmd, params); |
| 2752 | if (res < 0 || res >= (int) sizeof(buf)) |
| 2753 | return -1; |
| 2754 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 2755 | |
| 2756 | if (system(buf) != 0) { |
| 2757 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run: %s", buf); |
| 2758 | return -1; |
| 2759 | } |
| 2760 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 2761 | "Completed hs20-osu-client operation"); |
| 2762 | |
| 2763 | return 0; |
| 2764 | } |
| 2765 | |
| 2766 | |
| 2767 | static int download_ppsmo(struct sigma_dut *dut, |
| 2768 | struct sigma_conn *conn, |
| 2769 | const char *intf, |
| 2770 | struct sigma_cmd *cmd) |
| 2771 | { |
| 2772 | const char *name, *path, *val; |
| 2773 | char url[500], buf[600], fbuf[100]; |
| 2774 | char *fqdn = NULL; |
| 2775 | |
| 2776 | name = get_param(cmd, "FileName"); |
| 2777 | path = get_param(cmd, "FilePath"); |
| 2778 | if (name == NULL || path == NULL) |
| 2779 | return -1; |
| 2780 | |
| 2781 | if (strcasecmp(path, "VendorSpecific") == 0) { |
| 2782 | snprintf(url, sizeof(url), "PPS/%s", name); |
| 2783 | sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured PPS MO " |
| 2784 | "from the device (%s)", url); |
| 2785 | if (!file_exists(url)) { |
| 2786 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested " |
| 2787 | "PPS MO file does not exist"); |
| 2788 | return 0; |
| 2789 | } |
| 2790 | snprintf(buf, sizeof(buf), "cp %s pps-tnds.xml", url); |
| 2791 | if (system(buf) != 0) { |
| 2792 | send_resp(dut, conn, SIGMA_ERROR, |
| 2793 | "errorCode,Failed to copy PPS MO"); |
| 2794 | return 0; |
| 2795 | } |
| 2796 | } else if (strncasecmp(path, "http:", 5) != 0 && |
| 2797 | strncasecmp(path, "https:", 6) != 0) { |
| 2798 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode," |
| 2799 | "Unsupported FilePath value"); |
| 2800 | return 0; |
| 2801 | } else { |
| 2802 | snprintf(url, sizeof(url), "%s/%s", path, name); |
| 2803 | sigma_dut_print(dut, DUT_MSG_INFO, "Downloading PPS MO from %s", |
| 2804 | url); |
| 2805 | snprintf(buf, sizeof(buf), "wget -T 10 -t 3 -O pps-tnds.xml '%s'", url); |
| 2806 | remove("pps-tnds.xml"); |
| 2807 | if (system(buf) != 0) { |
| 2808 | send_resp(dut, conn, SIGMA_ERROR, |
| 2809 | "errorCode,Failed to download PPS MO"); |
| 2810 | return 0; |
| 2811 | } |
| 2812 | } |
| 2813 | |
| 2814 | if (run_hs20_osu(dut, "from_tnds pps-tnds.xml pps.xml") < 0) { |
| 2815 | send_resp(dut, conn, SIGMA_ERROR, |
| 2816 | "errorCode,Failed to parse downloaded PPSMO"); |
| 2817 | return 0; |
| 2818 | } |
| 2819 | unlink("pps-tnds.xml"); |
| 2820 | |
| 2821 | val = get_param(cmd, "managementTreeURI"); |
| 2822 | if (val) { |
| 2823 | const char *pos, *end; |
| 2824 | sigma_dut_print(dut, DUT_MSG_DEBUG, "managementTreeURI: %s", |
| 2825 | val); |
| 2826 | if (strncmp(val, "./Wi-Fi/", 8) != 0) { |
| 2827 | send_resp(dut, conn, SIGMA_ERROR, |
| 2828 | "errorCode,Invalid managementTreeURI prefix"); |
| 2829 | return 0; |
| 2830 | } |
| 2831 | pos = val + 8; |
| 2832 | end = strchr(pos, '/'); |
| 2833 | if (end == NULL || |
| 2834 | strcmp(end, "/PerProviderSubscription") != 0) { |
| 2835 | send_resp(dut, conn, SIGMA_ERROR, |
| 2836 | "errorCode,Invalid managementTreeURI postfix"); |
| 2837 | return 0; |
| 2838 | } |
| 2839 | if (end - pos >= (int) sizeof(fbuf)) { |
| 2840 | send_resp(dut, conn, SIGMA_ERROR, |
| 2841 | "errorCode,Too long FQDN in managementTreeURI"); |
| 2842 | return 0; |
| 2843 | } |
| 2844 | memcpy(fbuf, pos, end - pos); |
| 2845 | fbuf[end - pos] = '\0'; |
| 2846 | fqdn = fbuf; |
| 2847 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 2848 | "FQDN from managementTreeURI: %s", fqdn); |
| 2849 | } else if (run_hs20_osu(dut, "get_fqdn pps.xml") == 0) { |
| 2850 | FILE *f = fopen("pps-fqdn", "r"); |
| 2851 | if (f) { |
| 2852 | if (fgets(fbuf, sizeof(fbuf), f)) { |
| 2853 | fbuf[sizeof(fbuf) - 1] = '\0'; |
| 2854 | fqdn = fbuf; |
| 2855 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 2856 | "Use FQDN %s", fqdn); |
| 2857 | } |
| 2858 | fclose(f); |
| 2859 | } |
| 2860 | } |
| 2861 | |
| 2862 | if (fqdn == NULL) { |
| 2863 | send_resp(dut, conn, SIGMA_ERROR, |
| 2864 | "errorCode,No FQDN specified"); |
| 2865 | return 0; |
| 2866 | } |
| 2867 | |
| 2868 | mkdir("SP", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); |
| 2869 | snprintf(buf, sizeof(buf), "SP/%s", fqdn); |
| 2870 | mkdir(buf, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); |
| 2871 | |
| 2872 | snprintf(buf, sizeof(buf), "SP/%s/pps.xml", fqdn); |
| 2873 | if (rename("pps.xml", buf) < 0) { |
| 2874 | send_resp(dut, conn, SIGMA_ERROR, |
| 2875 | "errorCode,Could not move PPS MO"); |
| 2876 | return 0; |
| 2877 | } |
| 2878 | |
| 2879 | if (strcasecmp(path, "VendorSpecific") == 0) { |
| 2880 | snprintf(buf, sizeof(buf), "cp Certs/ca.pem SP/%s/ca.pem", |
| 2881 | fqdn); |
| 2882 | if (system(buf)) { |
| 2883 | send_resp(dut, conn, SIGMA_ERROR, |
| 2884 | "errorCode,Failed to copy OSU CA cert"); |
| 2885 | return 0; |
| 2886 | } |
| 2887 | |
| 2888 | snprintf(buf, sizeof(buf), |
| 2889 | "cp Certs/aaa-ca.pem SP/%s/aaa-ca.pem", |
| 2890 | fqdn); |
| 2891 | if (system(buf)) { |
| 2892 | send_resp(dut, conn, SIGMA_ERROR, |
| 2893 | "errorCode,Failed to copy AAA CA cert"); |
| 2894 | return 0; |
| 2895 | } |
| 2896 | } else { |
| 2897 | snprintf(buf, sizeof(buf), |
| 2898 | "dl_osu_ca SP/%s/pps.xml SP/%s/ca.pem", |
| 2899 | fqdn, fqdn); |
| 2900 | if (run_hs20_osu(dut, buf) < 0) { |
| 2901 | send_resp(dut, conn, SIGMA_ERROR, |
| 2902 | "errorCode,Failed to download OSU CA cert"); |
| 2903 | return 0; |
| 2904 | } |
| 2905 | |
| 2906 | snprintf(buf, sizeof(buf), |
| 2907 | "dl_aaa_ca SP/%s/pps.xml SP/%s/aaa-ca.pem", |
| 2908 | fqdn, fqdn); |
| 2909 | if (run_hs20_osu(dut, buf) < 0) { |
| 2910 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 2911 | "Failed to download AAA CA cert"); |
| 2912 | } |
| 2913 | } |
| 2914 | |
| 2915 | if (file_exists("next-client-cert.pem")) { |
| 2916 | snprintf(buf, sizeof(buf), "SP/%s/client-cert.pem", fqdn); |
| 2917 | if (rename("next-client-cert.pem", buf) < 0) { |
| 2918 | send_resp(dut, conn, SIGMA_ERROR, |
| 2919 | "errorCode,Could not move client certificate"); |
| 2920 | return 0; |
| 2921 | } |
| 2922 | } |
| 2923 | |
| 2924 | if (file_exists("next-client-key.pem")) { |
| 2925 | snprintf(buf, sizeof(buf), "SP/%s/client-key.pem", fqdn); |
| 2926 | if (rename("next-client-key.pem", buf) < 0) { |
| 2927 | send_resp(dut, conn, SIGMA_ERROR, |
| 2928 | "errorCode,Could not move client key"); |
| 2929 | return 0; |
| 2930 | } |
| 2931 | } |
| 2932 | |
| 2933 | snprintf(buf, sizeof(buf), "set_pps SP/%s/pps.xml", fqdn); |
| 2934 | if (run_hs20_osu(dut, buf) < 0) { |
| 2935 | send_resp(dut, conn, SIGMA_ERROR, |
| 2936 | "errorCode,Failed to configure credential from " |
| 2937 | "PPSMO"); |
| 2938 | return 0; |
| 2939 | } |
| 2940 | |
| 2941 | return 1; |
| 2942 | } |
| 2943 | |
| 2944 | |
| 2945 | static int download_cert(struct sigma_dut *dut, |
| 2946 | struct sigma_conn *conn, |
| 2947 | const char *intf, |
| 2948 | struct sigma_cmd *cmd) |
| 2949 | { |
| 2950 | const char *name, *path; |
| 2951 | char url[500], buf[600]; |
| 2952 | |
| 2953 | name = get_param(cmd, "FileName"); |
| 2954 | path = get_param(cmd, "FilePath"); |
| 2955 | if (name == NULL || path == NULL) |
| 2956 | return -1; |
| 2957 | |
| 2958 | if (strcasecmp(path, "VendorSpecific") == 0) { |
| 2959 | snprintf(url, sizeof(url), "Certs/%s-cert.pem", name); |
| 2960 | sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client " |
| 2961 | "certificate from the device (%s)", url); |
| 2962 | if (!file_exists(url)) { |
| 2963 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested " |
| 2964 | "certificate file does not exist"); |
| 2965 | return 0; |
| 2966 | } |
| 2967 | snprintf(buf, sizeof(buf), "cp %s next-client-cert.pem", url); |
| 2968 | if (system(buf) != 0) { |
| 2969 | send_resp(dut, conn, SIGMA_ERROR, |
| 2970 | "errorCode,Failed to copy client " |
| 2971 | "certificate"); |
| 2972 | return 0; |
| 2973 | } |
| 2974 | |
| 2975 | snprintf(url, sizeof(url), "Certs/%s-key.pem", name); |
| 2976 | sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client " |
| 2977 | "private key from the device (%s)", url); |
| 2978 | if (!file_exists(url)) { |
| 2979 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested " |
| 2980 | "private key file does not exist"); |
| 2981 | return 0; |
| 2982 | } |
| 2983 | snprintf(buf, sizeof(buf), "cp %s next-client-key.pem", url); |
| 2984 | if (system(buf) != 0) { |
| 2985 | send_resp(dut, conn, SIGMA_ERROR, |
| 2986 | "errorCode,Failed to copy client key"); |
| 2987 | return 0; |
| 2988 | } |
| 2989 | } else if (strncasecmp(path, "http:", 5) != 0 && |
| 2990 | strncasecmp(path, "https:", 6) != 0) { |
| 2991 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode," |
| 2992 | "Unsupported FilePath value"); |
| 2993 | return 0; |
| 2994 | } else { |
| 2995 | snprintf(url, sizeof(url), "%s/%s.pem", path, name); |
| 2996 | sigma_dut_print(dut, DUT_MSG_INFO, "Downloading client " |
| 2997 | "certificate/key from %s", url); |
| 2998 | snprintf(buf, sizeof(buf), |
| 2999 | "wget -T 10 -t 3 -O next-client-cert.pem '%s'", url); |
| 3000 | if (system(buf) != 0) { |
| 3001 | send_resp(dut, conn, SIGMA_ERROR, |
| 3002 | "errorCode,Failed to download client " |
| 3003 | "certificate"); |
| 3004 | return 0; |
| 3005 | } |
| 3006 | |
| 3007 | if (system("cp next-client-cert.pem next-client-key.pem") != 0) |
| 3008 | { |
| 3009 | send_resp(dut, conn, SIGMA_ERROR, |
| 3010 | "errorCode,Failed to copy client key"); |
| 3011 | return 0; |
| 3012 | } |
| 3013 | } |
| 3014 | |
| 3015 | return 1; |
| 3016 | } |
| 3017 | |
| 3018 | |
| 3019 | static int cmd_sta_preset_testparameters_hs2_r2(struct sigma_dut *dut, |
| 3020 | struct sigma_conn *conn, |
| 3021 | const char *intf, |
| 3022 | struct sigma_cmd *cmd) |
| 3023 | { |
| 3024 | const char *val; |
| 3025 | |
| 3026 | val = get_param(cmd, "FileType"); |
| 3027 | if (val && strcasecmp(val, "PPSMO") == 0) |
| 3028 | return download_ppsmo(dut, conn, intf, cmd); |
| 3029 | if (val && strcasecmp(val, "CERT") == 0) |
| 3030 | return download_cert(dut, conn, intf, cmd); |
| 3031 | if (val) { |
| 3032 | send_resp(dut, conn, SIGMA_ERROR, |
| 3033 | "ErrorCode,Unsupported FileType"); |
| 3034 | return 0; |
| 3035 | } |
| 3036 | |
| 3037 | return 1; |
| 3038 | } |
| 3039 | |
| 3040 | |
Ankita Bajaj | a2cb567 | 2017-10-25 16:08:28 +0530 | [diff] [blame] | 3041 | static int cmd_sta_preset_testparameters_oce(struct sigma_dut *dut, |
| 3042 | struct sigma_conn *conn, |
| 3043 | const char *intf, |
| 3044 | struct sigma_cmd *cmd) |
| 3045 | { |
| 3046 | const char *val; |
Ankita Bajaj | 1bde794 | 2018-01-09 19:15:01 +0530 | [diff] [blame] | 3047 | char buf[1000]; |
| 3048 | char text[20]; |
| 3049 | unsigned char addr[ETH_ALEN]; |
Ankita Bajaj | a2cb567 | 2017-10-25 16:08:28 +0530 | [diff] [blame] | 3050 | |
| 3051 | val = get_param(cmd, "OCESupport"); |
| 3052 | if (val && strcasecmp(val, "Disable") == 0) { |
| 3053 | if (wpa_command(intf, "SET oce 0") < 0) { |
| 3054 | send_resp(dut, conn, SIGMA_ERROR, |
| 3055 | "ErrorCode,Failed to disable OCE"); |
| 3056 | return 0; |
| 3057 | } |
| 3058 | } else if (val && strcasecmp(val, "Enable") == 0) { |
| 3059 | if (wpa_command(intf, "SET oce 1") < 0) { |
| 3060 | send_resp(dut, conn, SIGMA_ERROR, |
| 3061 | "ErrorCode,Failed to enable OCE"); |
| 3062 | return 0; |
| 3063 | } |
| 3064 | } |
| 3065 | |
vamsi krishna | a279949 | 2017-12-05 14:28:01 +0530 | [diff] [blame] | 3066 | val = get_param(cmd, "FILScap"); |
| 3067 | if (val && (atoi(val) == 1)) { |
| 3068 | if (wpa_command(intf, "SET disable_fils 0") < 0) { |
| 3069 | send_resp(dut, conn, SIGMA_ERROR, |
| 3070 | "ErrorCode,Failed to enable FILS"); |
| 3071 | return 0; |
| 3072 | } |
| 3073 | } else if (val && (atoi(val) == 0)) { |
| 3074 | if (wpa_command(intf, "SET disable_fils 1") < 0) { |
| 3075 | send_resp(dut, conn, SIGMA_ERROR, |
| 3076 | "ErrorCode,Failed to disable FILS"); |
| 3077 | return 0; |
| 3078 | } |
| 3079 | } |
| 3080 | |
Ankita Bajaj | 1bde794 | 2018-01-09 19:15:01 +0530 | [diff] [blame] | 3081 | val = get_param(cmd, "FILSHLP"); |
| 3082 | if (val && strcasecmp(val, "Enable") == 0) { |
| 3083 | if (get_wpa_status(get_station_ifname(), "address", text, |
| 3084 | sizeof(text)) < 0) |
| 3085 | return -2; |
| 3086 | hwaddr_aton(text, addr); |
| 3087 | snprintf(buf, sizeof(buf), |
| 3088 | "FILS_HLP_REQ_ADD ff:ff:ff:ff:ff:ff " |
| 3089 | "080045100140000040004011399e00000000ffffffff00440043" |
| 3090 | "012cb30001010600fd4f46410000000000000000000000000000" |
| 3091 | "000000000000" |
| 3092 | "%02x%02x%02x%02x%02x%02x" |
| 3093 | "0000000000000000000000000000000000000000000000000000" |
| 3094 | "0000000000000000000000000000000000000000000000000000" |
| 3095 | "0000000000000000000000000000000000000000000000000000" |
| 3096 | "0000000000000000000000000000000000000000000000000000" |
| 3097 | "0000000000000000000000000000000000000000000000000000" |
| 3098 | "0000000000000000000000000000000000000000000000000000" |
| 3099 | "0000000000000000000000000000000000000000000000000000" |
| 3100 | "0000000000000000000000000000000000000000638253633501" |
| 3101 | "013d0701000af549d29b390205dc3c12616e64726f69642d6468" |
| 3102 | "63702d382e302e30370a0103060f1a1c333a3b2b5000ff00", |
| 3103 | addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]); |
| 3104 | if (wpa_command(intf, buf)) { |
| 3105 | send_resp(dut, conn, SIGMA_ERROR, |
| 3106 | "ErrorCode,Failed to add HLP"); |
| 3107 | return 0; |
| 3108 | } |
| 3109 | dut->fils_hlp = 1; |
| 3110 | } |
| 3111 | |
Ankita Bajaj | a2cb567 | 2017-10-25 16:08:28 +0530 | [diff] [blame] | 3112 | return 1; |
| 3113 | } |
| 3114 | |
| 3115 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3116 | static void ath_sta_set_noack(struct sigma_dut *dut, const char *intf, |
| 3117 | const char *val) |
| 3118 | { |
| 3119 | int counter = 0; |
| 3120 | char token[50]; |
| 3121 | char *result; |
| 3122 | char buf[100]; |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 3123 | char *saveptr; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3124 | |
Peng Xu | b8fc5cc | 2017-05-10 17:27:28 -0700 | [diff] [blame] | 3125 | strlcpy(token, val, sizeof(token)); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3126 | token[sizeof(token) - 1] = '\0'; |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 3127 | result = strtok_r(token, ":", &saveptr); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3128 | while (result) { |
| 3129 | if (strcmp(result, "disable") == 0) { |
| 3130 | snprintf(buf, sizeof(buf), |
| 3131 | "iwpriv %s noackpolicy %d 1 0", |
| 3132 | intf, counter); |
| 3133 | } else { |
| 3134 | snprintf(buf, sizeof(buf), |
| 3135 | "iwpriv %s noackpolicy %d 1 1", |
| 3136 | intf, counter); |
| 3137 | } |
| 3138 | if (system(buf) != 0) { |
| 3139 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3140 | "iwpriv noackpolicy failed"); |
| 3141 | } |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 3142 | result = strtok_r(NULL, ":", &saveptr); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3143 | counter++; |
| 3144 | } |
| 3145 | } |
| 3146 | |
| 3147 | |
| 3148 | static void ath_sta_set_rts(struct sigma_dut *dut, const char *intf, |
| 3149 | const char *val) |
| 3150 | { |
| 3151 | char buf[100]; |
| 3152 | |
| 3153 | snprintf(buf, sizeof(buf), "iwconfig %s rts %s", intf, val); |
| 3154 | if (system(buf) != 0) { |
| 3155 | sigma_dut_print(dut, DUT_MSG_ERROR, "iwconfig RTS failed"); |
| 3156 | } |
| 3157 | } |
| 3158 | |
| 3159 | |
| 3160 | static void ath_sta_set_wmm(struct sigma_dut *dut, const char *intf, |
| 3161 | const char *val) |
| 3162 | { |
| 3163 | char buf[100]; |
| 3164 | |
| 3165 | if (strcasecmp(val, "off") == 0) { |
| 3166 | snprintf(buf, sizeof(buf), "iwpriv %s wmm 0", intf); |
| 3167 | if (system(buf) != 0) { |
| 3168 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3169 | "Failed to turn off WMM"); |
| 3170 | } |
| 3171 | } |
| 3172 | } |
| 3173 | |
| 3174 | |
Amarnath Hullur Subramanyam | 75214d2 | 2018-02-04 19:17:11 -0800 | [diff] [blame] | 3175 | static int wcn_sta_set_wmm(struct sigma_dut *dut, const char *intf, |
| 3176 | const char *val) |
| 3177 | { |
| 3178 | #ifdef NL80211_SUPPORT |
| 3179 | struct nl_msg *msg; |
| 3180 | int ret = 0; |
| 3181 | struct nlattr *params; |
| 3182 | int ifindex; |
| 3183 | int wmmenable = 1; |
| 3184 | |
| 3185 | if (val && |
| 3186 | (strcasecmp(val, "off") == 0 || strcmp(val, "0") == 0)) |
| 3187 | wmmenable = 0; |
| 3188 | |
| 3189 | ifindex = if_nametoindex(intf); |
| 3190 | if (ifindex == 0) { |
| 3191 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3192 | "%s: Index for interface %s failed", |
| 3193 | __func__, intf); |
| 3194 | return -1; |
| 3195 | } |
| 3196 | |
| 3197 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 3198 | NL80211_CMD_VENDOR)) || |
| 3199 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 3200 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 3201 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 3202 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || |
| 3203 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 3204 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WMM_ENABLE, |
| 3205 | wmmenable)) { |
| 3206 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3207 | "%s: err in adding vendor_cmd and vendor_data", |
| 3208 | __func__); |
| 3209 | nlmsg_free(msg); |
| 3210 | return -1; |
| 3211 | } |
| 3212 | nla_nest_end(msg, params); |
| 3213 | |
| 3214 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 3215 | if (ret) { |
| 3216 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3217 | "%s: err in send_and_recv_msgs, ret=%d", |
| 3218 | __func__, ret); |
| 3219 | } |
| 3220 | return ret; |
| 3221 | #else /* NL80211_SUPPORT */ |
| 3222 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3223 | "WMM cannot be changed without NL80211_SUPPORT defined"); |
| 3224 | return -1; |
| 3225 | #endif /* NL80211_SUPPORT */ |
| 3226 | } |
| 3227 | |
| 3228 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3229 | static void ath_sta_set_sgi(struct sigma_dut *dut, const char *intf, |
| 3230 | const char *val) |
| 3231 | { |
| 3232 | char buf[100]; |
| 3233 | int sgi20; |
| 3234 | |
| 3235 | sgi20 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0; |
| 3236 | |
| 3237 | snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d", intf, sgi20); |
| 3238 | if (system(buf) != 0) |
| 3239 | sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv shortgi failed"); |
| 3240 | } |
| 3241 | |
| 3242 | |
| 3243 | static void ath_sta_set_11nrates(struct sigma_dut *dut, const char *intf, |
| 3244 | const char *val) |
| 3245 | { |
| 3246 | char buf[100]; |
Pradeep Reddy POTTETI | 67376b7 | 2016-10-25 20:08:17 +0530 | [diff] [blame] | 3247 | int rate_code, v; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3248 | |
| 3249 | /* Disable Tx Beam forming when using a fixed rate */ |
| 3250 | ath_disable_txbf(dut, intf); |
| 3251 | |
Pradeep Reddy POTTETI | 67376b7 | 2016-10-25 20:08:17 +0530 | [diff] [blame] | 3252 | v = atoi(val); |
| 3253 | if (v < 0 || v > 32) { |
| 3254 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3255 | "Invalid Fixed MCS rate: %d", v); |
| 3256 | return; |
| 3257 | } |
| 3258 | rate_code = 0x80 + v; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3259 | |
| 3260 | snprintf(buf, sizeof(buf), "iwpriv %s set11NRates 0x%x", |
| 3261 | intf, rate_code); |
| 3262 | if (system(buf) != 0) { |
| 3263 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3264 | "iwpriv set11NRates failed"); |
| 3265 | } |
| 3266 | |
| 3267 | /* Channel width gets messed up, fix this */ |
| 3268 | snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d", intf, dut->chwidth); |
| 3269 | if (system(buf) != 0) |
| 3270 | sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv chwidth failed"); |
| 3271 | } |
| 3272 | |
| 3273 | |
Amarnath Hullur Subramanyam | d5bb573 | 2018-02-22 15:50:38 -0800 | [diff] [blame] | 3274 | static void iwpriv_sta_set_amsdu(struct sigma_dut *dut, const char *intf, |
| 3275 | const char *val) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3276 | { |
| 3277 | char buf[60]; |
| 3278 | |
| 3279 | if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) |
| 3280 | snprintf(buf, sizeof(buf), "iwpriv %s amsdu 2", intf); |
| 3281 | else |
| 3282 | snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf); |
| 3283 | |
| 3284 | if (system(buf) != 0) |
| 3285 | sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv amsdu failed"); |
| 3286 | } |
| 3287 | |
| 3288 | |
Deepak Dhamdhere | 80356cb | 2016-03-28 16:48:32 -0700 | [diff] [blame] | 3289 | static int iwpriv_sta_set_ampdu(struct sigma_dut *dut, const char *intf, |
| 3290 | int ampdu) |
| 3291 | { |
| 3292 | char buf[60]; |
Amarnath Hullur Subramanyam | 63c590a | 2018-03-07 15:26:21 -0800 | [diff] [blame] | 3293 | int maxaggregation = 63; |
Deepak Dhamdhere | 80356cb | 2016-03-28 16:48:32 -0700 | [diff] [blame] | 3294 | |
Amarnath Hullur Subramanyam | 63c590a | 2018-03-07 15:26:21 -0800 | [diff] [blame] | 3295 | if (ampdu) |
| 3296 | ampdu = maxaggregation; |
Deepak Dhamdhere | 80356cb | 2016-03-28 16:48:32 -0700 | [diff] [blame] | 3297 | snprintf(buf, sizeof(buf), "iwpriv %s ampdu %d", intf, ampdu); |
| 3298 | if (system(buf) != 0) { |
| 3299 | sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv ampdu failed"); |
| 3300 | return -1; |
| 3301 | } |
| 3302 | |
| 3303 | return 0; |
| 3304 | } |
| 3305 | |
| 3306 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3307 | static void ath_sta_set_stbc(struct sigma_dut *dut, const char *intf, |
| 3308 | const char *val) |
| 3309 | { |
| 3310 | char buf[60]; |
| 3311 | |
| 3312 | snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc %s", intf, val); |
| 3313 | if (system(buf) != 0) { |
| 3314 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3315 | "iwpriv tx_stbc failed"); |
| 3316 | } |
| 3317 | |
| 3318 | snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc %s", intf, val); |
| 3319 | if (system(buf) != 0) { |
| 3320 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3321 | "iwpriv rx_stbc failed"); |
| 3322 | } |
| 3323 | } |
| 3324 | |
| 3325 | |
| 3326 | static int wcn_sta_set_cts_width(struct sigma_dut *dut, const char *intf, |
| 3327 | const char *val) |
| 3328 | { |
| 3329 | char buf[60]; |
| 3330 | |
Peng Xu | cc317ed | 2017-05-18 16:44:37 -0700 | [diff] [blame] | 3331 | if (strcmp(val, "160") == 0) { |
| 3332 | snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 5", intf); |
| 3333 | } else if (strcmp(val, "80") == 0) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3334 | snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf); |
| 3335 | } else if (strcmp(val, "40") == 0) { |
| 3336 | snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 2", intf); |
| 3337 | } else if (strcmp(val, "20") == 0) { |
| 3338 | snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 1", intf); |
| 3339 | } else if (strcasecmp(val, "Auto") == 0) { |
| 3340 | buf[0] = '\0'; |
| 3341 | } else { |
| 3342 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3343 | "WIDTH/CTS_WIDTH value not supported"); |
| 3344 | return -1; |
| 3345 | } |
| 3346 | |
| 3347 | if (buf[0] != '\0' && system(buf) != 0) { |
| 3348 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3349 | "Failed to set WIDTH/CTS_WIDTH"); |
| 3350 | return -1; |
| 3351 | } |
| 3352 | |
| 3353 | return 0; |
| 3354 | } |
| 3355 | |
| 3356 | |
| 3357 | int ath_set_width(struct sigma_dut *dut, struct sigma_conn *conn, |
| 3358 | const char *intf, const char *val) |
| 3359 | { |
| 3360 | char buf[60]; |
| 3361 | |
| 3362 | if (strcasecmp(val, "Auto") == 0) { |
| 3363 | snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf); |
| 3364 | dut->chwidth = 0; |
| 3365 | } else if (strcasecmp(val, "20") == 0) { |
| 3366 | snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf); |
| 3367 | dut->chwidth = 0; |
| 3368 | } else if (strcasecmp(val, "40") == 0) { |
| 3369 | snprintf(buf, sizeof(buf), "iwpriv %s chwidth 1", intf); |
| 3370 | dut->chwidth = 1; |
| 3371 | } else if (strcasecmp(val, "80") == 0) { |
| 3372 | snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf); |
| 3373 | dut->chwidth = 2; |
| 3374 | } else if (strcasecmp(val, "160") == 0) { |
| 3375 | snprintf(buf, sizeof(buf), "iwpriv %s chwidth 3", intf); |
| 3376 | dut->chwidth = 3; |
| 3377 | } else { |
| 3378 | send_resp(dut, conn, SIGMA_ERROR, |
| 3379 | "ErrorCode,WIDTH not supported"); |
| 3380 | return -1; |
| 3381 | } |
| 3382 | |
| 3383 | if (system(buf) != 0) { |
| 3384 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3385 | "iwpriv chwidth failed"); |
| 3386 | } |
| 3387 | |
| 3388 | return 0; |
| 3389 | } |
| 3390 | |
| 3391 | |
| 3392 | static int wcn_sta_set_sp_stream(struct sigma_dut *dut, const char *intf, |
| 3393 | const char *val) |
| 3394 | { |
| 3395 | char buf[60]; |
Arif Hussain | ac6c511 | 2018-05-25 17:34:00 -0700 | [diff] [blame^] | 3396 | int sta_nss; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3397 | |
Amarnath Hullur Subramanyam | d5374fa | 2018-02-25 19:00:24 -0800 | [diff] [blame] | 3398 | if (strcmp(val, "1SS") == 0 || strcmp(val, "1") == 0) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3399 | snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf); |
Arif Hussain | ac6c511 | 2018-05-25 17:34:00 -0700 | [diff] [blame^] | 3400 | sta_nss = 1; |
Amarnath Hullur Subramanyam | d5374fa | 2018-02-25 19:00:24 -0800 | [diff] [blame] | 3401 | } else if (strcmp(val, "2SS") == 0 || strcmp(val, "2") == 0) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3402 | snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf); |
Arif Hussain | ac6c511 | 2018-05-25 17:34:00 -0700 | [diff] [blame^] | 3403 | sta_nss = 2; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3404 | } else { |
| 3405 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3406 | "SP_STREAM value not supported"); |
| 3407 | return -1; |
| 3408 | } |
| 3409 | |
| 3410 | if (system(buf) != 0) { |
| 3411 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3412 | "Failed to set SP_STREAM"); |
| 3413 | return -1; |
| 3414 | } |
| 3415 | |
Arif Hussain | ac6c511 | 2018-05-25 17:34:00 -0700 | [diff] [blame^] | 3416 | dut->sta_nss = sta_nss; |
| 3417 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3418 | return 0; |
| 3419 | } |
| 3420 | |
| 3421 | |
Pradeep Reddy POTTETI | 4a1f6b3 | 2016-11-23 13:15:21 +0530 | [diff] [blame] | 3422 | static void wcn_sta_set_stbc(struct sigma_dut *dut, const char *intf, |
| 3423 | const char *val) |
| 3424 | { |
| 3425 | char buf[60]; |
| 3426 | |
| 3427 | snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc %s", intf, val); |
| 3428 | if (system(buf) != 0) |
| 3429 | sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv tx_stbc failed"); |
| 3430 | |
| 3431 | snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc %s", intf, val); |
| 3432 | if (system(buf) != 0) |
| 3433 | sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv rx_stbc failed"); |
| 3434 | } |
| 3435 | |
| 3436 | |
Ashwini Patil | 68d02cd | 2017-01-10 15:39:16 +0530 | [diff] [blame] | 3437 | static int mbo_set_cellular_data_capa(struct sigma_dut *dut, |
| 3438 | struct sigma_conn *conn, |
| 3439 | const char *intf, int capa) |
| 3440 | { |
| 3441 | char buf[32]; |
| 3442 | |
| 3443 | if (capa > 0 && capa < 4) { |
| 3444 | snprintf(buf, sizeof(buf), "SET mbo_cell_capa %d", capa); |
| 3445 | if (wpa_command(intf, buf) < 0) { |
| 3446 | send_resp(dut, conn, SIGMA_ERROR, |
| 3447 | "ErrorCode, Failed to set cellular data capability"); |
| 3448 | return 0; |
| 3449 | } |
| 3450 | return 1; |
| 3451 | } |
| 3452 | |
| 3453 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3454 | "Invalid Cellular data capability: %d", capa); |
| 3455 | send_resp(dut, conn, SIGMA_INVALID, |
| 3456 | "ErrorCode,Invalid cellular data capability"); |
| 3457 | return 0; |
| 3458 | } |
| 3459 | |
| 3460 | |
Ashwini Patil | 9183fdb | 2017-04-13 16:58:25 +0530 | [diff] [blame] | 3461 | static int mbo_set_roaming(struct sigma_dut *dut, struct sigma_conn *conn, |
| 3462 | const char *intf, const char *val) |
| 3463 | { |
| 3464 | if (strcasecmp(val, "Disable") == 0) { |
| 3465 | if (wpa_command(intf, "SET roaming 0") < 0) { |
| 3466 | send_resp(dut, conn, SIGMA_ERROR, |
| 3467 | "ErrorCode,Failed to disable roaming"); |
| 3468 | return 0; |
| 3469 | } |
| 3470 | return 1; |
| 3471 | } |
| 3472 | |
| 3473 | if (strcasecmp(val, "Enable") == 0) { |
| 3474 | if (wpa_command(intf, "SET roaming 1") < 0) { |
| 3475 | send_resp(dut, conn, SIGMA_ERROR, |
| 3476 | "ErrorCode,Failed to enable roaming"); |
| 3477 | return 0; |
| 3478 | } |
| 3479 | return 1; |
| 3480 | } |
| 3481 | |
| 3482 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3483 | "Invalid value provided for roaming: %s", val); |
| 3484 | send_resp(dut, conn, SIGMA_INVALID, |
| 3485 | "ErrorCode,Unknown value provided for Roaming"); |
| 3486 | return 0; |
| 3487 | } |
| 3488 | |
| 3489 | |
Ashwini Patil | a75de5a | 2017-04-13 16:35:05 +0530 | [diff] [blame] | 3490 | static int mbo_set_assoc_disallow(struct sigma_dut *dut, |
| 3491 | struct sigma_conn *conn, |
| 3492 | const char *intf, const char *val) |
| 3493 | { |
| 3494 | if (strcasecmp(val, "Disable") == 0) { |
| 3495 | if (wpa_command(intf, "SET ignore_assoc_disallow 1") < 0) { |
| 3496 | send_resp(dut, conn, SIGMA_ERROR, |
| 3497 | "ErrorCode,Failed to disable Assoc_disallow"); |
| 3498 | return 0; |
| 3499 | } |
| 3500 | return 1; |
| 3501 | } |
| 3502 | |
| 3503 | if (strcasecmp(val, "Enable") == 0) { |
| 3504 | if (wpa_command(intf, "SET ignore_assoc_disallow 0") < 0) { |
| 3505 | send_resp(dut, conn, SIGMA_ERROR, |
| 3506 | "ErrorCode,Failed to enable Assoc_disallow"); |
| 3507 | return 0; |
| 3508 | } |
| 3509 | return 1; |
| 3510 | } |
| 3511 | |
| 3512 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3513 | "Invalid value provided for Assoc_disallow: %s", val); |
| 3514 | send_resp(dut, conn, SIGMA_INVALID, |
| 3515 | "ErrorCode,Unknown value provided for Assoc_disallow"); |
| 3516 | return 0; |
| 3517 | } |
| 3518 | |
| 3519 | |
Ashwini Patil | c63161e | 2017-04-13 16:30:23 +0530 | [diff] [blame] | 3520 | static int mbo_set_bss_trans_req(struct sigma_dut *dut, struct sigma_conn *conn, |
| 3521 | const char *intf, const char *val) |
| 3522 | { |
| 3523 | if (strcasecmp(val, "Reject") == 0) { |
| 3524 | if (wpa_command(intf, "SET reject_btm_req_reason 1") < 0) { |
| 3525 | send_resp(dut, conn, SIGMA_ERROR, |
| 3526 | "ErrorCode,Failed to Reject BTM Request"); |
| 3527 | return 0; |
| 3528 | } |
| 3529 | return 1; |
| 3530 | } |
| 3531 | |
| 3532 | if (strcasecmp(val, "Accept") == 0) { |
| 3533 | if (wpa_command(intf, "SET reject_btm_req_reason 0") < 0) { |
| 3534 | send_resp(dut, conn, SIGMA_ERROR, |
| 3535 | "ErrorCode,Failed to Accept BTM Request"); |
| 3536 | return 0; |
| 3537 | } |
| 3538 | return 1; |
| 3539 | } |
| 3540 | |
| 3541 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3542 | "Invalid value provided for BSS_Transition: %s", val); |
| 3543 | send_resp(dut, conn, SIGMA_INVALID, |
| 3544 | "ErrorCode,Unknown value provided for BSS_Transition"); |
| 3545 | return 0; |
| 3546 | } |
| 3547 | |
| 3548 | |
Ashwini Patil | 0040258 | 2017-04-13 12:29:39 +0530 | [diff] [blame] | 3549 | static int mbo_set_non_pref_ch_list(struct sigma_dut *dut, |
| 3550 | struct sigma_conn *conn, |
| 3551 | const char *intf, |
| 3552 | struct sigma_cmd *cmd) |
| 3553 | { |
| 3554 | const char *ch, *pref, *op_class, *reason; |
| 3555 | char buf[120]; |
| 3556 | int len, ret; |
| 3557 | |
| 3558 | pref = get_param(cmd, "Ch_Pref"); |
| 3559 | if (!pref) |
| 3560 | return 1; |
| 3561 | |
| 3562 | if (strcasecmp(pref, "clear") == 0) { |
| 3563 | free(dut->non_pref_ch_list); |
| 3564 | dut->non_pref_ch_list = NULL; |
| 3565 | } else { |
| 3566 | op_class = get_param(cmd, "Ch_Op_Class"); |
| 3567 | if (!op_class) { |
| 3568 | send_resp(dut, conn, SIGMA_INVALID, |
| 3569 | "ErrorCode,Ch_Op_Class not provided"); |
| 3570 | return 0; |
| 3571 | } |
| 3572 | |
| 3573 | ch = get_param(cmd, "Ch_Pref_Num"); |
| 3574 | if (!ch) { |
| 3575 | send_resp(dut, conn, SIGMA_INVALID, |
| 3576 | "ErrorCode,Ch_Pref_Num not provided"); |
| 3577 | return 0; |
| 3578 | } |
| 3579 | |
| 3580 | reason = get_param(cmd, "Ch_Reason_Code"); |
| 3581 | if (!reason) { |
| 3582 | send_resp(dut, conn, SIGMA_INVALID, |
| 3583 | "ErrorCode,Ch_Reason_Code not provided"); |
| 3584 | return 0; |
| 3585 | } |
| 3586 | |
| 3587 | if (!dut->non_pref_ch_list) { |
| 3588 | dut->non_pref_ch_list = |
| 3589 | calloc(1, NON_PREF_CH_LIST_SIZE); |
| 3590 | if (!dut->non_pref_ch_list) { |
| 3591 | send_resp(dut, conn, SIGMA_ERROR, |
| 3592 | "ErrorCode,Failed to allocate memory for non_pref_ch_list"); |
| 3593 | return 0; |
| 3594 | } |
| 3595 | } |
| 3596 | len = strlen(dut->non_pref_ch_list); |
| 3597 | ret = snprintf(dut->non_pref_ch_list + len, |
| 3598 | NON_PREF_CH_LIST_SIZE - len, |
| 3599 | " %s:%s:%s:%s", op_class, ch, pref, reason); |
| 3600 | if (ret > 0 && ret < NON_PREF_CH_LIST_SIZE - len) { |
| 3601 | sigma_dut_print(dut, DUT_MSG_DEBUG, "non_pref_list: %s", |
| 3602 | dut->non_pref_ch_list); |
| 3603 | } else { |
| 3604 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3605 | "snprintf failed for non_pref_list, ret = %d", |
| 3606 | ret); |
| 3607 | send_resp(dut, conn, SIGMA_ERROR, |
| 3608 | "ErrorCode,snprintf failed"); |
| 3609 | free(dut->non_pref_ch_list); |
| 3610 | dut->non_pref_ch_list = NULL; |
| 3611 | return 0; |
| 3612 | } |
| 3613 | } |
| 3614 | |
| 3615 | ret = snprintf(buf, sizeof(buf), "SET non_pref_chan%s", |
| 3616 | dut->non_pref_ch_list ? dut->non_pref_ch_list : " "); |
| 3617 | if (ret < 0 || ret >= (int) sizeof(buf)) { |
| 3618 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 3619 | "snprintf failed for set non_pref_chan, ret: %d", |
| 3620 | ret); |
| 3621 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,snprint failed"); |
| 3622 | return 0; |
| 3623 | } |
| 3624 | |
| 3625 | if (wpa_command(intf, buf) < 0) { |
| 3626 | send_resp(dut, conn, SIGMA_ERROR, |
| 3627 | "ErrorCode,Failed to set non-preferred channel list"); |
| 3628 | return 0; |
| 3629 | } |
| 3630 | |
| 3631 | return 1; |
| 3632 | } |
| 3633 | |
| 3634 | |
Amarnath Hullur Subramanyam | 474a17d | 2018-02-22 18:45:54 -0800 | [diff] [blame] | 3635 | #ifdef NL80211_SUPPORT |
Amarnath Hullur Subramanyam | ae8a2d9 | 2018-03-01 06:32:21 -0800 | [diff] [blame] | 3636 | |
Amarnath Hullur Subramanyam | 474a17d | 2018-02-22 18:45:54 -0800 | [diff] [blame] | 3637 | static int sta_set_he_fragmentation(struct sigma_dut *dut, const char *intf, |
| 3638 | enum he_fragmentation_val frag) |
| 3639 | { |
| 3640 | struct nl_msg *msg; |
| 3641 | int ret = 0; |
| 3642 | struct nlattr *params; |
| 3643 | int ifindex; |
| 3644 | |
| 3645 | ifindex = if_nametoindex(intf); |
| 3646 | if (ifindex == 0) { |
| 3647 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3648 | "%s: Index for interface %s failed", |
| 3649 | __func__, intf); |
| 3650 | return -1; |
| 3651 | } |
| 3652 | |
| 3653 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 3654 | NL80211_CMD_VENDOR)) || |
| 3655 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 3656 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 3657 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 3658 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || |
| 3659 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 3660 | nla_put_u8(msg, |
| 3661 | QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_FRAGMENTATION, |
| 3662 | frag)) { |
| 3663 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3664 | "%s: err in adding vendor_cmd and vendor_data", |
| 3665 | __func__); |
| 3666 | nlmsg_free(msg); |
| 3667 | return -1; |
| 3668 | } |
| 3669 | nla_nest_end(msg, params); |
| 3670 | |
| 3671 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 3672 | if (ret) { |
| 3673 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3674 | "%s: err in send_and_recv_msgs, ret=%d", |
| 3675 | __func__, ret); |
| 3676 | } |
| 3677 | return ret; |
| 3678 | } |
Amarnath Hullur Subramanyam | ae8a2d9 | 2018-03-01 06:32:21 -0800 | [diff] [blame] | 3679 | |
| 3680 | |
Subhani Shaik | 8e7a305 | 2018-04-24 14:03:00 -0700 | [diff] [blame] | 3681 | static int sta_set_he_ltf(struct sigma_dut *dut, const char *intf, |
| 3682 | enum qca_wlan_he_ltf_cfg ltf) |
| 3683 | { |
| 3684 | struct nl_msg *msg; |
| 3685 | int ret = 0; |
| 3686 | struct nlattr *params; |
| 3687 | int ifindex; |
| 3688 | |
| 3689 | ifindex = if_nametoindex(intf); |
| 3690 | if (ifindex == 0) { |
| 3691 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3692 | "%s: Index for interface %s failed", |
| 3693 | __func__, intf); |
| 3694 | return -1; |
| 3695 | } |
| 3696 | |
| 3697 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 3698 | NL80211_CMD_VENDOR)) || |
| 3699 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 3700 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 3701 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 3702 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || |
| 3703 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 3704 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_LTF, |
| 3705 | ltf)) { |
| 3706 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3707 | "%s: err in adding vendor_cmd and vendor_data", |
| 3708 | __func__); |
| 3709 | nlmsg_free(msg); |
| 3710 | return -1; |
| 3711 | } |
| 3712 | nla_nest_end(msg, params); |
| 3713 | |
| 3714 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 3715 | if (ret) { |
| 3716 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3717 | "%s: err in send_and_recv_msgs, ret=%d", |
| 3718 | __func__, ret); |
| 3719 | } |
| 3720 | return ret; |
| 3721 | } |
| 3722 | |
| 3723 | |
Amarnath Hullur Subramanyam | ae8a2d9 | 2018-03-01 06:32:21 -0800 | [diff] [blame] | 3724 | static int nlvendor_sta_set_noack(struct sigma_dut *dut, const char *intf, |
| 3725 | int noack, enum qca_wlan_ac_type ac) |
| 3726 | { |
| 3727 | struct nl_msg *msg; |
| 3728 | int ret = 0; |
| 3729 | struct nlattr *params; |
| 3730 | int ifindex; |
| 3731 | |
| 3732 | ifindex = if_nametoindex(intf); |
| 3733 | if (ifindex == 0) { |
| 3734 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3735 | "%s: Index for interface %s failed", |
| 3736 | __func__, intf); |
| 3737 | return -1; |
| 3738 | } |
| 3739 | |
| 3740 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 3741 | NL80211_CMD_VENDOR)) || |
| 3742 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 3743 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 3744 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 3745 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || |
| 3746 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 3747 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_NO_ACK, |
| 3748 | noack) || |
| 3749 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_NO_ACK_AC, |
| 3750 | ac)) { |
| 3751 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3752 | "%s: err in adding vendor_cmd and vendor_data", |
| 3753 | __func__); |
| 3754 | nlmsg_free(msg); |
| 3755 | return -1; |
| 3756 | } |
| 3757 | nla_nest_end(msg, params); |
| 3758 | |
| 3759 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 3760 | if (ret) { |
| 3761 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3762 | "%s: err in send_and_recv_msgs, ret=%d", |
| 3763 | __func__, ret); |
| 3764 | } |
| 3765 | return ret; |
| 3766 | } |
| 3767 | |
| 3768 | |
| 3769 | static void wcn_sta_set_noack(struct sigma_dut *dut, const char *intf, |
| 3770 | const char *val) |
| 3771 | { |
| 3772 | int noack, ret; |
| 3773 | char token[100]; |
| 3774 | char *result; |
| 3775 | char *saveptr; |
| 3776 | enum qca_wlan_ac_type ac = QCA_WLAN_AC_BE; |
| 3777 | |
| 3778 | strlcpy(token, val, sizeof(token)); |
| 3779 | token[sizeof(token) - 1] = '\0'; |
| 3780 | result = strtok_r(token, ":", &saveptr); |
| 3781 | while (result) { |
| 3782 | noack = strcasecmp(result, "Disable") != 0; |
| 3783 | ret = nlvendor_sta_set_noack(dut, intf, noack, ac); |
| 3784 | if (ret) { |
| 3785 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3786 | "nlvendor_sta_set_noack failed for ac:%d, ret:%d", |
| 3787 | ac, ret); |
| 3788 | } |
| 3789 | result = strtok_r(NULL, ":", &saveptr); |
| 3790 | ac++; |
| 3791 | } |
| 3792 | } |
| 3793 | |
Amarnath Hullur Subramanyam | 474a17d | 2018-02-22 18:45:54 -0800 | [diff] [blame] | 3794 | #endif /* NL80211_SUPPORT */ |
| 3795 | |
| 3796 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3797 | static int cmd_sta_preset_testparameters(struct sigma_dut *dut, |
| 3798 | struct sigma_conn *conn, |
| 3799 | struct sigma_cmd *cmd) |
| 3800 | { |
| 3801 | const char *intf = get_param(cmd, "Interface"); |
| 3802 | const char *val; |
| 3803 | |
| 3804 | val = get_param(cmd, "Program"); |
Peng Xu | e9fa795 | 2017-05-09 15:59:49 -0700 | [diff] [blame] | 3805 | if (val && strcasecmp(val, "HS2-R2") == 0) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3806 | return cmd_sta_preset_testparameters_hs2_r2(dut, conn, intf, |
| 3807 | cmd); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3808 | |
priyadharshini gowthaman | d66913a | 2016-07-29 15:11:17 -0700 | [diff] [blame] | 3809 | if (val && strcasecmp(val, "LOC") == 0) |
| 3810 | return loc_cmd_sta_preset_testparameters(dut, conn, cmd); |
| 3811 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3812 | #ifdef ANDROID_NAN |
| 3813 | if (val && strcasecmp(val, "NAN") == 0) |
| 3814 | return nan_cmd_sta_preset_testparameters(dut, conn, cmd); |
| 3815 | #endif /* ANDROID_NAN */ |
Amarnath Hullur Subramanyam | 9c381f5 | 2017-03-17 00:04:41 -0700 | [diff] [blame] | 3816 | #ifdef MIRACAST |
| 3817 | if (val && (strcasecmp(val, "WFD") == 0 || |
| 3818 | strcasecmp(val, "DisplayR2") == 0)) |
| 3819 | return miracast_preset_testparameters(dut, conn, cmd); |
| 3820 | #endif /* MIRACAST */ |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3821 | |
Ashwini Patil | 68d02cd | 2017-01-10 15:39:16 +0530 | [diff] [blame] | 3822 | if (val && strcasecmp(val, "MBO") == 0) { |
| 3823 | val = get_param(cmd, "Cellular_Data_Cap"); |
| 3824 | if (val && |
| 3825 | mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0) |
| 3826 | return 0; |
Ashwini Patil | 0040258 | 2017-04-13 12:29:39 +0530 | [diff] [blame] | 3827 | |
| 3828 | val = get_param(cmd, "Ch_Pref"); |
| 3829 | if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0) |
| 3830 | return 0; |
| 3831 | |
Ashwini Patil | c63161e | 2017-04-13 16:30:23 +0530 | [diff] [blame] | 3832 | val = get_param(cmd, "BSS_Transition"); |
| 3833 | if (val && mbo_set_bss_trans_req(dut, conn, intf, val) == 0) |
| 3834 | return 0; |
| 3835 | |
Ashwini Patil | a75de5a | 2017-04-13 16:35:05 +0530 | [diff] [blame] | 3836 | val = get_param(cmd, "Assoc_Disallow"); |
| 3837 | if (val && mbo_set_assoc_disallow(dut, conn, intf, val) == 0) |
| 3838 | return 0; |
| 3839 | |
Ashwini Patil | 9183fdb | 2017-04-13 16:58:25 +0530 | [diff] [blame] | 3840 | val = get_param(cmd, "Roaming"); |
| 3841 | if (val && mbo_set_roaming(dut, conn, intf, val) == 0) |
| 3842 | return 0; |
| 3843 | |
Ashwini Patil | 68d02cd | 2017-01-10 15:39:16 +0530 | [diff] [blame] | 3844 | return 1; |
| 3845 | } |
| 3846 | |
Ankita Bajaj | a2cb567 | 2017-10-25 16:08:28 +0530 | [diff] [blame] | 3847 | if (val && strcasecmp(val, "OCE") == 0) |
| 3848 | return cmd_sta_preset_testparameters_oce(dut, conn, intf, cmd); |
| 3849 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3850 | #if 0 |
| 3851 | val = get_param(cmd, "Supplicant"); |
| 3852 | if (val && strcasecmp(val, "Default") != 0) { |
| 3853 | send_resp(dut, conn, SIGMA_ERROR, |
| 3854 | "ErrorCode,Only default(Vendor) supplicant " |
| 3855 | "supported"); |
| 3856 | return 0; |
| 3857 | } |
| 3858 | #endif |
| 3859 | |
| 3860 | val = get_param(cmd, "RTS"); |
| 3861 | if (val) { |
| 3862 | switch (get_driver_type()) { |
| 3863 | case DRIVER_ATHEROS: |
| 3864 | ath_sta_set_rts(dut, intf, val); |
| 3865 | break; |
| 3866 | default: |
| 3867 | #if 0 |
| 3868 | send_resp(dut, conn, SIGMA_ERROR, |
| 3869 | "ErrorCode,Setting RTS not supported"); |
| 3870 | return 0; |
| 3871 | #else |
| 3872 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 3873 | "Setting RTS not supported"); |
| 3874 | break; |
| 3875 | #endif |
| 3876 | } |
| 3877 | } |
| 3878 | |
| 3879 | #if 0 |
| 3880 | val = get_param(cmd, "FRGMNT"); |
| 3881 | if (val) { |
| 3882 | /* TODO */ |
| 3883 | send_resp(dut, conn, SIGMA_ERROR, |
| 3884 | "ErrorCode,Setting FRGMNT not supported"); |
| 3885 | return 0; |
| 3886 | } |
| 3887 | #endif |
| 3888 | |
| 3889 | #if 0 |
| 3890 | val = get_param(cmd, "Preamble"); |
| 3891 | if (val) { |
| 3892 | /* TODO: Long/Short */ |
| 3893 | send_resp(dut, conn, SIGMA_ERROR, |
| 3894 | "ErrorCode,Setting Preamble not supported"); |
| 3895 | return 0; |
| 3896 | } |
| 3897 | #endif |
| 3898 | |
| 3899 | val = get_param(cmd, "Mode"); |
| 3900 | if (val) { |
| 3901 | if (strcmp(val, "11b") == 0 || |
| 3902 | strcmp(val, "11g") == 0 || |
| 3903 | strcmp(val, "11a") == 0 || |
| 3904 | strcmp(val, "11n") == 0 || |
| 3905 | strcmp(val, "11ng") == 0 || |
| 3906 | strcmp(val, "11nl") == 0 || |
| 3907 | strcmp(val, "11nl(nabg)") == 0 || |
| 3908 | strcmp(val, "AC") == 0 || |
| 3909 | strcmp(val, "11AC") == 0 || |
| 3910 | strcmp(val, "11ac") == 0 || |
| 3911 | strcmp(val, "11na") == 0 || |
Amarnath Hullur Subramanyam | b0db271 | 2018-01-30 19:40:35 -0800 | [diff] [blame] | 3912 | strcmp(val, "11an") == 0 || |
| 3913 | strcmp(val, "11ax") == 0) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3914 | /* STA supports all modes by default */ |
| 3915 | } else { |
| 3916 | send_resp(dut, conn, SIGMA_ERROR, |
| 3917 | "ErrorCode,Setting Mode not supported"); |
| 3918 | return 0; |
| 3919 | } |
Amarnath Hullur Subramanyam | 97d0e53 | 2018-01-31 02:53:02 -0800 | [diff] [blame] | 3920 | |
| 3921 | /* Change the mode only in case of testbed for HE program |
| 3922 | * and for 11a and 11g modes only. */ |
| 3923 | if (dut->program == PROGRAM_HE && |
| 3924 | dut->device_type == STA_testbed) { |
| 3925 | int phymode; |
| 3926 | char buf[60]; |
| 3927 | |
| 3928 | if (strcmp(val, "11a") == 0) { |
Amarnath Hullur Subramanyam | 94dfaf0 | 2018-03-02 19:26:57 -0800 | [diff] [blame] | 3929 | phymode = 1; /* IEEE80211_MODE_11A */ |
| 3930 | } else if (strcmp(val, "11g") == 0) { |
| 3931 | phymode = 3; /* IEEE80211_MODE_11G */ |
| 3932 | } else if (strcmp(val, "11b") == 0) { |
| 3933 | phymode = 2; /* IEEE80211_MODE_11B */ |
| 3934 | } else if (strcmp(val, "11n") == 0 || |
| 3935 | strcmp(val, "11nl") == 0 || |
| 3936 | strcmp(val, "11nl(nabg)") == 0) { |
| 3937 | phymode = 22; /* IEEE80211_MODE_11AGN */ |
| 3938 | } else if (strcmp(val, "11ng") == 0) { |
| 3939 | phymode = 13; /* IEEE80211_MODE_11NG_HT40 */ |
| 3940 | } else if (strcmp(val, "AC") == 0 || |
| 3941 | strcasecmp(val, "11AC") == 0) { |
| 3942 | phymode = 19; /* IEEE80211_MODE_11AC_VHT80 */ |
| 3943 | } else if (strcmp(val, "11na") == 0 || |
| 3944 | strcasecmp(val, "11an") == 0) { |
| 3945 | phymode = 14; /* IEEE80211_MODE_11NA_HT40 */ |
| 3946 | } else if (strcmp(val, "11ax") == 0) { |
| 3947 | phymode = 0; /* IEEE80211_MODE_AUTO */ |
Amarnath Hullur Subramanyam | 97d0e53 | 2018-01-31 02:53:02 -0800 | [diff] [blame] | 3948 | } else { |
| 3949 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 3950 | "Ignoring mode change for mode: %s", |
| 3951 | val); |
| 3952 | phymode = -1; |
| 3953 | } |
| 3954 | if (phymode != -1) { |
| 3955 | snprintf(buf, sizeof(buf), |
| 3956 | "iwpriv %s setphymode %d", |
| 3957 | intf, phymode); |
| 3958 | if (system(buf) != 0) { |
| 3959 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3960 | "iwpriv setting of phymode failed"); |
| 3961 | } |
| 3962 | } |
| 3963 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3964 | } |
| 3965 | |
| 3966 | val = get_param(cmd, "wmm"); |
| 3967 | if (val) { |
| 3968 | switch (get_driver_type()) { |
| 3969 | case DRIVER_ATHEROS: |
| 3970 | ath_sta_set_wmm(dut, intf, val); |
| 3971 | break; |
Amarnath Hullur Subramanyam | 75214d2 | 2018-02-04 19:17:11 -0800 | [diff] [blame] | 3972 | case DRIVER_WCN: |
| 3973 | wcn_sta_set_wmm(dut, intf, val); |
| 3974 | break; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3975 | default: |
| 3976 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 3977 | "Setting wmm not supported"); |
| 3978 | break; |
| 3979 | } |
| 3980 | } |
| 3981 | |
| 3982 | val = get_param(cmd, "Powersave"); |
| 3983 | if (val) { |
| 3984 | if (strcmp(val, "0") == 0 || strcasecmp(val, "off") == 0) { |
| 3985 | if (wpa_command(get_station_ifname(), |
| 3986 | "P2P_SET ps 0") < 0) |
| 3987 | return -2; |
| 3988 | /* Make sure test modes are disabled */ |
| 3989 | wpa_command(get_station_ifname(), "P2P_SET ps 98"); |
| 3990 | wpa_command(get_station_ifname(), "P2P_SET ps 96"); |
| 3991 | } else if (strcmp(val, "1") == 0 || |
| 3992 | strcasecmp(val, "PSPoll") == 0 || |
| 3993 | strcasecmp(val, "on") == 0) { |
| 3994 | /* Disable default power save mode */ |
| 3995 | wpa_command(get_station_ifname(), "P2P_SET ps 0"); |
| 3996 | /* Enable PS-Poll test mode */ |
| 3997 | if (wpa_command(get_station_ifname(), |
| 3998 | "P2P_SET ps 97") < 0 || |
| 3999 | wpa_command(get_station_ifname(), |
| 4000 | "P2P_SET ps 99") < 0) |
| 4001 | return -2; |
| 4002 | } else if (strcmp(val, "2") == 0 || |
| 4003 | strcasecmp(val, "Fast") == 0) { |
| 4004 | /* TODO */ |
| 4005 | send_resp(dut, conn, SIGMA_ERROR, |
| 4006 | "ErrorCode,Powersave=Fast not supported"); |
| 4007 | return 0; |
| 4008 | } else if (strcmp(val, "3") == 0 || |
| 4009 | strcasecmp(val, "PSNonPoll") == 0) { |
| 4010 | /* Make sure test modes are disabled */ |
| 4011 | wpa_command(get_station_ifname(), "P2P_SET ps 98"); |
| 4012 | wpa_command(get_station_ifname(), "P2P_SET ps 96"); |
| 4013 | |
| 4014 | /* Enable default power save mode */ |
| 4015 | if (wpa_command(get_station_ifname(), |
| 4016 | "P2P_SET ps 1") < 0) |
| 4017 | return -2; |
| 4018 | } else |
| 4019 | return -1; |
| 4020 | } |
| 4021 | |
| 4022 | val = get_param(cmd, "NoAck"); |
| 4023 | if (val) { |
| 4024 | switch (get_driver_type()) { |
| 4025 | case DRIVER_ATHEROS: |
| 4026 | ath_sta_set_noack(dut, intf, val); |
| 4027 | break; |
Amarnath Hullur Subramanyam | ae8a2d9 | 2018-03-01 06:32:21 -0800 | [diff] [blame] | 4028 | #ifdef NL80211_SUPPORT |
| 4029 | case DRIVER_WCN: |
| 4030 | wcn_sta_set_noack(dut, intf, val); |
| 4031 | break; |
| 4032 | #endif /* NL80211_SUPPORT */ |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4033 | default: |
| 4034 | send_resp(dut, conn, SIGMA_ERROR, |
| 4035 | "ErrorCode,Setting NoAck not supported"); |
| 4036 | return 0; |
| 4037 | } |
| 4038 | } |
| 4039 | |
| 4040 | val = get_param(cmd, "IgnoreChswitchProhibit"); |
| 4041 | if (val) { |
| 4042 | /* TODO: Enabled/disabled */ |
| 4043 | if (strcasecmp(val, "Enabled") == 0) { |
| 4044 | send_resp(dut, conn, SIGMA_ERROR, |
| 4045 | "ErrorCode,Enabling IgnoreChswitchProhibit " |
| 4046 | "not supported"); |
| 4047 | return 0; |
| 4048 | } |
| 4049 | } |
| 4050 | |
| 4051 | val = get_param(cmd, "TDLS"); |
| 4052 | if (val) { |
| 4053 | if (strcasecmp(val, "Disabled") == 0) { |
| 4054 | if (wpa_command(intf, "SET tdls_disabled 1")) { |
| 4055 | send_resp(dut, conn, SIGMA_ERROR, |
| 4056 | "ErrorCode,Failed to disable TDLS"); |
| 4057 | return 0; |
| 4058 | } |
| 4059 | } else if (strcasecmp(val, "Enabled") == 0) { |
| 4060 | if (wpa_command(intf, "SET tdls_disabled 0")) { |
| 4061 | send_resp(dut, conn, SIGMA_ERROR, |
| 4062 | "ErrorCode,Failed to enable TDLS"); |
| 4063 | return 0; |
| 4064 | } |
| 4065 | } else { |
| 4066 | send_resp(dut, conn, SIGMA_ERROR, |
| 4067 | "ErrorCode,Unsupported TDLS value"); |
| 4068 | return 0; |
| 4069 | } |
| 4070 | } |
| 4071 | |
| 4072 | val = get_param(cmd, "TDLSmode"); |
| 4073 | if (val) { |
| 4074 | if (strcasecmp(val, "Default") == 0) { |
| 4075 | wpa_command(intf, "SET tdls_testing 0"); |
| 4076 | } else if (strcasecmp(val, "APProhibit") == 0) { |
| 4077 | if (wpa_command(intf, "SET tdls_testing 0x400")) { |
| 4078 | send_resp(dut, conn, SIGMA_ERROR, |
| 4079 | "ErrorCode,Failed to enable ignore " |
| 4080 | "APProhibit TDLS mode"); |
| 4081 | return 0; |
| 4082 | } |
| 4083 | } else if (strcasecmp(val, "HiLoMac") == 0) { |
| 4084 | /* STA should respond with TDLS setup req for a TDLS |
| 4085 | * setup req */ |
| 4086 | if (wpa_command(intf, "SET tdls_testing 0x80")) { |
| 4087 | send_resp(dut, conn, SIGMA_ERROR, |
| 4088 | "ErrorCode,Failed to enable HiLoMac " |
| 4089 | "TDLS mode"); |
| 4090 | return 0; |
| 4091 | } |
| 4092 | } else if (strcasecmp(val, "WeakSecurity") == 0) { |
| 4093 | /* |
| 4094 | * Since all security modes are enabled by default when |
| 4095 | * Sigma control is used, there is no need to do |
| 4096 | * anything here. |
| 4097 | */ |
| 4098 | } else if (strcasecmp(val, "ExistLink") == 0) { |
| 4099 | /* |
| 4100 | * Since we allow new TDLS Setup Request even if there |
| 4101 | * is an existing link, nothing needs to be done for |
| 4102 | * this. |
| 4103 | */ |
| 4104 | } else { |
| 4105 | /* TODO: |
| 4106 | * ExistLink: STA should send TDLS setup req even if |
| 4107 | * direct link already exists |
| 4108 | */ |
| 4109 | send_resp(dut, conn, SIGMA_ERROR, |
| 4110 | "ErrorCode,Unsupported TDLSmode value"); |
| 4111 | return 0; |
| 4112 | } |
| 4113 | } |
| 4114 | |
| 4115 | val = get_param(cmd, "FakePubKey"); |
| 4116 | if (val && atoi(val) && wpa_command(intf, "SET wps_corrupt_pkhash 1")) { |
| 4117 | send_resp(dut, conn, SIGMA_ERROR, |
| 4118 | "ErrorCode,Failed to enable FakePubKey"); |
| 4119 | return 0; |
| 4120 | } |
| 4121 | |
Amarnath Hullur Subramanyam | ae1042b | 2018-02-22 21:52:52 -0800 | [diff] [blame] | 4122 | #ifdef NL80211_SUPPORT |
| 4123 | val = get_param(cmd, "FrgmntSupport"); |
| 4124 | if (val) { |
| 4125 | if (strcasecmp(val, "Enable") == 0) { |
| 4126 | if (sta_set_he_fragmentation(dut, intf, |
| 4127 | HE_FRAG_LEVEL1)) { |
| 4128 | send_resp(dut, conn, SIGMA_ERROR, |
| 4129 | "ErrorCode,Failed to enable HE Fragmentation"); |
| 4130 | return 0; |
| 4131 | } |
| 4132 | } else if (strcasecmp(val, "Disable") == 0) { |
| 4133 | if (sta_set_he_fragmentation(dut, intf, |
| 4134 | HE_FRAG_DISABLE)) { |
| 4135 | send_resp(dut, conn, SIGMA_ERROR, |
| 4136 | "ErrorCode,Failed to disable HE Fragmentation"); |
| 4137 | return 0; |
| 4138 | } |
| 4139 | } |
| 4140 | } |
| 4141 | #endif /* NL80211_SUPPORT */ |
| 4142 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4143 | return 1; |
| 4144 | } |
| 4145 | |
| 4146 | |
| 4147 | static const char * ath_get_radio_name(const char *radio_name) |
| 4148 | { |
| 4149 | if (radio_name == NULL) |
| 4150 | return "wifi0"; |
| 4151 | if (strcmp(radio_name, "wifi1") == 0) |
| 4152 | return "wifi1"; |
| 4153 | if (strcmp(radio_name, "wifi2") == 0) |
| 4154 | return "wifi2"; |
| 4155 | return "wifi0"; |
| 4156 | } |
| 4157 | |
| 4158 | |
| 4159 | static void ath_sta_set_txsp_stream(struct sigma_dut *dut, const char *intf, |
| 4160 | const char *val) |
| 4161 | { |
| 4162 | char buf[60]; |
| 4163 | unsigned int vht_mcsmap = 0; |
| 4164 | int txchainmask = 0; |
| 4165 | const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]); |
| 4166 | |
| 4167 | if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) { |
| 4168 | if (dut->testbed_flag_txsp == 1) { |
| 4169 | vht_mcsmap = 0xfffc; |
| 4170 | dut->testbed_flag_txsp = 0; |
| 4171 | } else { |
| 4172 | vht_mcsmap = 0xfffe; |
| 4173 | } |
| 4174 | txchainmask = 1; |
| 4175 | } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) { |
| 4176 | if (dut->testbed_flag_txsp == 1) { |
| 4177 | vht_mcsmap = 0xfff0; |
| 4178 | dut->testbed_flag_txsp = 0; |
| 4179 | } else { |
| 4180 | vht_mcsmap = 0xfffa; |
| 4181 | } |
| 4182 | txchainmask = 3; |
| 4183 | } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) { |
| 4184 | if (dut->testbed_flag_txsp == 1) { |
| 4185 | vht_mcsmap = 0xffc0; |
| 4186 | dut->testbed_flag_txsp = 0; |
| 4187 | } else { |
| 4188 | vht_mcsmap = 0xffea; |
| 4189 | } |
| 4190 | txchainmask = 7; |
| 4191 | } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) { |
| 4192 | if (dut->testbed_flag_txsp == 1) { |
| 4193 | vht_mcsmap = 0xff00; |
| 4194 | dut->testbed_flag_txsp = 0; |
| 4195 | } else { |
| 4196 | vht_mcsmap = 0xffaa; |
| 4197 | } |
| 4198 | txchainmask = 15; |
| 4199 | } else { |
| 4200 | if (dut->testbed_flag_txsp == 1) { |
| 4201 | vht_mcsmap = 0xffc0; |
| 4202 | dut->testbed_flag_txsp = 0; |
| 4203 | } else { |
| 4204 | vht_mcsmap = 0xffea; |
| 4205 | } |
| 4206 | } |
| 4207 | |
| 4208 | if (txchainmask) { |
| 4209 | snprintf(buf, sizeof(buf), "iwpriv %s txchainmask %d", |
| 4210 | basedev, txchainmask); |
| 4211 | if (system(buf) != 0) { |
| 4212 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4213 | "iwpriv txchainmask failed"); |
| 4214 | } |
| 4215 | } |
| 4216 | |
| 4217 | snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0x%04x", |
| 4218 | intf, vht_mcsmap); |
| 4219 | if (system(buf) != 0) { |
| 4220 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4221 | "iwpriv %s vht_mcsmap 0x%04x failed", |
| 4222 | intf, vht_mcsmap); |
| 4223 | } |
| 4224 | } |
| 4225 | |
| 4226 | |
| 4227 | static void ath_sta_set_rxsp_stream(struct sigma_dut *dut, const char *intf, |
| 4228 | const char *val) |
| 4229 | { |
| 4230 | char buf[60]; |
| 4231 | unsigned int vht_mcsmap = 0; |
| 4232 | int rxchainmask = 0; |
| 4233 | const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]); |
| 4234 | |
| 4235 | if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) { |
| 4236 | if (dut->testbed_flag_rxsp == 1) { |
| 4237 | vht_mcsmap = 0xfffc; |
| 4238 | dut->testbed_flag_rxsp = 0; |
| 4239 | } else { |
| 4240 | vht_mcsmap = 0xfffe; |
| 4241 | } |
| 4242 | rxchainmask = 1; |
| 4243 | } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) { |
| 4244 | if (dut->testbed_flag_rxsp == 1) { |
| 4245 | vht_mcsmap = 0xfff0; |
| 4246 | dut->testbed_flag_rxsp = 0; |
| 4247 | } else { |
| 4248 | vht_mcsmap = 0xfffa; |
| 4249 | } |
| 4250 | rxchainmask = 3; |
| 4251 | } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) { |
| 4252 | if (dut->testbed_flag_rxsp == 1) { |
| 4253 | vht_mcsmap = 0xffc0; |
| 4254 | dut->testbed_flag_rxsp = 0; |
| 4255 | } else { |
| 4256 | vht_mcsmap = 0xffea; |
| 4257 | } |
| 4258 | rxchainmask = 7; |
| 4259 | } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) { |
| 4260 | if (dut->testbed_flag_rxsp == 1) { |
| 4261 | vht_mcsmap = 0xff00; |
| 4262 | dut->testbed_flag_rxsp = 0; |
| 4263 | } else { |
| 4264 | vht_mcsmap = 0xffaa; |
| 4265 | } |
| 4266 | rxchainmask = 15; |
| 4267 | } else { |
| 4268 | if (dut->testbed_flag_rxsp == 1) { |
| 4269 | vht_mcsmap = 0xffc0; |
| 4270 | dut->testbed_flag_rxsp = 0; |
| 4271 | } else { |
| 4272 | vht_mcsmap = 0xffea; |
| 4273 | } |
| 4274 | } |
| 4275 | |
| 4276 | if (rxchainmask) { |
| 4277 | snprintf(buf, sizeof(buf), "iwpriv %s rxchainmask %d", |
| 4278 | basedev, rxchainmask); |
| 4279 | if (system(buf) != 0) { |
| 4280 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4281 | "iwpriv rxchainmask failed"); |
| 4282 | } |
| 4283 | } |
| 4284 | |
| 4285 | snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0x%04x", |
| 4286 | intf, vht_mcsmap); |
| 4287 | if (system(buf) != 0) { |
| 4288 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4289 | "iwpriv %s vht_mcsmap 0x%04x", |
| 4290 | intf, vht_mcsmap); |
| 4291 | } |
| 4292 | } |
| 4293 | |
| 4294 | |
| 4295 | void ath_set_zero_crc(struct sigma_dut *dut, const char *val) |
| 4296 | { |
| 4297 | if (strcasecmp(val, "enable") == 0) { |
| 4298 | if (system("athdiag --set --address=0x2a204 --and=0xbfffffff") |
| 4299 | != 0) { |
| 4300 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4301 | "Disable BB_VHTSIGB_CRC_CALC failed"); |
| 4302 | } |
| 4303 | |
| 4304 | if (system("athdiag --set --address=0x2a204 --or=0x80000000") |
| 4305 | != 0) { |
| 4306 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4307 | "Enable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed"); |
| 4308 | } |
| 4309 | } else { |
| 4310 | if (system("athdiag --set --address=0x2a204 --and=0x7fffffff") |
| 4311 | != 0) { |
| 4312 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4313 | "Disable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed"); |
| 4314 | } |
| 4315 | |
| 4316 | if (system("athdiag --set --address=0x2a204 --or=0x40000000") |
| 4317 | != 0) { |
| 4318 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4319 | "Enable BB_VHTSIGB_CRC_CALC failed"); |
| 4320 | } |
| 4321 | } |
| 4322 | } |
| 4323 | |
| 4324 | |
Amarnath Hullur Subramanyam | ebfe6b6 | 2018-01-31 03:04:17 -0800 | [diff] [blame] | 4325 | static int wcn_sta_set_width(struct sigma_dut *dut, const char *intf, |
| 4326 | const char *val) |
| 4327 | { |
| 4328 | char buf[60]; |
| 4329 | |
| 4330 | if (strcmp(val, "20") == 0) { |
| 4331 | snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf); |
| 4332 | dut->chwidth = 0; |
| 4333 | } else if (strcmp(val, "40") == 0) { |
| 4334 | snprintf(buf, sizeof(buf), "iwpriv %s chwidth 1", intf); |
| 4335 | dut->chwidth = 1; |
| 4336 | } else if (strcmp(val, "80") == 0) { |
| 4337 | snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf); |
| 4338 | dut->chwidth = 2; |
Sunil Dutt | b1cccac | 2018-05-22 21:03:12 +0530 | [diff] [blame] | 4339 | } else if (strcasecmp(val, "Auto") == 0) { |
Amarnath Hullur Subramanyam | ebfe6b6 | 2018-01-31 03:04:17 -0800 | [diff] [blame] | 4340 | buf[0] = '\0'; |
| 4341 | } else { |
| 4342 | sigma_dut_print(dut, DUT_MSG_ERROR, "WIDTH %s not supported", |
| 4343 | val); |
| 4344 | return -1; |
| 4345 | } |
| 4346 | |
| 4347 | if (buf[0] != '\0' && system(buf) != 0) { |
| 4348 | sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv chwidth failed"); |
| 4349 | return -1; |
| 4350 | } |
| 4351 | |
| 4352 | return 0; |
| 4353 | } |
| 4354 | |
| 4355 | |
Amarnath Hullur Subramanyam | d8a9db9 | 2018-02-02 18:53:14 -0800 | [diff] [blame] | 4356 | static int nlvendor_sta_set_addba_reject(struct sigma_dut *dut, |
| 4357 | const char *intf, int addbareject) |
| 4358 | { |
| 4359 | #ifdef NL80211_SUPPORT |
| 4360 | struct nl_msg *msg; |
| 4361 | int ret = 0; |
| 4362 | struct nlattr *params; |
| 4363 | int ifindex; |
| 4364 | |
| 4365 | ifindex = if_nametoindex(intf); |
| 4366 | if (ifindex == 0) { |
| 4367 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4368 | "%s: Index for interface %s failed", |
| 4369 | __func__, intf); |
| 4370 | return -1; |
| 4371 | } |
| 4372 | |
| 4373 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 4374 | NL80211_CMD_VENDOR)) || |
| 4375 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 4376 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 4377 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 4378 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || |
| 4379 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 4380 | nla_put_u8(msg, |
| 4381 | QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ACCEPT_ADDBA_REQ, |
| 4382 | !addbareject)) { |
| 4383 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4384 | "%s: err in adding vendor_cmd and vendor_data", |
| 4385 | __func__); |
| 4386 | nlmsg_free(msg); |
| 4387 | return -1; |
| 4388 | } |
| 4389 | nla_nest_end(msg, params); |
| 4390 | |
| 4391 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 4392 | if (ret) { |
| 4393 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4394 | "%s: err in send_and_recv_msgs, ret=%d", |
| 4395 | __func__, ret); |
| 4396 | } |
| 4397 | return ret; |
| 4398 | #else /* NL80211_SUPPORT */ |
| 4399 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4400 | "ADDBA_REJECT cannot be set without NL80211_SUPPORT defined"); |
| 4401 | return -1; |
| 4402 | #endif /* NL80211_SUPPORT */ |
| 4403 | } |
| 4404 | |
| 4405 | |
| 4406 | static int sta_set_addba_reject(struct sigma_dut *dut, const char *intf, |
| 4407 | int addbareject) |
| 4408 | { |
| 4409 | int ret; |
| 4410 | |
| 4411 | switch (get_driver_type()) { |
| 4412 | case DRIVER_WCN: |
| 4413 | ret = nlvendor_sta_set_addba_reject(dut, intf, addbareject); |
| 4414 | if (ret) { |
| 4415 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4416 | "nlvendor_sta_set_addba_reject failed, ret:%d", |
| 4417 | ret); |
| 4418 | return ret; |
| 4419 | } |
| 4420 | break; |
| 4421 | default: |
| 4422 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4423 | "errorCode,Unsupported ADDBA_REJECT with the current driver"); |
| 4424 | ret = -1; |
| 4425 | break; |
| 4426 | } |
| 4427 | |
| 4428 | return ret; |
| 4429 | } |
| 4430 | |
| 4431 | |
Amarnath Hullur Subramanyam | 1f65a67 | 2018-03-07 14:50:29 -0800 | [diff] [blame] | 4432 | static int nlvendor_config_send_addba(struct sigma_dut *dut, const char *intf, |
| 4433 | int enable) |
Amarnath Hullur Subramanyam | 9745b3c | 2018-02-04 21:27:57 -0800 | [diff] [blame] | 4434 | { |
| 4435 | #ifdef NL80211_SUPPORT |
| 4436 | struct nl_msg *msg; |
| 4437 | int ret = 0; |
| 4438 | struct nlattr *params; |
| 4439 | int ifindex; |
| 4440 | |
| 4441 | ifindex = if_nametoindex(intf); |
| 4442 | if (ifindex == 0) { |
| 4443 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4444 | "%s: Index for interface %s failed", |
| 4445 | __func__, intf); |
| 4446 | return -1; |
| 4447 | } |
| 4448 | |
| 4449 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 4450 | NL80211_CMD_VENDOR)) || |
| 4451 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 4452 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 4453 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 4454 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || |
| 4455 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 4456 | nla_put_u8(msg, |
| 4457 | QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SEND_ADDBA_REQ, |
Amarnath Hullur Subramanyam | 1f65a67 | 2018-03-07 14:50:29 -0800 | [diff] [blame] | 4458 | enable)) { |
Amarnath Hullur Subramanyam | 9745b3c | 2018-02-04 21:27:57 -0800 | [diff] [blame] | 4459 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4460 | "%s: err in adding vendor_cmd and vendor_data", |
| 4461 | __func__); |
| 4462 | nlmsg_free(msg); |
| 4463 | return -1; |
| 4464 | } |
| 4465 | nla_nest_end(msg, params); |
| 4466 | |
| 4467 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 4468 | if (ret) { |
| 4469 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4470 | "%s: err in send_and_recv_msgs, ret=%d", |
| 4471 | __func__, ret); |
| 4472 | } |
| 4473 | return ret; |
| 4474 | #else /* NL80211_SUPPORT */ |
| 4475 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4476 | "Disable addba not possible without NL80211_SUPPORT defined"); |
| 4477 | return -1; |
| 4478 | #endif /* NL80211_SUPPORT */ |
| 4479 | } |
| 4480 | |
| 4481 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4482 | static int cmd_sta_set_wireless_common(const char *intf, struct sigma_dut *dut, |
| 4483 | struct sigma_conn *conn, |
| 4484 | struct sigma_cmd *cmd) |
| 4485 | { |
| 4486 | const char *val; |
Amarnath Hullur Subramanyam | d8a9db9 | 2018-02-02 18:53:14 -0800 | [diff] [blame] | 4487 | int ampdu = -1, addbareject = -1; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4488 | char buf[30]; |
| 4489 | |
| 4490 | val = get_param(cmd, "40_INTOLERANT"); |
| 4491 | if (val) { |
| 4492 | if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) { |
| 4493 | /* TODO: iwpriv ht40intol through wpa_supplicant */ |
| 4494 | send_resp(dut, conn, SIGMA_ERROR, |
| 4495 | "ErrorCode,40_INTOLERANT not supported"); |
| 4496 | return 0; |
| 4497 | } |
| 4498 | } |
| 4499 | |
| 4500 | val = get_param(cmd, "ADDBA_REJECT"); |
| 4501 | if (val) { |
| 4502 | if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) { |
| 4503 | /* reject any ADDBA with status "decline" */ |
| 4504 | ampdu = 0; |
Amarnath Hullur Subramanyam | d8a9db9 | 2018-02-02 18:53:14 -0800 | [diff] [blame] | 4505 | addbareject = 1; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4506 | } else { |
| 4507 | /* accept ADDBA */ |
| 4508 | ampdu = 1; |
Amarnath Hullur Subramanyam | d8a9db9 | 2018-02-02 18:53:14 -0800 | [diff] [blame] | 4509 | addbareject = 0; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4510 | } |
| 4511 | } |
| 4512 | |
Amarnath Hullur Subramanyam | d8a9db9 | 2018-02-02 18:53:14 -0800 | [diff] [blame] | 4513 | if (addbareject >= 0 && |
| 4514 | sta_set_addba_reject(dut, intf, addbareject) < 0) { |
| 4515 | send_resp(dut, conn, SIGMA_ERROR, |
| 4516 | "ErrorCode,set addba_reject failed"); |
| 4517 | return 0; |
| 4518 | } |
| 4519 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4520 | val = get_param(cmd, "AMPDU"); |
| 4521 | if (val) { |
| 4522 | if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) { |
| 4523 | /* enable AMPDU Aggregation */ |
| 4524 | if (ampdu == 0) { |
| 4525 | send_resp(dut, conn, SIGMA_ERROR, |
| 4526 | "ErrorCode,Mismatch in " |
| 4527 | "addba_reject/ampdu - " |
| 4528 | "not supported"); |
| 4529 | return 0; |
| 4530 | } |
| 4531 | ampdu = 1; |
| 4532 | } else { |
| 4533 | /* disable AMPDU Aggregation */ |
| 4534 | if (ampdu == 1) { |
| 4535 | send_resp(dut, conn, SIGMA_ERROR, |
| 4536 | "ErrorCode,Mismatch in " |
| 4537 | "addba_reject/ampdu - " |
| 4538 | "not supported"); |
| 4539 | return 0; |
| 4540 | } |
| 4541 | ampdu = 0; |
| 4542 | } |
| 4543 | } |
| 4544 | |
| 4545 | if (ampdu >= 0) { |
Amarnath Hullur Subramanyam | 9745b3c | 2018-02-04 21:27:57 -0800 | [diff] [blame] | 4546 | int ret; |
| 4547 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4548 | sigma_dut_print(dut, DUT_MSG_DEBUG, "%s A-MPDU aggregation", |
| 4549 | ampdu ? "Enabling" : "Disabling"); |
| 4550 | snprintf(buf, sizeof(buf), "SET ampdu %d", ampdu); |
Deepak Dhamdhere | 80356cb | 2016-03-28 16:48:32 -0700 | [diff] [blame] | 4551 | if (wpa_command(intf, buf) < 0 && |
| 4552 | iwpriv_sta_set_ampdu(dut, intf, ampdu) < 0) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4553 | send_resp(dut, conn, SIGMA_ERROR, |
| 4554 | "ErrorCode,set aggr failed"); |
| 4555 | return 0; |
| 4556 | } |
Amarnath Hullur Subramanyam | 9745b3c | 2018-02-04 21:27:57 -0800 | [diff] [blame] | 4557 | |
| 4558 | if (ampdu == 0) { |
| 4559 | /* Disable sending of addba using nl vendor command */ |
Amarnath Hullur Subramanyam | 1f65a67 | 2018-03-07 14:50:29 -0800 | [diff] [blame] | 4560 | ret = nlvendor_config_send_addba(dut, intf, 0); |
Amarnath Hullur Subramanyam | 9745b3c | 2018-02-04 21:27:57 -0800 | [diff] [blame] | 4561 | if (ret) { |
| 4562 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4563 | "Failed to disable addba, ret:%d", |
| 4564 | ret); |
| 4565 | } |
| 4566 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4567 | } |
| 4568 | |
| 4569 | val = get_param(cmd, "AMSDU"); |
| 4570 | if (val) { |
| 4571 | switch (get_driver_type()) { |
| 4572 | case DRIVER_ATHEROS: |
Amarnath Hullur Subramanyam | d5bb573 | 2018-02-22 15:50:38 -0800 | [diff] [blame] | 4573 | case DRIVER_WCN: |
| 4574 | iwpriv_sta_set_amsdu(dut, intf, val); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4575 | break; |
| 4576 | default: |
| 4577 | if (strcmp(val, "1") == 0 || |
| 4578 | strcasecmp(val, "Enable") == 0) { |
| 4579 | /* Enable AMSDU Aggregation */ |
| 4580 | send_resp(dut, conn, SIGMA_ERROR, |
| 4581 | "ErrorCode,AMSDU aggregation not supported"); |
| 4582 | return 0; |
| 4583 | } |
| 4584 | break; |
| 4585 | } |
| 4586 | } |
| 4587 | |
| 4588 | val = get_param(cmd, "STBC_RX"); |
| 4589 | if (val) { |
| 4590 | switch (get_driver_type()) { |
| 4591 | case DRIVER_ATHEROS: |
| 4592 | ath_sta_set_stbc(dut, intf, val); |
| 4593 | break; |
Pradeep Reddy POTTETI | 4a1f6b3 | 2016-11-23 13:15:21 +0530 | [diff] [blame] | 4594 | case DRIVER_WCN: |
| 4595 | wcn_sta_set_stbc(dut, intf, val); |
| 4596 | break; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4597 | default: |
| 4598 | send_resp(dut, conn, SIGMA_ERROR, |
| 4599 | "ErrorCode,STBC_RX not supported"); |
| 4600 | return 0; |
| 4601 | } |
| 4602 | } |
| 4603 | |
| 4604 | val = get_param(cmd, "WIDTH"); |
| 4605 | if (val) { |
| 4606 | switch (get_driver_type()) { |
| 4607 | case DRIVER_WCN: |
Amarnath Hullur Subramanyam | ebfe6b6 | 2018-01-31 03:04:17 -0800 | [diff] [blame] | 4608 | if (wcn_sta_set_width(dut, intf, val) < 0) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4609 | send_resp(dut, conn, SIGMA_ERROR, |
| 4610 | "ErrorCode,Failed to set WIDTH"); |
| 4611 | return 0; |
| 4612 | } |
| 4613 | break; |
| 4614 | case DRIVER_ATHEROS: |
| 4615 | if (ath_set_width(dut, conn, intf, val) < 0) |
| 4616 | return 0; |
| 4617 | break; |
| 4618 | default: |
| 4619 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4620 | "Setting WIDTH not supported"); |
| 4621 | break; |
| 4622 | } |
| 4623 | } |
| 4624 | |
| 4625 | val = get_param(cmd, "SMPS"); |
| 4626 | if (val) { |
| 4627 | /* TODO: Dynamic/0, Static/1, No Limit/2 */ |
| 4628 | send_resp(dut, conn, SIGMA_ERROR, |
| 4629 | "ErrorCode,SMPS not supported"); |
| 4630 | return 0; |
| 4631 | } |
| 4632 | |
| 4633 | val = get_param(cmd, "TXSP_STREAM"); |
| 4634 | if (val) { |
| 4635 | switch (get_driver_type()) { |
| 4636 | case DRIVER_WCN: |
| 4637 | if (wcn_sta_set_sp_stream(dut, intf, val) < 0) { |
| 4638 | send_resp(dut, conn, SIGMA_ERROR, |
| 4639 | "ErrorCode,Failed to set TXSP_STREAM"); |
| 4640 | return 0; |
| 4641 | } |
| 4642 | break; |
| 4643 | case DRIVER_ATHEROS: |
| 4644 | ath_sta_set_txsp_stream(dut, intf, val); |
| 4645 | break; |
| 4646 | default: |
| 4647 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4648 | "Setting TXSP_STREAM not supported"); |
| 4649 | break; |
| 4650 | } |
| 4651 | } |
| 4652 | |
| 4653 | val = get_param(cmd, "RXSP_STREAM"); |
| 4654 | if (val) { |
| 4655 | switch (get_driver_type()) { |
| 4656 | case DRIVER_WCN: |
| 4657 | if (wcn_sta_set_sp_stream(dut, intf, val) < 0) { |
| 4658 | send_resp(dut, conn, SIGMA_ERROR, |
| 4659 | "ErrorCode,Failed to set RXSP_STREAM"); |
| 4660 | return 0; |
| 4661 | } |
| 4662 | break; |
| 4663 | case DRIVER_ATHEROS: |
| 4664 | ath_sta_set_rxsp_stream(dut, intf, val); |
| 4665 | break; |
| 4666 | default: |
| 4667 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4668 | "Setting RXSP_STREAM not supported"); |
| 4669 | break; |
| 4670 | } |
| 4671 | } |
| 4672 | |
| 4673 | val = get_param(cmd, "DYN_BW_SGNL"); |
| 4674 | if (val) { |
Priyadharshini Gowthaman | 818afef | 2015-11-09 13:28:15 -0800 | [diff] [blame] | 4675 | switch (get_driver_type()) { |
| 4676 | case DRIVER_WCN: |
Peng Xu | c59afd3 | 2016-11-21 15:01:11 -0800 | [diff] [blame] | 4677 | if (strcasecmp(val, "enable") == 0) { |
| 4678 | snprintf(buf, sizeof(buf), |
| 4679 | "iwpriv %s cwmenable 1", intf); |
| 4680 | if (system(buf) != 0) { |
| 4681 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4682 | "iwpriv cwmenable 1 failed"); |
| 4683 | return 0; |
| 4684 | } |
| 4685 | } else if (strcasecmp(val, "disable") == 0) { |
| 4686 | snprintf(buf, sizeof(buf), |
| 4687 | "iwpriv %s cwmenable 0", intf); |
| 4688 | if (system(buf) != 0) { |
| 4689 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4690 | "iwpriv cwmenable 0 failed"); |
| 4691 | return 0; |
| 4692 | } |
| 4693 | } else { |
| 4694 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4695 | "Unsupported DYN_BW_SGL"); |
| 4696 | } |
| 4697 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4698 | snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf); |
| 4699 | if (system(buf) != 0) { |
| 4700 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4701 | "Failed to set cts_cbw in DYN_BW_SGNL"); |
| 4702 | return 0; |
| 4703 | } |
Priyadharshini Gowthaman | 818afef | 2015-11-09 13:28:15 -0800 | [diff] [blame] | 4704 | break; |
| 4705 | case DRIVER_ATHEROS: |
priyadharshini gowthaman | e5e2517 | 2015-12-08 14:53:48 -0800 | [diff] [blame] | 4706 | novap_reset(dut, intf); |
Priyadharshini Gowthaman | 818afef | 2015-11-09 13:28:15 -0800 | [diff] [blame] | 4707 | ath_config_dyn_bw_sig(dut, intf, val); |
| 4708 | break; |
| 4709 | default: |
| 4710 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4711 | "Failed to set DYN_BW_SGNL"); |
| 4712 | break; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4713 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4714 | } |
| 4715 | |
| 4716 | val = get_param(cmd, "RTS_FORCE"); |
| 4717 | if (val) { |
priyadharshini gowthaman | e5e2517 | 2015-12-08 14:53:48 -0800 | [diff] [blame] | 4718 | novap_reset(dut, intf); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4719 | if (strcasecmp(val, "Enable") == 0) { |
| 4720 | snprintf(buf, sizeof(buf), "iwconfig %s rts 64", intf); |
Priyadharshini Gowthaman | abdb212 | 2015-11-17 11:52:19 +0200 | [diff] [blame] | 4721 | if (system(buf) != 0) { |
| 4722 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4723 | "Failed to set RTS_FORCE 64"); |
| 4724 | } |
priyadharshini gowthaman | 270870e | 2015-12-09 10:10:23 -0800 | [diff] [blame] | 4725 | snprintf(buf, sizeof(buf), |
| 4726 | "wifitool %s beeliner_fw_test 100 1", intf); |
| 4727 | if (system(buf) != 0) { |
| 4728 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4729 | "wifitool beeliner_fw_test 100 1 failed"); |
| 4730 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4731 | } else if (strcasecmp(val, "Disable") == 0) { |
| 4732 | snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", |
| 4733 | intf); |
Priyadharshini Gowthaman | abdb212 | 2015-11-17 11:52:19 +0200 | [diff] [blame] | 4734 | if (system(buf) != 0) { |
| 4735 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4736 | "Failed to set RTS_FORCE 2347"); |
| 4737 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4738 | } else { |
| 4739 | send_resp(dut, conn, SIGMA_ERROR, |
| 4740 | "ErrorCode,RTS_FORCE value not supported"); |
| 4741 | return 0; |
| 4742 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4743 | } |
| 4744 | |
| 4745 | val = get_param(cmd, "CTS_WIDTH"); |
| 4746 | if (val) { |
| 4747 | switch (get_driver_type()) { |
| 4748 | case DRIVER_WCN: |
| 4749 | if (wcn_sta_set_cts_width(dut, intf, val) < 0) { |
| 4750 | send_resp(dut, conn, SIGMA_ERROR, |
| 4751 | "ErrorCode,Failed to set CTS_WIDTH"); |
| 4752 | return 0; |
| 4753 | } |
| 4754 | break; |
| 4755 | case DRIVER_ATHEROS: |
| 4756 | ath_set_cts_width(dut, intf, val); |
| 4757 | break; |
| 4758 | default: |
| 4759 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4760 | "Setting CTS_WIDTH not supported"); |
| 4761 | break; |
| 4762 | } |
| 4763 | } |
| 4764 | |
| 4765 | val = get_param(cmd, "BW_SGNL"); |
| 4766 | if (val) { |
| 4767 | if (strcasecmp(val, "Enable") == 0) { |
| 4768 | snprintf(buf, sizeof(buf), "iwpriv %s cwmenable 1", |
| 4769 | intf); |
| 4770 | } else if (strcasecmp(val, "Disable") == 0) { |
| 4771 | /* TODO: Disable */ |
| 4772 | buf[0] = '\0'; |
| 4773 | } else { |
| 4774 | send_resp(dut, conn, SIGMA_ERROR, |
| 4775 | "ErrorCode,BW_SGNL value not supported"); |
| 4776 | return 0; |
| 4777 | } |
| 4778 | |
| 4779 | if (buf[0] != '\0' && system(buf) != 0) { |
| 4780 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4781 | "Failed to set BW_SGNL"); |
| 4782 | } |
| 4783 | } |
| 4784 | |
| 4785 | val = get_param(cmd, "Band"); |
| 4786 | if (val) { |
| 4787 | if (strcmp(val, "2.4") == 0 || strcmp(val, "5") == 0) { |
| 4788 | /* STA supports all bands by default */ |
| 4789 | } else { |
| 4790 | send_resp(dut, conn, SIGMA_ERROR, |
| 4791 | "ErrorCode,Unsupported Band"); |
| 4792 | return 0; |
| 4793 | } |
| 4794 | } |
| 4795 | |
| 4796 | val = get_param(cmd, "zero_crc"); |
| 4797 | if (val) { |
| 4798 | switch (get_driver_type()) { |
| 4799 | case DRIVER_ATHEROS: |
| 4800 | ath_set_zero_crc(dut, val); |
| 4801 | break; |
| 4802 | default: |
| 4803 | break; |
| 4804 | } |
| 4805 | } |
| 4806 | |
| 4807 | return 1; |
| 4808 | } |
| 4809 | |
| 4810 | |
| 4811 | static int sta_set_60g_common(struct sigma_dut *dut, struct sigma_conn *conn, |
| 4812 | struct sigma_cmd *cmd) |
| 4813 | { |
| 4814 | const char *val; |
| 4815 | char buf[100]; |
| 4816 | |
| 4817 | val = get_param(cmd, "MSDUSize"); |
| 4818 | if (val) { |
| 4819 | int mtu; |
| 4820 | |
| 4821 | dut->amsdu_size = atoi(val); |
| 4822 | if (dut->amsdu_size > IEEE80211_MAX_DATA_LEN_DMG || |
| 4823 | dut->amsdu_size < IEEE80211_SNAP_LEN_DMG) { |
| 4824 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4825 | "MSDUSize %d is above max %d or below min %d", |
| 4826 | dut->amsdu_size, |
| 4827 | IEEE80211_MAX_DATA_LEN_DMG, |
| 4828 | IEEE80211_SNAP_LEN_DMG); |
| 4829 | dut->amsdu_size = 0; |
| 4830 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; |
| 4831 | } |
| 4832 | |
| 4833 | mtu = dut->amsdu_size - IEEE80211_SNAP_LEN_DMG; |
| 4834 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 4835 | "Setting amsdu_size to %d", mtu); |
| 4836 | snprintf(buf, sizeof(buf), "ifconfig %s mtu %d", |
| 4837 | get_station_ifname(), mtu); |
| 4838 | |
| 4839 | if (system(buf) != 0) { |
| 4840 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s", |
| 4841 | buf); |
| 4842 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; |
| 4843 | } |
| 4844 | } |
| 4845 | |
| 4846 | val = get_param(cmd, "BAckRcvBuf"); |
| 4847 | if (val) { |
| 4848 | dut->back_rcv_buf = atoi(val); |
| 4849 | if (dut->back_rcv_buf == 0) { |
| 4850 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4851 | "Failed to convert %s or value is 0", |
| 4852 | val); |
| 4853 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; |
| 4854 | } |
| 4855 | |
| 4856 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 4857 | "Setting BAckRcvBuf to %s", val); |
| 4858 | } |
| 4859 | |
| 4860 | return SIGMA_DUT_SUCCESS_CALLER_SEND_STATUS; |
| 4861 | } |
| 4862 | |
| 4863 | |
| 4864 | static int sta_pcp_start(struct sigma_dut *dut, struct sigma_conn *conn, |
| 4865 | struct sigma_cmd *cmd) |
| 4866 | { |
| 4867 | int net_id; |
| 4868 | char *ifname; |
| 4869 | const char *val; |
| 4870 | char buf[100]; |
| 4871 | |
| 4872 | dut->mode = SIGMA_MODE_STATION; |
| 4873 | ifname = get_main_ifname(); |
| 4874 | if (wpa_command(ifname, "PING") != 0) { |
| 4875 | sigma_dut_print(dut, DUT_MSG_ERROR, "Supplicant not running"); |
| 4876 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; |
| 4877 | } |
| 4878 | |
| 4879 | wpa_command(ifname, "FLUSH"); |
| 4880 | net_id = add_network_common(dut, conn, ifname, cmd); |
| 4881 | if (net_id < 0) { |
| 4882 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add network"); |
| 4883 | return net_id; |
| 4884 | } |
| 4885 | |
| 4886 | /* TODO: mode=2 for the AP; in the future, replace for mode PCP */ |
| 4887 | if (set_network(ifname, net_id, "mode", "2") < 0) { |
| 4888 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4889 | "Failed to set supplicant network mode"); |
| 4890 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; |
| 4891 | } |
| 4892 | |
| 4893 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 4894 | "Supplicant set network with mode 2"); |
| 4895 | |
| 4896 | val = get_param(cmd, "Security"); |
| 4897 | if (val && strcasecmp(val, "OPEN") == 0) { |
| 4898 | dut->ap_key_mgmt = AP_OPEN; |
| 4899 | if (set_network(ifname, net_id, "key_mgmt", "NONE") < 0) { |
| 4900 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4901 | "Failed to set supplicant to %s security", |
| 4902 | val); |
| 4903 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; |
| 4904 | } |
| 4905 | } else if (val && strcasecmp(val, "WPA2-PSK") == 0) { |
| 4906 | dut->ap_key_mgmt = AP_WPA2_PSK; |
| 4907 | if (set_network(ifname, net_id, "key_mgmt", "WPA-PSK") < 0) { |
| 4908 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4909 | "Failed to set supplicant to %s security", |
| 4910 | val); |
| 4911 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; |
| 4912 | } |
| 4913 | |
| 4914 | if (set_network(ifname, net_id, "proto", "RSN") < 0) { |
| 4915 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4916 | "Failed to set supplicant to proto RSN"); |
| 4917 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; |
| 4918 | } |
| 4919 | } else if (val) { |
| 4920 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4921 | "Requested Security %s is not supported on 60GHz", |
| 4922 | val); |
| 4923 | return SIGMA_DUT_INVALID_CALLER_SEND_STATUS; |
| 4924 | } |
| 4925 | |
| 4926 | val = get_param(cmd, "Encrypt"); |
| 4927 | if (val && strcasecmp(val, "AES-GCMP") == 0) { |
| 4928 | if (set_network(ifname, net_id, "pairwise", "GCMP") < 0) { |
| 4929 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4930 | "Failed to set supplicant to pairwise GCMP"); |
| 4931 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; |
| 4932 | } |
| 4933 | if (set_network(ifname, net_id, "group", "GCMP") < 0) { |
| 4934 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4935 | "Failed to set supplicant to group GCMP"); |
| 4936 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; |
| 4937 | } |
| 4938 | } else if (val) { |
| 4939 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4940 | "Requested Encrypt %s is not supported on 60 GHz", |
| 4941 | val); |
| 4942 | return SIGMA_DUT_INVALID_CALLER_SEND_STATUS; |
| 4943 | } |
| 4944 | |
| 4945 | val = get_param(cmd, "PSK"); |
| 4946 | if (val && set_network_quoted(ifname, net_id, "psk", val) < 0) { |
| 4947 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set psk %s", |
| 4948 | val); |
| 4949 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; |
| 4950 | } |
| 4951 | |
| 4952 | /* Convert 60G channel to freq */ |
| 4953 | switch (dut->ap_channel) { |
| 4954 | case 1: |
| 4955 | val = "58320"; |
| 4956 | break; |
| 4957 | case 2: |
| 4958 | val = "60480"; |
| 4959 | break; |
| 4960 | case 3: |
| 4961 | val = "62640"; |
| 4962 | break; |
| 4963 | default: |
| 4964 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4965 | "Failed to configure channel %d. Not supported", |
| 4966 | dut->ap_channel); |
| 4967 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; |
| 4968 | } |
| 4969 | |
| 4970 | if (set_network(ifname, net_id, "frequency", val) < 0) { |
| 4971 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4972 | "Failed to set supplicant network frequency"); |
| 4973 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; |
| 4974 | } |
| 4975 | |
| 4976 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 4977 | "Supplicant set network with frequency"); |
| 4978 | |
| 4979 | snprintf(buf, sizeof(buf), "SELECT_NETWORK %d", net_id); |
| 4980 | if (wpa_command(ifname, buf) < 0) { |
| 4981 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 4982 | "Failed to select network id %d on %s", |
| 4983 | net_id, ifname); |
| 4984 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; |
| 4985 | } |
| 4986 | |
| 4987 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Selected network"); |
| 4988 | |
| 4989 | return SIGMA_DUT_SUCCESS_CALLER_SEND_STATUS; |
| 4990 | } |
| 4991 | |
| 4992 | |
Lior David | 67543f5 | 2017-01-03 19:04:22 +0200 | [diff] [blame] | 4993 | static int wil6210_set_abft_len(struct sigma_dut *dut, int abft_len) |
| 4994 | { |
| 4995 | char buf[128], fname[128]; |
| 4996 | FILE *f; |
| 4997 | |
| 4998 | if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) { |
| 4999 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5000 | "failed to get wil6210 debugfs dir"); |
| 5001 | return -1; |
| 5002 | } |
| 5003 | |
| 5004 | snprintf(fname, sizeof(fname), "%s/abft_len", buf); |
| 5005 | f = fopen(fname, "w"); |
| 5006 | if (!f) { |
| 5007 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5008 | "failed to open: %s", fname); |
| 5009 | return -1; |
| 5010 | } |
| 5011 | |
| 5012 | fprintf(f, "%d\n", abft_len); |
| 5013 | fclose(f); |
| 5014 | |
| 5015 | return 0; |
| 5016 | } |
| 5017 | |
| 5018 | |
| 5019 | static int sta_set_60g_abft_len(struct sigma_dut *dut, struct sigma_conn *conn, |
| 5020 | int abft_len) |
| 5021 | { |
| 5022 | switch (get_driver_type()) { |
| 5023 | case DRIVER_WIL6210: |
| 5024 | return wil6210_set_abft_len(dut, abft_len); |
| 5025 | default: |
| 5026 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5027 | "set abft_len not supported"); |
| 5028 | return -1; |
| 5029 | } |
| 5030 | } |
| 5031 | |
| 5032 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5033 | static int sta_set_60g_pcp(struct sigma_dut *dut, struct sigma_conn *conn, |
| 5034 | struct sigma_cmd *cmd) |
| 5035 | { |
| 5036 | const char *val; |
Lior David | 67543f5 | 2017-01-03 19:04:22 +0200 | [diff] [blame] | 5037 | unsigned int abft_len = 1; /* default is one slot */ |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5038 | |
| 5039 | if (dut->dev_role != DEVROLE_PCP) { |
| 5040 | send_resp(dut, conn, SIGMA_INVALID, |
| 5041 | "ErrorCode,Invalid DevRole"); |
| 5042 | return 0; |
| 5043 | } |
| 5044 | |
| 5045 | val = get_param(cmd, "SSID"); |
| 5046 | if (val) { |
| 5047 | if (strlen(val) > sizeof(dut->ap_ssid) - 1) { |
| 5048 | send_resp(dut, conn, SIGMA_INVALID, |
| 5049 | "ErrorCode,Invalid SSID"); |
| 5050 | return -1; |
| 5051 | } |
| 5052 | |
Peng Xu | b8fc5cc | 2017-05-10 17:27:28 -0700 | [diff] [blame] | 5053 | strlcpy(dut->ap_ssid, val, sizeof(dut->ap_ssid)); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5054 | } |
| 5055 | |
| 5056 | val = get_param(cmd, "CHANNEL"); |
| 5057 | if (val) { |
| 5058 | const char *pos; |
| 5059 | |
| 5060 | dut->ap_channel = atoi(val); |
| 5061 | pos = strchr(val, ';'); |
| 5062 | if (pos) { |
| 5063 | pos++; |
| 5064 | dut->ap_channel_1 = atoi(pos); |
| 5065 | } |
| 5066 | } |
| 5067 | |
| 5068 | switch (dut->ap_channel) { |
| 5069 | case 1: |
| 5070 | case 2: |
| 5071 | case 3: |
| 5072 | break; |
| 5073 | default: |
| 5074 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5075 | "Channel %d is not supported", dut->ap_channel); |
| 5076 | send_resp(dut, conn, SIGMA_ERROR, |
| 5077 | "Requested channel is not supported"); |
| 5078 | return -1; |
| 5079 | } |
| 5080 | |
| 5081 | val = get_param(cmd, "BCNINT"); |
| 5082 | if (val) |
| 5083 | dut->ap_bcnint = atoi(val); |
| 5084 | |
| 5085 | |
| 5086 | val = get_param(cmd, "ExtSchIE"); |
| 5087 | if (val) { |
| 5088 | send_resp(dut, conn, SIGMA_ERROR, |
| 5089 | "ErrorCode,ExtSchIE is not supported yet"); |
| 5090 | return -1; |
| 5091 | } |
| 5092 | |
| 5093 | val = get_param(cmd, "AllocType"); |
| 5094 | if (val) { |
| 5095 | send_resp(dut, conn, SIGMA_ERROR, |
| 5096 | "ErrorCode,AllocType is not supported yet"); |
| 5097 | return -1; |
| 5098 | } |
| 5099 | |
| 5100 | val = get_param(cmd, "PercentBI"); |
| 5101 | if (val) { |
| 5102 | send_resp(dut, conn, SIGMA_ERROR, |
| 5103 | "ErrorCode,PercentBI is not supported yet"); |
| 5104 | return -1; |
| 5105 | } |
| 5106 | |
| 5107 | val = get_param(cmd, "CBAPOnly"); |
| 5108 | if (val) { |
| 5109 | send_resp(dut, conn, SIGMA_ERROR, |
| 5110 | "ErrorCode,CBAPOnly is not supported yet"); |
| 5111 | return -1; |
| 5112 | } |
| 5113 | |
| 5114 | val = get_param(cmd, "AMPDU"); |
| 5115 | if (val) { |
| 5116 | if (strcasecmp(val, "Enable") == 0) |
| 5117 | dut->ap_ampdu = 1; |
| 5118 | else if (strcasecmp(val, "Disable") == 0) |
| 5119 | dut->ap_ampdu = 2; |
| 5120 | else { |
| 5121 | send_resp(dut, conn, SIGMA_ERROR, |
| 5122 | "ErrorCode,AMPDU value is not Enable nor Disabled"); |
| 5123 | return -1; |
| 5124 | } |
| 5125 | } |
| 5126 | |
| 5127 | val = get_param(cmd, "AMSDU"); |
| 5128 | if (val) { |
| 5129 | if (strcasecmp(val, "Enable") == 0) |
| 5130 | dut->ap_amsdu = 1; |
| 5131 | else if (strcasecmp(val, "Disable") == 0) |
| 5132 | dut->ap_amsdu = 2; |
| 5133 | } |
| 5134 | |
| 5135 | val = get_param(cmd, "NumMSDU"); |
| 5136 | if (val) { |
| 5137 | send_resp(dut, conn, SIGMA_ERROR, |
| 5138 | "ErrorCode, NumMSDU is not supported yet"); |
| 5139 | return -1; |
| 5140 | } |
| 5141 | |
| 5142 | val = get_param(cmd, "ABFTLRang"); |
| 5143 | if (val) { |
| 5144 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
Lior David | 67543f5 | 2017-01-03 19:04:22 +0200 | [diff] [blame] | 5145 | "ABFTLRang parameter %s", val); |
| 5146 | if (strcmp(val, "Gt1") == 0) |
| 5147 | abft_len = 2; /* 2 slots in this case */ |
| 5148 | } |
| 5149 | |
| 5150 | if (sta_set_60g_abft_len(dut, conn, abft_len)) { |
| 5151 | send_resp(dut, conn, SIGMA_ERROR, |
| 5152 | "ErrorCode, Can't set ABFT length"); |
| 5153 | return -1; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5154 | } |
| 5155 | |
| 5156 | if (sta_pcp_start(dut, conn, cmd) < 0) { |
| 5157 | send_resp(dut, conn, SIGMA_ERROR, |
| 5158 | "ErrorCode, Can't start PCP role"); |
| 5159 | return -1; |
| 5160 | } |
| 5161 | |
| 5162 | return sta_set_60g_common(dut, conn, cmd); |
| 5163 | } |
| 5164 | |
| 5165 | |
| 5166 | static int sta_set_60g_sta(struct sigma_dut *dut, struct sigma_conn *conn, |
| 5167 | struct sigma_cmd *cmd) |
| 5168 | { |
| 5169 | const char *val = get_param(cmd, "DiscoveryMode"); |
| 5170 | |
| 5171 | if (dut->dev_role != DEVROLE_STA) { |
| 5172 | send_resp(dut, conn, SIGMA_INVALID, |
| 5173 | "ErrorCode,Invalid DevRole"); |
| 5174 | return 0; |
| 5175 | } |
| 5176 | |
| 5177 | if (val) { |
| 5178 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Discovery: %s", val); |
| 5179 | /* Ignore Discovery mode till Driver expose API. */ |
| 5180 | #if 0 |
| 5181 | if (strcasecmp(val, "1") == 0) { |
| 5182 | send_resp(dut, conn, SIGMA_INVALID, |
| 5183 | "ErrorCode,DiscoveryMode 1 not supported"); |
| 5184 | return 0; |
| 5185 | } |
| 5186 | |
| 5187 | if (strcasecmp(val, "0") == 0) { |
| 5188 | /* OK */ |
| 5189 | } else { |
| 5190 | send_resp(dut, conn, SIGMA_INVALID, |
| 5191 | "ErrorCode,DiscoveryMode not supported"); |
| 5192 | return 0; |
| 5193 | } |
| 5194 | #endif |
| 5195 | } |
| 5196 | |
| 5197 | if (start_sta_mode(dut) != 0) |
| 5198 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; |
| 5199 | return sta_set_60g_common(dut, conn, cmd); |
| 5200 | } |
| 5201 | |
| 5202 | |
| 5203 | static int cmd_sta_disconnect(struct sigma_dut *dut, struct sigma_conn *conn, |
| 5204 | struct sigma_cmd *cmd) |
| 5205 | { |
| 5206 | const char *intf = get_param(cmd, "Interface"); |
Jouni Malinen | ed77e67 | 2018-01-10 16:45:13 +0200 | [diff] [blame] | 5207 | const char *val = get_param(cmd, "maintain_profile"); |
vamsi krishna | d605c42 | 2017-09-20 14:56:31 +0530 | [diff] [blame] | 5208 | |
Jouni Malinen | ed77e67 | 2018-01-10 16:45:13 +0200 | [diff] [blame] | 5209 | if (dut->program == PROGRAM_OCE || |
Amarnath Hullur Subramanyam | ebeda9e | 2018-01-31 03:21:48 -0800 | [diff] [blame] | 5210 | dut->program == PROGRAM_HE || |
Jouni Malinen | ed77e67 | 2018-01-10 16:45:13 +0200 | [diff] [blame] | 5211 | (val && atoi(val) == 1)) { |
vamsi krishna | d605c42 | 2017-09-20 14:56:31 +0530 | [diff] [blame] | 5212 | wpa_command(intf, "DISCONNECT"); |
| 5213 | return 1; |
| 5214 | } |
| 5215 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5216 | disconnect_station(dut); |
| 5217 | /* Try to ignore old scan results to avoid HS 2.0R2 test case failures |
| 5218 | * due to cached results. */ |
| 5219 | wpa_command(intf, "SET ignore_old_scan_res 1"); |
| 5220 | wpa_command(intf, "BSS_FLUSH"); |
| 5221 | return 1; |
| 5222 | } |
| 5223 | |
| 5224 | |
| 5225 | static int cmd_sta_reassoc(struct sigma_dut *dut, struct sigma_conn *conn, |
| 5226 | struct sigma_cmd *cmd) |
| 5227 | { |
| 5228 | const char *intf = get_param(cmd, "Interface"); |
| 5229 | const char *bssid = get_param(cmd, "bssid"); |
| 5230 | const char *val = get_param(cmd, "CHANNEL"); |
| 5231 | struct wpa_ctrl *ctrl; |
Srinivas Dasari | 0ebedb1 | 2018-02-14 17:03:51 +0530 | [diff] [blame] | 5232 | char buf[1000]; |
Sunil Dutt | d30ce09 | 2018-01-11 23:56:29 +0530 | [diff] [blame] | 5233 | char result[32]; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5234 | int res; |
| 5235 | int chan = 0; |
Ashwini Patil | 467efef | 2017-05-25 12:18:27 +0530 | [diff] [blame] | 5236 | int status = 0; |
Sunil Dutt | d30ce09 | 2018-01-11 23:56:29 +0530 | [diff] [blame] | 5237 | int fastreassoc = 1; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5238 | |
| 5239 | if (bssid == NULL) { |
| 5240 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing bssid " |
| 5241 | "argument"); |
| 5242 | return 0; |
| 5243 | } |
| 5244 | |
| 5245 | if (val) |
| 5246 | chan = atoi(val); |
| 5247 | |
| 5248 | if (wifi_chip_type != DRIVER_WCN && wifi_chip_type != DRIVER_AR6003) { |
| 5249 | /* The current network may be from sta_associate or |
| 5250 | * sta_hs2_associate |
| 5251 | */ |
| 5252 | if (set_network(intf, dut->infra_network_id, "bssid", bssid) < |
| 5253 | 0 || |
| 5254 | set_network(intf, 0, "bssid", bssid) < 0) |
| 5255 | return -2; |
| 5256 | } |
| 5257 | |
| 5258 | ctrl = open_wpa_mon(intf); |
| 5259 | if (ctrl == NULL) { |
| 5260 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open " |
| 5261 | "wpa_supplicant monitor connection"); |
| 5262 | return -1; |
| 5263 | } |
| 5264 | |
Sunil Dutt | d30ce09 | 2018-01-11 23:56:29 +0530 | [diff] [blame] | 5265 | if (get_wpa_status(get_station_ifname(), "wpa_state", result, |
| 5266 | sizeof(result)) < 0 || |
| 5267 | strncmp(result, "COMPLETED", 9) != 0) { |
| 5268 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 5269 | "sta_reassoc: Not connected"); |
| 5270 | fastreassoc = 0; |
| 5271 | } |
| 5272 | |
Srinivas Dasari | 0ebedb1 | 2018-02-14 17:03:51 +0530 | [diff] [blame] | 5273 | if (dut->rsne_override) { |
| 5274 | #ifdef NL80211_SUPPORT |
| 5275 | if (get_driver_type() == DRIVER_WCN && dut->config_rsnie == 0) { |
| 5276 | sta_config_rsnie(dut, 1); |
| 5277 | dut->config_rsnie = 1; |
| 5278 | } |
| 5279 | #endif /* NL80211_SUPPORT */ |
| 5280 | snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s", |
| 5281 | dut->rsne_override); |
| 5282 | if (wpa_command(intf, buf) < 0) { |
| 5283 | send_resp(dut, conn, SIGMA_ERROR, |
| 5284 | "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override"); |
| 5285 | return 0; |
| 5286 | } |
| 5287 | } |
| 5288 | |
Sunil Dutt | d30ce09 | 2018-01-11 23:56:29 +0530 | [diff] [blame] | 5289 | if (wifi_chip_type == DRIVER_WCN && fastreassoc) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5290 | #ifdef ANDROID |
Ashwini Patil | 4c8158f | 2017-05-25 12:49:21 +0530 | [diff] [blame] | 5291 | if (chan) { |
| 5292 | unsigned int freq; |
| 5293 | |
| 5294 | freq = channel_to_freq(chan); |
| 5295 | if (!freq) { |
| 5296 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5297 | "Invalid channel number provided: %d", |
| 5298 | chan); |
| 5299 | send_resp(dut, conn, SIGMA_INVALID, |
| 5300 | "ErrorCode,Invalid channel number"); |
| 5301 | goto close_mon_conn; |
| 5302 | } |
| 5303 | res = snprintf(buf, sizeof(buf), |
| 5304 | "SCAN TYPE=ONLY freq=%d", freq); |
| 5305 | } else { |
| 5306 | res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY"); |
| 5307 | } |
| 5308 | if (res < 0 || res >= (int) sizeof(buf)) { |
| 5309 | send_resp(dut, conn, SIGMA_ERROR, |
| 5310 | "ErrorCode,snprintf failed"); |
| 5311 | goto close_mon_conn; |
| 5312 | } |
| 5313 | if (wpa_command(intf, buf) < 0) { |
| 5314 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 5315 | "Failed to start scan"); |
| 5316 | send_resp(dut, conn, SIGMA_ERROR, |
| 5317 | "ErrorCode,scan failed"); |
| 5318 | goto close_mon_conn; |
| 5319 | } |
| 5320 | |
| 5321 | res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS", |
| 5322 | buf, sizeof(buf)); |
| 5323 | if (res < 0) { |
| 5324 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 5325 | "Scan did not complete"); |
| 5326 | send_resp(dut, conn, SIGMA_ERROR, |
| 5327 | "ErrorCode,scan did not complete"); |
| 5328 | goto close_mon_conn; |
| 5329 | } |
| 5330 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5331 | if (set_network(intf, dut->infra_network_id, "bssid", "any") |
| 5332 | < 0) { |
| 5333 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set " |
| 5334 | "bssid to any during FASTREASSOC"); |
Ashwini Patil | 467efef | 2017-05-25 12:18:27 +0530 | [diff] [blame] | 5335 | status = -2; |
| 5336 | goto close_mon_conn; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5337 | } |
| 5338 | res = snprintf(buf, sizeof(buf), "DRIVER FASTREASSOC %s %d", |
| 5339 | bssid, chan); |
| 5340 | if (res > 0 && res < (int) sizeof(buf)) |
| 5341 | res = wpa_command(intf, buf); |
| 5342 | |
| 5343 | if (res < 0 || res >= (int) sizeof(buf)) { |
| 5344 | send_resp(dut, conn, SIGMA_ERROR, |
| 5345 | "errorCode,Failed to run DRIVER FASTREASSOC"); |
Ashwini Patil | 467efef | 2017-05-25 12:18:27 +0530 | [diff] [blame] | 5346 | goto close_mon_conn; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5347 | } |
| 5348 | #else /* ANDROID */ |
| 5349 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 5350 | "Reassoc using iwpriv - skip chan=%d info", |
| 5351 | chan); |
| 5352 | snprintf(buf, sizeof(buf), "iwpriv %s reassoc", intf); |
| 5353 | if (system(buf) != 0) { |
| 5354 | sigma_dut_print(dut, DUT_MSG_ERROR, "%s failed", buf); |
Ashwini Patil | 467efef | 2017-05-25 12:18:27 +0530 | [diff] [blame] | 5355 | status = -2; |
| 5356 | goto close_mon_conn; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5357 | } |
| 5358 | #endif /* ANDROID */ |
| 5359 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 5360 | "sta_reassoc: Run %s successful", buf); |
| 5361 | } else if (wpa_command(intf, "REASSOCIATE")) { |
| 5362 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to " |
| 5363 | "request reassociation"); |
Ashwini Patil | 467efef | 2017-05-25 12:18:27 +0530 | [diff] [blame] | 5364 | goto close_mon_conn; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5365 | } |
| 5366 | |
| 5367 | res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED", |
| 5368 | buf, sizeof(buf)); |
Ashwini Patil | 467efef | 2017-05-25 12:18:27 +0530 | [diff] [blame] | 5369 | if (res < 0) { |
| 5370 | sigma_dut_print(dut, DUT_MSG_INFO, "Connection did not complete"); |
| 5371 | status = -1; |
| 5372 | goto close_mon_conn; |
| 5373 | } |
| 5374 | status = 1; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5375 | |
Ashwini Patil | 467efef | 2017-05-25 12:18:27 +0530 | [diff] [blame] | 5376 | close_mon_conn: |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5377 | wpa_ctrl_detach(ctrl); |
| 5378 | wpa_ctrl_close(ctrl); |
Ashwini Patil | 467efef | 2017-05-25 12:18:27 +0530 | [diff] [blame] | 5379 | return status; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5380 | } |
| 5381 | |
| 5382 | |
| 5383 | static void hs2_clear_credentials(const char *intf) |
| 5384 | { |
| 5385 | wpa_command(intf, "REMOVE_CRED all"); |
| 5386 | } |
| 5387 | |
| 5388 | |
Lior David | cc88b56 | 2017-01-03 18:52:09 +0200 | [diff] [blame] | 5389 | #ifdef __linux__ |
| 5390 | static int wil6210_get_aid(struct sigma_dut *dut, const char *bssid, |
| 5391 | unsigned int *aid) |
| 5392 | { |
Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 5393 | const char *pattern = "AID[ \t]+([0-9]+)"; |
Lior David | cc88b56 | 2017-01-03 18:52:09 +0200 | [diff] [blame] | 5394 | |
Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 5395 | return wil6210_get_sta_info_field(dut, bssid, pattern, aid); |
Lior David | cc88b56 | 2017-01-03 18:52:09 +0200 | [diff] [blame] | 5396 | } |
| 5397 | #endif /* __linux__ */ |
| 5398 | |
| 5399 | |
| 5400 | static int sta_get_aid_60g(struct sigma_dut *dut, const char *bssid, |
| 5401 | unsigned int *aid) |
| 5402 | { |
| 5403 | switch (get_driver_type()) { |
| 5404 | #ifdef __linux__ |
| 5405 | case DRIVER_WIL6210: |
| 5406 | return wil6210_get_aid(dut, bssid, aid); |
| 5407 | #endif /* __linux__ */ |
| 5408 | default: |
| 5409 | sigma_dut_print(dut, DUT_MSG_ERROR, "get AID not supported"); |
| 5410 | return -1; |
| 5411 | } |
| 5412 | } |
| 5413 | |
| 5414 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5415 | static int sta_get_parameter_60g(struct sigma_dut *dut, struct sigma_conn *conn, |
| 5416 | struct sigma_cmd *cmd) |
| 5417 | { |
| 5418 | char buf[MAX_CMD_LEN]; |
| 5419 | char bss_list[MAX_CMD_LEN]; |
| 5420 | const char *parameter = get_param(cmd, "Parameter"); |
| 5421 | |
| 5422 | if (parameter == NULL) |
| 5423 | return -1; |
| 5424 | |
Lior David | cc88b56 | 2017-01-03 18:52:09 +0200 | [diff] [blame] | 5425 | if (strcasecmp(parameter, "AID") == 0) { |
| 5426 | unsigned int aid = 0; |
| 5427 | char bssid[20]; |
| 5428 | |
| 5429 | if (get_wpa_status(get_station_ifname(), "bssid", |
| 5430 | bssid, sizeof(bssid)) < 0) { |
| 5431 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5432 | "could not get bssid"); |
| 5433 | return -2; |
| 5434 | } |
| 5435 | |
| 5436 | if (sta_get_aid_60g(dut, bssid, &aid)) |
| 5437 | return -2; |
| 5438 | |
| 5439 | snprintf(buf, sizeof(buf), "aid,%d", aid); |
| 5440 | sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf); |
| 5441 | send_resp(dut, conn, SIGMA_COMPLETE, buf); |
| 5442 | return 0; |
| 5443 | } |
| 5444 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5445 | if (strcasecmp(parameter, "DiscoveredDevList") == 0) { |
| 5446 | char *bss_line; |
| 5447 | char *bss_id = NULL; |
| 5448 | const char *ifname = get_param(cmd, "Interface"); |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 5449 | char *saveptr; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5450 | |
| 5451 | if (ifname == NULL) { |
| 5452 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 5453 | "For get DiscoveredDevList need Interface name."); |
| 5454 | return -1; |
| 5455 | } |
| 5456 | |
| 5457 | /* |
| 5458 | * Use "BSS RANGE=ALL MASK=0x2" which provides a list |
| 5459 | * of BSSIDs in "bssid=<BSSID>\n" |
| 5460 | */ |
| 5461 | if (wpa_command_resp(ifname, "BSS RANGE=ALL MASK=0x2", |
| 5462 | bss_list, |
| 5463 | sizeof(bss_list)) < 0) { |
| 5464 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5465 | "Failed to get bss list"); |
| 5466 | return -1; |
| 5467 | } |
| 5468 | |
| 5469 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 5470 | "bss list for ifname:%s is:%s", |
| 5471 | ifname, bss_list); |
| 5472 | |
| 5473 | snprintf(buf, sizeof(buf), "DeviceList"); |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 5474 | bss_line = strtok_r(bss_list, "\n", &saveptr); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5475 | while (bss_line) { |
| 5476 | if (sscanf(bss_line, "bssid=%ms", &bss_id) > 0 && |
| 5477 | bss_id) { |
| 5478 | int len; |
| 5479 | |
| 5480 | len = snprintf(buf + strlen(buf), |
| 5481 | sizeof(buf) - strlen(buf), |
| 5482 | ",%s", bss_id); |
| 5483 | free(bss_id); |
| 5484 | bss_id = NULL; |
| 5485 | if (len < 0) { |
| 5486 | sigma_dut_print(dut, |
| 5487 | DUT_MSG_ERROR, |
| 5488 | "Failed to read BSSID"); |
| 5489 | send_resp(dut, conn, SIGMA_ERROR, |
| 5490 | "ErrorCode,Failed to read BSS ID"); |
| 5491 | return 0; |
| 5492 | } |
| 5493 | |
| 5494 | if ((size_t) len >= sizeof(buf) - strlen(buf)) { |
| 5495 | sigma_dut_print(dut, |
| 5496 | DUT_MSG_ERROR, |
| 5497 | "Response buf too small for list"); |
| 5498 | send_resp(dut, conn, |
| 5499 | SIGMA_ERROR, |
| 5500 | "ErrorCode,Response buf too small for list"); |
| 5501 | return 0; |
| 5502 | } |
| 5503 | } |
| 5504 | |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 5505 | bss_line = strtok_r(NULL, "\n", &saveptr); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5506 | } |
| 5507 | |
| 5508 | sigma_dut_print(dut, DUT_MSG_INFO, "DiscoveredDevList is %s", |
| 5509 | buf); |
| 5510 | send_resp(dut, conn, SIGMA_COMPLETE, buf); |
| 5511 | return 0; |
| 5512 | } |
| 5513 | |
| 5514 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter"); |
| 5515 | return 0; |
| 5516 | } |
| 5517 | |
| 5518 | |
| 5519 | static int cmd_sta_get_parameter(struct sigma_dut *dut, struct sigma_conn *conn, |
| 5520 | struct sigma_cmd *cmd) |
| 5521 | { |
| 5522 | const char *program = get_param(cmd, "Program"); |
| 5523 | |
| 5524 | if (program == NULL) |
| 5525 | return -1; |
| 5526 | |
| 5527 | if (strcasecmp(program, "P2PNFC") == 0) |
| 5528 | return p2p_cmd_sta_get_parameter(dut, conn, cmd); |
| 5529 | |
| 5530 | if (strcasecmp(program, "60ghz") == 0) |
| 5531 | return sta_get_parameter_60g(dut, conn, cmd); |
| 5532 | |
| 5533 | #ifdef ANDROID_NAN |
| 5534 | if (strcasecmp(program, "NAN") == 0) |
Amarnath Hullur Subramanyam | 1854ec6 | 2016-08-11 19:29:35 -0700 | [diff] [blame] | 5535 | return nan_cmd_sta_get_parameter(dut, conn, cmd); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5536 | #endif /* ANDROID_NAN */ |
| 5537 | |
Amarnath Hullur Subramanyam | 9c381f5 | 2017-03-17 00:04:41 -0700 | [diff] [blame] | 5538 | #ifdef MIRACAST |
| 5539 | if (strcasecmp(program, "WFD") == 0 || |
| 5540 | strcasecmp(program, "DisplayR2") == 0) |
| 5541 | return miracast_cmd_sta_get_parameter(dut, conn, cmd); |
| 5542 | #endif /* MIRACAST */ |
| 5543 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5544 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter"); |
| 5545 | return 0; |
| 5546 | } |
| 5547 | |
| 5548 | |
| 5549 | static void sta_reset_default_ath(struct sigma_dut *dut, const char *intf, |
| 5550 | const char *type) |
| 5551 | { |
| 5552 | char buf[100]; |
| 5553 | |
| 5554 | if (dut->program == PROGRAM_VHT) { |
| 5555 | snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf); |
| 5556 | if (system(buf) != 0) { |
| 5557 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5558 | "iwpriv %s chwidth failed", intf); |
| 5559 | } |
| 5560 | |
| 5561 | snprintf(buf, sizeof(buf), "iwpriv %s mode 11ACVHT80", intf); |
| 5562 | if (system(buf) != 0) { |
| 5563 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5564 | "iwpriv %s mode 11ACVHT80 failed", |
| 5565 | intf); |
| 5566 | } |
| 5567 | |
| 5568 | snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs -1", intf); |
| 5569 | if (system(buf) != 0) { |
| 5570 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5571 | "iwpriv %s vhtmcs -1 failed", intf); |
| 5572 | } |
| 5573 | } |
| 5574 | |
| 5575 | if (dut->program == PROGRAM_HT) { |
| 5576 | snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf); |
| 5577 | if (system(buf) != 0) { |
| 5578 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5579 | "iwpriv %s chwidth failed", intf); |
| 5580 | } |
| 5581 | |
| 5582 | snprintf(buf, sizeof(buf), "iwpriv %s mode 11naht40", intf); |
| 5583 | if (system(buf) != 0) { |
| 5584 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5585 | "iwpriv %s mode 11naht40 failed", |
| 5586 | intf); |
| 5587 | } |
| 5588 | |
| 5589 | snprintf(buf, sizeof(buf), "iwpriv %s set11NRates 0", intf); |
| 5590 | if (system(buf) != 0) { |
| 5591 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5592 | "iwpriv set11NRates failed"); |
| 5593 | } |
| 5594 | } |
| 5595 | |
| 5596 | if (dut->program == PROGRAM_VHT || dut->program == PROGRAM_HT) { |
| 5597 | snprintf(buf, sizeof(buf), "iwpriv %s powersave 0", intf); |
| 5598 | if (system(buf) != 0) { |
| 5599 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5600 | "disabling powersave failed"); |
| 5601 | } |
| 5602 | |
| 5603 | /* Reset CTS width */ |
| 5604 | snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 54 0", |
| 5605 | intf); |
| 5606 | if (system(buf) != 0) { |
| 5607 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5608 | "wifitool %s beeliner_fw_test 54 0 failed", |
| 5609 | intf); |
| 5610 | } |
| 5611 | |
| 5612 | /* Enable Dynamic Bandwidth signalling by default */ |
| 5613 | snprintf(buf, sizeof(buf), "iwpriv %s cwmenable 1", intf); |
| 5614 | if (system(buf) != 0) { |
| 5615 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5616 | "iwpriv %s cwmenable 1 failed", intf); |
| 5617 | } |
| 5618 | |
| 5619 | snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", intf); |
| 5620 | if (system(buf) != 0) { |
| 5621 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5622 | "iwpriv rts failed"); |
| 5623 | } |
| 5624 | } |
| 5625 | |
| 5626 | if (type && strcasecmp(type, "Testbed") == 0) { |
| 5627 | dut->testbed_flag_txsp = 1; |
| 5628 | dut->testbed_flag_rxsp = 1; |
| 5629 | /* STA has to set spatial stream to 2 per Appendix H */ |
| 5630 | snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0xfff0", intf); |
| 5631 | if (system(buf) != 0) { |
| 5632 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5633 | "iwpriv vht_mcsmap failed"); |
| 5634 | } |
| 5635 | |
| 5636 | /* Disable LDPC per Appendix H */ |
| 5637 | snprintf(buf, sizeof(buf), "iwpriv %s ldpc 0", intf); |
| 5638 | if (system(buf) != 0) { |
| 5639 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5640 | "iwpriv %s ldpc 0 failed", intf); |
| 5641 | } |
| 5642 | |
| 5643 | snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf); |
| 5644 | if (system(buf) != 0) { |
| 5645 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5646 | "iwpriv amsdu failed"); |
| 5647 | } |
| 5648 | |
| 5649 | /* TODO: Disable STBC 2x1 transmit and receive */ |
| 5650 | snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc 0", intf); |
| 5651 | if (system(buf) != 0) { |
| 5652 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5653 | "Disable tx_stbc 0 failed"); |
| 5654 | } |
| 5655 | |
| 5656 | snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc 0", intf); |
| 5657 | if (system(buf) != 0) { |
| 5658 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5659 | "Disable rx_stbc 0 failed"); |
| 5660 | } |
| 5661 | |
| 5662 | /* STA has to disable Short GI per Appendix H */ |
| 5663 | snprintf(buf, sizeof(buf), "iwpriv %s shortgi 0", intf); |
| 5664 | if (system(buf) != 0) { |
| 5665 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5666 | "iwpriv %s shortgi 0 failed", intf); |
| 5667 | } |
| 5668 | } |
| 5669 | |
| 5670 | if (type && strcasecmp(type, "DUT") == 0) { |
| 5671 | snprintf(buf, sizeof(buf), "iwpriv %s nss 3", intf); |
| 5672 | if (system(buf) != 0) { |
| 5673 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5674 | "iwpriv %s nss 3 failed", intf); |
| 5675 | } |
Arif Hussain | ac6c511 | 2018-05-25 17:34:00 -0700 | [diff] [blame^] | 5676 | dut->sta_nss = 3; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5677 | |
| 5678 | snprintf(buf, sizeof(buf), "iwpriv %s shortgi 1", intf); |
| 5679 | if (system(buf) != 0) { |
| 5680 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5681 | "iwpriv %s shortgi 1 failed", intf); |
| 5682 | } |
| 5683 | } |
| 5684 | } |
| 5685 | |
| 5686 | |
Amarnath Hullur Subramanyam | 2538acc | 2018-02-02 16:15:25 -0800 | [diff] [blame] | 5687 | #ifdef NL80211_SUPPORT |
| 5688 | static int sta_set_he_mcs(struct sigma_dut *dut, const char *intf, |
| 5689 | enum he_mcs_config mcs) |
| 5690 | { |
| 5691 | struct nl_msg *msg; |
| 5692 | int ret = 0; |
| 5693 | struct nlattr *params; |
| 5694 | int ifindex; |
| 5695 | |
| 5696 | ifindex = if_nametoindex(intf); |
| 5697 | if (ifindex == 0) { |
| 5698 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5699 | "%s: Index for interface %s failed", |
| 5700 | __func__, intf); |
| 5701 | return -1; |
| 5702 | } |
| 5703 | |
| 5704 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 5705 | NL80211_CMD_VENDOR)) || |
| 5706 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 5707 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 5708 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 5709 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || |
| 5710 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 5711 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MCS, |
| 5712 | mcs)) { |
| 5713 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5714 | "%s: err in adding vendor_cmd and vendor_data", |
| 5715 | __func__); |
| 5716 | nlmsg_free(msg); |
| 5717 | return -1; |
| 5718 | } |
| 5719 | nla_nest_end(msg, params); |
| 5720 | |
| 5721 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 5722 | if (ret) { |
| 5723 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5724 | "%s: err in send_and_recv_msgs, ret=%d", |
| 5725 | __func__, ret); |
| 5726 | } |
| 5727 | return ret; |
| 5728 | } |
| 5729 | #endif /* NL80211_SUPPORT */ |
| 5730 | |
| 5731 | |
Amarnath Hullur Subramanyam | 4622a21 | 2018-02-23 12:12:14 -0800 | [diff] [blame] | 5732 | static int sta_set_heconfig_and_wep_tkip(struct sigma_dut *dut, |
| 5733 | const char *intf, int enable) |
| 5734 | { |
| 5735 | #ifdef NL80211_SUPPORT |
| 5736 | struct nl_msg *msg; |
| 5737 | int ret = 0; |
| 5738 | struct nlattr *params; |
| 5739 | int ifindex; |
| 5740 | |
| 5741 | ifindex = if_nametoindex(intf); |
| 5742 | if (ifindex == 0) { |
| 5743 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5744 | "%s: Index for interface %s failed", |
| 5745 | __func__, intf); |
| 5746 | return -1; |
| 5747 | } |
| 5748 | |
| 5749 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 5750 | NL80211_CMD_VENDOR)) || |
| 5751 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 5752 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 5753 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 5754 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || |
| 5755 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 5756 | nla_put_u8(msg, |
| 5757 | QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WEP_TKIP_IN_HE, |
| 5758 | enable)) { |
| 5759 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5760 | "%s: err in adding vendor_cmd and vendor_data", |
| 5761 | __func__); |
| 5762 | nlmsg_free(msg); |
| 5763 | return -1; |
| 5764 | } |
| 5765 | nla_nest_end(msg, params); |
| 5766 | |
| 5767 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 5768 | if (ret) { |
| 5769 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5770 | "%s: err in send_and_recv_msgs, ret=%d", |
| 5771 | __func__, ret); |
| 5772 | } |
| 5773 | return ret; |
| 5774 | #else /* NL80211_SUPPORT */ |
| 5775 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5776 | "HE config enablement cannot be changed without NL80211_SUPPORT defined"); |
| 5777 | return -1; |
| 5778 | #endif /* NL80211_SUPPORT */ |
| 5779 | } |
| 5780 | |
| 5781 | |
Amarnath Hullur Subramanyam | 13215de | 2018-02-27 14:12:55 -0800 | [diff] [blame] | 5782 | static int sta_set_addba_buf_size(struct sigma_dut *dut, |
| 5783 | const char *intf, int bufsize) |
| 5784 | { |
| 5785 | #ifdef NL80211_SUPPORT |
| 5786 | struct nl_msg *msg; |
| 5787 | int ret = 0; |
| 5788 | struct nlattr *params; |
| 5789 | int ifindex; |
| 5790 | |
| 5791 | ifindex = if_nametoindex(intf); |
| 5792 | if (ifindex == 0) { |
| 5793 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5794 | "%s: Index for interface %s failed", |
| 5795 | __func__, intf); |
| 5796 | return -1; |
| 5797 | } |
| 5798 | |
| 5799 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 5800 | NL80211_CMD_VENDOR)) || |
| 5801 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 5802 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 5803 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 5804 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || |
| 5805 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 5806 | nla_put_u8(msg, |
| 5807 | QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE, |
| 5808 | bufsize)) { |
| 5809 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5810 | "%s: err in adding vendor_cmd and vendor_data", |
| 5811 | __func__); |
| 5812 | nlmsg_free(msg); |
| 5813 | return -1; |
| 5814 | } |
| 5815 | nla_nest_end(msg, params); |
| 5816 | |
| 5817 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 5818 | if (ret) { |
| 5819 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5820 | "%s: err in send_and_recv_msgs, ret=%d", |
| 5821 | __func__, ret); |
| 5822 | } |
| 5823 | return ret; |
| 5824 | #else /* NL80211_SUPPORT */ |
| 5825 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5826 | "AddBA bufsize cannot be changed without NL80211_SUPPORT defined"); |
| 5827 | return -1; |
| 5828 | #endif /* NL80211_SUPPORT */ |
| 5829 | } |
| 5830 | |
| 5831 | |
Amarnath Hullur Subramanyam | 58f2a6e | 2018-01-31 03:36:00 -0800 | [diff] [blame] | 5832 | static void sta_reset_default_wcn(struct sigma_dut *dut, const char *intf, |
| 5833 | const char *type) |
| 5834 | { |
| 5835 | char buf[60]; |
| 5836 | |
| 5837 | if (dut->program == PROGRAM_HE) { |
| 5838 | /* resetting phymode to auto in case of HE program */ |
| 5839 | snprintf(buf, sizeof(buf), "iwpriv %s setphymode 0", intf); |
| 5840 | if (system(buf) != 0) { |
| 5841 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5842 | "iwpriv %s setphymode failed", intf); |
| 5843 | } |
| 5844 | |
Amarnath Hullur Subramanyam | 9cecb50 | 2018-04-25 13:26:30 -0700 | [diff] [blame] | 5845 | /* reset the rate to Auto rate */ |
| 5846 | snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0xff", |
| 5847 | intf); |
| 5848 | if (system(buf) != 0) { |
| 5849 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5850 | "iwpriv %s set_11ax_rate 0xff failed", |
| 5851 | intf); |
| 5852 | } |
| 5853 | |
Amarnath Hullur Subramanyam | 58f2a6e | 2018-01-31 03:36:00 -0800 | [diff] [blame] | 5854 | /* remove all network profiles */ |
| 5855 | remove_wpa_networks(intf); |
Amarnath Hullur Subramanyam | 2538acc | 2018-02-02 16:15:25 -0800 | [diff] [blame] | 5856 | |
Amarnath Hullur Subramanyam | 13215de | 2018-02-27 14:12:55 -0800 | [diff] [blame] | 5857 | /* Configure ADDBA Req/Rsp buffer size to be 64 */ |
| 5858 | sta_set_addba_buf_size(dut, intf, 64); |
| 5859 | |
Amarnath Hullur Subramanyam | 5f32d57 | 2018-03-02 00:02:33 -0800 | [diff] [blame] | 5860 | #ifdef NL80211_SUPPORT |
| 5861 | /* Disable noackpolicy for all AC */ |
| 5862 | if (nlvendor_sta_set_noack(dut, intf, 0, QCA_WLAN_AC_ALL)) { |
| 5863 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5864 | "Disable of noackpolicy for all AC failed"); |
| 5865 | } |
| 5866 | #endif /* NL80211_SUPPORT */ |
| 5867 | |
Amarnath Hullur Subramanyam | b1724a5 | 2018-03-07 14:31:46 -0800 | [diff] [blame] | 5868 | /* Enable WMM by default */ |
| 5869 | if (wcn_sta_set_wmm(dut, intf, "on")) { |
| 5870 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5871 | "Enable of WMM in sta_reset_default_wcn failed"); |
| 5872 | } |
| 5873 | |
| 5874 | /* Disable ADDBA_REJECT by default */ |
| 5875 | if (nlvendor_sta_set_addba_reject(dut, intf, 0)) { |
| 5876 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5877 | "Disable of addba_reject in sta_reset_default_wcn failed"); |
| 5878 | } |
| 5879 | |
Amarnath Hullur Subramanyam | 1f65a67 | 2018-03-07 14:50:29 -0800 | [diff] [blame] | 5880 | /* Enable sending of ADDBA by default */ |
| 5881 | if (nlvendor_config_send_addba(dut, intf, 1)) { |
| 5882 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5883 | "Enable sending of ADDBA in sta_reset_default_wcn failed"); |
| 5884 | } |
| 5885 | |
Amarnath Hullur Subramanyam | 63c590a | 2018-03-07 15:26:21 -0800 | [diff] [blame] | 5886 | /* Enable AMPDU by default */ |
| 5887 | iwpriv_sta_set_ampdu(dut, intf, 1); |
| 5888 | |
Subhani Shaik | 8e7a305 | 2018-04-24 14:03:00 -0700 | [diff] [blame] | 5889 | #ifdef NL80211_SUPPORT |
| 5890 | if (sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_AUTO)) { |
| 5891 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5892 | "Set LTF config to default in sta_reset_default_wcn failed"); |
| 5893 | } |
| 5894 | #endif /* NL80211_SUPPORT */ |
| 5895 | |
Amarnath Hullur Subramanyam | 2538acc | 2018-02-02 16:15:25 -0800 | [diff] [blame] | 5896 | /* Set nss to 1 and MCS 0-7 in case of testbed */ |
| 5897 | if (type && strcasecmp(type, "Testbed") == 0) { |
| 5898 | #ifdef NL80211_SUPPORT |
| 5899 | int ret; |
| 5900 | #endif /* NL80211_SUPPORT */ |
| 5901 | |
| 5902 | snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf); |
| 5903 | if (system(buf) != 0) { |
| 5904 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5905 | "iwpriv %s nss failed", intf); |
| 5906 | } |
| 5907 | |
| 5908 | #ifdef NL80211_SUPPORT |
| 5909 | ret = sta_set_he_mcs(dut, intf, HE_80_MCS0_7); |
| 5910 | if (ret) { |
| 5911 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5912 | "Setting of MCS failed, ret:%d", |
| 5913 | ret); |
| 5914 | } |
| 5915 | #endif /* NL80211_SUPPORT */ |
Amarnath Hullur Subramanyam | c67621d | 2018-02-04 23:18:01 -0800 | [diff] [blame] | 5916 | |
| 5917 | /* Disable STBC as default */ |
| 5918 | wcn_sta_set_stbc(dut, intf, "0"); |
Amarnath Hullur Subramanyam | d5bb573 | 2018-02-22 15:50:38 -0800 | [diff] [blame] | 5919 | |
| 5920 | /* Disable AMSDU as default */ |
| 5921 | iwpriv_sta_set_amsdu(dut, intf, "0"); |
Amarnath Hullur Subramanyam | 474a17d | 2018-02-22 18:45:54 -0800 | [diff] [blame] | 5922 | |
| 5923 | #ifdef NL80211_SUPPORT |
| 5924 | /* HE fragmentation default off */ |
| 5925 | if (sta_set_he_fragmentation(dut, intf, |
| 5926 | HE_FRAG_DISABLE)) { |
| 5927 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5928 | "Setting of HE fragmentation failed"); |
| 5929 | } |
| 5930 | #endif /* NL80211_SUPPORT */ |
Amarnath Hullur Subramanyam | 4622a21 | 2018-02-23 12:12:14 -0800 | [diff] [blame] | 5931 | |
| 5932 | /* Enable WEP/TKIP with HE capability in testbed */ |
| 5933 | if (sta_set_heconfig_and_wep_tkip(dut, intf, 1)) { |
| 5934 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5935 | "Enabling HE config with WEP/TKIP failed"); |
| 5936 | } |
Amarnath Hullur Subramanyam | 2538acc | 2018-02-02 16:15:25 -0800 | [diff] [blame] | 5937 | } |
Amarnath Hullur Subramanyam | 0acce2c | 2018-03-06 06:05:17 -0800 | [diff] [blame] | 5938 | |
| 5939 | /* Defaults in case of DUT */ |
| 5940 | if (type && strcasecmp(type, "DUT") == 0) { |
Arif Hussain | d48fcc7 | 2018-05-01 18:34:18 -0700 | [diff] [blame] | 5941 | /* Enable STBC by default */ |
| 5942 | wcn_sta_set_stbc(dut, intf, "1"); |
| 5943 | |
Amarnath Hullur Subramanyam | 0acce2c | 2018-03-06 06:05:17 -0800 | [diff] [blame] | 5944 | /* set nss to 2 */ |
| 5945 | snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf); |
| 5946 | if (system(buf) != 0) { |
| 5947 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5948 | "iwpriv %s nss 2 failed", intf); |
| 5949 | } |
Arif Hussain | ac6c511 | 2018-05-25 17:34:00 -0700 | [diff] [blame^] | 5950 | dut->sta_nss = 2; |
Amarnath Hullur Subramanyam | 0acce2c | 2018-03-06 06:05:17 -0800 | [diff] [blame] | 5951 | |
| 5952 | #ifdef NL80211_SUPPORT |
Arif Hussain | ae23984 | 2018-05-01 18:20:05 -0700 | [diff] [blame] | 5953 | /* Set HE_MCS to 0-11 */ |
| 5954 | if (sta_set_he_mcs(dut, intf, HE_80_MCS0_11)) { |
Amarnath Hullur Subramanyam | 0acce2c | 2018-03-06 06:05:17 -0800 | [diff] [blame] | 5955 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5956 | "Setting of MCS failed"); |
| 5957 | } |
| 5958 | #endif /* NL80211_SUPPORT */ |
| 5959 | |
| 5960 | /* Disable WEP/TKIP with HE capability in DUT */ |
| 5961 | if (sta_set_heconfig_and_wep_tkip(dut, intf, 0)) { |
| 5962 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5963 | "Enabling HE config with WEP/TKIP failed"); |
| 5964 | } |
| 5965 | } |
Amarnath Hullur Subramanyam | 58f2a6e | 2018-01-31 03:36:00 -0800 | [diff] [blame] | 5966 | } |
| 5967 | } |
| 5968 | |
| 5969 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5970 | static int cmd_sta_reset_default(struct sigma_dut *dut, |
| 5971 | struct sigma_conn *conn, |
| 5972 | struct sigma_cmd *cmd) |
| 5973 | { |
| 5974 | int cmd_sta_p2p_reset(struct sigma_dut *dut, struct sigma_conn *conn, |
| 5975 | struct sigma_cmd *cmd); |
| 5976 | const char *intf = get_param(cmd, "Interface"); |
| 5977 | const char *type; |
Amarnath Hullur Subramanyam | 9c381f5 | 2017-03-17 00:04:41 -0700 | [diff] [blame] | 5978 | const char *program = get_param(cmd, "program"); |
Ankita Bajaj | 0d5825b | 2017-10-25 16:20:17 +0530 | [diff] [blame] | 5979 | const char *dev_role = get_param(cmd, "DevRole"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5980 | |
Amarnath Hullur Subramanyam | 9c381f5 | 2017-03-17 00:04:41 -0700 | [diff] [blame] | 5981 | if (!program) |
| 5982 | program = get_param(cmd, "prog"); |
| 5983 | dut->program = sigma_program_to_enum(program); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5984 | dut->device_type = STA_unknown; |
| 5985 | type = get_param(cmd, "type"); |
| 5986 | if (type && strcasecmp(type, "Testbed") == 0) |
| 5987 | dut->device_type = STA_testbed; |
| 5988 | if (type && strcasecmp(type, "DUT") == 0) |
| 5989 | dut->device_type = STA_dut; |
| 5990 | |
| 5991 | if (dut->program == PROGRAM_TDLS) { |
| 5992 | /* Clear TDLS testing mode */ |
| 5993 | wpa_command(intf, "SET tdls_disabled 0"); |
| 5994 | wpa_command(intf, "SET tdls_testing 0"); |
| 5995 | dut->no_tpk_expiration = 0; |
Pradeep Reddy POTTETI | 8ce2a23 | 2016-10-28 12:17:32 +0530 | [diff] [blame] | 5996 | if (get_driver_type() == DRIVER_WCN) { |
| 5997 | /* Enable the WCN driver in TDLS Explicit trigger mode |
| 5998 | */ |
| 5999 | wpa_command(intf, "SET tdls_external_control 0"); |
| 6000 | wpa_command(intf, "SET tdls_trigger_control 0"); |
| 6001 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6002 | } |
| 6003 | |
Amarnath Hullur Subramanyam | 9c381f5 | 2017-03-17 00:04:41 -0700 | [diff] [blame] | 6004 | #ifdef MIRACAST |
| 6005 | if (dut->program == PROGRAM_WFD || |
| 6006 | dut->program == PROGRAM_DISPLAYR2) |
| 6007 | miracast_sta_reset_default(dut, conn, cmd); |
| 6008 | #endif /* MIRACAST */ |
| 6009 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6010 | switch (get_driver_type()) { |
| 6011 | case DRIVER_ATHEROS: |
| 6012 | sta_reset_default_ath(dut, intf, type); |
| 6013 | break; |
Amarnath Hullur Subramanyam | 58f2a6e | 2018-01-31 03:36:00 -0800 | [diff] [blame] | 6014 | case DRIVER_WCN: |
| 6015 | sta_reset_default_wcn(dut, intf, type); |
| 6016 | break; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6017 | default: |
| 6018 | break; |
| 6019 | } |
| 6020 | |
| 6021 | #ifdef ANDROID_NAN |
| 6022 | if (dut->program == PROGRAM_NAN) |
| 6023 | nan_cmd_sta_reset_default(dut, conn, cmd); |
| 6024 | #endif /* ANDROID_NAN */ |
| 6025 | |
| 6026 | if (dut->program == PROGRAM_HS2_R2) { |
| 6027 | unlink("SP/wi-fi.org/pps.xml"); |
| 6028 | if (system("rm -r SP/*") != 0) { |
| 6029 | } |
| 6030 | unlink("next-client-cert.pem"); |
| 6031 | unlink("next-client-key.pem"); |
| 6032 | } |
| 6033 | |
| 6034 | if (dut->program == PROGRAM_60GHZ) { |
| 6035 | const char *dev_role = get_param(cmd, "DevRole"); |
| 6036 | |
| 6037 | if (!dev_role) { |
| 6038 | send_resp(dut, conn, SIGMA_ERROR, |
| 6039 | "errorCode,Missing DevRole argument"); |
| 6040 | return 0; |
| 6041 | } |
| 6042 | |
| 6043 | if (strcasecmp(dev_role, "STA") == 0) |
| 6044 | dut->dev_role = DEVROLE_STA; |
| 6045 | else if (strcasecmp(dev_role, "PCP") == 0) |
| 6046 | dut->dev_role = DEVROLE_PCP; |
| 6047 | else { |
| 6048 | send_resp(dut, conn, SIGMA_ERROR, |
| 6049 | "errorCode,Unknown DevRole"); |
| 6050 | return 0; |
| 6051 | } |
| 6052 | |
| 6053 | if (dut->device_type == STA_unknown) { |
| 6054 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6055 | "Device type is not STA testbed or DUT"); |
| 6056 | send_resp(dut, conn, SIGMA_ERROR, |
| 6057 | "errorCode,Unknown device type"); |
| 6058 | return 0; |
| 6059 | } |
| 6060 | } |
| 6061 | |
| 6062 | wpa_command(intf, "WPS_ER_STOP"); |
| 6063 | wpa_command(intf, "FLUSH"); |
vamsi krishna | f39bc1e | 2017-08-23 17:37:53 +0530 | [diff] [blame] | 6064 | wpa_command(intf, "ERP_FLUSH"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6065 | wpa_command(intf, "SET radio_disabled 0"); |
| 6066 | |
| 6067 | if (dut->tmp_mac_addr && dut->set_macaddr) { |
| 6068 | dut->tmp_mac_addr = 0; |
| 6069 | if (system(dut->set_macaddr) != 0) { |
| 6070 | sigma_dut_print(dut, DUT_MSG_INFO, "Failed to clear " |
| 6071 | "temporary MAC address"); |
| 6072 | } |
| 6073 | } |
| 6074 | |
| 6075 | set_ps(intf, dut, 0); |
| 6076 | |
| 6077 | if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2) { |
| 6078 | wpa_command(intf, "SET interworking 1"); |
| 6079 | wpa_command(intf, "SET hs20 1"); |
| 6080 | } |
| 6081 | |
Deepak Dhamdhere | 0fe0e45 | 2017-12-18 14:52:09 -0800 | [diff] [blame] | 6082 | if (dut->program == PROGRAM_HS2_R2 || |
| 6083 | dut->program == PROGRAM_OCE) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6084 | wpa_command(intf, "SET pmf 1"); |
| 6085 | } else { |
| 6086 | wpa_command(intf, "SET pmf 0"); |
| 6087 | } |
| 6088 | |
| 6089 | hs2_clear_credentials(intf); |
| 6090 | wpa_command(intf, "SET hessid 00:00:00:00:00:00"); |
| 6091 | wpa_command(intf, "SET access_network_type 15"); |
| 6092 | |
| 6093 | static_ip_file(0, NULL, NULL, NULL); |
| 6094 | kill_dhcp_client(dut, intf); |
| 6095 | clear_ip_addr(dut, intf); |
| 6096 | |
| 6097 | dut->er_oper_performed = 0; |
| 6098 | dut->er_oper_bssid[0] = '\0'; |
| 6099 | |
priyadharshini gowthaman | ad6cbba | 2016-10-04 10:39:58 -0700 | [diff] [blame] | 6100 | if (dut->program == PROGRAM_LOC) { |
| 6101 | /* Disable Interworking by default */ |
| 6102 | wpa_command(get_station_ifname(), "SET interworking 0"); |
| 6103 | } |
| 6104 | |
Ashwini Patil | 0040258 | 2017-04-13 12:29:39 +0530 | [diff] [blame] | 6105 | if (dut->program == PROGRAM_MBO) { |
| 6106 | free(dut->non_pref_ch_list); |
| 6107 | dut->non_pref_ch_list = NULL; |
Ashwini Patil | 5acd738 | 2017-04-13 15:55:04 +0530 | [diff] [blame] | 6108 | free(dut->btm_query_cand_list); |
| 6109 | dut->btm_query_cand_list = NULL; |
Ashwini Patil | c63161e | 2017-04-13 16:30:23 +0530 | [diff] [blame] | 6110 | wpa_command(intf, "SET reject_btm_req_reason 0"); |
Ashwini Patil | a75de5a | 2017-04-13 16:35:05 +0530 | [diff] [blame] | 6111 | wpa_command(intf, "SET ignore_assoc_disallow 0"); |
Ashwini Patil | d174f2c | 2017-04-13 16:49:46 +0530 | [diff] [blame] | 6112 | wpa_command(intf, "SET gas_address3 0"); |
Ashwini Patil | 9183fdb | 2017-04-13 16:58:25 +0530 | [diff] [blame] | 6113 | wpa_command(intf, "SET roaming 1"); |
Ashwini Patil | 0040258 | 2017-04-13 12:29:39 +0530 | [diff] [blame] | 6114 | } |
| 6115 | |
Jouni Malinen | 3c367e8 | 2017-06-23 17:01:47 +0300 | [diff] [blame] | 6116 | free(dut->rsne_override); |
| 6117 | dut->rsne_override = NULL; |
| 6118 | |
Jouni Malinen | 6814313 | 2017-09-02 02:34:08 +0300 | [diff] [blame] | 6119 | free(dut->sae_commit_override); |
| 6120 | dut->sae_commit_override = NULL; |
| 6121 | |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 6122 | dut->dpp_conf_id = -1; |
Jouni Malinen | b1dd21f | 2017-11-13 19:14:29 +0200 | [diff] [blame] | 6123 | free(dut->dpp_peer_uri); |
| 6124 | dut->dpp_peer_uri = NULL; |
Jouni Malinen | 63d5041 | 2017-11-24 11:55:38 +0200 | [diff] [blame] | 6125 | dut->dpp_local_bootstrap = -1; |
Jouni Malinen | 5011fb5 | 2017-12-05 21:00:15 +0200 | [diff] [blame] | 6126 | wpa_command(intf, "SET dpp_config_processing 2"); |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 6127 | |
Jouni Malinen | fac9cad | 2017-10-10 18:35:55 +0300 | [diff] [blame] | 6128 | wpa_command(intf, "VENDOR_ELEM_REMOVE 13 *"); |
| 6129 | |
vamsi krishna | a279949 | 2017-12-05 14:28:01 +0530 | [diff] [blame] | 6130 | if (dut->program == PROGRAM_OCE) { |
Ankita Bajaj | a2cb567 | 2017-10-25 16:08:28 +0530 | [diff] [blame] | 6131 | wpa_command(intf, "SET oce 1"); |
vamsi krishna | a279949 | 2017-12-05 14:28:01 +0530 | [diff] [blame] | 6132 | wpa_command(intf, "SET disable_fils 0"); |
Ankita Bajaj | 1bde794 | 2018-01-09 19:15:01 +0530 | [diff] [blame] | 6133 | wpa_command(intf, "FILS_HLP_REQ_FLUSH"); |
| 6134 | dut->fils_hlp = 0; |
| 6135 | #ifdef ANDROID |
| 6136 | hlp_thread_cleanup(dut); |
| 6137 | #endif /* ANDROID */ |
vamsi krishna | a279949 | 2017-12-05 14:28:01 +0530 | [diff] [blame] | 6138 | } |
Ankita Bajaj | a2cb567 | 2017-10-25 16:08:28 +0530 | [diff] [blame] | 6139 | |
Sunil Dutt | 076081f | 2018-02-05 19:45:50 +0530 | [diff] [blame] | 6140 | #ifdef NL80211_SUPPORT |
Sunil Dutt | 4459508 | 2018-02-12 19:41:45 +0530 | [diff] [blame] | 6141 | if (get_driver_type() == DRIVER_WCN && |
| 6142 | dut->config_rsnie == 1) { |
| 6143 | dut->config_rsnie = 0; |
| 6144 | sta_config_rsnie(dut, 0); |
Sunil Dutt | 076081f | 2018-02-05 19:45:50 +0530 | [diff] [blame] | 6145 | } |
| 6146 | #endif /* NL80211_SUPPORT */ |
| 6147 | |
Sunil Dutt | febf8a8 | 2018-02-09 18:50:13 +0530 | [diff] [blame] | 6148 | if (dev_role && strcasecmp(dev_role, "STA-CFON") == 0) { |
| 6149 | dut->dev_role = DEVROLE_STA_CFON; |
| 6150 | return sta_cfon_reset_default(dut, conn, cmd); |
| 6151 | } |
| 6152 | |
| 6153 | if (dut->program != PROGRAM_VHT) |
| 6154 | return cmd_sta_p2p_reset(dut, conn, cmd); |
| 6155 | |
Priyadharshini Gowthaman | a7dfd49 | 2015-11-09 14:34:08 -0800 | [diff] [blame] | 6156 | return 1; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6157 | } |
| 6158 | |
| 6159 | |
| 6160 | static int cmd_sta_get_events(struct sigma_dut *dut, struct sigma_conn *conn, |
| 6161 | struct sigma_cmd *cmd) |
| 6162 | { |
| 6163 | const char *program = get_param(cmd, "Program"); |
| 6164 | |
| 6165 | if (program == NULL) |
| 6166 | return -1; |
| 6167 | #ifdef ANDROID_NAN |
| 6168 | if (strcasecmp(program, "NAN") == 0) |
| 6169 | return nan_cmd_sta_get_events(dut, conn, cmd); |
| 6170 | #endif /* ANDROID_NAN */ |
| 6171 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter"); |
| 6172 | return 0; |
| 6173 | } |
| 6174 | |
| 6175 | |
Jouni Malinen | 8290520 | 2018-04-29 17:20:10 +0300 | [diff] [blame] | 6176 | static int sta_exec_action_url(struct sigma_dut *dut, struct sigma_conn *conn, |
| 6177 | struct sigma_cmd *cmd) |
| 6178 | { |
| 6179 | const char *url = get_param(cmd, "url"); |
| 6180 | const char *method = get_param(cmd, "method"); |
| 6181 | pid_t pid; |
| 6182 | int status; |
| 6183 | |
| 6184 | if (!url || !method) |
| 6185 | return -1; |
| 6186 | |
| 6187 | /* TODO: Add support for method,post */ |
| 6188 | if (strcasecmp(method, "get") != 0) { |
| 6189 | send_resp(dut, conn, SIGMA_ERROR, |
| 6190 | "ErrorCode,Unsupported method"); |
| 6191 | return 0; |
| 6192 | } |
| 6193 | |
| 6194 | pid = fork(); |
| 6195 | if (pid < 0) { |
| 6196 | perror("fork"); |
| 6197 | return -1; |
| 6198 | } |
| 6199 | |
| 6200 | if (pid == 0) { |
| 6201 | char * argv[5] = { "wget", "-O", "/dev/null", |
| 6202 | (char *) url, NULL }; |
| 6203 | |
| 6204 | execv("/usr/bin/wget", argv); |
| 6205 | perror("execv"); |
| 6206 | exit(0); |
| 6207 | return -1; |
| 6208 | } |
| 6209 | |
| 6210 | if (waitpid(pid, &status, 0) < 0) { |
| 6211 | perror("waitpid"); |
| 6212 | return -1; |
| 6213 | } |
| 6214 | |
| 6215 | if (WIFEXITED(status)) { |
| 6216 | const char *errmsg; |
| 6217 | |
| 6218 | if (WEXITSTATUS(status) == 0) |
| 6219 | return 1; |
| 6220 | sigma_dut_print(dut, DUT_MSG_INFO, "wget exit status %d", |
| 6221 | WEXITSTATUS(status)); |
| 6222 | switch (WEXITSTATUS(status)) { |
| 6223 | case 4: |
| 6224 | errmsg = "errmsg,Network failure"; |
| 6225 | break; |
| 6226 | case 8: |
| 6227 | errmsg = "errmsg,Server issued an error response"; |
| 6228 | break; |
| 6229 | default: |
| 6230 | errmsg = "errmsg,Unknown failure from wget"; |
| 6231 | break; |
| 6232 | } |
| 6233 | send_resp(dut, conn, SIGMA_ERROR, errmsg); |
| 6234 | return 0; |
| 6235 | } |
| 6236 | |
| 6237 | send_resp(dut, conn, SIGMA_ERROR, "errmsg,Unknown failure"); |
| 6238 | return 0; |
| 6239 | } |
| 6240 | |
| 6241 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6242 | static int cmd_sta_exec_action(struct sigma_dut *dut, struct sigma_conn *conn, |
| 6243 | struct sigma_cmd *cmd) |
| 6244 | { |
| 6245 | const char *program = get_param(cmd, "Prog"); |
| 6246 | |
Jouni Malinen | 8290520 | 2018-04-29 17:20:10 +0300 | [diff] [blame] | 6247 | if (program && !get_param(cmd, "interface")) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6248 | return -1; |
| 6249 | #ifdef ANDROID_NAN |
Jouni Malinen | 8290520 | 2018-04-29 17:20:10 +0300 | [diff] [blame] | 6250 | if (program && strcasecmp(program, "NAN") == 0) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6251 | return nan_cmd_sta_exec_action(dut, conn, cmd); |
| 6252 | #endif /* ANDROID_NAN */ |
Jouni Malinen | 8290520 | 2018-04-29 17:20:10 +0300 | [diff] [blame] | 6253 | |
| 6254 | if (program && strcasecmp(program, "Loc") == 0) |
priyadharshini gowthaman | d66913a | 2016-07-29 15:11:17 -0700 | [diff] [blame] | 6255 | return loc_cmd_sta_exec_action(dut, conn, cmd); |
Jouni Malinen | 8290520 | 2018-04-29 17:20:10 +0300 | [diff] [blame] | 6256 | |
| 6257 | if (get_param(cmd, "url")) |
| 6258 | return sta_exec_action_url(dut, conn, cmd); |
| 6259 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6260 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter"); |
| 6261 | return 0; |
| 6262 | } |
| 6263 | |
| 6264 | |
| 6265 | static int cmd_sta_set_11n(struct sigma_dut *dut, struct sigma_conn *conn, |
| 6266 | struct sigma_cmd *cmd) |
| 6267 | { |
| 6268 | const char *intf = get_param(cmd, "Interface"); |
| 6269 | const char *val, *mcs32, *rate; |
| 6270 | |
| 6271 | val = get_param(cmd, "GREENFIELD"); |
| 6272 | if (val) { |
| 6273 | if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) { |
| 6274 | /* Enable GD */ |
| 6275 | send_resp(dut, conn, SIGMA_ERROR, |
| 6276 | "ErrorCode,GF not supported"); |
| 6277 | return 0; |
| 6278 | } |
| 6279 | } |
| 6280 | |
| 6281 | val = get_param(cmd, "SGI20"); |
| 6282 | if (val) { |
| 6283 | switch (get_driver_type()) { |
| 6284 | case DRIVER_ATHEROS: |
| 6285 | ath_sta_set_sgi(dut, intf, val); |
| 6286 | break; |
| 6287 | default: |
| 6288 | send_resp(dut, conn, SIGMA_ERROR, |
| 6289 | "ErrorCode,SGI20 not supported"); |
| 6290 | return 0; |
| 6291 | } |
| 6292 | } |
| 6293 | |
| 6294 | mcs32 = get_param(cmd, "MCS32"); /* HT Duplicate Mode Enable/Disable */ |
| 6295 | rate = get_param(cmd, "MCS_FIXEDRATE"); /* Fixed MCS rate (0..31) */ |
| 6296 | if (mcs32 && rate) { |
| 6297 | /* TODO */ |
| 6298 | send_resp(dut, conn, SIGMA_ERROR, |
| 6299 | "ErrorCode,MCS32,MCS_FIXEDRATE not supported"); |
| 6300 | return 0; |
| 6301 | } else if (mcs32 && !rate) { |
| 6302 | /* TODO */ |
| 6303 | send_resp(dut, conn, SIGMA_ERROR, |
| 6304 | "ErrorCode,MCS32 not supported"); |
| 6305 | return 0; |
| 6306 | } else if (!mcs32 && rate) { |
| 6307 | switch (get_driver_type()) { |
| 6308 | case DRIVER_ATHEROS: |
priyadharshini gowthaman | e5e2517 | 2015-12-08 14:53:48 -0800 | [diff] [blame] | 6309 | novap_reset(dut, intf); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6310 | ath_sta_set_11nrates(dut, intf, rate); |
| 6311 | break; |
| 6312 | default: |
| 6313 | send_resp(dut, conn, SIGMA_ERROR, |
| 6314 | "ErrorCode,MCS32_FIXEDRATE not supported"); |
| 6315 | return 0; |
| 6316 | } |
| 6317 | } |
| 6318 | |
| 6319 | return cmd_sta_set_wireless_common(intf, dut, conn, cmd); |
| 6320 | } |
| 6321 | |
| 6322 | |
| 6323 | static int cmd_sta_set_wireless_vht(struct sigma_dut *dut, |
| 6324 | struct sigma_conn *conn, |
| 6325 | struct sigma_cmd *cmd) |
| 6326 | { |
| 6327 | const char *intf = get_param(cmd, "Interface"); |
| 6328 | const char *val; |
| 6329 | char buf[30]; |
| 6330 | int tkip = -1; |
| 6331 | int wep = -1; |
| 6332 | |
| 6333 | val = get_param(cmd, "SGI80"); |
| 6334 | if (val) { |
| 6335 | int sgi80; |
| 6336 | |
| 6337 | sgi80 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0; |
| 6338 | snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d", intf, sgi80); |
| 6339 | if (system(buf) != 0) { |
| 6340 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6341 | "iwpriv shortgi failed"); |
| 6342 | } |
| 6343 | } |
| 6344 | |
| 6345 | val = get_param(cmd, "TxBF"); |
| 6346 | if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) { |
| 6347 | snprintf(buf, sizeof(buf), "iwpriv %s vhtsubfee 1", intf); |
| 6348 | if (system(buf) != 0) { |
| 6349 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6350 | "iwpriv vhtsubfee failed"); |
| 6351 | } |
| 6352 | snprintf(buf, sizeof(buf), "iwpriv %s vhtsubfer 1", intf); |
| 6353 | if (system(buf) != 0) { |
| 6354 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6355 | "iwpriv vhtsubfer failed"); |
| 6356 | } |
| 6357 | } |
| 6358 | |
| 6359 | val = get_param(cmd, "MU_TxBF"); |
| 6360 | if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) { |
| 6361 | switch (get_driver_type()) { |
| 6362 | case DRIVER_ATHEROS: |
| 6363 | ath_sta_set_txsp_stream(dut, intf, "1SS"); |
| 6364 | ath_sta_set_rxsp_stream(dut, intf, "1SS"); |
| 6365 | case DRIVER_WCN: |
| 6366 | if (wcn_sta_set_sp_stream(dut, intf, "1SS") < 0) { |
| 6367 | send_resp(dut, conn, SIGMA_ERROR, |
| 6368 | "ErrorCode,Failed to set RX/TXSP_STREAM"); |
| 6369 | return 0; |
| 6370 | } |
| 6371 | default: |
| 6372 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6373 | "Setting SP_STREAM not supported"); |
| 6374 | break; |
| 6375 | } |
| 6376 | snprintf(buf, sizeof(buf), "iwpriv %s vhtmubfee 1", intf); |
| 6377 | if (system(buf) != 0) { |
| 6378 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6379 | "iwpriv vhtmubfee failed"); |
| 6380 | } |
| 6381 | snprintf(buf, sizeof(buf), "iwpriv %s vhtmubfer 1", intf); |
| 6382 | if (system(buf) != 0) { |
| 6383 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6384 | "iwpriv vhtmubfer failed"); |
| 6385 | } |
| 6386 | } |
| 6387 | |
| 6388 | val = get_param(cmd, "LDPC"); |
| 6389 | if (val) { |
| 6390 | int ldpc; |
| 6391 | |
| 6392 | ldpc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0; |
| 6393 | snprintf(buf, sizeof(buf), "iwpriv %s ldpc %d", intf, ldpc); |
| 6394 | if (system(buf) != 0) { |
| 6395 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6396 | "iwpriv ldpc failed"); |
| 6397 | } |
| 6398 | } |
| 6399 | |
Amarnath Hullur Subramanyam | 7bae60e | 2018-01-31 03:46:50 -0800 | [diff] [blame] | 6400 | val = get_param(cmd, "BCC"); |
| 6401 | if (val) { |
| 6402 | int bcc; |
| 6403 | |
| 6404 | bcc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0; |
| 6405 | /* use LDPC iwpriv itself to set bcc coding, bcc coding |
| 6406 | * is mutually exclusive to bcc */ |
| 6407 | snprintf(buf, sizeof(buf), "iwpriv %s ldpc %d", intf, !bcc); |
| 6408 | if (system(buf) != 0) { |
| 6409 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6410 | "Enabling/Disabling of BCC failed"); |
| 6411 | } |
| 6412 | } |
| 6413 | |
Arif Hussain | ac6c511 | 2018-05-25 17:34:00 -0700 | [diff] [blame^] | 6414 | val = get_param(cmd, "MCS_FixedRate"); |
| 6415 | if (val) { |
| 6416 | #ifdef NL80211_SUPPORT |
| 6417 | int mcs, ratecode = 0; |
| 6418 | enum he_mcs_config mcs_config; |
| 6419 | int ret; |
| 6420 | |
| 6421 | ratecode = (0x07 & dut->sta_nss) << 5; |
| 6422 | mcs = atoi(val); |
| 6423 | /* Add the MCS to the ratecode */ |
| 6424 | if (mcs >= 0 && mcs <= 11) { |
| 6425 | ratecode += mcs; |
| 6426 | if (dut->device_type == STA_testbed && |
| 6427 | mcs > 7 && mcs <= 11) { |
| 6428 | if (mcs <= 9) |
| 6429 | mcs_config = HE_80_MCS0_9; |
| 6430 | else |
| 6431 | mcs_config = HE_80_MCS0_11; |
| 6432 | ret = sta_set_he_mcs(dut, intf, mcs_config); |
| 6433 | if (ret) { |
| 6434 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6435 | "MCS_FixedRate: mcs setting failed, mcs:%d, mcs_config %d, ret:%d", |
| 6436 | mcs, mcs_config, ret); |
| 6437 | } |
| 6438 | } |
| 6439 | snprintf(buf, sizeof(buf), |
| 6440 | "iwpriv %s set_11ax_rate 0x%03x", |
| 6441 | intf, ratecode); |
| 6442 | if (system(buf) != 0) { |
| 6443 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6444 | "MCS_FixedRate: iwpriv setting of 11ax rates 0x%03x failed", |
| 6445 | ratecode); |
| 6446 | } |
| 6447 | } else { |
| 6448 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6449 | "MCS_FixedRate: HE MCS %d not supported", |
| 6450 | mcs); |
| 6451 | } |
| 6452 | #else /* NL80211_SUPPORT */ |
| 6453 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6454 | "MCS_FixedRate cannot be changed without NL80211_SUPPORT defined"); |
| 6455 | #endif /* NL80211_SUPPORT */ |
| 6456 | } |
| 6457 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6458 | val = get_param(cmd, "opt_md_notif_ie"); |
| 6459 | if (val) { |
| 6460 | char *result = NULL; |
| 6461 | char delim[] = ";"; |
| 6462 | char token[30]; |
| 6463 | int value, config_val = 0; |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 6464 | char *saveptr; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6465 | |
Peng Xu | b8fc5cc | 2017-05-10 17:27:28 -0700 | [diff] [blame] | 6466 | strlcpy(token, val, sizeof(token)); |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 6467 | result = strtok_r(token, delim, &saveptr); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6468 | |
| 6469 | /* Extract the NSS information */ |
| 6470 | if (result) { |
| 6471 | value = atoi(result); |
| 6472 | switch (value) { |
| 6473 | case 1: |
| 6474 | config_val = 1; |
| 6475 | break; |
| 6476 | case 2: |
| 6477 | config_val = 3; |
| 6478 | break; |
| 6479 | case 3: |
| 6480 | config_val = 7; |
| 6481 | break; |
| 6482 | case 4: |
| 6483 | config_val = 15; |
| 6484 | break; |
| 6485 | default: |
| 6486 | config_val = 3; |
| 6487 | break; |
| 6488 | } |
| 6489 | |
| 6490 | snprintf(buf, sizeof(buf), "iwpriv %s rxchainmask %d", |
| 6491 | intf, config_val); |
| 6492 | if (system(buf) != 0) { |
| 6493 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6494 | "iwpriv rxchainmask failed"); |
| 6495 | } |
| 6496 | |
| 6497 | snprintf(buf, sizeof(buf), "iwpriv %s txchainmask %d", |
| 6498 | intf, config_val); |
| 6499 | if (system(buf) != 0) { |
| 6500 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6501 | "iwpriv txchainmask failed"); |
| 6502 | } |
| 6503 | } |
| 6504 | |
| 6505 | /* Extract the channel width information */ |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 6506 | result = strtok_r(NULL, delim, &saveptr); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6507 | if (result) { |
| 6508 | value = atoi(result); |
| 6509 | switch (value) { |
| 6510 | case 20: |
| 6511 | config_val = 0; |
| 6512 | break; |
| 6513 | case 40: |
| 6514 | config_val = 1; |
| 6515 | break; |
| 6516 | case 80: |
| 6517 | config_val = 2; |
| 6518 | break; |
| 6519 | case 160: |
| 6520 | config_val = 3; |
| 6521 | break; |
| 6522 | default: |
| 6523 | config_val = 2; |
| 6524 | break; |
| 6525 | } |
| 6526 | |
| 6527 | dut->chwidth = config_val; |
| 6528 | |
| 6529 | snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d", |
| 6530 | intf, config_val); |
| 6531 | if (system(buf) != 0) { |
| 6532 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6533 | "iwpriv chwidth failed"); |
| 6534 | } |
| 6535 | } |
| 6536 | |
| 6537 | snprintf(buf, sizeof(buf), "iwpriv %s opmode_notify 1", intf); |
| 6538 | if (system(buf) != 0) { |
| 6539 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6540 | "iwpriv opmode_notify failed"); |
| 6541 | } |
| 6542 | } |
| 6543 | |
| 6544 | val = get_param(cmd, "nss_mcs_cap"); |
| 6545 | if (val) { |
| 6546 | int nss, mcs; |
| 6547 | char token[20]; |
| 6548 | char *result = NULL; |
| 6549 | unsigned int vht_mcsmap = 0; |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 6550 | char *saveptr; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6551 | |
Peng Xu | b8fc5cc | 2017-05-10 17:27:28 -0700 | [diff] [blame] | 6552 | strlcpy(token, val, sizeof(token)); |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 6553 | result = strtok_r(token, ";", &saveptr); |
Pradeep Reddy POTTETI | cd649a2 | 2016-01-29 12:55:59 +0530 | [diff] [blame] | 6554 | if (!result) { |
| 6555 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6556 | "VHT NSS not specified"); |
| 6557 | return 0; |
| 6558 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6559 | nss = atoi(result); |
| 6560 | |
| 6561 | snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss); |
| 6562 | if (system(buf) != 0) { |
| 6563 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6564 | "iwpriv nss failed"); |
| 6565 | } |
Arif Hussain | ac6c511 | 2018-05-25 17:34:00 -0700 | [diff] [blame^] | 6566 | dut->sta_nss = nss; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6567 | |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 6568 | result = strtok_r(NULL, ";", &saveptr); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6569 | if (result == NULL) { |
| 6570 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6571 | "VHTMCS NOT SPECIFIED!"); |
| 6572 | return 0; |
| 6573 | } |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 6574 | result = strtok_r(result, "-", &saveptr); |
| 6575 | result = strtok_r(NULL, "-", &saveptr); |
Pradeep Reddy POTTETI | cd649a2 | 2016-01-29 12:55:59 +0530 | [diff] [blame] | 6576 | if (!result) { |
| 6577 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6578 | "VHT MCS not specified"); |
| 6579 | return 0; |
| 6580 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6581 | mcs = atoi(result); |
| 6582 | |
| 6583 | snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs %d", intf, mcs); |
| 6584 | if (system(buf) != 0) { |
| 6585 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6586 | "iwpriv mcs failed"); |
| 6587 | } |
| 6588 | |
| 6589 | switch (nss) { |
| 6590 | case 1: |
| 6591 | switch (mcs) { |
| 6592 | case 7: |
| 6593 | vht_mcsmap = 0xfffc; |
| 6594 | break; |
| 6595 | case 8: |
| 6596 | vht_mcsmap = 0xfffd; |
| 6597 | break; |
| 6598 | case 9: |
| 6599 | vht_mcsmap = 0xfffe; |
| 6600 | break; |
| 6601 | default: |
| 6602 | vht_mcsmap = 0xfffe; |
| 6603 | break; |
| 6604 | } |
| 6605 | break; |
| 6606 | case 2: |
| 6607 | switch (mcs) { |
| 6608 | case 7: |
| 6609 | vht_mcsmap = 0xfff0; |
| 6610 | break; |
| 6611 | case 8: |
| 6612 | vht_mcsmap = 0xfff5; |
| 6613 | break; |
| 6614 | case 9: |
| 6615 | vht_mcsmap = 0xfffa; |
| 6616 | break; |
| 6617 | default: |
| 6618 | vht_mcsmap = 0xfffa; |
| 6619 | break; |
| 6620 | } |
| 6621 | break; |
| 6622 | case 3: |
| 6623 | switch (mcs) { |
| 6624 | case 7: |
| 6625 | vht_mcsmap = 0xffc0; |
| 6626 | break; |
| 6627 | case 8: |
| 6628 | vht_mcsmap = 0xffd5; |
| 6629 | break; |
| 6630 | case 9: |
| 6631 | vht_mcsmap = 0xffea; |
| 6632 | break; |
| 6633 | default: |
| 6634 | vht_mcsmap = 0xffea; |
| 6635 | break; |
| 6636 | } |
| 6637 | break; |
| 6638 | default: |
| 6639 | vht_mcsmap = 0xffea; |
| 6640 | break; |
| 6641 | } |
| 6642 | snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0x%04x", |
| 6643 | intf, vht_mcsmap); |
| 6644 | if (system(buf) != 0) { |
| 6645 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6646 | "iwpriv vht_mcsmap failed"); |
| 6647 | } |
| 6648 | } |
| 6649 | |
| 6650 | /* UNSUPPORTED: val = get_param(cmd, "Tx_lgi_rate"); */ |
| 6651 | |
| 6652 | val = get_param(cmd, "Vht_tkip"); |
| 6653 | if (val) |
| 6654 | tkip = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0; |
| 6655 | |
| 6656 | val = get_param(cmd, "Vht_wep"); |
| 6657 | if (val) |
| 6658 | wep = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0; |
| 6659 | |
| 6660 | if (tkip != -1 || wep != -1) { |
| 6661 | if ((tkip == 1 && wep != 0) || (wep == 1 && tkip != 0)) { |
| 6662 | snprintf(buf, sizeof(buf), "iwpriv %s htweptkip 1", |
| 6663 | intf); |
| 6664 | } else if ((tkip == 0 && wep != 1) || (wep == 0 && tkip != 1)) { |
| 6665 | snprintf(buf, sizeof(buf), "iwpriv %s htweptkip 0", |
| 6666 | intf); |
| 6667 | } else { |
| 6668 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6669 | "ErrorCode,mixed mode of VHT TKIP/WEP not supported"); |
| 6670 | return 0; |
| 6671 | } |
| 6672 | |
| 6673 | if (system(buf) != 0) { |
| 6674 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6675 | "iwpriv htweptkip failed"); |
| 6676 | } |
| 6677 | } |
| 6678 | |
| 6679 | val = get_param(cmd, "txBandwidth"); |
| 6680 | if (val) { |
| 6681 | switch (get_driver_type()) { |
Amarnath Hullur Subramanyam | 4f86029 | 2018-01-31 03:49:35 -0800 | [diff] [blame] | 6682 | case DRIVER_WCN: |
| 6683 | if (wcn_sta_set_width(dut, intf, val) < 0) { |
| 6684 | send_resp(dut, conn, SIGMA_ERROR, |
| 6685 | "ErrorCode,Failed to set txBandwidth"); |
| 6686 | return 0; |
| 6687 | } |
| 6688 | break; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6689 | case DRIVER_ATHEROS: |
| 6690 | if (ath_set_width(dut, conn, intf, val) < 0) { |
| 6691 | send_resp(dut, conn, SIGMA_ERROR, |
| 6692 | "ErrorCode,Failed to set txBandwidth"); |
| 6693 | return 0; |
| 6694 | } |
| 6695 | break; |
| 6696 | default: |
| 6697 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6698 | "Setting txBandwidth not supported"); |
| 6699 | break; |
| 6700 | } |
| 6701 | } |
| 6702 | |
| 6703 | return cmd_sta_set_wireless_common(intf, dut, conn, cmd); |
| 6704 | } |
| 6705 | |
| 6706 | |
| 6707 | static int sta_set_wireless_60g(struct sigma_dut *dut, |
| 6708 | struct sigma_conn *conn, |
| 6709 | struct sigma_cmd *cmd) |
| 6710 | { |
| 6711 | const char *dev_role = get_param(cmd, "DevRole"); |
| 6712 | |
| 6713 | if (!dev_role) { |
| 6714 | send_resp(dut, conn, SIGMA_INVALID, |
| 6715 | "ErrorCode,DevRole not specified"); |
| 6716 | return 0; |
| 6717 | } |
| 6718 | |
| 6719 | if (strcasecmp(dev_role, "PCP") == 0) |
| 6720 | return sta_set_60g_pcp(dut, conn, cmd); |
| 6721 | if (strcasecmp(dev_role, "STA") == 0) |
| 6722 | return sta_set_60g_sta(dut, conn, cmd); |
| 6723 | send_resp(dut, conn, SIGMA_INVALID, |
| 6724 | "ErrorCode,DevRole not supported"); |
| 6725 | return 0; |
| 6726 | } |
| 6727 | |
| 6728 | |
Ankita Bajaj | 0d5825b | 2017-10-25 16:20:17 +0530 | [diff] [blame] | 6729 | static int sta_set_wireless_oce(struct sigma_dut *dut, struct sigma_conn *conn, |
| 6730 | struct sigma_cmd *cmd) |
| 6731 | { |
| 6732 | int status; |
| 6733 | const char *intf = get_param(cmd, "Interface"); |
| 6734 | const char *val = get_param(cmd, "DevRole"); |
| 6735 | |
| 6736 | if (val && strcasecmp(val, "STA-CFON") == 0) { |
| 6737 | status = sta_cfon_set_wireless(dut, conn, cmd); |
| 6738 | if (status) |
| 6739 | return status; |
| 6740 | } |
| 6741 | return cmd_sta_set_wireless_common(intf, dut, conn, cmd); |
| 6742 | } |
| 6743 | |
| 6744 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6745 | static int cmd_sta_set_wireless(struct sigma_dut *dut, struct sigma_conn *conn, |
| 6746 | struct sigma_cmd *cmd) |
| 6747 | { |
| 6748 | const char *val; |
| 6749 | |
| 6750 | val = get_param(cmd, "Program"); |
| 6751 | if (val) { |
| 6752 | if (strcasecmp(val, "11n") == 0) |
| 6753 | return cmd_sta_set_11n(dut, conn, cmd); |
Amarnath Hullur Subramanyam | 4f86029 | 2018-01-31 03:49:35 -0800 | [diff] [blame] | 6754 | if (strcasecmp(val, "VHT") == 0 || strcasecmp(val, "HE") == 0) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6755 | return cmd_sta_set_wireless_vht(dut, conn, cmd); |
| 6756 | if (strcasecmp(val, "60ghz") == 0) |
| 6757 | return sta_set_wireless_60g(dut, conn, cmd); |
Ankita Bajaj | 0d5825b | 2017-10-25 16:20:17 +0530 | [diff] [blame] | 6758 | if (strcasecmp(val, "OCE") == 0) |
| 6759 | return sta_set_wireless_oce(dut, conn, cmd); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6760 | send_resp(dut, conn, SIGMA_ERROR, |
| 6761 | "ErrorCode,Program value not supported"); |
| 6762 | } else { |
| 6763 | send_resp(dut, conn, SIGMA_ERROR, |
| 6764 | "ErrorCode,Program argument not available"); |
| 6765 | } |
| 6766 | |
| 6767 | return 0; |
| 6768 | } |
| 6769 | |
| 6770 | |
| 6771 | static void ath_sta_inject_frame(struct sigma_dut *dut, const char *intf, |
| 6772 | int tid) |
| 6773 | { |
| 6774 | char buf[100]; |
| 6775 | int tid_to_dscp [] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 }; |
| 6776 | |
Pradeep Reddy POTTETI | d31d132 | 2016-10-13 17:22:03 +0530 | [diff] [blame] | 6777 | if (tid < 0 || |
| 6778 | tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) { |
| 6779 | sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid); |
| 6780 | return; |
| 6781 | } |
| 6782 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6783 | /* |
| 6784 | * Two ways to ensure that addba request with a |
| 6785 | * non zero TID could be sent out. EV 117296 |
| 6786 | */ |
| 6787 | snprintf(buf, sizeof(buf), |
| 6788 | "ping -c 8 -Q %d `arp -a | grep wlan0 | awk '{print $2}' | tr -d '()'`", |
| 6789 | tid); |
| 6790 | if (system(buf) != 0) { |
| 6791 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6792 | "Ping did not send out"); |
| 6793 | } |
| 6794 | |
| 6795 | snprintf(buf, sizeof(buf), |
| 6796 | "iwconfig %s | grep Access | awk '{print $6}' > %s", |
| 6797 | intf, VI_QOS_TMP_FILE); |
| 6798 | if (system(buf) != 0) |
| 6799 | return; |
| 6800 | |
| 6801 | snprintf(buf, sizeof(buf), |
| 6802 | "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s", |
| 6803 | intf, VI_QOS_TMP_FILE); |
| 6804 | if (system(buf) != 0) |
| 6805 | sigma_dut_print(dut, DUT_MSG_ERROR, "HWaddr matching failed"); |
| 6806 | |
| 6807 | snprintf(buf,sizeof(buf), "sed -n '3,$p' %s >> %s", |
| 6808 | VI_QOS_REFFILE, VI_QOS_TMP_FILE); |
| 6809 | if (system(buf) != 0) { |
| 6810 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6811 | "VI_QOS_TEMP_FILE generation error failed"); |
| 6812 | } |
| 6813 | snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s", |
| 6814 | tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE); |
| 6815 | if (system(buf) != 0) { |
| 6816 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6817 | "VI_QOS_FILE generation failed"); |
| 6818 | } |
| 6819 | |
| 6820 | snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s", |
| 6821 | tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE); |
| 6822 | if (system(buf) != 0) { |
| 6823 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6824 | "VI_QOS_FILE generation failed"); |
| 6825 | } |
| 6826 | |
| 6827 | snprintf(buf, sizeof(buf), "ethinject %s %s", intf, VI_QOS_FILE); |
| 6828 | if (system(buf) != 0) { |
| 6829 | } |
| 6830 | } |
| 6831 | |
| 6832 | |
| 6833 | static int ath_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn, |
| 6834 | struct sigma_cmd *cmd) |
| 6835 | { |
| 6836 | const char *intf = get_param(cmd, "Interface"); |
| 6837 | const char *val; |
| 6838 | int tid = 0; |
| 6839 | char buf[100]; |
| 6840 | |
| 6841 | val = get_param(cmd, "TID"); |
| 6842 | if (val) { |
| 6843 | tid = atoi(val); |
| 6844 | if (tid) |
| 6845 | ath_sta_inject_frame(dut, intf, tid); |
| 6846 | } |
| 6847 | |
| 6848 | /* Command sequence for ADDBA request on Peregrine based devices */ |
| 6849 | snprintf(buf, sizeof(buf), "iwpriv %s setaddbaoper 1", intf); |
| 6850 | if (system(buf) != 0) { |
| 6851 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6852 | "iwpriv setaddbaoper failed"); |
| 6853 | } |
| 6854 | |
| 6855 | snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4", intf, tid); |
| 6856 | if (system(buf) != 0) { |
| 6857 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6858 | "wifitool senddelba failed"); |
| 6859 | } |
| 6860 | |
| 6861 | snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64", intf, tid); |
| 6862 | if (system(buf) != 0) { |
| 6863 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6864 | "wifitool sendaddba failed"); |
| 6865 | } |
| 6866 | |
| 6867 | /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */ |
| 6868 | |
| 6869 | return 1; |
| 6870 | } |
| 6871 | |
| 6872 | |
Lior David | 9981b51 | 2017-01-20 13:16:40 +0200 | [diff] [blame] | 6873 | #ifdef __linux__ |
| 6874 | |
| 6875 | static int wil6210_send_addba(struct sigma_dut *dut, const char *dest_mac, |
| 6876 | int agg_size) |
| 6877 | { |
| 6878 | char dir[128], buf[128]; |
| 6879 | FILE *f; |
| 6880 | regex_t re; |
| 6881 | regmatch_t m[2]; |
| 6882 | int rc, ret = -1, vring_id, found; |
| 6883 | |
| 6884 | if (wil6210_get_debugfs_dir(dut, dir, sizeof(dir))) { |
| 6885 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6886 | "failed to get wil6210 debugfs dir"); |
| 6887 | return -1; |
| 6888 | } |
| 6889 | |
| 6890 | snprintf(buf, sizeof(buf), "%s/vrings", dir); |
| 6891 | f = fopen(buf, "r"); |
| 6892 | if (!f) { |
| 6893 | sigma_dut_print(dut, DUT_MSG_ERROR, "failed to open: %s", buf); |
| 6894 | return -1; |
| 6895 | } |
| 6896 | |
| 6897 | if (regcomp(&re, "VRING tx_[ \t]*([0-9]+)", REG_EXTENDED)) { |
| 6898 | sigma_dut_print(dut, DUT_MSG_ERROR, "regcomp failed"); |
| 6899 | goto out; |
| 6900 | } |
| 6901 | |
| 6902 | /* find TX VRING for the mac address */ |
| 6903 | found = 0; |
| 6904 | while (fgets(buf, sizeof(buf), f)) { |
| 6905 | if (strcasestr(buf, dest_mac)) { |
| 6906 | found = 1; |
| 6907 | break; |
| 6908 | } |
| 6909 | } |
| 6910 | |
| 6911 | if (!found) { |
| 6912 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6913 | "no TX VRING for %s", dest_mac); |
| 6914 | goto out; |
| 6915 | } |
| 6916 | |
| 6917 | /* extract VRING ID, "VRING tx_<id> = {" */ |
| 6918 | if (!fgets(buf, sizeof(buf), f)) { |
| 6919 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6920 | "no VRING start line for %s", dest_mac); |
| 6921 | goto out; |
| 6922 | } |
| 6923 | |
| 6924 | rc = regexec(&re, buf, 2, m, 0); |
| 6925 | regfree(&re); |
| 6926 | if (rc || m[1].rm_so < 0) { |
| 6927 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6928 | "no VRING TX ID for %s", dest_mac); |
| 6929 | goto out; |
| 6930 | } |
| 6931 | buf[m[1].rm_eo] = 0; |
| 6932 | vring_id = atoi(&buf[m[1].rm_so]); |
| 6933 | |
| 6934 | /* send the addba command */ |
| 6935 | fclose(f); |
| 6936 | snprintf(buf, sizeof(buf), "%s/back", dir); |
| 6937 | f = fopen(buf, "w"); |
| 6938 | if (!f) { |
| 6939 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6940 | "failed to open: %s", buf); |
| 6941 | return -1; |
| 6942 | } |
| 6943 | |
| 6944 | fprintf(f, "add %d %d\n", vring_id, agg_size); |
| 6945 | |
| 6946 | ret = 0; |
| 6947 | |
| 6948 | out: |
| 6949 | fclose(f); |
| 6950 | |
| 6951 | return ret; |
| 6952 | } |
| 6953 | |
| 6954 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6955 | static int send_addba_60g(struct sigma_dut *dut, struct sigma_conn *conn, |
| 6956 | struct sigma_cmd *cmd) |
| 6957 | { |
| 6958 | const char *val; |
| 6959 | int tid = 0; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6960 | |
| 6961 | val = get_param(cmd, "TID"); |
| 6962 | if (val) { |
| 6963 | tid = atoi(val); |
| 6964 | if (tid != 0) { |
| 6965 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6966 | "Ignore TID %d for send_addba use TID 0 for 60g since only 0 required on TX", |
| 6967 | tid); |
| 6968 | } |
| 6969 | } |
| 6970 | |
| 6971 | val = get_param(cmd, "Dest_mac"); |
| 6972 | if (!val) { |
| 6973 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6974 | "Currently not supporting addba for 60G without Dest_mac"); |
| 6975 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; |
| 6976 | } |
| 6977 | |
Lior David | 9981b51 | 2017-01-20 13:16:40 +0200 | [diff] [blame] | 6978 | if (wil6210_send_addba(dut, val, dut->back_rcv_buf)) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6979 | return -1; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6980 | |
| 6981 | return 1; |
| 6982 | } |
| 6983 | |
Lior David | 9981b51 | 2017-01-20 13:16:40 +0200 | [diff] [blame] | 6984 | #endif /* __linux__ */ |
| 6985 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6986 | |
Amarnath Hullur Subramanyam | a72c016 | 2018-02-27 14:49:09 -0800 | [diff] [blame] | 6987 | static int wcn_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn, |
| 6988 | struct sigma_cmd *cmd) |
| 6989 | { |
| 6990 | #ifdef NL80211_SUPPORT |
| 6991 | const char *intf = get_param(cmd, "Interface"); |
| 6992 | const char *val; |
| 6993 | int tid = -1; |
| 6994 | int bufsize = 64; |
| 6995 | struct nl_msg *msg; |
| 6996 | int ret = 0; |
| 6997 | struct nlattr *params; |
| 6998 | int ifindex; |
| 6999 | |
| 7000 | val = get_param(cmd, "TID"); |
| 7001 | if (val) |
| 7002 | tid = atoi(val); |
| 7003 | |
| 7004 | if (tid == -1) { |
| 7005 | send_resp(dut, conn, SIGMA_ERROR, |
| 7006 | "ErrorCode,sta_send_addba tid invalid"); |
| 7007 | return 0; |
| 7008 | } |
| 7009 | |
| 7010 | /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */ |
| 7011 | |
| 7012 | ifindex = if_nametoindex(intf); |
| 7013 | if (ifindex == 0) { |
| 7014 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7015 | "%s: Index for interface %s failed", |
| 7016 | __func__, intf); |
| 7017 | send_resp(dut, conn, SIGMA_ERROR, |
| 7018 | "ErrorCode,sta_send_addba interface invalid"); |
| 7019 | return 0; |
| 7020 | } |
| 7021 | |
| 7022 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 7023 | NL80211_CMD_VENDOR)) || |
| 7024 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 7025 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 7026 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 7027 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || |
| 7028 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 7029 | nla_put_u8(msg, |
| 7030 | QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADD_DEL_BA_SESSION, |
| 7031 | QCA_WLAN_ADD_BA) || |
| 7032 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BA_TID, |
| 7033 | tid) || |
| 7034 | nla_put_u8(msg, |
| 7035 | QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE, |
| 7036 | bufsize)) { |
| 7037 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7038 | "%s: err in adding vendor_cmd and vendor_data", |
| 7039 | __func__); |
| 7040 | nlmsg_free(msg); |
| 7041 | send_resp(dut, conn, SIGMA_ERROR, |
| 7042 | "ErrorCode,sta_send_addba err in adding vendor_cmd and vendor_data"); |
| 7043 | return 0; |
| 7044 | } |
| 7045 | nla_nest_end(msg, params); |
| 7046 | |
| 7047 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 7048 | if (ret) { |
| 7049 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7050 | "%s: err in send_and_recv_msgs, ret=%d", |
| 7051 | __func__, ret); |
Sunil Dutt | 3060559 | 2018-05-04 20:35:50 +0530 | [diff] [blame] | 7052 | if (ret == -EOPNOTSUPP) |
| 7053 | return 1; |
Amarnath Hullur Subramanyam | a72c016 | 2018-02-27 14:49:09 -0800 | [diff] [blame] | 7054 | send_resp(dut, conn, SIGMA_ERROR, |
| 7055 | "ErrorCode,sta_send_addba err in send_and_recv_msgs"); |
| 7056 | return 0; |
| 7057 | } |
Amarnath Hullur Subramanyam | a72c016 | 2018-02-27 14:49:09 -0800 | [diff] [blame] | 7058 | #else /* NL80211_SUPPORT */ |
| 7059 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7060 | "sta_send_addba not supported without NL80211_SUPPORT defined"); |
Amarnath Hullur Subramanyam | a72c016 | 2018-02-27 14:49:09 -0800 | [diff] [blame] | 7061 | #endif /* NL80211_SUPPORT */ |
Sunil Dutt | 3060559 | 2018-05-04 20:35:50 +0530 | [diff] [blame] | 7062 | |
| 7063 | return 1; |
Amarnath Hullur Subramanyam | a72c016 | 2018-02-27 14:49:09 -0800 | [diff] [blame] | 7064 | } |
| 7065 | |
| 7066 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7067 | static int cmd_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn, |
| 7068 | struct sigma_cmd *cmd) |
| 7069 | { |
| 7070 | switch (get_driver_type()) { |
| 7071 | case DRIVER_ATHEROS: |
| 7072 | return ath_sta_send_addba(dut, conn, cmd); |
Amarnath Hullur Subramanyam | a72c016 | 2018-02-27 14:49:09 -0800 | [diff] [blame] | 7073 | case DRIVER_WCN: |
| 7074 | return wcn_sta_send_addba(dut, conn, cmd); |
Lior David | 9981b51 | 2017-01-20 13:16:40 +0200 | [diff] [blame] | 7075 | #ifdef __linux__ |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7076 | case DRIVER_WIL6210: |
| 7077 | return send_addba_60g(dut, conn, cmd); |
Lior David | 9981b51 | 2017-01-20 13:16:40 +0200 | [diff] [blame] | 7078 | #endif /* __linux__ */ |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7079 | default: |
| 7080 | /* |
| 7081 | * There is no driver specific implementation for other drivers. |
| 7082 | * Ignore the command and report COMPLETE since the following |
| 7083 | * throughput test operation will end up sending ADDBA anyway. |
| 7084 | */ |
| 7085 | return 1; |
| 7086 | } |
| 7087 | } |
| 7088 | |
| 7089 | |
| 7090 | int inject_eth_frame(int s, const void *data, size_t len, |
| 7091 | unsigned short ethtype, char *dst, char *src) |
| 7092 | { |
| 7093 | struct iovec iov[4] = { |
| 7094 | { |
| 7095 | .iov_base = dst, |
| 7096 | .iov_len = ETH_ALEN, |
| 7097 | }, |
| 7098 | { |
| 7099 | .iov_base = src, |
| 7100 | .iov_len = ETH_ALEN, |
| 7101 | }, |
| 7102 | { |
| 7103 | .iov_base = ðtype, |
| 7104 | .iov_len = sizeof(unsigned short), |
| 7105 | }, |
| 7106 | { |
| 7107 | .iov_base = (void *) data, |
| 7108 | .iov_len = len, |
| 7109 | } |
| 7110 | }; |
| 7111 | struct msghdr msg = { |
| 7112 | .msg_name = NULL, |
| 7113 | .msg_namelen = 0, |
| 7114 | .msg_iov = iov, |
| 7115 | .msg_iovlen = 4, |
| 7116 | .msg_control = NULL, |
| 7117 | .msg_controllen = 0, |
| 7118 | .msg_flags = 0, |
| 7119 | }; |
| 7120 | |
| 7121 | return sendmsg(s, &msg, 0); |
| 7122 | } |
| 7123 | |
| 7124 | #if defined(__linux__) || defined(__QNXNTO__) |
| 7125 | |
| 7126 | int inject_frame(int s, const void *data, size_t len, int encrypt) |
| 7127 | { |
| 7128 | #define IEEE80211_RADIOTAP_F_WEP 0x04 |
| 7129 | #define IEEE80211_RADIOTAP_F_FRAG 0x08 |
| 7130 | unsigned char rtap_hdr[] = { |
| 7131 | 0x00, 0x00, /* radiotap version */ |
| 7132 | 0x0e, 0x00, /* radiotap length */ |
| 7133 | 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */ |
| 7134 | IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */ |
| 7135 | 0x00, /* padding */ |
| 7136 | 0x00, 0x00, /* RX and TX flags to indicate that */ |
| 7137 | 0x00, 0x00, /* this is the injected frame directly */ |
| 7138 | }; |
| 7139 | struct iovec iov[2] = { |
| 7140 | { |
| 7141 | .iov_base = &rtap_hdr, |
| 7142 | .iov_len = sizeof(rtap_hdr), |
| 7143 | }, |
| 7144 | { |
| 7145 | .iov_base = (void *) data, |
| 7146 | .iov_len = len, |
| 7147 | } |
| 7148 | }; |
| 7149 | struct msghdr msg = { |
| 7150 | .msg_name = NULL, |
| 7151 | .msg_namelen = 0, |
| 7152 | .msg_iov = iov, |
| 7153 | .msg_iovlen = 2, |
| 7154 | .msg_control = NULL, |
| 7155 | .msg_controllen = 0, |
| 7156 | .msg_flags = 0, |
| 7157 | }; |
| 7158 | |
| 7159 | if (encrypt) |
| 7160 | rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP; |
| 7161 | |
| 7162 | return sendmsg(s, &msg, 0); |
| 7163 | } |
| 7164 | |
| 7165 | |
| 7166 | int open_monitor(const char *ifname) |
| 7167 | { |
| 7168 | #ifdef __QNXNTO__ |
| 7169 | struct sockaddr_dl ll; |
| 7170 | int s; |
| 7171 | |
| 7172 | memset(&ll, 0, sizeof(ll)); |
| 7173 | ll.sdl_family = AF_LINK; |
| 7174 | ll.sdl_index = if_nametoindex(ifname); |
| 7175 | if (ll.sdl_index == 0) { |
| 7176 | perror("if_nametoindex"); |
| 7177 | return -1; |
| 7178 | } |
| 7179 | s = socket(PF_INET, SOCK_RAW, 0); |
| 7180 | #else /* __QNXNTO__ */ |
| 7181 | struct sockaddr_ll ll; |
| 7182 | int s; |
| 7183 | |
| 7184 | memset(&ll, 0, sizeof(ll)); |
| 7185 | ll.sll_family = AF_PACKET; |
| 7186 | ll.sll_ifindex = if_nametoindex(ifname); |
| 7187 | if (ll.sll_ifindex == 0) { |
| 7188 | perror("if_nametoindex"); |
| 7189 | return -1; |
| 7190 | } |
| 7191 | s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); |
| 7192 | #endif /* __QNXNTO__ */ |
| 7193 | if (s < 0) { |
| 7194 | perror("socket[PF_PACKET,SOCK_RAW]"); |
| 7195 | return -1; |
| 7196 | } |
| 7197 | |
| 7198 | if (bind(s, (struct sockaddr *) &ll, sizeof(ll)) < 0) { |
| 7199 | perror("monitor socket bind"); |
| 7200 | close(s); |
| 7201 | return -1; |
| 7202 | } |
| 7203 | |
| 7204 | return s; |
| 7205 | } |
| 7206 | |
| 7207 | |
| 7208 | static int hex2num(char c) |
| 7209 | { |
| 7210 | if (c >= '0' && c <= '9') |
| 7211 | return c - '0'; |
| 7212 | if (c >= 'a' && c <= 'f') |
| 7213 | return c - 'a' + 10; |
| 7214 | if (c >= 'A' && c <= 'F') |
| 7215 | return c - 'A' + 10; |
| 7216 | return -1; |
| 7217 | } |
| 7218 | |
| 7219 | |
| 7220 | int hwaddr_aton(const char *txt, unsigned char *addr) |
| 7221 | { |
| 7222 | int i; |
| 7223 | |
| 7224 | for (i = 0; i < 6; i++) { |
| 7225 | int a, b; |
| 7226 | |
| 7227 | a = hex2num(*txt++); |
| 7228 | if (a < 0) |
| 7229 | return -1; |
| 7230 | b = hex2num(*txt++); |
| 7231 | if (b < 0) |
| 7232 | return -1; |
| 7233 | *addr++ = (a << 4) | b; |
| 7234 | if (i < 5 && *txt++ != ':') |
| 7235 | return -1; |
| 7236 | } |
| 7237 | |
| 7238 | return 0; |
| 7239 | } |
| 7240 | |
| 7241 | #endif /* defined(__linux__) || defined(__QNXNTO__) */ |
| 7242 | |
| 7243 | enum send_frame_type { |
| 7244 | DISASSOC, DEAUTH, SAQUERY, AUTH, ASSOCREQ, REASSOCREQ, DLS_REQ |
| 7245 | }; |
| 7246 | enum send_frame_protection { |
| 7247 | CORRECT_KEY, INCORRECT_KEY, UNPROTECTED |
| 7248 | }; |
| 7249 | |
| 7250 | |
| 7251 | static int sta_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn, |
| 7252 | enum send_frame_type frame, |
| 7253 | enum send_frame_protection protected, |
| 7254 | const char *dest) |
| 7255 | { |
| 7256 | #ifdef __linux__ |
| 7257 | unsigned char buf[1000], *pos; |
| 7258 | int s, res; |
| 7259 | char bssid[20], addr[20]; |
| 7260 | char result[32], ssid[100]; |
| 7261 | size_t ssid_len; |
| 7262 | |
| 7263 | if (get_wpa_status(get_station_ifname(), "wpa_state", result, |
| 7264 | sizeof(result)) < 0 || |
| 7265 | strncmp(result, "COMPLETED", 9) != 0) { |
| 7266 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Not connected"); |
| 7267 | return 0; |
| 7268 | } |
| 7269 | |
| 7270 | if (get_wpa_status(get_station_ifname(), "bssid", bssid, sizeof(bssid)) |
| 7271 | < 0) { |
| 7272 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get " |
| 7273 | "current BSSID"); |
| 7274 | return 0; |
| 7275 | } |
| 7276 | |
| 7277 | if (get_wpa_status(get_station_ifname(), "address", addr, sizeof(addr)) |
| 7278 | < 0) { |
| 7279 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get " |
| 7280 | "own MAC address"); |
| 7281 | return 0; |
| 7282 | } |
| 7283 | |
| 7284 | if (get_wpa_status(get_station_ifname(), "ssid", ssid, sizeof(ssid)) |
| 7285 | < 0) { |
| 7286 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get " |
| 7287 | "current SSID"); |
| 7288 | return 0; |
| 7289 | } |
| 7290 | ssid_len = strlen(ssid); |
| 7291 | |
| 7292 | pos = buf; |
| 7293 | |
| 7294 | /* Frame Control */ |
| 7295 | switch (frame) { |
| 7296 | case DISASSOC: |
| 7297 | *pos++ = 0xa0; |
| 7298 | break; |
| 7299 | case DEAUTH: |
| 7300 | *pos++ = 0xc0; |
| 7301 | break; |
| 7302 | case SAQUERY: |
| 7303 | *pos++ = 0xd0; |
| 7304 | break; |
| 7305 | case AUTH: |
| 7306 | *pos++ = 0xb0; |
| 7307 | break; |
| 7308 | case ASSOCREQ: |
| 7309 | *pos++ = 0x00; |
| 7310 | break; |
| 7311 | case REASSOCREQ: |
| 7312 | *pos++ = 0x20; |
| 7313 | break; |
| 7314 | case DLS_REQ: |
| 7315 | *pos++ = 0xd0; |
| 7316 | break; |
| 7317 | } |
| 7318 | |
| 7319 | if (protected == INCORRECT_KEY) |
| 7320 | *pos++ = 0x40; /* Set Protected field to 1 */ |
| 7321 | else |
| 7322 | *pos++ = 0x00; |
| 7323 | |
| 7324 | /* Duration */ |
| 7325 | *pos++ = 0x00; |
| 7326 | *pos++ = 0x00; |
| 7327 | |
| 7328 | /* addr1 = DA (current AP) */ |
| 7329 | hwaddr_aton(bssid, pos); |
| 7330 | pos += 6; |
| 7331 | /* addr2 = SA (own address) */ |
| 7332 | hwaddr_aton(addr, pos); |
| 7333 | pos += 6; |
| 7334 | /* addr3 = BSSID (current AP) */ |
| 7335 | hwaddr_aton(bssid, pos); |
| 7336 | pos += 6; |
| 7337 | |
| 7338 | /* Seq# (to be filled by driver/mac80211) */ |
| 7339 | *pos++ = 0x00; |
| 7340 | *pos++ = 0x00; |
| 7341 | |
| 7342 | if (protected == INCORRECT_KEY) { |
| 7343 | /* CCMP parameters */ |
| 7344 | memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8); |
| 7345 | pos += 8; |
| 7346 | } |
| 7347 | |
| 7348 | if (protected == INCORRECT_KEY) { |
| 7349 | switch (frame) { |
| 7350 | case DEAUTH: |
| 7351 | /* Reason code (encrypted) */ |
| 7352 | memcpy(pos, "\xa7\x39", 2); |
| 7353 | pos += 2; |
| 7354 | break; |
| 7355 | case DISASSOC: |
| 7356 | /* Reason code (encrypted) */ |
| 7357 | memcpy(pos, "\xa7\x39", 2); |
| 7358 | pos += 2; |
| 7359 | break; |
| 7360 | case SAQUERY: |
| 7361 | /* Category|Action|TransID (encrypted) */ |
| 7362 | memcpy(pos, "\x6f\xbd\xe9\x4d", 4); |
| 7363 | pos += 4; |
| 7364 | break; |
| 7365 | default: |
| 7366 | return -1; |
| 7367 | } |
| 7368 | |
| 7369 | /* CCMP MIC */ |
| 7370 | memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8); |
| 7371 | pos += 8; |
| 7372 | } else { |
| 7373 | switch (frame) { |
| 7374 | case DEAUTH: |
| 7375 | /* reason code = 8 */ |
| 7376 | *pos++ = 0x08; |
| 7377 | *pos++ = 0x00; |
| 7378 | break; |
| 7379 | case DISASSOC: |
| 7380 | /* reason code = 8 */ |
| 7381 | *pos++ = 0x08; |
| 7382 | *pos++ = 0x00; |
| 7383 | break; |
| 7384 | case SAQUERY: |
| 7385 | /* Category - SA Query */ |
| 7386 | *pos++ = 0x08; |
| 7387 | /* SA query Action - Request */ |
| 7388 | *pos++ = 0x00; |
| 7389 | /* Transaction ID */ |
| 7390 | *pos++ = 0x12; |
| 7391 | *pos++ = 0x34; |
| 7392 | break; |
| 7393 | case AUTH: |
| 7394 | /* Auth Alg (Open) */ |
| 7395 | *pos++ = 0x00; |
| 7396 | *pos++ = 0x00; |
| 7397 | /* Seq# */ |
| 7398 | *pos++ = 0x01; |
| 7399 | *pos++ = 0x00; |
| 7400 | /* Status code */ |
| 7401 | *pos++ = 0x00; |
| 7402 | *pos++ = 0x00; |
| 7403 | break; |
| 7404 | case ASSOCREQ: |
| 7405 | /* Capability Information */ |
| 7406 | *pos++ = 0x31; |
| 7407 | *pos++ = 0x04; |
| 7408 | /* Listen Interval */ |
| 7409 | *pos++ = 0x0a; |
| 7410 | *pos++ = 0x00; |
| 7411 | /* SSID */ |
| 7412 | *pos++ = 0x00; |
| 7413 | *pos++ = ssid_len; |
| 7414 | memcpy(pos, ssid, ssid_len); |
| 7415 | pos += ssid_len; |
| 7416 | /* Supported Rates */ |
| 7417 | memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24", |
| 7418 | 10); |
| 7419 | pos += 10; |
| 7420 | /* Extended Supported Rates */ |
| 7421 | memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6); |
| 7422 | pos += 6; |
| 7423 | /* RSN */ |
| 7424 | memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00" |
| 7425 | "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0" |
| 7426 | "\x00\x00\x00\x00\x0f\xac\x06", 28); |
| 7427 | pos += 28; |
| 7428 | break; |
| 7429 | case REASSOCREQ: |
| 7430 | /* Capability Information */ |
| 7431 | *pos++ = 0x31; |
| 7432 | *pos++ = 0x04; |
| 7433 | /* Listen Interval */ |
| 7434 | *pos++ = 0x0a; |
| 7435 | *pos++ = 0x00; |
| 7436 | /* Current AP */ |
| 7437 | hwaddr_aton(bssid, pos); |
| 7438 | pos += 6; |
| 7439 | /* SSID */ |
| 7440 | *pos++ = 0x00; |
| 7441 | *pos++ = ssid_len; |
| 7442 | memcpy(pos, ssid, ssid_len); |
| 7443 | pos += ssid_len; |
| 7444 | /* Supported Rates */ |
| 7445 | memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24", |
| 7446 | 10); |
| 7447 | pos += 10; |
| 7448 | /* Extended Supported Rates */ |
| 7449 | memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6); |
| 7450 | pos += 6; |
| 7451 | /* RSN */ |
| 7452 | memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00" |
| 7453 | "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0" |
| 7454 | "\x00\x00\x00\x00\x0f\xac\x06", 28); |
| 7455 | pos += 28; |
| 7456 | break; |
| 7457 | case DLS_REQ: |
| 7458 | /* Category - DLS */ |
| 7459 | *pos++ = 0x02; |
| 7460 | /* DLS Action - Request */ |
| 7461 | *pos++ = 0x00; |
| 7462 | /* Destination MACAddress */ |
| 7463 | if (dest) |
| 7464 | hwaddr_aton(dest, pos); |
| 7465 | else |
| 7466 | memset(pos, 0, 6); |
| 7467 | pos += 6; |
| 7468 | /* Source MACAddress */ |
| 7469 | hwaddr_aton(addr, pos); |
| 7470 | pos += 6; |
| 7471 | /* Capability Information */ |
| 7472 | *pos++ = 0x10; /* Privacy */ |
| 7473 | *pos++ = 0x06; /* QoS */ |
| 7474 | /* DLS Timeout Value */ |
| 7475 | *pos++ = 0x00; |
| 7476 | *pos++ = 0x01; |
| 7477 | /* Supported rates */ |
| 7478 | *pos++ = 0x01; |
| 7479 | *pos++ = 0x08; |
| 7480 | *pos++ = 0x0c; /* 6 Mbps */ |
| 7481 | *pos++ = 0x12; /* 9 Mbps */ |
| 7482 | *pos++ = 0x18; /* 12 Mbps */ |
| 7483 | *pos++ = 0x24; /* 18 Mbps */ |
| 7484 | *pos++ = 0x30; /* 24 Mbps */ |
| 7485 | *pos++ = 0x48; /* 36 Mbps */ |
| 7486 | *pos++ = 0x60; /* 48 Mbps */ |
| 7487 | *pos++ = 0x6c; /* 54 Mbps */ |
| 7488 | /* TODO: Extended Supported Rates */ |
| 7489 | /* TODO: HT Capabilities */ |
| 7490 | break; |
| 7491 | } |
| 7492 | } |
| 7493 | |
| 7494 | s = open_monitor("sigmadut"); |
| 7495 | if (s < 0) { |
| 7496 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open " |
| 7497 | "monitor socket"); |
| 7498 | return 0; |
| 7499 | } |
| 7500 | |
| 7501 | res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY); |
| 7502 | if (res < 0) { |
| 7503 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to " |
| 7504 | "inject frame"); |
Pradeep Reddy POTTETI | 673d85c | 2016-07-26 19:08:07 +0530 | [diff] [blame] | 7505 | close(s); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7506 | return 0; |
| 7507 | } |
| 7508 | if (res < pos - buf) { |
| 7509 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Only partial " |
| 7510 | "frame sent"); |
Pradeep Reddy POTTETI | 673d85c | 2016-07-26 19:08:07 +0530 | [diff] [blame] | 7511 | close(s); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7512 | return 0; |
| 7513 | } |
| 7514 | |
| 7515 | close(s); |
| 7516 | |
| 7517 | return 1; |
| 7518 | #else /* __linux__ */ |
| 7519 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,sta_send_frame not " |
| 7520 | "yet supported"); |
| 7521 | return 0; |
| 7522 | #endif /* __linux__ */ |
| 7523 | } |
| 7524 | |
| 7525 | |
| 7526 | static int cmd_sta_send_frame_tdls(struct sigma_dut *dut, |
| 7527 | struct sigma_conn *conn, |
| 7528 | struct sigma_cmd *cmd) |
| 7529 | { |
| 7530 | const char *intf = get_param(cmd, "Interface"); |
| 7531 | const char *sta, *val; |
| 7532 | unsigned char addr[ETH_ALEN]; |
| 7533 | char buf[100]; |
| 7534 | |
| 7535 | sta = get_param(cmd, "peer"); |
| 7536 | if (sta == NULL) |
| 7537 | sta = get_param(cmd, "station"); |
| 7538 | if (sta == NULL) { |
| 7539 | send_resp(dut, conn, SIGMA_ERROR, |
| 7540 | "ErrorCode,Missing peer address"); |
| 7541 | return 0; |
| 7542 | } |
| 7543 | if (hwaddr_aton(sta, addr) < 0) { |
| 7544 | send_resp(dut, conn, SIGMA_ERROR, |
| 7545 | "ErrorCode,Invalid peer address"); |
| 7546 | return 0; |
| 7547 | } |
| 7548 | |
| 7549 | val = get_param(cmd, "type"); |
| 7550 | if (val == NULL) |
| 7551 | return -1; |
| 7552 | |
| 7553 | if (strcasecmp(val, "DISCOVERY") == 0) { |
| 7554 | snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", sta); |
| 7555 | if (wpa_command(intf, buf) < 0) { |
| 7556 | send_resp(dut, conn, SIGMA_ERROR, |
| 7557 | "ErrorCode,Failed to send TDLS discovery"); |
| 7558 | return 0; |
| 7559 | } |
| 7560 | return 1; |
| 7561 | } |
| 7562 | |
| 7563 | if (strcasecmp(val, "SETUP") == 0) { |
| 7564 | int status = 0, timeout = 0; |
| 7565 | |
| 7566 | val = get_param(cmd, "Status"); |
| 7567 | if (val) |
| 7568 | status = atoi(val); |
| 7569 | |
| 7570 | val = get_param(cmd, "Timeout"); |
| 7571 | if (val) |
| 7572 | timeout = atoi(val); |
| 7573 | |
| 7574 | if (status != 0 && status != 37) { |
| 7575 | send_resp(dut, conn, SIGMA_ERROR, |
| 7576 | "ErrorCode,Unsupported status value"); |
| 7577 | return 0; |
| 7578 | } |
| 7579 | |
| 7580 | if (timeout != 0 && timeout != 301) { |
| 7581 | send_resp(dut, conn, SIGMA_ERROR, |
| 7582 | "ErrorCode,Unsupported timeout value"); |
| 7583 | return 0; |
| 7584 | } |
| 7585 | |
| 7586 | if (status && timeout) { |
| 7587 | send_resp(dut, conn, SIGMA_ERROR, |
| 7588 | "ErrorCode,Unsupported timeout+status " |
| 7589 | "combination"); |
| 7590 | return 0; |
| 7591 | } |
| 7592 | |
| 7593 | if (status == 37 && |
| 7594 | wpa_command(intf, "SET tdls_testing 0x200")) { |
| 7595 | send_resp(dut, conn, SIGMA_ERROR, |
| 7596 | "ErrorCode,Failed to enable " |
| 7597 | "decline setup response test mode"); |
| 7598 | return 0; |
| 7599 | } |
| 7600 | |
| 7601 | if (timeout == 301) { |
| 7602 | int res; |
| 7603 | if (dut->no_tpk_expiration) |
| 7604 | res = wpa_command(intf, |
| 7605 | "SET tdls_testing 0x108"); |
| 7606 | else |
| 7607 | res = wpa_command(intf, |
| 7608 | "SET tdls_testing 0x8"); |
| 7609 | if (res) { |
| 7610 | send_resp(dut, conn, SIGMA_ERROR, |
| 7611 | "ErrorCode,Failed to set short TPK " |
| 7612 | "lifetime"); |
| 7613 | return 0; |
| 7614 | } |
| 7615 | } |
| 7616 | |
| 7617 | snprintf(buf, sizeof(buf), "TDLS_SETUP %s", sta); |
| 7618 | if (wpa_command(intf, buf) < 0) { |
| 7619 | send_resp(dut, conn, SIGMA_ERROR, |
| 7620 | "ErrorCode,Failed to send TDLS setup"); |
| 7621 | return 0; |
| 7622 | } |
| 7623 | return 1; |
| 7624 | } |
| 7625 | |
| 7626 | if (strcasecmp(val, "TEARDOWN") == 0) { |
| 7627 | snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", sta); |
| 7628 | if (wpa_command(intf, buf) < 0) { |
| 7629 | send_resp(dut, conn, SIGMA_ERROR, |
| 7630 | "ErrorCode,Failed to send TDLS teardown"); |
| 7631 | return 0; |
| 7632 | } |
| 7633 | return 1; |
| 7634 | } |
| 7635 | |
| 7636 | send_resp(dut, conn, SIGMA_ERROR, |
| 7637 | "ErrorCode,Unsupported TDLS frame"); |
| 7638 | return 0; |
| 7639 | } |
| 7640 | |
| 7641 | |
| 7642 | static int sta_ap_known(const char *ifname, const char *bssid) |
| 7643 | { |
| 7644 | char buf[4096]; |
| 7645 | |
| 7646 | snprintf(buf, sizeof(buf), "BSS %s", bssid); |
| 7647 | if (wpa_command_resp(ifname, buf, buf, sizeof(buf)) < 0) |
| 7648 | return 0; |
| 7649 | if (strncmp(buf, "id=", 3) != 0) |
| 7650 | return 0; |
| 7651 | return 1; |
| 7652 | } |
| 7653 | |
| 7654 | |
| 7655 | static int sta_scan_ap(struct sigma_dut *dut, const char *ifname, |
| 7656 | const char *bssid) |
| 7657 | { |
| 7658 | int res; |
| 7659 | struct wpa_ctrl *ctrl; |
| 7660 | char buf[256]; |
| 7661 | |
| 7662 | if (sta_ap_known(ifname, bssid)) |
| 7663 | return 0; |
| 7664 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 7665 | "AP not in BSS table - start scan"); |
| 7666 | |
| 7667 | ctrl = open_wpa_mon(ifname); |
| 7668 | if (ctrl == NULL) { |
| 7669 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open " |
| 7670 | "wpa_supplicant monitor connection"); |
| 7671 | return -1; |
| 7672 | } |
| 7673 | |
| 7674 | if (wpa_command(ifname, "SCAN") < 0) { |
| 7675 | sigma_dut_print(dut, DUT_MSG_INFO, "Failed to start scan"); |
| 7676 | wpa_ctrl_detach(ctrl); |
| 7677 | wpa_ctrl_close(ctrl); |
| 7678 | return -1; |
| 7679 | } |
| 7680 | |
| 7681 | res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS", |
| 7682 | buf, sizeof(buf)); |
| 7683 | |
| 7684 | wpa_ctrl_detach(ctrl); |
| 7685 | wpa_ctrl_close(ctrl); |
| 7686 | |
| 7687 | if (res < 0) { |
| 7688 | sigma_dut_print(dut, DUT_MSG_INFO, "Scan did not complete"); |
| 7689 | return -1; |
| 7690 | } |
| 7691 | |
| 7692 | if (sta_ap_known(ifname, bssid)) |
| 7693 | return 0; |
| 7694 | sigma_dut_print(dut, DUT_MSG_INFO, "AP not in BSS table"); |
| 7695 | return -1; |
| 7696 | } |
| 7697 | |
| 7698 | |
| 7699 | static int cmd_sta_send_frame_hs2_neighadv(struct sigma_dut *dut, |
| 7700 | struct sigma_conn *conn, |
| 7701 | struct sigma_cmd *cmd, |
| 7702 | const char *intf) |
| 7703 | { |
| 7704 | char buf[200]; |
| 7705 | |
| 7706 | snprintf(buf, sizeof(buf), "ndsend 2001:DB8::1 %s", intf); |
| 7707 | if (system(buf) != 0) { |
| 7708 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Failed to run " |
| 7709 | "ndsend"); |
| 7710 | return 0; |
| 7711 | } |
| 7712 | |
| 7713 | return 1; |
| 7714 | } |
| 7715 | |
| 7716 | |
| 7717 | static int cmd_sta_send_frame_hs2_neighsolreq(struct sigma_dut *dut, |
| 7718 | struct sigma_conn *conn, |
| 7719 | struct sigma_cmd *cmd, |
| 7720 | const char *intf) |
| 7721 | { |
| 7722 | char buf[200]; |
| 7723 | const char *ip = get_param(cmd, "SenderIP"); |
| 7724 | |
Peng Xu | 26b356d | 2017-10-04 17:58:16 -0700 | [diff] [blame] | 7725 | if (!ip) |
| 7726 | return 0; |
| 7727 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7728 | snprintf(buf, sizeof(buf), "ndisc6 -nm %s %s -r 4", ip, intf); |
| 7729 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 7730 | if (system(buf) == 0) { |
| 7731 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 7732 | "Neighbor Solicitation got a response " |
| 7733 | "for %s@%s", ip, intf); |
| 7734 | } |
| 7735 | |
| 7736 | return 1; |
| 7737 | } |
| 7738 | |
| 7739 | |
| 7740 | static int cmd_sta_send_frame_hs2_arpprobe(struct sigma_dut *dut, |
| 7741 | struct sigma_conn *conn, |
| 7742 | struct sigma_cmd *cmd, |
| 7743 | const char *ifname) |
| 7744 | { |
| 7745 | char buf[200]; |
| 7746 | const char *ip = get_param(cmd, "SenderIP"); |
| 7747 | |
| 7748 | if (ip == NULL) { |
| 7749 | send_resp(dut, conn, SIGMA_ERROR, |
| 7750 | "ErrorCode,Missing SenderIP parameter"); |
| 7751 | return 0; |
| 7752 | } |
| 7753 | snprintf(buf, sizeof(buf), "arping -I %s -D %s -c 4", ifname, ip); |
| 7754 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 7755 | if (system(buf) != 0) { |
| 7756 | sigma_dut_print(dut, DUT_MSG_INFO, "arping DAD got a response " |
| 7757 | "for %s@%s", ip, ifname); |
| 7758 | } |
| 7759 | |
| 7760 | return 1; |
| 7761 | } |
| 7762 | |
| 7763 | |
| 7764 | static int cmd_sta_send_frame_hs2_arpannounce(struct sigma_dut *dut, |
| 7765 | struct sigma_conn *conn, |
| 7766 | struct sigma_cmd *cmd, |
| 7767 | const char *ifname) |
| 7768 | { |
| 7769 | char buf[200]; |
| 7770 | char ip[16]; |
| 7771 | int s; |
Peng Xu | b375688 | 2017-10-04 14:39:09 -0700 | [diff] [blame] | 7772 | struct ifreq ifr; |
| 7773 | struct sockaddr_in saddr; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7774 | |
| 7775 | s = socket(PF_INET, SOCK_DGRAM, 0); |
Peng Xu | b375688 | 2017-10-04 14:39:09 -0700 | [diff] [blame] | 7776 | if (s < 0) { |
| 7777 | perror("socket"); |
| 7778 | return -1; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7779 | } |
| 7780 | |
Peng Xu | b375688 | 2017-10-04 14:39:09 -0700 | [diff] [blame] | 7781 | memset(&ifr, 0, sizeof(ifr)); |
| 7782 | strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); |
| 7783 | if (ioctl(s, SIOCGIFADDR, &ifr) < 0) { |
| 7784 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 7785 | "Failed to get %s IP address: %s", |
| 7786 | ifname, strerror(errno)); |
| 7787 | close(s); |
| 7788 | return -1; |
| 7789 | } |
| 7790 | close(s); |
| 7791 | |
| 7792 | memcpy(&saddr, &ifr.ifr_addr, sizeof(struct sockaddr_in)); |
| 7793 | strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip)); |
| 7794 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7795 | snprintf(buf, sizeof(buf), "arping -I %s -s %s %s -c 4", ifname, ip, |
| 7796 | ip); |
| 7797 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 7798 | if (system(buf) != 0) { |
| 7799 | } |
| 7800 | |
| 7801 | return 1; |
| 7802 | } |
| 7803 | |
| 7804 | |
| 7805 | static int cmd_sta_send_frame_hs2_arpreply(struct sigma_dut *dut, |
| 7806 | struct sigma_conn *conn, |
| 7807 | struct sigma_cmd *cmd, |
| 7808 | const char *ifname) |
| 7809 | { |
| 7810 | char buf[200], addr[20]; |
| 7811 | char dst[ETH_ALEN], src[ETH_ALEN]; |
| 7812 | short ethtype = htons(ETH_P_ARP); |
| 7813 | char *pos; |
| 7814 | int s, res; |
| 7815 | const char *val; |
| 7816 | struct sockaddr_in taddr; |
| 7817 | |
| 7818 | val = get_param(cmd, "dest"); |
| 7819 | if (val) |
| 7820 | hwaddr_aton(val, (unsigned char *) dst); |
| 7821 | |
| 7822 | val = get_param(cmd, "DestIP"); |
| 7823 | if (val) |
| 7824 | inet_aton(val, &taddr.sin_addr); |
Peng Xu | 151c9e1 | 2017-10-04 14:39:09 -0700 | [diff] [blame] | 7825 | else |
| 7826 | return -2; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7827 | |
| 7828 | if (get_wpa_status(get_station_ifname(), "address", addr, |
| 7829 | sizeof(addr)) < 0) |
| 7830 | return -2; |
| 7831 | hwaddr_aton(addr, (unsigned char *) src); |
| 7832 | |
| 7833 | pos = buf; |
| 7834 | *pos++ = 0x00; |
| 7835 | *pos++ = 0x01; |
| 7836 | *pos++ = 0x08; |
| 7837 | *pos++ = 0x00; |
| 7838 | *pos++ = 0x06; |
| 7839 | *pos++ = 0x04; |
| 7840 | *pos++ = 0x00; |
| 7841 | *pos++ = 0x02; |
| 7842 | memcpy(pos, src, ETH_ALEN); |
| 7843 | pos += ETH_ALEN; |
| 7844 | memcpy(pos, &taddr.sin_addr, 4); |
| 7845 | pos += 4; |
| 7846 | memcpy(pos, dst, ETH_ALEN); |
| 7847 | pos += ETH_ALEN; |
| 7848 | memcpy(pos, &taddr.sin_addr, 4); |
| 7849 | pos += 4; |
| 7850 | |
| 7851 | s = open_monitor(get_station_ifname()); |
| 7852 | if (s < 0) { |
| 7853 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open " |
| 7854 | "monitor socket"); |
| 7855 | return 0; |
| 7856 | } |
| 7857 | |
| 7858 | res = inject_eth_frame(s, buf, pos - buf, ethtype, dst, src); |
| 7859 | if (res < 0) { |
| 7860 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to " |
| 7861 | "inject frame"); |
Pradeep Reddy POTTETI | 673d85c | 2016-07-26 19:08:07 +0530 | [diff] [blame] | 7862 | close(s); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7863 | return 0; |
| 7864 | } |
| 7865 | |
| 7866 | close(s); |
| 7867 | |
| 7868 | return 1; |
| 7869 | } |
| 7870 | |
| 7871 | |
| 7872 | static int cmd_sta_send_frame_hs2_dls_req(struct sigma_dut *dut, |
| 7873 | struct sigma_conn *conn, |
| 7874 | struct sigma_cmd *cmd, |
| 7875 | const char *intf, const char *dest) |
| 7876 | { |
| 7877 | char buf[100]; |
| 7878 | |
| 7879 | if (if_nametoindex("sigmadut") == 0) { |
| 7880 | snprintf(buf, sizeof(buf), |
| 7881 | "iw dev %s interface add sigmadut type monitor", |
| 7882 | get_station_ifname()); |
| 7883 | if (system(buf) != 0 || |
| 7884 | if_nametoindex("sigmadut") == 0) { |
| 7885 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add " |
| 7886 | "monitor interface with '%s'", buf); |
| 7887 | return -2; |
| 7888 | } |
| 7889 | } |
| 7890 | |
| 7891 | if (system("ifconfig sigmadut up") != 0) { |
| 7892 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set " |
| 7893 | "monitor interface up"); |
| 7894 | return -2; |
| 7895 | } |
| 7896 | |
| 7897 | return sta_inject_frame(dut, conn, DLS_REQ, UNPROTECTED, dest); |
| 7898 | } |
| 7899 | |
| 7900 | |
| 7901 | static int cmd_sta_send_frame_hs2(struct sigma_dut *dut, |
| 7902 | struct sigma_conn *conn, |
| 7903 | struct sigma_cmd *cmd) |
| 7904 | { |
| 7905 | const char *intf = get_param(cmd, "Interface"); |
| 7906 | const char *dest = get_param(cmd, "Dest"); |
| 7907 | const char *type = get_param(cmd, "FrameName"); |
| 7908 | const char *val; |
| 7909 | char buf[200], *pos, *end; |
| 7910 | int count, count2; |
| 7911 | |
| 7912 | if (type == NULL) |
| 7913 | type = get_param(cmd, "Type"); |
| 7914 | |
| 7915 | if (intf == NULL || dest == NULL || type == NULL) |
| 7916 | return -1; |
| 7917 | |
| 7918 | if (strcasecmp(type, "NeighAdv") == 0) |
| 7919 | return cmd_sta_send_frame_hs2_neighadv(dut, conn, cmd, intf); |
| 7920 | |
| 7921 | if (strcasecmp(type, "NeighSolicitReq") == 0) |
| 7922 | return cmd_sta_send_frame_hs2_neighsolreq(dut, conn, cmd, intf); |
| 7923 | |
| 7924 | if (strcasecmp(type, "ARPProbe") == 0) |
| 7925 | return cmd_sta_send_frame_hs2_arpprobe(dut, conn, cmd, intf); |
| 7926 | |
| 7927 | if (strcasecmp(type, "ARPAnnounce") == 0) |
| 7928 | return cmd_sta_send_frame_hs2_arpannounce(dut, conn, cmd, intf); |
| 7929 | |
| 7930 | if (strcasecmp(type, "ARPReply") == 0) |
| 7931 | return cmd_sta_send_frame_hs2_arpreply(dut, conn, cmd, intf); |
| 7932 | |
| 7933 | if (strcasecmp(type, "DLS-request") == 0 || |
| 7934 | strcasecmp(type, "DLSrequest") == 0) |
| 7935 | return cmd_sta_send_frame_hs2_dls_req(dut, conn, cmd, intf, |
| 7936 | dest); |
| 7937 | |
| 7938 | if (strcasecmp(type, "ANQPQuery") != 0 && |
| 7939 | strcasecmp(type, "Query") != 0) { |
| 7940 | send_resp(dut, conn, SIGMA_ERROR, |
| 7941 | "ErrorCode,Unsupported HS 2.0 send frame type"); |
| 7942 | return 0; |
| 7943 | } |
| 7944 | |
| 7945 | if (sta_scan_ap(dut, intf, dest) < 0) { |
| 7946 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not find " |
| 7947 | "the requested AP"); |
| 7948 | return 0; |
| 7949 | } |
| 7950 | |
| 7951 | pos = buf; |
| 7952 | end = buf + sizeof(buf); |
| 7953 | count = 0; |
| 7954 | pos += snprintf(pos, end - pos, "ANQP_GET %s ", dest); |
| 7955 | |
| 7956 | val = get_param(cmd, "ANQP_CAP_LIST"); |
| 7957 | if (val && atoi(val)) { |
| 7958 | pos += snprintf(pos, end - pos, "%s257", count > 0 ? "," : ""); |
| 7959 | count++; |
| 7960 | } |
| 7961 | |
| 7962 | val = get_param(cmd, "VENUE_NAME"); |
| 7963 | if (val && atoi(val)) { |
| 7964 | pos += snprintf(pos, end - pos, "%s258", count > 0 ? "," : ""); |
| 7965 | count++; |
| 7966 | } |
| 7967 | |
| 7968 | val = get_param(cmd, "NETWORK_AUTH_TYPE"); |
| 7969 | if (val && atoi(val)) { |
| 7970 | pos += snprintf(pos, end - pos, "%s260", count > 0 ? "," : ""); |
| 7971 | count++; |
| 7972 | } |
| 7973 | |
| 7974 | val = get_param(cmd, "ROAMING_CONS"); |
| 7975 | if (val && atoi(val)) { |
| 7976 | pos += snprintf(pos, end - pos, "%s261", count > 0 ? "," : ""); |
| 7977 | count++; |
| 7978 | } |
| 7979 | |
| 7980 | val = get_param(cmd, "IP_ADDR_TYPE_AVAILABILITY"); |
| 7981 | if (val && atoi(val)) { |
| 7982 | pos += snprintf(pos, end - pos, "%s262", count > 0 ? "," : ""); |
| 7983 | count++; |
| 7984 | } |
| 7985 | |
| 7986 | val = get_param(cmd, "NAI_REALM_LIST"); |
| 7987 | if (val && atoi(val)) { |
| 7988 | pos += snprintf(pos, end - pos, "%s263", count > 0 ? "," : ""); |
| 7989 | count++; |
| 7990 | } |
| 7991 | |
| 7992 | val = get_param(cmd, "3GPP_INFO"); |
| 7993 | if (val && atoi(val)) { |
| 7994 | pos += snprintf(pos, end - pos, "%s264", count > 0 ? "," : ""); |
| 7995 | count++; |
| 7996 | } |
| 7997 | |
| 7998 | val = get_param(cmd, "DOMAIN_LIST"); |
| 7999 | if (val && atoi(val)) { |
| 8000 | pos += snprintf(pos, end - pos, "%s268", count > 0 ? "," : ""); |
| 8001 | count++; |
| 8002 | } |
| 8003 | |
Jouni Malinen | 34cf953 | 2018-04-29 19:26:33 +0300 | [diff] [blame] | 8004 | val = get_param(cmd, "Venue_URL"); |
| 8005 | if (val && atoi(val)) { |
| 8006 | pos += snprintf(pos, end - pos, "%s277", count > 0 ? "," : ""); |
| 8007 | count++; |
| 8008 | } |
| 8009 | |
Jouni Malinen | d3bca5d | 2018-04-29 17:25:23 +0300 | [diff] [blame] | 8010 | val = get_param(cmd, "Advice_Of_Charge"); |
| 8011 | if (val && atoi(val)) { |
| 8012 | pos += snprintf(pos, end - pos, "%s278", count > 0 ? "," : ""); |
| 8013 | count++; |
| 8014 | } |
| 8015 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8016 | if (count && wpa_command(intf, buf)) { |
| 8017 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,ANQP_GET failed"); |
| 8018 | return 0; |
| 8019 | } |
| 8020 | |
| 8021 | pos = buf; |
| 8022 | end = buf + sizeof(buf); |
| 8023 | count2 = 0; |
| 8024 | pos += snprintf(pos, end - pos, "HS20_ANQP_GET %s ", dest); |
| 8025 | |
| 8026 | val = get_param(cmd, "HS_CAP_LIST"); |
| 8027 | if (val && atoi(val)) { |
| 8028 | pos += snprintf(pos, end - pos, "%s2", count2 > 0 ? "," : ""); |
| 8029 | count2++; |
| 8030 | } |
| 8031 | |
| 8032 | val = get_param(cmd, "OPER_NAME"); |
| 8033 | if (val && atoi(val)) { |
| 8034 | pos += snprintf(pos, end - pos, "%s3", count2 > 0 ? "," : ""); |
| 8035 | count2++; |
| 8036 | } |
| 8037 | |
| 8038 | val = get_param(cmd, "WAN_METRICS"); |
| 8039 | if (!val) |
| 8040 | val = get_param(cmd, "WAN_MAT"); |
| 8041 | if (!val) |
| 8042 | val = get_param(cmd, "WAN_MET"); |
| 8043 | if (val && atoi(val)) { |
| 8044 | pos += snprintf(pos, end - pos, "%s4", count2 > 0 ? "," : ""); |
| 8045 | count2++; |
| 8046 | } |
| 8047 | |
| 8048 | val = get_param(cmd, "CONNECTION_CAPABILITY"); |
| 8049 | if (val && atoi(val)) { |
| 8050 | pos += snprintf(pos, end - pos, "%s5", count2 > 0 ? "," : ""); |
| 8051 | count2++; |
| 8052 | } |
| 8053 | |
| 8054 | val = get_param(cmd, "OP_CLASS"); |
| 8055 | if (val && atoi(val)) { |
| 8056 | pos += snprintf(pos, end - pos, "%s7", count2 > 0 ? "," : ""); |
| 8057 | count2++; |
| 8058 | } |
| 8059 | |
| 8060 | val = get_param(cmd, "OSU_PROVIDER_LIST"); |
| 8061 | if (val && atoi(val)) { |
| 8062 | pos += snprintf(pos, end - pos, "%s8", count2 > 0 ? "," : ""); |
| 8063 | count2++; |
| 8064 | } |
| 8065 | |
Jouni Malinen | f67afec | 2018-04-29 19:24:58 +0300 | [diff] [blame] | 8066 | val = get_param(cmd, "OPER_ICON_METADATA"); |
| 8067 | if (!val) |
| 8068 | val = get_param(cmd, "OPERATOR_ICON_METADATA"); |
| 8069 | if (val && atoi(val)) { |
| 8070 | pos += snprintf(pos, end - pos, "%s12", count2 > 0 ? "," : ""); |
| 8071 | count2++; |
| 8072 | } |
| 8073 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8074 | if (count && count2) { |
| 8075 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before sending out " |
| 8076 | "second query"); |
| 8077 | sleep(1); |
| 8078 | } |
| 8079 | |
| 8080 | if (count2 && wpa_command(intf, buf)) { |
| 8081 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,HS20_ANQP_GET " |
| 8082 | "failed"); |
| 8083 | return 0; |
| 8084 | } |
| 8085 | |
| 8086 | val = get_param(cmd, "NAI_HOME_REALM_LIST"); |
| 8087 | if (val) { |
| 8088 | if (count || count2) { |
| 8089 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before " |
| 8090 | "sending out second query"); |
| 8091 | sleep(1); |
| 8092 | } |
| 8093 | |
| 8094 | if (strcmp(val, "1") == 0) |
| 8095 | val = "mail.example.com"; |
| 8096 | snprintf(buf, end - pos, |
| 8097 | "HS20_GET_NAI_HOME_REALM_LIST %s realm=%s", |
| 8098 | dest, val); |
| 8099 | if (wpa_command(intf, buf)) { |
| 8100 | send_resp(dut, conn, SIGMA_ERROR, |
| 8101 | "ErrorCode,HS20_GET_NAI_HOME_REALM_LIST " |
| 8102 | "failed"); |
| 8103 | return 0; |
| 8104 | } |
| 8105 | } |
| 8106 | |
| 8107 | val = get_param(cmd, "ICON_REQUEST"); |
| 8108 | if (val) { |
| 8109 | if (count || count2) { |
| 8110 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before " |
| 8111 | "sending out second query"); |
| 8112 | sleep(1); |
| 8113 | } |
| 8114 | |
| 8115 | snprintf(buf, end - pos, |
| 8116 | "HS20_ICON_REQUEST %s %s", dest, val); |
| 8117 | if (wpa_command(intf, buf)) { |
| 8118 | send_resp(dut, conn, SIGMA_ERROR, |
| 8119 | "ErrorCode,HS20_ICON_REQUEST failed"); |
| 8120 | return 0; |
| 8121 | } |
| 8122 | } |
| 8123 | |
| 8124 | return 1; |
| 8125 | } |
| 8126 | |
| 8127 | |
| 8128 | static int ath_sta_send_frame_vht(struct sigma_dut *dut, |
| 8129 | struct sigma_conn *conn, |
| 8130 | struct sigma_cmd *cmd) |
| 8131 | { |
| 8132 | const char *val; |
| 8133 | char *ifname; |
| 8134 | char buf[100]; |
| 8135 | int chwidth, nss; |
| 8136 | |
| 8137 | val = get_param(cmd, "framename"); |
| 8138 | if (!val) |
| 8139 | return -1; |
| 8140 | sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val); |
| 8141 | |
| 8142 | /* Command sequence to generate Op mode notification */ |
| 8143 | if (val && strcasecmp(val, "Op_md_notif_frm") == 0) { |
| 8144 | ifname = get_station_ifname(); |
| 8145 | |
| 8146 | /* Disable STBC */ |
| 8147 | snprintf(buf, sizeof(buf), |
| 8148 | "iwpriv %s tx_stbc 0", ifname); |
| 8149 | if (system(buf) != 0) { |
| 8150 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8151 | "iwpriv tx_stbc 0 failed!"); |
| 8152 | } |
| 8153 | |
| 8154 | /* Extract Channel width */ |
| 8155 | val = get_param(cmd, "Channel_width"); |
| 8156 | if (val) { |
| 8157 | switch (atoi(val)) { |
| 8158 | case 20: |
| 8159 | chwidth = 0; |
| 8160 | break; |
| 8161 | case 40: |
| 8162 | chwidth = 1; |
| 8163 | break; |
| 8164 | case 80: |
| 8165 | chwidth = 2; |
| 8166 | break; |
| 8167 | case 160: |
| 8168 | chwidth = 3; |
| 8169 | break; |
| 8170 | default: |
| 8171 | chwidth = 2; |
| 8172 | break; |
| 8173 | } |
| 8174 | |
| 8175 | snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d", |
| 8176 | ifname, chwidth); |
| 8177 | if (system(buf) != 0) { |
| 8178 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8179 | "iwpriv chwidth failed!"); |
| 8180 | } |
| 8181 | } |
| 8182 | |
| 8183 | /* Extract NSS */ |
| 8184 | val = get_param(cmd, "NSS"); |
| 8185 | if (val) { |
| 8186 | switch (atoi(val)) { |
| 8187 | case 1: |
| 8188 | nss = 1; |
| 8189 | break; |
| 8190 | case 2: |
| 8191 | nss = 3; |
| 8192 | break; |
| 8193 | case 3: |
| 8194 | nss = 7; |
| 8195 | break; |
| 8196 | default: |
| 8197 | /* We do not support NSS > 3 */ |
| 8198 | nss = 3; |
| 8199 | break; |
| 8200 | } |
| 8201 | snprintf(buf, sizeof(buf), |
| 8202 | "iwpriv %s rxchainmask %d", ifname, nss); |
| 8203 | if (system(buf) != 0) { |
| 8204 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8205 | "iwpriv rxchainmask failed!"); |
| 8206 | } |
| 8207 | } |
| 8208 | |
| 8209 | /* Opmode notify */ |
| 8210 | snprintf(buf, sizeof(buf), "iwpriv %s opmode_notify 1", ifname); |
| 8211 | if (system(buf) != 0) { |
| 8212 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8213 | "iwpriv opmode_notify failed!"); |
| 8214 | } else { |
| 8215 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 8216 | "Sent out the notify frame!"); |
| 8217 | } |
| 8218 | } |
| 8219 | |
| 8220 | return 1; |
| 8221 | } |
| 8222 | |
| 8223 | |
| 8224 | static int cmd_sta_send_frame_vht(struct sigma_dut *dut, |
| 8225 | struct sigma_conn *conn, |
| 8226 | struct sigma_cmd *cmd) |
| 8227 | { |
| 8228 | switch (get_driver_type()) { |
| 8229 | case DRIVER_ATHEROS: |
| 8230 | return ath_sta_send_frame_vht(dut, conn, cmd); |
| 8231 | default: |
| 8232 | send_resp(dut, conn, SIGMA_ERROR, |
| 8233 | "errorCode,Unsupported sta_set_frame(VHT) with the current driver"); |
| 8234 | return 0; |
| 8235 | } |
| 8236 | } |
| 8237 | |
| 8238 | |
Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 8239 | #ifdef __linux__ |
| 8240 | int wil6210_send_frame_60g(struct sigma_dut *dut, struct sigma_conn *conn, |
| 8241 | struct sigma_cmd *cmd) |
| 8242 | { |
| 8243 | const char *frame_name = get_param(cmd, "framename"); |
| 8244 | const char *mac = get_param(cmd, "dest_mac"); |
| 8245 | |
| 8246 | if (!frame_name || !mac) { |
| 8247 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8248 | "framename and dest_mac must be provided"); |
| 8249 | return -1; |
| 8250 | } |
| 8251 | |
| 8252 | if (strcasecmp(frame_name, "brp") == 0) { |
| 8253 | const char *l_rx = get_param(cmd, "L-RX"); |
| 8254 | int l_rx_i; |
| 8255 | |
| 8256 | if (!l_rx) { |
| 8257 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8258 | "L-RX must be provided"); |
| 8259 | return -1; |
| 8260 | } |
| 8261 | l_rx_i = atoi(l_rx); |
| 8262 | |
| 8263 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 8264 | "dev_send_frame: BRP-RX, dest_mac %s, L-RX %s", |
| 8265 | mac, l_rx); |
| 8266 | if (l_rx_i != 16) { |
| 8267 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8268 | "unsupported L-RX: %s", l_rx); |
| 8269 | return -1; |
| 8270 | } |
| 8271 | |
| 8272 | if (wil6210_send_brp_rx(dut, mac, l_rx_i)) |
| 8273 | return -1; |
| 8274 | } else if (strcasecmp(frame_name, "ssw") == 0) { |
| 8275 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 8276 | "dev_send_frame: SLS, dest_mac %s", mac); |
| 8277 | if (wil6210_send_sls(dut, mac)) |
| 8278 | return -1; |
| 8279 | } else { |
| 8280 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8281 | "unsupported frame type: %s", frame_name); |
| 8282 | return -1; |
| 8283 | } |
| 8284 | |
| 8285 | return 1; |
| 8286 | } |
| 8287 | #endif /* __linux__ */ |
| 8288 | |
| 8289 | |
| 8290 | static int cmd_sta_send_frame_60g(struct sigma_dut *dut, |
| 8291 | struct sigma_conn *conn, |
| 8292 | struct sigma_cmd *cmd) |
| 8293 | { |
| 8294 | switch (get_driver_type()) { |
| 8295 | #ifdef __linux__ |
| 8296 | case DRIVER_WIL6210: |
| 8297 | return wil6210_send_frame_60g(dut, conn, cmd); |
| 8298 | #endif /* __linux__ */ |
| 8299 | default: |
| 8300 | send_resp(dut, conn, SIGMA_ERROR, |
| 8301 | "errorCode,Unsupported sta_set_frame(60G) with the current driver"); |
| 8302 | return 0; |
| 8303 | } |
| 8304 | } |
| 8305 | |
| 8306 | |
Ashwini Patil | db59b3c | 2017-04-13 15:19:23 +0530 | [diff] [blame] | 8307 | static int mbo_send_anqp_query(struct sigma_dut *dut, struct sigma_conn *conn, |
| 8308 | const char *intf, struct sigma_cmd *cmd) |
| 8309 | { |
| 8310 | const char *val, *addr; |
| 8311 | char buf[100]; |
| 8312 | |
| 8313 | addr = get_param(cmd, "DestMac"); |
| 8314 | if (!addr) { |
| 8315 | send_resp(dut, conn, SIGMA_INVALID, |
| 8316 | "ErrorCode,AP MAC address is missing"); |
| 8317 | return 0; |
| 8318 | } |
| 8319 | |
| 8320 | val = get_param(cmd, "ANQPQuery_ID"); |
| 8321 | if (!val) { |
| 8322 | send_resp(dut, conn, SIGMA_INVALID, |
| 8323 | "ErrorCode,Missing ANQPQuery_ID"); |
| 8324 | return 0; |
| 8325 | } |
| 8326 | |
| 8327 | if (strcasecmp(val, "NeighborReportReq") == 0) { |
| 8328 | snprintf(buf, sizeof(buf), "ANQP_GET %s 272", addr); |
| 8329 | } else if (strcasecmp(val, "QueryListWithCellPref") == 0) { |
| 8330 | snprintf(buf, sizeof(buf), "ANQP_GET %s 272,mbo:2", addr); |
| 8331 | } else { |
| 8332 | sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid ANQPQuery_ID: %s", |
| 8333 | val); |
| 8334 | send_resp(dut, conn, SIGMA_INVALID, |
| 8335 | "ErrorCode,Invalid ANQPQuery_ID"); |
| 8336 | return 0; |
| 8337 | } |
| 8338 | |
Ashwini Patil | d174f2c | 2017-04-13 16:49:46 +0530 | [diff] [blame] | 8339 | /* Set gas_address3 field to IEEE 802.11-2012 standard compliant form |
| 8340 | * (Address3 = Wildcard BSSID when sent to not-associated AP; |
| 8341 | * if associated, AP BSSID). |
| 8342 | */ |
| 8343 | if (wpa_command(intf, "SET gas_address3 1") < 0) { |
| 8344 | send_resp(dut, conn, SIGMA_ERROR, |
| 8345 | "ErrorCode,Failed to set gas_address3"); |
| 8346 | return 0; |
| 8347 | } |
| 8348 | |
Ashwini Patil | db59b3c | 2017-04-13 15:19:23 +0530 | [diff] [blame] | 8349 | if (wpa_command(intf, buf) < 0) { |
| 8350 | send_resp(dut, conn, SIGMA_ERROR, |
| 8351 | "ErrorCode,Failed to send ANQP query"); |
| 8352 | return 0; |
| 8353 | } |
| 8354 | |
| 8355 | return 1; |
| 8356 | } |
| 8357 | |
| 8358 | |
| 8359 | static int mbo_cmd_sta_send_frame(struct sigma_dut *dut, |
| 8360 | struct sigma_conn *conn, |
| 8361 | const char *intf, |
| 8362 | struct sigma_cmd *cmd) |
| 8363 | { |
| 8364 | const char *val = get_param(cmd, "FrameName"); |
| 8365 | |
| 8366 | if (val && strcasecmp(val, "ANQPQuery") == 0) |
| 8367 | return mbo_send_anqp_query(dut, conn, intf, cmd); |
| 8368 | |
| 8369 | return 2; |
| 8370 | } |
| 8371 | |
| 8372 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8373 | int cmd_sta_send_frame(struct sigma_dut *dut, struct sigma_conn *conn, |
| 8374 | struct sigma_cmd *cmd) |
| 8375 | { |
| 8376 | const char *intf = get_param(cmd, "Interface"); |
| 8377 | const char *val; |
| 8378 | enum send_frame_type frame; |
| 8379 | enum send_frame_protection protected; |
| 8380 | char buf[100]; |
| 8381 | unsigned char addr[ETH_ALEN]; |
| 8382 | int res; |
| 8383 | |
| 8384 | val = get_param(cmd, "program"); |
| 8385 | if (val == NULL) |
| 8386 | val = get_param(cmd, "frame"); |
| 8387 | if (val && strcasecmp(val, "TDLS") == 0) |
| 8388 | return cmd_sta_send_frame_tdls(dut, conn, cmd); |
| 8389 | if (val && (strcasecmp(val, "HS2") == 0 || |
| 8390 | strcasecmp(val, "HS2-R2") == 0)) |
| 8391 | return cmd_sta_send_frame_hs2(dut, conn, cmd); |
| 8392 | if (val && strcasecmp(val, "VHT") == 0) |
| 8393 | return cmd_sta_send_frame_vht(dut, conn, cmd); |
priyadharshini gowthaman | d66913a | 2016-07-29 15:11:17 -0700 | [diff] [blame] | 8394 | if (val && strcasecmp(val, "LOC") == 0) |
| 8395 | return loc_cmd_sta_send_frame(dut, conn, cmd); |
Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 8396 | if (val && strcasecmp(val, "60GHz") == 0) |
| 8397 | return cmd_sta_send_frame_60g(dut, conn, cmd); |
Ashwini Patil | db59b3c | 2017-04-13 15:19:23 +0530 | [diff] [blame] | 8398 | if (val && strcasecmp(val, "MBO") == 0) { |
| 8399 | res = mbo_cmd_sta_send_frame(dut, conn, intf, cmd); |
| 8400 | if (res != 2) |
| 8401 | return res; |
| 8402 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8403 | |
| 8404 | val = get_param(cmd, "TD_DISC"); |
| 8405 | if (val) { |
| 8406 | if (hwaddr_aton(val, addr) < 0) |
| 8407 | return -1; |
| 8408 | snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", val); |
| 8409 | if (wpa_command(intf, buf) < 0) { |
| 8410 | send_resp(dut, conn, SIGMA_ERROR, |
| 8411 | "ErrorCode,Failed to send TDLS discovery"); |
| 8412 | return 0; |
| 8413 | } |
| 8414 | return 1; |
| 8415 | } |
| 8416 | |
| 8417 | val = get_param(cmd, "TD_Setup"); |
| 8418 | if (val) { |
| 8419 | if (hwaddr_aton(val, addr) < 0) |
| 8420 | return -1; |
| 8421 | snprintf(buf, sizeof(buf), "TDLS_SETUP %s", val); |
| 8422 | if (wpa_command(intf, buf) < 0) { |
| 8423 | send_resp(dut, conn, SIGMA_ERROR, |
| 8424 | "ErrorCode,Failed to start TDLS setup"); |
| 8425 | return 0; |
| 8426 | } |
| 8427 | return 1; |
| 8428 | } |
| 8429 | |
| 8430 | val = get_param(cmd, "TD_TearDown"); |
| 8431 | if (val) { |
| 8432 | if (hwaddr_aton(val, addr) < 0) |
| 8433 | return -1; |
| 8434 | snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", val); |
| 8435 | if (wpa_command(intf, buf) < 0) { |
| 8436 | send_resp(dut, conn, SIGMA_ERROR, |
| 8437 | "ErrorCode,Failed to tear down TDLS link"); |
| 8438 | return 0; |
| 8439 | } |
| 8440 | return 1; |
| 8441 | } |
| 8442 | |
| 8443 | val = get_param(cmd, "TD_ChannelSwitch"); |
| 8444 | if (val) { |
| 8445 | /* TODO */ |
| 8446 | send_resp(dut, conn, SIGMA_ERROR, |
| 8447 | "ErrorCode,TD_ChannelSwitch not yet supported"); |
| 8448 | return 0; |
| 8449 | } |
| 8450 | |
| 8451 | val = get_param(cmd, "TD_NF"); |
| 8452 | if (val) { |
| 8453 | /* TODO */ |
| 8454 | send_resp(dut, conn, SIGMA_ERROR, |
| 8455 | "ErrorCode,TD_NF not yet supported"); |
| 8456 | return 0; |
| 8457 | } |
| 8458 | |
| 8459 | val = get_param(cmd, "PMFFrameType"); |
| 8460 | if (val == NULL) |
| 8461 | val = get_param(cmd, "FrameName"); |
| 8462 | if (val == NULL) |
| 8463 | val = get_param(cmd, "Type"); |
| 8464 | if (val == NULL) |
| 8465 | return -1; |
| 8466 | if (strcasecmp(val, "disassoc") == 0) |
| 8467 | frame = DISASSOC; |
| 8468 | else if (strcasecmp(val, "deauth") == 0) |
| 8469 | frame = DEAUTH; |
| 8470 | else if (strcasecmp(val, "saquery") == 0) |
| 8471 | frame = SAQUERY; |
| 8472 | else if (strcasecmp(val, "auth") == 0) |
| 8473 | frame = AUTH; |
| 8474 | else if (strcasecmp(val, "assocreq") == 0) |
| 8475 | frame = ASSOCREQ; |
| 8476 | else if (strcasecmp(val, "reassocreq") == 0) |
| 8477 | frame = REASSOCREQ; |
| 8478 | else if (strcasecmp(val, "neigreq") == 0) { |
| 8479 | sigma_dut_print(dut, DUT_MSG_INFO, "Got neighbor request"); |
| 8480 | |
| 8481 | val = get_param(cmd, "ssid"); |
| 8482 | if (val == NULL) |
| 8483 | return -1; |
| 8484 | |
| 8485 | res = send_neighbor_request(dut, intf, val); |
| 8486 | if (res) { |
| 8487 | send_resp(dut, conn, SIGMA_ERROR, "errorCode," |
| 8488 | "Failed to send neighbor report request"); |
| 8489 | return 0; |
| 8490 | } |
| 8491 | |
| 8492 | return 1; |
Ashwini Patil | 5acd738 | 2017-04-13 15:55:04 +0530 | [diff] [blame] | 8493 | } else if (strcasecmp(val, "transmgmtquery") == 0 || |
| 8494 | strcasecmp(val, "BTMQuery") == 0) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8495 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 8496 | "Got Transition Management Query"); |
| 8497 | |
Ashwini Patil | 5acd738 | 2017-04-13 15:55:04 +0530 | [diff] [blame] | 8498 | res = send_trans_mgmt_query(dut, intf, cmd); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8499 | if (res) { |
| 8500 | send_resp(dut, conn, SIGMA_ERROR, "errorCode," |
| 8501 | "Failed to send Transition Management Query"); |
| 8502 | return 0; |
| 8503 | } |
| 8504 | |
| 8505 | return 1; |
| 8506 | } else { |
| 8507 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported " |
| 8508 | "PMFFrameType"); |
| 8509 | return 0; |
| 8510 | } |
| 8511 | |
| 8512 | val = get_param(cmd, "PMFProtected"); |
| 8513 | if (val == NULL) |
| 8514 | val = get_param(cmd, "Protected"); |
| 8515 | if (val == NULL) |
| 8516 | return -1; |
| 8517 | if (strcasecmp(val, "Correct-key") == 0 || |
| 8518 | strcasecmp(val, "CorrectKey") == 0) |
| 8519 | protected = CORRECT_KEY; |
| 8520 | else if (strcasecmp(val, "IncorrectKey") == 0) |
| 8521 | protected = INCORRECT_KEY; |
| 8522 | else if (strcasecmp(val, "Unprotected") == 0) |
| 8523 | protected = UNPROTECTED; |
| 8524 | else { |
| 8525 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported " |
| 8526 | "PMFProtected"); |
| 8527 | return 0; |
| 8528 | } |
| 8529 | |
| 8530 | if (protected != UNPROTECTED && |
| 8531 | (frame == AUTH || frame == ASSOCREQ || frame == REASSOCREQ)) { |
| 8532 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Impossible " |
| 8533 | "PMFProtected for auth/assocreq/reassocreq"); |
| 8534 | return 0; |
| 8535 | } |
| 8536 | |
| 8537 | if (if_nametoindex("sigmadut") == 0) { |
| 8538 | snprintf(buf, sizeof(buf), |
| 8539 | "iw dev %s interface add sigmadut type monitor", |
| 8540 | get_station_ifname()); |
| 8541 | if (system(buf) != 0 || |
| 8542 | if_nametoindex("sigmadut") == 0) { |
| 8543 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add " |
| 8544 | "monitor interface with '%s'", buf); |
| 8545 | return -2; |
| 8546 | } |
| 8547 | } |
| 8548 | |
| 8549 | if (system("ifconfig sigmadut up") != 0) { |
| 8550 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set " |
| 8551 | "monitor interface up"); |
| 8552 | return -2; |
| 8553 | } |
| 8554 | |
| 8555 | return sta_inject_frame(dut, conn, frame, protected, NULL); |
| 8556 | } |
| 8557 | |
| 8558 | |
| 8559 | static int cmd_sta_set_parameter_hs2(struct sigma_dut *dut, |
| 8560 | struct sigma_conn *conn, |
| 8561 | struct sigma_cmd *cmd, |
| 8562 | const char *ifname) |
| 8563 | { |
| 8564 | char buf[200]; |
| 8565 | const char *val; |
| 8566 | |
| 8567 | val = get_param(cmd, "ClearARP"); |
| 8568 | if (val && atoi(val) == 1) { |
| 8569 | snprintf(buf, sizeof(buf), "ip neigh flush dev %s", ifname); |
| 8570 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 8571 | if (system(buf) != 0) { |
| 8572 | send_resp(dut, conn, SIGMA_ERROR, |
| 8573 | "errorCode,Failed to clear ARP cache"); |
| 8574 | return 0; |
| 8575 | } |
| 8576 | } |
| 8577 | |
| 8578 | return 1; |
| 8579 | } |
| 8580 | |
| 8581 | |
| 8582 | int cmd_sta_set_parameter(struct sigma_dut *dut, struct sigma_conn *conn, |
| 8583 | struct sigma_cmd *cmd) |
| 8584 | { |
| 8585 | const char *intf = get_param(cmd, "Interface"); |
| 8586 | const char *val; |
| 8587 | |
| 8588 | if (intf == NULL) |
| 8589 | return -1; |
| 8590 | |
| 8591 | val = get_param(cmd, "program"); |
| 8592 | if (val && (strcasecmp(val, "HS2") == 0 || |
| 8593 | strcasecmp(val, "HS2-R2") == 0)) |
| 8594 | return cmd_sta_set_parameter_hs2(dut, conn, cmd, intf); |
| 8595 | |
| 8596 | return -1; |
| 8597 | } |
| 8598 | |
| 8599 | |
| 8600 | static int cmd_sta_set_macaddr(struct sigma_dut *dut, struct sigma_conn *conn, |
| 8601 | struct sigma_cmd *cmd) |
| 8602 | { |
| 8603 | const char *intf = get_param(cmd, "Interface"); |
| 8604 | const char *mac = get_param(cmd, "MAC"); |
| 8605 | |
| 8606 | if (intf == NULL || mac == NULL) |
| 8607 | return -1; |
| 8608 | |
| 8609 | sigma_dut_print(dut, DUT_MSG_INFO, "Change local MAC address for " |
| 8610 | "interface %s to %s", intf, mac); |
| 8611 | |
| 8612 | if (dut->set_macaddr) { |
| 8613 | char buf[128]; |
| 8614 | int res; |
| 8615 | if (strcasecmp(mac, "default") == 0) { |
| 8616 | res = snprintf(buf, sizeof(buf), "%s", |
| 8617 | dut->set_macaddr); |
| 8618 | dut->tmp_mac_addr = 0; |
| 8619 | } else { |
| 8620 | res = snprintf(buf, sizeof(buf), "%s %s", |
| 8621 | dut->set_macaddr, mac); |
| 8622 | dut->tmp_mac_addr = 1; |
| 8623 | } |
| 8624 | if (res < 0 || res >= (int) sizeof(buf)) |
| 8625 | return -1; |
| 8626 | if (system(buf) != 0) { |
| 8627 | send_resp(dut, conn, SIGMA_ERROR, |
| 8628 | "errorCode,Failed to set MAC " |
| 8629 | "address"); |
| 8630 | return 0; |
| 8631 | } |
| 8632 | return 1; |
| 8633 | } |
| 8634 | |
| 8635 | if (strcasecmp(mac, "default") == 0) |
| 8636 | return 1; |
| 8637 | |
| 8638 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported " |
| 8639 | "command"); |
| 8640 | return 0; |
| 8641 | } |
| 8642 | |
| 8643 | |
| 8644 | static int iwpriv_tdlsoffchnmode(struct sigma_dut *dut, |
| 8645 | struct sigma_conn *conn, const char *intf, |
| 8646 | int val) |
| 8647 | { |
| 8648 | char buf[200]; |
| 8649 | int res; |
| 8650 | |
| 8651 | res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchnmode %d", |
| 8652 | intf, val); |
| 8653 | if (res < 0 || res >= (int) sizeof(buf)) |
| 8654 | return -1; |
| 8655 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 8656 | if (system(buf) != 0) { |
| 8657 | send_resp(dut, conn, SIGMA_ERROR, |
| 8658 | "errorCode,Failed to configure offchannel mode"); |
| 8659 | return 0; |
| 8660 | } |
| 8661 | |
| 8662 | return 1; |
| 8663 | } |
| 8664 | |
| 8665 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8666 | static int off_chan_val(enum sec_ch_offset off) |
| 8667 | { |
| 8668 | switch (off) { |
| 8669 | case SEC_CH_NO: |
| 8670 | return 0; |
| 8671 | case SEC_CH_40ABOVE: |
| 8672 | return 40; |
| 8673 | case SEC_CH_40BELOW: |
| 8674 | return -40; |
| 8675 | } |
| 8676 | |
| 8677 | return 0; |
| 8678 | } |
| 8679 | |
| 8680 | |
| 8681 | static int iwpriv_set_offchan(struct sigma_dut *dut, struct sigma_conn *conn, |
| 8682 | const char *intf, int off_ch_num, |
| 8683 | enum sec_ch_offset sec) |
| 8684 | { |
| 8685 | char buf[200]; |
| 8686 | int res; |
| 8687 | |
| 8688 | res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchan %d", |
| 8689 | intf, off_ch_num); |
| 8690 | if (res < 0 || res >= (int) sizeof(buf)) |
| 8691 | return -1; |
| 8692 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 8693 | if (system(buf) != 0) { |
| 8694 | send_resp(dut, conn, SIGMA_ERROR, |
| 8695 | "errorCode,Failed to set offchan"); |
| 8696 | return 0; |
| 8697 | } |
| 8698 | |
| 8699 | res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsecchnoffst %d", |
| 8700 | intf, off_chan_val(sec)); |
| 8701 | if (res < 0 || res >= (int) sizeof(buf)) |
| 8702 | return -1; |
| 8703 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 8704 | if (system(buf) != 0) { |
| 8705 | send_resp(dut, conn, SIGMA_ERROR, |
| 8706 | "errorCode,Failed to set sec chan offset"); |
| 8707 | return 0; |
| 8708 | } |
| 8709 | |
| 8710 | return 1; |
| 8711 | } |
| 8712 | |
| 8713 | |
| 8714 | static int tdls_set_offchannel_offset(struct sigma_dut *dut, |
| 8715 | struct sigma_conn *conn, |
| 8716 | const char *intf, int off_ch_num, |
| 8717 | enum sec_ch_offset sec) |
| 8718 | { |
| 8719 | char buf[200]; |
| 8720 | int res; |
| 8721 | |
| 8722 | res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNEL %d", |
| 8723 | off_ch_num); |
| 8724 | if (res < 0 || res >= (int) sizeof(buf)) |
| 8725 | return -1; |
| 8726 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 8727 | |
| 8728 | if (wpa_command(intf, buf) < 0) { |
| 8729 | send_resp(dut, conn, SIGMA_ERROR, |
| 8730 | "ErrorCode,Failed to set offchan"); |
| 8731 | return 0; |
| 8732 | } |
| 8733 | res = snprintf(buf, sizeof(buf), "DRIVER TDLSSECONDARYCHANNELOFFSET %d", |
| 8734 | off_chan_val(sec)); |
| 8735 | if (res < 0 || res >= (int) sizeof(buf)) |
| 8736 | return -1; |
| 8737 | |
| 8738 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 8739 | |
| 8740 | if (wpa_command(intf, buf) < 0) { |
| 8741 | send_resp(dut, conn, SIGMA_ERROR, |
| 8742 | "ErrorCode,Failed to set sec chan offset"); |
| 8743 | return 0; |
| 8744 | } |
| 8745 | |
| 8746 | return 1; |
| 8747 | } |
| 8748 | |
| 8749 | |
| 8750 | static int tdls_set_offchannel_mode(struct sigma_dut *dut, |
| 8751 | struct sigma_conn *conn, |
| 8752 | const char *intf, int val) |
| 8753 | { |
| 8754 | char buf[200]; |
| 8755 | int res; |
| 8756 | |
| 8757 | res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNELMODE %d", |
| 8758 | val); |
| 8759 | if (res < 0 || res >= (int) sizeof(buf)) |
| 8760 | return -1; |
| 8761 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 8762 | |
| 8763 | if (wpa_command(intf, buf) < 0) { |
| 8764 | send_resp(dut, conn, SIGMA_ERROR, |
| 8765 | "ErrorCode,Failed to configure offchannel mode"); |
| 8766 | return 0; |
| 8767 | } |
| 8768 | |
| 8769 | return 1; |
| 8770 | } |
| 8771 | |
| 8772 | |
| 8773 | static int cmd_sta_set_rfeature_tdls(const char *intf, struct sigma_dut *dut, |
| 8774 | struct sigma_conn *conn, |
| 8775 | struct sigma_cmd *cmd) |
| 8776 | { |
| 8777 | const char *val; |
| 8778 | enum { |
| 8779 | CHSM_NOT_SET, |
| 8780 | CHSM_ENABLE, |
| 8781 | CHSM_DISABLE, |
| 8782 | CHSM_REJREQ, |
| 8783 | CHSM_UNSOLRESP |
| 8784 | } chsm = CHSM_NOT_SET; |
| 8785 | int off_ch_num = -1; |
| 8786 | enum sec_ch_offset sec_ch = SEC_CH_NO; |
| 8787 | int res; |
| 8788 | |
| 8789 | val = get_param(cmd, "Uapsd"); |
| 8790 | if (val) { |
| 8791 | char buf[100]; |
| 8792 | if (strcasecmp(val, "Enable") == 0) |
| 8793 | snprintf(buf, sizeof(buf), "SET ps 99"); |
| 8794 | else if (strcasecmp(val, "Disable") == 0) |
| 8795 | snprintf(buf, sizeof(buf), "SET ps 98"); |
| 8796 | else { |
| 8797 | send_resp(dut, conn, SIGMA_ERROR, "errorCode," |
| 8798 | "Unsupported uapsd parameter value"); |
| 8799 | return 0; |
| 8800 | } |
| 8801 | if (wpa_command(intf, buf)) { |
| 8802 | send_resp(dut, conn, SIGMA_ERROR, |
| 8803 | "ErrorCode,Failed to change U-APSD " |
| 8804 | "powersave mode"); |
| 8805 | return 0; |
| 8806 | } |
| 8807 | } |
| 8808 | |
| 8809 | val = get_param(cmd, "TPKTIMER"); |
| 8810 | if (val && strcasecmp(val, "DISABLE") == 0) { |
| 8811 | if (wpa_command(intf, "SET tdls_testing 0x100")) { |
| 8812 | send_resp(dut, conn, SIGMA_ERROR, |
| 8813 | "ErrorCode,Failed to enable no TPK " |
| 8814 | "expiration test mode"); |
| 8815 | return 0; |
| 8816 | } |
| 8817 | dut->no_tpk_expiration = 1; |
| 8818 | } |
| 8819 | |
| 8820 | val = get_param(cmd, "ChSwitchMode"); |
| 8821 | if (val) { |
| 8822 | if (strcasecmp(val, "Enable") == 0 || |
| 8823 | strcasecmp(val, "Initiate") == 0) |
| 8824 | chsm = CHSM_ENABLE; |
| 8825 | else if (strcasecmp(val, "Disable") == 0 || |
| 8826 | strcasecmp(val, "passive") == 0) |
| 8827 | chsm = CHSM_DISABLE; |
| 8828 | else if (strcasecmp(val, "RejReq") == 0) |
| 8829 | chsm = CHSM_REJREQ; |
| 8830 | else if (strcasecmp(val, "UnSolResp") == 0) |
| 8831 | chsm = CHSM_UNSOLRESP; |
| 8832 | else { |
| 8833 | send_resp(dut, conn, SIGMA_ERROR, |
| 8834 | "ErrorCode,Unknown ChSwitchMode value"); |
| 8835 | return 0; |
| 8836 | } |
| 8837 | } |
| 8838 | |
| 8839 | val = get_param(cmd, "OffChNum"); |
| 8840 | if (val) { |
| 8841 | off_ch_num = atoi(val); |
| 8842 | if (off_ch_num == 0) { |
| 8843 | send_resp(dut, conn, SIGMA_ERROR, |
| 8844 | "ErrorCode,Invalid OffChNum"); |
| 8845 | return 0; |
| 8846 | } |
| 8847 | } |
| 8848 | |
| 8849 | val = get_param(cmd, "SecChOffset"); |
| 8850 | if (val) { |
| 8851 | if (strcmp(val, "20") == 0) |
| 8852 | sec_ch = SEC_CH_NO; |
| 8853 | else if (strcasecmp(val, "40above") == 0) |
| 8854 | sec_ch = SEC_CH_40ABOVE; |
| 8855 | else if (strcasecmp(val, "40below") == 0) |
| 8856 | sec_ch = SEC_CH_40BELOW; |
| 8857 | else { |
| 8858 | send_resp(dut, conn, SIGMA_ERROR, |
| 8859 | "ErrorCode,Unknown SecChOffset value"); |
| 8860 | return 0; |
| 8861 | } |
| 8862 | } |
| 8863 | |
| 8864 | if (chsm == CHSM_NOT_SET) { |
| 8865 | /* no offchannel changes requested */ |
| 8866 | return 1; |
| 8867 | } |
| 8868 | |
| 8869 | if (strcmp(intf, get_main_ifname()) != 0 && |
| 8870 | strcmp(intf, get_station_ifname()) != 0) { |
| 8871 | send_resp(dut, conn, SIGMA_ERROR, |
| 8872 | "ErrorCode,Unknown interface"); |
| 8873 | return 0; |
| 8874 | } |
| 8875 | |
| 8876 | switch (chsm) { |
| 8877 | case CHSM_NOT_SET: |
Jouni Malinen | 280f5ba | 2016-08-29 21:33:10 +0300 | [diff] [blame] | 8878 | res = 1; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8879 | break; |
| 8880 | case CHSM_ENABLE: |
| 8881 | if (off_ch_num < 0) { |
| 8882 | send_resp(dut, conn, SIGMA_ERROR, |
| 8883 | "ErrorCode,Missing OffChNum argument"); |
| 8884 | return 0; |
| 8885 | } |
| 8886 | if (wifi_chip_type == DRIVER_WCN) { |
| 8887 | res = tdls_set_offchannel_offset(dut, conn, intf, |
| 8888 | off_ch_num, sec_ch); |
| 8889 | } else { |
| 8890 | res = iwpriv_set_offchan(dut, conn, intf, off_ch_num, |
| 8891 | sec_ch); |
| 8892 | } |
| 8893 | if (res != 1) |
| 8894 | return res; |
| 8895 | if (wifi_chip_type == DRIVER_WCN) |
| 8896 | res = tdls_set_offchannel_mode(dut, conn, intf, 1); |
| 8897 | else |
| 8898 | res = iwpriv_tdlsoffchnmode(dut, conn, intf, 1); |
| 8899 | break; |
| 8900 | case CHSM_DISABLE: |
| 8901 | if (wifi_chip_type == DRIVER_WCN) |
| 8902 | res = tdls_set_offchannel_mode(dut, conn, intf, 2); |
| 8903 | else |
| 8904 | res = iwpriv_tdlsoffchnmode(dut, conn, intf, 2); |
| 8905 | break; |
| 8906 | case CHSM_REJREQ: |
| 8907 | if (wifi_chip_type == DRIVER_WCN) |
| 8908 | res = tdls_set_offchannel_mode(dut, conn, intf, 3); |
| 8909 | else |
| 8910 | res = iwpriv_tdlsoffchnmode(dut, conn, intf, 3); |
| 8911 | break; |
| 8912 | case CHSM_UNSOLRESP: |
| 8913 | if (off_ch_num < 0) { |
| 8914 | send_resp(dut, conn, SIGMA_ERROR, |
| 8915 | "ErrorCode,Missing OffChNum argument"); |
| 8916 | return 0; |
| 8917 | } |
| 8918 | if (wifi_chip_type == DRIVER_WCN) { |
| 8919 | res = tdls_set_offchannel_offset(dut, conn, intf, |
| 8920 | off_ch_num, sec_ch); |
| 8921 | } else { |
| 8922 | res = iwpriv_set_offchan(dut, conn, intf, off_ch_num, |
| 8923 | sec_ch); |
| 8924 | } |
| 8925 | if (res != 1) |
| 8926 | return res; |
| 8927 | if (wifi_chip_type == DRIVER_WCN) |
| 8928 | res = tdls_set_offchannel_mode(dut, conn, intf, 4); |
| 8929 | else |
| 8930 | res = iwpriv_tdlsoffchnmode(dut, conn, intf, 4); |
| 8931 | break; |
| 8932 | } |
| 8933 | |
| 8934 | return res; |
| 8935 | } |
| 8936 | |
| 8937 | |
| 8938 | static int ath_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut, |
| 8939 | struct sigma_conn *conn, |
| 8940 | struct sigma_cmd *cmd) |
| 8941 | { |
| 8942 | const char *val; |
| 8943 | char *token, *result; |
| 8944 | |
priyadharshini gowthaman | e5e2517 | 2015-12-08 14:53:48 -0800 | [diff] [blame] | 8945 | novap_reset(dut, intf); |
| 8946 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8947 | val = get_param(cmd, "nss_mcs_opt"); |
| 8948 | if (val) { |
| 8949 | /* String (nss_operating_mode; mcs_operating_mode) */ |
| 8950 | int nss, mcs; |
| 8951 | char buf[50]; |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 8952 | char *saveptr; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8953 | |
| 8954 | token = strdup(val); |
| 8955 | if (!token) |
| 8956 | return 0; |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 8957 | result = strtok_r(token, ";", &saveptr); |
Pradeep Reddy POTTETI | 41b8c54 | 2016-06-15 16:09:46 +0530 | [diff] [blame] | 8958 | if (!result) { |
| 8959 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8960 | "VHT NSS not specified"); |
| 8961 | goto failed; |
| 8962 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8963 | if (strcasecmp(result, "def") != 0) { |
| 8964 | nss = atoi(result); |
| 8965 | if (nss == 4) |
| 8966 | ath_disable_txbf(dut, intf); |
| 8967 | snprintf(buf, sizeof(buf), "iwpriv %s nss %d", |
| 8968 | intf, nss); |
| 8969 | if (system(buf) != 0) { |
| 8970 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8971 | "iwpriv nss failed"); |
| 8972 | goto failed; |
| 8973 | } |
| 8974 | } |
| 8975 | |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 8976 | result = strtok_r(NULL, ";", &saveptr); |
Pradeep Reddy POTTETI | 41b8c54 | 2016-06-15 16:09:46 +0530 | [diff] [blame] | 8977 | if (!result) { |
| 8978 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8979 | "VHT MCS not specified"); |
| 8980 | goto failed; |
| 8981 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8982 | if (strcasecmp(result, "def") == 0) { |
| 8983 | snprintf(buf, sizeof(buf), "iwpriv %s set11NRates 0", |
| 8984 | intf); |
| 8985 | if (system(buf) != 0) { |
| 8986 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8987 | "iwpriv set11NRates failed"); |
| 8988 | goto failed; |
| 8989 | } |
| 8990 | |
| 8991 | } else { |
| 8992 | mcs = atoi(result); |
| 8993 | snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs %d", |
| 8994 | intf, mcs); |
| 8995 | if (system(buf) != 0) { |
| 8996 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8997 | "iwpriv vhtmcs failed"); |
| 8998 | goto failed; |
| 8999 | } |
| 9000 | } |
| 9001 | /* Channel width gets messed up, fix this */ |
| 9002 | snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d", |
| 9003 | intf, dut->chwidth); |
| 9004 | if (system(buf) != 0) { |
| 9005 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 9006 | "iwpriv chwidth failed"); |
| 9007 | } |
| 9008 | } |
| 9009 | |
| 9010 | return 1; |
| 9011 | failed: |
| 9012 | free(token); |
| 9013 | return 0; |
| 9014 | } |
| 9015 | |
| 9016 | |
| 9017 | static int cmd_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut, |
| 9018 | struct sigma_conn *conn, |
| 9019 | struct sigma_cmd *cmd) |
| 9020 | { |
| 9021 | switch (get_driver_type()) { |
| 9022 | case DRIVER_ATHEROS: |
| 9023 | return ath_sta_set_rfeature_vht(intf, dut, conn, cmd); |
| 9024 | default: |
| 9025 | send_resp(dut, conn, SIGMA_ERROR, |
| 9026 | "errorCode,Unsupported sta_set_rfeature(VHT) with the current driver"); |
| 9027 | return 0; |
| 9028 | } |
| 9029 | } |
| 9030 | |
| 9031 | |
Amarnath Hullur Subramanyam | 42c25a0 | 2018-01-31 04:02:27 -0800 | [diff] [blame] | 9032 | static int wcn_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut, |
| 9033 | struct sigma_conn *conn, |
| 9034 | struct sigma_cmd *cmd) |
| 9035 | { |
| 9036 | const char *val; |
| 9037 | char *token = NULL, *result; |
| 9038 | char buf[60]; |
| 9039 | |
| 9040 | val = get_param(cmd, "nss_mcs_opt"); |
| 9041 | if (val) { |
| 9042 | /* String (nss_operating_mode; mcs_operating_mode) */ |
| 9043 | int nss, mcs, ratecode; |
| 9044 | char *saveptr; |
| 9045 | |
| 9046 | token = strdup(val); |
| 9047 | if (!token) |
| 9048 | return -2; |
| 9049 | |
| 9050 | result = strtok_r(token, ";", &saveptr); |
| 9051 | if (!result) { |
| 9052 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 9053 | "HE NSS not specified"); |
| 9054 | goto failed; |
| 9055 | } |
| 9056 | nss = 1; |
| 9057 | if (strcasecmp(result, "def") != 0) |
| 9058 | nss = atoi(result); |
| 9059 | |
| 9060 | result = strtok_r(NULL, ";", &saveptr); |
| 9061 | if (!result) { |
| 9062 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 9063 | "HE MCS not specified"); |
| 9064 | goto failed; |
| 9065 | } |
| 9066 | mcs = 7; |
| 9067 | if (strcasecmp(result, "def") != 0) |
| 9068 | mcs = atoi(result); |
| 9069 | |
Arif Hussain | 557bf41 | 2018-05-25 17:29:36 -0700 | [diff] [blame] | 9070 | ratecode = 0x20; /* for nss:1 MCS 0 */ |
Amarnath Hullur Subramanyam | 42c25a0 | 2018-01-31 04:02:27 -0800 | [diff] [blame] | 9071 | if (nss == 2) { |
Arif Hussain | 557bf41 | 2018-05-25 17:29:36 -0700 | [diff] [blame] | 9072 | ratecode = 0x40; /* for nss:2 MCS 0 */ |
Amarnath Hullur Subramanyam | 42c25a0 | 2018-01-31 04:02:27 -0800 | [diff] [blame] | 9073 | } else if (nss > 2) { |
| 9074 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 9075 | "HE NSS %d not supported", nss); |
| 9076 | goto failed; |
| 9077 | } |
| 9078 | |
Arif Hussain | 557bf41 | 2018-05-25 17:29:36 -0700 | [diff] [blame] | 9079 | snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss); |
| 9080 | if (system(buf) != 0) { |
| 9081 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 9082 | "nss_mcs_opt: iwpriv %s nss %d failed", |
| 9083 | intf, nss); |
| 9084 | goto failed; |
| 9085 | } |
Arif Hussain | ac6c511 | 2018-05-25 17:34:00 -0700 | [diff] [blame^] | 9086 | dut->sta_nss = nss; |
Arif Hussain | 557bf41 | 2018-05-25 17:29:36 -0700 | [diff] [blame] | 9087 | |
Amarnath Hullur Subramanyam | 42c25a0 | 2018-01-31 04:02:27 -0800 | [diff] [blame] | 9088 | /* Add the MCS to the ratecode */ |
| 9089 | if (mcs >= 0 && mcs <= 11) { |
| 9090 | ratecode += mcs; |
Arif Hussain | 557bf41 | 2018-05-25 17:29:36 -0700 | [diff] [blame] | 9091 | #ifdef NL80211_SUPPORT |
| 9092 | if (dut->device_type == STA_testbed) { |
| 9093 | enum he_mcs_config mcs_config; |
| 9094 | int ret; |
| 9095 | |
| 9096 | if (mcs <= 7) |
| 9097 | mcs_config = HE_80_MCS0_7; |
| 9098 | else if (mcs <= 9) |
| 9099 | mcs_config = HE_80_MCS0_9; |
| 9100 | else |
| 9101 | mcs_config = HE_80_MCS0_11; |
| 9102 | ret = sta_set_he_mcs(dut, intf, mcs_config); |
| 9103 | if (ret) { |
| 9104 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 9105 | "nss_mcs_opt: mcs setting failed, mcs:%d, mcs_config %d, ret:%d", |
| 9106 | mcs, mcs_config, ret); |
| 9107 | goto failed; |
| 9108 | } |
| 9109 | } |
| 9110 | #endif /* NL80211_SUPPORT */ |
Amarnath Hullur Subramanyam | 42c25a0 | 2018-01-31 04:02:27 -0800 | [diff] [blame] | 9111 | } else { |
| 9112 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 9113 | "HE MCS %d not supported", mcs); |
| 9114 | goto failed; |
| 9115 | } |
| 9116 | snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0x%03x", |
| 9117 | intf, ratecode); |
| 9118 | if (system(buf) != 0) { |
| 9119 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 9120 | "iwpriv setting of 11ax rates failed"); |
| 9121 | goto failed; |
| 9122 | } |
| 9123 | free(token); |
| 9124 | } |
| 9125 | |
| 9126 | val = get_param(cmd, "GI"); |
| 9127 | if (val) { |
| 9128 | if (strcmp(val, "0.8") == 0) { |
Kiran Kumar Lokere | b8fec52 | 2018-05-01 14:26:00 -0700 | [diff] [blame] | 9129 | snprintf(buf, sizeof(buf), "iwpriv %s shortgi 9", intf); |
Amarnath Hullur Subramanyam | 42c25a0 | 2018-01-31 04:02:27 -0800 | [diff] [blame] | 9130 | } else if (strcmp(val, "1.6") == 0) { |
Kiran Kumar Lokere | b8fec52 | 2018-05-01 14:26:00 -0700 | [diff] [blame] | 9131 | snprintf(buf, sizeof(buf), "iwpriv %s shortgi 10", |
| 9132 | intf); |
Amarnath Hullur Subramanyam | 42c25a0 | 2018-01-31 04:02:27 -0800 | [diff] [blame] | 9133 | } else if (strcmp(val, "3.2") == 0) { |
Kiran Kumar Lokere | b8fec52 | 2018-05-01 14:26:00 -0700 | [diff] [blame] | 9134 | snprintf(buf, sizeof(buf), "iwpriv %s shortgi 11", |
| 9135 | intf); |
Amarnath Hullur Subramanyam | 42c25a0 | 2018-01-31 04:02:27 -0800 | [diff] [blame] | 9136 | } else { |
| 9137 | send_resp(dut, conn, SIGMA_ERROR, |
| 9138 | "errorCode,GI value not supported"); |
| 9139 | return 0; |
| 9140 | } |
| 9141 | if (system(buf) != 0) { |
| 9142 | send_resp(dut, conn, SIGMA_ERROR, |
| 9143 | "errorCode,Failed to set shortgi"); |
| 9144 | return 0; |
| 9145 | } |
| 9146 | } |
| 9147 | |
Subhani Shaik | 8e7a305 | 2018-04-24 14:03:00 -0700 | [diff] [blame] | 9148 | val = get_param(cmd, "LTF"); |
| 9149 | if (val) { |
| 9150 | #ifdef NL80211_SUPPORT |
| 9151 | if (strcmp(val, "3.2") == 0) { |
| 9152 | sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_1X); |
| 9153 | } if (strcmp(val, "6.4") == 0) { |
| 9154 | sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_2X); |
| 9155 | } else if (strcmp(val, "12.8") == 0) { |
| 9156 | sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_4X); |
| 9157 | } else { |
| 9158 | send_resp(dut, conn, SIGMA_ERROR, |
| 9159 | "errorCode, LTF value not supported"); |
| 9160 | return 0; |
| 9161 | } |
| 9162 | #else /* NL80211_SUPPORT */ |
| 9163 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 9164 | "LTF cannot be set without NL80211_SUPPORT defined"); |
| 9165 | return -2; |
| 9166 | #endif /* NL80211_SUPPORT */ |
| 9167 | } |
| 9168 | |
Amarnath Hullur Subramanyam | 42c25a0 | 2018-01-31 04:02:27 -0800 | [diff] [blame] | 9169 | return 1; |
| 9170 | |
| 9171 | failed: |
| 9172 | free(token); |
| 9173 | return -2; |
| 9174 | } |
| 9175 | |
| 9176 | |
| 9177 | static int cmd_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut, |
| 9178 | struct sigma_conn *conn, |
| 9179 | struct sigma_cmd *cmd) |
| 9180 | { |
| 9181 | switch (get_driver_type()) { |
| 9182 | case DRIVER_WCN: |
| 9183 | return wcn_sta_set_rfeature_he(intf, dut, conn, cmd); |
| 9184 | default: |
| 9185 | send_resp(dut, conn, SIGMA_ERROR, |
| 9186 | "errorCode,Unsupported sta_set_rfeature(HE) with the current driver"); |
| 9187 | return 0; |
| 9188 | } |
| 9189 | } |
| 9190 | |
| 9191 | |
Ashwini Patil | 5acd738 | 2017-04-13 15:55:04 +0530 | [diff] [blame] | 9192 | static int btm_query_candidate_list(struct sigma_dut *dut, |
| 9193 | struct sigma_conn *conn, |
| 9194 | struct sigma_cmd *cmd) |
| 9195 | { |
| 9196 | const char *bssid, *info, *op_class, *ch, *phy_type, *pref; |
| 9197 | int len, ret; |
| 9198 | char buf[10]; |
| 9199 | |
| 9200 | /* |
| 9201 | * Neighbor Report elements format: |
| 9202 | * neighbor=<BSSID>,<BSSID Information>,<Operating Class>, |
| 9203 | * <Channel Number>,<PHY Type>[,<hexdump of Optional Subelements>] |
| 9204 | * eg: neighbor=aa:bb:cc:dd:ee:ff,17,81,6,1,030101 |
| 9205 | */ |
| 9206 | |
| 9207 | bssid = get_param(cmd, "Nebor_BSSID"); |
| 9208 | if (!bssid) { |
| 9209 | send_resp(dut, conn, SIGMA_INVALID, |
| 9210 | "errorCode,Nebor_BSSID is missing"); |
| 9211 | return 0; |
| 9212 | } |
| 9213 | |
| 9214 | info = get_param(cmd, "Nebor_Bssid_Info"); |
| 9215 | if (!info) { |
| 9216 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 9217 | "Using default value for Nebor_Bssid_Info: %s", |
| 9218 | DEFAULT_NEIGHBOR_BSSID_INFO); |
| 9219 | info = DEFAULT_NEIGHBOR_BSSID_INFO; |
| 9220 | } |
| 9221 | |
| 9222 | op_class = get_param(cmd, "Nebor_Op_Class"); |
| 9223 | if (!op_class) { |
| 9224 | send_resp(dut, conn, SIGMA_INVALID, |
| 9225 | "errorCode,Nebor_Op_Class is missing"); |
| 9226 | return 0; |
| 9227 | } |
| 9228 | |
| 9229 | ch = get_param(cmd, "Nebor_Op_Ch"); |
| 9230 | if (!ch) { |
| 9231 | send_resp(dut, conn, SIGMA_INVALID, |
| 9232 | "errorCode,Nebor_Op_Ch is missing"); |
| 9233 | return 0; |
| 9234 | } |
| 9235 | |
| 9236 | phy_type = get_param(cmd, "Nebor_Phy_Type"); |
| 9237 | if (!phy_type) { |
| 9238 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 9239 | "Using default value for Nebor_Phy_Type: %s", |
| 9240 | DEFAULT_NEIGHBOR_PHY_TYPE); |
| 9241 | phy_type = DEFAULT_NEIGHBOR_PHY_TYPE; |
| 9242 | } |
| 9243 | |
| 9244 | /* Parse optional subelements */ |
| 9245 | buf[0] = '\0'; |
| 9246 | pref = get_param(cmd, "Nebor_Pref"); |
| 9247 | if (pref) { |
| 9248 | /* hexdump for preferrence subelement */ |
| 9249 | ret = snprintf(buf, sizeof(buf), ",0301%02x", atoi(pref)); |
| 9250 | if (ret < 0 || ret >= (int) sizeof(buf)) { |
| 9251 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 9252 | "snprintf failed for optional subelement ret: %d", |
| 9253 | ret); |
| 9254 | send_resp(dut, conn, SIGMA_ERROR, |
| 9255 | "errorCode,snprintf failed for subelement"); |
| 9256 | return 0; |
| 9257 | } |
| 9258 | } |
| 9259 | |
| 9260 | if (!dut->btm_query_cand_list) { |
| 9261 | dut->btm_query_cand_list = calloc(1, NEIGHBOR_REPORT_SIZE); |
| 9262 | if (!dut->btm_query_cand_list) { |
| 9263 | send_resp(dut, conn, SIGMA_ERROR, |
| 9264 | "errorCode,Failed to allocate memory for btm_query_cand_list"); |
| 9265 | return 0; |
| 9266 | } |
| 9267 | } |
| 9268 | |
| 9269 | len = strlen(dut->btm_query_cand_list); |
| 9270 | ret = snprintf(dut->btm_query_cand_list + len, |
| 9271 | NEIGHBOR_REPORT_SIZE - len, " neighbor=%s,%s,%s,%s,%s%s", |
| 9272 | bssid, info, op_class, ch, phy_type, buf); |
| 9273 | if (ret < 0 || ret >= NEIGHBOR_REPORT_SIZE - len) { |
| 9274 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 9275 | "snprintf failed for neighbor report list ret: %d", |
| 9276 | ret); |
| 9277 | send_resp(dut, conn, SIGMA_ERROR, |
| 9278 | "errorCode,snprintf failed for neighbor report"); |
| 9279 | free(dut->btm_query_cand_list); |
| 9280 | dut->btm_query_cand_list = NULL; |
| 9281 | return 0; |
| 9282 | } |
| 9283 | |
| 9284 | return 1; |
| 9285 | } |
| 9286 | |
| 9287 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 9288 | static int cmd_sta_set_rfeature(struct sigma_dut *dut, struct sigma_conn *conn, |
| 9289 | struct sigma_cmd *cmd) |
| 9290 | { |
| 9291 | const char *intf = get_param(cmd, "Interface"); |
| 9292 | const char *prog = get_param(cmd, "Prog"); |
Ashwini Patil | 68d02cd | 2017-01-10 15:39:16 +0530 | [diff] [blame] | 9293 | const char *val; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 9294 | |
| 9295 | if (intf == NULL || prog == NULL) |
| 9296 | return -1; |
| 9297 | |
Ashwini Patil | 5acd738 | 2017-04-13 15:55:04 +0530 | [diff] [blame] | 9298 | /* BSS Transition candidate list for BTM query */ |
| 9299 | val = get_param(cmd, "Nebor_BSSID"); |
| 9300 | if (val && btm_query_candidate_list(dut, conn, cmd) == 0) |
| 9301 | return 0; |
| 9302 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 9303 | if (strcasecmp(prog, "TDLS") == 0) |
| 9304 | return cmd_sta_set_rfeature_tdls(intf, dut, conn, cmd); |
| 9305 | |
| 9306 | if (strcasecmp(prog, "VHT") == 0) |
| 9307 | return cmd_sta_set_rfeature_vht(intf, dut, conn, cmd); |
| 9308 | |
Amarnath Hullur Subramanyam | 42c25a0 | 2018-01-31 04:02:27 -0800 | [diff] [blame] | 9309 | if (strcasecmp(prog, "HE") == 0) |
| 9310 | return cmd_sta_set_rfeature_he(intf, dut, conn, cmd); |
| 9311 | |
Ashwini Patil | 68d02cd | 2017-01-10 15:39:16 +0530 | [diff] [blame] | 9312 | if (strcasecmp(prog, "MBO") == 0) { |
| 9313 | val = get_param(cmd, "Cellular_Data_Cap"); |
| 9314 | if (val && |
| 9315 | mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0) |
| 9316 | return 0; |
Ashwini Patil | 0040258 | 2017-04-13 12:29:39 +0530 | [diff] [blame] | 9317 | |
| 9318 | val = get_param(cmd, "Ch_Pref"); |
| 9319 | if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0) |
| 9320 | return 0; |
| 9321 | |
Ashwini Patil | 68d02cd | 2017-01-10 15:39:16 +0530 | [diff] [blame] | 9322 | return 1; |
| 9323 | } |
| 9324 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 9325 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported Prog"); |
| 9326 | return 0; |
| 9327 | } |
| 9328 | |
| 9329 | |
| 9330 | static int cmd_sta_set_radio(struct sigma_dut *dut, struct sigma_conn *conn, |
| 9331 | struct sigma_cmd *cmd) |
| 9332 | { |
| 9333 | const char *intf = get_param(cmd, "Interface"); |
| 9334 | const char *mode = get_param(cmd, "Mode"); |
| 9335 | int res; |
| 9336 | |
| 9337 | if (intf == NULL || mode == NULL) |
| 9338 | return -1; |
| 9339 | |
| 9340 | if (strcasecmp(mode, "On") == 0) |
| 9341 | res = wpa_command(intf, "SET radio_disabled 0"); |
| 9342 | else if (strcasecmp(mode, "Off") == 0) |
| 9343 | res = wpa_command(intf, "SET radio_disabled 1"); |
| 9344 | else |
| 9345 | return -1; |
| 9346 | |
| 9347 | if (res) { |
| 9348 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change " |
| 9349 | "radio mode"); |
| 9350 | return 0; |
| 9351 | } |
| 9352 | |
| 9353 | return 1; |
| 9354 | } |
| 9355 | |
| 9356 | |
| 9357 | static int cmd_sta_set_pwrsave(struct sigma_dut *dut, struct sigma_conn *conn, |
| 9358 | struct sigma_cmd *cmd) |
| 9359 | { |
| 9360 | const char *intf = get_param(cmd, "Interface"); |
| 9361 | const char *mode = get_param(cmd, "Mode"); |
| 9362 | int res; |
| 9363 | |
| 9364 | if (intf == NULL || mode == NULL) |
| 9365 | return -1; |
| 9366 | |
| 9367 | if (strcasecmp(mode, "On") == 0) |
| 9368 | res = set_ps(intf, dut, 1); |
| 9369 | else if (strcasecmp(mode, "Off") == 0) |
| 9370 | res = set_ps(intf, dut, 0); |
| 9371 | else |
| 9372 | return -1; |
| 9373 | |
| 9374 | if (res) { |
| 9375 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change " |
| 9376 | "power save mode"); |
| 9377 | return 0; |
| 9378 | } |
| 9379 | |
| 9380 | return 1; |
| 9381 | } |
| 9382 | |
| 9383 | |
| 9384 | static int cmd_sta_bssid_pool(struct sigma_dut *dut, struct sigma_conn *conn, |
| 9385 | struct sigma_cmd *cmd) |
| 9386 | { |
| 9387 | const char *intf = get_param(cmd, "Interface"); |
| 9388 | const char *val, *bssid; |
| 9389 | int res; |
| 9390 | char *buf; |
| 9391 | size_t buf_len; |
| 9392 | |
| 9393 | val = get_param(cmd, "BSSID_FILTER"); |
| 9394 | if (val == NULL) |
| 9395 | return -1; |
| 9396 | |
| 9397 | bssid = get_param(cmd, "BSSID_List"); |
| 9398 | if (atoi(val) == 0 || bssid == NULL) { |
| 9399 | /* Disable BSSID filter */ |
| 9400 | if (wpa_command(intf, "SET bssid_filter ")) { |
| 9401 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed " |
| 9402 | "to disable BSSID filter"); |
| 9403 | return 0; |
| 9404 | } |
| 9405 | |
| 9406 | return 1; |
| 9407 | } |
| 9408 | |
| 9409 | buf_len = 100 + strlen(bssid); |
| 9410 | buf = malloc(buf_len); |
| 9411 | if (buf == NULL) |
| 9412 | return -1; |
| 9413 | |
| 9414 | snprintf(buf, buf_len, "SET bssid_filter %s", bssid); |
| 9415 | res = wpa_command(intf, buf); |
| 9416 | free(buf); |
| 9417 | if (res) { |
| 9418 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to enable " |
| 9419 | "BSSID filter"); |
| 9420 | return 0; |
| 9421 | } |
| 9422 | |
| 9423 | return 1; |
| 9424 | } |
| 9425 | |
| 9426 | |
| 9427 | static int cmd_sta_reset_parm(struct sigma_dut *dut, struct sigma_conn *conn, |
| 9428 | struct sigma_cmd *cmd) |
| 9429 | { |
| 9430 | const char *intf = get_param(cmd, "Interface"); |
| 9431 | const char *val; |
| 9432 | |
| 9433 | /* TODO: ARP */ |
| 9434 | |
| 9435 | val = get_param(cmd, "HS2_CACHE_PROFILE"); |
| 9436 | if (val && strcasecmp(val, "All") == 0) |
| 9437 | hs2_clear_credentials(intf); |
| 9438 | |
| 9439 | return 1; |
| 9440 | } |
| 9441 | |
| 9442 | |
| 9443 | static int cmd_sta_get_key(struct sigma_dut *dut, struct sigma_conn *conn, |
| 9444 | struct sigma_cmd *cmd) |
| 9445 | { |
| 9446 | const char *intf = get_param(cmd, "Interface"); |
| 9447 | const char *key_type = get_param(cmd, "KeyType"); |
| 9448 | char buf[100], resp[200]; |
| 9449 | |
| 9450 | if (key_type == NULL) |
| 9451 | return -1; |
| 9452 | |
| 9453 | if (strcasecmp(key_type, "GTK") == 0) { |
| 9454 | if (wpa_command_resp(intf, "GET gtk", buf, sizeof(buf)) < 0 || |
| 9455 | strncmp(buf, "FAIL", 4) == 0) { |
| 9456 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could " |
| 9457 | "not fetch current GTK"); |
| 9458 | return 0; |
| 9459 | } |
| 9460 | snprintf(resp, sizeof(resp), "KeyValue,%s", buf); |
| 9461 | send_resp(dut, conn, SIGMA_COMPLETE, resp); |
| 9462 | return 0; |
| 9463 | } else { |
| 9464 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported " |
| 9465 | "KeyType"); |
| 9466 | return 0; |
| 9467 | } |
| 9468 | |
| 9469 | return 1; |
| 9470 | } |
| 9471 | |
| 9472 | |
| 9473 | static int hs2_set_policy(struct sigma_dut *dut) |
| 9474 | { |
| 9475 | #ifdef ANDROID |
| 9476 | system("ip rule del prio 23000"); |
| 9477 | if (system("ip rule add from all lookup main prio 23000") != 0) { |
| 9478 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 9479 | "Failed to run:ip rule add from all lookup main prio"); |
| 9480 | return -1; |
| 9481 | } |
| 9482 | if (system("ip route flush cache") != 0) { |
| 9483 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 9484 | "Failed to run ip route flush cache"); |
| 9485 | return -1; |
| 9486 | } |
| 9487 | return 1; |
| 9488 | #else /* ANDROID */ |
| 9489 | return 0; |
| 9490 | #endif /* ANDROID */ |
| 9491 | } |
| 9492 | |
| 9493 | |
| 9494 | static int cmd_sta_hs2_associate(struct sigma_dut *dut, |
| 9495 | struct sigma_conn *conn, |
| 9496 | struct sigma_cmd *cmd) |
| 9497 | { |
| 9498 | const char *intf = get_param(cmd, "Interface"); |
| 9499 | const char *val = get_param(cmd, "Ignore_blacklist"); |
| 9500 | struct wpa_ctrl *ctrl; |
| 9501 | int res; |
| 9502 | char bssid[20], ssid[40], resp[100], buf[100], blacklisted[100]; |
| 9503 | int tries = 0; |
| 9504 | int ignore_blacklist = 0; |
| 9505 | const char *events[] = { |
| 9506 | "CTRL-EVENT-CONNECTED", |
| 9507 | "INTERWORKING-BLACKLISTED", |
| 9508 | "INTERWORKING-NO-MATCH", |
| 9509 | NULL |
| 9510 | }; |
| 9511 | |
| 9512 | start_sta_mode(dut); |
| 9513 | |
| 9514 | blacklisted[0] = '\0'; |
| 9515 | if (val && atoi(val)) |
| 9516 | ignore_blacklist = 1; |
| 9517 | |
| 9518 | try_again: |
| 9519 | ctrl = open_wpa_mon(intf); |
| 9520 | if (ctrl == NULL) { |
| 9521 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open " |
| 9522 | "wpa_supplicant monitor connection"); |
| 9523 | return -2; |
| 9524 | } |
| 9525 | |
| 9526 | tries++; |
| 9527 | if (wpa_command(intf, "INTERWORKING_SELECT auto")) { |
| 9528 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start " |
| 9529 | "Interworking connection"); |
| 9530 | wpa_ctrl_detach(ctrl); |
| 9531 | wpa_ctrl_close(ctrl); |
| 9532 | return 0; |
| 9533 | } |
| 9534 | |
| 9535 | buf[0] = '\0'; |
| 9536 | while (1) { |
| 9537 | char *pos; |
| 9538 | res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf)); |
| 9539 | pos = strstr(buf, "INTERWORKING-BLACKLISTED"); |
| 9540 | if (!pos) |
| 9541 | break; |
| 9542 | pos += 25; |
| 9543 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Found blacklisted AP: %s", |
| 9544 | pos); |
| 9545 | if (!blacklisted[0]) |
| 9546 | memcpy(blacklisted, pos, strlen(pos) + 1); |
| 9547 | } |
| 9548 | |
| 9549 | if (ignore_blacklist && blacklisted[0]) { |
| 9550 | char *end; |
| 9551 | end = strchr(blacklisted, ' '); |
| 9552 | if (end) |
| 9553 | *end = '\0'; |
| 9554 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Try to connect to a blacklisted network: %s", |
| 9555 | blacklisted); |
| 9556 | snprintf(buf, sizeof(buf), "INTERWORKING_CONNECT %s", |
| 9557 | blacklisted); |
| 9558 | if (wpa_command(intf, buf)) { |
| 9559 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start Interworking connection to blacklisted network"); |
| 9560 | wpa_ctrl_detach(ctrl); |
| 9561 | wpa_ctrl_close(ctrl); |
| 9562 | return 0; |
| 9563 | } |
| 9564 | res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED", |
| 9565 | buf, sizeof(buf)); |
| 9566 | } |
| 9567 | |
| 9568 | wpa_ctrl_detach(ctrl); |
| 9569 | wpa_ctrl_close(ctrl); |
| 9570 | |
| 9571 | if (res < 0) { |
| 9572 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not " |
| 9573 | "connect"); |
| 9574 | return 0; |
| 9575 | } |
| 9576 | |
| 9577 | if (strstr(buf, "INTERWORKING-NO-MATCH") || |
| 9578 | strstr(buf, "INTERWORKING-BLACKLISTED")) { |
| 9579 | if (tries < 2) { |
| 9580 | sigma_dut_print(dut, DUT_MSG_INFO, "No match found - try again to verify no APs were missed in the scan"); |
| 9581 | goto try_again; |
| 9582 | } |
| 9583 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,No network with " |
| 9584 | "matching credentials found"); |
| 9585 | return 0; |
| 9586 | } |
| 9587 | |
| 9588 | if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 || |
| 9589 | get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) { |
| 9590 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not " |
| 9591 | "get current BSSID/SSID"); |
| 9592 | return 0; |
| 9593 | } |
| 9594 | |
| 9595 | snprintf(resp, sizeof(resp), "SSID,%s,BSSID,%s", ssid, bssid); |
| 9596 | send_resp(dut, conn, SIGMA_COMPLETE, resp); |
| 9597 | hs2_set_policy(dut); |
| 9598 | return 0; |
| 9599 | } |
| 9600 | |
| 9601 | |
| 9602 | static int sta_add_credential_uname_pwd(struct sigma_dut *dut, |
| 9603 | struct sigma_conn *conn, |
| 9604 | const char *ifname, |
| 9605 | struct sigma_cmd *cmd) |
| 9606 | { |
| 9607 | const char *val; |
| 9608 | int id; |
| 9609 | |
| 9610 | id = add_cred(ifname); |
| 9611 | if (id < 0) |
| 9612 | return -2; |
| 9613 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id); |
| 9614 | |
| 9615 | val = get_param(cmd, "prefer"); |
| 9616 | if (val && atoi(val) > 0) |
| 9617 | set_cred(ifname, id, "priority", "1"); |
| 9618 | |
| 9619 | val = get_param(cmd, "REALM"); |
| 9620 | if (val && set_cred_quoted(ifname, id, "realm", val) < 0) { |
| 9621 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set " |
| 9622 | "realm"); |
| 9623 | return 0; |
| 9624 | } |
| 9625 | |
| 9626 | val = get_param(cmd, "HOME_FQDN"); |
| 9627 | if (val && set_cred_quoted(ifname, id, "domain", val) < 0) { |
| 9628 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set " |
| 9629 | "home_fqdn"); |
| 9630 | return 0; |
| 9631 | } |
| 9632 | |
| 9633 | val = get_param(cmd, "Username"); |
| 9634 | if (val && set_cred_quoted(ifname, id, "username", val) < 0) { |
| 9635 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set " |
| 9636 | "username"); |
| 9637 | return 0; |
| 9638 | } |
| 9639 | |
| 9640 | val = get_param(cmd, "Password"); |
| 9641 | if (val && set_cred_quoted(ifname, id, "password", val) < 0) { |
| 9642 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set " |
| 9643 | "password"); |
| 9644 | return 0; |
| 9645 | } |
| 9646 | |
| 9647 | val = get_param(cmd, "ROOT_CA"); |
| 9648 | if (val) { |
| 9649 | char fname[200]; |
| 9650 | snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val); |
| 9651 | #ifdef __linux__ |
| 9652 | if (!file_exists(fname)) { |
| 9653 | char msg[300]; |
| 9654 | snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA " |
| 9655 | "file (%s) not found", fname); |
| 9656 | send_resp(dut, conn, SIGMA_ERROR, msg); |
| 9657 | return 0; |
| 9658 | } |
| 9659 | #endif /* __linux__ */ |
| 9660 | if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) { |
| 9661 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could " |
| 9662 | "not set root CA"); |
| 9663 | return 0; |
| 9664 | } |
| 9665 | } |
| 9666 | |
| 9667 | return 1; |
| 9668 | } |
| 9669 | |
| 9670 | |
| 9671 | static int update_devdetail_imsi(struct sigma_dut *dut, const char *imsi) |
| 9672 | { |
| 9673 | FILE *in, *out; |
| 9674 | char buf[500]; |
| 9675 | int found = 0; |
| 9676 | |
| 9677 | in = fopen("devdetail.xml", "r"); |
| 9678 | if (in == NULL) |
| 9679 | return -1; |
| 9680 | out = fopen("devdetail.xml.tmp", "w"); |
| 9681 | if (out == NULL) { |
| 9682 | fclose(in); |
| 9683 | return -1; |
| 9684 | } |
| 9685 | |
| 9686 | while (fgets(buf, sizeof(buf), in)) { |
| 9687 | char *pos = strstr(buf, "<IMSI>"); |
| 9688 | if (pos) { |
| 9689 | sigma_dut_print(dut, DUT_MSG_INFO, "Updated DevDetail IMSI to %s", |
| 9690 | imsi); |
| 9691 | pos += 6; |
| 9692 | *pos = '\0'; |
| 9693 | fprintf(out, "%s%s</IMSI>\n", buf, imsi); |
| 9694 | found++; |
| 9695 | } else { |
| 9696 | fprintf(out, "%s", buf); |
| 9697 | } |
| 9698 | } |
| 9699 | |
| 9700 | fclose(out); |
| 9701 | fclose(in); |
| 9702 | if (found) |
| 9703 | rename("devdetail.xml.tmp", "devdetail.xml"); |
| 9704 | else |
| 9705 | unlink("devdetail.xml.tmp"); |
| 9706 | |
| 9707 | return 0; |
| 9708 | } |
| 9709 | |
| 9710 | |
| 9711 | static int sta_add_credential_sim(struct sigma_dut *dut, |
| 9712 | struct sigma_conn *conn, |
| 9713 | const char *ifname, struct sigma_cmd *cmd) |
| 9714 | { |
| 9715 | const char *val, *imsi = NULL; |
| 9716 | int id; |
| 9717 | char buf[200]; |
| 9718 | int res; |
| 9719 | const char *pos; |
| 9720 | size_t mnc_len; |
| 9721 | char plmn_mcc[4]; |
| 9722 | char plmn_mnc[4]; |
| 9723 | |
| 9724 | id = add_cred(ifname); |
| 9725 | if (id < 0) |
| 9726 | return -2; |
| 9727 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id); |
| 9728 | |
| 9729 | val = get_param(cmd, "prefer"); |
| 9730 | if (val && atoi(val) > 0) |
| 9731 | set_cred(ifname, id, "priority", "1"); |
| 9732 | |
| 9733 | val = get_param(cmd, "PLMN_MCC"); |
| 9734 | if (val == NULL) { |
| 9735 | send_resp(dut, conn, SIGMA_ERROR, |
| 9736 | "errorCode,Missing PLMN_MCC"); |
| 9737 | return 0; |
| 9738 | } |
| 9739 | if (strlen(val) != 3) { |
| 9740 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MCC"); |
| 9741 | return 0; |
| 9742 | } |
| 9743 | snprintf(plmn_mcc, sizeof(plmn_mcc), "%s", val); |
| 9744 | |
| 9745 | val = get_param(cmd, "PLMN_MNC"); |
| 9746 | if (val == NULL) { |
| 9747 | send_resp(dut, conn, SIGMA_ERROR, |
| 9748 | "errorCode,Missing PLMN_MNC"); |
| 9749 | return 0; |
| 9750 | } |
| 9751 | if (strlen(val) != 2 && strlen(val) != 3) { |
| 9752 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MNC"); |
| 9753 | return 0; |
| 9754 | } |
| 9755 | snprintf(plmn_mnc, sizeof(plmn_mnc), "%s", val); |
| 9756 | |
| 9757 | val = get_param(cmd, "IMSI"); |
| 9758 | if (val == NULL) { |
| 9759 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing SIM " |
| 9760 | "IMSI"); |
| 9761 | return 0; |
| 9762 | } |
| 9763 | |
| 9764 | imsi = pos = val; |
| 9765 | |
| 9766 | if (strncmp(plmn_mcc, pos, 3) != 0) { |
| 9767 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,MCC mismatch"); |
| 9768 | return 0; |
| 9769 | } |
| 9770 | pos += 3; |
| 9771 | |
| 9772 | mnc_len = strlen(plmn_mnc); |
| 9773 | if (mnc_len < 2) { |
| 9774 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC not set"); |
| 9775 | return 0; |
| 9776 | } |
| 9777 | |
| 9778 | if (strncmp(plmn_mnc, pos, mnc_len) != 0) { |
| 9779 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC mismatch"); |
| 9780 | return 0; |
| 9781 | } |
| 9782 | pos += mnc_len; |
| 9783 | |
| 9784 | res = snprintf(buf, sizeof(buf), "%s%s-%s",plmn_mcc, plmn_mnc, pos); |
| 9785 | if (res < 0 || res >= (int) sizeof(buf)) |
| 9786 | return -1; |
| 9787 | if (set_cred_quoted(ifname, id, "imsi", buf) < 0) { |
| 9788 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could " |
| 9789 | "not set IMSI"); |
| 9790 | return 0; |
| 9791 | } |
| 9792 | |
| 9793 | val = get_param(cmd, "Password"); |
| 9794 | if (val && set_cred_quoted(ifname, id, "milenage", val) < 0) { |
| 9795 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could " |
| 9796 | "not set password"); |
| 9797 | return 0; |
| 9798 | } |
| 9799 | |
| 9800 | if (dut->program == PROGRAM_HS2_R2) { |
| 9801 | /* |
| 9802 | * Set provisioning_sp for the test cases where SIM/USIM |
| 9803 | * provisioning is used. |
| 9804 | */ |
| 9805 | if (val && set_cred_quoted(ifname, id, "provisioning_sp", |
| 9806 | "wi-fi.org") < 0) { |
| 9807 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could " |
| 9808 | "not set provisioning_sp"); |
| 9809 | return 0; |
| 9810 | } |
| 9811 | |
| 9812 | update_devdetail_imsi(dut, imsi); |
| 9813 | } |
| 9814 | |
| 9815 | return 1; |
| 9816 | } |
| 9817 | |
| 9818 | |
| 9819 | static int sta_add_credential_cert(struct sigma_dut *dut, |
| 9820 | struct sigma_conn *conn, |
| 9821 | const char *ifname, |
| 9822 | struct sigma_cmd *cmd) |
| 9823 | { |
| 9824 | const char *val; |
| 9825 | int id; |
| 9826 | |
| 9827 | id = add_cred(ifname); |
| 9828 | if (id < 0) |
| 9829 | return -2; |
| 9830 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id); |
| 9831 | |
| 9832 | val = get_param(cmd, "prefer"); |
| 9833 | if (val && atoi(val) > 0) |
| 9834 | set_cred(ifname, id, "priority", "1"); |
| 9835 | |
| 9836 | val = get_param(cmd, "REALM"); |
| 9837 | if (val && set_cred_quoted(ifname, id, "realm", val) < 0) { |
| 9838 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set " |
| 9839 | "realm"); |
| 9840 | return 0; |
| 9841 | } |
| 9842 | |
| 9843 | val = get_param(cmd, "HOME_FQDN"); |
| 9844 | if (val && set_cred_quoted(ifname, id, "domain", val) < 0) { |
| 9845 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set " |
| 9846 | "home_fqdn"); |
| 9847 | return 0; |
| 9848 | } |
| 9849 | |
| 9850 | val = get_param(cmd, "Username"); |
| 9851 | if (val && set_cred_quoted(ifname, id, "username", val) < 0) { |
| 9852 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set " |
| 9853 | "username"); |
| 9854 | return 0; |
| 9855 | } |
| 9856 | |
| 9857 | val = get_param(cmd, "clientCertificate"); |
| 9858 | if (val) { |
| 9859 | char fname[200]; |
| 9860 | snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val); |
| 9861 | #ifdef __linux__ |
| 9862 | if (!file_exists(fname)) { |
| 9863 | char msg[300]; |
| 9864 | snprintf(msg, sizeof(msg), |
| 9865 | "ErrorCode,clientCertificate " |
| 9866 | "file (%s) not found", fname); |
| 9867 | send_resp(dut, conn, SIGMA_ERROR, msg); |
| 9868 | return 0; |
| 9869 | } |
| 9870 | #endif /* __linux__ */ |
| 9871 | if (set_cred_quoted(ifname, id, "client_cert", fname) < 0) { |
| 9872 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could " |
| 9873 | "not set client_cert"); |
| 9874 | return 0; |
| 9875 | } |
| 9876 | if (set_cred_quoted(ifname, id, "private_key", fname) < 0) { |
| 9877 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could " |
| 9878 | "not set private_key"); |
| 9879 | return 0; |
| 9880 | } |
| 9881 | } |
| 9882 | |
| 9883 | val = get_param(cmd, "ROOT_CA"); |
| 9884 | if (val) { |
| 9885 | char fname[200]; |
| 9886 | snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val); |
| 9887 | #ifdef __linux__ |
| 9888 | if (!file_exists(fname)) { |
| 9889 | char msg[300]; |
| 9890 | snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA " |
| 9891 | "file (%s) not found", fname); |
| 9892 | send_resp(dut, conn, SIGMA_ERROR, msg); |
| 9893 | return 0; |
| 9894 | } |
| 9895 | #endif /* __linux__ */ |
| 9896 | if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) { |
| 9897 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could " |
| 9898 | "not set root CA"); |
| 9899 | return 0; |
| 9900 | } |
| 9901 | } |
| 9902 | |
| 9903 | return 1; |
| 9904 | } |
| 9905 | |
| 9906 | |
| 9907 | static int cmd_sta_add_credential(struct sigma_dut *dut, |
| 9908 | struct sigma_conn *conn, |
| 9909 | struct sigma_cmd *cmd) |
| 9910 | { |
| 9911 | const char *intf = get_param(cmd, "Interface"); |
| 9912 | const char *type; |
| 9913 | |
| 9914 | start_sta_mode(dut); |
| 9915 | |
| 9916 | type = get_param(cmd, "Type"); |
| 9917 | if (!type) |
| 9918 | return -1; |
| 9919 | |
| 9920 | if (strcasecmp(type, "uname_pwd") == 0) |
| 9921 | return sta_add_credential_uname_pwd(dut, conn, intf, cmd); |
| 9922 | |
| 9923 | if (strcasecmp(type, "sim") == 0) |
| 9924 | return sta_add_credential_sim(dut, conn, intf, cmd); |
| 9925 | |
| 9926 | if (strcasecmp(type, "cert") == 0) |
| 9927 | return sta_add_credential_cert(dut, conn, intf, cmd); |
| 9928 | |
| 9929 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported credential " |
| 9930 | "type"); |
| 9931 | return 0; |
| 9932 | } |
| 9933 | |
| 9934 | |
| 9935 | static int cmd_sta_scan(struct sigma_dut *dut, struct sigma_conn *conn, |
| 9936 | struct sigma_cmd *cmd) |
| 9937 | { |
| 9938 | const char *intf = get_param(cmd, "Interface"); |
vamsi krishna | 89ad8c6 | 2017-09-19 12:51:18 +0530 | [diff] [blame] | 9939 | const char *val, *bssid, *ssid; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 9940 | char buf[100]; |
vamsi krishna | 89ad8c6 | 2017-09-19 12:51:18 +0530 | [diff] [blame] | 9941 | char ssid_hex[65]; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 9942 | int res; |
| 9943 | |
| 9944 | val = get_param(cmd, "HESSID"); |
| 9945 | if (val) { |
| 9946 | res = snprintf(buf, sizeof(buf), "SET hessid %s", val); |
| 9947 | if (res < 0 || res >= (int) sizeof(buf)) |
| 9948 | return -1; |
| 9949 | wpa_command(intf, buf); |
| 9950 | } |
| 9951 | |
| 9952 | val = get_param(cmd, "ACCS_NET_TYPE"); |
| 9953 | if (val) { |
| 9954 | res = snprintf(buf, sizeof(buf), "SET access_network_type %s", |
| 9955 | val); |
| 9956 | if (res < 0 || res >= (int) sizeof(buf)) |
| 9957 | return -1; |
| 9958 | wpa_command(intf, buf); |
| 9959 | } |
| 9960 | |
vamsi krishna | 89ad8c6 | 2017-09-19 12:51:18 +0530 | [diff] [blame] | 9961 | bssid = get_param(cmd, "Bssid"); |
| 9962 | ssid = get_param(cmd, "Ssid"); |
| 9963 | |
| 9964 | if (ssid) { |
| 9965 | if (2 * strlen(ssid) >= sizeof(ssid_hex)) { |
| 9966 | send_resp(dut, conn, SIGMA_ERROR, |
| 9967 | "ErrorCode,Too long SSID"); |
| 9968 | return 0; |
| 9969 | } |
| 9970 | ascii2hexstr(ssid, ssid_hex); |
| 9971 | } |
| 9972 | |
| 9973 | res = snprintf(buf, sizeof(buf), "SCAN%s%s%s%s", |
| 9974 | bssid ? " bssid=": "", |
| 9975 | bssid ? bssid : "", |
| 9976 | ssid ? " ssid " : "", |
| 9977 | ssid ? ssid_hex : ""); |
| 9978 | if (res < 0 || res >= (int) sizeof(buf)) |
| 9979 | return -1; |
| 9980 | |
| 9981 | if (wpa_command(intf, buf)) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 9982 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not start " |
| 9983 | "scan"); |
| 9984 | return 0; |
| 9985 | } |
| 9986 | |
| 9987 | return 1; |
| 9988 | } |
| 9989 | |
| 9990 | |
Jouni Malinen | 5e5d43d | 2018-01-10 17:29:33 +0200 | [diff] [blame] | 9991 | static int cmd_sta_scan_bss(struct sigma_dut *dut, struct sigma_conn *conn, |
| 9992 | struct sigma_cmd *cmd) |
| 9993 | { |
| 9994 | const char *intf = get_param(cmd, "Interface"); |
| 9995 | const char *bssid; |
| 9996 | char buf[4096], *pos; |
| 9997 | int freq, chan; |
| 9998 | char *ssid; |
| 9999 | char resp[100]; |
| 10000 | int res; |
| 10001 | struct wpa_ctrl *ctrl; |
| 10002 | |
| 10003 | bssid = get_param(cmd, "BSSID"); |
| 10004 | if (!bssid) { |
| 10005 | send_resp(dut, conn, SIGMA_INVALID, |
| 10006 | "errorCode,BSSID argument is missing"); |
| 10007 | return 0; |
| 10008 | } |
| 10009 | |
| 10010 | ctrl = open_wpa_mon(intf); |
| 10011 | if (!ctrl) { |
| 10012 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 10013 | "Failed to open wpa_supplicant monitor connection"); |
| 10014 | return -1; |
| 10015 | } |
| 10016 | |
| 10017 | if (wpa_command(intf, "SCAN TYPE=ONLY")) { |
| 10018 | send_resp(dut, conn, SIGMA_ERROR, |
| 10019 | "errorCode,Could not start scan"); |
| 10020 | wpa_ctrl_detach(ctrl); |
| 10021 | wpa_ctrl_close(ctrl); |
| 10022 | return 0; |
| 10023 | } |
| 10024 | |
| 10025 | res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS", |
| 10026 | buf, sizeof(buf)); |
| 10027 | |
| 10028 | wpa_ctrl_detach(ctrl); |
| 10029 | wpa_ctrl_close(ctrl); |
| 10030 | |
| 10031 | if (res < 0) { |
| 10032 | send_resp(dut, conn, SIGMA_ERROR, |
| 10033 | "errorCode,Scan did not complete"); |
| 10034 | return 0; |
| 10035 | } |
| 10036 | |
| 10037 | snprintf(buf, sizeof(buf), "BSS %s", bssid); |
| 10038 | if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 || |
| 10039 | strncmp(buf, "id=", 3) != 0) { |
| 10040 | send_resp(dut, conn, SIGMA_ERROR, |
| 10041 | "errorCode,Specified BSSID not found"); |
| 10042 | return 0; |
| 10043 | } |
| 10044 | |
| 10045 | pos = strstr(buf, "\nfreq="); |
| 10046 | if (!pos) { |
| 10047 | send_resp(dut, conn, SIGMA_ERROR, |
| 10048 | "errorCode,Channel not found"); |
| 10049 | return 0; |
| 10050 | } |
| 10051 | freq = atoi(pos + 6); |
| 10052 | chan = freq_to_channel(freq); |
| 10053 | |
| 10054 | pos = strstr(buf, "\nssid="); |
| 10055 | if (!pos) { |
| 10056 | send_resp(dut, conn, SIGMA_ERROR, |
| 10057 | "errorCode,SSID not found"); |
| 10058 | return 0; |
| 10059 | } |
| 10060 | ssid = pos + 6; |
| 10061 | pos = strchr(ssid, '\n'); |
| 10062 | if (pos) |
| 10063 | *pos = '\0'; |
| 10064 | snprintf(resp, sizeof(resp), "ssid,%s,bsschannel,%d", ssid, chan); |
| 10065 | send_resp(dut, conn, SIGMA_COMPLETE, resp); |
| 10066 | return 0; |
| 10067 | } |
| 10068 | |
| 10069 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 10070 | static int cmd_sta_set_systime(struct sigma_dut *dut, struct sigma_conn *conn, |
| 10071 | struct sigma_cmd *cmd) |
| 10072 | { |
| 10073 | #ifdef __linux__ |
| 10074 | struct timeval tv; |
| 10075 | struct tm tm; |
| 10076 | time_t t; |
| 10077 | const char *val; |
Pradeep Reddy POTTETI | 429c69e | 2016-10-13 17:22:03 +0530 | [diff] [blame] | 10078 | int v; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 10079 | |
| 10080 | wpa_command(get_station_ifname(), "PMKSA_FLUSH"); |
| 10081 | |
| 10082 | memset(&tm, 0, sizeof(tm)); |
| 10083 | val = get_param(cmd, "seconds"); |
| 10084 | if (val) |
| 10085 | tm.tm_sec = atoi(val); |
| 10086 | val = get_param(cmd, "minutes"); |
| 10087 | if (val) |
| 10088 | tm.tm_min = atoi(val); |
| 10089 | val = get_param(cmd, "hours"); |
| 10090 | if (val) |
| 10091 | tm.tm_hour = atoi(val); |
| 10092 | val = get_param(cmd, "date"); |
| 10093 | if (val) |
| 10094 | tm.tm_mday = atoi(val); |
| 10095 | val = get_param(cmd, "month"); |
Pradeep Reddy POTTETI | 429c69e | 2016-10-13 17:22:03 +0530 | [diff] [blame] | 10096 | if (val) { |
| 10097 | v = atoi(val); |
| 10098 | if (v < 1 || v > 12) { |
| 10099 | send_resp(dut, conn, SIGMA_INVALID, |
| 10100 | "errorCode,Invalid month"); |
| 10101 | return 0; |
| 10102 | } |
| 10103 | tm.tm_mon = v - 1; |
| 10104 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 10105 | val = get_param(cmd, "year"); |
| 10106 | if (val) { |
| 10107 | int year = atoi(val); |
| 10108 | #ifdef ANDROID |
| 10109 | if (year > 2035) |
| 10110 | year = 2035; /* years beyond 2035 not supported */ |
| 10111 | #endif /* ANDROID */ |
| 10112 | tm.tm_year = year - 1900; |
| 10113 | } |
| 10114 | t = mktime(&tm); |
| 10115 | if (t == (time_t) -1) { |
| 10116 | send_resp(dut, conn, SIGMA_ERROR, |
| 10117 | "errorCode,Invalid date or time"); |
| 10118 | return 0; |
| 10119 | } |
| 10120 | |
| 10121 | memset(&tv, 0, sizeof(tv)); |
| 10122 | tv.tv_sec = t; |
| 10123 | |
| 10124 | if (settimeofday(&tv, NULL) < 0) { |
| 10125 | sigma_dut_print(dut, DUT_MSG_INFO, "settimeofday failed: %s", |
| 10126 | strerror(errno)); |
| 10127 | send_resp(dut, conn, SIGMA_ERROR, |
| 10128 | "errorCode,Failed to set time"); |
| 10129 | return 0; |
| 10130 | } |
| 10131 | |
| 10132 | return 1; |
| 10133 | #endif /* __linux__ */ |
| 10134 | |
| 10135 | return -1; |
| 10136 | } |
| 10137 | |
| 10138 | |
| 10139 | static int cmd_sta_osu(struct sigma_dut *dut, struct sigma_conn *conn, |
| 10140 | struct sigma_cmd *cmd) |
| 10141 | { |
| 10142 | const char *intf = get_param(cmd, "Interface"); |
| 10143 | const char *name, *val; |
| 10144 | int prod_ess_assoc = 1; |
| 10145 | char buf[200], bssid[100], ssid[100]; |
| 10146 | int res; |
| 10147 | struct wpa_ctrl *ctrl; |
| 10148 | |
| 10149 | name = get_param(cmd, "osuFriendlyName"); |
| 10150 | |
| 10151 | val = get_param(cmd, "ProdESSAssoc"); |
| 10152 | if (val) |
| 10153 | prod_ess_assoc = atoi(val); |
| 10154 | |
| 10155 | kill_dhcp_client(dut, intf); |
| 10156 | if (start_dhcp_client(dut, intf) < 0) |
| 10157 | return -2; |
| 10158 | |
| 10159 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger OSU"); |
| 10160 | mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); |
| 10161 | res = snprintf(buf, sizeof(buf), |
| 10162 | "%s %s%s%s signup osu-ca.pem", |
| 10163 | prod_ess_assoc ? "" : "-N", |
| 10164 | name ? "-O'" : "", name ? name : "", |
| 10165 | name ? "'" : ""); |
| 10166 | |
Kanchanapally, Vidyullatha | 12b6676 | 2015-12-31 16:46:42 +0530 | [diff] [blame] | 10167 | hs2_set_policy(dut); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 10168 | if (run_hs20_osu(dut, buf) < 0) { |
| 10169 | FILE *f; |
| 10170 | |
| 10171 | sigma_dut_print(dut, DUT_MSG_INFO, "Failed to complete OSU"); |
| 10172 | |
| 10173 | f = fopen("hs20-osu-client.res", "r"); |
| 10174 | if (f) { |
| 10175 | char resp[400], res[300], *pos; |
| 10176 | if (!fgets(res, sizeof(res), f)) |
| 10177 | res[0] = '\0'; |
| 10178 | pos = strchr(res, '\n'); |
| 10179 | if (pos) |
| 10180 | *pos = '\0'; |
| 10181 | fclose(f); |
| 10182 | sigma_dut_summary(dut, "hs20-osu-client provisioning failed: %s", |
| 10183 | res); |
| 10184 | snprintf(resp, sizeof(resp), "notify-send '%s'", res); |
| 10185 | if (system(resp) != 0) { |
| 10186 | } |
| 10187 | snprintf(resp, sizeof(resp), |
| 10188 | "SSID,,BSSID,,failureReason,%s", res); |
| 10189 | send_resp(dut, conn, SIGMA_COMPLETE, resp); |
| 10190 | return 0; |
| 10191 | } |
| 10192 | |
| 10193 | send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,"); |
| 10194 | return 0; |
| 10195 | } |
| 10196 | |
| 10197 | if (!prod_ess_assoc) |
| 10198 | goto report; |
| 10199 | |
| 10200 | ctrl = open_wpa_mon(intf); |
| 10201 | if (ctrl == NULL) { |
| 10202 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open " |
| 10203 | "wpa_supplicant monitor connection"); |
| 10204 | return -1; |
| 10205 | } |
| 10206 | |
| 10207 | res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED", |
| 10208 | buf, sizeof(buf)); |
| 10209 | |
| 10210 | wpa_ctrl_detach(ctrl); |
| 10211 | wpa_ctrl_close(ctrl); |
| 10212 | |
| 10213 | if (res < 0) { |
| 10214 | sigma_dut_print(dut, DUT_MSG_INFO, "Failed to connect to " |
| 10215 | "network after OSU"); |
| 10216 | send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,"); |
| 10217 | return 0; |
| 10218 | } |
| 10219 | |
| 10220 | report: |
| 10221 | if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 || |
| 10222 | get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) { |
| 10223 | sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get BSSID/SSID"); |
| 10224 | send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,"); |
| 10225 | return 0; |
| 10226 | } |
| 10227 | |
| 10228 | snprintf(buf, sizeof(buf), "SSID,%s,BSSID,%s", ssid, bssid); |
| 10229 | send_resp(dut, conn, SIGMA_COMPLETE, buf); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 10230 | return 0; |
| 10231 | } |
| 10232 | |
| 10233 | |
| 10234 | static int cmd_sta_policy_update(struct sigma_dut *dut, struct sigma_conn *conn, |
| 10235 | struct sigma_cmd *cmd) |
| 10236 | { |
| 10237 | const char *val; |
| 10238 | int timeout = 120; |
| 10239 | |
| 10240 | val = get_param(cmd, "PolicyUpdate"); |
| 10241 | if (val == NULL || atoi(val) == 0) |
| 10242 | return 1; /* No operation requested */ |
| 10243 | |
| 10244 | val = get_param(cmd, "Timeout"); |
| 10245 | if (val) |
| 10246 | timeout = atoi(val); |
| 10247 | |
| 10248 | if (timeout) { |
| 10249 | /* TODO: time out the command and return |
| 10250 | * PolicyUpdateStatus,TIMEOUT if needed. */ |
| 10251 | } |
| 10252 | |
| 10253 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger policy update"); |
| 10254 | mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); |
| 10255 | if (run_hs20_osu(dut, "pol_upd fqdn=wi-fi.org") < 0) { |
| 10256 | send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,FAIL"); |
| 10257 | return 0; |
| 10258 | } |
| 10259 | |
| 10260 | send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,SUCCESS"); |
| 10261 | return 0; |
| 10262 | } |
| 10263 | |
| 10264 | |
| 10265 | static int cmd_sta_er_config(struct sigma_dut *dut, struct sigma_conn *conn, |
| 10266 | struct sigma_cmd *cmd) |
| 10267 | { |
| 10268 | struct wpa_ctrl *ctrl; |
| 10269 | const char *intf = get_param(cmd, "Interface"); |
| 10270 | const char *bssid = get_param(cmd, "Bssid"); |
| 10271 | const char *ssid = get_param(cmd, "SSID"); |
| 10272 | const char *security = get_param(cmd, "Security"); |
| 10273 | const char *passphrase = get_param(cmd, "Passphrase"); |
| 10274 | const char *pin = get_param(cmd, "PIN"); |
| 10275 | char buf[1000]; |
| 10276 | char ssid_hex[200], passphrase_hex[200]; |
| 10277 | const char *keymgmt, *cipher; |
| 10278 | |
| 10279 | if (intf == NULL) |
| 10280 | intf = get_main_ifname(); |
| 10281 | |
| 10282 | if (!bssid) { |
| 10283 | send_resp(dut, conn, SIGMA_ERROR, |
| 10284 | "ErrorCode,Missing Bssid argument"); |
| 10285 | return 0; |
| 10286 | } |
| 10287 | |
| 10288 | if (!ssid) { |
| 10289 | send_resp(dut, conn, SIGMA_ERROR, |
| 10290 | "ErrorCode,Missing SSID argument"); |
| 10291 | return 0; |
| 10292 | } |
| 10293 | |
| 10294 | if (!security) { |
| 10295 | send_resp(dut, conn, SIGMA_ERROR, |
| 10296 | "ErrorCode,Missing Security argument"); |
| 10297 | return 0; |
| 10298 | } |
| 10299 | |
| 10300 | if (!passphrase) { |
| 10301 | send_resp(dut, conn, SIGMA_ERROR, |
| 10302 | "ErrorCode,Missing Passphrase argument"); |
| 10303 | return 0; |
| 10304 | } |
| 10305 | |
| 10306 | if (!pin) { |
| 10307 | send_resp(dut, conn, SIGMA_ERROR, |
| 10308 | "ErrorCode,Missing PIN argument"); |
| 10309 | return 0; |
| 10310 | } |
| 10311 | |
vamsi krishna | 8c9c156 | 2017-05-12 15:51:46 +0530 | [diff] [blame] | 10312 | if (2 * strlen(ssid) >= sizeof(ssid_hex) || |
| 10313 | 2 * strlen(passphrase) >= sizeof(passphrase_hex)) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 10314 | send_resp(dut, conn, SIGMA_ERROR, |
| 10315 | "ErrorCode,Too long SSID/passphrase"); |
| 10316 | return 0; |
| 10317 | } |
| 10318 | |
| 10319 | ctrl = open_wpa_mon(intf); |
| 10320 | if (ctrl == NULL) { |
| 10321 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open " |
| 10322 | "wpa_supplicant monitor connection"); |
| 10323 | return -2; |
| 10324 | } |
| 10325 | |
| 10326 | if (strcasecmp(security, "wpa2-psk") == 0) { |
| 10327 | keymgmt = "WPA2PSK"; |
| 10328 | cipher = "CCMP"; |
| 10329 | } else { |
| 10330 | wpa_ctrl_detach(ctrl); |
| 10331 | wpa_ctrl_close(ctrl); |
| 10332 | send_resp(dut, conn, SIGMA_ERROR, |
| 10333 | "ErrorCode,Unsupported Security value"); |
| 10334 | return 0; |
| 10335 | } |
| 10336 | |
| 10337 | ascii2hexstr(ssid, ssid_hex); |
| 10338 | ascii2hexstr(passphrase, passphrase_hex); |
| 10339 | snprintf(buf, sizeof(buf), "WPS_REG %s %s %s %s %s %s", |
| 10340 | bssid, pin, ssid_hex, keymgmt, cipher, passphrase_hex); |
| 10341 | |
| 10342 | if (wpa_command(intf, buf) < 0) { |
| 10343 | wpa_ctrl_detach(ctrl); |
| 10344 | wpa_ctrl_close(ctrl); |
| 10345 | send_resp(dut, conn, SIGMA_ERROR, |
| 10346 | "ErrorCode,Failed to start registrar"); |
| 10347 | return 0; |
| 10348 | } |
| 10349 | |
| 10350 | snprintf(dut->er_oper_bssid, sizeof(dut->er_oper_bssid), "%s", bssid); |
| 10351 | dut->er_oper_performed = 1; |
| 10352 | |
| 10353 | return wps_connection_event(dut, conn, ctrl, intf, 0); |
| 10354 | } |
| 10355 | |
| 10356 | |
| 10357 | static int cmd_sta_wps_connect_pw_token(struct sigma_dut *dut, |
| 10358 | struct sigma_conn *conn, |
| 10359 | struct sigma_cmd *cmd) |
| 10360 | { |
| 10361 | struct wpa_ctrl *ctrl; |
| 10362 | const char *intf = get_param(cmd, "Interface"); |
| 10363 | const char *bssid = get_param(cmd, "Bssid"); |
| 10364 | char buf[100]; |
| 10365 | |
| 10366 | if (!bssid) { |
| 10367 | send_resp(dut, conn, SIGMA_ERROR, |
| 10368 | "ErrorCode,Missing Bssid argument"); |
| 10369 | return 0; |
| 10370 | } |
| 10371 | |
| 10372 | ctrl = open_wpa_mon(intf); |
| 10373 | if (ctrl == NULL) { |
| 10374 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open " |
| 10375 | "wpa_supplicant monitor connection"); |
| 10376 | return -2; |
| 10377 | } |
| 10378 | |
| 10379 | snprintf(buf, sizeof(buf), "WPS_NFC %s", bssid); |
| 10380 | |
| 10381 | if (wpa_command(intf, buf) < 0) { |
| 10382 | wpa_ctrl_detach(ctrl); |
| 10383 | wpa_ctrl_close(ctrl); |
| 10384 | send_resp(dut, conn, SIGMA_ERROR, |
| 10385 | "ErrorCode,Failed to start registrar"); |
| 10386 | return 0; |
| 10387 | } |
| 10388 | |
| 10389 | return wps_connection_event(dut, conn, ctrl, intf, 0); |
| 10390 | } |
| 10391 | |
| 10392 | |
vamsi krishna | 9b14400 | 2017-09-20 13:28:13 +0530 | [diff] [blame] | 10393 | static int cmd_start_wps_registration(struct sigma_dut *dut, |
| 10394 | struct sigma_conn *conn, |
| 10395 | struct sigma_cmd *cmd) |
| 10396 | { |
| 10397 | struct wpa_ctrl *ctrl; |
| 10398 | const char *intf = get_param(cmd, "Interface"); |
| 10399 | const char *role, *method; |
| 10400 | int res; |
| 10401 | char buf[256]; |
| 10402 | const char *events[] = { |
| 10403 | "CTRL-EVENT-CONNECTED", |
| 10404 | "WPS-OVERLAP-DETECTED", |
| 10405 | "WPS-TIMEOUT", |
| 10406 | "WPS-FAIL", |
| 10407 | NULL |
| 10408 | }; |
| 10409 | |
| 10410 | ctrl = open_wpa_mon(intf); |
| 10411 | if (!ctrl) { |
| 10412 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 10413 | "Failed to open wpa_supplicant monitor connection"); |
| 10414 | return -2; |
| 10415 | } |
| 10416 | |
| 10417 | role = get_param(cmd, "WpsRole"); |
| 10418 | if (!role) { |
| 10419 | send_resp(dut, conn, SIGMA_INVALID, |
| 10420 | "ErrorCode,WpsRole not provided"); |
| 10421 | goto fail; |
| 10422 | } |
| 10423 | |
| 10424 | if (strcasecmp(role, "Enrollee") == 0) { |
| 10425 | method = get_param(cmd, "WpsConfigMethod"); |
| 10426 | if (!method) { |
| 10427 | send_resp(dut, conn, SIGMA_INVALID, |
| 10428 | "ErrorCode,WpsConfigMethod not provided"); |
| 10429 | goto fail; |
| 10430 | } |
| 10431 | if (strcasecmp(method, "PBC") == 0) { |
| 10432 | if (wpa_command(intf, "WPS_PBC") < 0) { |
| 10433 | send_resp(dut, conn, SIGMA_ERROR, |
| 10434 | "ErrorCode,Failed to enable PBC"); |
| 10435 | goto fail; |
| 10436 | } |
| 10437 | } else { |
| 10438 | /* TODO: PIN method */ |
| 10439 | send_resp(dut, conn, SIGMA_ERROR, |
| 10440 | "ErrorCode,Unsupported WpsConfigMethod value"); |
| 10441 | goto fail; |
| 10442 | } |
| 10443 | res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf)); |
| 10444 | if (res < 0) { |
| 10445 | send_resp(dut, conn, SIGMA_ERROR, |
| 10446 | "ErrorCode,WPS connection did not complete"); |
| 10447 | goto fail; |
| 10448 | } |
| 10449 | if (strstr(buf, "WPS-TIMEOUT")) { |
| 10450 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,NoPeer"); |
| 10451 | } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) { |
| 10452 | send_resp(dut, conn, SIGMA_ERROR, |
| 10453 | "ErrorCode,OverlapSession"); |
| 10454 | } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) { |
| 10455 | send_resp(dut, conn, SIGMA_COMPLETE, "Successful"); |
| 10456 | } else { |
| 10457 | send_resp(dut, conn, SIGMA_ERROR, |
| 10458 | "ErrorCode,WPS operation failed"); |
| 10459 | } |
| 10460 | } else { |
| 10461 | /* TODO: Registrar role */ |
| 10462 | send_resp(dut, conn, SIGMA_ERROR, |
| 10463 | "ErrorCode,Unsupported WpsRole value"); |
| 10464 | } |
| 10465 | |
| 10466 | fail: |
| 10467 | wpa_ctrl_detach(ctrl); |
| 10468 | wpa_ctrl_close(ctrl); |
| 10469 | return 0; |
| 10470 | } |
| 10471 | |
| 10472 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 10473 | static int req_intf(struct sigma_cmd *cmd) |
| 10474 | { |
| 10475 | return get_param(cmd, "interface") == NULL ? -1 : 0; |
| 10476 | } |
| 10477 | |
| 10478 | |
| 10479 | void sta_register_cmds(void) |
| 10480 | { |
| 10481 | sigma_dut_reg_cmd("sta_get_ip_config", req_intf, |
| 10482 | cmd_sta_get_ip_config); |
| 10483 | sigma_dut_reg_cmd("sta_set_ip_config", req_intf, |
| 10484 | cmd_sta_set_ip_config); |
| 10485 | sigma_dut_reg_cmd("sta_get_info", req_intf, cmd_sta_get_info); |
| 10486 | sigma_dut_reg_cmd("sta_get_mac_address", req_intf, |
| 10487 | cmd_sta_get_mac_address); |
| 10488 | sigma_dut_reg_cmd("sta_is_connected", req_intf, cmd_sta_is_connected); |
| 10489 | sigma_dut_reg_cmd("sta_verify_ip_connection", req_intf, |
| 10490 | cmd_sta_verify_ip_connection); |
| 10491 | sigma_dut_reg_cmd("sta_get_bssid", req_intf, cmd_sta_get_bssid); |
| 10492 | sigma_dut_reg_cmd("sta_set_encryption", req_intf, |
| 10493 | cmd_sta_set_encryption); |
| 10494 | sigma_dut_reg_cmd("sta_set_psk", req_intf, cmd_sta_set_psk); |
| 10495 | sigma_dut_reg_cmd("sta_set_eaptls", req_intf, cmd_sta_set_eaptls); |
| 10496 | sigma_dut_reg_cmd("sta_set_eapttls", req_intf, cmd_sta_set_eapttls); |
| 10497 | sigma_dut_reg_cmd("sta_set_eapsim", req_intf, cmd_sta_set_eapsim); |
| 10498 | sigma_dut_reg_cmd("sta_set_peap", req_intf, cmd_sta_set_peap); |
| 10499 | sigma_dut_reg_cmd("sta_set_eapfast", req_intf, cmd_sta_set_eapfast); |
| 10500 | sigma_dut_reg_cmd("sta_set_eapaka", req_intf, cmd_sta_set_eapaka); |
| 10501 | sigma_dut_reg_cmd("sta_set_eapakaprime", req_intf, |
| 10502 | cmd_sta_set_eapakaprime); |
| 10503 | sigma_dut_reg_cmd("sta_set_security", req_intf, cmd_sta_set_security); |
| 10504 | sigma_dut_reg_cmd("sta_set_uapsd", req_intf, cmd_sta_set_uapsd); |
| 10505 | /* TODO: sta_set_ibss */ |
| 10506 | /* TODO: sta_set_mode */ |
| 10507 | sigma_dut_reg_cmd("sta_set_wmm", req_intf, cmd_sta_set_wmm); |
| 10508 | sigma_dut_reg_cmd("sta_associate", req_intf, cmd_sta_associate); |
| 10509 | /* TODO: sta_up_load */ |
| 10510 | sigma_dut_reg_cmd("sta_preset_testparameters", req_intf, |
| 10511 | cmd_sta_preset_testparameters); |
| 10512 | /* TODO: sta_set_system */ |
| 10513 | sigma_dut_reg_cmd("sta_set_11n", req_intf, cmd_sta_set_11n); |
| 10514 | /* TODO: sta_set_rifs_test */ |
| 10515 | sigma_dut_reg_cmd("sta_set_wireless", req_intf, cmd_sta_set_wireless); |
| 10516 | sigma_dut_reg_cmd("sta_send_addba", req_intf, cmd_sta_send_addba); |
| 10517 | /* TODO: sta_send_coexist_mgmt */ |
| 10518 | sigma_dut_reg_cmd("sta_disconnect", req_intf, cmd_sta_disconnect); |
| 10519 | sigma_dut_reg_cmd("sta_reassoc", req_intf, cmd_sta_reassoc); |
| 10520 | sigma_dut_reg_cmd("sta_reassociate", req_intf, cmd_sta_reassoc); |
| 10521 | sigma_dut_reg_cmd("sta_reset_default", req_intf, |
| 10522 | cmd_sta_reset_default); |
| 10523 | sigma_dut_reg_cmd("sta_send_frame", req_intf, cmd_sta_send_frame); |
| 10524 | sigma_dut_reg_cmd("sta_set_macaddr", req_intf, cmd_sta_set_macaddr); |
| 10525 | sigma_dut_reg_cmd("sta_set_rfeature", req_intf, cmd_sta_set_rfeature); |
| 10526 | sigma_dut_reg_cmd("sta_set_radio", req_intf, cmd_sta_set_radio); |
| 10527 | sigma_dut_reg_cmd("sta_set_pwrsave", req_intf, cmd_sta_set_pwrsave); |
| 10528 | sigma_dut_reg_cmd("sta_bssid_pool", req_intf, cmd_sta_bssid_pool); |
| 10529 | sigma_dut_reg_cmd("sta_reset_parm", req_intf, cmd_sta_reset_parm); |
| 10530 | sigma_dut_reg_cmd("sta_get_key", req_intf, cmd_sta_get_key); |
| 10531 | sigma_dut_reg_cmd("sta_hs2_associate", req_intf, |
| 10532 | cmd_sta_hs2_associate); |
| 10533 | sigma_dut_reg_cmd("sta_add_credential", req_intf, |
| 10534 | cmd_sta_add_credential); |
| 10535 | sigma_dut_reg_cmd("sta_scan", req_intf, cmd_sta_scan); |
Jouni Malinen | 5e5d43d | 2018-01-10 17:29:33 +0200 | [diff] [blame] | 10536 | sigma_dut_reg_cmd("sta_scan_bss", req_intf, cmd_sta_scan_bss); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 10537 | sigma_dut_reg_cmd("sta_set_systime", NULL, cmd_sta_set_systime); |
| 10538 | sigma_dut_reg_cmd("sta_osu", req_intf, cmd_sta_osu); |
| 10539 | sigma_dut_reg_cmd("sta_policy_update", req_intf, cmd_sta_policy_update); |
| 10540 | sigma_dut_reg_cmd("sta_er_config", NULL, cmd_sta_er_config); |
| 10541 | sigma_dut_reg_cmd("sta_wps_connect_pw_token", req_intf, |
| 10542 | cmd_sta_wps_connect_pw_token); |
Jouni Malinen | 8290520 | 2018-04-29 17:20:10 +0300 | [diff] [blame] | 10543 | sigma_dut_reg_cmd("sta_exec_action", NULL, cmd_sta_exec_action); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 10544 | sigma_dut_reg_cmd("sta_get_events", req_intf, cmd_sta_get_events); |
| 10545 | 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] | 10546 | sigma_dut_reg_cmd("start_wps_registration", req_intf, |
| 10547 | cmd_start_wps_registration); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 10548 | } |