Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Sigma Control API DUT (station/AP) |
| 3 | * Copyright (c) 2010-2011, Atheros Communications, Inc. |
Jouni Malinen | 9d7e31d | 2017-12-22 18:55:04 +0200 | [diff] [blame] | 4 | * Copyright (c) 2011-2017, Qualcomm Atheros, Inc. |
Jouni Malinen | c12ea4a | 2018-01-05 21:07:10 +0200 | [diff] [blame] | 5 | * Copyright (c) 2018, The Linux Foundation |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6 | * All Rights Reserved. |
| 7 | * Licensed under the Clear BSD license. See README for more details. |
| 8 | */ |
| 9 | |
| 10 | #include "sigma_dut.h" |
| 11 | #include <sys/ioctl.h> |
| 12 | #include <sys/stat.h> |
Jouni Malinen | 8290520 | 2018-04-29 17:20:10 +0300 | [diff] [blame] | 13 | #include <sys/wait.h> |
Alexei Avshalom Lazar | a90032d | 2019-05-02 13:34:02 +0300 | [diff] [blame] | 14 | #include <ctype.h> |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 15 | #ifdef __linux__ |
Lior David | cc88b56 | 2017-01-03 18:52:09 +0200 | [diff] [blame] | 16 | #include <regex.h> |
| 17 | #include <dirent.h> |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 18 | #include <sys/time.h> |
| 19 | #include <netpacket/packet.h> |
| 20 | #include <linux/if_ether.h> |
| 21 | #ifdef ANDROID |
| 22 | #include <cutils/properties.h> |
| 23 | #include <android/log.h> |
| 24 | #include "keystore_get.h" |
| 25 | #else /* ANDROID */ |
| 26 | #include <ifaddrs.h> |
| 27 | #endif /* ANDROID */ |
| 28 | #include <netdb.h> |
| 29 | #endif /* __linux__ */ |
| 30 | #ifdef __QNXNTO__ |
| 31 | #include <net/if_dl.h> |
| 32 | #endif /* __QNXNTO__ */ |
| 33 | #include "wpa_ctrl.h" |
| 34 | #include "wpa_helpers.h" |
Amarnath Hullur Subramanyam | 9c381f5 | 2017-03-17 00:04:41 -0700 | [diff] [blame] | 35 | #include "miracast.h" |
Kiran Kumar Lokere | 29c1bb0 | 2018-10-08 17:41:02 -0700 | [diff] [blame] | 36 | #include "qca-vendor_copy.h" |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 37 | |
| 38 | /* Temporary files for sta_send_addba */ |
| 39 | #define VI_QOS_TMP_FILE "/tmp/vi-qos.tmp" |
| 40 | #define VI_QOS_FILE "/tmp/vi-qos.txt" |
| 41 | #define VI_QOS_REFFILE "/etc/vi-qos.txt" |
| 42 | |
| 43 | /* |
| 44 | * MTU for Ethernet need to take into account 8-byte SNAP header |
| 45 | * to be added when encapsulating Ethernet frame into 802.11 |
| 46 | */ |
| 47 | #ifndef IEEE80211_MAX_DATA_LEN_DMG |
| 48 | #define IEEE80211_MAX_DATA_LEN_DMG 7920 |
| 49 | #endif |
| 50 | #ifndef IEEE80211_SNAP_LEN_DMG |
| 51 | #define IEEE80211_SNAP_LEN_DMG 8 |
| 52 | #endif |
| 53 | |
Ashwini Patil | 0040258 | 2017-04-13 12:29:39 +0530 | [diff] [blame] | 54 | #define NON_PREF_CH_LIST_SIZE 100 |
Ashwini Patil | 5acd738 | 2017-04-13 15:55:04 +0530 | [diff] [blame] | 55 | #define NEIGHBOR_REPORT_SIZE 1000 |
| 56 | #define DEFAULT_NEIGHBOR_BSSID_INFO "17" |
| 57 | #define DEFAULT_NEIGHBOR_PHY_TYPE "1" |
Ashwini Patil | 0040258 | 2017-04-13 12:29:39 +0530 | [diff] [blame] | 58 | |
Alexei Avshalom Lazar | a90032d | 2019-05-02 13:34:02 +0300 | [diff] [blame] | 59 | #define WIL_DEFAULT_BI 100 |
| 60 | |
| 61 | /* default remain on channel time for transmitting frames (milliseconds) */ |
| 62 | #define WIL_TRANSMIT_FRAME_DEFAULT_ROC 500 |
| 63 | #define IEEE80211_P2P_ATTR_DEVICE_ID 3 |
| 64 | #define IEEE80211_P2P_ATTR_GROUP_ID 15 |
| 65 | |
| 66 | /* describes tagged bytes in template frame file */ |
| 67 | struct template_frame_tag { |
| 68 | int num; |
| 69 | int offset; |
| 70 | size_t len; |
| 71 | }; |
| 72 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 73 | extern char *sigma_wpas_ctrl; |
| 74 | extern char *sigma_cert_path; |
| 75 | extern enum driver_type wifi_chip_type; |
| 76 | extern char *sigma_radio_ifname[]; |
| 77 | |
Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 78 | #ifdef __linux__ |
| 79 | #define WIL_WMI_MAX_PAYLOAD 248 |
Alexei Avshalom Lazar | bc180dc | 2018-12-18 16:01:14 +0200 | [diff] [blame] | 80 | #define WIL_WMI_ESE_CFG_CMDID 0xa01 |
Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 81 | #define WIL_WMI_BF_TRIG_CMDID 0x83a |
Alexei Avshalom Lazar | b094bf0 | 2018-12-18 16:00:53 +0200 | [diff] [blame] | 82 | #define WIL_WMI_UNIT_TEST_CMDID 0x900 |
Alexei Avshalom Lazar | a90032d | 2019-05-02 13:34:02 +0300 | [diff] [blame] | 83 | #define WIL_WMI_P2P_CFG_CMDID 0x910 |
| 84 | #define WIL_WMI_START_LISTEN_CMDID 0x914 |
| 85 | #define WIL_WMI_DISCOVERY_STOP_CMDID 0x917 |
Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 86 | |
| 87 | struct wil_wmi_header { |
| 88 | uint8_t mid; |
| 89 | uint8_t reserved; |
| 90 | uint16_t cmd; |
| 91 | uint32_t ts; |
| 92 | } __attribute__((packed)); |
| 93 | |
| 94 | enum wil_wmi_bf_trig_type { |
| 95 | WIL_WMI_SLS, |
| 96 | WIL_WMI_BRP_RX, |
| 97 | WIL_WMI_BRP_TX, |
| 98 | }; |
| 99 | |
| 100 | struct wil_wmi_bf_trig_cmd { |
| 101 | /* enum wil_wmi_bf_trig_type */ |
| 102 | uint32_t bf_type; |
| 103 | /* cid when type == WMI_BRP_RX */ |
| 104 | uint32_t sta_id; |
| 105 | uint32_t reserved; |
| 106 | /* mac address when type = WIL_WMI_SLS */ |
| 107 | uint8_t dest_mac[6]; |
| 108 | } __attribute__((packed)); |
Alexei Avshalom Lazar | b094bf0 | 2018-12-18 16:00:53 +0200 | [diff] [blame] | 109 | |
Alexei Avshalom Lazar | bc180dc | 2018-12-18 16:01:14 +0200 | [diff] [blame] | 110 | enum wil_wmi_sched_scheme_advertisment { |
| 111 | WIL_WMI_ADVERTISE_ESE_DISABLED, |
| 112 | WIL_WMI_ADVERTISE_ESE_IN_BEACON, |
| 113 | WIL_WMI_ADVERTISE_ESE_IN_ANNOUNCE_FRAME, |
| 114 | }; |
| 115 | |
| 116 | enum wil_wmi_ese_slot_type { |
| 117 | WIL_WMI_ESE_SP, |
| 118 | WIL_WMI_ESE_CBAP, |
| 119 | WIL_WMI_ESE_ANNOUNCE_NO_ACK, |
| 120 | }; |
| 121 | |
| 122 | struct wil_wmi_ese_slot { |
| 123 | /* offset from start of BI in microseconds */ |
| 124 | uint32_t tbtt_offset; |
| 125 | uint8_t flags; |
| 126 | /* enum wil_wmi_ese_slot_type */ |
| 127 | uint8_t slot_type; |
| 128 | /* duration in microseconds */ |
| 129 | uint16_t duration; |
| 130 | /* frame exchange sequence duration, microseconds */ |
| 131 | uint16_t tx_op; |
| 132 | /* time between 2 blocks for periodic allocation(microseconds) */ |
| 133 | uint16_t period; |
| 134 | /* number of blocks in periodic allocation */ |
| 135 | uint8_t num_blocks; |
| 136 | /* for semi-active allocations */ |
| 137 | uint8_t idle_period; |
| 138 | uint8_t src_aid; |
| 139 | uint8_t dst_aid; |
| 140 | uint32_t reserved; |
| 141 | } __attribute__((packed)); |
| 142 | |
| 143 | #define WIL_WMI_MAX_ESE_SLOTS 4 |
| 144 | struct wil_wmi_ese_cfg { |
| 145 | uint8_t serial_num; |
| 146 | /* wil_wmi_sched_scheme_advertisment */ |
| 147 | uint8_t ese_advertisment; |
| 148 | uint16_t flags; |
| 149 | uint8_t num_allocs; |
| 150 | uint8_t reserved[3]; |
| 151 | uint64_t start_tbtt; |
| 152 | /* allocations list */ |
| 153 | struct wil_wmi_ese_slot slots[WIL_WMI_MAX_ESE_SLOTS]; |
| 154 | } __attribute__((packed)); |
| 155 | |
Alexei Avshalom Lazar | aad97b0 | 2018-12-18 16:01:23 +0200 | [diff] [blame] | 156 | #define WIL_WMI_UT_FORCE_MCS 6 |
| 157 | struct wil_wmi_force_mcs { |
| 158 | /* WIL_WMI_UT_HW_SYSAPI */ |
| 159 | uint16_t module_id; |
| 160 | /* WIL_WMI_UT_FORCE_MCS */ |
| 161 | uint16_t subtype_id; |
| 162 | /* cid (ignored in oob_mode, affects all stations) */ |
| 163 | uint32_t cid; |
| 164 | /* 1 to force MCS, 0 to restore default behavior */ |
| 165 | uint32_t force_enable; |
| 166 | /* MCS index, 0-12 */ |
| 167 | uint32_t mcs; |
| 168 | } __attribute__((packed)); |
| 169 | |
Alexei Avshalom Lazar | b094bf0 | 2018-12-18 16:00:53 +0200 | [diff] [blame] | 170 | #define WIL_WMI_UT_HW_SYSAPI 10 |
| 171 | #define WIL_WMI_UT_FORCE_RSN_IE 0x29 |
| 172 | struct wil_wmi_force_rsn_ie { |
| 173 | /* WIL_WMI_UT_HW_SYSAPI */ |
| 174 | uint16_t module_id; |
| 175 | /* WIL_WMI_UT_FORCE_RSN_IE */ |
| 176 | uint16_t subtype_id; |
| 177 | /* 0 = no change, 1 = remove if exists, 2 = add if does not exist */ |
| 178 | uint32_t state; |
| 179 | } __attribute__((packed)); |
Alexei Avshalom Lazar | a90032d | 2019-05-02 13:34:02 +0300 | [diff] [blame] | 180 | |
| 181 | enum wil_wmi_discovery_mode { |
| 182 | WMI_DISCOVERY_MODE_NON_OFFLOAD, |
| 183 | WMI_DISCOVERY_MODE_OFFLOAD, |
| 184 | WMI_DISCOVERY_MODE_PEER2PEER, |
| 185 | }; |
| 186 | |
| 187 | struct wil_wmi_p2p_cfg_cmd { |
| 188 | /* enum wil_wmi_discovery_mode */ |
| 189 | uint8_t discovery_mode; |
| 190 | /* 0-based (wireless channel - 1) */ |
| 191 | uint8_t channel; |
| 192 | /* set to WIL_DEFAULT_BI */ |
| 193 | uint16_t bcon_interval; |
| 194 | } __attribute__((packed)); |
Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 195 | #endif /* __linux__ */ |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 196 | |
| 197 | #ifdef ANDROID |
| 198 | |
| 199 | static int add_ipv6_rule(struct sigma_dut *dut, const char *ifname); |
| 200 | |
| 201 | #define ANDROID_KEYSTORE_GET 'g' |
| 202 | #define ANDROID_KEYSTORE_GET_PUBKEY 'b' |
| 203 | |
| 204 | static int android_keystore_get(char cmd, const char *key, unsigned char *val) |
| 205 | { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 206 | /* Android 4.3 changed keystore design, so need to use keystore_get() */ |
| 207 | #ifndef KEYSTORE_MESSAGE_SIZE |
| 208 | #define KEYSTORE_MESSAGE_SIZE 65535 |
| 209 | #endif /* KEYSTORE_MESSAGE_SIZE */ |
| 210 | |
| 211 | ssize_t len; |
| 212 | uint8_t *value = NULL; |
| 213 | |
| 214 | __android_log_print(ANDROID_LOG_DEBUG, "sigma_dut", |
| 215 | "keystore command '%c' key '%s' --> keystore_get", |
| 216 | cmd, key); |
| 217 | |
| 218 | len = keystore_get(key, strlen(key), &value); |
| 219 | if (len < 0) { |
| 220 | __android_log_print(ANDROID_LOG_DEBUG, "sigma_dut", |
| 221 | "keystore_get() failed"); |
| 222 | return -1; |
| 223 | } |
| 224 | |
| 225 | if (len > KEYSTORE_MESSAGE_SIZE) |
| 226 | len = KEYSTORE_MESSAGE_SIZE; |
| 227 | memcpy(val, value, len); |
| 228 | free(value); |
| 229 | return len; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 230 | } |
| 231 | #endif /* ANDROID */ |
| 232 | |
| 233 | |
| 234 | int set_ps(const char *intf, struct sigma_dut *dut, int enabled) |
| 235 | { |
| 236 | #ifdef __linux__ |
| 237 | char buf[100]; |
| 238 | |
| 239 | if (wifi_chip_type == DRIVER_WCN) { |
| 240 | if (enabled) { |
| 241 | snprintf(buf, sizeof(buf), "iwpriv wlan0 dump 906"); |
Pradeep Reddy POTTETI | 625b370 | 2016-09-20 17:09:58 +0530 | [diff] [blame] | 242 | if (system(buf) != 0) |
| 243 | goto set_power_save; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 244 | } else { |
| 245 | snprintf(buf, sizeof(buf), "iwpriv wlan0 dump 905"); |
Pradeep Reddy POTTETI | 625b370 | 2016-09-20 17:09:58 +0530 | [diff] [blame] | 246 | if (system(buf) != 0) |
| 247 | goto set_power_save; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 248 | snprintf(buf, sizeof(buf), "iwpriv wlan0 dump 912"); |
Pradeep Reddy POTTETI | 625b370 | 2016-09-20 17:09:58 +0530 | [diff] [blame] | 249 | if (system(buf) != 0) |
| 250 | goto set_power_save; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | return 0; |
| 254 | } |
| 255 | |
Pradeep Reddy POTTETI | 625b370 | 2016-09-20 17:09:58 +0530 | [diff] [blame] | 256 | set_power_save: |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 257 | snprintf(buf, sizeof(buf), "./iw dev %s set power_save %s", |
| 258 | intf, enabled ? "on" : "off"); |
| 259 | if (system(buf) != 0) { |
| 260 | snprintf(buf, sizeof(buf), "iw dev %s set power_save %s", |
| 261 | intf, enabled ? "on" : "off"); |
Pradeep Reddy POTTETI | 625b370 | 2016-09-20 17:09:58 +0530 | [diff] [blame] | 262 | if (system(buf) != 0) { |
| 263 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 264 | "Failed to set power save %s", |
| 265 | enabled ? "on" : "off"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 266 | return -1; |
Pradeep Reddy POTTETI | 625b370 | 2016-09-20 17:09:58 +0530 | [diff] [blame] | 267 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | return 0; |
| 271 | #else /* __linux__ */ |
| 272 | return -1; |
| 273 | #endif /* __linux__ */ |
| 274 | } |
| 275 | |
| 276 | |
Lior David | cc88b56 | 2017-01-03 18:52:09 +0200 | [diff] [blame] | 277 | #ifdef __linux__ |
Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 278 | |
Lior David | cc88b56 | 2017-01-03 18:52:09 +0200 | [diff] [blame] | 279 | static int wil6210_get_debugfs_dir(struct sigma_dut *dut, char *path, |
| 280 | size_t len) |
| 281 | { |
| 282 | DIR *dir, *wil_dir; |
| 283 | struct dirent *entry; |
| 284 | int ret = -1; |
| 285 | const char *root_path = "/sys/kernel/debug/ieee80211"; |
| 286 | |
| 287 | dir = opendir(root_path); |
| 288 | if (!dir) |
| 289 | return -2; |
| 290 | |
| 291 | while ((entry = readdir(dir))) { |
| 292 | if (strcmp(entry->d_name, ".") == 0 || |
| 293 | strcmp(entry->d_name, "..") == 0) |
| 294 | continue; |
| 295 | |
| 296 | if (snprintf(path, len, "%s/%s/wil6210", |
| 297 | root_path, entry->d_name) >= (int) len) { |
| 298 | ret = -3; |
| 299 | break; |
| 300 | } |
| 301 | |
| 302 | wil_dir = opendir(path); |
| 303 | if (wil_dir) { |
| 304 | closedir(wil_dir); |
| 305 | ret = 0; |
| 306 | break; |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | closedir(dir); |
| 311 | return ret; |
| 312 | } |
Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 313 | |
| 314 | |
| 315 | static int wil6210_wmi_send(struct sigma_dut *dut, uint16_t command, |
| 316 | void *payload, uint16_t length) |
| 317 | { |
| 318 | struct { |
| 319 | struct wil_wmi_header hdr; |
| 320 | char payload[WIL_WMI_MAX_PAYLOAD]; |
| 321 | } __attribute__((packed)) cmd; |
| 322 | char buf[128], fname[128]; |
| 323 | size_t towrite, written; |
| 324 | FILE *f; |
Jouni Malinen | 3aa7286 | 2019-05-29 23:14:51 +0300 | [diff] [blame] | 325 | int res; |
Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 326 | |
| 327 | if (length > WIL_WMI_MAX_PAYLOAD) { |
| 328 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 329 | "payload too large(%u, max %u)", |
| 330 | length, WIL_WMI_MAX_PAYLOAD); |
| 331 | return -1; |
| 332 | } |
| 333 | |
| 334 | memset(&cmd.hdr, 0, sizeof(cmd.hdr)); |
| 335 | cmd.hdr.cmd = command; |
| 336 | memcpy(cmd.payload, payload, length); |
| 337 | |
| 338 | if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) { |
| 339 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 340 | "failed to get wil6210 debugfs dir"); |
| 341 | return -1; |
| 342 | } |
| 343 | |
Jouni Malinen | 3aa7286 | 2019-05-29 23:14:51 +0300 | [diff] [blame] | 344 | res = snprintf(fname, sizeof(fname), "%s/wmi_send", buf); |
| 345 | if (res < 0 || res >= sizeof(fname)) |
| 346 | return -1; |
Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 347 | f = fopen(fname, "wb"); |
| 348 | if (!f) { |
| 349 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 350 | "failed to open: %s", fname); |
| 351 | return -1; |
| 352 | } |
| 353 | |
| 354 | towrite = sizeof(cmd.hdr) + length; |
| 355 | written = fwrite(&cmd, 1, towrite, f); |
| 356 | fclose(f); |
| 357 | if (written != towrite) { |
| 358 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 359 | "failed to send wmi %u", command); |
| 360 | return -1; |
| 361 | } |
| 362 | |
| 363 | return 0; |
| 364 | } |
| 365 | |
| 366 | |
| 367 | static int wil6210_get_sta_info_field(struct sigma_dut *dut, const char *bssid, |
| 368 | const char *pattern, unsigned int *field) |
| 369 | { |
| 370 | char buf[128], fname[128]; |
| 371 | FILE *f; |
| 372 | regex_t re; |
| 373 | regmatch_t m[2]; |
Jouni Malinen | 3aa7286 | 2019-05-29 23:14:51 +0300 | [diff] [blame] | 374 | int rc, ret = -1, res; |
Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 375 | |
| 376 | if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) { |
| 377 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 378 | "failed to get wil6210 debugfs dir"); |
| 379 | return -1; |
| 380 | } |
| 381 | |
Jouni Malinen | 3aa7286 | 2019-05-29 23:14:51 +0300 | [diff] [blame] | 382 | res = snprintf(fname, sizeof(fname), "%s/stations", buf); |
| 383 | if (res < 0 || res >= sizeof(fname)) |
| 384 | return -1; |
Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 385 | f = fopen(fname, "r"); |
| 386 | if (!f) { |
| 387 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 388 | "failed to open: %s", fname); |
| 389 | return -1; |
| 390 | } |
| 391 | |
| 392 | if (regcomp(&re, pattern, REG_EXTENDED)) { |
| 393 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 394 | "regcomp failed: %s", pattern); |
| 395 | goto out; |
| 396 | } |
| 397 | |
| 398 | /* |
| 399 | * find the entry for the mac address |
| 400 | * line is of the form: [n] 11:22:33:44:55:66 state AID aid |
| 401 | */ |
| 402 | while (fgets(buf, sizeof(buf), f)) { |
| 403 | if (strcasestr(buf, bssid)) { |
| 404 | /* extract the field (CID/AID/state) */ |
| 405 | rc = regexec(&re, buf, 2, m, 0); |
| 406 | if (!rc && (m[1].rm_so >= 0)) { |
| 407 | buf[m[1].rm_eo] = 0; |
| 408 | *field = atoi(&buf[m[1].rm_so]); |
| 409 | ret = 0; |
| 410 | break; |
| 411 | } |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | regfree(&re); |
| 416 | if (ret) |
| 417 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 418 | "could not extract field"); |
| 419 | |
| 420 | out: |
| 421 | fclose(f); |
| 422 | |
| 423 | return ret; |
| 424 | } |
| 425 | |
| 426 | |
| 427 | static int wil6210_get_cid(struct sigma_dut *dut, const char *bssid, |
| 428 | unsigned int *cid) |
| 429 | { |
| 430 | const char *pattern = "\\[([0-9]+)\\]"; |
| 431 | |
| 432 | return wil6210_get_sta_info_field(dut, bssid, pattern, cid); |
| 433 | } |
| 434 | |
| 435 | |
| 436 | static int wil6210_send_brp_rx(struct sigma_dut *dut, const char *mac, |
| 437 | int l_rx) |
| 438 | { |
Rakesh Sunki | 556237d | 2017-03-30 14:49:31 -0700 | [diff] [blame] | 439 | struct wil_wmi_bf_trig_cmd cmd; |
Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 440 | unsigned int cid; |
| 441 | |
Rakesh Sunki | 556237d | 2017-03-30 14:49:31 -0700 | [diff] [blame] | 442 | memset(&cmd, 0, sizeof(cmd)); |
| 443 | |
Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 444 | if (wil6210_get_cid(dut, mac, &cid)) |
| 445 | return -1; |
| 446 | |
| 447 | cmd.bf_type = WIL_WMI_BRP_RX; |
| 448 | cmd.sta_id = cid; |
| 449 | /* training length (l_rx) is ignored, FW always uses length 16 */ |
| 450 | return wil6210_wmi_send(dut, WIL_WMI_BF_TRIG_CMDID, |
| 451 | &cmd, sizeof(cmd)); |
| 452 | } |
| 453 | |
| 454 | |
| 455 | static int wil6210_send_sls(struct sigma_dut *dut, const char *mac) |
| 456 | { |
Rakesh Sunki | 556237d | 2017-03-30 14:49:31 -0700 | [diff] [blame] | 457 | struct wil_wmi_bf_trig_cmd cmd; |
| 458 | |
| 459 | memset(&cmd, 0, sizeof(cmd)); |
Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 460 | |
| 461 | if (parse_mac_address(dut, mac, (unsigned char *)&cmd.dest_mac)) |
| 462 | return -1; |
| 463 | |
| 464 | cmd.bf_type = WIL_WMI_SLS; |
| 465 | return wil6210_wmi_send(dut, WIL_WMI_BF_TRIG_CMDID, |
| 466 | &cmd, sizeof(cmd)); |
| 467 | } |
| 468 | |
Alexei Avshalom Lazar | b094bf0 | 2018-12-18 16:00:53 +0200 | [diff] [blame] | 469 | |
Alexei Avshalom Lazar | bc180dc | 2018-12-18 16:01:14 +0200 | [diff] [blame] | 470 | int wil6210_set_ese(struct sigma_dut *dut, int count, |
| 471 | struct sigma_ese_alloc *allocs) |
| 472 | { |
| 473 | struct wil_wmi_ese_cfg cmd = { }; |
| 474 | int i; |
| 475 | |
| 476 | if (count == 0 || count > WIL_WMI_MAX_ESE_SLOTS) |
| 477 | return -1; |
| 478 | |
| 479 | if (dut->ap_bcnint <= 0) { |
| 480 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 481 | "invalid beacon interval(%d), check test", |
| 482 | dut->ap_bcnint); |
| 483 | return -1; |
| 484 | } |
| 485 | |
| 486 | cmd.ese_advertisment = WIL_WMI_ADVERTISE_ESE_IN_BEACON; |
| 487 | cmd.flags = 0x1d; |
| 488 | cmd.num_allocs = count; |
| 489 | for (i = 0; i < count; i++) { |
| 490 | /* |
| 491 | * Convert percent from BI (BI specified in milliseconds) |
| 492 | * to absolute duration in microseconds. |
| 493 | */ |
| 494 | cmd.slots[i].duration = |
| 495 | (allocs[i].percent_bi * dut->ap_bcnint * 1000) / 100; |
| 496 | switch (allocs[i].type) { |
| 497 | case ESE_CBAP: |
| 498 | cmd.slots[i].slot_type = WIL_WMI_ESE_CBAP; |
| 499 | break; |
| 500 | case ESE_SP: |
| 501 | cmd.slots[i].slot_type = WIL_WMI_ESE_SP; |
| 502 | break; |
| 503 | default: |
| 504 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 505 | "invalid slot type(%d) at index %d", |
| 506 | allocs[i].type, i); |
| 507 | return -1; |
| 508 | } |
| 509 | cmd.slots[i].src_aid = allocs[i].src_aid; |
| 510 | cmd.slots[i].dst_aid = allocs[i].dst_aid; |
| 511 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 512 | "slot %d, duration %u, type %d, srcAID %u dstAID %u", |
| 513 | i, cmd.slots[i].duration, |
| 514 | cmd.slots[i].slot_type, cmd.slots[i].src_aid, |
| 515 | cmd.slots[i].dst_aid); |
| 516 | } |
| 517 | |
| 518 | return wil6210_wmi_send(dut, WIL_WMI_ESE_CFG_CMDID, &cmd, sizeof(cmd)); |
| 519 | } |
| 520 | |
| 521 | |
Alexei Avshalom Lazar | aad97b0 | 2018-12-18 16:01:23 +0200 | [diff] [blame] | 522 | int wil6210_set_force_mcs(struct sigma_dut *dut, int force, int mcs) |
| 523 | { |
| 524 | struct wil_wmi_force_mcs cmd = { }; |
| 525 | |
| 526 | cmd.module_id = WIL_WMI_UT_HW_SYSAPI; |
| 527 | cmd.subtype_id = WIL_WMI_UT_FORCE_MCS; |
| 528 | cmd.force_enable = (uint32_t) force; |
| 529 | cmd.mcs = (uint32_t) mcs; |
| 530 | |
| 531 | return wil6210_wmi_send(dut, WIL_WMI_UNIT_TEST_CMDID, |
| 532 | &cmd, sizeof(cmd)); |
| 533 | } |
| 534 | |
| 535 | |
Alexei Avshalom Lazar | b094bf0 | 2018-12-18 16:00:53 +0200 | [diff] [blame] | 536 | static int wil6210_force_rsn_ie(struct sigma_dut *dut, int state) |
| 537 | { |
| 538 | struct wil_wmi_force_rsn_ie cmd = { }; |
| 539 | |
| 540 | cmd.module_id = WIL_WMI_UT_HW_SYSAPI; |
| 541 | cmd.subtype_id = WIL_WMI_UT_FORCE_RSN_IE; |
| 542 | cmd.state = (uint32_t) state; |
| 543 | |
| 544 | return wil6210_wmi_send(dut, WIL_WMI_UNIT_TEST_CMDID, |
| 545 | &cmd, sizeof(cmd)); |
| 546 | } |
| 547 | |
Alexei Avshalom Lazar | a90032d | 2019-05-02 13:34:02 +0300 | [diff] [blame] | 548 | |
| 549 | /* |
| 550 | * this function is also used to configure generic remain-on-channel |
| 551 | */ |
| 552 | static int wil6210_p2p_cfg(struct sigma_dut *dut, int freq) |
| 553 | { |
| 554 | struct wil_wmi_p2p_cfg_cmd cmd = { }; |
| 555 | int channel = freq_to_channel(freq); |
| 556 | |
| 557 | if (channel < 0) |
| 558 | return -1; |
| 559 | cmd.discovery_mode = WMI_DISCOVERY_MODE_NON_OFFLOAD; |
| 560 | cmd.channel = channel - 1; |
| 561 | cmd.bcon_interval = WIL_DEFAULT_BI; |
| 562 | cmd.discovery_mode = WMI_DISCOVERY_MODE_PEER2PEER; |
| 563 | |
| 564 | return wil6210_wmi_send(dut, WIL_WMI_P2P_CFG_CMDID, |
| 565 | &cmd, sizeof(cmd)); |
| 566 | } |
| 567 | |
| 568 | |
| 569 | static int wil6210_remain_on_channel(struct sigma_dut *dut, int freq) |
| 570 | { |
| 571 | int ret = wil6210_p2p_cfg(dut, freq); |
| 572 | |
| 573 | if (ret) |
| 574 | return ret; |
| 575 | |
| 576 | ret = wil6210_wmi_send(dut, WIL_WMI_START_LISTEN_CMDID, NULL, 0); |
| 577 | if (!ret) { |
| 578 | /* |
| 579 | * wait a bit to allow FW to setup the radio |
| 580 | * especially important if we switch channels |
| 581 | */ |
| 582 | usleep(500000); |
| 583 | } |
| 584 | |
| 585 | return ret; |
| 586 | } |
| 587 | |
| 588 | |
| 589 | static int wil6210_stop_discovery(struct sigma_dut *dut) |
| 590 | { |
| 591 | return wil6210_wmi_send(dut, WIL_WMI_DISCOVERY_STOP_CMDID, NULL, 0); |
| 592 | } |
| 593 | |
| 594 | |
| 595 | static int wil6210_transmit_frame(struct sigma_dut *dut, int freq, |
| 596 | int wait_duration, |
| 597 | const char *frame, size_t frame_len) |
| 598 | { |
| 599 | char buf[128], fname[128]; |
| 600 | FILE *f; |
Jouni Malinen | 3aa7286 | 2019-05-29 23:14:51 +0300 | [diff] [blame] | 601 | int res = 0, r; |
Alexei Avshalom Lazar | a90032d | 2019-05-02 13:34:02 +0300 | [diff] [blame] | 602 | size_t written; |
| 603 | |
| 604 | if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) { |
| 605 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 606 | "failed to get wil6210 debugfs dir"); |
| 607 | return -1; |
| 608 | } |
Jouni Malinen | 3aa7286 | 2019-05-29 23:14:51 +0300 | [diff] [blame] | 609 | r = snprintf(fname, sizeof(fname), "%s/tx_mgmt", buf); |
| 610 | if (r < 0 || r >= sizeof(fname)) |
| 611 | return -1; |
Alexei Avshalom Lazar | a90032d | 2019-05-02 13:34:02 +0300 | [diff] [blame] | 612 | |
| 613 | if (wil6210_remain_on_channel(dut, freq)) { |
| 614 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 615 | "failed to listen on channel"); |
| 616 | return -1; |
| 617 | } |
| 618 | |
| 619 | f = fopen(fname, "wb"); |
| 620 | if (!f) { |
| 621 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 622 | "failed to open: %s", fname); |
| 623 | res = -1; |
| 624 | goto out_stop; |
| 625 | } |
| 626 | written = fwrite(frame, 1, frame_len, f); |
| 627 | fclose(f); |
| 628 | |
| 629 | if (written != frame_len) { |
| 630 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 631 | "failed to transmit frame (got %zd, expected %zd)", |
| 632 | written, frame_len); |
| 633 | res = -1; |
| 634 | goto out_stop; |
| 635 | } |
| 636 | |
| 637 | usleep(wait_duration * 1000); |
| 638 | |
| 639 | out_stop: |
| 640 | wil6210_stop_discovery(dut); |
| 641 | return res; |
| 642 | } |
| 643 | |
| 644 | |
| 645 | static int find_template_frame_tag(struct template_frame_tag *tags, |
| 646 | int total_tags, int tag_num) |
| 647 | { |
| 648 | int i; |
| 649 | |
| 650 | for (i = 0; i < total_tags; i++) { |
| 651 | if (tag_num == tags[i].num) |
| 652 | return i; |
| 653 | } |
| 654 | |
| 655 | return -1; |
| 656 | } |
| 657 | |
| 658 | |
| 659 | static int replace_p2p_attribute(struct sigma_dut *dut, char *buf, size_t len, |
| 660 | int id, const char *value, size_t val_len) |
| 661 | { |
| 662 | struct wfa_p2p_attribute *attr = (struct wfa_p2p_attribute *) buf; |
| 663 | |
| 664 | if (len < 3 + val_len) { |
| 665 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 666 | "not enough space to replace P2P attribute"); |
| 667 | return -1; |
| 668 | } |
| 669 | |
| 670 | if (attr->len != val_len) { |
| 671 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 672 | "attribute length mismatch (need %zu have %hu)", |
| 673 | val_len, attr->len); |
| 674 | return -1; |
| 675 | } |
| 676 | |
| 677 | if (attr->id != id) { |
| 678 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 679 | "incorrect attribute id (expected %d actual %d)", |
| 680 | id, attr->id); |
| 681 | return -1; |
| 682 | } |
| 683 | |
| 684 | memcpy(attr->variable, value, val_len); |
| 685 | |
| 686 | return 0; |
| 687 | } |
| 688 | |
| 689 | |
| 690 | static int parse_template_frame_file(struct sigma_dut *dut, const char *fname, |
| 691 | char *buf, size_t *length, |
| 692 | struct template_frame_tag *tags, |
| 693 | size_t *num_tags) |
| 694 | { |
| 695 | char line[512]; |
| 696 | FILE *f; |
| 697 | size_t offset = 0, tag_index = 0; |
| 698 | int num, index; |
| 699 | int in_tag = 0, tag_num = 0, tag_offset = 0; |
| 700 | |
| 701 | if (*length < sizeof(struct ieee80211_hdr_3addr)) { |
| 702 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 703 | "supplied buffer is too small"); |
| 704 | return -1; |
| 705 | } |
| 706 | |
| 707 | f = fopen(fname, "r"); |
| 708 | if (!f) { |
| 709 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 710 | "failed to open template file %s", fname); |
| 711 | return -1; |
| 712 | } |
| 713 | |
| 714 | /* |
| 715 | * template file format: lines beginning with # are comments and |
| 716 | * ignored. |
| 717 | * It is possible to tag bytes in the frame to make it easy |
| 718 | * to replace fields in the template, espcially if they appear |
| 719 | * in variable-sized sections (such as IEs) |
| 720 | * This is done by a line beginning with $NUM where NUM is an integer |
| 721 | * tag number. It can be followed by space(s) and comment. |
| 722 | * The next line is considered the tagged bytes. The parser will fill |
| 723 | * the tag number, offset and length of the tagged bytes. |
| 724 | * rest of the lines contain frame bytes as sequence of hex digits, |
| 725 | * 2 digits for each byte. Spaces are allowed between bytes. |
| 726 | * On bytes lines only hex digits and spaces are allowed |
| 727 | */ |
| 728 | while (!feof(f)) { |
| 729 | if (!fgets(line, sizeof(line), f)) |
| 730 | break; |
| 731 | index = 0; |
| 732 | while (isspace((unsigned char) line[index])) |
| 733 | index++; |
| 734 | if (!line[index] || line[index] == '#') |
| 735 | continue; |
| 736 | if (line[index] == '$') { |
| 737 | if (tags) { |
| 738 | index++; |
| 739 | tag_num = strtol(&line[index], NULL, 0); |
| 740 | tag_offset = offset; |
| 741 | in_tag = 1; |
| 742 | } |
| 743 | continue; |
| 744 | } |
| 745 | while (line[index]) { |
| 746 | if (isspace((unsigned char) line[index])) { |
| 747 | index++; |
| 748 | continue; |
| 749 | } |
| 750 | num = hex_byte(&line[index]); |
| 751 | if (num < 0) |
| 752 | break; |
| 753 | buf[offset++] = num; |
| 754 | if (offset == *length) |
| 755 | goto out; |
| 756 | index += 2; |
| 757 | } |
| 758 | |
| 759 | if (in_tag) { |
| 760 | if (tag_index < *num_tags) { |
| 761 | tags[tag_index].num = tag_num; |
| 762 | tags[tag_index].offset = tag_offset; |
| 763 | tags[tag_index].len = offset - tag_offset; |
| 764 | tag_index++; |
| 765 | } else { |
| 766 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 767 | "too many tags, tag ignored"); |
| 768 | } |
| 769 | in_tag = 0; |
| 770 | } |
| 771 | } |
| 772 | |
| 773 | if (num_tags) |
| 774 | *num_tags = tag_index; |
| 775 | out: |
| 776 | fclose(f); |
| 777 | if (offset < sizeof(struct ieee80211_hdr_3addr)) { |
| 778 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 779 | "template frame is too small"); |
| 780 | return -1; |
| 781 | } |
| 782 | |
| 783 | *length = offset; |
| 784 | return 0; |
| 785 | } |
| 786 | |
Lior David | cc88b56 | 2017-01-03 18:52:09 +0200 | [diff] [blame] | 787 | #endif /* __linux__ */ |
| 788 | |
| 789 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 790 | static void static_ip_file(int proto, const char *addr, const char *mask, |
| 791 | const char *gw) |
| 792 | { |
| 793 | if (proto) { |
| 794 | FILE *f = fopen("static-ip", "w"); |
| 795 | if (f) { |
| 796 | fprintf(f, "%d %s %s %s\n", proto, addr, |
| 797 | mask ? mask : "N/A", |
| 798 | gw ? gw : "N/A"); |
| 799 | fclose(f); |
| 800 | } |
| 801 | } else { |
| 802 | unlink("static-ip"); |
| 803 | } |
| 804 | } |
| 805 | |
| 806 | |
| 807 | static int send_neighbor_request(struct sigma_dut *dut, const char *intf, |
| 808 | const char *ssid) |
| 809 | { |
| 810 | #ifdef __linux__ |
| 811 | char buf[100]; |
| 812 | |
| 813 | snprintf(buf, sizeof(buf), "iwpriv %s neighbor %s", |
| 814 | intf, ssid); |
| 815 | sigma_dut_print(dut, DUT_MSG_INFO, "Request: %s", buf); |
| 816 | |
| 817 | if (system(buf) != 0) { |
| 818 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 819 | "iwpriv neighbor request failed"); |
| 820 | return -1; |
| 821 | } |
| 822 | |
| 823 | sigma_dut_print(dut, DUT_MSG_INFO, "iwpriv neighbor request send"); |
| 824 | |
| 825 | return 0; |
| 826 | #else /* __linux__ */ |
| 827 | return -1; |
| 828 | #endif /* __linux__ */ |
| 829 | } |
| 830 | |
| 831 | |
| 832 | 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] | 833 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 834 | { |
Ashwini Patil | 5acd738 | 2017-04-13 15:55:04 +0530 | [diff] [blame] | 835 | const char *val; |
| 836 | int reason_code = 0; |
| 837 | char buf[1024]; |
| 838 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 839 | /* |
| 840 | * In the earlier builds we used WNM_QUERY and in later |
| 841 | * builds used WNM_BSS_QUERY. |
| 842 | */ |
| 843 | |
Ashwini Patil | 5acd738 | 2017-04-13 15:55:04 +0530 | [diff] [blame] | 844 | val = get_param(cmd, "BTMQuery_Reason_Code"); |
| 845 | if (val) |
| 846 | reason_code = atoi(val); |
| 847 | |
| 848 | val = get_param(cmd, "Cand_List"); |
| 849 | if (val && atoi(val) == 1 && dut->btm_query_cand_list) { |
| 850 | snprintf(buf, sizeof(buf), "WNM_BSS_QUERY %d%s", reason_code, |
| 851 | dut->btm_query_cand_list); |
| 852 | free(dut->btm_query_cand_list); |
| 853 | dut->btm_query_cand_list = NULL; |
| 854 | } else { |
| 855 | snprintf(buf, sizeof(buf), "WNM_BSS_QUERY %d", reason_code); |
| 856 | } |
| 857 | |
| 858 | if (wpa_command(intf, buf) != 0) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 859 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 860 | "transition management query failed"); |
| 861 | return -1; |
| 862 | } |
| 863 | |
| 864 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 865 | "transition management query sent"); |
| 866 | |
| 867 | return 0; |
| 868 | } |
| 869 | |
| 870 | |
| 871 | int is_ip_addr(const char *str) |
| 872 | { |
| 873 | const char *pos = str; |
| 874 | struct in_addr addr; |
| 875 | |
| 876 | while (*pos) { |
| 877 | if (*pos != '.' && (*pos < '0' || *pos > '9')) |
| 878 | return 0; |
| 879 | pos++; |
| 880 | } |
| 881 | |
| 882 | return inet_aton(str, &addr); |
| 883 | } |
| 884 | |
| 885 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 886 | int get_ip_config(struct sigma_dut *dut, const char *ifname, char *buf, |
| 887 | size_t buf_len) |
| 888 | { |
vamsi krishna | a11d073 | 2018-05-16 12:19:48 +0530 | [diff] [blame] | 889 | char tmp[256]; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 890 | char ip[16], mask[15], dns[16], sec_dns[16]; |
| 891 | int is_dhcp = 0; |
| 892 | int s; |
| 893 | #ifdef ANDROID |
| 894 | char prop[PROPERTY_VALUE_MAX]; |
vamsi krishna | a11d073 | 2018-05-16 12:19:48 +0530 | [diff] [blame] | 895 | #else /* ANDROID */ |
| 896 | FILE *f; |
| 897 | #ifdef __linux__ |
| 898 | const char *str_ps; |
| 899 | #endif /* __linux__ */ |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 900 | #endif /* ANDROID */ |
| 901 | |
| 902 | ip[0] = '\0'; |
| 903 | mask[0] = '\0'; |
| 904 | dns[0] = '\0'; |
| 905 | sec_dns[0] = '\0'; |
| 906 | |
| 907 | s = socket(PF_INET, SOCK_DGRAM, 0); |
| 908 | if (s >= 0) { |
| 909 | struct ifreq ifr; |
| 910 | struct sockaddr_in saddr; |
| 911 | |
| 912 | memset(&ifr, 0, sizeof(ifr)); |
Peng Xu | b8fc5cc | 2017-05-10 17:27:28 -0700 | [diff] [blame] | 913 | strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 914 | if (ioctl(s, SIOCGIFADDR, &ifr) < 0) { |
| 915 | sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get " |
| 916 | "%s IP address: %s", |
| 917 | ifname, strerror(errno)); |
| 918 | } else { |
| 919 | memcpy(&saddr, &ifr.ifr_addr, |
| 920 | sizeof(struct sockaddr_in)); |
Peng Xu | b8fc5cc | 2017-05-10 17:27:28 -0700 | [diff] [blame] | 921 | strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip)); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 922 | } |
| 923 | |
| 924 | if (ioctl(s, SIOCGIFNETMASK, &ifr) == 0) { |
| 925 | memcpy(&saddr, &ifr.ifr_addr, |
| 926 | sizeof(struct sockaddr_in)); |
Peng Xu | b8fc5cc | 2017-05-10 17:27:28 -0700 | [diff] [blame] | 927 | strlcpy(mask, inet_ntoa(saddr.sin_addr), sizeof(mask)); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 928 | } |
| 929 | close(s); |
| 930 | } |
| 931 | |
| 932 | #ifdef ANDROID |
| 933 | snprintf(tmp, sizeof(tmp), "dhcp.%s.pid", ifname); |
| 934 | if (property_get(tmp, prop, NULL) != 0 && atoi(prop) > 0) { |
| 935 | snprintf(tmp, sizeof(tmp), "dhcp.%s.result", ifname); |
| 936 | if (property_get(tmp, prop, NULL) != 0 && |
| 937 | strcmp(prop, "ok") == 0) { |
| 938 | snprintf(tmp, sizeof(tmp), "dhcp.%s.ipaddress", |
| 939 | ifname); |
| 940 | if (property_get(tmp, prop, NULL) != 0 && |
| 941 | strcmp(ip, prop) == 0) |
| 942 | is_dhcp = 1; |
| 943 | } |
| 944 | } |
| 945 | |
| 946 | snprintf(tmp, sizeof(tmp), "dhcp.%s.dns1", ifname); |
Peng Xu | b8fc5cc | 2017-05-10 17:27:28 -0700 | [diff] [blame] | 947 | if (property_get(tmp, prop, NULL) != 0) |
| 948 | strlcpy(dns, prop, sizeof(dns)); |
| 949 | else if (property_get("net.dns1", prop, NULL) != 0) |
| 950 | strlcpy(dns, prop, sizeof(dns)); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 951 | |
| 952 | snprintf(tmp, sizeof(tmp), "dhcp.%s.dns2", ifname); |
Peng Xu | b8fc5cc | 2017-05-10 17:27:28 -0700 | [diff] [blame] | 953 | if (property_get(tmp, prop, NULL) != 0) |
| 954 | strlcpy(sec_dns, prop, sizeof(sec_dns)); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 955 | #else /* ANDROID */ |
| 956 | #ifdef __linux__ |
Sarvepalli, Rajesh Babu | a76c644 | 2016-03-18 20:34:26 +0530 | [diff] [blame] | 957 | if (get_driver_type() == DRIVER_OPENWRT) |
| 958 | str_ps = "ps -w"; |
| 959 | else |
| 960 | str_ps = "ps ax"; |
| 961 | snprintf(tmp, sizeof(tmp), |
| 962 | "%s | grep dhclient | grep -v grep | grep -q %s", |
| 963 | str_ps, ifname); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 964 | if (system(tmp) == 0) |
| 965 | is_dhcp = 1; |
| 966 | else { |
Sarvepalli, Rajesh Babu | a76c644 | 2016-03-18 20:34:26 +0530 | [diff] [blame] | 967 | snprintf(tmp, sizeof(tmp), |
| 968 | "%s | grep udhcpc | grep -v grep | grep -q %s", |
| 969 | str_ps, ifname); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 970 | if (system(tmp) == 0) |
| 971 | is_dhcp = 1; |
| 972 | else { |
Sarvepalli, Rajesh Babu | a76c644 | 2016-03-18 20:34:26 +0530 | [diff] [blame] | 973 | snprintf(tmp, sizeof(tmp), |
| 974 | "%s | grep dhcpcd | grep -v grep | grep -q %s", |
| 975 | str_ps, ifname); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 976 | if (system(tmp) == 0) |
| 977 | is_dhcp = 1; |
| 978 | } |
| 979 | } |
| 980 | #endif /* __linux__ */ |
| 981 | |
| 982 | f = fopen("/etc/resolv.conf", "r"); |
| 983 | if (f) { |
vamsi krishna | a11d073 | 2018-05-16 12:19:48 +0530 | [diff] [blame] | 984 | char *pos, *pos2; |
| 985 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 986 | while (fgets(tmp, sizeof(tmp), f)) { |
| 987 | if (strncmp(tmp, "nameserver", 10) != 0) |
| 988 | continue; |
| 989 | pos = tmp + 10; |
| 990 | while (*pos == ' ' || *pos == '\t') |
| 991 | pos++; |
| 992 | pos2 = pos; |
| 993 | while (*pos2) { |
| 994 | if (*pos2 == '\n' || *pos2 == '\r') { |
| 995 | *pos2 = '\0'; |
| 996 | break; |
| 997 | } |
| 998 | pos2++; |
| 999 | } |
Peng Xu | b8fc5cc | 2017-05-10 17:27:28 -0700 | [diff] [blame] | 1000 | if (!dns[0]) |
| 1001 | strlcpy(dns, pos, sizeof(dns)); |
| 1002 | else if (!sec_dns[0]) |
| 1003 | strlcpy(sec_dns, pos, sizeof(sec_dns)); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1004 | } |
| 1005 | fclose(f); |
| 1006 | } |
| 1007 | #endif /* ANDROID */ |
| 1008 | |
| 1009 | snprintf(buf, buf_len, "dhcp,%d,ip,%s,mask,%s,primary-dns,%s", |
| 1010 | is_dhcp, ip, mask, dns); |
| 1011 | buf[buf_len - 1] = '\0'; |
| 1012 | |
| 1013 | return 0; |
| 1014 | } |
| 1015 | |
| 1016 | |
| 1017 | |
| 1018 | |
| 1019 | int get_ipv6_config(struct sigma_dut *dut, const char *ifname, char *buf, |
| 1020 | size_t buf_len) |
| 1021 | { |
| 1022 | #ifdef __linux__ |
| 1023 | #ifdef ANDROID |
| 1024 | char cmd[200], result[1000], *pos, *end; |
| 1025 | FILE *f; |
| 1026 | size_t len; |
| 1027 | |
| 1028 | snprintf(cmd, sizeof(cmd), "ip addr show dev %s scope global", ifname); |
| 1029 | f = popen(cmd, "r"); |
| 1030 | if (f == NULL) |
| 1031 | return -1; |
| 1032 | len = fread(result, 1, sizeof(result) - 1, f); |
| 1033 | pclose(f); |
| 1034 | if (len == 0) |
| 1035 | return -1; |
| 1036 | result[len] = '\0'; |
| 1037 | sigma_dut_print(dut, DUT_MSG_DEBUG, "%s result: %s\n", cmd, result); |
| 1038 | |
| 1039 | pos = strstr(result, "inet6 "); |
| 1040 | if (pos == NULL) |
| 1041 | return -1; |
| 1042 | pos += 6; |
| 1043 | end = strchr(pos, ' '); |
| 1044 | if (end) |
| 1045 | *end = '\0'; |
| 1046 | end = strchr(pos, '/'); |
| 1047 | if (end) |
| 1048 | *end = '\0'; |
| 1049 | snprintf(buf, buf_len, "ip,%s", pos); |
| 1050 | buf[buf_len - 1] = '\0'; |
| 1051 | return 0; |
| 1052 | #else /* ANDROID */ |
| 1053 | struct ifaddrs *ifaddr, *ifa; |
| 1054 | int res, found = 0; |
| 1055 | char host[NI_MAXHOST]; |
| 1056 | |
| 1057 | if (getifaddrs(&ifaddr) < 0) { |
| 1058 | perror("getifaddrs"); |
| 1059 | return -1; |
| 1060 | } |
| 1061 | |
| 1062 | for (ifa = ifaddr; ifa; ifa = ifa->ifa_next) { |
| 1063 | if (strcasecmp(ifname, ifa->ifa_name) != 0) |
| 1064 | continue; |
| 1065 | if (ifa->ifa_addr == NULL || |
| 1066 | ifa->ifa_addr->sa_family != AF_INET6) |
| 1067 | continue; |
| 1068 | |
| 1069 | res = getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in6), |
| 1070 | host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST); |
| 1071 | if (res != 0) { |
| 1072 | sigma_dut_print(dut, DUT_MSG_DEBUG, "getnameinfo: %s", |
| 1073 | gai_strerror(res)); |
| 1074 | continue; |
| 1075 | } |
| 1076 | if (strncmp(host, "fe80::", 6) == 0) |
| 1077 | continue; /* skip link-local */ |
| 1078 | |
| 1079 | sigma_dut_print(dut, DUT_MSG_DEBUG, "ifaddr: %s", host); |
| 1080 | found = 1; |
| 1081 | break; |
| 1082 | } |
| 1083 | |
| 1084 | freeifaddrs(ifaddr); |
| 1085 | |
| 1086 | if (found) { |
| 1087 | char *pos; |
| 1088 | pos = strchr(host, '%'); |
| 1089 | if (pos) |
| 1090 | *pos = '\0'; |
| 1091 | snprintf(buf, buf_len, "ip,%s", host); |
| 1092 | buf[buf_len - 1] = '\0'; |
| 1093 | return 0; |
| 1094 | } |
| 1095 | |
| 1096 | #endif /* ANDROID */ |
| 1097 | #endif /* __linux__ */ |
| 1098 | return -1; |
| 1099 | } |
| 1100 | |
| 1101 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 1102 | static enum sigma_cmd_result cmd_sta_get_ip_config(struct sigma_dut *dut, |
| 1103 | struct sigma_conn *conn, |
| 1104 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1105 | { |
| 1106 | const char *intf = get_param(cmd, "Interface"); |
| 1107 | const char *ifname; |
| 1108 | char buf[200]; |
| 1109 | const char *val; |
| 1110 | int type = 1; |
| 1111 | |
| 1112 | if (intf == NULL) |
| 1113 | return -1; |
| 1114 | |
| 1115 | if (strcmp(intf, get_main_ifname()) == 0) |
| 1116 | ifname = get_station_ifname(); |
| 1117 | else |
| 1118 | ifname = intf; |
| 1119 | |
| 1120 | /* |
| 1121 | * UCC may assume the IP address to be available immediately after |
| 1122 | * association without trying to run sta_get_ip_config multiple times. |
| 1123 | * Sigma CAPI does not specify this command as a block command that |
| 1124 | * would wait for the address to become available, but to pass tests |
| 1125 | * more reliably, it looks like such a wait may be needed here. |
| 1126 | */ |
| 1127 | if (wait_ip_addr(dut, ifname, 15) < 0) { |
| 1128 | sigma_dut_print(dut, DUT_MSG_INFO, "Could not get IP address " |
| 1129 | "for sta_get_ip_config"); |
| 1130 | /* |
| 1131 | * Try to continue anyway since many UCC tests do not really |
| 1132 | * care about the return value from here.. |
| 1133 | */ |
| 1134 | } |
| 1135 | |
| 1136 | val = get_param(cmd, "Type"); |
| 1137 | if (val) |
| 1138 | type = atoi(val); |
| 1139 | if (type == 2 || dut->last_set_ip_config_ipv6) { |
| 1140 | int i; |
| 1141 | |
| 1142 | /* |
| 1143 | * Since we do not have proper wait for IPv6 addresses, use a |
| 1144 | * fixed two second delay here as a workaround for UCC script |
| 1145 | * assuming IPv6 address is available when this command returns. |
| 1146 | * Some scripts did not use Type,2 properly for IPv6, so include |
| 1147 | * also the cases where the previous sta_set_ip_config indicated |
| 1148 | * use of IPv6. |
| 1149 | */ |
| 1150 | sigma_dut_print(dut, DUT_MSG_INFO, "Wait up to extra ten seconds in sta_get_ip_config for IPv6 address"); |
| 1151 | for (i = 0; i < 10; i++) { |
| 1152 | sleep(1); |
| 1153 | if (get_ipv6_config(dut, ifname, buf, sizeof(buf)) == 0) |
| 1154 | { |
| 1155 | sigma_dut_print(dut, DUT_MSG_INFO, "Found IPv6 address"); |
| 1156 | send_resp(dut, conn, SIGMA_COMPLETE, buf); |
| 1157 | #ifdef ANDROID |
| 1158 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 1159 | "Adding IPv6 rule on Android"); |
| 1160 | add_ipv6_rule(dut, intf); |
| 1161 | #endif /* ANDROID */ |
| 1162 | |
| 1163 | return 0; |
| 1164 | } |
| 1165 | } |
| 1166 | } |
| 1167 | if (type == 1) { |
| 1168 | if (get_ip_config(dut, ifname, buf, sizeof(buf)) < 0) |
| 1169 | return -2; |
| 1170 | } else if (type == 2) { |
| 1171 | if (get_ipv6_config(dut, ifname, buf, sizeof(buf)) < 0) |
| 1172 | return -2; |
| 1173 | } else { |
| 1174 | send_resp(dut, conn, SIGMA_ERROR, |
| 1175 | "errorCode,Unsupported address type"); |
| 1176 | return 0; |
| 1177 | } |
| 1178 | |
| 1179 | send_resp(dut, conn, SIGMA_COMPLETE, buf); |
| 1180 | return 0; |
| 1181 | } |
| 1182 | |
| 1183 | |
| 1184 | static void kill_dhcp_client(struct sigma_dut *dut, const char *ifname) |
| 1185 | { |
| 1186 | #ifdef __linux__ |
| 1187 | char buf[200]; |
| 1188 | char path[128]; |
| 1189 | struct stat s; |
| 1190 | |
| 1191 | #ifdef ANDROID |
| 1192 | snprintf(path, sizeof(path), "/data/misc/dhcp/dhcpcd-%s.pid", ifname); |
| 1193 | #else /* ANDROID */ |
| 1194 | snprintf(path, sizeof(path), "/var/run/dhclient-%s.pid", ifname); |
| 1195 | #endif /* ANDROID */ |
| 1196 | if (stat(path, &s) == 0) { |
| 1197 | snprintf(buf, sizeof(buf), "kill `cat %s`", path); |
| 1198 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 1199 | "Kill previous DHCP client: %s", buf); |
| 1200 | if (system(buf) != 0) |
| 1201 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 1202 | "Failed to kill DHCP client"); |
| 1203 | unlink(path); |
| 1204 | sleep(1); |
| 1205 | } else { |
| 1206 | snprintf(path, sizeof(path), "/var/run/dhcpcd-%s.pid", ifname); |
| 1207 | |
| 1208 | if (stat(path, &s) == 0) { |
| 1209 | snprintf(buf, sizeof(buf), "kill `cat %s`", path); |
| 1210 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 1211 | "Kill previous DHCP client: %s", buf); |
| 1212 | if (system(buf) != 0) |
| 1213 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 1214 | "Failed to kill DHCP client"); |
| 1215 | unlink(path); |
| 1216 | sleep(1); |
| 1217 | } |
| 1218 | } |
| 1219 | #endif /* __linux__ */ |
| 1220 | } |
| 1221 | |
| 1222 | |
| 1223 | static int start_dhcp_client(struct sigma_dut *dut, const char *ifname) |
| 1224 | { |
| 1225 | #ifdef __linux__ |
| 1226 | char buf[200]; |
| 1227 | |
| 1228 | #ifdef ANDROID |
Purushottam Kushwaha | 46d6426 | 2016-08-23 17:57:53 +0530 | [diff] [blame] | 1229 | if (access("/system/bin/dhcpcd", F_OK) != -1) { |
| 1230 | snprintf(buf, sizeof(buf), |
| 1231 | "/system/bin/dhcpcd -b %s", ifname); |
| 1232 | } else if (access("/system/bin/dhcptool", F_OK) != -1) { |
| 1233 | snprintf(buf, sizeof(buf), "/system/bin/dhcptool %s &", ifname); |
Ankita Bajaj | 8454e5d | 2019-04-05 16:04:55 +0530 | [diff] [blame] | 1234 | } else if (access("/vendor/bin/dhcpcd", F_OK) != -1) { |
| 1235 | snprintf(buf, sizeof(buf), "/vendor/bin/dhcpcd -b %s", ifname); |
| 1236 | } else if (access("/vendor/bin/dhcptool", F_OK) != -1) { |
| 1237 | snprintf(buf, sizeof(buf), "/vendor/bin/dhcptool %s", ifname); |
Purushottam Kushwaha | 46d6426 | 2016-08-23 17:57:53 +0530 | [diff] [blame] | 1238 | } else { |
| 1239 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 1240 | "DHCP client program missing"); |
| 1241 | return 0; |
| 1242 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1243 | #else /* ANDROID */ |
| 1244 | snprintf(buf, sizeof(buf), |
| 1245 | "dhclient -nw -pf /var/run/dhclient-%s.pid %s", |
| 1246 | ifname, ifname); |
| 1247 | #endif /* ANDROID */ |
| 1248 | sigma_dut_print(dut, DUT_MSG_INFO, "Start DHCP client: %s", buf); |
| 1249 | if (system(buf) != 0) { |
| 1250 | snprintf(buf, sizeof(buf), "dhcpcd -t 0 %s &", ifname); |
| 1251 | if (system(buf) != 0) { |
| 1252 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 1253 | "Failed to start DHCP client"); |
| 1254 | #ifndef ANDROID |
| 1255 | return -1; |
| 1256 | #endif /* ANDROID */ |
| 1257 | } |
| 1258 | } |
| 1259 | #endif /* __linux__ */ |
| 1260 | |
| 1261 | return 0; |
| 1262 | } |
| 1263 | |
| 1264 | |
| 1265 | static int clear_ip_addr(struct sigma_dut *dut, const char *ifname) |
| 1266 | { |
| 1267 | #ifdef __linux__ |
| 1268 | char buf[200]; |
| 1269 | |
| 1270 | snprintf(buf, sizeof(buf), "ip addr flush dev %s", ifname); |
| 1271 | if (system(buf) != 0) { |
| 1272 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 1273 | "Failed to clear IP addresses"); |
| 1274 | return -1; |
| 1275 | } |
| 1276 | #endif /* __linux__ */ |
| 1277 | |
| 1278 | return 0; |
| 1279 | } |
| 1280 | |
| 1281 | |
| 1282 | #ifdef ANDROID |
| 1283 | static int add_ipv6_rule(struct sigma_dut *dut, const char *ifname) |
| 1284 | { |
| 1285 | char cmd[200], *result, *pos; |
| 1286 | FILE *fp; |
Pradeep Reddy POTTETI | f58a1fe | 2016-10-13 17:22:03 +0530 | [diff] [blame] | 1287 | int tableid; |
| 1288 | size_t len, result_len = 1000; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1289 | |
| 1290 | snprintf(cmd, sizeof(cmd), "ip -6 route list table all | grep %s", |
| 1291 | ifname); |
| 1292 | fp = popen(cmd, "r"); |
| 1293 | if (fp == NULL) |
| 1294 | return -1; |
| 1295 | |
| 1296 | result = malloc(result_len); |
Pradeep Reddy POTTETI | 673d85c | 2016-07-26 19:08:07 +0530 | [diff] [blame] | 1297 | if (result == NULL) { |
| 1298 | fclose(fp); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1299 | return -1; |
Pradeep Reddy POTTETI | 673d85c | 2016-07-26 19:08:07 +0530 | [diff] [blame] | 1300 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1301 | |
Pradeep Reddy POTTETI | f58a1fe | 2016-10-13 17:22:03 +0530 | [diff] [blame] | 1302 | len = fread(result, 1, result_len - 1, fp); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1303 | fclose(fp); |
| 1304 | |
| 1305 | if (len == 0) { |
| 1306 | free(result); |
| 1307 | return -1; |
| 1308 | } |
Pradeep Reddy POTTETI | f58a1fe | 2016-10-13 17:22:03 +0530 | [diff] [blame] | 1309 | result[len] = '\0'; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1310 | |
| 1311 | pos = strstr(result, "table "); |
| 1312 | if (pos == NULL) { |
| 1313 | free(result); |
| 1314 | return -1; |
| 1315 | } |
| 1316 | |
| 1317 | pos += strlen("table "); |
| 1318 | tableid = atoi(pos); |
| 1319 | if (tableid != 0) { |
| 1320 | if (system("ip -6 rule del prio 22000") != 0) { |
| 1321 | /* ignore any error */ |
| 1322 | } |
| 1323 | snprintf(cmd, sizeof(cmd), |
| 1324 | "ip -6 rule add from all lookup %d prio 22000", |
| 1325 | tableid); |
| 1326 | if (system(cmd) != 0) { |
| 1327 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 1328 | "Failed to run %s", cmd); |
| 1329 | free(result); |
| 1330 | return -1; |
| 1331 | } |
| 1332 | } else { |
| 1333 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 1334 | "No Valid Table Id found %s", pos); |
| 1335 | free(result); |
| 1336 | return -1; |
| 1337 | } |
| 1338 | free(result); |
| 1339 | |
| 1340 | return 0; |
| 1341 | } |
| 1342 | #endif /* ANDROID */ |
| 1343 | |
| 1344 | |
Ankita Bajaj | 1bde794 | 2018-01-09 19:15:01 +0530 | [diff] [blame] | 1345 | int set_ipv4_addr(struct sigma_dut *dut, const char *ifname, |
| 1346 | const char *ip, const char *mask) |
| 1347 | { |
| 1348 | char buf[200]; |
| 1349 | |
| 1350 | snprintf(buf, sizeof(buf), "ifconfig %s %s netmask %s", |
| 1351 | ifname, ip, mask); |
| 1352 | return system(buf) == 0; |
| 1353 | } |
| 1354 | |
| 1355 | |
| 1356 | int set_ipv4_gw(struct sigma_dut *dut, const char *gw) |
| 1357 | { |
| 1358 | char buf[200]; |
| 1359 | |
| 1360 | if (!is_ip_addr(gw)) { |
| 1361 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Invalid gw addr - %s", gw); |
| 1362 | return -1; |
| 1363 | } |
| 1364 | |
| 1365 | snprintf(buf, sizeof(buf), "route add default gw %s", gw); |
| 1366 | if (!dut->no_ip_addr_set && system(buf) != 0) { |
| 1367 | snprintf(buf, sizeof(buf), "ip ro re default via %s", |
| 1368 | gw); |
| 1369 | if (system(buf) != 0) |
| 1370 | return 0; |
| 1371 | } |
| 1372 | |
| 1373 | return 1; |
| 1374 | } |
| 1375 | |
| 1376 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 1377 | static enum sigma_cmd_result cmd_sta_set_ip_config(struct sigma_dut *dut, |
| 1378 | struct sigma_conn *conn, |
| 1379 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1380 | { |
| 1381 | const char *intf = get_param(cmd, "Interface"); |
| 1382 | const char *ifname; |
| 1383 | char buf[200]; |
| 1384 | const char *val, *ip, *mask, *gw; |
| 1385 | int type = 1; |
| 1386 | |
| 1387 | if (intf == NULL) |
| 1388 | return -1; |
| 1389 | |
| 1390 | if (strcmp(intf, get_main_ifname()) == 0) |
| 1391 | ifname = get_station_ifname(); |
| 1392 | else |
| 1393 | ifname = intf; |
| 1394 | |
| 1395 | if (if_nametoindex(ifname) == 0) { |
| 1396 | send_resp(dut, conn, SIGMA_ERROR, |
| 1397 | "ErrorCode,Unknown interface"); |
| 1398 | return 0; |
| 1399 | } |
| 1400 | |
| 1401 | val = get_param(cmd, "Type"); |
| 1402 | if (val) { |
| 1403 | type = atoi(val); |
Ankita Bajaj | 1bde794 | 2018-01-09 19:15:01 +0530 | [diff] [blame] | 1404 | if (type < 1 || type > 3) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1405 | send_resp(dut, conn, SIGMA_ERROR, |
| 1406 | "ErrorCode,Unsupported address type"); |
| 1407 | return 0; |
| 1408 | } |
| 1409 | } |
| 1410 | |
| 1411 | dut->last_set_ip_config_ipv6 = 0; |
| 1412 | |
| 1413 | val = get_param(cmd, "dhcp"); |
| 1414 | if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "true") == 0)) { |
| 1415 | static_ip_file(0, NULL, NULL, NULL); |
| 1416 | #ifdef __linux__ |
| 1417 | if (type == 2) { |
| 1418 | dut->last_set_ip_config_ipv6 = 1; |
| 1419 | sigma_dut_print(dut, DUT_MSG_INFO, "Using IPv6 " |
| 1420 | "stateless address autoconfiguration"); |
| 1421 | #ifdef ANDROID |
| 1422 | /* |
| 1423 | * This sleep is required as the assignment in case of |
| 1424 | * Android is taking time and is done by the kernel. |
| 1425 | * The subsequent ping for IPv6 is impacting HS20 test |
| 1426 | * case. |
| 1427 | */ |
| 1428 | sleep(2); |
| 1429 | add_ipv6_rule(dut, intf); |
| 1430 | #endif /* ANDROID */ |
| 1431 | /* Assume this happens by default */ |
| 1432 | return 1; |
| 1433 | } |
Ankita Bajaj | 1bde794 | 2018-01-09 19:15:01 +0530 | [diff] [blame] | 1434 | if (type != 3) { |
| 1435 | kill_dhcp_client(dut, ifname); |
| 1436 | if (start_dhcp_client(dut, ifname) < 0) |
| 1437 | return -2; |
| 1438 | } else { |
| 1439 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 1440 | "Using FILS HLP DHCPv4 Rapid Commit"); |
| 1441 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1442 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1443 | return 1; |
| 1444 | #endif /* __linux__ */ |
| 1445 | return -2; |
| 1446 | } |
| 1447 | |
| 1448 | ip = get_param(cmd, "ip"); |
Pradeep Reddy POTTETI | b18c565 | 2016-01-18 12:45:37 +0530 | [diff] [blame] | 1449 | if (!ip) { |
| 1450 | send_resp(dut, conn, SIGMA_INVALID, |
| 1451 | "ErrorCode,Missing IP address"); |
| 1452 | return 0; |
| 1453 | } |
| 1454 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1455 | mask = get_param(cmd, "mask"); |
Pradeep Reddy POTTETI | b18c565 | 2016-01-18 12:45:37 +0530 | [diff] [blame] | 1456 | if (!mask) { |
| 1457 | send_resp(dut, conn, SIGMA_INVALID, |
| 1458 | "ErrorCode,Missing subnet mask"); |
| 1459 | return 0; |
| 1460 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1461 | |
| 1462 | if (type == 2) { |
| 1463 | int net = atoi(mask); |
| 1464 | |
| 1465 | if ((net < 0 && net > 64) || !is_ipv6_addr(ip)) |
| 1466 | return -1; |
| 1467 | |
| 1468 | if (dut->no_ip_addr_set) { |
| 1469 | snprintf(buf, sizeof(buf), |
| 1470 | "sysctl net.ipv6.conf.%s.disable_ipv6=1", |
| 1471 | ifname); |
| 1472 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 1473 | if (system(buf) != 0) { |
| 1474 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 1475 | "Failed to disable IPv6 address before association"); |
| 1476 | } |
| 1477 | } else { |
| 1478 | snprintf(buf, sizeof(buf), |
| 1479 | "ip -6 addr del %s/%s dev %s", |
| 1480 | ip, mask, ifname); |
| 1481 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 1482 | if (system(buf) != 0) { |
| 1483 | /* |
| 1484 | * This command may fail if the address being |
| 1485 | * deleted does not exist. Inaction here is |
| 1486 | * intentional. |
| 1487 | */ |
| 1488 | } |
| 1489 | |
| 1490 | snprintf(buf, sizeof(buf), |
| 1491 | "ip -6 addr add %s/%s dev %s", |
| 1492 | ip, mask, ifname); |
| 1493 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 1494 | if (system(buf) != 0) { |
| 1495 | send_resp(dut, conn, SIGMA_ERROR, |
| 1496 | "ErrorCode,Failed to set IPv6 address"); |
| 1497 | return 0; |
| 1498 | } |
| 1499 | } |
| 1500 | |
| 1501 | dut->last_set_ip_config_ipv6 = 1; |
| 1502 | static_ip_file(6, ip, mask, NULL); |
| 1503 | return 1; |
| 1504 | } else if (type == 1) { |
Pradeep Reddy POTTETI | b18c565 | 2016-01-18 12:45:37 +0530 | [diff] [blame] | 1505 | if (!is_ip_addr(ip) || !is_ip_addr(mask)) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1506 | return -1; |
| 1507 | } |
| 1508 | |
| 1509 | kill_dhcp_client(dut, ifname); |
| 1510 | |
| 1511 | if (!dut->no_ip_addr_set) { |
Ankita Bajaj | 1bde794 | 2018-01-09 19:15:01 +0530 | [diff] [blame] | 1512 | if (!set_ipv4_addr(dut, ifname, ip, mask)) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1513 | send_resp(dut, conn, SIGMA_ERROR, |
| 1514 | "ErrorCode,Failed to set IP address"); |
| 1515 | return 0; |
| 1516 | } |
| 1517 | } |
| 1518 | |
| 1519 | gw = get_param(cmd, "defaultGateway"); |
| 1520 | if (gw) { |
Ankita Bajaj | 1bde794 | 2018-01-09 19:15:01 +0530 | [diff] [blame] | 1521 | if (set_ipv4_gw(dut, gw) < 1) { |
| 1522 | send_resp(dut, conn, SIGMA_ERROR, |
| 1523 | "ErrorCode,Failed to set default gateway"); |
| 1524 | return 0; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1525 | } |
| 1526 | } |
| 1527 | |
| 1528 | val = get_param(cmd, "primary-dns"); |
| 1529 | if (val) { |
| 1530 | /* TODO */ |
| 1531 | sigma_dut_print(dut, DUT_MSG_INFO, "Ignored primary-dns %s " |
| 1532 | "setting", val); |
| 1533 | } |
| 1534 | |
| 1535 | val = get_param(cmd, "secondary-dns"); |
| 1536 | if (val) { |
| 1537 | /* TODO */ |
| 1538 | sigma_dut_print(dut, DUT_MSG_INFO, "Ignored secondary-dns %s " |
| 1539 | "setting", val); |
| 1540 | } |
| 1541 | |
| 1542 | static_ip_file(4, ip, mask, gw); |
| 1543 | |
| 1544 | return 1; |
| 1545 | } |
| 1546 | |
| 1547 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 1548 | static enum sigma_cmd_result cmd_sta_get_info(struct sigma_dut *dut, |
| 1549 | struct sigma_conn *conn, |
| 1550 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1551 | { |
| 1552 | /* const char *intf = get_param(cmd, "Interface"); */ |
| 1553 | /* TODO: could report more details here */ |
| 1554 | send_resp(dut, conn, SIGMA_COMPLETE, "vendor,Atheros"); |
| 1555 | return 0; |
| 1556 | } |
| 1557 | |
| 1558 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 1559 | static enum sigma_cmd_result cmd_sta_get_mac_address(struct sigma_dut *dut, |
| 1560 | struct sigma_conn *conn, |
| 1561 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1562 | { |
| 1563 | /* const char *intf = get_param(cmd, "Interface"); */ |
| 1564 | char addr[20], resp[50]; |
| 1565 | |
Ankita Bajaj | 0d5825b | 2017-10-25 16:20:17 +0530 | [diff] [blame] | 1566 | if (dut->dev_role == DEVROLE_STA_CFON) |
| 1567 | return sta_cfon_get_mac_address(dut, conn, cmd); |
| 1568 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1569 | if (get_wpa_status(get_station_ifname(), "address", addr, sizeof(addr)) |
| 1570 | < 0) |
| 1571 | return -2; |
| 1572 | |
| 1573 | snprintf(resp, sizeof(resp), "mac,%s", addr); |
| 1574 | send_resp(dut, conn, SIGMA_COMPLETE, resp); |
| 1575 | return 0; |
| 1576 | } |
| 1577 | |
| 1578 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 1579 | static enum sigma_cmd_result cmd_sta_is_connected(struct sigma_dut *dut, |
| 1580 | struct sigma_conn *conn, |
| 1581 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1582 | { |
| 1583 | /* const char *intf = get_param(cmd, "Interface"); */ |
| 1584 | int connected = 0; |
| 1585 | char result[32]; |
| 1586 | if (get_wpa_status(get_station_ifname(), "wpa_state", result, |
| 1587 | sizeof(result)) < 0) { |
| 1588 | sigma_dut_print(dut, DUT_MSG_INFO, "Could not get interface " |
| 1589 | "%s status", get_station_ifname()); |
| 1590 | return -2; |
| 1591 | } |
| 1592 | |
| 1593 | sigma_dut_print(dut, DUT_MSG_DEBUG, "wpa_state=%s", result); |
| 1594 | if (strncmp(result, "COMPLETED", 9) == 0) |
| 1595 | connected = 1; |
| 1596 | |
| 1597 | if (connected) |
| 1598 | send_resp(dut, conn, SIGMA_COMPLETE, "connected,1"); |
| 1599 | else |
| 1600 | send_resp(dut, conn, SIGMA_COMPLETE, "connected,0"); |
| 1601 | |
| 1602 | return 0; |
| 1603 | } |
| 1604 | |
| 1605 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 1606 | static enum sigma_cmd_result |
| 1607 | cmd_sta_verify_ip_connection(struct sigma_dut *dut, struct sigma_conn *conn, |
| 1608 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1609 | { |
| 1610 | /* const char *intf = get_param(cmd, "Interface"); */ |
| 1611 | const char *dst, *timeout; |
| 1612 | int wait_time = 90; |
| 1613 | char buf[100]; |
| 1614 | int res; |
| 1615 | |
| 1616 | dst = get_param(cmd, "destination"); |
| 1617 | if (dst == NULL || !is_ip_addr(dst)) |
| 1618 | return -1; |
| 1619 | |
| 1620 | timeout = get_param(cmd, "timeout"); |
| 1621 | if (timeout) { |
| 1622 | wait_time = atoi(timeout); |
| 1623 | if (wait_time < 1) |
| 1624 | wait_time = 1; |
| 1625 | } |
| 1626 | |
| 1627 | /* TODO: force renewal of IP lease if DHCP is enabled */ |
| 1628 | |
| 1629 | snprintf(buf, sizeof(buf), "ping %s -c 3 -W %d", dst, wait_time); |
| 1630 | res = system(buf); |
| 1631 | sigma_dut_print(dut, DUT_MSG_DEBUG, "ping returned: %d", res); |
| 1632 | if (res == 0) |
| 1633 | send_resp(dut, conn, SIGMA_COMPLETE, "connected,1"); |
| 1634 | else if (res == 256) |
| 1635 | send_resp(dut, conn, SIGMA_COMPLETE, "connected,0"); |
| 1636 | else |
| 1637 | return -2; |
| 1638 | |
| 1639 | return 0; |
| 1640 | } |
| 1641 | |
| 1642 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 1643 | static enum sigma_cmd_result cmd_sta_get_bssid(struct sigma_dut *dut, |
| 1644 | struct sigma_conn *conn, |
| 1645 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1646 | { |
| 1647 | /* const char *intf = get_param(cmd, "Interface"); */ |
| 1648 | char bssid[20], resp[50]; |
| 1649 | |
| 1650 | if (get_wpa_status(get_station_ifname(), "bssid", bssid, sizeof(bssid)) |
| 1651 | < 0) |
Peng Xu | b8fc5cc | 2017-05-10 17:27:28 -0700 | [diff] [blame] | 1652 | strlcpy(bssid, "00:00:00:00:00:00", sizeof(bssid)); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1653 | |
| 1654 | snprintf(resp, sizeof(resp), "bssid,%s", bssid); |
| 1655 | send_resp(dut, conn, SIGMA_COMPLETE, resp); |
| 1656 | return 0; |
| 1657 | } |
| 1658 | |
| 1659 | |
| 1660 | #ifdef __SAMSUNG__ |
| 1661 | static int add_use_network(const char *ifname) |
| 1662 | { |
| 1663 | char buf[100]; |
| 1664 | |
| 1665 | snprintf(buf, sizeof(buf), "USE_NETWORK ON"); |
| 1666 | wpa_command(ifname, buf); |
| 1667 | return 0; |
| 1668 | } |
| 1669 | #endif /* __SAMSUNG__ */ |
| 1670 | |
| 1671 | |
| 1672 | static int add_network_common(struct sigma_dut *dut, struct sigma_conn *conn, |
| 1673 | const char *ifname, struct sigma_cmd *cmd) |
| 1674 | { |
| 1675 | const char *ssid = get_param(cmd, "ssid"); |
| 1676 | int id; |
| 1677 | const char *val; |
| 1678 | |
| 1679 | if (ssid == NULL) |
| 1680 | return -1; |
| 1681 | |
| 1682 | start_sta_mode(dut); |
| 1683 | |
| 1684 | #ifdef __SAMSUNG__ |
| 1685 | add_use_network(ifname); |
| 1686 | #endif /* __SAMSUNG__ */ |
| 1687 | |
| 1688 | id = add_network(ifname); |
| 1689 | if (id < 0) |
| 1690 | return -2; |
| 1691 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding network %d", id); |
| 1692 | |
| 1693 | if (set_network_quoted(ifname, id, "ssid", ssid) < 0) |
| 1694 | return -2; |
| 1695 | |
| 1696 | dut->infra_network_id = id; |
| 1697 | snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid); |
| 1698 | |
| 1699 | val = get_param(cmd, "program"); |
| 1700 | if (!val) |
| 1701 | val = get_param(cmd, "prog"); |
| 1702 | if (val && strcasecmp(val, "hs2") == 0) { |
| 1703 | char buf[100]; |
| 1704 | snprintf(buf, sizeof(buf), "ENABLE_NETWORK %d no-connect", id); |
| 1705 | wpa_command(ifname, buf); |
| 1706 | |
| 1707 | val = get_param(cmd, "prefer"); |
| 1708 | if (val && atoi(val) > 0) |
| 1709 | set_network(ifname, id, "priority", "1"); |
| 1710 | } |
| 1711 | |
| 1712 | return id; |
| 1713 | } |
| 1714 | |
| 1715 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 1716 | static enum sigma_cmd_result cmd_sta_set_encryption(struct sigma_dut *dut, |
| 1717 | struct sigma_conn *conn, |
| 1718 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1719 | { |
| 1720 | const char *intf = get_param(cmd, "Interface"); |
| 1721 | const char *ssid = get_param(cmd, "ssid"); |
| 1722 | const char *type = get_param(cmd, "encpType"); |
| 1723 | const char *ifname; |
| 1724 | char buf[200]; |
| 1725 | int id; |
| 1726 | |
| 1727 | if (intf == NULL || ssid == NULL) |
| 1728 | return -1; |
| 1729 | |
| 1730 | if (strcmp(intf, get_main_ifname()) == 0) |
| 1731 | ifname = get_station_ifname(); |
| 1732 | else |
| 1733 | ifname = intf; |
| 1734 | |
| 1735 | id = add_network_common(dut, conn, ifname, cmd); |
| 1736 | if (id < 0) |
| 1737 | return id; |
| 1738 | |
| 1739 | if (set_network(ifname, id, "key_mgmt", "NONE") < 0) |
| 1740 | return -2; |
| 1741 | |
| 1742 | if (type && strcasecmp(type, "wep") == 0) { |
| 1743 | const char *val; |
| 1744 | int i; |
| 1745 | |
| 1746 | val = get_param(cmd, "activeKey"); |
| 1747 | if (val) { |
| 1748 | int keyid; |
| 1749 | keyid = atoi(val); |
| 1750 | if (keyid < 1 || keyid > 4) |
| 1751 | return -1; |
| 1752 | snprintf(buf, sizeof(buf), "%d", keyid - 1); |
| 1753 | if (set_network(ifname, id, "wep_tx_keyidx", buf) < 0) |
| 1754 | return -2; |
| 1755 | } |
| 1756 | |
| 1757 | for (i = 0; i < 4; i++) { |
| 1758 | snprintf(buf, sizeof(buf), "key%d", i + 1); |
| 1759 | val = get_param(cmd, buf); |
| 1760 | if (val == NULL) |
| 1761 | continue; |
| 1762 | snprintf(buf, sizeof(buf), "wep_key%d", i); |
| 1763 | if (set_network(ifname, id, buf, val) < 0) |
| 1764 | return -2; |
| 1765 | } |
| 1766 | } |
| 1767 | |
| 1768 | return 1; |
| 1769 | } |
| 1770 | |
| 1771 | |
Jouni Malinen | e4fde73 | 2019-03-25 22:29:37 +0200 | [diff] [blame] | 1772 | static int set_akm_suites(struct sigma_dut *dut, const char *ifname, |
| 1773 | int id, const char *val) |
| 1774 | { |
| 1775 | char key_mgmt[200], *end, *pos; |
| 1776 | const char *in_pos = val; |
| 1777 | |
Jouni Malinen | 8179fee | 2019-03-28 03:19:47 +0200 | [diff] [blame] | 1778 | dut->akm_values = 0; |
Jouni Malinen | e4fde73 | 2019-03-25 22:29:37 +0200 | [diff] [blame] | 1779 | pos = key_mgmt; |
| 1780 | end = pos + sizeof(key_mgmt); |
| 1781 | while (*in_pos) { |
| 1782 | int res, akm = atoi(in_pos); |
| 1783 | const char *str; |
| 1784 | |
Jouni Malinen | 8179fee | 2019-03-28 03:19:47 +0200 | [diff] [blame] | 1785 | if (akm >= 0 && akm < 32) |
| 1786 | dut->akm_values |= 1 << akm; |
| 1787 | |
Jouni Malinen | e4fde73 | 2019-03-25 22:29:37 +0200 | [diff] [blame] | 1788 | switch (akm) { |
| 1789 | case AKM_WPA_EAP: |
| 1790 | str = "WPA-EAP"; |
| 1791 | break; |
| 1792 | case AKM_WPA_PSK: |
| 1793 | str = "WPA-PSK"; |
| 1794 | break; |
| 1795 | case AKM_FT_EAP: |
| 1796 | str = "FT-EAP"; |
| 1797 | break; |
| 1798 | case AKM_FT_PSK: |
| 1799 | str = "FT-PSK"; |
| 1800 | break; |
| 1801 | case AKM_EAP_SHA256: |
| 1802 | str = "WPA-EAP-SHA256"; |
| 1803 | break; |
| 1804 | case AKM_PSK_SHA256: |
| 1805 | str = "WPA-PSK-SHA256"; |
| 1806 | break; |
| 1807 | case AKM_SAE: |
| 1808 | str = "SAE"; |
| 1809 | break; |
| 1810 | case AKM_FT_SAE: |
| 1811 | str = "FT-SAE"; |
| 1812 | break; |
| 1813 | case AKM_SUITE_B: |
| 1814 | str = "WPA-EAP-SUITE-B-192"; |
| 1815 | break; |
| 1816 | case AKM_FT_SUITE_B: |
| 1817 | str = "FT-EAP-SHA384"; |
| 1818 | break; |
| 1819 | case AKM_FILS_SHA256: |
| 1820 | str = "FILS-SHA256"; |
| 1821 | break; |
| 1822 | case AKM_FILS_SHA384: |
| 1823 | str = "FILS-SHA384"; |
| 1824 | break; |
| 1825 | case AKM_FT_FILS_SHA256: |
| 1826 | str = "FT-FILS-SHA256"; |
| 1827 | break; |
| 1828 | case AKM_FT_FILS_SHA384: |
| 1829 | str = "FT-FILS-SHA384"; |
| 1830 | break; |
| 1831 | default: |
| 1832 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 1833 | "Unsupported AKMSuitetype %d", akm); |
| 1834 | return -1; |
| 1835 | } |
| 1836 | |
| 1837 | res = snprintf(pos, end - pos, "%s%s", |
| 1838 | pos == key_mgmt ? "" : " ", str); |
| 1839 | if (res < 0 || res >= end - pos) |
| 1840 | return -1; |
| 1841 | pos += res; |
| 1842 | |
| 1843 | in_pos = strchr(in_pos, ';'); |
| 1844 | if (!in_pos) |
| 1845 | break; |
| 1846 | while (*in_pos == ';') |
| 1847 | in_pos++; |
| 1848 | } |
| 1849 | sigma_dut_print(dut, DUT_MSG_DEBUG, "AKMSuiteType %s --> %s", |
| 1850 | val, key_mgmt); |
| 1851 | return set_network(ifname, id, "key_mgmt", key_mgmt); |
| 1852 | } |
| 1853 | |
| 1854 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1855 | static int set_wpa_common(struct sigma_dut *dut, struct sigma_conn *conn, |
| 1856 | const char *ifname, struct sigma_cmd *cmd) |
| 1857 | { |
| 1858 | const char *val; |
| 1859 | int id; |
Jouni Malinen | ad395a2 | 2017-09-01 21:13:46 +0300 | [diff] [blame] | 1860 | int cipher_set = 0; |
Jouni Malinen | 47dcc95 | 2017-10-09 16:43:24 +0300 | [diff] [blame] | 1861 | int owe; |
Sunil Dutt | c75a1e6 | 2018-01-11 20:47:50 +0530 | [diff] [blame] | 1862 | int suite_b = 0; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1863 | |
| 1864 | id = add_network_common(dut, conn, ifname, cmd); |
| 1865 | if (id < 0) |
| 1866 | return id; |
| 1867 | |
Jouni Malinen | 47dcc95 | 2017-10-09 16:43:24 +0300 | [diff] [blame] | 1868 | val = get_param(cmd, "Type"); |
| 1869 | owe = val && strcasecmp(val, "OWE") == 0; |
| 1870 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1871 | val = get_param(cmd, "keyMgmtType"); |
Jouni Malinen | 47dcc95 | 2017-10-09 16:43:24 +0300 | [diff] [blame] | 1872 | if (!val && owe) |
| 1873 | val = "OWE"; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1874 | if (val == NULL) { |
Jouni Malinen | e4fde73 | 2019-03-25 22:29:37 +0200 | [diff] [blame] | 1875 | /* keyMgmtType is being replaced with AKMSuiteType, so ignore |
| 1876 | * this missing parameter and assume proto=WPA2. */ |
| 1877 | if (set_network(ifname, id, "proto", "WPA2") < 0) |
| 1878 | return ERROR_SEND_STATUS; |
| 1879 | } else if (strcasecmp(val, "wpa") == 0 || |
| 1880 | strcasecmp(val, "wpa-psk") == 0) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1881 | if (set_network(ifname, id, "proto", "WPA") < 0) |
| 1882 | return -2; |
| 1883 | } else if (strcasecmp(val, "wpa2") == 0 || |
| 1884 | strcasecmp(val, "wpa2-psk") == 0 || |
| 1885 | strcasecmp(val, "wpa2-ft") == 0 || |
| 1886 | strcasecmp(val, "wpa2-sha256") == 0) { |
| 1887 | if (set_network(ifname, id, "proto", "WPA2") < 0) |
| 1888 | return -2; |
Pradeep Reddy POTTETI | 6d04b3b | 2016-11-15 14:51:26 +0530 | [diff] [blame] | 1889 | } else if (strcasecmp(val, "wpa2-wpa-psk") == 0 || |
| 1890 | strcasecmp(val, "wpa2-wpa-ent") == 0) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1891 | if (set_network(ifname, id, "proto", "WPA WPA2") < 0) |
| 1892 | return -2; |
Jouni Malinen | ad395a2 | 2017-09-01 21:13:46 +0300 | [diff] [blame] | 1893 | } else if (strcasecmp(val, "SuiteB") == 0) { |
Sunil Dutt | c75a1e6 | 2018-01-11 20:47:50 +0530 | [diff] [blame] | 1894 | suite_b = 1; |
Jouni Malinen | ad395a2 | 2017-09-01 21:13:46 +0300 | [diff] [blame] | 1895 | if (set_network(ifname, id, "proto", "WPA2") < 0) |
| 1896 | return -2; |
Jouni Malinen | 47dcc95 | 2017-10-09 16:43:24 +0300 | [diff] [blame] | 1897 | } else if (strcasecmp(val, "OWE") == 0) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1898 | } else { |
| 1899 | send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized keyMgmtType value"); |
| 1900 | return 0; |
| 1901 | } |
| 1902 | |
| 1903 | val = get_param(cmd, "encpType"); |
Jouni Malinen | ad395a2 | 2017-09-01 21:13:46 +0300 | [diff] [blame] | 1904 | if (val) { |
| 1905 | cipher_set = 1; |
| 1906 | if (strcasecmp(val, "tkip") == 0) { |
| 1907 | if (set_network(ifname, id, "pairwise", "TKIP") < 0) |
| 1908 | return -2; |
| 1909 | } else if (strcasecmp(val, "aes-ccmp") == 0) { |
| 1910 | if (set_network(ifname, id, "pairwise", "CCMP") < 0) |
| 1911 | return -2; |
| 1912 | } else if (strcasecmp(val, "aes-ccmp-tkip") == 0) { |
| 1913 | if (set_network(ifname, id, "pairwise", |
| 1914 | "CCMP TKIP") < 0) |
| 1915 | return -2; |
| 1916 | } else if (strcasecmp(val, "aes-gcmp") == 0) { |
| 1917 | if (set_network(ifname, id, "pairwise", "GCMP") < 0) |
| 1918 | return -2; |
| 1919 | if (set_network(ifname, id, "group", "GCMP") < 0) |
| 1920 | return -2; |
| 1921 | } else { |
| 1922 | send_resp(dut, conn, SIGMA_ERROR, |
| 1923 | "errorCode,Unrecognized encpType value"); |
| 1924 | return 0; |
| 1925 | } |
| 1926 | } |
| 1927 | |
| 1928 | val = get_param(cmd, "PairwiseCipher"); |
| 1929 | if (val) { |
| 1930 | cipher_set = 1; |
| 1931 | /* TODO: Support space separated list */ |
| 1932 | if (strcasecmp(val, "AES-GCMP-256") == 0) { |
| 1933 | if (set_network(ifname, id, "pairwise", "GCMP-256") < 0) |
| 1934 | return -2; |
| 1935 | } else if (strcasecmp(val, "AES-CCMP-256") == 0) { |
| 1936 | if (set_network(ifname, id, "pairwise", |
| 1937 | "CCMP-256") < 0) |
| 1938 | return -2; |
| 1939 | } else if (strcasecmp(val, "AES-GCMP-128") == 0) { |
| 1940 | if (set_network(ifname, id, "pairwise", "GCMP") < 0) |
| 1941 | return -2; |
| 1942 | } else if (strcasecmp(val, "AES-CCMP-128") == 0) { |
| 1943 | if (set_network(ifname, id, "pairwise", "CCMP") < 0) |
| 1944 | return -2; |
| 1945 | } else { |
| 1946 | send_resp(dut, conn, SIGMA_ERROR, |
| 1947 | "errorCode,Unrecognized PairwiseCipher value"); |
| 1948 | return 0; |
| 1949 | } |
| 1950 | } |
| 1951 | |
Jouni Malinen | 47dcc95 | 2017-10-09 16:43:24 +0300 | [diff] [blame] | 1952 | if (!cipher_set && !owe) { |
Jouni Malinen | ad395a2 | 2017-09-01 21:13:46 +0300 | [diff] [blame] | 1953 | send_resp(dut, conn, SIGMA_ERROR, |
| 1954 | "errorCode,Missing encpType and PairwiseCipher"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1955 | return 0; |
| 1956 | } |
Jouni Malinen | ad395a2 | 2017-09-01 21:13:46 +0300 | [diff] [blame] | 1957 | |
| 1958 | val = get_param(cmd, "GroupCipher"); |
| 1959 | if (val) { |
| 1960 | if (strcasecmp(val, "AES-GCMP-256") == 0) { |
| 1961 | if (set_network(ifname, id, "group", "GCMP-256") < 0) |
| 1962 | return -2; |
| 1963 | } else if (strcasecmp(val, "AES-CCMP-256") == 0) { |
| 1964 | if (set_network(ifname, id, "group", "CCMP-256") < 0) |
| 1965 | return -2; |
| 1966 | } else if (strcasecmp(val, "AES-GCMP-128") == 0) { |
| 1967 | if (set_network(ifname, id, "group", "GCMP") < 0) |
| 1968 | return -2; |
| 1969 | } else if (strcasecmp(val, "AES-CCMP-128") == 0) { |
| 1970 | if (set_network(ifname, id, "group", "CCMP") < 0) |
| 1971 | return -2; |
| 1972 | } else { |
| 1973 | send_resp(dut, conn, SIGMA_ERROR, |
| 1974 | "errorCode,Unrecognized GroupCipher value"); |
| 1975 | return 0; |
| 1976 | } |
| 1977 | } |
| 1978 | |
Jouni Malinen | 7b23952 | 2017-09-14 21:37:18 +0300 | [diff] [blame] | 1979 | val = get_param(cmd, "GroupMgntCipher"); |
Jouni Malinen | ad395a2 | 2017-09-01 21:13:46 +0300 | [diff] [blame] | 1980 | if (val) { |
Jouni Malinen | e8898cb | 2017-09-26 17:55:26 +0300 | [diff] [blame] | 1981 | const char *cipher; |
| 1982 | |
| 1983 | if (strcasecmp(val, "BIP-GMAC-256") == 0) { |
| 1984 | cipher = "BIP-GMAC-256"; |
| 1985 | } else if (strcasecmp(val, "BIP-CMAC-256") == 0) { |
| 1986 | cipher = "BIP-CMAC-256"; |
| 1987 | } else if (strcasecmp(val, "BIP-GMAC-128") == 0) { |
| 1988 | cipher = "BIP-GMAC-128"; |
| 1989 | } else if (strcasecmp(val, "BIP-CMAC-128") == 0) { |
| 1990 | cipher = "AES-128-CMAC"; |
| 1991 | } else { |
| 1992 | send_resp(dut, conn, SIGMA_INVALID, |
| 1993 | "errorCode,Unsupported GroupMgntCipher"); |
| 1994 | return 0; |
| 1995 | } |
| 1996 | if (set_network(ifname, id, "group_mgmt", cipher) < 0) { |
| 1997 | send_resp(dut, conn, SIGMA_INVALID, |
| 1998 | "errorCode,Failed to set GroupMgntCipher"); |
| 1999 | return 0; |
| 2000 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2001 | } |
| 2002 | |
Jouni Malinen | e4fde73 | 2019-03-25 22:29:37 +0200 | [diff] [blame] | 2003 | val = get_param(cmd, "AKMSuiteType"); |
| 2004 | if (val && set_akm_suites(dut, ifname, id, val) < 0) |
| 2005 | return ERROR_SEND_STATUS; |
| 2006 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2007 | dut->sta_pmf = STA_PMF_DISABLED; |
vamsi krishna | f39bc1e | 2017-08-23 17:37:53 +0530 | [diff] [blame] | 2008 | |
| 2009 | if (dut->program == PROGRAM_OCE) { |
| 2010 | dut->sta_pmf = STA_PMF_OPTIONAL; |
| 2011 | if (set_network(ifname, id, "ieee80211w", "1") < 0) |
| 2012 | return -2; |
| 2013 | } |
| 2014 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2015 | val = get_param(cmd, "PMF"); |
| 2016 | if (val) { |
| 2017 | if (strcasecmp(val, "Required") == 0 || |
| 2018 | strcasecmp(val, "Forced_Required") == 0) { |
| 2019 | dut->sta_pmf = STA_PMF_REQUIRED; |
| 2020 | if (set_network(ifname, id, "ieee80211w", "2") < 0) |
| 2021 | return -2; |
| 2022 | } else if (strcasecmp(val, "Optional") == 0) { |
| 2023 | dut->sta_pmf = STA_PMF_OPTIONAL; |
| 2024 | if (set_network(ifname, id, "ieee80211w", "1") < 0) |
| 2025 | return -2; |
| 2026 | } else if (strcasecmp(val, "Disabled") == 0 || |
Kiran Kumar Lokere | 07da3b2 | 2018-12-16 22:42:49 -0800 | [diff] [blame] | 2027 | strcasecmp(val, "Disable") == 0 || |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2028 | strcasecmp(val, "Forced_Disabled") == 0) { |
| 2029 | dut->sta_pmf = STA_PMF_DISABLED; |
| 2030 | } else { |
| 2031 | send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized PMF value"); |
| 2032 | return 0; |
| 2033 | } |
Sunil Dutt | c75a1e6 | 2018-01-11 20:47:50 +0530 | [diff] [blame] | 2034 | } else if (owe || suite_b) { |
Jouni Malinen | 1287cd7 | 2018-01-04 17:08:01 +0200 | [diff] [blame] | 2035 | dut->sta_pmf = STA_PMF_REQUIRED; |
| 2036 | if (set_network(ifname, id, "ieee80211w", "2") < 0) |
| 2037 | return -2; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2038 | } |
| 2039 | |
| 2040 | return id; |
| 2041 | } |
| 2042 | |
| 2043 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 2044 | static enum sigma_cmd_result cmd_sta_set_psk(struct sigma_dut *dut, |
| 2045 | struct sigma_conn *conn, |
| 2046 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2047 | { |
| 2048 | const char *intf = get_param(cmd, "Interface"); |
Jouni Malinen | 992a81e | 2017-08-22 13:57:47 +0300 | [diff] [blame] | 2049 | const char *type = get_param(cmd, "Type"); |
Jouni Malinen | 1287cd7 | 2018-01-04 17:08:01 +0200 | [diff] [blame] | 2050 | const char *pmf = get_param(cmd, "PMF"); |
Alexei Avshalom Lazar | d596b51 | 2018-12-18 16:00:59 +0200 | [diff] [blame] | 2051 | const char *network_mode = get_param(cmd, "network_mode"); |
Jouni Malinen | e4fde73 | 2019-03-25 22:29:37 +0200 | [diff] [blame] | 2052 | const char *akm = get_param(cmd, "AKMSuiteType"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2053 | const char *ifname, *val, *alg; |
| 2054 | int id; |
| 2055 | |
| 2056 | if (intf == NULL) |
| 2057 | return -1; |
| 2058 | |
| 2059 | if (strcmp(intf, get_main_ifname()) == 0) |
| 2060 | ifname = get_station_ifname(); |
| 2061 | else |
| 2062 | ifname = intf; |
| 2063 | |
| 2064 | id = set_wpa_common(dut, conn, ifname, cmd); |
| 2065 | if (id < 0) |
| 2066 | return id; |
| 2067 | |
| 2068 | val = get_param(cmd, "keyMgmtType"); |
| 2069 | alg = get_param(cmd, "micAlg"); |
| 2070 | |
Jouni Malinen | 992a81e | 2017-08-22 13:57:47 +0300 | [diff] [blame] | 2071 | if (type && strcasecmp(type, "SAE") == 0) { |
Jouni Malinen | e4fde73 | 2019-03-25 22:29:37 +0200 | [diff] [blame] | 2072 | if (!akm && val && strcasecmp(val, "wpa2-ft") == 0) { |
Jouni Malinen | 992a81e | 2017-08-22 13:57:47 +0300 | [diff] [blame] | 2073 | if (set_network(ifname, id, "key_mgmt", "FT-SAE") < 0) |
| 2074 | return -2; |
Jouni Malinen | e4fde73 | 2019-03-25 22:29:37 +0200 | [diff] [blame] | 2075 | } else if (!akm) { |
Jouni Malinen | 992a81e | 2017-08-22 13:57:47 +0300 | [diff] [blame] | 2076 | if (set_network(ifname, id, "key_mgmt", "SAE") < 0) |
| 2077 | return -2; |
| 2078 | } |
| 2079 | if (wpa_command(ifname, "SET sae_groups ") != 0) { |
| 2080 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 2081 | "Failed to clear sae_groups to default"); |
| 2082 | return -2; |
| 2083 | } |
Jouni Malinen | 1287cd7 | 2018-01-04 17:08:01 +0200 | [diff] [blame] | 2084 | if (!pmf) { |
| 2085 | dut->sta_pmf = STA_PMF_REQUIRED; |
| 2086 | if (set_network(ifname, id, "ieee80211w", "2") < 0) |
| 2087 | return -2; |
| 2088 | } |
Jouni Malinen | 0ab50f4 | 2017-08-31 01:34:59 +0300 | [diff] [blame] | 2089 | } else if (type && strcasecmp(type, "PSK-SAE") == 0) { |
| 2090 | if (val && strcasecmp(val, "wpa2-ft") == 0) { |
| 2091 | if (set_network(ifname, id, "key_mgmt", |
| 2092 | "FT-SAE FT-PSK") < 0) |
| 2093 | return -2; |
Jouni Malinen | 3b73d87 | 2019-06-12 03:13:25 +0300 | [diff] [blame] | 2094 | } else if (!akm) { |
Jouni Malinen | 0ab50f4 | 2017-08-31 01:34:59 +0300 | [diff] [blame] | 2095 | if (set_network(ifname, id, "key_mgmt", |
| 2096 | "SAE WPA-PSK") < 0) |
| 2097 | return -2; |
| 2098 | } |
| 2099 | if (wpa_command(ifname, "SET sae_groups ") != 0) { |
| 2100 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 2101 | "Failed to clear sae_groups to default"); |
| 2102 | return -2; |
| 2103 | } |
Jouni Malinen | 1287cd7 | 2018-01-04 17:08:01 +0200 | [diff] [blame] | 2104 | if (!pmf) { |
| 2105 | dut->sta_pmf = STA_PMF_OPTIONAL; |
| 2106 | if (set_network(ifname, id, "ieee80211w", "1") < 0) |
| 2107 | return -2; |
| 2108 | } |
Jouni Malinen | 992a81e | 2017-08-22 13:57:47 +0300 | [diff] [blame] | 2109 | } else if (alg && strcasecmp(alg, "SHA-256") == 0) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2110 | if (set_network(ifname, id, "key_mgmt", "WPA-PSK-SHA256") < 0) |
| 2111 | return -2; |
| 2112 | } else if (alg && strcasecmp(alg, "SHA-1") == 0) { |
| 2113 | if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0) |
| 2114 | return -2; |
Ashwini Patil | 6dbf7b0 | 2017-03-20 13:42:11 +0530 | [diff] [blame] | 2115 | } else if (val && strcasecmp(val, "wpa2-ft") == 0) { |
| 2116 | if (set_network(ifname, id, "key_mgmt", "FT-PSK") < 0) |
| 2117 | return -2; |
Jouni Malinen | 3b73d87 | 2019-06-12 03:13:25 +0300 | [diff] [blame] | 2118 | } else if (!akm && |
| 2119 | ((val && strcasecmp(val, "wpa2-sha256") == 0) || |
| 2120 | dut->sta_pmf == STA_PMF_REQUIRED)) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2121 | if (set_network(ifname, id, "key_mgmt", |
| 2122 | "WPA-PSK WPA-PSK-SHA256") < 0) |
| 2123 | return -2; |
Jouni Malinen | 77ff3f0 | 2019-03-28 03:45:40 +0200 | [diff] [blame] | 2124 | } else if (!akm && dut->sta_pmf == STA_PMF_OPTIONAL) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2125 | if (set_network(ifname, id, "key_mgmt", |
| 2126 | "WPA-PSK WPA-PSK-SHA256") < 0) |
| 2127 | return -2; |
Jouni Malinen | 77ff3f0 | 2019-03-28 03:45:40 +0200 | [diff] [blame] | 2128 | } else if (!akm) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2129 | if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0) |
| 2130 | return -2; |
| 2131 | } |
| 2132 | |
| 2133 | val = get_param(cmd, "passPhrase"); |
| 2134 | if (val == NULL) |
| 2135 | return -1; |
Jouni Malinen | 2126f42 | 2017-10-11 23:24:33 +0300 | [diff] [blame] | 2136 | if (type && strcasecmp(type, "SAE") == 0) { |
| 2137 | if (set_network_quoted(ifname, id, "sae_password", val) < 0) |
| 2138 | return -2; |
| 2139 | } else { |
| 2140 | if (set_network_quoted(ifname, id, "psk", val) < 0) |
| 2141 | return -2; |
| 2142 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2143 | |
Jouni Malinen | 78d10c4 | 2019-03-25 22:34:32 +0200 | [diff] [blame] | 2144 | val = get_param(cmd, "PasswordId"); |
| 2145 | if (val && set_network_quoted(ifname, id, "sae_password_id", val) < 0) |
| 2146 | return ERROR_SEND_STATUS; |
| 2147 | |
Jouni Malinen | 992a81e | 2017-08-22 13:57:47 +0300 | [diff] [blame] | 2148 | val = get_param(cmd, "ECGroupID"); |
| 2149 | if (val) { |
| 2150 | char buf[50]; |
| 2151 | |
| 2152 | snprintf(buf, sizeof(buf), "SET sae_groups %u", atoi(val)); |
| 2153 | if (wpa_command(ifname, buf) != 0) { |
| 2154 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 2155 | "Failed to clear sae_groups"); |
| 2156 | return -2; |
| 2157 | } |
| 2158 | } |
| 2159 | |
Jouni Malinen | 6814313 | 2017-09-02 02:34:08 +0300 | [diff] [blame] | 2160 | val = get_param(cmd, "InvalidSAEElement"); |
| 2161 | if (val) { |
| 2162 | free(dut->sae_commit_override); |
| 2163 | dut->sae_commit_override = strdup(val); |
| 2164 | } |
| 2165 | |
Alexei Avshalom Lazar | d596b51 | 2018-12-18 16:00:59 +0200 | [diff] [blame] | 2166 | if (dut->program == PROGRAM_60GHZ && network_mode && |
| 2167 | strcasecmp(network_mode, "PBSS") == 0 && |
| 2168 | set_network(ifname, id, "pbss", "1") < 0) |
| 2169 | return -2; |
| 2170 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2171 | return 1; |
| 2172 | } |
| 2173 | |
| 2174 | |
Jouni Malinen | 8ac9345 | 2019-08-14 15:19:13 +0300 | [diff] [blame] | 2175 | static enum sigma_cmd_result set_trust_root_system(struct sigma_dut *dut, |
| 2176 | struct sigma_conn *conn, |
| 2177 | const char *ifname, int id) |
| 2178 | { |
| 2179 | char buf[200]; |
| 2180 | |
| 2181 | snprintf(buf, sizeof(buf), "%s/certs", sigma_cert_path); |
| 2182 | if (!file_exists(buf)) |
| 2183 | strlcpy(buf, "/system/etc/security/cacerts", sizeof(buf)); |
| 2184 | if (!file_exists(buf)) |
| 2185 | strlcpy(buf, "/etc/ssl/certs", sizeof(buf)); |
| 2186 | if (!file_exists(buf)) { |
| 2187 | char msg[300]; |
| 2188 | |
| 2189 | snprintf(msg, sizeof(msg), |
| 2190 | "ErrorCode,trustedRootCA system store (%s) not found", |
| 2191 | buf); |
| 2192 | send_resp(dut, conn, SIGMA_ERROR, msg); |
| 2193 | return STATUS_SENT_ERROR; |
| 2194 | } |
| 2195 | |
| 2196 | if (set_network_quoted(ifname, id, "ca_path", buf) < 0) |
| 2197 | return ERROR_SEND_STATUS; |
| 2198 | |
| 2199 | return SUCCESS_SEND_STATUS; |
| 2200 | } |
| 2201 | |
| 2202 | |
| 2203 | static enum sigma_cmd_result set_trust_root(struct sigma_dut *dut, |
| 2204 | struct sigma_conn *conn, |
| 2205 | const char *ifname, int id, |
| 2206 | const char *val) |
| 2207 | { |
| 2208 | char buf[200]; |
| 2209 | #ifdef ANDROID |
| 2210 | unsigned char kvalue[KEYSTORE_MESSAGE_SIZE]; |
| 2211 | int length; |
| 2212 | #endif /* ANDROID */ |
| 2213 | |
| 2214 | if (strcmp(val, "DEFAULT") == 0) |
| 2215 | return set_trust_root_system(dut, conn, ifname, id); |
| 2216 | |
| 2217 | #ifdef ANDROID |
| 2218 | snprintf(buf, sizeof(buf), "CACERT_%s", val); |
| 2219 | length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue); |
| 2220 | if (length > 0) { |
| 2221 | sigma_dut_print(dut, DUT_MSG_INFO, "Use Android keystore [%s]", |
| 2222 | buf); |
| 2223 | snprintf(buf, sizeof(buf), "keystore://CACERT_%s", val); |
| 2224 | goto ca_cert_selected; |
| 2225 | } |
| 2226 | #endif /* ANDROID */ |
| 2227 | |
| 2228 | snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val); |
| 2229 | #ifdef __linux__ |
| 2230 | if (!file_exists(buf)) { |
| 2231 | char msg[300]; |
| 2232 | |
| 2233 | snprintf(msg, sizeof(msg), |
| 2234 | "ErrorCode,trustedRootCA file (%s) not found", buf); |
| 2235 | send_resp(dut, conn, SIGMA_ERROR, msg); |
| 2236 | return STATUS_SENT_ERROR; |
| 2237 | } |
| 2238 | #endif /* __linux__ */ |
| 2239 | #ifdef ANDROID |
| 2240 | ca_cert_selected: |
| 2241 | #endif /* ANDROID */ |
| 2242 | if (set_network_quoted(ifname, id, "ca_cert", buf) < 0) |
| 2243 | return ERROR_SEND_STATUS; |
| 2244 | |
| 2245 | return SUCCESS_SEND_STATUS; |
| 2246 | } |
| 2247 | |
| 2248 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2249 | 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] | 2250 | const char *ifname, int username_identity, |
| 2251 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2252 | { |
Jouni Malinen | b4d56ba | 2019-08-23 18:17:44 +0300 | [diff] [blame^] | 2253 | const char *val, *alg, *akm, *trust_root, *domain, *domain_suffix; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2254 | int id; |
Jouni Malinen | 53264f6 | 2019-05-03 13:04:40 +0300 | [diff] [blame] | 2255 | char buf[200], buf2[300]; |
Jouni Malinen | 8179fee | 2019-03-28 03:19:47 +0200 | [diff] [blame] | 2256 | int erp = 0; |
Jouni Malinen | 8ac9345 | 2019-08-14 15:19:13 +0300 | [diff] [blame] | 2257 | enum sigma_cmd_result res; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2258 | |
| 2259 | id = set_wpa_common(dut, conn, ifname, cmd); |
| 2260 | if (id < 0) |
| 2261 | return id; |
| 2262 | |
| 2263 | val = get_param(cmd, "keyMgmtType"); |
| 2264 | alg = get_param(cmd, "micAlg"); |
vamsi krishna | f39bc1e | 2017-08-23 17:37:53 +0530 | [diff] [blame] | 2265 | akm = get_param(cmd, "AKMSuiteType"); |
Jouni Malinen | b4d56ba | 2019-08-23 18:17:44 +0300 | [diff] [blame^] | 2266 | trust_root = get_param(cmd, "trustedRootCA"); |
| 2267 | domain = get_param(cmd, "Domain"); |
| 2268 | domain_suffix = get_param(cmd, "DomainSuffix"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2269 | |
Jouni Malinen | ad395a2 | 2017-09-01 21:13:46 +0300 | [diff] [blame] | 2270 | if (val && strcasecmp(val, "SuiteB") == 0) { |
| 2271 | if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SUITE-B-192") < |
| 2272 | 0) |
| 2273 | return -2; |
| 2274 | } else if (alg && strcasecmp(alg, "SHA-256") == 0) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2275 | if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SHA256") < 0) |
| 2276 | return -2; |
| 2277 | } else if (alg && strcasecmp(alg, "SHA-1") == 0) { |
| 2278 | if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0) |
| 2279 | return -2; |
| 2280 | } else if (val && strcasecmp(val, "wpa2-ft") == 0) { |
| 2281 | if (set_network(ifname, id, "key_mgmt", "FT-EAP") < 0) |
| 2282 | return -2; |
Jouni Malinen | d6a9d69 | 2019-03-28 03:01:24 +0200 | [diff] [blame] | 2283 | } else if (!akm && |
| 2284 | ((val && strcasecmp(val, "wpa2-sha256") == 0) || |
| 2285 | dut->sta_pmf == STA_PMF_REQUIRED)) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2286 | if (set_network(ifname, id, "key_mgmt", |
| 2287 | "WPA-EAP WPA-EAP-SHA256") < 0) |
| 2288 | return -2; |
vamsi krishna | f39bc1e | 2017-08-23 17:37:53 +0530 | [diff] [blame] | 2289 | } else if (akm && atoi(akm) == 14) { |
| 2290 | if (dut->sta_pmf == STA_PMF_OPTIONAL || |
| 2291 | dut->sta_pmf == STA_PMF_REQUIRED) { |
| 2292 | if (set_network(ifname, id, "key_mgmt", |
| 2293 | "WPA-EAP-SHA256 FILS-SHA256") < 0) |
| 2294 | return -2; |
| 2295 | } else { |
| 2296 | if (set_network(ifname, id, "key_mgmt", |
| 2297 | "WPA-EAP FILS-SHA256") < 0) |
| 2298 | return -2; |
| 2299 | } |
| 2300 | |
Jouni Malinen | 8179fee | 2019-03-28 03:19:47 +0200 | [diff] [blame] | 2301 | erp = 1; |
vamsi krishna | f39bc1e | 2017-08-23 17:37:53 +0530 | [diff] [blame] | 2302 | } else if (akm && atoi(akm) == 15) { |
| 2303 | if (dut->sta_pmf == STA_PMF_OPTIONAL || |
| 2304 | dut->sta_pmf == STA_PMF_REQUIRED) { |
| 2305 | if (set_network(ifname, id, "key_mgmt", |
| 2306 | "WPA-EAP-SHA256 FILS-SHA384") < 0) |
| 2307 | return -2; |
| 2308 | } else { |
| 2309 | if (set_network(ifname, id, "key_mgmt", |
| 2310 | "WPA-EAP FILS-SHA384") < 0) |
| 2311 | return -2; |
| 2312 | } |
| 2313 | |
Jouni Malinen | 8179fee | 2019-03-28 03:19:47 +0200 | [diff] [blame] | 2314 | erp = 1; |
Jouni Malinen | d6a9d69 | 2019-03-28 03:01:24 +0200 | [diff] [blame] | 2315 | } else if (!akm && dut->sta_pmf == STA_PMF_OPTIONAL) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2316 | if (set_network(ifname, id, "key_mgmt", |
| 2317 | "WPA-EAP WPA-EAP-SHA256") < 0) |
| 2318 | return -2; |
Jouni Malinen | d6a9d69 | 2019-03-28 03:01:24 +0200 | [diff] [blame] | 2319 | } else if (!akm) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2320 | if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0) |
| 2321 | return -2; |
| 2322 | } |
| 2323 | |
Jouni Malinen | b4d56ba | 2019-08-23 18:17:44 +0300 | [diff] [blame^] | 2324 | if (trust_root) { |
| 2325 | if (strcmp(trust_root, "DEFAULT") == 0 && !domain && |
| 2326 | !domain_suffix) { |
| 2327 | send_resp(dut, conn, SIGMA_ERROR, |
| 2328 | "errorCode,trustRootCA DEFAULT used without specifying Domain or DomainSuffix"); |
| 2329 | return STATUS_SENT_ERROR; |
| 2330 | } |
| 2331 | res = set_trust_root(dut, conn, ifname, id, trust_root); |
Jouni Malinen | 8ac9345 | 2019-08-14 15:19:13 +0300 | [diff] [blame] | 2332 | if (res != SUCCESS_SEND_STATUS) |
| 2333 | return res; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2334 | } |
| 2335 | |
Jouni Malinen | 53264f6 | 2019-05-03 13:04:40 +0300 | [diff] [blame] | 2336 | val = get_param(cmd, "ServerCert"); |
| 2337 | if (val) { |
| 2338 | FILE *f; |
| 2339 | char *result = NULL, *pos; |
| 2340 | |
| 2341 | snprintf(buf, sizeof(buf), "%s/%s.sha256", sigma_cert_path, |
| 2342 | val); |
| 2343 | f = fopen(buf, "r"); |
| 2344 | if (f) { |
| 2345 | result = fgets(buf, sizeof(buf), f); |
| 2346 | fclose(f); |
| 2347 | } |
| 2348 | if (!result) { |
| 2349 | snprintf(buf2, sizeof(buf2), |
| 2350 | "ErrorCode,ServerCert hash could not be read from %s", |
| 2351 | buf); |
| 2352 | send_resp(dut, conn, SIGMA_ERROR, buf2); |
| 2353 | return STATUS_SENT_ERROR; |
| 2354 | } |
| 2355 | pos = strchr(buf, '\n'); |
| 2356 | if (pos) |
| 2357 | *pos = '\0'; |
| 2358 | snprintf(buf2, sizeof(buf2), "hash://server/sha256/%s", buf); |
| 2359 | if (set_network_quoted(ifname, id, "ca_cert", buf2) < 0) |
| 2360 | return ERROR_SEND_STATUS; |
Jouni Malinen | 29108dc | 2019-06-13 23:42:11 +0300 | [diff] [blame] | 2361 | |
| 2362 | snprintf(buf, sizeof(buf), "%s/%s.tod", sigma_cert_path, val); |
| 2363 | if (file_exists(buf)) { |
| 2364 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 2365 | "TOD policy enabled for the configured ServerCert hash"); |
| 2366 | dut->sta_tod_policy = 1; |
| 2367 | } |
Jouni Malinen | 53264f6 | 2019-05-03 13:04:40 +0300 | [diff] [blame] | 2368 | } |
| 2369 | |
Jouni Malinen | b4d56ba | 2019-08-23 18:17:44 +0300 | [diff] [blame^] | 2370 | if (domain && |
| 2371 | set_network_quoted(ifname, id, "domain_match", domain) < 0) |
Jouni Malinen | 96f84b0 | 2019-05-03 12:32:56 +0300 | [diff] [blame] | 2372 | return ERROR_SEND_STATUS; |
| 2373 | |
Jouni Malinen | b4d56ba | 2019-08-23 18:17:44 +0300 | [diff] [blame^] | 2374 | if (domain_suffix && |
| 2375 | set_network_quoted(ifname, id, "domain_suffix_match", |
| 2376 | domain_suffix) < 0) |
Jouni Malinen | 96f84b0 | 2019-05-03 12:32:56 +0300 | [diff] [blame] | 2377 | return ERROR_SEND_STATUS; |
| 2378 | |
Bala Krishna Bhamidipati | 73d7af0 | 2016-03-24 12:27:56 +0530 | [diff] [blame] | 2379 | if (username_identity) { |
| 2380 | val = get_param(cmd, "username"); |
| 2381 | if (val) { |
| 2382 | if (set_network_quoted(ifname, id, "identity", val) < 0) |
| 2383 | return -2; |
| 2384 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2385 | |
Bala Krishna Bhamidipati | 73d7af0 | 2016-03-24 12:27:56 +0530 | [diff] [blame] | 2386 | val = get_param(cmd, "password"); |
| 2387 | if (val) { |
| 2388 | if (set_network_quoted(ifname, id, "password", val) < 0) |
| 2389 | return -2; |
| 2390 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2391 | } |
| 2392 | |
Jouni Malinen | 8179fee | 2019-03-28 03:19:47 +0200 | [diff] [blame] | 2393 | if (dut->akm_values & |
| 2394 | ((1 << AKM_FILS_SHA256) | |
| 2395 | (1 << AKM_FILS_SHA384) | |
| 2396 | (1 << AKM_FT_FILS_SHA256) | |
| 2397 | (1 << AKM_FT_FILS_SHA384))) |
| 2398 | erp = 1; |
| 2399 | if (erp && set_network(ifname, id, "erp", "1") < 0) |
| 2400 | return ERROR_SEND_STATUS; |
| 2401 | |
Jouni Malinen | 134fe3c | 2019-06-12 04:16:49 +0300 | [diff] [blame] | 2402 | dut->sta_associate_wait_connect = 1; |
| 2403 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2404 | return id; |
| 2405 | } |
| 2406 | |
| 2407 | |
Jouni Malinen | 5eabb2a | 2017-10-03 18:17:30 +0300 | [diff] [blame] | 2408 | static int set_tls_cipher(const char *ifname, int id, const char *cipher) |
| 2409 | { |
| 2410 | const char *val; |
| 2411 | |
| 2412 | if (!cipher) |
| 2413 | return 0; |
| 2414 | |
| 2415 | if (strcasecmp(cipher, "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384") == 0) |
| 2416 | val = "ECDHE-ECDSA-AES256-GCM-SHA384"; |
| 2417 | else if (strcasecmp(cipher, |
| 2418 | "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384") == 0) |
| 2419 | val = "ECDHE-RSA-AES256-GCM-SHA384"; |
| 2420 | else if (strcasecmp(cipher, "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384") == 0) |
| 2421 | val = "DHE-RSA-AES256-GCM-SHA384"; |
| 2422 | else if (strcasecmp(cipher, |
| 2423 | "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256") == 0) |
| 2424 | val = "ECDHE-ECDSA-AES128-GCM-SHA256"; |
| 2425 | else |
| 2426 | return -1; |
| 2427 | |
| 2428 | /* Need to clear phase1="tls_suiteb=1" to allow cipher enforcement */ |
| 2429 | set_network_quoted(ifname, id, "phase1", ""); |
| 2430 | |
| 2431 | return set_network_quoted(ifname, id, "openssl_ciphers", val); |
| 2432 | } |
| 2433 | |
| 2434 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 2435 | static enum sigma_cmd_result cmd_sta_set_eaptls(struct sigma_dut *dut, |
| 2436 | struct sigma_conn *conn, |
| 2437 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2438 | { |
| 2439 | const char *intf = get_param(cmd, "Interface"); |
| 2440 | const char *ifname, *val; |
| 2441 | int id; |
| 2442 | char buf[200]; |
| 2443 | #ifdef ANDROID |
| 2444 | unsigned char kvalue[KEYSTORE_MESSAGE_SIZE]; |
| 2445 | int length; |
| 2446 | int jb_or_newer = 0; |
| 2447 | char prop[PROPERTY_VALUE_MAX]; |
| 2448 | #endif /* ANDROID */ |
| 2449 | |
| 2450 | if (intf == NULL) |
| 2451 | return -1; |
| 2452 | |
| 2453 | if (strcmp(intf, get_main_ifname()) == 0) |
| 2454 | ifname = get_station_ifname(); |
| 2455 | else |
| 2456 | ifname = intf; |
| 2457 | |
Bala Krishna Bhamidipati | 73d7af0 | 2016-03-24 12:27:56 +0530 | [diff] [blame] | 2458 | id = set_eap_common(dut, conn, ifname, 1, cmd); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2459 | if (id < 0) |
| 2460 | return id; |
| 2461 | |
| 2462 | if (set_network(ifname, id, "eap", "TLS") < 0) |
| 2463 | return -2; |
| 2464 | |
Pradeep Reddy POTTETI | 9f6c213 | 2016-05-05 16:28:19 +0530 | [diff] [blame] | 2465 | if (!get_param(cmd, "username") && |
| 2466 | set_network_quoted(ifname, id, "identity", |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2467 | "wifi-user@wifilabs.local") < 0) |
| 2468 | return -2; |
| 2469 | |
| 2470 | val = get_param(cmd, "clientCertificate"); |
| 2471 | if (val == NULL) |
| 2472 | return -1; |
| 2473 | #ifdef ANDROID |
| 2474 | snprintf(buf, sizeof(buf), "USRPKEY_%s", val); |
| 2475 | length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue); |
| 2476 | if (length < 0) { |
| 2477 | /* |
| 2478 | * JB started reporting keystore type mismatches, so retry with |
| 2479 | * the GET_PUBKEY command if the generic GET fails. |
| 2480 | */ |
| 2481 | length = android_keystore_get(ANDROID_KEYSTORE_GET_PUBKEY, |
| 2482 | buf, kvalue); |
| 2483 | } |
| 2484 | |
| 2485 | if (property_get("ro.build.version.release", prop, NULL) != 0) { |
| 2486 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Android release %s", prop); |
| 2487 | if (strncmp(prop, "4.0", 3) != 0) |
| 2488 | jb_or_newer = 1; |
| 2489 | } else |
| 2490 | jb_or_newer = 1; /* assume newer */ |
| 2491 | |
| 2492 | if (jb_or_newer && length > 0) { |
| 2493 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 2494 | "Use Android keystore [%s]", buf); |
| 2495 | if (set_network(ifname, id, "engine", "1") < 0) |
| 2496 | return -2; |
| 2497 | if (set_network_quoted(ifname, id, "engine_id", "keystore") < 0) |
| 2498 | return -2; |
| 2499 | snprintf(buf, sizeof(buf), "USRPKEY_%s", val); |
| 2500 | if (set_network_quoted(ifname, id, "key_id", buf) < 0) |
| 2501 | return -2; |
| 2502 | snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val); |
| 2503 | if (set_network_quoted(ifname, id, "client_cert", buf) < 0) |
| 2504 | return -2; |
| 2505 | return 1; |
| 2506 | } else if (length > 0) { |
| 2507 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 2508 | "Use Android keystore [%s]", buf); |
| 2509 | snprintf(buf, sizeof(buf), "keystore://USRPKEY_%s", val); |
| 2510 | if (set_network_quoted(ifname, id, "private_key", buf) < 0) |
| 2511 | return -2; |
| 2512 | snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val); |
| 2513 | if (set_network_quoted(ifname, id, "client_cert", buf) < 0) |
| 2514 | return -2; |
| 2515 | return 1; |
| 2516 | } |
| 2517 | #endif /* ANDROID */ |
| 2518 | |
| 2519 | snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val); |
| 2520 | #ifdef __linux__ |
| 2521 | if (!file_exists(buf)) { |
| 2522 | char msg[300]; |
| 2523 | snprintf(msg, sizeof(msg), "ErrorCode,clientCertificate file " |
| 2524 | "(%s) not found", buf); |
| 2525 | send_resp(dut, conn, SIGMA_ERROR, msg); |
| 2526 | return -3; |
| 2527 | } |
| 2528 | #endif /* __linux__ */ |
| 2529 | if (set_network_quoted(ifname, id, "private_key", buf) < 0) |
| 2530 | return -2; |
| 2531 | if (set_network_quoted(ifname, id, "client_cert", buf) < 0) |
| 2532 | return -2; |
| 2533 | |
| 2534 | if (set_network_quoted(ifname, id, "private_key_passwd", "wifi") < 0) |
| 2535 | return -2; |
| 2536 | |
Jouni Malinen | 5eabb2a | 2017-10-03 18:17:30 +0300 | [diff] [blame] | 2537 | val = get_param(cmd, "keyMgmtType"); |
| 2538 | if (val && strcasecmp(val, "SuiteB") == 0) { |
| 2539 | val = get_param(cmd, "CertType"); |
| 2540 | if (val && strcasecmp(val, "RSA") == 0) { |
| 2541 | if (set_network_quoted(ifname, id, "phase1", |
| 2542 | "tls_suiteb=1") < 0) |
| 2543 | return -2; |
| 2544 | } else { |
| 2545 | if (set_network_quoted(ifname, id, "openssl_ciphers", |
| 2546 | "SUITEB192") < 0) |
| 2547 | return -2; |
| 2548 | } |
| 2549 | |
| 2550 | val = get_param(cmd, "TLSCipher"); |
| 2551 | if (set_tls_cipher(ifname, id, val) < 0) { |
| 2552 | send_resp(dut, conn, SIGMA_ERROR, |
| 2553 | "ErrorCode,Unsupported TLSCipher value"); |
| 2554 | return -3; |
| 2555 | } |
| 2556 | } |
| 2557 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2558 | return 1; |
| 2559 | } |
| 2560 | |
| 2561 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 2562 | static enum sigma_cmd_result cmd_sta_set_eapttls(struct sigma_dut *dut, |
| 2563 | struct sigma_conn *conn, |
| 2564 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2565 | { |
| 2566 | const char *intf = get_param(cmd, "Interface"); |
| 2567 | const char *ifname; |
| 2568 | int id; |
| 2569 | |
| 2570 | if (intf == NULL) |
| 2571 | return -1; |
| 2572 | |
| 2573 | if (strcmp(intf, get_main_ifname()) == 0) |
| 2574 | ifname = get_station_ifname(); |
| 2575 | else |
| 2576 | ifname = intf; |
| 2577 | |
Bala Krishna Bhamidipati | 73d7af0 | 2016-03-24 12:27:56 +0530 | [diff] [blame] | 2578 | id = set_eap_common(dut, conn, ifname, 1, cmd); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2579 | if (id < 0) |
| 2580 | return id; |
| 2581 | |
| 2582 | if (set_network(ifname, id, "eap", "TTLS") < 0) { |
| 2583 | send_resp(dut, conn, SIGMA_ERROR, |
| 2584 | "errorCode,Failed to set TTLS method"); |
| 2585 | return 0; |
| 2586 | } |
| 2587 | |
| 2588 | if (set_network_quoted(ifname, id, "phase2", "auth=MSCHAPV2") < 0) { |
| 2589 | send_resp(dut, conn, SIGMA_ERROR, |
| 2590 | "errorCode,Failed to set MSCHAPv2 for TTLS Phase 2"); |
| 2591 | return 0; |
| 2592 | } |
| 2593 | |
| 2594 | return 1; |
| 2595 | } |
| 2596 | |
| 2597 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 2598 | static enum sigma_cmd_result cmd_sta_set_eapsim(struct sigma_dut *dut, |
| 2599 | struct sigma_conn *conn, |
| 2600 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2601 | { |
| 2602 | const char *intf = get_param(cmd, "Interface"); |
| 2603 | const char *ifname; |
| 2604 | int id; |
| 2605 | |
| 2606 | if (intf == NULL) |
| 2607 | return -1; |
| 2608 | |
| 2609 | if (strcmp(intf, get_main_ifname()) == 0) |
| 2610 | ifname = get_station_ifname(); |
| 2611 | else |
| 2612 | ifname = intf; |
| 2613 | |
Bala Krishna Bhamidipati | 73d7af0 | 2016-03-24 12:27:56 +0530 | [diff] [blame] | 2614 | id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2615 | if (id < 0) |
| 2616 | return id; |
| 2617 | |
| 2618 | if (set_network(ifname, id, "eap", "SIM") < 0) |
| 2619 | return -2; |
| 2620 | |
| 2621 | return 1; |
| 2622 | } |
| 2623 | |
| 2624 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 2625 | static enum sigma_cmd_result cmd_sta_set_peap(struct sigma_dut *dut, |
| 2626 | struct sigma_conn *conn, |
| 2627 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2628 | { |
| 2629 | const char *intf = get_param(cmd, "Interface"); |
| 2630 | const char *ifname, *val; |
| 2631 | int id; |
| 2632 | char buf[100]; |
| 2633 | |
| 2634 | if (intf == NULL) |
| 2635 | return -1; |
| 2636 | |
| 2637 | if (strcmp(intf, get_main_ifname()) == 0) |
| 2638 | ifname = get_station_ifname(); |
| 2639 | else |
| 2640 | ifname = intf; |
| 2641 | |
Bala Krishna Bhamidipati | 73d7af0 | 2016-03-24 12:27:56 +0530 | [diff] [blame] | 2642 | id = set_eap_common(dut, conn, ifname, 1, cmd); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2643 | if (id < 0) |
| 2644 | return id; |
| 2645 | |
| 2646 | if (set_network(ifname, id, "eap", "PEAP") < 0) |
| 2647 | return -2; |
| 2648 | |
| 2649 | val = get_param(cmd, "innerEAP"); |
| 2650 | if (val) { |
| 2651 | if (strcasecmp(val, "MSCHAPv2") == 0) { |
| 2652 | if (set_network_quoted(ifname, id, "phase2", |
| 2653 | "auth=MSCHAPV2") < 0) |
| 2654 | return -2; |
| 2655 | } else if (strcasecmp(val, "GTC") == 0) { |
| 2656 | if (set_network_quoted(ifname, id, "phase2", |
| 2657 | "auth=GTC") < 0) |
| 2658 | return -2; |
| 2659 | } else |
| 2660 | return -1; |
| 2661 | } |
| 2662 | |
| 2663 | val = get_param(cmd, "peapVersion"); |
| 2664 | if (val) { |
| 2665 | int ver = atoi(val); |
| 2666 | if (ver < 0 || ver > 1) |
| 2667 | return -1; |
| 2668 | snprintf(buf, sizeof(buf), "peapver=%d", ver); |
| 2669 | if (set_network_quoted(ifname, id, "phase1", buf) < 0) |
| 2670 | return -2; |
| 2671 | } |
| 2672 | |
| 2673 | return 1; |
| 2674 | } |
| 2675 | |
| 2676 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 2677 | static enum sigma_cmd_result cmd_sta_set_eapfast(struct sigma_dut *dut, |
| 2678 | struct sigma_conn *conn, |
| 2679 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2680 | { |
| 2681 | const char *intf = get_param(cmd, "Interface"); |
| 2682 | const char *ifname, *val; |
| 2683 | int id; |
| 2684 | char buf[100]; |
| 2685 | |
| 2686 | if (intf == NULL) |
| 2687 | return -1; |
| 2688 | |
| 2689 | if (strcmp(intf, get_main_ifname()) == 0) |
| 2690 | ifname = get_station_ifname(); |
| 2691 | else |
| 2692 | ifname = intf; |
| 2693 | |
Bala Krishna Bhamidipati | 73d7af0 | 2016-03-24 12:27:56 +0530 | [diff] [blame] | 2694 | id = set_eap_common(dut, conn, ifname, 1, cmd); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2695 | if (id < 0) |
| 2696 | return id; |
| 2697 | |
| 2698 | if (set_network(ifname, id, "eap", "FAST") < 0) |
| 2699 | return -2; |
| 2700 | |
| 2701 | val = get_param(cmd, "innerEAP"); |
| 2702 | if (val) { |
| 2703 | if (strcasecmp(val, "MSCHAPV2") == 0) { |
| 2704 | if (set_network_quoted(ifname, id, "phase2", |
| 2705 | "auth=MSCHAPV2") < 0) |
| 2706 | return -2; |
| 2707 | } else if (strcasecmp(val, "GTC") == 0) { |
| 2708 | if (set_network_quoted(ifname, id, "phase2", |
| 2709 | "auth=GTC") < 0) |
| 2710 | return -2; |
| 2711 | } else |
| 2712 | return -1; |
| 2713 | } |
| 2714 | |
| 2715 | val = get_param(cmd, "validateServer"); |
| 2716 | if (val) { |
| 2717 | /* TODO */ |
| 2718 | sigma_dut_print(dut, DUT_MSG_INFO, "Ignored EAP-FAST " |
| 2719 | "validateServer=%s", val); |
| 2720 | } |
| 2721 | |
| 2722 | val = get_param(cmd, "pacFile"); |
| 2723 | if (val) { |
| 2724 | snprintf(buf, sizeof(buf), "blob://%s", val); |
| 2725 | if (set_network_quoted(ifname, id, "pac_file", buf) < 0) |
| 2726 | return -2; |
| 2727 | } |
| 2728 | |
| 2729 | if (set_network_quoted(ifname, id, "phase1", "fast_provisioning=2") < |
| 2730 | 0) |
| 2731 | return -2; |
| 2732 | |
| 2733 | return 1; |
| 2734 | } |
| 2735 | |
| 2736 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 2737 | static enum sigma_cmd_result cmd_sta_set_eapaka(struct sigma_dut *dut, |
| 2738 | struct sigma_conn *conn, |
| 2739 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2740 | { |
| 2741 | const char *intf = get_param(cmd, "Interface"); |
| 2742 | const char *ifname; |
| 2743 | int id; |
| 2744 | |
| 2745 | if (intf == NULL) |
| 2746 | return -1; |
| 2747 | |
| 2748 | if (strcmp(intf, get_main_ifname()) == 0) |
| 2749 | ifname = get_station_ifname(); |
| 2750 | else |
| 2751 | ifname = intf; |
| 2752 | |
Bala Krishna Bhamidipati | 73d7af0 | 2016-03-24 12:27:56 +0530 | [diff] [blame] | 2753 | id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2754 | if (id < 0) |
| 2755 | return id; |
| 2756 | |
| 2757 | if (set_network(ifname, id, "eap", "AKA") < 0) |
| 2758 | return -2; |
| 2759 | |
| 2760 | return 1; |
| 2761 | } |
| 2762 | |
| 2763 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 2764 | static enum sigma_cmd_result cmd_sta_set_eapakaprime(struct sigma_dut *dut, |
| 2765 | struct sigma_conn *conn, |
| 2766 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2767 | { |
| 2768 | const char *intf = get_param(cmd, "Interface"); |
| 2769 | const char *ifname; |
| 2770 | int id; |
| 2771 | |
| 2772 | if (intf == NULL) |
| 2773 | return -1; |
| 2774 | |
| 2775 | if (strcmp(intf, get_main_ifname()) == 0) |
| 2776 | ifname = get_station_ifname(); |
| 2777 | else |
| 2778 | ifname = intf; |
| 2779 | |
Bala Krishna Bhamidipati | 73d7af0 | 2016-03-24 12:27:56 +0530 | [diff] [blame] | 2780 | id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2781 | if (id < 0) |
| 2782 | return id; |
| 2783 | |
| 2784 | if (set_network(ifname, id, "eap", "AKA'") < 0) |
| 2785 | return -2; |
| 2786 | |
| 2787 | return 1; |
| 2788 | } |
| 2789 | |
| 2790 | |
| 2791 | static int sta_set_open(struct sigma_dut *dut, struct sigma_conn *conn, |
| 2792 | struct sigma_cmd *cmd) |
| 2793 | { |
| 2794 | const char *intf = get_param(cmd, "Interface"); |
Alexei Avshalom Lazar | d596b51 | 2018-12-18 16:00:59 +0200 | [diff] [blame] | 2795 | const char *network_mode = get_param(cmd, "network_mode"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2796 | const char *ifname; |
| 2797 | int id; |
| 2798 | |
| 2799 | if (strcmp(intf, get_main_ifname()) == 0) |
| 2800 | ifname = get_station_ifname(); |
| 2801 | else |
| 2802 | ifname = intf; |
| 2803 | |
| 2804 | id = add_network_common(dut, conn, ifname, cmd); |
| 2805 | if (id < 0) |
| 2806 | return id; |
| 2807 | |
| 2808 | if (set_network(ifname, id, "key_mgmt", "NONE") < 0) |
| 2809 | return -2; |
| 2810 | |
Alexei Avshalom Lazar | d596b51 | 2018-12-18 16:00:59 +0200 | [diff] [blame] | 2811 | if (dut->program == PROGRAM_60GHZ && network_mode && |
| 2812 | strcasecmp(network_mode, "PBSS") == 0 && |
| 2813 | set_network(ifname, id, "pbss", "1") < 0) |
| 2814 | return -2; |
| 2815 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2816 | return 1; |
| 2817 | } |
| 2818 | |
| 2819 | |
Jouni Malinen | 47dcc95 | 2017-10-09 16:43:24 +0300 | [diff] [blame] | 2820 | static int sta_set_owe(struct sigma_dut *dut, struct sigma_conn *conn, |
| 2821 | struct sigma_cmd *cmd) |
| 2822 | { |
| 2823 | const char *intf = get_param(cmd, "Interface"); |
| 2824 | const char *ifname, *val; |
| 2825 | int id; |
| 2826 | |
| 2827 | if (intf == NULL) |
| 2828 | return -1; |
| 2829 | |
| 2830 | if (strcmp(intf, get_main_ifname()) == 0) |
| 2831 | ifname = get_station_ifname(); |
| 2832 | else |
| 2833 | ifname = intf; |
| 2834 | |
| 2835 | id = set_wpa_common(dut, conn, ifname, cmd); |
| 2836 | if (id < 0) |
| 2837 | return id; |
| 2838 | |
| 2839 | if (set_network(ifname, id, "key_mgmt", "OWE") < 0) |
| 2840 | return -2; |
| 2841 | |
| 2842 | val = get_param(cmd, "ECGroupID"); |
Jouni Malinen | fac9cad | 2017-10-10 18:35:55 +0300 | [diff] [blame] | 2843 | if (val && strcmp(val, "0") == 0) { |
| 2844 | if (wpa_command(ifname, |
| 2845 | "VENDOR_ELEM_ADD 13 ff23200000783590fb7440e03d5b3b33911f86affdcc6b4411b707846ac4ff08ddc8831ccd") != 0) { |
| 2846 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 2847 | "Failed to set OWE DH Param element override"); |
| 2848 | return -2; |
| 2849 | } |
| 2850 | } else if (val && set_network(ifname, id, "owe_group", val) < 0) { |
Jouni Malinen | 47dcc95 | 2017-10-09 16:43:24 +0300 | [diff] [blame] | 2851 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 2852 | "Failed to clear owe_group"); |
| 2853 | return -2; |
| 2854 | } |
| 2855 | |
| 2856 | return 1; |
| 2857 | } |
| 2858 | |
| 2859 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 2860 | static enum sigma_cmd_result cmd_sta_set_security(struct sigma_dut *dut, |
| 2861 | struct sigma_conn *conn, |
| 2862 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2863 | { |
| 2864 | const char *type = get_param(cmd, "Type"); |
| 2865 | |
| 2866 | if (type == NULL) { |
| 2867 | send_resp(dut, conn, SIGMA_ERROR, |
| 2868 | "ErrorCode,Missing Type argument"); |
| 2869 | return 0; |
| 2870 | } |
| 2871 | |
| 2872 | if (strcasecmp(type, "OPEN") == 0) |
| 2873 | return sta_set_open(dut, conn, cmd); |
Jouni Malinen | 47dcc95 | 2017-10-09 16:43:24 +0300 | [diff] [blame] | 2874 | if (strcasecmp(type, "OWE") == 0) |
| 2875 | return sta_set_owe(dut, conn, cmd); |
Jouni Malinen | 992a81e | 2017-08-22 13:57:47 +0300 | [diff] [blame] | 2876 | if (strcasecmp(type, "PSK") == 0 || |
Jouni Malinen | 0ab50f4 | 2017-08-31 01:34:59 +0300 | [diff] [blame] | 2877 | strcasecmp(type, "PSK-SAE") == 0 || |
Jouni Malinen | 992a81e | 2017-08-22 13:57:47 +0300 | [diff] [blame] | 2878 | strcasecmp(type, "SAE") == 0) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2879 | return cmd_sta_set_psk(dut, conn, cmd); |
| 2880 | if (strcasecmp(type, "EAPTLS") == 0) |
| 2881 | return cmd_sta_set_eaptls(dut, conn, cmd); |
| 2882 | if (strcasecmp(type, "EAPTTLS") == 0) |
| 2883 | return cmd_sta_set_eapttls(dut, conn, cmd); |
| 2884 | if (strcasecmp(type, "EAPPEAP") == 0) |
| 2885 | return cmd_sta_set_peap(dut, conn, cmd); |
| 2886 | if (strcasecmp(type, "EAPSIM") == 0) |
| 2887 | return cmd_sta_set_eapsim(dut, conn, cmd); |
| 2888 | if (strcasecmp(type, "EAPFAST") == 0) |
| 2889 | return cmd_sta_set_eapfast(dut, conn, cmd); |
| 2890 | if (strcasecmp(type, "EAPAKA") == 0) |
| 2891 | return cmd_sta_set_eapaka(dut, conn, cmd); |
| 2892 | if (strcasecmp(type, "EAPAKAPRIME") == 0) |
| 2893 | return cmd_sta_set_eapakaprime(dut, conn, cmd); |
Amarnath Hullur Subramanyam | 81b11cd | 2018-01-30 19:07:17 -0800 | [diff] [blame] | 2894 | if (strcasecmp(type, "wep") == 0) |
| 2895 | return cmd_sta_set_encryption(dut, conn, cmd); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2896 | |
| 2897 | send_resp(dut, conn, SIGMA_ERROR, |
| 2898 | "ErrorCode,Unsupported Type value"); |
| 2899 | return 0; |
| 2900 | } |
| 2901 | |
| 2902 | |
| 2903 | int ath6kl_client_uapsd(struct sigma_dut *dut, const char *intf, int uapsd) |
| 2904 | { |
| 2905 | #ifdef __linux__ |
| 2906 | /* special handling for ath6kl */ |
| 2907 | char path[128], fname[128], *pos; |
| 2908 | ssize_t res; |
| 2909 | FILE *f; |
| 2910 | |
Jouni Malinen | e39cd56 | 2019-05-29 23:39:56 +0300 | [diff] [blame] | 2911 | res = snprintf(fname, sizeof(fname), "/sys/class/net/%s/phy80211", |
| 2912 | intf); |
| 2913 | if (res < 0 || res >= sizeof(fname)) |
| 2914 | return 0; |
| 2915 | res = readlink(fname, path, sizeof(path)); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2916 | if (res < 0) |
| 2917 | return 0; /* not ath6kl */ |
| 2918 | |
| 2919 | if (res >= (int) sizeof(path)) |
| 2920 | res = sizeof(path) - 1; |
| 2921 | path[res] = '\0'; |
| 2922 | pos = strrchr(path, '/'); |
| 2923 | if (pos == NULL) |
| 2924 | pos = path; |
| 2925 | else |
| 2926 | pos++; |
| 2927 | snprintf(fname, sizeof(fname), |
| 2928 | "/sys/kernel/debug/ieee80211/%s/ath6kl/" |
| 2929 | "create_qos", pos); |
| 2930 | if (!file_exists(fname)) |
| 2931 | return 0; /* not ath6kl */ |
| 2932 | |
| 2933 | if (uapsd) { |
| 2934 | f = fopen(fname, "w"); |
| 2935 | if (f == NULL) |
| 2936 | return -1; |
| 2937 | |
| 2938 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl create_qos"); |
| 2939 | fprintf(f, "4 2 2 1 2 9999999 9999999 9999999 7777777 0 4 " |
| 2940 | "45000 200 56789000 56789000 5678900 0 0 9999999 " |
| 2941 | "20000 0\n"); |
| 2942 | fclose(f); |
| 2943 | } else { |
| 2944 | snprintf(fname, sizeof(fname), |
| 2945 | "/sys/kernel/debug/ieee80211/%s/ath6kl/" |
| 2946 | "delete_qos", pos); |
| 2947 | |
| 2948 | f = fopen(fname, "w"); |
| 2949 | if (f == NULL) |
| 2950 | return -1; |
| 2951 | |
| 2952 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl delete_qos"); |
| 2953 | fprintf(f, "2 4\n"); |
| 2954 | fclose(f); |
| 2955 | } |
| 2956 | #endif /* __linux__ */ |
| 2957 | |
| 2958 | return 0; |
| 2959 | } |
| 2960 | |
| 2961 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 2962 | static enum sigma_cmd_result cmd_sta_set_uapsd(struct sigma_dut *dut, |
| 2963 | struct sigma_conn *conn, |
| 2964 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2965 | { |
| 2966 | const char *intf = get_param(cmd, "Interface"); |
| 2967 | /* const char *ssid = get_param(cmd, "ssid"); */ |
| 2968 | const char *val; |
| 2969 | int max_sp_len = 4; |
| 2970 | int ac_be = 1, ac_bk = 1, ac_vi = 1, ac_vo = 1; |
| 2971 | char buf[100]; |
| 2972 | int ret1, ret2; |
| 2973 | |
| 2974 | val = get_param(cmd, "maxSPLength"); |
| 2975 | if (val) { |
| 2976 | max_sp_len = atoi(val); |
| 2977 | if (max_sp_len != 0 && max_sp_len != 1 && max_sp_len != 2 && |
| 2978 | max_sp_len != 4) |
| 2979 | return -1; |
| 2980 | } |
| 2981 | |
| 2982 | val = get_param(cmd, "acBE"); |
| 2983 | if (val) |
| 2984 | ac_be = atoi(val); |
| 2985 | |
| 2986 | val = get_param(cmd, "acBK"); |
| 2987 | if (val) |
| 2988 | ac_bk = atoi(val); |
| 2989 | |
| 2990 | val = get_param(cmd, "acVI"); |
| 2991 | if (val) |
| 2992 | ac_vi = atoi(val); |
| 2993 | |
| 2994 | val = get_param(cmd, "acVO"); |
| 2995 | if (val) |
| 2996 | ac_vo = atoi(val); |
| 2997 | |
| 2998 | dut->client_uapsd = ac_be || ac_bk || ac_vi || ac_vo; |
| 2999 | |
| 3000 | snprintf(buf, sizeof(buf), "P2P_SET client_apsd %d,%d,%d,%d;%d", |
| 3001 | ac_be, ac_bk, ac_vi, ac_vo, max_sp_len); |
| 3002 | ret1 = wpa_command(intf, buf); |
| 3003 | |
| 3004 | snprintf(buf, sizeof(buf), "SET uapsd %d,%d,%d,%d;%d", |
| 3005 | ac_be, ac_bk, ac_vi, ac_vo, max_sp_len); |
| 3006 | ret2 = wpa_command(intf, buf); |
| 3007 | |
| 3008 | if (ret1 && ret2) { |
| 3009 | sigma_dut_print(dut, DUT_MSG_INFO, "Failed to set client mode " |
| 3010 | "UAPSD parameters."); |
| 3011 | return -2; |
| 3012 | } |
| 3013 | |
| 3014 | if (ath6kl_client_uapsd(dut, intf, dut->client_uapsd) < 0) { |
| 3015 | send_resp(dut, conn, SIGMA_ERROR, |
| 3016 | "ErrorCode,Failed to set ath6kl QoS parameters"); |
| 3017 | return 0; |
| 3018 | } |
| 3019 | |
| 3020 | return 1; |
| 3021 | } |
| 3022 | |
| 3023 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 3024 | static enum sigma_cmd_result cmd_sta_set_wmm(struct sigma_dut *dut, |
| 3025 | struct sigma_conn *conn, |
| 3026 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3027 | { |
| 3028 | char buf[1000]; |
| 3029 | const char *intf = get_param(cmd, "Interface"); |
| 3030 | const char *grp = get_param(cmd, "Group"); |
| 3031 | const char *act = get_param(cmd, "Action"); |
| 3032 | const char *tid = get_param(cmd, "Tid"); |
| 3033 | const char *dir = get_param(cmd, "Direction"); |
| 3034 | const char *psb = get_param(cmd, "Psb"); |
| 3035 | const char *up = get_param(cmd, "Up"); |
| 3036 | const char *fixed = get_param(cmd, "Fixed"); |
| 3037 | const char *size = get_param(cmd, "Size"); |
| 3038 | const char *msize = get_param(cmd, "Maxsize"); |
| 3039 | const char *minsi = get_param(cmd, "Min_srvc_intrvl"); |
| 3040 | const char *maxsi = get_param(cmd, "Max_srvc_intrvl"); |
| 3041 | const char *inact = get_param(cmd, "Inactivity"); |
| 3042 | const char *sus = get_param(cmd, "Suspension"); |
| 3043 | const char *mindr = get_param(cmd, "Mindatarate"); |
| 3044 | const char *meandr = get_param(cmd, "Meandatarate"); |
| 3045 | const char *peakdr = get_param(cmd, "Peakdatarate"); |
| 3046 | const char *phyrate = get_param(cmd, "Phyrate"); |
| 3047 | const char *burstsize = get_param(cmd, "Burstsize"); |
| 3048 | const char *sba = get_param(cmd, "Sba"); |
| 3049 | int direction; |
| 3050 | int handle; |
Peng Xu | 9331962 | 2017-10-04 17:58:16 -0700 | [diff] [blame] | 3051 | float sba_fv = 0; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3052 | int fixed_int; |
| 3053 | int psb_ts; |
| 3054 | |
| 3055 | if (intf == NULL || grp == NULL || act == NULL ) |
| 3056 | return -1; |
| 3057 | |
| 3058 | if (strcasecmp(act, "addts") == 0) { |
| 3059 | if (tid == NULL || dir == NULL || psb == NULL || |
| 3060 | up == NULL || fixed == NULL || size == NULL) |
| 3061 | return -1; |
| 3062 | |
| 3063 | /* |
| 3064 | * Note: Sigma CAPI spec lists uplink, downlink, and bidi as the |
| 3065 | * possible values, but WMM-AC and V-E test scripts use "UP, |
| 3066 | * "DOWN", and "BIDI". |
| 3067 | */ |
| 3068 | if (strcasecmp(dir, "uplink") == 0 || |
| 3069 | strcasecmp(dir, "up") == 0) { |
| 3070 | direction = 0; |
| 3071 | } else if (strcasecmp(dir, "downlink") == 0 || |
| 3072 | strcasecmp(dir, "down") == 0) { |
| 3073 | direction = 1; |
| 3074 | } else if (strcasecmp(dir, "bidi") == 0) { |
| 3075 | direction = 2; |
| 3076 | } else { |
| 3077 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3078 | "Direction %s not supported", dir); |
| 3079 | return -1; |
| 3080 | } |
| 3081 | |
| 3082 | if (strcasecmp(psb, "legacy") == 0) { |
| 3083 | psb_ts = 0; |
| 3084 | } else if (strcasecmp(psb, "uapsd") == 0) { |
| 3085 | psb_ts = 1; |
| 3086 | } else { |
| 3087 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3088 | "PSB %s not supported", psb); |
| 3089 | return -1; |
| 3090 | } |
| 3091 | |
| 3092 | if (atoi(tid) < 0 || atoi(tid) > 7) { |
| 3093 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3094 | "TID %s not supported", tid); |
| 3095 | return -1; |
| 3096 | } |
| 3097 | |
| 3098 | if (strcasecmp(fixed, "true") == 0) { |
| 3099 | fixed_int = 1; |
| 3100 | } else { |
| 3101 | fixed_int = 0; |
| 3102 | } |
| 3103 | |
Peng Xu | 9331962 | 2017-10-04 17:58:16 -0700 | [diff] [blame] | 3104 | if (sba) |
| 3105 | sba_fv = atof(sba); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3106 | |
| 3107 | dut->dialog_token++; |
| 3108 | handle = 7000 + dut->dialog_token; |
| 3109 | |
| 3110 | /* |
| 3111 | * size: convert to hex |
| 3112 | * maxsi: convert to hex |
| 3113 | * mindr: convert to hex |
| 3114 | * meandr: convert to hex |
| 3115 | * peakdr: convert to hex |
| 3116 | * burstsize: convert to hex |
| 3117 | * phyrate: convert to hex |
| 3118 | * sba: convert to hex with modification |
| 3119 | * minsi: convert to integer |
| 3120 | * sus: convert to integer |
| 3121 | * inact: convert to integer |
| 3122 | * maxsi: convert to integer |
| 3123 | */ |
| 3124 | |
| 3125 | /* |
| 3126 | * The Nominal MSDU Size field is 2 octets long and contains an |
| 3127 | * unsigned integer that specifies the nominal size, in octets, |
| 3128 | * of MSDUs belonging to the traffic under this traffic |
| 3129 | * specification and is defined in Figure 16. If the Fixed |
| 3130 | * subfield is set to 1, then the size of the MSDU is fixed and |
| 3131 | * is indicated by the Size Subfield. If the Fixed subfield is |
| 3132 | * set to 0, then the size of the MSDU might not be fixed and |
| 3133 | * the Size indicates the nominal MSDU size. |
| 3134 | * |
| 3135 | * The Surplus Bandwidth Allowance Factor field is 2 octets long |
| 3136 | * and specifies the excess allocation of time (and bandwidth) |
| 3137 | * over and above the stated rates required to transport an MSDU |
| 3138 | * belonging to the traffic in this TSPEC. This field is |
| 3139 | * represented as an unsigned binary number with an implicit |
| 3140 | * binary point after the leftmost 3 bits. For example, an SBA |
| 3141 | * of 1.75 is represented as 0x3800. This field is included to |
| 3142 | * account for retransmissions. As such, the value of this field |
| 3143 | * must be greater than unity. |
| 3144 | */ |
| 3145 | |
| 3146 | snprintf(buf, sizeof(buf), |
| 3147 | "iwpriv %s addTspec %d %s %d %d %s 0x%X" |
| 3148 | " 0x%X 0x%X 0x%X" |
| 3149 | " 0x%X 0x%X 0x%X" |
| 3150 | " 0x%X %d %d %d %d" |
| 3151 | " %d %d", |
| 3152 | intf, handle, tid, direction, psb_ts, up, |
| 3153 | (unsigned int) ((fixed_int << 15) | atoi(size)), |
| 3154 | msize ? atoi(msize) : 0, |
| 3155 | mindr ? atoi(mindr) : 0, |
| 3156 | meandr ? atoi(meandr) : 0, |
| 3157 | peakdr ? atoi(peakdr) : 0, |
| 3158 | burstsize ? atoi(burstsize) : 0, |
| 3159 | phyrate ? atoi(phyrate) : 0, |
| 3160 | sba ? ((unsigned int) (((int) sba_fv << 13) | |
| 3161 | (int)((sba_fv - (int) sba_fv) * |
| 3162 | 8192))) : 0, |
| 3163 | minsi ? atoi(minsi) : 0, |
| 3164 | sus ? atoi(sus) : 0, |
| 3165 | 0, 0, |
| 3166 | inact ? atoi(inact) : 0, |
| 3167 | maxsi ? atoi(maxsi) : 0); |
| 3168 | |
| 3169 | if (system(buf) != 0) { |
| 3170 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3171 | "iwpriv addtspec request failed"); |
| 3172 | send_resp(dut, conn, SIGMA_ERROR, |
| 3173 | "errorCode,Failed to execute addTspec command"); |
| 3174 | return 0; |
| 3175 | } |
| 3176 | |
| 3177 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 3178 | "iwpriv addtspec request send"); |
| 3179 | |
| 3180 | /* Mapping handle to a TID */ |
| 3181 | dut->tid_to_handle[atoi(tid)] = handle; |
| 3182 | } else if (strcasecmp(act, "delts") == 0) { |
| 3183 | if (tid == NULL) |
| 3184 | return -1; |
| 3185 | |
| 3186 | if (atoi(tid) < 0 || atoi(tid) > 7) { |
| 3187 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3188 | "TID %s not supported", tid); |
| 3189 | send_resp(dut, conn, SIGMA_ERROR, |
| 3190 | "errorCode,Unsupported TID"); |
| 3191 | return 0; |
| 3192 | } |
| 3193 | |
| 3194 | handle = dut->tid_to_handle[atoi(tid)]; |
| 3195 | |
| 3196 | if (handle < 7000 || handle > 7255) { |
| 3197 | /* Invalid handle ie no mapping for that TID */ |
| 3198 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3199 | "handle-> %d not found", handle); |
| 3200 | } |
| 3201 | |
| 3202 | snprintf(buf, sizeof(buf), "iwpriv %s delTspec %d", |
| 3203 | intf, handle); |
| 3204 | |
| 3205 | if (system(buf) != 0) { |
| 3206 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3207 | "iwpriv deltspec request failed"); |
| 3208 | send_resp(dut, conn, SIGMA_ERROR, |
| 3209 | "errorCode,Failed to execute delTspec command"); |
| 3210 | return 0; |
| 3211 | } |
| 3212 | |
| 3213 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 3214 | "iwpriv deltspec request send"); |
| 3215 | |
| 3216 | dut->tid_to_handle[atoi(tid)] = 0; |
| 3217 | } else { |
| 3218 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3219 | "Action type %s not supported", act); |
| 3220 | send_resp(dut, conn, SIGMA_ERROR, |
| 3221 | "errorCode,Unsupported Action"); |
| 3222 | return 0; |
| 3223 | } |
| 3224 | |
| 3225 | return 1; |
| 3226 | } |
| 3227 | |
| 3228 | |
vamsi krishna | 52e16f9 | 2017-08-29 12:37:34 +0530 | [diff] [blame] | 3229 | static int find_network(struct sigma_dut *dut, const char *ssid) |
| 3230 | { |
| 3231 | char list[4096]; |
| 3232 | char *pos; |
| 3233 | |
| 3234 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 3235 | "Search for profile based on SSID: '%s'", ssid); |
| 3236 | if (wpa_command_resp(get_station_ifname(), "LIST_NETWORKS", |
| 3237 | list, sizeof(list)) < 0) |
| 3238 | return -1; |
| 3239 | pos = strstr(list, ssid); |
| 3240 | if (!pos || pos == list || pos[-1] != '\t' || pos[strlen(ssid)] != '\t') |
| 3241 | return -1; |
| 3242 | |
| 3243 | while (pos > list && pos[-1] != '\n') |
| 3244 | pos--; |
| 3245 | dut->infra_network_id = atoi(pos); |
| 3246 | snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid); |
| 3247 | return 0; |
| 3248 | } |
| 3249 | |
| 3250 | |
Sunil Dutt | 4459508 | 2018-02-12 19:41:45 +0530 | [diff] [blame] | 3251 | #ifdef NL80211_SUPPORT |
| 3252 | static int sta_config_rsnie(struct sigma_dut *dut, int val) |
| 3253 | { |
| 3254 | struct nl_msg *msg; |
| 3255 | int ret; |
| 3256 | struct nlattr *params; |
| 3257 | int ifindex; |
| 3258 | |
| 3259 | ifindex = if_nametoindex("wlan0"); |
| 3260 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 3261 | NL80211_CMD_VENDOR)) || |
| 3262 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 3263 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 3264 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 3265 | QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) || |
| 3266 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 3267 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE, val)) { |
| 3268 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3269 | "%s: err in adding vendor_cmd and vendor_data", |
| 3270 | __func__); |
| 3271 | nlmsg_free(msg); |
| 3272 | return -1; |
| 3273 | } |
| 3274 | nla_nest_end(msg, params); |
| 3275 | |
| 3276 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 3277 | if (ret) { |
| 3278 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3279 | "%s: err in send_and_recv_msgs, ret=%d", |
| 3280 | __func__, ret); |
| 3281 | return ret; |
| 3282 | } |
| 3283 | |
| 3284 | return 0; |
| 3285 | } |
| 3286 | #endif /* NL80211_SUPPORT */ |
| 3287 | |
| 3288 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 3289 | static enum sigma_cmd_result cmd_sta_associate(struct sigma_dut *dut, |
| 3290 | struct sigma_conn *conn, |
| 3291 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3292 | { |
| 3293 | /* const char *intf = get_param(cmd, "Interface"); */ |
| 3294 | const char *ssid = get_param(cmd, "ssid"); |
| 3295 | const char *wps_param = get_param(cmd, "WPS"); |
| 3296 | const char *bssid = get_param(cmd, "bssid"); |
Jouni Malinen | 46a19b6 | 2017-06-23 14:31:27 +0300 | [diff] [blame] | 3297 | const char *chan = get_param(cmd, "channel"); |
Alexei Avshalom Lazar | d596b51 | 2018-12-18 16:00:59 +0200 | [diff] [blame] | 3298 | const char *network_mode = get_param(cmd, "network_mode"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3299 | int wps = 0; |
Jouni Malinen | 3c367e8 | 2017-06-23 17:01:47 +0300 | [diff] [blame] | 3300 | char buf[1000], extra[50]; |
Jouni Malinen | 134fe3c | 2019-06-12 04:16:49 +0300 | [diff] [blame] | 3301 | int e; |
| 3302 | enum sigma_cmd_result ret = SUCCESS_SEND_STATUS; |
| 3303 | struct wpa_ctrl *ctrl = NULL; |
| 3304 | int num_network_not_found = 0; |
| 3305 | int num_disconnected = 0; |
| 3306 | int tod = -1; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3307 | |
| 3308 | if (ssid == NULL) |
| 3309 | return -1; |
| 3310 | |
Jouni Malinen | 37d5c69 | 2019-08-19 16:56:55 +0300 | [diff] [blame] | 3311 | dut->server_cert_tod = 0; |
| 3312 | |
Jouni Malinen | 3c367e8 | 2017-06-23 17:01:47 +0300 | [diff] [blame] | 3313 | if (dut->rsne_override) { |
Sunil Dutt | 4459508 | 2018-02-12 19:41:45 +0530 | [diff] [blame] | 3314 | #ifdef NL80211_SUPPORT |
| 3315 | if (get_driver_type() == DRIVER_WCN) { |
| 3316 | sta_config_rsnie(dut, 1); |
| 3317 | dut->config_rsnie = 1; |
| 3318 | } |
| 3319 | #endif /* NL80211_SUPPORT */ |
Jouni Malinen | 3c367e8 | 2017-06-23 17:01:47 +0300 | [diff] [blame] | 3320 | snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s", |
| 3321 | dut->rsne_override); |
| 3322 | if (wpa_command(get_station_ifname(), buf) < 0) { |
| 3323 | send_resp(dut, conn, SIGMA_ERROR, |
| 3324 | "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override"); |
| 3325 | return 0; |
| 3326 | } |
| 3327 | } |
| 3328 | |
Jouni Malinen | 6814313 | 2017-09-02 02:34:08 +0300 | [diff] [blame] | 3329 | if (dut->sae_commit_override) { |
| 3330 | snprintf(buf, sizeof(buf), "SET sae_commit_override %s", |
| 3331 | dut->sae_commit_override); |
| 3332 | if (wpa_command(get_station_ifname(), buf) < 0) { |
| 3333 | send_resp(dut, conn, SIGMA_ERROR, |
| 3334 | "ErrorCode,Failed to set SAE commit override"); |
| 3335 | return 0; |
| 3336 | } |
| 3337 | } |
Ankita Bajaj | 1bde794 | 2018-01-09 19:15:01 +0530 | [diff] [blame] | 3338 | #ifdef ANDROID |
| 3339 | if (dut->fils_hlp) |
| 3340 | process_fils_hlp(dut); |
| 3341 | #endif /* ANDROID */ |
Jouni Malinen | 6814313 | 2017-09-02 02:34:08 +0300 | [diff] [blame] | 3342 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3343 | if (wps_param && |
| 3344 | (strcmp(wps_param, "1") == 0 || strcasecmp(wps_param, "On") == 0)) |
| 3345 | wps = 1; |
| 3346 | |
| 3347 | if (wps) { |
Alexei Avshalom Lazar | d596b51 | 2018-12-18 16:00:59 +0200 | [diff] [blame] | 3348 | if (dut->program == PROGRAM_60GHZ && network_mode && |
| 3349 | strcasecmp(network_mode, "PBSS") == 0 && |
| 3350 | set_network(get_station_ifname(), dut->infra_network_id, |
| 3351 | "pbss", "1") < 0) |
| 3352 | return -2; |
| 3353 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3354 | if (dut->wps_method == WFA_CS_WPS_NOT_READY) { |
| 3355 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,WPS " |
| 3356 | "parameters not yet set"); |
| 3357 | return 0; |
| 3358 | } |
| 3359 | if (dut->wps_method == WFA_CS_WPS_PBC) { |
| 3360 | if (wpa_command(get_station_ifname(), "WPS_PBC") < 0) |
| 3361 | return -2; |
| 3362 | } else { |
| 3363 | snprintf(buf, sizeof(buf), "WPS_PIN any %s", |
| 3364 | dut->wps_pin); |
| 3365 | if (wpa_command(get_station_ifname(), buf) < 0) |
| 3366 | return -2; |
| 3367 | } |
| 3368 | } else { |
vamsi krishna | 52e16f9 | 2017-08-29 12:37:34 +0530 | [diff] [blame] | 3369 | if (strcmp(ssid, dut->infra_ssid) == 0) { |
| 3370 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 3371 | "sta_associate for the most recently added network"); |
| 3372 | } else if (find_network(dut, ssid) < 0) { |
| 3373 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 3374 | "sta_associate for a previously stored network profile"); |
| 3375 | send_resp(dut, conn, SIGMA_ERROR, |
| 3376 | "ErrorCode,Profile not found"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3377 | return 0; |
| 3378 | } |
| 3379 | |
| 3380 | if (bssid && |
| 3381 | set_network(get_station_ifname(), dut->infra_network_id, |
| 3382 | "bssid", bssid) < 0) { |
| 3383 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode," |
| 3384 | "Invalid bssid argument"); |
| 3385 | return 0; |
| 3386 | } |
| 3387 | |
Jouni Malinen | 134fe3c | 2019-06-12 04:16:49 +0300 | [diff] [blame] | 3388 | if (dut->program == PROGRAM_WPA3 && |
| 3389 | dut->sta_associate_wait_connect) { |
| 3390 | ctrl = open_wpa_mon(get_station_ifname()); |
| 3391 | if (!ctrl) |
| 3392 | return ERROR_SEND_STATUS; |
| 3393 | } |
| 3394 | |
Jouni Malinen | 46a19b6 | 2017-06-23 14:31:27 +0300 | [diff] [blame] | 3395 | extra[0] = '\0'; |
| 3396 | if (chan) |
| 3397 | snprintf(extra, sizeof(extra), " freq=%u", |
Alexei Avshalom Lazar | 093569f | 2018-11-13 14:08:17 +0200 | [diff] [blame] | 3398 | channel_to_freq(dut, atoi(chan))); |
Jouni Malinen | 46a19b6 | 2017-06-23 14:31:27 +0300 | [diff] [blame] | 3399 | snprintf(buf, sizeof(buf), "SELECT_NETWORK %d%s", |
| 3400 | dut->infra_network_id, extra); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3401 | if (wpa_command(get_station_ifname(), buf) < 0) { |
| 3402 | sigma_dut_print(dut, DUT_MSG_INFO, "Failed to select " |
| 3403 | "network id %d on %s", |
| 3404 | dut->infra_network_id, |
| 3405 | get_station_ifname()); |
Jouni Malinen | 134fe3c | 2019-06-12 04:16:49 +0300 | [diff] [blame] | 3406 | ret = ERROR_SEND_STATUS; |
| 3407 | goto done; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3408 | } |
| 3409 | } |
| 3410 | |
Jouni Malinen | 134fe3c | 2019-06-12 04:16:49 +0300 | [diff] [blame] | 3411 | if (!ctrl) |
| 3412 | return SUCCESS_SEND_STATUS; |
| 3413 | |
| 3414 | /* Wait for connection result to be able to store server certificate |
| 3415 | * hash for trust root override testing |
| 3416 | * (dev_exec_action,ServerCertTrust). */ |
| 3417 | |
| 3418 | for (e = 0; e < 20; e++) { |
| 3419 | const char *events[] = { |
| 3420 | "CTRL-EVENT-EAP-PEER-CERT", |
| 3421 | "CTRL-EVENT-EAP-TLS-CERT-ERROR", |
| 3422 | "CTRL-EVENT-DISCONNECTED", |
| 3423 | "CTRL-EVENT-CONNECTED", |
| 3424 | "CTRL-EVENT-NETWORK-NOT-FOUND", |
| 3425 | NULL |
| 3426 | }; |
| 3427 | char buf[1024]; |
| 3428 | int res; |
| 3429 | |
| 3430 | res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf)); |
| 3431 | if (res < 0) { |
| 3432 | send_resp(dut, conn, SIGMA_ERROR, |
| 3433 | "ErrorCode,Association did not complete"); |
| 3434 | ret = STATUS_SENT_ERROR; |
| 3435 | break; |
| 3436 | } |
| 3437 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Connection event: %s", |
| 3438 | buf); |
| 3439 | |
| 3440 | if (strstr(buf, "CTRL-EVENT-EAP-PEER-CERT") && |
| 3441 | strstr(buf, " depth=0")) { |
| 3442 | char *pos = strstr(buf, " hash="); |
| 3443 | |
| 3444 | if (pos) { |
| 3445 | char *end; |
| 3446 | |
Jouni Malinen | 34b19cb | 2019-08-16 16:37:17 +0300 | [diff] [blame] | 3447 | if (strstr(buf, " tod=1")) |
| 3448 | tod = 1; |
| 3449 | else if (strstr(buf, " tod=2")) |
| 3450 | tod = 2; |
| 3451 | else |
| 3452 | tod = 0; |
Jouni Malinen | 134fe3c | 2019-06-12 04:16:49 +0300 | [diff] [blame] | 3453 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 3454 | "Server certificate TOD policy: %d", |
| 3455 | tod); |
Jouni Malinen | 37d5c69 | 2019-08-19 16:56:55 +0300 | [diff] [blame] | 3456 | dut->server_cert_tod = tod; |
Jouni Malinen | 134fe3c | 2019-06-12 04:16:49 +0300 | [diff] [blame] | 3457 | |
| 3458 | pos += 6; |
| 3459 | end = strchr(pos, ' '); |
| 3460 | if (end) |
| 3461 | *end = '\0'; |
| 3462 | strlcpy(dut->server_cert_hash, pos, |
| 3463 | sizeof(dut->server_cert_hash)); |
| 3464 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 3465 | "Server certificate hash: %s", |
| 3466 | dut->server_cert_hash); |
| 3467 | } |
| 3468 | } |
| 3469 | |
| 3470 | if (strstr(buf, "CTRL-EVENT-EAP-TLS-CERT-ERROR")) { |
| 3471 | send_resp(dut, conn, SIGMA_COMPLETE, |
| 3472 | "Result,TLS server certificate validation failed"); |
| 3473 | ret = STATUS_SENT_ERROR; |
| 3474 | break; |
| 3475 | } |
| 3476 | |
| 3477 | if (strstr(buf, "CTRL-EVENT-NETWORK-NOT-FOUND")) { |
| 3478 | num_network_not_found++; |
| 3479 | |
| 3480 | if (num_network_not_found > 2) { |
| 3481 | send_resp(dut, conn, SIGMA_COMPLETE, |
| 3482 | "Result,Network not found"); |
| 3483 | ret = STATUS_SENT_ERROR; |
| 3484 | break; |
| 3485 | } |
| 3486 | } |
| 3487 | |
| 3488 | if (strstr(buf, "CTRL-EVENT-DISCONNECTED")) { |
| 3489 | num_disconnected++; |
| 3490 | |
| 3491 | if (num_disconnected > 2) { |
| 3492 | send_resp(dut, conn, SIGMA_COMPLETE, |
| 3493 | "Result,Connection failed"); |
| 3494 | ret = STATUS_SENT_ERROR; |
| 3495 | break; |
| 3496 | } |
| 3497 | } |
| 3498 | |
| 3499 | if (strstr(buf, "CTRL-EVENT-CONNECTED")) { |
| 3500 | if (tod >= 0) { |
| 3501 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 3502 | "Network profile TOD policy update: %d -> %d", |
| 3503 | dut->sta_tod_policy, tod); |
| 3504 | dut->sta_tod_policy = tod; |
| 3505 | } |
| 3506 | break; |
| 3507 | } |
| 3508 | } |
| 3509 | done: |
| 3510 | if (ctrl) { |
| 3511 | wpa_ctrl_detach(ctrl); |
| 3512 | wpa_ctrl_close(ctrl); |
| 3513 | } |
| 3514 | return ret; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3515 | } |
| 3516 | |
| 3517 | |
| 3518 | static int run_hs20_osu(struct sigma_dut *dut, const char *params) |
| 3519 | { |
| 3520 | char buf[500], cmd[200]; |
| 3521 | int res; |
| 3522 | |
| 3523 | /* Use hs20-osu-client file at the current dir, if found; otherwise use |
| 3524 | * default path */ |
| 3525 | res = snprintf(cmd, sizeof(cmd), |
| 3526 | "%s -w \"%s\" -r hs20-osu-client.res %s%s -dddKt -f Logs/hs20-osu-client.txt", |
| 3527 | file_exists("./hs20-osu-client") ? |
| 3528 | "./hs20-osu-client" : "hs20-osu-client", |
| 3529 | sigma_wpas_ctrl, |
| 3530 | dut->summary_log ? "-s " : "", |
| 3531 | dut->summary_log ? dut->summary_log : ""); |
| 3532 | if (res < 0 || res >= (int) sizeof(cmd)) |
| 3533 | return -1; |
| 3534 | |
| 3535 | res = snprintf(buf, sizeof(buf), "%s %s", cmd, params); |
| 3536 | if (res < 0 || res >= (int) sizeof(buf)) |
| 3537 | return -1; |
| 3538 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 3539 | |
| 3540 | if (system(buf) != 0) { |
| 3541 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run: %s", buf); |
| 3542 | return -1; |
| 3543 | } |
| 3544 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 3545 | "Completed hs20-osu-client operation"); |
| 3546 | |
| 3547 | return 0; |
| 3548 | } |
| 3549 | |
| 3550 | |
| 3551 | static int download_ppsmo(struct sigma_dut *dut, |
| 3552 | struct sigma_conn *conn, |
| 3553 | const char *intf, |
| 3554 | struct sigma_cmd *cmd) |
| 3555 | { |
| 3556 | const char *name, *path, *val; |
| 3557 | char url[500], buf[600], fbuf[100]; |
| 3558 | char *fqdn = NULL; |
| 3559 | |
| 3560 | name = get_param(cmd, "FileName"); |
| 3561 | path = get_param(cmd, "FilePath"); |
| 3562 | if (name == NULL || path == NULL) |
| 3563 | return -1; |
| 3564 | |
| 3565 | if (strcasecmp(path, "VendorSpecific") == 0) { |
| 3566 | snprintf(url, sizeof(url), "PPS/%s", name); |
| 3567 | sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured PPS MO " |
| 3568 | "from the device (%s)", url); |
| 3569 | if (!file_exists(url)) { |
| 3570 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested " |
| 3571 | "PPS MO file does not exist"); |
| 3572 | return 0; |
| 3573 | } |
| 3574 | snprintf(buf, sizeof(buf), "cp %s pps-tnds.xml", url); |
| 3575 | if (system(buf) != 0) { |
| 3576 | send_resp(dut, conn, SIGMA_ERROR, |
| 3577 | "errorCode,Failed to copy PPS MO"); |
| 3578 | return 0; |
| 3579 | } |
| 3580 | } else if (strncasecmp(path, "http:", 5) != 0 && |
| 3581 | strncasecmp(path, "https:", 6) != 0) { |
| 3582 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode," |
| 3583 | "Unsupported FilePath value"); |
| 3584 | return 0; |
| 3585 | } else { |
| 3586 | snprintf(url, sizeof(url), "%s/%s", path, name); |
| 3587 | sigma_dut_print(dut, DUT_MSG_INFO, "Downloading PPS MO from %s", |
| 3588 | url); |
| 3589 | snprintf(buf, sizeof(buf), "wget -T 10 -t 3 -O pps-tnds.xml '%s'", url); |
| 3590 | remove("pps-tnds.xml"); |
| 3591 | if (system(buf) != 0) { |
| 3592 | send_resp(dut, conn, SIGMA_ERROR, |
| 3593 | "errorCode,Failed to download PPS MO"); |
| 3594 | return 0; |
| 3595 | } |
| 3596 | } |
| 3597 | |
| 3598 | if (run_hs20_osu(dut, "from_tnds pps-tnds.xml pps.xml") < 0) { |
| 3599 | send_resp(dut, conn, SIGMA_ERROR, |
| 3600 | "errorCode,Failed to parse downloaded PPSMO"); |
| 3601 | return 0; |
| 3602 | } |
| 3603 | unlink("pps-tnds.xml"); |
| 3604 | |
| 3605 | val = get_param(cmd, "managementTreeURI"); |
| 3606 | if (val) { |
| 3607 | const char *pos, *end; |
| 3608 | sigma_dut_print(dut, DUT_MSG_DEBUG, "managementTreeURI: %s", |
| 3609 | val); |
| 3610 | if (strncmp(val, "./Wi-Fi/", 8) != 0) { |
| 3611 | send_resp(dut, conn, SIGMA_ERROR, |
| 3612 | "errorCode,Invalid managementTreeURI prefix"); |
| 3613 | return 0; |
| 3614 | } |
| 3615 | pos = val + 8; |
| 3616 | end = strchr(pos, '/'); |
| 3617 | if (end == NULL || |
| 3618 | strcmp(end, "/PerProviderSubscription") != 0) { |
| 3619 | send_resp(dut, conn, SIGMA_ERROR, |
| 3620 | "errorCode,Invalid managementTreeURI postfix"); |
| 3621 | return 0; |
| 3622 | } |
| 3623 | if (end - pos >= (int) sizeof(fbuf)) { |
| 3624 | send_resp(dut, conn, SIGMA_ERROR, |
| 3625 | "errorCode,Too long FQDN in managementTreeURI"); |
| 3626 | return 0; |
| 3627 | } |
| 3628 | memcpy(fbuf, pos, end - pos); |
| 3629 | fbuf[end - pos] = '\0'; |
| 3630 | fqdn = fbuf; |
| 3631 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 3632 | "FQDN from managementTreeURI: %s", fqdn); |
| 3633 | } else if (run_hs20_osu(dut, "get_fqdn pps.xml") == 0) { |
| 3634 | FILE *f = fopen("pps-fqdn", "r"); |
| 3635 | if (f) { |
| 3636 | if (fgets(fbuf, sizeof(fbuf), f)) { |
| 3637 | fbuf[sizeof(fbuf) - 1] = '\0'; |
| 3638 | fqdn = fbuf; |
| 3639 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 3640 | "Use FQDN %s", fqdn); |
| 3641 | } |
| 3642 | fclose(f); |
| 3643 | } |
| 3644 | } |
| 3645 | |
| 3646 | if (fqdn == NULL) { |
| 3647 | send_resp(dut, conn, SIGMA_ERROR, |
| 3648 | "errorCode,No FQDN specified"); |
| 3649 | return 0; |
| 3650 | } |
| 3651 | |
| 3652 | mkdir("SP", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); |
| 3653 | snprintf(buf, sizeof(buf), "SP/%s", fqdn); |
| 3654 | mkdir(buf, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); |
| 3655 | |
| 3656 | snprintf(buf, sizeof(buf), "SP/%s/pps.xml", fqdn); |
| 3657 | if (rename("pps.xml", buf) < 0) { |
| 3658 | send_resp(dut, conn, SIGMA_ERROR, |
| 3659 | "errorCode,Could not move PPS MO"); |
| 3660 | return 0; |
| 3661 | } |
| 3662 | |
| 3663 | if (strcasecmp(path, "VendorSpecific") == 0) { |
| 3664 | snprintf(buf, sizeof(buf), "cp Certs/ca.pem SP/%s/ca.pem", |
| 3665 | fqdn); |
| 3666 | if (system(buf)) { |
| 3667 | send_resp(dut, conn, SIGMA_ERROR, |
| 3668 | "errorCode,Failed to copy OSU CA cert"); |
| 3669 | return 0; |
| 3670 | } |
| 3671 | |
| 3672 | snprintf(buf, sizeof(buf), |
| 3673 | "cp Certs/aaa-ca.pem SP/%s/aaa-ca.pem", |
| 3674 | fqdn); |
| 3675 | if (system(buf)) { |
| 3676 | send_resp(dut, conn, SIGMA_ERROR, |
| 3677 | "errorCode,Failed to copy AAA CA cert"); |
| 3678 | return 0; |
| 3679 | } |
| 3680 | } else { |
| 3681 | snprintf(buf, sizeof(buf), |
| 3682 | "dl_osu_ca SP/%s/pps.xml SP/%s/ca.pem", |
| 3683 | fqdn, fqdn); |
| 3684 | if (run_hs20_osu(dut, buf) < 0) { |
| 3685 | send_resp(dut, conn, SIGMA_ERROR, |
| 3686 | "errorCode,Failed to download OSU CA cert"); |
| 3687 | return 0; |
| 3688 | } |
| 3689 | |
| 3690 | snprintf(buf, sizeof(buf), |
| 3691 | "dl_aaa_ca SP/%s/pps.xml SP/%s/aaa-ca.pem", |
| 3692 | fqdn, fqdn); |
| 3693 | if (run_hs20_osu(dut, buf) < 0) { |
| 3694 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 3695 | "Failed to download AAA CA cert"); |
| 3696 | } |
| 3697 | } |
| 3698 | |
| 3699 | if (file_exists("next-client-cert.pem")) { |
| 3700 | snprintf(buf, sizeof(buf), "SP/%s/client-cert.pem", fqdn); |
| 3701 | if (rename("next-client-cert.pem", buf) < 0) { |
| 3702 | send_resp(dut, conn, SIGMA_ERROR, |
| 3703 | "errorCode,Could not move client certificate"); |
| 3704 | return 0; |
| 3705 | } |
| 3706 | } |
| 3707 | |
| 3708 | if (file_exists("next-client-key.pem")) { |
| 3709 | snprintf(buf, sizeof(buf), "SP/%s/client-key.pem", fqdn); |
| 3710 | if (rename("next-client-key.pem", buf) < 0) { |
| 3711 | send_resp(dut, conn, SIGMA_ERROR, |
| 3712 | "errorCode,Could not move client key"); |
| 3713 | return 0; |
| 3714 | } |
| 3715 | } |
| 3716 | |
| 3717 | snprintf(buf, sizeof(buf), "set_pps SP/%s/pps.xml", fqdn); |
| 3718 | if (run_hs20_osu(dut, buf) < 0) { |
| 3719 | send_resp(dut, conn, SIGMA_ERROR, |
| 3720 | "errorCode,Failed to configure credential from " |
| 3721 | "PPSMO"); |
| 3722 | return 0; |
| 3723 | } |
| 3724 | |
| 3725 | return 1; |
| 3726 | } |
| 3727 | |
| 3728 | |
| 3729 | static int download_cert(struct sigma_dut *dut, |
| 3730 | struct sigma_conn *conn, |
| 3731 | const char *intf, |
| 3732 | struct sigma_cmd *cmd) |
| 3733 | { |
| 3734 | const char *name, *path; |
| 3735 | char url[500], buf[600]; |
| 3736 | |
| 3737 | name = get_param(cmd, "FileName"); |
| 3738 | path = get_param(cmd, "FilePath"); |
| 3739 | if (name == NULL || path == NULL) |
| 3740 | return -1; |
| 3741 | |
| 3742 | if (strcasecmp(path, "VendorSpecific") == 0) { |
| 3743 | snprintf(url, sizeof(url), "Certs/%s-cert.pem", name); |
| 3744 | sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client " |
| 3745 | "certificate from the device (%s)", url); |
| 3746 | if (!file_exists(url)) { |
| 3747 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested " |
| 3748 | "certificate file does not exist"); |
| 3749 | return 0; |
| 3750 | } |
| 3751 | snprintf(buf, sizeof(buf), "cp %s next-client-cert.pem", url); |
| 3752 | if (system(buf) != 0) { |
| 3753 | send_resp(dut, conn, SIGMA_ERROR, |
| 3754 | "errorCode,Failed to copy client " |
| 3755 | "certificate"); |
| 3756 | return 0; |
| 3757 | } |
| 3758 | |
| 3759 | snprintf(url, sizeof(url), "Certs/%s-key.pem", name); |
| 3760 | sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client " |
| 3761 | "private key from the device (%s)", url); |
| 3762 | if (!file_exists(url)) { |
| 3763 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested " |
| 3764 | "private key file does not exist"); |
| 3765 | return 0; |
| 3766 | } |
| 3767 | snprintf(buf, sizeof(buf), "cp %s next-client-key.pem", url); |
| 3768 | if (system(buf) != 0) { |
| 3769 | send_resp(dut, conn, SIGMA_ERROR, |
| 3770 | "errorCode,Failed to copy client key"); |
| 3771 | return 0; |
| 3772 | } |
| 3773 | } else if (strncasecmp(path, "http:", 5) != 0 && |
| 3774 | strncasecmp(path, "https:", 6) != 0) { |
| 3775 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode," |
| 3776 | "Unsupported FilePath value"); |
| 3777 | return 0; |
| 3778 | } else { |
| 3779 | snprintf(url, sizeof(url), "%s/%s.pem", path, name); |
| 3780 | sigma_dut_print(dut, DUT_MSG_INFO, "Downloading client " |
| 3781 | "certificate/key from %s", url); |
| 3782 | snprintf(buf, sizeof(buf), |
| 3783 | "wget -T 10 -t 3 -O next-client-cert.pem '%s'", url); |
| 3784 | if (system(buf) != 0) { |
| 3785 | send_resp(dut, conn, SIGMA_ERROR, |
| 3786 | "errorCode,Failed to download client " |
| 3787 | "certificate"); |
| 3788 | return 0; |
| 3789 | } |
| 3790 | |
| 3791 | if (system("cp next-client-cert.pem next-client-key.pem") != 0) |
| 3792 | { |
| 3793 | send_resp(dut, conn, SIGMA_ERROR, |
| 3794 | "errorCode,Failed to copy client key"); |
| 3795 | return 0; |
| 3796 | } |
| 3797 | } |
| 3798 | |
| 3799 | return 1; |
| 3800 | } |
| 3801 | |
| 3802 | |
Alexei Avshalom Lazar | 33f700c | 2018-12-18 16:00:39 +0200 | [diff] [blame] | 3803 | static int cmd_sta_preset_testparameters_60ghz(struct sigma_dut *dut, |
| 3804 | struct sigma_conn *conn, |
| 3805 | struct sigma_cmd *cmd) |
| 3806 | { |
| 3807 | const char *val; |
| 3808 | const char *intf = get_param(cmd, "interface"); |
| 3809 | |
| 3810 | if (!intf) |
| 3811 | return -1; |
| 3812 | |
| 3813 | val = get_param(cmd, "WscIEFragment"); |
| 3814 | if (val && strcasecmp(val, "enable") == 0) { |
| 3815 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 3816 | "Enable WSC IE fragmentation"); |
| 3817 | |
| 3818 | dut->wsc_fragment = 1; |
| 3819 | /* set long attributes to force fragmentation */ |
| 3820 | if (wpa_command(intf, "SET device_name " |
| 3821 | WPS_LONG_DEVICE_NAME) < 0) |
| 3822 | return -2; |
| 3823 | if (wpa_command(intf, "SET manufacturer " |
| 3824 | WPS_LONG_MANUFACTURER) < 0) |
| 3825 | return -2; |
| 3826 | if (wpa_command(intf, "SET model_name " |
| 3827 | WPS_LONG_MODEL_NAME) < 0) |
| 3828 | return -2; |
| 3829 | if (wpa_command(intf, "SET model_number " |
| 3830 | WPS_LONG_MODEL_NUMBER) < 0) |
| 3831 | return -2; |
| 3832 | if (wpa_command(intf, "SET serial_number " |
| 3833 | WPS_LONG_SERIAL_NUMBER) < 0) |
| 3834 | return -2; |
| 3835 | } |
| 3836 | |
Alexei Avshalom Lazar | b094bf0 | 2018-12-18 16:00:53 +0200 | [diff] [blame] | 3837 | val = get_param(cmd, "RSN_IE"); |
| 3838 | if (val) { |
| 3839 | if (strcasecmp(val, "disable") == 0) |
| 3840 | dut->force_rsn_ie = FORCE_RSN_IE_REMOVE; |
| 3841 | else if (strcasecmp(val, "enable") == 0) |
| 3842 | dut->force_rsn_ie = FORCE_RSN_IE_ADD; |
| 3843 | } |
| 3844 | |
Alexei Avshalom Lazar | 744ae8a | 2019-01-31 17:26:46 +0200 | [diff] [blame] | 3845 | val = get_param(cmd, "WpsVersion"); |
| 3846 | if (val) |
| 3847 | dut->wps_forced_version = get_wps_forced_version(dut, val); |
| 3848 | |
Alexei Avshalom Lazar | 2eccf4d | 2019-01-31 10:03:59 +0200 | [diff] [blame] | 3849 | val = get_param(cmd, "WscEAPFragment"); |
| 3850 | if (val && strcasecmp(val, "enable") == 0) |
| 3851 | dut->eap_fragment = 1; |
| 3852 | |
Alexei Avshalom Lazar | 33f700c | 2018-12-18 16:00:39 +0200 | [diff] [blame] | 3853 | return 1; |
| 3854 | } |
| 3855 | |
| 3856 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3857 | static int cmd_sta_preset_testparameters_hs2_r2(struct sigma_dut *dut, |
| 3858 | struct sigma_conn *conn, |
| 3859 | const char *intf, |
| 3860 | struct sigma_cmd *cmd) |
| 3861 | { |
| 3862 | const char *val; |
| 3863 | |
| 3864 | val = get_param(cmd, "FileType"); |
| 3865 | if (val && strcasecmp(val, "PPSMO") == 0) |
| 3866 | return download_ppsmo(dut, conn, intf, cmd); |
| 3867 | if (val && strcasecmp(val, "CERT") == 0) |
| 3868 | return download_cert(dut, conn, intf, cmd); |
| 3869 | if (val) { |
| 3870 | send_resp(dut, conn, SIGMA_ERROR, |
| 3871 | "ErrorCode,Unsupported FileType"); |
| 3872 | return 0; |
| 3873 | } |
| 3874 | |
| 3875 | return 1; |
| 3876 | } |
| 3877 | |
| 3878 | |
Ankita Bajaj | a2cb567 | 2017-10-25 16:08:28 +0530 | [diff] [blame] | 3879 | static int cmd_sta_preset_testparameters_oce(struct sigma_dut *dut, |
| 3880 | struct sigma_conn *conn, |
| 3881 | const char *intf, |
| 3882 | struct sigma_cmd *cmd) |
| 3883 | { |
| 3884 | const char *val; |
Ankita Bajaj | 1bde794 | 2018-01-09 19:15:01 +0530 | [diff] [blame] | 3885 | char buf[1000]; |
| 3886 | char text[20]; |
| 3887 | unsigned char addr[ETH_ALEN]; |
Ankita Bajaj | a2cb567 | 2017-10-25 16:08:28 +0530 | [diff] [blame] | 3888 | |
| 3889 | val = get_param(cmd, "OCESupport"); |
| 3890 | if (val && strcasecmp(val, "Disable") == 0) { |
| 3891 | if (wpa_command(intf, "SET oce 0") < 0) { |
| 3892 | send_resp(dut, conn, SIGMA_ERROR, |
| 3893 | "ErrorCode,Failed to disable OCE"); |
| 3894 | return 0; |
| 3895 | } |
| 3896 | } else if (val && strcasecmp(val, "Enable") == 0) { |
| 3897 | if (wpa_command(intf, "SET oce 1") < 0) { |
| 3898 | send_resp(dut, conn, SIGMA_ERROR, |
| 3899 | "ErrorCode,Failed to enable OCE"); |
| 3900 | return 0; |
| 3901 | } |
| 3902 | } |
| 3903 | |
vamsi krishna | a279949 | 2017-12-05 14:28:01 +0530 | [diff] [blame] | 3904 | val = get_param(cmd, "FILScap"); |
| 3905 | if (val && (atoi(val) == 1)) { |
| 3906 | if (wpa_command(intf, "SET disable_fils 0") < 0) { |
| 3907 | send_resp(dut, conn, SIGMA_ERROR, |
| 3908 | "ErrorCode,Failed to enable FILS"); |
| 3909 | return 0; |
| 3910 | } |
| 3911 | } else if (val && (atoi(val) == 0)) { |
| 3912 | if (wpa_command(intf, "SET disable_fils 1") < 0) { |
| 3913 | send_resp(dut, conn, SIGMA_ERROR, |
| 3914 | "ErrorCode,Failed to disable FILS"); |
| 3915 | return 0; |
| 3916 | } |
| 3917 | } |
| 3918 | |
Ankita Bajaj | 1bde794 | 2018-01-09 19:15:01 +0530 | [diff] [blame] | 3919 | val = get_param(cmd, "FILSHLP"); |
| 3920 | if (val && strcasecmp(val, "Enable") == 0) { |
| 3921 | if (get_wpa_status(get_station_ifname(), "address", text, |
| 3922 | sizeof(text)) < 0) |
| 3923 | return -2; |
| 3924 | hwaddr_aton(text, addr); |
| 3925 | snprintf(buf, sizeof(buf), |
| 3926 | "FILS_HLP_REQ_ADD ff:ff:ff:ff:ff:ff " |
| 3927 | "080045100140000040004011399e00000000ffffffff00440043" |
| 3928 | "012cb30001010600fd4f46410000000000000000000000000000" |
| 3929 | "000000000000" |
| 3930 | "%02x%02x%02x%02x%02x%02x" |
| 3931 | "0000000000000000000000000000000000000000000000000000" |
| 3932 | "0000000000000000000000000000000000000000000000000000" |
| 3933 | "0000000000000000000000000000000000000000000000000000" |
| 3934 | "0000000000000000000000000000000000000000000000000000" |
| 3935 | "0000000000000000000000000000000000000000000000000000" |
| 3936 | "0000000000000000000000000000000000000000000000000000" |
| 3937 | "0000000000000000000000000000000000000000000000000000" |
| 3938 | "0000000000000000000000000000000000000000638253633501" |
| 3939 | "013d0701000af549d29b390205dc3c12616e64726f69642d6468" |
| 3940 | "63702d382e302e30370a0103060f1a1c333a3b2b5000ff00", |
| 3941 | addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]); |
| 3942 | if (wpa_command(intf, buf)) { |
| 3943 | send_resp(dut, conn, SIGMA_ERROR, |
| 3944 | "ErrorCode,Failed to add HLP"); |
| 3945 | return 0; |
| 3946 | } |
| 3947 | dut->fils_hlp = 1; |
| 3948 | } |
| 3949 | |
Ankita Bajaj | a2cb567 | 2017-10-25 16:08:28 +0530 | [diff] [blame] | 3950 | return 1; |
| 3951 | } |
| 3952 | |
| 3953 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3954 | static void ath_sta_set_noack(struct sigma_dut *dut, const char *intf, |
| 3955 | const char *val) |
| 3956 | { |
| 3957 | int counter = 0; |
| 3958 | char token[50]; |
| 3959 | char *result; |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 3960 | char *saveptr; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3961 | |
Peng Xu | b8fc5cc | 2017-05-10 17:27:28 -0700 | [diff] [blame] | 3962 | strlcpy(token, val, sizeof(token)); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3963 | token[sizeof(token) - 1] = '\0'; |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 3964 | result = strtok_r(token, ":", &saveptr); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3965 | while (result) { |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 3966 | if (strcmp(result, "disable") == 0) |
| 3967 | run_iwpriv(dut, intf, "noackpolicy %d 1 0", counter); |
| 3968 | else |
| 3969 | run_iwpriv(dut, intf, "noackpolicy %d 1 1", counter); |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 3970 | result = strtok_r(NULL, ":", &saveptr); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3971 | counter++; |
| 3972 | } |
| 3973 | } |
| 3974 | |
| 3975 | |
| 3976 | static void ath_sta_set_rts(struct sigma_dut *dut, const char *intf, |
| 3977 | const char *val) |
| 3978 | { |
| 3979 | char buf[100]; |
| 3980 | |
| 3981 | snprintf(buf, sizeof(buf), "iwconfig %s rts %s", intf, val); |
| 3982 | if (system(buf) != 0) { |
| 3983 | sigma_dut_print(dut, DUT_MSG_ERROR, "iwconfig RTS failed"); |
| 3984 | } |
| 3985 | } |
| 3986 | |
| 3987 | |
| 3988 | static void ath_sta_set_wmm(struct sigma_dut *dut, const char *intf, |
| 3989 | const char *val) |
| 3990 | { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3991 | if (strcasecmp(val, "off") == 0) { |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 3992 | run_iwpriv(dut, intf, "wmm 0"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3993 | } |
| 3994 | } |
| 3995 | |
| 3996 | |
Amarnath Hullur Subramanyam | 75214d2 | 2018-02-04 19:17:11 -0800 | [diff] [blame] | 3997 | static int wcn_sta_set_wmm(struct sigma_dut *dut, const char *intf, |
| 3998 | const char *val) |
| 3999 | { |
| 4000 | #ifdef NL80211_SUPPORT |
| 4001 | struct nl_msg *msg; |
| 4002 | int ret = 0; |
| 4003 | struct nlattr *params; |
| 4004 | int ifindex; |
| 4005 | int wmmenable = 1; |
| 4006 | |
| 4007 | if (val && |
| 4008 | (strcasecmp(val, "off") == 0 || strcmp(val, "0") == 0)) |
| 4009 | wmmenable = 0; |
| 4010 | |
| 4011 | ifindex = if_nametoindex(intf); |
| 4012 | if (ifindex == 0) { |
| 4013 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4014 | "%s: Index for interface %s failed", |
| 4015 | __func__, intf); |
| 4016 | return -1; |
| 4017 | } |
| 4018 | |
| 4019 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 4020 | NL80211_CMD_VENDOR)) || |
| 4021 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 4022 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 4023 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 4024 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || |
| 4025 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 4026 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WMM_ENABLE, |
| 4027 | wmmenable)) { |
| 4028 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4029 | "%s: err in adding vendor_cmd and vendor_data", |
| 4030 | __func__); |
| 4031 | nlmsg_free(msg); |
| 4032 | return -1; |
| 4033 | } |
| 4034 | nla_nest_end(msg, params); |
| 4035 | |
| 4036 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 4037 | if (ret) { |
| 4038 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4039 | "%s: err in send_and_recv_msgs, ret=%d", |
| 4040 | __func__, ret); |
| 4041 | } |
| 4042 | return ret; |
| 4043 | #else /* NL80211_SUPPORT */ |
| 4044 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4045 | "WMM cannot be changed without NL80211_SUPPORT defined"); |
| 4046 | return -1; |
| 4047 | #endif /* NL80211_SUPPORT */ |
| 4048 | } |
| 4049 | |
| 4050 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4051 | static void ath_sta_set_sgi(struct sigma_dut *dut, const char *intf, |
| 4052 | const char *val) |
| 4053 | { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4054 | int sgi20; |
| 4055 | |
| 4056 | sgi20 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0; |
| 4057 | |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 4058 | run_iwpriv(dut, intf, "shortgi %d", sgi20); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4059 | } |
| 4060 | |
| 4061 | |
| 4062 | static void ath_sta_set_11nrates(struct sigma_dut *dut, const char *intf, |
| 4063 | const char *val) |
| 4064 | { |
Pradeep Reddy POTTETI | 67376b7 | 2016-10-25 20:08:17 +0530 | [diff] [blame] | 4065 | int rate_code, v; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4066 | |
| 4067 | /* Disable Tx Beam forming when using a fixed rate */ |
| 4068 | ath_disable_txbf(dut, intf); |
| 4069 | |
Pradeep Reddy POTTETI | 67376b7 | 2016-10-25 20:08:17 +0530 | [diff] [blame] | 4070 | v = atoi(val); |
| 4071 | if (v < 0 || v > 32) { |
| 4072 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4073 | "Invalid Fixed MCS rate: %d", v); |
| 4074 | return; |
| 4075 | } |
| 4076 | rate_code = 0x80 + v; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4077 | |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 4078 | run_iwpriv(dut, intf, "set11NRates 0x%x", rate_code); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4079 | |
| 4080 | /* Channel width gets messed up, fix this */ |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 4081 | run_iwpriv(dut, intf, "chwidth %d", dut->chwidth); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4082 | } |
| 4083 | |
| 4084 | |
Amarnath Hullur Subramanyam | d5bb573 | 2018-02-22 15:50:38 -0800 | [diff] [blame] | 4085 | static void iwpriv_sta_set_amsdu(struct sigma_dut *dut, const char *intf, |
| 4086 | const char *val) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4087 | { |
| 4088 | char buf[60]; |
| 4089 | |
| 4090 | if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) |
| 4091 | snprintf(buf, sizeof(buf), "iwpriv %s amsdu 2", intf); |
| 4092 | else |
| 4093 | snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf); |
| 4094 | |
| 4095 | if (system(buf) != 0) |
| 4096 | sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv amsdu failed"); |
| 4097 | } |
| 4098 | |
| 4099 | |
Deepak Dhamdhere | 80356cb | 2016-03-28 16:48:32 -0700 | [diff] [blame] | 4100 | static int iwpriv_sta_set_ampdu(struct sigma_dut *dut, const char *intf, |
| 4101 | int ampdu) |
| 4102 | { |
| 4103 | char buf[60]; |
Amarnath Hullur Subramanyam | 63c590a | 2018-03-07 15:26:21 -0800 | [diff] [blame] | 4104 | int maxaggregation = 63; |
Deepak Dhamdhere | 80356cb | 2016-03-28 16:48:32 -0700 | [diff] [blame] | 4105 | |
Amarnath Hullur Subramanyam | 63c590a | 2018-03-07 15:26:21 -0800 | [diff] [blame] | 4106 | if (ampdu) |
| 4107 | ampdu = maxaggregation; |
Deepak Dhamdhere | 80356cb | 2016-03-28 16:48:32 -0700 | [diff] [blame] | 4108 | snprintf(buf, sizeof(buf), "iwpriv %s ampdu %d", intf, ampdu); |
| 4109 | if (system(buf) != 0) { |
| 4110 | sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv ampdu failed"); |
| 4111 | return -1; |
| 4112 | } |
| 4113 | |
| 4114 | return 0; |
| 4115 | } |
| 4116 | |
| 4117 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4118 | static void ath_sta_set_stbc(struct sigma_dut *dut, const char *intf, |
| 4119 | const char *val) |
| 4120 | { |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 4121 | run_iwpriv(dut, intf, "tx_stbc %s", val); |
| 4122 | run_iwpriv(dut, intf, "rx_stbc %s", val); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4123 | } |
| 4124 | |
| 4125 | |
| 4126 | static int wcn_sta_set_cts_width(struct sigma_dut *dut, const char *intf, |
| 4127 | const char *val) |
| 4128 | { |
| 4129 | char buf[60]; |
| 4130 | |
Peng Xu | cc317ed | 2017-05-18 16:44:37 -0700 | [diff] [blame] | 4131 | if (strcmp(val, "160") == 0) { |
| 4132 | snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 5", intf); |
| 4133 | } else if (strcmp(val, "80") == 0) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4134 | snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf); |
| 4135 | } else if (strcmp(val, "40") == 0) { |
| 4136 | snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 2", intf); |
| 4137 | } else if (strcmp(val, "20") == 0) { |
| 4138 | snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 1", intf); |
| 4139 | } else if (strcasecmp(val, "Auto") == 0) { |
| 4140 | buf[0] = '\0'; |
| 4141 | } else { |
| 4142 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4143 | "WIDTH/CTS_WIDTH value not supported"); |
| 4144 | return -1; |
| 4145 | } |
| 4146 | |
| 4147 | if (buf[0] != '\0' && system(buf) != 0) { |
| 4148 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4149 | "Failed to set WIDTH/CTS_WIDTH"); |
| 4150 | return -1; |
| 4151 | } |
| 4152 | |
| 4153 | return 0; |
| 4154 | } |
| 4155 | |
| 4156 | |
| 4157 | int ath_set_width(struct sigma_dut *dut, struct sigma_conn *conn, |
| 4158 | const char *intf, const char *val) |
| 4159 | { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4160 | if (strcasecmp(val, "Auto") == 0) { |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 4161 | run_iwpriv(dut, intf, "chwidth 0"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4162 | dut->chwidth = 0; |
| 4163 | } else if (strcasecmp(val, "20") == 0) { |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 4164 | run_iwpriv(dut, intf, "chwidth 0"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4165 | dut->chwidth = 0; |
| 4166 | } else if (strcasecmp(val, "40") == 0) { |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 4167 | run_iwpriv(dut, intf, "chwidth 1"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4168 | dut->chwidth = 1; |
| 4169 | } else if (strcasecmp(val, "80") == 0) { |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 4170 | run_iwpriv(dut, intf, "chwidth 2"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4171 | dut->chwidth = 2; |
| 4172 | } else if (strcasecmp(val, "160") == 0) { |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 4173 | run_iwpriv(dut, intf, "chwidth 3"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4174 | dut->chwidth = 3; |
| 4175 | } else { |
| 4176 | send_resp(dut, conn, SIGMA_ERROR, |
| 4177 | "ErrorCode,WIDTH not supported"); |
| 4178 | return -1; |
| 4179 | } |
| 4180 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4181 | return 0; |
| 4182 | } |
| 4183 | |
| 4184 | |
| 4185 | static int wcn_sta_set_sp_stream(struct sigma_dut *dut, const char *intf, |
| 4186 | const char *val) |
| 4187 | { |
| 4188 | char buf[60]; |
Arif Hussain | ac6c511 | 2018-05-25 17:34:00 -0700 | [diff] [blame] | 4189 | int sta_nss; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4190 | |
Amarnath Hullur Subramanyam | d5374fa | 2018-02-25 19:00:24 -0800 | [diff] [blame] | 4191 | if (strcmp(val, "1SS") == 0 || strcmp(val, "1") == 0) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4192 | snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf); |
Arif Hussain | ac6c511 | 2018-05-25 17:34:00 -0700 | [diff] [blame] | 4193 | sta_nss = 1; |
Amarnath Hullur Subramanyam | d5374fa | 2018-02-25 19:00:24 -0800 | [diff] [blame] | 4194 | } else if (strcmp(val, "2SS") == 0 || strcmp(val, "2") == 0) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4195 | snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf); |
Arif Hussain | ac6c511 | 2018-05-25 17:34:00 -0700 | [diff] [blame] | 4196 | sta_nss = 2; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4197 | } else { |
| 4198 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4199 | "SP_STREAM value not supported"); |
| 4200 | return -1; |
| 4201 | } |
| 4202 | |
| 4203 | if (system(buf) != 0) { |
| 4204 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4205 | "Failed to set SP_STREAM"); |
| 4206 | return -1; |
| 4207 | } |
| 4208 | |
Arif Hussain | ac6c511 | 2018-05-25 17:34:00 -0700 | [diff] [blame] | 4209 | dut->sta_nss = sta_nss; |
| 4210 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4211 | return 0; |
| 4212 | } |
| 4213 | |
| 4214 | |
Pradeep Reddy POTTETI | 4a1f6b3 | 2016-11-23 13:15:21 +0530 | [diff] [blame] | 4215 | static void wcn_sta_set_stbc(struct sigma_dut *dut, const char *intf, |
| 4216 | const char *val) |
| 4217 | { |
| 4218 | char buf[60]; |
| 4219 | |
| 4220 | snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc %s", intf, val); |
| 4221 | if (system(buf) != 0) |
| 4222 | sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv tx_stbc failed"); |
| 4223 | |
| 4224 | snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc %s", intf, val); |
| 4225 | if (system(buf) != 0) |
| 4226 | sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv rx_stbc failed"); |
| 4227 | } |
| 4228 | |
| 4229 | |
Ashwini Patil | 68d02cd | 2017-01-10 15:39:16 +0530 | [diff] [blame] | 4230 | static int mbo_set_cellular_data_capa(struct sigma_dut *dut, |
| 4231 | struct sigma_conn *conn, |
| 4232 | const char *intf, int capa) |
| 4233 | { |
| 4234 | char buf[32]; |
| 4235 | |
| 4236 | if (capa > 0 && capa < 4) { |
| 4237 | snprintf(buf, sizeof(buf), "SET mbo_cell_capa %d", capa); |
| 4238 | if (wpa_command(intf, buf) < 0) { |
| 4239 | send_resp(dut, conn, SIGMA_ERROR, |
| 4240 | "ErrorCode, Failed to set cellular data capability"); |
| 4241 | return 0; |
| 4242 | } |
| 4243 | return 1; |
| 4244 | } |
| 4245 | |
| 4246 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4247 | "Invalid Cellular data capability: %d", capa); |
| 4248 | send_resp(dut, conn, SIGMA_INVALID, |
| 4249 | "ErrorCode,Invalid cellular data capability"); |
| 4250 | return 0; |
| 4251 | } |
| 4252 | |
| 4253 | |
Ashwini Patil | 9183fdb | 2017-04-13 16:58:25 +0530 | [diff] [blame] | 4254 | static int mbo_set_roaming(struct sigma_dut *dut, struct sigma_conn *conn, |
| 4255 | const char *intf, const char *val) |
| 4256 | { |
| 4257 | if (strcasecmp(val, "Disable") == 0) { |
| 4258 | if (wpa_command(intf, "SET roaming 0") < 0) { |
| 4259 | send_resp(dut, conn, SIGMA_ERROR, |
| 4260 | "ErrorCode,Failed to disable roaming"); |
| 4261 | return 0; |
| 4262 | } |
| 4263 | return 1; |
| 4264 | } |
| 4265 | |
| 4266 | if (strcasecmp(val, "Enable") == 0) { |
| 4267 | if (wpa_command(intf, "SET roaming 1") < 0) { |
| 4268 | send_resp(dut, conn, SIGMA_ERROR, |
| 4269 | "ErrorCode,Failed to enable roaming"); |
| 4270 | return 0; |
| 4271 | } |
| 4272 | return 1; |
| 4273 | } |
| 4274 | |
| 4275 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4276 | "Invalid value provided for roaming: %s", val); |
| 4277 | send_resp(dut, conn, SIGMA_INVALID, |
| 4278 | "ErrorCode,Unknown value provided for Roaming"); |
| 4279 | return 0; |
| 4280 | } |
| 4281 | |
| 4282 | |
Ashwini Patil | a75de5a | 2017-04-13 16:35:05 +0530 | [diff] [blame] | 4283 | static int mbo_set_assoc_disallow(struct sigma_dut *dut, |
| 4284 | struct sigma_conn *conn, |
| 4285 | const char *intf, const char *val) |
| 4286 | { |
| 4287 | if (strcasecmp(val, "Disable") == 0) { |
| 4288 | if (wpa_command(intf, "SET ignore_assoc_disallow 1") < 0) { |
| 4289 | send_resp(dut, conn, SIGMA_ERROR, |
| 4290 | "ErrorCode,Failed to disable Assoc_disallow"); |
| 4291 | return 0; |
| 4292 | } |
| 4293 | return 1; |
| 4294 | } |
| 4295 | |
| 4296 | if (strcasecmp(val, "Enable") == 0) { |
| 4297 | if (wpa_command(intf, "SET ignore_assoc_disallow 0") < 0) { |
| 4298 | send_resp(dut, conn, SIGMA_ERROR, |
| 4299 | "ErrorCode,Failed to enable Assoc_disallow"); |
| 4300 | return 0; |
| 4301 | } |
| 4302 | return 1; |
| 4303 | } |
| 4304 | |
| 4305 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4306 | "Invalid value provided for Assoc_disallow: %s", val); |
| 4307 | send_resp(dut, conn, SIGMA_INVALID, |
| 4308 | "ErrorCode,Unknown value provided for Assoc_disallow"); |
| 4309 | return 0; |
| 4310 | } |
| 4311 | |
| 4312 | |
Ashwini Patil | c63161e | 2017-04-13 16:30:23 +0530 | [diff] [blame] | 4313 | static int mbo_set_bss_trans_req(struct sigma_dut *dut, struct sigma_conn *conn, |
| 4314 | const char *intf, const char *val) |
| 4315 | { |
| 4316 | if (strcasecmp(val, "Reject") == 0) { |
| 4317 | if (wpa_command(intf, "SET reject_btm_req_reason 1") < 0) { |
| 4318 | send_resp(dut, conn, SIGMA_ERROR, |
| 4319 | "ErrorCode,Failed to Reject BTM Request"); |
| 4320 | return 0; |
| 4321 | } |
| 4322 | return 1; |
| 4323 | } |
| 4324 | |
| 4325 | if (strcasecmp(val, "Accept") == 0) { |
| 4326 | if (wpa_command(intf, "SET reject_btm_req_reason 0") < 0) { |
| 4327 | send_resp(dut, conn, SIGMA_ERROR, |
| 4328 | "ErrorCode,Failed to Accept BTM Request"); |
| 4329 | return 0; |
| 4330 | } |
| 4331 | return 1; |
| 4332 | } |
| 4333 | |
| 4334 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4335 | "Invalid value provided for BSS_Transition: %s", val); |
| 4336 | send_resp(dut, conn, SIGMA_INVALID, |
| 4337 | "ErrorCode,Unknown value provided for BSS_Transition"); |
| 4338 | return 0; |
| 4339 | } |
| 4340 | |
| 4341 | |
Ashwini Patil | 0040258 | 2017-04-13 12:29:39 +0530 | [diff] [blame] | 4342 | static int mbo_set_non_pref_ch_list(struct sigma_dut *dut, |
| 4343 | struct sigma_conn *conn, |
| 4344 | const char *intf, |
| 4345 | struct sigma_cmd *cmd) |
| 4346 | { |
| 4347 | const char *ch, *pref, *op_class, *reason; |
| 4348 | char buf[120]; |
| 4349 | int len, ret; |
| 4350 | |
| 4351 | pref = get_param(cmd, "Ch_Pref"); |
| 4352 | if (!pref) |
| 4353 | return 1; |
| 4354 | |
| 4355 | if (strcasecmp(pref, "clear") == 0) { |
| 4356 | free(dut->non_pref_ch_list); |
| 4357 | dut->non_pref_ch_list = NULL; |
| 4358 | } else { |
| 4359 | op_class = get_param(cmd, "Ch_Op_Class"); |
| 4360 | if (!op_class) { |
| 4361 | send_resp(dut, conn, SIGMA_INVALID, |
| 4362 | "ErrorCode,Ch_Op_Class not provided"); |
| 4363 | return 0; |
| 4364 | } |
| 4365 | |
| 4366 | ch = get_param(cmd, "Ch_Pref_Num"); |
| 4367 | if (!ch) { |
| 4368 | send_resp(dut, conn, SIGMA_INVALID, |
| 4369 | "ErrorCode,Ch_Pref_Num not provided"); |
| 4370 | return 0; |
| 4371 | } |
| 4372 | |
| 4373 | reason = get_param(cmd, "Ch_Reason_Code"); |
| 4374 | if (!reason) { |
| 4375 | send_resp(dut, conn, SIGMA_INVALID, |
| 4376 | "ErrorCode,Ch_Reason_Code not provided"); |
| 4377 | return 0; |
| 4378 | } |
| 4379 | |
| 4380 | if (!dut->non_pref_ch_list) { |
| 4381 | dut->non_pref_ch_list = |
| 4382 | calloc(1, NON_PREF_CH_LIST_SIZE); |
| 4383 | if (!dut->non_pref_ch_list) { |
| 4384 | send_resp(dut, conn, SIGMA_ERROR, |
| 4385 | "ErrorCode,Failed to allocate memory for non_pref_ch_list"); |
| 4386 | return 0; |
| 4387 | } |
| 4388 | } |
| 4389 | len = strlen(dut->non_pref_ch_list); |
| 4390 | ret = snprintf(dut->non_pref_ch_list + len, |
| 4391 | NON_PREF_CH_LIST_SIZE - len, |
| 4392 | " %s:%s:%s:%s", op_class, ch, pref, reason); |
| 4393 | if (ret > 0 && ret < NON_PREF_CH_LIST_SIZE - len) { |
| 4394 | sigma_dut_print(dut, DUT_MSG_DEBUG, "non_pref_list: %s", |
| 4395 | dut->non_pref_ch_list); |
| 4396 | } else { |
| 4397 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4398 | "snprintf failed for non_pref_list, ret = %d", |
| 4399 | ret); |
| 4400 | send_resp(dut, conn, SIGMA_ERROR, |
| 4401 | "ErrorCode,snprintf failed"); |
| 4402 | free(dut->non_pref_ch_list); |
| 4403 | dut->non_pref_ch_list = NULL; |
| 4404 | return 0; |
| 4405 | } |
| 4406 | } |
| 4407 | |
| 4408 | ret = snprintf(buf, sizeof(buf), "SET non_pref_chan%s", |
| 4409 | dut->non_pref_ch_list ? dut->non_pref_ch_list : " "); |
| 4410 | if (ret < 0 || ret >= (int) sizeof(buf)) { |
| 4411 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 4412 | "snprintf failed for set non_pref_chan, ret: %d", |
| 4413 | ret); |
| 4414 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,snprint failed"); |
| 4415 | return 0; |
| 4416 | } |
| 4417 | |
| 4418 | if (wpa_command(intf, buf) < 0) { |
| 4419 | send_resp(dut, conn, SIGMA_ERROR, |
| 4420 | "ErrorCode,Failed to set non-preferred channel list"); |
| 4421 | return 0; |
| 4422 | } |
| 4423 | |
| 4424 | return 1; |
| 4425 | } |
| 4426 | |
| 4427 | |
Amarnath Hullur Subramanyam | 474a17d | 2018-02-22 18:45:54 -0800 | [diff] [blame] | 4428 | #ifdef NL80211_SUPPORT |
Amarnath Hullur Subramanyam | ae8a2d9 | 2018-03-01 06:32:21 -0800 | [diff] [blame] | 4429 | |
Kiran Kumar Lokere | e5ed442 | 2018-12-18 18:25:02 -0800 | [diff] [blame] | 4430 | static int sta_set_he_htc_supp(struct sigma_dut *dut, const char *intf, |
| 4431 | uint8_t cfg) |
| 4432 | { |
| 4433 | struct nl_msg *msg; |
| 4434 | int ret = 0; |
| 4435 | struct nlattr *params; |
| 4436 | int ifindex; |
| 4437 | |
| 4438 | ifindex = if_nametoindex(intf); |
| 4439 | if (ifindex == 0) { |
| 4440 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4441 | "%s: Index for interface %s failed", |
| 4442 | __func__, intf); |
| 4443 | return -1; |
| 4444 | } |
| 4445 | |
| 4446 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 4447 | NL80211_CMD_VENDOR)) || |
| 4448 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 4449 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 4450 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 4451 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || |
| 4452 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 4453 | nla_put_u8(msg, |
| 4454 | QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_HTC_HE_SUPP, |
| 4455 | cfg)) { |
| 4456 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4457 | "%s: err in adding vendor_cmd and vendor_data", |
| 4458 | __func__); |
| 4459 | nlmsg_free(msg); |
| 4460 | return -1; |
| 4461 | } |
| 4462 | nla_nest_end(msg, params); |
| 4463 | |
| 4464 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 4465 | if (ret) { |
| 4466 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4467 | "%s: err in send_and_recv_msgs, ret=%d", |
| 4468 | __func__, ret); |
| 4469 | } |
| 4470 | return ret; |
| 4471 | } |
| 4472 | |
| 4473 | |
Amarnath Hullur Subramanyam | 474a17d | 2018-02-22 18:45:54 -0800 | [diff] [blame] | 4474 | static int sta_set_he_fragmentation(struct sigma_dut *dut, const char *intf, |
| 4475 | enum he_fragmentation_val frag) |
| 4476 | { |
| 4477 | struct nl_msg *msg; |
| 4478 | int ret = 0; |
| 4479 | struct nlattr *params; |
| 4480 | int ifindex; |
| 4481 | |
| 4482 | ifindex = if_nametoindex(intf); |
| 4483 | if (ifindex == 0) { |
| 4484 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4485 | "%s: Index for interface %s failed", |
| 4486 | __func__, intf); |
| 4487 | return -1; |
| 4488 | } |
| 4489 | |
| 4490 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 4491 | NL80211_CMD_VENDOR)) || |
| 4492 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 4493 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 4494 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 4495 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || |
| 4496 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 4497 | nla_put_u8(msg, |
| 4498 | QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_FRAGMENTATION, |
| 4499 | frag)) { |
| 4500 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4501 | "%s: err in adding vendor_cmd and vendor_data", |
| 4502 | __func__); |
| 4503 | nlmsg_free(msg); |
| 4504 | return -1; |
| 4505 | } |
| 4506 | nla_nest_end(msg, params); |
| 4507 | |
| 4508 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 4509 | if (ret) { |
| 4510 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4511 | "%s: err in send_and_recv_msgs, ret=%d", |
| 4512 | __func__, ret); |
| 4513 | } |
| 4514 | return ret; |
| 4515 | } |
Amarnath Hullur Subramanyam | ae8a2d9 | 2018-03-01 06:32:21 -0800 | [diff] [blame] | 4516 | |
| 4517 | |
Subhani Shaik | 8e7a305 | 2018-04-24 14:03:00 -0700 | [diff] [blame] | 4518 | static int sta_set_he_ltf(struct sigma_dut *dut, const char *intf, |
| 4519 | enum qca_wlan_he_ltf_cfg ltf) |
| 4520 | { |
| 4521 | struct nl_msg *msg; |
| 4522 | int ret = 0; |
| 4523 | struct nlattr *params; |
| 4524 | int ifindex; |
| 4525 | |
| 4526 | ifindex = if_nametoindex(intf); |
| 4527 | if (ifindex == 0) { |
| 4528 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4529 | "%s: Index for interface %s failed", |
| 4530 | __func__, intf); |
| 4531 | return -1; |
| 4532 | } |
| 4533 | |
| 4534 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 4535 | NL80211_CMD_VENDOR)) || |
| 4536 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 4537 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 4538 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 4539 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || |
| 4540 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 4541 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_LTF, |
| 4542 | ltf)) { |
| 4543 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4544 | "%s: err in adding vendor_cmd and vendor_data", |
| 4545 | __func__); |
| 4546 | nlmsg_free(msg); |
| 4547 | return -1; |
| 4548 | } |
| 4549 | nla_nest_end(msg, params); |
| 4550 | |
| 4551 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 4552 | if (ret) { |
| 4553 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4554 | "%s: err in send_and_recv_msgs, ret=%d", |
| 4555 | __func__, ret); |
| 4556 | } |
| 4557 | return ret; |
| 4558 | } |
| 4559 | |
| 4560 | |
Amarnath Hullur Subramanyam | ae8a2d9 | 2018-03-01 06:32:21 -0800 | [diff] [blame] | 4561 | static int nlvendor_sta_set_noack(struct sigma_dut *dut, const char *intf, |
| 4562 | int noack, enum qca_wlan_ac_type ac) |
| 4563 | { |
| 4564 | struct nl_msg *msg; |
| 4565 | int ret = 0; |
| 4566 | struct nlattr *params; |
| 4567 | int ifindex; |
| 4568 | |
| 4569 | ifindex = if_nametoindex(intf); |
| 4570 | if (ifindex == 0) { |
| 4571 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4572 | "%s: Index for interface %s failed", |
| 4573 | __func__, intf); |
| 4574 | return -1; |
| 4575 | } |
| 4576 | |
| 4577 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 4578 | NL80211_CMD_VENDOR)) || |
| 4579 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 4580 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 4581 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 4582 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || |
| 4583 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 4584 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_NO_ACK, |
| 4585 | noack) || |
| 4586 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_NO_ACK_AC, |
| 4587 | ac)) { |
| 4588 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4589 | "%s: err in adding vendor_cmd and vendor_data", |
| 4590 | __func__); |
| 4591 | nlmsg_free(msg); |
| 4592 | return -1; |
| 4593 | } |
| 4594 | nla_nest_end(msg, params); |
| 4595 | |
| 4596 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 4597 | if (ret) { |
| 4598 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4599 | "%s: err in send_and_recv_msgs, ret=%d", |
| 4600 | __func__, ret); |
| 4601 | } |
| 4602 | return ret; |
| 4603 | } |
| 4604 | |
| 4605 | |
| 4606 | static void wcn_sta_set_noack(struct sigma_dut *dut, const char *intf, |
| 4607 | const char *val) |
| 4608 | { |
| 4609 | int noack, ret; |
| 4610 | char token[100]; |
| 4611 | char *result; |
| 4612 | char *saveptr; |
| 4613 | enum qca_wlan_ac_type ac = QCA_WLAN_AC_BE; |
| 4614 | |
| 4615 | strlcpy(token, val, sizeof(token)); |
| 4616 | token[sizeof(token) - 1] = '\0'; |
| 4617 | result = strtok_r(token, ":", &saveptr); |
| 4618 | while (result) { |
| 4619 | noack = strcasecmp(result, "Disable") != 0; |
| 4620 | ret = nlvendor_sta_set_noack(dut, intf, noack, ac); |
| 4621 | if (ret) { |
| 4622 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4623 | "nlvendor_sta_set_noack failed for ac:%d, ret:%d", |
| 4624 | ac, ret); |
| 4625 | } |
| 4626 | result = strtok_r(NULL, ":", &saveptr); |
| 4627 | ac++; |
| 4628 | } |
| 4629 | } |
| 4630 | |
Amarnath Hullur Subramanyam | 474a17d | 2018-02-22 18:45:54 -0800 | [diff] [blame] | 4631 | #endif /* NL80211_SUPPORT */ |
| 4632 | |
| 4633 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 4634 | static enum sigma_cmd_result |
| 4635 | cmd_sta_preset_testparameters(struct sigma_dut *dut, struct sigma_conn *conn, |
| 4636 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4637 | { |
| 4638 | const char *intf = get_param(cmd, "Interface"); |
| 4639 | const char *val; |
| 4640 | |
Jouni Malinen | 6a7c9b4 | 2019-08-20 00:15:59 +0300 | [diff] [blame] | 4641 | val = get_param(cmd, "FT_DS"); |
| 4642 | if (val) { |
| 4643 | if (strcasecmp(val, "Enable") == 0) { |
| 4644 | dut->sta_ft_ds = 1; |
| 4645 | } else if (strcasecmp(val, "Disable") == 0) { |
| 4646 | dut->sta_ft_ds = 0; |
| 4647 | } else { |
| 4648 | send_resp(dut, conn, SIGMA_ERROR, |
| 4649 | "errorCode,Unsupported value for FT_DS"); |
| 4650 | return STATUS_SENT_ERROR; |
| 4651 | } |
| 4652 | } |
| 4653 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4654 | val = get_param(cmd, "Program"); |
Jouni Malinen | 1f6ae64 | 2018-06-07 23:56:13 +0300 | [diff] [blame] | 4655 | if (val && (strcasecmp(val, "HS2-R2") == 0 || |
| 4656 | strcasecmp(val, "HS2-R3") == 0)) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4657 | return cmd_sta_preset_testparameters_hs2_r2(dut, conn, intf, |
| 4658 | cmd); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4659 | |
priyadharshini gowthaman | d66913a | 2016-07-29 15:11:17 -0700 | [diff] [blame] | 4660 | if (val && strcasecmp(val, "LOC") == 0) |
| 4661 | return loc_cmd_sta_preset_testparameters(dut, conn, cmd); |
Alexei Avshalom Lazar | eee9ab0 | 2018-12-24 16:27:48 +0200 | [diff] [blame] | 4662 | if (val && strcasecmp(val, "60GHZ") == 0) { |
| 4663 | val = get_param(cmd, "WPS"); |
| 4664 | if (val && strcasecmp(val, "disable") == 0) { |
| 4665 | dut->wps_disable = 1; |
| 4666 | sigma_dut_print(dut, DUT_MSG_INFO, "WPS disabled"); |
| 4667 | } else { |
| 4668 | /* wps_disable can have other value from the previous |
| 4669 | * test, so make sure it has the correct value. |
| 4670 | */ |
| 4671 | dut->wps_disable = 0; |
| 4672 | } |
| 4673 | |
| 4674 | val = get_param(cmd, "P2P"); |
| 4675 | if (val && strcasecmp(val, "disable") == 0) |
| 4676 | sigma_dut_print(dut, DUT_MSG_INFO, "P2P disabled"); |
| 4677 | } |
priyadharshini gowthaman | d66913a | 2016-07-29 15:11:17 -0700 | [diff] [blame] | 4678 | |
Alexei Avshalom Lazar | 33f700c | 2018-12-18 16:00:39 +0200 | [diff] [blame] | 4679 | if (dut->program == PROGRAM_WPS && dut->band == WPS_BAND_60G) |
| 4680 | return cmd_sta_preset_testparameters_60ghz(dut, conn, cmd); |
| 4681 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4682 | #ifdef ANDROID_NAN |
| 4683 | if (val && strcasecmp(val, "NAN") == 0) |
| 4684 | return nan_cmd_sta_preset_testparameters(dut, conn, cmd); |
| 4685 | #endif /* ANDROID_NAN */ |
Amarnath Hullur Subramanyam | 9c381f5 | 2017-03-17 00:04:41 -0700 | [diff] [blame] | 4686 | #ifdef MIRACAST |
| 4687 | if (val && (strcasecmp(val, "WFD") == 0 || |
| 4688 | strcasecmp(val, "DisplayR2") == 0)) |
| 4689 | return miracast_preset_testparameters(dut, conn, cmd); |
| 4690 | #endif /* MIRACAST */ |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4691 | |
Ashwini Patil | 68d02cd | 2017-01-10 15:39:16 +0530 | [diff] [blame] | 4692 | if (val && strcasecmp(val, "MBO") == 0) { |
| 4693 | val = get_param(cmd, "Cellular_Data_Cap"); |
| 4694 | if (val && |
| 4695 | mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0) |
| 4696 | return 0; |
Ashwini Patil | 0040258 | 2017-04-13 12:29:39 +0530 | [diff] [blame] | 4697 | |
| 4698 | val = get_param(cmd, "Ch_Pref"); |
| 4699 | if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0) |
| 4700 | return 0; |
| 4701 | |
Ashwini Patil | c63161e | 2017-04-13 16:30:23 +0530 | [diff] [blame] | 4702 | val = get_param(cmd, "BSS_Transition"); |
| 4703 | if (val && mbo_set_bss_trans_req(dut, conn, intf, val) == 0) |
| 4704 | return 0; |
| 4705 | |
Ashwini Patil | a75de5a | 2017-04-13 16:35:05 +0530 | [diff] [blame] | 4706 | val = get_param(cmd, "Assoc_Disallow"); |
| 4707 | if (val && mbo_set_assoc_disallow(dut, conn, intf, val) == 0) |
| 4708 | return 0; |
| 4709 | |
Ashwini Patil | 9183fdb | 2017-04-13 16:58:25 +0530 | [diff] [blame] | 4710 | val = get_param(cmd, "Roaming"); |
| 4711 | if (val && mbo_set_roaming(dut, conn, intf, val) == 0) |
| 4712 | return 0; |
| 4713 | |
Ashwini Patil | 68d02cd | 2017-01-10 15:39:16 +0530 | [diff] [blame] | 4714 | return 1; |
| 4715 | } |
| 4716 | |
Ankita Bajaj | a2cb567 | 2017-10-25 16:08:28 +0530 | [diff] [blame] | 4717 | if (val && strcasecmp(val, "OCE") == 0) |
| 4718 | return cmd_sta_preset_testparameters_oce(dut, conn, intf, cmd); |
| 4719 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4720 | #if 0 |
| 4721 | val = get_param(cmd, "Supplicant"); |
| 4722 | if (val && strcasecmp(val, "Default") != 0) { |
| 4723 | send_resp(dut, conn, SIGMA_ERROR, |
| 4724 | "ErrorCode,Only default(Vendor) supplicant " |
| 4725 | "supported"); |
| 4726 | return 0; |
| 4727 | } |
| 4728 | #endif |
| 4729 | |
| 4730 | val = get_param(cmd, "RTS"); |
| 4731 | if (val) { |
| 4732 | switch (get_driver_type()) { |
| 4733 | case DRIVER_ATHEROS: |
| 4734 | ath_sta_set_rts(dut, intf, val); |
| 4735 | break; |
| 4736 | default: |
| 4737 | #if 0 |
| 4738 | send_resp(dut, conn, SIGMA_ERROR, |
| 4739 | "ErrorCode,Setting RTS not supported"); |
| 4740 | return 0; |
| 4741 | #else |
| 4742 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 4743 | "Setting RTS not supported"); |
| 4744 | break; |
| 4745 | #endif |
| 4746 | } |
| 4747 | } |
| 4748 | |
| 4749 | #if 0 |
| 4750 | val = get_param(cmd, "FRGMNT"); |
| 4751 | if (val) { |
| 4752 | /* TODO */ |
| 4753 | send_resp(dut, conn, SIGMA_ERROR, |
| 4754 | "ErrorCode,Setting FRGMNT not supported"); |
| 4755 | return 0; |
| 4756 | } |
| 4757 | #endif |
| 4758 | |
| 4759 | #if 0 |
| 4760 | val = get_param(cmd, "Preamble"); |
| 4761 | if (val) { |
| 4762 | /* TODO: Long/Short */ |
| 4763 | send_resp(dut, conn, SIGMA_ERROR, |
| 4764 | "ErrorCode,Setting Preamble not supported"); |
| 4765 | return 0; |
| 4766 | } |
| 4767 | #endif |
| 4768 | |
| 4769 | val = get_param(cmd, "Mode"); |
| 4770 | if (val) { |
| 4771 | if (strcmp(val, "11b") == 0 || |
| 4772 | strcmp(val, "11g") == 0 || |
| 4773 | strcmp(val, "11a") == 0 || |
| 4774 | strcmp(val, "11n") == 0 || |
| 4775 | strcmp(val, "11ng") == 0 || |
| 4776 | strcmp(val, "11nl") == 0 || |
| 4777 | strcmp(val, "11nl(nabg)") == 0 || |
| 4778 | strcmp(val, "AC") == 0 || |
| 4779 | strcmp(val, "11AC") == 0 || |
| 4780 | strcmp(val, "11ac") == 0 || |
| 4781 | strcmp(val, "11na") == 0 || |
Amarnath Hullur Subramanyam | b0db271 | 2018-01-30 19:40:35 -0800 | [diff] [blame] | 4782 | strcmp(val, "11an") == 0 || |
| 4783 | strcmp(val, "11ax") == 0) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4784 | /* STA supports all modes by default */ |
| 4785 | } else { |
| 4786 | send_resp(dut, conn, SIGMA_ERROR, |
| 4787 | "ErrorCode,Setting Mode not supported"); |
| 4788 | return 0; |
| 4789 | } |
Amarnath Hullur Subramanyam | 97d0e53 | 2018-01-31 02:53:02 -0800 | [diff] [blame] | 4790 | |
| 4791 | /* Change the mode only in case of testbed for HE program |
| 4792 | * and for 11a and 11g modes only. */ |
| 4793 | if (dut->program == PROGRAM_HE && |
| 4794 | dut->device_type == STA_testbed) { |
| 4795 | int phymode; |
| 4796 | char buf[60]; |
| 4797 | |
| 4798 | if (strcmp(val, "11a") == 0) { |
Amarnath Hullur Subramanyam | 94dfaf0 | 2018-03-02 19:26:57 -0800 | [diff] [blame] | 4799 | phymode = 1; /* IEEE80211_MODE_11A */ |
| 4800 | } else if (strcmp(val, "11g") == 0) { |
| 4801 | phymode = 3; /* IEEE80211_MODE_11G */ |
| 4802 | } else if (strcmp(val, "11b") == 0) { |
| 4803 | phymode = 2; /* IEEE80211_MODE_11B */ |
| 4804 | } else if (strcmp(val, "11n") == 0 || |
| 4805 | strcmp(val, "11nl") == 0 || |
| 4806 | strcmp(val, "11nl(nabg)") == 0) { |
| 4807 | phymode = 22; /* IEEE80211_MODE_11AGN */ |
| 4808 | } else if (strcmp(val, "11ng") == 0) { |
| 4809 | phymode = 13; /* IEEE80211_MODE_11NG_HT40 */ |
| 4810 | } else if (strcmp(val, "AC") == 0 || |
| 4811 | strcasecmp(val, "11AC") == 0) { |
| 4812 | phymode = 19; /* IEEE80211_MODE_11AC_VHT80 */ |
| 4813 | } else if (strcmp(val, "11na") == 0 || |
| 4814 | strcasecmp(val, "11an") == 0) { |
| 4815 | phymode = 14; /* IEEE80211_MODE_11NA_HT40 */ |
| 4816 | } else if (strcmp(val, "11ax") == 0) { |
| 4817 | phymode = 0; /* IEEE80211_MODE_AUTO */ |
Amarnath Hullur Subramanyam | 97d0e53 | 2018-01-31 02:53:02 -0800 | [diff] [blame] | 4818 | } else { |
| 4819 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 4820 | "Ignoring mode change for mode: %s", |
| 4821 | val); |
| 4822 | phymode = -1; |
| 4823 | } |
| 4824 | if (phymode != -1) { |
| 4825 | snprintf(buf, sizeof(buf), |
| 4826 | "iwpriv %s setphymode %d", |
| 4827 | intf, phymode); |
| 4828 | if (system(buf) != 0) { |
| 4829 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4830 | "iwpriv setting of phymode failed"); |
| 4831 | } |
| 4832 | } |
| 4833 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4834 | } |
| 4835 | |
| 4836 | val = get_param(cmd, "wmm"); |
| 4837 | if (val) { |
| 4838 | switch (get_driver_type()) { |
| 4839 | case DRIVER_ATHEROS: |
| 4840 | ath_sta_set_wmm(dut, intf, val); |
| 4841 | break; |
Amarnath Hullur Subramanyam | 75214d2 | 2018-02-04 19:17:11 -0800 | [diff] [blame] | 4842 | case DRIVER_WCN: |
| 4843 | wcn_sta_set_wmm(dut, intf, val); |
| 4844 | break; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4845 | default: |
| 4846 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 4847 | "Setting wmm not supported"); |
| 4848 | break; |
| 4849 | } |
| 4850 | } |
| 4851 | |
| 4852 | val = get_param(cmd, "Powersave"); |
| 4853 | if (val) { |
Kiran Kumar Lokere | d6149ff | 2018-12-05 20:20:41 -0800 | [diff] [blame] | 4854 | char buf[60]; |
| 4855 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4856 | if (strcmp(val, "0") == 0 || strcasecmp(val, "off") == 0) { |
Kiran Kumar Lokere | d6149ff | 2018-12-05 20:20:41 -0800 | [diff] [blame] | 4857 | if (get_driver_type() == DRIVER_WCN) { |
| 4858 | snprintf(buf, sizeof(buf), |
| 4859 | "iwpriv %s setPower 2", intf); |
| 4860 | if (system(buf) != 0) { |
| 4861 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4862 | "iwpriv setPower 2 failed"); |
| 4863 | return 0; |
| 4864 | } |
| 4865 | } |
| 4866 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4867 | if (wpa_command(get_station_ifname(), |
| 4868 | "P2P_SET ps 0") < 0) |
| 4869 | return -2; |
| 4870 | /* Make sure test modes are disabled */ |
| 4871 | wpa_command(get_station_ifname(), "P2P_SET ps 98"); |
| 4872 | wpa_command(get_station_ifname(), "P2P_SET ps 96"); |
| 4873 | } else if (strcmp(val, "1") == 0 || |
| 4874 | strcasecmp(val, "PSPoll") == 0 || |
| 4875 | strcasecmp(val, "on") == 0) { |
Kiran Kumar Lokere | d6149ff | 2018-12-05 20:20:41 -0800 | [diff] [blame] | 4876 | if (get_driver_type() == DRIVER_WCN) { |
| 4877 | snprintf(buf, sizeof(buf), |
| 4878 | "iwpriv %s setPower 1", intf); |
| 4879 | if (system(buf) != 0) { |
| 4880 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4881 | "iwpriv setPower 1 failed"); |
| 4882 | return 0; |
| 4883 | } |
| 4884 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4885 | /* Disable default power save mode */ |
| 4886 | wpa_command(get_station_ifname(), "P2P_SET ps 0"); |
| 4887 | /* Enable PS-Poll test mode */ |
| 4888 | if (wpa_command(get_station_ifname(), |
| 4889 | "P2P_SET ps 97") < 0 || |
| 4890 | wpa_command(get_station_ifname(), |
| 4891 | "P2P_SET ps 99") < 0) |
| 4892 | return -2; |
| 4893 | } else if (strcmp(val, "2") == 0 || |
| 4894 | strcasecmp(val, "Fast") == 0) { |
| 4895 | /* TODO */ |
| 4896 | send_resp(dut, conn, SIGMA_ERROR, |
| 4897 | "ErrorCode,Powersave=Fast not supported"); |
| 4898 | return 0; |
| 4899 | } else if (strcmp(val, "3") == 0 || |
| 4900 | strcasecmp(val, "PSNonPoll") == 0) { |
| 4901 | /* Make sure test modes are disabled */ |
| 4902 | wpa_command(get_station_ifname(), "P2P_SET ps 98"); |
| 4903 | wpa_command(get_station_ifname(), "P2P_SET ps 96"); |
| 4904 | |
| 4905 | /* Enable default power save mode */ |
| 4906 | if (wpa_command(get_station_ifname(), |
| 4907 | "P2P_SET ps 1") < 0) |
| 4908 | return -2; |
| 4909 | } else |
| 4910 | return -1; |
| 4911 | } |
| 4912 | |
| 4913 | val = get_param(cmd, "NoAck"); |
| 4914 | if (val) { |
| 4915 | switch (get_driver_type()) { |
| 4916 | case DRIVER_ATHEROS: |
| 4917 | ath_sta_set_noack(dut, intf, val); |
| 4918 | break; |
Amarnath Hullur Subramanyam | ae8a2d9 | 2018-03-01 06:32:21 -0800 | [diff] [blame] | 4919 | #ifdef NL80211_SUPPORT |
| 4920 | case DRIVER_WCN: |
| 4921 | wcn_sta_set_noack(dut, intf, val); |
| 4922 | break; |
| 4923 | #endif /* NL80211_SUPPORT */ |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4924 | default: |
| 4925 | send_resp(dut, conn, SIGMA_ERROR, |
| 4926 | "ErrorCode,Setting NoAck not supported"); |
| 4927 | return 0; |
| 4928 | } |
| 4929 | } |
| 4930 | |
| 4931 | val = get_param(cmd, "IgnoreChswitchProhibit"); |
| 4932 | if (val) { |
| 4933 | /* TODO: Enabled/disabled */ |
| 4934 | if (strcasecmp(val, "Enabled") == 0) { |
| 4935 | send_resp(dut, conn, SIGMA_ERROR, |
| 4936 | "ErrorCode,Enabling IgnoreChswitchProhibit " |
| 4937 | "not supported"); |
| 4938 | return 0; |
| 4939 | } |
| 4940 | } |
| 4941 | |
| 4942 | val = get_param(cmd, "TDLS"); |
| 4943 | if (val) { |
| 4944 | if (strcasecmp(val, "Disabled") == 0) { |
| 4945 | if (wpa_command(intf, "SET tdls_disabled 1")) { |
| 4946 | send_resp(dut, conn, SIGMA_ERROR, |
| 4947 | "ErrorCode,Failed to disable TDLS"); |
| 4948 | return 0; |
| 4949 | } |
| 4950 | } else if (strcasecmp(val, "Enabled") == 0) { |
| 4951 | if (wpa_command(intf, "SET tdls_disabled 0")) { |
| 4952 | send_resp(dut, conn, SIGMA_ERROR, |
| 4953 | "ErrorCode,Failed to enable TDLS"); |
| 4954 | return 0; |
| 4955 | } |
| 4956 | } else { |
| 4957 | send_resp(dut, conn, SIGMA_ERROR, |
| 4958 | "ErrorCode,Unsupported TDLS value"); |
| 4959 | return 0; |
| 4960 | } |
| 4961 | } |
| 4962 | |
| 4963 | val = get_param(cmd, "TDLSmode"); |
| 4964 | if (val) { |
| 4965 | if (strcasecmp(val, "Default") == 0) { |
| 4966 | wpa_command(intf, "SET tdls_testing 0"); |
| 4967 | } else if (strcasecmp(val, "APProhibit") == 0) { |
| 4968 | if (wpa_command(intf, "SET tdls_testing 0x400")) { |
| 4969 | send_resp(dut, conn, SIGMA_ERROR, |
| 4970 | "ErrorCode,Failed to enable ignore " |
| 4971 | "APProhibit TDLS mode"); |
| 4972 | return 0; |
| 4973 | } |
| 4974 | } else if (strcasecmp(val, "HiLoMac") == 0) { |
| 4975 | /* STA should respond with TDLS setup req for a TDLS |
| 4976 | * setup req */ |
| 4977 | if (wpa_command(intf, "SET tdls_testing 0x80")) { |
| 4978 | send_resp(dut, conn, SIGMA_ERROR, |
| 4979 | "ErrorCode,Failed to enable HiLoMac " |
| 4980 | "TDLS mode"); |
| 4981 | return 0; |
| 4982 | } |
| 4983 | } else if (strcasecmp(val, "WeakSecurity") == 0) { |
| 4984 | /* |
| 4985 | * Since all security modes are enabled by default when |
| 4986 | * Sigma control is used, there is no need to do |
| 4987 | * anything here. |
| 4988 | */ |
| 4989 | } else if (strcasecmp(val, "ExistLink") == 0) { |
| 4990 | /* |
| 4991 | * Since we allow new TDLS Setup Request even if there |
| 4992 | * is an existing link, nothing needs to be done for |
| 4993 | * this. |
| 4994 | */ |
| 4995 | } else { |
| 4996 | /* TODO: |
| 4997 | * ExistLink: STA should send TDLS setup req even if |
| 4998 | * direct link already exists |
| 4999 | */ |
| 5000 | send_resp(dut, conn, SIGMA_ERROR, |
| 5001 | "ErrorCode,Unsupported TDLSmode value"); |
| 5002 | return 0; |
| 5003 | } |
| 5004 | } |
| 5005 | |
| 5006 | val = get_param(cmd, "FakePubKey"); |
| 5007 | if (val && atoi(val) && wpa_command(intf, "SET wps_corrupt_pkhash 1")) { |
| 5008 | send_resp(dut, conn, SIGMA_ERROR, |
| 5009 | "ErrorCode,Failed to enable FakePubKey"); |
| 5010 | return 0; |
| 5011 | } |
| 5012 | |
Amarnath Hullur Subramanyam | ae1042b | 2018-02-22 21:52:52 -0800 | [diff] [blame] | 5013 | #ifdef NL80211_SUPPORT |
| 5014 | val = get_param(cmd, "FrgmntSupport"); |
| 5015 | if (val) { |
| 5016 | if (strcasecmp(val, "Enable") == 0) { |
| 5017 | if (sta_set_he_fragmentation(dut, intf, |
| 5018 | HE_FRAG_LEVEL1)) { |
| 5019 | send_resp(dut, conn, SIGMA_ERROR, |
| 5020 | "ErrorCode,Failed to enable HE Fragmentation"); |
| 5021 | return 0; |
| 5022 | } |
| 5023 | } else if (strcasecmp(val, "Disable") == 0) { |
| 5024 | if (sta_set_he_fragmentation(dut, intf, |
| 5025 | HE_FRAG_DISABLE)) { |
| 5026 | send_resp(dut, conn, SIGMA_ERROR, |
| 5027 | "ErrorCode,Failed to disable HE Fragmentation"); |
| 5028 | return 0; |
| 5029 | } |
| 5030 | } |
| 5031 | } |
| 5032 | #endif /* NL80211_SUPPORT */ |
| 5033 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5034 | return 1; |
| 5035 | } |
| 5036 | |
| 5037 | |
| 5038 | static const char * ath_get_radio_name(const char *radio_name) |
| 5039 | { |
| 5040 | if (radio_name == NULL) |
| 5041 | return "wifi0"; |
| 5042 | if (strcmp(radio_name, "wifi1") == 0) |
| 5043 | return "wifi1"; |
| 5044 | if (strcmp(radio_name, "wifi2") == 0) |
| 5045 | return "wifi2"; |
| 5046 | return "wifi0"; |
| 5047 | } |
| 5048 | |
| 5049 | |
| 5050 | static void ath_sta_set_txsp_stream(struct sigma_dut *dut, const char *intf, |
| 5051 | const char *val) |
| 5052 | { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5053 | unsigned int vht_mcsmap = 0; |
| 5054 | int txchainmask = 0; |
| 5055 | const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]); |
| 5056 | |
| 5057 | if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) { |
| 5058 | if (dut->testbed_flag_txsp == 1) { |
| 5059 | vht_mcsmap = 0xfffc; |
| 5060 | dut->testbed_flag_txsp = 0; |
| 5061 | } else { |
| 5062 | vht_mcsmap = 0xfffe; |
| 5063 | } |
| 5064 | txchainmask = 1; |
| 5065 | } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) { |
| 5066 | if (dut->testbed_flag_txsp == 1) { |
| 5067 | vht_mcsmap = 0xfff0; |
| 5068 | dut->testbed_flag_txsp = 0; |
| 5069 | } else { |
| 5070 | vht_mcsmap = 0xfffa; |
| 5071 | } |
| 5072 | txchainmask = 3; |
| 5073 | } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) { |
| 5074 | if (dut->testbed_flag_txsp == 1) { |
| 5075 | vht_mcsmap = 0xffc0; |
| 5076 | dut->testbed_flag_txsp = 0; |
| 5077 | } else { |
| 5078 | vht_mcsmap = 0xffea; |
| 5079 | } |
| 5080 | txchainmask = 7; |
| 5081 | } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) { |
| 5082 | if (dut->testbed_flag_txsp == 1) { |
| 5083 | vht_mcsmap = 0xff00; |
| 5084 | dut->testbed_flag_txsp = 0; |
| 5085 | } else { |
| 5086 | vht_mcsmap = 0xffaa; |
| 5087 | } |
| 5088 | txchainmask = 15; |
| 5089 | } else { |
| 5090 | if (dut->testbed_flag_txsp == 1) { |
| 5091 | vht_mcsmap = 0xffc0; |
| 5092 | dut->testbed_flag_txsp = 0; |
| 5093 | } else { |
| 5094 | vht_mcsmap = 0xffea; |
| 5095 | } |
| 5096 | } |
| 5097 | |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 5098 | if (txchainmask) |
| 5099 | run_iwpriv(dut, basedev, "txchainmask %d", txchainmask); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5100 | |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 5101 | run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5102 | } |
| 5103 | |
| 5104 | |
| 5105 | static void ath_sta_set_rxsp_stream(struct sigma_dut *dut, const char *intf, |
| 5106 | const char *val) |
| 5107 | { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5108 | unsigned int vht_mcsmap = 0; |
| 5109 | int rxchainmask = 0; |
| 5110 | const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]); |
| 5111 | |
| 5112 | if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) { |
| 5113 | if (dut->testbed_flag_rxsp == 1) { |
| 5114 | vht_mcsmap = 0xfffc; |
| 5115 | dut->testbed_flag_rxsp = 0; |
| 5116 | } else { |
| 5117 | vht_mcsmap = 0xfffe; |
| 5118 | } |
| 5119 | rxchainmask = 1; |
| 5120 | } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) { |
| 5121 | if (dut->testbed_flag_rxsp == 1) { |
| 5122 | vht_mcsmap = 0xfff0; |
| 5123 | dut->testbed_flag_rxsp = 0; |
| 5124 | } else { |
| 5125 | vht_mcsmap = 0xfffa; |
| 5126 | } |
| 5127 | rxchainmask = 3; |
| 5128 | } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) { |
| 5129 | if (dut->testbed_flag_rxsp == 1) { |
| 5130 | vht_mcsmap = 0xffc0; |
| 5131 | dut->testbed_flag_rxsp = 0; |
| 5132 | } else { |
| 5133 | vht_mcsmap = 0xffea; |
| 5134 | } |
| 5135 | rxchainmask = 7; |
| 5136 | } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) { |
| 5137 | if (dut->testbed_flag_rxsp == 1) { |
| 5138 | vht_mcsmap = 0xff00; |
| 5139 | dut->testbed_flag_rxsp = 0; |
| 5140 | } else { |
| 5141 | vht_mcsmap = 0xffaa; |
| 5142 | } |
| 5143 | rxchainmask = 15; |
| 5144 | } else { |
| 5145 | if (dut->testbed_flag_rxsp == 1) { |
| 5146 | vht_mcsmap = 0xffc0; |
| 5147 | dut->testbed_flag_rxsp = 0; |
| 5148 | } else { |
| 5149 | vht_mcsmap = 0xffea; |
| 5150 | } |
| 5151 | } |
| 5152 | |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 5153 | if (rxchainmask) |
| 5154 | run_iwpriv(dut, basedev, "rxchainmask %d", rxchainmask); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5155 | |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 5156 | run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5157 | } |
| 5158 | |
| 5159 | |
| 5160 | void ath_set_zero_crc(struct sigma_dut *dut, const char *val) |
| 5161 | { |
| 5162 | if (strcasecmp(val, "enable") == 0) { |
| 5163 | if (system("athdiag --set --address=0x2a204 --and=0xbfffffff") |
| 5164 | != 0) { |
| 5165 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5166 | "Disable BB_VHTSIGB_CRC_CALC failed"); |
| 5167 | } |
| 5168 | |
| 5169 | if (system("athdiag --set --address=0x2a204 --or=0x80000000") |
| 5170 | != 0) { |
| 5171 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5172 | "Enable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed"); |
| 5173 | } |
| 5174 | } else { |
| 5175 | if (system("athdiag --set --address=0x2a204 --and=0x7fffffff") |
| 5176 | != 0) { |
| 5177 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5178 | "Disable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed"); |
| 5179 | } |
| 5180 | |
| 5181 | if (system("athdiag --set --address=0x2a204 --or=0x40000000") |
| 5182 | != 0) { |
| 5183 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5184 | "Enable BB_VHTSIGB_CRC_CALC failed"); |
| 5185 | } |
| 5186 | } |
| 5187 | } |
| 5188 | |
| 5189 | |
Amarnath Hullur Subramanyam | ebfe6b6 | 2018-01-31 03:04:17 -0800 | [diff] [blame] | 5190 | static int wcn_sta_set_width(struct sigma_dut *dut, const char *intf, |
| 5191 | const char *val) |
| 5192 | { |
| 5193 | char buf[60]; |
| 5194 | |
| 5195 | if (strcmp(val, "20") == 0) { |
| 5196 | snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf); |
| 5197 | dut->chwidth = 0; |
| 5198 | } else if (strcmp(val, "40") == 0) { |
| 5199 | snprintf(buf, sizeof(buf), "iwpriv %s chwidth 1", intf); |
| 5200 | dut->chwidth = 1; |
| 5201 | } else if (strcmp(val, "80") == 0) { |
| 5202 | snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf); |
| 5203 | dut->chwidth = 2; |
Sunil Dutt | b1cccac | 2018-05-22 21:03:12 +0530 | [diff] [blame] | 5204 | } else if (strcasecmp(val, "Auto") == 0) { |
Amarnath Hullur Subramanyam | ebfe6b6 | 2018-01-31 03:04:17 -0800 | [diff] [blame] | 5205 | buf[0] = '\0'; |
| 5206 | } else { |
| 5207 | sigma_dut_print(dut, DUT_MSG_ERROR, "WIDTH %s not supported", |
| 5208 | val); |
| 5209 | return -1; |
| 5210 | } |
| 5211 | |
| 5212 | if (buf[0] != '\0' && system(buf) != 0) { |
| 5213 | sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv chwidth failed"); |
| 5214 | return -1; |
| 5215 | } |
| 5216 | |
| 5217 | return 0; |
| 5218 | } |
| 5219 | |
| 5220 | |
Amarnath Hullur Subramanyam | d8a9db9 | 2018-02-02 18:53:14 -0800 | [diff] [blame] | 5221 | static int nlvendor_sta_set_addba_reject(struct sigma_dut *dut, |
| 5222 | const char *intf, int addbareject) |
| 5223 | { |
| 5224 | #ifdef NL80211_SUPPORT |
| 5225 | struct nl_msg *msg; |
| 5226 | int ret = 0; |
| 5227 | struct nlattr *params; |
| 5228 | int ifindex; |
| 5229 | |
| 5230 | ifindex = if_nametoindex(intf); |
| 5231 | if (ifindex == 0) { |
| 5232 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5233 | "%s: Index for interface %s failed", |
| 5234 | __func__, intf); |
| 5235 | return -1; |
| 5236 | } |
| 5237 | |
| 5238 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 5239 | NL80211_CMD_VENDOR)) || |
| 5240 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 5241 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 5242 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 5243 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || |
| 5244 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 5245 | nla_put_u8(msg, |
| 5246 | QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ACCEPT_ADDBA_REQ, |
| 5247 | !addbareject)) { |
| 5248 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5249 | "%s: err in adding vendor_cmd and vendor_data", |
| 5250 | __func__); |
| 5251 | nlmsg_free(msg); |
| 5252 | return -1; |
| 5253 | } |
| 5254 | nla_nest_end(msg, params); |
| 5255 | |
| 5256 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 5257 | if (ret) { |
| 5258 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5259 | "%s: err in send_and_recv_msgs, ret=%d", |
| 5260 | __func__, ret); |
| 5261 | } |
| 5262 | return ret; |
| 5263 | #else /* NL80211_SUPPORT */ |
| 5264 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5265 | "ADDBA_REJECT cannot be set without NL80211_SUPPORT defined"); |
| 5266 | return -1; |
| 5267 | #endif /* NL80211_SUPPORT */ |
| 5268 | } |
| 5269 | |
| 5270 | |
| 5271 | static int sta_set_addba_reject(struct sigma_dut *dut, const char *intf, |
| 5272 | int addbareject) |
| 5273 | { |
| 5274 | int ret; |
| 5275 | |
| 5276 | switch (get_driver_type()) { |
| 5277 | case DRIVER_WCN: |
| 5278 | ret = nlvendor_sta_set_addba_reject(dut, intf, addbareject); |
| 5279 | if (ret) { |
| 5280 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5281 | "nlvendor_sta_set_addba_reject failed, ret:%d", |
| 5282 | ret); |
| 5283 | return ret; |
| 5284 | } |
| 5285 | break; |
| 5286 | default: |
| 5287 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5288 | "errorCode,Unsupported ADDBA_REJECT with the current driver"); |
| 5289 | ret = -1; |
| 5290 | break; |
| 5291 | } |
| 5292 | |
| 5293 | return ret; |
| 5294 | } |
| 5295 | |
| 5296 | |
Amarnath Hullur Subramanyam | 1f65a67 | 2018-03-07 14:50:29 -0800 | [diff] [blame] | 5297 | static int nlvendor_config_send_addba(struct sigma_dut *dut, const char *intf, |
| 5298 | int enable) |
Amarnath Hullur Subramanyam | 9745b3c | 2018-02-04 21:27:57 -0800 | [diff] [blame] | 5299 | { |
| 5300 | #ifdef NL80211_SUPPORT |
| 5301 | struct nl_msg *msg; |
| 5302 | int ret = 0; |
| 5303 | struct nlattr *params; |
| 5304 | int ifindex; |
| 5305 | |
| 5306 | ifindex = if_nametoindex(intf); |
| 5307 | if (ifindex == 0) { |
| 5308 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5309 | "%s: Index for interface %s failed", |
| 5310 | __func__, intf); |
| 5311 | return -1; |
| 5312 | } |
| 5313 | |
| 5314 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 5315 | NL80211_CMD_VENDOR)) || |
| 5316 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 5317 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 5318 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 5319 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || |
| 5320 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 5321 | nla_put_u8(msg, |
| 5322 | QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SEND_ADDBA_REQ, |
Amarnath Hullur Subramanyam | 1f65a67 | 2018-03-07 14:50:29 -0800 | [diff] [blame] | 5323 | enable)) { |
Amarnath Hullur Subramanyam | 9745b3c | 2018-02-04 21:27:57 -0800 | [diff] [blame] | 5324 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5325 | "%s: err in adding vendor_cmd and vendor_data", |
| 5326 | __func__); |
| 5327 | nlmsg_free(msg); |
| 5328 | return -1; |
| 5329 | } |
| 5330 | nla_nest_end(msg, params); |
| 5331 | |
| 5332 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 5333 | if (ret) { |
| 5334 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5335 | "%s: err in send_and_recv_msgs, ret=%d", |
| 5336 | __func__, ret); |
| 5337 | } |
| 5338 | return ret; |
| 5339 | #else /* NL80211_SUPPORT */ |
| 5340 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5341 | "Disable addba not possible without NL80211_SUPPORT defined"); |
| 5342 | return -1; |
| 5343 | #endif /* NL80211_SUPPORT */ |
| 5344 | } |
| 5345 | |
| 5346 | |
Veerendranath Jakkam | adcd620 | 2019-04-17 12:32:21 +0530 | [diff] [blame] | 5347 | #ifdef NL80211_SUPPORT |
| 5348 | static int nl80211_sta_set_rts(struct sigma_dut *dut, const char *intf, int val) |
| 5349 | { |
| 5350 | struct nl_msg *msg; |
| 5351 | int ret = 0; |
| 5352 | int ifindex; |
| 5353 | |
| 5354 | ifindex = if_nametoindex(intf); |
| 5355 | if (ifindex == 0) { |
| 5356 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5357 | "%s: Index for interface %s failed", |
| 5358 | __func__, intf); |
| 5359 | return -1; |
| 5360 | } |
| 5361 | |
| 5362 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 5363 | NL80211_CMD_SET_WIPHY)) || |
| 5364 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) { |
| 5365 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5366 | "%s: err in adding RTS threshold", |
| 5367 | __func__); |
| 5368 | nlmsg_free(msg); |
| 5369 | return -1; |
| 5370 | } |
| 5371 | |
| 5372 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 5373 | if (ret) { |
| 5374 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5375 | "%s: err in send_and_recv_msgs, ret=%d", |
| 5376 | __func__, ret); |
| 5377 | } |
| 5378 | return ret; |
| 5379 | } |
| 5380 | #endif /* NL80211_SUPPORT */ |
| 5381 | |
| 5382 | |
| 5383 | static int sta_set_rts(struct sigma_dut *dut, const char *intf, int val) |
| 5384 | { |
| 5385 | char buf[100]; |
| 5386 | |
| 5387 | #ifdef NL80211_SUPPORT |
| 5388 | if (nl80211_sta_set_rts(dut, intf, val) == 0) |
| 5389 | return 0; |
| 5390 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 5391 | "Fall back to using iwconfig for setting RTS threshold"); |
| 5392 | #endif /* NL80211_SUPPORT */ |
| 5393 | |
| 5394 | snprintf(buf, sizeof(buf), "iwconfig %s rts %d", intf, val); |
| 5395 | if (system(buf) != 0) { |
| 5396 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5397 | "Failed to set RTS threshold %d", val); |
| 5398 | return -1; |
| 5399 | } |
| 5400 | return 0; |
| 5401 | } |
| 5402 | |
| 5403 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5404 | static int cmd_sta_set_wireless_common(const char *intf, struct sigma_dut *dut, |
| 5405 | struct sigma_conn *conn, |
| 5406 | struct sigma_cmd *cmd) |
| 5407 | { |
| 5408 | const char *val; |
Amarnath Hullur Subramanyam | d8a9db9 | 2018-02-02 18:53:14 -0800 | [diff] [blame] | 5409 | int ampdu = -1, addbareject = -1; |
Jouni Malinen | 3aa7286 | 2019-05-29 23:14:51 +0300 | [diff] [blame] | 5410 | char buf[128]; |
| 5411 | int res; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5412 | |
| 5413 | val = get_param(cmd, "40_INTOLERANT"); |
| 5414 | if (val) { |
| 5415 | if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) { |
| 5416 | /* TODO: iwpriv ht40intol through wpa_supplicant */ |
| 5417 | send_resp(dut, conn, SIGMA_ERROR, |
| 5418 | "ErrorCode,40_INTOLERANT not supported"); |
| 5419 | return 0; |
| 5420 | } |
| 5421 | } |
| 5422 | |
| 5423 | val = get_param(cmd, "ADDBA_REJECT"); |
| 5424 | if (val) { |
| 5425 | if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) { |
| 5426 | /* reject any ADDBA with status "decline" */ |
| 5427 | ampdu = 0; |
Amarnath Hullur Subramanyam | d8a9db9 | 2018-02-02 18:53:14 -0800 | [diff] [blame] | 5428 | addbareject = 1; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5429 | } else { |
| 5430 | /* accept ADDBA */ |
| 5431 | ampdu = 1; |
Amarnath Hullur Subramanyam | d8a9db9 | 2018-02-02 18:53:14 -0800 | [diff] [blame] | 5432 | addbareject = 0; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5433 | } |
| 5434 | } |
| 5435 | |
Amarnath Hullur Subramanyam | d8a9db9 | 2018-02-02 18:53:14 -0800 | [diff] [blame] | 5436 | if (addbareject >= 0 && |
| 5437 | sta_set_addba_reject(dut, intf, addbareject) < 0) { |
| 5438 | send_resp(dut, conn, SIGMA_ERROR, |
| 5439 | "ErrorCode,set addba_reject failed"); |
| 5440 | return 0; |
| 5441 | } |
| 5442 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5443 | val = get_param(cmd, "AMPDU"); |
| 5444 | if (val) { |
| 5445 | if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) { |
| 5446 | /* enable AMPDU Aggregation */ |
| 5447 | if (ampdu == 0) { |
| 5448 | send_resp(dut, conn, SIGMA_ERROR, |
| 5449 | "ErrorCode,Mismatch in " |
| 5450 | "addba_reject/ampdu - " |
| 5451 | "not supported"); |
| 5452 | return 0; |
| 5453 | } |
| 5454 | ampdu = 1; |
| 5455 | } else { |
| 5456 | /* disable AMPDU Aggregation */ |
| 5457 | if (ampdu == 1) { |
| 5458 | send_resp(dut, conn, SIGMA_ERROR, |
| 5459 | "ErrorCode,Mismatch in " |
| 5460 | "addba_reject/ampdu - " |
| 5461 | "not supported"); |
| 5462 | return 0; |
| 5463 | } |
| 5464 | ampdu = 0; |
| 5465 | } |
| 5466 | } |
| 5467 | |
| 5468 | if (ampdu >= 0) { |
Amarnath Hullur Subramanyam | 9745b3c | 2018-02-04 21:27:57 -0800 | [diff] [blame] | 5469 | int ret; |
| 5470 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5471 | sigma_dut_print(dut, DUT_MSG_DEBUG, "%s A-MPDU aggregation", |
| 5472 | ampdu ? "Enabling" : "Disabling"); |
| 5473 | snprintf(buf, sizeof(buf), "SET ampdu %d", ampdu); |
Deepak Dhamdhere | 80356cb | 2016-03-28 16:48:32 -0700 | [diff] [blame] | 5474 | if (wpa_command(intf, buf) < 0 && |
| 5475 | iwpriv_sta_set_ampdu(dut, intf, ampdu) < 0) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5476 | send_resp(dut, conn, SIGMA_ERROR, |
| 5477 | "ErrorCode,set aggr failed"); |
| 5478 | return 0; |
| 5479 | } |
Amarnath Hullur Subramanyam | 9745b3c | 2018-02-04 21:27:57 -0800 | [diff] [blame] | 5480 | |
| 5481 | if (ampdu == 0) { |
| 5482 | /* Disable sending of addba using nl vendor command */ |
Amarnath Hullur Subramanyam | 1f65a67 | 2018-03-07 14:50:29 -0800 | [diff] [blame] | 5483 | ret = nlvendor_config_send_addba(dut, intf, 0); |
Amarnath Hullur Subramanyam | 9745b3c | 2018-02-04 21:27:57 -0800 | [diff] [blame] | 5484 | if (ret) { |
| 5485 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5486 | "Failed to disable addba, ret:%d", |
| 5487 | ret); |
| 5488 | } |
| 5489 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5490 | } |
| 5491 | |
| 5492 | val = get_param(cmd, "AMSDU"); |
| 5493 | if (val) { |
| 5494 | switch (get_driver_type()) { |
| 5495 | case DRIVER_ATHEROS: |
Amarnath Hullur Subramanyam | d5bb573 | 2018-02-22 15:50:38 -0800 | [diff] [blame] | 5496 | case DRIVER_WCN: |
| 5497 | iwpriv_sta_set_amsdu(dut, intf, val); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5498 | break; |
| 5499 | default: |
| 5500 | if (strcmp(val, "1") == 0 || |
| 5501 | strcasecmp(val, "Enable") == 0) { |
| 5502 | /* Enable AMSDU Aggregation */ |
| 5503 | send_resp(dut, conn, SIGMA_ERROR, |
| 5504 | "ErrorCode,AMSDU aggregation not supported"); |
| 5505 | return 0; |
| 5506 | } |
| 5507 | break; |
| 5508 | } |
| 5509 | } |
| 5510 | |
| 5511 | val = get_param(cmd, "STBC_RX"); |
| 5512 | if (val) { |
| 5513 | switch (get_driver_type()) { |
| 5514 | case DRIVER_ATHEROS: |
| 5515 | ath_sta_set_stbc(dut, intf, val); |
| 5516 | break; |
Pradeep Reddy POTTETI | 4a1f6b3 | 2016-11-23 13:15:21 +0530 | [diff] [blame] | 5517 | case DRIVER_WCN: |
| 5518 | wcn_sta_set_stbc(dut, intf, val); |
| 5519 | break; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5520 | default: |
| 5521 | send_resp(dut, conn, SIGMA_ERROR, |
| 5522 | "ErrorCode,STBC_RX not supported"); |
| 5523 | return 0; |
| 5524 | } |
| 5525 | } |
| 5526 | |
| 5527 | val = get_param(cmd, "WIDTH"); |
| 5528 | if (val) { |
| 5529 | switch (get_driver_type()) { |
| 5530 | case DRIVER_WCN: |
Amarnath Hullur Subramanyam | ebfe6b6 | 2018-01-31 03:04:17 -0800 | [diff] [blame] | 5531 | if (wcn_sta_set_width(dut, intf, val) < 0) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5532 | send_resp(dut, conn, SIGMA_ERROR, |
| 5533 | "ErrorCode,Failed to set WIDTH"); |
| 5534 | return 0; |
| 5535 | } |
| 5536 | break; |
| 5537 | case DRIVER_ATHEROS: |
| 5538 | if (ath_set_width(dut, conn, intf, val) < 0) |
| 5539 | return 0; |
| 5540 | break; |
| 5541 | default: |
| 5542 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5543 | "Setting WIDTH not supported"); |
| 5544 | break; |
| 5545 | } |
| 5546 | } |
| 5547 | |
| 5548 | val = get_param(cmd, "SMPS"); |
| 5549 | if (val) { |
| 5550 | /* TODO: Dynamic/0, Static/1, No Limit/2 */ |
| 5551 | send_resp(dut, conn, SIGMA_ERROR, |
| 5552 | "ErrorCode,SMPS not supported"); |
| 5553 | return 0; |
| 5554 | } |
| 5555 | |
| 5556 | val = get_param(cmd, "TXSP_STREAM"); |
| 5557 | if (val) { |
| 5558 | switch (get_driver_type()) { |
| 5559 | case DRIVER_WCN: |
| 5560 | if (wcn_sta_set_sp_stream(dut, intf, val) < 0) { |
| 5561 | send_resp(dut, conn, SIGMA_ERROR, |
| 5562 | "ErrorCode,Failed to set TXSP_STREAM"); |
| 5563 | return 0; |
| 5564 | } |
| 5565 | break; |
| 5566 | case DRIVER_ATHEROS: |
| 5567 | ath_sta_set_txsp_stream(dut, intf, val); |
| 5568 | break; |
| 5569 | default: |
| 5570 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5571 | "Setting TXSP_STREAM not supported"); |
| 5572 | break; |
| 5573 | } |
| 5574 | } |
| 5575 | |
| 5576 | val = get_param(cmd, "RXSP_STREAM"); |
| 5577 | if (val) { |
| 5578 | switch (get_driver_type()) { |
| 5579 | case DRIVER_WCN: |
| 5580 | if (wcn_sta_set_sp_stream(dut, intf, val) < 0) { |
| 5581 | send_resp(dut, conn, SIGMA_ERROR, |
| 5582 | "ErrorCode,Failed to set RXSP_STREAM"); |
| 5583 | return 0; |
| 5584 | } |
| 5585 | break; |
| 5586 | case DRIVER_ATHEROS: |
| 5587 | ath_sta_set_rxsp_stream(dut, intf, val); |
| 5588 | break; |
| 5589 | default: |
| 5590 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5591 | "Setting RXSP_STREAM not supported"); |
| 5592 | break; |
| 5593 | } |
| 5594 | } |
| 5595 | |
| 5596 | val = get_param(cmd, "DYN_BW_SGNL"); |
| 5597 | if (val) { |
Priyadharshini Gowthaman | 818afef | 2015-11-09 13:28:15 -0800 | [diff] [blame] | 5598 | switch (get_driver_type()) { |
| 5599 | case DRIVER_WCN: |
Peng Xu | c59afd3 | 2016-11-21 15:01:11 -0800 | [diff] [blame] | 5600 | if (strcasecmp(val, "enable") == 0) { |
| 5601 | snprintf(buf, sizeof(buf), |
| 5602 | "iwpriv %s cwmenable 1", intf); |
| 5603 | if (system(buf) != 0) { |
| 5604 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5605 | "iwpriv cwmenable 1 failed"); |
| 5606 | return 0; |
| 5607 | } |
| 5608 | } else if (strcasecmp(val, "disable") == 0) { |
| 5609 | snprintf(buf, sizeof(buf), |
| 5610 | "iwpriv %s cwmenable 0", intf); |
| 5611 | if (system(buf) != 0) { |
| 5612 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5613 | "iwpriv cwmenable 0 failed"); |
| 5614 | return 0; |
| 5615 | } |
| 5616 | } else { |
| 5617 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5618 | "Unsupported DYN_BW_SGL"); |
| 5619 | } |
| 5620 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5621 | snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf); |
| 5622 | if (system(buf) != 0) { |
| 5623 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5624 | "Failed to set cts_cbw in DYN_BW_SGNL"); |
| 5625 | return 0; |
| 5626 | } |
Priyadharshini Gowthaman | 818afef | 2015-11-09 13:28:15 -0800 | [diff] [blame] | 5627 | break; |
| 5628 | case DRIVER_ATHEROS: |
Priyadharshini Gowthaman | 8c5b9a4 | 2019-07-31 14:38:48 -0700 | [diff] [blame] | 5629 | novap_reset(dut, intf, 1); |
Priyadharshini Gowthaman | 818afef | 2015-11-09 13:28:15 -0800 | [diff] [blame] | 5630 | ath_config_dyn_bw_sig(dut, intf, val); |
| 5631 | break; |
| 5632 | default: |
| 5633 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5634 | "Failed to set DYN_BW_SGNL"); |
| 5635 | break; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5636 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5637 | } |
| 5638 | |
| 5639 | val = get_param(cmd, "RTS_FORCE"); |
| 5640 | if (val) { |
Priyadharshini Gowthaman | 8c5b9a4 | 2019-07-31 14:38:48 -0700 | [diff] [blame] | 5641 | novap_reset(dut, intf, 1); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5642 | if (strcasecmp(val, "Enable") == 0) { |
Veerendranath Jakkam | adcd620 | 2019-04-17 12:32:21 +0530 | [diff] [blame] | 5643 | if (sta_set_rts(dut, intf, 64) != 0) { |
Priyadharshini Gowthaman | abdb212 | 2015-11-17 11:52:19 +0200 | [diff] [blame] | 5644 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5645 | "Failed to set RTS_FORCE 64"); |
| 5646 | } |
Jouni Malinen | 3aa7286 | 2019-05-29 23:14:51 +0300 | [diff] [blame] | 5647 | res = snprintf(buf, sizeof(buf), |
| 5648 | "wifitool %s beeliner_fw_test 100 1", |
| 5649 | intf); |
| 5650 | if (res < 0 || res >= sizeof(buf) || system(buf) != 0) { |
priyadharshini gowthaman | 270870e | 2015-12-09 10:10:23 -0800 | [diff] [blame] | 5651 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5652 | "wifitool beeliner_fw_test 100 1 failed"); |
| 5653 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5654 | } else if (strcasecmp(val, "Disable") == 0) { |
Veerendranath Jakkam | adcd620 | 2019-04-17 12:32:21 +0530 | [diff] [blame] | 5655 | if (sta_set_rts(dut, intf, 2347) != 0) { |
Priyadharshini Gowthaman | abdb212 | 2015-11-17 11:52:19 +0200 | [diff] [blame] | 5656 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5657 | "Failed to set RTS_FORCE 2347"); |
| 5658 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5659 | } else { |
| 5660 | send_resp(dut, conn, SIGMA_ERROR, |
| 5661 | "ErrorCode,RTS_FORCE value not supported"); |
| 5662 | return 0; |
| 5663 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5664 | } |
| 5665 | |
| 5666 | val = get_param(cmd, "CTS_WIDTH"); |
| 5667 | if (val) { |
| 5668 | switch (get_driver_type()) { |
| 5669 | case DRIVER_WCN: |
| 5670 | if (wcn_sta_set_cts_width(dut, intf, val) < 0) { |
| 5671 | send_resp(dut, conn, SIGMA_ERROR, |
| 5672 | "ErrorCode,Failed to set CTS_WIDTH"); |
| 5673 | return 0; |
| 5674 | } |
| 5675 | break; |
| 5676 | case DRIVER_ATHEROS: |
| 5677 | ath_set_cts_width(dut, intf, val); |
| 5678 | break; |
| 5679 | default: |
| 5680 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5681 | "Setting CTS_WIDTH not supported"); |
| 5682 | break; |
| 5683 | } |
| 5684 | } |
| 5685 | |
| 5686 | val = get_param(cmd, "BW_SGNL"); |
| 5687 | if (val) { |
| 5688 | if (strcasecmp(val, "Enable") == 0) { |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 5689 | run_iwpriv(dut, intf, "cwmenable 1"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5690 | } else if (strcasecmp(val, "Disable") == 0) { |
| 5691 | /* TODO: Disable */ |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5692 | } else { |
| 5693 | send_resp(dut, conn, SIGMA_ERROR, |
| 5694 | "ErrorCode,BW_SGNL value not supported"); |
| 5695 | return 0; |
| 5696 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5697 | } |
| 5698 | |
| 5699 | val = get_param(cmd, "Band"); |
| 5700 | if (val) { |
| 5701 | if (strcmp(val, "2.4") == 0 || strcmp(val, "5") == 0) { |
| 5702 | /* STA supports all bands by default */ |
| 5703 | } else { |
| 5704 | send_resp(dut, conn, SIGMA_ERROR, |
| 5705 | "ErrorCode,Unsupported Band"); |
| 5706 | return 0; |
| 5707 | } |
| 5708 | } |
| 5709 | |
| 5710 | val = get_param(cmd, "zero_crc"); |
| 5711 | if (val) { |
| 5712 | switch (get_driver_type()) { |
| 5713 | case DRIVER_ATHEROS: |
| 5714 | ath_set_zero_crc(dut, val); |
| 5715 | break; |
| 5716 | default: |
| 5717 | break; |
| 5718 | } |
| 5719 | } |
| 5720 | |
| 5721 | return 1; |
| 5722 | } |
| 5723 | |
| 5724 | |
Alexei Avshalom Lazar | aad97b0 | 2018-12-18 16:01:23 +0200 | [diff] [blame] | 5725 | static int sta_set_force_mcs(struct sigma_dut *dut, int force, int mcs) |
| 5726 | { |
| 5727 | switch (get_driver_type()) { |
| 5728 | #ifdef __linux__ |
| 5729 | case DRIVER_WIL6210: |
| 5730 | return wil6210_set_force_mcs(dut, force, mcs); |
| 5731 | #endif /* __linux__ */ |
| 5732 | default: |
| 5733 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5734 | "Unsupported sta_set_force_mcs with the current driver"); |
| 5735 | return -1; |
| 5736 | } |
| 5737 | } |
| 5738 | |
| 5739 | |
Alexei Avshalom Lazar | b094bf0 | 2018-12-18 16:00:53 +0200 | [diff] [blame] | 5740 | static int sta_60g_force_rsn_ie(struct sigma_dut *dut, int state) |
| 5741 | { |
| 5742 | switch (get_driver_type()) { |
| 5743 | #ifdef __linux__ |
| 5744 | case DRIVER_WIL6210: |
| 5745 | return wil6210_force_rsn_ie(dut, state); |
| 5746 | #endif /* __linux__ */ |
| 5747 | default: |
| 5748 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5749 | "Unsupported sta_60g_force_rsn_ie with the current driver"); |
| 5750 | return -1; |
| 5751 | } |
| 5752 | } |
| 5753 | |
| 5754 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5755 | static int sta_set_60g_common(struct sigma_dut *dut, struct sigma_conn *conn, |
| 5756 | struct sigma_cmd *cmd) |
| 5757 | { |
| 5758 | const char *val; |
| 5759 | char buf[100]; |
| 5760 | |
| 5761 | val = get_param(cmd, "MSDUSize"); |
| 5762 | if (val) { |
| 5763 | int mtu; |
| 5764 | |
| 5765 | dut->amsdu_size = atoi(val); |
| 5766 | if (dut->amsdu_size > IEEE80211_MAX_DATA_LEN_DMG || |
| 5767 | dut->amsdu_size < IEEE80211_SNAP_LEN_DMG) { |
| 5768 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5769 | "MSDUSize %d is above max %d or below min %d", |
| 5770 | dut->amsdu_size, |
| 5771 | IEEE80211_MAX_DATA_LEN_DMG, |
| 5772 | IEEE80211_SNAP_LEN_DMG); |
| 5773 | dut->amsdu_size = 0; |
Jouni Malinen | 0e29cf2 | 2019-02-19 01:13:21 +0200 | [diff] [blame] | 5774 | return ERROR_SEND_STATUS; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5775 | } |
| 5776 | |
| 5777 | mtu = dut->amsdu_size - IEEE80211_SNAP_LEN_DMG; |
| 5778 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 5779 | "Setting amsdu_size to %d", mtu); |
| 5780 | snprintf(buf, sizeof(buf), "ifconfig %s mtu %d", |
| 5781 | get_station_ifname(), mtu); |
| 5782 | |
| 5783 | if (system(buf) != 0) { |
| 5784 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s", |
| 5785 | buf); |
Jouni Malinen | 0e29cf2 | 2019-02-19 01:13:21 +0200 | [diff] [blame] | 5786 | return ERROR_SEND_STATUS; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5787 | } |
| 5788 | } |
| 5789 | |
| 5790 | val = get_param(cmd, "BAckRcvBuf"); |
| 5791 | if (val) { |
| 5792 | dut->back_rcv_buf = atoi(val); |
| 5793 | if (dut->back_rcv_buf == 0) { |
| 5794 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5795 | "Failed to convert %s or value is 0", |
| 5796 | val); |
Jouni Malinen | 0e29cf2 | 2019-02-19 01:13:21 +0200 | [diff] [blame] | 5797 | return ERROR_SEND_STATUS; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5798 | } |
| 5799 | |
| 5800 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 5801 | "Setting BAckRcvBuf to %s", val); |
| 5802 | } |
| 5803 | |
Alexei Avshalom Lazar | aad97b0 | 2018-12-18 16:01:23 +0200 | [diff] [blame] | 5804 | val = get_param(cmd, "MCS_FixedRate"); |
| 5805 | if (val) { |
| 5806 | if (sta_set_force_mcs(dut, 1, atoi(val))) { |
| 5807 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5808 | "Failed to force MCS"); |
Jouni Malinen | 0e29cf2 | 2019-02-19 01:13:21 +0200 | [diff] [blame] | 5809 | return ERROR_SEND_STATUS; |
Alexei Avshalom Lazar | aad97b0 | 2018-12-18 16:01:23 +0200 | [diff] [blame] | 5810 | } |
| 5811 | } |
| 5812 | |
Jouni Malinen | 0e29cf2 | 2019-02-19 01:13:21 +0200 | [diff] [blame] | 5813 | return SUCCESS_SEND_STATUS; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5814 | } |
| 5815 | |
| 5816 | |
| 5817 | static int sta_pcp_start(struct sigma_dut *dut, struct sigma_conn *conn, |
| 5818 | struct sigma_cmd *cmd) |
| 5819 | { |
| 5820 | int net_id; |
| 5821 | char *ifname; |
| 5822 | const char *val; |
| 5823 | char buf[100]; |
| 5824 | |
| 5825 | dut->mode = SIGMA_MODE_STATION; |
| 5826 | ifname = get_main_ifname(); |
| 5827 | if (wpa_command(ifname, "PING") != 0) { |
| 5828 | sigma_dut_print(dut, DUT_MSG_ERROR, "Supplicant not running"); |
Jouni Malinen | 0e29cf2 | 2019-02-19 01:13:21 +0200 | [diff] [blame] | 5829 | return ERROR_SEND_STATUS; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5830 | } |
| 5831 | |
| 5832 | wpa_command(ifname, "FLUSH"); |
| 5833 | net_id = add_network_common(dut, conn, ifname, cmd); |
| 5834 | if (net_id < 0) { |
| 5835 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add network"); |
| 5836 | return net_id; |
| 5837 | } |
| 5838 | |
| 5839 | /* TODO: mode=2 for the AP; in the future, replace for mode PCP */ |
| 5840 | if (set_network(ifname, net_id, "mode", "2") < 0) { |
| 5841 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5842 | "Failed to set supplicant network mode"); |
Jouni Malinen | 0e29cf2 | 2019-02-19 01:13:21 +0200 | [diff] [blame] | 5843 | return ERROR_SEND_STATUS; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5844 | } |
| 5845 | |
Alexei Avshalom Lazar | d596b51 | 2018-12-18 16:00:59 +0200 | [diff] [blame] | 5846 | if (set_network(ifname, net_id, "pbss", "1") < 0) |
| 5847 | return -2; |
| 5848 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5849 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
Alexei Avshalom Lazar | fd9f135 | 2018-11-13 14:07:58 +0200 | [diff] [blame] | 5850 | "Supplicant set network with mode 2. network_id %d", |
| 5851 | net_id); |
| 5852 | |
| 5853 | if (set_network(ifname, net_id, "wps_disabled", "0") < 0) { |
| 5854 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 5855 | "Failed to set supplicant to WPS ENABLE"); |
Jouni Malinen | 0e29cf2 | 2019-02-19 01:13:21 +0200 | [diff] [blame] | 5856 | return ERROR_SEND_STATUS; |
Alexei Avshalom Lazar | fd9f135 | 2018-11-13 14:07:58 +0200 | [diff] [blame] | 5857 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5858 | |
| 5859 | val = get_param(cmd, "Security"); |
| 5860 | if (val && strcasecmp(val, "OPEN") == 0) { |
| 5861 | dut->ap_key_mgmt = AP_OPEN; |
| 5862 | if (set_network(ifname, net_id, "key_mgmt", "NONE") < 0) { |
| 5863 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5864 | "Failed to set supplicant to %s security", |
| 5865 | val); |
Jouni Malinen | 0e29cf2 | 2019-02-19 01:13:21 +0200 | [diff] [blame] | 5866 | return ERROR_SEND_STATUS; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5867 | } |
| 5868 | } else if (val && strcasecmp(val, "WPA2-PSK") == 0) { |
| 5869 | dut->ap_key_mgmt = AP_WPA2_PSK; |
| 5870 | if (set_network(ifname, net_id, "key_mgmt", "WPA-PSK") < 0) { |
| 5871 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5872 | "Failed to set supplicant to %s security", |
| 5873 | val); |
Jouni Malinen | 0e29cf2 | 2019-02-19 01:13:21 +0200 | [diff] [blame] | 5874 | return ERROR_SEND_STATUS; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5875 | } |
| 5876 | |
| 5877 | if (set_network(ifname, net_id, "proto", "RSN") < 0) { |
| 5878 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5879 | "Failed to set supplicant to proto RSN"); |
Jouni Malinen | 0e29cf2 | 2019-02-19 01:13:21 +0200 | [diff] [blame] | 5880 | return ERROR_SEND_STATUS; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5881 | } |
| 5882 | } else if (val) { |
| 5883 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5884 | "Requested Security %s is not supported on 60GHz", |
| 5885 | val); |
Jouni Malinen | 0e29cf2 | 2019-02-19 01:13:21 +0200 | [diff] [blame] | 5886 | return INVALID_SEND_STATUS; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5887 | } |
| 5888 | |
| 5889 | val = get_param(cmd, "Encrypt"); |
| 5890 | if (val && strcasecmp(val, "AES-GCMP") == 0) { |
| 5891 | if (set_network(ifname, net_id, "pairwise", "GCMP") < 0) { |
| 5892 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5893 | "Failed to set supplicant to pairwise GCMP"); |
Jouni Malinen | 0e29cf2 | 2019-02-19 01:13:21 +0200 | [diff] [blame] | 5894 | return ERROR_SEND_STATUS; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5895 | } |
| 5896 | if (set_network(ifname, net_id, "group", "GCMP") < 0) { |
| 5897 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5898 | "Failed to set supplicant to group GCMP"); |
Jouni Malinen | 0e29cf2 | 2019-02-19 01:13:21 +0200 | [diff] [blame] | 5899 | return ERROR_SEND_STATUS; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5900 | } |
| 5901 | } else if (val) { |
| 5902 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5903 | "Requested Encrypt %s is not supported on 60 GHz", |
| 5904 | val); |
Jouni Malinen | 0e29cf2 | 2019-02-19 01:13:21 +0200 | [diff] [blame] | 5905 | return INVALID_SEND_STATUS; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5906 | } |
| 5907 | |
| 5908 | val = get_param(cmd, "PSK"); |
| 5909 | if (val && set_network_quoted(ifname, net_id, "psk", val) < 0) { |
| 5910 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set psk %s", |
| 5911 | val); |
Jouni Malinen | 0e29cf2 | 2019-02-19 01:13:21 +0200 | [diff] [blame] | 5912 | return ERROR_SEND_STATUS; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5913 | } |
| 5914 | |
| 5915 | /* Convert 60G channel to freq */ |
| 5916 | switch (dut->ap_channel) { |
| 5917 | case 1: |
| 5918 | val = "58320"; |
| 5919 | break; |
| 5920 | case 2: |
| 5921 | val = "60480"; |
| 5922 | break; |
| 5923 | case 3: |
| 5924 | val = "62640"; |
| 5925 | break; |
| 5926 | default: |
| 5927 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5928 | "Failed to configure channel %d. Not supported", |
| 5929 | dut->ap_channel); |
Jouni Malinen | 0e29cf2 | 2019-02-19 01:13:21 +0200 | [diff] [blame] | 5930 | return ERROR_SEND_STATUS; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5931 | } |
| 5932 | |
| 5933 | if (set_network(ifname, net_id, "frequency", val) < 0) { |
| 5934 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5935 | "Failed to set supplicant network frequency"); |
Jouni Malinen | 0e29cf2 | 2019-02-19 01:13:21 +0200 | [diff] [blame] | 5936 | return ERROR_SEND_STATUS; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5937 | } |
| 5938 | |
Alexei Avshalom Lazar | 2eccf4d | 2019-01-31 10:03:59 +0200 | [diff] [blame] | 5939 | if (dut->eap_fragment) { |
| 5940 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 5941 | "Set EAP fragment size to 128 bytes."); |
| 5942 | if (set_network(ifname, net_id, "fragment_size", "128") < 0) |
| 5943 | return ERROR_SEND_STATUS; |
| 5944 | } |
| 5945 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5946 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 5947 | "Supplicant set network with frequency"); |
| 5948 | |
| 5949 | snprintf(buf, sizeof(buf), "SELECT_NETWORK %d", net_id); |
| 5950 | if (wpa_command(ifname, buf) < 0) { |
| 5951 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 5952 | "Failed to select network id %d on %s", |
| 5953 | net_id, ifname); |
Jouni Malinen | 0e29cf2 | 2019-02-19 01:13:21 +0200 | [diff] [blame] | 5954 | return ERROR_SEND_STATUS; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5955 | } |
| 5956 | |
| 5957 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Selected network"); |
| 5958 | |
Jouni Malinen | 0e29cf2 | 2019-02-19 01:13:21 +0200 | [diff] [blame] | 5959 | return SUCCESS_SEND_STATUS; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5960 | } |
| 5961 | |
| 5962 | |
Lior David | 67543f5 | 2017-01-03 19:04:22 +0200 | [diff] [blame] | 5963 | static int wil6210_set_abft_len(struct sigma_dut *dut, int abft_len) |
| 5964 | { |
| 5965 | char buf[128], fname[128]; |
| 5966 | FILE *f; |
Jouni Malinen | 3aa7286 | 2019-05-29 23:14:51 +0300 | [diff] [blame] | 5967 | int res; |
Lior David | 67543f5 | 2017-01-03 19:04:22 +0200 | [diff] [blame] | 5968 | |
| 5969 | if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) { |
| 5970 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5971 | "failed to get wil6210 debugfs dir"); |
| 5972 | return -1; |
| 5973 | } |
| 5974 | |
Jouni Malinen | 3aa7286 | 2019-05-29 23:14:51 +0300 | [diff] [blame] | 5975 | res = snprintf(fname, sizeof(fname), "%s/abft_len", buf); |
| 5976 | if (res < 0 || res >= sizeof(fname)) |
| 5977 | return -1; |
Lior David | 67543f5 | 2017-01-03 19:04:22 +0200 | [diff] [blame] | 5978 | f = fopen(fname, "w"); |
| 5979 | if (!f) { |
| 5980 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5981 | "failed to open: %s", fname); |
| 5982 | return -1; |
| 5983 | } |
| 5984 | |
| 5985 | fprintf(f, "%d\n", abft_len); |
| 5986 | fclose(f); |
| 5987 | |
| 5988 | return 0; |
| 5989 | } |
| 5990 | |
| 5991 | |
Alexei Avshalom Lazar | 49498b8 | 2019-01-31 15:16:32 +0200 | [diff] [blame] | 5992 | int sta_set_60g_abft_len(struct sigma_dut *dut, struct sigma_conn *conn, |
| 5993 | int abft_len) |
Lior David | 67543f5 | 2017-01-03 19:04:22 +0200 | [diff] [blame] | 5994 | { |
| 5995 | switch (get_driver_type()) { |
| 5996 | case DRIVER_WIL6210: |
| 5997 | return wil6210_set_abft_len(dut, abft_len); |
| 5998 | default: |
| 5999 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6000 | "set abft_len not supported"); |
| 6001 | return -1; |
| 6002 | } |
| 6003 | } |
| 6004 | |
| 6005 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6006 | static int sta_set_60g_pcp(struct sigma_dut *dut, struct sigma_conn *conn, |
| 6007 | struct sigma_cmd *cmd) |
| 6008 | { |
| 6009 | const char *val; |
Lior David | 67543f5 | 2017-01-03 19:04:22 +0200 | [diff] [blame] | 6010 | unsigned int abft_len = 1; /* default is one slot */ |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6011 | |
| 6012 | if (dut->dev_role != DEVROLE_PCP) { |
| 6013 | send_resp(dut, conn, SIGMA_INVALID, |
| 6014 | "ErrorCode,Invalid DevRole"); |
| 6015 | return 0; |
| 6016 | } |
| 6017 | |
| 6018 | val = get_param(cmd, "SSID"); |
| 6019 | if (val) { |
| 6020 | if (strlen(val) > sizeof(dut->ap_ssid) - 1) { |
| 6021 | send_resp(dut, conn, SIGMA_INVALID, |
| 6022 | "ErrorCode,Invalid SSID"); |
| 6023 | return -1; |
| 6024 | } |
| 6025 | |
Peng Xu | b8fc5cc | 2017-05-10 17:27:28 -0700 | [diff] [blame] | 6026 | strlcpy(dut->ap_ssid, val, sizeof(dut->ap_ssid)); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6027 | } |
| 6028 | |
| 6029 | val = get_param(cmd, "CHANNEL"); |
| 6030 | if (val) { |
| 6031 | const char *pos; |
| 6032 | |
| 6033 | dut->ap_channel = atoi(val); |
| 6034 | pos = strchr(val, ';'); |
| 6035 | if (pos) { |
| 6036 | pos++; |
| 6037 | dut->ap_channel_1 = atoi(pos); |
| 6038 | } |
| 6039 | } |
| 6040 | |
| 6041 | switch (dut->ap_channel) { |
| 6042 | case 1: |
| 6043 | case 2: |
| 6044 | case 3: |
| 6045 | break; |
| 6046 | default: |
| 6047 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6048 | "Channel %d is not supported", dut->ap_channel); |
| 6049 | send_resp(dut, conn, SIGMA_ERROR, |
| 6050 | "Requested channel is not supported"); |
| 6051 | return -1; |
| 6052 | } |
| 6053 | |
| 6054 | val = get_param(cmd, "BCNINT"); |
| 6055 | if (val) |
| 6056 | dut->ap_bcnint = atoi(val); |
| 6057 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6058 | val = get_param(cmd, "AllocType"); |
| 6059 | if (val) { |
| 6060 | send_resp(dut, conn, SIGMA_ERROR, |
| 6061 | "ErrorCode,AllocType is not supported yet"); |
| 6062 | return -1; |
| 6063 | } |
| 6064 | |
| 6065 | val = get_param(cmd, "PercentBI"); |
| 6066 | if (val) { |
| 6067 | send_resp(dut, conn, SIGMA_ERROR, |
| 6068 | "ErrorCode,PercentBI is not supported yet"); |
| 6069 | return -1; |
| 6070 | } |
| 6071 | |
| 6072 | val = get_param(cmd, "CBAPOnly"); |
| 6073 | if (val) { |
| 6074 | send_resp(dut, conn, SIGMA_ERROR, |
| 6075 | "ErrorCode,CBAPOnly is not supported yet"); |
| 6076 | return -1; |
| 6077 | } |
| 6078 | |
| 6079 | val = get_param(cmd, "AMPDU"); |
| 6080 | if (val) { |
| 6081 | if (strcasecmp(val, "Enable") == 0) |
| 6082 | dut->ap_ampdu = 1; |
| 6083 | else if (strcasecmp(val, "Disable") == 0) |
| 6084 | dut->ap_ampdu = 2; |
| 6085 | else { |
| 6086 | send_resp(dut, conn, SIGMA_ERROR, |
| 6087 | "ErrorCode,AMPDU value is not Enable nor Disabled"); |
| 6088 | return -1; |
| 6089 | } |
| 6090 | } |
| 6091 | |
| 6092 | val = get_param(cmd, "AMSDU"); |
| 6093 | if (val) { |
| 6094 | if (strcasecmp(val, "Enable") == 0) |
| 6095 | dut->ap_amsdu = 1; |
| 6096 | else if (strcasecmp(val, "Disable") == 0) |
| 6097 | dut->ap_amsdu = 2; |
| 6098 | } |
| 6099 | |
| 6100 | val = get_param(cmd, "NumMSDU"); |
| 6101 | if (val) { |
| 6102 | send_resp(dut, conn, SIGMA_ERROR, |
| 6103 | "ErrorCode, NumMSDU is not supported yet"); |
| 6104 | return -1; |
| 6105 | } |
| 6106 | |
| 6107 | val = get_param(cmd, "ABFTLRang"); |
| 6108 | if (val) { |
| 6109 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
Lior David | 67543f5 | 2017-01-03 19:04:22 +0200 | [diff] [blame] | 6110 | "ABFTLRang parameter %s", val); |
| 6111 | if (strcmp(val, "Gt1") == 0) |
| 6112 | abft_len = 2; /* 2 slots in this case */ |
| 6113 | } |
| 6114 | |
| 6115 | if (sta_set_60g_abft_len(dut, conn, abft_len)) { |
| 6116 | send_resp(dut, conn, SIGMA_ERROR, |
| 6117 | "ErrorCode, Can't set ABFT length"); |
| 6118 | return -1; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6119 | } |
| 6120 | |
| 6121 | if (sta_pcp_start(dut, conn, cmd) < 0) { |
| 6122 | send_resp(dut, conn, SIGMA_ERROR, |
| 6123 | "ErrorCode, Can't start PCP role"); |
| 6124 | return -1; |
| 6125 | } |
| 6126 | |
| 6127 | return sta_set_60g_common(dut, conn, cmd); |
| 6128 | } |
| 6129 | |
| 6130 | |
| 6131 | static int sta_set_60g_sta(struct sigma_dut *dut, struct sigma_conn *conn, |
| 6132 | struct sigma_cmd *cmd) |
| 6133 | { |
| 6134 | const char *val = get_param(cmd, "DiscoveryMode"); |
| 6135 | |
| 6136 | if (dut->dev_role != DEVROLE_STA) { |
| 6137 | send_resp(dut, conn, SIGMA_INVALID, |
| 6138 | "ErrorCode,Invalid DevRole"); |
| 6139 | return 0; |
| 6140 | } |
| 6141 | |
| 6142 | if (val) { |
| 6143 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Discovery: %s", val); |
| 6144 | /* Ignore Discovery mode till Driver expose API. */ |
| 6145 | #if 0 |
| 6146 | if (strcasecmp(val, "1") == 0) { |
| 6147 | send_resp(dut, conn, SIGMA_INVALID, |
| 6148 | "ErrorCode,DiscoveryMode 1 not supported"); |
| 6149 | return 0; |
| 6150 | } |
| 6151 | |
| 6152 | if (strcasecmp(val, "0") == 0) { |
| 6153 | /* OK */ |
| 6154 | } else { |
| 6155 | send_resp(dut, conn, SIGMA_INVALID, |
| 6156 | "ErrorCode,DiscoveryMode not supported"); |
| 6157 | return 0; |
| 6158 | } |
| 6159 | #endif |
| 6160 | } |
| 6161 | |
| 6162 | if (start_sta_mode(dut) != 0) |
Jouni Malinen | 0e29cf2 | 2019-02-19 01:13:21 +0200 | [diff] [blame] | 6163 | return ERROR_SEND_STATUS; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6164 | return sta_set_60g_common(dut, conn, cmd); |
| 6165 | } |
| 6166 | |
| 6167 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 6168 | static enum sigma_cmd_result cmd_sta_disconnect(struct sigma_dut *dut, |
| 6169 | struct sigma_conn *conn, |
| 6170 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6171 | { |
| 6172 | const char *intf = get_param(cmd, "Interface"); |
Jouni Malinen | ed77e67 | 2018-01-10 16:45:13 +0200 | [diff] [blame] | 6173 | const char *val = get_param(cmd, "maintain_profile"); |
vamsi krishna | d605c42 | 2017-09-20 14:56:31 +0530 | [diff] [blame] | 6174 | |
Jouni Malinen | ed77e67 | 2018-01-10 16:45:13 +0200 | [diff] [blame] | 6175 | if (dut->program == PROGRAM_OCE || |
Amarnath Hullur Subramanyam | ebeda9e | 2018-01-31 03:21:48 -0800 | [diff] [blame] | 6176 | dut->program == PROGRAM_HE || |
Jouni Malinen | ed77e67 | 2018-01-10 16:45:13 +0200 | [diff] [blame] | 6177 | (val && atoi(val) == 1)) { |
vamsi krishna | d605c42 | 2017-09-20 14:56:31 +0530 | [diff] [blame] | 6178 | wpa_command(intf, "DISCONNECT"); |
| 6179 | return 1; |
| 6180 | } |
| 6181 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6182 | disconnect_station(dut); |
| 6183 | /* Try to ignore old scan results to avoid HS 2.0R2 test case failures |
| 6184 | * due to cached results. */ |
| 6185 | wpa_command(intf, "SET ignore_old_scan_res 1"); |
| 6186 | wpa_command(intf, "BSS_FLUSH"); |
| 6187 | return 1; |
| 6188 | } |
| 6189 | |
| 6190 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 6191 | static enum sigma_cmd_result cmd_sta_reassoc(struct sigma_dut *dut, |
| 6192 | struct sigma_conn *conn, |
| 6193 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6194 | { |
| 6195 | const char *intf = get_param(cmd, "Interface"); |
| 6196 | const char *bssid = get_param(cmd, "bssid"); |
| 6197 | const char *val = get_param(cmd, "CHANNEL"); |
| 6198 | struct wpa_ctrl *ctrl; |
Srinivas Dasari | 0ebedb1 | 2018-02-14 17:03:51 +0530 | [diff] [blame] | 6199 | char buf[1000]; |
Sunil Dutt | d30ce09 | 2018-01-11 23:56:29 +0530 | [diff] [blame] | 6200 | char result[32]; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6201 | int res; |
| 6202 | int chan = 0; |
Jouni Malinen | 6a7c9b4 | 2019-08-20 00:15:59 +0300 | [diff] [blame] | 6203 | enum sigma_cmd_result status = STATUS_SENT; |
Sunil Dutt | d30ce09 | 2018-01-11 23:56:29 +0530 | [diff] [blame] | 6204 | int fastreassoc = 1; |
Jouni Malinen | 6a7c9b4 | 2019-08-20 00:15:59 +0300 | [diff] [blame] | 6205 | int ft_ds = 0; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6206 | |
| 6207 | if (bssid == NULL) { |
| 6208 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing bssid " |
| 6209 | "argument"); |
Jouni Malinen | 6a7c9b4 | 2019-08-20 00:15:59 +0300 | [diff] [blame] | 6210 | return STATUS_SENT_ERROR; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6211 | } |
| 6212 | |
| 6213 | if (val) |
| 6214 | chan = atoi(val); |
| 6215 | |
| 6216 | if (wifi_chip_type != DRIVER_WCN && wifi_chip_type != DRIVER_AR6003) { |
| 6217 | /* The current network may be from sta_associate or |
| 6218 | * sta_hs2_associate |
| 6219 | */ |
| 6220 | if (set_network(intf, dut->infra_network_id, "bssid", bssid) < |
| 6221 | 0 || |
| 6222 | set_network(intf, 0, "bssid", bssid) < 0) |
Jouni Malinen | 6a7c9b4 | 2019-08-20 00:15:59 +0300 | [diff] [blame] | 6223 | return ERROR_SEND_STATUS; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6224 | } |
| 6225 | |
| 6226 | ctrl = open_wpa_mon(intf); |
| 6227 | if (ctrl == NULL) { |
| 6228 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open " |
| 6229 | "wpa_supplicant monitor connection"); |
Jouni Malinen | 6a7c9b4 | 2019-08-20 00:15:59 +0300 | [diff] [blame] | 6230 | return ERROR_SEND_STATUS; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6231 | } |
| 6232 | |
Sunil Dutt | d30ce09 | 2018-01-11 23:56:29 +0530 | [diff] [blame] | 6233 | if (get_wpa_status(get_station_ifname(), "wpa_state", result, |
| 6234 | sizeof(result)) < 0 || |
| 6235 | strncmp(result, "COMPLETED", 9) != 0) { |
| 6236 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 6237 | "sta_reassoc: Not connected"); |
| 6238 | fastreassoc = 0; |
Jouni Malinen | 6a7c9b4 | 2019-08-20 00:15:59 +0300 | [diff] [blame] | 6239 | } else if (dut->sta_ft_ds) { |
| 6240 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 6241 | "sta_reassoc: Use FT-over-DS"); |
| 6242 | ft_ds = 1; |
Sunil Dutt | d30ce09 | 2018-01-11 23:56:29 +0530 | [diff] [blame] | 6243 | } |
| 6244 | |
Srinivas Dasari | 0ebedb1 | 2018-02-14 17:03:51 +0530 | [diff] [blame] | 6245 | if (dut->rsne_override) { |
| 6246 | #ifdef NL80211_SUPPORT |
| 6247 | if (get_driver_type() == DRIVER_WCN && dut->config_rsnie == 0) { |
| 6248 | sta_config_rsnie(dut, 1); |
| 6249 | dut->config_rsnie = 1; |
| 6250 | } |
| 6251 | #endif /* NL80211_SUPPORT */ |
| 6252 | snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s", |
| 6253 | dut->rsne_override); |
| 6254 | if (wpa_command(intf, buf) < 0) { |
| 6255 | send_resp(dut, conn, SIGMA_ERROR, |
| 6256 | "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override"); |
| 6257 | return 0; |
| 6258 | } |
| 6259 | } |
| 6260 | |
Jouni Malinen | 6a7c9b4 | 2019-08-20 00:15:59 +0300 | [diff] [blame] | 6261 | if (ft_ds) { |
| 6262 | if (chan) { |
| 6263 | unsigned int freq; |
| 6264 | |
| 6265 | freq = channel_to_freq(dut, chan); |
| 6266 | if (!freq) { |
| 6267 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6268 | "Invalid channel number provided: %d", |
| 6269 | chan); |
| 6270 | send_resp(dut, conn, SIGMA_INVALID, |
| 6271 | "ErrorCode,Invalid channel number"); |
| 6272 | goto close_mon_conn; |
| 6273 | } |
| 6274 | res = snprintf(buf, sizeof(buf), |
| 6275 | "SCAN TYPE=ONLY freq=%d", freq); |
| 6276 | } else { |
| 6277 | res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY"); |
| 6278 | } |
| 6279 | if (res < 0 || res >= (int) sizeof(buf)) { |
| 6280 | send_resp(dut, conn, SIGMA_ERROR, |
| 6281 | "ErrorCode,snprintf failed"); |
| 6282 | goto close_mon_conn; |
| 6283 | } |
| 6284 | if (wpa_command(intf, buf) < 0) { |
| 6285 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 6286 | "Failed to start scan"); |
| 6287 | send_resp(dut, conn, SIGMA_ERROR, |
| 6288 | "ErrorCode,scan failed"); |
| 6289 | goto close_mon_conn; |
| 6290 | } |
| 6291 | |
| 6292 | res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS", |
| 6293 | buf, sizeof(buf)); |
| 6294 | if (res < 0) { |
| 6295 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 6296 | "Scan did not complete"); |
| 6297 | send_resp(dut, conn, SIGMA_ERROR, |
| 6298 | "ErrorCode,scan did not complete"); |
| 6299 | goto close_mon_conn; |
| 6300 | } |
| 6301 | |
| 6302 | res = snprintf(buf, sizeof(buf), "FT_DS %s", bssid); |
| 6303 | if (res > 0 && res < (int) sizeof(buf)) |
| 6304 | res = wpa_command(intf, buf); |
| 6305 | |
| 6306 | if (res < 0 || res >= (int) sizeof(buf)) { |
| 6307 | send_resp(dut, conn, SIGMA_ERROR, |
| 6308 | "errorCode,FT_DS command failed"); |
| 6309 | status = STATUS_SENT_ERROR; |
| 6310 | goto close_mon_conn; |
| 6311 | } |
| 6312 | } else if (wifi_chip_type == DRIVER_WCN && fastreassoc) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6313 | #ifdef ANDROID |
Ashwini Patil | 4c8158f | 2017-05-25 12:49:21 +0530 | [diff] [blame] | 6314 | if (chan) { |
| 6315 | unsigned int freq; |
| 6316 | |
Alexei Avshalom Lazar | 093569f | 2018-11-13 14:08:17 +0200 | [diff] [blame] | 6317 | freq = channel_to_freq(dut, chan); |
Ashwini Patil | 4c8158f | 2017-05-25 12:49:21 +0530 | [diff] [blame] | 6318 | if (!freq) { |
| 6319 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6320 | "Invalid channel number provided: %d", |
| 6321 | chan); |
| 6322 | send_resp(dut, conn, SIGMA_INVALID, |
| 6323 | "ErrorCode,Invalid channel number"); |
| 6324 | goto close_mon_conn; |
| 6325 | } |
| 6326 | res = snprintf(buf, sizeof(buf), |
| 6327 | "SCAN TYPE=ONLY freq=%d", freq); |
| 6328 | } else { |
| 6329 | res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY"); |
| 6330 | } |
| 6331 | if (res < 0 || res >= (int) sizeof(buf)) { |
| 6332 | send_resp(dut, conn, SIGMA_ERROR, |
| 6333 | "ErrorCode,snprintf failed"); |
| 6334 | goto close_mon_conn; |
| 6335 | } |
| 6336 | if (wpa_command(intf, buf) < 0) { |
| 6337 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 6338 | "Failed to start scan"); |
| 6339 | send_resp(dut, conn, SIGMA_ERROR, |
| 6340 | "ErrorCode,scan failed"); |
| 6341 | goto close_mon_conn; |
| 6342 | } |
| 6343 | |
| 6344 | res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS", |
| 6345 | buf, sizeof(buf)); |
| 6346 | if (res < 0) { |
| 6347 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 6348 | "Scan did not complete"); |
| 6349 | send_resp(dut, conn, SIGMA_ERROR, |
| 6350 | "ErrorCode,scan did not complete"); |
| 6351 | goto close_mon_conn; |
| 6352 | } |
| 6353 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6354 | if (set_network(intf, dut->infra_network_id, "bssid", "any") |
| 6355 | < 0) { |
| 6356 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set " |
| 6357 | "bssid to any during FASTREASSOC"); |
Jouni Malinen | 6a7c9b4 | 2019-08-20 00:15:59 +0300 | [diff] [blame] | 6358 | status = ERROR_SEND_STATUS; |
Ashwini Patil | 467efef | 2017-05-25 12:18:27 +0530 | [diff] [blame] | 6359 | goto close_mon_conn; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6360 | } |
| 6361 | res = snprintf(buf, sizeof(buf), "DRIVER FASTREASSOC %s %d", |
| 6362 | bssid, chan); |
| 6363 | if (res > 0 && res < (int) sizeof(buf)) |
| 6364 | res = wpa_command(intf, buf); |
| 6365 | |
| 6366 | if (res < 0 || res >= (int) sizeof(buf)) { |
| 6367 | send_resp(dut, conn, SIGMA_ERROR, |
| 6368 | "errorCode,Failed to run DRIVER FASTREASSOC"); |
Ashwini Patil | 467efef | 2017-05-25 12:18:27 +0530 | [diff] [blame] | 6369 | goto close_mon_conn; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6370 | } |
| 6371 | #else /* ANDROID */ |
| 6372 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 6373 | "Reassoc using iwpriv - skip chan=%d info", |
| 6374 | chan); |
| 6375 | snprintf(buf, sizeof(buf), "iwpriv %s reassoc", intf); |
| 6376 | if (system(buf) != 0) { |
| 6377 | sigma_dut_print(dut, DUT_MSG_ERROR, "%s failed", buf); |
Jouni Malinen | 6a7c9b4 | 2019-08-20 00:15:59 +0300 | [diff] [blame] | 6378 | status = ERROR_SEND_STATUS; |
Ashwini Patil | 467efef | 2017-05-25 12:18:27 +0530 | [diff] [blame] | 6379 | goto close_mon_conn; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6380 | } |
| 6381 | #endif /* ANDROID */ |
| 6382 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 6383 | "sta_reassoc: Run %s successful", buf); |
| 6384 | } else if (wpa_command(intf, "REASSOCIATE")) { |
| 6385 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to " |
| 6386 | "request reassociation"); |
Ashwini Patil | 467efef | 2017-05-25 12:18:27 +0530 | [diff] [blame] | 6387 | goto close_mon_conn; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6388 | } |
| 6389 | |
| 6390 | res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED", |
| 6391 | buf, sizeof(buf)); |
Ashwini Patil | 467efef | 2017-05-25 12:18:27 +0530 | [diff] [blame] | 6392 | if (res < 0) { |
Jouni Malinen | 6a7c9b4 | 2019-08-20 00:15:59 +0300 | [diff] [blame] | 6393 | send_resp(dut, conn, SIGMA_ERROR, |
| 6394 | "errorCode,Connection did not complete"); |
| 6395 | status = STATUS_SENT_ERROR; |
Ashwini Patil | 467efef | 2017-05-25 12:18:27 +0530 | [diff] [blame] | 6396 | goto close_mon_conn; |
| 6397 | } |
Jouni Malinen | 6a7c9b4 | 2019-08-20 00:15:59 +0300 | [diff] [blame] | 6398 | status = SUCCESS_SEND_STATUS; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6399 | |
Ashwini Patil | 467efef | 2017-05-25 12:18:27 +0530 | [diff] [blame] | 6400 | close_mon_conn: |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6401 | wpa_ctrl_detach(ctrl); |
| 6402 | wpa_ctrl_close(ctrl); |
Ashwini Patil | 467efef | 2017-05-25 12:18:27 +0530 | [diff] [blame] | 6403 | return status; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6404 | } |
| 6405 | |
| 6406 | |
| 6407 | static void hs2_clear_credentials(const char *intf) |
| 6408 | { |
| 6409 | wpa_command(intf, "REMOVE_CRED all"); |
| 6410 | } |
| 6411 | |
| 6412 | |
Lior David | cc88b56 | 2017-01-03 18:52:09 +0200 | [diff] [blame] | 6413 | #ifdef __linux__ |
| 6414 | static int wil6210_get_aid(struct sigma_dut *dut, const char *bssid, |
| 6415 | unsigned int *aid) |
| 6416 | { |
Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 6417 | const char *pattern = "AID[ \t]+([0-9]+)"; |
Lior David | cc88b56 | 2017-01-03 18:52:09 +0200 | [diff] [blame] | 6418 | |
Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 6419 | return wil6210_get_sta_info_field(dut, bssid, pattern, aid); |
Lior David | cc88b56 | 2017-01-03 18:52:09 +0200 | [diff] [blame] | 6420 | } |
| 6421 | #endif /* __linux__ */ |
| 6422 | |
| 6423 | |
| 6424 | static int sta_get_aid_60g(struct sigma_dut *dut, const char *bssid, |
| 6425 | unsigned int *aid) |
| 6426 | { |
| 6427 | switch (get_driver_type()) { |
| 6428 | #ifdef __linux__ |
| 6429 | case DRIVER_WIL6210: |
| 6430 | return wil6210_get_aid(dut, bssid, aid); |
| 6431 | #endif /* __linux__ */ |
| 6432 | default: |
| 6433 | sigma_dut_print(dut, DUT_MSG_ERROR, "get AID not supported"); |
| 6434 | return -1; |
| 6435 | } |
| 6436 | } |
| 6437 | |
| 6438 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6439 | static int sta_get_parameter_60g(struct sigma_dut *dut, struct sigma_conn *conn, |
| 6440 | struct sigma_cmd *cmd) |
| 6441 | { |
| 6442 | char buf[MAX_CMD_LEN]; |
| 6443 | char bss_list[MAX_CMD_LEN]; |
| 6444 | const char *parameter = get_param(cmd, "Parameter"); |
| 6445 | |
| 6446 | if (parameter == NULL) |
| 6447 | return -1; |
| 6448 | |
Lior David | cc88b56 | 2017-01-03 18:52:09 +0200 | [diff] [blame] | 6449 | if (strcasecmp(parameter, "AID") == 0) { |
| 6450 | unsigned int aid = 0; |
| 6451 | char bssid[20]; |
| 6452 | |
| 6453 | if (get_wpa_status(get_station_ifname(), "bssid", |
| 6454 | bssid, sizeof(bssid)) < 0) { |
| 6455 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6456 | "could not get bssid"); |
| 6457 | return -2; |
| 6458 | } |
| 6459 | |
| 6460 | if (sta_get_aid_60g(dut, bssid, &aid)) |
| 6461 | return -2; |
| 6462 | |
| 6463 | snprintf(buf, sizeof(buf), "aid,%d", aid); |
| 6464 | sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf); |
| 6465 | send_resp(dut, conn, SIGMA_COMPLETE, buf); |
| 6466 | return 0; |
| 6467 | } |
| 6468 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6469 | if (strcasecmp(parameter, "DiscoveredDevList") == 0) { |
| 6470 | char *bss_line; |
| 6471 | char *bss_id = NULL; |
| 6472 | const char *ifname = get_param(cmd, "Interface"); |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 6473 | char *saveptr; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6474 | |
| 6475 | if (ifname == NULL) { |
| 6476 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 6477 | "For get DiscoveredDevList need Interface name."); |
| 6478 | return -1; |
| 6479 | } |
| 6480 | |
| 6481 | /* |
| 6482 | * Use "BSS RANGE=ALL MASK=0x2" which provides a list |
| 6483 | * of BSSIDs in "bssid=<BSSID>\n" |
| 6484 | */ |
| 6485 | if (wpa_command_resp(ifname, "BSS RANGE=ALL MASK=0x2", |
| 6486 | bss_list, |
| 6487 | sizeof(bss_list)) < 0) { |
| 6488 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6489 | "Failed to get bss list"); |
| 6490 | return -1; |
| 6491 | } |
| 6492 | |
| 6493 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 6494 | "bss list for ifname:%s is:%s", |
| 6495 | ifname, bss_list); |
| 6496 | |
| 6497 | snprintf(buf, sizeof(buf), "DeviceList"); |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 6498 | bss_line = strtok_r(bss_list, "\n", &saveptr); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6499 | while (bss_line) { |
| 6500 | if (sscanf(bss_line, "bssid=%ms", &bss_id) > 0 && |
| 6501 | bss_id) { |
| 6502 | int len; |
| 6503 | |
| 6504 | len = snprintf(buf + strlen(buf), |
| 6505 | sizeof(buf) - strlen(buf), |
| 6506 | ",%s", bss_id); |
| 6507 | free(bss_id); |
| 6508 | bss_id = NULL; |
| 6509 | if (len < 0) { |
| 6510 | sigma_dut_print(dut, |
| 6511 | DUT_MSG_ERROR, |
| 6512 | "Failed to read BSSID"); |
| 6513 | send_resp(dut, conn, SIGMA_ERROR, |
| 6514 | "ErrorCode,Failed to read BSS ID"); |
| 6515 | return 0; |
| 6516 | } |
| 6517 | |
| 6518 | if ((size_t) len >= sizeof(buf) - strlen(buf)) { |
| 6519 | sigma_dut_print(dut, |
| 6520 | DUT_MSG_ERROR, |
| 6521 | "Response buf too small for list"); |
| 6522 | send_resp(dut, conn, |
| 6523 | SIGMA_ERROR, |
| 6524 | "ErrorCode,Response buf too small for list"); |
| 6525 | return 0; |
| 6526 | } |
| 6527 | } |
| 6528 | |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 6529 | bss_line = strtok_r(NULL, "\n", &saveptr); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6530 | } |
| 6531 | |
| 6532 | sigma_dut_print(dut, DUT_MSG_INFO, "DiscoveredDevList is %s", |
| 6533 | buf); |
| 6534 | send_resp(dut, conn, SIGMA_COMPLETE, buf); |
| 6535 | return 0; |
| 6536 | } |
| 6537 | |
| 6538 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter"); |
| 6539 | return 0; |
| 6540 | } |
| 6541 | |
| 6542 | |
Kiran Kumar Lokere | c86d802 | 2018-10-11 13:57:12 -0700 | [diff] [blame] | 6543 | static int sta_get_parameter_he(struct sigma_dut *dut, struct sigma_conn *conn, |
| 6544 | struct sigma_cmd *cmd) |
| 6545 | { |
| 6546 | char buf[MAX_CMD_LEN]; |
| 6547 | const char *parameter = get_param(cmd, "Parameter"); |
| 6548 | |
| 6549 | if (!parameter) |
| 6550 | return -1; |
| 6551 | |
| 6552 | if (strcasecmp(parameter, "RSSI") == 0) { |
| 6553 | char rssi[10]; |
| 6554 | |
| 6555 | if (get_wpa_signal_poll(dut, get_station_ifname(), "RSSI", |
| 6556 | rssi, sizeof(rssi)) < 0) { |
| 6557 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6558 | "Could not get RSSI"); |
| 6559 | return -2; |
| 6560 | } |
| 6561 | |
| 6562 | snprintf(buf, sizeof(buf), "rssi,%s", rssi); |
| 6563 | sigma_dut_print(dut, DUT_MSG_INFO, "RSSI %s", buf); |
| 6564 | send_resp(dut, conn, SIGMA_COMPLETE, buf); |
| 6565 | return 0; |
| 6566 | } |
| 6567 | |
| 6568 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter"); |
| 6569 | return 0; |
| 6570 | } |
| 6571 | |
| 6572 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 6573 | static enum sigma_cmd_result cmd_sta_get_parameter(struct sigma_dut *dut, |
| 6574 | struct sigma_conn *conn, |
| 6575 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6576 | { |
| 6577 | const char *program = get_param(cmd, "Program"); |
| 6578 | |
| 6579 | if (program == NULL) |
| 6580 | return -1; |
| 6581 | |
| 6582 | if (strcasecmp(program, "P2PNFC") == 0) |
| 6583 | return p2p_cmd_sta_get_parameter(dut, conn, cmd); |
| 6584 | |
| 6585 | if (strcasecmp(program, "60ghz") == 0) |
| 6586 | return sta_get_parameter_60g(dut, conn, cmd); |
| 6587 | |
Kiran Kumar Lokere | c86d802 | 2018-10-11 13:57:12 -0700 | [diff] [blame] | 6588 | if (strcasecmp(program, "he") == 0) |
| 6589 | return sta_get_parameter_he(dut, conn, cmd); |
| 6590 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6591 | #ifdef ANDROID_NAN |
| 6592 | if (strcasecmp(program, "NAN") == 0) |
Amarnath Hullur Subramanyam | 1854ec6 | 2016-08-11 19:29:35 -0700 | [diff] [blame] | 6593 | return nan_cmd_sta_get_parameter(dut, conn, cmd); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6594 | #endif /* ANDROID_NAN */ |
| 6595 | |
Amarnath Hullur Subramanyam | 9c381f5 | 2017-03-17 00:04:41 -0700 | [diff] [blame] | 6596 | #ifdef MIRACAST |
| 6597 | if (strcasecmp(program, "WFD") == 0 || |
| 6598 | strcasecmp(program, "DisplayR2") == 0) |
| 6599 | return miracast_cmd_sta_get_parameter(dut, conn, cmd); |
| 6600 | #endif /* MIRACAST */ |
| 6601 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6602 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter"); |
| 6603 | return 0; |
| 6604 | } |
| 6605 | |
| 6606 | |
| 6607 | static void sta_reset_default_ath(struct sigma_dut *dut, const char *intf, |
| 6608 | const char *type) |
| 6609 | { |
| 6610 | char buf[100]; |
| 6611 | |
| 6612 | if (dut->program == PROGRAM_VHT) { |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 6613 | run_iwpriv(dut, intf, "chwidth 2"); |
| 6614 | run_iwpriv(dut, intf, "mode 11ACVHT80"); |
| 6615 | run_iwpriv(dut, intf, "vhtmcs -1"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6616 | } |
| 6617 | |
| 6618 | if (dut->program == PROGRAM_HT) { |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 6619 | run_iwpriv(dut, intf, "chwidth 0"); |
| 6620 | run_iwpriv(dut, intf, "mode 11naht40"); |
| 6621 | run_iwpriv(dut, intf, "set11NRates 0"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6622 | } |
| 6623 | |
| 6624 | if (dut->program == PROGRAM_VHT || dut->program == PROGRAM_HT) { |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 6625 | run_iwpriv(dut, intf, "powersave 0"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6626 | |
| 6627 | /* Reset CTS width */ |
| 6628 | snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 54 0", |
| 6629 | intf); |
| 6630 | if (system(buf) != 0) { |
| 6631 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6632 | "wifitool %s beeliner_fw_test 54 0 failed", |
| 6633 | intf); |
| 6634 | } |
| 6635 | |
| 6636 | /* Enable Dynamic Bandwidth signalling by default */ |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 6637 | run_iwpriv(dut, intf, "cwmenable 1"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6638 | |
| 6639 | snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", intf); |
| 6640 | if (system(buf) != 0) { |
| 6641 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6642 | "iwpriv rts failed"); |
| 6643 | } |
| 6644 | } |
| 6645 | |
| 6646 | if (type && strcasecmp(type, "Testbed") == 0) { |
| 6647 | dut->testbed_flag_txsp = 1; |
| 6648 | dut->testbed_flag_rxsp = 1; |
| 6649 | /* STA has to set spatial stream to 2 per Appendix H */ |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 6650 | run_iwpriv(dut, intf, "vht_mcsmap 0xfff0"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6651 | |
| 6652 | /* Disable LDPC per Appendix H */ |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 6653 | run_iwpriv(dut, intf, "ldpc 0"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6654 | |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 6655 | run_iwpriv(dut, intf, "amsdu 1"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6656 | |
| 6657 | /* TODO: Disable STBC 2x1 transmit and receive */ |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 6658 | run_iwpriv(dut, intf, "tx_stbc 0"); |
| 6659 | run_iwpriv(dut, intf, "rx_stbc 0"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6660 | |
| 6661 | /* STA has to disable Short GI per Appendix H */ |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 6662 | run_iwpriv(dut, intf, "shortgi 0"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6663 | } |
| 6664 | |
| 6665 | if (type && strcasecmp(type, "DUT") == 0) { |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 6666 | run_iwpriv(dut, intf, "nss 3"); |
Arif Hussain | ac6c511 | 2018-05-25 17:34:00 -0700 | [diff] [blame] | 6667 | dut->sta_nss = 3; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6668 | |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 6669 | run_iwpriv(dut, intf, "shortgi 1"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6670 | } |
| 6671 | } |
| 6672 | |
| 6673 | |
Amarnath Hullur Subramanyam | 2538acc | 2018-02-02 16:15:25 -0800 | [diff] [blame] | 6674 | #ifdef NL80211_SUPPORT |
| 6675 | static int sta_set_he_mcs(struct sigma_dut *dut, const char *intf, |
| 6676 | enum he_mcs_config mcs) |
| 6677 | { |
| 6678 | struct nl_msg *msg; |
| 6679 | int ret = 0; |
| 6680 | struct nlattr *params; |
| 6681 | int ifindex; |
| 6682 | |
| 6683 | ifindex = if_nametoindex(intf); |
| 6684 | if (ifindex == 0) { |
| 6685 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6686 | "%s: Index for interface %s failed", |
| 6687 | __func__, intf); |
| 6688 | return -1; |
| 6689 | } |
| 6690 | |
| 6691 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 6692 | NL80211_CMD_VENDOR)) || |
| 6693 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 6694 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 6695 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 6696 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || |
| 6697 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 6698 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MCS, |
| 6699 | mcs)) { |
| 6700 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6701 | "%s: err in adding vendor_cmd and vendor_data", |
| 6702 | __func__); |
| 6703 | nlmsg_free(msg); |
| 6704 | return -1; |
| 6705 | } |
| 6706 | nla_nest_end(msg, params); |
| 6707 | |
| 6708 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 6709 | if (ret) { |
| 6710 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6711 | "%s: err in send_and_recv_msgs, ret=%d", |
| 6712 | __func__, ret); |
| 6713 | } |
| 6714 | return ret; |
| 6715 | } |
| 6716 | #endif /* NL80211_SUPPORT */ |
| 6717 | |
| 6718 | |
Kiran Kumar Lokere | 419f696 | 2018-10-24 19:03:04 -0700 | [diff] [blame] | 6719 | static int sta_set_action_tx_in_he_tb_ppdu(struct sigma_dut *dut, |
| 6720 | const char *intf, int enable) |
| 6721 | { |
| 6722 | #ifdef NL80211_SUPPORT |
| 6723 | struct nl_msg *msg; |
| 6724 | int ret = 0; |
| 6725 | struct nlattr *params; |
| 6726 | int ifindex; |
| 6727 | |
| 6728 | ifindex = if_nametoindex(intf); |
| 6729 | if (ifindex == 0) { |
| 6730 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6731 | "%s: Index for interface %s failed", |
| 6732 | __func__, intf); |
| 6733 | return -1; |
| 6734 | } |
| 6735 | |
| 6736 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 6737 | NL80211_CMD_VENDOR)) || |
| 6738 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 6739 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 6740 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 6741 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || |
| 6742 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 6743 | nla_put_u8(msg, |
| 6744 | QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_ACTION_TX_TB_PPDU, |
| 6745 | enable)) { |
| 6746 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6747 | "%s: err in adding vendor_cmd and vendor_data", |
| 6748 | __func__); |
| 6749 | nlmsg_free(msg); |
| 6750 | return -1; |
| 6751 | } |
| 6752 | nla_nest_end(msg, params); |
| 6753 | |
| 6754 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 6755 | if (ret) { |
| 6756 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6757 | "%s: err in send_and_recv_msgs, ret=%d", |
| 6758 | __func__, ret); |
| 6759 | } |
| 6760 | return ret; |
| 6761 | #else /* NL80211_SUPPORT */ |
| 6762 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6763 | "HE action Tx TB PPDU cannot be set without NL80211_SUPPORT defined"); |
| 6764 | return -1; |
| 6765 | #endif /* NL80211_SUPPORT */ |
| 6766 | } |
| 6767 | |
| 6768 | |
Amarnath Hullur Subramanyam | 4622a21 | 2018-02-23 12:12:14 -0800 | [diff] [blame] | 6769 | static int sta_set_heconfig_and_wep_tkip(struct sigma_dut *dut, |
| 6770 | const char *intf, int enable) |
| 6771 | { |
| 6772 | #ifdef NL80211_SUPPORT |
| 6773 | struct nl_msg *msg; |
| 6774 | int ret = 0; |
| 6775 | struct nlattr *params; |
| 6776 | int ifindex; |
| 6777 | |
| 6778 | ifindex = if_nametoindex(intf); |
| 6779 | if (ifindex == 0) { |
| 6780 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6781 | "%s: Index for interface %s failed", |
| 6782 | __func__, intf); |
| 6783 | return -1; |
| 6784 | } |
| 6785 | |
| 6786 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 6787 | NL80211_CMD_VENDOR)) || |
| 6788 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 6789 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 6790 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 6791 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || |
| 6792 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 6793 | nla_put_u8(msg, |
| 6794 | QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WEP_TKIP_IN_HE, |
| 6795 | enable)) { |
| 6796 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6797 | "%s: err in adding vendor_cmd and vendor_data", |
| 6798 | __func__); |
| 6799 | nlmsg_free(msg); |
| 6800 | return -1; |
| 6801 | } |
| 6802 | nla_nest_end(msg, params); |
| 6803 | |
| 6804 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 6805 | if (ret) { |
| 6806 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6807 | "%s: err in send_and_recv_msgs, ret=%d", |
| 6808 | __func__, ret); |
| 6809 | } |
| 6810 | return ret; |
| 6811 | #else /* NL80211_SUPPORT */ |
| 6812 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6813 | "HE config enablement cannot be changed without NL80211_SUPPORT defined"); |
| 6814 | return -1; |
| 6815 | #endif /* NL80211_SUPPORT */ |
| 6816 | } |
| 6817 | |
| 6818 | |
Kiran Kumar Lokere | 765bdd8 | 2019-02-24 22:14:43 -0800 | [diff] [blame] | 6819 | #ifdef NL80211_SUPPORT |
Kiran Kumar Lokere | 642f7ce | 2019-02-25 18:28:10 -0800 | [diff] [blame] | 6820 | |
Kiran Kumar Lokere | 765bdd8 | 2019-02-24 22:14:43 -0800 | [diff] [blame] | 6821 | static int sta_set_he_testbed_def(struct sigma_dut *dut, |
| 6822 | const char *intf, int cfg) |
| 6823 | { |
| 6824 | struct nl_msg *msg; |
| 6825 | int ret = 0; |
| 6826 | struct nlattr *params; |
| 6827 | int ifindex; |
| 6828 | |
| 6829 | ifindex = if_nametoindex(intf); |
| 6830 | if (ifindex == 0) { |
| 6831 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6832 | "%s: Index for interface %s failed", |
| 6833 | __func__, intf); |
| 6834 | return -1; |
| 6835 | } |
| 6836 | |
| 6837 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 6838 | NL80211_CMD_VENDOR)) || |
| 6839 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 6840 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 6841 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 6842 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || |
| 6843 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 6844 | nla_put_u8(msg, |
| 6845 | QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SET_HE_TESTBED_DEFAULTS, |
| 6846 | cfg)) { |
| 6847 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6848 | "%s: err in adding vendor_cmd and vendor_data", |
| 6849 | __func__); |
| 6850 | nlmsg_free(msg); |
| 6851 | return -1; |
| 6852 | } |
| 6853 | nla_nest_end(msg, params); |
| 6854 | |
| 6855 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 6856 | if (ret) { |
| 6857 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6858 | "%s: err in send_and_recv_msgs, ret=%d", |
| 6859 | __func__, ret); |
| 6860 | } |
| 6861 | return ret; |
| 6862 | } |
Kiran Kumar Lokere | 642f7ce | 2019-02-25 18:28:10 -0800 | [diff] [blame] | 6863 | |
| 6864 | |
| 6865 | static int sta_set_2g_vht_supp(struct sigma_dut *dut, const char *intf, int cfg) |
| 6866 | { |
| 6867 | struct nl_msg *msg; |
| 6868 | int ret = 0; |
| 6869 | struct nlattr *params; |
| 6870 | int ifindex; |
| 6871 | |
| 6872 | ifindex = if_nametoindex(intf); |
| 6873 | if (ifindex == 0) { |
| 6874 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6875 | "%s: Index for interface %s failed", |
| 6876 | __func__, intf); |
| 6877 | return -1; |
| 6878 | } |
| 6879 | |
| 6880 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 6881 | NL80211_CMD_VENDOR)) || |
| 6882 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 6883 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 6884 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 6885 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || |
| 6886 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 6887 | nla_put_u8(msg, |
| 6888 | QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_2G_VHT, |
| 6889 | cfg)) { |
| 6890 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6891 | "%s: err in adding vendor_cmd and vendor_data", |
| 6892 | __func__); |
| 6893 | nlmsg_free(msg); |
| 6894 | return -1; |
| 6895 | } |
| 6896 | nla_nest_end(msg, params); |
| 6897 | |
| 6898 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 6899 | if (ret) { |
| 6900 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6901 | "%s: err in send_and_recv_msgs, ret=%d", |
| 6902 | __func__, ret); |
| 6903 | } |
| 6904 | return ret; |
| 6905 | } |
| 6906 | |
Kiran Kumar Lokere | 765bdd8 | 2019-02-24 22:14:43 -0800 | [diff] [blame] | 6907 | #endif /* NL80211_SUPPORT */ |
| 6908 | |
| 6909 | |
Amarnath Hullur Subramanyam | 13215de | 2018-02-27 14:12:55 -0800 | [diff] [blame] | 6910 | static int sta_set_addba_buf_size(struct sigma_dut *dut, |
| 6911 | const char *intf, int bufsize) |
| 6912 | { |
| 6913 | #ifdef NL80211_SUPPORT |
| 6914 | struct nl_msg *msg; |
| 6915 | int ret = 0; |
| 6916 | struct nlattr *params; |
| 6917 | int ifindex; |
| 6918 | |
| 6919 | ifindex = if_nametoindex(intf); |
| 6920 | if (ifindex == 0) { |
| 6921 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6922 | "%s: Index for interface %s failed", |
| 6923 | __func__, intf); |
| 6924 | return -1; |
| 6925 | } |
| 6926 | |
| 6927 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 6928 | NL80211_CMD_VENDOR)) || |
| 6929 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 6930 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 6931 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 6932 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || |
| 6933 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
Kiran Kumar Lokere | 26e2758 | 2018-08-01 16:18:34 -0700 | [diff] [blame] | 6934 | nla_put_u16(msg, |
| 6935 | QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE, |
| 6936 | bufsize)) { |
Amarnath Hullur Subramanyam | 13215de | 2018-02-27 14:12:55 -0800 | [diff] [blame] | 6937 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6938 | "%s: err in adding vendor_cmd and vendor_data", |
| 6939 | __func__); |
| 6940 | nlmsg_free(msg); |
| 6941 | return -1; |
| 6942 | } |
| 6943 | nla_nest_end(msg, params); |
| 6944 | |
| 6945 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 6946 | if (ret) { |
| 6947 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6948 | "%s: err in send_and_recv_msgs, ret=%d", |
| 6949 | __func__, ret); |
| 6950 | } |
| 6951 | return ret; |
| 6952 | #else /* NL80211_SUPPORT */ |
| 6953 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6954 | "AddBA bufsize cannot be changed without NL80211_SUPPORT defined"); |
| 6955 | return -1; |
| 6956 | #endif /* NL80211_SUPPORT */ |
| 6957 | } |
| 6958 | |
| 6959 | |
Arif Hussain | 8d5b27b | 2018-05-14 14:31:03 -0700 | [diff] [blame] | 6960 | static int sta_set_tx_beamformee(struct sigma_dut *dut, const char *intf, |
| 6961 | int enable) |
| 6962 | { |
| 6963 | #ifdef NL80211_SUPPORT |
| 6964 | struct nl_msg *msg; |
| 6965 | int ret = 0; |
| 6966 | struct nlattr *params; |
| 6967 | int ifindex; |
| 6968 | |
| 6969 | ifindex = if_nametoindex(intf); |
| 6970 | if (ifindex == 0) { |
| 6971 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6972 | "%s: Index for interface %s failed", |
| 6973 | __func__, intf); |
| 6974 | return -1; |
| 6975 | } |
| 6976 | |
| 6977 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 6978 | NL80211_CMD_VENDOR)) || |
| 6979 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 6980 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 6981 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 6982 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || |
| 6983 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 6984 | nla_put_u8(msg, |
| 6985 | QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_TX_BEAMFORMEE, |
| 6986 | enable)) { |
| 6987 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6988 | "%s: err in adding vendor_cmd and vendor_data", |
| 6989 | __func__); |
| 6990 | nlmsg_free(msg); |
| 6991 | return -1; |
| 6992 | } |
| 6993 | nla_nest_end(msg, params); |
| 6994 | |
| 6995 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 6996 | if (ret) { |
| 6997 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6998 | "%s: err in send_and_recv_msgs, ret=%d", |
| 6999 | __func__, ret); |
| 7000 | } |
| 7001 | return ret; |
| 7002 | #else /* NL80211_SUPPORT */ |
| 7003 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7004 | "tx beamformee cannot be changed without NL80211_SUPPORT defined"); |
| 7005 | return -1; |
| 7006 | #endif /* NL80211_SUPPORT */ |
| 7007 | } |
| 7008 | |
| 7009 | |
Arif Hussain | 9765f7d | 2018-07-03 08:28:26 -0700 | [diff] [blame] | 7010 | static int sta_set_beamformee_sts(struct sigma_dut *dut, const char *intf, |
| 7011 | int val) |
| 7012 | { |
| 7013 | #ifdef NL80211_SUPPORT |
| 7014 | struct nl_msg *msg; |
| 7015 | int ret = 0; |
| 7016 | struct nlattr *params; |
| 7017 | int ifindex; |
| 7018 | |
| 7019 | ifindex = if_nametoindex(intf); |
| 7020 | if (ifindex == 0) { |
| 7021 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7022 | "%s: Index for interface %s failed, val:%d", |
| 7023 | __func__, intf, val); |
| 7024 | return -1; |
| 7025 | } |
| 7026 | |
| 7027 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 7028 | NL80211_CMD_VENDOR)) || |
| 7029 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 7030 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 7031 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 7032 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || |
| 7033 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 7034 | nla_put_u8(msg, |
| 7035 | QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_BEAMFORMEE_NSTS, |
| 7036 | val)) { |
| 7037 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7038 | "%s: err in adding vendor_cmd and vendor_data, val: %d", |
| 7039 | __func__, val); |
| 7040 | nlmsg_free(msg); |
| 7041 | return -1; |
| 7042 | } |
| 7043 | nla_nest_end(msg, params); |
| 7044 | |
| 7045 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 7046 | if (ret) { |
| 7047 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7048 | "%s: err in send_and_recv_msgs, ret=%d, val=%d", |
| 7049 | __func__, ret, val); |
| 7050 | } |
| 7051 | return ret; |
| 7052 | #else /* NL80211_SUPPORT */ |
| 7053 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7054 | "beamformee sts cannot be changed without NL80211_SUPPORT defined"); |
| 7055 | return -1; |
| 7056 | #endif /* NL80211_SUPPORT */ |
| 7057 | } |
| 7058 | |
| 7059 | |
Arif Hussain | 68d23f5 | 2018-07-11 13:39:08 -0700 | [diff] [blame] | 7060 | #ifdef NL80211_SUPPORT |
Kiran Kumar Lokere | 55eb558 | 2018-08-19 20:03:26 -0700 | [diff] [blame] | 7061 | static int sta_set_mac_padding_duration(struct sigma_dut *dut, const char *intf, |
| 7062 | enum qca_wlan_he_mac_padding_dur val) |
| 7063 | { |
Arif Hussain | 68d23f5 | 2018-07-11 13:39:08 -0700 | [diff] [blame] | 7064 | struct nl_msg *msg; |
| 7065 | int ret = 0; |
| 7066 | struct nlattr *params; |
| 7067 | int ifindex; |
| 7068 | |
| 7069 | ifindex = if_nametoindex(intf); |
| 7070 | if (ifindex == 0) { |
| 7071 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7072 | "%s: Index for interface %s failed, val:%d", |
| 7073 | __func__, intf, val); |
| 7074 | return -1; |
| 7075 | } |
| 7076 | |
| 7077 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 7078 | NL80211_CMD_VENDOR)) || |
| 7079 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 7080 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 7081 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 7082 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || |
| 7083 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 7084 | nla_put_u8(msg, |
| 7085 | QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MAC_PADDING_DUR, |
| 7086 | val)) { |
| 7087 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7088 | "%s: err in adding vendor_cmd and vendor_data, val: %d", |
| 7089 | __func__, val); |
| 7090 | nlmsg_free(msg); |
| 7091 | return -1; |
| 7092 | } |
| 7093 | nla_nest_end(msg, params); |
| 7094 | |
| 7095 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 7096 | if (ret) { |
| 7097 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7098 | "%s: err in send_and_recv_msgs, ret=%d, val=%d", |
| 7099 | __func__, ret, val); |
| 7100 | } |
| 7101 | return ret; |
Arif Hussain | 68d23f5 | 2018-07-11 13:39:08 -0700 | [diff] [blame] | 7102 | } |
Kiran Kumar Lokere | 55eb558 | 2018-08-19 20:03:26 -0700 | [diff] [blame] | 7103 | #endif /* NL80211_SUPPORT */ |
Arif Hussain | 68d23f5 | 2018-07-11 13:39:08 -0700 | [diff] [blame] | 7104 | |
| 7105 | |
Kiran Kumar Lokere | 400d68f | 2018-08-29 18:45:11 -0700 | [diff] [blame] | 7106 | static int sta_set_tx_su_ppdu_cfg(struct sigma_dut *dut, const char *intf, |
| 7107 | int val) |
| 7108 | { |
| 7109 | #ifdef NL80211_SUPPORT |
| 7110 | struct nl_msg *msg; |
| 7111 | int ret = 0; |
| 7112 | struct nlattr *params; |
| 7113 | int ifindex; |
| 7114 | |
| 7115 | ifindex = if_nametoindex(intf); |
| 7116 | if (ifindex == 0) { |
| 7117 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7118 | "%s: Index for interface %s failed, val:%d", |
| 7119 | __func__, intf, val); |
| 7120 | return -1; |
| 7121 | } |
| 7122 | |
| 7123 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 7124 | NL80211_CMD_VENDOR)) || |
| 7125 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 7126 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 7127 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 7128 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || |
| 7129 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 7130 | nla_put_u8(msg, |
| 7131 | QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_SUPPDU, |
| 7132 | val)) { |
| 7133 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7134 | "%s: err in adding vendor_cmd and vendor_data, val: %d", |
| 7135 | __func__, val); |
| 7136 | nlmsg_free(msg); |
| 7137 | return -1; |
| 7138 | } |
| 7139 | nla_nest_end(msg, params); |
| 7140 | |
| 7141 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 7142 | if (ret) { |
| 7143 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7144 | "%s: err in send_and_recv_msgs, ret=%d, val=%d", |
| 7145 | __func__, ret, val); |
| 7146 | } |
| 7147 | return ret; |
| 7148 | #else /* NL80211_SUPPORT */ |
| 7149 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7150 | "Tx SU PPDU cannot be set without NL80211_SUPPORT defined"); |
| 7151 | return -1; |
| 7152 | #endif /* NL80211_SUPPORT */ |
| 7153 | } |
| 7154 | |
| 7155 | |
Kiran Kumar Lokere | 29c1bb0 | 2018-10-08 17:41:02 -0700 | [diff] [blame] | 7156 | #ifdef NL80211_SUPPORT |
| 7157 | static int sta_set_he_om_ctrl_reset(struct sigma_dut *dut, const char *intf) |
| 7158 | { |
| 7159 | struct nl_msg *msg; |
| 7160 | int ret = 0; |
| 7161 | struct nlattr *params; |
| 7162 | int ifindex; |
| 7163 | |
| 7164 | ifindex = if_nametoindex(intf); |
| 7165 | if (ifindex == 0) { |
| 7166 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7167 | "%s: Index for interface %s failed", |
| 7168 | __func__, intf); |
| 7169 | return -1; |
| 7170 | } |
| 7171 | |
| 7172 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 7173 | NL80211_CMD_VENDOR)) || |
| 7174 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 7175 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 7176 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 7177 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || |
| 7178 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 7179 | nla_put_flag(msg, |
| 7180 | QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_CLEAR_HE_OM_CTRL_CONFIG)) { |
| 7181 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7182 | "%s: err in adding vendor_cmd and vendor_data", |
| 7183 | __func__); |
| 7184 | nlmsg_free(msg); |
| 7185 | return -1; |
| 7186 | } |
| 7187 | nla_nest_end(msg, params); |
| 7188 | |
| 7189 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 7190 | if (ret) { |
| 7191 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7192 | "%s: err in send_and_recv_msgs, ret=%d", |
| 7193 | __func__, ret); |
| 7194 | } |
| 7195 | return ret; |
| 7196 | } |
| 7197 | #endif /* NL80211_SUPPORT */ |
| 7198 | |
| 7199 | |
Kiran Kumar Lokere | b101268 | 2018-08-08 17:48:32 -0700 | [diff] [blame] | 7200 | static int sta_set_mu_edca_override(struct sigma_dut *dut, const char *intf, |
| 7201 | int val) |
| 7202 | { |
| 7203 | #ifdef NL80211_SUPPORT |
| 7204 | struct nl_msg *msg; |
| 7205 | int ret = 0; |
| 7206 | struct nlattr *params; |
| 7207 | int ifindex; |
| 7208 | |
| 7209 | ifindex = if_nametoindex(intf); |
| 7210 | if (ifindex == 0) { |
| 7211 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7212 | "%s: Index for interface %s failed, val:%d", |
| 7213 | __func__, intf, val); |
| 7214 | return -1; |
| 7215 | } |
| 7216 | |
| 7217 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 7218 | NL80211_CMD_VENDOR)) || |
| 7219 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 7220 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 7221 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 7222 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || |
| 7223 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 7224 | nla_put_u8(msg, |
| 7225 | QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_OVERRIDE_MU_EDCA, |
| 7226 | val)) { |
| 7227 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7228 | "%s: err in adding vendor_cmd and vendor_data, val: %d", |
| 7229 | __func__, val); |
| 7230 | nlmsg_free(msg); |
| 7231 | return -1; |
| 7232 | } |
| 7233 | nla_nest_end(msg, params); |
| 7234 | |
| 7235 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 7236 | if (ret) { |
| 7237 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7238 | "%s: err in send_and_recv_msgs, ret=%d, val=%d", |
| 7239 | __func__, ret, val); |
| 7240 | } |
| 7241 | return ret; |
| 7242 | #else /* NL80211_SUPPORT */ |
| 7243 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7244 | "MU EDCA override cannot be changed without NL80211_SUPPORT defined"); |
| 7245 | return -1; |
| 7246 | #endif /* NL80211_SUPPORT */ |
| 7247 | } |
| 7248 | |
| 7249 | |
Kiran Kumar Lokere | de33e37 | 2018-08-29 16:26:24 -0700 | [diff] [blame] | 7250 | static int sta_set_om_ctrl_supp(struct sigma_dut *dut, const char *intf, |
| 7251 | int val) |
| 7252 | { |
| 7253 | #ifdef NL80211_SUPPORT |
| 7254 | struct nl_msg *msg; |
| 7255 | int ret = 0; |
| 7256 | struct nlattr *params; |
| 7257 | int ifindex; |
| 7258 | |
| 7259 | ifindex = if_nametoindex(intf); |
| 7260 | if (ifindex == 0) { |
| 7261 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7262 | "%s: Index for interface %s failed, val:%d", |
| 7263 | __func__, intf, val); |
| 7264 | return -1; |
| 7265 | } |
| 7266 | |
| 7267 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 7268 | NL80211_CMD_VENDOR)) || |
| 7269 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 7270 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 7271 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 7272 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || |
| 7273 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 7274 | nla_put_u8(msg, |
| 7275 | QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OM_CTRL_SUPP, |
| 7276 | val)) { |
| 7277 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7278 | "%s: err in adding vendor_cmd and vendor_data, val: %d", |
| 7279 | __func__, val); |
| 7280 | nlmsg_free(msg); |
| 7281 | return -1; |
| 7282 | } |
| 7283 | nla_nest_end(msg, params); |
| 7284 | |
| 7285 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 7286 | if (ret) { |
| 7287 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7288 | "%s: err in send_and_recv_msgs, ret=%d, val=%d", |
| 7289 | __func__, ret, val); |
| 7290 | } |
| 7291 | return ret; |
| 7292 | #else /* NL80211_SUPPORT */ |
| 7293 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7294 | "HE OM ctrl cannot be changed without NL80211_SUPPORT defined"); |
| 7295 | return -1; |
| 7296 | #endif /* NL80211_SUPPORT */ |
| 7297 | } |
| 7298 | |
| 7299 | |
Arif Hussain | 480d5f4 | 2019-03-12 14:40:42 -0700 | [diff] [blame] | 7300 | static int sta_set_twt_req_support(struct sigma_dut *dut, const char *intf, |
| 7301 | int val) |
| 7302 | { |
| 7303 | #ifdef NL80211_SUPPORT |
| 7304 | struct nl_msg *msg; |
| 7305 | int ret; |
| 7306 | struct nlattr *params; |
| 7307 | int ifindex; |
| 7308 | |
| 7309 | ifindex = if_nametoindex(intf); |
| 7310 | if (ifindex == 0) { |
| 7311 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7312 | "%s: Index for interface %s failed, val:%d", |
| 7313 | __func__, intf, val); |
| 7314 | return -1; |
| 7315 | } |
| 7316 | |
| 7317 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 7318 | NL80211_CMD_VENDOR)) || |
| 7319 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 7320 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 7321 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 7322 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || |
| 7323 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 7324 | nla_put_u8(msg, |
| 7325 | QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TWT_REQ_SUPPORT, |
| 7326 | val)) { |
| 7327 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7328 | "%s: err in adding vendor_cmd and vendor_data, val: %d", |
| 7329 | __func__, val); |
| 7330 | nlmsg_free(msg); |
| 7331 | return -1; |
| 7332 | } |
| 7333 | nla_nest_end(msg, params); |
| 7334 | |
| 7335 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 7336 | if (ret) { |
| 7337 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7338 | "%s: err in send_and_recv_msgs, ret=%d, val=%d", |
| 7339 | __func__, ret, val); |
| 7340 | } |
| 7341 | return ret; |
| 7342 | #else /* NL80211_SUPPORT */ |
| 7343 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7344 | "TWT Request cannot be changed without NL80211_SUPPORT defined"); |
| 7345 | return -1; |
| 7346 | #endif /* NL80211_SUPPORT */ |
| 7347 | } |
| 7348 | |
| 7349 | |
Amarnath Hullur Subramanyam | 58f2a6e | 2018-01-31 03:36:00 -0800 | [diff] [blame] | 7350 | static void sta_reset_default_wcn(struct sigma_dut *dut, const char *intf, |
| 7351 | const char *type) |
| 7352 | { |
| 7353 | char buf[60]; |
| 7354 | |
| 7355 | if (dut->program == PROGRAM_HE) { |
| 7356 | /* resetting phymode to auto in case of HE program */ |
| 7357 | snprintf(buf, sizeof(buf), "iwpriv %s setphymode 0", intf); |
| 7358 | if (system(buf) != 0) { |
| 7359 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7360 | "iwpriv %s setphymode failed", intf); |
| 7361 | } |
| 7362 | |
Amarnath Hullur Subramanyam | 9cecb50 | 2018-04-25 13:26:30 -0700 | [diff] [blame] | 7363 | /* reset the rate to Auto rate */ |
| 7364 | snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0xff", |
| 7365 | intf); |
| 7366 | if (system(buf) != 0) { |
| 7367 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7368 | "iwpriv %s set_11ax_rate 0xff failed", |
| 7369 | intf); |
| 7370 | } |
| 7371 | |
Kiran Kumar Lokere | 86cfe3a | 2018-06-01 11:55:15 -0700 | [diff] [blame] | 7372 | /* reset the LDPC setting */ |
| 7373 | snprintf(buf, sizeof(buf), "iwpriv %s ldpc 1", intf); |
| 7374 | if (system(buf) != 0) { |
| 7375 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7376 | "iwpriv %s ldpc 1 failed", intf); |
| 7377 | } |
| 7378 | |
Kiran Kumar Lokere | d6149ff | 2018-12-05 20:20:41 -0800 | [diff] [blame] | 7379 | /* reset the power save setting */ |
| 7380 | snprintf(buf, sizeof(buf), "iwpriv %s setPower 2", intf); |
| 7381 | if (system(buf) != 0) { |
| 7382 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7383 | "iwpriv %s setPower 2 failed", intf); |
| 7384 | } |
| 7385 | |
Amarnath Hullur Subramanyam | 58f2a6e | 2018-01-31 03:36:00 -0800 | [diff] [blame] | 7386 | /* remove all network profiles */ |
| 7387 | remove_wpa_networks(intf); |
Amarnath Hullur Subramanyam | 2538acc | 2018-02-02 16:15:25 -0800 | [diff] [blame] | 7388 | |
Amarnath Hullur Subramanyam | 13215de | 2018-02-27 14:12:55 -0800 | [diff] [blame] | 7389 | /* Configure ADDBA Req/Rsp buffer size to be 64 */ |
| 7390 | sta_set_addba_buf_size(dut, intf, 64); |
| 7391 | |
Amarnath Hullur Subramanyam | 5f32d57 | 2018-03-02 00:02:33 -0800 | [diff] [blame] | 7392 | #ifdef NL80211_SUPPORT |
Kiran Kumar Lokere | 765bdd8 | 2019-02-24 22:14:43 -0800 | [diff] [blame] | 7393 | /* Reset the device HE capabilities to its default supported |
| 7394 | * configuration. */ |
| 7395 | sta_set_he_testbed_def(dut, intf, 0); |
| 7396 | |
Amarnath Hullur Subramanyam | 5f32d57 | 2018-03-02 00:02:33 -0800 | [diff] [blame] | 7397 | /* Disable noackpolicy for all AC */ |
| 7398 | if (nlvendor_sta_set_noack(dut, intf, 0, QCA_WLAN_AC_ALL)) { |
| 7399 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7400 | "Disable of noackpolicy for all AC failed"); |
| 7401 | } |
| 7402 | #endif /* NL80211_SUPPORT */ |
| 7403 | |
Amarnath Hullur Subramanyam | b1724a5 | 2018-03-07 14:31:46 -0800 | [diff] [blame] | 7404 | /* Enable WMM by default */ |
| 7405 | if (wcn_sta_set_wmm(dut, intf, "on")) { |
| 7406 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7407 | "Enable of WMM in sta_reset_default_wcn failed"); |
| 7408 | } |
| 7409 | |
| 7410 | /* Disable ADDBA_REJECT by default */ |
| 7411 | if (nlvendor_sta_set_addba_reject(dut, intf, 0)) { |
| 7412 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7413 | "Disable of addba_reject in sta_reset_default_wcn failed"); |
| 7414 | } |
| 7415 | |
Amarnath Hullur Subramanyam | 1f65a67 | 2018-03-07 14:50:29 -0800 | [diff] [blame] | 7416 | /* Enable sending of ADDBA by default */ |
| 7417 | if (nlvendor_config_send_addba(dut, intf, 1)) { |
| 7418 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7419 | "Enable sending of ADDBA in sta_reset_default_wcn failed"); |
| 7420 | } |
| 7421 | |
Amarnath Hullur Subramanyam | 63c590a | 2018-03-07 15:26:21 -0800 | [diff] [blame] | 7422 | /* Enable AMPDU by default */ |
| 7423 | iwpriv_sta_set_ampdu(dut, intf, 1); |
| 7424 | |
Subhani Shaik | 8e7a305 | 2018-04-24 14:03:00 -0700 | [diff] [blame] | 7425 | #ifdef NL80211_SUPPORT |
| 7426 | if (sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_AUTO)) { |
| 7427 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7428 | "Set LTF config to default in sta_reset_default_wcn failed"); |
| 7429 | } |
Arif Hussain | 9765f7d | 2018-07-03 08:28:26 -0700 | [diff] [blame] | 7430 | |
Kiran Kumar Lokere | bad5112 | 2018-12-12 19:03:36 -0800 | [diff] [blame] | 7431 | /* set the beamformee NSTS(maximum number of |
| 7432 | * space-time streams) to default DUT config |
| 7433 | */ |
| 7434 | if (sta_set_beamformee_sts(dut, intf, 7)) { |
Arif Hussain | 9765f7d | 2018-07-03 08:28:26 -0700 | [diff] [blame] | 7435 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7436 | "Failed to set BeamformeeSTS"); |
| 7437 | } |
Arif Hussain | 68d23f5 | 2018-07-11 13:39:08 -0700 | [diff] [blame] | 7438 | |
Kiran Kumar Lokere | 55eb558 | 2018-08-19 20:03:26 -0700 | [diff] [blame] | 7439 | if (sta_set_mac_padding_duration( |
| 7440 | dut, intf, |
| 7441 | QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME)) { |
Arif Hussain | 68d23f5 | 2018-07-11 13:39:08 -0700 | [diff] [blame] | 7442 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7443 | "Failed to set MAC padding duration"); |
| 7444 | } |
Kiran Kumar Lokere | b101268 | 2018-08-08 17:48:32 -0700 | [diff] [blame] | 7445 | |
| 7446 | if (sta_set_mu_edca_override(dut, intf, 0)) { |
| 7447 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7448 | "ErrorCode,Failed to set MU EDCA override disable"); |
| 7449 | } |
Kiran Kumar Lokere | de33e37 | 2018-08-29 16:26:24 -0700 | [diff] [blame] | 7450 | |
| 7451 | if (sta_set_om_ctrl_supp(dut, intf, 1)) { |
| 7452 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7453 | "Failed to set OM ctrl supp"); |
| 7454 | } |
Kiran Kumar Lokere | 400d68f | 2018-08-29 18:45:11 -0700 | [diff] [blame] | 7455 | |
| 7456 | if (sta_set_tx_su_ppdu_cfg(dut, intf, 1)) { |
| 7457 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7458 | "Failed to set Tx SU PPDU enable"); |
| 7459 | } |
Kiran Kumar Lokere | 29c1bb0 | 2018-10-08 17:41:02 -0700 | [diff] [blame] | 7460 | |
Kiran Kumar Lokere | 419f696 | 2018-10-24 19:03:04 -0700 | [diff] [blame] | 7461 | if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 0)) { |
| 7462 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7463 | "failed to send TB PPDU Tx cfg"); |
| 7464 | } |
| 7465 | |
Kiran Kumar Lokere | 29c1bb0 | 2018-10-08 17:41:02 -0700 | [diff] [blame] | 7466 | if (sta_set_he_om_ctrl_reset(dut, intf)) { |
| 7467 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7468 | "Failed to set OM ctrl reset"); |
| 7469 | } |
Kiran Kumar Lokere | e5ed442 | 2018-12-18 18:25:02 -0800 | [diff] [blame] | 7470 | |
| 7471 | /* +HTC-HE support default on */ |
| 7472 | if (sta_set_he_htc_supp(dut, intf, 1)) { |
| 7473 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7474 | "Setting of +HTC-HE support failed"); |
| 7475 | } |
Subhani Shaik | 8e7a305 | 2018-04-24 14:03:00 -0700 | [diff] [blame] | 7476 | #endif /* NL80211_SUPPORT */ |
| 7477 | |
Arif Hussain | 8d5b27b | 2018-05-14 14:31:03 -0700 | [diff] [blame] | 7478 | if (sta_set_tx_beamformee(dut, intf, 1)) { |
| 7479 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7480 | "Set tx beamformee enable by default in sta_reset_default_wcn failed"); |
| 7481 | } |
| 7482 | |
Amarnath Hullur Subramanyam | 2538acc | 2018-02-02 16:15:25 -0800 | [diff] [blame] | 7483 | /* Set nss to 1 and MCS 0-7 in case of testbed */ |
| 7484 | if (type && strcasecmp(type, "Testbed") == 0) { |
| 7485 | #ifdef NL80211_SUPPORT |
| 7486 | int ret; |
| 7487 | #endif /* NL80211_SUPPORT */ |
| 7488 | |
| 7489 | snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf); |
| 7490 | if (system(buf) != 0) { |
| 7491 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7492 | "iwpriv %s nss failed", intf); |
| 7493 | } |
| 7494 | |
| 7495 | #ifdef NL80211_SUPPORT |
| 7496 | ret = sta_set_he_mcs(dut, intf, HE_80_MCS0_7); |
| 7497 | if (ret) { |
| 7498 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7499 | "Setting of MCS failed, ret:%d", |
| 7500 | ret); |
| 7501 | } |
| 7502 | #endif /* NL80211_SUPPORT */ |
Amarnath Hullur Subramanyam | c67621d | 2018-02-04 23:18:01 -0800 | [diff] [blame] | 7503 | |
| 7504 | /* Disable STBC as default */ |
| 7505 | wcn_sta_set_stbc(dut, intf, "0"); |
Amarnath Hullur Subramanyam | d5bb573 | 2018-02-22 15:50:38 -0800 | [diff] [blame] | 7506 | |
| 7507 | /* Disable AMSDU as default */ |
| 7508 | iwpriv_sta_set_amsdu(dut, intf, "0"); |
Amarnath Hullur Subramanyam | 474a17d | 2018-02-22 18:45:54 -0800 | [diff] [blame] | 7509 | |
| 7510 | #ifdef NL80211_SUPPORT |
| 7511 | /* HE fragmentation default off */ |
| 7512 | if (sta_set_he_fragmentation(dut, intf, |
| 7513 | HE_FRAG_DISABLE)) { |
| 7514 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7515 | "Setting of HE fragmentation failed"); |
| 7516 | } |
Kiran Kumar Lokere | bad5112 | 2018-12-12 19:03:36 -0800 | [diff] [blame] | 7517 | |
| 7518 | /* set the beamformee NSTS(maximum number of |
| 7519 | * space-time streams) to default testbed config |
| 7520 | */ |
| 7521 | if (sta_set_beamformee_sts(dut, intf, 3)) { |
| 7522 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7523 | "Failed to set BeamformeeSTS"); |
| 7524 | } |
| 7525 | |
Kiran Kumar Lokere | e5ed442 | 2018-12-18 18:25:02 -0800 | [diff] [blame] | 7526 | /* +HTC-HE support default off */ |
| 7527 | if (sta_set_he_htc_supp(dut, intf, 0)) { |
| 7528 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7529 | "Setting of +HTC-HE support failed"); |
| 7530 | } |
Kiran Kumar Lokere | 765bdd8 | 2019-02-24 22:14:43 -0800 | [diff] [blame] | 7531 | |
| 7532 | /* Set device HE capabilities to testbed default |
| 7533 | * configuration. */ |
| 7534 | if (sta_set_he_testbed_def(dut, intf, 1)) { |
| 7535 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 7536 | "Failed to set HE defaults"); |
| 7537 | } |
Kiran Kumar Lokere | 642f7ce | 2019-02-25 18:28:10 -0800 | [diff] [blame] | 7538 | |
| 7539 | /* Disable VHT support in 2.4 GHz for testbed */ |
| 7540 | sta_set_2g_vht_supp(dut, intf, 0); |
Amarnath Hullur Subramanyam | 474a17d | 2018-02-22 18:45:54 -0800 | [diff] [blame] | 7541 | #endif /* NL80211_SUPPORT */ |
Amarnath Hullur Subramanyam | 4622a21 | 2018-02-23 12:12:14 -0800 | [diff] [blame] | 7542 | |
| 7543 | /* Enable WEP/TKIP with HE capability in testbed */ |
| 7544 | if (sta_set_heconfig_and_wep_tkip(dut, intf, 1)) { |
| 7545 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7546 | "Enabling HE config with WEP/TKIP failed"); |
| 7547 | } |
Amarnath Hullur Subramanyam | 2538acc | 2018-02-02 16:15:25 -0800 | [diff] [blame] | 7548 | } |
Amarnath Hullur Subramanyam | 0acce2c | 2018-03-06 06:05:17 -0800 | [diff] [blame] | 7549 | |
| 7550 | /* Defaults in case of DUT */ |
| 7551 | if (type && strcasecmp(type, "DUT") == 0) { |
Arif Hussain | d48fcc7 | 2018-05-01 18:34:18 -0700 | [diff] [blame] | 7552 | /* Enable STBC by default */ |
| 7553 | wcn_sta_set_stbc(dut, intf, "1"); |
| 7554 | |
Amarnath Hullur Subramanyam | 0acce2c | 2018-03-06 06:05:17 -0800 | [diff] [blame] | 7555 | /* set nss to 2 */ |
| 7556 | snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf); |
| 7557 | if (system(buf) != 0) { |
| 7558 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7559 | "iwpriv %s nss 2 failed", intf); |
| 7560 | } |
Arif Hussain | ac6c511 | 2018-05-25 17:34:00 -0700 | [diff] [blame] | 7561 | dut->sta_nss = 2; |
Amarnath Hullur Subramanyam | 0acce2c | 2018-03-06 06:05:17 -0800 | [diff] [blame] | 7562 | |
| 7563 | #ifdef NL80211_SUPPORT |
Arif Hussain | ae23984 | 2018-05-01 18:20:05 -0700 | [diff] [blame] | 7564 | /* Set HE_MCS to 0-11 */ |
| 7565 | if (sta_set_he_mcs(dut, intf, HE_80_MCS0_11)) { |
Amarnath Hullur Subramanyam | 0acce2c | 2018-03-06 06:05:17 -0800 | [diff] [blame] | 7566 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7567 | "Setting of MCS failed"); |
| 7568 | } |
| 7569 | #endif /* NL80211_SUPPORT */ |
| 7570 | |
| 7571 | /* Disable WEP/TKIP with HE capability in DUT */ |
| 7572 | if (sta_set_heconfig_and_wep_tkip(dut, intf, 0)) { |
| 7573 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7574 | "Enabling HE config with WEP/TKIP failed"); |
| 7575 | } |
| 7576 | } |
Amarnath Hullur Subramanyam | 58f2a6e | 2018-01-31 03:36:00 -0800 | [diff] [blame] | 7577 | } |
| 7578 | } |
| 7579 | |
| 7580 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 7581 | static enum sigma_cmd_result cmd_sta_reset_default(struct sigma_dut *dut, |
| 7582 | struct sigma_conn *conn, |
| 7583 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7584 | { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7585 | const char *intf = get_param(cmd, "Interface"); |
Alexei Avshalom Lazar | 33f700c | 2018-12-18 16:00:39 +0200 | [diff] [blame] | 7586 | const char *band = get_param(cmd, "band"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7587 | const char *type; |
Amarnath Hullur Subramanyam | 9c381f5 | 2017-03-17 00:04:41 -0700 | [diff] [blame] | 7588 | const char *program = get_param(cmd, "program"); |
Ankita Bajaj | 0d5825b | 2017-10-25 16:20:17 +0530 | [diff] [blame] | 7589 | const char *dev_role = get_param(cmd, "DevRole"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7590 | |
Amarnath Hullur Subramanyam | 9c381f5 | 2017-03-17 00:04:41 -0700 | [diff] [blame] | 7591 | if (!program) |
| 7592 | program = get_param(cmd, "prog"); |
| 7593 | dut->program = sigma_program_to_enum(program); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7594 | dut->device_type = STA_unknown; |
| 7595 | type = get_param(cmd, "type"); |
| 7596 | if (type && strcasecmp(type, "Testbed") == 0) |
| 7597 | dut->device_type = STA_testbed; |
| 7598 | if (type && strcasecmp(type, "DUT") == 0) |
| 7599 | dut->device_type = STA_dut; |
| 7600 | |
| 7601 | if (dut->program == PROGRAM_TDLS) { |
| 7602 | /* Clear TDLS testing mode */ |
| 7603 | wpa_command(intf, "SET tdls_disabled 0"); |
| 7604 | wpa_command(intf, "SET tdls_testing 0"); |
| 7605 | dut->no_tpk_expiration = 0; |
Pradeep Reddy POTTETI | 8ce2a23 | 2016-10-28 12:17:32 +0530 | [diff] [blame] | 7606 | if (get_driver_type() == DRIVER_WCN) { |
| 7607 | /* Enable the WCN driver in TDLS Explicit trigger mode |
| 7608 | */ |
| 7609 | wpa_command(intf, "SET tdls_external_control 0"); |
| 7610 | wpa_command(intf, "SET tdls_trigger_control 0"); |
| 7611 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7612 | } |
| 7613 | |
Amarnath Hullur Subramanyam | 9c381f5 | 2017-03-17 00:04:41 -0700 | [diff] [blame] | 7614 | #ifdef MIRACAST |
| 7615 | if (dut->program == PROGRAM_WFD || |
| 7616 | dut->program == PROGRAM_DISPLAYR2) |
| 7617 | miracast_sta_reset_default(dut, conn, cmd); |
| 7618 | #endif /* MIRACAST */ |
| 7619 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7620 | switch (get_driver_type()) { |
| 7621 | case DRIVER_ATHEROS: |
| 7622 | sta_reset_default_ath(dut, intf, type); |
| 7623 | break; |
Amarnath Hullur Subramanyam | 58f2a6e | 2018-01-31 03:36:00 -0800 | [diff] [blame] | 7624 | case DRIVER_WCN: |
| 7625 | sta_reset_default_wcn(dut, intf, type); |
| 7626 | break; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7627 | default: |
| 7628 | break; |
| 7629 | } |
| 7630 | |
| 7631 | #ifdef ANDROID_NAN |
| 7632 | if (dut->program == PROGRAM_NAN) |
| 7633 | nan_cmd_sta_reset_default(dut, conn, cmd); |
| 7634 | #endif /* ANDROID_NAN */ |
| 7635 | |
Vinay Gannevaram | 3b9fdd3 | 2019-06-14 17:55:44 +0530 | [diff] [blame] | 7636 | if (dut->program == PROGRAM_LOC && |
| 7637 | lowi_cmd_sta_reset_default(dut, conn, cmd) < 0) |
| 7638 | return ERROR_SEND_STATUS; |
| 7639 | |
Jouni Malinen | ba63045 | 2018-06-22 11:49:59 +0300 | [diff] [blame] | 7640 | if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7641 | unlink("SP/wi-fi.org/pps.xml"); |
| 7642 | if (system("rm -r SP/*") != 0) { |
| 7643 | } |
| 7644 | unlink("next-client-cert.pem"); |
| 7645 | unlink("next-client-key.pem"); |
| 7646 | } |
| 7647 | |
Alexei Avshalom Lazar | 33f700c | 2018-12-18 16:00:39 +0200 | [diff] [blame] | 7648 | /* For WPS program of the 60 GHz band the band type needs to be saved */ |
| 7649 | if (dut->program == PROGRAM_WPS) { |
| 7650 | if (band && strcasecmp(band, "60GHz") == 0) { |
| 7651 | dut->band = WPS_BAND_60G; |
Alexei Avshalom Lazar | eee9ab0 | 2018-12-24 16:27:48 +0200 | [diff] [blame] | 7652 | /* For 60 GHz enable WPS for WPS TCs */ |
| 7653 | dut->wps_disable = 0; |
Alexei Avshalom Lazar | 33f700c | 2018-12-18 16:00:39 +0200 | [diff] [blame] | 7654 | } else { |
| 7655 | dut->band = WPS_BAND_NON_60G; |
| 7656 | } |
Alexei Avshalom Lazar | eee9ab0 | 2018-12-24 16:27:48 +0200 | [diff] [blame] | 7657 | } else if (dut->program == PROGRAM_60GHZ) { |
| 7658 | /* For 60 GHz MAC/PHY TCs WPS must be disabled */ |
| 7659 | dut->wps_disable = 1; |
Alexei Avshalom Lazar | 33f700c | 2018-12-18 16:00:39 +0200 | [diff] [blame] | 7660 | } |
| 7661 | |
Alexei Avshalom Lazar | 157ba06 | 2018-12-23 16:15:26 +0200 | [diff] [blame] | 7662 | if (is_60g_sigma_dut(dut)) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7663 | const char *dev_role = get_param(cmd, "DevRole"); |
Alexei Avshalom Lazar | c2a5bb1 | 2018-12-23 16:12:06 +0200 | [diff] [blame] | 7664 | char buf[256]; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7665 | |
Alexei Avshalom Lazar | eee9ab0 | 2018-12-24 16:27:48 +0200 | [diff] [blame] | 7666 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 7667 | "WPS 60 GHz program, wps_disable = %d", |
| 7668 | dut->wps_disable); |
| 7669 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7670 | if (!dev_role) { |
| 7671 | send_resp(dut, conn, SIGMA_ERROR, |
| 7672 | "errorCode,Missing DevRole argument"); |
| 7673 | return 0; |
| 7674 | } |
| 7675 | |
| 7676 | if (strcasecmp(dev_role, "STA") == 0) |
| 7677 | dut->dev_role = DEVROLE_STA; |
| 7678 | else if (strcasecmp(dev_role, "PCP") == 0) |
| 7679 | dut->dev_role = DEVROLE_PCP; |
| 7680 | else { |
| 7681 | send_resp(dut, conn, SIGMA_ERROR, |
| 7682 | "errorCode,Unknown DevRole"); |
| 7683 | return 0; |
| 7684 | } |
| 7685 | |
| 7686 | if (dut->device_type == STA_unknown) { |
| 7687 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7688 | "Device type is not STA testbed or DUT"); |
| 7689 | send_resp(dut, conn, SIGMA_ERROR, |
| 7690 | "errorCode,Unknown device type"); |
| 7691 | return 0; |
| 7692 | } |
Alexei Avshalom Lazar | c2a5bb1 | 2018-12-23 16:12:06 +0200 | [diff] [blame] | 7693 | |
| 7694 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 7695 | "Setting msdu_size to MAX: 7912"); |
| 7696 | snprintf(buf, sizeof(buf), "ifconfig %s mtu 7912", |
| 7697 | get_station_ifname()); |
| 7698 | |
| 7699 | if (system(buf) != 0) { |
| 7700 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s", |
| 7701 | buf); |
Jouni Malinen | 0e29cf2 | 2019-02-19 01:13:21 +0200 | [diff] [blame] | 7702 | return ERROR_SEND_STATUS; |
Alexei Avshalom Lazar | c2a5bb1 | 2018-12-23 16:12:06 +0200 | [diff] [blame] | 7703 | } |
Alexei Avshalom Lazar | aad97b0 | 2018-12-18 16:01:23 +0200 | [diff] [blame] | 7704 | |
| 7705 | if (sta_set_force_mcs(dut, 0, 1)) { |
| 7706 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7707 | "Failed to reset force MCS"); |
Jouni Malinen | 0e29cf2 | 2019-02-19 01:13:21 +0200 | [diff] [blame] | 7708 | return ERROR_SEND_STATUS; |
Alexei Avshalom Lazar | aad97b0 | 2018-12-18 16:01:23 +0200 | [diff] [blame] | 7709 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7710 | } |
| 7711 | |
| 7712 | wpa_command(intf, "WPS_ER_STOP"); |
| 7713 | wpa_command(intf, "FLUSH"); |
vamsi krishna | f39bc1e | 2017-08-23 17:37:53 +0530 | [diff] [blame] | 7714 | wpa_command(intf, "ERP_FLUSH"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7715 | wpa_command(intf, "SET radio_disabled 0"); |
| 7716 | |
Alexei Avshalom Lazar | 744ae8a | 2019-01-31 17:26:46 +0200 | [diff] [blame] | 7717 | dut->wps_forced_version = 0; |
| 7718 | |
Alexei Avshalom Lazar | 33f700c | 2018-12-18 16:00:39 +0200 | [diff] [blame] | 7719 | if (dut->wsc_fragment) { |
| 7720 | dut->wsc_fragment = 0; |
| 7721 | wpa_command(intf, "SET device_name Test client"); |
| 7722 | wpa_command(intf, "SET manufacturer "); |
| 7723 | wpa_command(intf, "SET model_name "); |
| 7724 | wpa_command(intf, "SET model_number "); |
| 7725 | wpa_command(intf, "SET serial_number "); |
| 7726 | } |
Alexei Avshalom Lazar | b094bf0 | 2018-12-18 16:00:53 +0200 | [diff] [blame] | 7727 | if (is_60g_sigma_dut(dut) && dut->force_rsn_ie) { |
| 7728 | dut->force_rsn_ie = FORCE_RSN_IE_NONE; |
| 7729 | sta_60g_force_rsn_ie(dut, FORCE_RSN_IE_NONE); |
| 7730 | } |
Alexei Avshalom Lazar | 33f700c | 2018-12-18 16:00:39 +0200 | [diff] [blame] | 7731 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7732 | if (dut->tmp_mac_addr && dut->set_macaddr) { |
| 7733 | dut->tmp_mac_addr = 0; |
| 7734 | if (system(dut->set_macaddr) != 0) { |
| 7735 | sigma_dut_print(dut, DUT_MSG_INFO, "Failed to clear " |
| 7736 | "temporary MAC address"); |
| 7737 | } |
| 7738 | } |
| 7739 | |
| 7740 | set_ps(intf, dut, 0); |
| 7741 | |
Jouni Malinen | ba63045 | 2018-06-22 11:49:59 +0300 | [diff] [blame] | 7742 | if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2 || |
| 7743 | dut->program == PROGRAM_HS2_R3) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7744 | wpa_command(intf, "SET interworking 1"); |
| 7745 | wpa_command(intf, "SET hs20 1"); |
| 7746 | } |
| 7747 | |
Deepak Dhamdhere | 0fe0e45 | 2017-12-18 14:52:09 -0800 | [diff] [blame] | 7748 | if (dut->program == PROGRAM_HS2_R2 || |
Jouni Malinen | ba63045 | 2018-06-22 11:49:59 +0300 | [diff] [blame] | 7749 | dut->program == PROGRAM_HS2_R3 || |
Deepak Dhamdhere | 0fe0e45 | 2017-12-18 14:52:09 -0800 | [diff] [blame] | 7750 | dut->program == PROGRAM_OCE) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7751 | wpa_command(intf, "SET pmf 1"); |
| 7752 | } else { |
| 7753 | wpa_command(intf, "SET pmf 0"); |
| 7754 | } |
| 7755 | |
| 7756 | hs2_clear_credentials(intf); |
| 7757 | wpa_command(intf, "SET hessid 00:00:00:00:00:00"); |
| 7758 | wpa_command(intf, "SET access_network_type 15"); |
| 7759 | |
| 7760 | static_ip_file(0, NULL, NULL, NULL); |
| 7761 | kill_dhcp_client(dut, intf); |
| 7762 | clear_ip_addr(dut, intf); |
| 7763 | |
| 7764 | dut->er_oper_performed = 0; |
| 7765 | dut->er_oper_bssid[0] = '\0'; |
| 7766 | |
priyadharshini gowthaman | ad6cbba | 2016-10-04 10:39:58 -0700 | [diff] [blame] | 7767 | if (dut->program == PROGRAM_LOC) { |
| 7768 | /* Disable Interworking by default */ |
| 7769 | wpa_command(get_station_ifname(), "SET interworking 0"); |
| 7770 | } |
| 7771 | |
Ashwini Patil | 0040258 | 2017-04-13 12:29:39 +0530 | [diff] [blame] | 7772 | if (dut->program == PROGRAM_MBO) { |
| 7773 | free(dut->non_pref_ch_list); |
| 7774 | dut->non_pref_ch_list = NULL; |
Ashwini Patil | 5acd738 | 2017-04-13 15:55:04 +0530 | [diff] [blame] | 7775 | free(dut->btm_query_cand_list); |
| 7776 | dut->btm_query_cand_list = NULL; |
Ashwini Patil | c63161e | 2017-04-13 16:30:23 +0530 | [diff] [blame] | 7777 | wpa_command(intf, "SET reject_btm_req_reason 0"); |
Ashwini Patil | a75de5a | 2017-04-13 16:35:05 +0530 | [diff] [blame] | 7778 | wpa_command(intf, "SET ignore_assoc_disallow 0"); |
Ashwini Patil | d174f2c | 2017-04-13 16:49:46 +0530 | [diff] [blame] | 7779 | wpa_command(intf, "SET gas_address3 0"); |
Ashwini Patil | 9183fdb | 2017-04-13 16:58:25 +0530 | [diff] [blame] | 7780 | wpa_command(intf, "SET roaming 1"); |
Ankita Bajaj | 1d97455 | 2018-09-18 16:56:44 +0530 | [diff] [blame] | 7781 | wpa_command(intf, "SET interworking 1"); |
Ashwini Patil | 0040258 | 2017-04-13 12:29:39 +0530 | [diff] [blame] | 7782 | } |
| 7783 | |
Jouni Malinen | 3c367e8 | 2017-06-23 17:01:47 +0300 | [diff] [blame] | 7784 | free(dut->rsne_override); |
| 7785 | dut->rsne_override = NULL; |
| 7786 | |
Jouni Malinen | 6814313 | 2017-09-02 02:34:08 +0300 | [diff] [blame] | 7787 | free(dut->sae_commit_override); |
| 7788 | dut->sae_commit_override = NULL; |
| 7789 | |
Jouni Malinen | 134fe3c | 2019-06-12 04:16:49 +0300 | [diff] [blame] | 7790 | dut->sta_associate_wait_connect = 0; |
| 7791 | dut->server_cert_hash[0] = '\0'; |
Jouni Malinen | 37d5c69 | 2019-08-19 16:56:55 +0300 | [diff] [blame] | 7792 | dut->server_cert_tod = 0; |
Jouni Malinen | 134fe3c | 2019-06-12 04:16:49 +0300 | [diff] [blame] | 7793 | dut->sta_tod_policy = 0; |
| 7794 | |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 7795 | dut->dpp_conf_id = -1; |
Jouni Malinen | b1dd21f | 2017-11-13 19:14:29 +0200 | [diff] [blame] | 7796 | free(dut->dpp_peer_uri); |
| 7797 | dut->dpp_peer_uri = NULL; |
Jouni Malinen | 63d5041 | 2017-11-24 11:55:38 +0200 | [diff] [blame] | 7798 | dut->dpp_local_bootstrap = -1; |
Jouni Malinen | 5011fb5 | 2017-12-05 21:00:15 +0200 | [diff] [blame] | 7799 | wpa_command(intf, "SET dpp_config_processing 2"); |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 7800 | |
Jouni Malinen | fac9cad | 2017-10-10 18:35:55 +0300 | [diff] [blame] | 7801 | wpa_command(intf, "VENDOR_ELEM_REMOVE 13 *"); |
| 7802 | |
vamsi krishna | a279949 | 2017-12-05 14:28:01 +0530 | [diff] [blame] | 7803 | if (dut->program == PROGRAM_OCE) { |
Ankita Bajaj | a2cb567 | 2017-10-25 16:08:28 +0530 | [diff] [blame] | 7804 | wpa_command(intf, "SET oce 1"); |
vamsi krishna | a279949 | 2017-12-05 14:28:01 +0530 | [diff] [blame] | 7805 | wpa_command(intf, "SET disable_fils 0"); |
Ankita Bajaj | 1bde794 | 2018-01-09 19:15:01 +0530 | [diff] [blame] | 7806 | wpa_command(intf, "FILS_HLP_REQ_FLUSH"); |
| 7807 | dut->fils_hlp = 0; |
| 7808 | #ifdef ANDROID |
| 7809 | hlp_thread_cleanup(dut); |
| 7810 | #endif /* ANDROID */ |
vamsi krishna | a279949 | 2017-12-05 14:28:01 +0530 | [diff] [blame] | 7811 | } |
Ankita Bajaj | a2cb567 | 2017-10-25 16:08:28 +0530 | [diff] [blame] | 7812 | |
Jouni Malinen | 8179fee | 2019-03-28 03:19:47 +0200 | [diff] [blame] | 7813 | dut->akm_values = 0; |
Jouni Malinen | 6a7c9b4 | 2019-08-20 00:15:59 +0300 | [diff] [blame] | 7814 | dut->sta_ft_ds = 0; |
Jouni Malinen | 8179fee | 2019-03-28 03:19:47 +0200 | [diff] [blame] | 7815 | |
Sunil Dutt | 076081f | 2018-02-05 19:45:50 +0530 | [diff] [blame] | 7816 | #ifdef NL80211_SUPPORT |
Sunil Dutt | 4459508 | 2018-02-12 19:41:45 +0530 | [diff] [blame] | 7817 | if (get_driver_type() == DRIVER_WCN && |
| 7818 | dut->config_rsnie == 1) { |
| 7819 | dut->config_rsnie = 0; |
| 7820 | sta_config_rsnie(dut, 0); |
Sunil Dutt | 076081f | 2018-02-05 19:45:50 +0530 | [diff] [blame] | 7821 | } |
| 7822 | #endif /* NL80211_SUPPORT */ |
| 7823 | |
Sunil Dutt | febf8a8 | 2018-02-09 18:50:13 +0530 | [diff] [blame] | 7824 | if (dev_role && strcasecmp(dev_role, "STA-CFON") == 0) { |
| 7825 | dut->dev_role = DEVROLE_STA_CFON; |
| 7826 | return sta_cfon_reset_default(dut, conn, cmd); |
| 7827 | } |
| 7828 | |
Jouni Malinen | 439352d | 2018-09-13 03:42:23 +0300 | [diff] [blame] | 7829 | wpa_command(intf, "SET setband AUTO"); |
| 7830 | |
Sunil Dutt | febf8a8 | 2018-02-09 18:50:13 +0530 | [diff] [blame] | 7831 | if (dut->program != PROGRAM_VHT) |
| 7832 | return cmd_sta_p2p_reset(dut, conn, cmd); |
| 7833 | |
Priyadharshini Gowthaman | a7dfd49 | 2015-11-09 14:34:08 -0800 | [diff] [blame] | 7834 | return 1; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7835 | } |
| 7836 | |
| 7837 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 7838 | static enum sigma_cmd_result cmd_sta_get_events(struct sigma_dut *dut, |
| 7839 | struct sigma_conn *conn, |
| 7840 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7841 | { |
| 7842 | const char *program = get_param(cmd, "Program"); |
| 7843 | |
| 7844 | if (program == NULL) |
| 7845 | return -1; |
| 7846 | #ifdef ANDROID_NAN |
| 7847 | if (strcasecmp(program, "NAN") == 0) |
| 7848 | return nan_cmd_sta_get_events(dut, conn, cmd); |
| 7849 | #endif /* ANDROID_NAN */ |
| 7850 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter"); |
| 7851 | return 0; |
| 7852 | } |
| 7853 | |
| 7854 | |
Jouni Malinen | 8290520 | 2018-04-29 17:20:10 +0300 | [diff] [blame] | 7855 | static int sta_exec_action_url(struct sigma_dut *dut, struct sigma_conn *conn, |
| 7856 | struct sigma_cmd *cmd) |
| 7857 | { |
| 7858 | const char *url = get_param(cmd, "url"); |
| 7859 | const char *method = get_param(cmd, "method"); |
| 7860 | pid_t pid; |
| 7861 | int status; |
| 7862 | |
| 7863 | if (!url || !method) |
| 7864 | return -1; |
| 7865 | |
| 7866 | /* TODO: Add support for method,post */ |
| 7867 | if (strcasecmp(method, "get") != 0) { |
| 7868 | send_resp(dut, conn, SIGMA_ERROR, |
| 7869 | "ErrorCode,Unsupported method"); |
| 7870 | return 0; |
| 7871 | } |
| 7872 | |
| 7873 | pid = fork(); |
| 7874 | if (pid < 0) { |
| 7875 | perror("fork"); |
| 7876 | return -1; |
| 7877 | } |
| 7878 | |
| 7879 | if (pid == 0) { |
| 7880 | char * argv[5] = { "wget", "-O", "/dev/null", |
| 7881 | (char *) url, NULL }; |
| 7882 | |
| 7883 | execv("/usr/bin/wget", argv); |
| 7884 | perror("execv"); |
| 7885 | exit(0); |
| 7886 | return -1; |
| 7887 | } |
| 7888 | |
| 7889 | if (waitpid(pid, &status, 0) < 0) { |
| 7890 | perror("waitpid"); |
| 7891 | return -1; |
| 7892 | } |
| 7893 | |
| 7894 | if (WIFEXITED(status)) { |
| 7895 | const char *errmsg; |
| 7896 | |
| 7897 | if (WEXITSTATUS(status) == 0) |
| 7898 | return 1; |
| 7899 | sigma_dut_print(dut, DUT_MSG_INFO, "wget exit status %d", |
| 7900 | WEXITSTATUS(status)); |
| 7901 | switch (WEXITSTATUS(status)) { |
| 7902 | case 4: |
| 7903 | errmsg = "errmsg,Network failure"; |
| 7904 | break; |
| 7905 | case 8: |
| 7906 | errmsg = "errmsg,Server issued an error response"; |
| 7907 | break; |
| 7908 | default: |
| 7909 | errmsg = "errmsg,Unknown failure from wget"; |
| 7910 | break; |
| 7911 | } |
| 7912 | send_resp(dut, conn, SIGMA_ERROR, errmsg); |
| 7913 | return 0; |
| 7914 | } |
| 7915 | |
| 7916 | send_resp(dut, conn, SIGMA_ERROR, "errmsg,Unknown failure"); |
| 7917 | return 0; |
| 7918 | } |
| 7919 | |
| 7920 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 7921 | static enum sigma_cmd_result cmd_sta_exec_action(struct sigma_dut *dut, |
| 7922 | struct sigma_conn *conn, |
| 7923 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7924 | { |
| 7925 | const char *program = get_param(cmd, "Prog"); |
| 7926 | |
Jouni Malinen | 8290520 | 2018-04-29 17:20:10 +0300 | [diff] [blame] | 7927 | if (program && !get_param(cmd, "interface")) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7928 | return -1; |
| 7929 | #ifdef ANDROID_NAN |
Jouni Malinen | 8290520 | 2018-04-29 17:20:10 +0300 | [diff] [blame] | 7930 | if (program && strcasecmp(program, "NAN") == 0) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7931 | return nan_cmd_sta_exec_action(dut, conn, cmd); |
| 7932 | #endif /* ANDROID_NAN */ |
Jouni Malinen | 8290520 | 2018-04-29 17:20:10 +0300 | [diff] [blame] | 7933 | |
| 7934 | if (program && strcasecmp(program, "Loc") == 0) |
priyadharshini gowthaman | d66913a | 2016-07-29 15:11:17 -0700 | [diff] [blame] | 7935 | return loc_cmd_sta_exec_action(dut, conn, cmd); |
Jouni Malinen | 8290520 | 2018-04-29 17:20:10 +0300 | [diff] [blame] | 7936 | |
| 7937 | if (get_param(cmd, "url")) |
| 7938 | return sta_exec_action_url(dut, conn, cmd); |
| 7939 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7940 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter"); |
| 7941 | return 0; |
| 7942 | } |
| 7943 | |
| 7944 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 7945 | static enum sigma_cmd_result cmd_sta_set_11n(struct sigma_dut *dut, |
| 7946 | struct sigma_conn *conn, |
| 7947 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7948 | { |
| 7949 | const char *intf = get_param(cmd, "Interface"); |
| 7950 | const char *val, *mcs32, *rate; |
| 7951 | |
| 7952 | val = get_param(cmd, "GREENFIELD"); |
| 7953 | if (val) { |
| 7954 | if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) { |
| 7955 | /* Enable GD */ |
| 7956 | send_resp(dut, conn, SIGMA_ERROR, |
| 7957 | "ErrorCode,GF not supported"); |
| 7958 | return 0; |
| 7959 | } |
| 7960 | } |
| 7961 | |
| 7962 | val = get_param(cmd, "SGI20"); |
| 7963 | if (val) { |
| 7964 | switch (get_driver_type()) { |
| 7965 | case DRIVER_ATHEROS: |
| 7966 | ath_sta_set_sgi(dut, intf, val); |
| 7967 | break; |
| 7968 | default: |
| 7969 | send_resp(dut, conn, SIGMA_ERROR, |
| 7970 | "ErrorCode,SGI20 not supported"); |
| 7971 | return 0; |
| 7972 | } |
| 7973 | } |
| 7974 | |
| 7975 | mcs32 = get_param(cmd, "MCS32"); /* HT Duplicate Mode Enable/Disable */ |
| 7976 | rate = get_param(cmd, "MCS_FIXEDRATE"); /* Fixed MCS rate (0..31) */ |
| 7977 | if (mcs32 && rate) { |
| 7978 | /* TODO */ |
| 7979 | send_resp(dut, conn, SIGMA_ERROR, |
| 7980 | "ErrorCode,MCS32,MCS_FIXEDRATE not supported"); |
| 7981 | return 0; |
| 7982 | } else if (mcs32 && !rate) { |
| 7983 | /* TODO */ |
| 7984 | send_resp(dut, conn, SIGMA_ERROR, |
| 7985 | "ErrorCode,MCS32 not supported"); |
| 7986 | return 0; |
| 7987 | } else if (!mcs32 && rate) { |
| 7988 | switch (get_driver_type()) { |
| 7989 | case DRIVER_ATHEROS: |
Priyadharshini Gowthaman | 8c5b9a4 | 2019-07-31 14:38:48 -0700 | [diff] [blame] | 7990 | novap_reset(dut, intf, 1); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7991 | ath_sta_set_11nrates(dut, intf, rate); |
| 7992 | break; |
| 7993 | default: |
| 7994 | send_resp(dut, conn, SIGMA_ERROR, |
| 7995 | "ErrorCode,MCS32_FIXEDRATE not supported"); |
| 7996 | return 0; |
| 7997 | } |
| 7998 | } |
| 7999 | |
| 8000 | return cmd_sta_set_wireless_common(intf, dut, conn, cmd); |
| 8001 | } |
| 8002 | |
| 8003 | |
Arif Hussain | 7b47d2d | 2018-05-09 10:44:02 -0700 | [diff] [blame] | 8004 | static void cmd_set_max_he_mcs(struct sigma_dut *dut, const char *intf, |
| 8005 | int mcs_config) |
| 8006 | { |
| 8007 | #ifdef NL80211_SUPPORT |
| 8008 | int ret; |
| 8009 | |
| 8010 | switch (mcs_config) { |
| 8011 | case HE_80_MCS0_7: |
| 8012 | case HE_80_MCS0_9: |
| 8013 | case HE_80_MCS0_11: |
| 8014 | ret = sta_set_he_mcs(dut, intf, mcs_config); |
| 8015 | if (ret) { |
| 8016 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8017 | "cmd_set_max_he_mcs: Setting of MCS:%d failed, ret:%d", |
| 8018 | mcs_config, ret); |
| 8019 | } |
| 8020 | break; |
| 8021 | default: |
| 8022 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8023 | "cmd_set_max_he_mcs: Invalid mcs %d", |
| 8024 | mcs_config); |
| 8025 | break; |
| 8026 | } |
| 8027 | #else /* NL80211_SUPPORT */ |
| 8028 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8029 | "max HE MCS cannot be changed without NL80211_SUPPORT defined"); |
| 8030 | #endif /* NL80211_SUPPORT */ |
| 8031 | } |
| 8032 | |
| 8033 | |
Arif Hussain | 480d5f4 | 2019-03-12 14:40:42 -0700 | [diff] [blame] | 8034 | static int sta_twt_request(struct sigma_dut *dut, struct sigma_conn *conn, |
| 8035 | struct sigma_cmd *cmd) |
| 8036 | { |
| 8037 | #ifdef NL80211_SUPPORT |
| 8038 | struct nlattr *params; |
| 8039 | struct nlattr *attr; |
| 8040 | struct nlattr *attr1; |
| 8041 | struct nl_msg *msg; |
| 8042 | int ifindex, ret; |
| 8043 | const char *val; |
| 8044 | const char *intf = get_param(cmd, "Interface"); |
| 8045 | int wake_interval_exp = 10, nominal_min_wake_dur = 255, |
| 8046 | wake_interval_mantissa = 512; |
| 8047 | int flow_type = 0, twt_trigger = 0, target_wake_time = 0, |
| 8048 | protection = 0; |
| 8049 | |
| 8050 | ifindex = if_nametoindex(intf); |
| 8051 | if (ifindex == 0) { |
| 8052 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8053 | "%s: Index for interface %s failed", |
| 8054 | __func__, intf); |
| 8055 | return -1; |
| 8056 | } |
| 8057 | |
| 8058 | val = get_param(cmd, "FlowType"); |
| 8059 | if (val) { |
| 8060 | flow_type = atoi(val); |
| 8061 | if (flow_type != 0 && flow_type != 1) { |
| 8062 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8063 | "TWT: Invalid FlowType %d", flow_type); |
| 8064 | return -1; |
| 8065 | } |
| 8066 | } |
| 8067 | |
| 8068 | val = get_param(cmd, "TWT_Trigger"); |
| 8069 | if (val) { |
| 8070 | twt_trigger = atoi(val); |
| 8071 | if (twt_trigger != 0 && twt_trigger != 1) { |
| 8072 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8073 | "TWT: Invalid TWT_Trigger %d", |
| 8074 | twt_trigger); |
| 8075 | return -1; |
| 8076 | } |
| 8077 | } |
| 8078 | |
| 8079 | val = get_param(cmd, "Protection"); |
| 8080 | if (val) { |
| 8081 | protection = atoi(val); |
| 8082 | if (protection != 0 && protection != 1) { |
| 8083 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8084 | "TWT: Invalid Protection %d", |
| 8085 | protection); |
| 8086 | return -1; |
| 8087 | } |
| 8088 | } |
| 8089 | |
| 8090 | val = get_param(cmd, "TargetWakeTime"); |
| 8091 | if (val) |
| 8092 | target_wake_time = atoi(val); |
| 8093 | |
| 8094 | val = get_param(cmd, "WakeIntervalMantissa"); |
| 8095 | if (val) |
| 8096 | wake_interval_mantissa = atoi(val); |
| 8097 | |
| 8098 | val = get_param(cmd, "WakeIntervalExp"); |
| 8099 | if (val) |
| 8100 | wake_interval_exp = atoi(val); |
| 8101 | |
| 8102 | val = get_param(cmd, "NominalMinWakeDur"); |
| 8103 | if (val) |
| 8104 | nominal_min_wake_dur = atoi(val); |
| 8105 | |
| 8106 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 8107 | NL80211_CMD_VENDOR)) || |
| 8108 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 8109 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 8110 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 8111 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || |
| 8112 | !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 8113 | !(params = nla_nest_start( |
| 8114 | msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_TWT_SETUP)) || |
| 8115 | !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 8116 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_EXP, |
| 8117 | wake_interval_exp) || |
| 8118 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_BCAST, 0) || |
| 8119 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_REQ_TYPE, 1) || |
| 8120 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_TRIGGER, |
| 8121 | twt_trigger) || |
| 8122 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE, |
| 8123 | flow_type) || |
| 8124 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_PROTECTION, |
| 8125 | protection) || |
| 8126 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_TIME, |
| 8127 | target_wake_time) || |
| 8128 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_DURATION, |
| 8129 | nominal_min_wake_dur) || |
| 8130 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_MANTISSA, |
| 8131 | wake_interval_mantissa)) { |
| 8132 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8133 | "%s: err in adding vendor_cmd and vendor_data", |
| 8134 | __func__); |
| 8135 | nlmsg_free(msg); |
| 8136 | return -1; |
| 8137 | } |
| 8138 | nla_nest_end(msg, attr1); |
| 8139 | nla_nest_end(msg, params); |
| 8140 | nla_nest_end(msg, attr); |
| 8141 | |
| 8142 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 8143 | if (ret) { |
| 8144 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8145 | "%s: err in send_and_recv_msgs, ret=%d", |
| 8146 | __func__, ret); |
| 8147 | } |
| 8148 | |
| 8149 | return ret; |
| 8150 | #else /* NL80211_SUPPORT */ |
| 8151 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8152 | "TWT request cannot be done without NL80211_SUPPORT defined"); |
| 8153 | return -1; |
| 8154 | #endif /* NL80211_SUPPORT */ |
| 8155 | } |
| 8156 | |
| 8157 | |
| 8158 | static int sta_twt_teardown(struct sigma_dut *dut, struct sigma_conn *conn, |
| 8159 | struct sigma_cmd *cmd) |
| 8160 | { |
| 8161 | #ifdef NL80211_SUPPORT |
| 8162 | struct nlattr *params; |
| 8163 | struct nlattr *attr; |
| 8164 | struct nlattr *attr1; |
| 8165 | int ifindex, ret; |
| 8166 | struct nl_msg *msg; |
| 8167 | const char *intf = get_param(cmd, "Interface"); |
| 8168 | |
| 8169 | ifindex = if_nametoindex(intf); |
| 8170 | if (ifindex == 0) { |
| 8171 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8172 | "%s: Index for interface %s failed", |
| 8173 | __func__, intf); |
| 8174 | return -1; |
| 8175 | } |
| 8176 | |
| 8177 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 8178 | NL80211_CMD_VENDOR)) || |
| 8179 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 8180 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 8181 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 8182 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || |
| 8183 | !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 8184 | !(params = nla_nest_start( |
| 8185 | msg, |
| 8186 | QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_TWT_TERMINATE)) || |
| 8187 | !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 8188 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE, 0)) { |
| 8189 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8190 | "%s: err in adding vendor_cmd and vendor_data", |
| 8191 | __func__); |
| 8192 | nlmsg_free(msg); |
| 8193 | return -1; |
| 8194 | } |
| 8195 | nla_nest_end(msg, attr1); |
| 8196 | nla_nest_end(msg, params); |
| 8197 | nla_nest_end(msg, attr); |
| 8198 | |
| 8199 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 8200 | if (ret) { |
| 8201 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8202 | "%s: err in send_and_recv_msgs, ret=%d", |
| 8203 | __func__, ret); |
| 8204 | } |
| 8205 | |
| 8206 | return ret; |
| 8207 | #else /* NL80211_SUPPORT */ |
| 8208 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8209 | "TWT teardown cannot be done without NL80211_SUPPORT defined"); |
| 8210 | return -1; |
| 8211 | #endif /* NL80211_SUPPORT */ |
| 8212 | } |
| 8213 | |
| 8214 | |
Kiran Kumar Lokere | 50eb2cd | 2018-12-18 18:31:28 -0800 | [diff] [blame] | 8215 | static int sta_transmit_omi(struct sigma_dut *dut, struct sigma_conn *conn, |
| 8216 | struct sigma_cmd *cmd) |
| 8217 | { |
| 8218 | #ifdef NL80211_SUPPORT |
| 8219 | struct nlattr *params; |
| 8220 | struct nlattr *attr; |
| 8221 | struct nlattr *attr1; |
| 8222 | struct nl_msg *msg; |
| 8223 | int ifindex, ret; |
| 8224 | const char *val; |
| 8225 | const char *intf = get_param(cmd, "Interface"); |
| 8226 | uint8_t rx_nss = 0xFF, ch_bw = 0xFF, tx_nsts = 0xFF, ulmu_dis = 0, |
| 8227 | ulmu_data_dis = 0; |
| 8228 | |
| 8229 | ifindex = if_nametoindex(intf); |
| 8230 | if (ifindex == 0) { |
| 8231 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8232 | "%s: Index for interface %s failed", |
| 8233 | __func__, intf); |
| 8234 | return -1; |
| 8235 | } |
| 8236 | val = get_param(cmd, "OMCtrl_RxNSS"); |
| 8237 | if (val) |
| 8238 | rx_nss = atoi(val); |
| 8239 | |
| 8240 | val = get_param(cmd, "OMCtrl_ChnlWidth"); |
| 8241 | if (val) |
| 8242 | ch_bw = atoi(val); |
| 8243 | |
| 8244 | val = get_param(cmd, "OMCtrl_ULMUDisable"); |
| 8245 | if (val) |
| 8246 | ulmu_dis = atoi(val); |
| 8247 | |
| 8248 | val = get_param(cmd, "OMCtrl_TxNSTS"); |
| 8249 | if (val) |
| 8250 | tx_nsts = atoi(val); |
| 8251 | |
| 8252 | val = get_param(cmd, "OMCtrl_ULMUDataDisable"); |
| 8253 | if (val) |
| 8254 | ulmu_data_dis = atoi(val); |
| 8255 | |
| 8256 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 8257 | NL80211_CMD_VENDOR)) || |
| 8258 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 8259 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 8260 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 8261 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || |
| 8262 | !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 8263 | !(params = nla_nest_start( |
| 8264 | msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OMI_TX)) || |
| 8265 | !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 8266 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_RX_NSS, rx_nss) || |
| 8267 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_CH_BW, ch_bw) || |
| 8268 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_TX_NSTS, tx_nsts) || |
| 8269 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DATA_DISABLE, |
| 8270 | ulmu_data_dis) || |
| 8271 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DISABLE, |
| 8272 | ulmu_dis)) { |
| 8273 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8274 | "%s: err in adding vendor_cmd and vendor_data", |
| 8275 | __func__); |
| 8276 | nlmsg_free(msg); |
| 8277 | return -1; |
| 8278 | } |
| 8279 | nla_nest_end(msg, attr1); |
| 8280 | nla_nest_end(msg, params); |
| 8281 | nla_nest_end(msg, attr); |
| 8282 | |
| 8283 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 8284 | if (ret) { |
| 8285 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8286 | "%s: err in send_and_recv_msgs, ret=%d", |
| 8287 | __func__, ret); |
| 8288 | } |
| 8289 | |
| 8290 | return ret; |
| 8291 | #else /* NL80211_SUPPORT */ |
| 8292 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8293 | "OMI TX cannot be processed without NL80211_SUPPORT defined"); |
| 8294 | return -1; |
| 8295 | #endif /* NL80211_SUPPORT */ |
| 8296 | } |
| 8297 | |
| 8298 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8299 | static int cmd_sta_set_wireless_vht(struct sigma_dut *dut, |
| 8300 | struct sigma_conn *conn, |
| 8301 | struct sigma_cmd *cmd) |
| 8302 | { |
| 8303 | const char *intf = get_param(cmd, "Interface"); |
| 8304 | const char *val; |
Arif Hussain | a37e955 | 2018-06-20 17:05:59 -0700 | [diff] [blame] | 8305 | const char *program; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8306 | int tkip = -1; |
| 8307 | int wep = -1; |
| 8308 | |
Arif Hussain | a37e955 | 2018-06-20 17:05:59 -0700 | [diff] [blame] | 8309 | program = get_param(cmd, "Program"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8310 | val = get_param(cmd, "SGI80"); |
| 8311 | if (val) { |
| 8312 | int sgi80; |
| 8313 | |
| 8314 | sgi80 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0; |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 8315 | run_iwpriv(dut, intf, "shortgi %d", sgi80); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8316 | } |
| 8317 | |
| 8318 | val = get_param(cmd, "TxBF"); |
| 8319 | if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) { |
Kiran Kumar Lokere | cb57d82 | 2018-07-06 16:37:42 -0700 | [diff] [blame] | 8320 | switch (get_driver_type()) { |
| 8321 | case DRIVER_WCN: |
| 8322 | if (sta_set_tx_beamformee(dut, intf, 1)) { |
| 8323 | send_resp(dut, conn, SIGMA_ERROR, |
| 8324 | "ErrorCode,Failed to set TX beamformee enable"); |
| 8325 | return 0; |
| 8326 | } |
| 8327 | break; |
| 8328 | case DRIVER_ATHEROS: |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 8329 | if (run_iwpriv(dut, intf, "vhtsubfee 1") < 0) { |
Kiran Kumar Lokere | cb57d82 | 2018-07-06 16:37:42 -0700 | [diff] [blame] | 8330 | send_resp(dut, conn, SIGMA_ERROR, |
| 8331 | "ErrorCode,Setting vhtsubfee failed"); |
| 8332 | return 0; |
| 8333 | } |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 8334 | if (run_iwpriv(dut, intf, "vhtsubfer 1") < 0) { |
Kiran Kumar Lokere | cb57d82 | 2018-07-06 16:37:42 -0700 | [diff] [blame] | 8335 | send_resp(dut, conn, SIGMA_ERROR, |
| 8336 | "ErrorCode,Setting vhtsubfer failed"); |
| 8337 | return 0; |
| 8338 | } |
| 8339 | break; |
| 8340 | default: |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8341 | sigma_dut_print(dut, DUT_MSG_ERROR, |
Kiran Kumar Lokere | cb57d82 | 2018-07-06 16:37:42 -0700 | [diff] [blame] | 8342 | "Unsupported driver type"); |
| 8343 | break; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8344 | } |
| 8345 | } |
| 8346 | |
| 8347 | val = get_param(cmd, "MU_TxBF"); |
| 8348 | if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) { |
| 8349 | switch (get_driver_type()) { |
| 8350 | case DRIVER_ATHEROS: |
| 8351 | ath_sta_set_txsp_stream(dut, intf, "1SS"); |
| 8352 | ath_sta_set_rxsp_stream(dut, intf, "1SS"); |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 8353 | run_iwpriv(dut, intf, "vhtmubfee 1"); |
| 8354 | run_iwpriv(dut, intf, "vhtmubfer 1"); |
Sunil Dutt | ae9e5d1 | 2018-06-29 11:50:47 +0530 | [diff] [blame] | 8355 | break; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8356 | case DRIVER_WCN: |
| 8357 | if (wcn_sta_set_sp_stream(dut, intf, "1SS") < 0) { |
| 8358 | send_resp(dut, conn, SIGMA_ERROR, |
| 8359 | "ErrorCode,Failed to set RX/TXSP_STREAM"); |
| 8360 | return 0; |
| 8361 | } |
Sunil Dutt | ae9e5d1 | 2018-06-29 11:50:47 +0530 | [diff] [blame] | 8362 | break; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8363 | default: |
| 8364 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8365 | "Setting SP_STREAM not supported"); |
| 8366 | break; |
| 8367 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8368 | } |
| 8369 | |
| 8370 | val = get_param(cmd, "LDPC"); |
| 8371 | if (val) { |
| 8372 | int ldpc; |
| 8373 | |
| 8374 | ldpc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0; |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 8375 | run_iwpriv(dut, intf, "ldpc %d", ldpc); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8376 | } |
| 8377 | |
Amarnath Hullur Subramanyam | 7bae60e | 2018-01-31 03:46:50 -0800 | [diff] [blame] | 8378 | val = get_param(cmd, "BCC"); |
| 8379 | if (val) { |
| 8380 | int bcc; |
| 8381 | |
| 8382 | bcc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0; |
| 8383 | /* use LDPC iwpriv itself to set bcc coding, bcc coding |
| 8384 | * is mutually exclusive to bcc */ |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 8385 | run_iwpriv(dut, intf, "ldpc %d", !bcc); |
Amarnath Hullur Subramanyam | 7bae60e | 2018-01-31 03:46:50 -0800 | [diff] [blame] | 8386 | } |
| 8387 | |
Arif Hussain | 7b47d2d | 2018-05-09 10:44:02 -0700 | [diff] [blame] | 8388 | val = get_param(cmd, "MaxHE-MCS_1SS_RxMapLTE80"); |
| 8389 | if (val && dut->sta_nss == 1) |
| 8390 | cmd_set_max_he_mcs(dut, intf, atoi(val)); |
| 8391 | |
| 8392 | val = get_param(cmd, "MaxHE-MCS_2SS_RxMapLTE80"); |
| 8393 | if (val && dut->sta_nss == 2) |
| 8394 | cmd_set_max_he_mcs(dut, intf, atoi(val)); |
| 8395 | |
Arif Hussain | ac6c511 | 2018-05-25 17:34:00 -0700 | [diff] [blame] | 8396 | val = get_param(cmd, "MCS_FixedRate"); |
| 8397 | if (val) { |
| 8398 | #ifdef NL80211_SUPPORT |
| 8399 | int mcs, ratecode = 0; |
| 8400 | enum he_mcs_config mcs_config; |
| 8401 | int ret; |
Jouni Malinen | b9b671d | 2019-04-26 13:23:17 +0300 | [diff] [blame] | 8402 | char buf[60]; |
Arif Hussain | ac6c511 | 2018-05-25 17:34:00 -0700 | [diff] [blame] | 8403 | |
| 8404 | ratecode = (0x07 & dut->sta_nss) << 5; |
| 8405 | mcs = atoi(val); |
| 8406 | /* Add the MCS to the ratecode */ |
| 8407 | if (mcs >= 0 && mcs <= 11) { |
| 8408 | ratecode += mcs; |
| 8409 | if (dut->device_type == STA_testbed && |
| 8410 | mcs > 7 && mcs <= 11) { |
| 8411 | if (mcs <= 9) |
| 8412 | mcs_config = HE_80_MCS0_9; |
| 8413 | else |
| 8414 | mcs_config = HE_80_MCS0_11; |
| 8415 | ret = sta_set_he_mcs(dut, intf, mcs_config); |
| 8416 | if (ret) { |
| 8417 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8418 | "MCS_FixedRate: mcs setting failed, mcs:%d, mcs_config %d, ret:%d", |
| 8419 | mcs, mcs_config, ret); |
| 8420 | } |
| 8421 | } |
| 8422 | snprintf(buf, sizeof(buf), |
| 8423 | "iwpriv %s set_11ax_rate 0x%03x", |
| 8424 | intf, ratecode); |
| 8425 | if (system(buf) != 0) { |
| 8426 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8427 | "MCS_FixedRate: iwpriv setting of 11ax rates 0x%03x failed", |
| 8428 | ratecode); |
| 8429 | } |
| 8430 | } else { |
| 8431 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8432 | "MCS_FixedRate: HE MCS %d not supported", |
| 8433 | mcs); |
| 8434 | } |
| 8435 | #else /* NL80211_SUPPORT */ |
| 8436 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8437 | "MCS_FixedRate cannot be changed without NL80211_SUPPORT defined"); |
| 8438 | #endif /* NL80211_SUPPORT */ |
| 8439 | } |
| 8440 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8441 | val = get_param(cmd, "opt_md_notif_ie"); |
| 8442 | if (val) { |
| 8443 | char *result = NULL; |
| 8444 | char delim[] = ";"; |
| 8445 | char token[30]; |
| 8446 | int value, config_val = 0; |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 8447 | char *saveptr; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8448 | |
Peng Xu | b8fc5cc | 2017-05-10 17:27:28 -0700 | [diff] [blame] | 8449 | strlcpy(token, val, sizeof(token)); |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 8450 | result = strtok_r(token, delim, &saveptr); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8451 | |
| 8452 | /* Extract the NSS information */ |
| 8453 | if (result) { |
| 8454 | value = atoi(result); |
| 8455 | switch (value) { |
| 8456 | case 1: |
| 8457 | config_val = 1; |
| 8458 | break; |
| 8459 | case 2: |
| 8460 | config_val = 3; |
| 8461 | break; |
| 8462 | case 3: |
| 8463 | config_val = 7; |
| 8464 | break; |
| 8465 | case 4: |
| 8466 | config_val = 15; |
| 8467 | break; |
| 8468 | default: |
| 8469 | config_val = 3; |
| 8470 | break; |
| 8471 | } |
| 8472 | |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 8473 | run_iwpriv(dut, intf, "rxchainmask %d", config_val); |
| 8474 | run_iwpriv(dut, intf, "txchainmask %d", config_val); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8475 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8476 | } |
| 8477 | |
| 8478 | /* Extract the channel width information */ |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 8479 | result = strtok_r(NULL, delim, &saveptr); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8480 | if (result) { |
| 8481 | value = atoi(result); |
| 8482 | switch (value) { |
| 8483 | case 20: |
| 8484 | config_val = 0; |
| 8485 | break; |
| 8486 | case 40: |
| 8487 | config_val = 1; |
| 8488 | break; |
| 8489 | case 80: |
| 8490 | config_val = 2; |
| 8491 | break; |
| 8492 | case 160: |
| 8493 | config_val = 3; |
| 8494 | break; |
| 8495 | default: |
| 8496 | config_val = 2; |
| 8497 | break; |
| 8498 | } |
| 8499 | |
| 8500 | dut->chwidth = config_val; |
| 8501 | |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 8502 | run_iwpriv(dut, intf, "chwidth %d", config_val); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8503 | } |
| 8504 | |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 8505 | run_iwpriv(dut, intf, "opmode_notify 1"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8506 | } |
| 8507 | |
| 8508 | val = get_param(cmd, "nss_mcs_cap"); |
| 8509 | if (val) { |
| 8510 | int nss, mcs; |
| 8511 | char token[20]; |
| 8512 | char *result = NULL; |
| 8513 | unsigned int vht_mcsmap = 0; |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 8514 | char *saveptr; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8515 | |
Peng Xu | b8fc5cc | 2017-05-10 17:27:28 -0700 | [diff] [blame] | 8516 | strlcpy(token, val, sizeof(token)); |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 8517 | result = strtok_r(token, ";", &saveptr); |
Pradeep Reddy POTTETI | cd649a2 | 2016-01-29 12:55:59 +0530 | [diff] [blame] | 8518 | if (!result) { |
| 8519 | sigma_dut_print(dut, DUT_MSG_ERROR, |
Arif Hussain | a37e955 | 2018-06-20 17:05:59 -0700 | [diff] [blame] | 8520 | "NSS not specified"); |
| 8521 | send_resp(dut, conn, SIGMA_ERROR, |
| 8522 | "errorCode,NSS not specified"); |
Pradeep Reddy POTTETI | cd649a2 | 2016-01-29 12:55:59 +0530 | [diff] [blame] | 8523 | return 0; |
| 8524 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8525 | nss = atoi(result); |
| 8526 | |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 8527 | run_iwpriv(dut, intf, "nss %d", nss); |
Arif Hussain | ac6c511 | 2018-05-25 17:34:00 -0700 | [diff] [blame] | 8528 | dut->sta_nss = nss; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8529 | |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 8530 | result = strtok_r(NULL, ";", &saveptr); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8531 | if (result == NULL) { |
| 8532 | sigma_dut_print(dut, DUT_MSG_ERROR, |
Arif Hussain | a37e955 | 2018-06-20 17:05:59 -0700 | [diff] [blame] | 8533 | "MCS not specified"); |
| 8534 | send_resp(dut, conn, SIGMA_ERROR, |
| 8535 | "errorCode,MCS not specified"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8536 | return 0; |
| 8537 | } |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 8538 | result = strtok_r(result, "-", &saveptr); |
| 8539 | result = strtok_r(NULL, "-", &saveptr); |
Pradeep Reddy POTTETI | cd649a2 | 2016-01-29 12:55:59 +0530 | [diff] [blame] | 8540 | if (!result) { |
| 8541 | sigma_dut_print(dut, DUT_MSG_ERROR, |
Arif Hussain | a37e955 | 2018-06-20 17:05:59 -0700 | [diff] [blame] | 8542 | "MCS not specified"); |
| 8543 | send_resp(dut, conn, SIGMA_ERROR, |
| 8544 | "errorCode,MCS not specified"); |
Pradeep Reddy POTTETI | cd649a2 | 2016-01-29 12:55:59 +0530 | [diff] [blame] | 8545 | return 0; |
| 8546 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8547 | mcs = atoi(result); |
| 8548 | |
Arif Hussain | a37e955 | 2018-06-20 17:05:59 -0700 | [diff] [blame] | 8549 | if (program && strcasecmp(program, "HE") == 0) { |
| 8550 | #ifdef NL80211_SUPPORT |
| 8551 | enum he_mcs_config mcs_config; |
| 8552 | int ret; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8553 | |
Arif Hussain | a37e955 | 2018-06-20 17:05:59 -0700 | [diff] [blame] | 8554 | if (mcs >= 0 && mcs <= 7) { |
| 8555 | mcs_config = HE_80_MCS0_7; |
| 8556 | } else if (mcs > 7 && mcs <= 9) { |
| 8557 | mcs_config = HE_80_MCS0_9; |
| 8558 | } else if (mcs > 9 && mcs <= 11) { |
| 8559 | mcs_config = HE_80_MCS0_11; |
| 8560 | } else { |
| 8561 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8562 | "nss_mcs_cap: HE: Invalid mcs: %d", |
| 8563 | mcs); |
| 8564 | send_resp(dut, conn, SIGMA_ERROR, |
| 8565 | "errorCode,Invalid MCS"); |
| 8566 | return 0; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8567 | } |
Arif Hussain | a37e955 | 2018-06-20 17:05:59 -0700 | [diff] [blame] | 8568 | |
| 8569 | ret = sta_set_he_mcs(dut, intf, mcs_config); |
| 8570 | if (ret) { |
| 8571 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8572 | "nss_mcs_cap: HE: Setting of MCS failed, mcs_config: %d, ret: %d", |
| 8573 | mcs_config, ret); |
| 8574 | send_resp(dut, conn, SIGMA_ERROR, |
| 8575 | "errorCode,Failed to set MCS"); |
| 8576 | return 0; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8577 | } |
Arif Hussain | a37e955 | 2018-06-20 17:05:59 -0700 | [diff] [blame] | 8578 | #else /* NL80211_SUPPORT */ |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8579 | sigma_dut_print(dut, DUT_MSG_ERROR, |
Arif Hussain | a37e955 | 2018-06-20 17:05:59 -0700 | [diff] [blame] | 8580 | "nss_mcs_cap: HE: MCS cannot be changed without NL80211_SUPPORT defined"); |
| 8581 | #endif /* NL80211_SUPPORT */ |
| 8582 | } else { |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 8583 | run_iwpriv(dut, intf, "vhtmcs %d", mcs); |
Arif Hussain | a37e955 | 2018-06-20 17:05:59 -0700 | [diff] [blame] | 8584 | |
| 8585 | switch (nss) { |
| 8586 | case 1: |
| 8587 | switch (mcs) { |
| 8588 | case 7: |
| 8589 | vht_mcsmap = 0xfffc; |
| 8590 | break; |
| 8591 | case 8: |
| 8592 | vht_mcsmap = 0xfffd; |
| 8593 | break; |
| 8594 | case 9: |
| 8595 | vht_mcsmap = 0xfffe; |
| 8596 | break; |
| 8597 | default: |
| 8598 | vht_mcsmap = 0xfffe; |
| 8599 | break; |
| 8600 | } |
| 8601 | break; |
| 8602 | case 2: |
| 8603 | switch (mcs) { |
| 8604 | case 7: |
| 8605 | vht_mcsmap = 0xfff0; |
| 8606 | break; |
| 8607 | case 8: |
| 8608 | vht_mcsmap = 0xfff5; |
| 8609 | break; |
| 8610 | case 9: |
| 8611 | vht_mcsmap = 0xfffa; |
| 8612 | break; |
| 8613 | default: |
| 8614 | vht_mcsmap = 0xfffa; |
| 8615 | break; |
| 8616 | } |
| 8617 | break; |
| 8618 | case 3: |
| 8619 | switch (mcs) { |
| 8620 | case 7: |
| 8621 | vht_mcsmap = 0xffc0; |
| 8622 | break; |
| 8623 | case 8: |
| 8624 | vht_mcsmap = 0xffd5; |
| 8625 | break; |
| 8626 | case 9: |
| 8627 | vht_mcsmap = 0xffea; |
| 8628 | break; |
| 8629 | default: |
| 8630 | vht_mcsmap = 0xffea; |
| 8631 | break; |
| 8632 | } |
| 8633 | break; |
| 8634 | default: |
| 8635 | vht_mcsmap = 0xffea; |
| 8636 | break; |
| 8637 | } |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 8638 | run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8639 | } |
| 8640 | } |
| 8641 | |
| 8642 | /* UNSUPPORTED: val = get_param(cmd, "Tx_lgi_rate"); */ |
| 8643 | |
| 8644 | val = get_param(cmd, "Vht_tkip"); |
| 8645 | if (val) |
| 8646 | tkip = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0; |
| 8647 | |
| 8648 | val = get_param(cmd, "Vht_wep"); |
| 8649 | if (val) |
| 8650 | wep = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0; |
| 8651 | |
| 8652 | if (tkip != -1 || wep != -1) { |
| 8653 | if ((tkip == 1 && wep != 0) || (wep == 1 && tkip != 0)) { |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 8654 | run_iwpriv(dut, intf, "htweptkip 1"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8655 | } else if ((tkip == 0 && wep != 1) || (wep == 0 && tkip != 1)) { |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 8656 | run_iwpriv(dut, intf, "htweptkip 0"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8657 | } else { |
| 8658 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8659 | "ErrorCode,mixed mode of VHT TKIP/WEP not supported"); |
| 8660 | return 0; |
| 8661 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8662 | } |
| 8663 | |
Arif Hussain | 55f00da | 2018-07-03 08:28:26 -0700 | [diff] [blame] | 8664 | val = get_param(cmd, "txBandwidth"); |
| 8665 | if (val) { |
| 8666 | switch (get_driver_type()) { |
| 8667 | case DRIVER_WCN: |
| 8668 | if (wcn_sta_set_width(dut, intf, val) < 0) { |
| 8669 | send_resp(dut, conn, SIGMA_ERROR, |
| 8670 | "ErrorCode,Failed to set txBandwidth"); |
| 8671 | return 0; |
| 8672 | } |
| 8673 | break; |
| 8674 | case DRIVER_ATHEROS: |
| 8675 | if (ath_set_width(dut, conn, intf, val) < 0) { |
| 8676 | send_resp(dut, conn, SIGMA_ERROR, |
| 8677 | "ErrorCode,Failed to set txBandwidth"); |
| 8678 | return 0; |
| 8679 | } |
| 8680 | break; |
| 8681 | default: |
| 8682 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8683 | "Setting txBandwidth not supported"); |
| 8684 | break; |
| 8685 | } |
| 8686 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8687 | |
Arif Hussain | 9765f7d | 2018-07-03 08:28:26 -0700 | [diff] [blame] | 8688 | val = get_param(cmd, "BeamformeeSTS"); |
| 8689 | if (val) { |
Kiran Kumar Lokere | bc89d43 | 2018-07-10 12:20:13 -0700 | [diff] [blame] | 8690 | if (sta_set_tx_beamformee(dut, intf, 1)) { |
| 8691 | send_resp(dut, conn, SIGMA_ERROR, |
| 8692 | "ErrorCode,Failed to set TX beamformee enable"); |
| 8693 | return 0; |
| 8694 | } |
| 8695 | |
Arif Hussain | 9765f7d | 2018-07-03 08:28:26 -0700 | [diff] [blame] | 8696 | if (sta_set_beamformee_sts(dut, intf, atoi(val))) { |
| 8697 | send_resp(dut, conn, SIGMA_ERROR, |
| 8698 | "ErrorCode,Failed to set BeamformeeSTS"); |
| 8699 | return 0; |
| 8700 | } |
| 8701 | } |
| 8702 | |
Arif Hussain | 68d23f5 | 2018-07-11 13:39:08 -0700 | [diff] [blame] | 8703 | val = get_param(cmd, "Trig_MAC_Padding_Dur"); |
| 8704 | if (val) { |
Kiran Kumar Lokere | 55eb558 | 2018-08-19 20:03:26 -0700 | [diff] [blame] | 8705 | #ifdef NL80211_SUPPORT |
| 8706 | enum qca_wlan_he_mac_padding_dur set_val; |
| 8707 | |
| 8708 | switch (atoi(val)) { |
| 8709 | case 16: |
| 8710 | set_val = QCA_WLAN_HE_16US_OF_PROCESS_TIME; |
| 8711 | break; |
| 8712 | case 8: |
| 8713 | set_val = QCA_WLAN_HE_8US_OF_PROCESS_TIME; |
| 8714 | break; |
| 8715 | default: |
| 8716 | set_val = QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME; |
| 8717 | break; |
| 8718 | } |
| 8719 | if (sta_set_mac_padding_duration(dut, intf, set_val)) { |
Arif Hussain | 68d23f5 | 2018-07-11 13:39:08 -0700 | [diff] [blame] | 8720 | send_resp(dut, conn, SIGMA_ERROR, |
| 8721 | "ErrorCode,Failed to set MAC padding duration"); |
| 8722 | return 0; |
| 8723 | } |
Kiran Kumar Lokere | 55eb558 | 2018-08-19 20:03:26 -0700 | [diff] [blame] | 8724 | #else /* NL80211_SUPPORT */ |
| 8725 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8726 | "MAC padding duration cannot be changed without NL80211_SUPPORT defined"); |
| 8727 | #endif /* NL80211_SUPPORT */ |
Arif Hussain | 68d23f5 | 2018-07-11 13:39:08 -0700 | [diff] [blame] | 8728 | } |
| 8729 | |
Arif Hussain | 480d5f4 | 2019-03-12 14:40:42 -0700 | [diff] [blame] | 8730 | val = get_param(cmd, "TWT_ReqSupport"); |
| 8731 | if (val) { |
| 8732 | int set_val; |
| 8733 | |
| 8734 | if (strcasecmp(val, "Enable") == 0) { |
| 8735 | set_val = 1; |
| 8736 | } else if (strcasecmp(val, "Disable") == 0) { |
| 8737 | set_val = 0; |
| 8738 | } else { |
| 8739 | send_resp(dut, conn, SIGMA_ERROR, |
| 8740 | "ErrorCode,Invalid TWT_ReqSupport"); |
| 8741 | return STATUS_SENT; |
| 8742 | } |
| 8743 | |
| 8744 | if (sta_set_twt_req_support(dut, intf, set_val)) { |
| 8745 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8746 | "Failed to set TWT req support %d", |
| 8747 | set_val); |
| 8748 | send_resp(dut, conn, SIGMA_ERROR, |
| 8749 | "ErrorCode,Failed to set TWT_ReqSupport"); |
| 8750 | return STATUS_SENT; |
| 8751 | } |
| 8752 | } |
| 8753 | |
Kiran Kumar Lokere | b101268 | 2018-08-08 17:48:32 -0700 | [diff] [blame] | 8754 | val = get_param(cmd, "MU_EDCA"); |
| 8755 | if (val && (strcasecmp(val, "Override") == 0)) { |
| 8756 | if (sta_set_mu_edca_override(dut, intf, 1)) { |
| 8757 | send_resp(dut, conn, SIGMA_ERROR, |
| 8758 | "ErrorCode,Failed to set MU EDCA override"); |
| 8759 | return 0; |
| 8760 | } |
| 8761 | } |
Kiran Kumar Lokere | c658182 | 2018-08-01 16:18:34 -0700 | [diff] [blame] | 8762 | |
Kiran Kumar Lokere | de33e37 | 2018-08-29 16:26:24 -0700 | [diff] [blame] | 8763 | val = get_param(cmd, "OMControl"); |
| 8764 | if (val) { |
| 8765 | int set_val = 1; |
| 8766 | |
| 8767 | if (strcasecmp(val, "Enable") == 0) |
| 8768 | set_val = 1; |
| 8769 | else if (strcasecmp(val, "Disable") == 0) |
| 8770 | set_val = 0; |
| 8771 | |
| 8772 | if (sta_set_om_ctrl_supp(dut, intf, set_val)) { |
| 8773 | send_resp(dut, conn, SIGMA_ERROR, |
| 8774 | "ErrorCode,Failed to set OM ctrl supp"); |
| 8775 | return 0; |
| 8776 | } |
| 8777 | } |
| 8778 | |
Kiran Kumar Lokere | c658182 | 2018-08-01 16:18:34 -0700 | [diff] [blame] | 8779 | val = get_param(cmd, "ADDBAResp_BufSize"); |
| 8780 | if (val) { |
| 8781 | int buf_size; |
| 8782 | |
| 8783 | if (strcasecmp(val, "gt64") == 0) |
| 8784 | buf_size = 256; |
| 8785 | else |
| 8786 | buf_size = 64; |
| 8787 | if (get_driver_type() == DRIVER_WCN && |
| 8788 | sta_set_addba_buf_size(dut, intf, buf_size)) { |
| 8789 | send_resp(dut, conn, SIGMA_ERROR, |
| 8790 | "ErrorCode,set addbaresp_buff_size failed"); |
| 8791 | return 0; |
| 8792 | } |
| 8793 | } |
| 8794 | |
| 8795 | val = get_param(cmd, "ADDBAReq_BufSize"); |
| 8796 | if (val) { |
| 8797 | int buf_size; |
| 8798 | |
| 8799 | if (strcasecmp(val, "gt64") == 0) |
| 8800 | buf_size = 256; |
| 8801 | else |
| 8802 | buf_size = 64; |
| 8803 | if (get_driver_type() == DRIVER_WCN && |
| 8804 | sta_set_addba_buf_size(dut, intf, buf_size)) { |
| 8805 | send_resp(dut, conn, SIGMA_ERROR, |
| 8806 | "ErrorCode,set addbareq_buff_size failed"); |
| 8807 | return 0; |
| 8808 | } |
| 8809 | } |
| 8810 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8811 | return cmd_sta_set_wireless_common(intf, dut, conn, cmd); |
| 8812 | } |
| 8813 | |
| 8814 | |
| 8815 | static int sta_set_wireless_60g(struct sigma_dut *dut, |
| 8816 | struct sigma_conn *conn, |
| 8817 | struct sigma_cmd *cmd) |
| 8818 | { |
| 8819 | const char *dev_role = get_param(cmd, "DevRole"); |
| 8820 | |
| 8821 | if (!dev_role) { |
| 8822 | send_resp(dut, conn, SIGMA_INVALID, |
| 8823 | "ErrorCode,DevRole not specified"); |
| 8824 | return 0; |
| 8825 | } |
| 8826 | |
| 8827 | if (strcasecmp(dev_role, "PCP") == 0) |
| 8828 | return sta_set_60g_pcp(dut, conn, cmd); |
| 8829 | if (strcasecmp(dev_role, "STA") == 0) |
| 8830 | return sta_set_60g_sta(dut, conn, cmd); |
| 8831 | send_resp(dut, conn, SIGMA_INVALID, |
| 8832 | "ErrorCode,DevRole not supported"); |
| 8833 | return 0; |
| 8834 | } |
| 8835 | |
| 8836 | |
Ankita Bajaj | 0d5825b | 2017-10-25 16:20:17 +0530 | [diff] [blame] | 8837 | static int sta_set_wireless_oce(struct sigma_dut *dut, struct sigma_conn *conn, |
| 8838 | struct sigma_cmd *cmd) |
| 8839 | { |
| 8840 | int status; |
| 8841 | const char *intf = get_param(cmd, "Interface"); |
| 8842 | const char *val = get_param(cmd, "DevRole"); |
| 8843 | |
| 8844 | if (val && strcasecmp(val, "STA-CFON") == 0) { |
| 8845 | status = sta_cfon_set_wireless(dut, conn, cmd); |
| 8846 | if (status) |
| 8847 | return status; |
| 8848 | } |
| 8849 | return cmd_sta_set_wireless_common(intf, dut, conn, cmd); |
| 8850 | } |
| 8851 | |
| 8852 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 8853 | static enum sigma_cmd_result cmd_sta_set_wireless(struct sigma_dut *dut, |
| 8854 | struct sigma_conn *conn, |
| 8855 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8856 | { |
| 8857 | const char *val; |
| 8858 | |
| 8859 | val = get_param(cmd, "Program"); |
| 8860 | if (val) { |
| 8861 | if (strcasecmp(val, "11n") == 0) |
| 8862 | return cmd_sta_set_11n(dut, conn, cmd); |
Amarnath Hullur Subramanyam | 4f86029 | 2018-01-31 03:49:35 -0800 | [diff] [blame] | 8863 | if (strcasecmp(val, "VHT") == 0 || strcasecmp(val, "HE") == 0) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8864 | return cmd_sta_set_wireless_vht(dut, conn, cmd); |
| 8865 | if (strcasecmp(val, "60ghz") == 0) |
| 8866 | return sta_set_wireless_60g(dut, conn, cmd); |
Ankita Bajaj | 0d5825b | 2017-10-25 16:20:17 +0530 | [diff] [blame] | 8867 | if (strcasecmp(val, "OCE") == 0) |
| 8868 | return sta_set_wireless_oce(dut, conn, cmd); |
Alexei Avshalom Lazar | 66bb997 | 2018-12-18 16:01:43 +0200 | [diff] [blame] | 8869 | /* sta_set_wireless in WPS program is only used for 60G */ |
| 8870 | if (is_60g_sigma_dut(dut)) |
| 8871 | return sta_set_wireless_60g(dut, conn, cmd); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8872 | send_resp(dut, conn, SIGMA_ERROR, |
| 8873 | "ErrorCode,Program value not supported"); |
| 8874 | } else { |
| 8875 | send_resp(dut, conn, SIGMA_ERROR, |
| 8876 | "ErrorCode,Program argument not available"); |
| 8877 | } |
| 8878 | |
| 8879 | return 0; |
| 8880 | } |
| 8881 | |
| 8882 | |
| 8883 | static void ath_sta_inject_frame(struct sigma_dut *dut, const char *intf, |
| 8884 | int tid) |
| 8885 | { |
| 8886 | char buf[100]; |
| 8887 | int tid_to_dscp [] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 }; |
| 8888 | |
Pradeep Reddy POTTETI | d31d132 | 2016-10-13 17:22:03 +0530 | [diff] [blame] | 8889 | if (tid < 0 || |
| 8890 | tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) { |
| 8891 | sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid); |
| 8892 | return; |
| 8893 | } |
| 8894 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8895 | /* |
| 8896 | * Two ways to ensure that addba request with a |
| 8897 | * non zero TID could be sent out. EV 117296 |
| 8898 | */ |
| 8899 | snprintf(buf, sizeof(buf), |
| 8900 | "ping -c 8 -Q %d `arp -a | grep wlan0 | awk '{print $2}' | tr -d '()'`", |
| 8901 | tid); |
| 8902 | if (system(buf) != 0) { |
| 8903 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8904 | "Ping did not send out"); |
| 8905 | } |
| 8906 | |
| 8907 | snprintf(buf, sizeof(buf), |
| 8908 | "iwconfig %s | grep Access | awk '{print $6}' > %s", |
| 8909 | intf, VI_QOS_TMP_FILE); |
| 8910 | if (system(buf) != 0) |
| 8911 | return; |
| 8912 | |
| 8913 | snprintf(buf, sizeof(buf), |
| 8914 | "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s", |
| 8915 | intf, VI_QOS_TMP_FILE); |
| 8916 | if (system(buf) != 0) |
| 8917 | sigma_dut_print(dut, DUT_MSG_ERROR, "HWaddr matching failed"); |
| 8918 | |
| 8919 | snprintf(buf,sizeof(buf), "sed -n '3,$p' %s >> %s", |
| 8920 | VI_QOS_REFFILE, VI_QOS_TMP_FILE); |
| 8921 | if (system(buf) != 0) { |
| 8922 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8923 | "VI_QOS_TEMP_FILE generation error failed"); |
| 8924 | } |
| 8925 | snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s", |
| 8926 | tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE); |
| 8927 | if (system(buf) != 0) { |
| 8928 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8929 | "VI_QOS_FILE generation failed"); |
| 8930 | } |
| 8931 | |
| 8932 | snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s", |
| 8933 | tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE); |
| 8934 | if (system(buf) != 0) { |
| 8935 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8936 | "VI_QOS_FILE generation failed"); |
| 8937 | } |
| 8938 | |
| 8939 | snprintf(buf, sizeof(buf), "ethinject %s %s", intf, VI_QOS_FILE); |
| 8940 | if (system(buf) != 0) { |
| 8941 | } |
| 8942 | } |
| 8943 | |
| 8944 | |
| 8945 | static int ath_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn, |
| 8946 | struct sigma_cmd *cmd) |
| 8947 | { |
| 8948 | const char *intf = get_param(cmd, "Interface"); |
| 8949 | const char *val; |
| 8950 | int tid = 0; |
| 8951 | char buf[100]; |
| 8952 | |
| 8953 | val = get_param(cmd, "TID"); |
| 8954 | if (val) { |
| 8955 | tid = atoi(val); |
| 8956 | if (tid) |
| 8957 | ath_sta_inject_frame(dut, intf, tid); |
| 8958 | } |
| 8959 | |
| 8960 | /* Command sequence for ADDBA request on Peregrine based devices */ |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 8961 | run_iwpriv(dut, intf, "setaddbaoper 1"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8962 | |
| 8963 | snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4", intf, tid); |
| 8964 | if (system(buf) != 0) { |
| 8965 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8966 | "wifitool senddelba failed"); |
| 8967 | } |
| 8968 | |
| 8969 | snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64", intf, tid); |
| 8970 | if (system(buf) != 0) { |
| 8971 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8972 | "wifitool sendaddba failed"); |
| 8973 | } |
| 8974 | |
| 8975 | /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */ |
| 8976 | |
| 8977 | return 1; |
| 8978 | } |
| 8979 | |
| 8980 | |
Lior David | 9981b51 | 2017-01-20 13:16:40 +0200 | [diff] [blame] | 8981 | #ifdef __linux__ |
| 8982 | |
| 8983 | static int wil6210_send_addba(struct sigma_dut *dut, const char *dest_mac, |
| 8984 | int agg_size) |
| 8985 | { |
| 8986 | char dir[128], buf[128]; |
| 8987 | FILE *f; |
| 8988 | regex_t re; |
| 8989 | regmatch_t m[2]; |
Jouni Malinen | 3aa7286 | 2019-05-29 23:14:51 +0300 | [diff] [blame] | 8990 | int rc, ret = -1, vring_id, found, res; |
Lior David | 9981b51 | 2017-01-20 13:16:40 +0200 | [diff] [blame] | 8991 | |
| 8992 | if (wil6210_get_debugfs_dir(dut, dir, sizeof(dir))) { |
| 8993 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8994 | "failed to get wil6210 debugfs dir"); |
| 8995 | return -1; |
| 8996 | } |
| 8997 | |
Jouni Malinen | 3aa7286 | 2019-05-29 23:14:51 +0300 | [diff] [blame] | 8998 | res = snprintf(buf, sizeof(buf), "%s/vrings", dir); |
| 8999 | if (res < 0 || res >= sizeof(buf)) |
| 9000 | return -1; |
Lior David | 9981b51 | 2017-01-20 13:16:40 +0200 | [diff] [blame] | 9001 | f = fopen(buf, "r"); |
| 9002 | if (!f) { |
| 9003 | sigma_dut_print(dut, DUT_MSG_ERROR, "failed to open: %s", buf); |
Alexei Avshalom Lazar | 2af1d25 | 2018-11-13 14:10:13 +0200 | [diff] [blame] | 9004 | /* newer wil6210 driver renamed file to "rings" */ |
Jouni Malinen | 3aa7286 | 2019-05-29 23:14:51 +0300 | [diff] [blame] | 9005 | res = snprintf(buf, sizeof(buf), "%s/rings", dir); |
| 9006 | if (res < 0 || res >= sizeof(buf)) |
| 9007 | return -1; |
Alexei Avshalom Lazar | 2af1d25 | 2018-11-13 14:10:13 +0200 | [diff] [blame] | 9008 | f = fopen(buf, "r"); |
| 9009 | if (!f) { |
| 9010 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 9011 | "failed to open: %s", buf); |
| 9012 | return -1; |
| 9013 | } |
Lior David | 9981b51 | 2017-01-20 13:16:40 +0200 | [diff] [blame] | 9014 | } |
| 9015 | |
Alexei Avshalom Lazar | 2af1d25 | 2018-11-13 14:10:13 +0200 | [diff] [blame] | 9016 | /* can be either VRING tx... or RING... */ |
| 9017 | if (regcomp(&re, "RING tx_[ \t]*([0-9]+)", REG_EXTENDED)) { |
Lior David | 9981b51 | 2017-01-20 13:16:40 +0200 | [diff] [blame] | 9018 | sigma_dut_print(dut, DUT_MSG_ERROR, "regcomp failed"); |
| 9019 | goto out; |
| 9020 | } |
| 9021 | |
| 9022 | /* find TX VRING for the mac address */ |
| 9023 | found = 0; |
| 9024 | while (fgets(buf, sizeof(buf), f)) { |
| 9025 | if (strcasestr(buf, dest_mac)) { |
| 9026 | found = 1; |
| 9027 | break; |
| 9028 | } |
| 9029 | } |
| 9030 | |
| 9031 | if (!found) { |
| 9032 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 9033 | "no TX VRING for %s", dest_mac); |
| 9034 | goto out; |
| 9035 | } |
| 9036 | |
| 9037 | /* extract VRING ID, "VRING tx_<id> = {" */ |
| 9038 | if (!fgets(buf, sizeof(buf), f)) { |
| 9039 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 9040 | "no VRING start line for %s", dest_mac); |
| 9041 | goto out; |
| 9042 | } |
| 9043 | |
| 9044 | rc = regexec(&re, buf, 2, m, 0); |
| 9045 | regfree(&re); |
| 9046 | if (rc || m[1].rm_so < 0) { |
| 9047 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 9048 | "no VRING TX ID for %s", dest_mac); |
| 9049 | goto out; |
| 9050 | } |
| 9051 | buf[m[1].rm_eo] = 0; |
| 9052 | vring_id = atoi(&buf[m[1].rm_so]); |
| 9053 | |
| 9054 | /* send the addba command */ |
| 9055 | fclose(f); |
Jouni Malinen | 3aa7286 | 2019-05-29 23:14:51 +0300 | [diff] [blame] | 9056 | res = snprintf(buf, sizeof(buf), "%s/back", dir); |
| 9057 | if (res < 0 || res >= sizeof(buf)) |
| 9058 | return -1; |
Lior David | 9981b51 | 2017-01-20 13:16:40 +0200 | [diff] [blame] | 9059 | f = fopen(buf, "w"); |
| 9060 | if (!f) { |
| 9061 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 9062 | "failed to open: %s", buf); |
| 9063 | return -1; |
| 9064 | } |
| 9065 | |
| 9066 | fprintf(f, "add %d %d\n", vring_id, agg_size); |
| 9067 | |
| 9068 | ret = 0; |
| 9069 | |
| 9070 | out: |
| 9071 | fclose(f); |
| 9072 | |
| 9073 | return ret; |
| 9074 | } |
| 9075 | |
| 9076 | |
Alexei Avshalom Lazar | 79fa3fe | 2018-12-24 15:43:33 +0200 | [diff] [blame] | 9077 | int send_addba_60g(struct sigma_dut *dut, struct sigma_conn *conn, |
| 9078 | struct sigma_cmd *cmd, const char *mac_param) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 9079 | { |
| 9080 | const char *val; |
| 9081 | int tid = 0; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 9082 | |
| 9083 | val = get_param(cmd, "TID"); |
| 9084 | if (val) { |
| 9085 | tid = atoi(val); |
| 9086 | if (tid != 0) { |
| 9087 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 9088 | "Ignore TID %d for send_addba use TID 0 for 60g since only 0 required on TX", |
| 9089 | tid); |
| 9090 | } |
| 9091 | } |
| 9092 | |
Alexei Avshalom Lazar | 79fa3fe | 2018-12-24 15:43:33 +0200 | [diff] [blame] | 9093 | val = get_param(cmd, mac_param); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 9094 | if (!val) { |
| 9095 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 9096 | "Currently not supporting addba for 60G without Dest_mac"); |
Jouni Malinen | 0e29cf2 | 2019-02-19 01:13:21 +0200 | [diff] [blame] | 9097 | return ERROR_SEND_STATUS; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 9098 | } |
| 9099 | |
Lior David | 9981b51 | 2017-01-20 13:16:40 +0200 | [diff] [blame] | 9100 | if (wil6210_send_addba(dut, val, dut->back_rcv_buf)) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 9101 | return -1; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 9102 | |
| 9103 | return 1; |
| 9104 | } |
| 9105 | |
Lior David | 9981b51 | 2017-01-20 13:16:40 +0200 | [diff] [blame] | 9106 | #endif /* __linux__ */ |
| 9107 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 9108 | |
Amarnath Hullur Subramanyam | a72c016 | 2018-02-27 14:49:09 -0800 | [diff] [blame] | 9109 | static int wcn_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn, |
| 9110 | struct sigma_cmd *cmd) |
| 9111 | { |
| 9112 | #ifdef NL80211_SUPPORT |
| 9113 | const char *intf = get_param(cmd, "Interface"); |
| 9114 | const char *val; |
| 9115 | int tid = -1; |
| 9116 | int bufsize = 64; |
| 9117 | struct nl_msg *msg; |
| 9118 | int ret = 0; |
| 9119 | struct nlattr *params; |
| 9120 | int ifindex; |
| 9121 | |
| 9122 | val = get_param(cmd, "TID"); |
| 9123 | if (val) |
| 9124 | tid = atoi(val); |
| 9125 | |
| 9126 | if (tid == -1) { |
| 9127 | send_resp(dut, conn, SIGMA_ERROR, |
| 9128 | "ErrorCode,sta_send_addba tid invalid"); |
| 9129 | return 0; |
| 9130 | } |
| 9131 | |
| 9132 | /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */ |
| 9133 | |
| 9134 | ifindex = if_nametoindex(intf); |
| 9135 | if (ifindex == 0) { |
| 9136 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 9137 | "%s: Index for interface %s failed", |
| 9138 | __func__, intf); |
| 9139 | send_resp(dut, conn, SIGMA_ERROR, |
| 9140 | "ErrorCode,sta_send_addba interface invalid"); |
| 9141 | return 0; |
| 9142 | } |
| 9143 | |
| 9144 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 9145 | NL80211_CMD_VENDOR)) || |
| 9146 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 9147 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 9148 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 9149 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || |
| 9150 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 9151 | nla_put_u8(msg, |
| 9152 | QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADD_DEL_BA_SESSION, |
| 9153 | QCA_WLAN_ADD_BA) || |
| 9154 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BA_TID, |
| 9155 | tid) || |
Kiran Kumar Lokere | 26e2758 | 2018-08-01 16:18:34 -0700 | [diff] [blame] | 9156 | nla_put_u16(msg, |
| 9157 | QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE, |
| 9158 | bufsize)) { |
Amarnath Hullur Subramanyam | a72c016 | 2018-02-27 14:49:09 -0800 | [diff] [blame] | 9159 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 9160 | "%s: err in adding vendor_cmd and vendor_data", |
| 9161 | __func__); |
| 9162 | nlmsg_free(msg); |
| 9163 | send_resp(dut, conn, SIGMA_ERROR, |
| 9164 | "ErrorCode,sta_send_addba err in adding vendor_cmd and vendor_data"); |
| 9165 | return 0; |
| 9166 | } |
| 9167 | nla_nest_end(msg, params); |
| 9168 | |
| 9169 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 9170 | if (ret) { |
| 9171 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 9172 | "%s: err in send_and_recv_msgs, ret=%d", |
| 9173 | __func__, ret); |
Sunil Dutt | 3060559 | 2018-05-04 20:35:50 +0530 | [diff] [blame] | 9174 | if (ret == -EOPNOTSUPP) |
| 9175 | return 1; |
Amarnath Hullur Subramanyam | a72c016 | 2018-02-27 14:49:09 -0800 | [diff] [blame] | 9176 | send_resp(dut, conn, SIGMA_ERROR, |
| 9177 | "ErrorCode,sta_send_addba err in send_and_recv_msgs"); |
| 9178 | return 0; |
| 9179 | } |
Amarnath Hullur Subramanyam | a72c016 | 2018-02-27 14:49:09 -0800 | [diff] [blame] | 9180 | #else /* NL80211_SUPPORT */ |
| 9181 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 9182 | "sta_send_addba not supported without NL80211_SUPPORT defined"); |
Amarnath Hullur Subramanyam | a72c016 | 2018-02-27 14:49:09 -0800 | [diff] [blame] | 9183 | #endif /* NL80211_SUPPORT */ |
Sunil Dutt | 3060559 | 2018-05-04 20:35:50 +0530 | [diff] [blame] | 9184 | |
| 9185 | return 1; |
Amarnath Hullur Subramanyam | a72c016 | 2018-02-27 14:49:09 -0800 | [diff] [blame] | 9186 | } |
| 9187 | |
| 9188 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 9189 | static enum sigma_cmd_result cmd_sta_send_addba(struct sigma_dut *dut, |
| 9190 | struct sigma_conn *conn, |
| 9191 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 9192 | { |
| 9193 | switch (get_driver_type()) { |
| 9194 | case DRIVER_ATHEROS: |
| 9195 | return ath_sta_send_addba(dut, conn, cmd); |
Amarnath Hullur Subramanyam | a72c016 | 2018-02-27 14:49:09 -0800 | [diff] [blame] | 9196 | case DRIVER_WCN: |
| 9197 | return wcn_sta_send_addba(dut, conn, cmd); |
Lior David | 9981b51 | 2017-01-20 13:16:40 +0200 | [diff] [blame] | 9198 | #ifdef __linux__ |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 9199 | case DRIVER_WIL6210: |
Alexei Avshalom Lazar | 79fa3fe | 2018-12-24 15:43:33 +0200 | [diff] [blame] | 9200 | return send_addba_60g(dut, conn, cmd, "Dest_mac"); |
Lior David | 9981b51 | 2017-01-20 13:16:40 +0200 | [diff] [blame] | 9201 | #endif /* __linux__ */ |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 9202 | default: |
| 9203 | /* |
| 9204 | * There is no driver specific implementation for other drivers. |
| 9205 | * Ignore the command and report COMPLETE since the following |
| 9206 | * throughput test operation will end up sending ADDBA anyway. |
| 9207 | */ |
| 9208 | return 1; |
| 9209 | } |
| 9210 | } |
| 9211 | |
| 9212 | |
| 9213 | int inject_eth_frame(int s, const void *data, size_t len, |
| 9214 | unsigned short ethtype, char *dst, char *src) |
| 9215 | { |
| 9216 | struct iovec iov[4] = { |
| 9217 | { |
| 9218 | .iov_base = dst, |
| 9219 | .iov_len = ETH_ALEN, |
| 9220 | }, |
| 9221 | { |
| 9222 | .iov_base = src, |
| 9223 | .iov_len = ETH_ALEN, |
| 9224 | }, |
| 9225 | { |
| 9226 | .iov_base = ðtype, |
| 9227 | .iov_len = sizeof(unsigned short), |
| 9228 | }, |
| 9229 | { |
| 9230 | .iov_base = (void *) data, |
| 9231 | .iov_len = len, |
| 9232 | } |
| 9233 | }; |
| 9234 | struct msghdr msg = { |
| 9235 | .msg_name = NULL, |
| 9236 | .msg_namelen = 0, |
| 9237 | .msg_iov = iov, |
| 9238 | .msg_iovlen = 4, |
| 9239 | .msg_control = NULL, |
| 9240 | .msg_controllen = 0, |
| 9241 | .msg_flags = 0, |
| 9242 | }; |
| 9243 | |
| 9244 | return sendmsg(s, &msg, 0); |
| 9245 | } |
| 9246 | |
| 9247 | #if defined(__linux__) || defined(__QNXNTO__) |
| 9248 | |
| 9249 | int inject_frame(int s, const void *data, size_t len, int encrypt) |
| 9250 | { |
| 9251 | #define IEEE80211_RADIOTAP_F_WEP 0x04 |
| 9252 | #define IEEE80211_RADIOTAP_F_FRAG 0x08 |
| 9253 | unsigned char rtap_hdr[] = { |
| 9254 | 0x00, 0x00, /* radiotap version */ |
| 9255 | 0x0e, 0x00, /* radiotap length */ |
| 9256 | 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */ |
| 9257 | IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */ |
| 9258 | 0x00, /* padding */ |
| 9259 | 0x00, 0x00, /* RX and TX flags to indicate that */ |
| 9260 | 0x00, 0x00, /* this is the injected frame directly */ |
| 9261 | }; |
| 9262 | struct iovec iov[2] = { |
| 9263 | { |
| 9264 | .iov_base = &rtap_hdr, |
| 9265 | .iov_len = sizeof(rtap_hdr), |
| 9266 | }, |
| 9267 | { |
| 9268 | .iov_base = (void *) data, |
| 9269 | .iov_len = len, |
| 9270 | } |
| 9271 | }; |
| 9272 | struct msghdr msg = { |
| 9273 | .msg_name = NULL, |
| 9274 | .msg_namelen = 0, |
| 9275 | .msg_iov = iov, |
| 9276 | .msg_iovlen = 2, |
| 9277 | .msg_control = NULL, |
| 9278 | .msg_controllen = 0, |
| 9279 | .msg_flags = 0, |
| 9280 | }; |
| 9281 | |
| 9282 | if (encrypt) |
| 9283 | rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP; |
| 9284 | |
| 9285 | return sendmsg(s, &msg, 0); |
| 9286 | } |
| 9287 | |
| 9288 | |
| 9289 | int open_monitor(const char *ifname) |
| 9290 | { |
| 9291 | #ifdef __QNXNTO__ |
| 9292 | struct sockaddr_dl ll; |
| 9293 | int s; |
| 9294 | |
| 9295 | memset(&ll, 0, sizeof(ll)); |
| 9296 | ll.sdl_family = AF_LINK; |
| 9297 | ll.sdl_index = if_nametoindex(ifname); |
| 9298 | if (ll.sdl_index == 0) { |
| 9299 | perror("if_nametoindex"); |
| 9300 | return -1; |
| 9301 | } |
| 9302 | s = socket(PF_INET, SOCK_RAW, 0); |
| 9303 | #else /* __QNXNTO__ */ |
| 9304 | struct sockaddr_ll ll; |
| 9305 | int s; |
| 9306 | |
| 9307 | memset(&ll, 0, sizeof(ll)); |
| 9308 | ll.sll_family = AF_PACKET; |
| 9309 | ll.sll_ifindex = if_nametoindex(ifname); |
| 9310 | if (ll.sll_ifindex == 0) { |
| 9311 | perror("if_nametoindex"); |
| 9312 | return -1; |
| 9313 | } |
| 9314 | s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); |
| 9315 | #endif /* __QNXNTO__ */ |
| 9316 | if (s < 0) { |
| 9317 | perror("socket[PF_PACKET,SOCK_RAW]"); |
| 9318 | return -1; |
| 9319 | } |
| 9320 | |
| 9321 | if (bind(s, (struct sockaddr *) &ll, sizeof(ll)) < 0) { |
| 9322 | perror("monitor socket bind"); |
| 9323 | close(s); |
| 9324 | return -1; |
| 9325 | } |
| 9326 | |
| 9327 | return s; |
| 9328 | } |
| 9329 | |
| 9330 | |
| 9331 | static int hex2num(char c) |
| 9332 | { |
| 9333 | if (c >= '0' && c <= '9') |
| 9334 | return c - '0'; |
| 9335 | if (c >= 'a' && c <= 'f') |
| 9336 | return c - 'a' + 10; |
| 9337 | if (c >= 'A' && c <= 'F') |
| 9338 | return c - 'A' + 10; |
| 9339 | return -1; |
| 9340 | } |
| 9341 | |
| 9342 | |
| 9343 | int hwaddr_aton(const char *txt, unsigned char *addr) |
| 9344 | { |
| 9345 | int i; |
| 9346 | |
| 9347 | for (i = 0; i < 6; i++) { |
| 9348 | int a, b; |
| 9349 | |
| 9350 | a = hex2num(*txt++); |
| 9351 | if (a < 0) |
| 9352 | return -1; |
| 9353 | b = hex2num(*txt++); |
| 9354 | if (b < 0) |
| 9355 | return -1; |
| 9356 | *addr++ = (a << 4) | b; |
| 9357 | if (i < 5 && *txt++ != ':') |
| 9358 | return -1; |
| 9359 | } |
| 9360 | |
| 9361 | return 0; |
| 9362 | } |
| 9363 | |
| 9364 | #endif /* defined(__linux__) || defined(__QNXNTO__) */ |
| 9365 | |
| 9366 | enum send_frame_type { |
| 9367 | DISASSOC, DEAUTH, SAQUERY, AUTH, ASSOCREQ, REASSOCREQ, DLS_REQ |
| 9368 | }; |
| 9369 | enum send_frame_protection { |
| 9370 | CORRECT_KEY, INCORRECT_KEY, UNPROTECTED |
| 9371 | }; |
| 9372 | |
| 9373 | |
| 9374 | static int sta_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn, |
| 9375 | enum send_frame_type frame, |
| 9376 | enum send_frame_protection protected, |
| 9377 | const char *dest) |
| 9378 | { |
| 9379 | #ifdef __linux__ |
| 9380 | unsigned char buf[1000], *pos; |
| 9381 | int s, res; |
| 9382 | char bssid[20], addr[20]; |
| 9383 | char result[32], ssid[100]; |
| 9384 | size_t ssid_len; |
| 9385 | |
| 9386 | if (get_wpa_status(get_station_ifname(), "wpa_state", result, |
| 9387 | sizeof(result)) < 0 || |
| 9388 | strncmp(result, "COMPLETED", 9) != 0) { |
| 9389 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Not connected"); |
| 9390 | return 0; |
| 9391 | } |
| 9392 | |
| 9393 | if (get_wpa_status(get_station_ifname(), "bssid", bssid, sizeof(bssid)) |
| 9394 | < 0) { |
| 9395 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get " |
| 9396 | "current BSSID"); |
| 9397 | return 0; |
| 9398 | } |
| 9399 | |
| 9400 | if (get_wpa_status(get_station_ifname(), "address", addr, sizeof(addr)) |
| 9401 | < 0) { |
| 9402 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get " |
| 9403 | "own MAC address"); |
| 9404 | return 0; |
| 9405 | } |
| 9406 | |
| 9407 | if (get_wpa_status(get_station_ifname(), "ssid", ssid, sizeof(ssid)) |
| 9408 | < 0) { |
| 9409 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get " |
| 9410 | "current SSID"); |
| 9411 | return 0; |
| 9412 | } |
| 9413 | ssid_len = strlen(ssid); |
| 9414 | |
| 9415 | pos = buf; |
| 9416 | |
| 9417 | /* Frame Control */ |
| 9418 | switch (frame) { |
| 9419 | case DISASSOC: |
| 9420 | *pos++ = 0xa0; |
| 9421 | break; |
| 9422 | case DEAUTH: |
| 9423 | *pos++ = 0xc0; |
| 9424 | break; |
| 9425 | case SAQUERY: |
| 9426 | *pos++ = 0xd0; |
| 9427 | break; |
| 9428 | case AUTH: |
| 9429 | *pos++ = 0xb0; |
| 9430 | break; |
| 9431 | case ASSOCREQ: |
| 9432 | *pos++ = 0x00; |
| 9433 | break; |
| 9434 | case REASSOCREQ: |
| 9435 | *pos++ = 0x20; |
| 9436 | break; |
| 9437 | case DLS_REQ: |
| 9438 | *pos++ = 0xd0; |
| 9439 | break; |
| 9440 | } |
| 9441 | |
| 9442 | if (protected == INCORRECT_KEY) |
| 9443 | *pos++ = 0x40; /* Set Protected field to 1 */ |
| 9444 | else |
| 9445 | *pos++ = 0x00; |
| 9446 | |
| 9447 | /* Duration */ |
| 9448 | *pos++ = 0x00; |
| 9449 | *pos++ = 0x00; |
| 9450 | |
| 9451 | /* addr1 = DA (current AP) */ |
| 9452 | hwaddr_aton(bssid, pos); |
| 9453 | pos += 6; |
| 9454 | /* addr2 = SA (own address) */ |
| 9455 | hwaddr_aton(addr, pos); |
| 9456 | pos += 6; |
| 9457 | /* addr3 = BSSID (current AP) */ |
| 9458 | hwaddr_aton(bssid, pos); |
| 9459 | pos += 6; |
| 9460 | |
| 9461 | /* Seq# (to be filled by driver/mac80211) */ |
| 9462 | *pos++ = 0x00; |
| 9463 | *pos++ = 0x00; |
| 9464 | |
| 9465 | if (protected == INCORRECT_KEY) { |
| 9466 | /* CCMP parameters */ |
| 9467 | memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8); |
| 9468 | pos += 8; |
| 9469 | } |
| 9470 | |
| 9471 | if (protected == INCORRECT_KEY) { |
| 9472 | switch (frame) { |
| 9473 | case DEAUTH: |
| 9474 | /* Reason code (encrypted) */ |
| 9475 | memcpy(pos, "\xa7\x39", 2); |
| 9476 | pos += 2; |
| 9477 | break; |
| 9478 | case DISASSOC: |
| 9479 | /* Reason code (encrypted) */ |
| 9480 | memcpy(pos, "\xa7\x39", 2); |
| 9481 | pos += 2; |
| 9482 | break; |
| 9483 | case SAQUERY: |
| 9484 | /* Category|Action|TransID (encrypted) */ |
| 9485 | memcpy(pos, "\x6f\xbd\xe9\x4d", 4); |
| 9486 | pos += 4; |
| 9487 | break; |
| 9488 | default: |
| 9489 | return -1; |
| 9490 | } |
| 9491 | |
| 9492 | /* CCMP MIC */ |
| 9493 | memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8); |
| 9494 | pos += 8; |
| 9495 | } else { |
| 9496 | switch (frame) { |
| 9497 | case DEAUTH: |
| 9498 | /* reason code = 8 */ |
| 9499 | *pos++ = 0x08; |
| 9500 | *pos++ = 0x00; |
| 9501 | break; |
| 9502 | case DISASSOC: |
| 9503 | /* reason code = 8 */ |
| 9504 | *pos++ = 0x08; |
| 9505 | *pos++ = 0x00; |
| 9506 | break; |
| 9507 | case SAQUERY: |
| 9508 | /* Category - SA Query */ |
| 9509 | *pos++ = 0x08; |
| 9510 | /* SA query Action - Request */ |
| 9511 | *pos++ = 0x00; |
| 9512 | /* Transaction ID */ |
| 9513 | *pos++ = 0x12; |
| 9514 | *pos++ = 0x34; |
| 9515 | break; |
| 9516 | case AUTH: |
| 9517 | /* Auth Alg (Open) */ |
| 9518 | *pos++ = 0x00; |
| 9519 | *pos++ = 0x00; |
| 9520 | /* Seq# */ |
| 9521 | *pos++ = 0x01; |
| 9522 | *pos++ = 0x00; |
| 9523 | /* Status code */ |
| 9524 | *pos++ = 0x00; |
| 9525 | *pos++ = 0x00; |
| 9526 | break; |
| 9527 | case ASSOCREQ: |
| 9528 | /* Capability Information */ |
| 9529 | *pos++ = 0x31; |
| 9530 | *pos++ = 0x04; |
| 9531 | /* Listen Interval */ |
| 9532 | *pos++ = 0x0a; |
| 9533 | *pos++ = 0x00; |
| 9534 | /* SSID */ |
| 9535 | *pos++ = 0x00; |
| 9536 | *pos++ = ssid_len; |
| 9537 | memcpy(pos, ssid, ssid_len); |
| 9538 | pos += ssid_len; |
| 9539 | /* Supported Rates */ |
| 9540 | memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24", |
| 9541 | 10); |
| 9542 | pos += 10; |
| 9543 | /* Extended Supported Rates */ |
| 9544 | memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6); |
| 9545 | pos += 6; |
| 9546 | /* RSN */ |
| 9547 | memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00" |
| 9548 | "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0" |
| 9549 | "\x00\x00\x00\x00\x0f\xac\x06", 28); |
| 9550 | pos += 28; |
| 9551 | break; |
| 9552 | case REASSOCREQ: |
| 9553 | /* Capability Information */ |
| 9554 | *pos++ = 0x31; |
| 9555 | *pos++ = 0x04; |
| 9556 | /* Listen Interval */ |
| 9557 | *pos++ = 0x0a; |
| 9558 | *pos++ = 0x00; |
| 9559 | /* Current AP */ |
| 9560 | hwaddr_aton(bssid, pos); |
| 9561 | pos += 6; |
| 9562 | /* SSID */ |
| 9563 | *pos++ = 0x00; |
| 9564 | *pos++ = ssid_len; |
| 9565 | memcpy(pos, ssid, ssid_len); |
| 9566 | pos += ssid_len; |
| 9567 | /* Supported Rates */ |
| 9568 | memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24", |
| 9569 | 10); |
| 9570 | pos += 10; |
| 9571 | /* Extended Supported Rates */ |
| 9572 | memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6); |
| 9573 | pos += 6; |
| 9574 | /* RSN */ |
| 9575 | memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00" |
| 9576 | "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0" |
| 9577 | "\x00\x00\x00\x00\x0f\xac\x06", 28); |
| 9578 | pos += 28; |
| 9579 | break; |
| 9580 | case DLS_REQ: |
| 9581 | /* Category - DLS */ |
| 9582 | *pos++ = 0x02; |
| 9583 | /* DLS Action - Request */ |
| 9584 | *pos++ = 0x00; |
| 9585 | /* Destination MACAddress */ |
| 9586 | if (dest) |
| 9587 | hwaddr_aton(dest, pos); |
| 9588 | else |
| 9589 | memset(pos, 0, 6); |
| 9590 | pos += 6; |
| 9591 | /* Source MACAddress */ |
| 9592 | hwaddr_aton(addr, pos); |
| 9593 | pos += 6; |
| 9594 | /* Capability Information */ |
| 9595 | *pos++ = 0x10; /* Privacy */ |
| 9596 | *pos++ = 0x06; /* QoS */ |
| 9597 | /* DLS Timeout Value */ |
| 9598 | *pos++ = 0x00; |
| 9599 | *pos++ = 0x01; |
| 9600 | /* Supported rates */ |
| 9601 | *pos++ = 0x01; |
| 9602 | *pos++ = 0x08; |
| 9603 | *pos++ = 0x0c; /* 6 Mbps */ |
| 9604 | *pos++ = 0x12; /* 9 Mbps */ |
| 9605 | *pos++ = 0x18; /* 12 Mbps */ |
| 9606 | *pos++ = 0x24; /* 18 Mbps */ |
| 9607 | *pos++ = 0x30; /* 24 Mbps */ |
| 9608 | *pos++ = 0x48; /* 36 Mbps */ |
| 9609 | *pos++ = 0x60; /* 48 Mbps */ |
| 9610 | *pos++ = 0x6c; /* 54 Mbps */ |
| 9611 | /* TODO: Extended Supported Rates */ |
| 9612 | /* TODO: HT Capabilities */ |
| 9613 | break; |
| 9614 | } |
| 9615 | } |
| 9616 | |
| 9617 | s = open_monitor("sigmadut"); |
| 9618 | if (s < 0) { |
| 9619 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open " |
| 9620 | "monitor socket"); |
| 9621 | return 0; |
| 9622 | } |
| 9623 | |
| 9624 | res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY); |
| 9625 | if (res < 0) { |
| 9626 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to " |
| 9627 | "inject frame"); |
Pradeep Reddy POTTETI | 673d85c | 2016-07-26 19:08:07 +0530 | [diff] [blame] | 9628 | close(s); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 9629 | return 0; |
| 9630 | } |
| 9631 | if (res < pos - buf) { |
| 9632 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Only partial " |
| 9633 | "frame sent"); |
Pradeep Reddy POTTETI | 673d85c | 2016-07-26 19:08:07 +0530 | [diff] [blame] | 9634 | close(s); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 9635 | return 0; |
| 9636 | } |
| 9637 | |
| 9638 | close(s); |
| 9639 | |
| 9640 | return 1; |
| 9641 | #else /* __linux__ */ |
| 9642 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,sta_send_frame not " |
| 9643 | "yet supported"); |
| 9644 | return 0; |
| 9645 | #endif /* __linux__ */ |
| 9646 | } |
| 9647 | |
| 9648 | |
| 9649 | static int cmd_sta_send_frame_tdls(struct sigma_dut *dut, |
| 9650 | struct sigma_conn *conn, |
| 9651 | struct sigma_cmd *cmd) |
| 9652 | { |
| 9653 | const char *intf = get_param(cmd, "Interface"); |
| 9654 | const char *sta, *val; |
| 9655 | unsigned char addr[ETH_ALEN]; |
| 9656 | char buf[100]; |
| 9657 | |
Alexei Avshalom Lazar | 4a3c2f8 | 2019-05-02 13:35:37 +0300 | [diff] [blame] | 9658 | if (!intf) |
| 9659 | return -1; |
| 9660 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 9661 | sta = get_param(cmd, "peer"); |
| 9662 | if (sta == NULL) |
| 9663 | sta = get_param(cmd, "station"); |
| 9664 | if (sta == NULL) { |
| 9665 | send_resp(dut, conn, SIGMA_ERROR, |
| 9666 | "ErrorCode,Missing peer address"); |
| 9667 | return 0; |
| 9668 | } |
| 9669 | if (hwaddr_aton(sta, addr) < 0) { |
| 9670 | send_resp(dut, conn, SIGMA_ERROR, |
| 9671 | "ErrorCode,Invalid peer address"); |
| 9672 | return 0; |
| 9673 | } |
| 9674 | |
| 9675 | val = get_param(cmd, "type"); |
| 9676 | if (val == NULL) |
| 9677 | return -1; |
| 9678 | |
| 9679 | if (strcasecmp(val, "DISCOVERY") == 0) { |
| 9680 | snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", sta); |
| 9681 | if (wpa_command(intf, buf) < 0) { |
| 9682 | send_resp(dut, conn, SIGMA_ERROR, |
| 9683 | "ErrorCode,Failed to send TDLS discovery"); |
| 9684 | return 0; |
| 9685 | } |
| 9686 | return 1; |
| 9687 | } |
| 9688 | |
| 9689 | if (strcasecmp(val, "SETUP") == 0) { |
| 9690 | int status = 0, timeout = 0; |
| 9691 | |
| 9692 | val = get_param(cmd, "Status"); |
| 9693 | if (val) |
| 9694 | status = atoi(val); |
| 9695 | |
| 9696 | val = get_param(cmd, "Timeout"); |
| 9697 | if (val) |
| 9698 | timeout = atoi(val); |
| 9699 | |
| 9700 | if (status != 0 && status != 37) { |
| 9701 | send_resp(dut, conn, SIGMA_ERROR, |
| 9702 | "ErrorCode,Unsupported status value"); |
| 9703 | return 0; |
| 9704 | } |
| 9705 | |
| 9706 | if (timeout != 0 && timeout != 301) { |
| 9707 | send_resp(dut, conn, SIGMA_ERROR, |
| 9708 | "ErrorCode,Unsupported timeout value"); |
| 9709 | return 0; |
| 9710 | } |
| 9711 | |
| 9712 | if (status && timeout) { |
| 9713 | send_resp(dut, conn, SIGMA_ERROR, |
| 9714 | "ErrorCode,Unsupported timeout+status " |
| 9715 | "combination"); |
| 9716 | return 0; |
| 9717 | } |
| 9718 | |
| 9719 | if (status == 37 && |
| 9720 | wpa_command(intf, "SET tdls_testing 0x200")) { |
| 9721 | send_resp(dut, conn, SIGMA_ERROR, |
| 9722 | "ErrorCode,Failed to enable " |
| 9723 | "decline setup response test mode"); |
| 9724 | return 0; |
| 9725 | } |
| 9726 | |
| 9727 | if (timeout == 301) { |
| 9728 | int res; |
| 9729 | if (dut->no_tpk_expiration) |
| 9730 | res = wpa_command(intf, |
| 9731 | "SET tdls_testing 0x108"); |
| 9732 | else |
| 9733 | res = wpa_command(intf, |
| 9734 | "SET tdls_testing 0x8"); |
| 9735 | if (res) { |
| 9736 | send_resp(dut, conn, SIGMA_ERROR, |
| 9737 | "ErrorCode,Failed to set short TPK " |
| 9738 | "lifetime"); |
| 9739 | return 0; |
| 9740 | } |
| 9741 | } |
| 9742 | |
| 9743 | snprintf(buf, sizeof(buf), "TDLS_SETUP %s", sta); |
| 9744 | if (wpa_command(intf, buf) < 0) { |
| 9745 | send_resp(dut, conn, SIGMA_ERROR, |
| 9746 | "ErrorCode,Failed to send TDLS setup"); |
| 9747 | return 0; |
| 9748 | } |
| 9749 | return 1; |
| 9750 | } |
| 9751 | |
| 9752 | if (strcasecmp(val, "TEARDOWN") == 0) { |
| 9753 | snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", sta); |
| 9754 | if (wpa_command(intf, buf) < 0) { |
| 9755 | send_resp(dut, conn, SIGMA_ERROR, |
| 9756 | "ErrorCode,Failed to send TDLS teardown"); |
| 9757 | return 0; |
| 9758 | } |
| 9759 | return 1; |
| 9760 | } |
| 9761 | |
| 9762 | send_resp(dut, conn, SIGMA_ERROR, |
| 9763 | "ErrorCode,Unsupported TDLS frame"); |
| 9764 | return 0; |
| 9765 | } |
| 9766 | |
| 9767 | |
| 9768 | static int sta_ap_known(const char *ifname, const char *bssid) |
| 9769 | { |
| 9770 | char buf[4096]; |
| 9771 | |
Jouni Malinen | dd32f19 | 2018-09-15 02:55:19 +0300 | [diff] [blame] | 9772 | snprintf(buf, sizeof(buf), "BSS MASK=1 %s", bssid); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 9773 | if (wpa_command_resp(ifname, buf, buf, sizeof(buf)) < 0) |
| 9774 | return 0; |
| 9775 | if (strncmp(buf, "id=", 3) != 0) |
| 9776 | return 0; |
| 9777 | return 1; |
| 9778 | } |
| 9779 | |
| 9780 | |
| 9781 | static int sta_scan_ap(struct sigma_dut *dut, const char *ifname, |
| 9782 | const char *bssid) |
| 9783 | { |
| 9784 | int res; |
| 9785 | struct wpa_ctrl *ctrl; |
| 9786 | char buf[256]; |
| 9787 | |
| 9788 | if (sta_ap_known(ifname, bssid)) |
| 9789 | return 0; |
| 9790 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 9791 | "AP not in BSS table - start scan"); |
| 9792 | |
| 9793 | ctrl = open_wpa_mon(ifname); |
| 9794 | if (ctrl == NULL) { |
| 9795 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open " |
| 9796 | "wpa_supplicant monitor connection"); |
| 9797 | return -1; |
| 9798 | } |
| 9799 | |
| 9800 | if (wpa_command(ifname, "SCAN") < 0) { |
| 9801 | sigma_dut_print(dut, DUT_MSG_INFO, "Failed to start scan"); |
| 9802 | wpa_ctrl_detach(ctrl); |
| 9803 | wpa_ctrl_close(ctrl); |
| 9804 | return -1; |
| 9805 | } |
| 9806 | |
| 9807 | res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS", |
| 9808 | buf, sizeof(buf)); |
| 9809 | |
| 9810 | wpa_ctrl_detach(ctrl); |
| 9811 | wpa_ctrl_close(ctrl); |
| 9812 | |
| 9813 | if (res < 0) { |
| 9814 | sigma_dut_print(dut, DUT_MSG_INFO, "Scan did not complete"); |
| 9815 | return -1; |
| 9816 | } |
| 9817 | |
| 9818 | if (sta_ap_known(ifname, bssid)) |
| 9819 | return 0; |
| 9820 | sigma_dut_print(dut, DUT_MSG_INFO, "AP not in BSS table"); |
| 9821 | return -1; |
| 9822 | } |
| 9823 | |
| 9824 | |
| 9825 | static int cmd_sta_send_frame_hs2_neighadv(struct sigma_dut *dut, |
| 9826 | struct sigma_conn *conn, |
| 9827 | struct sigma_cmd *cmd, |
| 9828 | const char *intf) |
| 9829 | { |
| 9830 | char buf[200]; |
| 9831 | |
| 9832 | snprintf(buf, sizeof(buf), "ndsend 2001:DB8::1 %s", intf); |
| 9833 | if (system(buf) != 0) { |
| 9834 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Failed to run " |
| 9835 | "ndsend"); |
| 9836 | return 0; |
| 9837 | } |
| 9838 | |
| 9839 | return 1; |
| 9840 | } |
| 9841 | |
| 9842 | |
| 9843 | static int cmd_sta_send_frame_hs2_neighsolreq(struct sigma_dut *dut, |
| 9844 | struct sigma_conn *conn, |
| 9845 | struct sigma_cmd *cmd, |
| 9846 | const char *intf) |
| 9847 | { |
| 9848 | char buf[200]; |
| 9849 | const char *ip = get_param(cmd, "SenderIP"); |
| 9850 | |
Peng Xu | 26b356d | 2017-10-04 17:58:16 -0700 | [diff] [blame] | 9851 | if (!ip) |
| 9852 | return 0; |
| 9853 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 9854 | snprintf(buf, sizeof(buf), "ndisc6 -nm %s %s -r 4", ip, intf); |
| 9855 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 9856 | if (system(buf) == 0) { |
| 9857 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 9858 | "Neighbor Solicitation got a response " |
| 9859 | "for %s@%s", ip, intf); |
| 9860 | } |
| 9861 | |
| 9862 | return 1; |
| 9863 | } |
| 9864 | |
| 9865 | |
| 9866 | static int cmd_sta_send_frame_hs2_arpprobe(struct sigma_dut *dut, |
| 9867 | struct sigma_conn *conn, |
| 9868 | struct sigma_cmd *cmd, |
| 9869 | const char *ifname) |
| 9870 | { |
| 9871 | char buf[200]; |
| 9872 | const char *ip = get_param(cmd, "SenderIP"); |
| 9873 | |
| 9874 | if (ip == NULL) { |
| 9875 | send_resp(dut, conn, SIGMA_ERROR, |
| 9876 | "ErrorCode,Missing SenderIP parameter"); |
| 9877 | return 0; |
| 9878 | } |
| 9879 | snprintf(buf, sizeof(buf), "arping -I %s -D %s -c 4", ifname, ip); |
| 9880 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 9881 | if (system(buf) != 0) { |
| 9882 | sigma_dut_print(dut, DUT_MSG_INFO, "arping DAD got a response " |
| 9883 | "for %s@%s", ip, ifname); |
| 9884 | } |
| 9885 | |
| 9886 | return 1; |
| 9887 | } |
| 9888 | |
| 9889 | |
| 9890 | static int cmd_sta_send_frame_hs2_arpannounce(struct sigma_dut *dut, |
| 9891 | struct sigma_conn *conn, |
| 9892 | struct sigma_cmd *cmd, |
| 9893 | const char *ifname) |
| 9894 | { |
| 9895 | char buf[200]; |
| 9896 | char ip[16]; |
| 9897 | int s; |
Peng Xu | b375688 | 2017-10-04 14:39:09 -0700 | [diff] [blame] | 9898 | struct ifreq ifr; |
| 9899 | struct sockaddr_in saddr; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 9900 | |
| 9901 | s = socket(PF_INET, SOCK_DGRAM, 0); |
Peng Xu | b375688 | 2017-10-04 14:39:09 -0700 | [diff] [blame] | 9902 | if (s < 0) { |
| 9903 | perror("socket"); |
| 9904 | return -1; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 9905 | } |
| 9906 | |
Peng Xu | b375688 | 2017-10-04 14:39:09 -0700 | [diff] [blame] | 9907 | memset(&ifr, 0, sizeof(ifr)); |
| 9908 | strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); |
| 9909 | if (ioctl(s, SIOCGIFADDR, &ifr) < 0) { |
| 9910 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 9911 | "Failed to get %s IP address: %s", |
| 9912 | ifname, strerror(errno)); |
| 9913 | close(s); |
| 9914 | return -1; |
| 9915 | } |
| 9916 | close(s); |
| 9917 | |
| 9918 | memcpy(&saddr, &ifr.ifr_addr, sizeof(struct sockaddr_in)); |
| 9919 | strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip)); |
| 9920 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 9921 | snprintf(buf, sizeof(buf), "arping -I %s -s %s %s -c 4", ifname, ip, |
| 9922 | ip); |
| 9923 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 9924 | if (system(buf) != 0) { |
| 9925 | } |
| 9926 | |
| 9927 | return 1; |
| 9928 | } |
| 9929 | |
| 9930 | |
| 9931 | static int cmd_sta_send_frame_hs2_arpreply(struct sigma_dut *dut, |
| 9932 | struct sigma_conn *conn, |
| 9933 | struct sigma_cmd *cmd, |
| 9934 | const char *ifname) |
| 9935 | { |
| 9936 | char buf[200], addr[20]; |
| 9937 | char dst[ETH_ALEN], src[ETH_ALEN]; |
| 9938 | short ethtype = htons(ETH_P_ARP); |
| 9939 | char *pos; |
| 9940 | int s, res; |
| 9941 | const char *val; |
| 9942 | struct sockaddr_in taddr; |
| 9943 | |
| 9944 | val = get_param(cmd, "dest"); |
| 9945 | if (val) |
| 9946 | hwaddr_aton(val, (unsigned char *) dst); |
| 9947 | |
| 9948 | val = get_param(cmd, "DestIP"); |
| 9949 | if (val) |
| 9950 | inet_aton(val, &taddr.sin_addr); |
Peng Xu | 151c9e1 | 2017-10-04 14:39:09 -0700 | [diff] [blame] | 9951 | else |
| 9952 | return -2; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 9953 | |
| 9954 | if (get_wpa_status(get_station_ifname(), "address", addr, |
| 9955 | sizeof(addr)) < 0) |
| 9956 | return -2; |
| 9957 | hwaddr_aton(addr, (unsigned char *) src); |
| 9958 | |
| 9959 | pos = buf; |
| 9960 | *pos++ = 0x00; |
| 9961 | *pos++ = 0x01; |
| 9962 | *pos++ = 0x08; |
| 9963 | *pos++ = 0x00; |
| 9964 | *pos++ = 0x06; |
| 9965 | *pos++ = 0x04; |
| 9966 | *pos++ = 0x00; |
| 9967 | *pos++ = 0x02; |
| 9968 | memcpy(pos, src, ETH_ALEN); |
| 9969 | pos += ETH_ALEN; |
| 9970 | memcpy(pos, &taddr.sin_addr, 4); |
| 9971 | pos += 4; |
| 9972 | memcpy(pos, dst, ETH_ALEN); |
| 9973 | pos += ETH_ALEN; |
| 9974 | memcpy(pos, &taddr.sin_addr, 4); |
| 9975 | pos += 4; |
| 9976 | |
| 9977 | s = open_monitor(get_station_ifname()); |
| 9978 | if (s < 0) { |
| 9979 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open " |
| 9980 | "monitor socket"); |
| 9981 | return 0; |
| 9982 | } |
| 9983 | |
| 9984 | res = inject_eth_frame(s, buf, pos - buf, ethtype, dst, src); |
| 9985 | if (res < 0) { |
| 9986 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to " |
| 9987 | "inject frame"); |
Pradeep Reddy POTTETI | 673d85c | 2016-07-26 19:08:07 +0530 | [diff] [blame] | 9988 | close(s); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 9989 | return 0; |
| 9990 | } |
| 9991 | |
| 9992 | close(s); |
| 9993 | |
| 9994 | return 1; |
| 9995 | } |
| 9996 | |
| 9997 | |
| 9998 | static int cmd_sta_send_frame_hs2_dls_req(struct sigma_dut *dut, |
| 9999 | struct sigma_conn *conn, |
| 10000 | struct sigma_cmd *cmd, |
| 10001 | const char *intf, const char *dest) |
| 10002 | { |
| 10003 | char buf[100]; |
| 10004 | |
| 10005 | if (if_nametoindex("sigmadut") == 0) { |
| 10006 | snprintf(buf, sizeof(buf), |
| 10007 | "iw dev %s interface add sigmadut type monitor", |
| 10008 | get_station_ifname()); |
| 10009 | if (system(buf) != 0 || |
| 10010 | if_nametoindex("sigmadut") == 0) { |
| 10011 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add " |
| 10012 | "monitor interface with '%s'", buf); |
| 10013 | return -2; |
| 10014 | } |
| 10015 | } |
| 10016 | |
| 10017 | if (system("ifconfig sigmadut up") != 0) { |
| 10018 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set " |
| 10019 | "monitor interface up"); |
| 10020 | return -2; |
| 10021 | } |
| 10022 | |
| 10023 | return sta_inject_frame(dut, conn, DLS_REQ, UNPROTECTED, dest); |
| 10024 | } |
| 10025 | |
| 10026 | |
| 10027 | static int cmd_sta_send_frame_hs2(struct sigma_dut *dut, |
| 10028 | struct sigma_conn *conn, |
| 10029 | struct sigma_cmd *cmd) |
| 10030 | { |
| 10031 | const char *intf = get_param(cmd, "Interface"); |
| 10032 | const char *dest = get_param(cmd, "Dest"); |
| 10033 | const char *type = get_param(cmd, "FrameName"); |
| 10034 | const char *val; |
| 10035 | char buf[200], *pos, *end; |
| 10036 | int count, count2; |
| 10037 | |
| 10038 | if (type == NULL) |
| 10039 | type = get_param(cmd, "Type"); |
| 10040 | |
| 10041 | if (intf == NULL || dest == NULL || type == NULL) |
| 10042 | return -1; |
| 10043 | |
| 10044 | if (strcasecmp(type, "NeighAdv") == 0) |
| 10045 | return cmd_sta_send_frame_hs2_neighadv(dut, conn, cmd, intf); |
| 10046 | |
| 10047 | if (strcasecmp(type, "NeighSolicitReq") == 0) |
| 10048 | return cmd_sta_send_frame_hs2_neighsolreq(dut, conn, cmd, intf); |
| 10049 | |
| 10050 | if (strcasecmp(type, "ARPProbe") == 0) |
| 10051 | return cmd_sta_send_frame_hs2_arpprobe(dut, conn, cmd, intf); |
| 10052 | |
| 10053 | if (strcasecmp(type, "ARPAnnounce") == 0) |
| 10054 | return cmd_sta_send_frame_hs2_arpannounce(dut, conn, cmd, intf); |
| 10055 | |
| 10056 | if (strcasecmp(type, "ARPReply") == 0) |
| 10057 | return cmd_sta_send_frame_hs2_arpreply(dut, conn, cmd, intf); |
| 10058 | |
| 10059 | if (strcasecmp(type, "DLS-request") == 0 || |
| 10060 | strcasecmp(type, "DLSrequest") == 0) |
| 10061 | return cmd_sta_send_frame_hs2_dls_req(dut, conn, cmd, intf, |
| 10062 | dest); |
| 10063 | |
| 10064 | if (strcasecmp(type, "ANQPQuery") != 0 && |
| 10065 | strcasecmp(type, "Query") != 0) { |
| 10066 | send_resp(dut, conn, SIGMA_ERROR, |
| 10067 | "ErrorCode,Unsupported HS 2.0 send frame type"); |
| 10068 | return 0; |
| 10069 | } |
| 10070 | |
| 10071 | if (sta_scan_ap(dut, intf, dest) < 0) { |
| 10072 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not find " |
| 10073 | "the requested AP"); |
| 10074 | return 0; |
| 10075 | } |
| 10076 | |
| 10077 | pos = buf; |
| 10078 | end = buf + sizeof(buf); |
| 10079 | count = 0; |
| 10080 | pos += snprintf(pos, end - pos, "ANQP_GET %s ", dest); |
| 10081 | |
| 10082 | val = get_param(cmd, "ANQP_CAP_LIST"); |
| 10083 | if (val && atoi(val)) { |
| 10084 | pos += snprintf(pos, end - pos, "%s257", count > 0 ? "," : ""); |
| 10085 | count++; |
| 10086 | } |
| 10087 | |
| 10088 | val = get_param(cmd, "VENUE_NAME"); |
| 10089 | if (val && atoi(val)) { |
| 10090 | pos += snprintf(pos, end - pos, "%s258", count > 0 ? "," : ""); |
| 10091 | count++; |
| 10092 | } |
| 10093 | |
| 10094 | val = get_param(cmd, "NETWORK_AUTH_TYPE"); |
| 10095 | if (val && atoi(val)) { |
| 10096 | pos += snprintf(pos, end - pos, "%s260", count > 0 ? "," : ""); |
| 10097 | count++; |
| 10098 | } |
| 10099 | |
| 10100 | val = get_param(cmd, "ROAMING_CONS"); |
| 10101 | if (val && atoi(val)) { |
| 10102 | pos += snprintf(pos, end - pos, "%s261", count > 0 ? "," : ""); |
| 10103 | count++; |
| 10104 | } |
| 10105 | |
| 10106 | val = get_param(cmd, "IP_ADDR_TYPE_AVAILABILITY"); |
| 10107 | if (val && atoi(val)) { |
| 10108 | pos += snprintf(pos, end - pos, "%s262", count > 0 ? "," : ""); |
| 10109 | count++; |
| 10110 | } |
| 10111 | |
| 10112 | val = get_param(cmd, "NAI_REALM_LIST"); |
| 10113 | if (val && atoi(val)) { |
| 10114 | pos += snprintf(pos, end - pos, "%s263", count > 0 ? "," : ""); |
| 10115 | count++; |
| 10116 | } |
| 10117 | |
| 10118 | val = get_param(cmd, "3GPP_INFO"); |
| 10119 | if (val && atoi(val)) { |
| 10120 | pos += snprintf(pos, end - pos, "%s264", count > 0 ? "," : ""); |
| 10121 | count++; |
| 10122 | } |
| 10123 | |
| 10124 | val = get_param(cmd, "DOMAIN_LIST"); |
| 10125 | if (val && atoi(val)) { |
| 10126 | pos += snprintf(pos, end - pos, "%s268", count > 0 ? "," : ""); |
| 10127 | count++; |
| 10128 | } |
| 10129 | |
Jouni Malinen | 34cf953 | 2018-04-29 19:26:33 +0300 | [diff] [blame] | 10130 | val = get_param(cmd, "Venue_URL"); |
| 10131 | if (val && atoi(val)) { |
| 10132 | pos += snprintf(pos, end - pos, "%s277", count > 0 ? "," : ""); |
| 10133 | count++; |
| 10134 | } |
| 10135 | |
Jouni Malinen | d3bca5d | 2018-04-29 17:25:23 +0300 | [diff] [blame] | 10136 | val = get_param(cmd, "Advice_Of_Charge"); |
| 10137 | if (val && atoi(val)) { |
| 10138 | pos += snprintf(pos, end - pos, "%s278", count > 0 ? "," : ""); |
| 10139 | count++; |
| 10140 | } |
| 10141 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 10142 | if (count && wpa_command(intf, buf)) { |
| 10143 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,ANQP_GET failed"); |
| 10144 | return 0; |
| 10145 | } |
| 10146 | |
| 10147 | pos = buf; |
| 10148 | end = buf + sizeof(buf); |
| 10149 | count2 = 0; |
| 10150 | pos += snprintf(pos, end - pos, "HS20_ANQP_GET %s ", dest); |
| 10151 | |
| 10152 | val = get_param(cmd, "HS_CAP_LIST"); |
| 10153 | if (val && atoi(val)) { |
| 10154 | pos += snprintf(pos, end - pos, "%s2", count2 > 0 ? "," : ""); |
| 10155 | count2++; |
| 10156 | } |
| 10157 | |
| 10158 | val = get_param(cmd, "OPER_NAME"); |
| 10159 | if (val && atoi(val)) { |
| 10160 | pos += snprintf(pos, end - pos, "%s3", count2 > 0 ? "," : ""); |
| 10161 | count2++; |
| 10162 | } |
| 10163 | |
| 10164 | val = get_param(cmd, "WAN_METRICS"); |
| 10165 | if (!val) |
| 10166 | val = get_param(cmd, "WAN_MAT"); |
| 10167 | if (!val) |
| 10168 | val = get_param(cmd, "WAN_MET"); |
| 10169 | if (val && atoi(val)) { |
| 10170 | pos += snprintf(pos, end - pos, "%s4", count2 > 0 ? "," : ""); |
| 10171 | count2++; |
| 10172 | } |
| 10173 | |
| 10174 | val = get_param(cmd, "CONNECTION_CAPABILITY"); |
| 10175 | if (val && atoi(val)) { |
| 10176 | pos += snprintf(pos, end - pos, "%s5", count2 > 0 ? "," : ""); |
| 10177 | count2++; |
| 10178 | } |
| 10179 | |
| 10180 | val = get_param(cmd, "OP_CLASS"); |
| 10181 | if (val && atoi(val)) { |
| 10182 | pos += snprintf(pos, end - pos, "%s7", count2 > 0 ? "," : ""); |
| 10183 | count2++; |
| 10184 | } |
| 10185 | |
| 10186 | val = get_param(cmd, "OSU_PROVIDER_LIST"); |
| 10187 | if (val && atoi(val)) { |
| 10188 | pos += snprintf(pos, end - pos, "%s8", count2 > 0 ? "," : ""); |
| 10189 | count2++; |
| 10190 | } |
| 10191 | |
Jouni Malinen | f67afec | 2018-04-29 19:24:58 +0300 | [diff] [blame] | 10192 | val = get_param(cmd, "OPER_ICON_METADATA"); |
| 10193 | if (!val) |
| 10194 | val = get_param(cmd, "OPERATOR_ICON_METADATA"); |
| 10195 | if (val && atoi(val)) { |
| 10196 | pos += snprintf(pos, end - pos, "%s12", count2 > 0 ? "," : ""); |
| 10197 | count2++; |
| 10198 | } |
| 10199 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 10200 | if (count && count2) { |
| 10201 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before sending out " |
| 10202 | "second query"); |
| 10203 | sleep(1); |
| 10204 | } |
| 10205 | |
| 10206 | if (count2 && wpa_command(intf, buf)) { |
| 10207 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,HS20_ANQP_GET " |
| 10208 | "failed"); |
| 10209 | return 0; |
| 10210 | } |
| 10211 | |
| 10212 | val = get_param(cmd, "NAI_HOME_REALM_LIST"); |
| 10213 | if (val) { |
| 10214 | if (count || count2) { |
| 10215 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before " |
| 10216 | "sending out second query"); |
| 10217 | sleep(1); |
| 10218 | } |
| 10219 | |
| 10220 | if (strcmp(val, "1") == 0) |
| 10221 | val = "mail.example.com"; |
| 10222 | snprintf(buf, end - pos, |
| 10223 | "HS20_GET_NAI_HOME_REALM_LIST %s realm=%s", |
| 10224 | dest, val); |
| 10225 | if (wpa_command(intf, buf)) { |
| 10226 | send_resp(dut, conn, SIGMA_ERROR, |
| 10227 | "ErrorCode,HS20_GET_NAI_HOME_REALM_LIST " |
| 10228 | "failed"); |
| 10229 | return 0; |
| 10230 | } |
| 10231 | } |
| 10232 | |
| 10233 | val = get_param(cmd, "ICON_REQUEST"); |
| 10234 | if (val) { |
| 10235 | if (count || count2) { |
| 10236 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before " |
| 10237 | "sending out second query"); |
| 10238 | sleep(1); |
| 10239 | } |
| 10240 | |
| 10241 | snprintf(buf, end - pos, |
| 10242 | "HS20_ICON_REQUEST %s %s", dest, val); |
| 10243 | if (wpa_command(intf, buf)) { |
| 10244 | send_resp(dut, conn, SIGMA_ERROR, |
| 10245 | "ErrorCode,HS20_ICON_REQUEST failed"); |
| 10246 | return 0; |
| 10247 | } |
| 10248 | } |
| 10249 | |
| 10250 | return 1; |
| 10251 | } |
| 10252 | |
| 10253 | |
| 10254 | static int ath_sta_send_frame_vht(struct sigma_dut *dut, |
| 10255 | struct sigma_conn *conn, |
| 10256 | struct sigma_cmd *cmd) |
| 10257 | { |
| 10258 | const char *val; |
| 10259 | char *ifname; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 10260 | int chwidth, nss; |
| 10261 | |
| 10262 | val = get_param(cmd, "framename"); |
| 10263 | if (!val) |
| 10264 | return -1; |
| 10265 | sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val); |
| 10266 | |
| 10267 | /* Command sequence to generate Op mode notification */ |
| 10268 | if (val && strcasecmp(val, "Op_md_notif_frm") == 0) { |
| 10269 | ifname = get_station_ifname(); |
| 10270 | |
| 10271 | /* Disable STBC */ |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 10272 | run_iwpriv(dut, ifname, "tx_stbc 0"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 10273 | |
| 10274 | /* Extract Channel width */ |
| 10275 | val = get_param(cmd, "Channel_width"); |
| 10276 | if (val) { |
| 10277 | switch (atoi(val)) { |
| 10278 | case 20: |
| 10279 | chwidth = 0; |
| 10280 | break; |
| 10281 | case 40: |
| 10282 | chwidth = 1; |
| 10283 | break; |
| 10284 | case 80: |
| 10285 | chwidth = 2; |
| 10286 | break; |
| 10287 | case 160: |
| 10288 | chwidth = 3; |
| 10289 | break; |
| 10290 | default: |
| 10291 | chwidth = 2; |
| 10292 | break; |
| 10293 | } |
| 10294 | |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 10295 | run_iwpriv(dut, ifname, "chwidth %d", chwidth); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 10296 | } |
| 10297 | |
| 10298 | /* Extract NSS */ |
| 10299 | val = get_param(cmd, "NSS"); |
| 10300 | if (val) { |
| 10301 | switch (atoi(val)) { |
| 10302 | case 1: |
| 10303 | nss = 1; |
| 10304 | break; |
| 10305 | case 2: |
| 10306 | nss = 3; |
| 10307 | break; |
| 10308 | case 3: |
| 10309 | nss = 7; |
| 10310 | break; |
| 10311 | default: |
| 10312 | /* We do not support NSS > 3 */ |
| 10313 | nss = 3; |
| 10314 | break; |
| 10315 | } |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 10316 | run_iwpriv(dut, ifname, "rxchainmask %d", nss); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 10317 | } |
| 10318 | |
| 10319 | /* Opmode notify */ |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 10320 | run_iwpriv(dut, ifname, "opmode_notify 1"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 10321 | } |
| 10322 | |
| 10323 | return 1; |
| 10324 | } |
| 10325 | |
| 10326 | |
| 10327 | static int cmd_sta_send_frame_vht(struct sigma_dut *dut, |
| 10328 | struct sigma_conn *conn, |
| 10329 | struct sigma_cmd *cmd) |
| 10330 | { |
| 10331 | switch (get_driver_type()) { |
| 10332 | case DRIVER_ATHEROS: |
| 10333 | return ath_sta_send_frame_vht(dut, conn, cmd); |
| 10334 | default: |
| 10335 | send_resp(dut, conn, SIGMA_ERROR, |
| 10336 | "errorCode,Unsupported sta_set_frame(VHT) with the current driver"); |
| 10337 | return 0; |
| 10338 | } |
| 10339 | } |
| 10340 | |
| 10341 | |
Kiran Kumar Lokere | 419f696 | 2018-10-24 19:03:04 -0700 | [diff] [blame] | 10342 | static int wcn_sta_send_frame_he(struct sigma_dut *dut, struct sigma_conn *conn, |
| 10343 | struct sigma_cmd *cmd) |
| 10344 | { |
| 10345 | const char *val; |
| 10346 | const char *intf = get_param(cmd, "Interface"); |
| 10347 | |
Alexei Avshalom Lazar | 4a3c2f8 | 2019-05-02 13:35:37 +0300 | [diff] [blame] | 10348 | if (!intf) |
| 10349 | return -1; |
| 10350 | |
Kiran Kumar Lokere | 419f696 | 2018-10-24 19:03:04 -0700 | [diff] [blame] | 10351 | val = get_param(cmd, "framename"); |
| 10352 | if (!val) |
| 10353 | return -1; |
| 10354 | sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val); |
| 10355 | |
| 10356 | /* Command sequence to generate Op mode notification */ |
| 10357 | if (val && strcasecmp(val, "action") == 0) { |
| 10358 | val = get_param(cmd, "PPDUTxType"); |
| 10359 | if (val && strcasecmp(val, "TB") == 0) { |
| 10360 | if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 1)) { |
| 10361 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 10362 | "failed to send TB PPDU Tx cfg"); |
| 10363 | send_resp(dut, conn, SIGMA_ERROR, |
| 10364 | "ErrorCode,set TB PPDU Tx cfg failed"); |
| 10365 | return 0; |
| 10366 | } |
| 10367 | return 1; |
| 10368 | } |
| 10369 | |
| 10370 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 10371 | "Action Tx type is not defined"); |
| 10372 | } |
| 10373 | |
| 10374 | return 1; |
| 10375 | } |
| 10376 | |
| 10377 | |
| 10378 | static int cmd_sta_send_frame_he(struct sigma_dut *dut, |
| 10379 | struct sigma_conn *conn, |
| 10380 | struct sigma_cmd *cmd) |
| 10381 | { |
| 10382 | switch (get_driver_type()) { |
| 10383 | case DRIVER_WCN: |
| 10384 | return wcn_sta_send_frame_he(dut, conn, cmd); |
| 10385 | default: |
| 10386 | send_resp(dut, conn, SIGMA_ERROR, |
| 10387 | "errorCode,Unsupported sta_set_frame(HE) with the current driver"); |
| 10388 | return 0; |
| 10389 | } |
| 10390 | } |
| 10391 | |
| 10392 | |
Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 10393 | #ifdef __linux__ |
Alexei Avshalom Lazar | a90032d | 2019-05-02 13:34:02 +0300 | [diff] [blame] | 10394 | |
| 10395 | static int |
| 10396 | wil6210_send_p2p_frame_60g(struct sigma_dut *dut, struct sigma_cmd *cmd, |
| 10397 | const char *frame_name, const char *dest_mac) |
| 10398 | { |
| 10399 | int isprobereq = strcasecmp(frame_name, "probereq") == 0; |
| 10400 | const char *ssid = get_param(cmd, "ssid"); |
| 10401 | const char *countstr = get_param(cmd, "count"); |
| 10402 | const char *channelstr = get_param(cmd, "channel"); |
| 10403 | const char *group_id = get_param(cmd, "groupid"); |
| 10404 | const char *client_id = get_param(cmd, "clientmac"); |
| 10405 | int count, channel, freq, i; |
| 10406 | const char *fname; |
| 10407 | char frame[1024], src_mac[20], group_id_attr[25], |
| 10408 | device_macstr[3 * ETH_ALEN], client_mac[ETH_ALEN]; |
| 10409 | const char *group_ssid; |
| 10410 | const int group_ssid_prefix_len = 9; |
| 10411 | struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *) frame; |
| 10412 | size_t framelen = sizeof(frame); |
| 10413 | struct template_frame_tag tags[2]; |
| 10414 | size_t tags_total = ARRAY_SIZE(tags); |
| 10415 | int tag_index, len, dst_len; |
| 10416 | |
| 10417 | if (!countstr || !channelstr) { |
| 10418 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 10419 | "Missing argument: count, channel"); |
| 10420 | return -1; |
| 10421 | } |
| 10422 | if (isprobereq && !ssid) { |
| 10423 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 10424 | "Missing argument: ssid"); |
| 10425 | return -1; |
| 10426 | } |
| 10427 | if (!isprobereq && (!group_id || !client_id)) { |
| 10428 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 10429 | "Missing argument: group_id, client_id"); |
| 10430 | return -1; |
| 10431 | } |
| 10432 | |
| 10433 | count = atoi(countstr); |
| 10434 | channel = atoi(channelstr); |
| 10435 | freq = channel_to_freq(dut, channel); |
| 10436 | |
| 10437 | if (!freq) { |
| 10438 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 10439 | "invalid channel: %s", channelstr); |
| 10440 | return -1; |
| 10441 | } |
| 10442 | |
| 10443 | if (isprobereq) { |
| 10444 | if (strcasecmp(ssid, "wildcard") == 0) { |
| 10445 | fname = "probe_req_wildcard.txt"; |
| 10446 | } else if (strcasecmp(ssid, "P2P_Wildcard") == 0) { |
| 10447 | fname = "probe_req_P2P_Wildcard.txt"; |
| 10448 | } else { |
| 10449 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 10450 | "invalid probe request type"); |
| 10451 | return -1; |
| 10452 | } |
| 10453 | } else { |
| 10454 | fname = "P2P_device_discovery_req.txt"; |
| 10455 | } |
| 10456 | |
| 10457 | if (parse_template_frame_file(dut, fname, frame, &framelen, |
| 10458 | tags, &tags_total)) { |
| 10459 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 10460 | "invalid frame template: %s", fname); |
| 10461 | return -1; |
| 10462 | } |
| 10463 | |
| 10464 | if (get_wpa_status(get_station_ifname(), "address", |
| 10465 | src_mac, sizeof(src_mac)) < 0 || |
| 10466 | parse_mac_address(dut, src_mac, &hdr->addr2[0]) || |
| 10467 | parse_mac_address(dut, dest_mac, &hdr->addr1[0])) |
| 10468 | return -1; |
| 10469 | /* Use wildcard BSSID, since we are in PBSS */ |
| 10470 | memset(&hdr->addr3, 0xFF, ETH_ALEN); |
| 10471 | |
| 10472 | if (!isprobereq) { |
| 10473 | tag_index = find_template_frame_tag(tags, tags_total, 1); |
| 10474 | if (tag_index < 0) { |
| 10475 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 10476 | "can't find device id attribute"); |
| 10477 | return -1; |
| 10478 | } |
| 10479 | if (parse_mac_address(dut, client_id, |
| 10480 | (unsigned char *) client_mac)) { |
| 10481 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 10482 | "invalid client_id: %s", client_id); |
| 10483 | return -1; |
| 10484 | } |
| 10485 | if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset], |
| 10486 | framelen - tags[tag_index].offset, |
| 10487 | IEEE80211_P2P_ATTR_DEVICE_ID, |
| 10488 | client_mac, ETH_ALEN)) { |
| 10489 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 10490 | "fail to replace device id attribute"); |
| 10491 | return -1; |
| 10492 | } |
| 10493 | |
| 10494 | /* |
| 10495 | * group_id arg contains device MAC address followed by |
| 10496 | * space and SSID (DIRECT-somessid). |
| 10497 | * group id attribute contains device address (6 bytes) |
| 10498 | * followed by SSID prefix DIRECT-XX (9 bytes) |
| 10499 | */ |
| 10500 | if (strlen(group_id) < sizeof(device_macstr)) { |
| 10501 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 10502 | "group_id arg too short"); |
| 10503 | return -1; |
| 10504 | } |
| 10505 | memcpy(device_macstr, group_id, sizeof(device_macstr)); |
| 10506 | device_macstr[sizeof(device_macstr) - 1] = '\0'; |
| 10507 | if (parse_mac_address(dut, device_macstr, |
| 10508 | (unsigned char *) group_id_attr)) { |
| 10509 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 10510 | "fail to parse device address from group_id"); |
| 10511 | return -1; |
| 10512 | } |
| 10513 | group_ssid = strchr(group_id, ' '); |
| 10514 | if (!group_ssid) { |
| 10515 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 10516 | "invalid group_id arg, no ssid"); |
| 10517 | return -1; |
| 10518 | } |
| 10519 | group_ssid++; |
| 10520 | len = strlen(group_ssid); |
| 10521 | if (len < group_ssid_prefix_len) { |
| 10522 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 10523 | "group_id SSID too short"); |
| 10524 | return -1; |
| 10525 | } |
| 10526 | dst_len = sizeof(group_id_attr) - ETH_ALEN; |
| 10527 | if (len > dst_len) { |
| 10528 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 10529 | "group_id SSID (%s) too long", |
| 10530 | group_ssid); |
| 10531 | return -1; |
| 10532 | } |
| 10533 | |
| 10534 | memcpy(group_id_attr + ETH_ALEN, group_ssid, len); |
| 10535 | tag_index = find_template_frame_tag(tags, tags_total, 2); |
| 10536 | if (tag_index < 0) { |
| 10537 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 10538 | "can't find group id attribute"); |
| 10539 | return -1; |
| 10540 | } |
| 10541 | if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset], |
| 10542 | framelen - tags[tag_index].offset, |
| 10543 | IEEE80211_P2P_ATTR_GROUP_ID, |
| 10544 | group_id_attr, |
| 10545 | sizeof(group_id_attr))) { |
| 10546 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 10547 | "fail to replace group id attribute"); |
| 10548 | return -1; |
| 10549 | } |
| 10550 | } |
| 10551 | |
| 10552 | for (i = 0; i < count; i++) { |
| 10553 | if (wil6210_transmit_frame(dut, freq, |
| 10554 | WIL_TRANSMIT_FRAME_DEFAULT_ROC, |
| 10555 | frame, framelen)) { |
| 10556 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 10557 | "fail to transmit probe request frame"); |
| 10558 | return -1; |
| 10559 | } |
| 10560 | } |
| 10561 | |
| 10562 | return 0; |
| 10563 | } |
| 10564 | |
| 10565 | |
Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 10566 | int wil6210_send_frame_60g(struct sigma_dut *dut, struct sigma_conn *conn, |
| 10567 | struct sigma_cmd *cmd) |
| 10568 | { |
| 10569 | const char *frame_name = get_param(cmd, "framename"); |
| 10570 | const char *mac = get_param(cmd, "dest_mac"); |
| 10571 | |
| 10572 | if (!frame_name || !mac) { |
| 10573 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 10574 | "framename and dest_mac must be provided"); |
| 10575 | return -1; |
| 10576 | } |
| 10577 | |
| 10578 | if (strcasecmp(frame_name, "brp") == 0) { |
| 10579 | const char *l_rx = get_param(cmd, "L-RX"); |
| 10580 | int l_rx_i; |
| 10581 | |
| 10582 | if (!l_rx) { |
| 10583 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 10584 | "L-RX must be provided"); |
| 10585 | return -1; |
| 10586 | } |
| 10587 | l_rx_i = atoi(l_rx); |
| 10588 | |
| 10589 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 10590 | "dev_send_frame: BRP-RX, dest_mac %s, L-RX %s", |
| 10591 | mac, l_rx); |
| 10592 | if (l_rx_i != 16) { |
| 10593 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 10594 | "unsupported L-RX: %s", l_rx); |
| 10595 | return -1; |
| 10596 | } |
| 10597 | |
| 10598 | if (wil6210_send_brp_rx(dut, mac, l_rx_i)) |
| 10599 | return -1; |
| 10600 | } else if (strcasecmp(frame_name, "ssw") == 0) { |
| 10601 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 10602 | "dev_send_frame: SLS, dest_mac %s", mac); |
| 10603 | if (wil6210_send_sls(dut, mac)) |
| 10604 | return -1; |
Alexei Avshalom Lazar | a90032d | 2019-05-02 13:34:02 +0300 | [diff] [blame] | 10605 | } else if ((strcasecmp(frame_name, "probereq") == 0) || |
| 10606 | (strcasecmp(frame_name, "devdiscreq") == 0)) { |
| 10607 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 10608 | "dev_send_frame: %s, dest_mac %s", frame_name, |
| 10609 | mac); |
| 10610 | if (wil6210_send_p2p_frame_60g(dut, cmd, frame_name, mac)) |
| 10611 | return -1; |
Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 10612 | } else { |
| 10613 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 10614 | "unsupported frame type: %s", frame_name); |
| 10615 | return -1; |
| 10616 | } |
| 10617 | |
| 10618 | return 1; |
| 10619 | } |
Alexei Avshalom Lazar | a90032d | 2019-05-02 13:34:02 +0300 | [diff] [blame] | 10620 | |
Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 10621 | #endif /* __linux__ */ |
| 10622 | |
| 10623 | |
| 10624 | static int cmd_sta_send_frame_60g(struct sigma_dut *dut, |
| 10625 | struct sigma_conn *conn, |
| 10626 | struct sigma_cmd *cmd) |
| 10627 | { |
| 10628 | switch (get_driver_type()) { |
| 10629 | #ifdef __linux__ |
| 10630 | case DRIVER_WIL6210: |
| 10631 | return wil6210_send_frame_60g(dut, conn, cmd); |
| 10632 | #endif /* __linux__ */ |
| 10633 | default: |
| 10634 | send_resp(dut, conn, SIGMA_ERROR, |
| 10635 | "errorCode,Unsupported sta_set_frame(60G) with the current driver"); |
| 10636 | return 0; |
| 10637 | } |
| 10638 | } |
| 10639 | |
| 10640 | |
Ashwini Patil | db59b3c | 2017-04-13 15:19:23 +0530 | [diff] [blame] | 10641 | static int mbo_send_anqp_query(struct sigma_dut *dut, struct sigma_conn *conn, |
| 10642 | const char *intf, struct sigma_cmd *cmd) |
| 10643 | { |
| 10644 | const char *val, *addr; |
| 10645 | char buf[100]; |
| 10646 | |
| 10647 | addr = get_param(cmd, "DestMac"); |
| 10648 | if (!addr) { |
| 10649 | send_resp(dut, conn, SIGMA_INVALID, |
| 10650 | "ErrorCode,AP MAC address is missing"); |
| 10651 | return 0; |
| 10652 | } |
| 10653 | |
| 10654 | val = get_param(cmd, "ANQPQuery_ID"); |
| 10655 | if (!val) { |
| 10656 | send_resp(dut, conn, SIGMA_INVALID, |
| 10657 | "ErrorCode,Missing ANQPQuery_ID"); |
| 10658 | return 0; |
| 10659 | } |
| 10660 | |
| 10661 | if (strcasecmp(val, "NeighborReportReq") == 0) { |
| 10662 | snprintf(buf, sizeof(buf), "ANQP_GET %s 272", addr); |
| 10663 | } else if (strcasecmp(val, "QueryListWithCellPref") == 0) { |
| 10664 | snprintf(buf, sizeof(buf), "ANQP_GET %s 272,mbo:2", addr); |
| 10665 | } else { |
| 10666 | sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid ANQPQuery_ID: %s", |
| 10667 | val); |
| 10668 | send_resp(dut, conn, SIGMA_INVALID, |
| 10669 | "ErrorCode,Invalid ANQPQuery_ID"); |
| 10670 | return 0; |
| 10671 | } |
| 10672 | |
Ashwini Patil | d174f2c | 2017-04-13 16:49:46 +0530 | [diff] [blame] | 10673 | /* Set gas_address3 field to IEEE 802.11-2012 standard compliant form |
| 10674 | * (Address3 = Wildcard BSSID when sent to not-associated AP; |
| 10675 | * if associated, AP BSSID). |
| 10676 | */ |
| 10677 | if (wpa_command(intf, "SET gas_address3 1") < 0) { |
| 10678 | send_resp(dut, conn, SIGMA_ERROR, |
| 10679 | "ErrorCode,Failed to set gas_address3"); |
| 10680 | return 0; |
| 10681 | } |
| 10682 | |
Ashwini Patil | db59b3c | 2017-04-13 15:19:23 +0530 | [diff] [blame] | 10683 | if (wpa_command(intf, buf) < 0) { |
| 10684 | send_resp(dut, conn, SIGMA_ERROR, |
| 10685 | "ErrorCode,Failed to send ANQP query"); |
| 10686 | return 0; |
| 10687 | } |
| 10688 | |
| 10689 | return 1; |
| 10690 | } |
| 10691 | |
| 10692 | |
| 10693 | static int mbo_cmd_sta_send_frame(struct sigma_dut *dut, |
| 10694 | struct sigma_conn *conn, |
| 10695 | const char *intf, |
| 10696 | struct sigma_cmd *cmd) |
| 10697 | { |
| 10698 | const char *val = get_param(cmd, "FrameName"); |
| 10699 | |
| 10700 | if (val && strcasecmp(val, "ANQPQuery") == 0) |
| 10701 | return mbo_send_anqp_query(dut, conn, intf, cmd); |
| 10702 | |
| 10703 | return 2; |
| 10704 | } |
| 10705 | |
| 10706 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 10707 | enum sigma_cmd_result cmd_sta_send_frame(struct sigma_dut *dut, |
| 10708 | struct sigma_conn *conn, |
| 10709 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 10710 | { |
| 10711 | const char *intf = get_param(cmd, "Interface"); |
| 10712 | const char *val; |
| 10713 | enum send_frame_type frame; |
| 10714 | enum send_frame_protection protected; |
| 10715 | char buf[100]; |
| 10716 | unsigned char addr[ETH_ALEN]; |
| 10717 | int res; |
| 10718 | |
Alexei Avshalom Lazar | 4a3c2f8 | 2019-05-02 13:35:37 +0300 | [diff] [blame] | 10719 | if (!intf) |
| 10720 | return -1; |
| 10721 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 10722 | val = get_param(cmd, "program"); |
| 10723 | if (val == NULL) |
| 10724 | val = get_param(cmd, "frame"); |
| 10725 | if (val && strcasecmp(val, "TDLS") == 0) |
| 10726 | return cmd_sta_send_frame_tdls(dut, conn, cmd); |
| 10727 | if (val && (strcasecmp(val, "HS2") == 0 || |
Jouni Malinen | 1f6ae64 | 2018-06-07 23:56:13 +0300 | [diff] [blame] | 10728 | strcasecmp(val, "HS2-R2") == 0 || |
| 10729 | strcasecmp(val, "HS2-R3") == 0)) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 10730 | return cmd_sta_send_frame_hs2(dut, conn, cmd); |
| 10731 | if (val && strcasecmp(val, "VHT") == 0) |
| 10732 | return cmd_sta_send_frame_vht(dut, conn, cmd); |
Kiran Kumar Lokere | 419f696 | 2018-10-24 19:03:04 -0700 | [diff] [blame] | 10733 | if (val && strcasecmp(val, "HE") == 0) |
| 10734 | return cmd_sta_send_frame_he(dut, conn, cmd); |
priyadharshini gowthaman | d66913a | 2016-07-29 15:11:17 -0700 | [diff] [blame] | 10735 | if (val && strcasecmp(val, "LOC") == 0) |
| 10736 | return loc_cmd_sta_send_frame(dut, conn, cmd); |
Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 10737 | if (val && strcasecmp(val, "60GHz") == 0) |
| 10738 | return cmd_sta_send_frame_60g(dut, conn, cmd); |
Ashwini Patil | db59b3c | 2017-04-13 15:19:23 +0530 | [diff] [blame] | 10739 | if (val && strcasecmp(val, "MBO") == 0) { |
| 10740 | res = mbo_cmd_sta_send_frame(dut, conn, intf, cmd); |
| 10741 | if (res != 2) |
| 10742 | return res; |
| 10743 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 10744 | |
| 10745 | val = get_param(cmd, "TD_DISC"); |
| 10746 | if (val) { |
| 10747 | if (hwaddr_aton(val, addr) < 0) |
| 10748 | return -1; |
| 10749 | snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", val); |
| 10750 | if (wpa_command(intf, buf) < 0) { |
| 10751 | send_resp(dut, conn, SIGMA_ERROR, |
| 10752 | "ErrorCode,Failed to send TDLS discovery"); |
| 10753 | return 0; |
| 10754 | } |
| 10755 | return 1; |
| 10756 | } |
| 10757 | |
| 10758 | val = get_param(cmd, "TD_Setup"); |
| 10759 | if (val) { |
| 10760 | if (hwaddr_aton(val, addr) < 0) |
| 10761 | return -1; |
| 10762 | snprintf(buf, sizeof(buf), "TDLS_SETUP %s", val); |
| 10763 | if (wpa_command(intf, buf) < 0) { |
| 10764 | send_resp(dut, conn, SIGMA_ERROR, |
| 10765 | "ErrorCode,Failed to start TDLS setup"); |
| 10766 | return 0; |
| 10767 | } |
| 10768 | return 1; |
| 10769 | } |
| 10770 | |
| 10771 | val = get_param(cmd, "TD_TearDown"); |
| 10772 | if (val) { |
| 10773 | if (hwaddr_aton(val, addr) < 0) |
| 10774 | return -1; |
| 10775 | snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", val); |
| 10776 | if (wpa_command(intf, buf) < 0) { |
| 10777 | send_resp(dut, conn, SIGMA_ERROR, |
| 10778 | "ErrorCode,Failed to tear down TDLS link"); |
| 10779 | return 0; |
| 10780 | } |
| 10781 | return 1; |
| 10782 | } |
| 10783 | |
| 10784 | val = get_param(cmd, "TD_ChannelSwitch"); |
| 10785 | if (val) { |
| 10786 | /* TODO */ |
| 10787 | send_resp(dut, conn, SIGMA_ERROR, |
| 10788 | "ErrorCode,TD_ChannelSwitch not yet supported"); |
| 10789 | return 0; |
| 10790 | } |
| 10791 | |
| 10792 | val = get_param(cmd, "TD_NF"); |
| 10793 | if (val) { |
| 10794 | /* TODO */ |
| 10795 | send_resp(dut, conn, SIGMA_ERROR, |
| 10796 | "ErrorCode,TD_NF not yet supported"); |
| 10797 | return 0; |
| 10798 | } |
| 10799 | |
| 10800 | val = get_param(cmd, "PMFFrameType"); |
| 10801 | if (val == NULL) |
| 10802 | val = get_param(cmd, "FrameName"); |
| 10803 | if (val == NULL) |
| 10804 | val = get_param(cmd, "Type"); |
| 10805 | if (val == NULL) |
| 10806 | return -1; |
| 10807 | if (strcasecmp(val, "disassoc") == 0) |
| 10808 | frame = DISASSOC; |
| 10809 | else if (strcasecmp(val, "deauth") == 0) |
| 10810 | frame = DEAUTH; |
| 10811 | else if (strcasecmp(val, "saquery") == 0) |
| 10812 | frame = SAQUERY; |
| 10813 | else if (strcasecmp(val, "auth") == 0) |
| 10814 | frame = AUTH; |
| 10815 | else if (strcasecmp(val, "assocreq") == 0) |
| 10816 | frame = ASSOCREQ; |
| 10817 | else if (strcasecmp(val, "reassocreq") == 0) |
| 10818 | frame = REASSOCREQ; |
| 10819 | else if (strcasecmp(val, "neigreq") == 0) { |
| 10820 | sigma_dut_print(dut, DUT_MSG_INFO, "Got neighbor request"); |
| 10821 | |
| 10822 | val = get_param(cmd, "ssid"); |
| 10823 | if (val == NULL) |
| 10824 | return -1; |
| 10825 | |
| 10826 | res = send_neighbor_request(dut, intf, val); |
| 10827 | if (res) { |
| 10828 | send_resp(dut, conn, SIGMA_ERROR, "errorCode," |
| 10829 | "Failed to send neighbor report request"); |
| 10830 | return 0; |
| 10831 | } |
| 10832 | |
| 10833 | return 1; |
Ashwini Patil | 5acd738 | 2017-04-13 15:55:04 +0530 | [diff] [blame] | 10834 | } else if (strcasecmp(val, "transmgmtquery") == 0 || |
| 10835 | strcasecmp(val, "BTMQuery") == 0) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 10836 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 10837 | "Got Transition Management Query"); |
| 10838 | |
Ashwini Patil | 5acd738 | 2017-04-13 15:55:04 +0530 | [diff] [blame] | 10839 | res = send_trans_mgmt_query(dut, intf, cmd); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 10840 | if (res) { |
| 10841 | send_resp(dut, conn, SIGMA_ERROR, "errorCode," |
| 10842 | "Failed to send Transition Management Query"); |
| 10843 | return 0; |
| 10844 | } |
| 10845 | |
| 10846 | return 1; |
| 10847 | } else { |
| 10848 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported " |
| 10849 | "PMFFrameType"); |
| 10850 | return 0; |
| 10851 | } |
| 10852 | |
| 10853 | val = get_param(cmd, "PMFProtected"); |
| 10854 | if (val == NULL) |
| 10855 | val = get_param(cmd, "Protected"); |
| 10856 | if (val == NULL) |
| 10857 | return -1; |
| 10858 | if (strcasecmp(val, "Correct-key") == 0 || |
| 10859 | strcasecmp(val, "CorrectKey") == 0) |
| 10860 | protected = CORRECT_KEY; |
| 10861 | else if (strcasecmp(val, "IncorrectKey") == 0) |
| 10862 | protected = INCORRECT_KEY; |
| 10863 | else if (strcasecmp(val, "Unprotected") == 0) |
| 10864 | protected = UNPROTECTED; |
| 10865 | else { |
| 10866 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported " |
| 10867 | "PMFProtected"); |
| 10868 | return 0; |
| 10869 | } |
| 10870 | |
| 10871 | if (protected != UNPROTECTED && |
| 10872 | (frame == AUTH || frame == ASSOCREQ || frame == REASSOCREQ)) { |
| 10873 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Impossible " |
| 10874 | "PMFProtected for auth/assocreq/reassocreq"); |
| 10875 | return 0; |
| 10876 | } |
| 10877 | |
| 10878 | if (if_nametoindex("sigmadut") == 0) { |
| 10879 | snprintf(buf, sizeof(buf), |
| 10880 | "iw dev %s interface add sigmadut type monitor", |
| 10881 | get_station_ifname()); |
| 10882 | if (system(buf) != 0 || |
| 10883 | if_nametoindex("sigmadut") == 0) { |
| 10884 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add " |
| 10885 | "monitor interface with '%s'", buf); |
| 10886 | return -2; |
| 10887 | } |
| 10888 | } |
| 10889 | |
| 10890 | if (system("ifconfig sigmadut up") != 0) { |
| 10891 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set " |
| 10892 | "monitor interface up"); |
| 10893 | return -2; |
| 10894 | } |
| 10895 | |
| 10896 | return sta_inject_frame(dut, conn, frame, protected, NULL); |
| 10897 | } |
| 10898 | |
| 10899 | |
| 10900 | static int cmd_sta_set_parameter_hs2(struct sigma_dut *dut, |
| 10901 | struct sigma_conn *conn, |
| 10902 | struct sigma_cmd *cmd, |
| 10903 | const char *ifname) |
| 10904 | { |
| 10905 | char buf[200]; |
| 10906 | const char *val; |
| 10907 | |
| 10908 | val = get_param(cmd, "ClearARP"); |
| 10909 | if (val && atoi(val) == 1) { |
| 10910 | snprintf(buf, sizeof(buf), "ip neigh flush dev %s", ifname); |
| 10911 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 10912 | if (system(buf) != 0) { |
| 10913 | send_resp(dut, conn, SIGMA_ERROR, |
| 10914 | "errorCode,Failed to clear ARP cache"); |
| 10915 | return 0; |
| 10916 | } |
| 10917 | } |
| 10918 | |
| 10919 | return 1; |
| 10920 | } |
| 10921 | |
| 10922 | |
| 10923 | int cmd_sta_set_parameter(struct sigma_dut *dut, struct sigma_conn *conn, |
| 10924 | struct sigma_cmd *cmd) |
| 10925 | { |
| 10926 | const char *intf = get_param(cmd, "Interface"); |
| 10927 | const char *val; |
| 10928 | |
| 10929 | if (intf == NULL) |
| 10930 | return -1; |
| 10931 | |
| 10932 | val = get_param(cmd, "program"); |
| 10933 | if (val && (strcasecmp(val, "HS2") == 0 || |
Jouni Malinen | 1f6ae64 | 2018-06-07 23:56:13 +0300 | [diff] [blame] | 10934 | strcasecmp(val, "HS2-R2") == 0 || |
| 10935 | strcasecmp(val, "HS2-R3") == 0)) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 10936 | return cmd_sta_set_parameter_hs2(dut, conn, cmd, intf); |
| 10937 | |
| 10938 | return -1; |
| 10939 | } |
| 10940 | |
| 10941 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 10942 | static enum sigma_cmd_result cmd_sta_set_macaddr(struct sigma_dut *dut, |
| 10943 | struct sigma_conn *conn, |
| 10944 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 10945 | { |
| 10946 | const char *intf = get_param(cmd, "Interface"); |
| 10947 | const char *mac = get_param(cmd, "MAC"); |
| 10948 | |
| 10949 | if (intf == NULL || mac == NULL) |
| 10950 | return -1; |
| 10951 | |
| 10952 | sigma_dut_print(dut, DUT_MSG_INFO, "Change local MAC address for " |
| 10953 | "interface %s to %s", intf, mac); |
| 10954 | |
| 10955 | if (dut->set_macaddr) { |
| 10956 | char buf[128]; |
| 10957 | int res; |
| 10958 | if (strcasecmp(mac, "default") == 0) { |
| 10959 | res = snprintf(buf, sizeof(buf), "%s", |
| 10960 | dut->set_macaddr); |
| 10961 | dut->tmp_mac_addr = 0; |
| 10962 | } else { |
| 10963 | res = snprintf(buf, sizeof(buf), "%s %s", |
| 10964 | dut->set_macaddr, mac); |
| 10965 | dut->tmp_mac_addr = 1; |
| 10966 | } |
| 10967 | if (res < 0 || res >= (int) sizeof(buf)) |
| 10968 | return -1; |
| 10969 | if (system(buf) != 0) { |
| 10970 | send_resp(dut, conn, SIGMA_ERROR, |
| 10971 | "errorCode,Failed to set MAC " |
| 10972 | "address"); |
| 10973 | return 0; |
| 10974 | } |
| 10975 | return 1; |
| 10976 | } |
| 10977 | |
| 10978 | if (strcasecmp(mac, "default") == 0) |
| 10979 | return 1; |
| 10980 | |
| 10981 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported " |
| 10982 | "command"); |
| 10983 | return 0; |
| 10984 | } |
| 10985 | |
| 10986 | |
| 10987 | static int iwpriv_tdlsoffchnmode(struct sigma_dut *dut, |
| 10988 | struct sigma_conn *conn, const char *intf, |
| 10989 | int val) |
| 10990 | { |
| 10991 | char buf[200]; |
| 10992 | int res; |
| 10993 | |
| 10994 | res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchnmode %d", |
| 10995 | intf, val); |
| 10996 | if (res < 0 || res >= (int) sizeof(buf)) |
| 10997 | return -1; |
| 10998 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 10999 | if (system(buf) != 0) { |
| 11000 | send_resp(dut, conn, SIGMA_ERROR, |
| 11001 | "errorCode,Failed to configure offchannel mode"); |
| 11002 | return 0; |
| 11003 | } |
| 11004 | |
| 11005 | return 1; |
| 11006 | } |
| 11007 | |
| 11008 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 11009 | static int off_chan_val(enum sec_ch_offset off) |
| 11010 | { |
| 11011 | switch (off) { |
| 11012 | case SEC_CH_NO: |
| 11013 | return 0; |
| 11014 | case SEC_CH_40ABOVE: |
| 11015 | return 40; |
| 11016 | case SEC_CH_40BELOW: |
| 11017 | return -40; |
| 11018 | } |
| 11019 | |
| 11020 | return 0; |
| 11021 | } |
| 11022 | |
| 11023 | |
| 11024 | static int iwpriv_set_offchan(struct sigma_dut *dut, struct sigma_conn *conn, |
| 11025 | const char *intf, int off_ch_num, |
| 11026 | enum sec_ch_offset sec) |
| 11027 | { |
| 11028 | char buf[200]; |
| 11029 | int res; |
| 11030 | |
| 11031 | res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchan %d", |
| 11032 | intf, off_ch_num); |
| 11033 | if (res < 0 || res >= (int) sizeof(buf)) |
| 11034 | return -1; |
| 11035 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 11036 | if (system(buf) != 0) { |
| 11037 | send_resp(dut, conn, SIGMA_ERROR, |
| 11038 | "errorCode,Failed to set offchan"); |
| 11039 | return 0; |
| 11040 | } |
| 11041 | |
| 11042 | res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsecchnoffst %d", |
| 11043 | intf, off_chan_val(sec)); |
| 11044 | if (res < 0 || res >= (int) sizeof(buf)) |
| 11045 | return -1; |
| 11046 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 11047 | if (system(buf) != 0) { |
| 11048 | send_resp(dut, conn, SIGMA_ERROR, |
| 11049 | "errorCode,Failed to set sec chan offset"); |
| 11050 | return 0; |
| 11051 | } |
| 11052 | |
| 11053 | return 1; |
| 11054 | } |
| 11055 | |
| 11056 | |
| 11057 | static int tdls_set_offchannel_offset(struct sigma_dut *dut, |
| 11058 | struct sigma_conn *conn, |
| 11059 | const char *intf, int off_ch_num, |
| 11060 | enum sec_ch_offset sec) |
| 11061 | { |
| 11062 | char buf[200]; |
| 11063 | int res; |
| 11064 | |
| 11065 | res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNEL %d", |
| 11066 | off_ch_num); |
| 11067 | if (res < 0 || res >= (int) sizeof(buf)) |
| 11068 | return -1; |
| 11069 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 11070 | |
| 11071 | if (wpa_command(intf, buf) < 0) { |
| 11072 | send_resp(dut, conn, SIGMA_ERROR, |
| 11073 | "ErrorCode,Failed to set offchan"); |
| 11074 | return 0; |
| 11075 | } |
| 11076 | res = snprintf(buf, sizeof(buf), "DRIVER TDLSSECONDARYCHANNELOFFSET %d", |
| 11077 | off_chan_val(sec)); |
| 11078 | if (res < 0 || res >= (int) sizeof(buf)) |
| 11079 | return -1; |
| 11080 | |
| 11081 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 11082 | |
| 11083 | if (wpa_command(intf, buf) < 0) { |
| 11084 | send_resp(dut, conn, SIGMA_ERROR, |
| 11085 | "ErrorCode,Failed to set sec chan offset"); |
| 11086 | return 0; |
| 11087 | } |
| 11088 | |
| 11089 | return 1; |
| 11090 | } |
| 11091 | |
| 11092 | |
| 11093 | static int tdls_set_offchannel_mode(struct sigma_dut *dut, |
| 11094 | struct sigma_conn *conn, |
| 11095 | const char *intf, int val) |
| 11096 | { |
| 11097 | char buf[200]; |
| 11098 | int res; |
| 11099 | |
| 11100 | res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNELMODE %d", |
| 11101 | val); |
| 11102 | if (res < 0 || res >= (int) sizeof(buf)) |
| 11103 | return -1; |
| 11104 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 11105 | |
| 11106 | if (wpa_command(intf, buf) < 0) { |
| 11107 | send_resp(dut, conn, SIGMA_ERROR, |
| 11108 | "ErrorCode,Failed to configure offchannel mode"); |
| 11109 | return 0; |
| 11110 | } |
| 11111 | |
| 11112 | return 1; |
| 11113 | } |
| 11114 | |
| 11115 | |
| 11116 | static int cmd_sta_set_rfeature_tdls(const char *intf, struct sigma_dut *dut, |
| 11117 | struct sigma_conn *conn, |
| 11118 | struct sigma_cmd *cmd) |
| 11119 | { |
| 11120 | const char *val; |
| 11121 | enum { |
| 11122 | CHSM_NOT_SET, |
| 11123 | CHSM_ENABLE, |
| 11124 | CHSM_DISABLE, |
| 11125 | CHSM_REJREQ, |
| 11126 | CHSM_UNSOLRESP |
| 11127 | } chsm = CHSM_NOT_SET; |
| 11128 | int off_ch_num = -1; |
| 11129 | enum sec_ch_offset sec_ch = SEC_CH_NO; |
| 11130 | int res; |
| 11131 | |
| 11132 | val = get_param(cmd, "Uapsd"); |
| 11133 | if (val) { |
| 11134 | char buf[100]; |
| 11135 | if (strcasecmp(val, "Enable") == 0) |
| 11136 | snprintf(buf, sizeof(buf), "SET ps 99"); |
| 11137 | else if (strcasecmp(val, "Disable") == 0) |
| 11138 | snprintf(buf, sizeof(buf), "SET ps 98"); |
| 11139 | else { |
| 11140 | send_resp(dut, conn, SIGMA_ERROR, "errorCode," |
| 11141 | "Unsupported uapsd parameter value"); |
| 11142 | return 0; |
| 11143 | } |
| 11144 | if (wpa_command(intf, buf)) { |
| 11145 | send_resp(dut, conn, SIGMA_ERROR, |
| 11146 | "ErrorCode,Failed to change U-APSD " |
| 11147 | "powersave mode"); |
| 11148 | return 0; |
| 11149 | } |
| 11150 | } |
| 11151 | |
| 11152 | val = get_param(cmd, "TPKTIMER"); |
| 11153 | if (val && strcasecmp(val, "DISABLE") == 0) { |
| 11154 | if (wpa_command(intf, "SET tdls_testing 0x100")) { |
| 11155 | send_resp(dut, conn, SIGMA_ERROR, |
| 11156 | "ErrorCode,Failed to enable no TPK " |
| 11157 | "expiration test mode"); |
| 11158 | return 0; |
| 11159 | } |
| 11160 | dut->no_tpk_expiration = 1; |
| 11161 | } |
| 11162 | |
| 11163 | val = get_param(cmd, "ChSwitchMode"); |
| 11164 | if (val) { |
| 11165 | if (strcasecmp(val, "Enable") == 0 || |
| 11166 | strcasecmp(val, "Initiate") == 0) |
| 11167 | chsm = CHSM_ENABLE; |
| 11168 | else if (strcasecmp(val, "Disable") == 0 || |
| 11169 | strcasecmp(val, "passive") == 0) |
| 11170 | chsm = CHSM_DISABLE; |
| 11171 | else if (strcasecmp(val, "RejReq") == 0) |
| 11172 | chsm = CHSM_REJREQ; |
| 11173 | else if (strcasecmp(val, "UnSolResp") == 0) |
| 11174 | chsm = CHSM_UNSOLRESP; |
| 11175 | else { |
| 11176 | send_resp(dut, conn, SIGMA_ERROR, |
| 11177 | "ErrorCode,Unknown ChSwitchMode value"); |
| 11178 | return 0; |
| 11179 | } |
| 11180 | } |
| 11181 | |
| 11182 | val = get_param(cmd, "OffChNum"); |
| 11183 | if (val) { |
| 11184 | off_ch_num = atoi(val); |
| 11185 | if (off_ch_num == 0) { |
| 11186 | send_resp(dut, conn, SIGMA_ERROR, |
| 11187 | "ErrorCode,Invalid OffChNum"); |
| 11188 | return 0; |
| 11189 | } |
| 11190 | } |
| 11191 | |
| 11192 | val = get_param(cmd, "SecChOffset"); |
| 11193 | if (val) { |
| 11194 | if (strcmp(val, "20") == 0) |
| 11195 | sec_ch = SEC_CH_NO; |
| 11196 | else if (strcasecmp(val, "40above") == 0) |
| 11197 | sec_ch = SEC_CH_40ABOVE; |
| 11198 | else if (strcasecmp(val, "40below") == 0) |
| 11199 | sec_ch = SEC_CH_40BELOW; |
| 11200 | else { |
| 11201 | send_resp(dut, conn, SIGMA_ERROR, |
| 11202 | "ErrorCode,Unknown SecChOffset value"); |
| 11203 | return 0; |
| 11204 | } |
| 11205 | } |
| 11206 | |
| 11207 | if (chsm == CHSM_NOT_SET) { |
| 11208 | /* no offchannel changes requested */ |
| 11209 | return 1; |
| 11210 | } |
| 11211 | |
| 11212 | if (strcmp(intf, get_main_ifname()) != 0 && |
| 11213 | strcmp(intf, get_station_ifname()) != 0) { |
| 11214 | send_resp(dut, conn, SIGMA_ERROR, |
| 11215 | "ErrorCode,Unknown interface"); |
| 11216 | return 0; |
| 11217 | } |
| 11218 | |
| 11219 | switch (chsm) { |
| 11220 | case CHSM_NOT_SET: |
Jouni Malinen | 280f5ba | 2016-08-29 21:33:10 +0300 | [diff] [blame] | 11221 | res = 1; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 11222 | break; |
| 11223 | case CHSM_ENABLE: |
| 11224 | if (off_ch_num < 0) { |
| 11225 | send_resp(dut, conn, SIGMA_ERROR, |
| 11226 | "ErrorCode,Missing OffChNum argument"); |
| 11227 | return 0; |
| 11228 | } |
| 11229 | if (wifi_chip_type == DRIVER_WCN) { |
| 11230 | res = tdls_set_offchannel_offset(dut, conn, intf, |
| 11231 | off_ch_num, sec_ch); |
| 11232 | } else { |
| 11233 | res = iwpriv_set_offchan(dut, conn, intf, off_ch_num, |
| 11234 | sec_ch); |
| 11235 | } |
| 11236 | if (res != 1) |
| 11237 | return res; |
| 11238 | if (wifi_chip_type == DRIVER_WCN) |
| 11239 | res = tdls_set_offchannel_mode(dut, conn, intf, 1); |
| 11240 | else |
| 11241 | res = iwpriv_tdlsoffchnmode(dut, conn, intf, 1); |
| 11242 | break; |
| 11243 | case CHSM_DISABLE: |
| 11244 | if (wifi_chip_type == DRIVER_WCN) |
| 11245 | res = tdls_set_offchannel_mode(dut, conn, intf, 2); |
| 11246 | else |
| 11247 | res = iwpriv_tdlsoffchnmode(dut, conn, intf, 2); |
| 11248 | break; |
| 11249 | case CHSM_REJREQ: |
| 11250 | if (wifi_chip_type == DRIVER_WCN) |
| 11251 | res = tdls_set_offchannel_mode(dut, conn, intf, 3); |
| 11252 | else |
| 11253 | res = iwpriv_tdlsoffchnmode(dut, conn, intf, 3); |
| 11254 | break; |
| 11255 | case CHSM_UNSOLRESP: |
| 11256 | if (off_ch_num < 0) { |
| 11257 | send_resp(dut, conn, SIGMA_ERROR, |
| 11258 | "ErrorCode,Missing OffChNum argument"); |
| 11259 | return 0; |
| 11260 | } |
| 11261 | if (wifi_chip_type == DRIVER_WCN) { |
| 11262 | res = tdls_set_offchannel_offset(dut, conn, intf, |
| 11263 | off_ch_num, sec_ch); |
| 11264 | } else { |
| 11265 | res = iwpriv_set_offchan(dut, conn, intf, off_ch_num, |
| 11266 | sec_ch); |
| 11267 | } |
| 11268 | if (res != 1) |
| 11269 | return res; |
| 11270 | if (wifi_chip_type == DRIVER_WCN) |
| 11271 | res = tdls_set_offchannel_mode(dut, conn, intf, 4); |
| 11272 | else |
| 11273 | res = iwpriv_tdlsoffchnmode(dut, conn, intf, 4); |
| 11274 | break; |
| 11275 | } |
| 11276 | |
| 11277 | return res; |
| 11278 | } |
| 11279 | |
| 11280 | |
| 11281 | static int ath_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut, |
| 11282 | struct sigma_conn *conn, |
| 11283 | struct sigma_cmd *cmd) |
| 11284 | { |
| 11285 | const char *val; |
Srikanth Marepalli | 5415acf | 2018-08-27 12:53:11 +0530 | [diff] [blame] | 11286 | char *token = NULL, *result; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 11287 | |
Priyadharshini Gowthaman | 8c5b9a4 | 2019-07-31 14:38:48 -0700 | [diff] [blame] | 11288 | novap_reset(dut, intf, 1); |
priyadharshini gowthaman | e5e2517 | 2015-12-08 14:53:48 -0800 | [diff] [blame] | 11289 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 11290 | val = get_param(cmd, "nss_mcs_opt"); |
| 11291 | if (val) { |
| 11292 | /* String (nss_operating_mode; mcs_operating_mode) */ |
| 11293 | int nss, mcs; |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 11294 | char *saveptr; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 11295 | |
| 11296 | token = strdup(val); |
| 11297 | if (!token) |
| 11298 | return 0; |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 11299 | result = strtok_r(token, ";", &saveptr); |
Pradeep Reddy POTTETI | 41b8c54 | 2016-06-15 16:09:46 +0530 | [diff] [blame] | 11300 | if (!result) { |
| 11301 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 11302 | "VHT NSS not specified"); |
| 11303 | goto failed; |
| 11304 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 11305 | if (strcasecmp(result, "def") != 0) { |
| 11306 | nss = atoi(result); |
| 11307 | if (nss == 4) |
| 11308 | ath_disable_txbf(dut, intf); |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 11309 | if (run_iwpriv(dut, intf, "nss %d", nss) < 0) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 11310 | goto failed; |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 11311 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 11312 | } |
| 11313 | |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 11314 | result = strtok_r(NULL, ";", &saveptr); |
Pradeep Reddy POTTETI | 41b8c54 | 2016-06-15 16:09:46 +0530 | [diff] [blame] | 11315 | if (!result) { |
| 11316 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 11317 | "VHT MCS not specified"); |
| 11318 | goto failed; |
| 11319 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 11320 | if (strcasecmp(result, "def") == 0) { |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 11321 | if (run_iwpriv(dut, intf, "set11NRates 0") < 0) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 11322 | goto failed; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 11323 | } else { |
| 11324 | mcs = atoi(result); |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 11325 | if (run_iwpriv(dut, intf, "vhtmcs %d", mcs) < 0) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 11326 | goto failed; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 11327 | } |
| 11328 | /* Channel width gets messed up, fix this */ |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 11329 | run_iwpriv(dut, intf, "chwidth %d", dut->chwidth); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 11330 | } |
| 11331 | |
Srikanth Marepalli | 5415acf | 2018-08-27 12:53:11 +0530 | [diff] [blame] | 11332 | free(token); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 11333 | return 1; |
| 11334 | failed: |
| 11335 | free(token); |
| 11336 | return 0; |
| 11337 | } |
| 11338 | |
| 11339 | |
| 11340 | static int cmd_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut, |
| 11341 | struct sigma_conn *conn, |
| 11342 | struct sigma_cmd *cmd) |
| 11343 | { |
| 11344 | switch (get_driver_type()) { |
| 11345 | case DRIVER_ATHEROS: |
| 11346 | return ath_sta_set_rfeature_vht(intf, dut, conn, cmd); |
| 11347 | default: |
| 11348 | send_resp(dut, conn, SIGMA_ERROR, |
| 11349 | "errorCode,Unsupported sta_set_rfeature(VHT) with the current driver"); |
| 11350 | return 0; |
| 11351 | } |
| 11352 | } |
| 11353 | |
| 11354 | |
Amarnath Hullur Subramanyam | 42c25a0 | 2018-01-31 04:02:27 -0800 | [diff] [blame] | 11355 | static int wcn_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut, |
| 11356 | struct sigma_conn *conn, |
| 11357 | struct sigma_cmd *cmd) |
| 11358 | { |
| 11359 | const char *val; |
| 11360 | char *token = NULL, *result; |
| 11361 | char buf[60]; |
| 11362 | |
| 11363 | val = get_param(cmd, "nss_mcs_opt"); |
| 11364 | if (val) { |
| 11365 | /* String (nss_operating_mode; mcs_operating_mode) */ |
| 11366 | int nss, mcs, ratecode; |
| 11367 | char *saveptr; |
| 11368 | |
| 11369 | token = strdup(val); |
| 11370 | if (!token) |
| 11371 | return -2; |
| 11372 | |
| 11373 | result = strtok_r(token, ";", &saveptr); |
| 11374 | if (!result) { |
| 11375 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 11376 | "HE NSS not specified"); |
| 11377 | goto failed; |
| 11378 | } |
| 11379 | nss = 1; |
| 11380 | if (strcasecmp(result, "def") != 0) |
| 11381 | nss = atoi(result); |
| 11382 | |
| 11383 | result = strtok_r(NULL, ";", &saveptr); |
| 11384 | if (!result) { |
| 11385 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 11386 | "HE MCS not specified"); |
| 11387 | goto failed; |
| 11388 | } |
| 11389 | mcs = 7; |
| 11390 | if (strcasecmp(result, "def") != 0) |
| 11391 | mcs = atoi(result); |
| 11392 | |
Arif Hussain | 557bf41 | 2018-05-25 17:29:36 -0700 | [diff] [blame] | 11393 | ratecode = 0x20; /* for nss:1 MCS 0 */ |
Amarnath Hullur Subramanyam | 42c25a0 | 2018-01-31 04:02:27 -0800 | [diff] [blame] | 11394 | if (nss == 2) { |
Arif Hussain | 557bf41 | 2018-05-25 17:29:36 -0700 | [diff] [blame] | 11395 | ratecode = 0x40; /* for nss:2 MCS 0 */ |
Amarnath Hullur Subramanyam | 42c25a0 | 2018-01-31 04:02:27 -0800 | [diff] [blame] | 11396 | } else if (nss > 2) { |
| 11397 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 11398 | "HE NSS %d not supported", nss); |
| 11399 | goto failed; |
| 11400 | } |
| 11401 | |
Arif Hussain | 557bf41 | 2018-05-25 17:29:36 -0700 | [diff] [blame] | 11402 | snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss); |
| 11403 | if (system(buf) != 0) { |
| 11404 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 11405 | "nss_mcs_opt: iwpriv %s nss %d failed", |
| 11406 | intf, nss); |
| 11407 | goto failed; |
| 11408 | } |
Arif Hussain | ac6c511 | 2018-05-25 17:34:00 -0700 | [diff] [blame] | 11409 | dut->sta_nss = nss; |
Arif Hussain | 557bf41 | 2018-05-25 17:29:36 -0700 | [diff] [blame] | 11410 | |
Amarnath Hullur Subramanyam | 42c25a0 | 2018-01-31 04:02:27 -0800 | [diff] [blame] | 11411 | /* Add the MCS to the ratecode */ |
| 11412 | if (mcs >= 0 && mcs <= 11) { |
| 11413 | ratecode += mcs; |
Arif Hussain | 557bf41 | 2018-05-25 17:29:36 -0700 | [diff] [blame] | 11414 | #ifdef NL80211_SUPPORT |
| 11415 | if (dut->device_type == STA_testbed) { |
| 11416 | enum he_mcs_config mcs_config; |
| 11417 | int ret; |
| 11418 | |
| 11419 | if (mcs <= 7) |
| 11420 | mcs_config = HE_80_MCS0_7; |
| 11421 | else if (mcs <= 9) |
| 11422 | mcs_config = HE_80_MCS0_9; |
| 11423 | else |
| 11424 | mcs_config = HE_80_MCS0_11; |
| 11425 | ret = sta_set_he_mcs(dut, intf, mcs_config); |
| 11426 | if (ret) { |
| 11427 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 11428 | "nss_mcs_opt: mcs setting failed, mcs:%d, mcs_config %d, ret:%d", |
| 11429 | mcs, mcs_config, ret); |
| 11430 | goto failed; |
| 11431 | } |
| 11432 | } |
| 11433 | #endif /* NL80211_SUPPORT */ |
Amarnath Hullur Subramanyam | 42c25a0 | 2018-01-31 04:02:27 -0800 | [diff] [blame] | 11434 | } else { |
| 11435 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 11436 | "HE MCS %d not supported", mcs); |
| 11437 | goto failed; |
| 11438 | } |
| 11439 | snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0x%03x", |
| 11440 | intf, ratecode); |
| 11441 | if (system(buf) != 0) { |
| 11442 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 11443 | "iwpriv setting of 11ax rates failed"); |
| 11444 | goto failed; |
| 11445 | } |
| 11446 | free(token); |
| 11447 | } |
| 11448 | |
| 11449 | val = get_param(cmd, "GI"); |
| 11450 | if (val) { |
Kiran Kumar Lokere | f6592d7 | 2019-01-16 18:44:00 -0800 | [diff] [blame] | 11451 | int fix_rate_sgi; |
| 11452 | |
Amarnath Hullur Subramanyam | 42c25a0 | 2018-01-31 04:02:27 -0800 | [diff] [blame] | 11453 | if (strcmp(val, "0.8") == 0) { |
Kiran Kumar Lokere | b8fec52 | 2018-05-01 14:26:00 -0700 | [diff] [blame] | 11454 | snprintf(buf, sizeof(buf), "iwpriv %s shortgi 9", intf); |
Kiran Kumar Lokere | f6592d7 | 2019-01-16 18:44:00 -0800 | [diff] [blame] | 11455 | fix_rate_sgi = 1; |
Amarnath Hullur Subramanyam | 42c25a0 | 2018-01-31 04:02:27 -0800 | [diff] [blame] | 11456 | } else if (strcmp(val, "1.6") == 0) { |
Kiran Kumar Lokere | b8fec52 | 2018-05-01 14:26:00 -0700 | [diff] [blame] | 11457 | snprintf(buf, sizeof(buf), "iwpriv %s shortgi 10", |
| 11458 | intf); |
Kiran Kumar Lokere | f6592d7 | 2019-01-16 18:44:00 -0800 | [diff] [blame] | 11459 | fix_rate_sgi = 2; |
Amarnath Hullur Subramanyam | 42c25a0 | 2018-01-31 04:02:27 -0800 | [diff] [blame] | 11460 | } else if (strcmp(val, "3.2") == 0) { |
Kiran Kumar Lokere | b8fec52 | 2018-05-01 14:26:00 -0700 | [diff] [blame] | 11461 | snprintf(buf, sizeof(buf), "iwpriv %s shortgi 11", |
| 11462 | intf); |
Kiran Kumar Lokere | f6592d7 | 2019-01-16 18:44:00 -0800 | [diff] [blame] | 11463 | fix_rate_sgi = 3; |
Amarnath Hullur Subramanyam | 42c25a0 | 2018-01-31 04:02:27 -0800 | [diff] [blame] | 11464 | } else { |
| 11465 | send_resp(dut, conn, SIGMA_ERROR, |
| 11466 | "errorCode,GI value not supported"); |
| 11467 | return 0; |
| 11468 | } |
| 11469 | if (system(buf) != 0) { |
| 11470 | send_resp(dut, conn, SIGMA_ERROR, |
| 11471 | "errorCode,Failed to set shortgi"); |
| 11472 | return 0; |
| 11473 | } |
Kiran Kumar Lokere | f6592d7 | 2019-01-16 18:44:00 -0800 | [diff] [blame] | 11474 | snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d", |
| 11475 | intf, fix_rate_sgi); |
| 11476 | if (system(buf) != 0) { |
| 11477 | send_resp(dut, conn, SIGMA_ERROR, |
| 11478 | "errorCode,Failed to set fix rate shortgi"); |
| 11479 | return STATUS_SENT; |
| 11480 | } |
Amarnath Hullur Subramanyam | 42c25a0 | 2018-01-31 04:02:27 -0800 | [diff] [blame] | 11481 | } |
| 11482 | |
Subhani Shaik | 8e7a305 | 2018-04-24 14:03:00 -0700 | [diff] [blame] | 11483 | val = get_param(cmd, "LTF"); |
| 11484 | if (val) { |
| 11485 | #ifdef NL80211_SUPPORT |
| 11486 | if (strcmp(val, "3.2") == 0) { |
| 11487 | sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_1X); |
| 11488 | } if (strcmp(val, "6.4") == 0) { |
| 11489 | sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_2X); |
| 11490 | } else if (strcmp(val, "12.8") == 0) { |
| 11491 | sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_4X); |
| 11492 | } else { |
| 11493 | send_resp(dut, conn, SIGMA_ERROR, |
| 11494 | "errorCode, LTF value not supported"); |
| 11495 | return 0; |
| 11496 | } |
| 11497 | #else /* NL80211_SUPPORT */ |
| 11498 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 11499 | "LTF cannot be set without NL80211_SUPPORT defined"); |
| 11500 | return -2; |
| 11501 | #endif /* NL80211_SUPPORT */ |
| 11502 | } |
| 11503 | |
Kiran Kumar Lokere | 400d68f | 2018-08-29 18:45:11 -0700 | [diff] [blame] | 11504 | val = get_param(cmd, "TxSUPPDU"); |
| 11505 | if (val) { |
| 11506 | int set_val = 1; |
| 11507 | |
| 11508 | if (strcasecmp(val, "Enable") == 0) |
| 11509 | set_val = 1; |
| 11510 | else if (strcasecmp(val, "Disable") == 0) |
| 11511 | set_val = 0; |
| 11512 | |
| 11513 | if (sta_set_tx_su_ppdu_cfg(dut, intf, set_val)) { |
| 11514 | send_resp(dut, conn, SIGMA_ERROR, |
| 11515 | "ErrorCode,Failed to set Tx SU PPDU config"); |
| 11516 | return 0; |
| 11517 | } |
| 11518 | } |
| 11519 | |
Arif Hussain | 480d5f4 | 2019-03-12 14:40:42 -0700 | [diff] [blame] | 11520 | val = get_param(cmd, "TWT_Setup"); |
| 11521 | if (val) { |
| 11522 | if (strcasecmp(val, "Request") == 0) { |
| 11523 | if (sta_twt_request(dut, conn, cmd)) { |
| 11524 | send_resp(dut, conn, SIGMA_ERROR, |
| 11525 | "ErrorCode,sta_twt_request failed"); |
| 11526 | return STATUS_SENT; |
| 11527 | } |
| 11528 | } else if (strcasecmp(val, "Teardown") == 0) { |
| 11529 | if (sta_twt_teardown(dut, conn, cmd)) { |
| 11530 | send_resp(dut, conn, SIGMA_ERROR, |
| 11531 | "ErrorCode,sta_twt_teardown failed"); |
| 11532 | return STATUS_SENT; |
| 11533 | } |
| 11534 | } |
| 11535 | } |
| 11536 | |
Kiran Kumar Lokere | 50eb2cd | 2018-12-18 18:31:28 -0800 | [diff] [blame] | 11537 | val = get_param(cmd, "transmitOMI"); |
| 11538 | if (val && sta_transmit_omi(dut, conn, cmd)) { |
| 11539 | send_resp(dut, conn, SIGMA_ERROR, |
| 11540 | "ErrorCode,sta_transmit_omi failed"); |
| 11541 | return STATUS_SENT; |
Kiran Kumar Lokere | 29c1bb0 | 2018-10-08 17:41:02 -0700 | [diff] [blame] | 11542 | } |
| 11543 | |
Kiran Kumar Lokere | c310dcd | 2018-12-17 20:56:06 -0800 | [diff] [blame] | 11544 | val = get_param(cmd, "Powersave"); |
| 11545 | if (val) { |
| 11546 | char buf[60]; |
| 11547 | |
| 11548 | if (strcasecmp(val, "off") == 0) { |
| 11549 | snprintf(buf, sizeof(buf), |
| 11550 | "iwpriv %s setPower 2", intf); |
| 11551 | if (system(buf) != 0) { |
| 11552 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 11553 | "iwpriv setPower 2 failed"); |
| 11554 | return 0; |
| 11555 | } |
| 11556 | } else if (strcasecmp(val, "on") == 0) { |
| 11557 | snprintf(buf, sizeof(buf), |
| 11558 | "iwpriv %s setPower 1", intf); |
| 11559 | if (system(buf) != 0) { |
| 11560 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 11561 | "iwpriv setPower 1 failed"); |
| 11562 | return 0; |
| 11563 | } |
| 11564 | } else { |
| 11565 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 11566 | "Unsupported Powersave value '%s'", |
| 11567 | val); |
| 11568 | return -1; |
| 11569 | } |
| 11570 | } |
| 11571 | |
Kiran Kumar Lokere | 2c4b7ce | 2019-01-30 12:02:28 -0800 | [diff] [blame] | 11572 | val = get_param(cmd, "MU_EDCA"); |
| 11573 | if (val) { |
| 11574 | if (strcasecmp(val, "Override") == 0) { |
| 11575 | if (sta_set_mu_edca_override(dut, intf, 1)) { |
| 11576 | send_resp(dut, conn, SIGMA_ERROR, |
| 11577 | "errorCode,MU EDCA override set failed"); |
| 11578 | return STATUS_SENT; |
| 11579 | } |
| 11580 | } else if (strcasecmp(val, "Disable") == 0) { |
| 11581 | if (sta_set_mu_edca_override(dut, intf, 0)) { |
| 11582 | send_resp(dut, conn, SIGMA_ERROR, |
| 11583 | "errorCode,MU EDCA override disable failed"); |
| 11584 | return STATUS_SENT; |
| 11585 | } |
| 11586 | } |
| 11587 | } |
| 11588 | |
Amarnath Hullur Subramanyam | 42c25a0 | 2018-01-31 04:02:27 -0800 | [diff] [blame] | 11589 | return 1; |
| 11590 | |
| 11591 | failed: |
| 11592 | free(token); |
| 11593 | return -2; |
| 11594 | } |
| 11595 | |
| 11596 | |
| 11597 | static int cmd_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut, |
| 11598 | struct sigma_conn *conn, |
| 11599 | struct sigma_cmd *cmd) |
| 11600 | { |
| 11601 | switch (get_driver_type()) { |
| 11602 | case DRIVER_WCN: |
| 11603 | return wcn_sta_set_rfeature_he(intf, dut, conn, cmd); |
| 11604 | default: |
| 11605 | send_resp(dut, conn, SIGMA_ERROR, |
| 11606 | "errorCode,Unsupported sta_set_rfeature(HE) with the current driver"); |
| 11607 | return 0; |
| 11608 | } |
| 11609 | } |
| 11610 | |
| 11611 | |
Kiran Kumar Lokere | e580c01 | 2019-01-03 17:08:53 -0800 | [diff] [blame] | 11612 | static int cmd_sta_set_power_save_he(const char *intf, struct sigma_dut *dut, |
| 11613 | struct sigma_conn *conn, |
| 11614 | struct sigma_cmd *cmd) |
| 11615 | { |
| 11616 | const char *val; |
| 11617 | |
| 11618 | val = get_param(cmd, "powersave"); |
| 11619 | if (val) { |
| 11620 | char buf[60]; |
| 11621 | |
| 11622 | if (strcasecmp(val, "off") == 0) { |
| 11623 | snprintf(buf, sizeof(buf), "iwpriv %s setPower 2", |
| 11624 | intf); |
| 11625 | if (system(buf) != 0) { |
| 11626 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 11627 | "iwpriv setPower 2 failed"); |
| 11628 | return 0; |
| 11629 | } |
| 11630 | } else if (strcasecmp(val, "on") == 0) { |
| 11631 | snprintf(buf, sizeof(buf), "iwpriv %s setPower 1", |
| 11632 | intf); |
| 11633 | if (system(buf) != 0) { |
| 11634 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 11635 | "iwpriv setPower 1 failed"); |
| 11636 | return 0; |
| 11637 | } |
| 11638 | } else { |
| 11639 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 11640 | "Unsupported power save config"); |
| 11641 | return -1; |
| 11642 | } |
| 11643 | return 1; |
| 11644 | } |
| 11645 | |
| 11646 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported command"); |
| 11647 | |
| 11648 | return 0; |
| 11649 | } |
| 11650 | |
| 11651 | |
Ashwini Patil | 5acd738 | 2017-04-13 15:55:04 +0530 | [diff] [blame] | 11652 | static int btm_query_candidate_list(struct sigma_dut *dut, |
| 11653 | struct sigma_conn *conn, |
| 11654 | struct sigma_cmd *cmd) |
| 11655 | { |
| 11656 | const char *bssid, *info, *op_class, *ch, *phy_type, *pref; |
| 11657 | int len, ret; |
| 11658 | char buf[10]; |
| 11659 | |
| 11660 | /* |
| 11661 | * Neighbor Report elements format: |
| 11662 | * neighbor=<BSSID>,<BSSID Information>,<Operating Class>, |
| 11663 | * <Channel Number>,<PHY Type>[,<hexdump of Optional Subelements>] |
| 11664 | * eg: neighbor=aa:bb:cc:dd:ee:ff,17,81,6,1,030101 |
| 11665 | */ |
| 11666 | |
| 11667 | bssid = get_param(cmd, "Nebor_BSSID"); |
| 11668 | if (!bssid) { |
| 11669 | send_resp(dut, conn, SIGMA_INVALID, |
| 11670 | "errorCode,Nebor_BSSID is missing"); |
| 11671 | return 0; |
| 11672 | } |
| 11673 | |
| 11674 | info = get_param(cmd, "Nebor_Bssid_Info"); |
| 11675 | if (!info) { |
| 11676 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 11677 | "Using default value for Nebor_Bssid_Info: %s", |
| 11678 | DEFAULT_NEIGHBOR_BSSID_INFO); |
| 11679 | info = DEFAULT_NEIGHBOR_BSSID_INFO; |
| 11680 | } |
| 11681 | |
| 11682 | op_class = get_param(cmd, "Nebor_Op_Class"); |
| 11683 | if (!op_class) { |
| 11684 | send_resp(dut, conn, SIGMA_INVALID, |
| 11685 | "errorCode,Nebor_Op_Class is missing"); |
| 11686 | return 0; |
| 11687 | } |
| 11688 | |
| 11689 | ch = get_param(cmd, "Nebor_Op_Ch"); |
| 11690 | if (!ch) { |
| 11691 | send_resp(dut, conn, SIGMA_INVALID, |
| 11692 | "errorCode,Nebor_Op_Ch is missing"); |
| 11693 | return 0; |
| 11694 | } |
| 11695 | |
| 11696 | phy_type = get_param(cmd, "Nebor_Phy_Type"); |
| 11697 | if (!phy_type) { |
| 11698 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 11699 | "Using default value for Nebor_Phy_Type: %s", |
| 11700 | DEFAULT_NEIGHBOR_PHY_TYPE); |
| 11701 | phy_type = DEFAULT_NEIGHBOR_PHY_TYPE; |
| 11702 | } |
| 11703 | |
| 11704 | /* Parse optional subelements */ |
| 11705 | buf[0] = '\0'; |
| 11706 | pref = get_param(cmd, "Nebor_Pref"); |
| 11707 | if (pref) { |
| 11708 | /* hexdump for preferrence subelement */ |
| 11709 | ret = snprintf(buf, sizeof(buf), ",0301%02x", atoi(pref)); |
| 11710 | if (ret < 0 || ret >= (int) sizeof(buf)) { |
| 11711 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 11712 | "snprintf failed for optional subelement ret: %d", |
| 11713 | ret); |
| 11714 | send_resp(dut, conn, SIGMA_ERROR, |
| 11715 | "errorCode,snprintf failed for subelement"); |
| 11716 | return 0; |
| 11717 | } |
| 11718 | } |
| 11719 | |
| 11720 | if (!dut->btm_query_cand_list) { |
| 11721 | dut->btm_query_cand_list = calloc(1, NEIGHBOR_REPORT_SIZE); |
| 11722 | if (!dut->btm_query_cand_list) { |
| 11723 | send_resp(dut, conn, SIGMA_ERROR, |
| 11724 | "errorCode,Failed to allocate memory for btm_query_cand_list"); |
| 11725 | return 0; |
| 11726 | } |
| 11727 | } |
| 11728 | |
| 11729 | len = strlen(dut->btm_query_cand_list); |
| 11730 | ret = snprintf(dut->btm_query_cand_list + len, |
| 11731 | NEIGHBOR_REPORT_SIZE - len, " neighbor=%s,%s,%s,%s,%s%s", |
| 11732 | bssid, info, op_class, ch, phy_type, buf); |
| 11733 | if (ret < 0 || ret >= NEIGHBOR_REPORT_SIZE - len) { |
| 11734 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 11735 | "snprintf failed for neighbor report list ret: %d", |
| 11736 | ret); |
| 11737 | send_resp(dut, conn, SIGMA_ERROR, |
| 11738 | "errorCode,snprintf failed for neighbor report"); |
| 11739 | free(dut->btm_query_cand_list); |
| 11740 | dut->btm_query_cand_list = NULL; |
| 11741 | return 0; |
| 11742 | } |
| 11743 | |
| 11744 | return 1; |
| 11745 | } |
| 11746 | |
| 11747 | |
Alexei Avshalom Lazar | bc180dc | 2018-12-18 16:01:14 +0200 | [diff] [blame] | 11748 | int sta_extract_60g_ese(struct sigma_dut *dut, struct sigma_cmd *cmd, |
| 11749 | struct sigma_ese_alloc *allocs, int *allocs_size) |
| 11750 | { |
| 11751 | int max_count = *allocs_size; |
| 11752 | int count = 0, i; |
| 11753 | const char *val; |
| 11754 | |
| 11755 | do { |
| 11756 | val = get_param_indexed(cmd, "AllocID", count); |
| 11757 | if (val) |
| 11758 | count++; |
| 11759 | } while (val); |
| 11760 | |
| 11761 | if (count == 0 || count > max_count) { |
| 11762 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 11763 | "Invalid number of allocations(%d)", count); |
| 11764 | return -1; |
| 11765 | } |
| 11766 | |
| 11767 | for (i = 0; i < count; i++) { |
| 11768 | val = get_param_indexed(cmd, "PercentBI", i); |
| 11769 | if (!val) { |
| 11770 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 11771 | "Missing PercentBI parameter at index %d", |
| 11772 | i); |
| 11773 | return -1; |
| 11774 | } |
| 11775 | allocs[i].percent_bi = atoi(val); |
| 11776 | |
| 11777 | val = get_param_indexed(cmd, "SrcAID", i); |
| 11778 | if (val) |
| 11779 | allocs[i].src_aid = strtol(val, NULL, 0); |
| 11780 | else |
| 11781 | allocs[i].src_aid = ESE_BCAST_AID; |
| 11782 | |
| 11783 | val = get_param_indexed(cmd, "DestAID", i); |
| 11784 | if (val) |
| 11785 | allocs[i].dst_aid = strtol(val, NULL, 0); |
| 11786 | else |
| 11787 | allocs[i].dst_aid = ESE_BCAST_AID; |
| 11788 | |
| 11789 | allocs[i].type = ESE_CBAP; |
| 11790 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 11791 | "Alloc %d PercentBI %d SrcAID %d DstAID %d", |
| 11792 | i, allocs[i].percent_bi, allocs[i].src_aid, |
| 11793 | allocs[i].dst_aid); |
| 11794 | } |
| 11795 | |
| 11796 | *allocs_size = count; |
| 11797 | return 0; |
| 11798 | } |
| 11799 | |
| 11800 | |
| 11801 | static int sta_set_60g_ese(struct sigma_dut *dut, int count, |
| 11802 | struct sigma_ese_alloc *allocs) |
| 11803 | { |
| 11804 | switch (get_driver_type()) { |
| 11805 | #ifdef __linux__ |
| 11806 | case DRIVER_WIL6210: |
| 11807 | if (wil6210_set_ese(dut, count, allocs)) |
| 11808 | return -1; |
| 11809 | return 1; |
| 11810 | #endif /* __linux__ */ |
| 11811 | default: |
| 11812 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 11813 | "Unsupported sta_set_60g_ese with the current driver"); |
| 11814 | return -1; |
| 11815 | } |
| 11816 | } |
| 11817 | |
| 11818 | |
| 11819 | static int cmd_sta_set_rfeature_60g(const char *intf, struct sigma_dut *dut, |
| 11820 | struct sigma_conn *conn, |
| 11821 | struct sigma_cmd *cmd) |
| 11822 | { |
| 11823 | const char *val; |
| 11824 | |
| 11825 | val = get_param(cmd, "ExtSchIE"); |
| 11826 | if (val && !strcasecmp(val, "Enable")) { |
| 11827 | struct sigma_ese_alloc allocs[MAX_ESE_ALLOCS]; |
| 11828 | int count = MAX_ESE_ALLOCS; |
| 11829 | |
| 11830 | if (sta_extract_60g_ese(dut, cmd, allocs, &count)) |
| 11831 | return -1; |
| 11832 | return sta_set_60g_ese(dut, count, allocs); |
| 11833 | } |
| 11834 | |
Alexei Avshalom Lazar | aad97b0 | 2018-12-18 16:01:23 +0200 | [diff] [blame] | 11835 | val = get_param(cmd, "MCS_FixedRate"); |
| 11836 | if (val) { |
| 11837 | int sta_mcs = atoi(val); |
| 11838 | |
| 11839 | sigma_dut_print(dut, DUT_MSG_INFO, "Force STA MCS to %d", |
| 11840 | sta_mcs); |
| 11841 | wil6210_set_force_mcs(dut, 1, sta_mcs); |
| 11842 | |
Jouni Malinen | 0e29cf2 | 2019-02-19 01:13:21 +0200 | [diff] [blame] | 11843 | return SUCCESS_SEND_STATUS; |
Alexei Avshalom Lazar | aad97b0 | 2018-12-18 16:01:23 +0200 | [diff] [blame] | 11844 | } |
| 11845 | |
Alexei Avshalom Lazar | bc180dc | 2018-12-18 16:01:14 +0200 | [diff] [blame] | 11846 | send_resp(dut, conn, SIGMA_ERROR, |
| 11847 | "errorCode,Invalid sta_set_rfeature(60G)"); |
Jouni Malinen | 0e29cf2 | 2019-02-19 01:13:21 +0200 | [diff] [blame] | 11848 | return STATUS_SENT; |
Alexei Avshalom Lazar | bc180dc | 2018-12-18 16:01:14 +0200 | [diff] [blame] | 11849 | } |
| 11850 | |
| 11851 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 11852 | static enum sigma_cmd_result cmd_sta_set_rfeature(struct sigma_dut *dut, |
| 11853 | struct sigma_conn *conn, |
| 11854 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 11855 | { |
| 11856 | const char *intf = get_param(cmd, "Interface"); |
| 11857 | const char *prog = get_param(cmd, "Prog"); |
Ashwini Patil | 68d02cd | 2017-01-10 15:39:16 +0530 | [diff] [blame] | 11858 | const char *val; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 11859 | |
| 11860 | if (intf == NULL || prog == NULL) |
| 11861 | return -1; |
| 11862 | |
Ashwini Patil | 5acd738 | 2017-04-13 15:55:04 +0530 | [diff] [blame] | 11863 | /* BSS Transition candidate list for BTM query */ |
| 11864 | val = get_param(cmd, "Nebor_BSSID"); |
| 11865 | if (val && btm_query_candidate_list(dut, conn, cmd) == 0) |
| 11866 | return 0; |
| 11867 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 11868 | if (strcasecmp(prog, "TDLS") == 0) |
| 11869 | return cmd_sta_set_rfeature_tdls(intf, dut, conn, cmd); |
| 11870 | |
| 11871 | if (strcasecmp(prog, "VHT") == 0) |
| 11872 | return cmd_sta_set_rfeature_vht(intf, dut, conn, cmd); |
| 11873 | |
Amarnath Hullur Subramanyam | 42c25a0 | 2018-01-31 04:02:27 -0800 | [diff] [blame] | 11874 | if (strcasecmp(prog, "HE") == 0) |
| 11875 | return cmd_sta_set_rfeature_he(intf, dut, conn, cmd); |
| 11876 | |
Ashwini Patil | 68d02cd | 2017-01-10 15:39:16 +0530 | [diff] [blame] | 11877 | if (strcasecmp(prog, "MBO") == 0) { |
| 11878 | val = get_param(cmd, "Cellular_Data_Cap"); |
| 11879 | if (val && |
| 11880 | mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0) |
| 11881 | return 0; |
Ashwini Patil | 0040258 | 2017-04-13 12:29:39 +0530 | [diff] [blame] | 11882 | |
| 11883 | val = get_param(cmd, "Ch_Pref"); |
| 11884 | if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0) |
| 11885 | return 0; |
| 11886 | |
Ashwini Patil | 68d02cd | 2017-01-10 15:39:16 +0530 | [diff] [blame] | 11887 | return 1; |
| 11888 | } |
| 11889 | |
Alexei Avshalom Lazar | bc180dc | 2018-12-18 16:01:14 +0200 | [diff] [blame] | 11890 | if (strcasecmp(prog, "60GHz") == 0) |
| 11891 | return cmd_sta_set_rfeature_60g(intf, dut, conn, cmd); |
| 11892 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 11893 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported Prog"); |
| 11894 | return 0; |
| 11895 | } |
| 11896 | |
| 11897 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 11898 | static enum sigma_cmd_result cmd_sta_set_radio(struct sigma_dut *dut, |
| 11899 | struct sigma_conn *conn, |
| 11900 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 11901 | { |
| 11902 | const char *intf = get_param(cmd, "Interface"); |
| 11903 | const char *mode = get_param(cmd, "Mode"); |
| 11904 | int res; |
| 11905 | |
| 11906 | if (intf == NULL || mode == NULL) |
| 11907 | return -1; |
| 11908 | |
| 11909 | if (strcasecmp(mode, "On") == 0) |
| 11910 | res = wpa_command(intf, "SET radio_disabled 0"); |
| 11911 | else if (strcasecmp(mode, "Off") == 0) |
| 11912 | res = wpa_command(intf, "SET radio_disabled 1"); |
| 11913 | else |
| 11914 | return -1; |
| 11915 | |
| 11916 | if (res) { |
| 11917 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change " |
| 11918 | "radio mode"); |
| 11919 | return 0; |
| 11920 | } |
| 11921 | |
| 11922 | return 1; |
| 11923 | } |
| 11924 | |
| 11925 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 11926 | static enum sigma_cmd_result cmd_sta_set_pwrsave(struct sigma_dut *dut, |
| 11927 | struct sigma_conn *conn, |
| 11928 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 11929 | { |
| 11930 | const char *intf = get_param(cmd, "Interface"); |
| 11931 | const char *mode = get_param(cmd, "Mode"); |
Alexei Avshalom Lazar | e49e387 | 2018-12-23 17:26:57 +0200 | [diff] [blame] | 11932 | const char *prog = get_param(cmd, "program"); |
| 11933 | const char *powersave = get_param(cmd, "powersave"); |
| 11934 | int res = 0; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 11935 | |
Alexei Avshalom Lazar | e49e387 | 2018-12-23 17:26:57 +0200 | [diff] [blame] | 11936 | if (intf == NULL) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 11937 | return -1; |
| 11938 | |
Alexei Avshalom Lazar | e49e387 | 2018-12-23 17:26:57 +0200 | [diff] [blame] | 11939 | if (prog && strcasecmp(prog, "60GHz") == 0) { |
| 11940 | /* |
| 11941 | * The CAPI mode parameter does not exist in 60G |
| 11942 | * unscheduled PS. |
| 11943 | */ |
Hu Wang | 5dc3ff1 | 2019-06-14 15:14:26 +0800 | [diff] [blame] | 11944 | if (powersave && strcasecmp(powersave, "unscheduled") == 0) |
Alexei Avshalom Lazar | e49e387 | 2018-12-23 17:26:57 +0200 | [diff] [blame] | 11945 | res = set_ps(intf, dut, 1); |
Alexei Avshalom Lazar | 2f6fdb4 | 2019-02-04 14:16:08 +0200 | [diff] [blame] | 11946 | } else if (prog && get_driver_type() == DRIVER_WCN && |
| 11947 | strcasecmp(prog, "HE") == 0) { |
| 11948 | return cmd_sta_set_power_save_he(intf, dut, conn, cmd); |
Alexei Avshalom Lazar | e49e387 | 2018-12-23 17:26:57 +0200 | [diff] [blame] | 11949 | } else { |
| 11950 | if (mode == NULL) |
| 11951 | return -1; |
| 11952 | |
| 11953 | if (strcasecmp(mode, "On") == 0) |
| 11954 | res = set_ps(intf, dut, 1); |
| 11955 | else if (strcasecmp(mode, "Off") == 0) |
| 11956 | res = set_ps(intf, dut, 0); |
| 11957 | else |
| 11958 | return -1; |
| 11959 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 11960 | |
| 11961 | if (res) { |
| 11962 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change " |
| 11963 | "power save mode"); |
| 11964 | return 0; |
| 11965 | } |
| 11966 | |
| 11967 | return 1; |
| 11968 | } |
| 11969 | |
| 11970 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 11971 | static enum sigma_cmd_result cmd_sta_bssid_pool(struct sigma_dut *dut, |
| 11972 | struct sigma_conn *conn, |
| 11973 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 11974 | { |
| 11975 | const char *intf = get_param(cmd, "Interface"); |
| 11976 | const char *val, *bssid; |
| 11977 | int res; |
| 11978 | char *buf; |
| 11979 | size_t buf_len; |
| 11980 | |
| 11981 | val = get_param(cmd, "BSSID_FILTER"); |
| 11982 | if (val == NULL) |
| 11983 | return -1; |
| 11984 | |
| 11985 | bssid = get_param(cmd, "BSSID_List"); |
| 11986 | if (atoi(val) == 0 || bssid == NULL) { |
| 11987 | /* Disable BSSID filter */ |
| 11988 | if (wpa_command(intf, "SET bssid_filter ")) { |
| 11989 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed " |
| 11990 | "to disable BSSID filter"); |
| 11991 | return 0; |
| 11992 | } |
| 11993 | |
| 11994 | return 1; |
| 11995 | } |
| 11996 | |
| 11997 | buf_len = 100 + strlen(bssid); |
| 11998 | buf = malloc(buf_len); |
| 11999 | if (buf == NULL) |
| 12000 | return -1; |
| 12001 | |
| 12002 | snprintf(buf, buf_len, "SET bssid_filter %s", bssid); |
| 12003 | res = wpa_command(intf, buf); |
| 12004 | free(buf); |
| 12005 | if (res) { |
| 12006 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to enable " |
| 12007 | "BSSID filter"); |
| 12008 | return 0; |
| 12009 | } |
| 12010 | |
| 12011 | return 1; |
| 12012 | } |
| 12013 | |
| 12014 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 12015 | static enum sigma_cmd_result cmd_sta_reset_parm(struct sigma_dut *dut, |
| 12016 | struct sigma_conn *conn, |
| 12017 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 12018 | { |
| 12019 | const char *intf = get_param(cmd, "Interface"); |
| 12020 | const char *val; |
| 12021 | |
| 12022 | /* TODO: ARP */ |
| 12023 | |
| 12024 | val = get_param(cmd, "HS2_CACHE_PROFILE"); |
| 12025 | if (val && strcasecmp(val, "All") == 0) |
| 12026 | hs2_clear_credentials(intf); |
| 12027 | |
| 12028 | return 1; |
| 12029 | } |
| 12030 | |
| 12031 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 12032 | static enum sigma_cmd_result cmd_sta_get_key(struct sigma_dut *dut, |
| 12033 | struct sigma_conn *conn, |
| 12034 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 12035 | { |
| 12036 | const char *intf = get_param(cmd, "Interface"); |
| 12037 | const char *key_type = get_param(cmd, "KeyType"); |
| 12038 | char buf[100], resp[200]; |
| 12039 | |
| 12040 | if (key_type == NULL) |
| 12041 | return -1; |
| 12042 | |
| 12043 | if (strcasecmp(key_type, "GTK") == 0) { |
| 12044 | if (wpa_command_resp(intf, "GET gtk", buf, sizeof(buf)) < 0 || |
| 12045 | strncmp(buf, "FAIL", 4) == 0) { |
| 12046 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could " |
| 12047 | "not fetch current GTK"); |
| 12048 | return 0; |
| 12049 | } |
| 12050 | snprintf(resp, sizeof(resp), "KeyValue,%s", buf); |
| 12051 | send_resp(dut, conn, SIGMA_COMPLETE, resp); |
| 12052 | return 0; |
| 12053 | } else { |
| 12054 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported " |
| 12055 | "KeyType"); |
| 12056 | return 0; |
| 12057 | } |
| 12058 | |
| 12059 | return 1; |
| 12060 | } |
| 12061 | |
| 12062 | |
| 12063 | static int hs2_set_policy(struct sigma_dut *dut) |
| 12064 | { |
| 12065 | #ifdef ANDROID |
| 12066 | system("ip rule del prio 23000"); |
| 12067 | if (system("ip rule add from all lookup main prio 23000") != 0) { |
| 12068 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 12069 | "Failed to run:ip rule add from all lookup main prio"); |
| 12070 | return -1; |
| 12071 | } |
| 12072 | if (system("ip route flush cache") != 0) { |
| 12073 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 12074 | "Failed to run ip route flush cache"); |
| 12075 | return -1; |
| 12076 | } |
| 12077 | return 1; |
| 12078 | #else /* ANDROID */ |
| 12079 | return 0; |
| 12080 | #endif /* ANDROID */ |
| 12081 | } |
| 12082 | |
| 12083 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 12084 | static enum sigma_cmd_result cmd_sta_hs2_associate(struct sigma_dut *dut, |
| 12085 | struct sigma_conn *conn, |
| 12086 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 12087 | { |
| 12088 | const char *intf = get_param(cmd, "Interface"); |
| 12089 | const char *val = get_param(cmd, "Ignore_blacklist"); |
Jouni Malinen | 439352d | 2018-09-13 03:42:23 +0300 | [diff] [blame] | 12090 | const char *band = get_param(cmd, "Band"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 12091 | struct wpa_ctrl *ctrl; |
Jouni Malinen | 3aa7286 | 2019-05-29 23:14:51 +0300 | [diff] [blame] | 12092 | int res, r; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 12093 | char bssid[20], ssid[40], resp[100], buf[100], blacklisted[100]; |
| 12094 | int tries = 0; |
| 12095 | int ignore_blacklist = 0; |
| 12096 | const char *events[] = { |
| 12097 | "CTRL-EVENT-CONNECTED", |
| 12098 | "INTERWORKING-BLACKLISTED", |
| 12099 | "INTERWORKING-NO-MATCH", |
| 12100 | NULL |
| 12101 | }; |
| 12102 | |
| 12103 | start_sta_mode(dut); |
| 12104 | |
Jouni Malinen | 439352d | 2018-09-13 03:42:23 +0300 | [diff] [blame] | 12105 | if (band) { |
| 12106 | if (strcmp(band, "2.4") == 0) { |
| 12107 | wpa_command(intf, "SET setband 2G"); |
| 12108 | } else if (strcmp(band, "5") == 0) { |
| 12109 | wpa_command(intf, "SET setband 5G"); |
| 12110 | } else { |
| 12111 | send_resp(dut, conn, SIGMA_ERROR, |
| 12112 | "errorCode,Unsupported band"); |
| 12113 | return 0; |
| 12114 | } |
| 12115 | } |
| 12116 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 12117 | blacklisted[0] = '\0'; |
| 12118 | if (val && atoi(val)) |
| 12119 | ignore_blacklist = 1; |
| 12120 | |
| 12121 | try_again: |
| 12122 | ctrl = open_wpa_mon(intf); |
| 12123 | if (ctrl == NULL) { |
| 12124 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open " |
| 12125 | "wpa_supplicant monitor connection"); |
| 12126 | return -2; |
| 12127 | } |
| 12128 | |
| 12129 | tries++; |
| 12130 | if (wpa_command(intf, "INTERWORKING_SELECT auto")) { |
| 12131 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start " |
| 12132 | "Interworking connection"); |
| 12133 | wpa_ctrl_detach(ctrl); |
| 12134 | wpa_ctrl_close(ctrl); |
| 12135 | return 0; |
| 12136 | } |
| 12137 | |
| 12138 | buf[0] = '\0'; |
| 12139 | while (1) { |
| 12140 | char *pos; |
| 12141 | res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf)); |
| 12142 | pos = strstr(buf, "INTERWORKING-BLACKLISTED"); |
| 12143 | if (!pos) |
| 12144 | break; |
| 12145 | pos += 25; |
| 12146 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Found blacklisted AP: %s", |
| 12147 | pos); |
| 12148 | if (!blacklisted[0]) |
| 12149 | memcpy(blacklisted, pos, strlen(pos) + 1); |
| 12150 | } |
| 12151 | |
| 12152 | if (ignore_blacklist && blacklisted[0]) { |
| 12153 | char *end; |
| 12154 | end = strchr(blacklisted, ' '); |
| 12155 | if (end) |
| 12156 | *end = '\0'; |
| 12157 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Try to connect to a blacklisted network: %s", |
| 12158 | blacklisted); |
Jouni Malinen | 3aa7286 | 2019-05-29 23:14:51 +0300 | [diff] [blame] | 12159 | r = snprintf(buf, sizeof(buf), "INTERWORKING_CONNECT %s", |
| 12160 | blacklisted); |
| 12161 | if (r < 0 || r >= sizeof(buf) || wpa_command(intf, buf)) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 12162 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start Interworking connection to blacklisted network"); |
| 12163 | wpa_ctrl_detach(ctrl); |
| 12164 | wpa_ctrl_close(ctrl); |
| 12165 | return 0; |
| 12166 | } |
| 12167 | res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED", |
| 12168 | buf, sizeof(buf)); |
| 12169 | } |
| 12170 | |
| 12171 | wpa_ctrl_detach(ctrl); |
| 12172 | wpa_ctrl_close(ctrl); |
| 12173 | |
| 12174 | if (res < 0) { |
| 12175 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not " |
| 12176 | "connect"); |
| 12177 | return 0; |
| 12178 | } |
| 12179 | |
| 12180 | if (strstr(buf, "INTERWORKING-NO-MATCH") || |
| 12181 | strstr(buf, "INTERWORKING-BLACKLISTED")) { |
| 12182 | if (tries < 2) { |
| 12183 | sigma_dut_print(dut, DUT_MSG_INFO, "No match found - try again to verify no APs were missed in the scan"); |
| 12184 | goto try_again; |
| 12185 | } |
| 12186 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,No network with " |
| 12187 | "matching credentials found"); |
| 12188 | return 0; |
| 12189 | } |
| 12190 | |
| 12191 | if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 || |
| 12192 | get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) { |
| 12193 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not " |
| 12194 | "get current BSSID/SSID"); |
| 12195 | return 0; |
| 12196 | } |
| 12197 | |
| 12198 | snprintf(resp, sizeof(resp), "SSID,%s,BSSID,%s", ssid, bssid); |
| 12199 | send_resp(dut, conn, SIGMA_COMPLETE, resp); |
| 12200 | hs2_set_policy(dut); |
| 12201 | return 0; |
| 12202 | } |
| 12203 | |
| 12204 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 12205 | static enum sigma_cmd_result cmd_sta_hs2_venue_info(struct sigma_dut *dut, |
| 12206 | struct sigma_conn *conn, |
| 12207 | struct sigma_cmd *cmd) |
Jouni Malinen | b639f1c | 2018-09-13 02:39:46 +0300 | [diff] [blame] | 12208 | { |
| 12209 | const char *intf = get_param(cmd, "Interface"); |
| 12210 | const char *display = get_param(cmd, "Display"); |
| 12211 | struct wpa_ctrl *ctrl; |
| 12212 | char buf[300], params[400], *pos; |
| 12213 | char bssid[20]; |
| 12214 | int info_avail = 0; |
| 12215 | unsigned int old_timeout; |
| 12216 | int res; |
| 12217 | |
| 12218 | if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) { |
| 12219 | send_resp(dut, conn, SIGMA_ERROR, |
| 12220 | "ErrorCode,Could not get current BSSID"); |
| 12221 | return 0; |
| 12222 | } |
| 12223 | ctrl = open_wpa_mon(intf); |
| 12224 | if (!ctrl) { |
| 12225 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 12226 | "Failed to open wpa_supplicant monitor connection"); |
| 12227 | return -2; |
| 12228 | } |
| 12229 | |
| 12230 | snprintf(buf, sizeof(buf), "ANQP_GET %s 277", bssid); |
| 12231 | wpa_command(intf, buf); |
| 12232 | |
| 12233 | res = get_wpa_cli_event(dut, ctrl, "GAS-QUERY-DONE", buf, sizeof(buf)); |
| 12234 | if (res < 0) { |
| 12235 | send_resp(dut, conn, SIGMA_ERROR, |
| 12236 | "ErrorCode,Could not complete GAS query"); |
| 12237 | goto fail; |
| 12238 | } |
| 12239 | |
| 12240 | old_timeout = dut->default_timeout; |
| 12241 | dut->default_timeout = 2; |
| 12242 | res = get_wpa_cli_event(dut, ctrl, "RX-VENUE-URL", buf, sizeof(buf)); |
| 12243 | dut->default_timeout = old_timeout; |
| 12244 | if (res < 0) |
| 12245 | goto done; |
| 12246 | pos = strchr(buf, ' '); |
| 12247 | if (!pos) |
| 12248 | goto done; |
| 12249 | pos++; |
| 12250 | pos = strchr(pos, ' '); |
| 12251 | if (!pos) |
| 12252 | goto done; |
| 12253 | pos++; |
| 12254 | info_avail = 1; |
| 12255 | snprintf(params, sizeof(params), "browser %s", pos); |
| 12256 | |
| 12257 | if (display && strcasecmp(display, "Yes") == 0) { |
| 12258 | pid_t pid; |
| 12259 | |
| 12260 | pid = fork(); |
| 12261 | if (pid < 0) { |
| 12262 | perror("fork"); |
| 12263 | return -1; |
| 12264 | } |
| 12265 | |
| 12266 | if (pid == 0) { |
| 12267 | run_hs20_osu(dut, params); |
| 12268 | exit(0); |
| 12269 | } |
| 12270 | } |
| 12271 | |
| 12272 | done: |
| 12273 | snprintf(buf, sizeof(buf), "Info_available,%s", |
| 12274 | info_avail ? "Yes" : "No"); |
| 12275 | send_resp(dut, conn, SIGMA_COMPLETE, buf); |
| 12276 | fail: |
| 12277 | wpa_ctrl_detach(ctrl); |
| 12278 | wpa_ctrl_close(ctrl); |
| 12279 | return 0; |
| 12280 | } |
| 12281 | |
| 12282 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 12283 | static int sta_add_credential_uname_pwd(struct sigma_dut *dut, |
| 12284 | struct sigma_conn *conn, |
| 12285 | const char *ifname, |
| 12286 | struct sigma_cmd *cmd) |
| 12287 | { |
| 12288 | const char *val; |
| 12289 | int id; |
| 12290 | |
| 12291 | id = add_cred(ifname); |
| 12292 | if (id < 0) |
| 12293 | return -2; |
| 12294 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id); |
| 12295 | |
| 12296 | val = get_param(cmd, "prefer"); |
| 12297 | if (val && atoi(val) > 0) |
| 12298 | set_cred(ifname, id, "priority", "1"); |
| 12299 | |
| 12300 | val = get_param(cmd, "REALM"); |
| 12301 | if (val && set_cred_quoted(ifname, id, "realm", val) < 0) { |
| 12302 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set " |
| 12303 | "realm"); |
| 12304 | return 0; |
| 12305 | } |
| 12306 | |
| 12307 | val = get_param(cmd, "HOME_FQDN"); |
| 12308 | if (val && set_cred_quoted(ifname, id, "domain", val) < 0) { |
| 12309 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set " |
| 12310 | "home_fqdn"); |
| 12311 | return 0; |
| 12312 | } |
| 12313 | |
| 12314 | val = get_param(cmd, "Username"); |
| 12315 | if (val && set_cred_quoted(ifname, id, "username", val) < 0) { |
| 12316 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set " |
| 12317 | "username"); |
| 12318 | return 0; |
| 12319 | } |
| 12320 | |
| 12321 | val = get_param(cmd, "Password"); |
| 12322 | if (val && set_cred_quoted(ifname, id, "password", val) < 0) { |
| 12323 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set " |
| 12324 | "password"); |
| 12325 | return 0; |
| 12326 | } |
| 12327 | |
| 12328 | val = get_param(cmd, "ROOT_CA"); |
| 12329 | if (val) { |
| 12330 | char fname[200]; |
| 12331 | snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val); |
| 12332 | #ifdef __linux__ |
| 12333 | if (!file_exists(fname)) { |
| 12334 | char msg[300]; |
| 12335 | snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA " |
| 12336 | "file (%s) not found", fname); |
| 12337 | send_resp(dut, conn, SIGMA_ERROR, msg); |
| 12338 | return 0; |
| 12339 | } |
| 12340 | #endif /* __linux__ */ |
| 12341 | if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) { |
| 12342 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could " |
| 12343 | "not set root CA"); |
| 12344 | return 0; |
| 12345 | } |
| 12346 | } |
| 12347 | |
| 12348 | return 1; |
| 12349 | } |
| 12350 | |
| 12351 | |
| 12352 | static int update_devdetail_imsi(struct sigma_dut *dut, const char *imsi) |
| 12353 | { |
| 12354 | FILE *in, *out; |
| 12355 | char buf[500]; |
| 12356 | int found = 0; |
| 12357 | |
| 12358 | in = fopen("devdetail.xml", "r"); |
| 12359 | if (in == NULL) |
| 12360 | return -1; |
| 12361 | out = fopen("devdetail.xml.tmp", "w"); |
| 12362 | if (out == NULL) { |
| 12363 | fclose(in); |
| 12364 | return -1; |
| 12365 | } |
| 12366 | |
| 12367 | while (fgets(buf, sizeof(buf), in)) { |
| 12368 | char *pos = strstr(buf, "<IMSI>"); |
| 12369 | if (pos) { |
| 12370 | sigma_dut_print(dut, DUT_MSG_INFO, "Updated DevDetail IMSI to %s", |
| 12371 | imsi); |
| 12372 | pos += 6; |
| 12373 | *pos = '\0'; |
| 12374 | fprintf(out, "%s%s</IMSI>\n", buf, imsi); |
| 12375 | found++; |
| 12376 | } else { |
| 12377 | fprintf(out, "%s", buf); |
| 12378 | } |
| 12379 | } |
| 12380 | |
| 12381 | fclose(out); |
| 12382 | fclose(in); |
| 12383 | if (found) |
| 12384 | rename("devdetail.xml.tmp", "devdetail.xml"); |
| 12385 | else |
| 12386 | unlink("devdetail.xml.tmp"); |
| 12387 | |
| 12388 | return 0; |
| 12389 | } |
| 12390 | |
| 12391 | |
| 12392 | static int sta_add_credential_sim(struct sigma_dut *dut, |
| 12393 | struct sigma_conn *conn, |
| 12394 | const char *ifname, struct sigma_cmd *cmd) |
| 12395 | { |
| 12396 | const char *val, *imsi = NULL; |
| 12397 | int id; |
| 12398 | char buf[200]; |
| 12399 | int res; |
| 12400 | const char *pos; |
| 12401 | size_t mnc_len; |
| 12402 | char plmn_mcc[4]; |
| 12403 | char plmn_mnc[4]; |
| 12404 | |
| 12405 | id = add_cred(ifname); |
| 12406 | if (id < 0) |
| 12407 | return -2; |
| 12408 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id); |
| 12409 | |
| 12410 | val = get_param(cmd, "prefer"); |
| 12411 | if (val && atoi(val) > 0) |
| 12412 | set_cred(ifname, id, "priority", "1"); |
| 12413 | |
| 12414 | val = get_param(cmd, "PLMN_MCC"); |
| 12415 | if (val == NULL) { |
| 12416 | send_resp(dut, conn, SIGMA_ERROR, |
| 12417 | "errorCode,Missing PLMN_MCC"); |
| 12418 | return 0; |
| 12419 | } |
| 12420 | if (strlen(val) != 3) { |
| 12421 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MCC"); |
| 12422 | return 0; |
| 12423 | } |
| 12424 | snprintf(plmn_mcc, sizeof(plmn_mcc), "%s", val); |
| 12425 | |
| 12426 | val = get_param(cmd, "PLMN_MNC"); |
| 12427 | if (val == NULL) { |
| 12428 | send_resp(dut, conn, SIGMA_ERROR, |
| 12429 | "errorCode,Missing PLMN_MNC"); |
| 12430 | return 0; |
| 12431 | } |
| 12432 | if (strlen(val) != 2 && strlen(val) != 3) { |
| 12433 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MNC"); |
| 12434 | return 0; |
| 12435 | } |
| 12436 | snprintf(plmn_mnc, sizeof(plmn_mnc), "%s", val); |
| 12437 | |
| 12438 | val = get_param(cmd, "IMSI"); |
| 12439 | if (val == NULL) { |
| 12440 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing SIM " |
| 12441 | "IMSI"); |
| 12442 | return 0; |
| 12443 | } |
| 12444 | |
| 12445 | imsi = pos = val; |
| 12446 | |
| 12447 | if (strncmp(plmn_mcc, pos, 3) != 0) { |
| 12448 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,MCC mismatch"); |
| 12449 | return 0; |
| 12450 | } |
| 12451 | pos += 3; |
| 12452 | |
| 12453 | mnc_len = strlen(plmn_mnc); |
| 12454 | if (mnc_len < 2) { |
| 12455 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC not set"); |
| 12456 | return 0; |
| 12457 | } |
| 12458 | |
| 12459 | if (strncmp(plmn_mnc, pos, mnc_len) != 0) { |
| 12460 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC mismatch"); |
| 12461 | return 0; |
| 12462 | } |
| 12463 | pos += mnc_len; |
| 12464 | |
| 12465 | res = snprintf(buf, sizeof(buf), "%s%s-%s",plmn_mcc, plmn_mnc, pos); |
| 12466 | if (res < 0 || res >= (int) sizeof(buf)) |
| 12467 | return -1; |
| 12468 | if (set_cred_quoted(ifname, id, "imsi", buf) < 0) { |
| 12469 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could " |
| 12470 | "not set IMSI"); |
| 12471 | return 0; |
| 12472 | } |
| 12473 | |
| 12474 | val = get_param(cmd, "Password"); |
| 12475 | if (val && set_cred_quoted(ifname, id, "milenage", val) < 0) { |
| 12476 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could " |
| 12477 | "not set password"); |
| 12478 | return 0; |
| 12479 | } |
| 12480 | |
Jouni Malinen | ba63045 | 2018-06-22 11:49:59 +0300 | [diff] [blame] | 12481 | if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 12482 | /* |
| 12483 | * Set provisioning_sp for the test cases where SIM/USIM |
| 12484 | * provisioning is used. |
| 12485 | */ |
| 12486 | if (val && set_cred_quoted(ifname, id, "provisioning_sp", |
| 12487 | "wi-fi.org") < 0) { |
| 12488 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could " |
| 12489 | "not set provisioning_sp"); |
| 12490 | return 0; |
| 12491 | } |
| 12492 | |
| 12493 | update_devdetail_imsi(dut, imsi); |
| 12494 | } |
| 12495 | |
| 12496 | return 1; |
| 12497 | } |
| 12498 | |
| 12499 | |
| 12500 | static int sta_add_credential_cert(struct sigma_dut *dut, |
| 12501 | struct sigma_conn *conn, |
| 12502 | const char *ifname, |
| 12503 | struct sigma_cmd *cmd) |
| 12504 | { |
| 12505 | const char *val; |
| 12506 | int id; |
| 12507 | |
| 12508 | id = add_cred(ifname); |
| 12509 | if (id < 0) |
| 12510 | return -2; |
| 12511 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id); |
| 12512 | |
| 12513 | val = get_param(cmd, "prefer"); |
| 12514 | if (val && atoi(val) > 0) |
| 12515 | set_cred(ifname, id, "priority", "1"); |
| 12516 | |
| 12517 | val = get_param(cmd, "REALM"); |
| 12518 | if (val && set_cred_quoted(ifname, id, "realm", val) < 0) { |
| 12519 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set " |
| 12520 | "realm"); |
| 12521 | return 0; |
| 12522 | } |
| 12523 | |
| 12524 | val = get_param(cmd, "HOME_FQDN"); |
| 12525 | if (val && set_cred_quoted(ifname, id, "domain", val) < 0) { |
| 12526 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set " |
| 12527 | "home_fqdn"); |
| 12528 | return 0; |
| 12529 | } |
| 12530 | |
| 12531 | val = get_param(cmd, "Username"); |
| 12532 | if (val && set_cred_quoted(ifname, id, "username", val) < 0) { |
| 12533 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set " |
| 12534 | "username"); |
| 12535 | return 0; |
| 12536 | } |
| 12537 | |
| 12538 | val = get_param(cmd, "clientCertificate"); |
| 12539 | if (val) { |
| 12540 | char fname[200]; |
| 12541 | snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val); |
| 12542 | #ifdef __linux__ |
| 12543 | if (!file_exists(fname)) { |
| 12544 | char msg[300]; |
| 12545 | snprintf(msg, sizeof(msg), |
| 12546 | "ErrorCode,clientCertificate " |
| 12547 | "file (%s) not found", fname); |
| 12548 | send_resp(dut, conn, SIGMA_ERROR, msg); |
| 12549 | return 0; |
| 12550 | } |
| 12551 | #endif /* __linux__ */ |
| 12552 | if (set_cred_quoted(ifname, id, "client_cert", fname) < 0) { |
| 12553 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could " |
| 12554 | "not set client_cert"); |
| 12555 | return 0; |
| 12556 | } |
| 12557 | if (set_cred_quoted(ifname, id, "private_key", fname) < 0) { |
| 12558 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could " |
| 12559 | "not set private_key"); |
| 12560 | return 0; |
| 12561 | } |
| 12562 | } |
| 12563 | |
| 12564 | val = get_param(cmd, "ROOT_CA"); |
| 12565 | if (val) { |
| 12566 | char fname[200]; |
| 12567 | snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val); |
| 12568 | #ifdef __linux__ |
| 12569 | if (!file_exists(fname)) { |
| 12570 | char msg[300]; |
| 12571 | snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA " |
| 12572 | "file (%s) not found", fname); |
| 12573 | send_resp(dut, conn, SIGMA_ERROR, msg); |
| 12574 | return 0; |
| 12575 | } |
| 12576 | #endif /* __linux__ */ |
| 12577 | if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) { |
| 12578 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could " |
| 12579 | "not set root CA"); |
| 12580 | return 0; |
| 12581 | } |
| 12582 | } |
| 12583 | |
| 12584 | return 1; |
| 12585 | } |
| 12586 | |
| 12587 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 12588 | static enum sigma_cmd_result cmd_sta_add_credential(struct sigma_dut *dut, |
| 12589 | struct sigma_conn *conn, |
| 12590 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 12591 | { |
| 12592 | const char *intf = get_param(cmd, "Interface"); |
| 12593 | const char *type; |
| 12594 | |
| 12595 | start_sta_mode(dut); |
| 12596 | |
| 12597 | type = get_param(cmd, "Type"); |
| 12598 | if (!type) |
| 12599 | return -1; |
| 12600 | |
| 12601 | if (strcasecmp(type, "uname_pwd") == 0) |
| 12602 | return sta_add_credential_uname_pwd(dut, conn, intf, cmd); |
| 12603 | |
| 12604 | if (strcasecmp(type, "sim") == 0) |
| 12605 | return sta_add_credential_sim(dut, conn, intf, cmd); |
| 12606 | |
| 12607 | if (strcasecmp(type, "cert") == 0) |
| 12608 | return sta_add_credential_cert(dut, conn, intf, cmd); |
| 12609 | |
| 12610 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported credential " |
| 12611 | "type"); |
| 12612 | return 0; |
| 12613 | } |
| 12614 | |
| 12615 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 12616 | static enum sigma_cmd_result cmd_sta_scan(struct sigma_dut *dut, |
| 12617 | struct sigma_conn *conn, |
| 12618 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 12619 | { |
| 12620 | const char *intf = get_param(cmd, "Interface"); |
vamsi krishna | 89ad8c6 | 2017-09-19 12:51:18 +0530 | [diff] [blame] | 12621 | const char *val, *bssid, *ssid; |
Arif Hussain | 66a4af0 | 2019-02-07 15:04:51 -0800 | [diff] [blame] | 12622 | char buf[4096]; |
vamsi krishna | 89ad8c6 | 2017-09-19 12:51:18 +0530 | [diff] [blame] | 12623 | char ssid_hex[65]; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 12624 | int res; |
| 12625 | |
Arif Hussain | 66a4af0 | 2019-02-07 15:04:51 -0800 | [diff] [blame] | 12626 | val = get_param(cmd, "GetParameter"); |
| 12627 | if (val && strcmp(val, "SSID_BSSID") == 0) { |
| 12628 | if (get_wpa_ssid_bssid(dut, get_station_ifname(), |
| 12629 | buf, sizeof(buf)) < 0) { |
| 12630 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 12631 | "Could not get ssid bssid"); |
| 12632 | return ERROR_SEND_STATUS; |
| 12633 | } |
| 12634 | |
| 12635 | sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf); |
| 12636 | send_resp(dut, conn, SIGMA_COMPLETE, buf); |
| 12637 | return STATUS_SENT; |
| 12638 | } |
| 12639 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 12640 | val = get_param(cmd, "HESSID"); |
| 12641 | if (val) { |
| 12642 | res = snprintf(buf, sizeof(buf), "SET hessid %s", val); |
| 12643 | if (res < 0 || res >= (int) sizeof(buf)) |
| 12644 | return -1; |
| 12645 | wpa_command(intf, buf); |
| 12646 | } |
| 12647 | |
| 12648 | val = get_param(cmd, "ACCS_NET_TYPE"); |
| 12649 | if (val) { |
| 12650 | res = snprintf(buf, sizeof(buf), "SET access_network_type %s", |
| 12651 | val); |
| 12652 | if (res < 0 || res >= (int) sizeof(buf)) |
| 12653 | return -1; |
| 12654 | wpa_command(intf, buf); |
| 12655 | } |
| 12656 | |
vamsi krishna | 89ad8c6 | 2017-09-19 12:51:18 +0530 | [diff] [blame] | 12657 | bssid = get_param(cmd, "Bssid"); |
| 12658 | ssid = get_param(cmd, "Ssid"); |
| 12659 | |
| 12660 | if (ssid) { |
| 12661 | if (2 * strlen(ssid) >= sizeof(ssid_hex)) { |
| 12662 | send_resp(dut, conn, SIGMA_ERROR, |
| 12663 | "ErrorCode,Too long SSID"); |
| 12664 | return 0; |
| 12665 | } |
| 12666 | ascii2hexstr(ssid, ssid_hex); |
| 12667 | } |
| 12668 | |
| 12669 | res = snprintf(buf, sizeof(buf), "SCAN%s%s%s%s", |
| 12670 | bssid ? " bssid=": "", |
| 12671 | bssid ? bssid : "", |
| 12672 | ssid ? " ssid " : "", |
| 12673 | ssid ? ssid_hex : ""); |
| 12674 | if (res < 0 || res >= (int) sizeof(buf)) |
| 12675 | return -1; |
| 12676 | |
| 12677 | if (wpa_command(intf, buf)) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 12678 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not start " |
| 12679 | "scan"); |
| 12680 | return 0; |
| 12681 | } |
| 12682 | |
| 12683 | return 1; |
| 12684 | } |
| 12685 | |
| 12686 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 12687 | static enum sigma_cmd_result cmd_sta_scan_bss(struct sigma_dut *dut, |
| 12688 | struct sigma_conn *conn, |
| 12689 | struct sigma_cmd *cmd) |
Jouni Malinen | 5e5d43d | 2018-01-10 17:29:33 +0200 | [diff] [blame] | 12690 | { |
| 12691 | const char *intf = get_param(cmd, "Interface"); |
| 12692 | const char *bssid; |
| 12693 | char buf[4096], *pos; |
| 12694 | int freq, chan; |
| 12695 | char *ssid; |
| 12696 | char resp[100]; |
| 12697 | int res; |
| 12698 | struct wpa_ctrl *ctrl; |
| 12699 | |
| 12700 | bssid = get_param(cmd, "BSSID"); |
| 12701 | if (!bssid) { |
| 12702 | send_resp(dut, conn, SIGMA_INVALID, |
| 12703 | "errorCode,BSSID argument is missing"); |
| 12704 | return 0; |
| 12705 | } |
| 12706 | |
| 12707 | ctrl = open_wpa_mon(intf); |
| 12708 | if (!ctrl) { |
| 12709 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 12710 | "Failed to open wpa_supplicant monitor connection"); |
| 12711 | return -1; |
| 12712 | } |
| 12713 | |
| 12714 | if (wpa_command(intf, "SCAN TYPE=ONLY")) { |
| 12715 | send_resp(dut, conn, SIGMA_ERROR, |
| 12716 | "errorCode,Could not start scan"); |
| 12717 | wpa_ctrl_detach(ctrl); |
| 12718 | wpa_ctrl_close(ctrl); |
| 12719 | return 0; |
| 12720 | } |
| 12721 | |
| 12722 | res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS", |
| 12723 | buf, sizeof(buf)); |
| 12724 | |
| 12725 | wpa_ctrl_detach(ctrl); |
| 12726 | wpa_ctrl_close(ctrl); |
| 12727 | |
| 12728 | if (res < 0) { |
| 12729 | send_resp(dut, conn, SIGMA_ERROR, |
| 12730 | "errorCode,Scan did not complete"); |
| 12731 | return 0; |
| 12732 | } |
| 12733 | |
| 12734 | snprintf(buf, sizeof(buf), "BSS %s", bssid); |
| 12735 | if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 || |
| 12736 | strncmp(buf, "id=", 3) != 0) { |
| 12737 | send_resp(dut, conn, SIGMA_ERROR, |
| 12738 | "errorCode,Specified BSSID not found"); |
| 12739 | return 0; |
| 12740 | } |
| 12741 | |
| 12742 | pos = strstr(buf, "\nfreq="); |
| 12743 | if (!pos) { |
| 12744 | send_resp(dut, conn, SIGMA_ERROR, |
| 12745 | "errorCode,Channel not found"); |
| 12746 | return 0; |
| 12747 | } |
| 12748 | freq = atoi(pos + 6); |
| 12749 | chan = freq_to_channel(freq); |
| 12750 | |
| 12751 | pos = strstr(buf, "\nssid="); |
| 12752 | if (!pos) { |
| 12753 | send_resp(dut, conn, SIGMA_ERROR, |
| 12754 | "errorCode,SSID not found"); |
| 12755 | return 0; |
| 12756 | } |
| 12757 | ssid = pos + 6; |
| 12758 | pos = strchr(ssid, '\n'); |
| 12759 | if (pos) |
| 12760 | *pos = '\0'; |
| 12761 | snprintf(resp, sizeof(resp), "ssid,%s,bsschannel,%d", ssid, chan); |
| 12762 | send_resp(dut, conn, SIGMA_COMPLETE, resp); |
| 12763 | return 0; |
| 12764 | } |
| 12765 | |
| 12766 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 12767 | static enum sigma_cmd_result cmd_sta_set_systime(struct sigma_dut *dut, |
| 12768 | struct sigma_conn *conn, |
| 12769 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 12770 | { |
| 12771 | #ifdef __linux__ |
| 12772 | struct timeval tv; |
| 12773 | struct tm tm; |
| 12774 | time_t t; |
| 12775 | const char *val; |
Pradeep Reddy POTTETI | 429c69e | 2016-10-13 17:22:03 +0530 | [diff] [blame] | 12776 | int v; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 12777 | |
| 12778 | wpa_command(get_station_ifname(), "PMKSA_FLUSH"); |
| 12779 | |
| 12780 | memset(&tm, 0, sizeof(tm)); |
| 12781 | val = get_param(cmd, "seconds"); |
| 12782 | if (val) |
| 12783 | tm.tm_sec = atoi(val); |
| 12784 | val = get_param(cmd, "minutes"); |
| 12785 | if (val) |
| 12786 | tm.tm_min = atoi(val); |
| 12787 | val = get_param(cmd, "hours"); |
| 12788 | if (val) |
| 12789 | tm.tm_hour = atoi(val); |
| 12790 | val = get_param(cmd, "date"); |
| 12791 | if (val) |
| 12792 | tm.tm_mday = atoi(val); |
| 12793 | val = get_param(cmd, "month"); |
Pradeep Reddy POTTETI | 429c69e | 2016-10-13 17:22:03 +0530 | [diff] [blame] | 12794 | if (val) { |
| 12795 | v = atoi(val); |
| 12796 | if (v < 1 || v > 12) { |
| 12797 | send_resp(dut, conn, SIGMA_INVALID, |
| 12798 | "errorCode,Invalid month"); |
| 12799 | return 0; |
| 12800 | } |
| 12801 | tm.tm_mon = v - 1; |
| 12802 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 12803 | val = get_param(cmd, "year"); |
| 12804 | if (val) { |
| 12805 | int year = atoi(val); |
| 12806 | #ifdef ANDROID |
| 12807 | if (year > 2035) |
| 12808 | year = 2035; /* years beyond 2035 not supported */ |
| 12809 | #endif /* ANDROID */ |
| 12810 | tm.tm_year = year - 1900; |
| 12811 | } |
| 12812 | t = mktime(&tm); |
| 12813 | if (t == (time_t) -1) { |
| 12814 | send_resp(dut, conn, SIGMA_ERROR, |
| 12815 | "errorCode,Invalid date or time"); |
| 12816 | return 0; |
| 12817 | } |
| 12818 | |
| 12819 | memset(&tv, 0, sizeof(tv)); |
| 12820 | tv.tv_sec = t; |
| 12821 | |
| 12822 | if (settimeofday(&tv, NULL) < 0) { |
| 12823 | sigma_dut_print(dut, DUT_MSG_INFO, "settimeofday failed: %s", |
| 12824 | strerror(errno)); |
| 12825 | send_resp(dut, conn, SIGMA_ERROR, |
| 12826 | "errorCode,Failed to set time"); |
| 12827 | return 0; |
| 12828 | } |
| 12829 | |
| 12830 | return 1; |
| 12831 | #endif /* __linux__ */ |
| 12832 | |
| 12833 | return -1; |
| 12834 | } |
| 12835 | |
| 12836 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 12837 | static enum sigma_cmd_result cmd_sta_osu(struct sigma_dut *dut, |
| 12838 | struct sigma_conn *conn, |
| 12839 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 12840 | { |
| 12841 | const char *intf = get_param(cmd, "Interface"); |
Jouni Malinen | 4c8681c | 2018-09-12 23:28:11 +0300 | [diff] [blame] | 12842 | const char *name, *osu_ssid, *val; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 12843 | int prod_ess_assoc = 1; |
Jouni Malinen | 4c8681c | 2018-09-12 23:28:11 +0300 | [diff] [blame] | 12844 | char buf[300], bssid[100], ssid[100]; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 12845 | int res; |
| 12846 | struct wpa_ctrl *ctrl; |
| 12847 | |
| 12848 | name = get_param(cmd, "osuFriendlyName"); |
Jouni Malinen | 4c8681c | 2018-09-12 23:28:11 +0300 | [diff] [blame] | 12849 | osu_ssid = get_param(cmd, "osu_ssid"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 12850 | |
| 12851 | val = get_param(cmd, "ProdESSAssoc"); |
| 12852 | if (val) |
| 12853 | prod_ess_assoc = atoi(val); |
| 12854 | |
| 12855 | kill_dhcp_client(dut, intf); |
| 12856 | if (start_dhcp_client(dut, intf) < 0) |
| 12857 | return -2; |
| 12858 | |
| 12859 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger OSU"); |
| 12860 | mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); |
| 12861 | res = snprintf(buf, sizeof(buf), |
Jouni Malinen | 4c8681c | 2018-09-12 23:28:11 +0300 | [diff] [blame] | 12862 | "%s %s%s%s %s%s%s signup osu-ca.pem", |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 12863 | prod_ess_assoc ? "" : "-N", |
| 12864 | name ? "-O'" : "", name ? name : "", |
Jouni Malinen | 4c8681c | 2018-09-12 23:28:11 +0300 | [diff] [blame] | 12865 | name ? "'" : "", |
| 12866 | osu_ssid ? "-o'" : "", osu_ssid ? osu_ssid : "", |
| 12867 | osu_ssid ? "'" : ""); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 12868 | |
Kanchanapally, Vidyullatha | 12b6676 | 2015-12-31 16:46:42 +0530 | [diff] [blame] | 12869 | hs2_set_policy(dut); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 12870 | if (run_hs20_osu(dut, buf) < 0) { |
| 12871 | FILE *f; |
| 12872 | |
| 12873 | sigma_dut_print(dut, DUT_MSG_INFO, "Failed to complete OSU"); |
| 12874 | |
| 12875 | f = fopen("hs20-osu-client.res", "r"); |
| 12876 | if (f) { |
| 12877 | char resp[400], res[300], *pos; |
| 12878 | if (!fgets(res, sizeof(res), f)) |
| 12879 | res[0] = '\0'; |
| 12880 | pos = strchr(res, '\n'); |
| 12881 | if (pos) |
| 12882 | *pos = '\0'; |
| 12883 | fclose(f); |
| 12884 | sigma_dut_summary(dut, "hs20-osu-client provisioning failed: %s", |
| 12885 | res); |
| 12886 | snprintf(resp, sizeof(resp), "notify-send '%s'", res); |
| 12887 | if (system(resp) != 0) { |
| 12888 | } |
| 12889 | snprintf(resp, sizeof(resp), |
| 12890 | "SSID,,BSSID,,failureReason,%s", res); |
| 12891 | send_resp(dut, conn, SIGMA_COMPLETE, resp); |
| 12892 | return 0; |
| 12893 | } |
| 12894 | |
| 12895 | send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,"); |
| 12896 | return 0; |
| 12897 | } |
| 12898 | |
| 12899 | if (!prod_ess_assoc) |
| 12900 | goto report; |
| 12901 | |
| 12902 | ctrl = open_wpa_mon(intf); |
| 12903 | if (ctrl == NULL) { |
| 12904 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open " |
| 12905 | "wpa_supplicant monitor connection"); |
| 12906 | return -1; |
| 12907 | } |
| 12908 | |
| 12909 | res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED", |
| 12910 | buf, sizeof(buf)); |
| 12911 | |
| 12912 | wpa_ctrl_detach(ctrl); |
| 12913 | wpa_ctrl_close(ctrl); |
| 12914 | |
| 12915 | if (res < 0) { |
| 12916 | sigma_dut_print(dut, DUT_MSG_INFO, "Failed to connect to " |
| 12917 | "network after OSU"); |
| 12918 | send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,"); |
| 12919 | return 0; |
| 12920 | } |
| 12921 | |
| 12922 | report: |
| 12923 | if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 || |
| 12924 | get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) { |
| 12925 | sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get BSSID/SSID"); |
| 12926 | send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,"); |
| 12927 | return 0; |
| 12928 | } |
| 12929 | |
| 12930 | snprintf(buf, sizeof(buf), "SSID,%s,BSSID,%s", ssid, bssid); |
| 12931 | send_resp(dut, conn, SIGMA_COMPLETE, buf); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 12932 | return 0; |
| 12933 | } |
| 12934 | |
| 12935 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 12936 | static enum sigma_cmd_result cmd_sta_policy_update(struct sigma_dut *dut, |
| 12937 | struct sigma_conn *conn, |
| 12938 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 12939 | { |
| 12940 | const char *val; |
| 12941 | int timeout = 120; |
| 12942 | |
| 12943 | val = get_param(cmd, "PolicyUpdate"); |
| 12944 | if (val == NULL || atoi(val) == 0) |
| 12945 | return 1; /* No operation requested */ |
| 12946 | |
| 12947 | val = get_param(cmd, "Timeout"); |
| 12948 | if (val) |
| 12949 | timeout = atoi(val); |
| 12950 | |
| 12951 | if (timeout) { |
| 12952 | /* TODO: time out the command and return |
| 12953 | * PolicyUpdateStatus,TIMEOUT if needed. */ |
| 12954 | } |
| 12955 | |
| 12956 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger policy update"); |
| 12957 | mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); |
| 12958 | if (run_hs20_osu(dut, "pol_upd fqdn=wi-fi.org") < 0) { |
| 12959 | send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,FAIL"); |
| 12960 | return 0; |
| 12961 | } |
| 12962 | |
| 12963 | send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,SUCCESS"); |
| 12964 | return 0; |
| 12965 | } |
| 12966 | |
| 12967 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 12968 | static enum sigma_cmd_result cmd_sta_er_config(struct sigma_dut *dut, |
| 12969 | struct sigma_conn *conn, |
| 12970 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 12971 | { |
| 12972 | struct wpa_ctrl *ctrl; |
| 12973 | const char *intf = get_param(cmd, "Interface"); |
| 12974 | const char *bssid = get_param(cmd, "Bssid"); |
| 12975 | const char *ssid = get_param(cmd, "SSID"); |
| 12976 | const char *security = get_param(cmd, "Security"); |
| 12977 | const char *passphrase = get_param(cmd, "Passphrase"); |
| 12978 | const char *pin = get_param(cmd, "PIN"); |
| 12979 | char buf[1000]; |
| 12980 | char ssid_hex[200], passphrase_hex[200]; |
| 12981 | const char *keymgmt, *cipher; |
| 12982 | |
| 12983 | if (intf == NULL) |
| 12984 | intf = get_main_ifname(); |
| 12985 | |
| 12986 | if (!bssid) { |
| 12987 | send_resp(dut, conn, SIGMA_ERROR, |
| 12988 | "ErrorCode,Missing Bssid argument"); |
| 12989 | return 0; |
| 12990 | } |
| 12991 | |
| 12992 | if (!ssid) { |
| 12993 | send_resp(dut, conn, SIGMA_ERROR, |
| 12994 | "ErrorCode,Missing SSID argument"); |
| 12995 | return 0; |
| 12996 | } |
| 12997 | |
| 12998 | if (!security) { |
| 12999 | send_resp(dut, conn, SIGMA_ERROR, |
| 13000 | "ErrorCode,Missing Security argument"); |
| 13001 | return 0; |
| 13002 | } |
| 13003 | |
| 13004 | if (!passphrase) { |
| 13005 | send_resp(dut, conn, SIGMA_ERROR, |
| 13006 | "ErrorCode,Missing Passphrase argument"); |
| 13007 | return 0; |
| 13008 | } |
| 13009 | |
| 13010 | if (!pin) { |
| 13011 | send_resp(dut, conn, SIGMA_ERROR, |
| 13012 | "ErrorCode,Missing PIN argument"); |
| 13013 | return 0; |
| 13014 | } |
| 13015 | |
vamsi krishna | 8c9c156 | 2017-05-12 15:51:46 +0530 | [diff] [blame] | 13016 | if (2 * strlen(ssid) >= sizeof(ssid_hex) || |
| 13017 | 2 * strlen(passphrase) >= sizeof(passphrase_hex)) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 13018 | send_resp(dut, conn, SIGMA_ERROR, |
| 13019 | "ErrorCode,Too long SSID/passphrase"); |
| 13020 | return 0; |
| 13021 | } |
| 13022 | |
| 13023 | ctrl = open_wpa_mon(intf); |
| 13024 | if (ctrl == NULL) { |
| 13025 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open " |
| 13026 | "wpa_supplicant monitor connection"); |
| 13027 | return -2; |
| 13028 | } |
| 13029 | |
| 13030 | if (strcasecmp(security, "wpa2-psk") == 0) { |
| 13031 | keymgmt = "WPA2PSK"; |
| 13032 | cipher = "CCMP"; |
| 13033 | } else { |
| 13034 | wpa_ctrl_detach(ctrl); |
| 13035 | wpa_ctrl_close(ctrl); |
| 13036 | send_resp(dut, conn, SIGMA_ERROR, |
| 13037 | "ErrorCode,Unsupported Security value"); |
| 13038 | return 0; |
| 13039 | } |
| 13040 | |
| 13041 | ascii2hexstr(ssid, ssid_hex); |
| 13042 | ascii2hexstr(passphrase, passphrase_hex); |
| 13043 | snprintf(buf, sizeof(buf), "WPS_REG %s %s %s %s %s %s", |
| 13044 | bssid, pin, ssid_hex, keymgmt, cipher, passphrase_hex); |
| 13045 | |
| 13046 | if (wpa_command(intf, buf) < 0) { |
| 13047 | wpa_ctrl_detach(ctrl); |
| 13048 | wpa_ctrl_close(ctrl); |
| 13049 | send_resp(dut, conn, SIGMA_ERROR, |
| 13050 | "ErrorCode,Failed to start registrar"); |
| 13051 | return 0; |
| 13052 | } |
| 13053 | |
| 13054 | snprintf(dut->er_oper_bssid, sizeof(dut->er_oper_bssid), "%s", bssid); |
| 13055 | dut->er_oper_performed = 1; |
| 13056 | |
| 13057 | return wps_connection_event(dut, conn, ctrl, intf, 0); |
| 13058 | } |
| 13059 | |
| 13060 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 13061 | static enum sigma_cmd_result |
| 13062 | cmd_sta_wps_connect_pw_token(struct sigma_dut *dut, struct sigma_conn *conn, |
| 13063 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 13064 | { |
| 13065 | struct wpa_ctrl *ctrl; |
| 13066 | const char *intf = get_param(cmd, "Interface"); |
| 13067 | const char *bssid = get_param(cmd, "Bssid"); |
| 13068 | char buf[100]; |
| 13069 | |
| 13070 | if (!bssid) { |
| 13071 | send_resp(dut, conn, SIGMA_ERROR, |
| 13072 | "ErrorCode,Missing Bssid argument"); |
| 13073 | return 0; |
| 13074 | } |
| 13075 | |
| 13076 | ctrl = open_wpa_mon(intf); |
| 13077 | if (ctrl == NULL) { |
| 13078 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open " |
| 13079 | "wpa_supplicant monitor connection"); |
| 13080 | return -2; |
| 13081 | } |
| 13082 | |
| 13083 | snprintf(buf, sizeof(buf), "WPS_NFC %s", bssid); |
| 13084 | |
| 13085 | if (wpa_command(intf, buf) < 0) { |
| 13086 | wpa_ctrl_detach(ctrl); |
| 13087 | wpa_ctrl_close(ctrl); |
| 13088 | send_resp(dut, conn, SIGMA_ERROR, |
| 13089 | "ErrorCode,Failed to start registrar"); |
| 13090 | return 0; |
| 13091 | } |
| 13092 | |
| 13093 | return wps_connection_event(dut, conn, ctrl, intf, 0); |
| 13094 | } |
| 13095 | |
| 13096 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 13097 | static enum sigma_cmd_result cmd_start_wps_registration(struct sigma_dut *dut, |
| 13098 | struct sigma_conn *conn, |
| 13099 | struct sigma_cmd *cmd) |
vamsi krishna | 9b14400 | 2017-09-20 13:28:13 +0530 | [diff] [blame] | 13100 | { |
| 13101 | struct wpa_ctrl *ctrl; |
| 13102 | const char *intf = get_param(cmd, "Interface"); |
Alexei Avshalom Lazar | d596b51 | 2018-12-18 16:00:59 +0200 | [diff] [blame] | 13103 | const char *network_mode = get_param(cmd, "network_mode"); |
Alexei Avshalom Lazar | 043230b | 2019-02-04 14:11:24 +0200 | [diff] [blame] | 13104 | const char *config_method = get_param(cmd, "WPSConfigMethod"); |
| 13105 | const char *role; |
vamsi krishna | 9b14400 | 2017-09-20 13:28:13 +0530 | [diff] [blame] | 13106 | int res; |
| 13107 | char buf[256]; |
| 13108 | const char *events[] = { |
| 13109 | "CTRL-EVENT-CONNECTED", |
| 13110 | "WPS-OVERLAP-DETECTED", |
| 13111 | "WPS-TIMEOUT", |
| 13112 | "WPS-FAIL", |
| 13113 | NULL |
| 13114 | }; |
Alexei Avshalom Lazar | d596b51 | 2018-12-18 16:00:59 +0200 | [diff] [blame] | 13115 | int id = 0; |
vamsi krishna | 9b14400 | 2017-09-20 13:28:13 +0530 | [diff] [blame] | 13116 | |
Alexei Avshalom Lazar | 35ab383 | 2018-12-23 16:49:49 +0200 | [diff] [blame] | 13117 | /* 60G WPS tests do not pass Interface parameter */ |
| 13118 | if (!intf) |
| 13119 | intf = get_main_ifname(); |
| 13120 | |
Alexei Avshalom Lazar | 043230b | 2019-02-04 14:11:24 +0200 | [diff] [blame] | 13121 | if (dut->mode == SIGMA_MODE_AP) |
| 13122 | return ap_wps_registration(dut, conn, cmd); |
| 13123 | |
| 13124 | if (config_method) { |
| 13125 | /* WFA_CS_WPS_PIN_KEYPAD mode is set when using the |
| 13126 | * sta_wps_enter_pin before calling start_wps_registration. */ |
| 13127 | if (strcasecmp(config_method, "PBC") == 0) |
| 13128 | dut->wps_method = WFA_CS_WPS_PBC; |
| 13129 | } |
| 13130 | if (dut->wps_method == WFA_CS_WPS_NOT_READY) { |
| 13131 | send_resp(dut, conn, SIGMA_ERROR, |
| 13132 | "ErrorCode,WPS parameters not yet set"); |
| 13133 | return STATUS_SENT; |
| 13134 | } |
| 13135 | |
| 13136 | /* Make sure WPS is enabled (also for STA mode) */ |
| 13137 | dut->wps_disable = 0; |
| 13138 | |
Alexei Avshalom Lazar | d596b51 | 2018-12-18 16:00:59 +0200 | [diff] [blame] | 13139 | if (dut->band == WPS_BAND_60G && network_mode && |
| 13140 | strcasecmp(network_mode, "PBSS") == 0) { |
| 13141 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 13142 | "Set PBSS network mode, network id %d", id); |
| 13143 | if (set_network(get_station_ifname(), id, "pbss", "1") < 0) |
| 13144 | return -2; |
| 13145 | } |
| 13146 | |
Alexei Avshalom Lazar | b094bf0 | 2018-12-18 16:00:53 +0200 | [diff] [blame] | 13147 | if (dut->force_rsn_ie) { |
| 13148 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Force RSN_IE: %d", |
| 13149 | dut->force_rsn_ie); |
| 13150 | if (sta_60g_force_rsn_ie(dut, dut->force_rsn_ie) < 0) { |
| 13151 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 13152 | "Failed to force RSN_IE"); |
Jouni Malinen | 0e29cf2 | 2019-02-19 01:13:21 +0200 | [diff] [blame] | 13153 | return ERROR_SEND_STATUS; |
Alexei Avshalom Lazar | b094bf0 | 2018-12-18 16:00:53 +0200 | [diff] [blame] | 13154 | } |
| 13155 | } |
| 13156 | |
vamsi krishna | 9b14400 | 2017-09-20 13:28:13 +0530 | [diff] [blame] | 13157 | ctrl = open_wpa_mon(intf); |
| 13158 | if (!ctrl) { |
| 13159 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 13160 | "Failed to open wpa_supplicant monitor connection"); |
| 13161 | return -2; |
| 13162 | } |
| 13163 | |
| 13164 | role = get_param(cmd, "WpsRole"); |
| 13165 | if (!role) { |
| 13166 | send_resp(dut, conn, SIGMA_INVALID, |
| 13167 | "ErrorCode,WpsRole not provided"); |
| 13168 | goto fail; |
| 13169 | } |
| 13170 | |
Alexei Avshalom Lazar | 043230b | 2019-02-04 14:11:24 +0200 | [diff] [blame] | 13171 | if (strcasecmp(role, "Enrollee") != 0) { |
| 13172 | /* Registrar role for STA not supported */ |
| 13173 | send_resp(dut, conn, SIGMA_ERROR, |
| 13174 | "ErrorCode,Unsupported WpsRole value"); |
| 13175 | goto fail; |
| 13176 | } |
| 13177 | |
| 13178 | if (is_60g_sigma_dut(dut)) { |
| 13179 | if (dut->wps_method == WFA_CS_WPS_PBC) |
| 13180 | snprintf(buf, sizeof(buf), "WPS_PBC"); |
| 13181 | else /* WFA_CS_WPS_PIN_KEYPAD */ |
| 13182 | snprintf(buf, sizeof(buf), "WPS_PIN any %s", |
| 13183 | dut->wps_pin); |
| 13184 | if (wpa_command(intf, buf) < 0) { |
| 13185 | send_resp(dut, conn, SIGMA_ERROR, |
| 13186 | "ErrorCode,Failed to start WPS"); |
vamsi krishna | 9b14400 | 2017-09-20 13:28:13 +0530 | [diff] [blame] | 13187 | goto fail; |
| 13188 | } |
Alexei Avshalom Lazar | 043230b | 2019-02-04 14:11:24 +0200 | [diff] [blame] | 13189 | res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf)); |
| 13190 | if (res < 0) { |
| 13191 | send_resp(dut, conn, SIGMA_ERROR, |
| 13192 | "ErrorCode,WPS connection did not complete"); |
| 13193 | goto fail; |
| 13194 | } |
| 13195 | if (strstr(buf, "WPS-TIMEOUT")) { |
| 13196 | send_resp(dut, conn, SIGMA_COMPLETE, "WpsState,NoPeer"); |
| 13197 | } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) { |
| 13198 | send_resp(dut, conn, SIGMA_COMPLETE, |
| 13199 | "WpsState,OverlapSession"); |
| 13200 | } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) { |
| 13201 | send_resp(dut, conn, SIGMA_COMPLETE, |
| 13202 | "WpsState,Successful"); |
| 13203 | } else { |
| 13204 | send_resp(dut, conn, SIGMA_COMPLETE, |
| 13205 | "WpsState,Failure"); |
| 13206 | } |
| 13207 | } else { |
| 13208 | if (dut->wps_method == WFA_CS_WPS_PBC) { |
vamsi krishna | 9b14400 | 2017-09-20 13:28:13 +0530 | [diff] [blame] | 13209 | if (wpa_command(intf, "WPS_PBC") < 0) { |
| 13210 | send_resp(dut, conn, SIGMA_ERROR, |
| 13211 | "ErrorCode,Failed to enable PBC"); |
| 13212 | goto fail; |
| 13213 | } |
| 13214 | } else { |
| 13215 | /* TODO: PIN method */ |
| 13216 | send_resp(dut, conn, SIGMA_ERROR, |
| 13217 | "ErrorCode,Unsupported WpsConfigMethod value"); |
| 13218 | goto fail; |
| 13219 | } |
| 13220 | res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf)); |
| 13221 | if (res < 0) { |
| 13222 | send_resp(dut, conn, SIGMA_ERROR, |
| 13223 | "ErrorCode,WPS connection did not complete"); |
| 13224 | goto fail; |
| 13225 | } |
| 13226 | if (strstr(buf, "WPS-TIMEOUT")) { |
| 13227 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,NoPeer"); |
| 13228 | } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) { |
| 13229 | send_resp(dut, conn, SIGMA_ERROR, |
| 13230 | "ErrorCode,OverlapSession"); |
| 13231 | } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) { |
| 13232 | send_resp(dut, conn, SIGMA_COMPLETE, "Successful"); |
| 13233 | } else { |
| 13234 | send_resp(dut, conn, SIGMA_ERROR, |
| 13235 | "ErrorCode,WPS operation failed"); |
| 13236 | } |
vamsi krishna | 9b14400 | 2017-09-20 13:28:13 +0530 | [diff] [blame] | 13237 | } |
| 13238 | |
| 13239 | fail: |
| 13240 | wpa_ctrl_detach(ctrl); |
| 13241 | wpa_ctrl_close(ctrl); |
| 13242 | return 0; |
| 13243 | } |
| 13244 | |
| 13245 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 13246 | static int req_intf(struct sigma_cmd *cmd) |
| 13247 | { |
| 13248 | return get_param(cmd, "interface") == NULL ? -1 : 0; |
| 13249 | } |
| 13250 | |
| 13251 | |
| 13252 | void sta_register_cmds(void) |
| 13253 | { |
| 13254 | sigma_dut_reg_cmd("sta_get_ip_config", req_intf, |
| 13255 | cmd_sta_get_ip_config); |
| 13256 | sigma_dut_reg_cmd("sta_set_ip_config", req_intf, |
| 13257 | cmd_sta_set_ip_config); |
| 13258 | sigma_dut_reg_cmd("sta_get_info", req_intf, cmd_sta_get_info); |
| 13259 | sigma_dut_reg_cmd("sta_get_mac_address", req_intf, |
| 13260 | cmd_sta_get_mac_address); |
| 13261 | sigma_dut_reg_cmd("sta_is_connected", req_intf, cmd_sta_is_connected); |
| 13262 | sigma_dut_reg_cmd("sta_verify_ip_connection", req_intf, |
| 13263 | cmd_sta_verify_ip_connection); |
| 13264 | sigma_dut_reg_cmd("sta_get_bssid", req_intf, cmd_sta_get_bssid); |
| 13265 | sigma_dut_reg_cmd("sta_set_encryption", req_intf, |
| 13266 | cmd_sta_set_encryption); |
| 13267 | sigma_dut_reg_cmd("sta_set_psk", req_intf, cmd_sta_set_psk); |
| 13268 | sigma_dut_reg_cmd("sta_set_eaptls", req_intf, cmd_sta_set_eaptls); |
| 13269 | sigma_dut_reg_cmd("sta_set_eapttls", req_intf, cmd_sta_set_eapttls); |
| 13270 | sigma_dut_reg_cmd("sta_set_eapsim", req_intf, cmd_sta_set_eapsim); |
| 13271 | sigma_dut_reg_cmd("sta_set_peap", req_intf, cmd_sta_set_peap); |
| 13272 | sigma_dut_reg_cmd("sta_set_eapfast", req_intf, cmd_sta_set_eapfast); |
| 13273 | sigma_dut_reg_cmd("sta_set_eapaka", req_intf, cmd_sta_set_eapaka); |
| 13274 | sigma_dut_reg_cmd("sta_set_eapakaprime", req_intf, |
| 13275 | cmd_sta_set_eapakaprime); |
| 13276 | sigma_dut_reg_cmd("sta_set_security", req_intf, cmd_sta_set_security); |
| 13277 | sigma_dut_reg_cmd("sta_set_uapsd", req_intf, cmd_sta_set_uapsd); |
| 13278 | /* TODO: sta_set_ibss */ |
| 13279 | /* TODO: sta_set_mode */ |
| 13280 | sigma_dut_reg_cmd("sta_set_wmm", req_intf, cmd_sta_set_wmm); |
| 13281 | sigma_dut_reg_cmd("sta_associate", req_intf, cmd_sta_associate); |
| 13282 | /* TODO: sta_up_load */ |
| 13283 | sigma_dut_reg_cmd("sta_preset_testparameters", req_intf, |
| 13284 | cmd_sta_preset_testparameters); |
| 13285 | /* TODO: sta_set_system */ |
| 13286 | sigma_dut_reg_cmd("sta_set_11n", req_intf, cmd_sta_set_11n); |
| 13287 | /* TODO: sta_set_rifs_test */ |
| 13288 | sigma_dut_reg_cmd("sta_set_wireless", req_intf, cmd_sta_set_wireless); |
| 13289 | sigma_dut_reg_cmd("sta_send_addba", req_intf, cmd_sta_send_addba); |
| 13290 | /* TODO: sta_send_coexist_mgmt */ |
| 13291 | sigma_dut_reg_cmd("sta_disconnect", req_intf, cmd_sta_disconnect); |
| 13292 | sigma_dut_reg_cmd("sta_reassoc", req_intf, cmd_sta_reassoc); |
| 13293 | sigma_dut_reg_cmd("sta_reassociate", req_intf, cmd_sta_reassoc); |
| 13294 | sigma_dut_reg_cmd("sta_reset_default", req_intf, |
| 13295 | cmd_sta_reset_default); |
| 13296 | sigma_dut_reg_cmd("sta_send_frame", req_intf, cmd_sta_send_frame); |
| 13297 | sigma_dut_reg_cmd("sta_set_macaddr", req_intf, cmd_sta_set_macaddr); |
| 13298 | sigma_dut_reg_cmd("sta_set_rfeature", req_intf, cmd_sta_set_rfeature); |
| 13299 | sigma_dut_reg_cmd("sta_set_radio", req_intf, cmd_sta_set_radio); |
| 13300 | sigma_dut_reg_cmd("sta_set_pwrsave", req_intf, cmd_sta_set_pwrsave); |
Alexei Avshalom Lazar | e49e387 | 2018-12-23 17:26:57 +0200 | [diff] [blame] | 13301 | sigma_dut_reg_cmd("sta_set_power_save", req_intf, cmd_sta_set_pwrsave); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 13302 | sigma_dut_reg_cmd("sta_bssid_pool", req_intf, cmd_sta_bssid_pool); |
| 13303 | sigma_dut_reg_cmd("sta_reset_parm", req_intf, cmd_sta_reset_parm); |
| 13304 | sigma_dut_reg_cmd("sta_get_key", req_intf, cmd_sta_get_key); |
| 13305 | sigma_dut_reg_cmd("sta_hs2_associate", req_intf, |
| 13306 | cmd_sta_hs2_associate); |
Jouni Malinen | b639f1c | 2018-09-13 02:39:46 +0300 | [diff] [blame] | 13307 | sigma_dut_reg_cmd("sta_hs2_venue_info", req_intf, |
| 13308 | cmd_sta_hs2_venue_info); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 13309 | sigma_dut_reg_cmd("sta_add_credential", req_intf, |
| 13310 | cmd_sta_add_credential); |
| 13311 | sigma_dut_reg_cmd("sta_scan", req_intf, cmd_sta_scan); |
Jouni Malinen | 5e5d43d | 2018-01-10 17:29:33 +0200 | [diff] [blame] | 13312 | 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] | 13313 | sigma_dut_reg_cmd("sta_set_systime", NULL, cmd_sta_set_systime); |
| 13314 | sigma_dut_reg_cmd("sta_osu", req_intf, cmd_sta_osu); |
| 13315 | sigma_dut_reg_cmd("sta_policy_update", req_intf, cmd_sta_policy_update); |
| 13316 | sigma_dut_reg_cmd("sta_er_config", NULL, cmd_sta_er_config); |
| 13317 | sigma_dut_reg_cmd("sta_wps_connect_pw_token", req_intf, |
| 13318 | cmd_sta_wps_connect_pw_token); |
Jouni Malinen | 8290520 | 2018-04-29 17:20:10 +0300 | [diff] [blame] | 13319 | sigma_dut_reg_cmd("sta_exec_action", NULL, cmd_sta_exec_action); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 13320 | sigma_dut_reg_cmd("sta_get_events", req_intf, cmd_sta_get_events); |
| 13321 | sigma_dut_reg_cmd("sta_get_parameter", req_intf, cmd_sta_get_parameter); |
Alexei Avshalom Lazar | 35ab383 | 2018-12-23 16:49:49 +0200 | [diff] [blame] | 13322 | sigma_dut_reg_cmd("start_wps_registration", NULL, |
vamsi krishna | 9b14400 | 2017-09-20 13:28:13 +0530 | [diff] [blame] | 13323 | cmd_start_wps_registration); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 13324 | } |