blob: 6ba53a2c45b2d761ea7d60fd86eff0ce0f562846 [file] [log] [blame]
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001/*
2 * Sigma Control API DUT (station/AP)
3 * Copyright (c) 2010-2011, Atheros Communications, Inc.
Jouni Malinen9d7e31d2017-12-22 18:55:04 +02004 * Copyright (c) 2011-2017, Qualcomm Atheros, Inc.
Jouni Malinenc12ea4a2018-01-05 21:07:10 +02005 * Copyright (c) 2018, The Linux Foundation
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006 * 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 Malinen82905202018-04-29 17:20:10 +030013#include <sys/wait.h>
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030014#include <ctype.h>
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015#ifdef __linux__
Lior Davidcc88b562017-01-03 18:52:09 +020016#include <regex.h>
17#include <dirent.h>
Jouni Malinencd4e3c32015-10-29 12:39:56 +020018#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 Subramanyam9c381f52017-03-17 00:04:41 -070035#include "miracast.h"
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -070036#include "qca-vendor_copy.h"
Jouni Malinencd4e3c32015-10-29 12:39:56 +020037
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 Patil00402582017-04-13 12:29:39 +053054#define NON_PREF_CH_LIST_SIZE 100
Ashwini Patil5acd7382017-04-13 15:55:04 +053055#define NEIGHBOR_REPORT_SIZE 1000
56#define DEFAULT_NEIGHBOR_BSSID_INFO "17"
57#define DEFAULT_NEIGHBOR_PHY_TYPE "1"
Ashwini Patil00402582017-04-13 12:29:39 +053058
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030059#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 */
67struct template_frame_tag {
68 int num;
69 int offset;
70 size_t len;
71};
72
Jouni Malinencd4e3c32015-10-29 12:39:56 +020073extern char *sigma_wpas_ctrl;
74extern char *sigma_cert_path;
75extern enum driver_type wifi_chip_type;
76extern char *sigma_radio_ifname[];
77
Lior David0fe101e2017-03-09 16:09:50 +020078#ifdef __linux__
79#define WIL_WMI_MAX_PAYLOAD 248
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020080#define WIL_WMI_ESE_CFG_CMDID 0xa01
Lior David0fe101e2017-03-09 16:09:50 +020081#define WIL_WMI_BF_TRIG_CMDID 0x83a
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020082#define WIL_WMI_UNIT_TEST_CMDID 0x900
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030083#define WIL_WMI_P2P_CFG_CMDID 0x910
84#define WIL_WMI_START_LISTEN_CMDID 0x914
85#define WIL_WMI_DISCOVERY_STOP_CMDID 0x917
Lior David0fe101e2017-03-09 16:09:50 +020086
87struct wil_wmi_header {
88 uint8_t mid;
89 uint8_t reserved;
90 uint16_t cmd;
91 uint32_t ts;
92} __attribute__((packed));
93
94enum wil_wmi_bf_trig_type {
95 WIL_WMI_SLS,
96 WIL_WMI_BRP_RX,
97 WIL_WMI_BRP_TX,
98};
99
100struct 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 Lazarb094bf02018-12-18 16:00:53 +0200109
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +0200110enum 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
116enum wil_wmi_ese_slot_type {
117 WIL_WMI_ESE_SP,
118 WIL_WMI_ESE_CBAP,
119 WIL_WMI_ESE_ANNOUNCE_NO_ACK,
120};
121
122struct 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
144struct 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 Lazaraad97b02018-12-18 16:01:23 +0200156#define WIL_WMI_UT_FORCE_MCS 6
157struct 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 Lazarb094bf02018-12-18 16:00:53 +0200170#define WIL_WMI_UT_HW_SYSAPI 10
171#define WIL_WMI_UT_FORCE_RSN_IE 0x29
172struct 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 Lazara90032d2019-05-02 13:34:02 +0300180
181enum wil_wmi_discovery_mode {
182 WMI_DISCOVERY_MODE_NON_OFFLOAD,
183 WMI_DISCOVERY_MODE_OFFLOAD,
184 WMI_DISCOVERY_MODE_PEER2PEER,
185};
186
187struct 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 David0fe101e2017-03-09 16:09:50 +0200195#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200196
197#ifdef ANDROID
198
199static 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
204static int android_keystore_get(char cmd, const char *key, unsigned char *val)
205{
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200206 /* 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 Malinencd4e3c32015-10-29 12:39:56 +0200230}
231#endif /* ANDROID */
232
233
Vinita S. Maloo0fcb57d2020-04-24 14:03:56 +0530234#ifdef NL80211_SUPPORT
235static int nl80211_sta_set_power_save(struct sigma_dut *dut,
236 const char *intf,
237 enum nl80211_ps_state ps_state)
238{
239 struct nl_msg *msg;
240 int ifindex, ret;
241
242 ifindex = if_nametoindex(intf);
243 if (ifindex == 0) {
244 sigma_dut_print(dut, DUT_MSG_ERROR,
245 "%s: Index for interface %s not found",
246 __func__, intf);
247 return -1;
248 }
249
250 msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
251 NL80211_CMD_SET_POWER_SAVE);
252 if (!msg) {
253 sigma_dut_print(dut, DUT_MSG_ERROR,
254 "%s: err in creating nl80211 msg", __func__);
255 return -1;
256 }
257
258 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) {
259 sigma_dut_print(dut, DUT_MSG_ERROR,
260 "%s: err in populating nl80211 msg", __func__);
261 nlmsg_free(msg);
262 return -1;
263 }
264
265 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
266 if (ret) {
267 sigma_dut_print(dut, DUT_MSG_ERROR,
268 "%s: err in send_and_recv_msgs, ret=%d (%s)",
269 __func__, ret, strerror(-ret));
270 return -1;
271 }
272
273 return 0;
274}
275#endif /* NL80211_SUPPORT */
276
277
Vinita S. Malooa8b62722020-04-23 01:45:41 +0530278static int set_power_save_wcn(struct sigma_dut *dut, const char *intf, int ps)
279{
280 char buf[100];
Vinita S. Maloo0fcb57d2020-04-24 14:03:56 +0530281#ifdef NL80211_SUPPORT
282 enum nl80211_ps_state ps_state;
283
284 ps_state = ps == 1 ? NL80211_PS_ENABLED : NL80211_PS_DISABLED;
285 if (nl80211_sta_set_power_save(dut, intf, ps_state) == 0)
286 return 0;
287#endif /* NL80211_SUPPORT */
Vinita S. Malooa8b62722020-04-23 01:45:41 +0530288
289 snprintf(buf, sizeof(buf), "iwpriv %s setPower %d", intf, ps);
290 if (system(buf) != 0) {
291 sigma_dut_print(dut, DUT_MSG_ERROR,
292 "iwpriv setPower %d failed", ps);
293 return -1;
294 }
295 return 0;
296}
297
298
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200299int set_ps(const char *intf, struct sigma_dut *dut, int enabled)
300{
301#ifdef __linux__
302 char buf[100];
303
304 if (wifi_chip_type == DRIVER_WCN) {
305 if (enabled) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +0530306 if (set_power_save_wcn(dut, intf, 1) < 0) {
Purushottam Kushwaha304561d2019-12-23 16:57:18 +0530307 snprintf(buf, sizeof(buf),
308 "iwpriv wlan0 dump 906");
309 if (system(buf) != 0)
310 goto set_power_save;
311 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200312 } else {
Vinita S. Malooa8b62722020-04-23 01:45:41 +0530313 if (set_power_save_wcn(dut, intf, 2) < 0) {
Purushottam Kushwaha304561d2019-12-23 16:57:18 +0530314 snprintf(buf, sizeof(buf),
315 "iwpriv wlan0 dump 905");
316 if (system(buf) != 0)
317 goto set_power_save;
318 snprintf(buf, sizeof(buf),
319 "iwpriv wlan0 dump 912");
320 if (system(buf) != 0)
321 goto set_power_save;
322 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200323 }
324
325 return 0;
326 }
327
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530328set_power_save:
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200329 snprintf(buf, sizeof(buf), "./iw dev %s set power_save %s",
330 intf, enabled ? "on" : "off");
331 if (system(buf) != 0) {
332 snprintf(buf, sizeof(buf), "iw dev %s set power_save %s",
333 intf, enabled ? "on" : "off");
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530334 if (system(buf) != 0) {
335 sigma_dut_print(dut, DUT_MSG_ERROR,
336 "Failed to set power save %s",
337 enabled ? "on" : "off");
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200338 return -1;
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530339 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200340 }
341
342 return 0;
343#else /* __linux__ */
344 return -1;
345#endif /* __linux__ */
346}
347
348
Lior Davidcc88b562017-01-03 18:52:09 +0200349#ifdef __linux__
Lior David0fe101e2017-03-09 16:09:50 +0200350
Lior Davidcc88b562017-01-03 18:52:09 +0200351static int wil6210_get_debugfs_dir(struct sigma_dut *dut, char *path,
352 size_t len)
353{
354 DIR *dir, *wil_dir;
355 struct dirent *entry;
356 int ret = -1;
357 const char *root_path = "/sys/kernel/debug/ieee80211";
358
359 dir = opendir(root_path);
360 if (!dir)
361 return -2;
362
363 while ((entry = readdir(dir))) {
364 if (strcmp(entry->d_name, ".") == 0 ||
365 strcmp(entry->d_name, "..") == 0)
366 continue;
367
368 if (snprintf(path, len, "%s/%s/wil6210",
369 root_path, entry->d_name) >= (int) len) {
370 ret = -3;
371 break;
372 }
373
374 wil_dir = opendir(path);
375 if (wil_dir) {
376 closedir(wil_dir);
377 ret = 0;
378 break;
379 }
380 }
381
382 closedir(dir);
383 return ret;
384}
Lior David0fe101e2017-03-09 16:09:50 +0200385
386
387static int wil6210_wmi_send(struct sigma_dut *dut, uint16_t command,
388 void *payload, uint16_t length)
389{
390 struct {
391 struct wil_wmi_header hdr;
392 char payload[WIL_WMI_MAX_PAYLOAD];
393 } __attribute__((packed)) cmd;
394 char buf[128], fname[128];
395 size_t towrite, written;
396 FILE *f;
Jouni Malinen3aa72862019-05-29 23:14:51 +0300397 int res;
Lior David0fe101e2017-03-09 16:09:50 +0200398
399 if (length > WIL_WMI_MAX_PAYLOAD) {
400 sigma_dut_print(dut, DUT_MSG_ERROR,
401 "payload too large(%u, max %u)",
402 length, WIL_WMI_MAX_PAYLOAD);
403 return -1;
404 }
405
406 memset(&cmd.hdr, 0, sizeof(cmd.hdr));
407 cmd.hdr.cmd = command;
408 memcpy(cmd.payload, payload, length);
409
410 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
411 sigma_dut_print(dut, DUT_MSG_ERROR,
412 "failed to get wil6210 debugfs dir");
413 return -1;
414 }
415
Jouni Malinen3aa72862019-05-29 23:14:51 +0300416 res = snprintf(fname, sizeof(fname), "%s/wmi_send", buf);
417 if (res < 0 || res >= sizeof(fname))
418 return -1;
Lior David0fe101e2017-03-09 16:09:50 +0200419 f = fopen(fname, "wb");
420 if (!f) {
421 sigma_dut_print(dut, DUT_MSG_ERROR,
422 "failed to open: %s", fname);
423 return -1;
424 }
425
426 towrite = sizeof(cmd.hdr) + length;
427 written = fwrite(&cmd, 1, towrite, f);
428 fclose(f);
429 if (written != towrite) {
430 sigma_dut_print(dut, DUT_MSG_ERROR,
431 "failed to send wmi %u", command);
432 return -1;
433 }
434
435 return 0;
436}
437
438
439static int wil6210_get_sta_info_field(struct sigma_dut *dut, const char *bssid,
440 const char *pattern, unsigned int *field)
441{
442 char buf[128], fname[128];
443 FILE *f;
444 regex_t re;
445 regmatch_t m[2];
Jouni Malinen3aa72862019-05-29 23:14:51 +0300446 int rc, ret = -1, res;
Lior David0fe101e2017-03-09 16:09:50 +0200447
448 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
449 sigma_dut_print(dut, DUT_MSG_ERROR,
450 "failed to get wil6210 debugfs dir");
451 return -1;
452 }
453
Jouni Malinen3aa72862019-05-29 23:14:51 +0300454 res = snprintf(fname, sizeof(fname), "%s/stations", buf);
455 if (res < 0 || res >= sizeof(fname))
456 return -1;
Lior David0fe101e2017-03-09 16:09:50 +0200457 f = fopen(fname, "r");
458 if (!f) {
459 sigma_dut_print(dut, DUT_MSG_ERROR,
460 "failed to open: %s", fname);
461 return -1;
462 }
463
464 if (regcomp(&re, pattern, REG_EXTENDED)) {
465 sigma_dut_print(dut, DUT_MSG_ERROR,
466 "regcomp failed: %s", pattern);
467 goto out;
468 }
469
470 /*
471 * find the entry for the mac address
472 * line is of the form: [n] 11:22:33:44:55:66 state AID aid
473 */
474 while (fgets(buf, sizeof(buf), f)) {
475 if (strcasestr(buf, bssid)) {
476 /* extract the field (CID/AID/state) */
477 rc = regexec(&re, buf, 2, m, 0);
478 if (!rc && (m[1].rm_so >= 0)) {
479 buf[m[1].rm_eo] = 0;
480 *field = atoi(&buf[m[1].rm_so]);
481 ret = 0;
482 break;
483 }
484 }
485 }
486
487 regfree(&re);
488 if (ret)
489 sigma_dut_print(dut, DUT_MSG_ERROR,
490 "could not extract field");
491
492out:
493 fclose(f);
494
495 return ret;
496}
497
498
499static int wil6210_get_cid(struct sigma_dut *dut, const char *bssid,
500 unsigned int *cid)
501{
502 const char *pattern = "\\[([0-9]+)\\]";
503
504 return wil6210_get_sta_info_field(dut, bssid, pattern, cid);
505}
506
507
508static int wil6210_send_brp_rx(struct sigma_dut *dut, const char *mac,
509 int l_rx)
510{
Rakesh Sunki556237d2017-03-30 14:49:31 -0700511 struct wil_wmi_bf_trig_cmd cmd;
Lior David0fe101e2017-03-09 16:09:50 +0200512 unsigned int cid;
513
Rakesh Sunki556237d2017-03-30 14:49:31 -0700514 memset(&cmd, 0, sizeof(cmd));
515
Lior David0fe101e2017-03-09 16:09:50 +0200516 if (wil6210_get_cid(dut, mac, &cid))
517 return -1;
518
519 cmd.bf_type = WIL_WMI_BRP_RX;
520 cmd.sta_id = cid;
521 /* training length (l_rx) is ignored, FW always uses length 16 */
522 return wil6210_wmi_send(dut, WIL_WMI_BF_TRIG_CMDID,
523 &cmd, sizeof(cmd));
524}
525
526
527static int wil6210_send_sls(struct sigma_dut *dut, const char *mac)
528{
Rakesh Sunki556237d2017-03-30 14:49:31 -0700529 struct wil_wmi_bf_trig_cmd cmd;
530
531 memset(&cmd, 0, sizeof(cmd));
Lior David0fe101e2017-03-09 16:09:50 +0200532
533 if (parse_mac_address(dut, mac, (unsigned char *)&cmd.dest_mac))
534 return -1;
535
536 cmd.bf_type = WIL_WMI_SLS;
537 return wil6210_wmi_send(dut, WIL_WMI_BF_TRIG_CMDID,
538 &cmd, sizeof(cmd));
539}
540
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +0200541
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +0200542int wil6210_set_ese(struct sigma_dut *dut, int count,
543 struct sigma_ese_alloc *allocs)
544{
545 struct wil_wmi_ese_cfg cmd = { };
546 int i;
547
548 if (count == 0 || count > WIL_WMI_MAX_ESE_SLOTS)
549 return -1;
550
551 if (dut->ap_bcnint <= 0) {
552 sigma_dut_print(dut, DUT_MSG_ERROR,
553 "invalid beacon interval(%d), check test",
554 dut->ap_bcnint);
555 return -1;
556 }
557
558 cmd.ese_advertisment = WIL_WMI_ADVERTISE_ESE_IN_BEACON;
559 cmd.flags = 0x1d;
560 cmd.num_allocs = count;
561 for (i = 0; i < count; i++) {
562 /*
563 * Convert percent from BI (BI specified in milliseconds)
564 * to absolute duration in microseconds.
565 */
566 cmd.slots[i].duration =
567 (allocs[i].percent_bi * dut->ap_bcnint * 1000) / 100;
568 switch (allocs[i].type) {
569 case ESE_CBAP:
570 cmd.slots[i].slot_type = WIL_WMI_ESE_CBAP;
571 break;
572 case ESE_SP:
573 cmd.slots[i].slot_type = WIL_WMI_ESE_SP;
574 break;
575 default:
576 sigma_dut_print(dut, DUT_MSG_ERROR,
577 "invalid slot type(%d) at index %d",
578 allocs[i].type, i);
579 return -1;
580 }
581 cmd.slots[i].src_aid = allocs[i].src_aid;
582 cmd.slots[i].dst_aid = allocs[i].dst_aid;
583 sigma_dut_print(dut, DUT_MSG_INFO,
584 "slot %d, duration %u, type %d, srcAID %u dstAID %u",
585 i, cmd.slots[i].duration,
586 cmd.slots[i].slot_type, cmd.slots[i].src_aid,
587 cmd.slots[i].dst_aid);
588 }
589
590 return wil6210_wmi_send(dut, WIL_WMI_ESE_CFG_CMDID, &cmd, sizeof(cmd));
591}
592
593
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +0200594int wil6210_set_force_mcs(struct sigma_dut *dut, int force, int mcs)
595{
596 struct wil_wmi_force_mcs cmd = { };
597
598 cmd.module_id = WIL_WMI_UT_HW_SYSAPI;
599 cmd.subtype_id = WIL_WMI_UT_FORCE_MCS;
600 cmd.force_enable = (uint32_t) force;
601 cmd.mcs = (uint32_t) mcs;
602
603 return wil6210_wmi_send(dut, WIL_WMI_UNIT_TEST_CMDID,
604 &cmd, sizeof(cmd));
605}
606
607
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +0200608static int wil6210_force_rsn_ie(struct sigma_dut *dut, int state)
609{
610 struct wil_wmi_force_rsn_ie cmd = { };
611
612 cmd.module_id = WIL_WMI_UT_HW_SYSAPI;
613 cmd.subtype_id = WIL_WMI_UT_FORCE_RSN_IE;
614 cmd.state = (uint32_t) state;
615
616 return wil6210_wmi_send(dut, WIL_WMI_UNIT_TEST_CMDID,
617 &cmd, sizeof(cmd));
618}
619
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +0300620
621/*
622 * this function is also used to configure generic remain-on-channel
623 */
624static int wil6210_p2p_cfg(struct sigma_dut *dut, int freq)
625{
626 struct wil_wmi_p2p_cfg_cmd cmd = { };
627 int channel = freq_to_channel(freq);
628
629 if (channel < 0)
630 return -1;
631 cmd.discovery_mode = WMI_DISCOVERY_MODE_NON_OFFLOAD;
632 cmd.channel = channel - 1;
633 cmd.bcon_interval = WIL_DEFAULT_BI;
634 cmd.discovery_mode = WMI_DISCOVERY_MODE_PEER2PEER;
635
636 return wil6210_wmi_send(dut, WIL_WMI_P2P_CFG_CMDID,
637 &cmd, sizeof(cmd));
638}
639
640
641static int wil6210_remain_on_channel(struct sigma_dut *dut, int freq)
642{
643 int ret = wil6210_p2p_cfg(dut, freq);
644
645 if (ret)
646 return ret;
647
648 ret = wil6210_wmi_send(dut, WIL_WMI_START_LISTEN_CMDID, NULL, 0);
649 if (!ret) {
650 /*
651 * wait a bit to allow FW to setup the radio
652 * especially important if we switch channels
653 */
654 usleep(500000);
655 }
656
657 return ret;
658}
659
660
661static int wil6210_stop_discovery(struct sigma_dut *dut)
662{
663 return wil6210_wmi_send(dut, WIL_WMI_DISCOVERY_STOP_CMDID, NULL, 0);
664}
665
666
667static int wil6210_transmit_frame(struct sigma_dut *dut, int freq,
668 int wait_duration,
669 const char *frame, size_t frame_len)
670{
671 char buf[128], fname[128];
672 FILE *f;
Jouni Malinen3aa72862019-05-29 23:14:51 +0300673 int res = 0, r;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +0300674 size_t written;
675
676 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
677 sigma_dut_print(dut, DUT_MSG_ERROR,
678 "failed to get wil6210 debugfs dir");
679 return -1;
680 }
Jouni Malinen3aa72862019-05-29 23:14:51 +0300681 r = snprintf(fname, sizeof(fname), "%s/tx_mgmt", buf);
682 if (r < 0 || r >= sizeof(fname))
683 return -1;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +0300684
685 if (wil6210_remain_on_channel(dut, freq)) {
686 sigma_dut_print(dut, DUT_MSG_ERROR,
687 "failed to listen on channel");
688 return -1;
689 }
690
691 f = fopen(fname, "wb");
692 if (!f) {
693 sigma_dut_print(dut, DUT_MSG_ERROR,
694 "failed to open: %s", fname);
695 res = -1;
696 goto out_stop;
697 }
698 written = fwrite(frame, 1, frame_len, f);
699 fclose(f);
700
701 if (written != frame_len) {
702 sigma_dut_print(dut, DUT_MSG_ERROR,
703 "failed to transmit frame (got %zd, expected %zd)",
704 written, frame_len);
705 res = -1;
706 goto out_stop;
707 }
708
709 usleep(wait_duration * 1000);
710
711out_stop:
712 wil6210_stop_discovery(dut);
713 return res;
714}
715
716
717static int find_template_frame_tag(struct template_frame_tag *tags,
718 int total_tags, int tag_num)
719{
720 int i;
721
722 for (i = 0; i < total_tags; i++) {
723 if (tag_num == tags[i].num)
724 return i;
725 }
726
727 return -1;
728}
729
730
731static int replace_p2p_attribute(struct sigma_dut *dut, char *buf, size_t len,
732 int id, const char *value, size_t val_len)
733{
734 struct wfa_p2p_attribute *attr = (struct wfa_p2p_attribute *) buf;
735
736 if (len < 3 + val_len) {
737 sigma_dut_print(dut, DUT_MSG_ERROR,
738 "not enough space to replace P2P attribute");
739 return -1;
740 }
741
742 if (attr->len != val_len) {
743 sigma_dut_print(dut, DUT_MSG_ERROR,
744 "attribute length mismatch (need %zu have %hu)",
745 val_len, attr->len);
746 return -1;
747 }
748
749 if (attr->id != id) {
750 sigma_dut_print(dut, DUT_MSG_ERROR,
751 "incorrect attribute id (expected %d actual %d)",
752 id, attr->id);
753 return -1;
754 }
755
756 memcpy(attr->variable, value, val_len);
757
758 return 0;
759}
760
761
762static int parse_template_frame_file(struct sigma_dut *dut, const char *fname,
763 char *buf, size_t *length,
764 struct template_frame_tag *tags,
765 size_t *num_tags)
766{
767 char line[512];
768 FILE *f;
769 size_t offset = 0, tag_index = 0;
770 int num, index;
771 int in_tag = 0, tag_num = 0, tag_offset = 0;
772
773 if (*length < sizeof(struct ieee80211_hdr_3addr)) {
774 sigma_dut_print(dut, DUT_MSG_ERROR,
775 "supplied buffer is too small");
776 return -1;
777 }
778
779 f = fopen(fname, "r");
780 if (!f) {
781 sigma_dut_print(dut, DUT_MSG_ERROR,
782 "failed to open template file %s", fname);
783 return -1;
784 }
785
786 /*
787 * template file format: lines beginning with # are comments and
788 * ignored.
789 * It is possible to tag bytes in the frame to make it easy
790 * to replace fields in the template, espcially if they appear
791 * in variable-sized sections (such as IEs)
792 * This is done by a line beginning with $NUM where NUM is an integer
793 * tag number. It can be followed by space(s) and comment.
794 * The next line is considered the tagged bytes. The parser will fill
795 * the tag number, offset and length of the tagged bytes.
796 * rest of the lines contain frame bytes as sequence of hex digits,
797 * 2 digits for each byte. Spaces are allowed between bytes.
798 * On bytes lines only hex digits and spaces are allowed
799 */
800 while (!feof(f)) {
801 if (!fgets(line, sizeof(line), f))
802 break;
803 index = 0;
804 while (isspace((unsigned char) line[index]))
805 index++;
806 if (!line[index] || line[index] == '#')
807 continue;
808 if (line[index] == '$') {
809 if (tags) {
810 index++;
811 tag_num = strtol(&line[index], NULL, 0);
812 tag_offset = offset;
813 in_tag = 1;
814 }
815 continue;
816 }
817 while (line[index]) {
818 if (isspace((unsigned char) line[index])) {
819 index++;
820 continue;
821 }
822 num = hex_byte(&line[index]);
823 if (num < 0)
824 break;
825 buf[offset++] = num;
826 if (offset == *length)
827 goto out;
828 index += 2;
829 }
830
831 if (in_tag) {
832 if (tag_index < *num_tags) {
833 tags[tag_index].num = tag_num;
834 tags[tag_index].offset = tag_offset;
835 tags[tag_index].len = offset - tag_offset;
836 tag_index++;
837 } else {
838 sigma_dut_print(dut, DUT_MSG_INFO,
839 "too many tags, tag ignored");
840 }
841 in_tag = 0;
842 }
843 }
844
845 if (num_tags)
846 *num_tags = tag_index;
847out:
848 fclose(f);
849 if (offset < sizeof(struct ieee80211_hdr_3addr)) {
850 sigma_dut_print(dut, DUT_MSG_ERROR,
851 "template frame is too small");
852 return -1;
853 }
854
855 *length = offset;
856 return 0;
857}
858
Lior Davidcc88b562017-01-03 18:52:09 +0200859#endif /* __linux__ */
860
861
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200862static void static_ip_file(int proto, const char *addr, const char *mask,
863 const char *gw)
864{
865 if (proto) {
866 FILE *f = fopen("static-ip", "w");
867 if (f) {
868 fprintf(f, "%d %s %s %s\n", proto, addr,
869 mask ? mask : "N/A",
870 gw ? gw : "N/A");
871 fclose(f);
872 }
873 } else {
874 unlink("static-ip");
875 }
876}
877
878
879static int send_neighbor_request(struct sigma_dut *dut, const char *intf,
880 const char *ssid)
881{
882#ifdef __linux__
883 char buf[100];
884
885 snprintf(buf, sizeof(buf), "iwpriv %s neighbor %s",
886 intf, ssid);
887 sigma_dut_print(dut, DUT_MSG_INFO, "Request: %s", buf);
888
889 if (system(buf) != 0) {
890 sigma_dut_print(dut, DUT_MSG_ERROR,
891 "iwpriv neighbor request failed");
892 return -1;
893 }
894
895 sigma_dut_print(dut, DUT_MSG_INFO, "iwpriv neighbor request send");
896
897 return 0;
898#else /* __linux__ */
899 return -1;
900#endif /* __linux__ */
901}
902
903
904static int send_trans_mgmt_query(struct sigma_dut *dut, const char *intf,
Ashwini Patil5acd7382017-04-13 15:55:04 +0530905 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200906{
Ashwini Patil5acd7382017-04-13 15:55:04 +0530907 const char *val;
908 int reason_code = 0;
909 char buf[1024];
910
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200911 /*
912 * In the earlier builds we used WNM_QUERY and in later
913 * builds used WNM_BSS_QUERY.
914 */
915
Ashwini Patil5acd7382017-04-13 15:55:04 +0530916 val = get_param(cmd, "BTMQuery_Reason_Code");
917 if (val)
918 reason_code = atoi(val);
919
920 val = get_param(cmd, "Cand_List");
921 if (val && atoi(val) == 1 && dut->btm_query_cand_list) {
922 snprintf(buf, sizeof(buf), "WNM_BSS_QUERY %d%s", reason_code,
923 dut->btm_query_cand_list);
924 free(dut->btm_query_cand_list);
925 dut->btm_query_cand_list = NULL;
926 } else {
927 snprintf(buf, sizeof(buf), "WNM_BSS_QUERY %d", reason_code);
928 }
929
930 if (wpa_command(intf, buf) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200931 sigma_dut_print(dut, DUT_MSG_ERROR,
932 "transition management query failed");
933 return -1;
934 }
935
936 sigma_dut_print(dut, DUT_MSG_DEBUG,
937 "transition management query sent");
938
939 return 0;
940}
941
942
943int is_ip_addr(const char *str)
944{
945 const char *pos = str;
946 struct in_addr addr;
947
948 while (*pos) {
949 if (*pos != '.' && (*pos < '0' || *pos > '9'))
950 return 0;
951 pos++;
952 }
953
954 return inet_aton(str, &addr);
955}
956
957
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200958int get_ip_config(struct sigma_dut *dut, const char *ifname, char *buf,
959 size_t buf_len)
960{
vamsi krishnaa11d0732018-05-16 12:19:48 +0530961 char tmp[256];
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200962 char ip[16], mask[15], dns[16], sec_dns[16];
963 int is_dhcp = 0;
964 int s;
965#ifdef ANDROID
966 char prop[PROPERTY_VALUE_MAX];
vamsi krishnaa11d0732018-05-16 12:19:48 +0530967#else /* ANDROID */
968 FILE *f;
969#ifdef __linux__
970 const char *str_ps;
971#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200972#endif /* ANDROID */
973
974 ip[0] = '\0';
975 mask[0] = '\0';
976 dns[0] = '\0';
977 sec_dns[0] = '\0';
978
979 s = socket(PF_INET, SOCK_DGRAM, 0);
980 if (s >= 0) {
981 struct ifreq ifr;
982 struct sockaddr_in saddr;
983
984 memset(&ifr, 0, sizeof(ifr));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700985 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200986 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
987 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get "
988 "%s IP address: %s",
989 ifname, strerror(errno));
990 } else {
991 memcpy(&saddr, &ifr.ifr_addr,
992 sizeof(struct sockaddr_in));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700993 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200994 }
995
996 if (ioctl(s, SIOCGIFNETMASK, &ifr) == 0) {
997 memcpy(&saddr, &ifr.ifr_addr,
998 sizeof(struct sockaddr_in));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700999 strlcpy(mask, inet_ntoa(saddr.sin_addr), sizeof(mask));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001000 }
1001 close(s);
1002 }
1003
1004#ifdef ANDROID
1005 snprintf(tmp, sizeof(tmp), "dhcp.%s.pid", ifname);
1006 if (property_get(tmp, prop, NULL) != 0 && atoi(prop) > 0) {
1007 snprintf(tmp, sizeof(tmp), "dhcp.%s.result", ifname);
1008 if (property_get(tmp, prop, NULL) != 0 &&
1009 strcmp(prop, "ok") == 0) {
1010 snprintf(tmp, sizeof(tmp), "dhcp.%s.ipaddress",
1011 ifname);
1012 if (property_get(tmp, prop, NULL) != 0 &&
1013 strcmp(ip, prop) == 0)
1014 is_dhcp = 1;
1015 }
1016 }
1017
1018 snprintf(tmp, sizeof(tmp), "dhcp.%s.dns1", ifname);
Peng Xub8fc5cc2017-05-10 17:27:28 -07001019 if (property_get(tmp, prop, NULL) != 0)
1020 strlcpy(dns, prop, sizeof(dns));
1021 else if (property_get("net.dns1", prop, NULL) != 0)
1022 strlcpy(dns, prop, sizeof(dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001023
1024 snprintf(tmp, sizeof(tmp), "dhcp.%s.dns2", ifname);
Peng Xub8fc5cc2017-05-10 17:27:28 -07001025 if (property_get(tmp, prop, NULL) != 0)
1026 strlcpy(sec_dns, prop, sizeof(sec_dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001027#else /* ANDROID */
1028#ifdef __linux__
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001029 if (get_driver_type(dut) == DRIVER_OPENWRT)
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +05301030 str_ps = "ps -w";
1031 else
1032 str_ps = "ps ax";
1033 snprintf(tmp, sizeof(tmp),
1034 "%s | grep dhclient | grep -v grep | grep -q %s",
1035 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001036 if (system(tmp) == 0)
1037 is_dhcp = 1;
1038 else {
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +05301039 snprintf(tmp, sizeof(tmp),
1040 "%s | grep udhcpc | grep -v grep | grep -q %s",
1041 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001042 if (system(tmp) == 0)
1043 is_dhcp = 1;
1044 else {
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +05301045 snprintf(tmp, sizeof(tmp),
1046 "%s | grep dhcpcd | grep -v grep | grep -q %s",
1047 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001048 if (system(tmp) == 0)
1049 is_dhcp = 1;
1050 }
1051 }
1052#endif /* __linux__ */
1053
1054 f = fopen("/etc/resolv.conf", "r");
1055 if (f) {
vamsi krishnaa11d0732018-05-16 12:19:48 +05301056 char *pos, *pos2;
1057
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001058 while (fgets(tmp, sizeof(tmp), f)) {
1059 if (strncmp(tmp, "nameserver", 10) != 0)
1060 continue;
1061 pos = tmp + 10;
1062 while (*pos == ' ' || *pos == '\t')
1063 pos++;
1064 pos2 = pos;
1065 while (*pos2) {
1066 if (*pos2 == '\n' || *pos2 == '\r') {
1067 *pos2 = '\0';
1068 break;
1069 }
1070 pos2++;
1071 }
Peng Xub8fc5cc2017-05-10 17:27:28 -07001072 if (!dns[0])
1073 strlcpy(dns, pos, sizeof(dns));
1074 else if (!sec_dns[0])
1075 strlcpy(sec_dns, pos, sizeof(sec_dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001076 }
1077 fclose(f);
1078 }
1079#endif /* ANDROID */
1080
1081 snprintf(buf, buf_len, "dhcp,%d,ip,%s,mask,%s,primary-dns,%s",
1082 is_dhcp, ip, mask, dns);
1083 buf[buf_len - 1] = '\0';
1084
1085 return 0;
1086}
1087
1088
1089
1090
1091int get_ipv6_config(struct sigma_dut *dut, const char *ifname, char *buf,
1092 size_t buf_len)
1093{
1094#ifdef __linux__
1095#ifdef ANDROID
1096 char cmd[200], result[1000], *pos, *end;
1097 FILE *f;
1098 size_t len;
1099
1100 snprintf(cmd, sizeof(cmd), "ip addr show dev %s scope global", ifname);
1101 f = popen(cmd, "r");
1102 if (f == NULL)
1103 return -1;
1104 len = fread(result, 1, sizeof(result) - 1, f);
1105 pclose(f);
1106 if (len == 0)
1107 return -1;
1108 result[len] = '\0';
1109 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s result: %s\n", cmd, result);
1110
1111 pos = strstr(result, "inet6 ");
1112 if (pos == NULL)
1113 return -1;
1114 pos += 6;
1115 end = strchr(pos, ' ');
1116 if (end)
1117 *end = '\0';
1118 end = strchr(pos, '/');
1119 if (end)
1120 *end = '\0';
1121 snprintf(buf, buf_len, "ip,%s", pos);
1122 buf[buf_len - 1] = '\0';
1123 return 0;
1124#else /* ANDROID */
1125 struct ifaddrs *ifaddr, *ifa;
1126 int res, found = 0;
1127 char host[NI_MAXHOST];
1128
1129 if (getifaddrs(&ifaddr) < 0) {
1130 perror("getifaddrs");
1131 return -1;
1132 }
1133
1134 for (ifa = ifaddr; ifa; ifa = ifa->ifa_next) {
1135 if (strcasecmp(ifname, ifa->ifa_name) != 0)
1136 continue;
1137 if (ifa->ifa_addr == NULL ||
1138 ifa->ifa_addr->sa_family != AF_INET6)
1139 continue;
1140
1141 res = getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in6),
1142 host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
1143 if (res != 0) {
1144 sigma_dut_print(dut, DUT_MSG_DEBUG, "getnameinfo: %s",
1145 gai_strerror(res));
1146 continue;
1147 }
1148 if (strncmp(host, "fe80::", 6) == 0)
1149 continue; /* skip link-local */
1150
1151 sigma_dut_print(dut, DUT_MSG_DEBUG, "ifaddr: %s", host);
1152 found = 1;
1153 break;
1154 }
1155
1156 freeifaddrs(ifaddr);
1157
1158 if (found) {
1159 char *pos;
1160 pos = strchr(host, '%');
1161 if (pos)
1162 *pos = '\0';
1163 snprintf(buf, buf_len, "ip,%s", host);
1164 buf[buf_len - 1] = '\0';
1165 return 0;
1166 }
1167
1168#endif /* ANDROID */
1169#endif /* __linux__ */
1170 return -1;
1171}
1172
1173
Jouni Malinenf7222712019-06-13 01:50:21 +03001174static enum sigma_cmd_result cmd_sta_get_ip_config(struct sigma_dut *dut,
1175 struct sigma_conn *conn,
1176 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001177{
1178 const char *intf = get_param(cmd, "Interface");
1179 const char *ifname;
1180 char buf[200];
1181 const char *val;
1182 int type = 1;
1183
1184 if (intf == NULL)
1185 return -1;
1186
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001187 if (strcmp(intf, get_main_ifname(dut)) == 0)
1188 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001189 else
1190 ifname = intf;
1191
1192 /*
1193 * UCC may assume the IP address to be available immediately after
1194 * association without trying to run sta_get_ip_config multiple times.
1195 * Sigma CAPI does not specify this command as a block command that
1196 * would wait for the address to become available, but to pass tests
1197 * more reliably, it looks like such a wait may be needed here.
1198 */
1199 if (wait_ip_addr(dut, ifname, 15) < 0) {
1200 sigma_dut_print(dut, DUT_MSG_INFO, "Could not get IP address "
1201 "for sta_get_ip_config");
1202 /*
1203 * Try to continue anyway since many UCC tests do not really
1204 * care about the return value from here..
1205 */
1206 }
1207
1208 val = get_param(cmd, "Type");
1209 if (val)
1210 type = atoi(val);
1211 if (type == 2 || dut->last_set_ip_config_ipv6) {
1212 int i;
1213
1214 /*
1215 * Since we do not have proper wait for IPv6 addresses, use a
1216 * fixed two second delay here as a workaround for UCC script
1217 * assuming IPv6 address is available when this command returns.
1218 * Some scripts did not use Type,2 properly for IPv6, so include
1219 * also the cases where the previous sta_set_ip_config indicated
1220 * use of IPv6.
1221 */
1222 sigma_dut_print(dut, DUT_MSG_INFO, "Wait up to extra ten seconds in sta_get_ip_config for IPv6 address");
1223 for (i = 0; i < 10; i++) {
1224 sleep(1);
1225 if (get_ipv6_config(dut, ifname, buf, sizeof(buf)) == 0)
1226 {
1227 sigma_dut_print(dut, DUT_MSG_INFO, "Found IPv6 address");
1228 send_resp(dut, conn, SIGMA_COMPLETE, buf);
1229#ifdef ANDROID
1230 sigma_dut_print(dut, DUT_MSG_INFO,
1231 "Adding IPv6 rule on Android");
1232 add_ipv6_rule(dut, intf);
1233#endif /* ANDROID */
1234
1235 return 0;
1236 }
1237 }
1238 }
1239 if (type == 1) {
1240 if (get_ip_config(dut, ifname, buf, sizeof(buf)) < 0)
1241 return -2;
1242 } else if (type == 2) {
1243 if (get_ipv6_config(dut, ifname, buf, sizeof(buf)) < 0)
1244 return -2;
1245 } else {
1246 send_resp(dut, conn, SIGMA_ERROR,
1247 "errorCode,Unsupported address type");
1248 return 0;
1249 }
1250
1251 send_resp(dut, conn, SIGMA_COMPLETE, buf);
1252 return 0;
1253}
1254
1255
1256static void kill_dhcp_client(struct sigma_dut *dut, const char *ifname)
1257{
1258#ifdef __linux__
1259 char buf[200];
1260 char path[128];
1261 struct stat s;
1262
1263#ifdef ANDROID
1264 snprintf(path, sizeof(path), "/data/misc/dhcp/dhcpcd-%s.pid", ifname);
1265#else /* ANDROID */
1266 snprintf(path, sizeof(path), "/var/run/dhclient-%s.pid", ifname);
1267#endif /* ANDROID */
1268 if (stat(path, &s) == 0) {
1269 snprintf(buf, sizeof(buf), "kill `cat %s`", path);
1270 sigma_dut_print(dut, DUT_MSG_INFO,
1271 "Kill previous DHCP client: %s", buf);
1272 if (system(buf) != 0)
1273 sigma_dut_print(dut, DUT_MSG_INFO,
1274 "Failed to kill DHCP client");
1275 unlink(path);
1276 sleep(1);
1277 } else {
1278 snprintf(path, sizeof(path), "/var/run/dhcpcd-%s.pid", ifname);
1279
1280 if (stat(path, &s) == 0) {
1281 snprintf(buf, sizeof(buf), "kill `cat %s`", path);
1282 sigma_dut_print(dut, DUT_MSG_INFO,
1283 "Kill previous DHCP client: %s", buf);
1284 if (system(buf) != 0)
1285 sigma_dut_print(dut, DUT_MSG_INFO,
1286 "Failed to kill DHCP client");
1287 unlink(path);
1288 sleep(1);
1289 }
1290 }
1291#endif /* __linux__ */
1292}
1293
1294
1295static int start_dhcp_client(struct sigma_dut *dut, const char *ifname)
1296{
1297#ifdef __linux__
1298 char buf[200];
1299
1300#ifdef ANDROID
Purushottam Kushwaha46d64262016-08-23 17:57:53 +05301301 if (access("/system/bin/dhcpcd", F_OK) != -1) {
1302 snprintf(buf, sizeof(buf),
1303 "/system/bin/dhcpcd -b %s", ifname);
1304 } else if (access("/system/bin/dhcptool", F_OK) != -1) {
1305 snprintf(buf, sizeof(buf), "/system/bin/dhcptool %s &", ifname);
Ankita Bajaj8454e5d2019-04-05 16:04:55 +05301306 } else if (access("/vendor/bin/dhcpcd", F_OK) != -1) {
1307 snprintf(buf, sizeof(buf), "/vendor/bin/dhcpcd -b %s", ifname);
1308 } else if (access("/vendor/bin/dhcptool", F_OK) != -1) {
1309 snprintf(buf, sizeof(buf), "/vendor/bin/dhcptool %s", ifname);
Purushottam Kushwaha46d64262016-08-23 17:57:53 +05301310 } else {
1311 sigma_dut_print(dut, DUT_MSG_ERROR,
1312 "DHCP client program missing");
1313 return 0;
1314 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001315#else /* ANDROID */
1316 snprintf(buf, sizeof(buf),
1317 "dhclient -nw -pf /var/run/dhclient-%s.pid %s",
1318 ifname, ifname);
1319#endif /* ANDROID */
1320 sigma_dut_print(dut, DUT_MSG_INFO, "Start DHCP client: %s", buf);
1321 if (system(buf) != 0) {
1322 snprintf(buf, sizeof(buf), "dhcpcd -t 0 %s &", ifname);
1323 if (system(buf) != 0) {
1324 sigma_dut_print(dut, DUT_MSG_INFO,
1325 "Failed to start DHCP client");
1326#ifndef ANDROID
1327 return -1;
1328#endif /* ANDROID */
1329 }
1330 }
1331#endif /* __linux__ */
1332
1333 return 0;
1334}
1335
1336
1337static int clear_ip_addr(struct sigma_dut *dut, const char *ifname)
1338{
1339#ifdef __linux__
1340 char buf[200];
1341
1342 snprintf(buf, sizeof(buf), "ip addr flush dev %s", ifname);
1343 if (system(buf) != 0) {
1344 sigma_dut_print(dut, DUT_MSG_INFO,
1345 "Failed to clear IP addresses");
1346 return -1;
1347 }
1348#endif /* __linux__ */
1349
1350 return 0;
1351}
1352
1353
1354#ifdef ANDROID
1355static int add_ipv6_rule(struct sigma_dut *dut, const char *ifname)
1356{
1357 char cmd[200], *result, *pos;
1358 FILE *fp;
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +05301359 int tableid;
1360 size_t len, result_len = 1000;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001361
1362 snprintf(cmd, sizeof(cmd), "ip -6 route list table all | grep %s",
1363 ifname);
1364 fp = popen(cmd, "r");
1365 if (fp == NULL)
1366 return -1;
1367
1368 result = malloc(result_len);
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05301369 if (result == NULL) {
1370 fclose(fp);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001371 return -1;
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05301372 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001373
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +05301374 len = fread(result, 1, result_len - 1, fp);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001375 fclose(fp);
1376
1377 if (len == 0) {
1378 free(result);
1379 return -1;
1380 }
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +05301381 result[len] = '\0';
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001382
1383 pos = strstr(result, "table ");
1384 if (pos == NULL) {
1385 free(result);
1386 return -1;
1387 }
1388
1389 pos += strlen("table ");
1390 tableid = atoi(pos);
1391 if (tableid != 0) {
1392 if (system("ip -6 rule del prio 22000") != 0) {
1393 /* ignore any error */
1394 }
1395 snprintf(cmd, sizeof(cmd),
1396 "ip -6 rule add from all lookup %d prio 22000",
1397 tableid);
1398 if (system(cmd) != 0) {
1399 sigma_dut_print(dut, DUT_MSG_INFO,
1400 "Failed to run %s", cmd);
1401 free(result);
1402 return -1;
1403 }
1404 } else {
1405 sigma_dut_print(dut, DUT_MSG_INFO,
1406 "No Valid Table Id found %s", pos);
1407 free(result);
1408 return -1;
1409 }
1410 free(result);
1411
1412 return 0;
1413}
1414#endif /* ANDROID */
1415
1416
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301417int set_ipv4_addr(struct sigma_dut *dut, const char *ifname,
1418 const char *ip, const char *mask)
1419{
1420 char buf[200];
1421
1422 snprintf(buf, sizeof(buf), "ifconfig %s %s netmask %s",
1423 ifname, ip, mask);
1424 return system(buf) == 0;
1425}
1426
1427
1428int set_ipv4_gw(struct sigma_dut *dut, const char *gw)
1429{
1430 char buf[200];
1431
1432 if (!is_ip_addr(gw)) {
1433 sigma_dut_print(dut, DUT_MSG_DEBUG, "Invalid gw addr - %s", gw);
1434 return -1;
1435 }
1436
1437 snprintf(buf, sizeof(buf), "route add default gw %s", gw);
1438 if (!dut->no_ip_addr_set && system(buf) != 0) {
1439 snprintf(buf, sizeof(buf), "ip ro re default via %s",
1440 gw);
1441 if (system(buf) != 0)
1442 return 0;
1443 }
1444
1445 return 1;
1446}
1447
1448
Jouni Malinenf7222712019-06-13 01:50:21 +03001449static enum sigma_cmd_result cmd_sta_set_ip_config(struct sigma_dut *dut,
1450 struct sigma_conn *conn,
1451 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001452{
1453 const char *intf = get_param(cmd, "Interface");
1454 const char *ifname;
1455 char buf[200];
1456 const char *val, *ip, *mask, *gw;
1457 int type = 1;
1458
1459 if (intf == NULL)
1460 return -1;
1461
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001462 if (strcmp(intf, get_main_ifname(dut)) == 0)
1463 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001464 else
1465 ifname = intf;
1466
1467 if (if_nametoindex(ifname) == 0) {
1468 send_resp(dut, conn, SIGMA_ERROR,
1469 "ErrorCode,Unknown interface");
1470 return 0;
1471 }
1472
1473 val = get_param(cmd, "Type");
1474 if (val) {
1475 type = atoi(val);
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301476 if (type < 1 || type > 3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001477 send_resp(dut, conn, SIGMA_ERROR,
1478 "ErrorCode,Unsupported address type");
1479 return 0;
1480 }
1481 }
1482
1483 dut->last_set_ip_config_ipv6 = 0;
1484
1485 val = get_param(cmd, "dhcp");
1486 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "true") == 0)) {
1487 static_ip_file(0, NULL, NULL, NULL);
1488#ifdef __linux__
1489 if (type == 2) {
1490 dut->last_set_ip_config_ipv6 = 1;
1491 sigma_dut_print(dut, DUT_MSG_INFO, "Using IPv6 "
1492 "stateless address autoconfiguration");
1493#ifdef ANDROID
1494 /*
1495 * This sleep is required as the assignment in case of
1496 * Android is taking time and is done by the kernel.
1497 * The subsequent ping for IPv6 is impacting HS20 test
1498 * case.
1499 */
1500 sleep(2);
1501 add_ipv6_rule(dut, intf);
1502#endif /* ANDROID */
1503 /* Assume this happens by default */
1504 return 1;
1505 }
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301506 if (type != 3) {
1507 kill_dhcp_client(dut, ifname);
1508 if (start_dhcp_client(dut, ifname) < 0)
1509 return -2;
1510 } else {
1511 sigma_dut_print(dut, DUT_MSG_DEBUG,
1512 "Using FILS HLP DHCPv4 Rapid Commit");
1513 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001514
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001515 return 1;
1516#endif /* __linux__ */
1517 return -2;
1518 }
1519
1520 ip = get_param(cmd, "ip");
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301521 if (!ip) {
1522 send_resp(dut, conn, SIGMA_INVALID,
1523 "ErrorCode,Missing IP address");
1524 return 0;
1525 }
1526
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001527 mask = get_param(cmd, "mask");
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301528 if (!mask) {
1529 send_resp(dut, conn, SIGMA_INVALID,
1530 "ErrorCode,Missing subnet mask");
1531 return 0;
1532 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001533
1534 if (type == 2) {
1535 int net = atoi(mask);
1536
1537 if ((net < 0 && net > 64) || !is_ipv6_addr(ip))
1538 return -1;
1539
1540 if (dut->no_ip_addr_set) {
1541 snprintf(buf, sizeof(buf),
1542 "sysctl net.ipv6.conf.%s.disable_ipv6=1",
1543 ifname);
1544 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
1545 if (system(buf) != 0) {
1546 sigma_dut_print(dut, DUT_MSG_DEBUG,
1547 "Failed to disable IPv6 address before association");
1548 }
1549 } else {
1550 snprintf(buf, sizeof(buf),
1551 "ip -6 addr del %s/%s dev %s",
1552 ip, mask, ifname);
1553 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
1554 if (system(buf) != 0) {
1555 /*
1556 * This command may fail if the address being
1557 * deleted does not exist. Inaction here is
1558 * intentional.
1559 */
1560 }
1561
1562 snprintf(buf, sizeof(buf),
1563 "ip -6 addr add %s/%s dev %s",
1564 ip, mask, ifname);
1565 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
1566 if (system(buf) != 0) {
1567 send_resp(dut, conn, SIGMA_ERROR,
1568 "ErrorCode,Failed to set IPv6 address");
1569 return 0;
1570 }
1571 }
1572
1573 dut->last_set_ip_config_ipv6 = 1;
1574 static_ip_file(6, ip, mask, NULL);
1575 return 1;
1576 } else if (type == 1) {
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301577 if (!is_ip_addr(ip) || !is_ip_addr(mask))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001578 return -1;
1579 }
1580
1581 kill_dhcp_client(dut, ifname);
1582
1583 if (!dut->no_ip_addr_set) {
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301584 if (!set_ipv4_addr(dut, ifname, ip, mask)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001585 send_resp(dut, conn, SIGMA_ERROR,
1586 "ErrorCode,Failed to set IP address");
1587 return 0;
1588 }
1589 }
1590
1591 gw = get_param(cmd, "defaultGateway");
1592 if (gw) {
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301593 if (set_ipv4_gw(dut, gw) < 1) {
1594 send_resp(dut, conn, SIGMA_ERROR,
1595 "ErrorCode,Failed to set default gateway");
1596 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001597 }
1598 }
1599
1600 val = get_param(cmd, "primary-dns");
1601 if (val) {
1602 /* TODO */
1603 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored primary-dns %s "
1604 "setting", val);
1605 }
1606
1607 val = get_param(cmd, "secondary-dns");
1608 if (val) {
1609 /* TODO */
1610 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored secondary-dns %s "
1611 "setting", val);
1612 }
1613
1614 static_ip_file(4, ip, mask, gw);
1615
1616 return 1;
1617}
1618
1619
Jouni Malinenf7222712019-06-13 01:50:21 +03001620static enum sigma_cmd_result cmd_sta_get_info(struct sigma_dut *dut,
1621 struct sigma_conn *conn,
1622 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001623{
1624 /* const char *intf = get_param(cmd, "Interface"); */
1625 /* TODO: could report more details here */
1626 send_resp(dut, conn, SIGMA_COMPLETE, "vendor,Atheros");
1627 return 0;
1628}
1629
1630
Jouni Malinenf7222712019-06-13 01:50:21 +03001631static enum sigma_cmd_result cmd_sta_get_mac_address(struct sigma_dut *dut,
1632 struct sigma_conn *conn,
1633 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001634{
1635 /* const char *intf = get_param(cmd, "Interface"); */
1636 char addr[20], resp[50];
1637
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05301638 if (dut->dev_role == DEVROLE_STA_CFON)
1639 return sta_cfon_get_mac_address(dut, conn, cmd);
1640
Jouni Malinen9540e012019-11-05 17:08:42 +02001641 start_sta_mode(dut);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001642 if (get_wpa_status(get_station_ifname(dut), "address",
1643 addr, sizeof(addr)) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001644 return -2;
1645
1646 snprintf(resp, sizeof(resp), "mac,%s", addr);
1647 send_resp(dut, conn, SIGMA_COMPLETE, resp);
1648 return 0;
1649}
1650
1651
Jouni Malinenf7222712019-06-13 01:50:21 +03001652static enum sigma_cmd_result cmd_sta_is_connected(struct sigma_dut *dut,
1653 struct sigma_conn *conn,
1654 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001655{
1656 /* const char *intf = get_param(cmd, "Interface"); */
1657 int connected = 0;
1658 char result[32];
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001659 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001660 sizeof(result)) < 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001661 sigma_dut_print(dut, DUT_MSG_INFO,
1662 "Could not get interface %s status",
1663 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001664 return -2;
1665 }
1666
1667 sigma_dut_print(dut, DUT_MSG_DEBUG, "wpa_state=%s", result);
1668 if (strncmp(result, "COMPLETED", 9) == 0)
1669 connected = 1;
1670
1671 if (connected)
1672 send_resp(dut, conn, SIGMA_COMPLETE, "connected,1");
1673 else
1674 send_resp(dut, conn, SIGMA_COMPLETE, "connected,0");
1675
1676 return 0;
1677}
1678
1679
Jouni Malinenf7222712019-06-13 01:50:21 +03001680static enum sigma_cmd_result
1681cmd_sta_verify_ip_connection(struct sigma_dut *dut, struct sigma_conn *conn,
1682 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001683{
1684 /* const char *intf = get_param(cmd, "Interface"); */
1685 const char *dst, *timeout;
1686 int wait_time = 90;
1687 char buf[100];
1688 int res;
1689
1690 dst = get_param(cmd, "destination");
1691 if (dst == NULL || !is_ip_addr(dst))
1692 return -1;
1693
1694 timeout = get_param(cmd, "timeout");
1695 if (timeout) {
1696 wait_time = atoi(timeout);
1697 if (wait_time < 1)
1698 wait_time = 1;
1699 }
1700
1701 /* TODO: force renewal of IP lease if DHCP is enabled */
1702
1703 snprintf(buf, sizeof(buf), "ping %s -c 3 -W %d", dst, wait_time);
1704 res = system(buf);
1705 sigma_dut_print(dut, DUT_MSG_DEBUG, "ping returned: %d", res);
1706 if (res == 0)
1707 send_resp(dut, conn, SIGMA_COMPLETE, "connected,1");
1708 else if (res == 256)
1709 send_resp(dut, conn, SIGMA_COMPLETE, "connected,0");
1710 else
1711 return -2;
1712
1713 return 0;
1714}
1715
1716
Jouni Malinenf7222712019-06-13 01:50:21 +03001717static enum sigma_cmd_result cmd_sta_get_bssid(struct sigma_dut *dut,
1718 struct sigma_conn *conn,
1719 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001720{
1721 /* const char *intf = get_param(cmd, "Interface"); */
1722 char bssid[20], resp[50];
1723
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001724 if (get_wpa_status(get_station_ifname(dut), "bssid",
1725 bssid, sizeof(bssid)) < 0)
Peng Xub8fc5cc2017-05-10 17:27:28 -07001726 strlcpy(bssid, "00:00:00:00:00:00", sizeof(bssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001727
1728 snprintf(resp, sizeof(resp), "bssid,%s", bssid);
1729 send_resp(dut, conn, SIGMA_COMPLETE, resp);
1730 return 0;
1731}
1732
1733
1734#ifdef __SAMSUNG__
1735static int add_use_network(const char *ifname)
1736{
1737 char buf[100];
1738
1739 snprintf(buf, sizeof(buf), "USE_NETWORK ON");
1740 wpa_command(ifname, buf);
1741 return 0;
1742}
1743#endif /* __SAMSUNG__ */
1744
1745
1746static int add_network_common(struct sigma_dut *dut, struct sigma_conn *conn,
1747 const char *ifname, struct sigma_cmd *cmd)
1748{
1749 const char *ssid = get_param(cmd, "ssid");
1750 int id;
1751 const char *val;
1752
1753 if (ssid == NULL)
1754 return -1;
1755
1756 start_sta_mode(dut);
1757
1758#ifdef __SAMSUNG__
1759 add_use_network(ifname);
1760#endif /* __SAMSUNG__ */
1761
1762 id = add_network(ifname);
1763 if (id < 0)
1764 return -2;
1765 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding network %d", id);
1766
1767 if (set_network_quoted(ifname, id, "ssid", ssid) < 0)
1768 return -2;
1769
1770 dut->infra_network_id = id;
1771 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
1772
1773 val = get_param(cmd, "program");
1774 if (!val)
1775 val = get_param(cmd, "prog");
1776 if (val && strcasecmp(val, "hs2") == 0) {
1777 char buf[100];
1778 snprintf(buf, sizeof(buf), "ENABLE_NETWORK %d no-connect", id);
1779 wpa_command(ifname, buf);
1780
1781 val = get_param(cmd, "prefer");
1782 if (val && atoi(val) > 0)
1783 set_network(ifname, id, "priority", "1");
1784 }
1785
1786 return id;
1787}
1788
1789
Jouni Malinenf7222712019-06-13 01:50:21 +03001790static enum sigma_cmd_result cmd_sta_set_encryption(struct sigma_dut *dut,
1791 struct sigma_conn *conn,
1792 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001793{
1794 const char *intf = get_param(cmd, "Interface");
1795 const char *ssid = get_param(cmd, "ssid");
1796 const char *type = get_param(cmd, "encpType");
1797 const char *ifname;
1798 char buf[200];
1799 int id;
1800
1801 if (intf == NULL || ssid == NULL)
1802 return -1;
1803
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001804 if (strcmp(intf, get_main_ifname(dut)) == 0)
1805 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001806 else
1807 ifname = intf;
1808
1809 id = add_network_common(dut, conn, ifname, cmd);
1810 if (id < 0)
1811 return id;
1812
1813 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
1814 return -2;
1815
1816 if (type && strcasecmp(type, "wep") == 0) {
1817 const char *val;
1818 int i;
1819
1820 val = get_param(cmd, "activeKey");
1821 if (val) {
1822 int keyid;
1823 keyid = atoi(val);
1824 if (keyid < 1 || keyid > 4)
1825 return -1;
1826 snprintf(buf, sizeof(buf), "%d", keyid - 1);
1827 if (set_network(ifname, id, "wep_tx_keyidx", buf) < 0)
1828 return -2;
1829 }
1830
1831 for (i = 0; i < 4; i++) {
1832 snprintf(buf, sizeof(buf), "key%d", i + 1);
1833 val = get_param(cmd, buf);
1834 if (val == NULL)
1835 continue;
1836 snprintf(buf, sizeof(buf), "wep_key%d", i);
1837 if (set_network(ifname, id, buf, val) < 0)
1838 return -2;
1839 }
1840 }
1841
1842 return 1;
1843}
1844
1845
Jouni Malinene4fde732019-03-25 22:29:37 +02001846static int set_akm_suites(struct sigma_dut *dut, const char *ifname,
1847 int id, const char *val)
1848{
1849 char key_mgmt[200], *end, *pos;
1850 const char *in_pos = val;
1851
Jouni Malinen8179fee2019-03-28 03:19:47 +02001852 dut->akm_values = 0;
Jouni Malinene4fde732019-03-25 22:29:37 +02001853 pos = key_mgmt;
1854 end = pos + sizeof(key_mgmt);
1855 while (*in_pos) {
1856 int res, akm = atoi(in_pos);
1857 const char *str;
1858
Jouni Malinen8179fee2019-03-28 03:19:47 +02001859 if (akm >= 0 && akm < 32)
1860 dut->akm_values |= 1 << akm;
1861
Jouni Malinene4fde732019-03-25 22:29:37 +02001862 switch (akm) {
1863 case AKM_WPA_EAP:
1864 str = "WPA-EAP";
1865 break;
1866 case AKM_WPA_PSK:
1867 str = "WPA-PSK";
1868 break;
1869 case AKM_FT_EAP:
1870 str = "FT-EAP";
1871 break;
1872 case AKM_FT_PSK:
1873 str = "FT-PSK";
1874 break;
1875 case AKM_EAP_SHA256:
1876 str = "WPA-EAP-SHA256";
1877 break;
1878 case AKM_PSK_SHA256:
1879 str = "WPA-PSK-SHA256";
1880 break;
1881 case AKM_SAE:
1882 str = "SAE";
1883 break;
1884 case AKM_FT_SAE:
1885 str = "FT-SAE";
1886 break;
1887 case AKM_SUITE_B:
1888 str = "WPA-EAP-SUITE-B-192";
1889 break;
1890 case AKM_FT_SUITE_B:
1891 str = "FT-EAP-SHA384";
1892 break;
1893 case AKM_FILS_SHA256:
1894 str = "FILS-SHA256";
1895 break;
1896 case AKM_FILS_SHA384:
1897 str = "FILS-SHA384";
1898 break;
1899 case AKM_FT_FILS_SHA256:
1900 str = "FT-FILS-SHA256";
1901 break;
1902 case AKM_FT_FILS_SHA384:
1903 str = "FT-FILS-SHA384";
1904 break;
1905 default:
1906 sigma_dut_print(dut, DUT_MSG_ERROR,
1907 "Unsupported AKMSuitetype %d", akm);
1908 return -1;
1909 }
1910
1911 res = snprintf(pos, end - pos, "%s%s",
1912 pos == key_mgmt ? "" : " ", str);
1913 if (res < 0 || res >= end - pos)
1914 return -1;
1915 pos += res;
1916
1917 in_pos = strchr(in_pos, ';');
1918 if (!in_pos)
1919 break;
1920 while (*in_pos == ';')
1921 in_pos++;
1922 }
1923 sigma_dut_print(dut, DUT_MSG_DEBUG, "AKMSuiteType %s --> %s",
1924 val, key_mgmt);
1925 return set_network(ifname, id, "key_mgmt", key_mgmt);
1926}
1927
1928
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001929static int set_wpa_common(struct sigma_dut *dut, struct sigma_conn *conn,
1930 const char *ifname, struct sigma_cmd *cmd)
1931{
1932 const char *val;
1933 int id;
Jouni Malinenad395a22017-09-01 21:13:46 +03001934 int cipher_set = 0;
Jouni Malinen47dcc952017-10-09 16:43:24 +03001935 int owe;
Sunil Duttc75a1e62018-01-11 20:47:50 +05301936 int suite_b = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001937
1938 id = add_network_common(dut, conn, ifname, cmd);
1939 if (id < 0)
1940 return id;
1941
Jouni Malinen47dcc952017-10-09 16:43:24 +03001942 val = get_param(cmd, "Type");
1943 owe = val && strcasecmp(val, "OWE") == 0;
1944
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001945 val = get_param(cmd, "keyMgmtType");
Jouni Malinen47dcc952017-10-09 16:43:24 +03001946 if (!val && owe)
1947 val = "OWE";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001948 if (val == NULL) {
Jouni Malinene4fde732019-03-25 22:29:37 +02001949 /* keyMgmtType is being replaced with AKMSuiteType, so ignore
1950 * this missing parameter and assume proto=WPA2. */
1951 if (set_network(ifname, id, "proto", "WPA2") < 0)
1952 return ERROR_SEND_STATUS;
1953 } else if (strcasecmp(val, "wpa") == 0 ||
1954 strcasecmp(val, "wpa-psk") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001955 if (set_network(ifname, id, "proto", "WPA") < 0)
1956 return -2;
1957 } else if (strcasecmp(val, "wpa2") == 0 ||
1958 strcasecmp(val, "wpa2-psk") == 0 ||
1959 strcasecmp(val, "wpa2-ft") == 0 ||
1960 strcasecmp(val, "wpa2-sha256") == 0) {
1961 if (set_network(ifname, id, "proto", "WPA2") < 0)
1962 return -2;
Pradeep Reddy POTTETI6d04b3b2016-11-15 14:51:26 +05301963 } else if (strcasecmp(val, "wpa2-wpa-psk") == 0 ||
1964 strcasecmp(val, "wpa2-wpa-ent") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001965 if (set_network(ifname, id, "proto", "WPA WPA2") < 0)
1966 return -2;
Jouni Malinenad395a22017-09-01 21:13:46 +03001967 } else if (strcasecmp(val, "SuiteB") == 0) {
Sunil Duttc75a1e62018-01-11 20:47:50 +05301968 suite_b = 1;
Jouni Malinenad395a22017-09-01 21:13:46 +03001969 if (set_network(ifname, id, "proto", "WPA2") < 0)
1970 return -2;
Jouni Malinen47dcc952017-10-09 16:43:24 +03001971 } else if (strcasecmp(val, "OWE") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001972 } else {
1973 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized keyMgmtType value");
1974 return 0;
1975 }
1976
1977 val = get_param(cmd, "encpType");
Jouni Malinenad395a22017-09-01 21:13:46 +03001978 if (val) {
1979 cipher_set = 1;
1980 if (strcasecmp(val, "tkip") == 0) {
1981 if (set_network(ifname, id, "pairwise", "TKIP") < 0)
1982 return -2;
1983 } else if (strcasecmp(val, "aes-ccmp") == 0) {
1984 if (set_network(ifname, id, "pairwise", "CCMP") < 0)
1985 return -2;
1986 } else if (strcasecmp(val, "aes-ccmp-tkip") == 0) {
1987 if (set_network(ifname, id, "pairwise",
1988 "CCMP TKIP") < 0)
1989 return -2;
1990 } else if (strcasecmp(val, "aes-gcmp") == 0) {
1991 if (set_network(ifname, id, "pairwise", "GCMP") < 0)
1992 return -2;
1993 if (set_network(ifname, id, "group", "GCMP") < 0)
1994 return -2;
1995 } else {
1996 send_resp(dut, conn, SIGMA_ERROR,
1997 "errorCode,Unrecognized encpType value");
1998 return 0;
1999 }
2000 }
2001
2002 val = get_param(cmd, "PairwiseCipher");
2003 if (val) {
2004 cipher_set = 1;
2005 /* TODO: Support space separated list */
2006 if (strcasecmp(val, "AES-GCMP-256") == 0) {
2007 if (set_network(ifname, id, "pairwise", "GCMP-256") < 0)
2008 return -2;
2009 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
2010 if (set_network(ifname, id, "pairwise",
2011 "CCMP-256") < 0)
2012 return -2;
2013 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
2014 if (set_network(ifname, id, "pairwise", "GCMP") < 0)
2015 return -2;
2016 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
2017 if (set_network(ifname, id, "pairwise", "CCMP") < 0)
2018 return -2;
2019 } else {
2020 send_resp(dut, conn, SIGMA_ERROR,
2021 "errorCode,Unrecognized PairwiseCipher value");
2022 return 0;
2023 }
2024 }
2025
Jouni Malinen47dcc952017-10-09 16:43:24 +03002026 if (!cipher_set && !owe) {
Jouni Malinenad395a22017-09-01 21:13:46 +03002027 send_resp(dut, conn, SIGMA_ERROR,
2028 "errorCode,Missing encpType and PairwiseCipher");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002029 return 0;
2030 }
Jouni Malinenad395a22017-09-01 21:13:46 +03002031
2032 val = get_param(cmd, "GroupCipher");
2033 if (val) {
2034 if (strcasecmp(val, "AES-GCMP-256") == 0) {
2035 if (set_network(ifname, id, "group", "GCMP-256") < 0)
2036 return -2;
2037 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
2038 if (set_network(ifname, id, "group", "CCMP-256") < 0)
2039 return -2;
2040 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
2041 if (set_network(ifname, id, "group", "GCMP") < 0)
2042 return -2;
2043 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
2044 if (set_network(ifname, id, "group", "CCMP") < 0)
2045 return -2;
2046 } else {
2047 send_resp(dut, conn, SIGMA_ERROR,
2048 "errorCode,Unrecognized GroupCipher value");
2049 return 0;
2050 }
2051 }
2052
Jouni Malinen7b239522017-09-14 21:37:18 +03002053 val = get_param(cmd, "GroupMgntCipher");
Jouni Malinenad395a22017-09-01 21:13:46 +03002054 if (val) {
Jouni Malinene8898cb2017-09-26 17:55:26 +03002055 const char *cipher;
2056
2057 if (strcasecmp(val, "BIP-GMAC-256") == 0) {
2058 cipher = "BIP-GMAC-256";
2059 } else if (strcasecmp(val, "BIP-CMAC-256") == 0) {
2060 cipher = "BIP-CMAC-256";
2061 } else if (strcasecmp(val, "BIP-GMAC-128") == 0) {
2062 cipher = "BIP-GMAC-128";
2063 } else if (strcasecmp(val, "BIP-CMAC-128") == 0) {
2064 cipher = "AES-128-CMAC";
2065 } else {
2066 send_resp(dut, conn, SIGMA_INVALID,
2067 "errorCode,Unsupported GroupMgntCipher");
2068 return 0;
2069 }
2070 if (set_network(ifname, id, "group_mgmt", cipher) < 0) {
2071 send_resp(dut, conn, SIGMA_INVALID,
2072 "errorCode,Failed to set GroupMgntCipher");
2073 return 0;
2074 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002075 }
2076
Jouni Malinene4fde732019-03-25 22:29:37 +02002077 val = get_param(cmd, "AKMSuiteType");
2078 if (val && set_akm_suites(dut, ifname, id, val) < 0)
2079 return ERROR_SEND_STATUS;
2080
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002081 dut->sta_pmf = STA_PMF_DISABLED;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302082
2083 if (dut->program == PROGRAM_OCE) {
2084 dut->sta_pmf = STA_PMF_OPTIONAL;
2085 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2086 return -2;
2087 }
2088
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002089 val = get_param(cmd, "PMF");
2090 if (val) {
2091 if (strcasecmp(val, "Required") == 0 ||
2092 strcasecmp(val, "Forced_Required") == 0) {
2093 dut->sta_pmf = STA_PMF_REQUIRED;
2094 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2095 return -2;
2096 } else if (strcasecmp(val, "Optional") == 0) {
2097 dut->sta_pmf = STA_PMF_OPTIONAL;
2098 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2099 return -2;
2100 } else if (strcasecmp(val, "Disabled") == 0 ||
Kiran Kumar Lokere07da3b22018-12-16 22:42:49 -08002101 strcasecmp(val, "Disable") == 0 ||
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002102 strcasecmp(val, "Forced_Disabled") == 0) {
2103 dut->sta_pmf = STA_PMF_DISABLED;
2104 } else {
2105 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized PMF value");
2106 return 0;
2107 }
Sunil Duttc75a1e62018-01-11 20:47:50 +05302108 } else if (owe || suite_b) {
Jouni Malinen1287cd72018-01-04 17:08:01 +02002109 dut->sta_pmf = STA_PMF_REQUIRED;
2110 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2111 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002112 }
2113
Jouni Malinen0165c7f2020-03-26 11:51:58 +02002114 val = get_param(cmd, "BeaconProtection");
2115 if (val && atoi(val) == 1 &&
2116 set_network(ifname, id, "beacon_prot", "1") < 0)
2117 return ERROR_SEND_STATUS;
2118
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002119 return id;
2120}
2121
2122
Jouni Malinenf7222712019-06-13 01:50:21 +03002123static enum sigma_cmd_result cmd_sta_set_psk(struct sigma_dut *dut,
2124 struct sigma_conn *conn,
2125 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002126{
2127 const char *intf = get_param(cmd, "Interface");
Jouni Malinen992a81e2017-08-22 13:57:47 +03002128 const char *type = get_param(cmd, "Type");
Jouni Malinen1287cd72018-01-04 17:08:01 +02002129 const char *pmf = get_param(cmd, "PMF");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002130 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinene4fde732019-03-25 22:29:37 +02002131 const char *akm = get_param(cmd, "AKMSuiteType");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002132 const char *ifname, *val, *alg;
2133 int id;
Jouni Malinen4b3769d2019-10-10 16:20:29 +03002134 char buf[50];
Jouni Malinen11e55212019-11-22 21:46:59 +02002135 int sae_pwe = -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002136
2137 if (intf == NULL)
2138 return -1;
2139
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002140 if (strcmp(intf, get_main_ifname(dut)) == 0)
2141 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002142 else
2143 ifname = intf;
2144
2145 id = set_wpa_common(dut, conn, ifname, cmd);
2146 if (id < 0)
2147 return id;
2148
2149 val = get_param(cmd, "keyMgmtType");
2150 alg = get_param(cmd, "micAlg");
2151
Jouni Malinen992a81e2017-08-22 13:57:47 +03002152 if (type && strcasecmp(type, "SAE") == 0) {
Jouni Malinene4fde732019-03-25 22:29:37 +02002153 if (!akm && val && strcasecmp(val, "wpa2-ft") == 0) {
Jouni Malinen992a81e2017-08-22 13:57:47 +03002154 if (set_network(ifname, id, "key_mgmt", "FT-SAE") < 0)
2155 return -2;
Jouni Malinene4fde732019-03-25 22:29:37 +02002156 } else if (!akm) {
Jouni Malinen992a81e2017-08-22 13:57:47 +03002157 if (set_network(ifname, id, "key_mgmt", "SAE") < 0)
2158 return -2;
2159 }
2160 if (wpa_command(ifname, "SET sae_groups ") != 0) {
2161 sigma_dut_print(dut, DUT_MSG_ERROR,
2162 "Failed to clear sae_groups to default");
2163 return -2;
2164 }
Jouni Malinen1287cd72018-01-04 17:08:01 +02002165 if (!pmf) {
2166 dut->sta_pmf = STA_PMF_REQUIRED;
2167 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2168 return -2;
2169 }
Jouni Malinen0ab50f42017-08-31 01:34:59 +03002170 } else if (type && strcasecmp(type, "PSK-SAE") == 0) {
2171 if (val && strcasecmp(val, "wpa2-ft") == 0) {
2172 if (set_network(ifname, id, "key_mgmt",
2173 "FT-SAE FT-PSK") < 0)
2174 return -2;
Jouni Malinen3b73d872019-06-12 03:13:25 +03002175 } else if (!akm) {
Jouni Malinen0ab50f42017-08-31 01:34:59 +03002176 if (set_network(ifname, id, "key_mgmt",
2177 "SAE WPA-PSK") < 0)
2178 return -2;
2179 }
2180 if (wpa_command(ifname, "SET sae_groups ") != 0) {
2181 sigma_dut_print(dut, DUT_MSG_ERROR,
2182 "Failed to clear sae_groups to default");
2183 return -2;
2184 }
Jouni Malinen1287cd72018-01-04 17:08:01 +02002185 if (!pmf) {
2186 dut->sta_pmf = STA_PMF_OPTIONAL;
2187 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2188 return -2;
2189 }
Jouni Malinen992a81e2017-08-22 13:57:47 +03002190 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002191 if (set_network(ifname, id, "key_mgmt", "WPA-PSK-SHA256") < 0)
2192 return -2;
2193 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
2194 if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0)
2195 return -2;
Ashwini Patil6dbf7b02017-03-20 13:42:11 +05302196 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
2197 if (set_network(ifname, id, "key_mgmt", "FT-PSK") < 0)
2198 return -2;
Jouni Malinen3b73d872019-06-12 03:13:25 +03002199 } else if (!akm &&
2200 ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
2201 dut->sta_pmf == STA_PMF_REQUIRED)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002202 if (set_network(ifname, id, "key_mgmt",
2203 "WPA-PSK WPA-PSK-SHA256") < 0)
2204 return -2;
Jouni Malinen77ff3f02019-03-28 03:45:40 +02002205 } else if (!akm && dut->sta_pmf == STA_PMF_OPTIONAL) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002206 if (set_network(ifname, id, "key_mgmt",
2207 "WPA-PSK WPA-PSK-SHA256") < 0)
2208 return -2;
Jouni Malinen77ff3f02019-03-28 03:45:40 +02002209 } else if (!akm) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002210 if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0)
2211 return -2;
2212 }
2213
2214 val = get_param(cmd, "passPhrase");
2215 if (val == NULL)
2216 return -1;
Jouni Malinen2126f422017-10-11 23:24:33 +03002217 if (type && strcasecmp(type, "SAE") == 0) {
2218 if (set_network_quoted(ifname, id, "sae_password", val) < 0)
2219 return -2;
2220 } else {
2221 if (set_network_quoted(ifname, id, "psk", val) < 0)
2222 return -2;
2223 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002224
Jouni Malinen78d10c42019-03-25 22:34:32 +02002225 val = get_param(cmd, "PasswordId");
2226 if (val && set_network_quoted(ifname, id, "sae_password_id", val) < 0)
2227 return ERROR_SEND_STATUS;
2228
Jouni Malinen992a81e2017-08-22 13:57:47 +03002229 val = get_param(cmd, "ECGroupID");
2230 if (val) {
Jouni Malinenb54f0df2019-12-12 01:57:29 +02002231 snprintf(buf, sizeof(buf), "SET sae_groups %s", val);
Jouni Malinen992a81e2017-08-22 13:57:47 +03002232 if (wpa_command(ifname, buf) != 0) {
2233 sigma_dut_print(dut, DUT_MSG_ERROR,
2234 "Failed to clear sae_groups");
2235 return -2;
2236 }
2237 }
2238
Jouni Malinen68143132017-09-02 02:34:08 +03002239 val = get_param(cmd, "InvalidSAEElement");
2240 if (val) {
2241 free(dut->sae_commit_override);
2242 dut->sae_commit_override = strdup(val);
2243 }
2244
Jouni Malinen4b3769d2019-10-10 16:20:29 +03002245 val = get_param(cmd, "PMKID_Include");
2246 if (val) {
2247 snprintf(buf, sizeof(buf), "SET sae_pmkid_in_assoc %d",
2248 get_enable_disable(val));
2249 wpa_command(intf, buf);
2250 }
2251
Jouni Malineneeb43d32019-12-06 17:40:07 +02002252 val = get_param(cmd, "IgnoreH2E_RSNXE_BSSMemSel");
2253 if (val) {
2254 snprintf(buf, sizeof(buf), "SET ignore_sae_h2e_only %d",
2255 get_enable_disable(val));
2256 wpa_command(intf, buf);
2257 }
2258
Jouni Malinenf2348d22019-12-07 11:52:55 +02002259 val = get_param(cmd, "ECGroupID_RGE");
2260 if (val) {
2261 snprintf(buf, sizeof(buf), "SET extra_sae_rejected_groups %s",
2262 val);
2263 wpa_command(intf, buf);
2264 }
2265
Jouni Malinen99e55022019-12-07 13:59:41 +02002266 val = get_param(cmd, "RSNXE_Content");
2267 if (val) {
2268 const char *param;
2269
2270 if (strncasecmp(val, "AssocReq:", 9) == 0) {
2271 val += 9;
2272 param = "rsnxe_override_assoc";
2273 } else if (strncasecmp(val, "EapolM2:", 8) == 0) {
2274 val += 8;
2275 param = "rsnxe_override_eapol";
2276 } else {
2277 send_resp(dut, conn, SIGMA_ERROR,
2278 "errorCode,Unsupported RSNXE_Content value");
2279 return STATUS_SENT_ERROR;
2280 }
2281 snprintf(buf, sizeof(buf), "SET %s %s", param, val);
2282 wpa_command(intf, buf);
2283 }
2284
Jouni Malinen11e55212019-11-22 21:46:59 +02002285 val = get_param(cmd, "sae_pwe");
2286 if (val) {
2287 if (strcasecmp(val, "h2e") == 0) {
2288 dut->sae_pwe = SAE_PWE_H2E;
Jouni Malinen7244a412019-12-07 11:54:10 +02002289 } else if (strcasecmp(val, "loop") == 0 ||
2290 strcasecmp(val, "looping") == 0) {
Jouni Malinen11e55212019-11-22 21:46:59 +02002291 dut->sae_pwe = SAE_PWE_LOOP;
2292 } else {
2293 send_resp(dut, conn, SIGMA_ERROR,
2294 "errorCode,Unsupported sae_pwe value");
2295 return STATUS_SENT_ERROR;
2296 }
2297 }
Vinita S. Maloo6d7454f2020-04-02 15:03:26 +05302298
2299 val = get_param(cmd, "Clear_RSNXE");
2300 if (val && strcmp(val, "1") == 0 &&
2301 (wpa_command(intf, "SET rsnxe_override_assoc ") ||
2302 wpa_command(intf, "SET rsnxe_override_eapol "))) {
2303 send_resp(dut, conn, SIGMA_ERROR,
2304 "errorCode,Failed to clear RSNXE");
2305 return ERROR_SEND_STATUS;
2306 }
2307
Jouni Malinenc0078772020-03-04 21:23:16 +02002308 if (dut->sae_pwe == SAE_PWE_LOOP && get_param(cmd, "PasswordId"))
2309 sae_pwe = 3;
2310 else if (dut->sae_pwe == SAE_PWE_LOOP)
Jouni Malinen11e55212019-11-22 21:46:59 +02002311 sae_pwe = 0;
2312 else if (dut->sae_pwe == SAE_PWE_H2E)
2313 sae_pwe = 1;
2314 else if (dut->sae_h2e_default)
2315 sae_pwe = 2;
2316 snprintf(buf, sizeof(buf), "SET sae_pwe %d", sae_pwe);
2317 if (sae_pwe >= 0 && wpa_command(ifname, buf) != 0)
2318 return ERROR_SEND_STATUS;
2319
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002320 if (dut->program == PROGRAM_60GHZ && network_mode &&
2321 strcasecmp(network_mode, "PBSS") == 0 &&
2322 set_network(ifname, id, "pbss", "1") < 0)
2323 return -2;
2324
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002325 return 1;
2326}
2327
2328
Jouni Malinen8ac93452019-08-14 15:19:13 +03002329static enum sigma_cmd_result set_trust_root_system(struct sigma_dut *dut,
2330 struct sigma_conn *conn,
2331 const char *ifname, int id)
2332{
2333 char buf[200];
2334
2335 snprintf(buf, sizeof(buf), "%s/certs", sigma_cert_path);
2336 if (!file_exists(buf))
2337 strlcpy(buf, "/system/etc/security/cacerts", sizeof(buf));
2338 if (!file_exists(buf))
2339 strlcpy(buf, "/etc/ssl/certs", sizeof(buf));
2340 if (!file_exists(buf)) {
2341 char msg[300];
2342
2343 snprintf(msg, sizeof(msg),
2344 "ErrorCode,trustedRootCA system store (%s) not found",
2345 buf);
2346 send_resp(dut, conn, SIGMA_ERROR, msg);
2347 return STATUS_SENT_ERROR;
2348 }
2349
2350 if (set_network_quoted(ifname, id, "ca_path", buf) < 0)
2351 return ERROR_SEND_STATUS;
2352
2353 return SUCCESS_SEND_STATUS;
2354}
2355
2356
2357static enum sigma_cmd_result set_trust_root(struct sigma_dut *dut,
2358 struct sigma_conn *conn,
2359 const char *ifname, int id,
2360 const char *val)
2361{
2362 char buf[200];
2363#ifdef ANDROID
2364 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
2365 int length;
2366#endif /* ANDROID */
2367
2368 if (strcmp(val, "DEFAULT") == 0)
2369 return set_trust_root_system(dut, conn, ifname, id);
2370
2371#ifdef ANDROID
2372 snprintf(buf, sizeof(buf), "CACERT_%s", val);
2373 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
2374 if (length > 0) {
2375 sigma_dut_print(dut, DUT_MSG_INFO, "Use Android keystore [%s]",
2376 buf);
2377 snprintf(buf, sizeof(buf), "keystore://CACERT_%s", val);
2378 goto ca_cert_selected;
2379 }
2380#endif /* ANDROID */
2381
2382 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
2383#ifdef __linux__
2384 if (!file_exists(buf)) {
2385 char msg[300];
2386
2387 snprintf(msg, sizeof(msg),
2388 "ErrorCode,trustedRootCA file (%s) not found", buf);
2389 send_resp(dut, conn, SIGMA_ERROR, msg);
2390 return STATUS_SENT_ERROR;
2391 }
2392#endif /* __linux__ */
2393#ifdef ANDROID
2394ca_cert_selected:
2395#endif /* ANDROID */
2396 if (set_network_quoted(ifname, id, "ca_cert", buf) < 0)
2397 return ERROR_SEND_STATUS;
2398
2399 return SUCCESS_SEND_STATUS;
2400}
2401
2402
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002403static int set_eap_common(struct sigma_dut *dut, struct sigma_conn *conn,
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302404 const char *ifname, int username_identity,
2405 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002406{
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002407 const char *val, *alg, *akm, *trust_root, *domain, *domain_suffix;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002408 int id;
Jouni Malinen53264f62019-05-03 13:04:40 +03002409 char buf[200], buf2[300];
Jouni Malinen8179fee2019-03-28 03:19:47 +02002410 int erp = 0;
Jouni Malinen8ac93452019-08-14 15:19:13 +03002411 enum sigma_cmd_result res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002412
2413 id = set_wpa_common(dut, conn, ifname, cmd);
2414 if (id < 0)
2415 return id;
2416
2417 val = get_param(cmd, "keyMgmtType");
2418 alg = get_param(cmd, "micAlg");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302419 akm = get_param(cmd, "AKMSuiteType");
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002420 trust_root = get_param(cmd, "trustedRootCA");
2421 domain = get_param(cmd, "Domain");
2422 domain_suffix = get_param(cmd, "DomainSuffix");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002423
Jouni Malinenad395a22017-09-01 21:13:46 +03002424 if (val && strcasecmp(val, "SuiteB") == 0) {
2425 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SUITE-B-192") <
2426 0)
2427 return -2;
2428 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002429 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SHA256") < 0)
2430 return -2;
2431 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
2432 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
2433 return -2;
2434 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
2435 if (set_network(ifname, id, "key_mgmt", "FT-EAP") < 0)
2436 return -2;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002437 } else if (!akm &&
2438 ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
2439 dut->sta_pmf == STA_PMF_REQUIRED)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002440 if (set_network(ifname, id, "key_mgmt",
2441 "WPA-EAP WPA-EAP-SHA256") < 0)
2442 return -2;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302443 } else if (akm && atoi(akm) == 14) {
2444 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
2445 dut->sta_pmf == STA_PMF_REQUIRED) {
2446 if (set_network(ifname, id, "key_mgmt",
2447 "WPA-EAP-SHA256 FILS-SHA256") < 0)
2448 return -2;
2449 } else {
2450 if (set_network(ifname, id, "key_mgmt",
2451 "WPA-EAP FILS-SHA256") < 0)
2452 return -2;
2453 }
2454
Jouni Malinen8179fee2019-03-28 03:19:47 +02002455 erp = 1;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302456 } else if (akm && atoi(akm) == 15) {
2457 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
2458 dut->sta_pmf == STA_PMF_REQUIRED) {
2459 if (set_network(ifname, id, "key_mgmt",
2460 "WPA-EAP-SHA256 FILS-SHA384") < 0)
2461 return -2;
2462 } else {
2463 if (set_network(ifname, id, "key_mgmt",
2464 "WPA-EAP FILS-SHA384") < 0)
2465 return -2;
2466 }
2467
Jouni Malinen8179fee2019-03-28 03:19:47 +02002468 erp = 1;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002469 } else if (!akm && dut->sta_pmf == STA_PMF_OPTIONAL) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002470 if (set_network(ifname, id, "key_mgmt",
2471 "WPA-EAP WPA-EAP-SHA256") < 0)
2472 return -2;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002473 } else if (!akm) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002474 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
2475 return -2;
2476 }
2477
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002478 if (trust_root) {
2479 if (strcmp(trust_root, "DEFAULT") == 0 && !domain &&
2480 !domain_suffix) {
2481 send_resp(dut, conn, SIGMA_ERROR,
2482 "errorCode,trustRootCA DEFAULT used without specifying Domain or DomainSuffix");
2483 return STATUS_SENT_ERROR;
2484 }
2485 res = set_trust_root(dut, conn, ifname, id, trust_root);
Jouni Malinen8ac93452019-08-14 15:19:13 +03002486 if (res != SUCCESS_SEND_STATUS)
2487 return res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002488 }
2489
Jouni Malinen53264f62019-05-03 13:04:40 +03002490 val = get_param(cmd, "ServerCert");
2491 if (val) {
2492 FILE *f;
2493 char *result = NULL, *pos;
2494
2495 snprintf(buf, sizeof(buf), "%s/%s.sha256", sigma_cert_path,
2496 val);
2497 f = fopen(buf, "r");
2498 if (f) {
2499 result = fgets(buf, sizeof(buf), f);
2500 fclose(f);
2501 }
2502 if (!result) {
2503 snprintf(buf2, sizeof(buf2),
2504 "ErrorCode,ServerCert hash could not be read from %s",
2505 buf);
2506 send_resp(dut, conn, SIGMA_ERROR, buf2);
2507 return STATUS_SENT_ERROR;
2508 }
2509 pos = strchr(buf, '\n');
2510 if (pos)
2511 *pos = '\0';
2512 snprintf(buf2, sizeof(buf2), "hash://server/sha256/%s", buf);
2513 if (set_network_quoted(ifname, id, "ca_cert", buf2) < 0)
2514 return ERROR_SEND_STATUS;
Jouni Malinen29108dc2019-06-13 23:42:11 +03002515
2516 snprintf(buf, sizeof(buf), "%s/%s.tod", sigma_cert_path, val);
2517 if (file_exists(buf)) {
2518 sigma_dut_print(dut, DUT_MSG_DEBUG,
2519 "TOD policy enabled for the configured ServerCert hash");
2520 dut->sta_tod_policy = 1;
2521 }
Jouni Malinen53264f62019-05-03 13:04:40 +03002522 }
2523
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002524 if (domain &&
2525 set_network_quoted(ifname, id, "domain_match", domain) < 0)
Jouni Malinen96f84b02019-05-03 12:32:56 +03002526 return ERROR_SEND_STATUS;
2527
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002528 if (domain_suffix &&
2529 set_network_quoted(ifname, id, "domain_suffix_match",
2530 domain_suffix) < 0)
Jouni Malinen96f84b02019-05-03 12:32:56 +03002531 return ERROR_SEND_STATUS;
2532
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302533 if (username_identity) {
2534 val = get_param(cmd, "username");
2535 if (val) {
2536 if (set_network_quoted(ifname, id, "identity", val) < 0)
2537 return -2;
2538 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002539
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302540 val = get_param(cmd, "password");
2541 if (val) {
2542 if (set_network_quoted(ifname, id, "password", val) < 0)
2543 return -2;
2544 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002545 }
2546
Jouni Malinen8179fee2019-03-28 03:19:47 +02002547 if (dut->akm_values &
2548 ((1 << AKM_FILS_SHA256) |
2549 (1 << AKM_FILS_SHA384) |
2550 (1 << AKM_FT_FILS_SHA256) |
2551 (1 << AKM_FT_FILS_SHA384)))
2552 erp = 1;
2553 if (erp && set_network(ifname, id, "erp", "1") < 0)
2554 return ERROR_SEND_STATUS;
2555
Jouni Malinen134fe3c2019-06-12 04:16:49 +03002556 dut->sta_associate_wait_connect = 1;
2557
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002558 return id;
2559}
2560
2561
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002562static int set_tls_cipher(const char *ifname, int id, const char *cipher)
2563{
2564 const char *val;
2565
2566 if (!cipher)
2567 return 0;
2568
2569 if (strcasecmp(cipher, "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384") == 0)
2570 val = "ECDHE-ECDSA-AES256-GCM-SHA384";
2571 else if (strcasecmp(cipher,
2572 "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
2573 val = "ECDHE-RSA-AES256-GCM-SHA384";
2574 else if (strcasecmp(cipher, "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
2575 val = "DHE-RSA-AES256-GCM-SHA384";
2576 else if (strcasecmp(cipher,
2577 "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256") == 0)
2578 val = "ECDHE-ECDSA-AES128-GCM-SHA256";
2579 else
2580 return -1;
2581
2582 /* Need to clear phase1="tls_suiteb=1" to allow cipher enforcement */
2583 set_network_quoted(ifname, id, "phase1", "");
2584
2585 return set_network_quoted(ifname, id, "openssl_ciphers", val);
2586}
2587
2588
Jouni Malinenf7222712019-06-13 01:50:21 +03002589static enum sigma_cmd_result cmd_sta_set_eaptls(struct sigma_dut *dut,
2590 struct sigma_conn *conn,
2591 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002592{
2593 const char *intf = get_param(cmd, "Interface");
2594 const char *ifname, *val;
2595 int id;
2596 char buf[200];
2597#ifdef ANDROID
2598 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
2599 int length;
2600 int jb_or_newer = 0;
2601 char prop[PROPERTY_VALUE_MAX];
2602#endif /* ANDROID */
2603
2604 if (intf == NULL)
2605 return -1;
2606
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002607 if (strcmp(intf, get_main_ifname(dut)) == 0)
2608 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002609 else
2610 ifname = intf;
2611
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302612 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002613 if (id < 0)
2614 return id;
2615
2616 if (set_network(ifname, id, "eap", "TLS") < 0)
2617 return -2;
2618
Pradeep Reddy POTTETI9f6c2132016-05-05 16:28:19 +05302619 if (!get_param(cmd, "username") &&
2620 set_network_quoted(ifname, id, "identity",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002621 "wifi-user@wifilabs.local") < 0)
2622 return -2;
2623
2624 val = get_param(cmd, "clientCertificate");
2625 if (val == NULL)
2626 return -1;
2627#ifdef ANDROID
2628 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2629 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
2630 if (length < 0) {
2631 /*
2632 * JB started reporting keystore type mismatches, so retry with
2633 * the GET_PUBKEY command if the generic GET fails.
2634 */
2635 length = android_keystore_get(ANDROID_KEYSTORE_GET_PUBKEY,
2636 buf, kvalue);
2637 }
2638
2639 if (property_get("ro.build.version.release", prop, NULL) != 0) {
2640 sigma_dut_print(dut, DUT_MSG_DEBUG, "Android release %s", prop);
2641 if (strncmp(prop, "4.0", 3) != 0)
2642 jb_or_newer = 1;
2643 } else
2644 jb_or_newer = 1; /* assume newer */
2645
2646 if (jb_or_newer && length > 0) {
2647 sigma_dut_print(dut, DUT_MSG_INFO,
2648 "Use Android keystore [%s]", buf);
2649 if (set_network(ifname, id, "engine", "1") < 0)
2650 return -2;
2651 if (set_network_quoted(ifname, id, "engine_id", "keystore") < 0)
2652 return -2;
2653 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2654 if (set_network_quoted(ifname, id, "key_id", buf) < 0)
2655 return -2;
2656 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2657 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2658 return -2;
2659 return 1;
2660 } else if (length > 0) {
2661 sigma_dut_print(dut, DUT_MSG_INFO,
2662 "Use Android keystore [%s]", buf);
2663 snprintf(buf, sizeof(buf), "keystore://USRPKEY_%s", val);
2664 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2665 return -2;
2666 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2667 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2668 return -2;
2669 return 1;
2670 }
2671#endif /* ANDROID */
2672
2673 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
2674#ifdef __linux__
2675 if (!file_exists(buf)) {
2676 char msg[300];
2677 snprintf(msg, sizeof(msg), "ErrorCode,clientCertificate file "
2678 "(%s) not found", buf);
2679 send_resp(dut, conn, SIGMA_ERROR, msg);
2680 return -3;
2681 }
2682#endif /* __linux__ */
2683 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2684 return -2;
2685 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2686 return -2;
2687
2688 if (set_network_quoted(ifname, id, "private_key_passwd", "wifi") < 0)
2689 return -2;
2690
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002691 val = get_param(cmd, "keyMgmtType");
2692 if (val && strcasecmp(val, "SuiteB") == 0) {
2693 val = get_param(cmd, "CertType");
2694 if (val && strcasecmp(val, "RSA") == 0) {
2695 if (set_network_quoted(ifname, id, "phase1",
2696 "tls_suiteb=1") < 0)
2697 return -2;
2698 } else {
2699 if (set_network_quoted(ifname, id, "openssl_ciphers",
2700 "SUITEB192") < 0)
2701 return -2;
2702 }
2703
2704 val = get_param(cmd, "TLSCipher");
2705 if (set_tls_cipher(ifname, id, val) < 0) {
2706 send_resp(dut, conn, SIGMA_ERROR,
2707 "ErrorCode,Unsupported TLSCipher value");
2708 return -3;
2709 }
2710 }
2711
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002712 return 1;
2713}
2714
2715
Jouni Malinenf7222712019-06-13 01:50:21 +03002716static enum sigma_cmd_result cmd_sta_set_eapttls(struct sigma_dut *dut,
2717 struct sigma_conn *conn,
2718 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002719{
2720 const char *intf = get_param(cmd, "Interface");
2721 const char *ifname;
2722 int id;
2723
2724 if (intf == NULL)
2725 return -1;
2726
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002727 if (strcmp(intf, get_main_ifname(dut)) == 0)
2728 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002729 else
2730 ifname = intf;
2731
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302732 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002733 if (id < 0)
2734 return id;
2735
2736 if (set_network(ifname, id, "eap", "TTLS") < 0) {
2737 send_resp(dut, conn, SIGMA_ERROR,
2738 "errorCode,Failed to set TTLS method");
2739 return 0;
2740 }
2741
2742 if (set_network_quoted(ifname, id, "phase2", "auth=MSCHAPV2") < 0) {
2743 send_resp(dut, conn, SIGMA_ERROR,
2744 "errorCode,Failed to set MSCHAPv2 for TTLS Phase 2");
2745 return 0;
2746 }
2747
2748 return 1;
2749}
2750
2751
Jouni Malinenf7222712019-06-13 01:50:21 +03002752static enum sigma_cmd_result cmd_sta_set_eapsim(struct sigma_dut *dut,
2753 struct sigma_conn *conn,
2754 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002755{
2756 const char *intf = get_param(cmd, "Interface");
2757 const char *ifname;
2758 int id;
2759
2760 if (intf == NULL)
2761 return -1;
2762
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002763 if (strcmp(intf, get_main_ifname(dut)) == 0)
2764 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002765 else
2766 ifname = intf;
2767
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302768 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002769 if (id < 0)
2770 return id;
2771
2772 if (set_network(ifname, id, "eap", "SIM") < 0)
2773 return -2;
2774
2775 return 1;
2776}
2777
2778
Jouni Malinenf7222712019-06-13 01:50:21 +03002779static enum sigma_cmd_result cmd_sta_set_peap(struct sigma_dut *dut,
2780 struct sigma_conn *conn,
2781 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002782{
2783 const char *intf = get_param(cmd, "Interface");
2784 const char *ifname, *val;
2785 int id;
2786 char buf[100];
2787
2788 if (intf == NULL)
2789 return -1;
2790
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002791 if (strcmp(intf, get_main_ifname(dut)) == 0)
2792 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002793 else
2794 ifname = intf;
2795
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302796 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002797 if (id < 0)
2798 return id;
2799
2800 if (set_network(ifname, id, "eap", "PEAP") < 0)
2801 return -2;
2802
2803 val = get_param(cmd, "innerEAP");
2804 if (val) {
2805 if (strcasecmp(val, "MSCHAPv2") == 0) {
2806 if (set_network_quoted(ifname, id, "phase2",
2807 "auth=MSCHAPV2") < 0)
2808 return -2;
2809 } else if (strcasecmp(val, "GTC") == 0) {
2810 if (set_network_quoted(ifname, id, "phase2",
2811 "auth=GTC") < 0)
2812 return -2;
2813 } else
2814 return -1;
2815 }
2816
2817 val = get_param(cmd, "peapVersion");
2818 if (val) {
2819 int ver = atoi(val);
2820 if (ver < 0 || ver > 1)
2821 return -1;
2822 snprintf(buf, sizeof(buf), "peapver=%d", ver);
2823 if (set_network_quoted(ifname, id, "phase1", buf) < 0)
2824 return -2;
2825 }
2826
2827 return 1;
2828}
2829
2830
Jouni Malinenf7222712019-06-13 01:50:21 +03002831static enum sigma_cmd_result cmd_sta_set_eapfast(struct sigma_dut *dut,
2832 struct sigma_conn *conn,
2833 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002834{
2835 const char *intf = get_param(cmd, "Interface");
2836 const char *ifname, *val;
2837 int id;
2838 char buf[100];
2839
2840 if (intf == NULL)
2841 return -1;
2842
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002843 if (strcmp(intf, get_main_ifname(dut)) == 0)
2844 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002845 else
2846 ifname = intf;
2847
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302848 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002849 if (id < 0)
2850 return id;
2851
2852 if (set_network(ifname, id, "eap", "FAST") < 0)
2853 return -2;
2854
2855 val = get_param(cmd, "innerEAP");
2856 if (val) {
2857 if (strcasecmp(val, "MSCHAPV2") == 0) {
2858 if (set_network_quoted(ifname, id, "phase2",
2859 "auth=MSCHAPV2") < 0)
2860 return -2;
2861 } else if (strcasecmp(val, "GTC") == 0) {
2862 if (set_network_quoted(ifname, id, "phase2",
2863 "auth=GTC") < 0)
2864 return -2;
2865 } else
2866 return -1;
2867 }
2868
2869 val = get_param(cmd, "validateServer");
2870 if (val) {
2871 /* TODO */
2872 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored EAP-FAST "
2873 "validateServer=%s", val);
2874 }
2875
2876 val = get_param(cmd, "pacFile");
2877 if (val) {
2878 snprintf(buf, sizeof(buf), "blob://%s", val);
2879 if (set_network_quoted(ifname, id, "pac_file", buf) < 0)
2880 return -2;
2881 }
2882
2883 if (set_network_quoted(ifname, id, "phase1", "fast_provisioning=2") <
2884 0)
2885 return -2;
2886
2887 return 1;
2888}
2889
2890
Jouni Malinenf7222712019-06-13 01:50:21 +03002891static enum sigma_cmd_result cmd_sta_set_eapaka(struct sigma_dut *dut,
2892 struct sigma_conn *conn,
2893 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002894{
2895 const char *intf = get_param(cmd, "Interface");
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302896 const char *username = get_param(cmd, "Username");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002897 const char *ifname;
2898 int id;
2899
2900 if (intf == NULL)
2901 return -1;
2902
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002903 if (strcmp(intf, get_main_ifname(dut)) == 0)
2904 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002905 else
2906 ifname = intf;
2907
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302908 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002909 if (id < 0)
2910 return id;
2911
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302912 /* RFC 5448: EAP-AKA' MUST use the leading character "6" (ASCII 36
2913 * hexadecimal).
2914 */
2915 if (username && username[0] == '6') {
2916 if (set_network(ifname, id, "eap", "AKA'") < 0)
2917 return -2;
2918 } else if (set_network(ifname, id, "eap", "AKA") < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002919 return -2;
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302920 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002921
2922 return 1;
2923}
2924
2925
Jouni Malinenf7222712019-06-13 01:50:21 +03002926static enum sigma_cmd_result cmd_sta_set_eapakaprime(struct sigma_dut *dut,
2927 struct sigma_conn *conn,
2928 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002929{
2930 const char *intf = get_param(cmd, "Interface");
2931 const char *ifname;
2932 int id;
2933
2934 if (intf == NULL)
2935 return -1;
2936
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002937 if (strcmp(intf, get_main_ifname(dut)) == 0)
2938 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002939 else
2940 ifname = intf;
2941
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302942 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002943 if (id < 0)
2944 return id;
2945
2946 if (set_network(ifname, id, "eap", "AKA'") < 0)
2947 return -2;
2948
2949 return 1;
2950}
2951
2952
2953static int sta_set_open(struct sigma_dut *dut, struct sigma_conn *conn,
2954 struct sigma_cmd *cmd)
2955{
2956 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002957 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002958 const char *ifname;
2959 int id;
2960
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002961 if (strcmp(intf, get_main_ifname(dut)) == 0)
2962 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002963 else
2964 ifname = intf;
2965
2966 id = add_network_common(dut, conn, ifname, cmd);
2967 if (id < 0)
2968 return id;
2969
2970 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
2971 return -2;
2972
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002973 if (dut->program == PROGRAM_60GHZ && network_mode &&
2974 strcasecmp(network_mode, "PBSS") == 0 &&
2975 set_network(ifname, id, "pbss", "1") < 0)
2976 return -2;
2977
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002978 return 1;
2979}
2980
2981
Jouni Malinen47dcc952017-10-09 16:43:24 +03002982static int sta_set_owe(struct sigma_dut *dut, struct sigma_conn *conn,
2983 struct sigma_cmd *cmd)
2984{
2985 const char *intf = get_param(cmd, "Interface");
2986 const char *ifname, *val;
2987 int id;
2988
2989 if (intf == NULL)
2990 return -1;
2991
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002992 if (strcmp(intf, get_main_ifname(dut)) == 0)
2993 ifname = get_station_ifname(dut);
Jouni Malinen47dcc952017-10-09 16:43:24 +03002994 else
2995 ifname = intf;
2996
2997 id = set_wpa_common(dut, conn, ifname, cmd);
2998 if (id < 0)
2999 return id;
3000
3001 if (set_network(ifname, id, "key_mgmt", "OWE") < 0)
3002 return -2;
3003
3004 val = get_param(cmd, "ECGroupID");
Jouni Malinenfac9cad2017-10-10 18:35:55 +03003005 if (val && strcmp(val, "0") == 0) {
3006 if (wpa_command(ifname,
3007 "VENDOR_ELEM_ADD 13 ff23200000783590fb7440e03d5b3b33911f86affdcc6b4411b707846ac4ff08ddc8831ccd") != 0) {
3008 sigma_dut_print(dut, DUT_MSG_ERROR,
3009 "Failed to set OWE DH Param element override");
3010 return -2;
3011 }
Hu Wang6010ce72020-03-05 19:33:53 +08003012 } else if (val &&
3013 (set_network(ifname, id, "owe_group", val) < 0 ||
3014 (dut->owe_ptk_workaround &&
3015 set_network(ifname, id, "owe_ptk_workaround", "1") < 0))) {
Jouni Malinen47dcc952017-10-09 16:43:24 +03003016 sigma_dut_print(dut, DUT_MSG_ERROR,
Hu Wang6010ce72020-03-05 19:33:53 +08003017 "Failed to set owe_group");
Jouni Malinen47dcc952017-10-09 16:43:24 +03003018 return -2;
3019 }
3020
3021 return 1;
3022}
3023
3024
Jouni Malinenf7222712019-06-13 01:50:21 +03003025static enum sigma_cmd_result cmd_sta_set_security(struct sigma_dut *dut,
3026 struct sigma_conn *conn,
3027 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003028{
3029 const char *type = get_param(cmd, "Type");
3030
3031 if (type == NULL) {
3032 send_resp(dut, conn, SIGMA_ERROR,
3033 "ErrorCode,Missing Type argument");
3034 return 0;
3035 }
3036
3037 if (strcasecmp(type, "OPEN") == 0)
3038 return sta_set_open(dut, conn, cmd);
Jouni Malinen47dcc952017-10-09 16:43:24 +03003039 if (strcasecmp(type, "OWE") == 0)
3040 return sta_set_owe(dut, conn, cmd);
Jouni Malinen992a81e2017-08-22 13:57:47 +03003041 if (strcasecmp(type, "PSK") == 0 ||
Jouni Malinen0ab50f42017-08-31 01:34:59 +03003042 strcasecmp(type, "PSK-SAE") == 0 ||
Jouni Malinen992a81e2017-08-22 13:57:47 +03003043 strcasecmp(type, "SAE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003044 return cmd_sta_set_psk(dut, conn, cmd);
3045 if (strcasecmp(type, "EAPTLS") == 0)
3046 return cmd_sta_set_eaptls(dut, conn, cmd);
3047 if (strcasecmp(type, "EAPTTLS") == 0)
3048 return cmd_sta_set_eapttls(dut, conn, cmd);
3049 if (strcasecmp(type, "EAPPEAP") == 0)
3050 return cmd_sta_set_peap(dut, conn, cmd);
3051 if (strcasecmp(type, "EAPSIM") == 0)
3052 return cmd_sta_set_eapsim(dut, conn, cmd);
3053 if (strcasecmp(type, "EAPFAST") == 0)
3054 return cmd_sta_set_eapfast(dut, conn, cmd);
3055 if (strcasecmp(type, "EAPAKA") == 0)
3056 return cmd_sta_set_eapaka(dut, conn, cmd);
3057 if (strcasecmp(type, "EAPAKAPRIME") == 0)
3058 return cmd_sta_set_eapakaprime(dut, conn, cmd);
Amarnath Hullur Subramanyam81b11cd2018-01-30 19:07:17 -08003059 if (strcasecmp(type, "wep") == 0)
3060 return cmd_sta_set_encryption(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003061
3062 send_resp(dut, conn, SIGMA_ERROR,
3063 "ErrorCode,Unsupported Type value");
3064 return 0;
3065}
3066
3067
3068int ath6kl_client_uapsd(struct sigma_dut *dut, const char *intf, int uapsd)
3069{
3070#ifdef __linux__
3071 /* special handling for ath6kl */
3072 char path[128], fname[128], *pos;
3073 ssize_t res;
3074 FILE *f;
3075
Jouni Malinene39cd562019-05-29 23:39:56 +03003076 res = snprintf(fname, sizeof(fname), "/sys/class/net/%s/phy80211",
3077 intf);
3078 if (res < 0 || res >= sizeof(fname))
3079 return 0;
3080 res = readlink(fname, path, sizeof(path));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003081 if (res < 0)
3082 return 0; /* not ath6kl */
3083
3084 if (res >= (int) sizeof(path))
3085 res = sizeof(path) - 1;
3086 path[res] = '\0';
3087 pos = strrchr(path, '/');
3088 if (pos == NULL)
3089 pos = path;
3090 else
3091 pos++;
Jouni Malinen77dda642020-01-07 11:21:55 +02003092 res = snprintf(fname, sizeof(fname),
3093 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
3094 "create_qos", pos);
3095 if (res < 0 || res >= sizeof(fname) || !file_exists(fname))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003096 return 0; /* not ath6kl */
3097
3098 if (uapsd) {
3099 f = fopen(fname, "w");
3100 if (f == NULL)
3101 return -1;
3102
3103 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl create_qos");
3104 fprintf(f, "4 2 2 1 2 9999999 9999999 9999999 7777777 0 4 "
3105 "45000 200 56789000 56789000 5678900 0 0 9999999 "
3106 "20000 0\n");
3107 fclose(f);
3108 } else {
Jouni Malinen77dda642020-01-07 11:21:55 +02003109 res = snprintf(fname, sizeof(fname),
3110 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
3111 "delete_qos", pos);
3112 if (res < 0 || res >= sizeof(fname))
3113 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003114
3115 f = fopen(fname, "w");
3116 if (f == NULL)
3117 return -1;
3118
3119 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl delete_qos");
3120 fprintf(f, "2 4\n");
3121 fclose(f);
3122 }
3123#endif /* __linux__ */
3124
3125 return 0;
3126}
3127
3128
Jouni Malinenf7222712019-06-13 01:50:21 +03003129static enum sigma_cmd_result cmd_sta_set_uapsd(struct sigma_dut *dut,
3130 struct sigma_conn *conn,
3131 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003132{
3133 const char *intf = get_param(cmd, "Interface");
3134 /* const char *ssid = get_param(cmd, "ssid"); */
3135 const char *val;
3136 int max_sp_len = 4;
3137 int ac_be = 1, ac_bk = 1, ac_vi = 1, ac_vo = 1;
3138 char buf[100];
3139 int ret1, ret2;
3140
3141 val = get_param(cmd, "maxSPLength");
3142 if (val) {
3143 max_sp_len = atoi(val);
3144 if (max_sp_len != 0 && max_sp_len != 1 && max_sp_len != 2 &&
3145 max_sp_len != 4)
3146 return -1;
3147 }
3148
3149 val = get_param(cmd, "acBE");
3150 if (val)
3151 ac_be = atoi(val);
3152
3153 val = get_param(cmd, "acBK");
3154 if (val)
3155 ac_bk = atoi(val);
3156
3157 val = get_param(cmd, "acVI");
3158 if (val)
3159 ac_vi = atoi(val);
3160
3161 val = get_param(cmd, "acVO");
3162 if (val)
3163 ac_vo = atoi(val);
3164
3165 dut->client_uapsd = ac_be || ac_bk || ac_vi || ac_vo;
3166
3167 snprintf(buf, sizeof(buf), "P2P_SET client_apsd %d,%d,%d,%d;%d",
3168 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
3169 ret1 = wpa_command(intf, buf);
3170
3171 snprintf(buf, sizeof(buf), "SET uapsd %d,%d,%d,%d;%d",
3172 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
3173 ret2 = wpa_command(intf, buf);
3174
3175 if (ret1 && ret2) {
3176 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to set client mode "
3177 "UAPSD parameters.");
3178 return -2;
3179 }
3180
3181 if (ath6kl_client_uapsd(dut, intf, dut->client_uapsd) < 0) {
3182 send_resp(dut, conn, SIGMA_ERROR,
3183 "ErrorCode,Failed to set ath6kl QoS parameters");
3184 return 0;
3185 }
3186
3187 return 1;
3188}
3189
3190
Jouni Malinenf7222712019-06-13 01:50:21 +03003191static enum sigma_cmd_result cmd_sta_set_wmm(struct sigma_dut *dut,
3192 struct sigma_conn *conn,
3193 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003194{
3195 char buf[1000];
3196 const char *intf = get_param(cmd, "Interface");
3197 const char *grp = get_param(cmd, "Group");
3198 const char *act = get_param(cmd, "Action");
3199 const char *tid = get_param(cmd, "Tid");
3200 const char *dir = get_param(cmd, "Direction");
3201 const char *psb = get_param(cmd, "Psb");
3202 const char *up = get_param(cmd, "Up");
3203 const char *fixed = get_param(cmd, "Fixed");
3204 const char *size = get_param(cmd, "Size");
3205 const char *msize = get_param(cmd, "Maxsize");
3206 const char *minsi = get_param(cmd, "Min_srvc_intrvl");
3207 const char *maxsi = get_param(cmd, "Max_srvc_intrvl");
3208 const char *inact = get_param(cmd, "Inactivity");
3209 const char *sus = get_param(cmd, "Suspension");
3210 const char *mindr = get_param(cmd, "Mindatarate");
3211 const char *meandr = get_param(cmd, "Meandatarate");
3212 const char *peakdr = get_param(cmd, "Peakdatarate");
3213 const char *phyrate = get_param(cmd, "Phyrate");
3214 const char *burstsize = get_param(cmd, "Burstsize");
3215 const char *sba = get_param(cmd, "Sba");
3216 int direction;
3217 int handle;
Peng Xu93319622017-10-04 17:58:16 -07003218 float sba_fv = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003219 int fixed_int;
3220 int psb_ts;
3221
3222 if (intf == NULL || grp == NULL || act == NULL )
3223 return -1;
3224
3225 if (strcasecmp(act, "addts") == 0) {
3226 if (tid == NULL || dir == NULL || psb == NULL ||
3227 up == NULL || fixed == NULL || size == NULL)
3228 return -1;
3229
3230 /*
3231 * Note: Sigma CAPI spec lists uplink, downlink, and bidi as the
3232 * possible values, but WMM-AC and V-E test scripts use "UP,
3233 * "DOWN", and "BIDI".
3234 */
3235 if (strcasecmp(dir, "uplink") == 0 ||
3236 strcasecmp(dir, "up") == 0) {
3237 direction = 0;
3238 } else if (strcasecmp(dir, "downlink") == 0 ||
3239 strcasecmp(dir, "down") == 0) {
3240 direction = 1;
3241 } else if (strcasecmp(dir, "bidi") == 0) {
3242 direction = 2;
3243 } else {
3244 sigma_dut_print(dut, DUT_MSG_ERROR,
3245 "Direction %s not supported", dir);
3246 return -1;
3247 }
3248
3249 if (strcasecmp(psb, "legacy") == 0) {
3250 psb_ts = 0;
3251 } else if (strcasecmp(psb, "uapsd") == 0) {
3252 psb_ts = 1;
3253 } else {
3254 sigma_dut_print(dut, DUT_MSG_ERROR,
3255 "PSB %s not supported", psb);
3256 return -1;
3257 }
3258
3259 if (atoi(tid) < 0 || atoi(tid) > 7) {
3260 sigma_dut_print(dut, DUT_MSG_ERROR,
3261 "TID %s not supported", tid);
3262 return -1;
3263 }
3264
3265 if (strcasecmp(fixed, "true") == 0) {
3266 fixed_int = 1;
3267 } else {
3268 fixed_int = 0;
3269 }
3270
Peng Xu93319622017-10-04 17:58:16 -07003271 if (sba)
3272 sba_fv = atof(sba);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003273
3274 dut->dialog_token++;
3275 handle = 7000 + dut->dialog_token;
3276
3277 /*
3278 * size: convert to hex
3279 * maxsi: convert to hex
3280 * mindr: convert to hex
3281 * meandr: convert to hex
3282 * peakdr: convert to hex
3283 * burstsize: convert to hex
3284 * phyrate: convert to hex
3285 * sba: convert to hex with modification
3286 * minsi: convert to integer
3287 * sus: convert to integer
3288 * inact: convert to integer
3289 * maxsi: convert to integer
3290 */
3291
3292 /*
3293 * The Nominal MSDU Size field is 2 octets long and contains an
3294 * unsigned integer that specifies the nominal size, in octets,
3295 * of MSDUs belonging to the traffic under this traffic
3296 * specification and is defined in Figure 16. If the Fixed
3297 * subfield is set to 1, then the size of the MSDU is fixed and
3298 * is indicated by the Size Subfield. If the Fixed subfield is
3299 * set to 0, then the size of the MSDU might not be fixed and
3300 * the Size indicates the nominal MSDU size.
3301 *
3302 * The Surplus Bandwidth Allowance Factor field is 2 octets long
3303 * and specifies the excess allocation of time (and bandwidth)
3304 * over and above the stated rates required to transport an MSDU
3305 * belonging to the traffic in this TSPEC. This field is
3306 * represented as an unsigned binary number with an implicit
3307 * binary point after the leftmost 3 bits. For example, an SBA
3308 * of 1.75 is represented as 0x3800. This field is included to
3309 * account for retransmissions. As such, the value of this field
3310 * must be greater than unity.
3311 */
3312
3313 snprintf(buf, sizeof(buf),
3314 "iwpriv %s addTspec %d %s %d %d %s 0x%X"
3315 " 0x%X 0x%X 0x%X"
3316 " 0x%X 0x%X 0x%X"
3317 " 0x%X %d %d %d %d"
3318 " %d %d",
3319 intf, handle, tid, direction, psb_ts, up,
3320 (unsigned int) ((fixed_int << 15) | atoi(size)),
3321 msize ? atoi(msize) : 0,
3322 mindr ? atoi(mindr) : 0,
3323 meandr ? atoi(meandr) : 0,
3324 peakdr ? atoi(peakdr) : 0,
3325 burstsize ? atoi(burstsize) : 0,
3326 phyrate ? atoi(phyrate) : 0,
3327 sba ? ((unsigned int) (((int) sba_fv << 13) |
3328 (int)((sba_fv - (int) sba_fv) *
3329 8192))) : 0,
3330 minsi ? atoi(minsi) : 0,
3331 sus ? atoi(sus) : 0,
3332 0, 0,
3333 inact ? atoi(inact) : 0,
3334 maxsi ? atoi(maxsi) : 0);
3335
3336 if (system(buf) != 0) {
3337 sigma_dut_print(dut, DUT_MSG_ERROR,
3338 "iwpriv addtspec request failed");
3339 send_resp(dut, conn, SIGMA_ERROR,
3340 "errorCode,Failed to execute addTspec command");
3341 return 0;
3342 }
3343
3344 sigma_dut_print(dut, DUT_MSG_INFO,
3345 "iwpriv addtspec request send");
3346
3347 /* Mapping handle to a TID */
3348 dut->tid_to_handle[atoi(tid)] = handle;
3349 } else if (strcasecmp(act, "delts") == 0) {
3350 if (tid == NULL)
3351 return -1;
3352
3353 if (atoi(tid) < 0 || atoi(tid) > 7) {
3354 sigma_dut_print(dut, DUT_MSG_ERROR,
3355 "TID %s not supported", tid);
3356 send_resp(dut, conn, SIGMA_ERROR,
3357 "errorCode,Unsupported TID");
3358 return 0;
3359 }
3360
3361 handle = dut->tid_to_handle[atoi(tid)];
3362
3363 if (handle < 7000 || handle > 7255) {
3364 /* Invalid handle ie no mapping for that TID */
3365 sigma_dut_print(dut, DUT_MSG_ERROR,
3366 "handle-> %d not found", handle);
3367 }
3368
3369 snprintf(buf, sizeof(buf), "iwpriv %s delTspec %d",
3370 intf, handle);
3371
3372 if (system(buf) != 0) {
3373 sigma_dut_print(dut, DUT_MSG_ERROR,
3374 "iwpriv deltspec request failed");
3375 send_resp(dut, conn, SIGMA_ERROR,
3376 "errorCode,Failed to execute delTspec command");
3377 return 0;
3378 }
3379
3380 sigma_dut_print(dut, DUT_MSG_INFO,
3381 "iwpriv deltspec request send");
3382
3383 dut->tid_to_handle[atoi(tid)] = 0;
3384 } else {
3385 sigma_dut_print(dut, DUT_MSG_ERROR,
3386 "Action type %s not supported", act);
3387 send_resp(dut, conn, SIGMA_ERROR,
3388 "errorCode,Unsupported Action");
3389 return 0;
3390 }
3391
3392 return 1;
3393}
3394
3395
vamsi krishna52e16f92017-08-29 12:37:34 +05303396static int find_network(struct sigma_dut *dut, const char *ssid)
3397{
3398 char list[4096];
3399 char *pos;
3400
3401 sigma_dut_print(dut, DUT_MSG_DEBUG,
3402 "Search for profile based on SSID: '%s'", ssid);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003403 if (wpa_command_resp(get_station_ifname(dut), "LIST_NETWORKS",
vamsi krishna52e16f92017-08-29 12:37:34 +05303404 list, sizeof(list)) < 0)
3405 return -1;
3406 pos = strstr(list, ssid);
3407 if (!pos || pos == list || pos[-1] != '\t' || pos[strlen(ssid)] != '\t')
3408 return -1;
3409
3410 while (pos > list && pos[-1] != '\n')
3411 pos--;
3412 dut->infra_network_id = atoi(pos);
3413 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
3414 return 0;
3415}
3416
3417
Sunil Dutt44595082018-02-12 19:41:45 +05303418#ifdef NL80211_SUPPORT
3419static int sta_config_rsnie(struct sigma_dut *dut, int val)
3420{
3421 struct nl_msg *msg;
3422 int ret;
3423 struct nlattr *params;
3424 int ifindex;
3425
3426 ifindex = if_nametoindex("wlan0");
3427 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
3428 NL80211_CMD_VENDOR)) ||
3429 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
3430 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
3431 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
3432 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) ||
3433 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
3434 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE, val)) {
3435 sigma_dut_print(dut, DUT_MSG_ERROR,
3436 "%s: err in adding vendor_cmd and vendor_data",
3437 __func__);
3438 nlmsg_free(msg);
3439 return -1;
3440 }
3441 nla_nest_end(msg, params);
3442
3443 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
3444 if (ret) {
3445 sigma_dut_print(dut, DUT_MSG_ERROR,
3446 "%s: err in send_and_recv_msgs, ret=%d",
3447 __func__, ret);
3448 return ret;
3449 }
3450
3451 return 0;
3452}
3453#endif /* NL80211_SUPPORT */
3454
3455
Jouni Malinenf7222712019-06-13 01:50:21 +03003456static enum sigma_cmd_result cmd_sta_associate(struct sigma_dut *dut,
3457 struct sigma_conn *conn,
3458 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003459{
3460 /* const char *intf = get_param(cmd, "Interface"); */
3461 const char *ssid = get_param(cmd, "ssid");
3462 const char *wps_param = get_param(cmd, "WPS");
3463 const char *bssid = get_param(cmd, "bssid");
Jouni Malinen46a19b62017-06-23 14:31:27 +03003464 const char *chan = get_param(cmd, "channel");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003465 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003466 int wps = 0;
Jouni Malinen3c367e82017-06-23 17:01:47 +03003467 char buf[1000], extra[50];
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003468 int e;
3469 enum sigma_cmd_result ret = SUCCESS_SEND_STATUS;
3470 struct wpa_ctrl *ctrl = NULL;
3471 int num_network_not_found = 0;
3472 int num_disconnected = 0;
3473 int tod = -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003474
3475 if (ssid == NULL)
3476 return -1;
3477
Jouni Malinen37d5c692019-08-19 16:56:55 +03003478 dut->server_cert_tod = 0;
3479
Jouni Malinen3c367e82017-06-23 17:01:47 +03003480 if (dut->rsne_override) {
Sunil Dutt44595082018-02-12 19:41:45 +05303481#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003482 if (get_driver_type(dut) == DRIVER_WCN) {
Sunil Dutt44595082018-02-12 19:41:45 +05303483 sta_config_rsnie(dut, 1);
3484 dut->config_rsnie = 1;
3485 }
3486#endif /* NL80211_SUPPORT */
Jouni Malinen3c367e82017-06-23 17:01:47 +03003487 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
3488 dut->rsne_override);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003489 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinen3c367e82017-06-23 17:01:47 +03003490 send_resp(dut, conn, SIGMA_ERROR,
3491 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
3492 return 0;
3493 }
3494 }
3495
Jouni Malinen68143132017-09-02 02:34:08 +03003496 if (dut->sae_commit_override) {
3497 snprintf(buf, sizeof(buf), "SET sae_commit_override %s",
3498 dut->sae_commit_override);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003499 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinen68143132017-09-02 02:34:08 +03003500 send_resp(dut, conn, SIGMA_ERROR,
3501 "ErrorCode,Failed to set SAE commit override");
3502 return 0;
3503 }
3504 }
Ankita Bajaj1bde7942018-01-09 19:15:01 +05303505#ifdef ANDROID
3506 if (dut->fils_hlp)
3507 process_fils_hlp(dut);
3508#endif /* ANDROID */
Jouni Malinen68143132017-09-02 02:34:08 +03003509
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003510 if (wps_param &&
3511 (strcmp(wps_param, "1") == 0 || strcasecmp(wps_param, "On") == 0))
3512 wps = 1;
3513
Vamsi Krishnac1633d22020-05-06 18:31:21 +05303514 if (dut->ocvc &&
3515 set_network(get_station_ifname(dut), dut->infra_network_id,
3516 "ocv", "1") < 0)
3517 return ERROR_SEND_STATUS;
3518
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003519 if (wps) {
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003520 if (dut->program == PROGRAM_60GHZ && network_mode &&
3521 strcasecmp(network_mode, "PBSS") == 0 &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003522 set_network(get_station_ifname(dut), dut->infra_network_id,
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003523 "pbss", "1") < 0)
3524 return -2;
3525
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003526 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
3527 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,WPS "
3528 "parameters not yet set");
3529 return 0;
3530 }
3531 if (dut->wps_method == WFA_CS_WPS_PBC) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003532 if (wpa_command(get_station_ifname(dut), "WPS_PBC") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003533 return -2;
3534 } else {
3535 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
3536 dut->wps_pin);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003537 if (wpa_command(get_station_ifname(dut), buf) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003538 return -2;
3539 }
3540 } else {
vamsi krishna52e16f92017-08-29 12:37:34 +05303541 if (strcmp(ssid, dut->infra_ssid) == 0) {
3542 sigma_dut_print(dut, DUT_MSG_DEBUG,
3543 "sta_associate for the most recently added network");
3544 } else if (find_network(dut, ssid) < 0) {
3545 sigma_dut_print(dut, DUT_MSG_DEBUG,
3546 "sta_associate for a previously stored network profile");
3547 send_resp(dut, conn, SIGMA_ERROR,
3548 "ErrorCode,Profile not found");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003549 return 0;
3550 }
3551
3552 if (bssid &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003553 set_network(get_station_ifname(dut), dut->infra_network_id,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003554 "bssid", bssid) < 0) {
3555 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3556 "Invalid bssid argument");
3557 return 0;
3558 }
3559
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003560 if (dut->program == PROGRAM_WPA3 &&
3561 dut->sta_associate_wait_connect) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003562 ctrl = open_wpa_mon(get_station_ifname(dut));
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003563 if (!ctrl)
3564 return ERROR_SEND_STATUS;
3565 }
3566
Jouni Malinen46a19b62017-06-23 14:31:27 +03003567 extra[0] = '\0';
3568 if (chan)
3569 snprintf(extra, sizeof(extra), " freq=%u",
Alexei Avshalom Lazar093569f2018-11-13 14:08:17 +02003570 channel_to_freq(dut, atoi(chan)));
Jouni Malinen46a19b62017-06-23 14:31:27 +03003571 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d%s",
3572 dut->infra_network_id, extra);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003573 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003574 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to select "
3575 "network id %d on %s",
3576 dut->infra_network_id,
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003577 get_station_ifname(dut));
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003578 ret = ERROR_SEND_STATUS;
3579 goto done;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003580 }
3581 }
3582
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003583 if (!ctrl)
3584 return SUCCESS_SEND_STATUS;
3585
3586 /* Wait for connection result to be able to store server certificate
3587 * hash for trust root override testing
3588 * (dev_exec_action,ServerCertTrust). */
3589
3590 for (e = 0; e < 20; e++) {
3591 const char *events[] = {
3592 "CTRL-EVENT-EAP-PEER-CERT",
3593 "CTRL-EVENT-EAP-TLS-CERT-ERROR",
3594 "CTRL-EVENT-DISCONNECTED",
3595 "CTRL-EVENT-CONNECTED",
3596 "CTRL-EVENT-NETWORK-NOT-FOUND",
3597 NULL
3598 };
3599 char buf[1024];
3600 int res;
3601
3602 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
3603 if (res < 0) {
Jouni Malinenf1f16642019-11-15 21:19:04 +02003604 send_resp(dut, conn, SIGMA_COMPLETE,
3605 "Result,Association did not complete");
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003606 ret = STATUS_SENT_ERROR;
3607 break;
3608 }
3609 sigma_dut_print(dut, DUT_MSG_DEBUG, "Connection event: %s",
3610 buf);
3611
3612 if (strstr(buf, "CTRL-EVENT-EAP-PEER-CERT") &&
3613 strstr(buf, " depth=0")) {
3614 char *pos = strstr(buf, " hash=");
3615
3616 if (pos) {
3617 char *end;
3618
Jouni Malinen34b19cb2019-08-16 16:37:17 +03003619 if (strstr(buf, " tod=1"))
3620 tod = 1;
3621 else if (strstr(buf, " tod=2"))
3622 tod = 2;
3623 else
3624 tod = 0;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003625 sigma_dut_print(dut, DUT_MSG_DEBUG,
3626 "Server certificate TOD policy: %d",
3627 tod);
Jouni Malinen37d5c692019-08-19 16:56:55 +03003628 dut->server_cert_tod = tod;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003629
3630 pos += 6;
3631 end = strchr(pos, ' ');
3632 if (end)
3633 *end = '\0';
3634 strlcpy(dut->server_cert_hash, pos,
3635 sizeof(dut->server_cert_hash));
3636 sigma_dut_print(dut, DUT_MSG_DEBUG,
3637 "Server certificate hash: %s",
3638 dut->server_cert_hash);
3639 }
3640 }
3641
3642 if (strstr(buf, "CTRL-EVENT-EAP-TLS-CERT-ERROR")) {
3643 send_resp(dut, conn, SIGMA_COMPLETE,
3644 "Result,TLS server certificate validation failed");
3645 ret = STATUS_SENT_ERROR;
3646 break;
3647 }
3648
3649 if (strstr(buf, "CTRL-EVENT-NETWORK-NOT-FOUND")) {
3650 num_network_not_found++;
3651
3652 if (num_network_not_found > 2) {
3653 send_resp(dut, conn, SIGMA_COMPLETE,
3654 "Result,Network not found");
3655 ret = STATUS_SENT_ERROR;
3656 break;
3657 }
3658 }
3659
3660 if (strstr(buf, "CTRL-EVENT-DISCONNECTED")) {
3661 num_disconnected++;
3662
3663 if (num_disconnected > 2) {
3664 send_resp(dut, conn, SIGMA_COMPLETE,
3665 "Result,Connection failed");
3666 ret = STATUS_SENT_ERROR;
3667 break;
3668 }
3669 }
3670
3671 if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
3672 if (tod >= 0) {
3673 sigma_dut_print(dut, DUT_MSG_DEBUG,
3674 "Network profile TOD policy update: %d -> %d",
3675 dut->sta_tod_policy, tod);
3676 dut->sta_tod_policy = tod;
3677 }
3678 break;
3679 }
3680 }
3681done:
3682 if (ctrl) {
3683 wpa_ctrl_detach(ctrl);
3684 wpa_ctrl_close(ctrl);
3685 }
3686 return ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003687}
3688
3689
3690static int run_hs20_osu(struct sigma_dut *dut, const char *params)
3691{
3692 char buf[500], cmd[200];
3693 int res;
3694
3695 /* Use hs20-osu-client file at the current dir, if found; otherwise use
3696 * default path */
3697 res = snprintf(cmd, sizeof(cmd),
3698 "%s -w \"%s\" -r hs20-osu-client.res %s%s -dddKt -f Logs/hs20-osu-client.txt",
3699 file_exists("./hs20-osu-client") ?
3700 "./hs20-osu-client" : "hs20-osu-client",
3701 sigma_wpas_ctrl,
3702 dut->summary_log ? "-s " : "",
3703 dut->summary_log ? dut->summary_log : "");
3704 if (res < 0 || res >= (int) sizeof(cmd))
3705 return -1;
3706
3707 res = snprintf(buf, sizeof(buf), "%s %s", cmd, params);
3708 if (res < 0 || res >= (int) sizeof(buf))
3709 return -1;
3710 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
3711
3712 if (system(buf) != 0) {
3713 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run: %s", buf);
3714 return -1;
3715 }
3716 sigma_dut_print(dut, DUT_MSG_DEBUG,
3717 "Completed hs20-osu-client operation");
3718
3719 return 0;
3720}
3721
3722
3723static int download_ppsmo(struct sigma_dut *dut,
3724 struct sigma_conn *conn,
3725 const char *intf,
3726 struct sigma_cmd *cmd)
3727{
3728 const char *name, *path, *val;
3729 char url[500], buf[600], fbuf[100];
3730 char *fqdn = NULL;
3731
3732 name = get_param(cmd, "FileName");
3733 path = get_param(cmd, "FilePath");
3734 if (name == NULL || path == NULL)
3735 return -1;
3736
3737 if (strcasecmp(path, "VendorSpecific") == 0) {
3738 snprintf(url, sizeof(url), "PPS/%s", name);
3739 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured PPS MO "
3740 "from the device (%s)", url);
3741 if (!file_exists(url)) {
3742 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
3743 "PPS MO file does not exist");
3744 return 0;
3745 }
3746 snprintf(buf, sizeof(buf), "cp %s pps-tnds.xml", url);
3747 if (system(buf) != 0) {
3748 send_resp(dut, conn, SIGMA_ERROR,
3749 "errorCode,Failed to copy PPS MO");
3750 return 0;
3751 }
3752 } else if (strncasecmp(path, "http:", 5) != 0 &&
3753 strncasecmp(path, "https:", 6) != 0) {
3754 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3755 "Unsupported FilePath value");
3756 return 0;
3757 } else {
3758 snprintf(url, sizeof(url), "%s/%s", path, name);
3759 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading PPS MO from %s",
3760 url);
3761 snprintf(buf, sizeof(buf), "wget -T 10 -t 3 -O pps-tnds.xml '%s'", url);
3762 remove("pps-tnds.xml");
3763 if (system(buf) != 0) {
3764 send_resp(dut, conn, SIGMA_ERROR,
3765 "errorCode,Failed to download PPS MO");
3766 return 0;
3767 }
3768 }
3769
3770 if (run_hs20_osu(dut, "from_tnds pps-tnds.xml pps.xml") < 0) {
3771 send_resp(dut, conn, SIGMA_ERROR,
3772 "errorCode,Failed to parse downloaded PPSMO");
3773 return 0;
3774 }
3775 unlink("pps-tnds.xml");
3776
3777 val = get_param(cmd, "managementTreeURI");
3778 if (val) {
3779 const char *pos, *end;
3780 sigma_dut_print(dut, DUT_MSG_DEBUG, "managementTreeURI: %s",
3781 val);
3782 if (strncmp(val, "./Wi-Fi/", 8) != 0) {
3783 send_resp(dut, conn, SIGMA_ERROR,
3784 "errorCode,Invalid managementTreeURI prefix");
3785 return 0;
3786 }
3787 pos = val + 8;
3788 end = strchr(pos, '/');
3789 if (end == NULL ||
3790 strcmp(end, "/PerProviderSubscription") != 0) {
3791 send_resp(dut, conn, SIGMA_ERROR,
3792 "errorCode,Invalid managementTreeURI postfix");
3793 return 0;
3794 }
3795 if (end - pos >= (int) sizeof(fbuf)) {
3796 send_resp(dut, conn, SIGMA_ERROR,
3797 "errorCode,Too long FQDN in managementTreeURI");
3798 return 0;
3799 }
3800 memcpy(fbuf, pos, end - pos);
3801 fbuf[end - pos] = '\0';
3802 fqdn = fbuf;
3803 sigma_dut_print(dut, DUT_MSG_INFO,
3804 "FQDN from managementTreeURI: %s", fqdn);
3805 } else if (run_hs20_osu(dut, "get_fqdn pps.xml") == 0) {
3806 FILE *f = fopen("pps-fqdn", "r");
3807 if (f) {
3808 if (fgets(fbuf, sizeof(fbuf), f)) {
3809 fbuf[sizeof(fbuf) - 1] = '\0';
3810 fqdn = fbuf;
3811 sigma_dut_print(dut, DUT_MSG_DEBUG,
3812 "Use FQDN %s", fqdn);
3813 }
3814 fclose(f);
3815 }
3816 }
3817
3818 if (fqdn == NULL) {
3819 send_resp(dut, conn, SIGMA_ERROR,
3820 "errorCode,No FQDN specified");
3821 return 0;
3822 }
3823
3824 mkdir("SP", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
3825 snprintf(buf, sizeof(buf), "SP/%s", fqdn);
3826 mkdir(buf, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
3827
3828 snprintf(buf, sizeof(buf), "SP/%s/pps.xml", fqdn);
3829 if (rename("pps.xml", buf) < 0) {
3830 send_resp(dut, conn, SIGMA_ERROR,
3831 "errorCode,Could not move PPS MO");
3832 return 0;
3833 }
3834
3835 if (strcasecmp(path, "VendorSpecific") == 0) {
3836 snprintf(buf, sizeof(buf), "cp Certs/ca.pem SP/%s/ca.pem",
3837 fqdn);
3838 if (system(buf)) {
3839 send_resp(dut, conn, SIGMA_ERROR,
3840 "errorCode,Failed to copy OSU CA cert");
3841 return 0;
3842 }
3843
3844 snprintf(buf, sizeof(buf),
3845 "cp Certs/aaa-ca.pem SP/%s/aaa-ca.pem",
3846 fqdn);
3847 if (system(buf)) {
3848 send_resp(dut, conn, SIGMA_ERROR,
3849 "errorCode,Failed to copy AAA CA cert");
3850 return 0;
3851 }
3852 } else {
3853 snprintf(buf, sizeof(buf),
3854 "dl_osu_ca SP/%s/pps.xml SP/%s/ca.pem",
3855 fqdn, fqdn);
3856 if (run_hs20_osu(dut, buf) < 0) {
3857 send_resp(dut, conn, SIGMA_ERROR,
3858 "errorCode,Failed to download OSU CA cert");
3859 return 0;
3860 }
3861
3862 snprintf(buf, sizeof(buf),
3863 "dl_aaa_ca SP/%s/pps.xml SP/%s/aaa-ca.pem",
3864 fqdn, fqdn);
3865 if (run_hs20_osu(dut, buf) < 0) {
3866 sigma_dut_print(dut, DUT_MSG_INFO,
3867 "Failed to download AAA CA cert");
3868 }
3869 }
3870
3871 if (file_exists("next-client-cert.pem")) {
3872 snprintf(buf, sizeof(buf), "SP/%s/client-cert.pem", fqdn);
3873 if (rename("next-client-cert.pem", buf) < 0) {
3874 send_resp(dut, conn, SIGMA_ERROR,
3875 "errorCode,Could not move client certificate");
3876 return 0;
3877 }
3878 }
3879
3880 if (file_exists("next-client-key.pem")) {
3881 snprintf(buf, sizeof(buf), "SP/%s/client-key.pem", fqdn);
3882 if (rename("next-client-key.pem", buf) < 0) {
3883 send_resp(dut, conn, SIGMA_ERROR,
3884 "errorCode,Could not move client key");
3885 return 0;
3886 }
3887 }
3888
3889 snprintf(buf, sizeof(buf), "set_pps SP/%s/pps.xml", fqdn);
3890 if (run_hs20_osu(dut, buf) < 0) {
3891 send_resp(dut, conn, SIGMA_ERROR,
3892 "errorCode,Failed to configure credential from "
3893 "PPSMO");
3894 return 0;
3895 }
3896
3897 return 1;
3898}
3899
3900
3901static int download_cert(struct sigma_dut *dut,
3902 struct sigma_conn *conn,
3903 const char *intf,
3904 struct sigma_cmd *cmd)
3905{
3906 const char *name, *path;
3907 char url[500], buf[600];
3908
3909 name = get_param(cmd, "FileName");
3910 path = get_param(cmd, "FilePath");
3911 if (name == NULL || path == NULL)
3912 return -1;
3913
3914 if (strcasecmp(path, "VendorSpecific") == 0) {
3915 snprintf(url, sizeof(url), "Certs/%s-cert.pem", name);
3916 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
3917 "certificate from the device (%s)", url);
3918 if (!file_exists(url)) {
3919 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
3920 "certificate file does not exist");
3921 return 0;
3922 }
3923 snprintf(buf, sizeof(buf), "cp %s next-client-cert.pem", url);
3924 if (system(buf) != 0) {
3925 send_resp(dut, conn, SIGMA_ERROR,
3926 "errorCode,Failed to copy client "
3927 "certificate");
3928 return 0;
3929 }
3930
3931 snprintf(url, sizeof(url), "Certs/%s-key.pem", name);
3932 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
3933 "private key from the device (%s)", url);
3934 if (!file_exists(url)) {
3935 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
3936 "private key file does not exist");
3937 return 0;
3938 }
3939 snprintf(buf, sizeof(buf), "cp %s next-client-key.pem", url);
3940 if (system(buf) != 0) {
3941 send_resp(dut, conn, SIGMA_ERROR,
3942 "errorCode,Failed to copy client key");
3943 return 0;
3944 }
3945 } else if (strncasecmp(path, "http:", 5) != 0 &&
3946 strncasecmp(path, "https:", 6) != 0) {
3947 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3948 "Unsupported FilePath value");
3949 return 0;
3950 } else {
3951 snprintf(url, sizeof(url), "%s/%s.pem", path, name);
3952 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading client "
3953 "certificate/key from %s", url);
3954 snprintf(buf, sizeof(buf),
3955 "wget -T 10 -t 3 -O next-client-cert.pem '%s'", url);
3956 if (system(buf) != 0) {
3957 send_resp(dut, conn, SIGMA_ERROR,
3958 "errorCode,Failed to download client "
3959 "certificate");
3960 return 0;
3961 }
3962
3963 if (system("cp next-client-cert.pem next-client-key.pem") != 0)
3964 {
3965 send_resp(dut, conn, SIGMA_ERROR,
3966 "errorCode,Failed to copy client key");
3967 return 0;
3968 }
3969 }
3970
3971 return 1;
3972}
3973
3974
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02003975static int cmd_sta_preset_testparameters_60ghz(struct sigma_dut *dut,
3976 struct sigma_conn *conn,
3977 struct sigma_cmd *cmd)
3978{
3979 const char *val;
3980 const char *intf = get_param(cmd, "interface");
3981
3982 if (!intf)
3983 return -1;
3984
3985 val = get_param(cmd, "WscIEFragment");
3986 if (val && strcasecmp(val, "enable") == 0) {
3987 sigma_dut_print(dut, DUT_MSG_DEBUG,
3988 "Enable WSC IE fragmentation");
3989
3990 dut->wsc_fragment = 1;
3991 /* set long attributes to force fragmentation */
3992 if (wpa_command(intf, "SET device_name "
3993 WPS_LONG_DEVICE_NAME) < 0)
3994 return -2;
3995 if (wpa_command(intf, "SET manufacturer "
3996 WPS_LONG_MANUFACTURER) < 0)
3997 return -2;
3998 if (wpa_command(intf, "SET model_name "
3999 WPS_LONG_MODEL_NAME) < 0)
4000 return -2;
4001 if (wpa_command(intf, "SET model_number "
4002 WPS_LONG_MODEL_NUMBER) < 0)
4003 return -2;
4004 if (wpa_command(intf, "SET serial_number "
4005 WPS_LONG_SERIAL_NUMBER) < 0)
4006 return -2;
4007 }
4008
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02004009 val = get_param(cmd, "RSN_IE");
4010 if (val) {
4011 if (strcasecmp(val, "disable") == 0)
4012 dut->force_rsn_ie = FORCE_RSN_IE_REMOVE;
4013 else if (strcasecmp(val, "enable") == 0)
4014 dut->force_rsn_ie = FORCE_RSN_IE_ADD;
4015 }
4016
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02004017 val = get_param(cmd, "WpsVersion");
4018 if (val)
4019 dut->wps_forced_version = get_wps_forced_version(dut, val);
4020
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02004021 val = get_param(cmd, "WscEAPFragment");
4022 if (val && strcasecmp(val, "enable") == 0)
4023 dut->eap_fragment = 1;
4024
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02004025 return 1;
4026}
4027
4028
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004029static int cmd_sta_preset_testparameters_hs2_r2(struct sigma_dut *dut,
4030 struct sigma_conn *conn,
4031 const char *intf,
4032 struct sigma_cmd *cmd)
4033{
4034 const char *val;
4035
4036 val = get_param(cmd, "FileType");
4037 if (val && strcasecmp(val, "PPSMO") == 0)
4038 return download_ppsmo(dut, conn, intf, cmd);
4039 if (val && strcasecmp(val, "CERT") == 0)
4040 return download_cert(dut, conn, intf, cmd);
4041 if (val) {
4042 send_resp(dut, conn, SIGMA_ERROR,
4043 "ErrorCode,Unsupported FileType");
4044 return 0;
4045 }
4046
4047 return 1;
4048}
4049
4050
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304051static int cmd_sta_preset_testparameters_oce(struct sigma_dut *dut,
4052 struct sigma_conn *conn,
4053 const char *intf,
4054 struct sigma_cmd *cmd)
4055{
4056 const char *val;
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304057 char buf[1000];
4058 char text[20];
4059 unsigned char addr[ETH_ALEN];
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304060
4061 val = get_param(cmd, "OCESupport");
4062 if (val && strcasecmp(val, "Disable") == 0) {
4063 if (wpa_command(intf, "SET oce 0") < 0) {
4064 send_resp(dut, conn, SIGMA_ERROR,
4065 "ErrorCode,Failed to disable OCE");
4066 return 0;
4067 }
4068 } else if (val && strcasecmp(val, "Enable") == 0) {
4069 if (wpa_command(intf, "SET oce 1") < 0) {
4070 send_resp(dut, conn, SIGMA_ERROR,
4071 "ErrorCode,Failed to enable OCE");
4072 return 0;
4073 }
4074 }
4075
vamsi krishnaa2799492017-12-05 14:28:01 +05304076 val = get_param(cmd, "FILScap");
4077 if (val && (atoi(val) == 1)) {
4078 if (wpa_command(intf, "SET disable_fils 0") < 0) {
4079 send_resp(dut, conn, SIGMA_ERROR,
4080 "ErrorCode,Failed to enable FILS");
4081 return 0;
4082 }
4083 } else if (val && (atoi(val) == 0)) {
4084 if (wpa_command(intf, "SET disable_fils 1") < 0) {
4085 send_resp(dut, conn, SIGMA_ERROR,
4086 "ErrorCode,Failed to disable FILS");
4087 return 0;
4088 }
4089 }
4090
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304091 val = get_param(cmd, "FILSHLP");
4092 if (val && strcasecmp(val, "Enable") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004093 if (get_wpa_status(get_station_ifname(dut), "address", text,
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304094 sizeof(text)) < 0)
4095 return -2;
4096 hwaddr_aton(text, addr);
4097 snprintf(buf, sizeof(buf),
4098 "FILS_HLP_REQ_ADD ff:ff:ff:ff:ff:ff "
4099 "080045100140000040004011399e00000000ffffffff00440043"
4100 "012cb30001010600fd4f46410000000000000000000000000000"
4101 "000000000000"
4102 "%02x%02x%02x%02x%02x%02x"
4103 "0000000000000000000000000000000000000000000000000000"
4104 "0000000000000000000000000000000000000000000000000000"
4105 "0000000000000000000000000000000000000000000000000000"
4106 "0000000000000000000000000000000000000000000000000000"
4107 "0000000000000000000000000000000000000000000000000000"
4108 "0000000000000000000000000000000000000000000000000000"
4109 "0000000000000000000000000000000000000000000000000000"
4110 "0000000000000000000000000000000000000000638253633501"
4111 "013d0701000af549d29b390205dc3c12616e64726f69642d6468"
4112 "63702d382e302e30370a0103060f1a1c333a3b2b5000ff00",
4113 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
4114 if (wpa_command(intf, buf)) {
4115 send_resp(dut, conn, SIGMA_ERROR,
4116 "ErrorCode,Failed to add HLP");
4117 return 0;
4118 }
4119 dut->fils_hlp = 1;
4120 }
4121
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304122 return 1;
4123}
4124
4125
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004126static void ath_sta_set_noack(struct sigma_dut *dut, const char *intf,
4127 const char *val)
4128{
4129 int counter = 0;
4130 char token[50];
4131 char *result;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304132 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004133
Peng Xub8fc5cc2017-05-10 17:27:28 -07004134 strlcpy(token, val, sizeof(token));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004135 token[sizeof(token) - 1] = '\0';
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304136 result = strtok_r(token, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004137 while (result) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004138 if (strcmp(result, "disable") == 0)
4139 run_iwpriv(dut, intf, "noackpolicy %d 1 0", counter);
4140 else
4141 run_iwpriv(dut, intf, "noackpolicy %d 1 1", counter);
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304142 result = strtok_r(NULL, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004143 counter++;
4144 }
4145}
4146
4147
4148static void ath_sta_set_rts(struct sigma_dut *dut, const char *intf,
4149 const char *val)
4150{
4151 char buf[100];
4152
4153 snprintf(buf, sizeof(buf), "iwconfig %s rts %s", intf, val);
4154 if (system(buf) != 0) {
4155 sigma_dut_print(dut, DUT_MSG_ERROR, "iwconfig RTS failed");
4156 }
4157}
4158
4159
4160static void ath_sta_set_wmm(struct sigma_dut *dut, const char *intf,
4161 const char *val)
4162{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004163 if (strcasecmp(val, "off") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004164 run_iwpriv(dut, intf, "wmm 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004165 }
4166}
4167
4168
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08004169static int wcn_sta_set_wmm(struct sigma_dut *dut, const char *intf,
4170 const char *val)
4171{
4172#ifdef NL80211_SUPPORT
4173 struct nl_msg *msg;
4174 int ret = 0;
4175 struct nlattr *params;
4176 int ifindex;
4177 int wmmenable = 1;
4178
4179 if (val &&
4180 (strcasecmp(val, "off") == 0 || strcmp(val, "0") == 0))
4181 wmmenable = 0;
4182
4183 ifindex = if_nametoindex(intf);
4184 if (ifindex == 0) {
4185 sigma_dut_print(dut, DUT_MSG_ERROR,
4186 "%s: Index for interface %s failed",
4187 __func__, intf);
4188 return -1;
4189 }
4190
4191 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4192 NL80211_CMD_VENDOR)) ||
4193 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4194 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4195 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4196 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4197 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4198 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WMM_ENABLE,
4199 wmmenable)) {
4200 sigma_dut_print(dut, DUT_MSG_ERROR,
4201 "%s: err in adding vendor_cmd and vendor_data",
4202 __func__);
4203 nlmsg_free(msg);
4204 return -1;
4205 }
4206 nla_nest_end(msg, params);
4207
4208 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4209 if (ret) {
4210 sigma_dut_print(dut, DUT_MSG_ERROR,
4211 "%s: err in send_and_recv_msgs, ret=%d",
4212 __func__, ret);
4213 }
4214 return ret;
4215#else /* NL80211_SUPPORT */
4216 sigma_dut_print(dut, DUT_MSG_ERROR,
4217 "WMM cannot be changed without NL80211_SUPPORT defined");
4218 return -1;
4219#endif /* NL80211_SUPPORT */
4220}
4221
4222
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004223static void ath_sta_set_sgi(struct sigma_dut *dut, const char *intf,
4224 const char *val)
4225{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004226 int sgi20;
4227
4228 sgi20 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
4229
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004230 run_iwpriv(dut, intf, "shortgi %d", sgi20);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004231}
4232
4233
4234static void ath_sta_set_11nrates(struct sigma_dut *dut, const char *intf,
4235 const char *val)
4236{
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05304237 int rate_code, v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004238
4239 /* Disable Tx Beam forming when using a fixed rate */
4240 ath_disable_txbf(dut, intf);
4241
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05304242 v = atoi(val);
4243 if (v < 0 || v > 32) {
4244 sigma_dut_print(dut, DUT_MSG_ERROR,
4245 "Invalid Fixed MCS rate: %d", v);
4246 return;
4247 }
4248 rate_code = 0x80 + v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004249
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004250 run_iwpriv(dut, intf, "set11NRates 0x%x", rate_code);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004251
4252 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004253 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004254}
4255
4256
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08004257static void iwpriv_sta_set_amsdu(struct sigma_dut *dut, const char *intf,
4258 const char *val)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004259{
4260 char buf[60];
4261
4262 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)
4263 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 2", intf);
4264 else
4265 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf);
4266
4267 if (system(buf) != 0)
4268 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv amsdu failed");
4269}
4270
4271
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004272static int iwpriv_sta_set_ampdu(struct sigma_dut *dut, const char *intf,
4273 int ampdu)
4274{
4275 char buf[60];
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08004276 int maxaggregation = 63;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004277
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08004278 if (ampdu)
4279 ampdu = maxaggregation;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004280 snprintf(buf, sizeof(buf), "iwpriv %s ampdu %d", intf, ampdu);
4281 if (system(buf) != 0) {
4282 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv ampdu failed");
4283 return -1;
4284 }
4285
4286 return 0;
4287}
4288
4289
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004290static void ath_sta_set_stbc(struct sigma_dut *dut, const char *intf,
4291 const char *val)
4292{
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004293 run_iwpriv(dut, intf, "tx_stbc %s", val);
4294 run_iwpriv(dut, intf, "rx_stbc %s", val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004295}
4296
4297
4298static int wcn_sta_set_cts_width(struct sigma_dut *dut, const char *intf,
4299 const char *val)
4300{
4301 char buf[60];
4302
Peng Xucc317ed2017-05-18 16:44:37 -07004303 if (strcmp(val, "160") == 0) {
4304 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 5", intf);
4305 } else if (strcmp(val, "80") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004306 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
4307 } else if (strcmp(val, "40") == 0) {
4308 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 2", intf);
4309 } else if (strcmp(val, "20") == 0) {
4310 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 1", intf);
4311 } else if (strcasecmp(val, "Auto") == 0) {
4312 buf[0] = '\0';
4313 } else {
4314 sigma_dut_print(dut, DUT_MSG_ERROR,
4315 "WIDTH/CTS_WIDTH value not supported");
4316 return -1;
4317 }
4318
4319 if (buf[0] != '\0' && system(buf) != 0) {
4320 sigma_dut_print(dut, DUT_MSG_ERROR,
4321 "Failed to set WIDTH/CTS_WIDTH");
4322 return -1;
4323 }
4324
4325 return 0;
4326}
4327
4328
4329int ath_set_width(struct sigma_dut *dut, struct sigma_conn *conn,
4330 const char *intf, const char *val)
4331{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004332 if (strcasecmp(val, "Auto") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004333 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004334 dut->chwidth = 0;
4335 } else if (strcasecmp(val, "20") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004336 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004337 dut->chwidth = 0;
4338 } else if (strcasecmp(val, "40") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004339 run_iwpriv(dut, intf, "chwidth 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004340 dut->chwidth = 1;
4341 } else if (strcasecmp(val, "80") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004342 run_iwpriv(dut, intf, "chwidth 2");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004343 dut->chwidth = 2;
4344 } else if (strcasecmp(val, "160") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004345 run_iwpriv(dut, intf, "chwidth 3");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004346 dut->chwidth = 3;
4347 } else {
4348 send_resp(dut, conn, SIGMA_ERROR,
4349 "ErrorCode,WIDTH not supported");
4350 return -1;
4351 }
4352
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004353 return 0;
4354}
4355
4356
4357static int wcn_sta_set_sp_stream(struct sigma_dut *dut, const char *intf,
4358 const char *val)
4359{
4360 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07004361 int sta_nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004362
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08004363 if (strcmp(val, "1SS") == 0 || strcmp(val, "1") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004364 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07004365 sta_nss = 1;
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08004366 } else if (strcmp(val, "2SS") == 0 || strcmp(val, "2") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004367 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07004368 sta_nss = 2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004369 } else {
4370 sigma_dut_print(dut, DUT_MSG_ERROR,
4371 "SP_STREAM value not supported");
4372 return -1;
4373 }
4374
4375 if (system(buf) != 0) {
4376 sigma_dut_print(dut, DUT_MSG_ERROR,
4377 "Failed to set SP_STREAM");
4378 return -1;
4379 }
4380
Arif Hussainac6c5112018-05-25 17:34:00 -07004381 dut->sta_nss = sta_nss;
4382
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004383 return 0;
4384}
4385
4386
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304387static void wcn_sta_set_stbc(struct sigma_dut *dut, const char *intf,
4388 const char *val)
4389{
4390 char buf[60];
4391
4392 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc %s", intf, val);
4393 if (system(buf) != 0)
4394 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv tx_stbc failed");
4395
4396 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc %s", intf, val);
4397 if (system(buf) != 0)
4398 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv rx_stbc failed");
4399}
4400
4401
Ashwini Patil68d02cd2017-01-10 15:39:16 +05304402static int mbo_set_cellular_data_capa(struct sigma_dut *dut,
4403 struct sigma_conn *conn,
4404 const char *intf, int capa)
4405{
4406 char buf[32];
4407
4408 if (capa > 0 && capa < 4) {
4409 snprintf(buf, sizeof(buf), "SET mbo_cell_capa %d", capa);
4410 if (wpa_command(intf, buf) < 0) {
4411 send_resp(dut, conn, SIGMA_ERROR,
4412 "ErrorCode, Failed to set cellular data capability");
4413 return 0;
4414 }
4415 return 1;
4416 }
4417
4418 sigma_dut_print(dut, DUT_MSG_ERROR,
4419 "Invalid Cellular data capability: %d", capa);
4420 send_resp(dut, conn, SIGMA_INVALID,
4421 "ErrorCode,Invalid cellular data capability");
4422 return 0;
4423}
4424
4425
Ashwini Patil9183fdb2017-04-13 16:58:25 +05304426static int mbo_set_roaming(struct sigma_dut *dut, struct sigma_conn *conn,
4427 const char *intf, const char *val)
4428{
4429 if (strcasecmp(val, "Disable") == 0) {
4430 if (wpa_command(intf, "SET roaming 0") < 0) {
4431 send_resp(dut, conn, SIGMA_ERROR,
4432 "ErrorCode,Failed to disable roaming");
4433 return 0;
4434 }
4435 return 1;
4436 }
4437
4438 if (strcasecmp(val, "Enable") == 0) {
4439 if (wpa_command(intf, "SET roaming 1") < 0) {
4440 send_resp(dut, conn, SIGMA_ERROR,
4441 "ErrorCode,Failed to enable roaming");
4442 return 0;
4443 }
4444 return 1;
4445 }
4446
4447 sigma_dut_print(dut, DUT_MSG_ERROR,
4448 "Invalid value provided for roaming: %s", val);
4449 send_resp(dut, conn, SIGMA_INVALID,
4450 "ErrorCode,Unknown value provided for Roaming");
4451 return 0;
4452}
4453
4454
Ashwini Patila75de5a2017-04-13 16:35:05 +05304455static int mbo_set_assoc_disallow(struct sigma_dut *dut,
4456 struct sigma_conn *conn,
4457 const char *intf, const char *val)
4458{
4459 if (strcasecmp(val, "Disable") == 0) {
4460 if (wpa_command(intf, "SET ignore_assoc_disallow 1") < 0) {
4461 send_resp(dut, conn, SIGMA_ERROR,
4462 "ErrorCode,Failed to disable Assoc_disallow");
4463 return 0;
4464 }
4465 return 1;
4466 }
4467
4468 if (strcasecmp(val, "Enable") == 0) {
4469 if (wpa_command(intf, "SET ignore_assoc_disallow 0") < 0) {
4470 send_resp(dut, conn, SIGMA_ERROR,
4471 "ErrorCode,Failed to enable Assoc_disallow");
4472 return 0;
4473 }
4474 return 1;
4475 }
4476
4477 sigma_dut_print(dut, DUT_MSG_ERROR,
4478 "Invalid value provided for Assoc_disallow: %s", val);
4479 send_resp(dut, conn, SIGMA_INVALID,
4480 "ErrorCode,Unknown value provided for Assoc_disallow");
4481 return 0;
4482}
4483
4484
Ashwini Patilc63161e2017-04-13 16:30:23 +05304485static int mbo_set_bss_trans_req(struct sigma_dut *dut, struct sigma_conn *conn,
4486 const char *intf, const char *val)
4487{
4488 if (strcasecmp(val, "Reject") == 0) {
4489 if (wpa_command(intf, "SET reject_btm_req_reason 1") < 0) {
4490 send_resp(dut, conn, SIGMA_ERROR,
4491 "ErrorCode,Failed to Reject BTM Request");
4492 return 0;
4493 }
4494 return 1;
4495 }
4496
4497 if (strcasecmp(val, "Accept") == 0) {
4498 if (wpa_command(intf, "SET reject_btm_req_reason 0") < 0) {
4499 send_resp(dut, conn, SIGMA_ERROR,
4500 "ErrorCode,Failed to Accept BTM Request");
4501 return 0;
4502 }
4503 return 1;
4504 }
4505
4506 sigma_dut_print(dut, DUT_MSG_ERROR,
4507 "Invalid value provided for BSS_Transition: %s", val);
4508 send_resp(dut, conn, SIGMA_INVALID,
4509 "ErrorCode,Unknown value provided for BSS_Transition");
4510 return 0;
4511}
4512
4513
Ashwini Patil00402582017-04-13 12:29:39 +05304514static int mbo_set_non_pref_ch_list(struct sigma_dut *dut,
4515 struct sigma_conn *conn,
4516 const char *intf,
4517 struct sigma_cmd *cmd)
4518{
4519 const char *ch, *pref, *op_class, *reason;
4520 char buf[120];
4521 int len, ret;
4522
4523 pref = get_param(cmd, "Ch_Pref");
4524 if (!pref)
4525 return 1;
4526
4527 if (strcasecmp(pref, "clear") == 0) {
4528 free(dut->non_pref_ch_list);
4529 dut->non_pref_ch_list = NULL;
4530 } else {
4531 op_class = get_param(cmd, "Ch_Op_Class");
4532 if (!op_class) {
4533 send_resp(dut, conn, SIGMA_INVALID,
4534 "ErrorCode,Ch_Op_Class not provided");
4535 return 0;
4536 }
4537
4538 ch = get_param(cmd, "Ch_Pref_Num");
4539 if (!ch) {
4540 send_resp(dut, conn, SIGMA_INVALID,
4541 "ErrorCode,Ch_Pref_Num not provided");
4542 return 0;
4543 }
4544
4545 reason = get_param(cmd, "Ch_Reason_Code");
4546 if (!reason) {
4547 send_resp(dut, conn, SIGMA_INVALID,
4548 "ErrorCode,Ch_Reason_Code not provided");
4549 return 0;
4550 }
4551
4552 if (!dut->non_pref_ch_list) {
4553 dut->non_pref_ch_list =
4554 calloc(1, NON_PREF_CH_LIST_SIZE);
4555 if (!dut->non_pref_ch_list) {
4556 send_resp(dut, conn, SIGMA_ERROR,
4557 "ErrorCode,Failed to allocate memory for non_pref_ch_list");
4558 return 0;
4559 }
4560 }
4561 len = strlen(dut->non_pref_ch_list);
4562 ret = snprintf(dut->non_pref_ch_list + len,
4563 NON_PREF_CH_LIST_SIZE - len,
4564 " %s:%s:%s:%s", op_class, ch, pref, reason);
4565 if (ret > 0 && ret < NON_PREF_CH_LIST_SIZE - len) {
4566 sigma_dut_print(dut, DUT_MSG_DEBUG, "non_pref_list: %s",
4567 dut->non_pref_ch_list);
4568 } else {
4569 sigma_dut_print(dut, DUT_MSG_ERROR,
4570 "snprintf failed for non_pref_list, ret = %d",
4571 ret);
4572 send_resp(dut, conn, SIGMA_ERROR,
4573 "ErrorCode,snprintf failed");
4574 free(dut->non_pref_ch_list);
4575 dut->non_pref_ch_list = NULL;
4576 return 0;
4577 }
4578 }
4579
4580 ret = snprintf(buf, sizeof(buf), "SET non_pref_chan%s",
4581 dut->non_pref_ch_list ? dut->non_pref_ch_list : " ");
4582 if (ret < 0 || ret >= (int) sizeof(buf)) {
4583 sigma_dut_print(dut, DUT_MSG_DEBUG,
4584 "snprintf failed for set non_pref_chan, ret: %d",
4585 ret);
4586 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,snprint failed");
4587 return 0;
4588 }
4589
4590 if (wpa_command(intf, buf) < 0) {
4591 send_resp(dut, conn, SIGMA_ERROR,
4592 "ErrorCode,Failed to set non-preferred channel list");
4593 return 0;
4594 }
4595
4596 return 1;
4597}
4598
4599
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004600#ifdef NL80211_SUPPORT
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004601
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08004602static int sta_set_he_htc_supp(struct sigma_dut *dut, const char *intf,
4603 uint8_t cfg)
4604{
4605 struct nl_msg *msg;
4606 int ret = 0;
4607 struct nlattr *params;
4608 int ifindex;
4609
4610 ifindex = if_nametoindex(intf);
4611 if (ifindex == 0) {
4612 sigma_dut_print(dut, DUT_MSG_ERROR,
4613 "%s: Index for interface %s failed",
4614 __func__, intf);
4615 return -1;
4616 }
4617
4618 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4619 NL80211_CMD_VENDOR)) ||
4620 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4621 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4622 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4623 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4624 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4625 nla_put_u8(msg,
4626 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_HTC_HE_SUPP,
4627 cfg)) {
4628 sigma_dut_print(dut, DUT_MSG_ERROR,
4629 "%s: err in adding vendor_cmd and vendor_data",
4630 __func__);
4631 nlmsg_free(msg);
4632 return -1;
4633 }
4634 nla_nest_end(msg, params);
4635
4636 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4637 if (ret) {
4638 sigma_dut_print(dut, DUT_MSG_ERROR,
4639 "%s: err in send_and_recv_msgs, ret=%d",
4640 __func__, ret);
4641 }
4642 return ret;
4643}
4644
4645
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004646static int sta_set_he_fragmentation(struct sigma_dut *dut, const char *intf,
4647 enum he_fragmentation_val frag)
4648{
4649 struct nl_msg *msg;
4650 int ret = 0;
4651 struct nlattr *params;
4652 int ifindex;
4653
4654 ifindex = if_nametoindex(intf);
4655 if (ifindex == 0) {
4656 sigma_dut_print(dut, DUT_MSG_ERROR,
4657 "%s: Index for interface %s failed",
4658 __func__, intf);
4659 return -1;
4660 }
4661
4662 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4663 NL80211_CMD_VENDOR)) ||
4664 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4665 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4666 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4667 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4668 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4669 nla_put_u8(msg,
4670 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_FRAGMENTATION,
4671 frag)) {
4672 sigma_dut_print(dut, DUT_MSG_ERROR,
4673 "%s: err in adding vendor_cmd and vendor_data",
4674 __func__);
4675 nlmsg_free(msg);
4676 return -1;
4677 }
4678 nla_nest_end(msg, params);
4679
4680 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4681 if (ret) {
4682 sigma_dut_print(dut, DUT_MSG_ERROR,
4683 "%s: err in send_and_recv_msgs, ret=%d",
4684 __func__, ret);
4685 }
4686 return ret;
4687}
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004688
4689
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -08004690int wcn_set_he_ltf(struct sigma_dut *dut, const char *intf,
4691 enum qca_wlan_he_ltf_cfg ltf)
Subhani Shaik8e7a3052018-04-24 14:03:00 -07004692{
4693 struct nl_msg *msg;
4694 int ret = 0;
4695 struct nlattr *params;
4696 int ifindex;
4697
4698 ifindex = if_nametoindex(intf);
4699 if (ifindex == 0) {
4700 sigma_dut_print(dut, DUT_MSG_ERROR,
4701 "%s: Index for interface %s failed",
4702 __func__, intf);
4703 return -1;
4704 }
4705
4706 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4707 NL80211_CMD_VENDOR)) ||
4708 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4709 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4710 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4711 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4712 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4713 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_LTF,
4714 ltf)) {
4715 sigma_dut_print(dut, DUT_MSG_ERROR,
4716 "%s: err in adding vendor_cmd and vendor_data",
4717 __func__);
4718 nlmsg_free(msg);
4719 return -1;
4720 }
4721 nla_nest_end(msg, params);
4722
4723 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4724 if (ret) {
4725 sigma_dut_print(dut, DUT_MSG_ERROR,
4726 "%s: err in send_and_recv_msgs, ret=%d",
4727 __func__, ret);
4728 }
4729 return ret;
4730}
4731
4732
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004733static int nlvendor_sta_set_noack(struct sigma_dut *dut, const char *intf,
4734 int noack, enum qca_wlan_ac_type ac)
4735{
4736 struct nl_msg *msg;
4737 int ret = 0;
4738 struct nlattr *params;
4739 int ifindex;
4740
4741 ifindex = if_nametoindex(intf);
4742 if (ifindex == 0) {
4743 sigma_dut_print(dut, DUT_MSG_ERROR,
4744 "%s: Index for interface %s failed",
4745 __func__, intf);
4746 return -1;
4747 }
4748
4749 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4750 NL80211_CMD_VENDOR)) ||
4751 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4752 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4753 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4754 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4755 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4756 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_NO_ACK,
4757 noack) ||
4758 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_NO_ACK_AC,
4759 ac)) {
4760 sigma_dut_print(dut, DUT_MSG_ERROR,
4761 "%s: err in adding vendor_cmd and vendor_data",
4762 __func__);
4763 nlmsg_free(msg);
4764 return -1;
4765 }
4766 nla_nest_end(msg, params);
4767
4768 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4769 if (ret) {
4770 sigma_dut_print(dut, DUT_MSG_ERROR,
4771 "%s: err in send_and_recv_msgs, ret=%d",
4772 __func__, ret);
4773 }
4774 return ret;
4775}
4776
4777
4778static void wcn_sta_set_noack(struct sigma_dut *dut, const char *intf,
4779 const char *val)
4780{
4781 int noack, ret;
4782 char token[100];
4783 char *result;
4784 char *saveptr;
4785 enum qca_wlan_ac_type ac = QCA_WLAN_AC_BE;
4786
4787 strlcpy(token, val, sizeof(token));
4788 token[sizeof(token) - 1] = '\0';
4789 result = strtok_r(token, ":", &saveptr);
4790 while (result) {
4791 noack = strcasecmp(result, "Disable") != 0;
4792 ret = nlvendor_sta_set_noack(dut, intf, noack, ac);
4793 if (ret) {
4794 sigma_dut_print(dut, DUT_MSG_ERROR,
4795 "nlvendor_sta_set_noack failed for ac:%d, ret:%d",
4796 ac, ret);
4797 }
4798 result = strtok_r(NULL, ":", &saveptr);
4799 ac++;
4800 }
4801}
4802
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004803#endif /* NL80211_SUPPORT */
4804
4805
Jouni Malinenf7222712019-06-13 01:50:21 +03004806static enum sigma_cmd_result
4807cmd_sta_preset_testparameters(struct sigma_dut *dut, struct sigma_conn *conn,
4808 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004809{
4810 const char *intf = get_param(cmd, "Interface");
4811 const char *val;
4812
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03004813 val = get_param(cmd, "FT_DS");
4814 if (val) {
4815 if (strcasecmp(val, "Enable") == 0) {
4816 dut->sta_ft_ds = 1;
4817 } else if (strcasecmp(val, "Disable") == 0) {
4818 dut->sta_ft_ds = 0;
4819 } else {
4820 send_resp(dut, conn, SIGMA_ERROR,
4821 "errorCode,Unsupported value for FT_DS");
4822 return STATUS_SENT_ERROR;
4823 }
4824 }
4825
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004826 val = get_param(cmd, "Program");
Jouni Malinen1f6ae642018-06-07 23:56:13 +03004827 if (val && (strcasecmp(val, "HS2-R2") == 0 ||
4828 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004829 return cmd_sta_preset_testparameters_hs2_r2(dut, conn, intf,
4830 cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004831
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07004832 if (val && strcasecmp(val, "LOC") == 0)
4833 return loc_cmd_sta_preset_testparameters(dut, conn, cmd);
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02004834 if (val && strcasecmp(val, "60GHZ") == 0) {
4835 val = get_param(cmd, "WPS");
4836 if (val && strcasecmp(val, "disable") == 0) {
4837 dut->wps_disable = 1;
4838 sigma_dut_print(dut, DUT_MSG_INFO, "WPS disabled");
4839 } else {
4840 /* wps_disable can have other value from the previous
4841 * test, so make sure it has the correct value.
4842 */
4843 dut->wps_disable = 0;
4844 }
4845
4846 val = get_param(cmd, "P2P");
4847 if (val && strcasecmp(val, "disable") == 0)
4848 sigma_dut_print(dut, DUT_MSG_INFO, "P2P disabled");
4849 }
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07004850
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02004851 if (dut->program == PROGRAM_WPS && dut->band == WPS_BAND_60G)
4852 return cmd_sta_preset_testparameters_60ghz(dut, conn, cmd);
4853
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004854#ifdef ANDROID_NAN
4855 if (val && strcasecmp(val, "NAN") == 0)
4856 return nan_cmd_sta_preset_testparameters(dut, conn, cmd);
4857#endif /* ANDROID_NAN */
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07004858#ifdef MIRACAST
4859 if (val && (strcasecmp(val, "WFD") == 0 ||
4860 strcasecmp(val, "DisplayR2") == 0))
4861 return miracast_preset_testparameters(dut, conn, cmd);
4862#endif /* MIRACAST */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004863
Ashwini Patil68d02cd2017-01-10 15:39:16 +05304864 if (val && strcasecmp(val, "MBO") == 0) {
4865 val = get_param(cmd, "Cellular_Data_Cap");
4866 if (val &&
4867 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
4868 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +05304869
4870 val = get_param(cmd, "Ch_Pref");
4871 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
4872 return 0;
4873
Ashwini Patilc63161e2017-04-13 16:30:23 +05304874 val = get_param(cmd, "BSS_Transition");
4875 if (val && mbo_set_bss_trans_req(dut, conn, intf, val) == 0)
4876 return 0;
4877
Ashwini Patila75de5a2017-04-13 16:35:05 +05304878 val = get_param(cmd, "Assoc_Disallow");
4879 if (val && mbo_set_assoc_disallow(dut, conn, intf, val) == 0)
4880 return 0;
4881
Ashwini Patil9183fdb2017-04-13 16:58:25 +05304882 val = get_param(cmd, "Roaming");
4883 if (val && mbo_set_roaming(dut, conn, intf, val) == 0)
4884 return 0;
4885
Ashwini Patil68d02cd2017-01-10 15:39:16 +05304886 return 1;
4887 }
4888
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304889 if (val && strcasecmp(val, "OCE") == 0)
4890 return cmd_sta_preset_testparameters_oce(dut, conn, intf, cmd);
4891
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004892#if 0
4893 val = get_param(cmd, "Supplicant");
4894 if (val && strcasecmp(val, "Default") != 0) {
4895 send_resp(dut, conn, SIGMA_ERROR,
4896 "ErrorCode,Only default(Vendor) supplicant "
4897 "supported");
4898 return 0;
4899 }
4900#endif
4901
4902 val = get_param(cmd, "RTS");
4903 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004904 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004905 case DRIVER_ATHEROS:
4906 ath_sta_set_rts(dut, intf, val);
4907 break;
4908 default:
4909#if 0
4910 send_resp(dut, conn, SIGMA_ERROR,
4911 "ErrorCode,Setting RTS not supported");
4912 return 0;
4913#else
4914 sigma_dut_print(dut, DUT_MSG_DEBUG,
4915 "Setting RTS not supported");
4916 break;
4917#endif
4918 }
4919 }
4920
4921#if 0
4922 val = get_param(cmd, "FRGMNT");
4923 if (val) {
4924 /* TODO */
4925 send_resp(dut, conn, SIGMA_ERROR,
4926 "ErrorCode,Setting FRGMNT not supported");
4927 return 0;
4928 }
4929#endif
4930
4931#if 0
4932 val = get_param(cmd, "Preamble");
4933 if (val) {
4934 /* TODO: Long/Short */
4935 send_resp(dut, conn, SIGMA_ERROR,
4936 "ErrorCode,Setting Preamble not supported");
4937 return 0;
4938 }
4939#endif
4940
4941 val = get_param(cmd, "Mode");
4942 if (val) {
4943 if (strcmp(val, "11b") == 0 ||
4944 strcmp(val, "11g") == 0 ||
4945 strcmp(val, "11a") == 0 ||
4946 strcmp(val, "11n") == 0 ||
4947 strcmp(val, "11ng") == 0 ||
4948 strcmp(val, "11nl") == 0 ||
4949 strcmp(val, "11nl(nabg)") == 0 ||
4950 strcmp(val, "AC") == 0 ||
4951 strcmp(val, "11AC") == 0 ||
4952 strcmp(val, "11ac") == 0 ||
4953 strcmp(val, "11na") == 0 ||
Amarnath Hullur Subramanyamb0db2712018-01-30 19:40:35 -08004954 strcmp(val, "11an") == 0 ||
4955 strcmp(val, "11ax") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004956 /* STA supports all modes by default */
4957 } else {
4958 send_resp(dut, conn, SIGMA_ERROR,
4959 "ErrorCode,Setting Mode not supported");
4960 return 0;
4961 }
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08004962
4963 /* Change the mode only in case of testbed for HE program
4964 * and for 11a and 11g modes only. */
4965 if (dut->program == PROGRAM_HE &&
4966 dut->device_type == STA_testbed) {
4967 int phymode;
4968 char buf[60];
4969
4970 if (strcmp(val, "11a") == 0) {
Amarnath Hullur Subramanyam94dfaf02018-03-02 19:26:57 -08004971 phymode = 1; /* IEEE80211_MODE_11A */
4972 } else if (strcmp(val, "11g") == 0) {
4973 phymode = 3; /* IEEE80211_MODE_11G */
4974 } else if (strcmp(val, "11b") == 0) {
4975 phymode = 2; /* IEEE80211_MODE_11B */
4976 } else if (strcmp(val, "11n") == 0 ||
4977 strcmp(val, "11nl") == 0 ||
4978 strcmp(val, "11nl(nabg)") == 0) {
4979 phymode = 22; /* IEEE80211_MODE_11AGN */
4980 } else if (strcmp(val, "11ng") == 0) {
4981 phymode = 13; /* IEEE80211_MODE_11NG_HT40 */
4982 } else if (strcmp(val, "AC") == 0 ||
4983 strcasecmp(val, "11AC") == 0) {
4984 phymode = 19; /* IEEE80211_MODE_11AC_VHT80 */
4985 } else if (strcmp(val, "11na") == 0 ||
4986 strcasecmp(val, "11an") == 0) {
4987 phymode = 14; /* IEEE80211_MODE_11NA_HT40 */
4988 } else if (strcmp(val, "11ax") == 0) {
4989 phymode = 0; /* IEEE80211_MODE_AUTO */
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08004990 } else {
4991 sigma_dut_print(dut, DUT_MSG_DEBUG,
4992 "Ignoring mode change for mode: %s",
4993 val);
4994 phymode = -1;
4995 }
4996 if (phymode != -1) {
4997 snprintf(buf, sizeof(buf),
4998 "iwpriv %s setphymode %d",
4999 intf, phymode);
5000 if (system(buf) != 0) {
5001 sigma_dut_print(dut, DUT_MSG_ERROR,
5002 "iwpriv setting of phymode failed");
5003 }
5004 }
5005 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005006 }
5007
5008 val = get_param(cmd, "wmm");
5009 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005010 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005011 case DRIVER_ATHEROS:
5012 ath_sta_set_wmm(dut, intf, val);
5013 break;
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08005014 case DRIVER_WCN:
5015 wcn_sta_set_wmm(dut, intf, val);
5016 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005017 default:
5018 sigma_dut_print(dut, DUT_MSG_DEBUG,
5019 "Setting wmm not supported");
5020 break;
5021 }
5022 }
5023
5024 val = get_param(cmd, "Powersave");
5025 if (val) {
5026 if (strcmp(val, "0") == 0 || strcasecmp(val, "off") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005027 if (get_driver_type(dut) == DRIVER_WCN) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +05305028 if (set_power_save_wcn(dut, intf, 2) < 0)
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005029 return 0;
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005030 }
5031
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005032 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005033 "P2P_SET ps 0") < 0)
5034 return -2;
5035 /* Make sure test modes are disabled */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005036 wpa_command(get_station_ifname(dut), "P2P_SET ps 98");
5037 wpa_command(get_station_ifname(dut), "P2P_SET ps 96");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005038 } else if (strcmp(val, "1") == 0 ||
5039 strcasecmp(val, "PSPoll") == 0 ||
5040 strcasecmp(val, "on") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005041 if (get_driver_type(dut) == DRIVER_WCN) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +05305042 if (set_power_save_wcn(dut, intf, 1) < 0)
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005043 return 0;
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005044 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005045 /* Disable default power save mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005046 wpa_command(get_station_ifname(dut), "P2P_SET ps 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005047 /* Enable PS-Poll test mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005048 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005049 "P2P_SET ps 97") < 0 ||
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005050 wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005051 "P2P_SET ps 99") < 0)
5052 return -2;
5053 } else if (strcmp(val, "2") == 0 ||
5054 strcasecmp(val, "Fast") == 0) {
5055 /* TODO */
5056 send_resp(dut, conn, SIGMA_ERROR,
5057 "ErrorCode,Powersave=Fast not supported");
5058 return 0;
5059 } else if (strcmp(val, "3") == 0 ||
5060 strcasecmp(val, "PSNonPoll") == 0) {
5061 /* Make sure test modes are disabled */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005062 wpa_command(get_station_ifname(dut), "P2P_SET ps 98");
5063 wpa_command(get_station_ifname(dut), "P2P_SET ps 96");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005064
5065 /* Enable default power save mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005066 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005067 "P2P_SET ps 1") < 0)
5068 return -2;
5069 } else
5070 return -1;
5071 }
5072
5073 val = get_param(cmd, "NoAck");
5074 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005075 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005076 case DRIVER_ATHEROS:
5077 ath_sta_set_noack(dut, intf, val);
5078 break;
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08005079#ifdef NL80211_SUPPORT
5080 case DRIVER_WCN:
5081 wcn_sta_set_noack(dut, intf, val);
5082 break;
5083#endif /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005084 default:
5085 send_resp(dut, conn, SIGMA_ERROR,
5086 "ErrorCode,Setting NoAck not supported");
5087 return 0;
5088 }
5089 }
5090
5091 val = get_param(cmd, "IgnoreChswitchProhibit");
5092 if (val) {
5093 /* TODO: Enabled/disabled */
5094 if (strcasecmp(val, "Enabled") == 0) {
5095 send_resp(dut, conn, SIGMA_ERROR,
5096 "ErrorCode,Enabling IgnoreChswitchProhibit "
5097 "not supported");
5098 return 0;
5099 }
5100 }
5101
5102 val = get_param(cmd, "TDLS");
5103 if (val) {
5104 if (strcasecmp(val, "Disabled") == 0) {
5105 if (wpa_command(intf, "SET tdls_disabled 1")) {
5106 send_resp(dut, conn, SIGMA_ERROR,
5107 "ErrorCode,Failed to disable TDLS");
5108 return 0;
5109 }
5110 } else if (strcasecmp(val, "Enabled") == 0) {
5111 if (wpa_command(intf, "SET tdls_disabled 0")) {
5112 send_resp(dut, conn, SIGMA_ERROR,
5113 "ErrorCode,Failed to enable TDLS");
5114 return 0;
5115 }
5116 } else {
5117 send_resp(dut, conn, SIGMA_ERROR,
5118 "ErrorCode,Unsupported TDLS value");
5119 return 0;
5120 }
5121 }
5122
5123 val = get_param(cmd, "TDLSmode");
5124 if (val) {
5125 if (strcasecmp(val, "Default") == 0) {
5126 wpa_command(intf, "SET tdls_testing 0");
5127 } else if (strcasecmp(val, "APProhibit") == 0) {
5128 if (wpa_command(intf, "SET tdls_testing 0x400")) {
5129 send_resp(dut, conn, SIGMA_ERROR,
5130 "ErrorCode,Failed to enable ignore "
5131 "APProhibit TDLS mode");
5132 return 0;
5133 }
5134 } else if (strcasecmp(val, "HiLoMac") == 0) {
5135 /* STA should respond with TDLS setup req for a TDLS
5136 * setup req */
5137 if (wpa_command(intf, "SET tdls_testing 0x80")) {
5138 send_resp(dut, conn, SIGMA_ERROR,
5139 "ErrorCode,Failed to enable HiLoMac "
5140 "TDLS mode");
5141 return 0;
5142 }
5143 } else if (strcasecmp(val, "WeakSecurity") == 0) {
5144 /*
5145 * Since all security modes are enabled by default when
5146 * Sigma control is used, there is no need to do
5147 * anything here.
5148 */
5149 } else if (strcasecmp(val, "ExistLink") == 0) {
5150 /*
5151 * Since we allow new TDLS Setup Request even if there
5152 * is an existing link, nothing needs to be done for
5153 * this.
5154 */
5155 } else {
5156 /* TODO:
5157 * ExistLink: STA should send TDLS setup req even if
5158 * direct link already exists
5159 */
5160 send_resp(dut, conn, SIGMA_ERROR,
5161 "ErrorCode,Unsupported TDLSmode value");
5162 return 0;
5163 }
5164 }
5165
5166 val = get_param(cmd, "FakePubKey");
5167 if (val && atoi(val) && wpa_command(intf, "SET wps_corrupt_pkhash 1")) {
5168 send_resp(dut, conn, SIGMA_ERROR,
5169 "ErrorCode,Failed to enable FakePubKey");
5170 return 0;
5171 }
5172
Amarnath Hullur Subramanyamae1042b2018-02-22 21:52:52 -08005173#ifdef NL80211_SUPPORT
5174 val = get_param(cmd, "FrgmntSupport");
5175 if (val) {
5176 if (strcasecmp(val, "Enable") == 0) {
5177 if (sta_set_he_fragmentation(dut, intf,
5178 HE_FRAG_LEVEL1)) {
5179 send_resp(dut, conn, SIGMA_ERROR,
5180 "ErrorCode,Failed to enable HE Fragmentation");
5181 return 0;
5182 }
5183 } else if (strcasecmp(val, "Disable") == 0) {
5184 if (sta_set_he_fragmentation(dut, intf,
5185 HE_FRAG_DISABLE)) {
5186 send_resp(dut, conn, SIGMA_ERROR,
5187 "ErrorCode,Failed to disable HE Fragmentation");
5188 return 0;
5189 }
5190 }
5191 }
5192#endif /* NL80211_SUPPORT */
5193
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005194 return 1;
5195}
5196
5197
5198static const char * ath_get_radio_name(const char *radio_name)
5199{
5200 if (radio_name == NULL)
5201 return "wifi0";
5202 if (strcmp(radio_name, "wifi1") == 0)
5203 return "wifi1";
5204 if (strcmp(radio_name, "wifi2") == 0)
5205 return "wifi2";
5206 return "wifi0";
5207}
5208
5209
5210static void ath_sta_set_txsp_stream(struct sigma_dut *dut, const char *intf,
5211 const char *val)
5212{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005213 unsigned int vht_mcsmap = 0;
5214 int txchainmask = 0;
5215 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
5216
5217 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
5218 if (dut->testbed_flag_txsp == 1) {
5219 vht_mcsmap = 0xfffc;
5220 dut->testbed_flag_txsp = 0;
5221 } else {
5222 vht_mcsmap = 0xfffe;
5223 }
5224 txchainmask = 1;
5225 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
5226 if (dut->testbed_flag_txsp == 1) {
5227 vht_mcsmap = 0xfff0;
5228 dut->testbed_flag_txsp = 0;
5229 } else {
5230 vht_mcsmap = 0xfffa;
5231 }
5232 txchainmask = 3;
5233 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
5234 if (dut->testbed_flag_txsp == 1) {
5235 vht_mcsmap = 0xffc0;
5236 dut->testbed_flag_txsp = 0;
5237 } else {
5238 vht_mcsmap = 0xffea;
5239 }
5240 txchainmask = 7;
5241 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
5242 if (dut->testbed_flag_txsp == 1) {
5243 vht_mcsmap = 0xff00;
5244 dut->testbed_flag_txsp = 0;
5245 } else {
5246 vht_mcsmap = 0xffaa;
5247 }
5248 txchainmask = 15;
5249 } else {
5250 if (dut->testbed_flag_txsp == 1) {
5251 vht_mcsmap = 0xffc0;
5252 dut->testbed_flag_txsp = 0;
5253 } else {
5254 vht_mcsmap = 0xffea;
5255 }
5256 }
5257
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005258 if (txchainmask)
5259 run_iwpriv(dut, basedev, "txchainmask %d", txchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005260
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005261 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005262}
5263
5264
5265static void ath_sta_set_rxsp_stream(struct sigma_dut *dut, const char *intf,
5266 const char *val)
5267{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005268 unsigned int vht_mcsmap = 0;
5269 int rxchainmask = 0;
5270 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
5271
5272 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
5273 if (dut->testbed_flag_rxsp == 1) {
5274 vht_mcsmap = 0xfffc;
5275 dut->testbed_flag_rxsp = 0;
5276 } else {
5277 vht_mcsmap = 0xfffe;
5278 }
5279 rxchainmask = 1;
5280 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
5281 if (dut->testbed_flag_rxsp == 1) {
5282 vht_mcsmap = 0xfff0;
5283 dut->testbed_flag_rxsp = 0;
5284 } else {
5285 vht_mcsmap = 0xfffa;
5286 }
5287 rxchainmask = 3;
5288 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
5289 if (dut->testbed_flag_rxsp == 1) {
5290 vht_mcsmap = 0xffc0;
5291 dut->testbed_flag_rxsp = 0;
5292 } else {
5293 vht_mcsmap = 0xffea;
5294 }
5295 rxchainmask = 7;
5296 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
5297 if (dut->testbed_flag_rxsp == 1) {
5298 vht_mcsmap = 0xff00;
5299 dut->testbed_flag_rxsp = 0;
5300 } else {
5301 vht_mcsmap = 0xffaa;
5302 }
5303 rxchainmask = 15;
5304 } else {
5305 if (dut->testbed_flag_rxsp == 1) {
5306 vht_mcsmap = 0xffc0;
5307 dut->testbed_flag_rxsp = 0;
5308 } else {
5309 vht_mcsmap = 0xffea;
5310 }
5311 }
5312
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005313 if (rxchainmask)
5314 run_iwpriv(dut, basedev, "rxchainmask %d", rxchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005315
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005316 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005317}
5318
5319
5320void ath_set_zero_crc(struct sigma_dut *dut, const char *val)
5321{
5322 if (strcasecmp(val, "enable") == 0) {
5323 if (system("athdiag --set --address=0x2a204 --and=0xbfffffff")
5324 != 0) {
5325 sigma_dut_print(dut, DUT_MSG_ERROR,
5326 "Disable BB_VHTSIGB_CRC_CALC failed");
5327 }
5328
5329 if (system("athdiag --set --address=0x2a204 --or=0x80000000")
5330 != 0) {
5331 sigma_dut_print(dut, DUT_MSG_ERROR,
5332 "Enable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
5333 }
5334 } else {
5335 if (system("athdiag --set --address=0x2a204 --and=0x7fffffff")
5336 != 0) {
5337 sigma_dut_print(dut, DUT_MSG_ERROR,
5338 "Disable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
5339 }
5340
5341 if (system("athdiag --set --address=0x2a204 --or=0x40000000")
5342 != 0) {
5343 sigma_dut_print(dut, DUT_MSG_ERROR,
5344 "Enable BB_VHTSIGB_CRC_CALC failed");
5345 }
5346 }
5347}
5348
5349
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005350static int wcn_sta_set_width(struct sigma_dut *dut, const char *intf,
5351 const char *val)
5352{
5353 char buf[60];
5354
5355 if (strcmp(val, "20") == 0) {
5356 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
5357 dut->chwidth = 0;
5358 } else if (strcmp(val, "40") == 0) {
5359 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 1", intf);
5360 dut->chwidth = 1;
5361 } else if (strcmp(val, "80") == 0) {
5362 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
5363 dut->chwidth = 2;
Sunil Duttb1cccac2018-05-22 21:03:12 +05305364 } else if (strcasecmp(val, "Auto") == 0) {
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005365 buf[0] = '\0';
5366 } else {
5367 sigma_dut_print(dut, DUT_MSG_ERROR, "WIDTH %s not supported",
5368 val);
5369 return -1;
5370 }
5371
5372 if (buf[0] != '\0' && system(buf) != 0) {
5373 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv chwidth failed");
5374 return -1;
5375 }
5376
5377 return 0;
5378}
5379
5380
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005381static int nlvendor_sta_set_addba_reject(struct sigma_dut *dut,
5382 const char *intf, int addbareject)
5383{
5384#ifdef NL80211_SUPPORT
5385 struct nl_msg *msg;
5386 int ret = 0;
5387 struct nlattr *params;
5388 int ifindex;
5389
5390 ifindex = if_nametoindex(intf);
5391 if (ifindex == 0) {
5392 sigma_dut_print(dut, DUT_MSG_ERROR,
5393 "%s: Index for interface %s failed",
5394 __func__, intf);
5395 return -1;
5396 }
5397
5398 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5399 NL80211_CMD_VENDOR)) ||
5400 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5401 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5402 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5403 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5404 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5405 nla_put_u8(msg,
5406 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ACCEPT_ADDBA_REQ,
5407 !addbareject)) {
5408 sigma_dut_print(dut, DUT_MSG_ERROR,
5409 "%s: err in adding vendor_cmd and vendor_data",
5410 __func__);
5411 nlmsg_free(msg);
5412 return -1;
5413 }
5414 nla_nest_end(msg, params);
5415
5416 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5417 if (ret) {
5418 sigma_dut_print(dut, DUT_MSG_ERROR,
5419 "%s: err in send_and_recv_msgs, ret=%d",
5420 __func__, ret);
5421 }
5422 return ret;
5423#else /* NL80211_SUPPORT */
5424 sigma_dut_print(dut, DUT_MSG_ERROR,
5425 "ADDBA_REJECT cannot be set without NL80211_SUPPORT defined");
5426 return -1;
5427#endif /* NL80211_SUPPORT */
5428}
5429
5430
5431static int sta_set_addba_reject(struct sigma_dut *dut, const char *intf,
5432 int addbareject)
5433{
5434 int ret;
5435
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005436 switch (get_driver_type(dut)) {
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005437 case DRIVER_WCN:
5438 ret = nlvendor_sta_set_addba_reject(dut, intf, addbareject);
5439 if (ret) {
5440 sigma_dut_print(dut, DUT_MSG_ERROR,
5441 "nlvendor_sta_set_addba_reject failed, ret:%d",
5442 ret);
5443 return ret;
5444 }
5445 break;
5446 default:
5447 sigma_dut_print(dut, DUT_MSG_ERROR,
5448 "errorCode,Unsupported ADDBA_REJECT with the current driver");
5449 ret = -1;
5450 break;
5451 }
5452
5453 return ret;
5454}
5455
5456
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005457static int nlvendor_config_send_addba(struct sigma_dut *dut, const char *intf,
5458 int enable)
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005459{
5460#ifdef NL80211_SUPPORT
5461 struct nl_msg *msg;
5462 int ret = 0;
5463 struct nlattr *params;
5464 int ifindex;
5465
5466 ifindex = if_nametoindex(intf);
5467 if (ifindex == 0) {
5468 sigma_dut_print(dut, DUT_MSG_ERROR,
5469 "%s: Index for interface %s failed",
5470 __func__, intf);
5471 return -1;
5472 }
5473
5474 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5475 NL80211_CMD_VENDOR)) ||
5476 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5477 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5478 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5479 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5480 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5481 nla_put_u8(msg,
5482 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SEND_ADDBA_REQ,
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005483 enable)) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005484 sigma_dut_print(dut, DUT_MSG_ERROR,
5485 "%s: err in adding vendor_cmd and vendor_data",
5486 __func__);
5487 nlmsg_free(msg);
5488 return -1;
5489 }
5490 nla_nest_end(msg, params);
5491
5492 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5493 if (ret) {
5494 sigma_dut_print(dut, DUT_MSG_ERROR,
5495 "%s: err in send_and_recv_msgs, ret=%d",
5496 __func__, ret);
5497 }
5498 return ret;
5499#else /* NL80211_SUPPORT */
5500 sigma_dut_print(dut, DUT_MSG_ERROR,
5501 "Disable addba not possible without NL80211_SUPPORT defined");
5502 return -1;
5503#endif /* NL80211_SUPPORT */
5504}
5505
5506
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305507#ifdef NL80211_SUPPORT
5508static int nl80211_sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
5509{
5510 struct nl_msg *msg;
5511 int ret = 0;
5512 int ifindex;
5513
5514 ifindex = if_nametoindex(intf);
5515 if (ifindex == 0) {
5516 sigma_dut_print(dut, DUT_MSG_ERROR,
5517 "%s: Index for interface %s failed",
5518 __func__, intf);
5519 return -1;
5520 }
5521
5522 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5523 NL80211_CMD_SET_WIPHY)) ||
5524 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) {
5525 sigma_dut_print(dut, DUT_MSG_ERROR,
5526 "%s: err in adding RTS threshold",
5527 __func__);
5528 nlmsg_free(msg);
5529 return -1;
5530 }
5531
5532 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5533 if (ret) {
5534 sigma_dut_print(dut, DUT_MSG_ERROR,
5535 "%s: err in send_and_recv_msgs, ret=%d",
5536 __func__, ret);
5537 }
5538 return ret;
5539}
5540#endif /* NL80211_SUPPORT */
5541
5542
5543static int sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
5544{
5545 char buf[100];
5546
5547#ifdef NL80211_SUPPORT
5548 if (nl80211_sta_set_rts(dut, intf, val) == 0)
5549 return 0;
5550 sigma_dut_print(dut, DUT_MSG_DEBUG,
5551 "Fall back to using iwconfig for setting RTS threshold");
5552#endif /* NL80211_SUPPORT */
5553
5554 snprintf(buf, sizeof(buf), "iwconfig %s rts %d", intf, val);
5555 if (system(buf) != 0) {
5556 sigma_dut_print(dut, DUT_MSG_ERROR,
5557 "Failed to set RTS threshold %d", val);
5558 return -1;
5559 }
5560 return 0;
5561}
5562
5563
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005564static int cmd_sta_set_wireless_common(const char *intf, struct sigma_dut *dut,
5565 struct sigma_conn *conn,
5566 struct sigma_cmd *cmd)
5567{
5568 const char *val;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005569 int ampdu = -1, addbareject = -1;
Jouni Malinen3aa72862019-05-29 23:14:51 +03005570 char buf[128];
5571 int res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005572
5573 val = get_param(cmd, "40_INTOLERANT");
5574 if (val) {
5575 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5576 /* TODO: iwpriv ht40intol through wpa_supplicant */
5577 send_resp(dut, conn, SIGMA_ERROR,
5578 "ErrorCode,40_INTOLERANT not supported");
5579 return 0;
5580 }
5581 }
5582
5583 val = get_param(cmd, "ADDBA_REJECT");
5584 if (val) {
5585 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5586 /* reject any ADDBA with status "decline" */
5587 ampdu = 0;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005588 addbareject = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005589 } else {
5590 /* accept ADDBA */
5591 ampdu = 1;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005592 addbareject = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005593 }
5594 }
5595
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005596 if (addbareject >= 0 &&
5597 sta_set_addba_reject(dut, intf, addbareject) < 0) {
5598 send_resp(dut, conn, SIGMA_ERROR,
5599 "ErrorCode,set addba_reject failed");
5600 return 0;
5601 }
5602
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005603 val = get_param(cmd, "AMPDU");
5604 if (val) {
5605 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5606 /* enable AMPDU Aggregation */
5607 if (ampdu == 0) {
5608 send_resp(dut, conn, SIGMA_ERROR,
5609 "ErrorCode,Mismatch in "
5610 "addba_reject/ampdu - "
5611 "not supported");
5612 return 0;
5613 }
5614 ampdu = 1;
5615 } else {
5616 /* disable AMPDU Aggregation */
5617 if (ampdu == 1) {
5618 send_resp(dut, conn, SIGMA_ERROR,
5619 "ErrorCode,Mismatch in "
5620 "addba_reject/ampdu - "
5621 "not supported");
5622 return 0;
5623 }
5624 ampdu = 0;
5625 }
5626 }
5627
5628 if (ampdu >= 0) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005629 int ret;
5630
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005631 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s A-MPDU aggregation",
5632 ampdu ? "Enabling" : "Disabling");
5633 snprintf(buf, sizeof(buf), "SET ampdu %d", ampdu);
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07005634 if (wpa_command(intf, buf) < 0 &&
5635 iwpriv_sta_set_ampdu(dut, intf, ampdu) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005636 send_resp(dut, conn, SIGMA_ERROR,
5637 "ErrorCode,set aggr failed");
5638 return 0;
5639 }
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005640
5641 if (ampdu == 0) {
5642 /* Disable sending of addba using nl vendor command */
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005643 ret = nlvendor_config_send_addba(dut, intf, 0);
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005644 if (ret) {
5645 sigma_dut_print(dut, DUT_MSG_ERROR,
5646 "Failed to disable addba, ret:%d",
5647 ret);
5648 }
5649 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005650 }
5651
5652 val = get_param(cmd, "AMSDU");
5653 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005654 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005655 case DRIVER_ATHEROS:
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08005656 case DRIVER_WCN:
5657 iwpriv_sta_set_amsdu(dut, intf, val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005658 break;
5659 default:
5660 if (strcmp(val, "1") == 0 ||
5661 strcasecmp(val, "Enable") == 0) {
5662 /* Enable AMSDU Aggregation */
5663 send_resp(dut, conn, SIGMA_ERROR,
5664 "ErrorCode,AMSDU aggregation not supported");
5665 return 0;
5666 }
5667 break;
5668 }
5669 }
5670
5671 val = get_param(cmd, "STBC_RX");
5672 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005673 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005674 case DRIVER_ATHEROS:
5675 ath_sta_set_stbc(dut, intf, val);
5676 break;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05305677 case DRIVER_WCN:
5678 wcn_sta_set_stbc(dut, intf, val);
5679 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005680 default:
5681 send_resp(dut, conn, SIGMA_ERROR,
5682 "ErrorCode,STBC_RX not supported");
5683 return 0;
5684 }
5685 }
5686
5687 val = get_param(cmd, "WIDTH");
5688 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005689 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005690 case DRIVER_WCN:
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005691 if (wcn_sta_set_width(dut, intf, val) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005692 send_resp(dut, conn, SIGMA_ERROR,
5693 "ErrorCode,Failed to set WIDTH");
5694 return 0;
5695 }
5696 break;
5697 case DRIVER_ATHEROS:
5698 if (ath_set_width(dut, conn, intf, val) < 0)
5699 return 0;
5700 break;
5701 default:
5702 sigma_dut_print(dut, DUT_MSG_ERROR,
5703 "Setting WIDTH not supported");
5704 break;
5705 }
5706 }
5707
5708 val = get_param(cmd, "SMPS");
5709 if (val) {
5710 /* TODO: Dynamic/0, Static/1, No Limit/2 */
5711 send_resp(dut, conn, SIGMA_ERROR,
5712 "ErrorCode,SMPS not supported");
5713 return 0;
5714 }
5715
5716 val = get_param(cmd, "TXSP_STREAM");
5717 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005718 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005719 case DRIVER_WCN:
5720 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
5721 send_resp(dut, conn, SIGMA_ERROR,
5722 "ErrorCode,Failed to set TXSP_STREAM");
5723 return 0;
5724 }
5725 break;
5726 case DRIVER_ATHEROS:
5727 ath_sta_set_txsp_stream(dut, intf, val);
5728 break;
5729 default:
5730 sigma_dut_print(dut, DUT_MSG_ERROR,
5731 "Setting TXSP_STREAM not supported");
5732 break;
5733 }
5734 }
5735
5736 val = get_param(cmd, "RXSP_STREAM");
5737 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005738 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005739 case DRIVER_WCN:
5740 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
5741 send_resp(dut, conn, SIGMA_ERROR,
5742 "ErrorCode,Failed to set RXSP_STREAM");
5743 return 0;
5744 }
5745 break;
5746 case DRIVER_ATHEROS:
5747 ath_sta_set_rxsp_stream(dut, intf, val);
5748 break;
5749 default:
5750 sigma_dut_print(dut, DUT_MSG_ERROR,
5751 "Setting RXSP_STREAM not supported");
5752 break;
5753 }
5754 }
5755
5756 val = get_param(cmd, "DYN_BW_SGNL");
5757 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005758 switch (get_driver_type(dut)) {
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005759 case DRIVER_WCN:
Peng Xuc59afd32016-11-21 15:01:11 -08005760 if (strcasecmp(val, "enable") == 0) {
5761 snprintf(buf, sizeof(buf),
5762 "iwpriv %s cwmenable 1", intf);
5763 if (system(buf) != 0) {
5764 sigma_dut_print(dut, DUT_MSG_ERROR,
5765 "iwpriv cwmenable 1 failed");
5766 return 0;
5767 }
5768 } else if (strcasecmp(val, "disable") == 0) {
5769 snprintf(buf, sizeof(buf),
5770 "iwpriv %s cwmenable 0", intf);
5771 if (system(buf) != 0) {
5772 sigma_dut_print(dut, DUT_MSG_ERROR,
5773 "iwpriv cwmenable 0 failed");
5774 return 0;
5775 }
5776 } else {
5777 sigma_dut_print(dut, DUT_MSG_ERROR,
5778 "Unsupported DYN_BW_SGL");
5779 }
5780
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005781 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
5782 if (system(buf) != 0) {
5783 sigma_dut_print(dut, DUT_MSG_ERROR,
5784 "Failed to set cts_cbw in DYN_BW_SGNL");
5785 return 0;
5786 }
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005787 break;
5788 case DRIVER_ATHEROS:
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07005789 novap_reset(dut, intf, 1);
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005790 ath_config_dyn_bw_sig(dut, intf, val);
5791 break;
5792 default:
5793 sigma_dut_print(dut, DUT_MSG_ERROR,
5794 "Failed to set DYN_BW_SGNL");
5795 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005796 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005797 }
5798
5799 val = get_param(cmd, "RTS_FORCE");
5800 if (val) {
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07005801 novap_reset(dut, intf, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005802 if (strcasecmp(val, "Enable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305803 if (sta_set_rts(dut, intf, 64) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02005804 sigma_dut_print(dut, DUT_MSG_ERROR,
5805 "Failed to set RTS_FORCE 64");
5806 }
Jouni Malinen3aa72862019-05-29 23:14:51 +03005807 res = snprintf(buf, sizeof(buf),
5808 "wifitool %s beeliner_fw_test 100 1",
5809 intf);
5810 if (res < 0 || res >= sizeof(buf) || system(buf) != 0) {
priyadharshini gowthaman270870e2015-12-09 10:10:23 -08005811 sigma_dut_print(dut, DUT_MSG_ERROR,
5812 "wifitool beeliner_fw_test 100 1 failed");
5813 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005814 } else if (strcasecmp(val, "Disable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305815 if (sta_set_rts(dut, intf, 2347) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02005816 sigma_dut_print(dut, DUT_MSG_ERROR,
5817 "Failed to set RTS_FORCE 2347");
5818 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005819 } else {
5820 send_resp(dut, conn, SIGMA_ERROR,
5821 "ErrorCode,RTS_FORCE value not supported");
5822 return 0;
5823 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005824 }
5825
5826 val = get_param(cmd, "CTS_WIDTH");
5827 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005828 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005829 case DRIVER_WCN:
5830 if (wcn_sta_set_cts_width(dut, intf, val) < 0) {
5831 send_resp(dut, conn, SIGMA_ERROR,
5832 "ErrorCode,Failed to set CTS_WIDTH");
5833 return 0;
5834 }
5835 break;
5836 case DRIVER_ATHEROS:
5837 ath_set_cts_width(dut, intf, val);
5838 break;
5839 default:
5840 sigma_dut_print(dut, DUT_MSG_ERROR,
5841 "Setting CTS_WIDTH not supported");
5842 break;
5843 }
5844 }
5845
5846 val = get_param(cmd, "BW_SGNL");
5847 if (val) {
5848 if (strcasecmp(val, "Enable") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005849 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005850 } else if (strcasecmp(val, "Disable") == 0) {
5851 /* TODO: Disable */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005852 } else {
5853 send_resp(dut, conn, SIGMA_ERROR,
5854 "ErrorCode,BW_SGNL value not supported");
5855 return 0;
5856 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005857 }
5858
5859 val = get_param(cmd, "Band");
5860 if (val) {
5861 if (strcmp(val, "2.4") == 0 || strcmp(val, "5") == 0) {
5862 /* STA supports all bands by default */
5863 } else {
5864 send_resp(dut, conn, SIGMA_ERROR,
5865 "ErrorCode,Unsupported Band");
5866 return 0;
5867 }
5868 }
5869
5870 val = get_param(cmd, "zero_crc");
5871 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005872 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005873 case DRIVER_ATHEROS:
5874 ath_set_zero_crc(dut, val);
5875 break;
5876 default:
5877 break;
5878 }
5879 }
5880
5881 return 1;
5882}
5883
5884
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005885static int sta_set_force_mcs(struct sigma_dut *dut, int force, int mcs)
5886{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005887 switch (get_driver_type(dut)) {
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005888#ifdef __linux__
5889 case DRIVER_WIL6210:
5890 return wil6210_set_force_mcs(dut, force, mcs);
5891#endif /* __linux__ */
5892 default:
5893 sigma_dut_print(dut, DUT_MSG_ERROR,
5894 "Unsupported sta_set_force_mcs with the current driver");
5895 return -1;
5896 }
5897}
5898
5899
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02005900static int sta_60g_force_rsn_ie(struct sigma_dut *dut, int state)
5901{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005902 switch (get_driver_type(dut)) {
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02005903#ifdef __linux__
5904 case DRIVER_WIL6210:
5905 return wil6210_force_rsn_ie(dut, state);
5906#endif /* __linux__ */
5907 default:
5908 sigma_dut_print(dut, DUT_MSG_ERROR,
5909 "Unsupported sta_60g_force_rsn_ie with the current driver");
5910 return -1;
5911 }
5912}
5913
5914
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005915static int sta_set_60g_common(struct sigma_dut *dut, struct sigma_conn *conn,
5916 struct sigma_cmd *cmd)
5917{
5918 const char *val;
5919 char buf[100];
5920
5921 val = get_param(cmd, "MSDUSize");
5922 if (val) {
5923 int mtu;
5924
5925 dut->amsdu_size = atoi(val);
5926 if (dut->amsdu_size > IEEE80211_MAX_DATA_LEN_DMG ||
5927 dut->amsdu_size < IEEE80211_SNAP_LEN_DMG) {
5928 sigma_dut_print(dut, DUT_MSG_ERROR,
5929 "MSDUSize %d is above max %d or below min %d",
5930 dut->amsdu_size,
5931 IEEE80211_MAX_DATA_LEN_DMG,
5932 IEEE80211_SNAP_LEN_DMG);
5933 dut->amsdu_size = 0;
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005934 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005935 }
5936
5937 mtu = dut->amsdu_size - IEEE80211_SNAP_LEN_DMG;
5938 sigma_dut_print(dut, DUT_MSG_DEBUG,
5939 "Setting amsdu_size to %d", mtu);
5940 snprintf(buf, sizeof(buf), "ifconfig %s mtu %d",
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005941 get_station_ifname(dut), mtu);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005942
5943 if (system(buf) != 0) {
5944 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
5945 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005946 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005947 }
5948 }
5949
5950 val = get_param(cmd, "BAckRcvBuf");
5951 if (val) {
5952 dut->back_rcv_buf = atoi(val);
5953 if (dut->back_rcv_buf == 0) {
5954 sigma_dut_print(dut, DUT_MSG_ERROR,
5955 "Failed to convert %s or value is 0",
5956 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005957 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005958 }
5959
5960 sigma_dut_print(dut, DUT_MSG_DEBUG,
5961 "Setting BAckRcvBuf to %s", val);
5962 }
5963
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005964 val = get_param(cmd, "MCS_FixedRate");
5965 if (val) {
5966 if (sta_set_force_mcs(dut, 1, atoi(val))) {
5967 sigma_dut_print(dut, DUT_MSG_ERROR,
5968 "Failed to force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005969 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005970 }
5971 }
5972
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005973 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005974}
5975
5976
5977static int sta_pcp_start(struct sigma_dut *dut, struct sigma_conn *conn,
5978 struct sigma_cmd *cmd)
5979{
5980 int net_id;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005981 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005982 const char *val;
5983 char buf[100];
5984
5985 dut->mode = SIGMA_MODE_STATION;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005986 ifname = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005987 if (wpa_command(ifname, "PING") != 0) {
5988 sigma_dut_print(dut, DUT_MSG_ERROR, "Supplicant not running");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005989 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005990 }
5991
5992 wpa_command(ifname, "FLUSH");
5993 net_id = add_network_common(dut, conn, ifname, cmd);
5994 if (net_id < 0) {
5995 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add network");
5996 return net_id;
5997 }
5998
5999 /* TODO: mode=2 for the AP; in the future, replace for mode PCP */
6000 if (set_network(ifname, net_id, "mode", "2") < 0) {
6001 sigma_dut_print(dut, DUT_MSG_ERROR,
6002 "Failed to set supplicant network mode");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006003 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006004 }
6005
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02006006 if (set_network(ifname, net_id, "pbss", "1") < 0)
6007 return -2;
6008
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006009 sigma_dut_print(dut, DUT_MSG_DEBUG,
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02006010 "Supplicant set network with mode 2. network_id %d",
6011 net_id);
6012
6013 if (set_network(ifname, net_id, "wps_disabled", "0") < 0) {
6014 sigma_dut_print(dut, DUT_MSG_INFO,
6015 "Failed to set supplicant to WPS ENABLE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006016 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02006017 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006018
6019 val = get_param(cmd, "Security");
6020 if (val && strcasecmp(val, "OPEN") == 0) {
6021 dut->ap_key_mgmt = AP_OPEN;
6022 if (set_network(ifname, net_id, "key_mgmt", "NONE") < 0) {
6023 sigma_dut_print(dut, DUT_MSG_ERROR,
6024 "Failed to set supplicant to %s security",
6025 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006026 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006027 }
6028 } else if (val && strcasecmp(val, "WPA2-PSK") == 0) {
6029 dut->ap_key_mgmt = AP_WPA2_PSK;
6030 if (set_network(ifname, net_id, "key_mgmt", "WPA-PSK") < 0) {
6031 sigma_dut_print(dut, DUT_MSG_ERROR,
6032 "Failed to set supplicant to %s security",
6033 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006034 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006035 }
6036
6037 if (set_network(ifname, net_id, "proto", "RSN") < 0) {
6038 sigma_dut_print(dut, DUT_MSG_ERROR,
6039 "Failed to set supplicant to proto RSN");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006040 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006041 }
6042 } else if (val) {
6043 sigma_dut_print(dut, DUT_MSG_ERROR,
6044 "Requested Security %s is not supported on 60GHz",
6045 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006046 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006047 }
6048
6049 val = get_param(cmd, "Encrypt");
6050 if (val && strcasecmp(val, "AES-GCMP") == 0) {
6051 if (set_network(ifname, net_id, "pairwise", "GCMP") < 0) {
6052 sigma_dut_print(dut, DUT_MSG_ERROR,
6053 "Failed to set supplicant to pairwise GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006054 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006055 }
6056 if (set_network(ifname, net_id, "group", "GCMP") < 0) {
6057 sigma_dut_print(dut, DUT_MSG_ERROR,
6058 "Failed to set supplicant to group GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006059 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006060 }
6061 } else if (val) {
6062 sigma_dut_print(dut, DUT_MSG_ERROR,
6063 "Requested Encrypt %s is not supported on 60 GHz",
6064 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006065 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006066 }
6067
6068 val = get_param(cmd, "PSK");
6069 if (val && set_network_quoted(ifname, net_id, "psk", val) < 0) {
6070 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set psk %s",
6071 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006072 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006073 }
6074
6075 /* Convert 60G channel to freq */
6076 switch (dut->ap_channel) {
6077 case 1:
6078 val = "58320";
6079 break;
6080 case 2:
6081 val = "60480";
6082 break;
6083 case 3:
6084 val = "62640";
6085 break;
6086 default:
6087 sigma_dut_print(dut, DUT_MSG_ERROR,
6088 "Failed to configure channel %d. Not supported",
6089 dut->ap_channel);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006090 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006091 }
6092
6093 if (set_network(ifname, net_id, "frequency", val) < 0) {
6094 sigma_dut_print(dut, DUT_MSG_ERROR,
6095 "Failed to set supplicant network frequency");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006096 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006097 }
6098
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02006099 if (dut->eap_fragment) {
6100 sigma_dut_print(dut, DUT_MSG_DEBUG,
6101 "Set EAP fragment size to 128 bytes.");
6102 if (set_network(ifname, net_id, "fragment_size", "128") < 0)
6103 return ERROR_SEND_STATUS;
6104 }
6105
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006106 sigma_dut_print(dut, DUT_MSG_DEBUG,
6107 "Supplicant set network with frequency");
6108
6109 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d", net_id);
6110 if (wpa_command(ifname, buf) < 0) {
6111 sigma_dut_print(dut, DUT_MSG_INFO,
6112 "Failed to select network id %d on %s",
6113 net_id, ifname);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006114 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006115 }
6116
6117 sigma_dut_print(dut, DUT_MSG_DEBUG, "Selected network");
6118
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006119 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006120}
6121
6122
Lior David67543f52017-01-03 19:04:22 +02006123static int wil6210_set_abft_len(struct sigma_dut *dut, int abft_len)
6124{
6125 char buf[128], fname[128];
6126 FILE *f;
Jouni Malinen3aa72862019-05-29 23:14:51 +03006127 int res;
Lior David67543f52017-01-03 19:04:22 +02006128
6129 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
6130 sigma_dut_print(dut, DUT_MSG_ERROR,
6131 "failed to get wil6210 debugfs dir");
6132 return -1;
6133 }
6134
Jouni Malinen3aa72862019-05-29 23:14:51 +03006135 res = snprintf(fname, sizeof(fname), "%s/abft_len", buf);
6136 if (res < 0 || res >= sizeof(fname))
6137 return -1;
Lior David67543f52017-01-03 19:04:22 +02006138 f = fopen(fname, "w");
6139 if (!f) {
6140 sigma_dut_print(dut, DUT_MSG_ERROR,
6141 "failed to open: %s", fname);
6142 return -1;
6143 }
6144
6145 fprintf(f, "%d\n", abft_len);
6146 fclose(f);
6147
6148 return 0;
6149}
6150
6151
Alexei Avshalom Lazar49498b82019-01-31 15:16:32 +02006152int sta_set_60g_abft_len(struct sigma_dut *dut, struct sigma_conn *conn,
6153 int abft_len)
Lior David67543f52017-01-03 19:04:22 +02006154{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006155 switch (get_driver_type(dut)) {
Lior David67543f52017-01-03 19:04:22 +02006156 case DRIVER_WIL6210:
6157 return wil6210_set_abft_len(dut, abft_len);
6158 default:
6159 sigma_dut_print(dut, DUT_MSG_ERROR,
6160 "set abft_len not supported");
6161 return -1;
6162 }
6163}
6164
6165
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006166static int sta_set_60g_pcp(struct sigma_dut *dut, struct sigma_conn *conn,
6167 struct sigma_cmd *cmd)
6168{
6169 const char *val;
Lior David67543f52017-01-03 19:04:22 +02006170 unsigned int abft_len = 1; /* default is one slot */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006171
6172 if (dut->dev_role != DEVROLE_PCP) {
6173 send_resp(dut, conn, SIGMA_INVALID,
6174 "ErrorCode,Invalid DevRole");
6175 return 0;
6176 }
6177
6178 val = get_param(cmd, "SSID");
6179 if (val) {
6180 if (strlen(val) > sizeof(dut->ap_ssid) - 1) {
6181 send_resp(dut, conn, SIGMA_INVALID,
6182 "ErrorCode,Invalid SSID");
6183 return -1;
6184 }
6185
Peng Xub8fc5cc2017-05-10 17:27:28 -07006186 strlcpy(dut->ap_ssid, val, sizeof(dut->ap_ssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006187 }
6188
6189 val = get_param(cmd, "CHANNEL");
6190 if (val) {
6191 const char *pos;
6192
6193 dut->ap_channel = atoi(val);
6194 pos = strchr(val, ';');
6195 if (pos) {
6196 pos++;
6197 dut->ap_channel_1 = atoi(pos);
6198 }
6199 }
6200
6201 switch (dut->ap_channel) {
6202 case 1:
6203 case 2:
6204 case 3:
6205 break;
6206 default:
6207 sigma_dut_print(dut, DUT_MSG_ERROR,
6208 "Channel %d is not supported", dut->ap_channel);
6209 send_resp(dut, conn, SIGMA_ERROR,
6210 "Requested channel is not supported");
6211 return -1;
6212 }
6213
6214 val = get_param(cmd, "BCNINT");
6215 if (val)
6216 dut->ap_bcnint = atoi(val);
6217
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006218 val = get_param(cmd, "AllocType");
6219 if (val) {
6220 send_resp(dut, conn, SIGMA_ERROR,
6221 "ErrorCode,AllocType is not supported yet");
6222 return -1;
6223 }
6224
6225 val = get_param(cmd, "PercentBI");
6226 if (val) {
6227 send_resp(dut, conn, SIGMA_ERROR,
6228 "ErrorCode,PercentBI is not supported yet");
6229 return -1;
6230 }
6231
6232 val = get_param(cmd, "CBAPOnly");
6233 if (val) {
6234 send_resp(dut, conn, SIGMA_ERROR,
6235 "ErrorCode,CBAPOnly is not supported yet");
6236 return -1;
6237 }
6238
6239 val = get_param(cmd, "AMPDU");
6240 if (val) {
6241 if (strcasecmp(val, "Enable") == 0)
6242 dut->ap_ampdu = 1;
6243 else if (strcasecmp(val, "Disable") == 0)
6244 dut->ap_ampdu = 2;
6245 else {
6246 send_resp(dut, conn, SIGMA_ERROR,
6247 "ErrorCode,AMPDU value is not Enable nor Disabled");
6248 return -1;
6249 }
6250 }
6251
6252 val = get_param(cmd, "AMSDU");
6253 if (val) {
6254 if (strcasecmp(val, "Enable") == 0)
6255 dut->ap_amsdu = 1;
6256 else if (strcasecmp(val, "Disable") == 0)
6257 dut->ap_amsdu = 2;
6258 }
6259
6260 val = get_param(cmd, "NumMSDU");
6261 if (val) {
6262 send_resp(dut, conn, SIGMA_ERROR,
6263 "ErrorCode, NumMSDU is not supported yet");
6264 return -1;
6265 }
6266
6267 val = get_param(cmd, "ABFTLRang");
6268 if (val) {
6269 sigma_dut_print(dut, DUT_MSG_DEBUG,
Lior David67543f52017-01-03 19:04:22 +02006270 "ABFTLRang parameter %s", val);
6271 if (strcmp(val, "Gt1") == 0)
6272 abft_len = 2; /* 2 slots in this case */
6273 }
6274
6275 if (sta_set_60g_abft_len(dut, conn, abft_len)) {
6276 send_resp(dut, conn, SIGMA_ERROR,
6277 "ErrorCode, Can't set ABFT length");
6278 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006279 }
6280
6281 if (sta_pcp_start(dut, conn, cmd) < 0) {
6282 send_resp(dut, conn, SIGMA_ERROR,
6283 "ErrorCode, Can't start PCP role");
6284 return -1;
6285 }
6286
6287 return sta_set_60g_common(dut, conn, cmd);
6288}
6289
6290
6291static int sta_set_60g_sta(struct sigma_dut *dut, struct sigma_conn *conn,
6292 struct sigma_cmd *cmd)
6293{
6294 const char *val = get_param(cmd, "DiscoveryMode");
6295
6296 if (dut->dev_role != DEVROLE_STA) {
6297 send_resp(dut, conn, SIGMA_INVALID,
6298 "ErrorCode,Invalid DevRole");
6299 return 0;
6300 }
6301
6302 if (val) {
6303 sigma_dut_print(dut, DUT_MSG_DEBUG, "Discovery: %s", val);
6304 /* Ignore Discovery mode till Driver expose API. */
6305#if 0
6306 if (strcasecmp(val, "1") == 0) {
6307 send_resp(dut, conn, SIGMA_INVALID,
6308 "ErrorCode,DiscoveryMode 1 not supported");
6309 return 0;
6310 }
6311
6312 if (strcasecmp(val, "0") == 0) {
6313 /* OK */
6314 } else {
6315 send_resp(dut, conn, SIGMA_INVALID,
6316 "ErrorCode,DiscoveryMode not supported");
6317 return 0;
6318 }
6319#endif
6320 }
6321
6322 if (start_sta_mode(dut) != 0)
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006323 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006324 return sta_set_60g_common(dut, conn, cmd);
6325}
6326
6327
Jouni Malinenf7222712019-06-13 01:50:21 +03006328static enum sigma_cmd_result cmd_sta_disconnect(struct sigma_dut *dut,
6329 struct sigma_conn *conn,
6330 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006331{
6332 const char *intf = get_param(cmd, "Interface");
Jouni Malinened77e672018-01-10 16:45:13 +02006333 const char *val = get_param(cmd, "maintain_profile");
vamsi krishnad605c422017-09-20 14:56:31 +05306334
Jouni Malinened77e672018-01-10 16:45:13 +02006335 if (dut->program == PROGRAM_OCE ||
Amarnath Hullur Subramanyamebeda9e2018-01-31 03:21:48 -08006336 dut->program == PROGRAM_HE ||
Jouni Malinened77e672018-01-10 16:45:13 +02006337 (val && atoi(val) == 1)) {
vamsi krishnad605c422017-09-20 14:56:31 +05306338 wpa_command(intf, "DISCONNECT");
6339 return 1;
6340 }
6341
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006342 disconnect_station(dut);
6343 /* Try to ignore old scan results to avoid HS 2.0R2 test case failures
6344 * due to cached results. */
6345 wpa_command(intf, "SET ignore_old_scan_res 1");
6346 wpa_command(intf, "BSS_FLUSH");
6347 return 1;
6348}
6349
6350
Jouni Malinenf7222712019-06-13 01:50:21 +03006351static enum sigma_cmd_result cmd_sta_reassoc(struct sigma_dut *dut,
6352 struct sigma_conn *conn,
6353 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006354{
6355 const char *intf = get_param(cmd, "Interface");
6356 const char *bssid = get_param(cmd, "bssid");
6357 const char *val = get_param(cmd, "CHANNEL");
6358 struct wpa_ctrl *ctrl;
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306359 char buf[1000];
Sunil Duttd30ce092018-01-11 23:56:29 +05306360 char result[32];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006361 int res;
6362 int chan = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006363 enum sigma_cmd_result status = STATUS_SENT;
Sunil Duttd30ce092018-01-11 23:56:29 +05306364 int fastreassoc = 1;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006365 int ft_ds = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006366
6367 if (bssid == NULL) {
6368 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing bssid "
6369 "argument");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006370 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006371 }
6372
6373 if (val)
6374 chan = atoi(val);
6375
6376 if (wifi_chip_type != DRIVER_WCN && wifi_chip_type != DRIVER_AR6003) {
6377 /* The current network may be from sta_associate or
6378 * sta_hs2_associate
6379 */
6380 if (set_network(intf, dut->infra_network_id, "bssid", bssid) <
6381 0 ||
6382 set_network(intf, 0, "bssid", bssid) < 0)
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006383 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006384 }
6385
6386 ctrl = open_wpa_mon(intf);
6387 if (ctrl == NULL) {
6388 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
6389 "wpa_supplicant monitor connection");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006390 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006391 }
6392
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006393 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Sunil Duttd30ce092018-01-11 23:56:29 +05306394 sizeof(result)) < 0 ||
6395 strncmp(result, "COMPLETED", 9) != 0) {
6396 sigma_dut_print(dut, DUT_MSG_DEBUG,
6397 "sta_reassoc: Not connected");
6398 fastreassoc = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006399 } else if (dut->sta_ft_ds) {
6400 sigma_dut_print(dut, DUT_MSG_DEBUG,
6401 "sta_reassoc: Use FT-over-DS");
6402 ft_ds = 1;
Sunil Duttd30ce092018-01-11 23:56:29 +05306403 }
6404
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306405 if (dut->rsne_override) {
6406#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006407 if (get_driver_type(dut) == DRIVER_WCN &&
6408 dut->config_rsnie == 0) {
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306409 sta_config_rsnie(dut, 1);
6410 dut->config_rsnie = 1;
6411 }
6412#endif /* NL80211_SUPPORT */
6413 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
6414 dut->rsne_override);
6415 if (wpa_command(intf, buf) < 0) {
6416 send_resp(dut, conn, SIGMA_ERROR,
6417 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
6418 return 0;
6419 }
6420 }
6421
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006422 if (ft_ds) {
6423 if (chan) {
6424 unsigned int freq;
6425
6426 freq = channel_to_freq(dut, chan);
6427 if (!freq) {
6428 sigma_dut_print(dut, DUT_MSG_ERROR,
6429 "Invalid channel number provided: %d",
6430 chan);
6431 send_resp(dut, conn, SIGMA_INVALID,
6432 "ErrorCode,Invalid channel number");
6433 goto close_mon_conn;
6434 }
6435 res = snprintf(buf, sizeof(buf),
6436 "SCAN TYPE=ONLY freq=%d", freq);
6437 } else {
6438 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
6439 }
6440 if (res < 0 || res >= (int) sizeof(buf)) {
6441 send_resp(dut, conn, SIGMA_ERROR,
6442 "ErrorCode,snprintf failed");
6443 goto close_mon_conn;
6444 }
6445 if (wpa_command(intf, buf) < 0) {
6446 sigma_dut_print(dut, DUT_MSG_INFO,
6447 "Failed to start scan");
6448 send_resp(dut, conn, SIGMA_ERROR,
6449 "ErrorCode,scan failed");
6450 goto close_mon_conn;
6451 }
6452
6453 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
6454 buf, sizeof(buf));
6455 if (res < 0) {
6456 sigma_dut_print(dut, DUT_MSG_INFO,
6457 "Scan did not complete");
6458 send_resp(dut, conn, SIGMA_ERROR,
6459 "ErrorCode,scan did not complete");
6460 goto close_mon_conn;
6461 }
6462
6463 res = snprintf(buf, sizeof(buf), "FT_DS %s", bssid);
6464 if (res > 0 && res < (int) sizeof(buf))
6465 res = wpa_command(intf, buf);
6466
6467 if (res < 0 || res >= (int) sizeof(buf)) {
6468 send_resp(dut, conn, SIGMA_ERROR,
6469 "errorCode,FT_DS command failed");
6470 status = STATUS_SENT_ERROR;
6471 goto close_mon_conn;
6472 }
6473 } else if (wifi_chip_type == DRIVER_WCN && fastreassoc) {
Ashwini Patil4c8158f2017-05-25 12:49:21 +05306474 if (chan) {
6475 unsigned int freq;
6476
Alexei Avshalom Lazar093569f2018-11-13 14:08:17 +02006477 freq = channel_to_freq(dut, chan);
Ashwini Patil4c8158f2017-05-25 12:49:21 +05306478 if (!freq) {
6479 sigma_dut_print(dut, DUT_MSG_ERROR,
6480 "Invalid channel number provided: %d",
6481 chan);
6482 send_resp(dut, conn, SIGMA_INVALID,
6483 "ErrorCode,Invalid channel number");
6484 goto close_mon_conn;
6485 }
6486 res = snprintf(buf, sizeof(buf),
6487 "SCAN TYPE=ONLY freq=%d", freq);
6488 } else {
6489 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
6490 }
6491 if (res < 0 || res >= (int) sizeof(buf)) {
6492 send_resp(dut, conn, SIGMA_ERROR,
6493 "ErrorCode,snprintf failed");
6494 goto close_mon_conn;
6495 }
6496 if (wpa_command(intf, buf) < 0) {
6497 sigma_dut_print(dut, DUT_MSG_INFO,
6498 "Failed to start scan");
6499 send_resp(dut, conn, SIGMA_ERROR,
6500 "ErrorCode,scan failed");
6501 goto close_mon_conn;
6502 }
6503
6504 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
6505 buf, sizeof(buf));
6506 if (res < 0) {
6507 sigma_dut_print(dut, DUT_MSG_INFO,
6508 "Scan did not complete");
6509 send_resp(dut, conn, SIGMA_ERROR,
6510 "ErrorCode,scan did not complete");
6511 goto close_mon_conn;
6512 }
6513
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006514 if (set_network(intf, dut->infra_network_id, "bssid", "any")
6515 < 0) {
6516 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
6517 "bssid to any during FASTREASSOC");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006518 status = ERROR_SEND_STATUS;
Ashwini Patil467efef2017-05-25 12:18:27 +05306519 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006520 }
Vinita Maloo54b78cf2020-03-30 12:18:19 +05306521 res = snprintf(buf, sizeof(buf), "FASTREASSOC %s %d",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006522 bssid, chan);
Vinita Maloo54b78cf2020-03-30 12:18:19 +05306523 if (res < 0 || res >= (int) sizeof(buf) ||
6524 wcn_driver_cmd(intf, buf) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006525 send_resp(dut, conn, SIGMA_ERROR,
Vinita Maloo54b78cf2020-03-30 12:18:19 +05306526 "errorCode,Failed to run FASTREASSOC");
Ashwini Patil467efef2017-05-25 12:18:27 +05306527 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006528 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006529 sigma_dut_print(dut, DUT_MSG_INFO,
6530 "sta_reassoc: Run %s successful", buf);
6531 } else if (wpa_command(intf, "REASSOCIATE")) {
6532 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
6533 "request reassociation");
Ashwini Patil467efef2017-05-25 12:18:27 +05306534 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006535 }
6536
6537 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
6538 buf, sizeof(buf));
Ashwini Patil467efef2017-05-25 12:18:27 +05306539 if (res < 0) {
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006540 send_resp(dut, conn, SIGMA_ERROR,
6541 "errorCode,Connection did not complete");
6542 status = STATUS_SENT_ERROR;
Ashwini Patil467efef2017-05-25 12:18:27 +05306543 goto close_mon_conn;
6544 }
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006545 status = SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006546
Ashwini Patil467efef2017-05-25 12:18:27 +05306547close_mon_conn:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006548 wpa_ctrl_detach(ctrl);
6549 wpa_ctrl_close(ctrl);
Ashwini Patil467efef2017-05-25 12:18:27 +05306550 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006551}
6552
6553
6554static void hs2_clear_credentials(const char *intf)
6555{
6556 wpa_command(intf, "REMOVE_CRED all");
6557}
6558
6559
Lior Davidcc88b562017-01-03 18:52:09 +02006560#ifdef __linux__
6561static int wil6210_get_aid(struct sigma_dut *dut, const char *bssid,
6562 unsigned int *aid)
6563{
Lior David0fe101e2017-03-09 16:09:50 +02006564 const char *pattern = "AID[ \t]+([0-9]+)";
Lior Davidcc88b562017-01-03 18:52:09 +02006565
Lior David0fe101e2017-03-09 16:09:50 +02006566 return wil6210_get_sta_info_field(dut, bssid, pattern, aid);
Lior Davidcc88b562017-01-03 18:52:09 +02006567}
6568#endif /* __linux__ */
6569
6570
6571static int sta_get_aid_60g(struct sigma_dut *dut, const char *bssid,
6572 unsigned int *aid)
6573{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006574 switch (get_driver_type(dut)) {
Lior Davidcc88b562017-01-03 18:52:09 +02006575#ifdef __linux__
6576 case DRIVER_WIL6210:
6577 return wil6210_get_aid(dut, bssid, aid);
6578#endif /* __linux__ */
6579 default:
6580 sigma_dut_print(dut, DUT_MSG_ERROR, "get AID not supported");
6581 return -1;
6582 }
6583}
6584
6585
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006586static int sta_get_parameter_60g(struct sigma_dut *dut, struct sigma_conn *conn,
6587 struct sigma_cmd *cmd)
6588{
6589 char buf[MAX_CMD_LEN];
6590 char bss_list[MAX_CMD_LEN];
6591 const char *parameter = get_param(cmd, "Parameter");
6592
6593 if (parameter == NULL)
6594 return -1;
6595
Lior Davidcc88b562017-01-03 18:52:09 +02006596 if (strcasecmp(parameter, "AID") == 0) {
6597 unsigned int aid = 0;
6598 char bssid[20];
6599
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006600 if (get_wpa_status(get_station_ifname(dut), "bssid",
Lior Davidcc88b562017-01-03 18:52:09 +02006601 bssid, sizeof(bssid)) < 0) {
6602 sigma_dut_print(dut, DUT_MSG_ERROR,
6603 "could not get bssid");
6604 return -2;
6605 }
6606
6607 if (sta_get_aid_60g(dut, bssid, &aid))
6608 return -2;
6609
6610 snprintf(buf, sizeof(buf), "aid,%d", aid);
6611 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
6612 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6613 return 0;
6614 }
6615
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006616 if (strcasecmp(parameter, "DiscoveredDevList") == 0) {
6617 char *bss_line;
6618 char *bss_id = NULL;
6619 const char *ifname = get_param(cmd, "Interface");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306620 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006621
6622 if (ifname == NULL) {
6623 sigma_dut_print(dut, DUT_MSG_INFO,
6624 "For get DiscoveredDevList need Interface name.");
6625 return -1;
6626 }
6627
6628 /*
6629 * Use "BSS RANGE=ALL MASK=0x2" which provides a list
6630 * of BSSIDs in "bssid=<BSSID>\n"
6631 */
6632 if (wpa_command_resp(ifname, "BSS RANGE=ALL MASK=0x2",
6633 bss_list,
6634 sizeof(bss_list)) < 0) {
6635 sigma_dut_print(dut, DUT_MSG_ERROR,
6636 "Failed to get bss list");
6637 return -1;
6638 }
6639
6640 sigma_dut_print(dut, DUT_MSG_DEBUG,
6641 "bss list for ifname:%s is:%s",
6642 ifname, bss_list);
6643
6644 snprintf(buf, sizeof(buf), "DeviceList");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306645 bss_line = strtok_r(bss_list, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006646 while (bss_line) {
6647 if (sscanf(bss_line, "bssid=%ms", &bss_id) > 0 &&
6648 bss_id) {
6649 int len;
6650
6651 len = snprintf(buf + strlen(buf),
6652 sizeof(buf) - strlen(buf),
6653 ",%s", bss_id);
6654 free(bss_id);
6655 bss_id = NULL;
6656 if (len < 0) {
6657 sigma_dut_print(dut,
6658 DUT_MSG_ERROR,
6659 "Failed to read BSSID");
6660 send_resp(dut, conn, SIGMA_ERROR,
6661 "ErrorCode,Failed to read BSS ID");
6662 return 0;
6663 }
6664
6665 if ((size_t) len >= sizeof(buf) - strlen(buf)) {
6666 sigma_dut_print(dut,
6667 DUT_MSG_ERROR,
6668 "Response buf too small for list");
6669 send_resp(dut, conn,
6670 SIGMA_ERROR,
6671 "ErrorCode,Response buf too small for list");
6672 return 0;
6673 }
6674 }
6675
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306676 bss_line = strtok_r(NULL, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006677 }
6678
6679 sigma_dut_print(dut, DUT_MSG_INFO, "DiscoveredDevList is %s",
6680 buf);
6681 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6682 return 0;
6683 }
6684
6685 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6686 return 0;
6687}
6688
6689
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006690static int sta_get_parameter_he(struct sigma_dut *dut, struct sigma_conn *conn,
6691 struct sigma_cmd *cmd)
6692{
6693 char buf[MAX_CMD_LEN];
6694 const char *parameter = get_param(cmd, "Parameter");
6695
6696 if (!parameter)
6697 return -1;
6698
6699 if (strcasecmp(parameter, "RSSI") == 0) {
6700 char rssi[10];
6701
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006702 if (get_wpa_signal_poll(dut, get_station_ifname(dut), "RSSI",
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006703 rssi, sizeof(rssi)) < 0) {
6704 sigma_dut_print(dut, DUT_MSG_ERROR,
6705 "Could not get RSSI");
6706 return -2;
6707 }
6708
6709 snprintf(buf, sizeof(buf), "rssi,%s", rssi);
6710 sigma_dut_print(dut, DUT_MSG_INFO, "RSSI %s", buf);
6711 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6712 return 0;
6713 }
6714
6715 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6716 return 0;
6717}
6718
6719
Jouni Malinenca0abd32020-02-09 20:18:10 +02006720static enum sigma_cmd_result sta_get_pmk(struct sigma_dut *dut,
6721 struct sigma_conn *conn,
6722 struct sigma_cmd *cmd)
6723{
6724 const char *intf = get_param(cmd, "Interface");
6725 char buf[4096], bssid[20], resp[200], *pos, *tmp;
6726
6727 snprintf(buf, sizeof(buf), "PMKSA_GET %d", dut->infra_network_id);
6728 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
6729 strncmp(buf, "UNKNOWN COMMAND", 15) == 0) {
6730 send_resp(dut, conn, SIGMA_ERROR,
6731 "ErrorCode,PMKSA_GET not supported");
6732 return STATUS_SENT_ERROR;
6733 }
6734
6735 if (strncmp(buf, "FAIL", 4) == 0 ||
6736 get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
6737 send_resp(dut, conn, SIGMA_ERROR,
6738 "ErrorCode,Could not find current network");
6739 return STATUS_SENT_ERROR;
6740 }
6741
6742 pos = buf;
6743 while (pos) {
6744 if (strncmp(pos, bssid, 17) == 0) {
6745 pos = strchr(pos, ' ');
6746 if (!pos)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05306747 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02006748 pos++;
6749 pos = strchr(pos, ' ');
6750 if (!pos)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05306751 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02006752 pos++;
6753 tmp = strchr(pos, ' ');
6754 if (!tmp)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05306755 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02006756 *tmp = '\0';
6757 break;
6758 }
Jouni Malinenca0abd32020-02-09 20:18:10 +02006759 pos = strchr(pos, '\n');
6760 if (pos)
6761 pos++;
6762 }
6763
6764 if (!pos) {
6765 send_resp(dut, conn, SIGMA_ERROR,
6766 "ErrorCode,PMK not available");
6767 return STATUS_SENT_ERROR;
6768 }
6769
6770 snprintf(resp, sizeof(resp), "PMK,%s", pos);
6771 send_resp(dut, conn, SIGMA_COMPLETE, resp);
6772 return STATUS_SENT;
6773}
6774
6775
Jouni Malinenf7222712019-06-13 01:50:21 +03006776static enum sigma_cmd_result cmd_sta_get_parameter(struct sigma_dut *dut,
6777 struct sigma_conn *conn,
6778 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006779{
6780 const char *program = get_param(cmd, "Program");
Jouni Malinenca0abd32020-02-09 20:18:10 +02006781 const char *parameter = get_param(cmd, "Parameter");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006782
Jouni Malinenca0abd32020-02-09 20:18:10 +02006783 if (!parameter)
6784 return INVALID_SEND_STATUS;
6785
6786 if (strcasecmp(parameter, "PMK") == 0)
6787 return sta_get_pmk(dut, conn, cmd);
6788
6789 if (!program)
6790 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006791
6792 if (strcasecmp(program, "P2PNFC") == 0)
6793 return p2p_cmd_sta_get_parameter(dut, conn, cmd);
6794
6795 if (strcasecmp(program, "60ghz") == 0)
6796 return sta_get_parameter_60g(dut, conn, cmd);
6797
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006798 if (strcasecmp(program, "he") == 0)
6799 return sta_get_parameter_he(dut, conn, cmd);
6800
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006801#ifdef ANDROID_NAN
6802 if (strcasecmp(program, "NAN") == 0)
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07006803 return nan_cmd_sta_get_parameter(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006804#endif /* ANDROID_NAN */
6805
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07006806#ifdef MIRACAST
6807 if (strcasecmp(program, "WFD") == 0 ||
6808 strcasecmp(program, "DisplayR2") == 0)
6809 return miracast_cmd_sta_get_parameter(dut, conn, cmd);
6810#endif /* MIRACAST */
6811
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006812 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6813 return 0;
6814}
6815
6816
6817static void sta_reset_default_ath(struct sigma_dut *dut, const char *intf,
6818 const char *type)
6819{
6820 char buf[100];
6821
6822 if (dut->program == PROGRAM_VHT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006823 run_iwpriv(dut, intf, "chwidth 2");
6824 run_iwpriv(dut, intf, "mode 11ACVHT80");
6825 run_iwpriv(dut, intf, "vhtmcs -1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006826 }
6827
6828 if (dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006829 run_iwpriv(dut, intf, "chwidth 0");
6830 run_iwpriv(dut, intf, "mode 11naht40");
6831 run_iwpriv(dut, intf, "set11NRates 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006832 }
6833
6834 if (dut->program == PROGRAM_VHT || dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006835 run_iwpriv(dut, intf, "powersave 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006836
6837 /* Reset CTS width */
6838 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 54 0",
6839 intf);
6840 if (system(buf) != 0) {
6841 sigma_dut_print(dut, DUT_MSG_ERROR,
6842 "wifitool %s beeliner_fw_test 54 0 failed",
6843 intf);
6844 }
6845
6846 /* Enable Dynamic Bandwidth signalling by default */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006847 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006848
6849 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", intf);
6850 if (system(buf) != 0) {
6851 sigma_dut_print(dut, DUT_MSG_ERROR,
6852 "iwpriv rts failed");
6853 }
6854 }
6855
6856 if (type && strcasecmp(type, "Testbed") == 0) {
6857 dut->testbed_flag_txsp = 1;
6858 dut->testbed_flag_rxsp = 1;
6859 /* STA has to set spatial stream to 2 per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006860 run_iwpriv(dut, intf, "vht_mcsmap 0xfff0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006861
6862 /* Disable LDPC per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006863 run_iwpriv(dut, intf, "ldpc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006864
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006865 run_iwpriv(dut, intf, "amsdu 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006866
6867 /* TODO: Disable STBC 2x1 transmit and receive */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006868 run_iwpriv(dut, intf, "tx_stbc 0");
6869 run_iwpriv(dut, intf, "rx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006870
6871 /* STA has to disable Short GI per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006872 run_iwpriv(dut, intf, "shortgi 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006873 }
6874
6875 if (type && strcasecmp(type, "DUT") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006876 run_iwpriv(dut, intf, "nss 3");
Arif Hussainac6c5112018-05-25 17:34:00 -07006877 dut->sta_nss = 3;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006878
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006879 run_iwpriv(dut, intf, "shortgi 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006880 }
6881}
6882
6883
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08006884#ifdef NL80211_SUPPORT
6885static int sta_set_he_mcs(struct sigma_dut *dut, const char *intf,
6886 enum he_mcs_config mcs)
6887{
6888 struct nl_msg *msg;
6889 int ret = 0;
6890 struct nlattr *params;
6891 int ifindex;
6892
6893 ifindex = if_nametoindex(intf);
6894 if (ifindex == 0) {
6895 sigma_dut_print(dut, DUT_MSG_ERROR,
6896 "%s: Index for interface %s failed",
6897 __func__, intf);
6898 return -1;
6899 }
6900
6901 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6902 NL80211_CMD_VENDOR)) ||
6903 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6904 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6905 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6906 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6907 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6908 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MCS,
6909 mcs)) {
6910 sigma_dut_print(dut, DUT_MSG_ERROR,
6911 "%s: err in adding vendor_cmd and vendor_data",
6912 __func__);
6913 nlmsg_free(msg);
6914 return -1;
6915 }
6916 nla_nest_end(msg, params);
6917
6918 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6919 if (ret) {
6920 sigma_dut_print(dut, DUT_MSG_ERROR,
6921 "%s: err in send_and_recv_msgs, ret=%d",
6922 __func__, ret);
6923 }
6924 return ret;
6925}
6926#endif /* NL80211_SUPPORT */
6927
6928
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07006929static int sta_set_action_tx_in_he_tb_ppdu(struct sigma_dut *dut,
6930 const char *intf, int enable)
6931{
6932#ifdef NL80211_SUPPORT
6933 struct nl_msg *msg;
6934 int ret = 0;
6935 struct nlattr *params;
6936 int ifindex;
6937
6938 ifindex = if_nametoindex(intf);
6939 if (ifindex == 0) {
6940 sigma_dut_print(dut, DUT_MSG_ERROR,
6941 "%s: Index for interface %s failed",
6942 __func__, intf);
6943 return -1;
6944 }
6945
6946 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6947 NL80211_CMD_VENDOR)) ||
6948 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6949 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6950 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6951 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6952 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6953 nla_put_u8(msg,
6954 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_ACTION_TX_TB_PPDU,
6955 enable)) {
6956 sigma_dut_print(dut, DUT_MSG_ERROR,
6957 "%s: err in adding vendor_cmd and vendor_data",
6958 __func__);
6959 nlmsg_free(msg);
6960 return -1;
6961 }
6962 nla_nest_end(msg, params);
6963
6964 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6965 if (ret) {
6966 sigma_dut_print(dut, DUT_MSG_ERROR,
6967 "%s: err in send_and_recv_msgs, ret=%d",
6968 __func__, ret);
6969 }
6970 return ret;
6971#else /* NL80211_SUPPORT */
6972 sigma_dut_print(dut, DUT_MSG_ERROR,
6973 "HE action Tx TB PPDU cannot be set without NL80211_SUPPORT defined");
6974 return -1;
6975#endif /* NL80211_SUPPORT */
6976}
6977
6978
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08006979static int sta_set_heconfig_and_wep_tkip(struct sigma_dut *dut,
6980 const char *intf, int enable)
6981{
6982#ifdef NL80211_SUPPORT
6983 struct nl_msg *msg;
6984 int ret = 0;
6985 struct nlattr *params;
6986 int ifindex;
6987
6988 ifindex = if_nametoindex(intf);
6989 if (ifindex == 0) {
6990 sigma_dut_print(dut, DUT_MSG_ERROR,
6991 "%s: Index for interface %s failed",
6992 __func__, intf);
6993 return -1;
6994 }
6995
6996 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6997 NL80211_CMD_VENDOR)) ||
6998 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6999 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7000 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7001 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7002 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7003 nla_put_u8(msg,
7004 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WEP_TKIP_IN_HE,
7005 enable)) {
7006 sigma_dut_print(dut, DUT_MSG_ERROR,
7007 "%s: err in adding vendor_cmd and vendor_data",
7008 __func__);
7009 nlmsg_free(msg);
7010 return -1;
7011 }
7012 nla_nest_end(msg, params);
7013
7014 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7015 if (ret) {
7016 sigma_dut_print(dut, DUT_MSG_ERROR,
7017 "%s: err in send_and_recv_msgs, ret=%d",
7018 __func__, ret);
7019 }
7020 return ret;
7021#else /* NL80211_SUPPORT */
7022 sigma_dut_print(dut, DUT_MSG_ERROR,
7023 "HE config enablement cannot be changed without NL80211_SUPPORT defined");
7024 return -1;
7025#endif /* NL80211_SUPPORT */
7026}
7027
7028
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007029#ifdef NL80211_SUPPORT
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007030
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007031static int sta_set_he_testbed_def(struct sigma_dut *dut,
7032 const char *intf, int cfg)
7033{
7034 struct nl_msg *msg;
7035 int ret = 0;
7036 struct nlattr *params;
7037 int ifindex;
7038
7039 ifindex = if_nametoindex(intf);
7040 if (ifindex == 0) {
7041 sigma_dut_print(dut, DUT_MSG_ERROR,
7042 "%s: Index for interface %s failed",
7043 __func__, intf);
7044 return -1;
7045 }
7046
7047 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7048 NL80211_CMD_VENDOR)) ||
7049 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7050 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7051 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7052 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7053 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7054 nla_put_u8(msg,
7055 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SET_HE_TESTBED_DEFAULTS,
7056 cfg)) {
7057 sigma_dut_print(dut, DUT_MSG_ERROR,
7058 "%s: err in adding vendor_cmd and vendor_data",
7059 __func__);
7060 nlmsg_free(msg);
7061 return -1;
7062 }
7063 nla_nest_end(msg, params);
7064
7065 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7066 if (ret) {
7067 sigma_dut_print(dut, DUT_MSG_ERROR,
7068 "%s: err in send_and_recv_msgs, ret=%d",
7069 __func__, ret);
7070 }
7071 return ret;
7072}
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007073
7074
7075static int sta_set_2g_vht_supp(struct sigma_dut *dut, const char *intf, int cfg)
7076{
7077 struct nl_msg *msg;
7078 int ret = 0;
7079 struct nlattr *params;
7080 int ifindex;
7081
7082 ifindex = if_nametoindex(intf);
7083 if (ifindex == 0) {
7084 sigma_dut_print(dut, DUT_MSG_ERROR,
7085 "%s: Index for interface %s failed",
7086 __func__, intf);
7087 return -1;
7088 }
7089
7090 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7091 NL80211_CMD_VENDOR)) ||
7092 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7093 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7094 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7095 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7096 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7097 nla_put_u8(msg,
7098 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_2G_VHT,
7099 cfg)) {
7100 sigma_dut_print(dut, DUT_MSG_ERROR,
7101 "%s: err in adding vendor_cmd and vendor_data",
7102 __func__);
7103 nlmsg_free(msg);
7104 return -1;
7105 }
7106 nla_nest_end(msg, params);
7107
7108 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7109 if (ret) {
7110 sigma_dut_print(dut, DUT_MSG_ERROR,
7111 "%s: err in send_and_recv_msgs, ret=%d",
7112 __func__, ret);
7113 }
7114 return ret;
7115}
7116
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007117#endif /* NL80211_SUPPORT */
7118
7119
Qiwei Caib6806972020-01-15 13:52:11 +08007120int sta_set_addba_buf_size(struct sigma_dut *dut,
7121 const char *intf, int bufsize)
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007122{
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",
7133 __func__, intf);
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)) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -07007144 nla_put_u16(msg,
7145 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
7146 bufsize)) {
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007147 sigma_dut_print(dut, DUT_MSG_ERROR,
7148 "%s: err in adding vendor_cmd and vendor_data",
7149 __func__);
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",
7159 __func__, ret);
7160 }
7161 return ret;
7162#else /* NL80211_SUPPORT */
7163 sigma_dut_print(dut, DUT_MSG_ERROR,
7164 "AddBA bufsize cannot be changed without NL80211_SUPPORT defined");
7165 return -1;
7166#endif /* NL80211_SUPPORT */
7167}
7168
7169
Arif Hussain8d5b27b2018-05-14 14:31:03 -07007170static int sta_set_tx_beamformee(struct sigma_dut *dut, const char *intf,
7171 int enable)
7172{
7173#ifdef NL80211_SUPPORT
7174 struct nl_msg *msg;
7175 int ret = 0;
7176 struct nlattr *params;
7177 int ifindex;
7178
7179 ifindex = if_nametoindex(intf);
7180 if (ifindex == 0) {
7181 sigma_dut_print(dut, DUT_MSG_ERROR,
7182 "%s: Index for interface %s failed",
7183 __func__, intf);
7184 return -1;
7185 }
7186
7187 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7188 NL80211_CMD_VENDOR)) ||
7189 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7190 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7191 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7192 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7193 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7194 nla_put_u8(msg,
7195 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_TX_BEAMFORMEE,
7196 enable)) {
7197 sigma_dut_print(dut, DUT_MSG_ERROR,
7198 "%s: err in adding vendor_cmd and vendor_data",
7199 __func__);
7200 nlmsg_free(msg);
7201 return -1;
7202 }
7203 nla_nest_end(msg, params);
7204
7205 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7206 if (ret) {
7207 sigma_dut_print(dut, DUT_MSG_ERROR,
7208 "%s: err in send_and_recv_msgs, ret=%d",
7209 __func__, ret);
7210 }
7211 return ret;
7212#else /* NL80211_SUPPORT */
7213 sigma_dut_print(dut, DUT_MSG_ERROR,
7214 "tx beamformee cannot be changed without NL80211_SUPPORT defined");
7215 return -1;
7216#endif /* NL80211_SUPPORT */
7217}
7218
7219
Arif Hussain9765f7d2018-07-03 08:28:26 -07007220static int sta_set_beamformee_sts(struct sigma_dut *dut, const char *intf,
7221 int val)
7222{
7223#ifdef NL80211_SUPPORT
7224 struct nl_msg *msg;
7225 int ret = 0;
7226 struct nlattr *params;
7227 int ifindex;
7228
7229 ifindex = if_nametoindex(intf);
7230 if (ifindex == 0) {
7231 sigma_dut_print(dut, DUT_MSG_ERROR,
7232 "%s: Index for interface %s failed, val:%d",
7233 __func__, intf, val);
7234 return -1;
7235 }
7236
7237 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7238 NL80211_CMD_VENDOR)) ||
7239 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7240 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7241 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7242 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7243 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7244 nla_put_u8(msg,
7245 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_BEAMFORMEE_NSTS,
7246 val)) {
7247 sigma_dut_print(dut, DUT_MSG_ERROR,
7248 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7249 __func__, val);
7250 nlmsg_free(msg);
7251 return -1;
7252 }
7253 nla_nest_end(msg, params);
7254
7255 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7256 if (ret) {
7257 sigma_dut_print(dut, DUT_MSG_ERROR,
7258 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7259 __func__, ret, val);
7260 }
7261 return ret;
7262#else /* NL80211_SUPPORT */
7263 sigma_dut_print(dut, DUT_MSG_ERROR,
7264 "beamformee sts cannot be changed without NL80211_SUPPORT defined");
7265 return -1;
7266#endif /* NL80211_SUPPORT */
7267}
7268
7269
Arif Hussain68d23f52018-07-11 13:39:08 -07007270#ifdef NL80211_SUPPORT
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007271static int sta_set_mac_padding_duration(struct sigma_dut *dut, const char *intf,
7272 enum qca_wlan_he_mac_padding_dur val)
7273{
Arif Hussain68d23f52018-07-11 13:39:08 -07007274 struct nl_msg *msg;
7275 int ret = 0;
7276 struct nlattr *params;
7277 int ifindex;
7278
7279 ifindex = if_nametoindex(intf);
7280 if (ifindex == 0) {
7281 sigma_dut_print(dut, DUT_MSG_ERROR,
7282 "%s: Index for interface %s failed, val:%d",
7283 __func__, intf, val);
7284 return -1;
7285 }
7286
7287 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7288 NL80211_CMD_VENDOR)) ||
7289 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7290 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7291 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7292 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7293 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7294 nla_put_u8(msg,
7295 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MAC_PADDING_DUR,
7296 val)) {
7297 sigma_dut_print(dut, DUT_MSG_ERROR,
7298 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7299 __func__, val);
7300 nlmsg_free(msg);
7301 return -1;
7302 }
7303 nla_nest_end(msg, params);
7304
7305 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7306 if (ret) {
7307 sigma_dut_print(dut, DUT_MSG_ERROR,
7308 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7309 __func__, ret, val);
7310 }
7311 return ret;
Arif Hussain68d23f52018-07-11 13:39:08 -07007312}
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007313#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07007314
7315
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07007316static int sta_set_tx_su_ppdu_cfg(struct sigma_dut *dut, const char *intf,
7317 int val)
7318{
7319#ifdef NL80211_SUPPORT
7320 struct nl_msg *msg;
7321 int ret = 0;
7322 struct nlattr *params;
7323 int ifindex;
7324
7325 ifindex = if_nametoindex(intf);
7326 if (ifindex == 0) {
7327 sigma_dut_print(dut, DUT_MSG_ERROR,
7328 "%s: Index for interface %s failed, val:%d",
7329 __func__, intf, val);
7330 return -1;
7331 }
7332
7333 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7334 NL80211_CMD_VENDOR)) ||
7335 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7336 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7337 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7338 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7339 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7340 nla_put_u8(msg,
7341 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_SUPPDU,
7342 val)) {
7343 sigma_dut_print(dut, DUT_MSG_ERROR,
7344 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7345 __func__, val);
7346 nlmsg_free(msg);
7347 return -1;
7348 }
7349 nla_nest_end(msg, params);
7350
7351 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7352 if (ret) {
7353 sigma_dut_print(dut, DUT_MSG_ERROR,
7354 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7355 __func__, ret, val);
7356 }
7357 return ret;
7358#else /* NL80211_SUPPORT */
7359 sigma_dut_print(dut, DUT_MSG_ERROR,
7360 "Tx SU PPDU cannot be set without NL80211_SUPPORT defined");
7361 return -1;
7362#endif /* NL80211_SUPPORT */
7363}
7364
7365
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007366#ifdef NL80211_SUPPORT
7367static int sta_set_he_om_ctrl_reset(struct sigma_dut *dut, const char *intf)
7368{
7369 struct nl_msg *msg;
7370 int ret = 0;
7371 struct nlattr *params;
7372 int ifindex;
7373
7374 ifindex = if_nametoindex(intf);
7375 if (ifindex == 0) {
7376 sigma_dut_print(dut, DUT_MSG_ERROR,
7377 "%s: Index for interface %s failed",
7378 __func__, intf);
7379 return -1;
7380 }
7381
7382 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7383 NL80211_CMD_VENDOR)) ||
7384 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7385 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7386 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7387 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7388 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7389 nla_put_flag(msg,
7390 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_CLEAR_HE_OM_CTRL_CONFIG)) {
7391 sigma_dut_print(dut, DUT_MSG_ERROR,
7392 "%s: err in adding vendor_cmd and vendor_data",
7393 __func__);
7394 nlmsg_free(msg);
7395 return -1;
7396 }
7397 nla_nest_end(msg, params);
7398
7399 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7400 if (ret) {
7401 sigma_dut_print(dut, DUT_MSG_ERROR,
7402 "%s: err in send_and_recv_msgs, ret=%d",
7403 __func__, ret);
7404 }
7405 return ret;
7406}
7407#endif /* NL80211_SUPPORT */
7408
7409
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07007410static int sta_set_mu_edca_override(struct sigma_dut *dut, const char *intf,
7411 int val)
7412{
7413#ifdef NL80211_SUPPORT
7414 struct nl_msg *msg;
7415 int ret = 0;
7416 struct nlattr *params;
7417 int ifindex;
7418
7419 ifindex = if_nametoindex(intf);
7420 if (ifindex == 0) {
7421 sigma_dut_print(dut, DUT_MSG_ERROR,
7422 "%s: Index for interface %s failed, val:%d",
7423 __func__, intf, val);
7424 return -1;
7425 }
7426
7427 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7428 NL80211_CMD_VENDOR)) ||
7429 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7430 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7431 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7432 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7433 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7434 nla_put_u8(msg,
7435 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_OVERRIDE_MU_EDCA,
7436 val)) {
7437 sigma_dut_print(dut, DUT_MSG_ERROR,
7438 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7439 __func__, val);
7440 nlmsg_free(msg);
7441 return -1;
7442 }
7443 nla_nest_end(msg, params);
7444
7445 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7446 if (ret) {
7447 sigma_dut_print(dut, DUT_MSG_ERROR,
7448 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7449 __func__, ret, val);
7450 }
7451 return ret;
7452#else /* NL80211_SUPPORT */
7453 sigma_dut_print(dut, DUT_MSG_ERROR,
7454 "MU EDCA override cannot be changed without NL80211_SUPPORT defined");
7455 return -1;
7456#endif /* NL80211_SUPPORT */
7457}
7458
7459
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007460static int sta_set_om_ctrl_supp(struct sigma_dut *dut, const char *intf,
7461 int val)
7462{
7463#ifdef NL80211_SUPPORT
7464 struct nl_msg *msg;
7465 int ret = 0;
7466 struct nlattr *params;
7467 int ifindex;
7468
7469 ifindex = if_nametoindex(intf);
7470 if (ifindex == 0) {
7471 sigma_dut_print(dut, DUT_MSG_ERROR,
7472 "%s: Index for interface %s failed, val:%d",
7473 __func__, intf, val);
7474 return -1;
7475 }
7476
7477 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7478 NL80211_CMD_VENDOR)) ||
7479 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7480 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7481 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7482 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7483 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7484 nla_put_u8(msg,
7485 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OM_CTRL_SUPP,
7486 val)) {
7487 sigma_dut_print(dut, DUT_MSG_ERROR,
7488 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7489 __func__, val);
7490 nlmsg_free(msg);
7491 return -1;
7492 }
7493 nla_nest_end(msg, params);
7494
7495 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7496 if (ret) {
7497 sigma_dut_print(dut, DUT_MSG_ERROR,
7498 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7499 __func__, ret, val);
7500 }
7501 return ret;
7502#else /* NL80211_SUPPORT */
7503 sigma_dut_print(dut, DUT_MSG_ERROR,
7504 "HE OM ctrl cannot be changed without NL80211_SUPPORT defined");
7505 return -1;
7506#endif /* NL80211_SUPPORT */
7507}
7508
7509
Arif Hussain480d5f42019-03-12 14:40:42 -07007510static int sta_set_twt_req_support(struct sigma_dut *dut, const char *intf,
7511 int val)
7512{
7513#ifdef NL80211_SUPPORT
7514 struct nl_msg *msg;
7515 int ret;
7516 struct nlattr *params;
7517 int ifindex;
7518
7519 ifindex = if_nametoindex(intf);
7520 if (ifindex == 0) {
7521 sigma_dut_print(dut, DUT_MSG_ERROR,
7522 "%s: Index for interface %s failed, val:%d",
7523 __func__, intf, val);
7524 return -1;
7525 }
7526
7527 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7528 NL80211_CMD_VENDOR)) ||
7529 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7530 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7531 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7532 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7533 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7534 nla_put_u8(msg,
7535 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TWT_REQ_SUPPORT,
7536 val)) {
7537 sigma_dut_print(dut, DUT_MSG_ERROR,
7538 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7539 __func__, val);
7540 nlmsg_free(msg);
7541 return -1;
7542 }
7543 nla_nest_end(msg, params);
7544
7545 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7546 if (ret) {
7547 sigma_dut_print(dut, DUT_MSG_ERROR,
7548 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7549 __func__, ret, val);
7550 }
7551 return ret;
7552#else /* NL80211_SUPPORT */
7553 sigma_dut_print(dut, DUT_MSG_ERROR,
7554 "TWT Request cannot be changed without NL80211_SUPPORT defined");
7555 return -1;
7556#endif /* NL80211_SUPPORT */
7557}
7558
7559
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007560static void sta_reset_default_wcn(struct sigma_dut *dut, const char *intf,
7561 const char *type)
7562{
7563 char buf[60];
7564
7565 if (dut->program == PROGRAM_HE) {
7566 /* resetting phymode to auto in case of HE program */
7567 snprintf(buf, sizeof(buf), "iwpriv %s setphymode 0", intf);
7568 if (system(buf) != 0) {
7569 sigma_dut_print(dut, DUT_MSG_ERROR,
7570 "iwpriv %s setphymode failed", intf);
7571 }
7572
Amarnath Hullur Subramanyam9cecb502018-04-25 13:26:30 -07007573 /* reset the rate to Auto rate */
7574 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0xff",
7575 intf);
7576 if (system(buf) != 0) {
7577 sigma_dut_print(dut, DUT_MSG_ERROR,
7578 "iwpriv %s set_11ax_rate 0xff failed",
7579 intf);
7580 }
7581
Kiran Kumar Lokere86cfe3a2018-06-01 11:55:15 -07007582 /* reset the LDPC setting */
7583 snprintf(buf, sizeof(buf), "iwpriv %s ldpc 1", intf);
7584 if (system(buf) != 0) {
7585 sigma_dut_print(dut, DUT_MSG_ERROR,
7586 "iwpriv %s ldpc 1 failed", intf);
7587 }
7588
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08007589 /* reset the power save setting */
Vinita S. Malooa8b62722020-04-23 01:45:41 +05307590 set_power_save_wcn(dut, intf, 2);
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08007591
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007592 /* remove all network profiles */
7593 remove_wpa_networks(intf);
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007594
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007595 /* Configure ADDBA Req/Rsp buffer size to be 64 */
7596 sta_set_addba_buf_size(dut, intf, 64);
7597
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08007598#ifdef NL80211_SUPPORT
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007599 /* Reset the device HE capabilities to its default supported
7600 * configuration. */
7601 sta_set_he_testbed_def(dut, intf, 0);
7602
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08007603 /* Disable noackpolicy for all AC */
7604 if (nlvendor_sta_set_noack(dut, intf, 0, QCA_WLAN_AC_ALL)) {
7605 sigma_dut_print(dut, DUT_MSG_ERROR,
7606 "Disable of noackpolicy for all AC failed");
7607 }
7608#endif /* NL80211_SUPPORT */
7609
Amarnath Hullur Subramanyamb1724a52018-03-07 14:31:46 -08007610 /* Enable WMM by default */
7611 if (wcn_sta_set_wmm(dut, intf, "on")) {
7612 sigma_dut_print(dut, DUT_MSG_ERROR,
7613 "Enable of WMM in sta_reset_default_wcn failed");
7614 }
7615
7616 /* Disable ADDBA_REJECT by default */
7617 if (nlvendor_sta_set_addba_reject(dut, intf, 0)) {
7618 sigma_dut_print(dut, DUT_MSG_ERROR,
7619 "Disable of addba_reject in sta_reset_default_wcn failed");
7620 }
7621
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08007622 /* Enable sending of ADDBA by default */
7623 if (nlvendor_config_send_addba(dut, intf, 1)) {
7624 sigma_dut_print(dut, DUT_MSG_ERROR,
7625 "Enable sending of ADDBA in sta_reset_default_wcn failed");
7626 }
7627
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08007628 /* Enable AMPDU by default */
7629 iwpriv_sta_set_ampdu(dut, intf, 1);
7630
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007631#ifdef NL80211_SUPPORT
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -08007632 if (wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_AUTO)) {
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007633 sigma_dut_print(dut, DUT_MSG_ERROR,
7634 "Set LTF config to default in sta_reset_default_wcn failed");
7635 }
Arif Hussain9765f7d2018-07-03 08:28:26 -07007636
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08007637 /* set the beamformee NSTS(maximum number of
7638 * space-time streams) to default DUT config
7639 */
7640 if (sta_set_beamformee_sts(dut, intf, 7)) {
Arif Hussain9765f7d2018-07-03 08:28:26 -07007641 sigma_dut_print(dut, DUT_MSG_ERROR,
7642 "Failed to set BeamformeeSTS");
7643 }
Arif Hussain68d23f52018-07-11 13:39:08 -07007644
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007645 if (sta_set_mac_padding_duration(
7646 dut, intf,
7647 QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07007648 sigma_dut_print(dut, DUT_MSG_ERROR,
7649 "Failed to set MAC padding duration");
7650 }
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07007651
7652 if (sta_set_mu_edca_override(dut, intf, 0)) {
7653 sigma_dut_print(dut, DUT_MSG_ERROR,
7654 "ErrorCode,Failed to set MU EDCA override disable");
7655 }
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007656
7657 if (sta_set_om_ctrl_supp(dut, intf, 1)) {
7658 sigma_dut_print(dut, DUT_MSG_ERROR,
7659 "Failed to set OM ctrl supp");
7660 }
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07007661
7662 if (sta_set_tx_su_ppdu_cfg(dut, intf, 1)) {
7663 sigma_dut_print(dut, DUT_MSG_ERROR,
7664 "Failed to set Tx SU PPDU enable");
7665 }
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007666
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07007667 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 0)) {
7668 sigma_dut_print(dut, DUT_MSG_ERROR,
7669 "failed to send TB PPDU Tx cfg");
7670 }
7671
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007672 if (sta_set_he_om_ctrl_reset(dut, intf)) {
7673 sigma_dut_print(dut, DUT_MSG_ERROR,
7674 "Failed to set OM ctrl reset");
7675 }
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08007676
7677 /* +HTC-HE support default on */
7678 if (sta_set_he_htc_supp(dut, intf, 1)) {
7679 sigma_dut_print(dut, DUT_MSG_ERROR,
7680 "Setting of +HTC-HE support failed");
7681 }
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007682#endif /* NL80211_SUPPORT */
7683
Arif Hussain8d5b27b2018-05-14 14:31:03 -07007684 if (sta_set_tx_beamformee(dut, intf, 1)) {
7685 sigma_dut_print(dut, DUT_MSG_ERROR,
7686 "Set tx beamformee enable by default in sta_reset_default_wcn failed");
7687 }
7688
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007689 /* Set nss to 1 and MCS 0-7 in case of testbed */
7690 if (type && strcasecmp(type, "Testbed") == 0) {
7691#ifdef NL80211_SUPPORT
7692 int ret;
7693#endif /* NL80211_SUPPORT */
7694
7695 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
7696 if (system(buf) != 0) {
7697 sigma_dut_print(dut, DUT_MSG_ERROR,
7698 "iwpriv %s nss failed", intf);
7699 }
7700
7701#ifdef NL80211_SUPPORT
7702 ret = sta_set_he_mcs(dut, intf, HE_80_MCS0_7);
7703 if (ret) {
7704 sigma_dut_print(dut, DUT_MSG_ERROR,
7705 "Setting of MCS failed, ret:%d",
7706 ret);
7707 }
7708#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyamc67621d2018-02-04 23:18:01 -08007709
7710 /* Disable STBC as default */
7711 wcn_sta_set_stbc(dut, intf, "0");
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08007712
7713 /* Disable AMSDU as default */
7714 iwpriv_sta_set_amsdu(dut, intf, "0");
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08007715
7716#ifdef NL80211_SUPPORT
7717 /* HE fragmentation default off */
7718 if (sta_set_he_fragmentation(dut, intf,
7719 HE_FRAG_DISABLE)) {
7720 sigma_dut_print(dut, DUT_MSG_ERROR,
7721 "Setting of HE fragmentation failed");
7722 }
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08007723
7724 /* set the beamformee NSTS(maximum number of
7725 * space-time streams) to default testbed config
7726 */
7727 if (sta_set_beamformee_sts(dut, intf, 3)) {
7728 sigma_dut_print(dut, DUT_MSG_ERROR,
7729 "Failed to set BeamformeeSTS");
7730 }
7731
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08007732 /* +HTC-HE support default off */
7733 if (sta_set_he_htc_supp(dut, intf, 0)) {
7734 sigma_dut_print(dut, DUT_MSG_ERROR,
7735 "Setting of +HTC-HE support failed");
7736 }
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007737
7738 /* Set device HE capabilities to testbed default
7739 * configuration. */
7740 if (sta_set_he_testbed_def(dut, intf, 1)) {
7741 sigma_dut_print(dut, DUT_MSG_DEBUG,
7742 "Failed to set HE defaults");
7743 }
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007744
7745 /* Disable VHT support in 2.4 GHz for testbed */
7746 sta_set_2g_vht_supp(dut, intf, 0);
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08007747#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08007748
7749 /* Enable WEP/TKIP with HE capability in testbed */
7750 if (sta_set_heconfig_and_wep_tkip(dut, intf, 1)) {
7751 sigma_dut_print(dut, DUT_MSG_ERROR,
7752 "Enabling HE config with WEP/TKIP failed");
7753 }
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007754 }
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007755
7756 /* Defaults in case of DUT */
7757 if (type && strcasecmp(type, "DUT") == 0) {
Arif Hussaind48fcc72018-05-01 18:34:18 -07007758 /* Enable STBC by default */
7759 wcn_sta_set_stbc(dut, intf, "1");
7760
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007761 /* set nss to 2 */
7762 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
7763 if (system(buf) != 0) {
7764 sigma_dut_print(dut, DUT_MSG_ERROR,
7765 "iwpriv %s nss 2 failed", intf);
7766 }
Arif Hussainac6c5112018-05-25 17:34:00 -07007767 dut->sta_nss = 2;
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007768
7769#ifdef NL80211_SUPPORT
Arif Hussainae239842018-05-01 18:20:05 -07007770 /* Set HE_MCS to 0-11 */
7771 if (sta_set_he_mcs(dut, intf, HE_80_MCS0_11)) {
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007772 sigma_dut_print(dut, DUT_MSG_ERROR,
7773 "Setting of MCS failed");
7774 }
7775#endif /* NL80211_SUPPORT */
7776
7777 /* Disable WEP/TKIP with HE capability in DUT */
7778 if (sta_set_heconfig_and_wep_tkip(dut, intf, 0)) {
7779 sigma_dut_print(dut, DUT_MSG_ERROR,
7780 "Enabling HE config with WEP/TKIP failed");
7781 }
7782 }
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007783 }
7784}
7785
7786
Jouni Malinenf7222712019-06-13 01:50:21 +03007787static enum sigma_cmd_result cmd_sta_reset_default(struct sigma_dut *dut,
7788 struct sigma_conn *conn,
7789 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007790{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007791 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007792 const char *band = get_param(cmd, "band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007793 const char *type;
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007794 const char *program = get_param(cmd, "program");
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05307795 const char *dev_role = get_param(cmd, "DevRole");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007796
Jouni Malinenb21f0542019-11-04 17:53:38 +02007797 if (dut->station_ifname_2g &&
7798 strcmp(dut->station_ifname_2g, intf) == 0)
7799 dut->use_5g = 0;
7800 else if (dut->station_ifname_5g &&
7801 strcmp(dut->station_ifname_5g, intf) == 0)
7802 dut->use_5g = 1;
7803
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007804 if (!program)
7805 program = get_param(cmd, "prog");
7806 dut->program = sigma_program_to_enum(program);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007807 dut->device_type = STA_unknown;
7808 type = get_param(cmd, "type");
7809 if (type && strcasecmp(type, "Testbed") == 0)
7810 dut->device_type = STA_testbed;
7811 if (type && strcasecmp(type, "DUT") == 0)
7812 dut->device_type = STA_dut;
7813
7814 if (dut->program == PROGRAM_TDLS) {
7815 /* Clear TDLS testing mode */
7816 wpa_command(intf, "SET tdls_disabled 0");
7817 wpa_command(intf, "SET tdls_testing 0");
7818 dut->no_tpk_expiration = 0;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007819 if (get_driver_type(dut) == DRIVER_WCN) {
Pradeep Reddy POTTETI8ce2a232016-10-28 12:17:32 +05307820 /* Enable the WCN driver in TDLS Explicit trigger mode
7821 */
7822 wpa_command(intf, "SET tdls_external_control 0");
7823 wpa_command(intf, "SET tdls_trigger_control 0");
7824 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007825 }
7826
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007827#ifdef MIRACAST
7828 if (dut->program == PROGRAM_WFD ||
7829 dut->program == PROGRAM_DISPLAYR2)
7830 miracast_sta_reset_default(dut, conn, cmd);
7831#endif /* MIRACAST */
7832
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007833 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007834 case DRIVER_ATHEROS:
7835 sta_reset_default_ath(dut, intf, type);
7836 break;
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007837 case DRIVER_WCN:
7838 sta_reset_default_wcn(dut, intf, type);
7839 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007840 default:
7841 break;
7842 }
7843
7844#ifdef ANDROID_NAN
7845 if (dut->program == PROGRAM_NAN)
7846 nan_cmd_sta_reset_default(dut, conn, cmd);
7847#endif /* ANDROID_NAN */
7848
Vinay Gannevaram3b9fdd32019-06-14 17:55:44 +05307849 if (dut->program == PROGRAM_LOC &&
7850 lowi_cmd_sta_reset_default(dut, conn, cmd) < 0)
7851 return ERROR_SEND_STATUS;
7852
Jouni Malinenba630452018-06-22 11:49:59 +03007853 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007854 unlink("SP/wi-fi.org/pps.xml");
7855 if (system("rm -r SP/*") != 0) {
7856 }
7857 unlink("next-client-cert.pem");
7858 unlink("next-client-key.pem");
7859 }
7860
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007861 /* For WPS program of the 60 GHz band the band type needs to be saved */
7862 if (dut->program == PROGRAM_WPS) {
7863 if (band && strcasecmp(band, "60GHz") == 0) {
7864 dut->band = WPS_BAND_60G;
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02007865 /* For 60 GHz enable WPS for WPS TCs */
7866 dut->wps_disable = 0;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007867 } else {
7868 dut->band = WPS_BAND_NON_60G;
7869 }
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02007870 } else if (dut->program == PROGRAM_60GHZ) {
7871 /* For 60 GHz MAC/PHY TCs WPS must be disabled */
7872 dut->wps_disable = 1;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007873 }
7874
Alexei Avshalom Lazar157ba062018-12-23 16:15:26 +02007875 if (is_60g_sigma_dut(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007876 const char *dev_role = get_param(cmd, "DevRole");
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007877 char buf[256];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007878
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02007879 sigma_dut_print(dut, DUT_MSG_INFO,
7880 "WPS 60 GHz program, wps_disable = %d",
7881 dut->wps_disable);
7882
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007883 if (!dev_role) {
7884 send_resp(dut, conn, SIGMA_ERROR,
7885 "errorCode,Missing DevRole argument");
7886 return 0;
7887 }
7888
7889 if (strcasecmp(dev_role, "STA") == 0)
7890 dut->dev_role = DEVROLE_STA;
7891 else if (strcasecmp(dev_role, "PCP") == 0)
7892 dut->dev_role = DEVROLE_PCP;
7893 else {
7894 send_resp(dut, conn, SIGMA_ERROR,
7895 "errorCode,Unknown DevRole");
7896 return 0;
7897 }
7898
7899 if (dut->device_type == STA_unknown) {
7900 sigma_dut_print(dut, DUT_MSG_ERROR,
7901 "Device type is not STA testbed or DUT");
7902 send_resp(dut, conn, SIGMA_ERROR,
7903 "errorCode,Unknown device type");
7904 return 0;
7905 }
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007906
7907 sigma_dut_print(dut, DUT_MSG_DEBUG,
7908 "Setting msdu_size to MAX: 7912");
7909 snprintf(buf, sizeof(buf), "ifconfig %s mtu 7912",
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007910 get_station_ifname(dut));
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007911
7912 if (system(buf) != 0) {
7913 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
7914 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007915 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007916 }
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02007917
7918 if (sta_set_force_mcs(dut, 0, 1)) {
7919 sigma_dut_print(dut, DUT_MSG_ERROR,
7920 "Failed to reset force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007921 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02007922 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007923 }
7924
7925 wpa_command(intf, "WPS_ER_STOP");
7926 wpa_command(intf, "FLUSH");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05307927 wpa_command(intf, "ERP_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007928 wpa_command(intf, "SET radio_disabled 0");
7929
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02007930 dut->wps_forced_version = 0;
7931
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007932 if (dut->wsc_fragment) {
7933 dut->wsc_fragment = 0;
7934 wpa_command(intf, "SET device_name Test client");
7935 wpa_command(intf, "SET manufacturer ");
7936 wpa_command(intf, "SET model_name ");
7937 wpa_command(intf, "SET model_number ");
7938 wpa_command(intf, "SET serial_number ");
7939 }
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02007940 if (is_60g_sigma_dut(dut) && dut->force_rsn_ie) {
7941 dut->force_rsn_ie = FORCE_RSN_IE_NONE;
7942 sta_60g_force_rsn_ie(dut, FORCE_RSN_IE_NONE);
7943 }
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007944
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007945 if (dut->tmp_mac_addr && dut->set_macaddr) {
7946 dut->tmp_mac_addr = 0;
7947 if (system(dut->set_macaddr) != 0) {
7948 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to clear "
7949 "temporary MAC address");
7950 }
7951 }
7952
7953 set_ps(intf, dut, 0);
7954
Jouni Malinenba630452018-06-22 11:49:59 +03007955 if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2 ||
7956 dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007957 wpa_command(intf, "SET interworking 1");
7958 wpa_command(intf, "SET hs20 1");
7959 }
7960
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08007961 if (dut->program == PROGRAM_HS2_R2 ||
Jouni Malinenba630452018-06-22 11:49:59 +03007962 dut->program == PROGRAM_HS2_R3 ||
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08007963 dut->program == PROGRAM_OCE) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007964 wpa_command(intf, "SET pmf 1");
7965 } else {
7966 wpa_command(intf, "SET pmf 0");
7967 }
7968
7969 hs2_clear_credentials(intf);
7970 wpa_command(intf, "SET hessid 00:00:00:00:00:00");
7971 wpa_command(intf, "SET access_network_type 15");
7972
7973 static_ip_file(0, NULL, NULL, NULL);
7974 kill_dhcp_client(dut, intf);
7975 clear_ip_addr(dut, intf);
7976
7977 dut->er_oper_performed = 0;
7978 dut->er_oper_bssid[0] = '\0';
7979
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07007980 if (dut->program == PROGRAM_LOC) {
7981 /* Disable Interworking by default */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007982 wpa_command(get_station_ifname(dut), "SET interworking 0");
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07007983 }
7984
Ashwini Patil00402582017-04-13 12:29:39 +05307985 if (dut->program == PROGRAM_MBO) {
7986 free(dut->non_pref_ch_list);
7987 dut->non_pref_ch_list = NULL;
Ashwini Patil5acd7382017-04-13 15:55:04 +05307988 free(dut->btm_query_cand_list);
7989 dut->btm_query_cand_list = NULL;
Ashwini Patilc63161e2017-04-13 16:30:23 +05307990 wpa_command(intf, "SET reject_btm_req_reason 0");
Ashwini Patila75de5a2017-04-13 16:35:05 +05307991 wpa_command(intf, "SET ignore_assoc_disallow 0");
Ashwini Patild174f2c2017-04-13 16:49:46 +05307992 wpa_command(intf, "SET gas_address3 0");
Ashwini Patil9183fdb2017-04-13 16:58:25 +05307993 wpa_command(intf, "SET roaming 1");
Ankita Bajaj1d974552018-09-18 16:56:44 +05307994 wpa_command(intf, "SET interworking 1");
Ashwini Patil00402582017-04-13 12:29:39 +05307995 }
7996
Jouni Malinen3c367e82017-06-23 17:01:47 +03007997 free(dut->rsne_override);
7998 dut->rsne_override = NULL;
7999
Jouni Malinen68143132017-09-02 02:34:08 +03008000 free(dut->sae_commit_override);
8001 dut->sae_commit_override = NULL;
Jouni Malinen4b3769d2019-10-10 16:20:29 +03008002 wpa_command(intf, "SET sae_pmkid_in_assoc 0");
Jouni Malinen11e55212019-11-22 21:46:59 +02008003 dut->sae_pwe = SAE_PWE_DEFAULT;
Jouni Malinen68143132017-09-02 02:34:08 +03008004
Jouni Malinen134fe3c2019-06-12 04:16:49 +03008005 dut->sta_associate_wait_connect = 0;
8006 dut->server_cert_hash[0] = '\0';
Jouni Malinen37d5c692019-08-19 16:56:55 +03008007 dut->server_cert_tod = 0;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03008008 dut->sta_tod_policy = 0;
8009
Jouni Malinend86e5822017-08-29 03:55:32 +03008010 dut->dpp_conf_id = -1;
Jouni Malinenb1dd21f2017-11-13 19:14:29 +02008011 free(dut->dpp_peer_uri);
8012 dut->dpp_peer_uri = NULL;
Jouni Malinen63d50412017-11-24 11:55:38 +02008013 dut->dpp_local_bootstrap = -1;
Jouni Malinen5011fb52017-12-05 21:00:15 +02008014 wpa_command(intf, "SET dpp_config_processing 2");
Jouni Malinen90776b12020-05-04 15:34:46 +03008015 wpa_command(intf, "SET dpp_mud_url ");
Jouni Malinend86e5822017-08-29 03:55:32 +03008016
Jouni Malinenfac9cad2017-10-10 18:35:55 +03008017 wpa_command(intf, "VENDOR_ELEM_REMOVE 13 *");
8018
vamsi krishnaa2799492017-12-05 14:28:01 +05308019 if (dut->program == PROGRAM_OCE) {
Ankita Bajaja2cb5672017-10-25 16:08:28 +05308020 wpa_command(intf, "SET oce 1");
vamsi krishnaa2799492017-12-05 14:28:01 +05308021 wpa_command(intf, "SET disable_fils 0");
Ankita Bajaj1bde7942018-01-09 19:15:01 +05308022 wpa_command(intf, "FILS_HLP_REQ_FLUSH");
8023 dut->fils_hlp = 0;
8024#ifdef ANDROID
8025 hlp_thread_cleanup(dut);
8026#endif /* ANDROID */
vamsi krishnaa2799492017-12-05 14:28:01 +05308027 }
Ankita Bajaja2cb5672017-10-25 16:08:28 +05308028
Vamsi Krishnaf642d6a2020-03-27 12:33:14 +05308029 if (dut->program == PROGRAM_QM)
8030 wpa_command(intf, "SET interworking 1");
8031
Jouni Malinen8179fee2019-03-28 03:19:47 +02008032 dut->akm_values = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03008033 dut->sta_ft_ds = 0;
Jouni Malinen8179fee2019-03-28 03:19:47 +02008034
Sunil Dutt076081f2018-02-05 19:45:50 +05308035#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008036 if (get_driver_type(dut) == DRIVER_WCN &&
Sunil Dutt44595082018-02-12 19:41:45 +05308037 dut->config_rsnie == 1) {
8038 dut->config_rsnie = 0;
8039 sta_config_rsnie(dut, 0);
Sunil Dutt076081f2018-02-05 19:45:50 +05308040 }
8041#endif /* NL80211_SUPPORT */
8042
Sunil Duttfebf8a82018-02-09 18:50:13 +05308043 if (dev_role && strcasecmp(dev_role, "STA-CFON") == 0) {
8044 dut->dev_role = DEVROLE_STA_CFON;
8045 return sta_cfon_reset_default(dut, conn, cmd);
8046 }
8047
Jouni Malinen439352d2018-09-13 03:42:23 +03008048 wpa_command(intf, "SET setband AUTO");
8049
Vamsi Krishnac1633d22020-05-06 18:31:21 +05308050 dut->ocvc = 0;
8051
Sunil Duttfebf8a82018-02-09 18:50:13 +05308052 if (dut->program != PROGRAM_VHT)
8053 return cmd_sta_p2p_reset(dut, conn, cmd);
8054
Priyadharshini Gowthamana7dfd492015-11-09 14:34:08 -08008055 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008056}
8057
8058
Jouni Malinenf7222712019-06-13 01:50:21 +03008059static enum sigma_cmd_result cmd_sta_get_events(struct sigma_dut *dut,
8060 struct sigma_conn *conn,
8061 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008062{
8063 const char *program = get_param(cmd, "Program");
8064
8065 if (program == NULL)
8066 return -1;
8067#ifdef ANDROID_NAN
8068 if (strcasecmp(program, "NAN") == 0)
8069 return nan_cmd_sta_get_events(dut, conn, cmd);
8070#endif /* ANDROID_NAN */
8071 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
8072 return 0;
8073}
8074
8075
Jouni Malinen82905202018-04-29 17:20:10 +03008076static int sta_exec_action_url(struct sigma_dut *dut, struct sigma_conn *conn,
8077 struct sigma_cmd *cmd)
8078{
8079 const char *url = get_param(cmd, "url");
8080 const char *method = get_param(cmd, "method");
8081 pid_t pid;
8082 int status;
8083
8084 if (!url || !method)
8085 return -1;
8086
8087 /* TODO: Add support for method,post */
8088 if (strcasecmp(method, "get") != 0) {
8089 send_resp(dut, conn, SIGMA_ERROR,
8090 "ErrorCode,Unsupported method");
8091 return 0;
8092 }
8093
8094 pid = fork();
8095 if (pid < 0) {
8096 perror("fork");
8097 return -1;
8098 }
8099
8100 if (pid == 0) {
8101 char * argv[5] = { "wget", "-O", "/dev/null",
8102 (char *) url, NULL };
8103
8104 execv("/usr/bin/wget", argv);
8105 perror("execv");
8106 exit(0);
8107 return -1;
8108 }
8109
8110 if (waitpid(pid, &status, 0) < 0) {
8111 perror("waitpid");
8112 return -1;
8113 }
8114
8115 if (WIFEXITED(status)) {
8116 const char *errmsg;
8117
8118 if (WEXITSTATUS(status) == 0)
8119 return 1;
8120 sigma_dut_print(dut, DUT_MSG_INFO, "wget exit status %d",
8121 WEXITSTATUS(status));
8122 switch (WEXITSTATUS(status)) {
8123 case 4:
8124 errmsg = "errmsg,Network failure";
8125 break;
8126 case 8:
8127 errmsg = "errmsg,Server issued an error response";
8128 break;
8129 default:
8130 errmsg = "errmsg,Unknown failure from wget";
8131 break;
8132 }
8133 send_resp(dut, conn, SIGMA_ERROR, errmsg);
8134 return 0;
8135 }
8136
8137 send_resp(dut, conn, SIGMA_ERROR, "errmsg,Unknown failure");
8138 return 0;
8139}
8140
8141
Jouni Malinenf7222712019-06-13 01:50:21 +03008142static enum sigma_cmd_result cmd_sta_exec_action(struct sigma_dut *dut,
8143 struct sigma_conn *conn,
8144 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008145{
8146 const char *program = get_param(cmd, "Prog");
8147
Jouni Malinen82905202018-04-29 17:20:10 +03008148 if (program && !get_param(cmd, "interface"))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008149 return -1;
8150#ifdef ANDROID_NAN
Jouni Malinen82905202018-04-29 17:20:10 +03008151 if (program && strcasecmp(program, "NAN") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008152 return nan_cmd_sta_exec_action(dut, conn, cmd);
8153#endif /* ANDROID_NAN */
Jouni Malinen82905202018-04-29 17:20:10 +03008154
8155 if (program && strcasecmp(program, "Loc") == 0)
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07008156 return loc_cmd_sta_exec_action(dut, conn, cmd);
Jouni Malinen82905202018-04-29 17:20:10 +03008157
8158 if (get_param(cmd, "url"))
8159 return sta_exec_action_url(dut, conn, cmd);
8160
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008161 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
8162 return 0;
8163}
8164
8165
Jouni Malinenf7222712019-06-13 01:50:21 +03008166static enum sigma_cmd_result cmd_sta_set_11n(struct sigma_dut *dut,
8167 struct sigma_conn *conn,
8168 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008169{
8170 const char *intf = get_param(cmd, "Interface");
8171 const char *val, *mcs32, *rate;
8172
8173 val = get_param(cmd, "GREENFIELD");
8174 if (val) {
8175 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
8176 /* Enable GD */
8177 send_resp(dut, conn, SIGMA_ERROR,
8178 "ErrorCode,GF not supported");
8179 return 0;
8180 }
8181 }
8182
8183 val = get_param(cmd, "SGI20");
8184 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008185 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008186 case DRIVER_ATHEROS:
8187 ath_sta_set_sgi(dut, intf, val);
8188 break;
8189 default:
8190 send_resp(dut, conn, SIGMA_ERROR,
8191 "ErrorCode,SGI20 not supported");
8192 return 0;
8193 }
8194 }
8195
8196 mcs32 = get_param(cmd, "MCS32"); /* HT Duplicate Mode Enable/Disable */
8197 rate = get_param(cmd, "MCS_FIXEDRATE"); /* Fixed MCS rate (0..31) */
8198 if (mcs32 && rate) {
8199 /* TODO */
8200 send_resp(dut, conn, SIGMA_ERROR,
8201 "ErrorCode,MCS32,MCS_FIXEDRATE not supported");
8202 return 0;
8203 } else if (mcs32 && !rate) {
8204 /* TODO */
8205 send_resp(dut, conn, SIGMA_ERROR,
8206 "ErrorCode,MCS32 not supported");
8207 return 0;
8208 } else if (!mcs32 && rate) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008209 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008210 case DRIVER_ATHEROS:
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07008211 novap_reset(dut, intf, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008212 ath_sta_set_11nrates(dut, intf, rate);
8213 break;
8214 default:
8215 send_resp(dut, conn, SIGMA_ERROR,
8216 "ErrorCode,MCS32_FIXEDRATE not supported");
8217 return 0;
8218 }
8219 }
8220
8221 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
8222}
8223
8224
Arif Hussain7b47d2d2018-05-09 10:44:02 -07008225static void cmd_set_max_he_mcs(struct sigma_dut *dut, const char *intf,
8226 int mcs_config)
8227{
8228#ifdef NL80211_SUPPORT
8229 int ret;
8230
8231 switch (mcs_config) {
8232 case HE_80_MCS0_7:
8233 case HE_80_MCS0_9:
8234 case HE_80_MCS0_11:
8235 ret = sta_set_he_mcs(dut, intf, mcs_config);
8236 if (ret) {
8237 sigma_dut_print(dut, DUT_MSG_ERROR,
8238 "cmd_set_max_he_mcs: Setting of MCS:%d failed, ret:%d",
8239 mcs_config, ret);
8240 }
8241 break;
8242 default:
8243 sigma_dut_print(dut, DUT_MSG_ERROR,
8244 "cmd_set_max_he_mcs: Invalid mcs %d",
8245 mcs_config);
8246 break;
8247 }
8248#else /* NL80211_SUPPORT */
8249 sigma_dut_print(dut, DUT_MSG_ERROR,
8250 "max HE MCS cannot be changed without NL80211_SUPPORT defined");
8251#endif /* NL80211_SUPPORT */
8252}
8253
8254
Arif Hussain480d5f42019-03-12 14:40:42 -07008255static int sta_twt_request(struct sigma_dut *dut, struct sigma_conn *conn,
8256 struct sigma_cmd *cmd)
8257{
8258#ifdef NL80211_SUPPORT
8259 struct nlattr *params;
8260 struct nlattr *attr;
8261 struct nlattr *attr1;
8262 struct nl_msg *msg;
8263 int ifindex, ret;
8264 const char *val;
8265 const char *intf = get_param(cmd, "Interface");
8266 int wake_interval_exp = 10, nominal_min_wake_dur = 255,
8267 wake_interval_mantissa = 512;
8268 int flow_type = 0, twt_trigger = 0, target_wake_time = 0,
8269 protection = 0;
8270
8271 ifindex = if_nametoindex(intf);
8272 if (ifindex == 0) {
8273 sigma_dut_print(dut, DUT_MSG_ERROR,
8274 "%s: Index for interface %s failed",
8275 __func__, intf);
8276 return -1;
8277 }
8278
8279 val = get_param(cmd, "FlowType");
8280 if (val) {
8281 flow_type = atoi(val);
8282 if (flow_type != 0 && flow_type != 1) {
8283 sigma_dut_print(dut, DUT_MSG_ERROR,
8284 "TWT: Invalid FlowType %d", flow_type);
8285 return -1;
8286 }
8287 }
8288
8289 val = get_param(cmd, "TWT_Trigger");
8290 if (val) {
8291 twt_trigger = atoi(val);
8292 if (twt_trigger != 0 && twt_trigger != 1) {
8293 sigma_dut_print(dut, DUT_MSG_ERROR,
8294 "TWT: Invalid TWT_Trigger %d",
8295 twt_trigger);
8296 return -1;
8297 }
8298 }
8299
8300 val = get_param(cmd, "Protection");
8301 if (val) {
8302 protection = atoi(val);
8303 if (protection != 0 && protection != 1) {
8304 sigma_dut_print(dut, DUT_MSG_ERROR,
8305 "TWT: Invalid Protection %d",
8306 protection);
8307 return -1;
8308 }
8309 }
8310
8311 val = get_param(cmd, "TargetWakeTime");
8312 if (val)
8313 target_wake_time = atoi(val);
8314
8315 val = get_param(cmd, "WakeIntervalMantissa");
8316 if (val)
8317 wake_interval_mantissa = atoi(val);
8318
8319 val = get_param(cmd, "WakeIntervalExp");
8320 if (val)
8321 wake_interval_exp = atoi(val);
8322
8323 val = get_param(cmd, "NominalMinWakeDur");
8324 if (val)
8325 nominal_min_wake_dur = atoi(val);
8326
8327 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8328 NL80211_CMD_VENDOR)) ||
8329 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8330 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8331 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8332 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8333 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8334 !(params = nla_nest_start(
8335 msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_TWT_SETUP)) ||
8336 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8337 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_EXP,
8338 wake_interval_exp) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008339 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_REQ_TYPE, 1) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -07008340 (twt_trigger &&
8341 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_TRIGGER)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008342 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE,
8343 flow_type) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -07008344 (protection &&
8345 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_PROTECTION)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008346 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_TIME,
8347 target_wake_time) ||
8348 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_DURATION,
8349 nominal_min_wake_dur) ||
8350 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_MANTISSA,
8351 wake_interval_mantissa)) {
8352 sigma_dut_print(dut, DUT_MSG_ERROR,
8353 "%s: err in adding vendor_cmd and vendor_data",
8354 __func__);
8355 nlmsg_free(msg);
8356 return -1;
8357 }
8358 nla_nest_end(msg, attr1);
8359 nla_nest_end(msg, params);
8360 nla_nest_end(msg, attr);
8361
8362 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8363 if (ret) {
8364 sigma_dut_print(dut, DUT_MSG_ERROR,
8365 "%s: err in send_and_recv_msgs, ret=%d",
8366 __func__, ret);
8367 }
8368
8369 return ret;
8370#else /* NL80211_SUPPORT */
8371 sigma_dut_print(dut, DUT_MSG_ERROR,
8372 "TWT request cannot be done without NL80211_SUPPORT defined");
8373 return -1;
8374#endif /* NL80211_SUPPORT */
8375}
8376
8377
8378static int sta_twt_teardown(struct sigma_dut *dut, struct sigma_conn *conn,
8379 struct sigma_cmd *cmd)
8380{
8381 #ifdef NL80211_SUPPORT
8382 struct nlattr *params;
8383 struct nlattr *attr;
8384 struct nlattr *attr1;
8385 int ifindex, ret;
8386 struct nl_msg *msg;
8387 const char *intf = get_param(cmd, "Interface");
8388
8389 ifindex = if_nametoindex(intf);
8390 if (ifindex == 0) {
8391 sigma_dut_print(dut, DUT_MSG_ERROR,
8392 "%s: Index for interface %s failed",
8393 __func__, intf);
8394 return -1;
8395 }
8396
8397 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8398 NL80211_CMD_VENDOR)) ||
8399 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8400 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8401 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8402 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8403 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8404 !(params = nla_nest_start(
8405 msg,
8406 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_TWT_TERMINATE)) ||
8407 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8408 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE, 0)) {
8409 sigma_dut_print(dut, DUT_MSG_ERROR,
8410 "%s: err in adding vendor_cmd and vendor_data",
8411 __func__);
8412 nlmsg_free(msg);
8413 return -1;
8414 }
8415 nla_nest_end(msg, attr1);
8416 nla_nest_end(msg, params);
8417 nla_nest_end(msg, attr);
8418
8419 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8420 if (ret) {
8421 sigma_dut_print(dut, DUT_MSG_ERROR,
8422 "%s: err in send_and_recv_msgs, ret=%d",
8423 __func__, ret);
8424 }
8425
8426 return ret;
8427#else /* NL80211_SUPPORT */
8428 sigma_dut_print(dut, DUT_MSG_ERROR,
8429 "TWT teardown cannot be done without NL80211_SUPPORT defined");
8430 return -1;
8431#endif /* NL80211_SUPPORT */
8432}
8433
8434
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -08008435static int sta_transmit_omi(struct sigma_dut *dut, struct sigma_conn *conn,
8436 struct sigma_cmd *cmd)
8437{
8438#ifdef NL80211_SUPPORT
8439 struct nlattr *params;
8440 struct nlattr *attr;
8441 struct nlattr *attr1;
8442 struct nl_msg *msg;
8443 int ifindex, ret;
8444 const char *val;
8445 const char *intf = get_param(cmd, "Interface");
8446 uint8_t rx_nss = 0xFF, ch_bw = 0xFF, tx_nsts = 0xFF, ulmu_dis = 0,
8447 ulmu_data_dis = 0;
8448
8449 ifindex = if_nametoindex(intf);
8450 if (ifindex == 0) {
8451 sigma_dut_print(dut, DUT_MSG_ERROR,
8452 "%s: Index for interface %s failed",
8453 __func__, intf);
8454 return -1;
8455 }
8456 val = get_param(cmd, "OMCtrl_RxNSS");
8457 if (val)
8458 rx_nss = atoi(val);
8459
8460 val = get_param(cmd, "OMCtrl_ChnlWidth");
8461 if (val)
8462 ch_bw = atoi(val);
8463
8464 val = get_param(cmd, "OMCtrl_ULMUDisable");
8465 if (val)
8466 ulmu_dis = atoi(val);
8467
8468 val = get_param(cmd, "OMCtrl_TxNSTS");
8469 if (val)
8470 tx_nsts = atoi(val);
8471
8472 val = get_param(cmd, "OMCtrl_ULMUDataDisable");
8473 if (val)
8474 ulmu_data_dis = atoi(val);
8475
8476 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8477 NL80211_CMD_VENDOR)) ||
8478 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8479 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8480 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8481 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8482 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8483 !(params = nla_nest_start(
8484 msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OMI_TX)) ||
8485 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8486 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_RX_NSS, rx_nss) ||
8487 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_CH_BW, ch_bw) ||
8488 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_TX_NSTS, tx_nsts) ||
8489 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DATA_DISABLE,
8490 ulmu_data_dis) ||
8491 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DISABLE,
8492 ulmu_dis)) {
8493 sigma_dut_print(dut, DUT_MSG_ERROR,
8494 "%s: err in adding vendor_cmd and vendor_data",
8495 __func__);
8496 nlmsg_free(msg);
8497 return -1;
8498 }
8499 nla_nest_end(msg, attr1);
8500 nla_nest_end(msg, params);
8501 nla_nest_end(msg, attr);
8502
8503 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8504 if (ret) {
8505 sigma_dut_print(dut, DUT_MSG_ERROR,
8506 "%s: err in send_and_recv_msgs, ret=%d",
8507 __func__, ret);
8508 }
8509
8510 return ret;
8511#else /* NL80211_SUPPORT */
8512 sigma_dut_print(dut, DUT_MSG_ERROR,
8513 "OMI TX cannot be processed without NL80211_SUPPORT defined");
8514 return -1;
8515#endif /* NL80211_SUPPORT */
8516}
8517
8518
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008519static int cmd_sta_set_wireless_vht(struct sigma_dut *dut,
8520 struct sigma_conn *conn,
8521 struct sigma_cmd *cmd)
8522{
8523 const char *intf = get_param(cmd, "Interface");
8524 const char *val;
Arif Hussaina37e9552018-06-20 17:05:59 -07008525 const char *program;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008526 int tkip = -1;
8527 int wep = -1;
8528
Arif Hussaina37e9552018-06-20 17:05:59 -07008529 program = get_param(cmd, "Program");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008530 val = get_param(cmd, "SGI80");
8531 if (val) {
8532 int sgi80;
8533
8534 sgi80 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008535 run_iwpriv(dut, intf, "shortgi %d", sgi80);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008536 }
8537
8538 val = get_param(cmd, "TxBF");
8539 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008540 switch (get_driver_type(dut)) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008541 case DRIVER_WCN:
8542 if (sta_set_tx_beamformee(dut, intf, 1)) {
8543 send_resp(dut, conn, SIGMA_ERROR,
8544 "ErrorCode,Failed to set TX beamformee enable");
8545 return 0;
8546 }
8547 break;
8548 case DRIVER_ATHEROS:
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008549 if (run_iwpriv(dut, intf, "vhtsubfee 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008550 send_resp(dut, conn, SIGMA_ERROR,
8551 "ErrorCode,Setting vhtsubfee failed");
8552 return 0;
8553 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008554 if (run_iwpriv(dut, intf, "vhtsubfer 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008555 send_resp(dut, conn, SIGMA_ERROR,
8556 "ErrorCode,Setting vhtsubfer failed");
8557 return 0;
8558 }
8559 break;
8560 default:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008561 sigma_dut_print(dut, DUT_MSG_ERROR,
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008562 "Unsupported driver type");
8563 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008564 }
8565 }
8566
8567 val = get_param(cmd, "MU_TxBF");
8568 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008569 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008570 case DRIVER_ATHEROS:
8571 ath_sta_set_txsp_stream(dut, intf, "1SS");
8572 ath_sta_set_rxsp_stream(dut, intf, "1SS");
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008573 run_iwpriv(dut, intf, "vhtmubfee 1");
8574 run_iwpriv(dut, intf, "vhtmubfer 1");
Sunil Duttae9e5d12018-06-29 11:50:47 +05308575 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008576 case DRIVER_WCN:
8577 if (wcn_sta_set_sp_stream(dut, intf, "1SS") < 0) {
8578 send_resp(dut, conn, SIGMA_ERROR,
8579 "ErrorCode,Failed to set RX/TXSP_STREAM");
8580 return 0;
8581 }
Sunil Duttae9e5d12018-06-29 11:50:47 +05308582 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008583 default:
8584 sigma_dut_print(dut, DUT_MSG_ERROR,
8585 "Setting SP_STREAM not supported");
8586 break;
8587 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008588 }
8589
8590 val = get_param(cmd, "LDPC");
8591 if (val) {
8592 int ldpc;
8593
8594 ldpc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008595 run_iwpriv(dut, intf, "ldpc %d", ldpc);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008596 }
8597
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08008598 val = get_param(cmd, "BCC");
8599 if (val) {
8600 int bcc;
8601
8602 bcc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8603 /* use LDPC iwpriv itself to set bcc coding, bcc coding
8604 * is mutually exclusive to bcc */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008605 run_iwpriv(dut, intf, "ldpc %d", !bcc);
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08008606 }
8607
Arif Hussain7b47d2d2018-05-09 10:44:02 -07008608 val = get_param(cmd, "MaxHE-MCS_1SS_RxMapLTE80");
8609 if (val && dut->sta_nss == 1)
8610 cmd_set_max_he_mcs(dut, intf, atoi(val));
8611
8612 val = get_param(cmd, "MaxHE-MCS_2SS_RxMapLTE80");
8613 if (val && dut->sta_nss == 2)
8614 cmd_set_max_he_mcs(dut, intf, atoi(val));
8615
Arif Hussainac6c5112018-05-25 17:34:00 -07008616 val = get_param(cmd, "MCS_FixedRate");
8617 if (val) {
8618#ifdef NL80211_SUPPORT
8619 int mcs, ratecode = 0;
8620 enum he_mcs_config mcs_config;
8621 int ret;
Jouni Malinenb9b671d2019-04-26 13:23:17 +03008622 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07008623
8624 ratecode = (0x07 & dut->sta_nss) << 5;
8625 mcs = atoi(val);
8626 /* Add the MCS to the ratecode */
8627 if (mcs >= 0 && mcs <= 11) {
8628 ratecode += mcs;
8629 if (dut->device_type == STA_testbed &&
8630 mcs > 7 && mcs <= 11) {
8631 if (mcs <= 9)
8632 mcs_config = HE_80_MCS0_9;
8633 else
8634 mcs_config = HE_80_MCS0_11;
8635 ret = sta_set_he_mcs(dut, intf, mcs_config);
8636 if (ret) {
8637 sigma_dut_print(dut, DUT_MSG_ERROR,
8638 "MCS_FixedRate: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
8639 mcs, mcs_config, ret);
8640 }
8641 }
8642 snprintf(buf, sizeof(buf),
8643 "iwpriv %s set_11ax_rate 0x%03x",
8644 intf, ratecode);
8645 if (system(buf) != 0) {
8646 sigma_dut_print(dut, DUT_MSG_ERROR,
8647 "MCS_FixedRate: iwpriv setting of 11ax rates 0x%03x failed",
8648 ratecode);
8649 }
8650 } else {
8651 sigma_dut_print(dut, DUT_MSG_ERROR,
8652 "MCS_FixedRate: HE MCS %d not supported",
8653 mcs);
8654 }
8655#else /* NL80211_SUPPORT */
8656 sigma_dut_print(dut, DUT_MSG_ERROR,
8657 "MCS_FixedRate cannot be changed without NL80211_SUPPORT defined");
8658#endif /* NL80211_SUPPORT */
8659 }
8660
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008661 val = get_param(cmd, "opt_md_notif_ie");
8662 if (val) {
8663 char *result = NULL;
8664 char delim[] = ";";
8665 char token[30];
8666 int value, config_val = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308667 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008668
Peng Xub8fc5cc2017-05-10 17:27:28 -07008669 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308670 result = strtok_r(token, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008671
8672 /* Extract the NSS information */
8673 if (result) {
8674 value = atoi(result);
8675 switch (value) {
8676 case 1:
8677 config_val = 1;
8678 break;
8679 case 2:
8680 config_val = 3;
8681 break;
8682 case 3:
8683 config_val = 7;
8684 break;
8685 case 4:
8686 config_val = 15;
8687 break;
8688 default:
8689 config_val = 3;
8690 break;
8691 }
8692
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008693 run_iwpriv(dut, intf, "rxchainmask %d", config_val);
8694 run_iwpriv(dut, intf, "txchainmask %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008695
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008696 }
8697
8698 /* Extract the channel width information */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308699 result = strtok_r(NULL, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008700 if (result) {
8701 value = atoi(result);
8702 switch (value) {
8703 case 20:
8704 config_val = 0;
8705 break;
8706 case 40:
8707 config_val = 1;
8708 break;
8709 case 80:
8710 config_val = 2;
8711 break;
8712 case 160:
8713 config_val = 3;
8714 break;
8715 default:
8716 config_val = 2;
8717 break;
8718 }
8719
8720 dut->chwidth = config_val;
8721
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008722 run_iwpriv(dut, intf, "chwidth %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008723 }
8724
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008725 run_iwpriv(dut, intf, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008726 }
8727
8728 val = get_param(cmd, "nss_mcs_cap");
8729 if (val) {
8730 int nss, mcs;
8731 char token[20];
8732 char *result = NULL;
8733 unsigned int vht_mcsmap = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308734 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008735
Peng Xub8fc5cc2017-05-10 17:27:28 -07008736 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308737 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308738 if (!result) {
8739 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008740 "NSS not specified");
8741 send_resp(dut, conn, SIGMA_ERROR,
8742 "errorCode,NSS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308743 return 0;
8744 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008745 nss = atoi(result);
8746
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008747 run_iwpriv(dut, intf, "nss %d", nss);
Arif Hussainac6c5112018-05-25 17:34:00 -07008748 dut->sta_nss = nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008749
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308750 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008751 if (result == NULL) {
8752 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008753 "MCS not specified");
8754 send_resp(dut, conn, SIGMA_ERROR,
8755 "errorCode,MCS not specified");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008756 return 0;
8757 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308758 result = strtok_r(result, "-", &saveptr);
8759 result = strtok_r(NULL, "-", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308760 if (!result) {
8761 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008762 "MCS not specified");
8763 send_resp(dut, conn, SIGMA_ERROR,
8764 "errorCode,MCS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308765 return 0;
8766 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008767 mcs = atoi(result);
8768
Arif Hussaina37e9552018-06-20 17:05:59 -07008769 if (program && strcasecmp(program, "HE") == 0) {
8770#ifdef NL80211_SUPPORT
8771 enum he_mcs_config mcs_config;
8772 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008773
Arif Hussaina37e9552018-06-20 17:05:59 -07008774 if (mcs >= 0 && mcs <= 7) {
8775 mcs_config = HE_80_MCS0_7;
8776 } else if (mcs > 7 && mcs <= 9) {
8777 mcs_config = HE_80_MCS0_9;
8778 } else if (mcs > 9 && mcs <= 11) {
8779 mcs_config = HE_80_MCS0_11;
8780 } else {
8781 sigma_dut_print(dut, DUT_MSG_ERROR,
8782 "nss_mcs_cap: HE: Invalid mcs: %d",
8783 mcs);
8784 send_resp(dut, conn, SIGMA_ERROR,
8785 "errorCode,Invalid MCS");
8786 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008787 }
Arif Hussaina37e9552018-06-20 17:05:59 -07008788
8789 ret = sta_set_he_mcs(dut, intf, mcs_config);
8790 if (ret) {
8791 sigma_dut_print(dut, DUT_MSG_ERROR,
8792 "nss_mcs_cap: HE: Setting of MCS failed, mcs_config: %d, ret: %d",
8793 mcs_config, ret);
8794 send_resp(dut, conn, SIGMA_ERROR,
8795 "errorCode,Failed to set MCS");
8796 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008797 }
Arif Hussaina37e9552018-06-20 17:05:59 -07008798#else /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008799 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008800 "nss_mcs_cap: HE: MCS cannot be changed without NL80211_SUPPORT defined");
8801#endif /* NL80211_SUPPORT */
8802 } else {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008803 run_iwpriv(dut, intf, "vhtmcs %d", mcs);
Arif Hussaina37e9552018-06-20 17:05:59 -07008804
8805 switch (nss) {
8806 case 1:
8807 switch (mcs) {
8808 case 7:
8809 vht_mcsmap = 0xfffc;
8810 break;
8811 case 8:
8812 vht_mcsmap = 0xfffd;
8813 break;
8814 case 9:
8815 vht_mcsmap = 0xfffe;
8816 break;
8817 default:
8818 vht_mcsmap = 0xfffe;
8819 break;
8820 }
8821 break;
8822 case 2:
8823 switch (mcs) {
8824 case 7:
8825 vht_mcsmap = 0xfff0;
8826 break;
8827 case 8:
8828 vht_mcsmap = 0xfff5;
8829 break;
8830 case 9:
8831 vht_mcsmap = 0xfffa;
8832 break;
8833 default:
8834 vht_mcsmap = 0xfffa;
8835 break;
8836 }
8837 break;
8838 case 3:
8839 switch (mcs) {
8840 case 7:
8841 vht_mcsmap = 0xffc0;
8842 break;
8843 case 8:
8844 vht_mcsmap = 0xffd5;
8845 break;
8846 case 9:
8847 vht_mcsmap = 0xffea;
8848 break;
8849 default:
8850 vht_mcsmap = 0xffea;
8851 break;
8852 }
8853 break;
8854 default:
8855 vht_mcsmap = 0xffea;
8856 break;
8857 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008858 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008859 }
8860 }
8861
8862 /* UNSUPPORTED: val = get_param(cmd, "Tx_lgi_rate"); */
8863
8864 val = get_param(cmd, "Vht_tkip");
8865 if (val)
8866 tkip = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8867
8868 val = get_param(cmd, "Vht_wep");
8869 if (val)
8870 wep = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8871
8872 if (tkip != -1 || wep != -1) {
8873 if ((tkip == 1 && wep != 0) || (wep == 1 && tkip != 0)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008874 run_iwpriv(dut, intf, "htweptkip 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008875 } else if ((tkip == 0 && wep != 1) || (wep == 0 && tkip != 1)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008876 run_iwpriv(dut, intf, "htweptkip 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008877 } else {
8878 sigma_dut_print(dut, DUT_MSG_ERROR,
8879 "ErrorCode,mixed mode of VHT TKIP/WEP not supported");
8880 return 0;
8881 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008882 }
8883
Arif Hussain55f00da2018-07-03 08:28:26 -07008884 val = get_param(cmd, "txBandwidth");
8885 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008886 switch (get_driver_type(dut)) {
Arif Hussain55f00da2018-07-03 08:28:26 -07008887 case DRIVER_WCN:
8888 if (wcn_sta_set_width(dut, intf, val) < 0) {
8889 send_resp(dut, conn, SIGMA_ERROR,
8890 "ErrorCode,Failed to set txBandwidth");
8891 return 0;
8892 }
8893 break;
8894 case DRIVER_ATHEROS:
8895 if (ath_set_width(dut, conn, intf, val) < 0) {
8896 send_resp(dut, conn, SIGMA_ERROR,
8897 "ErrorCode,Failed to set txBandwidth");
8898 return 0;
8899 }
8900 break;
8901 default:
8902 sigma_dut_print(dut, DUT_MSG_ERROR,
8903 "Setting txBandwidth not supported");
8904 break;
8905 }
8906 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008907
Arif Hussain9765f7d2018-07-03 08:28:26 -07008908 val = get_param(cmd, "BeamformeeSTS");
8909 if (val) {
Kiran Kumar Lokerebc89d432018-07-10 12:20:13 -07008910 if (sta_set_tx_beamformee(dut, intf, 1)) {
8911 send_resp(dut, conn, SIGMA_ERROR,
8912 "ErrorCode,Failed to set TX beamformee enable");
8913 return 0;
8914 }
8915
Arif Hussain9765f7d2018-07-03 08:28:26 -07008916 if (sta_set_beamformee_sts(dut, intf, atoi(val))) {
8917 send_resp(dut, conn, SIGMA_ERROR,
8918 "ErrorCode,Failed to set BeamformeeSTS");
8919 return 0;
8920 }
8921 }
8922
Arif Hussain68d23f52018-07-11 13:39:08 -07008923 val = get_param(cmd, "Trig_MAC_Padding_Dur");
8924 if (val) {
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07008925#ifdef NL80211_SUPPORT
8926 enum qca_wlan_he_mac_padding_dur set_val;
8927
8928 switch (atoi(val)) {
8929 case 16:
8930 set_val = QCA_WLAN_HE_16US_OF_PROCESS_TIME;
8931 break;
8932 case 8:
8933 set_val = QCA_WLAN_HE_8US_OF_PROCESS_TIME;
8934 break;
8935 default:
8936 set_val = QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME;
8937 break;
8938 }
8939 if (sta_set_mac_padding_duration(dut, intf, set_val)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07008940 send_resp(dut, conn, SIGMA_ERROR,
8941 "ErrorCode,Failed to set MAC padding duration");
8942 return 0;
8943 }
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07008944#else /* NL80211_SUPPORT */
8945 sigma_dut_print(dut, DUT_MSG_ERROR,
8946 "MAC padding duration cannot be changed without NL80211_SUPPORT defined");
8947#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07008948 }
8949
Arif Hussain480d5f42019-03-12 14:40:42 -07008950 val = get_param(cmd, "TWT_ReqSupport");
8951 if (val) {
8952 int set_val;
8953
8954 if (strcasecmp(val, "Enable") == 0) {
8955 set_val = 1;
8956 } else if (strcasecmp(val, "Disable") == 0) {
8957 set_val = 0;
8958 } else {
8959 send_resp(dut, conn, SIGMA_ERROR,
8960 "ErrorCode,Invalid TWT_ReqSupport");
8961 return STATUS_SENT;
8962 }
8963
8964 if (sta_set_twt_req_support(dut, intf, set_val)) {
8965 sigma_dut_print(dut, DUT_MSG_ERROR,
8966 "Failed to set TWT req support %d",
8967 set_val);
8968 send_resp(dut, conn, SIGMA_ERROR,
8969 "ErrorCode,Failed to set TWT_ReqSupport");
8970 return STATUS_SENT;
8971 }
8972 }
8973
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07008974 val = get_param(cmd, "MU_EDCA");
8975 if (val && (strcasecmp(val, "Override") == 0)) {
8976 if (sta_set_mu_edca_override(dut, intf, 1)) {
8977 send_resp(dut, conn, SIGMA_ERROR,
8978 "ErrorCode,Failed to set MU EDCA override");
8979 return 0;
8980 }
8981 }
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07008982
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07008983 val = get_param(cmd, "OMControl");
8984 if (val) {
8985 int set_val = 1;
8986
8987 if (strcasecmp(val, "Enable") == 0)
8988 set_val = 1;
8989 else if (strcasecmp(val, "Disable") == 0)
8990 set_val = 0;
8991
8992 if (sta_set_om_ctrl_supp(dut, intf, set_val)) {
8993 send_resp(dut, conn, SIGMA_ERROR,
8994 "ErrorCode,Failed to set OM ctrl supp");
8995 return 0;
8996 }
8997 }
8998
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07008999 val = get_param(cmd, "ADDBAResp_BufSize");
9000 if (val) {
9001 int buf_size;
9002
9003 if (strcasecmp(val, "gt64") == 0)
9004 buf_size = 256;
9005 else
9006 buf_size = 64;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009007 if (get_driver_type(dut) == DRIVER_WCN &&
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009008 sta_set_addba_buf_size(dut, intf, buf_size)) {
9009 send_resp(dut, conn, SIGMA_ERROR,
9010 "ErrorCode,set addbaresp_buff_size failed");
9011 return 0;
9012 }
9013 }
9014
9015 val = get_param(cmd, "ADDBAReq_BufSize");
9016 if (val) {
9017 int buf_size;
9018
9019 if (strcasecmp(val, "gt64") == 0)
9020 buf_size = 256;
9021 else
9022 buf_size = 64;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009023 if (get_driver_type(dut) == DRIVER_WCN &&
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009024 sta_set_addba_buf_size(dut, intf, buf_size)) {
9025 send_resp(dut, conn, SIGMA_ERROR,
9026 "ErrorCode,set addbareq_buff_size failed");
9027 return 0;
9028 }
9029 }
9030
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009031 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
9032}
9033
9034
9035static int sta_set_wireless_60g(struct sigma_dut *dut,
9036 struct sigma_conn *conn,
9037 struct sigma_cmd *cmd)
9038{
9039 const char *dev_role = get_param(cmd, "DevRole");
9040
9041 if (!dev_role) {
9042 send_resp(dut, conn, SIGMA_INVALID,
9043 "ErrorCode,DevRole not specified");
9044 return 0;
9045 }
9046
9047 if (strcasecmp(dev_role, "PCP") == 0)
9048 return sta_set_60g_pcp(dut, conn, cmd);
9049 if (strcasecmp(dev_role, "STA") == 0)
9050 return sta_set_60g_sta(dut, conn, cmd);
9051 send_resp(dut, conn, SIGMA_INVALID,
9052 "ErrorCode,DevRole not supported");
9053 return 0;
9054}
9055
9056
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05309057static int sta_set_wireless_oce(struct sigma_dut *dut, struct sigma_conn *conn,
9058 struct sigma_cmd *cmd)
9059{
9060 int status;
9061 const char *intf = get_param(cmd, "Interface");
9062 const char *val = get_param(cmd, "DevRole");
9063
9064 if (val && strcasecmp(val, "STA-CFON") == 0) {
9065 status = sta_cfon_set_wireless(dut, conn, cmd);
9066 if (status)
9067 return status;
9068 }
9069 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
9070}
9071
9072
Vamsi Krishnac1633d22020-05-06 18:31:21 +05309073static int sta_set_wireless_wpa3(struct sigma_dut *dut, struct sigma_conn *conn,
9074 struct sigma_cmd *cmd)
9075{
9076 const char *intf = get_param(cmd, "Interface");
9077 const char *val;
9078
9079 val = get_param(cmd, "ocvc");
9080 if (val)
9081 dut->ocvc = atoi(val);
9082
9083 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
9084}
9085
9086
Jouni Malinenf7222712019-06-13 01:50:21 +03009087static enum sigma_cmd_result cmd_sta_set_wireless(struct sigma_dut *dut,
9088 struct sigma_conn *conn,
9089 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009090{
9091 const char *val;
9092
9093 val = get_param(cmd, "Program");
9094 if (val) {
9095 if (strcasecmp(val, "11n") == 0)
9096 return cmd_sta_set_11n(dut, conn, cmd);
Amarnath Hullur Subramanyam4f860292018-01-31 03:49:35 -08009097 if (strcasecmp(val, "VHT") == 0 || strcasecmp(val, "HE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009098 return cmd_sta_set_wireless_vht(dut, conn, cmd);
9099 if (strcasecmp(val, "60ghz") == 0)
9100 return sta_set_wireless_60g(dut, conn, cmd);
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05309101 if (strcasecmp(val, "OCE") == 0)
9102 return sta_set_wireless_oce(dut, conn, cmd);
Alexei Avshalom Lazar66bb9972018-12-18 16:01:43 +02009103 /* sta_set_wireless in WPS program is only used for 60G */
9104 if (is_60g_sigma_dut(dut))
9105 return sta_set_wireless_60g(dut, conn, cmd);
Vamsi Krishnac1633d22020-05-06 18:31:21 +05309106 if (strcasecmp(val, "WPA3") == 0)
9107 return sta_set_wireless_wpa3(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009108 send_resp(dut, conn, SIGMA_ERROR,
9109 "ErrorCode,Program value not supported");
9110 } else {
9111 send_resp(dut, conn, SIGMA_ERROR,
9112 "ErrorCode,Program argument not available");
9113 }
9114
9115 return 0;
9116}
9117
9118
9119static void ath_sta_inject_frame(struct sigma_dut *dut, const char *intf,
9120 int tid)
9121{
9122 char buf[100];
9123 int tid_to_dscp [] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 };
9124
Pradeep Reddy POTTETId31d1322016-10-13 17:22:03 +05309125 if (tid < 0 ||
9126 tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) {
9127 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid);
9128 return;
9129 }
9130
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009131 /*
9132 * Two ways to ensure that addba request with a
9133 * non zero TID could be sent out. EV 117296
9134 */
9135 snprintf(buf, sizeof(buf),
9136 "ping -c 8 -Q %d `arp -a | grep wlan0 | awk '{print $2}' | tr -d '()'`",
9137 tid);
9138 if (system(buf) != 0) {
9139 sigma_dut_print(dut, DUT_MSG_ERROR,
9140 "Ping did not send out");
9141 }
9142
9143 snprintf(buf, sizeof(buf),
9144 "iwconfig %s | grep Access | awk '{print $6}' > %s",
9145 intf, VI_QOS_TMP_FILE);
9146 if (system(buf) != 0)
9147 return;
9148
9149 snprintf(buf, sizeof(buf),
9150 "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s",
9151 intf, VI_QOS_TMP_FILE);
9152 if (system(buf) != 0)
9153 sigma_dut_print(dut, DUT_MSG_ERROR, "HWaddr matching failed");
9154
9155 snprintf(buf,sizeof(buf), "sed -n '3,$p' %s >> %s",
9156 VI_QOS_REFFILE, VI_QOS_TMP_FILE);
9157 if (system(buf) != 0) {
9158 sigma_dut_print(dut, DUT_MSG_ERROR,
9159 "VI_QOS_TEMP_FILE generation error failed");
9160 }
9161 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
9162 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
9163 if (system(buf) != 0) {
9164 sigma_dut_print(dut, DUT_MSG_ERROR,
9165 "VI_QOS_FILE generation failed");
9166 }
9167
9168 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
9169 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
9170 if (system(buf) != 0) {
9171 sigma_dut_print(dut, DUT_MSG_ERROR,
9172 "VI_QOS_FILE generation failed");
9173 }
9174
9175 snprintf(buf, sizeof(buf), "ethinject %s %s", intf, VI_QOS_FILE);
9176 if (system(buf) != 0) {
9177 }
9178}
9179
9180
9181static int ath_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
9182 struct sigma_cmd *cmd)
9183{
9184 const char *intf = get_param(cmd, "Interface");
9185 const char *val;
9186 int tid = 0;
9187 char buf[100];
9188
9189 val = get_param(cmd, "TID");
9190 if (val) {
9191 tid = atoi(val);
9192 if (tid)
9193 ath_sta_inject_frame(dut, intf, tid);
9194 }
9195
9196 /* Command sequence for ADDBA request on Peregrine based devices */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009197 run_iwpriv(dut, intf, "setaddbaoper 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009198
9199 snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4", intf, tid);
9200 if (system(buf) != 0) {
9201 sigma_dut_print(dut, DUT_MSG_ERROR,
9202 "wifitool senddelba failed");
9203 }
9204
9205 snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64", intf, tid);
9206 if (system(buf) != 0) {
9207 sigma_dut_print(dut, DUT_MSG_ERROR,
9208 "wifitool sendaddba failed");
9209 }
9210
9211 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
9212
9213 return 1;
9214}
9215
9216
Lior David9981b512017-01-20 13:16:40 +02009217#ifdef __linux__
9218
9219static int wil6210_send_addba(struct sigma_dut *dut, const char *dest_mac,
9220 int agg_size)
9221{
9222 char dir[128], buf[128];
9223 FILE *f;
9224 regex_t re;
9225 regmatch_t m[2];
Jouni Malinen3aa72862019-05-29 23:14:51 +03009226 int rc, ret = -1, vring_id, found, res;
Lior David9981b512017-01-20 13:16:40 +02009227
9228 if (wil6210_get_debugfs_dir(dut, dir, sizeof(dir))) {
9229 sigma_dut_print(dut, DUT_MSG_ERROR,
9230 "failed to get wil6210 debugfs dir");
9231 return -1;
9232 }
9233
Jouni Malinen3aa72862019-05-29 23:14:51 +03009234 res = snprintf(buf, sizeof(buf), "%s/vrings", dir);
9235 if (res < 0 || res >= sizeof(buf))
9236 return -1;
Lior David9981b512017-01-20 13:16:40 +02009237 f = fopen(buf, "r");
9238 if (!f) {
9239 sigma_dut_print(dut, DUT_MSG_ERROR, "failed to open: %s", buf);
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009240 /* newer wil6210 driver renamed file to "rings" */
Jouni Malinen3aa72862019-05-29 23:14:51 +03009241 res = snprintf(buf, sizeof(buf), "%s/rings", dir);
9242 if (res < 0 || res >= sizeof(buf))
9243 return -1;
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009244 f = fopen(buf, "r");
9245 if (!f) {
9246 sigma_dut_print(dut, DUT_MSG_ERROR,
9247 "failed to open: %s", buf);
9248 return -1;
9249 }
Lior David9981b512017-01-20 13:16:40 +02009250 }
9251
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009252 /* can be either VRING tx... or RING... */
9253 if (regcomp(&re, "RING tx_[ \t]*([0-9]+)", REG_EXTENDED)) {
Lior David9981b512017-01-20 13:16:40 +02009254 sigma_dut_print(dut, DUT_MSG_ERROR, "regcomp failed");
9255 goto out;
9256 }
9257
9258 /* find TX VRING for the mac address */
9259 found = 0;
9260 while (fgets(buf, sizeof(buf), f)) {
9261 if (strcasestr(buf, dest_mac)) {
9262 found = 1;
9263 break;
9264 }
9265 }
9266
9267 if (!found) {
9268 sigma_dut_print(dut, DUT_MSG_ERROR,
9269 "no TX VRING for %s", dest_mac);
9270 goto out;
9271 }
9272
9273 /* extract VRING ID, "VRING tx_<id> = {" */
9274 if (!fgets(buf, sizeof(buf), f)) {
9275 sigma_dut_print(dut, DUT_MSG_ERROR,
9276 "no VRING start line for %s", dest_mac);
9277 goto out;
9278 }
9279
9280 rc = regexec(&re, buf, 2, m, 0);
9281 regfree(&re);
9282 if (rc || m[1].rm_so < 0) {
9283 sigma_dut_print(dut, DUT_MSG_ERROR,
9284 "no VRING TX ID for %s", dest_mac);
9285 goto out;
9286 }
9287 buf[m[1].rm_eo] = 0;
9288 vring_id = atoi(&buf[m[1].rm_so]);
9289
9290 /* send the addba command */
9291 fclose(f);
Jouni Malinen3aa72862019-05-29 23:14:51 +03009292 res = snprintf(buf, sizeof(buf), "%s/back", dir);
9293 if (res < 0 || res >= sizeof(buf))
9294 return -1;
Lior David9981b512017-01-20 13:16:40 +02009295 f = fopen(buf, "w");
9296 if (!f) {
9297 sigma_dut_print(dut, DUT_MSG_ERROR,
9298 "failed to open: %s", buf);
9299 return -1;
9300 }
9301
9302 fprintf(f, "add %d %d\n", vring_id, agg_size);
9303
9304 ret = 0;
9305
9306out:
9307 fclose(f);
9308
9309 return ret;
9310}
9311
9312
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009313int send_addba_60g(struct sigma_dut *dut, struct sigma_conn *conn,
9314 struct sigma_cmd *cmd, const char *mac_param)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009315{
9316 const char *val;
9317 int tid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009318
9319 val = get_param(cmd, "TID");
9320 if (val) {
9321 tid = atoi(val);
9322 if (tid != 0) {
9323 sigma_dut_print(dut, DUT_MSG_ERROR,
9324 "Ignore TID %d for send_addba use TID 0 for 60g since only 0 required on TX",
9325 tid);
9326 }
9327 }
9328
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009329 val = get_param(cmd, mac_param);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009330 if (!val) {
9331 sigma_dut_print(dut, DUT_MSG_ERROR,
9332 "Currently not supporting addba for 60G without Dest_mac");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02009333 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009334 }
9335
Lior David9981b512017-01-20 13:16:40 +02009336 if (wil6210_send_addba(dut, val, dut->back_rcv_buf))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009337 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009338
9339 return 1;
9340}
9341
Lior David9981b512017-01-20 13:16:40 +02009342#endif /* __linux__ */
9343
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009344
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009345static int wcn_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
9346 struct sigma_cmd *cmd)
9347{
9348#ifdef NL80211_SUPPORT
9349 const char *intf = get_param(cmd, "Interface");
9350 const char *val;
9351 int tid = -1;
9352 int bufsize = 64;
9353 struct nl_msg *msg;
9354 int ret = 0;
9355 struct nlattr *params;
9356 int ifindex;
9357
9358 val = get_param(cmd, "TID");
9359 if (val)
9360 tid = atoi(val);
9361
9362 if (tid == -1) {
9363 send_resp(dut, conn, SIGMA_ERROR,
9364 "ErrorCode,sta_send_addba tid invalid");
9365 return 0;
9366 }
9367
9368 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
9369
9370 ifindex = if_nametoindex(intf);
9371 if (ifindex == 0) {
9372 sigma_dut_print(dut, DUT_MSG_ERROR,
9373 "%s: Index for interface %s failed",
9374 __func__, intf);
9375 send_resp(dut, conn, SIGMA_ERROR,
9376 "ErrorCode,sta_send_addba interface invalid");
9377 return 0;
9378 }
9379
9380 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9381 NL80211_CMD_VENDOR)) ||
9382 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9383 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9384 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9385 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
9386 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9387 nla_put_u8(msg,
9388 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADD_DEL_BA_SESSION,
9389 QCA_WLAN_ADD_BA) ||
9390 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BA_TID,
9391 tid) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -07009392 nla_put_u16(msg,
9393 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
9394 bufsize)) {
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009395 sigma_dut_print(dut, DUT_MSG_ERROR,
9396 "%s: err in adding vendor_cmd and vendor_data",
9397 __func__);
9398 nlmsg_free(msg);
9399 send_resp(dut, conn, SIGMA_ERROR,
9400 "ErrorCode,sta_send_addba err in adding vendor_cmd and vendor_data");
9401 return 0;
9402 }
9403 nla_nest_end(msg, params);
9404
9405 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9406 if (ret) {
9407 sigma_dut_print(dut, DUT_MSG_ERROR,
9408 "%s: err in send_and_recv_msgs, ret=%d",
9409 __func__, ret);
Sunil Dutt30605592018-05-04 20:35:50 +05309410 if (ret == -EOPNOTSUPP)
9411 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009412 send_resp(dut, conn, SIGMA_ERROR,
9413 "ErrorCode,sta_send_addba err in send_and_recv_msgs");
9414 return 0;
9415 }
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009416#else /* NL80211_SUPPORT */
9417 sigma_dut_print(dut, DUT_MSG_ERROR,
9418 "sta_send_addba not supported without NL80211_SUPPORT defined");
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009419#endif /* NL80211_SUPPORT */
Sunil Dutt30605592018-05-04 20:35:50 +05309420
9421 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009422}
9423
9424
Jouni Malinenf7222712019-06-13 01:50:21 +03009425static enum sigma_cmd_result cmd_sta_send_addba(struct sigma_dut *dut,
9426 struct sigma_conn *conn,
9427 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009428{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009429 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009430 case DRIVER_ATHEROS:
9431 return ath_sta_send_addba(dut, conn, cmd);
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009432 case DRIVER_WCN:
9433 return wcn_sta_send_addba(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +02009434#ifdef __linux__
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009435 case DRIVER_WIL6210:
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009436 return send_addba_60g(dut, conn, cmd, "Dest_mac");
Lior David9981b512017-01-20 13:16:40 +02009437#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009438 default:
9439 /*
9440 * There is no driver specific implementation for other drivers.
9441 * Ignore the command and report COMPLETE since the following
9442 * throughput test operation will end up sending ADDBA anyway.
9443 */
9444 return 1;
9445 }
9446}
9447
9448
9449int inject_eth_frame(int s, const void *data, size_t len,
9450 unsigned short ethtype, char *dst, char *src)
9451{
9452 struct iovec iov[4] = {
9453 {
9454 .iov_base = dst,
9455 .iov_len = ETH_ALEN,
9456 },
9457 {
9458 .iov_base = src,
9459 .iov_len = ETH_ALEN,
9460 },
9461 {
9462 .iov_base = &ethtype,
9463 .iov_len = sizeof(unsigned short),
9464 },
9465 {
9466 .iov_base = (void *) data,
9467 .iov_len = len,
9468 }
9469 };
9470 struct msghdr msg = {
9471 .msg_name = NULL,
9472 .msg_namelen = 0,
9473 .msg_iov = iov,
9474 .msg_iovlen = 4,
9475 .msg_control = NULL,
9476 .msg_controllen = 0,
9477 .msg_flags = 0,
9478 };
9479
9480 return sendmsg(s, &msg, 0);
9481}
9482
9483#if defined(__linux__) || defined(__QNXNTO__)
9484
9485int inject_frame(int s, const void *data, size_t len, int encrypt)
9486{
9487#define IEEE80211_RADIOTAP_F_WEP 0x04
9488#define IEEE80211_RADIOTAP_F_FRAG 0x08
9489 unsigned char rtap_hdr[] = {
9490 0x00, 0x00, /* radiotap version */
9491 0x0e, 0x00, /* radiotap length */
9492 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
9493 IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */
9494 0x00, /* padding */
9495 0x00, 0x00, /* RX and TX flags to indicate that */
9496 0x00, 0x00, /* this is the injected frame directly */
9497 };
9498 struct iovec iov[2] = {
9499 {
9500 .iov_base = &rtap_hdr,
9501 .iov_len = sizeof(rtap_hdr),
9502 },
9503 {
9504 .iov_base = (void *) data,
9505 .iov_len = len,
9506 }
9507 };
9508 struct msghdr msg = {
9509 .msg_name = NULL,
9510 .msg_namelen = 0,
9511 .msg_iov = iov,
9512 .msg_iovlen = 2,
9513 .msg_control = NULL,
9514 .msg_controllen = 0,
9515 .msg_flags = 0,
9516 };
9517
9518 if (encrypt)
9519 rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP;
9520
9521 return sendmsg(s, &msg, 0);
9522}
9523
9524
9525int open_monitor(const char *ifname)
9526{
9527#ifdef __QNXNTO__
9528 struct sockaddr_dl ll;
9529 int s;
9530
9531 memset(&ll, 0, sizeof(ll));
9532 ll.sdl_family = AF_LINK;
9533 ll.sdl_index = if_nametoindex(ifname);
9534 if (ll.sdl_index == 0) {
9535 perror("if_nametoindex");
9536 return -1;
9537 }
9538 s = socket(PF_INET, SOCK_RAW, 0);
9539#else /* __QNXNTO__ */
9540 struct sockaddr_ll ll;
9541 int s;
9542
9543 memset(&ll, 0, sizeof(ll));
9544 ll.sll_family = AF_PACKET;
9545 ll.sll_ifindex = if_nametoindex(ifname);
9546 if (ll.sll_ifindex == 0) {
9547 perror("if_nametoindex");
9548 return -1;
9549 }
9550 s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
9551#endif /* __QNXNTO__ */
9552 if (s < 0) {
9553 perror("socket[PF_PACKET,SOCK_RAW]");
9554 return -1;
9555 }
9556
9557 if (bind(s, (struct sockaddr *) &ll, sizeof(ll)) < 0) {
9558 perror("monitor socket bind");
9559 close(s);
9560 return -1;
9561 }
9562
9563 return s;
9564}
9565
9566
9567static int hex2num(char c)
9568{
9569 if (c >= '0' && c <= '9')
9570 return c - '0';
9571 if (c >= 'a' && c <= 'f')
9572 return c - 'a' + 10;
9573 if (c >= 'A' && c <= 'F')
9574 return c - 'A' + 10;
9575 return -1;
9576}
9577
9578
9579int hwaddr_aton(const char *txt, unsigned char *addr)
9580{
9581 int i;
9582
9583 for (i = 0; i < 6; i++) {
9584 int a, b;
9585
9586 a = hex2num(*txt++);
9587 if (a < 0)
9588 return -1;
9589 b = hex2num(*txt++);
9590 if (b < 0)
9591 return -1;
9592 *addr++ = (a << 4) | b;
9593 if (i < 5 && *txt++ != ':')
9594 return -1;
9595 }
9596
9597 return 0;
9598}
9599
9600#endif /* defined(__linux__) || defined(__QNXNTO__) */
9601
9602enum send_frame_type {
9603 DISASSOC, DEAUTH, SAQUERY, AUTH, ASSOCREQ, REASSOCREQ, DLS_REQ
9604};
9605enum send_frame_protection {
9606 CORRECT_KEY, INCORRECT_KEY, UNPROTECTED
9607};
9608
9609
9610static int sta_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn,
9611 enum send_frame_type frame,
9612 enum send_frame_protection protected,
9613 const char *dest)
9614{
9615#ifdef __linux__
9616 unsigned char buf[1000], *pos;
9617 int s, res;
9618 char bssid[20], addr[20];
9619 char result[32], ssid[100];
9620 size_t ssid_len;
9621
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009622 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009623 sizeof(result)) < 0 ||
9624 strncmp(result, "COMPLETED", 9) != 0) {
9625 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Not connected");
9626 return 0;
9627 }
9628
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009629 if (get_wpa_status(get_station_ifname(dut), "bssid",
9630 bssid, sizeof(bssid)) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009631 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9632 "current BSSID");
9633 return 0;
9634 }
9635
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009636 if (get_wpa_status(get_station_ifname(dut), "address",
9637 addr, sizeof(addr)) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009638 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9639 "own MAC address");
9640 return 0;
9641 }
9642
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009643 if (get_wpa_status(get_station_ifname(dut), "ssid", ssid, sizeof(ssid))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009644 < 0) {
9645 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9646 "current SSID");
9647 return 0;
9648 }
9649 ssid_len = strlen(ssid);
9650
9651 pos = buf;
9652
9653 /* Frame Control */
9654 switch (frame) {
9655 case DISASSOC:
9656 *pos++ = 0xa0;
9657 break;
9658 case DEAUTH:
9659 *pos++ = 0xc0;
9660 break;
9661 case SAQUERY:
9662 *pos++ = 0xd0;
9663 break;
9664 case AUTH:
9665 *pos++ = 0xb0;
9666 break;
9667 case ASSOCREQ:
9668 *pos++ = 0x00;
9669 break;
9670 case REASSOCREQ:
9671 *pos++ = 0x20;
9672 break;
9673 case DLS_REQ:
9674 *pos++ = 0xd0;
9675 break;
9676 }
9677
9678 if (protected == INCORRECT_KEY)
9679 *pos++ = 0x40; /* Set Protected field to 1 */
9680 else
9681 *pos++ = 0x00;
9682
9683 /* Duration */
9684 *pos++ = 0x00;
9685 *pos++ = 0x00;
9686
9687 /* addr1 = DA (current AP) */
9688 hwaddr_aton(bssid, pos);
9689 pos += 6;
9690 /* addr2 = SA (own address) */
9691 hwaddr_aton(addr, pos);
9692 pos += 6;
9693 /* addr3 = BSSID (current AP) */
9694 hwaddr_aton(bssid, pos);
9695 pos += 6;
9696
9697 /* Seq# (to be filled by driver/mac80211) */
9698 *pos++ = 0x00;
9699 *pos++ = 0x00;
9700
9701 if (protected == INCORRECT_KEY) {
9702 /* CCMP parameters */
9703 memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8);
9704 pos += 8;
9705 }
9706
9707 if (protected == INCORRECT_KEY) {
9708 switch (frame) {
9709 case DEAUTH:
9710 /* Reason code (encrypted) */
9711 memcpy(pos, "\xa7\x39", 2);
9712 pos += 2;
9713 break;
9714 case DISASSOC:
9715 /* Reason code (encrypted) */
9716 memcpy(pos, "\xa7\x39", 2);
9717 pos += 2;
9718 break;
9719 case SAQUERY:
9720 /* Category|Action|TransID (encrypted) */
9721 memcpy(pos, "\x6f\xbd\xe9\x4d", 4);
9722 pos += 4;
9723 break;
9724 default:
9725 return -1;
9726 }
9727
9728 /* CCMP MIC */
9729 memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8);
9730 pos += 8;
9731 } else {
9732 switch (frame) {
9733 case DEAUTH:
9734 /* reason code = 8 */
9735 *pos++ = 0x08;
9736 *pos++ = 0x00;
9737 break;
9738 case DISASSOC:
9739 /* reason code = 8 */
9740 *pos++ = 0x08;
9741 *pos++ = 0x00;
9742 break;
9743 case SAQUERY:
9744 /* Category - SA Query */
9745 *pos++ = 0x08;
9746 /* SA query Action - Request */
9747 *pos++ = 0x00;
9748 /* Transaction ID */
9749 *pos++ = 0x12;
9750 *pos++ = 0x34;
9751 break;
9752 case AUTH:
9753 /* Auth Alg (Open) */
9754 *pos++ = 0x00;
9755 *pos++ = 0x00;
9756 /* Seq# */
9757 *pos++ = 0x01;
9758 *pos++ = 0x00;
9759 /* Status code */
9760 *pos++ = 0x00;
9761 *pos++ = 0x00;
9762 break;
9763 case ASSOCREQ:
9764 /* Capability Information */
9765 *pos++ = 0x31;
9766 *pos++ = 0x04;
9767 /* Listen Interval */
9768 *pos++ = 0x0a;
9769 *pos++ = 0x00;
9770 /* SSID */
9771 *pos++ = 0x00;
9772 *pos++ = ssid_len;
9773 memcpy(pos, ssid, ssid_len);
9774 pos += ssid_len;
9775 /* Supported Rates */
9776 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
9777 10);
9778 pos += 10;
9779 /* Extended Supported Rates */
9780 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
9781 pos += 6;
9782 /* RSN */
9783 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
9784 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
9785 "\x00\x00\x00\x00\x0f\xac\x06", 28);
9786 pos += 28;
9787 break;
9788 case REASSOCREQ:
9789 /* Capability Information */
9790 *pos++ = 0x31;
9791 *pos++ = 0x04;
9792 /* Listen Interval */
9793 *pos++ = 0x0a;
9794 *pos++ = 0x00;
9795 /* Current AP */
9796 hwaddr_aton(bssid, pos);
9797 pos += 6;
9798 /* SSID */
9799 *pos++ = 0x00;
9800 *pos++ = ssid_len;
9801 memcpy(pos, ssid, ssid_len);
9802 pos += ssid_len;
9803 /* Supported Rates */
9804 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
9805 10);
9806 pos += 10;
9807 /* Extended Supported Rates */
9808 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
9809 pos += 6;
9810 /* RSN */
9811 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
9812 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
9813 "\x00\x00\x00\x00\x0f\xac\x06", 28);
9814 pos += 28;
9815 break;
9816 case DLS_REQ:
9817 /* Category - DLS */
9818 *pos++ = 0x02;
9819 /* DLS Action - Request */
9820 *pos++ = 0x00;
9821 /* Destination MACAddress */
9822 if (dest)
9823 hwaddr_aton(dest, pos);
9824 else
9825 memset(pos, 0, 6);
9826 pos += 6;
9827 /* Source MACAddress */
9828 hwaddr_aton(addr, pos);
9829 pos += 6;
9830 /* Capability Information */
9831 *pos++ = 0x10; /* Privacy */
9832 *pos++ = 0x06; /* QoS */
9833 /* DLS Timeout Value */
9834 *pos++ = 0x00;
9835 *pos++ = 0x01;
9836 /* Supported rates */
9837 *pos++ = 0x01;
9838 *pos++ = 0x08;
9839 *pos++ = 0x0c; /* 6 Mbps */
9840 *pos++ = 0x12; /* 9 Mbps */
9841 *pos++ = 0x18; /* 12 Mbps */
9842 *pos++ = 0x24; /* 18 Mbps */
9843 *pos++ = 0x30; /* 24 Mbps */
9844 *pos++ = 0x48; /* 36 Mbps */
9845 *pos++ = 0x60; /* 48 Mbps */
9846 *pos++ = 0x6c; /* 54 Mbps */
9847 /* TODO: Extended Supported Rates */
9848 /* TODO: HT Capabilities */
9849 break;
9850 }
9851 }
9852
9853 s = open_monitor("sigmadut");
9854 if (s < 0) {
9855 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
9856 "monitor socket");
9857 return 0;
9858 }
9859
9860 res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY);
9861 if (res < 0) {
9862 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
9863 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05309864 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009865 return 0;
9866 }
9867 if (res < pos - buf) {
9868 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Only partial "
9869 "frame sent");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05309870 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009871 return 0;
9872 }
9873
9874 close(s);
9875
9876 return 1;
9877#else /* __linux__ */
9878 send_resp(dut, conn, SIGMA_ERROR, "errorCode,sta_send_frame not "
9879 "yet supported");
9880 return 0;
9881#endif /* __linux__ */
9882}
9883
9884
9885static int cmd_sta_send_frame_tdls(struct sigma_dut *dut,
9886 struct sigma_conn *conn,
9887 struct sigma_cmd *cmd)
9888{
9889 const char *intf = get_param(cmd, "Interface");
9890 const char *sta, *val;
9891 unsigned char addr[ETH_ALEN];
9892 char buf[100];
9893
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +03009894 if (!intf)
9895 return -1;
9896
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009897 sta = get_param(cmd, "peer");
9898 if (sta == NULL)
9899 sta = get_param(cmd, "station");
9900 if (sta == NULL) {
9901 send_resp(dut, conn, SIGMA_ERROR,
9902 "ErrorCode,Missing peer address");
9903 return 0;
9904 }
9905 if (hwaddr_aton(sta, addr) < 0) {
9906 send_resp(dut, conn, SIGMA_ERROR,
9907 "ErrorCode,Invalid peer address");
9908 return 0;
9909 }
9910
9911 val = get_param(cmd, "type");
9912 if (val == NULL)
9913 return -1;
9914
9915 if (strcasecmp(val, "DISCOVERY") == 0) {
9916 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", sta);
9917 if (wpa_command(intf, buf) < 0) {
9918 send_resp(dut, conn, SIGMA_ERROR,
9919 "ErrorCode,Failed to send TDLS discovery");
9920 return 0;
9921 }
9922 return 1;
9923 }
9924
9925 if (strcasecmp(val, "SETUP") == 0) {
9926 int status = 0, timeout = 0;
9927
9928 val = get_param(cmd, "Status");
9929 if (val)
9930 status = atoi(val);
9931
9932 val = get_param(cmd, "Timeout");
9933 if (val)
9934 timeout = atoi(val);
9935
9936 if (status != 0 && status != 37) {
9937 send_resp(dut, conn, SIGMA_ERROR,
9938 "ErrorCode,Unsupported status value");
9939 return 0;
9940 }
9941
9942 if (timeout != 0 && timeout != 301) {
9943 send_resp(dut, conn, SIGMA_ERROR,
9944 "ErrorCode,Unsupported timeout value");
9945 return 0;
9946 }
9947
9948 if (status && timeout) {
9949 send_resp(dut, conn, SIGMA_ERROR,
9950 "ErrorCode,Unsupported timeout+status "
9951 "combination");
9952 return 0;
9953 }
9954
9955 if (status == 37 &&
9956 wpa_command(intf, "SET tdls_testing 0x200")) {
9957 send_resp(dut, conn, SIGMA_ERROR,
9958 "ErrorCode,Failed to enable "
9959 "decline setup response test mode");
9960 return 0;
9961 }
9962
9963 if (timeout == 301) {
9964 int res;
9965 if (dut->no_tpk_expiration)
9966 res = wpa_command(intf,
9967 "SET tdls_testing 0x108");
9968 else
9969 res = wpa_command(intf,
9970 "SET tdls_testing 0x8");
9971 if (res) {
9972 send_resp(dut, conn, SIGMA_ERROR,
9973 "ErrorCode,Failed to set short TPK "
9974 "lifetime");
9975 return 0;
9976 }
9977 }
9978
9979 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", sta);
9980 if (wpa_command(intf, buf) < 0) {
9981 send_resp(dut, conn, SIGMA_ERROR,
9982 "ErrorCode,Failed to send TDLS setup");
9983 return 0;
9984 }
9985 return 1;
9986 }
9987
9988 if (strcasecmp(val, "TEARDOWN") == 0) {
9989 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", sta);
9990 if (wpa_command(intf, buf) < 0) {
9991 send_resp(dut, conn, SIGMA_ERROR,
9992 "ErrorCode,Failed to send TDLS teardown");
9993 return 0;
9994 }
9995 return 1;
9996 }
9997
9998 send_resp(dut, conn, SIGMA_ERROR,
9999 "ErrorCode,Unsupported TDLS frame");
10000 return 0;
10001}
10002
10003
10004static int sta_ap_known(const char *ifname, const char *bssid)
10005{
10006 char buf[4096];
10007
Jouni Malinendd32f192018-09-15 02:55:19 +030010008 snprintf(buf, sizeof(buf), "BSS MASK=1 %s", bssid);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010009 if (wpa_command_resp(ifname, buf, buf, sizeof(buf)) < 0)
10010 return 0;
10011 if (strncmp(buf, "id=", 3) != 0)
10012 return 0;
10013 return 1;
10014}
10015
10016
10017static int sta_scan_ap(struct sigma_dut *dut, const char *ifname,
10018 const char *bssid)
10019{
10020 int res;
10021 struct wpa_ctrl *ctrl;
10022 char buf[256];
10023
10024 if (sta_ap_known(ifname, bssid))
10025 return 0;
10026 sigma_dut_print(dut, DUT_MSG_DEBUG,
10027 "AP not in BSS table - start scan");
10028
10029 ctrl = open_wpa_mon(ifname);
10030 if (ctrl == NULL) {
10031 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
10032 "wpa_supplicant monitor connection");
10033 return -1;
10034 }
10035
10036 if (wpa_command(ifname, "SCAN") < 0) {
10037 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to start scan");
10038 wpa_ctrl_detach(ctrl);
10039 wpa_ctrl_close(ctrl);
10040 return -1;
10041 }
10042
10043 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
10044 buf, sizeof(buf));
10045
10046 wpa_ctrl_detach(ctrl);
10047 wpa_ctrl_close(ctrl);
10048
10049 if (res < 0) {
10050 sigma_dut_print(dut, DUT_MSG_INFO, "Scan did not complete");
10051 return -1;
10052 }
10053
10054 if (sta_ap_known(ifname, bssid))
10055 return 0;
10056 sigma_dut_print(dut, DUT_MSG_INFO, "AP not in BSS table");
10057 return -1;
10058}
10059
10060
10061static int cmd_sta_send_frame_hs2_neighadv(struct sigma_dut *dut,
10062 struct sigma_conn *conn,
10063 struct sigma_cmd *cmd,
10064 const char *intf)
10065{
10066 char buf[200];
10067
10068 snprintf(buf, sizeof(buf), "ndsend 2001:DB8::1 %s", intf);
10069 if (system(buf) != 0) {
10070 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Failed to run "
10071 "ndsend");
10072 return 0;
10073 }
10074
10075 return 1;
10076}
10077
10078
10079static int cmd_sta_send_frame_hs2_neighsolreq(struct sigma_dut *dut,
10080 struct sigma_conn *conn,
10081 struct sigma_cmd *cmd,
10082 const char *intf)
10083{
10084 char buf[200];
10085 const char *ip = get_param(cmd, "SenderIP");
10086
Peng Xu26b356d2017-10-04 17:58:16 -070010087 if (!ip)
10088 return 0;
10089
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010090 snprintf(buf, sizeof(buf), "ndisc6 -nm %s %s -r 4", ip, intf);
10091 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10092 if (system(buf) == 0) {
10093 sigma_dut_print(dut, DUT_MSG_INFO,
10094 "Neighbor Solicitation got a response "
10095 "for %s@%s", ip, intf);
10096 }
10097
10098 return 1;
10099}
10100
10101
10102static int cmd_sta_send_frame_hs2_arpprobe(struct sigma_dut *dut,
10103 struct sigma_conn *conn,
10104 struct sigma_cmd *cmd,
10105 const char *ifname)
10106{
10107 char buf[200];
10108 const char *ip = get_param(cmd, "SenderIP");
10109
10110 if (ip == NULL) {
10111 send_resp(dut, conn, SIGMA_ERROR,
10112 "ErrorCode,Missing SenderIP parameter");
10113 return 0;
10114 }
10115 snprintf(buf, sizeof(buf), "arping -I %s -D %s -c 4", ifname, ip);
10116 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10117 if (system(buf) != 0) {
10118 sigma_dut_print(dut, DUT_MSG_INFO, "arping DAD got a response "
10119 "for %s@%s", ip, ifname);
10120 }
10121
10122 return 1;
10123}
10124
10125
10126static int cmd_sta_send_frame_hs2_arpannounce(struct sigma_dut *dut,
10127 struct sigma_conn *conn,
10128 struct sigma_cmd *cmd,
10129 const char *ifname)
10130{
10131 char buf[200];
10132 char ip[16];
10133 int s;
Peng Xub3756882017-10-04 14:39:09 -070010134 struct ifreq ifr;
10135 struct sockaddr_in saddr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010136
10137 s = socket(PF_INET, SOCK_DGRAM, 0);
Peng Xub3756882017-10-04 14:39:09 -070010138 if (s < 0) {
10139 perror("socket");
10140 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010141 }
10142
Peng Xub3756882017-10-04 14:39:09 -070010143 memset(&ifr, 0, sizeof(ifr));
10144 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
10145 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
10146 sigma_dut_print(dut, DUT_MSG_INFO,
10147 "Failed to get %s IP address: %s",
10148 ifname, strerror(errno));
10149 close(s);
10150 return -1;
10151 }
10152 close(s);
10153
10154 memcpy(&saddr, &ifr.ifr_addr, sizeof(struct sockaddr_in));
10155 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
10156
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010157 snprintf(buf, sizeof(buf), "arping -I %s -s %s %s -c 4", ifname, ip,
10158 ip);
10159 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10160 if (system(buf) != 0) {
10161 }
10162
10163 return 1;
10164}
10165
10166
10167static int cmd_sta_send_frame_hs2_arpreply(struct sigma_dut *dut,
10168 struct sigma_conn *conn,
10169 struct sigma_cmd *cmd,
10170 const char *ifname)
10171{
10172 char buf[200], addr[20];
10173 char dst[ETH_ALEN], src[ETH_ALEN];
10174 short ethtype = htons(ETH_P_ARP);
10175 char *pos;
10176 int s, res;
10177 const char *val;
10178 struct sockaddr_in taddr;
10179
10180 val = get_param(cmd, "dest");
10181 if (val)
10182 hwaddr_aton(val, (unsigned char *) dst);
10183
10184 val = get_param(cmd, "DestIP");
10185 if (val)
10186 inet_aton(val, &taddr.sin_addr);
Peng Xu151c9e12017-10-04 14:39:09 -070010187 else
10188 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010189
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010190 if (get_wpa_status(get_station_ifname(dut), "address", addr,
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010191 sizeof(addr)) < 0)
10192 return -2;
10193 hwaddr_aton(addr, (unsigned char *) src);
10194
10195 pos = buf;
10196 *pos++ = 0x00;
10197 *pos++ = 0x01;
10198 *pos++ = 0x08;
10199 *pos++ = 0x00;
10200 *pos++ = 0x06;
10201 *pos++ = 0x04;
10202 *pos++ = 0x00;
10203 *pos++ = 0x02;
10204 memcpy(pos, src, ETH_ALEN);
10205 pos += ETH_ALEN;
10206 memcpy(pos, &taddr.sin_addr, 4);
10207 pos += 4;
10208 memcpy(pos, dst, ETH_ALEN);
10209 pos += ETH_ALEN;
10210 memcpy(pos, &taddr.sin_addr, 4);
10211 pos += 4;
10212
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010213 s = open_monitor(get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010214 if (s < 0) {
10215 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
10216 "monitor socket");
10217 return 0;
10218 }
10219
10220 res = inject_eth_frame(s, buf, pos - buf, ethtype, dst, src);
10221 if (res < 0) {
10222 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
10223 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +053010224 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010225 return 0;
10226 }
10227
10228 close(s);
10229
10230 return 1;
10231}
10232
10233
10234static int cmd_sta_send_frame_hs2_dls_req(struct sigma_dut *dut,
10235 struct sigma_conn *conn,
10236 struct sigma_cmd *cmd,
10237 const char *intf, const char *dest)
10238{
10239 char buf[100];
10240
10241 if (if_nametoindex("sigmadut") == 0) {
10242 snprintf(buf, sizeof(buf),
10243 "iw dev %s interface add sigmadut type monitor",
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010244 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010245 if (system(buf) != 0 ||
10246 if_nametoindex("sigmadut") == 0) {
10247 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
10248 "monitor interface with '%s'", buf);
10249 return -2;
10250 }
10251 }
10252
10253 if (system("ifconfig sigmadut up") != 0) {
10254 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
10255 "monitor interface up");
10256 return -2;
10257 }
10258
10259 return sta_inject_frame(dut, conn, DLS_REQ, UNPROTECTED, dest);
10260}
10261
10262
10263static int cmd_sta_send_frame_hs2(struct sigma_dut *dut,
10264 struct sigma_conn *conn,
10265 struct sigma_cmd *cmd)
10266{
10267 const char *intf = get_param(cmd, "Interface");
10268 const char *dest = get_param(cmd, "Dest");
10269 const char *type = get_param(cmd, "FrameName");
10270 const char *val;
10271 char buf[200], *pos, *end;
10272 int count, count2;
10273
10274 if (type == NULL)
10275 type = get_param(cmd, "Type");
10276
10277 if (intf == NULL || dest == NULL || type == NULL)
10278 return -1;
10279
10280 if (strcasecmp(type, "NeighAdv") == 0)
10281 return cmd_sta_send_frame_hs2_neighadv(dut, conn, cmd, intf);
10282
10283 if (strcasecmp(type, "NeighSolicitReq") == 0)
10284 return cmd_sta_send_frame_hs2_neighsolreq(dut, conn, cmd, intf);
10285
10286 if (strcasecmp(type, "ARPProbe") == 0)
10287 return cmd_sta_send_frame_hs2_arpprobe(dut, conn, cmd, intf);
10288
10289 if (strcasecmp(type, "ARPAnnounce") == 0)
10290 return cmd_sta_send_frame_hs2_arpannounce(dut, conn, cmd, intf);
10291
10292 if (strcasecmp(type, "ARPReply") == 0)
10293 return cmd_sta_send_frame_hs2_arpreply(dut, conn, cmd, intf);
10294
10295 if (strcasecmp(type, "DLS-request") == 0 ||
10296 strcasecmp(type, "DLSrequest") == 0)
10297 return cmd_sta_send_frame_hs2_dls_req(dut, conn, cmd, intf,
10298 dest);
10299
10300 if (strcasecmp(type, "ANQPQuery") != 0 &&
10301 strcasecmp(type, "Query") != 0) {
10302 send_resp(dut, conn, SIGMA_ERROR,
10303 "ErrorCode,Unsupported HS 2.0 send frame type");
10304 return 0;
10305 }
10306
10307 if (sta_scan_ap(dut, intf, dest) < 0) {
10308 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not find "
10309 "the requested AP");
10310 return 0;
10311 }
10312
10313 pos = buf;
10314 end = buf + sizeof(buf);
10315 count = 0;
10316 pos += snprintf(pos, end - pos, "ANQP_GET %s ", dest);
10317
10318 val = get_param(cmd, "ANQP_CAP_LIST");
10319 if (val && atoi(val)) {
10320 pos += snprintf(pos, end - pos, "%s257", count > 0 ? "," : "");
10321 count++;
10322 }
10323
10324 val = get_param(cmd, "VENUE_NAME");
10325 if (val && atoi(val)) {
10326 pos += snprintf(pos, end - pos, "%s258", count > 0 ? "," : "");
10327 count++;
10328 }
10329
10330 val = get_param(cmd, "NETWORK_AUTH_TYPE");
10331 if (val && atoi(val)) {
10332 pos += snprintf(pos, end - pos, "%s260", count > 0 ? "," : "");
10333 count++;
10334 }
10335
10336 val = get_param(cmd, "ROAMING_CONS");
10337 if (val && atoi(val)) {
10338 pos += snprintf(pos, end - pos, "%s261", count > 0 ? "," : "");
10339 count++;
10340 }
10341
10342 val = get_param(cmd, "IP_ADDR_TYPE_AVAILABILITY");
10343 if (val && atoi(val)) {
10344 pos += snprintf(pos, end - pos, "%s262", count > 0 ? "," : "");
10345 count++;
10346 }
10347
10348 val = get_param(cmd, "NAI_REALM_LIST");
10349 if (val && atoi(val)) {
10350 pos += snprintf(pos, end - pos, "%s263", count > 0 ? "," : "");
10351 count++;
10352 }
10353
10354 val = get_param(cmd, "3GPP_INFO");
10355 if (val && atoi(val)) {
10356 pos += snprintf(pos, end - pos, "%s264", count > 0 ? "," : "");
10357 count++;
10358 }
10359
10360 val = get_param(cmd, "DOMAIN_LIST");
10361 if (val && atoi(val)) {
10362 pos += snprintf(pos, end - pos, "%s268", count > 0 ? "," : "");
10363 count++;
10364 }
10365
Jouni Malinen34cf9532018-04-29 19:26:33 +030010366 val = get_param(cmd, "Venue_URL");
10367 if (val && atoi(val)) {
10368 pos += snprintf(pos, end - pos, "%s277", count > 0 ? "," : "");
10369 count++;
10370 }
10371
Jouni Malinend3bca5d2018-04-29 17:25:23 +030010372 val = get_param(cmd, "Advice_Of_Charge");
10373 if (val && atoi(val)) {
10374 pos += snprintf(pos, end - pos, "%s278", count > 0 ? "," : "");
10375 count++;
10376 }
10377
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010378 if (count && wpa_command(intf, buf)) {
10379 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,ANQP_GET failed");
10380 return 0;
10381 }
10382
10383 pos = buf;
10384 end = buf + sizeof(buf);
10385 count2 = 0;
10386 pos += snprintf(pos, end - pos, "HS20_ANQP_GET %s ", dest);
10387
10388 val = get_param(cmd, "HS_CAP_LIST");
10389 if (val && atoi(val)) {
10390 pos += snprintf(pos, end - pos, "%s2", count2 > 0 ? "," : "");
10391 count2++;
10392 }
10393
10394 val = get_param(cmd, "OPER_NAME");
10395 if (val && atoi(val)) {
10396 pos += snprintf(pos, end - pos, "%s3", count2 > 0 ? "," : "");
10397 count2++;
10398 }
10399
10400 val = get_param(cmd, "WAN_METRICS");
10401 if (!val)
10402 val = get_param(cmd, "WAN_MAT");
10403 if (!val)
10404 val = get_param(cmd, "WAN_MET");
10405 if (val && atoi(val)) {
10406 pos += snprintf(pos, end - pos, "%s4", count2 > 0 ? "," : "");
10407 count2++;
10408 }
10409
10410 val = get_param(cmd, "CONNECTION_CAPABILITY");
10411 if (val && atoi(val)) {
10412 pos += snprintf(pos, end - pos, "%s5", count2 > 0 ? "," : "");
10413 count2++;
10414 }
10415
10416 val = get_param(cmd, "OP_CLASS");
10417 if (val && atoi(val)) {
10418 pos += snprintf(pos, end - pos, "%s7", count2 > 0 ? "," : "");
10419 count2++;
10420 }
10421
10422 val = get_param(cmd, "OSU_PROVIDER_LIST");
10423 if (val && atoi(val)) {
10424 pos += snprintf(pos, end - pos, "%s8", count2 > 0 ? "," : "");
10425 count2++;
10426 }
10427
Jouni Malinenf67afec2018-04-29 19:24:58 +030010428 val = get_param(cmd, "OPER_ICON_METADATA");
10429 if (!val)
10430 val = get_param(cmd, "OPERATOR_ICON_METADATA");
10431 if (val && atoi(val)) {
10432 pos += snprintf(pos, end - pos, "%s12", count2 > 0 ? "," : "");
10433 count2++;
10434 }
10435
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010436 if (count && count2) {
10437 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before sending out "
10438 "second query");
10439 sleep(1);
10440 }
10441
10442 if (count2 && wpa_command(intf, buf)) {
10443 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,HS20_ANQP_GET "
10444 "failed");
10445 return 0;
10446 }
10447
10448 val = get_param(cmd, "NAI_HOME_REALM_LIST");
10449 if (val) {
10450 if (count || count2) {
10451 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
10452 "sending out second query");
10453 sleep(1);
10454 }
10455
10456 if (strcmp(val, "1") == 0)
10457 val = "mail.example.com";
10458 snprintf(buf, end - pos,
10459 "HS20_GET_NAI_HOME_REALM_LIST %s realm=%s",
10460 dest, val);
10461 if (wpa_command(intf, buf)) {
10462 send_resp(dut, conn, SIGMA_ERROR,
10463 "ErrorCode,HS20_GET_NAI_HOME_REALM_LIST "
10464 "failed");
10465 return 0;
10466 }
10467 }
10468
10469 val = get_param(cmd, "ICON_REQUEST");
10470 if (val) {
10471 if (count || count2) {
10472 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
10473 "sending out second query");
10474 sleep(1);
10475 }
10476
10477 snprintf(buf, end - pos,
10478 "HS20_ICON_REQUEST %s %s", dest, val);
10479 if (wpa_command(intf, buf)) {
10480 send_resp(dut, conn, SIGMA_ERROR,
10481 "ErrorCode,HS20_ICON_REQUEST failed");
10482 return 0;
10483 }
10484 }
10485
10486 return 1;
10487}
10488
10489
10490static int ath_sta_send_frame_vht(struct sigma_dut *dut,
10491 struct sigma_conn *conn,
10492 struct sigma_cmd *cmd)
10493{
10494 const char *val;
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010495 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010496 int chwidth, nss;
10497
10498 val = get_param(cmd, "framename");
10499 if (!val)
10500 return -1;
10501 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
10502
10503 /* Command sequence to generate Op mode notification */
10504 if (val && strcasecmp(val, "Op_md_notif_frm") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010505 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010506
10507 /* Disable STBC */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010508 run_iwpriv(dut, ifname, "tx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010509
10510 /* Extract Channel width */
10511 val = get_param(cmd, "Channel_width");
10512 if (val) {
10513 switch (atoi(val)) {
10514 case 20:
10515 chwidth = 0;
10516 break;
10517 case 40:
10518 chwidth = 1;
10519 break;
10520 case 80:
10521 chwidth = 2;
10522 break;
10523 case 160:
10524 chwidth = 3;
10525 break;
10526 default:
10527 chwidth = 2;
10528 break;
10529 }
10530
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010531 run_iwpriv(dut, ifname, "chwidth %d", chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010532 }
10533
10534 /* Extract NSS */
10535 val = get_param(cmd, "NSS");
10536 if (val) {
10537 switch (atoi(val)) {
10538 case 1:
10539 nss = 1;
10540 break;
10541 case 2:
10542 nss = 3;
10543 break;
10544 case 3:
10545 nss = 7;
10546 break;
10547 default:
10548 /* We do not support NSS > 3 */
10549 nss = 3;
10550 break;
10551 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010552 run_iwpriv(dut, ifname, "rxchainmask %d", nss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010553 }
10554
10555 /* Opmode notify */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010556 run_iwpriv(dut, ifname, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010557 }
10558
10559 return 1;
10560}
10561
10562
10563static int cmd_sta_send_frame_vht(struct sigma_dut *dut,
10564 struct sigma_conn *conn,
10565 struct sigma_cmd *cmd)
10566{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010567 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010568 case DRIVER_ATHEROS:
10569 return ath_sta_send_frame_vht(dut, conn, cmd);
10570 default:
10571 send_resp(dut, conn, SIGMA_ERROR,
10572 "errorCode,Unsupported sta_set_frame(VHT) with the current driver");
10573 return 0;
10574 }
10575}
10576
10577
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010578static int wcn_sta_send_frame_he(struct sigma_dut *dut, struct sigma_conn *conn,
10579 struct sigma_cmd *cmd)
10580{
10581 const char *val;
10582 const char *intf = get_param(cmd, "Interface");
10583
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030010584 if (!intf)
10585 return -1;
10586
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010587 val = get_param(cmd, "framename");
10588 if (!val)
10589 return -1;
10590 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
10591
10592 /* Command sequence to generate Op mode notification */
10593 if (val && strcasecmp(val, "action") == 0) {
10594 val = get_param(cmd, "PPDUTxType");
10595 if (val && strcasecmp(val, "TB") == 0) {
10596 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 1)) {
10597 sigma_dut_print(dut, DUT_MSG_ERROR,
10598 "failed to send TB PPDU Tx cfg");
10599 send_resp(dut, conn, SIGMA_ERROR,
10600 "ErrorCode,set TB PPDU Tx cfg failed");
10601 return 0;
10602 }
10603 return 1;
10604 }
10605
10606 sigma_dut_print(dut, DUT_MSG_ERROR,
10607 "Action Tx type is not defined");
10608 }
10609
10610 return 1;
10611}
10612
10613
10614static int cmd_sta_send_frame_he(struct sigma_dut *dut,
10615 struct sigma_conn *conn,
10616 struct sigma_cmd *cmd)
10617{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010618 switch (get_driver_type(dut)) {
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010619 case DRIVER_WCN:
10620 return wcn_sta_send_frame_he(dut, conn, cmd);
10621 default:
10622 send_resp(dut, conn, SIGMA_ERROR,
10623 "errorCode,Unsupported sta_set_frame(HE) with the current driver");
10624 return 0;
10625 }
10626}
10627
10628
Lior David0fe101e2017-03-09 16:09:50 +020010629#ifdef __linux__
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010630
10631static int
10632wil6210_send_p2p_frame_60g(struct sigma_dut *dut, struct sigma_cmd *cmd,
10633 const char *frame_name, const char *dest_mac)
10634{
10635 int isprobereq = strcasecmp(frame_name, "probereq") == 0;
10636 const char *ssid = get_param(cmd, "ssid");
10637 const char *countstr = get_param(cmd, "count");
10638 const char *channelstr = get_param(cmd, "channel");
10639 const char *group_id = get_param(cmd, "groupid");
10640 const char *client_id = get_param(cmd, "clientmac");
10641 int count, channel, freq, i;
10642 const char *fname;
10643 char frame[1024], src_mac[20], group_id_attr[25],
10644 device_macstr[3 * ETH_ALEN], client_mac[ETH_ALEN];
10645 const char *group_ssid;
10646 const int group_ssid_prefix_len = 9;
10647 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *) frame;
10648 size_t framelen = sizeof(frame);
10649 struct template_frame_tag tags[2];
10650 size_t tags_total = ARRAY_SIZE(tags);
10651 int tag_index, len, dst_len;
10652
10653 if (!countstr || !channelstr) {
10654 sigma_dut_print(dut, DUT_MSG_ERROR,
10655 "Missing argument: count, channel");
10656 return -1;
10657 }
10658 if (isprobereq && !ssid) {
10659 sigma_dut_print(dut, DUT_MSG_ERROR,
10660 "Missing argument: ssid");
10661 return -1;
10662 }
10663 if (!isprobereq && (!group_id || !client_id)) {
10664 sigma_dut_print(dut, DUT_MSG_ERROR,
10665 "Missing argument: group_id, client_id");
10666 return -1;
10667 }
10668
10669 count = atoi(countstr);
10670 channel = atoi(channelstr);
10671 freq = channel_to_freq(dut, channel);
10672
10673 if (!freq) {
10674 sigma_dut_print(dut, DUT_MSG_ERROR,
10675 "invalid channel: %s", channelstr);
10676 return -1;
10677 }
10678
10679 if (isprobereq) {
10680 if (strcasecmp(ssid, "wildcard") == 0) {
10681 fname = "probe_req_wildcard.txt";
10682 } else if (strcasecmp(ssid, "P2P_Wildcard") == 0) {
10683 fname = "probe_req_P2P_Wildcard.txt";
10684 } else {
10685 sigma_dut_print(dut, DUT_MSG_ERROR,
10686 "invalid probe request type");
10687 return -1;
10688 }
10689 } else {
10690 fname = "P2P_device_discovery_req.txt";
10691 }
10692
10693 if (parse_template_frame_file(dut, fname, frame, &framelen,
10694 tags, &tags_total)) {
10695 sigma_dut_print(dut, DUT_MSG_ERROR,
10696 "invalid frame template: %s", fname);
10697 return -1;
10698 }
10699
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010700 if (get_wpa_status(get_station_ifname(dut), "address",
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010701 src_mac, sizeof(src_mac)) < 0 ||
10702 parse_mac_address(dut, src_mac, &hdr->addr2[0]) ||
10703 parse_mac_address(dut, dest_mac, &hdr->addr1[0]))
10704 return -1;
10705 /* Use wildcard BSSID, since we are in PBSS */
10706 memset(&hdr->addr3, 0xFF, ETH_ALEN);
10707
10708 if (!isprobereq) {
10709 tag_index = find_template_frame_tag(tags, tags_total, 1);
10710 if (tag_index < 0) {
10711 sigma_dut_print(dut, DUT_MSG_ERROR,
10712 "can't find device id attribute");
10713 return -1;
10714 }
10715 if (parse_mac_address(dut, client_id,
10716 (unsigned char *) client_mac)) {
10717 sigma_dut_print(dut, DUT_MSG_ERROR,
10718 "invalid client_id: %s", client_id);
10719 return -1;
10720 }
10721 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
10722 framelen - tags[tag_index].offset,
10723 IEEE80211_P2P_ATTR_DEVICE_ID,
10724 client_mac, ETH_ALEN)) {
10725 sigma_dut_print(dut, DUT_MSG_ERROR,
10726 "fail to replace device id attribute");
10727 return -1;
10728 }
10729
10730 /*
10731 * group_id arg contains device MAC address followed by
10732 * space and SSID (DIRECT-somessid).
10733 * group id attribute contains device address (6 bytes)
10734 * followed by SSID prefix DIRECT-XX (9 bytes)
10735 */
10736 if (strlen(group_id) < sizeof(device_macstr)) {
10737 sigma_dut_print(dut, DUT_MSG_ERROR,
10738 "group_id arg too short");
10739 return -1;
10740 }
10741 memcpy(device_macstr, group_id, sizeof(device_macstr));
10742 device_macstr[sizeof(device_macstr) - 1] = '\0';
10743 if (parse_mac_address(dut, device_macstr,
10744 (unsigned char *) group_id_attr)) {
10745 sigma_dut_print(dut, DUT_MSG_ERROR,
10746 "fail to parse device address from group_id");
10747 return -1;
10748 }
10749 group_ssid = strchr(group_id, ' ');
10750 if (!group_ssid) {
10751 sigma_dut_print(dut, DUT_MSG_ERROR,
10752 "invalid group_id arg, no ssid");
10753 return -1;
10754 }
10755 group_ssid++;
10756 len = strlen(group_ssid);
10757 if (len < group_ssid_prefix_len) {
10758 sigma_dut_print(dut, DUT_MSG_ERROR,
10759 "group_id SSID too short");
10760 return -1;
10761 }
10762 dst_len = sizeof(group_id_attr) - ETH_ALEN;
10763 if (len > dst_len) {
10764 sigma_dut_print(dut, DUT_MSG_ERROR,
10765 "group_id SSID (%s) too long",
10766 group_ssid);
10767 return -1;
10768 }
10769
10770 memcpy(group_id_attr + ETH_ALEN, group_ssid, len);
10771 tag_index = find_template_frame_tag(tags, tags_total, 2);
10772 if (tag_index < 0) {
10773 sigma_dut_print(dut, DUT_MSG_ERROR,
10774 "can't find group id attribute");
10775 return -1;
10776 }
10777 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
10778 framelen - tags[tag_index].offset,
10779 IEEE80211_P2P_ATTR_GROUP_ID,
10780 group_id_attr,
10781 sizeof(group_id_attr))) {
10782 sigma_dut_print(dut, DUT_MSG_ERROR,
10783 "fail to replace group id attribute");
10784 return -1;
10785 }
10786 }
10787
10788 for (i = 0; i < count; i++) {
10789 if (wil6210_transmit_frame(dut, freq,
10790 WIL_TRANSMIT_FRAME_DEFAULT_ROC,
10791 frame, framelen)) {
10792 sigma_dut_print(dut, DUT_MSG_ERROR,
10793 "fail to transmit probe request frame");
10794 return -1;
10795 }
10796 }
10797
10798 return 0;
10799}
10800
10801
Lior David0fe101e2017-03-09 16:09:50 +020010802int wil6210_send_frame_60g(struct sigma_dut *dut, struct sigma_conn *conn,
10803 struct sigma_cmd *cmd)
10804{
10805 const char *frame_name = get_param(cmd, "framename");
10806 const char *mac = get_param(cmd, "dest_mac");
10807
10808 if (!frame_name || !mac) {
10809 sigma_dut_print(dut, DUT_MSG_ERROR,
10810 "framename and dest_mac must be provided");
10811 return -1;
10812 }
10813
10814 if (strcasecmp(frame_name, "brp") == 0) {
10815 const char *l_rx = get_param(cmd, "L-RX");
10816 int l_rx_i;
10817
10818 if (!l_rx) {
10819 sigma_dut_print(dut, DUT_MSG_ERROR,
10820 "L-RX must be provided");
10821 return -1;
10822 }
10823 l_rx_i = atoi(l_rx);
10824
10825 sigma_dut_print(dut, DUT_MSG_INFO,
10826 "dev_send_frame: BRP-RX, dest_mac %s, L-RX %s",
10827 mac, l_rx);
10828 if (l_rx_i != 16) {
10829 sigma_dut_print(dut, DUT_MSG_ERROR,
10830 "unsupported L-RX: %s", l_rx);
10831 return -1;
10832 }
10833
10834 if (wil6210_send_brp_rx(dut, mac, l_rx_i))
10835 return -1;
10836 } else if (strcasecmp(frame_name, "ssw") == 0) {
10837 sigma_dut_print(dut, DUT_MSG_INFO,
10838 "dev_send_frame: SLS, dest_mac %s", mac);
10839 if (wil6210_send_sls(dut, mac))
10840 return -1;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010841 } else if ((strcasecmp(frame_name, "probereq") == 0) ||
10842 (strcasecmp(frame_name, "devdiscreq") == 0)) {
10843 sigma_dut_print(dut, DUT_MSG_INFO,
10844 "dev_send_frame: %s, dest_mac %s", frame_name,
10845 mac);
10846 if (wil6210_send_p2p_frame_60g(dut, cmd, frame_name, mac))
10847 return -1;
Lior David0fe101e2017-03-09 16:09:50 +020010848 } else {
10849 sigma_dut_print(dut, DUT_MSG_ERROR,
10850 "unsupported frame type: %s", frame_name);
10851 return -1;
10852 }
10853
10854 return 1;
10855}
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010856
Lior David0fe101e2017-03-09 16:09:50 +020010857#endif /* __linux__ */
10858
10859
10860static int cmd_sta_send_frame_60g(struct sigma_dut *dut,
10861 struct sigma_conn *conn,
10862 struct sigma_cmd *cmd)
10863{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010864 switch (get_driver_type(dut)) {
Lior David0fe101e2017-03-09 16:09:50 +020010865#ifdef __linux__
10866 case DRIVER_WIL6210:
10867 return wil6210_send_frame_60g(dut, conn, cmd);
10868#endif /* __linux__ */
10869 default:
10870 send_resp(dut, conn, SIGMA_ERROR,
10871 "errorCode,Unsupported sta_set_frame(60G) with the current driver");
10872 return 0;
10873 }
10874}
10875
10876
Ashwini Patildb59b3c2017-04-13 15:19:23 +053010877static int mbo_send_anqp_query(struct sigma_dut *dut, struct sigma_conn *conn,
10878 const char *intf, struct sigma_cmd *cmd)
10879{
10880 const char *val, *addr;
10881 char buf[100];
10882
10883 addr = get_param(cmd, "DestMac");
10884 if (!addr) {
10885 send_resp(dut, conn, SIGMA_INVALID,
10886 "ErrorCode,AP MAC address is missing");
10887 return 0;
10888 }
10889
10890 val = get_param(cmd, "ANQPQuery_ID");
10891 if (!val) {
10892 send_resp(dut, conn, SIGMA_INVALID,
10893 "ErrorCode,Missing ANQPQuery_ID");
10894 return 0;
10895 }
10896
10897 if (strcasecmp(val, "NeighborReportReq") == 0) {
10898 snprintf(buf, sizeof(buf), "ANQP_GET %s 272", addr);
10899 } else if (strcasecmp(val, "QueryListWithCellPref") == 0) {
10900 snprintf(buf, sizeof(buf), "ANQP_GET %s 272,mbo:2", addr);
10901 } else {
10902 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid ANQPQuery_ID: %s",
10903 val);
10904 send_resp(dut, conn, SIGMA_INVALID,
10905 "ErrorCode,Invalid ANQPQuery_ID");
10906 return 0;
10907 }
10908
Ashwini Patild174f2c2017-04-13 16:49:46 +053010909 /* Set gas_address3 field to IEEE 802.11-2012 standard compliant form
10910 * (Address3 = Wildcard BSSID when sent to not-associated AP;
10911 * if associated, AP BSSID).
10912 */
10913 if (wpa_command(intf, "SET gas_address3 1") < 0) {
10914 send_resp(dut, conn, SIGMA_ERROR,
10915 "ErrorCode,Failed to set gas_address3");
10916 return 0;
10917 }
10918
Ashwini Patildb59b3c2017-04-13 15:19:23 +053010919 if (wpa_command(intf, buf) < 0) {
10920 send_resp(dut, conn, SIGMA_ERROR,
10921 "ErrorCode,Failed to send ANQP query");
10922 return 0;
10923 }
10924
10925 return 1;
10926}
10927
10928
10929static int mbo_cmd_sta_send_frame(struct sigma_dut *dut,
10930 struct sigma_conn *conn,
10931 const char *intf,
10932 struct sigma_cmd *cmd)
10933{
10934 const char *val = get_param(cmd, "FrameName");
10935
10936 if (val && strcasecmp(val, "ANQPQuery") == 0)
10937 return mbo_send_anqp_query(dut, conn, intf, cmd);
10938
10939 return 2;
10940}
10941
10942
Jouni Malinenf7222712019-06-13 01:50:21 +030010943enum sigma_cmd_result cmd_sta_send_frame(struct sigma_dut *dut,
10944 struct sigma_conn *conn,
10945 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010946{
10947 const char *intf = get_param(cmd, "Interface");
10948 const char *val;
10949 enum send_frame_type frame;
10950 enum send_frame_protection protected;
10951 char buf[100];
10952 unsigned char addr[ETH_ALEN];
10953 int res;
10954
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030010955 if (!intf)
10956 return -1;
10957
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010958 val = get_param(cmd, "program");
10959 if (val == NULL)
10960 val = get_param(cmd, "frame");
10961 if (val && strcasecmp(val, "TDLS") == 0)
10962 return cmd_sta_send_frame_tdls(dut, conn, cmd);
10963 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030010964 strcasecmp(val, "HS2-R2") == 0 ||
10965 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010966 return cmd_sta_send_frame_hs2(dut, conn, cmd);
10967 if (val && strcasecmp(val, "VHT") == 0)
10968 return cmd_sta_send_frame_vht(dut, conn, cmd);
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010969 if (val && strcasecmp(val, "HE") == 0)
10970 return cmd_sta_send_frame_he(dut, conn, cmd);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -070010971 if (val && strcasecmp(val, "LOC") == 0)
10972 return loc_cmd_sta_send_frame(dut, conn, cmd);
Lior David0fe101e2017-03-09 16:09:50 +020010973 if (val && strcasecmp(val, "60GHz") == 0)
10974 return cmd_sta_send_frame_60g(dut, conn, cmd);
Ashwini Patildb59b3c2017-04-13 15:19:23 +053010975 if (val && strcasecmp(val, "MBO") == 0) {
10976 res = mbo_cmd_sta_send_frame(dut, conn, intf, cmd);
10977 if (res != 2)
10978 return res;
10979 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010980
10981 val = get_param(cmd, "TD_DISC");
10982 if (val) {
10983 if (hwaddr_aton(val, addr) < 0)
10984 return -1;
10985 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", val);
10986 if (wpa_command(intf, buf) < 0) {
10987 send_resp(dut, conn, SIGMA_ERROR,
10988 "ErrorCode,Failed to send TDLS discovery");
10989 return 0;
10990 }
10991 return 1;
10992 }
10993
10994 val = get_param(cmd, "TD_Setup");
10995 if (val) {
10996 if (hwaddr_aton(val, addr) < 0)
10997 return -1;
10998 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", val);
10999 if (wpa_command(intf, buf) < 0) {
11000 send_resp(dut, conn, SIGMA_ERROR,
11001 "ErrorCode,Failed to start TDLS setup");
11002 return 0;
11003 }
11004 return 1;
11005 }
11006
11007 val = get_param(cmd, "TD_TearDown");
11008 if (val) {
11009 if (hwaddr_aton(val, addr) < 0)
11010 return -1;
11011 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", val);
11012 if (wpa_command(intf, buf) < 0) {
11013 send_resp(dut, conn, SIGMA_ERROR,
11014 "ErrorCode,Failed to tear down TDLS link");
11015 return 0;
11016 }
11017 return 1;
11018 }
11019
11020 val = get_param(cmd, "TD_ChannelSwitch");
11021 if (val) {
11022 /* TODO */
11023 send_resp(dut, conn, SIGMA_ERROR,
11024 "ErrorCode,TD_ChannelSwitch not yet supported");
11025 return 0;
11026 }
11027
11028 val = get_param(cmd, "TD_NF");
11029 if (val) {
11030 /* TODO */
11031 send_resp(dut, conn, SIGMA_ERROR,
11032 "ErrorCode,TD_NF not yet supported");
11033 return 0;
11034 }
11035
11036 val = get_param(cmd, "PMFFrameType");
11037 if (val == NULL)
11038 val = get_param(cmd, "FrameName");
11039 if (val == NULL)
11040 val = get_param(cmd, "Type");
11041 if (val == NULL)
11042 return -1;
11043 if (strcasecmp(val, "disassoc") == 0)
11044 frame = DISASSOC;
11045 else if (strcasecmp(val, "deauth") == 0)
11046 frame = DEAUTH;
11047 else if (strcasecmp(val, "saquery") == 0)
11048 frame = SAQUERY;
11049 else if (strcasecmp(val, "auth") == 0)
11050 frame = AUTH;
11051 else if (strcasecmp(val, "assocreq") == 0)
11052 frame = ASSOCREQ;
11053 else if (strcasecmp(val, "reassocreq") == 0)
11054 frame = REASSOCREQ;
11055 else if (strcasecmp(val, "neigreq") == 0) {
11056 sigma_dut_print(dut, DUT_MSG_INFO, "Got neighbor request");
11057
11058 val = get_param(cmd, "ssid");
11059 if (val == NULL)
11060 return -1;
11061
11062 res = send_neighbor_request(dut, intf, val);
11063 if (res) {
11064 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
11065 "Failed to send neighbor report request");
11066 return 0;
11067 }
11068
11069 return 1;
Ashwini Patil5acd7382017-04-13 15:55:04 +053011070 } else if (strcasecmp(val, "transmgmtquery") == 0 ||
11071 strcasecmp(val, "BTMQuery") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011072 sigma_dut_print(dut, DUT_MSG_DEBUG,
11073 "Got Transition Management Query");
11074
Ashwini Patil5acd7382017-04-13 15:55:04 +053011075 res = send_trans_mgmt_query(dut, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011076 if (res) {
11077 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
11078 "Failed to send Transition Management Query");
11079 return 0;
11080 }
11081
11082 return 1;
11083 } else {
11084 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
11085 "PMFFrameType");
11086 return 0;
11087 }
11088
11089 val = get_param(cmd, "PMFProtected");
11090 if (val == NULL)
11091 val = get_param(cmd, "Protected");
11092 if (val == NULL)
11093 return -1;
11094 if (strcasecmp(val, "Correct-key") == 0 ||
11095 strcasecmp(val, "CorrectKey") == 0)
11096 protected = CORRECT_KEY;
11097 else if (strcasecmp(val, "IncorrectKey") == 0)
11098 protected = INCORRECT_KEY;
11099 else if (strcasecmp(val, "Unprotected") == 0)
11100 protected = UNPROTECTED;
11101 else {
11102 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
11103 "PMFProtected");
11104 return 0;
11105 }
11106
11107 if (protected != UNPROTECTED &&
11108 (frame == AUTH || frame == ASSOCREQ || frame == REASSOCREQ)) {
11109 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Impossible "
11110 "PMFProtected for auth/assocreq/reassocreq");
11111 return 0;
11112 }
11113
11114 if (if_nametoindex("sigmadut") == 0) {
11115 snprintf(buf, sizeof(buf),
11116 "iw dev %s interface add sigmadut type monitor",
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011117 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011118 if (system(buf) != 0 ||
11119 if_nametoindex("sigmadut") == 0) {
11120 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
11121 "monitor interface with '%s'", buf);
11122 return -2;
11123 }
11124 }
11125
11126 if (system("ifconfig sigmadut up") != 0) {
11127 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
11128 "monitor interface up");
11129 return -2;
11130 }
11131
11132 return sta_inject_frame(dut, conn, frame, protected, NULL);
11133}
11134
11135
11136static int cmd_sta_set_parameter_hs2(struct sigma_dut *dut,
11137 struct sigma_conn *conn,
11138 struct sigma_cmd *cmd,
11139 const char *ifname)
11140{
11141 char buf[200];
11142 const char *val;
11143
11144 val = get_param(cmd, "ClearARP");
11145 if (val && atoi(val) == 1) {
11146 snprintf(buf, sizeof(buf), "ip neigh flush dev %s", ifname);
11147 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11148 if (system(buf) != 0) {
11149 send_resp(dut, conn, SIGMA_ERROR,
11150 "errorCode,Failed to clear ARP cache");
11151 return 0;
11152 }
11153 }
11154
11155 return 1;
11156}
11157
11158
11159int cmd_sta_set_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
11160 struct sigma_cmd *cmd)
11161{
11162 const char *intf = get_param(cmd, "Interface");
11163 const char *val;
11164
11165 if (intf == NULL)
11166 return -1;
11167
11168 val = get_param(cmd, "program");
11169 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030011170 strcasecmp(val, "HS2-R2") == 0 ||
11171 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011172 return cmd_sta_set_parameter_hs2(dut, conn, cmd, intf);
11173
11174 return -1;
11175}
11176
11177
Jouni Malinenf7222712019-06-13 01:50:21 +030011178static enum sigma_cmd_result cmd_sta_set_macaddr(struct sigma_dut *dut,
11179 struct sigma_conn *conn,
11180 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011181{
11182 const char *intf = get_param(cmd, "Interface");
11183 const char *mac = get_param(cmd, "MAC");
11184
11185 if (intf == NULL || mac == NULL)
11186 return -1;
11187
11188 sigma_dut_print(dut, DUT_MSG_INFO, "Change local MAC address for "
11189 "interface %s to %s", intf, mac);
11190
11191 if (dut->set_macaddr) {
11192 char buf[128];
11193 int res;
11194 if (strcasecmp(mac, "default") == 0) {
11195 res = snprintf(buf, sizeof(buf), "%s",
11196 dut->set_macaddr);
11197 dut->tmp_mac_addr = 0;
11198 } else {
11199 res = snprintf(buf, sizeof(buf), "%s %s",
11200 dut->set_macaddr, mac);
11201 dut->tmp_mac_addr = 1;
11202 }
11203 if (res < 0 || res >= (int) sizeof(buf))
11204 return -1;
11205 if (system(buf) != 0) {
11206 send_resp(dut, conn, SIGMA_ERROR,
11207 "errorCode,Failed to set MAC "
11208 "address");
11209 return 0;
11210 }
11211 return 1;
11212 }
11213
11214 if (strcasecmp(mac, "default") == 0)
11215 return 1;
11216
11217 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
11218 "command");
11219 return 0;
11220}
11221
11222
11223static int iwpriv_tdlsoffchnmode(struct sigma_dut *dut,
11224 struct sigma_conn *conn, const char *intf,
11225 int val)
11226{
11227 char buf[200];
11228 int res;
11229
11230 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchnmode %d",
11231 intf, val);
11232 if (res < 0 || res >= (int) sizeof(buf))
11233 return -1;
11234 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11235 if (system(buf) != 0) {
11236 send_resp(dut, conn, SIGMA_ERROR,
11237 "errorCode,Failed to configure offchannel mode");
11238 return 0;
11239 }
11240
11241 return 1;
11242}
11243
11244
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011245static int off_chan_val(enum sec_ch_offset off)
11246{
11247 switch (off) {
11248 case SEC_CH_NO:
11249 return 0;
11250 case SEC_CH_40ABOVE:
11251 return 40;
11252 case SEC_CH_40BELOW:
11253 return -40;
11254 }
11255
11256 return 0;
11257}
11258
11259
11260static int iwpriv_set_offchan(struct sigma_dut *dut, struct sigma_conn *conn,
11261 const char *intf, int off_ch_num,
11262 enum sec_ch_offset sec)
11263{
11264 char buf[200];
11265 int res;
11266
11267 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchan %d",
11268 intf, off_ch_num);
11269 if (res < 0 || res >= (int) sizeof(buf))
11270 return -1;
11271 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11272 if (system(buf) != 0) {
11273 send_resp(dut, conn, SIGMA_ERROR,
11274 "errorCode,Failed to set offchan");
11275 return 0;
11276 }
11277
11278 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsecchnoffst %d",
11279 intf, off_chan_val(sec));
11280 if (res < 0 || res >= (int) sizeof(buf))
11281 return -1;
11282 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11283 if (system(buf) != 0) {
11284 send_resp(dut, conn, SIGMA_ERROR,
11285 "errorCode,Failed to set sec chan offset");
11286 return 0;
11287 }
11288
11289 return 1;
11290}
11291
11292
11293static int tdls_set_offchannel_offset(struct sigma_dut *dut,
11294 struct sigma_conn *conn,
11295 const char *intf, int off_ch_num,
11296 enum sec_ch_offset sec)
11297{
11298 char buf[200];
11299 int res;
11300
11301 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNEL %d",
11302 off_ch_num);
11303 if (res < 0 || res >= (int) sizeof(buf))
11304 return -1;
11305 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11306
11307 if (wpa_command(intf, buf) < 0) {
11308 send_resp(dut, conn, SIGMA_ERROR,
11309 "ErrorCode,Failed to set offchan");
11310 return 0;
11311 }
11312 res = snprintf(buf, sizeof(buf), "DRIVER TDLSSECONDARYCHANNELOFFSET %d",
11313 off_chan_val(sec));
11314 if (res < 0 || res >= (int) sizeof(buf))
11315 return -1;
11316
11317 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11318
11319 if (wpa_command(intf, buf) < 0) {
11320 send_resp(dut, conn, SIGMA_ERROR,
11321 "ErrorCode,Failed to set sec chan offset");
11322 return 0;
11323 }
11324
11325 return 1;
11326}
11327
11328
11329static int tdls_set_offchannel_mode(struct sigma_dut *dut,
11330 struct sigma_conn *conn,
11331 const char *intf, int val)
11332{
11333 char buf[200];
11334 int res;
11335
11336 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNELMODE %d",
11337 val);
11338 if (res < 0 || res >= (int) sizeof(buf))
11339 return -1;
11340 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11341
11342 if (wpa_command(intf, buf) < 0) {
11343 send_resp(dut, conn, SIGMA_ERROR,
11344 "ErrorCode,Failed to configure offchannel mode");
11345 return 0;
11346 }
11347
11348 return 1;
11349}
11350
11351
11352static int cmd_sta_set_rfeature_tdls(const char *intf, struct sigma_dut *dut,
11353 struct sigma_conn *conn,
11354 struct sigma_cmd *cmd)
11355{
11356 const char *val;
11357 enum {
11358 CHSM_NOT_SET,
11359 CHSM_ENABLE,
11360 CHSM_DISABLE,
11361 CHSM_REJREQ,
11362 CHSM_UNSOLRESP
11363 } chsm = CHSM_NOT_SET;
11364 int off_ch_num = -1;
11365 enum sec_ch_offset sec_ch = SEC_CH_NO;
11366 int res;
11367
11368 val = get_param(cmd, "Uapsd");
11369 if (val) {
11370 char buf[100];
11371 if (strcasecmp(val, "Enable") == 0)
11372 snprintf(buf, sizeof(buf), "SET ps 99");
11373 else if (strcasecmp(val, "Disable") == 0)
11374 snprintf(buf, sizeof(buf), "SET ps 98");
11375 else {
11376 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
11377 "Unsupported uapsd parameter value");
11378 return 0;
11379 }
11380 if (wpa_command(intf, buf)) {
11381 send_resp(dut, conn, SIGMA_ERROR,
11382 "ErrorCode,Failed to change U-APSD "
11383 "powersave mode");
11384 return 0;
11385 }
11386 }
11387
11388 val = get_param(cmd, "TPKTIMER");
11389 if (val && strcasecmp(val, "DISABLE") == 0) {
11390 if (wpa_command(intf, "SET tdls_testing 0x100")) {
11391 send_resp(dut, conn, SIGMA_ERROR,
11392 "ErrorCode,Failed to enable no TPK "
11393 "expiration test mode");
11394 return 0;
11395 }
11396 dut->no_tpk_expiration = 1;
11397 }
11398
11399 val = get_param(cmd, "ChSwitchMode");
11400 if (val) {
11401 if (strcasecmp(val, "Enable") == 0 ||
11402 strcasecmp(val, "Initiate") == 0)
11403 chsm = CHSM_ENABLE;
11404 else if (strcasecmp(val, "Disable") == 0 ||
11405 strcasecmp(val, "passive") == 0)
11406 chsm = CHSM_DISABLE;
11407 else if (strcasecmp(val, "RejReq") == 0)
11408 chsm = CHSM_REJREQ;
11409 else if (strcasecmp(val, "UnSolResp") == 0)
11410 chsm = CHSM_UNSOLRESP;
11411 else {
11412 send_resp(dut, conn, SIGMA_ERROR,
11413 "ErrorCode,Unknown ChSwitchMode value");
11414 return 0;
11415 }
11416 }
11417
11418 val = get_param(cmd, "OffChNum");
11419 if (val) {
11420 off_ch_num = atoi(val);
11421 if (off_ch_num == 0) {
11422 send_resp(dut, conn, SIGMA_ERROR,
11423 "ErrorCode,Invalid OffChNum");
11424 return 0;
11425 }
11426 }
11427
11428 val = get_param(cmd, "SecChOffset");
11429 if (val) {
11430 if (strcmp(val, "20") == 0)
11431 sec_ch = SEC_CH_NO;
11432 else if (strcasecmp(val, "40above") == 0)
11433 sec_ch = SEC_CH_40ABOVE;
11434 else if (strcasecmp(val, "40below") == 0)
11435 sec_ch = SEC_CH_40BELOW;
11436 else {
11437 send_resp(dut, conn, SIGMA_ERROR,
11438 "ErrorCode,Unknown SecChOffset value");
11439 return 0;
11440 }
11441 }
11442
11443 if (chsm == CHSM_NOT_SET) {
11444 /* no offchannel changes requested */
11445 return 1;
11446 }
11447
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011448 if (strcmp(intf, get_main_ifname(dut)) != 0 &&
11449 strcmp(intf, get_station_ifname(dut)) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011450 send_resp(dut, conn, SIGMA_ERROR,
11451 "ErrorCode,Unknown interface");
11452 return 0;
11453 }
11454
11455 switch (chsm) {
11456 case CHSM_NOT_SET:
Jouni Malinen280f5ba2016-08-29 21:33:10 +030011457 res = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011458 break;
11459 case CHSM_ENABLE:
11460 if (off_ch_num < 0) {
11461 send_resp(dut, conn, SIGMA_ERROR,
11462 "ErrorCode,Missing OffChNum argument");
11463 return 0;
11464 }
11465 if (wifi_chip_type == DRIVER_WCN) {
11466 res = tdls_set_offchannel_offset(dut, conn, intf,
11467 off_ch_num, sec_ch);
11468 } else {
11469 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
11470 sec_ch);
11471 }
11472 if (res != 1)
11473 return res;
11474 if (wifi_chip_type == DRIVER_WCN)
11475 res = tdls_set_offchannel_mode(dut, conn, intf, 1);
11476 else
11477 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 1);
11478 break;
11479 case CHSM_DISABLE:
11480 if (wifi_chip_type == DRIVER_WCN)
11481 res = tdls_set_offchannel_mode(dut, conn, intf, 2);
11482 else
11483 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 2);
11484 break;
11485 case CHSM_REJREQ:
11486 if (wifi_chip_type == DRIVER_WCN)
11487 res = tdls_set_offchannel_mode(dut, conn, intf, 3);
11488 else
11489 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 3);
11490 break;
11491 case CHSM_UNSOLRESP:
11492 if (off_ch_num < 0) {
11493 send_resp(dut, conn, SIGMA_ERROR,
11494 "ErrorCode,Missing OffChNum argument");
11495 return 0;
11496 }
11497 if (wifi_chip_type == DRIVER_WCN) {
11498 res = tdls_set_offchannel_offset(dut, conn, intf,
11499 off_ch_num, sec_ch);
11500 } else {
11501 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
11502 sec_ch);
11503 }
11504 if (res != 1)
11505 return res;
11506 if (wifi_chip_type == DRIVER_WCN)
11507 res = tdls_set_offchannel_mode(dut, conn, intf, 4);
11508 else
11509 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 4);
11510 break;
11511 }
11512
11513 return res;
11514}
11515
11516
11517static int ath_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
11518 struct sigma_conn *conn,
11519 struct sigma_cmd *cmd)
11520{
11521 const char *val;
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053011522 char *token = NULL, *result;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011523
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -070011524 novap_reset(dut, intf, 1);
priyadharshini gowthamane5e25172015-12-08 14:53:48 -080011525
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011526 val = get_param(cmd, "nss_mcs_opt");
11527 if (val) {
11528 /* String (nss_operating_mode; mcs_operating_mode) */
11529 int nss, mcs;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011530 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011531
11532 token = strdup(val);
11533 if (!token)
11534 return 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011535 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053011536 if (!result) {
11537 sigma_dut_print(dut, DUT_MSG_ERROR,
11538 "VHT NSS not specified");
11539 goto failed;
11540 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011541 if (strcasecmp(result, "def") != 0) {
11542 nss = atoi(result);
11543 if (nss == 4)
11544 ath_disable_txbf(dut, intf);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011545 if (run_iwpriv(dut, intf, "nss %d", nss) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011546 goto failed;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011547
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011548 }
11549
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011550 result = strtok_r(NULL, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053011551 if (!result) {
11552 sigma_dut_print(dut, DUT_MSG_ERROR,
11553 "VHT MCS not specified");
11554 goto failed;
11555 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011556 if (strcasecmp(result, "def") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011557 if (run_iwpriv(dut, intf, "set11NRates 0") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011558 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011559 } else {
11560 mcs = atoi(result);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011561 if (run_iwpriv(dut, intf, "vhtmcs %d", mcs) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011562 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011563 }
11564 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011565 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011566 }
11567
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053011568 free(token);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011569 return 1;
11570failed:
11571 free(token);
11572 return 0;
11573}
11574
11575
11576static int cmd_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
11577 struct sigma_conn *conn,
11578 struct sigma_cmd *cmd)
11579{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011580 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011581 case DRIVER_ATHEROS:
11582 return ath_sta_set_rfeature_vht(intf, dut, conn, cmd);
11583 default:
11584 send_resp(dut, conn, SIGMA_ERROR,
11585 "errorCode,Unsupported sta_set_rfeature(VHT) with the current driver");
11586 return 0;
11587 }
11588}
11589
11590
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011591static int wcn_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
11592 struct sigma_conn *conn,
11593 struct sigma_cmd *cmd)
11594{
11595 const char *val;
11596 char *token = NULL, *result;
11597 char buf[60];
11598
11599 val = get_param(cmd, "nss_mcs_opt");
11600 if (val) {
11601 /* String (nss_operating_mode; mcs_operating_mode) */
11602 int nss, mcs, ratecode;
11603 char *saveptr;
11604
11605 token = strdup(val);
11606 if (!token)
11607 return -2;
11608
11609 result = strtok_r(token, ";", &saveptr);
11610 if (!result) {
11611 sigma_dut_print(dut, DUT_MSG_ERROR,
11612 "HE NSS not specified");
11613 goto failed;
11614 }
11615 nss = 1;
11616 if (strcasecmp(result, "def") != 0)
11617 nss = atoi(result);
11618
11619 result = strtok_r(NULL, ";", &saveptr);
11620 if (!result) {
11621 sigma_dut_print(dut, DUT_MSG_ERROR,
11622 "HE MCS not specified");
11623 goto failed;
11624 }
11625 mcs = 7;
11626 if (strcasecmp(result, "def") != 0)
11627 mcs = atoi(result);
11628
Arif Hussain557bf412018-05-25 17:29:36 -070011629 ratecode = 0x20; /* for nss:1 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011630 if (nss == 2) {
Arif Hussain557bf412018-05-25 17:29:36 -070011631 ratecode = 0x40; /* for nss:2 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011632 } else if (nss > 2) {
11633 sigma_dut_print(dut, DUT_MSG_ERROR,
11634 "HE NSS %d not supported", nss);
11635 goto failed;
11636 }
11637
Arif Hussain557bf412018-05-25 17:29:36 -070011638 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss);
11639 if (system(buf) != 0) {
11640 sigma_dut_print(dut, DUT_MSG_ERROR,
11641 "nss_mcs_opt: iwpriv %s nss %d failed",
11642 intf, nss);
11643 goto failed;
11644 }
Arif Hussainac6c5112018-05-25 17:34:00 -070011645 dut->sta_nss = nss;
Arif Hussain557bf412018-05-25 17:29:36 -070011646
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011647 /* Add the MCS to the ratecode */
11648 if (mcs >= 0 && mcs <= 11) {
11649 ratecode += mcs;
Arif Hussain557bf412018-05-25 17:29:36 -070011650#ifdef NL80211_SUPPORT
11651 if (dut->device_type == STA_testbed) {
11652 enum he_mcs_config mcs_config;
11653 int ret;
11654
11655 if (mcs <= 7)
11656 mcs_config = HE_80_MCS0_7;
11657 else if (mcs <= 9)
11658 mcs_config = HE_80_MCS0_9;
11659 else
11660 mcs_config = HE_80_MCS0_11;
11661 ret = sta_set_he_mcs(dut, intf, mcs_config);
11662 if (ret) {
11663 sigma_dut_print(dut, DUT_MSG_ERROR,
11664 "nss_mcs_opt: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
11665 mcs, mcs_config, ret);
11666 goto failed;
11667 }
11668 }
11669#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011670 } else {
11671 sigma_dut_print(dut, DUT_MSG_ERROR,
11672 "HE MCS %d not supported", mcs);
11673 goto failed;
11674 }
11675 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0x%03x",
11676 intf, ratecode);
11677 if (system(buf) != 0) {
11678 sigma_dut_print(dut, DUT_MSG_ERROR,
11679 "iwpriv setting of 11ax rates failed");
11680 goto failed;
11681 }
11682 free(token);
11683 }
11684
11685 val = get_param(cmd, "GI");
11686 if (val) {
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011687 int fix_rate_sgi;
11688
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011689 if (strcmp(val, "0.8") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070011690 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 9", intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011691 fix_rate_sgi = 1;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011692 } else if (strcmp(val, "1.6") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070011693 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 10",
11694 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011695 fix_rate_sgi = 2;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011696 } else if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070011697 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 11",
11698 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011699 fix_rate_sgi = 3;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011700 } else {
11701 send_resp(dut, conn, SIGMA_ERROR,
11702 "errorCode,GI value not supported");
11703 return 0;
11704 }
11705 if (system(buf) != 0) {
11706 send_resp(dut, conn, SIGMA_ERROR,
11707 "errorCode,Failed to set shortgi");
11708 return 0;
11709 }
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011710 snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d",
11711 intf, fix_rate_sgi);
11712 if (system(buf) != 0) {
11713 send_resp(dut, conn, SIGMA_ERROR,
11714 "errorCode,Failed to set fix rate shortgi");
11715 return STATUS_SENT;
11716 }
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011717 }
11718
Subhani Shaik8e7a3052018-04-24 14:03:00 -070011719 val = get_param(cmd, "LTF");
11720 if (val) {
11721#ifdef NL80211_SUPPORT
11722 if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080011723 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_1X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070011724 } if (strcmp(val, "6.4") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080011725 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_2X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070011726 } else if (strcmp(val, "12.8") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080011727 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_4X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070011728 } else {
11729 send_resp(dut, conn, SIGMA_ERROR,
11730 "errorCode, LTF value not supported");
11731 return 0;
11732 }
11733#else /* NL80211_SUPPORT */
11734 sigma_dut_print(dut, DUT_MSG_ERROR,
11735 "LTF cannot be set without NL80211_SUPPORT defined");
11736 return -2;
11737#endif /* NL80211_SUPPORT */
11738 }
11739
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -070011740 val = get_param(cmd, "TxSUPPDU");
11741 if (val) {
11742 int set_val = 1;
11743
11744 if (strcasecmp(val, "Enable") == 0)
11745 set_val = 1;
11746 else if (strcasecmp(val, "Disable") == 0)
11747 set_val = 0;
11748
11749 if (sta_set_tx_su_ppdu_cfg(dut, intf, set_val)) {
11750 send_resp(dut, conn, SIGMA_ERROR,
11751 "ErrorCode,Failed to set Tx SU PPDU config");
11752 return 0;
11753 }
11754 }
11755
Arif Hussain480d5f42019-03-12 14:40:42 -070011756 val = get_param(cmd, "TWT_Setup");
11757 if (val) {
11758 if (strcasecmp(val, "Request") == 0) {
11759 if (sta_twt_request(dut, conn, cmd)) {
11760 send_resp(dut, conn, SIGMA_ERROR,
11761 "ErrorCode,sta_twt_request failed");
11762 return STATUS_SENT;
11763 }
11764 } else if (strcasecmp(val, "Teardown") == 0) {
11765 if (sta_twt_teardown(dut, conn, cmd)) {
11766 send_resp(dut, conn, SIGMA_ERROR,
11767 "ErrorCode,sta_twt_teardown failed");
11768 return STATUS_SENT;
11769 }
11770 }
11771 }
11772
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -080011773 val = get_param(cmd, "transmitOMI");
11774 if (val && sta_transmit_omi(dut, conn, cmd)) {
11775 send_resp(dut, conn, SIGMA_ERROR,
11776 "ErrorCode,sta_transmit_omi failed");
11777 return STATUS_SENT;
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -070011778 }
11779
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080011780 val = get_param(cmd, "Powersave");
11781 if (val) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053011782 int ps;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080011783
11784 if (strcasecmp(val, "off") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053011785 ps = 2;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080011786 } else if (strcasecmp(val, "on") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053011787 ps = 1;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080011788 } else {
11789 sigma_dut_print(dut, DUT_MSG_ERROR,
11790 "Unsupported Powersave value '%s'",
11791 val);
11792 return -1;
11793 }
Vinita S. Malooa8b62722020-04-23 01:45:41 +053011794 if (set_power_save_wcn(dut, intf, ps) < 0)
11795 return 0;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080011796 }
11797
Kiran Kumar Lokere2c4b7ce2019-01-30 12:02:28 -080011798 val = get_param(cmd, "MU_EDCA");
11799 if (val) {
11800 if (strcasecmp(val, "Override") == 0) {
11801 if (sta_set_mu_edca_override(dut, intf, 1)) {
11802 send_resp(dut, conn, SIGMA_ERROR,
11803 "errorCode,MU EDCA override set failed");
11804 return STATUS_SENT;
11805 }
11806 } else if (strcasecmp(val, "Disable") == 0) {
11807 if (sta_set_mu_edca_override(dut, intf, 0)) {
11808 send_resp(dut, conn, SIGMA_ERROR,
11809 "errorCode,MU EDCA override disable failed");
11810 return STATUS_SENT;
11811 }
11812 }
11813 }
11814
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011815 return 1;
11816
11817failed:
11818 free(token);
11819 return -2;
11820}
11821
11822
11823static int cmd_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
11824 struct sigma_conn *conn,
11825 struct sigma_cmd *cmd)
11826{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011827 switch (get_driver_type(dut)) {
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011828 case DRIVER_WCN:
11829 return wcn_sta_set_rfeature_he(intf, dut, conn, cmd);
11830 default:
11831 send_resp(dut, conn, SIGMA_ERROR,
11832 "errorCode,Unsupported sta_set_rfeature(HE) with the current driver");
11833 return 0;
11834 }
11835}
11836
11837
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080011838static int cmd_sta_set_power_save_he(const char *intf, struct sigma_dut *dut,
11839 struct sigma_conn *conn,
11840 struct sigma_cmd *cmd)
11841{
11842 const char *val;
11843
11844 val = get_param(cmd, "powersave");
11845 if (val) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053011846 int ps;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080011847
11848 if (strcasecmp(val, "off") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053011849 ps = 2;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080011850 } else if (strcasecmp(val, "on") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053011851 ps = 1;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080011852 } else {
11853 sigma_dut_print(dut, DUT_MSG_ERROR,
11854 "Unsupported power save config");
11855 return -1;
11856 }
Vinita S. Malooa8b62722020-04-23 01:45:41 +053011857 if (set_power_save_wcn(dut, intf, ps) < 0)
11858 return 0;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080011859 return 1;
11860 }
11861
11862 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported command");
11863
11864 return 0;
11865}
11866
11867
Ashwini Patil5acd7382017-04-13 15:55:04 +053011868static int btm_query_candidate_list(struct sigma_dut *dut,
11869 struct sigma_conn *conn,
11870 struct sigma_cmd *cmd)
11871{
11872 const char *bssid, *info, *op_class, *ch, *phy_type, *pref;
11873 int len, ret;
11874 char buf[10];
11875
11876 /*
11877 * Neighbor Report elements format:
11878 * neighbor=<BSSID>,<BSSID Information>,<Operating Class>,
11879 * <Channel Number>,<PHY Type>[,<hexdump of Optional Subelements>]
11880 * eg: neighbor=aa:bb:cc:dd:ee:ff,17,81,6,1,030101
11881 */
11882
11883 bssid = get_param(cmd, "Nebor_BSSID");
11884 if (!bssid) {
11885 send_resp(dut, conn, SIGMA_INVALID,
11886 "errorCode,Nebor_BSSID is missing");
11887 return 0;
11888 }
11889
11890 info = get_param(cmd, "Nebor_Bssid_Info");
11891 if (!info) {
11892 sigma_dut_print(dut, DUT_MSG_INFO,
11893 "Using default value for Nebor_Bssid_Info: %s",
11894 DEFAULT_NEIGHBOR_BSSID_INFO);
11895 info = DEFAULT_NEIGHBOR_BSSID_INFO;
11896 }
11897
11898 op_class = get_param(cmd, "Nebor_Op_Class");
11899 if (!op_class) {
11900 send_resp(dut, conn, SIGMA_INVALID,
11901 "errorCode,Nebor_Op_Class is missing");
11902 return 0;
11903 }
11904
11905 ch = get_param(cmd, "Nebor_Op_Ch");
11906 if (!ch) {
11907 send_resp(dut, conn, SIGMA_INVALID,
11908 "errorCode,Nebor_Op_Ch is missing");
11909 return 0;
11910 }
11911
11912 phy_type = get_param(cmd, "Nebor_Phy_Type");
11913 if (!phy_type) {
11914 sigma_dut_print(dut, DUT_MSG_INFO,
11915 "Using default value for Nebor_Phy_Type: %s",
11916 DEFAULT_NEIGHBOR_PHY_TYPE);
11917 phy_type = DEFAULT_NEIGHBOR_PHY_TYPE;
11918 }
11919
11920 /* Parse optional subelements */
11921 buf[0] = '\0';
11922 pref = get_param(cmd, "Nebor_Pref");
11923 if (pref) {
11924 /* hexdump for preferrence subelement */
11925 ret = snprintf(buf, sizeof(buf), ",0301%02x", atoi(pref));
11926 if (ret < 0 || ret >= (int) sizeof(buf)) {
11927 sigma_dut_print(dut, DUT_MSG_ERROR,
11928 "snprintf failed for optional subelement ret: %d",
11929 ret);
11930 send_resp(dut, conn, SIGMA_ERROR,
11931 "errorCode,snprintf failed for subelement");
11932 return 0;
11933 }
11934 }
11935
11936 if (!dut->btm_query_cand_list) {
11937 dut->btm_query_cand_list = calloc(1, NEIGHBOR_REPORT_SIZE);
11938 if (!dut->btm_query_cand_list) {
11939 send_resp(dut, conn, SIGMA_ERROR,
11940 "errorCode,Failed to allocate memory for btm_query_cand_list");
11941 return 0;
11942 }
11943 }
11944
11945 len = strlen(dut->btm_query_cand_list);
11946 ret = snprintf(dut->btm_query_cand_list + len,
11947 NEIGHBOR_REPORT_SIZE - len, " neighbor=%s,%s,%s,%s,%s%s",
11948 bssid, info, op_class, ch, phy_type, buf);
11949 if (ret < 0 || ret >= NEIGHBOR_REPORT_SIZE - len) {
11950 sigma_dut_print(dut, DUT_MSG_ERROR,
11951 "snprintf failed for neighbor report list ret: %d",
11952 ret);
11953 send_resp(dut, conn, SIGMA_ERROR,
11954 "errorCode,snprintf failed for neighbor report");
11955 free(dut->btm_query_cand_list);
11956 dut->btm_query_cand_list = NULL;
11957 return 0;
11958 }
11959
11960 return 1;
11961}
11962
11963
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020011964int sta_extract_60g_ese(struct sigma_dut *dut, struct sigma_cmd *cmd,
11965 struct sigma_ese_alloc *allocs, int *allocs_size)
11966{
11967 int max_count = *allocs_size;
11968 int count = 0, i;
11969 const char *val;
11970
11971 do {
11972 val = get_param_indexed(cmd, "AllocID", count);
11973 if (val)
11974 count++;
11975 } while (val);
11976
11977 if (count == 0 || count > max_count) {
11978 sigma_dut_print(dut, DUT_MSG_ERROR,
11979 "Invalid number of allocations(%d)", count);
11980 return -1;
11981 }
11982
11983 for (i = 0; i < count; i++) {
11984 val = get_param_indexed(cmd, "PercentBI", i);
11985 if (!val) {
11986 sigma_dut_print(dut, DUT_MSG_ERROR,
11987 "Missing PercentBI parameter at index %d",
11988 i);
11989 return -1;
11990 }
11991 allocs[i].percent_bi = atoi(val);
11992
11993 val = get_param_indexed(cmd, "SrcAID", i);
11994 if (val)
11995 allocs[i].src_aid = strtol(val, NULL, 0);
11996 else
11997 allocs[i].src_aid = ESE_BCAST_AID;
11998
11999 val = get_param_indexed(cmd, "DestAID", i);
12000 if (val)
12001 allocs[i].dst_aid = strtol(val, NULL, 0);
12002 else
12003 allocs[i].dst_aid = ESE_BCAST_AID;
12004
12005 allocs[i].type = ESE_CBAP;
12006 sigma_dut_print(dut, DUT_MSG_INFO,
12007 "Alloc %d PercentBI %d SrcAID %d DstAID %d",
12008 i, allocs[i].percent_bi, allocs[i].src_aid,
12009 allocs[i].dst_aid);
12010 }
12011
12012 *allocs_size = count;
12013 return 0;
12014}
12015
12016
12017static int sta_set_60g_ese(struct sigma_dut *dut, int count,
12018 struct sigma_ese_alloc *allocs)
12019{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012020 switch (get_driver_type(dut)) {
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012021#ifdef __linux__
12022 case DRIVER_WIL6210:
12023 if (wil6210_set_ese(dut, count, allocs))
12024 return -1;
12025 return 1;
12026#endif /* __linux__ */
12027 default:
12028 sigma_dut_print(dut, DUT_MSG_ERROR,
12029 "Unsupported sta_set_60g_ese with the current driver");
12030 return -1;
12031 }
12032}
12033
12034
12035static int cmd_sta_set_rfeature_60g(const char *intf, struct sigma_dut *dut,
12036 struct sigma_conn *conn,
12037 struct sigma_cmd *cmd)
12038{
12039 const char *val;
12040
12041 val = get_param(cmd, "ExtSchIE");
12042 if (val && !strcasecmp(val, "Enable")) {
12043 struct sigma_ese_alloc allocs[MAX_ESE_ALLOCS];
12044 int count = MAX_ESE_ALLOCS;
12045
12046 if (sta_extract_60g_ese(dut, cmd, allocs, &count))
12047 return -1;
12048 return sta_set_60g_ese(dut, count, allocs);
12049 }
12050
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020012051 val = get_param(cmd, "MCS_FixedRate");
12052 if (val) {
12053 int sta_mcs = atoi(val);
12054
12055 sigma_dut_print(dut, DUT_MSG_INFO, "Force STA MCS to %d",
12056 sta_mcs);
12057 wil6210_set_force_mcs(dut, 1, sta_mcs);
12058
Jouni Malinen0e29cf22019-02-19 01:13:21 +020012059 return SUCCESS_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020012060 }
12061
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012062 send_resp(dut, conn, SIGMA_ERROR,
12063 "errorCode,Invalid sta_set_rfeature(60G)");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020012064 return STATUS_SENT;
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012065}
12066
12067
Jouni Malinen6250cb02020-04-15 13:54:45 +030012068static enum sigma_cmd_result
12069cmd_sta_set_rfeature_wpa3(const char *intf, struct sigma_dut *dut,
12070 struct sigma_conn *conn,
12071 struct sigma_cmd *cmd)
12072{
Vamsi Krishnad29bc762020-05-08 23:23:30 +053012073 const char *val, *oci_chan, *oci_frametype;
Jouni Malinen6250cb02020-04-15 13:54:45 +030012074
Veerendranath Jakkam30bf9072020-04-16 14:37:57 +053012075 val = get_param(cmd, "ReassocReq_RSNXE_Used");
Jouni Malinen6250cb02020-04-15 13:54:45 +030012076 if (val && atoi(val) == 1) {
12077 if (wpa_command(intf, "SET ft_rsnxe_used 1") < 0) {
12078 send_resp(dut, conn, SIGMA_ERROR,
12079 "errorCode,Failed to set ft_rsnxe_used");
12080 return STATUS_SENT_ERROR;
12081 }
12082 return SUCCESS_SEND_STATUS;
12083 }
Vamsi Krishnad29bc762020-05-08 23:23:30 +053012084
12085 oci_chan = get_param(cmd, "OCIChannel");
12086 oci_frametype = get_param(cmd, "OCIFrameType");
12087 if (oci_chan && oci_frametype) {
12088 unsigned int oci_freq = channel_to_freq(dut, atoi(oci_chan));
12089 char buf[100];
12090
12091 if (!oci_freq) {
12092 send_resp(dut, conn, SIGMA_ERROR,
12093 "errorCode,Invalid OCIChannel number");
12094 return STATUS_SENT_ERROR;
12095 }
12096
12097 if (strcasecmp(oci_frametype, "eapolM2") == 0) {
12098 snprintf(buf, sizeof(buf),
12099 "SET oci_freq_override_eapol %d", oci_freq);
12100 } else if (strcasecmp(oci_frametype, "SAQueryReq") == 0) {
12101 snprintf(buf, sizeof(buf),
12102 "SET oci_freq_override_saquery_req %d",
12103 oci_freq);
12104 } else if (strcasecmp(oci_frametype, "SAQueryResp") == 0) {
12105 snprintf(buf, sizeof(buf),
12106 "SET oci_freq_override_saquery_resp %d",
12107 oci_freq);
12108 } else {
12109 send_resp(dut, conn, SIGMA_ERROR,
12110 "errorCode,Unsupported OCIFrameType");
12111 return STATUS_SENT_ERROR;
12112 }
12113 if (wpa_command(intf, buf) < 0) {
12114 send_resp(dut, conn, SIGMA_ERROR,
12115 "errorCode,Failed to set oci_freq_override");
12116 return STATUS_SENT_ERROR;
12117 }
12118 return SUCCESS_SEND_STATUS;
12119 }
12120
Jouni Malinen6250cb02020-04-15 13:54:45 +030012121 send_resp(dut, conn, SIGMA_ERROR,
12122 "errorCode,Unsupported WPA3 rfeature");
12123 return STATUS_SENT_ERROR;
12124}
12125
12126
Jouni Malinenf7222712019-06-13 01:50:21 +030012127static enum sigma_cmd_result cmd_sta_set_rfeature(struct sigma_dut *dut,
12128 struct sigma_conn *conn,
12129 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012130{
12131 const char *intf = get_param(cmd, "Interface");
12132 const char *prog = get_param(cmd, "Prog");
Ashwini Patil68d02cd2017-01-10 15:39:16 +053012133 const char *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012134
12135 if (intf == NULL || prog == NULL)
12136 return -1;
12137
Ashwini Patil5acd7382017-04-13 15:55:04 +053012138 /* BSS Transition candidate list for BTM query */
12139 val = get_param(cmd, "Nebor_BSSID");
12140 if (val && btm_query_candidate_list(dut, conn, cmd) == 0)
12141 return 0;
12142
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012143 if (strcasecmp(prog, "TDLS") == 0)
12144 return cmd_sta_set_rfeature_tdls(intf, dut, conn, cmd);
12145
12146 if (strcasecmp(prog, "VHT") == 0)
12147 return cmd_sta_set_rfeature_vht(intf, dut, conn, cmd);
12148
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012149 if (strcasecmp(prog, "HE") == 0)
12150 return cmd_sta_set_rfeature_he(intf, dut, conn, cmd);
12151
Ashwini Patil68d02cd2017-01-10 15:39:16 +053012152 if (strcasecmp(prog, "MBO") == 0) {
12153 val = get_param(cmd, "Cellular_Data_Cap");
12154 if (val &&
12155 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
12156 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +053012157
12158 val = get_param(cmd, "Ch_Pref");
12159 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
12160 return 0;
12161
Ashwini Patil68d02cd2017-01-10 15:39:16 +053012162 return 1;
12163 }
12164
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012165 if (strcasecmp(prog, "60GHz") == 0)
12166 return cmd_sta_set_rfeature_60g(intf, dut, conn, cmd);
12167
Jouni Malinen6250cb02020-04-15 13:54:45 +030012168 if (strcasecmp(prog, "WPA3") == 0)
12169 return cmd_sta_set_rfeature_wpa3(intf, dut, conn, cmd);
12170
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012171 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported Prog");
12172 return 0;
12173}
12174
12175
Jouni Malinenf7222712019-06-13 01:50:21 +030012176static enum sigma_cmd_result cmd_sta_set_radio(struct sigma_dut *dut,
12177 struct sigma_conn *conn,
12178 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012179{
12180 const char *intf = get_param(cmd, "Interface");
12181 const char *mode = get_param(cmd, "Mode");
12182 int res;
12183
12184 if (intf == NULL || mode == NULL)
12185 return -1;
12186
12187 if (strcasecmp(mode, "On") == 0)
12188 res = wpa_command(intf, "SET radio_disabled 0");
12189 else if (strcasecmp(mode, "Off") == 0)
12190 res = wpa_command(intf, "SET radio_disabled 1");
12191 else
12192 return -1;
12193
12194 if (res) {
12195 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
12196 "radio mode");
12197 return 0;
12198 }
12199
12200 return 1;
12201}
12202
12203
Jouni Malinenf7222712019-06-13 01:50:21 +030012204static enum sigma_cmd_result cmd_sta_set_pwrsave(struct sigma_dut *dut,
12205 struct sigma_conn *conn,
12206 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012207{
12208 const char *intf = get_param(cmd, "Interface");
12209 const char *mode = get_param(cmd, "Mode");
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012210 const char *prog = get_param(cmd, "program");
12211 const char *powersave = get_param(cmd, "powersave");
12212 int res = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012213
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012214 if (intf == NULL)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012215 return -1;
12216
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012217 if (prog && strcasecmp(prog, "60GHz") == 0) {
12218 /*
12219 * The CAPI mode parameter does not exist in 60G
12220 * unscheduled PS.
12221 */
Hu Wang5dc3ff12019-06-14 15:14:26 +080012222 if (powersave && strcasecmp(powersave, "unscheduled") == 0)
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012223 res = set_ps(intf, dut, 1);
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012224 } else if (prog && get_driver_type(dut) == DRIVER_WCN &&
Alexei Avshalom Lazar2f6fdb42019-02-04 14:16:08 +020012225 strcasecmp(prog, "HE") == 0) {
12226 return cmd_sta_set_power_save_he(intf, dut, conn, cmd);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012227 } else {
12228 if (mode == NULL)
12229 return -1;
12230
12231 if (strcasecmp(mode, "On") == 0)
12232 res = set_ps(intf, dut, 1);
12233 else if (strcasecmp(mode, "Off") == 0)
12234 res = set_ps(intf, dut, 0);
12235 else
12236 return -1;
12237 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012238
12239 if (res) {
12240 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
12241 "power save mode");
12242 return 0;
12243 }
12244
12245 return 1;
12246}
12247
12248
Jouni Malinenf7222712019-06-13 01:50:21 +030012249static enum sigma_cmd_result cmd_sta_bssid_pool(struct sigma_dut *dut,
12250 struct sigma_conn *conn,
12251 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012252{
12253 const char *intf = get_param(cmd, "Interface");
12254 const char *val, *bssid;
12255 int res;
12256 char *buf;
12257 size_t buf_len;
12258
12259 val = get_param(cmd, "BSSID_FILTER");
12260 if (val == NULL)
12261 return -1;
12262
12263 bssid = get_param(cmd, "BSSID_List");
12264 if (atoi(val) == 0 || bssid == NULL) {
12265 /* Disable BSSID filter */
12266 if (wpa_command(intf, "SET bssid_filter ")) {
12267 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed "
12268 "to disable BSSID filter");
12269 return 0;
12270 }
12271
12272 return 1;
12273 }
12274
12275 buf_len = 100 + strlen(bssid);
12276 buf = malloc(buf_len);
12277 if (buf == NULL)
12278 return -1;
12279
12280 snprintf(buf, buf_len, "SET bssid_filter %s", bssid);
12281 res = wpa_command(intf, buf);
12282 free(buf);
12283 if (res) {
12284 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to enable "
12285 "BSSID filter");
12286 return 0;
12287 }
12288
12289 return 1;
12290}
12291
12292
Jouni Malinenf7222712019-06-13 01:50:21 +030012293static enum sigma_cmd_result cmd_sta_reset_parm(struct sigma_dut *dut,
12294 struct sigma_conn *conn,
12295 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012296{
12297 const char *intf = get_param(cmd, "Interface");
12298 const char *val;
12299
12300 /* TODO: ARP */
12301
12302 val = get_param(cmd, "HS2_CACHE_PROFILE");
12303 if (val && strcasecmp(val, "All") == 0)
12304 hs2_clear_credentials(intf);
12305
12306 return 1;
12307}
12308
12309
Jouni Malinenf7222712019-06-13 01:50:21 +030012310static enum sigma_cmd_result cmd_sta_get_key(struct sigma_dut *dut,
12311 struct sigma_conn *conn,
12312 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012313{
12314 const char *intf = get_param(cmd, "Interface");
12315 const char *key_type = get_param(cmd, "KeyType");
12316 char buf[100], resp[200];
12317
12318 if (key_type == NULL)
12319 return -1;
12320
12321 if (strcasecmp(key_type, "GTK") == 0) {
12322 if (wpa_command_resp(intf, "GET gtk", buf, sizeof(buf)) < 0 ||
12323 strncmp(buf, "FAIL", 4) == 0) {
12324 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12325 "not fetch current GTK");
12326 return 0;
12327 }
12328 snprintf(resp, sizeof(resp), "KeyValue,%s", buf);
12329 send_resp(dut, conn, SIGMA_COMPLETE, resp);
12330 return 0;
12331 } else {
12332 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
12333 "KeyType");
12334 return 0;
12335 }
12336
12337 return 1;
12338}
12339
12340
12341static int hs2_set_policy(struct sigma_dut *dut)
12342{
12343#ifdef ANDROID
12344 system("ip rule del prio 23000");
12345 if (system("ip rule add from all lookup main prio 23000") != 0) {
12346 sigma_dut_print(dut, DUT_MSG_ERROR,
12347 "Failed to run:ip rule add from all lookup main prio");
12348 return -1;
12349 }
12350 if (system("ip route flush cache") != 0) {
12351 sigma_dut_print(dut, DUT_MSG_ERROR,
12352 "Failed to run ip route flush cache");
12353 return -1;
12354 }
12355 return 1;
12356#else /* ANDROID */
12357 return 0;
12358#endif /* ANDROID */
12359}
12360
12361
Jouni Malinenf7222712019-06-13 01:50:21 +030012362static enum sigma_cmd_result cmd_sta_hs2_associate(struct sigma_dut *dut,
12363 struct sigma_conn *conn,
12364 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012365{
12366 const char *intf = get_param(cmd, "Interface");
12367 const char *val = get_param(cmd, "Ignore_blacklist");
Jouni Malinen439352d2018-09-13 03:42:23 +030012368 const char *band = get_param(cmd, "Band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012369 struct wpa_ctrl *ctrl;
Jouni Malinen3aa72862019-05-29 23:14:51 +030012370 int res, r;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012371 char bssid[20], ssid[40], resp[100], buf[100], blacklisted[100];
12372 int tries = 0;
12373 int ignore_blacklist = 0;
12374 const char *events[] = {
12375 "CTRL-EVENT-CONNECTED",
12376 "INTERWORKING-BLACKLISTED",
12377 "INTERWORKING-NO-MATCH",
12378 NULL
12379 };
12380
12381 start_sta_mode(dut);
12382
Jouni Malinen439352d2018-09-13 03:42:23 +030012383 if (band) {
12384 if (strcmp(band, "2.4") == 0) {
12385 wpa_command(intf, "SET setband 2G");
12386 } else if (strcmp(band, "5") == 0) {
12387 wpa_command(intf, "SET setband 5G");
12388 } else {
12389 send_resp(dut, conn, SIGMA_ERROR,
12390 "errorCode,Unsupported band");
12391 return 0;
12392 }
12393 }
12394
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012395 blacklisted[0] = '\0';
12396 if (val && atoi(val))
12397 ignore_blacklist = 1;
12398
12399try_again:
12400 ctrl = open_wpa_mon(intf);
12401 if (ctrl == NULL) {
12402 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
12403 "wpa_supplicant monitor connection");
12404 return -2;
12405 }
12406
12407 tries++;
12408 if (wpa_command(intf, "INTERWORKING_SELECT auto")) {
12409 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start "
12410 "Interworking connection");
12411 wpa_ctrl_detach(ctrl);
12412 wpa_ctrl_close(ctrl);
12413 return 0;
12414 }
12415
12416 buf[0] = '\0';
12417 while (1) {
12418 char *pos;
12419 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
12420 pos = strstr(buf, "INTERWORKING-BLACKLISTED");
12421 if (!pos)
12422 break;
12423 pos += 25;
12424 sigma_dut_print(dut, DUT_MSG_DEBUG, "Found blacklisted AP: %s",
12425 pos);
12426 if (!blacklisted[0])
12427 memcpy(blacklisted, pos, strlen(pos) + 1);
12428 }
12429
12430 if (ignore_blacklist && blacklisted[0]) {
12431 char *end;
12432 end = strchr(blacklisted, ' ');
12433 if (end)
12434 *end = '\0';
12435 sigma_dut_print(dut, DUT_MSG_DEBUG, "Try to connect to a blacklisted network: %s",
12436 blacklisted);
Jouni Malinen3aa72862019-05-29 23:14:51 +030012437 r = snprintf(buf, sizeof(buf), "INTERWORKING_CONNECT %s",
12438 blacklisted);
12439 if (r < 0 || r >= sizeof(buf) || wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012440 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start Interworking connection to blacklisted network");
12441 wpa_ctrl_detach(ctrl);
12442 wpa_ctrl_close(ctrl);
12443 return 0;
12444 }
12445 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
12446 buf, sizeof(buf));
12447 }
12448
12449 wpa_ctrl_detach(ctrl);
12450 wpa_ctrl_close(ctrl);
12451
12452 if (res < 0) {
12453 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
12454 "connect");
12455 return 0;
12456 }
12457
12458 if (strstr(buf, "INTERWORKING-NO-MATCH") ||
12459 strstr(buf, "INTERWORKING-BLACKLISTED")) {
12460 if (tries < 2) {
12461 sigma_dut_print(dut, DUT_MSG_INFO, "No match found - try again to verify no APs were missed in the scan");
12462 goto try_again;
12463 }
12464 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,No network with "
12465 "matching credentials found");
12466 return 0;
12467 }
12468
12469 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
12470 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
12471 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
12472 "get current BSSID/SSID");
12473 return 0;
12474 }
12475
12476 snprintf(resp, sizeof(resp), "SSID,%s,BSSID,%s", ssid, bssid);
12477 send_resp(dut, conn, SIGMA_COMPLETE, resp);
12478 hs2_set_policy(dut);
12479 return 0;
12480}
12481
12482
Jouni Malinenf7222712019-06-13 01:50:21 +030012483static enum sigma_cmd_result cmd_sta_hs2_venue_info(struct sigma_dut *dut,
12484 struct sigma_conn *conn,
12485 struct sigma_cmd *cmd)
Jouni Malinenb639f1c2018-09-13 02:39:46 +030012486{
12487 const char *intf = get_param(cmd, "Interface");
12488 const char *display = get_param(cmd, "Display");
12489 struct wpa_ctrl *ctrl;
12490 char buf[300], params[400], *pos;
12491 char bssid[20];
12492 int info_avail = 0;
12493 unsigned int old_timeout;
12494 int res;
12495
12496 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
12497 send_resp(dut, conn, SIGMA_ERROR,
12498 "ErrorCode,Could not get current BSSID");
12499 return 0;
12500 }
12501 ctrl = open_wpa_mon(intf);
12502 if (!ctrl) {
12503 sigma_dut_print(dut, DUT_MSG_ERROR,
12504 "Failed to open wpa_supplicant monitor connection");
12505 return -2;
12506 }
12507
12508 snprintf(buf, sizeof(buf), "ANQP_GET %s 277", bssid);
12509 wpa_command(intf, buf);
12510
12511 res = get_wpa_cli_event(dut, ctrl, "GAS-QUERY-DONE", buf, sizeof(buf));
12512 if (res < 0) {
12513 send_resp(dut, conn, SIGMA_ERROR,
12514 "ErrorCode,Could not complete GAS query");
12515 goto fail;
12516 }
12517
12518 old_timeout = dut->default_timeout;
12519 dut->default_timeout = 2;
12520 res = get_wpa_cli_event(dut, ctrl, "RX-VENUE-URL", buf, sizeof(buf));
12521 dut->default_timeout = old_timeout;
12522 if (res < 0)
12523 goto done;
12524 pos = strchr(buf, ' ');
12525 if (!pos)
12526 goto done;
12527 pos++;
12528 pos = strchr(pos, ' ');
12529 if (!pos)
12530 goto done;
12531 pos++;
12532 info_avail = 1;
12533 snprintf(params, sizeof(params), "browser %s", pos);
12534
12535 if (display && strcasecmp(display, "Yes") == 0) {
12536 pid_t pid;
12537
12538 pid = fork();
12539 if (pid < 0) {
12540 perror("fork");
12541 return -1;
12542 }
12543
12544 if (pid == 0) {
12545 run_hs20_osu(dut, params);
12546 exit(0);
12547 }
12548 }
12549
12550done:
12551 snprintf(buf, sizeof(buf), "Info_available,%s",
12552 info_avail ? "Yes" : "No");
12553 send_resp(dut, conn, SIGMA_COMPLETE, buf);
12554fail:
12555 wpa_ctrl_detach(ctrl);
12556 wpa_ctrl_close(ctrl);
12557 return 0;
12558}
12559
12560
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012561static int sta_add_credential_uname_pwd(struct sigma_dut *dut,
12562 struct sigma_conn *conn,
12563 const char *ifname,
12564 struct sigma_cmd *cmd)
12565{
12566 const char *val;
12567 int id;
12568
12569 id = add_cred(ifname);
12570 if (id < 0)
12571 return -2;
12572 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
12573
12574 val = get_param(cmd, "prefer");
12575 if (val && atoi(val) > 0)
12576 set_cred(ifname, id, "priority", "1");
12577
12578 val = get_param(cmd, "REALM");
12579 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
12580 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12581 "realm");
12582 return 0;
12583 }
12584
12585 val = get_param(cmd, "HOME_FQDN");
12586 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
12587 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12588 "home_fqdn");
12589 return 0;
12590 }
12591
12592 val = get_param(cmd, "Username");
12593 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
12594 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12595 "username");
12596 return 0;
12597 }
12598
12599 val = get_param(cmd, "Password");
12600 if (val && set_cred_quoted(ifname, id, "password", val) < 0) {
12601 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12602 "password");
12603 return 0;
12604 }
12605
12606 val = get_param(cmd, "ROOT_CA");
12607 if (val) {
12608 char fname[200];
12609 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
12610#ifdef __linux__
12611 if (!file_exists(fname)) {
12612 char msg[300];
12613 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
12614 "file (%s) not found", fname);
12615 send_resp(dut, conn, SIGMA_ERROR, msg);
12616 return 0;
12617 }
12618#endif /* __linux__ */
12619 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
12620 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12621 "not set root CA");
12622 return 0;
12623 }
12624 }
12625
12626 return 1;
12627}
12628
12629
12630static int update_devdetail_imsi(struct sigma_dut *dut, const char *imsi)
12631{
12632 FILE *in, *out;
12633 char buf[500];
12634 int found = 0;
12635
12636 in = fopen("devdetail.xml", "r");
12637 if (in == NULL)
12638 return -1;
12639 out = fopen("devdetail.xml.tmp", "w");
12640 if (out == NULL) {
12641 fclose(in);
12642 return -1;
12643 }
12644
12645 while (fgets(buf, sizeof(buf), in)) {
12646 char *pos = strstr(buf, "<IMSI>");
12647 if (pos) {
12648 sigma_dut_print(dut, DUT_MSG_INFO, "Updated DevDetail IMSI to %s",
12649 imsi);
12650 pos += 6;
12651 *pos = '\0';
12652 fprintf(out, "%s%s</IMSI>\n", buf, imsi);
12653 found++;
12654 } else {
12655 fprintf(out, "%s", buf);
12656 }
12657 }
12658
12659 fclose(out);
12660 fclose(in);
12661 if (found)
12662 rename("devdetail.xml.tmp", "devdetail.xml");
12663 else
12664 unlink("devdetail.xml.tmp");
12665
12666 return 0;
12667}
12668
12669
12670static int sta_add_credential_sim(struct sigma_dut *dut,
12671 struct sigma_conn *conn,
12672 const char *ifname, struct sigma_cmd *cmd)
12673{
12674 const char *val, *imsi = NULL;
12675 int id;
12676 char buf[200];
12677 int res;
12678 const char *pos;
12679 size_t mnc_len;
12680 char plmn_mcc[4];
12681 char plmn_mnc[4];
12682
12683 id = add_cred(ifname);
12684 if (id < 0)
12685 return -2;
12686 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
12687
12688 val = get_param(cmd, "prefer");
12689 if (val && atoi(val) > 0)
12690 set_cred(ifname, id, "priority", "1");
12691
12692 val = get_param(cmd, "PLMN_MCC");
12693 if (val == NULL) {
12694 send_resp(dut, conn, SIGMA_ERROR,
12695 "errorCode,Missing PLMN_MCC");
12696 return 0;
12697 }
12698 if (strlen(val) != 3) {
12699 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MCC");
12700 return 0;
12701 }
12702 snprintf(plmn_mcc, sizeof(plmn_mcc), "%s", val);
12703
12704 val = get_param(cmd, "PLMN_MNC");
12705 if (val == NULL) {
12706 send_resp(dut, conn, SIGMA_ERROR,
12707 "errorCode,Missing PLMN_MNC");
12708 return 0;
12709 }
12710 if (strlen(val) != 2 && strlen(val) != 3) {
12711 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MNC");
12712 return 0;
12713 }
12714 snprintf(plmn_mnc, sizeof(plmn_mnc), "%s", val);
12715
12716 val = get_param(cmd, "IMSI");
12717 if (val == NULL) {
12718 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing SIM "
12719 "IMSI");
12720 return 0;
12721 }
12722
12723 imsi = pos = val;
12724
12725 if (strncmp(plmn_mcc, pos, 3) != 0) {
12726 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MCC mismatch");
12727 return 0;
12728 }
12729 pos += 3;
12730
12731 mnc_len = strlen(plmn_mnc);
12732 if (mnc_len < 2) {
12733 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC not set");
12734 return 0;
12735 }
12736
12737 if (strncmp(plmn_mnc, pos, mnc_len) != 0) {
12738 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC mismatch");
12739 return 0;
12740 }
12741 pos += mnc_len;
12742
12743 res = snprintf(buf, sizeof(buf), "%s%s-%s",plmn_mcc, plmn_mnc, pos);
12744 if (res < 0 || res >= (int) sizeof(buf))
12745 return -1;
12746 if (set_cred_quoted(ifname, id, "imsi", buf) < 0) {
12747 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12748 "not set IMSI");
12749 return 0;
12750 }
12751
12752 val = get_param(cmd, "Password");
12753 if (val && set_cred_quoted(ifname, id, "milenage", val) < 0) {
12754 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12755 "not set password");
12756 return 0;
12757 }
12758
Jouni Malinenba630452018-06-22 11:49:59 +030012759 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012760 /*
12761 * Set provisioning_sp for the test cases where SIM/USIM
12762 * provisioning is used.
12763 */
12764 if (val && set_cred_quoted(ifname, id, "provisioning_sp",
12765 "wi-fi.org") < 0) {
12766 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12767 "not set provisioning_sp");
12768 return 0;
12769 }
12770
12771 update_devdetail_imsi(dut, imsi);
12772 }
12773
12774 return 1;
12775}
12776
12777
12778static int sta_add_credential_cert(struct sigma_dut *dut,
12779 struct sigma_conn *conn,
12780 const char *ifname,
12781 struct sigma_cmd *cmd)
12782{
12783 const char *val;
12784 int id;
12785
12786 id = add_cred(ifname);
12787 if (id < 0)
12788 return -2;
12789 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
12790
12791 val = get_param(cmd, "prefer");
12792 if (val && atoi(val) > 0)
12793 set_cred(ifname, id, "priority", "1");
12794
12795 val = get_param(cmd, "REALM");
12796 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
12797 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12798 "realm");
12799 return 0;
12800 }
12801
12802 val = get_param(cmd, "HOME_FQDN");
12803 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
12804 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12805 "home_fqdn");
12806 return 0;
12807 }
12808
12809 val = get_param(cmd, "Username");
12810 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
12811 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12812 "username");
12813 return 0;
12814 }
12815
12816 val = get_param(cmd, "clientCertificate");
12817 if (val) {
12818 char fname[200];
12819 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
12820#ifdef __linux__
12821 if (!file_exists(fname)) {
12822 char msg[300];
12823 snprintf(msg, sizeof(msg),
12824 "ErrorCode,clientCertificate "
12825 "file (%s) not found", fname);
12826 send_resp(dut, conn, SIGMA_ERROR, msg);
12827 return 0;
12828 }
12829#endif /* __linux__ */
12830 if (set_cred_quoted(ifname, id, "client_cert", fname) < 0) {
12831 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12832 "not set client_cert");
12833 return 0;
12834 }
12835 if (set_cred_quoted(ifname, id, "private_key", fname) < 0) {
12836 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12837 "not set private_key");
12838 return 0;
12839 }
12840 }
12841
12842 val = get_param(cmd, "ROOT_CA");
12843 if (val) {
12844 char fname[200];
12845 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
12846#ifdef __linux__
12847 if (!file_exists(fname)) {
12848 char msg[300];
12849 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
12850 "file (%s) not found", fname);
12851 send_resp(dut, conn, SIGMA_ERROR, msg);
12852 return 0;
12853 }
12854#endif /* __linux__ */
12855 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
12856 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12857 "not set root CA");
12858 return 0;
12859 }
12860 }
12861
12862 return 1;
12863}
12864
12865
Jouni Malinenf7222712019-06-13 01:50:21 +030012866static enum sigma_cmd_result cmd_sta_add_credential(struct sigma_dut *dut,
12867 struct sigma_conn *conn,
12868 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012869{
12870 const char *intf = get_param(cmd, "Interface");
12871 const char *type;
12872
12873 start_sta_mode(dut);
12874
12875 type = get_param(cmd, "Type");
12876 if (!type)
12877 return -1;
12878
12879 if (strcasecmp(type, "uname_pwd") == 0)
12880 return sta_add_credential_uname_pwd(dut, conn, intf, cmd);
12881
12882 if (strcasecmp(type, "sim") == 0)
12883 return sta_add_credential_sim(dut, conn, intf, cmd);
12884
12885 if (strcasecmp(type, "cert") == 0)
12886 return sta_add_credential_cert(dut, conn, intf, cmd);
12887
12888 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported credential "
12889 "type");
12890 return 0;
12891}
12892
12893
Jouni Malinenf7222712019-06-13 01:50:21 +030012894static enum sigma_cmd_result cmd_sta_scan(struct sigma_dut *dut,
12895 struct sigma_conn *conn,
12896 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012897{
12898 const char *intf = get_param(cmd, "Interface");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080012899 const char *val, *bssid, *ssid, *scan_freq, *short_ssid;
Arif Hussain66a4af02019-02-07 15:04:51 -080012900 char buf[4096];
vamsi krishna89ad8c62017-09-19 12:51:18 +053012901 char ssid_hex[65];
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080012902 int wildcard_ssid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012903 int res;
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080012904 enum sigma_cmd_result status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012905
Jouni Malinen8c1abeb2019-11-06 18:48:34 +020012906 start_sta_mode(dut);
12907
Arif Hussain66a4af02019-02-07 15:04:51 -080012908 val = get_param(cmd, "GetParameter");
12909 if (val && strcmp(val, "SSID_BSSID") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012910 if (get_wpa_ssid_bssid(dut, get_station_ifname(dut),
Arif Hussain66a4af02019-02-07 15:04:51 -080012911 buf, sizeof(buf)) < 0) {
12912 sigma_dut_print(dut, DUT_MSG_ERROR,
12913 "Could not get ssid bssid");
12914 return ERROR_SEND_STATUS;
12915 }
12916
12917 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
12918 send_resp(dut, conn, SIGMA_COMPLETE, buf);
12919 return STATUS_SENT;
12920 }
12921
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012922 val = get_param(cmd, "HESSID");
12923 if (val) {
12924 res = snprintf(buf, sizeof(buf), "SET hessid %s", val);
12925 if (res < 0 || res >= (int) sizeof(buf))
12926 return -1;
12927 wpa_command(intf, buf);
12928 }
12929
12930 val = get_param(cmd, "ACCS_NET_TYPE");
12931 if (val) {
12932 res = snprintf(buf, sizeof(buf), "SET access_network_type %s",
12933 val);
12934 if (res < 0 || res >= (int) sizeof(buf))
12935 return -1;
12936 wpa_command(intf, buf);
12937 }
12938
vamsi krishna89ad8c62017-09-19 12:51:18 +053012939 bssid = get_param(cmd, "Bssid");
12940 ssid = get_param(cmd, "Ssid");
12941
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080012942 if (ssid && strcasecmp(ssid, "ZeroLength") == 0 &&
12943 dut->device_type == STA_testbed) {
12944 ssid = NULL;
12945 wildcard_ssid = 1;
12946 }
12947
vamsi krishna89ad8c62017-09-19 12:51:18 +053012948 if (ssid) {
12949 if (2 * strlen(ssid) >= sizeof(ssid_hex)) {
12950 send_resp(dut, conn, SIGMA_ERROR,
12951 "ErrorCode,Too long SSID");
12952 return 0;
12953 }
12954 ascii2hexstr(ssid, ssid_hex);
12955 }
12956
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080012957 short_ssid = get_param(cmd, "ShortSSID");
12958 if (short_ssid) {
12959 uint32_t short_ssid_hex;
12960
12961 short_ssid_hex = strtoul(short_ssid, NULL, 16);
12962 short_ssid_hex = ((short_ssid_hex & 0xFF) << 24) |
12963 (((short_ssid_hex >> 8) & 0xFF) << 16) |
12964 (((short_ssid_hex >> 16) & 0xFF) << 8) |
12965 ((short_ssid_hex >> 24) & 0xFF);
12966
12967 res = snprintf(buf, sizeof(buf),
12968 "VENDOR_ELEM_ADD 14 ff053a%08x",
12969 short_ssid_hex);
12970 if (res < 0 || res >= (int) sizeof(buf) ||
12971 wpa_command(intf, buf)) {
12972 send_resp(dut, conn, SIGMA_ERROR,
12973 "errorCode,Failed to add short SSID");
12974 return STATUS_SENT_ERROR;
12975 }
12976 }
12977
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080012978 scan_freq = get_param(cmd, "ChnlFreq");
12979
12980 res = snprintf(buf, sizeof(buf), "SCAN%s%s%s%s%s%s%s",
vamsi krishna89ad8c62017-09-19 12:51:18 +053012981 bssid ? " bssid=": "",
12982 bssid ? bssid : "",
12983 ssid ? " ssid " : "",
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080012984 ssid ? ssid_hex : "",
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080012985 wildcard_ssid ? " wildcard_ssid=1" : "",
12986 scan_freq ? " freq=" : "",
12987 scan_freq ? scan_freq : "");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080012988 if (res < 0 || res >= (int) sizeof(buf)) {
12989 send_resp(dut, conn, SIGMA_ERROR,
12990 "errorCode,Could not build scan command");
12991 status = STATUS_SENT_ERROR;
12992 goto remove_s_ssid;
12993 }
vamsi krishna89ad8c62017-09-19 12:51:18 +053012994
12995 if (wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012996 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not start "
12997 "scan");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080012998 status = STATUS_SENT_ERROR;
12999 } else {
13000 status = SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013001 }
13002
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013003remove_s_ssid:
13004 if (short_ssid && wpa_command(intf, "VENDOR_ELEM_REMOVE 14 *"))
13005 sigma_dut_print(dut, DUT_MSG_ERROR,
13006 "Failed to delete vendor element");
13007
13008 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013009}
13010
13011
Jouni Malinenf7222712019-06-13 01:50:21 +030013012static enum sigma_cmd_result cmd_sta_scan_bss(struct sigma_dut *dut,
13013 struct sigma_conn *conn,
13014 struct sigma_cmd *cmd)
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020013015{
13016 const char *intf = get_param(cmd, "Interface");
13017 const char *bssid;
13018 char buf[4096], *pos;
13019 int freq, chan;
13020 char *ssid;
13021 char resp[100];
13022 int res;
13023 struct wpa_ctrl *ctrl;
13024
13025 bssid = get_param(cmd, "BSSID");
13026 if (!bssid) {
13027 send_resp(dut, conn, SIGMA_INVALID,
13028 "errorCode,BSSID argument is missing");
13029 return 0;
13030 }
13031
13032 ctrl = open_wpa_mon(intf);
13033 if (!ctrl) {
13034 sigma_dut_print(dut, DUT_MSG_ERROR,
13035 "Failed to open wpa_supplicant monitor connection");
13036 return -1;
13037 }
13038
13039 if (wpa_command(intf, "SCAN TYPE=ONLY")) {
13040 send_resp(dut, conn, SIGMA_ERROR,
13041 "errorCode,Could not start scan");
13042 wpa_ctrl_detach(ctrl);
13043 wpa_ctrl_close(ctrl);
13044 return 0;
13045 }
13046
13047 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
13048 buf, sizeof(buf));
13049
13050 wpa_ctrl_detach(ctrl);
13051 wpa_ctrl_close(ctrl);
13052
13053 if (res < 0) {
13054 send_resp(dut, conn, SIGMA_ERROR,
13055 "errorCode,Scan did not complete");
13056 return 0;
13057 }
13058
13059 snprintf(buf, sizeof(buf), "BSS %s", bssid);
13060 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
13061 strncmp(buf, "id=", 3) != 0) {
13062 send_resp(dut, conn, SIGMA_ERROR,
13063 "errorCode,Specified BSSID not found");
13064 return 0;
13065 }
13066
13067 pos = strstr(buf, "\nfreq=");
13068 if (!pos) {
13069 send_resp(dut, conn, SIGMA_ERROR,
13070 "errorCode,Channel not found");
13071 return 0;
13072 }
13073 freq = atoi(pos + 6);
13074 chan = freq_to_channel(freq);
13075
13076 pos = strstr(buf, "\nssid=");
13077 if (!pos) {
13078 send_resp(dut, conn, SIGMA_ERROR,
13079 "errorCode,SSID not found");
13080 return 0;
13081 }
13082 ssid = pos + 6;
13083 pos = strchr(ssid, '\n');
13084 if (pos)
13085 *pos = '\0';
13086 snprintf(resp, sizeof(resp), "ssid,%s,bsschannel,%d", ssid, chan);
13087 send_resp(dut, conn, SIGMA_COMPLETE, resp);
13088 return 0;
13089}
13090
13091
Jouni Malinenf7222712019-06-13 01:50:21 +030013092static enum sigma_cmd_result cmd_sta_set_systime(struct sigma_dut *dut,
13093 struct sigma_conn *conn,
13094 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013095{
13096#ifdef __linux__
13097 struct timeval tv;
13098 struct tm tm;
13099 time_t t;
13100 const char *val;
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053013101 int v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013102
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013103 wpa_command(get_station_ifname(dut), "PMKSA_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013104
13105 memset(&tm, 0, sizeof(tm));
13106 val = get_param(cmd, "seconds");
13107 if (val)
13108 tm.tm_sec = atoi(val);
13109 val = get_param(cmd, "minutes");
13110 if (val)
13111 tm.tm_min = atoi(val);
13112 val = get_param(cmd, "hours");
13113 if (val)
13114 tm.tm_hour = atoi(val);
13115 val = get_param(cmd, "date");
13116 if (val)
13117 tm.tm_mday = atoi(val);
13118 val = get_param(cmd, "month");
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053013119 if (val) {
13120 v = atoi(val);
13121 if (v < 1 || v > 12) {
13122 send_resp(dut, conn, SIGMA_INVALID,
13123 "errorCode,Invalid month");
13124 return 0;
13125 }
13126 tm.tm_mon = v - 1;
13127 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013128 val = get_param(cmd, "year");
13129 if (val) {
13130 int year = atoi(val);
13131#ifdef ANDROID
13132 if (year > 2035)
13133 year = 2035; /* years beyond 2035 not supported */
13134#endif /* ANDROID */
13135 tm.tm_year = year - 1900;
13136 }
13137 t = mktime(&tm);
13138 if (t == (time_t) -1) {
13139 send_resp(dut, conn, SIGMA_ERROR,
13140 "errorCode,Invalid date or time");
13141 return 0;
13142 }
13143
13144 memset(&tv, 0, sizeof(tv));
13145 tv.tv_sec = t;
13146
13147 if (settimeofday(&tv, NULL) < 0) {
13148 sigma_dut_print(dut, DUT_MSG_INFO, "settimeofday failed: %s",
13149 strerror(errno));
13150 send_resp(dut, conn, SIGMA_ERROR,
13151 "errorCode,Failed to set time");
13152 return 0;
13153 }
13154
13155 return 1;
13156#endif /* __linux__ */
13157
13158 return -1;
13159}
13160
13161
Jouni Malinenf7222712019-06-13 01:50:21 +030013162static enum sigma_cmd_result cmd_sta_osu(struct sigma_dut *dut,
13163 struct sigma_conn *conn,
13164 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013165{
13166 const char *intf = get_param(cmd, "Interface");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013167 const char *name, *osu_ssid, *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013168 int prod_ess_assoc = 1;
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013169 char buf[300], bssid[100], ssid[100];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013170 int res;
13171 struct wpa_ctrl *ctrl;
13172
13173 name = get_param(cmd, "osuFriendlyName");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013174 osu_ssid = get_param(cmd, "osu_ssid");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013175
13176 val = get_param(cmd, "ProdESSAssoc");
13177 if (val)
13178 prod_ess_assoc = atoi(val);
13179
13180 kill_dhcp_client(dut, intf);
13181 if (start_dhcp_client(dut, intf) < 0)
13182 return -2;
13183
13184 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger OSU");
13185 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
13186 res = snprintf(buf, sizeof(buf),
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013187 "%s %s%s%s %s%s%s signup osu-ca.pem",
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013188 prod_ess_assoc ? "" : "-N",
13189 name ? "-O'" : "", name ? name : "",
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013190 name ? "'" : "",
13191 osu_ssid ? "-o'" : "", osu_ssid ? osu_ssid : "",
13192 osu_ssid ? "'" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013193
Kanchanapally, Vidyullatha12b66762015-12-31 16:46:42 +053013194 hs2_set_policy(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013195 if (run_hs20_osu(dut, buf) < 0) {
13196 FILE *f;
13197
13198 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to complete OSU");
13199
13200 f = fopen("hs20-osu-client.res", "r");
13201 if (f) {
13202 char resp[400], res[300], *pos;
13203 if (!fgets(res, sizeof(res), f))
13204 res[0] = '\0';
13205 pos = strchr(res, '\n');
13206 if (pos)
13207 *pos = '\0';
13208 fclose(f);
13209 sigma_dut_summary(dut, "hs20-osu-client provisioning failed: %s",
13210 res);
13211 snprintf(resp, sizeof(resp), "notify-send '%s'", res);
13212 if (system(resp) != 0) {
13213 }
13214 snprintf(resp, sizeof(resp),
13215 "SSID,,BSSID,,failureReason,%s", res);
13216 send_resp(dut, conn, SIGMA_COMPLETE, resp);
13217 return 0;
13218 }
13219
13220 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
13221 return 0;
13222 }
13223
13224 if (!prod_ess_assoc)
13225 goto report;
13226
13227 ctrl = open_wpa_mon(intf);
13228 if (ctrl == NULL) {
13229 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
13230 "wpa_supplicant monitor connection");
13231 return -1;
13232 }
13233
13234 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
13235 buf, sizeof(buf));
13236
13237 wpa_ctrl_detach(ctrl);
13238 wpa_ctrl_close(ctrl);
13239
13240 if (res < 0) {
13241 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to connect to "
13242 "network after OSU");
13243 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
13244 return 0;
13245 }
13246
13247report:
13248 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
13249 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
13250 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get BSSID/SSID");
13251 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
13252 return 0;
13253 }
13254
13255 snprintf(buf, sizeof(buf), "SSID,%s,BSSID,%s", ssid, bssid);
13256 send_resp(dut, conn, SIGMA_COMPLETE, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013257 return 0;
13258}
13259
13260
Jouni Malinenf7222712019-06-13 01:50:21 +030013261static enum sigma_cmd_result cmd_sta_policy_update(struct sigma_dut *dut,
13262 struct sigma_conn *conn,
13263 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013264{
13265 const char *val;
13266 int timeout = 120;
13267
13268 val = get_param(cmd, "PolicyUpdate");
13269 if (val == NULL || atoi(val) == 0)
13270 return 1; /* No operation requested */
13271
13272 val = get_param(cmd, "Timeout");
13273 if (val)
13274 timeout = atoi(val);
13275
13276 if (timeout) {
13277 /* TODO: time out the command and return
13278 * PolicyUpdateStatus,TIMEOUT if needed. */
13279 }
13280
13281 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger policy update");
13282 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
13283 if (run_hs20_osu(dut, "pol_upd fqdn=wi-fi.org") < 0) {
13284 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,FAIL");
13285 return 0;
13286 }
13287
13288 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,SUCCESS");
13289 return 0;
13290}
13291
13292
Jouni Malinenf7222712019-06-13 01:50:21 +030013293static enum sigma_cmd_result cmd_sta_er_config(struct sigma_dut *dut,
13294 struct sigma_conn *conn,
13295 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013296{
13297 struct wpa_ctrl *ctrl;
13298 const char *intf = get_param(cmd, "Interface");
13299 const char *bssid = get_param(cmd, "Bssid");
13300 const char *ssid = get_param(cmd, "SSID");
13301 const char *security = get_param(cmd, "Security");
13302 const char *passphrase = get_param(cmd, "Passphrase");
13303 const char *pin = get_param(cmd, "PIN");
13304 char buf[1000];
13305 char ssid_hex[200], passphrase_hex[200];
13306 const char *keymgmt, *cipher;
13307
13308 if (intf == NULL)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013309 intf = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013310
13311 if (!bssid) {
13312 send_resp(dut, conn, SIGMA_ERROR,
13313 "ErrorCode,Missing Bssid argument");
13314 return 0;
13315 }
13316
13317 if (!ssid) {
13318 send_resp(dut, conn, SIGMA_ERROR,
13319 "ErrorCode,Missing SSID argument");
13320 return 0;
13321 }
13322
13323 if (!security) {
13324 send_resp(dut, conn, SIGMA_ERROR,
13325 "ErrorCode,Missing Security argument");
13326 return 0;
13327 }
13328
13329 if (!passphrase) {
13330 send_resp(dut, conn, SIGMA_ERROR,
13331 "ErrorCode,Missing Passphrase argument");
13332 return 0;
13333 }
13334
13335 if (!pin) {
13336 send_resp(dut, conn, SIGMA_ERROR,
13337 "ErrorCode,Missing PIN argument");
13338 return 0;
13339 }
13340
vamsi krishna8c9c1562017-05-12 15:51:46 +053013341 if (2 * strlen(ssid) >= sizeof(ssid_hex) ||
13342 2 * strlen(passphrase) >= sizeof(passphrase_hex)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013343 send_resp(dut, conn, SIGMA_ERROR,
13344 "ErrorCode,Too long SSID/passphrase");
13345 return 0;
13346 }
13347
13348 ctrl = open_wpa_mon(intf);
13349 if (ctrl == NULL) {
13350 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
13351 "wpa_supplicant monitor connection");
13352 return -2;
13353 }
13354
13355 if (strcasecmp(security, "wpa2-psk") == 0) {
13356 keymgmt = "WPA2PSK";
13357 cipher = "CCMP";
13358 } else {
13359 wpa_ctrl_detach(ctrl);
13360 wpa_ctrl_close(ctrl);
13361 send_resp(dut, conn, SIGMA_ERROR,
13362 "ErrorCode,Unsupported Security value");
13363 return 0;
13364 }
13365
13366 ascii2hexstr(ssid, ssid_hex);
13367 ascii2hexstr(passphrase, passphrase_hex);
13368 snprintf(buf, sizeof(buf), "WPS_REG %s %s %s %s %s %s",
13369 bssid, pin, ssid_hex, keymgmt, cipher, passphrase_hex);
13370
13371 if (wpa_command(intf, buf) < 0) {
13372 wpa_ctrl_detach(ctrl);
13373 wpa_ctrl_close(ctrl);
13374 send_resp(dut, conn, SIGMA_ERROR,
13375 "ErrorCode,Failed to start registrar");
13376 return 0;
13377 }
13378
13379 snprintf(dut->er_oper_bssid, sizeof(dut->er_oper_bssid), "%s", bssid);
13380 dut->er_oper_performed = 1;
13381
13382 return wps_connection_event(dut, conn, ctrl, intf, 0);
13383}
13384
13385
Jouni Malinenf7222712019-06-13 01:50:21 +030013386static enum sigma_cmd_result
13387cmd_sta_wps_connect_pw_token(struct sigma_dut *dut, struct sigma_conn *conn,
13388 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013389{
13390 struct wpa_ctrl *ctrl;
13391 const char *intf = get_param(cmd, "Interface");
13392 const char *bssid = get_param(cmd, "Bssid");
13393 char buf[100];
13394
13395 if (!bssid) {
13396 send_resp(dut, conn, SIGMA_ERROR,
13397 "ErrorCode,Missing Bssid argument");
13398 return 0;
13399 }
13400
13401 ctrl = open_wpa_mon(intf);
13402 if (ctrl == NULL) {
13403 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
13404 "wpa_supplicant monitor connection");
13405 return -2;
13406 }
13407
13408 snprintf(buf, sizeof(buf), "WPS_NFC %s", bssid);
13409
13410 if (wpa_command(intf, buf) < 0) {
13411 wpa_ctrl_detach(ctrl);
13412 wpa_ctrl_close(ctrl);
13413 send_resp(dut, conn, SIGMA_ERROR,
13414 "ErrorCode,Failed to start registrar");
13415 return 0;
13416 }
13417
13418 return wps_connection_event(dut, conn, ctrl, intf, 0);
13419}
13420
13421
Jouni Malinenf7222712019-06-13 01:50:21 +030013422static enum sigma_cmd_result cmd_start_wps_registration(struct sigma_dut *dut,
13423 struct sigma_conn *conn,
13424 struct sigma_cmd *cmd)
vamsi krishna9b144002017-09-20 13:28:13 +053013425{
13426 struct wpa_ctrl *ctrl;
13427 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020013428 const char *network_mode = get_param(cmd, "network_mode");
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020013429 const char *config_method = get_param(cmd, "WPSConfigMethod");
13430 const char *role;
vamsi krishna9b144002017-09-20 13:28:13 +053013431 int res;
13432 char buf[256];
13433 const char *events[] = {
13434 "CTRL-EVENT-CONNECTED",
13435 "WPS-OVERLAP-DETECTED",
13436 "WPS-TIMEOUT",
13437 "WPS-FAIL",
13438 NULL
13439 };
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020013440 int id = 0;
vamsi krishna9b144002017-09-20 13:28:13 +053013441
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020013442 /* 60G WPS tests do not pass Interface parameter */
13443 if (!intf)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013444 intf = get_main_ifname(dut);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020013445
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020013446 if (dut->mode == SIGMA_MODE_AP)
13447 return ap_wps_registration(dut, conn, cmd);
13448
13449 if (config_method) {
13450 /* WFA_CS_WPS_PIN_KEYPAD mode is set when using the
13451 * sta_wps_enter_pin before calling start_wps_registration. */
13452 if (strcasecmp(config_method, "PBC") == 0)
13453 dut->wps_method = WFA_CS_WPS_PBC;
13454 }
13455 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
13456 send_resp(dut, conn, SIGMA_ERROR,
13457 "ErrorCode,WPS parameters not yet set");
13458 return STATUS_SENT;
13459 }
13460
13461 /* Make sure WPS is enabled (also for STA mode) */
13462 dut->wps_disable = 0;
13463
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020013464 if (dut->band == WPS_BAND_60G && network_mode &&
13465 strcasecmp(network_mode, "PBSS") == 0) {
13466 sigma_dut_print(dut, DUT_MSG_DEBUG,
13467 "Set PBSS network mode, network id %d", id);
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013468 if (set_network(get_station_ifname(dut), id, "pbss", "1") < 0)
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020013469 return -2;
13470 }
13471
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020013472 if (dut->force_rsn_ie) {
13473 sigma_dut_print(dut, DUT_MSG_DEBUG, "Force RSN_IE: %d",
13474 dut->force_rsn_ie);
13475 if (sta_60g_force_rsn_ie(dut, dut->force_rsn_ie) < 0) {
13476 sigma_dut_print(dut, DUT_MSG_INFO,
13477 "Failed to force RSN_IE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020013478 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020013479 }
13480 }
13481
vamsi krishna9b144002017-09-20 13:28:13 +053013482 ctrl = open_wpa_mon(intf);
13483 if (!ctrl) {
13484 sigma_dut_print(dut, DUT_MSG_ERROR,
13485 "Failed to open wpa_supplicant monitor connection");
13486 return -2;
13487 }
13488
13489 role = get_param(cmd, "WpsRole");
13490 if (!role) {
13491 send_resp(dut, conn, SIGMA_INVALID,
13492 "ErrorCode,WpsRole not provided");
13493 goto fail;
13494 }
13495
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020013496 if (strcasecmp(role, "Enrollee") != 0) {
13497 /* Registrar role for STA not supported */
13498 send_resp(dut, conn, SIGMA_ERROR,
13499 "ErrorCode,Unsupported WpsRole value");
13500 goto fail;
13501 }
13502
13503 if (is_60g_sigma_dut(dut)) {
13504 if (dut->wps_method == WFA_CS_WPS_PBC)
13505 snprintf(buf, sizeof(buf), "WPS_PBC");
13506 else /* WFA_CS_WPS_PIN_KEYPAD */
13507 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
13508 dut->wps_pin);
13509 if (wpa_command(intf, buf) < 0) {
13510 send_resp(dut, conn, SIGMA_ERROR,
13511 "ErrorCode,Failed to start WPS");
vamsi krishna9b144002017-09-20 13:28:13 +053013512 goto fail;
13513 }
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020013514 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
13515 if (res < 0) {
13516 send_resp(dut, conn, SIGMA_ERROR,
13517 "ErrorCode,WPS connection did not complete");
13518 goto fail;
13519 }
13520 if (strstr(buf, "WPS-TIMEOUT")) {
13521 send_resp(dut, conn, SIGMA_COMPLETE, "WpsState,NoPeer");
13522 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
13523 send_resp(dut, conn, SIGMA_COMPLETE,
13524 "WpsState,OverlapSession");
13525 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
13526 send_resp(dut, conn, SIGMA_COMPLETE,
13527 "WpsState,Successful");
13528 } else {
13529 send_resp(dut, conn, SIGMA_COMPLETE,
13530 "WpsState,Failure");
13531 }
13532 } else {
13533 if (dut->wps_method == WFA_CS_WPS_PBC) {
vamsi krishna9b144002017-09-20 13:28:13 +053013534 if (wpa_command(intf, "WPS_PBC") < 0) {
13535 send_resp(dut, conn, SIGMA_ERROR,
13536 "ErrorCode,Failed to enable PBC");
13537 goto fail;
13538 }
13539 } else {
13540 /* TODO: PIN method */
13541 send_resp(dut, conn, SIGMA_ERROR,
13542 "ErrorCode,Unsupported WpsConfigMethod value");
13543 goto fail;
13544 }
13545 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
13546 if (res < 0) {
13547 send_resp(dut, conn, SIGMA_ERROR,
13548 "ErrorCode,WPS connection did not complete");
13549 goto fail;
13550 }
13551 if (strstr(buf, "WPS-TIMEOUT")) {
13552 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,NoPeer");
13553 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
13554 send_resp(dut, conn, SIGMA_ERROR,
13555 "ErrorCode,OverlapSession");
13556 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
13557 send_resp(dut, conn, SIGMA_COMPLETE, "Successful");
13558 } else {
13559 send_resp(dut, conn, SIGMA_ERROR,
13560 "ErrorCode,WPS operation failed");
13561 }
vamsi krishna9b144002017-09-20 13:28:13 +053013562 }
13563
13564fail:
13565 wpa_ctrl_detach(ctrl);
13566 wpa_ctrl_close(ctrl);
13567 return 0;
13568}
13569
13570
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013571static int req_intf(struct sigma_cmd *cmd)
13572{
13573 return get_param(cmd, "interface") == NULL ? -1 : 0;
13574}
13575
13576
13577void sta_register_cmds(void)
13578{
13579 sigma_dut_reg_cmd("sta_get_ip_config", req_intf,
13580 cmd_sta_get_ip_config);
13581 sigma_dut_reg_cmd("sta_set_ip_config", req_intf,
13582 cmd_sta_set_ip_config);
13583 sigma_dut_reg_cmd("sta_get_info", req_intf, cmd_sta_get_info);
13584 sigma_dut_reg_cmd("sta_get_mac_address", req_intf,
13585 cmd_sta_get_mac_address);
13586 sigma_dut_reg_cmd("sta_is_connected", req_intf, cmd_sta_is_connected);
13587 sigma_dut_reg_cmd("sta_verify_ip_connection", req_intf,
13588 cmd_sta_verify_ip_connection);
13589 sigma_dut_reg_cmd("sta_get_bssid", req_intf, cmd_sta_get_bssid);
13590 sigma_dut_reg_cmd("sta_set_encryption", req_intf,
13591 cmd_sta_set_encryption);
13592 sigma_dut_reg_cmd("sta_set_psk", req_intf, cmd_sta_set_psk);
13593 sigma_dut_reg_cmd("sta_set_eaptls", req_intf, cmd_sta_set_eaptls);
13594 sigma_dut_reg_cmd("sta_set_eapttls", req_intf, cmd_sta_set_eapttls);
13595 sigma_dut_reg_cmd("sta_set_eapsim", req_intf, cmd_sta_set_eapsim);
13596 sigma_dut_reg_cmd("sta_set_peap", req_intf, cmd_sta_set_peap);
13597 sigma_dut_reg_cmd("sta_set_eapfast", req_intf, cmd_sta_set_eapfast);
13598 sigma_dut_reg_cmd("sta_set_eapaka", req_intf, cmd_sta_set_eapaka);
13599 sigma_dut_reg_cmd("sta_set_eapakaprime", req_intf,
13600 cmd_sta_set_eapakaprime);
13601 sigma_dut_reg_cmd("sta_set_security", req_intf, cmd_sta_set_security);
13602 sigma_dut_reg_cmd("sta_set_uapsd", req_intf, cmd_sta_set_uapsd);
13603 /* TODO: sta_set_ibss */
13604 /* TODO: sta_set_mode */
13605 sigma_dut_reg_cmd("sta_set_wmm", req_intf, cmd_sta_set_wmm);
13606 sigma_dut_reg_cmd("sta_associate", req_intf, cmd_sta_associate);
13607 /* TODO: sta_up_load */
13608 sigma_dut_reg_cmd("sta_preset_testparameters", req_intf,
13609 cmd_sta_preset_testparameters);
13610 /* TODO: sta_set_system */
13611 sigma_dut_reg_cmd("sta_set_11n", req_intf, cmd_sta_set_11n);
13612 /* TODO: sta_set_rifs_test */
13613 sigma_dut_reg_cmd("sta_set_wireless", req_intf, cmd_sta_set_wireless);
13614 sigma_dut_reg_cmd("sta_send_addba", req_intf, cmd_sta_send_addba);
13615 /* TODO: sta_send_coexist_mgmt */
13616 sigma_dut_reg_cmd("sta_disconnect", req_intf, cmd_sta_disconnect);
13617 sigma_dut_reg_cmd("sta_reassoc", req_intf, cmd_sta_reassoc);
13618 sigma_dut_reg_cmd("sta_reassociate", req_intf, cmd_sta_reassoc);
13619 sigma_dut_reg_cmd("sta_reset_default", req_intf,
13620 cmd_sta_reset_default);
13621 sigma_dut_reg_cmd("sta_send_frame", req_intf, cmd_sta_send_frame);
13622 sigma_dut_reg_cmd("sta_set_macaddr", req_intf, cmd_sta_set_macaddr);
13623 sigma_dut_reg_cmd("sta_set_rfeature", req_intf, cmd_sta_set_rfeature);
13624 sigma_dut_reg_cmd("sta_set_radio", req_intf, cmd_sta_set_radio);
13625 sigma_dut_reg_cmd("sta_set_pwrsave", req_intf, cmd_sta_set_pwrsave);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020013626 sigma_dut_reg_cmd("sta_set_power_save", req_intf, cmd_sta_set_pwrsave);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013627 sigma_dut_reg_cmd("sta_bssid_pool", req_intf, cmd_sta_bssid_pool);
13628 sigma_dut_reg_cmd("sta_reset_parm", req_intf, cmd_sta_reset_parm);
13629 sigma_dut_reg_cmd("sta_get_key", req_intf, cmd_sta_get_key);
13630 sigma_dut_reg_cmd("sta_hs2_associate", req_intf,
13631 cmd_sta_hs2_associate);
Jouni Malinenb639f1c2018-09-13 02:39:46 +030013632 sigma_dut_reg_cmd("sta_hs2_venue_info", req_intf,
13633 cmd_sta_hs2_venue_info);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013634 sigma_dut_reg_cmd("sta_add_credential", req_intf,
13635 cmd_sta_add_credential);
13636 sigma_dut_reg_cmd("sta_scan", req_intf, cmd_sta_scan);
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020013637 sigma_dut_reg_cmd("sta_scan_bss", req_intf, cmd_sta_scan_bss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013638 sigma_dut_reg_cmd("sta_set_systime", NULL, cmd_sta_set_systime);
13639 sigma_dut_reg_cmd("sta_osu", req_intf, cmd_sta_osu);
13640 sigma_dut_reg_cmd("sta_policy_update", req_intf, cmd_sta_policy_update);
13641 sigma_dut_reg_cmd("sta_er_config", NULL, cmd_sta_er_config);
13642 sigma_dut_reg_cmd("sta_wps_connect_pw_token", req_intf,
13643 cmd_sta_wps_connect_pw_token);
Jouni Malinen82905202018-04-29 17:20:10 +030013644 sigma_dut_reg_cmd("sta_exec_action", NULL, cmd_sta_exec_action);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013645 sigma_dut_reg_cmd("sta_get_events", req_intf, cmd_sta_get_events);
13646 sigma_dut_reg_cmd("sta_get_parameter", req_intf, cmd_sta_get_parameter);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020013647 sigma_dut_reg_cmd("start_wps_registration", NULL,
vamsi krishna9b144002017-09-20 13:28:13 +053013648 cmd_start_wps_registration);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013649}