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; |
Jouni Malinen | 4b3769d | 2019-10-10 16:20:29 +0300 | [diff] [blame^] | 2055 | char buf[50]; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2056 | |
| 2057 | if (intf == NULL) |
| 2058 | return -1; |
| 2059 | |
| 2060 | if (strcmp(intf, get_main_ifname()) == 0) |
| 2061 | ifname = get_station_ifname(); |
| 2062 | else |
| 2063 | ifname = intf; |
| 2064 | |
| 2065 | id = set_wpa_common(dut, conn, ifname, cmd); |
| 2066 | if (id < 0) |
| 2067 | return id; |
| 2068 | |
| 2069 | val = get_param(cmd, "keyMgmtType"); |
| 2070 | alg = get_param(cmd, "micAlg"); |
| 2071 | |
Jouni Malinen | 992a81e | 2017-08-22 13:57:47 +0300 | [diff] [blame] | 2072 | if (type && strcasecmp(type, "SAE") == 0) { |
Jouni Malinen | e4fde73 | 2019-03-25 22:29:37 +0200 | [diff] [blame] | 2073 | if (!akm && val && strcasecmp(val, "wpa2-ft") == 0) { |
Jouni Malinen | 992a81e | 2017-08-22 13:57:47 +0300 | [diff] [blame] | 2074 | if (set_network(ifname, id, "key_mgmt", "FT-SAE") < 0) |
| 2075 | return -2; |
Jouni Malinen | e4fde73 | 2019-03-25 22:29:37 +0200 | [diff] [blame] | 2076 | } else if (!akm) { |
Jouni Malinen | 992a81e | 2017-08-22 13:57:47 +0300 | [diff] [blame] | 2077 | if (set_network(ifname, id, "key_mgmt", "SAE") < 0) |
| 2078 | return -2; |
| 2079 | } |
| 2080 | if (wpa_command(ifname, "SET sae_groups ") != 0) { |
| 2081 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 2082 | "Failed to clear sae_groups to default"); |
| 2083 | return -2; |
| 2084 | } |
Jouni Malinen | 1287cd7 | 2018-01-04 17:08:01 +0200 | [diff] [blame] | 2085 | if (!pmf) { |
| 2086 | dut->sta_pmf = STA_PMF_REQUIRED; |
| 2087 | if (set_network(ifname, id, "ieee80211w", "2") < 0) |
| 2088 | return -2; |
| 2089 | } |
Jouni Malinen | 0ab50f4 | 2017-08-31 01:34:59 +0300 | [diff] [blame] | 2090 | } else if (type && strcasecmp(type, "PSK-SAE") == 0) { |
| 2091 | if (val && strcasecmp(val, "wpa2-ft") == 0) { |
| 2092 | if (set_network(ifname, id, "key_mgmt", |
| 2093 | "FT-SAE FT-PSK") < 0) |
| 2094 | return -2; |
Jouni Malinen | 3b73d87 | 2019-06-12 03:13:25 +0300 | [diff] [blame] | 2095 | } else if (!akm) { |
Jouni Malinen | 0ab50f4 | 2017-08-31 01:34:59 +0300 | [diff] [blame] | 2096 | if (set_network(ifname, id, "key_mgmt", |
| 2097 | "SAE WPA-PSK") < 0) |
| 2098 | return -2; |
| 2099 | } |
| 2100 | if (wpa_command(ifname, "SET sae_groups ") != 0) { |
| 2101 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 2102 | "Failed to clear sae_groups to default"); |
| 2103 | return -2; |
| 2104 | } |
Jouni Malinen | 1287cd7 | 2018-01-04 17:08:01 +0200 | [diff] [blame] | 2105 | if (!pmf) { |
| 2106 | dut->sta_pmf = STA_PMF_OPTIONAL; |
| 2107 | if (set_network(ifname, id, "ieee80211w", "1") < 0) |
| 2108 | return -2; |
| 2109 | } |
Jouni Malinen | 992a81e | 2017-08-22 13:57:47 +0300 | [diff] [blame] | 2110 | } else if (alg && strcasecmp(alg, "SHA-256") == 0) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2111 | if (set_network(ifname, id, "key_mgmt", "WPA-PSK-SHA256") < 0) |
| 2112 | return -2; |
| 2113 | } else if (alg && strcasecmp(alg, "SHA-1") == 0) { |
| 2114 | if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0) |
| 2115 | return -2; |
Ashwini Patil | 6dbf7b0 | 2017-03-20 13:42:11 +0530 | [diff] [blame] | 2116 | } else if (val && strcasecmp(val, "wpa2-ft") == 0) { |
| 2117 | if (set_network(ifname, id, "key_mgmt", "FT-PSK") < 0) |
| 2118 | return -2; |
Jouni Malinen | 3b73d87 | 2019-06-12 03:13:25 +0300 | [diff] [blame] | 2119 | } else if (!akm && |
| 2120 | ((val && strcasecmp(val, "wpa2-sha256") == 0) || |
| 2121 | dut->sta_pmf == STA_PMF_REQUIRED)) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2122 | if (set_network(ifname, id, "key_mgmt", |
| 2123 | "WPA-PSK WPA-PSK-SHA256") < 0) |
| 2124 | return -2; |
Jouni Malinen | 77ff3f0 | 2019-03-28 03:45:40 +0200 | [diff] [blame] | 2125 | } else if (!akm && dut->sta_pmf == STA_PMF_OPTIONAL) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2126 | if (set_network(ifname, id, "key_mgmt", |
| 2127 | "WPA-PSK WPA-PSK-SHA256") < 0) |
| 2128 | return -2; |
Jouni Malinen | 77ff3f0 | 2019-03-28 03:45:40 +0200 | [diff] [blame] | 2129 | } else if (!akm) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2130 | if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0) |
| 2131 | return -2; |
| 2132 | } |
| 2133 | |
| 2134 | val = get_param(cmd, "passPhrase"); |
| 2135 | if (val == NULL) |
| 2136 | return -1; |
Jouni Malinen | 2126f42 | 2017-10-11 23:24:33 +0300 | [diff] [blame] | 2137 | if (type && strcasecmp(type, "SAE") == 0) { |
| 2138 | if (set_network_quoted(ifname, id, "sae_password", val) < 0) |
| 2139 | return -2; |
| 2140 | } else { |
| 2141 | if (set_network_quoted(ifname, id, "psk", val) < 0) |
| 2142 | return -2; |
| 2143 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2144 | |
Jouni Malinen | 78d10c4 | 2019-03-25 22:34:32 +0200 | [diff] [blame] | 2145 | val = get_param(cmd, "PasswordId"); |
| 2146 | if (val && set_network_quoted(ifname, id, "sae_password_id", val) < 0) |
| 2147 | return ERROR_SEND_STATUS; |
| 2148 | |
Jouni Malinen | 992a81e | 2017-08-22 13:57:47 +0300 | [diff] [blame] | 2149 | val = get_param(cmd, "ECGroupID"); |
| 2150 | if (val) { |
Jouni Malinen | 992a81e | 2017-08-22 13:57:47 +0300 | [diff] [blame] | 2151 | snprintf(buf, sizeof(buf), "SET sae_groups %u", atoi(val)); |
| 2152 | if (wpa_command(ifname, buf) != 0) { |
| 2153 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 2154 | "Failed to clear sae_groups"); |
| 2155 | return -2; |
| 2156 | } |
| 2157 | } |
| 2158 | |
Jouni Malinen | 6814313 | 2017-09-02 02:34:08 +0300 | [diff] [blame] | 2159 | val = get_param(cmd, "InvalidSAEElement"); |
| 2160 | if (val) { |
| 2161 | free(dut->sae_commit_override); |
| 2162 | dut->sae_commit_override = strdup(val); |
| 2163 | } |
| 2164 | |
Jouni Malinen | 4b3769d | 2019-10-10 16:20:29 +0300 | [diff] [blame^] | 2165 | val = get_param(cmd, "PMKID_Include"); |
| 2166 | if (val) { |
| 2167 | snprintf(buf, sizeof(buf), "SET sae_pmkid_in_assoc %d", |
| 2168 | get_enable_disable(val)); |
| 2169 | wpa_command(intf, buf); |
| 2170 | } |
| 2171 | |
Alexei Avshalom Lazar | d596b51 | 2018-12-18 16:00:59 +0200 | [diff] [blame] | 2172 | if (dut->program == PROGRAM_60GHZ && network_mode && |
| 2173 | strcasecmp(network_mode, "PBSS") == 0 && |
| 2174 | set_network(ifname, id, "pbss", "1") < 0) |
| 2175 | return -2; |
| 2176 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2177 | return 1; |
| 2178 | } |
| 2179 | |
| 2180 | |
Jouni Malinen | 8ac9345 | 2019-08-14 15:19:13 +0300 | [diff] [blame] | 2181 | static enum sigma_cmd_result set_trust_root_system(struct sigma_dut *dut, |
| 2182 | struct sigma_conn *conn, |
| 2183 | const char *ifname, int id) |
| 2184 | { |
| 2185 | char buf[200]; |
| 2186 | |
| 2187 | snprintf(buf, sizeof(buf), "%s/certs", sigma_cert_path); |
| 2188 | if (!file_exists(buf)) |
| 2189 | strlcpy(buf, "/system/etc/security/cacerts", sizeof(buf)); |
| 2190 | if (!file_exists(buf)) |
| 2191 | strlcpy(buf, "/etc/ssl/certs", sizeof(buf)); |
| 2192 | if (!file_exists(buf)) { |
| 2193 | char msg[300]; |
| 2194 | |
| 2195 | snprintf(msg, sizeof(msg), |
| 2196 | "ErrorCode,trustedRootCA system store (%s) not found", |
| 2197 | buf); |
| 2198 | send_resp(dut, conn, SIGMA_ERROR, msg); |
| 2199 | return STATUS_SENT_ERROR; |
| 2200 | } |
| 2201 | |
| 2202 | if (set_network_quoted(ifname, id, "ca_path", buf) < 0) |
| 2203 | return ERROR_SEND_STATUS; |
| 2204 | |
| 2205 | return SUCCESS_SEND_STATUS; |
| 2206 | } |
| 2207 | |
| 2208 | |
| 2209 | static enum sigma_cmd_result set_trust_root(struct sigma_dut *dut, |
| 2210 | struct sigma_conn *conn, |
| 2211 | const char *ifname, int id, |
| 2212 | const char *val) |
| 2213 | { |
| 2214 | char buf[200]; |
| 2215 | #ifdef ANDROID |
| 2216 | unsigned char kvalue[KEYSTORE_MESSAGE_SIZE]; |
| 2217 | int length; |
| 2218 | #endif /* ANDROID */ |
| 2219 | |
| 2220 | if (strcmp(val, "DEFAULT") == 0) |
| 2221 | return set_trust_root_system(dut, conn, ifname, id); |
| 2222 | |
| 2223 | #ifdef ANDROID |
| 2224 | snprintf(buf, sizeof(buf), "CACERT_%s", val); |
| 2225 | length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue); |
| 2226 | if (length > 0) { |
| 2227 | sigma_dut_print(dut, DUT_MSG_INFO, "Use Android keystore [%s]", |
| 2228 | buf); |
| 2229 | snprintf(buf, sizeof(buf), "keystore://CACERT_%s", val); |
| 2230 | goto ca_cert_selected; |
| 2231 | } |
| 2232 | #endif /* ANDROID */ |
| 2233 | |
| 2234 | snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val); |
| 2235 | #ifdef __linux__ |
| 2236 | if (!file_exists(buf)) { |
| 2237 | char msg[300]; |
| 2238 | |
| 2239 | snprintf(msg, sizeof(msg), |
| 2240 | "ErrorCode,trustedRootCA file (%s) not found", buf); |
| 2241 | send_resp(dut, conn, SIGMA_ERROR, msg); |
| 2242 | return STATUS_SENT_ERROR; |
| 2243 | } |
| 2244 | #endif /* __linux__ */ |
| 2245 | #ifdef ANDROID |
| 2246 | ca_cert_selected: |
| 2247 | #endif /* ANDROID */ |
| 2248 | if (set_network_quoted(ifname, id, "ca_cert", buf) < 0) |
| 2249 | return ERROR_SEND_STATUS; |
| 2250 | |
| 2251 | return SUCCESS_SEND_STATUS; |
| 2252 | } |
| 2253 | |
| 2254 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2255 | 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] | 2256 | const char *ifname, int username_identity, |
| 2257 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2258 | { |
Jouni Malinen | b4d56ba | 2019-08-23 18:17:44 +0300 | [diff] [blame] | 2259 | const char *val, *alg, *akm, *trust_root, *domain, *domain_suffix; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2260 | int id; |
Jouni Malinen | 53264f6 | 2019-05-03 13:04:40 +0300 | [diff] [blame] | 2261 | char buf[200], buf2[300]; |
Jouni Malinen | 8179fee | 2019-03-28 03:19:47 +0200 | [diff] [blame] | 2262 | int erp = 0; |
Jouni Malinen | 8ac9345 | 2019-08-14 15:19:13 +0300 | [diff] [blame] | 2263 | enum sigma_cmd_result res; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2264 | |
| 2265 | id = set_wpa_common(dut, conn, ifname, cmd); |
| 2266 | if (id < 0) |
| 2267 | return id; |
| 2268 | |
| 2269 | val = get_param(cmd, "keyMgmtType"); |
| 2270 | alg = get_param(cmd, "micAlg"); |
vamsi krishna | f39bc1e | 2017-08-23 17:37:53 +0530 | [diff] [blame] | 2271 | akm = get_param(cmd, "AKMSuiteType"); |
Jouni Malinen | b4d56ba | 2019-08-23 18:17:44 +0300 | [diff] [blame] | 2272 | trust_root = get_param(cmd, "trustedRootCA"); |
| 2273 | domain = get_param(cmd, "Domain"); |
| 2274 | domain_suffix = get_param(cmd, "DomainSuffix"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2275 | |
Jouni Malinen | ad395a2 | 2017-09-01 21:13:46 +0300 | [diff] [blame] | 2276 | if (val && strcasecmp(val, "SuiteB") == 0) { |
| 2277 | if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SUITE-B-192") < |
| 2278 | 0) |
| 2279 | return -2; |
| 2280 | } else if (alg && strcasecmp(alg, "SHA-256") == 0) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2281 | if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SHA256") < 0) |
| 2282 | return -2; |
| 2283 | } else if (alg && strcasecmp(alg, "SHA-1") == 0) { |
| 2284 | if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0) |
| 2285 | return -2; |
| 2286 | } else if (val && strcasecmp(val, "wpa2-ft") == 0) { |
| 2287 | if (set_network(ifname, id, "key_mgmt", "FT-EAP") < 0) |
| 2288 | return -2; |
Jouni Malinen | d6a9d69 | 2019-03-28 03:01:24 +0200 | [diff] [blame] | 2289 | } else if (!akm && |
| 2290 | ((val && strcasecmp(val, "wpa2-sha256") == 0) || |
| 2291 | dut->sta_pmf == STA_PMF_REQUIRED)) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2292 | if (set_network(ifname, id, "key_mgmt", |
| 2293 | "WPA-EAP WPA-EAP-SHA256") < 0) |
| 2294 | return -2; |
vamsi krishna | f39bc1e | 2017-08-23 17:37:53 +0530 | [diff] [blame] | 2295 | } else if (akm && atoi(akm) == 14) { |
| 2296 | if (dut->sta_pmf == STA_PMF_OPTIONAL || |
| 2297 | dut->sta_pmf == STA_PMF_REQUIRED) { |
| 2298 | if (set_network(ifname, id, "key_mgmt", |
| 2299 | "WPA-EAP-SHA256 FILS-SHA256") < 0) |
| 2300 | return -2; |
| 2301 | } else { |
| 2302 | if (set_network(ifname, id, "key_mgmt", |
| 2303 | "WPA-EAP FILS-SHA256") < 0) |
| 2304 | return -2; |
| 2305 | } |
| 2306 | |
Jouni Malinen | 8179fee | 2019-03-28 03:19:47 +0200 | [diff] [blame] | 2307 | erp = 1; |
vamsi krishna | f39bc1e | 2017-08-23 17:37:53 +0530 | [diff] [blame] | 2308 | } else if (akm && atoi(akm) == 15) { |
| 2309 | if (dut->sta_pmf == STA_PMF_OPTIONAL || |
| 2310 | dut->sta_pmf == STA_PMF_REQUIRED) { |
| 2311 | if (set_network(ifname, id, "key_mgmt", |
| 2312 | "WPA-EAP-SHA256 FILS-SHA384") < 0) |
| 2313 | return -2; |
| 2314 | } else { |
| 2315 | if (set_network(ifname, id, "key_mgmt", |
| 2316 | "WPA-EAP FILS-SHA384") < 0) |
| 2317 | return -2; |
| 2318 | } |
| 2319 | |
Jouni Malinen | 8179fee | 2019-03-28 03:19:47 +0200 | [diff] [blame] | 2320 | erp = 1; |
Jouni Malinen | d6a9d69 | 2019-03-28 03:01:24 +0200 | [diff] [blame] | 2321 | } else if (!akm && dut->sta_pmf == STA_PMF_OPTIONAL) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2322 | if (set_network(ifname, id, "key_mgmt", |
| 2323 | "WPA-EAP WPA-EAP-SHA256") < 0) |
| 2324 | return -2; |
Jouni Malinen | d6a9d69 | 2019-03-28 03:01:24 +0200 | [diff] [blame] | 2325 | } else if (!akm) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2326 | if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0) |
| 2327 | return -2; |
| 2328 | } |
| 2329 | |
Jouni Malinen | b4d56ba | 2019-08-23 18:17:44 +0300 | [diff] [blame] | 2330 | if (trust_root) { |
| 2331 | if (strcmp(trust_root, "DEFAULT") == 0 && !domain && |
| 2332 | !domain_suffix) { |
| 2333 | send_resp(dut, conn, SIGMA_ERROR, |
| 2334 | "errorCode,trustRootCA DEFAULT used without specifying Domain or DomainSuffix"); |
| 2335 | return STATUS_SENT_ERROR; |
| 2336 | } |
| 2337 | res = set_trust_root(dut, conn, ifname, id, trust_root); |
Jouni Malinen | 8ac9345 | 2019-08-14 15:19:13 +0300 | [diff] [blame] | 2338 | if (res != SUCCESS_SEND_STATUS) |
| 2339 | return res; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2340 | } |
| 2341 | |
Jouni Malinen | 53264f6 | 2019-05-03 13:04:40 +0300 | [diff] [blame] | 2342 | val = get_param(cmd, "ServerCert"); |
| 2343 | if (val) { |
| 2344 | FILE *f; |
| 2345 | char *result = NULL, *pos; |
| 2346 | |
| 2347 | snprintf(buf, sizeof(buf), "%s/%s.sha256", sigma_cert_path, |
| 2348 | val); |
| 2349 | f = fopen(buf, "r"); |
| 2350 | if (f) { |
| 2351 | result = fgets(buf, sizeof(buf), f); |
| 2352 | fclose(f); |
| 2353 | } |
| 2354 | if (!result) { |
| 2355 | snprintf(buf2, sizeof(buf2), |
| 2356 | "ErrorCode,ServerCert hash could not be read from %s", |
| 2357 | buf); |
| 2358 | send_resp(dut, conn, SIGMA_ERROR, buf2); |
| 2359 | return STATUS_SENT_ERROR; |
| 2360 | } |
| 2361 | pos = strchr(buf, '\n'); |
| 2362 | if (pos) |
| 2363 | *pos = '\0'; |
| 2364 | snprintf(buf2, sizeof(buf2), "hash://server/sha256/%s", buf); |
| 2365 | if (set_network_quoted(ifname, id, "ca_cert", buf2) < 0) |
| 2366 | return ERROR_SEND_STATUS; |
Jouni Malinen | 29108dc | 2019-06-13 23:42:11 +0300 | [diff] [blame] | 2367 | |
| 2368 | snprintf(buf, sizeof(buf), "%s/%s.tod", sigma_cert_path, val); |
| 2369 | if (file_exists(buf)) { |
| 2370 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 2371 | "TOD policy enabled for the configured ServerCert hash"); |
| 2372 | dut->sta_tod_policy = 1; |
| 2373 | } |
Jouni Malinen | 53264f6 | 2019-05-03 13:04:40 +0300 | [diff] [blame] | 2374 | } |
| 2375 | |
Jouni Malinen | b4d56ba | 2019-08-23 18:17:44 +0300 | [diff] [blame] | 2376 | if (domain && |
| 2377 | set_network_quoted(ifname, id, "domain_match", domain) < 0) |
Jouni Malinen | 96f84b0 | 2019-05-03 12:32:56 +0300 | [diff] [blame] | 2378 | return ERROR_SEND_STATUS; |
| 2379 | |
Jouni Malinen | b4d56ba | 2019-08-23 18:17:44 +0300 | [diff] [blame] | 2380 | if (domain_suffix && |
| 2381 | set_network_quoted(ifname, id, "domain_suffix_match", |
| 2382 | domain_suffix) < 0) |
Jouni Malinen | 96f84b0 | 2019-05-03 12:32:56 +0300 | [diff] [blame] | 2383 | return ERROR_SEND_STATUS; |
| 2384 | |
Bala Krishna Bhamidipati | 73d7af0 | 2016-03-24 12:27:56 +0530 | [diff] [blame] | 2385 | if (username_identity) { |
| 2386 | val = get_param(cmd, "username"); |
| 2387 | if (val) { |
| 2388 | if (set_network_quoted(ifname, id, "identity", val) < 0) |
| 2389 | return -2; |
| 2390 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2391 | |
Bala Krishna Bhamidipati | 73d7af0 | 2016-03-24 12:27:56 +0530 | [diff] [blame] | 2392 | val = get_param(cmd, "password"); |
| 2393 | if (val) { |
| 2394 | if (set_network_quoted(ifname, id, "password", val) < 0) |
| 2395 | return -2; |
| 2396 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2397 | } |
| 2398 | |
Jouni Malinen | 8179fee | 2019-03-28 03:19:47 +0200 | [diff] [blame] | 2399 | if (dut->akm_values & |
| 2400 | ((1 << AKM_FILS_SHA256) | |
| 2401 | (1 << AKM_FILS_SHA384) | |
| 2402 | (1 << AKM_FT_FILS_SHA256) | |
| 2403 | (1 << AKM_FT_FILS_SHA384))) |
| 2404 | erp = 1; |
| 2405 | if (erp && set_network(ifname, id, "erp", "1") < 0) |
| 2406 | return ERROR_SEND_STATUS; |
| 2407 | |
Jouni Malinen | 134fe3c | 2019-06-12 04:16:49 +0300 | [diff] [blame] | 2408 | dut->sta_associate_wait_connect = 1; |
| 2409 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2410 | return id; |
| 2411 | } |
| 2412 | |
| 2413 | |
Jouni Malinen | 5eabb2a | 2017-10-03 18:17:30 +0300 | [diff] [blame] | 2414 | static int set_tls_cipher(const char *ifname, int id, const char *cipher) |
| 2415 | { |
| 2416 | const char *val; |
| 2417 | |
| 2418 | if (!cipher) |
| 2419 | return 0; |
| 2420 | |
| 2421 | if (strcasecmp(cipher, "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384") == 0) |
| 2422 | val = "ECDHE-ECDSA-AES256-GCM-SHA384"; |
| 2423 | else if (strcasecmp(cipher, |
| 2424 | "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384") == 0) |
| 2425 | val = "ECDHE-RSA-AES256-GCM-SHA384"; |
| 2426 | else if (strcasecmp(cipher, "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384") == 0) |
| 2427 | val = "DHE-RSA-AES256-GCM-SHA384"; |
| 2428 | else if (strcasecmp(cipher, |
| 2429 | "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256") == 0) |
| 2430 | val = "ECDHE-ECDSA-AES128-GCM-SHA256"; |
| 2431 | else |
| 2432 | return -1; |
| 2433 | |
| 2434 | /* Need to clear phase1="tls_suiteb=1" to allow cipher enforcement */ |
| 2435 | set_network_quoted(ifname, id, "phase1", ""); |
| 2436 | |
| 2437 | return set_network_quoted(ifname, id, "openssl_ciphers", val); |
| 2438 | } |
| 2439 | |
| 2440 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 2441 | static enum sigma_cmd_result cmd_sta_set_eaptls(struct sigma_dut *dut, |
| 2442 | struct sigma_conn *conn, |
| 2443 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2444 | { |
| 2445 | const char *intf = get_param(cmd, "Interface"); |
| 2446 | const char *ifname, *val; |
| 2447 | int id; |
| 2448 | char buf[200]; |
| 2449 | #ifdef ANDROID |
| 2450 | unsigned char kvalue[KEYSTORE_MESSAGE_SIZE]; |
| 2451 | int length; |
| 2452 | int jb_or_newer = 0; |
| 2453 | char prop[PROPERTY_VALUE_MAX]; |
| 2454 | #endif /* ANDROID */ |
| 2455 | |
| 2456 | if (intf == NULL) |
| 2457 | return -1; |
| 2458 | |
| 2459 | if (strcmp(intf, get_main_ifname()) == 0) |
| 2460 | ifname = get_station_ifname(); |
| 2461 | else |
| 2462 | ifname = intf; |
| 2463 | |
Bala Krishna Bhamidipati | 73d7af0 | 2016-03-24 12:27:56 +0530 | [diff] [blame] | 2464 | id = set_eap_common(dut, conn, ifname, 1, cmd); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2465 | if (id < 0) |
| 2466 | return id; |
| 2467 | |
| 2468 | if (set_network(ifname, id, "eap", "TLS") < 0) |
| 2469 | return -2; |
| 2470 | |
Pradeep Reddy POTTETI | 9f6c213 | 2016-05-05 16:28:19 +0530 | [diff] [blame] | 2471 | if (!get_param(cmd, "username") && |
| 2472 | set_network_quoted(ifname, id, "identity", |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2473 | "wifi-user@wifilabs.local") < 0) |
| 2474 | return -2; |
| 2475 | |
| 2476 | val = get_param(cmd, "clientCertificate"); |
| 2477 | if (val == NULL) |
| 2478 | return -1; |
| 2479 | #ifdef ANDROID |
| 2480 | snprintf(buf, sizeof(buf), "USRPKEY_%s", val); |
| 2481 | length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue); |
| 2482 | if (length < 0) { |
| 2483 | /* |
| 2484 | * JB started reporting keystore type mismatches, so retry with |
| 2485 | * the GET_PUBKEY command if the generic GET fails. |
| 2486 | */ |
| 2487 | length = android_keystore_get(ANDROID_KEYSTORE_GET_PUBKEY, |
| 2488 | buf, kvalue); |
| 2489 | } |
| 2490 | |
| 2491 | if (property_get("ro.build.version.release", prop, NULL) != 0) { |
| 2492 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Android release %s", prop); |
| 2493 | if (strncmp(prop, "4.0", 3) != 0) |
| 2494 | jb_or_newer = 1; |
| 2495 | } else |
| 2496 | jb_or_newer = 1; /* assume newer */ |
| 2497 | |
| 2498 | if (jb_or_newer && length > 0) { |
| 2499 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 2500 | "Use Android keystore [%s]", buf); |
| 2501 | if (set_network(ifname, id, "engine", "1") < 0) |
| 2502 | return -2; |
| 2503 | if (set_network_quoted(ifname, id, "engine_id", "keystore") < 0) |
| 2504 | return -2; |
| 2505 | snprintf(buf, sizeof(buf), "USRPKEY_%s", val); |
| 2506 | if (set_network_quoted(ifname, id, "key_id", buf) < 0) |
| 2507 | return -2; |
| 2508 | snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val); |
| 2509 | if (set_network_quoted(ifname, id, "client_cert", buf) < 0) |
| 2510 | return -2; |
| 2511 | return 1; |
| 2512 | } else if (length > 0) { |
| 2513 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 2514 | "Use Android keystore [%s]", buf); |
| 2515 | snprintf(buf, sizeof(buf), "keystore://USRPKEY_%s", val); |
| 2516 | if (set_network_quoted(ifname, id, "private_key", buf) < 0) |
| 2517 | return -2; |
| 2518 | snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val); |
| 2519 | if (set_network_quoted(ifname, id, "client_cert", buf) < 0) |
| 2520 | return -2; |
| 2521 | return 1; |
| 2522 | } |
| 2523 | #endif /* ANDROID */ |
| 2524 | |
| 2525 | snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val); |
| 2526 | #ifdef __linux__ |
| 2527 | if (!file_exists(buf)) { |
| 2528 | char msg[300]; |
| 2529 | snprintf(msg, sizeof(msg), "ErrorCode,clientCertificate file " |
| 2530 | "(%s) not found", buf); |
| 2531 | send_resp(dut, conn, SIGMA_ERROR, msg); |
| 2532 | return -3; |
| 2533 | } |
| 2534 | #endif /* __linux__ */ |
| 2535 | if (set_network_quoted(ifname, id, "private_key", buf) < 0) |
| 2536 | return -2; |
| 2537 | if (set_network_quoted(ifname, id, "client_cert", buf) < 0) |
| 2538 | return -2; |
| 2539 | |
| 2540 | if (set_network_quoted(ifname, id, "private_key_passwd", "wifi") < 0) |
| 2541 | return -2; |
| 2542 | |
Jouni Malinen | 5eabb2a | 2017-10-03 18:17:30 +0300 | [diff] [blame] | 2543 | val = get_param(cmd, "keyMgmtType"); |
| 2544 | if (val && strcasecmp(val, "SuiteB") == 0) { |
| 2545 | val = get_param(cmd, "CertType"); |
| 2546 | if (val && strcasecmp(val, "RSA") == 0) { |
| 2547 | if (set_network_quoted(ifname, id, "phase1", |
| 2548 | "tls_suiteb=1") < 0) |
| 2549 | return -2; |
| 2550 | } else { |
| 2551 | if (set_network_quoted(ifname, id, "openssl_ciphers", |
| 2552 | "SUITEB192") < 0) |
| 2553 | return -2; |
| 2554 | } |
| 2555 | |
| 2556 | val = get_param(cmd, "TLSCipher"); |
| 2557 | if (set_tls_cipher(ifname, id, val) < 0) { |
| 2558 | send_resp(dut, conn, SIGMA_ERROR, |
| 2559 | "ErrorCode,Unsupported TLSCipher value"); |
| 2560 | return -3; |
| 2561 | } |
| 2562 | } |
| 2563 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2564 | return 1; |
| 2565 | } |
| 2566 | |
| 2567 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 2568 | static enum sigma_cmd_result cmd_sta_set_eapttls(struct sigma_dut *dut, |
| 2569 | struct sigma_conn *conn, |
| 2570 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2571 | { |
| 2572 | const char *intf = get_param(cmd, "Interface"); |
| 2573 | const char *ifname; |
| 2574 | int id; |
| 2575 | |
| 2576 | if (intf == NULL) |
| 2577 | return -1; |
| 2578 | |
| 2579 | if (strcmp(intf, get_main_ifname()) == 0) |
| 2580 | ifname = get_station_ifname(); |
| 2581 | else |
| 2582 | ifname = intf; |
| 2583 | |
Bala Krishna Bhamidipati | 73d7af0 | 2016-03-24 12:27:56 +0530 | [diff] [blame] | 2584 | id = set_eap_common(dut, conn, ifname, 1, cmd); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2585 | if (id < 0) |
| 2586 | return id; |
| 2587 | |
| 2588 | if (set_network(ifname, id, "eap", "TTLS") < 0) { |
| 2589 | send_resp(dut, conn, SIGMA_ERROR, |
| 2590 | "errorCode,Failed to set TTLS method"); |
| 2591 | return 0; |
| 2592 | } |
| 2593 | |
| 2594 | if (set_network_quoted(ifname, id, "phase2", "auth=MSCHAPV2") < 0) { |
| 2595 | send_resp(dut, conn, SIGMA_ERROR, |
| 2596 | "errorCode,Failed to set MSCHAPv2 for TTLS Phase 2"); |
| 2597 | return 0; |
| 2598 | } |
| 2599 | |
| 2600 | return 1; |
| 2601 | } |
| 2602 | |
| 2603 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 2604 | static enum sigma_cmd_result cmd_sta_set_eapsim(struct sigma_dut *dut, |
| 2605 | struct sigma_conn *conn, |
| 2606 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2607 | { |
| 2608 | const char *intf = get_param(cmd, "Interface"); |
| 2609 | const char *ifname; |
| 2610 | int id; |
| 2611 | |
| 2612 | if (intf == NULL) |
| 2613 | return -1; |
| 2614 | |
| 2615 | if (strcmp(intf, get_main_ifname()) == 0) |
| 2616 | ifname = get_station_ifname(); |
| 2617 | else |
| 2618 | ifname = intf; |
| 2619 | |
Bala Krishna Bhamidipati | 73d7af0 | 2016-03-24 12:27:56 +0530 | [diff] [blame] | 2620 | id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2621 | if (id < 0) |
| 2622 | return id; |
| 2623 | |
| 2624 | if (set_network(ifname, id, "eap", "SIM") < 0) |
| 2625 | return -2; |
| 2626 | |
| 2627 | return 1; |
| 2628 | } |
| 2629 | |
| 2630 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 2631 | static enum sigma_cmd_result cmd_sta_set_peap(struct sigma_dut *dut, |
| 2632 | struct sigma_conn *conn, |
| 2633 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2634 | { |
| 2635 | const char *intf = get_param(cmd, "Interface"); |
| 2636 | const char *ifname, *val; |
| 2637 | int id; |
| 2638 | char buf[100]; |
| 2639 | |
| 2640 | if (intf == NULL) |
| 2641 | return -1; |
| 2642 | |
| 2643 | if (strcmp(intf, get_main_ifname()) == 0) |
| 2644 | ifname = get_station_ifname(); |
| 2645 | else |
| 2646 | ifname = intf; |
| 2647 | |
Bala Krishna Bhamidipati | 73d7af0 | 2016-03-24 12:27:56 +0530 | [diff] [blame] | 2648 | id = set_eap_common(dut, conn, ifname, 1, cmd); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2649 | if (id < 0) |
| 2650 | return id; |
| 2651 | |
| 2652 | if (set_network(ifname, id, "eap", "PEAP") < 0) |
| 2653 | return -2; |
| 2654 | |
| 2655 | val = get_param(cmd, "innerEAP"); |
| 2656 | if (val) { |
| 2657 | if (strcasecmp(val, "MSCHAPv2") == 0) { |
| 2658 | if (set_network_quoted(ifname, id, "phase2", |
| 2659 | "auth=MSCHAPV2") < 0) |
| 2660 | return -2; |
| 2661 | } else if (strcasecmp(val, "GTC") == 0) { |
| 2662 | if (set_network_quoted(ifname, id, "phase2", |
| 2663 | "auth=GTC") < 0) |
| 2664 | return -2; |
| 2665 | } else |
| 2666 | return -1; |
| 2667 | } |
| 2668 | |
| 2669 | val = get_param(cmd, "peapVersion"); |
| 2670 | if (val) { |
| 2671 | int ver = atoi(val); |
| 2672 | if (ver < 0 || ver > 1) |
| 2673 | return -1; |
| 2674 | snprintf(buf, sizeof(buf), "peapver=%d", ver); |
| 2675 | if (set_network_quoted(ifname, id, "phase1", buf) < 0) |
| 2676 | return -2; |
| 2677 | } |
| 2678 | |
| 2679 | return 1; |
| 2680 | } |
| 2681 | |
| 2682 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 2683 | static enum sigma_cmd_result cmd_sta_set_eapfast(struct sigma_dut *dut, |
| 2684 | struct sigma_conn *conn, |
| 2685 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2686 | { |
| 2687 | const char *intf = get_param(cmd, "Interface"); |
| 2688 | const char *ifname, *val; |
| 2689 | int id; |
| 2690 | char buf[100]; |
| 2691 | |
| 2692 | if (intf == NULL) |
| 2693 | return -1; |
| 2694 | |
| 2695 | if (strcmp(intf, get_main_ifname()) == 0) |
| 2696 | ifname = get_station_ifname(); |
| 2697 | else |
| 2698 | ifname = intf; |
| 2699 | |
Bala Krishna Bhamidipati | 73d7af0 | 2016-03-24 12:27:56 +0530 | [diff] [blame] | 2700 | id = set_eap_common(dut, conn, ifname, 1, cmd); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2701 | if (id < 0) |
| 2702 | return id; |
| 2703 | |
| 2704 | if (set_network(ifname, id, "eap", "FAST") < 0) |
| 2705 | return -2; |
| 2706 | |
| 2707 | val = get_param(cmd, "innerEAP"); |
| 2708 | if (val) { |
| 2709 | if (strcasecmp(val, "MSCHAPV2") == 0) { |
| 2710 | if (set_network_quoted(ifname, id, "phase2", |
| 2711 | "auth=MSCHAPV2") < 0) |
| 2712 | return -2; |
| 2713 | } else if (strcasecmp(val, "GTC") == 0) { |
| 2714 | if (set_network_quoted(ifname, id, "phase2", |
| 2715 | "auth=GTC") < 0) |
| 2716 | return -2; |
| 2717 | } else |
| 2718 | return -1; |
| 2719 | } |
| 2720 | |
| 2721 | val = get_param(cmd, "validateServer"); |
| 2722 | if (val) { |
| 2723 | /* TODO */ |
| 2724 | sigma_dut_print(dut, DUT_MSG_INFO, "Ignored EAP-FAST " |
| 2725 | "validateServer=%s", val); |
| 2726 | } |
| 2727 | |
| 2728 | val = get_param(cmd, "pacFile"); |
| 2729 | if (val) { |
| 2730 | snprintf(buf, sizeof(buf), "blob://%s", val); |
| 2731 | if (set_network_quoted(ifname, id, "pac_file", buf) < 0) |
| 2732 | return -2; |
| 2733 | } |
| 2734 | |
| 2735 | if (set_network_quoted(ifname, id, "phase1", "fast_provisioning=2") < |
| 2736 | 0) |
| 2737 | return -2; |
| 2738 | |
| 2739 | return 1; |
| 2740 | } |
| 2741 | |
| 2742 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 2743 | static enum sigma_cmd_result cmd_sta_set_eapaka(struct sigma_dut *dut, |
| 2744 | struct sigma_conn *conn, |
| 2745 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2746 | { |
| 2747 | const char *intf = get_param(cmd, "Interface"); |
Purushottam Kushwaha | cdd8cb1 | 2019-10-04 11:33:59 +0530 | [diff] [blame] | 2748 | const char *username = get_param(cmd, "Username"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2749 | const char *ifname; |
| 2750 | int id; |
| 2751 | |
| 2752 | if (intf == NULL) |
| 2753 | return -1; |
| 2754 | |
| 2755 | if (strcmp(intf, get_main_ifname()) == 0) |
| 2756 | ifname = get_station_ifname(); |
| 2757 | else |
| 2758 | ifname = intf; |
| 2759 | |
Bala Krishna Bhamidipati | 73d7af0 | 2016-03-24 12:27:56 +0530 | [diff] [blame] | 2760 | id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2761 | if (id < 0) |
| 2762 | return id; |
| 2763 | |
Purushottam Kushwaha | cdd8cb1 | 2019-10-04 11:33:59 +0530 | [diff] [blame] | 2764 | /* RFC 5448: EAP-AKA' MUST use the leading character "6" (ASCII 36 |
| 2765 | * hexadecimal). |
| 2766 | */ |
| 2767 | if (username && username[0] == '6') { |
| 2768 | if (set_network(ifname, id, "eap", "AKA'") < 0) |
| 2769 | return -2; |
| 2770 | } else if (set_network(ifname, id, "eap", "AKA") < 0) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2771 | return -2; |
Purushottam Kushwaha | cdd8cb1 | 2019-10-04 11:33:59 +0530 | [diff] [blame] | 2772 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2773 | |
| 2774 | return 1; |
| 2775 | } |
| 2776 | |
| 2777 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 2778 | static enum sigma_cmd_result cmd_sta_set_eapakaprime(struct sigma_dut *dut, |
| 2779 | struct sigma_conn *conn, |
| 2780 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2781 | { |
| 2782 | const char *intf = get_param(cmd, "Interface"); |
| 2783 | const char *ifname; |
| 2784 | int id; |
| 2785 | |
| 2786 | if (intf == NULL) |
| 2787 | return -1; |
| 2788 | |
| 2789 | if (strcmp(intf, get_main_ifname()) == 0) |
| 2790 | ifname = get_station_ifname(); |
| 2791 | else |
| 2792 | ifname = intf; |
| 2793 | |
Bala Krishna Bhamidipati | 73d7af0 | 2016-03-24 12:27:56 +0530 | [diff] [blame] | 2794 | id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2795 | if (id < 0) |
| 2796 | return id; |
| 2797 | |
| 2798 | if (set_network(ifname, id, "eap", "AKA'") < 0) |
| 2799 | return -2; |
| 2800 | |
| 2801 | return 1; |
| 2802 | } |
| 2803 | |
| 2804 | |
| 2805 | static int sta_set_open(struct sigma_dut *dut, struct sigma_conn *conn, |
| 2806 | struct sigma_cmd *cmd) |
| 2807 | { |
| 2808 | const char *intf = get_param(cmd, "Interface"); |
Alexei Avshalom Lazar | d596b51 | 2018-12-18 16:00:59 +0200 | [diff] [blame] | 2809 | const char *network_mode = get_param(cmd, "network_mode"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2810 | const char *ifname; |
| 2811 | int id; |
| 2812 | |
| 2813 | if (strcmp(intf, get_main_ifname()) == 0) |
| 2814 | ifname = get_station_ifname(); |
| 2815 | else |
| 2816 | ifname = intf; |
| 2817 | |
| 2818 | id = add_network_common(dut, conn, ifname, cmd); |
| 2819 | if (id < 0) |
| 2820 | return id; |
| 2821 | |
| 2822 | if (set_network(ifname, id, "key_mgmt", "NONE") < 0) |
| 2823 | return -2; |
| 2824 | |
Alexei Avshalom Lazar | d596b51 | 2018-12-18 16:00:59 +0200 | [diff] [blame] | 2825 | if (dut->program == PROGRAM_60GHZ && network_mode && |
| 2826 | strcasecmp(network_mode, "PBSS") == 0 && |
| 2827 | set_network(ifname, id, "pbss", "1") < 0) |
| 2828 | return -2; |
| 2829 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2830 | return 1; |
| 2831 | } |
| 2832 | |
| 2833 | |
Jouni Malinen | 47dcc95 | 2017-10-09 16:43:24 +0300 | [diff] [blame] | 2834 | static int sta_set_owe(struct sigma_dut *dut, struct sigma_conn *conn, |
| 2835 | struct sigma_cmd *cmd) |
| 2836 | { |
| 2837 | const char *intf = get_param(cmd, "Interface"); |
| 2838 | const char *ifname, *val; |
| 2839 | int id; |
| 2840 | |
| 2841 | if (intf == NULL) |
| 2842 | return -1; |
| 2843 | |
| 2844 | if (strcmp(intf, get_main_ifname()) == 0) |
| 2845 | ifname = get_station_ifname(); |
| 2846 | else |
| 2847 | ifname = intf; |
| 2848 | |
| 2849 | id = set_wpa_common(dut, conn, ifname, cmd); |
| 2850 | if (id < 0) |
| 2851 | return id; |
| 2852 | |
| 2853 | if (set_network(ifname, id, "key_mgmt", "OWE") < 0) |
| 2854 | return -2; |
| 2855 | |
| 2856 | val = get_param(cmd, "ECGroupID"); |
Jouni Malinen | fac9cad | 2017-10-10 18:35:55 +0300 | [diff] [blame] | 2857 | if (val && strcmp(val, "0") == 0) { |
| 2858 | if (wpa_command(ifname, |
| 2859 | "VENDOR_ELEM_ADD 13 ff23200000783590fb7440e03d5b3b33911f86affdcc6b4411b707846ac4ff08ddc8831ccd") != 0) { |
| 2860 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 2861 | "Failed to set OWE DH Param element override"); |
| 2862 | return -2; |
| 2863 | } |
| 2864 | } else if (val && set_network(ifname, id, "owe_group", val) < 0) { |
Jouni Malinen | 47dcc95 | 2017-10-09 16:43:24 +0300 | [diff] [blame] | 2865 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 2866 | "Failed to clear owe_group"); |
| 2867 | return -2; |
| 2868 | } |
| 2869 | |
| 2870 | return 1; |
| 2871 | } |
| 2872 | |
| 2873 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 2874 | static enum sigma_cmd_result cmd_sta_set_security(struct sigma_dut *dut, |
| 2875 | struct sigma_conn *conn, |
| 2876 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2877 | { |
| 2878 | const char *type = get_param(cmd, "Type"); |
| 2879 | |
| 2880 | if (type == NULL) { |
| 2881 | send_resp(dut, conn, SIGMA_ERROR, |
| 2882 | "ErrorCode,Missing Type argument"); |
| 2883 | return 0; |
| 2884 | } |
| 2885 | |
| 2886 | if (strcasecmp(type, "OPEN") == 0) |
| 2887 | return sta_set_open(dut, conn, cmd); |
Jouni Malinen | 47dcc95 | 2017-10-09 16:43:24 +0300 | [diff] [blame] | 2888 | if (strcasecmp(type, "OWE") == 0) |
| 2889 | return sta_set_owe(dut, conn, cmd); |
Jouni Malinen | 992a81e | 2017-08-22 13:57:47 +0300 | [diff] [blame] | 2890 | if (strcasecmp(type, "PSK") == 0 || |
Jouni Malinen | 0ab50f4 | 2017-08-31 01:34:59 +0300 | [diff] [blame] | 2891 | strcasecmp(type, "PSK-SAE") == 0 || |
Jouni Malinen | 992a81e | 2017-08-22 13:57:47 +0300 | [diff] [blame] | 2892 | strcasecmp(type, "SAE") == 0) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2893 | return cmd_sta_set_psk(dut, conn, cmd); |
| 2894 | if (strcasecmp(type, "EAPTLS") == 0) |
| 2895 | return cmd_sta_set_eaptls(dut, conn, cmd); |
| 2896 | if (strcasecmp(type, "EAPTTLS") == 0) |
| 2897 | return cmd_sta_set_eapttls(dut, conn, cmd); |
| 2898 | if (strcasecmp(type, "EAPPEAP") == 0) |
| 2899 | return cmd_sta_set_peap(dut, conn, cmd); |
| 2900 | if (strcasecmp(type, "EAPSIM") == 0) |
| 2901 | return cmd_sta_set_eapsim(dut, conn, cmd); |
| 2902 | if (strcasecmp(type, "EAPFAST") == 0) |
| 2903 | return cmd_sta_set_eapfast(dut, conn, cmd); |
| 2904 | if (strcasecmp(type, "EAPAKA") == 0) |
| 2905 | return cmd_sta_set_eapaka(dut, conn, cmd); |
| 2906 | if (strcasecmp(type, "EAPAKAPRIME") == 0) |
| 2907 | return cmd_sta_set_eapakaprime(dut, conn, cmd); |
Amarnath Hullur Subramanyam | 81b11cd | 2018-01-30 19:07:17 -0800 | [diff] [blame] | 2908 | if (strcasecmp(type, "wep") == 0) |
| 2909 | return cmd_sta_set_encryption(dut, conn, cmd); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2910 | |
| 2911 | send_resp(dut, conn, SIGMA_ERROR, |
| 2912 | "ErrorCode,Unsupported Type value"); |
| 2913 | return 0; |
| 2914 | } |
| 2915 | |
| 2916 | |
| 2917 | int ath6kl_client_uapsd(struct sigma_dut *dut, const char *intf, int uapsd) |
| 2918 | { |
| 2919 | #ifdef __linux__ |
| 2920 | /* special handling for ath6kl */ |
| 2921 | char path[128], fname[128], *pos; |
| 2922 | ssize_t res; |
| 2923 | FILE *f; |
| 2924 | |
Jouni Malinen | e39cd56 | 2019-05-29 23:39:56 +0300 | [diff] [blame] | 2925 | res = snprintf(fname, sizeof(fname), "/sys/class/net/%s/phy80211", |
| 2926 | intf); |
| 2927 | if (res < 0 || res >= sizeof(fname)) |
| 2928 | return 0; |
| 2929 | res = readlink(fname, path, sizeof(path)); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2930 | if (res < 0) |
| 2931 | return 0; /* not ath6kl */ |
| 2932 | |
| 2933 | if (res >= (int) sizeof(path)) |
| 2934 | res = sizeof(path) - 1; |
| 2935 | path[res] = '\0'; |
| 2936 | pos = strrchr(path, '/'); |
| 2937 | if (pos == NULL) |
| 2938 | pos = path; |
| 2939 | else |
| 2940 | pos++; |
| 2941 | snprintf(fname, sizeof(fname), |
| 2942 | "/sys/kernel/debug/ieee80211/%s/ath6kl/" |
| 2943 | "create_qos", pos); |
| 2944 | if (!file_exists(fname)) |
| 2945 | return 0; /* not ath6kl */ |
| 2946 | |
| 2947 | if (uapsd) { |
| 2948 | f = fopen(fname, "w"); |
| 2949 | if (f == NULL) |
| 2950 | return -1; |
| 2951 | |
| 2952 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl create_qos"); |
| 2953 | fprintf(f, "4 2 2 1 2 9999999 9999999 9999999 7777777 0 4 " |
| 2954 | "45000 200 56789000 56789000 5678900 0 0 9999999 " |
| 2955 | "20000 0\n"); |
| 2956 | fclose(f); |
| 2957 | } else { |
| 2958 | snprintf(fname, sizeof(fname), |
| 2959 | "/sys/kernel/debug/ieee80211/%s/ath6kl/" |
| 2960 | "delete_qos", pos); |
| 2961 | |
| 2962 | f = fopen(fname, "w"); |
| 2963 | if (f == NULL) |
| 2964 | return -1; |
| 2965 | |
| 2966 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl delete_qos"); |
| 2967 | fprintf(f, "2 4\n"); |
| 2968 | fclose(f); |
| 2969 | } |
| 2970 | #endif /* __linux__ */ |
| 2971 | |
| 2972 | return 0; |
| 2973 | } |
| 2974 | |
| 2975 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 2976 | static enum sigma_cmd_result cmd_sta_set_uapsd(struct sigma_dut *dut, |
| 2977 | struct sigma_conn *conn, |
| 2978 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2979 | { |
| 2980 | const char *intf = get_param(cmd, "Interface"); |
| 2981 | /* const char *ssid = get_param(cmd, "ssid"); */ |
| 2982 | const char *val; |
| 2983 | int max_sp_len = 4; |
| 2984 | int ac_be = 1, ac_bk = 1, ac_vi = 1, ac_vo = 1; |
| 2985 | char buf[100]; |
| 2986 | int ret1, ret2; |
| 2987 | |
| 2988 | val = get_param(cmd, "maxSPLength"); |
| 2989 | if (val) { |
| 2990 | max_sp_len = atoi(val); |
| 2991 | if (max_sp_len != 0 && max_sp_len != 1 && max_sp_len != 2 && |
| 2992 | max_sp_len != 4) |
| 2993 | return -1; |
| 2994 | } |
| 2995 | |
| 2996 | val = get_param(cmd, "acBE"); |
| 2997 | if (val) |
| 2998 | ac_be = atoi(val); |
| 2999 | |
| 3000 | val = get_param(cmd, "acBK"); |
| 3001 | if (val) |
| 3002 | ac_bk = atoi(val); |
| 3003 | |
| 3004 | val = get_param(cmd, "acVI"); |
| 3005 | if (val) |
| 3006 | ac_vi = atoi(val); |
| 3007 | |
| 3008 | val = get_param(cmd, "acVO"); |
| 3009 | if (val) |
| 3010 | ac_vo = atoi(val); |
| 3011 | |
| 3012 | dut->client_uapsd = ac_be || ac_bk || ac_vi || ac_vo; |
| 3013 | |
| 3014 | snprintf(buf, sizeof(buf), "P2P_SET client_apsd %d,%d,%d,%d;%d", |
| 3015 | ac_be, ac_bk, ac_vi, ac_vo, max_sp_len); |
| 3016 | ret1 = wpa_command(intf, buf); |
| 3017 | |
| 3018 | snprintf(buf, sizeof(buf), "SET uapsd %d,%d,%d,%d;%d", |
| 3019 | ac_be, ac_bk, ac_vi, ac_vo, max_sp_len); |
| 3020 | ret2 = wpa_command(intf, buf); |
| 3021 | |
| 3022 | if (ret1 && ret2) { |
| 3023 | sigma_dut_print(dut, DUT_MSG_INFO, "Failed to set client mode " |
| 3024 | "UAPSD parameters."); |
| 3025 | return -2; |
| 3026 | } |
| 3027 | |
| 3028 | if (ath6kl_client_uapsd(dut, intf, dut->client_uapsd) < 0) { |
| 3029 | send_resp(dut, conn, SIGMA_ERROR, |
| 3030 | "ErrorCode,Failed to set ath6kl QoS parameters"); |
| 3031 | return 0; |
| 3032 | } |
| 3033 | |
| 3034 | return 1; |
| 3035 | } |
| 3036 | |
| 3037 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 3038 | static enum sigma_cmd_result cmd_sta_set_wmm(struct sigma_dut *dut, |
| 3039 | struct sigma_conn *conn, |
| 3040 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3041 | { |
| 3042 | char buf[1000]; |
| 3043 | const char *intf = get_param(cmd, "Interface"); |
| 3044 | const char *grp = get_param(cmd, "Group"); |
| 3045 | const char *act = get_param(cmd, "Action"); |
| 3046 | const char *tid = get_param(cmd, "Tid"); |
| 3047 | const char *dir = get_param(cmd, "Direction"); |
| 3048 | const char *psb = get_param(cmd, "Psb"); |
| 3049 | const char *up = get_param(cmd, "Up"); |
| 3050 | const char *fixed = get_param(cmd, "Fixed"); |
| 3051 | const char *size = get_param(cmd, "Size"); |
| 3052 | const char *msize = get_param(cmd, "Maxsize"); |
| 3053 | const char *minsi = get_param(cmd, "Min_srvc_intrvl"); |
| 3054 | const char *maxsi = get_param(cmd, "Max_srvc_intrvl"); |
| 3055 | const char *inact = get_param(cmd, "Inactivity"); |
| 3056 | const char *sus = get_param(cmd, "Suspension"); |
| 3057 | const char *mindr = get_param(cmd, "Mindatarate"); |
| 3058 | const char *meandr = get_param(cmd, "Meandatarate"); |
| 3059 | const char *peakdr = get_param(cmd, "Peakdatarate"); |
| 3060 | const char *phyrate = get_param(cmd, "Phyrate"); |
| 3061 | const char *burstsize = get_param(cmd, "Burstsize"); |
| 3062 | const char *sba = get_param(cmd, "Sba"); |
| 3063 | int direction; |
| 3064 | int handle; |
Peng Xu | 9331962 | 2017-10-04 17:58:16 -0700 | [diff] [blame] | 3065 | float sba_fv = 0; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3066 | int fixed_int; |
| 3067 | int psb_ts; |
| 3068 | |
| 3069 | if (intf == NULL || grp == NULL || act == NULL ) |
| 3070 | return -1; |
| 3071 | |
| 3072 | if (strcasecmp(act, "addts") == 0) { |
| 3073 | if (tid == NULL || dir == NULL || psb == NULL || |
| 3074 | up == NULL || fixed == NULL || size == NULL) |
| 3075 | return -1; |
| 3076 | |
| 3077 | /* |
| 3078 | * Note: Sigma CAPI spec lists uplink, downlink, and bidi as the |
| 3079 | * possible values, but WMM-AC and V-E test scripts use "UP, |
| 3080 | * "DOWN", and "BIDI". |
| 3081 | */ |
| 3082 | if (strcasecmp(dir, "uplink") == 0 || |
| 3083 | strcasecmp(dir, "up") == 0) { |
| 3084 | direction = 0; |
| 3085 | } else if (strcasecmp(dir, "downlink") == 0 || |
| 3086 | strcasecmp(dir, "down") == 0) { |
| 3087 | direction = 1; |
| 3088 | } else if (strcasecmp(dir, "bidi") == 0) { |
| 3089 | direction = 2; |
| 3090 | } else { |
| 3091 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3092 | "Direction %s not supported", dir); |
| 3093 | return -1; |
| 3094 | } |
| 3095 | |
| 3096 | if (strcasecmp(psb, "legacy") == 0) { |
| 3097 | psb_ts = 0; |
| 3098 | } else if (strcasecmp(psb, "uapsd") == 0) { |
| 3099 | psb_ts = 1; |
| 3100 | } else { |
| 3101 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3102 | "PSB %s not supported", psb); |
| 3103 | return -1; |
| 3104 | } |
| 3105 | |
| 3106 | if (atoi(tid) < 0 || atoi(tid) > 7) { |
| 3107 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3108 | "TID %s not supported", tid); |
| 3109 | return -1; |
| 3110 | } |
| 3111 | |
| 3112 | if (strcasecmp(fixed, "true") == 0) { |
| 3113 | fixed_int = 1; |
| 3114 | } else { |
| 3115 | fixed_int = 0; |
| 3116 | } |
| 3117 | |
Peng Xu | 9331962 | 2017-10-04 17:58:16 -0700 | [diff] [blame] | 3118 | if (sba) |
| 3119 | sba_fv = atof(sba); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3120 | |
| 3121 | dut->dialog_token++; |
| 3122 | handle = 7000 + dut->dialog_token; |
| 3123 | |
| 3124 | /* |
| 3125 | * size: convert to hex |
| 3126 | * maxsi: convert to hex |
| 3127 | * mindr: convert to hex |
| 3128 | * meandr: convert to hex |
| 3129 | * peakdr: convert to hex |
| 3130 | * burstsize: convert to hex |
| 3131 | * phyrate: convert to hex |
| 3132 | * sba: convert to hex with modification |
| 3133 | * minsi: convert to integer |
| 3134 | * sus: convert to integer |
| 3135 | * inact: convert to integer |
| 3136 | * maxsi: convert to integer |
| 3137 | */ |
| 3138 | |
| 3139 | /* |
| 3140 | * The Nominal MSDU Size field is 2 octets long and contains an |
| 3141 | * unsigned integer that specifies the nominal size, in octets, |
| 3142 | * of MSDUs belonging to the traffic under this traffic |
| 3143 | * specification and is defined in Figure 16. If the Fixed |
| 3144 | * subfield is set to 1, then the size of the MSDU is fixed and |
| 3145 | * is indicated by the Size Subfield. If the Fixed subfield is |
| 3146 | * set to 0, then the size of the MSDU might not be fixed and |
| 3147 | * the Size indicates the nominal MSDU size. |
| 3148 | * |
| 3149 | * The Surplus Bandwidth Allowance Factor field is 2 octets long |
| 3150 | * and specifies the excess allocation of time (and bandwidth) |
| 3151 | * over and above the stated rates required to transport an MSDU |
| 3152 | * belonging to the traffic in this TSPEC. This field is |
| 3153 | * represented as an unsigned binary number with an implicit |
| 3154 | * binary point after the leftmost 3 bits. For example, an SBA |
| 3155 | * of 1.75 is represented as 0x3800. This field is included to |
| 3156 | * account for retransmissions. As such, the value of this field |
| 3157 | * must be greater than unity. |
| 3158 | */ |
| 3159 | |
| 3160 | snprintf(buf, sizeof(buf), |
| 3161 | "iwpriv %s addTspec %d %s %d %d %s 0x%X" |
| 3162 | " 0x%X 0x%X 0x%X" |
| 3163 | " 0x%X 0x%X 0x%X" |
| 3164 | " 0x%X %d %d %d %d" |
| 3165 | " %d %d", |
| 3166 | intf, handle, tid, direction, psb_ts, up, |
| 3167 | (unsigned int) ((fixed_int << 15) | atoi(size)), |
| 3168 | msize ? atoi(msize) : 0, |
| 3169 | mindr ? atoi(mindr) : 0, |
| 3170 | meandr ? atoi(meandr) : 0, |
| 3171 | peakdr ? atoi(peakdr) : 0, |
| 3172 | burstsize ? atoi(burstsize) : 0, |
| 3173 | phyrate ? atoi(phyrate) : 0, |
| 3174 | sba ? ((unsigned int) (((int) sba_fv << 13) | |
| 3175 | (int)((sba_fv - (int) sba_fv) * |
| 3176 | 8192))) : 0, |
| 3177 | minsi ? atoi(minsi) : 0, |
| 3178 | sus ? atoi(sus) : 0, |
| 3179 | 0, 0, |
| 3180 | inact ? atoi(inact) : 0, |
| 3181 | maxsi ? atoi(maxsi) : 0); |
| 3182 | |
| 3183 | if (system(buf) != 0) { |
| 3184 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3185 | "iwpriv addtspec request failed"); |
| 3186 | send_resp(dut, conn, SIGMA_ERROR, |
| 3187 | "errorCode,Failed to execute addTspec command"); |
| 3188 | return 0; |
| 3189 | } |
| 3190 | |
| 3191 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 3192 | "iwpriv addtspec request send"); |
| 3193 | |
| 3194 | /* Mapping handle to a TID */ |
| 3195 | dut->tid_to_handle[atoi(tid)] = handle; |
| 3196 | } else if (strcasecmp(act, "delts") == 0) { |
| 3197 | if (tid == NULL) |
| 3198 | return -1; |
| 3199 | |
| 3200 | if (atoi(tid) < 0 || atoi(tid) > 7) { |
| 3201 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3202 | "TID %s not supported", tid); |
| 3203 | send_resp(dut, conn, SIGMA_ERROR, |
| 3204 | "errorCode,Unsupported TID"); |
| 3205 | return 0; |
| 3206 | } |
| 3207 | |
| 3208 | handle = dut->tid_to_handle[atoi(tid)]; |
| 3209 | |
| 3210 | if (handle < 7000 || handle > 7255) { |
| 3211 | /* Invalid handle ie no mapping for that TID */ |
| 3212 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3213 | "handle-> %d not found", handle); |
| 3214 | } |
| 3215 | |
| 3216 | snprintf(buf, sizeof(buf), "iwpriv %s delTspec %d", |
| 3217 | intf, handle); |
| 3218 | |
| 3219 | if (system(buf) != 0) { |
| 3220 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3221 | "iwpriv deltspec request failed"); |
| 3222 | send_resp(dut, conn, SIGMA_ERROR, |
| 3223 | "errorCode,Failed to execute delTspec command"); |
| 3224 | return 0; |
| 3225 | } |
| 3226 | |
| 3227 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 3228 | "iwpriv deltspec request send"); |
| 3229 | |
| 3230 | dut->tid_to_handle[atoi(tid)] = 0; |
| 3231 | } else { |
| 3232 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3233 | "Action type %s not supported", act); |
| 3234 | send_resp(dut, conn, SIGMA_ERROR, |
| 3235 | "errorCode,Unsupported Action"); |
| 3236 | return 0; |
| 3237 | } |
| 3238 | |
| 3239 | return 1; |
| 3240 | } |
| 3241 | |
| 3242 | |
vamsi krishna | 52e16f9 | 2017-08-29 12:37:34 +0530 | [diff] [blame] | 3243 | static int find_network(struct sigma_dut *dut, const char *ssid) |
| 3244 | { |
| 3245 | char list[4096]; |
| 3246 | char *pos; |
| 3247 | |
| 3248 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 3249 | "Search for profile based on SSID: '%s'", ssid); |
| 3250 | if (wpa_command_resp(get_station_ifname(), "LIST_NETWORKS", |
| 3251 | list, sizeof(list)) < 0) |
| 3252 | return -1; |
| 3253 | pos = strstr(list, ssid); |
| 3254 | if (!pos || pos == list || pos[-1] != '\t' || pos[strlen(ssid)] != '\t') |
| 3255 | return -1; |
| 3256 | |
| 3257 | while (pos > list && pos[-1] != '\n') |
| 3258 | pos--; |
| 3259 | dut->infra_network_id = atoi(pos); |
| 3260 | snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid); |
| 3261 | return 0; |
| 3262 | } |
| 3263 | |
| 3264 | |
Sunil Dutt | 4459508 | 2018-02-12 19:41:45 +0530 | [diff] [blame] | 3265 | #ifdef NL80211_SUPPORT |
| 3266 | static int sta_config_rsnie(struct sigma_dut *dut, int val) |
| 3267 | { |
| 3268 | struct nl_msg *msg; |
| 3269 | int ret; |
| 3270 | struct nlattr *params; |
| 3271 | int ifindex; |
| 3272 | |
| 3273 | ifindex = if_nametoindex("wlan0"); |
| 3274 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 3275 | NL80211_CMD_VENDOR)) || |
| 3276 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 3277 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 3278 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 3279 | QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) || |
| 3280 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 3281 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE, val)) { |
| 3282 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3283 | "%s: err in adding vendor_cmd and vendor_data", |
| 3284 | __func__); |
| 3285 | nlmsg_free(msg); |
| 3286 | return -1; |
| 3287 | } |
| 3288 | nla_nest_end(msg, params); |
| 3289 | |
| 3290 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 3291 | if (ret) { |
| 3292 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 3293 | "%s: err in send_and_recv_msgs, ret=%d", |
| 3294 | __func__, ret); |
| 3295 | return ret; |
| 3296 | } |
| 3297 | |
| 3298 | return 0; |
| 3299 | } |
| 3300 | #endif /* NL80211_SUPPORT */ |
| 3301 | |
| 3302 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 3303 | static enum sigma_cmd_result cmd_sta_associate(struct sigma_dut *dut, |
| 3304 | struct sigma_conn *conn, |
| 3305 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3306 | { |
| 3307 | /* const char *intf = get_param(cmd, "Interface"); */ |
| 3308 | const char *ssid = get_param(cmd, "ssid"); |
| 3309 | const char *wps_param = get_param(cmd, "WPS"); |
| 3310 | const char *bssid = get_param(cmd, "bssid"); |
Jouni Malinen | 46a19b6 | 2017-06-23 14:31:27 +0300 | [diff] [blame] | 3311 | const char *chan = get_param(cmd, "channel"); |
Alexei Avshalom Lazar | d596b51 | 2018-12-18 16:00:59 +0200 | [diff] [blame] | 3312 | const char *network_mode = get_param(cmd, "network_mode"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3313 | int wps = 0; |
Jouni Malinen | 3c367e8 | 2017-06-23 17:01:47 +0300 | [diff] [blame] | 3314 | char buf[1000], extra[50]; |
Jouni Malinen | 134fe3c | 2019-06-12 04:16:49 +0300 | [diff] [blame] | 3315 | int e; |
| 3316 | enum sigma_cmd_result ret = SUCCESS_SEND_STATUS; |
| 3317 | struct wpa_ctrl *ctrl = NULL; |
| 3318 | int num_network_not_found = 0; |
| 3319 | int num_disconnected = 0; |
| 3320 | int tod = -1; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3321 | |
| 3322 | if (ssid == NULL) |
| 3323 | return -1; |
| 3324 | |
Jouni Malinen | 37d5c69 | 2019-08-19 16:56:55 +0300 | [diff] [blame] | 3325 | dut->server_cert_tod = 0; |
| 3326 | |
Jouni Malinen | 3c367e8 | 2017-06-23 17:01:47 +0300 | [diff] [blame] | 3327 | if (dut->rsne_override) { |
Sunil Dutt | 4459508 | 2018-02-12 19:41:45 +0530 | [diff] [blame] | 3328 | #ifdef NL80211_SUPPORT |
| 3329 | if (get_driver_type() == DRIVER_WCN) { |
| 3330 | sta_config_rsnie(dut, 1); |
| 3331 | dut->config_rsnie = 1; |
| 3332 | } |
| 3333 | #endif /* NL80211_SUPPORT */ |
Jouni Malinen | 3c367e8 | 2017-06-23 17:01:47 +0300 | [diff] [blame] | 3334 | snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s", |
| 3335 | dut->rsne_override); |
| 3336 | if (wpa_command(get_station_ifname(), buf) < 0) { |
| 3337 | send_resp(dut, conn, SIGMA_ERROR, |
| 3338 | "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override"); |
| 3339 | return 0; |
| 3340 | } |
| 3341 | } |
| 3342 | |
Jouni Malinen | 6814313 | 2017-09-02 02:34:08 +0300 | [diff] [blame] | 3343 | if (dut->sae_commit_override) { |
| 3344 | snprintf(buf, sizeof(buf), "SET sae_commit_override %s", |
| 3345 | dut->sae_commit_override); |
| 3346 | if (wpa_command(get_station_ifname(), buf) < 0) { |
| 3347 | send_resp(dut, conn, SIGMA_ERROR, |
| 3348 | "ErrorCode,Failed to set SAE commit override"); |
| 3349 | return 0; |
| 3350 | } |
| 3351 | } |
Ankita Bajaj | 1bde794 | 2018-01-09 19:15:01 +0530 | [diff] [blame] | 3352 | #ifdef ANDROID |
| 3353 | if (dut->fils_hlp) |
| 3354 | process_fils_hlp(dut); |
| 3355 | #endif /* ANDROID */ |
Jouni Malinen | 6814313 | 2017-09-02 02:34:08 +0300 | [diff] [blame] | 3356 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3357 | if (wps_param && |
| 3358 | (strcmp(wps_param, "1") == 0 || strcasecmp(wps_param, "On") == 0)) |
| 3359 | wps = 1; |
| 3360 | |
| 3361 | if (wps) { |
Alexei Avshalom Lazar | d596b51 | 2018-12-18 16:00:59 +0200 | [diff] [blame] | 3362 | if (dut->program == PROGRAM_60GHZ && network_mode && |
| 3363 | strcasecmp(network_mode, "PBSS") == 0 && |
| 3364 | set_network(get_station_ifname(), dut->infra_network_id, |
| 3365 | "pbss", "1") < 0) |
| 3366 | return -2; |
| 3367 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3368 | if (dut->wps_method == WFA_CS_WPS_NOT_READY) { |
| 3369 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,WPS " |
| 3370 | "parameters not yet set"); |
| 3371 | return 0; |
| 3372 | } |
| 3373 | if (dut->wps_method == WFA_CS_WPS_PBC) { |
| 3374 | if (wpa_command(get_station_ifname(), "WPS_PBC") < 0) |
| 3375 | return -2; |
| 3376 | } else { |
| 3377 | snprintf(buf, sizeof(buf), "WPS_PIN any %s", |
| 3378 | dut->wps_pin); |
| 3379 | if (wpa_command(get_station_ifname(), buf) < 0) |
| 3380 | return -2; |
| 3381 | } |
| 3382 | } else { |
vamsi krishna | 52e16f9 | 2017-08-29 12:37:34 +0530 | [diff] [blame] | 3383 | if (strcmp(ssid, dut->infra_ssid) == 0) { |
| 3384 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 3385 | "sta_associate for the most recently added network"); |
| 3386 | } else if (find_network(dut, ssid) < 0) { |
| 3387 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 3388 | "sta_associate for a previously stored network profile"); |
| 3389 | send_resp(dut, conn, SIGMA_ERROR, |
| 3390 | "ErrorCode,Profile not found"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3391 | return 0; |
| 3392 | } |
| 3393 | |
| 3394 | if (bssid && |
| 3395 | set_network(get_station_ifname(), dut->infra_network_id, |
| 3396 | "bssid", bssid) < 0) { |
| 3397 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode," |
| 3398 | "Invalid bssid argument"); |
| 3399 | return 0; |
| 3400 | } |
| 3401 | |
Jouni Malinen | 134fe3c | 2019-06-12 04:16:49 +0300 | [diff] [blame] | 3402 | if (dut->program == PROGRAM_WPA3 && |
| 3403 | dut->sta_associate_wait_connect) { |
| 3404 | ctrl = open_wpa_mon(get_station_ifname()); |
| 3405 | if (!ctrl) |
| 3406 | return ERROR_SEND_STATUS; |
| 3407 | } |
| 3408 | |
Jouni Malinen | 46a19b6 | 2017-06-23 14:31:27 +0300 | [diff] [blame] | 3409 | extra[0] = '\0'; |
| 3410 | if (chan) |
| 3411 | snprintf(extra, sizeof(extra), " freq=%u", |
Alexei Avshalom Lazar | 093569f | 2018-11-13 14:08:17 +0200 | [diff] [blame] | 3412 | channel_to_freq(dut, atoi(chan))); |
Jouni Malinen | 46a19b6 | 2017-06-23 14:31:27 +0300 | [diff] [blame] | 3413 | snprintf(buf, sizeof(buf), "SELECT_NETWORK %d%s", |
| 3414 | dut->infra_network_id, extra); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3415 | if (wpa_command(get_station_ifname(), buf) < 0) { |
| 3416 | sigma_dut_print(dut, DUT_MSG_INFO, "Failed to select " |
| 3417 | "network id %d on %s", |
| 3418 | dut->infra_network_id, |
| 3419 | get_station_ifname()); |
Jouni Malinen | 134fe3c | 2019-06-12 04:16:49 +0300 | [diff] [blame] | 3420 | ret = ERROR_SEND_STATUS; |
| 3421 | goto done; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3422 | } |
| 3423 | } |
| 3424 | |
Jouni Malinen | 134fe3c | 2019-06-12 04:16:49 +0300 | [diff] [blame] | 3425 | if (!ctrl) |
| 3426 | return SUCCESS_SEND_STATUS; |
| 3427 | |
| 3428 | /* Wait for connection result to be able to store server certificate |
| 3429 | * hash for trust root override testing |
| 3430 | * (dev_exec_action,ServerCertTrust). */ |
| 3431 | |
| 3432 | for (e = 0; e < 20; e++) { |
| 3433 | const char *events[] = { |
| 3434 | "CTRL-EVENT-EAP-PEER-CERT", |
| 3435 | "CTRL-EVENT-EAP-TLS-CERT-ERROR", |
| 3436 | "CTRL-EVENT-DISCONNECTED", |
| 3437 | "CTRL-EVENT-CONNECTED", |
| 3438 | "CTRL-EVENT-NETWORK-NOT-FOUND", |
| 3439 | NULL |
| 3440 | }; |
| 3441 | char buf[1024]; |
| 3442 | int res; |
| 3443 | |
| 3444 | res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf)); |
| 3445 | if (res < 0) { |
| 3446 | send_resp(dut, conn, SIGMA_ERROR, |
| 3447 | "ErrorCode,Association did not complete"); |
| 3448 | ret = STATUS_SENT_ERROR; |
| 3449 | break; |
| 3450 | } |
| 3451 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Connection event: %s", |
| 3452 | buf); |
| 3453 | |
| 3454 | if (strstr(buf, "CTRL-EVENT-EAP-PEER-CERT") && |
| 3455 | strstr(buf, " depth=0")) { |
| 3456 | char *pos = strstr(buf, " hash="); |
| 3457 | |
| 3458 | if (pos) { |
| 3459 | char *end; |
| 3460 | |
Jouni Malinen | 34b19cb | 2019-08-16 16:37:17 +0300 | [diff] [blame] | 3461 | if (strstr(buf, " tod=1")) |
| 3462 | tod = 1; |
| 3463 | else if (strstr(buf, " tod=2")) |
| 3464 | tod = 2; |
| 3465 | else |
| 3466 | tod = 0; |
Jouni Malinen | 134fe3c | 2019-06-12 04:16:49 +0300 | [diff] [blame] | 3467 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 3468 | "Server certificate TOD policy: %d", |
| 3469 | tod); |
Jouni Malinen | 37d5c69 | 2019-08-19 16:56:55 +0300 | [diff] [blame] | 3470 | dut->server_cert_tod = tod; |
Jouni Malinen | 134fe3c | 2019-06-12 04:16:49 +0300 | [diff] [blame] | 3471 | |
| 3472 | pos += 6; |
| 3473 | end = strchr(pos, ' '); |
| 3474 | if (end) |
| 3475 | *end = '\0'; |
| 3476 | strlcpy(dut->server_cert_hash, pos, |
| 3477 | sizeof(dut->server_cert_hash)); |
| 3478 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 3479 | "Server certificate hash: %s", |
| 3480 | dut->server_cert_hash); |
| 3481 | } |
| 3482 | } |
| 3483 | |
| 3484 | if (strstr(buf, "CTRL-EVENT-EAP-TLS-CERT-ERROR")) { |
| 3485 | send_resp(dut, conn, SIGMA_COMPLETE, |
| 3486 | "Result,TLS server certificate validation failed"); |
| 3487 | ret = STATUS_SENT_ERROR; |
| 3488 | break; |
| 3489 | } |
| 3490 | |
| 3491 | if (strstr(buf, "CTRL-EVENT-NETWORK-NOT-FOUND")) { |
| 3492 | num_network_not_found++; |
| 3493 | |
| 3494 | if (num_network_not_found > 2) { |
| 3495 | send_resp(dut, conn, SIGMA_COMPLETE, |
| 3496 | "Result,Network not found"); |
| 3497 | ret = STATUS_SENT_ERROR; |
| 3498 | break; |
| 3499 | } |
| 3500 | } |
| 3501 | |
| 3502 | if (strstr(buf, "CTRL-EVENT-DISCONNECTED")) { |
| 3503 | num_disconnected++; |
| 3504 | |
| 3505 | if (num_disconnected > 2) { |
| 3506 | send_resp(dut, conn, SIGMA_COMPLETE, |
| 3507 | "Result,Connection failed"); |
| 3508 | ret = STATUS_SENT_ERROR; |
| 3509 | break; |
| 3510 | } |
| 3511 | } |
| 3512 | |
| 3513 | if (strstr(buf, "CTRL-EVENT-CONNECTED")) { |
| 3514 | if (tod >= 0) { |
| 3515 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 3516 | "Network profile TOD policy update: %d -> %d", |
| 3517 | dut->sta_tod_policy, tod); |
| 3518 | dut->sta_tod_policy = tod; |
| 3519 | } |
| 3520 | break; |
| 3521 | } |
| 3522 | } |
| 3523 | done: |
| 3524 | if (ctrl) { |
| 3525 | wpa_ctrl_detach(ctrl); |
| 3526 | wpa_ctrl_close(ctrl); |
| 3527 | } |
| 3528 | return ret; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3529 | } |
| 3530 | |
| 3531 | |
| 3532 | static int run_hs20_osu(struct sigma_dut *dut, const char *params) |
| 3533 | { |
| 3534 | char buf[500], cmd[200]; |
| 3535 | int res; |
| 3536 | |
| 3537 | /* Use hs20-osu-client file at the current dir, if found; otherwise use |
| 3538 | * default path */ |
| 3539 | res = snprintf(cmd, sizeof(cmd), |
| 3540 | "%s -w \"%s\" -r hs20-osu-client.res %s%s -dddKt -f Logs/hs20-osu-client.txt", |
| 3541 | file_exists("./hs20-osu-client") ? |
| 3542 | "./hs20-osu-client" : "hs20-osu-client", |
| 3543 | sigma_wpas_ctrl, |
| 3544 | dut->summary_log ? "-s " : "", |
| 3545 | dut->summary_log ? dut->summary_log : ""); |
| 3546 | if (res < 0 || res >= (int) sizeof(cmd)) |
| 3547 | return -1; |
| 3548 | |
| 3549 | res = snprintf(buf, sizeof(buf), "%s %s", cmd, params); |
| 3550 | if (res < 0 || res >= (int) sizeof(buf)) |
| 3551 | return -1; |
| 3552 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 3553 | |
| 3554 | if (system(buf) != 0) { |
| 3555 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run: %s", buf); |
| 3556 | return -1; |
| 3557 | } |
| 3558 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 3559 | "Completed hs20-osu-client operation"); |
| 3560 | |
| 3561 | return 0; |
| 3562 | } |
| 3563 | |
| 3564 | |
| 3565 | static int download_ppsmo(struct sigma_dut *dut, |
| 3566 | struct sigma_conn *conn, |
| 3567 | const char *intf, |
| 3568 | struct sigma_cmd *cmd) |
| 3569 | { |
| 3570 | const char *name, *path, *val; |
| 3571 | char url[500], buf[600], fbuf[100]; |
| 3572 | char *fqdn = NULL; |
| 3573 | |
| 3574 | name = get_param(cmd, "FileName"); |
| 3575 | path = get_param(cmd, "FilePath"); |
| 3576 | if (name == NULL || path == NULL) |
| 3577 | return -1; |
| 3578 | |
| 3579 | if (strcasecmp(path, "VendorSpecific") == 0) { |
| 3580 | snprintf(url, sizeof(url), "PPS/%s", name); |
| 3581 | sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured PPS MO " |
| 3582 | "from the device (%s)", url); |
| 3583 | if (!file_exists(url)) { |
| 3584 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested " |
| 3585 | "PPS MO file does not exist"); |
| 3586 | return 0; |
| 3587 | } |
| 3588 | snprintf(buf, sizeof(buf), "cp %s pps-tnds.xml", url); |
| 3589 | if (system(buf) != 0) { |
| 3590 | send_resp(dut, conn, SIGMA_ERROR, |
| 3591 | "errorCode,Failed to copy PPS MO"); |
| 3592 | return 0; |
| 3593 | } |
| 3594 | } else if (strncasecmp(path, "http:", 5) != 0 && |
| 3595 | strncasecmp(path, "https:", 6) != 0) { |
| 3596 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode," |
| 3597 | "Unsupported FilePath value"); |
| 3598 | return 0; |
| 3599 | } else { |
| 3600 | snprintf(url, sizeof(url), "%s/%s", path, name); |
| 3601 | sigma_dut_print(dut, DUT_MSG_INFO, "Downloading PPS MO from %s", |
| 3602 | url); |
| 3603 | snprintf(buf, sizeof(buf), "wget -T 10 -t 3 -O pps-tnds.xml '%s'", url); |
| 3604 | remove("pps-tnds.xml"); |
| 3605 | if (system(buf) != 0) { |
| 3606 | send_resp(dut, conn, SIGMA_ERROR, |
| 3607 | "errorCode,Failed to download PPS MO"); |
| 3608 | return 0; |
| 3609 | } |
| 3610 | } |
| 3611 | |
| 3612 | if (run_hs20_osu(dut, "from_tnds pps-tnds.xml pps.xml") < 0) { |
| 3613 | send_resp(dut, conn, SIGMA_ERROR, |
| 3614 | "errorCode,Failed to parse downloaded PPSMO"); |
| 3615 | return 0; |
| 3616 | } |
| 3617 | unlink("pps-tnds.xml"); |
| 3618 | |
| 3619 | val = get_param(cmd, "managementTreeURI"); |
| 3620 | if (val) { |
| 3621 | const char *pos, *end; |
| 3622 | sigma_dut_print(dut, DUT_MSG_DEBUG, "managementTreeURI: %s", |
| 3623 | val); |
| 3624 | if (strncmp(val, "./Wi-Fi/", 8) != 0) { |
| 3625 | send_resp(dut, conn, SIGMA_ERROR, |
| 3626 | "errorCode,Invalid managementTreeURI prefix"); |
| 3627 | return 0; |
| 3628 | } |
| 3629 | pos = val + 8; |
| 3630 | end = strchr(pos, '/'); |
| 3631 | if (end == NULL || |
| 3632 | strcmp(end, "/PerProviderSubscription") != 0) { |
| 3633 | send_resp(dut, conn, SIGMA_ERROR, |
| 3634 | "errorCode,Invalid managementTreeURI postfix"); |
| 3635 | return 0; |
| 3636 | } |
| 3637 | if (end - pos >= (int) sizeof(fbuf)) { |
| 3638 | send_resp(dut, conn, SIGMA_ERROR, |
| 3639 | "errorCode,Too long FQDN in managementTreeURI"); |
| 3640 | return 0; |
| 3641 | } |
| 3642 | memcpy(fbuf, pos, end - pos); |
| 3643 | fbuf[end - pos] = '\0'; |
| 3644 | fqdn = fbuf; |
| 3645 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 3646 | "FQDN from managementTreeURI: %s", fqdn); |
| 3647 | } else if (run_hs20_osu(dut, "get_fqdn pps.xml") == 0) { |
| 3648 | FILE *f = fopen("pps-fqdn", "r"); |
| 3649 | if (f) { |
| 3650 | if (fgets(fbuf, sizeof(fbuf), f)) { |
| 3651 | fbuf[sizeof(fbuf) - 1] = '\0'; |
| 3652 | fqdn = fbuf; |
| 3653 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 3654 | "Use FQDN %s", fqdn); |
| 3655 | } |
| 3656 | fclose(f); |
| 3657 | } |
| 3658 | } |
| 3659 | |
| 3660 | if (fqdn == NULL) { |
| 3661 | send_resp(dut, conn, SIGMA_ERROR, |
| 3662 | "errorCode,No FQDN specified"); |
| 3663 | return 0; |
| 3664 | } |
| 3665 | |
| 3666 | mkdir("SP", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); |
| 3667 | snprintf(buf, sizeof(buf), "SP/%s", fqdn); |
| 3668 | mkdir(buf, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); |
| 3669 | |
| 3670 | snprintf(buf, sizeof(buf), "SP/%s/pps.xml", fqdn); |
| 3671 | if (rename("pps.xml", buf) < 0) { |
| 3672 | send_resp(dut, conn, SIGMA_ERROR, |
| 3673 | "errorCode,Could not move PPS MO"); |
| 3674 | return 0; |
| 3675 | } |
| 3676 | |
| 3677 | if (strcasecmp(path, "VendorSpecific") == 0) { |
| 3678 | snprintf(buf, sizeof(buf), "cp Certs/ca.pem SP/%s/ca.pem", |
| 3679 | fqdn); |
| 3680 | if (system(buf)) { |
| 3681 | send_resp(dut, conn, SIGMA_ERROR, |
| 3682 | "errorCode,Failed to copy OSU CA cert"); |
| 3683 | return 0; |
| 3684 | } |
| 3685 | |
| 3686 | snprintf(buf, sizeof(buf), |
| 3687 | "cp Certs/aaa-ca.pem SP/%s/aaa-ca.pem", |
| 3688 | fqdn); |
| 3689 | if (system(buf)) { |
| 3690 | send_resp(dut, conn, SIGMA_ERROR, |
| 3691 | "errorCode,Failed to copy AAA CA cert"); |
| 3692 | return 0; |
| 3693 | } |
| 3694 | } else { |
| 3695 | snprintf(buf, sizeof(buf), |
| 3696 | "dl_osu_ca SP/%s/pps.xml SP/%s/ca.pem", |
| 3697 | fqdn, fqdn); |
| 3698 | if (run_hs20_osu(dut, buf) < 0) { |
| 3699 | send_resp(dut, conn, SIGMA_ERROR, |
| 3700 | "errorCode,Failed to download OSU CA cert"); |
| 3701 | return 0; |
| 3702 | } |
| 3703 | |
| 3704 | snprintf(buf, sizeof(buf), |
| 3705 | "dl_aaa_ca SP/%s/pps.xml SP/%s/aaa-ca.pem", |
| 3706 | fqdn, fqdn); |
| 3707 | if (run_hs20_osu(dut, buf) < 0) { |
| 3708 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 3709 | "Failed to download AAA CA cert"); |
| 3710 | } |
| 3711 | } |
| 3712 | |
| 3713 | if (file_exists("next-client-cert.pem")) { |
| 3714 | snprintf(buf, sizeof(buf), "SP/%s/client-cert.pem", fqdn); |
| 3715 | if (rename("next-client-cert.pem", buf) < 0) { |
| 3716 | send_resp(dut, conn, SIGMA_ERROR, |
| 3717 | "errorCode,Could not move client certificate"); |
| 3718 | return 0; |
| 3719 | } |
| 3720 | } |
| 3721 | |
| 3722 | if (file_exists("next-client-key.pem")) { |
| 3723 | snprintf(buf, sizeof(buf), "SP/%s/client-key.pem", fqdn); |
| 3724 | if (rename("next-client-key.pem", buf) < 0) { |
| 3725 | send_resp(dut, conn, SIGMA_ERROR, |
| 3726 | "errorCode,Could not move client key"); |
| 3727 | return 0; |
| 3728 | } |
| 3729 | } |
| 3730 | |
| 3731 | snprintf(buf, sizeof(buf), "set_pps SP/%s/pps.xml", fqdn); |
| 3732 | if (run_hs20_osu(dut, buf) < 0) { |
| 3733 | send_resp(dut, conn, SIGMA_ERROR, |
| 3734 | "errorCode,Failed to configure credential from " |
| 3735 | "PPSMO"); |
| 3736 | return 0; |
| 3737 | } |
| 3738 | |
| 3739 | return 1; |
| 3740 | } |
| 3741 | |
| 3742 | |
| 3743 | static int download_cert(struct sigma_dut *dut, |
| 3744 | struct sigma_conn *conn, |
| 3745 | const char *intf, |
| 3746 | struct sigma_cmd *cmd) |
| 3747 | { |
| 3748 | const char *name, *path; |
| 3749 | char url[500], buf[600]; |
| 3750 | |
| 3751 | name = get_param(cmd, "FileName"); |
| 3752 | path = get_param(cmd, "FilePath"); |
| 3753 | if (name == NULL || path == NULL) |
| 3754 | return -1; |
| 3755 | |
| 3756 | if (strcasecmp(path, "VendorSpecific") == 0) { |
| 3757 | snprintf(url, sizeof(url), "Certs/%s-cert.pem", name); |
| 3758 | sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client " |
| 3759 | "certificate from the device (%s)", url); |
| 3760 | if (!file_exists(url)) { |
| 3761 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested " |
| 3762 | "certificate file does not exist"); |
| 3763 | return 0; |
| 3764 | } |
| 3765 | snprintf(buf, sizeof(buf), "cp %s next-client-cert.pem", url); |
| 3766 | if (system(buf) != 0) { |
| 3767 | send_resp(dut, conn, SIGMA_ERROR, |
| 3768 | "errorCode,Failed to copy client " |
| 3769 | "certificate"); |
| 3770 | return 0; |
| 3771 | } |
| 3772 | |
| 3773 | snprintf(url, sizeof(url), "Certs/%s-key.pem", name); |
| 3774 | sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client " |
| 3775 | "private key from the device (%s)", url); |
| 3776 | if (!file_exists(url)) { |
| 3777 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested " |
| 3778 | "private key file does not exist"); |
| 3779 | return 0; |
| 3780 | } |
| 3781 | snprintf(buf, sizeof(buf), "cp %s next-client-key.pem", url); |
| 3782 | if (system(buf) != 0) { |
| 3783 | send_resp(dut, conn, SIGMA_ERROR, |
| 3784 | "errorCode,Failed to copy client key"); |
| 3785 | return 0; |
| 3786 | } |
| 3787 | } else if (strncasecmp(path, "http:", 5) != 0 && |
| 3788 | strncasecmp(path, "https:", 6) != 0) { |
| 3789 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode," |
| 3790 | "Unsupported FilePath value"); |
| 3791 | return 0; |
| 3792 | } else { |
| 3793 | snprintf(url, sizeof(url), "%s/%s.pem", path, name); |
| 3794 | sigma_dut_print(dut, DUT_MSG_INFO, "Downloading client " |
| 3795 | "certificate/key from %s", url); |
| 3796 | snprintf(buf, sizeof(buf), |
| 3797 | "wget -T 10 -t 3 -O next-client-cert.pem '%s'", url); |
| 3798 | if (system(buf) != 0) { |
| 3799 | send_resp(dut, conn, SIGMA_ERROR, |
| 3800 | "errorCode,Failed to download client " |
| 3801 | "certificate"); |
| 3802 | return 0; |
| 3803 | } |
| 3804 | |
| 3805 | if (system("cp next-client-cert.pem next-client-key.pem") != 0) |
| 3806 | { |
| 3807 | send_resp(dut, conn, SIGMA_ERROR, |
| 3808 | "errorCode,Failed to copy client key"); |
| 3809 | return 0; |
| 3810 | } |
| 3811 | } |
| 3812 | |
| 3813 | return 1; |
| 3814 | } |
| 3815 | |
| 3816 | |
Alexei Avshalom Lazar | 33f700c | 2018-12-18 16:00:39 +0200 | [diff] [blame] | 3817 | static int cmd_sta_preset_testparameters_60ghz(struct sigma_dut *dut, |
| 3818 | struct sigma_conn *conn, |
| 3819 | struct sigma_cmd *cmd) |
| 3820 | { |
| 3821 | const char *val; |
| 3822 | const char *intf = get_param(cmd, "interface"); |
| 3823 | |
| 3824 | if (!intf) |
| 3825 | return -1; |
| 3826 | |
| 3827 | val = get_param(cmd, "WscIEFragment"); |
| 3828 | if (val && strcasecmp(val, "enable") == 0) { |
| 3829 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 3830 | "Enable WSC IE fragmentation"); |
| 3831 | |
| 3832 | dut->wsc_fragment = 1; |
| 3833 | /* set long attributes to force fragmentation */ |
| 3834 | if (wpa_command(intf, "SET device_name " |
| 3835 | WPS_LONG_DEVICE_NAME) < 0) |
| 3836 | return -2; |
| 3837 | if (wpa_command(intf, "SET manufacturer " |
| 3838 | WPS_LONG_MANUFACTURER) < 0) |
| 3839 | return -2; |
| 3840 | if (wpa_command(intf, "SET model_name " |
| 3841 | WPS_LONG_MODEL_NAME) < 0) |
| 3842 | return -2; |
| 3843 | if (wpa_command(intf, "SET model_number " |
| 3844 | WPS_LONG_MODEL_NUMBER) < 0) |
| 3845 | return -2; |
| 3846 | if (wpa_command(intf, "SET serial_number " |
| 3847 | WPS_LONG_SERIAL_NUMBER) < 0) |
| 3848 | return -2; |
| 3849 | } |
| 3850 | |
Alexei Avshalom Lazar | b094bf0 | 2018-12-18 16:00:53 +0200 | [diff] [blame] | 3851 | val = get_param(cmd, "RSN_IE"); |
| 3852 | if (val) { |
| 3853 | if (strcasecmp(val, "disable") == 0) |
| 3854 | dut->force_rsn_ie = FORCE_RSN_IE_REMOVE; |
| 3855 | else if (strcasecmp(val, "enable") == 0) |
| 3856 | dut->force_rsn_ie = FORCE_RSN_IE_ADD; |
| 3857 | } |
| 3858 | |
Alexei Avshalom Lazar | 744ae8a | 2019-01-31 17:26:46 +0200 | [diff] [blame] | 3859 | val = get_param(cmd, "WpsVersion"); |
| 3860 | if (val) |
| 3861 | dut->wps_forced_version = get_wps_forced_version(dut, val); |
| 3862 | |
Alexei Avshalom Lazar | 2eccf4d | 2019-01-31 10:03:59 +0200 | [diff] [blame] | 3863 | val = get_param(cmd, "WscEAPFragment"); |
| 3864 | if (val && strcasecmp(val, "enable") == 0) |
| 3865 | dut->eap_fragment = 1; |
| 3866 | |
Alexei Avshalom Lazar | 33f700c | 2018-12-18 16:00:39 +0200 | [diff] [blame] | 3867 | return 1; |
| 3868 | } |
| 3869 | |
| 3870 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3871 | static int cmd_sta_preset_testparameters_hs2_r2(struct sigma_dut *dut, |
| 3872 | struct sigma_conn *conn, |
| 3873 | const char *intf, |
| 3874 | struct sigma_cmd *cmd) |
| 3875 | { |
| 3876 | const char *val; |
| 3877 | |
| 3878 | val = get_param(cmd, "FileType"); |
| 3879 | if (val && strcasecmp(val, "PPSMO") == 0) |
| 3880 | return download_ppsmo(dut, conn, intf, cmd); |
| 3881 | if (val && strcasecmp(val, "CERT") == 0) |
| 3882 | return download_cert(dut, conn, intf, cmd); |
| 3883 | if (val) { |
| 3884 | send_resp(dut, conn, SIGMA_ERROR, |
| 3885 | "ErrorCode,Unsupported FileType"); |
| 3886 | return 0; |
| 3887 | } |
| 3888 | |
| 3889 | return 1; |
| 3890 | } |
| 3891 | |
| 3892 | |
Ankita Bajaj | a2cb567 | 2017-10-25 16:08:28 +0530 | [diff] [blame] | 3893 | static int cmd_sta_preset_testparameters_oce(struct sigma_dut *dut, |
| 3894 | struct sigma_conn *conn, |
| 3895 | const char *intf, |
| 3896 | struct sigma_cmd *cmd) |
| 3897 | { |
| 3898 | const char *val; |
Ankita Bajaj | 1bde794 | 2018-01-09 19:15:01 +0530 | [diff] [blame] | 3899 | char buf[1000]; |
| 3900 | char text[20]; |
| 3901 | unsigned char addr[ETH_ALEN]; |
Ankita Bajaj | a2cb567 | 2017-10-25 16:08:28 +0530 | [diff] [blame] | 3902 | |
| 3903 | val = get_param(cmd, "OCESupport"); |
| 3904 | if (val && strcasecmp(val, "Disable") == 0) { |
| 3905 | if (wpa_command(intf, "SET oce 0") < 0) { |
| 3906 | send_resp(dut, conn, SIGMA_ERROR, |
| 3907 | "ErrorCode,Failed to disable OCE"); |
| 3908 | return 0; |
| 3909 | } |
| 3910 | } else if (val && strcasecmp(val, "Enable") == 0) { |
| 3911 | if (wpa_command(intf, "SET oce 1") < 0) { |
| 3912 | send_resp(dut, conn, SIGMA_ERROR, |
| 3913 | "ErrorCode,Failed to enable OCE"); |
| 3914 | return 0; |
| 3915 | } |
| 3916 | } |
| 3917 | |
vamsi krishna | a279949 | 2017-12-05 14:28:01 +0530 | [diff] [blame] | 3918 | val = get_param(cmd, "FILScap"); |
| 3919 | if (val && (atoi(val) == 1)) { |
| 3920 | if (wpa_command(intf, "SET disable_fils 0") < 0) { |
| 3921 | send_resp(dut, conn, SIGMA_ERROR, |
| 3922 | "ErrorCode,Failed to enable FILS"); |
| 3923 | return 0; |
| 3924 | } |
| 3925 | } else if (val && (atoi(val) == 0)) { |
| 3926 | if (wpa_command(intf, "SET disable_fils 1") < 0) { |
| 3927 | send_resp(dut, conn, SIGMA_ERROR, |
| 3928 | "ErrorCode,Failed to disable FILS"); |
| 3929 | return 0; |
| 3930 | } |
| 3931 | } |
| 3932 | |
Ankita Bajaj | 1bde794 | 2018-01-09 19:15:01 +0530 | [diff] [blame] | 3933 | val = get_param(cmd, "FILSHLP"); |
| 3934 | if (val && strcasecmp(val, "Enable") == 0) { |
| 3935 | if (get_wpa_status(get_station_ifname(), "address", text, |
| 3936 | sizeof(text)) < 0) |
| 3937 | return -2; |
| 3938 | hwaddr_aton(text, addr); |
| 3939 | snprintf(buf, sizeof(buf), |
| 3940 | "FILS_HLP_REQ_ADD ff:ff:ff:ff:ff:ff " |
| 3941 | "080045100140000040004011399e00000000ffffffff00440043" |
| 3942 | "012cb30001010600fd4f46410000000000000000000000000000" |
| 3943 | "000000000000" |
| 3944 | "%02x%02x%02x%02x%02x%02x" |
| 3945 | "0000000000000000000000000000000000000000000000000000" |
| 3946 | "0000000000000000000000000000000000000000000000000000" |
| 3947 | "0000000000000000000000000000000000000000000000000000" |
| 3948 | "0000000000000000000000000000000000000000000000000000" |
| 3949 | "0000000000000000000000000000000000000000000000000000" |
| 3950 | "0000000000000000000000000000000000000000000000000000" |
| 3951 | "0000000000000000000000000000000000000000000000000000" |
| 3952 | "0000000000000000000000000000000000000000638253633501" |
| 3953 | "013d0701000af549d29b390205dc3c12616e64726f69642d6468" |
| 3954 | "63702d382e302e30370a0103060f1a1c333a3b2b5000ff00", |
| 3955 | addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]); |
| 3956 | if (wpa_command(intf, buf)) { |
| 3957 | send_resp(dut, conn, SIGMA_ERROR, |
| 3958 | "ErrorCode,Failed to add HLP"); |
| 3959 | return 0; |
| 3960 | } |
| 3961 | dut->fils_hlp = 1; |
| 3962 | } |
| 3963 | |
Ankita Bajaj | a2cb567 | 2017-10-25 16:08:28 +0530 | [diff] [blame] | 3964 | return 1; |
| 3965 | } |
| 3966 | |
| 3967 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3968 | static void ath_sta_set_noack(struct sigma_dut *dut, const char *intf, |
| 3969 | const char *val) |
| 3970 | { |
| 3971 | int counter = 0; |
| 3972 | char token[50]; |
| 3973 | char *result; |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 3974 | char *saveptr; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3975 | |
Peng Xu | b8fc5cc | 2017-05-10 17:27:28 -0700 | [diff] [blame] | 3976 | strlcpy(token, val, sizeof(token)); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3977 | token[sizeof(token) - 1] = '\0'; |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 3978 | result = strtok_r(token, ":", &saveptr); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3979 | while (result) { |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 3980 | if (strcmp(result, "disable") == 0) |
| 3981 | run_iwpriv(dut, intf, "noackpolicy %d 1 0", counter); |
| 3982 | else |
| 3983 | run_iwpriv(dut, intf, "noackpolicy %d 1 1", counter); |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 3984 | result = strtok_r(NULL, ":", &saveptr); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 3985 | counter++; |
| 3986 | } |
| 3987 | } |
| 3988 | |
| 3989 | |
| 3990 | static void ath_sta_set_rts(struct sigma_dut *dut, const char *intf, |
| 3991 | const char *val) |
| 3992 | { |
| 3993 | char buf[100]; |
| 3994 | |
| 3995 | snprintf(buf, sizeof(buf), "iwconfig %s rts %s", intf, val); |
| 3996 | if (system(buf) != 0) { |
| 3997 | sigma_dut_print(dut, DUT_MSG_ERROR, "iwconfig RTS failed"); |
| 3998 | } |
| 3999 | } |
| 4000 | |
| 4001 | |
| 4002 | static void ath_sta_set_wmm(struct sigma_dut *dut, const char *intf, |
| 4003 | const char *val) |
| 4004 | { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4005 | if (strcasecmp(val, "off") == 0) { |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 4006 | run_iwpriv(dut, intf, "wmm 0"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4007 | } |
| 4008 | } |
| 4009 | |
| 4010 | |
Amarnath Hullur Subramanyam | 75214d2 | 2018-02-04 19:17:11 -0800 | [diff] [blame] | 4011 | static int wcn_sta_set_wmm(struct sigma_dut *dut, const char *intf, |
| 4012 | const char *val) |
| 4013 | { |
| 4014 | #ifdef NL80211_SUPPORT |
| 4015 | struct nl_msg *msg; |
| 4016 | int ret = 0; |
| 4017 | struct nlattr *params; |
| 4018 | int ifindex; |
| 4019 | int wmmenable = 1; |
| 4020 | |
| 4021 | if (val && |
| 4022 | (strcasecmp(val, "off") == 0 || strcmp(val, "0") == 0)) |
| 4023 | wmmenable = 0; |
| 4024 | |
| 4025 | ifindex = if_nametoindex(intf); |
| 4026 | if (ifindex == 0) { |
| 4027 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4028 | "%s: Index for interface %s failed", |
| 4029 | __func__, intf); |
| 4030 | return -1; |
| 4031 | } |
| 4032 | |
| 4033 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 4034 | NL80211_CMD_VENDOR)) || |
| 4035 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 4036 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 4037 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 4038 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || |
| 4039 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 4040 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WMM_ENABLE, |
| 4041 | wmmenable)) { |
| 4042 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4043 | "%s: err in adding vendor_cmd and vendor_data", |
| 4044 | __func__); |
| 4045 | nlmsg_free(msg); |
| 4046 | return -1; |
| 4047 | } |
| 4048 | nla_nest_end(msg, params); |
| 4049 | |
| 4050 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 4051 | if (ret) { |
| 4052 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4053 | "%s: err in send_and_recv_msgs, ret=%d", |
| 4054 | __func__, ret); |
| 4055 | } |
| 4056 | return ret; |
| 4057 | #else /* NL80211_SUPPORT */ |
| 4058 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4059 | "WMM cannot be changed without NL80211_SUPPORT defined"); |
| 4060 | return -1; |
| 4061 | #endif /* NL80211_SUPPORT */ |
| 4062 | } |
| 4063 | |
| 4064 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4065 | static void ath_sta_set_sgi(struct sigma_dut *dut, const char *intf, |
| 4066 | const char *val) |
| 4067 | { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4068 | int sgi20; |
| 4069 | |
| 4070 | sgi20 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0; |
| 4071 | |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 4072 | run_iwpriv(dut, intf, "shortgi %d", sgi20); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4073 | } |
| 4074 | |
| 4075 | |
| 4076 | static void ath_sta_set_11nrates(struct sigma_dut *dut, const char *intf, |
| 4077 | const char *val) |
| 4078 | { |
Pradeep Reddy POTTETI | 67376b7 | 2016-10-25 20:08:17 +0530 | [diff] [blame] | 4079 | int rate_code, v; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4080 | |
| 4081 | /* Disable Tx Beam forming when using a fixed rate */ |
| 4082 | ath_disable_txbf(dut, intf); |
| 4083 | |
Pradeep Reddy POTTETI | 67376b7 | 2016-10-25 20:08:17 +0530 | [diff] [blame] | 4084 | v = atoi(val); |
| 4085 | if (v < 0 || v > 32) { |
| 4086 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4087 | "Invalid Fixed MCS rate: %d", v); |
| 4088 | return; |
| 4089 | } |
| 4090 | rate_code = 0x80 + v; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4091 | |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 4092 | run_iwpriv(dut, intf, "set11NRates 0x%x", rate_code); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4093 | |
| 4094 | /* Channel width gets messed up, fix this */ |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 4095 | run_iwpriv(dut, intf, "chwidth %d", dut->chwidth); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4096 | } |
| 4097 | |
| 4098 | |
Amarnath Hullur Subramanyam | d5bb573 | 2018-02-22 15:50:38 -0800 | [diff] [blame] | 4099 | static void iwpriv_sta_set_amsdu(struct sigma_dut *dut, const char *intf, |
| 4100 | const char *val) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4101 | { |
| 4102 | char buf[60]; |
| 4103 | |
| 4104 | if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) |
| 4105 | snprintf(buf, sizeof(buf), "iwpriv %s amsdu 2", intf); |
| 4106 | else |
| 4107 | snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf); |
| 4108 | |
| 4109 | if (system(buf) != 0) |
| 4110 | sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv amsdu failed"); |
| 4111 | } |
| 4112 | |
| 4113 | |
Deepak Dhamdhere | 80356cb | 2016-03-28 16:48:32 -0700 | [diff] [blame] | 4114 | static int iwpriv_sta_set_ampdu(struct sigma_dut *dut, const char *intf, |
| 4115 | int ampdu) |
| 4116 | { |
| 4117 | char buf[60]; |
Amarnath Hullur Subramanyam | 63c590a | 2018-03-07 15:26:21 -0800 | [diff] [blame] | 4118 | int maxaggregation = 63; |
Deepak Dhamdhere | 80356cb | 2016-03-28 16:48:32 -0700 | [diff] [blame] | 4119 | |
Amarnath Hullur Subramanyam | 63c590a | 2018-03-07 15:26:21 -0800 | [diff] [blame] | 4120 | if (ampdu) |
| 4121 | ampdu = maxaggregation; |
Deepak Dhamdhere | 80356cb | 2016-03-28 16:48:32 -0700 | [diff] [blame] | 4122 | snprintf(buf, sizeof(buf), "iwpriv %s ampdu %d", intf, ampdu); |
| 4123 | if (system(buf) != 0) { |
| 4124 | sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv ampdu failed"); |
| 4125 | return -1; |
| 4126 | } |
| 4127 | |
| 4128 | return 0; |
| 4129 | } |
| 4130 | |
| 4131 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4132 | static void ath_sta_set_stbc(struct sigma_dut *dut, const char *intf, |
| 4133 | const char *val) |
| 4134 | { |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 4135 | run_iwpriv(dut, intf, "tx_stbc %s", val); |
| 4136 | run_iwpriv(dut, intf, "rx_stbc %s", val); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4137 | } |
| 4138 | |
| 4139 | |
| 4140 | static int wcn_sta_set_cts_width(struct sigma_dut *dut, const char *intf, |
| 4141 | const char *val) |
| 4142 | { |
| 4143 | char buf[60]; |
| 4144 | |
Peng Xu | cc317ed | 2017-05-18 16:44:37 -0700 | [diff] [blame] | 4145 | if (strcmp(val, "160") == 0) { |
| 4146 | snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 5", intf); |
| 4147 | } else if (strcmp(val, "80") == 0) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4148 | snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf); |
| 4149 | } else if (strcmp(val, "40") == 0) { |
| 4150 | snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 2", intf); |
| 4151 | } else if (strcmp(val, "20") == 0) { |
| 4152 | snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 1", intf); |
| 4153 | } else if (strcasecmp(val, "Auto") == 0) { |
| 4154 | buf[0] = '\0'; |
| 4155 | } else { |
| 4156 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4157 | "WIDTH/CTS_WIDTH value not supported"); |
| 4158 | return -1; |
| 4159 | } |
| 4160 | |
| 4161 | if (buf[0] != '\0' && system(buf) != 0) { |
| 4162 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4163 | "Failed to set WIDTH/CTS_WIDTH"); |
| 4164 | return -1; |
| 4165 | } |
| 4166 | |
| 4167 | return 0; |
| 4168 | } |
| 4169 | |
| 4170 | |
| 4171 | int ath_set_width(struct sigma_dut *dut, struct sigma_conn *conn, |
| 4172 | const char *intf, const char *val) |
| 4173 | { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4174 | if (strcasecmp(val, "Auto") == 0) { |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 4175 | run_iwpriv(dut, intf, "chwidth 0"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4176 | dut->chwidth = 0; |
| 4177 | } else if (strcasecmp(val, "20") == 0) { |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 4178 | run_iwpriv(dut, intf, "chwidth 0"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4179 | dut->chwidth = 0; |
| 4180 | } else if (strcasecmp(val, "40") == 0) { |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 4181 | run_iwpriv(dut, intf, "chwidth 1"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4182 | dut->chwidth = 1; |
| 4183 | } else if (strcasecmp(val, "80") == 0) { |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 4184 | run_iwpriv(dut, intf, "chwidth 2"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4185 | dut->chwidth = 2; |
| 4186 | } else if (strcasecmp(val, "160") == 0) { |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 4187 | run_iwpriv(dut, intf, "chwidth 3"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4188 | dut->chwidth = 3; |
| 4189 | } else { |
| 4190 | send_resp(dut, conn, SIGMA_ERROR, |
| 4191 | "ErrorCode,WIDTH not supported"); |
| 4192 | return -1; |
| 4193 | } |
| 4194 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4195 | return 0; |
| 4196 | } |
| 4197 | |
| 4198 | |
| 4199 | static int wcn_sta_set_sp_stream(struct sigma_dut *dut, const char *intf, |
| 4200 | const char *val) |
| 4201 | { |
| 4202 | char buf[60]; |
Arif Hussain | ac6c511 | 2018-05-25 17:34:00 -0700 | [diff] [blame] | 4203 | int sta_nss; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4204 | |
Amarnath Hullur Subramanyam | d5374fa | 2018-02-25 19:00:24 -0800 | [diff] [blame] | 4205 | if (strcmp(val, "1SS") == 0 || strcmp(val, "1") == 0) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4206 | snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf); |
Arif Hussain | ac6c511 | 2018-05-25 17:34:00 -0700 | [diff] [blame] | 4207 | sta_nss = 1; |
Amarnath Hullur Subramanyam | d5374fa | 2018-02-25 19:00:24 -0800 | [diff] [blame] | 4208 | } else if (strcmp(val, "2SS") == 0 || strcmp(val, "2") == 0) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4209 | snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf); |
Arif Hussain | ac6c511 | 2018-05-25 17:34:00 -0700 | [diff] [blame] | 4210 | sta_nss = 2; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4211 | } else { |
| 4212 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4213 | "SP_STREAM value not supported"); |
| 4214 | return -1; |
| 4215 | } |
| 4216 | |
| 4217 | if (system(buf) != 0) { |
| 4218 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4219 | "Failed to set SP_STREAM"); |
| 4220 | return -1; |
| 4221 | } |
| 4222 | |
Arif Hussain | ac6c511 | 2018-05-25 17:34:00 -0700 | [diff] [blame] | 4223 | dut->sta_nss = sta_nss; |
| 4224 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4225 | return 0; |
| 4226 | } |
| 4227 | |
| 4228 | |
Pradeep Reddy POTTETI | 4a1f6b3 | 2016-11-23 13:15:21 +0530 | [diff] [blame] | 4229 | static void wcn_sta_set_stbc(struct sigma_dut *dut, const char *intf, |
| 4230 | const char *val) |
| 4231 | { |
| 4232 | char buf[60]; |
| 4233 | |
| 4234 | snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc %s", intf, val); |
| 4235 | if (system(buf) != 0) |
| 4236 | sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv tx_stbc failed"); |
| 4237 | |
| 4238 | snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc %s", intf, val); |
| 4239 | if (system(buf) != 0) |
| 4240 | sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv rx_stbc failed"); |
| 4241 | } |
| 4242 | |
| 4243 | |
Ashwini Patil | 68d02cd | 2017-01-10 15:39:16 +0530 | [diff] [blame] | 4244 | static int mbo_set_cellular_data_capa(struct sigma_dut *dut, |
| 4245 | struct sigma_conn *conn, |
| 4246 | const char *intf, int capa) |
| 4247 | { |
| 4248 | char buf[32]; |
| 4249 | |
| 4250 | if (capa > 0 && capa < 4) { |
| 4251 | snprintf(buf, sizeof(buf), "SET mbo_cell_capa %d", capa); |
| 4252 | if (wpa_command(intf, buf) < 0) { |
| 4253 | send_resp(dut, conn, SIGMA_ERROR, |
| 4254 | "ErrorCode, Failed to set cellular data capability"); |
| 4255 | return 0; |
| 4256 | } |
| 4257 | return 1; |
| 4258 | } |
| 4259 | |
| 4260 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4261 | "Invalid Cellular data capability: %d", capa); |
| 4262 | send_resp(dut, conn, SIGMA_INVALID, |
| 4263 | "ErrorCode,Invalid cellular data capability"); |
| 4264 | return 0; |
| 4265 | } |
| 4266 | |
| 4267 | |
Ashwini Patil | 9183fdb | 2017-04-13 16:58:25 +0530 | [diff] [blame] | 4268 | static int mbo_set_roaming(struct sigma_dut *dut, struct sigma_conn *conn, |
| 4269 | const char *intf, const char *val) |
| 4270 | { |
| 4271 | if (strcasecmp(val, "Disable") == 0) { |
| 4272 | if (wpa_command(intf, "SET roaming 0") < 0) { |
| 4273 | send_resp(dut, conn, SIGMA_ERROR, |
| 4274 | "ErrorCode,Failed to disable roaming"); |
| 4275 | return 0; |
| 4276 | } |
| 4277 | return 1; |
| 4278 | } |
| 4279 | |
| 4280 | if (strcasecmp(val, "Enable") == 0) { |
| 4281 | if (wpa_command(intf, "SET roaming 1") < 0) { |
| 4282 | send_resp(dut, conn, SIGMA_ERROR, |
| 4283 | "ErrorCode,Failed to enable roaming"); |
| 4284 | return 0; |
| 4285 | } |
| 4286 | return 1; |
| 4287 | } |
| 4288 | |
| 4289 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4290 | "Invalid value provided for roaming: %s", val); |
| 4291 | send_resp(dut, conn, SIGMA_INVALID, |
| 4292 | "ErrorCode,Unknown value provided for Roaming"); |
| 4293 | return 0; |
| 4294 | } |
| 4295 | |
| 4296 | |
Ashwini Patil | a75de5a | 2017-04-13 16:35:05 +0530 | [diff] [blame] | 4297 | static int mbo_set_assoc_disallow(struct sigma_dut *dut, |
| 4298 | struct sigma_conn *conn, |
| 4299 | const char *intf, const char *val) |
| 4300 | { |
| 4301 | if (strcasecmp(val, "Disable") == 0) { |
| 4302 | if (wpa_command(intf, "SET ignore_assoc_disallow 1") < 0) { |
| 4303 | send_resp(dut, conn, SIGMA_ERROR, |
| 4304 | "ErrorCode,Failed to disable Assoc_disallow"); |
| 4305 | return 0; |
| 4306 | } |
| 4307 | return 1; |
| 4308 | } |
| 4309 | |
| 4310 | if (strcasecmp(val, "Enable") == 0) { |
| 4311 | if (wpa_command(intf, "SET ignore_assoc_disallow 0") < 0) { |
| 4312 | send_resp(dut, conn, SIGMA_ERROR, |
| 4313 | "ErrorCode,Failed to enable Assoc_disallow"); |
| 4314 | return 0; |
| 4315 | } |
| 4316 | return 1; |
| 4317 | } |
| 4318 | |
| 4319 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4320 | "Invalid value provided for Assoc_disallow: %s", val); |
| 4321 | send_resp(dut, conn, SIGMA_INVALID, |
| 4322 | "ErrorCode,Unknown value provided for Assoc_disallow"); |
| 4323 | return 0; |
| 4324 | } |
| 4325 | |
| 4326 | |
Ashwini Patil | c63161e | 2017-04-13 16:30:23 +0530 | [diff] [blame] | 4327 | static int mbo_set_bss_trans_req(struct sigma_dut *dut, struct sigma_conn *conn, |
| 4328 | const char *intf, const char *val) |
| 4329 | { |
| 4330 | if (strcasecmp(val, "Reject") == 0) { |
| 4331 | if (wpa_command(intf, "SET reject_btm_req_reason 1") < 0) { |
| 4332 | send_resp(dut, conn, SIGMA_ERROR, |
| 4333 | "ErrorCode,Failed to Reject BTM Request"); |
| 4334 | return 0; |
| 4335 | } |
| 4336 | return 1; |
| 4337 | } |
| 4338 | |
| 4339 | if (strcasecmp(val, "Accept") == 0) { |
| 4340 | if (wpa_command(intf, "SET reject_btm_req_reason 0") < 0) { |
| 4341 | send_resp(dut, conn, SIGMA_ERROR, |
| 4342 | "ErrorCode,Failed to Accept BTM Request"); |
| 4343 | return 0; |
| 4344 | } |
| 4345 | return 1; |
| 4346 | } |
| 4347 | |
| 4348 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4349 | "Invalid value provided for BSS_Transition: %s", val); |
| 4350 | send_resp(dut, conn, SIGMA_INVALID, |
| 4351 | "ErrorCode,Unknown value provided for BSS_Transition"); |
| 4352 | return 0; |
| 4353 | } |
| 4354 | |
| 4355 | |
Ashwini Patil | 0040258 | 2017-04-13 12:29:39 +0530 | [diff] [blame] | 4356 | static int mbo_set_non_pref_ch_list(struct sigma_dut *dut, |
| 4357 | struct sigma_conn *conn, |
| 4358 | const char *intf, |
| 4359 | struct sigma_cmd *cmd) |
| 4360 | { |
| 4361 | const char *ch, *pref, *op_class, *reason; |
| 4362 | char buf[120]; |
| 4363 | int len, ret; |
| 4364 | |
| 4365 | pref = get_param(cmd, "Ch_Pref"); |
| 4366 | if (!pref) |
| 4367 | return 1; |
| 4368 | |
| 4369 | if (strcasecmp(pref, "clear") == 0) { |
| 4370 | free(dut->non_pref_ch_list); |
| 4371 | dut->non_pref_ch_list = NULL; |
| 4372 | } else { |
| 4373 | op_class = get_param(cmd, "Ch_Op_Class"); |
| 4374 | if (!op_class) { |
| 4375 | send_resp(dut, conn, SIGMA_INVALID, |
| 4376 | "ErrorCode,Ch_Op_Class not provided"); |
| 4377 | return 0; |
| 4378 | } |
| 4379 | |
| 4380 | ch = get_param(cmd, "Ch_Pref_Num"); |
| 4381 | if (!ch) { |
| 4382 | send_resp(dut, conn, SIGMA_INVALID, |
| 4383 | "ErrorCode,Ch_Pref_Num not provided"); |
| 4384 | return 0; |
| 4385 | } |
| 4386 | |
| 4387 | reason = get_param(cmd, "Ch_Reason_Code"); |
| 4388 | if (!reason) { |
| 4389 | send_resp(dut, conn, SIGMA_INVALID, |
| 4390 | "ErrorCode,Ch_Reason_Code not provided"); |
| 4391 | return 0; |
| 4392 | } |
| 4393 | |
| 4394 | if (!dut->non_pref_ch_list) { |
| 4395 | dut->non_pref_ch_list = |
| 4396 | calloc(1, NON_PREF_CH_LIST_SIZE); |
| 4397 | if (!dut->non_pref_ch_list) { |
| 4398 | send_resp(dut, conn, SIGMA_ERROR, |
| 4399 | "ErrorCode,Failed to allocate memory for non_pref_ch_list"); |
| 4400 | return 0; |
| 4401 | } |
| 4402 | } |
| 4403 | len = strlen(dut->non_pref_ch_list); |
| 4404 | ret = snprintf(dut->non_pref_ch_list + len, |
| 4405 | NON_PREF_CH_LIST_SIZE - len, |
| 4406 | " %s:%s:%s:%s", op_class, ch, pref, reason); |
| 4407 | if (ret > 0 && ret < NON_PREF_CH_LIST_SIZE - len) { |
| 4408 | sigma_dut_print(dut, DUT_MSG_DEBUG, "non_pref_list: %s", |
| 4409 | dut->non_pref_ch_list); |
| 4410 | } else { |
| 4411 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4412 | "snprintf failed for non_pref_list, ret = %d", |
| 4413 | ret); |
| 4414 | send_resp(dut, conn, SIGMA_ERROR, |
| 4415 | "ErrorCode,snprintf failed"); |
| 4416 | free(dut->non_pref_ch_list); |
| 4417 | dut->non_pref_ch_list = NULL; |
| 4418 | return 0; |
| 4419 | } |
| 4420 | } |
| 4421 | |
| 4422 | ret = snprintf(buf, sizeof(buf), "SET non_pref_chan%s", |
| 4423 | dut->non_pref_ch_list ? dut->non_pref_ch_list : " "); |
| 4424 | if (ret < 0 || ret >= (int) sizeof(buf)) { |
| 4425 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 4426 | "snprintf failed for set non_pref_chan, ret: %d", |
| 4427 | ret); |
| 4428 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,snprint failed"); |
| 4429 | return 0; |
| 4430 | } |
| 4431 | |
| 4432 | if (wpa_command(intf, buf) < 0) { |
| 4433 | send_resp(dut, conn, SIGMA_ERROR, |
| 4434 | "ErrorCode,Failed to set non-preferred channel list"); |
| 4435 | return 0; |
| 4436 | } |
| 4437 | |
| 4438 | return 1; |
| 4439 | } |
| 4440 | |
| 4441 | |
Amarnath Hullur Subramanyam | 474a17d | 2018-02-22 18:45:54 -0800 | [diff] [blame] | 4442 | #ifdef NL80211_SUPPORT |
Amarnath Hullur Subramanyam | ae8a2d9 | 2018-03-01 06:32:21 -0800 | [diff] [blame] | 4443 | |
Kiran Kumar Lokere | e5ed442 | 2018-12-18 18:25:02 -0800 | [diff] [blame] | 4444 | static int sta_set_he_htc_supp(struct sigma_dut *dut, const char *intf, |
| 4445 | uint8_t cfg) |
| 4446 | { |
| 4447 | struct nl_msg *msg; |
| 4448 | int ret = 0; |
| 4449 | struct nlattr *params; |
| 4450 | int ifindex; |
| 4451 | |
| 4452 | ifindex = if_nametoindex(intf); |
| 4453 | if (ifindex == 0) { |
| 4454 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4455 | "%s: Index for interface %s failed", |
| 4456 | __func__, intf); |
| 4457 | return -1; |
| 4458 | } |
| 4459 | |
| 4460 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 4461 | NL80211_CMD_VENDOR)) || |
| 4462 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 4463 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 4464 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 4465 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || |
| 4466 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 4467 | nla_put_u8(msg, |
| 4468 | QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_HTC_HE_SUPP, |
| 4469 | cfg)) { |
| 4470 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4471 | "%s: err in adding vendor_cmd and vendor_data", |
| 4472 | __func__); |
| 4473 | nlmsg_free(msg); |
| 4474 | return -1; |
| 4475 | } |
| 4476 | nla_nest_end(msg, params); |
| 4477 | |
| 4478 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 4479 | if (ret) { |
| 4480 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4481 | "%s: err in send_and_recv_msgs, ret=%d", |
| 4482 | __func__, ret); |
| 4483 | } |
| 4484 | return ret; |
| 4485 | } |
| 4486 | |
| 4487 | |
Amarnath Hullur Subramanyam | 474a17d | 2018-02-22 18:45:54 -0800 | [diff] [blame] | 4488 | static int sta_set_he_fragmentation(struct sigma_dut *dut, const char *intf, |
| 4489 | enum he_fragmentation_val frag) |
| 4490 | { |
| 4491 | struct nl_msg *msg; |
| 4492 | int ret = 0; |
| 4493 | struct nlattr *params; |
| 4494 | int ifindex; |
| 4495 | |
| 4496 | ifindex = if_nametoindex(intf); |
| 4497 | if (ifindex == 0) { |
| 4498 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4499 | "%s: Index for interface %s failed", |
| 4500 | __func__, intf); |
| 4501 | return -1; |
| 4502 | } |
| 4503 | |
| 4504 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 4505 | NL80211_CMD_VENDOR)) || |
| 4506 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 4507 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 4508 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 4509 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || |
| 4510 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 4511 | nla_put_u8(msg, |
| 4512 | QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_FRAGMENTATION, |
| 4513 | frag)) { |
| 4514 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4515 | "%s: err in adding vendor_cmd and vendor_data", |
| 4516 | __func__); |
| 4517 | nlmsg_free(msg); |
| 4518 | return -1; |
| 4519 | } |
| 4520 | nla_nest_end(msg, params); |
| 4521 | |
| 4522 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 4523 | if (ret) { |
| 4524 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4525 | "%s: err in send_and_recv_msgs, ret=%d", |
| 4526 | __func__, ret); |
| 4527 | } |
| 4528 | return ret; |
| 4529 | } |
Amarnath Hullur Subramanyam | ae8a2d9 | 2018-03-01 06:32:21 -0800 | [diff] [blame] | 4530 | |
| 4531 | |
Subhani Shaik | 8e7a305 | 2018-04-24 14:03:00 -0700 | [diff] [blame] | 4532 | static int sta_set_he_ltf(struct sigma_dut *dut, const char *intf, |
| 4533 | enum qca_wlan_he_ltf_cfg ltf) |
| 4534 | { |
| 4535 | struct nl_msg *msg; |
| 4536 | int ret = 0; |
| 4537 | struct nlattr *params; |
| 4538 | int ifindex; |
| 4539 | |
| 4540 | ifindex = if_nametoindex(intf); |
| 4541 | if (ifindex == 0) { |
| 4542 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4543 | "%s: Index for interface %s failed", |
| 4544 | __func__, intf); |
| 4545 | return -1; |
| 4546 | } |
| 4547 | |
| 4548 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 4549 | NL80211_CMD_VENDOR)) || |
| 4550 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 4551 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 4552 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 4553 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || |
| 4554 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 4555 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_LTF, |
| 4556 | ltf)) { |
| 4557 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4558 | "%s: err in adding vendor_cmd and vendor_data", |
| 4559 | __func__); |
| 4560 | nlmsg_free(msg); |
| 4561 | return -1; |
| 4562 | } |
| 4563 | nla_nest_end(msg, params); |
| 4564 | |
| 4565 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 4566 | if (ret) { |
| 4567 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4568 | "%s: err in send_and_recv_msgs, ret=%d", |
| 4569 | __func__, ret); |
| 4570 | } |
| 4571 | return ret; |
| 4572 | } |
| 4573 | |
| 4574 | |
Amarnath Hullur Subramanyam | ae8a2d9 | 2018-03-01 06:32:21 -0800 | [diff] [blame] | 4575 | static int nlvendor_sta_set_noack(struct sigma_dut *dut, const char *intf, |
| 4576 | int noack, enum qca_wlan_ac_type ac) |
| 4577 | { |
| 4578 | struct nl_msg *msg; |
| 4579 | int ret = 0; |
| 4580 | struct nlattr *params; |
| 4581 | int ifindex; |
| 4582 | |
| 4583 | ifindex = if_nametoindex(intf); |
| 4584 | if (ifindex == 0) { |
| 4585 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4586 | "%s: Index for interface %s failed", |
| 4587 | __func__, intf); |
| 4588 | return -1; |
| 4589 | } |
| 4590 | |
| 4591 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 4592 | NL80211_CMD_VENDOR)) || |
| 4593 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 4594 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 4595 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 4596 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || |
| 4597 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 4598 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_NO_ACK, |
| 4599 | noack) || |
| 4600 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_NO_ACK_AC, |
| 4601 | ac)) { |
| 4602 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4603 | "%s: err in adding vendor_cmd and vendor_data", |
| 4604 | __func__); |
| 4605 | nlmsg_free(msg); |
| 4606 | return -1; |
| 4607 | } |
| 4608 | nla_nest_end(msg, params); |
| 4609 | |
| 4610 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 4611 | if (ret) { |
| 4612 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4613 | "%s: err in send_and_recv_msgs, ret=%d", |
| 4614 | __func__, ret); |
| 4615 | } |
| 4616 | return ret; |
| 4617 | } |
| 4618 | |
| 4619 | |
| 4620 | static void wcn_sta_set_noack(struct sigma_dut *dut, const char *intf, |
| 4621 | const char *val) |
| 4622 | { |
| 4623 | int noack, ret; |
| 4624 | char token[100]; |
| 4625 | char *result; |
| 4626 | char *saveptr; |
| 4627 | enum qca_wlan_ac_type ac = QCA_WLAN_AC_BE; |
| 4628 | |
| 4629 | strlcpy(token, val, sizeof(token)); |
| 4630 | token[sizeof(token) - 1] = '\0'; |
| 4631 | result = strtok_r(token, ":", &saveptr); |
| 4632 | while (result) { |
| 4633 | noack = strcasecmp(result, "Disable") != 0; |
| 4634 | ret = nlvendor_sta_set_noack(dut, intf, noack, ac); |
| 4635 | if (ret) { |
| 4636 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4637 | "nlvendor_sta_set_noack failed for ac:%d, ret:%d", |
| 4638 | ac, ret); |
| 4639 | } |
| 4640 | result = strtok_r(NULL, ":", &saveptr); |
| 4641 | ac++; |
| 4642 | } |
| 4643 | } |
| 4644 | |
Amarnath Hullur Subramanyam | 474a17d | 2018-02-22 18:45:54 -0800 | [diff] [blame] | 4645 | #endif /* NL80211_SUPPORT */ |
| 4646 | |
| 4647 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 4648 | static enum sigma_cmd_result |
| 4649 | cmd_sta_preset_testparameters(struct sigma_dut *dut, struct sigma_conn *conn, |
| 4650 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4651 | { |
| 4652 | const char *intf = get_param(cmd, "Interface"); |
| 4653 | const char *val; |
| 4654 | |
Jouni Malinen | 6a7c9b4 | 2019-08-20 00:15:59 +0300 | [diff] [blame] | 4655 | val = get_param(cmd, "FT_DS"); |
| 4656 | if (val) { |
| 4657 | if (strcasecmp(val, "Enable") == 0) { |
| 4658 | dut->sta_ft_ds = 1; |
| 4659 | } else if (strcasecmp(val, "Disable") == 0) { |
| 4660 | dut->sta_ft_ds = 0; |
| 4661 | } else { |
| 4662 | send_resp(dut, conn, SIGMA_ERROR, |
| 4663 | "errorCode,Unsupported value for FT_DS"); |
| 4664 | return STATUS_SENT_ERROR; |
| 4665 | } |
| 4666 | } |
| 4667 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4668 | val = get_param(cmd, "Program"); |
Jouni Malinen | 1f6ae64 | 2018-06-07 23:56:13 +0300 | [diff] [blame] | 4669 | if (val && (strcasecmp(val, "HS2-R2") == 0 || |
| 4670 | strcasecmp(val, "HS2-R3") == 0)) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4671 | return cmd_sta_preset_testparameters_hs2_r2(dut, conn, intf, |
| 4672 | cmd); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4673 | |
priyadharshini gowthaman | d66913a | 2016-07-29 15:11:17 -0700 | [diff] [blame] | 4674 | if (val && strcasecmp(val, "LOC") == 0) |
| 4675 | return loc_cmd_sta_preset_testparameters(dut, conn, cmd); |
Alexei Avshalom Lazar | eee9ab0 | 2018-12-24 16:27:48 +0200 | [diff] [blame] | 4676 | if (val && strcasecmp(val, "60GHZ") == 0) { |
| 4677 | val = get_param(cmd, "WPS"); |
| 4678 | if (val && strcasecmp(val, "disable") == 0) { |
| 4679 | dut->wps_disable = 1; |
| 4680 | sigma_dut_print(dut, DUT_MSG_INFO, "WPS disabled"); |
| 4681 | } else { |
| 4682 | /* wps_disable can have other value from the previous |
| 4683 | * test, so make sure it has the correct value. |
| 4684 | */ |
| 4685 | dut->wps_disable = 0; |
| 4686 | } |
| 4687 | |
| 4688 | val = get_param(cmd, "P2P"); |
| 4689 | if (val && strcasecmp(val, "disable") == 0) |
| 4690 | sigma_dut_print(dut, DUT_MSG_INFO, "P2P disabled"); |
| 4691 | } |
priyadharshini gowthaman | d66913a | 2016-07-29 15:11:17 -0700 | [diff] [blame] | 4692 | |
Alexei Avshalom Lazar | 33f700c | 2018-12-18 16:00:39 +0200 | [diff] [blame] | 4693 | if (dut->program == PROGRAM_WPS && dut->band == WPS_BAND_60G) |
| 4694 | return cmd_sta_preset_testparameters_60ghz(dut, conn, cmd); |
| 4695 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4696 | #ifdef ANDROID_NAN |
| 4697 | if (val && strcasecmp(val, "NAN") == 0) |
| 4698 | return nan_cmd_sta_preset_testparameters(dut, conn, cmd); |
| 4699 | #endif /* ANDROID_NAN */ |
Amarnath Hullur Subramanyam | 9c381f5 | 2017-03-17 00:04:41 -0700 | [diff] [blame] | 4700 | #ifdef MIRACAST |
| 4701 | if (val && (strcasecmp(val, "WFD") == 0 || |
| 4702 | strcasecmp(val, "DisplayR2") == 0)) |
| 4703 | return miracast_preset_testparameters(dut, conn, cmd); |
| 4704 | #endif /* MIRACAST */ |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4705 | |
Ashwini Patil | 68d02cd | 2017-01-10 15:39:16 +0530 | [diff] [blame] | 4706 | if (val && strcasecmp(val, "MBO") == 0) { |
| 4707 | val = get_param(cmd, "Cellular_Data_Cap"); |
| 4708 | if (val && |
| 4709 | mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0) |
| 4710 | return 0; |
Ashwini Patil | 0040258 | 2017-04-13 12:29:39 +0530 | [diff] [blame] | 4711 | |
| 4712 | val = get_param(cmd, "Ch_Pref"); |
| 4713 | if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0) |
| 4714 | return 0; |
| 4715 | |
Ashwini Patil | c63161e | 2017-04-13 16:30:23 +0530 | [diff] [blame] | 4716 | val = get_param(cmd, "BSS_Transition"); |
| 4717 | if (val && mbo_set_bss_trans_req(dut, conn, intf, val) == 0) |
| 4718 | return 0; |
| 4719 | |
Ashwini Patil | a75de5a | 2017-04-13 16:35:05 +0530 | [diff] [blame] | 4720 | val = get_param(cmd, "Assoc_Disallow"); |
| 4721 | if (val && mbo_set_assoc_disallow(dut, conn, intf, val) == 0) |
| 4722 | return 0; |
| 4723 | |
Ashwini Patil | 9183fdb | 2017-04-13 16:58:25 +0530 | [diff] [blame] | 4724 | val = get_param(cmd, "Roaming"); |
| 4725 | if (val && mbo_set_roaming(dut, conn, intf, val) == 0) |
| 4726 | return 0; |
| 4727 | |
Ashwini Patil | 68d02cd | 2017-01-10 15:39:16 +0530 | [diff] [blame] | 4728 | return 1; |
| 4729 | } |
| 4730 | |
Ankita Bajaj | a2cb567 | 2017-10-25 16:08:28 +0530 | [diff] [blame] | 4731 | if (val && strcasecmp(val, "OCE") == 0) |
| 4732 | return cmd_sta_preset_testparameters_oce(dut, conn, intf, cmd); |
| 4733 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4734 | #if 0 |
| 4735 | val = get_param(cmd, "Supplicant"); |
| 4736 | if (val && strcasecmp(val, "Default") != 0) { |
| 4737 | send_resp(dut, conn, SIGMA_ERROR, |
| 4738 | "ErrorCode,Only default(Vendor) supplicant " |
| 4739 | "supported"); |
| 4740 | return 0; |
| 4741 | } |
| 4742 | #endif |
| 4743 | |
| 4744 | val = get_param(cmd, "RTS"); |
| 4745 | if (val) { |
| 4746 | switch (get_driver_type()) { |
| 4747 | case DRIVER_ATHEROS: |
| 4748 | ath_sta_set_rts(dut, intf, val); |
| 4749 | break; |
| 4750 | default: |
| 4751 | #if 0 |
| 4752 | send_resp(dut, conn, SIGMA_ERROR, |
| 4753 | "ErrorCode,Setting RTS not supported"); |
| 4754 | return 0; |
| 4755 | #else |
| 4756 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 4757 | "Setting RTS not supported"); |
| 4758 | break; |
| 4759 | #endif |
| 4760 | } |
| 4761 | } |
| 4762 | |
| 4763 | #if 0 |
| 4764 | val = get_param(cmd, "FRGMNT"); |
| 4765 | if (val) { |
| 4766 | /* TODO */ |
| 4767 | send_resp(dut, conn, SIGMA_ERROR, |
| 4768 | "ErrorCode,Setting FRGMNT not supported"); |
| 4769 | return 0; |
| 4770 | } |
| 4771 | #endif |
| 4772 | |
| 4773 | #if 0 |
| 4774 | val = get_param(cmd, "Preamble"); |
| 4775 | if (val) { |
| 4776 | /* TODO: Long/Short */ |
| 4777 | send_resp(dut, conn, SIGMA_ERROR, |
| 4778 | "ErrorCode,Setting Preamble not supported"); |
| 4779 | return 0; |
| 4780 | } |
| 4781 | #endif |
| 4782 | |
| 4783 | val = get_param(cmd, "Mode"); |
| 4784 | if (val) { |
| 4785 | if (strcmp(val, "11b") == 0 || |
| 4786 | strcmp(val, "11g") == 0 || |
| 4787 | strcmp(val, "11a") == 0 || |
| 4788 | strcmp(val, "11n") == 0 || |
| 4789 | strcmp(val, "11ng") == 0 || |
| 4790 | strcmp(val, "11nl") == 0 || |
| 4791 | strcmp(val, "11nl(nabg)") == 0 || |
| 4792 | strcmp(val, "AC") == 0 || |
| 4793 | strcmp(val, "11AC") == 0 || |
| 4794 | strcmp(val, "11ac") == 0 || |
| 4795 | strcmp(val, "11na") == 0 || |
Amarnath Hullur Subramanyam | b0db271 | 2018-01-30 19:40:35 -0800 | [diff] [blame] | 4796 | strcmp(val, "11an") == 0 || |
| 4797 | strcmp(val, "11ax") == 0) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4798 | /* STA supports all modes by default */ |
| 4799 | } else { |
| 4800 | send_resp(dut, conn, SIGMA_ERROR, |
| 4801 | "ErrorCode,Setting Mode not supported"); |
| 4802 | return 0; |
| 4803 | } |
Amarnath Hullur Subramanyam | 97d0e53 | 2018-01-31 02:53:02 -0800 | [diff] [blame] | 4804 | |
| 4805 | /* Change the mode only in case of testbed for HE program |
| 4806 | * and for 11a and 11g modes only. */ |
| 4807 | if (dut->program == PROGRAM_HE && |
| 4808 | dut->device_type == STA_testbed) { |
| 4809 | int phymode; |
| 4810 | char buf[60]; |
| 4811 | |
| 4812 | if (strcmp(val, "11a") == 0) { |
Amarnath Hullur Subramanyam | 94dfaf0 | 2018-03-02 19:26:57 -0800 | [diff] [blame] | 4813 | phymode = 1; /* IEEE80211_MODE_11A */ |
| 4814 | } else if (strcmp(val, "11g") == 0) { |
| 4815 | phymode = 3; /* IEEE80211_MODE_11G */ |
| 4816 | } else if (strcmp(val, "11b") == 0) { |
| 4817 | phymode = 2; /* IEEE80211_MODE_11B */ |
| 4818 | } else if (strcmp(val, "11n") == 0 || |
| 4819 | strcmp(val, "11nl") == 0 || |
| 4820 | strcmp(val, "11nl(nabg)") == 0) { |
| 4821 | phymode = 22; /* IEEE80211_MODE_11AGN */ |
| 4822 | } else if (strcmp(val, "11ng") == 0) { |
| 4823 | phymode = 13; /* IEEE80211_MODE_11NG_HT40 */ |
| 4824 | } else if (strcmp(val, "AC") == 0 || |
| 4825 | strcasecmp(val, "11AC") == 0) { |
| 4826 | phymode = 19; /* IEEE80211_MODE_11AC_VHT80 */ |
| 4827 | } else if (strcmp(val, "11na") == 0 || |
| 4828 | strcasecmp(val, "11an") == 0) { |
| 4829 | phymode = 14; /* IEEE80211_MODE_11NA_HT40 */ |
| 4830 | } else if (strcmp(val, "11ax") == 0) { |
| 4831 | phymode = 0; /* IEEE80211_MODE_AUTO */ |
Amarnath Hullur Subramanyam | 97d0e53 | 2018-01-31 02:53:02 -0800 | [diff] [blame] | 4832 | } else { |
| 4833 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 4834 | "Ignoring mode change for mode: %s", |
| 4835 | val); |
| 4836 | phymode = -1; |
| 4837 | } |
| 4838 | if (phymode != -1) { |
| 4839 | snprintf(buf, sizeof(buf), |
| 4840 | "iwpriv %s setphymode %d", |
| 4841 | intf, phymode); |
| 4842 | if (system(buf) != 0) { |
| 4843 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4844 | "iwpriv setting of phymode failed"); |
| 4845 | } |
| 4846 | } |
| 4847 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4848 | } |
| 4849 | |
| 4850 | val = get_param(cmd, "wmm"); |
| 4851 | if (val) { |
| 4852 | switch (get_driver_type()) { |
| 4853 | case DRIVER_ATHEROS: |
| 4854 | ath_sta_set_wmm(dut, intf, val); |
| 4855 | break; |
Amarnath Hullur Subramanyam | 75214d2 | 2018-02-04 19:17:11 -0800 | [diff] [blame] | 4856 | case DRIVER_WCN: |
| 4857 | wcn_sta_set_wmm(dut, intf, val); |
| 4858 | break; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4859 | default: |
| 4860 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 4861 | "Setting wmm not supported"); |
| 4862 | break; |
| 4863 | } |
| 4864 | } |
| 4865 | |
| 4866 | val = get_param(cmd, "Powersave"); |
| 4867 | if (val) { |
Kiran Kumar Lokere | d6149ff | 2018-12-05 20:20:41 -0800 | [diff] [blame] | 4868 | char buf[60]; |
| 4869 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4870 | if (strcmp(val, "0") == 0 || strcasecmp(val, "off") == 0) { |
Kiran Kumar Lokere | d6149ff | 2018-12-05 20:20:41 -0800 | [diff] [blame] | 4871 | if (get_driver_type() == DRIVER_WCN) { |
| 4872 | snprintf(buf, sizeof(buf), |
| 4873 | "iwpriv %s setPower 2", intf); |
| 4874 | if (system(buf) != 0) { |
| 4875 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4876 | "iwpriv setPower 2 failed"); |
| 4877 | return 0; |
| 4878 | } |
| 4879 | } |
| 4880 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4881 | if (wpa_command(get_station_ifname(), |
| 4882 | "P2P_SET ps 0") < 0) |
| 4883 | return -2; |
| 4884 | /* Make sure test modes are disabled */ |
| 4885 | wpa_command(get_station_ifname(), "P2P_SET ps 98"); |
| 4886 | wpa_command(get_station_ifname(), "P2P_SET ps 96"); |
| 4887 | } else if (strcmp(val, "1") == 0 || |
| 4888 | strcasecmp(val, "PSPoll") == 0 || |
| 4889 | strcasecmp(val, "on") == 0) { |
Kiran Kumar Lokere | d6149ff | 2018-12-05 20:20:41 -0800 | [diff] [blame] | 4890 | if (get_driver_type() == DRIVER_WCN) { |
| 4891 | snprintf(buf, sizeof(buf), |
| 4892 | "iwpriv %s setPower 1", intf); |
| 4893 | if (system(buf) != 0) { |
| 4894 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 4895 | "iwpriv setPower 1 failed"); |
| 4896 | return 0; |
| 4897 | } |
| 4898 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4899 | /* Disable default power save mode */ |
| 4900 | wpa_command(get_station_ifname(), "P2P_SET ps 0"); |
| 4901 | /* Enable PS-Poll test mode */ |
| 4902 | if (wpa_command(get_station_ifname(), |
| 4903 | "P2P_SET ps 97") < 0 || |
| 4904 | wpa_command(get_station_ifname(), |
| 4905 | "P2P_SET ps 99") < 0) |
| 4906 | return -2; |
| 4907 | } else if (strcmp(val, "2") == 0 || |
| 4908 | strcasecmp(val, "Fast") == 0) { |
| 4909 | /* TODO */ |
| 4910 | send_resp(dut, conn, SIGMA_ERROR, |
| 4911 | "ErrorCode,Powersave=Fast not supported"); |
| 4912 | return 0; |
| 4913 | } else if (strcmp(val, "3") == 0 || |
| 4914 | strcasecmp(val, "PSNonPoll") == 0) { |
| 4915 | /* Make sure test modes are disabled */ |
| 4916 | wpa_command(get_station_ifname(), "P2P_SET ps 98"); |
| 4917 | wpa_command(get_station_ifname(), "P2P_SET ps 96"); |
| 4918 | |
| 4919 | /* Enable default power save mode */ |
| 4920 | if (wpa_command(get_station_ifname(), |
| 4921 | "P2P_SET ps 1") < 0) |
| 4922 | return -2; |
| 4923 | } else |
| 4924 | return -1; |
| 4925 | } |
| 4926 | |
| 4927 | val = get_param(cmd, "NoAck"); |
| 4928 | if (val) { |
| 4929 | switch (get_driver_type()) { |
| 4930 | case DRIVER_ATHEROS: |
| 4931 | ath_sta_set_noack(dut, intf, val); |
| 4932 | break; |
Amarnath Hullur Subramanyam | ae8a2d9 | 2018-03-01 06:32:21 -0800 | [diff] [blame] | 4933 | #ifdef NL80211_SUPPORT |
| 4934 | case DRIVER_WCN: |
| 4935 | wcn_sta_set_noack(dut, intf, val); |
| 4936 | break; |
| 4937 | #endif /* NL80211_SUPPORT */ |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4938 | default: |
| 4939 | send_resp(dut, conn, SIGMA_ERROR, |
| 4940 | "ErrorCode,Setting NoAck not supported"); |
| 4941 | return 0; |
| 4942 | } |
| 4943 | } |
| 4944 | |
| 4945 | val = get_param(cmd, "IgnoreChswitchProhibit"); |
| 4946 | if (val) { |
| 4947 | /* TODO: Enabled/disabled */ |
| 4948 | if (strcasecmp(val, "Enabled") == 0) { |
| 4949 | send_resp(dut, conn, SIGMA_ERROR, |
| 4950 | "ErrorCode,Enabling IgnoreChswitchProhibit " |
| 4951 | "not supported"); |
| 4952 | return 0; |
| 4953 | } |
| 4954 | } |
| 4955 | |
| 4956 | val = get_param(cmd, "TDLS"); |
| 4957 | if (val) { |
| 4958 | if (strcasecmp(val, "Disabled") == 0) { |
| 4959 | if (wpa_command(intf, "SET tdls_disabled 1")) { |
| 4960 | send_resp(dut, conn, SIGMA_ERROR, |
| 4961 | "ErrorCode,Failed to disable TDLS"); |
| 4962 | return 0; |
| 4963 | } |
| 4964 | } else if (strcasecmp(val, "Enabled") == 0) { |
| 4965 | if (wpa_command(intf, "SET tdls_disabled 0")) { |
| 4966 | send_resp(dut, conn, SIGMA_ERROR, |
| 4967 | "ErrorCode,Failed to enable TDLS"); |
| 4968 | return 0; |
| 4969 | } |
| 4970 | } else { |
| 4971 | send_resp(dut, conn, SIGMA_ERROR, |
| 4972 | "ErrorCode,Unsupported TDLS value"); |
| 4973 | return 0; |
| 4974 | } |
| 4975 | } |
| 4976 | |
| 4977 | val = get_param(cmd, "TDLSmode"); |
| 4978 | if (val) { |
| 4979 | if (strcasecmp(val, "Default") == 0) { |
| 4980 | wpa_command(intf, "SET tdls_testing 0"); |
| 4981 | } else if (strcasecmp(val, "APProhibit") == 0) { |
| 4982 | if (wpa_command(intf, "SET tdls_testing 0x400")) { |
| 4983 | send_resp(dut, conn, SIGMA_ERROR, |
| 4984 | "ErrorCode,Failed to enable ignore " |
| 4985 | "APProhibit TDLS mode"); |
| 4986 | return 0; |
| 4987 | } |
| 4988 | } else if (strcasecmp(val, "HiLoMac") == 0) { |
| 4989 | /* STA should respond with TDLS setup req for a TDLS |
| 4990 | * setup req */ |
| 4991 | if (wpa_command(intf, "SET tdls_testing 0x80")) { |
| 4992 | send_resp(dut, conn, SIGMA_ERROR, |
| 4993 | "ErrorCode,Failed to enable HiLoMac " |
| 4994 | "TDLS mode"); |
| 4995 | return 0; |
| 4996 | } |
| 4997 | } else if (strcasecmp(val, "WeakSecurity") == 0) { |
| 4998 | /* |
| 4999 | * Since all security modes are enabled by default when |
| 5000 | * Sigma control is used, there is no need to do |
| 5001 | * anything here. |
| 5002 | */ |
| 5003 | } else if (strcasecmp(val, "ExistLink") == 0) { |
| 5004 | /* |
| 5005 | * Since we allow new TDLS Setup Request even if there |
| 5006 | * is an existing link, nothing needs to be done for |
| 5007 | * this. |
| 5008 | */ |
| 5009 | } else { |
| 5010 | /* TODO: |
| 5011 | * ExistLink: STA should send TDLS setup req even if |
| 5012 | * direct link already exists |
| 5013 | */ |
| 5014 | send_resp(dut, conn, SIGMA_ERROR, |
| 5015 | "ErrorCode,Unsupported TDLSmode value"); |
| 5016 | return 0; |
| 5017 | } |
| 5018 | } |
| 5019 | |
| 5020 | val = get_param(cmd, "FakePubKey"); |
| 5021 | if (val && atoi(val) && wpa_command(intf, "SET wps_corrupt_pkhash 1")) { |
| 5022 | send_resp(dut, conn, SIGMA_ERROR, |
| 5023 | "ErrorCode,Failed to enable FakePubKey"); |
| 5024 | return 0; |
| 5025 | } |
| 5026 | |
Amarnath Hullur Subramanyam | ae1042b | 2018-02-22 21:52:52 -0800 | [diff] [blame] | 5027 | #ifdef NL80211_SUPPORT |
| 5028 | val = get_param(cmd, "FrgmntSupport"); |
| 5029 | if (val) { |
| 5030 | if (strcasecmp(val, "Enable") == 0) { |
| 5031 | if (sta_set_he_fragmentation(dut, intf, |
| 5032 | HE_FRAG_LEVEL1)) { |
| 5033 | send_resp(dut, conn, SIGMA_ERROR, |
| 5034 | "ErrorCode,Failed to enable HE Fragmentation"); |
| 5035 | return 0; |
| 5036 | } |
| 5037 | } else if (strcasecmp(val, "Disable") == 0) { |
| 5038 | if (sta_set_he_fragmentation(dut, intf, |
| 5039 | HE_FRAG_DISABLE)) { |
| 5040 | send_resp(dut, conn, SIGMA_ERROR, |
| 5041 | "ErrorCode,Failed to disable HE Fragmentation"); |
| 5042 | return 0; |
| 5043 | } |
| 5044 | } |
| 5045 | } |
| 5046 | #endif /* NL80211_SUPPORT */ |
| 5047 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5048 | return 1; |
| 5049 | } |
| 5050 | |
| 5051 | |
| 5052 | static const char * ath_get_radio_name(const char *radio_name) |
| 5053 | { |
| 5054 | if (radio_name == NULL) |
| 5055 | return "wifi0"; |
| 5056 | if (strcmp(radio_name, "wifi1") == 0) |
| 5057 | return "wifi1"; |
| 5058 | if (strcmp(radio_name, "wifi2") == 0) |
| 5059 | return "wifi2"; |
| 5060 | return "wifi0"; |
| 5061 | } |
| 5062 | |
| 5063 | |
| 5064 | static void ath_sta_set_txsp_stream(struct sigma_dut *dut, const char *intf, |
| 5065 | const char *val) |
| 5066 | { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5067 | unsigned int vht_mcsmap = 0; |
| 5068 | int txchainmask = 0; |
| 5069 | const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]); |
| 5070 | |
| 5071 | if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) { |
| 5072 | if (dut->testbed_flag_txsp == 1) { |
| 5073 | vht_mcsmap = 0xfffc; |
| 5074 | dut->testbed_flag_txsp = 0; |
| 5075 | } else { |
| 5076 | vht_mcsmap = 0xfffe; |
| 5077 | } |
| 5078 | txchainmask = 1; |
| 5079 | } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) { |
| 5080 | if (dut->testbed_flag_txsp == 1) { |
| 5081 | vht_mcsmap = 0xfff0; |
| 5082 | dut->testbed_flag_txsp = 0; |
| 5083 | } else { |
| 5084 | vht_mcsmap = 0xfffa; |
| 5085 | } |
| 5086 | txchainmask = 3; |
| 5087 | } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) { |
| 5088 | if (dut->testbed_flag_txsp == 1) { |
| 5089 | vht_mcsmap = 0xffc0; |
| 5090 | dut->testbed_flag_txsp = 0; |
| 5091 | } else { |
| 5092 | vht_mcsmap = 0xffea; |
| 5093 | } |
| 5094 | txchainmask = 7; |
| 5095 | } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) { |
| 5096 | if (dut->testbed_flag_txsp == 1) { |
| 5097 | vht_mcsmap = 0xff00; |
| 5098 | dut->testbed_flag_txsp = 0; |
| 5099 | } else { |
| 5100 | vht_mcsmap = 0xffaa; |
| 5101 | } |
| 5102 | txchainmask = 15; |
| 5103 | } else { |
| 5104 | if (dut->testbed_flag_txsp == 1) { |
| 5105 | vht_mcsmap = 0xffc0; |
| 5106 | dut->testbed_flag_txsp = 0; |
| 5107 | } else { |
| 5108 | vht_mcsmap = 0xffea; |
| 5109 | } |
| 5110 | } |
| 5111 | |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 5112 | if (txchainmask) |
| 5113 | run_iwpriv(dut, basedev, "txchainmask %d", txchainmask); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5114 | |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 5115 | run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5116 | } |
| 5117 | |
| 5118 | |
| 5119 | static void ath_sta_set_rxsp_stream(struct sigma_dut *dut, const char *intf, |
| 5120 | const char *val) |
| 5121 | { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5122 | unsigned int vht_mcsmap = 0; |
| 5123 | int rxchainmask = 0; |
| 5124 | const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]); |
| 5125 | |
| 5126 | if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) { |
| 5127 | if (dut->testbed_flag_rxsp == 1) { |
| 5128 | vht_mcsmap = 0xfffc; |
| 5129 | dut->testbed_flag_rxsp = 0; |
| 5130 | } else { |
| 5131 | vht_mcsmap = 0xfffe; |
| 5132 | } |
| 5133 | rxchainmask = 1; |
| 5134 | } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) { |
| 5135 | if (dut->testbed_flag_rxsp == 1) { |
| 5136 | vht_mcsmap = 0xfff0; |
| 5137 | dut->testbed_flag_rxsp = 0; |
| 5138 | } else { |
| 5139 | vht_mcsmap = 0xfffa; |
| 5140 | } |
| 5141 | rxchainmask = 3; |
| 5142 | } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) { |
| 5143 | if (dut->testbed_flag_rxsp == 1) { |
| 5144 | vht_mcsmap = 0xffc0; |
| 5145 | dut->testbed_flag_rxsp = 0; |
| 5146 | } else { |
| 5147 | vht_mcsmap = 0xffea; |
| 5148 | } |
| 5149 | rxchainmask = 7; |
| 5150 | } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) { |
| 5151 | if (dut->testbed_flag_rxsp == 1) { |
| 5152 | vht_mcsmap = 0xff00; |
| 5153 | dut->testbed_flag_rxsp = 0; |
| 5154 | } else { |
| 5155 | vht_mcsmap = 0xffaa; |
| 5156 | } |
| 5157 | rxchainmask = 15; |
| 5158 | } else { |
| 5159 | if (dut->testbed_flag_rxsp == 1) { |
| 5160 | vht_mcsmap = 0xffc0; |
| 5161 | dut->testbed_flag_rxsp = 0; |
| 5162 | } else { |
| 5163 | vht_mcsmap = 0xffea; |
| 5164 | } |
| 5165 | } |
| 5166 | |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 5167 | if (rxchainmask) |
| 5168 | run_iwpriv(dut, basedev, "rxchainmask %d", rxchainmask); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5169 | |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 5170 | run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5171 | } |
| 5172 | |
| 5173 | |
| 5174 | void ath_set_zero_crc(struct sigma_dut *dut, const char *val) |
| 5175 | { |
| 5176 | if (strcasecmp(val, "enable") == 0) { |
| 5177 | if (system("athdiag --set --address=0x2a204 --and=0xbfffffff") |
| 5178 | != 0) { |
| 5179 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5180 | "Disable BB_VHTSIGB_CRC_CALC failed"); |
| 5181 | } |
| 5182 | |
| 5183 | if (system("athdiag --set --address=0x2a204 --or=0x80000000") |
| 5184 | != 0) { |
| 5185 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5186 | "Enable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed"); |
| 5187 | } |
| 5188 | } else { |
| 5189 | if (system("athdiag --set --address=0x2a204 --and=0x7fffffff") |
| 5190 | != 0) { |
| 5191 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5192 | "Disable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed"); |
| 5193 | } |
| 5194 | |
| 5195 | if (system("athdiag --set --address=0x2a204 --or=0x40000000") |
| 5196 | != 0) { |
| 5197 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5198 | "Enable BB_VHTSIGB_CRC_CALC failed"); |
| 5199 | } |
| 5200 | } |
| 5201 | } |
| 5202 | |
| 5203 | |
Amarnath Hullur Subramanyam | ebfe6b6 | 2018-01-31 03:04:17 -0800 | [diff] [blame] | 5204 | static int wcn_sta_set_width(struct sigma_dut *dut, const char *intf, |
| 5205 | const char *val) |
| 5206 | { |
| 5207 | char buf[60]; |
| 5208 | |
| 5209 | if (strcmp(val, "20") == 0) { |
| 5210 | snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf); |
| 5211 | dut->chwidth = 0; |
| 5212 | } else if (strcmp(val, "40") == 0) { |
| 5213 | snprintf(buf, sizeof(buf), "iwpriv %s chwidth 1", intf); |
| 5214 | dut->chwidth = 1; |
| 5215 | } else if (strcmp(val, "80") == 0) { |
| 5216 | snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf); |
| 5217 | dut->chwidth = 2; |
Sunil Dutt | b1cccac | 2018-05-22 21:03:12 +0530 | [diff] [blame] | 5218 | } else if (strcasecmp(val, "Auto") == 0) { |
Amarnath Hullur Subramanyam | ebfe6b6 | 2018-01-31 03:04:17 -0800 | [diff] [blame] | 5219 | buf[0] = '\0'; |
| 5220 | } else { |
| 5221 | sigma_dut_print(dut, DUT_MSG_ERROR, "WIDTH %s not supported", |
| 5222 | val); |
| 5223 | return -1; |
| 5224 | } |
| 5225 | |
| 5226 | if (buf[0] != '\0' && system(buf) != 0) { |
| 5227 | sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv chwidth failed"); |
| 5228 | return -1; |
| 5229 | } |
| 5230 | |
| 5231 | return 0; |
| 5232 | } |
| 5233 | |
| 5234 | |
Amarnath Hullur Subramanyam | d8a9db9 | 2018-02-02 18:53:14 -0800 | [diff] [blame] | 5235 | static int nlvendor_sta_set_addba_reject(struct sigma_dut *dut, |
| 5236 | const char *intf, int addbareject) |
| 5237 | { |
| 5238 | #ifdef NL80211_SUPPORT |
| 5239 | struct nl_msg *msg; |
| 5240 | int ret = 0; |
| 5241 | struct nlattr *params; |
| 5242 | int ifindex; |
| 5243 | |
| 5244 | ifindex = if_nametoindex(intf); |
| 5245 | if (ifindex == 0) { |
| 5246 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5247 | "%s: Index for interface %s failed", |
| 5248 | __func__, intf); |
| 5249 | return -1; |
| 5250 | } |
| 5251 | |
| 5252 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 5253 | NL80211_CMD_VENDOR)) || |
| 5254 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 5255 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 5256 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 5257 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || |
| 5258 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 5259 | nla_put_u8(msg, |
| 5260 | QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ACCEPT_ADDBA_REQ, |
| 5261 | !addbareject)) { |
| 5262 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5263 | "%s: err in adding vendor_cmd and vendor_data", |
| 5264 | __func__); |
| 5265 | nlmsg_free(msg); |
| 5266 | return -1; |
| 5267 | } |
| 5268 | nla_nest_end(msg, params); |
| 5269 | |
| 5270 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 5271 | if (ret) { |
| 5272 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5273 | "%s: err in send_and_recv_msgs, ret=%d", |
| 5274 | __func__, ret); |
| 5275 | } |
| 5276 | return ret; |
| 5277 | #else /* NL80211_SUPPORT */ |
| 5278 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5279 | "ADDBA_REJECT cannot be set without NL80211_SUPPORT defined"); |
| 5280 | return -1; |
| 5281 | #endif /* NL80211_SUPPORT */ |
| 5282 | } |
| 5283 | |
| 5284 | |
| 5285 | static int sta_set_addba_reject(struct sigma_dut *dut, const char *intf, |
| 5286 | int addbareject) |
| 5287 | { |
| 5288 | int ret; |
| 5289 | |
| 5290 | switch (get_driver_type()) { |
| 5291 | case DRIVER_WCN: |
| 5292 | ret = nlvendor_sta_set_addba_reject(dut, intf, addbareject); |
| 5293 | if (ret) { |
| 5294 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5295 | "nlvendor_sta_set_addba_reject failed, ret:%d", |
| 5296 | ret); |
| 5297 | return ret; |
| 5298 | } |
| 5299 | break; |
| 5300 | default: |
| 5301 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5302 | "errorCode,Unsupported ADDBA_REJECT with the current driver"); |
| 5303 | ret = -1; |
| 5304 | break; |
| 5305 | } |
| 5306 | |
| 5307 | return ret; |
| 5308 | } |
| 5309 | |
| 5310 | |
Amarnath Hullur Subramanyam | 1f65a67 | 2018-03-07 14:50:29 -0800 | [diff] [blame] | 5311 | static int nlvendor_config_send_addba(struct sigma_dut *dut, const char *intf, |
| 5312 | int enable) |
Amarnath Hullur Subramanyam | 9745b3c | 2018-02-04 21:27:57 -0800 | [diff] [blame] | 5313 | { |
| 5314 | #ifdef NL80211_SUPPORT |
| 5315 | struct nl_msg *msg; |
| 5316 | int ret = 0; |
| 5317 | struct nlattr *params; |
| 5318 | int ifindex; |
| 5319 | |
| 5320 | ifindex = if_nametoindex(intf); |
| 5321 | if (ifindex == 0) { |
| 5322 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5323 | "%s: Index for interface %s failed", |
| 5324 | __func__, intf); |
| 5325 | return -1; |
| 5326 | } |
| 5327 | |
| 5328 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 5329 | NL80211_CMD_VENDOR)) || |
| 5330 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 5331 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 5332 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 5333 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || |
| 5334 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 5335 | nla_put_u8(msg, |
| 5336 | QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SEND_ADDBA_REQ, |
Amarnath Hullur Subramanyam | 1f65a67 | 2018-03-07 14:50:29 -0800 | [diff] [blame] | 5337 | enable)) { |
Amarnath Hullur Subramanyam | 9745b3c | 2018-02-04 21:27:57 -0800 | [diff] [blame] | 5338 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5339 | "%s: err in adding vendor_cmd and vendor_data", |
| 5340 | __func__); |
| 5341 | nlmsg_free(msg); |
| 5342 | return -1; |
| 5343 | } |
| 5344 | nla_nest_end(msg, params); |
| 5345 | |
| 5346 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 5347 | if (ret) { |
| 5348 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5349 | "%s: err in send_and_recv_msgs, ret=%d", |
| 5350 | __func__, ret); |
| 5351 | } |
| 5352 | return ret; |
| 5353 | #else /* NL80211_SUPPORT */ |
| 5354 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5355 | "Disable addba not possible without NL80211_SUPPORT defined"); |
| 5356 | return -1; |
| 5357 | #endif /* NL80211_SUPPORT */ |
| 5358 | } |
| 5359 | |
| 5360 | |
Veerendranath Jakkam | adcd620 | 2019-04-17 12:32:21 +0530 | [diff] [blame] | 5361 | #ifdef NL80211_SUPPORT |
| 5362 | static int nl80211_sta_set_rts(struct sigma_dut *dut, const char *intf, int val) |
| 5363 | { |
| 5364 | struct nl_msg *msg; |
| 5365 | int ret = 0; |
| 5366 | int ifindex; |
| 5367 | |
| 5368 | ifindex = if_nametoindex(intf); |
| 5369 | if (ifindex == 0) { |
| 5370 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5371 | "%s: Index for interface %s failed", |
| 5372 | __func__, intf); |
| 5373 | return -1; |
| 5374 | } |
| 5375 | |
| 5376 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 5377 | NL80211_CMD_SET_WIPHY)) || |
| 5378 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) { |
| 5379 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5380 | "%s: err in adding RTS threshold", |
| 5381 | __func__); |
| 5382 | nlmsg_free(msg); |
| 5383 | return -1; |
| 5384 | } |
| 5385 | |
| 5386 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 5387 | if (ret) { |
| 5388 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5389 | "%s: err in send_and_recv_msgs, ret=%d", |
| 5390 | __func__, ret); |
| 5391 | } |
| 5392 | return ret; |
| 5393 | } |
| 5394 | #endif /* NL80211_SUPPORT */ |
| 5395 | |
| 5396 | |
| 5397 | static int sta_set_rts(struct sigma_dut *dut, const char *intf, int val) |
| 5398 | { |
| 5399 | char buf[100]; |
| 5400 | |
| 5401 | #ifdef NL80211_SUPPORT |
| 5402 | if (nl80211_sta_set_rts(dut, intf, val) == 0) |
| 5403 | return 0; |
| 5404 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 5405 | "Fall back to using iwconfig for setting RTS threshold"); |
| 5406 | #endif /* NL80211_SUPPORT */ |
| 5407 | |
| 5408 | snprintf(buf, sizeof(buf), "iwconfig %s rts %d", intf, val); |
| 5409 | if (system(buf) != 0) { |
| 5410 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5411 | "Failed to set RTS threshold %d", val); |
| 5412 | return -1; |
| 5413 | } |
| 5414 | return 0; |
| 5415 | } |
| 5416 | |
| 5417 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5418 | static int cmd_sta_set_wireless_common(const char *intf, struct sigma_dut *dut, |
| 5419 | struct sigma_conn *conn, |
| 5420 | struct sigma_cmd *cmd) |
| 5421 | { |
| 5422 | const char *val; |
Amarnath Hullur Subramanyam | d8a9db9 | 2018-02-02 18:53:14 -0800 | [diff] [blame] | 5423 | int ampdu = -1, addbareject = -1; |
Jouni Malinen | 3aa7286 | 2019-05-29 23:14:51 +0300 | [diff] [blame] | 5424 | char buf[128]; |
| 5425 | int res; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5426 | |
| 5427 | val = get_param(cmd, "40_INTOLERANT"); |
| 5428 | if (val) { |
| 5429 | if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) { |
| 5430 | /* TODO: iwpriv ht40intol through wpa_supplicant */ |
| 5431 | send_resp(dut, conn, SIGMA_ERROR, |
| 5432 | "ErrorCode,40_INTOLERANT not supported"); |
| 5433 | return 0; |
| 5434 | } |
| 5435 | } |
| 5436 | |
| 5437 | val = get_param(cmd, "ADDBA_REJECT"); |
| 5438 | if (val) { |
| 5439 | if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) { |
| 5440 | /* reject any ADDBA with status "decline" */ |
| 5441 | ampdu = 0; |
Amarnath Hullur Subramanyam | d8a9db9 | 2018-02-02 18:53:14 -0800 | [diff] [blame] | 5442 | addbareject = 1; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5443 | } else { |
| 5444 | /* accept ADDBA */ |
| 5445 | ampdu = 1; |
Amarnath Hullur Subramanyam | d8a9db9 | 2018-02-02 18:53:14 -0800 | [diff] [blame] | 5446 | addbareject = 0; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5447 | } |
| 5448 | } |
| 5449 | |
Amarnath Hullur Subramanyam | d8a9db9 | 2018-02-02 18:53:14 -0800 | [diff] [blame] | 5450 | if (addbareject >= 0 && |
| 5451 | sta_set_addba_reject(dut, intf, addbareject) < 0) { |
| 5452 | send_resp(dut, conn, SIGMA_ERROR, |
| 5453 | "ErrorCode,set addba_reject failed"); |
| 5454 | return 0; |
| 5455 | } |
| 5456 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5457 | val = get_param(cmd, "AMPDU"); |
| 5458 | if (val) { |
| 5459 | if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) { |
| 5460 | /* enable AMPDU Aggregation */ |
| 5461 | if (ampdu == 0) { |
| 5462 | send_resp(dut, conn, SIGMA_ERROR, |
| 5463 | "ErrorCode,Mismatch in " |
| 5464 | "addba_reject/ampdu - " |
| 5465 | "not supported"); |
| 5466 | return 0; |
| 5467 | } |
| 5468 | ampdu = 1; |
| 5469 | } else { |
| 5470 | /* disable AMPDU Aggregation */ |
| 5471 | if (ampdu == 1) { |
| 5472 | send_resp(dut, conn, SIGMA_ERROR, |
| 5473 | "ErrorCode,Mismatch in " |
| 5474 | "addba_reject/ampdu - " |
| 5475 | "not supported"); |
| 5476 | return 0; |
| 5477 | } |
| 5478 | ampdu = 0; |
| 5479 | } |
| 5480 | } |
| 5481 | |
| 5482 | if (ampdu >= 0) { |
Amarnath Hullur Subramanyam | 9745b3c | 2018-02-04 21:27:57 -0800 | [diff] [blame] | 5483 | int ret; |
| 5484 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5485 | sigma_dut_print(dut, DUT_MSG_DEBUG, "%s A-MPDU aggregation", |
| 5486 | ampdu ? "Enabling" : "Disabling"); |
| 5487 | snprintf(buf, sizeof(buf), "SET ampdu %d", ampdu); |
Deepak Dhamdhere | 80356cb | 2016-03-28 16:48:32 -0700 | [diff] [blame] | 5488 | if (wpa_command(intf, buf) < 0 && |
| 5489 | iwpriv_sta_set_ampdu(dut, intf, ampdu) < 0) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5490 | send_resp(dut, conn, SIGMA_ERROR, |
| 5491 | "ErrorCode,set aggr failed"); |
| 5492 | return 0; |
| 5493 | } |
Amarnath Hullur Subramanyam | 9745b3c | 2018-02-04 21:27:57 -0800 | [diff] [blame] | 5494 | |
| 5495 | if (ampdu == 0) { |
| 5496 | /* Disable sending of addba using nl vendor command */ |
Amarnath Hullur Subramanyam | 1f65a67 | 2018-03-07 14:50:29 -0800 | [diff] [blame] | 5497 | ret = nlvendor_config_send_addba(dut, intf, 0); |
Amarnath Hullur Subramanyam | 9745b3c | 2018-02-04 21:27:57 -0800 | [diff] [blame] | 5498 | if (ret) { |
| 5499 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5500 | "Failed to disable addba, ret:%d", |
| 5501 | ret); |
| 5502 | } |
| 5503 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5504 | } |
| 5505 | |
| 5506 | val = get_param(cmd, "AMSDU"); |
| 5507 | if (val) { |
| 5508 | switch (get_driver_type()) { |
| 5509 | case DRIVER_ATHEROS: |
Amarnath Hullur Subramanyam | d5bb573 | 2018-02-22 15:50:38 -0800 | [diff] [blame] | 5510 | case DRIVER_WCN: |
| 5511 | iwpriv_sta_set_amsdu(dut, intf, val); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5512 | break; |
| 5513 | default: |
| 5514 | if (strcmp(val, "1") == 0 || |
| 5515 | strcasecmp(val, "Enable") == 0) { |
| 5516 | /* Enable AMSDU Aggregation */ |
| 5517 | send_resp(dut, conn, SIGMA_ERROR, |
| 5518 | "ErrorCode,AMSDU aggregation not supported"); |
| 5519 | return 0; |
| 5520 | } |
| 5521 | break; |
| 5522 | } |
| 5523 | } |
| 5524 | |
| 5525 | val = get_param(cmd, "STBC_RX"); |
| 5526 | if (val) { |
| 5527 | switch (get_driver_type()) { |
| 5528 | case DRIVER_ATHEROS: |
| 5529 | ath_sta_set_stbc(dut, intf, val); |
| 5530 | break; |
Pradeep Reddy POTTETI | 4a1f6b3 | 2016-11-23 13:15:21 +0530 | [diff] [blame] | 5531 | case DRIVER_WCN: |
| 5532 | wcn_sta_set_stbc(dut, intf, val); |
| 5533 | break; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5534 | default: |
| 5535 | send_resp(dut, conn, SIGMA_ERROR, |
| 5536 | "ErrorCode,STBC_RX not supported"); |
| 5537 | return 0; |
| 5538 | } |
| 5539 | } |
| 5540 | |
| 5541 | val = get_param(cmd, "WIDTH"); |
| 5542 | if (val) { |
| 5543 | switch (get_driver_type()) { |
| 5544 | case DRIVER_WCN: |
Amarnath Hullur Subramanyam | ebfe6b6 | 2018-01-31 03:04:17 -0800 | [diff] [blame] | 5545 | if (wcn_sta_set_width(dut, intf, val) < 0) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5546 | send_resp(dut, conn, SIGMA_ERROR, |
| 5547 | "ErrorCode,Failed to set WIDTH"); |
| 5548 | return 0; |
| 5549 | } |
| 5550 | break; |
| 5551 | case DRIVER_ATHEROS: |
| 5552 | if (ath_set_width(dut, conn, intf, val) < 0) |
| 5553 | return 0; |
| 5554 | break; |
| 5555 | default: |
| 5556 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5557 | "Setting WIDTH not supported"); |
| 5558 | break; |
| 5559 | } |
| 5560 | } |
| 5561 | |
| 5562 | val = get_param(cmd, "SMPS"); |
| 5563 | if (val) { |
| 5564 | /* TODO: Dynamic/0, Static/1, No Limit/2 */ |
| 5565 | send_resp(dut, conn, SIGMA_ERROR, |
| 5566 | "ErrorCode,SMPS not supported"); |
| 5567 | return 0; |
| 5568 | } |
| 5569 | |
| 5570 | val = get_param(cmd, "TXSP_STREAM"); |
| 5571 | if (val) { |
| 5572 | switch (get_driver_type()) { |
| 5573 | case DRIVER_WCN: |
| 5574 | if (wcn_sta_set_sp_stream(dut, intf, val) < 0) { |
| 5575 | send_resp(dut, conn, SIGMA_ERROR, |
| 5576 | "ErrorCode,Failed to set TXSP_STREAM"); |
| 5577 | return 0; |
| 5578 | } |
| 5579 | break; |
| 5580 | case DRIVER_ATHEROS: |
| 5581 | ath_sta_set_txsp_stream(dut, intf, val); |
| 5582 | break; |
| 5583 | default: |
| 5584 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5585 | "Setting TXSP_STREAM not supported"); |
| 5586 | break; |
| 5587 | } |
| 5588 | } |
| 5589 | |
| 5590 | val = get_param(cmd, "RXSP_STREAM"); |
| 5591 | if (val) { |
| 5592 | switch (get_driver_type()) { |
| 5593 | case DRIVER_WCN: |
| 5594 | if (wcn_sta_set_sp_stream(dut, intf, val) < 0) { |
| 5595 | send_resp(dut, conn, SIGMA_ERROR, |
| 5596 | "ErrorCode,Failed to set RXSP_STREAM"); |
| 5597 | return 0; |
| 5598 | } |
| 5599 | break; |
| 5600 | case DRIVER_ATHEROS: |
| 5601 | ath_sta_set_rxsp_stream(dut, intf, val); |
| 5602 | break; |
| 5603 | default: |
| 5604 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5605 | "Setting RXSP_STREAM not supported"); |
| 5606 | break; |
| 5607 | } |
| 5608 | } |
| 5609 | |
| 5610 | val = get_param(cmd, "DYN_BW_SGNL"); |
| 5611 | if (val) { |
Priyadharshini Gowthaman | 818afef | 2015-11-09 13:28:15 -0800 | [diff] [blame] | 5612 | switch (get_driver_type()) { |
| 5613 | case DRIVER_WCN: |
Peng Xu | c59afd3 | 2016-11-21 15:01:11 -0800 | [diff] [blame] | 5614 | if (strcasecmp(val, "enable") == 0) { |
| 5615 | snprintf(buf, sizeof(buf), |
| 5616 | "iwpriv %s cwmenable 1", intf); |
| 5617 | if (system(buf) != 0) { |
| 5618 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5619 | "iwpriv cwmenable 1 failed"); |
| 5620 | return 0; |
| 5621 | } |
| 5622 | } else if (strcasecmp(val, "disable") == 0) { |
| 5623 | snprintf(buf, sizeof(buf), |
| 5624 | "iwpriv %s cwmenable 0", intf); |
| 5625 | if (system(buf) != 0) { |
| 5626 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5627 | "iwpriv cwmenable 0 failed"); |
| 5628 | return 0; |
| 5629 | } |
| 5630 | } else { |
| 5631 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5632 | "Unsupported DYN_BW_SGL"); |
| 5633 | } |
| 5634 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5635 | snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf); |
| 5636 | if (system(buf) != 0) { |
| 5637 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5638 | "Failed to set cts_cbw in DYN_BW_SGNL"); |
| 5639 | return 0; |
| 5640 | } |
Priyadharshini Gowthaman | 818afef | 2015-11-09 13:28:15 -0800 | [diff] [blame] | 5641 | break; |
| 5642 | case DRIVER_ATHEROS: |
Priyadharshini Gowthaman | 8c5b9a4 | 2019-07-31 14:38:48 -0700 | [diff] [blame] | 5643 | novap_reset(dut, intf, 1); |
Priyadharshini Gowthaman | 818afef | 2015-11-09 13:28:15 -0800 | [diff] [blame] | 5644 | ath_config_dyn_bw_sig(dut, intf, val); |
| 5645 | break; |
| 5646 | default: |
| 5647 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5648 | "Failed to set DYN_BW_SGNL"); |
| 5649 | break; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5650 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5651 | } |
| 5652 | |
| 5653 | val = get_param(cmd, "RTS_FORCE"); |
| 5654 | if (val) { |
Priyadharshini Gowthaman | 8c5b9a4 | 2019-07-31 14:38:48 -0700 | [diff] [blame] | 5655 | novap_reset(dut, intf, 1); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5656 | if (strcasecmp(val, "Enable") == 0) { |
Veerendranath Jakkam | adcd620 | 2019-04-17 12:32:21 +0530 | [diff] [blame] | 5657 | if (sta_set_rts(dut, intf, 64) != 0) { |
Priyadharshini Gowthaman | abdb212 | 2015-11-17 11:52:19 +0200 | [diff] [blame] | 5658 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5659 | "Failed to set RTS_FORCE 64"); |
| 5660 | } |
Jouni Malinen | 3aa7286 | 2019-05-29 23:14:51 +0300 | [diff] [blame] | 5661 | res = snprintf(buf, sizeof(buf), |
| 5662 | "wifitool %s beeliner_fw_test 100 1", |
| 5663 | intf); |
| 5664 | if (res < 0 || res >= sizeof(buf) || system(buf) != 0) { |
priyadharshini gowthaman | 270870e | 2015-12-09 10:10:23 -0800 | [diff] [blame] | 5665 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5666 | "wifitool beeliner_fw_test 100 1 failed"); |
| 5667 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5668 | } else if (strcasecmp(val, "Disable") == 0) { |
Veerendranath Jakkam | adcd620 | 2019-04-17 12:32:21 +0530 | [diff] [blame] | 5669 | if (sta_set_rts(dut, intf, 2347) != 0) { |
Priyadharshini Gowthaman | abdb212 | 2015-11-17 11:52:19 +0200 | [diff] [blame] | 5670 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5671 | "Failed to set RTS_FORCE 2347"); |
| 5672 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5673 | } else { |
| 5674 | send_resp(dut, conn, SIGMA_ERROR, |
| 5675 | "ErrorCode,RTS_FORCE value not supported"); |
| 5676 | return 0; |
| 5677 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5678 | } |
| 5679 | |
| 5680 | val = get_param(cmd, "CTS_WIDTH"); |
| 5681 | if (val) { |
| 5682 | switch (get_driver_type()) { |
| 5683 | case DRIVER_WCN: |
| 5684 | if (wcn_sta_set_cts_width(dut, intf, val) < 0) { |
| 5685 | send_resp(dut, conn, SIGMA_ERROR, |
| 5686 | "ErrorCode,Failed to set CTS_WIDTH"); |
| 5687 | return 0; |
| 5688 | } |
| 5689 | break; |
| 5690 | case DRIVER_ATHEROS: |
| 5691 | ath_set_cts_width(dut, intf, val); |
| 5692 | break; |
| 5693 | default: |
| 5694 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5695 | "Setting CTS_WIDTH not supported"); |
| 5696 | break; |
| 5697 | } |
| 5698 | } |
| 5699 | |
| 5700 | val = get_param(cmd, "BW_SGNL"); |
| 5701 | if (val) { |
| 5702 | if (strcasecmp(val, "Enable") == 0) { |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 5703 | run_iwpriv(dut, intf, "cwmenable 1"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5704 | } else if (strcasecmp(val, "Disable") == 0) { |
| 5705 | /* TODO: Disable */ |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5706 | } else { |
| 5707 | send_resp(dut, conn, SIGMA_ERROR, |
| 5708 | "ErrorCode,BW_SGNL value not supported"); |
| 5709 | return 0; |
| 5710 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5711 | } |
| 5712 | |
| 5713 | val = get_param(cmd, "Band"); |
| 5714 | if (val) { |
| 5715 | if (strcmp(val, "2.4") == 0 || strcmp(val, "5") == 0) { |
| 5716 | /* STA supports all bands by default */ |
| 5717 | } else { |
| 5718 | send_resp(dut, conn, SIGMA_ERROR, |
| 5719 | "ErrorCode,Unsupported Band"); |
| 5720 | return 0; |
| 5721 | } |
| 5722 | } |
| 5723 | |
| 5724 | val = get_param(cmd, "zero_crc"); |
| 5725 | if (val) { |
| 5726 | switch (get_driver_type()) { |
| 5727 | case DRIVER_ATHEROS: |
| 5728 | ath_set_zero_crc(dut, val); |
| 5729 | break; |
| 5730 | default: |
| 5731 | break; |
| 5732 | } |
| 5733 | } |
| 5734 | |
| 5735 | return 1; |
| 5736 | } |
| 5737 | |
| 5738 | |
Alexei Avshalom Lazar | aad97b0 | 2018-12-18 16:01:23 +0200 | [diff] [blame] | 5739 | static int sta_set_force_mcs(struct sigma_dut *dut, int force, int mcs) |
| 5740 | { |
| 5741 | switch (get_driver_type()) { |
| 5742 | #ifdef __linux__ |
| 5743 | case DRIVER_WIL6210: |
| 5744 | return wil6210_set_force_mcs(dut, force, mcs); |
| 5745 | #endif /* __linux__ */ |
| 5746 | default: |
| 5747 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5748 | "Unsupported sta_set_force_mcs with the current driver"); |
| 5749 | return -1; |
| 5750 | } |
| 5751 | } |
| 5752 | |
| 5753 | |
Alexei Avshalom Lazar | b094bf0 | 2018-12-18 16:00:53 +0200 | [diff] [blame] | 5754 | static int sta_60g_force_rsn_ie(struct sigma_dut *dut, int state) |
| 5755 | { |
| 5756 | switch (get_driver_type()) { |
| 5757 | #ifdef __linux__ |
| 5758 | case DRIVER_WIL6210: |
| 5759 | return wil6210_force_rsn_ie(dut, state); |
| 5760 | #endif /* __linux__ */ |
| 5761 | default: |
| 5762 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5763 | "Unsupported sta_60g_force_rsn_ie with the current driver"); |
| 5764 | return -1; |
| 5765 | } |
| 5766 | } |
| 5767 | |
| 5768 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5769 | static int sta_set_60g_common(struct sigma_dut *dut, struct sigma_conn *conn, |
| 5770 | struct sigma_cmd *cmd) |
| 5771 | { |
| 5772 | const char *val; |
| 5773 | char buf[100]; |
| 5774 | |
| 5775 | val = get_param(cmd, "MSDUSize"); |
| 5776 | if (val) { |
| 5777 | int mtu; |
| 5778 | |
| 5779 | dut->amsdu_size = atoi(val); |
| 5780 | if (dut->amsdu_size > IEEE80211_MAX_DATA_LEN_DMG || |
| 5781 | dut->amsdu_size < IEEE80211_SNAP_LEN_DMG) { |
| 5782 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5783 | "MSDUSize %d is above max %d or below min %d", |
| 5784 | dut->amsdu_size, |
| 5785 | IEEE80211_MAX_DATA_LEN_DMG, |
| 5786 | IEEE80211_SNAP_LEN_DMG); |
| 5787 | dut->amsdu_size = 0; |
Jouni Malinen | 0e29cf2 | 2019-02-19 01:13:21 +0200 | [diff] [blame] | 5788 | return ERROR_SEND_STATUS; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5789 | } |
| 5790 | |
| 5791 | mtu = dut->amsdu_size - IEEE80211_SNAP_LEN_DMG; |
| 5792 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 5793 | "Setting amsdu_size to %d", mtu); |
| 5794 | snprintf(buf, sizeof(buf), "ifconfig %s mtu %d", |
| 5795 | get_station_ifname(), mtu); |
| 5796 | |
| 5797 | if (system(buf) != 0) { |
| 5798 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s", |
| 5799 | buf); |
Jouni Malinen | 0e29cf2 | 2019-02-19 01:13:21 +0200 | [diff] [blame] | 5800 | return ERROR_SEND_STATUS; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5801 | } |
| 5802 | } |
| 5803 | |
| 5804 | val = get_param(cmd, "BAckRcvBuf"); |
| 5805 | if (val) { |
| 5806 | dut->back_rcv_buf = atoi(val); |
| 5807 | if (dut->back_rcv_buf == 0) { |
| 5808 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5809 | "Failed to convert %s or value is 0", |
| 5810 | val); |
Jouni Malinen | 0e29cf2 | 2019-02-19 01:13:21 +0200 | [diff] [blame] | 5811 | return ERROR_SEND_STATUS; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5812 | } |
| 5813 | |
| 5814 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 5815 | "Setting BAckRcvBuf to %s", val); |
| 5816 | } |
| 5817 | |
Alexei Avshalom Lazar | aad97b0 | 2018-12-18 16:01:23 +0200 | [diff] [blame] | 5818 | val = get_param(cmd, "MCS_FixedRate"); |
| 5819 | if (val) { |
| 5820 | if (sta_set_force_mcs(dut, 1, atoi(val))) { |
| 5821 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5822 | "Failed to force MCS"); |
Jouni Malinen | 0e29cf2 | 2019-02-19 01:13:21 +0200 | [diff] [blame] | 5823 | return ERROR_SEND_STATUS; |
Alexei Avshalom Lazar | aad97b0 | 2018-12-18 16:01:23 +0200 | [diff] [blame] | 5824 | } |
| 5825 | } |
| 5826 | |
Jouni Malinen | 0e29cf2 | 2019-02-19 01:13:21 +0200 | [diff] [blame] | 5827 | return SUCCESS_SEND_STATUS; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5828 | } |
| 5829 | |
| 5830 | |
| 5831 | static int sta_pcp_start(struct sigma_dut *dut, struct sigma_conn *conn, |
| 5832 | struct sigma_cmd *cmd) |
| 5833 | { |
| 5834 | int net_id; |
| 5835 | char *ifname; |
| 5836 | const char *val; |
| 5837 | char buf[100]; |
| 5838 | |
| 5839 | dut->mode = SIGMA_MODE_STATION; |
| 5840 | ifname = get_main_ifname(); |
| 5841 | if (wpa_command(ifname, "PING") != 0) { |
| 5842 | sigma_dut_print(dut, DUT_MSG_ERROR, "Supplicant not running"); |
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 | |
| 5846 | wpa_command(ifname, "FLUSH"); |
| 5847 | net_id = add_network_common(dut, conn, ifname, cmd); |
| 5848 | if (net_id < 0) { |
| 5849 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add network"); |
| 5850 | return net_id; |
| 5851 | } |
| 5852 | |
| 5853 | /* TODO: mode=2 for the AP; in the future, replace for mode PCP */ |
| 5854 | if (set_network(ifname, net_id, "mode", "2") < 0) { |
| 5855 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5856 | "Failed to set supplicant network mode"); |
Jouni Malinen | 0e29cf2 | 2019-02-19 01:13:21 +0200 | [diff] [blame] | 5857 | return ERROR_SEND_STATUS; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5858 | } |
| 5859 | |
Alexei Avshalom Lazar | d596b51 | 2018-12-18 16:00:59 +0200 | [diff] [blame] | 5860 | if (set_network(ifname, net_id, "pbss", "1") < 0) |
| 5861 | return -2; |
| 5862 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5863 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
Alexei Avshalom Lazar | fd9f135 | 2018-11-13 14:07:58 +0200 | [diff] [blame] | 5864 | "Supplicant set network with mode 2. network_id %d", |
| 5865 | net_id); |
| 5866 | |
| 5867 | if (set_network(ifname, net_id, "wps_disabled", "0") < 0) { |
| 5868 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 5869 | "Failed to set supplicant to WPS ENABLE"); |
Jouni Malinen | 0e29cf2 | 2019-02-19 01:13:21 +0200 | [diff] [blame] | 5870 | return ERROR_SEND_STATUS; |
Alexei Avshalom Lazar | fd9f135 | 2018-11-13 14:07:58 +0200 | [diff] [blame] | 5871 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5872 | |
| 5873 | val = get_param(cmd, "Security"); |
| 5874 | if (val && strcasecmp(val, "OPEN") == 0) { |
| 5875 | dut->ap_key_mgmt = AP_OPEN; |
| 5876 | if (set_network(ifname, net_id, "key_mgmt", "NONE") < 0) { |
| 5877 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5878 | "Failed to set supplicant to %s security", |
| 5879 | val); |
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 && strcasecmp(val, "WPA2-PSK") == 0) { |
| 5883 | dut->ap_key_mgmt = AP_WPA2_PSK; |
| 5884 | if (set_network(ifname, net_id, "key_mgmt", "WPA-PSK") < 0) { |
| 5885 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5886 | "Failed to set supplicant to %s security", |
| 5887 | val); |
Jouni Malinen | 0e29cf2 | 2019-02-19 01:13:21 +0200 | [diff] [blame] | 5888 | return ERROR_SEND_STATUS; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5889 | } |
| 5890 | |
| 5891 | if (set_network(ifname, net_id, "proto", "RSN") < 0) { |
| 5892 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5893 | "Failed to set supplicant to proto RSN"); |
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 | } else if (val) { |
| 5897 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5898 | "Requested Security %s is not supported on 60GHz", |
| 5899 | val); |
Jouni Malinen | 0e29cf2 | 2019-02-19 01:13:21 +0200 | [diff] [blame] | 5900 | return INVALID_SEND_STATUS; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5901 | } |
| 5902 | |
| 5903 | val = get_param(cmd, "Encrypt"); |
| 5904 | if (val && strcasecmp(val, "AES-GCMP") == 0) { |
| 5905 | if (set_network(ifname, net_id, "pairwise", "GCMP") < 0) { |
| 5906 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5907 | "Failed to set supplicant to pairwise GCMP"); |
Jouni Malinen | 0e29cf2 | 2019-02-19 01:13:21 +0200 | [diff] [blame] | 5908 | return ERROR_SEND_STATUS; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5909 | } |
| 5910 | if (set_network(ifname, net_id, "group", "GCMP") < 0) { |
| 5911 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5912 | "Failed to set supplicant to group GCMP"); |
Jouni Malinen | 0e29cf2 | 2019-02-19 01:13:21 +0200 | [diff] [blame] | 5913 | return ERROR_SEND_STATUS; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5914 | } |
| 5915 | } else if (val) { |
| 5916 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5917 | "Requested Encrypt %s is not supported on 60 GHz", |
| 5918 | val); |
Jouni Malinen | 0e29cf2 | 2019-02-19 01:13:21 +0200 | [diff] [blame] | 5919 | return INVALID_SEND_STATUS; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5920 | } |
| 5921 | |
| 5922 | val = get_param(cmd, "PSK"); |
| 5923 | if (val && set_network_quoted(ifname, net_id, "psk", val) < 0) { |
| 5924 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set psk %s", |
| 5925 | val); |
Jouni Malinen | 0e29cf2 | 2019-02-19 01:13:21 +0200 | [diff] [blame] | 5926 | return ERROR_SEND_STATUS; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5927 | } |
| 5928 | |
| 5929 | /* Convert 60G channel to freq */ |
| 5930 | switch (dut->ap_channel) { |
| 5931 | case 1: |
| 5932 | val = "58320"; |
| 5933 | break; |
| 5934 | case 2: |
| 5935 | val = "60480"; |
| 5936 | break; |
| 5937 | case 3: |
| 5938 | val = "62640"; |
| 5939 | break; |
| 5940 | default: |
| 5941 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5942 | "Failed to configure channel %d. Not supported", |
| 5943 | dut->ap_channel); |
Jouni Malinen | 0e29cf2 | 2019-02-19 01:13:21 +0200 | [diff] [blame] | 5944 | return ERROR_SEND_STATUS; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5945 | } |
| 5946 | |
| 5947 | if (set_network(ifname, net_id, "frequency", val) < 0) { |
| 5948 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5949 | "Failed to set supplicant network frequency"); |
Jouni Malinen | 0e29cf2 | 2019-02-19 01:13:21 +0200 | [diff] [blame] | 5950 | return ERROR_SEND_STATUS; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5951 | } |
| 5952 | |
Alexei Avshalom Lazar | 2eccf4d | 2019-01-31 10:03:59 +0200 | [diff] [blame] | 5953 | if (dut->eap_fragment) { |
| 5954 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 5955 | "Set EAP fragment size to 128 bytes."); |
| 5956 | if (set_network(ifname, net_id, "fragment_size", "128") < 0) |
| 5957 | return ERROR_SEND_STATUS; |
| 5958 | } |
| 5959 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5960 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 5961 | "Supplicant set network with frequency"); |
| 5962 | |
| 5963 | snprintf(buf, sizeof(buf), "SELECT_NETWORK %d", net_id); |
| 5964 | if (wpa_command(ifname, buf) < 0) { |
| 5965 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 5966 | "Failed to select network id %d on %s", |
| 5967 | net_id, ifname); |
Jouni Malinen | 0e29cf2 | 2019-02-19 01:13:21 +0200 | [diff] [blame] | 5968 | return ERROR_SEND_STATUS; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5969 | } |
| 5970 | |
| 5971 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Selected network"); |
| 5972 | |
Jouni Malinen | 0e29cf2 | 2019-02-19 01:13:21 +0200 | [diff] [blame] | 5973 | return SUCCESS_SEND_STATUS; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5974 | } |
| 5975 | |
| 5976 | |
Lior David | 67543f5 | 2017-01-03 19:04:22 +0200 | [diff] [blame] | 5977 | static int wil6210_set_abft_len(struct sigma_dut *dut, int abft_len) |
| 5978 | { |
| 5979 | char buf[128], fname[128]; |
| 5980 | FILE *f; |
Jouni Malinen | 3aa7286 | 2019-05-29 23:14:51 +0300 | [diff] [blame] | 5981 | int res; |
Lior David | 67543f5 | 2017-01-03 19:04:22 +0200 | [diff] [blame] | 5982 | |
| 5983 | if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) { |
| 5984 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5985 | "failed to get wil6210 debugfs dir"); |
| 5986 | return -1; |
| 5987 | } |
| 5988 | |
Jouni Malinen | 3aa7286 | 2019-05-29 23:14:51 +0300 | [diff] [blame] | 5989 | res = snprintf(fname, sizeof(fname), "%s/abft_len", buf); |
| 5990 | if (res < 0 || res >= sizeof(fname)) |
| 5991 | return -1; |
Lior David | 67543f5 | 2017-01-03 19:04:22 +0200 | [diff] [blame] | 5992 | f = fopen(fname, "w"); |
| 5993 | if (!f) { |
| 5994 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 5995 | "failed to open: %s", fname); |
| 5996 | return -1; |
| 5997 | } |
| 5998 | |
| 5999 | fprintf(f, "%d\n", abft_len); |
| 6000 | fclose(f); |
| 6001 | |
| 6002 | return 0; |
| 6003 | } |
| 6004 | |
| 6005 | |
Alexei Avshalom Lazar | 49498b8 | 2019-01-31 15:16:32 +0200 | [diff] [blame] | 6006 | int sta_set_60g_abft_len(struct sigma_dut *dut, struct sigma_conn *conn, |
| 6007 | int abft_len) |
Lior David | 67543f5 | 2017-01-03 19:04:22 +0200 | [diff] [blame] | 6008 | { |
| 6009 | switch (get_driver_type()) { |
| 6010 | case DRIVER_WIL6210: |
| 6011 | return wil6210_set_abft_len(dut, abft_len); |
| 6012 | default: |
| 6013 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6014 | "set abft_len not supported"); |
| 6015 | return -1; |
| 6016 | } |
| 6017 | } |
| 6018 | |
| 6019 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6020 | static int sta_set_60g_pcp(struct sigma_dut *dut, struct sigma_conn *conn, |
| 6021 | struct sigma_cmd *cmd) |
| 6022 | { |
| 6023 | const char *val; |
Lior David | 67543f5 | 2017-01-03 19:04:22 +0200 | [diff] [blame] | 6024 | unsigned int abft_len = 1; /* default is one slot */ |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6025 | |
| 6026 | if (dut->dev_role != DEVROLE_PCP) { |
| 6027 | send_resp(dut, conn, SIGMA_INVALID, |
| 6028 | "ErrorCode,Invalid DevRole"); |
| 6029 | return 0; |
| 6030 | } |
| 6031 | |
| 6032 | val = get_param(cmd, "SSID"); |
| 6033 | if (val) { |
| 6034 | if (strlen(val) > sizeof(dut->ap_ssid) - 1) { |
| 6035 | send_resp(dut, conn, SIGMA_INVALID, |
| 6036 | "ErrorCode,Invalid SSID"); |
| 6037 | return -1; |
| 6038 | } |
| 6039 | |
Peng Xu | b8fc5cc | 2017-05-10 17:27:28 -0700 | [diff] [blame] | 6040 | strlcpy(dut->ap_ssid, val, sizeof(dut->ap_ssid)); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6041 | } |
| 6042 | |
| 6043 | val = get_param(cmd, "CHANNEL"); |
| 6044 | if (val) { |
| 6045 | const char *pos; |
| 6046 | |
| 6047 | dut->ap_channel = atoi(val); |
| 6048 | pos = strchr(val, ';'); |
| 6049 | if (pos) { |
| 6050 | pos++; |
| 6051 | dut->ap_channel_1 = atoi(pos); |
| 6052 | } |
| 6053 | } |
| 6054 | |
| 6055 | switch (dut->ap_channel) { |
| 6056 | case 1: |
| 6057 | case 2: |
| 6058 | case 3: |
| 6059 | break; |
| 6060 | default: |
| 6061 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6062 | "Channel %d is not supported", dut->ap_channel); |
| 6063 | send_resp(dut, conn, SIGMA_ERROR, |
| 6064 | "Requested channel is not supported"); |
| 6065 | return -1; |
| 6066 | } |
| 6067 | |
| 6068 | val = get_param(cmd, "BCNINT"); |
| 6069 | if (val) |
| 6070 | dut->ap_bcnint = atoi(val); |
| 6071 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6072 | val = get_param(cmd, "AllocType"); |
| 6073 | if (val) { |
| 6074 | send_resp(dut, conn, SIGMA_ERROR, |
| 6075 | "ErrorCode,AllocType is not supported yet"); |
| 6076 | return -1; |
| 6077 | } |
| 6078 | |
| 6079 | val = get_param(cmd, "PercentBI"); |
| 6080 | if (val) { |
| 6081 | send_resp(dut, conn, SIGMA_ERROR, |
| 6082 | "ErrorCode,PercentBI is not supported yet"); |
| 6083 | return -1; |
| 6084 | } |
| 6085 | |
| 6086 | val = get_param(cmd, "CBAPOnly"); |
| 6087 | if (val) { |
| 6088 | send_resp(dut, conn, SIGMA_ERROR, |
| 6089 | "ErrorCode,CBAPOnly is not supported yet"); |
| 6090 | return -1; |
| 6091 | } |
| 6092 | |
| 6093 | val = get_param(cmd, "AMPDU"); |
| 6094 | if (val) { |
| 6095 | if (strcasecmp(val, "Enable") == 0) |
| 6096 | dut->ap_ampdu = 1; |
| 6097 | else if (strcasecmp(val, "Disable") == 0) |
| 6098 | dut->ap_ampdu = 2; |
| 6099 | else { |
| 6100 | send_resp(dut, conn, SIGMA_ERROR, |
| 6101 | "ErrorCode,AMPDU value is not Enable nor Disabled"); |
| 6102 | return -1; |
| 6103 | } |
| 6104 | } |
| 6105 | |
| 6106 | val = get_param(cmd, "AMSDU"); |
| 6107 | if (val) { |
| 6108 | if (strcasecmp(val, "Enable") == 0) |
| 6109 | dut->ap_amsdu = 1; |
| 6110 | else if (strcasecmp(val, "Disable") == 0) |
| 6111 | dut->ap_amsdu = 2; |
| 6112 | } |
| 6113 | |
| 6114 | val = get_param(cmd, "NumMSDU"); |
| 6115 | if (val) { |
| 6116 | send_resp(dut, conn, SIGMA_ERROR, |
| 6117 | "ErrorCode, NumMSDU is not supported yet"); |
| 6118 | return -1; |
| 6119 | } |
| 6120 | |
| 6121 | val = get_param(cmd, "ABFTLRang"); |
| 6122 | if (val) { |
| 6123 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
Lior David | 67543f5 | 2017-01-03 19:04:22 +0200 | [diff] [blame] | 6124 | "ABFTLRang parameter %s", val); |
| 6125 | if (strcmp(val, "Gt1") == 0) |
| 6126 | abft_len = 2; /* 2 slots in this case */ |
| 6127 | } |
| 6128 | |
| 6129 | if (sta_set_60g_abft_len(dut, conn, abft_len)) { |
| 6130 | send_resp(dut, conn, SIGMA_ERROR, |
| 6131 | "ErrorCode, Can't set ABFT length"); |
| 6132 | return -1; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6133 | } |
| 6134 | |
| 6135 | if (sta_pcp_start(dut, conn, cmd) < 0) { |
| 6136 | send_resp(dut, conn, SIGMA_ERROR, |
| 6137 | "ErrorCode, Can't start PCP role"); |
| 6138 | return -1; |
| 6139 | } |
| 6140 | |
| 6141 | return sta_set_60g_common(dut, conn, cmd); |
| 6142 | } |
| 6143 | |
| 6144 | |
| 6145 | static int sta_set_60g_sta(struct sigma_dut *dut, struct sigma_conn *conn, |
| 6146 | struct sigma_cmd *cmd) |
| 6147 | { |
| 6148 | const char *val = get_param(cmd, "DiscoveryMode"); |
| 6149 | |
| 6150 | if (dut->dev_role != DEVROLE_STA) { |
| 6151 | send_resp(dut, conn, SIGMA_INVALID, |
| 6152 | "ErrorCode,Invalid DevRole"); |
| 6153 | return 0; |
| 6154 | } |
| 6155 | |
| 6156 | if (val) { |
| 6157 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Discovery: %s", val); |
| 6158 | /* Ignore Discovery mode till Driver expose API. */ |
| 6159 | #if 0 |
| 6160 | if (strcasecmp(val, "1") == 0) { |
| 6161 | send_resp(dut, conn, SIGMA_INVALID, |
| 6162 | "ErrorCode,DiscoveryMode 1 not supported"); |
| 6163 | return 0; |
| 6164 | } |
| 6165 | |
| 6166 | if (strcasecmp(val, "0") == 0) { |
| 6167 | /* OK */ |
| 6168 | } else { |
| 6169 | send_resp(dut, conn, SIGMA_INVALID, |
| 6170 | "ErrorCode,DiscoveryMode not supported"); |
| 6171 | return 0; |
| 6172 | } |
| 6173 | #endif |
| 6174 | } |
| 6175 | |
| 6176 | if (start_sta_mode(dut) != 0) |
Jouni Malinen | 0e29cf2 | 2019-02-19 01:13:21 +0200 | [diff] [blame] | 6177 | return ERROR_SEND_STATUS; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6178 | return sta_set_60g_common(dut, conn, cmd); |
| 6179 | } |
| 6180 | |
| 6181 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 6182 | static enum sigma_cmd_result cmd_sta_disconnect(struct sigma_dut *dut, |
| 6183 | struct sigma_conn *conn, |
| 6184 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6185 | { |
| 6186 | const char *intf = get_param(cmd, "Interface"); |
Jouni Malinen | ed77e67 | 2018-01-10 16:45:13 +0200 | [diff] [blame] | 6187 | const char *val = get_param(cmd, "maintain_profile"); |
vamsi krishna | d605c42 | 2017-09-20 14:56:31 +0530 | [diff] [blame] | 6188 | |
Jouni Malinen | ed77e67 | 2018-01-10 16:45:13 +0200 | [diff] [blame] | 6189 | if (dut->program == PROGRAM_OCE || |
Amarnath Hullur Subramanyam | ebeda9e | 2018-01-31 03:21:48 -0800 | [diff] [blame] | 6190 | dut->program == PROGRAM_HE || |
Jouni Malinen | ed77e67 | 2018-01-10 16:45:13 +0200 | [diff] [blame] | 6191 | (val && atoi(val) == 1)) { |
vamsi krishna | d605c42 | 2017-09-20 14:56:31 +0530 | [diff] [blame] | 6192 | wpa_command(intf, "DISCONNECT"); |
| 6193 | return 1; |
| 6194 | } |
| 6195 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6196 | disconnect_station(dut); |
| 6197 | /* Try to ignore old scan results to avoid HS 2.0R2 test case failures |
| 6198 | * due to cached results. */ |
| 6199 | wpa_command(intf, "SET ignore_old_scan_res 1"); |
| 6200 | wpa_command(intf, "BSS_FLUSH"); |
| 6201 | return 1; |
| 6202 | } |
| 6203 | |
| 6204 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 6205 | static enum sigma_cmd_result cmd_sta_reassoc(struct sigma_dut *dut, |
| 6206 | struct sigma_conn *conn, |
| 6207 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6208 | { |
| 6209 | const char *intf = get_param(cmd, "Interface"); |
| 6210 | const char *bssid = get_param(cmd, "bssid"); |
| 6211 | const char *val = get_param(cmd, "CHANNEL"); |
| 6212 | struct wpa_ctrl *ctrl; |
Srinivas Dasari | 0ebedb1 | 2018-02-14 17:03:51 +0530 | [diff] [blame] | 6213 | char buf[1000]; |
Sunil Dutt | d30ce09 | 2018-01-11 23:56:29 +0530 | [diff] [blame] | 6214 | char result[32]; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6215 | int res; |
| 6216 | int chan = 0; |
Jouni Malinen | 6a7c9b4 | 2019-08-20 00:15:59 +0300 | [diff] [blame] | 6217 | enum sigma_cmd_result status = STATUS_SENT; |
Sunil Dutt | d30ce09 | 2018-01-11 23:56:29 +0530 | [diff] [blame] | 6218 | int fastreassoc = 1; |
Jouni Malinen | 6a7c9b4 | 2019-08-20 00:15:59 +0300 | [diff] [blame] | 6219 | int ft_ds = 0; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6220 | |
| 6221 | if (bssid == NULL) { |
| 6222 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing bssid " |
| 6223 | "argument"); |
Jouni Malinen | 6a7c9b4 | 2019-08-20 00:15:59 +0300 | [diff] [blame] | 6224 | return STATUS_SENT_ERROR; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6225 | } |
| 6226 | |
| 6227 | if (val) |
| 6228 | chan = atoi(val); |
| 6229 | |
| 6230 | if (wifi_chip_type != DRIVER_WCN && wifi_chip_type != DRIVER_AR6003) { |
| 6231 | /* The current network may be from sta_associate or |
| 6232 | * sta_hs2_associate |
| 6233 | */ |
| 6234 | if (set_network(intf, dut->infra_network_id, "bssid", bssid) < |
| 6235 | 0 || |
| 6236 | set_network(intf, 0, "bssid", bssid) < 0) |
Jouni Malinen | 6a7c9b4 | 2019-08-20 00:15:59 +0300 | [diff] [blame] | 6237 | return ERROR_SEND_STATUS; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6238 | } |
| 6239 | |
| 6240 | ctrl = open_wpa_mon(intf); |
| 6241 | if (ctrl == NULL) { |
| 6242 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open " |
| 6243 | "wpa_supplicant monitor connection"); |
Jouni Malinen | 6a7c9b4 | 2019-08-20 00:15:59 +0300 | [diff] [blame] | 6244 | return ERROR_SEND_STATUS; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6245 | } |
| 6246 | |
Sunil Dutt | d30ce09 | 2018-01-11 23:56:29 +0530 | [diff] [blame] | 6247 | if (get_wpa_status(get_station_ifname(), "wpa_state", result, |
| 6248 | sizeof(result)) < 0 || |
| 6249 | strncmp(result, "COMPLETED", 9) != 0) { |
| 6250 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 6251 | "sta_reassoc: Not connected"); |
| 6252 | fastreassoc = 0; |
Jouni Malinen | 6a7c9b4 | 2019-08-20 00:15:59 +0300 | [diff] [blame] | 6253 | } else if (dut->sta_ft_ds) { |
| 6254 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 6255 | "sta_reassoc: Use FT-over-DS"); |
| 6256 | ft_ds = 1; |
Sunil Dutt | d30ce09 | 2018-01-11 23:56:29 +0530 | [diff] [blame] | 6257 | } |
| 6258 | |
Srinivas Dasari | 0ebedb1 | 2018-02-14 17:03:51 +0530 | [diff] [blame] | 6259 | if (dut->rsne_override) { |
| 6260 | #ifdef NL80211_SUPPORT |
| 6261 | if (get_driver_type() == DRIVER_WCN && dut->config_rsnie == 0) { |
| 6262 | sta_config_rsnie(dut, 1); |
| 6263 | dut->config_rsnie = 1; |
| 6264 | } |
| 6265 | #endif /* NL80211_SUPPORT */ |
| 6266 | snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s", |
| 6267 | dut->rsne_override); |
| 6268 | if (wpa_command(intf, buf) < 0) { |
| 6269 | send_resp(dut, conn, SIGMA_ERROR, |
| 6270 | "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override"); |
| 6271 | return 0; |
| 6272 | } |
| 6273 | } |
| 6274 | |
Jouni Malinen | 6a7c9b4 | 2019-08-20 00:15:59 +0300 | [diff] [blame] | 6275 | if (ft_ds) { |
| 6276 | if (chan) { |
| 6277 | unsigned int freq; |
| 6278 | |
| 6279 | freq = channel_to_freq(dut, chan); |
| 6280 | if (!freq) { |
| 6281 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6282 | "Invalid channel number provided: %d", |
| 6283 | chan); |
| 6284 | send_resp(dut, conn, SIGMA_INVALID, |
| 6285 | "ErrorCode,Invalid channel number"); |
| 6286 | goto close_mon_conn; |
| 6287 | } |
| 6288 | res = snprintf(buf, sizeof(buf), |
| 6289 | "SCAN TYPE=ONLY freq=%d", freq); |
| 6290 | } else { |
| 6291 | res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY"); |
| 6292 | } |
| 6293 | if (res < 0 || res >= (int) sizeof(buf)) { |
| 6294 | send_resp(dut, conn, SIGMA_ERROR, |
| 6295 | "ErrorCode,snprintf failed"); |
| 6296 | goto close_mon_conn; |
| 6297 | } |
| 6298 | if (wpa_command(intf, buf) < 0) { |
| 6299 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 6300 | "Failed to start scan"); |
| 6301 | send_resp(dut, conn, SIGMA_ERROR, |
| 6302 | "ErrorCode,scan failed"); |
| 6303 | goto close_mon_conn; |
| 6304 | } |
| 6305 | |
| 6306 | res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS", |
| 6307 | buf, sizeof(buf)); |
| 6308 | if (res < 0) { |
| 6309 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 6310 | "Scan did not complete"); |
| 6311 | send_resp(dut, conn, SIGMA_ERROR, |
| 6312 | "ErrorCode,scan did not complete"); |
| 6313 | goto close_mon_conn; |
| 6314 | } |
| 6315 | |
| 6316 | res = snprintf(buf, sizeof(buf), "FT_DS %s", bssid); |
| 6317 | if (res > 0 && res < (int) sizeof(buf)) |
| 6318 | res = wpa_command(intf, buf); |
| 6319 | |
| 6320 | if (res < 0 || res >= (int) sizeof(buf)) { |
| 6321 | send_resp(dut, conn, SIGMA_ERROR, |
| 6322 | "errorCode,FT_DS command failed"); |
| 6323 | status = STATUS_SENT_ERROR; |
| 6324 | goto close_mon_conn; |
| 6325 | } |
| 6326 | } else if (wifi_chip_type == DRIVER_WCN && fastreassoc) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6327 | #ifdef ANDROID |
Ashwini Patil | 4c8158f | 2017-05-25 12:49:21 +0530 | [diff] [blame] | 6328 | if (chan) { |
| 6329 | unsigned int freq; |
| 6330 | |
Alexei Avshalom Lazar | 093569f | 2018-11-13 14:08:17 +0200 | [diff] [blame] | 6331 | freq = channel_to_freq(dut, chan); |
Ashwini Patil | 4c8158f | 2017-05-25 12:49:21 +0530 | [diff] [blame] | 6332 | if (!freq) { |
| 6333 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6334 | "Invalid channel number provided: %d", |
| 6335 | chan); |
| 6336 | send_resp(dut, conn, SIGMA_INVALID, |
| 6337 | "ErrorCode,Invalid channel number"); |
| 6338 | goto close_mon_conn; |
| 6339 | } |
| 6340 | res = snprintf(buf, sizeof(buf), |
| 6341 | "SCAN TYPE=ONLY freq=%d", freq); |
| 6342 | } else { |
| 6343 | res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY"); |
| 6344 | } |
| 6345 | if (res < 0 || res >= (int) sizeof(buf)) { |
| 6346 | send_resp(dut, conn, SIGMA_ERROR, |
| 6347 | "ErrorCode,snprintf failed"); |
| 6348 | goto close_mon_conn; |
| 6349 | } |
| 6350 | if (wpa_command(intf, buf) < 0) { |
| 6351 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 6352 | "Failed to start scan"); |
| 6353 | send_resp(dut, conn, SIGMA_ERROR, |
| 6354 | "ErrorCode,scan failed"); |
| 6355 | goto close_mon_conn; |
| 6356 | } |
| 6357 | |
| 6358 | res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS", |
| 6359 | buf, sizeof(buf)); |
| 6360 | if (res < 0) { |
| 6361 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 6362 | "Scan did not complete"); |
| 6363 | send_resp(dut, conn, SIGMA_ERROR, |
| 6364 | "ErrorCode,scan did not complete"); |
| 6365 | goto close_mon_conn; |
| 6366 | } |
| 6367 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6368 | if (set_network(intf, dut->infra_network_id, "bssid", "any") |
| 6369 | < 0) { |
| 6370 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set " |
| 6371 | "bssid to any during FASTREASSOC"); |
Jouni Malinen | 6a7c9b4 | 2019-08-20 00:15:59 +0300 | [diff] [blame] | 6372 | status = ERROR_SEND_STATUS; |
Ashwini Patil | 467efef | 2017-05-25 12:18:27 +0530 | [diff] [blame] | 6373 | goto close_mon_conn; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6374 | } |
| 6375 | res = snprintf(buf, sizeof(buf), "DRIVER FASTREASSOC %s %d", |
| 6376 | bssid, chan); |
| 6377 | if (res > 0 && res < (int) sizeof(buf)) |
| 6378 | res = wpa_command(intf, buf); |
| 6379 | |
| 6380 | if (res < 0 || res >= (int) sizeof(buf)) { |
| 6381 | send_resp(dut, conn, SIGMA_ERROR, |
| 6382 | "errorCode,Failed to run DRIVER FASTREASSOC"); |
Ashwini Patil | 467efef | 2017-05-25 12:18:27 +0530 | [diff] [blame] | 6383 | goto close_mon_conn; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6384 | } |
| 6385 | #else /* ANDROID */ |
| 6386 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 6387 | "Reassoc using iwpriv - skip chan=%d info", |
| 6388 | chan); |
| 6389 | snprintf(buf, sizeof(buf), "iwpriv %s reassoc", intf); |
| 6390 | if (system(buf) != 0) { |
| 6391 | sigma_dut_print(dut, DUT_MSG_ERROR, "%s failed", buf); |
Jouni Malinen | 6a7c9b4 | 2019-08-20 00:15:59 +0300 | [diff] [blame] | 6392 | status = ERROR_SEND_STATUS; |
Ashwini Patil | 467efef | 2017-05-25 12:18:27 +0530 | [diff] [blame] | 6393 | goto close_mon_conn; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6394 | } |
| 6395 | #endif /* ANDROID */ |
| 6396 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 6397 | "sta_reassoc: Run %s successful", buf); |
| 6398 | } else if (wpa_command(intf, "REASSOCIATE")) { |
| 6399 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to " |
| 6400 | "request reassociation"); |
Ashwini Patil | 467efef | 2017-05-25 12:18:27 +0530 | [diff] [blame] | 6401 | goto close_mon_conn; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6402 | } |
| 6403 | |
| 6404 | res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED", |
| 6405 | buf, sizeof(buf)); |
Ashwini Patil | 467efef | 2017-05-25 12:18:27 +0530 | [diff] [blame] | 6406 | if (res < 0) { |
Jouni Malinen | 6a7c9b4 | 2019-08-20 00:15:59 +0300 | [diff] [blame] | 6407 | send_resp(dut, conn, SIGMA_ERROR, |
| 6408 | "errorCode,Connection did not complete"); |
| 6409 | status = STATUS_SENT_ERROR; |
Ashwini Patil | 467efef | 2017-05-25 12:18:27 +0530 | [diff] [blame] | 6410 | goto close_mon_conn; |
| 6411 | } |
Jouni Malinen | 6a7c9b4 | 2019-08-20 00:15:59 +0300 | [diff] [blame] | 6412 | status = SUCCESS_SEND_STATUS; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6413 | |
Ashwini Patil | 467efef | 2017-05-25 12:18:27 +0530 | [diff] [blame] | 6414 | close_mon_conn: |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6415 | wpa_ctrl_detach(ctrl); |
| 6416 | wpa_ctrl_close(ctrl); |
Ashwini Patil | 467efef | 2017-05-25 12:18:27 +0530 | [diff] [blame] | 6417 | return status; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6418 | } |
| 6419 | |
| 6420 | |
| 6421 | static void hs2_clear_credentials(const char *intf) |
| 6422 | { |
| 6423 | wpa_command(intf, "REMOVE_CRED all"); |
| 6424 | } |
| 6425 | |
| 6426 | |
Lior David | cc88b56 | 2017-01-03 18:52:09 +0200 | [diff] [blame] | 6427 | #ifdef __linux__ |
| 6428 | static int wil6210_get_aid(struct sigma_dut *dut, const char *bssid, |
| 6429 | unsigned int *aid) |
| 6430 | { |
Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 6431 | const char *pattern = "AID[ \t]+([0-9]+)"; |
Lior David | cc88b56 | 2017-01-03 18:52:09 +0200 | [diff] [blame] | 6432 | |
Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 6433 | return wil6210_get_sta_info_field(dut, bssid, pattern, aid); |
Lior David | cc88b56 | 2017-01-03 18:52:09 +0200 | [diff] [blame] | 6434 | } |
| 6435 | #endif /* __linux__ */ |
| 6436 | |
| 6437 | |
| 6438 | static int sta_get_aid_60g(struct sigma_dut *dut, const char *bssid, |
| 6439 | unsigned int *aid) |
| 6440 | { |
| 6441 | switch (get_driver_type()) { |
| 6442 | #ifdef __linux__ |
| 6443 | case DRIVER_WIL6210: |
| 6444 | return wil6210_get_aid(dut, bssid, aid); |
| 6445 | #endif /* __linux__ */ |
| 6446 | default: |
| 6447 | sigma_dut_print(dut, DUT_MSG_ERROR, "get AID not supported"); |
| 6448 | return -1; |
| 6449 | } |
| 6450 | } |
| 6451 | |
| 6452 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6453 | static int sta_get_parameter_60g(struct sigma_dut *dut, struct sigma_conn *conn, |
| 6454 | struct sigma_cmd *cmd) |
| 6455 | { |
| 6456 | char buf[MAX_CMD_LEN]; |
| 6457 | char bss_list[MAX_CMD_LEN]; |
| 6458 | const char *parameter = get_param(cmd, "Parameter"); |
| 6459 | |
| 6460 | if (parameter == NULL) |
| 6461 | return -1; |
| 6462 | |
Lior David | cc88b56 | 2017-01-03 18:52:09 +0200 | [diff] [blame] | 6463 | if (strcasecmp(parameter, "AID") == 0) { |
| 6464 | unsigned int aid = 0; |
| 6465 | char bssid[20]; |
| 6466 | |
| 6467 | if (get_wpa_status(get_station_ifname(), "bssid", |
| 6468 | bssid, sizeof(bssid)) < 0) { |
| 6469 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6470 | "could not get bssid"); |
| 6471 | return -2; |
| 6472 | } |
| 6473 | |
| 6474 | if (sta_get_aid_60g(dut, bssid, &aid)) |
| 6475 | return -2; |
| 6476 | |
| 6477 | snprintf(buf, sizeof(buf), "aid,%d", aid); |
| 6478 | sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf); |
| 6479 | send_resp(dut, conn, SIGMA_COMPLETE, buf); |
| 6480 | return 0; |
| 6481 | } |
| 6482 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6483 | if (strcasecmp(parameter, "DiscoveredDevList") == 0) { |
| 6484 | char *bss_line; |
| 6485 | char *bss_id = NULL; |
| 6486 | const char *ifname = get_param(cmd, "Interface"); |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 6487 | char *saveptr; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6488 | |
| 6489 | if (ifname == NULL) { |
| 6490 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 6491 | "For get DiscoveredDevList need Interface name."); |
| 6492 | return -1; |
| 6493 | } |
| 6494 | |
| 6495 | /* |
| 6496 | * Use "BSS RANGE=ALL MASK=0x2" which provides a list |
| 6497 | * of BSSIDs in "bssid=<BSSID>\n" |
| 6498 | */ |
| 6499 | if (wpa_command_resp(ifname, "BSS RANGE=ALL MASK=0x2", |
| 6500 | bss_list, |
| 6501 | sizeof(bss_list)) < 0) { |
| 6502 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6503 | "Failed to get bss list"); |
| 6504 | return -1; |
| 6505 | } |
| 6506 | |
| 6507 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 6508 | "bss list for ifname:%s is:%s", |
| 6509 | ifname, bss_list); |
| 6510 | |
| 6511 | snprintf(buf, sizeof(buf), "DeviceList"); |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 6512 | bss_line = strtok_r(bss_list, "\n", &saveptr); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6513 | while (bss_line) { |
| 6514 | if (sscanf(bss_line, "bssid=%ms", &bss_id) > 0 && |
| 6515 | bss_id) { |
| 6516 | int len; |
| 6517 | |
| 6518 | len = snprintf(buf + strlen(buf), |
| 6519 | sizeof(buf) - strlen(buf), |
| 6520 | ",%s", bss_id); |
| 6521 | free(bss_id); |
| 6522 | bss_id = NULL; |
| 6523 | if (len < 0) { |
| 6524 | sigma_dut_print(dut, |
| 6525 | DUT_MSG_ERROR, |
| 6526 | "Failed to read BSSID"); |
| 6527 | send_resp(dut, conn, SIGMA_ERROR, |
| 6528 | "ErrorCode,Failed to read BSS ID"); |
| 6529 | return 0; |
| 6530 | } |
| 6531 | |
| 6532 | if ((size_t) len >= sizeof(buf) - strlen(buf)) { |
| 6533 | sigma_dut_print(dut, |
| 6534 | DUT_MSG_ERROR, |
| 6535 | "Response buf too small for list"); |
| 6536 | send_resp(dut, conn, |
| 6537 | SIGMA_ERROR, |
| 6538 | "ErrorCode,Response buf too small for list"); |
| 6539 | return 0; |
| 6540 | } |
| 6541 | } |
| 6542 | |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 6543 | bss_line = strtok_r(NULL, "\n", &saveptr); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6544 | } |
| 6545 | |
| 6546 | sigma_dut_print(dut, DUT_MSG_INFO, "DiscoveredDevList is %s", |
| 6547 | buf); |
| 6548 | send_resp(dut, conn, SIGMA_COMPLETE, buf); |
| 6549 | return 0; |
| 6550 | } |
| 6551 | |
| 6552 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter"); |
| 6553 | return 0; |
| 6554 | } |
| 6555 | |
| 6556 | |
Kiran Kumar Lokere | c86d802 | 2018-10-11 13:57:12 -0700 | [diff] [blame] | 6557 | static int sta_get_parameter_he(struct sigma_dut *dut, struct sigma_conn *conn, |
| 6558 | struct sigma_cmd *cmd) |
| 6559 | { |
| 6560 | char buf[MAX_CMD_LEN]; |
| 6561 | const char *parameter = get_param(cmd, "Parameter"); |
| 6562 | |
| 6563 | if (!parameter) |
| 6564 | return -1; |
| 6565 | |
| 6566 | if (strcasecmp(parameter, "RSSI") == 0) { |
| 6567 | char rssi[10]; |
| 6568 | |
| 6569 | if (get_wpa_signal_poll(dut, get_station_ifname(), "RSSI", |
| 6570 | rssi, sizeof(rssi)) < 0) { |
| 6571 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6572 | "Could not get RSSI"); |
| 6573 | return -2; |
| 6574 | } |
| 6575 | |
| 6576 | snprintf(buf, sizeof(buf), "rssi,%s", rssi); |
| 6577 | sigma_dut_print(dut, DUT_MSG_INFO, "RSSI %s", buf); |
| 6578 | send_resp(dut, conn, SIGMA_COMPLETE, buf); |
| 6579 | return 0; |
| 6580 | } |
| 6581 | |
| 6582 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter"); |
| 6583 | return 0; |
| 6584 | } |
| 6585 | |
| 6586 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 6587 | static enum sigma_cmd_result cmd_sta_get_parameter(struct sigma_dut *dut, |
| 6588 | struct sigma_conn *conn, |
| 6589 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6590 | { |
| 6591 | const char *program = get_param(cmd, "Program"); |
| 6592 | |
| 6593 | if (program == NULL) |
| 6594 | return -1; |
| 6595 | |
| 6596 | if (strcasecmp(program, "P2PNFC") == 0) |
| 6597 | return p2p_cmd_sta_get_parameter(dut, conn, cmd); |
| 6598 | |
| 6599 | if (strcasecmp(program, "60ghz") == 0) |
| 6600 | return sta_get_parameter_60g(dut, conn, cmd); |
| 6601 | |
Kiran Kumar Lokere | c86d802 | 2018-10-11 13:57:12 -0700 | [diff] [blame] | 6602 | if (strcasecmp(program, "he") == 0) |
| 6603 | return sta_get_parameter_he(dut, conn, cmd); |
| 6604 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6605 | #ifdef ANDROID_NAN |
| 6606 | if (strcasecmp(program, "NAN") == 0) |
Amarnath Hullur Subramanyam | 1854ec6 | 2016-08-11 19:29:35 -0700 | [diff] [blame] | 6607 | return nan_cmd_sta_get_parameter(dut, conn, cmd); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6608 | #endif /* ANDROID_NAN */ |
| 6609 | |
Amarnath Hullur Subramanyam | 9c381f5 | 2017-03-17 00:04:41 -0700 | [diff] [blame] | 6610 | #ifdef MIRACAST |
| 6611 | if (strcasecmp(program, "WFD") == 0 || |
| 6612 | strcasecmp(program, "DisplayR2") == 0) |
| 6613 | return miracast_cmd_sta_get_parameter(dut, conn, cmd); |
| 6614 | #endif /* MIRACAST */ |
| 6615 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6616 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter"); |
| 6617 | return 0; |
| 6618 | } |
| 6619 | |
| 6620 | |
| 6621 | static void sta_reset_default_ath(struct sigma_dut *dut, const char *intf, |
| 6622 | const char *type) |
| 6623 | { |
| 6624 | char buf[100]; |
| 6625 | |
| 6626 | if (dut->program == PROGRAM_VHT) { |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 6627 | run_iwpriv(dut, intf, "chwidth 2"); |
| 6628 | run_iwpriv(dut, intf, "mode 11ACVHT80"); |
| 6629 | run_iwpriv(dut, intf, "vhtmcs -1"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6630 | } |
| 6631 | |
| 6632 | if (dut->program == PROGRAM_HT) { |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 6633 | run_iwpriv(dut, intf, "chwidth 0"); |
| 6634 | run_iwpriv(dut, intf, "mode 11naht40"); |
| 6635 | run_iwpriv(dut, intf, "set11NRates 0"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6636 | } |
| 6637 | |
| 6638 | if (dut->program == PROGRAM_VHT || dut->program == PROGRAM_HT) { |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 6639 | run_iwpriv(dut, intf, "powersave 0"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6640 | |
| 6641 | /* Reset CTS width */ |
| 6642 | snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 54 0", |
| 6643 | intf); |
| 6644 | if (system(buf) != 0) { |
| 6645 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6646 | "wifitool %s beeliner_fw_test 54 0 failed", |
| 6647 | intf); |
| 6648 | } |
| 6649 | |
| 6650 | /* Enable Dynamic Bandwidth signalling by default */ |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 6651 | run_iwpriv(dut, intf, "cwmenable 1"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6652 | |
| 6653 | snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", intf); |
| 6654 | if (system(buf) != 0) { |
| 6655 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6656 | "iwpriv rts failed"); |
| 6657 | } |
| 6658 | } |
| 6659 | |
| 6660 | if (type && strcasecmp(type, "Testbed") == 0) { |
| 6661 | dut->testbed_flag_txsp = 1; |
| 6662 | dut->testbed_flag_rxsp = 1; |
| 6663 | /* STA has to set spatial stream to 2 per Appendix H */ |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 6664 | run_iwpriv(dut, intf, "vht_mcsmap 0xfff0"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6665 | |
| 6666 | /* Disable LDPC per Appendix H */ |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 6667 | run_iwpriv(dut, intf, "ldpc 0"); |
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, "amsdu 1"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6670 | |
| 6671 | /* TODO: Disable STBC 2x1 transmit and receive */ |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 6672 | run_iwpriv(dut, intf, "tx_stbc 0"); |
| 6673 | run_iwpriv(dut, intf, "rx_stbc 0"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6674 | |
| 6675 | /* STA has to disable Short GI per Appendix H */ |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 6676 | run_iwpriv(dut, intf, "shortgi 0"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6677 | } |
| 6678 | |
| 6679 | if (type && strcasecmp(type, "DUT") == 0) { |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 6680 | run_iwpriv(dut, intf, "nss 3"); |
Arif Hussain | ac6c511 | 2018-05-25 17:34:00 -0700 | [diff] [blame] | 6681 | dut->sta_nss = 3; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6682 | |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 6683 | run_iwpriv(dut, intf, "shortgi 1"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 6684 | } |
| 6685 | } |
| 6686 | |
| 6687 | |
Amarnath Hullur Subramanyam | 2538acc | 2018-02-02 16:15:25 -0800 | [diff] [blame] | 6688 | #ifdef NL80211_SUPPORT |
| 6689 | static int sta_set_he_mcs(struct sigma_dut *dut, const char *intf, |
| 6690 | enum he_mcs_config mcs) |
| 6691 | { |
| 6692 | struct nl_msg *msg; |
| 6693 | int ret = 0; |
| 6694 | struct nlattr *params; |
| 6695 | int ifindex; |
| 6696 | |
| 6697 | ifindex = if_nametoindex(intf); |
| 6698 | if (ifindex == 0) { |
| 6699 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6700 | "%s: Index for interface %s failed", |
| 6701 | __func__, intf); |
| 6702 | return -1; |
| 6703 | } |
| 6704 | |
| 6705 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 6706 | NL80211_CMD_VENDOR)) || |
| 6707 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 6708 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 6709 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 6710 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || |
| 6711 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 6712 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MCS, |
| 6713 | mcs)) { |
| 6714 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6715 | "%s: err in adding vendor_cmd and vendor_data", |
| 6716 | __func__); |
| 6717 | nlmsg_free(msg); |
| 6718 | return -1; |
| 6719 | } |
| 6720 | nla_nest_end(msg, params); |
| 6721 | |
| 6722 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 6723 | if (ret) { |
| 6724 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6725 | "%s: err in send_and_recv_msgs, ret=%d", |
| 6726 | __func__, ret); |
| 6727 | } |
| 6728 | return ret; |
| 6729 | } |
| 6730 | #endif /* NL80211_SUPPORT */ |
| 6731 | |
| 6732 | |
Kiran Kumar Lokere | 419f696 | 2018-10-24 19:03:04 -0700 | [diff] [blame] | 6733 | static int sta_set_action_tx_in_he_tb_ppdu(struct sigma_dut *dut, |
| 6734 | const char *intf, int enable) |
| 6735 | { |
| 6736 | #ifdef NL80211_SUPPORT |
| 6737 | struct nl_msg *msg; |
| 6738 | int ret = 0; |
| 6739 | struct nlattr *params; |
| 6740 | int ifindex; |
| 6741 | |
| 6742 | ifindex = if_nametoindex(intf); |
| 6743 | if (ifindex == 0) { |
| 6744 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6745 | "%s: Index for interface %s failed", |
| 6746 | __func__, intf); |
| 6747 | return -1; |
| 6748 | } |
| 6749 | |
| 6750 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 6751 | NL80211_CMD_VENDOR)) || |
| 6752 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 6753 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 6754 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 6755 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || |
| 6756 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 6757 | nla_put_u8(msg, |
| 6758 | QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_ACTION_TX_TB_PPDU, |
| 6759 | enable)) { |
| 6760 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6761 | "%s: err in adding vendor_cmd and vendor_data", |
| 6762 | __func__); |
| 6763 | nlmsg_free(msg); |
| 6764 | return -1; |
| 6765 | } |
| 6766 | nla_nest_end(msg, params); |
| 6767 | |
| 6768 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 6769 | if (ret) { |
| 6770 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6771 | "%s: err in send_and_recv_msgs, ret=%d", |
| 6772 | __func__, ret); |
| 6773 | } |
| 6774 | return ret; |
| 6775 | #else /* NL80211_SUPPORT */ |
| 6776 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6777 | "HE action Tx TB PPDU cannot be set without NL80211_SUPPORT defined"); |
| 6778 | return -1; |
| 6779 | #endif /* NL80211_SUPPORT */ |
| 6780 | } |
| 6781 | |
| 6782 | |
Amarnath Hullur Subramanyam | 4622a21 | 2018-02-23 12:12:14 -0800 | [diff] [blame] | 6783 | static int sta_set_heconfig_and_wep_tkip(struct sigma_dut *dut, |
| 6784 | const char *intf, int enable) |
| 6785 | { |
| 6786 | #ifdef NL80211_SUPPORT |
| 6787 | struct nl_msg *msg; |
| 6788 | int ret = 0; |
| 6789 | struct nlattr *params; |
| 6790 | int ifindex; |
| 6791 | |
| 6792 | ifindex = if_nametoindex(intf); |
| 6793 | if (ifindex == 0) { |
| 6794 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6795 | "%s: Index for interface %s failed", |
| 6796 | __func__, intf); |
| 6797 | return -1; |
| 6798 | } |
| 6799 | |
| 6800 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 6801 | NL80211_CMD_VENDOR)) || |
| 6802 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 6803 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 6804 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 6805 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || |
| 6806 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 6807 | nla_put_u8(msg, |
| 6808 | QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WEP_TKIP_IN_HE, |
| 6809 | enable)) { |
| 6810 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6811 | "%s: err in adding vendor_cmd and vendor_data", |
| 6812 | __func__); |
| 6813 | nlmsg_free(msg); |
| 6814 | return -1; |
| 6815 | } |
| 6816 | nla_nest_end(msg, params); |
| 6817 | |
| 6818 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 6819 | if (ret) { |
| 6820 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6821 | "%s: err in send_and_recv_msgs, ret=%d", |
| 6822 | __func__, ret); |
| 6823 | } |
| 6824 | return ret; |
| 6825 | #else /* NL80211_SUPPORT */ |
| 6826 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6827 | "HE config enablement cannot be changed without NL80211_SUPPORT defined"); |
| 6828 | return -1; |
| 6829 | #endif /* NL80211_SUPPORT */ |
| 6830 | } |
| 6831 | |
| 6832 | |
Kiran Kumar Lokere | 765bdd8 | 2019-02-24 22:14:43 -0800 | [diff] [blame] | 6833 | #ifdef NL80211_SUPPORT |
Kiran Kumar Lokere | 642f7ce | 2019-02-25 18:28:10 -0800 | [diff] [blame] | 6834 | |
Kiran Kumar Lokere | 765bdd8 | 2019-02-24 22:14:43 -0800 | [diff] [blame] | 6835 | static int sta_set_he_testbed_def(struct sigma_dut *dut, |
| 6836 | const char *intf, int cfg) |
| 6837 | { |
| 6838 | struct nl_msg *msg; |
| 6839 | int ret = 0; |
| 6840 | struct nlattr *params; |
| 6841 | int ifindex; |
| 6842 | |
| 6843 | ifindex = if_nametoindex(intf); |
| 6844 | if (ifindex == 0) { |
| 6845 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6846 | "%s: Index for interface %s failed", |
| 6847 | __func__, intf); |
| 6848 | return -1; |
| 6849 | } |
| 6850 | |
| 6851 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 6852 | NL80211_CMD_VENDOR)) || |
| 6853 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 6854 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 6855 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 6856 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || |
| 6857 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 6858 | nla_put_u8(msg, |
| 6859 | QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SET_HE_TESTBED_DEFAULTS, |
| 6860 | cfg)) { |
| 6861 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6862 | "%s: err in adding vendor_cmd and vendor_data", |
| 6863 | __func__); |
| 6864 | nlmsg_free(msg); |
| 6865 | return -1; |
| 6866 | } |
| 6867 | nla_nest_end(msg, params); |
| 6868 | |
| 6869 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 6870 | if (ret) { |
| 6871 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6872 | "%s: err in send_and_recv_msgs, ret=%d", |
| 6873 | __func__, ret); |
| 6874 | } |
| 6875 | return ret; |
| 6876 | } |
Kiran Kumar Lokere | 642f7ce | 2019-02-25 18:28:10 -0800 | [diff] [blame] | 6877 | |
| 6878 | |
| 6879 | static int sta_set_2g_vht_supp(struct sigma_dut *dut, const char *intf, int cfg) |
| 6880 | { |
| 6881 | struct nl_msg *msg; |
| 6882 | int ret = 0; |
| 6883 | struct nlattr *params; |
| 6884 | int ifindex; |
| 6885 | |
| 6886 | ifindex = if_nametoindex(intf); |
| 6887 | if (ifindex == 0) { |
| 6888 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6889 | "%s: Index for interface %s failed", |
| 6890 | __func__, intf); |
| 6891 | return -1; |
| 6892 | } |
| 6893 | |
| 6894 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 6895 | NL80211_CMD_VENDOR)) || |
| 6896 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 6897 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 6898 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 6899 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || |
| 6900 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 6901 | nla_put_u8(msg, |
| 6902 | QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_2G_VHT, |
| 6903 | cfg)) { |
| 6904 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6905 | "%s: err in adding vendor_cmd and vendor_data", |
| 6906 | __func__); |
| 6907 | nlmsg_free(msg); |
| 6908 | return -1; |
| 6909 | } |
| 6910 | nla_nest_end(msg, params); |
| 6911 | |
| 6912 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 6913 | if (ret) { |
| 6914 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6915 | "%s: err in send_and_recv_msgs, ret=%d", |
| 6916 | __func__, ret); |
| 6917 | } |
| 6918 | return ret; |
| 6919 | } |
| 6920 | |
Kiran Kumar Lokere | 765bdd8 | 2019-02-24 22:14:43 -0800 | [diff] [blame] | 6921 | #endif /* NL80211_SUPPORT */ |
| 6922 | |
| 6923 | |
Amarnath Hullur Subramanyam | 13215de | 2018-02-27 14:12:55 -0800 | [diff] [blame] | 6924 | static int sta_set_addba_buf_size(struct sigma_dut *dut, |
| 6925 | const char *intf, int bufsize) |
| 6926 | { |
| 6927 | #ifdef NL80211_SUPPORT |
| 6928 | struct nl_msg *msg; |
| 6929 | int ret = 0; |
| 6930 | struct nlattr *params; |
| 6931 | int ifindex; |
| 6932 | |
| 6933 | ifindex = if_nametoindex(intf); |
| 6934 | if (ifindex == 0) { |
| 6935 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6936 | "%s: Index for interface %s failed", |
| 6937 | __func__, intf); |
| 6938 | return -1; |
| 6939 | } |
| 6940 | |
| 6941 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 6942 | NL80211_CMD_VENDOR)) || |
| 6943 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 6944 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 6945 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 6946 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || |
| 6947 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
Kiran Kumar Lokere | 26e2758 | 2018-08-01 16:18:34 -0700 | [diff] [blame] | 6948 | nla_put_u16(msg, |
| 6949 | QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE, |
| 6950 | bufsize)) { |
Amarnath Hullur Subramanyam | 13215de | 2018-02-27 14:12:55 -0800 | [diff] [blame] | 6951 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6952 | "%s: err in adding vendor_cmd and vendor_data", |
| 6953 | __func__); |
| 6954 | nlmsg_free(msg); |
| 6955 | return -1; |
| 6956 | } |
| 6957 | nla_nest_end(msg, params); |
| 6958 | |
| 6959 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 6960 | if (ret) { |
| 6961 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6962 | "%s: err in send_and_recv_msgs, ret=%d", |
| 6963 | __func__, ret); |
| 6964 | } |
| 6965 | return ret; |
| 6966 | #else /* NL80211_SUPPORT */ |
| 6967 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6968 | "AddBA bufsize cannot be changed without NL80211_SUPPORT defined"); |
| 6969 | return -1; |
| 6970 | #endif /* NL80211_SUPPORT */ |
| 6971 | } |
| 6972 | |
| 6973 | |
Arif Hussain | 8d5b27b | 2018-05-14 14:31:03 -0700 | [diff] [blame] | 6974 | static int sta_set_tx_beamformee(struct sigma_dut *dut, const char *intf, |
| 6975 | int enable) |
| 6976 | { |
| 6977 | #ifdef NL80211_SUPPORT |
| 6978 | struct nl_msg *msg; |
| 6979 | int ret = 0; |
| 6980 | struct nlattr *params; |
| 6981 | int ifindex; |
| 6982 | |
| 6983 | ifindex = if_nametoindex(intf); |
| 6984 | if (ifindex == 0) { |
| 6985 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 6986 | "%s: Index for interface %s failed", |
| 6987 | __func__, intf); |
| 6988 | return -1; |
| 6989 | } |
| 6990 | |
| 6991 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 6992 | NL80211_CMD_VENDOR)) || |
| 6993 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 6994 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 6995 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 6996 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || |
| 6997 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 6998 | nla_put_u8(msg, |
| 6999 | QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_TX_BEAMFORMEE, |
| 7000 | enable)) { |
| 7001 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7002 | "%s: err in adding vendor_cmd and vendor_data", |
| 7003 | __func__); |
| 7004 | nlmsg_free(msg); |
| 7005 | return -1; |
| 7006 | } |
| 7007 | nla_nest_end(msg, params); |
| 7008 | |
| 7009 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 7010 | if (ret) { |
| 7011 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7012 | "%s: err in send_and_recv_msgs, ret=%d", |
| 7013 | __func__, ret); |
| 7014 | } |
| 7015 | return ret; |
| 7016 | #else /* NL80211_SUPPORT */ |
| 7017 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7018 | "tx beamformee cannot be changed without NL80211_SUPPORT defined"); |
| 7019 | return -1; |
| 7020 | #endif /* NL80211_SUPPORT */ |
| 7021 | } |
| 7022 | |
| 7023 | |
Arif Hussain | 9765f7d | 2018-07-03 08:28:26 -0700 | [diff] [blame] | 7024 | static int sta_set_beamformee_sts(struct sigma_dut *dut, const char *intf, |
| 7025 | int val) |
| 7026 | { |
| 7027 | #ifdef NL80211_SUPPORT |
| 7028 | struct nl_msg *msg; |
| 7029 | int ret = 0; |
| 7030 | struct nlattr *params; |
| 7031 | int ifindex; |
| 7032 | |
| 7033 | ifindex = if_nametoindex(intf); |
| 7034 | if (ifindex == 0) { |
| 7035 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7036 | "%s: Index for interface %s failed, val:%d", |
| 7037 | __func__, intf, val); |
| 7038 | return -1; |
| 7039 | } |
| 7040 | |
| 7041 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 7042 | NL80211_CMD_VENDOR)) || |
| 7043 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 7044 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 7045 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 7046 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || |
| 7047 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 7048 | nla_put_u8(msg, |
| 7049 | QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_BEAMFORMEE_NSTS, |
| 7050 | val)) { |
| 7051 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7052 | "%s: err in adding vendor_cmd and vendor_data, val: %d", |
| 7053 | __func__, val); |
| 7054 | nlmsg_free(msg); |
| 7055 | return -1; |
| 7056 | } |
| 7057 | nla_nest_end(msg, params); |
| 7058 | |
| 7059 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 7060 | if (ret) { |
| 7061 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7062 | "%s: err in send_and_recv_msgs, ret=%d, val=%d", |
| 7063 | __func__, ret, val); |
| 7064 | } |
| 7065 | return ret; |
| 7066 | #else /* NL80211_SUPPORT */ |
| 7067 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7068 | "beamformee sts cannot be changed without NL80211_SUPPORT defined"); |
| 7069 | return -1; |
| 7070 | #endif /* NL80211_SUPPORT */ |
| 7071 | } |
| 7072 | |
| 7073 | |
Arif Hussain | 68d23f5 | 2018-07-11 13:39:08 -0700 | [diff] [blame] | 7074 | #ifdef NL80211_SUPPORT |
Kiran Kumar Lokere | 55eb558 | 2018-08-19 20:03:26 -0700 | [diff] [blame] | 7075 | static int sta_set_mac_padding_duration(struct sigma_dut *dut, const char *intf, |
| 7076 | enum qca_wlan_he_mac_padding_dur val) |
| 7077 | { |
Arif Hussain | 68d23f5 | 2018-07-11 13:39:08 -0700 | [diff] [blame] | 7078 | struct nl_msg *msg; |
| 7079 | int ret = 0; |
| 7080 | struct nlattr *params; |
| 7081 | int ifindex; |
| 7082 | |
| 7083 | ifindex = if_nametoindex(intf); |
| 7084 | if (ifindex == 0) { |
| 7085 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7086 | "%s: Index for interface %s failed, val:%d", |
| 7087 | __func__, intf, val); |
| 7088 | return -1; |
| 7089 | } |
| 7090 | |
| 7091 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 7092 | NL80211_CMD_VENDOR)) || |
| 7093 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 7094 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 7095 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 7096 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || |
| 7097 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 7098 | nla_put_u8(msg, |
| 7099 | QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MAC_PADDING_DUR, |
| 7100 | val)) { |
| 7101 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7102 | "%s: err in adding vendor_cmd and vendor_data, val: %d", |
| 7103 | __func__, val); |
| 7104 | nlmsg_free(msg); |
| 7105 | return -1; |
| 7106 | } |
| 7107 | nla_nest_end(msg, params); |
| 7108 | |
| 7109 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 7110 | if (ret) { |
| 7111 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7112 | "%s: err in send_and_recv_msgs, ret=%d, val=%d", |
| 7113 | __func__, ret, val); |
| 7114 | } |
| 7115 | return ret; |
Arif Hussain | 68d23f5 | 2018-07-11 13:39:08 -0700 | [diff] [blame] | 7116 | } |
Kiran Kumar Lokere | 55eb558 | 2018-08-19 20:03:26 -0700 | [diff] [blame] | 7117 | #endif /* NL80211_SUPPORT */ |
Arif Hussain | 68d23f5 | 2018-07-11 13:39:08 -0700 | [diff] [blame] | 7118 | |
| 7119 | |
Kiran Kumar Lokere | 400d68f | 2018-08-29 18:45:11 -0700 | [diff] [blame] | 7120 | static int sta_set_tx_su_ppdu_cfg(struct sigma_dut *dut, const char *intf, |
| 7121 | int val) |
| 7122 | { |
| 7123 | #ifdef NL80211_SUPPORT |
| 7124 | struct nl_msg *msg; |
| 7125 | int ret = 0; |
| 7126 | struct nlattr *params; |
| 7127 | int ifindex; |
| 7128 | |
| 7129 | ifindex = if_nametoindex(intf); |
| 7130 | if (ifindex == 0) { |
| 7131 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7132 | "%s: Index for interface %s failed, val:%d", |
| 7133 | __func__, intf, val); |
| 7134 | return -1; |
| 7135 | } |
| 7136 | |
| 7137 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 7138 | NL80211_CMD_VENDOR)) || |
| 7139 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 7140 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 7141 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 7142 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || |
| 7143 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 7144 | nla_put_u8(msg, |
| 7145 | QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_SUPPDU, |
| 7146 | val)) { |
| 7147 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7148 | "%s: err in adding vendor_cmd and vendor_data, val: %d", |
| 7149 | __func__, val); |
| 7150 | nlmsg_free(msg); |
| 7151 | return -1; |
| 7152 | } |
| 7153 | nla_nest_end(msg, params); |
| 7154 | |
| 7155 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 7156 | if (ret) { |
| 7157 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7158 | "%s: err in send_and_recv_msgs, ret=%d, val=%d", |
| 7159 | __func__, ret, val); |
| 7160 | } |
| 7161 | return ret; |
| 7162 | #else /* NL80211_SUPPORT */ |
| 7163 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7164 | "Tx SU PPDU cannot be set without NL80211_SUPPORT defined"); |
| 7165 | return -1; |
| 7166 | #endif /* NL80211_SUPPORT */ |
| 7167 | } |
| 7168 | |
| 7169 | |
Kiran Kumar Lokere | 29c1bb0 | 2018-10-08 17:41:02 -0700 | [diff] [blame] | 7170 | #ifdef NL80211_SUPPORT |
| 7171 | static int sta_set_he_om_ctrl_reset(struct sigma_dut *dut, const char *intf) |
| 7172 | { |
| 7173 | struct nl_msg *msg; |
| 7174 | int ret = 0; |
| 7175 | struct nlattr *params; |
| 7176 | int ifindex; |
| 7177 | |
| 7178 | ifindex = if_nametoindex(intf); |
| 7179 | if (ifindex == 0) { |
| 7180 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7181 | "%s: Index for interface %s failed", |
| 7182 | __func__, intf); |
| 7183 | return -1; |
| 7184 | } |
| 7185 | |
| 7186 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 7187 | NL80211_CMD_VENDOR)) || |
| 7188 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 7189 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 7190 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 7191 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || |
| 7192 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 7193 | nla_put_flag(msg, |
| 7194 | QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_CLEAR_HE_OM_CTRL_CONFIG)) { |
| 7195 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7196 | "%s: err in adding vendor_cmd and vendor_data", |
| 7197 | __func__); |
| 7198 | nlmsg_free(msg); |
| 7199 | return -1; |
| 7200 | } |
| 7201 | nla_nest_end(msg, params); |
| 7202 | |
| 7203 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 7204 | if (ret) { |
| 7205 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7206 | "%s: err in send_and_recv_msgs, ret=%d", |
| 7207 | __func__, ret); |
| 7208 | } |
| 7209 | return ret; |
| 7210 | } |
| 7211 | #endif /* NL80211_SUPPORT */ |
| 7212 | |
| 7213 | |
Kiran Kumar Lokere | b101268 | 2018-08-08 17:48:32 -0700 | [diff] [blame] | 7214 | static int sta_set_mu_edca_override(struct sigma_dut *dut, const char *intf, |
| 7215 | int val) |
| 7216 | { |
| 7217 | #ifdef NL80211_SUPPORT |
| 7218 | struct nl_msg *msg; |
| 7219 | int ret = 0; |
| 7220 | struct nlattr *params; |
| 7221 | int ifindex; |
| 7222 | |
| 7223 | ifindex = if_nametoindex(intf); |
| 7224 | if (ifindex == 0) { |
| 7225 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7226 | "%s: Index for interface %s failed, val:%d", |
| 7227 | __func__, intf, val); |
| 7228 | return -1; |
| 7229 | } |
| 7230 | |
| 7231 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 7232 | NL80211_CMD_VENDOR)) || |
| 7233 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 7234 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 7235 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 7236 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || |
| 7237 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 7238 | nla_put_u8(msg, |
| 7239 | QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_OVERRIDE_MU_EDCA, |
| 7240 | val)) { |
| 7241 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7242 | "%s: err in adding vendor_cmd and vendor_data, val: %d", |
| 7243 | __func__, val); |
| 7244 | nlmsg_free(msg); |
| 7245 | return -1; |
| 7246 | } |
| 7247 | nla_nest_end(msg, params); |
| 7248 | |
| 7249 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 7250 | if (ret) { |
| 7251 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7252 | "%s: err in send_and_recv_msgs, ret=%d, val=%d", |
| 7253 | __func__, ret, val); |
| 7254 | } |
| 7255 | return ret; |
| 7256 | #else /* NL80211_SUPPORT */ |
| 7257 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7258 | "MU EDCA override cannot be changed without NL80211_SUPPORT defined"); |
| 7259 | return -1; |
| 7260 | #endif /* NL80211_SUPPORT */ |
| 7261 | } |
| 7262 | |
| 7263 | |
Kiran Kumar Lokere | de33e37 | 2018-08-29 16:26:24 -0700 | [diff] [blame] | 7264 | static int sta_set_om_ctrl_supp(struct sigma_dut *dut, const char *intf, |
| 7265 | int val) |
| 7266 | { |
| 7267 | #ifdef NL80211_SUPPORT |
| 7268 | struct nl_msg *msg; |
| 7269 | int ret = 0; |
| 7270 | struct nlattr *params; |
| 7271 | int ifindex; |
| 7272 | |
| 7273 | ifindex = if_nametoindex(intf); |
| 7274 | if (ifindex == 0) { |
| 7275 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7276 | "%s: Index for interface %s failed, val:%d", |
| 7277 | __func__, intf, val); |
| 7278 | return -1; |
| 7279 | } |
| 7280 | |
| 7281 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 7282 | NL80211_CMD_VENDOR)) || |
| 7283 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 7284 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 7285 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 7286 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || |
| 7287 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 7288 | nla_put_u8(msg, |
| 7289 | QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OM_CTRL_SUPP, |
| 7290 | val)) { |
| 7291 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7292 | "%s: err in adding vendor_cmd and vendor_data, val: %d", |
| 7293 | __func__, val); |
| 7294 | nlmsg_free(msg); |
| 7295 | return -1; |
| 7296 | } |
| 7297 | nla_nest_end(msg, params); |
| 7298 | |
| 7299 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 7300 | if (ret) { |
| 7301 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7302 | "%s: err in send_and_recv_msgs, ret=%d, val=%d", |
| 7303 | __func__, ret, val); |
| 7304 | } |
| 7305 | return ret; |
| 7306 | #else /* NL80211_SUPPORT */ |
| 7307 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7308 | "HE OM ctrl cannot be changed without NL80211_SUPPORT defined"); |
| 7309 | return -1; |
| 7310 | #endif /* NL80211_SUPPORT */ |
| 7311 | } |
| 7312 | |
| 7313 | |
Arif Hussain | 480d5f4 | 2019-03-12 14:40:42 -0700 | [diff] [blame] | 7314 | static int sta_set_twt_req_support(struct sigma_dut *dut, const char *intf, |
| 7315 | int val) |
| 7316 | { |
| 7317 | #ifdef NL80211_SUPPORT |
| 7318 | struct nl_msg *msg; |
| 7319 | int ret; |
| 7320 | struct nlattr *params; |
| 7321 | int ifindex; |
| 7322 | |
| 7323 | ifindex = if_nametoindex(intf); |
| 7324 | if (ifindex == 0) { |
| 7325 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7326 | "%s: Index for interface %s failed, val:%d", |
| 7327 | __func__, intf, val); |
| 7328 | return -1; |
| 7329 | } |
| 7330 | |
| 7331 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 7332 | NL80211_CMD_VENDOR)) || |
| 7333 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 7334 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 7335 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 7336 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || |
| 7337 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 7338 | nla_put_u8(msg, |
| 7339 | QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TWT_REQ_SUPPORT, |
| 7340 | val)) { |
| 7341 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7342 | "%s: err in adding vendor_cmd and vendor_data, val: %d", |
| 7343 | __func__, val); |
| 7344 | nlmsg_free(msg); |
| 7345 | return -1; |
| 7346 | } |
| 7347 | nla_nest_end(msg, params); |
| 7348 | |
| 7349 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 7350 | if (ret) { |
| 7351 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7352 | "%s: err in send_and_recv_msgs, ret=%d, val=%d", |
| 7353 | __func__, ret, val); |
| 7354 | } |
| 7355 | return ret; |
| 7356 | #else /* NL80211_SUPPORT */ |
| 7357 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7358 | "TWT Request cannot be changed without NL80211_SUPPORT defined"); |
| 7359 | return -1; |
| 7360 | #endif /* NL80211_SUPPORT */ |
| 7361 | } |
| 7362 | |
| 7363 | |
Amarnath Hullur Subramanyam | 58f2a6e | 2018-01-31 03:36:00 -0800 | [diff] [blame] | 7364 | static void sta_reset_default_wcn(struct sigma_dut *dut, const char *intf, |
| 7365 | const char *type) |
| 7366 | { |
| 7367 | char buf[60]; |
| 7368 | |
| 7369 | if (dut->program == PROGRAM_HE) { |
| 7370 | /* resetting phymode to auto in case of HE program */ |
| 7371 | snprintf(buf, sizeof(buf), "iwpriv %s setphymode 0", intf); |
| 7372 | if (system(buf) != 0) { |
| 7373 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7374 | "iwpriv %s setphymode failed", intf); |
| 7375 | } |
| 7376 | |
Amarnath Hullur Subramanyam | 9cecb50 | 2018-04-25 13:26:30 -0700 | [diff] [blame] | 7377 | /* reset the rate to Auto rate */ |
| 7378 | snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0xff", |
| 7379 | intf); |
| 7380 | if (system(buf) != 0) { |
| 7381 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7382 | "iwpriv %s set_11ax_rate 0xff failed", |
| 7383 | intf); |
| 7384 | } |
| 7385 | |
Kiran Kumar Lokere | 86cfe3a | 2018-06-01 11:55:15 -0700 | [diff] [blame] | 7386 | /* reset the LDPC setting */ |
| 7387 | snprintf(buf, sizeof(buf), "iwpriv %s ldpc 1", intf); |
| 7388 | if (system(buf) != 0) { |
| 7389 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7390 | "iwpriv %s ldpc 1 failed", intf); |
| 7391 | } |
| 7392 | |
Kiran Kumar Lokere | d6149ff | 2018-12-05 20:20:41 -0800 | [diff] [blame] | 7393 | /* reset the power save setting */ |
| 7394 | snprintf(buf, sizeof(buf), "iwpriv %s setPower 2", intf); |
| 7395 | if (system(buf) != 0) { |
| 7396 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7397 | "iwpriv %s setPower 2 failed", intf); |
| 7398 | } |
| 7399 | |
Amarnath Hullur Subramanyam | 58f2a6e | 2018-01-31 03:36:00 -0800 | [diff] [blame] | 7400 | /* remove all network profiles */ |
| 7401 | remove_wpa_networks(intf); |
Amarnath Hullur Subramanyam | 2538acc | 2018-02-02 16:15:25 -0800 | [diff] [blame] | 7402 | |
Amarnath Hullur Subramanyam | 13215de | 2018-02-27 14:12:55 -0800 | [diff] [blame] | 7403 | /* Configure ADDBA Req/Rsp buffer size to be 64 */ |
| 7404 | sta_set_addba_buf_size(dut, intf, 64); |
| 7405 | |
Amarnath Hullur Subramanyam | 5f32d57 | 2018-03-02 00:02:33 -0800 | [diff] [blame] | 7406 | #ifdef NL80211_SUPPORT |
Kiran Kumar Lokere | 765bdd8 | 2019-02-24 22:14:43 -0800 | [diff] [blame] | 7407 | /* Reset the device HE capabilities to its default supported |
| 7408 | * configuration. */ |
| 7409 | sta_set_he_testbed_def(dut, intf, 0); |
| 7410 | |
Amarnath Hullur Subramanyam | 5f32d57 | 2018-03-02 00:02:33 -0800 | [diff] [blame] | 7411 | /* Disable noackpolicy for all AC */ |
| 7412 | if (nlvendor_sta_set_noack(dut, intf, 0, QCA_WLAN_AC_ALL)) { |
| 7413 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7414 | "Disable of noackpolicy for all AC failed"); |
| 7415 | } |
| 7416 | #endif /* NL80211_SUPPORT */ |
| 7417 | |
Amarnath Hullur Subramanyam | b1724a5 | 2018-03-07 14:31:46 -0800 | [diff] [blame] | 7418 | /* Enable WMM by default */ |
| 7419 | if (wcn_sta_set_wmm(dut, intf, "on")) { |
| 7420 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7421 | "Enable of WMM in sta_reset_default_wcn failed"); |
| 7422 | } |
| 7423 | |
| 7424 | /* Disable ADDBA_REJECT by default */ |
| 7425 | if (nlvendor_sta_set_addba_reject(dut, intf, 0)) { |
| 7426 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7427 | "Disable of addba_reject in sta_reset_default_wcn failed"); |
| 7428 | } |
| 7429 | |
Amarnath Hullur Subramanyam | 1f65a67 | 2018-03-07 14:50:29 -0800 | [diff] [blame] | 7430 | /* Enable sending of ADDBA by default */ |
| 7431 | if (nlvendor_config_send_addba(dut, intf, 1)) { |
| 7432 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7433 | "Enable sending of ADDBA in sta_reset_default_wcn failed"); |
| 7434 | } |
| 7435 | |
Amarnath Hullur Subramanyam | 63c590a | 2018-03-07 15:26:21 -0800 | [diff] [blame] | 7436 | /* Enable AMPDU by default */ |
| 7437 | iwpriv_sta_set_ampdu(dut, intf, 1); |
| 7438 | |
Subhani Shaik | 8e7a305 | 2018-04-24 14:03:00 -0700 | [diff] [blame] | 7439 | #ifdef NL80211_SUPPORT |
| 7440 | if (sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_AUTO)) { |
| 7441 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7442 | "Set LTF config to default in sta_reset_default_wcn failed"); |
| 7443 | } |
Arif Hussain | 9765f7d | 2018-07-03 08:28:26 -0700 | [diff] [blame] | 7444 | |
Kiran Kumar Lokere | bad5112 | 2018-12-12 19:03:36 -0800 | [diff] [blame] | 7445 | /* set the beamformee NSTS(maximum number of |
| 7446 | * space-time streams) to default DUT config |
| 7447 | */ |
| 7448 | if (sta_set_beamformee_sts(dut, intf, 7)) { |
Arif Hussain | 9765f7d | 2018-07-03 08:28:26 -0700 | [diff] [blame] | 7449 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7450 | "Failed to set BeamformeeSTS"); |
| 7451 | } |
Arif Hussain | 68d23f5 | 2018-07-11 13:39:08 -0700 | [diff] [blame] | 7452 | |
Kiran Kumar Lokere | 55eb558 | 2018-08-19 20:03:26 -0700 | [diff] [blame] | 7453 | if (sta_set_mac_padding_duration( |
| 7454 | dut, intf, |
| 7455 | QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME)) { |
Arif Hussain | 68d23f5 | 2018-07-11 13:39:08 -0700 | [diff] [blame] | 7456 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7457 | "Failed to set MAC padding duration"); |
| 7458 | } |
Kiran Kumar Lokere | b101268 | 2018-08-08 17:48:32 -0700 | [diff] [blame] | 7459 | |
| 7460 | if (sta_set_mu_edca_override(dut, intf, 0)) { |
| 7461 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7462 | "ErrorCode,Failed to set MU EDCA override disable"); |
| 7463 | } |
Kiran Kumar Lokere | de33e37 | 2018-08-29 16:26:24 -0700 | [diff] [blame] | 7464 | |
| 7465 | if (sta_set_om_ctrl_supp(dut, intf, 1)) { |
| 7466 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7467 | "Failed to set OM ctrl supp"); |
| 7468 | } |
Kiran Kumar Lokere | 400d68f | 2018-08-29 18:45:11 -0700 | [diff] [blame] | 7469 | |
| 7470 | if (sta_set_tx_su_ppdu_cfg(dut, intf, 1)) { |
| 7471 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7472 | "Failed to set Tx SU PPDU enable"); |
| 7473 | } |
Kiran Kumar Lokere | 29c1bb0 | 2018-10-08 17:41:02 -0700 | [diff] [blame] | 7474 | |
Kiran Kumar Lokere | 419f696 | 2018-10-24 19:03:04 -0700 | [diff] [blame] | 7475 | if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 0)) { |
| 7476 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7477 | "failed to send TB PPDU Tx cfg"); |
| 7478 | } |
| 7479 | |
Kiran Kumar Lokere | 29c1bb0 | 2018-10-08 17:41:02 -0700 | [diff] [blame] | 7480 | if (sta_set_he_om_ctrl_reset(dut, intf)) { |
| 7481 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7482 | "Failed to set OM ctrl reset"); |
| 7483 | } |
Kiran Kumar Lokere | e5ed442 | 2018-12-18 18:25:02 -0800 | [diff] [blame] | 7484 | |
| 7485 | /* +HTC-HE support default on */ |
| 7486 | if (sta_set_he_htc_supp(dut, intf, 1)) { |
| 7487 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7488 | "Setting of +HTC-HE support failed"); |
| 7489 | } |
Subhani Shaik | 8e7a305 | 2018-04-24 14:03:00 -0700 | [diff] [blame] | 7490 | #endif /* NL80211_SUPPORT */ |
| 7491 | |
Arif Hussain | 8d5b27b | 2018-05-14 14:31:03 -0700 | [diff] [blame] | 7492 | if (sta_set_tx_beamformee(dut, intf, 1)) { |
| 7493 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7494 | "Set tx beamformee enable by default in sta_reset_default_wcn failed"); |
| 7495 | } |
| 7496 | |
Amarnath Hullur Subramanyam | 2538acc | 2018-02-02 16:15:25 -0800 | [diff] [blame] | 7497 | /* Set nss to 1 and MCS 0-7 in case of testbed */ |
| 7498 | if (type && strcasecmp(type, "Testbed") == 0) { |
| 7499 | #ifdef NL80211_SUPPORT |
| 7500 | int ret; |
| 7501 | #endif /* NL80211_SUPPORT */ |
| 7502 | |
| 7503 | snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf); |
| 7504 | if (system(buf) != 0) { |
| 7505 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7506 | "iwpriv %s nss failed", intf); |
| 7507 | } |
| 7508 | |
| 7509 | #ifdef NL80211_SUPPORT |
| 7510 | ret = sta_set_he_mcs(dut, intf, HE_80_MCS0_7); |
| 7511 | if (ret) { |
| 7512 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7513 | "Setting of MCS failed, ret:%d", |
| 7514 | ret); |
| 7515 | } |
| 7516 | #endif /* NL80211_SUPPORT */ |
Amarnath Hullur Subramanyam | c67621d | 2018-02-04 23:18:01 -0800 | [diff] [blame] | 7517 | |
| 7518 | /* Disable STBC as default */ |
| 7519 | wcn_sta_set_stbc(dut, intf, "0"); |
Amarnath Hullur Subramanyam | d5bb573 | 2018-02-22 15:50:38 -0800 | [diff] [blame] | 7520 | |
| 7521 | /* Disable AMSDU as default */ |
| 7522 | iwpriv_sta_set_amsdu(dut, intf, "0"); |
Amarnath Hullur Subramanyam | 474a17d | 2018-02-22 18:45:54 -0800 | [diff] [blame] | 7523 | |
| 7524 | #ifdef NL80211_SUPPORT |
| 7525 | /* HE fragmentation default off */ |
| 7526 | if (sta_set_he_fragmentation(dut, intf, |
| 7527 | HE_FRAG_DISABLE)) { |
| 7528 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7529 | "Setting of HE fragmentation failed"); |
| 7530 | } |
Kiran Kumar Lokere | bad5112 | 2018-12-12 19:03:36 -0800 | [diff] [blame] | 7531 | |
| 7532 | /* set the beamformee NSTS(maximum number of |
| 7533 | * space-time streams) to default testbed config |
| 7534 | */ |
| 7535 | if (sta_set_beamformee_sts(dut, intf, 3)) { |
| 7536 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7537 | "Failed to set BeamformeeSTS"); |
| 7538 | } |
| 7539 | |
Kiran Kumar Lokere | e5ed442 | 2018-12-18 18:25:02 -0800 | [diff] [blame] | 7540 | /* +HTC-HE support default off */ |
| 7541 | if (sta_set_he_htc_supp(dut, intf, 0)) { |
| 7542 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7543 | "Setting of +HTC-HE support failed"); |
| 7544 | } |
Kiran Kumar Lokere | 765bdd8 | 2019-02-24 22:14:43 -0800 | [diff] [blame] | 7545 | |
| 7546 | /* Set device HE capabilities to testbed default |
| 7547 | * configuration. */ |
| 7548 | if (sta_set_he_testbed_def(dut, intf, 1)) { |
| 7549 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 7550 | "Failed to set HE defaults"); |
| 7551 | } |
Kiran Kumar Lokere | 642f7ce | 2019-02-25 18:28:10 -0800 | [diff] [blame] | 7552 | |
| 7553 | /* Disable VHT support in 2.4 GHz for testbed */ |
| 7554 | sta_set_2g_vht_supp(dut, intf, 0); |
Amarnath Hullur Subramanyam | 474a17d | 2018-02-22 18:45:54 -0800 | [diff] [blame] | 7555 | #endif /* NL80211_SUPPORT */ |
Amarnath Hullur Subramanyam | 4622a21 | 2018-02-23 12:12:14 -0800 | [diff] [blame] | 7556 | |
| 7557 | /* Enable WEP/TKIP with HE capability in testbed */ |
| 7558 | if (sta_set_heconfig_and_wep_tkip(dut, intf, 1)) { |
| 7559 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7560 | "Enabling HE config with WEP/TKIP failed"); |
| 7561 | } |
Amarnath Hullur Subramanyam | 2538acc | 2018-02-02 16:15:25 -0800 | [diff] [blame] | 7562 | } |
Amarnath Hullur Subramanyam | 0acce2c | 2018-03-06 06:05:17 -0800 | [diff] [blame] | 7563 | |
| 7564 | /* Defaults in case of DUT */ |
| 7565 | if (type && strcasecmp(type, "DUT") == 0) { |
Arif Hussain | d48fcc7 | 2018-05-01 18:34:18 -0700 | [diff] [blame] | 7566 | /* Enable STBC by default */ |
| 7567 | wcn_sta_set_stbc(dut, intf, "1"); |
| 7568 | |
Amarnath Hullur Subramanyam | 0acce2c | 2018-03-06 06:05:17 -0800 | [diff] [blame] | 7569 | /* set nss to 2 */ |
| 7570 | snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf); |
| 7571 | if (system(buf) != 0) { |
| 7572 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7573 | "iwpriv %s nss 2 failed", intf); |
| 7574 | } |
Arif Hussain | ac6c511 | 2018-05-25 17:34:00 -0700 | [diff] [blame] | 7575 | dut->sta_nss = 2; |
Amarnath Hullur Subramanyam | 0acce2c | 2018-03-06 06:05:17 -0800 | [diff] [blame] | 7576 | |
| 7577 | #ifdef NL80211_SUPPORT |
Arif Hussain | ae23984 | 2018-05-01 18:20:05 -0700 | [diff] [blame] | 7578 | /* Set HE_MCS to 0-11 */ |
| 7579 | if (sta_set_he_mcs(dut, intf, HE_80_MCS0_11)) { |
Amarnath Hullur Subramanyam | 0acce2c | 2018-03-06 06:05:17 -0800 | [diff] [blame] | 7580 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7581 | "Setting of MCS failed"); |
| 7582 | } |
| 7583 | #endif /* NL80211_SUPPORT */ |
| 7584 | |
| 7585 | /* Disable WEP/TKIP with HE capability in DUT */ |
| 7586 | if (sta_set_heconfig_and_wep_tkip(dut, intf, 0)) { |
| 7587 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7588 | "Enabling HE config with WEP/TKIP failed"); |
| 7589 | } |
| 7590 | } |
Amarnath Hullur Subramanyam | 58f2a6e | 2018-01-31 03:36:00 -0800 | [diff] [blame] | 7591 | } |
| 7592 | } |
| 7593 | |
| 7594 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 7595 | static enum sigma_cmd_result cmd_sta_reset_default(struct sigma_dut *dut, |
| 7596 | struct sigma_conn *conn, |
| 7597 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7598 | { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7599 | const char *intf = get_param(cmd, "Interface"); |
Alexei Avshalom Lazar | 33f700c | 2018-12-18 16:00:39 +0200 | [diff] [blame] | 7600 | const char *band = get_param(cmd, "band"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7601 | const char *type; |
Amarnath Hullur Subramanyam | 9c381f5 | 2017-03-17 00:04:41 -0700 | [diff] [blame] | 7602 | const char *program = get_param(cmd, "program"); |
Ankita Bajaj | 0d5825b | 2017-10-25 16:20:17 +0530 | [diff] [blame] | 7603 | const char *dev_role = get_param(cmd, "DevRole"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7604 | |
Amarnath Hullur Subramanyam | 9c381f5 | 2017-03-17 00:04:41 -0700 | [diff] [blame] | 7605 | if (!program) |
| 7606 | program = get_param(cmd, "prog"); |
| 7607 | dut->program = sigma_program_to_enum(program); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7608 | dut->device_type = STA_unknown; |
| 7609 | type = get_param(cmd, "type"); |
| 7610 | if (type && strcasecmp(type, "Testbed") == 0) |
| 7611 | dut->device_type = STA_testbed; |
| 7612 | if (type && strcasecmp(type, "DUT") == 0) |
| 7613 | dut->device_type = STA_dut; |
| 7614 | |
| 7615 | if (dut->program == PROGRAM_TDLS) { |
| 7616 | /* Clear TDLS testing mode */ |
| 7617 | wpa_command(intf, "SET tdls_disabled 0"); |
| 7618 | wpa_command(intf, "SET tdls_testing 0"); |
| 7619 | dut->no_tpk_expiration = 0; |
Pradeep Reddy POTTETI | 8ce2a23 | 2016-10-28 12:17:32 +0530 | [diff] [blame] | 7620 | if (get_driver_type() == DRIVER_WCN) { |
| 7621 | /* Enable the WCN driver in TDLS Explicit trigger mode |
| 7622 | */ |
| 7623 | wpa_command(intf, "SET tdls_external_control 0"); |
| 7624 | wpa_command(intf, "SET tdls_trigger_control 0"); |
| 7625 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7626 | } |
| 7627 | |
Amarnath Hullur Subramanyam | 9c381f5 | 2017-03-17 00:04:41 -0700 | [diff] [blame] | 7628 | #ifdef MIRACAST |
| 7629 | if (dut->program == PROGRAM_WFD || |
| 7630 | dut->program == PROGRAM_DISPLAYR2) |
| 7631 | miracast_sta_reset_default(dut, conn, cmd); |
| 7632 | #endif /* MIRACAST */ |
| 7633 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7634 | switch (get_driver_type()) { |
| 7635 | case DRIVER_ATHEROS: |
| 7636 | sta_reset_default_ath(dut, intf, type); |
| 7637 | break; |
Amarnath Hullur Subramanyam | 58f2a6e | 2018-01-31 03:36:00 -0800 | [diff] [blame] | 7638 | case DRIVER_WCN: |
| 7639 | sta_reset_default_wcn(dut, intf, type); |
| 7640 | break; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7641 | default: |
| 7642 | break; |
| 7643 | } |
| 7644 | |
| 7645 | #ifdef ANDROID_NAN |
| 7646 | if (dut->program == PROGRAM_NAN) |
| 7647 | nan_cmd_sta_reset_default(dut, conn, cmd); |
| 7648 | #endif /* ANDROID_NAN */ |
| 7649 | |
Vinay Gannevaram | 3b9fdd3 | 2019-06-14 17:55:44 +0530 | [diff] [blame] | 7650 | if (dut->program == PROGRAM_LOC && |
| 7651 | lowi_cmd_sta_reset_default(dut, conn, cmd) < 0) |
| 7652 | return ERROR_SEND_STATUS; |
| 7653 | |
Jouni Malinen | ba63045 | 2018-06-22 11:49:59 +0300 | [diff] [blame] | 7654 | if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7655 | unlink("SP/wi-fi.org/pps.xml"); |
| 7656 | if (system("rm -r SP/*") != 0) { |
| 7657 | } |
| 7658 | unlink("next-client-cert.pem"); |
| 7659 | unlink("next-client-key.pem"); |
| 7660 | } |
| 7661 | |
Alexei Avshalom Lazar | 33f700c | 2018-12-18 16:00:39 +0200 | [diff] [blame] | 7662 | /* For WPS program of the 60 GHz band the band type needs to be saved */ |
| 7663 | if (dut->program == PROGRAM_WPS) { |
| 7664 | if (band && strcasecmp(band, "60GHz") == 0) { |
| 7665 | dut->band = WPS_BAND_60G; |
Alexei Avshalom Lazar | eee9ab0 | 2018-12-24 16:27:48 +0200 | [diff] [blame] | 7666 | /* For 60 GHz enable WPS for WPS TCs */ |
| 7667 | dut->wps_disable = 0; |
Alexei Avshalom Lazar | 33f700c | 2018-12-18 16:00:39 +0200 | [diff] [blame] | 7668 | } else { |
| 7669 | dut->band = WPS_BAND_NON_60G; |
| 7670 | } |
Alexei Avshalom Lazar | eee9ab0 | 2018-12-24 16:27:48 +0200 | [diff] [blame] | 7671 | } else if (dut->program == PROGRAM_60GHZ) { |
| 7672 | /* For 60 GHz MAC/PHY TCs WPS must be disabled */ |
| 7673 | dut->wps_disable = 1; |
Alexei Avshalom Lazar | 33f700c | 2018-12-18 16:00:39 +0200 | [diff] [blame] | 7674 | } |
| 7675 | |
Alexei Avshalom Lazar | 157ba06 | 2018-12-23 16:15:26 +0200 | [diff] [blame] | 7676 | if (is_60g_sigma_dut(dut)) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7677 | const char *dev_role = get_param(cmd, "DevRole"); |
Alexei Avshalom Lazar | c2a5bb1 | 2018-12-23 16:12:06 +0200 | [diff] [blame] | 7678 | char buf[256]; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7679 | |
Alexei Avshalom Lazar | eee9ab0 | 2018-12-24 16:27:48 +0200 | [diff] [blame] | 7680 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 7681 | "WPS 60 GHz program, wps_disable = %d", |
| 7682 | dut->wps_disable); |
| 7683 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7684 | if (!dev_role) { |
| 7685 | send_resp(dut, conn, SIGMA_ERROR, |
| 7686 | "errorCode,Missing DevRole argument"); |
| 7687 | return 0; |
| 7688 | } |
| 7689 | |
| 7690 | if (strcasecmp(dev_role, "STA") == 0) |
| 7691 | dut->dev_role = DEVROLE_STA; |
| 7692 | else if (strcasecmp(dev_role, "PCP") == 0) |
| 7693 | dut->dev_role = DEVROLE_PCP; |
| 7694 | else { |
| 7695 | send_resp(dut, conn, SIGMA_ERROR, |
| 7696 | "errorCode,Unknown DevRole"); |
| 7697 | return 0; |
| 7698 | } |
| 7699 | |
| 7700 | if (dut->device_type == STA_unknown) { |
| 7701 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7702 | "Device type is not STA testbed or DUT"); |
| 7703 | send_resp(dut, conn, SIGMA_ERROR, |
| 7704 | "errorCode,Unknown device type"); |
| 7705 | return 0; |
| 7706 | } |
Alexei Avshalom Lazar | c2a5bb1 | 2018-12-23 16:12:06 +0200 | [diff] [blame] | 7707 | |
| 7708 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 7709 | "Setting msdu_size to MAX: 7912"); |
| 7710 | snprintf(buf, sizeof(buf), "ifconfig %s mtu 7912", |
| 7711 | get_station_ifname()); |
| 7712 | |
| 7713 | if (system(buf) != 0) { |
| 7714 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s", |
| 7715 | buf); |
Jouni Malinen | 0e29cf2 | 2019-02-19 01:13:21 +0200 | [diff] [blame] | 7716 | return ERROR_SEND_STATUS; |
Alexei Avshalom Lazar | c2a5bb1 | 2018-12-23 16:12:06 +0200 | [diff] [blame] | 7717 | } |
Alexei Avshalom Lazar | aad97b0 | 2018-12-18 16:01:23 +0200 | [diff] [blame] | 7718 | |
| 7719 | if (sta_set_force_mcs(dut, 0, 1)) { |
| 7720 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 7721 | "Failed to reset force MCS"); |
Jouni Malinen | 0e29cf2 | 2019-02-19 01:13:21 +0200 | [diff] [blame] | 7722 | return ERROR_SEND_STATUS; |
Alexei Avshalom Lazar | aad97b0 | 2018-12-18 16:01:23 +0200 | [diff] [blame] | 7723 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7724 | } |
| 7725 | |
| 7726 | wpa_command(intf, "WPS_ER_STOP"); |
| 7727 | wpa_command(intf, "FLUSH"); |
vamsi krishna | f39bc1e | 2017-08-23 17:37:53 +0530 | [diff] [blame] | 7728 | wpa_command(intf, "ERP_FLUSH"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7729 | wpa_command(intf, "SET radio_disabled 0"); |
| 7730 | |
Alexei Avshalom Lazar | 744ae8a | 2019-01-31 17:26:46 +0200 | [diff] [blame] | 7731 | dut->wps_forced_version = 0; |
| 7732 | |
Alexei Avshalom Lazar | 33f700c | 2018-12-18 16:00:39 +0200 | [diff] [blame] | 7733 | if (dut->wsc_fragment) { |
| 7734 | dut->wsc_fragment = 0; |
| 7735 | wpa_command(intf, "SET device_name Test client"); |
| 7736 | wpa_command(intf, "SET manufacturer "); |
| 7737 | wpa_command(intf, "SET model_name "); |
| 7738 | wpa_command(intf, "SET model_number "); |
| 7739 | wpa_command(intf, "SET serial_number "); |
| 7740 | } |
Alexei Avshalom Lazar | b094bf0 | 2018-12-18 16:00:53 +0200 | [diff] [blame] | 7741 | if (is_60g_sigma_dut(dut) && dut->force_rsn_ie) { |
| 7742 | dut->force_rsn_ie = FORCE_RSN_IE_NONE; |
| 7743 | sta_60g_force_rsn_ie(dut, FORCE_RSN_IE_NONE); |
| 7744 | } |
Alexei Avshalom Lazar | 33f700c | 2018-12-18 16:00:39 +0200 | [diff] [blame] | 7745 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7746 | if (dut->tmp_mac_addr && dut->set_macaddr) { |
| 7747 | dut->tmp_mac_addr = 0; |
| 7748 | if (system(dut->set_macaddr) != 0) { |
| 7749 | sigma_dut_print(dut, DUT_MSG_INFO, "Failed to clear " |
| 7750 | "temporary MAC address"); |
| 7751 | } |
| 7752 | } |
| 7753 | |
| 7754 | set_ps(intf, dut, 0); |
| 7755 | |
Jouni Malinen | ba63045 | 2018-06-22 11:49:59 +0300 | [diff] [blame] | 7756 | if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2 || |
| 7757 | dut->program == PROGRAM_HS2_R3) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7758 | wpa_command(intf, "SET interworking 1"); |
| 7759 | wpa_command(intf, "SET hs20 1"); |
| 7760 | } |
| 7761 | |
Deepak Dhamdhere | 0fe0e45 | 2017-12-18 14:52:09 -0800 | [diff] [blame] | 7762 | if (dut->program == PROGRAM_HS2_R2 || |
Jouni Malinen | ba63045 | 2018-06-22 11:49:59 +0300 | [diff] [blame] | 7763 | dut->program == PROGRAM_HS2_R3 || |
Deepak Dhamdhere | 0fe0e45 | 2017-12-18 14:52:09 -0800 | [diff] [blame] | 7764 | dut->program == PROGRAM_OCE) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7765 | wpa_command(intf, "SET pmf 1"); |
| 7766 | } else { |
| 7767 | wpa_command(intf, "SET pmf 0"); |
| 7768 | } |
| 7769 | |
| 7770 | hs2_clear_credentials(intf); |
| 7771 | wpa_command(intf, "SET hessid 00:00:00:00:00:00"); |
| 7772 | wpa_command(intf, "SET access_network_type 15"); |
| 7773 | |
| 7774 | static_ip_file(0, NULL, NULL, NULL); |
| 7775 | kill_dhcp_client(dut, intf); |
| 7776 | clear_ip_addr(dut, intf); |
| 7777 | |
| 7778 | dut->er_oper_performed = 0; |
| 7779 | dut->er_oper_bssid[0] = '\0'; |
| 7780 | |
priyadharshini gowthaman | ad6cbba | 2016-10-04 10:39:58 -0700 | [diff] [blame] | 7781 | if (dut->program == PROGRAM_LOC) { |
| 7782 | /* Disable Interworking by default */ |
| 7783 | wpa_command(get_station_ifname(), "SET interworking 0"); |
| 7784 | } |
| 7785 | |
Ashwini Patil | 0040258 | 2017-04-13 12:29:39 +0530 | [diff] [blame] | 7786 | if (dut->program == PROGRAM_MBO) { |
| 7787 | free(dut->non_pref_ch_list); |
| 7788 | dut->non_pref_ch_list = NULL; |
Ashwini Patil | 5acd738 | 2017-04-13 15:55:04 +0530 | [diff] [blame] | 7789 | free(dut->btm_query_cand_list); |
| 7790 | dut->btm_query_cand_list = NULL; |
Ashwini Patil | c63161e | 2017-04-13 16:30:23 +0530 | [diff] [blame] | 7791 | wpa_command(intf, "SET reject_btm_req_reason 0"); |
Ashwini Patil | a75de5a | 2017-04-13 16:35:05 +0530 | [diff] [blame] | 7792 | wpa_command(intf, "SET ignore_assoc_disallow 0"); |
Ashwini Patil | d174f2c | 2017-04-13 16:49:46 +0530 | [diff] [blame] | 7793 | wpa_command(intf, "SET gas_address3 0"); |
Ashwini Patil | 9183fdb | 2017-04-13 16:58:25 +0530 | [diff] [blame] | 7794 | wpa_command(intf, "SET roaming 1"); |
Ankita Bajaj | 1d97455 | 2018-09-18 16:56:44 +0530 | [diff] [blame] | 7795 | wpa_command(intf, "SET interworking 1"); |
Ashwini Patil | 0040258 | 2017-04-13 12:29:39 +0530 | [diff] [blame] | 7796 | } |
| 7797 | |
Jouni Malinen | 3c367e8 | 2017-06-23 17:01:47 +0300 | [diff] [blame] | 7798 | free(dut->rsne_override); |
| 7799 | dut->rsne_override = NULL; |
| 7800 | |
Jouni Malinen | 6814313 | 2017-09-02 02:34:08 +0300 | [diff] [blame] | 7801 | free(dut->sae_commit_override); |
| 7802 | dut->sae_commit_override = NULL; |
Jouni Malinen | 4b3769d | 2019-10-10 16:20:29 +0300 | [diff] [blame^] | 7803 | wpa_command(intf, "SET sae_pmkid_in_assoc 0"); |
Jouni Malinen | 6814313 | 2017-09-02 02:34:08 +0300 | [diff] [blame] | 7804 | |
Jouni Malinen | 134fe3c | 2019-06-12 04:16:49 +0300 | [diff] [blame] | 7805 | dut->sta_associate_wait_connect = 0; |
| 7806 | dut->server_cert_hash[0] = '\0'; |
Jouni Malinen | 37d5c69 | 2019-08-19 16:56:55 +0300 | [diff] [blame] | 7807 | dut->server_cert_tod = 0; |
Jouni Malinen | 134fe3c | 2019-06-12 04:16:49 +0300 | [diff] [blame] | 7808 | dut->sta_tod_policy = 0; |
| 7809 | |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 7810 | dut->dpp_conf_id = -1; |
Jouni Malinen | b1dd21f | 2017-11-13 19:14:29 +0200 | [diff] [blame] | 7811 | free(dut->dpp_peer_uri); |
| 7812 | dut->dpp_peer_uri = NULL; |
Jouni Malinen | 63d5041 | 2017-11-24 11:55:38 +0200 | [diff] [blame] | 7813 | dut->dpp_local_bootstrap = -1; |
Jouni Malinen | 5011fb5 | 2017-12-05 21:00:15 +0200 | [diff] [blame] | 7814 | wpa_command(intf, "SET dpp_config_processing 2"); |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 7815 | |
Jouni Malinen | fac9cad | 2017-10-10 18:35:55 +0300 | [diff] [blame] | 7816 | wpa_command(intf, "VENDOR_ELEM_REMOVE 13 *"); |
| 7817 | |
vamsi krishna | a279949 | 2017-12-05 14:28:01 +0530 | [diff] [blame] | 7818 | if (dut->program == PROGRAM_OCE) { |
Ankita Bajaj | a2cb567 | 2017-10-25 16:08:28 +0530 | [diff] [blame] | 7819 | wpa_command(intf, "SET oce 1"); |
vamsi krishna | a279949 | 2017-12-05 14:28:01 +0530 | [diff] [blame] | 7820 | wpa_command(intf, "SET disable_fils 0"); |
Ankita Bajaj | 1bde794 | 2018-01-09 19:15:01 +0530 | [diff] [blame] | 7821 | wpa_command(intf, "FILS_HLP_REQ_FLUSH"); |
| 7822 | dut->fils_hlp = 0; |
| 7823 | #ifdef ANDROID |
| 7824 | hlp_thread_cleanup(dut); |
| 7825 | #endif /* ANDROID */ |
vamsi krishna | a279949 | 2017-12-05 14:28:01 +0530 | [diff] [blame] | 7826 | } |
Ankita Bajaj | a2cb567 | 2017-10-25 16:08:28 +0530 | [diff] [blame] | 7827 | |
Jouni Malinen | 8179fee | 2019-03-28 03:19:47 +0200 | [diff] [blame] | 7828 | dut->akm_values = 0; |
Jouni Malinen | 6a7c9b4 | 2019-08-20 00:15:59 +0300 | [diff] [blame] | 7829 | dut->sta_ft_ds = 0; |
Jouni Malinen | 8179fee | 2019-03-28 03:19:47 +0200 | [diff] [blame] | 7830 | |
Sunil Dutt | 076081f | 2018-02-05 19:45:50 +0530 | [diff] [blame] | 7831 | #ifdef NL80211_SUPPORT |
Sunil Dutt | 4459508 | 2018-02-12 19:41:45 +0530 | [diff] [blame] | 7832 | if (get_driver_type() == DRIVER_WCN && |
| 7833 | dut->config_rsnie == 1) { |
| 7834 | dut->config_rsnie = 0; |
| 7835 | sta_config_rsnie(dut, 0); |
Sunil Dutt | 076081f | 2018-02-05 19:45:50 +0530 | [diff] [blame] | 7836 | } |
| 7837 | #endif /* NL80211_SUPPORT */ |
| 7838 | |
Sunil Dutt | febf8a8 | 2018-02-09 18:50:13 +0530 | [diff] [blame] | 7839 | if (dev_role && strcasecmp(dev_role, "STA-CFON") == 0) { |
| 7840 | dut->dev_role = DEVROLE_STA_CFON; |
| 7841 | return sta_cfon_reset_default(dut, conn, cmd); |
| 7842 | } |
| 7843 | |
Jouni Malinen | 439352d | 2018-09-13 03:42:23 +0300 | [diff] [blame] | 7844 | wpa_command(intf, "SET setband AUTO"); |
| 7845 | |
Sunil Dutt | febf8a8 | 2018-02-09 18:50:13 +0530 | [diff] [blame] | 7846 | if (dut->program != PROGRAM_VHT) |
| 7847 | return cmd_sta_p2p_reset(dut, conn, cmd); |
| 7848 | |
Priyadharshini Gowthaman | a7dfd49 | 2015-11-09 14:34:08 -0800 | [diff] [blame] | 7849 | return 1; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7850 | } |
| 7851 | |
| 7852 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 7853 | static enum sigma_cmd_result cmd_sta_get_events(struct sigma_dut *dut, |
| 7854 | struct sigma_conn *conn, |
| 7855 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7856 | { |
| 7857 | const char *program = get_param(cmd, "Program"); |
| 7858 | |
| 7859 | if (program == NULL) |
| 7860 | return -1; |
| 7861 | #ifdef ANDROID_NAN |
| 7862 | if (strcasecmp(program, "NAN") == 0) |
| 7863 | return nan_cmd_sta_get_events(dut, conn, cmd); |
| 7864 | #endif /* ANDROID_NAN */ |
| 7865 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter"); |
| 7866 | return 0; |
| 7867 | } |
| 7868 | |
| 7869 | |
Jouni Malinen | 8290520 | 2018-04-29 17:20:10 +0300 | [diff] [blame] | 7870 | static int sta_exec_action_url(struct sigma_dut *dut, struct sigma_conn *conn, |
| 7871 | struct sigma_cmd *cmd) |
| 7872 | { |
| 7873 | const char *url = get_param(cmd, "url"); |
| 7874 | const char *method = get_param(cmd, "method"); |
| 7875 | pid_t pid; |
| 7876 | int status; |
| 7877 | |
| 7878 | if (!url || !method) |
| 7879 | return -1; |
| 7880 | |
| 7881 | /* TODO: Add support for method,post */ |
| 7882 | if (strcasecmp(method, "get") != 0) { |
| 7883 | send_resp(dut, conn, SIGMA_ERROR, |
| 7884 | "ErrorCode,Unsupported method"); |
| 7885 | return 0; |
| 7886 | } |
| 7887 | |
| 7888 | pid = fork(); |
| 7889 | if (pid < 0) { |
| 7890 | perror("fork"); |
| 7891 | return -1; |
| 7892 | } |
| 7893 | |
| 7894 | if (pid == 0) { |
| 7895 | char * argv[5] = { "wget", "-O", "/dev/null", |
| 7896 | (char *) url, NULL }; |
| 7897 | |
| 7898 | execv("/usr/bin/wget", argv); |
| 7899 | perror("execv"); |
| 7900 | exit(0); |
| 7901 | return -1; |
| 7902 | } |
| 7903 | |
| 7904 | if (waitpid(pid, &status, 0) < 0) { |
| 7905 | perror("waitpid"); |
| 7906 | return -1; |
| 7907 | } |
| 7908 | |
| 7909 | if (WIFEXITED(status)) { |
| 7910 | const char *errmsg; |
| 7911 | |
| 7912 | if (WEXITSTATUS(status) == 0) |
| 7913 | return 1; |
| 7914 | sigma_dut_print(dut, DUT_MSG_INFO, "wget exit status %d", |
| 7915 | WEXITSTATUS(status)); |
| 7916 | switch (WEXITSTATUS(status)) { |
| 7917 | case 4: |
| 7918 | errmsg = "errmsg,Network failure"; |
| 7919 | break; |
| 7920 | case 8: |
| 7921 | errmsg = "errmsg,Server issued an error response"; |
| 7922 | break; |
| 7923 | default: |
| 7924 | errmsg = "errmsg,Unknown failure from wget"; |
| 7925 | break; |
| 7926 | } |
| 7927 | send_resp(dut, conn, SIGMA_ERROR, errmsg); |
| 7928 | return 0; |
| 7929 | } |
| 7930 | |
| 7931 | send_resp(dut, conn, SIGMA_ERROR, "errmsg,Unknown failure"); |
| 7932 | return 0; |
| 7933 | } |
| 7934 | |
| 7935 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 7936 | static enum sigma_cmd_result cmd_sta_exec_action(struct sigma_dut *dut, |
| 7937 | struct sigma_conn *conn, |
| 7938 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7939 | { |
| 7940 | const char *program = get_param(cmd, "Prog"); |
| 7941 | |
Jouni Malinen | 8290520 | 2018-04-29 17:20:10 +0300 | [diff] [blame] | 7942 | if (program && !get_param(cmd, "interface")) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7943 | return -1; |
| 7944 | #ifdef ANDROID_NAN |
Jouni Malinen | 8290520 | 2018-04-29 17:20:10 +0300 | [diff] [blame] | 7945 | if (program && strcasecmp(program, "NAN") == 0) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7946 | return nan_cmd_sta_exec_action(dut, conn, cmd); |
| 7947 | #endif /* ANDROID_NAN */ |
Jouni Malinen | 8290520 | 2018-04-29 17:20:10 +0300 | [diff] [blame] | 7948 | |
| 7949 | if (program && strcasecmp(program, "Loc") == 0) |
priyadharshini gowthaman | d66913a | 2016-07-29 15:11:17 -0700 | [diff] [blame] | 7950 | return loc_cmd_sta_exec_action(dut, conn, cmd); |
Jouni Malinen | 8290520 | 2018-04-29 17:20:10 +0300 | [diff] [blame] | 7951 | |
| 7952 | if (get_param(cmd, "url")) |
| 7953 | return sta_exec_action_url(dut, conn, cmd); |
| 7954 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7955 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter"); |
| 7956 | return 0; |
| 7957 | } |
| 7958 | |
| 7959 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 7960 | static enum sigma_cmd_result cmd_sta_set_11n(struct sigma_dut *dut, |
| 7961 | struct sigma_conn *conn, |
| 7962 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 7963 | { |
| 7964 | const char *intf = get_param(cmd, "Interface"); |
| 7965 | const char *val, *mcs32, *rate; |
| 7966 | |
| 7967 | val = get_param(cmd, "GREENFIELD"); |
| 7968 | if (val) { |
| 7969 | if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) { |
| 7970 | /* Enable GD */ |
| 7971 | send_resp(dut, conn, SIGMA_ERROR, |
| 7972 | "ErrorCode,GF not supported"); |
| 7973 | return 0; |
| 7974 | } |
| 7975 | } |
| 7976 | |
| 7977 | val = get_param(cmd, "SGI20"); |
| 7978 | if (val) { |
| 7979 | switch (get_driver_type()) { |
| 7980 | case DRIVER_ATHEROS: |
| 7981 | ath_sta_set_sgi(dut, intf, val); |
| 7982 | break; |
| 7983 | default: |
| 7984 | send_resp(dut, conn, SIGMA_ERROR, |
| 7985 | "ErrorCode,SGI20 not supported"); |
| 7986 | return 0; |
| 7987 | } |
| 7988 | } |
| 7989 | |
| 7990 | mcs32 = get_param(cmd, "MCS32"); /* HT Duplicate Mode Enable/Disable */ |
| 7991 | rate = get_param(cmd, "MCS_FIXEDRATE"); /* Fixed MCS rate (0..31) */ |
| 7992 | if (mcs32 && rate) { |
| 7993 | /* TODO */ |
| 7994 | send_resp(dut, conn, SIGMA_ERROR, |
| 7995 | "ErrorCode,MCS32,MCS_FIXEDRATE not supported"); |
| 7996 | return 0; |
| 7997 | } else if (mcs32 && !rate) { |
| 7998 | /* TODO */ |
| 7999 | send_resp(dut, conn, SIGMA_ERROR, |
| 8000 | "ErrorCode,MCS32 not supported"); |
| 8001 | return 0; |
| 8002 | } else if (!mcs32 && rate) { |
| 8003 | switch (get_driver_type()) { |
| 8004 | case DRIVER_ATHEROS: |
Priyadharshini Gowthaman | 8c5b9a4 | 2019-07-31 14:38:48 -0700 | [diff] [blame] | 8005 | novap_reset(dut, intf, 1); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8006 | ath_sta_set_11nrates(dut, intf, rate); |
| 8007 | break; |
| 8008 | default: |
| 8009 | send_resp(dut, conn, SIGMA_ERROR, |
| 8010 | "ErrorCode,MCS32_FIXEDRATE not supported"); |
| 8011 | return 0; |
| 8012 | } |
| 8013 | } |
| 8014 | |
| 8015 | return cmd_sta_set_wireless_common(intf, dut, conn, cmd); |
| 8016 | } |
| 8017 | |
| 8018 | |
Arif Hussain | 7b47d2d | 2018-05-09 10:44:02 -0700 | [diff] [blame] | 8019 | static void cmd_set_max_he_mcs(struct sigma_dut *dut, const char *intf, |
| 8020 | int mcs_config) |
| 8021 | { |
| 8022 | #ifdef NL80211_SUPPORT |
| 8023 | int ret; |
| 8024 | |
| 8025 | switch (mcs_config) { |
| 8026 | case HE_80_MCS0_7: |
| 8027 | case HE_80_MCS0_9: |
| 8028 | case HE_80_MCS0_11: |
| 8029 | ret = sta_set_he_mcs(dut, intf, mcs_config); |
| 8030 | if (ret) { |
| 8031 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8032 | "cmd_set_max_he_mcs: Setting of MCS:%d failed, ret:%d", |
| 8033 | mcs_config, ret); |
| 8034 | } |
| 8035 | break; |
| 8036 | default: |
| 8037 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8038 | "cmd_set_max_he_mcs: Invalid mcs %d", |
| 8039 | mcs_config); |
| 8040 | break; |
| 8041 | } |
| 8042 | #else /* NL80211_SUPPORT */ |
| 8043 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8044 | "max HE MCS cannot be changed without NL80211_SUPPORT defined"); |
| 8045 | #endif /* NL80211_SUPPORT */ |
| 8046 | } |
| 8047 | |
| 8048 | |
Arif Hussain | 480d5f4 | 2019-03-12 14:40:42 -0700 | [diff] [blame] | 8049 | static int sta_twt_request(struct sigma_dut *dut, struct sigma_conn *conn, |
| 8050 | struct sigma_cmd *cmd) |
| 8051 | { |
| 8052 | #ifdef NL80211_SUPPORT |
| 8053 | struct nlattr *params; |
| 8054 | struct nlattr *attr; |
| 8055 | struct nlattr *attr1; |
| 8056 | struct nl_msg *msg; |
| 8057 | int ifindex, ret; |
| 8058 | const char *val; |
| 8059 | const char *intf = get_param(cmd, "Interface"); |
| 8060 | int wake_interval_exp = 10, nominal_min_wake_dur = 255, |
| 8061 | wake_interval_mantissa = 512; |
| 8062 | int flow_type = 0, twt_trigger = 0, target_wake_time = 0, |
| 8063 | protection = 0; |
| 8064 | |
| 8065 | ifindex = if_nametoindex(intf); |
| 8066 | if (ifindex == 0) { |
| 8067 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8068 | "%s: Index for interface %s failed", |
| 8069 | __func__, intf); |
| 8070 | return -1; |
| 8071 | } |
| 8072 | |
| 8073 | val = get_param(cmd, "FlowType"); |
| 8074 | if (val) { |
| 8075 | flow_type = atoi(val); |
| 8076 | if (flow_type != 0 && flow_type != 1) { |
| 8077 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8078 | "TWT: Invalid FlowType %d", flow_type); |
| 8079 | return -1; |
| 8080 | } |
| 8081 | } |
| 8082 | |
| 8083 | val = get_param(cmd, "TWT_Trigger"); |
| 8084 | if (val) { |
| 8085 | twt_trigger = atoi(val); |
| 8086 | if (twt_trigger != 0 && twt_trigger != 1) { |
| 8087 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8088 | "TWT: Invalid TWT_Trigger %d", |
| 8089 | twt_trigger); |
| 8090 | return -1; |
| 8091 | } |
| 8092 | } |
| 8093 | |
| 8094 | val = get_param(cmd, "Protection"); |
| 8095 | if (val) { |
| 8096 | protection = atoi(val); |
| 8097 | if (protection != 0 && protection != 1) { |
| 8098 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8099 | "TWT: Invalid Protection %d", |
| 8100 | protection); |
| 8101 | return -1; |
| 8102 | } |
| 8103 | } |
| 8104 | |
| 8105 | val = get_param(cmd, "TargetWakeTime"); |
| 8106 | if (val) |
| 8107 | target_wake_time = atoi(val); |
| 8108 | |
| 8109 | val = get_param(cmd, "WakeIntervalMantissa"); |
| 8110 | if (val) |
| 8111 | wake_interval_mantissa = atoi(val); |
| 8112 | |
| 8113 | val = get_param(cmd, "WakeIntervalExp"); |
| 8114 | if (val) |
| 8115 | wake_interval_exp = atoi(val); |
| 8116 | |
| 8117 | val = get_param(cmd, "NominalMinWakeDur"); |
| 8118 | if (val) |
| 8119 | nominal_min_wake_dur = atoi(val); |
| 8120 | |
| 8121 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 8122 | NL80211_CMD_VENDOR)) || |
| 8123 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 8124 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 8125 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 8126 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || |
| 8127 | !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 8128 | !(params = nla_nest_start( |
| 8129 | msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_TWT_SETUP)) || |
| 8130 | !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 8131 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_EXP, |
| 8132 | wake_interval_exp) || |
Arif Hussain | 480d5f4 | 2019-03-12 14:40:42 -0700 | [diff] [blame] | 8133 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_REQ_TYPE, 1) || |
Kiran Kumar Lokere | 2cffae5 | 2019-09-26 18:44:15 -0700 | [diff] [blame] | 8134 | (twt_trigger && |
| 8135 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_TRIGGER)) || |
Arif Hussain | 480d5f4 | 2019-03-12 14:40:42 -0700 | [diff] [blame] | 8136 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE, |
| 8137 | flow_type) || |
Kiran Kumar Lokere | 2cffae5 | 2019-09-26 18:44:15 -0700 | [diff] [blame] | 8138 | (protection && |
| 8139 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_PROTECTION)) || |
Arif Hussain | 480d5f4 | 2019-03-12 14:40:42 -0700 | [diff] [blame] | 8140 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_TIME, |
| 8141 | target_wake_time) || |
| 8142 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_DURATION, |
| 8143 | nominal_min_wake_dur) || |
| 8144 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_MANTISSA, |
| 8145 | wake_interval_mantissa)) { |
| 8146 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8147 | "%s: err in adding vendor_cmd and vendor_data", |
| 8148 | __func__); |
| 8149 | nlmsg_free(msg); |
| 8150 | return -1; |
| 8151 | } |
| 8152 | nla_nest_end(msg, attr1); |
| 8153 | nla_nest_end(msg, params); |
| 8154 | nla_nest_end(msg, attr); |
| 8155 | |
| 8156 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 8157 | if (ret) { |
| 8158 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8159 | "%s: err in send_and_recv_msgs, ret=%d", |
| 8160 | __func__, ret); |
| 8161 | } |
| 8162 | |
| 8163 | return ret; |
| 8164 | #else /* NL80211_SUPPORT */ |
| 8165 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8166 | "TWT request cannot be done without NL80211_SUPPORT defined"); |
| 8167 | return -1; |
| 8168 | #endif /* NL80211_SUPPORT */ |
| 8169 | } |
| 8170 | |
| 8171 | |
| 8172 | static int sta_twt_teardown(struct sigma_dut *dut, struct sigma_conn *conn, |
| 8173 | struct sigma_cmd *cmd) |
| 8174 | { |
| 8175 | #ifdef NL80211_SUPPORT |
| 8176 | struct nlattr *params; |
| 8177 | struct nlattr *attr; |
| 8178 | struct nlattr *attr1; |
| 8179 | int ifindex, ret; |
| 8180 | struct nl_msg *msg; |
| 8181 | const char *intf = get_param(cmd, "Interface"); |
| 8182 | |
| 8183 | ifindex = if_nametoindex(intf); |
| 8184 | if (ifindex == 0) { |
| 8185 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8186 | "%s: Index for interface %s failed", |
| 8187 | __func__, intf); |
| 8188 | return -1; |
| 8189 | } |
| 8190 | |
| 8191 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 8192 | NL80211_CMD_VENDOR)) || |
| 8193 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 8194 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 8195 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 8196 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || |
| 8197 | !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 8198 | !(params = nla_nest_start( |
| 8199 | msg, |
| 8200 | QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_TWT_TERMINATE)) || |
| 8201 | !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 8202 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE, 0)) { |
| 8203 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8204 | "%s: err in adding vendor_cmd and vendor_data", |
| 8205 | __func__); |
| 8206 | nlmsg_free(msg); |
| 8207 | return -1; |
| 8208 | } |
| 8209 | nla_nest_end(msg, attr1); |
| 8210 | nla_nest_end(msg, params); |
| 8211 | nla_nest_end(msg, attr); |
| 8212 | |
| 8213 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 8214 | if (ret) { |
| 8215 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8216 | "%s: err in send_and_recv_msgs, ret=%d", |
| 8217 | __func__, ret); |
| 8218 | } |
| 8219 | |
| 8220 | return ret; |
| 8221 | #else /* NL80211_SUPPORT */ |
| 8222 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8223 | "TWT teardown cannot be done without NL80211_SUPPORT defined"); |
| 8224 | return -1; |
| 8225 | #endif /* NL80211_SUPPORT */ |
| 8226 | } |
| 8227 | |
| 8228 | |
Kiran Kumar Lokere | 50eb2cd | 2018-12-18 18:31:28 -0800 | [diff] [blame] | 8229 | static int sta_transmit_omi(struct sigma_dut *dut, struct sigma_conn *conn, |
| 8230 | struct sigma_cmd *cmd) |
| 8231 | { |
| 8232 | #ifdef NL80211_SUPPORT |
| 8233 | struct nlattr *params; |
| 8234 | struct nlattr *attr; |
| 8235 | struct nlattr *attr1; |
| 8236 | struct nl_msg *msg; |
| 8237 | int ifindex, ret; |
| 8238 | const char *val; |
| 8239 | const char *intf = get_param(cmd, "Interface"); |
| 8240 | uint8_t rx_nss = 0xFF, ch_bw = 0xFF, tx_nsts = 0xFF, ulmu_dis = 0, |
| 8241 | ulmu_data_dis = 0; |
| 8242 | |
| 8243 | ifindex = if_nametoindex(intf); |
| 8244 | if (ifindex == 0) { |
| 8245 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8246 | "%s: Index for interface %s failed", |
| 8247 | __func__, intf); |
| 8248 | return -1; |
| 8249 | } |
| 8250 | val = get_param(cmd, "OMCtrl_RxNSS"); |
| 8251 | if (val) |
| 8252 | rx_nss = atoi(val); |
| 8253 | |
| 8254 | val = get_param(cmd, "OMCtrl_ChnlWidth"); |
| 8255 | if (val) |
| 8256 | ch_bw = atoi(val); |
| 8257 | |
| 8258 | val = get_param(cmd, "OMCtrl_ULMUDisable"); |
| 8259 | if (val) |
| 8260 | ulmu_dis = atoi(val); |
| 8261 | |
| 8262 | val = get_param(cmd, "OMCtrl_TxNSTS"); |
| 8263 | if (val) |
| 8264 | tx_nsts = atoi(val); |
| 8265 | |
| 8266 | val = get_param(cmd, "OMCtrl_ULMUDataDisable"); |
| 8267 | if (val) |
| 8268 | ulmu_data_dis = atoi(val); |
| 8269 | |
| 8270 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 8271 | NL80211_CMD_VENDOR)) || |
| 8272 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 8273 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 8274 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 8275 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || |
| 8276 | !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 8277 | !(params = nla_nest_start( |
| 8278 | msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OMI_TX)) || |
| 8279 | !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 8280 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_RX_NSS, rx_nss) || |
| 8281 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_CH_BW, ch_bw) || |
| 8282 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_TX_NSTS, tx_nsts) || |
| 8283 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DATA_DISABLE, |
| 8284 | ulmu_data_dis) || |
| 8285 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DISABLE, |
| 8286 | ulmu_dis)) { |
| 8287 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8288 | "%s: err in adding vendor_cmd and vendor_data", |
| 8289 | __func__); |
| 8290 | nlmsg_free(msg); |
| 8291 | return -1; |
| 8292 | } |
| 8293 | nla_nest_end(msg, attr1); |
| 8294 | nla_nest_end(msg, params); |
| 8295 | nla_nest_end(msg, attr); |
| 8296 | |
| 8297 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 8298 | if (ret) { |
| 8299 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8300 | "%s: err in send_and_recv_msgs, ret=%d", |
| 8301 | __func__, ret); |
| 8302 | } |
| 8303 | |
| 8304 | return ret; |
| 8305 | #else /* NL80211_SUPPORT */ |
| 8306 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8307 | "OMI TX cannot be processed without NL80211_SUPPORT defined"); |
| 8308 | return -1; |
| 8309 | #endif /* NL80211_SUPPORT */ |
| 8310 | } |
| 8311 | |
| 8312 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8313 | static int cmd_sta_set_wireless_vht(struct sigma_dut *dut, |
| 8314 | struct sigma_conn *conn, |
| 8315 | struct sigma_cmd *cmd) |
| 8316 | { |
| 8317 | const char *intf = get_param(cmd, "Interface"); |
| 8318 | const char *val; |
Arif Hussain | a37e955 | 2018-06-20 17:05:59 -0700 | [diff] [blame] | 8319 | const char *program; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8320 | int tkip = -1; |
| 8321 | int wep = -1; |
| 8322 | |
Arif Hussain | a37e955 | 2018-06-20 17:05:59 -0700 | [diff] [blame] | 8323 | program = get_param(cmd, "Program"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8324 | val = get_param(cmd, "SGI80"); |
| 8325 | if (val) { |
| 8326 | int sgi80; |
| 8327 | |
| 8328 | sgi80 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0; |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 8329 | run_iwpriv(dut, intf, "shortgi %d", sgi80); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8330 | } |
| 8331 | |
| 8332 | val = get_param(cmd, "TxBF"); |
| 8333 | if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) { |
Kiran Kumar Lokere | cb57d82 | 2018-07-06 16:37:42 -0700 | [diff] [blame] | 8334 | switch (get_driver_type()) { |
| 8335 | case DRIVER_WCN: |
| 8336 | if (sta_set_tx_beamformee(dut, intf, 1)) { |
| 8337 | send_resp(dut, conn, SIGMA_ERROR, |
| 8338 | "ErrorCode,Failed to set TX beamformee enable"); |
| 8339 | return 0; |
| 8340 | } |
| 8341 | break; |
| 8342 | case DRIVER_ATHEROS: |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 8343 | if (run_iwpriv(dut, intf, "vhtsubfee 1") < 0) { |
Kiran Kumar Lokere | cb57d82 | 2018-07-06 16:37:42 -0700 | [diff] [blame] | 8344 | send_resp(dut, conn, SIGMA_ERROR, |
| 8345 | "ErrorCode,Setting vhtsubfee failed"); |
| 8346 | return 0; |
| 8347 | } |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 8348 | if (run_iwpriv(dut, intf, "vhtsubfer 1") < 0) { |
Kiran Kumar Lokere | cb57d82 | 2018-07-06 16:37:42 -0700 | [diff] [blame] | 8349 | send_resp(dut, conn, SIGMA_ERROR, |
| 8350 | "ErrorCode,Setting vhtsubfer failed"); |
| 8351 | return 0; |
| 8352 | } |
| 8353 | break; |
| 8354 | default: |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8355 | sigma_dut_print(dut, DUT_MSG_ERROR, |
Kiran Kumar Lokere | cb57d82 | 2018-07-06 16:37:42 -0700 | [diff] [blame] | 8356 | "Unsupported driver type"); |
| 8357 | break; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8358 | } |
| 8359 | } |
| 8360 | |
| 8361 | val = get_param(cmd, "MU_TxBF"); |
| 8362 | if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) { |
| 8363 | switch (get_driver_type()) { |
| 8364 | case DRIVER_ATHEROS: |
| 8365 | ath_sta_set_txsp_stream(dut, intf, "1SS"); |
| 8366 | ath_sta_set_rxsp_stream(dut, intf, "1SS"); |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 8367 | run_iwpriv(dut, intf, "vhtmubfee 1"); |
| 8368 | run_iwpriv(dut, intf, "vhtmubfer 1"); |
Sunil Dutt | ae9e5d1 | 2018-06-29 11:50:47 +0530 | [diff] [blame] | 8369 | break; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8370 | case DRIVER_WCN: |
| 8371 | if (wcn_sta_set_sp_stream(dut, intf, "1SS") < 0) { |
| 8372 | send_resp(dut, conn, SIGMA_ERROR, |
| 8373 | "ErrorCode,Failed to set RX/TXSP_STREAM"); |
| 8374 | return 0; |
| 8375 | } |
Sunil Dutt | ae9e5d1 | 2018-06-29 11:50:47 +0530 | [diff] [blame] | 8376 | break; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8377 | default: |
| 8378 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8379 | "Setting SP_STREAM not supported"); |
| 8380 | break; |
| 8381 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8382 | } |
| 8383 | |
| 8384 | val = get_param(cmd, "LDPC"); |
| 8385 | if (val) { |
| 8386 | int ldpc; |
| 8387 | |
| 8388 | ldpc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0; |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 8389 | run_iwpriv(dut, intf, "ldpc %d", ldpc); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8390 | } |
| 8391 | |
Amarnath Hullur Subramanyam | 7bae60e | 2018-01-31 03:46:50 -0800 | [diff] [blame] | 8392 | val = get_param(cmd, "BCC"); |
| 8393 | if (val) { |
| 8394 | int bcc; |
| 8395 | |
| 8396 | bcc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0; |
| 8397 | /* use LDPC iwpriv itself to set bcc coding, bcc coding |
| 8398 | * is mutually exclusive to bcc */ |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 8399 | run_iwpriv(dut, intf, "ldpc %d", !bcc); |
Amarnath Hullur Subramanyam | 7bae60e | 2018-01-31 03:46:50 -0800 | [diff] [blame] | 8400 | } |
| 8401 | |
Arif Hussain | 7b47d2d | 2018-05-09 10:44:02 -0700 | [diff] [blame] | 8402 | val = get_param(cmd, "MaxHE-MCS_1SS_RxMapLTE80"); |
| 8403 | if (val && dut->sta_nss == 1) |
| 8404 | cmd_set_max_he_mcs(dut, intf, atoi(val)); |
| 8405 | |
| 8406 | val = get_param(cmd, "MaxHE-MCS_2SS_RxMapLTE80"); |
| 8407 | if (val && dut->sta_nss == 2) |
| 8408 | cmd_set_max_he_mcs(dut, intf, atoi(val)); |
| 8409 | |
Arif Hussain | ac6c511 | 2018-05-25 17:34:00 -0700 | [diff] [blame] | 8410 | val = get_param(cmd, "MCS_FixedRate"); |
| 8411 | if (val) { |
| 8412 | #ifdef NL80211_SUPPORT |
| 8413 | int mcs, ratecode = 0; |
| 8414 | enum he_mcs_config mcs_config; |
| 8415 | int ret; |
Jouni Malinen | b9b671d | 2019-04-26 13:23:17 +0300 | [diff] [blame] | 8416 | char buf[60]; |
Arif Hussain | ac6c511 | 2018-05-25 17:34:00 -0700 | [diff] [blame] | 8417 | |
| 8418 | ratecode = (0x07 & dut->sta_nss) << 5; |
| 8419 | mcs = atoi(val); |
| 8420 | /* Add the MCS to the ratecode */ |
| 8421 | if (mcs >= 0 && mcs <= 11) { |
| 8422 | ratecode += mcs; |
| 8423 | if (dut->device_type == STA_testbed && |
| 8424 | mcs > 7 && mcs <= 11) { |
| 8425 | if (mcs <= 9) |
| 8426 | mcs_config = HE_80_MCS0_9; |
| 8427 | else |
| 8428 | mcs_config = HE_80_MCS0_11; |
| 8429 | ret = sta_set_he_mcs(dut, intf, mcs_config); |
| 8430 | if (ret) { |
| 8431 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8432 | "MCS_FixedRate: mcs setting failed, mcs:%d, mcs_config %d, ret:%d", |
| 8433 | mcs, mcs_config, ret); |
| 8434 | } |
| 8435 | } |
| 8436 | snprintf(buf, sizeof(buf), |
| 8437 | "iwpriv %s set_11ax_rate 0x%03x", |
| 8438 | intf, ratecode); |
| 8439 | if (system(buf) != 0) { |
| 8440 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8441 | "MCS_FixedRate: iwpriv setting of 11ax rates 0x%03x failed", |
| 8442 | ratecode); |
| 8443 | } |
| 8444 | } else { |
| 8445 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8446 | "MCS_FixedRate: HE MCS %d not supported", |
| 8447 | mcs); |
| 8448 | } |
| 8449 | #else /* NL80211_SUPPORT */ |
| 8450 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8451 | "MCS_FixedRate cannot be changed without NL80211_SUPPORT defined"); |
| 8452 | #endif /* NL80211_SUPPORT */ |
| 8453 | } |
| 8454 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8455 | val = get_param(cmd, "opt_md_notif_ie"); |
| 8456 | if (val) { |
| 8457 | char *result = NULL; |
| 8458 | char delim[] = ";"; |
| 8459 | char token[30]; |
| 8460 | int value, config_val = 0; |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 8461 | char *saveptr; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8462 | |
Peng Xu | b8fc5cc | 2017-05-10 17:27:28 -0700 | [diff] [blame] | 8463 | strlcpy(token, val, sizeof(token)); |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 8464 | result = strtok_r(token, delim, &saveptr); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8465 | |
| 8466 | /* Extract the NSS information */ |
| 8467 | if (result) { |
| 8468 | value = atoi(result); |
| 8469 | switch (value) { |
| 8470 | case 1: |
| 8471 | config_val = 1; |
| 8472 | break; |
| 8473 | case 2: |
| 8474 | config_val = 3; |
| 8475 | break; |
| 8476 | case 3: |
| 8477 | config_val = 7; |
| 8478 | break; |
| 8479 | case 4: |
| 8480 | config_val = 15; |
| 8481 | break; |
| 8482 | default: |
| 8483 | config_val = 3; |
| 8484 | break; |
| 8485 | } |
| 8486 | |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 8487 | run_iwpriv(dut, intf, "rxchainmask %d", config_val); |
| 8488 | run_iwpriv(dut, intf, "txchainmask %d", config_val); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8489 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8490 | } |
| 8491 | |
| 8492 | /* Extract the channel width information */ |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 8493 | result = strtok_r(NULL, delim, &saveptr); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8494 | if (result) { |
| 8495 | value = atoi(result); |
| 8496 | switch (value) { |
| 8497 | case 20: |
| 8498 | config_val = 0; |
| 8499 | break; |
| 8500 | case 40: |
| 8501 | config_val = 1; |
| 8502 | break; |
| 8503 | case 80: |
| 8504 | config_val = 2; |
| 8505 | break; |
| 8506 | case 160: |
| 8507 | config_val = 3; |
| 8508 | break; |
| 8509 | default: |
| 8510 | config_val = 2; |
| 8511 | break; |
| 8512 | } |
| 8513 | |
| 8514 | dut->chwidth = config_val; |
| 8515 | |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 8516 | run_iwpriv(dut, intf, "chwidth %d", config_val); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8517 | } |
| 8518 | |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 8519 | run_iwpriv(dut, intf, "opmode_notify 1"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8520 | } |
| 8521 | |
| 8522 | val = get_param(cmd, "nss_mcs_cap"); |
| 8523 | if (val) { |
| 8524 | int nss, mcs; |
| 8525 | char token[20]; |
| 8526 | char *result = NULL; |
| 8527 | unsigned int vht_mcsmap = 0; |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 8528 | char *saveptr; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8529 | |
Peng Xu | b8fc5cc | 2017-05-10 17:27:28 -0700 | [diff] [blame] | 8530 | strlcpy(token, val, sizeof(token)); |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 8531 | result = strtok_r(token, ";", &saveptr); |
Pradeep Reddy POTTETI | cd649a2 | 2016-01-29 12:55:59 +0530 | [diff] [blame] | 8532 | if (!result) { |
| 8533 | sigma_dut_print(dut, DUT_MSG_ERROR, |
Arif Hussain | a37e955 | 2018-06-20 17:05:59 -0700 | [diff] [blame] | 8534 | "NSS not specified"); |
| 8535 | send_resp(dut, conn, SIGMA_ERROR, |
| 8536 | "errorCode,NSS not specified"); |
Pradeep Reddy POTTETI | cd649a2 | 2016-01-29 12:55:59 +0530 | [diff] [blame] | 8537 | return 0; |
| 8538 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8539 | nss = atoi(result); |
| 8540 | |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 8541 | run_iwpriv(dut, intf, "nss %d", nss); |
Arif Hussain | ac6c511 | 2018-05-25 17:34:00 -0700 | [diff] [blame] | 8542 | dut->sta_nss = nss; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8543 | |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 8544 | result = strtok_r(NULL, ";", &saveptr); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8545 | if (result == NULL) { |
| 8546 | sigma_dut_print(dut, DUT_MSG_ERROR, |
Arif Hussain | a37e955 | 2018-06-20 17:05:59 -0700 | [diff] [blame] | 8547 | "MCS not specified"); |
| 8548 | send_resp(dut, conn, SIGMA_ERROR, |
| 8549 | "errorCode,MCS not specified"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8550 | return 0; |
| 8551 | } |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 8552 | result = strtok_r(result, "-", &saveptr); |
| 8553 | result = strtok_r(NULL, "-", &saveptr); |
Pradeep Reddy POTTETI | cd649a2 | 2016-01-29 12:55:59 +0530 | [diff] [blame] | 8554 | if (!result) { |
| 8555 | sigma_dut_print(dut, DUT_MSG_ERROR, |
Arif Hussain | a37e955 | 2018-06-20 17:05:59 -0700 | [diff] [blame] | 8556 | "MCS not specified"); |
| 8557 | send_resp(dut, conn, SIGMA_ERROR, |
| 8558 | "errorCode,MCS not specified"); |
Pradeep Reddy POTTETI | cd649a2 | 2016-01-29 12:55:59 +0530 | [diff] [blame] | 8559 | return 0; |
| 8560 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8561 | mcs = atoi(result); |
| 8562 | |
Arif Hussain | a37e955 | 2018-06-20 17:05:59 -0700 | [diff] [blame] | 8563 | if (program && strcasecmp(program, "HE") == 0) { |
| 8564 | #ifdef NL80211_SUPPORT |
| 8565 | enum he_mcs_config mcs_config; |
| 8566 | int ret; |
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 | if (mcs >= 0 && mcs <= 7) { |
| 8569 | mcs_config = HE_80_MCS0_7; |
| 8570 | } else if (mcs > 7 && mcs <= 9) { |
| 8571 | mcs_config = HE_80_MCS0_9; |
| 8572 | } else if (mcs > 9 && mcs <= 11) { |
| 8573 | mcs_config = HE_80_MCS0_11; |
| 8574 | } else { |
| 8575 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8576 | "nss_mcs_cap: HE: Invalid mcs: %d", |
| 8577 | mcs); |
| 8578 | send_resp(dut, conn, SIGMA_ERROR, |
| 8579 | "errorCode,Invalid MCS"); |
| 8580 | return 0; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8581 | } |
Arif Hussain | a37e955 | 2018-06-20 17:05:59 -0700 | [diff] [blame] | 8582 | |
| 8583 | ret = sta_set_he_mcs(dut, intf, mcs_config); |
| 8584 | if (ret) { |
| 8585 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8586 | "nss_mcs_cap: HE: Setting of MCS failed, mcs_config: %d, ret: %d", |
| 8587 | mcs_config, ret); |
| 8588 | send_resp(dut, conn, SIGMA_ERROR, |
| 8589 | "errorCode,Failed to set MCS"); |
| 8590 | return 0; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8591 | } |
Arif Hussain | a37e955 | 2018-06-20 17:05:59 -0700 | [diff] [blame] | 8592 | #else /* NL80211_SUPPORT */ |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8593 | sigma_dut_print(dut, DUT_MSG_ERROR, |
Arif Hussain | a37e955 | 2018-06-20 17:05:59 -0700 | [diff] [blame] | 8594 | "nss_mcs_cap: HE: MCS cannot be changed without NL80211_SUPPORT defined"); |
| 8595 | #endif /* NL80211_SUPPORT */ |
| 8596 | } else { |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 8597 | run_iwpriv(dut, intf, "vhtmcs %d", mcs); |
Arif Hussain | a37e955 | 2018-06-20 17:05:59 -0700 | [diff] [blame] | 8598 | |
| 8599 | switch (nss) { |
| 8600 | case 1: |
| 8601 | switch (mcs) { |
| 8602 | case 7: |
| 8603 | vht_mcsmap = 0xfffc; |
| 8604 | break; |
| 8605 | case 8: |
| 8606 | vht_mcsmap = 0xfffd; |
| 8607 | break; |
| 8608 | case 9: |
| 8609 | vht_mcsmap = 0xfffe; |
| 8610 | break; |
| 8611 | default: |
| 8612 | vht_mcsmap = 0xfffe; |
| 8613 | break; |
| 8614 | } |
| 8615 | break; |
| 8616 | case 2: |
| 8617 | switch (mcs) { |
| 8618 | case 7: |
| 8619 | vht_mcsmap = 0xfff0; |
| 8620 | break; |
| 8621 | case 8: |
| 8622 | vht_mcsmap = 0xfff5; |
| 8623 | break; |
| 8624 | case 9: |
| 8625 | vht_mcsmap = 0xfffa; |
| 8626 | break; |
| 8627 | default: |
| 8628 | vht_mcsmap = 0xfffa; |
| 8629 | break; |
| 8630 | } |
| 8631 | break; |
| 8632 | case 3: |
| 8633 | switch (mcs) { |
| 8634 | case 7: |
| 8635 | vht_mcsmap = 0xffc0; |
| 8636 | break; |
| 8637 | case 8: |
| 8638 | vht_mcsmap = 0xffd5; |
| 8639 | break; |
| 8640 | case 9: |
| 8641 | vht_mcsmap = 0xffea; |
| 8642 | break; |
| 8643 | default: |
| 8644 | vht_mcsmap = 0xffea; |
| 8645 | break; |
| 8646 | } |
| 8647 | break; |
| 8648 | default: |
| 8649 | vht_mcsmap = 0xffea; |
| 8650 | break; |
| 8651 | } |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 8652 | run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8653 | } |
| 8654 | } |
| 8655 | |
| 8656 | /* UNSUPPORTED: val = get_param(cmd, "Tx_lgi_rate"); */ |
| 8657 | |
| 8658 | val = get_param(cmd, "Vht_tkip"); |
| 8659 | if (val) |
| 8660 | tkip = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0; |
| 8661 | |
| 8662 | val = get_param(cmd, "Vht_wep"); |
| 8663 | if (val) |
| 8664 | wep = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0; |
| 8665 | |
| 8666 | if (tkip != -1 || wep != -1) { |
| 8667 | if ((tkip == 1 && wep != 0) || (wep == 1 && tkip != 0)) { |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 8668 | run_iwpriv(dut, intf, "htweptkip 1"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8669 | } else if ((tkip == 0 && wep != 1) || (wep == 0 && tkip != 1)) { |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 8670 | run_iwpriv(dut, intf, "htweptkip 0"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8671 | } else { |
| 8672 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8673 | "ErrorCode,mixed mode of VHT TKIP/WEP not supported"); |
| 8674 | return 0; |
| 8675 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8676 | } |
| 8677 | |
Arif Hussain | 55f00da | 2018-07-03 08:28:26 -0700 | [diff] [blame] | 8678 | val = get_param(cmd, "txBandwidth"); |
| 8679 | if (val) { |
| 8680 | switch (get_driver_type()) { |
| 8681 | case DRIVER_WCN: |
| 8682 | if (wcn_sta_set_width(dut, intf, val) < 0) { |
| 8683 | send_resp(dut, conn, SIGMA_ERROR, |
| 8684 | "ErrorCode,Failed to set txBandwidth"); |
| 8685 | return 0; |
| 8686 | } |
| 8687 | break; |
| 8688 | case DRIVER_ATHEROS: |
| 8689 | if (ath_set_width(dut, conn, intf, val) < 0) { |
| 8690 | send_resp(dut, conn, SIGMA_ERROR, |
| 8691 | "ErrorCode,Failed to set txBandwidth"); |
| 8692 | return 0; |
| 8693 | } |
| 8694 | break; |
| 8695 | default: |
| 8696 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8697 | "Setting txBandwidth not supported"); |
| 8698 | break; |
| 8699 | } |
| 8700 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8701 | |
Arif Hussain | 9765f7d | 2018-07-03 08:28:26 -0700 | [diff] [blame] | 8702 | val = get_param(cmd, "BeamformeeSTS"); |
| 8703 | if (val) { |
Kiran Kumar Lokere | bc89d43 | 2018-07-10 12:20:13 -0700 | [diff] [blame] | 8704 | if (sta_set_tx_beamformee(dut, intf, 1)) { |
| 8705 | send_resp(dut, conn, SIGMA_ERROR, |
| 8706 | "ErrorCode,Failed to set TX beamformee enable"); |
| 8707 | return 0; |
| 8708 | } |
| 8709 | |
Arif Hussain | 9765f7d | 2018-07-03 08:28:26 -0700 | [diff] [blame] | 8710 | if (sta_set_beamformee_sts(dut, intf, atoi(val))) { |
| 8711 | send_resp(dut, conn, SIGMA_ERROR, |
| 8712 | "ErrorCode,Failed to set BeamformeeSTS"); |
| 8713 | return 0; |
| 8714 | } |
| 8715 | } |
| 8716 | |
Arif Hussain | 68d23f5 | 2018-07-11 13:39:08 -0700 | [diff] [blame] | 8717 | val = get_param(cmd, "Trig_MAC_Padding_Dur"); |
| 8718 | if (val) { |
Kiran Kumar Lokere | 55eb558 | 2018-08-19 20:03:26 -0700 | [diff] [blame] | 8719 | #ifdef NL80211_SUPPORT |
| 8720 | enum qca_wlan_he_mac_padding_dur set_val; |
| 8721 | |
| 8722 | switch (atoi(val)) { |
| 8723 | case 16: |
| 8724 | set_val = QCA_WLAN_HE_16US_OF_PROCESS_TIME; |
| 8725 | break; |
| 8726 | case 8: |
| 8727 | set_val = QCA_WLAN_HE_8US_OF_PROCESS_TIME; |
| 8728 | break; |
| 8729 | default: |
| 8730 | set_val = QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME; |
| 8731 | break; |
| 8732 | } |
| 8733 | if (sta_set_mac_padding_duration(dut, intf, set_val)) { |
Arif Hussain | 68d23f5 | 2018-07-11 13:39:08 -0700 | [diff] [blame] | 8734 | send_resp(dut, conn, SIGMA_ERROR, |
| 8735 | "ErrorCode,Failed to set MAC padding duration"); |
| 8736 | return 0; |
| 8737 | } |
Kiran Kumar Lokere | 55eb558 | 2018-08-19 20:03:26 -0700 | [diff] [blame] | 8738 | #else /* NL80211_SUPPORT */ |
| 8739 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8740 | "MAC padding duration cannot be changed without NL80211_SUPPORT defined"); |
| 8741 | #endif /* NL80211_SUPPORT */ |
Arif Hussain | 68d23f5 | 2018-07-11 13:39:08 -0700 | [diff] [blame] | 8742 | } |
| 8743 | |
Arif Hussain | 480d5f4 | 2019-03-12 14:40:42 -0700 | [diff] [blame] | 8744 | val = get_param(cmd, "TWT_ReqSupport"); |
| 8745 | if (val) { |
| 8746 | int set_val; |
| 8747 | |
| 8748 | if (strcasecmp(val, "Enable") == 0) { |
| 8749 | set_val = 1; |
| 8750 | } else if (strcasecmp(val, "Disable") == 0) { |
| 8751 | set_val = 0; |
| 8752 | } else { |
| 8753 | send_resp(dut, conn, SIGMA_ERROR, |
| 8754 | "ErrorCode,Invalid TWT_ReqSupport"); |
| 8755 | return STATUS_SENT; |
| 8756 | } |
| 8757 | |
| 8758 | if (sta_set_twt_req_support(dut, intf, set_val)) { |
| 8759 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8760 | "Failed to set TWT req support %d", |
| 8761 | set_val); |
| 8762 | send_resp(dut, conn, SIGMA_ERROR, |
| 8763 | "ErrorCode,Failed to set TWT_ReqSupport"); |
| 8764 | return STATUS_SENT; |
| 8765 | } |
| 8766 | } |
| 8767 | |
Kiran Kumar Lokere | b101268 | 2018-08-08 17:48:32 -0700 | [diff] [blame] | 8768 | val = get_param(cmd, "MU_EDCA"); |
| 8769 | if (val && (strcasecmp(val, "Override") == 0)) { |
| 8770 | if (sta_set_mu_edca_override(dut, intf, 1)) { |
| 8771 | send_resp(dut, conn, SIGMA_ERROR, |
| 8772 | "ErrorCode,Failed to set MU EDCA override"); |
| 8773 | return 0; |
| 8774 | } |
| 8775 | } |
Kiran Kumar Lokere | c658182 | 2018-08-01 16:18:34 -0700 | [diff] [blame] | 8776 | |
Kiran Kumar Lokere | de33e37 | 2018-08-29 16:26:24 -0700 | [diff] [blame] | 8777 | val = get_param(cmd, "OMControl"); |
| 8778 | if (val) { |
| 8779 | int set_val = 1; |
| 8780 | |
| 8781 | if (strcasecmp(val, "Enable") == 0) |
| 8782 | set_val = 1; |
| 8783 | else if (strcasecmp(val, "Disable") == 0) |
| 8784 | set_val = 0; |
| 8785 | |
| 8786 | if (sta_set_om_ctrl_supp(dut, intf, set_val)) { |
| 8787 | send_resp(dut, conn, SIGMA_ERROR, |
| 8788 | "ErrorCode,Failed to set OM ctrl supp"); |
| 8789 | return 0; |
| 8790 | } |
| 8791 | } |
| 8792 | |
Kiran Kumar Lokere | c658182 | 2018-08-01 16:18:34 -0700 | [diff] [blame] | 8793 | val = get_param(cmd, "ADDBAResp_BufSize"); |
| 8794 | if (val) { |
| 8795 | int buf_size; |
| 8796 | |
| 8797 | if (strcasecmp(val, "gt64") == 0) |
| 8798 | buf_size = 256; |
| 8799 | else |
| 8800 | buf_size = 64; |
| 8801 | if (get_driver_type() == DRIVER_WCN && |
| 8802 | sta_set_addba_buf_size(dut, intf, buf_size)) { |
| 8803 | send_resp(dut, conn, SIGMA_ERROR, |
| 8804 | "ErrorCode,set addbaresp_buff_size failed"); |
| 8805 | return 0; |
| 8806 | } |
| 8807 | } |
| 8808 | |
| 8809 | val = get_param(cmd, "ADDBAReq_BufSize"); |
| 8810 | if (val) { |
| 8811 | int buf_size; |
| 8812 | |
| 8813 | if (strcasecmp(val, "gt64") == 0) |
| 8814 | buf_size = 256; |
| 8815 | else |
| 8816 | buf_size = 64; |
| 8817 | if (get_driver_type() == DRIVER_WCN && |
| 8818 | sta_set_addba_buf_size(dut, intf, buf_size)) { |
| 8819 | send_resp(dut, conn, SIGMA_ERROR, |
| 8820 | "ErrorCode,set addbareq_buff_size failed"); |
| 8821 | return 0; |
| 8822 | } |
| 8823 | } |
| 8824 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8825 | return cmd_sta_set_wireless_common(intf, dut, conn, cmd); |
| 8826 | } |
| 8827 | |
| 8828 | |
| 8829 | static int sta_set_wireless_60g(struct sigma_dut *dut, |
| 8830 | struct sigma_conn *conn, |
| 8831 | struct sigma_cmd *cmd) |
| 8832 | { |
| 8833 | const char *dev_role = get_param(cmd, "DevRole"); |
| 8834 | |
| 8835 | if (!dev_role) { |
| 8836 | send_resp(dut, conn, SIGMA_INVALID, |
| 8837 | "ErrorCode,DevRole not specified"); |
| 8838 | return 0; |
| 8839 | } |
| 8840 | |
| 8841 | if (strcasecmp(dev_role, "PCP") == 0) |
| 8842 | return sta_set_60g_pcp(dut, conn, cmd); |
| 8843 | if (strcasecmp(dev_role, "STA") == 0) |
| 8844 | return sta_set_60g_sta(dut, conn, cmd); |
| 8845 | send_resp(dut, conn, SIGMA_INVALID, |
| 8846 | "ErrorCode,DevRole not supported"); |
| 8847 | return 0; |
| 8848 | } |
| 8849 | |
| 8850 | |
Ankita Bajaj | 0d5825b | 2017-10-25 16:20:17 +0530 | [diff] [blame] | 8851 | static int sta_set_wireless_oce(struct sigma_dut *dut, struct sigma_conn *conn, |
| 8852 | struct sigma_cmd *cmd) |
| 8853 | { |
| 8854 | int status; |
| 8855 | const char *intf = get_param(cmd, "Interface"); |
| 8856 | const char *val = get_param(cmd, "DevRole"); |
| 8857 | |
| 8858 | if (val && strcasecmp(val, "STA-CFON") == 0) { |
| 8859 | status = sta_cfon_set_wireless(dut, conn, cmd); |
| 8860 | if (status) |
| 8861 | return status; |
| 8862 | } |
| 8863 | return cmd_sta_set_wireless_common(intf, dut, conn, cmd); |
| 8864 | } |
| 8865 | |
| 8866 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 8867 | static enum sigma_cmd_result cmd_sta_set_wireless(struct sigma_dut *dut, |
| 8868 | struct sigma_conn *conn, |
| 8869 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8870 | { |
| 8871 | const char *val; |
| 8872 | |
| 8873 | val = get_param(cmd, "Program"); |
| 8874 | if (val) { |
| 8875 | if (strcasecmp(val, "11n") == 0) |
| 8876 | return cmd_sta_set_11n(dut, conn, cmd); |
Amarnath Hullur Subramanyam | 4f86029 | 2018-01-31 03:49:35 -0800 | [diff] [blame] | 8877 | if (strcasecmp(val, "VHT") == 0 || strcasecmp(val, "HE") == 0) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8878 | return cmd_sta_set_wireless_vht(dut, conn, cmd); |
| 8879 | if (strcasecmp(val, "60ghz") == 0) |
| 8880 | return sta_set_wireless_60g(dut, conn, cmd); |
Ankita Bajaj | 0d5825b | 2017-10-25 16:20:17 +0530 | [diff] [blame] | 8881 | if (strcasecmp(val, "OCE") == 0) |
| 8882 | return sta_set_wireless_oce(dut, conn, cmd); |
Alexei Avshalom Lazar | 66bb997 | 2018-12-18 16:01:43 +0200 | [diff] [blame] | 8883 | /* sta_set_wireless in WPS program is only used for 60G */ |
| 8884 | if (is_60g_sigma_dut(dut)) |
| 8885 | return sta_set_wireless_60g(dut, conn, cmd); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8886 | send_resp(dut, conn, SIGMA_ERROR, |
| 8887 | "ErrorCode,Program value not supported"); |
| 8888 | } else { |
| 8889 | send_resp(dut, conn, SIGMA_ERROR, |
| 8890 | "ErrorCode,Program argument not available"); |
| 8891 | } |
| 8892 | |
| 8893 | return 0; |
| 8894 | } |
| 8895 | |
| 8896 | |
| 8897 | static void ath_sta_inject_frame(struct sigma_dut *dut, const char *intf, |
| 8898 | int tid) |
| 8899 | { |
| 8900 | char buf[100]; |
| 8901 | int tid_to_dscp [] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 }; |
| 8902 | |
Pradeep Reddy POTTETI | d31d132 | 2016-10-13 17:22:03 +0530 | [diff] [blame] | 8903 | if (tid < 0 || |
| 8904 | tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) { |
| 8905 | sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid); |
| 8906 | return; |
| 8907 | } |
| 8908 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8909 | /* |
| 8910 | * Two ways to ensure that addba request with a |
| 8911 | * non zero TID could be sent out. EV 117296 |
| 8912 | */ |
| 8913 | snprintf(buf, sizeof(buf), |
| 8914 | "ping -c 8 -Q %d `arp -a | grep wlan0 | awk '{print $2}' | tr -d '()'`", |
| 8915 | tid); |
| 8916 | if (system(buf) != 0) { |
| 8917 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8918 | "Ping did not send out"); |
| 8919 | } |
| 8920 | |
| 8921 | snprintf(buf, sizeof(buf), |
| 8922 | "iwconfig %s | grep Access | awk '{print $6}' > %s", |
| 8923 | intf, VI_QOS_TMP_FILE); |
| 8924 | if (system(buf) != 0) |
| 8925 | return; |
| 8926 | |
| 8927 | snprintf(buf, sizeof(buf), |
| 8928 | "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s", |
| 8929 | intf, VI_QOS_TMP_FILE); |
| 8930 | if (system(buf) != 0) |
| 8931 | sigma_dut_print(dut, DUT_MSG_ERROR, "HWaddr matching failed"); |
| 8932 | |
| 8933 | snprintf(buf,sizeof(buf), "sed -n '3,$p' %s >> %s", |
| 8934 | VI_QOS_REFFILE, VI_QOS_TMP_FILE); |
| 8935 | if (system(buf) != 0) { |
| 8936 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8937 | "VI_QOS_TEMP_FILE generation error failed"); |
| 8938 | } |
| 8939 | snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s", |
| 8940 | tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE); |
| 8941 | if (system(buf) != 0) { |
| 8942 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8943 | "VI_QOS_FILE generation failed"); |
| 8944 | } |
| 8945 | |
| 8946 | snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s", |
| 8947 | tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE); |
| 8948 | if (system(buf) != 0) { |
| 8949 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8950 | "VI_QOS_FILE generation failed"); |
| 8951 | } |
| 8952 | |
| 8953 | snprintf(buf, sizeof(buf), "ethinject %s %s", intf, VI_QOS_FILE); |
| 8954 | if (system(buf) != 0) { |
| 8955 | } |
| 8956 | } |
| 8957 | |
| 8958 | |
| 8959 | static int ath_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn, |
| 8960 | struct sigma_cmd *cmd) |
| 8961 | { |
| 8962 | const char *intf = get_param(cmd, "Interface"); |
| 8963 | const char *val; |
| 8964 | int tid = 0; |
| 8965 | char buf[100]; |
| 8966 | |
| 8967 | val = get_param(cmd, "TID"); |
| 8968 | if (val) { |
| 8969 | tid = atoi(val); |
| 8970 | if (tid) |
| 8971 | ath_sta_inject_frame(dut, intf, tid); |
| 8972 | } |
| 8973 | |
| 8974 | /* Command sequence for ADDBA request on Peregrine based devices */ |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 8975 | run_iwpriv(dut, intf, "setaddbaoper 1"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 8976 | |
| 8977 | snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4", intf, tid); |
| 8978 | if (system(buf) != 0) { |
| 8979 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8980 | "wifitool senddelba failed"); |
| 8981 | } |
| 8982 | |
| 8983 | snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64", intf, tid); |
| 8984 | if (system(buf) != 0) { |
| 8985 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 8986 | "wifitool sendaddba failed"); |
| 8987 | } |
| 8988 | |
| 8989 | /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */ |
| 8990 | |
| 8991 | return 1; |
| 8992 | } |
| 8993 | |
| 8994 | |
Lior David | 9981b51 | 2017-01-20 13:16:40 +0200 | [diff] [blame] | 8995 | #ifdef __linux__ |
| 8996 | |
| 8997 | static int wil6210_send_addba(struct sigma_dut *dut, const char *dest_mac, |
| 8998 | int agg_size) |
| 8999 | { |
| 9000 | char dir[128], buf[128]; |
| 9001 | FILE *f; |
| 9002 | regex_t re; |
| 9003 | regmatch_t m[2]; |
Jouni Malinen | 3aa7286 | 2019-05-29 23:14:51 +0300 | [diff] [blame] | 9004 | int rc, ret = -1, vring_id, found, res; |
Lior David | 9981b51 | 2017-01-20 13:16:40 +0200 | [diff] [blame] | 9005 | |
| 9006 | if (wil6210_get_debugfs_dir(dut, dir, sizeof(dir))) { |
| 9007 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 9008 | "failed to get wil6210 debugfs dir"); |
| 9009 | return -1; |
| 9010 | } |
| 9011 | |
Jouni Malinen | 3aa7286 | 2019-05-29 23:14:51 +0300 | [diff] [blame] | 9012 | res = snprintf(buf, sizeof(buf), "%s/vrings", dir); |
| 9013 | if (res < 0 || res >= sizeof(buf)) |
| 9014 | return -1; |
Lior David | 9981b51 | 2017-01-20 13:16:40 +0200 | [diff] [blame] | 9015 | f = fopen(buf, "r"); |
| 9016 | if (!f) { |
| 9017 | 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] | 9018 | /* newer wil6210 driver renamed file to "rings" */ |
Jouni Malinen | 3aa7286 | 2019-05-29 23:14:51 +0300 | [diff] [blame] | 9019 | res = snprintf(buf, sizeof(buf), "%s/rings", dir); |
| 9020 | if (res < 0 || res >= sizeof(buf)) |
| 9021 | return -1; |
Alexei Avshalom Lazar | 2af1d25 | 2018-11-13 14:10:13 +0200 | [diff] [blame] | 9022 | f = fopen(buf, "r"); |
| 9023 | if (!f) { |
| 9024 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 9025 | "failed to open: %s", buf); |
| 9026 | return -1; |
| 9027 | } |
Lior David | 9981b51 | 2017-01-20 13:16:40 +0200 | [diff] [blame] | 9028 | } |
| 9029 | |
Alexei Avshalom Lazar | 2af1d25 | 2018-11-13 14:10:13 +0200 | [diff] [blame] | 9030 | /* can be either VRING tx... or RING... */ |
| 9031 | if (regcomp(&re, "RING tx_[ \t]*([0-9]+)", REG_EXTENDED)) { |
Lior David | 9981b51 | 2017-01-20 13:16:40 +0200 | [diff] [blame] | 9032 | sigma_dut_print(dut, DUT_MSG_ERROR, "regcomp failed"); |
| 9033 | goto out; |
| 9034 | } |
| 9035 | |
| 9036 | /* find TX VRING for the mac address */ |
| 9037 | found = 0; |
| 9038 | while (fgets(buf, sizeof(buf), f)) { |
| 9039 | if (strcasestr(buf, dest_mac)) { |
| 9040 | found = 1; |
| 9041 | break; |
| 9042 | } |
| 9043 | } |
| 9044 | |
| 9045 | if (!found) { |
| 9046 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 9047 | "no TX VRING for %s", dest_mac); |
| 9048 | goto out; |
| 9049 | } |
| 9050 | |
| 9051 | /* extract VRING ID, "VRING tx_<id> = {" */ |
| 9052 | if (!fgets(buf, sizeof(buf), f)) { |
| 9053 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 9054 | "no VRING start line for %s", dest_mac); |
| 9055 | goto out; |
| 9056 | } |
| 9057 | |
| 9058 | rc = regexec(&re, buf, 2, m, 0); |
| 9059 | regfree(&re); |
| 9060 | if (rc || m[1].rm_so < 0) { |
| 9061 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 9062 | "no VRING TX ID for %s", dest_mac); |
| 9063 | goto out; |
| 9064 | } |
| 9065 | buf[m[1].rm_eo] = 0; |
| 9066 | vring_id = atoi(&buf[m[1].rm_so]); |
| 9067 | |
| 9068 | /* send the addba command */ |
| 9069 | fclose(f); |
Jouni Malinen | 3aa7286 | 2019-05-29 23:14:51 +0300 | [diff] [blame] | 9070 | res = snprintf(buf, sizeof(buf), "%s/back", dir); |
| 9071 | if (res < 0 || res >= sizeof(buf)) |
| 9072 | return -1; |
Lior David | 9981b51 | 2017-01-20 13:16:40 +0200 | [diff] [blame] | 9073 | f = fopen(buf, "w"); |
| 9074 | if (!f) { |
| 9075 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 9076 | "failed to open: %s", buf); |
| 9077 | return -1; |
| 9078 | } |
| 9079 | |
| 9080 | fprintf(f, "add %d %d\n", vring_id, agg_size); |
| 9081 | |
| 9082 | ret = 0; |
| 9083 | |
| 9084 | out: |
| 9085 | fclose(f); |
| 9086 | |
| 9087 | return ret; |
| 9088 | } |
| 9089 | |
| 9090 | |
Alexei Avshalom Lazar | 79fa3fe | 2018-12-24 15:43:33 +0200 | [diff] [blame] | 9091 | int send_addba_60g(struct sigma_dut *dut, struct sigma_conn *conn, |
| 9092 | struct sigma_cmd *cmd, const char *mac_param) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 9093 | { |
| 9094 | const char *val; |
| 9095 | int tid = 0; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 9096 | |
| 9097 | val = get_param(cmd, "TID"); |
| 9098 | if (val) { |
| 9099 | tid = atoi(val); |
| 9100 | if (tid != 0) { |
| 9101 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 9102 | "Ignore TID %d for send_addba use TID 0 for 60g since only 0 required on TX", |
| 9103 | tid); |
| 9104 | } |
| 9105 | } |
| 9106 | |
Alexei Avshalom Lazar | 79fa3fe | 2018-12-24 15:43:33 +0200 | [diff] [blame] | 9107 | val = get_param(cmd, mac_param); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 9108 | if (!val) { |
| 9109 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 9110 | "Currently not supporting addba for 60G without Dest_mac"); |
Jouni Malinen | 0e29cf2 | 2019-02-19 01:13:21 +0200 | [diff] [blame] | 9111 | return ERROR_SEND_STATUS; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 9112 | } |
| 9113 | |
Lior David | 9981b51 | 2017-01-20 13:16:40 +0200 | [diff] [blame] | 9114 | if (wil6210_send_addba(dut, val, dut->back_rcv_buf)) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 9115 | return -1; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 9116 | |
| 9117 | return 1; |
| 9118 | } |
| 9119 | |
Lior David | 9981b51 | 2017-01-20 13:16:40 +0200 | [diff] [blame] | 9120 | #endif /* __linux__ */ |
| 9121 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 9122 | |
Amarnath Hullur Subramanyam | a72c016 | 2018-02-27 14:49:09 -0800 | [diff] [blame] | 9123 | static int wcn_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn, |
| 9124 | struct sigma_cmd *cmd) |
| 9125 | { |
| 9126 | #ifdef NL80211_SUPPORT |
| 9127 | const char *intf = get_param(cmd, "Interface"); |
| 9128 | const char *val; |
| 9129 | int tid = -1; |
| 9130 | int bufsize = 64; |
| 9131 | struct nl_msg *msg; |
| 9132 | int ret = 0; |
| 9133 | struct nlattr *params; |
| 9134 | int ifindex; |
| 9135 | |
| 9136 | val = get_param(cmd, "TID"); |
| 9137 | if (val) |
| 9138 | tid = atoi(val); |
| 9139 | |
| 9140 | if (tid == -1) { |
| 9141 | send_resp(dut, conn, SIGMA_ERROR, |
| 9142 | "ErrorCode,sta_send_addba tid invalid"); |
| 9143 | return 0; |
| 9144 | } |
| 9145 | |
| 9146 | /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */ |
| 9147 | |
| 9148 | ifindex = if_nametoindex(intf); |
| 9149 | if (ifindex == 0) { |
| 9150 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 9151 | "%s: Index for interface %s failed", |
| 9152 | __func__, intf); |
| 9153 | send_resp(dut, conn, SIGMA_ERROR, |
| 9154 | "ErrorCode,sta_send_addba interface invalid"); |
| 9155 | return 0; |
| 9156 | } |
| 9157 | |
| 9158 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 9159 | NL80211_CMD_VENDOR)) || |
| 9160 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 9161 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 9162 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 9163 | QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) || |
| 9164 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 9165 | nla_put_u8(msg, |
| 9166 | QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADD_DEL_BA_SESSION, |
| 9167 | QCA_WLAN_ADD_BA) || |
| 9168 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BA_TID, |
| 9169 | tid) || |
Kiran Kumar Lokere | 26e2758 | 2018-08-01 16:18:34 -0700 | [diff] [blame] | 9170 | nla_put_u16(msg, |
| 9171 | QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE, |
| 9172 | bufsize)) { |
Amarnath Hullur Subramanyam | a72c016 | 2018-02-27 14:49:09 -0800 | [diff] [blame] | 9173 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 9174 | "%s: err in adding vendor_cmd and vendor_data", |
| 9175 | __func__); |
| 9176 | nlmsg_free(msg); |
| 9177 | send_resp(dut, conn, SIGMA_ERROR, |
| 9178 | "ErrorCode,sta_send_addba err in adding vendor_cmd and vendor_data"); |
| 9179 | return 0; |
| 9180 | } |
| 9181 | nla_nest_end(msg, params); |
| 9182 | |
| 9183 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 9184 | if (ret) { |
| 9185 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 9186 | "%s: err in send_and_recv_msgs, ret=%d", |
| 9187 | __func__, ret); |
Sunil Dutt | 3060559 | 2018-05-04 20:35:50 +0530 | [diff] [blame] | 9188 | if (ret == -EOPNOTSUPP) |
| 9189 | return 1; |
Amarnath Hullur Subramanyam | a72c016 | 2018-02-27 14:49:09 -0800 | [diff] [blame] | 9190 | send_resp(dut, conn, SIGMA_ERROR, |
| 9191 | "ErrorCode,sta_send_addba err in send_and_recv_msgs"); |
| 9192 | return 0; |
| 9193 | } |
Amarnath Hullur Subramanyam | a72c016 | 2018-02-27 14:49:09 -0800 | [diff] [blame] | 9194 | #else /* NL80211_SUPPORT */ |
| 9195 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 9196 | "sta_send_addba not supported without NL80211_SUPPORT defined"); |
Amarnath Hullur Subramanyam | a72c016 | 2018-02-27 14:49:09 -0800 | [diff] [blame] | 9197 | #endif /* NL80211_SUPPORT */ |
Sunil Dutt | 3060559 | 2018-05-04 20:35:50 +0530 | [diff] [blame] | 9198 | |
| 9199 | return 1; |
Amarnath Hullur Subramanyam | a72c016 | 2018-02-27 14:49:09 -0800 | [diff] [blame] | 9200 | } |
| 9201 | |
| 9202 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 9203 | static enum sigma_cmd_result cmd_sta_send_addba(struct sigma_dut *dut, |
| 9204 | struct sigma_conn *conn, |
| 9205 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 9206 | { |
| 9207 | switch (get_driver_type()) { |
| 9208 | case DRIVER_ATHEROS: |
| 9209 | return ath_sta_send_addba(dut, conn, cmd); |
Amarnath Hullur Subramanyam | a72c016 | 2018-02-27 14:49:09 -0800 | [diff] [blame] | 9210 | case DRIVER_WCN: |
| 9211 | return wcn_sta_send_addba(dut, conn, cmd); |
Lior David | 9981b51 | 2017-01-20 13:16:40 +0200 | [diff] [blame] | 9212 | #ifdef __linux__ |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 9213 | case DRIVER_WIL6210: |
Alexei Avshalom Lazar | 79fa3fe | 2018-12-24 15:43:33 +0200 | [diff] [blame] | 9214 | return send_addba_60g(dut, conn, cmd, "Dest_mac"); |
Lior David | 9981b51 | 2017-01-20 13:16:40 +0200 | [diff] [blame] | 9215 | #endif /* __linux__ */ |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 9216 | default: |
| 9217 | /* |
| 9218 | * There is no driver specific implementation for other drivers. |
| 9219 | * Ignore the command and report COMPLETE since the following |
| 9220 | * throughput test operation will end up sending ADDBA anyway. |
| 9221 | */ |
| 9222 | return 1; |
| 9223 | } |
| 9224 | } |
| 9225 | |
| 9226 | |
| 9227 | int inject_eth_frame(int s, const void *data, size_t len, |
| 9228 | unsigned short ethtype, char *dst, char *src) |
| 9229 | { |
| 9230 | struct iovec iov[4] = { |
| 9231 | { |
| 9232 | .iov_base = dst, |
| 9233 | .iov_len = ETH_ALEN, |
| 9234 | }, |
| 9235 | { |
| 9236 | .iov_base = src, |
| 9237 | .iov_len = ETH_ALEN, |
| 9238 | }, |
| 9239 | { |
| 9240 | .iov_base = ðtype, |
| 9241 | .iov_len = sizeof(unsigned short), |
| 9242 | }, |
| 9243 | { |
| 9244 | .iov_base = (void *) data, |
| 9245 | .iov_len = len, |
| 9246 | } |
| 9247 | }; |
| 9248 | struct msghdr msg = { |
| 9249 | .msg_name = NULL, |
| 9250 | .msg_namelen = 0, |
| 9251 | .msg_iov = iov, |
| 9252 | .msg_iovlen = 4, |
| 9253 | .msg_control = NULL, |
| 9254 | .msg_controllen = 0, |
| 9255 | .msg_flags = 0, |
| 9256 | }; |
| 9257 | |
| 9258 | return sendmsg(s, &msg, 0); |
| 9259 | } |
| 9260 | |
| 9261 | #if defined(__linux__) || defined(__QNXNTO__) |
| 9262 | |
| 9263 | int inject_frame(int s, const void *data, size_t len, int encrypt) |
| 9264 | { |
| 9265 | #define IEEE80211_RADIOTAP_F_WEP 0x04 |
| 9266 | #define IEEE80211_RADIOTAP_F_FRAG 0x08 |
| 9267 | unsigned char rtap_hdr[] = { |
| 9268 | 0x00, 0x00, /* radiotap version */ |
| 9269 | 0x0e, 0x00, /* radiotap length */ |
| 9270 | 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */ |
| 9271 | IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */ |
| 9272 | 0x00, /* padding */ |
| 9273 | 0x00, 0x00, /* RX and TX flags to indicate that */ |
| 9274 | 0x00, 0x00, /* this is the injected frame directly */ |
| 9275 | }; |
| 9276 | struct iovec iov[2] = { |
| 9277 | { |
| 9278 | .iov_base = &rtap_hdr, |
| 9279 | .iov_len = sizeof(rtap_hdr), |
| 9280 | }, |
| 9281 | { |
| 9282 | .iov_base = (void *) data, |
| 9283 | .iov_len = len, |
| 9284 | } |
| 9285 | }; |
| 9286 | struct msghdr msg = { |
| 9287 | .msg_name = NULL, |
| 9288 | .msg_namelen = 0, |
| 9289 | .msg_iov = iov, |
| 9290 | .msg_iovlen = 2, |
| 9291 | .msg_control = NULL, |
| 9292 | .msg_controllen = 0, |
| 9293 | .msg_flags = 0, |
| 9294 | }; |
| 9295 | |
| 9296 | if (encrypt) |
| 9297 | rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP; |
| 9298 | |
| 9299 | return sendmsg(s, &msg, 0); |
| 9300 | } |
| 9301 | |
| 9302 | |
| 9303 | int open_monitor(const char *ifname) |
| 9304 | { |
| 9305 | #ifdef __QNXNTO__ |
| 9306 | struct sockaddr_dl ll; |
| 9307 | int s; |
| 9308 | |
| 9309 | memset(&ll, 0, sizeof(ll)); |
| 9310 | ll.sdl_family = AF_LINK; |
| 9311 | ll.sdl_index = if_nametoindex(ifname); |
| 9312 | if (ll.sdl_index == 0) { |
| 9313 | perror("if_nametoindex"); |
| 9314 | return -1; |
| 9315 | } |
| 9316 | s = socket(PF_INET, SOCK_RAW, 0); |
| 9317 | #else /* __QNXNTO__ */ |
| 9318 | struct sockaddr_ll ll; |
| 9319 | int s; |
| 9320 | |
| 9321 | memset(&ll, 0, sizeof(ll)); |
| 9322 | ll.sll_family = AF_PACKET; |
| 9323 | ll.sll_ifindex = if_nametoindex(ifname); |
| 9324 | if (ll.sll_ifindex == 0) { |
| 9325 | perror("if_nametoindex"); |
| 9326 | return -1; |
| 9327 | } |
| 9328 | s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); |
| 9329 | #endif /* __QNXNTO__ */ |
| 9330 | if (s < 0) { |
| 9331 | perror("socket[PF_PACKET,SOCK_RAW]"); |
| 9332 | return -1; |
| 9333 | } |
| 9334 | |
| 9335 | if (bind(s, (struct sockaddr *) &ll, sizeof(ll)) < 0) { |
| 9336 | perror("monitor socket bind"); |
| 9337 | close(s); |
| 9338 | return -1; |
| 9339 | } |
| 9340 | |
| 9341 | return s; |
| 9342 | } |
| 9343 | |
| 9344 | |
| 9345 | static int hex2num(char c) |
| 9346 | { |
| 9347 | if (c >= '0' && c <= '9') |
| 9348 | return c - '0'; |
| 9349 | if (c >= 'a' && c <= 'f') |
| 9350 | return c - 'a' + 10; |
| 9351 | if (c >= 'A' && c <= 'F') |
| 9352 | return c - 'A' + 10; |
| 9353 | return -1; |
| 9354 | } |
| 9355 | |
| 9356 | |
| 9357 | int hwaddr_aton(const char *txt, unsigned char *addr) |
| 9358 | { |
| 9359 | int i; |
| 9360 | |
| 9361 | for (i = 0; i < 6; i++) { |
| 9362 | int a, b; |
| 9363 | |
| 9364 | a = hex2num(*txt++); |
| 9365 | if (a < 0) |
| 9366 | return -1; |
| 9367 | b = hex2num(*txt++); |
| 9368 | if (b < 0) |
| 9369 | return -1; |
| 9370 | *addr++ = (a << 4) | b; |
| 9371 | if (i < 5 && *txt++ != ':') |
| 9372 | return -1; |
| 9373 | } |
| 9374 | |
| 9375 | return 0; |
| 9376 | } |
| 9377 | |
| 9378 | #endif /* defined(__linux__) || defined(__QNXNTO__) */ |
| 9379 | |
| 9380 | enum send_frame_type { |
| 9381 | DISASSOC, DEAUTH, SAQUERY, AUTH, ASSOCREQ, REASSOCREQ, DLS_REQ |
| 9382 | }; |
| 9383 | enum send_frame_protection { |
| 9384 | CORRECT_KEY, INCORRECT_KEY, UNPROTECTED |
| 9385 | }; |
| 9386 | |
| 9387 | |
| 9388 | static int sta_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn, |
| 9389 | enum send_frame_type frame, |
| 9390 | enum send_frame_protection protected, |
| 9391 | const char *dest) |
| 9392 | { |
| 9393 | #ifdef __linux__ |
| 9394 | unsigned char buf[1000], *pos; |
| 9395 | int s, res; |
| 9396 | char bssid[20], addr[20]; |
| 9397 | char result[32], ssid[100]; |
| 9398 | size_t ssid_len; |
| 9399 | |
| 9400 | if (get_wpa_status(get_station_ifname(), "wpa_state", result, |
| 9401 | sizeof(result)) < 0 || |
| 9402 | strncmp(result, "COMPLETED", 9) != 0) { |
| 9403 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Not connected"); |
| 9404 | return 0; |
| 9405 | } |
| 9406 | |
| 9407 | if (get_wpa_status(get_station_ifname(), "bssid", bssid, sizeof(bssid)) |
| 9408 | < 0) { |
| 9409 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get " |
| 9410 | "current BSSID"); |
| 9411 | return 0; |
| 9412 | } |
| 9413 | |
| 9414 | if (get_wpa_status(get_station_ifname(), "address", addr, sizeof(addr)) |
| 9415 | < 0) { |
| 9416 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get " |
| 9417 | "own MAC address"); |
| 9418 | return 0; |
| 9419 | } |
| 9420 | |
| 9421 | if (get_wpa_status(get_station_ifname(), "ssid", ssid, sizeof(ssid)) |
| 9422 | < 0) { |
| 9423 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get " |
| 9424 | "current SSID"); |
| 9425 | return 0; |
| 9426 | } |
| 9427 | ssid_len = strlen(ssid); |
| 9428 | |
| 9429 | pos = buf; |
| 9430 | |
| 9431 | /* Frame Control */ |
| 9432 | switch (frame) { |
| 9433 | case DISASSOC: |
| 9434 | *pos++ = 0xa0; |
| 9435 | break; |
| 9436 | case DEAUTH: |
| 9437 | *pos++ = 0xc0; |
| 9438 | break; |
| 9439 | case SAQUERY: |
| 9440 | *pos++ = 0xd0; |
| 9441 | break; |
| 9442 | case AUTH: |
| 9443 | *pos++ = 0xb0; |
| 9444 | break; |
| 9445 | case ASSOCREQ: |
| 9446 | *pos++ = 0x00; |
| 9447 | break; |
| 9448 | case REASSOCREQ: |
| 9449 | *pos++ = 0x20; |
| 9450 | break; |
| 9451 | case DLS_REQ: |
| 9452 | *pos++ = 0xd0; |
| 9453 | break; |
| 9454 | } |
| 9455 | |
| 9456 | if (protected == INCORRECT_KEY) |
| 9457 | *pos++ = 0x40; /* Set Protected field to 1 */ |
| 9458 | else |
| 9459 | *pos++ = 0x00; |
| 9460 | |
| 9461 | /* Duration */ |
| 9462 | *pos++ = 0x00; |
| 9463 | *pos++ = 0x00; |
| 9464 | |
| 9465 | /* addr1 = DA (current AP) */ |
| 9466 | hwaddr_aton(bssid, pos); |
| 9467 | pos += 6; |
| 9468 | /* addr2 = SA (own address) */ |
| 9469 | hwaddr_aton(addr, pos); |
| 9470 | pos += 6; |
| 9471 | /* addr3 = BSSID (current AP) */ |
| 9472 | hwaddr_aton(bssid, pos); |
| 9473 | pos += 6; |
| 9474 | |
| 9475 | /* Seq# (to be filled by driver/mac80211) */ |
| 9476 | *pos++ = 0x00; |
| 9477 | *pos++ = 0x00; |
| 9478 | |
| 9479 | if (protected == INCORRECT_KEY) { |
| 9480 | /* CCMP parameters */ |
| 9481 | memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8); |
| 9482 | pos += 8; |
| 9483 | } |
| 9484 | |
| 9485 | if (protected == INCORRECT_KEY) { |
| 9486 | switch (frame) { |
| 9487 | case DEAUTH: |
| 9488 | /* Reason code (encrypted) */ |
| 9489 | memcpy(pos, "\xa7\x39", 2); |
| 9490 | pos += 2; |
| 9491 | break; |
| 9492 | case DISASSOC: |
| 9493 | /* Reason code (encrypted) */ |
| 9494 | memcpy(pos, "\xa7\x39", 2); |
| 9495 | pos += 2; |
| 9496 | break; |
| 9497 | case SAQUERY: |
| 9498 | /* Category|Action|TransID (encrypted) */ |
| 9499 | memcpy(pos, "\x6f\xbd\xe9\x4d", 4); |
| 9500 | pos += 4; |
| 9501 | break; |
| 9502 | default: |
| 9503 | return -1; |
| 9504 | } |
| 9505 | |
| 9506 | /* CCMP MIC */ |
| 9507 | memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8); |
| 9508 | pos += 8; |
| 9509 | } else { |
| 9510 | switch (frame) { |
| 9511 | case DEAUTH: |
| 9512 | /* reason code = 8 */ |
| 9513 | *pos++ = 0x08; |
| 9514 | *pos++ = 0x00; |
| 9515 | break; |
| 9516 | case DISASSOC: |
| 9517 | /* reason code = 8 */ |
| 9518 | *pos++ = 0x08; |
| 9519 | *pos++ = 0x00; |
| 9520 | break; |
| 9521 | case SAQUERY: |
| 9522 | /* Category - SA Query */ |
| 9523 | *pos++ = 0x08; |
| 9524 | /* SA query Action - Request */ |
| 9525 | *pos++ = 0x00; |
| 9526 | /* Transaction ID */ |
| 9527 | *pos++ = 0x12; |
| 9528 | *pos++ = 0x34; |
| 9529 | break; |
| 9530 | case AUTH: |
| 9531 | /* Auth Alg (Open) */ |
| 9532 | *pos++ = 0x00; |
| 9533 | *pos++ = 0x00; |
| 9534 | /* Seq# */ |
| 9535 | *pos++ = 0x01; |
| 9536 | *pos++ = 0x00; |
| 9537 | /* Status code */ |
| 9538 | *pos++ = 0x00; |
| 9539 | *pos++ = 0x00; |
| 9540 | break; |
| 9541 | case ASSOCREQ: |
| 9542 | /* Capability Information */ |
| 9543 | *pos++ = 0x31; |
| 9544 | *pos++ = 0x04; |
| 9545 | /* Listen Interval */ |
| 9546 | *pos++ = 0x0a; |
| 9547 | *pos++ = 0x00; |
| 9548 | /* SSID */ |
| 9549 | *pos++ = 0x00; |
| 9550 | *pos++ = ssid_len; |
| 9551 | memcpy(pos, ssid, ssid_len); |
| 9552 | pos += ssid_len; |
| 9553 | /* Supported Rates */ |
| 9554 | memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24", |
| 9555 | 10); |
| 9556 | pos += 10; |
| 9557 | /* Extended Supported Rates */ |
| 9558 | memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6); |
| 9559 | pos += 6; |
| 9560 | /* RSN */ |
| 9561 | memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00" |
| 9562 | "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0" |
| 9563 | "\x00\x00\x00\x00\x0f\xac\x06", 28); |
| 9564 | pos += 28; |
| 9565 | break; |
| 9566 | case REASSOCREQ: |
| 9567 | /* Capability Information */ |
| 9568 | *pos++ = 0x31; |
| 9569 | *pos++ = 0x04; |
| 9570 | /* Listen Interval */ |
| 9571 | *pos++ = 0x0a; |
| 9572 | *pos++ = 0x00; |
| 9573 | /* Current AP */ |
| 9574 | hwaddr_aton(bssid, pos); |
| 9575 | pos += 6; |
| 9576 | /* SSID */ |
| 9577 | *pos++ = 0x00; |
| 9578 | *pos++ = ssid_len; |
| 9579 | memcpy(pos, ssid, ssid_len); |
| 9580 | pos += ssid_len; |
| 9581 | /* Supported Rates */ |
| 9582 | memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24", |
| 9583 | 10); |
| 9584 | pos += 10; |
| 9585 | /* Extended Supported Rates */ |
| 9586 | memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6); |
| 9587 | pos += 6; |
| 9588 | /* RSN */ |
| 9589 | memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00" |
| 9590 | "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0" |
| 9591 | "\x00\x00\x00\x00\x0f\xac\x06", 28); |
| 9592 | pos += 28; |
| 9593 | break; |
| 9594 | case DLS_REQ: |
| 9595 | /* Category - DLS */ |
| 9596 | *pos++ = 0x02; |
| 9597 | /* DLS Action - Request */ |
| 9598 | *pos++ = 0x00; |
| 9599 | /* Destination MACAddress */ |
| 9600 | if (dest) |
| 9601 | hwaddr_aton(dest, pos); |
| 9602 | else |
| 9603 | memset(pos, 0, 6); |
| 9604 | pos += 6; |
| 9605 | /* Source MACAddress */ |
| 9606 | hwaddr_aton(addr, pos); |
| 9607 | pos += 6; |
| 9608 | /* Capability Information */ |
| 9609 | *pos++ = 0x10; /* Privacy */ |
| 9610 | *pos++ = 0x06; /* QoS */ |
| 9611 | /* DLS Timeout Value */ |
| 9612 | *pos++ = 0x00; |
| 9613 | *pos++ = 0x01; |
| 9614 | /* Supported rates */ |
| 9615 | *pos++ = 0x01; |
| 9616 | *pos++ = 0x08; |
| 9617 | *pos++ = 0x0c; /* 6 Mbps */ |
| 9618 | *pos++ = 0x12; /* 9 Mbps */ |
| 9619 | *pos++ = 0x18; /* 12 Mbps */ |
| 9620 | *pos++ = 0x24; /* 18 Mbps */ |
| 9621 | *pos++ = 0x30; /* 24 Mbps */ |
| 9622 | *pos++ = 0x48; /* 36 Mbps */ |
| 9623 | *pos++ = 0x60; /* 48 Mbps */ |
| 9624 | *pos++ = 0x6c; /* 54 Mbps */ |
| 9625 | /* TODO: Extended Supported Rates */ |
| 9626 | /* TODO: HT Capabilities */ |
| 9627 | break; |
| 9628 | } |
| 9629 | } |
| 9630 | |
| 9631 | s = open_monitor("sigmadut"); |
| 9632 | if (s < 0) { |
| 9633 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open " |
| 9634 | "monitor socket"); |
| 9635 | return 0; |
| 9636 | } |
| 9637 | |
| 9638 | res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY); |
| 9639 | if (res < 0) { |
| 9640 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to " |
| 9641 | "inject frame"); |
Pradeep Reddy POTTETI | 673d85c | 2016-07-26 19:08:07 +0530 | [diff] [blame] | 9642 | close(s); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 9643 | return 0; |
| 9644 | } |
| 9645 | if (res < pos - buf) { |
| 9646 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Only partial " |
| 9647 | "frame sent"); |
Pradeep Reddy POTTETI | 673d85c | 2016-07-26 19:08:07 +0530 | [diff] [blame] | 9648 | close(s); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 9649 | return 0; |
| 9650 | } |
| 9651 | |
| 9652 | close(s); |
| 9653 | |
| 9654 | return 1; |
| 9655 | #else /* __linux__ */ |
| 9656 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,sta_send_frame not " |
| 9657 | "yet supported"); |
| 9658 | return 0; |
| 9659 | #endif /* __linux__ */ |
| 9660 | } |
| 9661 | |
| 9662 | |
| 9663 | static int cmd_sta_send_frame_tdls(struct sigma_dut *dut, |
| 9664 | struct sigma_conn *conn, |
| 9665 | struct sigma_cmd *cmd) |
| 9666 | { |
| 9667 | const char *intf = get_param(cmd, "Interface"); |
| 9668 | const char *sta, *val; |
| 9669 | unsigned char addr[ETH_ALEN]; |
| 9670 | char buf[100]; |
| 9671 | |
Alexei Avshalom Lazar | 4a3c2f8 | 2019-05-02 13:35:37 +0300 | [diff] [blame] | 9672 | if (!intf) |
| 9673 | return -1; |
| 9674 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 9675 | sta = get_param(cmd, "peer"); |
| 9676 | if (sta == NULL) |
| 9677 | sta = get_param(cmd, "station"); |
| 9678 | if (sta == NULL) { |
| 9679 | send_resp(dut, conn, SIGMA_ERROR, |
| 9680 | "ErrorCode,Missing peer address"); |
| 9681 | return 0; |
| 9682 | } |
| 9683 | if (hwaddr_aton(sta, addr) < 0) { |
| 9684 | send_resp(dut, conn, SIGMA_ERROR, |
| 9685 | "ErrorCode,Invalid peer address"); |
| 9686 | return 0; |
| 9687 | } |
| 9688 | |
| 9689 | val = get_param(cmd, "type"); |
| 9690 | if (val == NULL) |
| 9691 | return -1; |
| 9692 | |
| 9693 | if (strcasecmp(val, "DISCOVERY") == 0) { |
| 9694 | snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", sta); |
| 9695 | if (wpa_command(intf, buf) < 0) { |
| 9696 | send_resp(dut, conn, SIGMA_ERROR, |
| 9697 | "ErrorCode,Failed to send TDLS discovery"); |
| 9698 | return 0; |
| 9699 | } |
| 9700 | return 1; |
| 9701 | } |
| 9702 | |
| 9703 | if (strcasecmp(val, "SETUP") == 0) { |
| 9704 | int status = 0, timeout = 0; |
| 9705 | |
| 9706 | val = get_param(cmd, "Status"); |
| 9707 | if (val) |
| 9708 | status = atoi(val); |
| 9709 | |
| 9710 | val = get_param(cmd, "Timeout"); |
| 9711 | if (val) |
| 9712 | timeout = atoi(val); |
| 9713 | |
| 9714 | if (status != 0 && status != 37) { |
| 9715 | send_resp(dut, conn, SIGMA_ERROR, |
| 9716 | "ErrorCode,Unsupported status value"); |
| 9717 | return 0; |
| 9718 | } |
| 9719 | |
| 9720 | if (timeout != 0 && timeout != 301) { |
| 9721 | send_resp(dut, conn, SIGMA_ERROR, |
| 9722 | "ErrorCode,Unsupported timeout value"); |
| 9723 | return 0; |
| 9724 | } |
| 9725 | |
| 9726 | if (status && timeout) { |
| 9727 | send_resp(dut, conn, SIGMA_ERROR, |
| 9728 | "ErrorCode,Unsupported timeout+status " |
| 9729 | "combination"); |
| 9730 | return 0; |
| 9731 | } |
| 9732 | |
| 9733 | if (status == 37 && |
| 9734 | wpa_command(intf, "SET tdls_testing 0x200")) { |
| 9735 | send_resp(dut, conn, SIGMA_ERROR, |
| 9736 | "ErrorCode,Failed to enable " |
| 9737 | "decline setup response test mode"); |
| 9738 | return 0; |
| 9739 | } |
| 9740 | |
| 9741 | if (timeout == 301) { |
| 9742 | int res; |
| 9743 | if (dut->no_tpk_expiration) |
| 9744 | res = wpa_command(intf, |
| 9745 | "SET tdls_testing 0x108"); |
| 9746 | else |
| 9747 | res = wpa_command(intf, |
| 9748 | "SET tdls_testing 0x8"); |
| 9749 | if (res) { |
| 9750 | send_resp(dut, conn, SIGMA_ERROR, |
| 9751 | "ErrorCode,Failed to set short TPK " |
| 9752 | "lifetime"); |
| 9753 | return 0; |
| 9754 | } |
| 9755 | } |
| 9756 | |
| 9757 | snprintf(buf, sizeof(buf), "TDLS_SETUP %s", sta); |
| 9758 | if (wpa_command(intf, buf) < 0) { |
| 9759 | send_resp(dut, conn, SIGMA_ERROR, |
| 9760 | "ErrorCode,Failed to send TDLS setup"); |
| 9761 | return 0; |
| 9762 | } |
| 9763 | return 1; |
| 9764 | } |
| 9765 | |
| 9766 | if (strcasecmp(val, "TEARDOWN") == 0) { |
| 9767 | snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", sta); |
| 9768 | if (wpa_command(intf, buf) < 0) { |
| 9769 | send_resp(dut, conn, SIGMA_ERROR, |
| 9770 | "ErrorCode,Failed to send TDLS teardown"); |
| 9771 | return 0; |
| 9772 | } |
| 9773 | return 1; |
| 9774 | } |
| 9775 | |
| 9776 | send_resp(dut, conn, SIGMA_ERROR, |
| 9777 | "ErrorCode,Unsupported TDLS frame"); |
| 9778 | return 0; |
| 9779 | } |
| 9780 | |
| 9781 | |
| 9782 | static int sta_ap_known(const char *ifname, const char *bssid) |
| 9783 | { |
| 9784 | char buf[4096]; |
| 9785 | |
Jouni Malinen | dd32f19 | 2018-09-15 02:55:19 +0300 | [diff] [blame] | 9786 | snprintf(buf, sizeof(buf), "BSS MASK=1 %s", bssid); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 9787 | if (wpa_command_resp(ifname, buf, buf, sizeof(buf)) < 0) |
| 9788 | return 0; |
| 9789 | if (strncmp(buf, "id=", 3) != 0) |
| 9790 | return 0; |
| 9791 | return 1; |
| 9792 | } |
| 9793 | |
| 9794 | |
| 9795 | static int sta_scan_ap(struct sigma_dut *dut, const char *ifname, |
| 9796 | const char *bssid) |
| 9797 | { |
| 9798 | int res; |
| 9799 | struct wpa_ctrl *ctrl; |
| 9800 | char buf[256]; |
| 9801 | |
| 9802 | if (sta_ap_known(ifname, bssid)) |
| 9803 | return 0; |
| 9804 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 9805 | "AP not in BSS table - start scan"); |
| 9806 | |
| 9807 | ctrl = open_wpa_mon(ifname); |
| 9808 | if (ctrl == NULL) { |
| 9809 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open " |
| 9810 | "wpa_supplicant monitor connection"); |
| 9811 | return -1; |
| 9812 | } |
| 9813 | |
| 9814 | if (wpa_command(ifname, "SCAN") < 0) { |
| 9815 | sigma_dut_print(dut, DUT_MSG_INFO, "Failed to start scan"); |
| 9816 | wpa_ctrl_detach(ctrl); |
| 9817 | wpa_ctrl_close(ctrl); |
| 9818 | return -1; |
| 9819 | } |
| 9820 | |
| 9821 | res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS", |
| 9822 | buf, sizeof(buf)); |
| 9823 | |
| 9824 | wpa_ctrl_detach(ctrl); |
| 9825 | wpa_ctrl_close(ctrl); |
| 9826 | |
| 9827 | if (res < 0) { |
| 9828 | sigma_dut_print(dut, DUT_MSG_INFO, "Scan did not complete"); |
| 9829 | return -1; |
| 9830 | } |
| 9831 | |
| 9832 | if (sta_ap_known(ifname, bssid)) |
| 9833 | return 0; |
| 9834 | sigma_dut_print(dut, DUT_MSG_INFO, "AP not in BSS table"); |
| 9835 | return -1; |
| 9836 | } |
| 9837 | |
| 9838 | |
| 9839 | static int cmd_sta_send_frame_hs2_neighadv(struct sigma_dut *dut, |
| 9840 | struct sigma_conn *conn, |
| 9841 | struct sigma_cmd *cmd, |
| 9842 | const char *intf) |
| 9843 | { |
| 9844 | char buf[200]; |
| 9845 | |
| 9846 | snprintf(buf, sizeof(buf), "ndsend 2001:DB8::1 %s", intf); |
| 9847 | if (system(buf) != 0) { |
| 9848 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Failed to run " |
| 9849 | "ndsend"); |
| 9850 | return 0; |
| 9851 | } |
| 9852 | |
| 9853 | return 1; |
| 9854 | } |
| 9855 | |
| 9856 | |
| 9857 | static int cmd_sta_send_frame_hs2_neighsolreq(struct sigma_dut *dut, |
| 9858 | struct sigma_conn *conn, |
| 9859 | struct sigma_cmd *cmd, |
| 9860 | const char *intf) |
| 9861 | { |
| 9862 | char buf[200]; |
| 9863 | const char *ip = get_param(cmd, "SenderIP"); |
| 9864 | |
Peng Xu | 26b356d | 2017-10-04 17:58:16 -0700 | [diff] [blame] | 9865 | if (!ip) |
| 9866 | return 0; |
| 9867 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 9868 | snprintf(buf, sizeof(buf), "ndisc6 -nm %s %s -r 4", ip, intf); |
| 9869 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 9870 | if (system(buf) == 0) { |
| 9871 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 9872 | "Neighbor Solicitation got a response " |
| 9873 | "for %s@%s", ip, intf); |
| 9874 | } |
| 9875 | |
| 9876 | return 1; |
| 9877 | } |
| 9878 | |
| 9879 | |
| 9880 | static int cmd_sta_send_frame_hs2_arpprobe(struct sigma_dut *dut, |
| 9881 | struct sigma_conn *conn, |
| 9882 | struct sigma_cmd *cmd, |
| 9883 | const char *ifname) |
| 9884 | { |
| 9885 | char buf[200]; |
| 9886 | const char *ip = get_param(cmd, "SenderIP"); |
| 9887 | |
| 9888 | if (ip == NULL) { |
| 9889 | send_resp(dut, conn, SIGMA_ERROR, |
| 9890 | "ErrorCode,Missing SenderIP parameter"); |
| 9891 | return 0; |
| 9892 | } |
| 9893 | snprintf(buf, sizeof(buf), "arping -I %s -D %s -c 4", ifname, ip); |
| 9894 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 9895 | if (system(buf) != 0) { |
| 9896 | sigma_dut_print(dut, DUT_MSG_INFO, "arping DAD got a response " |
| 9897 | "for %s@%s", ip, ifname); |
| 9898 | } |
| 9899 | |
| 9900 | return 1; |
| 9901 | } |
| 9902 | |
| 9903 | |
| 9904 | static int cmd_sta_send_frame_hs2_arpannounce(struct sigma_dut *dut, |
| 9905 | struct sigma_conn *conn, |
| 9906 | struct sigma_cmd *cmd, |
| 9907 | const char *ifname) |
| 9908 | { |
| 9909 | char buf[200]; |
| 9910 | char ip[16]; |
| 9911 | int s; |
Peng Xu | b375688 | 2017-10-04 14:39:09 -0700 | [diff] [blame] | 9912 | struct ifreq ifr; |
| 9913 | struct sockaddr_in saddr; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 9914 | |
| 9915 | s = socket(PF_INET, SOCK_DGRAM, 0); |
Peng Xu | b375688 | 2017-10-04 14:39:09 -0700 | [diff] [blame] | 9916 | if (s < 0) { |
| 9917 | perror("socket"); |
| 9918 | return -1; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 9919 | } |
| 9920 | |
Peng Xu | b375688 | 2017-10-04 14:39:09 -0700 | [diff] [blame] | 9921 | memset(&ifr, 0, sizeof(ifr)); |
| 9922 | strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); |
| 9923 | if (ioctl(s, SIOCGIFADDR, &ifr) < 0) { |
| 9924 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 9925 | "Failed to get %s IP address: %s", |
| 9926 | ifname, strerror(errno)); |
| 9927 | close(s); |
| 9928 | return -1; |
| 9929 | } |
| 9930 | close(s); |
| 9931 | |
| 9932 | memcpy(&saddr, &ifr.ifr_addr, sizeof(struct sockaddr_in)); |
| 9933 | strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip)); |
| 9934 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 9935 | snprintf(buf, sizeof(buf), "arping -I %s -s %s %s -c 4", ifname, ip, |
| 9936 | ip); |
| 9937 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 9938 | if (system(buf) != 0) { |
| 9939 | } |
| 9940 | |
| 9941 | return 1; |
| 9942 | } |
| 9943 | |
| 9944 | |
| 9945 | static int cmd_sta_send_frame_hs2_arpreply(struct sigma_dut *dut, |
| 9946 | struct sigma_conn *conn, |
| 9947 | struct sigma_cmd *cmd, |
| 9948 | const char *ifname) |
| 9949 | { |
| 9950 | char buf[200], addr[20]; |
| 9951 | char dst[ETH_ALEN], src[ETH_ALEN]; |
| 9952 | short ethtype = htons(ETH_P_ARP); |
| 9953 | char *pos; |
| 9954 | int s, res; |
| 9955 | const char *val; |
| 9956 | struct sockaddr_in taddr; |
| 9957 | |
| 9958 | val = get_param(cmd, "dest"); |
| 9959 | if (val) |
| 9960 | hwaddr_aton(val, (unsigned char *) dst); |
| 9961 | |
| 9962 | val = get_param(cmd, "DestIP"); |
| 9963 | if (val) |
| 9964 | inet_aton(val, &taddr.sin_addr); |
Peng Xu | 151c9e1 | 2017-10-04 14:39:09 -0700 | [diff] [blame] | 9965 | else |
| 9966 | return -2; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 9967 | |
| 9968 | if (get_wpa_status(get_station_ifname(), "address", addr, |
| 9969 | sizeof(addr)) < 0) |
| 9970 | return -2; |
| 9971 | hwaddr_aton(addr, (unsigned char *) src); |
| 9972 | |
| 9973 | pos = buf; |
| 9974 | *pos++ = 0x00; |
| 9975 | *pos++ = 0x01; |
| 9976 | *pos++ = 0x08; |
| 9977 | *pos++ = 0x00; |
| 9978 | *pos++ = 0x06; |
| 9979 | *pos++ = 0x04; |
| 9980 | *pos++ = 0x00; |
| 9981 | *pos++ = 0x02; |
| 9982 | memcpy(pos, src, ETH_ALEN); |
| 9983 | pos += ETH_ALEN; |
| 9984 | memcpy(pos, &taddr.sin_addr, 4); |
| 9985 | pos += 4; |
| 9986 | memcpy(pos, dst, ETH_ALEN); |
| 9987 | pos += ETH_ALEN; |
| 9988 | memcpy(pos, &taddr.sin_addr, 4); |
| 9989 | pos += 4; |
| 9990 | |
| 9991 | s = open_monitor(get_station_ifname()); |
| 9992 | if (s < 0) { |
| 9993 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open " |
| 9994 | "monitor socket"); |
| 9995 | return 0; |
| 9996 | } |
| 9997 | |
| 9998 | res = inject_eth_frame(s, buf, pos - buf, ethtype, dst, src); |
| 9999 | if (res < 0) { |
| 10000 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to " |
| 10001 | "inject frame"); |
Pradeep Reddy POTTETI | 673d85c | 2016-07-26 19:08:07 +0530 | [diff] [blame] | 10002 | close(s); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 10003 | return 0; |
| 10004 | } |
| 10005 | |
| 10006 | close(s); |
| 10007 | |
| 10008 | return 1; |
| 10009 | } |
| 10010 | |
| 10011 | |
| 10012 | static int cmd_sta_send_frame_hs2_dls_req(struct sigma_dut *dut, |
| 10013 | struct sigma_conn *conn, |
| 10014 | struct sigma_cmd *cmd, |
| 10015 | const char *intf, const char *dest) |
| 10016 | { |
| 10017 | char buf[100]; |
| 10018 | |
| 10019 | if (if_nametoindex("sigmadut") == 0) { |
| 10020 | snprintf(buf, sizeof(buf), |
| 10021 | "iw dev %s interface add sigmadut type monitor", |
| 10022 | get_station_ifname()); |
| 10023 | if (system(buf) != 0 || |
| 10024 | if_nametoindex("sigmadut") == 0) { |
| 10025 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add " |
| 10026 | "monitor interface with '%s'", buf); |
| 10027 | return -2; |
| 10028 | } |
| 10029 | } |
| 10030 | |
| 10031 | if (system("ifconfig sigmadut up") != 0) { |
| 10032 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set " |
| 10033 | "monitor interface up"); |
| 10034 | return -2; |
| 10035 | } |
| 10036 | |
| 10037 | return sta_inject_frame(dut, conn, DLS_REQ, UNPROTECTED, dest); |
| 10038 | } |
| 10039 | |
| 10040 | |
| 10041 | static int cmd_sta_send_frame_hs2(struct sigma_dut *dut, |
| 10042 | struct sigma_conn *conn, |
| 10043 | struct sigma_cmd *cmd) |
| 10044 | { |
| 10045 | const char *intf = get_param(cmd, "Interface"); |
| 10046 | const char *dest = get_param(cmd, "Dest"); |
| 10047 | const char *type = get_param(cmd, "FrameName"); |
| 10048 | const char *val; |
| 10049 | char buf[200], *pos, *end; |
| 10050 | int count, count2; |
| 10051 | |
| 10052 | if (type == NULL) |
| 10053 | type = get_param(cmd, "Type"); |
| 10054 | |
| 10055 | if (intf == NULL || dest == NULL || type == NULL) |
| 10056 | return -1; |
| 10057 | |
| 10058 | if (strcasecmp(type, "NeighAdv") == 0) |
| 10059 | return cmd_sta_send_frame_hs2_neighadv(dut, conn, cmd, intf); |
| 10060 | |
| 10061 | if (strcasecmp(type, "NeighSolicitReq") == 0) |
| 10062 | return cmd_sta_send_frame_hs2_neighsolreq(dut, conn, cmd, intf); |
| 10063 | |
| 10064 | if (strcasecmp(type, "ARPProbe") == 0) |
| 10065 | return cmd_sta_send_frame_hs2_arpprobe(dut, conn, cmd, intf); |
| 10066 | |
| 10067 | if (strcasecmp(type, "ARPAnnounce") == 0) |
| 10068 | return cmd_sta_send_frame_hs2_arpannounce(dut, conn, cmd, intf); |
| 10069 | |
| 10070 | if (strcasecmp(type, "ARPReply") == 0) |
| 10071 | return cmd_sta_send_frame_hs2_arpreply(dut, conn, cmd, intf); |
| 10072 | |
| 10073 | if (strcasecmp(type, "DLS-request") == 0 || |
| 10074 | strcasecmp(type, "DLSrequest") == 0) |
| 10075 | return cmd_sta_send_frame_hs2_dls_req(dut, conn, cmd, intf, |
| 10076 | dest); |
| 10077 | |
| 10078 | if (strcasecmp(type, "ANQPQuery") != 0 && |
| 10079 | strcasecmp(type, "Query") != 0) { |
| 10080 | send_resp(dut, conn, SIGMA_ERROR, |
| 10081 | "ErrorCode,Unsupported HS 2.0 send frame type"); |
| 10082 | return 0; |
| 10083 | } |
| 10084 | |
| 10085 | if (sta_scan_ap(dut, intf, dest) < 0) { |
| 10086 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not find " |
| 10087 | "the requested AP"); |
| 10088 | return 0; |
| 10089 | } |
| 10090 | |
| 10091 | pos = buf; |
| 10092 | end = buf + sizeof(buf); |
| 10093 | count = 0; |
| 10094 | pos += snprintf(pos, end - pos, "ANQP_GET %s ", dest); |
| 10095 | |
| 10096 | val = get_param(cmd, "ANQP_CAP_LIST"); |
| 10097 | if (val && atoi(val)) { |
| 10098 | pos += snprintf(pos, end - pos, "%s257", count > 0 ? "," : ""); |
| 10099 | count++; |
| 10100 | } |
| 10101 | |
| 10102 | val = get_param(cmd, "VENUE_NAME"); |
| 10103 | if (val && atoi(val)) { |
| 10104 | pos += snprintf(pos, end - pos, "%s258", count > 0 ? "," : ""); |
| 10105 | count++; |
| 10106 | } |
| 10107 | |
| 10108 | val = get_param(cmd, "NETWORK_AUTH_TYPE"); |
| 10109 | if (val && atoi(val)) { |
| 10110 | pos += snprintf(pos, end - pos, "%s260", count > 0 ? "," : ""); |
| 10111 | count++; |
| 10112 | } |
| 10113 | |
| 10114 | val = get_param(cmd, "ROAMING_CONS"); |
| 10115 | if (val && atoi(val)) { |
| 10116 | pos += snprintf(pos, end - pos, "%s261", count > 0 ? "," : ""); |
| 10117 | count++; |
| 10118 | } |
| 10119 | |
| 10120 | val = get_param(cmd, "IP_ADDR_TYPE_AVAILABILITY"); |
| 10121 | if (val && atoi(val)) { |
| 10122 | pos += snprintf(pos, end - pos, "%s262", count > 0 ? "," : ""); |
| 10123 | count++; |
| 10124 | } |
| 10125 | |
| 10126 | val = get_param(cmd, "NAI_REALM_LIST"); |
| 10127 | if (val && atoi(val)) { |
| 10128 | pos += snprintf(pos, end - pos, "%s263", count > 0 ? "," : ""); |
| 10129 | count++; |
| 10130 | } |
| 10131 | |
| 10132 | val = get_param(cmd, "3GPP_INFO"); |
| 10133 | if (val && atoi(val)) { |
| 10134 | pos += snprintf(pos, end - pos, "%s264", count > 0 ? "," : ""); |
| 10135 | count++; |
| 10136 | } |
| 10137 | |
| 10138 | val = get_param(cmd, "DOMAIN_LIST"); |
| 10139 | if (val && atoi(val)) { |
| 10140 | pos += snprintf(pos, end - pos, "%s268", count > 0 ? "," : ""); |
| 10141 | count++; |
| 10142 | } |
| 10143 | |
Jouni Malinen | 34cf953 | 2018-04-29 19:26:33 +0300 | [diff] [blame] | 10144 | val = get_param(cmd, "Venue_URL"); |
| 10145 | if (val && atoi(val)) { |
| 10146 | pos += snprintf(pos, end - pos, "%s277", count > 0 ? "," : ""); |
| 10147 | count++; |
| 10148 | } |
| 10149 | |
Jouni Malinen | d3bca5d | 2018-04-29 17:25:23 +0300 | [diff] [blame] | 10150 | val = get_param(cmd, "Advice_Of_Charge"); |
| 10151 | if (val && atoi(val)) { |
| 10152 | pos += snprintf(pos, end - pos, "%s278", count > 0 ? "," : ""); |
| 10153 | count++; |
| 10154 | } |
| 10155 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 10156 | if (count && wpa_command(intf, buf)) { |
| 10157 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,ANQP_GET failed"); |
| 10158 | return 0; |
| 10159 | } |
| 10160 | |
| 10161 | pos = buf; |
| 10162 | end = buf + sizeof(buf); |
| 10163 | count2 = 0; |
| 10164 | pos += snprintf(pos, end - pos, "HS20_ANQP_GET %s ", dest); |
| 10165 | |
| 10166 | val = get_param(cmd, "HS_CAP_LIST"); |
| 10167 | if (val && atoi(val)) { |
| 10168 | pos += snprintf(pos, end - pos, "%s2", count2 > 0 ? "," : ""); |
| 10169 | count2++; |
| 10170 | } |
| 10171 | |
| 10172 | val = get_param(cmd, "OPER_NAME"); |
| 10173 | if (val && atoi(val)) { |
| 10174 | pos += snprintf(pos, end - pos, "%s3", count2 > 0 ? "," : ""); |
| 10175 | count2++; |
| 10176 | } |
| 10177 | |
| 10178 | val = get_param(cmd, "WAN_METRICS"); |
| 10179 | if (!val) |
| 10180 | val = get_param(cmd, "WAN_MAT"); |
| 10181 | if (!val) |
| 10182 | val = get_param(cmd, "WAN_MET"); |
| 10183 | if (val && atoi(val)) { |
| 10184 | pos += snprintf(pos, end - pos, "%s4", count2 > 0 ? "," : ""); |
| 10185 | count2++; |
| 10186 | } |
| 10187 | |
| 10188 | val = get_param(cmd, "CONNECTION_CAPABILITY"); |
| 10189 | if (val && atoi(val)) { |
| 10190 | pos += snprintf(pos, end - pos, "%s5", count2 > 0 ? "," : ""); |
| 10191 | count2++; |
| 10192 | } |
| 10193 | |
| 10194 | val = get_param(cmd, "OP_CLASS"); |
| 10195 | if (val && atoi(val)) { |
| 10196 | pos += snprintf(pos, end - pos, "%s7", count2 > 0 ? "," : ""); |
| 10197 | count2++; |
| 10198 | } |
| 10199 | |
| 10200 | val = get_param(cmd, "OSU_PROVIDER_LIST"); |
| 10201 | if (val && atoi(val)) { |
| 10202 | pos += snprintf(pos, end - pos, "%s8", count2 > 0 ? "," : ""); |
| 10203 | count2++; |
| 10204 | } |
| 10205 | |
Jouni Malinen | f67afec | 2018-04-29 19:24:58 +0300 | [diff] [blame] | 10206 | val = get_param(cmd, "OPER_ICON_METADATA"); |
| 10207 | if (!val) |
| 10208 | val = get_param(cmd, "OPERATOR_ICON_METADATA"); |
| 10209 | if (val && atoi(val)) { |
| 10210 | pos += snprintf(pos, end - pos, "%s12", count2 > 0 ? "," : ""); |
| 10211 | count2++; |
| 10212 | } |
| 10213 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 10214 | if (count && count2) { |
| 10215 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before sending out " |
| 10216 | "second query"); |
| 10217 | sleep(1); |
| 10218 | } |
| 10219 | |
| 10220 | if (count2 && wpa_command(intf, buf)) { |
| 10221 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,HS20_ANQP_GET " |
| 10222 | "failed"); |
| 10223 | return 0; |
| 10224 | } |
| 10225 | |
| 10226 | val = get_param(cmd, "NAI_HOME_REALM_LIST"); |
| 10227 | if (val) { |
| 10228 | if (count || count2) { |
| 10229 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before " |
| 10230 | "sending out second query"); |
| 10231 | sleep(1); |
| 10232 | } |
| 10233 | |
| 10234 | if (strcmp(val, "1") == 0) |
| 10235 | val = "mail.example.com"; |
| 10236 | snprintf(buf, end - pos, |
| 10237 | "HS20_GET_NAI_HOME_REALM_LIST %s realm=%s", |
| 10238 | dest, val); |
| 10239 | if (wpa_command(intf, buf)) { |
| 10240 | send_resp(dut, conn, SIGMA_ERROR, |
| 10241 | "ErrorCode,HS20_GET_NAI_HOME_REALM_LIST " |
| 10242 | "failed"); |
| 10243 | return 0; |
| 10244 | } |
| 10245 | } |
| 10246 | |
| 10247 | val = get_param(cmd, "ICON_REQUEST"); |
| 10248 | if (val) { |
| 10249 | if (count || count2) { |
| 10250 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before " |
| 10251 | "sending out second query"); |
| 10252 | sleep(1); |
| 10253 | } |
| 10254 | |
| 10255 | snprintf(buf, end - pos, |
| 10256 | "HS20_ICON_REQUEST %s %s", dest, val); |
| 10257 | if (wpa_command(intf, buf)) { |
| 10258 | send_resp(dut, conn, SIGMA_ERROR, |
| 10259 | "ErrorCode,HS20_ICON_REQUEST failed"); |
| 10260 | return 0; |
| 10261 | } |
| 10262 | } |
| 10263 | |
| 10264 | return 1; |
| 10265 | } |
| 10266 | |
| 10267 | |
| 10268 | static int ath_sta_send_frame_vht(struct sigma_dut *dut, |
| 10269 | struct sigma_conn *conn, |
| 10270 | struct sigma_cmd *cmd) |
| 10271 | { |
| 10272 | const char *val; |
| 10273 | char *ifname; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 10274 | int chwidth, nss; |
| 10275 | |
| 10276 | val = get_param(cmd, "framename"); |
| 10277 | if (!val) |
| 10278 | return -1; |
| 10279 | sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val); |
| 10280 | |
| 10281 | /* Command sequence to generate Op mode notification */ |
| 10282 | if (val && strcasecmp(val, "Op_md_notif_frm") == 0) { |
| 10283 | ifname = get_station_ifname(); |
| 10284 | |
| 10285 | /* Disable STBC */ |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 10286 | run_iwpriv(dut, ifname, "tx_stbc 0"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 10287 | |
| 10288 | /* Extract Channel width */ |
| 10289 | val = get_param(cmd, "Channel_width"); |
| 10290 | if (val) { |
| 10291 | switch (atoi(val)) { |
| 10292 | case 20: |
| 10293 | chwidth = 0; |
| 10294 | break; |
| 10295 | case 40: |
| 10296 | chwidth = 1; |
| 10297 | break; |
| 10298 | case 80: |
| 10299 | chwidth = 2; |
| 10300 | break; |
| 10301 | case 160: |
| 10302 | chwidth = 3; |
| 10303 | break; |
| 10304 | default: |
| 10305 | chwidth = 2; |
| 10306 | break; |
| 10307 | } |
| 10308 | |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 10309 | run_iwpriv(dut, ifname, "chwidth %d", chwidth); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 10310 | } |
| 10311 | |
| 10312 | /* Extract NSS */ |
| 10313 | val = get_param(cmd, "NSS"); |
| 10314 | if (val) { |
| 10315 | switch (atoi(val)) { |
| 10316 | case 1: |
| 10317 | nss = 1; |
| 10318 | break; |
| 10319 | case 2: |
| 10320 | nss = 3; |
| 10321 | break; |
| 10322 | case 3: |
| 10323 | nss = 7; |
| 10324 | break; |
| 10325 | default: |
| 10326 | /* We do not support NSS > 3 */ |
| 10327 | nss = 3; |
| 10328 | break; |
| 10329 | } |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 10330 | run_iwpriv(dut, ifname, "rxchainmask %d", nss); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 10331 | } |
| 10332 | |
| 10333 | /* Opmode notify */ |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 10334 | run_iwpriv(dut, ifname, "opmode_notify 1"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 10335 | } |
| 10336 | |
| 10337 | return 1; |
| 10338 | } |
| 10339 | |
| 10340 | |
| 10341 | static int cmd_sta_send_frame_vht(struct sigma_dut *dut, |
| 10342 | struct sigma_conn *conn, |
| 10343 | struct sigma_cmd *cmd) |
| 10344 | { |
| 10345 | switch (get_driver_type()) { |
| 10346 | case DRIVER_ATHEROS: |
| 10347 | return ath_sta_send_frame_vht(dut, conn, cmd); |
| 10348 | default: |
| 10349 | send_resp(dut, conn, SIGMA_ERROR, |
| 10350 | "errorCode,Unsupported sta_set_frame(VHT) with the current driver"); |
| 10351 | return 0; |
| 10352 | } |
| 10353 | } |
| 10354 | |
| 10355 | |
Kiran Kumar Lokere | 419f696 | 2018-10-24 19:03:04 -0700 | [diff] [blame] | 10356 | static int wcn_sta_send_frame_he(struct sigma_dut *dut, struct sigma_conn *conn, |
| 10357 | struct sigma_cmd *cmd) |
| 10358 | { |
| 10359 | const char *val; |
| 10360 | const char *intf = get_param(cmd, "Interface"); |
| 10361 | |
Alexei Avshalom Lazar | 4a3c2f8 | 2019-05-02 13:35:37 +0300 | [diff] [blame] | 10362 | if (!intf) |
| 10363 | return -1; |
| 10364 | |
Kiran Kumar Lokere | 419f696 | 2018-10-24 19:03:04 -0700 | [diff] [blame] | 10365 | val = get_param(cmd, "framename"); |
| 10366 | if (!val) |
| 10367 | return -1; |
| 10368 | sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val); |
| 10369 | |
| 10370 | /* Command sequence to generate Op mode notification */ |
| 10371 | if (val && strcasecmp(val, "action") == 0) { |
| 10372 | val = get_param(cmd, "PPDUTxType"); |
| 10373 | if (val && strcasecmp(val, "TB") == 0) { |
| 10374 | if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 1)) { |
| 10375 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 10376 | "failed to send TB PPDU Tx cfg"); |
| 10377 | send_resp(dut, conn, SIGMA_ERROR, |
| 10378 | "ErrorCode,set TB PPDU Tx cfg failed"); |
| 10379 | return 0; |
| 10380 | } |
| 10381 | return 1; |
| 10382 | } |
| 10383 | |
| 10384 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 10385 | "Action Tx type is not defined"); |
| 10386 | } |
| 10387 | |
| 10388 | return 1; |
| 10389 | } |
| 10390 | |
| 10391 | |
| 10392 | static int cmd_sta_send_frame_he(struct sigma_dut *dut, |
| 10393 | struct sigma_conn *conn, |
| 10394 | struct sigma_cmd *cmd) |
| 10395 | { |
| 10396 | switch (get_driver_type()) { |
| 10397 | case DRIVER_WCN: |
| 10398 | return wcn_sta_send_frame_he(dut, conn, cmd); |
| 10399 | default: |
| 10400 | send_resp(dut, conn, SIGMA_ERROR, |
| 10401 | "errorCode,Unsupported sta_set_frame(HE) with the current driver"); |
| 10402 | return 0; |
| 10403 | } |
| 10404 | } |
| 10405 | |
| 10406 | |
Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 10407 | #ifdef __linux__ |
Alexei Avshalom Lazar | a90032d | 2019-05-02 13:34:02 +0300 | [diff] [blame] | 10408 | |
| 10409 | static int |
| 10410 | wil6210_send_p2p_frame_60g(struct sigma_dut *dut, struct sigma_cmd *cmd, |
| 10411 | const char *frame_name, const char *dest_mac) |
| 10412 | { |
| 10413 | int isprobereq = strcasecmp(frame_name, "probereq") == 0; |
| 10414 | const char *ssid = get_param(cmd, "ssid"); |
| 10415 | const char *countstr = get_param(cmd, "count"); |
| 10416 | const char *channelstr = get_param(cmd, "channel"); |
| 10417 | const char *group_id = get_param(cmd, "groupid"); |
| 10418 | const char *client_id = get_param(cmd, "clientmac"); |
| 10419 | int count, channel, freq, i; |
| 10420 | const char *fname; |
| 10421 | char frame[1024], src_mac[20], group_id_attr[25], |
| 10422 | device_macstr[3 * ETH_ALEN], client_mac[ETH_ALEN]; |
| 10423 | const char *group_ssid; |
| 10424 | const int group_ssid_prefix_len = 9; |
| 10425 | struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *) frame; |
| 10426 | size_t framelen = sizeof(frame); |
| 10427 | struct template_frame_tag tags[2]; |
| 10428 | size_t tags_total = ARRAY_SIZE(tags); |
| 10429 | int tag_index, len, dst_len; |
| 10430 | |
| 10431 | if (!countstr || !channelstr) { |
| 10432 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 10433 | "Missing argument: count, channel"); |
| 10434 | return -1; |
| 10435 | } |
| 10436 | if (isprobereq && !ssid) { |
| 10437 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 10438 | "Missing argument: ssid"); |
| 10439 | return -1; |
| 10440 | } |
| 10441 | if (!isprobereq && (!group_id || !client_id)) { |
| 10442 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 10443 | "Missing argument: group_id, client_id"); |
| 10444 | return -1; |
| 10445 | } |
| 10446 | |
| 10447 | count = atoi(countstr); |
| 10448 | channel = atoi(channelstr); |
| 10449 | freq = channel_to_freq(dut, channel); |
| 10450 | |
| 10451 | if (!freq) { |
| 10452 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 10453 | "invalid channel: %s", channelstr); |
| 10454 | return -1; |
| 10455 | } |
| 10456 | |
| 10457 | if (isprobereq) { |
| 10458 | if (strcasecmp(ssid, "wildcard") == 0) { |
| 10459 | fname = "probe_req_wildcard.txt"; |
| 10460 | } else if (strcasecmp(ssid, "P2P_Wildcard") == 0) { |
| 10461 | fname = "probe_req_P2P_Wildcard.txt"; |
| 10462 | } else { |
| 10463 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 10464 | "invalid probe request type"); |
| 10465 | return -1; |
| 10466 | } |
| 10467 | } else { |
| 10468 | fname = "P2P_device_discovery_req.txt"; |
| 10469 | } |
| 10470 | |
| 10471 | if (parse_template_frame_file(dut, fname, frame, &framelen, |
| 10472 | tags, &tags_total)) { |
| 10473 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 10474 | "invalid frame template: %s", fname); |
| 10475 | return -1; |
| 10476 | } |
| 10477 | |
| 10478 | if (get_wpa_status(get_station_ifname(), "address", |
| 10479 | src_mac, sizeof(src_mac)) < 0 || |
| 10480 | parse_mac_address(dut, src_mac, &hdr->addr2[0]) || |
| 10481 | parse_mac_address(dut, dest_mac, &hdr->addr1[0])) |
| 10482 | return -1; |
| 10483 | /* Use wildcard BSSID, since we are in PBSS */ |
| 10484 | memset(&hdr->addr3, 0xFF, ETH_ALEN); |
| 10485 | |
| 10486 | if (!isprobereq) { |
| 10487 | tag_index = find_template_frame_tag(tags, tags_total, 1); |
| 10488 | if (tag_index < 0) { |
| 10489 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 10490 | "can't find device id attribute"); |
| 10491 | return -1; |
| 10492 | } |
| 10493 | if (parse_mac_address(dut, client_id, |
| 10494 | (unsigned char *) client_mac)) { |
| 10495 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 10496 | "invalid client_id: %s", client_id); |
| 10497 | return -1; |
| 10498 | } |
| 10499 | if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset], |
| 10500 | framelen - tags[tag_index].offset, |
| 10501 | IEEE80211_P2P_ATTR_DEVICE_ID, |
| 10502 | client_mac, ETH_ALEN)) { |
| 10503 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 10504 | "fail to replace device id attribute"); |
| 10505 | return -1; |
| 10506 | } |
| 10507 | |
| 10508 | /* |
| 10509 | * group_id arg contains device MAC address followed by |
| 10510 | * space and SSID (DIRECT-somessid). |
| 10511 | * group id attribute contains device address (6 bytes) |
| 10512 | * followed by SSID prefix DIRECT-XX (9 bytes) |
| 10513 | */ |
| 10514 | if (strlen(group_id) < sizeof(device_macstr)) { |
| 10515 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 10516 | "group_id arg too short"); |
| 10517 | return -1; |
| 10518 | } |
| 10519 | memcpy(device_macstr, group_id, sizeof(device_macstr)); |
| 10520 | device_macstr[sizeof(device_macstr) - 1] = '\0'; |
| 10521 | if (parse_mac_address(dut, device_macstr, |
| 10522 | (unsigned char *) group_id_attr)) { |
| 10523 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 10524 | "fail to parse device address from group_id"); |
| 10525 | return -1; |
| 10526 | } |
| 10527 | group_ssid = strchr(group_id, ' '); |
| 10528 | if (!group_ssid) { |
| 10529 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 10530 | "invalid group_id arg, no ssid"); |
| 10531 | return -1; |
| 10532 | } |
| 10533 | group_ssid++; |
| 10534 | len = strlen(group_ssid); |
| 10535 | if (len < group_ssid_prefix_len) { |
| 10536 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 10537 | "group_id SSID too short"); |
| 10538 | return -1; |
| 10539 | } |
| 10540 | dst_len = sizeof(group_id_attr) - ETH_ALEN; |
| 10541 | if (len > dst_len) { |
| 10542 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 10543 | "group_id SSID (%s) too long", |
| 10544 | group_ssid); |
| 10545 | return -1; |
| 10546 | } |
| 10547 | |
| 10548 | memcpy(group_id_attr + ETH_ALEN, group_ssid, len); |
| 10549 | tag_index = find_template_frame_tag(tags, tags_total, 2); |
| 10550 | if (tag_index < 0) { |
| 10551 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 10552 | "can't find group id attribute"); |
| 10553 | return -1; |
| 10554 | } |
| 10555 | if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset], |
| 10556 | framelen - tags[tag_index].offset, |
| 10557 | IEEE80211_P2P_ATTR_GROUP_ID, |
| 10558 | group_id_attr, |
| 10559 | sizeof(group_id_attr))) { |
| 10560 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 10561 | "fail to replace group id attribute"); |
| 10562 | return -1; |
| 10563 | } |
| 10564 | } |
| 10565 | |
| 10566 | for (i = 0; i < count; i++) { |
| 10567 | if (wil6210_transmit_frame(dut, freq, |
| 10568 | WIL_TRANSMIT_FRAME_DEFAULT_ROC, |
| 10569 | frame, framelen)) { |
| 10570 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 10571 | "fail to transmit probe request frame"); |
| 10572 | return -1; |
| 10573 | } |
| 10574 | } |
| 10575 | |
| 10576 | return 0; |
| 10577 | } |
| 10578 | |
| 10579 | |
Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 10580 | int wil6210_send_frame_60g(struct sigma_dut *dut, struct sigma_conn *conn, |
| 10581 | struct sigma_cmd *cmd) |
| 10582 | { |
| 10583 | const char *frame_name = get_param(cmd, "framename"); |
| 10584 | const char *mac = get_param(cmd, "dest_mac"); |
| 10585 | |
| 10586 | if (!frame_name || !mac) { |
| 10587 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 10588 | "framename and dest_mac must be provided"); |
| 10589 | return -1; |
| 10590 | } |
| 10591 | |
| 10592 | if (strcasecmp(frame_name, "brp") == 0) { |
| 10593 | const char *l_rx = get_param(cmd, "L-RX"); |
| 10594 | int l_rx_i; |
| 10595 | |
| 10596 | if (!l_rx) { |
| 10597 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 10598 | "L-RX must be provided"); |
| 10599 | return -1; |
| 10600 | } |
| 10601 | l_rx_i = atoi(l_rx); |
| 10602 | |
| 10603 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 10604 | "dev_send_frame: BRP-RX, dest_mac %s, L-RX %s", |
| 10605 | mac, l_rx); |
| 10606 | if (l_rx_i != 16) { |
| 10607 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 10608 | "unsupported L-RX: %s", l_rx); |
| 10609 | return -1; |
| 10610 | } |
| 10611 | |
| 10612 | if (wil6210_send_brp_rx(dut, mac, l_rx_i)) |
| 10613 | return -1; |
| 10614 | } else if (strcasecmp(frame_name, "ssw") == 0) { |
| 10615 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 10616 | "dev_send_frame: SLS, dest_mac %s", mac); |
| 10617 | if (wil6210_send_sls(dut, mac)) |
| 10618 | return -1; |
Alexei Avshalom Lazar | a90032d | 2019-05-02 13:34:02 +0300 | [diff] [blame] | 10619 | } else if ((strcasecmp(frame_name, "probereq") == 0) || |
| 10620 | (strcasecmp(frame_name, "devdiscreq") == 0)) { |
| 10621 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 10622 | "dev_send_frame: %s, dest_mac %s", frame_name, |
| 10623 | mac); |
| 10624 | if (wil6210_send_p2p_frame_60g(dut, cmd, frame_name, mac)) |
| 10625 | return -1; |
Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 10626 | } else { |
| 10627 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 10628 | "unsupported frame type: %s", frame_name); |
| 10629 | return -1; |
| 10630 | } |
| 10631 | |
| 10632 | return 1; |
| 10633 | } |
Alexei Avshalom Lazar | a90032d | 2019-05-02 13:34:02 +0300 | [diff] [blame] | 10634 | |
Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 10635 | #endif /* __linux__ */ |
| 10636 | |
| 10637 | |
| 10638 | static int cmd_sta_send_frame_60g(struct sigma_dut *dut, |
| 10639 | struct sigma_conn *conn, |
| 10640 | struct sigma_cmd *cmd) |
| 10641 | { |
| 10642 | switch (get_driver_type()) { |
| 10643 | #ifdef __linux__ |
| 10644 | case DRIVER_WIL6210: |
| 10645 | return wil6210_send_frame_60g(dut, conn, cmd); |
| 10646 | #endif /* __linux__ */ |
| 10647 | default: |
| 10648 | send_resp(dut, conn, SIGMA_ERROR, |
| 10649 | "errorCode,Unsupported sta_set_frame(60G) with the current driver"); |
| 10650 | return 0; |
| 10651 | } |
| 10652 | } |
| 10653 | |
| 10654 | |
Ashwini Patil | db59b3c | 2017-04-13 15:19:23 +0530 | [diff] [blame] | 10655 | static int mbo_send_anqp_query(struct sigma_dut *dut, struct sigma_conn *conn, |
| 10656 | const char *intf, struct sigma_cmd *cmd) |
| 10657 | { |
| 10658 | const char *val, *addr; |
| 10659 | char buf[100]; |
| 10660 | |
| 10661 | addr = get_param(cmd, "DestMac"); |
| 10662 | if (!addr) { |
| 10663 | send_resp(dut, conn, SIGMA_INVALID, |
| 10664 | "ErrorCode,AP MAC address is missing"); |
| 10665 | return 0; |
| 10666 | } |
| 10667 | |
| 10668 | val = get_param(cmd, "ANQPQuery_ID"); |
| 10669 | if (!val) { |
| 10670 | send_resp(dut, conn, SIGMA_INVALID, |
| 10671 | "ErrorCode,Missing ANQPQuery_ID"); |
| 10672 | return 0; |
| 10673 | } |
| 10674 | |
| 10675 | if (strcasecmp(val, "NeighborReportReq") == 0) { |
| 10676 | snprintf(buf, sizeof(buf), "ANQP_GET %s 272", addr); |
| 10677 | } else if (strcasecmp(val, "QueryListWithCellPref") == 0) { |
| 10678 | snprintf(buf, sizeof(buf), "ANQP_GET %s 272,mbo:2", addr); |
| 10679 | } else { |
| 10680 | sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid ANQPQuery_ID: %s", |
| 10681 | val); |
| 10682 | send_resp(dut, conn, SIGMA_INVALID, |
| 10683 | "ErrorCode,Invalid ANQPQuery_ID"); |
| 10684 | return 0; |
| 10685 | } |
| 10686 | |
Ashwini Patil | d174f2c | 2017-04-13 16:49:46 +0530 | [diff] [blame] | 10687 | /* Set gas_address3 field to IEEE 802.11-2012 standard compliant form |
| 10688 | * (Address3 = Wildcard BSSID when sent to not-associated AP; |
| 10689 | * if associated, AP BSSID). |
| 10690 | */ |
| 10691 | if (wpa_command(intf, "SET gas_address3 1") < 0) { |
| 10692 | send_resp(dut, conn, SIGMA_ERROR, |
| 10693 | "ErrorCode,Failed to set gas_address3"); |
| 10694 | return 0; |
| 10695 | } |
| 10696 | |
Ashwini Patil | db59b3c | 2017-04-13 15:19:23 +0530 | [diff] [blame] | 10697 | if (wpa_command(intf, buf) < 0) { |
| 10698 | send_resp(dut, conn, SIGMA_ERROR, |
| 10699 | "ErrorCode,Failed to send ANQP query"); |
| 10700 | return 0; |
| 10701 | } |
| 10702 | |
| 10703 | return 1; |
| 10704 | } |
| 10705 | |
| 10706 | |
| 10707 | static int mbo_cmd_sta_send_frame(struct sigma_dut *dut, |
| 10708 | struct sigma_conn *conn, |
| 10709 | const char *intf, |
| 10710 | struct sigma_cmd *cmd) |
| 10711 | { |
| 10712 | const char *val = get_param(cmd, "FrameName"); |
| 10713 | |
| 10714 | if (val && strcasecmp(val, "ANQPQuery") == 0) |
| 10715 | return mbo_send_anqp_query(dut, conn, intf, cmd); |
| 10716 | |
| 10717 | return 2; |
| 10718 | } |
| 10719 | |
| 10720 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 10721 | enum sigma_cmd_result cmd_sta_send_frame(struct sigma_dut *dut, |
| 10722 | struct sigma_conn *conn, |
| 10723 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 10724 | { |
| 10725 | const char *intf = get_param(cmd, "Interface"); |
| 10726 | const char *val; |
| 10727 | enum send_frame_type frame; |
| 10728 | enum send_frame_protection protected; |
| 10729 | char buf[100]; |
| 10730 | unsigned char addr[ETH_ALEN]; |
| 10731 | int res; |
| 10732 | |
Alexei Avshalom Lazar | 4a3c2f8 | 2019-05-02 13:35:37 +0300 | [diff] [blame] | 10733 | if (!intf) |
| 10734 | return -1; |
| 10735 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 10736 | val = get_param(cmd, "program"); |
| 10737 | if (val == NULL) |
| 10738 | val = get_param(cmd, "frame"); |
| 10739 | if (val && strcasecmp(val, "TDLS") == 0) |
| 10740 | return cmd_sta_send_frame_tdls(dut, conn, cmd); |
| 10741 | if (val && (strcasecmp(val, "HS2") == 0 || |
Jouni Malinen | 1f6ae64 | 2018-06-07 23:56:13 +0300 | [diff] [blame] | 10742 | strcasecmp(val, "HS2-R2") == 0 || |
| 10743 | strcasecmp(val, "HS2-R3") == 0)) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 10744 | return cmd_sta_send_frame_hs2(dut, conn, cmd); |
| 10745 | if (val && strcasecmp(val, "VHT") == 0) |
| 10746 | return cmd_sta_send_frame_vht(dut, conn, cmd); |
Kiran Kumar Lokere | 419f696 | 2018-10-24 19:03:04 -0700 | [diff] [blame] | 10747 | if (val && strcasecmp(val, "HE") == 0) |
| 10748 | return cmd_sta_send_frame_he(dut, conn, cmd); |
priyadharshini gowthaman | d66913a | 2016-07-29 15:11:17 -0700 | [diff] [blame] | 10749 | if (val && strcasecmp(val, "LOC") == 0) |
| 10750 | return loc_cmd_sta_send_frame(dut, conn, cmd); |
Lior David | 0fe101e | 2017-03-09 16:09:50 +0200 | [diff] [blame] | 10751 | if (val && strcasecmp(val, "60GHz") == 0) |
| 10752 | return cmd_sta_send_frame_60g(dut, conn, cmd); |
Ashwini Patil | db59b3c | 2017-04-13 15:19:23 +0530 | [diff] [blame] | 10753 | if (val && strcasecmp(val, "MBO") == 0) { |
| 10754 | res = mbo_cmd_sta_send_frame(dut, conn, intf, cmd); |
| 10755 | if (res != 2) |
| 10756 | return res; |
| 10757 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 10758 | |
| 10759 | val = get_param(cmd, "TD_DISC"); |
| 10760 | if (val) { |
| 10761 | if (hwaddr_aton(val, addr) < 0) |
| 10762 | return -1; |
| 10763 | snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", val); |
| 10764 | if (wpa_command(intf, buf) < 0) { |
| 10765 | send_resp(dut, conn, SIGMA_ERROR, |
| 10766 | "ErrorCode,Failed to send TDLS discovery"); |
| 10767 | return 0; |
| 10768 | } |
| 10769 | return 1; |
| 10770 | } |
| 10771 | |
| 10772 | val = get_param(cmd, "TD_Setup"); |
| 10773 | if (val) { |
| 10774 | if (hwaddr_aton(val, addr) < 0) |
| 10775 | return -1; |
| 10776 | snprintf(buf, sizeof(buf), "TDLS_SETUP %s", val); |
| 10777 | if (wpa_command(intf, buf) < 0) { |
| 10778 | send_resp(dut, conn, SIGMA_ERROR, |
| 10779 | "ErrorCode,Failed to start TDLS setup"); |
| 10780 | return 0; |
| 10781 | } |
| 10782 | return 1; |
| 10783 | } |
| 10784 | |
| 10785 | val = get_param(cmd, "TD_TearDown"); |
| 10786 | if (val) { |
| 10787 | if (hwaddr_aton(val, addr) < 0) |
| 10788 | return -1; |
| 10789 | snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", val); |
| 10790 | if (wpa_command(intf, buf) < 0) { |
| 10791 | send_resp(dut, conn, SIGMA_ERROR, |
| 10792 | "ErrorCode,Failed to tear down TDLS link"); |
| 10793 | return 0; |
| 10794 | } |
| 10795 | return 1; |
| 10796 | } |
| 10797 | |
| 10798 | val = get_param(cmd, "TD_ChannelSwitch"); |
| 10799 | if (val) { |
| 10800 | /* TODO */ |
| 10801 | send_resp(dut, conn, SIGMA_ERROR, |
| 10802 | "ErrorCode,TD_ChannelSwitch not yet supported"); |
| 10803 | return 0; |
| 10804 | } |
| 10805 | |
| 10806 | val = get_param(cmd, "TD_NF"); |
| 10807 | if (val) { |
| 10808 | /* TODO */ |
| 10809 | send_resp(dut, conn, SIGMA_ERROR, |
| 10810 | "ErrorCode,TD_NF not yet supported"); |
| 10811 | return 0; |
| 10812 | } |
| 10813 | |
| 10814 | val = get_param(cmd, "PMFFrameType"); |
| 10815 | if (val == NULL) |
| 10816 | val = get_param(cmd, "FrameName"); |
| 10817 | if (val == NULL) |
| 10818 | val = get_param(cmd, "Type"); |
| 10819 | if (val == NULL) |
| 10820 | return -1; |
| 10821 | if (strcasecmp(val, "disassoc") == 0) |
| 10822 | frame = DISASSOC; |
| 10823 | else if (strcasecmp(val, "deauth") == 0) |
| 10824 | frame = DEAUTH; |
| 10825 | else if (strcasecmp(val, "saquery") == 0) |
| 10826 | frame = SAQUERY; |
| 10827 | else if (strcasecmp(val, "auth") == 0) |
| 10828 | frame = AUTH; |
| 10829 | else if (strcasecmp(val, "assocreq") == 0) |
| 10830 | frame = ASSOCREQ; |
| 10831 | else if (strcasecmp(val, "reassocreq") == 0) |
| 10832 | frame = REASSOCREQ; |
| 10833 | else if (strcasecmp(val, "neigreq") == 0) { |
| 10834 | sigma_dut_print(dut, DUT_MSG_INFO, "Got neighbor request"); |
| 10835 | |
| 10836 | val = get_param(cmd, "ssid"); |
| 10837 | if (val == NULL) |
| 10838 | return -1; |
| 10839 | |
| 10840 | res = send_neighbor_request(dut, intf, val); |
| 10841 | if (res) { |
| 10842 | send_resp(dut, conn, SIGMA_ERROR, "errorCode," |
| 10843 | "Failed to send neighbor report request"); |
| 10844 | return 0; |
| 10845 | } |
| 10846 | |
| 10847 | return 1; |
Ashwini Patil | 5acd738 | 2017-04-13 15:55:04 +0530 | [diff] [blame] | 10848 | } else if (strcasecmp(val, "transmgmtquery") == 0 || |
| 10849 | strcasecmp(val, "BTMQuery") == 0) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 10850 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 10851 | "Got Transition Management Query"); |
| 10852 | |
Ashwini Patil | 5acd738 | 2017-04-13 15:55:04 +0530 | [diff] [blame] | 10853 | res = send_trans_mgmt_query(dut, intf, cmd); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 10854 | if (res) { |
| 10855 | send_resp(dut, conn, SIGMA_ERROR, "errorCode," |
| 10856 | "Failed to send Transition Management Query"); |
| 10857 | return 0; |
| 10858 | } |
| 10859 | |
| 10860 | return 1; |
| 10861 | } else { |
| 10862 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported " |
| 10863 | "PMFFrameType"); |
| 10864 | return 0; |
| 10865 | } |
| 10866 | |
| 10867 | val = get_param(cmd, "PMFProtected"); |
| 10868 | if (val == NULL) |
| 10869 | val = get_param(cmd, "Protected"); |
| 10870 | if (val == NULL) |
| 10871 | return -1; |
| 10872 | if (strcasecmp(val, "Correct-key") == 0 || |
| 10873 | strcasecmp(val, "CorrectKey") == 0) |
| 10874 | protected = CORRECT_KEY; |
| 10875 | else if (strcasecmp(val, "IncorrectKey") == 0) |
| 10876 | protected = INCORRECT_KEY; |
| 10877 | else if (strcasecmp(val, "Unprotected") == 0) |
| 10878 | protected = UNPROTECTED; |
| 10879 | else { |
| 10880 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported " |
| 10881 | "PMFProtected"); |
| 10882 | return 0; |
| 10883 | } |
| 10884 | |
| 10885 | if (protected != UNPROTECTED && |
| 10886 | (frame == AUTH || frame == ASSOCREQ || frame == REASSOCREQ)) { |
| 10887 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Impossible " |
| 10888 | "PMFProtected for auth/assocreq/reassocreq"); |
| 10889 | return 0; |
| 10890 | } |
| 10891 | |
| 10892 | if (if_nametoindex("sigmadut") == 0) { |
| 10893 | snprintf(buf, sizeof(buf), |
| 10894 | "iw dev %s interface add sigmadut type monitor", |
| 10895 | get_station_ifname()); |
| 10896 | if (system(buf) != 0 || |
| 10897 | if_nametoindex("sigmadut") == 0) { |
| 10898 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add " |
| 10899 | "monitor interface with '%s'", buf); |
| 10900 | return -2; |
| 10901 | } |
| 10902 | } |
| 10903 | |
| 10904 | if (system("ifconfig sigmadut up") != 0) { |
| 10905 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set " |
| 10906 | "monitor interface up"); |
| 10907 | return -2; |
| 10908 | } |
| 10909 | |
| 10910 | return sta_inject_frame(dut, conn, frame, protected, NULL); |
| 10911 | } |
| 10912 | |
| 10913 | |
| 10914 | static int cmd_sta_set_parameter_hs2(struct sigma_dut *dut, |
| 10915 | struct sigma_conn *conn, |
| 10916 | struct sigma_cmd *cmd, |
| 10917 | const char *ifname) |
| 10918 | { |
| 10919 | char buf[200]; |
| 10920 | const char *val; |
| 10921 | |
| 10922 | val = get_param(cmd, "ClearARP"); |
| 10923 | if (val && atoi(val) == 1) { |
| 10924 | snprintf(buf, sizeof(buf), "ip neigh flush dev %s", ifname); |
| 10925 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 10926 | if (system(buf) != 0) { |
| 10927 | send_resp(dut, conn, SIGMA_ERROR, |
| 10928 | "errorCode,Failed to clear ARP cache"); |
| 10929 | return 0; |
| 10930 | } |
| 10931 | } |
| 10932 | |
| 10933 | return 1; |
| 10934 | } |
| 10935 | |
| 10936 | |
| 10937 | int cmd_sta_set_parameter(struct sigma_dut *dut, struct sigma_conn *conn, |
| 10938 | struct sigma_cmd *cmd) |
| 10939 | { |
| 10940 | const char *intf = get_param(cmd, "Interface"); |
| 10941 | const char *val; |
| 10942 | |
| 10943 | if (intf == NULL) |
| 10944 | return -1; |
| 10945 | |
| 10946 | val = get_param(cmd, "program"); |
| 10947 | if (val && (strcasecmp(val, "HS2") == 0 || |
Jouni Malinen | 1f6ae64 | 2018-06-07 23:56:13 +0300 | [diff] [blame] | 10948 | strcasecmp(val, "HS2-R2") == 0 || |
| 10949 | strcasecmp(val, "HS2-R3") == 0)) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 10950 | return cmd_sta_set_parameter_hs2(dut, conn, cmd, intf); |
| 10951 | |
| 10952 | return -1; |
| 10953 | } |
| 10954 | |
| 10955 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 10956 | static enum sigma_cmd_result cmd_sta_set_macaddr(struct sigma_dut *dut, |
| 10957 | struct sigma_conn *conn, |
| 10958 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 10959 | { |
| 10960 | const char *intf = get_param(cmd, "Interface"); |
| 10961 | const char *mac = get_param(cmd, "MAC"); |
| 10962 | |
| 10963 | if (intf == NULL || mac == NULL) |
| 10964 | return -1; |
| 10965 | |
| 10966 | sigma_dut_print(dut, DUT_MSG_INFO, "Change local MAC address for " |
| 10967 | "interface %s to %s", intf, mac); |
| 10968 | |
| 10969 | if (dut->set_macaddr) { |
| 10970 | char buf[128]; |
| 10971 | int res; |
| 10972 | if (strcasecmp(mac, "default") == 0) { |
| 10973 | res = snprintf(buf, sizeof(buf), "%s", |
| 10974 | dut->set_macaddr); |
| 10975 | dut->tmp_mac_addr = 0; |
| 10976 | } else { |
| 10977 | res = snprintf(buf, sizeof(buf), "%s %s", |
| 10978 | dut->set_macaddr, mac); |
| 10979 | dut->tmp_mac_addr = 1; |
| 10980 | } |
| 10981 | if (res < 0 || res >= (int) sizeof(buf)) |
| 10982 | return -1; |
| 10983 | if (system(buf) != 0) { |
| 10984 | send_resp(dut, conn, SIGMA_ERROR, |
| 10985 | "errorCode,Failed to set MAC " |
| 10986 | "address"); |
| 10987 | return 0; |
| 10988 | } |
| 10989 | return 1; |
| 10990 | } |
| 10991 | |
| 10992 | if (strcasecmp(mac, "default") == 0) |
| 10993 | return 1; |
| 10994 | |
| 10995 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported " |
| 10996 | "command"); |
| 10997 | return 0; |
| 10998 | } |
| 10999 | |
| 11000 | |
| 11001 | static int iwpriv_tdlsoffchnmode(struct sigma_dut *dut, |
| 11002 | struct sigma_conn *conn, const char *intf, |
| 11003 | int val) |
| 11004 | { |
| 11005 | char buf[200]; |
| 11006 | int res; |
| 11007 | |
| 11008 | res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchnmode %d", |
| 11009 | intf, val); |
| 11010 | if (res < 0 || res >= (int) sizeof(buf)) |
| 11011 | return -1; |
| 11012 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 11013 | if (system(buf) != 0) { |
| 11014 | send_resp(dut, conn, SIGMA_ERROR, |
| 11015 | "errorCode,Failed to configure offchannel mode"); |
| 11016 | return 0; |
| 11017 | } |
| 11018 | |
| 11019 | return 1; |
| 11020 | } |
| 11021 | |
| 11022 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 11023 | static int off_chan_val(enum sec_ch_offset off) |
| 11024 | { |
| 11025 | switch (off) { |
| 11026 | case SEC_CH_NO: |
| 11027 | return 0; |
| 11028 | case SEC_CH_40ABOVE: |
| 11029 | return 40; |
| 11030 | case SEC_CH_40BELOW: |
| 11031 | return -40; |
| 11032 | } |
| 11033 | |
| 11034 | return 0; |
| 11035 | } |
| 11036 | |
| 11037 | |
| 11038 | static int iwpriv_set_offchan(struct sigma_dut *dut, struct sigma_conn *conn, |
| 11039 | const char *intf, int off_ch_num, |
| 11040 | enum sec_ch_offset sec) |
| 11041 | { |
| 11042 | char buf[200]; |
| 11043 | int res; |
| 11044 | |
| 11045 | res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchan %d", |
| 11046 | intf, off_ch_num); |
| 11047 | if (res < 0 || res >= (int) sizeof(buf)) |
| 11048 | return -1; |
| 11049 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 11050 | if (system(buf) != 0) { |
| 11051 | send_resp(dut, conn, SIGMA_ERROR, |
| 11052 | "errorCode,Failed to set offchan"); |
| 11053 | return 0; |
| 11054 | } |
| 11055 | |
| 11056 | res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsecchnoffst %d", |
| 11057 | intf, off_chan_val(sec)); |
| 11058 | if (res < 0 || res >= (int) sizeof(buf)) |
| 11059 | return -1; |
| 11060 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 11061 | if (system(buf) != 0) { |
| 11062 | send_resp(dut, conn, SIGMA_ERROR, |
| 11063 | "errorCode,Failed to set sec chan offset"); |
| 11064 | return 0; |
| 11065 | } |
| 11066 | |
| 11067 | return 1; |
| 11068 | } |
| 11069 | |
| 11070 | |
| 11071 | static int tdls_set_offchannel_offset(struct sigma_dut *dut, |
| 11072 | struct sigma_conn *conn, |
| 11073 | const char *intf, int off_ch_num, |
| 11074 | enum sec_ch_offset sec) |
| 11075 | { |
| 11076 | char buf[200]; |
| 11077 | int res; |
| 11078 | |
| 11079 | res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNEL %d", |
| 11080 | off_ch_num); |
| 11081 | if (res < 0 || res >= (int) sizeof(buf)) |
| 11082 | return -1; |
| 11083 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 11084 | |
| 11085 | if (wpa_command(intf, buf) < 0) { |
| 11086 | send_resp(dut, conn, SIGMA_ERROR, |
| 11087 | "ErrorCode,Failed to set offchan"); |
| 11088 | return 0; |
| 11089 | } |
| 11090 | res = snprintf(buf, sizeof(buf), "DRIVER TDLSSECONDARYCHANNELOFFSET %d", |
| 11091 | off_chan_val(sec)); |
| 11092 | if (res < 0 || res >= (int) sizeof(buf)) |
| 11093 | return -1; |
| 11094 | |
| 11095 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 11096 | |
| 11097 | if (wpa_command(intf, buf) < 0) { |
| 11098 | send_resp(dut, conn, SIGMA_ERROR, |
| 11099 | "ErrorCode,Failed to set sec chan offset"); |
| 11100 | return 0; |
| 11101 | } |
| 11102 | |
| 11103 | return 1; |
| 11104 | } |
| 11105 | |
| 11106 | |
| 11107 | static int tdls_set_offchannel_mode(struct sigma_dut *dut, |
| 11108 | struct sigma_conn *conn, |
| 11109 | const char *intf, int val) |
| 11110 | { |
| 11111 | char buf[200]; |
| 11112 | int res; |
| 11113 | |
| 11114 | res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNELMODE %d", |
| 11115 | val); |
| 11116 | if (res < 0 || res >= (int) sizeof(buf)) |
| 11117 | return -1; |
| 11118 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf); |
| 11119 | |
| 11120 | if (wpa_command(intf, buf) < 0) { |
| 11121 | send_resp(dut, conn, SIGMA_ERROR, |
| 11122 | "ErrorCode,Failed to configure offchannel mode"); |
| 11123 | return 0; |
| 11124 | } |
| 11125 | |
| 11126 | return 1; |
| 11127 | } |
| 11128 | |
| 11129 | |
| 11130 | static int cmd_sta_set_rfeature_tdls(const char *intf, struct sigma_dut *dut, |
| 11131 | struct sigma_conn *conn, |
| 11132 | struct sigma_cmd *cmd) |
| 11133 | { |
| 11134 | const char *val; |
| 11135 | enum { |
| 11136 | CHSM_NOT_SET, |
| 11137 | CHSM_ENABLE, |
| 11138 | CHSM_DISABLE, |
| 11139 | CHSM_REJREQ, |
| 11140 | CHSM_UNSOLRESP |
| 11141 | } chsm = CHSM_NOT_SET; |
| 11142 | int off_ch_num = -1; |
| 11143 | enum sec_ch_offset sec_ch = SEC_CH_NO; |
| 11144 | int res; |
| 11145 | |
| 11146 | val = get_param(cmd, "Uapsd"); |
| 11147 | if (val) { |
| 11148 | char buf[100]; |
| 11149 | if (strcasecmp(val, "Enable") == 0) |
| 11150 | snprintf(buf, sizeof(buf), "SET ps 99"); |
| 11151 | else if (strcasecmp(val, "Disable") == 0) |
| 11152 | snprintf(buf, sizeof(buf), "SET ps 98"); |
| 11153 | else { |
| 11154 | send_resp(dut, conn, SIGMA_ERROR, "errorCode," |
| 11155 | "Unsupported uapsd parameter value"); |
| 11156 | return 0; |
| 11157 | } |
| 11158 | if (wpa_command(intf, buf)) { |
| 11159 | send_resp(dut, conn, SIGMA_ERROR, |
| 11160 | "ErrorCode,Failed to change U-APSD " |
| 11161 | "powersave mode"); |
| 11162 | return 0; |
| 11163 | } |
| 11164 | } |
| 11165 | |
| 11166 | val = get_param(cmd, "TPKTIMER"); |
| 11167 | if (val && strcasecmp(val, "DISABLE") == 0) { |
| 11168 | if (wpa_command(intf, "SET tdls_testing 0x100")) { |
| 11169 | send_resp(dut, conn, SIGMA_ERROR, |
| 11170 | "ErrorCode,Failed to enable no TPK " |
| 11171 | "expiration test mode"); |
| 11172 | return 0; |
| 11173 | } |
| 11174 | dut->no_tpk_expiration = 1; |
| 11175 | } |
| 11176 | |
| 11177 | val = get_param(cmd, "ChSwitchMode"); |
| 11178 | if (val) { |
| 11179 | if (strcasecmp(val, "Enable") == 0 || |
| 11180 | strcasecmp(val, "Initiate") == 0) |
| 11181 | chsm = CHSM_ENABLE; |
| 11182 | else if (strcasecmp(val, "Disable") == 0 || |
| 11183 | strcasecmp(val, "passive") == 0) |
| 11184 | chsm = CHSM_DISABLE; |
| 11185 | else if (strcasecmp(val, "RejReq") == 0) |
| 11186 | chsm = CHSM_REJREQ; |
| 11187 | else if (strcasecmp(val, "UnSolResp") == 0) |
| 11188 | chsm = CHSM_UNSOLRESP; |
| 11189 | else { |
| 11190 | send_resp(dut, conn, SIGMA_ERROR, |
| 11191 | "ErrorCode,Unknown ChSwitchMode value"); |
| 11192 | return 0; |
| 11193 | } |
| 11194 | } |
| 11195 | |
| 11196 | val = get_param(cmd, "OffChNum"); |
| 11197 | if (val) { |
| 11198 | off_ch_num = atoi(val); |
| 11199 | if (off_ch_num == 0) { |
| 11200 | send_resp(dut, conn, SIGMA_ERROR, |
| 11201 | "ErrorCode,Invalid OffChNum"); |
| 11202 | return 0; |
| 11203 | } |
| 11204 | } |
| 11205 | |
| 11206 | val = get_param(cmd, "SecChOffset"); |
| 11207 | if (val) { |
| 11208 | if (strcmp(val, "20") == 0) |
| 11209 | sec_ch = SEC_CH_NO; |
| 11210 | else if (strcasecmp(val, "40above") == 0) |
| 11211 | sec_ch = SEC_CH_40ABOVE; |
| 11212 | else if (strcasecmp(val, "40below") == 0) |
| 11213 | sec_ch = SEC_CH_40BELOW; |
| 11214 | else { |
| 11215 | send_resp(dut, conn, SIGMA_ERROR, |
| 11216 | "ErrorCode,Unknown SecChOffset value"); |
| 11217 | return 0; |
| 11218 | } |
| 11219 | } |
| 11220 | |
| 11221 | if (chsm == CHSM_NOT_SET) { |
| 11222 | /* no offchannel changes requested */ |
| 11223 | return 1; |
| 11224 | } |
| 11225 | |
| 11226 | if (strcmp(intf, get_main_ifname()) != 0 && |
| 11227 | strcmp(intf, get_station_ifname()) != 0) { |
| 11228 | send_resp(dut, conn, SIGMA_ERROR, |
| 11229 | "ErrorCode,Unknown interface"); |
| 11230 | return 0; |
| 11231 | } |
| 11232 | |
| 11233 | switch (chsm) { |
| 11234 | case CHSM_NOT_SET: |
Jouni Malinen | 280f5ba | 2016-08-29 21:33:10 +0300 | [diff] [blame] | 11235 | res = 1; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 11236 | break; |
| 11237 | case CHSM_ENABLE: |
| 11238 | if (off_ch_num < 0) { |
| 11239 | send_resp(dut, conn, SIGMA_ERROR, |
| 11240 | "ErrorCode,Missing OffChNum argument"); |
| 11241 | return 0; |
| 11242 | } |
| 11243 | if (wifi_chip_type == DRIVER_WCN) { |
| 11244 | res = tdls_set_offchannel_offset(dut, conn, intf, |
| 11245 | off_ch_num, sec_ch); |
| 11246 | } else { |
| 11247 | res = iwpriv_set_offchan(dut, conn, intf, off_ch_num, |
| 11248 | sec_ch); |
| 11249 | } |
| 11250 | if (res != 1) |
| 11251 | return res; |
| 11252 | if (wifi_chip_type == DRIVER_WCN) |
| 11253 | res = tdls_set_offchannel_mode(dut, conn, intf, 1); |
| 11254 | else |
| 11255 | res = iwpriv_tdlsoffchnmode(dut, conn, intf, 1); |
| 11256 | break; |
| 11257 | case CHSM_DISABLE: |
| 11258 | if (wifi_chip_type == DRIVER_WCN) |
| 11259 | res = tdls_set_offchannel_mode(dut, conn, intf, 2); |
| 11260 | else |
| 11261 | res = iwpriv_tdlsoffchnmode(dut, conn, intf, 2); |
| 11262 | break; |
| 11263 | case CHSM_REJREQ: |
| 11264 | if (wifi_chip_type == DRIVER_WCN) |
| 11265 | res = tdls_set_offchannel_mode(dut, conn, intf, 3); |
| 11266 | else |
| 11267 | res = iwpriv_tdlsoffchnmode(dut, conn, intf, 3); |
| 11268 | break; |
| 11269 | case CHSM_UNSOLRESP: |
| 11270 | if (off_ch_num < 0) { |
| 11271 | send_resp(dut, conn, SIGMA_ERROR, |
| 11272 | "ErrorCode,Missing OffChNum argument"); |
| 11273 | return 0; |
| 11274 | } |
| 11275 | if (wifi_chip_type == DRIVER_WCN) { |
| 11276 | res = tdls_set_offchannel_offset(dut, conn, intf, |
| 11277 | off_ch_num, sec_ch); |
| 11278 | } else { |
| 11279 | res = iwpriv_set_offchan(dut, conn, intf, off_ch_num, |
| 11280 | sec_ch); |
| 11281 | } |
| 11282 | if (res != 1) |
| 11283 | return res; |
| 11284 | if (wifi_chip_type == DRIVER_WCN) |
| 11285 | res = tdls_set_offchannel_mode(dut, conn, intf, 4); |
| 11286 | else |
| 11287 | res = iwpriv_tdlsoffchnmode(dut, conn, intf, 4); |
| 11288 | break; |
| 11289 | } |
| 11290 | |
| 11291 | return res; |
| 11292 | } |
| 11293 | |
| 11294 | |
| 11295 | static int ath_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut, |
| 11296 | struct sigma_conn *conn, |
| 11297 | struct sigma_cmd *cmd) |
| 11298 | { |
| 11299 | const char *val; |
Srikanth Marepalli | 5415acf | 2018-08-27 12:53:11 +0530 | [diff] [blame] | 11300 | char *token = NULL, *result; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 11301 | |
Priyadharshini Gowthaman | 8c5b9a4 | 2019-07-31 14:38:48 -0700 | [diff] [blame] | 11302 | novap_reset(dut, intf, 1); |
priyadharshini gowthaman | e5e2517 | 2015-12-08 14:53:48 -0800 | [diff] [blame] | 11303 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 11304 | val = get_param(cmd, "nss_mcs_opt"); |
| 11305 | if (val) { |
| 11306 | /* String (nss_operating_mode; mcs_operating_mode) */ |
| 11307 | int nss, mcs; |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 11308 | char *saveptr; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 11309 | |
| 11310 | token = strdup(val); |
| 11311 | if (!token) |
| 11312 | return 0; |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 11313 | result = strtok_r(token, ";", &saveptr); |
Pradeep Reddy POTTETI | 41b8c54 | 2016-06-15 16:09:46 +0530 | [diff] [blame] | 11314 | if (!result) { |
| 11315 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 11316 | "VHT NSS not specified"); |
| 11317 | goto failed; |
| 11318 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 11319 | if (strcasecmp(result, "def") != 0) { |
| 11320 | nss = atoi(result); |
| 11321 | if (nss == 4) |
| 11322 | ath_disable_txbf(dut, intf); |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 11323 | if (run_iwpriv(dut, intf, "nss %d", nss) < 0) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 11324 | goto failed; |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 11325 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 11326 | } |
| 11327 | |
Pradeep Reddy POTTETI | dbf7d71 | 2016-04-28 18:42:07 +0530 | [diff] [blame] | 11328 | result = strtok_r(NULL, ";", &saveptr); |
Pradeep Reddy POTTETI | 41b8c54 | 2016-06-15 16:09:46 +0530 | [diff] [blame] | 11329 | if (!result) { |
| 11330 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 11331 | "VHT MCS not specified"); |
| 11332 | goto failed; |
| 11333 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 11334 | if (strcasecmp(result, "def") == 0) { |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 11335 | if (run_iwpriv(dut, intf, "set11NRates 0") < 0) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 11336 | goto failed; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 11337 | } else { |
| 11338 | mcs = atoi(result); |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 11339 | if (run_iwpriv(dut, intf, "vhtmcs %d", mcs) < 0) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 11340 | goto failed; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 11341 | } |
| 11342 | /* Channel width gets messed up, fix this */ |
Priyadharshini Gowthaman | b999e9e | 2019-04-22 15:45:55 -0700 | [diff] [blame] | 11343 | run_iwpriv(dut, intf, "chwidth %d", dut->chwidth); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 11344 | } |
| 11345 | |
Srikanth Marepalli | 5415acf | 2018-08-27 12:53:11 +0530 | [diff] [blame] | 11346 | free(token); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 11347 | return 1; |
| 11348 | failed: |
| 11349 | free(token); |
| 11350 | return 0; |
| 11351 | } |
| 11352 | |
| 11353 | |
| 11354 | static int cmd_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut, |
| 11355 | struct sigma_conn *conn, |
| 11356 | struct sigma_cmd *cmd) |
| 11357 | { |
| 11358 | switch (get_driver_type()) { |
| 11359 | case DRIVER_ATHEROS: |
| 11360 | return ath_sta_set_rfeature_vht(intf, dut, conn, cmd); |
| 11361 | default: |
| 11362 | send_resp(dut, conn, SIGMA_ERROR, |
| 11363 | "errorCode,Unsupported sta_set_rfeature(VHT) with the current driver"); |
| 11364 | return 0; |
| 11365 | } |
| 11366 | } |
| 11367 | |
| 11368 | |
Amarnath Hullur Subramanyam | 42c25a0 | 2018-01-31 04:02:27 -0800 | [diff] [blame] | 11369 | static int wcn_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut, |
| 11370 | struct sigma_conn *conn, |
| 11371 | struct sigma_cmd *cmd) |
| 11372 | { |
| 11373 | const char *val; |
| 11374 | char *token = NULL, *result; |
| 11375 | char buf[60]; |
| 11376 | |
| 11377 | val = get_param(cmd, "nss_mcs_opt"); |
| 11378 | if (val) { |
| 11379 | /* String (nss_operating_mode; mcs_operating_mode) */ |
| 11380 | int nss, mcs, ratecode; |
| 11381 | char *saveptr; |
| 11382 | |
| 11383 | token = strdup(val); |
| 11384 | if (!token) |
| 11385 | return -2; |
| 11386 | |
| 11387 | result = strtok_r(token, ";", &saveptr); |
| 11388 | if (!result) { |
| 11389 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 11390 | "HE NSS not specified"); |
| 11391 | goto failed; |
| 11392 | } |
| 11393 | nss = 1; |
| 11394 | if (strcasecmp(result, "def") != 0) |
| 11395 | nss = atoi(result); |
| 11396 | |
| 11397 | result = strtok_r(NULL, ";", &saveptr); |
| 11398 | if (!result) { |
| 11399 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 11400 | "HE MCS not specified"); |
| 11401 | goto failed; |
| 11402 | } |
| 11403 | mcs = 7; |
| 11404 | if (strcasecmp(result, "def") != 0) |
| 11405 | mcs = atoi(result); |
| 11406 | |
Arif Hussain | 557bf41 | 2018-05-25 17:29:36 -0700 | [diff] [blame] | 11407 | ratecode = 0x20; /* for nss:1 MCS 0 */ |
Amarnath Hullur Subramanyam | 42c25a0 | 2018-01-31 04:02:27 -0800 | [diff] [blame] | 11408 | if (nss == 2) { |
Arif Hussain | 557bf41 | 2018-05-25 17:29:36 -0700 | [diff] [blame] | 11409 | ratecode = 0x40; /* for nss:2 MCS 0 */ |
Amarnath Hullur Subramanyam | 42c25a0 | 2018-01-31 04:02:27 -0800 | [diff] [blame] | 11410 | } else if (nss > 2) { |
| 11411 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 11412 | "HE NSS %d not supported", nss); |
| 11413 | goto failed; |
| 11414 | } |
| 11415 | |
Arif Hussain | 557bf41 | 2018-05-25 17:29:36 -0700 | [diff] [blame] | 11416 | snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss); |
| 11417 | if (system(buf) != 0) { |
| 11418 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 11419 | "nss_mcs_opt: iwpriv %s nss %d failed", |
| 11420 | intf, nss); |
| 11421 | goto failed; |
| 11422 | } |
Arif Hussain | ac6c511 | 2018-05-25 17:34:00 -0700 | [diff] [blame] | 11423 | dut->sta_nss = nss; |
Arif Hussain | 557bf41 | 2018-05-25 17:29:36 -0700 | [diff] [blame] | 11424 | |
Amarnath Hullur Subramanyam | 42c25a0 | 2018-01-31 04:02:27 -0800 | [diff] [blame] | 11425 | /* Add the MCS to the ratecode */ |
| 11426 | if (mcs >= 0 && mcs <= 11) { |
| 11427 | ratecode += mcs; |
Arif Hussain | 557bf41 | 2018-05-25 17:29:36 -0700 | [diff] [blame] | 11428 | #ifdef NL80211_SUPPORT |
| 11429 | if (dut->device_type == STA_testbed) { |
| 11430 | enum he_mcs_config mcs_config; |
| 11431 | int ret; |
| 11432 | |
| 11433 | if (mcs <= 7) |
| 11434 | mcs_config = HE_80_MCS0_7; |
| 11435 | else if (mcs <= 9) |
| 11436 | mcs_config = HE_80_MCS0_9; |
| 11437 | else |
| 11438 | mcs_config = HE_80_MCS0_11; |
| 11439 | ret = sta_set_he_mcs(dut, intf, mcs_config); |
| 11440 | if (ret) { |
| 11441 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 11442 | "nss_mcs_opt: mcs setting failed, mcs:%d, mcs_config %d, ret:%d", |
| 11443 | mcs, mcs_config, ret); |
| 11444 | goto failed; |
| 11445 | } |
| 11446 | } |
| 11447 | #endif /* NL80211_SUPPORT */ |
Amarnath Hullur Subramanyam | 42c25a0 | 2018-01-31 04:02:27 -0800 | [diff] [blame] | 11448 | } else { |
| 11449 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 11450 | "HE MCS %d not supported", mcs); |
| 11451 | goto failed; |
| 11452 | } |
| 11453 | snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0x%03x", |
| 11454 | intf, ratecode); |
| 11455 | if (system(buf) != 0) { |
| 11456 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 11457 | "iwpriv setting of 11ax rates failed"); |
| 11458 | goto failed; |
| 11459 | } |
| 11460 | free(token); |
| 11461 | } |
| 11462 | |
| 11463 | val = get_param(cmd, "GI"); |
| 11464 | if (val) { |
Kiran Kumar Lokere | f6592d7 | 2019-01-16 18:44:00 -0800 | [diff] [blame] | 11465 | int fix_rate_sgi; |
| 11466 | |
Amarnath Hullur Subramanyam | 42c25a0 | 2018-01-31 04:02:27 -0800 | [diff] [blame] | 11467 | if (strcmp(val, "0.8") == 0) { |
Kiran Kumar Lokere | b8fec52 | 2018-05-01 14:26:00 -0700 | [diff] [blame] | 11468 | snprintf(buf, sizeof(buf), "iwpriv %s shortgi 9", intf); |
Kiran Kumar Lokere | f6592d7 | 2019-01-16 18:44:00 -0800 | [diff] [blame] | 11469 | fix_rate_sgi = 1; |
Amarnath Hullur Subramanyam | 42c25a0 | 2018-01-31 04:02:27 -0800 | [diff] [blame] | 11470 | } else if (strcmp(val, "1.6") == 0) { |
Kiran Kumar Lokere | b8fec52 | 2018-05-01 14:26:00 -0700 | [diff] [blame] | 11471 | snprintf(buf, sizeof(buf), "iwpriv %s shortgi 10", |
| 11472 | intf); |
Kiran Kumar Lokere | f6592d7 | 2019-01-16 18:44:00 -0800 | [diff] [blame] | 11473 | fix_rate_sgi = 2; |
Amarnath Hullur Subramanyam | 42c25a0 | 2018-01-31 04:02:27 -0800 | [diff] [blame] | 11474 | } else if (strcmp(val, "3.2") == 0) { |
Kiran Kumar Lokere | b8fec52 | 2018-05-01 14:26:00 -0700 | [diff] [blame] | 11475 | snprintf(buf, sizeof(buf), "iwpriv %s shortgi 11", |
| 11476 | intf); |
Kiran Kumar Lokere | f6592d7 | 2019-01-16 18:44:00 -0800 | [diff] [blame] | 11477 | fix_rate_sgi = 3; |
Amarnath Hullur Subramanyam | 42c25a0 | 2018-01-31 04:02:27 -0800 | [diff] [blame] | 11478 | } else { |
| 11479 | send_resp(dut, conn, SIGMA_ERROR, |
| 11480 | "errorCode,GI value not supported"); |
| 11481 | return 0; |
| 11482 | } |
| 11483 | if (system(buf) != 0) { |
| 11484 | send_resp(dut, conn, SIGMA_ERROR, |
| 11485 | "errorCode,Failed to set shortgi"); |
| 11486 | return 0; |
| 11487 | } |
Kiran Kumar Lokere | f6592d7 | 2019-01-16 18:44:00 -0800 | [diff] [blame] | 11488 | snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d", |
| 11489 | intf, fix_rate_sgi); |
| 11490 | if (system(buf) != 0) { |
| 11491 | send_resp(dut, conn, SIGMA_ERROR, |
| 11492 | "errorCode,Failed to set fix rate shortgi"); |
| 11493 | return STATUS_SENT; |
| 11494 | } |
Amarnath Hullur Subramanyam | 42c25a0 | 2018-01-31 04:02:27 -0800 | [diff] [blame] | 11495 | } |
| 11496 | |
Subhani Shaik | 8e7a305 | 2018-04-24 14:03:00 -0700 | [diff] [blame] | 11497 | val = get_param(cmd, "LTF"); |
| 11498 | if (val) { |
| 11499 | #ifdef NL80211_SUPPORT |
| 11500 | if (strcmp(val, "3.2") == 0) { |
| 11501 | sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_1X); |
| 11502 | } if (strcmp(val, "6.4") == 0) { |
| 11503 | sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_2X); |
| 11504 | } else if (strcmp(val, "12.8") == 0) { |
| 11505 | sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_4X); |
| 11506 | } else { |
| 11507 | send_resp(dut, conn, SIGMA_ERROR, |
| 11508 | "errorCode, LTF value not supported"); |
| 11509 | return 0; |
| 11510 | } |
| 11511 | #else /* NL80211_SUPPORT */ |
| 11512 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 11513 | "LTF cannot be set without NL80211_SUPPORT defined"); |
| 11514 | return -2; |
| 11515 | #endif /* NL80211_SUPPORT */ |
| 11516 | } |
| 11517 | |
Kiran Kumar Lokere | 400d68f | 2018-08-29 18:45:11 -0700 | [diff] [blame] | 11518 | val = get_param(cmd, "TxSUPPDU"); |
| 11519 | if (val) { |
| 11520 | int set_val = 1; |
| 11521 | |
| 11522 | if (strcasecmp(val, "Enable") == 0) |
| 11523 | set_val = 1; |
| 11524 | else if (strcasecmp(val, "Disable") == 0) |
| 11525 | set_val = 0; |
| 11526 | |
| 11527 | if (sta_set_tx_su_ppdu_cfg(dut, intf, set_val)) { |
| 11528 | send_resp(dut, conn, SIGMA_ERROR, |
| 11529 | "ErrorCode,Failed to set Tx SU PPDU config"); |
| 11530 | return 0; |
| 11531 | } |
| 11532 | } |
| 11533 | |
Arif Hussain | 480d5f4 | 2019-03-12 14:40:42 -0700 | [diff] [blame] | 11534 | val = get_param(cmd, "TWT_Setup"); |
| 11535 | if (val) { |
| 11536 | if (strcasecmp(val, "Request") == 0) { |
| 11537 | if (sta_twt_request(dut, conn, cmd)) { |
| 11538 | send_resp(dut, conn, SIGMA_ERROR, |
| 11539 | "ErrorCode,sta_twt_request failed"); |
| 11540 | return STATUS_SENT; |
| 11541 | } |
| 11542 | } else if (strcasecmp(val, "Teardown") == 0) { |
| 11543 | if (sta_twt_teardown(dut, conn, cmd)) { |
| 11544 | send_resp(dut, conn, SIGMA_ERROR, |
| 11545 | "ErrorCode,sta_twt_teardown failed"); |
| 11546 | return STATUS_SENT; |
| 11547 | } |
| 11548 | } |
| 11549 | } |
| 11550 | |
Kiran Kumar Lokere | 50eb2cd | 2018-12-18 18:31:28 -0800 | [diff] [blame] | 11551 | val = get_param(cmd, "transmitOMI"); |
| 11552 | if (val && sta_transmit_omi(dut, conn, cmd)) { |
| 11553 | send_resp(dut, conn, SIGMA_ERROR, |
| 11554 | "ErrorCode,sta_transmit_omi failed"); |
| 11555 | return STATUS_SENT; |
Kiran Kumar Lokere | 29c1bb0 | 2018-10-08 17:41:02 -0700 | [diff] [blame] | 11556 | } |
| 11557 | |
Kiran Kumar Lokere | c310dcd | 2018-12-17 20:56:06 -0800 | [diff] [blame] | 11558 | val = get_param(cmd, "Powersave"); |
| 11559 | if (val) { |
| 11560 | char buf[60]; |
| 11561 | |
| 11562 | if (strcasecmp(val, "off") == 0) { |
| 11563 | snprintf(buf, sizeof(buf), |
| 11564 | "iwpriv %s setPower 2", intf); |
| 11565 | if (system(buf) != 0) { |
| 11566 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 11567 | "iwpriv setPower 2 failed"); |
| 11568 | return 0; |
| 11569 | } |
| 11570 | } else if (strcasecmp(val, "on") == 0) { |
| 11571 | snprintf(buf, sizeof(buf), |
| 11572 | "iwpriv %s setPower 1", intf); |
| 11573 | if (system(buf) != 0) { |
| 11574 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 11575 | "iwpriv setPower 1 failed"); |
| 11576 | return 0; |
| 11577 | } |
| 11578 | } else { |
| 11579 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 11580 | "Unsupported Powersave value '%s'", |
| 11581 | val); |
| 11582 | return -1; |
| 11583 | } |
| 11584 | } |
| 11585 | |
Kiran Kumar Lokere | 2c4b7ce | 2019-01-30 12:02:28 -0800 | [diff] [blame] | 11586 | val = get_param(cmd, "MU_EDCA"); |
| 11587 | if (val) { |
| 11588 | if (strcasecmp(val, "Override") == 0) { |
| 11589 | if (sta_set_mu_edca_override(dut, intf, 1)) { |
| 11590 | send_resp(dut, conn, SIGMA_ERROR, |
| 11591 | "errorCode,MU EDCA override set failed"); |
| 11592 | return STATUS_SENT; |
| 11593 | } |
| 11594 | } else if (strcasecmp(val, "Disable") == 0) { |
| 11595 | if (sta_set_mu_edca_override(dut, intf, 0)) { |
| 11596 | send_resp(dut, conn, SIGMA_ERROR, |
| 11597 | "errorCode,MU EDCA override disable failed"); |
| 11598 | return STATUS_SENT; |
| 11599 | } |
| 11600 | } |
| 11601 | } |
| 11602 | |
Amarnath Hullur Subramanyam | 42c25a0 | 2018-01-31 04:02:27 -0800 | [diff] [blame] | 11603 | return 1; |
| 11604 | |
| 11605 | failed: |
| 11606 | free(token); |
| 11607 | return -2; |
| 11608 | } |
| 11609 | |
| 11610 | |
| 11611 | static int cmd_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut, |
| 11612 | struct sigma_conn *conn, |
| 11613 | struct sigma_cmd *cmd) |
| 11614 | { |
| 11615 | switch (get_driver_type()) { |
| 11616 | case DRIVER_WCN: |
| 11617 | return wcn_sta_set_rfeature_he(intf, dut, conn, cmd); |
| 11618 | default: |
| 11619 | send_resp(dut, conn, SIGMA_ERROR, |
| 11620 | "errorCode,Unsupported sta_set_rfeature(HE) with the current driver"); |
| 11621 | return 0; |
| 11622 | } |
| 11623 | } |
| 11624 | |
| 11625 | |
Kiran Kumar Lokere | e580c01 | 2019-01-03 17:08:53 -0800 | [diff] [blame] | 11626 | static int cmd_sta_set_power_save_he(const char *intf, struct sigma_dut *dut, |
| 11627 | struct sigma_conn *conn, |
| 11628 | struct sigma_cmd *cmd) |
| 11629 | { |
| 11630 | const char *val; |
| 11631 | |
| 11632 | val = get_param(cmd, "powersave"); |
| 11633 | if (val) { |
| 11634 | char buf[60]; |
| 11635 | |
| 11636 | if (strcasecmp(val, "off") == 0) { |
| 11637 | snprintf(buf, sizeof(buf), "iwpriv %s setPower 2", |
| 11638 | intf); |
| 11639 | if (system(buf) != 0) { |
| 11640 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 11641 | "iwpriv setPower 2 failed"); |
| 11642 | return 0; |
| 11643 | } |
| 11644 | } else if (strcasecmp(val, "on") == 0) { |
| 11645 | snprintf(buf, sizeof(buf), "iwpriv %s setPower 1", |
| 11646 | intf); |
| 11647 | if (system(buf) != 0) { |
| 11648 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 11649 | "iwpriv setPower 1 failed"); |
| 11650 | return 0; |
| 11651 | } |
| 11652 | } else { |
| 11653 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 11654 | "Unsupported power save config"); |
| 11655 | return -1; |
| 11656 | } |
| 11657 | return 1; |
| 11658 | } |
| 11659 | |
| 11660 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported command"); |
| 11661 | |
| 11662 | return 0; |
| 11663 | } |
| 11664 | |
| 11665 | |
Ashwini Patil | 5acd738 | 2017-04-13 15:55:04 +0530 | [diff] [blame] | 11666 | static int btm_query_candidate_list(struct sigma_dut *dut, |
| 11667 | struct sigma_conn *conn, |
| 11668 | struct sigma_cmd *cmd) |
| 11669 | { |
| 11670 | const char *bssid, *info, *op_class, *ch, *phy_type, *pref; |
| 11671 | int len, ret; |
| 11672 | char buf[10]; |
| 11673 | |
| 11674 | /* |
| 11675 | * Neighbor Report elements format: |
| 11676 | * neighbor=<BSSID>,<BSSID Information>,<Operating Class>, |
| 11677 | * <Channel Number>,<PHY Type>[,<hexdump of Optional Subelements>] |
| 11678 | * eg: neighbor=aa:bb:cc:dd:ee:ff,17,81,6,1,030101 |
| 11679 | */ |
| 11680 | |
| 11681 | bssid = get_param(cmd, "Nebor_BSSID"); |
| 11682 | if (!bssid) { |
| 11683 | send_resp(dut, conn, SIGMA_INVALID, |
| 11684 | "errorCode,Nebor_BSSID is missing"); |
| 11685 | return 0; |
| 11686 | } |
| 11687 | |
| 11688 | info = get_param(cmd, "Nebor_Bssid_Info"); |
| 11689 | if (!info) { |
| 11690 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 11691 | "Using default value for Nebor_Bssid_Info: %s", |
| 11692 | DEFAULT_NEIGHBOR_BSSID_INFO); |
| 11693 | info = DEFAULT_NEIGHBOR_BSSID_INFO; |
| 11694 | } |
| 11695 | |
| 11696 | op_class = get_param(cmd, "Nebor_Op_Class"); |
| 11697 | if (!op_class) { |
| 11698 | send_resp(dut, conn, SIGMA_INVALID, |
| 11699 | "errorCode,Nebor_Op_Class is missing"); |
| 11700 | return 0; |
| 11701 | } |
| 11702 | |
| 11703 | ch = get_param(cmd, "Nebor_Op_Ch"); |
| 11704 | if (!ch) { |
| 11705 | send_resp(dut, conn, SIGMA_INVALID, |
| 11706 | "errorCode,Nebor_Op_Ch is missing"); |
| 11707 | return 0; |
| 11708 | } |
| 11709 | |
| 11710 | phy_type = get_param(cmd, "Nebor_Phy_Type"); |
| 11711 | if (!phy_type) { |
| 11712 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 11713 | "Using default value for Nebor_Phy_Type: %s", |
| 11714 | DEFAULT_NEIGHBOR_PHY_TYPE); |
| 11715 | phy_type = DEFAULT_NEIGHBOR_PHY_TYPE; |
| 11716 | } |
| 11717 | |
| 11718 | /* Parse optional subelements */ |
| 11719 | buf[0] = '\0'; |
| 11720 | pref = get_param(cmd, "Nebor_Pref"); |
| 11721 | if (pref) { |
| 11722 | /* hexdump for preferrence subelement */ |
| 11723 | ret = snprintf(buf, sizeof(buf), ",0301%02x", atoi(pref)); |
| 11724 | if (ret < 0 || ret >= (int) sizeof(buf)) { |
| 11725 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 11726 | "snprintf failed for optional subelement ret: %d", |
| 11727 | ret); |
| 11728 | send_resp(dut, conn, SIGMA_ERROR, |
| 11729 | "errorCode,snprintf failed for subelement"); |
| 11730 | return 0; |
| 11731 | } |
| 11732 | } |
| 11733 | |
| 11734 | if (!dut->btm_query_cand_list) { |
| 11735 | dut->btm_query_cand_list = calloc(1, NEIGHBOR_REPORT_SIZE); |
| 11736 | if (!dut->btm_query_cand_list) { |
| 11737 | send_resp(dut, conn, SIGMA_ERROR, |
| 11738 | "errorCode,Failed to allocate memory for btm_query_cand_list"); |
| 11739 | return 0; |
| 11740 | } |
| 11741 | } |
| 11742 | |
| 11743 | len = strlen(dut->btm_query_cand_list); |
| 11744 | ret = snprintf(dut->btm_query_cand_list + len, |
| 11745 | NEIGHBOR_REPORT_SIZE - len, " neighbor=%s,%s,%s,%s,%s%s", |
| 11746 | bssid, info, op_class, ch, phy_type, buf); |
| 11747 | if (ret < 0 || ret >= NEIGHBOR_REPORT_SIZE - len) { |
| 11748 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 11749 | "snprintf failed for neighbor report list ret: %d", |
| 11750 | ret); |
| 11751 | send_resp(dut, conn, SIGMA_ERROR, |
| 11752 | "errorCode,snprintf failed for neighbor report"); |
| 11753 | free(dut->btm_query_cand_list); |
| 11754 | dut->btm_query_cand_list = NULL; |
| 11755 | return 0; |
| 11756 | } |
| 11757 | |
| 11758 | return 1; |
| 11759 | } |
| 11760 | |
| 11761 | |
Alexei Avshalom Lazar | bc180dc | 2018-12-18 16:01:14 +0200 | [diff] [blame] | 11762 | int sta_extract_60g_ese(struct sigma_dut *dut, struct sigma_cmd *cmd, |
| 11763 | struct sigma_ese_alloc *allocs, int *allocs_size) |
| 11764 | { |
| 11765 | int max_count = *allocs_size; |
| 11766 | int count = 0, i; |
| 11767 | const char *val; |
| 11768 | |
| 11769 | do { |
| 11770 | val = get_param_indexed(cmd, "AllocID", count); |
| 11771 | if (val) |
| 11772 | count++; |
| 11773 | } while (val); |
| 11774 | |
| 11775 | if (count == 0 || count > max_count) { |
| 11776 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 11777 | "Invalid number of allocations(%d)", count); |
| 11778 | return -1; |
| 11779 | } |
| 11780 | |
| 11781 | for (i = 0; i < count; i++) { |
| 11782 | val = get_param_indexed(cmd, "PercentBI", i); |
| 11783 | if (!val) { |
| 11784 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 11785 | "Missing PercentBI parameter at index %d", |
| 11786 | i); |
| 11787 | return -1; |
| 11788 | } |
| 11789 | allocs[i].percent_bi = atoi(val); |
| 11790 | |
| 11791 | val = get_param_indexed(cmd, "SrcAID", i); |
| 11792 | if (val) |
| 11793 | allocs[i].src_aid = strtol(val, NULL, 0); |
| 11794 | else |
| 11795 | allocs[i].src_aid = ESE_BCAST_AID; |
| 11796 | |
| 11797 | val = get_param_indexed(cmd, "DestAID", i); |
| 11798 | if (val) |
| 11799 | allocs[i].dst_aid = strtol(val, NULL, 0); |
| 11800 | else |
| 11801 | allocs[i].dst_aid = ESE_BCAST_AID; |
| 11802 | |
| 11803 | allocs[i].type = ESE_CBAP; |
| 11804 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 11805 | "Alloc %d PercentBI %d SrcAID %d DstAID %d", |
| 11806 | i, allocs[i].percent_bi, allocs[i].src_aid, |
| 11807 | allocs[i].dst_aid); |
| 11808 | } |
| 11809 | |
| 11810 | *allocs_size = count; |
| 11811 | return 0; |
| 11812 | } |
| 11813 | |
| 11814 | |
| 11815 | static int sta_set_60g_ese(struct sigma_dut *dut, int count, |
| 11816 | struct sigma_ese_alloc *allocs) |
| 11817 | { |
| 11818 | switch (get_driver_type()) { |
| 11819 | #ifdef __linux__ |
| 11820 | case DRIVER_WIL6210: |
| 11821 | if (wil6210_set_ese(dut, count, allocs)) |
| 11822 | return -1; |
| 11823 | return 1; |
| 11824 | #endif /* __linux__ */ |
| 11825 | default: |
| 11826 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 11827 | "Unsupported sta_set_60g_ese with the current driver"); |
| 11828 | return -1; |
| 11829 | } |
| 11830 | } |
| 11831 | |
| 11832 | |
| 11833 | static int cmd_sta_set_rfeature_60g(const char *intf, struct sigma_dut *dut, |
| 11834 | struct sigma_conn *conn, |
| 11835 | struct sigma_cmd *cmd) |
| 11836 | { |
| 11837 | const char *val; |
| 11838 | |
| 11839 | val = get_param(cmd, "ExtSchIE"); |
| 11840 | if (val && !strcasecmp(val, "Enable")) { |
| 11841 | struct sigma_ese_alloc allocs[MAX_ESE_ALLOCS]; |
| 11842 | int count = MAX_ESE_ALLOCS; |
| 11843 | |
| 11844 | if (sta_extract_60g_ese(dut, cmd, allocs, &count)) |
| 11845 | return -1; |
| 11846 | return sta_set_60g_ese(dut, count, allocs); |
| 11847 | } |
| 11848 | |
Alexei Avshalom Lazar | aad97b0 | 2018-12-18 16:01:23 +0200 | [diff] [blame] | 11849 | val = get_param(cmd, "MCS_FixedRate"); |
| 11850 | if (val) { |
| 11851 | int sta_mcs = atoi(val); |
| 11852 | |
| 11853 | sigma_dut_print(dut, DUT_MSG_INFO, "Force STA MCS to %d", |
| 11854 | sta_mcs); |
| 11855 | wil6210_set_force_mcs(dut, 1, sta_mcs); |
| 11856 | |
Jouni Malinen | 0e29cf2 | 2019-02-19 01:13:21 +0200 | [diff] [blame] | 11857 | return SUCCESS_SEND_STATUS; |
Alexei Avshalom Lazar | aad97b0 | 2018-12-18 16:01:23 +0200 | [diff] [blame] | 11858 | } |
| 11859 | |
Alexei Avshalom Lazar | bc180dc | 2018-12-18 16:01:14 +0200 | [diff] [blame] | 11860 | send_resp(dut, conn, SIGMA_ERROR, |
| 11861 | "errorCode,Invalid sta_set_rfeature(60G)"); |
Jouni Malinen | 0e29cf2 | 2019-02-19 01:13:21 +0200 | [diff] [blame] | 11862 | return STATUS_SENT; |
Alexei Avshalom Lazar | bc180dc | 2018-12-18 16:01:14 +0200 | [diff] [blame] | 11863 | } |
| 11864 | |
| 11865 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 11866 | static enum sigma_cmd_result cmd_sta_set_rfeature(struct sigma_dut *dut, |
| 11867 | struct sigma_conn *conn, |
| 11868 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 11869 | { |
| 11870 | const char *intf = get_param(cmd, "Interface"); |
| 11871 | const char *prog = get_param(cmd, "Prog"); |
Ashwini Patil | 68d02cd | 2017-01-10 15:39:16 +0530 | [diff] [blame] | 11872 | const char *val; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 11873 | |
| 11874 | if (intf == NULL || prog == NULL) |
| 11875 | return -1; |
| 11876 | |
Ashwini Patil | 5acd738 | 2017-04-13 15:55:04 +0530 | [diff] [blame] | 11877 | /* BSS Transition candidate list for BTM query */ |
| 11878 | val = get_param(cmd, "Nebor_BSSID"); |
| 11879 | if (val && btm_query_candidate_list(dut, conn, cmd) == 0) |
| 11880 | return 0; |
| 11881 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 11882 | if (strcasecmp(prog, "TDLS") == 0) |
| 11883 | return cmd_sta_set_rfeature_tdls(intf, dut, conn, cmd); |
| 11884 | |
| 11885 | if (strcasecmp(prog, "VHT") == 0) |
| 11886 | return cmd_sta_set_rfeature_vht(intf, dut, conn, cmd); |
| 11887 | |
Amarnath Hullur Subramanyam | 42c25a0 | 2018-01-31 04:02:27 -0800 | [diff] [blame] | 11888 | if (strcasecmp(prog, "HE") == 0) |
| 11889 | return cmd_sta_set_rfeature_he(intf, dut, conn, cmd); |
| 11890 | |
Ashwini Patil | 68d02cd | 2017-01-10 15:39:16 +0530 | [diff] [blame] | 11891 | if (strcasecmp(prog, "MBO") == 0) { |
| 11892 | val = get_param(cmd, "Cellular_Data_Cap"); |
| 11893 | if (val && |
| 11894 | mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0) |
| 11895 | return 0; |
Ashwini Patil | 0040258 | 2017-04-13 12:29:39 +0530 | [diff] [blame] | 11896 | |
| 11897 | val = get_param(cmd, "Ch_Pref"); |
| 11898 | if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0) |
| 11899 | return 0; |
| 11900 | |
Ashwini Patil | 68d02cd | 2017-01-10 15:39:16 +0530 | [diff] [blame] | 11901 | return 1; |
| 11902 | } |
| 11903 | |
Alexei Avshalom Lazar | bc180dc | 2018-12-18 16:01:14 +0200 | [diff] [blame] | 11904 | if (strcasecmp(prog, "60GHz") == 0) |
| 11905 | return cmd_sta_set_rfeature_60g(intf, dut, conn, cmd); |
| 11906 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 11907 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported Prog"); |
| 11908 | return 0; |
| 11909 | } |
| 11910 | |
| 11911 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 11912 | static enum sigma_cmd_result cmd_sta_set_radio(struct sigma_dut *dut, |
| 11913 | struct sigma_conn *conn, |
| 11914 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 11915 | { |
| 11916 | const char *intf = get_param(cmd, "Interface"); |
| 11917 | const char *mode = get_param(cmd, "Mode"); |
| 11918 | int res; |
| 11919 | |
| 11920 | if (intf == NULL || mode == NULL) |
| 11921 | return -1; |
| 11922 | |
| 11923 | if (strcasecmp(mode, "On") == 0) |
| 11924 | res = wpa_command(intf, "SET radio_disabled 0"); |
| 11925 | else if (strcasecmp(mode, "Off") == 0) |
| 11926 | res = wpa_command(intf, "SET radio_disabled 1"); |
| 11927 | else |
| 11928 | return -1; |
| 11929 | |
| 11930 | if (res) { |
| 11931 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change " |
| 11932 | "radio mode"); |
| 11933 | return 0; |
| 11934 | } |
| 11935 | |
| 11936 | return 1; |
| 11937 | } |
| 11938 | |
| 11939 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 11940 | static enum sigma_cmd_result cmd_sta_set_pwrsave(struct sigma_dut *dut, |
| 11941 | struct sigma_conn *conn, |
| 11942 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 11943 | { |
| 11944 | const char *intf = get_param(cmd, "Interface"); |
| 11945 | const char *mode = get_param(cmd, "Mode"); |
Alexei Avshalom Lazar | e49e387 | 2018-12-23 17:26:57 +0200 | [diff] [blame] | 11946 | const char *prog = get_param(cmd, "program"); |
| 11947 | const char *powersave = get_param(cmd, "powersave"); |
| 11948 | int res = 0; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 11949 | |
Alexei Avshalom Lazar | e49e387 | 2018-12-23 17:26:57 +0200 | [diff] [blame] | 11950 | if (intf == NULL) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 11951 | return -1; |
| 11952 | |
Alexei Avshalom Lazar | e49e387 | 2018-12-23 17:26:57 +0200 | [diff] [blame] | 11953 | if (prog && strcasecmp(prog, "60GHz") == 0) { |
| 11954 | /* |
| 11955 | * The CAPI mode parameter does not exist in 60G |
| 11956 | * unscheduled PS. |
| 11957 | */ |
Hu Wang | 5dc3ff1 | 2019-06-14 15:14:26 +0800 | [diff] [blame] | 11958 | if (powersave && strcasecmp(powersave, "unscheduled") == 0) |
Alexei Avshalom Lazar | e49e387 | 2018-12-23 17:26:57 +0200 | [diff] [blame] | 11959 | res = set_ps(intf, dut, 1); |
Alexei Avshalom Lazar | 2f6fdb4 | 2019-02-04 14:16:08 +0200 | [diff] [blame] | 11960 | } else if (prog && get_driver_type() == DRIVER_WCN && |
| 11961 | strcasecmp(prog, "HE") == 0) { |
| 11962 | return cmd_sta_set_power_save_he(intf, dut, conn, cmd); |
Alexei Avshalom Lazar | e49e387 | 2018-12-23 17:26:57 +0200 | [diff] [blame] | 11963 | } else { |
| 11964 | if (mode == NULL) |
| 11965 | return -1; |
| 11966 | |
| 11967 | if (strcasecmp(mode, "On") == 0) |
| 11968 | res = set_ps(intf, dut, 1); |
| 11969 | else if (strcasecmp(mode, "Off") == 0) |
| 11970 | res = set_ps(intf, dut, 0); |
| 11971 | else |
| 11972 | return -1; |
| 11973 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 11974 | |
| 11975 | if (res) { |
| 11976 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change " |
| 11977 | "power save mode"); |
| 11978 | return 0; |
| 11979 | } |
| 11980 | |
| 11981 | return 1; |
| 11982 | } |
| 11983 | |
| 11984 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 11985 | static enum sigma_cmd_result cmd_sta_bssid_pool(struct sigma_dut *dut, |
| 11986 | struct sigma_conn *conn, |
| 11987 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 11988 | { |
| 11989 | const char *intf = get_param(cmd, "Interface"); |
| 11990 | const char *val, *bssid; |
| 11991 | int res; |
| 11992 | char *buf; |
| 11993 | size_t buf_len; |
| 11994 | |
| 11995 | val = get_param(cmd, "BSSID_FILTER"); |
| 11996 | if (val == NULL) |
| 11997 | return -1; |
| 11998 | |
| 11999 | bssid = get_param(cmd, "BSSID_List"); |
| 12000 | if (atoi(val) == 0 || bssid == NULL) { |
| 12001 | /* Disable BSSID filter */ |
| 12002 | if (wpa_command(intf, "SET bssid_filter ")) { |
| 12003 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed " |
| 12004 | "to disable BSSID filter"); |
| 12005 | return 0; |
| 12006 | } |
| 12007 | |
| 12008 | return 1; |
| 12009 | } |
| 12010 | |
| 12011 | buf_len = 100 + strlen(bssid); |
| 12012 | buf = malloc(buf_len); |
| 12013 | if (buf == NULL) |
| 12014 | return -1; |
| 12015 | |
| 12016 | snprintf(buf, buf_len, "SET bssid_filter %s", bssid); |
| 12017 | res = wpa_command(intf, buf); |
| 12018 | free(buf); |
| 12019 | if (res) { |
| 12020 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to enable " |
| 12021 | "BSSID filter"); |
| 12022 | return 0; |
| 12023 | } |
| 12024 | |
| 12025 | return 1; |
| 12026 | } |
| 12027 | |
| 12028 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 12029 | static enum sigma_cmd_result cmd_sta_reset_parm(struct sigma_dut *dut, |
| 12030 | struct sigma_conn *conn, |
| 12031 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 12032 | { |
| 12033 | const char *intf = get_param(cmd, "Interface"); |
| 12034 | const char *val; |
| 12035 | |
| 12036 | /* TODO: ARP */ |
| 12037 | |
| 12038 | val = get_param(cmd, "HS2_CACHE_PROFILE"); |
| 12039 | if (val && strcasecmp(val, "All") == 0) |
| 12040 | hs2_clear_credentials(intf); |
| 12041 | |
| 12042 | return 1; |
| 12043 | } |
| 12044 | |
| 12045 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 12046 | static enum sigma_cmd_result cmd_sta_get_key(struct sigma_dut *dut, |
| 12047 | struct sigma_conn *conn, |
| 12048 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 12049 | { |
| 12050 | const char *intf = get_param(cmd, "Interface"); |
| 12051 | const char *key_type = get_param(cmd, "KeyType"); |
| 12052 | char buf[100], resp[200]; |
| 12053 | |
| 12054 | if (key_type == NULL) |
| 12055 | return -1; |
| 12056 | |
| 12057 | if (strcasecmp(key_type, "GTK") == 0) { |
| 12058 | if (wpa_command_resp(intf, "GET gtk", buf, sizeof(buf)) < 0 || |
| 12059 | strncmp(buf, "FAIL", 4) == 0) { |
| 12060 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could " |
| 12061 | "not fetch current GTK"); |
| 12062 | return 0; |
| 12063 | } |
| 12064 | snprintf(resp, sizeof(resp), "KeyValue,%s", buf); |
| 12065 | send_resp(dut, conn, SIGMA_COMPLETE, resp); |
| 12066 | return 0; |
| 12067 | } else { |
| 12068 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported " |
| 12069 | "KeyType"); |
| 12070 | return 0; |
| 12071 | } |
| 12072 | |
| 12073 | return 1; |
| 12074 | } |
| 12075 | |
| 12076 | |
| 12077 | static int hs2_set_policy(struct sigma_dut *dut) |
| 12078 | { |
| 12079 | #ifdef ANDROID |
| 12080 | system("ip rule del prio 23000"); |
| 12081 | if (system("ip rule add from all lookup main prio 23000") != 0) { |
| 12082 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 12083 | "Failed to run:ip rule add from all lookup main prio"); |
| 12084 | return -1; |
| 12085 | } |
| 12086 | if (system("ip route flush cache") != 0) { |
| 12087 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 12088 | "Failed to run ip route flush cache"); |
| 12089 | return -1; |
| 12090 | } |
| 12091 | return 1; |
| 12092 | #else /* ANDROID */ |
| 12093 | return 0; |
| 12094 | #endif /* ANDROID */ |
| 12095 | } |
| 12096 | |
| 12097 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 12098 | static enum sigma_cmd_result cmd_sta_hs2_associate(struct sigma_dut *dut, |
| 12099 | struct sigma_conn *conn, |
| 12100 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 12101 | { |
| 12102 | const char *intf = get_param(cmd, "Interface"); |
| 12103 | const char *val = get_param(cmd, "Ignore_blacklist"); |
Jouni Malinen | 439352d | 2018-09-13 03:42:23 +0300 | [diff] [blame] | 12104 | const char *band = get_param(cmd, "Band"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 12105 | struct wpa_ctrl *ctrl; |
Jouni Malinen | 3aa7286 | 2019-05-29 23:14:51 +0300 | [diff] [blame] | 12106 | int res, r; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 12107 | char bssid[20], ssid[40], resp[100], buf[100], blacklisted[100]; |
| 12108 | int tries = 0; |
| 12109 | int ignore_blacklist = 0; |
| 12110 | const char *events[] = { |
| 12111 | "CTRL-EVENT-CONNECTED", |
| 12112 | "INTERWORKING-BLACKLISTED", |
| 12113 | "INTERWORKING-NO-MATCH", |
| 12114 | NULL |
| 12115 | }; |
| 12116 | |
| 12117 | start_sta_mode(dut); |
| 12118 | |
Jouni Malinen | 439352d | 2018-09-13 03:42:23 +0300 | [diff] [blame] | 12119 | if (band) { |
| 12120 | if (strcmp(band, "2.4") == 0) { |
| 12121 | wpa_command(intf, "SET setband 2G"); |
| 12122 | } else if (strcmp(band, "5") == 0) { |
| 12123 | wpa_command(intf, "SET setband 5G"); |
| 12124 | } else { |
| 12125 | send_resp(dut, conn, SIGMA_ERROR, |
| 12126 | "errorCode,Unsupported band"); |
| 12127 | return 0; |
| 12128 | } |
| 12129 | } |
| 12130 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 12131 | blacklisted[0] = '\0'; |
| 12132 | if (val && atoi(val)) |
| 12133 | ignore_blacklist = 1; |
| 12134 | |
| 12135 | try_again: |
| 12136 | ctrl = open_wpa_mon(intf); |
| 12137 | if (ctrl == NULL) { |
| 12138 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open " |
| 12139 | "wpa_supplicant monitor connection"); |
| 12140 | return -2; |
| 12141 | } |
| 12142 | |
| 12143 | tries++; |
| 12144 | if (wpa_command(intf, "INTERWORKING_SELECT auto")) { |
| 12145 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start " |
| 12146 | "Interworking connection"); |
| 12147 | wpa_ctrl_detach(ctrl); |
| 12148 | wpa_ctrl_close(ctrl); |
| 12149 | return 0; |
| 12150 | } |
| 12151 | |
| 12152 | buf[0] = '\0'; |
| 12153 | while (1) { |
| 12154 | char *pos; |
| 12155 | res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf)); |
| 12156 | pos = strstr(buf, "INTERWORKING-BLACKLISTED"); |
| 12157 | if (!pos) |
| 12158 | break; |
| 12159 | pos += 25; |
| 12160 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Found blacklisted AP: %s", |
| 12161 | pos); |
| 12162 | if (!blacklisted[0]) |
| 12163 | memcpy(blacklisted, pos, strlen(pos) + 1); |
| 12164 | } |
| 12165 | |
| 12166 | if (ignore_blacklist && blacklisted[0]) { |
| 12167 | char *end; |
| 12168 | end = strchr(blacklisted, ' '); |
| 12169 | if (end) |
| 12170 | *end = '\0'; |
| 12171 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Try to connect to a blacklisted network: %s", |
| 12172 | blacklisted); |
Jouni Malinen | 3aa7286 | 2019-05-29 23:14:51 +0300 | [diff] [blame] | 12173 | r = snprintf(buf, sizeof(buf), "INTERWORKING_CONNECT %s", |
| 12174 | blacklisted); |
| 12175 | if (r < 0 || r >= sizeof(buf) || wpa_command(intf, buf)) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 12176 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start Interworking connection to blacklisted network"); |
| 12177 | wpa_ctrl_detach(ctrl); |
| 12178 | wpa_ctrl_close(ctrl); |
| 12179 | return 0; |
| 12180 | } |
| 12181 | res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED", |
| 12182 | buf, sizeof(buf)); |
| 12183 | } |
| 12184 | |
| 12185 | wpa_ctrl_detach(ctrl); |
| 12186 | wpa_ctrl_close(ctrl); |
| 12187 | |
| 12188 | if (res < 0) { |
| 12189 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not " |
| 12190 | "connect"); |
| 12191 | return 0; |
| 12192 | } |
| 12193 | |
| 12194 | if (strstr(buf, "INTERWORKING-NO-MATCH") || |
| 12195 | strstr(buf, "INTERWORKING-BLACKLISTED")) { |
| 12196 | if (tries < 2) { |
| 12197 | sigma_dut_print(dut, DUT_MSG_INFO, "No match found - try again to verify no APs were missed in the scan"); |
| 12198 | goto try_again; |
| 12199 | } |
| 12200 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,No network with " |
| 12201 | "matching credentials found"); |
| 12202 | return 0; |
| 12203 | } |
| 12204 | |
| 12205 | if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 || |
| 12206 | get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) { |
| 12207 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not " |
| 12208 | "get current BSSID/SSID"); |
| 12209 | return 0; |
| 12210 | } |
| 12211 | |
| 12212 | snprintf(resp, sizeof(resp), "SSID,%s,BSSID,%s", ssid, bssid); |
| 12213 | send_resp(dut, conn, SIGMA_COMPLETE, resp); |
| 12214 | hs2_set_policy(dut); |
| 12215 | return 0; |
| 12216 | } |
| 12217 | |
| 12218 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 12219 | static enum sigma_cmd_result cmd_sta_hs2_venue_info(struct sigma_dut *dut, |
| 12220 | struct sigma_conn *conn, |
| 12221 | struct sigma_cmd *cmd) |
Jouni Malinen | b639f1c | 2018-09-13 02:39:46 +0300 | [diff] [blame] | 12222 | { |
| 12223 | const char *intf = get_param(cmd, "Interface"); |
| 12224 | const char *display = get_param(cmd, "Display"); |
| 12225 | struct wpa_ctrl *ctrl; |
| 12226 | char buf[300], params[400], *pos; |
| 12227 | char bssid[20]; |
| 12228 | int info_avail = 0; |
| 12229 | unsigned int old_timeout; |
| 12230 | int res; |
| 12231 | |
| 12232 | if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) { |
| 12233 | send_resp(dut, conn, SIGMA_ERROR, |
| 12234 | "ErrorCode,Could not get current BSSID"); |
| 12235 | return 0; |
| 12236 | } |
| 12237 | ctrl = open_wpa_mon(intf); |
| 12238 | if (!ctrl) { |
| 12239 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 12240 | "Failed to open wpa_supplicant monitor connection"); |
| 12241 | return -2; |
| 12242 | } |
| 12243 | |
| 12244 | snprintf(buf, sizeof(buf), "ANQP_GET %s 277", bssid); |
| 12245 | wpa_command(intf, buf); |
| 12246 | |
| 12247 | res = get_wpa_cli_event(dut, ctrl, "GAS-QUERY-DONE", buf, sizeof(buf)); |
| 12248 | if (res < 0) { |
| 12249 | send_resp(dut, conn, SIGMA_ERROR, |
| 12250 | "ErrorCode,Could not complete GAS query"); |
| 12251 | goto fail; |
| 12252 | } |
| 12253 | |
| 12254 | old_timeout = dut->default_timeout; |
| 12255 | dut->default_timeout = 2; |
| 12256 | res = get_wpa_cli_event(dut, ctrl, "RX-VENUE-URL", buf, sizeof(buf)); |
| 12257 | dut->default_timeout = old_timeout; |
| 12258 | if (res < 0) |
| 12259 | goto done; |
| 12260 | pos = strchr(buf, ' '); |
| 12261 | if (!pos) |
| 12262 | goto done; |
| 12263 | pos++; |
| 12264 | pos = strchr(pos, ' '); |
| 12265 | if (!pos) |
| 12266 | goto done; |
| 12267 | pos++; |
| 12268 | info_avail = 1; |
| 12269 | snprintf(params, sizeof(params), "browser %s", pos); |
| 12270 | |
| 12271 | if (display && strcasecmp(display, "Yes") == 0) { |
| 12272 | pid_t pid; |
| 12273 | |
| 12274 | pid = fork(); |
| 12275 | if (pid < 0) { |
| 12276 | perror("fork"); |
| 12277 | return -1; |
| 12278 | } |
| 12279 | |
| 12280 | if (pid == 0) { |
| 12281 | run_hs20_osu(dut, params); |
| 12282 | exit(0); |
| 12283 | } |
| 12284 | } |
| 12285 | |
| 12286 | done: |
| 12287 | snprintf(buf, sizeof(buf), "Info_available,%s", |
| 12288 | info_avail ? "Yes" : "No"); |
| 12289 | send_resp(dut, conn, SIGMA_COMPLETE, buf); |
| 12290 | fail: |
| 12291 | wpa_ctrl_detach(ctrl); |
| 12292 | wpa_ctrl_close(ctrl); |
| 12293 | return 0; |
| 12294 | } |
| 12295 | |
| 12296 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 12297 | static int sta_add_credential_uname_pwd(struct sigma_dut *dut, |
| 12298 | struct sigma_conn *conn, |
| 12299 | const char *ifname, |
| 12300 | struct sigma_cmd *cmd) |
| 12301 | { |
| 12302 | const char *val; |
| 12303 | int id; |
| 12304 | |
| 12305 | id = add_cred(ifname); |
| 12306 | if (id < 0) |
| 12307 | return -2; |
| 12308 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id); |
| 12309 | |
| 12310 | val = get_param(cmd, "prefer"); |
| 12311 | if (val && atoi(val) > 0) |
| 12312 | set_cred(ifname, id, "priority", "1"); |
| 12313 | |
| 12314 | val = get_param(cmd, "REALM"); |
| 12315 | if (val && set_cred_quoted(ifname, id, "realm", val) < 0) { |
| 12316 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set " |
| 12317 | "realm"); |
| 12318 | return 0; |
| 12319 | } |
| 12320 | |
| 12321 | val = get_param(cmd, "HOME_FQDN"); |
| 12322 | if (val && set_cred_quoted(ifname, id, "domain", val) < 0) { |
| 12323 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set " |
| 12324 | "home_fqdn"); |
| 12325 | return 0; |
| 12326 | } |
| 12327 | |
| 12328 | val = get_param(cmd, "Username"); |
| 12329 | if (val && set_cred_quoted(ifname, id, "username", val) < 0) { |
| 12330 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set " |
| 12331 | "username"); |
| 12332 | return 0; |
| 12333 | } |
| 12334 | |
| 12335 | val = get_param(cmd, "Password"); |
| 12336 | if (val && set_cred_quoted(ifname, id, "password", val) < 0) { |
| 12337 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set " |
| 12338 | "password"); |
| 12339 | return 0; |
| 12340 | } |
| 12341 | |
| 12342 | val = get_param(cmd, "ROOT_CA"); |
| 12343 | if (val) { |
| 12344 | char fname[200]; |
| 12345 | snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val); |
| 12346 | #ifdef __linux__ |
| 12347 | if (!file_exists(fname)) { |
| 12348 | char msg[300]; |
| 12349 | snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA " |
| 12350 | "file (%s) not found", fname); |
| 12351 | send_resp(dut, conn, SIGMA_ERROR, msg); |
| 12352 | return 0; |
| 12353 | } |
| 12354 | #endif /* __linux__ */ |
| 12355 | if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) { |
| 12356 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could " |
| 12357 | "not set root CA"); |
| 12358 | return 0; |
| 12359 | } |
| 12360 | } |
| 12361 | |
| 12362 | return 1; |
| 12363 | } |
| 12364 | |
| 12365 | |
| 12366 | static int update_devdetail_imsi(struct sigma_dut *dut, const char *imsi) |
| 12367 | { |
| 12368 | FILE *in, *out; |
| 12369 | char buf[500]; |
| 12370 | int found = 0; |
| 12371 | |
| 12372 | in = fopen("devdetail.xml", "r"); |
| 12373 | if (in == NULL) |
| 12374 | return -1; |
| 12375 | out = fopen("devdetail.xml.tmp", "w"); |
| 12376 | if (out == NULL) { |
| 12377 | fclose(in); |
| 12378 | return -1; |
| 12379 | } |
| 12380 | |
| 12381 | while (fgets(buf, sizeof(buf), in)) { |
| 12382 | char *pos = strstr(buf, "<IMSI>"); |
| 12383 | if (pos) { |
| 12384 | sigma_dut_print(dut, DUT_MSG_INFO, "Updated DevDetail IMSI to %s", |
| 12385 | imsi); |
| 12386 | pos += 6; |
| 12387 | *pos = '\0'; |
| 12388 | fprintf(out, "%s%s</IMSI>\n", buf, imsi); |
| 12389 | found++; |
| 12390 | } else { |
| 12391 | fprintf(out, "%s", buf); |
| 12392 | } |
| 12393 | } |
| 12394 | |
| 12395 | fclose(out); |
| 12396 | fclose(in); |
| 12397 | if (found) |
| 12398 | rename("devdetail.xml.tmp", "devdetail.xml"); |
| 12399 | else |
| 12400 | unlink("devdetail.xml.tmp"); |
| 12401 | |
| 12402 | return 0; |
| 12403 | } |
| 12404 | |
| 12405 | |
| 12406 | static int sta_add_credential_sim(struct sigma_dut *dut, |
| 12407 | struct sigma_conn *conn, |
| 12408 | const char *ifname, struct sigma_cmd *cmd) |
| 12409 | { |
| 12410 | const char *val, *imsi = NULL; |
| 12411 | int id; |
| 12412 | char buf[200]; |
| 12413 | int res; |
| 12414 | const char *pos; |
| 12415 | size_t mnc_len; |
| 12416 | char plmn_mcc[4]; |
| 12417 | char plmn_mnc[4]; |
| 12418 | |
| 12419 | id = add_cred(ifname); |
| 12420 | if (id < 0) |
| 12421 | return -2; |
| 12422 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id); |
| 12423 | |
| 12424 | val = get_param(cmd, "prefer"); |
| 12425 | if (val && atoi(val) > 0) |
| 12426 | set_cred(ifname, id, "priority", "1"); |
| 12427 | |
| 12428 | val = get_param(cmd, "PLMN_MCC"); |
| 12429 | if (val == NULL) { |
| 12430 | send_resp(dut, conn, SIGMA_ERROR, |
| 12431 | "errorCode,Missing PLMN_MCC"); |
| 12432 | return 0; |
| 12433 | } |
| 12434 | if (strlen(val) != 3) { |
| 12435 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MCC"); |
| 12436 | return 0; |
| 12437 | } |
| 12438 | snprintf(plmn_mcc, sizeof(plmn_mcc), "%s", val); |
| 12439 | |
| 12440 | val = get_param(cmd, "PLMN_MNC"); |
| 12441 | if (val == NULL) { |
| 12442 | send_resp(dut, conn, SIGMA_ERROR, |
| 12443 | "errorCode,Missing PLMN_MNC"); |
| 12444 | return 0; |
| 12445 | } |
| 12446 | if (strlen(val) != 2 && strlen(val) != 3) { |
| 12447 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MNC"); |
| 12448 | return 0; |
| 12449 | } |
| 12450 | snprintf(plmn_mnc, sizeof(plmn_mnc), "%s", val); |
| 12451 | |
| 12452 | val = get_param(cmd, "IMSI"); |
| 12453 | if (val == NULL) { |
| 12454 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing SIM " |
| 12455 | "IMSI"); |
| 12456 | return 0; |
| 12457 | } |
| 12458 | |
| 12459 | imsi = pos = val; |
| 12460 | |
| 12461 | if (strncmp(plmn_mcc, pos, 3) != 0) { |
| 12462 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,MCC mismatch"); |
| 12463 | return 0; |
| 12464 | } |
| 12465 | pos += 3; |
| 12466 | |
| 12467 | mnc_len = strlen(plmn_mnc); |
| 12468 | if (mnc_len < 2) { |
| 12469 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC not set"); |
| 12470 | return 0; |
| 12471 | } |
| 12472 | |
| 12473 | if (strncmp(plmn_mnc, pos, mnc_len) != 0) { |
| 12474 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC mismatch"); |
| 12475 | return 0; |
| 12476 | } |
| 12477 | pos += mnc_len; |
| 12478 | |
| 12479 | res = snprintf(buf, sizeof(buf), "%s%s-%s",plmn_mcc, plmn_mnc, pos); |
| 12480 | if (res < 0 || res >= (int) sizeof(buf)) |
| 12481 | return -1; |
| 12482 | if (set_cred_quoted(ifname, id, "imsi", buf) < 0) { |
| 12483 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could " |
| 12484 | "not set IMSI"); |
| 12485 | return 0; |
| 12486 | } |
| 12487 | |
| 12488 | val = get_param(cmd, "Password"); |
| 12489 | if (val && set_cred_quoted(ifname, id, "milenage", val) < 0) { |
| 12490 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could " |
| 12491 | "not set password"); |
| 12492 | return 0; |
| 12493 | } |
| 12494 | |
Jouni Malinen | ba63045 | 2018-06-22 11:49:59 +0300 | [diff] [blame] | 12495 | if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 12496 | /* |
| 12497 | * Set provisioning_sp for the test cases where SIM/USIM |
| 12498 | * provisioning is used. |
| 12499 | */ |
| 12500 | if (val && set_cred_quoted(ifname, id, "provisioning_sp", |
| 12501 | "wi-fi.org") < 0) { |
| 12502 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could " |
| 12503 | "not set provisioning_sp"); |
| 12504 | return 0; |
| 12505 | } |
| 12506 | |
| 12507 | update_devdetail_imsi(dut, imsi); |
| 12508 | } |
| 12509 | |
| 12510 | return 1; |
| 12511 | } |
| 12512 | |
| 12513 | |
| 12514 | static int sta_add_credential_cert(struct sigma_dut *dut, |
| 12515 | struct sigma_conn *conn, |
| 12516 | const char *ifname, |
| 12517 | struct sigma_cmd *cmd) |
| 12518 | { |
| 12519 | const char *val; |
| 12520 | int id; |
| 12521 | |
| 12522 | id = add_cred(ifname); |
| 12523 | if (id < 0) |
| 12524 | return -2; |
| 12525 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id); |
| 12526 | |
| 12527 | val = get_param(cmd, "prefer"); |
| 12528 | if (val && atoi(val) > 0) |
| 12529 | set_cred(ifname, id, "priority", "1"); |
| 12530 | |
| 12531 | val = get_param(cmd, "REALM"); |
| 12532 | if (val && set_cred_quoted(ifname, id, "realm", val) < 0) { |
| 12533 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set " |
| 12534 | "realm"); |
| 12535 | return 0; |
| 12536 | } |
| 12537 | |
| 12538 | val = get_param(cmd, "HOME_FQDN"); |
| 12539 | if (val && set_cred_quoted(ifname, id, "domain", val) < 0) { |
| 12540 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set " |
| 12541 | "home_fqdn"); |
| 12542 | return 0; |
| 12543 | } |
| 12544 | |
| 12545 | val = get_param(cmd, "Username"); |
| 12546 | if (val && set_cred_quoted(ifname, id, "username", val) < 0) { |
| 12547 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set " |
| 12548 | "username"); |
| 12549 | return 0; |
| 12550 | } |
| 12551 | |
| 12552 | val = get_param(cmd, "clientCertificate"); |
| 12553 | if (val) { |
| 12554 | char fname[200]; |
| 12555 | snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val); |
| 12556 | #ifdef __linux__ |
| 12557 | if (!file_exists(fname)) { |
| 12558 | char msg[300]; |
| 12559 | snprintf(msg, sizeof(msg), |
| 12560 | "ErrorCode,clientCertificate " |
| 12561 | "file (%s) not found", fname); |
| 12562 | send_resp(dut, conn, SIGMA_ERROR, msg); |
| 12563 | return 0; |
| 12564 | } |
| 12565 | #endif /* __linux__ */ |
| 12566 | if (set_cred_quoted(ifname, id, "client_cert", fname) < 0) { |
| 12567 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could " |
| 12568 | "not set client_cert"); |
| 12569 | return 0; |
| 12570 | } |
| 12571 | if (set_cred_quoted(ifname, id, "private_key", fname) < 0) { |
| 12572 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could " |
| 12573 | "not set private_key"); |
| 12574 | return 0; |
| 12575 | } |
| 12576 | } |
| 12577 | |
| 12578 | val = get_param(cmd, "ROOT_CA"); |
| 12579 | if (val) { |
| 12580 | char fname[200]; |
| 12581 | snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val); |
| 12582 | #ifdef __linux__ |
| 12583 | if (!file_exists(fname)) { |
| 12584 | char msg[300]; |
| 12585 | snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA " |
| 12586 | "file (%s) not found", fname); |
| 12587 | send_resp(dut, conn, SIGMA_ERROR, msg); |
| 12588 | return 0; |
| 12589 | } |
| 12590 | #endif /* __linux__ */ |
| 12591 | if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) { |
| 12592 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could " |
| 12593 | "not set root CA"); |
| 12594 | return 0; |
| 12595 | } |
| 12596 | } |
| 12597 | |
| 12598 | return 1; |
| 12599 | } |
| 12600 | |
| 12601 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 12602 | static enum sigma_cmd_result cmd_sta_add_credential(struct sigma_dut *dut, |
| 12603 | struct sigma_conn *conn, |
| 12604 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 12605 | { |
| 12606 | const char *intf = get_param(cmd, "Interface"); |
| 12607 | const char *type; |
| 12608 | |
| 12609 | start_sta_mode(dut); |
| 12610 | |
| 12611 | type = get_param(cmd, "Type"); |
| 12612 | if (!type) |
| 12613 | return -1; |
| 12614 | |
| 12615 | if (strcasecmp(type, "uname_pwd") == 0) |
| 12616 | return sta_add_credential_uname_pwd(dut, conn, intf, cmd); |
| 12617 | |
| 12618 | if (strcasecmp(type, "sim") == 0) |
| 12619 | return sta_add_credential_sim(dut, conn, intf, cmd); |
| 12620 | |
| 12621 | if (strcasecmp(type, "cert") == 0) |
| 12622 | return sta_add_credential_cert(dut, conn, intf, cmd); |
| 12623 | |
| 12624 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported credential " |
| 12625 | "type"); |
| 12626 | return 0; |
| 12627 | } |
| 12628 | |
| 12629 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 12630 | static enum sigma_cmd_result cmd_sta_scan(struct sigma_dut *dut, |
| 12631 | struct sigma_conn *conn, |
| 12632 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 12633 | { |
| 12634 | const char *intf = get_param(cmd, "Interface"); |
vamsi krishna | 89ad8c6 | 2017-09-19 12:51:18 +0530 | [diff] [blame] | 12635 | const char *val, *bssid, *ssid; |
Arif Hussain | 66a4af0 | 2019-02-07 15:04:51 -0800 | [diff] [blame] | 12636 | char buf[4096]; |
vamsi krishna | 89ad8c6 | 2017-09-19 12:51:18 +0530 | [diff] [blame] | 12637 | char ssid_hex[65]; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 12638 | int res; |
| 12639 | |
Arif Hussain | 66a4af0 | 2019-02-07 15:04:51 -0800 | [diff] [blame] | 12640 | val = get_param(cmd, "GetParameter"); |
| 12641 | if (val && strcmp(val, "SSID_BSSID") == 0) { |
| 12642 | if (get_wpa_ssid_bssid(dut, get_station_ifname(), |
| 12643 | buf, sizeof(buf)) < 0) { |
| 12644 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 12645 | "Could not get ssid bssid"); |
| 12646 | return ERROR_SEND_STATUS; |
| 12647 | } |
| 12648 | |
| 12649 | sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf); |
| 12650 | send_resp(dut, conn, SIGMA_COMPLETE, buf); |
| 12651 | return STATUS_SENT; |
| 12652 | } |
| 12653 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 12654 | val = get_param(cmd, "HESSID"); |
| 12655 | if (val) { |
| 12656 | res = snprintf(buf, sizeof(buf), "SET hessid %s", val); |
| 12657 | if (res < 0 || res >= (int) sizeof(buf)) |
| 12658 | return -1; |
| 12659 | wpa_command(intf, buf); |
| 12660 | } |
| 12661 | |
| 12662 | val = get_param(cmd, "ACCS_NET_TYPE"); |
| 12663 | if (val) { |
| 12664 | res = snprintf(buf, sizeof(buf), "SET access_network_type %s", |
| 12665 | val); |
| 12666 | if (res < 0 || res >= (int) sizeof(buf)) |
| 12667 | return -1; |
| 12668 | wpa_command(intf, buf); |
| 12669 | } |
| 12670 | |
vamsi krishna | 89ad8c6 | 2017-09-19 12:51:18 +0530 | [diff] [blame] | 12671 | bssid = get_param(cmd, "Bssid"); |
| 12672 | ssid = get_param(cmd, "Ssid"); |
| 12673 | |
| 12674 | if (ssid) { |
| 12675 | if (2 * strlen(ssid) >= sizeof(ssid_hex)) { |
| 12676 | send_resp(dut, conn, SIGMA_ERROR, |
| 12677 | "ErrorCode,Too long SSID"); |
| 12678 | return 0; |
| 12679 | } |
| 12680 | ascii2hexstr(ssid, ssid_hex); |
| 12681 | } |
| 12682 | |
| 12683 | res = snprintf(buf, sizeof(buf), "SCAN%s%s%s%s", |
| 12684 | bssid ? " bssid=": "", |
| 12685 | bssid ? bssid : "", |
| 12686 | ssid ? " ssid " : "", |
| 12687 | ssid ? ssid_hex : ""); |
| 12688 | if (res < 0 || res >= (int) sizeof(buf)) |
| 12689 | return -1; |
| 12690 | |
| 12691 | if (wpa_command(intf, buf)) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 12692 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not start " |
| 12693 | "scan"); |
| 12694 | return 0; |
| 12695 | } |
| 12696 | |
| 12697 | return 1; |
| 12698 | } |
| 12699 | |
| 12700 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 12701 | static enum sigma_cmd_result cmd_sta_scan_bss(struct sigma_dut *dut, |
| 12702 | struct sigma_conn *conn, |
| 12703 | struct sigma_cmd *cmd) |
Jouni Malinen | 5e5d43d | 2018-01-10 17:29:33 +0200 | [diff] [blame] | 12704 | { |
| 12705 | const char *intf = get_param(cmd, "Interface"); |
| 12706 | const char *bssid; |
| 12707 | char buf[4096], *pos; |
| 12708 | int freq, chan; |
| 12709 | char *ssid; |
| 12710 | char resp[100]; |
| 12711 | int res; |
| 12712 | struct wpa_ctrl *ctrl; |
| 12713 | |
| 12714 | bssid = get_param(cmd, "BSSID"); |
| 12715 | if (!bssid) { |
| 12716 | send_resp(dut, conn, SIGMA_INVALID, |
| 12717 | "errorCode,BSSID argument is missing"); |
| 12718 | return 0; |
| 12719 | } |
| 12720 | |
| 12721 | ctrl = open_wpa_mon(intf); |
| 12722 | if (!ctrl) { |
| 12723 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 12724 | "Failed to open wpa_supplicant monitor connection"); |
| 12725 | return -1; |
| 12726 | } |
| 12727 | |
| 12728 | if (wpa_command(intf, "SCAN TYPE=ONLY")) { |
| 12729 | send_resp(dut, conn, SIGMA_ERROR, |
| 12730 | "errorCode,Could not start scan"); |
| 12731 | wpa_ctrl_detach(ctrl); |
| 12732 | wpa_ctrl_close(ctrl); |
| 12733 | return 0; |
| 12734 | } |
| 12735 | |
| 12736 | res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS", |
| 12737 | buf, sizeof(buf)); |
| 12738 | |
| 12739 | wpa_ctrl_detach(ctrl); |
| 12740 | wpa_ctrl_close(ctrl); |
| 12741 | |
| 12742 | if (res < 0) { |
| 12743 | send_resp(dut, conn, SIGMA_ERROR, |
| 12744 | "errorCode,Scan did not complete"); |
| 12745 | return 0; |
| 12746 | } |
| 12747 | |
| 12748 | snprintf(buf, sizeof(buf), "BSS %s", bssid); |
| 12749 | if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 || |
| 12750 | strncmp(buf, "id=", 3) != 0) { |
| 12751 | send_resp(dut, conn, SIGMA_ERROR, |
| 12752 | "errorCode,Specified BSSID not found"); |
| 12753 | return 0; |
| 12754 | } |
| 12755 | |
| 12756 | pos = strstr(buf, "\nfreq="); |
| 12757 | if (!pos) { |
| 12758 | send_resp(dut, conn, SIGMA_ERROR, |
| 12759 | "errorCode,Channel not found"); |
| 12760 | return 0; |
| 12761 | } |
| 12762 | freq = atoi(pos + 6); |
| 12763 | chan = freq_to_channel(freq); |
| 12764 | |
| 12765 | pos = strstr(buf, "\nssid="); |
| 12766 | if (!pos) { |
| 12767 | send_resp(dut, conn, SIGMA_ERROR, |
| 12768 | "errorCode,SSID not found"); |
| 12769 | return 0; |
| 12770 | } |
| 12771 | ssid = pos + 6; |
| 12772 | pos = strchr(ssid, '\n'); |
| 12773 | if (pos) |
| 12774 | *pos = '\0'; |
| 12775 | snprintf(resp, sizeof(resp), "ssid,%s,bsschannel,%d", ssid, chan); |
| 12776 | send_resp(dut, conn, SIGMA_COMPLETE, resp); |
| 12777 | return 0; |
| 12778 | } |
| 12779 | |
| 12780 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 12781 | static enum sigma_cmd_result cmd_sta_set_systime(struct sigma_dut *dut, |
| 12782 | struct sigma_conn *conn, |
| 12783 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 12784 | { |
| 12785 | #ifdef __linux__ |
| 12786 | struct timeval tv; |
| 12787 | struct tm tm; |
| 12788 | time_t t; |
| 12789 | const char *val; |
Pradeep Reddy POTTETI | 429c69e | 2016-10-13 17:22:03 +0530 | [diff] [blame] | 12790 | int v; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 12791 | |
| 12792 | wpa_command(get_station_ifname(), "PMKSA_FLUSH"); |
| 12793 | |
| 12794 | memset(&tm, 0, sizeof(tm)); |
| 12795 | val = get_param(cmd, "seconds"); |
| 12796 | if (val) |
| 12797 | tm.tm_sec = atoi(val); |
| 12798 | val = get_param(cmd, "minutes"); |
| 12799 | if (val) |
| 12800 | tm.tm_min = atoi(val); |
| 12801 | val = get_param(cmd, "hours"); |
| 12802 | if (val) |
| 12803 | tm.tm_hour = atoi(val); |
| 12804 | val = get_param(cmd, "date"); |
| 12805 | if (val) |
| 12806 | tm.tm_mday = atoi(val); |
| 12807 | val = get_param(cmd, "month"); |
Pradeep Reddy POTTETI | 429c69e | 2016-10-13 17:22:03 +0530 | [diff] [blame] | 12808 | if (val) { |
| 12809 | v = atoi(val); |
| 12810 | if (v < 1 || v > 12) { |
| 12811 | send_resp(dut, conn, SIGMA_INVALID, |
| 12812 | "errorCode,Invalid month"); |
| 12813 | return 0; |
| 12814 | } |
| 12815 | tm.tm_mon = v - 1; |
| 12816 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 12817 | val = get_param(cmd, "year"); |
| 12818 | if (val) { |
| 12819 | int year = atoi(val); |
| 12820 | #ifdef ANDROID |
| 12821 | if (year > 2035) |
| 12822 | year = 2035; /* years beyond 2035 not supported */ |
| 12823 | #endif /* ANDROID */ |
| 12824 | tm.tm_year = year - 1900; |
| 12825 | } |
| 12826 | t = mktime(&tm); |
| 12827 | if (t == (time_t) -1) { |
| 12828 | send_resp(dut, conn, SIGMA_ERROR, |
| 12829 | "errorCode,Invalid date or time"); |
| 12830 | return 0; |
| 12831 | } |
| 12832 | |
| 12833 | memset(&tv, 0, sizeof(tv)); |
| 12834 | tv.tv_sec = t; |
| 12835 | |
| 12836 | if (settimeofday(&tv, NULL) < 0) { |
| 12837 | sigma_dut_print(dut, DUT_MSG_INFO, "settimeofday failed: %s", |
| 12838 | strerror(errno)); |
| 12839 | send_resp(dut, conn, SIGMA_ERROR, |
| 12840 | "errorCode,Failed to set time"); |
| 12841 | return 0; |
| 12842 | } |
| 12843 | |
| 12844 | return 1; |
| 12845 | #endif /* __linux__ */ |
| 12846 | |
| 12847 | return -1; |
| 12848 | } |
| 12849 | |
| 12850 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 12851 | static enum sigma_cmd_result cmd_sta_osu(struct sigma_dut *dut, |
| 12852 | struct sigma_conn *conn, |
| 12853 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 12854 | { |
| 12855 | const char *intf = get_param(cmd, "Interface"); |
Jouni Malinen | 4c8681c | 2018-09-12 23:28:11 +0300 | [diff] [blame] | 12856 | const char *name, *osu_ssid, *val; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 12857 | int prod_ess_assoc = 1; |
Jouni Malinen | 4c8681c | 2018-09-12 23:28:11 +0300 | [diff] [blame] | 12858 | char buf[300], bssid[100], ssid[100]; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 12859 | int res; |
| 12860 | struct wpa_ctrl *ctrl; |
| 12861 | |
| 12862 | name = get_param(cmd, "osuFriendlyName"); |
Jouni Malinen | 4c8681c | 2018-09-12 23:28:11 +0300 | [diff] [blame] | 12863 | osu_ssid = get_param(cmd, "osu_ssid"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 12864 | |
| 12865 | val = get_param(cmd, "ProdESSAssoc"); |
| 12866 | if (val) |
| 12867 | prod_ess_assoc = atoi(val); |
| 12868 | |
| 12869 | kill_dhcp_client(dut, intf); |
| 12870 | if (start_dhcp_client(dut, intf) < 0) |
| 12871 | return -2; |
| 12872 | |
| 12873 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger OSU"); |
| 12874 | mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); |
| 12875 | res = snprintf(buf, sizeof(buf), |
Jouni Malinen | 4c8681c | 2018-09-12 23:28:11 +0300 | [diff] [blame] | 12876 | "%s %s%s%s %s%s%s signup osu-ca.pem", |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 12877 | prod_ess_assoc ? "" : "-N", |
| 12878 | name ? "-O'" : "", name ? name : "", |
Jouni Malinen | 4c8681c | 2018-09-12 23:28:11 +0300 | [diff] [blame] | 12879 | name ? "'" : "", |
| 12880 | osu_ssid ? "-o'" : "", osu_ssid ? osu_ssid : "", |
| 12881 | osu_ssid ? "'" : ""); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 12882 | |
Kanchanapally, Vidyullatha | 12b6676 | 2015-12-31 16:46:42 +0530 | [diff] [blame] | 12883 | hs2_set_policy(dut); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 12884 | if (run_hs20_osu(dut, buf) < 0) { |
| 12885 | FILE *f; |
| 12886 | |
| 12887 | sigma_dut_print(dut, DUT_MSG_INFO, "Failed to complete OSU"); |
| 12888 | |
| 12889 | f = fopen("hs20-osu-client.res", "r"); |
| 12890 | if (f) { |
| 12891 | char resp[400], res[300], *pos; |
| 12892 | if (!fgets(res, sizeof(res), f)) |
| 12893 | res[0] = '\0'; |
| 12894 | pos = strchr(res, '\n'); |
| 12895 | if (pos) |
| 12896 | *pos = '\0'; |
| 12897 | fclose(f); |
| 12898 | sigma_dut_summary(dut, "hs20-osu-client provisioning failed: %s", |
| 12899 | res); |
| 12900 | snprintf(resp, sizeof(resp), "notify-send '%s'", res); |
| 12901 | if (system(resp) != 0) { |
| 12902 | } |
| 12903 | snprintf(resp, sizeof(resp), |
| 12904 | "SSID,,BSSID,,failureReason,%s", res); |
| 12905 | send_resp(dut, conn, SIGMA_COMPLETE, resp); |
| 12906 | return 0; |
| 12907 | } |
| 12908 | |
| 12909 | send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,"); |
| 12910 | return 0; |
| 12911 | } |
| 12912 | |
| 12913 | if (!prod_ess_assoc) |
| 12914 | goto report; |
| 12915 | |
| 12916 | ctrl = open_wpa_mon(intf); |
| 12917 | if (ctrl == NULL) { |
| 12918 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open " |
| 12919 | "wpa_supplicant monitor connection"); |
| 12920 | return -1; |
| 12921 | } |
| 12922 | |
| 12923 | res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED", |
| 12924 | buf, sizeof(buf)); |
| 12925 | |
| 12926 | wpa_ctrl_detach(ctrl); |
| 12927 | wpa_ctrl_close(ctrl); |
| 12928 | |
| 12929 | if (res < 0) { |
| 12930 | sigma_dut_print(dut, DUT_MSG_INFO, "Failed to connect to " |
| 12931 | "network after OSU"); |
| 12932 | send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,"); |
| 12933 | return 0; |
| 12934 | } |
| 12935 | |
| 12936 | report: |
| 12937 | if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 || |
| 12938 | get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) { |
| 12939 | sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get BSSID/SSID"); |
| 12940 | send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,"); |
| 12941 | return 0; |
| 12942 | } |
| 12943 | |
| 12944 | snprintf(buf, sizeof(buf), "SSID,%s,BSSID,%s", ssid, bssid); |
| 12945 | send_resp(dut, conn, SIGMA_COMPLETE, buf); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 12946 | return 0; |
| 12947 | } |
| 12948 | |
| 12949 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 12950 | static enum sigma_cmd_result cmd_sta_policy_update(struct sigma_dut *dut, |
| 12951 | struct sigma_conn *conn, |
| 12952 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 12953 | { |
| 12954 | const char *val; |
| 12955 | int timeout = 120; |
| 12956 | |
| 12957 | val = get_param(cmd, "PolicyUpdate"); |
| 12958 | if (val == NULL || atoi(val) == 0) |
| 12959 | return 1; /* No operation requested */ |
| 12960 | |
| 12961 | val = get_param(cmd, "Timeout"); |
| 12962 | if (val) |
| 12963 | timeout = atoi(val); |
| 12964 | |
| 12965 | if (timeout) { |
| 12966 | /* TODO: time out the command and return |
| 12967 | * PolicyUpdateStatus,TIMEOUT if needed. */ |
| 12968 | } |
| 12969 | |
| 12970 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger policy update"); |
| 12971 | mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); |
| 12972 | if (run_hs20_osu(dut, "pol_upd fqdn=wi-fi.org") < 0) { |
| 12973 | send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,FAIL"); |
| 12974 | return 0; |
| 12975 | } |
| 12976 | |
| 12977 | send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,SUCCESS"); |
| 12978 | return 0; |
| 12979 | } |
| 12980 | |
| 12981 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 12982 | static enum sigma_cmd_result cmd_sta_er_config(struct sigma_dut *dut, |
| 12983 | struct sigma_conn *conn, |
| 12984 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 12985 | { |
| 12986 | struct wpa_ctrl *ctrl; |
| 12987 | const char *intf = get_param(cmd, "Interface"); |
| 12988 | const char *bssid = get_param(cmd, "Bssid"); |
| 12989 | const char *ssid = get_param(cmd, "SSID"); |
| 12990 | const char *security = get_param(cmd, "Security"); |
| 12991 | const char *passphrase = get_param(cmd, "Passphrase"); |
| 12992 | const char *pin = get_param(cmd, "PIN"); |
| 12993 | char buf[1000]; |
| 12994 | char ssid_hex[200], passphrase_hex[200]; |
| 12995 | const char *keymgmt, *cipher; |
| 12996 | |
| 12997 | if (intf == NULL) |
| 12998 | intf = get_main_ifname(); |
| 12999 | |
| 13000 | if (!bssid) { |
| 13001 | send_resp(dut, conn, SIGMA_ERROR, |
| 13002 | "ErrorCode,Missing Bssid argument"); |
| 13003 | return 0; |
| 13004 | } |
| 13005 | |
| 13006 | if (!ssid) { |
| 13007 | send_resp(dut, conn, SIGMA_ERROR, |
| 13008 | "ErrorCode,Missing SSID argument"); |
| 13009 | return 0; |
| 13010 | } |
| 13011 | |
| 13012 | if (!security) { |
| 13013 | send_resp(dut, conn, SIGMA_ERROR, |
| 13014 | "ErrorCode,Missing Security argument"); |
| 13015 | return 0; |
| 13016 | } |
| 13017 | |
| 13018 | if (!passphrase) { |
| 13019 | send_resp(dut, conn, SIGMA_ERROR, |
| 13020 | "ErrorCode,Missing Passphrase argument"); |
| 13021 | return 0; |
| 13022 | } |
| 13023 | |
| 13024 | if (!pin) { |
| 13025 | send_resp(dut, conn, SIGMA_ERROR, |
| 13026 | "ErrorCode,Missing PIN argument"); |
| 13027 | return 0; |
| 13028 | } |
| 13029 | |
vamsi krishna | 8c9c156 | 2017-05-12 15:51:46 +0530 | [diff] [blame] | 13030 | if (2 * strlen(ssid) >= sizeof(ssid_hex) || |
| 13031 | 2 * strlen(passphrase) >= sizeof(passphrase_hex)) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 13032 | send_resp(dut, conn, SIGMA_ERROR, |
| 13033 | "ErrorCode,Too long SSID/passphrase"); |
| 13034 | return 0; |
| 13035 | } |
| 13036 | |
| 13037 | ctrl = open_wpa_mon(intf); |
| 13038 | if (ctrl == NULL) { |
| 13039 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open " |
| 13040 | "wpa_supplicant monitor connection"); |
| 13041 | return -2; |
| 13042 | } |
| 13043 | |
| 13044 | if (strcasecmp(security, "wpa2-psk") == 0) { |
| 13045 | keymgmt = "WPA2PSK"; |
| 13046 | cipher = "CCMP"; |
| 13047 | } else { |
| 13048 | wpa_ctrl_detach(ctrl); |
| 13049 | wpa_ctrl_close(ctrl); |
| 13050 | send_resp(dut, conn, SIGMA_ERROR, |
| 13051 | "ErrorCode,Unsupported Security value"); |
| 13052 | return 0; |
| 13053 | } |
| 13054 | |
| 13055 | ascii2hexstr(ssid, ssid_hex); |
| 13056 | ascii2hexstr(passphrase, passphrase_hex); |
| 13057 | snprintf(buf, sizeof(buf), "WPS_REG %s %s %s %s %s %s", |
| 13058 | bssid, pin, ssid_hex, keymgmt, cipher, passphrase_hex); |
| 13059 | |
| 13060 | if (wpa_command(intf, buf) < 0) { |
| 13061 | wpa_ctrl_detach(ctrl); |
| 13062 | wpa_ctrl_close(ctrl); |
| 13063 | send_resp(dut, conn, SIGMA_ERROR, |
| 13064 | "ErrorCode,Failed to start registrar"); |
| 13065 | return 0; |
| 13066 | } |
| 13067 | |
| 13068 | snprintf(dut->er_oper_bssid, sizeof(dut->er_oper_bssid), "%s", bssid); |
| 13069 | dut->er_oper_performed = 1; |
| 13070 | |
| 13071 | return wps_connection_event(dut, conn, ctrl, intf, 0); |
| 13072 | } |
| 13073 | |
| 13074 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 13075 | static enum sigma_cmd_result |
| 13076 | cmd_sta_wps_connect_pw_token(struct sigma_dut *dut, struct sigma_conn *conn, |
| 13077 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 13078 | { |
| 13079 | struct wpa_ctrl *ctrl; |
| 13080 | const char *intf = get_param(cmd, "Interface"); |
| 13081 | const char *bssid = get_param(cmd, "Bssid"); |
| 13082 | char buf[100]; |
| 13083 | |
| 13084 | if (!bssid) { |
| 13085 | send_resp(dut, conn, SIGMA_ERROR, |
| 13086 | "ErrorCode,Missing Bssid argument"); |
| 13087 | return 0; |
| 13088 | } |
| 13089 | |
| 13090 | ctrl = open_wpa_mon(intf); |
| 13091 | if (ctrl == NULL) { |
| 13092 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open " |
| 13093 | "wpa_supplicant monitor connection"); |
| 13094 | return -2; |
| 13095 | } |
| 13096 | |
| 13097 | snprintf(buf, sizeof(buf), "WPS_NFC %s", bssid); |
| 13098 | |
| 13099 | if (wpa_command(intf, buf) < 0) { |
| 13100 | wpa_ctrl_detach(ctrl); |
| 13101 | wpa_ctrl_close(ctrl); |
| 13102 | send_resp(dut, conn, SIGMA_ERROR, |
| 13103 | "ErrorCode,Failed to start registrar"); |
| 13104 | return 0; |
| 13105 | } |
| 13106 | |
| 13107 | return wps_connection_event(dut, conn, ctrl, intf, 0); |
| 13108 | } |
| 13109 | |
| 13110 | |
Jouni Malinen | f722271 | 2019-06-13 01:50:21 +0300 | [diff] [blame] | 13111 | static enum sigma_cmd_result cmd_start_wps_registration(struct sigma_dut *dut, |
| 13112 | struct sigma_conn *conn, |
| 13113 | struct sigma_cmd *cmd) |
vamsi krishna | 9b14400 | 2017-09-20 13:28:13 +0530 | [diff] [blame] | 13114 | { |
| 13115 | struct wpa_ctrl *ctrl; |
| 13116 | const char *intf = get_param(cmd, "Interface"); |
Alexei Avshalom Lazar | d596b51 | 2018-12-18 16:00:59 +0200 | [diff] [blame] | 13117 | const char *network_mode = get_param(cmd, "network_mode"); |
Alexei Avshalom Lazar | 043230b | 2019-02-04 14:11:24 +0200 | [diff] [blame] | 13118 | const char *config_method = get_param(cmd, "WPSConfigMethod"); |
| 13119 | const char *role; |
vamsi krishna | 9b14400 | 2017-09-20 13:28:13 +0530 | [diff] [blame] | 13120 | int res; |
| 13121 | char buf[256]; |
| 13122 | const char *events[] = { |
| 13123 | "CTRL-EVENT-CONNECTED", |
| 13124 | "WPS-OVERLAP-DETECTED", |
| 13125 | "WPS-TIMEOUT", |
| 13126 | "WPS-FAIL", |
| 13127 | NULL |
| 13128 | }; |
Alexei Avshalom Lazar | d596b51 | 2018-12-18 16:00:59 +0200 | [diff] [blame] | 13129 | int id = 0; |
vamsi krishna | 9b14400 | 2017-09-20 13:28:13 +0530 | [diff] [blame] | 13130 | |
Alexei Avshalom Lazar | 35ab383 | 2018-12-23 16:49:49 +0200 | [diff] [blame] | 13131 | /* 60G WPS tests do not pass Interface parameter */ |
| 13132 | if (!intf) |
| 13133 | intf = get_main_ifname(); |
| 13134 | |
Alexei Avshalom Lazar | 043230b | 2019-02-04 14:11:24 +0200 | [diff] [blame] | 13135 | if (dut->mode == SIGMA_MODE_AP) |
| 13136 | return ap_wps_registration(dut, conn, cmd); |
| 13137 | |
| 13138 | if (config_method) { |
| 13139 | /* WFA_CS_WPS_PIN_KEYPAD mode is set when using the |
| 13140 | * sta_wps_enter_pin before calling start_wps_registration. */ |
| 13141 | if (strcasecmp(config_method, "PBC") == 0) |
| 13142 | dut->wps_method = WFA_CS_WPS_PBC; |
| 13143 | } |
| 13144 | if (dut->wps_method == WFA_CS_WPS_NOT_READY) { |
| 13145 | send_resp(dut, conn, SIGMA_ERROR, |
| 13146 | "ErrorCode,WPS parameters not yet set"); |
| 13147 | return STATUS_SENT; |
| 13148 | } |
| 13149 | |
| 13150 | /* Make sure WPS is enabled (also for STA mode) */ |
| 13151 | dut->wps_disable = 0; |
| 13152 | |
Alexei Avshalom Lazar | d596b51 | 2018-12-18 16:00:59 +0200 | [diff] [blame] | 13153 | if (dut->band == WPS_BAND_60G && network_mode && |
| 13154 | strcasecmp(network_mode, "PBSS") == 0) { |
| 13155 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 13156 | "Set PBSS network mode, network id %d", id); |
| 13157 | if (set_network(get_station_ifname(), id, "pbss", "1") < 0) |
| 13158 | return -2; |
| 13159 | } |
| 13160 | |
Alexei Avshalom Lazar | b094bf0 | 2018-12-18 16:00:53 +0200 | [diff] [blame] | 13161 | if (dut->force_rsn_ie) { |
| 13162 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Force RSN_IE: %d", |
| 13163 | dut->force_rsn_ie); |
| 13164 | if (sta_60g_force_rsn_ie(dut, dut->force_rsn_ie) < 0) { |
| 13165 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 13166 | "Failed to force RSN_IE"); |
Jouni Malinen | 0e29cf2 | 2019-02-19 01:13:21 +0200 | [diff] [blame] | 13167 | return ERROR_SEND_STATUS; |
Alexei Avshalom Lazar | b094bf0 | 2018-12-18 16:00:53 +0200 | [diff] [blame] | 13168 | } |
| 13169 | } |
| 13170 | |
vamsi krishna | 9b14400 | 2017-09-20 13:28:13 +0530 | [diff] [blame] | 13171 | ctrl = open_wpa_mon(intf); |
| 13172 | if (!ctrl) { |
| 13173 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 13174 | "Failed to open wpa_supplicant monitor connection"); |
| 13175 | return -2; |
| 13176 | } |
| 13177 | |
| 13178 | role = get_param(cmd, "WpsRole"); |
| 13179 | if (!role) { |
| 13180 | send_resp(dut, conn, SIGMA_INVALID, |
| 13181 | "ErrorCode,WpsRole not provided"); |
| 13182 | goto fail; |
| 13183 | } |
| 13184 | |
Alexei Avshalom Lazar | 043230b | 2019-02-04 14:11:24 +0200 | [diff] [blame] | 13185 | if (strcasecmp(role, "Enrollee") != 0) { |
| 13186 | /* Registrar role for STA not supported */ |
| 13187 | send_resp(dut, conn, SIGMA_ERROR, |
| 13188 | "ErrorCode,Unsupported WpsRole value"); |
| 13189 | goto fail; |
| 13190 | } |
| 13191 | |
| 13192 | if (is_60g_sigma_dut(dut)) { |
| 13193 | if (dut->wps_method == WFA_CS_WPS_PBC) |
| 13194 | snprintf(buf, sizeof(buf), "WPS_PBC"); |
| 13195 | else /* WFA_CS_WPS_PIN_KEYPAD */ |
| 13196 | snprintf(buf, sizeof(buf), "WPS_PIN any %s", |
| 13197 | dut->wps_pin); |
| 13198 | if (wpa_command(intf, buf) < 0) { |
| 13199 | send_resp(dut, conn, SIGMA_ERROR, |
| 13200 | "ErrorCode,Failed to start WPS"); |
vamsi krishna | 9b14400 | 2017-09-20 13:28:13 +0530 | [diff] [blame] | 13201 | goto fail; |
| 13202 | } |
Alexei Avshalom Lazar | 043230b | 2019-02-04 14:11:24 +0200 | [diff] [blame] | 13203 | res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf)); |
| 13204 | if (res < 0) { |
| 13205 | send_resp(dut, conn, SIGMA_ERROR, |
| 13206 | "ErrorCode,WPS connection did not complete"); |
| 13207 | goto fail; |
| 13208 | } |
| 13209 | if (strstr(buf, "WPS-TIMEOUT")) { |
| 13210 | send_resp(dut, conn, SIGMA_COMPLETE, "WpsState,NoPeer"); |
| 13211 | } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) { |
| 13212 | send_resp(dut, conn, SIGMA_COMPLETE, |
| 13213 | "WpsState,OverlapSession"); |
| 13214 | } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) { |
| 13215 | send_resp(dut, conn, SIGMA_COMPLETE, |
| 13216 | "WpsState,Successful"); |
| 13217 | } else { |
| 13218 | send_resp(dut, conn, SIGMA_COMPLETE, |
| 13219 | "WpsState,Failure"); |
| 13220 | } |
| 13221 | } else { |
| 13222 | if (dut->wps_method == WFA_CS_WPS_PBC) { |
vamsi krishna | 9b14400 | 2017-09-20 13:28:13 +0530 | [diff] [blame] | 13223 | if (wpa_command(intf, "WPS_PBC") < 0) { |
| 13224 | send_resp(dut, conn, SIGMA_ERROR, |
| 13225 | "ErrorCode,Failed to enable PBC"); |
| 13226 | goto fail; |
| 13227 | } |
| 13228 | } else { |
| 13229 | /* TODO: PIN method */ |
| 13230 | send_resp(dut, conn, SIGMA_ERROR, |
| 13231 | "ErrorCode,Unsupported WpsConfigMethod value"); |
| 13232 | goto fail; |
| 13233 | } |
| 13234 | res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf)); |
| 13235 | if (res < 0) { |
| 13236 | send_resp(dut, conn, SIGMA_ERROR, |
| 13237 | "ErrorCode,WPS connection did not complete"); |
| 13238 | goto fail; |
| 13239 | } |
| 13240 | if (strstr(buf, "WPS-TIMEOUT")) { |
| 13241 | send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,NoPeer"); |
| 13242 | } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) { |
| 13243 | send_resp(dut, conn, SIGMA_ERROR, |
| 13244 | "ErrorCode,OverlapSession"); |
| 13245 | } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) { |
| 13246 | send_resp(dut, conn, SIGMA_COMPLETE, "Successful"); |
| 13247 | } else { |
| 13248 | send_resp(dut, conn, SIGMA_ERROR, |
| 13249 | "ErrorCode,WPS operation failed"); |
| 13250 | } |
vamsi krishna | 9b14400 | 2017-09-20 13:28:13 +0530 | [diff] [blame] | 13251 | } |
| 13252 | |
| 13253 | fail: |
| 13254 | wpa_ctrl_detach(ctrl); |
| 13255 | wpa_ctrl_close(ctrl); |
| 13256 | return 0; |
| 13257 | } |
| 13258 | |
| 13259 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 13260 | static int req_intf(struct sigma_cmd *cmd) |
| 13261 | { |
| 13262 | return get_param(cmd, "interface") == NULL ? -1 : 0; |
| 13263 | } |
| 13264 | |
| 13265 | |
| 13266 | void sta_register_cmds(void) |
| 13267 | { |
| 13268 | sigma_dut_reg_cmd("sta_get_ip_config", req_intf, |
| 13269 | cmd_sta_get_ip_config); |
| 13270 | sigma_dut_reg_cmd("sta_set_ip_config", req_intf, |
| 13271 | cmd_sta_set_ip_config); |
| 13272 | sigma_dut_reg_cmd("sta_get_info", req_intf, cmd_sta_get_info); |
| 13273 | sigma_dut_reg_cmd("sta_get_mac_address", req_intf, |
| 13274 | cmd_sta_get_mac_address); |
| 13275 | sigma_dut_reg_cmd("sta_is_connected", req_intf, cmd_sta_is_connected); |
| 13276 | sigma_dut_reg_cmd("sta_verify_ip_connection", req_intf, |
| 13277 | cmd_sta_verify_ip_connection); |
| 13278 | sigma_dut_reg_cmd("sta_get_bssid", req_intf, cmd_sta_get_bssid); |
| 13279 | sigma_dut_reg_cmd("sta_set_encryption", req_intf, |
| 13280 | cmd_sta_set_encryption); |
| 13281 | sigma_dut_reg_cmd("sta_set_psk", req_intf, cmd_sta_set_psk); |
| 13282 | sigma_dut_reg_cmd("sta_set_eaptls", req_intf, cmd_sta_set_eaptls); |
| 13283 | sigma_dut_reg_cmd("sta_set_eapttls", req_intf, cmd_sta_set_eapttls); |
| 13284 | sigma_dut_reg_cmd("sta_set_eapsim", req_intf, cmd_sta_set_eapsim); |
| 13285 | sigma_dut_reg_cmd("sta_set_peap", req_intf, cmd_sta_set_peap); |
| 13286 | sigma_dut_reg_cmd("sta_set_eapfast", req_intf, cmd_sta_set_eapfast); |
| 13287 | sigma_dut_reg_cmd("sta_set_eapaka", req_intf, cmd_sta_set_eapaka); |
| 13288 | sigma_dut_reg_cmd("sta_set_eapakaprime", req_intf, |
| 13289 | cmd_sta_set_eapakaprime); |
| 13290 | sigma_dut_reg_cmd("sta_set_security", req_intf, cmd_sta_set_security); |
| 13291 | sigma_dut_reg_cmd("sta_set_uapsd", req_intf, cmd_sta_set_uapsd); |
| 13292 | /* TODO: sta_set_ibss */ |
| 13293 | /* TODO: sta_set_mode */ |
| 13294 | sigma_dut_reg_cmd("sta_set_wmm", req_intf, cmd_sta_set_wmm); |
| 13295 | sigma_dut_reg_cmd("sta_associate", req_intf, cmd_sta_associate); |
| 13296 | /* TODO: sta_up_load */ |
| 13297 | sigma_dut_reg_cmd("sta_preset_testparameters", req_intf, |
| 13298 | cmd_sta_preset_testparameters); |
| 13299 | /* TODO: sta_set_system */ |
| 13300 | sigma_dut_reg_cmd("sta_set_11n", req_intf, cmd_sta_set_11n); |
| 13301 | /* TODO: sta_set_rifs_test */ |
| 13302 | sigma_dut_reg_cmd("sta_set_wireless", req_intf, cmd_sta_set_wireless); |
| 13303 | sigma_dut_reg_cmd("sta_send_addba", req_intf, cmd_sta_send_addba); |
| 13304 | /* TODO: sta_send_coexist_mgmt */ |
| 13305 | sigma_dut_reg_cmd("sta_disconnect", req_intf, cmd_sta_disconnect); |
| 13306 | sigma_dut_reg_cmd("sta_reassoc", req_intf, cmd_sta_reassoc); |
| 13307 | sigma_dut_reg_cmd("sta_reassociate", req_intf, cmd_sta_reassoc); |
| 13308 | sigma_dut_reg_cmd("sta_reset_default", req_intf, |
| 13309 | cmd_sta_reset_default); |
| 13310 | sigma_dut_reg_cmd("sta_send_frame", req_intf, cmd_sta_send_frame); |
| 13311 | sigma_dut_reg_cmd("sta_set_macaddr", req_intf, cmd_sta_set_macaddr); |
| 13312 | sigma_dut_reg_cmd("sta_set_rfeature", req_intf, cmd_sta_set_rfeature); |
| 13313 | sigma_dut_reg_cmd("sta_set_radio", req_intf, cmd_sta_set_radio); |
| 13314 | 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] | 13315 | 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] | 13316 | sigma_dut_reg_cmd("sta_bssid_pool", req_intf, cmd_sta_bssid_pool); |
| 13317 | sigma_dut_reg_cmd("sta_reset_parm", req_intf, cmd_sta_reset_parm); |
| 13318 | sigma_dut_reg_cmd("sta_get_key", req_intf, cmd_sta_get_key); |
| 13319 | sigma_dut_reg_cmd("sta_hs2_associate", req_intf, |
| 13320 | cmd_sta_hs2_associate); |
Jouni Malinen | b639f1c | 2018-09-13 02:39:46 +0300 | [diff] [blame] | 13321 | sigma_dut_reg_cmd("sta_hs2_venue_info", req_intf, |
| 13322 | cmd_sta_hs2_venue_info); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 13323 | sigma_dut_reg_cmd("sta_add_credential", req_intf, |
| 13324 | cmd_sta_add_credential); |
| 13325 | sigma_dut_reg_cmd("sta_scan", req_intf, cmd_sta_scan); |
Jouni Malinen | 5e5d43d | 2018-01-10 17:29:33 +0200 | [diff] [blame] | 13326 | 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] | 13327 | sigma_dut_reg_cmd("sta_set_systime", NULL, cmd_sta_set_systime); |
| 13328 | sigma_dut_reg_cmd("sta_osu", req_intf, cmd_sta_osu); |
| 13329 | sigma_dut_reg_cmd("sta_policy_update", req_intf, cmd_sta_policy_update); |
| 13330 | sigma_dut_reg_cmd("sta_er_config", NULL, cmd_sta_er_config); |
| 13331 | sigma_dut_reg_cmd("sta_wps_connect_pw_token", req_intf, |
| 13332 | cmd_sta_wps_connect_pw_token); |
Jouni Malinen | 8290520 | 2018-04-29 17:20:10 +0300 | [diff] [blame] | 13333 | sigma_dut_reg_cmd("sta_exec_action", NULL, cmd_sta_exec_action); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 13334 | sigma_dut_reg_cmd("sta_get_events", req_intf, cmd_sta_get_events); |
| 13335 | 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] | 13336 | sigma_dut_reg_cmd("start_wps_registration", NULL, |
vamsi krishna | 9b14400 | 2017-09-20 13:28:13 +0530 | [diff] [blame] | 13337 | cmd_start_wps_registration); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 13338 | } |