| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1 | /* | 
|  | 2 | * Sigma Control API DUT (station/AP) | 
|  | 3 | * Copyright (c) 2010-2011, Atheros Communications, Inc. | 
| Jouni Malinen | 9d7e31d | 2017-12-22 18:55:04 +0200 | [diff] [blame] | 4 | * Copyright (c) 2011-2017, Qualcomm Atheros, Inc. | 
| Jouni Malinen | c12ea4a | 2018-01-05 21:07:10 +0200 | [diff] [blame] | 5 | * Copyright (c) 2018, The Linux Foundation | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6 | * All Rights Reserved. | 
|  | 7 | * Licensed under the Clear BSD license. See README for more details. | 
|  | 8 | */ | 
|  | 9 |  | 
|  | 10 | #include "sigma_dut.h" | 
|  | 11 | #include <sys/ioctl.h> | 
|  | 12 | #include <sys/stat.h> | 
|  | 13 | #ifdef __linux__ | 
| Lior David | cc88b56 | 2017-01-03 18:52:09 +0200 | [diff] [blame] | 14 | #include <regex.h> | 
|  | 15 | #include <dirent.h> | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 16 | #include <sys/time.h> | 
|  | 17 | #include <netpacket/packet.h> | 
|  | 18 | #include <linux/if_ether.h> | 
|  | 19 | #ifdef ANDROID | 
|  | 20 | #include <cutils/properties.h> | 
|  | 21 | #include <android/log.h> | 
|  | 22 | #include "keystore_get.h" | 
|  | 23 | #else /* ANDROID */ | 
|  | 24 | #include <ifaddrs.h> | 
|  | 25 | #endif /* ANDROID */ | 
|  | 26 | #include <netdb.h> | 
|  | 27 | #endif /* __linux__ */ | 
|  | 28 | #ifdef __QNXNTO__ | 
|  | 29 | #include <net/if_dl.h> | 
|  | 30 | #endif /* __QNXNTO__ */ | 
|  | 31 | #include "wpa_ctrl.h" | 
|  | 32 | #include "wpa_helpers.h" | 
| Amarnath Hullur Subramanyam | 9c381f5 | 2017-03-17 00:04:41 -0700 | [diff] [blame] | 33 | #include "miracast.h" | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 34 |  | 
|  | 35 | /* Temporary files for sta_send_addba */ | 
|  | 36 | #define VI_QOS_TMP_FILE     "/tmp/vi-qos.tmp" | 
|  | 37 | #define VI_QOS_FILE         "/tmp/vi-qos.txt" | 
|  | 38 | #define VI_QOS_REFFILE      "/etc/vi-qos.txt" | 
|  | 39 |  | 
|  | 40 | /* | 
|  | 41 | * MTU for Ethernet need to take into account 8-byte SNAP header | 
|  | 42 | * to be added when encapsulating Ethernet frame into 802.11 | 
|  | 43 | */ | 
|  | 44 | #ifndef IEEE80211_MAX_DATA_LEN_DMG | 
|  | 45 | #define IEEE80211_MAX_DATA_LEN_DMG 7920 | 
|  | 46 | #endif | 
|  | 47 | #ifndef IEEE80211_SNAP_LEN_DMG | 
|  | 48 | #define IEEE80211_SNAP_LEN_DMG 8 | 
|  | 49 | #endif | 
|  | 50 |  | 
| Ashwini Patil | 0040258 | 2017-04-13 12:29:39 +0530 | [diff] [blame] | 51 | #define NON_PREF_CH_LIST_SIZE 100 | 
| Ashwini Patil | 5acd738 | 2017-04-13 15:55:04 +0530 | [diff] [blame] | 52 | #define NEIGHBOR_REPORT_SIZE 1000 | 
|  | 53 | #define DEFAULT_NEIGHBOR_BSSID_INFO "17" | 
|  | 54 | #define DEFAULT_NEIGHBOR_PHY_TYPE "1" | 
| Ashwini Patil | 0040258 | 2017-04-13 12:29:39 +0530 | [diff] [blame] | 55 |  | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 56 | extern char *sigma_wpas_ctrl; | 
|  | 57 | extern char *sigma_cert_path; | 
|  | 58 | extern enum driver_type wifi_chip_type; | 
|  | 59 | extern char *sigma_radio_ifname[]; | 
|  | 60 |  | 
| Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 61 | #ifdef __linux__ | 
|  | 62 | #define WIL_WMI_MAX_PAYLOAD	248 | 
|  | 63 | #define WIL_WMI_BF_TRIG_CMDID	0x83a | 
|  | 64 |  | 
|  | 65 | struct wil_wmi_header { | 
|  | 66 | uint8_t mid; | 
|  | 67 | uint8_t reserved; | 
|  | 68 | uint16_t cmd; | 
|  | 69 | uint32_t ts; | 
|  | 70 | } __attribute__((packed)); | 
|  | 71 |  | 
|  | 72 | enum wil_wmi_bf_trig_type { | 
|  | 73 | WIL_WMI_SLS, | 
|  | 74 | WIL_WMI_BRP_RX, | 
|  | 75 | WIL_WMI_BRP_TX, | 
|  | 76 | }; | 
|  | 77 |  | 
|  | 78 | struct wil_wmi_bf_trig_cmd { | 
|  | 79 | /* enum wil_wmi_bf_trig_type */ | 
|  | 80 | uint32_t bf_type; | 
|  | 81 | /* cid when type == WMI_BRP_RX */ | 
|  | 82 | uint32_t sta_id; | 
|  | 83 | uint32_t reserved; | 
|  | 84 | /* mac address when type = WIL_WMI_SLS */ | 
|  | 85 | uint8_t dest_mac[6]; | 
|  | 86 | } __attribute__((packed)); | 
|  | 87 | #endif /* __linux__ */ | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 88 |  | 
|  | 89 | #ifdef ANDROID | 
|  | 90 |  | 
|  | 91 | static int add_ipv6_rule(struct sigma_dut *dut, const char *ifname); | 
|  | 92 |  | 
|  | 93 | #define ANDROID_KEYSTORE_GET 'g' | 
|  | 94 | #define ANDROID_KEYSTORE_GET_PUBKEY 'b' | 
|  | 95 |  | 
|  | 96 | static int android_keystore_get(char cmd, const char *key, unsigned char *val) | 
|  | 97 | { | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 98 | /* Android 4.3 changed keystore design, so need to use keystore_get() */ | 
|  | 99 | #ifndef KEYSTORE_MESSAGE_SIZE | 
|  | 100 | #define KEYSTORE_MESSAGE_SIZE 65535 | 
|  | 101 | #endif /* KEYSTORE_MESSAGE_SIZE */ | 
|  | 102 |  | 
|  | 103 | ssize_t len; | 
|  | 104 | uint8_t *value = NULL; | 
|  | 105 |  | 
|  | 106 | __android_log_print(ANDROID_LOG_DEBUG, "sigma_dut", | 
|  | 107 | "keystore command '%c' key '%s' --> keystore_get", | 
|  | 108 | cmd, key); | 
|  | 109 |  | 
|  | 110 | len = keystore_get(key, strlen(key), &value); | 
|  | 111 | if (len < 0) { | 
|  | 112 | __android_log_print(ANDROID_LOG_DEBUG, "sigma_dut", | 
|  | 113 | "keystore_get() failed"); | 
|  | 114 | return -1; | 
|  | 115 | } | 
|  | 116 |  | 
|  | 117 | if (len > KEYSTORE_MESSAGE_SIZE) | 
|  | 118 | len = KEYSTORE_MESSAGE_SIZE; | 
|  | 119 | memcpy(val, value, len); | 
|  | 120 | free(value); | 
|  | 121 | return len; | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 122 | } | 
|  | 123 | #endif /* ANDROID */ | 
|  | 124 |  | 
|  | 125 |  | 
|  | 126 | int set_ps(const char *intf, struct sigma_dut *dut, int enabled) | 
|  | 127 | { | 
|  | 128 | #ifdef __linux__ | 
|  | 129 | char buf[100]; | 
|  | 130 |  | 
|  | 131 | if (wifi_chip_type == DRIVER_WCN) { | 
|  | 132 | if (enabled) { | 
|  | 133 | snprintf(buf, sizeof(buf), "iwpriv wlan0 dump 906"); | 
| Pradeep Reddy POTTETI | 625b370 | 2016-09-20 17:09:58 +0530 | [diff] [blame] | 134 | if (system(buf) != 0) | 
|  | 135 | goto set_power_save; | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 136 | } else { | 
|  | 137 | snprintf(buf, sizeof(buf), "iwpriv wlan0 dump 905"); | 
| Pradeep Reddy POTTETI | 625b370 | 2016-09-20 17:09:58 +0530 | [diff] [blame] | 138 | if (system(buf) != 0) | 
|  | 139 | goto set_power_save; | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 140 | snprintf(buf, sizeof(buf), "iwpriv wlan0 dump 912"); | 
| Pradeep Reddy POTTETI | 625b370 | 2016-09-20 17:09:58 +0530 | [diff] [blame] | 141 | if (system(buf) != 0) | 
|  | 142 | goto set_power_save; | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 143 | } | 
|  | 144 |  | 
|  | 145 | return 0; | 
|  | 146 | } | 
|  | 147 |  | 
| Pradeep Reddy POTTETI | 625b370 | 2016-09-20 17:09:58 +0530 | [diff] [blame] | 148 | set_power_save: | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 149 | snprintf(buf, sizeof(buf), "./iw dev %s set power_save %s", | 
|  | 150 | intf, enabled ? "on" : "off"); | 
|  | 151 | if (system(buf) != 0) { | 
|  | 152 | snprintf(buf, sizeof(buf), "iw dev %s set power_save %s", | 
|  | 153 | intf, enabled ? "on" : "off"); | 
| Pradeep Reddy POTTETI | 625b370 | 2016-09-20 17:09:58 +0530 | [diff] [blame] | 154 | if (system(buf) != 0) { | 
|  | 155 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 156 | "Failed to set power save %s", | 
|  | 157 | enabled ? "on" : "off"); | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 158 | return -1; | 
| Pradeep Reddy POTTETI | 625b370 | 2016-09-20 17:09:58 +0530 | [diff] [blame] | 159 | } | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 160 | } | 
|  | 161 |  | 
|  | 162 | return 0; | 
|  | 163 | #else /* __linux__ */ | 
|  | 164 | return -1; | 
|  | 165 | #endif /* __linux__ */ | 
|  | 166 | } | 
|  | 167 |  | 
|  | 168 |  | 
| Lior David | cc88b56 | 2017-01-03 18:52:09 +0200 | [diff] [blame] | 169 | #ifdef __linux__ | 
| Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 170 |  | 
| Lior David | cc88b56 | 2017-01-03 18:52:09 +0200 | [diff] [blame] | 171 | static int wil6210_get_debugfs_dir(struct sigma_dut *dut, char *path, | 
|  | 172 | size_t len) | 
|  | 173 | { | 
|  | 174 | DIR *dir, *wil_dir; | 
|  | 175 | struct dirent *entry; | 
|  | 176 | int ret = -1; | 
|  | 177 | const char *root_path = "/sys/kernel/debug/ieee80211"; | 
|  | 178 |  | 
|  | 179 | dir = opendir(root_path); | 
|  | 180 | if (!dir) | 
|  | 181 | return -2; | 
|  | 182 |  | 
|  | 183 | while ((entry = readdir(dir))) { | 
|  | 184 | if (strcmp(entry->d_name, ".") == 0 || | 
|  | 185 | strcmp(entry->d_name, "..") == 0) | 
|  | 186 | continue; | 
|  | 187 |  | 
|  | 188 | if (snprintf(path, len, "%s/%s/wil6210", | 
|  | 189 | root_path, entry->d_name) >= (int) len) { | 
|  | 190 | ret = -3; | 
|  | 191 | break; | 
|  | 192 | } | 
|  | 193 |  | 
|  | 194 | wil_dir = opendir(path); | 
|  | 195 | if (wil_dir) { | 
|  | 196 | closedir(wil_dir); | 
|  | 197 | ret = 0; | 
|  | 198 | break; | 
|  | 199 | } | 
|  | 200 | } | 
|  | 201 |  | 
|  | 202 | closedir(dir); | 
|  | 203 | return ret; | 
|  | 204 | } | 
| Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 205 |  | 
|  | 206 |  | 
|  | 207 | static int wil6210_wmi_send(struct sigma_dut *dut, uint16_t command, | 
|  | 208 | void *payload, uint16_t length) | 
|  | 209 | { | 
|  | 210 | struct { | 
|  | 211 | struct wil_wmi_header hdr; | 
|  | 212 | char payload[WIL_WMI_MAX_PAYLOAD]; | 
|  | 213 | } __attribute__((packed)) cmd; | 
|  | 214 | char buf[128], fname[128]; | 
|  | 215 | size_t towrite, written; | 
|  | 216 | FILE *f; | 
|  | 217 |  | 
|  | 218 | if (length > WIL_WMI_MAX_PAYLOAD) { | 
|  | 219 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 220 | "payload too large(%u, max %u)", | 
|  | 221 | length, WIL_WMI_MAX_PAYLOAD); | 
|  | 222 | return -1; | 
|  | 223 | } | 
|  | 224 |  | 
|  | 225 | memset(&cmd.hdr, 0, sizeof(cmd.hdr)); | 
|  | 226 | cmd.hdr.cmd = command; | 
|  | 227 | memcpy(cmd.payload, payload, length); | 
|  | 228 |  | 
|  | 229 | if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) { | 
|  | 230 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 231 | "failed to get wil6210 debugfs dir"); | 
|  | 232 | return -1; | 
|  | 233 | } | 
|  | 234 |  | 
|  | 235 | snprintf(fname, sizeof(fname), "%s/wmi_send", buf); | 
|  | 236 | f = fopen(fname, "wb"); | 
|  | 237 | if (!f) { | 
|  | 238 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 239 | "failed to open: %s", fname); | 
|  | 240 | return -1; | 
|  | 241 | } | 
|  | 242 |  | 
|  | 243 | towrite = sizeof(cmd.hdr) + length; | 
|  | 244 | written = fwrite(&cmd, 1, towrite, f); | 
|  | 245 | fclose(f); | 
|  | 246 | if (written != towrite) { | 
|  | 247 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 248 | "failed to send wmi %u", command); | 
|  | 249 | return -1; | 
|  | 250 | } | 
|  | 251 |  | 
|  | 252 | return 0; | 
|  | 253 | } | 
|  | 254 |  | 
|  | 255 |  | 
|  | 256 | static int wil6210_get_sta_info_field(struct sigma_dut *dut, const char *bssid, | 
|  | 257 | const char *pattern, unsigned int *field) | 
|  | 258 | { | 
|  | 259 | char buf[128], fname[128]; | 
|  | 260 | FILE *f; | 
|  | 261 | regex_t re; | 
|  | 262 | regmatch_t m[2]; | 
|  | 263 | int rc, ret = -1; | 
|  | 264 |  | 
|  | 265 | if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) { | 
|  | 266 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 267 | "failed to get wil6210 debugfs dir"); | 
|  | 268 | return -1; | 
|  | 269 | } | 
|  | 270 |  | 
|  | 271 | snprintf(fname, sizeof(fname), "%s/stations", buf); | 
|  | 272 | f = fopen(fname, "r"); | 
|  | 273 | if (!f) { | 
|  | 274 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 275 | "failed to open: %s", fname); | 
|  | 276 | return -1; | 
|  | 277 | } | 
|  | 278 |  | 
|  | 279 | if (regcomp(&re, pattern, REG_EXTENDED)) { | 
|  | 280 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 281 | "regcomp failed: %s", pattern); | 
|  | 282 | goto out; | 
|  | 283 | } | 
|  | 284 |  | 
|  | 285 | /* | 
|  | 286 | * find the entry for the mac address | 
|  | 287 | * line is of the form: [n] 11:22:33:44:55:66 state AID aid | 
|  | 288 | */ | 
|  | 289 | while (fgets(buf, sizeof(buf), f)) { | 
|  | 290 | if (strcasestr(buf, bssid)) { | 
|  | 291 | /* extract the field (CID/AID/state) */ | 
|  | 292 | rc = regexec(&re, buf, 2, m, 0); | 
|  | 293 | if (!rc && (m[1].rm_so >= 0)) { | 
|  | 294 | buf[m[1].rm_eo] = 0; | 
|  | 295 | *field = atoi(&buf[m[1].rm_so]); | 
|  | 296 | ret = 0; | 
|  | 297 | break; | 
|  | 298 | } | 
|  | 299 | } | 
|  | 300 | } | 
|  | 301 |  | 
|  | 302 | regfree(&re); | 
|  | 303 | if (ret) | 
|  | 304 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 305 | "could not extract field"); | 
|  | 306 |  | 
|  | 307 | out: | 
|  | 308 | fclose(f); | 
|  | 309 |  | 
|  | 310 | return ret; | 
|  | 311 | } | 
|  | 312 |  | 
|  | 313 |  | 
|  | 314 | static int wil6210_get_cid(struct sigma_dut *dut, const char *bssid, | 
|  | 315 | unsigned int *cid) | 
|  | 316 | { | 
|  | 317 | const char *pattern = "\\[([0-9]+)\\]"; | 
|  | 318 |  | 
|  | 319 | return wil6210_get_sta_info_field(dut, bssid, pattern, cid); | 
|  | 320 | } | 
|  | 321 |  | 
|  | 322 |  | 
|  | 323 | static int wil6210_send_brp_rx(struct sigma_dut *dut, const char *mac, | 
|  | 324 | int l_rx) | 
|  | 325 | { | 
| Rakesh Sunki | 556237d | 2017-03-30 14:49:31 -0700 | [diff] [blame] | 326 | struct wil_wmi_bf_trig_cmd cmd; | 
| Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 327 | unsigned int cid; | 
|  | 328 |  | 
| Rakesh Sunki | 556237d | 2017-03-30 14:49:31 -0700 | [diff] [blame] | 329 | memset(&cmd, 0, sizeof(cmd)); | 
|  | 330 |  | 
| Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 331 | if (wil6210_get_cid(dut, mac, &cid)) | 
|  | 332 | return -1; | 
|  | 333 |  | 
|  | 334 | cmd.bf_type = WIL_WMI_BRP_RX; | 
|  | 335 | cmd.sta_id = cid; | 
|  | 336 | /* training length (l_rx) is ignored, FW always uses length 16 */ | 
|  | 337 | return wil6210_wmi_send(dut, WIL_WMI_BF_TRIG_CMDID, | 
|  | 338 | &cmd, sizeof(cmd)); | 
|  | 339 | } | 
|  | 340 |  | 
|  | 341 |  | 
|  | 342 | static int wil6210_send_sls(struct sigma_dut *dut, const char *mac) | 
|  | 343 | { | 
| Rakesh Sunki | 556237d | 2017-03-30 14:49:31 -0700 | [diff] [blame] | 344 | struct wil_wmi_bf_trig_cmd cmd; | 
|  | 345 |  | 
|  | 346 | memset(&cmd, 0, sizeof(cmd)); | 
| Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 347 |  | 
|  | 348 | if (parse_mac_address(dut, mac, (unsigned char *)&cmd.dest_mac)) | 
|  | 349 | return -1; | 
|  | 350 |  | 
|  | 351 | cmd.bf_type = WIL_WMI_SLS; | 
|  | 352 | return wil6210_wmi_send(dut, WIL_WMI_BF_TRIG_CMDID, | 
|  | 353 | &cmd, sizeof(cmd)); | 
|  | 354 | } | 
|  | 355 |  | 
| Lior David | cc88b56 | 2017-01-03 18:52:09 +0200 | [diff] [blame] | 356 | #endif /* __linux__ */ | 
|  | 357 |  | 
|  | 358 |  | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 359 | static void static_ip_file(int proto, const char *addr, const char *mask, | 
|  | 360 | const char *gw) | 
|  | 361 | { | 
|  | 362 | if (proto) { | 
|  | 363 | FILE *f = fopen("static-ip", "w"); | 
|  | 364 | if (f) { | 
|  | 365 | fprintf(f, "%d %s %s %s\n", proto, addr, | 
|  | 366 | mask ? mask : "N/A", | 
|  | 367 | gw ? gw : "N/A"); | 
|  | 368 | fclose(f); | 
|  | 369 | } | 
|  | 370 | } else { | 
|  | 371 | unlink("static-ip"); | 
|  | 372 | } | 
|  | 373 | } | 
|  | 374 |  | 
|  | 375 |  | 
|  | 376 | static int send_neighbor_request(struct sigma_dut *dut, const char *intf, | 
|  | 377 | const char *ssid) | 
|  | 378 | { | 
|  | 379 | #ifdef __linux__ | 
|  | 380 | char buf[100]; | 
|  | 381 |  | 
|  | 382 | snprintf(buf, sizeof(buf), "iwpriv %s neighbor %s", | 
|  | 383 | intf, ssid); | 
|  | 384 | sigma_dut_print(dut, DUT_MSG_INFO, "Request: %s", buf); | 
|  | 385 |  | 
|  | 386 | if (system(buf) != 0) { | 
|  | 387 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 388 | "iwpriv neighbor request failed"); | 
|  | 389 | return -1; | 
|  | 390 | } | 
|  | 391 |  | 
|  | 392 | sigma_dut_print(dut, DUT_MSG_INFO, "iwpriv neighbor request send"); | 
|  | 393 |  | 
|  | 394 | return 0; | 
|  | 395 | #else /* __linux__ */ | 
|  | 396 | return -1; | 
|  | 397 | #endif /* __linux__ */ | 
|  | 398 | } | 
|  | 399 |  | 
|  | 400 |  | 
|  | 401 | static int send_trans_mgmt_query(struct sigma_dut *dut, const char *intf, | 
| Ashwini Patil | 5acd738 | 2017-04-13 15:55:04 +0530 | [diff] [blame] | 402 | struct sigma_cmd *cmd) | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 403 | { | 
| Ashwini Patil | 5acd738 | 2017-04-13 15:55:04 +0530 | [diff] [blame] | 404 | const char *val; | 
|  | 405 | int reason_code = 0; | 
|  | 406 | char buf[1024]; | 
|  | 407 |  | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 408 | /* | 
|  | 409 | * In the earlier builds we used WNM_QUERY and in later | 
|  | 410 | * builds used WNM_BSS_QUERY. | 
|  | 411 | */ | 
|  | 412 |  | 
| Ashwini Patil | 5acd738 | 2017-04-13 15:55:04 +0530 | [diff] [blame] | 413 | val = get_param(cmd, "BTMQuery_Reason_Code"); | 
|  | 414 | if (val) | 
|  | 415 | reason_code = atoi(val); | 
|  | 416 |  | 
|  | 417 | val = get_param(cmd, "Cand_List"); | 
|  | 418 | if (val && atoi(val) == 1 && dut->btm_query_cand_list) { | 
|  | 419 | snprintf(buf, sizeof(buf), "WNM_BSS_QUERY %d%s", reason_code, | 
|  | 420 | dut->btm_query_cand_list); | 
|  | 421 | free(dut->btm_query_cand_list); | 
|  | 422 | dut->btm_query_cand_list = NULL; | 
|  | 423 | } else { | 
|  | 424 | snprintf(buf, sizeof(buf), "WNM_BSS_QUERY %d", reason_code); | 
|  | 425 | } | 
|  | 426 |  | 
|  | 427 | if (wpa_command(intf, buf) != 0) { | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 428 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 429 | "transition management query failed"); | 
|  | 430 | return -1; | 
|  | 431 | } | 
|  | 432 |  | 
|  | 433 | sigma_dut_print(dut, DUT_MSG_DEBUG, | 
|  | 434 | "transition management query sent"); | 
|  | 435 |  | 
|  | 436 | return 0; | 
|  | 437 | } | 
|  | 438 |  | 
|  | 439 |  | 
|  | 440 | int is_ip_addr(const char *str) | 
|  | 441 | { | 
|  | 442 | const char *pos = str; | 
|  | 443 | struct in_addr addr; | 
|  | 444 |  | 
|  | 445 | while (*pos) { | 
|  | 446 | if (*pos != '.' && (*pos < '0' || *pos > '9')) | 
|  | 447 | return 0; | 
|  | 448 | pos++; | 
|  | 449 | } | 
|  | 450 |  | 
|  | 451 | return inet_aton(str, &addr); | 
|  | 452 | } | 
|  | 453 |  | 
|  | 454 |  | 
|  | 455 | int is_ipv6_addr(const char *str) | 
|  | 456 | { | 
|  | 457 | struct sockaddr_in6 addr; | 
|  | 458 |  | 
|  | 459 | return inet_pton(AF_INET6, str, &(addr.sin6_addr)); | 
|  | 460 | } | 
|  | 461 |  | 
|  | 462 |  | 
|  | 463 | int get_ip_config(struct sigma_dut *dut, const char *ifname, char *buf, | 
|  | 464 | size_t buf_len) | 
|  | 465 | { | 
|  | 466 | char tmp[256], *pos, *pos2; | 
|  | 467 | FILE *f; | 
|  | 468 | char ip[16], mask[15], dns[16], sec_dns[16]; | 
| Sarvepalli, Rajesh Babu | a76c644 | 2016-03-18 20:34:26 +0530 | [diff] [blame] | 469 | const char *str_ps; | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 470 | int is_dhcp = 0; | 
|  | 471 | int s; | 
|  | 472 | #ifdef ANDROID | 
|  | 473 | char prop[PROPERTY_VALUE_MAX]; | 
|  | 474 | #endif /* ANDROID */ | 
|  | 475 |  | 
|  | 476 | ip[0] = '\0'; | 
|  | 477 | mask[0] = '\0'; | 
|  | 478 | dns[0] = '\0'; | 
|  | 479 | sec_dns[0] = '\0'; | 
|  | 480 |  | 
|  | 481 | s = socket(PF_INET, SOCK_DGRAM, 0); | 
|  | 482 | if (s >= 0) { | 
|  | 483 | struct ifreq ifr; | 
|  | 484 | struct sockaddr_in saddr; | 
|  | 485 |  | 
|  | 486 | memset(&ifr, 0, sizeof(ifr)); | 
| Peng Xu | b8fc5cc | 2017-05-10 17:27:28 -0700 | [diff] [blame] | 487 | strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 488 | if (ioctl(s, SIOCGIFADDR, &ifr) < 0) { | 
|  | 489 | sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get " | 
|  | 490 | "%s IP address: %s", | 
|  | 491 | ifname, strerror(errno)); | 
|  | 492 | } else { | 
|  | 493 | memcpy(&saddr, &ifr.ifr_addr, | 
|  | 494 | sizeof(struct sockaddr_in)); | 
| Peng Xu | b8fc5cc | 2017-05-10 17:27:28 -0700 | [diff] [blame] | 495 | strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip)); | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 496 | } | 
|  | 497 |  | 
|  | 498 | if (ioctl(s, SIOCGIFNETMASK, &ifr) == 0) { | 
|  | 499 | memcpy(&saddr, &ifr.ifr_addr, | 
|  | 500 | sizeof(struct sockaddr_in)); | 
| Peng Xu | b8fc5cc | 2017-05-10 17:27:28 -0700 | [diff] [blame] | 501 | strlcpy(mask, inet_ntoa(saddr.sin_addr), sizeof(mask)); | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 502 | } | 
|  | 503 | close(s); | 
|  | 504 | } | 
|  | 505 |  | 
|  | 506 | #ifdef ANDROID | 
|  | 507 | snprintf(tmp, sizeof(tmp), "dhcp.%s.pid", ifname); | 
|  | 508 | if (property_get(tmp, prop, NULL) != 0 && atoi(prop) > 0) { | 
|  | 509 | snprintf(tmp, sizeof(tmp), "dhcp.%s.result", ifname); | 
|  | 510 | if (property_get(tmp, prop, NULL) != 0 && | 
|  | 511 | strcmp(prop, "ok") == 0) { | 
|  | 512 | snprintf(tmp, sizeof(tmp), "dhcp.%s.ipaddress", | 
|  | 513 | ifname); | 
|  | 514 | if (property_get(tmp, prop, NULL) != 0 && | 
|  | 515 | strcmp(ip, prop) == 0) | 
|  | 516 | is_dhcp = 1; | 
|  | 517 | } | 
|  | 518 | } | 
|  | 519 |  | 
|  | 520 | snprintf(tmp, sizeof(tmp), "dhcp.%s.dns1", ifname); | 
| Peng Xu | b8fc5cc | 2017-05-10 17:27:28 -0700 | [diff] [blame] | 521 | if (property_get(tmp, prop, NULL) != 0) | 
|  | 522 | strlcpy(dns, prop, sizeof(dns)); | 
|  | 523 | else if (property_get("net.dns1", prop, NULL) != 0) | 
|  | 524 | strlcpy(dns, prop, sizeof(dns)); | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 525 |  | 
|  | 526 | snprintf(tmp, sizeof(tmp), "dhcp.%s.dns2", ifname); | 
| Peng Xu | b8fc5cc | 2017-05-10 17:27:28 -0700 | [diff] [blame] | 527 | if (property_get(tmp, prop, NULL) != 0) | 
|  | 528 | strlcpy(sec_dns, prop, sizeof(sec_dns)); | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 529 | #else /* ANDROID */ | 
|  | 530 | #ifdef __linux__ | 
| Sarvepalli, Rajesh Babu | a76c644 | 2016-03-18 20:34:26 +0530 | [diff] [blame] | 531 | if (get_driver_type() == DRIVER_OPENWRT) | 
|  | 532 | str_ps = "ps -w"; | 
|  | 533 | else | 
|  | 534 | str_ps = "ps ax"; | 
|  | 535 | snprintf(tmp, sizeof(tmp), | 
|  | 536 | "%s | grep dhclient | grep -v grep | grep -q %s", | 
|  | 537 | str_ps, ifname); | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 538 | if (system(tmp) == 0) | 
|  | 539 | is_dhcp = 1; | 
|  | 540 | else { | 
| Sarvepalli, Rajesh Babu | a76c644 | 2016-03-18 20:34:26 +0530 | [diff] [blame] | 541 | snprintf(tmp, sizeof(tmp), | 
|  | 542 | "%s | grep udhcpc | grep -v grep | grep -q %s", | 
|  | 543 | str_ps, ifname); | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 544 | if (system(tmp) == 0) | 
|  | 545 | is_dhcp = 1; | 
|  | 546 | else { | 
| Sarvepalli, Rajesh Babu | a76c644 | 2016-03-18 20:34:26 +0530 | [diff] [blame] | 547 | snprintf(tmp, sizeof(tmp), | 
|  | 548 | "%s | grep dhcpcd | grep -v grep | grep -q %s", | 
|  | 549 | str_ps, ifname); | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 550 | if (system(tmp) == 0) | 
|  | 551 | is_dhcp = 1; | 
|  | 552 | } | 
|  | 553 | } | 
|  | 554 | #endif /* __linux__ */ | 
|  | 555 |  | 
|  | 556 | f = fopen("/etc/resolv.conf", "r"); | 
|  | 557 | if (f) { | 
|  | 558 | while (fgets(tmp, sizeof(tmp), f)) { | 
|  | 559 | if (strncmp(tmp, "nameserver", 10) != 0) | 
|  | 560 | continue; | 
|  | 561 | pos = tmp + 10; | 
|  | 562 | while (*pos == ' ' || *pos == '\t') | 
|  | 563 | pos++; | 
|  | 564 | pos2 = pos; | 
|  | 565 | while (*pos2) { | 
|  | 566 | if (*pos2 == '\n' || *pos2 == '\r') { | 
|  | 567 | *pos2 = '\0'; | 
|  | 568 | break; | 
|  | 569 | } | 
|  | 570 | pos2++; | 
|  | 571 | } | 
| Peng Xu | b8fc5cc | 2017-05-10 17:27:28 -0700 | [diff] [blame] | 572 | if (!dns[0]) | 
|  | 573 | strlcpy(dns, pos, sizeof(dns)); | 
|  | 574 | else if (!sec_dns[0]) | 
|  | 575 | strlcpy(sec_dns, pos, sizeof(sec_dns)); | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 576 | } | 
|  | 577 | fclose(f); | 
|  | 578 | } | 
|  | 579 | #endif /* ANDROID */ | 
|  | 580 |  | 
|  | 581 | snprintf(buf, buf_len, "dhcp,%d,ip,%s,mask,%s,primary-dns,%s", | 
|  | 582 | is_dhcp, ip, mask, dns); | 
|  | 583 | buf[buf_len - 1] = '\0'; | 
|  | 584 |  | 
|  | 585 | return 0; | 
|  | 586 | } | 
|  | 587 |  | 
|  | 588 |  | 
|  | 589 |  | 
|  | 590 |  | 
|  | 591 | int get_ipv6_config(struct sigma_dut *dut, const char *ifname, char *buf, | 
|  | 592 | size_t buf_len) | 
|  | 593 | { | 
|  | 594 | #ifdef __linux__ | 
|  | 595 | #ifdef ANDROID | 
|  | 596 | char cmd[200], result[1000], *pos, *end; | 
|  | 597 | FILE *f; | 
|  | 598 | size_t len; | 
|  | 599 |  | 
|  | 600 | snprintf(cmd, sizeof(cmd), "ip addr show dev %s scope global", ifname); | 
|  | 601 | f = popen(cmd, "r"); | 
|  | 602 | if (f == NULL) | 
|  | 603 | return -1; | 
|  | 604 | len = fread(result, 1, sizeof(result) - 1, f); | 
|  | 605 | pclose(f); | 
|  | 606 | if (len == 0) | 
|  | 607 | return -1; | 
|  | 608 | result[len] = '\0'; | 
|  | 609 | sigma_dut_print(dut, DUT_MSG_DEBUG, "%s result: %s\n", cmd, result); | 
|  | 610 |  | 
|  | 611 | pos = strstr(result, "inet6 "); | 
|  | 612 | if (pos == NULL) | 
|  | 613 | return -1; | 
|  | 614 | pos += 6; | 
|  | 615 | end = strchr(pos, ' '); | 
|  | 616 | if (end) | 
|  | 617 | *end = '\0'; | 
|  | 618 | end = strchr(pos, '/'); | 
|  | 619 | if (end) | 
|  | 620 | *end = '\0'; | 
|  | 621 | snprintf(buf, buf_len, "ip,%s", pos); | 
|  | 622 | buf[buf_len - 1] = '\0'; | 
|  | 623 | return 0; | 
|  | 624 | #else /* ANDROID */ | 
|  | 625 | struct ifaddrs *ifaddr, *ifa; | 
|  | 626 | int res, found = 0; | 
|  | 627 | char host[NI_MAXHOST]; | 
|  | 628 |  | 
|  | 629 | if (getifaddrs(&ifaddr) < 0) { | 
|  | 630 | perror("getifaddrs"); | 
|  | 631 | return -1; | 
|  | 632 | } | 
|  | 633 |  | 
|  | 634 | for (ifa = ifaddr; ifa; ifa = ifa->ifa_next) { | 
|  | 635 | if (strcasecmp(ifname, ifa->ifa_name) != 0) | 
|  | 636 | continue; | 
|  | 637 | if (ifa->ifa_addr == NULL || | 
|  | 638 | ifa->ifa_addr->sa_family != AF_INET6) | 
|  | 639 | continue; | 
|  | 640 |  | 
|  | 641 | res = getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in6), | 
|  | 642 | host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST); | 
|  | 643 | if (res != 0) { | 
|  | 644 | sigma_dut_print(dut, DUT_MSG_DEBUG, "getnameinfo: %s", | 
|  | 645 | gai_strerror(res)); | 
|  | 646 | continue; | 
|  | 647 | } | 
|  | 648 | if (strncmp(host, "fe80::", 6) == 0) | 
|  | 649 | continue; /* skip link-local */ | 
|  | 650 |  | 
|  | 651 | sigma_dut_print(dut, DUT_MSG_DEBUG, "ifaddr: %s", host); | 
|  | 652 | found = 1; | 
|  | 653 | break; | 
|  | 654 | } | 
|  | 655 |  | 
|  | 656 | freeifaddrs(ifaddr); | 
|  | 657 |  | 
|  | 658 | if (found) { | 
|  | 659 | char *pos; | 
|  | 660 | pos = strchr(host, '%'); | 
|  | 661 | if (pos) | 
|  | 662 | *pos = '\0'; | 
|  | 663 | snprintf(buf, buf_len, "ip,%s", host); | 
|  | 664 | buf[buf_len - 1] = '\0'; | 
|  | 665 | return 0; | 
|  | 666 | } | 
|  | 667 |  | 
|  | 668 | #endif /* ANDROID */ | 
|  | 669 | #endif /* __linux__ */ | 
|  | 670 | return -1; | 
|  | 671 | } | 
|  | 672 |  | 
|  | 673 |  | 
|  | 674 | static int cmd_sta_get_ip_config(struct sigma_dut *dut, | 
|  | 675 | struct sigma_conn *conn, | 
|  | 676 | struct sigma_cmd *cmd) | 
|  | 677 | { | 
|  | 678 | const char *intf = get_param(cmd, "Interface"); | 
|  | 679 | const char *ifname; | 
|  | 680 | char buf[200]; | 
|  | 681 | const char *val; | 
|  | 682 | int type = 1; | 
|  | 683 |  | 
|  | 684 | if (intf == NULL) | 
|  | 685 | return -1; | 
|  | 686 |  | 
|  | 687 | if (strcmp(intf, get_main_ifname()) == 0) | 
|  | 688 | ifname = get_station_ifname(); | 
|  | 689 | else | 
|  | 690 | ifname = intf; | 
|  | 691 |  | 
|  | 692 | /* | 
|  | 693 | * UCC may assume the IP address to be available immediately after | 
|  | 694 | * association without trying to run sta_get_ip_config multiple times. | 
|  | 695 | * Sigma CAPI does not specify this command as a block command that | 
|  | 696 | * would wait for the address to become available, but to pass tests | 
|  | 697 | * more reliably, it looks like such a wait may be needed here. | 
|  | 698 | */ | 
|  | 699 | if (wait_ip_addr(dut, ifname, 15) < 0) { | 
|  | 700 | sigma_dut_print(dut, DUT_MSG_INFO, "Could not get IP address " | 
|  | 701 | "for sta_get_ip_config"); | 
|  | 702 | /* | 
|  | 703 | * Try to continue anyway since many UCC tests do not really | 
|  | 704 | * care about the return value from here.. | 
|  | 705 | */ | 
|  | 706 | } | 
|  | 707 |  | 
|  | 708 | val = get_param(cmd, "Type"); | 
|  | 709 | if (val) | 
|  | 710 | type = atoi(val); | 
|  | 711 | if (type == 2 || dut->last_set_ip_config_ipv6) { | 
|  | 712 | int i; | 
|  | 713 |  | 
|  | 714 | /* | 
|  | 715 | * Since we do not have proper wait for IPv6 addresses, use a | 
|  | 716 | * fixed two second delay here as a workaround for UCC script | 
|  | 717 | * assuming IPv6 address is available when this command returns. | 
|  | 718 | * Some scripts did not use Type,2 properly for IPv6, so include | 
|  | 719 | * also the cases where the previous sta_set_ip_config indicated | 
|  | 720 | * use of IPv6. | 
|  | 721 | */ | 
|  | 722 | sigma_dut_print(dut, DUT_MSG_INFO, "Wait up to extra ten seconds in sta_get_ip_config for IPv6 address"); | 
|  | 723 | for (i = 0; i < 10; i++) { | 
|  | 724 | sleep(1); | 
|  | 725 | if (get_ipv6_config(dut, ifname, buf, sizeof(buf)) == 0) | 
|  | 726 | { | 
|  | 727 | sigma_dut_print(dut, DUT_MSG_INFO, "Found IPv6 address"); | 
|  | 728 | send_resp(dut, conn, SIGMA_COMPLETE, buf); | 
|  | 729 | #ifdef ANDROID | 
|  | 730 | sigma_dut_print(dut, DUT_MSG_INFO, | 
|  | 731 | "Adding IPv6 rule on Android"); | 
|  | 732 | add_ipv6_rule(dut, intf); | 
|  | 733 | #endif /* ANDROID */ | 
|  | 734 |  | 
|  | 735 | return 0; | 
|  | 736 | } | 
|  | 737 | } | 
|  | 738 | } | 
|  | 739 | if (type == 1) { | 
|  | 740 | if (get_ip_config(dut, ifname, buf, sizeof(buf)) < 0) | 
|  | 741 | return -2; | 
|  | 742 | } else if (type == 2) { | 
|  | 743 | if (get_ipv6_config(dut, ifname, buf, sizeof(buf)) < 0) | 
|  | 744 | return -2; | 
|  | 745 | } else { | 
|  | 746 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 747 | "errorCode,Unsupported address type"); | 
|  | 748 | return 0; | 
|  | 749 | } | 
|  | 750 |  | 
|  | 751 | send_resp(dut, conn, SIGMA_COMPLETE, buf); | 
|  | 752 | return 0; | 
|  | 753 | } | 
|  | 754 |  | 
|  | 755 |  | 
|  | 756 | static void kill_dhcp_client(struct sigma_dut *dut, const char *ifname) | 
|  | 757 | { | 
|  | 758 | #ifdef __linux__ | 
|  | 759 | char buf[200]; | 
|  | 760 | char path[128]; | 
|  | 761 | struct stat s; | 
|  | 762 |  | 
|  | 763 | #ifdef ANDROID | 
|  | 764 | snprintf(path, sizeof(path), "/data/misc/dhcp/dhcpcd-%s.pid", ifname); | 
|  | 765 | #else /* ANDROID */ | 
|  | 766 | snprintf(path, sizeof(path), "/var/run/dhclient-%s.pid", ifname); | 
|  | 767 | #endif /* ANDROID */ | 
|  | 768 | if (stat(path, &s) == 0) { | 
|  | 769 | snprintf(buf, sizeof(buf), "kill `cat %s`", path); | 
|  | 770 | sigma_dut_print(dut, DUT_MSG_INFO, | 
|  | 771 | "Kill previous DHCP client: %s", buf); | 
|  | 772 | if (system(buf) != 0) | 
|  | 773 | sigma_dut_print(dut, DUT_MSG_INFO, | 
|  | 774 | "Failed to kill DHCP client"); | 
|  | 775 | unlink(path); | 
|  | 776 | sleep(1); | 
|  | 777 | } else { | 
|  | 778 | snprintf(path, sizeof(path), "/var/run/dhcpcd-%s.pid", ifname); | 
|  | 779 |  | 
|  | 780 | if (stat(path, &s) == 0) { | 
|  | 781 | snprintf(buf, sizeof(buf), "kill `cat %s`", path); | 
|  | 782 | sigma_dut_print(dut, DUT_MSG_INFO, | 
|  | 783 | "Kill previous DHCP client: %s", buf); | 
|  | 784 | if (system(buf) != 0) | 
|  | 785 | sigma_dut_print(dut, DUT_MSG_INFO, | 
|  | 786 | "Failed to kill DHCP client"); | 
|  | 787 | unlink(path); | 
|  | 788 | sleep(1); | 
|  | 789 | } | 
|  | 790 | } | 
|  | 791 | #endif /* __linux__ */ | 
|  | 792 | } | 
|  | 793 |  | 
|  | 794 |  | 
|  | 795 | static int start_dhcp_client(struct sigma_dut *dut, const char *ifname) | 
|  | 796 | { | 
|  | 797 | #ifdef __linux__ | 
|  | 798 | char buf[200]; | 
|  | 799 |  | 
|  | 800 | #ifdef ANDROID | 
| Purushottam Kushwaha | 46d6426 | 2016-08-23 17:57:53 +0530 | [diff] [blame] | 801 | if (access("/system/bin/dhcpcd", F_OK) != -1) { | 
|  | 802 | snprintf(buf, sizeof(buf), | 
|  | 803 | "/system/bin/dhcpcd -b %s", ifname); | 
|  | 804 | } else if (access("/system/bin/dhcptool", F_OK) != -1) { | 
|  | 805 | snprintf(buf, sizeof(buf), "/system/bin/dhcptool %s &", ifname); | 
|  | 806 | } else { | 
|  | 807 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 808 | "DHCP client program missing"); | 
|  | 809 | return 0; | 
|  | 810 | } | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 811 | #else /* ANDROID */ | 
|  | 812 | snprintf(buf, sizeof(buf), | 
|  | 813 | "dhclient -nw -pf /var/run/dhclient-%s.pid %s", | 
|  | 814 | ifname, ifname); | 
|  | 815 | #endif /* ANDROID */ | 
|  | 816 | sigma_dut_print(dut, DUT_MSG_INFO, "Start DHCP client: %s", buf); | 
|  | 817 | if (system(buf) != 0) { | 
|  | 818 | snprintf(buf, sizeof(buf), "dhcpcd -t 0 %s &", ifname); | 
|  | 819 | if (system(buf) != 0) { | 
|  | 820 | sigma_dut_print(dut, DUT_MSG_INFO, | 
|  | 821 | "Failed to start DHCP client"); | 
|  | 822 | #ifndef ANDROID | 
|  | 823 | return -1; | 
|  | 824 | #endif /* ANDROID */ | 
|  | 825 | } | 
|  | 826 | } | 
|  | 827 | #endif /* __linux__ */ | 
|  | 828 |  | 
|  | 829 | return 0; | 
|  | 830 | } | 
|  | 831 |  | 
|  | 832 |  | 
|  | 833 | static int clear_ip_addr(struct sigma_dut *dut, const char *ifname) | 
|  | 834 | { | 
|  | 835 | #ifdef __linux__ | 
|  | 836 | char buf[200]; | 
|  | 837 |  | 
|  | 838 | snprintf(buf, sizeof(buf), "ip addr flush dev %s", ifname); | 
|  | 839 | if (system(buf) != 0) { | 
|  | 840 | sigma_dut_print(dut, DUT_MSG_INFO, | 
|  | 841 | "Failed to clear IP addresses"); | 
|  | 842 | return -1; | 
|  | 843 | } | 
|  | 844 | #endif /* __linux__ */ | 
|  | 845 |  | 
|  | 846 | return 0; | 
|  | 847 | } | 
|  | 848 |  | 
|  | 849 |  | 
|  | 850 | #ifdef ANDROID | 
|  | 851 | static int add_ipv6_rule(struct sigma_dut *dut, const char *ifname) | 
|  | 852 | { | 
|  | 853 | char cmd[200], *result, *pos; | 
|  | 854 | FILE *fp; | 
| Pradeep Reddy POTTETI | f58a1fe | 2016-10-13 17:22:03 +0530 | [diff] [blame] | 855 | int tableid; | 
|  | 856 | size_t len, result_len = 1000; | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 857 |  | 
|  | 858 | snprintf(cmd, sizeof(cmd), "ip -6 route list table all | grep %s", | 
|  | 859 | ifname); | 
|  | 860 | fp = popen(cmd, "r"); | 
|  | 861 | if (fp == NULL) | 
|  | 862 | return -1; | 
|  | 863 |  | 
|  | 864 | result = malloc(result_len); | 
| Pradeep Reddy POTTETI | 673d85c | 2016-07-26 19:08:07 +0530 | [diff] [blame] | 865 | if (result == NULL) { | 
|  | 866 | fclose(fp); | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 867 | return -1; | 
| Pradeep Reddy POTTETI | 673d85c | 2016-07-26 19:08:07 +0530 | [diff] [blame] | 868 | } | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 869 |  | 
| Pradeep Reddy POTTETI | f58a1fe | 2016-10-13 17:22:03 +0530 | [diff] [blame] | 870 | len = fread(result, 1, result_len - 1, fp); | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 871 | fclose(fp); | 
|  | 872 |  | 
|  | 873 | if (len == 0) { | 
|  | 874 | free(result); | 
|  | 875 | return -1; | 
|  | 876 | } | 
| Pradeep Reddy POTTETI | f58a1fe | 2016-10-13 17:22:03 +0530 | [diff] [blame] | 877 | result[len] = '\0'; | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 878 |  | 
|  | 879 | pos = strstr(result, "table "); | 
|  | 880 | if (pos == NULL) { | 
|  | 881 | free(result); | 
|  | 882 | return -1; | 
|  | 883 | } | 
|  | 884 |  | 
|  | 885 | pos += strlen("table "); | 
|  | 886 | tableid = atoi(pos); | 
|  | 887 | if (tableid != 0) { | 
|  | 888 | if (system("ip -6 rule del prio 22000") != 0) { | 
|  | 889 | /* ignore any error */ | 
|  | 890 | } | 
|  | 891 | snprintf(cmd, sizeof(cmd), | 
|  | 892 | "ip -6 rule add from all lookup %d prio 22000", | 
|  | 893 | tableid); | 
|  | 894 | if (system(cmd) != 0) { | 
|  | 895 | sigma_dut_print(dut, DUT_MSG_INFO, | 
|  | 896 | "Failed to run %s", cmd); | 
|  | 897 | free(result); | 
|  | 898 | return -1; | 
|  | 899 | } | 
|  | 900 | } else { | 
|  | 901 | sigma_dut_print(dut, DUT_MSG_INFO, | 
|  | 902 | "No Valid Table Id found %s", pos); | 
|  | 903 | free(result); | 
|  | 904 | return -1; | 
|  | 905 | } | 
|  | 906 | free(result); | 
|  | 907 |  | 
|  | 908 | return 0; | 
|  | 909 | } | 
|  | 910 | #endif /* ANDROID */ | 
|  | 911 |  | 
|  | 912 |  | 
| Ankita Bajaj | 1bde794 | 2018-01-09 19:15:01 +0530 | [diff] [blame] | 913 | int set_ipv4_addr(struct sigma_dut *dut, const char *ifname, | 
|  | 914 | const char *ip, const char *mask) | 
|  | 915 | { | 
|  | 916 | char buf[200]; | 
|  | 917 |  | 
|  | 918 | snprintf(buf, sizeof(buf), "ifconfig %s %s netmask %s", | 
|  | 919 | ifname, ip, mask); | 
|  | 920 | return system(buf) == 0; | 
|  | 921 | } | 
|  | 922 |  | 
|  | 923 |  | 
|  | 924 | int set_ipv4_gw(struct sigma_dut *dut, const char *gw) | 
|  | 925 | { | 
|  | 926 | char buf[200]; | 
|  | 927 |  | 
|  | 928 | if (!is_ip_addr(gw)) { | 
|  | 929 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Invalid gw addr - %s", gw); | 
|  | 930 | return -1; | 
|  | 931 | } | 
|  | 932 |  | 
|  | 933 | snprintf(buf, sizeof(buf), "route add default gw %s", gw); | 
|  | 934 | if (!dut->no_ip_addr_set && system(buf) != 0) { | 
|  | 935 | snprintf(buf, sizeof(buf), "ip ro re default via %s", | 
|  | 936 | gw); | 
|  | 937 | if (system(buf) != 0) | 
|  | 938 | return 0; | 
|  | 939 | } | 
|  | 940 |  | 
|  | 941 | return 1; | 
|  | 942 | } | 
|  | 943 |  | 
|  | 944 |  | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 945 | static int cmd_sta_set_ip_config(struct sigma_dut *dut, | 
|  | 946 | struct sigma_conn *conn, | 
|  | 947 | struct sigma_cmd *cmd) | 
|  | 948 | { | 
|  | 949 | const char *intf = get_param(cmd, "Interface"); | 
|  | 950 | const char *ifname; | 
|  | 951 | char buf[200]; | 
|  | 952 | const char *val, *ip, *mask, *gw; | 
|  | 953 | int type = 1; | 
|  | 954 |  | 
|  | 955 | if (intf == NULL) | 
|  | 956 | return -1; | 
|  | 957 |  | 
|  | 958 | if (strcmp(intf, get_main_ifname()) == 0) | 
|  | 959 | ifname = get_station_ifname(); | 
|  | 960 | else | 
|  | 961 | ifname = intf; | 
|  | 962 |  | 
|  | 963 | if (if_nametoindex(ifname) == 0) { | 
|  | 964 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 965 | "ErrorCode,Unknown interface"); | 
|  | 966 | return 0; | 
|  | 967 | } | 
|  | 968 |  | 
|  | 969 | val = get_param(cmd, "Type"); | 
|  | 970 | if (val) { | 
|  | 971 | type = atoi(val); | 
| Ankita Bajaj | 1bde794 | 2018-01-09 19:15:01 +0530 | [diff] [blame] | 972 | if (type < 1 || type > 3) { | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 973 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 974 | "ErrorCode,Unsupported address type"); | 
|  | 975 | return 0; | 
|  | 976 | } | 
|  | 977 | } | 
|  | 978 |  | 
|  | 979 | dut->last_set_ip_config_ipv6 = 0; | 
|  | 980 |  | 
|  | 981 | val = get_param(cmd, "dhcp"); | 
|  | 982 | if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "true") == 0)) { | 
|  | 983 | static_ip_file(0, NULL, NULL, NULL); | 
|  | 984 | #ifdef __linux__ | 
|  | 985 | if (type == 2) { | 
|  | 986 | dut->last_set_ip_config_ipv6 = 1; | 
|  | 987 | sigma_dut_print(dut, DUT_MSG_INFO, "Using IPv6 " | 
|  | 988 | "stateless address autoconfiguration"); | 
|  | 989 | #ifdef ANDROID | 
|  | 990 | /* | 
|  | 991 | * This sleep is required as the assignment in case of | 
|  | 992 | * Android is taking time and is done by the kernel. | 
|  | 993 | * The subsequent ping for IPv6 is impacting HS20 test | 
|  | 994 | * case. | 
|  | 995 | */ | 
|  | 996 | sleep(2); | 
|  | 997 | add_ipv6_rule(dut, intf); | 
|  | 998 | #endif /* ANDROID */ | 
|  | 999 | /* Assume this happens by default */ | 
|  | 1000 | return 1; | 
|  | 1001 | } | 
| Ankita Bajaj | 1bde794 | 2018-01-09 19:15:01 +0530 | [diff] [blame] | 1002 | if (type != 3) { | 
|  | 1003 | kill_dhcp_client(dut, ifname); | 
|  | 1004 | if (start_dhcp_client(dut, ifname) < 0) | 
|  | 1005 | return -2; | 
|  | 1006 | } else { | 
|  | 1007 | sigma_dut_print(dut, DUT_MSG_DEBUG, | 
|  | 1008 | "Using FILS HLP DHCPv4 Rapid Commit"); | 
|  | 1009 | } | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1010 |  | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1011 | return 1; | 
|  | 1012 | #endif /* __linux__ */ | 
|  | 1013 | return -2; | 
|  | 1014 | } | 
|  | 1015 |  | 
|  | 1016 | ip = get_param(cmd, "ip"); | 
| Pradeep Reddy POTTETI | b18c565 | 2016-01-18 12:45:37 +0530 | [diff] [blame] | 1017 | if (!ip) { | 
|  | 1018 | send_resp(dut, conn, SIGMA_INVALID, | 
|  | 1019 | "ErrorCode,Missing IP address"); | 
|  | 1020 | return 0; | 
|  | 1021 | } | 
|  | 1022 |  | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1023 | mask = get_param(cmd, "mask"); | 
| Pradeep Reddy POTTETI | b18c565 | 2016-01-18 12:45:37 +0530 | [diff] [blame] | 1024 | if (!mask) { | 
|  | 1025 | send_resp(dut, conn, SIGMA_INVALID, | 
|  | 1026 | "ErrorCode,Missing subnet mask"); | 
|  | 1027 | return 0; | 
|  | 1028 | } | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1029 |  | 
|  | 1030 | if (type == 2) { | 
|  | 1031 | int net = atoi(mask); | 
|  | 1032 |  | 
|  | 1033 | if ((net < 0 && net > 64) || !is_ipv6_addr(ip)) | 
|  | 1034 | return -1; | 
|  | 1035 |  | 
|  | 1036 | if (dut->no_ip_addr_set) { | 
|  | 1037 | snprintf(buf, sizeof(buf), | 
|  | 1038 | "sysctl net.ipv6.conf.%s.disable_ipv6=1", | 
|  | 1039 | ifname); | 
|  | 1040 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); | 
|  | 1041 | if (system(buf) != 0) { | 
|  | 1042 | sigma_dut_print(dut, DUT_MSG_DEBUG, | 
|  | 1043 | "Failed to disable IPv6 address before association"); | 
|  | 1044 | } | 
|  | 1045 | } else { | 
|  | 1046 | snprintf(buf, sizeof(buf), | 
|  | 1047 | "ip -6 addr del %s/%s dev %s", | 
|  | 1048 | ip, mask, ifname); | 
|  | 1049 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); | 
|  | 1050 | if (system(buf) != 0) { | 
|  | 1051 | /* | 
|  | 1052 | * This command may fail if the address being | 
|  | 1053 | * deleted does not exist. Inaction here is | 
|  | 1054 | * intentional. | 
|  | 1055 | */ | 
|  | 1056 | } | 
|  | 1057 |  | 
|  | 1058 | snprintf(buf, sizeof(buf), | 
|  | 1059 | "ip -6 addr add %s/%s dev %s", | 
|  | 1060 | ip, mask, ifname); | 
|  | 1061 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); | 
|  | 1062 | if (system(buf) != 0) { | 
|  | 1063 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 1064 | "ErrorCode,Failed to set IPv6 address"); | 
|  | 1065 | return 0; | 
|  | 1066 | } | 
|  | 1067 | } | 
|  | 1068 |  | 
|  | 1069 | dut->last_set_ip_config_ipv6 = 1; | 
|  | 1070 | static_ip_file(6, ip, mask, NULL); | 
|  | 1071 | return 1; | 
|  | 1072 | } else if (type == 1) { | 
| Pradeep Reddy POTTETI | b18c565 | 2016-01-18 12:45:37 +0530 | [diff] [blame] | 1073 | if (!is_ip_addr(ip) || !is_ip_addr(mask)) | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1074 | return -1; | 
|  | 1075 | } | 
|  | 1076 |  | 
|  | 1077 | kill_dhcp_client(dut, ifname); | 
|  | 1078 |  | 
|  | 1079 | if (!dut->no_ip_addr_set) { | 
| Ankita Bajaj | 1bde794 | 2018-01-09 19:15:01 +0530 | [diff] [blame] | 1080 | if (!set_ipv4_addr(dut, ifname, ip, mask)) { | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1081 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 1082 | "ErrorCode,Failed to set IP address"); | 
|  | 1083 | return 0; | 
|  | 1084 | } | 
|  | 1085 | } | 
|  | 1086 |  | 
|  | 1087 | gw = get_param(cmd, "defaultGateway"); | 
|  | 1088 | if (gw) { | 
| Ankita Bajaj | 1bde794 | 2018-01-09 19:15:01 +0530 | [diff] [blame] | 1089 | if (set_ipv4_gw(dut, gw) < 1) { | 
|  | 1090 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 1091 | "ErrorCode,Failed to set default gateway"); | 
|  | 1092 | return 0; | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1093 | } | 
|  | 1094 | } | 
|  | 1095 |  | 
|  | 1096 | val = get_param(cmd, "primary-dns"); | 
|  | 1097 | if (val) { | 
|  | 1098 | /* TODO */ | 
|  | 1099 | sigma_dut_print(dut, DUT_MSG_INFO, "Ignored primary-dns %s " | 
|  | 1100 | "setting", val); | 
|  | 1101 | } | 
|  | 1102 |  | 
|  | 1103 | val = get_param(cmd, "secondary-dns"); | 
|  | 1104 | if (val) { | 
|  | 1105 | /* TODO */ | 
|  | 1106 | sigma_dut_print(dut, DUT_MSG_INFO, "Ignored secondary-dns %s " | 
|  | 1107 | "setting", val); | 
|  | 1108 | } | 
|  | 1109 |  | 
|  | 1110 | static_ip_file(4, ip, mask, gw); | 
|  | 1111 |  | 
|  | 1112 | return 1; | 
|  | 1113 | } | 
|  | 1114 |  | 
|  | 1115 |  | 
|  | 1116 | static int cmd_sta_get_info(struct sigma_dut *dut, struct sigma_conn *conn, | 
|  | 1117 | struct sigma_cmd *cmd) | 
|  | 1118 | { | 
|  | 1119 | /* const char *intf = get_param(cmd, "Interface"); */ | 
|  | 1120 | /* TODO: could report more details here */ | 
|  | 1121 | send_resp(dut, conn, SIGMA_COMPLETE, "vendor,Atheros"); | 
|  | 1122 | return 0; | 
|  | 1123 | } | 
|  | 1124 |  | 
|  | 1125 |  | 
|  | 1126 | static int cmd_sta_get_mac_address(struct sigma_dut *dut, | 
|  | 1127 | struct sigma_conn *conn, | 
|  | 1128 | struct sigma_cmd *cmd) | 
|  | 1129 | { | 
|  | 1130 | /* const char *intf = get_param(cmd, "Interface"); */ | 
|  | 1131 | char addr[20], resp[50]; | 
|  | 1132 |  | 
| Ankita Bajaj | 0d5825b | 2017-10-25 16:20:17 +0530 | [diff] [blame] | 1133 | if (dut->dev_role == DEVROLE_STA_CFON) | 
|  | 1134 | return sta_cfon_get_mac_address(dut, conn, cmd); | 
|  | 1135 |  | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1136 | if (get_wpa_status(get_station_ifname(), "address", addr, sizeof(addr)) | 
|  | 1137 | < 0) | 
|  | 1138 | return -2; | 
|  | 1139 |  | 
|  | 1140 | snprintf(resp, sizeof(resp), "mac,%s", addr); | 
|  | 1141 | send_resp(dut, conn, SIGMA_COMPLETE, resp); | 
|  | 1142 | return 0; | 
|  | 1143 | } | 
|  | 1144 |  | 
|  | 1145 |  | 
|  | 1146 | static int cmd_sta_is_connected(struct sigma_dut *dut, struct sigma_conn *conn, | 
|  | 1147 | struct sigma_cmd *cmd) | 
|  | 1148 | { | 
|  | 1149 | /* const char *intf = get_param(cmd, "Interface"); */ | 
|  | 1150 | int connected = 0; | 
|  | 1151 | char result[32]; | 
|  | 1152 | if (get_wpa_status(get_station_ifname(), "wpa_state", result, | 
|  | 1153 | sizeof(result)) < 0) { | 
|  | 1154 | sigma_dut_print(dut, DUT_MSG_INFO, "Could not get interface " | 
|  | 1155 | "%s status", get_station_ifname()); | 
|  | 1156 | return -2; | 
|  | 1157 | } | 
|  | 1158 |  | 
|  | 1159 | sigma_dut_print(dut, DUT_MSG_DEBUG, "wpa_state=%s", result); | 
|  | 1160 | if (strncmp(result, "COMPLETED", 9) == 0) | 
|  | 1161 | connected = 1; | 
|  | 1162 |  | 
|  | 1163 | if (connected) | 
|  | 1164 | send_resp(dut, conn, SIGMA_COMPLETE, "connected,1"); | 
|  | 1165 | else | 
|  | 1166 | send_resp(dut, conn, SIGMA_COMPLETE, "connected,0"); | 
|  | 1167 |  | 
|  | 1168 | return 0; | 
|  | 1169 | } | 
|  | 1170 |  | 
|  | 1171 |  | 
|  | 1172 | static int cmd_sta_verify_ip_connection(struct sigma_dut *dut, | 
|  | 1173 | struct sigma_conn *conn, | 
|  | 1174 | struct sigma_cmd *cmd) | 
|  | 1175 | { | 
|  | 1176 | /* const char *intf = get_param(cmd, "Interface"); */ | 
|  | 1177 | const char *dst, *timeout; | 
|  | 1178 | int wait_time = 90; | 
|  | 1179 | char buf[100]; | 
|  | 1180 | int res; | 
|  | 1181 |  | 
|  | 1182 | dst = get_param(cmd, "destination"); | 
|  | 1183 | if (dst == NULL || !is_ip_addr(dst)) | 
|  | 1184 | return -1; | 
|  | 1185 |  | 
|  | 1186 | timeout = get_param(cmd, "timeout"); | 
|  | 1187 | if (timeout) { | 
|  | 1188 | wait_time = atoi(timeout); | 
|  | 1189 | if (wait_time < 1) | 
|  | 1190 | wait_time = 1; | 
|  | 1191 | } | 
|  | 1192 |  | 
|  | 1193 | /* TODO: force renewal of IP lease if DHCP is enabled */ | 
|  | 1194 |  | 
|  | 1195 | snprintf(buf, sizeof(buf), "ping %s -c 3 -W %d", dst, wait_time); | 
|  | 1196 | res = system(buf); | 
|  | 1197 | sigma_dut_print(dut, DUT_MSG_DEBUG, "ping returned: %d", res); | 
|  | 1198 | if (res == 0) | 
|  | 1199 | send_resp(dut, conn, SIGMA_COMPLETE, "connected,1"); | 
|  | 1200 | else if (res == 256) | 
|  | 1201 | send_resp(dut, conn, SIGMA_COMPLETE, "connected,0"); | 
|  | 1202 | else | 
|  | 1203 | return -2; | 
|  | 1204 |  | 
|  | 1205 | return 0; | 
|  | 1206 | } | 
|  | 1207 |  | 
|  | 1208 |  | 
|  | 1209 | static int cmd_sta_get_bssid(struct sigma_dut *dut, struct sigma_conn *conn, | 
|  | 1210 | struct sigma_cmd *cmd) | 
|  | 1211 | { | 
|  | 1212 | /* const char *intf = get_param(cmd, "Interface"); */ | 
|  | 1213 | char bssid[20], resp[50]; | 
|  | 1214 |  | 
|  | 1215 | if (get_wpa_status(get_station_ifname(), "bssid", bssid, sizeof(bssid)) | 
|  | 1216 | < 0) | 
| Peng Xu | b8fc5cc | 2017-05-10 17:27:28 -0700 | [diff] [blame] | 1217 | strlcpy(bssid, "00:00:00:00:00:00", sizeof(bssid)); | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1218 |  | 
|  | 1219 | snprintf(resp, sizeof(resp), "bssid,%s", bssid); | 
|  | 1220 | send_resp(dut, conn, SIGMA_COMPLETE, resp); | 
|  | 1221 | return 0; | 
|  | 1222 | } | 
|  | 1223 |  | 
|  | 1224 |  | 
|  | 1225 | #ifdef __SAMSUNG__ | 
|  | 1226 | static int add_use_network(const char *ifname) | 
|  | 1227 | { | 
|  | 1228 | char buf[100]; | 
|  | 1229 |  | 
|  | 1230 | snprintf(buf, sizeof(buf), "USE_NETWORK ON"); | 
|  | 1231 | wpa_command(ifname, buf); | 
|  | 1232 | return 0; | 
|  | 1233 | } | 
|  | 1234 | #endif /* __SAMSUNG__ */ | 
|  | 1235 |  | 
|  | 1236 |  | 
|  | 1237 | static int add_network_common(struct sigma_dut *dut, struct sigma_conn *conn, | 
|  | 1238 | const char *ifname, struct sigma_cmd *cmd) | 
|  | 1239 | { | 
|  | 1240 | const char *ssid = get_param(cmd, "ssid"); | 
|  | 1241 | int id; | 
|  | 1242 | const char *val; | 
|  | 1243 |  | 
|  | 1244 | if (ssid == NULL) | 
|  | 1245 | return -1; | 
|  | 1246 |  | 
|  | 1247 | start_sta_mode(dut); | 
|  | 1248 |  | 
|  | 1249 | #ifdef __SAMSUNG__ | 
|  | 1250 | add_use_network(ifname); | 
|  | 1251 | #endif /* __SAMSUNG__ */ | 
|  | 1252 |  | 
|  | 1253 | id = add_network(ifname); | 
|  | 1254 | if (id < 0) | 
|  | 1255 | return -2; | 
|  | 1256 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding network %d", id); | 
|  | 1257 |  | 
|  | 1258 | if (set_network_quoted(ifname, id, "ssid", ssid) < 0) | 
|  | 1259 | return -2; | 
|  | 1260 |  | 
|  | 1261 | dut->infra_network_id = id; | 
|  | 1262 | snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid); | 
|  | 1263 |  | 
|  | 1264 | val = get_param(cmd, "program"); | 
|  | 1265 | if (!val) | 
|  | 1266 | val = get_param(cmd, "prog"); | 
|  | 1267 | if (val && strcasecmp(val, "hs2") == 0) { | 
|  | 1268 | char buf[100]; | 
|  | 1269 | snprintf(buf, sizeof(buf), "ENABLE_NETWORK %d no-connect", id); | 
|  | 1270 | wpa_command(ifname, buf); | 
|  | 1271 |  | 
|  | 1272 | val = get_param(cmd, "prefer"); | 
|  | 1273 | if (val && atoi(val) > 0) | 
|  | 1274 | set_network(ifname, id, "priority", "1"); | 
|  | 1275 | } | 
|  | 1276 |  | 
|  | 1277 | return id; | 
|  | 1278 | } | 
|  | 1279 |  | 
|  | 1280 |  | 
|  | 1281 | static int cmd_sta_set_encryption(struct sigma_dut *dut, | 
|  | 1282 | struct sigma_conn *conn, | 
|  | 1283 | struct sigma_cmd *cmd) | 
|  | 1284 | { | 
|  | 1285 | const char *intf = get_param(cmd, "Interface"); | 
|  | 1286 | const char *ssid = get_param(cmd, "ssid"); | 
|  | 1287 | const char *type = get_param(cmd, "encpType"); | 
|  | 1288 | const char *ifname; | 
|  | 1289 | char buf[200]; | 
|  | 1290 | int id; | 
|  | 1291 |  | 
|  | 1292 | if (intf == NULL || ssid == NULL) | 
|  | 1293 | return -1; | 
|  | 1294 |  | 
|  | 1295 | if (strcmp(intf, get_main_ifname()) == 0) | 
|  | 1296 | ifname = get_station_ifname(); | 
|  | 1297 | else | 
|  | 1298 | ifname = intf; | 
|  | 1299 |  | 
|  | 1300 | id = add_network_common(dut, conn, ifname, cmd); | 
|  | 1301 | if (id < 0) | 
|  | 1302 | return id; | 
|  | 1303 |  | 
|  | 1304 | if (set_network(ifname, id, "key_mgmt", "NONE") < 0) | 
|  | 1305 | return -2; | 
|  | 1306 |  | 
|  | 1307 | if (type && strcasecmp(type, "wep") == 0) { | 
|  | 1308 | const char *val; | 
|  | 1309 | int i; | 
|  | 1310 |  | 
|  | 1311 | val = get_param(cmd, "activeKey"); | 
|  | 1312 | if (val) { | 
|  | 1313 | int keyid; | 
|  | 1314 | keyid = atoi(val); | 
|  | 1315 | if (keyid < 1 || keyid > 4) | 
|  | 1316 | return -1; | 
|  | 1317 | snprintf(buf, sizeof(buf), "%d", keyid - 1); | 
|  | 1318 | if (set_network(ifname, id, "wep_tx_keyidx", buf) < 0) | 
|  | 1319 | return -2; | 
|  | 1320 | } | 
|  | 1321 |  | 
|  | 1322 | for (i = 0; i < 4; i++) { | 
|  | 1323 | snprintf(buf, sizeof(buf), "key%d", i + 1); | 
|  | 1324 | val = get_param(cmd, buf); | 
|  | 1325 | if (val == NULL) | 
|  | 1326 | continue; | 
|  | 1327 | snprintf(buf, sizeof(buf), "wep_key%d", i); | 
|  | 1328 | if (set_network(ifname, id, buf, val) < 0) | 
|  | 1329 | return -2; | 
|  | 1330 | } | 
|  | 1331 | } | 
|  | 1332 |  | 
|  | 1333 | return 1; | 
|  | 1334 | } | 
|  | 1335 |  | 
|  | 1336 |  | 
|  | 1337 | static int set_wpa_common(struct sigma_dut *dut, struct sigma_conn *conn, | 
|  | 1338 | const char *ifname, struct sigma_cmd *cmd) | 
|  | 1339 | { | 
|  | 1340 | const char *val; | 
|  | 1341 | int id; | 
| Jouni Malinen | ad395a2 | 2017-09-01 21:13:46 +0300 | [diff] [blame] | 1342 | int cipher_set = 0; | 
| Jouni Malinen | 47dcc95 | 2017-10-09 16:43:24 +0300 | [diff] [blame] | 1343 | int owe; | 
| Sunil Dutt | c75a1e6 | 2018-01-11 20:47:50 +0530 | [diff] [blame] | 1344 | int suite_b = 0; | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1345 |  | 
|  | 1346 | id = add_network_common(dut, conn, ifname, cmd); | 
|  | 1347 | if (id < 0) | 
|  | 1348 | return id; | 
|  | 1349 |  | 
| Jouni Malinen | 47dcc95 | 2017-10-09 16:43:24 +0300 | [diff] [blame] | 1350 | val = get_param(cmd, "Type"); | 
|  | 1351 | owe = val && strcasecmp(val, "OWE") == 0; | 
|  | 1352 |  | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1353 | val = get_param(cmd, "keyMgmtType"); | 
| Jouni Malinen | 47dcc95 | 2017-10-09 16:43:24 +0300 | [diff] [blame] | 1354 | if (!val && owe) | 
|  | 1355 | val = "OWE"; | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1356 | if (val == NULL) { | 
|  | 1357 | send_resp(dut, conn, SIGMA_INVALID, "errorCode,Missing keyMgmtType"); | 
|  | 1358 | return 0; | 
|  | 1359 | } | 
|  | 1360 | if (strcasecmp(val, "wpa") == 0 || | 
|  | 1361 | strcasecmp(val, "wpa-psk") == 0) { | 
|  | 1362 | if (set_network(ifname, id, "proto", "WPA") < 0) | 
|  | 1363 | return -2; | 
|  | 1364 | } else if (strcasecmp(val, "wpa2") == 0 || | 
|  | 1365 | strcasecmp(val, "wpa2-psk") == 0 || | 
|  | 1366 | strcasecmp(val, "wpa2-ft") == 0 || | 
|  | 1367 | strcasecmp(val, "wpa2-sha256") == 0) { | 
|  | 1368 | if (set_network(ifname, id, "proto", "WPA2") < 0) | 
|  | 1369 | return -2; | 
| Pradeep Reddy POTTETI | 6d04b3b | 2016-11-15 14:51:26 +0530 | [diff] [blame] | 1370 | } else if (strcasecmp(val, "wpa2-wpa-psk") == 0 || | 
|  | 1371 | strcasecmp(val, "wpa2-wpa-ent") == 0) { | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1372 | if (set_network(ifname, id, "proto", "WPA WPA2") < 0) | 
|  | 1373 | return -2; | 
| Jouni Malinen | ad395a2 | 2017-09-01 21:13:46 +0300 | [diff] [blame] | 1374 | } else if (strcasecmp(val, "SuiteB") == 0) { | 
| Sunil Dutt | c75a1e6 | 2018-01-11 20:47:50 +0530 | [diff] [blame] | 1375 | suite_b = 1; | 
| Jouni Malinen | ad395a2 | 2017-09-01 21:13:46 +0300 | [diff] [blame] | 1376 | if (set_network(ifname, id, "proto", "WPA2") < 0) | 
|  | 1377 | return -2; | 
| Jouni Malinen | 47dcc95 | 2017-10-09 16:43:24 +0300 | [diff] [blame] | 1378 | } else if (strcasecmp(val, "OWE") == 0) { | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1379 | } else { | 
|  | 1380 | send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized keyMgmtType value"); | 
|  | 1381 | return 0; | 
|  | 1382 | } | 
|  | 1383 |  | 
|  | 1384 | val = get_param(cmd, "encpType"); | 
| Jouni Malinen | ad395a2 | 2017-09-01 21:13:46 +0300 | [diff] [blame] | 1385 | if (val) { | 
|  | 1386 | cipher_set = 1; | 
|  | 1387 | if (strcasecmp(val, "tkip") == 0) { | 
|  | 1388 | if (set_network(ifname, id, "pairwise", "TKIP") < 0) | 
|  | 1389 | return -2; | 
|  | 1390 | } else if (strcasecmp(val, "aes-ccmp") == 0) { | 
|  | 1391 | if (set_network(ifname, id, "pairwise", "CCMP") < 0) | 
|  | 1392 | return -2; | 
|  | 1393 | } else if (strcasecmp(val, "aes-ccmp-tkip") == 0) { | 
|  | 1394 | if (set_network(ifname, id, "pairwise", | 
|  | 1395 | "CCMP TKIP") < 0) | 
|  | 1396 | return -2; | 
|  | 1397 | } else if (strcasecmp(val, "aes-gcmp") == 0) { | 
|  | 1398 | if (set_network(ifname, id, "pairwise", "GCMP") < 0) | 
|  | 1399 | return -2; | 
|  | 1400 | if (set_network(ifname, id, "group", "GCMP") < 0) | 
|  | 1401 | return -2; | 
|  | 1402 | } else { | 
|  | 1403 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 1404 | "errorCode,Unrecognized encpType value"); | 
|  | 1405 | return 0; | 
|  | 1406 | } | 
|  | 1407 | } | 
|  | 1408 |  | 
|  | 1409 | val = get_param(cmd, "PairwiseCipher"); | 
|  | 1410 | if (val) { | 
|  | 1411 | cipher_set = 1; | 
|  | 1412 | /* TODO: Support space separated list */ | 
|  | 1413 | if (strcasecmp(val, "AES-GCMP-256") == 0) { | 
|  | 1414 | if (set_network(ifname, id, "pairwise", "GCMP-256") < 0) | 
|  | 1415 | return -2; | 
|  | 1416 | } else if (strcasecmp(val, "AES-CCMP-256") == 0) { | 
|  | 1417 | if (set_network(ifname, id, "pairwise", | 
|  | 1418 | "CCMP-256") < 0) | 
|  | 1419 | return -2; | 
|  | 1420 | } else if (strcasecmp(val, "AES-GCMP-128") == 0) { | 
|  | 1421 | if (set_network(ifname, id, "pairwise",	"GCMP") < 0) | 
|  | 1422 | return -2; | 
|  | 1423 | } else if (strcasecmp(val, "AES-CCMP-128") == 0) { | 
|  | 1424 | if (set_network(ifname, id, "pairwise",	"CCMP") < 0) | 
|  | 1425 | return -2; | 
|  | 1426 | } else { | 
|  | 1427 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 1428 | "errorCode,Unrecognized PairwiseCipher value"); | 
|  | 1429 | return 0; | 
|  | 1430 | } | 
|  | 1431 | } | 
|  | 1432 |  | 
| Jouni Malinen | 47dcc95 | 2017-10-09 16:43:24 +0300 | [diff] [blame] | 1433 | if (!cipher_set && !owe) { | 
| Jouni Malinen | ad395a2 | 2017-09-01 21:13:46 +0300 | [diff] [blame] | 1434 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 1435 | "errorCode,Missing encpType and PairwiseCipher"); | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1436 | return 0; | 
|  | 1437 | } | 
| Jouni Malinen | ad395a2 | 2017-09-01 21:13:46 +0300 | [diff] [blame] | 1438 |  | 
|  | 1439 | val = get_param(cmd, "GroupCipher"); | 
|  | 1440 | if (val) { | 
|  | 1441 | if (strcasecmp(val, "AES-GCMP-256") == 0) { | 
|  | 1442 | if (set_network(ifname, id, "group", "GCMP-256") < 0) | 
|  | 1443 | return -2; | 
|  | 1444 | } else if (strcasecmp(val, "AES-CCMP-256") == 0) { | 
|  | 1445 | if (set_network(ifname, id, "group", "CCMP-256") < 0) | 
|  | 1446 | return -2; | 
|  | 1447 | } else if (strcasecmp(val, "AES-GCMP-128") == 0) { | 
|  | 1448 | if (set_network(ifname, id, "group", "GCMP") < 0) | 
|  | 1449 | return -2; | 
|  | 1450 | } else if (strcasecmp(val, "AES-CCMP-128") == 0) { | 
|  | 1451 | if (set_network(ifname, id, "group", "CCMP") < 0) | 
|  | 1452 | return -2; | 
|  | 1453 | } else { | 
|  | 1454 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 1455 | "errorCode,Unrecognized GroupCipher value"); | 
|  | 1456 | return 0; | 
|  | 1457 | } | 
|  | 1458 | } | 
|  | 1459 |  | 
| Jouni Malinen | 7b23952 | 2017-09-14 21:37:18 +0300 | [diff] [blame] | 1460 | val = get_param(cmd, "GroupMgntCipher"); | 
| Jouni Malinen | ad395a2 | 2017-09-01 21:13:46 +0300 | [diff] [blame] | 1461 | if (val) { | 
| Jouni Malinen | e8898cb | 2017-09-26 17:55:26 +0300 | [diff] [blame] | 1462 | const char *cipher; | 
|  | 1463 |  | 
|  | 1464 | if (strcasecmp(val, "BIP-GMAC-256") == 0) { | 
|  | 1465 | cipher = "BIP-GMAC-256"; | 
|  | 1466 | } else if (strcasecmp(val, "BIP-CMAC-256") == 0) { | 
|  | 1467 | cipher = "BIP-CMAC-256"; | 
|  | 1468 | } else if (strcasecmp(val, "BIP-GMAC-128") == 0) { | 
|  | 1469 | cipher = "BIP-GMAC-128"; | 
|  | 1470 | } else if (strcasecmp(val, "BIP-CMAC-128") == 0) { | 
|  | 1471 | cipher = "AES-128-CMAC"; | 
|  | 1472 | } else { | 
|  | 1473 | send_resp(dut, conn, SIGMA_INVALID, | 
|  | 1474 | "errorCode,Unsupported GroupMgntCipher"); | 
|  | 1475 | return 0; | 
|  | 1476 | } | 
|  | 1477 | if (set_network(ifname, id, "group_mgmt", cipher) < 0) { | 
|  | 1478 | send_resp(dut, conn, SIGMA_INVALID, | 
|  | 1479 | "errorCode,Failed to set GroupMgntCipher"); | 
|  | 1480 | return 0; | 
|  | 1481 | } | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1482 | } | 
|  | 1483 |  | 
|  | 1484 | dut->sta_pmf = STA_PMF_DISABLED; | 
| vamsi krishna | f39bc1e | 2017-08-23 17:37:53 +0530 | [diff] [blame] | 1485 |  | 
|  | 1486 | if (dut->program == PROGRAM_OCE) { | 
|  | 1487 | dut->sta_pmf = STA_PMF_OPTIONAL; | 
|  | 1488 | if (set_network(ifname, id, "ieee80211w", "1") < 0) | 
|  | 1489 | return -2; | 
|  | 1490 | } | 
|  | 1491 |  | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1492 | val = get_param(cmd, "PMF"); | 
|  | 1493 | if (val) { | 
|  | 1494 | if (strcasecmp(val, "Required") == 0 || | 
|  | 1495 | strcasecmp(val, "Forced_Required") == 0) { | 
|  | 1496 | dut->sta_pmf = STA_PMF_REQUIRED; | 
|  | 1497 | if (set_network(ifname, id, "ieee80211w", "2") < 0) | 
|  | 1498 | return -2; | 
|  | 1499 | } else if (strcasecmp(val, "Optional") == 0) { | 
|  | 1500 | dut->sta_pmf = STA_PMF_OPTIONAL; | 
|  | 1501 | if (set_network(ifname, id, "ieee80211w", "1") < 0) | 
|  | 1502 | return -2; | 
|  | 1503 | } else if (strcasecmp(val, "Disabled") == 0 || | 
|  | 1504 | strcasecmp(val, "Forced_Disabled") == 0) { | 
|  | 1505 | dut->sta_pmf = STA_PMF_DISABLED; | 
|  | 1506 | } else { | 
|  | 1507 | send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized PMF value"); | 
|  | 1508 | return 0; | 
|  | 1509 | } | 
| Sunil Dutt | c75a1e6 | 2018-01-11 20:47:50 +0530 | [diff] [blame] | 1510 | } else if (owe || suite_b) { | 
| Jouni Malinen | 1287cd7 | 2018-01-04 17:08:01 +0200 | [diff] [blame] | 1511 | dut->sta_pmf = STA_PMF_REQUIRED; | 
|  | 1512 | if (set_network(ifname, id, "ieee80211w", "2") < 0) | 
|  | 1513 | return -2; | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1514 | } | 
|  | 1515 |  | 
|  | 1516 | return id; | 
|  | 1517 | } | 
|  | 1518 |  | 
|  | 1519 |  | 
|  | 1520 | static int cmd_sta_set_psk(struct sigma_dut *dut, struct sigma_conn *conn, | 
|  | 1521 | struct sigma_cmd *cmd) | 
|  | 1522 | { | 
|  | 1523 | const char *intf = get_param(cmd, "Interface"); | 
| Jouni Malinen | 992a81e | 2017-08-22 13:57:47 +0300 | [diff] [blame] | 1524 | const char *type = get_param(cmd, "Type"); | 
| Jouni Malinen | 1287cd7 | 2018-01-04 17:08:01 +0200 | [diff] [blame] | 1525 | const char *pmf = get_param(cmd, "PMF"); | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1526 | const char *ifname, *val, *alg; | 
|  | 1527 | int id; | 
|  | 1528 |  | 
|  | 1529 | if (intf == NULL) | 
|  | 1530 | return -1; | 
|  | 1531 |  | 
|  | 1532 | if (strcmp(intf, get_main_ifname()) == 0) | 
|  | 1533 | ifname = get_station_ifname(); | 
|  | 1534 | else | 
|  | 1535 | ifname = intf; | 
|  | 1536 |  | 
|  | 1537 | id = set_wpa_common(dut, conn, ifname, cmd); | 
|  | 1538 | if (id < 0) | 
|  | 1539 | return id; | 
|  | 1540 |  | 
|  | 1541 | val = get_param(cmd, "keyMgmtType"); | 
|  | 1542 | alg = get_param(cmd, "micAlg"); | 
|  | 1543 |  | 
| Jouni Malinen | 992a81e | 2017-08-22 13:57:47 +0300 | [diff] [blame] | 1544 | if (type && strcasecmp(type, "SAE") == 0) { | 
|  | 1545 | if (val && strcasecmp(val, "wpa2-ft") == 0) { | 
|  | 1546 | if (set_network(ifname, id, "key_mgmt", "FT-SAE") < 0) | 
|  | 1547 | return -2; | 
|  | 1548 | } else { | 
|  | 1549 | if (set_network(ifname, id, "key_mgmt", "SAE") < 0) | 
|  | 1550 | return -2; | 
|  | 1551 | } | 
|  | 1552 | if (wpa_command(ifname, "SET sae_groups ") != 0) { | 
|  | 1553 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 1554 | "Failed to clear sae_groups to default"); | 
|  | 1555 | return -2; | 
|  | 1556 | } | 
| Jouni Malinen | 1287cd7 | 2018-01-04 17:08:01 +0200 | [diff] [blame] | 1557 | if (!pmf) { | 
|  | 1558 | dut->sta_pmf = STA_PMF_REQUIRED; | 
|  | 1559 | if (set_network(ifname, id, "ieee80211w", "2") < 0) | 
|  | 1560 | return -2; | 
|  | 1561 | } | 
| Jouni Malinen | 0ab50f4 | 2017-08-31 01:34:59 +0300 | [diff] [blame] | 1562 | } else if (type && strcasecmp(type, "PSK-SAE") == 0) { | 
|  | 1563 | if (val && strcasecmp(val, "wpa2-ft") == 0) { | 
|  | 1564 | if (set_network(ifname, id, "key_mgmt", | 
|  | 1565 | "FT-SAE FT-PSK") < 0) | 
|  | 1566 | return -2; | 
|  | 1567 | } else { | 
|  | 1568 | if (set_network(ifname, id, "key_mgmt", | 
|  | 1569 | "SAE WPA-PSK") < 0) | 
|  | 1570 | return -2; | 
|  | 1571 | } | 
|  | 1572 | if (wpa_command(ifname, "SET sae_groups ") != 0) { | 
|  | 1573 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 1574 | "Failed to clear sae_groups to default"); | 
|  | 1575 | return -2; | 
|  | 1576 | } | 
| Jouni Malinen | 1287cd7 | 2018-01-04 17:08:01 +0200 | [diff] [blame] | 1577 | if (!pmf) { | 
|  | 1578 | dut->sta_pmf = STA_PMF_OPTIONAL; | 
|  | 1579 | if (set_network(ifname, id, "ieee80211w", "1") < 0) | 
|  | 1580 | return -2; | 
|  | 1581 | } | 
| Jouni Malinen | 992a81e | 2017-08-22 13:57:47 +0300 | [diff] [blame] | 1582 | } else if (alg && strcasecmp(alg, "SHA-256") == 0) { | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1583 | if (set_network(ifname, id, "key_mgmt", "WPA-PSK-SHA256") < 0) | 
|  | 1584 | return -2; | 
|  | 1585 | } else if (alg && strcasecmp(alg, "SHA-1") == 0) { | 
|  | 1586 | if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0) | 
|  | 1587 | return -2; | 
| Ashwini Patil | 6dbf7b0 | 2017-03-20 13:42:11 +0530 | [diff] [blame] | 1588 | } else if (val && strcasecmp(val, "wpa2-ft") == 0) { | 
|  | 1589 | if (set_network(ifname, id, "key_mgmt", "FT-PSK") < 0) | 
|  | 1590 | return -2; | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1591 | } else if ((val && strcasecmp(val, "wpa2-sha256") == 0) || | 
|  | 1592 | dut->sta_pmf == STA_PMF_REQUIRED) { | 
|  | 1593 | if (set_network(ifname, id, "key_mgmt", | 
|  | 1594 | "WPA-PSK WPA-PSK-SHA256") < 0) | 
|  | 1595 | return -2; | 
|  | 1596 | } else if (dut->sta_pmf == STA_PMF_OPTIONAL) { | 
|  | 1597 | if (set_network(ifname, id, "key_mgmt", | 
|  | 1598 | "WPA-PSK WPA-PSK-SHA256") < 0) | 
|  | 1599 | return -2; | 
|  | 1600 | } else { | 
|  | 1601 | if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0) | 
|  | 1602 | return -2; | 
|  | 1603 | } | 
|  | 1604 |  | 
|  | 1605 | val = get_param(cmd, "passPhrase"); | 
|  | 1606 | if (val == NULL) | 
|  | 1607 | return -1; | 
| Jouni Malinen | 2126f42 | 2017-10-11 23:24:33 +0300 | [diff] [blame] | 1608 | if (type && strcasecmp(type, "SAE") == 0) { | 
|  | 1609 | if (set_network_quoted(ifname, id, "sae_password", val) < 0) | 
|  | 1610 | return -2; | 
|  | 1611 | } else { | 
|  | 1612 | if (set_network_quoted(ifname, id, "psk", val) < 0) | 
|  | 1613 | return -2; | 
|  | 1614 | } | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1615 |  | 
| Jouni Malinen | 992a81e | 2017-08-22 13:57:47 +0300 | [diff] [blame] | 1616 | val = get_param(cmd, "ECGroupID"); | 
|  | 1617 | if (val) { | 
|  | 1618 | char buf[50]; | 
|  | 1619 |  | 
|  | 1620 | snprintf(buf, sizeof(buf), "SET sae_groups %u", atoi(val)); | 
|  | 1621 | if (wpa_command(ifname, buf) != 0) { | 
|  | 1622 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 1623 | "Failed to clear sae_groups"); | 
|  | 1624 | return -2; | 
|  | 1625 | } | 
|  | 1626 | } | 
|  | 1627 |  | 
| Jouni Malinen | 6814313 | 2017-09-02 02:34:08 +0300 | [diff] [blame] | 1628 | val = get_param(cmd, "InvalidSAEElement"); | 
|  | 1629 | if (val) { | 
|  | 1630 | free(dut->sae_commit_override); | 
|  | 1631 | dut->sae_commit_override = strdup(val); | 
|  | 1632 | } | 
|  | 1633 |  | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1634 | return 1; | 
|  | 1635 | } | 
|  | 1636 |  | 
|  | 1637 |  | 
|  | 1638 | 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] | 1639 | const char *ifname, int username_identity, | 
|  | 1640 | struct sigma_cmd *cmd) | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1641 | { | 
| vamsi krishna | f39bc1e | 2017-08-23 17:37:53 +0530 | [diff] [blame] | 1642 | const char *val, *alg, *akm; | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1643 | int id; | 
|  | 1644 | char buf[200]; | 
|  | 1645 | #ifdef ANDROID | 
|  | 1646 | unsigned char kvalue[KEYSTORE_MESSAGE_SIZE]; | 
|  | 1647 | int length; | 
|  | 1648 | #endif /* ANDROID */ | 
|  | 1649 |  | 
|  | 1650 | id = set_wpa_common(dut, conn, ifname, cmd); | 
|  | 1651 | if (id < 0) | 
|  | 1652 | return id; | 
|  | 1653 |  | 
|  | 1654 | val = get_param(cmd, "keyMgmtType"); | 
|  | 1655 | alg = get_param(cmd, "micAlg"); | 
| vamsi krishna | f39bc1e | 2017-08-23 17:37:53 +0530 | [diff] [blame] | 1656 | akm = get_param(cmd, "AKMSuiteType"); | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1657 |  | 
| Jouni Malinen | ad395a2 | 2017-09-01 21:13:46 +0300 | [diff] [blame] | 1658 | if (val && strcasecmp(val, "SuiteB") == 0) { | 
|  | 1659 | if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SUITE-B-192") < | 
|  | 1660 | 0) | 
|  | 1661 | return -2; | 
|  | 1662 | } else if (alg && strcasecmp(alg, "SHA-256") == 0) { | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1663 | if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SHA256") < 0) | 
|  | 1664 | return -2; | 
|  | 1665 | } else if (alg && strcasecmp(alg, "SHA-1") == 0) { | 
|  | 1666 | if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0) | 
|  | 1667 | return -2; | 
|  | 1668 | } else if (val && strcasecmp(val, "wpa2-ft") == 0) { | 
|  | 1669 | if (set_network(ifname, id, "key_mgmt", "FT-EAP") < 0) | 
|  | 1670 | return -2; | 
|  | 1671 | } else if ((val && strcasecmp(val, "wpa2-sha256") == 0) || | 
|  | 1672 | dut->sta_pmf == STA_PMF_REQUIRED) { | 
|  | 1673 | if (set_network(ifname, id, "key_mgmt", | 
|  | 1674 | "WPA-EAP WPA-EAP-SHA256") < 0) | 
|  | 1675 | return -2; | 
| vamsi krishna | f39bc1e | 2017-08-23 17:37:53 +0530 | [diff] [blame] | 1676 | } else if (akm && atoi(akm) == 14) { | 
|  | 1677 | if (dut->sta_pmf == STA_PMF_OPTIONAL || | 
|  | 1678 | dut->sta_pmf == STA_PMF_REQUIRED) { | 
|  | 1679 | if (set_network(ifname, id, "key_mgmt", | 
|  | 1680 | "WPA-EAP-SHA256 FILS-SHA256") < 0) | 
|  | 1681 | return -2; | 
|  | 1682 | } else { | 
|  | 1683 | if (set_network(ifname, id, "key_mgmt", | 
|  | 1684 | "WPA-EAP FILS-SHA256") < 0) | 
|  | 1685 | return -2; | 
|  | 1686 | } | 
|  | 1687 |  | 
|  | 1688 | if (set_network(ifname, id, "erp", "1") < 0) | 
|  | 1689 | return -2; | 
|  | 1690 | } else if (akm && atoi(akm) == 15) { | 
|  | 1691 | if (dut->sta_pmf == STA_PMF_OPTIONAL || | 
|  | 1692 | dut->sta_pmf == STA_PMF_REQUIRED) { | 
|  | 1693 | if (set_network(ifname, id, "key_mgmt", | 
|  | 1694 | "WPA-EAP-SHA256 FILS-SHA384") < 0) | 
|  | 1695 | return -2; | 
|  | 1696 | } else { | 
|  | 1697 | if (set_network(ifname, id, "key_mgmt", | 
|  | 1698 | "WPA-EAP FILS-SHA384") < 0) | 
|  | 1699 | return -2; | 
|  | 1700 | } | 
|  | 1701 |  | 
|  | 1702 | if (set_network(ifname, id, "erp", "1") < 0) | 
|  | 1703 | return -2; | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1704 | } else if (dut->sta_pmf == STA_PMF_OPTIONAL) { | 
|  | 1705 | if (set_network(ifname, id, "key_mgmt", | 
|  | 1706 | "WPA-EAP WPA-EAP-SHA256") < 0) | 
|  | 1707 | return -2; | 
|  | 1708 | } else { | 
|  | 1709 | if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0) | 
|  | 1710 | return -2; | 
|  | 1711 | } | 
|  | 1712 |  | 
|  | 1713 | val = get_param(cmd, "trustedRootCA"); | 
|  | 1714 | if (val) { | 
|  | 1715 | #ifdef ANDROID | 
|  | 1716 | snprintf(buf, sizeof(buf), "CACERT_%s", val); | 
|  | 1717 | length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, | 
|  | 1718 | kvalue); | 
|  | 1719 | if (length > 0) { | 
|  | 1720 | sigma_dut_print(dut, DUT_MSG_INFO, | 
|  | 1721 | "Use Android keystore [%s]", buf); | 
|  | 1722 | snprintf(buf, sizeof(buf), "keystore://CACERT_%s", | 
|  | 1723 | val); | 
|  | 1724 | goto ca_cert_selected; | 
|  | 1725 | } | 
|  | 1726 | #endif /* ANDROID */ | 
|  | 1727 |  | 
|  | 1728 | snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val); | 
|  | 1729 | #ifdef __linux__ | 
|  | 1730 | if (!file_exists(buf)) { | 
|  | 1731 | char msg[300]; | 
|  | 1732 | snprintf(msg, sizeof(msg), "ErrorCode,trustedRootCA " | 
|  | 1733 | "file (%s) not found", buf); | 
|  | 1734 | send_resp(dut, conn, SIGMA_ERROR, msg); | 
|  | 1735 | return -3; | 
|  | 1736 | } | 
|  | 1737 | #endif /* __linux__ */ | 
|  | 1738 | #ifdef ANDROID | 
|  | 1739 | ca_cert_selected: | 
|  | 1740 | #endif /* ANDROID */ | 
|  | 1741 | if (set_network_quoted(ifname, id, "ca_cert", buf) < 0) | 
|  | 1742 | return -2; | 
|  | 1743 | } | 
|  | 1744 |  | 
| Bala Krishna Bhamidipati | 73d7af0 | 2016-03-24 12:27:56 +0530 | [diff] [blame] | 1745 | if (username_identity) { | 
|  | 1746 | val = get_param(cmd, "username"); | 
|  | 1747 | if (val) { | 
|  | 1748 | if (set_network_quoted(ifname, id, "identity", val) < 0) | 
|  | 1749 | return -2; | 
|  | 1750 | } | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1751 |  | 
| Bala Krishna Bhamidipati | 73d7af0 | 2016-03-24 12:27:56 +0530 | [diff] [blame] | 1752 | val = get_param(cmd, "password"); | 
|  | 1753 | if (val) { | 
|  | 1754 | if (set_network_quoted(ifname, id, "password", val) < 0) | 
|  | 1755 | return -2; | 
|  | 1756 | } | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1757 | } | 
|  | 1758 |  | 
|  | 1759 | return id; | 
|  | 1760 | } | 
|  | 1761 |  | 
|  | 1762 |  | 
| Jouni Malinen | 5eabb2a | 2017-10-03 18:17:30 +0300 | [diff] [blame] | 1763 | static int set_tls_cipher(const char *ifname, int id, const char *cipher) | 
|  | 1764 | { | 
|  | 1765 | const char *val; | 
|  | 1766 |  | 
|  | 1767 | if (!cipher) | 
|  | 1768 | return 0; | 
|  | 1769 |  | 
|  | 1770 | if (strcasecmp(cipher, "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384") == 0) | 
|  | 1771 | val = "ECDHE-ECDSA-AES256-GCM-SHA384"; | 
|  | 1772 | else if (strcasecmp(cipher, | 
|  | 1773 | "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384") == 0) | 
|  | 1774 | val = "ECDHE-RSA-AES256-GCM-SHA384"; | 
|  | 1775 | else if (strcasecmp(cipher, "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384") == 0) | 
|  | 1776 | val = "DHE-RSA-AES256-GCM-SHA384"; | 
|  | 1777 | else if (strcasecmp(cipher, | 
|  | 1778 | "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256") == 0) | 
|  | 1779 | val = "ECDHE-ECDSA-AES128-GCM-SHA256"; | 
|  | 1780 | else | 
|  | 1781 | return -1; | 
|  | 1782 |  | 
|  | 1783 | /* Need to clear phase1="tls_suiteb=1" to allow cipher enforcement */ | 
|  | 1784 | set_network_quoted(ifname, id, "phase1", ""); | 
|  | 1785 |  | 
|  | 1786 | return set_network_quoted(ifname, id, "openssl_ciphers", val); | 
|  | 1787 | } | 
|  | 1788 |  | 
|  | 1789 |  | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1790 | static int cmd_sta_set_eaptls(struct sigma_dut *dut, struct sigma_conn *conn, | 
|  | 1791 | struct sigma_cmd *cmd) | 
|  | 1792 | { | 
|  | 1793 | const char *intf = get_param(cmd, "Interface"); | 
|  | 1794 | const char *ifname, *val; | 
|  | 1795 | int id; | 
|  | 1796 | char buf[200]; | 
|  | 1797 | #ifdef ANDROID | 
|  | 1798 | unsigned char kvalue[KEYSTORE_MESSAGE_SIZE]; | 
|  | 1799 | int length; | 
|  | 1800 | int jb_or_newer = 0; | 
|  | 1801 | char prop[PROPERTY_VALUE_MAX]; | 
|  | 1802 | #endif /* ANDROID */ | 
|  | 1803 |  | 
|  | 1804 | if (intf == NULL) | 
|  | 1805 | return -1; | 
|  | 1806 |  | 
|  | 1807 | if (strcmp(intf, get_main_ifname()) == 0) | 
|  | 1808 | ifname = get_station_ifname(); | 
|  | 1809 | else | 
|  | 1810 | ifname = intf; | 
|  | 1811 |  | 
| Bala Krishna Bhamidipati | 73d7af0 | 2016-03-24 12:27:56 +0530 | [diff] [blame] | 1812 | id = set_eap_common(dut, conn, ifname, 1, cmd); | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1813 | if (id < 0) | 
|  | 1814 | return id; | 
|  | 1815 |  | 
|  | 1816 | if (set_network(ifname, id, "eap", "TLS") < 0) | 
|  | 1817 | return -2; | 
|  | 1818 |  | 
| Pradeep Reddy POTTETI | 9f6c213 | 2016-05-05 16:28:19 +0530 | [diff] [blame] | 1819 | if (!get_param(cmd, "username") && | 
|  | 1820 | set_network_quoted(ifname, id, "identity", | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1821 | "wifi-user@wifilabs.local") < 0) | 
|  | 1822 | return -2; | 
|  | 1823 |  | 
|  | 1824 | val = get_param(cmd, "clientCertificate"); | 
|  | 1825 | if (val == NULL) | 
|  | 1826 | return -1; | 
|  | 1827 | #ifdef ANDROID | 
|  | 1828 | snprintf(buf, sizeof(buf), "USRPKEY_%s", val); | 
|  | 1829 | length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue); | 
|  | 1830 | if (length < 0) { | 
|  | 1831 | /* | 
|  | 1832 | * JB started reporting keystore type mismatches, so retry with | 
|  | 1833 | * the GET_PUBKEY command if the generic GET fails. | 
|  | 1834 | */ | 
|  | 1835 | length = android_keystore_get(ANDROID_KEYSTORE_GET_PUBKEY, | 
|  | 1836 | buf, kvalue); | 
|  | 1837 | } | 
|  | 1838 |  | 
|  | 1839 | if (property_get("ro.build.version.release", prop, NULL) != 0) { | 
|  | 1840 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Android release %s", prop); | 
|  | 1841 | if (strncmp(prop, "4.0", 3) != 0) | 
|  | 1842 | jb_or_newer = 1; | 
|  | 1843 | } else | 
|  | 1844 | jb_or_newer = 1; /* assume newer */ | 
|  | 1845 |  | 
|  | 1846 | if (jb_or_newer && length > 0) { | 
|  | 1847 | sigma_dut_print(dut, DUT_MSG_INFO, | 
|  | 1848 | "Use Android keystore [%s]", buf); | 
|  | 1849 | if (set_network(ifname, id, "engine", "1") < 0) | 
|  | 1850 | return -2; | 
|  | 1851 | if (set_network_quoted(ifname, id, "engine_id", "keystore") < 0) | 
|  | 1852 | return -2; | 
|  | 1853 | snprintf(buf, sizeof(buf), "USRPKEY_%s", val); | 
|  | 1854 | if (set_network_quoted(ifname, id, "key_id", buf) < 0) | 
|  | 1855 | return -2; | 
|  | 1856 | snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val); | 
|  | 1857 | if (set_network_quoted(ifname, id, "client_cert", buf) < 0) | 
|  | 1858 | return -2; | 
|  | 1859 | return 1; | 
|  | 1860 | } else if (length > 0) { | 
|  | 1861 | sigma_dut_print(dut, DUT_MSG_INFO, | 
|  | 1862 | "Use Android keystore [%s]", buf); | 
|  | 1863 | snprintf(buf, sizeof(buf), "keystore://USRPKEY_%s", val); | 
|  | 1864 | if (set_network_quoted(ifname, id, "private_key", buf) < 0) | 
|  | 1865 | return -2; | 
|  | 1866 | snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val); | 
|  | 1867 | if (set_network_quoted(ifname, id, "client_cert", buf) < 0) | 
|  | 1868 | return -2; | 
|  | 1869 | return 1; | 
|  | 1870 | } | 
|  | 1871 | #endif /* ANDROID */ | 
|  | 1872 |  | 
|  | 1873 | snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val); | 
|  | 1874 | #ifdef __linux__ | 
|  | 1875 | if (!file_exists(buf)) { | 
|  | 1876 | char msg[300]; | 
|  | 1877 | snprintf(msg, sizeof(msg), "ErrorCode,clientCertificate file " | 
|  | 1878 | "(%s) not found", buf); | 
|  | 1879 | send_resp(dut, conn, SIGMA_ERROR, msg); | 
|  | 1880 | return -3; | 
|  | 1881 | } | 
|  | 1882 | #endif /* __linux__ */ | 
|  | 1883 | if (set_network_quoted(ifname, id, "private_key", buf) < 0) | 
|  | 1884 | return -2; | 
|  | 1885 | if (set_network_quoted(ifname, id, "client_cert", buf) < 0) | 
|  | 1886 | return -2; | 
|  | 1887 |  | 
|  | 1888 | if (set_network_quoted(ifname, id, "private_key_passwd", "wifi") < 0) | 
|  | 1889 | return -2; | 
|  | 1890 |  | 
| Jouni Malinen | 5eabb2a | 2017-10-03 18:17:30 +0300 | [diff] [blame] | 1891 | val = get_param(cmd, "keyMgmtType"); | 
|  | 1892 | if (val && strcasecmp(val, "SuiteB") == 0) { | 
|  | 1893 | val = get_param(cmd, "CertType"); | 
|  | 1894 | if (val && strcasecmp(val, "RSA") == 0) { | 
|  | 1895 | if (set_network_quoted(ifname, id, "phase1", | 
|  | 1896 | "tls_suiteb=1") < 0) | 
|  | 1897 | return -2; | 
|  | 1898 | } else { | 
|  | 1899 | if (set_network_quoted(ifname, id, "openssl_ciphers", | 
|  | 1900 | "SUITEB192") < 0) | 
|  | 1901 | return -2; | 
|  | 1902 | } | 
|  | 1903 |  | 
|  | 1904 | val = get_param(cmd, "TLSCipher"); | 
|  | 1905 | if (set_tls_cipher(ifname, id, val) < 0) { | 
|  | 1906 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 1907 | "ErrorCode,Unsupported TLSCipher value"); | 
|  | 1908 | return -3; | 
|  | 1909 | } | 
|  | 1910 | } | 
|  | 1911 |  | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1912 | return 1; | 
|  | 1913 | } | 
|  | 1914 |  | 
|  | 1915 |  | 
|  | 1916 | static int cmd_sta_set_eapttls(struct sigma_dut *dut, struct sigma_conn *conn, | 
|  | 1917 | struct sigma_cmd *cmd) | 
|  | 1918 | { | 
|  | 1919 | const char *intf = get_param(cmd, "Interface"); | 
|  | 1920 | const char *ifname; | 
|  | 1921 | int id; | 
|  | 1922 |  | 
|  | 1923 | if (intf == NULL) | 
|  | 1924 | return -1; | 
|  | 1925 |  | 
|  | 1926 | if (strcmp(intf, get_main_ifname()) == 0) | 
|  | 1927 | ifname = get_station_ifname(); | 
|  | 1928 | else | 
|  | 1929 | ifname = intf; | 
|  | 1930 |  | 
| Bala Krishna Bhamidipati | 73d7af0 | 2016-03-24 12:27:56 +0530 | [diff] [blame] | 1931 | id = set_eap_common(dut, conn, ifname, 1, cmd); | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1932 | if (id < 0) | 
|  | 1933 | return id; | 
|  | 1934 |  | 
|  | 1935 | if (set_network(ifname, id, "eap", "TTLS") < 0) { | 
|  | 1936 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 1937 | "errorCode,Failed to set TTLS method"); | 
|  | 1938 | return 0; | 
|  | 1939 | } | 
|  | 1940 |  | 
|  | 1941 | if (set_network_quoted(ifname, id, "phase2", "auth=MSCHAPV2") < 0) { | 
|  | 1942 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 1943 | "errorCode,Failed to set MSCHAPv2 for TTLS Phase 2"); | 
|  | 1944 | return 0; | 
|  | 1945 | } | 
|  | 1946 |  | 
|  | 1947 | return 1; | 
|  | 1948 | } | 
|  | 1949 |  | 
|  | 1950 |  | 
|  | 1951 | static int cmd_sta_set_eapsim(struct sigma_dut *dut, struct sigma_conn *conn, | 
|  | 1952 | struct sigma_cmd *cmd) | 
|  | 1953 | { | 
|  | 1954 | const char *intf = get_param(cmd, "Interface"); | 
|  | 1955 | const char *ifname; | 
|  | 1956 | int id; | 
|  | 1957 |  | 
|  | 1958 | if (intf == NULL) | 
|  | 1959 | return -1; | 
|  | 1960 |  | 
|  | 1961 | if (strcmp(intf, get_main_ifname()) == 0) | 
|  | 1962 | ifname = get_station_ifname(); | 
|  | 1963 | else | 
|  | 1964 | ifname = intf; | 
|  | 1965 |  | 
| Bala Krishna Bhamidipati | 73d7af0 | 2016-03-24 12:27:56 +0530 | [diff] [blame] | 1966 | id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd); | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1967 | if (id < 0) | 
|  | 1968 | return id; | 
|  | 1969 |  | 
|  | 1970 | if (set_network(ifname, id, "eap", "SIM") < 0) | 
|  | 1971 | return -2; | 
|  | 1972 |  | 
|  | 1973 | return 1; | 
|  | 1974 | } | 
|  | 1975 |  | 
|  | 1976 |  | 
|  | 1977 | static int cmd_sta_set_peap(struct sigma_dut *dut, struct sigma_conn *conn, | 
|  | 1978 | struct sigma_cmd *cmd) | 
|  | 1979 | { | 
|  | 1980 | const char *intf = get_param(cmd, "Interface"); | 
|  | 1981 | const char *ifname, *val; | 
|  | 1982 | int id; | 
|  | 1983 | char buf[100]; | 
|  | 1984 |  | 
|  | 1985 | if (intf == NULL) | 
|  | 1986 | return -1; | 
|  | 1987 |  | 
|  | 1988 | if (strcmp(intf, get_main_ifname()) == 0) | 
|  | 1989 | ifname = get_station_ifname(); | 
|  | 1990 | else | 
|  | 1991 | ifname = intf; | 
|  | 1992 |  | 
| Bala Krishna Bhamidipati | 73d7af0 | 2016-03-24 12:27:56 +0530 | [diff] [blame] | 1993 | id = set_eap_common(dut, conn, ifname, 1, cmd); | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1994 | if (id < 0) | 
|  | 1995 | return id; | 
|  | 1996 |  | 
|  | 1997 | if (set_network(ifname, id, "eap", "PEAP") < 0) | 
|  | 1998 | return -2; | 
|  | 1999 |  | 
|  | 2000 | val = get_param(cmd, "innerEAP"); | 
|  | 2001 | if (val) { | 
|  | 2002 | if (strcasecmp(val, "MSCHAPv2") == 0) { | 
|  | 2003 | if (set_network_quoted(ifname, id, "phase2", | 
|  | 2004 | "auth=MSCHAPV2") < 0) | 
|  | 2005 | return -2; | 
|  | 2006 | } else if (strcasecmp(val, "GTC") == 0) { | 
|  | 2007 | if (set_network_quoted(ifname, id, "phase2", | 
|  | 2008 | "auth=GTC") < 0) | 
|  | 2009 | return -2; | 
|  | 2010 | } else | 
|  | 2011 | return -1; | 
|  | 2012 | } | 
|  | 2013 |  | 
|  | 2014 | val = get_param(cmd, "peapVersion"); | 
|  | 2015 | if (val) { | 
|  | 2016 | int ver = atoi(val); | 
|  | 2017 | if (ver < 0 || ver > 1) | 
|  | 2018 | return -1; | 
|  | 2019 | snprintf(buf, sizeof(buf), "peapver=%d", ver); | 
|  | 2020 | if (set_network_quoted(ifname, id, "phase1", buf) < 0) | 
|  | 2021 | return -2; | 
|  | 2022 | } | 
|  | 2023 |  | 
|  | 2024 | return 1; | 
|  | 2025 | } | 
|  | 2026 |  | 
|  | 2027 |  | 
|  | 2028 | static int cmd_sta_set_eapfast(struct sigma_dut *dut, struct sigma_conn *conn, | 
|  | 2029 | struct sigma_cmd *cmd) | 
|  | 2030 | { | 
|  | 2031 | const char *intf = get_param(cmd, "Interface"); | 
|  | 2032 | const char *ifname, *val; | 
|  | 2033 | int id; | 
|  | 2034 | char buf[100]; | 
|  | 2035 |  | 
|  | 2036 | if (intf == NULL) | 
|  | 2037 | return -1; | 
|  | 2038 |  | 
|  | 2039 | if (strcmp(intf, get_main_ifname()) == 0) | 
|  | 2040 | ifname = get_station_ifname(); | 
|  | 2041 | else | 
|  | 2042 | ifname = intf; | 
|  | 2043 |  | 
| Bala Krishna Bhamidipati | 73d7af0 | 2016-03-24 12:27:56 +0530 | [diff] [blame] | 2044 | id = set_eap_common(dut, conn, ifname, 1, cmd); | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2045 | if (id < 0) | 
|  | 2046 | return id; | 
|  | 2047 |  | 
|  | 2048 | if (set_network(ifname, id, "eap", "FAST") < 0) | 
|  | 2049 | return -2; | 
|  | 2050 |  | 
|  | 2051 | val = get_param(cmd, "innerEAP"); | 
|  | 2052 | if (val) { | 
|  | 2053 | if (strcasecmp(val, "MSCHAPV2") == 0) { | 
|  | 2054 | if (set_network_quoted(ifname, id, "phase2", | 
|  | 2055 | "auth=MSCHAPV2") < 0) | 
|  | 2056 | return -2; | 
|  | 2057 | } else if (strcasecmp(val, "GTC") == 0) { | 
|  | 2058 | if (set_network_quoted(ifname, id, "phase2", | 
|  | 2059 | "auth=GTC") < 0) | 
|  | 2060 | return -2; | 
|  | 2061 | } else | 
|  | 2062 | return -1; | 
|  | 2063 | } | 
|  | 2064 |  | 
|  | 2065 | val = get_param(cmd, "validateServer"); | 
|  | 2066 | if (val) { | 
|  | 2067 | /* TODO */ | 
|  | 2068 | sigma_dut_print(dut, DUT_MSG_INFO, "Ignored EAP-FAST " | 
|  | 2069 | "validateServer=%s", val); | 
|  | 2070 | } | 
|  | 2071 |  | 
|  | 2072 | val = get_param(cmd, "pacFile"); | 
|  | 2073 | if (val) { | 
|  | 2074 | snprintf(buf, sizeof(buf), "blob://%s", val); | 
|  | 2075 | if (set_network_quoted(ifname, id, "pac_file", buf) < 0) | 
|  | 2076 | return -2; | 
|  | 2077 | } | 
|  | 2078 |  | 
|  | 2079 | if (set_network_quoted(ifname, id, "phase1", "fast_provisioning=2") < | 
|  | 2080 | 0) | 
|  | 2081 | return -2; | 
|  | 2082 |  | 
|  | 2083 | return 1; | 
|  | 2084 | } | 
|  | 2085 |  | 
|  | 2086 |  | 
|  | 2087 | static int cmd_sta_set_eapaka(struct sigma_dut *dut, struct sigma_conn *conn, | 
|  | 2088 | struct sigma_cmd *cmd) | 
|  | 2089 | { | 
|  | 2090 | const char *intf = get_param(cmd, "Interface"); | 
|  | 2091 | const char *ifname; | 
|  | 2092 | int id; | 
|  | 2093 |  | 
|  | 2094 | if (intf == NULL) | 
|  | 2095 | return -1; | 
|  | 2096 |  | 
|  | 2097 | if (strcmp(intf, get_main_ifname()) == 0) | 
|  | 2098 | ifname = get_station_ifname(); | 
|  | 2099 | else | 
|  | 2100 | ifname = intf; | 
|  | 2101 |  | 
| Bala Krishna Bhamidipati | 73d7af0 | 2016-03-24 12:27:56 +0530 | [diff] [blame] | 2102 | id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd); | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2103 | if (id < 0) | 
|  | 2104 | return id; | 
|  | 2105 |  | 
|  | 2106 | if (set_network(ifname, id, "eap", "AKA") < 0) | 
|  | 2107 | return -2; | 
|  | 2108 |  | 
|  | 2109 | return 1; | 
|  | 2110 | } | 
|  | 2111 |  | 
|  | 2112 |  | 
|  | 2113 | static int cmd_sta_set_eapakaprime(struct sigma_dut *dut, | 
|  | 2114 | struct sigma_conn *conn, | 
|  | 2115 | struct sigma_cmd *cmd) | 
|  | 2116 | { | 
|  | 2117 | const char *intf = get_param(cmd, "Interface"); | 
|  | 2118 | const char *ifname; | 
|  | 2119 | int id; | 
|  | 2120 |  | 
|  | 2121 | if (intf == NULL) | 
|  | 2122 | return -1; | 
|  | 2123 |  | 
|  | 2124 | if (strcmp(intf, get_main_ifname()) == 0) | 
|  | 2125 | ifname = get_station_ifname(); | 
|  | 2126 | else | 
|  | 2127 | ifname = intf; | 
|  | 2128 |  | 
| Bala Krishna Bhamidipati | 73d7af0 | 2016-03-24 12:27:56 +0530 | [diff] [blame] | 2129 | id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd); | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2130 | if (id < 0) | 
|  | 2131 | return id; | 
|  | 2132 |  | 
|  | 2133 | if (set_network(ifname, id, "eap", "AKA'") < 0) | 
|  | 2134 | return -2; | 
|  | 2135 |  | 
|  | 2136 | return 1; | 
|  | 2137 | } | 
|  | 2138 |  | 
|  | 2139 |  | 
|  | 2140 | static int sta_set_open(struct sigma_dut *dut, struct sigma_conn *conn, | 
|  | 2141 | struct sigma_cmd *cmd) | 
|  | 2142 | { | 
|  | 2143 | const char *intf = get_param(cmd, "Interface"); | 
|  | 2144 | const char *ifname; | 
|  | 2145 | int id; | 
|  | 2146 |  | 
|  | 2147 | if (strcmp(intf, get_main_ifname()) == 0) | 
|  | 2148 | ifname = get_station_ifname(); | 
|  | 2149 | else | 
|  | 2150 | ifname = intf; | 
|  | 2151 |  | 
|  | 2152 | id = add_network_common(dut, conn, ifname, cmd); | 
|  | 2153 | if (id < 0) | 
|  | 2154 | return id; | 
|  | 2155 |  | 
|  | 2156 | if (set_network(ifname, id, "key_mgmt", "NONE") < 0) | 
|  | 2157 | return -2; | 
|  | 2158 |  | 
|  | 2159 | return 1; | 
|  | 2160 | } | 
|  | 2161 |  | 
|  | 2162 |  | 
| Jouni Malinen | 47dcc95 | 2017-10-09 16:43:24 +0300 | [diff] [blame] | 2163 | static int sta_set_owe(struct sigma_dut *dut, struct sigma_conn *conn, | 
|  | 2164 | struct sigma_cmd *cmd) | 
|  | 2165 | { | 
|  | 2166 | const char *intf = get_param(cmd, "Interface"); | 
|  | 2167 | const char *ifname, *val; | 
|  | 2168 | int id; | 
|  | 2169 |  | 
|  | 2170 | if (intf == NULL) | 
|  | 2171 | return -1; | 
|  | 2172 |  | 
|  | 2173 | if (strcmp(intf, get_main_ifname()) == 0) | 
|  | 2174 | ifname = get_station_ifname(); | 
|  | 2175 | else | 
|  | 2176 | ifname = intf; | 
|  | 2177 |  | 
|  | 2178 | id = set_wpa_common(dut, conn, ifname, cmd); | 
|  | 2179 | if (id < 0) | 
|  | 2180 | return id; | 
|  | 2181 |  | 
|  | 2182 | if (set_network(ifname, id, "key_mgmt", "OWE") < 0) | 
|  | 2183 | return -2; | 
|  | 2184 |  | 
|  | 2185 | val = get_param(cmd, "ECGroupID"); | 
| Jouni Malinen | fac9cad | 2017-10-10 18:35:55 +0300 | [diff] [blame] | 2186 | if (val && strcmp(val, "0") == 0) { | 
|  | 2187 | if (wpa_command(ifname, | 
|  | 2188 | "VENDOR_ELEM_ADD 13 ff23200000783590fb7440e03d5b3b33911f86affdcc6b4411b707846ac4ff08ddc8831ccd") != 0) { | 
|  | 2189 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 2190 | "Failed to set OWE DH Param element override"); | 
|  | 2191 | return -2; | 
|  | 2192 | } | 
|  | 2193 | } else if (val && set_network(ifname, id, "owe_group", val) < 0) { | 
| Jouni Malinen | 47dcc95 | 2017-10-09 16:43:24 +0300 | [diff] [blame] | 2194 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 2195 | "Failed to clear owe_group"); | 
|  | 2196 | return -2; | 
|  | 2197 | } | 
|  | 2198 |  | 
|  | 2199 | return 1; | 
|  | 2200 | } | 
|  | 2201 |  | 
|  | 2202 |  | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2203 | static int cmd_sta_set_security(struct sigma_dut *dut, struct sigma_conn *conn, | 
|  | 2204 | struct sigma_cmd *cmd) | 
|  | 2205 | { | 
|  | 2206 | const char *type = get_param(cmd, "Type"); | 
|  | 2207 |  | 
|  | 2208 | if (type == NULL) { | 
|  | 2209 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 2210 | "ErrorCode,Missing Type argument"); | 
|  | 2211 | return 0; | 
|  | 2212 | } | 
|  | 2213 |  | 
|  | 2214 | if (strcasecmp(type, "OPEN") == 0) | 
|  | 2215 | return sta_set_open(dut, conn, cmd); | 
| Jouni Malinen | 47dcc95 | 2017-10-09 16:43:24 +0300 | [diff] [blame] | 2216 | if (strcasecmp(type, "OWE") == 0) | 
|  | 2217 | return sta_set_owe(dut, conn, cmd); | 
| Jouni Malinen | 992a81e | 2017-08-22 13:57:47 +0300 | [diff] [blame] | 2218 | if (strcasecmp(type, "PSK") == 0 || | 
| Jouni Malinen | 0ab50f4 | 2017-08-31 01:34:59 +0300 | [diff] [blame] | 2219 | strcasecmp(type, "PSK-SAE") == 0 || | 
| Jouni Malinen | 992a81e | 2017-08-22 13:57:47 +0300 | [diff] [blame] | 2220 | strcasecmp(type, "SAE") == 0) | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2221 | return cmd_sta_set_psk(dut, conn, cmd); | 
|  | 2222 | if (strcasecmp(type, "EAPTLS") == 0) | 
|  | 2223 | return cmd_sta_set_eaptls(dut, conn, cmd); | 
|  | 2224 | if (strcasecmp(type, "EAPTTLS") == 0) | 
|  | 2225 | return cmd_sta_set_eapttls(dut, conn, cmd); | 
|  | 2226 | if (strcasecmp(type, "EAPPEAP") == 0) | 
|  | 2227 | return cmd_sta_set_peap(dut, conn, cmd); | 
|  | 2228 | if (strcasecmp(type, "EAPSIM") == 0) | 
|  | 2229 | return cmd_sta_set_eapsim(dut, conn, cmd); | 
|  | 2230 | if (strcasecmp(type, "EAPFAST") == 0) | 
|  | 2231 | return cmd_sta_set_eapfast(dut, conn, cmd); | 
|  | 2232 | if (strcasecmp(type, "EAPAKA") == 0) | 
|  | 2233 | return cmd_sta_set_eapaka(dut, conn, cmd); | 
|  | 2234 | if (strcasecmp(type, "EAPAKAPRIME") == 0) | 
|  | 2235 | return cmd_sta_set_eapakaprime(dut, conn, cmd); | 
| Amarnath Hullur Subramanyam | 81b11cd | 2018-01-30 19:07:17 -0800 | [diff] [blame] | 2236 | if (strcasecmp(type, "wep") == 0) | 
|  | 2237 | return cmd_sta_set_encryption(dut, conn, cmd); | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2238 |  | 
|  | 2239 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 2240 | "ErrorCode,Unsupported Type value"); | 
|  | 2241 | return 0; | 
|  | 2242 | } | 
|  | 2243 |  | 
|  | 2244 |  | 
|  | 2245 | int ath6kl_client_uapsd(struct sigma_dut *dut, const char *intf, int uapsd) | 
|  | 2246 | { | 
|  | 2247 | #ifdef __linux__ | 
|  | 2248 | /* special handling for ath6kl */ | 
|  | 2249 | char path[128], fname[128], *pos; | 
|  | 2250 | ssize_t res; | 
|  | 2251 | FILE *f; | 
|  | 2252 |  | 
|  | 2253 | snprintf(path, sizeof(path), "/sys/class/net/%s/phy80211", intf); | 
|  | 2254 | res = readlink(path, path, sizeof(path)); | 
|  | 2255 | if (res < 0) | 
|  | 2256 | return 0; /* not ath6kl */ | 
|  | 2257 |  | 
|  | 2258 | if (res >= (int) sizeof(path)) | 
|  | 2259 | res = sizeof(path) - 1; | 
|  | 2260 | path[res] = '\0'; | 
|  | 2261 | pos = strrchr(path, '/'); | 
|  | 2262 | if (pos == NULL) | 
|  | 2263 | pos = path; | 
|  | 2264 | else | 
|  | 2265 | pos++; | 
|  | 2266 | snprintf(fname, sizeof(fname), | 
|  | 2267 | "/sys/kernel/debug/ieee80211/%s/ath6kl/" | 
|  | 2268 | "create_qos", pos); | 
|  | 2269 | if (!file_exists(fname)) | 
|  | 2270 | return 0; /* not ath6kl */ | 
|  | 2271 |  | 
|  | 2272 | if (uapsd) { | 
|  | 2273 | f = fopen(fname, "w"); | 
|  | 2274 | if (f == NULL) | 
|  | 2275 | return -1; | 
|  | 2276 |  | 
|  | 2277 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl create_qos"); | 
|  | 2278 | fprintf(f, "4 2 2 1 2 9999999 9999999 9999999 7777777 0 4 " | 
|  | 2279 | "45000 200 56789000 56789000 5678900 0 0 9999999 " | 
|  | 2280 | "20000 0\n"); | 
|  | 2281 | fclose(f); | 
|  | 2282 | } else { | 
|  | 2283 | snprintf(fname, sizeof(fname), | 
|  | 2284 | "/sys/kernel/debug/ieee80211/%s/ath6kl/" | 
|  | 2285 | "delete_qos", pos); | 
|  | 2286 |  | 
|  | 2287 | f = fopen(fname, "w"); | 
|  | 2288 | if (f == NULL) | 
|  | 2289 | return -1; | 
|  | 2290 |  | 
|  | 2291 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl delete_qos"); | 
|  | 2292 | fprintf(f, "2 4\n"); | 
|  | 2293 | fclose(f); | 
|  | 2294 | } | 
|  | 2295 | #endif /* __linux__ */ | 
|  | 2296 |  | 
|  | 2297 | return 0; | 
|  | 2298 | } | 
|  | 2299 |  | 
|  | 2300 |  | 
|  | 2301 | static int cmd_sta_set_uapsd(struct sigma_dut *dut, struct sigma_conn *conn, | 
|  | 2302 | struct sigma_cmd *cmd) | 
|  | 2303 | { | 
|  | 2304 | const char *intf = get_param(cmd, "Interface"); | 
|  | 2305 | /* const char *ssid = get_param(cmd, "ssid"); */ | 
|  | 2306 | const char *val; | 
|  | 2307 | int max_sp_len = 4; | 
|  | 2308 | int ac_be = 1, ac_bk = 1, ac_vi = 1, ac_vo = 1; | 
|  | 2309 | char buf[100]; | 
|  | 2310 | int ret1, ret2; | 
|  | 2311 |  | 
|  | 2312 | val = get_param(cmd, "maxSPLength"); | 
|  | 2313 | if (val) { | 
|  | 2314 | max_sp_len = atoi(val); | 
|  | 2315 | if (max_sp_len != 0 && max_sp_len != 1 && max_sp_len != 2 && | 
|  | 2316 | max_sp_len != 4) | 
|  | 2317 | return -1; | 
|  | 2318 | } | 
|  | 2319 |  | 
|  | 2320 | val = get_param(cmd, "acBE"); | 
|  | 2321 | if (val) | 
|  | 2322 | ac_be = atoi(val); | 
|  | 2323 |  | 
|  | 2324 | val = get_param(cmd, "acBK"); | 
|  | 2325 | if (val) | 
|  | 2326 | ac_bk = atoi(val); | 
|  | 2327 |  | 
|  | 2328 | val = get_param(cmd, "acVI"); | 
|  | 2329 | if (val) | 
|  | 2330 | ac_vi = atoi(val); | 
|  | 2331 |  | 
|  | 2332 | val = get_param(cmd, "acVO"); | 
|  | 2333 | if (val) | 
|  | 2334 | ac_vo = atoi(val); | 
|  | 2335 |  | 
|  | 2336 | dut->client_uapsd = ac_be || ac_bk || ac_vi || ac_vo; | 
|  | 2337 |  | 
|  | 2338 | snprintf(buf, sizeof(buf), "P2P_SET client_apsd %d,%d,%d,%d;%d", | 
|  | 2339 | ac_be, ac_bk, ac_vi, ac_vo, max_sp_len); | 
|  | 2340 | ret1 = wpa_command(intf, buf); | 
|  | 2341 |  | 
|  | 2342 | snprintf(buf, sizeof(buf), "SET uapsd %d,%d,%d,%d;%d", | 
|  | 2343 | ac_be, ac_bk, ac_vi, ac_vo, max_sp_len); | 
|  | 2344 | ret2 = wpa_command(intf, buf); | 
|  | 2345 |  | 
|  | 2346 | if (ret1 && ret2) { | 
|  | 2347 | sigma_dut_print(dut, DUT_MSG_INFO, "Failed to set client mode " | 
|  | 2348 | "UAPSD parameters."); | 
|  | 2349 | return -2; | 
|  | 2350 | } | 
|  | 2351 |  | 
|  | 2352 | if (ath6kl_client_uapsd(dut, intf, dut->client_uapsd) < 0) { | 
|  | 2353 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 2354 | "ErrorCode,Failed to set ath6kl QoS parameters"); | 
|  | 2355 | return 0; | 
|  | 2356 | } | 
|  | 2357 |  | 
|  | 2358 | return 1; | 
|  | 2359 | } | 
|  | 2360 |  | 
|  | 2361 |  | 
|  | 2362 | static int cmd_sta_set_wmm(struct sigma_dut *dut, struct sigma_conn *conn, | 
|  | 2363 | struct sigma_cmd *cmd) | 
|  | 2364 | { | 
|  | 2365 | char buf[1000]; | 
|  | 2366 | const char *intf = get_param(cmd, "Interface"); | 
|  | 2367 | const char *grp = get_param(cmd, "Group"); | 
|  | 2368 | const char *act = get_param(cmd, "Action"); | 
|  | 2369 | const char *tid = get_param(cmd, "Tid"); | 
|  | 2370 | const char *dir = get_param(cmd, "Direction"); | 
|  | 2371 | const char *psb = get_param(cmd, "Psb"); | 
|  | 2372 | const char *up = get_param(cmd, "Up"); | 
|  | 2373 | const char *fixed = get_param(cmd, "Fixed"); | 
|  | 2374 | const char *size = get_param(cmd, "Size"); | 
|  | 2375 | const char *msize = get_param(cmd, "Maxsize"); | 
|  | 2376 | const char *minsi = get_param(cmd, "Min_srvc_intrvl"); | 
|  | 2377 | const char *maxsi = get_param(cmd, "Max_srvc_intrvl"); | 
|  | 2378 | const char *inact = get_param(cmd, "Inactivity"); | 
|  | 2379 | const char *sus = get_param(cmd, "Suspension"); | 
|  | 2380 | const char *mindr = get_param(cmd, "Mindatarate"); | 
|  | 2381 | const char *meandr = get_param(cmd, "Meandatarate"); | 
|  | 2382 | const char *peakdr = get_param(cmd, "Peakdatarate"); | 
|  | 2383 | const char *phyrate = get_param(cmd, "Phyrate"); | 
|  | 2384 | const char *burstsize = get_param(cmd, "Burstsize"); | 
|  | 2385 | const char *sba = get_param(cmd, "Sba"); | 
|  | 2386 | int direction; | 
|  | 2387 | int handle; | 
| Peng Xu | 9331962 | 2017-10-04 17:58:16 -0700 | [diff] [blame] | 2388 | float sba_fv = 0; | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2389 | int fixed_int; | 
|  | 2390 | int psb_ts; | 
|  | 2391 |  | 
|  | 2392 | if (intf == NULL || grp == NULL || act == NULL ) | 
|  | 2393 | return -1; | 
|  | 2394 |  | 
|  | 2395 | if (strcasecmp(act, "addts") == 0) { | 
|  | 2396 | if (tid == NULL || dir == NULL || psb == NULL || | 
|  | 2397 | up == NULL || fixed == NULL || size == NULL) | 
|  | 2398 | return -1; | 
|  | 2399 |  | 
|  | 2400 | /* | 
|  | 2401 | * Note: Sigma CAPI spec lists uplink, downlink, and bidi as the | 
|  | 2402 | * possible values, but WMM-AC and V-E test scripts use "UP, | 
|  | 2403 | * "DOWN", and "BIDI". | 
|  | 2404 | */ | 
|  | 2405 | if (strcasecmp(dir, "uplink") == 0 || | 
|  | 2406 | strcasecmp(dir, "up") == 0) { | 
|  | 2407 | direction = 0; | 
|  | 2408 | } else if (strcasecmp(dir, "downlink") == 0 || | 
|  | 2409 | strcasecmp(dir, "down") == 0) { | 
|  | 2410 | direction = 1; | 
|  | 2411 | } else if (strcasecmp(dir, "bidi") == 0) { | 
|  | 2412 | direction = 2; | 
|  | 2413 | } else { | 
|  | 2414 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 2415 | "Direction %s not supported", dir); | 
|  | 2416 | return -1; | 
|  | 2417 | } | 
|  | 2418 |  | 
|  | 2419 | if (strcasecmp(psb, "legacy") == 0) { | 
|  | 2420 | psb_ts = 0; | 
|  | 2421 | } else if (strcasecmp(psb, "uapsd") == 0) { | 
|  | 2422 | psb_ts = 1; | 
|  | 2423 | } else { | 
|  | 2424 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 2425 | "PSB %s not supported", psb); | 
|  | 2426 | return -1; | 
|  | 2427 | } | 
|  | 2428 |  | 
|  | 2429 | if (atoi(tid) < 0 || atoi(tid) > 7) { | 
|  | 2430 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 2431 | "TID %s not supported", tid); | 
|  | 2432 | return -1; | 
|  | 2433 | } | 
|  | 2434 |  | 
|  | 2435 | if (strcasecmp(fixed, "true") == 0) { | 
|  | 2436 | fixed_int = 1; | 
|  | 2437 | } else { | 
|  | 2438 | fixed_int = 0; | 
|  | 2439 | } | 
|  | 2440 |  | 
| Peng Xu | 9331962 | 2017-10-04 17:58:16 -0700 | [diff] [blame] | 2441 | if (sba) | 
|  | 2442 | sba_fv = atof(sba); | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2443 |  | 
|  | 2444 | dut->dialog_token++; | 
|  | 2445 | handle = 7000 + dut->dialog_token; | 
|  | 2446 |  | 
|  | 2447 | /* | 
|  | 2448 | * size: convert to hex | 
|  | 2449 | * maxsi: convert to hex | 
|  | 2450 | * mindr: convert to hex | 
|  | 2451 | * meandr: convert to hex | 
|  | 2452 | * peakdr: convert to hex | 
|  | 2453 | * burstsize: convert to hex | 
|  | 2454 | * phyrate: convert to hex | 
|  | 2455 | * sba: convert to hex with modification | 
|  | 2456 | * minsi: convert to integer | 
|  | 2457 | * sus: convert to integer | 
|  | 2458 | * inact: convert to integer | 
|  | 2459 | * maxsi: convert to integer | 
|  | 2460 | */ | 
|  | 2461 |  | 
|  | 2462 | /* | 
|  | 2463 | * The Nominal MSDU Size field is 2 octets long and contains an | 
|  | 2464 | * unsigned integer that specifies the nominal size, in octets, | 
|  | 2465 | * of MSDUs belonging to the traffic under this traffic | 
|  | 2466 | * specification and is defined in Figure 16. If the Fixed | 
|  | 2467 | * subfield is set to 1, then the size of the MSDU is fixed and | 
|  | 2468 | * is indicated by the Size Subfield. If the Fixed subfield is | 
|  | 2469 | * set to 0, then the size of the MSDU might not be fixed and | 
|  | 2470 | * the Size indicates the nominal MSDU size. | 
|  | 2471 | * | 
|  | 2472 | * The Surplus Bandwidth Allowance Factor field is 2 octets long | 
|  | 2473 | * and specifies the excess allocation of time (and bandwidth) | 
|  | 2474 | * over and above the stated rates required to transport an MSDU | 
|  | 2475 | * belonging to the traffic in this TSPEC. This field is | 
|  | 2476 | * represented as an unsigned binary number with an implicit | 
|  | 2477 | * binary point after the leftmost 3 bits. For example, an SBA | 
|  | 2478 | * of 1.75 is represented as 0x3800. This field is included to | 
|  | 2479 | * account for retransmissions. As such, the value of this field | 
|  | 2480 | * must be greater than unity. | 
|  | 2481 | */ | 
|  | 2482 |  | 
|  | 2483 | snprintf(buf, sizeof(buf), | 
|  | 2484 | "iwpriv %s addTspec %d %s %d %d %s 0x%X" | 
|  | 2485 | " 0x%X 0x%X 0x%X" | 
|  | 2486 | " 0x%X 0x%X 0x%X" | 
|  | 2487 | " 0x%X %d %d %d %d" | 
|  | 2488 | " %d %d", | 
|  | 2489 | intf, handle, tid, direction, psb_ts, up, | 
|  | 2490 | (unsigned int) ((fixed_int << 15) | atoi(size)), | 
|  | 2491 | msize ? atoi(msize) : 0, | 
|  | 2492 | mindr ? atoi(mindr) : 0, | 
|  | 2493 | meandr ? atoi(meandr) : 0, | 
|  | 2494 | peakdr ? atoi(peakdr) : 0, | 
|  | 2495 | burstsize ? atoi(burstsize) : 0, | 
|  | 2496 | phyrate ? atoi(phyrate) : 0, | 
|  | 2497 | sba ? ((unsigned int) (((int) sba_fv << 13) | | 
|  | 2498 | (int)((sba_fv - (int) sba_fv) * | 
|  | 2499 | 8192))) : 0, | 
|  | 2500 | minsi ? atoi(minsi) : 0, | 
|  | 2501 | sus ? atoi(sus) : 0, | 
|  | 2502 | 0, 0, | 
|  | 2503 | inact ? atoi(inact) : 0, | 
|  | 2504 | maxsi ? atoi(maxsi) : 0); | 
|  | 2505 |  | 
|  | 2506 | if (system(buf) != 0) { | 
|  | 2507 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 2508 | "iwpriv addtspec request failed"); | 
|  | 2509 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 2510 | "errorCode,Failed to execute addTspec command"); | 
|  | 2511 | return 0; | 
|  | 2512 | } | 
|  | 2513 |  | 
|  | 2514 | sigma_dut_print(dut, DUT_MSG_INFO, | 
|  | 2515 | "iwpriv addtspec request send"); | 
|  | 2516 |  | 
|  | 2517 | /* Mapping handle to a TID */ | 
|  | 2518 | dut->tid_to_handle[atoi(tid)] = handle; | 
|  | 2519 | } else if (strcasecmp(act, "delts") == 0) { | 
|  | 2520 | if (tid == NULL) | 
|  | 2521 | return -1; | 
|  | 2522 |  | 
|  | 2523 | if (atoi(tid) < 0 || atoi(tid) > 7) { | 
|  | 2524 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 2525 | "TID %s not supported", tid); | 
|  | 2526 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 2527 | "errorCode,Unsupported TID"); | 
|  | 2528 | return 0; | 
|  | 2529 | } | 
|  | 2530 |  | 
|  | 2531 | handle = dut->tid_to_handle[atoi(tid)]; | 
|  | 2532 |  | 
|  | 2533 | if (handle < 7000 || handle > 7255) { | 
|  | 2534 | /* Invalid handle ie no mapping for that TID */ | 
|  | 2535 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 2536 | "handle-> %d not found", handle); | 
|  | 2537 | } | 
|  | 2538 |  | 
|  | 2539 | snprintf(buf, sizeof(buf), "iwpriv %s delTspec %d", | 
|  | 2540 | intf, handle); | 
|  | 2541 |  | 
|  | 2542 | if (system(buf) != 0) { | 
|  | 2543 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 2544 | "iwpriv deltspec request failed"); | 
|  | 2545 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 2546 | "errorCode,Failed to execute delTspec command"); | 
|  | 2547 | return 0; | 
|  | 2548 | } | 
|  | 2549 |  | 
|  | 2550 | sigma_dut_print(dut, DUT_MSG_INFO, | 
|  | 2551 | "iwpriv deltspec request send"); | 
|  | 2552 |  | 
|  | 2553 | dut->tid_to_handle[atoi(tid)] = 0; | 
|  | 2554 | } else { | 
|  | 2555 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 2556 | "Action type %s not supported", act); | 
|  | 2557 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 2558 | "errorCode,Unsupported Action"); | 
|  | 2559 | return 0; | 
|  | 2560 | } | 
|  | 2561 |  | 
|  | 2562 | return 1; | 
|  | 2563 | } | 
|  | 2564 |  | 
|  | 2565 |  | 
| vamsi krishna | 52e16f9 | 2017-08-29 12:37:34 +0530 | [diff] [blame] | 2566 | static int find_network(struct sigma_dut *dut, const char *ssid) | 
|  | 2567 | { | 
|  | 2568 | char list[4096]; | 
|  | 2569 | char *pos; | 
|  | 2570 |  | 
|  | 2571 | sigma_dut_print(dut, DUT_MSG_DEBUG, | 
|  | 2572 | "Search for profile based on SSID: '%s'", ssid); | 
|  | 2573 | if (wpa_command_resp(get_station_ifname(), "LIST_NETWORKS", | 
|  | 2574 | list, sizeof(list)) < 0) | 
|  | 2575 | return -1; | 
|  | 2576 | pos = strstr(list, ssid); | 
|  | 2577 | if (!pos || pos == list || pos[-1] != '\t' || pos[strlen(ssid)] != '\t') | 
|  | 2578 | return -1; | 
|  | 2579 |  | 
|  | 2580 | while (pos > list && pos[-1] != '\n') | 
|  | 2581 | pos--; | 
|  | 2582 | dut->infra_network_id = atoi(pos); | 
|  | 2583 | snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid); | 
|  | 2584 | return 0; | 
|  | 2585 | } | 
|  | 2586 |  | 
|  | 2587 |  | 
| Sunil Dutt | 4459508 | 2018-02-12 19:41:45 +0530 | [diff] [blame] | 2588 | #ifdef NL80211_SUPPORT | 
|  | 2589 | static int sta_config_rsnie(struct sigma_dut *dut, int val) | 
|  | 2590 | { | 
|  | 2591 | struct nl_msg *msg; | 
|  | 2592 | int ret; | 
|  | 2593 | struct nlattr *params; | 
|  | 2594 | int ifindex; | 
|  | 2595 |  | 
|  | 2596 | ifindex = if_nametoindex("wlan0"); | 
|  | 2597 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, | 
|  | 2598 | NL80211_CMD_VENDOR)) || | 
|  | 2599 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || | 
|  | 2600 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | 
|  | 2601 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | 
|  | 2602 | QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) || | 
|  | 2603 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | 
|  | 2604 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE, val)) { | 
|  | 2605 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 2606 | "%s: err in adding vendor_cmd and vendor_data", | 
|  | 2607 | __func__); | 
|  | 2608 | nlmsg_free(msg); | 
|  | 2609 | return -1; | 
|  | 2610 | } | 
|  | 2611 | nla_nest_end(msg, params); | 
|  | 2612 |  | 
|  | 2613 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); | 
|  | 2614 | if (ret) { | 
|  | 2615 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 2616 | "%s: err in send_and_recv_msgs, ret=%d", | 
|  | 2617 | __func__, ret); | 
|  | 2618 | return ret; | 
|  | 2619 | } | 
|  | 2620 |  | 
|  | 2621 | return 0; | 
|  | 2622 | } | 
|  | 2623 | #endif /* NL80211_SUPPORT */ | 
|  | 2624 |  | 
|  | 2625 |  | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2626 | static int cmd_sta_associate(struct sigma_dut *dut, struct sigma_conn *conn, | 
|  | 2627 | struct sigma_cmd *cmd) | 
|  | 2628 | { | 
|  | 2629 | /* const char *intf = get_param(cmd, "Interface"); */ | 
|  | 2630 | const char *ssid = get_param(cmd, "ssid"); | 
|  | 2631 | const char *wps_param = get_param(cmd, "WPS"); | 
|  | 2632 | const char *bssid = get_param(cmd, "bssid"); | 
| Jouni Malinen | 46a19b6 | 2017-06-23 14:31:27 +0300 | [diff] [blame] | 2633 | const char *chan = get_param(cmd, "channel"); | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2634 | int wps = 0; | 
| Jouni Malinen | 3c367e8 | 2017-06-23 17:01:47 +0300 | [diff] [blame] | 2635 | char buf[1000], extra[50]; | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2636 |  | 
|  | 2637 | if (ssid == NULL) | 
|  | 2638 | return -1; | 
|  | 2639 |  | 
| Jouni Malinen | 3c367e8 | 2017-06-23 17:01:47 +0300 | [diff] [blame] | 2640 | if (dut->rsne_override) { | 
| Sunil Dutt | 4459508 | 2018-02-12 19:41:45 +0530 | [diff] [blame] | 2641 | #ifdef NL80211_SUPPORT | 
|  | 2642 | if (get_driver_type() == DRIVER_WCN) { | 
|  | 2643 | sta_config_rsnie(dut, 1); | 
|  | 2644 | dut->config_rsnie = 1; | 
|  | 2645 | } | 
|  | 2646 | #endif /* NL80211_SUPPORT */ | 
| Jouni Malinen | 3c367e8 | 2017-06-23 17:01:47 +0300 | [diff] [blame] | 2647 | snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s", | 
|  | 2648 | dut->rsne_override); | 
|  | 2649 | if (wpa_command(get_station_ifname(), buf) < 0) { | 
|  | 2650 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 2651 | "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override"); | 
|  | 2652 | return 0; | 
|  | 2653 | } | 
|  | 2654 | } | 
|  | 2655 |  | 
| Jouni Malinen | 6814313 | 2017-09-02 02:34:08 +0300 | [diff] [blame] | 2656 | if (dut->sae_commit_override) { | 
|  | 2657 | snprintf(buf, sizeof(buf), "SET sae_commit_override %s", | 
|  | 2658 | dut->sae_commit_override); | 
|  | 2659 | if (wpa_command(get_station_ifname(), buf) < 0) { | 
|  | 2660 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 2661 | "ErrorCode,Failed to set SAE commit override"); | 
|  | 2662 | return 0; | 
|  | 2663 | } | 
|  | 2664 | } | 
| Ankita Bajaj | 1bde794 | 2018-01-09 19:15:01 +0530 | [diff] [blame] | 2665 | #ifdef ANDROID | 
|  | 2666 | if (dut->fils_hlp) | 
|  | 2667 | process_fils_hlp(dut); | 
|  | 2668 | #endif /* ANDROID */ | 
| Jouni Malinen | 6814313 | 2017-09-02 02:34:08 +0300 | [diff] [blame] | 2669 |  | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2670 | if (wps_param && | 
|  | 2671 | (strcmp(wps_param, "1") == 0 || strcasecmp(wps_param, "On") == 0)) | 
|  | 2672 | wps = 1; | 
|  | 2673 |  | 
|  | 2674 | if (wps) { | 
|  | 2675 | if (dut->wps_method == WFA_CS_WPS_NOT_READY) { | 
|  | 2676 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,WPS " | 
|  | 2677 | "parameters not yet set"); | 
|  | 2678 | return 0; | 
|  | 2679 | } | 
|  | 2680 | if (dut->wps_method == WFA_CS_WPS_PBC) { | 
|  | 2681 | if (wpa_command(get_station_ifname(), "WPS_PBC") < 0) | 
|  | 2682 | return -2; | 
|  | 2683 | } else { | 
|  | 2684 | snprintf(buf, sizeof(buf), "WPS_PIN any %s", | 
|  | 2685 | dut->wps_pin); | 
|  | 2686 | if (wpa_command(get_station_ifname(), buf) < 0) | 
|  | 2687 | return -2; | 
|  | 2688 | } | 
|  | 2689 | } else { | 
| vamsi krishna | 52e16f9 | 2017-08-29 12:37:34 +0530 | [diff] [blame] | 2690 | if (strcmp(ssid, dut->infra_ssid) == 0) { | 
|  | 2691 | sigma_dut_print(dut, DUT_MSG_DEBUG, | 
|  | 2692 | "sta_associate for the most recently added network"); | 
|  | 2693 | } else if (find_network(dut, ssid) < 0) { | 
|  | 2694 | sigma_dut_print(dut, DUT_MSG_DEBUG, | 
|  | 2695 | "sta_associate for a previously stored network profile"); | 
|  | 2696 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 2697 | "ErrorCode,Profile not found"); | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2698 | return 0; | 
|  | 2699 | } | 
|  | 2700 |  | 
|  | 2701 | if (bssid && | 
|  | 2702 | set_network(get_station_ifname(), dut->infra_network_id, | 
|  | 2703 | "bssid", bssid) < 0) { | 
|  | 2704 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode," | 
|  | 2705 | "Invalid bssid argument"); | 
|  | 2706 | return 0; | 
|  | 2707 | } | 
|  | 2708 |  | 
| Jouni Malinen | 46a19b6 | 2017-06-23 14:31:27 +0300 | [diff] [blame] | 2709 | extra[0] = '\0'; | 
|  | 2710 | if (chan) | 
|  | 2711 | snprintf(extra, sizeof(extra), " freq=%u", | 
|  | 2712 | channel_to_freq(atoi(chan))); | 
|  | 2713 | snprintf(buf, sizeof(buf), "SELECT_NETWORK %d%s", | 
|  | 2714 | dut->infra_network_id, extra); | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2715 | if (wpa_command(get_station_ifname(), buf) < 0) { | 
|  | 2716 | sigma_dut_print(dut, DUT_MSG_INFO, "Failed to select " | 
|  | 2717 | "network id %d on %s", | 
|  | 2718 | dut->infra_network_id, | 
|  | 2719 | get_station_ifname()); | 
|  | 2720 | return -2; | 
|  | 2721 | } | 
|  | 2722 | } | 
|  | 2723 |  | 
|  | 2724 | return 1; | 
|  | 2725 | } | 
|  | 2726 |  | 
|  | 2727 |  | 
|  | 2728 | static int run_hs20_osu(struct sigma_dut *dut, const char *params) | 
|  | 2729 | { | 
|  | 2730 | char buf[500], cmd[200]; | 
|  | 2731 | int res; | 
|  | 2732 |  | 
|  | 2733 | /* Use hs20-osu-client file at the current dir, if found; otherwise use | 
|  | 2734 | * default path */ | 
|  | 2735 | res = snprintf(cmd, sizeof(cmd), | 
|  | 2736 | "%s -w \"%s\" -r hs20-osu-client.res %s%s -dddKt -f Logs/hs20-osu-client.txt", | 
|  | 2737 | file_exists("./hs20-osu-client") ? | 
|  | 2738 | "./hs20-osu-client" : "hs20-osu-client", | 
|  | 2739 | sigma_wpas_ctrl, | 
|  | 2740 | dut->summary_log ? "-s " : "", | 
|  | 2741 | dut->summary_log ? dut->summary_log : ""); | 
|  | 2742 | if (res < 0 || res >= (int) sizeof(cmd)) | 
|  | 2743 | return -1; | 
|  | 2744 |  | 
|  | 2745 | res = snprintf(buf, sizeof(buf), "%s %s", cmd, params); | 
|  | 2746 | if (res < 0 || res >= (int) sizeof(buf)) | 
|  | 2747 | return -1; | 
|  | 2748 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); | 
|  | 2749 |  | 
|  | 2750 | if (system(buf) != 0) { | 
|  | 2751 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run: %s", buf); | 
|  | 2752 | return -1; | 
|  | 2753 | } | 
|  | 2754 | sigma_dut_print(dut, DUT_MSG_DEBUG, | 
|  | 2755 | "Completed hs20-osu-client operation"); | 
|  | 2756 |  | 
|  | 2757 | return 0; | 
|  | 2758 | } | 
|  | 2759 |  | 
|  | 2760 |  | 
|  | 2761 | static int download_ppsmo(struct sigma_dut *dut, | 
|  | 2762 | struct sigma_conn *conn, | 
|  | 2763 | const char *intf, | 
|  | 2764 | struct sigma_cmd *cmd) | 
|  | 2765 | { | 
|  | 2766 | const char *name, *path, *val; | 
|  | 2767 | char url[500], buf[600], fbuf[100]; | 
|  | 2768 | char *fqdn = NULL; | 
|  | 2769 |  | 
|  | 2770 | name = get_param(cmd, "FileName"); | 
|  | 2771 | path = get_param(cmd, "FilePath"); | 
|  | 2772 | if (name == NULL || path == NULL) | 
|  | 2773 | return -1; | 
|  | 2774 |  | 
|  | 2775 | if (strcasecmp(path, "VendorSpecific") == 0) { | 
|  | 2776 | snprintf(url, sizeof(url), "PPS/%s", name); | 
|  | 2777 | sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured PPS MO " | 
|  | 2778 | "from the device (%s)", url); | 
|  | 2779 | if (!file_exists(url)) { | 
|  | 2780 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested " | 
|  | 2781 | "PPS MO file does not exist"); | 
|  | 2782 | return 0; | 
|  | 2783 | } | 
|  | 2784 | snprintf(buf, sizeof(buf), "cp %s pps-tnds.xml", url); | 
|  | 2785 | if (system(buf) != 0) { | 
|  | 2786 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 2787 | "errorCode,Failed to copy PPS MO"); | 
|  | 2788 | return 0; | 
|  | 2789 | } | 
|  | 2790 | } else if (strncasecmp(path, "http:", 5) != 0 && | 
|  | 2791 | strncasecmp(path, "https:", 6) != 0) { | 
|  | 2792 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode," | 
|  | 2793 | "Unsupported FilePath value"); | 
|  | 2794 | return 0; | 
|  | 2795 | } else { | 
|  | 2796 | snprintf(url, sizeof(url), "%s/%s", path, name); | 
|  | 2797 | sigma_dut_print(dut, DUT_MSG_INFO, "Downloading PPS MO from %s", | 
|  | 2798 | url); | 
|  | 2799 | snprintf(buf, sizeof(buf), "wget -T 10 -t 3 -O pps-tnds.xml '%s'", url); | 
|  | 2800 | remove("pps-tnds.xml"); | 
|  | 2801 | if (system(buf) != 0) { | 
|  | 2802 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 2803 | "errorCode,Failed to download PPS MO"); | 
|  | 2804 | return 0; | 
|  | 2805 | } | 
|  | 2806 | } | 
|  | 2807 |  | 
|  | 2808 | if (run_hs20_osu(dut, "from_tnds pps-tnds.xml pps.xml") < 0) { | 
|  | 2809 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 2810 | "errorCode,Failed to parse downloaded PPSMO"); | 
|  | 2811 | return 0; | 
|  | 2812 | } | 
|  | 2813 | unlink("pps-tnds.xml"); | 
|  | 2814 |  | 
|  | 2815 | val = get_param(cmd, "managementTreeURI"); | 
|  | 2816 | if (val) { | 
|  | 2817 | const char *pos, *end; | 
|  | 2818 | sigma_dut_print(dut, DUT_MSG_DEBUG, "managementTreeURI: %s", | 
|  | 2819 | val); | 
|  | 2820 | if (strncmp(val, "./Wi-Fi/", 8) != 0) { | 
|  | 2821 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 2822 | "errorCode,Invalid managementTreeURI prefix"); | 
|  | 2823 | return 0; | 
|  | 2824 | } | 
|  | 2825 | pos = val + 8; | 
|  | 2826 | end = strchr(pos, '/'); | 
|  | 2827 | if (end == NULL || | 
|  | 2828 | strcmp(end, "/PerProviderSubscription") != 0) { | 
|  | 2829 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 2830 | "errorCode,Invalid managementTreeURI postfix"); | 
|  | 2831 | return 0; | 
|  | 2832 | } | 
|  | 2833 | if (end - pos >= (int) sizeof(fbuf)) { | 
|  | 2834 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 2835 | "errorCode,Too long FQDN in managementTreeURI"); | 
|  | 2836 | return 0; | 
|  | 2837 | } | 
|  | 2838 | memcpy(fbuf, pos, end - pos); | 
|  | 2839 | fbuf[end - pos] = '\0'; | 
|  | 2840 | fqdn = fbuf; | 
|  | 2841 | sigma_dut_print(dut, DUT_MSG_INFO, | 
|  | 2842 | "FQDN from managementTreeURI: %s", fqdn); | 
|  | 2843 | } else if (run_hs20_osu(dut, "get_fqdn pps.xml") == 0) { | 
|  | 2844 | FILE *f = fopen("pps-fqdn", "r"); | 
|  | 2845 | if (f) { | 
|  | 2846 | if (fgets(fbuf, sizeof(fbuf), f)) { | 
|  | 2847 | fbuf[sizeof(fbuf) - 1] = '\0'; | 
|  | 2848 | fqdn = fbuf; | 
|  | 2849 | sigma_dut_print(dut, DUT_MSG_DEBUG, | 
|  | 2850 | "Use FQDN %s", fqdn); | 
|  | 2851 | } | 
|  | 2852 | fclose(f); | 
|  | 2853 | } | 
|  | 2854 | } | 
|  | 2855 |  | 
|  | 2856 | if (fqdn == NULL) { | 
|  | 2857 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 2858 | "errorCode,No FQDN specified"); | 
|  | 2859 | return 0; | 
|  | 2860 | } | 
|  | 2861 |  | 
|  | 2862 | mkdir("SP", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); | 
|  | 2863 | snprintf(buf, sizeof(buf), "SP/%s", fqdn); | 
|  | 2864 | mkdir(buf, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); | 
|  | 2865 |  | 
|  | 2866 | snprintf(buf, sizeof(buf), "SP/%s/pps.xml", fqdn); | 
|  | 2867 | if (rename("pps.xml", buf) < 0) { | 
|  | 2868 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 2869 | "errorCode,Could not move PPS MO"); | 
|  | 2870 | return 0; | 
|  | 2871 | } | 
|  | 2872 |  | 
|  | 2873 | if (strcasecmp(path, "VendorSpecific") == 0) { | 
|  | 2874 | snprintf(buf, sizeof(buf), "cp Certs/ca.pem SP/%s/ca.pem", | 
|  | 2875 | fqdn); | 
|  | 2876 | if (system(buf)) { | 
|  | 2877 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 2878 | "errorCode,Failed to copy OSU CA cert"); | 
|  | 2879 | return 0; | 
|  | 2880 | } | 
|  | 2881 |  | 
|  | 2882 | snprintf(buf, sizeof(buf), | 
|  | 2883 | "cp Certs/aaa-ca.pem SP/%s/aaa-ca.pem", | 
|  | 2884 | fqdn); | 
|  | 2885 | if (system(buf)) { | 
|  | 2886 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 2887 | "errorCode,Failed to copy AAA CA cert"); | 
|  | 2888 | return 0; | 
|  | 2889 | } | 
|  | 2890 | } else { | 
|  | 2891 | snprintf(buf, sizeof(buf), | 
|  | 2892 | "dl_osu_ca SP/%s/pps.xml SP/%s/ca.pem", | 
|  | 2893 | fqdn, fqdn); | 
|  | 2894 | if (run_hs20_osu(dut, buf) < 0) { | 
|  | 2895 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 2896 | "errorCode,Failed to download OSU CA cert"); | 
|  | 2897 | return 0; | 
|  | 2898 | } | 
|  | 2899 |  | 
|  | 2900 | snprintf(buf, sizeof(buf), | 
|  | 2901 | "dl_aaa_ca SP/%s/pps.xml SP/%s/aaa-ca.pem", | 
|  | 2902 | fqdn, fqdn); | 
|  | 2903 | if (run_hs20_osu(dut, buf) < 0) { | 
|  | 2904 | sigma_dut_print(dut, DUT_MSG_INFO, | 
|  | 2905 | "Failed to download AAA CA cert"); | 
|  | 2906 | } | 
|  | 2907 | } | 
|  | 2908 |  | 
|  | 2909 | if (file_exists("next-client-cert.pem")) { | 
|  | 2910 | snprintf(buf, sizeof(buf), "SP/%s/client-cert.pem", fqdn); | 
|  | 2911 | if (rename("next-client-cert.pem", buf) < 0) { | 
|  | 2912 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 2913 | "errorCode,Could not move client certificate"); | 
|  | 2914 | return 0; | 
|  | 2915 | } | 
|  | 2916 | } | 
|  | 2917 |  | 
|  | 2918 | if (file_exists("next-client-key.pem")) { | 
|  | 2919 | snprintf(buf, sizeof(buf), "SP/%s/client-key.pem", fqdn); | 
|  | 2920 | if (rename("next-client-key.pem", buf) < 0) { | 
|  | 2921 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 2922 | "errorCode,Could not move client key"); | 
|  | 2923 | return 0; | 
|  | 2924 | } | 
|  | 2925 | } | 
|  | 2926 |  | 
|  | 2927 | snprintf(buf, sizeof(buf), "set_pps SP/%s/pps.xml", fqdn); | 
|  | 2928 | if (run_hs20_osu(dut, buf) < 0) { | 
|  | 2929 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 2930 | "errorCode,Failed to configure credential from " | 
|  | 2931 | "PPSMO"); | 
|  | 2932 | return 0; | 
|  | 2933 | } | 
|  | 2934 |  | 
|  | 2935 | return 1; | 
|  | 2936 | } | 
|  | 2937 |  | 
|  | 2938 |  | 
|  | 2939 | static int download_cert(struct sigma_dut *dut, | 
|  | 2940 | struct sigma_conn *conn, | 
|  | 2941 | const char *intf, | 
|  | 2942 | struct sigma_cmd *cmd) | 
|  | 2943 | { | 
|  | 2944 | const char *name, *path; | 
|  | 2945 | char url[500], buf[600]; | 
|  | 2946 |  | 
|  | 2947 | name = get_param(cmd, "FileName"); | 
|  | 2948 | path = get_param(cmd, "FilePath"); | 
|  | 2949 | if (name == NULL || path == NULL) | 
|  | 2950 | return -1; | 
|  | 2951 |  | 
|  | 2952 | if (strcasecmp(path, "VendorSpecific") == 0) { | 
|  | 2953 | snprintf(url, sizeof(url), "Certs/%s-cert.pem", name); | 
|  | 2954 | sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client " | 
|  | 2955 | "certificate from the device (%s)", url); | 
|  | 2956 | if (!file_exists(url)) { | 
|  | 2957 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested " | 
|  | 2958 | "certificate file does not exist"); | 
|  | 2959 | return 0; | 
|  | 2960 | } | 
|  | 2961 | snprintf(buf, sizeof(buf), "cp %s next-client-cert.pem", url); | 
|  | 2962 | if (system(buf) != 0) { | 
|  | 2963 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 2964 | "errorCode,Failed to copy client " | 
|  | 2965 | "certificate"); | 
|  | 2966 | return 0; | 
|  | 2967 | } | 
|  | 2968 |  | 
|  | 2969 | snprintf(url, sizeof(url), "Certs/%s-key.pem", name); | 
|  | 2970 | sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client " | 
|  | 2971 | "private key from the device (%s)", url); | 
|  | 2972 | if (!file_exists(url)) { | 
|  | 2973 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested " | 
|  | 2974 | "private key file does not exist"); | 
|  | 2975 | return 0; | 
|  | 2976 | } | 
|  | 2977 | snprintf(buf, sizeof(buf), "cp %s next-client-key.pem", url); | 
|  | 2978 | if (system(buf) != 0) { | 
|  | 2979 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 2980 | "errorCode,Failed to copy client key"); | 
|  | 2981 | return 0; | 
|  | 2982 | } | 
|  | 2983 | } else if (strncasecmp(path, "http:", 5) != 0 && | 
|  | 2984 | strncasecmp(path, "https:", 6) != 0) { | 
|  | 2985 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode," | 
|  | 2986 | "Unsupported FilePath value"); | 
|  | 2987 | return 0; | 
|  | 2988 | } else { | 
|  | 2989 | snprintf(url, sizeof(url), "%s/%s.pem", path, name); | 
|  | 2990 | sigma_dut_print(dut, DUT_MSG_INFO, "Downloading client " | 
|  | 2991 | "certificate/key from %s", url); | 
|  | 2992 | snprintf(buf, sizeof(buf), | 
|  | 2993 | "wget -T 10 -t 3 -O next-client-cert.pem '%s'", url); | 
|  | 2994 | if (system(buf) != 0) { | 
|  | 2995 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 2996 | "errorCode,Failed to download client " | 
|  | 2997 | "certificate"); | 
|  | 2998 | return 0; | 
|  | 2999 | } | 
|  | 3000 |  | 
|  | 3001 | if (system("cp next-client-cert.pem next-client-key.pem") != 0) | 
|  | 3002 | { | 
|  | 3003 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 3004 | "errorCode,Failed to copy client key"); | 
|  | 3005 | return 0; | 
|  | 3006 | } | 
|  | 3007 | } | 
|  | 3008 |  | 
|  | 3009 | return 1; | 
|  | 3010 | } | 
|  | 3011 |  | 
|  | 3012 |  | 
|  | 3013 | static int cmd_sta_preset_testparameters_hs2_r2(struct sigma_dut *dut, | 
|  | 3014 | struct sigma_conn *conn, | 
|  | 3015 | const char *intf, | 
|  | 3016 | struct sigma_cmd *cmd) | 
|  | 3017 | { | 
|  | 3018 | const char *val; | 
|  | 3019 |  | 
|  | 3020 | val = get_param(cmd, "FileType"); | 
|  | 3021 | if (val && strcasecmp(val, "PPSMO") == 0) | 
|  | 3022 | return download_ppsmo(dut, conn, intf, cmd); | 
|  | 3023 | if (val && strcasecmp(val, "CERT") == 0) | 
|  | 3024 | return download_cert(dut, conn, intf, cmd); | 
|  | 3025 | if (val) { | 
|  | 3026 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 3027 | "ErrorCode,Unsupported FileType"); | 
|  | 3028 | return 0; | 
|  | 3029 | } | 
|  | 3030 |  | 
|  | 3031 | return 1; | 
|  | 3032 | } | 
|  | 3033 |  | 
|  | 3034 |  | 
| Ankita Bajaj | a2cb567 | 2017-10-25 16:08:28 +0530 | [diff] [blame] | 3035 | static int cmd_sta_preset_testparameters_oce(struct sigma_dut *dut, | 
|  | 3036 | struct sigma_conn *conn, | 
|  | 3037 | const char *intf, | 
|  | 3038 | struct sigma_cmd *cmd) | 
|  | 3039 | { | 
|  | 3040 | const char *val; | 
| Ankita Bajaj | 1bde794 | 2018-01-09 19:15:01 +0530 | [diff] [blame] | 3041 | char buf[1000]; | 
|  | 3042 | char text[20]; | 
|  | 3043 | unsigned char addr[ETH_ALEN]; | 
| Ankita Bajaj | a2cb567 | 2017-10-25 16:08:28 +0530 | [diff] [blame] | 3044 |  | 
|  | 3045 | val = get_param(cmd, "OCESupport"); | 
|  | 3046 | if (val && strcasecmp(val, "Disable") == 0) { | 
|  | 3047 | if (wpa_command(intf, "SET oce 0") < 0) { | 
|  | 3048 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 3049 | "ErrorCode,Failed to disable OCE"); | 
|  | 3050 | return 0; | 
|  | 3051 | } | 
|  | 3052 | } else if (val && strcasecmp(val, "Enable") == 0) { | 
|  | 3053 | if (wpa_command(intf, "SET oce 1") < 0) { | 
|  | 3054 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 3055 | "ErrorCode,Failed to enable OCE"); | 
|  | 3056 | return 0; | 
|  | 3057 | } | 
|  | 3058 | } | 
|  | 3059 |  | 
| vamsi krishna | a279949 | 2017-12-05 14:28:01 +0530 | [diff] [blame] | 3060 | val = get_param(cmd, "FILScap"); | 
|  | 3061 | if (val && (atoi(val) == 1)) { | 
|  | 3062 | if (wpa_command(intf, "SET disable_fils 0") < 0) { | 
|  | 3063 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 3064 | "ErrorCode,Failed to enable FILS"); | 
|  | 3065 | return 0; | 
|  | 3066 | } | 
|  | 3067 | } else if (val && (atoi(val) == 0)) { | 
|  | 3068 | if (wpa_command(intf, "SET disable_fils 1") < 0) { | 
|  | 3069 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 3070 | "ErrorCode,Failed to disable FILS"); | 
|  | 3071 | return 0; | 
|  | 3072 | } | 
|  | 3073 | } | 
|  | 3074 |  | 
| Ankita Bajaj | 1bde794 | 2018-01-09 19:15:01 +0530 | [diff] [blame] | 3075 | val = get_param(cmd, "FILSHLP"); | 
|  | 3076 | if (val && strcasecmp(val, "Enable") == 0) { | 
|  | 3077 | if (get_wpa_status(get_station_ifname(), "address", text, | 
|  | 3078 | sizeof(text)) < 0) | 
|  | 3079 | return -2; | 
|  | 3080 | hwaddr_aton(text, addr); | 
|  | 3081 | snprintf(buf, sizeof(buf), | 
|  | 3082 | "FILS_HLP_REQ_ADD ff:ff:ff:ff:ff:ff " | 
|  | 3083 | "080045100140000040004011399e00000000ffffffff00440043" | 
|  | 3084 | "012cb30001010600fd4f46410000000000000000000000000000" | 
|  | 3085 | "000000000000" | 
|  | 3086 | "%02x%02x%02x%02x%02x%02x" | 
|  | 3087 | "0000000000000000000000000000000000000000000000000000" | 
|  | 3088 | "0000000000000000000000000000000000000000000000000000" | 
|  | 3089 | "0000000000000000000000000000000000000000000000000000" | 
|  | 3090 | "0000000000000000000000000000000000000000000000000000" | 
|  | 3091 | "0000000000000000000000000000000000000000000000000000" | 
|  | 3092 | "0000000000000000000000000000000000000000000000000000" | 
|  | 3093 | "0000000000000000000000000000000000000000000000000000" | 
|  | 3094 | "0000000000000000000000000000000000000000638253633501" | 
|  | 3095 | "013d0701000af549d29b390205dc3c12616e64726f69642d6468" | 
|  | 3096 | "63702d382e302e30370a0103060f1a1c333a3b2b5000ff00", | 
|  | 3097 | addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]); | 
|  | 3098 | if (wpa_command(intf, buf)) { | 
|  | 3099 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 3100 | "ErrorCode,Failed to add HLP"); | 
|  | 3101 | return 0; | 
|  | 3102 | } | 
|  | 3103 | dut->fils_hlp = 1; | 
|  | 3104 | } | 
|  | 3105 |  | 
| Ankita Bajaj | a2cb567 | 2017-10-25 16:08:28 +0530 | [diff] [blame] | 3106 | return 1; | 
|  | 3107 | } | 
|  | 3108 |  | 
|  | 3109 |  | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3110 | static void ath_sta_set_noack(struct sigma_dut *dut, const char *intf, | 
|  | 3111 | const char *val) | 
|  | 3112 | { | 
|  | 3113 | int counter = 0; | 
|  | 3114 | char token[50]; | 
|  | 3115 | char *result; | 
|  | 3116 | char buf[100]; | 
| Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 3117 | char *saveptr; | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3118 |  | 
| Peng Xu | b8fc5cc | 2017-05-10 17:27:28 -0700 | [diff] [blame] | 3119 | strlcpy(token, val, sizeof(token)); | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3120 | token[sizeof(token) - 1] = '\0'; | 
| Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 3121 | result = strtok_r(token, ":", &saveptr); | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3122 | while (result) { | 
|  | 3123 | if (strcmp(result, "disable") == 0) { | 
|  | 3124 | snprintf(buf, sizeof(buf), | 
|  | 3125 | "iwpriv %s noackpolicy %d 1 0", | 
|  | 3126 | intf, counter); | 
|  | 3127 | } else { | 
|  | 3128 | snprintf(buf, sizeof(buf), | 
|  | 3129 | "iwpriv %s noackpolicy %d 1 1", | 
|  | 3130 | intf, counter); | 
|  | 3131 | } | 
|  | 3132 | if (system(buf) != 0) { | 
|  | 3133 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 3134 | "iwpriv noackpolicy failed"); | 
|  | 3135 | } | 
| Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 3136 | result = strtok_r(NULL, ":", &saveptr); | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3137 | counter++; | 
|  | 3138 | } | 
|  | 3139 | } | 
|  | 3140 |  | 
|  | 3141 |  | 
|  | 3142 | static void ath_sta_set_rts(struct sigma_dut *dut, const char *intf, | 
|  | 3143 | const char *val) | 
|  | 3144 | { | 
|  | 3145 | char buf[100]; | 
|  | 3146 |  | 
|  | 3147 | snprintf(buf, sizeof(buf), "iwconfig %s rts %s", intf, val); | 
|  | 3148 | if (system(buf) != 0) { | 
|  | 3149 | sigma_dut_print(dut, DUT_MSG_ERROR, "iwconfig RTS failed"); | 
|  | 3150 | } | 
|  | 3151 | } | 
|  | 3152 |  | 
|  | 3153 |  | 
|  | 3154 | static void ath_sta_set_wmm(struct sigma_dut *dut, const char *intf, | 
|  | 3155 | const char *val) | 
|  | 3156 | { | 
|  | 3157 | char buf[100]; | 
|  | 3158 |  | 
|  | 3159 | if (strcasecmp(val, "off") == 0) { | 
|  | 3160 | snprintf(buf, sizeof(buf), "iwpriv %s wmm 0", intf); | 
|  | 3161 | if (system(buf) != 0) { | 
|  | 3162 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 3163 | "Failed to turn off WMM"); | 
|  | 3164 | } | 
|  | 3165 | } | 
|  | 3166 | } | 
|  | 3167 |  | 
|  | 3168 |  | 
| Amarnath Hullur Subramanyam | 75214d2 | 2018-02-04 19:17:11 -0800 | [diff] [blame] | 3169 | static int wcn_sta_set_wmm(struct sigma_dut *dut, const char *intf, | 
|  | 3170 | const char *val) | 
|  | 3171 | { | 
|  | 3172 | #ifdef NL80211_SUPPORT | 
|  | 3173 | struct nl_msg *msg; | 
|  | 3174 | int ret = 0; | 
|  | 3175 | struct nlattr *params; | 
|  | 3176 | int ifindex; | 
|  | 3177 | int wmmenable = 1; | 
|  | 3178 |  | 
|  | 3179 | if (val && | 
|  | 3180 | (strcasecmp(val, "off") == 0 || strcmp(val, "0") == 0)) | 
|  | 3181 | wmmenable = 0; | 
|  | 3182 |  | 
|  | 3183 | ifindex = if_nametoindex(intf); | 
|  | 3184 | if (ifindex == 0) { | 
|  | 3185 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 3186 | "%s: Index for interface %s failed", | 
|  | 3187 | __func__, intf); | 
|  | 3188 | return -1; | 
|  | 3189 | } | 
|  | 3190 |  | 
|  | 3191 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, | 
|  | 3192 | NL80211_CMD_VENDOR)) || | 
|  | 3193 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || | 
|  | 3194 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | 
|  | 3195 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | 
|  | 3196 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || | 
|  | 3197 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | 
|  | 3198 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WMM_ENABLE, | 
|  | 3199 | wmmenable)) { | 
|  | 3200 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 3201 | "%s: err in adding vendor_cmd and vendor_data", | 
|  | 3202 | __func__); | 
|  | 3203 | nlmsg_free(msg); | 
|  | 3204 | return -1; | 
|  | 3205 | } | 
|  | 3206 | nla_nest_end(msg, params); | 
|  | 3207 |  | 
|  | 3208 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); | 
|  | 3209 | if (ret) { | 
|  | 3210 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 3211 | "%s: err in send_and_recv_msgs, ret=%d", | 
|  | 3212 | __func__, ret); | 
|  | 3213 | } | 
|  | 3214 | return ret; | 
|  | 3215 | #else /* NL80211_SUPPORT */ | 
|  | 3216 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 3217 | "WMM cannot be changed without NL80211_SUPPORT defined"); | 
|  | 3218 | return -1; | 
|  | 3219 | #endif /* NL80211_SUPPORT */ | 
|  | 3220 | } | 
|  | 3221 |  | 
|  | 3222 |  | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3223 | static void ath_sta_set_sgi(struct sigma_dut *dut, const char *intf, | 
|  | 3224 | const char *val) | 
|  | 3225 | { | 
|  | 3226 | char buf[100]; | 
|  | 3227 | int sgi20; | 
|  | 3228 |  | 
|  | 3229 | sgi20 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0; | 
|  | 3230 |  | 
|  | 3231 | snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d", intf, sgi20); | 
|  | 3232 | if (system(buf) != 0) | 
|  | 3233 | sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv shortgi failed"); | 
|  | 3234 | } | 
|  | 3235 |  | 
|  | 3236 |  | 
|  | 3237 | static void ath_sta_set_11nrates(struct sigma_dut *dut, const char *intf, | 
|  | 3238 | const char *val) | 
|  | 3239 | { | 
|  | 3240 | char buf[100]; | 
| Pradeep Reddy POTTETI | 67376b7 | 2016-10-25 20:08:17 +0530 | [diff] [blame] | 3241 | int rate_code, v; | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3242 |  | 
|  | 3243 | /* Disable Tx Beam forming when using a fixed rate */ | 
|  | 3244 | ath_disable_txbf(dut, intf); | 
|  | 3245 |  | 
| Pradeep Reddy POTTETI | 67376b7 | 2016-10-25 20:08:17 +0530 | [diff] [blame] | 3246 | v = atoi(val); | 
|  | 3247 | if (v < 0 || v > 32) { | 
|  | 3248 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 3249 | "Invalid Fixed MCS rate: %d", v); | 
|  | 3250 | return; | 
|  | 3251 | } | 
|  | 3252 | rate_code = 0x80 + v; | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3253 |  | 
|  | 3254 | snprintf(buf, sizeof(buf), "iwpriv %s set11NRates 0x%x", | 
|  | 3255 | intf, rate_code); | 
|  | 3256 | if (system(buf) != 0) { | 
|  | 3257 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 3258 | "iwpriv set11NRates failed"); | 
|  | 3259 | } | 
|  | 3260 |  | 
|  | 3261 | /* Channel width gets messed up, fix this */ | 
|  | 3262 | snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d", intf, dut->chwidth); | 
|  | 3263 | if (system(buf) != 0) | 
|  | 3264 | sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv chwidth failed"); | 
|  | 3265 | } | 
|  | 3266 |  | 
|  | 3267 |  | 
| Amarnath Hullur Subramanyam | d5bb573 | 2018-02-22 15:50:38 -0800 | [diff] [blame] | 3268 | static void iwpriv_sta_set_amsdu(struct sigma_dut *dut, const char *intf, | 
|  | 3269 | const char *val) | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3270 | { | 
|  | 3271 | char buf[60]; | 
|  | 3272 |  | 
|  | 3273 | if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) | 
|  | 3274 | snprintf(buf, sizeof(buf), "iwpriv %s amsdu 2", intf); | 
|  | 3275 | else | 
|  | 3276 | snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf); | 
|  | 3277 |  | 
|  | 3278 | if (system(buf) != 0) | 
|  | 3279 | sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv amsdu failed"); | 
|  | 3280 | } | 
|  | 3281 |  | 
|  | 3282 |  | 
| Deepak Dhamdhere | 80356cb | 2016-03-28 16:48:32 -0700 | [diff] [blame] | 3283 | static int iwpriv_sta_set_ampdu(struct sigma_dut *dut, const char *intf, | 
|  | 3284 | int ampdu) | 
|  | 3285 | { | 
|  | 3286 | char buf[60]; | 
| Amarnath Hullur Subramanyam | 63c590a | 2018-03-07 15:26:21 -0800 | [diff] [blame^] | 3287 | int maxaggregation = 63; | 
| Deepak Dhamdhere | 80356cb | 2016-03-28 16:48:32 -0700 | [diff] [blame] | 3288 |  | 
| Amarnath Hullur Subramanyam | 63c590a | 2018-03-07 15:26:21 -0800 | [diff] [blame^] | 3289 | if (ampdu) | 
|  | 3290 | ampdu = maxaggregation; | 
| Deepak Dhamdhere | 80356cb | 2016-03-28 16:48:32 -0700 | [diff] [blame] | 3291 | snprintf(buf, sizeof(buf), "iwpriv %s ampdu %d", intf, ampdu); | 
|  | 3292 | if (system(buf) != 0) { | 
|  | 3293 | sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv ampdu failed"); | 
|  | 3294 | return -1; | 
|  | 3295 | } | 
|  | 3296 |  | 
|  | 3297 | return 0; | 
|  | 3298 | } | 
|  | 3299 |  | 
|  | 3300 |  | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3301 | static void ath_sta_set_stbc(struct sigma_dut *dut, const char *intf, | 
|  | 3302 | const char *val) | 
|  | 3303 | { | 
|  | 3304 | char buf[60]; | 
|  | 3305 |  | 
|  | 3306 | snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc %s", intf, val); | 
|  | 3307 | if (system(buf) != 0) { | 
|  | 3308 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 3309 | "iwpriv tx_stbc failed"); | 
|  | 3310 | } | 
|  | 3311 |  | 
|  | 3312 | snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc %s", intf, val); | 
|  | 3313 | if (system(buf) != 0) { | 
|  | 3314 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 3315 | "iwpriv rx_stbc failed"); | 
|  | 3316 | } | 
|  | 3317 | } | 
|  | 3318 |  | 
|  | 3319 |  | 
|  | 3320 | static int wcn_sta_set_cts_width(struct sigma_dut *dut, const char *intf, | 
|  | 3321 | const char *val) | 
|  | 3322 | { | 
|  | 3323 | char buf[60]; | 
|  | 3324 |  | 
| Peng Xu | cc317ed | 2017-05-18 16:44:37 -0700 | [diff] [blame] | 3325 | if (strcmp(val, "160") == 0) { | 
|  | 3326 | snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 5", intf); | 
|  | 3327 | } else if (strcmp(val, "80") == 0) { | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3328 | snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf); | 
|  | 3329 | } else if (strcmp(val, "40") == 0) { | 
|  | 3330 | snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 2", intf); | 
|  | 3331 | } else if (strcmp(val, "20") == 0) { | 
|  | 3332 | snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 1", intf); | 
|  | 3333 | } else if (strcasecmp(val, "Auto") == 0) { | 
|  | 3334 | buf[0] = '\0'; | 
|  | 3335 | } else { | 
|  | 3336 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 3337 | "WIDTH/CTS_WIDTH value not supported"); | 
|  | 3338 | return -1; | 
|  | 3339 | } | 
|  | 3340 |  | 
|  | 3341 | if (buf[0] != '\0' && system(buf) != 0) { | 
|  | 3342 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 3343 | "Failed to set WIDTH/CTS_WIDTH"); | 
|  | 3344 | return -1; | 
|  | 3345 | } | 
|  | 3346 |  | 
|  | 3347 | return 0; | 
|  | 3348 | } | 
|  | 3349 |  | 
|  | 3350 |  | 
|  | 3351 | int ath_set_width(struct sigma_dut *dut, struct sigma_conn *conn, | 
|  | 3352 | const char *intf, const char *val) | 
|  | 3353 | { | 
|  | 3354 | char buf[60]; | 
|  | 3355 |  | 
|  | 3356 | if (strcasecmp(val, "Auto") == 0) { | 
|  | 3357 | snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf); | 
|  | 3358 | dut->chwidth = 0; | 
|  | 3359 | } else if (strcasecmp(val, "20") == 0) { | 
|  | 3360 | snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf); | 
|  | 3361 | dut->chwidth = 0; | 
|  | 3362 | } else if (strcasecmp(val, "40") == 0) { | 
|  | 3363 | snprintf(buf, sizeof(buf), "iwpriv %s chwidth 1", intf); | 
|  | 3364 | dut->chwidth = 1; | 
|  | 3365 | } else if (strcasecmp(val, "80") == 0) { | 
|  | 3366 | snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf); | 
|  | 3367 | dut->chwidth = 2; | 
|  | 3368 | } else if (strcasecmp(val, "160") == 0) { | 
|  | 3369 | snprintf(buf, sizeof(buf), "iwpriv %s chwidth 3", intf); | 
|  | 3370 | dut->chwidth = 3; | 
|  | 3371 | } else { | 
|  | 3372 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 3373 | "ErrorCode,WIDTH not supported"); | 
|  | 3374 | return -1; | 
|  | 3375 | } | 
|  | 3376 |  | 
|  | 3377 | if (system(buf) != 0) { | 
|  | 3378 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 3379 | "iwpriv chwidth failed"); | 
|  | 3380 | } | 
|  | 3381 |  | 
|  | 3382 | return 0; | 
|  | 3383 | } | 
|  | 3384 |  | 
|  | 3385 |  | 
|  | 3386 | static int wcn_sta_set_sp_stream(struct sigma_dut *dut, const char *intf, | 
|  | 3387 | const char *val) | 
|  | 3388 | { | 
|  | 3389 | char buf[60]; | 
|  | 3390 |  | 
| Amarnath Hullur Subramanyam | d5374fa | 2018-02-25 19:00:24 -0800 | [diff] [blame] | 3391 | if (strcmp(val, "1SS") == 0 || strcmp(val, "1") == 0) { | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3392 | snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf); | 
| Amarnath Hullur Subramanyam | d5374fa | 2018-02-25 19:00:24 -0800 | [diff] [blame] | 3393 | } else if (strcmp(val, "2SS") == 0 || strcmp(val, "2") == 0) { | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3394 | snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf); | 
|  | 3395 | } else { | 
|  | 3396 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 3397 | "SP_STREAM value not supported"); | 
|  | 3398 | return -1; | 
|  | 3399 | } | 
|  | 3400 |  | 
|  | 3401 | if (system(buf) != 0) { | 
|  | 3402 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 3403 | "Failed to set SP_STREAM"); | 
|  | 3404 | return -1; | 
|  | 3405 | } | 
|  | 3406 |  | 
|  | 3407 | return 0; | 
|  | 3408 | } | 
|  | 3409 |  | 
|  | 3410 |  | 
| Pradeep Reddy POTTETI | 4a1f6b3 | 2016-11-23 13:15:21 +0530 | [diff] [blame] | 3411 | static void wcn_sta_set_stbc(struct sigma_dut *dut, const char *intf, | 
|  | 3412 | const char *val) | 
|  | 3413 | { | 
|  | 3414 | char buf[60]; | 
|  | 3415 |  | 
|  | 3416 | snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc %s", intf, val); | 
|  | 3417 | if (system(buf) != 0) | 
|  | 3418 | sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv tx_stbc failed"); | 
|  | 3419 |  | 
|  | 3420 | snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc %s", intf, val); | 
|  | 3421 | if (system(buf) != 0) | 
|  | 3422 | sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv rx_stbc failed"); | 
|  | 3423 | } | 
|  | 3424 |  | 
|  | 3425 |  | 
| Ashwini Patil | 68d02cd | 2017-01-10 15:39:16 +0530 | [diff] [blame] | 3426 | static int mbo_set_cellular_data_capa(struct sigma_dut *dut, | 
|  | 3427 | struct sigma_conn *conn, | 
|  | 3428 | const char *intf, int capa) | 
|  | 3429 | { | 
|  | 3430 | char buf[32]; | 
|  | 3431 |  | 
|  | 3432 | if (capa > 0 && capa < 4) { | 
|  | 3433 | snprintf(buf, sizeof(buf), "SET mbo_cell_capa %d", capa); | 
|  | 3434 | if (wpa_command(intf, buf) < 0) { | 
|  | 3435 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 3436 | "ErrorCode, Failed to set cellular data capability"); | 
|  | 3437 | return 0; | 
|  | 3438 | } | 
|  | 3439 | return 1; | 
|  | 3440 | } | 
|  | 3441 |  | 
|  | 3442 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 3443 | "Invalid Cellular data capability: %d", capa); | 
|  | 3444 | send_resp(dut, conn, SIGMA_INVALID, | 
|  | 3445 | "ErrorCode,Invalid cellular data capability"); | 
|  | 3446 | return 0; | 
|  | 3447 | } | 
|  | 3448 |  | 
|  | 3449 |  | 
| Ashwini Patil | 9183fdb | 2017-04-13 16:58:25 +0530 | [diff] [blame] | 3450 | static int mbo_set_roaming(struct sigma_dut *dut, struct sigma_conn *conn, | 
|  | 3451 | const char *intf, const char *val) | 
|  | 3452 | { | 
|  | 3453 | if (strcasecmp(val, "Disable") == 0) { | 
|  | 3454 | if (wpa_command(intf, "SET roaming 0") < 0) { | 
|  | 3455 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 3456 | "ErrorCode,Failed to disable roaming"); | 
|  | 3457 | return 0; | 
|  | 3458 | } | 
|  | 3459 | return 1; | 
|  | 3460 | } | 
|  | 3461 |  | 
|  | 3462 | if (strcasecmp(val, "Enable") == 0) { | 
|  | 3463 | if (wpa_command(intf, "SET roaming 1") < 0) { | 
|  | 3464 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 3465 | "ErrorCode,Failed to enable roaming"); | 
|  | 3466 | return 0; | 
|  | 3467 | } | 
|  | 3468 | return 1; | 
|  | 3469 | } | 
|  | 3470 |  | 
|  | 3471 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 3472 | "Invalid value provided for roaming: %s", val); | 
|  | 3473 | send_resp(dut, conn, SIGMA_INVALID, | 
|  | 3474 | "ErrorCode,Unknown value provided for Roaming"); | 
|  | 3475 | return 0; | 
|  | 3476 | } | 
|  | 3477 |  | 
|  | 3478 |  | 
| Ashwini Patil | a75de5a | 2017-04-13 16:35:05 +0530 | [diff] [blame] | 3479 | static int mbo_set_assoc_disallow(struct sigma_dut *dut, | 
|  | 3480 | struct sigma_conn *conn, | 
|  | 3481 | const char *intf, const char *val) | 
|  | 3482 | { | 
|  | 3483 | if (strcasecmp(val, "Disable") == 0) { | 
|  | 3484 | if (wpa_command(intf, "SET ignore_assoc_disallow 1") < 0) { | 
|  | 3485 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 3486 | "ErrorCode,Failed to disable Assoc_disallow"); | 
|  | 3487 | return 0; | 
|  | 3488 | } | 
|  | 3489 | return 1; | 
|  | 3490 | } | 
|  | 3491 |  | 
|  | 3492 | if (strcasecmp(val, "Enable") == 0) { | 
|  | 3493 | if (wpa_command(intf, "SET ignore_assoc_disallow 0") < 0) { | 
|  | 3494 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 3495 | "ErrorCode,Failed to enable Assoc_disallow"); | 
|  | 3496 | return 0; | 
|  | 3497 | } | 
|  | 3498 | return 1; | 
|  | 3499 | } | 
|  | 3500 |  | 
|  | 3501 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 3502 | "Invalid value provided for Assoc_disallow: %s", val); | 
|  | 3503 | send_resp(dut, conn, SIGMA_INVALID, | 
|  | 3504 | "ErrorCode,Unknown value provided for Assoc_disallow"); | 
|  | 3505 | return 0; | 
|  | 3506 | } | 
|  | 3507 |  | 
|  | 3508 |  | 
| Ashwini Patil | c63161e | 2017-04-13 16:30:23 +0530 | [diff] [blame] | 3509 | static int mbo_set_bss_trans_req(struct sigma_dut *dut, struct sigma_conn *conn, | 
|  | 3510 | const char *intf, const char *val) | 
|  | 3511 | { | 
|  | 3512 | if (strcasecmp(val, "Reject") == 0) { | 
|  | 3513 | if (wpa_command(intf, "SET reject_btm_req_reason 1") < 0) { | 
|  | 3514 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 3515 | "ErrorCode,Failed to Reject BTM Request"); | 
|  | 3516 | return 0; | 
|  | 3517 | } | 
|  | 3518 | return 1; | 
|  | 3519 | } | 
|  | 3520 |  | 
|  | 3521 | if (strcasecmp(val, "Accept") == 0) { | 
|  | 3522 | if (wpa_command(intf, "SET reject_btm_req_reason 0") < 0) { | 
|  | 3523 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 3524 | "ErrorCode,Failed to Accept BTM Request"); | 
|  | 3525 | return 0; | 
|  | 3526 | } | 
|  | 3527 | return 1; | 
|  | 3528 | } | 
|  | 3529 |  | 
|  | 3530 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 3531 | "Invalid value provided for BSS_Transition: %s", val); | 
|  | 3532 | send_resp(dut, conn, SIGMA_INVALID, | 
|  | 3533 | "ErrorCode,Unknown value provided for BSS_Transition"); | 
|  | 3534 | return 0; | 
|  | 3535 | } | 
|  | 3536 |  | 
|  | 3537 |  | 
| Ashwini Patil | 0040258 | 2017-04-13 12:29:39 +0530 | [diff] [blame] | 3538 | static int mbo_set_non_pref_ch_list(struct sigma_dut *dut, | 
|  | 3539 | struct sigma_conn *conn, | 
|  | 3540 | const char *intf, | 
|  | 3541 | struct sigma_cmd *cmd) | 
|  | 3542 | { | 
|  | 3543 | const char *ch, *pref, *op_class, *reason; | 
|  | 3544 | char buf[120]; | 
|  | 3545 | int len, ret; | 
|  | 3546 |  | 
|  | 3547 | pref = get_param(cmd, "Ch_Pref"); | 
|  | 3548 | if (!pref) | 
|  | 3549 | return 1; | 
|  | 3550 |  | 
|  | 3551 | if (strcasecmp(pref, "clear") == 0) { | 
|  | 3552 | free(dut->non_pref_ch_list); | 
|  | 3553 | dut->non_pref_ch_list = NULL; | 
|  | 3554 | } else { | 
|  | 3555 | op_class = get_param(cmd, "Ch_Op_Class"); | 
|  | 3556 | if (!op_class) { | 
|  | 3557 | send_resp(dut, conn, SIGMA_INVALID, | 
|  | 3558 | "ErrorCode,Ch_Op_Class not provided"); | 
|  | 3559 | return 0; | 
|  | 3560 | } | 
|  | 3561 |  | 
|  | 3562 | ch = get_param(cmd, "Ch_Pref_Num"); | 
|  | 3563 | if (!ch) { | 
|  | 3564 | send_resp(dut, conn, SIGMA_INVALID, | 
|  | 3565 | "ErrorCode,Ch_Pref_Num not provided"); | 
|  | 3566 | return 0; | 
|  | 3567 | } | 
|  | 3568 |  | 
|  | 3569 | reason = get_param(cmd, "Ch_Reason_Code"); | 
|  | 3570 | if (!reason) { | 
|  | 3571 | send_resp(dut, conn, SIGMA_INVALID, | 
|  | 3572 | "ErrorCode,Ch_Reason_Code not provided"); | 
|  | 3573 | return 0; | 
|  | 3574 | } | 
|  | 3575 |  | 
|  | 3576 | if (!dut->non_pref_ch_list) { | 
|  | 3577 | dut->non_pref_ch_list = | 
|  | 3578 | calloc(1, NON_PREF_CH_LIST_SIZE); | 
|  | 3579 | if (!dut->non_pref_ch_list) { | 
|  | 3580 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 3581 | "ErrorCode,Failed to allocate memory for non_pref_ch_list"); | 
|  | 3582 | return 0; | 
|  | 3583 | } | 
|  | 3584 | } | 
|  | 3585 | len = strlen(dut->non_pref_ch_list); | 
|  | 3586 | ret = snprintf(dut->non_pref_ch_list + len, | 
|  | 3587 | NON_PREF_CH_LIST_SIZE - len, | 
|  | 3588 | " %s:%s:%s:%s", op_class, ch, pref, reason); | 
|  | 3589 | if (ret > 0 && ret < NON_PREF_CH_LIST_SIZE - len) { | 
|  | 3590 | sigma_dut_print(dut, DUT_MSG_DEBUG, "non_pref_list: %s", | 
|  | 3591 | dut->non_pref_ch_list); | 
|  | 3592 | } else { | 
|  | 3593 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 3594 | "snprintf failed for non_pref_list, ret = %d", | 
|  | 3595 | ret); | 
|  | 3596 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 3597 | "ErrorCode,snprintf failed"); | 
|  | 3598 | free(dut->non_pref_ch_list); | 
|  | 3599 | dut->non_pref_ch_list = NULL; | 
|  | 3600 | return 0; | 
|  | 3601 | } | 
|  | 3602 | } | 
|  | 3603 |  | 
|  | 3604 | ret = snprintf(buf, sizeof(buf), "SET non_pref_chan%s", | 
|  | 3605 | dut->non_pref_ch_list ? dut->non_pref_ch_list : " "); | 
|  | 3606 | if (ret < 0 || ret >= (int) sizeof(buf)) { | 
|  | 3607 | sigma_dut_print(dut, DUT_MSG_DEBUG, | 
|  | 3608 | "snprintf failed for set non_pref_chan, ret: %d", | 
|  | 3609 | ret); | 
|  | 3610 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,snprint failed"); | 
|  | 3611 | return 0; | 
|  | 3612 | } | 
|  | 3613 |  | 
|  | 3614 | if (wpa_command(intf, buf) < 0) { | 
|  | 3615 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 3616 | "ErrorCode,Failed to set non-preferred channel list"); | 
|  | 3617 | return 0; | 
|  | 3618 | } | 
|  | 3619 |  | 
|  | 3620 | return 1; | 
|  | 3621 | } | 
|  | 3622 |  | 
|  | 3623 |  | 
| Amarnath Hullur Subramanyam | 474a17d | 2018-02-22 18:45:54 -0800 | [diff] [blame] | 3624 | #ifdef NL80211_SUPPORT | 
| Amarnath Hullur Subramanyam | ae8a2d9 | 2018-03-01 06:32:21 -0800 | [diff] [blame] | 3625 |  | 
| Amarnath Hullur Subramanyam | 474a17d | 2018-02-22 18:45:54 -0800 | [diff] [blame] | 3626 | static int sta_set_he_fragmentation(struct sigma_dut *dut, const char *intf, | 
|  | 3627 | enum he_fragmentation_val frag) | 
|  | 3628 | { | 
|  | 3629 | struct nl_msg *msg; | 
|  | 3630 | int ret = 0; | 
|  | 3631 | struct nlattr *params; | 
|  | 3632 | int ifindex; | 
|  | 3633 |  | 
|  | 3634 | ifindex = if_nametoindex(intf); | 
|  | 3635 | if (ifindex == 0) { | 
|  | 3636 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 3637 | "%s: Index for interface %s failed", | 
|  | 3638 | __func__, intf); | 
|  | 3639 | return -1; | 
|  | 3640 | } | 
|  | 3641 |  | 
|  | 3642 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, | 
|  | 3643 | NL80211_CMD_VENDOR)) || | 
|  | 3644 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || | 
|  | 3645 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | 
|  | 3646 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | 
|  | 3647 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || | 
|  | 3648 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | 
|  | 3649 | nla_put_u8(msg, | 
|  | 3650 | QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_FRAGMENTATION, | 
|  | 3651 | frag)) { | 
|  | 3652 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 3653 | "%s: err in adding vendor_cmd and vendor_data", | 
|  | 3654 | __func__); | 
|  | 3655 | nlmsg_free(msg); | 
|  | 3656 | return -1; | 
|  | 3657 | } | 
|  | 3658 | nla_nest_end(msg, params); | 
|  | 3659 |  | 
|  | 3660 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); | 
|  | 3661 | if (ret) { | 
|  | 3662 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 3663 | "%s: err in send_and_recv_msgs, ret=%d", | 
|  | 3664 | __func__, ret); | 
|  | 3665 | } | 
|  | 3666 | return ret; | 
|  | 3667 | } | 
| Amarnath Hullur Subramanyam | ae8a2d9 | 2018-03-01 06:32:21 -0800 | [diff] [blame] | 3668 |  | 
|  | 3669 |  | 
|  | 3670 | static int nlvendor_sta_set_noack(struct sigma_dut *dut, const char *intf, | 
|  | 3671 | int noack, enum qca_wlan_ac_type ac) | 
|  | 3672 | { | 
|  | 3673 | struct nl_msg *msg; | 
|  | 3674 | int ret = 0; | 
|  | 3675 | struct nlattr *params; | 
|  | 3676 | int ifindex; | 
|  | 3677 |  | 
|  | 3678 | ifindex = if_nametoindex(intf); | 
|  | 3679 | if (ifindex == 0) { | 
|  | 3680 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 3681 | "%s: Index for interface %s failed", | 
|  | 3682 | __func__, intf); | 
|  | 3683 | return -1; | 
|  | 3684 | } | 
|  | 3685 |  | 
|  | 3686 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, | 
|  | 3687 | NL80211_CMD_VENDOR)) || | 
|  | 3688 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || | 
|  | 3689 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | 
|  | 3690 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | 
|  | 3691 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || | 
|  | 3692 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | 
|  | 3693 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_NO_ACK, | 
|  | 3694 | noack) || | 
|  | 3695 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_NO_ACK_AC, | 
|  | 3696 | ac)) { | 
|  | 3697 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 3698 | "%s: err in adding vendor_cmd and vendor_data", | 
|  | 3699 | __func__); | 
|  | 3700 | nlmsg_free(msg); | 
|  | 3701 | return -1; | 
|  | 3702 | } | 
|  | 3703 | nla_nest_end(msg, params); | 
|  | 3704 |  | 
|  | 3705 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); | 
|  | 3706 | if (ret) { | 
|  | 3707 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 3708 | "%s: err in send_and_recv_msgs, ret=%d", | 
|  | 3709 | __func__, ret); | 
|  | 3710 | } | 
|  | 3711 | return ret; | 
|  | 3712 | } | 
|  | 3713 |  | 
|  | 3714 |  | 
|  | 3715 | static void wcn_sta_set_noack(struct sigma_dut *dut, const char *intf, | 
|  | 3716 | const char *val) | 
|  | 3717 | { | 
|  | 3718 | int noack, ret; | 
|  | 3719 | char token[100]; | 
|  | 3720 | char *result; | 
|  | 3721 | char *saveptr; | 
|  | 3722 | enum qca_wlan_ac_type ac = QCA_WLAN_AC_BE; | 
|  | 3723 |  | 
|  | 3724 | strlcpy(token, val, sizeof(token)); | 
|  | 3725 | token[sizeof(token) - 1] = '\0'; | 
|  | 3726 | result = strtok_r(token, ":", &saveptr); | 
|  | 3727 | while (result) { | 
|  | 3728 | noack = strcasecmp(result, "Disable") != 0; | 
|  | 3729 | ret = nlvendor_sta_set_noack(dut, intf, noack, ac); | 
|  | 3730 | if (ret) { | 
|  | 3731 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 3732 | "nlvendor_sta_set_noack failed for ac:%d, ret:%d", | 
|  | 3733 | ac, ret); | 
|  | 3734 | } | 
|  | 3735 | result = strtok_r(NULL, ":", &saveptr); | 
|  | 3736 | ac++; | 
|  | 3737 | } | 
|  | 3738 | } | 
|  | 3739 |  | 
| Amarnath Hullur Subramanyam | 474a17d | 2018-02-22 18:45:54 -0800 | [diff] [blame] | 3740 | #endif /* NL80211_SUPPORT */ | 
|  | 3741 |  | 
|  | 3742 |  | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3743 | static int cmd_sta_preset_testparameters(struct sigma_dut *dut, | 
|  | 3744 | struct sigma_conn *conn, | 
|  | 3745 | struct sigma_cmd *cmd) | 
|  | 3746 | { | 
|  | 3747 | const char *intf = get_param(cmd, "Interface"); | 
|  | 3748 | const char *val; | 
|  | 3749 |  | 
|  | 3750 | val = get_param(cmd, "Program"); | 
| Peng Xu | e9fa795 | 2017-05-09 15:59:49 -0700 | [diff] [blame] | 3751 | if (val && strcasecmp(val, "HS2-R2") == 0) | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3752 | return cmd_sta_preset_testparameters_hs2_r2(dut, conn, intf, | 
|  | 3753 | cmd); | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3754 |  | 
| priyadharshini gowthaman | d66913a | 2016-07-29 15:11:17 -0700 | [diff] [blame] | 3755 | if (val && strcasecmp(val, "LOC") == 0) | 
|  | 3756 | return loc_cmd_sta_preset_testparameters(dut, conn, cmd); | 
|  | 3757 |  | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3758 | #ifdef ANDROID_NAN | 
|  | 3759 | if (val && strcasecmp(val, "NAN") == 0) | 
|  | 3760 | return nan_cmd_sta_preset_testparameters(dut, conn, cmd); | 
|  | 3761 | #endif /* ANDROID_NAN */ | 
| Amarnath Hullur Subramanyam | 9c381f5 | 2017-03-17 00:04:41 -0700 | [diff] [blame] | 3762 | #ifdef MIRACAST | 
|  | 3763 | if (val && (strcasecmp(val, "WFD") == 0 || | 
|  | 3764 | strcasecmp(val, "DisplayR2") == 0)) | 
|  | 3765 | return miracast_preset_testparameters(dut, conn, cmd); | 
|  | 3766 | #endif /* MIRACAST */ | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3767 |  | 
| Ashwini Patil | 68d02cd | 2017-01-10 15:39:16 +0530 | [diff] [blame] | 3768 | if (val && strcasecmp(val, "MBO") == 0) { | 
|  | 3769 | val = get_param(cmd, "Cellular_Data_Cap"); | 
|  | 3770 | if (val && | 
|  | 3771 | mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0) | 
|  | 3772 | return 0; | 
| Ashwini Patil | 0040258 | 2017-04-13 12:29:39 +0530 | [diff] [blame] | 3773 |  | 
|  | 3774 | val = get_param(cmd, "Ch_Pref"); | 
|  | 3775 | if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0) | 
|  | 3776 | return 0; | 
|  | 3777 |  | 
| Ashwini Patil | c63161e | 2017-04-13 16:30:23 +0530 | [diff] [blame] | 3778 | val = get_param(cmd, "BSS_Transition"); | 
|  | 3779 | if (val && mbo_set_bss_trans_req(dut, conn, intf, val) == 0) | 
|  | 3780 | return 0; | 
|  | 3781 |  | 
| Ashwini Patil | a75de5a | 2017-04-13 16:35:05 +0530 | [diff] [blame] | 3782 | val = get_param(cmd, "Assoc_Disallow"); | 
|  | 3783 | if (val && mbo_set_assoc_disallow(dut, conn, intf, val) == 0) | 
|  | 3784 | return 0; | 
|  | 3785 |  | 
| Ashwini Patil | 9183fdb | 2017-04-13 16:58:25 +0530 | [diff] [blame] | 3786 | val = get_param(cmd, "Roaming"); | 
|  | 3787 | if (val && mbo_set_roaming(dut, conn, intf, val) == 0) | 
|  | 3788 | return 0; | 
|  | 3789 |  | 
| Ashwini Patil | 68d02cd | 2017-01-10 15:39:16 +0530 | [diff] [blame] | 3790 | return 1; | 
|  | 3791 | } | 
|  | 3792 |  | 
| Ankita Bajaj | a2cb567 | 2017-10-25 16:08:28 +0530 | [diff] [blame] | 3793 | if (val && strcasecmp(val, "OCE") == 0) | 
|  | 3794 | return cmd_sta_preset_testparameters_oce(dut, conn, intf, cmd); | 
|  | 3795 |  | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3796 | #if 0 | 
|  | 3797 | val = get_param(cmd, "Supplicant"); | 
|  | 3798 | if (val && strcasecmp(val, "Default") != 0) { | 
|  | 3799 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 3800 | "ErrorCode,Only default(Vendor) supplicant " | 
|  | 3801 | "supported"); | 
|  | 3802 | return 0; | 
|  | 3803 | } | 
|  | 3804 | #endif | 
|  | 3805 |  | 
|  | 3806 | val = get_param(cmd, "RTS"); | 
|  | 3807 | if (val) { | 
|  | 3808 | switch (get_driver_type()) { | 
|  | 3809 | case DRIVER_ATHEROS: | 
|  | 3810 | ath_sta_set_rts(dut, intf, val); | 
|  | 3811 | break; | 
|  | 3812 | default: | 
|  | 3813 | #if 0 | 
|  | 3814 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 3815 | "ErrorCode,Setting RTS not supported"); | 
|  | 3816 | return 0; | 
|  | 3817 | #else | 
|  | 3818 | sigma_dut_print(dut, DUT_MSG_DEBUG, | 
|  | 3819 | "Setting RTS not supported"); | 
|  | 3820 | break; | 
|  | 3821 | #endif | 
|  | 3822 | } | 
|  | 3823 | } | 
|  | 3824 |  | 
|  | 3825 | #if 0 | 
|  | 3826 | val = get_param(cmd, "FRGMNT"); | 
|  | 3827 | if (val) { | 
|  | 3828 | /* TODO */ | 
|  | 3829 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 3830 | "ErrorCode,Setting FRGMNT not supported"); | 
|  | 3831 | return 0; | 
|  | 3832 | } | 
|  | 3833 | #endif | 
|  | 3834 |  | 
|  | 3835 | #if 0 | 
|  | 3836 | val = get_param(cmd, "Preamble"); | 
|  | 3837 | if (val) { | 
|  | 3838 | /* TODO: Long/Short */ | 
|  | 3839 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 3840 | "ErrorCode,Setting Preamble not supported"); | 
|  | 3841 | return 0; | 
|  | 3842 | } | 
|  | 3843 | #endif | 
|  | 3844 |  | 
|  | 3845 | val = get_param(cmd, "Mode"); | 
|  | 3846 | if (val) { | 
|  | 3847 | if (strcmp(val, "11b") == 0 || | 
|  | 3848 | strcmp(val, "11g") == 0 || | 
|  | 3849 | strcmp(val, "11a") == 0 || | 
|  | 3850 | strcmp(val, "11n") == 0 || | 
|  | 3851 | strcmp(val, "11ng") == 0 || | 
|  | 3852 | strcmp(val, "11nl") == 0 || | 
|  | 3853 | strcmp(val, "11nl(nabg)") == 0 || | 
|  | 3854 | strcmp(val, "AC") == 0 || | 
|  | 3855 | strcmp(val, "11AC") == 0 || | 
|  | 3856 | strcmp(val, "11ac") == 0 || | 
|  | 3857 | strcmp(val, "11na") == 0 || | 
| Amarnath Hullur Subramanyam | b0db271 | 2018-01-30 19:40:35 -0800 | [diff] [blame] | 3858 | strcmp(val, "11an") == 0 || | 
|  | 3859 | strcmp(val, "11ax") == 0) { | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3860 | /* STA supports all modes by default */ | 
|  | 3861 | } else { | 
|  | 3862 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 3863 | "ErrorCode,Setting Mode not supported"); | 
|  | 3864 | return 0; | 
|  | 3865 | } | 
| Amarnath Hullur Subramanyam | 97d0e53 | 2018-01-31 02:53:02 -0800 | [diff] [blame] | 3866 |  | 
|  | 3867 | /* Change the mode only in case of testbed for HE program | 
|  | 3868 | * and for 11a and 11g modes only. */ | 
|  | 3869 | if (dut->program == PROGRAM_HE && | 
|  | 3870 | dut->device_type == STA_testbed) { | 
|  | 3871 | int phymode; | 
|  | 3872 | char buf[60]; | 
|  | 3873 |  | 
|  | 3874 | if (strcmp(val, "11a") == 0) { | 
| Amarnath Hullur Subramanyam | 94dfaf0 | 2018-03-02 19:26:57 -0800 | [diff] [blame] | 3875 | phymode = 1; /* IEEE80211_MODE_11A */ | 
|  | 3876 | } else if (strcmp(val, "11g") == 0) { | 
|  | 3877 | phymode = 3; /* IEEE80211_MODE_11G */ | 
|  | 3878 | } else if (strcmp(val, "11b") == 0) { | 
|  | 3879 | phymode = 2; /* IEEE80211_MODE_11B */ | 
|  | 3880 | } else if (strcmp(val, "11n") == 0 || | 
|  | 3881 | strcmp(val, "11nl") == 0 || | 
|  | 3882 | strcmp(val, "11nl(nabg)") == 0) { | 
|  | 3883 | phymode = 22; /* IEEE80211_MODE_11AGN */ | 
|  | 3884 | } else if (strcmp(val, "11ng") == 0) { | 
|  | 3885 | phymode = 13; /* IEEE80211_MODE_11NG_HT40 */ | 
|  | 3886 | } else if (strcmp(val, "AC") == 0 || | 
|  | 3887 | strcasecmp(val, "11AC") == 0) { | 
|  | 3888 | phymode = 19; /* IEEE80211_MODE_11AC_VHT80 */ | 
|  | 3889 | } else if (strcmp(val, "11na") == 0 || | 
|  | 3890 | strcasecmp(val, "11an") == 0) { | 
|  | 3891 | phymode = 14; /* IEEE80211_MODE_11NA_HT40 */ | 
|  | 3892 | } else if (strcmp(val, "11ax") == 0) { | 
|  | 3893 | phymode = 0; /* IEEE80211_MODE_AUTO */ | 
| Amarnath Hullur Subramanyam | 97d0e53 | 2018-01-31 02:53:02 -0800 | [diff] [blame] | 3894 | } else { | 
|  | 3895 | sigma_dut_print(dut, DUT_MSG_DEBUG, | 
|  | 3896 | "Ignoring mode change for mode: %s", | 
|  | 3897 | val); | 
|  | 3898 | phymode = -1; | 
|  | 3899 | } | 
|  | 3900 | if (phymode != -1) { | 
|  | 3901 | snprintf(buf, sizeof(buf), | 
|  | 3902 | "iwpriv %s setphymode %d", | 
|  | 3903 | intf, phymode); | 
|  | 3904 | if (system(buf) != 0) { | 
|  | 3905 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 3906 | "iwpriv setting of phymode failed"); | 
|  | 3907 | } | 
|  | 3908 | } | 
|  | 3909 | } | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3910 | } | 
|  | 3911 |  | 
|  | 3912 | val = get_param(cmd, "wmm"); | 
|  | 3913 | if (val) { | 
|  | 3914 | switch (get_driver_type()) { | 
|  | 3915 | case DRIVER_ATHEROS: | 
|  | 3916 | ath_sta_set_wmm(dut, intf, val); | 
|  | 3917 | break; | 
| Amarnath Hullur Subramanyam | 75214d2 | 2018-02-04 19:17:11 -0800 | [diff] [blame] | 3918 | case DRIVER_WCN: | 
|  | 3919 | wcn_sta_set_wmm(dut, intf, val); | 
|  | 3920 | break; | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3921 | default: | 
|  | 3922 | sigma_dut_print(dut, DUT_MSG_DEBUG, | 
|  | 3923 | "Setting wmm not supported"); | 
|  | 3924 | break; | 
|  | 3925 | } | 
|  | 3926 | } | 
|  | 3927 |  | 
|  | 3928 | val = get_param(cmd, "Powersave"); | 
|  | 3929 | if (val) { | 
|  | 3930 | if (strcmp(val, "0") == 0 || strcasecmp(val, "off") == 0) { | 
|  | 3931 | if (wpa_command(get_station_ifname(), | 
|  | 3932 | "P2P_SET ps 0") < 0) | 
|  | 3933 | return -2; | 
|  | 3934 | /* Make sure test modes are disabled */ | 
|  | 3935 | wpa_command(get_station_ifname(), "P2P_SET ps 98"); | 
|  | 3936 | wpa_command(get_station_ifname(), "P2P_SET ps 96"); | 
|  | 3937 | } else if (strcmp(val, "1") == 0 || | 
|  | 3938 | strcasecmp(val, "PSPoll") == 0 || | 
|  | 3939 | strcasecmp(val, "on") == 0) { | 
|  | 3940 | /* Disable default power save mode */ | 
|  | 3941 | wpa_command(get_station_ifname(), "P2P_SET ps 0"); | 
|  | 3942 | /* Enable PS-Poll test mode */ | 
|  | 3943 | if (wpa_command(get_station_ifname(), | 
|  | 3944 | "P2P_SET ps 97") < 0 || | 
|  | 3945 | wpa_command(get_station_ifname(), | 
|  | 3946 | "P2P_SET ps 99") < 0) | 
|  | 3947 | return -2; | 
|  | 3948 | } else if (strcmp(val, "2") == 0 || | 
|  | 3949 | strcasecmp(val, "Fast") == 0) { | 
|  | 3950 | /* TODO */ | 
|  | 3951 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 3952 | "ErrorCode,Powersave=Fast not supported"); | 
|  | 3953 | return 0; | 
|  | 3954 | } else if (strcmp(val, "3") == 0 || | 
|  | 3955 | strcasecmp(val, "PSNonPoll") == 0) { | 
|  | 3956 | /* Make sure test modes are disabled */ | 
|  | 3957 | wpa_command(get_station_ifname(), "P2P_SET ps 98"); | 
|  | 3958 | wpa_command(get_station_ifname(), "P2P_SET ps 96"); | 
|  | 3959 |  | 
|  | 3960 | /* Enable default power save mode */ | 
|  | 3961 | if (wpa_command(get_station_ifname(), | 
|  | 3962 | "P2P_SET ps 1") < 0) | 
|  | 3963 | return -2; | 
|  | 3964 | } else | 
|  | 3965 | return -1; | 
|  | 3966 | } | 
|  | 3967 |  | 
|  | 3968 | val = get_param(cmd, "NoAck"); | 
|  | 3969 | if (val) { | 
|  | 3970 | switch (get_driver_type()) { | 
|  | 3971 | case DRIVER_ATHEROS: | 
|  | 3972 | ath_sta_set_noack(dut, intf, val); | 
|  | 3973 | break; | 
| Amarnath Hullur Subramanyam | ae8a2d9 | 2018-03-01 06:32:21 -0800 | [diff] [blame] | 3974 | #ifdef NL80211_SUPPORT | 
|  | 3975 | case DRIVER_WCN: | 
|  | 3976 | wcn_sta_set_noack(dut, intf, val); | 
|  | 3977 | break; | 
|  | 3978 | #endif /* NL80211_SUPPORT */ | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3979 | default: | 
|  | 3980 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 3981 | "ErrorCode,Setting NoAck not supported"); | 
|  | 3982 | return 0; | 
|  | 3983 | } | 
|  | 3984 | } | 
|  | 3985 |  | 
|  | 3986 | val = get_param(cmd, "IgnoreChswitchProhibit"); | 
|  | 3987 | if (val) { | 
|  | 3988 | /* TODO: Enabled/disabled */ | 
|  | 3989 | if (strcasecmp(val, "Enabled") == 0) { | 
|  | 3990 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 3991 | "ErrorCode,Enabling IgnoreChswitchProhibit " | 
|  | 3992 | "not supported"); | 
|  | 3993 | return 0; | 
|  | 3994 | } | 
|  | 3995 | } | 
|  | 3996 |  | 
|  | 3997 | val = get_param(cmd, "TDLS"); | 
|  | 3998 | if (val) { | 
|  | 3999 | if (strcasecmp(val, "Disabled") == 0) { | 
|  | 4000 | if (wpa_command(intf, "SET tdls_disabled 1")) { | 
|  | 4001 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 4002 | "ErrorCode,Failed to disable TDLS"); | 
|  | 4003 | return 0; | 
|  | 4004 | } | 
|  | 4005 | } else if (strcasecmp(val, "Enabled") == 0) { | 
|  | 4006 | if (wpa_command(intf, "SET tdls_disabled 0")) { | 
|  | 4007 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 4008 | "ErrorCode,Failed to enable TDLS"); | 
|  | 4009 | return 0; | 
|  | 4010 | } | 
|  | 4011 | } else { | 
|  | 4012 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 4013 | "ErrorCode,Unsupported TDLS value"); | 
|  | 4014 | return 0; | 
|  | 4015 | } | 
|  | 4016 | } | 
|  | 4017 |  | 
|  | 4018 | val = get_param(cmd, "TDLSmode"); | 
|  | 4019 | if (val) { | 
|  | 4020 | if (strcasecmp(val, "Default") == 0) { | 
|  | 4021 | wpa_command(intf, "SET tdls_testing 0"); | 
|  | 4022 | } else if (strcasecmp(val, "APProhibit") == 0) { | 
|  | 4023 | if (wpa_command(intf, "SET tdls_testing 0x400")) { | 
|  | 4024 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 4025 | "ErrorCode,Failed to enable ignore " | 
|  | 4026 | "APProhibit TDLS mode"); | 
|  | 4027 | return 0; | 
|  | 4028 | } | 
|  | 4029 | } else if (strcasecmp(val, "HiLoMac") == 0) { | 
|  | 4030 | /* STA should respond with TDLS setup req for a TDLS | 
|  | 4031 | * setup req */ | 
|  | 4032 | if (wpa_command(intf, "SET tdls_testing 0x80")) { | 
|  | 4033 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 4034 | "ErrorCode,Failed to enable HiLoMac " | 
|  | 4035 | "TDLS mode"); | 
|  | 4036 | return 0; | 
|  | 4037 | } | 
|  | 4038 | } else if (strcasecmp(val, "WeakSecurity") == 0) { | 
|  | 4039 | /* | 
|  | 4040 | * Since all security modes are enabled by default when | 
|  | 4041 | * Sigma control is used, there is no need to do | 
|  | 4042 | * anything here. | 
|  | 4043 | */ | 
|  | 4044 | } else if (strcasecmp(val, "ExistLink") == 0) { | 
|  | 4045 | /* | 
|  | 4046 | * Since we allow new TDLS Setup Request even if there | 
|  | 4047 | * is an existing link, nothing needs to be done for | 
|  | 4048 | * this. | 
|  | 4049 | */ | 
|  | 4050 | } else { | 
|  | 4051 | /* TODO: | 
|  | 4052 | * ExistLink: STA should send TDLS setup req even if | 
|  | 4053 | * direct link already exists | 
|  | 4054 | */ | 
|  | 4055 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 4056 | "ErrorCode,Unsupported TDLSmode value"); | 
|  | 4057 | return 0; | 
|  | 4058 | } | 
|  | 4059 | } | 
|  | 4060 |  | 
|  | 4061 | val = get_param(cmd, "FakePubKey"); | 
|  | 4062 | if (val && atoi(val) && wpa_command(intf, "SET wps_corrupt_pkhash 1")) { | 
|  | 4063 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 4064 | "ErrorCode,Failed to enable FakePubKey"); | 
|  | 4065 | return 0; | 
|  | 4066 | } | 
|  | 4067 |  | 
| Amarnath Hullur Subramanyam | ae1042b | 2018-02-22 21:52:52 -0800 | [diff] [blame] | 4068 | #ifdef NL80211_SUPPORT | 
|  | 4069 | val = get_param(cmd, "FrgmntSupport"); | 
|  | 4070 | if (val) { | 
|  | 4071 | if (strcasecmp(val, "Enable") == 0) { | 
|  | 4072 | if (sta_set_he_fragmentation(dut, intf, | 
|  | 4073 | HE_FRAG_LEVEL1)) { | 
|  | 4074 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 4075 | "ErrorCode,Failed to enable HE Fragmentation"); | 
|  | 4076 | return 0; | 
|  | 4077 | } | 
|  | 4078 | } else if (strcasecmp(val, "Disable") == 0) { | 
|  | 4079 | if (sta_set_he_fragmentation(dut, intf, | 
|  | 4080 | HE_FRAG_DISABLE)) { | 
|  | 4081 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 4082 | "ErrorCode,Failed to disable HE Fragmentation"); | 
|  | 4083 | return 0; | 
|  | 4084 | } | 
|  | 4085 | } | 
|  | 4086 | } | 
|  | 4087 | #endif /* NL80211_SUPPORT */ | 
|  | 4088 |  | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4089 | return 1; | 
|  | 4090 | } | 
|  | 4091 |  | 
|  | 4092 |  | 
|  | 4093 | static const char * ath_get_radio_name(const char *radio_name) | 
|  | 4094 | { | 
|  | 4095 | if (radio_name == NULL) | 
|  | 4096 | return "wifi0"; | 
|  | 4097 | if (strcmp(radio_name, "wifi1") == 0) | 
|  | 4098 | return "wifi1"; | 
|  | 4099 | if (strcmp(radio_name, "wifi2") == 0) | 
|  | 4100 | return "wifi2"; | 
|  | 4101 | return "wifi0"; | 
|  | 4102 | } | 
|  | 4103 |  | 
|  | 4104 |  | 
|  | 4105 | static void ath_sta_set_txsp_stream(struct sigma_dut *dut, const char *intf, | 
|  | 4106 | const char *val) | 
|  | 4107 | { | 
|  | 4108 | char buf[60]; | 
|  | 4109 | unsigned int vht_mcsmap = 0; | 
|  | 4110 | int txchainmask = 0; | 
|  | 4111 | const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]); | 
|  | 4112 |  | 
|  | 4113 | if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) { | 
|  | 4114 | if (dut->testbed_flag_txsp == 1) { | 
|  | 4115 | vht_mcsmap = 0xfffc; | 
|  | 4116 | dut->testbed_flag_txsp = 0; | 
|  | 4117 | } else { | 
|  | 4118 | vht_mcsmap = 0xfffe; | 
|  | 4119 | } | 
|  | 4120 | txchainmask = 1; | 
|  | 4121 | } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) { | 
|  | 4122 | if (dut->testbed_flag_txsp == 1) { | 
|  | 4123 | vht_mcsmap = 0xfff0; | 
|  | 4124 | dut->testbed_flag_txsp = 0; | 
|  | 4125 | } else { | 
|  | 4126 | vht_mcsmap = 0xfffa; | 
|  | 4127 | } | 
|  | 4128 | txchainmask = 3; | 
|  | 4129 | } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) { | 
|  | 4130 | if (dut->testbed_flag_txsp == 1) { | 
|  | 4131 | vht_mcsmap = 0xffc0; | 
|  | 4132 | dut->testbed_flag_txsp = 0; | 
|  | 4133 | } else { | 
|  | 4134 | vht_mcsmap = 0xffea; | 
|  | 4135 | } | 
|  | 4136 | txchainmask = 7; | 
|  | 4137 | } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) { | 
|  | 4138 | if (dut->testbed_flag_txsp == 1) { | 
|  | 4139 | vht_mcsmap = 0xff00; | 
|  | 4140 | dut->testbed_flag_txsp = 0; | 
|  | 4141 | } else { | 
|  | 4142 | vht_mcsmap = 0xffaa; | 
|  | 4143 | } | 
|  | 4144 | txchainmask = 15; | 
|  | 4145 | } else { | 
|  | 4146 | if (dut->testbed_flag_txsp == 1) { | 
|  | 4147 | vht_mcsmap = 0xffc0; | 
|  | 4148 | dut->testbed_flag_txsp = 0; | 
|  | 4149 | } else { | 
|  | 4150 | vht_mcsmap = 0xffea; | 
|  | 4151 | } | 
|  | 4152 | } | 
|  | 4153 |  | 
|  | 4154 | if (txchainmask) { | 
|  | 4155 | snprintf(buf, sizeof(buf), "iwpriv %s txchainmask %d", | 
|  | 4156 | basedev, txchainmask); | 
|  | 4157 | if (system(buf) != 0) { | 
|  | 4158 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 4159 | "iwpriv txchainmask failed"); | 
|  | 4160 | } | 
|  | 4161 | } | 
|  | 4162 |  | 
|  | 4163 | snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0x%04x", | 
|  | 4164 | intf, vht_mcsmap); | 
|  | 4165 | if (system(buf) != 0) { | 
|  | 4166 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 4167 | "iwpriv %s vht_mcsmap 0x%04x failed", | 
|  | 4168 | intf, vht_mcsmap); | 
|  | 4169 | } | 
|  | 4170 | } | 
|  | 4171 |  | 
|  | 4172 |  | 
|  | 4173 | static void ath_sta_set_rxsp_stream(struct sigma_dut *dut, const char *intf, | 
|  | 4174 | const char *val) | 
|  | 4175 | { | 
|  | 4176 | char buf[60]; | 
|  | 4177 | unsigned int vht_mcsmap = 0; | 
|  | 4178 | int rxchainmask = 0; | 
|  | 4179 | const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]); | 
|  | 4180 |  | 
|  | 4181 | if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) { | 
|  | 4182 | if (dut->testbed_flag_rxsp == 1) { | 
|  | 4183 | vht_mcsmap = 0xfffc; | 
|  | 4184 | dut->testbed_flag_rxsp = 0; | 
|  | 4185 | } else { | 
|  | 4186 | vht_mcsmap = 0xfffe; | 
|  | 4187 | } | 
|  | 4188 | rxchainmask = 1; | 
|  | 4189 | } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) { | 
|  | 4190 | if (dut->testbed_flag_rxsp == 1) { | 
|  | 4191 | vht_mcsmap = 0xfff0; | 
|  | 4192 | dut->testbed_flag_rxsp = 0; | 
|  | 4193 | } else { | 
|  | 4194 | vht_mcsmap = 0xfffa; | 
|  | 4195 | } | 
|  | 4196 | rxchainmask = 3; | 
|  | 4197 | } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) { | 
|  | 4198 | if (dut->testbed_flag_rxsp == 1) { | 
|  | 4199 | vht_mcsmap = 0xffc0; | 
|  | 4200 | dut->testbed_flag_rxsp = 0; | 
|  | 4201 | } else { | 
|  | 4202 | vht_mcsmap = 0xffea; | 
|  | 4203 | } | 
|  | 4204 | rxchainmask = 7; | 
|  | 4205 | } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) { | 
|  | 4206 | if (dut->testbed_flag_rxsp == 1) { | 
|  | 4207 | vht_mcsmap = 0xff00; | 
|  | 4208 | dut->testbed_flag_rxsp = 0; | 
|  | 4209 | } else { | 
|  | 4210 | vht_mcsmap = 0xffaa; | 
|  | 4211 | } | 
|  | 4212 | rxchainmask = 15; | 
|  | 4213 | } else { | 
|  | 4214 | if (dut->testbed_flag_rxsp == 1) { | 
|  | 4215 | vht_mcsmap = 0xffc0; | 
|  | 4216 | dut->testbed_flag_rxsp = 0; | 
|  | 4217 | } else { | 
|  | 4218 | vht_mcsmap = 0xffea; | 
|  | 4219 | } | 
|  | 4220 | } | 
|  | 4221 |  | 
|  | 4222 | if (rxchainmask) { | 
|  | 4223 | snprintf(buf, sizeof(buf), "iwpriv %s rxchainmask %d", | 
|  | 4224 | basedev, rxchainmask); | 
|  | 4225 | if (system(buf) != 0) { | 
|  | 4226 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 4227 | "iwpriv rxchainmask failed"); | 
|  | 4228 | } | 
|  | 4229 | } | 
|  | 4230 |  | 
|  | 4231 | snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0x%04x", | 
|  | 4232 | intf, vht_mcsmap); | 
|  | 4233 | if (system(buf) != 0) { | 
|  | 4234 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 4235 | "iwpriv %s vht_mcsmap 0x%04x", | 
|  | 4236 | intf, vht_mcsmap); | 
|  | 4237 | } | 
|  | 4238 | } | 
|  | 4239 |  | 
|  | 4240 |  | 
|  | 4241 | void ath_set_zero_crc(struct sigma_dut *dut, const char *val) | 
|  | 4242 | { | 
|  | 4243 | if (strcasecmp(val, "enable") == 0) { | 
|  | 4244 | if (system("athdiag --set --address=0x2a204 --and=0xbfffffff") | 
|  | 4245 | != 0) { | 
|  | 4246 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 4247 | "Disable BB_VHTSIGB_CRC_CALC failed"); | 
|  | 4248 | } | 
|  | 4249 |  | 
|  | 4250 | if (system("athdiag --set --address=0x2a204 --or=0x80000000") | 
|  | 4251 | != 0) { | 
|  | 4252 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 4253 | "Enable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed"); | 
|  | 4254 | } | 
|  | 4255 | } else { | 
|  | 4256 | if (system("athdiag --set --address=0x2a204 --and=0x7fffffff") | 
|  | 4257 | != 0) { | 
|  | 4258 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 4259 | "Disable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed"); | 
|  | 4260 | } | 
|  | 4261 |  | 
|  | 4262 | if (system("athdiag --set --address=0x2a204 --or=0x40000000") | 
|  | 4263 | != 0) { | 
|  | 4264 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 4265 | "Enable BB_VHTSIGB_CRC_CALC failed"); | 
|  | 4266 | } | 
|  | 4267 | } | 
|  | 4268 | } | 
|  | 4269 |  | 
|  | 4270 |  | 
| Amarnath Hullur Subramanyam | ebfe6b6 | 2018-01-31 03:04:17 -0800 | [diff] [blame] | 4271 | static int wcn_sta_set_width(struct sigma_dut *dut, const char *intf, | 
|  | 4272 | const char *val) | 
|  | 4273 | { | 
|  | 4274 | char buf[60]; | 
|  | 4275 |  | 
|  | 4276 | if (strcmp(val, "20") == 0) { | 
|  | 4277 | snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf); | 
|  | 4278 | dut->chwidth = 0; | 
|  | 4279 | } else if (strcmp(val, "40") == 0) { | 
|  | 4280 | snprintf(buf, sizeof(buf), "iwpriv %s chwidth 1", intf); | 
|  | 4281 | dut->chwidth = 1; | 
|  | 4282 | } else if (strcmp(val, "80") == 0) { | 
|  | 4283 | snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf); | 
|  | 4284 | dut->chwidth = 2; | 
|  | 4285 | } else if (strcmp(val, "Auto") == 0) { | 
|  | 4286 | buf[0] = '\0'; | 
|  | 4287 | } else { | 
|  | 4288 | sigma_dut_print(dut, DUT_MSG_ERROR, "WIDTH %s not supported", | 
|  | 4289 | val); | 
|  | 4290 | return -1; | 
|  | 4291 | } | 
|  | 4292 |  | 
|  | 4293 | if (buf[0] != '\0' && system(buf) != 0) { | 
|  | 4294 | sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv chwidth failed"); | 
|  | 4295 | return -1; | 
|  | 4296 | } | 
|  | 4297 |  | 
|  | 4298 | return 0; | 
|  | 4299 | } | 
|  | 4300 |  | 
|  | 4301 |  | 
| Amarnath Hullur Subramanyam | d8a9db9 | 2018-02-02 18:53:14 -0800 | [diff] [blame] | 4302 | static int nlvendor_sta_set_addba_reject(struct sigma_dut *dut, | 
|  | 4303 | const char *intf, int addbareject) | 
|  | 4304 | { | 
|  | 4305 | #ifdef NL80211_SUPPORT | 
|  | 4306 | struct nl_msg *msg; | 
|  | 4307 | int ret = 0; | 
|  | 4308 | struct nlattr *params; | 
|  | 4309 | int ifindex; | 
|  | 4310 |  | 
|  | 4311 | ifindex = if_nametoindex(intf); | 
|  | 4312 | if (ifindex == 0) { | 
|  | 4313 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 4314 | "%s: Index for interface %s failed", | 
|  | 4315 | __func__, intf); | 
|  | 4316 | return -1; | 
|  | 4317 | } | 
|  | 4318 |  | 
|  | 4319 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, | 
|  | 4320 | NL80211_CMD_VENDOR)) || | 
|  | 4321 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || | 
|  | 4322 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | 
|  | 4323 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | 
|  | 4324 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || | 
|  | 4325 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | 
|  | 4326 | nla_put_u8(msg, | 
|  | 4327 | QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ACCEPT_ADDBA_REQ, | 
|  | 4328 | !addbareject)) { | 
|  | 4329 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 4330 | "%s: err in adding vendor_cmd and vendor_data", | 
|  | 4331 | __func__); | 
|  | 4332 | nlmsg_free(msg); | 
|  | 4333 | return -1; | 
|  | 4334 | } | 
|  | 4335 | nla_nest_end(msg, params); | 
|  | 4336 |  | 
|  | 4337 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); | 
|  | 4338 | if (ret) { | 
|  | 4339 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 4340 | "%s: err in send_and_recv_msgs, ret=%d", | 
|  | 4341 | __func__, ret); | 
|  | 4342 | } | 
|  | 4343 | return ret; | 
|  | 4344 | #else /* NL80211_SUPPORT */ | 
|  | 4345 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 4346 | "ADDBA_REJECT cannot be set without NL80211_SUPPORT defined"); | 
|  | 4347 | return -1; | 
|  | 4348 | #endif /* NL80211_SUPPORT */ | 
|  | 4349 | } | 
|  | 4350 |  | 
|  | 4351 |  | 
|  | 4352 | static int sta_set_addba_reject(struct sigma_dut *dut, const char *intf, | 
|  | 4353 | int addbareject) | 
|  | 4354 | { | 
|  | 4355 | int ret; | 
|  | 4356 |  | 
|  | 4357 | switch (get_driver_type()) { | 
|  | 4358 | case DRIVER_WCN: | 
|  | 4359 | ret = nlvendor_sta_set_addba_reject(dut, intf, addbareject); | 
|  | 4360 | if (ret) { | 
|  | 4361 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 4362 | "nlvendor_sta_set_addba_reject failed, ret:%d", | 
|  | 4363 | ret); | 
|  | 4364 | return ret; | 
|  | 4365 | } | 
|  | 4366 | break; | 
|  | 4367 | default: | 
|  | 4368 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 4369 | "errorCode,Unsupported ADDBA_REJECT with the current driver"); | 
|  | 4370 | ret = -1; | 
|  | 4371 | break; | 
|  | 4372 | } | 
|  | 4373 |  | 
|  | 4374 | return ret; | 
|  | 4375 | } | 
|  | 4376 |  | 
|  | 4377 |  | 
| Amarnath Hullur Subramanyam | 1f65a67 | 2018-03-07 14:50:29 -0800 | [diff] [blame] | 4378 | static int nlvendor_config_send_addba(struct sigma_dut *dut, const char *intf, | 
|  | 4379 | int enable) | 
| Amarnath Hullur Subramanyam | 9745b3c | 2018-02-04 21:27:57 -0800 | [diff] [blame] | 4380 | { | 
|  | 4381 | #ifdef NL80211_SUPPORT | 
|  | 4382 | struct nl_msg *msg; | 
|  | 4383 | int ret = 0; | 
|  | 4384 | struct nlattr *params; | 
|  | 4385 | int ifindex; | 
|  | 4386 |  | 
|  | 4387 | ifindex = if_nametoindex(intf); | 
|  | 4388 | if (ifindex == 0) { | 
|  | 4389 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 4390 | "%s: Index for interface %s failed", | 
|  | 4391 | __func__, intf); | 
|  | 4392 | return -1; | 
|  | 4393 | } | 
|  | 4394 |  | 
|  | 4395 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, | 
|  | 4396 | NL80211_CMD_VENDOR)) || | 
|  | 4397 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || | 
|  | 4398 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | 
|  | 4399 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | 
|  | 4400 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || | 
|  | 4401 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | 
|  | 4402 | nla_put_u8(msg, | 
|  | 4403 | QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SEND_ADDBA_REQ, | 
| Amarnath Hullur Subramanyam | 1f65a67 | 2018-03-07 14:50:29 -0800 | [diff] [blame] | 4404 | enable)) { | 
| Amarnath Hullur Subramanyam | 9745b3c | 2018-02-04 21:27:57 -0800 | [diff] [blame] | 4405 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 4406 | "%s: err in adding vendor_cmd and vendor_data", | 
|  | 4407 | __func__); | 
|  | 4408 | nlmsg_free(msg); | 
|  | 4409 | return -1; | 
|  | 4410 | } | 
|  | 4411 | nla_nest_end(msg, params); | 
|  | 4412 |  | 
|  | 4413 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); | 
|  | 4414 | if (ret) { | 
|  | 4415 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 4416 | "%s: err in send_and_recv_msgs, ret=%d", | 
|  | 4417 | __func__, ret); | 
|  | 4418 | } | 
|  | 4419 | return ret; | 
|  | 4420 | #else /* NL80211_SUPPORT */ | 
|  | 4421 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 4422 | "Disable addba not possible without NL80211_SUPPORT defined"); | 
|  | 4423 | return -1; | 
|  | 4424 | #endif /* NL80211_SUPPORT */ | 
|  | 4425 | } | 
|  | 4426 |  | 
|  | 4427 |  | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4428 | static int cmd_sta_set_wireless_common(const char *intf, struct sigma_dut *dut, | 
|  | 4429 | struct sigma_conn *conn, | 
|  | 4430 | struct sigma_cmd *cmd) | 
|  | 4431 | { | 
|  | 4432 | const char *val; | 
| Amarnath Hullur Subramanyam | d8a9db9 | 2018-02-02 18:53:14 -0800 | [diff] [blame] | 4433 | int ampdu = -1, addbareject = -1; | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4434 | char buf[30]; | 
|  | 4435 |  | 
|  | 4436 | val = get_param(cmd, "40_INTOLERANT"); | 
|  | 4437 | if (val) { | 
|  | 4438 | if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) { | 
|  | 4439 | /* TODO: iwpriv ht40intol through wpa_supplicant */ | 
|  | 4440 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 4441 | "ErrorCode,40_INTOLERANT not supported"); | 
|  | 4442 | return 0; | 
|  | 4443 | } | 
|  | 4444 | } | 
|  | 4445 |  | 
|  | 4446 | val = get_param(cmd, "ADDBA_REJECT"); | 
|  | 4447 | if (val) { | 
|  | 4448 | if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) { | 
|  | 4449 | /* reject any ADDBA with status "decline" */ | 
|  | 4450 | ampdu = 0; | 
| Amarnath Hullur Subramanyam | d8a9db9 | 2018-02-02 18:53:14 -0800 | [diff] [blame] | 4451 | addbareject = 1; | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4452 | } else { | 
|  | 4453 | /* accept ADDBA */ | 
|  | 4454 | ampdu = 1; | 
| Amarnath Hullur Subramanyam | d8a9db9 | 2018-02-02 18:53:14 -0800 | [diff] [blame] | 4455 | addbareject = 0; | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4456 | } | 
|  | 4457 | } | 
|  | 4458 |  | 
| Amarnath Hullur Subramanyam | d8a9db9 | 2018-02-02 18:53:14 -0800 | [diff] [blame] | 4459 | if (addbareject >= 0 && | 
|  | 4460 | sta_set_addba_reject(dut, intf, addbareject) < 0) { | 
|  | 4461 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 4462 | "ErrorCode,set addba_reject failed"); | 
|  | 4463 | return 0; | 
|  | 4464 | } | 
|  | 4465 |  | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4466 | val = get_param(cmd, "AMPDU"); | 
|  | 4467 | if (val) { | 
|  | 4468 | if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) { | 
|  | 4469 | /* enable AMPDU Aggregation */ | 
|  | 4470 | if (ampdu == 0) { | 
|  | 4471 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 4472 | "ErrorCode,Mismatch in " | 
|  | 4473 | "addba_reject/ampdu - " | 
|  | 4474 | "not supported"); | 
|  | 4475 | return 0; | 
|  | 4476 | } | 
|  | 4477 | ampdu = 1; | 
|  | 4478 | } else { | 
|  | 4479 | /* disable AMPDU Aggregation */ | 
|  | 4480 | if (ampdu == 1) { | 
|  | 4481 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 4482 | "ErrorCode,Mismatch in " | 
|  | 4483 | "addba_reject/ampdu - " | 
|  | 4484 | "not supported"); | 
|  | 4485 | return 0; | 
|  | 4486 | } | 
|  | 4487 | ampdu = 0; | 
|  | 4488 | } | 
|  | 4489 | } | 
|  | 4490 |  | 
|  | 4491 | if (ampdu >= 0) { | 
| Amarnath Hullur Subramanyam | 9745b3c | 2018-02-04 21:27:57 -0800 | [diff] [blame] | 4492 | int ret; | 
|  | 4493 |  | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4494 | sigma_dut_print(dut, DUT_MSG_DEBUG, "%s A-MPDU aggregation", | 
|  | 4495 | ampdu ? "Enabling" : "Disabling"); | 
|  | 4496 | snprintf(buf, sizeof(buf), "SET ampdu %d", ampdu); | 
| Deepak Dhamdhere | 80356cb | 2016-03-28 16:48:32 -0700 | [diff] [blame] | 4497 | if (wpa_command(intf, buf) < 0 && | 
|  | 4498 | iwpriv_sta_set_ampdu(dut, intf, ampdu) < 0) { | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4499 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 4500 | "ErrorCode,set aggr failed"); | 
|  | 4501 | return 0; | 
|  | 4502 | } | 
| Amarnath Hullur Subramanyam | 9745b3c | 2018-02-04 21:27:57 -0800 | [diff] [blame] | 4503 |  | 
|  | 4504 | if (ampdu == 0) { | 
|  | 4505 | /* Disable sending of addba using nl vendor command */ | 
| Amarnath Hullur Subramanyam | 1f65a67 | 2018-03-07 14:50:29 -0800 | [diff] [blame] | 4506 | ret = nlvendor_config_send_addba(dut, intf, 0); | 
| Amarnath Hullur Subramanyam | 9745b3c | 2018-02-04 21:27:57 -0800 | [diff] [blame] | 4507 | if (ret) { | 
|  | 4508 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 4509 | "Failed to disable addba, ret:%d", | 
|  | 4510 | ret); | 
|  | 4511 | } | 
|  | 4512 | } | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4513 | } | 
|  | 4514 |  | 
|  | 4515 | val = get_param(cmd, "AMSDU"); | 
|  | 4516 | if (val) { | 
|  | 4517 | switch (get_driver_type()) { | 
|  | 4518 | case DRIVER_ATHEROS: | 
| Amarnath Hullur Subramanyam | d5bb573 | 2018-02-22 15:50:38 -0800 | [diff] [blame] | 4519 | case DRIVER_WCN: | 
|  | 4520 | iwpriv_sta_set_amsdu(dut, intf, val); | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4521 | break; | 
|  | 4522 | default: | 
|  | 4523 | if (strcmp(val, "1") == 0 || | 
|  | 4524 | strcasecmp(val, "Enable") == 0) { | 
|  | 4525 | /* Enable AMSDU Aggregation */ | 
|  | 4526 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 4527 | "ErrorCode,AMSDU aggregation not supported"); | 
|  | 4528 | return 0; | 
|  | 4529 | } | 
|  | 4530 | break; | 
|  | 4531 | } | 
|  | 4532 | } | 
|  | 4533 |  | 
|  | 4534 | val = get_param(cmd, "STBC_RX"); | 
|  | 4535 | if (val) { | 
|  | 4536 | switch (get_driver_type()) { | 
|  | 4537 | case DRIVER_ATHEROS: | 
|  | 4538 | ath_sta_set_stbc(dut, intf, val); | 
|  | 4539 | break; | 
| Pradeep Reddy POTTETI | 4a1f6b3 | 2016-11-23 13:15:21 +0530 | [diff] [blame] | 4540 | case DRIVER_WCN: | 
|  | 4541 | wcn_sta_set_stbc(dut, intf, val); | 
|  | 4542 | break; | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4543 | default: | 
|  | 4544 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 4545 | "ErrorCode,STBC_RX not supported"); | 
|  | 4546 | return 0; | 
|  | 4547 | } | 
|  | 4548 | } | 
|  | 4549 |  | 
|  | 4550 | val = get_param(cmd, "WIDTH"); | 
|  | 4551 | if (val) { | 
|  | 4552 | switch (get_driver_type()) { | 
|  | 4553 | case DRIVER_WCN: | 
| Amarnath Hullur Subramanyam | ebfe6b6 | 2018-01-31 03:04:17 -0800 | [diff] [blame] | 4554 | if (wcn_sta_set_width(dut, intf, val) < 0) { | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4555 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 4556 | "ErrorCode,Failed to set WIDTH"); | 
|  | 4557 | return 0; | 
|  | 4558 | } | 
|  | 4559 | break; | 
|  | 4560 | case DRIVER_ATHEROS: | 
|  | 4561 | if (ath_set_width(dut, conn, intf, val) < 0) | 
|  | 4562 | return 0; | 
|  | 4563 | break; | 
|  | 4564 | default: | 
|  | 4565 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 4566 | "Setting WIDTH not supported"); | 
|  | 4567 | break; | 
|  | 4568 | } | 
|  | 4569 | } | 
|  | 4570 |  | 
|  | 4571 | val = get_param(cmd, "SMPS"); | 
|  | 4572 | if (val) { | 
|  | 4573 | /* TODO: Dynamic/0, Static/1, No Limit/2 */ | 
|  | 4574 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 4575 | "ErrorCode,SMPS not supported"); | 
|  | 4576 | return 0; | 
|  | 4577 | } | 
|  | 4578 |  | 
|  | 4579 | val = get_param(cmd, "TXSP_STREAM"); | 
|  | 4580 | if (val) { | 
|  | 4581 | switch (get_driver_type()) { | 
|  | 4582 | case DRIVER_WCN: | 
|  | 4583 | if (wcn_sta_set_sp_stream(dut, intf, val) < 0) { | 
|  | 4584 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 4585 | "ErrorCode,Failed to set TXSP_STREAM"); | 
|  | 4586 | return 0; | 
|  | 4587 | } | 
|  | 4588 | break; | 
|  | 4589 | case DRIVER_ATHEROS: | 
|  | 4590 | ath_sta_set_txsp_stream(dut, intf, val); | 
|  | 4591 | break; | 
|  | 4592 | default: | 
|  | 4593 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 4594 | "Setting TXSP_STREAM not supported"); | 
|  | 4595 | break; | 
|  | 4596 | } | 
|  | 4597 | } | 
|  | 4598 |  | 
|  | 4599 | val = get_param(cmd, "RXSP_STREAM"); | 
|  | 4600 | if (val) { | 
|  | 4601 | switch (get_driver_type()) { | 
|  | 4602 | case DRIVER_WCN: | 
|  | 4603 | if (wcn_sta_set_sp_stream(dut, intf, val) < 0) { | 
|  | 4604 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 4605 | "ErrorCode,Failed to set RXSP_STREAM"); | 
|  | 4606 | return 0; | 
|  | 4607 | } | 
|  | 4608 | break; | 
|  | 4609 | case DRIVER_ATHEROS: | 
|  | 4610 | ath_sta_set_rxsp_stream(dut, intf, val); | 
|  | 4611 | break; | 
|  | 4612 | default: | 
|  | 4613 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 4614 | "Setting RXSP_STREAM not supported"); | 
|  | 4615 | break; | 
|  | 4616 | } | 
|  | 4617 | } | 
|  | 4618 |  | 
|  | 4619 | val = get_param(cmd, "DYN_BW_SGNL"); | 
|  | 4620 | if (val) { | 
| Priyadharshini Gowthaman | 818afef | 2015-11-09 13:28:15 -0800 | [diff] [blame] | 4621 | switch (get_driver_type()) { | 
|  | 4622 | case DRIVER_WCN: | 
| Peng Xu | c59afd3 | 2016-11-21 15:01:11 -0800 | [diff] [blame] | 4623 | if (strcasecmp(val, "enable") == 0) { | 
|  | 4624 | snprintf(buf, sizeof(buf), | 
|  | 4625 | "iwpriv %s cwmenable 1", intf); | 
|  | 4626 | if (system(buf) != 0) { | 
|  | 4627 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 4628 | "iwpriv cwmenable 1 failed"); | 
|  | 4629 | return 0; | 
|  | 4630 | } | 
|  | 4631 | } else if (strcasecmp(val, "disable") == 0) { | 
|  | 4632 | snprintf(buf, sizeof(buf), | 
|  | 4633 | "iwpriv %s cwmenable 0", intf); | 
|  | 4634 | if (system(buf) != 0) { | 
|  | 4635 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 4636 | "iwpriv cwmenable 0 failed"); | 
|  | 4637 | return 0; | 
|  | 4638 | } | 
|  | 4639 | } else { | 
|  | 4640 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 4641 | "Unsupported DYN_BW_SGL"); | 
|  | 4642 | } | 
|  | 4643 |  | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4644 | snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf); | 
|  | 4645 | if (system(buf) != 0) { | 
|  | 4646 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 4647 | "Failed to set cts_cbw in DYN_BW_SGNL"); | 
|  | 4648 | return 0; | 
|  | 4649 | } | 
| Priyadharshini Gowthaman | 818afef | 2015-11-09 13:28:15 -0800 | [diff] [blame] | 4650 | break; | 
|  | 4651 | case DRIVER_ATHEROS: | 
| priyadharshini gowthaman | e5e2517 | 2015-12-08 14:53:48 -0800 | [diff] [blame] | 4652 | novap_reset(dut, intf); | 
| Priyadharshini Gowthaman | 818afef | 2015-11-09 13:28:15 -0800 | [diff] [blame] | 4653 | ath_config_dyn_bw_sig(dut, intf, val); | 
|  | 4654 | break; | 
|  | 4655 | default: | 
|  | 4656 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 4657 | "Failed to set DYN_BW_SGNL"); | 
|  | 4658 | break; | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4659 | } | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4660 | } | 
|  | 4661 |  | 
|  | 4662 | val = get_param(cmd, "RTS_FORCE"); | 
|  | 4663 | if (val) { | 
| priyadharshini gowthaman | e5e2517 | 2015-12-08 14:53:48 -0800 | [diff] [blame] | 4664 | novap_reset(dut, intf); | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4665 | if (strcasecmp(val, "Enable") == 0) { | 
|  | 4666 | snprintf(buf, sizeof(buf), "iwconfig %s rts 64", intf); | 
| Priyadharshini Gowthaman | abdb212 | 2015-11-17 11:52:19 +0200 | [diff] [blame] | 4667 | if (system(buf) != 0) { | 
|  | 4668 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 4669 | "Failed to set RTS_FORCE 64"); | 
|  | 4670 | } | 
| priyadharshini gowthaman | 270870e | 2015-12-09 10:10:23 -0800 | [diff] [blame] | 4671 | snprintf(buf, sizeof(buf), | 
|  | 4672 | "wifitool %s beeliner_fw_test 100 1", intf); | 
|  | 4673 | if (system(buf) != 0) { | 
|  | 4674 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 4675 | "wifitool beeliner_fw_test 100 1 failed"); | 
|  | 4676 | } | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4677 | } else if (strcasecmp(val, "Disable") == 0) { | 
|  | 4678 | snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", | 
|  | 4679 | intf); | 
| Priyadharshini Gowthaman | abdb212 | 2015-11-17 11:52:19 +0200 | [diff] [blame] | 4680 | if (system(buf) != 0) { | 
|  | 4681 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 4682 | "Failed to set RTS_FORCE 2347"); | 
|  | 4683 | } | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4684 | } else { | 
|  | 4685 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 4686 | "ErrorCode,RTS_FORCE value not supported"); | 
|  | 4687 | return 0; | 
|  | 4688 | } | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4689 | } | 
|  | 4690 |  | 
|  | 4691 | val = get_param(cmd, "CTS_WIDTH"); | 
|  | 4692 | if (val) { | 
|  | 4693 | switch (get_driver_type()) { | 
|  | 4694 | case DRIVER_WCN: | 
|  | 4695 | if (wcn_sta_set_cts_width(dut, intf, val) < 0) { | 
|  | 4696 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 4697 | "ErrorCode,Failed to set CTS_WIDTH"); | 
|  | 4698 | return 0; | 
|  | 4699 | } | 
|  | 4700 | break; | 
|  | 4701 | case DRIVER_ATHEROS: | 
|  | 4702 | ath_set_cts_width(dut, intf, val); | 
|  | 4703 | break; | 
|  | 4704 | default: | 
|  | 4705 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 4706 | "Setting CTS_WIDTH not supported"); | 
|  | 4707 | break; | 
|  | 4708 | } | 
|  | 4709 | } | 
|  | 4710 |  | 
|  | 4711 | val = get_param(cmd, "BW_SGNL"); | 
|  | 4712 | if (val) { | 
|  | 4713 | if (strcasecmp(val, "Enable") == 0) { | 
|  | 4714 | snprintf(buf, sizeof(buf), "iwpriv %s cwmenable 1", | 
|  | 4715 | intf); | 
|  | 4716 | } else if (strcasecmp(val, "Disable") == 0) { | 
|  | 4717 | /* TODO: Disable */ | 
|  | 4718 | buf[0] = '\0'; | 
|  | 4719 | } else { | 
|  | 4720 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 4721 | "ErrorCode,BW_SGNL value not supported"); | 
|  | 4722 | return 0; | 
|  | 4723 | } | 
|  | 4724 |  | 
|  | 4725 | if (buf[0] != '\0' && system(buf) != 0) { | 
|  | 4726 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 4727 | "Failed to set BW_SGNL"); | 
|  | 4728 | } | 
|  | 4729 | } | 
|  | 4730 |  | 
|  | 4731 | val = get_param(cmd, "Band"); | 
|  | 4732 | if (val) { | 
|  | 4733 | if (strcmp(val, "2.4") == 0 || strcmp(val, "5") == 0) { | 
|  | 4734 | /* STA supports all bands by default */ | 
|  | 4735 | } else { | 
|  | 4736 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 4737 | "ErrorCode,Unsupported Band"); | 
|  | 4738 | return 0; | 
|  | 4739 | } | 
|  | 4740 | } | 
|  | 4741 |  | 
|  | 4742 | val = get_param(cmd, "zero_crc"); | 
|  | 4743 | if (val) { | 
|  | 4744 | switch (get_driver_type()) { | 
|  | 4745 | case DRIVER_ATHEROS: | 
|  | 4746 | ath_set_zero_crc(dut, val); | 
|  | 4747 | break; | 
|  | 4748 | default: | 
|  | 4749 | break; | 
|  | 4750 | } | 
|  | 4751 | } | 
|  | 4752 |  | 
|  | 4753 | return 1; | 
|  | 4754 | } | 
|  | 4755 |  | 
|  | 4756 |  | 
|  | 4757 | static int sta_set_60g_common(struct sigma_dut *dut, struct sigma_conn *conn, | 
|  | 4758 | struct sigma_cmd *cmd) | 
|  | 4759 | { | 
|  | 4760 | const char *val; | 
|  | 4761 | char buf[100]; | 
|  | 4762 |  | 
|  | 4763 | val = get_param(cmd, "MSDUSize"); | 
|  | 4764 | if (val) { | 
|  | 4765 | int mtu; | 
|  | 4766 |  | 
|  | 4767 | dut->amsdu_size = atoi(val); | 
|  | 4768 | if (dut->amsdu_size > IEEE80211_MAX_DATA_LEN_DMG || | 
|  | 4769 | dut->amsdu_size < IEEE80211_SNAP_LEN_DMG) { | 
|  | 4770 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 4771 | "MSDUSize %d is above max %d or below min %d", | 
|  | 4772 | dut->amsdu_size, | 
|  | 4773 | IEEE80211_MAX_DATA_LEN_DMG, | 
|  | 4774 | IEEE80211_SNAP_LEN_DMG); | 
|  | 4775 | dut->amsdu_size = 0; | 
|  | 4776 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; | 
|  | 4777 | } | 
|  | 4778 |  | 
|  | 4779 | mtu = dut->amsdu_size - IEEE80211_SNAP_LEN_DMG; | 
|  | 4780 | sigma_dut_print(dut, DUT_MSG_DEBUG, | 
|  | 4781 | "Setting amsdu_size to %d", mtu); | 
|  | 4782 | snprintf(buf, sizeof(buf), "ifconfig %s mtu %d", | 
|  | 4783 | get_station_ifname(), mtu); | 
|  | 4784 |  | 
|  | 4785 | if (system(buf) != 0) { | 
|  | 4786 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s", | 
|  | 4787 | buf); | 
|  | 4788 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; | 
|  | 4789 | } | 
|  | 4790 | } | 
|  | 4791 |  | 
|  | 4792 | val = get_param(cmd, "BAckRcvBuf"); | 
|  | 4793 | if (val) { | 
|  | 4794 | dut->back_rcv_buf = atoi(val); | 
|  | 4795 | if (dut->back_rcv_buf == 0) { | 
|  | 4796 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 4797 | "Failed to convert %s or value is 0", | 
|  | 4798 | val); | 
|  | 4799 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; | 
|  | 4800 | } | 
|  | 4801 |  | 
|  | 4802 | sigma_dut_print(dut, DUT_MSG_DEBUG, | 
|  | 4803 | "Setting BAckRcvBuf to %s", val); | 
|  | 4804 | } | 
|  | 4805 |  | 
|  | 4806 | return SIGMA_DUT_SUCCESS_CALLER_SEND_STATUS; | 
|  | 4807 | } | 
|  | 4808 |  | 
|  | 4809 |  | 
|  | 4810 | static int sta_pcp_start(struct sigma_dut *dut, struct sigma_conn *conn, | 
|  | 4811 | struct sigma_cmd *cmd) | 
|  | 4812 | { | 
|  | 4813 | int net_id; | 
|  | 4814 | char *ifname; | 
|  | 4815 | const char *val; | 
|  | 4816 | char buf[100]; | 
|  | 4817 |  | 
|  | 4818 | dut->mode = SIGMA_MODE_STATION; | 
|  | 4819 | ifname = get_main_ifname(); | 
|  | 4820 | if (wpa_command(ifname, "PING") != 0) { | 
|  | 4821 | sigma_dut_print(dut, DUT_MSG_ERROR, "Supplicant not running"); | 
|  | 4822 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; | 
|  | 4823 | } | 
|  | 4824 |  | 
|  | 4825 | wpa_command(ifname, "FLUSH"); | 
|  | 4826 | net_id = add_network_common(dut, conn, ifname, cmd); | 
|  | 4827 | if (net_id < 0) { | 
|  | 4828 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add network"); | 
|  | 4829 | return net_id; | 
|  | 4830 | } | 
|  | 4831 |  | 
|  | 4832 | /* TODO: mode=2 for the AP; in the future, replace for mode PCP */ | 
|  | 4833 | if (set_network(ifname, net_id, "mode", "2") < 0) { | 
|  | 4834 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 4835 | "Failed to set supplicant network mode"); | 
|  | 4836 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; | 
|  | 4837 | } | 
|  | 4838 |  | 
|  | 4839 | sigma_dut_print(dut, DUT_MSG_DEBUG, | 
|  | 4840 | "Supplicant set network with mode 2"); | 
|  | 4841 |  | 
|  | 4842 | val = get_param(cmd, "Security"); | 
|  | 4843 | if (val && strcasecmp(val, "OPEN") == 0) { | 
|  | 4844 | dut->ap_key_mgmt = AP_OPEN; | 
|  | 4845 | if (set_network(ifname, net_id, "key_mgmt", "NONE") < 0) { | 
|  | 4846 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 4847 | "Failed to set supplicant to %s security", | 
|  | 4848 | val); | 
|  | 4849 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; | 
|  | 4850 | } | 
|  | 4851 | } else if (val && strcasecmp(val, "WPA2-PSK") == 0) { | 
|  | 4852 | dut->ap_key_mgmt = AP_WPA2_PSK; | 
|  | 4853 | if (set_network(ifname, net_id, "key_mgmt", "WPA-PSK") < 0) { | 
|  | 4854 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 4855 | "Failed to set supplicant to %s security", | 
|  | 4856 | val); | 
|  | 4857 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; | 
|  | 4858 | } | 
|  | 4859 |  | 
|  | 4860 | if (set_network(ifname, net_id, "proto", "RSN") < 0) { | 
|  | 4861 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 4862 | "Failed to set supplicant to proto RSN"); | 
|  | 4863 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; | 
|  | 4864 | } | 
|  | 4865 | } else if (val) { | 
|  | 4866 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 4867 | "Requested Security %s is not supported on 60GHz", | 
|  | 4868 | val); | 
|  | 4869 | return SIGMA_DUT_INVALID_CALLER_SEND_STATUS; | 
|  | 4870 | } | 
|  | 4871 |  | 
|  | 4872 | val = get_param(cmd, "Encrypt"); | 
|  | 4873 | if (val && strcasecmp(val, "AES-GCMP") == 0) { | 
|  | 4874 | if (set_network(ifname, net_id, "pairwise", "GCMP") < 0) { | 
|  | 4875 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 4876 | "Failed to set supplicant to pairwise GCMP"); | 
|  | 4877 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; | 
|  | 4878 | } | 
|  | 4879 | if (set_network(ifname, net_id, "group", "GCMP") < 0) { | 
|  | 4880 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 4881 | "Failed to set supplicant to group GCMP"); | 
|  | 4882 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; | 
|  | 4883 | } | 
|  | 4884 | } else if (val) { | 
|  | 4885 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 4886 | "Requested Encrypt %s is not supported on 60 GHz", | 
|  | 4887 | val); | 
|  | 4888 | return SIGMA_DUT_INVALID_CALLER_SEND_STATUS; | 
|  | 4889 | } | 
|  | 4890 |  | 
|  | 4891 | val = get_param(cmd, "PSK"); | 
|  | 4892 | if (val && set_network_quoted(ifname, net_id, "psk", val) < 0) { | 
|  | 4893 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set psk %s", | 
|  | 4894 | val); | 
|  | 4895 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; | 
|  | 4896 | } | 
|  | 4897 |  | 
|  | 4898 | /* Convert 60G channel to freq */ | 
|  | 4899 | switch (dut->ap_channel) { | 
|  | 4900 | case 1: | 
|  | 4901 | val = "58320"; | 
|  | 4902 | break; | 
|  | 4903 | case 2: | 
|  | 4904 | val = "60480"; | 
|  | 4905 | break; | 
|  | 4906 | case 3: | 
|  | 4907 | val = "62640"; | 
|  | 4908 | break; | 
|  | 4909 | default: | 
|  | 4910 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 4911 | "Failed to configure channel %d. Not supported", | 
|  | 4912 | dut->ap_channel); | 
|  | 4913 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; | 
|  | 4914 | } | 
|  | 4915 |  | 
|  | 4916 | if (set_network(ifname, net_id, "frequency", val) < 0) { | 
|  | 4917 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 4918 | "Failed to set supplicant network frequency"); | 
|  | 4919 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; | 
|  | 4920 | } | 
|  | 4921 |  | 
|  | 4922 | sigma_dut_print(dut, DUT_MSG_DEBUG, | 
|  | 4923 | "Supplicant set network with frequency"); | 
|  | 4924 |  | 
|  | 4925 | snprintf(buf, sizeof(buf), "SELECT_NETWORK %d", net_id); | 
|  | 4926 | if (wpa_command(ifname, buf) < 0) { | 
|  | 4927 | sigma_dut_print(dut, DUT_MSG_INFO, | 
|  | 4928 | "Failed to select network id %d on %s", | 
|  | 4929 | net_id, ifname); | 
|  | 4930 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; | 
|  | 4931 | } | 
|  | 4932 |  | 
|  | 4933 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Selected network"); | 
|  | 4934 |  | 
|  | 4935 | return SIGMA_DUT_SUCCESS_CALLER_SEND_STATUS; | 
|  | 4936 | } | 
|  | 4937 |  | 
|  | 4938 |  | 
| Lior David | 67543f5 | 2017-01-03 19:04:22 +0200 | [diff] [blame] | 4939 | static int wil6210_set_abft_len(struct sigma_dut *dut, int abft_len) | 
|  | 4940 | { | 
|  | 4941 | char buf[128], fname[128]; | 
|  | 4942 | FILE *f; | 
|  | 4943 |  | 
|  | 4944 | if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) { | 
|  | 4945 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 4946 | "failed to get wil6210 debugfs dir"); | 
|  | 4947 | return -1; | 
|  | 4948 | } | 
|  | 4949 |  | 
|  | 4950 | snprintf(fname, sizeof(fname), "%s/abft_len", buf); | 
|  | 4951 | f = fopen(fname, "w"); | 
|  | 4952 | if (!f) { | 
|  | 4953 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 4954 | "failed to open: %s", fname); | 
|  | 4955 | return -1; | 
|  | 4956 | } | 
|  | 4957 |  | 
|  | 4958 | fprintf(f, "%d\n", abft_len); | 
|  | 4959 | fclose(f); | 
|  | 4960 |  | 
|  | 4961 | return 0; | 
|  | 4962 | } | 
|  | 4963 |  | 
|  | 4964 |  | 
|  | 4965 | static int sta_set_60g_abft_len(struct sigma_dut *dut, struct sigma_conn *conn, | 
|  | 4966 | int abft_len) | 
|  | 4967 | { | 
|  | 4968 | switch (get_driver_type()) { | 
|  | 4969 | case DRIVER_WIL6210: | 
|  | 4970 | return wil6210_set_abft_len(dut, abft_len); | 
|  | 4971 | default: | 
|  | 4972 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 4973 | "set abft_len not supported"); | 
|  | 4974 | return -1; | 
|  | 4975 | } | 
|  | 4976 | } | 
|  | 4977 |  | 
|  | 4978 |  | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4979 | static int sta_set_60g_pcp(struct sigma_dut *dut, struct sigma_conn *conn, | 
|  | 4980 | struct sigma_cmd *cmd) | 
|  | 4981 | { | 
|  | 4982 | const char *val; | 
| Lior David | 67543f5 | 2017-01-03 19:04:22 +0200 | [diff] [blame] | 4983 | unsigned int abft_len = 1; /* default is one slot */ | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4984 |  | 
|  | 4985 | if (dut->dev_role != DEVROLE_PCP) { | 
|  | 4986 | send_resp(dut, conn, SIGMA_INVALID, | 
|  | 4987 | "ErrorCode,Invalid DevRole"); | 
|  | 4988 | return 0; | 
|  | 4989 | } | 
|  | 4990 |  | 
|  | 4991 | val = get_param(cmd, "SSID"); | 
|  | 4992 | if (val) { | 
|  | 4993 | if (strlen(val) > sizeof(dut->ap_ssid) - 1) { | 
|  | 4994 | send_resp(dut, conn, SIGMA_INVALID, | 
|  | 4995 | "ErrorCode,Invalid SSID"); | 
|  | 4996 | return -1; | 
|  | 4997 | } | 
|  | 4998 |  | 
| Peng Xu | b8fc5cc | 2017-05-10 17:27:28 -0700 | [diff] [blame] | 4999 | strlcpy(dut->ap_ssid, val, sizeof(dut->ap_ssid)); | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5000 | } | 
|  | 5001 |  | 
|  | 5002 | val = get_param(cmd, "CHANNEL"); | 
|  | 5003 | if (val) { | 
|  | 5004 | const char *pos; | 
|  | 5005 |  | 
|  | 5006 | dut->ap_channel = atoi(val); | 
|  | 5007 | pos = strchr(val, ';'); | 
|  | 5008 | if (pos) { | 
|  | 5009 | pos++; | 
|  | 5010 | dut->ap_channel_1 = atoi(pos); | 
|  | 5011 | } | 
|  | 5012 | } | 
|  | 5013 |  | 
|  | 5014 | switch (dut->ap_channel) { | 
|  | 5015 | case 1: | 
|  | 5016 | case 2: | 
|  | 5017 | case 3: | 
|  | 5018 | break; | 
|  | 5019 | default: | 
|  | 5020 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 5021 | "Channel %d is not supported", dut->ap_channel); | 
|  | 5022 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 5023 | "Requested channel is not supported"); | 
|  | 5024 | return -1; | 
|  | 5025 | } | 
|  | 5026 |  | 
|  | 5027 | val = get_param(cmd, "BCNINT"); | 
|  | 5028 | if (val) | 
|  | 5029 | dut->ap_bcnint = atoi(val); | 
|  | 5030 |  | 
|  | 5031 |  | 
|  | 5032 | val = get_param(cmd, "ExtSchIE"); | 
|  | 5033 | if (val) { | 
|  | 5034 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 5035 | "ErrorCode,ExtSchIE is not supported yet"); | 
|  | 5036 | return -1; | 
|  | 5037 | } | 
|  | 5038 |  | 
|  | 5039 | val = get_param(cmd, "AllocType"); | 
|  | 5040 | if (val) { | 
|  | 5041 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 5042 | "ErrorCode,AllocType is not supported yet"); | 
|  | 5043 | return -1; | 
|  | 5044 | } | 
|  | 5045 |  | 
|  | 5046 | val = get_param(cmd, "PercentBI"); | 
|  | 5047 | if (val) { | 
|  | 5048 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 5049 | "ErrorCode,PercentBI is not supported yet"); | 
|  | 5050 | return -1; | 
|  | 5051 | } | 
|  | 5052 |  | 
|  | 5053 | val = get_param(cmd, "CBAPOnly"); | 
|  | 5054 | if (val) { | 
|  | 5055 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 5056 | "ErrorCode,CBAPOnly is not supported yet"); | 
|  | 5057 | return -1; | 
|  | 5058 | } | 
|  | 5059 |  | 
|  | 5060 | val = get_param(cmd, "AMPDU"); | 
|  | 5061 | if (val) { | 
|  | 5062 | if (strcasecmp(val, "Enable") == 0) | 
|  | 5063 | dut->ap_ampdu = 1; | 
|  | 5064 | else if (strcasecmp(val, "Disable") == 0) | 
|  | 5065 | dut->ap_ampdu = 2; | 
|  | 5066 | else { | 
|  | 5067 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 5068 | "ErrorCode,AMPDU value is not Enable nor Disabled"); | 
|  | 5069 | return -1; | 
|  | 5070 | } | 
|  | 5071 | } | 
|  | 5072 |  | 
|  | 5073 | val = get_param(cmd, "AMSDU"); | 
|  | 5074 | if (val) { | 
|  | 5075 | if (strcasecmp(val, "Enable") == 0) | 
|  | 5076 | dut->ap_amsdu = 1; | 
|  | 5077 | else if (strcasecmp(val, "Disable") == 0) | 
|  | 5078 | dut->ap_amsdu = 2; | 
|  | 5079 | } | 
|  | 5080 |  | 
|  | 5081 | val = get_param(cmd, "NumMSDU"); | 
|  | 5082 | if (val) { | 
|  | 5083 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 5084 | "ErrorCode, NumMSDU is not supported yet"); | 
|  | 5085 | return -1; | 
|  | 5086 | } | 
|  | 5087 |  | 
|  | 5088 | val = get_param(cmd, "ABFTLRang"); | 
|  | 5089 | if (val) { | 
|  | 5090 | sigma_dut_print(dut, DUT_MSG_DEBUG, | 
| Lior David | 67543f5 | 2017-01-03 19:04:22 +0200 | [diff] [blame] | 5091 | "ABFTLRang parameter %s", val); | 
|  | 5092 | if (strcmp(val, "Gt1") == 0) | 
|  | 5093 | abft_len = 2; /* 2 slots in this case */ | 
|  | 5094 | } | 
|  | 5095 |  | 
|  | 5096 | if (sta_set_60g_abft_len(dut, conn, abft_len)) { | 
|  | 5097 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 5098 | "ErrorCode, Can't set ABFT length"); | 
|  | 5099 | return -1; | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5100 | } | 
|  | 5101 |  | 
|  | 5102 | if (sta_pcp_start(dut, conn, cmd) < 0) { | 
|  | 5103 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 5104 | "ErrorCode, Can't start PCP role"); | 
|  | 5105 | return -1; | 
|  | 5106 | } | 
|  | 5107 |  | 
|  | 5108 | return sta_set_60g_common(dut, conn, cmd); | 
|  | 5109 | } | 
|  | 5110 |  | 
|  | 5111 |  | 
|  | 5112 | static int sta_set_60g_sta(struct sigma_dut *dut, struct sigma_conn *conn, | 
|  | 5113 | struct sigma_cmd *cmd) | 
|  | 5114 | { | 
|  | 5115 | const char *val = get_param(cmd, "DiscoveryMode"); | 
|  | 5116 |  | 
|  | 5117 | if (dut->dev_role != DEVROLE_STA) { | 
|  | 5118 | send_resp(dut, conn, SIGMA_INVALID, | 
|  | 5119 | "ErrorCode,Invalid DevRole"); | 
|  | 5120 | return 0; | 
|  | 5121 | } | 
|  | 5122 |  | 
|  | 5123 | if (val) { | 
|  | 5124 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Discovery: %s", val); | 
|  | 5125 | /* Ignore Discovery mode till Driver expose API. */ | 
|  | 5126 | #if 0 | 
|  | 5127 | if (strcasecmp(val, "1") == 0) { | 
|  | 5128 | send_resp(dut, conn, SIGMA_INVALID, | 
|  | 5129 | "ErrorCode,DiscoveryMode 1 not supported"); | 
|  | 5130 | return 0; | 
|  | 5131 | } | 
|  | 5132 |  | 
|  | 5133 | if (strcasecmp(val, "0") == 0) { | 
|  | 5134 | /* OK */ | 
|  | 5135 | } else { | 
|  | 5136 | send_resp(dut, conn, SIGMA_INVALID, | 
|  | 5137 | "ErrorCode,DiscoveryMode not supported"); | 
|  | 5138 | return 0; | 
|  | 5139 | } | 
|  | 5140 | #endif | 
|  | 5141 | } | 
|  | 5142 |  | 
|  | 5143 | if (start_sta_mode(dut) != 0) | 
|  | 5144 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; | 
|  | 5145 | return sta_set_60g_common(dut, conn, cmd); | 
|  | 5146 | } | 
|  | 5147 |  | 
|  | 5148 |  | 
|  | 5149 | static int cmd_sta_disconnect(struct sigma_dut *dut, struct sigma_conn *conn, | 
|  | 5150 | struct sigma_cmd *cmd) | 
|  | 5151 | { | 
|  | 5152 | const char *intf = get_param(cmd, "Interface"); | 
| Jouni Malinen | ed77e67 | 2018-01-10 16:45:13 +0200 | [diff] [blame] | 5153 | const char *val = get_param(cmd, "maintain_profile"); | 
| vamsi krishna | d605c42 | 2017-09-20 14:56:31 +0530 | [diff] [blame] | 5154 |  | 
| Jouni Malinen | ed77e67 | 2018-01-10 16:45:13 +0200 | [diff] [blame] | 5155 | if (dut->program == PROGRAM_OCE || | 
| Amarnath Hullur Subramanyam | ebeda9e | 2018-01-31 03:21:48 -0800 | [diff] [blame] | 5156 | dut->program == PROGRAM_HE || | 
| Jouni Malinen | ed77e67 | 2018-01-10 16:45:13 +0200 | [diff] [blame] | 5157 | (val && atoi(val) == 1)) { | 
| vamsi krishna | d605c42 | 2017-09-20 14:56:31 +0530 | [diff] [blame] | 5158 | wpa_command(intf, "DISCONNECT"); | 
|  | 5159 | return 1; | 
|  | 5160 | } | 
|  | 5161 |  | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5162 | disconnect_station(dut); | 
|  | 5163 | /* Try to ignore old scan results to avoid HS 2.0R2 test case failures | 
|  | 5164 | * due to cached results. */ | 
|  | 5165 | wpa_command(intf, "SET ignore_old_scan_res 1"); | 
|  | 5166 | wpa_command(intf, "BSS_FLUSH"); | 
|  | 5167 | return 1; | 
|  | 5168 | } | 
|  | 5169 |  | 
|  | 5170 |  | 
|  | 5171 | static int cmd_sta_reassoc(struct sigma_dut *dut, struct sigma_conn *conn, | 
|  | 5172 | struct sigma_cmd *cmd) | 
|  | 5173 | { | 
|  | 5174 | const char *intf = get_param(cmd, "Interface"); | 
|  | 5175 | const char *bssid = get_param(cmd, "bssid"); | 
|  | 5176 | const char *val = get_param(cmd, "CHANNEL"); | 
|  | 5177 | struct wpa_ctrl *ctrl; | 
| Srinivas Dasari | 0ebedb1 | 2018-02-14 17:03:51 +0530 | [diff] [blame] | 5178 | char buf[1000]; | 
| Sunil Dutt | d30ce09 | 2018-01-11 23:56:29 +0530 | [diff] [blame] | 5179 | char result[32]; | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5180 | int res; | 
|  | 5181 | int chan = 0; | 
| Ashwini Patil | 467efef | 2017-05-25 12:18:27 +0530 | [diff] [blame] | 5182 | int status = 0; | 
| Sunil Dutt | d30ce09 | 2018-01-11 23:56:29 +0530 | [diff] [blame] | 5183 | int fastreassoc = 1; | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5184 |  | 
|  | 5185 | if (bssid == NULL) { | 
|  | 5186 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing bssid " | 
|  | 5187 | "argument"); | 
|  | 5188 | return 0; | 
|  | 5189 | } | 
|  | 5190 |  | 
|  | 5191 | if (val) | 
|  | 5192 | chan = atoi(val); | 
|  | 5193 |  | 
|  | 5194 | if (wifi_chip_type != DRIVER_WCN && wifi_chip_type != DRIVER_AR6003) { | 
|  | 5195 | /* The current network may be from sta_associate or | 
|  | 5196 | * sta_hs2_associate | 
|  | 5197 | */ | 
|  | 5198 | if (set_network(intf, dut->infra_network_id, "bssid", bssid) < | 
|  | 5199 | 0 || | 
|  | 5200 | set_network(intf, 0, "bssid", bssid) < 0) | 
|  | 5201 | return -2; | 
|  | 5202 | } | 
|  | 5203 |  | 
|  | 5204 | ctrl = open_wpa_mon(intf); | 
|  | 5205 | if (ctrl == NULL) { | 
|  | 5206 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open " | 
|  | 5207 | "wpa_supplicant monitor connection"); | 
|  | 5208 | return -1; | 
|  | 5209 | } | 
|  | 5210 |  | 
| Sunil Dutt | d30ce09 | 2018-01-11 23:56:29 +0530 | [diff] [blame] | 5211 | if (get_wpa_status(get_station_ifname(), "wpa_state", result, | 
|  | 5212 | sizeof(result)) < 0 || | 
|  | 5213 | strncmp(result, "COMPLETED", 9) != 0) { | 
|  | 5214 | sigma_dut_print(dut, DUT_MSG_DEBUG, | 
|  | 5215 | "sta_reassoc: Not connected"); | 
|  | 5216 | fastreassoc = 0; | 
|  | 5217 | } | 
|  | 5218 |  | 
| Srinivas Dasari | 0ebedb1 | 2018-02-14 17:03:51 +0530 | [diff] [blame] | 5219 | if (dut->rsne_override) { | 
|  | 5220 | #ifdef NL80211_SUPPORT | 
|  | 5221 | if (get_driver_type() == DRIVER_WCN && dut->config_rsnie == 0) { | 
|  | 5222 | sta_config_rsnie(dut, 1); | 
|  | 5223 | dut->config_rsnie = 1; | 
|  | 5224 | } | 
|  | 5225 | #endif /* NL80211_SUPPORT */ | 
|  | 5226 | snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s", | 
|  | 5227 | dut->rsne_override); | 
|  | 5228 | if (wpa_command(intf, buf) < 0) { | 
|  | 5229 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 5230 | "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override"); | 
|  | 5231 | return 0; | 
|  | 5232 | } | 
|  | 5233 | } | 
|  | 5234 |  | 
| Sunil Dutt | d30ce09 | 2018-01-11 23:56:29 +0530 | [diff] [blame] | 5235 | if (wifi_chip_type == DRIVER_WCN && fastreassoc) { | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5236 | #ifdef ANDROID | 
| Ashwini Patil | 4c8158f | 2017-05-25 12:49:21 +0530 | [diff] [blame] | 5237 | if (chan) { | 
|  | 5238 | unsigned int freq; | 
|  | 5239 |  | 
|  | 5240 | freq = channel_to_freq(chan); | 
|  | 5241 | if (!freq) { | 
|  | 5242 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 5243 | "Invalid channel number provided: %d", | 
|  | 5244 | chan); | 
|  | 5245 | send_resp(dut, conn, SIGMA_INVALID, | 
|  | 5246 | "ErrorCode,Invalid channel number"); | 
|  | 5247 | goto close_mon_conn; | 
|  | 5248 | } | 
|  | 5249 | res = snprintf(buf, sizeof(buf), | 
|  | 5250 | "SCAN TYPE=ONLY freq=%d", freq); | 
|  | 5251 | } else { | 
|  | 5252 | res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY"); | 
|  | 5253 | } | 
|  | 5254 | if (res < 0 || res >= (int) sizeof(buf)) { | 
|  | 5255 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 5256 | "ErrorCode,snprintf failed"); | 
|  | 5257 | goto close_mon_conn; | 
|  | 5258 | } | 
|  | 5259 | if (wpa_command(intf, buf) < 0) { | 
|  | 5260 | sigma_dut_print(dut, DUT_MSG_INFO, | 
|  | 5261 | "Failed to start scan"); | 
|  | 5262 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 5263 | "ErrorCode,scan failed"); | 
|  | 5264 | goto close_mon_conn; | 
|  | 5265 | } | 
|  | 5266 |  | 
|  | 5267 | res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS", | 
|  | 5268 | buf, sizeof(buf)); | 
|  | 5269 | if (res < 0) { | 
|  | 5270 | sigma_dut_print(dut, DUT_MSG_INFO, | 
|  | 5271 | "Scan did not complete"); | 
|  | 5272 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 5273 | "ErrorCode,scan did not complete"); | 
|  | 5274 | goto close_mon_conn; | 
|  | 5275 | } | 
|  | 5276 |  | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5277 | if (set_network(intf, dut->infra_network_id, "bssid", "any") | 
|  | 5278 | < 0) { | 
|  | 5279 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set " | 
|  | 5280 | "bssid to any during FASTREASSOC"); | 
| Ashwini Patil | 467efef | 2017-05-25 12:18:27 +0530 | [diff] [blame] | 5281 | status = -2; | 
|  | 5282 | goto close_mon_conn; | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5283 | } | 
|  | 5284 | res = snprintf(buf, sizeof(buf), "DRIVER FASTREASSOC %s %d", | 
|  | 5285 | bssid, chan); | 
|  | 5286 | if (res > 0 && res < (int) sizeof(buf)) | 
|  | 5287 | res = wpa_command(intf, buf); | 
|  | 5288 |  | 
|  | 5289 | if (res < 0 || res >= (int) sizeof(buf)) { | 
|  | 5290 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 5291 | "errorCode,Failed to run DRIVER FASTREASSOC"); | 
| Ashwini Patil | 467efef | 2017-05-25 12:18:27 +0530 | [diff] [blame] | 5292 | goto close_mon_conn; | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5293 | } | 
|  | 5294 | #else /* ANDROID */ | 
|  | 5295 | sigma_dut_print(dut, DUT_MSG_DEBUG, | 
|  | 5296 | "Reassoc using iwpriv - skip chan=%d info", | 
|  | 5297 | chan); | 
|  | 5298 | snprintf(buf, sizeof(buf), "iwpriv %s reassoc", intf); | 
|  | 5299 | if (system(buf) != 0) { | 
|  | 5300 | sigma_dut_print(dut, DUT_MSG_ERROR, "%s failed", buf); | 
| Ashwini Patil | 467efef | 2017-05-25 12:18:27 +0530 | [diff] [blame] | 5301 | status = -2; | 
|  | 5302 | goto close_mon_conn; | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5303 | } | 
|  | 5304 | #endif /* ANDROID */ | 
|  | 5305 | sigma_dut_print(dut, DUT_MSG_INFO, | 
|  | 5306 | "sta_reassoc: Run %s successful", buf); | 
|  | 5307 | } else if (wpa_command(intf, "REASSOCIATE")) { | 
|  | 5308 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to " | 
|  | 5309 | "request reassociation"); | 
| Ashwini Patil | 467efef | 2017-05-25 12:18:27 +0530 | [diff] [blame] | 5310 | goto close_mon_conn; | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5311 | } | 
|  | 5312 |  | 
|  | 5313 | res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED", | 
|  | 5314 | buf, sizeof(buf)); | 
| Ashwini Patil | 467efef | 2017-05-25 12:18:27 +0530 | [diff] [blame] | 5315 | if (res < 0) { | 
|  | 5316 | sigma_dut_print(dut, DUT_MSG_INFO, "Connection did not complete"); | 
|  | 5317 | status = -1; | 
|  | 5318 | goto close_mon_conn; | 
|  | 5319 | } | 
|  | 5320 | status = 1; | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5321 |  | 
| Ashwini Patil | 467efef | 2017-05-25 12:18:27 +0530 | [diff] [blame] | 5322 | close_mon_conn: | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5323 | wpa_ctrl_detach(ctrl); | 
|  | 5324 | wpa_ctrl_close(ctrl); | 
| Ashwini Patil | 467efef | 2017-05-25 12:18:27 +0530 | [diff] [blame] | 5325 | return status; | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5326 | } | 
|  | 5327 |  | 
|  | 5328 |  | 
|  | 5329 | static void hs2_clear_credentials(const char *intf) | 
|  | 5330 | { | 
|  | 5331 | wpa_command(intf, "REMOVE_CRED all"); | 
|  | 5332 | } | 
|  | 5333 |  | 
|  | 5334 |  | 
| Lior David | cc88b56 | 2017-01-03 18:52:09 +0200 | [diff] [blame] | 5335 | #ifdef __linux__ | 
|  | 5336 | static int wil6210_get_aid(struct sigma_dut *dut, const char *bssid, | 
|  | 5337 | unsigned int *aid) | 
|  | 5338 | { | 
| Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 5339 | const char *pattern = "AID[ \t]+([0-9]+)"; | 
| Lior David | cc88b56 | 2017-01-03 18:52:09 +0200 | [diff] [blame] | 5340 |  | 
| Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 5341 | return wil6210_get_sta_info_field(dut, bssid, pattern, aid); | 
| Lior David | cc88b56 | 2017-01-03 18:52:09 +0200 | [diff] [blame] | 5342 | } | 
|  | 5343 | #endif /* __linux__ */ | 
|  | 5344 |  | 
|  | 5345 |  | 
|  | 5346 | static int sta_get_aid_60g(struct sigma_dut *dut, const char *bssid, | 
|  | 5347 | unsigned int *aid) | 
|  | 5348 | { | 
|  | 5349 | switch (get_driver_type()) { | 
|  | 5350 | #ifdef __linux__ | 
|  | 5351 | case DRIVER_WIL6210: | 
|  | 5352 | return wil6210_get_aid(dut, bssid, aid); | 
|  | 5353 | #endif /* __linux__ */ | 
|  | 5354 | default: | 
|  | 5355 | sigma_dut_print(dut, DUT_MSG_ERROR, "get AID not supported"); | 
|  | 5356 | return -1; | 
|  | 5357 | } | 
|  | 5358 | } | 
|  | 5359 |  | 
|  | 5360 |  | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5361 | static int sta_get_parameter_60g(struct sigma_dut *dut, struct sigma_conn *conn, | 
|  | 5362 | struct sigma_cmd *cmd) | 
|  | 5363 | { | 
|  | 5364 | char buf[MAX_CMD_LEN]; | 
|  | 5365 | char bss_list[MAX_CMD_LEN]; | 
|  | 5366 | const char *parameter = get_param(cmd, "Parameter"); | 
|  | 5367 |  | 
|  | 5368 | if (parameter == NULL) | 
|  | 5369 | return -1; | 
|  | 5370 |  | 
| Lior David | cc88b56 | 2017-01-03 18:52:09 +0200 | [diff] [blame] | 5371 | if (strcasecmp(parameter, "AID") == 0) { | 
|  | 5372 | unsigned int aid = 0; | 
|  | 5373 | char bssid[20]; | 
|  | 5374 |  | 
|  | 5375 | if (get_wpa_status(get_station_ifname(), "bssid", | 
|  | 5376 | bssid, sizeof(bssid)) < 0) { | 
|  | 5377 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 5378 | "could not get bssid"); | 
|  | 5379 | return -2; | 
|  | 5380 | } | 
|  | 5381 |  | 
|  | 5382 | if (sta_get_aid_60g(dut, bssid, &aid)) | 
|  | 5383 | return -2; | 
|  | 5384 |  | 
|  | 5385 | snprintf(buf, sizeof(buf), "aid,%d", aid); | 
|  | 5386 | sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf); | 
|  | 5387 | send_resp(dut, conn, SIGMA_COMPLETE, buf); | 
|  | 5388 | return 0; | 
|  | 5389 | } | 
|  | 5390 |  | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5391 | if (strcasecmp(parameter, "DiscoveredDevList") == 0) { | 
|  | 5392 | char *bss_line; | 
|  | 5393 | char *bss_id = NULL; | 
|  | 5394 | const char *ifname = get_param(cmd, "Interface"); | 
| Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 5395 | char *saveptr; | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5396 |  | 
|  | 5397 | if (ifname == NULL) { | 
|  | 5398 | sigma_dut_print(dut, DUT_MSG_INFO, | 
|  | 5399 | "For get DiscoveredDevList need Interface name."); | 
|  | 5400 | return -1; | 
|  | 5401 | } | 
|  | 5402 |  | 
|  | 5403 | /* | 
|  | 5404 | * Use "BSS RANGE=ALL MASK=0x2" which provides a list | 
|  | 5405 | * of BSSIDs in "bssid=<BSSID>\n" | 
|  | 5406 | */ | 
|  | 5407 | if (wpa_command_resp(ifname, "BSS RANGE=ALL MASK=0x2", | 
|  | 5408 | bss_list, | 
|  | 5409 | sizeof(bss_list)) < 0) { | 
|  | 5410 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 5411 | "Failed to get bss list"); | 
|  | 5412 | return -1; | 
|  | 5413 | } | 
|  | 5414 |  | 
|  | 5415 | sigma_dut_print(dut, DUT_MSG_DEBUG, | 
|  | 5416 | "bss list for ifname:%s is:%s", | 
|  | 5417 | ifname, bss_list); | 
|  | 5418 |  | 
|  | 5419 | snprintf(buf, sizeof(buf), "DeviceList"); | 
| Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 5420 | bss_line = strtok_r(bss_list, "\n", &saveptr); | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5421 | while (bss_line) { | 
|  | 5422 | if (sscanf(bss_line, "bssid=%ms", &bss_id) > 0 && | 
|  | 5423 | bss_id) { | 
|  | 5424 | int len; | 
|  | 5425 |  | 
|  | 5426 | len = snprintf(buf + strlen(buf), | 
|  | 5427 | sizeof(buf) - strlen(buf), | 
|  | 5428 | ",%s", bss_id); | 
|  | 5429 | free(bss_id); | 
|  | 5430 | bss_id = NULL; | 
|  | 5431 | if (len < 0) { | 
|  | 5432 | sigma_dut_print(dut, | 
|  | 5433 | DUT_MSG_ERROR, | 
|  | 5434 | "Failed to read BSSID"); | 
|  | 5435 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 5436 | "ErrorCode,Failed to read BSS ID"); | 
|  | 5437 | return 0; | 
|  | 5438 | } | 
|  | 5439 |  | 
|  | 5440 | if ((size_t) len >= sizeof(buf) - strlen(buf)) { | 
|  | 5441 | sigma_dut_print(dut, | 
|  | 5442 | DUT_MSG_ERROR, | 
|  | 5443 | "Response buf too small for list"); | 
|  | 5444 | send_resp(dut, conn, | 
|  | 5445 | SIGMA_ERROR, | 
|  | 5446 | "ErrorCode,Response buf too small for list"); | 
|  | 5447 | return 0; | 
|  | 5448 | } | 
|  | 5449 | } | 
|  | 5450 |  | 
| Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 5451 | bss_line = strtok_r(NULL, "\n", &saveptr); | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5452 | } | 
|  | 5453 |  | 
|  | 5454 | sigma_dut_print(dut, DUT_MSG_INFO, "DiscoveredDevList is %s", | 
|  | 5455 | buf); | 
|  | 5456 | send_resp(dut, conn, SIGMA_COMPLETE, buf); | 
|  | 5457 | return 0; | 
|  | 5458 | } | 
|  | 5459 |  | 
|  | 5460 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter"); | 
|  | 5461 | return 0; | 
|  | 5462 | } | 
|  | 5463 |  | 
|  | 5464 |  | 
|  | 5465 | static int cmd_sta_get_parameter(struct sigma_dut *dut, struct sigma_conn *conn, | 
|  | 5466 | struct sigma_cmd *cmd) | 
|  | 5467 | { | 
|  | 5468 | const char *program = get_param(cmd, "Program"); | 
|  | 5469 |  | 
|  | 5470 | if (program == NULL) | 
|  | 5471 | return -1; | 
|  | 5472 |  | 
|  | 5473 | if (strcasecmp(program, "P2PNFC") == 0) | 
|  | 5474 | return p2p_cmd_sta_get_parameter(dut, conn, cmd); | 
|  | 5475 |  | 
|  | 5476 | if (strcasecmp(program, "60ghz") == 0) | 
|  | 5477 | return sta_get_parameter_60g(dut, conn, cmd); | 
|  | 5478 |  | 
|  | 5479 | #ifdef ANDROID_NAN | 
|  | 5480 | if (strcasecmp(program, "NAN") == 0) | 
| Amarnath Hullur Subramanyam | 1854ec6 | 2016-08-11 19:29:35 -0700 | [diff] [blame] | 5481 | return nan_cmd_sta_get_parameter(dut, conn, cmd); | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5482 | #endif /* ANDROID_NAN */ | 
|  | 5483 |  | 
| Amarnath Hullur Subramanyam | 9c381f5 | 2017-03-17 00:04:41 -0700 | [diff] [blame] | 5484 | #ifdef MIRACAST | 
|  | 5485 | if (strcasecmp(program, "WFD") == 0 || | 
|  | 5486 | strcasecmp(program, "DisplayR2") == 0) | 
|  | 5487 | return miracast_cmd_sta_get_parameter(dut, conn, cmd); | 
|  | 5488 | #endif /* MIRACAST */ | 
|  | 5489 |  | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5490 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter"); | 
|  | 5491 | return 0; | 
|  | 5492 | } | 
|  | 5493 |  | 
|  | 5494 |  | 
|  | 5495 | static void sta_reset_default_ath(struct sigma_dut *dut, const char *intf, | 
|  | 5496 | const char *type) | 
|  | 5497 | { | 
|  | 5498 | char buf[100]; | 
|  | 5499 |  | 
|  | 5500 | if (dut->program == PROGRAM_VHT) { | 
|  | 5501 | snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf); | 
|  | 5502 | if (system(buf) != 0) { | 
|  | 5503 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 5504 | "iwpriv %s chwidth failed", intf); | 
|  | 5505 | } | 
|  | 5506 |  | 
|  | 5507 | snprintf(buf, sizeof(buf), "iwpriv %s mode 11ACVHT80", intf); | 
|  | 5508 | if (system(buf) != 0) { | 
|  | 5509 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 5510 | "iwpriv %s mode 11ACVHT80 failed", | 
|  | 5511 | intf); | 
|  | 5512 | } | 
|  | 5513 |  | 
|  | 5514 | snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs -1", intf); | 
|  | 5515 | if (system(buf) != 0) { | 
|  | 5516 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 5517 | "iwpriv %s vhtmcs -1 failed", intf); | 
|  | 5518 | } | 
|  | 5519 | } | 
|  | 5520 |  | 
|  | 5521 | if (dut->program == PROGRAM_HT) { | 
|  | 5522 | snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf); | 
|  | 5523 | if (system(buf) != 0) { | 
|  | 5524 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 5525 | "iwpriv %s chwidth failed", intf); | 
|  | 5526 | } | 
|  | 5527 |  | 
|  | 5528 | snprintf(buf, sizeof(buf), "iwpriv %s mode 11naht40", intf); | 
|  | 5529 | if (system(buf) != 0) { | 
|  | 5530 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 5531 | "iwpriv %s mode 11naht40 failed", | 
|  | 5532 | intf); | 
|  | 5533 | } | 
|  | 5534 |  | 
|  | 5535 | snprintf(buf, sizeof(buf), "iwpriv %s set11NRates 0", intf); | 
|  | 5536 | if (system(buf) != 0) { | 
|  | 5537 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 5538 | "iwpriv set11NRates failed"); | 
|  | 5539 | } | 
|  | 5540 | } | 
|  | 5541 |  | 
|  | 5542 | if (dut->program == PROGRAM_VHT || dut->program == PROGRAM_HT) { | 
|  | 5543 | snprintf(buf, sizeof(buf), "iwpriv %s powersave 0", intf); | 
|  | 5544 | if (system(buf) != 0) { | 
|  | 5545 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 5546 | "disabling powersave failed"); | 
|  | 5547 | } | 
|  | 5548 |  | 
|  | 5549 | /* Reset CTS width */ | 
|  | 5550 | snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 54 0", | 
|  | 5551 | intf); | 
|  | 5552 | if (system(buf) != 0) { | 
|  | 5553 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 5554 | "wifitool %s beeliner_fw_test 54 0 failed", | 
|  | 5555 | intf); | 
|  | 5556 | } | 
|  | 5557 |  | 
|  | 5558 | /* Enable Dynamic Bandwidth signalling by default */ | 
|  | 5559 | snprintf(buf, sizeof(buf), "iwpriv %s cwmenable 1", intf); | 
|  | 5560 | if (system(buf) != 0) { | 
|  | 5561 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 5562 | "iwpriv %s cwmenable 1 failed", intf); | 
|  | 5563 | } | 
|  | 5564 |  | 
|  | 5565 | snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", intf); | 
|  | 5566 | if (system(buf) != 0) { | 
|  | 5567 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 5568 | "iwpriv rts failed"); | 
|  | 5569 | } | 
|  | 5570 | } | 
|  | 5571 |  | 
|  | 5572 | if (type && strcasecmp(type, "Testbed") == 0) { | 
|  | 5573 | dut->testbed_flag_txsp = 1; | 
|  | 5574 | dut->testbed_flag_rxsp = 1; | 
|  | 5575 | /* STA has to set spatial stream to 2 per Appendix H */ | 
|  | 5576 | snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0xfff0", intf); | 
|  | 5577 | if (system(buf) != 0) { | 
|  | 5578 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 5579 | "iwpriv vht_mcsmap failed"); | 
|  | 5580 | } | 
|  | 5581 |  | 
|  | 5582 | /* Disable LDPC per Appendix H */ | 
|  | 5583 | snprintf(buf, sizeof(buf), "iwpriv %s ldpc 0", intf); | 
|  | 5584 | if (system(buf) != 0) { | 
|  | 5585 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 5586 | "iwpriv %s ldpc 0 failed", intf); | 
|  | 5587 | } | 
|  | 5588 |  | 
|  | 5589 | snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf); | 
|  | 5590 | if (system(buf) != 0) { | 
|  | 5591 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 5592 | "iwpriv amsdu failed"); | 
|  | 5593 | } | 
|  | 5594 |  | 
|  | 5595 | /* TODO: Disable STBC 2x1 transmit and receive */ | 
|  | 5596 | snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc 0", intf); | 
|  | 5597 | if (system(buf) != 0) { | 
|  | 5598 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 5599 | "Disable tx_stbc 0 failed"); | 
|  | 5600 | } | 
|  | 5601 |  | 
|  | 5602 | snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc 0", intf); | 
|  | 5603 | if (system(buf) != 0) { | 
|  | 5604 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 5605 | "Disable rx_stbc 0 failed"); | 
|  | 5606 | } | 
|  | 5607 |  | 
|  | 5608 | /* STA has to disable Short GI per Appendix H */ | 
|  | 5609 | snprintf(buf, sizeof(buf), "iwpriv %s shortgi 0", intf); | 
|  | 5610 | if (system(buf) != 0) { | 
|  | 5611 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 5612 | "iwpriv %s shortgi 0 failed", intf); | 
|  | 5613 | } | 
|  | 5614 | } | 
|  | 5615 |  | 
|  | 5616 | if (type && strcasecmp(type, "DUT") == 0) { | 
|  | 5617 | snprintf(buf, sizeof(buf), "iwpriv %s nss 3", intf); | 
|  | 5618 | if (system(buf) != 0) { | 
|  | 5619 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 5620 | "iwpriv %s nss 3 failed", intf); | 
|  | 5621 | } | 
|  | 5622 |  | 
|  | 5623 | snprintf(buf, sizeof(buf), "iwpriv %s shortgi 1", intf); | 
|  | 5624 | if (system(buf) != 0) { | 
|  | 5625 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 5626 | "iwpriv %s shortgi 1 failed", intf); | 
|  | 5627 | } | 
|  | 5628 | } | 
|  | 5629 | } | 
|  | 5630 |  | 
|  | 5631 |  | 
| Amarnath Hullur Subramanyam | 2538acc | 2018-02-02 16:15:25 -0800 | [diff] [blame] | 5632 | #ifdef NL80211_SUPPORT | 
|  | 5633 | static int sta_set_he_mcs(struct sigma_dut *dut, const char *intf, | 
|  | 5634 | enum he_mcs_config mcs) | 
|  | 5635 | { | 
|  | 5636 | struct nl_msg *msg; | 
|  | 5637 | int ret = 0; | 
|  | 5638 | struct nlattr *params; | 
|  | 5639 | int ifindex; | 
|  | 5640 |  | 
|  | 5641 | ifindex = if_nametoindex(intf); | 
|  | 5642 | if (ifindex == 0) { | 
|  | 5643 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 5644 | "%s: Index for interface %s failed", | 
|  | 5645 | __func__, intf); | 
|  | 5646 | return -1; | 
|  | 5647 | } | 
|  | 5648 |  | 
|  | 5649 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, | 
|  | 5650 | NL80211_CMD_VENDOR)) || | 
|  | 5651 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || | 
|  | 5652 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | 
|  | 5653 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | 
|  | 5654 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || | 
|  | 5655 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | 
|  | 5656 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MCS, | 
|  | 5657 | mcs)) { | 
|  | 5658 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 5659 | "%s: err in adding vendor_cmd and vendor_data", | 
|  | 5660 | __func__); | 
|  | 5661 | nlmsg_free(msg); | 
|  | 5662 | return -1; | 
|  | 5663 | } | 
|  | 5664 | nla_nest_end(msg, params); | 
|  | 5665 |  | 
|  | 5666 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); | 
|  | 5667 | if (ret) { | 
|  | 5668 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 5669 | "%s: err in send_and_recv_msgs, ret=%d", | 
|  | 5670 | __func__, ret); | 
|  | 5671 | } | 
|  | 5672 | return ret; | 
|  | 5673 | } | 
|  | 5674 | #endif /* NL80211_SUPPORT */ | 
|  | 5675 |  | 
|  | 5676 |  | 
| Amarnath Hullur Subramanyam | 4622a21 | 2018-02-23 12:12:14 -0800 | [diff] [blame] | 5677 | static int sta_set_heconfig_and_wep_tkip(struct sigma_dut *dut, | 
|  | 5678 | const char *intf, int enable) | 
|  | 5679 | { | 
|  | 5680 | #ifdef NL80211_SUPPORT | 
|  | 5681 | struct nl_msg *msg; | 
|  | 5682 | int ret = 0; | 
|  | 5683 | struct nlattr *params; | 
|  | 5684 | int ifindex; | 
|  | 5685 |  | 
|  | 5686 | ifindex = if_nametoindex(intf); | 
|  | 5687 | if (ifindex == 0) { | 
|  | 5688 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 5689 | "%s: Index for interface %s failed", | 
|  | 5690 | __func__, intf); | 
|  | 5691 | return -1; | 
|  | 5692 | } | 
|  | 5693 |  | 
|  | 5694 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, | 
|  | 5695 | NL80211_CMD_VENDOR)) || | 
|  | 5696 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || | 
|  | 5697 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | 
|  | 5698 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | 
|  | 5699 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || | 
|  | 5700 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | 
|  | 5701 | nla_put_u8(msg, | 
|  | 5702 | QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WEP_TKIP_IN_HE, | 
|  | 5703 | enable)) { | 
|  | 5704 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 5705 | "%s: err in adding vendor_cmd and vendor_data", | 
|  | 5706 | __func__); | 
|  | 5707 | nlmsg_free(msg); | 
|  | 5708 | return -1; | 
|  | 5709 | } | 
|  | 5710 | nla_nest_end(msg, params); | 
|  | 5711 |  | 
|  | 5712 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); | 
|  | 5713 | if (ret) { | 
|  | 5714 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 5715 | "%s: err in send_and_recv_msgs, ret=%d", | 
|  | 5716 | __func__, ret); | 
|  | 5717 | } | 
|  | 5718 | return ret; | 
|  | 5719 | #else /* NL80211_SUPPORT */ | 
|  | 5720 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 5721 | "HE config enablement cannot be changed without NL80211_SUPPORT defined"); | 
|  | 5722 | return -1; | 
|  | 5723 | #endif /* NL80211_SUPPORT */ | 
|  | 5724 | } | 
|  | 5725 |  | 
|  | 5726 |  | 
| Amarnath Hullur Subramanyam | 13215de | 2018-02-27 14:12:55 -0800 | [diff] [blame] | 5727 | static int sta_set_addba_buf_size(struct sigma_dut *dut, | 
|  | 5728 | const char *intf, int bufsize) | 
|  | 5729 | { | 
|  | 5730 | #ifdef NL80211_SUPPORT | 
|  | 5731 | struct nl_msg *msg; | 
|  | 5732 | int ret = 0; | 
|  | 5733 | struct nlattr *params; | 
|  | 5734 | int ifindex; | 
|  | 5735 |  | 
|  | 5736 | ifindex = if_nametoindex(intf); | 
|  | 5737 | if (ifindex == 0) { | 
|  | 5738 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 5739 | "%s: Index for interface %s failed", | 
|  | 5740 | __func__, intf); | 
|  | 5741 | return -1; | 
|  | 5742 | } | 
|  | 5743 |  | 
|  | 5744 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, | 
|  | 5745 | NL80211_CMD_VENDOR)) || | 
|  | 5746 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || | 
|  | 5747 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | 
|  | 5748 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | 
|  | 5749 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || | 
|  | 5750 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | 
|  | 5751 | nla_put_u8(msg, | 
|  | 5752 | QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE, | 
|  | 5753 | bufsize)) { | 
|  | 5754 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 5755 | "%s: err in adding vendor_cmd and vendor_data", | 
|  | 5756 | __func__); | 
|  | 5757 | nlmsg_free(msg); | 
|  | 5758 | return -1; | 
|  | 5759 | } | 
|  | 5760 | nla_nest_end(msg, params); | 
|  | 5761 |  | 
|  | 5762 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); | 
|  | 5763 | if (ret) { | 
|  | 5764 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 5765 | "%s: err in send_and_recv_msgs, ret=%d", | 
|  | 5766 | __func__, ret); | 
|  | 5767 | } | 
|  | 5768 | return ret; | 
|  | 5769 | #else /* NL80211_SUPPORT */ | 
|  | 5770 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 5771 | "AddBA bufsize cannot be changed without NL80211_SUPPORT defined"); | 
|  | 5772 | return -1; | 
|  | 5773 | #endif /* NL80211_SUPPORT */ | 
|  | 5774 | } | 
|  | 5775 |  | 
|  | 5776 |  | 
| Amarnath Hullur Subramanyam | 58f2a6e | 2018-01-31 03:36:00 -0800 | [diff] [blame] | 5777 | static void sta_reset_default_wcn(struct sigma_dut *dut, const char *intf, | 
|  | 5778 | const char *type) | 
|  | 5779 | { | 
|  | 5780 | char buf[60]; | 
|  | 5781 |  | 
|  | 5782 | if (dut->program == PROGRAM_HE) { | 
|  | 5783 | /* resetting phymode to auto in case of HE program */ | 
|  | 5784 | snprintf(buf, sizeof(buf), "iwpriv %s setphymode 0", intf); | 
|  | 5785 | if (system(buf) != 0) { | 
|  | 5786 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 5787 | "iwpriv %s setphymode failed", intf); | 
|  | 5788 | } | 
|  | 5789 |  | 
|  | 5790 | /* remove all network profiles */ | 
|  | 5791 | remove_wpa_networks(intf); | 
| Amarnath Hullur Subramanyam | 2538acc | 2018-02-02 16:15:25 -0800 | [diff] [blame] | 5792 |  | 
| Amarnath Hullur Subramanyam | 13215de | 2018-02-27 14:12:55 -0800 | [diff] [blame] | 5793 | /* Configure ADDBA Req/Rsp buffer size to be 64 */ | 
|  | 5794 | sta_set_addba_buf_size(dut, intf, 64); | 
|  | 5795 |  | 
| Amarnath Hullur Subramanyam | 5f32d57 | 2018-03-02 00:02:33 -0800 | [diff] [blame] | 5796 | #ifdef NL80211_SUPPORT | 
|  | 5797 | /* Disable noackpolicy for all AC */ | 
|  | 5798 | if (nlvendor_sta_set_noack(dut, intf, 0, QCA_WLAN_AC_ALL)) { | 
|  | 5799 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 5800 | "Disable of noackpolicy for all AC failed"); | 
|  | 5801 | } | 
|  | 5802 | #endif /* NL80211_SUPPORT */ | 
|  | 5803 |  | 
| Amarnath Hullur Subramanyam | b1724a5 | 2018-03-07 14:31:46 -0800 | [diff] [blame] | 5804 | /* Enable WMM by default */ | 
|  | 5805 | if (wcn_sta_set_wmm(dut, intf, "on")) { | 
|  | 5806 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 5807 | "Enable of WMM in sta_reset_default_wcn failed"); | 
|  | 5808 | } | 
|  | 5809 |  | 
|  | 5810 | /* Disable ADDBA_REJECT by default */ | 
|  | 5811 | if (nlvendor_sta_set_addba_reject(dut, intf, 0)) { | 
|  | 5812 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 5813 | "Disable of addba_reject in sta_reset_default_wcn failed"); | 
|  | 5814 | } | 
|  | 5815 |  | 
| Amarnath Hullur Subramanyam | 1f65a67 | 2018-03-07 14:50:29 -0800 | [diff] [blame] | 5816 | /* Enable sending of ADDBA by default */ | 
|  | 5817 | if (nlvendor_config_send_addba(dut, intf, 1)) { | 
|  | 5818 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 5819 | "Enable sending of ADDBA in sta_reset_default_wcn failed"); | 
|  | 5820 | } | 
|  | 5821 |  | 
| Amarnath Hullur Subramanyam | 63c590a | 2018-03-07 15:26:21 -0800 | [diff] [blame^] | 5822 | /* Enable AMPDU by default */ | 
|  | 5823 | iwpriv_sta_set_ampdu(dut, intf, 1); | 
|  | 5824 |  | 
| Amarnath Hullur Subramanyam | 2538acc | 2018-02-02 16:15:25 -0800 | [diff] [blame] | 5825 | /* Set nss to 1 and MCS 0-7 in case of testbed */ | 
|  | 5826 | if (type && strcasecmp(type, "Testbed") == 0) { | 
|  | 5827 | #ifdef NL80211_SUPPORT | 
|  | 5828 | int ret; | 
|  | 5829 | #endif /* NL80211_SUPPORT */ | 
|  | 5830 |  | 
|  | 5831 | snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf); | 
|  | 5832 | if (system(buf) != 0) { | 
|  | 5833 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 5834 | "iwpriv %s nss failed", intf); | 
|  | 5835 | } | 
|  | 5836 |  | 
|  | 5837 | #ifdef NL80211_SUPPORT | 
|  | 5838 | ret = sta_set_he_mcs(dut, intf, HE_80_MCS0_7); | 
|  | 5839 | if (ret) { | 
|  | 5840 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 5841 | "Setting of MCS failed, ret:%d", | 
|  | 5842 | ret); | 
|  | 5843 | } | 
|  | 5844 | #endif /* NL80211_SUPPORT */ | 
| Amarnath Hullur Subramanyam | c67621d | 2018-02-04 23:18:01 -0800 | [diff] [blame] | 5845 |  | 
|  | 5846 | /* Disable STBC as default */ | 
|  | 5847 | wcn_sta_set_stbc(dut, intf, "0"); | 
| Amarnath Hullur Subramanyam | d5bb573 | 2018-02-22 15:50:38 -0800 | [diff] [blame] | 5848 |  | 
|  | 5849 | /* Disable AMSDU as default */ | 
|  | 5850 | iwpriv_sta_set_amsdu(dut, intf, "0"); | 
| Amarnath Hullur Subramanyam | 474a17d | 2018-02-22 18:45:54 -0800 | [diff] [blame] | 5851 |  | 
|  | 5852 | #ifdef NL80211_SUPPORT | 
|  | 5853 | /* HE fragmentation default off */ | 
|  | 5854 | if (sta_set_he_fragmentation(dut, intf, | 
|  | 5855 | HE_FRAG_DISABLE)) { | 
|  | 5856 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 5857 | "Setting of HE fragmentation failed"); | 
|  | 5858 | } | 
|  | 5859 | #endif /* NL80211_SUPPORT */ | 
| Amarnath Hullur Subramanyam | 4622a21 | 2018-02-23 12:12:14 -0800 | [diff] [blame] | 5860 |  | 
|  | 5861 | /* Enable WEP/TKIP with HE capability in testbed */ | 
|  | 5862 | if (sta_set_heconfig_and_wep_tkip(dut, intf, 1)) { | 
|  | 5863 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 5864 | "Enabling HE config with WEP/TKIP failed"); | 
|  | 5865 | } | 
| Amarnath Hullur Subramanyam | 2538acc | 2018-02-02 16:15:25 -0800 | [diff] [blame] | 5866 | } | 
| Amarnath Hullur Subramanyam | 0acce2c | 2018-03-06 06:05:17 -0800 | [diff] [blame] | 5867 |  | 
|  | 5868 | /* Defaults in case of DUT */ | 
|  | 5869 | if (type && strcasecmp(type, "DUT") == 0) { | 
|  | 5870 | /* set nss to 2 */ | 
|  | 5871 | snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf); | 
|  | 5872 | if (system(buf) != 0) { | 
|  | 5873 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 5874 | "iwpriv %s nss 2 failed", intf); | 
|  | 5875 | } | 
|  | 5876 |  | 
|  | 5877 | #ifdef NL80211_SUPPORT | 
|  | 5878 | /* Set HE_MCS to 0-7 */ | 
|  | 5879 | if (sta_set_he_mcs(dut, intf, HE_80_MCS0_7)) { | 
|  | 5880 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 5881 | "Setting of MCS failed"); | 
|  | 5882 | } | 
|  | 5883 | #endif /* NL80211_SUPPORT */ | 
|  | 5884 |  | 
|  | 5885 | /* Disable WEP/TKIP with HE capability in DUT */ | 
|  | 5886 | if (sta_set_heconfig_and_wep_tkip(dut, intf, 0)) { | 
|  | 5887 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 5888 | "Enabling HE config with WEP/TKIP failed"); | 
|  | 5889 | } | 
|  | 5890 | } | 
| Amarnath Hullur Subramanyam | 58f2a6e | 2018-01-31 03:36:00 -0800 | [diff] [blame] | 5891 | } | 
|  | 5892 | } | 
|  | 5893 |  | 
|  | 5894 |  | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5895 | static int cmd_sta_reset_default(struct sigma_dut *dut, | 
|  | 5896 | struct sigma_conn *conn, | 
|  | 5897 | struct sigma_cmd *cmd) | 
|  | 5898 | { | 
|  | 5899 | int cmd_sta_p2p_reset(struct sigma_dut *dut, struct sigma_conn *conn, | 
|  | 5900 | struct sigma_cmd *cmd); | 
|  | 5901 | const char *intf = get_param(cmd, "Interface"); | 
|  | 5902 | const char *type; | 
| Amarnath Hullur Subramanyam | 9c381f5 | 2017-03-17 00:04:41 -0700 | [diff] [blame] | 5903 | const char *program = get_param(cmd, "program"); | 
| Ankita Bajaj | 0d5825b | 2017-10-25 16:20:17 +0530 | [diff] [blame] | 5904 | const char *dev_role = get_param(cmd, "DevRole"); | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5905 |  | 
| Amarnath Hullur Subramanyam | 9c381f5 | 2017-03-17 00:04:41 -0700 | [diff] [blame] | 5906 | if (!program) | 
|  | 5907 | program = get_param(cmd, "prog"); | 
|  | 5908 | dut->program = sigma_program_to_enum(program); | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5909 | dut->device_type = STA_unknown; | 
|  | 5910 | type = get_param(cmd, "type"); | 
|  | 5911 | if (type && strcasecmp(type, "Testbed") == 0) | 
|  | 5912 | dut->device_type = STA_testbed; | 
|  | 5913 | if (type && strcasecmp(type, "DUT") == 0) | 
|  | 5914 | dut->device_type = STA_dut; | 
|  | 5915 |  | 
|  | 5916 | if (dut->program == PROGRAM_TDLS) { | 
|  | 5917 | /* Clear TDLS testing mode */ | 
|  | 5918 | wpa_command(intf, "SET tdls_disabled 0"); | 
|  | 5919 | wpa_command(intf, "SET tdls_testing 0"); | 
|  | 5920 | dut->no_tpk_expiration = 0; | 
| Pradeep Reddy POTTETI | 8ce2a23 | 2016-10-28 12:17:32 +0530 | [diff] [blame] | 5921 | if (get_driver_type() == DRIVER_WCN) { | 
|  | 5922 | /* Enable the WCN driver in TDLS Explicit trigger mode | 
|  | 5923 | */ | 
|  | 5924 | wpa_command(intf, "SET tdls_external_control 0"); | 
|  | 5925 | wpa_command(intf, "SET tdls_trigger_control 0"); | 
|  | 5926 | } | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5927 | } | 
|  | 5928 |  | 
| Amarnath Hullur Subramanyam | 9c381f5 | 2017-03-17 00:04:41 -0700 | [diff] [blame] | 5929 | #ifdef MIRACAST | 
|  | 5930 | if (dut->program == PROGRAM_WFD || | 
|  | 5931 | dut->program == PROGRAM_DISPLAYR2) | 
|  | 5932 | miracast_sta_reset_default(dut, conn, cmd); | 
|  | 5933 | #endif /* MIRACAST */ | 
|  | 5934 |  | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5935 | switch (get_driver_type()) { | 
|  | 5936 | case DRIVER_ATHEROS: | 
|  | 5937 | sta_reset_default_ath(dut, intf, type); | 
|  | 5938 | break; | 
| Amarnath Hullur Subramanyam | 58f2a6e | 2018-01-31 03:36:00 -0800 | [diff] [blame] | 5939 | case DRIVER_WCN: | 
|  | 5940 | sta_reset_default_wcn(dut, intf, type); | 
|  | 5941 | break; | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5942 | default: | 
|  | 5943 | break; | 
|  | 5944 | } | 
|  | 5945 |  | 
|  | 5946 | #ifdef ANDROID_NAN | 
|  | 5947 | if (dut->program == PROGRAM_NAN) | 
|  | 5948 | nan_cmd_sta_reset_default(dut, conn, cmd); | 
|  | 5949 | #endif /* ANDROID_NAN */ | 
|  | 5950 |  | 
|  | 5951 | if (dut->program == PROGRAM_HS2_R2) { | 
|  | 5952 | unlink("SP/wi-fi.org/pps.xml"); | 
|  | 5953 | if (system("rm -r SP/*") != 0) { | 
|  | 5954 | } | 
|  | 5955 | unlink("next-client-cert.pem"); | 
|  | 5956 | unlink("next-client-key.pem"); | 
|  | 5957 | } | 
|  | 5958 |  | 
|  | 5959 | if (dut->program == PROGRAM_60GHZ) { | 
|  | 5960 | const char *dev_role = get_param(cmd, "DevRole"); | 
|  | 5961 |  | 
|  | 5962 | if (!dev_role) { | 
|  | 5963 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 5964 | "errorCode,Missing DevRole argument"); | 
|  | 5965 | return 0; | 
|  | 5966 | } | 
|  | 5967 |  | 
|  | 5968 | if (strcasecmp(dev_role, "STA") == 0) | 
|  | 5969 | dut->dev_role = DEVROLE_STA; | 
|  | 5970 | else if (strcasecmp(dev_role, "PCP") == 0) | 
|  | 5971 | dut->dev_role = DEVROLE_PCP; | 
|  | 5972 | else { | 
|  | 5973 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 5974 | "errorCode,Unknown DevRole"); | 
|  | 5975 | return 0; | 
|  | 5976 | } | 
|  | 5977 |  | 
|  | 5978 | if (dut->device_type == STA_unknown) { | 
|  | 5979 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 5980 | "Device type is not STA testbed or DUT"); | 
|  | 5981 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 5982 | "errorCode,Unknown device type"); | 
|  | 5983 | return 0; | 
|  | 5984 | } | 
|  | 5985 | } | 
|  | 5986 |  | 
|  | 5987 | wpa_command(intf, "WPS_ER_STOP"); | 
|  | 5988 | wpa_command(intf, "FLUSH"); | 
| vamsi krishna | f39bc1e | 2017-08-23 17:37:53 +0530 | [diff] [blame] | 5989 | wpa_command(intf, "ERP_FLUSH"); | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5990 | wpa_command(intf, "SET radio_disabled 0"); | 
|  | 5991 |  | 
|  | 5992 | if (dut->tmp_mac_addr && dut->set_macaddr) { | 
|  | 5993 | dut->tmp_mac_addr = 0; | 
|  | 5994 | if (system(dut->set_macaddr) != 0) { | 
|  | 5995 | sigma_dut_print(dut, DUT_MSG_INFO, "Failed to clear " | 
|  | 5996 | "temporary MAC address"); | 
|  | 5997 | } | 
|  | 5998 | } | 
|  | 5999 |  | 
|  | 6000 | set_ps(intf, dut, 0); | 
|  | 6001 |  | 
|  | 6002 | if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2) { | 
|  | 6003 | wpa_command(intf, "SET interworking 1"); | 
|  | 6004 | wpa_command(intf, "SET hs20 1"); | 
|  | 6005 | } | 
|  | 6006 |  | 
| Deepak Dhamdhere | 0fe0e45 | 2017-12-18 14:52:09 -0800 | [diff] [blame] | 6007 | if (dut->program == PROGRAM_HS2_R2 || | 
|  | 6008 | dut->program == PROGRAM_OCE) { | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6009 | wpa_command(intf, "SET pmf 1"); | 
|  | 6010 | } else { | 
|  | 6011 | wpa_command(intf, "SET pmf 0"); | 
|  | 6012 | } | 
|  | 6013 |  | 
|  | 6014 | hs2_clear_credentials(intf); | 
|  | 6015 | wpa_command(intf, "SET hessid 00:00:00:00:00:00"); | 
|  | 6016 | wpa_command(intf, "SET access_network_type 15"); | 
|  | 6017 |  | 
|  | 6018 | static_ip_file(0, NULL, NULL, NULL); | 
|  | 6019 | kill_dhcp_client(dut, intf); | 
|  | 6020 | clear_ip_addr(dut, intf); | 
|  | 6021 |  | 
|  | 6022 | dut->er_oper_performed = 0; | 
|  | 6023 | dut->er_oper_bssid[0] = '\0'; | 
|  | 6024 |  | 
| priyadharshini gowthaman | ad6cbba | 2016-10-04 10:39:58 -0700 | [diff] [blame] | 6025 | if (dut->program == PROGRAM_LOC) { | 
|  | 6026 | /* Disable Interworking by default */ | 
|  | 6027 | wpa_command(get_station_ifname(), "SET interworking 0"); | 
|  | 6028 | } | 
|  | 6029 |  | 
| Ashwini Patil | 0040258 | 2017-04-13 12:29:39 +0530 | [diff] [blame] | 6030 | if (dut->program == PROGRAM_MBO) { | 
|  | 6031 | free(dut->non_pref_ch_list); | 
|  | 6032 | dut->non_pref_ch_list = NULL; | 
| Ashwini Patil | 5acd738 | 2017-04-13 15:55:04 +0530 | [diff] [blame] | 6033 | free(dut->btm_query_cand_list); | 
|  | 6034 | dut->btm_query_cand_list = NULL; | 
| Ashwini Patil | c63161e | 2017-04-13 16:30:23 +0530 | [diff] [blame] | 6035 | wpa_command(intf, "SET reject_btm_req_reason 0"); | 
| Ashwini Patil | a75de5a | 2017-04-13 16:35:05 +0530 | [diff] [blame] | 6036 | wpa_command(intf, "SET ignore_assoc_disallow 0"); | 
| Ashwini Patil | d174f2c | 2017-04-13 16:49:46 +0530 | [diff] [blame] | 6037 | wpa_command(intf, "SET gas_address3 0"); | 
| Ashwini Patil | 9183fdb | 2017-04-13 16:58:25 +0530 | [diff] [blame] | 6038 | wpa_command(intf, "SET roaming 1"); | 
| Ashwini Patil | 0040258 | 2017-04-13 12:29:39 +0530 | [diff] [blame] | 6039 | } | 
|  | 6040 |  | 
| Jouni Malinen | 3c367e8 | 2017-06-23 17:01:47 +0300 | [diff] [blame] | 6041 | free(dut->rsne_override); | 
|  | 6042 | dut->rsne_override = NULL; | 
|  | 6043 |  | 
| Jouni Malinen | 6814313 | 2017-09-02 02:34:08 +0300 | [diff] [blame] | 6044 | free(dut->sae_commit_override); | 
|  | 6045 | dut->sae_commit_override = NULL; | 
|  | 6046 |  | 
| Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 6047 | dut->dpp_conf_id = -1; | 
| Jouni Malinen | b1dd21f | 2017-11-13 19:14:29 +0200 | [diff] [blame] | 6048 | free(dut->dpp_peer_uri); | 
|  | 6049 | dut->dpp_peer_uri = NULL; | 
| Jouni Malinen | 63d5041 | 2017-11-24 11:55:38 +0200 | [diff] [blame] | 6050 | dut->dpp_local_bootstrap = -1; | 
| Jouni Malinen | 5011fb5 | 2017-12-05 21:00:15 +0200 | [diff] [blame] | 6051 | wpa_command(intf, "SET dpp_config_processing 2"); | 
| Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 6052 |  | 
| Jouni Malinen | fac9cad | 2017-10-10 18:35:55 +0300 | [diff] [blame] | 6053 | wpa_command(intf, "VENDOR_ELEM_REMOVE 13 *"); | 
|  | 6054 |  | 
| vamsi krishna | a279949 | 2017-12-05 14:28:01 +0530 | [diff] [blame] | 6055 | if (dut->program == PROGRAM_OCE) { | 
| Ankita Bajaj | a2cb567 | 2017-10-25 16:08:28 +0530 | [diff] [blame] | 6056 | wpa_command(intf, "SET oce 1"); | 
| vamsi krishna | a279949 | 2017-12-05 14:28:01 +0530 | [diff] [blame] | 6057 | wpa_command(intf, "SET disable_fils 0"); | 
| Ankita Bajaj | 1bde794 | 2018-01-09 19:15:01 +0530 | [diff] [blame] | 6058 | wpa_command(intf, "FILS_HLP_REQ_FLUSH"); | 
|  | 6059 | dut->fils_hlp = 0; | 
|  | 6060 | #ifdef ANDROID | 
|  | 6061 | hlp_thread_cleanup(dut); | 
|  | 6062 | #endif /* ANDROID */ | 
| vamsi krishna | a279949 | 2017-12-05 14:28:01 +0530 | [diff] [blame] | 6063 | } | 
| Ankita Bajaj | a2cb567 | 2017-10-25 16:08:28 +0530 | [diff] [blame] | 6064 |  | 
| Sunil Dutt | 076081f | 2018-02-05 19:45:50 +0530 | [diff] [blame] | 6065 | #ifdef NL80211_SUPPORT | 
| Sunil Dutt | 4459508 | 2018-02-12 19:41:45 +0530 | [diff] [blame] | 6066 | if (get_driver_type() == DRIVER_WCN && | 
|  | 6067 | dut->config_rsnie == 1) { | 
|  | 6068 | dut->config_rsnie = 0; | 
|  | 6069 | sta_config_rsnie(dut, 0); | 
| Sunil Dutt | 076081f | 2018-02-05 19:45:50 +0530 | [diff] [blame] | 6070 | } | 
|  | 6071 | #endif /* NL80211_SUPPORT */ | 
|  | 6072 |  | 
| Sunil Dutt | febf8a8 | 2018-02-09 18:50:13 +0530 | [diff] [blame] | 6073 | if (dev_role && strcasecmp(dev_role, "STA-CFON") == 0) { | 
|  | 6074 | dut->dev_role = DEVROLE_STA_CFON; | 
|  | 6075 | return sta_cfon_reset_default(dut, conn, cmd); | 
|  | 6076 | } | 
|  | 6077 |  | 
|  | 6078 | if (dut->program != PROGRAM_VHT) | 
|  | 6079 | return cmd_sta_p2p_reset(dut, conn, cmd); | 
|  | 6080 |  | 
| Priyadharshini Gowthaman | a7dfd49 | 2015-11-09 14:34:08 -0800 | [diff] [blame] | 6081 | return 1; | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6082 | } | 
|  | 6083 |  | 
|  | 6084 |  | 
|  | 6085 | static int cmd_sta_get_events(struct sigma_dut *dut, struct sigma_conn *conn, | 
|  | 6086 | struct sigma_cmd *cmd) | 
|  | 6087 | { | 
|  | 6088 | const char *program = get_param(cmd, "Program"); | 
|  | 6089 |  | 
|  | 6090 | if (program == NULL) | 
|  | 6091 | return -1; | 
|  | 6092 | #ifdef ANDROID_NAN | 
|  | 6093 | if (strcasecmp(program, "NAN") == 0) | 
|  | 6094 | return nan_cmd_sta_get_events(dut, conn, cmd); | 
|  | 6095 | #endif /* ANDROID_NAN */ | 
|  | 6096 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter"); | 
|  | 6097 | return 0; | 
|  | 6098 | } | 
|  | 6099 |  | 
|  | 6100 |  | 
|  | 6101 | static int cmd_sta_exec_action(struct sigma_dut *dut, struct sigma_conn *conn, | 
|  | 6102 | struct sigma_cmd *cmd) | 
|  | 6103 | { | 
|  | 6104 | const char *program = get_param(cmd, "Prog"); | 
|  | 6105 |  | 
|  | 6106 | if (program == NULL) | 
|  | 6107 | return -1; | 
|  | 6108 | #ifdef ANDROID_NAN | 
|  | 6109 | if (strcasecmp(program, "NAN") == 0) | 
|  | 6110 | return nan_cmd_sta_exec_action(dut, conn, cmd); | 
|  | 6111 | #endif /* ANDROID_NAN */ | 
| priyadharshini gowthaman | d66913a | 2016-07-29 15:11:17 -0700 | [diff] [blame] | 6112 | if (strcasecmp(program, "Loc") == 0) | 
|  | 6113 | return loc_cmd_sta_exec_action(dut, conn, cmd); | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6114 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter"); | 
|  | 6115 | return 0; | 
|  | 6116 | } | 
|  | 6117 |  | 
|  | 6118 |  | 
|  | 6119 | static int cmd_sta_set_11n(struct sigma_dut *dut, struct sigma_conn *conn, | 
|  | 6120 | struct sigma_cmd *cmd) | 
|  | 6121 | { | 
|  | 6122 | const char *intf = get_param(cmd, "Interface"); | 
|  | 6123 | const char *val, *mcs32, *rate; | 
|  | 6124 |  | 
|  | 6125 | val = get_param(cmd, "GREENFIELD"); | 
|  | 6126 | if (val) { | 
|  | 6127 | if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) { | 
|  | 6128 | /* Enable GD */ | 
|  | 6129 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 6130 | "ErrorCode,GF not supported"); | 
|  | 6131 | return 0; | 
|  | 6132 | } | 
|  | 6133 | } | 
|  | 6134 |  | 
|  | 6135 | val = get_param(cmd, "SGI20"); | 
|  | 6136 | if (val) { | 
|  | 6137 | switch (get_driver_type()) { | 
|  | 6138 | case DRIVER_ATHEROS: | 
|  | 6139 | ath_sta_set_sgi(dut, intf, val); | 
|  | 6140 | break; | 
|  | 6141 | default: | 
|  | 6142 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 6143 | "ErrorCode,SGI20 not supported"); | 
|  | 6144 | return 0; | 
|  | 6145 | } | 
|  | 6146 | } | 
|  | 6147 |  | 
|  | 6148 | mcs32 = get_param(cmd, "MCS32"); /* HT Duplicate Mode Enable/Disable */ | 
|  | 6149 | rate = get_param(cmd, "MCS_FIXEDRATE"); /* Fixed MCS rate (0..31) */ | 
|  | 6150 | if (mcs32 && rate) { | 
|  | 6151 | /* TODO */ | 
|  | 6152 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 6153 | "ErrorCode,MCS32,MCS_FIXEDRATE not supported"); | 
|  | 6154 | return 0; | 
|  | 6155 | } else if (mcs32 && !rate) { | 
|  | 6156 | /* TODO */ | 
|  | 6157 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 6158 | "ErrorCode,MCS32 not supported"); | 
|  | 6159 | return 0; | 
|  | 6160 | } else if (!mcs32 && rate) { | 
|  | 6161 | switch (get_driver_type()) { | 
|  | 6162 | case DRIVER_ATHEROS: | 
| priyadharshini gowthaman | e5e2517 | 2015-12-08 14:53:48 -0800 | [diff] [blame] | 6163 | novap_reset(dut, intf); | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6164 | ath_sta_set_11nrates(dut, intf, rate); | 
|  | 6165 | break; | 
|  | 6166 | default: | 
|  | 6167 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 6168 | "ErrorCode,MCS32_FIXEDRATE not supported"); | 
|  | 6169 | return 0; | 
|  | 6170 | } | 
|  | 6171 | } | 
|  | 6172 |  | 
|  | 6173 | return cmd_sta_set_wireless_common(intf, dut, conn, cmd); | 
|  | 6174 | } | 
|  | 6175 |  | 
|  | 6176 |  | 
|  | 6177 | static int cmd_sta_set_wireless_vht(struct sigma_dut *dut, | 
|  | 6178 | struct sigma_conn *conn, | 
|  | 6179 | struct sigma_cmd *cmd) | 
|  | 6180 | { | 
|  | 6181 | const char *intf = get_param(cmd, "Interface"); | 
|  | 6182 | const char *val; | 
|  | 6183 | char buf[30]; | 
|  | 6184 | int tkip = -1; | 
|  | 6185 | int wep = -1; | 
|  | 6186 |  | 
|  | 6187 | val = get_param(cmd, "SGI80"); | 
|  | 6188 | if (val) { | 
|  | 6189 | int sgi80; | 
|  | 6190 |  | 
|  | 6191 | sgi80 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0; | 
|  | 6192 | snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d", intf, sgi80); | 
|  | 6193 | if (system(buf) != 0) { | 
|  | 6194 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 6195 | "iwpriv shortgi failed"); | 
|  | 6196 | } | 
|  | 6197 | } | 
|  | 6198 |  | 
|  | 6199 | val = get_param(cmd, "TxBF"); | 
|  | 6200 | if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) { | 
|  | 6201 | snprintf(buf, sizeof(buf), "iwpriv %s vhtsubfee 1", intf); | 
|  | 6202 | if (system(buf) != 0) { | 
|  | 6203 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 6204 | "iwpriv vhtsubfee failed"); | 
|  | 6205 | } | 
|  | 6206 | snprintf(buf, sizeof(buf), "iwpriv %s vhtsubfer 1", intf); | 
|  | 6207 | if (system(buf) != 0) { | 
|  | 6208 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 6209 | "iwpriv vhtsubfer failed"); | 
|  | 6210 | } | 
|  | 6211 | } | 
|  | 6212 |  | 
|  | 6213 | val = get_param(cmd, "MU_TxBF"); | 
|  | 6214 | if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) { | 
|  | 6215 | switch (get_driver_type()) { | 
|  | 6216 | case DRIVER_ATHEROS: | 
|  | 6217 | ath_sta_set_txsp_stream(dut, intf, "1SS"); | 
|  | 6218 | ath_sta_set_rxsp_stream(dut, intf, "1SS"); | 
|  | 6219 | case DRIVER_WCN: | 
|  | 6220 | if (wcn_sta_set_sp_stream(dut, intf, "1SS") < 0) { | 
|  | 6221 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 6222 | "ErrorCode,Failed to set RX/TXSP_STREAM"); | 
|  | 6223 | return 0; | 
|  | 6224 | } | 
|  | 6225 | default: | 
|  | 6226 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 6227 | "Setting SP_STREAM not supported"); | 
|  | 6228 | break; | 
|  | 6229 | } | 
|  | 6230 | snprintf(buf, sizeof(buf), "iwpriv %s vhtmubfee 1", intf); | 
|  | 6231 | if (system(buf) != 0) { | 
|  | 6232 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 6233 | "iwpriv vhtmubfee failed"); | 
|  | 6234 | } | 
|  | 6235 | snprintf(buf, sizeof(buf), "iwpriv %s vhtmubfer 1", intf); | 
|  | 6236 | if (system(buf) != 0) { | 
|  | 6237 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 6238 | "iwpriv vhtmubfer failed"); | 
|  | 6239 | } | 
|  | 6240 | } | 
|  | 6241 |  | 
|  | 6242 | val = get_param(cmd, "LDPC"); | 
|  | 6243 | if (val) { | 
|  | 6244 | int ldpc; | 
|  | 6245 |  | 
|  | 6246 | ldpc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0; | 
|  | 6247 | snprintf(buf, sizeof(buf), "iwpriv %s ldpc %d", intf, ldpc); | 
|  | 6248 | if (system(buf) != 0) { | 
|  | 6249 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 6250 | "iwpriv ldpc failed"); | 
|  | 6251 | } | 
|  | 6252 | } | 
|  | 6253 |  | 
| Amarnath Hullur Subramanyam | 7bae60e | 2018-01-31 03:46:50 -0800 | [diff] [blame] | 6254 | val = get_param(cmd, "BCC"); | 
|  | 6255 | if (val) { | 
|  | 6256 | int bcc; | 
|  | 6257 |  | 
|  | 6258 | bcc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0; | 
|  | 6259 | /* use LDPC iwpriv itself to set bcc coding, bcc coding | 
|  | 6260 | * is mutually exclusive to bcc */ | 
|  | 6261 | snprintf(buf, sizeof(buf), "iwpriv %s ldpc %d", intf, !bcc); | 
|  | 6262 | if (system(buf) != 0) { | 
|  | 6263 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 6264 | "Enabling/Disabling of BCC failed"); | 
|  | 6265 | } | 
|  | 6266 | } | 
|  | 6267 |  | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6268 | val = get_param(cmd, "opt_md_notif_ie"); | 
|  | 6269 | if (val) { | 
|  | 6270 | char *result = NULL; | 
|  | 6271 | char delim[] = ";"; | 
|  | 6272 | char token[30]; | 
|  | 6273 | int value, config_val = 0; | 
| Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 6274 | char *saveptr; | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6275 |  | 
| Peng Xu | b8fc5cc | 2017-05-10 17:27:28 -0700 | [diff] [blame] | 6276 | strlcpy(token, val, sizeof(token)); | 
| Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 6277 | result = strtok_r(token, delim, &saveptr); | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6278 |  | 
|  | 6279 | /* Extract the NSS information */ | 
|  | 6280 | if (result) { | 
|  | 6281 | value = atoi(result); | 
|  | 6282 | switch (value) { | 
|  | 6283 | case 1: | 
|  | 6284 | config_val = 1; | 
|  | 6285 | break; | 
|  | 6286 | case 2: | 
|  | 6287 | config_val = 3; | 
|  | 6288 | break; | 
|  | 6289 | case 3: | 
|  | 6290 | config_val = 7; | 
|  | 6291 | break; | 
|  | 6292 | case 4: | 
|  | 6293 | config_val = 15; | 
|  | 6294 | break; | 
|  | 6295 | default: | 
|  | 6296 | config_val = 3; | 
|  | 6297 | break; | 
|  | 6298 | } | 
|  | 6299 |  | 
|  | 6300 | snprintf(buf, sizeof(buf), "iwpriv %s rxchainmask %d", | 
|  | 6301 | intf, config_val); | 
|  | 6302 | if (system(buf) != 0) { | 
|  | 6303 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 6304 | "iwpriv rxchainmask failed"); | 
|  | 6305 | } | 
|  | 6306 |  | 
|  | 6307 | snprintf(buf, sizeof(buf), "iwpriv %s txchainmask %d", | 
|  | 6308 | intf, config_val); | 
|  | 6309 | if (system(buf) != 0) { | 
|  | 6310 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 6311 | "iwpriv txchainmask failed"); | 
|  | 6312 | } | 
|  | 6313 | } | 
|  | 6314 |  | 
|  | 6315 | /* Extract the channel width information */ | 
| Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 6316 | result = strtok_r(NULL, delim, &saveptr); | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6317 | if (result) { | 
|  | 6318 | value = atoi(result); | 
|  | 6319 | switch (value) { | 
|  | 6320 | case 20: | 
|  | 6321 | config_val = 0; | 
|  | 6322 | break; | 
|  | 6323 | case 40: | 
|  | 6324 | config_val = 1; | 
|  | 6325 | break; | 
|  | 6326 | case 80: | 
|  | 6327 | config_val = 2; | 
|  | 6328 | break; | 
|  | 6329 | case 160: | 
|  | 6330 | config_val = 3; | 
|  | 6331 | break; | 
|  | 6332 | default: | 
|  | 6333 | config_val = 2; | 
|  | 6334 | break; | 
|  | 6335 | } | 
|  | 6336 |  | 
|  | 6337 | dut->chwidth = config_val; | 
|  | 6338 |  | 
|  | 6339 | snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d", | 
|  | 6340 | intf, config_val); | 
|  | 6341 | if (system(buf) != 0) { | 
|  | 6342 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 6343 | "iwpriv chwidth failed"); | 
|  | 6344 | } | 
|  | 6345 | } | 
|  | 6346 |  | 
|  | 6347 | snprintf(buf, sizeof(buf), "iwpriv %s opmode_notify 1", intf); | 
|  | 6348 | if (system(buf) != 0) { | 
|  | 6349 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 6350 | "iwpriv opmode_notify failed"); | 
|  | 6351 | } | 
|  | 6352 | } | 
|  | 6353 |  | 
|  | 6354 | val = get_param(cmd, "nss_mcs_cap"); | 
|  | 6355 | if (val) { | 
|  | 6356 | int nss, mcs; | 
|  | 6357 | char token[20]; | 
|  | 6358 | char *result = NULL; | 
|  | 6359 | unsigned int vht_mcsmap = 0; | 
| Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 6360 | char *saveptr; | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6361 |  | 
| Peng Xu | b8fc5cc | 2017-05-10 17:27:28 -0700 | [diff] [blame] | 6362 | strlcpy(token, val, sizeof(token)); | 
| Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 6363 | result = strtok_r(token, ";", &saveptr); | 
| Pradeep Reddy POTTETI | cd649a2 | 2016-01-29 12:55:59 +0530 | [diff] [blame] | 6364 | if (!result) { | 
|  | 6365 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 6366 | "VHT NSS not specified"); | 
|  | 6367 | return 0; | 
|  | 6368 | } | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6369 | nss = atoi(result); | 
|  | 6370 |  | 
|  | 6371 | snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss); | 
|  | 6372 | if (system(buf) != 0) { | 
|  | 6373 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 6374 | "iwpriv nss failed"); | 
|  | 6375 | } | 
|  | 6376 |  | 
| Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 6377 | result = strtok_r(NULL, ";", &saveptr); | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6378 | if (result == NULL) { | 
|  | 6379 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 6380 | "VHTMCS NOT SPECIFIED!"); | 
|  | 6381 | return 0; | 
|  | 6382 | } | 
| Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 6383 | result = strtok_r(result, "-", &saveptr); | 
|  | 6384 | result = strtok_r(NULL, "-", &saveptr); | 
| Pradeep Reddy POTTETI | cd649a2 | 2016-01-29 12:55:59 +0530 | [diff] [blame] | 6385 | if (!result) { | 
|  | 6386 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 6387 | "VHT MCS not specified"); | 
|  | 6388 | return 0; | 
|  | 6389 | } | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6390 | mcs = atoi(result); | 
|  | 6391 |  | 
|  | 6392 | snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs %d", intf, mcs); | 
|  | 6393 | if (system(buf) != 0) { | 
|  | 6394 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 6395 | "iwpriv mcs failed"); | 
|  | 6396 | } | 
|  | 6397 |  | 
|  | 6398 | switch (nss) { | 
|  | 6399 | case 1: | 
|  | 6400 | switch (mcs) { | 
|  | 6401 | case 7: | 
|  | 6402 | vht_mcsmap = 0xfffc; | 
|  | 6403 | break; | 
|  | 6404 | case 8: | 
|  | 6405 | vht_mcsmap = 0xfffd; | 
|  | 6406 | break; | 
|  | 6407 | case 9: | 
|  | 6408 | vht_mcsmap = 0xfffe; | 
|  | 6409 | break; | 
|  | 6410 | default: | 
|  | 6411 | vht_mcsmap = 0xfffe; | 
|  | 6412 | break; | 
|  | 6413 | } | 
|  | 6414 | break; | 
|  | 6415 | case 2: | 
|  | 6416 | switch (mcs) { | 
|  | 6417 | case 7: | 
|  | 6418 | vht_mcsmap = 0xfff0; | 
|  | 6419 | break; | 
|  | 6420 | case 8: | 
|  | 6421 | vht_mcsmap = 0xfff5; | 
|  | 6422 | break; | 
|  | 6423 | case 9: | 
|  | 6424 | vht_mcsmap = 0xfffa; | 
|  | 6425 | break; | 
|  | 6426 | default: | 
|  | 6427 | vht_mcsmap = 0xfffa; | 
|  | 6428 | break; | 
|  | 6429 | } | 
|  | 6430 | break; | 
|  | 6431 | case 3: | 
|  | 6432 | switch (mcs) { | 
|  | 6433 | case 7: | 
|  | 6434 | vht_mcsmap = 0xffc0; | 
|  | 6435 | break; | 
|  | 6436 | case 8: | 
|  | 6437 | vht_mcsmap = 0xffd5; | 
|  | 6438 | break; | 
|  | 6439 | case 9: | 
|  | 6440 | vht_mcsmap = 0xffea; | 
|  | 6441 | break; | 
|  | 6442 | default: | 
|  | 6443 | vht_mcsmap = 0xffea; | 
|  | 6444 | break; | 
|  | 6445 | } | 
|  | 6446 | break; | 
|  | 6447 | default: | 
|  | 6448 | vht_mcsmap = 0xffea; | 
|  | 6449 | break; | 
|  | 6450 | } | 
|  | 6451 | snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0x%04x", | 
|  | 6452 | intf, vht_mcsmap); | 
|  | 6453 | if (system(buf) != 0) { | 
|  | 6454 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 6455 | "iwpriv vht_mcsmap failed"); | 
|  | 6456 | } | 
|  | 6457 | } | 
|  | 6458 |  | 
|  | 6459 | /* UNSUPPORTED: val = get_param(cmd, "Tx_lgi_rate"); */ | 
|  | 6460 |  | 
|  | 6461 | val = get_param(cmd, "Vht_tkip"); | 
|  | 6462 | if (val) | 
|  | 6463 | tkip = strcmp(val, "1") == 0 ||	strcasecmp(val, "Enable") == 0; | 
|  | 6464 |  | 
|  | 6465 | val = get_param(cmd, "Vht_wep"); | 
|  | 6466 | if (val) | 
|  | 6467 | wep = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0; | 
|  | 6468 |  | 
|  | 6469 | if (tkip != -1 || wep != -1) { | 
|  | 6470 | if ((tkip == 1 && wep != 0) || (wep == 1 && tkip != 0)) { | 
|  | 6471 | snprintf(buf, sizeof(buf), "iwpriv %s htweptkip 1", | 
|  | 6472 | intf); | 
|  | 6473 | } else if ((tkip == 0 && wep != 1) || (wep == 0 && tkip != 1)) { | 
|  | 6474 | snprintf(buf, sizeof(buf), "iwpriv %s htweptkip 0", | 
|  | 6475 | intf); | 
|  | 6476 | } else { | 
|  | 6477 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 6478 | "ErrorCode,mixed mode of VHT TKIP/WEP not supported"); | 
|  | 6479 | return 0; | 
|  | 6480 | } | 
|  | 6481 |  | 
|  | 6482 | if (system(buf) != 0) { | 
|  | 6483 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 6484 | "iwpriv htweptkip failed"); | 
|  | 6485 | } | 
|  | 6486 | } | 
|  | 6487 |  | 
|  | 6488 | val = get_param(cmd, "txBandwidth"); | 
|  | 6489 | if (val) { | 
|  | 6490 | switch (get_driver_type()) { | 
| Amarnath Hullur Subramanyam | 4f86029 | 2018-01-31 03:49:35 -0800 | [diff] [blame] | 6491 | case DRIVER_WCN: | 
|  | 6492 | if (wcn_sta_set_width(dut, intf, val) < 0) { | 
|  | 6493 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 6494 | "ErrorCode,Failed to set txBandwidth"); | 
|  | 6495 | return 0; | 
|  | 6496 | } | 
|  | 6497 | break; | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6498 | case DRIVER_ATHEROS: | 
|  | 6499 | if (ath_set_width(dut, conn, intf, val) < 0) { | 
|  | 6500 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 6501 | "ErrorCode,Failed to set txBandwidth"); | 
|  | 6502 | return 0; | 
|  | 6503 | } | 
|  | 6504 | break; | 
|  | 6505 | default: | 
|  | 6506 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 6507 | "Setting txBandwidth not supported"); | 
|  | 6508 | break; | 
|  | 6509 | } | 
|  | 6510 | } | 
|  | 6511 |  | 
|  | 6512 | return cmd_sta_set_wireless_common(intf, dut, conn, cmd); | 
|  | 6513 | } | 
|  | 6514 |  | 
|  | 6515 |  | 
|  | 6516 | static int sta_set_wireless_60g(struct sigma_dut *dut, | 
|  | 6517 | struct sigma_conn *conn, | 
|  | 6518 | struct sigma_cmd *cmd) | 
|  | 6519 | { | 
|  | 6520 | const char *dev_role = get_param(cmd, "DevRole"); | 
|  | 6521 |  | 
|  | 6522 | if (!dev_role) { | 
|  | 6523 | send_resp(dut, conn, SIGMA_INVALID, | 
|  | 6524 | "ErrorCode,DevRole not specified"); | 
|  | 6525 | return 0; | 
|  | 6526 | } | 
|  | 6527 |  | 
|  | 6528 | if (strcasecmp(dev_role, "PCP") == 0) | 
|  | 6529 | return sta_set_60g_pcp(dut, conn, cmd); | 
|  | 6530 | if (strcasecmp(dev_role, "STA") == 0) | 
|  | 6531 | return sta_set_60g_sta(dut, conn, cmd); | 
|  | 6532 | send_resp(dut, conn, SIGMA_INVALID, | 
|  | 6533 | "ErrorCode,DevRole not supported"); | 
|  | 6534 | return 0; | 
|  | 6535 | } | 
|  | 6536 |  | 
|  | 6537 |  | 
| Ankita Bajaj | 0d5825b | 2017-10-25 16:20:17 +0530 | [diff] [blame] | 6538 | static int sta_set_wireless_oce(struct sigma_dut *dut, struct sigma_conn *conn, | 
|  | 6539 | struct sigma_cmd *cmd) | 
|  | 6540 | { | 
|  | 6541 | int status; | 
|  | 6542 | const char *intf = get_param(cmd, "Interface"); | 
|  | 6543 | const char *val = get_param(cmd, "DevRole"); | 
|  | 6544 |  | 
|  | 6545 | if (val && strcasecmp(val, "STA-CFON") == 0) { | 
|  | 6546 | status = sta_cfon_set_wireless(dut, conn, cmd); | 
|  | 6547 | if (status) | 
|  | 6548 | return status; | 
|  | 6549 | } | 
|  | 6550 | return cmd_sta_set_wireless_common(intf, dut, conn, cmd); | 
|  | 6551 | } | 
|  | 6552 |  | 
|  | 6553 |  | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6554 | static int cmd_sta_set_wireless(struct sigma_dut *dut, struct sigma_conn *conn, | 
|  | 6555 | struct sigma_cmd *cmd) | 
|  | 6556 | { | 
|  | 6557 | const char *val; | 
|  | 6558 |  | 
|  | 6559 | val = get_param(cmd, "Program"); | 
|  | 6560 | if (val) { | 
|  | 6561 | if (strcasecmp(val, "11n") == 0) | 
|  | 6562 | return cmd_sta_set_11n(dut, conn, cmd); | 
| Amarnath Hullur Subramanyam | 4f86029 | 2018-01-31 03:49:35 -0800 | [diff] [blame] | 6563 | if (strcasecmp(val, "VHT") == 0 || strcasecmp(val, "HE") == 0) | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6564 | return cmd_sta_set_wireless_vht(dut, conn, cmd); | 
|  | 6565 | if (strcasecmp(val, "60ghz") == 0) | 
|  | 6566 | return sta_set_wireless_60g(dut, conn, cmd); | 
| Ankita Bajaj | 0d5825b | 2017-10-25 16:20:17 +0530 | [diff] [blame] | 6567 | if (strcasecmp(val, "OCE") == 0) | 
|  | 6568 | return sta_set_wireless_oce(dut, conn, cmd); | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6569 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 6570 | "ErrorCode,Program value not supported"); | 
|  | 6571 | } else { | 
|  | 6572 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 6573 | "ErrorCode,Program argument not available"); | 
|  | 6574 | } | 
|  | 6575 |  | 
|  | 6576 | return 0; | 
|  | 6577 | } | 
|  | 6578 |  | 
|  | 6579 |  | 
|  | 6580 | static void ath_sta_inject_frame(struct sigma_dut *dut, const char *intf, | 
|  | 6581 | int tid) | 
|  | 6582 | { | 
|  | 6583 | char buf[100]; | 
|  | 6584 | int tid_to_dscp [] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 }; | 
|  | 6585 |  | 
| Pradeep Reddy POTTETI | d31d132 | 2016-10-13 17:22:03 +0530 | [diff] [blame] | 6586 | if (tid < 0 || | 
|  | 6587 | tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) { | 
|  | 6588 | sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid); | 
|  | 6589 | return; | 
|  | 6590 | } | 
|  | 6591 |  | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6592 | /* | 
|  | 6593 | * Two ways to ensure that addba request with a | 
|  | 6594 | * non zero TID could be sent out. EV 117296 | 
|  | 6595 | */ | 
|  | 6596 | snprintf(buf, sizeof(buf), | 
|  | 6597 | "ping -c 8 -Q %d `arp -a | grep wlan0 | awk '{print $2}' | tr -d '()'`", | 
|  | 6598 | tid); | 
|  | 6599 | if (system(buf) != 0) { | 
|  | 6600 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 6601 | "Ping did not send out"); | 
|  | 6602 | } | 
|  | 6603 |  | 
|  | 6604 | snprintf(buf, sizeof(buf), | 
|  | 6605 | "iwconfig %s | grep Access | awk '{print $6}' > %s", | 
|  | 6606 | intf, VI_QOS_TMP_FILE); | 
|  | 6607 | if (system(buf) != 0) | 
|  | 6608 | return; | 
|  | 6609 |  | 
|  | 6610 | snprintf(buf, sizeof(buf), | 
|  | 6611 | "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s", | 
|  | 6612 | intf, VI_QOS_TMP_FILE); | 
|  | 6613 | if (system(buf) != 0) | 
|  | 6614 | sigma_dut_print(dut, DUT_MSG_ERROR, "HWaddr matching failed"); | 
|  | 6615 |  | 
|  | 6616 | snprintf(buf,sizeof(buf), "sed -n '3,$p' %s >> %s", | 
|  | 6617 | VI_QOS_REFFILE, VI_QOS_TMP_FILE); | 
|  | 6618 | if (system(buf) != 0) { | 
|  | 6619 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 6620 | "VI_QOS_TEMP_FILE generation error failed"); | 
|  | 6621 | } | 
|  | 6622 | snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s", | 
|  | 6623 | tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE); | 
|  | 6624 | if (system(buf) != 0) { | 
|  | 6625 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 6626 | "VI_QOS_FILE generation failed"); | 
|  | 6627 | } | 
|  | 6628 |  | 
|  | 6629 | snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s", | 
|  | 6630 | tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE); | 
|  | 6631 | if (system(buf) != 0) { | 
|  | 6632 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 6633 | "VI_QOS_FILE generation failed"); | 
|  | 6634 | } | 
|  | 6635 |  | 
|  | 6636 | snprintf(buf, sizeof(buf), "ethinject %s %s", intf, VI_QOS_FILE); | 
|  | 6637 | if (system(buf) != 0) { | 
|  | 6638 | } | 
|  | 6639 | } | 
|  | 6640 |  | 
|  | 6641 |  | 
|  | 6642 | static int ath_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn, | 
|  | 6643 | struct sigma_cmd *cmd) | 
|  | 6644 | { | 
|  | 6645 | const char *intf = get_param(cmd, "Interface"); | 
|  | 6646 | const char *val; | 
|  | 6647 | int tid = 0; | 
|  | 6648 | char buf[100]; | 
|  | 6649 |  | 
|  | 6650 | val = get_param(cmd, "TID"); | 
|  | 6651 | if (val) { | 
|  | 6652 | tid = atoi(val); | 
|  | 6653 | if (tid) | 
|  | 6654 | ath_sta_inject_frame(dut, intf, tid); | 
|  | 6655 | } | 
|  | 6656 |  | 
|  | 6657 | /* Command sequence for ADDBA request on Peregrine based devices */ | 
|  | 6658 | snprintf(buf, sizeof(buf), "iwpriv %s setaddbaoper 1", intf); | 
|  | 6659 | if (system(buf) != 0) { | 
|  | 6660 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 6661 | "iwpriv setaddbaoper failed"); | 
|  | 6662 | } | 
|  | 6663 |  | 
|  | 6664 | snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4", intf, tid); | 
|  | 6665 | if (system(buf) != 0) { | 
|  | 6666 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 6667 | "wifitool senddelba failed"); | 
|  | 6668 | } | 
|  | 6669 |  | 
|  | 6670 | snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64", intf, tid); | 
|  | 6671 | if (system(buf) != 0) { | 
|  | 6672 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 6673 | "wifitool sendaddba failed"); | 
|  | 6674 | } | 
|  | 6675 |  | 
|  | 6676 | /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */ | 
|  | 6677 |  | 
|  | 6678 | return 1; | 
|  | 6679 | } | 
|  | 6680 |  | 
|  | 6681 |  | 
| Lior David | 9981b51 | 2017-01-20 13:16:40 +0200 | [diff] [blame] | 6682 | #ifdef __linux__ | 
|  | 6683 |  | 
|  | 6684 | static int wil6210_send_addba(struct sigma_dut *dut, const char *dest_mac, | 
|  | 6685 | int agg_size) | 
|  | 6686 | { | 
|  | 6687 | char dir[128], buf[128]; | 
|  | 6688 | FILE *f; | 
|  | 6689 | regex_t re; | 
|  | 6690 | regmatch_t m[2]; | 
|  | 6691 | int rc, ret = -1, vring_id, found; | 
|  | 6692 |  | 
|  | 6693 | if (wil6210_get_debugfs_dir(dut, dir, sizeof(dir))) { | 
|  | 6694 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 6695 | "failed to get wil6210 debugfs dir"); | 
|  | 6696 | return -1; | 
|  | 6697 | } | 
|  | 6698 |  | 
|  | 6699 | snprintf(buf, sizeof(buf), "%s/vrings", dir); | 
|  | 6700 | f = fopen(buf, "r"); | 
|  | 6701 | if (!f) { | 
|  | 6702 | sigma_dut_print(dut, DUT_MSG_ERROR, "failed to open: %s", buf); | 
|  | 6703 | return -1; | 
|  | 6704 | } | 
|  | 6705 |  | 
|  | 6706 | if (regcomp(&re, "VRING tx_[ \t]*([0-9]+)", REG_EXTENDED)) { | 
|  | 6707 | sigma_dut_print(dut, DUT_MSG_ERROR, "regcomp failed"); | 
|  | 6708 | goto out; | 
|  | 6709 | } | 
|  | 6710 |  | 
|  | 6711 | /* find TX VRING for the mac address */ | 
|  | 6712 | found = 0; | 
|  | 6713 | while (fgets(buf, sizeof(buf), f)) { | 
|  | 6714 | if (strcasestr(buf, dest_mac)) { | 
|  | 6715 | found = 1; | 
|  | 6716 | break; | 
|  | 6717 | } | 
|  | 6718 | } | 
|  | 6719 |  | 
|  | 6720 | if (!found) { | 
|  | 6721 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 6722 | "no TX VRING for %s", dest_mac); | 
|  | 6723 | goto out; | 
|  | 6724 | } | 
|  | 6725 |  | 
|  | 6726 | /* extract VRING ID, "VRING tx_<id> = {" */ | 
|  | 6727 | if (!fgets(buf, sizeof(buf), f)) { | 
|  | 6728 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 6729 | "no VRING start line for %s", dest_mac); | 
|  | 6730 | goto out; | 
|  | 6731 | } | 
|  | 6732 |  | 
|  | 6733 | rc = regexec(&re, buf, 2, m, 0); | 
|  | 6734 | regfree(&re); | 
|  | 6735 | if (rc || m[1].rm_so < 0) { | 
|  | 6736 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 6737 | "no VRING TX ID for %s", dest_mac); | 
|  | 6738 | goto out; | 
|  | 6739 | } | 
|  | 6740 | buf[m[1].rm_eo] = 0; | 
|  | 6741 | vring_id = atoi(&buf[m[1].rm_so]); | 
|  | 6742 |  | 
|  | 6743 | /* send the addba command */ | 
|  | 6744 | fclose(f); | 
|  | 6745 | snprintf(buf, sizeof(buf), "%s/back", dir); | 
|  | 6746 | f = fopen(buf, "w"); | 
|  | 6747 | if (!f) { | 
|  | 6748 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 6749 | "failed to open: %s", buf); | 
|  | 6750 | return -1; | 
|  | 6751 | } | 
|  | 6752 |  | 
|  | 6753 | fprintf(f, "add %d %d\n", vring_id, agg_size); | 
|  | 6754 |  | 
|  | 6755 | ret = 0; | 
|  | 6756 |  | 
|  | 6757 | out: | 
|  | 6758 | fclose(f); | 
|  | 6759 |  | 
|  | 6760 | return ret; | 
|  | 6761 | } | 
|  | 6762 |  | 
|  | 6763 |  | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6764 | static int send_addba_60g(struct sigma_dut *dut, struct sigma_conn *conn, | 
|  | 6765 | struct sigma_cmd *cmd) | 
|  | 6766 | { | 
|  | 6767 | const char *val; | 
|  | 6768 | int tid = 0; | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6769 |  | 
|  | 6770 | val = get_param(cmd, "TID"); | 
|  | 6771 | if (val) { | 
|  | 6772 | tid = atoi(val); | 
|  | 6773 | if (tid != 0) { | 
|  | 6774 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 6775 | "Ignore TID %d for send_addba use TID 0 for 60g since only 0 required on TX", | 
|  | 6776 | tid); | 
|  | 6777 | } | 
|  | 6778 | } | 
|  | 6779 |  | 
|  | 6780 | val = get_param(cmd, "Dest_mac"); | 
|  | 6781 | if (!val) { | 
|  | 6782 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 6783 | "Currently not supporting addba for 60G without Dest_mac"); | 
|  | 6784 | return SIGMA_DUT_ERROR_CALLER_SEND_STATUS; | 
|  | 6785 | } | 
|  | 6786 |  | 
| Lior David | 9981b51 | 2017-01-20 13:16:40 +0200 | [diff] [blame] | 6787 | if (wil6210_send_addba(dut, val, dut->back_rcv_buf)) | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6788 | return -1; | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6789 |  | 
|  | 6790 | return 1; | 
|  | 6791 | } | 
|  | 6792 |  | 
| Lior David | 9981b51 | 2017-01-20 13:16:40 +0200 | [diff] [blame] | 6793 | #endif /* __linux__ */ | 
|  | 6794 |  | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6795 |  | 
| Amarnath Hullur Subramanyam | a72c016 | 2018-02-27 14:49:09 -0800 | [diff] [blame] | 6796 | static int wcn_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn, | 
|  | 6797 | struct sigma_cmd *cmd) | 
|  | 6798 | { | 
|  | 6799 | #ifdef NL80211_SUPPORT | 
|  | 6800 | const char *intf = get_param(cmd, "Interface"); | 
|  | 6801 | const char *val; | 
|  | 6802 | int tid = -1; | 
|  | 6803 | int bufsize = 64; | 
|  | 6804 | struct nl_msg *msg; | 
|  | 6805 | int ret = 0; | 
|  | 6806 | struct nlattr *params; | 
|  | 6807 | int ifindex; | 
|  | 6808 |  | 
|  | 6809 | val = get_param(cmd, "TID"); | 
|  | 6810 | if (val) | 
|  | 6811 | tid = atoi(val); | 
|  | 6812 |  | 
|  | 6813 | if (tid == -1) { | 
|  | 6814 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 6815 | "ErrorCode,sta_send_addba tid invalid"); | 
|  | 6816 | return 0; | 
|  | 6817 | } | 
|  | 6818 |  | 
|  | 6819 | /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */ | 
|  | 6820 |  | 
|  | 6821 | ifindex = if_nametoindex(intf); | 
|  | 6822 | if (ifindex == 0) { | 
|  | 6823 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 6824 | "%s: Index for interface %s failed", | 
|  | 6825 | __func__, intf); | 
|  | 6826 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 6827 | "ErrorCode,sta_send_addba interface invalid"); | 
|  | 6828 | return 0; | 
|  | 6829 | } | 
|  | 6830 |  | 
|  | 6831 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, | 
|  | 6832 | NL80211_CMD_VENDOR)) || | 
|  | 6833 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || | 
|  | 6834 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | 
|  | 6835 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | 
|  | 6836 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || | 
|  | 6837 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | 
|  | 6838 | nla_put_u8(msg, | 
|  | 6839 | QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADD_DEL_BA_SESSION, | 
|  | 6840 | QCA_WLAN_ADD_BA) || | 
|  | 6841 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BA_TID, | 
|  | 6842 | tid) || | 
|  | 6843 | nla_put_u8(msg, | 
|  | 6844 | QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE, | 
|  | 6845 | bufsize)) { | 
|  | 6846 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 6847 | "%s: err in adding vendor_cmd and vendor_data", | 
|  | 6848 | __func__); | 
|  | 6849 | nlmsg_free(msg); | 
|  | 6850 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 6851 | "ErrorCode,sta_send_addba err in adding vendor_cmd and vendor_data"); | 
|  | 6852 | return 0; | 
|  | 6853 | } | 
|  | 6854 | nla_nest_end(msg, params); | 
|  | 6855 |  | 
|  | 6856 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); | 
|  | 6857 | if (ret) { | 
|  | 6858 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 6859 | "%s: err in send_and_recv_msgs, ret=%d", | 
|  | 6860 | __func__, ret); | 
|  | 6861 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 6862 | "ErrorCode,sta_send_addba err in send_and_recv_msgs"); | 
|  | 6863 | return 0; | 
|  | 6864 | } | 
|  | 6865 | return 1; | 
|  | 6866 | #else /* NL80211_SUPPORT */ | 
|  | 6867 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 6868 | "sta_send_addba not supported without NL80211_SUPPORT defined"); | 
|  | 6869 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 6870 | "ErrorCode,sta_send_addba not supported, NL80211_SUPPORT not enabled"); | 
|  | 6871 | return 0; | 
|  | 6872 | #endif /* NL80211_SUPPORT */ | 
|  | 6873 | } | 
|  | 6874 |  | 
|  | 6875 |  | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6876 | static int cmd_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn, | 
|  | 6877 | struct sigma_cmd *cmd) | 
|  | 6878 | { | 
|  | 6879 | switch (get_driver_type()) { | 
|  | 6880 | case DRIVER_ATHEROS: | 
|  | 6881 | return ath_sta_send_addba(dut, conn, cmd); | 
| Amarnath Hullur Subramanyam | a72c016 | 2018-02-27 14:49:09 -0800 | [diff] [blame] | 6882 | case DRIVER_WCN: | 
|  | 6883 | return wcn_sta_send_addba(dut, conn, cmd); | 
| Lior David | 9981b51 | 2017-01-20 13:16:40 +0200 | [diff] [blame] | 6884 | #ifdef __linux__ | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6885 | case DRIVER_WIL6210: | 
|  | 6886 | return send_addba_60g(dut, conn, cmd); | 
| Lior David | 9981b51 | 2017-01-20 13:16:40 +0200 | [diff] [blame] | 6887 | #endif /* __linux__ */ | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6888 | default: | 
|  | 6889 | /* | 
|  | 6890 | * There is no driver specific implementation for other drivers. | 
|  | 6891 | * Ignore the command and report COMPLETE since the following | 
|  | 6892 | * throughput test operation will end up sending ADDBA anyway. | 
|  | 6893 | */ | 
|  | 6894 | return 1; | 
|  | 6895 | } | 
|  | 6896 | } | 
|  | 6897 |  | 
|  | 6898 |  | 
|  | 6899 | int inject_eth_frame(int s, const void *data, size_t len, | 
|  | 6900 | unsigned short ethtype, char *dst, char *src) | 
|  | 6901 | { | 
|  | 6902 | struct iovec iov[4] = { | 
|  | 6903 | { | 
|  | 6904 | .iov_base = dst, | 
|  | 6905 | .iov_len = ETH_ALEN, | 
|  | 6906 | }, | 
|  | 6907 | { | 
|  | 6908 | .iov_base = src, | 
|  | 6909 | .iov_len = ETH_ALEN, | 
|  | 6910 | }, | 
|  | 6911 | { | 
|  | 6912 | .iov_base = ðtype, | 
|  | 6913 | .iov_len = sizeof(unsigned short), | 
|  | 6914 | }, | 
|  | 6915 | { | 
|  | 6916 | .iov_base = (void *) data, | 
|  | 6917 | .iov_len = len, | 
|  | 6918 | } | 
|  | 6919 | }; | 
|  | 6920 | struct msghdr msg = { | 
|  | 6921 | .msg_name = NULL, | 
|  | 6922 | .msg_namelen = 0, | 
|  | 6923 | .msg_iov = iov, | 
|  | 6924 | .msg_iovlen = 4, | 
|  | 6925 | .msg_control = NULL, | 
|  | 6926 | .msg_controllen = 0, | 
|  | 6927 | .msg_flags = 0, | 
|  | 6928 | }; | 
|  | 6929 |  | 
|  | 6930 | return sendmsg(s, &msg, 0); | 
|  | 6931 | } | 
|  | 6932 |  | 
|  | 6933 | #if defined(__linux__) || defined(__QNXNTO__) | 
|  | 6934 |  | 
|  | 6935 | int inject_frame(int s, const void *data, size_t len, int encrypt) | 
|  | 6936 | { | 
|  | 6937 | #define	IEEE80211_RADIOTAP_F_WEP	0x04 | 
|  | 6938 | #define	IEEE80211_RADIOTAP_F_FRAG	0x08 | 
|  | 6939 | unsigned char rtap_hdr[] = { | 
|  | 6940 | 0x00, 0x00, /* radiotap version */ | 
|  | 6941 | 0x0e, 0x00, /* radiotap length */ | 
|  | 6942 | 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */ | 
|  | 6943 | IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */ | 
|  | 6944 | 0x00,       /* padding */ | 
|  | 6945 | 0x00, 0x00, /* RX and TX flags to indicate that */ | 
|  | 6946 | 0x00, 0x00, /* this is the injected frame directly */ | 
|  | 6947 | }; | 
|  | 6948 | struct iovec iov[2] = { | 
|  | 6949 | { | 
|  | 6950 | .iov_base = &rtap_hdr, | 
|  | 6951 | .iov_len = sizeof(rtap_hdr), | 
|  | 6952 | }, | 
|  | 6953 | { | 
|  | 6954 | .iov_base = (void *) data, | 
|  | 6955 | .iov_len = len, | 
|  | 6956 | } | 
|  | 6957 | }; | 
|  | 6958 | struct msghdr msg = { | 
|  | 6959 | .msg_name = NULL, | 
|  | 6960 | .msg_namelen = 0, | 
|  | 6961 | .msg_iov = iov, | 
|  | 6962 | .msg_iovlen = 2, | 
|  | 6963 | .msg_control = NULL, | 
|  | 6964 | .msg_controllen = 0, | 
|  | 6965 | .msg_flags = 0, | 
|  | 6966 | }; | 
|  | 6967 |  | 
|  | 6968 | if (encrypt) | 
|  | 6969 | rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP; | 
|  | 6970 |  | 
|  | 6971 | return sendmsg(s, &msg, 0); | 
|  | 6972 | } | 
|  | 6973 |  | 
|  | 6974 |  | 
|  | 6975 | int open_monitor(const char *ifname) | 
|  | 6976 | { | 
|  | 6977 | #ifdef __QNXNTO__ | 
|  | 6978 | struct sockaddr_dl ll; | 
|  | 6979 | int s; | 
|  | 6980 |  | 
|  | 6981 | memset(&ll, 0, sizeof(ll)); | 
|  | 6982 | ll.sdl_family = AF_LINK; | 
|  | 6983 | ll.sdl_index = if_nametoindex(ifname); | 
|  | 6984 | if (ll.sdl_index == 0) { | 
|  | 6985 | perror("if_nametoindex"); | 
|  | 6986 | return -1; | 
|  | 6987 | } | 
|  | 6988 | s = socket(PF_INET, SOCK_RAW, 0); | 
|  | 6989 | #else /* __QNXNTO__ */ | 
|  | 6990 | struct sockaddr_ll ll; | 
|  | 6991 | int s; | 
|  | 6992 |  | 
|  | 6993 | memset(&ll, 0, sizeof(ll)); | 
|  | 6994 | ll.sll_family = AF_PACKET; | 
|  | 6995 | ll.sll_ifindex = if_nametoindex(ifname); | 
|  | 6996 | if (ll.sll_ifindex == 0) { | 
|  | 6997 | perror("if_nametoindex"); | 
|  | 6998 | return -1; | 
|  | 6999 | } | 
|  | 7000 | s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); | 
|  | 7001 | #endif /* __QNXNTO__ */ | 
|  | 7002 | if (s < 0) { | 
|  | 7003 | perror("socket[PF_PACKET,SOCK_RAW]"); | 
|  | 7004 | return -1; | 
|  | 7005 | } | 
|  | 7006 |  | 
|  | 7007 | if (bind(s, (struct sockaddr *) &ll, sizeof(ll)) < 0) { | 
|  | 7008 | perror("monitor socket bind"); | 
|  | 7009 | close(s); | 
|  | 7010 | return -1; | 
|  | 7011 | } | 
|  | 7012 |  | 
|  | 7013 | return s; | 
|  | 7014 | } | 
|  | 7015 |  | 
|  | 7016 |  | 
|  | 7017 | static int hex2num(char c) | 
|  | 7018 | { | 
|  | 7019 | if (c >= '0' && c <= '9') | 
|  | 7020 | return c - '0'; | 
|  | 7021 | if (c >= 'a' && c <= 'f') | 
|  | 7022 | return c - 'a' + 10; | 
|  | 7023 | if (c >= 'A' && c <= 'F') | 
|  | 7024 | return c - 'A' + 10; | 
|  | 7025 | return -1; | 
|  | 7026 | } | 
|  | 7027 |  | 
|  | 7028 |  | 
|  | 7029 | int hwaddr_aton(const char *txt, unsigned char *addr) | 
|  | 7030 | { | 
|  | 7031 | int i; | 
|  | 7032 |  | 
|  | 7033 | for (i = 0; i < 6; i++) { | 
|  | 7034 | int a, b; | 
|  | 7035 |  | 
|  | 7036 | a = hex2num(*txt++); | 
|  | 7037 | if (a < 0) | 
|  | 7038 | return -1; | 
|  | 7039 | b = hex2num(*txt++); | 
|  | 7040 | if (b < 0) | 
|  | 7041 | return -1; | 
|  | 7042 | *addr++ = (a << 4) | b; | 
|  | 7043 | if (i < 5 && *txt++ != ':') | 
|  | 7044 | return -1; | 
|  | 7045 | } | 
|  | 7046 |  | 
|  | 7047 | return 0; | 
|  | 7048 | } | 
|  | 7049 |  | 
|  | 7050 | #endif /* defined(__linux__) || defined(__QNXNTO__) */ | 
|  | 7051 |  | 
|  | 7052 | enum send_frame_type { | 
|  | 7053 | DISASSOC, DEAUTH, SAQUERY, AUTH, ASSOCREQ, REASSOCREQ, DLS_REQ | 
|  | 7054 | }; | 
|  | 7055 | enum send_frame_protection { | 
|  | 7056 | CORRECT_KEY, INCORRECT_KEY, UNPROTECTED | 
|  | 7057 | }; | 
|  | 7058 |  | 
|  | 7059 |  | 
|  | 7060 | static int sta_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn, | 
|  | 7061 | enum send_frame_type frame, | 
|  | 7062 | enum send_frame_protection protected, | 
|  | 7063 | const char *dest) | 
|  | 7064 | { | 
|  | 7065 | #ifdef __linux__ | 
|  | 7066 | unsigned char buf[1000], *pos; | 
|  | 7067 | int s, res; | 
|  | 7068 | char bssid[20], addr[20]; | 
|  | 7069 | char result[32], ssid[100]; | 
|  | 7070 | size_t ssid_len; | 
|  | 7071 |  | 
|  | 7072 | if (get_wpa_status(get_station_ifname(), "wpa_state", result, | 
|  | 7073 | sizeof(result)) < 0 || | 
|  | 7074 | strncmp(result, "COMPLETED", 9) != 0) { | 
|  | 7075 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Not connected"); | 
|  | 7076 | return 0; | 
|  | 7077 | } | 
|  | 7078 |  | 
|  | 7079 | if (get_wpa_status(get_station_ifname(), "bssid", bssid, sizeof(bssid)) | 
|  | 7080 | < 0) { | 
|  | 7081 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get " | 
|  | 7082 | "current BSSID"); | 
|  | 7083 | return 0; | 
|  | 7084 | } | 
|  | 7085 |  | 
|  | 7086 | if (get_wpa_status(get_station_ifname(), "address", addr, sizeof(addr)) | 
|  | 7087 | < 0) { | 
|  | 7088 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get " | 
|  | 7089 | "own MAC address"); | 
|  | 7090 | return 0; | 
|  | 7091 | } | 
|  | 7092 |  | 
|  | 7093 | if (get_wpa_status(get_station_ifname(), "ssid", ssid, sizeof(ssid)) | 
|  | 7094 | < 0) { | 
|  | 7095 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get " | 
|  | 7096 | "current SSID"); | 
|  | 7097 | return 0; | 
|  | 7098 | } | 
|  | 7099 | ssid_len = strlen(ssid); | 
|  | 7100 |  | 
|  | 7101 | pos = buf; | 
|  | 7102 |  | 
|  | 7103 | /* Frame Control */ | 
|  | 7104 | switch (frame) { | 
|  | 7105 | case DISASSOC: | 
|  | 7106 | *pos++ = 0xa0; | 
|  | 7107 | break; | 
|  | 7108 | case DEAUTH: | 
|  | 7109 | *pos++ = 0xc0; | 
|  | 7110 | break; | 
|  | 7111 | case SAQUERY: | 
|  | 7112 | *pos++ = 0xd0; | 
|  | 7113 | break; | 
|  | 7114 | case AUTH: | 
|  | 7115 | *pos++ = 0xb0; | 
|  | 7116 | break; | 
|  | 7117 | case ASSOCREQ: | 
|  | 7118 | *pos++ = 0x00; | 
|  | 7119 | break; | 
|  | 7120 | case REASSOCREQ: | 
|  | 7121 | *pos++ = 0x20; | 
|  | 7122 | break; | 
|  | 7123 | case DLS_REQ: | 
|  | 7124 | *pos++ = 0xd0; | 
|  | 7125 | break; | 
|  | 7126 | } | 
|  | 7127 |  | 
|  | 7128 | if (protected == INCORRECT_KEY) | 
|  | 7129 | *pos++ = 0x40; /* Set Protected field to 1 */ | 
|  | 7130 | else | 
|  | 7131 | *pos++ = 0x00; | 
|  | 7132 |  | 
|  | 7133 | /* Duration */ | 
|  | 7134 | *pos++ = 0x00; | 
|  | 7135 | *pos++ = 0x00; | 
|  | 7136 |  | 
|  | 7137 | /* addr1 = DA (current AP) */ | 
|  | 7138 | hwaddr_aton(bssid, pos); | 
|  | 7139 | pos += 6; | 
|  | 7140 | /* addr2 = SA (own address) */ | 
|  | 7141 | hwaddr_aton(addr, pos); | 
|  | 7142 | pos += 6; | 
|  | 7143 | /* addr3 = BSSID (current AP) */ | 
|  | 7144 | hwaddr_aton(bssid, pos); | 
|  | 7145 | pos += 6; | 
|  | 7146 |  | 
|  | 7147 | /* Seq# (to be filled by driver/mac80211) */ | 
|  | 7148 | *pos++ = 0x00; | 
|  | 7149 | *pos++ = 0x00; | 
|  | 7150 |  | 
|  | 7151 | if (protected == INCORRECT_KEY) { | 
|  | 7152 | /* CCMP parameters */ | 
|  | 7153 | memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8); | 
|  | 7154 | pos += 8; | 
|  | 7155 | } | 
|  | 7156 |  | 
|  | 7157 | if (protected == INCORRECT_KEY) { | 
|  | 7158 | switch (frame) { | 
|  | 7159 | case DEAUTH: | 
|  | 7160 | /* Reason code (encrypted) */ | 
|  | 7161 | memcpy(pos, "\xa7\x39", 2); | 
|  | 7162 | pos += 2; | 
|  | 7163 | break; | 
|  | 7164 | case DISASSOC: | 
|  | 7165 | /* Reason code (encrypted) */ | 
|  | 7166 | memcpy(pos, "\xa7\x39", 2); | 
|  | 7167 | pos += 2; | 
|  | 7168 | break; | 
|  | 7169 | case SAQUERY: | 
|  | 7170 | /* Category|Action|TransID (encrypted) */ | 
|  | 7171 | memcpy(pos, "\x6f\xbd\xe9\x4d", 4); | 
|  | 7172 | pos += 4; | 
|  | 7173 | break; | 
|  | 7174 | default: | 
|  | 7175 | return -1; | 
|  | 7176 | } | 
|  | 7177 |  | 
|  | 7178 | /* CCMP MIC */ | 
|  | 7179 | memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8); | 
|  | 7180 | pos += 8; | 
|  | 7181 | } else { | 
|  | 7182 | switch (frame) { | 
|  | 7183 | case DEAUTH: | 
|  | 7184 | /* reason code = 8 */ | 
|  | 7185 | *pos++ = 0x08; | 
|  | 7186 | *pos++ = 0x00; | 
|  | 7187 | break; | 
|  | 7188 | case DISASSOC: | 
|  | 7189 | /* reason code = 8 */ | 
|  | 7190 | *pos++ = 0x08; | 
|  | 7191 | *pos++ = 0x00; | 
|  | 7192 | break; | 
|  | 7193 | case SAQUERY: | 
|  | 7194 | /* Category - SA Query */ | 
|  | 7195 | *pos++ = 0x08; | 
|  | 7196 | /* SA query Action - Request */ | 
|  | 7197 | *pos++ = 0x00; | 
|  | 7198 | /* Transaction ID */ | 
|  | 7199 | *pos++ = 0x12; | 
|  | 7200 | *pos++ = 0x34; | 
|  | 7201 | break; | 
|  | 7202 | case AUTH: | 
|  | 7203 | /* Auth Alg (Open) */ | 
|  | 7204 | *pos++ = 0x00; | 
|  | 7205 | *pos++ = 0x00; | 
|  | 7206 | /* Seq# */ | 
|  | 7207 | *pos++ = 0x01; | 
|  | 7208 | *pos++ = 0x00; | 
|  | 7209 | /* Status code */ | 
|  | 7210 | *pos++ = 0x00; | 
|  | 7211 | *pos++ = 0x00; | 
|  | 7212 | break; | 
|  | 7213 | case ASSOCREQ: | 
|  | 7214 | /* Capability Information */ | 
|  | 7215 | *pos++ = 0x31; | 
|  | 7216 | *pos++ = 0x04; | 
|  | 7217 | /* Listen Interval */ | 
|  | 7218 | *pos++ = 0x0a; | 
|  | 7219 | *pos++ = 0x00; | 
|  | 7220 | /* SSID */ | 
|  | 7221 | *pos++ = 0x00; | 
|  | 7222 | *pos++ = ssid_len; | 
|  | 7223 | memcpy(pos, ssid, ssid_len); | 
|  | 7224 | pos += ssid_len; | 
|  | 7225 | /* Supported Rates */ | 
|  | 7226 | memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24", | 
|  | 7227 | 10); | 
|  | 7228 | pos += 10; | 
|  | 7229 | /* Extended Supported Rates */ | 
|  | 7230 | memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6); | 
|  | 7231 | pos += 6; | 
|  | 7232 | /* RSN */ | 
|  | 7233 | memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00" | 
|  | 7234 | "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0" | 
|  | 7235 | "\x00\x00\x00\x00\x0f\xac\x06", 28); | 
|  | 7236 | pos += 28; | 
|  | 7237 | break; | 
|  | 7238 | case REASSOCREQ: | 
|  | 7239 | /* Capability Information */ | 
|  | 7240 | *pos++ = 0x31; | 
|  | 7241 | *pos++ = 0x04; | 
|  | 7242 | /* Listen Interval */ | 
|  | 7243 | *pos++ = 0x0a; | 
|  | 7244 | *pos++ = 0x00; | 
|  | 7245 | /* Current AP */ | 
|  | 7246 | hwaddr_aton(bssid, pos); | 
|  | 7247 | pos += 6; | 
|  | 7248 | /* SSID */ | 
|  | 7249 | *pos++ = 0x00; | 
|  | 7250 | *pos++ = ssid_len; | 
|  | 7251 | memcpy(pos, ssid, ssid_len); | 
|  | 7252 | pos += ssid_len; | 
|  | 7253 | /* Supported Rates */ | 
|  | 7254 | memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24", | 
|  | 7255 | 10); | 
|  | 7256 | pos += 10; | 
|  | 7257 | /* Extended Supported Rates */ | 
|  | 7258 | memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6); | 
|  | 7259 | pos += 6; | 
|  | 7260 | /* RSN */ | 
|  | 7261 | memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00" | 
|  | 7262 | "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0" | 
|  | 7263 | "\x00\x00\x00\x00\x0f\xac\x06", 28); | 
|  | 7264 | pos += 28; | 
|  | 7265 | break; | 
|  | 7266 | case DLS_REQ: | 
|  | 7267 | /* Category - DLS */ | 
|  | 7268 | *pos++ = 0x02; | 
|  | 7269 | /* DLS Action - Request */ | 
|  | 7270 | *pos++ = 0x00; | 
|  | 7271 | /* Destination MACAddress */ | 
|  | 7272 | if (dest) | 
|  | 7273 | hwaddr_aton(dest, pos); | 
|  | 7274 | else | 
|  | 7275 | memset(pos, 0, 6); | 
|  | 7276 | pos += 6; | 
|  | 7277 | /* Source MACAddress */ | 
|  | 7278 | hwaddr_aton(addr, pos); | 
|  | 7279 | pos += 6; | 
|  | 7280 | /* Capability Information */ | 
|  | 7281 | *pos++ = 0x10; /* Privacy */ | 
|  | 7282 | *pos++ = 0x06; /* QoS */ | 
|  | 7283 | /* DLS Timeout Value */ | 
|  | 7284 | *pos++ = 0x00; | 
|  | 7285 | *pos++ = 0x01; | 
|  | 7286 | /* Supported rates */ | 
|  | 7287 | *pos++ = 0x01; | 
|  | 7288 | *pos++ = 0x08; | 
|  | 7289 | *pos++ = 0x0c; /* 6 Mbps */ | 
|  | 7290 | *pos++ = 0x12; /* 9 Mbps */ | 
|  | 7291 | *pos++ = 0x18; /* 12 Mbps */ | 
|  | 7292 | *pos++ = 0x24; /* 18 Mbps */ | 
|  | 7293 | *pos++ = 0x30; /* 24 Mbps */ | 
|  | 7294 | *pos++ = 0x48; /* 36 Mbps */ | 
|  | 7295 | *pos++ = 0x60; /* 48 Mbps */ | 
|  | 7296 | *pos++ = 0x6c; /* 54 Mbps */ | 
|  | 7297 | /* TODO: Extended Supported Rates */ | 
|  | 7298 | /* TODO: HT Capabilities */ | 
|  | 7299 | break; | 
|  | 7300 | } | 
|  | 7301 | } | 
|  | 7302 |  | 
|  | 7303 | s = open_monitor("sigmadut"); | 
|  | 7304 | if (s < 0) { | 
|  | 7305 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open " | 
|  | 7306 | "monitor socket"); | 
|  | 7307 | return 0; | 
|  | 7308 | } | 
|  | 7309 |  | 
|  | 7310 | res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY); | 
|  | 7311 | if (res < 0) { | 
|  | 7312 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to " | 
|  | 7313 | "inject frame"); | 
| Pradeep Reddy POTTETI | 673d85c | 2016-07-26 19:08:07 +0530 | [diff] [blame] | 7314 | close(s); | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7315 | return 0; | 
|  | 7316 | } | 
|  | 7317 | if (res < pos - buf) { | 
|  | 7318 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Only partial " | 
|  | 7319 | "frame sent"); | 
| Pradeep Reddy POTTETI | 673d85c | 2016-07-26 19:08:07 +0530 | [diff] [blame] | 7320 | close(s); | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7321 | return 0; | 
|  | 7322 | } | 
|  | 7323 |  | 
|  | 7324 | close(s); | 
|  | 7325 |  | 
|  | 7326 | return 1; | 
|  | 7327 | #else /* __linux__ */ | 
|  | 7328 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,sta_send_frame not " | 
|  | 7329 | "yet supported"); | 
|  | 7330 | return 0; | 
|  | 7331 | #endif /* __linux__ */ | 
|  | 7332 | } | 
|  | 7333 |  | 
|  | 7334 |  | 
|  | 7335 | static int cmd_sta_send_frame_tdls(struct sigma_dut *dut, | 
|  | 7336 | struct sigma_conn *conn, | 
|  | 7337 | struct sigma_cmd *cmd) | 
|  | 7338 | { | 
|  | 7339 | const char *intf = get_param(cmd, "Interface"); | 
|  | 7340 | const char *sta, *val; | 
|  | 7341 | unsigned char addr[ETH_ALEN]; | 
|  | 7342 | char buf[100]; | 
|  | 7343 |  | 
|  | 7344 | sta = get_param(cmd, "peer"); | 
|  | 7345 | if (sta == NULL) | 
|  | 7346 | sta = get_param(cmd, "station"); | 
|  | 7347 | if (sta == NULL) { | 
|  | 7348 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 7349 | "ErrorCode,Missing peer address"); | 
|  | 7350 | return 0; | 
|  | 7351 | } | 
|  | 7352 | if (hwaddr_aton(sta, addr) < 0) { | 
|  | 7353 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 7354 | "ErrorCode,Invalid peer address"); | 
|  | 7355 | return 0; | 
|  | 7356 | } | 
|  | 7357 |  | 
|  | 7358 | val = get_param(cmd, "type"); | 
|  | 7359 | if (val == NULL) | 
|  | 7360 | return -1; | 
|  | 7361 |  | 
|  | 7362 | if (strcasecmp(val, "DISCOVERY") == 0) { | 
|  | 7363 | snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", sta); | 
|  | 7364 | if (wpa_command(intf, buf) < 0) { | 
|  | 7365 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 7366 | "ErrorCode,Failed to send TDLS discovery"); | 
|  | 7367 | return 0; | 
|  | 7368 | } | 
|  | 7369 | return 1; | 
|  | 7370 | } | 
|  | 7371 |  | 
|  | 7372 | if (strcasecmp(val, "SETUP") == 0) { | 
|  | 7373 | int status = 0, timeout = 0; | 
|  | 7374 |  | 
|  | 7375 | val = get_param(cmd, "Status"); | 
|  | 7376 | if (val) | 
|  | 7377 | status = atoi(val); | 
|  | 7378 |  | 
|  | 7379 | val = get_param(cmd, "Timeout"); | 
|  | 7380 | if (val) | 
|  | 7381 | timeout = atoi(val); | 
|  | 7382 |  | 
|  | 7383 | if (status != 0 && status != 37) { | 
|  | 7384 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 7385 | "ErrorCode,Unsupported status value"); | 
|  | 7386 | return 0; | 
|  | 7387 | } | 
|  | 7388 |  | 
|  | 7389 | if (timeout != 0 && timeout != 301) { | 
|  | 7390 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 7391 | "ErrorCode,Unsupported timeout value"); | 
|  | 7392 | return 0; | 
|  | 7393 | } | 
|  | 7394 |  | 
|  | 7395 | if (status && timeout) { | 
|  | 7396 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 7397 | "ErrorCode,Unsupported timeout+status " | 
|  | 7398 | "combination"); | 
|  | 7399 | return 0; | 
|  | 7400 | } | 
|  | 7401 |  | 
|  | 7402 | if (status == 37 && | 
|  | 7403 | wpa_command(intf, "SET tdls_testing 0x200")) { | 
|  | 7404 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 7405 | "ErrorCode,Failed to enable " | 
|  | 7406 | "decline setup response test mode"); | 
|  | 7407 | return 0; | 
|  | 7408 | } | 
|  | 7409 |  | 
|  | 7410 | if (timeout == 301) { | 
|  | 7411 | int res; | 
|  | 7412 | if (dut->no_tpk_expiration) | 
|  | 7413 | res = wpa_command(intf, | 
|  | 7414 | "SET tdls_testing 0x108"); | 
|  | 7415 | else | 
|  | 7416 | res = wpa_command(intf, | 
|  | 7417 | "SET tdls_testing 0x8"); | 
|  | 7418 | if (res) { | 
|  | 7419 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 7420 | "ErrorCode,Failed to set short TPK " | 
|  | 7421 | "lifetime"); | 
|  | 7422 | return 0; | 
|  | 7423 | } | 
|  | 7424 | } | 
|  | 7425 |  | 
|  | 7426 | snprintf(buf, sizeof(buf), "TDLS_SETUP %s", sta); | 
|  | 7427 | if (wpa_command(intf, buf) < 0) { | 
|  | 7428 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 7429 | "ErrorCode,Failed to send TDLS setup"); | 
|  | 7430 | return 0; | 
|  | 7431 | } | 
|  | 7432 | return 1; | 
|  | 7433 | } | 
|  | 7434 |  | 
|  | 7435 | if (strcasecmp(val, "TEARDOWN") == 0) { | 
|  | 7436 | snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", sta); | 
|  | 7437 | if (wpa_command(intf, buf) < 0) { | 
|  | 7438 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 7439 | "ErrorCode,Failed to send TDLS teardown"); | 
|  | 7440 | return 0; | 
|  | 7441 | } | 
|  | 7442 | return 1; | 
|  | 7443 | } | 
|  | 7444 |  | 
|  | 7445 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 7446 | "ErrorCode,Unsupported TDLS frame"); | 
|  | 7447 | return 0; | 
|  | 7448 | } | 
|  | 7449 |  | 
|  | 7450 |  | 
|  | 7451 | static int sta_ap_known(const char *ifname, const char *bssid) | 
|  | 7452 | { | 
|  | 7453 | char buf[4096]; | 
|  | 7454 |  | 
|  | 7455 | snprintf(buf, sizeof(buf), "BSS %s", bssid); | 
|  | 7456 | if (wpa_command_resp(ifname, buf, buf, sizeof(buf)) < 0) | 
|  | 7457 | return 0; | 
|  | 7458 | if (strncmp(buf, "id=", 3) != 0) | 
|  | 7459 | return 0; | 
|  | 7460 | return 1; | 
|  | 7461 | } | 
|  | 7462 |  | 
|  | 7463 |  | 
|  | 7464 | static int sta_scan_ap(struct sigma_dut *dut, const char *ifname, | 
|  | 7465 | const char *bssid) | 
|  | 7466 | { | 
|  | 7467 | int res; | 
|  | 7468 | struct wpa_ctrl *ctrl; | 
|  | 7469 | char buf[256]; | 
|  | 7470 |  | 
|  | 7471 | if (sta_ap_known(ifname, bssid)) | 
|  | 7472 | return 0; | 
|  | 7473 | sigma_dut_print(dut, DUT_MSG_DEBUG, | 
|  | 7474 | "AP not in BSS table - start scan"); | 
|  | 7475 |  | 
|  | 7476 | ctrl = open_wpa_mon(ifname); | 
|  | 7477 | if (ctrl == NULL) { | 
|  | 7478 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open " | 
|  | 7479 | "wpa_supplicant monitor connection"); | 
|  | 7480 | return -1; | 
|  | 7481 | } | 
|  | 7482 |  | 
|  | 7483 | if (wpa_command(ifname, "SCAN") < 0) { | 
|  | 7484 | sigma_dut_print(dut, DUT_MSG_INFO, "Failed to start scan"); | 
|  | 7485 | wpa_ctrl_detach(ctrl); | 
|  | 7486 | wpa_ctrl_close(ctrl); | 
|  | 7487 | return -1; | 
|  | 7488 | } | 
|  | 7489 |  | 
|  | 7490 | res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS", | 
|  | 7491 | buf, sizeof(buf)); | 
|  | 7492 |  | 
|  | 7493 | wpa_ctrl_detach(ctrl); | 
|  | 7494 | wpa_ctrl_close(ctrl); | 
|  | 7495 |  | 
|  | 7496 | if (res < 0) { | 
|  | 7497 | sigma_dut_print(dut, DUT_MSG_INFO, "Scan did not complete"); | 
|  | 7498 | return -1; | 
|  | 7499 | } | 
|  | 7500 |  | 
|  | 7501 | if (sta_ap_known(ifname, bssid)) | 
|  | 7502 | return 0; | 
|  | 7503 | sigma_dut_print(dut, DUT_MSG_INFO, "AP not in BSS table"); | 
|  | 7504 | return -1; | 
|  | 7505 | } | 
|  | 7506 |  | 
|  | 7507 |  | 
|  | 7508 | static int cmd_sta_send_frame_hs2_neighadv(struct sigma_dut *dut, | 
|  | 7509 | struct sigma_conn *conn, | 
|  | 7510 | struct sigma_cmd *cmd, | 
|  | 7511 | const char *intf) | 
|  | 7512 | { | 
|  | 7513 | char buf[200]; | 
|  | 7514 |  | 
|  | 7515 | snprintf(buf, sizeof(buf), "ndsend 2001:DB8::1 %s", intf); | 
|  | 7516 | if (system(buf) != 0) { | 
|  | 7517 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Failed to run " | 
|  | 7518 | "ndsend"); | 
|  | 7519 | return 0; | 
|  | 7520 | } | 
|  | 7521 |  | 
|  | 7522 | return 1; | 
|  | 7523 | } | 
|  | 7524 |  | 
|  | 7525 |  | 
|  | 7526 | static int cmd_sta_send_frame_hs2_neighsolreq(struct sigma_dut *dut, | 
|  | 7527 | struct sigma_conn *conn, | 
|  | 7528 | struct sigma_cmd *cmd, | 
|  | 7529 | const char *intf) | 
|  | 7530 | { | 
|  | 7531 | char buf[200]; | 
|  | 7532 | const char *ip = get_param(cmd, "SenderIP"); | 
|  | 7533 |  | 
| Peng Xu | 26b356d | 2017-10-04 17:58:16 -0700 | [diff] [blame] | 7534 | if (!ip) | 
|  | 7535 | return 0; | 
|  | 7536 |  | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7537 | snprintf(buf, sizeof(buf), "ndisc6 -nm %s %s -r 4", ip, intf); | 
|  | 7538 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); | 
|  | 7539 | if (system(buf) == 0) { | 
|  | 7540 | sigma_dut_print(dut, DUT_MSG_INFO, | 
|  | 7541 | "Neighbor Solicitation got a response " | 
|  | 7542 | "for %s@%s", ip, intf); | 
|  | 7543 | } | 
|  | 7544 |  | 
|  | 7545 | return 1; | 
|  | 7546 | } | 
|  | 7547 |  | 
|  | 7548 |  | 
|  | 7549 | static int cmd_sta_send_frame_hs2_arpprobe(struct sigma_dut *dut, | 
|  | 7550 | struct sigma_conn *conn, | 
|  | 7551 | struct sigma_cmd *cmd, | 
|  | 7552 | const char *ifname) | 
|  | 7553 | { | 
|  | 7554 | char buf[200]; | 
|  | 7555 | const char *ip = get_param(cmd, "SenderIP"); | 
|  | 7556 |  | 
|  | 7557 | if (ip == NULL) { | 
|  | 7558 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 7559 | "ErrorCode,Missing SenderIP parameter"); | 
|  | 7560 | return 0; | 
|  | 7561 | } | 
|  | 7562 | snprintf(buf, sizeof(buf), "arping -I %s -D %s -c 4", ifname, ip); | 
|  | 7563 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); | 
|  | 7564 | if (system(buf) != 0) { | 
|  | 7565 | sigma_dut_print(dut, DUT_MSG_INFO, "arping DAD got a response " | 
|  | 7566 | "for %s@%s", ip, ifname); | 
|  | 7567 | } | 
|  | 7568 |  | 
|  | 7569 | return 1; | 
|  | 7570 | } | 
|  | 7571 |  | 
|  | 7572 |  | 
|  | 7573 | static int cmd_sta_send_frame_hs2_arpannounce(struct sigma_dut *dut, | 
|  | 7574 | struct sigma_conn *conn, | 
|  | 7575 | struct sigma_cmd *cmd, | 
|  | 7576 | const char *ifname) | 
|  | 7577 | { | 
|  | 7578 | char buf[200]; | 
|  | 7579 | char ip[16]; | 
|  | 7580 | int s; | 
| Peng Xu | b375688 | 2017-10-04 14:39:09 -0700 | [diff] [blame] | 7581 | struct ifreq ifr; | 
|  | 7582 | struct sockaddr_in saddr; | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7583 |  | 
|  | 7584 | s = socket(PF_INET, SOCK_DGRAM, 0); | 
| Peng Xu | b375688 | 2017-10-04 14:39:09 -0700 | [diff] [blame] | 7585 | if (s < 0) { | 
|  | 7586 | perror("socket"); | 
|  | 7587 | return -1; | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7588 | } | 
|  | 7589 |  | 
| Peng Xu | b375688 | 2017-10-04 14:39:09 -0700 | [diff] [blame] | 7590 | memset(&ifr, 0, sizeof(ifr)); | 
|  | 7591 | strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); | 
|  | 7592 | if (ioctl(s, SIOCGIFADDR, &ifr) < 0) { | 
|  | 7593 | sigma_dut_print(dut, DUT_MSG_INFO, | 
|  | 7594 | "Failed to get %s IP address: %s", | 
|  | 7595 | ifname, strerror(errno)); | 
|  | 7596 | close(s); | 
|  | 7597 | return -1; | 
|  | 7598 | } | 
|  | 7599 | close(s); | 
|  | 7600 |  | 
|  | 7601 | memcpy(&saddr, &ifr.ifr_addr, sizeof(struct sockaddr_in)); | 
|  | 7602 | strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip)); | 
|  | 7603 |  | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7604 | snprintf(buf, sizeof(buf), "arping -I %s -s %s %s -c 4", ifname, ip, | 
|  | 7605 | ip); | 
|  | 7606 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); | 
|  | 7607 | if (system(buf) != 0) { | 
|  | 7608 | } | 
|  | 7609 |  | 
|  | 7610 | return 1; | 
|  | 7611 | } | 
|  | 7612 |  | 
|  | 7613 |  | 
|  | 7614 | static int cmd_sta_send_frame_hs2_arpreply(struct sigma_dut *dut, | 
|  | 7615 | struct sigma_conn *conn, | 
|  | 7616 | struct sigma_cmd *cmd, | 
|  | 7617 | const char *ifname) | 
|  | 7618 | { | 
|  | 7619 | char buf[200], addr[20]; | 
|  | 7620 | char dst[ETH_ALEN], src[ETH_ALEN]; | 
|  | 7621 | short ethtype = htons(ETH_P_ARP); | 
|  | 7622 | char *pos; | 
|  | 7623 | int s, res; | 
|  | 7624 | const char *val; | 
|  | 7625 | struct sockaddr_in taddr; | 
|  | 7626 |  | 
|  | 7627 | val = get_param(cmd, "dest"); | 
|  | 7628 | if (val) | 
|  | 7629 | hwaddr_aton(val, (unsigned char *) dst); | 
|  | 7630 |  | 
|  | 7631 | val = get_param(cmd, "DestIP"); | 
|  | 7632 | if (val) | 
|  | 7633 | inet_aton(val, &taddr.sin_addr); | 
| Peng Xu | 151c9e1 | 2017-10-04 14:39:09 -0700 | [diff] [blame] | 7634 | else | 
|  | 7635 | return -2; | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7636 |  | 
|  | 7637 | if (get_wpa_status(get_station_ifname(), "address", addr, | 
|  | 7638 | sizeof(addr)) < 0) | 
|  | 7639 | return -2; | 
|  | 7640 | hwaddr_aton(addr, (unsigned char *) src); | 
|  | 7641 |  | 
|  | 7642 | pos = buf; | 
|  | 7643 | *pos++ = 0x00; | 
|  | 7644 | *pos++ = 0x01; | 
|  | 7645 | *pos++ = 0x08; | 
|  | 7646 | *pos++ = 0x00; | 
|  | 7647 | *pos++ = 0x06; | 
|  | 7648 | *pos++ = 0x04; | 
|  | 7649 | *pos++ = 0x00; | 
|  | 7650 | *pos++ = 0x02; | 
|  | 7651 | memcpy(pos, src, ETH_ALEN); | 
|  | 7652 | pos += ETH_ALEN; | 
|  | 7653 | memcpy(pos, &taddr.sin_addr, 4); | 
|  | 7654 | pos += 4; | 
|  | 7655 | memcpy(pos, dst, ETH_ALEN); | 
|  | 7656 | pos += ETH_ALEN; | 
|  | 7657 | memcpy(pos, &taddr.sin_addr, 4); | 
|  | 7658 | pos += 4; | 
|  | 7659 |  | 
|  | 7660 | s = open_monitor(get_station_ifname()); | 
|  | 7661 | if (s < 0) { | 
|  | 7662 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open " | 
|  | 7663 | "monitor socket"); | 
|  | 7664 | return 0; | 
|  | 7665 | } | 
|  | 7666 |  | 
|  | 7667 | res = inject_eth_frame(s, buf, pos - buf, ethtype, dst, src); | 
|  | 7668 | if (res < 0) { | 
|  | 7669 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to " | 
|  | 7670 | "inject frame"); | 
| Pradeep Reddy POTTETI | 673d85c | 2016-07-26 19:08:07 +0530 | [diff] [blame] | 7671 | close(s); | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7672 | return 0; | 
|  | 7673 | } | 
|  | 7674 |  | 
|  | 7675 | close(s); | 
|  | 7676 |  | 
|  | 7677 | return 1; | 
|  | 7678 | } | 
|  | 7679 |  | 
|  | 7680 |  | 
|  | 7681 | static int cmd_sta_send_frame_hs2_dls_req(struct sigma_dut *dut, | 
|  | 7682 | struct sigma_conn *conn, | 
|  | 7683 | struct sigma_cmd *cmd, | 
|  | 7684 | const char *intf, const char *dest) | 
|  | 7685 | { | 
|  | 7686 | char buf[100]; | 
|  | 7687 |  | 
|  | 7688 | if (if_nametoindex("sigmadut") == 0) { | 
|  | 7689 | snprintf(buf, sizeof(buf), | 
|  | 7690 | "iw dev %s interface add sigmadut type monitor", | 
|  | 7691 | get_station_ifname()); | 
|  | 7692 | if (system(buf) != 0 || | 
|  | 7693 | if_nametoindex("sigmadut") == 0) { | 
|  | 7694 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add " | 
|  | 7695 | "monitor interface with '%s'", buf); | 
|  | 7696 | return -2; | 
|  | 7697 | } | 
|  | 7698 | } | 
|  | 7699 |  | 
|  | 7700 | if (system("ifconfig sigmadut up") != 0) { | 
|  | 7701 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set " | 
|  | 7702 | "monitor interface up"); | 
|  | 7703 | return -2; | 
|  | 7704 | } | 
|  | 7705 |  | 
|  | 7706 | return sta_inject_frame(dut, conn, DLS_REQ, UNPROTECTED, dest); | 
|  | 7707 | } | 
|  | 7708 |  | 
|  | 7709 |  | 
|  | 7710 | static int cmd_sta_send_frame_hs2(struct sigma_dut *dut, | 
|  | 7711 | struct sigma_conn *conn, | 
|  | 7712 | struct sigma_cmd *cmd) | 
|  | 7713 | { | 
|  | 7714 | const char *intf = get_param(cmd, "Interface"); | 
|  | 7715 | const char *dest = get_param(cmd, "Dest"); | 
|  | 7716 | const char *type = get_param(cmd, "FrameName"); | 
|  | 7717 | const char *val; | 
|  | 7718 | char buf[200], *pos, *end; | 
|  | 7719 | int count, count2; | 
|  | 7720 |  | 
|  | 7721 | if (type == NULL) | 
|  | 7722 | type = get_param(cmd, "Type"); | 
|  | 7723 |  | 
|  | 7724 | if (intf == NULL || dest == NULL || type == NULL) | 
|  | 7725 | return -1; | 
|  | 7726 |  | 
|  | 7727 | if (strcasecmp(type, "NeighAdv") == 0) | 
|  | 7728 | return cmd_sta_send_frame_hs2_neighadv(dut, conn, cmd, intf); | 
|  | 7729 |  | 
|  | 7730 | if (strcasecmp(type, "NeighSolicitReq") == 0) | 
|  | 7731 | return cmd_sta_send_frame_hs2_neighsolreq(dut, conn, cmd, intf); | 
|  | 7732 |  | 
|  | 7733 | if (strcasecmp(type, "ARPProbe") == 0) | 
|  | 7734 | return cmd_sta_send_frame_hs2_arpprobe(dut, conn, cmd, intf); | 
|  | 7735 |  | 
|  | 7736 | if (strcasecmp(type, "ARPAnnounce") == 0) | 
|  | 7737 | return cmd_sta_send_frame_hs2_arpannounce(dut, conn, cmd, intf); | 
|  | 7738 |  | 
|  | 7739 | if (strcasecmp(type, "ARPReply") == 0) | 
|  | 7740 | return cmd_sta_send_frame_hs2_arpreply(dut, conn, cmd, intf); | 
|  | 7741 |  | 
|  | 7742 | if (strcasecmp(type, "DLS-request") == 0 || | 
|  | 7743 | strcasecmp(type, "DLSrequest") == 0) | 
|  | 7744 | return cmd_sta_send_frame_hs2_dls_req(dut, conn, cmd, intf, | 
|  | 7745 | dest); | 
|  | 7746 |  | 
|  | 7747 | if (strcasecmp(type, "ANQPQuery") != 0 && | 
|  | 7748 | strcasecmp(type, "Query") != 0) { | 
|  | 7749 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 7750 | "ErrorCode,Unsupported HS 2.0 send frame type"); | 
|  | 7751 | return 0; | 
|  | 7752 | } | 
|  | 7753 |  | 
|  | 7754 | if (sta_scan_ap(dut, intf, dest) < 0) { | 
|  | 7755 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not find " | 
|  | 7756 | "the requested AP"); | 
|  | 7757 | return 0; | 
|  | 7758 | } | 
|  | 7759 |  | 
|  | 7760 | pos = buf; | 
|  | 7761 | end = buf + sizeof(buf); | 
|  | 7762 | count = 0; | 
|  | 7763 | pos += snprintf(pos, end - pos, "ANQP_GET %s ", dest); | 
|  | 7764 |  | 
|  | 7765 | val = get_param(cmd, "ANQP_CAP_LIST"); | 
|  | 7766 | if (val && atoi(val)) { | 
|  | 7767 | pos += snprintf(pos, end - pos, "%s257", count > 0 ? "," : ""); | 
|  | 7768 | count++; | 
|  | 7769 | } | 
|  | 7770 |  | 
|  | 7771 | val = get_param(cmd, "VENUE_NAME"); | 
|  | 7772 | if (val && atoi(val)) { | 
|  | 7773 | pos += snprintf(pos, end - pos, "%s258", count > 0 ? "," : ""); | 
|  | 7774 | count++; | 
|  | 7775 | } | 
|  | 7776 |  | 
|  | 7777 | val = get_param(cmd, "NETWORK_AUTH_TYPE"); | 
|  | 7778 | if (val && atoi(val)) { | 
|  | 7779 | pos += snprintf(pos, end - pos, "%s260", count > 0 ? "," : ""); | 
|  | 7780 | count++; | 
|  | 7781 | } | 
|  | 7782 |  | 
|  | 7783 | val = get_param(cmd, "ROAMING_CONS"); | 
|  | 7784 | if (val && atoi(val)) { | 
|  | 7785 | pos += snprintf(pos, end - pos, "%s261", count > 0 ? "," : ""); | 
|  | 7786 | count++; | 
|  | 7787 | } | 
|  | 7788 |  | 
|  | 7789 | val = get_param(cmd, "IP_ADDR_TYPE_AVAILABILITY"); | 
|  | 7790 | if (val && atoi(val)) { | 
|  | 7791 | pos += snprintf(pos, end - pos, "%s262", count > 0 ? "," : ""); | 
|  | 7792 | count++; | 
|  | 7793 | } | 
|  | 7794 |  | 
|  | 7795 | val = get_param(cmd, "NAI_REALM_LIST"); | 
|  | 7796 | if (val && atoi(val)) { | 
|  | 7797 | pos += snprintf(pos, end - pos, "%s263", count > 0 ? "," : ""); | 
|  | 7798 | count++; | 
|  | 7799 | } | 
|  | 7800 |  | 
|  | 7801 | val = get_param(cmd, "3GPP_INFO"); | 
|  | 7802 | if (val && atoi(val)) { | 
|  | 7803 | pos += snprintf(pos, end - pos, "%s264", count > 0 ? "," : ""); | 
|  | 7804 | count++; | 
|  | 7805 | } | 
|  | 7806 |  | 
|  | 7807 | val = get_param(cmd, "DOMAIN_LIST"); | 
|  | 7808 | if (val && atoi(val)) { | 
|  | 7809 | pos += snprintf(pos, end - pos, "%s268", count > 0 ? "," : ""); | 
|  | 7810 | count++; | 
|  | 7811 | } | 
|  | 7812 |  | 
|  | 7813 | if (count && wpa_command(intf, buf)) { | 
|  | 7814 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,ANQP_GET failed"); | 
|  | 7815 | return 0; | 
|  | 7816 | } | 
|  | 7817 |  | 
|  | 7818 | pos = buf; | 
|  | 7819 | end = buf + sizeof(buf); | 
|  | 7820 | count2 = 0; | 
|  | 7821 | pos += snprintf(pos, end - pos, "HS20_ANQP_GET %s ", dest); | 
|  | 7822 |  | 
|  | 7823 | val = get_param(cmd, "HS_CAP_LIST"); | 
|  | 7824 | if (val && atoi(val)) { | 
|  | 7825 | pos += snprintf(pos, end - pos, "%s2", count2 > 0 ? "," : ""); | 
|  | 7826 | count2++; | 
|  | 7827 | } | 
|  | 7828 |  | 
|  | 7829 | val = get_param(cmd, "OPER_NAME"); | 
|  | 7830 | if (val && atoi(val)) { | 
|  | 7831 | pos += snprintf(pos, end - pos, "%s3", count2 > 0 ? "," : ""); | 
|  | 7832 | count2++; | 
|  | 7833 | } | 
|  | 7834 |  | 
|  | 7835 | val = get_param(cmd, "WAN_METRICS"); | 
|  | 7836 | if (!val) | 
|  | 7837 | val = get_param(cmd, "WAN_MAT"); | 
|  | 7838 | if (!val) | 
|  | 7839 | val = get_param(cmd, "WAN_MET"); | 
|  | 7840 | if (val && atoi(val)) { | 
|  | 7841 | pos += snprintf(pos, end - pos, "%s4", count2 > 0 ? "," : ""); | 
|  | 7842 | count2++; | 
|  | 7843 | } | 
|  | 7844 |  | 
|  | 7845 | val = get_param(cmd, "CONNECTION_CAPABILITY"); | 
|  | 7846 | if (val && atoi(val)) { | 
|  | 7847 | pos += snprintf(pos, end - pos, "%s5", count2 > 0 ? "," : ""); | 
|  | 7848 | count2++; | 
|  | 7849 | } | 
|  | 7850 |  | 
|  | 7851 | val = get_param(cmd, "OP_CLASS"); | 
|  | 7852 | if (val && atoi(val)) { | 
|  | 7853 | pos += snprintf(pos, end - pos, "%s7", count2 > 0 ? "," : ""); | 
|  | 7854 | count2++; | 
|  | 7855 | } | 
|  | 7856 |  | 
|  | 7857 | val = get_param(cmd, "OSU_PROVIDER_LIST"); | 
|  | 7858 | if (val && atoi(val)) { | 
|  | 7859 | pos += snprintf(pos, end - pos, "%s8", count2 > 0 ? "," : ""); | 
|  | 7860 | count2++; | 
|  | 7861 | } | 
|  | 7862 |  | 
|  | 7863 | if (count && count2) { | 
|  | 7864 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before sending out " | 
|  | 7865 | "second query"); | 
|  | 7866 | sleep(1); | 
|  | 7867 | } | 
|  | 7868 |  | 
|  | 7869 | if (count2 && wpa_command(intf, buf)) { | 
|  | 7870 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,HS20_ANQP_GET " | 
|  | 7871 | "failed"); | 
|  | 7872 | return 0; | 
|  | 7873 | } | 
|  | 7874 |  | 
|  | 7875 | val = get_param(cmd, "NAI_HOME_REALM_LIST"); | 
|  | 7876 | if (val) { | 
|  | 7877 | if (count || count2) { | 
|  | 7878 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before " | 
|  | 7879 | "sending out second query"); | 
|  | 7880 | sleep(1); | 
|  | 7881 | } | 
|  | 7882 |  | 
|  | 7883 | if (strcmp(val, "1") == 0) | 
|  | 7884 | val = "mail.example.com"; | 
|  | 7885 | snprintf(buf, end - pos, | 
|  | 7886 | "HS20_GET_NAI_HOME_REALM_LIST %s realm=%s", | 
|  | 7887 | dest, val); | 
|  | 7888 | if (wpa_command(intf, buf)) { | 
|  | 7889 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 7890 | "ErrorCode,HS20_GET_NAI_HOME_REALM_LIST " | 
|  | 7891 | "failed"); | 
|  | 7892 | return 0; | 
|  | 7893 | } | 
|  | 7894 | } | 
|  | 7895 |  | 
|  | 7896 | val = get_param(cmd, "ICON_REQUEST"); | 
|  | 7897 | if (val) { | 
|  | 7898 | if (count || count2) { | 
|  | 7899 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before " | 
|  | 7900 | "sending out second query"); | 
|  | 7901 | sleep(1); | 
|  | 7902 | } | 
|  | 7903 |  | 
|  | 7904 | snprintf(buf, end - pos, | 
|  | 7905 | "HS20_ICON_REQUEST %s %s", dest, val); | 
|  | 7906 | if (wpa_command(intf, buf)) { | 
|  | 7907 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 7908 | "ErrorCode,HS20_ICON_REQUEST failed"); | 
|  | 7909 | return 0; | 
|  | 7910 | } | 
|  | 7911 | } | 
|  | 7912 |  | 
|  | 7913 | return 1; | 
|  | 7914 | } | 
|  | 7915 |  | 
|  | 7916 |  | 
|  | 7917 | static int ath_sta_send_frame_vht(struct sigma_dut *dut, | 
|  | 7918 | struct sigma_conn *conn, | 
|  | 7919 | struct sigma_cmd *cmd) | 
|  | 7920 | { | 
|  | 7921 | const char *val; | 
|  | 7922 | char *ifname; | 
|  | 7923 | char buf[100]; | 
|  | 7924 | int chwidth, nss; | 
|  | 7925 |  | 
|  | 7926 | val = get_param(cmd, "framename"); | 
|  | 7927 | if (!val) | 
|  | 7928 | return -1; | 
|  | 7929 | sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val); | 
|  | 7930 |  | 
|  | 7931 | /* Command sequence to generate Op mode notification */ | 
|  | 7932 | if (val && strcasecmp(val, "Op_md_notif_frm") == 0) { | 
|  | 7933 | ifname = get_station_ifname(); | 
|  | 7934 |  | 
|  | 7935 | /* Disable STBC */ | 
|  | 7936 | snprintf(buf, sizeof(buf), | 
|  | 7937 | "iwpriv %s tx_stbc 0", ifname); | 
|  | 7938 | if (system(buf) != 0) { | 
|  | 7939 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 7940 | "iwpriv tx_stbc 0 failed!"); | 
|  | 7941 | } | 
|  | 7942 |  | 
|  | 7943 | /* Extract Channel width */ | 
|  | 7944 | val = get_param(cmd, "Channel_width"); | 
|  | 7945 | if (val) { | 
|  | 7946 | switch (atoi(val)) { | 
|  | 7947 | case 20: | 
|  | 7948 | chwidth = 0; | 
|  | 7949 | break; | 
|  | 7950 | case 40: | 
|  | 7951 | chwidth = 1; | 
|  | 7952 | break; | 
|  | 7953 | case 80: | 
|  | 7954 | chwidth = 2; | 
|  | 7955 | break; | 
|  | 7956 | case 160: | 
|  | 7957 | chwidth = 3; | 
|  | 7958 | break; | 
|  | 7959 | default: | 
|  | 7960 | chwidth = 2; | 
|  | 7961 | break; | 
|  | 7962 | } | 
|  | 7963 |  | 
|  | 7964 | snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d", | 
|  | 7965 | ifname, chwidth); | 
|  | 7966 | if (system(buf) != 0) { | 
|  | 7967 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 7968 | "iwpriv chwidth failed!"); | 
|  | 7969 | } | 
|  | 7970 | } | 
|  | 7971 |  | 
|  | 7972 | /* Extract NSS */ | 
|  | 7973 | val = get_param(cmd, "NSS"); | 
|  | 7974 | if (val) { | 
|  | 7975 | switch (atoi(val)) { | 
|  | 7976 | case 1: | 
|  | 7977 | nss = 1; | 
|  | 7978 | break; | 
|  | 7979 | case 2: | 
|  | 7980 | nss = 3; | 
|  | 7981 | break; | 
|  | 7982 | case 3: | 
|  | 7983 | nss = 7; | 
|  | 7984 | break; | 
|  | 7985 | default: | 
|  | 7986 | /* We do not support NSS > 3 */ | 
|  | 7987 | nss = 3; | 
|  | 7988 | break; | 
|  | 7989 | } | 
|  | 7990 | snprintf(buf, sizeof(buf), | 
|  | 7991 | "iwpriv %s rxchainmask %d", ifname, nss); | 
|  | 7992 | if (system(buf) != 0) { | 
|  | 7993 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 7994 | "iwpriv rxchainmask failed!"); | 
|  | 7995 | } | 
|  | 7996 | } | 
|  | 7997 |  | 
|  | 7998 | /* Opmode notify */ | 
|  | 7999 | snprintf(buf, sizeof(buf), "iwpriv %s opmode_notify 1", ifname); | 
|  | 8000 | if (system(buf) != 0) { | 
|  | 8001 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 8002 | "iwpriv opmode_notify failed!"); | 
|  | 8003 | } else { | 
|  | 8004 | sigma_dut_print(dut, DUT_MSG_INFO, | 
|  | 8005 | "Sent out the notify frame!"); | 
|  | 8006 | } | 
|  | 8007 | } | 
|  | 8008 |  | 
|  | 8009 | return 1; | 
|  | 8010 | } | 
|  | 8011 |  | 
|  | 8012 |  | 
|  | 8013 | static int cmd_sta_send_frame_vht(struct sigma_dut *dut, | 
|  | 8014 | struct sigma_conn *conn, | 
|  | 8015 | struct sigma_cmd *cmd) | 
|  | 8016 | { | 
|  | 8017 | switch (get_driver_type()) { | 
|  | 8018 | case DRIVER_ATHEROS: | 
|  | 8019 | return ath_sta_send_frame_vht(dut, conn, cmd); | 
|  | 8020 | default: | 
|  | 8021 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 8022 | "errorCode,Unsupported sta_set_frame(VHT) with the current driver"); | 
|  | 8023 | return 0; | 
|  | 8024 | } | 
|  | 8025 | } | 
|  | 8026 |  | 
|  | 8027 |  | 
| Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 8028 | #ifdef __linux__ | 
|  | 8029 | int wil6210_send_frame_60g(struct sigma_dut *dut, struct sigma_conn *conn, | 
|  | 8030 | struct sigma_cmd *cmd) | 
|  | 8031 | { | 
|  | 8032 | const char *frame_name = get_param(cmd, "framename"); | 
|  | 8033 | const char *mac = get_param(cmd, "dest_mac"); | 
|  | 8034 |  | 
|  | 8035 | if (!frame_name || !mac) { | 
|  | 8036 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 8037 | "framename and dest_mac must be provided"); | 
|  | 8038 | return -1; | 
|  | 8039 | } | 
|  | 8040 |  | 
|  | 8041 | if (strcasecmp(frame_name, "brp") == 0) { | 
|  | 8042 | const char *l_rx = get_param(cmd, "L-RX"); | 
|  | 8043 | int l_rx_i; | 
|  | 8044 |  | 
|  | 8045 | if (!l_rx) { | 
|  | 8046 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 8047 | "L-RX must be provided"); | 
|  | 8048 | return -1; | 
|  | 8049 | } | 
|  | 8050 | l_rx_i = atoi(l_rx); | 
|  | 8051 |  | 
|  | 8052 | sigma_dut_print(dut, DUT_MSG_INFO, | 
|  | 8053 | "dev_send_frame: BRP-RX, dest_mac %s, L-RX %s", | 
|  | 8054 | mac, l_rx); | 
|  | 8055 | if (l_rx_i != 16) { | 
|  | 8056 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 8057 | "unsupported L-RX: %s", l_rx); | 
|  | 8058 | return -1; | 
|  | 8059 | } | 
|  | 8060 |  | 
|  | 8061 | if (wil6210_send_brp_rx(dut, mac, l_rx_i)) | 
|  | 8062 | return -1; | 
|  | 8063 | } else if (strcasecmp(frame_name, "ssw") == 0) { | 
|  | 8064 | sigma_dut_print(dut, DUT_MSG_INFO, | 
|  | 8065 | "dev_send_frame: SLS, dest_mac %s", mac); | 
|  | 8066 | if (wil6210_send_sls(dut, mac)) | 
|  | 8067 | return -1; | 
|  | 8068 | } else { | 
|  | 8069 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 8070 | "unsupported frame type: %s", frame_name); | 
|  | 8071 | return -1; | 
|  | 8072 | } | 
|  | 8073 |  | 
|  | 8074 | return 1; | 
|  | 8075 | } | 
|  | 8076 | #endif /* __linux__ */ | 
|  | 8077 |  | 
|  | 8078 |  | 
|  | 8079 | static int cmd_sta_send_frame_60g(struct sigma_dut *dut, | 
|  | 8080 | struct sigma_conn *conn, | 
|  | 8081 | struct sigma_cmd *cmd) | 
|  | 8082 | { | 
|  | 8083 | switch (get_driver_type()) { | 
|  | 8084 | #ifdef __linux__ | 
|  | 8085 | case DRIVER_WIL6210: | 
|  | 8086 | return wil6210_send_frame_60g(dut, conn, cmd); | 
|  | 8087 | #endif /* __linux__ */ | 
|  | 8088 | default: | 
|  | 8089 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 8090 | "errorCode,Unsupported sta_set_frame(60G) with the current driver"); | 
|  | 8091 | return 0; | 
|  | 8092 | } | 
|  | 8093 | } | 
|  | 8094 |  | 
|  | 8095 |  | 
| Ashwini Patil | db59b3c | 2017-04-13 15:19:23 +0530 | [diff] [blame] | 8096 | static int mbo_send_anqp_query(struct sigma_dut *dut, struct sigma_conn *conn, | 
|  | 8097 | const char *intf, struct sigma_cmd *cmd) | 
|  | 8098 | { | 
|  | 8099 | const char *val, *addr; | 
|  | 8100 | char buf[100]; | 
|  | 8101 |  | 
|  | 8102 | addr = get_param(cmd, "DestMac"); | 
|  | 8103 | if (!addr) { | 
|  | 8104 | send_resp(dut, conn, SIGMA_INVALID, | 
|  | 8105 | "ErrorCode,AP MAC address is missing"); | 
|  | 8106 | return 0; | 
|  | 8107 | } | 
|  | 8108 |  | 
|  | 8109 | val = get_param(cmd, "ANQPQuery_ID"); | 
|  | 8110 | if (!val) { | 
|  | 8111 | send_resp(dut, conn, SIGMA_INVALID, | 
|  | 8112 | "ErrorCode,Missing ANQPQuery_ID"); | 
|  | 8113 | return 0; | 
|  | 8114 | } | 
|  | 8115 |  | 
|  | 8116 | if (strcasecmp(val, "NeighborReportReq") == 0) { | 
|  | 8117 | snprintf(buf, sizeof(buf), "ANQP_GET %s 272", addr); | 
|  | 8118 | } else if (strcasecmp(val, "QueryListWithCellPref") == 0) { | 
|  | 8119 | snprintf(buf, sizeof(buf), "ANQP_GET %s 272,mbo:2", addr); | 
|  | 8120 | } else { | 
|  | 8121 | sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid ANQPQuery_ID: %s", | 
|  | 8122 | val); | 
|  | 8123 | send_resp(dut, conn, SIGMA_INVALID, | 
|  | 8124 | "ErrorCode,Invalid ANQPQuery_ID"); | 
|  | 8125 | return 0; | 
|  | 8126 | } | 
|  | 8127 |  | 
| Ashwini Patil | d174f2c | 2017-04-13 16:49:46 +0530 | [diff] [blame] | 8128 | /* Set gas_address3 field to IEEE 802.11-2012 standard compliant form | 
|  | 8129 | * (Address3 = Wildcard BSSID when sent to not-associated AP; | 
|  | 8130 | * if associated, AP BSSID). | 
|  | 8131 | */ | 
|  | 8132 | if (wpa_command(intf, "SET gas_address3 1") < 0) { | 
|  | 8133 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 8134 | "ErrorCode,Failed to set gas_address3"); | 
|  | 8135 | return 0; | 
|  | 8136 | } | 
|  | 8137 |  | 
| Ashwini Patil | db59b3c | 2017-04-13 15:19:23 +0530 | [diff] [blame] | 8138 | if (wpa_command(intf, buf) < 0) { | 
|  | 8139 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 8140 | "ErrorCode,Failed to send ANQP query"); | 
|  | 8141 | return 0; | 
|  | 8142 | } | 
|  | 8143 |  | 
|  | 8144 | return 1; | 
|  | 8145 | } | 
|  | 8146 |  | 
|  | 8147 |  | 
|  | 8148 | static int mbo_cmd_sta_send_frame(struct sigma_dut *dut, | 
|  | 8149 | struct sigma_conn *conn, | 
|  | 8150 | const char *intf, | 
|  | 8151 | struct sigma_cmd *cmd) | 
|  | 8152 | { | 
|  | 8153 | const char *val = get_param(cmd, "FrameName"); | 
|  | 8154 |  | 
|  | 8155 | if (val && strcasecmp(val, "ANQPQuery") == 0) | 
|  | 8156 | return mbo_send_anqp_query(dut, conn, intf, cmd); | 
|  | 8157 |  | 
|  | 8158 | return 2; | 
|  | 8159 | } | 
|  | 8160 |  | 
|  | 8161 |  | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8162 | int cmd_sta_send_frame(struct sigma_dut *dut, struct sigma_conn *conn, | 
|  | 8163 | struct sigma_cmd *cmd) | 
|  | 8164 | { | 
|  | 8165 | const char *intf = get_param(cmd, "Interface"); | 
|  | 8166 | const char *val; | 
|  | 8167 | enum send_frame_type frame; | 
|  | 8168 | enum send_frame_protection protected; | 
|  | 8169 | char buf[100]; | 
|  | 8170 | unsigned char addr[ETH_ALEN]; | 
|  | 8171 | int res; | 
|  | 8172 |  | 
|  | 8173 | val = get_param(cmd, "program"); | 
|  | 8174 | if (val == NULL) | 
|  | 8175 | val = get_param(cmd, "frame"); | 
|  | 8176 | if (val && strcasecmp(val, "TDLS") == 0) | 
|  | 8177 | return cmd_sta_send_frame_tdls(dut, conn, cmd); | 
|  | 8178 | if (val && (strcasecmp(val, "HS2") == 0 || | 
|  | 8179 | strcasecmp(val, "HS2-R2") == 0)) | 
|  | 8180 | return cmd_sta_send_frame_hs2(dut, conn, cmd); | 
|  | 8181 | if (val && strcasecmp(val, "VHT") == 0) | 
|  | 8182 | return cmd_sta_send_frame_vht(dut, conn, cmd); | 
| priyadharshini gowthaman | d66913a | 2016-07-29 15:11:17 -0700 | [diff] [blame] | 8183 | if (val && strcasecmp(val, "LOC") == 0) | 
|  | 8184 | return loc_cmd_sta_send_frame(dut, conn, cmd); | 
| Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 8185 | if (val && strcasecmp(val, "60GHz") == 0) | 
|  | 8186 | return cmd_sta_send_frame_60g(dut, conn, cmd); | 
| Ashwini Patil | db59b3c | 2017-04-13 15:19:23 +0530 | [diff] [blame] | 8187 | if (val && strcasecmp(val, "MBO") == 0) { | 
|  | 8188 | res = mbo_cmd_sta_send_frame(dut, conn, intf, cmd); | 
|  | 8189 | if (res != 2) | 
|  | 8190 | return res; | 
|  | 8191 | } | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8192 |  | 
|  | 8193 | val = get_param(cmd, "TD_DISC"); | 
|  | 8194 | if (val) { | 
|  | 8195 | if (hwaddr_aton(val, addr) < 0) | 
|  | 8196 | return -1; | 
|  | 8197 | snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", val); | 
|  | 8198 | if (wpa_command(intf, buf) < 0) { | 
|  | 8199 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 8200 | "ErrorCode,Failed to send TDLS discovery"); | 
|  | 8201 | return 0; | 
|  | 8202 | } | 
|  | 8203 | return 1; | 
|  | 8204 | } | 
|  | 8205 |  | 
|  | 8206 | val = get_param(cmd, "TD_Setup"); | 
|  | 8207 | if (val) { | 
|  | 8208 | if (hwaddr_aton(val, addr) < 0) | 
|  | 8209 | return -1; | 
|  | 8210 | snprintf(buf, sizeof(buf), "TDLS_SETUP %s", val); | 
|  | 8211 | if (wpa_command(intf, buf) < 0) { | 
|  | 8212 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 8213 | "ErrorCode,Failed to start TDLS setup"); | 
|  | 8214 | return 0; | 
|  | 8215 | } | 
|  | 8216 | return 1; | 
|  | 8217 | } | 
|  | 8218 |  | 
|  | 8219 | val = get_param(cmd, "TD_TearDown"); | 
|  | 8220 | if (val) { | 
|  | 8221 | if (hwaddr_aton(val, addr) < 0) | 
|  | 8222 | return -1; | 
|  | 8223 | snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", val); | 
|  | 8224 | if (wpa_command(intf, buf) < 0) { | 
|  | 8225 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 8226 | "ErrorCode,Failed to tear down TDLS link"); | 
|  | 8227 | return 0; | 
|  | 8228 | } | 
|  | 8229 | return 1; | 
|  | 8230 | } | 
|  | 8231 |  | 
|  | 8232 | val = get_param(cmd, "TD_ChannelSwitch"); | 
|  | 8233 | if (val) { | 
|  | 8234 | /* TODO */ | 
|  | 8235 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 8236 | "ErrorCode,TD_ChannelSwitch not yet supported"); | 
|  | 8237 | return 0; | 
|  | 8238 | } | 
|  | 8239 |  | 
|  | 8240 | val = get_param(cmd, "TD_NF"); | 
|  | 8241 | if (val) { | 
|  | 8242 | /* TODO */ | 
|  | 8243 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 8244 | "ErrorCode,TD_NF not yet supported"); | 
|  | 8245 | return 0; | 
|  | 8246 | } | 
|  | 8247 |  | 
|  | 8248 | val = get_param(cmd, "PMFFrameType"); | 
|  | 8249 | if (val == NULL) | 
|  | 8250 | val = get_param(cmd, "FrameName"); | 
|  | 8251 | if (val == NULL) | 
|  | 8252 | val = get_param(cmd, "Type"); | 
|  | 8253 | if (val == NULL) | 
|  | 8254 | return -1; | 
|  | 8255 | if (strcasecmp(val, "disassoc") == 0) | 
|  | 8256 | frame = DISASSOC; | 
|  | 8257 | else if (strcasecmp(val, "deauth") == 0) | 
|  | 8258 | frame = DEAUTH; | 
|  | 8259 | else if (strcasecmp(val, "saquery") == 0) | 
|  | 8260 | frame = SAQUERY; | 
|  | 8261 | else if (strcasecmp(val, "auth") == 0) | 
|  | 8262 | frame = AUTH; | 
|  | 8263 | else if (strcasecmp(val, "assocreq") == 0) | 
|  | 8264 | frame = ASSOCREQ; | 
|  | 8265 | else if (strcasecmp(val, "reassocreq") == 0) | 
|  | 8266 | frame = REASSOCREQ; | 
|  | 8267 | else if (strcasecmp(val, "neigreq") == 0) { | 
|  | 8268 | sigma_dut_print(dut, DUT_MSG_INFO, "Got neighbor request"); | 
|  | 8269 |  | 
|  | 8270 | val = get_param(cmd, "ssid"); | 
|  | 8271 | if (val == NULL) | 
|  | 8272 | return -1; | 
|  | 8273 |  | 
|  | 8274 | res = send_neighbor_request(dut, intf, val); | 
|  | 8275 | if (res) { | 
|  | 8276 | send_resp(dut, conn, SIGMA_ERROR, "errorCode," | 
|  | 8277 | "Failed to send neighbor report request"); | 
|  | 8278 | return 0; | 
|  | 8279 | } | 
|  | 8280 |  | 
|  | 8281 | return 1; | 
| Ashwini Patil | 5acd738 | 2017-04-13 15:55:04 +0530 | [diff] [blame] | 8282 | } else if (strcasecmp(val, "transmgmtquery") == 0 || | 
|  | 8283 | strcasecmp(val, "BTMQuery") == 0) { | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8284 | sigma_dut_print(dut, DUT_MSG_DEBUG, | 
|  | 8285 | "Got Transition Management Query"); | 
|  | 8286 |  | 
| Ashwini Patil | 5acd738 | 2017-04-13 15:55:04 +0530 | [diff] [blame] | 8287 | res = send_trans_mgmt_query(dut, intf, cmd); | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8288 | if (res) { | 
|  | 8289 | send_resp(dut, conn, SIGMA_ERROR, "errorCode," | 
|  | 8290 | "Failed to send Transition Management Query"); | 
|  | 8291 | return 0; | 
|  | 8292 | } | 
|  | 8293 |  | 
|  | 8294 | return 1; | 
|  | 8295 | } else { | 
|  | 8296 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported " | 
|  | 8297 | "PMFFrameType"); | 
|  | 8298 | return 0; | 
|  | 8299 | } | 
|  | 8300 |  | 
|  | 8301 | val = get_param(cmd, "PMFProtected"); | 
|  | 8302 | if (val == NULL) | 
|  | 8303 | val = get_param(cmd, "Protected"); | 
|  | 8304 | if (val == NULL) | 
|  | 8305 | return -1; | 
|  | 8306 | if (strcasecmp(val, "Correct-key") == 0 || | 
|  | 8307 | strcasecmp(val, "CorrectKey") == 0) | 
|  | 8308 | protected = CORRECT_KEY; | 
|  | 8309 | else if (strcasecmp(val, "IncorrectKey") == 0) | 
|  | 8310 | protected = INCORRECT_KEY; | 
|  | 8311 | else if (strcasecmp(val, "Unprotected") == 0) | 
|  | 8312 | protected = UNPROTECTED; | 
|  | 8313 | else { | 
|  | 8314 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported " | 
|  | 8315 | "PMFProtected"); | 
|  | 8316 | return 0; | 
|  | 8317 | } | 
|  | 8318 |  | 
|  | 8319 | if (protected != UNPROTECTED && | 
|  | 8320 | (frame == AUTH || frame == ASSOCREQ || frame == REASSOCREQ)) { | 
|  | 8321 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Impossible " | 
|  | 8322 | "PMFProtected for auth/assocreq/reassocreq"); | 
|  | 8323 | return 0; | 
|  | 8324 | } | 
|  | 8325 |  | 
|  | 8326 | if (if_nametoindex("sigmadut") == 0) { | 
|  | 8327 | snprintf(buf, sizeof(buf), | 
|  | 8328 | "iw dev %s interface add sigmadut type monitor", | 
|  | 8329 | get_station_ifname()); | 
|  | 8330 | if (system(buf) != 0 || | 
|  | 8331 | if_nametoindex("sigmadut") == 0) { | 
|  | 8332 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add " | 
|  | 8333 | "monitor interface with '%s'", buf); | 
|  | 8334 | return -2; | 
|  | 8335 | } | 
|  | 8336 | } | 
|  | 8337 |  | 
|  | 8338 | if (system("ifconfig sigmadut up") != 0) { | 
|  | 8339 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set " | 
|  | 8340 | "monitor interface up"); | 
|  | 8341 | return -2; | 
|  | 8342 | } | 
|  | 8343 |  | 
|  | 8344 | return sta_inject_frame(dut, conn, frame, protected, NULL); | 
|  | 8345 | } | 
|  | 8346 |  | 
|  | 8347 |  | 
|  | 8348 | static int cmd_sta_set_parameter_hs2(struct sigma_dut *dut, | 
|  | 8349 | struct sigma_conn *conn, | 
|  | 8350 | struct sigma_cmd *cmd, | 
|  | 8351 | const char *ifname) | 
|  | 8352 | { | 
|  | 8353 | char buf[200]; | 
|  | 8354 | const char *val; | 
|  | 8355 |  | 
|  | 8356 | val = get_param(cmd, "ClearARP"); | 
|  | 8357 | if (val && atoi(val) == 1) { | 
|  | 8358 | snprintf(buf, sizeof(buf), "ip neigh flush dev %s", ifname); | 
|  | 8359 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); | 
|  | 8360 | if (system(buf) != 0) { | 
|  | 8361 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 8362 | "errorCode,Failed to clear ARP cache"); | 
|  | 8363 | return 0; | 
|  | 8364 | } | 
|  | 8365 | } | 
|  | 8366 |  | 
|  | 8367 | return 1; | 
|  | 8368 | } | 
|  | 8369 |  | 
|  | 8370 |  | 
|  | 8371 | int cmd_sta_set_parameter(struct sigma_dut *dut, struct sigma_conn *conn, | 
|  | 8372 | struct sigma_cmd *cmd) | 
|  | 8373 | { | 
|  | 8374 | const char *intf = get_param(cmd, "Interface"); | 
|  | 8375 | const char *val; | 
|  | 8376 |  | 
|  | 8377 | if (intf == NULL) | 
|  | 8378 | return -1; | 
|  | 8379 |  | 
|  | 8380 | val = get_param(cmd, "program"); | 
|  | 8381 | if (val && (strcasecmp(val, "HS2") == 0 || | 
|  | 8382 | strcasecmp(val, "HS2-R2") == 0)) | 
|  | 8383 | return cmd_sta_set_parameter_hs2(dut, conn, cmd, intf); | 
|  | 8384 |  | 
|  | 8385 | return -1; | 
|  | 8386 | } | 
|  | 8387 |  | 
|  | 8388 |  | 
|  | 8389 | static int cmd_sta_set_macaddr(struct sigma_dut *dut, struct sigma_conn *conn, | 
|  | 8390 | struct sigma_cmd *cmd) | 
|  | 8391 | { | 
|  | 8392 | const char *intf = get_param(cmd, "Interface"); | 
|  | 8393 | const char *mac = get_param(cmd, "MAC"); | 
|  | 8394 |  | 
|  | 8395 | if (intf == NULL || mac == NULL) | 
|  | 8396 | return -1; | 
|  | 8397 |  | 
|  | 8398 | sigma_dut_print(dut, DUT_MSG_INFO, "Change local MAC address for " | 
|  | 8399 | "interface %s to %s", intf, mac); | 
|  | 8400 |  | 
|  | 8401 | if (dut->set_macaddr) { | 
|  | 8402 | char buf[128]; | 
|  | 8403 | int res; | 
|  | 8404 | if (strcasecmp(mac, "default") == 0) { | 
|  | 8405 | res = snprintf(buf, sizeof(buf), "%s", | 
|  | 8406 | dut->set_macaddr); | 
|  | 8407 | dut->tmp_mac_addr = 0; | 
|  | 8408 | } else { | 
|  | 8409 | res = snprintf(buf, sizeof(buf), "%s %s", | 
|  | 8410 | dut->set_macaddr, mac); | 
|  | 8411 | dut->tmp_mac_addr = 1; | 
|  | 8412 | } | 
|  | 8413 | if (res < 0 || res >= (int) sizeof(buf)) | 
|  | 8414 | return -1; | 
|  | 8415 | if (system(buf) != 0) { | 
|  | 8416 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 8417 | "errorCode,Failed to set MAC " | 
|  | 8418 | "address"); | 
|  | 8419 | return 0; | 
|  | 8420 | } | 
|  | 8421 | return 1; | 
|  | 8422 | } | 
|  | 8423 |  | 
|  | 8424 | if (strcasecmp(mac, "default") == 0) | 
|  | 8425 | return 1; | 
|  | 8426 |  | 
|  | 8427 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported " | 
|  | 8428 | "command"); | 
|  | 8429 | return 0; | 
|  | 8430 | } | 
|  | 8431 |  | 
|  | 8432 |  | 
|  | 8433 | static int iwpriv_tdlsoffchnmode(struct sigma_dut *dut, | 
|  | 8434 | struct sigma_conn *conn, const char *intf, | 
|  | 8435 | int val) | 
|  | 8436 | { | 
|  | 8437 | char buf[200]; | 
|  | 8438 | int res; | 
|  | 8439 |  | 
|  | 8440 | res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchnmode %d", | 
|  | 8441 | intf, val); | 
|  | 8442 | if (res < 0 || res >= (int) sizeof(buf)) | 
|  | 8443 | return -1; | 
|  | 8444 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); | 
|  | 8445 | if (system(buf) != 0) { | 
|  | 8446 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 8447 | "errorCode,Failed to configure offchannel mode"); | 
|  | 8448 | return 0; | 
|  | 8449 | } | 
|  | 8450 |  | 
|  | 8451 | return 1; | 
|  | 8452 | } | 
|  | 8453 |  | 
|  | 8454 |  | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8455 | static int off_chan_val(enum sec_ch_offset off) | 
|  | 8456 | { | 
|  | 8457 | switch (off) { | 
|  | 8458 | case SEC_CH_NO: | 
|  | 8459 | return 0; | 
|  | 8460 | case SEC_CH_40ABOVE: | 
|  | 8461 | return 40; | 
|  | 8462 | case SEC_CH_40BELOW: | 
|  | 8463 | return -40; | 
|  | 8464 | } | 
|  | 8465 |  | 
|  | 8466 | return 0; | 
|  | 8467 | } | 
|  | 8468 |  | 
|  | 8469 |  | 
|  | 8470 | static int iwpriv_set_offchan(struct sigma_dut *dut, struct sigma_conn *conn, | 
|  | 8471 | const char *intf, int off_ch_num, | 
|  | 8472 | enum sec_ch_offset sec) | 
|  | 8473 | { | 
|  | 8474 | char buf[200]; | 
|  | 8475 | int res; | 
|  | 8476 |  | 
|  | 8477 | res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchan %d", | 
|  | 8478 | intf, off_ch_num); | 
|  | 8479 | if (res < 0 || res >= (int) sizeof(buf)) | 
|  | 8480 | return -1; | 
|  | 8481 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); | 
|  | 8482 | if (system(buf) != 0) { | 
|  | 8483 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 8484 | "errorCode,Failed to set offchan"); | 
|  | 8485 | return 0; | 
|  | 8486 | } | 
|  | 8487 |  | 
|  | 8488 | res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsecchnoffst %d", | 
|  | 8489 | intf, off_chan_val(sec)); | 
|  | 8490 | if (res < 0 || res >= (int) sizeof(buf)) | 
|  | 8491 | return -1; | 
|  | 8492 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); | 
|  | 8493 | if (system(buf) != 0) { | 
|  | 8494 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 8495 | "errorCode,Failed to set sec chan offset"); | 
|  | 8496 | return 0; | 
|  | 8497 | } | 
|  | 8498 |  | 
|  | 8499 | return 1; | 
|  | 8500 | } | 
|  | 8501 |  | 
|  | 8502 |  | 
|  | 8503 | static int tdls_set_offchannel_offset(struct sigma_dut *dut, | 
|  | 8504 | struct sigma_conn *conn, | 
|  | 8505 | const char *intf, int off_ch_num, | 
|  | 8506 | enum sec_ch_offset sec) | 
|  | 8507 | { | 
|  | 8508 | char buf[200]; | 
|  | 8509 | int res; | 
|  | 8510 |  | 
|  | 8511 | res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNEL %d", | 
|  | 8512 | off_ch_num); | 
|  | 8513 | if (res < 0 || res >= (int) sizeof(buf)) | 
|  | 8514 | return -1; | 
|  | 8515 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); | 
|  | 8516 |  | 
|  | 8517 | if (wpa_command(intf, buf) < 0) { | 
|  | 8518 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 8519 | "ErrorCode,Failed to set offchan"); | 
|  | 8520 | return 0; | 
|  | 8521 | } | 
|  | 8522 | res = snprintf(buf, sizeof(buf), "DRIVER TDLSSECONDARYCHANNELOFFSET %d", | 
|  | 8523 | off_chan_val(sec)); | 
|  | 8524 | if (res < 0 || res >= (int) sizeof(buf)) | 
|  | 8525 | return -1; | 
|  | 8526 |  | 
|  | 8527 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); | 
|  | 8528 |  | 
|  | 8529 | if (wpa_command(intf, buf) < 0) { | 
|  | 8530 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 8531 | "ErrorCode,Failed to set sec chan offset"); | 
|  | 8532 | return 0; | 
|  | 8533 | } | 
|  | 8534 |  | 
|  | 8535 | return 1; | 
|  | 8536 | } | 
|  | 8537 |  | 
|  | 8538 |  | 
|  | 8539 | static int tdls_set_offchannel_mode(struct sigma_dut *dut, | 
|  | 8540 | struct sigma_conn *conn, | 
|  | 8541 | const char *intf, int val) | 
|  | 8542 | { | 
|  | 8543 | char buf[200]; | 
|  | 8544 | int res; | 
|  | 8545 |  | 
|  | 8546 | res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNELMODE %d", | 
|  | 8547 | val); | 
|  | 8548 | if (res < 0 || res >= (int) sizeof(buf)) | 
|  | 8549 | return -1; | 
|  | 8550 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); | 
|  | 8551 |  | 
|  | 8552 | if (wpa_command(intf, buf) < 0) { | 
|  | 8553 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 8554 | "ErrorCode,Failed to configure offchannel mode"); | 
|  | 8555 | return 0; | 
|  | 8556 | } | 
|  | 8557 |  | 
|  | 8558 | return 1; | 
|  | 8559 | } | 
|  | 8560 |  | 
|  | 8561 |  | 
|  | 8562 | static int cmd_sta_set_rfeature_tdls(const char *intf, struct sigma_dut *dut, | 
|  | 8563 | struct sigma_conn *conn, | 
|  | 8564 | struct sigma_cmd *cmd) | 
|  | 8565 | { | 
|  | 8566 | const char *val; | 
|  | 8567 | enum { | 
|  | 8568 | CHSM_NOT_SET, | 
|  | 8569 | CHSM_ENABLE, | 
|  | 8570 | CHSM_DISABLE, | 
|  | 8571 | CHSM_REJREQ, | 
|  | 8572 | CHSM_UNSOLRESP | 
|  | 8573 | } chsm = CHSM_NOT_SET; | 
|  | 8574 | int off_ch_num = -1; | 
|  | 8575 | enum sec_ch_offset sec_ch = SEC_CH_NO; | 
|  | 8576 | int res; | 
|  | 8577 |  | 
|  | 8578 | val = get_param(cmd, "Uapsd"); | 
|  | 8579 | if (val) { | 
|  | 8580 | char buf[100]; | 
|  | 8581 | if (strcasecmp(val, "Enable") == 0) | 
|  | 8582 | snprintf(buf, sizeof(buf), "SET ps 99"); | 
|  | 8583 | else if (strcasecmp(val, "Disable") == 0) | 
|  | 8584 | snprintf(buf, sizeof(buf), "SET ps 98"); | 
|  | 8585 | else { | 
|  | 8586 | send_resp(dut, conn, SIGMA_ERROR, "errorCode," | 
|  | 8587 | "Unsupported uapsd parameter value"); | 
|  | 8588 | return 0; | 
|  | 8589 | } | 
|  | 8590 | if (wpa_command(intf, buf)) { | 
|  | 8591 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 8592 | "ErrorCode,Failed to change U-APSD " | 
|  | 8593 | "powersave mode"); | 
|  | 8594 | return 0; | 
|  | 8595 | } | 
|  | 8596 | } | 
|  | 8597 |  | 
|  | 8598 | val = get_param(cmd, "TPKTIMER"); | 
|  | 8599 | if (val && strcasecmp(val, "DISABLE") == 0) { | 
|  | 8600 | if (wpa_command(intf, "SET tdls_testing 0x100")) { | 
|  | 8601 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 8602 | "ErrorCode,Failed to enable no TPK " | 
|  | 8603 | "expiration test mode"); | 
|  | 8604 | return 0; | 
|  | 8605 | } | 
|  | 8606 | dut->no_tpk_expiration = 1; | 
|  | 8607 | } | 
|  | 8608 |  | 
|  | 8609 | val = get_param(cmd, "ChSwitchMode"); | 
|  | 8610 | if (val) { | 
|  | 8611 | if (strcasecmp(val, "Enable") == 0 || | 
|  | 8612 | strcasecmp(val, "Initiate") == 0) | 
|  | 8613 | chsm = CHSM_ENABLE; | 
|  | 8614 | else if (strcasecmp(val, "Disable") == 0 || | 
|  | 8615 | strcasecmp(val, "passive") == 0) | 
|  | 8616 | chsm = CHSM_DISABLE; | 
|  | 8617 | else if (strcasecmp(val, "RejReq") == 0) | 
|  | 8618 | chsm = CHSM_REJREQ; | 
|  | 8619 | else if (strcasecmp(val, "UnSolResp") == 0) | 
|  | 8620 | chsm = CHSM_UNSOLRESP; | 
|  | 8621 | else { | 
|  | 8622 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 8623 | "ErrorCode,Unknown ChSwitchMode value"); | 
|  | 8624 | return 0; | 
|  | 8625 | } | 
|  | 8626 | } | 
|  | 8627 |  | 
|  | 8628 | val = get_param(cmd, "OffChNum"); | 
|  | 8629 | if (val) { | 
|  | 8630 | off_ch_num = atoi(val); | 
|  | 8631 | if (off_ch_num == 0) { | 
|  | 8632 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 8633 | "ErrorCode,Invalid OffChNum"); | 
|  | 8634 | return 0; | 
|  | 8635 | } | 
|  | 8636 | } | 
|  | 8637 |  | 
|  | 8638 | val = get_param(cmd, "SecChOffset"); | 
|  | 8639 | if (val) { | 
|  | 8640 | if (strcmp(val, "20") == 0) | 
|  | 8641 | sec_ch = SEC_CH_NO; | 
|  | 8642 | else if (strcasecmp(val, "40above") == 0) | 
|  | 8643 | sec_ch = SEC_CH_40ABOVE; | 
|  | 8644 | else if (strcasecmp(val, "40below") == 0) | 
|  | 8645 | sec_ch = SEC_CH_40BELOW; | 
|  | 8646 | else { | 
|  | 8647 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 8648 | "ErrorCode,Unknown SecChOffset value"); | 
|  | 8649 | return 0; | 
|  | 8650 | } | 
|  | 8651 | } | 
|  | 8652 |  | 
|  | 8653 | if (chsm == CHSM_NOT_SET) { | 
|  | 8654 | /* no offchannel changes requested */ | 
|  | 8655 | return 1; | 
|  | 8656 | } | 
|  | 8657 |  | 
|  | 8658 | if (strcmp(intf, get_main_ifname()) != 0 && | 
|  | 8659 | strcmp(intf, get_station_ifname()) != 0) { | 
|  | 8660 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 8661 | "ErrorCode,Unknown interface"); | 
|  | 8662 | return 0; | 
|  | 8663 | } | 
|  | 8664 |  | 
|  | 8665 | switch (chsm) { | 
|  | 8666 | case CHSM_NOT_SET: | 
| Jouni Malinen | 280f5ba | 2016-08-29 21:33:10 +0300 | [diff] [blame] | 8667 | res = 1; | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8668 | break; | 
|  | 8669 | case CHSM_ENABLE: | 
|  | 8670 | if (off_ch_num < 0) { | 
|  | 8671 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 8672 | "ErrorCode,Missing OffChNum argument"); | 
|  | 8673 | return 0; | 
|  | 8674 | } | 
|  | 8675 | if (wifi_chip_type == DRIVER_WCN) { | 
|  | 8676 | res = tdls_set_offchannel_offset(dut, conn, intf, | 
|  | 8677 | off_ch_num, sec_ch); | 
|  | 8678 | } else { | 
|  | 8679 | res = iwpriv_set_offchan(dut, conn, intf, off_ch_num, | 
|  | 8680 | sec_ch); | 
|  | 8681 | } | 
|  | 8682 | if (res != 1) | 
|  | 8683 | return res; | 
|  | 8684 | if (wifi_chip_type == DRIVER_WCN) | 
|  | 8685 | res = tdls_set_offchannel_mode(dut, conn, intf, 1); | 
|  | 8686 | else | 
|  | 8687 | res = iwpriv_tdlsoffchnmode(dut, conn, intf, 1); | 
|  | 8688 | break; | 
|  | 8689 | case CHSM_DISABLE: | 
|  | 8690 | if (wifi_chip_type == DRIVER_WCN) | 
|  | 8691 | res = tdls_set_offchannel_mode(dut, conn, intf, 2); | 
|  | 8692 | else | 
|  | 8693 | res = iwpriv_tdlsoffchnmode(dut, conn, intf, 2); | 
|  | 8694 | break; | 
|  | 8695 | case CHSM_REJREQ: | 
|  | 8696 | if (wifi_chip_type == DRIVER_WCN) | 
|  | 8697 | res = tdls_set_offchannel_mode(dut, conn, intf, 3); | 
|  | 8698 | else | 
|  | 8699 | res = iwpriv_tdlsoffchnmode(dut, conn, intf, 3); | 
|  | 8700 | break; | 
|  | 8701 | case CHSM_UNSOLRESP: | 
|  | 8702 | if (off_ch_num < 0) { | 
|  | 8703 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 8704 | "ErrorCode,Missing OffChNum argument"); | 
|  | 8705 | return 0; | 
|  | 8706 | } | 
|  | 8707 | if (wifi_chip_type == DRIVER_WCN) { | 
|  | 8708 | res = tdls_set_offchannel_offset(dut, conn, intf, | 
|  | 8709 | off_ch_num, sec_ch); | 
|  | 8710 | } else { | 
|  | 8711 | res = iwpriv_set_offchan(dut, conn, intf, off_ch_num, | 
|  | 8712 | sec_ch); | 
|  | 8713 | } | 
|  | 8714 | if (res != 1) | 
|  | 8715 | return res; | 
|  | 8716 | if (wifi_chip_type == DRIVER_WCN) | 
|  | 8717 | res = tdls_set_offchannel_mode(dut, conn, intf, 4); | 
|  | 8718 | else | 
|  | 8719 | res = iwpriv_tdlsoffchnmode(dut, conn, intf, 4); | 
|  | 8720 | break; | 
|  | 8721 | } | 
|  | 8722 |  | 
|  | 8723 | return res; | 
|  | 8724 | } | 
|  | 8725 |  | 
|  | 8726 |  | 
|  | 8727 | static int ath_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut, | 
|  | 8728 | struct sigma_conn *conn, | 
|  | 8729 | struct sigma_cmd *cmd) | 
|  | 8730 | { | 
|  | 8731 | const char *val; | 
|  | 8732 | char *token, *result; | 
|  | 8733 |  | 
| priyadharshini gowthaman | e5e2517 | 2015-12-08 14:53:48 -0800 | [diff] [blame] | 8734 | novap_reset(dut, intf); | 
|  | 8735 |  | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8736 | val = get_param(cmd, "nss_mcs_opt"); | 
|  | 8737 | if (val) { | 
|  | 8738 | /* String (nss_operating_mode; mcs_operating_mode) */ | 
|  | 8739 | int nss, mcs; | 
|  | 8740 | char buf[50]; | 
| Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 8741 | char *saveptr; | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8742 |  | 
|  | 8743 | token = strdup(val); | 
|  | 8744 | if (!token) | 
|  | 8745 | return 0; | 
| Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 8746 | result = strtok_r(token, ";", &saveptr); | 
| Pradeep Reddy POTTETI | 41b8c54 | 2016-06-15 16:09:46 +0530 | [diff] [blame] | 8747 | if (!result) { | 
|  | 8748 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 8749 | "VHT NSS not specified"); | 
|  | 8750 | goto failed; | 
|  | 8751 | } | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8752 | if (strcasecmp(result, "def") != 0) { | 
|  | 8753 | nss = atoi(result); | 
|  | 8754 | if (nss == 4) | 
|  | 8755 | ath_disable_txbf(dut, intf); | 
|  | 8756 | snprintf(buf, sizeof(buf), "iwpriv %s nss %d", | 
|  | 8757 | intf, nss); | 
|  | 8758 | if (system(buf) != 0) { | 
|  | 8759 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 8760 | "iwpriv nss failed"); | 
|  | 8761 | goto failed; | 
|  | 8762 | } | 
|  | 8763 | } | 
|  | 8764 |  | 
| Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 8765 | result = strtok_r(NULL, ";", &saveptr); | 
| Pradeep Reddy POTTETI | 41b8c54 | 2016-06-15 16:09:46 +0530 | [diff] [blame] | 8766 | if (!result) { | 
|  | 8767 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 8768 | "VHT MCS not specified"); | 
|  | 8769 | goto failed; | 
|  | 8770 | } | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8771 | if (strcasecmp(result, "def") == 0) { | 
|  | 8772 | snprintf(buf, sizeof(buf), "iwpriv %s set11NRates 0", | 
|  | 8773 | intf); | 
|  | 8774 | if (system(buf) != 0) { | 
|  | 8775 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 8776 | "iwpriv set11NRates failed"); | 
|  | 8777 | goto failed; | 
|  | 8778 | } | 
|  | 8779 |  | 
|  | 8780 | } else { | 
|  | 8781 | mcs = atoi(result); | 
|  | 8782 | snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs %d", | 
|  | 8783 | intf, mcs); | 
|  | 8784 | if (system(buf) != 0) { | 
|  | 8785 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 8786 | "iwpriv vhtmcs failed"); | 
|  | 8787 | goto failed; | 
|  | 8788 | } | 
|  | 8789 | } | 
|  | 8790 | /* Channel width gets messed up, fix this */ | 
|  | 8791 | snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d", | 
|  | 8792 | intf, dut->chwidth); | 
|  | 8793 | if (system(buf) != 0) { | 
|  | 8794 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 8795 | "iwpriv chwidth failed"); | 
|  | 8796 | } | 
|  | 8797 | } | 
|  | 8798 |  | 
|  | 8799 | return 1; | 
|  | 8800 | failed: | 
|  | 8801 | free(token); | 
|  | 8802 | return 0; | 
|  | 8803 | } | 
|  | 8804 |  | 
|  | 8805 |  | 
|  | 8806 | static int cmd_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut, | 
|  | 8807 | struct sigma_conn *conn, | 
|  | 8808 | struct sigma_cmd *cmd) | 
|  | 8809 | { | 
|  | 8810 | switch (get_driver_type()) { | 
|  | 8811 | case DRIVER_ATHEROS: | 
|  | 8812 | return ath_sta_set_rfeature_vht(intf, dut, conn, cmd); | 
|  | 8813 | default: | 
|  | 8814 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 8815 | "errorCode,Unsupported sta_set_rfeature(VHT) with the current driver"); | 
|  | 8816 | return 0; | 
|  | 8817 | } | 
|  | 8818 | } | 
|  | 8819 |  | 
|  | 8820 |  | 
| Amarnath Hullur Subramanyam | 42c25a0 | 2018-01-31 04:02:27 -0800 | [diff] [blame] | 8821 | static int wcn_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut, | 
|  | 8822 | struct sigma_conn *conn, | 
|  | 8823 | struct sigma_cmd *cmd) | 
|  | 8824 | { | 
|  | 8825 | const char *val; | 
|  | 8826 | char *token = NULL, *result; | 
|  | 8827 | char buf[60]; | 
|  | 8828 |  | 
|  | 8829 | val = get_param(cmd, "nss_mcs_opt"); | 
|  | 8830 | if (val) { | 
|  | 8831 | /* String (nss_operating_mode; mcs_operating_mode) */ | 
|  | 8832 | int nss, mcs, ratecode; | 
|  | 8833 | char *saveptr; | 
|  | 8834 |  | 
|  | 8835 | token = strdup(val); | 
|  | 8836 | if (!token) | 
|  | 8837 | return -2; | 
|  | 8838 |  | 
|  | 8839 | result = strtok_r(token, ";", &saveptr); | 
|  | 8840 | if (!result) { | 
|  | 8841 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 8842 | "HE NSS not specified"); | 
|  | 8843 | goto failed; | 
|  | 8844 | } | 
|  | 8845 | nss = 1; | 
|  | 8846 | if (strcasecmp(result, "def") != 0) | 
|  | 8847 | nss = atoi(result); | 
|  | 8848 |  | 
|  | 8849 | result = strtok_r(NULL, ";", &saveptr); | 
|  | 8850 | if (!result) { | 
|  | 8851 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 8852 | "HE MCS not specified"); | 
|  | 8853 | goto failed; | 
|  | 8854 | } | 
|  | 8855 | mcs = 7; | 
|  | 8856 | if (strcasecmp(result, "def") != 0) | 
|  | 8857 | mcs = atoi(result); | 
|  | 8858 |  | 
|  | 8859 | ratecode = 0x400; /* for nss:1 MCS 0 */ | 
|  | 8860 | if (nss == 2) { | 
|  | 8861 | ratecode = 0x420; /* for nss:2 MCS 0 */ | 
|  | 8862 | } else if (nss > 2) { | 
|  | 8863 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 8864 | "HE NSS %d not supported", nss); | 
|  | 8865 | goto failed; | 
|  | 8866 | } | 
|  | 8867 |  | 
|  | 8868 | /* Add the MCS to the ratecode */ | 
|  | 8869 | if (mcs >= 0 && mcs <= 11) { | 
|  | 8870 | ratecode += mcs; | 
|  | 8871 | } else { | 
|  | 8872 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 8873 | "HE MCS %d not supported", mcs); | 
|  | 8874 | goto failed; | 
|  | 8875 | } | 
|  | 8876 | snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0x%03x", | 
|  | 8877 | intf, ratecode); | 
|  | 8878 | if (system(buf) != 0) { | 
|  | 8879 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 8880 | "iwpriv setting of 11ax rates failed"); | 
|  | 8881 | goto failed; | 
|  | 8882 | } | 
|  | 8883 | free(token); | 
|  | 8884 | } | 
|  | 8885 |  | 
|  | 8886 | val = get_param(cmd, "GI"); | 
|  | 8887 | if (val) { | 
|  | 8888 | if (strcmp(val, "0.8") == 0) { | 
|  | 8889 | snprintf(buf, sizeof(buf), "iwpriv %s shortgi 0", intf); | 
|  | 8890 | } else if (strcmp(val, "1.6") == 0) { | 
|  | 8891 | snprintf(buf, sizeof(buf), "iwpriv %s shortgi 2", intf); | 
|  | 8892 | } else if (strcmp(val, "3.2") == 0) { | 
|  | 8893 | snprintf(buf, sizeof(buf), "iwpriv %s shortgi 3", intf); | 
|  | 8894 | } else { | 
|  | 8895 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 8896 | "errorCode,GI value not supported"); | 
|  | 8897 | return 0; | 
|  | 8898 | } | 
|  | 8899 | if (system(buf) != 0) { | 
|  | 8900 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 8901 | "errorCode,Failed to set shortgi"); | 
|  | 8902 | return 0; | 
|  | 8903 | } | 
|  | 8904 | } | 
|  | 8905 |  | 
|  | 8906 | return 1; | 
|  | 8907 |  | 
|  | 8908 | failed: | 
|  | 8909 | free(token); | 
|  | 8910 | return -2; | 
|  | 8911 | } | 
|  | 8912 |  | 
|  | 8913 |  | 
|  | 8914 | static int cmd_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut, | 
|  | 8915 | struct sigma_conn *conn, | 
|  | 8916 | struct sigma_cmd *cmd) | 
|  | 8917 | { | 
|  | 8918 | switch (get_driver_type()) { | 
|  | 8919 | case DRIVER_WCN: | 
|  | 8920 | return wcn_sta_set_rfeature_he(intf, dut, conn, cmd); | 
|  | 8921 | default: | 
|  | 8922 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 8923 | "errorCode,Unsupported sta_set_rfeature(HE) with the current driver"); | 
|  | 8924 | return 0; | 
|  | 8925 | } | 
|  | 8926 | } | 
|  | 8927 |  | 
|  | 8928 |  | 
| Ashwini Patil | 5acd738 | 2017-04-13 15:55:04 +0530 | [diff] [blame] | 8929 | static int btm_query_candidate_list(struct sigma_dut *dut, | 
|  | 8930 | struct sigma_conn *conn, | 
|  | 8931 | struct sigma_cmd *cmd) | 
|  | 8932 | { | 
|  | 8933 | const char *bssid, *info, *op_class, *ch, *phy_type, *pref; | 
|  | 8934 | int len, ret; | 
|  | 8935 | char buf[10]; | 
|  | 8936 |  | 
|  | 8937 | /* | 
|  | 8938 | * Neighbor Report elements format: | 
|  | 8939 | * neighbor=<BSSID>,<BSSID Information>,<Operating Class>, | 
|  | 8940 | * <Channel Number>,<PHY Type>[,<hexdump of Optional Subelements>] | 
|  | 8941 | * eg: neighbor=aa:bb:cc:dd:ee:ff,17,81,6,1,030101 | 
|  | 8942 | */ | 
|  | 8943 |  | 
|  | 8944 | bssid = get_param(cmd, "Nebor_BSSID"); | 
|  | 8945 | if (!bssid) { | 
|  | 8946 | send_resp(dut, conn, SIGMA_INVALID, | 
|  | 8947 | "errorCode,Nebor_BSSID is missing"); | 
|  | 8948 | return 0; | 
|  | 8949 | } | 
|  | 8950 |  | 
|  | 8951 | info = get_param(cmd, "Nebor_Bssid_Info"); | 
|  | 8952 | if (!info) { | 
|  | 8953 | sigma_dut_print(dut, DUT_MSG_INFO, | 
|  | 8954 | "Using default value for Nebor_Bssid_Info: %s", | 
|  | 8955 | DEFAULT_NEIGHBOR_BSSID_INFO); | 
|  | 8956 | info = DEFAULT_NEIGHBOR_BSSID_INFO; | 
|  | 8957 | } | 
|  | 8958 |  | 
|  | 8959 | op_class = get_param(cmd, "Nebor_Op_Class"); | 
|  | 8960 | if (!op_class) { | 
|  | 8961 | send_resp(dut, conn, SIGMA_INVALID, | 
|  | 8962 | "errorCode,Nebor_Op_Class is missing"); | 
|  | 8963 | return 0; | 
|  | 8964 | } | 
|  | 8965 |  | 
|  | 8966 | ch = get_param(cmd, "Nebor_Op_Ch"); | 
|  | 8967 | if (!ch) { | 
|  | 8968 | send_resp(dut, conn, SIGMA_INVALID, | 
|  | 8969 | "errorCode,Nebor_Op_Ch is missing"); | 
|  | 8970 | return 0; | 
|  | 8971 | } | 
|  | 8972 |  | 
|  | 8973 | phy_type = get_param(cmd, "Nebor_Phy_Type"); | 
|  | 8974 | if (!phy_type) { | 
|  | 8975 | sigma_dut_print(dut, DUT_MSG_INFO, | 
|  | 8976 | "Using default value for Nebor_Phy_Type: %s", | 
|  | 8977 | DEFAULT_NEIGHBOR_PHY_TYPE); | 
|  | 8978 | phy_type = DEFAULT_NEIGHBOR_PHY_TYPE; | 
|  | 8979 | } | 
|  | 8980 |  | 
|  | 8981 | /* Parse optional subelements */ | 
|  | 8982 | buf[0] = '\0'; | 
|  | 8983 | pref = get_param(cmd, "Nebor_Pref"); | 
|  | 8984 | if (pref) { | 
|  | 8985 | /* hexdump for preferrence subelement */ | 
|  | 8986 | ret = snprintf(buf, sizeof(buf), ",0301%02x", atoi(pref)); | 
|  | 8987 | if (ret < 0 || ret >= (int) sizeof(buf)) { | 
|  | 8988 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 8989 | "snprintf failed for optional subelement ret: %d", | 
|  | 8990 | ret); | 
|  | 8991 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 8992 | "errorCode,snprintf failed for subelement"); | 
|  | 8993 | return 0; | 
|  | 8994 | } | 
|  | 8995 | } | 
|  | 8996 |  | 
|  | 8997 | if (!dut->btm_query_cand_list) { | 
|  | 8998 | dut->btm_query_cand_list = calloc(1, NEIGHBOR_REPORT_SIZE); | 
|  | 8999 | if (!dut->btm_query_cand_list) { | 
|  | 9000 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 9001 | "errorCode,Failed to allocate memory for btm_query_cand_list"); | 
|  | 9002 | return 0; | 
|  | 9003 | } | 
|  | 9004 | } | 
|  | 9005 |  | 
|  | 9006 | len = strlen(dut->btm_query_cand_list); | 
|  | 9007 | ret = snprintf(dut->btm_query_cand_list + len, | 
|  | 9008 | NEIGHBOR_REPORT_SIZE - len, " neighbor=%s,%s,%s,%s,%s%s", | 
|  | 9009 | bssid, info, op_class, ch, phy_type, buf); | 
|  | 9010 | if (ret < 0 || ret >= NEIGHBOR_REPORT_SIZE - len) { | 
|  | 9011 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 9012 | "snprintf failed for neighbor report list ret: %d", | 
|  | 9013 | ret); | 
|  | 9014 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 9015 | "errorCode,snprintf failed for neighbor report"); | 
|  | 9016 | free(dut->btm_query_cand_list); | 
|  | 9017 | dut->btm_query_cand_list = NULL; | 
|  | 9018 | return 0; | 
|  | 9019 | } | 
|  | 9020 |  | 
|  | 9021 | return 1; | 
|  | 9022 | } | 
|  | 9023 |  | 
|  | 9024 |  | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 9025 | static int cmd_sta_set_rfeature(struct sigma_dut *dut, struct sigma_conn *conn, | 
|  | 9026 | struct sigma_cmd *cmd) | 
|  | 9027 | { | 
|  | 9028 | const char *intf = get_param(cmd, "Interface"); | 
|  | 9029 | const char *prog = get_param(cmd, "Prog"); | 
| Ashwini Patil | 68d02cd | 2017-01-10 15:39:16 +0530 | [diff] [blame] | 9030 | const char *val; | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 9031 |  | 
|  | 9032 | if (intf == NULL || prog == NULL) | 
|  | 9033 | return -1; | 
|  | 9034 |  | 
| Ashwini Patil | 5acd738 | 2017-04-13 15:55:04 +0530 | [diff] [blame] | 9035 | /* BSS Transition candidate list for BTM query */ | 
|  | 9036 | val = get_param(cmd, "Nebor_BSSID"); | 
|  | 9037 | if (val && btm_query_candidate_list(dut, conn, cmd) == 0) | 
|  | 9038 | return 0; | 
|  | 9039 |  | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 9040 | if (strcasecmp(prog, "TDLS") == 0) | 
|  | 9041 | return cmd_sta_set_rfeature_tdls(intf, dut, conn, cmd); | 
|  | 9042 |  | 
|  | 9043 | if (strcasecmp(prog, "VHT") == 0) | 
|  | 9044 | return cmd_sta_set_rfeature_vht(intf, dut, conn, cmd); | 
|  | 9045 |  | 
| Amarnath Hullur Subramanyam | 42c25a0 | 2018-01-31 04:02:27 -0800 | [diff] [blame] | 9046 | if (strcasecmp(prog, "HE") == 0) | 
|  | 9047 | return cmd_sta_set_rfeature_he(intf, dut, conn, cmd); | 
|  | 9048 |  | 
| Ashwini Patil | 68d02cd | 2017-01-10 15:39:16 +0530 | [diff] [blame] | 9049 | if (strcasecmp(prog, "MBO") == 0) { | 
|  | 9050 | val = get_param(cmd, "Cellular_Data_Cap"); | 
|  | 9051 | if (val && | 
|  | 9052 | mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0) | 
|  | 9053 | return 0; | 
| Ashwini Patil | 0040258 | 2017-04-13 12:29:39 +0530 | [diff] [blame] | 9054 |  | 
|  | 9055 | val = get_param(cmd, "Ch_Pref"); | 
|  | 9056 | if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0) | 
|  | 9057 | return 0; | 
|  | 9058 |  | 
| Ashwini Patil | 68d02cd | 2017-01-10 15:39:16 +0530 | [diff] [blame] | 9059 | return 1; | 
|  | 9060 | } | 
|  | 9061 |  | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 9062 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported Prog"); | 
|  | 9063 | return 0; | 
|  | 9064 | } | 
|  | 9065 |  | 
|  | 9066 |  | 
|  | 9067 | static int cmd_sta_set_radio(struct sigma_dut *dut, struct sigma_conn *conn, | 
|  | 9068 | struct sigma_cmd *cmd) | 
|  | 9069 | { | 
|  | 9070 | const char *intf = get_param(cmd, "Interface"); | 
|  | 9071 | const char *mode = get_param(cmd, "Mode"); | 
|  | 9072 | int res; | 
|  | 9073 |  | 
|  | 9074 | if (intf == NULL || mode == NULL) | 
|  | 9075 | return -1; | 
|  | 9076 |  | 
|  | 9077 | if (strcasecmp(mode, "On") == 0) | 
|  | 9078 | res = wpa_command(intf, "SET radio_disabled 0"); | 
|  | 9079 | else if (strcasecmp(mode, "Off") == 0) | 
|  | 9080 | res = wpa_command(intf, "SET radio_disabled 1"); | 
|  | 9081 | else | 
|  | 9082 | return -1; | 
|  | 9083 |  | 
|  | 9084 | if (res) { | 
|  | 9085 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change " | 
|  | 9086 | "radio mode"); | 
|  | 9087 | return 0; | 
|  | 9088 | } | 
|  | 9089 |  | 
|  | 9090 | return 1; | 
|  | 9091 | } | 
|  | 9092 |  | 
|  | 9093 |  | 
|  | 9094 | static int cmd_sta_set_pwrsave(struct sigma_dut *dut, struct sigma_conn *conn, | 
|  | 9095 | struct sigma_cmd *cmd) | 
|  | 9096 | { | 
|  | 9097 | const char *intf = get_param(cmd, "Interface"); | 
|  | 9098 | const char *mode = get_param(cmd, "Mode"); | 
|  | 9099 | int res; | 
|  | 9100 |  | 
|  | 9101 | if (intf == NULL || mode == NULL) | 
|  | 9102 | return -1; | 
|  | 9103 |  | 
|  | 9104 | if (strcasecmp(mode, "On") == 0) | 
|  | 9105 | res = set_ps(intf, dut, 1); | 
|  | 9106 | else if (strcasecmp(mode, "Off") == 0) | 
|  | 9107 | res = set_ps(intf, dut, 0); | 
|  | 9108 | else | 
|  | 9109 | return -1; | 
|  | 9110 |  | 
|  | 9111 | if (res) { | 
|  | 9112 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change " | 
|  | 9113 | "power save mode"); | 
|  | 9114 | return 0; | 
|  | 9115 | } | 
|  | 9116 |  | 
|  | 9117 | return 1; | 
|  | 9118 | } | 
|  | 9119 |  | 
|  | 9120 |  | 
|  | 9121 | static int cmd_sta_bssid_pool(struct sigma_dut *dut, struct sigma_conn *conn, | 
|  | 9122 | struct sigma_cmd *cmd) | 
|  | 9123 | { | 
|  | 9124 | const char *intf = get_param(cmd, "Interface"); | 
|  | 9125 | const char *val, *bssid; | 
|  | 9126 | int res; | 
|  | 9127 | char *buf; | 
|  | 9128 | size_t buf_len; | 
|  | 9129 |  | 
|  | 9130 | val = get_param(cmd, "BSSID_FILTER"); | 
|  | 9131 | if (val == NULL) | 
|  | 9132 | return -1; | 
|  | 9133 |  | 
|  | 9134 | bssid = get_param(cmd, "BSSID_List"); | 
|  | 9135 | if (atoi(val) == 0 || bssid == NULL) { | 
|  | 9136 | /* Disable BSSID filter */ | 
|  | 9137 | if (wpa_command(intf, "SET bssid_filter ")) { | 
|  | 9138 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed " | 
|  | 9139 | "to disable BSSID filter"); | 
|  | 9140 | return 0; | 
|  | 9141 | } | 
|  | 9142 |  | 
|  | 9143 | return 1; | 
|  | 9144 | } | 
|  | 9145 |  | 
|  | 9146 | buf_len = 100 + strlen(bssid); | 
|  | 9147 | buf = malloc(buf_len); | 
|  | 9148 | if (buf == NULL) | 
|  | 9149 | return -1; | 
|  | 9150 |  | 
|  | 9151 | snprintf(buf, buf_len, "SET bssid_filter %s", bssid); | 
|  | 9152 | res = wpa_command(intf, buf); | 
|  | 9153 | free(buf); | 
|  | 9154 | if (res) { | 
|  | 9155 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to enable " | 
|  | 9156 | "BSSID filter"); | 
|  | 9157 | return 0; | 
|  | 9158 | } | 
|  | 9159 |  | 
|  | 9160 | return 1; | 
|  | 9161 | } | 
|  | 9162 |  | 
|  | 9163 |  | 
|  | 9164 | static int cmd_sta_reset_parm(struct sigma_dut *dut, struct sigma_conn *conn, | 
|  | 9165 | struct sigma_cmd *cmd) | 
|  | 9166 | { | 
|  | 9167 | const char *intf = get_param(cmd, "Interface"); | 
|  | 9168 | const char *val; | 
|  | 9169 |  | 
|  | 9170 | /* TODO: ARP */ | 
|  | 9171 |  | 
|  | 9172 | val = get_param(cmd, "HS2_CACHE_PROFILE"); | 
|  | 9173 | if (val && strcasecmp(val, "All") == 0) | 
|  | 9174 | hs2_clear_credentials(intf); | 
|  | 9175 |  | 
|  | 9176 | return 1; | 
|  | 9177 | } | 
|  | 9178 |  | 
|  | 9179 |  | 
|  | 9180 | static int cmd_sta_get_key(struct sigma_dut *dut, struct sigma_conn *conn, | 
|  | 9181 | struct sigma_cmd *cmd) | 
|  | 9182 | { | 
|  | 9183 | const char *intf = get_param(cmd, "Interface"); | 
|  | 9184 | const char *key_type = get_param(cmd, "KeyType"); | 
|  | 9185 | char buf[100], resp[200]; | 
|  | 9186 |  | 
|  | 9187 | if (key_type == NULL) | 
|  | 9188 | return -1; | 
|  | 9189 |  | 
|  | 9190 | if (strcasecmp(key_type, "GTK") == 0) { | 
|  | 9191 | if (wpa_command_resp(intf, "GET gtk", buf, sizeof(buf)) < 0 || | 
|  | 9192 | strncmp(buf, "FAIL", 4) == 0) { | 
|  | 9193 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could " | 
|  | 9194 | "not fetch current GTK"); | 
|  | 9195 | return 0; | 
|  | 9196 | } | 
|  | 9197 | snprintf(resp, sizeof(resp), "KeyValue,%s", buf); | 
|  | 9198 | send_resp(dut, conn, SIGMA_COMPLETE, resp); | 
|  | 9199 | return 0; | 
|  | 9200 | } else { | 
|  | 9201 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported " | 
|  | 9202 | "KeyType"); | 
|  | 9203 | return 0; | 
|  | 9204 | } | 
|  | 9205 |  | 
|  | 9206 | return 1; | 
|  | 9207 | } | 
|  | 9208 |  | 
|  | 9209 |  | 
|  | 9210 | static int hs2_set_policy(struct sigma_dut *dut) | 
|  | 9211 | { | 
|  | 9212 | #ifdef ANDROID | 
|  | 9213 | system("ip rule del prio 23000"); | 
|  | 9214 | if (system("ip rule add from all lookup main prio 23000") != 0) { | 
|  | 9215 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 9216 | "Failed to run:ip rule add from all lookup main prio"); | 
|  | 9217 | return -1; | 
|  | 9218 | } | 
|  | 9219 | if (system("ip route flush cache") != 0) { | 
|  | 9220 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 9221 | "Failed to run ip route flush cache"); | 
|  | 9222 | return -1; | 
|  | 9223 | } | 
|  | 9224 | return 1; | 
|  | 9225 | #else /* ANDROID */ | 
|  | 9226 | return 0; | 
|  | 9227 | #endif /* ANDROID */ | 
|  | 9228 | } | 
|  | 9229 |  | 
|  | 9230 |  | 
|  | 9231 | static int cmd_sta_hs2_associate(struct sigma_dut *dut, | 
|  | 9232 | struct sigma_conn *conn, | 
|  | 9233 | struct sigma_cmd *cmd) | 
|  | 9234 | { | 
|  | 9235 | const char *intf = get_param(cmd, "Interface"); | 
|  | 9236 | const char *val = get_param(cmd, "Ignore_blacklist"); | 
|  | 9237 | struct wpa_ctrl *ctrl; | 
|  | 9238 | int res; | 
|  | 9239 | char bssid[20], ssid[40], resp[100], buf[100], blacklisted[100]; | 
|  | 9240 | int tries = 0; | 
|  | 9241 | int ignore_blacklist = 0; | 
|  | 9242 | const char *events[] = { | 
|  | 9243 | "CTRL-EVENT-CONNECTED", | 
|  | 9244 | "INTERWORKING-BLACKLISTED", | 
|  | 9245 | "INTERWORKING-NO-MATCH", | 
|  | 9246 | NULL | 
|  | 9247 | }; | 
|  | 9248 |  | 
|  | 9249 | start_sta_mode(dut); | 
|  | 9250 |  | 
|  | 9251 | blacklisted[0] = '\0'; | 
|  | 9252 | if (val && atoi(val)) | 
|  | 9253 | ignore_blacklist = 1; | 
|  | 9254 |  | 
|  | 9255 | try_again: | 
|  | 9256 | ctrl = open_wpa_mon(intf); | 
|  | 9257 | if (ctrl == NULL) { | 
|  | 9258 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open " | 
|  | 9259 | "wpa_supplicant monitor connection"); | 
|  | 9260 | return -2; | 
|  | 9261 | } | 
|  | 9262 |  | 
|  | 9263 | tries++; | 
|  | 9264 | if (wpa_command(intf, "INTERWORKING_SELECT auto")) { | 
|  | 9265 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start " | 
|  | 9266 | "Interworking connection"); | 
|  | 9267 | wpa_ctrl_detach(ctrl); | 
|  | 9268 | wpa_ctrl_close(ctrl); | 
|  | 9269 | return 0; | 
|  | 9270 | } | 
|  | 9271 |  | 
|  | 9272 | buf[0] = '\0'; | 
|  | 9273 | while (1) { | 
|  | 9274 | char *pos; | 
|  | 9275 | res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf)); | 
|  | 9276 | pos = strstr(buf, "INTERWORKING-BLACKLISTED"); | 
|  | 9277 | if (!pos) | 
|  | 9278 | break; | 
|  | 9279 | pos += 25; | 
|  | 9280 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Found blacklisted AP: %s", | 
|  | 9281 | pos); | 
|  | 9282 | if (!blacklisted[0]) | 
|  | 9283 | memcpy(blacklisted, pos, strlen(pos) + 1); | 
|  | 9284 | } | 
|  | 9285 |  | 
|  | 9286 | if (ignore_blacklist && blacklisted[0]) { | 
|  | 9287 | char *end; | 
|  | 9288 | end = strchr(blacklisted, ' '); | 
|  | 9289 | if (end) | 
|  | 9290 | *end = '\0'; | 
|  | 9291 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Try to connect to a blacklisted network: %s", | 
|  | 9292 | blacklisted); | 
|  | 9293 | snprintf(buf, sizeof(buf), "INTERWORKING_CONNECT %s", | 
|  | 9294 | blacklisted); | 
|  | 9295 | if (wpa_command(intf, buf)) { | 
|  | 9296 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start Interworking connection to blacklisted network"); | 
|  | 9297 | wpa_ctrl_detach(ctrl); | 
|  | 9298 | wpa_ctrl_close(ctrl); | 
|  | 9299 | return 0; | 
|  | 9300 | } | 
|  | 9301 | res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED", | 
|  | 9302 | buf, sizeof(buf)); | 
|  | 9303 | } | 
|  | 9304 |  | 
|  | 9305 | wpa_ctrl_detach(ctrl); | 
|  | 9306 | wpa_ctrl_close(ctrl); | 
|  | 9307 |  | 
|  | 9308 | if (res < 0) { | 
|  | 9309 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not " | 
|  | 9310 | "connect"); | 
|  | 9311 | return 0; | 
|  | 9312 | } | 
|  | 9313 |  | 
|  | 9314 | if (strstr(buf, "INTERWORKING-NO-MATCH") || | 
|  | 9315 | strstr(buf, "INTERWORKING-BLACKLISTED")) { | 
|  | 9316 | if (tries < 2) { | 
|  | 9317 | sigma_dut_print(dut, DUT_MSG_INFO, "No match found - try again to verify no APs were missed in the scan"); | 
|  | 9318 | goto try_again; | 
|  | 9319 | } | 
|  | 9320 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,No network with " | 
|  | 9321 | "matching credentials found"); | 
|  | 9322 | return 0; | 
|  | 9323 | } | 
|  | 9324 |  | 
|  | 9325 | if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 || | 
|  | 9326 | get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) { | 
|  | 9327 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not " | 
|  | 9328 | "get current BSSID/SSID"); | 
|  | 9329 | return 0; | 
|  | 9330 | } | 
|  | 9331 |  | 
|  | 9332 | snprintf(resp, sizeof(resp), "SSID,%s,BSSID,%s", ssid, bssid); | 
|  | 9333 | send_resp(dut, conn, SIGMA_COMPLETE, resp); | 
|  | 9334 | hs2_set_policy(dut); | 
|  | 9335 | return 0; | 
|  | 9336 | } | 
|  | 9337 |  | 
|  | 9338 |  | 
|  | 9339 | static int sta_add_credential_uname_pwd(struct sigma_dut *dut, | 
|  | 9340 | struct sigma_conn *conn, | 
|  | 9341 | const char *ifname, | 
|  | 9342 | struct sigma_cmd *cmd) | 
|  | 9343 | { | 
|  | 9344 | const char *val; | 
|  | 9345 | int id; | 
|  | 9346 |  | 
|  | 9347 | id = add_cred(ifname); | 
|  | 9348 | if (id < 0) | 
|  | 9349 | return -2; | 
|  | 9350 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id); | 
|  | 9351 |  | 
|  | 9352 | val = get_param(cmd, "prefer"); | 
|  | 9353 | if (val && atoi(val) > 0) | 
|  | 9354 | set_cred(ifname, id, "priority", "1"); | 
|  | 9355 |  | 
|  | 9356 | val = get_param(cmd, "REALM"); | 
|  | 9357 | if (val && set_cred_quoted(ifname, id, "realm", val) < 0) { | 
|  | 9358 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set " | 
|  | 9359 | "realm"); | 
|  | 9360 | return 0; | 
|  | 9361 | } | 
|  | 9362 |  | 
|  | 9363 | val = get_param(cmd, "HOME_FQDN"); | 
|  | 9364 | if (val && set_cred_quoted(ifname, id, "domain", val) < 0) { | 
|  | 9365 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set " | 
|  | 9366 | "home_fqdn"); | 
|  | 9367 | return 0; | 
|  | 9368 | } | 
|  | 9369 |  | 
|  | 9370 | val = get_param(cmd, "Username"); | 
|  | 9371 | if (val && set_cred_quoted(ifname, id, "username", val) < 0) { | 
|  | 9372 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set " | 
|  | 9373 | "username"); | 
|  | 9374 | return 0; | 
|  | 9375 | } | 
|  | 9376 |  | 
|  | 9377 | val = get_param(cmd, "Password"); | 
|  | 9378 | if (val && set_cred_quoted(ifname, id, "password", val) < 0) { | 
|  | 9379 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set " | 
|  | 9380 | "password"); | 
|  | 9381 | return 0; | 
|  | 9382 | } | 
|  | 9383 |  | 
|  | 9384 | val = get_param(cmd, "ROOT_CA"); | 
|  | 9385 | if (val) { | 
|  | 9386 | char fname[200]; | 
|  | 9387 | snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val); | 
|  | 9388 | #ifdef __linux__ | 
|  | 9389 | if (!file_exists(fname)) { | 
|  | 9390 | char msg[300]; | 
|  | 9391 | snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA " | 
|  | 9392 | "file (%s) not found", fname); | 
|  | 9393 | send_resp(dut, conn, SIGMA_ERROR, msg); | 
|  | 9394 | return 0; | 
|  | 9395 | } | 
|  | 9396 | #endif /* __linux__ */ | 
|  | 9397 | if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) { | 
|  | 9398 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could " | 
|  | 9399 | "not set root CA"); | 
|  | 9400 | return 0; | 
|  | 9401 | } | 
|  | 9402 | } | 
|  | 9403 |  | 
|  | 9404 | return 1; | 
|  | 9405 | } | 
|  | 9406 |  | 
|  | 9407 |  | 
|  | 9408 | static int update_devdetail_imsi(struct sigma_dut *dut, const char *imsi) | 
|  | 9409 | { | 
|  | 9410 | FILE *in, *out; | 
|  | 9411 | char buf[500]; | 
|  | 9412 | int found = 0; | 
|  | 9413 |  | 
|  | 9414 | in = fopen("devdetail.xml", "r"); | 
|  | 9415 | if (in == NULL) | 
|  | 9416 | return -1; | 
|  | 9417 | out = fopen("devdetail.xml.tmp", "w"); | 
|  | 9418 | if (out == NULL) { | 
|  | 9419 | fclose(in); | 
|  | 9420 | return -1; | 
|  | 9421 | } | 
|  | 9422 |  | 
|  | 9423 | while (fgets(buf, sizeof(buf), in)) { | 
|  | 9424 | char *pos = strstr(buf, "<IMSI>"); | 
|  | 9425 | if (pos) { | 
|  | 9426 | sigma_dut_print(dut, DUT_MSG_INFO, "Updated DevDetail IMSI to %s", | 
|  | 9427 | imsi); | 
|  | 9428 | pos += 6; | 
|  | 9429 | *pos = '\0'; | 
|  | 9430 | fprintf(out, "%s%s</IMSI>\n", buf, imsi); | 
|  | 9431 | found++; | 
|  | 9432 | } else { | 
|  | 9433 | fprintf(out, "%s", buf); | 
|  | 9434 | } | 
|  | 9435 | } | 
|  | 9436 |  | 
|  | 9437 | fclose(out); | 
|  | 9438 | fclose(in); | 
|  | 9439 | if (found) | 
|  | 9440 | rename("devdetail.xml.tmp", "devdetail.xml"); | 
|  | 9441 | else | 
|  | 9442 | unlink("devdetail.xml.tmp"); | 
|  | 9443 |  | 
|  | 9444 | return 0; | 
|  | 9445 | } | 
|  | 9446 |  | 
|  | 9447 |  | 
|  | 9448 | static int sta_add_credential_sim(struct sigma_dut *dut, | 
|  | 9449 | struct sigma_conn *conn, | 
|  | 9450 | const char *ifname, struct sigma_cmd *cmd) | 
|  | 9451 | { | 
|  | 9452 | const char *val, *imsi = NULL; | 
|  | 9453 | int id; | 
|  | 9454 | char buf[200]; | 
|  | 9455 | int res; | 
|  | 9456 | const char *pos; | 
|  | 9457 | size_t mnc_len; | 
|  | 9458 | char plmn_mcc[4]; | 
|  | 9459 | char plmn_mnc[4]; | 
|  | 9460 |  | 
|  | 9461 | id = add_cred(ifname); | 
|  | 9462 | if (id < 0) | 
|  | 9463 | return -2; | 
|  | 9464 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id); | 
|  | 9465 |  | 
|  | 9466 | val = get_param(cmd, "prefer"); | 
|  | 9467 | if (val && atoi(val) > 0) | 
|  | 9468 | set_cred(ifname, id, "priority", "1"); | 
|  | 9469 |  | 
|  | 9470 | val = get_param(cmd, "PLMN_MCC"); | 
|  | 9471 | if (val == NULL) { | 
|  | 9472 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 9473 | "errorCode,Missing PLMN_MCC"); | 
|  | 9474 | return 0; | 
|  | 9475 | } | 
|  | 9476 | if (strlen(val) != 3) { | 
|  | 9477 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MCC"); | 
|  | 9478 | return 0; | 
|  | 9479 | } | 
|  | 9480 | snprintf(plmn_mcc, sizeof(plmn_mcc), "%s", val); | 
|  | 9481 |  | 
|  | 9482 | val = get_param(cmd, "PLMN_MNC"); | 
|  | 9483 | if (val == NULL) { | 
|  | 9484 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 9485 | "errorCode,Missing PLMN_MNC"); | 
|  | 9486 | return 0; | 
|  | 9487 | } | 
|  | 9488 | if (strlen(val) != 2 && strlen(val) != 3) { | 
|  | 9489 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MNC"); | 
|  | 9490 | return 0; | 
|  | 9491 | } | 
|  | 9492 | snprintf(plmn_mnc, sizeof(plmn_mnc), "%s", val); | 
|  | 9493 |  | 
|  | 9494 | val = get_param(cmd, "IMSI"); | 
|  | 9495 | if (val == NULL) { | 
|  | 9496 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing SIM " | 
|  | 9497 | "IMSI"); | 
|  | 9498 | return 0; | 
|  | 9499 | } | 
|  | 9500 |  | 
|  | 9501 | imsi = pos = val; | 
|  | 9502 |  | 
|  | 9503 | if (strncmp(plmn_mcc, pos, 3) != 0) { | 
|  | 9504 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,MCC mismatch"); | 
|  | 9505 | return 0; | 
|  | 9506 | } | 
|  | 9507 | pos += 3; | 
|  | 9508 |  | 
|  | 9509 | mnc_len = strlen(plmn_mnc); | 
|  | 9510 | if (mnc_len < 2) { | 
|  | 9511 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC not set"); | 
|  | 9512 | return 0; | 
|  | 9513 | } | 
|  | 9514 |  | 
|  | 9515 | if (strncmp(plmn_mnc, pos, mnc_len) != 0) { | 
|  | 9516 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC mismatch"); | 
|  | 9517 | return 0; | 
|  | 9518 | } | 
|  | 9519 | pos += mnc_len; | 
|  | 9520 |  | 
|  | 9521 | res = snprintf(buf, sizeof(buf), "%s%s-%s",plmn_mcc, plmn_mnc, pos); | 
|  | 9522 | if (res < 0 || res >= (int) sizeof(buf)) | 
|  | 9523 | return -1; | 
|  | 9524 | if (set_cred_quoted(ifname, id, "imsi", buf) < 0) { | 
|  | 9525 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could " | 
|  | 9526 | "not set IMSI"); | 
|  | 9527 | return 0; | 
|  | 9528 | } | 
|  | 9529 |  | 
|  | 9530 | val = get_param(cmd, "Password"); | 
|  | 9531 | if (val && set_cred_quoted(ifname, id, "milenage", val) < 0) { | 
|  | 9532 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could " | 
|  | 9533 | "not set password"); | 
|  | 9534 | return 0; | 
|  | 9535 | } | 
|  | 9536 |  | 
|  | 9537 | if (dut->program == PROGRAM_HS2_R2) { | 
|  | 9538 | /* | 
|  | 9539 | * Set provisioning_sp for the test cases where SIM/USIM | 
|  | 9540 | * provisioning is used. | 
|  | 9541 | */ | 
|  | 9542 | if (val && set_cred_quoted(ifname, id, "provisioning_sp", | 
|  | 9543 | "wi-fi.org") < 0) { | 
|  | 9544 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could " | 
|  | 9545 | "not set provisioning_sp"); | 
|  | 9546 | return 0; | 
|  | 9547 | } | 
|  | 9548 |  | 
|  | 9549 | update_devdetail_imsi(dut, imsi); | 
|  | 9550 | } | 
|  | 9551 |  | 
|  | 9552 | return 1; | 
|  | 9553 | } | 
|  | 9554 |  | 
|  | 9555 |  | 
|  | 9556 | static int sta_add_credential_cert(struct sigma_dut *dut, | 
|  | 9557 | struct sigma_conn *conn, | 
|  | 9558 | const char *ifname, | 
|  | 9559 | struct sigma_cmd *cmd) | 
|  | 9560 | { | 
|  | 9561 | const char *val; | 
|  | 9562 | int id; | 
|  | 9563 |  | 
|  | 9564 | id = add_cred(ifname); | 
|  | 9565 | if (id < 0) | 
|  | 9566 | return -2; | 
|  | 9567 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id); | 
|  | 9568 |  | 
|  | 9569 | val = get_param(cmd, "prefer"); | 
|  | 9570 | if (val && atoi(val) > 0) | 
|  | 9571 | set_cred(ifname, id, "priority", "1"); | 
|  | 9572 |  | 
|  | 9573 | val = get_param(cmd, "REALM"); | 
|  | 9574 | if (val && set_cred_quoted(ifname, id, "realm", val) < 0) { | 
|  | 9575 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set " | 
|  | 9576 | "realm"); | 
|  | 9577 | return 0; | 
|  | 9578 | } | 
|  | 9579 |  | 
|  | 9580 | val = get_param(cmd, "HOME_FQDN"); | 
|  | 9581 | if (val && set_cred_quoted(ifname, id, "domain", val) < 0) { | 
|  | 9582 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set " | 
|  | 9583 | "home_fqdn"); | 
|  | 9584 | return 0; | 
|  | 9585 | } | 
|  | 9586 |  | 
|  | 9587 | val = get_param(cmd, "Username"); | 
|  | 9588 | if (val && set_cred_quoted(ifname, id, "username", val) < 0) { | 
|  | 9589 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set " | 
|  | 9590 | "username"); | 
|  | 9591 | return 0; | 
|  | 9592 | } | 
|  | 9593 |  | 
|  | 9594 | val = get_param(cmd, "clientCertificate"); | 
|  | 9595 | if (val) { | 
|  | 9596 | char fname[200]; | 
|  | 9597 | snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val); | 
|  | 9598 | #ifdef __linux__ | 
|  | 9599 | if (!file_exists(fname)) { | 
|  | 9600 | char msg[300]; | 
|  | 9601 | snprintf(msg, sizeof(msg), | 
|  | 9602 | "ErrorCode,clientCertificate " | 
|  | 9603 | "file (%s) not found", fname); | 
|  | 9604 | send_resp(dut, conn, SIGMA_ERROR, msg); | 
|  | 9605 | return 0; | 
|  | 9606 | } | 
|  | 9607 | #endif /* __linux__ */ | 
|  | 9608 | if (set_cred_quoted(ifname, id, "client_cert", fname) < 0) { | 
|  | 9609 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could " | 
|  | 9610 | "not set client_cert"); | 
|  | 9611 | return 0; | 
|  | 9612 | } | 
|  | 9613 | if (set_cred_quoted(ifname, id, "private_key", fname) < 0) { | 
|  | 9614 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could " | 
|  | 9615 | "not set private_key"); | 
|  | 9616 | return 0; | 
|  | 9617 | } | 
|  | 9618 | } | 
|  | 9619 |  | 
|  | 9620 | val = get_param(cmd, "ROOT_CA"); | 
|  | 9621 | if (val) { | 
|  | 9622 | char fname[200]; | 
|  | 9623 | snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val); | 
|  | 9624 | #ifdef __linux__ | 
|  | 9625 | if (!file_exists(fname)) { | 
|  | 9626 | char msg[300]; | 
|  | 9627 | snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA " | 
|  | 9628 | "file (%s) not found", fname); | 
|  | 9629 | send_resp(dut, conn, SIGMA_ERROR, msg); | 
|  | 9630 | return 0; | 
|  | 9631 | } | 
|  | 9632 | #endif /* __linux__ */ | 
|  | 9633 | if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) { | 
|  | 9634 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could " | 
|  | 9635 | "not set root CA"); | 
|  | 9636 | return 0; | 
|  | 9637 | } | 
|  | 9638 | } | 
|  | 9639 |  | 
|  | 9640 | return 1; | 
|  | 9641 | } | 
|  | 9642 |  | 
|  | 9643 |  | 
|  | 9644 | static int cmd_sta_add_credential(struct sigma_dut *dut, | 
|  | 9645 | struct sigma_conn *conn, | 
|  | 9646 | struct sigma_cmd *cmd) | 
|  | 9647 | { | 
|  | 9648 | const char *intf = get_param(cmd, "Interface"); | 
|  | 9649 | const char *type; | 
|  | 9650 |  | 
|  | 9651 | start_sta_mode(dut); | 
|  | 9652 |  | 
|  | 9653 | type = get_param(cmd, "Type"); | 
|  | 9654 | if (!type) | 
|  | 9655 | return -1; | 
|  | 9656 |  | 
|  | 9657 | if (strcasecmp(type, "uname_pwd") == 0) | 
|  | 9658 | return sta_add_credential_uname_pwd(dut, conn, intf, cmd); | 
|  | 9659 |  | 
|  | 9660 | if (strcasecmp(type, "sim") == 0) | 
|  | 9661 | return sta_add_credential_sim(dut, conn, intf, cmd); | 
|  | 9662 |  | 
|  | 9663 | if (strcasecmp(type, "cert") == 0) | 
|  | 9664 | return sta_add_credential_cert(dut, conn, intf, cmd); | 
|  | 9665 |  | 
|  | 9666 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported credential " | 
|  | 9667 | "type"); | 
|  | 9668 | return 0; | 
|  | 9669 | } | 
|  | 9670 |  | 
|  | 9671 |  | 
|  | 9672 | static int cmd_sta_scan(struct sigma_dut *dut, struct sigma_conn *conn, | 
|  | 9673 | struct sigma_cmd *cmd) | 
|  | 9674 | { | 
|  | 9675 | const char *intf = get_param(cmd, "Interface"); | 
| vamsi krishna | 89ad8c6 | 2017-09-19 12:51:18 +0530 | [diff] [blame] | 9676 | const char *val, *bssid, *ssid; | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 9677 | char buf[100]; | 
| vamsi krishna | 89ad8c6 | 2017-09-19 12:51:18 +0530 | [diff] [blame] | 9678 | char ssid_hex[65]; | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 9679 | int res; | 
|  | 9680 |  | 
|  | 9681 | val = get_param(cmd, "HESSID"); | 
|  | 9682 | if (val) { | 
|  | 9683 | res = snprintf(buf, sizeof(buf), "SET hessid %s", val); | 
|  | 9684 | if (res < 0 || res >= (int) sizeof(buf)) | 
|  | 9685 | return -1; | 
|  | 9686 | wpa_command(intf, buf); | 
|  | 9687 | } | 
|  | 9688 |  | 
|  | 9689 | val = get_param(cmd, "ACCS_NET_TYPE"); | 
|  | 9690 | if (val) { | 
|  | 9691 | res = snprintf(buf, sizeof(buf), "SET access_network_type %s", | 
|  | 9692 | val); | 
|  | 9693 | if (res < 0 || res >= (int) sizeof(buf)) | 
|  | 9694 | return -1; | 
|  | 9695 | wpa_command(intf, buf); | 
|  | 9696 | } | 
|  | 9697 |  | 
| vamsi krishna | 89ad8c6 | 2017-09-19 12:51:18 +0530 | [diff] [blame] | 9698 | bssid = get_param(cmd, "Bssid"); | 
|  | 9699 | ssid = get_param(cmd, "Ssid"); | 
|  | 9700 |  | 
|  | 9701 | if (ssid) { | 
|  | 9702 | if (2 * strlen(ssid) >= sizeof(ssid_hex)) { | 
|  | 9703 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 9704 | "ErrorCode,Too long SSID"); | 
|  | 9705 | return 0; | 
|  | 9706 | } | 
|  | 9707 | ascii2hexstr(ssid, ssid_hex); | 
|  | 9708 | } | 
|  | 9709 |  | 
|  | 9710 | res = snprintf(buf, sizeof(buf), "SCAN%s%s%s%s", | 
|  | 9711 | bssid ? " bssid=": "", | 
|  | 9712 | bssid ? bssid : "", | 
|  | 9713 | ssid ? " ssid " : "", | 
|  | 9714 | ssid ? ssid_hex : ""); | 
|  | 9715 | if (res < 0 || res >= (int) sizeof(buf)) | 
|  | 9716 | return -1; | 
|  | 9717 |  | 
|  | 9718 | if (wpa_command(intf, buf)) { | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 9719 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not start " | 
|  | 9720 | "scan"); | 
|  | 9721 | return 0; | 
|  | 9722 | } | 
|  | 9723 |  | 
|  | 9724 | return 1; | 
|  | 9725 | } | 
|  | 9726 |  | 
|  | 9727 |  | 
| Jouni Malinen | 5e5d43d | 2018-01-10 17:29:33 +0200 | [diff] [blame] | 9728 | static int cmd_sta_scan_bss(struct sigma_dut *dut, struct sigma_conn *conn, | 
|  | 9729 | struct sigma_cmd *cmd) | 
|  | 9730 | { | 
|  | 9731 | const char *intf = get_param(cmd, "Interface"); | 
|  | 9732 | const char *bssid; | 
|  | 9733 | char buf[4096], *pos; | 
|  | 9734 | int freq, chan; | 
|  | 9735 | char *ssid; | 
|  | 9736 | char resp[100]; | 
|  | 9737 | int res; | 
|  | 9738 | struct wpa_ctrl *ctrl; | 
|  | 9739 |  | 
|  | 9740 | bssid = get_param(cmd, "BSSID"); | 
|  | 9741 | if (!bssid) { | 
|  | 9742 | send_resp(dut, conn, SIGMA_INVALID, | 
|  | 9743 | "errorCode,BSSID argument is missing"); | 
|  | 9744 | return 0; | 
|  | 9745 | } | 
|  | 9746 |  | 
|  | 9747 | ctrl = open_wpa_mon(intf); | 
|  | 9748 | if (!ctrl) { | 
|  | 9749 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 9750 | "Failed to open wpa_supplicant monitor connection"); | 
|  | 9751 | return -1; | 
|  | 9752 | } | 
|  | 9753 |  | 
|  | 9754 | if (wpa_command(intf, "SCAN TYPE=ONLY")) { | 
|  | 9755 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 9756 | "errorCode,Could not start scan"); | 
|  | 9757 | wpa_ctrl_detach(ctrl); | 
|  | 9758 | wpa_ctrl_close(ctrl); | 
|  | 9759 | return 0; | 
|  | 9760 | } | 
|  | 9761 |  | 
|  | 9762 | res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS", | 
|  | 9763 | buf, sizeof(buf)); | 
|  | 9764 |  | 
|  | 9765 | wpa_ctrl_detach(ctrl); | 
|  | 9766 | wpa_ctrl_close(ctrl); | 
|  | 9767 |  | 
|  | 9768 | if (res < 0) { | 
|  | 9769 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 9770 | "errorCode,Scan did not complete"); | 
|  | 9771 | return 0; | 
|  | 9772 | } | 
|  | 9773 |  | 
|  | 9774 | snprintf(buf, sizeof(buf), "BSS %s", bssid); | 
|  | 9775 | if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 || | 
|  | 9776 | strncmp(buf, "id=", 3) != 0) { | 
|  | 9777 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 9778 | "errorCode,Specified BSSID not found"); | 
|  | 9779 | return 0; | 
|  | 9780 | } | 
|  | 9781 |  | 
|  | 9782 | pos = strstr(buf, "\nfreq="); | 
|  | 9783 | if (!pos) { | 
|  | 9784 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 9785 | "errorCode,Channel not found"); | 
|  | 9786 | return 0; | 
|  | 9787 | } | 
|  | 9788 | freq = atoi(pos + 6); | 
|  | 9789 | chan = freq_to_channel(freq); | 
|  | 9790 |  | 
|  | 9791 | pos = strstr(buf, "\nssid="); | 
|  | 9792 | if (!pos) { | 
|  | 9793 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 9794 | "errorCode,SSID not found"); | 
|  | 9795 | return 0; | 
|  | 9796 | } | 
|  | 9797 | ssid = pos + 6; | 
|  | 9798 | pos = strchr(ssid, '\n'); | 
|  | 9799 | if (pos) | 
|  | 9800 | *pos = '\0'; | 
|  | 9801 | snprintf(resp, sizeof(resp), "ssid,%s,bsschannel,%d", ssid, chan); | 
|  | 9802 | send_resp(dut, conn, SIGMA_COMPLETE, resp); | 
|  | 9803 | return 0; | 
|  | 9804 | } | 
|  | 9805 |  | 
|  | 9806 |  | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 9807 | static int cmd_sta_set_systime(struct sigma_dut *dut, struct sigma_conn *conn, | 
|  | 9808 | struct sigma_cmd *cmd) | 
|  | 9809 | { | 
|  | 9810 | #ifdef __linux__ | 
|  | 9811 | struct timeval tv; | 
|  | 9812 | struct tm tm; | 
|  | 9813 | time_t t; | 
|  | 9814 | const char *val; | 
| Pradeep Reddy POTTETI | 429c69e | 2016-10-13 17:22:03 +0530 | [diff] [blame] | 9815 | int v; | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 9816 |  | 
|  | 9817 | wpa_command(get_station_ifname(), "PMKSA_FLUSH"); | 
|  | 9818 |  | 
|  | 9819 | memset(&tm, 0, sizeof(tm)); | 
|  | 9820 | val = get_param(cmd, "seconds"); | 
|  | 9821 | if (val) | 
|  | 9822 | tm.tm_sec = atoi(val); | 
|  | 9823 | val = get_param(cmd, "minutes"); | 
|  | 9824 | if (val) | 
|  | 9825 | tm.tm_min = atoi(val); | 
|  | 9826 | val = get_param(cmd, "hours"); | 
|  | 9827 | if (val) | 
|  | 9828 | tm.tm_hour = atoi(val); | 
|  | 9829 | val = get_param(cmd, "date"); | 
|  | 9830 | if (val) | 
|  | 9831 | tm.tm_mday = atoi(val); | 
|  | 9832 | val = get_param(cmd, "month"); | 
| Pradeep Reddy POTTETI | 429c69e | 2016-10-13 17:22:03 +0530 | [diff] [blame] | 9833 | if (val) { | 
|  | 9834 | v = atoi(val); | 
|  | 9835 | if (v < 1 || v > 12) { | 
|  | 9836 | send_resp(dut, conn, SIGMA_INVALID, | 
|  | 9837 | "errorCode,Invalid month"); | 
|  | 9838 | return 0; | 
|  | 9839 | } | 
|  | 9840 | tm.tm_mon = v - 1; | 
|  | 9841 | } | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 9842 | val = get_param(cmd, "year"); | 
|  | 9843 | if (val) { | 
|  | 9844 | int year = atoi(val); | 
|  | 9845 | #ifdef ANDROID | 
|  | 9846 | if (year > 2035) | 
|  | 9847 | year = 2035; /* years beyond 2035 not supported */ | 
|  | 9848 | #endif /* ANDROID */ | 
|  | 9849 | tm.tm_year = year - 1900; | 
|  | 9850 | } | 
|  | 9851 | t = mktime(&tm); | 
|  | 9852 | if (t == (time_t) -1) { | 
|  | 9853 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 9854 | "errorCode,Invalid date or time"); | 
|  | 9855 | return 0; | 
|  | 9856 | } | 
|  | 9857 |  | 
|  | 9858 | memset(&tv, 0, sizeof(tv)); | 
|  | 9859 | tv.tv_sec = t; | 
|  | 9860 |  | 
|  | 9861 | if (settimeofday(&tv, NULL) < 0) { | 
|  | 9862 | sigma_dut_print(dut, DUT_MSG_INFO, "settimeofday failed: %s", | 
|  | 9863 | strerror(errno)); | 
|  | 9864 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 9865 | "errorCode,Failed to set time"); | 
|  | 9866 | return 0; | 
|  | 9867 | } | 
|  | 9868 |  | 
|  | 9869 | return 1; | 
|  | 9870 | #endif /* __linux__ */ | 
|  | 9871 |  | 
|  | 9872 | return -1; | 
|  | 9873 | } | 
|  | 9874 |  | 
|  | 9875 |  | 
|  | 9876 | static int cmd_sta_osu(struct sigma_dut *dut, struct sigma_conn *conn, | 
|  | 9877 | struct sigma_cmd *cmd) | 
|  | 9878 | { | 
|  | 9879 | const char *intf = get_param(cmd, "Interface"); | 
|  | 9880 | const char *name, *val; | 
|  | 9881 | int prod_ess_assoc = 1; | 
|  | 9882 | char buf[200], bssid[100], ssid[100]; | 
|  | 9883 | int res; | 
|  | 9884 | struct wpa_ctrl *ctrl; | 
|  | 9885 |  | 
|  | 9886 | name = get_param(cmd, "osuFriendlyName"); | 
|  | 9887 |  | 
|  | 9888 | val = get_param(cmd, "ProdESSAssoc"); | 
|  | 9889 | if (val) | 
|  | 9890 | prod_ess_assoc = atoi(val); | 
|  | 9891 |  | 
|  | 9892 | kill_dhcp_client(dut, intf); | 
|  | 9893 | if (start_dhcp_client(dut, intf) < 0) | 
|  | 9894 | return -2; | 
|  | 9895 |  | 
|  | 9896 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger OSU"); | 
|  | 9897 | mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); | 
|  | 9898 | res = snprintf(buf, sizeof(buf), | 
|  | 9899 | "%s %s%s%s signup osu-ca.pem", | 
|  | 9900 | prod_ess_assoc ? "" : "-N", | 
|  | 9901 | name ? "-O'" : "", name ? name : "", | 
|  | 9902 | name ? "'" : ""); | 
|  | 9903 |  | 
| Kanchanapally, Vidyullatha | 12b6676 | 2015-12-31 16:46:42 +0530 | [diff] [blame] | 9904 | hs2_set_policy(dut); | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 9905 | if (run_hs20_osu(dut, buf) < 0) { | 
|  | 9906 | FILE *f; | 
|  | 9907 |  | 
|  | 9908 | sigma_dut_print(dut, DUT_MSG_INFO, "Failed to complete OSU"); | 
|  | 9909 |  | 
|  | 9910 | f = fopen("hs20-osu-client.res", "r"); | 
|  | 9911 | if (f) { | 
|  | 9912 | char resp[400], res[300], *pos; | 
|  | 9913 | if (!fgets(res, sizeof(res), f)) | 
|  | 9914 | res[0] = '\0'; | 
|  | 9915 | pos = strchr(res, '\n'); | 
|  | 9916 | if (pos) | 
|  | 9917 | *pos = '\0'; | 
|  | 9918 | fclose(f); | 
|  | 9919 | sigma_dut_summary(dut, "hs20-osu-client provisioning failed: %s", | 
|  | 9920 | res); | 
|  | 9921 | snprintf(resp, sizeof(resp), "notify-send '%s'", res); | 
|  | 9922 | if (system(resp) != 0) { | 
|  | 9923 | } | 
|  | 9924 | snprintf(resp, sizeof(resp), | 
|  | 9925 | "SSID,,BSSID,,failureReason,%s", res); | 
|  | 9926 | send_resp(dut, conn, SIGMA_COMPLETE, resp); | 
|  | 9927 | return 0; | 
|  | 9928 | } | 
|  | 9929 |  | 
|  | 9930 | send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,"); | 
|  | 9931 | return 0; | 
|  | 9932 | } | 
|  | 9933 |  | 
|  | 9934 | if (!prod_ess_assoc) | 
|  | 9935 | goto report; | 
|  | 9936 |  | 
|  | 9937 | ctrl = open_wpa_mon(intf); | 
|  | 9938 | if (ctrl == NULL) { | 
|  | 9939 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open " | 
|  | 9940 | "wpa_supplicant monitor connection"); | 
|  | 9941 | return -1; | 
|  | 9942 | } | 
|  | 9943 |  | 
|  | 9944 | res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED", | 
|  | 9945 | buf, sizeof(buf)); | 
|  | 9946 |  | 
|  | 9947 | wpa_ctrl_detach(ctrl); | 
|  | 9948 | wpa_ctrl_close(ctrl); | 
|  | 9949 |  | 
|  | 9950 | if (res < 0) { | 
|  | 9951 | sigma_dut_print(dut, DUT_MSG_INFO, "Failed to connect to " | 
|  | 9952 | "network after OSU"); | 
|  | 9953 | send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,"); | 
|  | 9954 | return 0; | 
|  | 9955 | } | 
|  | 9956 |  | 
|  | 9957 | report: | 
|  | 9958 | if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 || | 
|  | 9959 | get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) { | 
|  | 9960 | sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get BSSID/SSID"); | 
|  | 9961 | send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,"); | 
|  | 9962 | return 0; | 
|  | 9963 | } | 
|  | 9964 |  | 
|  | 9965 | snprintf(buf, sizeof(buf), "SSID,%s,BSSID,%s", ssid, bssid); | 
|  | 9966 | send_resp(dut, conn, SIGMA_COMPLETE, buf); | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 9967 | return 0; | 
|  | 9968 | } | 
|  | 9969 |  | 
|  | 9970 |  | 
|  | 9971 | static int cmd_sta_policy_update(struct sigma_dut *dut, struct sigma_conn *conn, | 
|  | 9972 | struct sigma_cmd *cmd) | 
|  | 9973 | { | 
|  | 9974 | const char *val; | 
|  | 9975 | int timeout = 120; | 
|  | 9976 |  | 
|  | 9977 | val = get_param(cmd, "PolicyUpdate"); | 
|  | 9978 | if (val == NULL || atoi(val) == 0) | 
|  | 9979 | return 1; /* No operation requested */ | 
|  | 9980 |  | 
|  | 9981 | val = get_param(cmd, "Timeout"); | 
|  | 9982 | if (val) | 
|  | 9983 | timeout = atoi(val); | 
|  | 9984 |  | 
|  | 9985 | if (timeout) { | 
|  | 9986 | /* TODO: time out the command and return | 
|  | 9987 | * PolicyUpdateStatus,TIMEOUT if needed. */ | 
|  | 9988 | } | 
|  | 9989 |  | 
|  | 9990 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger policy update"); | 
|  | 9991 | mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); | 
|  | 9992 | if (run_hs20_osu(dut, "pol_upd fqdn=wi-fi.org") < 0) { | 
|  | 9993 | send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,FAIL"); | 
|  | 9994 | return 0; | 
|  | 9995 | } | 
|  | 9996 |  | 
|  | 9997 | send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,SUCCESS"); | 
|  | 9998 | return 0; | 
|  | 9999 | } | 
|  | 10000 |  | 
|  | 10001 |  | 
|  | 10002 | static int cmd_sta_er_config(struct sigma_dut *dut, struct sigma_conn *conn, | 
|  | 10003 | struct sigma_cmd *cmd) | 
|  | 10004 | { | 
|  | 10005 | struct wpa_ctrl *ctrl; | 
|  | 10006 | const char *intf = get_param(cmd, "Interface"); | 
|  | 10007 | const char *bssid = get_param(cmd, "Bssid"); | 
|  | 10008 | const char *ssid = get_param(cmd, "SSID"); | 
|  | 10009 | const char *security = get_param(cmd, "Security"); | 
|  | 10010 | const char *passphrase = get_param(cmd, "Passphrase"); | 
|  | 10011 | const char *pin = get_param(cmd, "PIN"); | 
|  | 10012 | char buf[1000]; | 
|  | 10013 | char ssid_hex[200], passphrase_hex[200]; | 
|  | 10014 | const char *keymgmt, *cipher; | 
|  | 10015 |  | 
|  | 10016 | if (intf == NULL) | 
|  | 10017 | intf = get_main_ifname(); | 
|  | 10018 |  | 
|  | 10019 | if (!bssid) { | 
|  | 10020 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 10021 | "ErrorCode,Missing Bssid argument"); | 
|  | 10022 | return 0; | 
|  | 10023 | } | 
|  | 10024 |  | 
|  | 10025 | if (!ssid) { | 
|  | 10026 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 10027 | "ErrorCode,Missing SSID argument"); | 
|  | 10028 | return 0; | 
|  | 10029 | } | 
|  | 10030 |  | 
|  | 10031 | if (!security) { | 
|  | 10032 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 10033 | "ErrorCode,Missing Security argument"); | 
|  | 10034 | return 0; | 
|  | 10035 | } | 
|  | 10036 |  | 
|  | 10037 | if (!passphrase) { | 
|  | 10038 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 10039 | "ErrorCode,Missing Passphrase argument"); | 
|  | 10040 | return 0; | 
|  | 10041 | } | 
|  | 10042 |  | 
|  | 10043 | if (!pin) { | 
|  | 10044 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 10045 | "ErrorCode,Missing PIN argument"); | 
|  | 10046 | return 0; | 
|  | 10047 | } | 
|  | 10048 |  | 
| vamsi krishna | 8c9c156 | 2017-05-12 15:51:46 +0530 | [diff] [blame] | 10049 | if (2 * strlen(ssid) >= sizeof(ssid_hex) || | 
|  | 10050 | 2 * strlen(passphrase) >= sizeof(passphrase_hex)) { | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 10051 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 10052 | "ErrorCode,Too long SSID/passphrase"); | 
|  | 10053 | return 0; | 
|  | 10054 | } | 
|  | 10055 |  | 
|  | 10056 | ctrl = open_wpa_mon(intf); | 
|  | 10057 | if (ctrl == NULL) { | 
|  | 10058 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open " | 
|  | 10059 | "wpa_supplicant monitor connection"); | 
|  | 10060 | return -2; | 
|  | 10061 | } | 
|  | 10062 |  | 
|  | 10063 | if (strcasecmp(security, "wpa2-psk") == 0) { | 
|  | 10064 | keymgmt = "WPA2PSK"; | 
|  | 10065 | cipher = "CCMP"; | 
|  | 10066 | } else { | 
|  | 10067 | wpa_ctrl_detach(ctrl); | 
|  | 10068 | wpa_ctrl_close(ctrl); | 
|  | 10069 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 10070 | "ErrorCode,Unsupported Security value"); | 
|  | 10071 | return 0; | 
|  | 10072 | } | 
|  | 10073 |  | 
|  | 10074 | ascii2hexstr(ssid, ssid_hex); | 
|  | 10075 | ascii2hexstr(passphrase, passphrase_hex); | 
|  | 10076 | snprintf(buf, sizeof(buf), "WPS_REG %s %s %s %s %s %s", | 
|  | 10077 | bssid, pin, ssid_hex, keymgmt, cipher, passphrase_hex); | 
|  | 10078 |  | 
|  | 10079 | if (wpa_command(intf, buf) < 0) { | 
|  | 10080 | wpa_ctrl_detach(ctrl); | 
|  | 10081 | wpa_ctrl_close(ctrl); | 
|  | 10082 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 10083 | "ErrorCode,Failed to start registrar"); | 
|  | 10084 | return 0; | 
|  | 10085 | } | 
|  | 10086 |  | 
|  | 10087 | snprintf(dut->er_oper_bssid, sizeof(dut->er_oper_bssid), "%s", bssid); | 
|  | 10088 | dut->er_oper_performed = 1; | 
|  | 10089 |  | 
|  | 10090 | return wps_connection_event(dut, conn, ctrl, intf, 0); | 
|  | 10091 | } | 
|  | 10092 |  | 
|  | 10093 |  | 
|  | 10094 | static int cmd_sta_wps_connect_pw_token(struct sigma_dut *dut, | 
|  | 10095 | struct sigma_conn *conn, | 
|  | 10096 | struct sigma_cmd *cmd) | 
|  | 10097 | { | 
|  | 10098 | struct wpa_ctrl *ctrl; | 
|  | 10099 | const char *intf = get_param(cmd, "Interface"); | 
|  | 10100 | const char *bssid = get_param(cmd, "Bssid"); | 
|  | 10101 | char buf[100]; | 
|  | 10102 |  | 
|  | 10103 | if (!bssid) { | 
|  | 10104 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 10105 | "ErrorCode,Missing Bssid argument"); | 
|  | 10106 | return 0; | 
|  | 10107 | } | 
|  | 10108 |  | 
|  | 10109 | ctrl = open_wpa_mon(intf); | 
|  | 10110 | if (ctrl == NULL) { | 
|  | 10111 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open " | 
|  | 10112 | "wpa_supplicant monitor connection"); | 
|  | 10113 | return -2; | 
|  | 10114 | } | 
|  | 10115 |  | 
|  | 10116 | snprintf(buf, sizeof(buf), "WPS_NFC %s", bssid); | 
|  | 10117 |  | 
|  | 10118 | if (wpa_command(intf, buf) < 0) { | 
|  | 10119 | wpa_ctrl_detach(ctrl); | 
|  | 10120 | wpa_ctrl_close(ctrl); | 
|  | 10121 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 10122 | "ErrorCode,Failed to start registrar"); | 
|  | 10123 | return 0; | 
|  | 10124 | } | 
|  | 10125 |  | 
|  | 10126 | return wps_connection_event(dut, conn, ctrl, intf, 0); | 
|  | 10127 | } | 
|  | 10128 |  | 
|  | 10129 |  | 
| vamsi krishna | 9b14400 | 2017-09-20 13:28:13 +0530 | [diff] [blame] | 10130 | static int cmd_start_wps_registration(struct sigma_dut *dut, | 
|  | 10131 | struct sigma_conn *conn, | 
|  | 10132 | struct sigma_cmd *cmd) | 
|  | 10133 | { | 
|  | 10134 | struct wpa_ctrl *ctrl; | 
|  | 10135 | const char *intf = get_param(cmd, "Interface"); | 
|  | 10136 | const char *role, *method; | 
|  | 10137 | int res; | 
|  | 10138 | char buf[256]; | 
|  | 10139 | const char *events[] = { | 
|  | 10140 | "CTRL-EVENT-CONNECTED", | 
|  | 10141 | "WPS-OVERLAP-DETECTED", | 
|  | 10142 | "WPS-TIMEOUT", | 
|  | 10143 | "WPS-FAIL", | 
|  | 10144 | NULL | 
|  | 10145 | }; | 
|  | 10146 |  | 
|  | 10147 | ctrl = open_wpa_mon(intf); | 
|  | 10148 | if (!ctrl) { | 
|  | 10149 | sigma_dut_print(dut, DUT_MSG_ERROR, | 
|  | 10150 | "Failed to open wpa_supplicant monitor connection"); | 
|  | 10151 | return -2; | 
|  | 10152 | } | 
|  | 10153 |  | 
|  | 10154 | role = get_param(cmd, "WpsRole"); | 
|  | 10155 | if (!role) { | 
|  | 10156 | send_resp(dut, conn, SIGMA_INVALID, | 
|  | 10157 | "ErrorCode,WpsRole not provided"); | 
|  | 10158 | goto fail; | 
|  | 10159 | } | 
|  | 10160 |  | 
|  | 10161 | if (strcasecmp(role, "Enrollee") == 0) { | 
|  | 10162 | method = get_param(cmd, "WpsConfigMethod"); | 
|  | 10163 | if (!method) { | 
|  | 10164 | send_resp(dut, conn, SIGMA_INVALID, | 
|  | 10165 | "ErrorCode,WpsConfigMethod not provided"); | 
|  | 10166 | goto fail; | 
|  | 10167 | } | 
|  | 10168 | if (strcasecmp(method, "PBC") == 0) { | 
|  | 10169 | if (wpa_command(intf, "WPS_PBC") < 0) { | 
|  | 10170 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 10171 | "ErrorCode,Failed to enable PBC"); | 
|  | 10172 | goto fail; | 
|  | 10173 | } | 
|  | 10174 | } else { | 
|  | 10175 | /* TODO: PIN method */ | 
|  | 10176 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 10177 | "ErrorCode,Unsupported WpsConfigMethod value"); | 
|  | 10178 | goto fail; | 
|  | 10179 | } | 
|  | 10180 | res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf)); | 
|  | 10181 | if (res < 0) { | 
|  | 10182 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 10183 | "ErrorCode,WPS connection did not complete"); | 
|  | 10184 | goto fail; | 
|  | 10185 | } | 
|  | 10186 | if (strstr(buf, "WPS-TIMEOUT")) { | 
|  | 10187 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,NoPeer"); | 
|  | 10188 | } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) { | 
|  | 10189 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 10190 | "ErrorCode,OverlapSession"); | 
|  | 10191 | } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) { | 
|  | 10192 | send_resp(dut, conn, SIGMA_COMPLETE, "Successful"); | 
|  | 10193 | } else { | 
|  | 10194 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 10195 | "ErrorCode,WPS operation failed"); | 
|  | 10196 | } | 
|  | 10197 | } else { | 
|  | 10198 | /* TODO: Registrar role */ | 
|  | 10199 | send_resp(dut, conn, SIGMA_ERROR, | 
|  | 10200 | "ErrorCode,Unsupported WpsRole value"); | 
|  | 10201 | } | 
|  | 10202 |  | 
|  | 10203 | fail: | 
|  | 10204 | wpa_ctrl_detach(ctrl); | 
|  | 10205 | wpa_ctrl_close(ctrl); | 
|  | 10206 | return 0; | 
|  | 10207 | } | 
|  | 10208 |  | 
|  | 10209 |  | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 10210 | static int req_intf(struct sigma_cmd *cmd) | 
|  | 10211 | { | 
|  | 10212 | return get_param(cmd, "interface") == NULL ? -1 : 0; | 
|  | 10213 | } | 
|  | 10214 |  | 
|  | 10215 |  | 
|  | 10216 | void sta_register_cmds(void) | 
|  | 10217 | { | 
|  | 10218 | sigma_dut_reg_cmd("sta_get_ip_config", req_intf, | 
|  | 10219 | cmd_sta_get_ip_config); | 
|  | 10220 | sigma_dut_reg_cmd("sta_set_ip_config", req_intf, | 
|  | 10221 | cmd_sta_set_ip_config); | 
|  | 10222 | sigma_dut_reg_cmd("sta_get_info", req_intf, cmd_sta_get_info); | 
|  | 10223 | sigma_dut_reg_cmd("sta_get_mac_address", req_intf, | 
|  | 10224 | cmd_sta_get_mac_address); | 
|  | 10225 | sigma_dut_reg_cmd("sta_is_connected", req_intf, cmd_sta_is_connected); | 
|  | 10226 | sigma_dut_reg_cmd("sta_verify_ip_connection", req_intf, | 
|  | 10227 | cmd_sta_verify_ip_connection); | 
|  | 10228 | sigma_dut_reg_cmd("sta_get_bssid", req_intf, cmd_sta_get_bssid); | 
|  | 10229 | sigma_dut_reg_cmd("sta_set_encryption", req_intf, | 
|  | 10230 | cmd_sta_set_encryption); | 
|  | 10231 | sigma_dut_reg_cmd("sta_set_psk", req_intf, cmd_sta_set_psk); | 
|  | 10232 | sigma_dut_reg_cmd("sta_set_eaptls", req_intf, cmd_sta_set_eaptls); | 
|  | 10233 | sigma_dut_reg_cmd("sta_set_eapttls", req_intf, cmd_sta_set_eapttls); | 
|  | 10234 | sigma_dut_reg_cmd("sta_set_eapsim", req_intf, cmd_sta_set_eapsim); | 
|  | 10235 | sigma_dut_reg_cmd("sta_set_peap", req_intf, cmd_sta_set_peap); | 
|  | 10236 | sigma_dut_reg_cmd("sta_set_eapfast", req_intf, cmd_sta_set_eapfast); | 
|  | 10237 | sigma_dut_reg_cmd("sta_set_eapaka", req_intf, cmd_sta_set_eapaka); | 
|  | 10238 | sigma_dut_reg_cmd("sta_set_eapakaprime", req_intf, | 
|  | 10239 | cmd_sta_set_eapakaprime); | 
|  | 10240 | sigma_dut_reg_cmd("sta_set_security", req_intf, cmd_sta_set_security); | 
|  | 10241 | sigma_dut_reg_cmd("sta_set_uapsd", req_intf, cmd_sta_set_uapsd); | 
|  | 10242 | /* TODO: sta_set_ibss */ | 
|  | 10243 | /* TODO: sta_set_mode */ | 
|  | 10244 | sigma_dut_reg_cmd("sta_set_wmm", req_intf, cmd_sta_set_wmm); | 
|  | 10245 | sigma_dut_reg_cmd("sta_associate", req_intf, cmd_sta_associate); | 
|  | 10246 | /* TODO: sta_up_load */ | 
|  | 10247 | sigma_dut_reg_cmd("sta_preset_testparameters", req_intf, | 
|  | 10248 | cmd_sta_preset_testparameters); | 
|  | 10249 | /* TODO: sta_set_system */ | 
|  | 10250 | sigma_dut_reg_cmd("sta_set_11n", req_intf, cmd_sta_set_11n); | 
|  | 10251 | /* TODO: sta_set_rifs_test */ | 
|  | 10252 | sigma_dut_reg_cmd("sta_set_wireless", req_intf, cmd_sta_set_wireless); | 
|  | 10253 | sigma_dut_reg_cmd("sta_send_addba", req_intf, cmd_sta_send_addba); | 
|  | 10254 | /* TODO: sta_send_coexist_mgmt */ | 
|  | 10255 | sigma_dut_reg_cmd("sta_disconnect", req_intf, cmd_sta_disconnect); | 
|  | 10256 | sigma_dut_reg_cmd("sta_reassoc", req_intf, cmd_sta_reassoc); | 
|  | 10257 | sigma_dut_reg_cmd("sta_reassociate", req_intf, cmd_sta_reassoc); | 
|  | 10258 | sigma_dut_reg_cmd("sta_reset_default", req_intf, | 
|  | 10259 | cmd_sta_reset_default); | 
|  | 10260 | sigma_dut_reg_cmd("sta_send_frame", req_intf, cmd_sta_send_frame); | 
|  | 10261 | sigma_dut_reg_cmd("sta_set_macaddr", req_intf, cmd_sta_set_macaddr); | 
|  | 10262 | sigma_dut_reg_cmd("sta_set_rfeature", req_intf, cmd_sta_set_rfeature); | 
|  | 10263 | sigma_dut_reg_cmd("sta_set_radio", req_intf, cmd_sta_set_radio); | 
|  | 10264 | sigma_dut_reg_cmd("sta_set_pwrsave", req_intf, cmd_sta_set_pwrsave); | 
|  | 10265 | sigma_dut_reg_cmd("sta_bssid_pool", req_intf, cmd_sta_bssid_pool); | 
|  | 10266 | sigma_dut_reg_cmd("sta_reset_parm", req_intf, cmd_sta_reset_parm); | 
|  | 10267 | sigma_dut_reg_cmd("sta_get_key", req_intf, cmd_sta_get_key); | 
|  | 10268 | sigma_dut_reg_cmd("sta_hs2_associate", req_intf, | 
|  | 10269 | cmd_sta_hs2_associate); | 
|  | 10270 | sigma_dut_reg_cmd("sta_add_credential", req_intf, | 
|  | 10271 | cmd_sta_add_credential); | 
|  | 10272 | sigma_dut_reg_cmd("sta_scan", req_intf, cmd_sta_scan); | 
| Jouni Malinen | 5e5d43d | 2018-01-10 17:29:33 +0200 | [diff] [blame] | 10273 | 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] | 10274 | sigma_dut_reg_cmd("sta_set_systime", NULL, cmd_sta_set_systime); | 
|  | 10275 | sigma_dut_reg_cmd("sta_osu", req_intf, cmd_sta_osu); | 
|  | 10276 | sigma_dut_reg_cmd("sta_policy_update", req_intf, cmd_sta_policy_update); | 
|  | 10277 | sigma_dut_reg_cmd("sta_er_config", NULL, cmd_sta_er_config); | 
|  | 10278 | sigma_dut_reg_cmd("sta_wps_connect_pw_token", req_intf, | 
|  | 10279 | cmd_sta_wps_connect_pw_token); | 
|  | 10280 | sigma_dut_reg_cmd("sta_exec_action", req_intf, cmd_sta_exec_action); | 
|  | 10281 | sigma_dut_reg_cmd("sta_get_events", req_intf, cmd_sta_get_events); | 
|  | 10282 | 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] | 10283 | sigma_dut_reg_cmd("start_wps_registration", req_intf, | 
|  | 10284 | cmd_start_wps_registration); | 
| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 10285 | } |