blob: a0d08a099c860c14eb19a57848576d3537a756f0 [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 {
Veerendranath Jakkam176181c2020-05-16 00:19:21 +05301550 if (set_ipv6_addr(dut, ip, mask, ifname) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001551 send_resp(dut, conn, SIGMA_ERROR,
1552 "ErrorCode,Failed to set IPv6 address");
1553 return 0;
1554 }
1555 }
1556
1557 dut->last_set_ip_config_ipv6 = 1;
1558 static_ip_file(6, ip, mask, NULL);
1559 return 1;
1560 } else if (type == 1) {
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301561 if (!is_ip_addr(ip) || !is_ip_addr(mask))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001562 return -1;
1563 }
1564
1565 kill_dhcp_client(dut, ifname);
1566
1567 if (!dut->no_ip_addr_set) {
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301568 if (!set_ipv4_addr(dut, ifname, ip, mask)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001569 send_resp(dut, conn, SIGMA_ERROR,
1570 "ErrorCode,Failed to set IP address");
1571 return 0;
1572 }
1573 }
1574
1575 gw = get_param(cmd, "defaultGateway");
1576 if (gw) {
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301577 if (set_ipv4_gw(dut, gw) < 1) {
1578 send_resp(dut, conn, SIGMA_ERROR,
1579 "ErrorCode,Failed to set default gateway");
1580 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001581 }
1582 }
1583
1584 val = get_param(cmd, "primary-dns");
1585 if (val) {
1586 /* TODO */
1587 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored primary-dns %s "
1588 "setting", val);
1589 }
1590
1591 val = get_param(cmd, "secondary-dns");
1592 if (val) {
1593 /* TODO */
1594 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored secondary-dns %s "
1595 "setting", val);
1596 }
1597
1598 static_ip_file(4, ip, mask, gw);
1599
1600 return 1;
1601}
1602
1603
Jouni Malinenf7222712019-06-13 01:50:21 +03001604static enum sigma_cmd_result cmd_sta_get_info(struct sigma_dut *dut,
1605 struct sigma_conn *conn,
1606 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001607{
1608 /* const char *intf = get_param(cmd, "Interface"); */
1609 /* TODO: could report more details here */
1610 send_resp(dut, conn, SIGMA_COMPLETE, "vendor,Atheros");
1611 return 0;
1612}
1613
1614
Jouni Malinenf7222712019-06-13 01:50:21 +03001615static enum sigma_cmd_result cmd_sta_get_mac_address(struct sigma_dut *dut,
1616 struct sigma_conn *conn,
1617 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001618{
1619 /* const char *intf = get_param(cmd, "Interface"); */
1620 char addr[20], resp[50];
1621
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05301622 if (dut->dev_role == DEVROLE_STA_CFON)
1623 return sta_cfon_get_mac_address(dut, conn, cmd);
1624
Jouni Malinen9540e012019-11-05 17:08:42 +02001625 start_sta_mode(dut);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001626 if (get_wpa_status(get_station_ifname(dut), "address",
1627 addr, sizeof(addr)) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001628 return -2;
1629
1630 snprintf(resp, sizeof(resp), "mac,%s", addr);
1631 send_resp(dut, conn, SIGMA_COMPLETE, resp);
1632 return 0;
1633}
1634
1635
Jouni Malinenf7222712019-06-13 01:50:21 +03001636static enum sigma_cmd_result cmd_sta_is_connected(struct sigma_dut *dut,
1637 struct sigma_conn *conn,
1638 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001639{
1640 /* const char *intf = get_param(cmd, "Interface"); */
1641 int connected = 0;
1642 char result[32];
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001643 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001644 sizeof(result)) < 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001645 sigma_dut_print(dut, DUT_MSG_INFO,
1646 "Could not get interface %s status",
1647 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001648 return -2;
1649 }
1650
1651 sigma_dut_print(dut, DUT_MSG_DEBUG, "wpa_state=%s", result);
1652 if (strncmp(result, "COMPLETED", 9) == 0)
1653 connected = 1;
1654
1655 if (connected)
1656 send_resp(dut, conn, SIGMA_COMPLETE, "connected,1");
1657 else
1658 send_resp(dut, conn, SIGMA_COMPLETE, "connected,0");
1659
1660 return 0;
1661}
1662
1663
Jouni Malinenf7222712019-06-13 01:50:21 +03001664static enum sigma_cmd_result
1665cmd_sta_verify_ip_connection(struct sigma_dut *dut, struct sigma_conn *conn,
1666 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001667{
1668 /* const char *intf = get_param(cmd, "Interface"); */
1669 const char *dst, *timeout;
1670 int wait_time = 90;
1671 char buf[100];
1672 int res;
1673
1674 dst = get_param(cmd, "destination");
1675 if (dst == NULL || !is_ip_addr(dst))
1676 return -1;
1677
1678 timeout = get_param(cmd, "timeout");
1679 if (timeout) {
1680 wait_time = atoi(timeout);
1681 if (wait_time < 1)
1682 wait_time = 1;
1683 }
1684
1685 /* TODO: force renewal of IP lease if DHCP is enabled */
1686
1687 snprintf(buf, sizeof(buf), "ping %s -c 3 -W %d", dst, wait_time);
1688 res = system(buf);
1689 sigma_dut_print(dut, DUT_MSG_DEBUG, "ping returned: %d", res);
1690 if (res == 0)
1691 send_resp(dut, conn, SIGMA_COMPLETE, "connected,1");
1692 else if (res == 256)
1693 send_resp(dut, conn, SIGMA_COMPLETE, "connected,0");
1694 else
1695 return -2;
1696
1697 return 0;
1698}
1699
1700
Jouni Malinenf7222712019-06-13 01:50:21 +03001701static enum sigma_cmd_result cmd_sta_get_bssid(struct sigma_dut *dut,
1702 struct sigma_conn *conn,
1703 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001704{
1705 /* const char *intf = get_param(cmd, "Interface"); */
1706 char bssid[20], resp[50];
1707
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001708 if (get_wpa_status(get_station_ifname(dut), "bssid",
1709 bssid, sizeof(bssid)) < 0)
Peng Xub8fc5cc2017-05-10 17:27:28 -07001710 strlcpy(bssid, "00:00:00:00:00:00", sizeof(bssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001711
1712 snprintf(resp, sizeof(resp), "bssid,%s", bssid);
1713 send_resp(dut, conn, SIGMA_COMPLETE, resp);
1714 return 0;
1715}
1716
1717
1718#ifdef __SAMSUNG__
1719static int add_use_network(const char *ifname)
1720{
1721 char buf[100];
1722
1723 snprintf(buf, sizeof(buf), "USE_NETWORK ON");
1724 wpa_command(ifname, buf);
1725 return 0;
1726}
1727#endif /* __SAMSUNG__ */
1728
1729
1730static int add_network_common(struct sigma_dut *dut, struct sigma_conn *conn,
1731 const char *ifname, struct sigma_cmd *cmd)
1732{
1733 const char *ssid = get_param(cmd, "ssid");
1734 int id;
1735 const char *val;
1736
1737 if (ssid == NULL)
1738 return -1;
1739
1740 start_sta_mode(dut);
1741
1742#ifdef __SAMSUNG__
1743 add_use_network(ifname);
1744#endif /* __SAMSUNG__ */
1745
1746 id = add_network(ifname);
1747 if (id < 0)
1748 return -2;
1749 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding network %d", id);
1750
1751 if (set_network_quoted(ifname, id, "ssid", ssid) < 0)
1752 return -2;
1753
1754 dut->infra_network_id = id;
1755 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
1756
1757 val = get_param(cmd, "program");
1758 if (!val)
1759 val = get_param(cmd, "prog");
1760 if (val && strcasecmp(val, "hs2") == 0) {
1761 char buf[100];
1762 snprintf(buf, sizeof(buf), "ENABLE_NETWORK %d no-connect", id);
1763 wpa_command(ifname, buf);
1764
1765 val = get_param(cmd, "prefer");
1766 if (val && atoi(val) > 0)
1767 set_network(ifname, id, "priority", "1");
1768 }
1769
1770 return id;
1771}
1772
1773
Jouni Malinenf7222712019-06-13 01:50:21 +03001774static enum sigma_cmd_result cmd_sta_set_encryption(struct sigma_dut *dut,
1775 struct sigma_conn *conn,
1776 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001777{
1778 const char *intf = get_param(cmd, "Interface");
1779 const char *ssid = get_param(cmd, "ssid");
1780 const char *type = get_param(cmd, "encpType");
1781 const char *ifname;
1782 char buf[200];
1783 int id;
1784
1785 if (intf == NULL || ssid == NULL)
1786 return -1;
1787
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001788 if (strcmp(intf, get_main_ifname(dut)) == 0)
1789 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001790 else
1791 ifname = intf;
1792
1793 id = add_network_common(dut, conn, ifname, cmd);
1794 if (id < 0)
1795 return id;
1796
1797 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
1798 return -2;
1799
1800 if (type && strcasecmp(type, "wep") == 0) {
1801 const char *val;
1802 int i;
1803
1804 val = get_param(cmd, "activeKey");
1805 if (val) {
1806 int keyid;
1807 keyid = atoi(val);
1808 if (keyid < 1 || keyid > 4)
1809 return -1;
1810 snprintf(buf, sizeof(buf), "%d", keyid - 1);
1811 if (set_network(ifname, id, "wep_tx_keyidx", buf) < 0)
1812 return -2;
1813 }
1814
1815 for (i = 0; i < 4; i++) {
1816 snprintf(buf, sizeof(buf), "key%d", i + 1);
1817 val = get_param(cmd, buf);
1818 if (val == NULL)
1819 continue;
1820 snprintf(buf, sizeof(buf), "wep_key%d", i);
1821 if (set_network(ifname, id, buf, val) < 0)
1822 return -2;
1823 }
1824 }
1825
1826 return 1;
1827}
1828
1829
Jouni Malinene4fde732019-03-25 22:29:37 +02001830static int set_akm_suites(struct sigma_dut *dut, const char *ifname,
1831 int id, const char *val)
1832{
1833 char key_mgmt[200], *end, *pos;
1834 const char *in_pos = val;
1835
Jouni Malinen8179fee2019-03-28 03:19:47 +02001836 dut->akm_values = 0;
Jouni Malinene4fde732019-03-25 22:29:37 +02001837 pos = key_mgmt;
1838 end = pos + sizeof(key_mgmt);
1839 while (*in_pos) {
1840 int res, akm = atoi(in_pos);
1841 const char *str;
1842
Jouni Malinen8179fee2019-03-28 03:19:47 +02001843 if (akm >= 0 && akm < 32)
1844 dut->akm_values |= 1 << akm;
1845
Jouni Malinene4fde732019-03-25 22:29:37 +02001846 switch (akm) {
1847 case AKM_WPA_EAP:
1848 str = "WPA-EAP";
1849 break;
1850 case AKM_WPA_PSK:
1851 str = "WPA-PSK";
1852 break;
1853 case AKM_FT_EAP:
1854 str = "FT-EAP";
1855 break;
1856 case AKM_FT_PSK:
1857 str = "FT-PSK";
1858 break;
1859 case AKM_EAP_SHA256:
1860 str = "WPA-EAP-SHA256";
1861 break;
1862 case AKM_PSK_SHA256:
1863 str = "WPA-PSK-SHA256";
1864 break;
1865 case AKM_SAE:
1866 str = "SAE";
1867 break;
1868 case AKM_FT_SAE:
1869 str = "FT-SAE";
1870 break;
1871 case AKM_SUITE_B:
1872 str = "WPA-EAP-SUITE-B-192";
1873 break;
1874 case AKM_FT_SUITE_B:
1875 str = "FT-EAP-SHA384";
1876 break;
1877 case AKM_FILS_SHA256:
1878 str = "FILS-SHA256";
1879 break;
1880 case AKM_FILS_SHA384:
1881 str = "FILS-SHA384";
1882 break;
1883 case AKM_FT_FILS_SHA256:
1884 str = "FT-FILS-SHA256";
1885 break;
1886 case AKM_FT_FILS_SHA384:
1887 str = "FT-FILS-SHA384";
1888 break;
1889 default:
1890 sigma_dut_print(dut, DUT_MSG_ERROR,
1891 "Unsupported AKMSuitetype %d", akm);
1892 return -1;
1893 }
1894
1895 res = snprintf(pos, end - pos, "%s%s",
1896 pos == key_mgmt ? "" : " ", str);
1897 if (res < 0 || res >= end - pos)
1898 return -1;
1899 pos += res;
1900
1901 in_pos = strchr(in_pos, ';');
1902 if (!in_pos)
1903 break;
1904 while (*in_pos == ';')
1905 in_pos++;
1906 }
1907 sigma_dut_print(dut, DUT_MSG_DEBUG, "AKMSuiteType %s --> %s",
1908 val, key_mgmt);
1909 return set_network(ifname, id, "key_mgmt", key_mgmt);
1910}
1911
1912
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001913static int set_wpa_common(struct sigma_dut *dut, struct sigma_conn *conn,
1914 const char *ifname, struct sigma_cmd *cmd)
1915{
1916 const char *val;
1917 int id;
Jouni Malinenad395a22017-09-01 21:13:46 +03001918 int cipher_set = 0;
Jouni Malinen47dcc952017-10-09 16:43:24 +03001919 int owe;
Sunil Duttc75a1e62018-01-11 20:47:50 +05301920 int suite_b = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001921
1922 id = add_network_common(dut, conn, ifname, cmd);
1923 if (id < 0)
1924 return id;
1925
Jouni Malinen47dcc952017-10-09 16:43:24 +03001926 val = get_param(cmd, "Type");
1927 owe = val && strcasecmp(val, "OWE") == 0;
1928
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001929 val = get_param(cmd, "keyMgmtType");
Jouni Malinen47dcc952017-10-09 16:43:24 +03001930 if (!val && owe)
1931 val = "OWE";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001932 if (val == NULL) {
Jouni Malinene4fde732019-03-25 22:29:37 +02001933 /* keyMgmtType is being replaced with AKMSuiteType, so ignore
1934 * this missing parameter and assume proto=WPA2. */
1935 if (set_network(ifname, id, "proto", "WPA2") < 0)
1936 return ERROR_SEND_STATUS;
1937 } else if (strcasecmp(val, "wpa") == 0 ||
1938 strcasecmp(val, "wpa-psk") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001939 if (set_network(ifname, id, "proto", "WPA") < 0)
1940 return -2;
1941 } else if (strcasecmp(val, "wpa2") == 0 ||
1942 strcasecmp(val, "wpa2-psk") == 0 ||
1943 strcasecmp(val, "wpa2-ft") == 0 ||
1944 strcasecmp(val, "wpa2-sha256") == 0) {
1945 if (set_network(ifname, id, "proto", "WPA2") < 0)
1946 return -2;
Pradeep Reddy POTTETI6d04b3b2016-11-15 14:51:26 +05301947 } else if (strcasecmp(val, "wpa2-wpa-psk") == 0 ||
1948 strcasecmp(val, "wpa2-wpa-ent") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001949 if (set_network(ifname, id, "proto", "WPA WPA2") < 0)
1950 return -2;
Jouni Malinenad395a22017-09-01 21:13:46 +03001951 } else if (strcasecmp(val, "SuiteB") == 0) {
Sunil Duttc75a1e62018-01-11 20:47:50 +05301952 suite_b = 1;
Jouni Malinenad395a22017-09-01 21:13:46 +03001953 if (set_network(ifname, id, "proto", "WPA2") < 0)
1954 return -2;
Jouni Malinen47dcc952017-10-09 16:43:24 +03001955 } else if (strcasecmp(val, "OWE") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001956 } else {
1957 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized keyMgmtType value");
1958 return 0;
1959 }
1960
1961 val = get_param(cmd, "encpType");
Jouni Malinenad395a22017-09-01 21:13:46 +03001962 if (val) {
1963 cipher_set = 1;
1964 if (strcasecmp(val, "tkip") == 0) {
1965 if (set_network(ifname, id, "pairwise", "TKIP") < 0)
1966 return -2;
1967 } else if (strcasecmp(val, "aes-ccmp") == 0) {
1968 if (set_network(ifname, id, "pairwise", "CCMP") < 0)
1969 return -2;
1970 } else if (strcasecmp(val, "aes-ccmp-tkip") == 0) {
1971 if (set_network(ifname, id, "pairwise",
1972 "CCMP TKIP") < 0)
1973 return -2;
1974 } else if (strcasecmp(val, "aes-gcmp") == 0) {
1975 if (set_network(ifname, id, "pairwise", "GCMP") < 0)
1976 return -2;
1977 if (set_network(ifname, id, "group", "GCMP") < 0)
1978 return -2;
1979 } else {
1980 send_resp(dut, conn, SIGMA_ERROR,
1981 "errorCode,Unrecognized encpType value");
1982 return 0;
1983 }
1984 }
1985
1986 val = get_param(cmd, "PairwiseCipher");
1987 if (val) {
1988 cipher_set = 1;
1989 /* TODO: Support space separated list */
1990 if (strcasecmp(val, "AES-GCMP-256") == 0) {
1991 if (set_network(ifname, id, "pairwise", "GCMP-256") < 0)
1992 return -2;
1993 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
1994 if (set_network(ifname, id, "pairwise",
1995 "CCMP-256") < 0)
1996 return -2;
1997 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
1998 if (set_network(ifname, id, "pairwise", "GCMP") < 0)
1999 return -2;
2000 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
2001 if (set_network(ifname, id, "pairwise", "CCMP") < 0)
2002 return -2;
2003 } else {
2004 send_resp(dut, conn, SIGMA_ERROR,
2005 "errorCode,Unrecognized PairwiseCipher value");
2006 return 0;
2007 }
2008 }
2009
Jouni Malinen47dcc952017-10-09 16:43:24 +03002010 if (!cipher_set && !owe) {
Jouni Malinenad395a22017-09-01 21:13:46 +03002011 send_resp(dut, conn, SIGMA_ERROR,
2012 "errorCode,Missing encpType and PairwiseCipher");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002013 return 0;
2014 }
Jouni Malinenad395a22017-09-01 21:13:46 +03002015
2016 val = get_param(cmd, "GroupCipher");
2017 if (val) {
2018 if (strcasecmp(val, "AES-GCMP-256") == 0) {
2019 if (set_network(ifname, id, "group", "GCMP-256") < 0)
2020 return -2;
2021 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
2022 if (set_network(ifname, id, "group", "CCMP-256") < 0)
2023 return -2;
2024 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
2025 if (set_network(ifname, id, "group", "GCMP") < 0)
2026 return -2;
2027 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
2028 if (set_network(ifname, id, "group", "CCMP") < 0)
2029 return -2;
2030 } else {
2031 send_resp(dut, conn, SIGMA_ERROR,
2032 "errorCode,Unrecognized GroupCipher value");
2033 return 0;
2034 }
2035 }
2036
Jouni Malinen7b239522017-09-14 21:37:18 +03002037 val = get_param(cmd, "GroupMgntCipher");
Jouni Malinenad395a22017-09-01 21:13:46 +03002038 if (val) {
Jouni Malinene8898cb2017-09-26 17:55:26 +03002039 const char *cipher;
2040
2041 if (strcasecmp(val, "BIP-GMAC-256") == 0) {
2042 cipher = "BIP-GMAC-256";
2043 } else if (strcasecmp(val, "BIP-CMAC-256") == 0) {
2044 cipher = "BIP-CMAC-256";
2045 } else if (strcasecmp(val, "BIP-GMAC-128") == 0) {
2046 cipher = "BIP-GMAC-128";
2047 } else if (strcasecmp(val, "BIP-CMAC-128") == 0) {
2048 cipher = "AES-128-CMAC";
2049 } else {
2050 send_resp(dut, conn, SIGMA_INVALID,
2051 "errorCode,Unsupported GroupMgntCipher");
2052 return 0;
2053 }
2054 if (set_network(ifname, id, "group_mgmt", cipher) < 0) {
2055 send_resp(dut, conn, SIGMA_INVALID,
2056 "errorCode,Failed to set GroupMgntCipher");
2057 return 0;
2058 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002059 }
2060
Jouni Malinene4fde732019-03-25 22:29:37 +02002061 val = get_param(cmd, "AKMSuiteType");
2062 if (val && set_akm_suites(dut, ifname, id, val) < 0)
2063 return ERROR_SEND_STATUS;
2064
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002065 dut->sta_pmf = STA_PMF_DISABLED;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302066
2067 if (dut->program == PROGRAM_OCE) {
2068 dut->sta_pmf = STA_PMF_OPTIONAL;
2069 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2070 return -2;
2071 }
2072
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002073 val = get_param(cmd, "PMF");
2074 if (val) {
2075 if (strcasecmp(val, "Required") == 0 ||
2076 strcasecmp(val, "Forced_Required") == 0) {
2077 dut->sta_pmf = STA_PMF_REQUIRED;
2078 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2079 return -2;
2080 } else if (strcasecmp(val, "Optional") == 0) {
2081 dut->sta_pmf = STA_PMF_OPTIONAL;
2082 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2083 return -2;
2084 } else if (strcasecmp(val, "Disabled") == 0 ||
Kiran Kumar Lokere07da3b22018-12-16 22:42:49 -08002085 strcasecmp(val, "Disable") == 0 ||
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002086 strcasecmp(val, "Forced_Disabled") == 0) {
2087 dut->sta_pmf = STA_PMF_DISABLED;
2088 } else {
2089 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized PMF value");
2090 return 0;
2091 }
Sunil Duttc75a1e62018-01-11 20:47:50 +05302092 } else if (owe || suite_b) {
Jouni Malinen1287cd72018-01-04 17:08:01 +02002093 dut->sta_pmf = STA_PMF_REQUIRED;
2094 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2095 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002096 }
2097
Jouni Malinen0165c7f2020-03-26 11:51:58 +02002098 val = get_param(cmd, "BeaconProtection");
2099 if (val && atoi(val) == 1 &&
2100 set_network(ifname, id, "beacon_prot", "1") < 0)
2101 return ERROR_SEND_STATUS;
2102
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002103 return id;
2104}
2105
2106
Jouni Malinenf7222712019-06-13 01:50:21 +03002107static enum sigma_cmd_result cmd_sta_set_psk(struct sigma_dut *dut,
2108 struct sigma_conn *conn,
2109 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002110{
2111 const char *intf = get_param(cmd, "Interface");
Jouni Malinen992a81e2017-08-22 13:57:47 +03002112 const char *type = get_param(cmd, "Type");
Jouni Malinen1287cd72018-01-04 17:08:01 +02002113 const char *pmf = get_param(cmd, "PMF");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002114 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinene4fde732019-03-25 22:29:37 +02002115 const char *akm = get_param(cmd, "AKMSuiteType");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002116 const char *ifname, *val, *alg;
2117 int id;
Jouni Malinen4b3769d2019-10-10 16:20:29 +03002118 char buf[50];
Jouni Malinen11e55212019-11-22 21:46:59 +02002119 int sae_pwe = -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002120
2121 if (intf == NULL)
2122 return -1;
2123
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002124 if (strcmp(intf, get_main_ifname(dut)) == 0)
2125 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002126 else
2127 ifname = intf;
2128
2129 id = set_wpa_common(dut, conn, ifname, cmd);
2130 if (id < 0)
2131 return id;
2132
2133 val = get_param(cmd, "keyMgmtType");
2134 alg = get_param(cmd, "micAlg");
2135
Jouni Malinen992a81e2017-08-22 13:57:47 +03002136 if (type && strcasecmp(type, "SAE") == 0) {
Jouni Malinene4fde732019-03-25 22:29:37 +02002137 if (!akm && val && strcasecmp(val, "wpa2-ft") == 0) {
Jouni Malinen992a81e2017-08-22 13:57:47 +03002138 if (set_network(ifname, id, "key_mgmt", "FT-SAE") < 0)
2139 return -2;
Jouni Malinene4fde732019-03-25 22:29:37 +02002140 } else if (!akm) {
Jouni Malinen992a81e2017-08-22 13:57:47 +03002141 if (set_network(ifname, id, "key_mgmt", "SAE") < 0)
2142 return -2;
2143 }
2144 if (wpa_command(ifname, "SET sae_groups ") != 0) {
2145 sigma_dut_print(dut, DUT_MSG_ERROR,
2146 "Failed to clear sae_groups to default");
2147 return -2;
2148 }
Jouni Malinen1287cd72018-01-04 17:08:01 +02002149 if (!pmf) {
2150 dut->sta_pmf = STA_PMF_REQUIRED;
2151 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2152 return -2;
2153 }
Jouni Malinen0ab50f42017-08-31 01:34:59 +03002154 } else if (type && strcasecmp(type, "PSK-SAE") == 0) {
2155 if (val && strcasecmp(val, "wpa2-ft") == 0) {
2156 if (set_network(ifname, id, "key_mgmt",
2157 "FT-SAE FT-PSK") < 0)
2158 return -2;
Jouni Malinen3b73d872019-06-12 03:13:25 +03002159 } else if (!akm) {
Jouni Malinen0ab50f42017-08-31 01:34:59 +03002160 if (set_network(ifname, id, "key_mgmt",
2161 "SAE WPA-PSK") < 0)
2162 return -2;
2163 }
2164 if (wpa_command(ifname, "SET sae_groups ") != 0) {
2165 sigma_dut_print(dut, DUT_MSG_ERROR,
2166 "Failed to clear sae_groups to default");
2167 return -2;
2168 }
Jouni Malinen1287cd72018-01-04 17:08:01 +02002169 if (!pmf) {
2170 dut->sta_pmf = STA_PMF_OPTIONAL;
2171 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2172 return -2;
2173 }
Jouni Malinen992a81e2017-08-22 13:57:47 +03002174 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002175 if (set_network(ifname, id, "key_mgmt", "WPA-PSK-SHA256") < 0)
2176 return -2;
2177 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
2178 if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0)
2179 return -2;
Ashwini Patil6dbf7b02017-03-20 13:42:11 +05302180 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
2181 if (set_network(ifname, id, "key_mgmt", "FT-PSK") < 0)
2182 return -2;
Jouni Malinen3b73d872019-06-12 03:13:25 +03002183 } else if (!akm &&
2184 ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
2185 dut->sta_pmf == STA_PMF_REQUIRED)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002186 if (set_network(ifname, id, "key_mgmt",
2187 "WPA-PSK WPA-PSK-SHA256") < 0)
2188 return -2;
Jouni Malinen77ff3f02019-03-28 03:45:40 +02002189 } else if (!akm && dut->sta_pmf == STA_PMF_OPTIONAL) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002190 if (set_network(ifname, id, "key_mgmt",
2191 "WPA-PSK WPA-PSK-SHA256") < 0)
2192 return -2;
Jouni Malinen77ff3f02019-03-28 03:45:40 +02002193 } else if (!akm) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002194 if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0)
2195 return -2;
2196 }
2197
2198 val = get_param(cmd, "passPhrase");
2199 if (val == NULL)
2200 return -1;
Jouni Malinen2126f422017-10-11 23:24:33 +03002201 if (type && strcasecmp(type, "SAE") == 0) {
2202 if (set_network_quoted(ifname, id, "sae_password", val) < 0)
2203 return -2;
2204 } else {
2205 if (set_network_quoted(ifname, id, "psk", val) < 0)
2206 return -2;
2207 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002208
Jouni Malinen78d10c42019-03-25 22:34:32 +02002209 val = get_param(cmd, "PasswordId");
2210 if (val && set_network_quoted(ifname, id, "sae_password_id", val) < 0)
2211 return ERROR_SEND_STATUS;
2212
Jouni Malinen992a81e2017-08-22 13:57:47 +03002213 val = get_param(cmd, "ECGroupID");
2214 if (val) {
Jouni Malinenb54f0df2019-12-12 01:57:29 +02002215 snprintf(buf, sizeof(buf), "SET sae_groups %s", val);
Jouni Malinen992a81e2017-08-22 13:57:47 +03002216 if (wpa_command(ifname, buf) != 0) {
2217 sigma_dut_print(dut, DUT_MSG_ERROR,
2218 "Failed to clear sae_groups");
2219 return -2;
2220 }
2221 }
2222
Jouni Malinen68143132017-09-02 02:34:08 +03002223 val = get_param(cmd, "InvalidSAEElement");
2224 if (val) {
2225 free(dut->sae_commit_override);
2226 dut->sae_commit_override = strdup(val);
2227 }
2228
Jouni Malinen4b3769d2019-10-10 16:20:29 +03002229 val = get_param(cmd, "PMKID_Include");
2230 if (val) {
2231 snprintf(buf, sizeof(buf), "SET sae_pmkid_in_assoc %d",
2232 get_enable_disable(val));
2233 wpa_command(intf, buf);
2234 }
2235
Jouni Malineneeb43d32019-12-06 17:40:07 +02002236 val = get_param(cmd, "IgnoreH2E_RSNXE_BSSMemSel");
2237 if (val) {
2238 snprintf(buf, sizeof(buf), "SET ignore_sae_h2e_only %d",
2239 get_enable_disable(val));
2240 wpa_command(intf, buf);
2241 }
2242
Jouni Malinenf2348d22019-12-07 11:52:55 +02002243 val = get_param(cmd, "ECGroupID_RGE");
2244 if (val) {
2245 snprintf(buf, sizeof(buf), "SET extra_sae_rejected_groups %s",
2246 val);
2247 wpa_command(intf, buf);
2248 }
2249
Jouni Malinen99e55022019-12-07 13:59:41 +02002250 val = get_param(cmd, "RSNXE_Content");
2251 if (val) {
2252 const char *param;
2253
2254 if (strncasecmp(val, "AssocReq:", 9) == 0) {
2255 val += 9;
2256 param = "rsnxe_override_assoc";
2257 } else if (strncasecmp(val, "EapolM2:", 8) == 0) {
2258 val += 8;
2259 param = "rsnxe_override_eapol";
2260 } else {
2261 send_resp(dut, conn, SIGMA_ERROR,
2262 "errorCode,Unsupported RSNXE_Content value");
2263 return STATUS_SENT_ERROR;
2264 }
2265 snprintf(buf, sizeof(buf), "SET %s %s", param, val);
2266 wpa_command(intf, buf);
2267 }
2268
Jouni Malinen11e55212019-11-22 21:46:59 +02002269 val = get_param(cmd, "sae_pwe");
2270 if (val) {
2271 if (strcasecmp(val, "h2e") == 0) {
2272 dut->sae_pwe = SAE_PWE_H2E;
Jouni Malinen7244a412019-12-07 11:54:10 +02002273 } else if (strcasecmp(val, "loop") == 0 ||
2274 strcasecmp(val, "looping") == 0) {
Jouni Malinen11e55212019-11-22 21:46:59 +02002275 dut->sae_pwe = SAE_PWE_LOOP;
2276 } else {
2277 send_resp(dut, conn, SIGMA_ERROR,
2278 "errorCode,Unsupported sae_pwe value");
2279 return STATUS_SENT_ERROR;
2280 }
2281 }
Vinita S. Maloo6d7454f2020-04-02 15:03:26 +05302282
2283 val = get_param(cmd, "Clear_RSNXE");
2284 if (val && strcmp(val, "1") == 0 &&
2285 (wpa_command(intf, "SET rsnxe_override_assoc ") ||
2286 wpa_command(intf, "SET rsnxe_override_eapol "))) {
2287 send_resp(dut, conn, SIGMA_ERROR,
2288 "errorCode,Failed to clear RSNXE");
Jouni Malinenb11498c2020-08-03 11:05:53 +03002289 return STATUS_SENT_ERROR;
Vinita S. Maloo6d7454f2020-04-02 15:03:26 +05302290 }
2291
Jouni Malinenc0078772020-03-04 21:23:16 +02002292 if (dut->sae_pwe == SAE_PWE_LOOP && get_param(cmd, "PasswordId"))
2293 sae_pwe = 3;
2294 else if (dut->sae_pwe == SAE_PWE_LOOP)
Jouni Malinen11e55212019-11-22 21:46:59 +02002295 sae_pwe = 0;
2296 else if (dut->sae_pwe == SAE_PWE_H2E)
2297 sae_pwe = 1;
2298 else if (dut->sae_h2e_default)
2299 sae_pwe = 2;
2300 snprintf(buf, sizeof(buf), "SET sae_pwe %d", sae_pwe);
2301 if (sae_pwe >= 0 && wpa_command(ifname, buf) != 0)
2302 return ERROR_SEND_STATUS;
2303
Veerendranath Jakkam0316be12020-06-23 20:11:41 +05302304 val = get_param(cmd, "sae_pk");
2305 if (val && strcmp(val, "0") == 0 &&
2306 set_network(ifname, id, "sae_pk", "2") < 0)
2307 return ERROR_SEND_STATUS;
2308
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002309 if (dut->program == PROGRAM_60GHZ && network_mode &&
2310 strcasecmp(network_mode, "PBSS") == 0 &&
2311 set_network(ifname, id, "pbss", "1") < 0)
2312 return -2;
2313
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002314 return 1;
2315}
2316
2317
Jouni Malinen8ac93452019-08-14 15:19:13 +03002318static enum sigma_cmd_result set_trust_root_system(struct sigma_dut *dut,
2319 struct sigma_conn *conn,
2320 const char *ifname, int id)
2321{
2322 char buf[200];
2323
2324 snprintf(buf, sizeof(buf), "%s/certs", sigma_cert_path);
2325 if (!file_exists(buf))
2326 strlcpy(buf, "/system/etc/security/cacerts", sizeof(buf));
2327 if (!file_exists(buf))
2328 strlcpy(buf, "/etc/ssl/certs", sizeof(buf));
2329 if (!file_exists(buf)) {
2330 char msg[300];
2331
2332 snprintf(msg, sizeof(msg),
2333 "ErrorCode,trustedRootCA system store (%s) not found",
2334 buf);
2335 send_resp(dut, conn, SIGMA_ERROR, msg);
2336 return STATUS_SENT_ERROR;
2337 }
2338
2339 if (set_network_quoted(ifname, id, "ca_path", buf) < 0)
2340 return ERROR_SEND_STATUS;
2341
2342 return SUCCESS_SEND_STATUS;
2343}
2344
2345
2346static enum sigma_cmd_result set_trust_root(struct sigma_dut *dut,
2347 struct sigma_conn *conn,
2348 const char *ifname, int id,
2349 const char *val)
2350{
2351 char buf[200];
2352#ifdef ANDROID
2353 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
2354 int length;
2355#endif /* ANDROID */
2356
2357 if (strcmp(val, "DEFAULT") == 0)
2358 return set_trust_root_system(dut, conn, ifname, id);
2359
2360#ifdef ANDROID
2361 snprintf(buf, sizeof(buf), "CACERT_%s", val);
2362 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
2363 if (length > 0) {
2364 sigma_dut_print(dut, DUT_MSG_INFO, "Use Android keystore [%s]",
2365 buf);
2366 snprintf(buf, sizeof(buf), "keystore://CACERT_%s", val);
2367 goto ca_cert_selected;
2368 }
2369#endif /* ANDROID */
2370
2371 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
2372#ifdef __linux__
2373 if (!file_exists(buf)) {
2374 char msg[300];
2375
2376 snprintf(msg, sizeof(msg),
2377 "ErrorCode,trustedRootCA file (%s) not found", buf);
2378 send_resp(dut, conn, SIGMA_ERROR, msg);
2379 return STATUS_SENT_ERROR;
2380 }
2381#endif /* __linux__ */
2382#ifdef ANDROID
2383ca_cert_selected:
2384#endif /* ANDROID */
2385 if (set_network_quoted(ifname, id, "ca_cert", buf) < 0)
2386 return ERROR_SEND_STATUS;
2387
2388 return SUCCESS_SEND_STATUS;
2389}
2390
2391
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002392static int set_eap_common(struct sigma_dut *dut, struct sigma_conn *conn,
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302393 const char *ifname, int username_identity,
2394 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002395{
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002396 const char *val, *alg, *akm, *trust_root, *domain, *domain_suffix;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002397 int id;
Jouni Malinen53264f62019-05-03 13:04:40 +03002398 char buf[200], buf2[300];
Jouni Malinen8179fee2019-03-28 03:19:47 +02002399 int erp = 0;
Jouni Malinen8ac93452019-08-14 15:19:13 +03002400 enum sigma_cmd_result res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002401
2402 id = set_wpa_common(dut, conn, ifname, cmd);
2403 if (id < 0)
2404 return id;
2405
2406 val = get_param(cmd, "keyMgmtType");
2407 alg = get_param(cmd, "micAlg");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302408 akm = get_param(cmd, "AKMSuiteType");
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002409 trust_root = get_param(cmd, "trustedRootCA");
2410 domain = get_param(cmd, "Domain");
2411 domain_suffix = get_param(cmd, "DomainSuffix");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002412
Jouni Malinenad395a22017-09-01 21:13:46 +03002413 if (val && strcasecmp(val, "SuiteB") == 0) {
2414 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SUITE-B-192") <
2415 0)
2416 return -2;
2417 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002418 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SHA256") < 0)
2419 return -2;
2420 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
2421 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
2422 return -2;
2423 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
2424 if (set_network(ifname, id, "key_mgmt", "FT-EAP") < 0)
2425 return -2;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002426 } else if (!akm &&
2427 ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
2428 dut->sta_pmf == STA_PMF_REQUIRED)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002429 if (set_network(ifname, id, "key_mgmt",
2430 "WPA-EAP WPA-EAP-SHA256") < 0)
2431 return -2;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302432 } else if (akm && atoi(akm) == 14) {
2433 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
2434 dut->sta_pmf == STA_PMF_REQUIRED) {
2435 if (set_network(ifname, id, "key_mgmt",
2436 "WPA-EAP-SHA256 FILS-SHA256") < 0)
2437 return -2;
2438 } else {
2439 if (set_network(ifname, id, "key_mgmt",
2440 "WPA-EAP FILS-SHA256") < 0)
2441 return -2;
2442 }
2443
Jouni Malinen8179fee2019-03-28 03:19:47 +02002444 erp = 1;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302445 } else if (akm && atoi(akm) == 15) {
2446 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
2447 dut->sta_pmf == STA_PMF_REQUIRED) {
2448 if (set_network(ifname, id, "key_mgmt",
2449 "WPA-EAP-SHA256 FILS-SHA384") < 0)
2450 return -2;
2451 } else {
2452 if (set_network(ifname, id, "key_mgmt",
2453 "WPA-EAP FILS-SHA384") < 0)
2454 return -2;
2455 }
2456
Jouni Malinen8179fee2019-03-28 03:19:47 +02002457 erp = 1;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002458 } else if (!akm && dut->sta_pmf == STA_PMF_OPTIONAL) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002459 if (set_network(ifname, id, "key_mgmt",
2460 "WPA-EAP WPA-EAP-SHA256") < 0)
2461 return -2;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002462 } else if (!akm) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002463 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
2464 return -2;
2465 }
2466
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002467 if (trust_root) {
2468 if (strcmp(trust_root, "DEFAULT") == 0 && !domain &&
2469 !domain_suffix) {
2470 send_resp(dut, conn, SIGMA_ERROR,
2471 "errorCode,trustRootCA DEFAULT used without specifying Domain or DomainSuffix");
2472 return STATUS_SENT_ERROR;
2473 }
2474 res = set_trust_root(dut, conn, ifname, id, trust_root);
Jouni Malinen8ac93452019-08-14 15:19:13 +03002475 if (res != SUCCESS_SEND_STATUS)
2476 return res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002477 }
2478
Jouni Malinen53264f62019-05-03 13:04:40 +03002479 val = get_param(cmd, "ServerCert");
2480 if (val) {
2481 FILE *f;
2482 char *result = NULL, *pos;
2483
2484 snprintf(buf, sizeof(buf), "%s/%s.sha256", sigma_cert_path,
2485 val);
2486 f = fopen(buf, "r");
2487 if (f) {
2488 result = fgets(buf, sizeof(buf), f);
2489 fclose(f);
2490 }
2491 if (!result) {
2492 snprintf(buf2, sizeof(buf2),
2493 "ErrorCode,ServerCert hash could not be read from %s",
2494 buf);
2495 send_resp(dut, conn, SIGMA_ERROR, buf2);
2496 return STATUS_SENT_ERROR;
2497 }
2498 pos = strchr(buf, '\n');
2499 if (pos)
2500 *pos = '\0';
2501 snprintf(buf2, sizeof(buf2), "hash://server/sha256/%s", buf);
2502 if (set_network_quoted(ifname, id, "ca_cert", buf2) < 0)
2503 return ERROR_SEND_STATUS;
Jouni Malinen29108dc2019-06-13 23:42:11 +03002504
2505 snprintf(buf, sizeof(buf), "%s/%s.tod", sigma_cert_path, val);
2506 if (file_exists(buf)) {
2507 sigma_dut_print(dut, DUT_MSG_DEBUG,
2508 "TOD policy enabled for the configured ServerCert hash");
2509 dut->sta_tod_policy = 1;
2510 }
Jouni Malinen53264f62019-05-03 13:04:40 +03002511 }
2512
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002513 if (domain &&
2514 set_network_quoted(ifname, id, "domain_match", domain) < 0)
Jouni Malinen96f84b02019-05-03 12:32:56 +03002515 return ERROR_SEND_STATUS;
2516
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002517 if (domain_suffix &&
2518 set_network_quoted(ifname, id, "domain_suffix_match",
2519 domain_suffix) < 0)
Jouni Malinen96f84b02019-05-03 12:32:56 +03002520 return ERROR_SEND_STATUS;
2521
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302522 if (username_identity) {
2523 val = get_param(cmd, "username");
2524 if (val) {
2525 if (set_network_quoted(ifname, id, "identity", val) < 0)
2526 return -2;
2527 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002528
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302529 val = get_param(cmd, "password");
2530 if (val) {
2531 if (set_network_quoted(ifname, id, "password", val) < 0)
2532 return -2;
2533 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002534 }
2535
Jouni Malinen8179fee2019-03-28 03:19:47 +02002536 if (dut->akm_values &
2537 ((1 << AKM_FILS_SHA256) |
2538 (1 << AKM_FILS_SHA384) |
2539 (1 << AKM_FT_FILS_SHA256) |
2540 (1 << AKM_FT_FILS_SHA384)))
2541 erp = 1;
2542 if (erp && set_network(ifname, id, "erp", "1") < 0)
2543 return ERROR_SEND_STATUS;
2544
Jouni Malinen134fe3c2019-06-12 04:16:49 +03002545 dut->sta_associate_wait_connect = 1;
2546
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002547 return id;
2548}
2549
2550
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002551static int set_tls_cipher(const char *ifname, int id, const char *cipher)
2552{
2553 const char *val;
2554
2555 if (!cipher)
2556 return 0;
2557
2558 if (strcasecmp(cipher, "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384") == 0)
2559 val = "ECDHE-ECDSA-AES256-GCM-SHA384";
2560 else if (strcasecmp(cipher,
2561 "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
2562 val = "ECDHE-RSA-AES256-GCM-SHA384";
2563 else if (strcasecmp(cipher, "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
2564 val = "DHE-RSA-AES256-GCM-SHA384";
2565 else if (strcasecmp(cipher,
2566 "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256") == 0)
2567 val = "ECDHE-ECDSA-AES128-GCM-SHA256";
2568 else
2569 return -1;
2570
2571 /* Need to clear phase1="tls_suiteb=1" to allow cipher enforcement */
2572 set_network_quoted(ifname, id, "phase1", "");
2573
2574 return set_network_quoted(ifname, id, "openssl_ciphers", val);
2575}
2576
2577
Jouni Malinenf7222712019-06-13 01:50:21 +03002578static enum sigma_cmd_result cmd_sta_set_eaptls(struct sigma_dut *dut,
2579 struct sigma_conn *conn,
2580 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002581{
2582 const char *intf = get_param(cmd, "Interface");
2583 const char *ifname, *val;
2584 int id;
2585 char buf[200];
2586#ifdef ANDROID
2587 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
2588 int length;
2589 int jb_or_newer = 0;
2590 char prop[PROPERTY_VALUE_MAX];
2591#endif /* ANDROID */
2592
2593 if (intf == NULL)
2594 return -1;
2595
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002596 if (strcmp(intf, get_main_ifname(dut)) == 0)
2597 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002598 else
2599 ifname = intf;
2600
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302601 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002602 if (id < 0)
2603 return id;
2604
2605 if (set_network(ifname, id, "eap", "TLS") < 0)
2606 return -2;
2607
Pradeep Reddy POTTETI9f6c2132016-05-05 16:28:19 +05302608 if (!get_param(cmd, "username") &&
2609 set_network_quoted(ifname, id, "identity",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002610 "wifi-user@wifilabs.local") < 0)
2611 return -2;
2612
2613 val = get_param(cmd, "clientCertificate");
2614 if (val == NULL)
2615 return -1;
2616#ifdef ANDROID
2617 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2618 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
2619 if (length < 0) {
2620 /*
2621 * JB started reporting keystore type mismatches, so retry with
2622 * the GET_PUBKEY command if the generic GET fails.
2623 */
2624 length = android_keystore_get(ANDROID_KEYSTORE_GET_PUBKEY,
2625 buf, kvalue);
2626 }
2627
2628 if (property_get("ro.build.version.release", prop, NULL) != 0) {
2629 sigma_dut_print(dut, DUT_MSG_DEBUG, "Android release %s", prop);
2630 if (strncmp(prop, "4.0", 3) != 0)
2631 jb_or_newer = 1;
2632 } else
2633 jb_or_newer = 1; /* assume newer */
2634
2635 if (jb_or_newer && length > 0) {
2636 sigma_dut_print(dut, DUT_MSG_INFO,
2637 "Use Android keystore [%s]", buf);
2638 if (set_network(ifname, id, "engine", "1") < 0)
2639 return -2;
2640 if (set_network_quoted(ifname, id, "engine_id", "keystore") < 0)
2641 return -2;
2642 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2643 if (set_network_quoted(ifname, id, "key_id", buf) < 0)
2644 return -2;
2645 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2646 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2647 return -2;
2648 return 1;
2649 } else if (length > 0) {
2650 sigma_dut_print(dut, DUT_MSG_INFO,
2651 "Use Android keystore [%s]", buf);
2652 snprintf(buf, sizeof(buf), "keystore://USRPKEY_%s", val);
2653 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2654 return -2;
2655 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2656 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2657 return -2;
2658 return 1;
2659 }
2660#endif /* ANDROID */
2661
2662 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
2663#ifdef __linux__
2664 if (!file_exists(buf)) {
2665 char msg[300];
2666 snprintf(msg, sizeof(msg), "ErrorCode,clientCertificate file "
2667 "(%s) not found", buf);
2668 send_resp(dut, conn, SIGMA_ERROR, msg);
2669 return -3;
2670 }
2671#endif /* __linux__ */
2672 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2673 return -2;
2674 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2675 return -2;
2676
2677 if (set_network_quoted(ifname, id, "private_key_passwd", "wifi") < 0)
2678 return -2;
2679
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002680 val = get_param(cmd, "keyMgmtType");
2681 if (val && strcasecmp(val, "SuiteB") == 0) {
2682 val = get_param(cmd, "CertType");
2683 if (val && strcasecmp(val, "RSA") == 0) {
2684 if (set_network_quoted(ifname, id, "phase1",
2685 "tls_suiteb=1") < 0)
2686 return -2;
2687 } else {
2688 if (set_network_quoted(ifname, id, "openssl_ciphers",
2689 "SUITEB192") < 0)
2690 return -2;
2691 }
2692
2693 val = get_param(cmd, "TLSCipher");
2694 if (set_tls_cipher(ifname, id, val) < 0) {
2695 send_resp(dut, conn, SIGMA_ERROR,
2696 "ErrorCode,Unsupported TLSCipher value");
2697 return -3;
2698 }
2699 }
2700
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002701 return 1;
2702}
2703
2704
Jouni Malinenf7222712019-06-13 01:50:21 +03002705static enum sigma_cmd_result cmd_sta_set_eapttls(struct sigma_dut *dut,
2706 struct sigma_conn *conn,
2707 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002708{
2709 const char *intf = get_param(cmd, "Interface");
2710 const char *ifname;
2711 int id;
2712
2713 if (intf == NULL)
2714 return -1;
2715
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002716 if (strcmp(intf, get_main_ifname(dut)) == 0)
2717 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002718 else
2719 ifname = intf;
2720
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302721 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002722 if (id < 0)
2723 return id;
2724
2725 if (set_network(ifname, id, "eap", "TTLS") < 0) {
2726 send_resp(dut, conn, SIGMA_ERROR,
2727 "errorCode,Failed to set TTLS method");
2728 return 0;
2729 }
2730
2731 if (set_network_quoted(ifname, id, "phase2", "auth=MSCHAPV2") < 0) {
2732 send_resp(dut, conn, SIGMA_ERROR,
2733 "errorCode,Failed to set MSCHAPv2 for TTLS Phase 2");
2734 return 0;
2735 }
2736
2737 return 1;
2738}
2739
2740
Jouni Malinenf7222712019-06-13 01:50:21 +03002741static enum sigma_cmd_result cmd_sta_set_eapsim(struct sigma_dut *dut,
2742 struct sigma_conn *conn,
2743 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002744{
2745 const char *intf = get_param(cmd, "Interface");
2746 const char *ifname;
2747 int id;
2748
2749 if (intf == NULL)
2750 return -1;
2751
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002752 if (strcmp(intf, get_main_ifname(dut)) == 0)
2753 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002754 else
2755 ifname = intf;
2756
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302757 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002758 if (id < 0)
2759 return id;
2760
2761 if (set_network(ifname, id, "eap", "SIM") < 0)
2762 return -2;
2763
2764 return 1;
2765}
2766
2767
Jouni Malinenf7222712019-06-13 01:50:21 +03002768static enum sigma_cmd_result cmd_sta_set_peap(struct sigma_dut *dut,
2769 struct sigma_conn *conn,
2770 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002771{
2772 const char *intf = get_param(cmd, "Interface");
2773 const char *ifname, *val;
2774 int id;
2775 char buf[100];
2776
2777 if (intf == NULL)
2778 return -1;
2779
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002780 if (strcmp(intf, get_main_ifname(dut)) == 0)
2781 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002782 else
2783 ifname = intf;
2784
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302785 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002786 if (id < 0)
2787 return id;
2788
2789 if (set_network(ifname, id, "eap", "PEAP") < 0)
2790 return -2;
2791
2792 val = get_param(cmd, "innerEAP");
2793 if (val) {
2794 if (strcasecmp(val, "MSCHAPv2") == 0) {
2795 if (set_network_quoted(ifname, id, "phase2",
2796 "auth=MSCHAPV2") < 0)
2797 return -2;
2798 } else if (strcasecmp(val, "GTC") == 0) {
2799 if (set_network_quoted(ifname, id, "phase2",
2800 "auth=GTC") < 0)
2801 return -2;
2802 } else
2803 return -1;
2804 }
2805
2806 val = get_param(cmd, "peapVersion");
2807 if (val) {
2808 int ver = atoi(val);
2809 if (ver < 0 || ver > 1)
2810 return -1;
2811 snprintf(buf, sizeof(buf), "peapver=%d", ver);
2812 if (set_network_quoted(ifname, id, "phase1", buf) < 0)
2813 return -2;
2814 }
2815
2816 return 1;
2817}
2818
2819
Jouni Malinenf7222712019-06-13 01:50:21 +03002820static enum sigma_cmd_result cmd_sta_set_eapfast(struct sigma_dut *dut,
2821 struct sigma_conn *conn,
2822 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002823{
2824 const char *intf = get_param(cmd, "Interface");
2825 const char *ifname, *val;
2826 int id;
2827 char buf[100];
2828
2829 if (intf == NULL)
2830 return -1;
2831
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002832 if (strcmp(intf, get_main_ifname(dut)) == 0)
2833 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002834 else
2835 ifname = intf;
2836
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302837 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002838 if (id < 0)
2839 return id;
2840
2841 if (set_network(ifname, id, "eap", "FAST") < 0)
2842 return -2;
2843
2844 val = get_param(cmd, "innerEAP");
2845 if (val) {
2846 if (strcasecmp(val, "MSCHAPV2") == 0) {
2847 if (set_network_quoted(ifname, id, "phase2",
2848 "auth=MSCHAPV2") < 0)
2849 return -2;
2850 } else if (strcasecmp(val, "GTC") == 0) {
2851 if (set_network_quoted(ifname, id, "phase2",
2852 "auth=GTC") < 0)
2853 return -2;
2854 } else
2855 return -1;
2856 }
2857
2858 val = get_param(cmd, "validateServer");
2859 if (val) {
2860 /* TODO */
2861 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored EAP-FAST "
2862 "validateServer=%s", val);
2863 }
2864
2865 val = get_param(cmd, "pacFile");
2866 if (val) {
2867 snprintf(buf, sizeof(buf), "blob://%s", val);
2868 if (set_network_quoted(ifname, id, "pac_file", buf) < 0)
2869 return -2;
2870 }
2871
2872 if (set_network_quoted(ifname, id, "phase1", "fast_provisioning=2") <
2873 0)
2874 return -2;
2875
2876 return 1;
2877}
2878
2879
Jouni Malinenf7222712019-06-13 01:50:21 +03002880static enum sigma_cmd_result cmd_sta_set_eapaka(struct sigma_dut *dut,
2881 struct sigma_conn *conn,
2882 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002883{
2884 const char *intf = get_param(cmd, "Interface");
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302885 const char *username = get_param(cmd, "Username");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002886 const char *ifname;
2887 int id;
2888
2889 if (intf == NULL)
2890 return -1;
2891
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002892 if (strcmp(intf, get_main_ifname(dut)) == 0)
2893 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002894 else
2895 ifname = intf;
2896
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302897 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002898 if (id < 0)
2899 return id;
2900
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302901 /* RFC 5448: EAP-AKA' MUST use the leading character "6" (ASCII 36
2902 * hexadecimal).
2903 */
2904 if (username && username[0] == '6') {
2905 if (set_network(ifname, id, "eap", "AKA'") < 0)
2906 return -2;
2907 } else if (set_network(ifname, id, "eap", "AKA") < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002908 return -2;
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302909 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002910
2911 return 1;
2912}
2913
2914
Jouni Malinenf7222712019-06-13 01:50:21 +03002915static enum sigma_cmd_result cmd_sta_set_eapakaprime(struct sigma_dut *dut,
2916 struct sigma_conn *conn,
2917 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002918{
2919 const char *intf = get_param(cmd, "Interface");
2920 const char *ifname;
2921 int id;
2922
2923 if (intf == NULL)
2924 return -1;
2925
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002926 if (strcmp(intf, get_main_ifname(dut)) == 0)
2927 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002928 else
2929 ifname = intf;
2930
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302931 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002932 if (id < 0)
2933 return id;
2934
2935 if (set_network(ifname, id, "eap", "AKA'") < 0)
2936 return -2;
2937
2938 return 1;
2939}
2940
2941
2942static int sta_set_open(struct sigma_dut *dut, struct sigma_conn *conn,
2943 struct sigma_cmd *cmd)
2944{
2945 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002946 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002947 const char *ifname;
2948 int id;
2949
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002950 if (strcmp(intf, get_main_ifname(dut)) == 0)
2951 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002952 else
2953 ifname = intf;
2954
2955 id = add_network_common(dut, conn, ifname, cmd);
2956 if (id < 0)
2957 return id;
2958
2959 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
2960 return -2;
2961
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002962 if (dut->program == PROGRAM_60GHZ && network_mode &&
2963 strcasecmp(network_mode, "PBSS") == 0 &&
2964 set_network(ifname, id, "pbss", "1") < 0)
2965 return -2;
2966
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002967 return 1;
2968}
2969
2970
Jouni Malinen47dcc952017-10-09 16:43:24 +03002971static int sta_set_owe(struct sigma_dut *dut, struct sigma_conn *conn,
2972 struct sigma_cmd *cmd)
2973{
2974 const char *intf = get_param(cmd, "Interface");
2975 const char *ifname, *val;
2976 int id;
2977
2978 if (intf == NULL)
2979 return -1;
2980
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002981 if (strcmp(intf, get_main_ifname(dut)) == 0)
2982 ifname = get_station_ifname(dut);
Jouni Malinen47dcc952017-10-09 16:43:24 +03002983 else
2984 ifname = intf;
2985
2986 id = set_wpa_common(dut, conn, ifname, cmd);
2987 if (id < 0)
2988 return id;
2989
2990 if (set_network(ifname, id, "key_mgmt", "OWE") < 0)
2991 return -2;
2992
2993 val = get_param(cmd, "ECGroupID");
Jouni Malinenfac9cad2017-10-10 18:35:55 +03002994 if (val && strcmp(val, "0") == 0) {
2995 if (wpa_command(ifname,
2996 "VENDOR_ELEM_ADD 13 ff23200000783590fb7440e03d5b3b33911f86affdcc6b4411b707846ac4ff08ddc8831ccd") != 0) {
2997 sigma_dut_print(dut, DUT_MSG_ERROR,
2998 "Failed to set OWE DH Param element override");
2999 return -2;
3000 }
Hu Wang6010ce72020-03-05 19:33:53 +08003001 } else if (val &&
3002 (set_network(ifname, id, "owe_group", val) < 0 ||
3003 (dut->owe_ptk_workaround &&
3004 set_network(ifname, id, "owe_ptk_workaround", "1") < 0))) {
Jouni Malinen47dcc952017-10-09 16:43:24 +03003005 sigma_dut_print(dut, DUT_MSG_ERROR,
Hu Wang6010ce72020-03-05 19:33:53 +08003006 "Failed to set owe_group");
Jouni Malinen47dcc952017-10-09 16:43:24 +03003007 return -2;
3008 }
3009
3010 return 1;
3011}
3012
3013
Jouni Malinenf7222712019-06-13 01:50:21 +03003014static enum sigma_cmd_result cmd_sta_set_security(struct sigma_dut *dut,
3015 struct sigma_conn *conn,
3016 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003017{
3018 const char *type = get_param(cmd, "Type");
3019
3020 if (type == NULL) {
3021 send_resp(dut, conn, SIGMA_ERROR,
3022 "ErrorCode,Missing Type argument");
3023 return 0;
3024 }
3025
3026 if (strcasecmp(type, "OPEN") == 0)
3027 return sta_set_open(dut, conn, cmd);
Jouni Malinen47dcc952017-10-09 16:43:24 +03003028 if (strcasecmp(type, "OWE") == 0)
3029 return sta_set_owe(dut, conn, cmd);
Jouni Malinen992a81e2017-08-22 13:57:47 +03003030 if (strcasecmp(type, "PSK") == 0 ||
Jouni Malinen0ab50f42017-08-31 01:34:59 +03003031 strcasecmp(type, "PSK-SAE") == 0 ||
Jouni Malinen992a81e2017-08-22 13:57:47 +03003032 strcasecmp(type, "SAE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003033 return cmd_sta_set_psk(dut, conn, cmd);
3034 if (strcasecmp(type, "EAPTLS") == 0)
3035 return cmd_sta_set_eaptls(dut, conn, cmd);
3036 if (strcasecmp(type, "EAPTTLS") == 0)
3037 return cmd_sta_set_eapttls(dut, conn, cmd);
3038 if (strcasecmp(type, "EAPPEAP") == 0)
3039 return cmd_sta_set_peap(dut, conn, cmd);
3040 if (strcasecmp(type, "EAPSIM") == 0)
3041 return cmd_sta_set_eapsim(dut, conn, cmd);
3042 if (strcasecmp(type, "EAPFAST") == 0)
3043 return cmd_sta_set_eapfast(dut, conn, cmd);
3044 if (strcasecmp(type, "EAPAKA") == 0)
3045 return cmd_sta_set_eapaka(dut, conn, cmd);
3046 if (strcasecmp(type, "EAPAKAPRIME") == 0)
3047 return cmd_sta_set_eapakaprime(dut, conn, cmd);
Amarnath Hullur Subramanyam81b11cd2018-01-30 19:07:17 -08003048 if (strcasecmp(type, "wep") == 0)
3049 return cmd_sta_set_encryption(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003050
3051 send_resp(dut, conn, SIGMA_ERROR,
3052 "ErrorCode,Unsupported Type value");
3053 return 0;
3054}
3055
3056
3057int ath6kl_client_uapsd(struct sigma_dut *dut, const char *intf, int uapsd)
3058{
3059#ifdef __linux__
3060 /* special handling for ath6kl */
3061 char path[128], fname[128], *pos;
3062 ssize_t res;
3063 FILE *f;
3064
Jouni Malinene39cd562019-05-29 23:39:56 +03003065 res = snprintf(fname, sizeof(fname), "/sys/class/net/%s/phy80211",
3066 intf);
3067 if (res < 0 || res >= sizeof(fname))
3068 return 0;
3069 res = readlink(fname, path, sizeof(path));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003070 if (res < 0)
3071 return 0; /* not ath6kl */
3072
3073 if (res >= (int) sizeof(path))
3074 res = sizeof(path) - 1;
3075 path[res] = '\0';
3076 pos = strrchr(path, '/');
3077 if (pos == NULL)
3078 pos = path;
3079 else
3080 pos++;
Jouni Malinen77dda642020-01-07 11:21:55 +02003081 res = snprintf(fname, sizeof(fname),
3082 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
3083 "create_qos", pos);
3084 if (res < 0 || res >= sizeof(fname) || !file_exists(fname))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003085 return 0; /* not ath6kl */
3086
3087 if (uapsd) {
3088 f = fopen(fname, "w");
3089 if (f == NULL)
3090 return -1;
3091
3092 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl create_qos");
3093 fprintf(f, "4 2 2 1 2 9999999 9999999 9999999 7777777 0 4 "
3094 "45000 200 56789000 56789000 5678900 0 0 9999999 "
3095 "20000 0\n");
3096 fclose(f);
3097 } else {
Jouni Malinen77dda642020-01-07 11:21:55 +02003098 res = snprintf(fname, sizeof(fname),
3099 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
3100 "delete_qos", pos);
3101 if (res < 0 || res >= sizeof(fname))
3102 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003103
3104 f = fopen(fname, "w");
3105 if (f == NULL)
3106 return -1;
3107
3108 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl delete_qos");
3109 fprintf(f, "2 4\n");
3110 fclose(f);
3111 }
3112#endif /* __linux__ */
3113
3114 return 0;
3115}
3116
3117
Jouni Malinenf7222712019-06-13 01:50:21 +03003118static enum sigma_cmd_result cmd_sta_set_uapsd(struct sigma_dut *dut,
3119 struct sigma_conn *conn,
3120 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003121{
3122 const char *intf = get_param(cmd, "Interface");
3123 /* const char *ssid = get_param(cmd, "ssid"); */
3124 const char *val;
3125 int max_sp_len = 4;
3126 int ac_be = 1, ac_bk = 1, ac_vi = 1, ac_vo = 1;
3127 char buf[100];
3128 int ret1, ret2;
3129
3130 val = get_param(cmd, "maxSPLength");
3131 if (val) {
3132 max_sp_len = atoi(val);
3133 if (max_sp_len != 0 && max_sp_len != 1 && max_sp_len != 2 &&
3134 max_sp_len != 4)
3135 return -1;
3136 }
3137
3138 val = get_param(cmd, "acBE");
3139 if (val)
3140 ac_be = atoi(val);
3141
3142 val = get_param(cmd, "acBK");
3143 if (val)
3144 ac_bk = atoi(val);
3145
3146 val = get_param(cmd, "acVI");
3147 if (val)
3148 ac_vi = atoi(val);
3149
3150 val = get_param(cmd, "acVO");
3151 if (val)
3152 ac_vo = atoi(val);
3153
3154 dut->client_uapsd = ac_be || ac_bk || ac_vi || ac_vo;
3155
3156 snprintf(buf, sizeof(buf), "P2P_SET client_apsd %d,%d,%d,%d;%d",
3157 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
3158 ret1 = wpa_command(intf, buf);
3159
3160 snprintf(buf, sizeof(buf), "SET uapsd %d,%d,%d,%d;%d",
3161 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
3162 ret2 = wpa_command(intf, buf);
3163
3164 if (ret1 && ret2) {
3165 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to set client mode "
3166 "UAPSD parameters.");
3167 return -2;
3168 }
3169
3170 if (ath6kl_client_uapsd(dut, intf, dut->client_uapsd) < 0) {
3171 send_resp(dut, conn, SIGMA_ERROR,
3172 "ErrorCode,Failed to set ath6kl QoS parameters");
3173 return 0;
3174 }
3175
3176 return 1;
3177}
3178
3179
Jouni Malinenf7222712019-06-13 01:50:21 +03003180static enum sigma_cmd_result cmd_sta_set_wmm(struct sigma_dut *dut,
3181 struct sigma_conn *conn,
3182 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003183{
3184 char buf[1000];
3185 const char *intf = get_param(cmd, "Interface");
3186 const char *grp = get_param(cmd, "Group");
3187 const char *act = get_param(cmd, "Action");
3188 const char *tid = get_param(cmd, "Tid");
3189 const char *dir = get_param(cmd, "Direction");
3190 const char *psb = get_param(cmd, "Psb");
3191 const char *up = get_param(cmd, "Up");
3192 const char *fixed = get_param(cmd, "Fixed");
3193 const char *size = get_param(cmd, "Size");
3194 const char *msize = get_param(cmd, "Maxsize");
3195 const char *minsi = get_param(cmd, "Min_srvc_intrvl");
3196 const char *maxsi = get_param(cmd, "Max_srvc_intrvl");
3197 const char *inact = get_param(cmd, "Inactivity");
3198 const char *sus = get_param(cmd, "Suspension");
3199 const char *mindr = get_param(cmd, "Mindatarate");
3200 const char *meandr = get_param(cmd, "Meandatarate");
3201 const char *peakdr = get_param(cmd, "Peakdatarate");
3202 const char *phyrate = get_param(cmd, "Phyrate");
3203 const char *burstsize = get_param(cmd, "Burstsize");
3204 const char *sba = get_param(cmd, "Sba");
3205 int direction;
3206 int handle;
Peng Xu93319622017-10-04 17:58:16 -07003207 float sba_fv = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003208 int fixed_int;
3209 int psb_ts;
3210
3211 if (intf == NULL || grp == NULL || act == NULL )
3212 return -1;
3213
3214 if (strcasecmp(act, "addts") == 0) {
3215 if (tid == NULL || dir == NULL || psb == NULL ||
3216 up == NULL || fixed == NULL || size == NULL)
3217 return -1;
3218
3219 /*
3220 * Note: Sigma CAPI spec lists uplink, downlink, and bidi as the
3221 * possible values, but WMM-AC and V-E test scripts use "UP,
3222 * "DOWN", and "BIDI".
3223 */
3224 if (strcasecmp(dir, "uplink") == 0 ||
3225 strcasecmp(dir, "up") == 0) {
3226 direction = 0;
3227 } else if (strcasecmp(dir, "downlink") == 0 ||
3228 strcasecmp(dir, "down") == 0) {
3229 direction = 1;
3230 } else if (strcasecmp(dir, "bidi") == 0) {
3231 direction = 2;
3232 } else {
3233 sigma_dut_print(dut, DUT_MSG_ERROR,
3234 "Direction %s not supported", dir);
3235 return -1;
3236 }
3237
3238 if (strcasecmp(psb, "legacy") == 0) {
3239 psb_ts = 0;
3240 } else if (strcasecmp(psb, "uapsd") == 0) {
3241 psb_ts = 1;
3242 } else {
3243 sigma_dut_print(dut, DUT_MSG_ERROR,
3244 "PSB %s not supported", psb);
3245 return -1;
3246 }
3247
3248 if (atoi(tid) < 0 || atoi(tid) > 7) {
3249 sigma_dut_print(dut, DUT_MSG_ERROR,
3250 "TID %s not supported", tid);
3251 return -1;
3252 }
3253
3254 if (strcasecmp(fixed, "true") == 0) {
3255 fixed_int = 1;
3256 } else {
3257 fixed_int = 0;
3258 }
3259
Peng Xu93319622017-10-04 17:58:16 -07003260 if (sba)
3261 sba_fv = atof(sba);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003262
3263 dut->dialog_token++;
3264 handle = 7000 + dut->dialog_token;
3265
3266 /*
3267 * size: convert to hex
3268 * maxsi: convert to hex
3269 * mindr: convert to hex
3270 * meandr: convert to hex
3271 * peakdr: convert to hex
3272 * burstsize: convert to hex
3273 * phyrate: convert to hex
3274 * sba: convert to hex with modification
3275 * minsi: convert to integer
3276 * sus: convert to integer
3277 * inact: convert to integer
3278 * maxsi: convert to integer
3279 */
3280
3281 /*
3282 * The Nominal MSDU Size field is 2 octets long and contains an
3283 * unsigned integer that specifies the nominal size, in octets,
3284 * of MSDUs belonging to the traffic under this traffic
3285 * specification and is defined in Figure 16. If the Fixed
3286 * subfield is set to 1, then the size of the MSDU is fixed and
3287 * is indicated by the Size Subfield. If the Fixed subfield is
3288 * set to 0, then the size of the MSDU might not be fixed and
3289 * the Size indicates the nominal MSDU size.
3290 *
3291 * The Surplus Bandwidth Allowance Factor field is 2 octets long
3292 * and specifies the excess allocation of time (and bandwidth)
3293 * over and above the stated rates required to transport an MSDU
3294 * belonging to the traffic in this TSPEC. This field is
3295 * represented as an unsigned binary number with an implicit
3296 * binary point after the leftmost 3 bits. For example, an SBA
3297 * of 1.75 is represented as 0x3800. This field is included to
3298 * account for retransmissions. As such, the value of this field
3299 * must be greater than unity.
3300 */
3301
3302 snprintf(buf, sizeof(buf),
3303 "iwpriv %s addTspec %d %s %d %d %s 0x%X"
3304 " 0x%X 0x%X 0x%X"
3305 " 0x%X 0x%X 0x%X"
3306 " 0x%X %d %d %d %d"
3307 " %d %d",
3308 intf, handle, tid, direction, psb_ts, up,
3309 (unsigned int) ((fixed_int << 15) | atoi(size)),
3310 msize ? atoi(msize) : 0,
3311 mindr ? atoi(mindr) : 0,
3312 meandr ? atoi(meandr) : 0,
3313 peakdr ? atoi(peakdr) : 0,
3314 burstsize ? atoi(burstsize) : 0,
3315 phyrate ? atoi(phyrate) : 0,
3316 sba ? ((unsigned int) (((int) sba_fv << 13) |
3317 (int)((sba_fv - (int) sba_fv) *
3318 8192))) : 0,
3319 minsi ? atoi(minsi) : 0,
3320 sus ? atoi(sus) : 0,
3321 0, 0,
3322 inact ? atoi(inact) : 0,
3323 maxsi ? atoi(maxsi) : 0);
3324
3325 if (system(buf) != 0) {
3326 sigma_dut_print(dut, DUT_MSG_ERROR,
3327 "iwpriv addtspec request failed");
3328 send_resp(dut, conn, SIGMA_ERROR,
3329 "errorCode,Failed to execute addTspec command");
3330 return 0;
3331 }
3332
3333 sigma_dut_print(dut, DUT_MSG_INFO,
3334 "iwpriv addtspec request send");
3335
3336 /* Mapping handle to a TID */
3337 dut->tid_to_handle[atoi(tid)] = handle;
3338 } else if (strcasecmp(act, "delts") == 0) {
3339 if (tid == NULL)
3340 return -1;
3341
3342 if (atoi(tid) < 0 || atoi(tid) > 7) {
3343 sigma_dut_print(dut, DUT_MSG_ERROR,
3344 "TID %s not supported", tid);
3345 send_resp(dut, conn, SIGMA_ERROR,
3346 "errorCode,Unsupported TID");
3347 return 0;
3348 }
3349
3350 handle = dut->tid_to_handle[atoi(tid)];
3351
3352 if (handle < 7000 || handle > 7255) {
3353 /* Invalid handle ie no mapping for that TID */
3354 sigma_dut_print(dut, DUT_MSG_ERROR,
3355 "handle-> %d not found", handle);
3356 }
3357
3358 snprintf(buf, sizeof(buf), "iwpriv %s delTspec %d",
3359 intf, handle);
3360
3361 if (system(buf) != 0) {
3362 sigma_dut_print(dut, DUT_MSG_ERROR,
3363 "iwpriv deltspec request failed");
3364 send_resp(dut, conn, SIGMA_ERROR,
3365 "errorCode,Failed to execute delTspec command");
3366 return 0;
3367 }
3368
3369 sigma_dut_print(dut, DUT_MSG_INFO,
3370 "iwpriv deltspec request send");
3371
3372 dut->tid_to_handle[atoi(tid)] = 0;
3373 } else {
3374 sigma_dut_print(dut, DUT_MSG_ERROR,
3375 "Action type %s not supported", act);
3376 send_resp(dut, conn, SIGMA_ERROR,
3377 "errorCode,Unsupported Action");
3378 return 0;
3379 }
3380
3381 return 1;
3382}
3383
3384
vamsi krishna52e16f92017-08-29 12:37:34 +05303385static int find_network(struct sigma_dut *dut, const char *ssid)
3386{
3387 char list[4096];
3388 char *pos;
3389
3390 sigma_dut_print(dut, DUT_MSG_DEBUG,
3391 "Search for profile based on SSID: '%s'", ssid);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003392 if (wpa_command_resp(get_station_ifname(dut), "LIST_NETWORKS",
vamsi krishna52e16f92017-08-29 12:37:34 +05303393 list, sizeof(list)) < 0)
3394 return -1;
3395 pos = strstr(list, ssid);
3396 if (!pos || pos == list || pos[-1] != '\t' || pos[strlen(ssid)] != '\t')
3397 return -1;
3398
3399 while (pos > list && pos[-1] != '\n')
3400 pos--;
3401 dut->infra_network_id = atoi(pos);
3402 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
3403 return 0;
3404}
3405
3406
Sunil Dutt44595082018-02-12 19:41:45 +05303407#ifdef NL80211_SUPPORT
3408static int sta_config_rsnie(struct sigma_dut *dut, int val)
3409{
3410 struct nl_msg *msg;
3411 int ret;
3412 struct nlattr *params;
3413 int ifindex;
3414
3415 ifindex = if_nametoindex("wlan0");
3416 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
3417 NL80211_CMD_VENDOR)) ||
3418 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
3419 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
3420 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
3421 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) ||
3422 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
3423 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE, val)) {
3424 sigma_dut_print(dut, DUT_MSG_ERROR,
3425 "%s: err in adding vendor_cmd and vendor_data",
3426 __func__);
3427 nlmsg_free(msg);
3428 return -1;
3429 }
3430 nla_nest_end(msg, params);
3431
3432 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
3433 if (ret) {
3434 sigma_dut_print(dut, DUT_MSG_ERROR,
3435 "%s: err in send_and_recv_msgs, ret=%d",
3436 __func__, ret);
3437 return ret;
3438 }
3439
3440 return 0;
3441}
3442#endif /* NL80211_SUPPORT */
3443
3444
Jouni Malinenf7222712019-06-13 01:50:21 +03003445static enum sigma_cmd_result cmd_sta_associate(struct sigma_dut *dut,
3446 struct sigma_conn *conn,
3447 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003448{
3449 /* const char *intf = get_param(cmd, "Interface"); */
3450 const char *ssid = get_param(cmd, "ssid");
3451 const char *wps_param = get_param(cmd, "WPS");
3452 const char *bssid = get_param(cmd, "bssid");
Jouni Malinen46a19b62017-06-23 14:31:27 +03003453 const char *chan = get_param(cmd, "channel");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003454 const char *network_mode = get_param(cmd, "network_mode");
Veerendranath Jakkama082e342020-05-16 00:19:21 +05303455 const char *ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003456 int wps = 0;
Jouni Malinen3c367e82017-06-23 17:01:47 +03003457 char buf[1000], extra[50];
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003458 int e;
3459 enum sigma_cmd_result ret = SUCCESS_SEND_STATUS;
3460 struct wpa_ctrl *ctrl = NULL;
3461 int num_network_not_found = 0;
3462 int num_disconnected = 0;
3463 int tod = -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003464
3465 if (ssid == NULL)
3466 return -1;
3467
Jouni Malinen37d5c692019-08-19 16:56:55 +03003468 dut->server_cert_tod = 0;
3469
Jouni Malinen3c367e82017-06-23 17:01:47 +03003470 if (dut->rsne_override) {
Sunil Dutt44595082018-02-12 19:41:45 +05303471#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003472 if (get_driver_type(dut) == DRIVER_WCN) {
Sunil Dutt44595082018-02-12 19:41:45 +05303473 sta_config_rsnie(dut, 1);
3474 dut->config_rsnie = 1;
3475 }
3476#endif /* NL80211_SUPPORT */
Jouni Malinen3c367e82017-06-23 17:01:47 +03003477 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
3478 dut->rsne_override);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003479 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinen3c367e82017-06-23 17:01:47 +03003480 send_resp(dut, conn, SIGMA_ERROR,
3481 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
3482 return 0;
3483 }
3484 }
3485
Jouni Malinen68143132017-09-02 02:34:08 +03003486 if (dut->sae_commit_override) {
3487 snprintf(buf, sizeof(buf), "SET sae_commit_override %s",
3488 dut->sae_commit_override);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003489 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinen68143132017-09-02 02:34:08 +03003490 send_resp(dut, conn, SIGMA_ERROR,
3491 "ErrorCode,Failed to set SAE commit override");
3492 return 0;
3493 }
3494 }
Ankita Bajaj1bde7942018-01-09 19:15:01 +05303495#ifdef ANDROID
3496 if (dut->fils_hlp)
3497 process_fils_hlp(dut);
3498#endif /* ANDROID */
Jouni Malinen68143132017-09-02 02:34:08 +03003499
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003500 if (wps_param &&
3501 (strcmp(wps_param, "1") == 0 || strcasecmp(wps_param, "On") == 0))
3502 wps = 1;
3503
Vamsi Krishnac1633d22020-05-06 18:31:21 +05303504 if (dut->ocvc &&
3505 set_network(get_station_ifname(dut), dut->infra_network_id,
3506 "ocv", "1") < 0)
3507 return ERROR_SEND_STATUS;
3508
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003509 if (wps) {
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003510 if (dut->program == PROGRAM_60GHZ && network_mode &&
3511 strcasecmp(network_mode, "PBSS") == 0 &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003512 set_network(get_station_ifname(dut), dut->infra_network_id,
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003513 "pbss", "1") < 0)
3514 return -2;
3515
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003516 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
3517 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,WPS "
3518 "parameters not yet set");
3519 return 0;
3520 }
3521 if (dut->wps_method == WFA_CS_WPS_PBC) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003522 if (wpa_command(get_station_ifname(dut), "WPS_PBC") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003523 return -2;
3524 } else {
3525 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
3526 dut->wps_pin);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003527 if (wpa_command(get_station_ifname(dut), buf) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003528 return -2;
3529 }
3530 } else {
vamsi krishna52e16f92017-08-29 12:37:34 +05303531 if (strcmp(ssid, dut->infra_ssid) == 0) {
3532 sigma_dut_print(dut, DUT_MSG_DEBUG,
3533 "sta_associate for the most recently added network");
3534 } else if (find_network(dut, ssid) < 0) {
3535 sigma_dut_print(dut, DUT_MSG_DEBUG,
3536 "sta_associate for a previously stored network profile");
3537 send_resp(dut, conn, SIGMA_ERROR,
3538 "ErrorCode,Profile not found");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003539 return 0;
3540 }
3541
3542 if (bssid &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003543 set_network(get_station_ifname(dut), dut->infra_network_id,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003544 "bssid", bssid) < 0) {
3545 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3546 "Invalid bssid argument");
3547 return 0;
3548 }
3549
Veerendranath Jakkama082e342020-05-16 00:19:21 +05303550 if ((dut->program == PROGRAM_WPA3 &&
3551 dut->sta_associate_wait_connect) ||
3552 dut->program == PROGRAM_QM) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003553 ctrl = open_wpa_mon(get_station_ifname(dut));
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003554 if (!ctrl)
3555 return ERROR_SEND_STATUS;
3556 }
3557
Jouni Malinen46a19b62017-06-23 14:31:27 +03003558 extra[0] = '\0';
3559 if (chan)
3560 snprintf(extra, sizeof(extra), " freq=%u",
Alexei Avshalom Lazar093569f2018-11-13 14:08:17 +02003561 channel_to_freq(dut, atoi(chan)));
Jouni Malinen46a19b62017-06-23 14:31:27 +03003562 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d%s",
3563 dut->infra_network_id, extra);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003564 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003565 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to select "
3566 "network id %d on %s",
3567 dut->infra_network_id,
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003568 get_station_ifname(dut));
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003569 ret = ERROR_SEND_STATUS;
3570 goto done;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003571 }
3572 }
3573
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003574 if (!ctrl)
3575 return SUCCESS_SEND_STATUS;
3576
3577 /* Wait for connection result to be able to store server certificate
3578 * hash for trust root override testing
3579 * (dev_exec_action,ServerCertTrust). */
3580
3581 for (e = 0; e < 20; e++) {
3582 const char *events[] = {
3583 "CTRL-EVENT-EAP-PEER-CERT",
3584 "CTRL-EVENT-EAP-TLS-CERT-ERROR",
3585 "CTRL-EVENT-DISCONNECTED",
3586 "CTRL-EVENT-CONNECTED",
3587 "CTRL-EVENT-NETWORK-NOT-FOUND",
3588 NULL
3589 };
3590 char buf[1024];
3591 int res;
3592
3593 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
3594 if (res < 0) {
Jouni Malinenf1f16642019-11-15 21:19:04 +02003595 send_resp(dut, conn, SIGMA_COMPLETE,
3596 "Result,Association did not complete");
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003597 ret = STATUS_SENT_ERROR;
3598 break;
3599 }
3600 sigma_dut_print(dut, DUT_MSG_DEBUG, "Connection event: %s",
3601 buf);
3602
3603 if (strstr(buf, "CTRL-EVENT-EAP-PEER-CERT") &&
3604 strstr(buf, " depth=0")) {
3605 char *pos = strstr(buf, " hash=");
3606
3607 if (pos) {
3608 char *end;
3609
Jouni Malinen34b19cb2019-08-16 16:37:17 +03003610 if (strstr(buf, " tod=1"))
3611 tod = 1;
3612 else if (strstr(buf, " tod=2"))
3613 tod = 2;
3614 else
3615 tod = 0;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003616 sigma_dut_print(dut, DUT_MSG_DEBUG,
3617 "Server certificate TOD policy: %d",
3618 tod);
Jouni Malinen37d5c692019-08-19 16:56:55 +03003619 dut->server_cert_tod = tod;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003620
3621 pos += 6;
3622 end = strchr(pos, ' ');
3623 if (end)
3624 *end = '\0';
3625 strlcpy(dut->server_cert_hash, pos,
3626 sizeof(dut->server_cert_hash));
3627 sigma_dut_print(dut, DUT_MSG_DEBUG,
3628 "Server certificate hash: %s",
3629 dut->server_cert_hash);
3630 }
3631 }
3632
3633 if (strstr(buf, "CTRL-EVENT-EAP-TLS-CERT-ERROR")) {
3634 send_resp(dut, conn, SIGMA_COMPLETE,
3635 "Result,TLS server certificate validation failed");
3636 ret = STATUS_SENT_ERROR;
3637 break;
3638 }
3639
3640 if (strstr(buf, "CTRL-EVENT-NETWORK-NOT-FOUND")) {
3641 num_network_not_found++;
3642
3643 if (num_network_not_found > 2) {
3644 send_resp(dut, conn, SIGMA_COMPLETE,
3645 "Result,Network not found");
3646 ret = STATUS_SENT_ERROR;
3647 break;
3648 }
3649 }
3650
3651 if (strstr(buf, "CTRL-EVENT-DISCONNECTED")) {
3652 num_disconnected++;
3653
3654 if (num_disconnected > 2) {
3655 send_resp(dut, conn, SIGMA_COMPLETE,
3656 "Result,Connection failed");
3657 ret = STATUS_SENT_ERROR;
3658 break;
3659 }
3660 }
3661
3662 if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
3663 if (tod >= 0) {
3664 sigma_dut_print(dut, DUT_MSG_DEBUG,
3665 "Network profile TOD policy update: %d -> %d",
3666 dut->sta_tod_policy, tod);
3667 dut->sta_tod_policy = tod;
3668 }
Veerendranath Jakkama082e342020-05-16 00:19:21 +05303669 if (dut->program == PROGRAM_QM) {
3670 unsigned char iface_mac_addr[ETH_ALEN];
3671 char ipv6[100];
3672
3673 if (get_hwaddr(ifname, iface_mac_addr) < 0) {
3674 sigma_dut_print(dut, DUT_MSG_ERROR,
3675 "%s: get_hwaddr %s failed",
3676 __func__, ifname);
3677 ret = ERROR_SEND_STATUS;
3678 break;
3679 }
3680
3681 convert_mac_addr_to_ipv6_lladdr(iface_mac_addr,
3682 ipv6,
3683 sizeof(ipv6));
3684
3685 if (set_ipv6_addr(dut, ipv6, "64", ifname) !=
3686 0) {
3687 ret = ERROR_SEND_STATUS;
3688 break;
3689 }
3690 }
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003691 break;
3692 }
3693 }
3694done:
3695 if (ctrl) {
3696 wpa_ctrl_detach(ctrl);
3697 wpa_ctrl_close(ctrl);
3698 }
3699 return ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003700}
3701
3702
3703static int run_hs20_osu(struct sigma_dut *dut, const char *params)
3704{
3705 char buf[500], cmd[200];
3706 int res;
3707
3708 /* Use hs20-osu-client file at the current dir, if found; otherwise use
3709 * default path */
3710 res = snprintf(cmd, sizeof(cmd),
3711 "%s -w \"%s\" -r hs20-osu-client.res %s%s -dddKt -f Logs/hs20-osu-client.txt",
3712 file_exists("./hs20-osu-client") ?
3713 "./hs20-osu-client" : "hs20-osu-client",
3714 sigma_wpas_ctrl,
3715 dut->summary_log ? "-s " : "",
3716 dut->summary_log ? dut->summary_log : "");
3717 if (res < 0 || res >= (int) sizeof(cmd))
3718 return -1;
3719
3720 res = snprintf(buf, sizeof(buf), "%s %s", cmd, params);
3721 if (res < 0 || res >= (int) sizeof(buf))
3722 return -1;
3723 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
3724
3725 if (system(buf) != 0) {
3726 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run: %s", buf);
3727 return -1;
3728 }
3729 sigma_dut_print(dut, DUT_MSG_DEBUG,
3730 "Completed hs20-osu-client operation");
3731
3732 return 0;
3733}
3734
3735
3736static int download_ppsmo(struct sigma_dut *dut,
3737 struct sigma_conn *conn,
3738 const char *intf,
3739 struct sigma_cmd *cmd)
3740{
3741 const char *name, *path, *val;
3742 char url[500], buf[600], fbuf[100];
3743 char *fqdn = NULL;
3744
3745 name = get_param(cmd, "FileName");
3746 path = get_param(cmd, "FilePath");
3747 if (name == NULL || path == NULL)
3748 return -1;
3749
3750 if (strcasecmp(path, "VendorSpecific") == 0) {
3751 snprintf(url, sizeof(url), "PPS/%s", name);
3752 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured PPS MO "
3753 "from the device (%s)", url);
3754 if (!file_exists(url)) {
3755 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
3756 "PPS MO file does not exist");
3757 return 0;
3758 }
3759 snprintf(buf, sizeof(buf), "cp %s pps-tnds.xml", url);
3760 if (system(buf) != 0) {
3761 send_resp(dut, conn, SIGMA_ERROR,
3762 "errorCode,Failed to copy PPS MO");
3763 return 0;
3764 }
3765 } else if (strncasecmp(path, "http:", 5) != 0 &&
3766 strncasecmp(path, "https:", 6) != 0) {
3767 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3768 "Unsupported FilePath value");
3769 return 0;
3770 } else {
3771 snprintf(url, sizeof(url), "%s/%s", path, name);
3772 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading PPS MO from %s",
3773 url);
3774 snprintf(buf, sizeof(buf), "wget -T 10 -t 3 -O pps-tnds.xml '%s'", url);
3775 remove("pps-tnds.xml");
3776 if (system(buf) != 0) {
3777 send_resp(dut, conn, SIGMA_ERROR,
3778 "errorCode,Failed to download PPS MO");
3779 return 0;
3780 }
3781 }
3782
3783 if (run_hs20_osu(dut, "from_tnds pps-tnds.xml pps.xml") < 0) {
3784 send_resp(dut, conn, SIGMA_ERROR,
3785 "errorCode,Failed to parse downloaded PPSMO");
3786 return 0;
3787 }
3788 unlink("pps-tnds.xml");
3789
3790 val = get_param(cmd, "managementTreeURI");
3791 if (val) {
3792 const char *pos, *end;
3793 sigma_dut_print(dut, DUT_MSG_DEBUG, "managementTreeURI: %s",
3794 val);
3795 if (strncmp(val, "./Wi-Fi/", 8) != 0) {
3796 send_resp(dut, conn, SIGMA_ERROR,
3797 "errorCode,Invalid managementTreeURI prefix");
3798 return 0;
3799 }
3800 pos = val + 8;
3801 end = strchr(pos, '/');
3802 if (end == NULL ||
3803 strcmp(end, "/PerProviderSubscription") != 0) {
3804 send_resp(dut, conn, SIGMA_ERROR,
3805 "errorCode,Invalid managementTreeURI postfix");
3806 return 0;
3807 }
3808 if (end - pos >= (int) sizeof(fbuf)) {
3809 send_resp(dut, conn, SIGMA_ERROR,
3810 "errorCode,Too long FQDN in managementTreeURI");
3811 return 0;
3812 }
3813 memcpy(fbuf, pos, end - pos);
3814 fbuf[end - pos] = '\0';
3815 fqdn = fbuf;
3816 sigma_dut_print(dut, DUT_MSG_INFO,
3817 "FQDN from managementTreeURI: %s", fqdn);
3818 } else if (run_hs20_osu(dut, "get_fqdn pps.xml") == 0) {
3819 FILE *f = fopen("pps-fqdn", "r");
3820 if (f) {
3821 if (fgets(fbuf, sizeof(fbuf), f)) {
3822 fbuf[sizeof(fbuf) - 1] = '\0';
3823 fqdn = fbuf;
3824 sigma_dut_print(dut, DUT_MSG_DEBUG,
3825 "Use FQDN %s", fqdn);
3826 }
3827 fclose(f);
3828 }
3829 }
3830
3831 if (fqdn == NULL) {
3832 send_resp(dut, conn, SIGMA_ERROR,
3833 "errorCode,No FQDN specified");
3834 return 0;
3835 }
3836
3837 mkdir("SP", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
3838 snprintf(buf, sizeof(buf), "SP/%s", fqdn);
3839 mkdir(buf, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
3840
3841 snprintf(buf, sizeof(buf), "SP/%s/pps.xml", fqdn);
3842 if (rename("pps.xml", buf) < 0) {
3843 send_resp(dut, conn, SIGMA_ERROR,
3844 "errorCode,Could not move PPS MO");
3845 return 0;
3846 }
3847
3848 if (strcasecmp(path, "VendorSpecific") == 0) {
3849 snprintf(buf, sizeof(buf), "cp Certs/ca.pem SP/%s/ca.pem",
3850 fqdn);
3851 if (system(buf)) {
3852 send_resp(dut, conn, SIGMA_ERROR,
3853 "errorCode,Failed to copy OSU CA cert");
3854 return 0;
3855 }
3856
3857 snprintf(buf, sizeof(buf),
3858 "cp Certs/aaa-ca.pem SP/%s/aaa-ca.pem",
3859 fqdn);
3860 if (system(buf)) {
3861 send_resp(dut, conn, SIGMA_ERROR,
3862 "errorCode,Failed to copy AAA CA cert");
3863 return 0;
3864 }
3865 } else {
3866 snprintf(buf, sizeof(buf),
3867 "dl_osu_ca SP/%s/pps.xml SP/%s/ca.pem",
3868 fqdn, fqdn);
3869 if (run_hs20_osu(dut, buf) < 0) {
3870 send_resp(dut, conn, SIGMA_ERROR,
3871 "errorCode,Failed to download OSU CA cert");
3872 return 0;
3873 }
3874
3875 snprintf(buf, sizeof(buf),
3876 "dl_aaa_ca SP/%s/pps.xml SP/%s/aaa-ca.pem",
3877 fqdn, fqdn);
3878 if (run_hs20_osu(dut, buf) < 0) {
3879 sigma_dut_print(dut, DUT_MSG_INFO,
3880 "Failed to download AAA CA cert");
3881 }
3882 }
3883
3884 if (file_exists("next-client-cert.pem")) {
3885 snprintf(buf, sizeof(buf), "SP/%s/client-cert.pem", fqdn);
3886 if (rename("next-client-cert.pem", buf) < 0) {
3887 send_resp(dut, conn, SIGMA_ERROR,
3888 "errorCode,Could not move client certificate");
3889 return 0;
3890 }
3891 }
3892
3893 if (file_exists("next-client-key.pem")) {
3894 snprintf(buf, sizeof(buf), "SP/%s/client-key.pem", fqdn);
3895 if (rename("next-client-key.pem", buf) < 0) {
3896 send_resp(dut, conn, SIGMA_ERROR,
3897 "errorCode,Could not move client key");
3898 return 0;
3899 }
3900 }
3901
3902 snprintf(buf, sizeof(buf), "set_pps SP/%s/pps.xml", fqdn);
3903 if (run_hs20_osu(dut, buf) < 0) {
3904 send_resp(dut, conn, SIGMA_ERROR,
3905 "errorCode,Failed to configure credential from "
3906 "PPSMO");
3907 return 0;
3908 }
3909
3910 return 1;
3911}
3912
3913
3914static int download_cert(struct sigma_dut *dut,
3915 struct sigma_conn *conn,
3916 const char *intf,
3917 struct sigma_cmd *cmd)
3918{
3919 const char *name, *path;
3920 char url[500], buf[600];
3921
3922 name = get_param(cmd, "FileName");
3923 path = get_param(cmd, "FilePath");
3924 if (name == NULL || path == NULL)
3925 return -1;
3926
3927 if (strcasecmp(path, "VendorSpecific") == 0) {
3928 snprintf(url, sizeof(url), "Certs/%s-cert.pem", name);
3929 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
3930 "certificate from the device (%s)", url);
3931 if (!file_exists(url)) {
3932 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
3933 "certificate file does not exist");
3934 return 0;
3935 }
3936 snprintf(buf, sizeof(buf), "cp %s next-client-cert.pem", url);
3937 if (system(buf) != 0) {
3938 send_resp(dut, conn, SIGMA_ERROR,
3939 "errorCode,Failed to copy client "
3940 "certificate");
3941 return 0;
3942 }
3943
3944 snprintf(url, sizeof(url), "Certs/%s-key.pem", name);
3945 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
3946 "private key from the device (%s)", url);
3947 if (!file_exists(url)) {
3948 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
3949 "private key file does not exist");
3950 return 0;
3951 }
3952 snprintf(buf, sizeof(buf), "cp %s next-client-key.pem", url);
3953 if (system(buf) != 0) {
3954 send_resp(dut, conn, SIGMA_ERROR,
3955 "errorCode,Failed to copy client key");
3956 return 0;
3957 }
3958 } else if (strncasecmp(path, "http:", 5) != 0 &&
3959 strncasecmp(path, "https:", 6) != 0) {
3960 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3961 "Unsupported FilePath value");
3962 return 0;
3963 } else {
3964 snprintf(url, sizeof(url), "%s/%s.pem", path, name);
3965 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading client "
3966 "certificate/key from %s", url);
3967 snprintf(buf, sizeof(buf),
3968 "wget -T 10 -t 3 -O next-client-cert.pem '%s'", url);
3969 if (system(buf) != 0) {
3970 send_resp(dut, conn, SIGMA_ERROR,
3971 "errorCode,Failed to download client "
3972 "certificate");
3973 return 0;
3974 }
3975
3976 if (system("cp next-client-cert.pem next-client-key.pem") != 0)
3977 {
3978 send_resp(dut, conn, SIGMA_ERROR,
3979 "errorCode,Failed to copy client key");
3980 return 0;
3981 }
3982 }
3983
3984 return 1;
3985}
3986
3987
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02003988static int cmd_sta_preset_testparameters_60ghz(struct sigma_dut *dut,
3989 struct sigma_conn *conn,
3990 struct sigma_cmd *cmd)
3991{
3992 const char *val;
3993 const char *intf = get_param(cmd, "interface");
3994
3995 if (!intf)
3996 return -1;
3997
3998 val = get_param(cmd, "WscIEFragment");
3999 if (val && strcasecmp(val, "enable") == 0) {
4000 sigma_dut_print(dut, DUT_MSG_DEBUG,
4001 "Enable WSC IE fragmentation");
4002
4003 dut->wsc_fragment = 1;
4004 /* set long attributes to force fragmentation */
4005 if (wpa_command(intf, "SET device_name "
4006 WPS_LONG_DEVICE_NAME) < 0)
4007 return -2;
4008 if (wpa_command(intf, "SET manufacturer "
4009 WPS_LONG_MANUFACTURER) < 0)
4010 return -2;
4011 if (wpa_command(intf, "SET model_name "
4012 WPS_LONG_MODEL_NAME) < 0)
4013 return -2;
4014 if (wpa_command(intf, "SET model_number "
4015 WPS_LONG_MODEL_NUMBER) < 0)
4016 return -2;
4017 if (wpa_command(intf, "SET serial_number "
4018 WPS_LONG_SERIAL_NUMBER) < 0)
4019 return -2;
4020 }
4021
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02004022 val = get_param(cmd, "RSN_IE");
4023 if (val) {
4024 if (strcasecmp(val, "disable") == 0)
4025 dut->force_rsn_ie = FORCE_RSN_IE_REMOVE;
4026 else if (strcasecmp(val, "enable") == 0)
4027 dut->force_rsn_ie = FORCE_RSN_IE_ADD;
4028 }
4029
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02004030 val = get_param(cmd, "WpsVersion");
4031 if (val)
4032 dut->wps_forced_version = get_wps_forced_version(dut, val);
4033
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02004034 val = get_param(cmd, "WscEAPFragment");
4035 if (val && strcasecmp(val, "enable") == 0)
4036 dut->eap_fragment = 1;
4037
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02004038 return 1;
4039}
4040
4041
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004042static int cmd_sta_preset_testparameters_hs2_r2(struct sigma_dut *dut,
4043 struct sigma_conn *conn,
4044 const char *intf,
4045 struct sigma_cmd *cmd)
4046{
4047 const char *val;
4048
4049 val = get_param(cmd, "FileType");
4050 if (val && strcasecmp(val, "PPSMO") == 0)
4051 return download_ppsmo(dut, conn, intf, cmd);
4052 if (val && strcasecmp(val, "CERT") == 0)
4053 return download_cert(dut, conn, intf, cmd);
4054 if (val) {
4055 send_resp(dut, conn, SIGMA_ERROR,
4056 "ErrorCode,Unsupported FileType");
4057 return 0;
4058 }
4059
4060 return 1;
4061}
4062
4063
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304064static int cmd_sta_preset_testparameters_oce(struct sigma_dut *dut,
4065 struct sigma_conn *conn,
4066 const char *intf,
4067 struct sigma_cmd *cmd)
4068{
4069 const char *val;
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304070 char buf[1000];
4071 char text[20];
4072 unsigned char addr[ETH_ALEN];
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304073
4074 val = get_param(cmd, "OCESupport");
4075 if (val && strcasecmp(val, "Disable") == 0) {
4076 if (wpa_command(intf, "SET oce 0") < 0) {
4077 send_resp(dut, conn, SIGMA_ERROR,
4078 "ErrorCode,Failed to disable OCE");
4079 return 0;
4080 }
4081 } else if (val && strcasecmp(val, "Enable") == 0) {
4082 if (wpa_command(intf, "SET oce 1") < 0) {
4083 send_resp(dut, conn, SIGMA_ERROR,
4084 "ErrorCode,Failed to enable OCE");
4085 return 0;
4086 }
4087 }
4088
vamsi krishnaa2799492017-12-05 14:28:01 +05304089 val = get_param(cmd, "FILScap");
4090 if (val && (atoi(val) == 1)) {
4091 if (wpa_command(intf, "SET disable_fils 0") < 0) {
4092 send_resp(dut, conn, SIGMA_ERROR,
4093 "ErrorCode,Failed to enable FILS");
4094 return 0;
4095 }
4096 } else if (val && (atoi(val) == 0)) {
4097 if (wpa_command(intf, "SET disable_fils 1") < 0) {
4098 send_resp(dut, conn, SIGMA_ERROR,
4099 "ErrorCode,Failed to disable FILS");
4100 return 0;
4101 }
4102 }
4103
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304104 val = get_param(cmd, "FILSHLP");
4105 if (val && strcasecmp(val, "Enable") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004106 if (get_wpa_status(get_station_ifname(dut), "address", text,
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304107 sizeof(text)) < 0)
4108 return -2;
4109 hwaddr_aton(text, addr);
4110 snprintf(buf, sizeof(buf),
4111 "FILS_HLP_REQ_ADD ff:ff:ff:ff:ff:ff "
4112 "080045100140000040004011399e00000000ffffffff00440043"
4113 "012cb30001010600fd4f46410000000000000000000000000000"
4114 "000000000000"
4115 "%02x%02x%02x%02x%02x%02x"
4116 "0000000000000000000000000000000000000000000000000000"
4117 "0000000000000000000000000000000000000000000000000000"
4118 "0000000000000000000000000000000000000000000000000000"
4119 "0000000000000000000000000000000000000000000000000000"
4120 "0000000000000000000000000000000000000000000000000000"
4121 "0000000000000000000000000000000000000000000000000000"
4122 "0000000000000000000000000000000000000000000000000000"
4123 "0000000000000000000000000000000000000000638253633501"
4124 "013d0701000af549d29b390205dc3c12616e64726f69642d6468"
4125 "63702d382e302e30370a0103060f1a1c333a3b2b5000ff00",
4126 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
4127 if (wpa_command(intf, buf)) {
4128 send_resp(dut, conn, SIGMA_ERROR,
4129 "ErrorCode,Failed to add HLP");
4130 return 0;
4131 }
4132 dut->fils_hlp = 1;
4133 }
4134
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304135 return 1;
4136}
4137
4138
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004139static void ath_sta_set_noack(struct sigma_dut *dut, const char *intf,
4140 const char *val)
4141{
4142 int counter = 0;
4143 char token[50];
4144 char *result;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304145 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004146
Peng Xub8fc5cc2017-05-10 17:27:28 -07004147 strlcpy(token, val, sizeof(token));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004148 token[sizeof(token) - 1] = '\0';
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304149 result = strtok_r(token, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004150 while (result) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004151 if (strcmp(result, "disable") == 0)
4152 run_iwpriv(dut, intf, "noackpolicy %d 1 0", counter);
4153 else
4154 run_iwpriv(dut, intf, "noackpolicy %d 1 1", counter);
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304155 result = strtok_r(NULL, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004156 counter++;
4157 }
4158}
4159
4160
4161static void ath_sta_set_rts(struct sigma_dut *dut, const char *intf,
4162 const char *val)
4163{
4164 char buf[100];
4165
4166 snprintf(buf, sizeof(buf), "iwconfig %s rts %s", intf, val);
4167 if (system(buf) != 0) {
4168 sigma_dut_print(dut, DUT_MSG_ERROR, "iwconfig RTS failed");
4169 }
4170}
4171
4172
4173static void ath_sta_set_wmm(struct sigma_dut *dut, const char *intf,
4174 const char *val)
4175{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004176 if (strcasecmp(val, "off") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004177 run_iwpriv(dut, intf, "wmm 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004178 }
4179}
4180
4181
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08004182static int wcn_sta_set_wmm(struct sigma_dut *dut, const char *intf,
4183 const char *val)
4184{
4185#ifdef NL80211_SUPPORT
4186 struct nl_msg *msg;
4187 int ret = 0;
4188 struct nlattr *params;
4189 int ifindex;
4190 int wmmenable = 1;
4191
4192 if (val &&
4193 (strcasecmp(val, "off") == 0 || strcmp(val, "0") == 0))
4194 wmmenable = 0;
4195
4196 ifindex = if_nametoindex(intf);
4197 if (ifindex == 0) {
4198 sigma_dut_print(dut, DUT_MSG_ERROR,
4199 "%s: Index for interface %s failed",
4200 __func__, intf);
4201 return -1;
4202 }
4203
4204 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4205 NL80211_CMD_VENDOR)) ||
4206 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4207 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4208 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4209 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4210 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4211 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WMM_ENABLE,
4212 wmmenable)) {
4213 sigma_dut_print(dut, DUT_MSG_ERROR,
4214 "%s: err in adding vendor_cmd and vendor_data",
4215 __func__);
4216 nlmsg_free(msg);
4217 return -1;
4218 }
4219 nla_nest_end(msg, params);
4220
4221 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4222 if (ret) {
4223 sigma_dut_print(dut, DUT_MSG_ERROR,
4224 "%s: err in send_and_recv_msgs, ret=%d",
4225 __func__, ret);
4226 }
4227 return ret;
4228#else /* NL80211_SUPPORT */
4229 sigma_dut_print(dut, DUT_MSG_ERROR,
4230 "WMM cannot be changed without NL80211_SUPPORT defined");
4231 return -1;
4232#endif /* NL80211_SUPPORT */
4233}
4234
4235
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004236static void ath_sta_set_sgi(struct sigma_dut *dut, const char *intf,
4237 const char *val)
4238{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004239 int sgi20;
4240
4241 sgi20 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
4242
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004243 run_iwpriv(dut, intf, "shortgi %d", sgi20);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004244}
4245
4246
4247static void ath_sta_set_11nrates(struct sigma_dut *dut, const char *intf,
4248 const char *val)
4249{
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05304250 int rate_code, v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004251
4252 /* Disable Tx Beam forming when using a fixed rate */
4253 ath_disable_txbf(dut, intf);
4254
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05304255 v = atoi(val);
4256 if (v < 0 || v > 32) {
4257 sigma_dut_print(dut, DUT_MSG_ERROR,
4258 "Invalid Fixed MCS rate: %d", v);
4259 return;
4260 }
4261 rate_code = 0x80 + v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004262
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004263 run_iwpriv(dut, intf, "set11NRates 0x%x", rate_code);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004264
4265 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004266 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004267}
4268
4269
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08004270static void iwpriv_sta_set_amsdu(struct sigma_dut *dut, const char *intf,
4271 const char *val)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004272{
4273 char buf[60];
4274
4275 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)
4276 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 2", intf);
4277 else
4278 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf);
4279
4280 if (system(buf) != 0)
4281 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv amsdu failed");
4282}
4283
4284
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004285static int iwpriv_sta_set_ampdu(struct sigma_dut *dut, const char *intf,
4286 int ampdu)
4287{
4288 char buf[60];
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08004289 int maxaggregation = 63;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004290
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08004291 if (ampdu)
4292 ampdu = maxaggregation;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004293 snprintf(buf, sizeof(buf), "iwpriv %s ampdu %d", intf, ampdu);
4294 if (system(buf) != 0) {
4295 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv ampdu failed");
4296 return -1;
4297 }
4298
4299 return 0;
4300}
4301
4302
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004303static void ath_sta_set_stbc(struct sigma_dut *dut, const char *intf,
4304 const char *val)
4305{
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004306 run_iwpriv(dut, intf, "tx_stbc %s", val);
4307 run_iwpriv(dut, intf, "rx_stbc %s", val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004308}
4309
4310
4311static int wcn_sta_set_cts_width(struct sigma_dut *dut, const char *intf,
4312 const char *val)
4313{
4314 char buf[60];
4315
Peng Xucc317ed2017-05-18 16:44:37 -07004316 if (strcmp(val, "160") == 0) {
4317 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 5", intf);
4318 } else if (strcmp(val, "80") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004319 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
4320 } else if (strcmp(val, "40") == 0) {
4321 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 2", intf);
4322 } else if (strcmp(val, "20") == 0) {
4323 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 1", intf);
4324 } else if (strcasecmp(val, "Auto") == 0) {
4325 buf[0] = '\0';
4326 } else {
4327 sigma_dut_print(dut, DUT_MSG_ERROR,
4328 "WIDTH/CTS_WIDTH value not supported");
4329 return -1;
4330 }
4331
4332 if (buf[0] != '\0' && system(buf) != 0) {
4333 sigma_dut_print(dut, DUT_MSG_ERROR,
4334 "Failed to set WIDTH/CTS_WIDTH");
4335 return -1;
4336 }
4337
4338 return 0;
4339}
4340
4341
4342int ath_set_width(struct sigma_dut *dut, struct sigma_conn *conn,
4343 const char *intf, const char *val)
4344{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004345 if (strcasecmp(val, "Auto") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004346 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004347 dut->chwidth = 0;
4348 } else if (strcasecmp(val, "20") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004349 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004350 dut->chwidth = 0;
4351 } else if (strcasecmp(val, "40") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004352 run_iwpriv(dut, intf, "chwidth 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004353 dut->chwidth = 1;
4354 } else if (strcasecmp(val, "80") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004355 run_iwpriv(dut, intf, "chwidth 2");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004356 dut->chwidth = 2;
4357 } else if (strcasecmp(val, "160") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004358 run_iwpriv(dut, intf, "chwidth 3");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004359 dut->chwidth = 3;
4360 } else {
4361 send_resp(dut, conn, SIGMA_ERROR,
4362 "ErrorCode,WIDTH not supported");
4363 return -1;
4364 }
4365
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004366 return 0;
4367}
4368
4369
4370static int wcn_sta_set_sp_stream(struct sigma_dut *dut, const char *intf,
4371 const char *val)
4372{
4373 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07004374 int sta_nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004375
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08004376 if (strcmp(val, "1SS") == 0 || strcmp(val, "1") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004377 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07004378 sta_nss = 1;
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08004379 } else if (strcmp(val, "2SS") == 0 || strcmp(val, "2") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004380 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07004381 sta_nss = 2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004382 } else {
4383 sigma_dut_print(dut, DUT_MSG_ERROR,
4384 "SP_STREAM value not supported");
4385 return -1;
4386 }
4387
4388 if (system(buf) != 0) {
4389 sigma_dut_print(dut, DUT_MSG_ERROR,
4390 "Failed to set SP_STREAM");
4391 return -1;
4392 }
4393
Arif Hussainac6c5112018-05-25 17:34:00 -07004394 dut->sta_nss = sta_nss;
4395
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004396 return 0;
4397}
4398
4399
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304400static void wcn_sta_set_stbc(struct sigma_dut *dut, const char *intf,
4401 const char *val)
4402{
4403 char buf[60];
4404
4405 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc %s", intf, val);
4406 if (system(buf) != 0)
4407 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv tx_stbc failed");
4408
4409 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc %s", intf, val);
4410 if (system(buf) != 0)
4411 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv rx_stbc failed");
4412}
4413
4414
Ashwini Patil68d02cd2017-01-10 15:39:16 +05304415static int mbo_set_cellular_data_capa(struct sigma_dut *dut,
4416 struct sigma_conn *conn,
4417 const char *intf, int capa)
4418{
4419 char buf[32];
4420
4421 if (capa > 0 && capa < 4) {
4422 snprintf(buf, sizeof(buf), "SET mbo_cell_capa %d", capa);
4423 if (wpa_command(intf, buf) < 0) {
4424 send_resp(dut, conn, SIGMA_ERROR,
4425 "ErrorCode, Failed to set cellular data capability");
4426 return 0;
4427 }
4428 return 1;
4429 }
4430
4431 sigma_dut_print(dut, DUT_MSG_ERROR,
4432 "Invalid Cellular data capability: %d", capa);
4433 send_resp(dut, conn, SIGMA_INVALID,
4434 "ErrorCode,Invalid cellular data capability");
4435 return 0;
4436}
4437
4438
Ashwini Patil9183fdb2017-04-13 16:58:25 +05304439static int mbo_set_roaming(struct sigma_dut *dut, struct sigma_conn *conn,
4440 const char *intf, const char *val)
4441{
4442 if (strcasecmp(val, "Disable") == 0) {
4443 if (wpa_command(intf, "SET roaming 0") < 0) {
4444 send_resp(dut, conn, SIGMA_ERROR,
4445 "ErrorCode,Failed to disable roaming");
4446 return 0;
4447 }
4448 return 1;
4449 }
4450
4451 if (strcasecmp(val, "Enable") == 0) {
4452 if (wpa_command(intf, "SET roaming 1") < 0) {
4453 send_resp(dut, conn, SIGMA_ERROR,
4454 "ErrorCode,Failed to enable roaming");
4455 return 0;
4456 }
4457 return 1;
4458 }
4459
4460 sigma_dut_print(dut, DUT_MSG_ERROR,
4461 "Invalid value provided for roaming: %s", val);
4462 send_resp(dut, conn, SIGMA_INVALID,
4463 "ErrorCode,Unknown value provided for Roaming");
4464 return 0;
4465}
4466
4467
Ashwini Patila75de5a2017-04-13 16:35:05 +05304468static int mbo_set_assoc_disallow(struct sigma_dut *dut,
4469 struct sigma_conn *conn,
4470 const char *intf, const char *val)
4471{
4472 if (strcasecmp(val, "Disable") == 0) {
4473 if (wpa_command(intf, "SET ignore_assoc_disallow 1") < 0) {
4474 send_resp(dut, conn, SIGMA_ERROR,
4475 "ErrorCode,Failed to disable Assoc_disallow");
4476 return 0;
4477 }
4478 return 1;
4479 }
4480
4481 if (strcasecmp(val, "Enable") == 0) {
4482 if (wpa_command(intf, "SET ignore_assoc_disallow 0") < 0) {
4483 send_resp(dut, conn, SIGMA_ERROR,
4484 "ErrorCode,Failed to enable Assoc_disallow");
4485 return 0;
4486 }
4487 return 1;
4488 }
4489
4490 sigma_dut_print(dut, DUT_MSG_ERROR,
4491 "Invalid value provided for Assoc_disallow: %s", val);
4492 send_resp(dut, conn, SIGMA_INVALID,
4493 "ErrorCode,Unknown value provided for Assoc_disallow");
4494 return 0;
4495}
4496
4497
Ashwini Patilc63161e2017-04-13 16:30:23 +05304498static int mbo_set_bss_trans_req(struct sigma_dut *dut, struct sigma_conn *conn,
4499 const char *intf, const char *val)
4500{
4501 if (strcasecmp(val, "Reject") == 0) {
4502 if (wpa_command(intf, "SET reject_btm_req_reason 1") < 0) {
4503 send_resp(dut, conn, SIGMA_ERROR,
4504 "ErrorCode,Failed to Reject BTM Request");
4505 return 0;
4506 }
4507 return 1;
4508 }
4509
4510 if (strcasecmp(val, "Accept") == 0) {
4511 if (wpa_command(intf, "SET reject_btm_req_reason 0") < 0) {
4512 send_resp(dut, conn, SIGMA_ERROR,
4513 "ErrorCode,Failed to Accept BTM Request");
4514 return 0;
4515 }
4516 return 1;
4517 }
4518
4519 sigma_dut_print(dut, DUT_MSG_ERROR,
4520 "Invalid value provided for BSS_Transition: %s", val);
4521 send_resp(dut, conn, SIGMA_INVALID,
4522 "ErrorCode,Unknown value provided for BSS_Transition");
4523 return 0;
4524}
4525
4526
Ashwini Patil00402582017-04-13 12:29:39 +05304527static int mbo_set_non_pref_ch_list(struct sigma_dut *dut,
4528 struct sigma_conn *conn,
4529 const char *intf,
4530 struct sigma_cmd *cmd)
4531{
4532 const char *ch, *pref, *op_class, *reason;
4533 char buf[120];
4534 int len, ret;
4535
4536 pref = get_param(cmd, "Ch_Pref");
4537 if (!pref)
4538 return 1;
4539
4540 if (strcasecmp(pref, "clear") == 0) {
4541 free(dut->non_pref_ch_list);
4542 dut->non_pref_ch_list = NULL;
4543 } else {
4544 op_class = get_param(cmd, "Ch_Op_Class");
4545 if (!op_class) {
4546 send_resp(dut, conn, SIGMA_INVALID,
4547 "ErrorCode,Ch_Op_Class not provided");
4548 return 0;
4549 }
4550
4551 ch = get_param(cmd, "Ch_Pref_Num");
4552 if (!ch) {
4553 send_resp(dut, conn, SIGMA_INVALID,
4554 "ErrorCode,Ch_Pref_Num not provided");
4555 return 0;
4556 }
4557
4558 reason = get_param(cmd, "Ch_Reason_Code");
4559 if (!reason) {
4560 send_resp(dut, conn, SIGMA_INVALID,
4561 "ErrorCode,Ch_Reason_Code not provided");
4562 return 0;
4563 }
4564
4565 if (!dut->non_pref_ch_list) {
4566 dut->non_pref_ch_list =
4567 calloc(1, NON_PREF_CH_LIST_SIZE);
4568 if (!dut->non_pref_ch_list) {
4569 send_resp(dut, conn, SIGMA_ERROR,
4570 "ErrorCode,Failed to allocate memory for non_pref_ch_list");
4571 return 0;
4572 }
4573 }
4574 len = strlen(dut->non_pref_ch_list);
4575 ret = snprintf(dut->non_pref_ch_list + len,
4576 NON_PREF_CH_LIST_SIZE - len,
4577 " %s:%s:%s:%s", op_class, ch, pref, reason);
4578 if (ret > 0 && ret < NON_PREF_CH_LIST_SIZE - len) {
4579 sigma_dut_print(dut, DUT_MSG_DEBUG, "non_pref_list: %s",
4580 dut->non_pref_ch_list);
4581 } else {
4582 sigma_dut_print(dut, DUT_MSG_ERROR,
4583 "snprintf failed for non_pref_list, ret = %d",
4584 ret);
4585 send_resp(dut, conn, SIGMA_ERROR,
4586 "ErrorCode,snprintf failed");
4587 free(dut->non_pref_ch_list);
4588 dut->non_pref_ch_list = NULL;
4589 return 0;
4590 }
4591 }
4592
4593 ret = snprintf(buf, sizeof(buf), "SET non_pref_chan%s",
4594 dut->non_pref_ch_list ? dut->non_pref_ch_list : " ");
4595 if (ret < 0 || ret >= (int) sizeof(buf)) {
4596 sigma_dut_print(dut, DUT_MSG_DEBUG,
4597 "snprintf failed for set non_pref_chan, ret: %d",
4598 ret);
4599 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,snprint failed");
4600 return 0;
4601 }
4602
4603 if (wpa_command(intf, buf) < 0) {
4604 send_resp(dut, conn, SIGMA_ERROR,
4605 "ErrorCode,Failed to set non-preferred channel list");
4606 return 0;
4607 }
4608
4609 return 1;
4610}
4611
4612
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004613#ifdef NL80211_SUPPORT
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004614
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08004615static int sta_set_he_htc_supp(struct sigma_dut *dut, const char *intf,
4616 uint8_t cfg)
4617{
4618 struct nl_msg *msg;
4619 int ret = 0;
4620 struct nlattr *params;
4621 int ifindex;
4622
4623 ifindex = if_nametoindex(intf);
4624 if (ifindex == 0) {
4625 sigma_dut_print(dut, DUT_MSG_ERROR,
4626 "%s: Index for interface %s failed",
4627 __func__, intf);
4628 return -1;
4629 }
4630
4631 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4632 NL80211_CMD_VENDOR)) ||
4633 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4634 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4635 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4636 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4637 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4638 nla_put_u8(msg,
4639 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_HTC_HE_SUPP,
4640 cfg)) {
4641 sigma_dut_print(dut, DUT_MSG_ERROR,
4642 "%s: err in adding vendor_cmd and vendor_data",
4643 __func__);
4644 nlmsg_free(msg);
4645 return -1;
4646 }
4647 nla_nest_end(msg, params);
4648
4649 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4650 if (ret) {
4651 sigma_dut_print(dut, DUT_MSG_ERROR,
4652 "%s: err in send_and_recv_msgs, ret=%d",
4653 __func__, ret);
4654 }
4655 return ret;
4656}
4657
4658
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004659static int sta_set_he_fragmentation(struct sigma_dut *dut, const char *intf,
4660 enum he_fragmentation_val frag)
4661{
4662 struct nl_msg *msg;
4663 int ret = 0;
4664 struct nlattr *params;
4665 int ifindex;
4666
4667 ifindex = if_nametoindex(intf);
4668 if (ifindex == 0) {
4669 sigma_dut_print(dut, DUT_MSG_ERROR,
4670 "%s: Index for interface %s failed",
4671 __func__, intf);
4672 return -1;
4673 }
4674
4675 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4676 NL80211_CMD_VENDOR)) ||
4677 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4678 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4679 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4680 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4681 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4682 nla_put_u8(msg,
4683 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_FRAGMENTATION,
4684 frag)) {
4685 sigma_dut_print(dut, DUT_MSG_ERROR,
4686 "%s: err in adding vendor_cmd and vendor_data",
4687 __func__);
4688 nlmsg_free(msg);
4689 return -1;
4690 }
4691 nla_nest_end(msg, params);
4692
4693 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4694 if (ret) {
4695 sigma_dut_print(dut, DUT_MSG_ERROR,
4696 "%s: err in send_and_recv_msgs, ret=%d",
4697 __func__, ret);
4698 }
4699 return ret;
4700}
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004701
4702
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -08004703int wcn_set_he_ltf(struct sigma_dut *dut, const char *intf,
4704 enum qca_wlan_he_ltf_cfg ltf)
Subhani Shaik8e7a3052018-04-24 14:03:00 -07004705{
4706 struct nl_msg *msg;
4707 int ret = 0;
4708 struct nlattr *params;
4709 int ifindex;
4710
4711 ifindex = if_nametoindex(intf);
4712 if (ifindex == 0) {
4713 sigma_dut_print(dut, DUT_MSG_ERROR,
4714 "%s: Index for interface %s failed",
4715 __func__, intf);
4716 return -1;
4717 }
4718
4719 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4720 NL80211_CMD_VENDOR)) ||
4721 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4722 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4723 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4724 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4725 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4726 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_LTF,
4727 ltf)) {
4728 sigma_dut_print(dut, DUT_MSG_ERROR,
4729 "%s: err in adding vendor_cmd and vendor_data",
4730 __func__);
4731 nlmsg_free(msg);
4732 return -1;
4733 }
4734 nla_nest_end(msg, params);
4735
4736 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4737 if (ret) {
4738 sigma_dut_print(dut, DUT_MSG_ERROR,
4739 "%s: err in send_and_recv_msgs, ret=%d",
4740 __func__, ret);
4741 }
4742 return ret;
4743}
4744
4745
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004746static int nlvendor_sta_set_noack(struct sigma_dut *dut, const char *intf,
4747 int noack, enum qca_wlan_ac_type ac)
4748{
4749 struct nl_msg *msg;
4750 int ret = 0;
4751 struct nlattr *params;
4752 int ifindex;
4753
4754 ifindex = if_nametoindex(intf);
4755 if (ifindex == 0) {
4756 sigma_dut_print(dut, DUT_MSG_ERROR,
4757 "%s: Index for interface %s failed",
4758 __func__, intf);
4759 return -1;
4760 }
4761
4762 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4763 NL80211_CMD_VENDOR)) ||
4764 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4765 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4766 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4767 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4768 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4769 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_NO_ACK,
4770 noack) ||
4771 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_NO_ACK_AC,
4772 ac)) {
4773 sigma_dut_print(dut, DUT_MSG_ERROR,
4774 "%s: err in adding vendor_cmd and vendor_data",
4775 __func__);
4776 nlmsg_free(msg);
4777 return -1;
4778 }
4779 nla_nest_end(msg, params);
4780
4781 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4782 if (ret) {
4783 sigma_dut_print(dut, DUT_MSG_ERROR,
4784 "%s: err in send_and_recv_msgs, ret=%d",
4785 __func__, ret);
4786 }
4787 return ret;
4788}
4789
4790
4791static void wcn_sta_set_noack(struct sigma_dut *dut, const char *intf,
4792 const char *val)
4793{
4794 int noack, ret;
4795 char token[100];
4796 char *result;
4797 char *saveptr;
4798 enum qca_wlan_ac_type ac = QCA_WLAN_AC_BE;
4799
4800 strlcpy(token, val, sizeof(token));
4801 token[sizeof(token) - 1] = '\0';
4802 result = strtok_r(token, ":", &saveptr);
4803 while (result) {
4804 noack = strcasecmp(result, "Disable") != 0;
4805 ret = nlvendor_sta_set_noack(dut, intf, noack, ac);
4806 if (ret) {
4807 sigma_dut_print(dut, DUT_MSG_ERROR,
4808 "nlvendor_sta_set_noack failed for ac:%d, ret:%d",
4809 ac, ret);
4810 }
4811 result = strtok_r(NULL, ":", &saveptr);
4812 ac++;
4813 }
4814}
4815
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004816#endif /* NL80211_SUPPORT */
4817
4818
Jouni Malinenf7222712019-06-13 01:50:21 +03004819static enum sigma_cmd_result
4820cmd_sta_preset_testparameters(struct sigma_dut *dut, struct sigma_conn *conn,
4821 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004822{
4823 const char *intf = get_param(cmd, "Interface");
4824 const char *val;
4825
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03004826 val = get_param(cmd, "FT_DS");
4827 if (val) {
4828 if (strcasecmp(val, "Enable") == 0) {
4829 dut->sta_ft_ds = 1;
4830 } else if (strcasecmp(val, "Disable") == 0) {
4831 dut->sta_ft_ds = 0;
4832 } else {
4833 send_resp(dut, conn, SIGMA_ERROR,
4834 "errorCode,Unsupported value for FT_DS");
4835 return STATUS_SENT_ERROR;
4836 }
4837 }
4838
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004839 val = get_param(cmd, "Program");
Jouni Malinen1f6ae642018-06-07 23:56:13 +03004840 if (val && (strcasecmp(val, "HS2-R2") == 0 ||
4841 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004842 return cmd_sta_preset_testparameters_hs2_r2(dut, conn, intf,
4843 cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004844
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07004845 if (val && strcasecmp(val, "LOC") == 0)
4846 return loc_cmd_sta_preset_testparameters(dut, conn, cmd);
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02004847 if (val && strcasecmp(val, "60GHZ") == 0) {
4848 val = get_param(cmd, "WPS");
4849 if (val && strcasecmp(val, "disable") == 0) {
4850 dut->wps_disable = 1;
4851 sigma_dut_print(dut, DUT_MSG_INFO, "WPS disabled");
4852 } else {
4853 /* wps_disable can have other value from the previous
4854 * test, so make sure it has the correct value.
4855 */
4856 dut->wps_disable = 0;
4857 }
4858
4859 val = get_param(cmd, "P2P");
4860 if (val && strcasecmp(val, "disable") == 0)
4861 sigma_dut_print(dut, DUT_MSG_INFO, "P2P disabled");
4862 }
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07004863
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02004864 if (dut->program == PROGRAM_WPS && dut->band == WPS_BAND_60G)
4865 return cmd_sta_preset_testparameters_60ghz(dut, conn, cmd);
4866
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004867#ifdef ANDROID_NAN
4868 if (val && strcasecmp(val, "NAN") == 0)
4869 return nan_cmd_sta_preset_testparameters(dut, conn, cmd);
4870#endif /* ANDROID_NAN */
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07004871#ifdef MIRACAST
4872 if (val && (strcasecmp(val, "WFD") == 0 ||
4873 strcasecmp(val, "DisplayR2") == 0))
4874 return miracast_preset_testparameters(dut, conn, cmd);
4875#endif /* MIRACAST */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004876
Kiran Kumar Lokeredd086642020-06-04 00:29:26 -07004877 if (val &&
4878 (strcasecmp(val, "MBO") == 0 || strcasecmp(val, "HE") == 0)) {
Ashwini Patil68d02cd2017-01-10 15:39:16 +05304879 val = get_param(cmd, "Cellular_Data_Cap");
4880 if (val &&
4881 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
4882 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +05304883
4884 val = get_param(cmd, "Ch_Pref");
4885 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
4886 return 0;
4887
Ashwini Patilc63161e2017-04-13 16:30:23 +05304888 val = get_param(cmd, "BSS_Transition");
4889 if (val && mbo_set_bss_trans_req(dut, conn, intf, val) == 0)
4890 return 0;
4891
Ashwini Patila75de5a2017-04-13 16:35:05 +05304892 val = get_param(cmd, "Assoc_Disallow");
4893 if (val && mbo_set_assoc_disallow(dut, conn, intf, val) == 0)
4894 return 0;
4895
Ashwini Patil9183fdb2017-04-13 16:58:25 +05304896 val = get_param(cmd, "Roaming");
4897 if (val && mbo_set_roaming(dut, conn, intf, val) == 0)
4898 return 0;
4899
Ashwini Patil68d02cd2017-01-10 15:39:16 +05304900 return 1;
4901 }
4902
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304903 if (val && strcasecmp(val, "OCE") == 0)
4904 return cmd_sta_preset_testparameters_oce(dut, conn, intf, cmd);
4905
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004906#if 0
4907 val = get_param(cmd, "Supplicant");
4908 if (val && strcasecmp(val, "Default") != 0) {
4909 send_resp(dut, conn, SIGMA_ERROR,
4910 "ErrorCode,Only default(Vendor) supplicant "
4911 "supported");
4912 return 0;
4913 }
4914#endif
4915
4916 val = get_param(cmd, "RTS");
4917 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004918 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004919 case DRIVER_ATHEROS:
4920 ath_sta_set_rts(dut, intf, val);
4921 break;
4922 default:
4923#if 0
4924 send_resp(dut, conn, SIGMA_ERROR,
4925 "ErrorCode,Setting RTS not supported");
4926 return 0;
4927#else
4928 sigma_dut_print(dut, DUT_MSG_DEBUG,
4929 "Setting RTS not supported");
4930 break;
4931#endif
4932 }
4933 }
4934
4935#if 0
4936 val = get_param(cmd, "FRGMNT");
4937 if (val) {
4938 /* TODO */
4939 send_resp(dut, conn, SIGMA_ERROR,
4940 "ErrorCode,Setting FRGMNT not supported");
4941 return 0;
4942 }
4943#endif
4944
4945#if 0
4946 val = get_param(cmd, "Preamble");
4947 if (val) {
4948 /* TODO: Long/Short */
4949 send_resp(dut, conn, SIGMA_ERROR,
4950 "ErrorCode,Setting Preamble not supported");
4951 return 0;
4952 }
4953#endif
4954
4955 val = get_param(cmd, "Mode");
4956 if (val) {
4957 if (strcmp(val, "11b") == 0 ||
4958 strcmp(val, "11g") == 0 ||
4959 strcmp(val, "11a") == 0 ||
4960 strcmp(val, "11n") == 0 ||
4961 strcmp(val, "11ng") == 0 ||
4962 strcmp(val, "11nl") == 0 ||
4963 strcmp(val, "11nl(nabg)") == 0 ||
4964 strcmp(val, "AC") == 0 ||
4965 strcmp(val, "11AC") == 0 ||
4966 strcmp(val, "11ac") == 0 ||
4967 strcmp(val, "11na") == 0 ||
Amarnath Hullur Subramanyamb0db2712018-01-30 19:40:35 -08004968 strcmp(val, "11an") == 0 ||
4969 strcmp(val, "11ax") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004970 /* STA supports all modes by default */
4971 } else {
4972 send_resp(dut, conn, SIGMA_ERROR,
4973 "ErrorCode,Setting Mode not supported");
4974 return 0;
4975 }
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08004976
4977 /* Change the mode only in case of testbed for HE program
4978 * and for 11a and 11g modes only. */
4979 if (dut->program == PROGRAM_HE &&
4980 dut->device_type == STA_testbed) {
4981 int phymode;
4982 char buf[60];
4983
4984 if (strcmp(val, "11a") == 0) {
Amarnath Hullur Subramanyam94dfaf02018-03-02 19:26:57 -08004985 phymode = 1; /* IEEE80211_MODE_11A */
4986 } else if (strcmp(val, "11g") == 0) {
4987 phymode = 3; /* IEEE80211_MODE_11G */
4988 } else if (strcmp(val, "11b") == 0) {
4989 phymode = 2; /* IEEE80211_MODE_11B */
4990 } else if (strcmp(val, "11n") == 0 ||
4991 strcmp(val, "11nl") == 0 ||
4992 strcmp(val, "11nl(nabg)") == 0) {
4993 phymode = 22; /* IEEE80211_MODE_11AGN */
4994 } else if (strcmp(val, "11ng") == 0) {
4995 phymode = 13; /* IEEE80211_MODE_11NG_HT40 */
4996 } else if (strcmp(val, "AC") == 0 ||
4997 strcasecmp(val, "11AC") == 0) {
4998 phymode = 19; /* IEEE80211_MODE_11AC_VHT80 */
4999 } else if (strcmp(val, "11na") == 0 ||
5000 strcasecmp(val, "11an") == 0) {
5001 phymode = 14; /* IEEE80211_MODE_11NA_HT40 */
5002 } else if (strcmp(val, "11ax") == 0) {
5003 phymode = 0; /* IEEE80211_MODE_AUTO */
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08005004 } else {
5005 sigma_dut_print(dut, DUT_MSG_DEBUG,
5006 "Ignoring mode change for mode: %s",
5007 val);
5008 phymode = -1;
5009 }
5010 if (phymode != -1) {
5011 snprintf(buf, sizeof(buf),
5012 "iwpriv %s setphymode %d",
5013 intf, phymode);
5014 if (system(buf) != 0) {
5015 sigma_dut_print(dut, DUT_MSG_ERROR,
5016 "iwpriv setting of phymode failed");
5017 }
5018 }
5019 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005020 }
5021
5022 val = get_param(cmd, "wmm");
5023 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005024 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005025 case DRIVER_ATHEROS:
5026 ath_sta_set_wmm(dut, intf, val);
5027 break;
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08005028 case DRIVER_WCN:
5029 wcn_sta_set_wmm(dut, intf, val);
5030 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005031 default:
5032 sigma_dut_print(dut, DUT_MSG_DEBUG,
5033 "Setting wmm not supported");
5034 break;
5035 }
5036 }
5037
5038 val = get_param(cmd, "Powersave");
5039 if (val) {
5040 if (strcmp(val, "0") == 0 || strcasecmp(val, "off") == 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, 2) < 0)
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005043 return 0;
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005044 }
5045
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005046 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005047 "P2P_SET ps 0") < 0)
5048 return -2;
5049 /* Make sure test modes are disabled */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005050 wpa_command(get_station_ifname(dut), "P2P_SET ps 98");
5051 wpa_command(get_station_ifname(dut), "P2P_SET ps 96");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005052 } else if (strcmp(val, "1") == 0 ||
5053 strcasecmp(val, "PSPoll") == 0 ||
5054 strcasecmp(val, "on") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005055 if (get_driver_type(dut) == DRIVER_WCN) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +05305056 if (set_power_save_wcn(dut, intf, 1) < 0)
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005057 return 0;
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005058 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005059 /* Disable default power save mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005060 wpa_command(get_station_ifname(dut), "P2P_SET ps 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005061 /* Enable PS-Poll test mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005062 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005063 "P2P_SET ps 97") < 0 ||
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005064 wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005065 "P2P_SET ps 99") < 0)
5066 return -2;
5067 } else if (strcmp(val, "2") == 0 ||
5068 strcasecmp(val, "Fast") == 0) {
5069 /* TODO */
5070 send_resp(dut, conn, SIGMA_ERROR,
5071 "ErrorCode,Powersave=Fast not supported");
5072 return 0;
5073 } else if (strcmp(val, "3") == 0 ||
5074 strcasecmp(val, "PSNonPoll") == 0) {
5075 /* Make sure test modes are disabled */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005076 wpa_command(get_station_ifname(dut), "P2P_SET ps 98");
5077 wpa_command(get_station_ifname(dut), "P2P_SET ps 96");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005078
5079 /* Enable default power save mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005080 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005081 "P2P_SET ps 1") < 0)
5082 return -2;
5083 } else
5084 return -1;
5085 }
5086
5087 val = get_param(cmd, "NoAck");
5088 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005089 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005090 case DRIVER_ATHEROS:
5091 ath_sta_set_noack(dut, intf, val);
5092 break;
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08005093#ifdef NL80211_SUPPORT
5094 case DRIVER_WCN:
5095 wcn_sta_set_noack(dut, intf, val);
5096 break;
5097#endif /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005098 default:
5099 send_resp(dut, conn, SIGMA_ERROR,
5100 "ErrorCode,Setting NoAck not supported");
5101 return 0;
5102 }
5103 }
5104
5105 val = get_param(cmd, "IgnoreChswitchProhibit");
5106 if (val) {
5107 /* TODO: Enabled/disabled */
5108 if (strcasecmp(val, "Enabled") == 0) {
5109 send_resp(dut, conn, SIGMA_ERROR,
5110 "ErrorCode,Enabling IgnoreChswitchProhibit "
5111 "not supported");
5112 return 0;
5113 }
5114 }
5115
5116 val = get_param(cmd, "TDLS");
5117 if (val) {
5118 if (strcasecmp(val, "Disabled") == 0) {
5119 if (wpa_command(intf, "SET tdls_disabled 1")) {
5120 send_resp(dut, conn, SIGMA_ERROR,
5121 "ErrorCode,Failed to disable TDLS");
5122 return 0;
5123 }
5124 } else if (strcasecmp(val, "Enabled") == 0) {
5125 if (wpa_command(intf, "SET tdls_disabled 0")) {
5126 send_resp(dut, conn, SIGMA_ERROR,
5127 "ErrorCode,Failed to enable TDLS");
5128 return 0;
5129 }
5130 } else {
5131 send_resp(dut, conn, SIGMA_ERROR,
5132 "ErrorCode,Unsupported TDLS value");
5133 return 0;
5134 }
5135 }
5136
5137 val = get_param(cmd, "TDLSmode");
5138 if (val) {
5139 if (strcasecmp(val, "Default") == 0) {
5140 wpa_command(intf, "SET tdls_testing 0");
5141 } else if (strcasecmp(val, "APProhibit") == 0) {
5142 if (wpa_command(intf, "SET tdls_testing 0x400")) {
5143 send_resp(dut, conn, SIGMA_ERROR,
5144 "ErrorCode,Failed to enable ignore "
5145 "APProhibit TDLS mode");
5146 return 0;
5147 }
5148 } else if (strcasecmp(val, "HiLoMac") == 0) {
5149 /* STA should respond with TDLS setup req for a TDLS
5150 * setup req */
5151 if (wpa_command(intf, "SET tdls_testing 0x80")) {
5152 send_resp(dut, conn, SIGMA_ERROR,
5153 "ErrorCode,Failed to enable HiLoMac "
5154 "TDLS mode");
5155 return 0;
5156 }
5157 } else if (strcasecmp(val, "WeakSecurity") == 0) {
5158 /*
5159 * Since all security modes are enabled by default when
5160 * Sigma control is used, there is no need to do
5161 * anything here.
5162 */
5163 } else if (strcasecmp(val, "ExistLink") == 0) {
5164 /*
5165 * Since we allow new TDLS Setup Request even if there
5166 * is an existing link, nothing needs to be done for
5167 * this.
5168 */
5169 } else {
5170 /* TODO:
5171 * ExistLink: STA should send TDLS setup req even if
5172 * direct link already exists
5173 */
5174 send_resp(dut, conn, SIGMA_ERROR,
5175 "ErrorCode,Unsupported TDLSmode value");
5176 return 0;
5177 }
5178 }
5179
5180 val = get_param(cmd, "FakePubKey");
5181 if (val && atoi(val) && wpa_command(intf, "SET wps_corrupt_pkhash 1")) {
5182 send_resp(dut, conn, SIGMA_ERROR,
5183 "ErrorCode,Failed to enable FakePubKey");
5184 return 0;
5185 }
5186
Amarnath Hullur Subramanyamae1042b2018-02-22 21:52:52 -08005187#ifdef NL80211_SUPPORT
5188 val = get_param(cmd, "FrgmntSupport");
5189 if (val) {
5190 if (strcasecmp(val, "Enable") == 0) {
5191 if (sta_set_he_fragmentation(dut, intf,
5192 HE_FRAG_LEVEL1)) {
5193 send_resp(dut, conn, SIGMA_ERROR,
5194 "ErrorCode,Failed to enable HE Fragmentation");
5195 return 0;
5196 }
5197 } else if (strcasecmp(val, "Disable") == 0) {
5198 if (sta_set_he_fragmentation(dut, intf,
5199 HE_FRAG_DISABLE)) {
5200 send_resp(dut, conn, SIGMA_ERROR,
5201 "ErrorCode,Failed to disable HE Fragmentation");
5202 return 0;
5203 }
5204 }
5205 }
5206#endif /* NL80211_SUPPORT */
5207
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005208 return 1;
5209}
5210
5211
5212static const char * ath_get_radio_name(const char *radio_name)
5213{
5214 if (radio_name == NULL)
5215 return "wifi0";
5216 if (strcmp(radio_name, "wifi1") == 0)
5217 return "wifi1";
5218 if (strcmp(radio_name, "wifi2") == 0)
5219 return "wifi2";
5220 return "wifi0";
5221}
5222
5223
5224static void ath_sta_set_txsp_stream(struct sigma_dut *dut, const char *intf,
5225 const char *val)
5226{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005227 unsigned int vht_mcsmap = 0;
5228 int txchainmask = 0;
5229 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
5230
5231 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
5232 if (dut->testbed_flag_txsp == 1) {
5233 vht_mcsmap = 0xfffc;
5234 dut->testbed_flag_txsp = 0;
5235 } else {
5236 vht_mcsmap = 0xfffe;
5237 }
5238 txchainmask = 1;
5239 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
5240 if (dut->testbed_flag_txsp == 1) {
5241 vht_mcsmap = 0xfff0;
5242 dut->testbed_flag_txsp = 0;
5243 } else {
5244 vht_mcsmap = 0xfffa;
5245 }
5246 txchainmask = 3;
5247 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
5248 if (dut->testbed_flag_txsp == 1) {
5249 vht_mcsmap = 0xffc0;
5250 dut->testbed_flag_txsp = 0;
5251 } else {
5252 vht_mcsmap = 0xffea;
5253 }
5254 txchainmask = 7;
5255 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
5256 if (dut->testbed_flag_txsp == 1) {
5257 vht_mcsmap = 0xff00;
5258 dut->testbed_flag_txsp = 0;
5259 } else {
5260 vht_mcsmap = 0xffaa;
5261 }
5262 txchainmask = 15;
5263 } else {
5264 if (dut->testbed_flag_txsp == 1) {
5265 vht_mcsmap = 0xffc0;
5266 dut->testbed_flag_txsp = 0;
5267 } else {
5268 vht_mcsmap = 0xffea;
5269 }
5270 }
5271
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005272 if (txchainmask)
5273 run_iwpriv(dut, basedev, "txchainmask %d", txchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005274
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005275 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005276}
5277
5278
5279static void ath_sta_set_rxsp_stream(struct sigma_dut *dut, const char *intf,
5280 const char *val)
5281{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005282 unsigned int vht_mcsmap = 0;
5283 int rxchainmask = 0;
5284 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
5285
5286 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
5287 if (dut->testbed_flag_rxsp == 1) {
5288 vht_mcsmap = 0xfffc;
5289 dut->testbed_flag_rxsp = 0;
5290 } else {
5291 vht_mcsmap = 0xfffe;
5292 }
5293 rxchainmask = 1;
5294 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
5295 if (dut->testbed_flag_rxsp == 1) {
5296 vht_mcsmap = 0xfff0;
5297 dut->testbed_flag_rxsp = 0;
5298 } else {
5299 vht_mcsmap = 0xfffa;
5300 }
5301 rxchainmask = 3;
5302 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
5303 if (dut->testbed_flag_rxsp == 1) {
5304 vht_mcsmap = 0xffc0;
5305 dut->testbed_flag_rxsp = 0;
5306 } else {
5307 vht_mcsmap = 0xffea;
5308 }
5309 rxchainmask = 7;
5310 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
5311 if (dut->testbed_flag_rxsp == 1) {
5312 vht_mcsmap = 0xff00;
5313 dut->testbed_flag_rxsp = 0;
5314 } else {
5315 vht_mcsmap = 0xffaa;
5316 }
5317 rxchainmask = 15;
5318 } else {
5319 if (dut->testbed_flag_rxsp == 1) {
5320 vht_mcsmap = 0xffc0;
5321 dut->testbed_flag_rxsp = 0;
5322 } else {
5323 vht_mcsmap = 0xffea;
5324 }
5325 }
5326
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005327 if (rxchainmask)
5328 run_iwpriv(dut, basedev, "rxchainmask %d", rxchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005329
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005330 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005331}
5332
5333
5334void ath_set_zero_crc(struct sigma_dut *dut, const char *val)
5335{
5336 if (strcasecmp(val, "enable") == 0) {
5337 if (system("athdiag --set --address=0x2a204 --and=0xbfffffff")
5338 != 0) {
5339 sigma_dut_print(dut, DUT_MSG_ERROR,
5340 "Disable BB_VHTSIGB_CRC_CALC failed");
5341 }
5342
5343 if (system("athdiag --set --address=0x2a204 --or=0x80000000")
5344 != 0) {
5345 sigma_dut_print(dut, DUT_MSG_ERROR,
5346 "Enable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
5347 }
5348 } else {
5349 if (system("athdiag --set --address=0x2a204 --and=0x7fffffff")
5350 != 0) {
5351 sigma_dut_print(dut, DUT_MSG_ERROR,
5352 "Disable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
5353 }
5354
5355 if (system("athdiag --set --address=0x2a204 --or=0x40000000")
5356 != 0) {
5357 sigma_dut_print(dut, DUT_MSG_ERROR,
5358 "Enable BB_VHTSIGB_CRC_CALC failed");
5359 }
5360 }
5361}
5362
5363
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005364static int wcn_sta_set_width(struct sigma_dut *dut, const char *intf,
5365 const char *val)
5366{
5367 char buf[60];
5368
5369 if (strcmp(val, "20") == 0) {
5370 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
5371 dut->chwidth = 0;
5372 } else if (strcmp(val, "40") == 0) {
5373 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 1", intf);
5374 dut->chwidth = 1;
5375 } else if (strcmp(val, "80") == 0) {
5376 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
5377 dut->chwidth = 2;
Sunil Duttb1cccac2018-05-22 21:03:12 +05305378 } else if (strcasecmp(val, "Auto") == 0) {
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005379 buf[0] = '\0';
5380 } else {
5381 sigma_dut_print(dut, DUT_MSG_ERROR, "WIDTH %s not supported",
5382 val);
5383 return -1;
5384 }
5385
5386 if (buf[0] != '\0' && system(buf) != 0) {
5387 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv chwidth failed");
5388 return -1;
5389 }
5390
5391 return 0;
5392}
5393
5394
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005395static int nlvendor_sta_set_addba_reject(struct sigma_dut *dut,
5396 const char *intf, int addbareject)
5397{
5398#ifdef NL80211_SUPPORT
5399 struct nl_msg *msg;
5400 int ret = 0;
5401 struct nlattr *params;
5402 int ifindex;
5403
5404 ifindex = if_nametoindex(intf);
5405 if (ifindex == 0) {
5406 sigma_dut_print(dut, DUT_MSG_ERROR,
5407 "%s: Index for interface %s failed",
5408 __func__, intf);
5409 return -1;
5410 }
5411
5412 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5413 NL80211_CMD_VENDOR)) ||
5414 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5415 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5416 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5417 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5418 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5419 nla_put_u8(msg,
5420 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ACCEPT_ADDBA_REQ,
5421 !addbareject)) {
5422 sigma_dut_print(dut, DUT_MSG_ERROR,
5423 "%s: err in adding vendor_cmd and vendor_data",
5424 __func__);
5425 nlmsg_free(msg);
5426 return -1;
5427 }
5428 nla_nest_end(msg, params);
5429
5430 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5431 if (ret) {
5432 sigma_dut_print(dut, DUT_MSG_ERROR,
5433 "%s: err in send_and_recv_msgs, ret=%d",
5434 __func__, ret);
5435 }
5436 return ret;
5437#else /* NL80211_SUPPORT */
5438 sigma_dut_print(dut, DUT_MSG_ERROR,
5439 "ADDBA_REJECT cannot be set without NL80211_SUPPORT defined");
5440 return -1;
5441#endif /* NL80211_SUPPORT */
5442}
5443
5444
5445static int sta_set_addba_reject(struct sigma_dut *dut, const char *intf,
5446 int addbareject)
5447{
5448 int ret;
5449
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005450 switch (get_driver_type(dut)) {
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005451 case DRIVER_WCN:
5452 ret = nlvendor_sta_set_addba_reject(dut, intf, addbareject);
5453 if (ret) {
5454 sigma_dut_print(dut, DUT_MSG_ERROR,
5455 "nlvendor_sta_set_addba_reject failed, ret:%d",
5456 ret);
5457 return ret;
5458 }
5459 break;
5460 default:
5461 sigma_dut_print(dut, DUT_MSG_ERROR,
5462 "errorCode,Unsupported ADDBA_REJECT with the current driver");
5463 ret = -1;
5464 break;
5465 }
5466
5467 return ret;
5468}
5469
5470
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005471static int nlvendor_config_send_addba(struct sigma_dut *dut, const char *intf,
5472 int enable)
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005473{
5474#ifdef NL80211_SUPPORT
5475 struct nl_msg *msg;
5476 int ret = 0;
5477 struct nlattr *params;
5478 int ifindex;
5479
5480 ifindex = if_nametoindex(intf);
5481 if (ifindex == 0) {
5482 sigma_dut_print(dut, DUT_MSG_ERROR,
5483 "%s: Index for interface %s failed",
5484 __func__, intf);
5485 return -1;
5486 }
5487
5488 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5489 NL80211_CMD_VENDOR)) ||
5490 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5491 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5492 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5493 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5494 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5495 nla_put_u8(msg,
5496 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SEND_ADDBA_REQ,
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005497 enable)) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005498 sigma_dut_print(dut, DUT_MSG_ERROR,
5499 "%s: err in adding vendor_cmd and vendor_data",
5500 __func__);
5501 nlmsg_free(msg);
5502 return -1;
5503 }
5504 nla_nest_end(msg, params);
5505
5506 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5507 if (ret) {
5508 sigma_dut_print(dut, DUT_MSG_ERROR,
5509 "%s: err in send_and_recv_msgs, ret=%d",
5510 __func__, ret);
5511 }
5512 return ret;
5513#else /* NL80211_SUPPORT */
5514 sigma_dut_print(dut, DUT_MSG_ERROR,
5515 "Disable addba not possible without NL80211_SUPPORT defined");
5516 return -1;
5517#endif /* NL80211_SUPPORT */
5518}
5519
5520
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305521#ifdef NL80211_SUPPORT
5522static int nl80211_sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
5523{
5524 struct nl_msg *msg;
5525 int ret = 0;
5526 int ifindex;
5527
5528 ifindex = if_nametoindex(intf);
5529 if (ifindex == 0) {
5530 sigma_dut_print(dut, DUT_MSG_ERROR,
5531 "%s: Index for interface %s failed",
5532 __func__, intf);
5533 return -1;
5534 }
5535
5536 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5537 NL80211_CMD_SET_WIPHY)) ||
5538 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) {
5539 sigma_dut_print(dut, DUT_MSG_ERROR,
5540 "%s: err in adding RTS threshold",
5541 __func__);
5542 nlmsg_free(msg);
5543 return -1;
5544 }
5545
5546 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5547 if (ret) {
5548 sigma_dut_print(dut, DUT_MSG_ERROR,
5549 "%s: err in send_and_recv_msgs, ret=%d",
5550 __func__, ret);
5551 }
5552 return ret;
5553}
5554#endif /* NL80211_SUPPORT */
5555
5556
5557static int sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
5558{
5559 char buf[100];
5560
5561#ifdef NL80211_SUPPORT
5562 if (nl80211_sta_set_rts(dut, intf, val) == 0)
5563 return 0;
5564 sigma_dut_print(dut, DUT_MSG_DEBUG,
5565 "Fall back to using iwconfig for setting RTS threshold");
5566#endif /* NL80211_SUPPORT */
5567
5568 snprintf(buf, sizeof(buf), "iwconfig %s rts %d", intf, val);
5569 if (system(buf) != 0) {
5570 sigma_dut_print(dut, DUT_MSG_ERROR,
5571 "Failed to set RTS threshold %d", val);
5572 return -1;
5573 }
5574 return 0;
5575}
5576
5577
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005578static int cmd_sta_set_wireless_common(const char *intf, struct sigma_dut *dut,
5579 struct sigma_conn *conn,
5580 struct sigma_cmd *cmd)
5581{
5582 const char *val;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005583 int ampdu = -1, addbareject = -1;
Jouni Malinen3aa72862019-05-29 23:14:51 +03005584 char buf[128];
5585 int res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005586
5587 val = get_param(cmd, "40_INTOLERANT");
5588 if (val) {
5589 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5590 /* TODO: iwpriv ht40intol through wpa_supplicant */
5591 send_resp(dut, conn, SIGMA_ERROR,
5592 "ErrorCode,40_INTOLERANT not supported");
5593 return 0;
5594 }
5595 }
5596
5597 val = get_param(cmd, "ADDBA_REJECT");
5598 if (val) {
5599 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5600 /* reject any ADDBA with status "decline" */
5601 ampdu = 0;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005602 addbareject = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005603 } else {
5604 /* accept ADDBA */
5605 ampdu = 1;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005606 addbareject = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005607 }
5608 }
5609
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005610 if (addbareject >= 0 &&
5611 sta_set_addba_reject(dut, intf, addbareject) < 0) {
5612 send_resp(dut, conn, SIGMA_ERROR,
5613 "ErrorCode,set addba_reject failed");
5614 return 0;
5615 }
5616
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005617 val = get_param(cmd, "AMPDU");
5618 if (val) {
5619 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5620 /* enable AMPDU Aggregation */
5621 if (ampdu == 0) {
5622 send_resp(dut, conn, SIGMA_ERROR,
5623 "ErrorCode,Mismatch in "
5624 "addba_reject/ampdu - "
5625 "not supported");
5626 return 0;
5627 }
5628 ampdu = 1;
5629 } else {
5630 /* disable AMPDU Aggregation */
5631 if (ampdu == 1) {
5632 send_resp(dut, conn, SIGMA_ERROR,
5633 "ErrorCode,Mismatch in "
5634 "addba_reject/ampdu - "
5635 "not supported");
5636 return 0;
5637 }
5638 ampdu = 0;
5639 }
5640 }
5641
5642 if (ampdu >= 0) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005643 int ret;
5644
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005645 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s A-MPDU aggregation",
5646 ampdu ? "Enabling" : "Disabling");
5647 snprintf(buf, sizeof(buf), "SET ampdu %d", ampdu);
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07005648 if (wpa_command(intf, buf) < 0 &&
5649 iwpriv_sta_set_ampdu(dut, intf, ampdu) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005650 send_resp(dut, conn, SIGMA_ERROR,
5651 "ErrorCode,set aggr failed");
5652 return 0;
5653 }
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005654
5655 if (ampdu == 0) {
5656 /* Disable sending of addba using nl vendor command */
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005657 ret = nlvendor_config_send_addba(dut, intf, 0);
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005658 if (ret) {
5659 sigma_dut_print(dut, DUT_MSG_ERROR,
5660 "Failed to disable addba, ret:%d",
5661 ret);
5662 }
5663 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005664 }
5665
5666 val = get_param(cmd, "AMSDU");
5667 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005668 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005669 case DRIVER_ATHEROS:
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08005670 case DRIVER_WCN:
5671 iwpriv_sta_set_amsdu(dut, intf, val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005672 break;
5673 default:
5674 if (strcmp(val, "1") == 0 ||
5675 strcasecmp(val, "Enable") == 0) {
5676 /* Enable AMSDU Aggregation */
5677 send_resp(dut, conn, SIGMA_ERROR,
5678 "ErrorCode,AMSDU aggregation not supported");
5679 return 0;
5680 }
5681 break;
5682 }
5683 }
5684
5685 val = get_param(cmd, "STBC_RX");
5686 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005687 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005688 case DRIVER_ATHEROS:
5689 ath_sta_set_stbc(dut, intf, val);
5690 break;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05305691 case DRIVER_WCN:
5692 wcn_sta_set_stbc(dut, intf, val);
5693 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005694 default:
5695 send_resp(dut, conn, SIGMA_ERROR,
5696 "ErrorCode,STBC_RX not supported");
5697 return 0;
5698 }
5699 }
5700
5701 val = get_param(cmd, "WIDTH");
5702 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005703 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005704 case DRIVER_WCN:
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005705 if (wcn_sta_set_width(dut, intf, val) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005706 send_resp(dut, conn, SIGMA_ERROR,
5707 "ErrorCode,Failed to set WIDTH");
5708 return 0;
5709 }
5710 break;
5711 case DRIVER_ATHEROS:
5712 if (ath_set_width(dut, conn, intf, val) < 0)
5713 return 0;
5714 break;
5715 default:
5716 sigma_dut_print(dut, DUT_MSG_ERROR,
5717 "Setting WIDTH not supported");
5718 break;
5719 }
5720 }
5721
5722 val = get_param(cmd, "SMPS");
5723 if (val) {
5724 /* TODO: Dynamic/0, Static/1, No Limit/2 */
5725 send_resp(dut, conn, SIGMA_ERROR,
5726 "ErrorCode,SMPS not supported");
5727 return 0;
5728 }
5729
5730 val = get_param(cmd, "TXSP_STREAM");
5731 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005732 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005733 case DRIVER_WCN:
5734 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
5735 send_resp(dut, conn, SIGMA_ERROR,
5736 "ErrorCode,Failed to set TXSP_STREAM");
5737 return 0;
5738 }
5739 break;
5740 case DRIVER_ATHEROS:
5741 ath_sta_set_txsp_stream(dut, intf, val);
5742 break;
5743 default:
5744 sigma_dut_print(dut, DUT_MSG_ERROR,
5745 "Setting TXSP_STREAM not supported");
5746 break;
5747 }
5748 }
5749
5750 val = get_param(cmd, "RXSP_STREAM");
5751 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005752 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005753 case DRIVER_WCN:
5754 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
5755 send_resp(dut, conn, SIGMA_ERROR,
5756 "ErrorCode,Failed to set RXSP_STREAM");
5757 return 0;
5758 }
5759 break;
5760 case DRIVER_ATHEROS:
5761 ath_sta_set_rxsp_stream(dut, intf, val);
5762 break;
5763 default:
5764 sigma_dut_print(dut, DUT_MSG_ERROR,
5765 "Setting RXSP_STREAM not supported");
5766 break;
5767 }
5768 }
5769
5770 val = get_param(cmd, "DYN_BW_SGNL");
5771 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005772 switch (get_driver_type(dut)) {
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005773 case DRIVER_WCN:
Peng Xuc59afd32016-11-21 15:01:11 -08005774 if (strcasecmp(val, "enable") == 0) {
5775 snprintf(buf, sizeof(buf),
5776 "iwpriv %s cwmenable 1", intf);
5777 if (system(buf) != 0) {
5778 sigma_dut_print(dut, DUT_MSG_ERROR,
5779 "iwpriv cwmenable 1 failed");
5780 return 0;
5781 }
5782 } else if (strcasecmp(val, "disable") == 0) {
5783 snprintf(buf, sizeof(buf),
5784 "iwpriv %s cwmenable 0", intf);
5785 if (system(buf) != 0) {
5786 sigma_dut_print(dut, DUT_MSG_ERROR,
5787 "iwpriv cwmenable 0 failed");
5788 return 0;
5789 }
5790 } else {
5791 sigma_dut_print(dut, DUT_MSG_ERROR,
5792 "Unsupported DYN_BW_SGL");
5793 }
5794
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005795 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
5796 if (system(buf) != 0) {
5797 sigma_dut_print(dut, DUT_MSG_ERROR,
5798 "Failed to set cts_cbw in DYN_BW_SGNL");
5799 return 0;
5800 }
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005801 break;
5802 case DRIVER_ATHEROS:
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07005803 novap_reset(dut, intf, 1);
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005804 ath_config_dyn_bw_sig(dut, intf, val);
5805 break;
5806 default:
5807 sigma_dut_print(dut, DUT_MSG_ERROR,
5808 "Failed to set DYN_BW_SGNL");
5809 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005810 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005811 }
5812
5813 val = get_param(cmd, "RTS_FORCE");
5814 if (val) {
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07005815 novap_reset(dut, intf, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005816 if (strcasecmp(val, "Enable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305817 if (sta_set_rts(dut, intf, 64) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02005818 sigma_dut_print(dut, DUT_MSG_ERROR,
5819 "Failed to set RTS_FORCE 64");
5820 }
Jouni Malinen3aa72862019-05-29 23:14:51 +03005821 res = snprintf(buf, sizeof(buf),
5822 "wifitool %s beeliner_fw_test 100 1",
5823 intf);
5824 if (res < 0 || res >= sizeof(buf) || system(buf) != 0) {
priyadharshini gowthaman270870e2015-12-09 10:10:23 -08005825 sigma_dut_print(dut, DUT_MSG_ERROR,
5826 "wifitool beeliner_fw_test 100 1 failed");
5827 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005828 } else if (strcasecmp(val, "Disable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305829 if (sta_set_rts(dut, intf, 2347) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02005830 sigma_dut_print(dut, DUT_MSG_ERROR,
5831 "Failed to set RTS_FORCE 2347");
5832 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005833 } else {
5834 send_resp(dut, conn, SIGMA_ERROR,
5835 "ErrorCode,RTS_FORCE value not supported");
5836 return 0;
5837 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005838 }
5839
5840 val = get_param(cmd, "CTS_WIDTH");
5841 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005842 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005843 case DRIVER_WCN:
5844 if (wcn_sta_set_cts_width(dut, intf, val) < 0) {
5845 send_resp(dut, conn, SIGMA_ERROR,
5846 "ErrorCode,Failed to set CTS_WIDTH");
5847 return 0;
5848 }
5849 break;
5850 case DRIVER_ATHEROS:
5851 ath_set_cts_width(dut, intf, val);
5852 break;
5853 default:
5854 sigma_dut_print(dut, DUT_MSG_ERROR,
5855 "Setting CTS_WIDTH not supported");
5856 break;
5857 }
5858 }
5859
5860 val = get_param(cmd, "BW_SGNL");
5861 if (val) {
5862 if (strcasecmp(val, "Enable") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005863 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005864 } else if (strcasecmp(val, "Disable") == 0) {
5865 /* TODO: Disable */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005866 } else {
5867 send_resp(dut, conn, SIGMA_ERROR,
5868 "ErrorCode,BW_SGNL value not supported");
5869 return 0;
5870 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005871 }
5872
5873 val = get_param(cmd, "Band");
5874 if (val) {
5875 if (strcmp(val, "2.4") == 0 || strcmp(val, "5") == 0) {
5876 /* STA supports all bands by default */
5877 } else {
5878 send_resp(dut, conn, SIGMA_ERROR,
5879 "ErrorCode,Unsupported Band");
5880 return 0;
5881 }
5882 }
5883
5884 val = get_param(cmd, "zero_crc");
5885 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005886 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005887 case DRIVER_ATHEROS:
5888 ath_set_zero_crc(dut, val);
5889 break;
5890 default:
5891 break;
5892 }
5893 }
5894
5895 return 1;
5896}
5897
5898
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005899static int sta_set_force_mcs(struct sigma_dut *dut, int force, int mcs)
5900{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005901 switch (get_driver_type(dut)) {
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005902#ifdef __linux__
5903 case DRIVER_WIL6210:
5904 return wil6210_set_force_mcs(dut, force, mcs);
5905#endif /* __linux__ */
5906 default:
5907 sigma_dut_print(dut, DUT_MSG_ERROR,
5908 "Unsupported sta_set_force_mcs with the current driver");
5909 return -1;
5910 }
5911}
5912
5913
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02005914static int sta_60g_force_rsn_ie(struct sigma_dut *dut, int state)
5915{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005916 switch (get_driver_type(dut)) {
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02005917#ifdef __linux__
5918 case DRIVER_WIL6210:
5919 return wil6210_force_rsn_ie(dut, state);
5920#endif /* __linux__ */
5921 default:
5922 sigma_dut_print(dut, DUT_MSG_ERROR,
5923 "Unsupported sta_60g_force_rsn_ie with the current driver");
5924 return -1;
5925 }
5926}
5927
5928
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005929static int sta_set_60g_common(struct sigma_dut *dut, struct sigma_conn *conn,
5930 struct sigma_cmd *cmd)
5931{
5932 const char *val;
5933 char buf[100];
5934
5935 val = get_param(cmd, "MSDUSize");
5936 if (val) {
5937 int mtu;
5938
5939 dut->amsdu_size = atoi(val);
5940 if (dut->amsdu_size > IEEE80211_MAX_DATA_LEN_DMG ||
5941 dut->amsdu_size < IEEE80211_SNAP_LEN_DMG) {
5942 sigma_dut_print(dut, DUT_MSG_ERROR,
5943 "MSDUSize %d is above max %d or below min %d",
5944 dut->amsdu_size,
5945 IEEE80211_MAX_DATA_LEN_DMG,
5946 IEEE80211_SNAP_LEN_DMG);
5947 dut->amsdu_size = 0;
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005948 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005949 }
5950
5951 mtu = dut->amsdu_size - IEEE80211_SNAP_LEN_DMG;
5952 sigma_dut_print(dut, DUT_MSG_DEBUG,
5953 "Setting amsdu_size to %d", mtu);
5954 snprintf(buf, sizeof(buf), "ifconfig %s mtu %d",
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005955 get_station_ifname(dut), mtu);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005956
5957 if (system(buf) != 0) {
5958 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
5959 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005960 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005961 }
5962 }
5963
5964 val = get_param(cmd, "BAckRcvBuf");
5965 if (val) {
5966 dut->back_rcv_buf = atoi(val);
5967 if (dut->back_rcv_buf == 0) {
5968 sigma_dut_print(dut, DUT_MSG_ERROR,
5969 "Failed to convert %s or value is 0",
5970 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005971 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005972 }
5973
5974 sigma_dut_print(dut, DUT_MSG_DEBUG,
5975 "Setting BAckRcvBuf to %s", val);
5976 }
5977
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005978 val = get_param(cmd, "MCS_FixedRate");
5979 if (val) {
5980 if (sta_set_force_mcs(dut, 1, atoi(val))) {
5981 sigma_dut_print(dut, DUT_MSG_ERROR,
5982 "Failed to force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005983 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005984 }
5985 }
5986
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005987 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005988}
5989
5990
5991static int sta_pcp_start(struct sigma_dut *dut, struct sigma_conn *conn,
5992 struct sigma_cmd *cmd)
5993{
5994 int net_id;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005995 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005996 const char *val;
5997 char buf[100];
5998
5999 dut->mode = SIGMA_MODE_STATION;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006000 ifname = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006001 if (wpa_command(ifname, "PING") != 0) {
6002 sigma_dut_print(dut, DUT_MSG_ERROR, "Supplicant not running");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006003 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006004 }
6005
6006 wpa_command(ifname, "FLUSH");
6007 net_id = add_network_common(dut, conn, ifname, cmd);
6008 if (net_id < 0) {
6009 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add network");
6010 return net_id;
6011 }
6012
6013 /* TODO: mode=2 for the AP; in the future, replace for mode PCP */
6014 if (set_network(ifname, net_id, "mode", "2") < 0) {
6015 sigma_dut_print(dut, DUT_MSG_ERROR,
6016 "Failed to set supplicant network mode");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006017 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006018 }
6019
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02006020 if (set_network(ifname, net_id, "pbss", "1") < 0)
6021 return -2;
6022
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006023 sigma_dut_print(dut, DUT_MSG_DEBUG,
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02006024 "Supplicant set network with mode 2. network_id %d",
6025 net_id);
6026
6027 if (set_network(ifname, net_id, "wps_disabled", "0") < 0) {
6028 sigma_dut_print(dut, DUT_MSG_INFO,
6029 "Failed to set supplicant to WPS ENABLE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006030 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02006031 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006032
6033 val = get_param(cmd, "Security");
6034 if (val && strcasecmp(val, "OPEN") == 0) {
6035 dut->ap_key_mgmt = AP_OPEN;
6036 if (set_network(ifname, net_id, "key_mgmt", "NONE") < 0) {
6037 sigma_dut_print(dut, DUT_MSG_ERROR,
6038 "Failed to set supplicant to %s security",
6039 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006040 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006041 }
6042 } else if (val && strcasecmp(val, "WPA2-PSK") == 0) {
6043 dut->ap_key_mgmt = AP_WPA2_PSK;
6044 if (set_network(ifname, net_id, "key_mgmt", "WPA-PSK") < 0) {
6045 sigma_dut_print(dut, DUT_MSG_ERROR,
6046 "Failed to set supplicant to %s security",
6047 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006048 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006049 }
6050
6051 if (set_network(ifname, net_id, "proto", "RSN") < 0) {
6052 sigma_dut_print(dut, DUT_MSG_ERROR,
6053 "Failed to set supplicant to proto RSN");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006054 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006055 }
6056 } else if (val) {
6057 sigma_dut_print(dut, DUT_MSG_ERROR,
6058 "Requested Security %s is not supported on 60GHz",
6059 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006060 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006061 }
6062
6063 val = get_param(cmd, "Encrypt");
6064 if (val && strcasecmp(val, "AES-GCMP") == 0) {
6065 if (set_network(ifname, net_id, "pairwise", "GCMP") < 0) {
6066 sigma_dut_print(dut, DUT_MSG_ERROR,
6067 "Failed to set supplicant to pairwise GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006068 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006069 }
6070 if (set_network(ifname, net_id, "group", "GCMP") < 0) {
6071 sigma_dut_print(dut, DUT_MSG_ERROR,
6072 "Failed to set supplicant to group GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006073 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006074 }
6075 } else if (val) {
6076 sigma_dut_print(dut, DUT_MSG_ERROR,
6077 "Requested Encrypt %s is not supported on 60 GHz",
6078 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006079 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006080 }
6081
6082 val = get_param(cmd, "PSK");
6083 if (val && set_network_quoted(ifname, net_id, "psk", val) < 0) {
6084 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set psk %s",
6085 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006086 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006087 }
6088
6089 /* Convert 60G channel to freq */
6090 switch (dut->ap_channel) {
6091 case 1:
6092 val = "58320";
6093 break;
6094 case 2:
6095 val = "60480";
6096 break;
6097 case 3:
6098 val = "62640";
6099 break;
6100 default:
6101 sigma_dut_print(dut, DUT_MSG_ERROR,
6102 "Failed to configure channel %d. Not supported",
6103 dut->ap_channel);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006104 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006105 }
6106
6107 if (set_network(ifname, net_id, "frequency", val) < 0) {
6108 sigma_dut_print(dut, DUT_MSG_ERROR,
6109 "Failed to set supplicant network frequency");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006110 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006111 }
6112
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02006113 if (dut->eap_fragment) {
6114 sigma_dut_print(dut, DUT_MSG_DEBUG,
6115 "Set EAP fragment size to 128 bytes.");
6116 if (set_network(ifname, net_id, "fragment_size", "128") < 0)
6117 return ERROR_SEND_STATUS;
6118 }
6119
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006120 sigma_dut_print(dut, DUT_MSG_DEBUG,
6121 "Supplicant set network with frequency");
6122
6123 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d", net_id);
6124 if (wpa_command(ifname, buf) < 0) {
6125 sigma_dut_print(dut, DUT_MSG_INFO,
6126 "Failed to select network id %d on %s",
6127 net_id, ifname);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006128 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006129 }
6130
6131 sigma_dut_print(dut, DUT_MSG_DEBUG, "Selected network");
6132
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006133 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006134}
6135
6136
Lior David67543f52017-01-03 19:04:22 +02006137static int wil6210_set_abft_len(struct sigma_dut *dut, int abft_len)
6138{
6139 char buf[128], fname[128];
6140 FILE *f;
Jouni Malinen3aa72862019-05-29 23:14:51 +03006141 int res;
Lior David67543f52017-01-03 19:04:22 +02006142
6143 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
6144 sigma_dut_print(dut, DUT_MSG_ERROR,
6145 "failed to get wil6210 debugfs dir");
6146 return -1;
6147 }
6148
Jouni Malinen3aa72862019-05-29 23:14:51 +03006149 res = snprintf(fname, sizeof(fname), "%s/abft_len", buf);
6150 if (res < 0 || res >= sizeof(fname))
6151 return -1;
Lior David67543f52017-01-03 19:04:22 +02006152 f = fopen(fname, "w");
6153 if (!f) {
6154 sigma_dut_print(dut, DUT_MSG_ERROR,
6155 "failed to open: %s", fname);
6156 return -1;
6157 }
6158
6159 fprintf(f, "%d\n", abft_len);
6160 fclose(f);
6161
6162 return 0;
6163}
6164
6165
Alexei Avshalom Lazar49498b82019-01-31 15:16:32 +02006166int sta_set_60g_abft_len(struct sigma_dut *dut, struct sigma_conn *conn,
6167 int abft_len)
Lior David67543f52017-01-03 19:04:22 +02006168{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006169 switch (get_driver_type(dut)) {
Lior David67543f52017-01-03 19:04:22 +02006170 case DRIVER_WIL6210:
6171 return wil6210_set_abft_len(dut, abft_len);
6172 default:
6173 sigma_dut_print(dut, DUT_MSG_ERROR,
6174 "set abft_len not supported");
6175 return -1;
6176 }
6177}
6178
6179
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006180static int sta_set_60g_pcp(struct sigma_dut *dut, struct sigma_conn *conn,
6181 struct sigma_cmd *cmd)
6182{
6183 const char *val;
Lior David67543f52017-01-03 19:04:22 +02006184 unsigned int abft_len = 1; /* default is one slot */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006185
6186 if (dut->dev_role != DEVROLE_PCP) {
6187 send_resp(dut, conn, SIGMA_INVALID,
6188 "ErrorCode,Invalid DevRole");
6189 return 0;
6190 }
6191
6192 val = get_param(cmd, "SSID");
6193 if (val) {
6194 if (strlen(val) > sizeof(dut->ap_ssid) - 1) {
6195 send_resp(dut, conn, SIGMA_INVALID,
6196 "ErrorCode,Invalid SSID");
6197 return -1;
6198 }
6199
Peng Xub8fc5cc2017-05-10 17:27:28 -07006200 strlcpy(dut->ap_ssid, val, sizeof(dut->ap_ssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006201 }
6202
6203 val = get_param(cmd, "CHANNEL");
6204 if (val) {
6205 const char *pos;
6206
6207 dut->ap_channel = atoi(val);
6208 pos = strchr(val, ';');
6209 if (pos) {
6210 pos++;
6211 dut->ap_channel_1 = atoi(pos);
6212 }
6213 }
6214
6215 switch (dut->ap_channel) {
6216 case 1:
6217 case 2:
6218 case 3:
6219 break;
6220 default:
6221 sigma_dut_print(dut, DUT_MSG_ERROR,
6222 "Channel %d is not supported", dut->ap_channel);
6223 send_resp(dut, conn, SIGMA_ERROR,
6224 "Requested channel is not supported");
6225 return -1;
6226 }
6227
6228 val = get_param(cmd, "BCNINT");
6229 if (val)
6230 dut->ap_bcnint = atoi(val);
6231
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006232 val = get_param(cmd, "AllocType");
6233 if (val) {
6234 send_resp(dut, conn, SIGMA_ERROR,
6235 "ErrorCode,AllocType is not supported yet");
6236 return -1;
6237 }
6238
6239 val = get_param(cmd, "PercentBI");
6240 if (val) {
6241 send_resp(dut, conn, SIGMA_ERROR,
6242 "ErrorCode,PercentBI is not supported yet");
6243 return -1;
6244 }
6245
6246 val = get_param(cmd, "CBAPOnly");
6247 if (val) {
6248 send_resp(dut, conn, SIGMA_ERROR,
6249 "ErrorCode,CBAPOnly is not supported yet");
6250 return -1;
6251 }
6252
6253 val = get_param(cmd, "AMPDU");
6254 if (val) {
6255 if (strcasecmp(val, "Enable") == 0)
6256 dut->ap_ampdu = 1;
6257 else if (strcasecmp(val, "Disable") == 0)
6258 dut->ap_ampdu = 2;
6259 else {
6260 send_resp(dut, conn, SIGMA_ERROR,
6261 "ErrorCode,AMPDU value is not Enable nor Disabled");
6262 return -1;
6263 }
6264 }
6265
6266 val = get_param(cmd, "AMSDU");
6267 if (val) {
6268 if (strcasecmp(val, "Enable") == 0)
6269 dut->ap_amsdu = 1;
6270 else if (strcasecmp(val, "Disable") == 0)
6271 dut->ap_amsdu = 2;
6272 }
6273
6274 val = get_param(cmd, "NumMSDU");
6275 if (val) {
6276 send_resp(dut, conn, SIGMA_ERROR,
6277 "ErrorCode, NumMSDU is not supported yet");
6278 return -1;
6279 }
6280
6281 val = get_param(cmd, "ABFTLRang");
6282 if (val) {
6283 sigma_dut_print(dut, DUT_MSG_DEBUG,
Lior David67543f52017-01-03 19:04:22 +02006284 "ABFTLRang parameter %s", val);
6285 if (strcmp(val, "Gt1") == 0)
6286 abft_len = 2; /* 2 slots in this case */
6287 }
6288
6289 if (sta_set_60g_abft_len(dut, conn, abft_len)) {
6290 send_resp(dut, conn, SIGMA_ERROR,
6291 "ErrorCode, Can't set ABFT length");
6292 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006293 }
6294
6295 if (sta_pcp_start(dut, conn, cmd) < 0) {
6296 send_resp(dut, conn, SIGMA_ERROR,
6297 "ErrorCode, Can't start PCP role");
6298 return -1;
6299 }
6300
6301 return sta_set_60g_common(dut, conn, cmd);
6302}
6303
6304
6305static int sta_set_60g_sta(struct sigma_dut *dut, struct sigma_conn *conn,
6306 struct sigma_cmd *cmd)
6307{
6308 const char *val = get_param(cmd, "DiscoveryMode");
6309
6310 if (dut->dev_role != DEVROLE_STA) {
6311 send_resp(dut, conn, SIGMA_INVALID,
6312 "ErrorCode,Invalid DevRole");
6313 return 0;
6314 }
6315
6316 if (val) {
6317 sigma_dut_print(dut, DUT_MSG_DEBUG, "Discovery: %s", val);
6318 /* Ignore Discovery mode till Driver expose API. */
6319#if 0
6320 if (strcasecmp(val, "1") == 0) {
6321 send_resp(dut, conn, SIGMA_INVALID,
6322 "ErrorCode,DiscoveryMode 1 not supported");
6323 return 0;
6324 }
6325
6326 if (strcasecmp(val, "0") == 0) {
6327 /* OK */
6328 } else {
6329 send_resp(dut, conn, SIGMA_INVALID,
6330 "ErrorCode,DiscoveryMode not supported");
6331 return 0;
6332 }
6333#endif
6334 }
6335
6336 if (start_sta_mode(dut) != 0)
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006337 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006338 return sta_set_60g_common(dut, conn, cmd);
6339}
6340
6341
Jouni Malinenf7222712019-06-13 01:50:21 +03006342static enum sigma_cmd_result cmd_sta_disconnect(struct sigma_dut *dut,
6343 struct sigma_conn *conn,
6344 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006345{
6346 const char *intf = get_param(cmd, "Interface");
Jouni Malinened77e672018-01-10 16:45:13 +02006347 const char *val = get_param(cmd, "maintain_profile");
vamsi krishnad605c422017-09-20 14:56:31 +05306348
Jouni Malinened77e672018-01-10 16:45:13 +02006349 if (dut->program == PROGRAM_OCE ||
Amarnath Hullur Subramanyamebeda9e2018-01-31 03:21:48 -08006350 dut->program == PROGRAM_HE ||
Jouni Malinened77e672018-01-10 16:45:13 +02006351 (val && atoi(val) == 1)) {
vamsi krishnad605c422017-09-20 14:56:31 +05306352 wpa_command(intf, "DISCONNECT");
6353 return 1;
6354 }
6355
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006356 disconnect_station(dut);
6357 /* Try to ignore old scan results to avoid HS 2.0R2 test case failures
6358 * due to cached results. */
6359 wpa_command(intf, "SET ignore_old_scan_res 1");
6360 wpa_command(intf, "BSS_FLUSH");
6361 return 1;
6362}
6363
6364
Jouni Malinenf7222712019-06-13 01:50:21 +03006365static enum sigma_cmd_result cmd_sta_reassoc(struct sigma_dut *dut,
6366 struct sigma_conn *conn,
6367 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006368{
6369 const char *intf = get_param(cmd, "Interface");
6370 const char *bssid = get_param(cmd, "bssid");
6371 const char *val = get_param(cmd, "CHANNEL");
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006372 const char *freq_val = get_param(cmd, "ChnlFreq");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006373 struct wpa_ctrl *ctrl;
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306374 char buf[1000];
Sunil Duttd30ce092018-01-11 23:56:29 +05306375 char result[32];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006376 int res;
6377 int chan = 0;
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006378 int freq = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006379 enum sigma_cmd_result status = STATUS_SENT;
Sunil Duttd30ce092018-01-11 23:56:29 +05306380 int fastreassoc = 1;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006381 int ft_ds = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006382
6383 if (bssid == NULL) {
6384 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing bssid "
6385 "argument");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006386 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006387 }
6388
6389 if (val)
6390 chan = atoi(val);
6391
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006392 if (freq_val)
6393 freq = atoi(freq_val);
6394
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006395 if (wifi_chip_type != DRIVER_WCN && wifi_chip_type != DRIVER_AR6003) {
6396 /* The current network may be from sta_associate or
6397 * sta_hs2_associate
6398 */
6399 if (set_network(intf, dut->infra_network_id, "bssid", bssid) <
6400 0 ||
6401 set_network(intf, 0, "bssid", bssid) < 0)
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006402 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006403 }
6404
6405 ctrl = open_wpa_mon(intf);
6406 if (ctrl == NULL) {
6407 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
6408 "wpa_supplicant monitor connection");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006409 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006410 }
6411
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006412 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Sunil Duttd30ce092018-01-11 23:56:29 +05306413 sizeof(result)) < 0 ||
6414 strncmp(result, "COMPLETED", 9) != 0) {
6415 sigma_dut_print(dut, DUT_MSG_DEBUG,
6416 "sta_reassoc: Not connected");
6417 fastreassoc = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006418 } else if (dut->sta_ft_ds) {
6419 sigma_dut_print(dut, DUT_MSG_DEBUG,
6420 "sta_reassoc: Use FT-over-DS");
6421 ft_ds = 1;
Sunil Duttd30ce092018-01-11 23:56:29 +05306422 }
6423
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306424 if (dut->rsne_override) {
6425#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006426 if (get_driver_type(dut) == DRIVER_WCN &&
6427 dut->config_rsnie == 0) {
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306428 sta_config_rsnie(dut, 1);
6429 dut->config_rsnie = 1;
6430 }
6431#endif /* NL80211_SUPPORT */
6432 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
6433 dut->rsne_override);
6434 if (wpa_command(intf, buf) < 0) {
6435 send_resp(dut, conn, SIGMA_ERROR,
6436 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
6437 return 0;
6438 }
6439 }
6440
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006441 if (ft_ds) {
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006442 if (chan || freq) {
6443 if (!freq)
6444 freq = channel_to_freq(dut, chan);
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006445 if (!freq) {
6446 sigma_dut_print(dut, DUT_MSG_ERROR,
6447 "Invalid channel number provided: %d",
6448 chan);
6449 send_resp(dut, conn, SIGMA_INVALID,
6450 "ErrorCode,Invalid channel number");
6451 goto close_mon_conn;
6452 }
6453 res = snprintf(buf, sizeof(buf),
6454 "SCAN TYPE=ONLY freq=%d", freq);
6455 } else {
6456 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
6457 }
6458 if (res < 0 || res >= (int) sizeof(buf)) {
6459 send_resp(dut, conn, SIGMA_ERROR,
6460 "ErrorCode,snprintf failed");
6461 goto close_mon_conn;
6462 }
6463 if (wpa_command(intf, buf) < 0) {
6464 sigma_dut_print(dut, DUT_MSG_INFO,
6465 "Failed to start scan");
6466 send_resp(dut, conn, SIGMA_ERROR,
6467 "ErrorCode,scan failed");
6468 goto close_mon_conn;
6469 }
6470
6471 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
6472 buf, sizeof(buf));
6473 if (res < 0) {
6474 sigma_dut_print(dut, DUT_MSG_INFO,
6475 "Scan did not complete");
6476 send_resp(dut, conn, SIGMA_ERROR,
6477 "ErrorCode,scan did not complete");
6478 goto close_mon_conn;
6479 }
6480
6481 res = snprintf(buf, sizeof(buf), "FT_DS %s", bssid);
6482 if (res > 0 && res < (int) sizeof(buf))
6483 res = wpa_command(intf, buf);
6484
6485 if (res < 0 || res >= (int) sizeof(buf)) {
6486 send_resp(dut, conn, SIGMA_ERROR,
6487 "errorCode,FT_DS command failed");
6488 status = STATUS_SENT_ERROR;
6489 goto close_mon_conn;
6490 }
6491 } else if (wifi_chip_type == DRIVER_WCN && fastreassoc) {
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006492 if (chan || freq) {
6493 if (!freq)
6494 freq = channel_to_freq(dut, chan);
Ashwini Patil4c8158f2017-05-25 12:49:21 +05306495 if (!freq) {
6496 sigma_dut_print(dut, DUT_MSG_ERROR,
6497 "Invalid channel number provided: %d",
6498 chan);
6499 send_resp(dut, conn, SIGMA_INVALID,
6500 "ErrorCode,Invalid channel number");
6501 goto close_mon_conn;
6502 }
6503 res = snprintf(buf, sizeof(buf),
6504 "SCAN TYPE=ONLY freq=%d", freq);
6505 } else {
6506 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
6507 }
6508 if (res < 0 || res >= (int) sizeof(buf)) {
6509 send_resp(dut, conn, SIGMA_ERROR,
6510 "ErrorCode,snprintf failed");
6511 goto close_mon_conn;
6512 }
6513 if (wpa_command(intf, buf) < 0) {
6514 sigma_dut_print(dut, DUT_MSG_INFO,
6515 "Failed to start scan");
6516 send_resp(dut, conn, SIGMA_ERROR,
6517 "ErrorCode,scan failed");
6518 goto close_mon_conn;
6519 }
6520
6521 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
6522 buf, sizeof(buf));
6523 if (res < 0) {
6524 sigma_dut_print(dut, DUT_MSG_INFO,
6525 "Scan did not complete");
6526 send_resp(dut, conn, SIGMA_ERROR,
6527 "ErrorCode,scan did not complete");
6528 goto close_mon_conn;
6529 }
6530
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006531 if (set_network(intf, dut->infra_network_id, "bssid", "any")
6532 < 0) {
6533 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
6534 "bssid to any during FASTREASSOC");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006535 status = ERROR_SEND_STATUS;
Ashwini Patil467efef2017-05-25 12:18:27 +05306536 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006537 }
Vinita Maloo54b78cf2020-03-30 12:18:19 +05306538 res = snprintf(buf, sizeof(buf), "FASTREASSOC %s %d",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006539 bssid, chan);
Vinita Maloo54b78cf2020-03-30 12:18:19 +05306540 if (res < 0 || res >= (int) sizeof(buf) ||
6541 wcn_driver_cmd(intf, buf) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006542 send_resp(dut, conn, SIGMA_ERROR,
Vinita Maloo54b78cf2020-03-30 12:18:19 +05306543 "errorCode,Failed to run FASTREASSOC");
Ashwini Patil467efef2017-05-25 12:18:27 +05306544 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006545 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006546 sigma_dut_print(dut, DUT_MSG_INFO,
6547 "sta_reassoc: Run %s successful", buf);
6548 } else if (wpa_command(intf, "REASSOCIATE")) {
6549 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
6550 "request reassociation");
Ashwini Patil467efef2017-05-25 12:18:27 +05306551 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006552 }
6553
6554 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
6555 buf, sizeof(buf));
Ashwini Patil467efef2017-05-25 12:18:27 +05306556 if (res < 0) {
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006557 send_resp(dut, conn, SIGMA_ERROR,
6558 "errorCode,Connection did not complete");
6559 status = STATUS_SENT_ERROR;
Ashwini Patil467efef2017-05-25 12:18:27 +05306560 goto close_mon_conn;
6561 }
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006562 status = SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006563
Ashwini Patil467efef2017-05-25 12:18:27 +05306564close_mon_conn:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006565 wpa_ctrl_detach(ctrl);
6566 wpa_ctrl_close(ctrl);
Ashwini Patil467efef2017-05-25 12:18:27 +05306567 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006568}
6569
6570
6571static void hs2_clear_credentials(const char *intf)
6572{
6573 wpa_command(intf, "REMOVE_CRED all");
6574}
6575
6576
Lior Davidcc88b562017-01-03 18:52:09 +02006577#ifdef __linux__
6578static int wil6210_get_aid(struct sigma_dut *dut, const char *bssid,
6579 unsigned int *aid)
6580{
Lior David0fe101e2017-03-09 16:09:50 +02006581 const char *pattern = "AID[ \t]+([0-9]+)";
Lior Davidcc88b562017-01-03 18:52:09 +02006582
Lior David0fe101e2017-03-09 16:09:50 +02006583 return wil6210_get_sta_info_field(dut, bssid, pattern, aid);
Lior Davidcc88b562017-01-03 18:52:09 +02006584}
6585#endif /* __linux__ */
6586
6587
6588static int sta_get_aid_60g(struct sigma_dut *dut, const char *bssid,
6589 unsigned int *aid)
6590{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006591 switch (get_driver_type(dut)) {
Lior Davidcc88b562017-01-03 18:52:09 +02006592#ifdef __linux__
6593 case DRIVER_WIL6210:
6594 return wil6210_get_aid(dut, bssid, aid);
6595#endif /* __linux__ */
6596 default:
6597 sigma_dut_print(dut, DUT_MSG_ERROR, "get AID not supported");
6598 return -1;
6599 }
6600}
6601
6602
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006603static int sta_get_parameter_60g(struct sigma_dut *dut, struct sigma_conn *conn,
6604 struct sigma_cmd *cmd)
6605{
6606 char buf[MAX_CMD_LEN];
6607 char bss_list[MAX_CMD_LEN];
6608 const char *parameter = get_param(cmd, "Parameter");
6609
6610 if (parameter == NULL)
6611 return -1;
6612
Lior Davidcc88b562017-01-03 18:52:09 +02006613 if (strcasecmp(parameter, "AID") == 0) {
6614 unsigned int aid = 0;
6615 char bssid[20];
6616
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006617 if (get_wpa_status(get_station_ifname(dut), "bssid",
Lior Davidcc88b562017-01-03 18:52:09 +02006618 bssid, sizeof(bssid)) < 0) {
6619 sigma_dut_print(dut, DUT_MSG_ERROR,
6620 "could not get bssid");
6621 return -2;
6622 }
6623
6624 if (sta_get_aid_60g(dut, bssid, &aid))
6625 return -2;
6626
6627 snprintf(buf, sizeof(buf), "aid,%d", aid);
6628 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
6629 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6630 return 0;
6631 }
6632
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006633 if (strcasecmp(parameter, "DiscoveredDevList") == 0) {
6634 char *bss_line;
6635 char *bss_id = NULL;
6636 const char *ifname = get_param(cmd, "Interface");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306637 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006638
6639 if (ifname == NULL) {
6640 sigma_dut_print(dut, DUT_MSG_INFO,
6641 "For get DiscoveredDevList need Interface name.");
6642 return -1;
6643 }
6644
6645 /*
6646 * Use "BSS RANGE=ALL MASK=0x2" which provides a list
6647 * of BSSIDs in "bssid=<BSSID>\n"
6648 */
6649 if (wpa_command_resp(ifname, "BSS RANGE=ALL MASK=0x2",
6650 bss_list,
6651 sizeof(bss_list)) < 0) {
6652 sigma_dut_print(dut, DUT_MSG_ERROR,
6653 "Failed to get bss list");
6654 return -1;
6655 }
6656
6657 sigma_dut_print(dut, DUT_MSG_DEBUG,
6658 "bss list for ifname:%s is:%s",
6659 ifname, bss_list);
6660
6661 snprintf(buf, sizeof(buf), "DeviceList");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306662 bss_line = strtok_r(bss_list, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006663 while (bss_line) {
6664 if (sscanf(bss_line, "bssid=%ms", &bss_id) > 0 &&
6665 bss_id) {
6666 int len;
6667
6668 len = snprintf(buf + strlen(buf),
6669 sizeof(buf) - strlen(buf),
6670 ",%s", bss_id);
6671 free(bss_id);
6672 bss_id = NULL;
6673 if (len < 0) {
6674 sigma_dut_print(dut,
6675 DUT_MSG_ERROR,
6676 "Failed to read BSSID");
6677 send_resp(dut, conn, SIGMA_ERROR,
6678 "ErrorCode,Failed to read BSS ID");
6679 return 0;
6680 }
6681
6682 if ((size_t) len >= sizeof(buf) - strlen(buf)) {
6683 sigma_dut_print(dut,
6684 DUT_MSG_ERROR,
6685 "Response buf too small for list");
6686 send_resp(dut, conn,
6687 SIGMA_ERROR,
6688 "ErrorCode,Response buf too small for list");
6689 return 0;
6690 }
6691 }
6692
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306693 bss_line = strtok_r(NULL, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006694 }
6695
6696 sigma_dut_print(dut, DUT_MSG_INFO, "DiscoveredDevList is %s",
6697 buf);
6698 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6699 return 0;
6700 }
6701
6702 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6703 return 0;
6704}
6705
6706
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006707static int sta_get_parameter_he(struct sigma_dut *dut, struct sigma_conn *conn,
6708 struct sigma_cmd *cmd)
6709{
6710 char buf[MAX_CMD_LEN];
6711 const char *parameter = get_param(cmd, "Parameter");
6712
6713 if (!parameter)
6714 return -1;
6715
6716 if (strcasecmp(parameter, "RSSI") == 0) {
6717 char rssi[10];
6718
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006719 if (get_wpa_signal_poll(dut, get_station_ifname(dut), "RSSI",
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006720 rssi, sizeof(rssi)) < 0) {
6721 sigma_dut_print(dut, DUT_MSG_ERROR,
6722 "Could not get RSSI");
6723 return -2;
6724 }
6725
6726 snprintf(buf, sizeof(buf), "rssi,%s", rssi);
6727 sigma_dut_print(dut, DUT_MSG_INFO, "RSSI %s", buf);
6728 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6729 return 0;
6730 }
6731
6732 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6733 return 0;
6734}
6735
6736
Jouni Malinenca0abd32020-02-09 20:18:10 +02006737static enum sigma_cmd_result sta_get_pmk(struct sigma_dut *dut,
6738 struct sigma_conn *conn,
6739 struct sigma_cmd *cmd)
6740{
6741 const char *intf = get_param(cmd, "Interface");
6742 char buf[4096], bssid[20], resp[200], *pos, *tmp;
6743
6744 snprintf(buf, sizeof(buf), "PMKSA_GET %d", dut->infra_network_id);
6745 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
6746 strncmp(buf, "UNKNOWN COMMAND", 15) == 0) {
6747 send_resp(dut, conn, SIGMA_ERROR,
6748 "ErrorCode,PMKSA_GET not supported");
6749 return STATUS_SENT_ERROR;
6750 }
6751
6752 if (strncmp(buf, "FAIL", 4) == 0 ||
6753 get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
6754 send_resp(dut, conn, SIGMA_ERROR,
6755 "ErrorCode,Could not find current network");
6756 return STATUS_SENT_ERROR;
6757 }
6758
6759 pos = buf;
6760 while (pos) {
6761 if (strncmp(pos, bssid, 17) == 0) {
6762 pos = strchr(pos, ' ');
6763 if (!pos)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05306764 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02006765 pos++;
6766 pos = strchr(pos, ' ');
6767 if (!pos)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05306768 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02006769 pos++;
6770 tmp = strchr(pos, ' ');
6771 if (!tmp)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05306772 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02006773 *tmp = '\0';
6774 break;
6775 }
Jouni Malinenca0abd32020-02-09 20:18:10 +02006776 pos = strchr(pos, '\n');
6777 if (pos)
6778 pos++;
6779 }
6780
6781 if (!pos) {
6782 send_resp(dut, conn, SIGMA_ERROR,
6783 "ErrorCode,PMK not available");
6784 return STATUS_SENT_ERROR;
6785 }
6786
6787 snprintf(resp, sizeof(resp), "PMK,%s", pos);
6788 send_resp(dut, conn, SIGMA_COMPLETE, resp);
6789 return STATUS_SENT;
6790}
6791
6792
Jouni Malinenf7222712019-06-13 01:50:21 +03006793static enum sigma_cmd_result cmd_sta_get_parameter(struct sigma_dut *dut,
6794 struct sigma_conn *conn,
6795 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006796{
6797 const char *program = get_param(cmd, "Program");
Jouni Malinenca0abd32020-02-09 20:18:10 +02006798 const char *parameter = get_param(cmd, "Parameter");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006799
Jouni Malinenca0abd32020-02-09 20:18:10 +02006800 if (!parameter)
6801 return INVALID_SEND_STATUS;
6802
6803 if (strcasecmp(parameter, "PMK") == 0)
6804 return sta_get_pmk(dut, conn, cmd);
6805
6806 if (!program)
6807 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006808
6809 if (strcasecmp(program, "P2PNFC") == 0)
6810 return p2p_cmd_sta_get_parameter(dut, conn, cmd);
6811
6812 if (strcasecmp(program, "60ghz") == 0)
6813 return sta_get_parameter_60g(dut, conn, cmd);
6814
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006815 if (strcasecmp(program, "he") == 0)
6816 return sta_get_parameter_he(dut, conn, cmd);
6817
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006818#ifdef ANDROID_NAN
6819 if (strcasecmp(program, "NAN") == 0)
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07006820 return nan_cmd_sta_get_parameter(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006821#endif /* ANDROID_NAN */
6822
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07006823#ifdef MIRACAST
6824 if (strcasecmp(program, "WFD") == 0 ||
6825 strcasecmp(program, "DisplayR2") == 0)
6826 return miracast_cmd_sta_get_parameter(dut, conn, cmd);
6827#endif /* MIRACAST */
6828
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006829 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6830 return 0;
6831}
6832
6833
6834static void sta_reset_default_ath(struct sigma_dut *dut, const char *intf,
6835 const char *type)
6836{
6837 char buf[100];
6838
6839 if (dut->program == PROGRAM_VHT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006840 run_iwpriv(dut, intf, "chwidth 2");
6841 run_iwpriv(dut, intf, "mode 11ACVHT80");
6842 run_iwpriv(dut, intf, "vhtmcs -1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006843 }
6844
6845 if (dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006846 run_iwpriv(dut, intf, "chwidth 0");
6847 run_iwpriv(dut, intf, "mode 11naht40");
6848 run_iwpriv(dut, intf, "set11NRates 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006849 }
6850
6851 if (dut->program == PROGRAM_VHT || dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006852 run_iwpriv(dut, intf, "powersave 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006853
6854 /* Reset CTS width */
6855 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 54 0",
6856 intf);
6857 if (system(buf) != 0) {
6858 sigma_dut_print(dut, DUT_MSG_ERROR,
6859 "wifitool %s beeliner_fw_test 54 0 failed",
6860 intf);
6861 }
6862
6863 /* Enable Dynamic Bandwidth signalling by default */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006864 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006865
6866 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", intf);
6867 if (system(buf) != 0) {
6868 sigma_dut_print(dut, DUT_MSG_ERROR,
6869 "iwpriv rts failed");
6870 }
6871 }
6872
6873 if (type && strcasecmp(type, "Testbed") == 0) {
6874 dut->testbed_flag_txsp = 1;
6875 dut->testbed_flag_rxsp = 1;
6876 /* STA has to set spatial stream to 2 per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006877 run_iwpriv(dut, intf, "vht_mcsmap 0xfff0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006878
6879 /* Disable LDPC per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006880 run_iwpriv(dut, intf, "ldpc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006881
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006882 run_iwpriv(dut, intf, "amsdu 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006883
6884 /* TODO: Disable STBC 2x1 transmit and receive */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006885 run_iwpriv(dut, intf, "tx_stbc 0");
6886 run_iwpriv(dut, intf, "rx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006887
6888 /* STA has to disable Short GI per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006889 run_iwpriv(dut, intf, "shortgi 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006890 }
6891
6892 if (type && strcasecmp(type, "DUT") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006893 run_iwpriv(dut, intf, "nss 3");
Arif Hussainac6c5112018-05-25 17:34:00 -07006894 dut->sta_nss = 3;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006895
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006896 run_iwpriv(dut, intf, "shortgi 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006897 }
6898}
6899
6900
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08006901#ifdef NL80211_SUPPORT
6902static int sta_set_he_mcs(struct sigma_dut *dut, const char *intf,
6903 enum he_mcs_config mcs)
6904{
6905 struct nl_msg *msg;
6906 int ret = 0;
6907 struct nlattr *params;
6908 int ifindex;
6909
6910 ifindex = if_nametoindex(intf);
6911 if (ifindex == 0) {
6912 sigma_dut_print(dut, DUT_MSG_ERROR,
6913 "%s: Index for interface %s failed",
6914 __func__, intf);
6915 return -1;
6916 }
6917
6918 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6919 NL80211_CMD_VENDOR)) ||
6920 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6921 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6922 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6923 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6924 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6925 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MCS,
6926 mcs)) {
6927 sigma_dut_print(dut, DUT_MSG_ERROR,
6928 "%s: err in adding vendor_cmd and vendor_data",
6929 __func__);
6930 nlmsg_free(msg);
6931 return -1;
6932 }
6933 nla_nest_end(msg, params);
6934
6935 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6936 if (ret) {
6937 sigma_dut_print(dut, DUT_MSG_ERROR,
6938 "%s: err in send_and_recv_msgs, ret=%d",
6939 __func__, ret);
6940 }
6941 return ret;
6942}
6943#endif /* NL80211_SUPPORT */
6944
6945
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07006946static int sta_set_action_tx_in_he_tb_ppdu(struct sigma_dut *dut,
6947 const char *intf, int enable)
6948{
6949#ifdef NL80211_SUPPORT
6950 struct nl_msg *msg;
6951 int ret = 0;
6952 struct nlattr *params;
6953 int ifindex;
6954
6955 ifindex = if_nametoindex(intf);
6956 if (ifindex == 0) {
6957 sigma_dut_print(dut, DUT_MSG_ERROR,
6958 "%s: Index for interface %s failed",
6959 __func__, intf);
6960 return -1;
6961 }
6962
6963 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6964 NL80211_CMD_VENDOR)) ||
6965 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6966 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6967 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6968 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6969 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6970 nla_put_u8(msg,
6971 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_ACTION_TX_TB_PPDU,
6972 enable)) {
6973 sigma_dut_print(dut, DUT_MSG_ERROR,
6974 "%s: err in adding vendor_cmd and vendor_data",
6975 __func__);
6976 nlmsg_free(msg);
6977 return -1;
6978 }
6979 nla_nest_end(msg, params);
6980
6981 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6982 if (ret) {
6983 sigma_dut_print(dut, DUT_MSG_ERROR,
6984 "%s: err in send_and_recv_msgs, ret=%d",
6985 __func__, ret);
6986 }
6987 return ret;
6988#else /* NL80211_SUPPORT */
6989 sigma_dut_print(dut, DUT_MSG_ERROR,
6990 "HE action Tx TB PPDU cannot be set without NL80211_SUPPORT defined");
6991 return -1;
6992#endif /* NL80211_SUPPORT */
6993}
6994
6995
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08006996static int sta_set_heconfig_and_wep_tkip(struct sigma_dut *dut,
6997 const char *intf, int enable)
6998{
6999#ifdef NL80211_SUPPORT
7000 struct nl_msg *msg;
7001 int ret = 0;
7002 struct nlattr *params;
7003 int ifindex;
7004
7005 ifindex = if_nametoindex(intf);
7006 if (ifindex == 0) {
7007 sigma_dut_print(dut, DUT_MSG_ERROR,
7008 "%s: Index for interface %s failed",
7009 __func__, intf);
7010 return -1;
7011 }
7012
7013 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7014 NL80211_CMD_VENDOR)) ||
7015 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7016 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7017 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7018 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7019 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7020 nla_put_u8(msg,
7021 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WEP_TKIP_IN_HE,
7022 enable)) {
7023 sigma_dut_print(dut, DUT_MSG_ERROR,
7024 "%s: err in adding vendor_cmd and vendor_data",
7025 __func__);
7026 nlmsg_free(msg);
7027 return -1;
7028 }
7029 nla_nest_end(msg, params);
7030
7031 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7032 if (ret) {
7033 sigma_dut_print(dut, DUT_MSG_ERROR,
7034 "%s: err in send_and_recv_msgs, ret=%d",
7035 __func__, ret);
7036 }
7037 return ret;
7038#else /* NL80211_SUPPORT */
7039 sigma_dut_print(dut, DUT_MSG_ERROR,
7040 "HE config enablement cannot be changed without NL80211_SUPPORT defined");
7041 return -1;
7042#endif /* NL80211_SUPPORT */
7043}
7044
7045
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007046#ifdef NL80211_SUPPORT
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007047
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007048static int sta_set_he_testbed_def(struct sigma_dut *dut,
7049 const char *intf, int cfg)
7050{
7051 struct nl_msg *msg;
7052 int ret = 0;
7053 struct nlattr *params;
7054 int ifindex;
7055
7056 ifindex = if_nametoindex(intf);
7057 if (ifindex == 0) {
7058 sigma_dut_print(dut, DUT_MSG_ERROR,
7059 "%s: Index for interface %s failed",
7060 __func__, intf);
7061 return -1;
7062 }
7063
7064 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7065 NL80211_CMD_VENDOR)) ||
7066 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7067 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7068 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7069 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7070 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7071 nla_put_u8(msg,
7072 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SET_HE_TESTBED_DEFAULTS,
7073 cfg)) {
7074 sigma_dut_print(dut, DUT_MSG_ERROR,
7075 "%s: err in adding vendor_cmd and vendor_data",
7076 __func__);
7077 nlmsg_free(msg);
7078 return -1;
7079 }
7080 nla_nest_end(msg, params);
7081
7082 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7083 if (ret) {
7084 sigma_dut_print(dut, DUT_MSG_ERROR,
7085 "%s: err in send_and_recv_msgs, ret=%d",
7086 __func__, ret);
7087 }
7088 return ret;
7089}
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007090
7091
7092static int sta_set_2g_vht_supp(struct sigma_dut *dut, const char *intf, int cfg)
7093{
7094 struct nl_msg *msg;
7095 int ret = 0;
7096 struct nlattr *params;
7097 int ifindex;
7098
7099 ifindex = if_nametoindex(intf);
7100 if (ifindex == 0) {
7101 sigma_dut_print(dut, DUT_MSG_ERROR,
7102 "%s: Index for interface %s failed",
7103 __func__, intf);
7104 return -1;
7105 }
7106
7107 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7108 NL80211_CMD_VENDOR)) ||
7109 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7110 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7111 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7112 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7113 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7114 nla_put_u8(msg,
7115 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_2G_VHT,
7116 cfg)) {
7117 sigma_dut_print(dut, DUT_MSG_ERROR,
7118 "%s: err in adding vendor_cmd and vendor_data",
7119 __func__);
7120 nlmsg_free(msg);
7121 return -1;
7122 }
7123 nla_nest_end(msg, params);
7124
7125 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7126 if (ret) {
7127 sigma_dut_print(dut, DUT_MSG_ERROR,
7128 "%s: err in send_and_recv_msgs, ret=%d",
7129 __func__, ret);
7130 }
7131 return ret;
7132}
7133
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007134#endif /* NL80211_SUPPORT */
7135
7136
Qiwei Caib6806972020-01-15 13:52:11 +08007137int sta_set_addba_buf_size(struct sigma_dut *dut,
7138 const char *intf, int bufsize)
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007139{
7140#ifdef NL80211_SUPPORT
7141 struct nl_msg *msg;
7142 int ret = 0;
7143 struct nlattr *params;
7144 int ifindex;
7145
7146 ifindex = if_nametoindex(intf);
7147 if (ifindex == 0) {
7148 sigma_dut_print(dut, DUT_MSG_ERROR,
7149 "%s: Index for interface %s failed",
7150 __func__, intf);
7151 return -1;
7152 }
7153
7154 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7155 NL80211_CMD_VENDOR)) ||
7156 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7157 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7158 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7159 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7160 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -07007161 nla_put_u16(msg,
7162 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
7163 bufsize)) {
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007164 sigma_dut_print(dut, DUT_MSG_ERROR,
7165 "%s: err in adding vendor_cmd and vendor_data",
7166 __func__);
7167 nlmsg_free(msg);
7168 return -1;
7169 }
7170 nla_nest_end(msg, params);
7171
7172 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7173 if (ret) {
7174 sigma_dut_print(dut, DUT_MSG_ERROR,
7175 "%s: err in send_and_recv_msgs, ret=%d",
7176 __func__, ret);
7177 }
7178 return ret;
7179#else /* NL80211_SUPPORT */
7180 sigma_dut_print(dut, DUT_MSG_ERROR,
7181 "AddBA bufsize cannot be changed without NL80211_SUPPORT defined");
7182 return -1;
7183#endif /* NL80211_SUPPORT */
7184}
7185
7186
Arif Hussain8d5b27b2018-05-14 14:31:03 -07007187static int sta_set_tx_beamformee(struct sigma_dut *dut, const char *intf,
7188 int enable)
7189{
7190#ifdef NL80211_SUPPORT
7191 struct nl_msg *msg;
7192 int ret = 0;
7193 struct nlattr *params;
7194 int ifindex;
7195
7196 ifindex = if_nametoindex(intf);
7197 if (ifindex == 0) {
7198 sigma_dut_print(dut, DUT_MSG_ERROR,
7199 "%s: Index for interface %s failed",
7200 __func__, intf);
7201 return -1;
7202 }
7203
7204 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7205 NL80211_CMD_VENDOR)) ||
7206 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7207 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7208 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7209 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7210 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7211 nla_put_u8(msg,
7212 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_TX_BEAMFORMEE,
7213 enable)) {
7214 sigma_dut_print(dut, DUT_MSG_ERROR,
7215 "%s: err in adding vendor_cmd and vendor_data",
7216 __func__);
7217 nlmsg_free(msg);
7218 return -1;
7219 }
7220 nla_nest_end(msg, params);
7221
7222 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7223 if (ret) {
7224 sigma_dut_print(dut, DUT_MSG_ERROR,
7225 "%s: err in send_and_recv_msgs, ret=%d",
7226 __func__, ret);
7227 }
7228 return ret;
7229#else /* NL80211_SUPPORT */
7230 sigma_dut_print(dut, DUT_MSG_ERROR,
7231 "tx beamformee cannot be changed without NL80211_SUPPORT defined");
7232 return -1;
7233#endif /* NL80211_SUPPORT */
7234}
7235
7236
Arif Hussain9765f7d2018-07-03 08:28:26 -07007237static int sta_set_beamformee_sts(struct sigma_dut *dut, const char *intf,
7238 int val)
7239{
7240#ifdef NL80211_SUPPORT
7241 struct nl_msg *msg;
7242 int ret = 0;
7243 struct nlattr *params;
7244 int ifindex;
7245
7246 ifindex = if_nametoindex(intf);
7247 if (ifindex == 0) {
7248 sigma_dut_print(dut, DUT_MSG_ERROR,
7249 "%s: Index for interface %s failed, val:%d",
7250 __func__, intf, val);
7251 return -1;
7252 }
7253
7254 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7255 NL80211_CMD_VENDOR)) ||
7256 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7257 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7258 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7259 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7260 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7261 nla_put_u8(msg,
7262 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_BEAMFORMEE_NSTS,
7263 val)) {
7264 sigma_dut_print(dut, DUT_MSG_ERROR,
7265 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7266 __func__, val);
7267 nlmsg_free(msg);
7268 return -1;
7269 }
7270 nla_nest_end(msg, params);
7271
7272 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7273 if (ret) {
7274 sigma_dut_print(dut, DUT_MSG_ERROR,
7275 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7276 __func__, ret, val);
7277 }
7278 return ret;
7279#else /* NL80211_SUPPORT */
7280 sigma_dut_print(dut, DUT_MSG_ERROR,
7281 "beamformee sts cannot be changed without NL80211_SUPPORT defined");
7282 return -1;
7283#endif /* NL80211_SUPPORT */
7284}
7285
7286
Arif Hussain68d23f52018-07-11 13:39:08 -07007287#ifdef NL80211_SUPPORT
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007288static int sta_set_mac_padding_duration(struct sigma_dut *dut, const char *intf,
7289 enum qca_wlan_he_mac_padding_dur val)
7290{
Arif Hussain68d23f52018-07-11 13:39:08 -07007291 struct nl_msg *msg;
7292 int ret = 0;
7293 struct nlattr *params;
7294 int ifindex;
7295
7296 ifindex = if_nametoindex(intf);
7297 if (ifindex == 0) {
7298 sigma_dut_print(dut, DUT_MSG_ERROR,
7299 "%s: Index for interface %s failed, val:%d",
7300 __func__, intf, val);
7301 return -1;
7302 }
7303
7304 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7305 NL80211_CMD_VENDOR)) ||
7306 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7307 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7308 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7309 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7310 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7311 nla_put_u8(msg,
7312 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MAC_PADDING_DUR,
7313 val)) {
7314 sigma_dut_print(dut, DUT_MSG_ERROR,
7315 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7316 __func__, val);
7317 nlmsg_free(msg);
7318 return -1;
7319 }
7320 nla_nest_end(msg, params);
7321
7322 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7323 if (ret) {
7324 sigma_dut_print(dut, DUT_MSG_ERROR,
7325 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7326 __func__, ret, val);
7327 }
7328 return ret;
Arif Hussain68d23f52018-07-11 13:39:08 -07007329}
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007330#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07007331
7332
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07007333static int sta_set_tx_su_ppdu_cfg(struct sigma_dut *dut, const char *intf,
7334 int val)
7335{
7336#ifdef NL80211_SUPPORT
7337 struct nl_msg *msg;
7338 int ret = 0;
7339 struct nlattr *params;
7340 int ifindex;
7341
7342 ifindex = if_nametoindex(intf);
7343 if (ifindex == 0) {
7344 sigma_dut_print(dut, DUT_MSG_ERROR,
7345 "%s: Index for interface %s failed, val:%d",
7346 __func__, intf, val);
7347 return -1;
7348 }
7349
7350 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7351 NL80211_CMD_VENDOR)) ||
7352 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7353 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7354 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7355 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7356 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7357 nla_put_u8(msg,
7358 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_SUPPDU,
7359 val)) {
7360 sigma_dut_print(dut, DUT_MSG_ERROR,
7361 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7362 __func__, val);
7363 nlmsg_free(msg);
7364 return -1;
7365 }
7366 nla_nest_end(msg, params);
7367
7368 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7369 if (ret) {
7370 sigma_dut_print(dut, DUT_MSG_ERROR,
7371 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7372 __func__, ret, val);
7373 }
7374 return ret;
7375#else /* NL80211_SUPPORT */
7376 sigma_dut_print(dut, DUT_MSG_ERROR,
7377 "Tx SU PPDU cannot be set without NL80211_SUPPORT defined");
7378 return -1;
7379#endif /* NL80211_SUPPORT */
7380}
7381
7382
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007383#ifdef NL80211_SUPPORT
7384static int sta_set_he_om_ctrl_reset(struct sigma_dut *dut, const char *intf)
7385{
7386 struct nl_msg *msg;
7387 int ret = 0;
7388 struct nlattr *params;
7389 int ifindex;
7390
7391 ifindex = if_nametoindex(intf);
7392 if (ifindex == 0) {
7393 sigma_dut_print(dut, DUT_MSG_ERROR,
7394 "%s: Index for interface %s failed",
7395 __func__, intf);
7396 return -1;
7397 }
7398
7399 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7400 NL80211_CMD_VENDOR)) ||
7401 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7402 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7403 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7404 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7405 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7406 nla_put_flag(msg,
7407 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_CLEAR_HE_OM_CTRL_CONFIG)) {
7408 sigma_dut_print(dut, DUT_MSG_ERROR,
7409 "%s: err in adding vendor_cmd and vendor_data",
7410 __func__);
7411 nlmsg_free(msg);
7412 return -1;
7413 }
7414 nla_nest_end(msg, params);
7415
7416 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7417 if (ret) {
7418 sigma_dut_print(dut, DUT_MSG_ERROR,
7419 "%s: err in send_and_recv_msgs, ret=%d",
7420 __func__, ret);
7421 }
7422 return ret;
7423}
7424#endif /* NL80211_SUPPORT */
7425
7426
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07007427static int sta_set_mu_edca_override(struct sigma_dut *dut, const char *intf,
7428 int val)
7429{
7430#ifdef NL80211_SUPPORT
7431 struct nl_msg *msg;
7432 int ret = 0;
7433 struct nlattr *params;
7434 int ifindex;
7435
7436 ifindex = if_nametoindex(intf);
7437 if (ifindex == 0) {
7438 sigma_dut_print(dut, DUT_MSG_ERROR,
7439 "%s: Index for interface %s failed, val:%d",
7440 __func__, intf, val);
7441 return -1;
7442 }
7443
7444 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7445 NL80211_CMD_VENDOR)) ||
7446 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7447 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7448 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7449 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7450 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7451 nla_put_u8(msg,
7452 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_OVERRIDE_MU_EDCA,
7453 val)) {
7454 sigma_dut_print(dut, DUT_MSG_ERROR,
7455 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7456 __func__, val);
7457 nlmsg_free(msg);
7458 return -1;
7459 }
7460 nla_nest_end(msg, params);
7461
7462 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7463 if (ret) {
7464 sigma_dut_print(dut, DUT_MSG_ERROR,
7465 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7466 __func__, ret, val);
7467 }
7468 return ret;
7469#else /* NL80211_SUPPORT */
7470 sigma_dut_print(dut, DUT_MSG_ERROR,
7471 "MU EDCA override cannot be changed without NL80211_SUPPORT defined");
7472 return -1;
7473#endif /* NL80211_SUPPORT */
7474}
7475
7476
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007477static int sta_set_om_ctrl_supp(struct sigma_dut *dut, const char *intf,
7478 int val)
7479{
7480#ifdef NL80211_SUPPORT
7481 struct nl_msg *msg;
7482 int ret = 0;
7483 struct nlattr *params;
7484 int ifindex;
7485
7486 ifindex = if_nametoindex(intf);
7487 if (ifindex == 0) {
7488 sigma_dut_print(dut, DUT_MSG_ERROR,
7489 "%s: Index for interface %s failed, val:%d",
7490 __func__, intf, val);
7491 return -1;
7492 }
7493
7494 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7495 NL80211_CMD_VENDOR)) ||
7496 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7497 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7498 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7499 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7500 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7501 nla_put_u8(msg,
7502 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OM_CTRL_SUPP,
7503 val)) {
7504 sigma_dut_print(dut, DUT_MSG_ERROR,
7505 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7506 __func__, val);
7507 nlmsg_free(msg);
7508 return -1;
7509 }
7510 nla_nest_end(msg, params);
7511
7512 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7513 if (ret) {
7514 sigma_dut_print(dut, DUT_MSG_ERROR,
7515 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7516 __func__, ret, val);
7517 }
7518 return ret;
7519#else /* NL80211_SUPPORT */
7520 sigma_dut_print(dut, DUT_MSG_ERROR,
7521 "HE OM ctrl cannot be changed without NL80211_SUPPORT defined");
7522 return -1;
7523#endif /* NL80211_SUPPORT */
7524}
7525
7526
Arif Hussain480d5f42019-03-12 14:40:42 -07007527static int sta_set_twt_req_support(struct sigma_dut *dut, const char *intf,
7528 int val)
7529{
7530#ifdef NL80211_SUPPORT
7531 struct nl_msg *msg;
7532 int ret;
7533 struct nlattr *params;
7534 int ifindex;
7535
7536 ifindex = if_nametoindex(intf);
7537 if (ifindex == 0) {
7538 sigma_dut_print(dut, DUT_MSG_ERROR,
7539 "%s: Index for interface %s failed, val:%d",
7540 __func__, intf, val);
7541 return -1;
7542 }
7543
7544 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7545 NL80211_CMD_VENDOR)) ||
7546 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7547 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7548 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7549 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7550 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7551 nla_put_u8(msg,
7552 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TWT_REQ_SUPPORT,
7553 val)) {
7554 sigma_dut_print(dut, DUT_MSG_ERROR,
7555 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7556 __func__, val);
7557 nlmsg_free(msg);
7558 return -1;
7559 }
7560 nla_nest_end(msg, params);
7561
7562 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7563 if (ret) {
7564 sigma_dut_print(dut, DUT_MSG_ERROR,
7565 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7566 __func__, ret, val);
7567 }
7568 return ret;
7569#else /* NL80211_SUPPORT */
7570 sigma_dut_print(dut, DUT_MSG_ERROR,
7571 "TWT Request cannot be changed without NL80211_SUPPORT defined");
7572 return -1;
7573#endif /* NL80211_SUPPORT */
7574}
7575
7576
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007577static void sta_reset_default_wcn(struct sigma_dut *dut, const char *intf,
7578 const char *type)
7579{
7580 char buf[60];
7581
7582 if (dut->program == PROGRAM_HE) {
7583 /* resetting phymode to auto in case of HE program */
7584 snprintf(buf, sizeof(buf), "iwpriv %s setphymode 0", intf);
7585 if (system(buf) != 0) {
7586 sigma_dut_print(dut, DUT_MSG_ERROR,
7587 "iwpriv %s setphymode failed", intf);
7588 }
7589
Amarnath Hullur Subramanyam9cecb502018-04-25 13:26:30 -07007590 /* reset the rate to Auto rate */
7591 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0xff",
7592 intf);
7593 if (system(buf) != 0) {
7594 sigma_dut_print(dut, DUT_MSG_ERROR,
7595 "iwpriv %s set_11ax_rate 0xff failed",
7596 intf);
7597 }
7598
Kiran Kumar Lokere86cfe3a2018-06-01 11:55:15 -07007599 /* reset the LDPC setting */
7600 snprintf(buf, sizeof(buf), "iwpriv %s ldpc 1", intf);
7601 if (system(buf) != 0) {
7602 sigma_dut_print(dut, DUT_MSG_ERROR,
7603 "iwpriv %s ldpc 1 failed", intf);
7604 }
7605
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08007606 /* reset the power save setting */
Vinita S. Malooa8b62722020-04-23 01:45:41 +05307607 set_power_save_wcn(dut, intf, 2);
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08007608
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007609 /* remove all network profiles */
7610 remove_wpa_networks(intf);
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007611
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007612 /* Configure ADDBA Req/Rsp buffer size to be 64 */
7613 sta_set_addba_buf_size(dut, intf, 64);
7614
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08007615#ifdef NL80211_SUPPORT
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007616 /* Reset the device HE capabilities to its default supported
7617 * configuration. */
7618 sta_set_he_testbed_def(dut, intf, 0);
7619
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08007620 /* Disable noackpolicy for all AC */
7621 if (nlvendor_sta_set_noack(dut, intf, 0, QCA_WLAN_AC_ALL)) {
7622 sigma_dut_print(dut, DUT_MSG_ERROR,
7623 "Disable of noackpolicy for all AC failed");
7624 }
7625#endif /* NL80211_SUPPORT */
7626
Amarnath Hullur Subramanyamb1724a52018-03-07 14:31:46 -08007627 /* Enable WMM by default */
7628 if (wcn_sta_set_wmm(dut, intf, "on")) {
7629 sigma_dut_print(dut, DUT_MSG_ERROR,
7630 "Enable of WMM in sta_reset_default_wcn failed");
7631 }
7632
7633 /* Disable ADDBA_REJECT by default */
7634 if (nlvendor_sta_set_addba_reject(dut, intf, 0)) {
7635 sigma_dut_print(dut, DUT_MSG_ERROR,
7636 "Disable of addba_reject in sta_reset_default_wcn failed");
7637 }
7638
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08007639 /* Enable sending of ADDBA by default */
7640 if (nlvendor_config_send_addba(dut, intf, 1)) {
7641 sigma_dut_print(dut, DUT_MSG_ERROR,
7642 "Enable sending of ADDBA in sta_reset_default_wcn failed");
7643 }
7644
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08007645 /* Enable AMPDU by default */
7646 iwpriv_sta_set_ampdu(dut, intf, 1);
7647
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007648#ifdef NL80211_SUPPORT
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -08007649 if (wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_AUTO)) {
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007650 sigma_dut_print(dut, DUT_MSG_ERROR,
7651 "Set LTF config to default in sta_reset_default_wcn failed");
7652 }
Arif Hussain9765f7d2018-07-03 08:28:26 -07007653
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08007654 /* set the beamformee NSTS(maximum number of
7655 * space-time streams) to default DUT config
7656 */
7657 if (sta_set_beamformee_sts(dut, intf, 7)) {
Arif Hussain9765f7d2018-07-03 08:28:26 -07007658 sigma_dut_print(dut, DUT_MSG_ERROR,
7659 "Failed to set BeamformeeSTS");
7660 }
Arif Hussain68d23f52018-07-11 13:39:08 -07007661
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007662 if (sta_set_mac_padding_duration(
7663 dut, intf,
7664 QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07007665 sigma_dut_print(dut, DUT_MSG_ERROR,
7666 "Failed to set MAC padding duration");
7667 }
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07007668
7669 if (sta_set_mu_edca_override(dut, intf, 0)) {
7670 sigma_dut_print(dut, DUT_MSG_ERROR,
7671 "ErrorCode,Failed to set MU EDCA override disable");
7672 }
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007673
7674 if (sta_set_om_ctrl_supp(dut, intf, 1)) {
7675 sigma_dut_print(dut, DUT_MSG_ERROR,
7676 "Failed to set OM ctrl supp");
7677 }
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07007678
7679 if (sta_set_tx_su_ppdu_cfg(dut, intf, 1)) {
7680 sigma_dut_print(dut, DUT_MSG_ERROR,
7681 "Failed to set Tx SU PPDU enable");
7682 }
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007683
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07007684 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 0)) {
7685 sigma_dut_print(dut, DUT_MSG_ERROR,
7686 "failed to send TB PPDU Tx cfg");
7687 }
7688
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007689 if (sta_set_he_om_ctrl_reset(dut, intf)) {
7690 sigma_dut_print(dut, DUT_MSG_ERROR,
7691 "Failed to set OM ctrl reset");
7692 }
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08007693
7694 /* +HTC-HE support default on */
7695 if (sta_set_he_htc_supp(dut, intf, 1)) {
7696 sigma_dut_print(dut, DUT_MSG_ERROR,
7697 "Setting of +HTC-HE support failed");
7698 }
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007699#endif /* NL80211_SUPPORT */
7700
Arif Hussain8d5b27b2018-05-14 14:31:03 -07007701 if (sta_set_tx_beamformee(dut, intf, 1)) {
7702 sigma_dut_print(dut, DUT_MSG_ERROR,
7703 "Set tx beamformee enable by default in sta_reset_default_wcn failed");
7704 }
7705
Kiran Kumar Lokereb55ff442020-07-15 00:20:40 -07007706 wpa_command(intf, "SET oce 1");
7707
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007708 /* Set nss to 1 and MCS 0-7 in case of testbed */
7709 if (type && strcasecmp(type, "Testbed") == 0) {
7710#ifdef NL80211_SUPPORT
7711 int ret;
7712#endif /* NL80211_SUPPORT */
7713
Kiran Kumar Lokereb55ff442020-07-15 00:20:40 -07007714 wpa_command(intf, "SET oce 0");
7715
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007716 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
7717 if (system(buf) != 0) {
7718 sigma_dut_print(dut, DUT_MSG_ERROR,
7719 "iwpriv %s nss failed", intf);
7720 }
7721
7722#ifdef NL80211_SUPPORT
7723 ret = sta_set_he_mcs(dut, intf, HE_80_MCS0_7);
7724 if (ret) {
7725 sigma_dut_print(dut, DUT_MSG_ERROR,
7726 "Setting of MCS failed, ret:%d",
7727 ret);
7728 }
7729#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyamc67621d2018-02-04 23:18:01 -08007730
7731 /* Disable STBC as default */
7732 wcn_sta_set_stbc(dut, intf, "0");
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08007733
7734 /* Disable AMSDU as default */
7735 iwpriv_sta_set_amsdu(dut, intf, "0");
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08007736
7737#ifdef NL80211_SUPPORT
7738 /* HE fragmentation default off */
7739 if (sta_set_he_fragmentation(dut, intf,
7740 HE_FRAG_DISABLE)) {
7741 sigma_dut_print(dut, DUT_MSG_ERROR,
7742 "Setting of HE fragmentation failed");
7743 }
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08007744
7745 /* set the beamformee NSTS(maximum number of
7746 * space-time streams) to default testbed config
7747 */
7748 if (sta_set_beamformee_sts(dut, intf, 3)) {
7749 sigma_dut_print(dut, DUT_MSG_ERROR,
7750 "Failed to set BeamformeeSTS");
7751 }
7752
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08007753 /* +HTC-HE support default off */
7754 if (sta_set_he_htc_supp(dut, intf, 0)) {
7755 sigma_dut_print(dut, DUT_MSG_ERROR,
7756 "Setting of +HTC-HE support failed");
7757 }
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007758
7759 /* Set device HE capabilities to testbed default
7760 * configuration. */
7761 if (sta_set_he_testbed_def(dut, intf, 1)) {
7762 sigma_dut_print(dut, DUT_MSG_DEBUG,
7763 "Failed to set HE defaults");
7764 }
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007765
7766 /* Disable VHT support in 2.4 GHz for testbed */
7767 sta_set_2g_vht_supp(dut, intf, 0);
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08007768#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08007769
7770 /* Enable WEP/TKIP with HE capability in testbed */
7771 if (sta_set_heconfig_and_wep_tkip(dut, intf, 1)) {
7772 sigma_dut_print(dut, DUT_MSG_ERROR,
7773 "Enabling HE config with WEP/TKIP failed");
7774 }
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007775 }
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007776
7777 /* Defaults in case of DUT */
7778 if (type && strcasecmp(type, "DUT") == 0) {
Arif Hussaind48fcc72018-05-01 18:34:18 -07007779 /* Enable STBC by default */
7780 wcn_sta_set_stbc(dut, intf, "1");
7781
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007782 /* set nss to 2 */
7783 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
7784 if (system(buf) != 0) {
7785 sigma_dut_print(dut, DUT_MSG_ERROR,
7786 "iwpriv %s nss 2 failed", intf);
7787 }
Arif Hussainac6c5112018-05-25 17:34:00 -07007788 dut->sta_nss = 2;
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007789
7790#ifdef NL80211_SUPPORT
Arif Hussainae239842018-05-01 18:20:05 -07007791 /* Set HE_MCS to 0-11 */
7792 if (sta_set_he_mcs(dut, intf, HE_80_MCS0_11)) {
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007793 sigma_dut_print(dut, DUT_MSG_ERROR,
7794 "Setting of MCS failed");
7795 }
7796#endif /* NL80211_SUPPORT */
7797
7798 /* Disable WEP/TKIP with HE capability in DUT */
7799 if (sta_set_heconfig_and_wep_tkip(dut, intf, 0)) {
7800 sigma_dut_print(dut, DUT_MSG_ERROR,
7801 "Enabling HE config with WEP/TKIP failed");
7802 }
7803 }
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007804 }
7805}
7806
7807
Jouni Malinenf7222712019-06-13 01:50:21 +03007808static enum sigma_cmd_result cmd_sta_reset_default(struct sigma_dut *dut,
7809 struct sigma_conn *conn,
7810 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007811{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007812 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007813 const char *band = get_param(cmd, "band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007814 const char *type;
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007815 const char *program = get_param(cmd, "program");
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05307816 const char *dev_role = get_param(cmd, "DevRole");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007817
Jouni Malinenb21f0542019-11-04 17:53:38 +02007818 if (dut->station_ifname_2g &&
7819 strcmp(dut->station_ifname_2g, intf) == 0)
7820 dut->use_5g = 0;
7821 else if (dut->station_ifname_5g &&
7822 strcmp(dut->station_ifname_5g, intf) == 0)
7823 dut->use_5g = 1;
7824
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007825 if (!program)
7826 program = get_param(cmd, "prog");
7827 dut->program = sigma_program_to_enum(program);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007828 dut->device_type = STA_unknown;
7829 type = get_param(cmd, "type");
7830 if (type && strcasecmp(type, "Testbed") == 0)
7831 dut->device_type = STA_testbed;
7832 if (type && strcasecmp(type, "DUT") == 0)
7833 dut->device_type = STA_dut;
7834
7835 if (dut->program == PROGRAM_TDLS) {
7836 /* Clear TDLS testing mode */
7837 wpa_command(intf, "SET tdls_disabled 0");
7838 wpa_command(intf, "SET tdls_testing 0");
7839 dut->no_tpk_expiration = 0;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007840 if (get_driver_type(dut) == DRIVER_WCN) {
Pradeep Reddy POTTETI8ce2a232016-10-28 12:17:32 +05307841 /* Enable the WCN driver in TDLS Explicit trigger mode
7842 */
7843 wpa_command(intf, "SET tdls_external_control 0");
7844 wpa_command(intf, "SET tdls_trigger_control 0");
7845 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007846 }
7847
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007848#ifdef MIRACAST
7849 if (dut->program == PROGRAM_WFD ||
7850 dut->program == PROGRAM_DISPLAYR2)
7851 miracast_sta_reset_default(dut, conn, cmd);
7852#endif /* MIRACAST */
7853
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007854 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007855 case DRIVER_ATHEROS:
7856 sta_reset_default_ath(dut, intf, type);
7857 break;
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007858 case DRIVER_WCN:
7859 sta_reset_default_wcn(dut, intf, type);
7860 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007861 default:
7862 break;
7863 }
7864
7865#ifdef ANDROID_NAN
7866 if (dut->program == PROGRAM_NAN)
7867 nan_cmd_sta_reset_default(dut, conn, cmd);
7868#endif /* ANDROID_NAN */
7869
Vinay Gannevaram3b9fdd32019-06-14 17:55:44 +05307870 if (dut->program == PROGRAM_LOC &&
7871 lowi_cmd_sta_reset_default(dut, conn, cmd) < 0)
7872 return ERROR_SEND_STATUS;
7873
Jouni Malinenba630452018-06-22 11:49:59 +03007874 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007875 unlink("SP/wi-fi.org/pps.xml");
7876 if (system("rm -r SP/*") != 0) {
7877 }
7878 unlink("next-client-cert.pem");
7879 unlink("next-client-key.pem");
7880 }
7881
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007882 /* For WPS program of the 60 GHz band the band type needs to be saved */
7883 if (dut->program == PROGRAM_WPS) {
7884 if (band && strcasecmp(band, "60GHz") == 0) {
7885 dut->band = WPS_BAND_60G;
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02007886 /* For 60 GHz enable WPS for WPS TCs */
7887 dut->wps_disable = 0;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007888 } else {
7889 dut->band = WPS_BAND_NON_60G;
7890 }
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02007891 } else if (dut->program == PROGRAM_60GHZ) {
7892 /* For 60 GHz MAC/PHY TCs WPS must be disabled */
7893 dut->wps_disable = 1;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007894 }
7895
Alexei Avshalom Lazar157ba062018-12-23 16:15:26 +02007896 if (is_60g_sigma_dut(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007897 const char *dev_role = get_param(cmd, "DevRole");
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007898 char buf[256];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007899
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02007900 sigma_dut_print(dut, DUT_MSG_INFO,
7901 "WPS 60 GHz program, wps_disable = %d",
7902 dut->wps_disable);
7903
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007904 if (!dev_role) {
7905 send_resp(dut, conn, SIGMA_ERROR,
7906 "errorCode,Missing DevRole argument");
7907 return 0;
7908 }
7909
7910 if (strcasecmp(dev_role, "STA") == 0)
7911 dut->dev_role = DEVROLE_STA;
7912 else if (strcasecmp(dev_role, "PCP") == 0)
7913 dut->dev_role = DEVROLE_PCP;
7914 else {
7915 send_resp(dut, conn, SIGMA_ERROR,
7916 "errorCode,Unknown DevRole");
7917 return 0;
7918 }
7919
7920 if (dut->device_type == STA_unknown) {
7921 sigma_dut_print(dut, DUT_MSG_ERROR,
7922 "Device type is not STA testbed or DUT");
7923 send_resp(dut, conn, SIGMA_ERROR,
7924 "errorCode,Unknown device type");
7925 return 0;
7926 }
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007927
7928 sigma_dut_print(dut, DUT_MSG_DEBUG,
7929 "Setting msdu_size to MAX: 7912");
7930 snprintf(buf, sizeof(buf), "ifconfig %s mtu 7912",
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007931 get_station_ifname(dut));
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007932
7933 if (system(buf) != 0) {
7934 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
7935 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007936 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007937 }
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02007938
7939 if (sta_set_force_mcs(dut, 0, 1)) {
7940 sigma_dut_print(dut, DUT_MSG_ERROR,
7941 "Failed to reset force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007942 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02007943 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007944 }
7945
7946 wpa_command(intf, "WPS_ER_STOP");
7947 wpa_command(intf, "FLUSH");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05307948 wpa_command(intf, "ERP_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007949 wpa_command(intf, "SET radio_disabled 0");
7950
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02007951 dut->wps_forced_version = 0;
7952
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007953 if (dut->wsc_fragment) {
7954 dut->wsc_fragment = 0;
7955 wpa_command(intf, "SET device_name Test client");
7956 wpa_command(intf, "SET manufacturer ");
7957 wpa_command(intf, "SET model_name ");
7958 wpa_command(intf, "SET model_number ");
7959 wpa_command(intf, "SET serial_number ");
7960 }
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02007961 if (is_60g_sigma_dut(dut) && dut->force_rsn_ie) {
7962 dut->force_rsn_ie = FORCE_RSN_IE_NONE;
7963 sta_60g_force_rsn_ie(dut, FORCE_RSN_IE_NONE);
7964 }
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007965
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007966 if (dut->tmp_mac_addr && dut->set_macaddr) {
7967 dut->tmp_mac_addr = 0;
7968 if (system(dut->set_macaddr) != 0) {
7969 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to clear "
7970 "temporary MAC address");
7971 }
7972 }
7973
7974 set_ps(intf, dut, 0);
7975
Jouni Malinenba630452018-06-22 11:49:59 +03007976 if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2 ||
7977 dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007978 wpa_command(intf, "SET interworking 1");
7979 wpa_command(intf, "SET hs20 1");
7980 }
7981
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08007982 if (dut->program == PROGRAM_HS2_R2 ||
Jouni Malinenba630452018-06-22 11:49:59 +03007983 dut->program == PROGRAM_HS2_R3 ||
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08007984 dut->program == PROGRAM_OCE) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007985 wpa_command(intf, "SET pmf 1");
7986 } else {
7987 wpa_command(intf, "SET pmf 0");
7988 }
7989
7990 hs2_clear_credentials(intf);
7991 wpa_command(intf, "SET hessid 00:00:00:00:00:00");
7992 wpa_command(intf, "SET access_network_type 15");
7993
7994 static_ip_file(0, NULL, NULL, NULL);
7995 kill_dhcp_client(dut, intf);
7996 clear_ip_addr(dut, intf);
7997
7998 dut->er_oper_performed = 0;
7999 dut->er_oper_bssid[0] = '\0';
8000
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07008001 if (dut->program == PROGRAM_LOC) {
8002 /* Disable Interworking by default */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008003 wpa_command(get_station_ifname(dut), "SET interworking 0");
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07008004 }
8005
Kiran Kumar Lokeredd086642020-06-04 00:29:26 -07008006 if (dut->program == PROGRAM_MBO || dut->program == PROGRAM_HE) {
Ashwini Patil00402582017-04-13 12:29:39 +05308007 free(dut->non_pref_ch_list);
8008 dut->non_pref_ch_list = NULL;
Ashwini Patil5acd7382017-04-13 15:55:04 +05308009 free(dut->btm_query_cand_list);
8010 dut->btm_query_cand_list = NULL;
Ashwini Patilc63161e2017-04-13 16:30:23 +05308011 wpa_command(intf, "SET reject_btm_req_reason 0");
Ashwini Patila75de5a2017-04-13 16:35:05 +05308012 wpa_command(intf, "SET ignore_assoc_disallow 0");
Ashwini Patild174f2c2017-04-13 16:49:46 +05308013 wpa_command(intf, "SET gas_address3 0");
Ashwini Patil9183fdb2017-04-13 16:58:25 +05308014 wpa_command(intf, "SET roaming 1");
Ankita Bajaj1d974552018-09-18 16:56:44 +05308015 wpa_command(intf, "SET interworking 1");
Ashwini Patil00402582017-04-13 12:29:39 +05308016 }
8017
Jouni Malinen3c367e82017-06-23 17:01:47 +03008018 free(dut->rsne_override);
8019 dut->rsne_override = NULL;
8020
Jouni Malinen68143132017-09-02 02:34:08 +03008021 free(dut->sae_commit_override);
8022 dut->sae_commit_override = NULL;
Jouni Malinen4b3769d2019-10-10 16:20:29 +03008023 wpa_command(intf, "SET sae_pmkid_in_assoc 0");
Jouni Malinen11e55212019-11-22 21:46:59 +02008024 dut->sae_pwe = SAE_PWE_DEFAULT;
Jouni Malinen68143132017-09-02 02:34:08 +03008025
Jouni Malinen134fe3c2019-06-12 04:16:49 +03008026 dut->sta_associate_wait_connect = 0;
8027 dut->server_cert_hash[0] = '\0';
Jouni Malinen37d5c692019-08-19 16:56:55 +03008028 dut->server_cert_tod = 0;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03008029 dut->sta_tod_policy = 0;
8030
Jouni Malinend86e5822017-08-29 03:55:32 +03008031 dut->dpp_conf_id = -1;
Jouni Malinenb1dd21f2017-11-13 19:14:29 +02008032 free(dut->dpp_peer_uri);
8033 dut->dpp_peer_uri = NULL;
Jouni Malinen63d50412017-11-24 11:55:38 +02008034 dut->dpp_local_bootstrap = -1;
Jouni Malinen5011fb52017-12-05 21:00:15 +02008035 wpa_command(intf, "SET dpp_config_processing 2");
Jouni Malinen90776b12020-05-04 15:34:46 +03008036 wpa_command(intf, "SET dpp_mud_url ");
Jouni Malinend86e5822017-08-29 03:55:32 +03008037
Jouni Malinenfac9cad2017-10-10 18:35:55 +03008038 wpa_command(intf, "VENDOR_ELEM_REMOVE 13 *");
8039
vamsi krishnaa2799492017-12-05 14:28:01 +05308040 if (dut->program == PROGRAM_OCE) {
Ankita Bajaja2cb5672017-10-25 16:08:28 +05308041 wpa_command(intf, "SET oce 1");
vamsi krishnaa2799492017-12-05 14:28:01 +05308042 wpa_command(intf, "SET disable_fils 0");
Ankita Bajaj1bde7942018-01-09 19:15:01 +05308043 wpa_command(intf, "FILS_HLP_REQ_FLUSH");
8044 dut->fils_hlp = 0;
8045#ifdef ANDROID
8046 hlp_thread_cleanup(dut);
8047#endif /* ANDROID */
vamsi krishnaa2799492017-12-05 14:28:01 +05308048 }
Ankita Bajaja2cb5672017-10-25 16:08:28 +05308049
Vamsi Krishnaf642d6a2020-03-27 12:33:14 +05308050 if (dut->program == PROGRAM_QM)
8051 wpa_command(intf, "SET interworking 1");
8052
Jouni Malinen8179fee2019-03-28 03:19:47 +02008053 dut->akm_values = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03008054 dut->sta_ft_ds = 0;
Jouni Malinen8179fee2019-03-28 03:19:47 +02008055
Sunil Dutt076081f2018-02-05 19:45:50 +05308056#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008057 if (get_driver_type(dut) == DRIVER_WCN &&
Sunil Dutt44595082018-02-12 19:41:45 +05308058 dut->config_rsnie == 1) {
8059 dut->config_rsnie = 0;
8060 sta_config_rsnie(dut, 0);
Sunil Dutt076081f2018-02-05 19:45:50 +05308061 }
8062#endif /* NL80211_SUPPORT */
8063
Sunil Duttfebf8a82018-02-09 18:50:13 +05308064 if (dev_role && strcasecmp(dev_role, "STA-CFON") == 0) {
8065 dut->dev_role = DEVROLE_STA_CFON;
8066 return sta_cfon_reset_default(dut, conn, cmd);
8067 }
8068
Jouni Malinen439352d2018-09-13 03:42:23 +03008069 wpa_command(intf, "SET setband AUTO");
8070
Vamsi Krishnac1633d22020-05-06 18:31:21 +05308071 dut->ocvc = 0;
Jouni Malinen67433fc2020-06-26 22:50:33 +03008072 dut->client_privacy = 0;
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +05308073 dut->saquery_oci_freq = 0;
Vamsi Krishnac1633d22020-05-06 18:31:21 +05308074
Sunil Duttfebf8a82018-02-09 18:50:13 +05308075 if (dut->program != PROGRAM_VHT)
8076 return cmd_sta_p2p_reset(dut, conn, cmd);
8077
Priyadharshini Gowthamana7dfd492015-11-09 14:34:08 -08008078 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008079}
8080
8081
Jouni Malinenf7222712019-06-13 01:50:21 +03008082static enum sigma_cmd_result cmd_sta_get_events(struct sigma_dut *dut,
8083 struct sigma_conn *conn,
8084 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008085{
8086 const char *program = get_param(cmd, "Program");
8087
8088 if (program == NULL)
8089 return -1;
8090#ifdef ANDROID_NAN
8091 if (strcasecmp(program, "NAN") == 0)
8092 return nan_cmd_sta_get_events(dut, conn, cmd);
8093#endif /* ANDROID_NAN */
8094 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
8095 return 0;
8096}
8097
8098
Jouni Malinen82905202018-04-29 17:20:10 +03008099static int sta_exec_action_url(struct sigma_dut *dut, struct sigma_conn *conn,
8100 struct sigma_cmd *cmd)
8101{
8102 const char *url = get_param(cmd, "url");
8103 const char *method = get_param(cmd, "method");
8104 pid_t pid;
8105 int status;
8106
8107 if (!url || !method)
8108 return -1;
8109
8110 /* TODO: Add support for method,post */
8111 if (strcasecmp(method, "get") != 0) {
8112 send_resp(dut, conn, SIGMA_ERROR,
8113 "ErrorCode,Unsupported method");
8114 return 0;
8115 }
8116
8117 pid = fork();
8118 if (pid < 0) {
8119 perror("fork");
8120 return -1;
8121 }
8122
8123 if (pid == 0) {
8124 char * argv[5] = { "wget", "-O", "/dev/null",
8125 (char *) url, NULL };
8126
8127 execv("/usr/bin/wget", argv);
8128 perror("execv");
8129 exit(0);
8130 return -1;
8131 }
8132
8133 if (waitpid(pid, &status, 0) < 0) {
8134 perror("waitpid");
8135 return -1;
8136 }
8137
8138 if (WIFEXITED(status)) {
8139 const char *errmsg;
8140
8141 if (WEXITSTATUS(status) == 0)
8142 return 1;
8143 sigma_dut_print(dut, DUT_MSG_INFO, "wget exit status %d",
8144 WEXITSTATUS(status));
8145 switch (WEXITSTATUS(status)) {
8146 case 4:
8147 errmsg = "errmsg,Network failure";
8148 break;
8149 case 8:
8150 errmsg = "errmsg,Server issued an error response";
8151 break;
8152 default:
8153 errmsg = "errmsg,Unknown failure from wget";
8154 break;
8155 }
8156 send_resp(dut, conn, SIGMA_ERROR, errmsg);
8157 return 0;
8158 }
8159
8160 send_resp(dut, conn, SIGMA_ERROR, "errmsg,Unknown failure");
8161 return 0;
8162}
8163
8164
Jouni Malinenf7222712019-06-13 01:50:21 +03008165static enum sigma_cmd_result cmd_sta_exec_action(struct sigma_dut *dut,
8166 struct sigma_conn *conn,
8167 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008168{
8169 const char *program = get_param(cmd, "Prog");
8170
Jouni Malinen82905202018-04-29 17:20:10 +03008171 if (program && !get_param(cmd, "interface"))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008172 return -1;
8173#ifdef ANDROID_NAN
Jouni Malinen82905202018-04-29 17:20:10 +03008174 if (program && strcasecmp(program, "NAN") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008175 return nan_cmd_sta_exec_action(dut, conn, cmd);
8176#endif /* ANDROID_NAN */
Jouni Malinen82905202018-04-29 17:20:10 +03008177
8178 if (program && strcasecmp(program, "Loc") == 0)
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07008179 return loc_cmd_sta_exec_action(dut, conn, cmd);
Jouni Malinen82905202018-04-29 17:20:10 +03008180
8181 if (get_param(cmd, "url"))
8182 return sta_exec_action_url(dut, conn, cmd);
8183
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008184 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
8185 return 0;
8186}
8187
8188
Jouni Malinenf7222712019-06-13 01:50:21 +03008189static enum sigma_cmd_result cmd_sta_set_11n(struct sigma_dut *dut,
8190 struct sigma_conn *conn,
8191 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008192{
8193 const char *intf = get_param(cmd, "Interface");
8194 const char *val, *mcs32, *rate;
8195
8196 val = get_param(cmd, "GREENFIELD");
8197 if (val) {
8198 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
8199 /* Enable GD */
8200 send_resp(dut, conn, SIGMA_ERROR,
8201 "ErrorCode,GF not supported");
8202 return 0;
8203 }
8204 }
8205
8206 val = get_param(cmd, "SGI20");
8207 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008208 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008209 case DRIVER_ATHEROS:
8210 ath_sta_set_sgi(dut, intf, val);
8211 break;
8212 default:
8213 send_resp(dut, conn, SIGMA_ERROR,
8214 "ErrorCode,SGI20 not supported");
8215 return 0;
8216 }
8217 }
8218
8219 mcs32 = get_param(cmd, "MCS32"); /* HT Duplicate Mode Enable/Disable */
8220 rate = get_param(cmd, "MCS_FIXEDRATE"); /* Fixed MCS rate (0..31) */
8221 if (mcs32 && rate) {
8222 /* TODO */
8223 send_resp(dut, conn, SIGMA_ERROR,
8224 "ErrorCode,MCS32,MCS_FIXEDRATE not supported");
8225 return 0;
8226 } else if (mcs32 && !rate) {
8227 /* TODO */
8228 send_resp(dut, conn, SIGMA_ERROR,
8229 "ErrorCode,MCS32 not supported");
8230 return 0;
8231 } else if (!mcs32 && rate) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008232 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008233 case DRIVER_ATHEROS:
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07008234 novap_reset(dut, intf, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008235 ath_sta_set_11nrates(dut, intf, rate);
8236 break;
8237 default:
8238 send_resp(dut, conn, SIGMA_ERROR,
8239 "ErrorCode,MCS32_FIXEDRATE not supported");
8240 return 0;
8241 }
8242 }
8243
8244 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
8245}
8246
8247
Arif Hussain7b47d2d2018-05-09 10:44:02 -07008248static void cmd_set_max_he_mcs(struct sigma_dut *dut, const char *intf,
8249 int mcs_config)
8250{
8251#ifdef NL80211_SUPPORT
8252 int ret;
8253
8254 switch (mcs_config) {
8255 case HE_80_MCS0_7:
8256 case HE_80_MCS0_9:
8257 case HE_80_MCS0_11:
8258 ret = sta_set_he_mcs(dut, intf, mcs_config);
8259 if (ret) {
8260 sigma_dut_print(dut, DUT_MSG_ERROR,
8261 "cmd_set_max_he_mcs: Setting of MCS:%d failed, ret:%d",
8262 mcs_config, ret);
8263 }
8264 break;
8265 default:
8266 sigma_dut_print(dut, DUT_MSG_ERROR,
8267 "cmd_set_max_he_mcs: Invalid mcs %d",
8268 mcs_config);
8269 break;
8270 }
8271#else /* NL80211_SUPPORT */
8272 sigma_dut_print(dut, DUT_MSG_ERROR,
8273 "max HE MCS cannot be changed without NL80211_SUPPORT defined");
8274#endif /* NL80211_SUPPORT */
8275}
8276
8277
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07008278#define TWT_REQUEST_CMD 0
8279#define TWT_SUGGEST_CMD 1
8280#define TWT_DEMAND_CMD 2
8281
Arif Hussain480d5f42019-03-12 14:40:42 -07008282static int sta_twt_request(struct sigma_dut *dut, struct sigma_conn *conn,
8283 struct sigma_cmd *cmd)
8284{
8285#ifdef NL80211_SUPPORT
8286 struct nlattr *params;
8287 struct nlattr *attr;
8288 struct nlattr *attr1;
8289 struct nl_msg *msg;
8290 int ifindex, ret;
8291 const char *val;
8292 const char *intf = get_param(cmd, "Interface");
8293 int wake_interval_exp = 10, nominal_min_wake_dur = 255,
8294 wake_interval_mantissa = 512;
8295 int flow_type = 0, twt_trigger = 0, target_wake_time = 0,
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07008296 protection = 0, cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_SUGGEST;
Arif Hussain480d5f42019-03-12 14:40:42 -07008297
8298 ifindex = if_nametoindex(intf);
8299 if (ifindex == 0) {
8300 sigma_dut_print(dut, DUT_MSG_ERROR,
8301 "%s: Index for interface %s failed",
8302 __func__, intf);
8303 return -1;
8304 }
8305
8306 val = get_param(cmd, "FlowType");
8307 if (val) {
8308 flow_type = atoi(val);
8309 if (flow_type != 0 && flow_type != 1) {
8310 sigma_dut_print(dut, DUT_MSG_ERROR,
8311 "TWT: Invalid FlowType %d", flow_type);
8312 return -1;
8313 }
8314 }
8315
8316 val = get_param(cmd, "TWT_Trigger");
8317 if (val) {
8318 twt_trigger = atoi(val);
8319 if (twt_trigger != 0 && twt_trigger != 1) {
8320 sigma_dut_print(dut, DUT_MSG_ERROR,
8321 "TWT: Invalid TWT_Trigger %d",
8322 twt_trigger);
8323 return -1;
8324 }
8325 }
8326
8327 val = get_param(cmd, "Protection");
8328 if (val) {
8329 protection = atoi(val);
8330 if (protection != 0 && protection != 1) {
8331 sigma_dut_print(dut, DUT_MSG_ERROR,
8332 "TWT: Invalid Protection %d",
8333 protection);
8334 return -1;
8335 }
8336 }
8337
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07008338 val = get_param(cmd, "SetupCommand");
8339 if (val) {
8340 cmd_type = atoi(val);
8341 if (cmd_type == TWT_REQUEST_CMD)
8342 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_REQUEST;
8343 else if (cmd_type == TWT_SUGGEST_CMD)
8344 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_SUGGEST;
8345 else if (cmd_type == TWT_DEMAND_CMD)
8346 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_DEMAND;
8347 else
8348 sigma_dut_print(dut, DUT_MSG_ERROR,
8349 "Default suggest is used for cmd %d",
8350 cmd_type);
8351 }
8352
Arif Hussain480d5f42019-03-12 14:40:42 -07008353 val = get_param(cmd, "TargetWakeTime");
8354 if (val)
8355 target_wake_time = atoi(val);
8356
8357 val = get_param(cmd, "WakeIntervalMantissa");
8358 if (val)
8359 wake_interval_mantissa = atoi(val);
8360
8361 val = get_param(cmd, "WakeIntervalExp");
8362 if (val)
8363 wake_interval_exp = atoi(val);
8364
8365 val = get_param(cmd, "NominalMinWakeDur");
8366 if (val)
8367 nominal_min_wake_dur = atoi(val);
8368
8369 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8370 NL80211_CMD_VENDOR)) ||
8371 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8372 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8373 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8374 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8375 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8376 !(params = nla_nest_start(
8377 msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_TWT_SETUP)) ||
8378 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8379 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_EXP,
8380 wake_interval_exp) ||
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07008381 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_REQ_TYPE, cmd_type) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -07008382 (twt_trigger &&
8383 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_TRIGGER)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008384 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE,
8385 flow_type) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -07008386 (protection &&
8387 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_PROTECTION)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008388 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_TIME,
8389 target_wake_time) ||
8390 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_DURATION,
8391 nominal_min_wake_dur) ||
8392 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_MANTISSA,
8393 wake_interval_mantissa)) {
8394 sigma_dut_print(dut, DUT_MSG_ERROR,
8395 "%s: err in adding vendor_cmd and vendor_data",
8396 __func__);
8397 nlmsg_free(msg);
8398 return -1;
8399 }
8400 nla_nest_end(msg, attr1);
8401 nla_nest_end(msg, params);
8402 nla_nest_end(msg, attr);
8403
8404 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8405 if (ret) {
8406 sigma_dut_print(dut, DUT_MSG_ERROR,
8407 "%s: err in send_and_recv_msgs, ret=%d",
8408 __func__, ret);
8409 }
8410
8411 return ret;
8412#else /* NL80211_SUPPORT */
8413 sigma_dut_print(dut, DUT_MSG_ERROR,
8414 "TWT request cannot be done without NL80211_SUPPORT defined");
8415 return -1;
8416#endif /* NL80211_SUPPORT */
8417}
8418
8419
8420static int sta_twt_teardown(struct sigma_dut *dut, struct sigma_conn *conn,
8421 struct sigma_cmd *cmd)
8422{
8423 #ifdef NL80211_SUPPORT
8424 struct nlattr *params;
8425 struct nlattr *attr;
8426 struct nlattr *attr1;
8427 int ifindex, ret;
8428 struct nl_msg *msg;
8429 const char *intf = get_param(cmd, "Interface");
8430
8431 ifindex = if_nametoindex(intf);
8432 if (ifindex == 0) {
8433 sigma_dut_print(dut, DUT_MSG_ERROR,
8434 "%s: Index for interface %s failed",
8435 __func__, intf);
8436 return -1;
8437 }
8438
8439 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8440 NL80211_CMD_VENDOR)) ||
8441 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8442 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8443 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8444 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8445 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8446 !(params = nla_nest_start(
8447 msg,
8448 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_TWT_TERMINATE)) ||
8449 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8450 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE, 0)) {
8451 sigma_dut_print(dut, DUT_MSG_ERROR,
8452 "%s: err in adding vendor_cmd and vendor_data",
8453 __func__);
8454 nlmsg_free(msg);
8455 return -1;
8456 }
8457 nla_nest_end(msg, attr1);
8458 nla_nest_end(msg, params);
8459 nla_nest_end(msg, attr);
8460
8461 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8462 if (ret) {
8463 sigma_dut_print(dut, DUT_MSG_ERROR,
8464 "%s: err in send_and_recv_msgs, ret=%d",
8465 __func__, ret);
8466 }
8467
8468 return ret;
8469#else /* NL80211_SUPPORT */
8470 sigma_dut_print(dut, DUT_MSG_ERROR,
8471 "TWT teardown cannot be done without NL80211_SUPPORT defined");
8472 return -1;
8473#endif /* NL80211_SUPPORT */
8474}
8475
8476
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -08008477static int sta_transmit_omi(struct sigma_dut *dut, struct sigma_conn *conn,
8478 struct sigma_cmd *cmd)
8479{
8480#ifdef NL80211_SUPPORT
8481 struct nlattr *params;
8482 struct nlattr *attr;
8483 struct nlattr *attr1;
8484 struct nl_msg *msg;
8485 int ifindex, ret;
8486 const char *val;
8487 const char *intf = get_param(cmd, "Interface");
8488 uint8_t rx_nss = 0xFF, ch_bw = 0xFF, tx_nsts = 0xFF, ulmu_dis = 0,
8489 ulmu_data_dis = 0;
8490
8491 ifindex = if_nametoindex(intf);
8492 if (ifindex == 0) {
8493 sigma_dut_print(dut, DUT_MSG_ERROR,
8494 "%s: Index for interface %s failed",
8495 __func__, intf);
8496 return -1;
8497 }
8498 val = get_param(cmd, "OMCtrl_RxNSS");
8499 if (val)
8500 rx_nss = atoi(val);
8501
8502 val = get_param(cmd, "OMCtrl_ChnlWidth");
8503 if (val)
8504 ch_bw = atoi(val);
8505
8506 val = get_param(cmd, "OMCtrl_ULMUDisable");
8507 if (val)
8508 ulmu_dis = atoi(val);
8509
8510 val = get_param(cmd, "OMCtrl_TxNSTS");
8511 if (val)
8512 tx_nsts = atoi(val);
8513
8514 val = get_param(cmd, "OMCtrl_ULMUDataDisable");
8515 if (val)
8516 ulmu_data_dis = atoi(val);
8517
8518 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8519 NL80211_CMD_VENDOR)) ||
8520 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8521 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8522 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8523 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8524 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8525 !(params = nla_nest_start(
8526 msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OMI_TX)) ||
8527 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8528 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_RX_NSS, rx_nss) ||
8529 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_CH_BW, ch_bw) ||
8530 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_TX_NSTS, tx_nsts) ||
8531 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DATA_DISABLE,
8532 ulmu_data_dis) ||
8533 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DISABLE,
8534 ulmu_dis)) {
8535 sigma_dut_print(dut, DUT_MSG_ERROR,
8536 "%s: err in adding vendor_cmd and vendor_data",
8537 __func__);
8538 nlmsg_free(msg);
8539 return -1;
8540 }
8541 nla_nest_end(msg, attr1);
8542 nla_nest_end(msg, params);
8543 nla_nest_end(msg, attr);
8544
8545 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8546 if (ret) {
8547 sigma_dut_print(dut, DUT_MSG_ERROR,
8548 "%s: err in send_and_recv_msgs, ret=%d",
8549 __func__, ret);
8550 }
8551
8552 return ret;
8553#else /* NL80211_SUPPORT */
8554 sigma_dut_print(dut, DUT_MSG_ERROR,
8555 "OMI TX cannot be processed without NL80211_SUPPORT defined");
8556 return -1;
8557#endif /* NL80211_SUPPORT */
8558}
8559
8560
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008561static int cmd_sta_set_wireless_vht(struct sigma_dut *dut,
8562 struct sigma_conn *conn,
8563 struct sigma_cmd *cmd)
8564{
8565 const char *intf = get_param(cmd, "Interface");
8566 const char *val;
Arif Hussaina37e9552018-06-20 17:05:59 -07008567 const char *program;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008568 int tkip = -1;
8569 int wep = -1;
8570
Arif Hussaina37e9552018-06-20 17:05:59 -07008571 program = get_param(cmd, "Program");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008572 val = get_param(cmd, "SGI80");
8573 if (val) {
8574 int sgi80;
8575
8576 sgi80 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008577 run_iwpriv(dut, intf, "shortgi %d", sgi80);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008578 }
8579
8580 val = get_param(cmd, "TxBF");
8581 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008582 switch (get_driver_type(dut)) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008583 case DRIVER_WCN:
8584 if (sta_set_tx_beamformee(dut, intf, 1)) {
8585 send_resp(dut, conn, SIGMA_ERROR,
8586 "ErrorCode,Failed to set TX beamformee enable");
8587 return 0;
8588 }
8589 break;
8590 case DRIVER_ATHEROS:
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008591 if (run_iwpriv(dut, intf, "vhtsubfee 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008592 send_resp(dut, conn, SIGMA_ERROR,
8593 "ErrorCode,Setting vhtsubfee failed");
8594 return 0;
8595 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008596 if (run_iwpriv(dut, intf, "vhtsubfer 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008597 send_resp(dut, conn, SIGMA_ERROR,
8598 "ErrorCode,Setting vhtsubfer failed");
8599 return 0;
8600 }
8601 break;
8602 default:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008603 sigma_dut_print(dut, DUT_MSG_ERROR,
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008604 "Unsupported driver type");
8605 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008606 }
8607 }
8608
8609 val = get_param(cmd, "MU_TxBF");
8610 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008611 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008612 case DRIVER_ATHEROS:
8613 ath_sta_set_txsp_stream(dut, intf, "1SS");
8614 ath_sta_set_rxsp_stream(dut, intf, "1SS");
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008615 run_iwpriv(dut, intf, "vhtmubfee 1");
8616 run_iwpriv(dut, intf, "vhtmubfer 1");
Sunil Duttae9e5d12018-06-29 11:50:47 +05308617 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008618 case DRIVER_WCN:
8619 if (wcn_sta_set_sp_stream(dut, intf, "1SS") < 0) {
8620 send_resp(dut, conn, SIGMA_ERROR,
8621 "ErrorCode,Failed to set RX/TXSP_STREAM");
8622 return 0;
8623 }
Sunil Duttae9e5d12018-06-29 11:50:47 +05308624 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008625 default:
8626 sigma_dut_print(dut, DUT_MSG_ERROR,
8627 "Setting SP_STREAM not supported");
8628 break;
8629 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008630 }
8631
8632 val = get_param(cmd, "LDPC");
8633 if (val) {
8634 int ldpc;
8635
8636 ldpc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008637 run_iwpriv(dut, intf, "ldpc %d", ldpc);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008638 }
8639
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08008640 val = get_param(cmd, "BCC");
8641 if (val) {
8642 int bcc;
8643
8644 bcc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8645 /* use LDPC iwpriv itself to set bcc coding, bcc coding
8646 * is mutually exclusive to bcc */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008647 run_iwpriv(dut, intf, "ldpc %d", !bcc);
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08008648 }
8649
Arif Hussain7b47d2d2018-05-09 10:44:02 -07008650 val = get_param(cmd, "MaxHE-MCS_1SS_RxMapLTE80");
8651 if (val && dut->sta_nss == 1)
8652 cmd_set_max_he_mcs(dut, intf, atoi(val));
8653
8654 val = get_param(cmd, "MaxHE-MCS_2SS_RxMapLTE80");
8655 if (val && dut->sta_nss == 2)
8656 cmd_set_max_he_mcs(dut, intf, atoi(val));
8657
Arif Hussainac6c5112018-05-25 17:34:00 -07008658 val = get_param(cmd, "MCS_FixedRate");
8659 if (val) {
8660#ifdef NL80211_SUPPORT
8661 int mcs, ratecode = 0;
8662 enum he_mcs_config mcs_config;
8663 int ret;
Jouni Malinenb9b671d2019-04-26 13:23:17 +03008664 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07008665
8666 ratecode = (0x07 & dut->sta_nss) << 5;
8667 mcs = atoi(val);
8668 /* Add the MCS to the ratecode */
8669 if (mcs >= 0 && mcs <= 11) {
8670 ratecode += mcs;
8671 if (dut->device_type == STA_testbed &&
8672 mcs > 7 && mcs <= 11) {
8673 if (mcs <= 9)
8674 mcs_config = HE_80_MCS0_9;
8675 else
8676 mcs_config = HE_80_MCS0_11;
8677 ret = sta_set_he_mcs(dut, intf, mcs_config);
8678 if (ret) {
8679 sigma_dut_print(dut, DUT_MSG_ERROR,
8680 "MCS_FixedRate: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
8681 mcs, mcs_config, ret);
8682 }
8683 }
8684 snprintf(buf, sizeof(buf),
8685 "iwpriv %s set_11ax_rate 0x%03x",
8686 intf, ratecode);
8687 if (system(buf) != 0) {
8688 sigma_dut_print(dut, DUT_MSG_ERROR,
8689 "MCS_FixedRate: iwpriv setting of 11ax rates 0x%03x failed",
8690 ratecode);
8691 }
8692 } else {
8693 sigma_dut_print(dut, DUT_MSG_ERROR,
8694 "MCS_FixedRate: HE MCS %d not supported",
8695 mcs);
8696 }
8697#else /* NL80211_SUPPORT */
8698 sigma_dut_print(dut, DUT_MSG_ERROR,
8699 "MCS_FixedRate cannot be changed without NL80211_SUPPORT defined");
8700#endif /* NL80211_SUPPORT */
8701 }
8702
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008703 val = get_param(cmd, "opt_md_notif_ie");
8704 if (val) {
8705 char *result = NULL;
8706 char delim[] = ";";
8707 char token[30];
8708 int value, config_val = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308709 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008710
Peng Xub8fc5cc2017-05-10 17:27:28 -07008711 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308712 result = strtok_r(token, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008713
8714 /* Extract the NSS information */
8715 if (result) {
8716 value = atoi(result);
8717 switch (value) {
8718 case 1:
8719 config_val = 1;
8720 break;
8721 case 2:
8722 config_val = 3;
8723 break;
8724 case 3:
8725 config_val = 7;
8726 break;
8727 case 4:
8728 config_val = 15;
8729 break;
8730 default:
8731 config_val = 3;
8732 break;
8733 }
8734
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008735 run_iwpriv(dut, intf, "rxchainmask %d", config_val);
8736 run_iwpriv(dut, intf, "txchainmask %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008737
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008738 }
8739
8740 /* Extract the channel width information */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308741 result = strtok_r(NULL, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008742 if (result) {
8743 value = atoi(result);
8744 switch (value) {
8745 case 20:
8746 config_val = 0;
8747 break;
8748 case 40:
8749 config_val = 1;
8750 break;
8751 case 80:
8752 config_val = 2;
8753 break;
8754 case 160:
8755 config_val = 3;
8756 break;
8757 default:
8758 config_val = 2;
8759 break;
8760 }
8761
8762 dut->chwidth = config_val;
8763
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008764 run_iwpriv(dut, intf, "chwidth %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008765 }
8766
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008767 run_iwpriv(dut, intf, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008768 }
8769
8770 val = get_param(cmd, "nss_mcs_cap");
8771 if (val) {
8772 int nss, mcs;
8773 char token[20];
8774 char *result = NULL;
8775 unsigned int vht_mcsmap = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308776 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008777
Peng Xub8fc5cc2017-05-10 17:27:28 -07008778 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308779 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308780 if (!result) {
8781 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008782 "NSS not specified");
8783 send_resp(dut, conn, SIGMA_ERROR,
8784 "errorCode,NSS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308785 return 0;
8786 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008787 nss = atoi(result);
8788
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008789 run_iwpriv(dut, intf, "nss %d", nss);
Arif Hussainac6c5112018-05-25 17:34:00 -07008790 dut->sta_nss = nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008791
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308792 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008793 if (result == NULL) {
8794 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008795 "MCS not specified");
8796 send_resp(dut, conn, SIGMA_ERROR,
8797 "errorCode,MCS not specified");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008798 return 0;
8799 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308800 result = strtok_r(result, "-", &saveptr);
8801 result = strtok_r(NULL, "-", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308802 if (!result) {
8803 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008804 "MCS not specified");
8805 send_resp(dut, conn, SIGMA_ERROR,
8806 "errorCode,MCS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308807 return 0;
8808 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008809 mcs = atoi(result);
8810
Arif Hussaina37e9552018-06-20 17:05:59 -07008811 if (program && strcasecmp(program, "HE") == 0) {
8812#ifdef NL80211_SUPPORT
8813 enum he_mcs_config mcs_config;
8814 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008815
Arif Hussaina37e9552018-06-20 17:05:59 -07008816 if (mcs >= 0 && mcs <= 7) {
8817 mcs_config = HE_80_MCS0_7;
8818 } else if (mcs > 7 && mcs <= 9) {
8819 mcs_config = HE_80_MCS0_9;
8820 } else if (mcs > 9 && mcs <= 11) {
8821 mcs_config = HE_80_MCS0_11;
8822 } else {
8823 sigma_dut_print(dut, DUT_MSG_ERROR,
8824 "nss_mcs_cap: HE: Invalid mcs: %d",
8825 mcs);
8826 send_resp(dut, conn, SIGMA_ERROR,
8827 "errorCode,Invalid MCS");
8828 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008829 }
Arif Hussaina37e9552018-06-20 17:05:59 -07008830
8831 ret = sta_set_he_mcs(dut, intf, mcs_config);
8832 if (ret) {
8833 sigma_dut_print(dut, DUT_MSG_ERROR,
8834 "nss_mcs_cap: HE: Setting of MCS failed, mcs_config: %d, ret: %d",
8835 mcs_config, ret);
8836 send_resp(dut, conn, SIGMA_ERROR,
8837 "errorCode,Failed to set MCS");
8838 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008839 }
Arif Hussaina37e9552018-06-20 17:05:59 -07008840#else /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008841 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008842 "nss_mcs_cap: HE: MCS cannot be changed without NL80211_SUPPORT defined");
8843#endif /* NL80211_SUPPORT */
8844 } else {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008845 run_iwpriv(dut, intf, "vhtmcs %d", mcs);
Arif Hussaina37e9552018-06-20 17:05:59 -07008846
8847 switch (nss) {
8848 case 1:
8849 switch (mcs) {
8850 case 7:
8851 vht_mcsmap = 0xfffc;
8852 break;
8853 case 8:
8854 vht_mcsmap = 0xfffd;
8855 break;
8856 case 9:
8857 vht_mcsmap = 0xfffe;
8858 break;
8859 default:
8860 vht_mcsmap = 0xfffe;
8861 break;
8862 }
8863 break;
8864 case 2:
8865 switch (mcs) {
8866 case 7:
8867 vht_mcsmap = 0xfff0;
8868 break;
8869 case 8:
8870 vht_mcsmap = 0xfff5;
8871 break;
8872 case 9:
8873 vht_mcsmap = 0xfffa;
8874 break;
8875 default:
8876 vht_mcsmap = 0xfffa;
8877 break;
8878 }
8879 break;
8880 case 3:
8881 switch (mcs) {
8882 case 7:
8883 vht_mcsmap = 0xffc0;
8884 break;
8885 case 8:
8886 vht_mcsmap = 0xffd5;
8887 break;
8888 case 9:
8889 vht_mcsmap = 0xffea;
8890 break;
8891 default:
8892 vht_mcsmap = 0xffea;
8893 break;
8894 }
8895 break;
8896 default:
8897 vht_mcsmap = 0xffea;
8898 break;
8899 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008900 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008901 }
8902 }
8903
8904 /* UNSUPPORTED: val = get_param(cmd, "Tx_lgi_rate"); */
8905
8906 val = get_param(cmd, "Vht_tkip");
8907 if (val)
8908 tkip = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8909
8910 val = get_param(cmd, "Vht_wep");
8911 if (val)
8912 wep = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8913
8914 if (tkip != -1 || wep != -1) {
8915 if ((tkip == 1 && wep != 0) || (wep == 1 && tkip != 0)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008916 run_iwpriv(dut, intf, "htweptkip 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008917 } else if ((tkip == 0 && wep != 1) || (wep == 0 && tkip != 1)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008918 run_iwpriv(dut, intf, "htweptkip 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008919 } else {
8920 sigma_dut_print(dut, DUT_MSG_ERROR,
8921 "ErrorCode,mixed mode of VHT TKIP/WEP not supported");
8922 return 0;
8923 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008924 }
8925
Arif Hussain55f00da2018-07-03 08:28:26 -07008926 val = get_param(cmd, "txBandwidth");
8927 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008928 switch (get_driver_type(dut)) {
Arif Hussain55f00da2018-07-03 08:28:26 -07008929 case DRIVER_WCN:
8930 if (wcn_sta_set_width(dut, intf, val) < 0) {
8931 send_resp(dut, conn, SIGMA_ERROR,
8932 "ErrorCode,Failed to set txBandwidth");
8933 return 0;
8934 }
8935 break;
8936 case DRIVER_ATHEROS:
8937 if (ath_set_width(dut, conn, intf, val) < 0) {
8938 send_resp(dut, conn, SIGMA_ERROR,
8939 "ErrorCode,Failed to set txBandwidth");
8940 return 0;
8941 }
8942 break;
8943 default:
8944 sigma_dut_print(dut, DUT_MSG_ERROR,
8945 "Setting txBandwidth not supported");
8946 break;
8947 }
8948 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008949
Arif Hussain9765f7d2018-07-03 08:28:26 -07008950 val = get_param(cmd, "BeamformeeSTS");
8951 if (val) {
Kiran Kumar Lokerebc89d432018-07-10 12:20:13 -07008952 if (sta_set_tx_beamformee(dut, intf, 1)) {
8953 send_resp(dut, conn, SIGMA_ERROR,
8954 "ErrorCode,Failed to set TX beamformee enable");
8955 return 0;
8956 }
8957
Arif Hussain9765f7d2018-07-03 08:28:26 -07008958 if (sta_set_beamformee_sts(dut, intf, atoi(val))) {
8959 send_resp(dut, conn, SIGMA_ERROR,
8960 "ErrorCode,Failed to set BeamformeeSTS");
8961 return 0;
8962 }
8963 }
8964
Arif Hussain68d23f52018-07-11 13:39:08 -07008965 val = get_param(cmd, "Trig_MAC_Padding_Dur");
8966 if (val) {
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07008967#ifdef NL80211_SUPPORT
8968 enum qca_wlan_he_mac_padding_dur set_val;
8969
8970 switch (atoi(val)) {
8971 case 16:
8972 set_val = QCA_WLAN_HE_16US_OF_PROCESS_TIME;
8973 break;
8974 case 8:
8975 set_val = QCA_WLAN_HE_8US_OF_PROCESS_TIME;
8976 break;
8977 default:
8978 set_val = QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME;
8979 break;
8980 }
8981 if (sta_set_mac_padding_duration(dut, intf, set_val)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07008982 send_resp(dut, conn, SIGMA_ERROR,
8983 "ErrorCode,Failed to set MAC padding duration");
8984 return 0;
8985 }
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07008986#else /* NL80211_SUPPORT */
8987 sigma_dut_print(dut, DUT_MSG_ERROR,
8988 "MAC padding duration cannot be changed without NL80211_SUPPORT defined");
8989#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07008990 }
8991
Arif Hussain480d5f42019-03-12 14:40:42 -07008992 val = get_param(cmd, "TWT_ReqSupport");
8993 if (val) {
8994 int set_val;
8995
8996 if (strcasecmp(val, "Enable") == 0) {
8997 set_val = 1;
8998 } else if (strcasecmp(val, "Disable") == 0) {
8999 set_val = 0;
9000 } else {
9001 send_resp(dut, conn, SIGMA_ERROR,
9002 "ErrorCode,Invalid TWT_ReqSupport");
9003 return STATUS_SENT;
9004 }
9005
9006 if (sta_set_twt_req_support(dut, intf, set_val)) {
9007 sigma_dut_print(dut, DUT_MSG_ERROR,
9008 "Failed to set TWT req support %d",
9009 set_val);
9010 send_resp(dut, conn, SIGMA_ERROR,
9011 "ErrorCode,Failed to set TWT_ReqSupport");
9012 return STATUS_SENT;
9013 }
9014 }
9015
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07009016 val = get_param(cmd, "MU_EDCA");
9017 if (val && (strcasecmp(val, "Override") == 0)) {
9018 if (sta_set_mu_edca_override(dut, intf, 1)) {
9019 send_resp(dut, conn, SIGMA_ERROR,
9020 "ErrorCode,Failed to set MU EDCA override");
9021 return 0;
9022 }
9023 }
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009024
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07009025 val = get_param(cmd, "OMControl");
9026 if (val) {
9027 int set_val = 1;
9028
9029 if (strcasecmp(val, "Enable") == 0)
9030 set_val = 1;
9031 else if (strcasecmp(val, "Disable") == 0)
9032 set_val = 0;
9033
9034 if (sta_set_om_ctrl_supp(dut, intf, set_val)) {
9035 send_resp(dut, conn, SIGMA_ERROR,
9036 "ErrorCode,Failed to set OM ctrl supp");
9037 return 0;
9038 }
9039 }
9040
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009041 val = get_param(cmd, "ADDBAResp_BufSize");
9042 if (val) {
9043 int buf_size;
9044
9045 if (strcasecmp(val, "gt64") == 0)
9046 buf_size = 256;
9047 else
9048 buf_size = 64;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009049 if (get_driver_type(dut) == DRIVER_WCN &&
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009050 sta_set_addba_buf_size(dut, intf, buf_size)) {
9051 send_resp(dut, conn, SIGMA_ERROR,
9052 "ErrorCode,set addbaresp_buff_size failed");
9053 return 0;
9054 }
9055 }
9056
9057 val = get_param(cmd, "ADDBAReq_BufSize");
9058 if (val) {
9059 int buf_size;
9060
9061 if (strcasecmp(val, "gt64") == 0)
9062 buf_size = 256;
9063 else
9064 buf_size = 64;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009065 if (get_driver_type(dut) == DRIVER_WCN &&
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009066 sta_set_addba_buf_size(dut, intf, buf_size)) {
9067 send_resp(dut, conn, SIGMA_ERROR,
9068 "ErrorCode,set addbareq_buff_size failed");
9069 return 0;
9070 }
9071 }
9072
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009073 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
9074}
9075
9076
9077static int sta_set_wireless_60g(struct sigma_dut *dut,
9078 struct sigma_conn *conn,
9079 struct sigma_cmd *cmd)
9080{
9081 const char *dev_role = get_param(cmd, "DevRole");
9082
9083 if (!dev_role) {
9084 send_resp(dut, conn, SIGMA_INVALID,
9085 "ErrorCode,DevRole not specified");
9086 return 0;
9087 }
9088
9089 if (strcasecmp(dev_role, "PCP") == 0)
9090 return sta_set_60g_pcp(dut, conn, cmd);
9091 if (strcasecmp(dev_role, "STA") == 0)
9092 return sta_set_60g_sta(dut, conn, cmd);
9093 send_resp(dut, conn, SIGMA_INVALID,
9094 "ErrorCode,DevRole not supported");
9095 return 0;
9096}
9097
9098
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05309099static int sta_set_wireless_oce(struct sigma_dut *dut, struct sigma_conn *conn,
9100 struct sigma_cmd *cmd)
9101{
9102 int status;
9103 const char *intf = get_param(cmd, "Interface");
9104 const char *val = get_param(cmd, "DevRole");
9105
9106 if (val && strcasecmp(val, "STA-CFON") == 0) {
9107 status = sta_cfon_set_wireless(dut, conn, cmd);
9108 if (status)
9109 return status;
9110 }
9111 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
9112}
9113
9114
Jouni Malinen67433fc2020-06-26 22:50:33 +03009115static enum sigma_cmd_result
9116sta_set_wireless_wpa3(struct sigma_dut *dut, struct sigma_conn *conn,
9117 struct sigma_cmd *cmd)
Vamsi Krishnac1633d22020-05-06 18:31:21 +05309118{
9119 const char *intf = get_param(cmd, "Interface");
9120 const char *val;
9121
9122 val = get_param(cmd, "ocvc");
9123 if (val)
9124 dut->ocvc = atoi(val);
9125
Jouni Malinen67433fc2020-06-26 22:50:33 +03009126 val = get_param(cmd, "ClientPrivacy");
9127 if (val) {
9128 dut->client_privacy = atoi(val);
9129 if (dut->client_privacy &&
9130 (wpa_command(intf, "SET mac_addr 1") < 0 ||
9131 wpa_command(intf, "SET rand_addr_lifetime 1") < 0 ||
9132 wpa_command(intf, "SET preassoc_mac_addr 1") < 0 ||
9133 wpa_command(intf, "SET gas_rand_mac_addr 1") < 0 ||
9134 wpa_command(intf, "SET gas_rand_addr_lifetime 1") < 0)) {
9135 send_resp(dut, conn, SIGMA_ERROR,
9136 "errorCode,Failed to enable random MAC address use");
9137 return STATUS_SENT_ERROR;
9138 }
9139 }
9140
Vamsi Krishnac1633d22020-05-06 18:31:21 +05309141 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
9142}
9143
9144
Jouni Malinenf7222712019-06-13 01:50:21 +03009145static enum sigma_cmd_result cmd_sta_set_wireless(struct sigma_dut *dut,
9146 struct sigma_conn *conn,
9147 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009148{
9149 const char *val;
9150
9151 val = get_param(cmd, "Program");
9152 if (val) {
9153 if (strcasecmp(val, "11n") == 0)
9154 return cmd_sta_set_11n(dut, conn, cmd);
Amarnath Hullur Subramanyam4f860292018-01-31 03:49:35 -08009155 if (strcasecmp(val, "VHT") == 0 || strcasecmp(val, "HE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009156 return cmd_sta_set_wireless_vht(dut, conn, cmd);
9157 if (strcasecmp(val, "60ghz") == 0)
9158 return sta_set_wireless_60g(dut, conn, cmd);
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05309159 if (strcasecmp(val, "OCE") == 0)
9160 return sta_set_wireless_oce(dut, conn, cmd);
Alexei Avshalom Lazar66bb9972018-12-18 16:01:43 +02009161 /* sta_set_wireless in WPS program is only used for 60G */
9162 if (is_60g_sigma_dut(dut))
9163 return sta_set_wireless_60g(dut, conn, cmd);
Vamsi Krishnac1633d22020-05-06 18:31:21 +05309164 if (strcasecmp(val, "WPA3") == 0)
9165 return sta_set_wireless_wpa3(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009166 send_resp(dut, conn, SIGMA_ERROR,
9167 "ErrorCode,Program value not supported");
9168 } else {
9169 send_resp(dut, conn, SIGMA_ERROR,
9170 "ErrorCode,Program argument not available");
9171 }
9172
9173 return 0;
9174}
9175
9176
9177static void ath_sta_inject_frame(struct sigma_dut *dut, const char *intf,
9178 int tid)
9179{
9180 char buf[100];
9181 int tid_to_dscp [] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 };
9182
Pradeep Reddy POTTETId31d1322016-10-13 17:22:03 +05309183 if (tid < 0 ||
9184 tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) {
9185 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid);
9186 return;
9187 }
9188
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009189 /*
9190 * Two ways to ensure that addba request with a
9191 * non zero TID could be sent out. EV 117296
9192 */
9193 snprintf(buf, sizeof(buf),
9194 "ping -c 8 -Q %d `arp -a | grep wlan0 | awk '{print $2}' | tr -d '()'`",
9195 tid);
9196 if (system(buf) != 0) {
9197 sigma_dut_print(dut, DUT_MSG_ERROR,
9198 "Ping did not send out");
9199 }
9200
9201 snprintf(buf, sizeof(buf),
9202 "iwconfig %s | grep Access | awk '{print $6}' > %s",
9203 intf, VI_QOS_TMP_FILE);
9204 if (system(buf) != 0)
9205 return;
9206
9207 snprintf(buf, sizeof(buf),
9208 "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s",
9209 intf, VI_QOS_TMP_FILE);
9210 if (system(buf) != 0)
9211 sigma_dut_print(dut, DUT_MSG_ERROR, "HWaddr matching failed");
9212
9213 snprintf(buf,sizeof(buf), "sed -n '3,$p' %s >> %s",
9214 VI_QOS_REFFILE, VI_QOS_TMP_FILE);
9215 if (system(buf) != 0) {
9216 sigma_dut_print(dut, DUT_MSG_ERROR,
9217 "VI_QOS_TEMP_FILE generation error failed");
9218 }
9219 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
9220 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
9221 if (system(buf) != 0) {
9222 sigma_dut_print(dut, DUT_MSG_ERROR,
9223 "VI_QOS_FILE generation failed");
9224 }
9225
9226 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
9227 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
9228 if (system(buf) != 0) {
9229 sigma_dut_print(dut, DUT_MSG_ERROR,
9230 "VI_QOS_FILE generation failed");
9231 }
9232
9233 snprintf(buf, sizeof(buf), "ethinject %s %s", intf, VI_QOS_FILE);
9234 if (system(buf) != 0) {
9235 }
9236}
9237
9238
9239static int ath_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
9240 struct sigma_cmd *cmd)
9241{
9242 const char *intf = get_param(cmd, "Interface");
9243 const char *val;
9244 int tid = 0;
9245 char buf[100];
9246
9247 val = get_param(cmd, "TID");
9248 if (val) {
9249 tid = atoi(val);
9250 if (tid)
9251 ath_sta_inject_frame(dut, intf, tid);
9252 }
9253
9254 /* Command sequence for ADDBA request on Peregrine based devices */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009255 run_iwpriv(dut, intf, "setaddbaoper 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009256
9257 snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4", intf, tid);
9258 if (system(buf) != 0) {
9259 sigma_dut_print(dut, DUT_MSG_ERROR,
9260 "wifitool senddelba failed");
9261 }
9262
9263 snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64", intf, tid);
9264 if (system(buf) != 0) {
9265 sigma_dut_print(dut, DUT_MSG_ERROR,
9266 "wifitool sendaddba failed");
9267 }
9268
9269 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
9270
9271 return 1;
9272}
9273
9274
Lior David9981b512017-01-20 13:16:40 +02009275#ifdef __linux__
9276
9277static int wil6210_send_addba(struct sigma_dut *dut, const char *dest_mac,
9278 int agg_size)
9279{
9280 char dir[128], buf[128];
9281 FILE *f;
9282 regex_t re;
9283 regmatch_t m[2];
Jouni Malinen3aa72862019-05-29 23:14:51 +03009284 int rc, ret = -1, vring_id, found, res;
Lior David9981b512017-01-20 13:16:40 +02009285
9286 if (wil6210_get_debugfs_dir(dut, dir, sizeof(dir))) {
9287 sigma_dut_print(dut, DUT_MSG_ERROR,
9288 "failed to get wil6210 debugfs dir");
9289 return -1;
9290 }
9291
Jouni Malinen3aa72862019-05-29 23:14:51 +03009292 res = snprintf(buf, sizeof(buf), "%s/vrings", dir);
9293 if (res < 0 || res >= sizeof(buf))
9294 return -1;
Lior David9981b512017-01-20 13:16:40 +02009295 f = fopen(buf, "r");
9296 if (!f) {
9297 sigma_dut_print(dut, DUT_MSG_ERROR, "failed to open: %s", buf);
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009298 /* newer wil6210 driver renamed file to "rings" */
Jouni Malinen3aa72862019-05-29 23:14:51 +03009299 res = snprintf(buf, sizeof(buf), "%s/rings", dir);
9300 if (res < 0 || res >= sizeof(buf))
9301 return -1;
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009302 f = fopen(buf, "r");
9303 if (!f) {
9304 sigma_dut_print(dut, DUT_MSG_ERROR,
9305 "failed to open: %s", buf);
9306 return -1;
9307 }
Lior David9981b512017-01-20 13:16:40 +02009308 }
9309
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009310 /* can be either VRING tx... or RING... */
9311 if (regcomp(&re, "RING tx_[ \t]*([0-9]+)", REG_EXTENDED)) {
Lior David9981b512017-01-20 13:16:40 +02009312 sigma_dut_print(dut, DUT_MSG_ERROR, "regcomp failed");
9313 goto out;
9314 }
9315
9316 /* find TX VRING for the mac address */
9317 found = 0;
9318 while (fgets(buf, sizeof(buf), f)) {
9319 if (strcasestr(buf, dest_mac)) {
9320 found = 1;
9321 break;
9322 }
9323 }
9324
9325 if (!found) {
9326 sigma_dut_print(dut, DUT_MSG_ERROR,
9327 "no TX VRING for %s", dest_mac);
9328 goto out;
9329 }
9330
9331 /* extract VRING ID, "VRING tx_<id> = {" */
9332 if (!fgets(buf, sizeof(buf), f)) {
9333 sigma_dut_print(dut, DUT_MSG_ERROR,
9334 "no VRING start line for %s", dest_mac);
9335 goto out;
9336 }
9337
9338 rc = regexec(&re, buf, 2, m, 0);
9339 regfree(&re);
9340 if (rc || m[1].rm_so < 0) {
9341 sigma_dut_print(dut, DUT_MSG_ERROR,
9342 "no VRING TX ID for %s", dest_mac);
9343 goto out;
9344 }
9345 buf[m[1].rm_eo] = 0;
9346 vring_id = atoi(&buf[m[1].rm_so]);
9347
9348 /* send the addba command */
9349 fclose(f);
Jouni Malinen3aa72862019-05-29 23:14:51 +03009350 res = snprintf(buf, sizeof(buf), "%s/back", dir);
9351 if (res < 0 || res >= sizeof(buf))
9352 return -1;
Lior David9981b512017-01-20 13:16:40 +02009353 f = fopen(buf, "w");
9354 if (!f) {
9355 sigma_dut_print(dut, DUT_MSG_ERROR,
9356 "failed to open: %s", buf);
9357 return -1;
9358 }
9359
9360 fprintf(f, "add %d %d\n", vring_id, agg_size);
9361
9362 ret = 0;
9363
9364out:
9365 fclose(f);
9366
9367 return ret;
9368}
9369
9370
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009371int send_addba_60g(struct sigma_dut *dut, struct sigma_conn *conn,
9372 struct sigma_cmd *cmd, const char *mac_param)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009373{
9374 const char *val;
9375 int tid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009376
9377 val = get_param(cmd, "TID");
9378 if (val) {
9379 tid = atoi(val);
9380 if (tid != 0) {
9381 sigma_dut_print(dut, DUT_MSG_ERROR,
9382 "Ignore TID %d for send_addba use TID 0 for 60g since only 0 required on TX",
9383 tid);
9384 }
9385 }
9386
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009387 val = get_param(cmd, mac_param);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009388 if (!val) {
9389 sigma_dut_print(dut, DUT_MSG_ERROR,
9390 "Currently not supporting addba for 60G without Dest_mac");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02009391 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009392 }
9393
Lior David9981b512017-01-20 13:16:40 +02009394 if (wil6210_send_addba(dut, val, dut->back_rcv_buf))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009395 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009396
9397 return 1;
9398}
9399
Lior David9981b512017-01-20 13:16:40 +02009400#endif /* __linux__ */
9401
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009402
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009403static int wcn_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
9404 struct sigma_cmd *cmd)
9405{
9406#ifdef NL80211_SUPPORT
9407 const char *intf = get_param(cmd, "Interface");
9408 const char *val;
9409 int tid = -1;
9410 int bufsize = 64;
9411 struct nl_msg *msg;
9412 int ret = 0;
9413 struct nlattr *params;
9414 int ifindex;
9415
9416 val = get_param(cmd, "TID");
9417 if (val)
9418 tid = atoi(val);
9419
9420 if (tid == -1) {
9421 send_resp(dut, conn, SIGMA_ERROR,
9422 "ErrorCode,sta_send_addba tid invalid");
9423 return 0;
9424 }
9425
9426 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
9427
9428 ifindex = if_nametoindex(intf);
9429 if (ifindex == 0) {
9430 sigma_dut_print(dut, DUT_MSG_ERROR,
9431 "%s: Index for interface %s failed",
9432 __func__, intf);
9433 send_resp(dut, conn, SIGMA_ERROR,
9434 "ErrorCode,sta_send_addba interface invalid");
9435 return 0;
9436 }
9437
9438 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9439 NL80211_CMD_VENDOR)) ||
9440 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9441 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9442 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9443 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
9444 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9445 nla_put_u8(msg,
9446 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADD_DEL_BA_SESSION,
9447 QCA_WLAN_ADD_BA) ||
9448 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BA_TID,
9449 tid) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -07009450 nla_put_u16(msg,
9451 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
9452 bufsize)) {
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009453 sigma_dut_print(dut, DUT_MSG_ERROR,
9454 "%s: err in adding vendor_cmd and vendor_data",
9455 __func__);
9456 nlmsg_free(msg);
9457 send_resp(dut, conn, SIGMA_ERROR,
9458 "ErrorCode,sta_send_addba err in adding vendor_cmd and vendor_data");
9459 return 0;
9460 }
9461 nla_nest_end(msg, params);
9462
9463 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9464 if (ret) {
9465 sigma_dut_print(dut, DUT_MSG_ERROR,
9466 "%s: err in send_and_recv_msgs, ret=%d",
9467 __func__, ret);
Sunil Dutt30605592018-05-04 20:35:50 +05309468 if (ret == -EOPNOTSUPP)
9469 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009470 send_resp(dut, conn, SIGMA_ERROR,
9471 "ErrorCode,sta_send_addba err in send_and_recv_msgs");
9472 return 0;
9473 }
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009474#else /* NL80211_SUPPORT */
9475 sigma_dut_print(dut, DUT_MSG_ERROR,
9476 "sta_send_addba not supported without NL80211_SUPPORT defined");
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009477#endif /* NL80211_SUPPORT */
Sunil Dutt30605592018-05-04 20:35:50 +05309478
9479 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009480}
9481
9482
Jouni Malinenf7222712019-06-13 01:50:21 +03009483static enum sigma_cmd_result cmd_sta_send_addba(struct sigma_dut *dut,
9484 struct sigma_conn *conn,
9485 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009486{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009487 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009488 case DRIVER_ATHEROS:
9489 return ath_sta_send_addba(dut, conn, cmd);
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009490 case DRIVER_WCN:
9491 return wcn_sta_send_addba(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +02009492#ifdef __linux__
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009493 case DRIVER_WIL6210:
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009494 return send_addba_60g(dut, conn, cmd, "Dest_mac");
Lior David9981b512017-01-20 13:16:40 +02009495#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009496 default:
9497 /*
9498 * There is no driver specific implementation for other drivers.
9499 * Ignore the command and report COMPLETE since the following
9500 * throughput test operation will end up sending ADDBA anyway.
9501 */
9502 return 1;
9503 }
9504}
9505
9506
9507int inject_eth_frame(int s, const void *data, size_t len,
9508 unsigned short ethtype, char *dst, char *src)
9509{
9510 struct iovec iov[4] = {
9511 {
9512 .iov_base = dst,
9513 .iov_len = ETH_ALEN,
9514 },
9515 {
9516 .iov_base = src,
9517 .iov_len = ETH_ALEN,
9518 },
9519 {
9520 .iov_base = &ethtype,
9521 .iov_len = sizeof(unsigned short),
9522 },
9523 {
9524 .iov_base = (void *) data,
9525 .iov_len = len,
9526 }
9527 };
9528 struct msghdr msg = {
9529 .msg_name = NULL,
9530 .msg_namelen = 0,
9531 .msg_iov = iov,
9532 .msg_iovlen = 4,
9533 .msg_control = NULL,
9534 .msg_controllen = 0,
9535 .msg_flags = 0,
9536 };
9537
9538 return sendmsg(s, &msg, 0);
9539}
9540
9541#if defined(__linux__) || defined(__QNXNTO__)
9542
9543int inject_frame(int s, const void *data, size_t len, int encrypt)
9544{
9545#define IEEE80211_RADIOTAP_F_WEP 0x04
9546#define IEEE80211_RADIOTAP_F_FRAG 0x08
9547 unsigned char rtap_hdr[] = {
9548 0x00, 0x00, /* radiotap version */
9549 0x0e, 0x00, /* radiotap length */
9550 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
9551 IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */
9552 0x00, /* padding */
9553 0x00, 0x00, /* RX and TX flags to indicate that */
9554 0x00, 0x00, /* this is the injected frame directly */
9555 };
9556 struct iovec iov[2] = {
9557 {
9558 .iov_base = &rtap_hdr,
9559 .iov_len = sizeof(rtap_hdr),
9560 },
9561 {
9562 .iov_base = (void *) data,
9563 .iov_len = len,
9564 }
9565 };
9566 struct msghdr msg = {
9567 .msg_name = NULL,
9568 .msg_namelen = 0,
9569 .msg_iov = iov,
9570 .msg_iovlen = 2,
9571 .msg_control = NULL,
9572 .msg_controllen = 0,
9573 .msg_flags = 0,
9574 };
9575
9576 if (encrypt)
9577 rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP;
9578
9579 return sendmsg(s, &msg, 0);
9580}
9581
9582
9583int open_monitor(const char *ifname)
9584{
9585#ifdef __QNXNTO__
9586 struct sockaddr_dl ll;
9587 int s;
9588
9589 memset(&ll, 0, sizeof(ll));
9590 ll.sdl_family = AF_LINK;
9591 ll.sdl_index = if_nametoindex(ifname);
9592 if (ll.sdl_index == 0) {
9593 perror("if_nametoindex");
9594 return -1;
9595 }
9596 s = socket(PF_INET, SOCK_RAW, 0);
9597#else /* __QNXNTO__ */
9598 struct sockaddr_ll ll;
9599 int s;
9600
9601 memset(&ll, 0, sizeof(ll));
9602 ll.sll_family = AF_PACKET;
9603 ll.sll_ifindex = if_nametoindex(ifname);
9604 if (ll.sll_ifindex == 0) {
9605 perror("if_nametoindex");
9606 return -1;
9607 }
9608 s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
9609#endif /* __QNXNTO__ */
9610 if (s < 0) {
9611 perror("socket[PF_PACKET,SOCK_RAW]");
9612 return -1;
9613 }
9614
9615 if (bind(s, (struct sockaddr *) &ll, sizeof(ll)) < 0) {
9616 perror("monitor socket bind");
9617 close(s);
9618 return -1;
9619 }
9620
9621 return s;
9622}
9623
9624
9625static int hex2num(char c)
9626{
9627 if (c >= '0' && c <= '9')
9628 return c - '0';
9629 if (c >= 'a' && c <= 'f')
9630 return c - 'a' + 10;
9631 if (c >= 'A' && c <= 'F')
9632 return c - 'A' + 10;
9633 return -1;
9634}
9635
9636
9637int hwaddr_aton(const char *txt, unsigned char *addr)
9638{
9639 int i;
9640
9641 for (i = 0; i < 6; i++) {
9642 int a, b;
9643
9644 a = hex2num(*txt++);
9645 if (a < 0)
9646 return -1;
9647 b = hex2num(*txt++);
9648 if (b < 0)
9649 return -1;
9650 *addr++ = (a << 4) | b;
9651 if (i < 5 && *txt++ != ':')
9652 return -1;
9653 }
9654
9655 return 0;
9656}
9657
9658#endif /* defined(__linux__) || defined(__QNXNTO__) */
9659
Veerendranath Jakkam49774122020-07-05 09:52:18 +05309660
9661#ifdef NL80211_SUPPORT
9662static int nl80211_send_frame_cmd(struct sigma_dut *dut, const char *intf,
9663 const u8 *data, size_t data_len, int freq)
9664{
9665 struct nl_msg *msg;
9666 int ret = 0;
9667 int ifindex;
9668
9669 ifindex = if_nametoindex(intf);
9670 if (ifindex == 0) {
9671 sigma_dut_print(dut, DUT_MSG_ERROR,
9672 "%s: Index for interface %s failed",
9673 __func__, intf);
9674 return -1;
9675 }
9676
9677 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9678 NL80211_CMD_FRAME)) ||
9679 (freq && nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
9680 nla_put(msg, NL80211_ATTR_FRAME, data_len, data)) {
9681 sigma_dut_print(dut, DUT_MSG_ERROR,
9682 "%s: Error in adding NL80211_CMD_FRAME",
9683 __func__);
9684 nlmsg_free(msg);
9685 return -1;
9686 }
9687
9688 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9689 if (ret) {
9690 sigma_dut_print(dut, DUT_MSG_ERROR,
9691 "nl80211: Frame command failed: ret=%d (%s) req=%u",
9692 ret, strerror(-ret), freq);
9693 return -1;
9694 }
9695
9696 return 0;
9697}
9698#endif /* NL80211_SUPPORT */
9699
9700
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009701enum send_frame_type {
9702 DISASSOC, DEAUTH, SAQUERY, AUTH, ASSOCREQ, REASSOCREQ, DLS_REQ
9703};
9704enum send_frame_protection {
9705 CORRECT_KEY, INCORRECT_KEY, UNPROTECTED
9706};
9707
9708
9709static int sta_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn,
Veerendranath Jakkam49774122020-07-05 09:52:18 +05309710 const char *intf, enum send_frame_type frame,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009711 enum send_frame_protection protected,
Veerendranath Jakkam49774122020-07-05 09:52:18 +05309712 const char *dest, int use_monitor)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009713{
9714#ifdef __linux__
9715 unsigned char buf[1000], *pos;
9716 int s, res;
9717 char bssid[20], addr[20];
9718 char result[32], ssid[100];
9719 size_t ssid_len;
9720
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009721 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009722 sizeof(result)) < 0 ||
9723 strncmp(result, "COMPLETED", 9) != 0) {
9724 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Not connected");
9725 return 0;
9726 }
9727
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009728 if (get_wpa_status(get_station_ifname(dut), "bssid",
9729 bssid, sizeof(bssid)) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009730 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9731 "current BSSID");
9732 return 0;
9733 }
9734
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009735 if (get_wpa_status(get_station_ifname(dut), "address",
9736 addr, sizeof(addr)) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009737 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9738 "own MAC address");
9739 return 0;
9740 }
9741
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009742 if (get_wpa_status(get_station_ifname(dut), "ssid", ssid, sizeof(ssid))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009743 < 0) {
9744 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9745 "current SSID");
9746 return 0;
9747 }
9748 ssid_len = strlen(ssid);
9749
9750 pos = buf;
9751
9752 /* Frame Control */
9753 switch (frame) {
9754 case DISASSOC:
9755 *pos++ = 0xa0;
9756 break;
9757 case DEAUTH:
9758 *pos++ = 0xc0;
9759 break;
9760 case SAQUERY:
9761 *pos++ = 0xd0;
9762 break;
9763 case AUTH:
9764 *pos++ = 0xb0;
9765 break;
9766 case ASSOCREQ:
9767 *pos++ = 0x00;
9768 break;
9769 case REASSOCREQ:
9770 *pos++ = 0x20;
9771 break;
9772 case DLS_REQ:
9773 *pos++ = 0xd0;
9774 break;
9775 }
9776
9777 if (protected == INCORRECT_KEY)
9778 *pos++ = 0x40; /* Set Protected field to 1 */
9779 else
9780 *pos++ = 0x00;
9781
9782 /* Duration */
9783 *pos++ = 0x00;
9784 *pos++ = 0x00;
9785
9786 /* addr1 = DA (current AP) */
9787 hwaddr_aton(bssid, pos);
9788 pos += 6;
9789 /* addr2 = SA (own address) */
9790 hwaddr_aton(addr, pos);
9791 pos += 6;
9792 /* addr3 = BSSID (current AP) */
9793 hwaddr_aton(bssid, pos);
9794 pos += 6;
9795
9796 /* Seq# (to be filled by driver/mac80211) */
9797 *pos++ = 0x00;
9798 *pos++ = 0x00;
9799
9800 if (protected == INCORRECT_KEY) {
9801 /* CCMP parameters */
9802 memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8);
9803 pos += 8;
9804 }
9805
9806 if (protected == INCORRECT_KEY) {
9807 switch (frame) {
9808 case DEAUTH:
9809 /* Reason code (encrypted) */
9810 memcpy(pos, "\xa7\x39", 2);
9811 pos += 2;
9812 break;
9813 case DISASSOC:
9814 /* Reason code (encrypted) */
9815 memcpy(pos, "\xa7\x39", 2);
9816 pos += 2;
9817 break;
9818 case SAQUERY:
9819 /* Category|Action|TransID (encrypted) */
9820 memcpy(pos, "\x6f\xbd\xe9\x4d", 4);
9821 pos += 4;
9822 break;
9823 default:
9824 return -1;
9825 }
9826
9827 /* CCMP MIC */
9828 memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8);
9829 pos += 8;
9830 } else {
9831 switch (frame) {
9832 case DEAUTH:
9833 /* reason code = 8 */
9834 *pos++ = 0x08;
9835 *pos++ = 0x00;
9836 break;
9837 case DISASSOC:
9838 /* reason code = 8 */
9839 *pos++ = 0x08;
9840 *pos++ = 0x00;
9841 break;
9842 case SAQUERY:
9843 /* Category - SA Query */
9844 *pos++ = 0x08;
9845 /* SA query Action - Request */
9846 *pos++ = 0x00;
9847 /* Transaction ID */
9848 *pos++ = 0x12;
9849 *pos++ = 0x34;
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +05309850 if (dut->saquery_oci_freq) {
9851 /* OCI IE - Extended ID */
9852 *pos++ = 0xFF;
9853 *pos++ = 0x04;
9854 *pos++ = 0x36;
9855 /* Operating Class */
9856 *pos++ = 0x74;
9857 /* Primary Channel */
9858 *pos++ = freq_to_channel(dut->saquery_oci_freq);
9859 /* Frequency Segment 1 Channel Number */
9860 *pos++ = 0x00;
9861 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009862 break;
9863 case AUTH:
9864 /* Auth Alg (Open) */
9865 *pos++ = 0x00;
9866 *pos++ = 0x00;
9867 /* Seq# */
9868 *pos++ = 0x01;
9869 *pos++ = 0x00;
9870 /* Status code */
9871 *pos++ = 0x00;
9872 *pos++ = 0x00;
9873 break;
9874 case ASSOCREQ:
9875 /* Capability Information */
9876 *pos++ = 0x31;
9877 *pos++ = 0x04;
9878 /* Listen Interval */
9879 *pos++ = 0x0a;
9880 *pos++ = 0x00;
9881 /* SSID */
9882 *pos++ = 0x00;
9883 *pos++ = ssid_len;
9884 memcpy(pos, ssid, ssid_len);
9885 pos += ssid_len;
9886 /* Supported Rates */
9887 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
9888 10);
9889 pos += 10;
9890 /* Extended Supported Rates */
9891 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
9892 pos += 6;
9893 /* RSN */
9894 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
9895 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
9896 "\x00\x00\x00\x00\x0f\xac\x06", 28);
9897 pos += 28;
9898 break;
9899 case REASSOCREQ:
9900 /* Capability Information */
9901 *pos++ = 0x31;
9902 *pos++ = 0x04;
9903 /* Listen Interval */
9904 *pos++ = 0x0a;
9905 *pos++ = 0x00;
9906 /* Current AP */
9907 hwaddr_aton(bssid, pos);
9908 pos += 6;
9909 /* SSID */
9910 *pos++ = 0x00;
9911 *pos++ = ssid_len;
9912 memcpy(pos, ssid, ssid_len);
9913 pos += ssid_len;
9914 /* Supported Rates */
9915 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
9916 10);
9917 pos += 10;
9918 /* Extended Supported Rates */
9919 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
9920 pos += 6;
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +05309921 /* RSNE - Group and Pairwise ciphers */
9922 memcpy(pos,
9923 "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x04",
9924 14);
9925 pos += 14;
9926 /* RSNE - AKM Suite count */
9927 *pos++ = 0x01;
9928 *pos++ = 0x00;
9929 /* RSNE - AKM Suites */
9930 if (dut->program == PROGRAM_WPA3)
9931 memcpy(pos, "\x00\x0f\xac\x08", 4);
9932 else
9933 memcpy(pos, "\x00\x0f\xac\x02", 4);
9934 pos += 4;
9935 /* RSNE - Capabilities */
9936 *pos++ = 0xc0;
9937 if (dut->ocvc)
9938 *pos++ = 0x40;
9939 else
9940 *pos++ = 0x00;
9941 /* RSNE - PMKID list and Group Management Ciphers */
9942 memcpy(pos, "\x00\x00\x00\x0f\xac\x06", 6);
9943 pos += 6;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009944 break;
9945 case DLS_REQ:
9946 /* Category - DLS */
9947 *pos++ = 0x02;
9948 /* DLS Action - Request */
9949 *pos++ = 0x00;
9950 /* Destination MACAddress */
9951 if (dest)
9952 hwaddr_aton(dest, pos);
9953 else
9954 memset(pos, 0, 6);
9955 pos += 6;
9956 /* Source MACAddress */
9957 hwaddr_aton(addr, pos);
9958 pos += 6;
9959 /* Capability Information */
9960 *pos++ = 0x10; /* Privacy */
9961 *pos++ = 0x06; /* QoS */
9962 /* DLS Timeout Value */
9963 *pos++ = 0x00;
9964 *pos++ = 0x01;
9965 /* Supported rates */
9966 *pos++ = 0x01;
9967 *pos++ = 0x08;
9968 *pos++ = 0x0c; /* 6 Mbps */
9969 *pos++ = 0x12; /* 9 Mbps */
9970 *pos++ = 0x18; /* 12 Mbps */
9971 *pos++ = 0x24; /* 18 Mbps */
9972 *pos++ = 0x30; /* 24 Mbps */
9973 *pos++ = 0x48; /* 36 Mbps */
9974 *pos++ = 0x60; /* 48 Mbps */
9975 *pos++ = 0x6c; /* 54 Mbps */
9976 /* TODO: Extended Supported Rates */
9977 /* TODO: HT Capabilities */
9978 break;
9979 }
9980 }
9981
Veerendranath Jakkam49774122020-07-05 09:52:18 +05309982 if (use_monitor) {
9983 s = open_monitor("sigmadut");
9984 if (s < 0) {
9985 send_resp(dut, conn, SIGMA_ERROR,
9986 "errorCode,Failed to open monitor socket");
9987 return 0;
9988 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009989
Veerendranath Jakkam49774122020-07-05 09:52:18 +05309990 res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY);
9991 if (res < 0) {
9992 send_resp(dut, conn, SIGMA_ERROR,
9993 "errorCode,Failed to inject frame");
9994 close(s);
9995 return 0;
9996 }
9997 if (res < pos - buf) {
9998 send_resp(dut, conn, SIGMA_ERROR,
9999 "errorCode,Only partial frame sent");
10000 close(s);
10001 return 0;
10002 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010003
Veerendranath Jakkam49774122020-07-05 09:52:18 +053010004 close(s);
10005 } else {
10006#ifdef NL80211_SUPPORT
10007 int freq;
10008 char freq_str[10];
10009
10010 if (get_wpa_status(get_station_ifname(dut), "freq",
10011 freq_str, sizeof(freq_str)) < 0) {
10012 send_resp(dut, conn, SIGMA_ERROR,
10013 "errorCode,Could not get current operating frequency");
10014 return 0;
10015 }
10016 freq = atoi(freq_str);
10017
10018 if (nl80211_send_frame_cmd(dut, intf, buf, pos - buf, freq)) {
10019 send_resp(dut, conn, SIGMA_ERROR,
10020 "errorCode,Failed to inject frame");
10021 return 0;
10022 }
10023#else /* NL80211_SUPPORT */
10024 send_resp(dut, conn, SIGMA_ERROR,
10025 "errorCode,Failed to inject frame (no NL80211_SUPPORT)");
10026 return 0;
10027#endif /* NL80211_SUPPORT */
10028 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010029
10030 return 1;
10031#else /* __linux__ */
10032 send_resp(dut, conn, SIGMA_ERROR, "errorCode,sta_send_frame not "
10033 "yet supported");
10034 return 0;
10035#endif /* __linux__ */
10036}
10037
10038
10039static int cmd_sta_send_frame_tdls(struct sigma_dut *dut,
10040 struct sigma_conn *conn,
10041 struct sigma_cmd *cmd)
10042{
10043 const char *intf = get_param(cmd, "Interface");
10044 const char *sta, *val;
10045 unsigned char addr[ETH_ALEN];
10046 char buf[100];
10047
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030010048 if (!intf)
10049 return -1;
10050
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010051 sta = get_param(cmd, "peer");
10052 if (sta == NULL)
10053 sta = get_param(cmd, "station");
10054 if (sta == NULL) {
10055 send_resp(dut, conn, SIGMA_ERROR,
10056 "ErrorCode,Missing peer address");
10057 return 0;
10058 }
10059 if (hwaddr_aton(sta, addr) < 0) {
10060 send_resp(dut, conn, SIGMA_ERROR,
10061 "ErrorCode,Invalid peer address");
10062 return 0;
10063 }
10064
10065 val = get_param(cmd, "type");
10066 if (val == NULL)
10067 return -1;
10068
10069 if (strcasecmp(val, "DISCOVERY") == 0) {
10070 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", sta);
10071 if (wpa_command(intf, buf) < 0) {
10072 send_resp(dut, conn, SIGMA_ERROR,
10073 "ErrorCode,Failed to send TDLS discovery");
10074 return 0;
10075 }
10076 return 1;
10077 }
10078
10079 if (strcasecmp(val, "SETUP") == 0) {
10080 int status = 0, timeout = 0;
10081
10082 val = get_param(cmd, "Status");
10083 if (val)
10084 status = atoi(val);
10085
10086 val = get_param(cmd, "Timeout");
10087 if (val)
10088 timeout = atoi(val);
10089
10090 if (status != 0 && status != 37) {
10091 send_resp(dut, conn, SIGMA_ERROR,
10092 "ErrorCode,Unsupported status value");
10093 return 0;
10094 }
10095
10096 if (timeout != 0 && timeout != 301) {
10097 send_resp(dut, conn, SIGMA_ERROR,
10098 "ErrorCode,Unsupported timeout value");
10099 return 0;
10100 }
10101
10102 if (status && timeout) {
10103 send_resp(dut, conn, SIGMA_ERROR,
10104 "ErrorCode,Unsupported timeout+status "
10105 "combination");
10106 return 0;
10107 }
10108
10109 if (status == 37 &&
10110 wpa_command(intf, "SET tdls_testing 0x200")) {
10111 send_resp(dut, conn, SIGMA_ERROR,
10112 "ErrorCode,Failed to enable "
10113 "decline setup response test mode");
10114 return 0;
10115 }
10116
10117 if (timeout == 301) {
10118 int res;
10119 if (dut->no_tpk_expiration)
10120 res = wpa_command(intf,
10121 "SET tdls_testing 0x108");
10122 else
10123 res = wpa_command(intf,
10124 "SET tdls_testing 0x8");
10125 if (res) {
10126 send_resp(dut, conn, SIGMA_ERROR,
10127 "ErrorCode,Failed to set short TPK "
10128 "lifetime");
10129 return 0;
10130 }
10131 }
10132
10133 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", sta);
10134 if (wpa_command(intf, buf) < 0) {
10135 send_resp(dut, conn, SIGMA_ERROR,
10136 "ErrorCode,Failed to send TDLS setup");
10137 return 0;
10138 }
10139 return 1;
10140 }
10141
10142 if (strcasecmp(val, "TEARDOWN") == 0) {
10143 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", sta);
10144 if (wpa_command(intf, buf) < 0) {
10145 send_resp(dut, conn, SIGMA_ERROR,
10146 "ErrorCode,Failed to send TDLS teardown");
10147 return 0;
10148 }
10149 return 1;
10150 }
10151
10152 send_resp(dut, conn, SIGMA_ERROR,
10153 "ErrorCode,Unsupported TDLS frame");
10154 return 0;
10155}
10156
10157
10158static int sta_ap_known(const char *ifname, const char *bssid)
10159{
10160 char buf[4096];
10161
Jouni Malinendd32f192018-09-15 02:55:19 +030010162 snprintf(buf, sizeof(buf), "BSS MASK=1 %s", bssid);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010163 if (wpa_command_resp(ifname, buf, buf, sizeof(buf)) < 0)
10164 return 0;
10165 if (strncmp(buf, "id=", 3) != 0)
10166 return 0;
10167 return 1;
10168}
10169
10170
10171static int sta_scan_ap(struct sigma_dut *dut, const char *ifname,
10172 const char *bssid)
10173{
10174 int res;
10175 struct wpa_ctrl *ctrl;
10176 char buf[256];
10177
10178 if (sta_ap_known(ifname, bssid))
10179 return 0;
10180 sigma_dut_print(dut, DUT_MSG_DEBUG,
10181 "AP not in BSS table - start scan");
10182
10183 ctrl = open_wpa_mon(ifname);
10184 if (ctrl == NULL) {
10185 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
10186 "wpa_supplicant monitor connection");
10187 return -1;
10188 }
10189
10190 if (wpa_command(ifname, "SCAN") < 0) {
10191 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to start scan");
10192 wpa_ctrl_detach(ctrl);
10193 wpa_ctrl_close(ctrl);
10194 return -1;
10195 }
10196
10197 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
10198 buf, sizeof(buf));
10199
10200 wpa_ctrl_detach(ctrl);
10201 wpa_ctrl_close(ctrl);
10202
10203 if (res < 0) {
10204 sigma_dut_print(dut, DUT_MSG_INFO, "Scan did not complete");
10205 return -1;
10206 }
10207
10208 if (sta_ap_known(ifname, bssid))
10209 return 0;
10210 sigma_dut_print(dut, DUT_MSG_INFO, "AP not in BSS table");
10211 return -1;
10212}
10213
10214
10215static int cmd_sta_send_frame_hs2_neighadv(struct sigma_dut *dut,
10216 struct sigma_conn *conn,
10217 struct sigma_cmd *cmd,
10218 const char *intf)
10219{
10220 char buf[200];
10221
10222 snprintf(buf, sizeof(buf), "ndsend 2001:DB8::1 %s", intf);
10223 if (system(buf) != 0) {
10224 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Failed to run "
10225 "ndsend");
10226 return 0;
10227 }
10228
10229 return 1;
10230}
10231
10232
10233static int cmd_sta_send_frame_hs2_neighsolreq(struct sigma_dut *dut,
10234 struct sigma_conn *conn,
10235 struct sigma_cmd *cmd,
10236 const char *intf)
10237{
10238 char buf[200];
10239 const char *ip = get_param(cmd, "SenderIP");
10240
Peng Xu26b356d2017-10-04 17:58:16 -070010241 if (!ip)
10242 return 0;
10243
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010244 snprintf(buf, sizeof(buf), "ndisc6 -nm %s %s -r 4", ip, intf);
10245 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10246 if (system(buf) == 0) {
10247 sigma_dut_print(dut, DUT_MSG_INFO,
10248 "Neighbor Solicitation got a response "
10249 "for %s@%s", ip, intf);
10250 }
10251
10252 return 1;
10253}
10254
10255
10256static int cmd_sta_send_frame_hs2_arpprobe(struct sigma_dut *dut,
10257 struct sigma_conn *conn,
10258 struct sigma_cmd *cmd,
10259 const char *ifname)
10260{
10261 char buf[200];
10262 const char *ip = get_param(cmd, "SenderIP");
10263
10264 if (ip == NULL) {
10265 send_resp(dut, conn, SIGMA_ERROR,
10266 "ErrorCode,Missing SenderIP parameter");
10267 return 0;
10268 }
10269 snprintf(buf, sizeof(buf), "arping -I %s -D %s -c 4", ifname, ip);
10270 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10271 if (system(buf) != 0) {
10272 sigma_dut_print(dut, DUT_MSG_INFO, "arping DAD got a response "
10273 "for %s@%s", ip, ifname);
10274 }
10275
10276 return 1;
10277}
10278
10279
10280static int cmd_sta_send_frame_hs2_arpannounce(struct sigma_dut *dut,
10281 struct sigma_conn *conn,
10282 struct sigma_cmd *cmd,
10283 const char *ifname)
10284{
10285 char buf[200];
10286 char ip[16];
10287 int s;
Peng Xub3756882017-10-04 14:39:09 -070010288 struct ifreq ifr;
10289 struct sockaddr_in saddr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010290
10291 s = socket(PF_INET, SOCK_DGRAM, 0);
Peng Xub3756882017-10-04 14:39:09 -070010292 if (s < 0) {
10293 perror("socket");
10294 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010295 }
10296
Peng Xub3756882017-10-04 14:39:09 -070010297 memset(&ifr, 0, sizeof(ifr));
10298 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
10299 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
10300 sigma_dut_print(dut, DUT_MSG_INFO,
10301 "Failed to get %s IP address: %s",
10302 ifname, strerror(errno));
10303 close(s);
10304 return -1;
10305 }
10306 close(s);
10307
10308 memcpy(&saddr, &ifr.ifr_addr, sizeof(struct sockaddr_in));
10309 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
10310
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010311 snprintf(buf, sizeof(buf), "arping -I %s -s %s %s -c 4", ifname, ip,
10312 ip);
10313 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10314 if (system(buf) != 0) {
10315 }
10316
10317 return 1;
10318}
10319
10320
10321static int cmd_sta_send_frame_hs2_arpreply(struct sigma_dut *dut,
10322 struct sigma_conn *conn,
10323 struct sigma_cmd *cmd,
10324 const char *ifname)
10325{
10326 char buf[200], addr[20];
10327 char dst[ETH_ALEN], src[ETH_ALEN];
10328 short ethtype = htons(ETH_P_ARP);
10329 char *pos;
10330 int s, res;
10331 const char *val;
10332 struct sockaddr_in taddr;
10333
10334 val = get_param(cmd, "dest");
10335 if (val)
10336 hwaddr_aton(val, (unsigned char *) dst);
10337
10338 val = get_param(cmd, "DestIP");
10339 if (val)
10340 inet_aton(val, &taddr.sin_addr);
Peng Xu151c9e12017-10-04 14:39:09 -070010341 else
10342 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010343
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010344 if (get_wpa_status(get_station_ifname(dut), "address", addr,
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010345 sizeof(addr)) < 0)
10346 return -2;
10347 hwaddr_aton(addr, (unsigned char *) src);
10348
10349 pos = buf;
10350 *pos++ = 0x00;
10351 *pos++ = 0x01;
10352 *pos++ = 0x08;
10353 *pos++ = 0x00;
10354 *pos++ = 0x06;
10355 *pos++ = 0x04;
10356 *pos++ = 0x00;
10357 *pos++ = 0x02;
10358 memcpy(pos, src, ETH_ALEN);
10359 pos += ETH_ALEN;
10360 memcpy(pos, &taddr.sin_addr, 4);
10361 pos += 4;
10362 memcpy(pos, dst, ETH_ALEN);
10363 pos += ETH_ALEN;
10364 memcpy(pos, &taddr.sin_addr, 4);
10365 pos += 4;
10366
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010367 s = open_monitor(get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010368 if (s < 0) {
10369 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
10370 "monitor socket");
10371 return 0;
10372 }
10373
10374 res = inject_eth_frame(s, buf, pos - buf, ethtype, dst, src);
10375 if (res < 0) {
10376 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
10377 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +053010378 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010379 return 0;
10380 }
10381
10382 close(s);
10383
10384 return 1;
10385}
10386
10387
10388static int cmd_sta_send_frame_hs2_dls_req(struct sigma_dut *dut,
10389 struct sigma_conn *conn,
10390 struct sigma_cmd *cmd,
10391 const char *intf, const char *dest)
10392{
10393 char buf[100];
10394
10395 if (if_nametoindex("sigmadut") == 0) {
10396 snprintf(buf, sizeof(buf),
10397 "iw dev %s interface add sigmadut type monitor",
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010398 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010399 if (system(buf) != 0 ||
10400 if_nametoindex("sigmadut") == 0) {
10401 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
10402 "monitor interface with '%s'", buf);
10403 return -2;
10404 }
10405 }
10406
10407 if (system("ifconfig sigmadut up") != 0) {
10408 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
10409 "monitor interface up");
10410 return -2;
10411 }
10412
Veerendranath Jakkam49774122020-07-05 09:52:18 +053010413 return sta_inject_frame(dut, conn, intf, DLS_REQ, UNPROTECTED, dest, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010414}
10415
10416
10417static int cmd_sta_send_frame_hs2(struct sigma_dut *dut,
10418 struct sigma_conn *conn,
10419 struct sigma_cmd *cmd)
10420{
10421 const char *intf = get_param(cmd, "Interface");
10422 const char *dest = get_param(cmd, "Dest");
10423 const char *type = get_param(cmd, "FrameName");
10424 const char *val;
10425 char buf[200], *pos, *end;
10426 int count, count2;
10427
10428 if (type == NULL)
10429 type = get_param(cmd, "Type");
10430
10431 if (intf == NULL || dest == NULL || type == NULL)
10432 return -1;
10433
10434 if (strcasecmp(type, "NeighAdv") == 0)
10435 return cmd_sta_send_frame_hs2_neighadv(dut, conn, cmd, intf);
10436
10437 if (strcasecmp(type, "NeighSolicitReq") == 0)
10438 return cmd_sta_send_frame_hs2_neighsolreq(dut, conn, cmd, intf);
10439
10440 if (strcasecmp(type, "ARPProbe") == 0)
10441 return cmd_sta_send_frame_hs2_arpprobe(dut, conn, cmd, intf);
10442
10443 if (strcasecmp(type, "ARPAnnounce") == 0)
10444 return cmd_sta_send_frame_hs2_arpannounce(dut, conn, cmd, intf);
10445
10446 if (strcasecmp(type, "ARPReply") == 0)
10447 return cmd_sta_send_frame_hs2_arpreply(dut, conn, cmd, intf);
10448
10449 if (strcasecmp(type, "DLS-request") == 0 ||
10450 strcasecmp(type, "DLSrequest") == 0)
10451 return cmd_sta_send_frame_hs2_dls_req(dut, conn, cmd, intf,
10452 dest);
10453
10454 if (strcasecmp(type, "ANQPQuery") != 0 &&
10455 strcasecmp(type, "Query") != 0) {
10456 send_resp(dut, conn, SIGMA_ERROR,
10457 "ErrorCode,Unsupported HS 2.0 send frame type");
10458 return 0;
10459 }
10460
10461 if (sta_scan_ap(dut, intf, dest) < 0) {
10462 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not find "
10463 "the requested AP");
10464 return 0;
10465 }
10466
10467 pos = buf;
10468 end = buf + sizeof(buf);
10469 count = 0;
10470 pos += snprintf(pos, end - pos, "ANQP_GET %s ", dest);
10471
10472 val = get_param(cmd, "ANQP_CAP_LIST");
10473 if (val && atoi(val)) {
10474 pos += snprintf(pos, end - pos, "%s257", count > 0 ? "," : "");
10475 count++;
10476 }
10477
10478 val = get_param(cmd, "VENUE_NAME");
10479 if (val && atoi(val)) {
10480 pos += snprintf(pos, end - pos, "%s258", count > 0 ? "," : "");
10481 count++;
10482 }
10483
10484 val = get_param(cmd, "NETWORK_AUTH_TYPE");
10485 if (val && atoi(val)) {
10486 pos += snprintf(pos, end - pos, "%s260", count > 0 ? "," : "");
10487 count++;
10488 }
10489
10490 val = get_param(cmd, "ROAMING_CONS");
10491 if (val && atoi(val)) {
10492 pos += snprintf(pos, end - pos, "%s261", count > 0 ? "," : "");
10493 count++;
10494 }
10495
10496 val = get_param(cmd, "IP_ADDR_TYPE_AVAILABILITY");
10497 if (val && atoi(val)) {
10498 pos += snprintf(pos, end - pos, "%s262", count > 0 ? "," : "");
10499 count++;
10500 }
10501
10502 val = get_param(cmd, "NAI_REALM_LIST");
10503 if (val && atoi(val)) {
10504 pos += snprintf(pos, end - pos, "%s263", count > 0 ? "," : "");
10505 count++;
10506 }
10507
10508 val = get_param(cmd, "3GPP_INFO");
10509 if (val && atoi(val)) {
10510 pos += snprintf(pos, end - pos, "%s264", count > 0 ? "," : "");
10511 count++;
10512 }
10513
10514 val = get_param(cmd, "DOMAIN_LIST");
10515 if (val && atoi(val)) {
10516 pos += snprintf(pos, end - pos, "%s268", count > 0 ? "," : "");
10517 count++;
10518 }
10519
Jouni Malinen34cf9532018-04-29 19:26:33 +030010520 val = get_param(cmd, "Venue_URL");
10521 if (val && atoi(val)) {
10522 pos += snprintf(pos, end - pos, "%s277", count > 0 ? "," : "");
10523 count++;
10524 }
10525
Jouni Malinend3bca5d2018-04-29 17:25:23 +030010526 val = get_param(cmd, "Advice_Of_Charge");
10527 if (val && atoi(val)) {
10528 pos += snprintf(pos, end - pos, "%s278", count > 0 ? "," : "");
10529 count++;
10530 }
10531
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010532 if (count && wpa_command(intf, buf)) {
10533 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,ANQP_GET failed");
10534 return 0;
10535 }
10536
10537 pos = buf;
10538 end = buf + sizeof(buf);
10539 count2 = 0;
10540 pos += snprintf(pos, end - pos, "HS20_ANQP_GET %s ", dest);
10541
10542 val = get_param(cmd, "HS_CAP_LIST");
10543 if (val && atoi(val)) {
10544 pos += snprintf(pos, end - pos, "%s2", count2 > 0 ? "," : "");
10545 count2++;
10546 }
10547
10548 val = get_param(cmd, "OPER_NAME");
10549 if (val && atoi(val)) {
10550 pos += snprintf(pos, end - pos, "%s3", count2 > 0 ? "," : "");
10551 count2++;
10552 }
10553
10554 val = get_param(cmd, "WAN_METRICS");
10555 if (!val)
10556 val = get_param(cmd, "WAN_MAT");
10557 if (!val)
10558 val = get_param(cmd, "WAN_MET");
10559 if (val && atoi(val)) {
10560 pos += snprintf(pos, end - pos, "%s4", count2 > 0 ? "," : "");
10561 count2++;
10562 }
10563
10564 val = get_param(cmd, "CONNECTION_CAPABILITY");
10565 if (val && atoi(val)) {
10566 pos += snprintf(pos, end - pos, "%s5", count2 > 0 ? "," : "");
10567 count2++;
10568 }
10569
10570 val = get_param(cmd, "OP_CLASS");
10571 if (val && atoi(val)) {
10572 pos += snprintf(pos, end - pos, "%s7", count2 > 0 ? "," : "");
10573 count2++;
10574 }
10575
10576 val = get_param(cmd, "OSU_PROVIDER_LIST");
10577 if (val && atoi(val)) {
10578 pos += snprintf(pos, end - pos, "%s8", count2 > 0 ? "," : "");
10579 count2++;
10580 }
10581
Jouni Malinenf67afec2018-04-29 19:24:58 +030010582 val = get_param(cmd, "OPER_ICON_METADATA");
10583 if (!val)
10584 val = get_param(cmd, "OPERATOR_ICON_METADATA");
10585 if (val && atoi(val)) {
10586 pos += snprintf(pos, end - pos, "%s12", count2 > 0 ? "," : "");
10587 count2++;
10588 }
10589
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010590 if (count && count2) {
10591 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before sending out "
10592 "second query");
10593 sleep(1);
10594 }
10595
10596 if (count2 && wpa_command(intf, buf)) {
10597 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,HS20_ANQP_GET "
10598 "failed");
10599 return 0;
10600 }
10601
10602 val = get_param(cmd, "NAI_HOME_REALM_LIST");
10603 if (val) {
10604 if (count || count2) {
10605 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
10606 "sending out second query");
10607 sleep(1);
10608 }
10609
10610 if (strcmp(val, "1") == 0)
10611 val = "mail.example.com";
10612 snprintf(buf, end - pos,
10613 "HS20_GET_NAI_HOME_REALM_LIST %s realm=%s",
10614 dest, val);
10615 if (wpa_command(intf, buf)) {
10616 send_resp(dut, conn, SIGMA_ERROR,
10617 "ErrorCode,HS20_GET_NAI_HOME_REALM_LIST "
10618 "failed");
10619 return 0;
10620 }
10621 }
10622
10623 val = get_param(cmd, "ICON_REQUEST");
10624 if (val) {
10625 if (count || count2) {
10626 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
10627 "sending out second query");
10628 sleep(1);
10629 }
10630
10631 snprintf(buf, end - pos,
10632 "HS20_ICON_REQUEST %s %s", dest, val);
10633 if (wpa_command(intf, buf)) {
10634 send_resp(dut, conn, SIGMA_ERROR,
10635 "ErrorCode,HS20_ICON_REQUEST failed");
10636 return 0;
10637 }
10638 }
10639
10640 return 1;
10641}
10642
10643
10644static int ath_sta_send_frame_vht(struct sigma_dut *dut,
10645 struct sigma_conn *conn,
10646 struct sigma_cmd *cmd)
10647{
10648 const char *val;
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010649 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010650 int chwidth, nss;
10651
10652 val = get_param(cmd, "framename");
10653 if (!val)
10654 return -1;
10655 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
10656
10657 /* Command sequence to generate Op mode notification */
10658 if (val && strcasecmp(val, "Op_md_notif_frm") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010659 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010660
10661 /* Disable STBC */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010662 run_iwpriv(dut, ifname, "tx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010663
10664 /* Extract Channel width */
10665 val = get_param(cmd, "Channel_width");
10666 if (val) {
10667 switch (atoi(val)) {
10668 case 20:
10669 chwidth = 0;
10670 break;
10671 case 40:
10672 chwidth = 1;
10673 break;
10674 case 80:
10675 chwidth = 2;
10676 break;
10677 case 160:
10678 chwidth = 3;
10679 break;
10680 default:
10681 chwidth = 2;
10682 break;
10683 }
10684
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010685 run_iwpriv(dut, ifname, "chwidth %d", chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010686 }
10687
10688 /* Extract NSS */
10689 val = get_param(cmd, "NSS");
10690 if (val) {
10691 switch (atoi(val)) {
10692 case 1:
10693 nss = 1;
10694 break;
10695 case 2:
10696 nss = 3;
10697 break;
10698 case 3:
10699 nss = 7;
10700 break;
10701 default:
10702 /* We do not support NSS > 3 */
10703 nss = 3;
10704 break;
10705 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010706 run_iwpriv(dut, ifname, "rxchainmask %d", nss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010707 }
10708
10709 /* Opmode notify */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010710 run_iwpriv(dut, ifname, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010711 }
10712
10713 return 1;
10714}
10715
10716
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070010717static int wcn_sta_set_pmf_config(struct sigma_dut *dut, const char *intf,
10718 enum send_frame_protection protected)
10719{
10720#ifdef NL80211_SUPPORT
10721 struct nl_msg *msg;
10722 int ret = 0;
10723 struct nlattr *params;
10724 int ifindex;
10725
10726 ifindex = if_nametoindex(intf);
10727 if (ifindex == 0) {
10728 sigma_dut_print(dut, DUT_MSG_ERROR,
10729 "%s: Index for interface %s failed",
10730 __func__, intf);
10731 return -1;
10732 }
10733
10734 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
10735 NL80211_CMD_VENDOR)) ||
10736 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
10737 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
10738 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
10739 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
10740 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
10741 nla_put_u8(msg,
10742 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_PMF_PROTECTION,
10743 protected)) {
10744 sigma_dut_print(dut, DUT_MSG_ERROR,
10745 "%s: err in adding vendor_cmd and vendor_data",
10746 __func__);
10747 nlmsg_free(msg);
10748 return -1;
10749 }
10750 nla_nest_end(msg, params);
10751
10752 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
10753 if (ret) {
10754 sigma_dut_print(dut, DUT_MSG_ERROR,
10755 "%s: err in send_and_recv_msgs, ret=%d",
10756 __func__, ret);
10757 }
10758 return ret;
10759#else /* NL80211_SUPPORT */
10760 sigma_dut_print(dut, DUT_MSG_ERROR,
10761 "PMF config cannot be set without NL80211_SUPPORT defined");
10762 return -1;
10763#endif /* NL80211_SUPPORT */
10764}
10765
10766
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010767static int cmd_sta_send_frame_vht(struct sigma_dut *dut,
10768 struct sigma_conn *conn,
10769 struct sigma_cmd *cmd)
10770{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010771 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010772 case DRIVER_ATHEROS:
10773 return ath_sta_send_frame_vht(dut, conn, cmd);
10774 default:
10775 send_resp(dut, conn, SIGMA_ERROR,
10776 "errorCode,Unsupported sta_set_frame(VHT) with the current driver");
10777 return 0;
10778 }
10779}
10780
10781
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070010782static int wcn_sta_send_disassoc(struct sigma_dut *dut, const char *intf)
10783{
10784#ifdef NL80211_SUPPORT
10785 struct nl_msg *msg;
10786 int ret = 0;
10787 struct nlattr *params;
10788 int ifindex;
10789
10790 ifindex = if_nametoindex(intf);
10791 if (ifindex == 0) {
10792 sigma_dut_print(dut, DUT_MSG_ERROR,
10793 "%s: Index for interface %s failed",
10794 __func__, intf);
10795 return -1;
10796 }
10797
10798 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
10799 NL80211_CMD_VENDOR)) ||
10800 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
10801 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
10802 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
10803 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
10804 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
10805 nla_put_flag(msg,
10806 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_DISASSOC_TX)) {
10807 sigma_dut_print(dut, DUT_MSG_ERROR,
10808 "%s: err in adding vendor_cmd and vendor_data",
10809 __func__);
10810 nlmsg_free(msg);
10811 return -1;
10812 }
10813 nla_nest_end(msg, params);
10814
10815 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
10816 if (ret) {
10817 sigma_dut_print(dut, DUT_MSG_ERROR,
10818 "%s: err in send_and_recv_msgs, ret=%d",
10819 __func__, ret);
10820 }
10821 return ret;
10822#else /* NL80211_SUPPORT */
10823 sigma_dut_print(dut, DUT_MSG_ERROR,
10824 "Disassoc Tx cannot be done without NL80211_SUPPORT defined");
10825 return -1;
10826#endif /* NL80211_SUPPORT */
10827}
10828
10829
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010830static int wcn_sta_send_frame_he(struct sigma_dut *dut, struct sigma_conn *conn,
10831 struct sigma_cmd *cmd)
10832{
10833 const char *val;
10834 const char *intf = get_param(cmd, "Interface");
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070010835 enum send_frame_protection protected;
10836 const char *pmf;
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010837
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030010838 if (!intf)
10839 return -1;
10840
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010841 val = get_param(cmd, "framename");
10842 if (!val)
10843 return -1;
10844 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
10845
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070010846 pmf = get_param(cmd, "PMFProtected");
10847 if (!pmf)
10848 pmf = get_param(cmd, "Protected");
10849 if (pmf) {
10850 if (strcasecmp(pmf, "Correct-key") == 0 ||
10851 strcasecmp(pmf, "CorrectKey") == 0) {
10852 protected = CORRECT_KEY;
10853 } else if (strcasecmp(pmf, "IncorrectKey") == 0) {
10854 protected = INCORRECT_KEY;
10855 } else if (strcasecmp(pmf, "Unprotected") == 0) {
10856 protected = UNPROTECTED;
10857 } else {
10858 send_resp(dut, conn, SIGMA_ERROR,
10859 "errorCode,Unsupported PMFProtected");
10860 return STATUS_SENT_ERROR;
10861 }
10862 sigma_dut_print(dut, DUT_MSG_DEBUG, "Config PMF protection %d",
10863 protected);
10864 wcn_sta_set_pmf_config(dut, intf, protected);
10865 }
10866
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010867 /* Command sequence to generate Op mode notification */
10868 if (val && strcasecmp(val, "action") == 0) {
10869 val = get_param(cmd, "PPDUTxType");
10870 if (val && strcasecmp(val, "TB") == 0) {
10871 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 1)) {
10872 sigma_dut_print(dut, DUT_MSG_ERROR,
10873 "failed to send TB PPDU Tx cfg");
10874 send_resp(dut, conn, SIGMA_ERROR,
10875 "ErrorCode,set TB PPDU Tx cfg failed");
10876 return 0;
10877 }
10878 return 1;
10879 }
10880
10881 sigma_dut_print(dut, DUT_MSG_ERROR,
10882 "Action Tx type is not defined");
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070010883
10884 return SUCCESS_SEND_STATUS;
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010885 }
10886
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070010887 if (strcasecmp(val, "disassoc") == 0)
10888 wcn_sta_send_disassoc(dut, intf);
10889
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010890 return 1;
10891}
10892
10893
10894static int cmd_sta_send_frame_he(struct sigma_dut *dut,
10895 struct sigma_conn *conn,
10896 struct sigma_cmd *cmd)
10897{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010898 switch (get_driver_type(dut)) {
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010899 case DRIVER_WCN:
10900 return wcn_sta_send_frame_he(dut, conn, cmd);
10901 default:
10902 send_resp(dut, conn, SIGMA_ERROR,
10903 "errorCode,Unsupported sta_set_frame(HE) with the current driver");
10904 return 0;
10905 }
10906}
10907
10908
Lior David0fe101e2017-03-09 16:09:50 +020010909#ifdef __linux__
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010910
10911static int
10912wil6210_send_p2p_frame_60g(struct sigma_dut *dut, struct sigma_cmd *cmd,
10913 const char *frame_name, const char *dest_mac)
10914{
10915 int isprobereq = strcasecmp(frame_name, "probereq") == 0;
10916 const char *ssid = get_param(cmd, "ssid");
10917 const char *countstr = get_param(cmd, "count");
10918 const char *channelstr = get_param(cmd, "channel");
10919 const char *group_id = get_param(cmd, "groupid");
10920 const char *client_id = get_param(cmd, "clientmac");
10921 int count, channel, freq, i;
10922 const char *fname;
10923 char frame[1024], src_mac[20], group_id_attr[25],
10924 device_macstr[3 * ETH_ALEN], client_mac[ETH_ALEN];
10925 const char *group_ssid;
10926 const int group_ssid_prefix_len = 9;
10927 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *) frame;
10928 size_t framelen = sizeof(frame);
10929 struct template_frame_tag tags[2];
10930 size_t tags_total = ARRAY_SIZE(tags);
10931 int tag_index, len, dst_len;
10932
10933 if (!countstr || !channelstr) {
10934 sigma_dut_print(dut, DUT_MSG_ERROR,
10935 "Missing argument: count, channel");
10936 return -1;
10937 }
10938 if (isprobereq && !ssid) {
10939 sigma_dut_print(dut, DUT_MSG_ERROR,
10940 "Missing argument: ssid");
10941 return -1;
10942 }
10943 if (!isprobereq && (!group_id || !client_id)) {
10944 sigma_dut_print(dut, DUT_MSG_ERROR,
10945 "Missing argument: group_id, client_id");
10946 return -1;
10947 }
10948
10949 count = atoi(countstr);
10950 channel = atoi(channelstr);
10951 freq = channel_to_freq(dut, channel);
10952
10953 if (!freq) {
10954 sigma_dut_print(dut, DUT_MSG_ERROR,
10955 "invalid channel: %s", channelstr);
10956 return -1;
10957 }
10958
10959 if (isprobereq) {
10960 if (strcasecmp(ssid, "wildcard") == 0) {
10961 fname = "probe_req_wildcard.txt";
10962 } else if (strcasecmp(ssid, "P2P_Wildcard") == 0) {
10963 fname = "probe_req_P2P_Wildcard.txt";
10964 } else {
10965 sigma_dut_print(dut, DUT_MSG_ERROR,
10966 "invalid probe request type");
10967 return -1;
10968 }
10969 } else {
10970 fname = "P2P_device_discovery_req.txt";
10971 }
10972
10973 if (parse_template_frame_file(dut, fname, frame, &framelen,
10974 tags, &tags_total)) {
10975 sigma_dut_print(dut, DUT_MSG_ERROR,
10976 "invalid frame template: %s", fname);
10977 return -1;
10978 }
10979
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010980 if (get_wpa_status(get_station_ifname(dut), "address",
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010981 src_mac, sizeof(src_mac)) < 0 ||
10982 parse_mac_address(dut, src_mac, &hdr->addr2[0]) ||
10983 parse_mac_address(dut, dest_mac, &hdr->addr1[0]))
10984 return -1;
10985 /* Use wildcard BSSID, since we are in PBSS */
10986 memset(&hdr->addr3, 0xFF, ETH_ALEN);
10987
10988 if (!isprobereq) {
10989 tag_index = find_template_frame_tag(tags, tags_total, 1);
10990 if (tag_index < 0) {
10991 sigma_dut_print(dut, DUT_MSG_ERROR,
10992 "can't find device id attribute");
10993 return -1;
10994 }
10995 if (parse_mac_address(dut, client_id,
10996 (unsigned char *) client_mac)) {
10997 sigma_dut_print(dut, DUT_MSG_ERROR,
10998 "invalid client_id: %s", client_id);
10999 return -1;
11000 }
11001 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
11002 framelen - tags[tag_index].offset,
11003 IEEE80211_P2P_ATTR_DEVICE_ID,
11004 client_mac, ETH_ALEN)) {
11005 sigma_dut_print(dut, DUT_MSG_ERROR,
11006 "fail to replace device id attribute");
11007 return -1;
11008 }
11009
11010 /*
11011 * group_id arg contains device MAC address followed by
11012 * space and SSID (DIRECT-somessid).
11013 * group id attribute contains device address (6 bytes)
11014 * followed by SSID prefix DIRECT-XX (9 bytes)
11015 */
11016 if (strlen(group_id) < sizeof(device_macstr)) {
11017 sigma_dut_print(dut, DUT_MSG_ERROR,
11018 "group_id arg too short");
11019 return -1;
11020 }
11021 memcpy(device_macstr, group_id, sizeof(device_macstr));
11022 device_macstr[sizeof(device_macstr) - 1] = '\0';
11023 if (parse_mac_address(dut, device_macstr,
11024 (unsigned char *) group_id_attr)) {
11025 sigma_dut_print(dut, DUT_MSG_ERROR,
11026 "fail to parse device address from group_id");
11027 return -1;
11028 }
11029 group_ssid = strchr(group_id, ' ');
11030 if (!group_ssid) {
11031 sigma_dut_print(dut, DUT_MSG_ERROR,
11032 "invalid group_id arg, no ssid");
11033 return -1;
11034 }
11035 group_ssid++;
11036 len = strlen(group_ssid);
11037 if (len < group_ssid_prefix_len) {
11038 sigma_dut_print(dut, DUT_MSG_ERROR,
11039 "group_id SSID too short");
11040 return -1;
11041 }
11042 dst_len = sizeof(group_id_attr) - ETH_ALEN;
11043 if (len > dst_len) {
11044 sigma_dut_print(dut, DUT_MSG_ERROR,
11045 "group_id SSID (%s) too long",
11046 group_ssid);
11047 return -1;
11048 }
11049
11050 memcpy(group_id_attr + ETH_ALEN, group_ssid, len);
11051 tag_index = find_template_frame_tag(tags, tags_total, 2);
11052 if (tag_index < 0) {
11053 sigma_dut_print(dut, DUT_MSG_ERROR,
11054 "can't find group id attribute");
11055 return -1;
11056 }
11057 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
11058 framelen - tags[tag_index].offset,
11059 IEEE80211_P2P_ATTR_GROUP_ID,
11060 group_id_attr,
11061 sizeof(group_id_attr))) {
11062 sigma_dut_print(dut, DUT_MSG_ERROR,
11063 "fail to replace group id attribute");
11064 return -1;
11065 }
11066 }
11067
11068 for (i = 0; i < count; i++) {
11069 if (wil6210_transmit_frame(dut, freq,
11070 WIL_TRANSMIT_FRAME_DEFAULT_ROC,
11071 frame, framelen)) {
11072 sigma_dut_print(dut, DUT_MSG_ERROR,
11073 "fail to transmit probe request frame");
11074 return -1;
11075 }
11076 }
11077
11078 return 0;
11079}
11080
11081
Lior David0fe101e2017-03-09 16:09:50 +020011082int wil6210_send_frame_60g(struct sigma_dut *dut, struct sigma_conn *conn,
11083 struct sigma_cmd *cmd)
11084{
11085 const char *frame_name = get_param(cmd, "framename");
11086 const char *mac = get_param(cmd, "dest_mac");
11087
11088 if (!frame_name || !mac) {
11089 sigma_dut_print(dut, DUT_MSG_ERROR,
11090 "framename and dest_mac must be provided");
11091 return -1;
11092 }
11093
11094 if (strcasecmp(frame_name, "brp") == 0) {
11095 const char *l_rx = get_param(cmd, "L-RX");
11096 int l_rx_i;
11097
11098 if (!l_rx) {
11099 sigma_dut_print(dut, DUT_MSG_ERROR,
11100 "L-RX must be provided");
11101 return -1;
11102 }
11103 l_rx_i = atoi(l_rx);
11104
11105 sigma_dut_print(dut, DUT_MSG_INFO,
11106 "dev_send_frame: BRP-RX, dest_mac %s, L-RX %s",
11107 mac, l_rx);
11108 if (l_rx_i != 16) {
11109 sigma_dut_print(dut, DUT_MSG_ERROR,
11110 "unsupported L-RX: %s", l_rx);
11111 return -1;
11112 }
11113
11114 if (wil6210_send_brp_rx(dut, mac, l_rx_i))
11115 return -1;
11116 } else if (strcasecmp(frame_name, "ssw") == 0) {
11117 sigma_dut_print(dut, DUT_MSG_INFO,
11118 "dev_send_frame: SLS, dest_mac %s", mac);
11119 if (wil6210_send_sls(dut, mac))
11120 return -1;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030011121 } else if ((strcasecmp(frame_name, "probereq") == 0) ||
11122 (strcasecmp(frame_name, "devdiscreq") == 0)) {
11123 sigma_dut_print(dut, DUT_MSG_INFO,
11124 "dev_send_frame: %s, dest_mac %s", frame_name,
11125 mac);
11126 if (wil6210_send_p2p_frame_60g(dut, cmd, frame_name, mac))
11127 return -1;
Lior David0fe101e2017-03-09 16:09:50 +020011128 } else {
11129 sigma_dut_print(dut, DUT_MSG_ERROR,
11130 "unsupported frame type: %s", frame_name);
11131 return -1;
11132 }
11133
11134 return 1;
11135}
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030011136
Lior David0fe101e2017-03-09 16:09:50 +020011137#endif /* __linux__ */
11138
11139
11140static int cmd_sta_send_frame_60g(struct sigma_dut *dut,
11141 struct sigma_conn *conn,
11142 struct sigma_cmd *cmd)
11143{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011144 switch (get_driver_type(dut)) {
Lior David0fe101e2017-03-09 16:09:50 +020011145#ifdef __linux__
11146 case DRIVER_WIL6210:
11147 return wil6210_send_frame_60g(dut, conn, cmd);
11148#endif /* __linux__ */
11149 default:
11150 send_resp(dut, conn, SIGMA_ERROR,
11151 "errorCode,Unsupported sta_set_frame(60G) with the current driver");
11152 return 0;
11153 }
11154}
11155
11156
Ashwini Patildb59b3c2017-04-13 15:19:23 +053011157static int mbo_send_anqp_query(struct sigma_dut *dut, struct sigma_conn *conn,
11158 const char *intf, struct sigma_cmd *cmd)
11159{
11160 const char *val, *addr;
11161 char buf[100];
11162
11163 addr = get_param(cmd, "DestMac");
11164 if (!addr) {
11165 send_resp(dut, conn, SIGMA_INVALID,
11166 "ErrorCode,AP MAC address is missing");
11167 return 0;
11168 }
11169
11170 val = get_param(cmd, "ANQPQuery_ID");
11171 if (!val) {
11172 send_resp(dut, conn, SIGMA_INVALID,
11173 "ErrorCode,Missing ANQPQuery_ID");
11174 return 0;
11175 }
11176
11177 if (strcasecmp(val, "NeighborReportReq") == 0) {
11178 snprintf(buf, sizeof(buf), "ANQP_GET %s 272", addr);
11179 } else if (strcasecmp(val, "QueryListWithCellPref") == 0) {
11180 snprintf(buf, sizeof(buf), "ANQP_GET %s 272,mbo:2", addr);
11181 } else {
11182 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid ANQPQuery_ID: %s",
11183 val);
11184 send_resp(dut, conn, SIGMA_INVALID,
11185 "ErrorCode,Invalid ANQPQuery_ID");
11186 return 0;
11187 }
11188
Ashwini Patild174f2c2017-04-13 16:49:46 +053011189 /* Set gas_address3 field to IEEE 802.11-2012 standard compliant form
11190 * (Address3 = Wildcard BSSID when sent to not-associated AP;
11191 * if associated, AP BSSID).
11192 */
11193 if (wpa_command(intf, "SET gas_address3 1") < 0) {
11194 send_resp(dut, conn, SIGMA_ERROR,
11195 "ErrorCode,Failed to set gas_address3");
11196 return 0;
11197 }
11198
Ashwini Patildb59b3c2017-04-13 15:19:23 +053011199 if (wpa_command(intf, buf) < 0) {
11200 send_resp(dut, conn, SIGMA_ERROR,
11201 "ErrorCode,Failed to send ANQP query");
11202 return 0;
11203 }
11204
11205 return 1;
11206}
11207
11208
11209static int mbo_cmd_sta_send_frame(struct sigma_dut *dut,
11210 struct sigma_conn *conn,
11211 const char *intf,
11212 struct sigma_cmd *cmd)
11213{
11214 const char *val = get_param(cmd, "FrameName");
11215
11216 if (val && strcasecmp(val, "ANQPQuery") == 0)
11217 return mbo_send_anqp_query(dut, conn, intf, cmd);
11218
11219 return 2;
11220}
11221
11222
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053011223static enum sigma_cmd_result cmd_sta_send_frame_wpa3(struct sigma_dut *dut,
11224 struct sigma_conn *conn,
11225 const char *intf,
11226 struct sigma_cmd *cmd)
11227{
11228 const char *val = get_param(cmd, "framename");
11229
11230 if (!val)
11231 return INVALID_SEND_STATUS;
11232
11233 if (strcasecmp(val, "SAQueryReq") == 0) {
11234 val = get_param(cmd, "OCIChannel");
11235
11236 if (!val) {
11237 send_resp(dut, conn, SIGMA_ERROR,
11238 "errorCode,OCIChannel not present");
11239 return STATUS_SENT_ERROR;
11240 }
11241
11242 dut->saquery_oci_freq = channel_to_freq(dut, atoi(val));
11243 if (!dut->saquery_oci_freq) {
11244 send_resp(dut, conn, SIGMA_ERROR,
11245 "errorCode,Invalid OCIChannel number");
11246 return STATUS_SENT_ERROR;
11247 }
11248
11249 return sta_inject_frame(dut, conn, intf, SAQUERY, CORRECT_KEY,
11250 NULL, 0);
11251 }
11252
11253 if (strcasecmp(val, "reassocreq") == 0)
11254 return sta_inject_frame(dut, conn, intf, REASSOCREQ,
11255 CORRECT_KEY, NULL, 0);
11256
11257 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported framename");
11258 return STATUS_SENT_ERROR;
11259}
11260
11261
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053011262static enum sigma_cmd_result
11263cmd_sta_send_frame_mscs(struct sigma_dut *dut, struct sigma_conn *conn,
11264 const char *intf, struct sigma_cmd *cmd)
11265{
11266 char buf[128], *pos;
11267 const char *val, *classifier_type = "04", *type;
11268 int len, rem_len;
11269 u8 up_bitmap;
11270
11271 val = get_param(cmd, "FrameName");
11272 type = get_param(cmd, "Request_Type");
11273 if (!val || !type || strcasecmp(val, "MSCSReq") != 0) {
11274 sigma_dut_print(dut, DUT_MSG_ERROR,
11275 "%s: frame name or type not valid", __func__);
11276 return INVALID_SEND_STATUS;
11277 }
11278
11279 rem_len = sizeof(buf);
11280 pos = buf;
11281 if (strcasecmp(type, "add") == 0) {
11282 len = snprintf(pos, rem_len, "MSCS add");
11283 } else if (strcasecmp(type, "update") == 0) {
11284 len = snprintf(pos, rem_len, "MSCS change");
11285 } else if (strcasecmp(type, "remove") == 0) {
11286 if (wpa_command(intf, "MSCS remove") != 0) {
11287 send_resp(dut, conn, SIGMA_ERROR,
11288 "ErrorCode,Failed to send MSCS frame req");
11289 return STATUS_SENT_ERROR;
11290 }
11291 return SUCCESS_SEND_STATUS;
11292 } else {
11293 sigma_dut_print(dut, DUT_MSG_ERROR,
11294 "%s: request type invalid", __func__);
11295 return INVALID_SEND_STATUS;
11296 }
11297
11298 if (len < 0 || len >= rem_len)
11299 goto fail;
11300
11301 pos += len;
11302 rem_len -= len;
11303
11304 val = get_param(cmd, "User_Priority_Bitmap");
11305 if (!val) {
11306 sigma_dut_print(dut, DUT_MSG_ERROR,
11307 "%s: user priority bitmap empty", __func__);
11308 return INVALID_SEND_STATUS;
11309 }
11310
11311 switch (atoi(val)) {
11312 case 0:
11313 up_bitmap = 0x00;
11314 break;
11315 case 1:
11316 up_bitmap = 0xF0;
11317 break;
11318 case 2:
11319 up_bitmap = 0xF6;
11320 break;
11321 default:
11322 sigma_dut_print(dut, DUT_MSG_ERROR,
11323 "%s: Unknown User_Priority_Bitmap value %d",
11324 __func__, atoi(val));
11325 return INVALID_SEND_STATUS;
11326 }
11327
11328 len = snprintf(pos, rem_len, " up_bitmap=%02x", up_bitmap);
11329 if (len < 0 || len >= rem_len)
11330 goto fail;
11331
11332 pos += len;
11333 rem_len -= len;
11334
11335 val = get_param(cmd, "User_Priority_Limit");
11336 if (!val) {
11337 sigma_dut_print(dut, DUT_MSG_ERROR,
11338 "%s: invalid user priority limit", __func__);
11339 return INVALID_SEND_STATUS;
11340 }
11341
11342 len = snprintf(pos, rem_len, " up_limit=%s", val);
11343 if (len < 0 || len >= rem_len)
11344 goto fail;
11345
11346 pos += len;
11347 rem_len -= len;
11348
11349 val = get_param(cmd, "Stream_Timeout");
11350 if (!val)
11351 val = get_param(cmd, "Stream_Timtout");
11352 if (!val) {
11353 sigma_dut_print(dut, DUT_MSG_ERROR,
11354 "%s: invalid stream timeout", __func__);
11355 return INVALID_SEND_STATUS;
11356 }
11357
11358 len = snprintf(pos, rem_len, " stream_timeout=%s", val);
11359 if (len < 0 || len >= rem_len)
11360 goto fail;
11361
11362 pos += len;
11363 rem_len -= len;
11364
11365 val = get_param(cmd, "TCLAS_Mask");
11366 if (!val) {
11367 sigma_dut_print(dut, DUT_MSG_ERROR,
11368 "%s: invalid tclas mask", __func__);
11369 return INVALID_SEND_STATUS;
11370 }
11371
11372 len = snprintf(pos, rem_len, " frame_classifier=%s%lx%032x",
11373 classifier_type, strtol(val, NULL, 2), 0);
11374 if (len < 0 || len >= rem_len)
11375 goto fail;
11376
11377 if (wpa_command(intf, buf) != 0) {
11378 send_resp(dut, conn, SIGMA_ERROR,
11379 "ErrorCode,Failed to send MSCS frame req");
11380 return STATUS_SENT_ERROR;
11381 }
11382
11383 sigma_dut_print(dut, DUT_MSG_DEBUG,
11384 "MSCS frame request sent: %s", buf);
11385
11386 return SUCCESS_SEND_STATUS;
11387fail:
11388 sigma_dut_print(dut, DUT_MSG_ERROR,
11389 "Failed to create MSCS frame req");
11390 return ERROR_SEND_STATUS;
11391}
11392
11393
Jouni Malinenf7222712019-06-13 01:50:21 +030011394enum sigma_cmd_result cmd_sta_send_frame(struct sigma_dut *dut,
11395 struct sigma_conn *conn,
11396 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011397{
11398 const char *intf = get_param(cmd, "Interface");
11399 const char *val;
11400 enum send_frame_type frame;
11401 enum send_frame_protection protected;
11402 char buf[100];
11403 unsigned char addr[ETH_ALEN];
11404 int res;
11405
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030011406 if (!intf)
11407 return -1;
11408
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011409 val = get_param(cmd, "program");
11410 if (val == NULL)
11411 val = get_param(cmd, "frame");
11412 if (val && strcasecmp(val, "TDLS") == 0)
11413 return cmd_sta_send_frame_tdls(dut, conn, cmd);
11414 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030011415 strcasecmp(val, "HS2-R2") == 0 ||
11416 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011417 return cmd_sta_send_frame_hs2(dut, conn, cmd);
11418 if (val && strcasecmp(val, "VHT") == 0)
11419 return cmd_sta_send_frame_vht(dut, conn, cmd);
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011420 if (val && strcasecmp(val, "HE") == 0)
11421 return cmd_sta_send_frame_he(dut, conn, cmd);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -070011422 if (val && strcasecmp(val, "LOC") == 0)
11423 return loc_cmd_sta_send_frame(dut, conn, cmd);
Lior David0fe101e2017-03-09 16:09:50 +020011424 if (val && strcasecmp(val, "60GHz") == 0)
11425 return cmd_sta_send_frame_60g(dut, conn, cmd);
Ashwini Patildb59b3c2017-04-13 15:19:23 +053011426 if (val && strcasecmp(val, "MBO") == 0) {
11427 res = mbo_cmd_sta_send_frame(dut, conn, intf, cmd);
11428 if (res != 2)
11429 return res;
11430 }
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053011431 if (val && strcasecmp(val, "WPA3") == 0)
11432 return cmd_sta_send_frame_wpa3(dut, conn, intf, cmd);
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053011433 if (val && strcasecmp(val, "QM") == 0)
11434 return cmd_sta_send_frame_mscs(dut, conn, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011435
11436 val = get_param(cmd, "TD_DISC");
11437 if (val) {
11438 if (hwaddr_aton(val, addr) < 0)
11439 return -1;
11440 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", val);
11441 if (wpa_command(intf, buf) < 0) {
11442 send_resp(dut, conn, SIGMA_ERROR,
11443 "ErrorCode,Failed to send TDLS discovery");
11444 return 0;
11445 }
11446 return 1;
11447 }
11448
11449 val = get_param(cmd, "TD_Setup");
11450 if (val) {
11451 if (hwaddr_aton(val, addr) < 0)
11452 return -1;
11453 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", val);
11454 if (wpa_command(intf, buf) < 0) {
11455 send_resp(dut, conn, SIGMA_ERROR,
11456 "ErrorCode,Failed to start TDLS setup");
11457 return 0;
11458 }
11459 return 1;
11460 }
11461
11462 val = get_param(cmd, "TD_TearDown");
11463 if (val) {
11464 if (hwaddr_aton(val, addr) < 0)
11465 return -1;
11466 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", val);
11467 if (wpa_command(intf, buf) < 0) {
11468 send_resp(dut, conn, SIGMA_ERROR,
11469 "ErrorCode,Failed to tear down TDLS link");
11470 return 0;
11471 }
11472 return 1;
11473 }
11474
11475 val = get_param(cmd, "TD_ChannelSwitch");
11476 if (val) {
11477 /* TODO */
11478 send_resp(dut, conn, SIGMA_ERROR,
11479 "ErrorCode,TD_ChannelSwitch not yet supported");
11480 return 0;
11481 }
11482
11483 val = get_param(cmd, "TD_NF");
11484 if (val) {
11485 /* TODO */
11486 send_resp(dut, conn, SIGMA_ERROR,
11487 "ErrorCode,TD_NF not yet supported");
11488 return 0;
11489 }
11490
11491 val = get_param(cmd, "PMFFrameType");
11492 if (val == NULL)
11493 val = get_param(cmd, "FrameName");
11494 if (val == NULL)
11495 val = get_param(cmd, "Type");
11496 if (val == NULL)
11497 return -1;
11498 if (strcasecmp(val, "disassoc") == 0)
11499 frame = DISASSOC;
11500 else if (strcasecmp(val, "deauth") == 0)
11501 frame = DEAUTH;
11502 else if (strcasecmp(val, "saquery") == 0)
11503 frame = SAQUERY;
11504 else if (strcasecmp(val, "auth") == 0)
11505 frame = AUTH;
11506 else if (strcasecmp(val, "assocreq") == 0)
11507 frame = ASSOCREQ;
11508 else if (strcasecmp(val, "reassocreq") == 0)
11509 frame = REASSOCREQ;
11510 else if (strcasecmp(val, "neigreq") == 0) {
11511 sigma_dut_print(dut, DUT_MSG_INFO, "Got neighbor request");
11512
11513 val = get_param(cmd, "ssid");
11514 if (val == NULL)
11515 return -1;
11516
11517 res = send_neighbor_request(dut, intf, val);
11518 if (res) {
11519 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
11520 "Failed to send neighbor report request");
11521 return 0;
11522 }
11523
11524 return 1;
Ashwini Patil5acd7382017-04-13 15:55:04 +053011525 } else if (strcasecmp(val, "transmgmtquery") == 0 ||
11526 strcasecmp(val, "BTMQuery") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011527 sigma_dut_print(dut, DUT_MSG_DEBUG,
11528 "Got Transition Management Query");
11529
Ashwini Patil5acd7382017-04-13 15:55:04 +053011530 res = send_trans_mgmt_query(dut, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011531 if (res) {
11532 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
11533 "Failed to send Transition Management Query");
11534 return 0;
11535 }
11536
11537 return 1;
11538 } else {
11539 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
11540 "PMFFrameType");
11541 return 0;
11542 }
11543
11544 val = get_param(cmd, "PMFProtected");
11545 if (val == NULL)
11546 val = get_param(cmd, "Protected");
11547 if (val == NULL)
11548 return -1;
11549 if (strcasecmp(val, "Correct-key") == 0 ||
11550 strcasecmp(val, "CorrectKey") == 0)
11551 protected = CORRECT_KEY;
11552 else if (strcasecmp(val, "IncorrectKey") == 0)
11553 protected = INCORRECT_KEY;
11554 else if (strcasecmp(val, "Unprotected") == 0)
11555 protected = UNPROTECTED;
11556 else {
11557 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
11558 "PMFProtected");
11559 return 0;
11560 }
11561
11562 if (protected != UNPROTECTED &&
11563 (frame == AUTH || frame == ASSOCREQ || frame == REASSOCREQ)) {
11564 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Impossible "
11565 "PMFProtected for auth/assocreq/reassocreq");
11566 return 0;
11567 }
11568
11569 if (if_nametoindex("sigmadut") == 0) {
11570 snprintf(buf, sizeof(buf),
11571 "iw dev %s interface add sigmadut type monitor",
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011572 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011573 if (system(buf) != 0 ||
11574 if_nametoindex("sigmadut") == 0) {
11575 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
11576 "monitor interface with '%s'", buf);
11577 return -2;
11578 }
11579 }
11580
11581 if (system("ifconfig sigmadut up") != 0) {
11582 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
11583 "monitor interface up");
11584 return -2;
11585 }
11586
Veerendranath Jakkam49774122020-07-05 09:52:18 +053011587 return sta_inject_frame(dut, conn, intf, frame, protected, NULL, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011588}
11589
11590
11591static int cmd_sta_set_parameter_hs2(struct sigma_dut *dut,
11592 struct sigma_conn *conn,
11593 struct sigma_cmd *cmd,
11594 const char *ifname)
11595{
11596 char buf[200];
11597 const char *val;
11598
11599 val = get_param(cmd, "ClearARP");
11600 if (val && atoi(val) == 1) {
11601 snprintf(buf, sizeof(buf), "ip neigh flush dev %s", ifname);
11602 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11603 if (system(buf) != 0) {
11604 send_resp(dut, conn, SIGMA_ERROR,
11605 "errorCode,Failed to clear ARP cache");
11606 return 0;
11607 }
11608 }
11609
11610 return 1;
11611}
11612
11613
11614int cmd_sta_set_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
11615 struct sigma_cmd *cmd)
11616{
11617 const char *intf = get_param(cmd, "Interface");
11618 const char *val;
11619
11620 if (intf == NULL)
11621 return -1;
11622
11623 val = get_param(cmd, "program");
11624 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030011625 strcasecmp(val, "HS2-R2") == 0 ||
11626 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011627 return cmd_sta_set_parameter_hs2(dut, conn, cmd, intf);
11628
11629 return -1;
11630}
11631
11632
Jouni Malinenf7222712019-06-13 01:50:21 +030011633static enum sigma_cmd_result cmd_sta_set_macaddr(struct sigma_dut *dut,
11634 struct sigma_conn *conn,
11635 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011636{
11637 const char *intf = get_param(cmd, "Interface");
11638 const char *mac = get_param(cmd, "MAC");
11639
11640 if (intf == NULL || mac == NULL)
11641 return -1;
11642
11643 sigma_dut_print(dut, DUT_MSG_INFO, "Change local MAC address for "
11644 "interface %s to %s", intf, mac);
11645
11646 if (dut->set_macaddr) {
11647 char buf[128];
11648 int res;
11649 if (strcasecmp(mac, "default") == 0) {
11650 res = snprintf(buf, sizeof(buf), "%s",
11651 dut->set_macaddr);
11652 dut->tmp_mac_addr = 0;
11653 } else {
11654 res = snprintf(buf, sizeof(buf), "%s %s",
11655 dut->set_macaddr, mac);
11656 dut->tmp_mac_addr = 1;
11657 }
11658 if (res < 0 || res >= (int) sizeof(buf))
11659 return -1;
11660 if (system(buf) != 0) {
11661 send_resp(dut, conn, SIGMA_ERROR,
11662 "errorCode,Failed to set MAC "
11663 "address");
11664 return 0;
11665 }
11666 return 1;
11667 }
11668
11669 if (strcasecmp(mac, "default") == 0)
11670 return 1;
11671
11672 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
11673 "command");
11674 return 0;
11675}
11676
11677
11678static int iwpriv_tdlsoffchnmode(struct sigma_dut *dut,
11679 struct sigma_conn *conn, const char *intf,
11680 int val)
11681{
11682 char buf[200];
11683 int res;
11684
11685 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchnmode %d",
11686 intf, val);
11687 if (res < 0 || res >= (int) sizeof(buf))
11688 return -1;
11689 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11690 if (system(buf) != 0) {
11691 send_resp(dut, conn, SIGMA_ERROR,
11692 "errorCode,Failed to configure offchannel mode");
11693 return 0;
11694 }
11695
11696 return 1;
11697}
11698
11699
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011700static int off_chan_val(enum sec_ch_offset off)
11701{
11702 switch (off) {
11703 case SEC_CH_NO:
11704 return 0;
11705 case SEC_CH_40ABOVE:
11706 return 40;
11707 case SEC_CH_40BELOW:
11708 return -40;
11709 }
11710
11711 return 0;
11712}
11713
11714
11715static int iwpriv_set_offchan(struct sigma_dut *dut, struct sigma_conn *conn,
11716 const char *intf, int off_ch_num,
11717 enum sec_ch_offset sec)
11718{
11719 char buf[200];
11720 int res;
11721
11722 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchan %d",
11723 intf, off_ch_num);
11724 if (res < 0 || res >= (int) sizeof(buf))
11725 return -1;
11726 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11727 if (system(buf) != 0) {
11728 send_resp(dut, conn, SIGMA_ERROR,
11729 "errorCode,Failed to set offchan");
11730 return 0;
11731 }
11732
11733 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsecchnoffst %d",
11734 intf, off_chan_val(sec));
11735 if (res < 0 || res >= (int) sizeof(buf))
11736 return -1;
11737 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11738 if (system(buf) != 0) {
11739 send_resp(dut, conn, SIGMA_ERROR,
11740 "errorCode,Failed to set sec chan offset");
11741 return 0;
11742 }
11743
11744 return 1;
11745}
11746
11747
11748static int tdls_set_offchannel_offset(struct sigma_dut *dut,
11749 struct sigma_conn *conn,
11750 const char *intf, int off_ch_num,
11751 enum sec_ch_offset sec)
11752{
11753 char buf[200];
11754 int res;
11755
11756 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNEL %d",
11757 off_ch_num);
11758 if (res < 0 || res >= (int) sizeof(buf))
11759 return -1;
11760 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11761
11762 if (wpa_command(intf, buf) < 0) {
11763 send_resp(dut, conn, SIGMA_ERROR,
11764 "ErrorCode,Failed to set offchan");
11765 return 0;
11766 }
11767 res = snprintf(buf, sizeof(buf), "DRIVER TDLSSECONDARYCHANNELOFFSET %d",
11768 off_chan_val(sec));
11769 if (res < 0 || res >= (int) sizeof(buf))
11770 return -1;
11771
11772 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11773
11774 if (wpa_command(intf, buf) < 0) {
11775 send_resp(dut, conn, SIGMA_ERROR,
11776 "ErrorCode,Failed to set sec chan offset");
11777 return 0;
11778 }
11779
11780 return 1;
11781}
11782
11783
11784static int tdls_set_offchannel_mode(struct sigma_dut *dut,
11785 struct sigma_conn *conn,
11786 const char *intf, int val)
11787{
11788 char buf[200];
11789 int res;
11790
11791 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNELMODE %d",
11792 val);
11793 if (res < 0 || res >= (int) sizeof(buf))
11794 return -1;
11795 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11796
11797 if (wpa_command(intf, buf) < 0) {
11798 send_resp(dut, conn, SIGMA_ERROR,
11799 "ErrorCode,Failed to configure offchannel mode");
11800 return 0;
11801 }
11802
11803 return 1;
11804}
11805
11806
11807static int cmd_sta_set_rfeature_tdls(const char *intf, struct sigma_dut *dut,
11808 struct sigma_conn *conn,
11809 struct sigma_cmd *cmd)
11810{
11811 const char *val;
11812 enum {
11813 CHSM_NOT_SET,
11814 CHSM_ENABLE,
11815 CHSM_DISABLE,
11816 CHSM_REJREQ,
11817 CHSM_UNSOLRESP
11818 } chsm = CHSM_NOT_SET;
11819 int off_ch_num = -1;
11820 enum sec_ch_offset sec_ch = SEC_CH_NO;
11821 int res;
11822
11823 val = get_param(cmd, "Uapsd");
11824 if (val) {
11825 char buf[100];
11826 if (strcasecmp(val, "Enable") == 0)
11827 snprintf(buf, sizeof(buf), "SET ps 99");
11828 else if (strcasecmp(val, "Disable") == 0)
11829 snprintf(buf, sizeof(buf), "SET ps 98");
11830 else {
11831 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
11832 "Unsupported uapsd parameter value");
11833 return 0;
11834 }
11835 if (wpa_command(intf, buf)) {
11836 send_resp(dut, conn, SIGMA_ERROR,
11837 "ErrorCode,Failed to change U-APSD "
11838 "powersave mode");
11839 return 0;
11840 }
11841 }
11842
11843 val = get_param(cmd, "TPKTIMER");
11844 if (val && strcasecmp(val, "DISABLE") == 0) {
11845 if (wpa_command(intf, "SET tdls_testing 0x100")) {
11846 send_resp(dut, conn, SIGMA_ERROR,
11847 "ErrorCode,Failed to enable no TPK "
11848 "expiration test mode");
11849 return 0;
11850 }
11851 dut->no_tpk_expiration = 1;
11852 }
11853
11854 val = get_param(cmd, "ChSwitchMode");
11855 if (val) {
11856 if (strcasecmp(val, "Enable") == 0 ||
11857 strcasecmp(val, "Initiate") == 0)
11858 chsm = CHSM_ENABLE;
11859 else if (strcasecmp(val, "Disable") == 0 ||
11860 strcasecmp(val, "passive") == 0)
11861 chsm = CHSM_DISABLE;
11862 else if (strcasecmp(val, "RejReq") == 0)
11863 chsm = CHSM_REJREQ;
11864 else if (strcasecmp(val, "UnSolResp") == 0)
11865 chsm = CHSM_UNSOLRESP;
11866 else {
11867 send_resp(dut, conn, SIGMA_ERROR,
11868 "ErrorCode,Unknown ChSwitchMode value");
11869 return 0;
11870 }
11871 }
11872
11873 val = get_param(cmd, "OffChNum");
11874 if (val) {
11875 off_ch_num = atoi(val);
11876 if (off_ch_num == 0) {
11877 send_resp(dut, conn, SIGMA_ERROR,
11878 "ErrorCode,Invalid OffChNum");
11879 return 0;
11880 }
11881 }
11882
11883 val = get_param(cmd, "SecChOffset");
11884 if (val) {
11885 if (strcmp(val, "20") == 0)
11886 sec_ch = SEC_CH_NO;
11887 else if (strcasecmp(val, "40above") == 0)
11888 sec_ch = SEC_CH_40ABOVE;
11889 else if (strcasecmp(val, "40below") == 0)
11890 sec_ch = SEC_CH_40BELOW;
11891 else {
11892 send_resp(dut, conn, SIGMA_ERROR,
11893 "ErrorCode,Unknown SecChOffset value");
11894 return 0;
11895 }
11896 }
11897
11898 if (chsm == CHSM_NOT_SET) {
11899 /* no offchannel changes requested */
11900 return 1;
11901 }
11902
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011903 if (strcmp(intf, get_main_ifname(dut)) != 0 &&
11904 strcmp(intf, get_station_ifname(dut)) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011905 send_resp(dut, conn, SIGMA_ERROR,
11906 "ErrorCode,Unknown interface");
11907 return 0;
11908 }
11909
11910 switch (chsm) {
11911 case CHSM_NOT_SET:
Jouni Malinen280f5ba2016-08-29 21:33:10 +030011912 res = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011913 break;
11914 case CHSM_ENABLE:
11915 if (off_ch_num < 0) {
11916 send_resp(dut, conn, SIGMA_ERROR,
11917 "ErrorCode,Missing OffChNum argument");
11918 return 0;
11919 }
11920 if (wifi_chip_type == DRIVER_WCN) {
11921 res = tdls_set_offchannel_offset(dut, conn, intf,
11922 off_ch_num, sec_ch);
11923 } else {
11924 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
11925 sec_ch);
11926 }
11927 if (res != 1)
11928 return res;
11929 if (wifi_chip_type == DRIVER_WCN)
11930 res = tdls_set_offchannel_mode(dut, conn, intf, 1);
11931 else
11932 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 1);
11933 break;
11934 case CHSM_DISABLE:
11935 if (wifi_chip_type == DRIVER_WCN)
11936 res = tdls_set_offchannel_mode(dut, conn, intf, 2);
11937 else
11938 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 2);
11939 break;
11940 case CHSM_REJREQ:
11941 if (wifi_chip_type == DRIVER_WCN)
11942 res = tdls_set_offchannel_mode(dut, conn, intf, 3);
11943 else
11944 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 3);
11945 break;
11946 case CHSM_UNSOLRESP:
11947 if (off_ch_num < 0) {
11948 send_resp(dut, conn, SIGMA_ERROR,
11949 "ErrorCode,Missing OffChNum argument");
11950 return 0;
11951 }
11952 if (wifi_chip_type == DRIVER_WCN) {
11953 res = tdls_set_offchannel_offset(dut, conn, intf,
11954 off_ch_num, sec_ch);
11955 } else {
11956 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
11957 sec_ch);
11958 }
11959 if (res != 1)
11960 return res;
11961 if (wifi_chip_type == DRIVER_WCN)
11962 res = tdls_set_offchannel_mode(dut, conn, intf, 4);
11963 else
11964 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 4);
11965 break;
11966 }
11967
11968 return res;
11969}
11970
11971
11972static int ath_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
11973 struct sigma_conn *conn,
11974 struct sigma_cmd *cmd)
11975{
11976 const char *val;
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053011977 char *token = NULL, *result;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011978
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -070011979 novap_reset(dut, intf, 1);
priyadharshini gowthamane5e25172015-12-08 14:53:48 -080011980
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011981 val = get_param(cmd, "nss_mcs_opt");
11982 if (val) {
11983 /* String (nss_operating_mode; mcs_operating_mode) */
11984 int nss, mcs;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011985 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011986
11987 token = strdup(val);
11988 if (!token)
11989 return 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011990 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053011991 if (!result) {
11992 sigma_dut_print(dut, DUT_MSG_ERROR,
11993 "VHT NSS not specified");
11994 goto failed;
11995 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011996 if (strcasecmp(result, "def") != 0) {
11997 nss = atoi(result);
11998 if (nss == 4)
11999 ath_disable_txbf(dut, intf);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012000 if (run_iwpriv(dut, intf, "nss %d", nss) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012001 goto failed;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012002
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012003 }
12004
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053012005 result = strtok_r(NULL, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053012006 if (!result) {
12007 sigma_dut_print(dut, DUT_MSG_ERROR,
12008 "VHT MCS not specified");
12009 goto failed;
12010 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012011 if (strcasecmp(result, "def") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012012 if (run_iwpriv(dut, intf, "set11NRates 0") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012013 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012014 } else {
12015 mcs = atoi(result);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012016 if (run_iwpriv(dut, intf, "vhtmcs %d", mcs) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012017 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012018 }
12019 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012020 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012021 }
12022
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053012023 free(token);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012024 return 1;
12025failed:
12026 free(token);
12027 return 0;
12028}
12029
12030
12031static int cmd_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
12032 struct sigma_conn *conn,
12033 struct sigma_cmd *cmd)
12034{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012035 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012036 case DRIVER_ATHEROS:
12037 return ath_sta_set_rfeature_vht(intf, dut, conn, cmd);
12038 default:
12039 send_resp(dut, conn, SIGMA_ERROR,
12040 "errorCode,Unsupported sta_set_rfeature(VHT) with the current driver");
12041 return 0;
12042 }
12043}
12044
12045
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012046static int wcn_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
12047 struct sigma_conn *conn,
12048 struct sigma_cmd *cmd)
12049{
12050 const char *val;
12051 char *token = NULL, *result;
12052 char buf[60];
12053
12054 val = get_param(cmd, "nss_mcs_opt");
12055 if (val) {
12056 /* String (nss_operating_mode; mcs_operating_mode) */
12057 int nss, mcs, ratecode;
12058 char *saveptr;
12059
12060 token = strdup(val);
12061 if (!token)
12062 return -2;
12063
12064 result = strtok_r(token, ";", &saveptr);
12065 if (!result) {
12066 sigma_dut_print(dut, DUT_MSG_ERROR,
12067 "HE NSS not specified");
12068 goto failed;
12069 }
12070 nss = 1;
12071 if (strcasecmp(result, "def") != 0)
12072 nss = atoi(result);
12073
12074 result = strtok_r(NULL, ";", &saveptr);
12075 if (!result) {
12076 sigma_dut_print(dut, DUT_MSG_ERROR,
12077 "HE MCS not specified");
12078 goto failed;
12079 }
12080 mcs = 7;
12081 if (strcasecmp(result, "def") != 0)
12082 mcs = atoi(result);
12083
Arif Hussain557bf412018-05-25 17:29:36 -070012084 ratecode = 0x20; /* for nss:1 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012085 if (nss == 2) {
Arif Hussain557bf412018-05-25 17:29:36 -070012086 ratecode = 0x40; /* for nss:2 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012087 } else if (nss > 2) {
12088 sigma_dut_print(dut, DUT_MSG_ERROR,
12089 "HE NSS %d not supported", nss);
12090 goto failed;
12091 }
12092
Arif Hussain557bf412018-05-25 17:29:36 -070012093 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss);
12094 if (system(buf) != 0) {
12095 sigma_dut_print(dut, DUT_MSG_ERROR,
12096 "nss_mcs_opt: iwpriv %s nss %d failed",
12097 intf, nss);
12098 goto failed;
12099 }
Arif Hussainac6c5112018-05-25 17:34:00 -070012100 dut->sta_nss = nss;
Arif Hussain557bf412018-05-25 17:29:36 -070012101
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012102 /* Add the MCS to the ratecode */
12103 if (mcs >= 0 && mcs <= 11) {
12104 ratecode += mcs;
Arif Hussain557bf412018-05-25 17:29:36 -070012105#ifdef NL80211_SUPPORT
12106 if (dut->device_type == STA_testbed) {
12107 enum he_mcs_config mcs_config;
12108 int ret;
12109
12110 if (mcs <= 7)
12111 mcs_config = HE_80_MCS0_7;
12112 else if (mcs <= 9)
12113 mcs_config = HE_80_MCS0_9;
12114 else
12115 mcs_config = HE_80_MCS0_11;
12116 ret = sta_set_he_mcs(dut, intf, mcs_config);
12117 if (ret) {
12118 sigma_dut_print(dut, DUT_MSG_ERROR,
12119 "nss_mcs_opt: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
12120 mcs, mcs_config, ret);
12121 goto failed;
12122 }
12123 }
12124#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012125 } else {
12126 sigma_dut_print(dut, DUT_MSG_ERROR,
12127 "HE MCS %d not supported", mcs);
12128 goto failed;
12129 }
12130 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0x%03x",
12131 intf, ratecode);
12132 if (system(buf) != 0) {
12133 sigma_dut_print(dut, DUT_MSG_ERROR,
12134 "iwpriv setting of 11ax rates failed");
12135 goto failed;
12136 }
12137 free(token);
12138 }
12139
12140 val = get_param(cmd, "GI");
12141 if (val) {
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080012142 int fix_rate_sgi;
12143
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012144 if (strcmp(val, "0.8") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070012145 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 9", intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080012146 fix_rate_sgi = 1;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012147 } else if (strcmp(val, "1.6") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070012148 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 10",
12149 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080012150 fix_rate_sgi = 2;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012151 } else if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070012152 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 11",
12153 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080012154 fix_rate_sgi = 3;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012155 } else {
12156 send_resp(dut, conn, SIGMA_ERROR,
12157 "errorCode,GI value not supported");
12158 return 0;
12159 }
12160 if (system(buf) != 0) {
12161 send_resp(dut, conn, SIGMA_ERROR,
12162 "errorCode,Failed to set shortgi");
12163 return 0;
12164 }
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080012165 snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d",
12166 intf, fix_rate_sgi);
12167 if (system(buf) != 0) {
12168 send_resp(dut, conn, SIGMA_ERROR,
12169 "errorCode,Failed to set fix rate shortgi");
12170 return STATUS_SENT;
12171 }
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012172 }
12173
Subhani Shaik8e7a3052018-04-24 14:03:00 -070012174 val = get_param(cmd, "LTF");
12175 if (val) {
12176#ifdef NL80211_SUPPORT
12177 if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080012178 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_1X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070012179 } if (strcmp(val, "6.4") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080012180 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_2X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070012181 } else if (strcmp(val, "12.8") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080012182 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_4X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070012183 } else {
12184 send_resp(dut, conn, SIGMA_ERROR,
12185 "errorCode, LTF value not supported");
12186 return 0;
12187 }
12188#else /* NL80211_SUPPORT */
12189 sigma_dut_print(dut, DUT_MSG_ERROR,
12190 "LTF cannot be set without NL80211_SUPPORT defined");
12191 return -2;
12192#endif /* NL80211_SUPPORT */
12193 }
12194
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -070012195 val = get_param(cmd, "TxSUPPDU");
12196 if (val) {
12197 int set_val = 1;
12198
12199 if (strcasecmp(val, "Enable") == 0)
12200 set_val = 1;
12201 else if (strcasecmp(val, "Disable") == 0)
12202 set_val = 0;
12203
12204 if (sta_set_tx_su_ppdu_cfg(dut, intf, set_val)) {
12205 send_resp(dut, conn, SIGMA_ERROR,
12206 "ErrorCode,Failed to set Tx SU PPDU config");
12207 return 0;
12208 }
12209 }
12210
Arif Hussain480d5f42019-03-12 14:40:42 -070012211 val = get_param(cmd, "TWT_Setup");
12212 if (val) {
12213 if (strcasecmp(val, "Request") == 0) {
12214 if (sta_twt_request(dut, conn, cmd)) {
12215 send_resp(dut, conn, SIGMA_ERROR,
12216 "ErrorCode,sta_twt_request failed");
12217 return STATUS_SENT;
12218 }
12219 } else if (strcasecmp(val, "Teardown") == 0) {
12220 if (sta_twt_teardown(dut, conn, cmd)) {
12221 send_resp(dut, conn, SIGMA_ERROR,
12222 "ErrorCode,sta_twt_teardown failed");
12223 return STATUS_SENT;
12224 }
12225 }
12226 }
12227
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -080012228 val = get_param(cmd, "transmitOMI");
12229 if (val && sta_transmit_omi(dut, conn, cmd)) {
12230 send_resp(dut, conn, SIGMA_ERROR,
12231 "ErrorCode,sta_transmit_omi failed");
12232 return STATUS_SENT;
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -070012233 }
12234
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080012235 val = get_param(cmd, "Powersave");
12236 if (val) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012237 int ps;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080012238
12239 if (strcasecmp(val, "off") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012240 ps = 2;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080012241 } else if (strcasecmp(val, "on") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012242 ps = 1;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080012243 } else {
12244 sigma_dut_print(dut, DUT_MSG_ERROR,
12245 "Unsupported Powersave value '%s'",
12246 val);
12247 return -1;
12248 }
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012249 if (set_power_save_wcn(dut, intf, ps) < 0)
12250 return 0;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080012251 }
12252
Kiran Kumar Lokere2c4b7ce2019-01-30 12:02:28 -080012253 val = get_param(cmd, "MU_EDCA");
12254 if (val) {
12255 if (strcasecmp(val, "Override") == 0) {
12256 if (sta_set_mu_edca_override(dut, intf, 1)) {
12257 send_resp(dut, conn, SIGMA_ERROR,
12258 "errorCode,MU EDCA override set failed");
12259 return STATUS_SENT;
12260 }
12261 } else if (strcasecmp(val, "Disable") == 0) {
12262 if (sta_set_mu_edca_override(dut, intf, 0)) {
12263 send_resp(dut, conn, SIGMA_ERROR,
12264 "errorCode,MU EDCA override disable failed");
12265 return STATUS_SENT;
12266 }
12267 }
12268 }
12269
Kiran Kumar Lokeredd086642020-06-04 00:29:26 -070012270 val = get_param(cmd, "Ch_Pref");
12271 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
12272 return STATUS_SENT;
12273
12274 val = get_param(cmd, "Cellular_Data_Cap");
12275 if (val && mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
12276 return STATUS_SENT;
12277
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012278 return 1;
12279
12280failed:
12281 free(token);
12282 return -2;
12283}
12284
12285
12286static int cmd_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
12287 struct sigma_conn *conn,
12288 struct sigma_cmd *cmd)
12289{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012290 switch (get_driver_type(dut)) {
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012291 case DRIVER_WCN:
12292 return wcn_sta_set_rfeature_he(intf, dut, conn, cmd);
12293 default:
12294 send_resp(dut, conn, SIGMA_ERROR,
12295 "errorCode,Unsupported sta_set_rfeature(HE) with the current driver");
12296 return 0;
12297 }
12298}
12299
12300
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012301static int cmd_sta_set_power_save_he(const char *intf, struct sigma_dut *dut,
12302 struct sigma_conn *conn,
12303 struct sigma_cmd *cmd)
12304{
12305 const char *val;
12306
12307 val = get_param(cmd, "powersave");
12308 if (val) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012309 int ps;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012310
12311 if (strcasecmp(val, "off") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012312 ps = 2;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012313 } else if (strcasecmp(val, "on") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012314 ps = 1;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012315 } else {
12316 sigma_dut_print(dut, DUT_MSG_ERROR,
12317 "Unsupported power save config");
12318 return -1;
12319 }
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012320 if (set_power_save_wcn(dut, intf, ps) < 0)
12321 return 0;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012322 return 1;
12323 }
12324
12325 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported command");
12326
12327 return 0;
12328}
12329
12330
Ashwini Patil5acd7382017-04-13 15:55:04 +053012331static int btm_query_candidate_list(struct sigma_dut *dut,
12332 struct sigma_conn *conn,
12333 struct sigma_cmd *cmd)
12334{
12335 const char *bssid, *info, *op_class, *ch, *phy_type, *pref;
12336 int len, ret;
12337 char buf[10];
12338
12339 /*
12340 * Neighbor Report elements format:
12341 * neighbor=<BSSID>,<BSSID Information>,<Operating Class>,
12342 * <Channel Number>,<PHY Type>[,<hexdump of Optional Subelements>]
12343 * eg: neighbor=aa:bb:cc:dd:ee:ff,17,81,6,1,030101
12344 */
12345
12346 bssid = get_param(cmd, "Nebor_BSSID");
12347 if (!bssid) {
12348 send_resp(dut, conn, SIGMA_INVALID,
12349 "errorCode,Nebor_BSSID is missing");
12350 return 0;
12351 }
12352
12353 info = get_param(cmd, "Nebor_Bssid_Info");
12354 if (!info) {
12355 sigma_dut_print(dut, DUT_MSG_INFO,
12356 "Using default value for Nebor_Bssid_Info: %s",
12357 DEFAULT_NEIGHBOR_BSSID_INFO);
12358 info = DEFAULT_NEIGHBOR_BSSID_INFO;
12359 }
12360
12361 op_class = get_param(cmd, "Nebor_Op_Class");
12362 if (!op_class) {
12363 send_resp(dut, conn, SIGMA_INVALID,
12364 "errorCode,Nebor_Op_Class is missing");
12365 return 0;
12366 }
12367
12368 ch = get_param(cmd, "Nebor_Op_Ch");
12369 if (!ch) {
12370 send_resp(dut, conn, SIGMA_INVALID,
12371 "errorCode,Nebor_Op_Ch is missing");
12372 return 0;
12373 }
12374
12375 phy_type = get_param(cmd, "Nebor_Phy_Type");
12376 if (!phy_type) {
12377 sigma_dut_print(dut, DUT_MSG_INFO,
12378 "Using default value for Nebor_Phy_Type: %s",
12379 DEFAULT_NEIGHBOR_PHY_TYPE);
12380 phy_type = DEFAULT_NEIGHBOR_PHY_TYPE;
12381 }
12382
12383 /* Parse optional subelements */
12384 buf[0] = '\0';
12385 pref = get_param(cmd, "Nebor_Pref");
12386 if (pref) {
12387 /* hexdump for preferrence subelement */
12388 ret = snprintf(buf, sizeof(buf), ",0301%02x", atoi(pref));
12389 if (ret < 0 || ret >= (int) sizeof(buf)) {
12390 sigma_dut_print(dut, DUT_MSG_ERROR,
12391 "snprintf failed for optional subelement ret: %d",
12392 ret);
12393 send_resp(dut, conn, SIGMA_ERROR,
12394 "errorCode,snprintf failed for subelement");
12395 return 0;
12396 }
12397 }
12398
12399 if (!dut->btm_query_cand_list) {
12400 dut->btm_query_cand_list = calloc(1, NEIGHBOR_REPORT_SIZE);
12401 if (!dut->btm_query_cand_list) {
12402 send_resp(dut, conn, SIGMA_ERROR,
12403 "errorCode,Failed to allocate memory for btm_query_cand_list");
12404 return 0;
12405 }
12406 }
12407
12408 len = strlen(dut->btm_query_cand_list);
12409 ret = snprintf(dut->btm_query_cand_list + len,
12410 NEIGHBOR_REPORT_SIZE - len, " neighbor=%s,%s,%s,%s,%s%s",
12411 bssid, info, op_class, ch, phy_type, buf);
12412 if (ret < 0 || ret >= NEIGHBOR_REPORT_SIZE - len) {
12413 sigma_dut_print(dut, DUT_MSG_ERROR,
12414 "snprintf failed for neighbor report list ret: %d",
12415 ret);
12416 send_resp(dut, conn, SIGMA_ERROR,
12417 "errorCode,snprintf failed for neighbor report");
12418 free(dut->btm_query_cand_list);
12419 dut->btm_query_cand_list = NULL;
12420 return 0;
12421 }
12422
12423 return 1;
12424}
12425
12426
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012427int sta_extract_60g_ese(struct sigma_dut *dut, struct sigma_cmd *cmd,
12428 struct sigma_ese_alloc *allocs, int *allocs_size)
12429{
12430 int max_count = *allocs_size;
12431 int count = 0, i;
12432 const char *val;
12433
12434 do {
12435 val = get_param_indexed(cmd, "AllocID", count);
12436 if (val)
12437 count++;
12438 } while (val);
12439
12440 if (count == 0 || count > max_count) {
12441 sigma_dut_print(dut, DUT_MSG_ERROR,
12442 "Invalid number of allocations(%d)", count);
12443 return -1;
12444 }
12445
12446 for (i = 0; i < count; i++) {
12447 val = get_param_indexed(cmd, "PercentBI", i);
12448 if (!val) {
12449 sigma_dut_print(dut, DUT_MSG_ERROR,
12450 "Missing PercentBI parameter at index %d",
12451 i);
12452 return -1;
12453 }
12454 allocs[i].percent_bi = atoi(val);
12455
12456 val = get_param_indexed(cmd, "SrcAID", i);
12457 if (val)
12458 allocs[i].src_aid = strtol(val, NULL, 0);
12459 else
12460 allocs[i].src_aid = ESE_BCAST_AID;
12461
12462 val = get_param_indexed(cmd, "DestAID", i);
12463 if (val)
12464 allocs[i].dst_aid = strtol(val, NULL, 0);
12465 else
12466 allocs[i].dst_aid = ESE_BCAST_AID;
12467
12468 allocs[i].type = ESE_CBAP;
12469 sigma_dut_print(dut, DUT_MSG_INFO,
12470 "Alloc %d PercentBI %d SrcAID %d DstAID %d",
12471 i, allocs[i].percent_bi, allocs[i].src_aid,
12472 allocs[i].dst_aid);
12473 }
12474
12475 *allocs_size = count;
12476 return 0;
12477}
12478
12479
12480static int sta_set_60g_ese(struct sigma_dut *dut, int count,
12481 struct sigma_ese_alloc *allocs)
12482{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012483 switch (get_driver_type(dut)) {
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012484#ifdef __linux__
12485 case DRIVER_WIL6210:
12486 if (wil6210_set_ese(dut, count, allocs))
12487 return -1;
12488 return 1;
12489#endif /* __linux__ */
12490 default:
12491 sigma_dut_print(dut, DUT_MSG_ERROR,
12492 "Unsupported sta_set_60g_ese with the current driver");
12493 return -1;
12494 }
12495}
12496
12497
12498static int cmd_sta_set_rfeature_60g(const char *intf, struct sigma_dut *dut,
12499 struct sigma_conn *conn,
12500 struct sigma_cmd *cmd)
12501{
12502 const char *val;
12503
12504 val = get_param(cmd, "ExtSchIE");
12505 if (val && !strcasecmp(val, "Enable")) {
12506 struct sigma_ese_alloc allocs[MAX_ESE_ALLOCS];
12507 int count = MAX_ESE_ALLOCS;
12508
12509 if (sta_extract_60g_ese(dut, cmd, allocs, &count))
12510 return -1;
12511 return sta_set_60g_ese(dut, count, allocs);
12512 }
12513
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020012514 val = get_param(cmd, "MCS_FixedRate");
12515 if (val) {
12516 int sta_mcs = atoi(val);
12517
12518 sigma_dut_print(dut, DUT_MSG_INFO, "Force STA MCS to %d",
12519 sta_mcs);
12520 wil6210_set_force_mcs(dut, 1, sta_mcs);
12521
Jouni Malinen0e29cf22019-02-19 01:13:21 +020012522 return SUCCESS_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020012523 }
12524
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012525 send_resp(dut, conn, SIGMA_ERROR,
12526 "errorCode,Invalid sta_set_rfeature(60G)");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020012527 return STATUS_SENT;
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012528}
12529
12530
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053012531static int wcn_sta_override_oci(struct sigma_dut *dut, const char *intf,
12532 const char *oci_frametype, uint32_t oci_freq)
12533{
12534#ifdef NL80211_SUPPORT
12535 struct nl_msg *msg;
12536 int ret = 0;
12537 struct nlattr *params;
12538 struct nlattr *attr;
12539 int ifindex;
12540 u8 frame_type;
12541
12542 ifindex = if_nametoindex(intf);
12543 if (ifindex == 0) {
12544 sigma_dut_print(dut, DUT_MSG_ERROR,
12545 "%s: Index for interface %s failed",
12546 __func__, intf);
12547 return -1;
12548 }
12549
12550 if (strcasecmp(oci_frametype, "SAQueryReq") == 0) {
12551 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_SA_QUERY_REQ;
12552 } else if (strcasecmp(oci_frametype, "SAQueryResp") == 0) {
12553 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_SA_QUERY_RESP;
12554 } else if (strcasecmp(oci_frametype, "Reassocreq") == 0) {
12555 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_FT_REASSOC_REQ;
12556 } else {
12557 sigma_dut_print(dut, DUT_MSG_ERROR, "%s: Unknown frametype %s",
12558 __func__, oci_frametype);
12559 return -1;
12560 }
12561
12562
12563 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
12564 NL80211_CMD_VENDOR)) ||
12565 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
12566 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
12567 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
12568 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
12569 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
12570 !(params = nla_nest_start(
12571 msg,
12572 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_OCI_OVERRIDE)) ||
12573 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_OCI_OVERRIDE_FRAME_TYPE,
12574 frame_type) ||
12575 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_OCI_OVERRIDE_FREQUENCY,
12576 oci_freq)) {
12577 sigma_dut_print(dut, DUT_MSG_ERROR,
12578 "%s: err in adding vendor_cmd and vendor_data",
12579 __func__);
12580 nlmsg_free(msg);
12581 return -1;
12582 }
12583 nla_nest_end(msg, params);
12584 nla_nest_end(msg, attr);
12585
12586 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
12587 if (ret) {
12588 sigma_dut_print(dut, DUT_MSG_ERROR,
12589 "%s: err in send_and_recv_msgs, ret=%d",
12590 __func__, ret);
12591 }
12592 return ret;
12593#else /* NL80211_SUPPORT */
12594 sigma_dut_print(dut, DUT_MSG_ERROR,
12595 "OCI override not possible without NL80211_SUPPORT defined");
12596 return -1;
12597#endif /* NL80211_SUPPORT */
12598}
12599
12600
Jouni Malinen6250cb02020-04-15 13:54:45 +030012601static enum sigma_cmd_result
12602cmd_sta_set_rfeature_wpa3(const char *intf, struct sigma_dut *dut,
12603 struct sigma_conn *conn,
12604 struct sigma_cmd *cmd)
12605{
Vamsi Krishnad29bc762020-05-08 23:23:30 +053012606 const char *val, *oci_chan, *oci_frametype;
Jouni Malinen6250cb02020-04-15 13:54:45 +030012607
Veerendranath Jakkam30bf9072020-04-16 14:37:57 +053012608 val = get_param(cmd, "ReassocReq_RSNXE_Used");
Jouni Malinen6250cb02020-04-15 13:54:45 +030012609 if (val && atoi(val) == 1) {
12610 if (wpa_command(intf, "SET ft_rsnxe_used 1") < 0) {
12611 send_resp(dut, conn, SIGMA_ERROR,
12612 "errorCode,Failed to set ft_rsnxe_used");
12613 return STATUS_SENT_ERROR;
12614 }
12615 return SUCCESS_SEND_STATUS;
12616 }
Vamsi Krishnad29bc762020-05-08 23:23:30 +053012617
12618 oci_chan = get_param(cmd, "OCIChannel");
12619 oci_frametype = get_param(cmd, "OCIFrameType");
12620 if (oci_chan && oci_frametype) {
12621 unsigned int oci_freq = channel_to_freq(dut, atoi(oci_chan));
12622 char buf[100];
12623
12624 if (!oci_freq) {
12625 send_resp(dut, conn, SIGMA_ERROR,
12626 "errorCode,Invalid OCIChannel number");
12627 return STATUS_SENT_ERROR;
12628 }
12629
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053012630 if (wifi_chip_type == DRIVER_WCN &&
12631 (strcasecmp(oci_frametype, "SAQueryReq") == 0 ||
12632 strcasecmp(oci_frametype, "SAQueryResp") == 0 ||
12633 strcasecmp(oci_frametype, "Reassocreq") == 0)) {
12634 if (wcn_sta_override_oci(dut, intf, oci_frametype,
12635 oci_freq)) {
12636 send_resp(dut, conn, SIGMA_ERROR,
12637 "errorCode,Failed to override OCI");
12638 return STATUS_SENT_ERROR;
12639 }
12640 return SUCCESS_SEND_STATUS;
12641 }
12642
Vamsi Krishnad29bc762020-05-08 23:23:30 +053012643 if (strcasecmp(oci_frametype, "eapolM2") == 0) {
12644 snprintf(buf, sizeof(buf),
12645 "SET oci_freq_override_eapol %d", oci_freq);
12646 } else if (strcasecmp(oci_frametype, "SAQueryReq") == 0) {
12647 snprintf(buf, sizeof(buf),
12648 "SET oci_freq_override_saquery_req %d",
12649 oci_freq);
12650 } else if (strcasecmp(oci_frametype, "SAQueryResp") == 0) {
12651 snprintf(buf, sizeof(buf),
12652 "SET oci_freq_override_saquery_resp %d",
12653 oci_freq);
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053012654 } else if (strcasecmp(oci_frametype, "GrpKeyM2") == 0) {
12655 snprintf(buf, sizeof(buf),
12656 "SET oci_freq_override_eapol_g2 %d",
12657 oci_freq);
12658 } else if (strcasecmp(oci_frametype, "Reassocreq") == 0) {
12659 snprintf(buf, sizeof(buf),
12660 "SET oci_freq_override_ft_assoc %d",
12661 oci_freq);
Vamsi Krishnad29bc762020-05-08 23:23:30 +053012662 } else {
12663 send_resp(dut, conn, SIGMA_ERROR,
12664 "errorCode,Unsupported OCIFrameType");
12665 return STATUS_SENT_ERROR;
12666 }
12667 if (wpa_command(intf, buf) < 0) {
12668 send_resp(dut, conn, SIGMA_ERROR,
12669 "errorCode,Failed to set oci_freq_override");
12670 return STATUS_SENT_ERROR;
12671 }
12672 return SUCCESS_SEND_STATUS;
12673 }
12674
Jouni Malinen6250cb02020-04-15 13:54:45 +030012675 send_resp(dut, conn, SIGMA_ERROR,
12676 "errorCode,Unsupported WPA3 rfeature");
12677 return STATUS_SENT_ERROR;
12678}
12679
12680
Jouni Malinenf7222712019-06-13 01:50:21 +030012681static enum sigma_cmd_result cmd_sta_set_rfeature(struct sigma_dut *dut,
12682 struct sigma_conn *conn,
12683 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012684{
12685 const char *intf = get_param(cmd, "Interface");
12686 const char *prog = get_param(cmd, "Prog");
Ashwini Patil68d02cd2017-01-10 15:39:16 +053012687 const char *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012688
12689 if (intf == NULL || prog == NULL)
12690 return -1;
12691
Ashwini Patil5acd7382017-04-13 15:55:04 +053012692 /* BSS Transition candidate list for BTM query */
12693 val = get_param(cmd, "Nebor_BSSID");
12694 if (val && btm_query_candidate_list(dut, conn, cmd) == 0)
12695 return 0;
12696
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012697 if (strcasecmp(prog, "TDLS") == 0)
12698 return cmd_sta_set_rfeature_tdls(intf, dut, conn, cmd);
12699
12700 if (strcasecmp(prog, "VHT") == 0)
12701 return cmd_sta_set_rfeature_vht(intf, dut, conn, cmd);
12702
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012703 if (strcasecmp(prog, "HE") == 0)
12704 return cmd_sta_set_rfeature_he(intf, dut, conn, cmd);
12705
Ashwini Patil68d02cd2017-01-10 15:39:16 +053012706 if (strcasecmp(prog, "MBO") == 0) {
12707 val = get_param(cmd, "Cellular_Data_Cap");
12708 if (val &&
12709 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
12710 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +053012711
12712 val = get_param(cmd, "Ch_Pref");
12713 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
12714 return 0;
12715
Ashwini Patil68d02cd2017-01-10 15:39:16 +053012716 return 1;
12717 }
12718
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012719 if (strcasecmp(prog, "60GHz") == 0)
12720 return cmd_sta_set_rfeature_60g(intf, dut, conn, cmd);
12721
Jouni Malinen6250cb02020-04-15 13:54:45 +030012722 if (strcasecmp(prog, "WPA3") == 0)
12723 return cmd_sta_set_rfeature_wpa3(intf, dut, conn, cmd);
12724
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012725 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported Prog");
12726 return 0;
12727}
12728
12729
Jouni Malinenf7222712019-06-13 01:50:21 +030012730static enum sigma_cmd_result cmd_sta_set_radio(struct sigma_dut *dut,
12731 struct sigma_conn *conn,
12732 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012733{
12734 const char *intf = get_param(cmd, "Interface");
12735 const char *mode = get_param(cmd, "Mode");
12736 int res;
12737
12738 if (intf == NULL || mode == NULL)
12739 return -1;
12740
12741 if (strcasecmp(mode, "On") == 0)
12742 res = wpa_command(intf, "SET radio_disabled 0");
12743 else if (strcasecmp(mode, "Off") == 0)
12744 res = wpa_command(intf, "SET radio_disabled 1");
12745 else
12746 return -1;
12747
12748 if (res) {
12749 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
12750 "radio mode");
12751 return 0;
12752 }
12753
12754 return 1;
12755}
12756
12757
Jouni Malinenf7222712019-06-13 01:50:21 +030012758static enum sigma_cmd_result cmd_sta_set_pwrsave(struct sigma_dut *dut,
12759 struct sigma_conn *conn,
12760 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012761{
12762 const char *intf = get_param(cmd, "Interface");
12763 const char *mode = get_param(cmd, "Mode");
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012764 const char *prog = get_param(cmd, "program");
12765 const char *powersave = get_param(cmd, "powersave");
12766 int res = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012767
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012768 if (intf == NULL)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012769 return -1;
12770
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012771 if (prog && strcasecmp(prog, "60GHz") == 0) {
12772 /*
12773 * The CAPI mode parameter does not exist in 60G
12774 * unscheduled PS.
12775 */
Hu Wang5dc3ff12019-06-14 15:14:26 +080012776 if (powersave && strcasecmp(powersave, "unscheduled") == 0)
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012777 res = set_ps(intf, dut, 1);
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012778 } else if (prog && get_driver_type(dut) == DRIVER_WCN &&
Alexei Avshalom Lazar2f6fdb42019-02-04 14:16:08 +020012779 strcasecmp(prog, "HE") == 0) {
12780 return cmd_sta_set_power_save_he(intf, dut, conn, cmd);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012781 } else {
12782 if (mode == NULL)
12783 return -1;
12784
12785 if (strcasecmp(mode, "On") == 0)
12786 res = set_ps(intf, dut, 1);
12787 else if (strcasecmp(mode, "Off") == 0)
12788 res = set_ps(intf, dut, 0);
12789 else
12790 return -1;
12791 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012792
12793 if (res) {
12794 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
12795 "power save mode");
12796 return 0;
12797 }
12798
12799 return 1;
12800}
12801
12802
Jouni Malinenf7222712019-06-13 01:50:21 +030012803static enum sigma_cmd_result cmd_sta_bssid_pool(struct sigma_dut *dut,
12804 struct sigma_conn *conn,
12805 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012806{
12807 const char *intf = get_param(cmd, "Interface");
12808 const char *val, *bssid;
12809 int res;
12810 char *buf;
12811 size_t buf_len;
12812
12813 val = get_param(cmd, "BSSID_FILTER");
12814 if (val == NULL)
12815 return -1;
12816
12817 bssid = get_param(cmd, "BSSID_List");
12818 if (atoi(val) == 0 || bssid == NULL) {
12819 /* Disable BSSID filter */
12820 if (wpa_command(intf, "SET bssid_filter ")) {
12821 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed "
12822 "to disable BSSID filter");
12823 return 0;
12824 }
12825
12826 return 1;
12827 }
12828
12829 buf_len = 100 + strlen(bssid);
12830 buf = malloc(buf_len);
12831 if (buf == NULL)
12832 return -1;
12833
12834 snprintf(buf, buf_len, "SET bssid_filter %s", bssid);
12835 res = wpa_command(intf, buf);
12836 free(buf);
12837 if (res) {
12838 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to enable "
12839 "BSSID filter");
12840 return 0;
12841 }
12842
12843 return 1;
12844}
12845
12846
Jouni Malinenf7222712019-06-13 01:50:21 +030012847static enum sigma_cmd_result cmd_sta_reset_parm(struct sigma_dut *dut,
12848 struct sigma_conn *conn,
12849 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012850{
12851 const char *intf = get_param(cmd, "Interface");
12852 const char *val;
12853
12854 /* TODO: ARP */
12855
12856 val = get_param(cmd, "HS2_CACHE_PROFILE");
12857 if (val && strcasecmp(val, "All") == 0)
12858 hs2_clear_credentials(intf);
12859
12860 return 1;
12861}
12862
12863
Jouni Malinenf7222712019-06-13 01:50:21 +030012864static enum sigma_cmd_result cmd_sta_get_key(struct sigma_dut *dut,
12865 struct sigma_conn *conn,
12866 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012867{
12868 const char *intf = get_param(cmd, "Interface");
12869 const char *key_type = get_param(cmd, "KeyType");
12870 char buf[100], resp[200];
12871
12872 if (key_type == NULL)
12873 return -1;
12874
12875 if (strcasecmp(key_type, "GTK") == 0) {
12876 if (wpa_command_resp(intf, "GET gtk", buf, sizeof(buf)) < 0 ||
12877 strncmp(buf, "FAIL", 4) == 0) {
12878 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12879 "not fetch current GTK");
12880 return 0;
12881 }
12882 snprintf(resp, sizeof(resp), "KeyValue,%s", buf);
12883 send_resp(dut, conn, SIGMA_COMPLETE, resp);
12884 return 0;
12885 } else {
12886 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
12887 "KeyType");
12888 return 0;
12889 }
12890
12891 return 1;
12892}
12893
12894
12895static int hs2_set_policy(struct sigma_dut *dut)
12896{
12897#ifdef ANDROID
12898 system("ip rule del prio 23000");
12899 if (system("ip rule add from all lookup main prio 23000") != 0) {
12900 sigma_dut_print(dut, DUT_MSG_ERROR,
12901 "Failed to run:ip rule add from all lookup main prio");
12902 return -1;
12903 }
12904 if (system("ip route flush cache") != 0) {
12905 sigma_dut_print(dut, DUT_MSG_ERROR,
12906 "Failed to run ip route flush cache");
12907 return -1;
12908 }
12909 return 1;
12910#else /* ANDROID */
12911 return 0;
12912#endif /* ANDROID */
12913}
12914
12915
Jouni Malinenf7222712019-06-13 01:50:21 +030012916static enum sigma_cmd_result cmd_sta_hs2_associate(struct sigma_dut *dut,
12917 struct sigma_conn *conn,
12918 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012919{
12920 const char *intf = get_param(cmd, "Interface");
12921 const char *val = get_param(cmd, "Ignore_blacklist");
Jouni Malinen439352d2018-09-13 03:42:23 +030012922 const char *band = get_param(cmd, "Band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012923 struct wpa_ctrl *ctrl;
Jouni Malinen3aa72862019-05-29 23:14:51 +030012924 int res, r;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012925 char bssid[20], ssid[40], resp[100], buf[100], blacklisted[100];
12926 int tries = 0;
12927 int ignore_blacklist = 0;
12928 const char *events[] = {
12929 "CTRL-EVENT-CONNECTED",
12930 "INTERWORKING-BLACKLISTED",
12931 "INTERWORKING-NO-MATCH",
12932 NULL
12933 };
12934
12935 start_sta_mode(dut);
12936
Jouni Malinen439352d2018-09-13 03:42:23 +030012937 if (band) {
12938 if (strcmp(band, "2.4") == 0) {
12939 wpa_command(intf, "SET setband 2G");
12940 } else if (strcmp(band, "5") == 0) {
12941 wpa_command(intf, "SET setband 5G");
12942 } else {
12943 send_resp(dut, conn, SIGMA_ERROR,
12944 "errorCode,Unsupported band");
12945 return 0;
12946 }
12947 }
12948
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012949 blacklisted[0] = '\0';
12950 if (val && atoi(val))
12951 ignore_blacklist = 1;
12952
12953try_again:
12954 ctrl = open_wpa_mon(intf);
12955 if (ctrl == NULL) {
12956 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
12957 "wpa_supplicant monitor connection");
12958 return -2;
12959 }
12960
12961 tries++;
12962 if (wpa_command(intf, "INTERWORKING_SELECT auto")) {
12963 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start "
12964 "Interworking connection");
12965 wpa_ctrl_detach(ctrl);
12966 wpa_ctrl_close(ctrl);
12967 return 0;
12968 }
12969
12970 buf[0] = '\0';
12971 while (1) {
12972 char *pos;
12973 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
12974 pos = strstr(buf, "INTERWORKING-BLACKLISTED");
12975 if (!pos)
12976 break;
12977 pos += 25;
12978 sigma_dut_print(dut, DUT_MSG_DEBUG, "Found blacklisted AP: %s",
12979 pos);
12980 if (!blacklisted[0])
12981 memcpy(blacklisted, pos, strlen(pos) + 1);
12982 }
12983
12984 if (ignore_blacklist && blacklisted[0]) {
12985 char *end;
12986 end = strchr(blacklisted, ' ');
12987 if (end)
12988 *end = '\0';
12989 sigma_dut_print(dut, DUT_MSG_DEBUG, "Try to connect to a blacklisted network: %s",
12990 blacklisted);
Jouni Malinen3aa72862019-05-29 23:14:51 +030012991 r = snprintf(buf, sizeof(buf), "INTERWORKING_CONNECT %s",
12992 blacklisted);
12993 if (r < 0 || r >= sizeof(buf) || wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012994 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start Interworking connection to blacklisted network");
12995 wpa_ctrl_detach(ctrl);
12996 wpa_ctrl_close(ctrl);
12997 return 0;
12998 }
12999 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
13000 buf, sizeof(buf));
13001 }
13002
13003 wpa_ctrl_detach(ctrl);
13004 wpa_ctrl_close(ctrl);
13005
13006 if (res < 0) {
13007 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
13008 "connect");
13009 return 0;
13010 }
13011
13012 if (strstr(buf, "INTERWORKING-NO-MATCH") ||
13013 strstr(buf, "INTERWORKING-BLACKLISTED")) {
13014 if (tries < 2) {
13015 sigma_dut_print(dut, DUT_MSG_INFO, "No match found - try again to verify no APs were missed in the scan");
13016 goto try_again;
13017 }
13018 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,No network with "
13019 "matching credentials found");
13020 return 0;
13021 }
13022
13023 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
13024 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
13025 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
13026 "get current BSSID/SSID");
13027 return 0;
13028 }
13029
13030 snprintf(resp, sizeof(resp), "SSID,%s,BSSID,%s", ssid, bssid);
13031 send_resp(dut, conn, SIGMA_COMPLETE, resp);
13032 hs2_set_policy(dut);
13033 return 0;
13034}
13035
13036
Jouni Malinenf7222712019-06-13 01:50:21 +030013037static enum sigma_cmd_result cmd_sta_hs2_venue_info(struct sigma_dut *dut,
13038 struct sigma_conn *conn,
13039 struct sigma_cmd *cmd)
Jouni Malinenb639f1c2018-09-13 02:39:46 +030013040{
13041 const char *intf = get_param(cmd, "Interface");
13042 const char *display = get_param(cmd, "Display");
13043 struct wpa_ctrl *ctrl;
13044 char buf[300], params[400], *pos;
13045 char bssid[20];
13046 int info_avail = 0;
13047 unsigned int old_timeout;
13048 int res;
13049
13050 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
13051 send_resp(dut, conn, SIGMA_ERROR,
13052 "ErrorCode,Could not get current BSSID");
13053 return 0;
13054 }
13055 ctrl = open_wpa_mon(intf);
13056 if (!ctrl) {
13057 sigma_dut_print(dut, DUT_MSG_ERROR,
13058 "Failed to open wpa_supplicant monitor connection");
13059 return -2;
13060 }
13061
13062 snprintf(buf, sizeof(buf), "ANQP_GET %s 277", bssid);
13063 wpa_command(intf, buf);
13064
13065 res = get_wpa_cli_event(dut, ctrl, "GAS-QUERY-DONE", buf, sizeof(buf));
13066 if (res < 0) {
13067 send_resp(dut, conn, SIGMA_ERROR,
13068 "ErrorCode,Could not complete GAS query");
13069 goto fail;
13070 }
13071
13072 old_timeout = dut->default_timeout;
13073 dut->default_timeout = 2;
13074 res = get_wpa_cli_event(dut, ctrl, "RX-VENUE-URL", buf, sizeof(buf));
13075 dut->default_timeout = old_timeout;
13076 if (res < 0)
13077 goto done;
13078 pos = strchr(buf, ' ');
13079 if (!pos)
13080 goto done;
13081 pos++;
13082 pos = strchr(pos, ' ');
13083 if (!pos)
13084 goto done;
13085 pos++;
13086 info_avail = 1;
13087 snprintf(params, sizeof(params), "browser %s", pos);
13088
13089 if (display && strcasecmp(display, "Yes") == 0) {
13090 pid_t pid;
13091
13092 pid = fork();
13093 if (pid < 0) {
13094 perror("fork");
13095 return -1;
13096 }
13097
13098 if (pid == 0) {
13099 run_hs20_osu(dut, params);
13100 exit(0);
13101 }
13102 }
13103
13104done:
13105 snprintf(buf, sizeof(buf), "Info_available,%s",
13106 info_avail ? "Yes" : "No");
13107 send_resp(dut, conn, SIGMA_COMPLETE, buf);
13108fail:
13109 wpa_ctrl_detach(ctrl);
13110 wpa_ctrl_close(ctrl);
13111 return 0;
13112}
13113
13114
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013115static int sta_add_credential_uname_pwd(struct sigma_dut *dut,
13116 struct sigma_conn *conn,
13117 const char *ifname,
13118 struct sigma_cmd *cmd)
13119{
13120 const char *val;
13121 int id;
13122
13123 id = add_cred(ifname);
13124 if (id < 0)
13125 return -2;
13126 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
13127
13128 val = get_param(cmd, "prefer");
13129 if (val && atoi(val) > 0)
13130 set_cred(ifname, id, "priority", "1");
13131
13132 val = get_param(cmd, "REALM");
13133 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
13134 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13135 "realm");
13136 return 0;
13137 }
13138
13139 val = get_param(cmd, "HOME_FQDN");
13140 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
13141 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13142 "home_fqdn");
13143 return 0;
13144 }
13145
13146 val = get_param(cmd, "Username");
13147 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
13148 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13149 "username");
13150 return 0;
13151 }
13152
13153 val = get_param(cmd, "Password");
13154 if (val && set_cred_quoted(ifname, id, "password", val) < 0) {
13155 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13156 "password");
13157 return 0;
13158 }
13159
13160 val = get_param(cmd, "ROOT_CA");
13161 if (val) {
13162 char fname[200];
13163 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
13164#ifdef __linux__
13165 if (!file_exists(fname)) {
13166 char msg[300];
13167 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
13168 "file (%s) not found", fname);
13169 send_resp(dut, conn, SIGMA_ERROR, msg);
13170 return 0;
13171 }
13172#endif /* __linux__ */
13173 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
13174 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13175 "not set root CA");
13176 return 0;
13177 }
13178 }
13179
13180 return 1;
13181}
13182
13183
13184static int update_devdetail_imsi(struct sigma_dut *dut, const char *imsi)
13185{
13186 FILE *in, *out;
13187 char buf[500];
13188 int found = 0;
13189
13190 in = fopen("devdetail.xml", "r");
13191 if (in == NULL)
13192 return -1;
13193 out = fopen("devdetail.xml.tmp", "w");
13194 if (out == NULL) {
13195 fclose(in);
13196 return -1;
13197 }
13198
13199 while (fgets(buf, sizeof(buf), in)) {
13200 char *pos = strstr(buf, "<IMSI>");
13201 if (pos) {
13202 sigma_dut_print(dut, DUT_MSG_INFO, "Updated DevDetail IMSI to %s",
13203 imsi);
13204 pos += 6;
13205 *pos = '\0';
13206 fprintf(out, "%s%s</IMSI>\n", buf, imsi);
13207 found++;
13208 } else {
13209 fprintf(out, "%s", buf);
13210 }
13211 }
13212
13213 fclose(out);
13214 fclose(in);
13215 if (found)
13216 rename("devdetail.xml.tmp", "devdetail.xml");
13217 else
13218 unlink("devdetail.xml.tmp");
13219
13220 return 0;
13221}
13222
13223
13224static int sta_add_credential_sim(struct sigma_dut *dut,
13225 struct sigma_conn *conn,
13226 const char *ifname, struct sigma_cmd *cmd)
13227{
13228 const char *val, *imsi = NULL;
13229 int id;
13230 char buf[200];
13231 int res;
13232 const char *pos;
13233 size_t mnc_len;
13234 char plmn_mcc[4];
13235 char plmn_mnc[4];
13236
13237 id = add_cred(ifname);
13238 if (id < 0)
13239 return -2;
13240 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
13241
13242 val = get_param(cmd, "prefer");
13243 if (val && atoi(val) > 0)
13244 set_cred(ifname, id, "priority", "1");
13245
13246 val = get_param(cmd, "PLMN_MCC");
13247 if (val == NULL) {
13248 send_resp(dut, conn, SIGMA_ERROR,
13249 "errorCode,Missing PLMN_MCC");
13250 return 0;
13251 }
13252 if (strlen(val) != 3) {
13253 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MCC");
13254 return 0;
13255 }
13256 snprintf(plmn_mcc, sizeof(plmn_mcc), "%s", val);
13257
13258 val = get_param(cmd, "PLMN_MNC");
13259 if (val == NULL) {
13260 send_resp(dut, conn, SIGMA_ERROR,
13261 "errorCode,Missing PLMN_MNC");
13262 return 0;
13263 }
13264 if (strlen(val) != 2 && strlen(val) != 3) {
13265 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MNC");
13266 return 0;
13267 }
13268 snprintf(plmn_mnc, sizeof(plmn_mnc), "%s", val);
13269
13270 val = get_param(cmd, "IMSI");
13271 if (val == NULL) {
13272 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing SIM "
13273 "IMSI");
13274 return 0;
13275 }
13276
13277 imsi = pos = val;
13278
13279 if (strncmp(plmn_mcc, pos, 3) != 0) {
13280 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MCC mismatch");
13281 return 0;
13282 }
13283 pos += 3;
13284
13285 mnc_len = strlen(plmn_mnc);
13286 if (mnc_len < 2) {
13287 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC not set");
13288 return 0;
13289 }
13290
13291 if (strncmp(plmn_mnc, pos, mnc_len) != 0) {
13292 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC mismatch");
13293 return 0;
13294 }
13295 pos += mnc_len;
13296
13297 res = snprintf(buf, sizeof(buf), "%s%s-%s",plmn_mcc, plmn_mnc, pos);
13298 if (res < 0 || res >= (int) sizeof(buf))
13299 return -1;
13300 if (set_cred_quoted(ifname, id, "imsi", buf) < 0) {
13301 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13302 "not set IMSI");
13303 return 0;
13304 }
13305
13306 val = get_param(cmd, "Password");
13307 if (val && set_cred_quoted(ifname, id, "milenage", val) < 0) {
13308 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13309 "not set password");
13310 return 0;
13311 }
13312
Jouni Malinenba630452018-06-22 11:49:59 +030013313 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013314 /*
13315 * Set provisioning_sp for the test cases where SIM/USIM
13316 * provisioning is used.
13317 */
13318 if (val && set_cred_quoted(ifname, id, "provisioning_sp",
13319 "wi-fi.org") < 0) {
13320 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13321 "not set provisioning_sp");
13322 return 0;
13323 }
13324
13325 update_devdetail_imsi(dut, imsi);
13326 }
13327
13328 return 1;
13329}
13330
13331
13332static int sta_add_credential_cert(struct sigma_dut *dut,
13333 struct sigma_conn *conn,
13334 const char *ifname,
13335 struct sigma_cmd *cmd)
13336{
13337 const char *val;
13338 int id;
13339
13340 id = add_cred(ifname);
13341 if (id < 0)
13342 return -2;
13343 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
13344
13345 val = get_param(cmd, "prefer");
13346 if (val && atoi(val) > 0)
13347 set_cred(ifname, id, "priority", "1");
13348
13349 val = get_param(cmd, "REALM");
13350 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
13351 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13352 "realm");
13353 return 0;
13354 }
13355
13356 val = get_param(cmd, "HOME_FQDN");
13357 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
13358 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13359 "home_fqdn");
13360 return 0;
13361 }
13362
13363 val = get_param(cmd, "Username");
13364 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
13365 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13366 "username");
13367 return 0;
13368 }
13369
13370 val = get_param(cmd, "clientCertificate");
13371 if (val) {
13372 char fname[200];
13373 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
13374#ifdef __linux__
13375 if (!file_exists(fname)) {
13376 char msg[300];
13377 snprintf(msg, sizeof(msg),
13378 "ErrorCode,clientCertificate "
13379 "file (%s) not found", fname);
13380 send_resp(dut, conn, SIGMA_ERROR, msg);
13381 return 0;
13382 }
13383#endif /* __linux__ */
13384 if (set_cred_quoted(ifname, id, "client_cert", fname) < 0) {
13385 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13386 "not set client_cert");
13387 return 0;
13388 }
13389 if (set_cred_quoted(ifname, id, "private_key", fname) < 0) {
13390 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13391 "not set private_key");
13392 return 0;
13393 }
13394 }
13395
13396 val = get_param(cmd, "ROOT_CA");
13397 if (val) {
13398 char fname[200];
13399 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
13400#ifdef __linux__
13401 if (!file_exists(fname)) {
13402 char msg[300];
13403 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
13404 "file (%s) not found", fname);
13405 send_resp(dut, conn, SIGMA_ERROR, msg);
13406 return 0;
13407 }
13408#endif /* __linux__ */
13409 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
13410 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13411 "not set root CA");
13412 return 0;
13413 }
13414 }
13415
13416 return 1;
13417}
13418
13419
Jouni Malinenf7222712019-06-13 01:50:21 +030013420static enum sigma_cmd_result cmd_sta_add_credential(struct sigma_dut *dut,
13421 struct sigma_conn *conn,
13422 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013423{
13424 const char *intf = get_param(cmd, "Interface");
13425 const char *type;
13426
13427 start_sta_mode(dut);
13428
13429 type = get_param(cmd, "Type");
13430 if (!type)
13431 return -1;
13432
13433 if (strcasecmp(type, "uname_pwd") == 0)
13434 return sta_add_credential_uname_pwd(dut, conn, intf, cmd);
13435
13436 if (strcasecmp(type, "sim") == 0)
13437 return sta_add_credential_sim(dut, conn, intf, cmd);
13438
13439 if (strcasecmp(type, "cert") == 0)
13440 return sta_add_credential_cert(dut, conn, intf, cmd);
13441
13442 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported credential "
13443 "type");
13444 return 0;
13445}
13446
13447
Jouni Malinenf7222712019-06-13 01:50:21 +030013448static enum sigma_cmd_result cmd_sta_scan(struct sigma_dut *dut,
13449 struct sigma_conn *conn,
13450 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013451{
13452 const char *intf = get_param(cmd, "Interface");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013453 const char *val, *bssid, *ssid, *scan_freq, *short_ssid;
Arif Hussain66a4af02019-02-07 15:04:51 -080013454 char buf[4096];
vamsi krishna89ad8c62017-09-19 12:51:18 +053013455 char ssid_hex[65];
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080013456 int wildcard_ssid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013457 int res;
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013458 enum sigma_cmd_result status;
Jouni Malinen228a2fc2020-06-22 23:37:45 +030013459 struct wpa_ctrl *ctrl = NULL;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013460
Jouni Malinen8c1abeb2019-11-06 18:48:34 +020013461 start_sta_mode(dut);
13462
Arif Hussain66a4af02019-02-07 15:04:51 -080013463 val = get_param(cmd, "GetParameter");
13464 if (val && strcmp(val, "SSID_BSSID") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013465 if (get_wpa_ssid_bssid(dut, get_station_ifname(dut),
Arif Hussain66a4af02019-02-07 15:04:51 -080013466 buf, sizeof(buf)) < 0) {
13467 sigma_dut_print(dut, DUT_MSG_ERROR,
13468 "Could not get ssid bssid");
13469 return ERROR_SEND_STATUS;
13470 }
13471
13472 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
13473 send_resp(dut, conn, SIGMA_COMPLETE, buf);
13474 return STATUS_SENT;
13475 }
13476
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013477 val = get_param(cmd, "HESSID");
13478 if (val) {
13479 res = snprintf(buf, sizeof(buf), "SET hessid %s", val);
13480 if (res < 0 || res >= (int) sizeof(buf))
13481 return -1;
13482 wpa_command(intf, buf);
13483 }
13484
13485 val = get_param(cmd, "ACCS_NET_TYPE");
13486 if (val) {
13487 res = snprintf(buf, sizeof(buf), "SET access_network_type %s",
13488 val);
13489 if (res < 0 || res >= (int) sizeof(buf))
13490 return -1;
13491 wpa_command(intf, buf);
13492 }
13493
vamsi krishna89ad8c62017-09-19 12:51:18 +053013494 bssid = get_param(cmd, "Bssid");
13495 ssid = get_param(cmd, "Ssid");
13496
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080013497 if (ssid && strcasecmp(ssid, "ZeroLength") == 0 &&
13498 dut->device_type == STA_testbed) {
13499 ssid = NULL;
13500 wildcard_ssid = 1;
13501 }
13502
vamsi krishna89ad8c62017-09-19 12:51:18 +053013503 if (ssid) {
13504 if (2 * strlen(ssid) >= sizeof(ssid_hex)) {
13505 send_resp(dut, conn, SIGMA_ERROR,
13506 "ErrorCode,Too long SSID");
13507 return 0;
13508 }
13509 ascii2hexstr(ssid, ssid_hex);
13510 }
13511
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013512 short_ssid = get_param(cmd, "ShortSSID");
13513 if (short_ssid) {
13514 uint32_t short_ssid_hex;
13515
13516 short_ssid_hex = strtoul(short_ssid, NULL, 16);
13517 short_ssid_hex = ((short_ssid_hex & 0xFF) << 24) |
13518 (((short_ssid_hex >> 8) & 0xFF) << 16) |
13519 (((short_ssid_hex >> 16) & 0xFF) << 8) |
13520 ((short_ssid_hex >> 24) & 0xFF);
13521
13522 res = snprintf(buf, sizeof(buf),
13523 "VENDOR_ELEM_ADD 14 ff053a%08x",
13524 short_ssid_hex);
13525 if (res < 0 || res >= (int) sizeof(buf) ||
13526 wpa_command(intf, buf)) {
13527 send_resp(dut, conn, SIGMA_ERROR,
13528 "errorCode,Failed to add short SSID");
13529 return STATUS_SENT_ERROR;
13530 }
13531 }
13532
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080013533 scan_freq = get_param(cmd, "ChnlFreq");
13534
Jouni Malinen228a2fc2020-06-22 23:37:45 +030013535 val = get_param(cmd, "WaitCompletion");
13536 if (val && atoi(val) == 1) {
13537 ctrl = open_wpa_mon(intf);
13538 if (!ctrl) {
13539 send_resp(dut, conn, SIGMA_ERROR,
13540 "errorCode,Failed to open monitor socket");
13541 return STATUS_SENT_ERROR;
13542 }
13543 }
13544
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080013545 res = snprintf(buf, sizeof(buf), "SCAN%s%s%s%s%s%s%s",
vamsi krishna89ad8c62017-09-19 12:51:18 +053013546 bssid ? " bssid=": "",
13547 bssid ? bssid : "",
13548 ssid ? " ssid " : "",
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080013549 ssid ? ssid_hex : "",
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080013550 wildcard_ssid ? " wildcard_ssid=1" : "",
13551 scan_freq ? " freq=" : "",
13552 scan_freq ? scan_freq : "");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013553 if (res < 0 || res >= (int) sizeof(buf)) {
13554 send_resp(dut, conn, SIGMA_ERROR,
13555 "errorCode,Could not build scan command");
13556 status = STATUS_SENT_ERROR;
13557 goto remove_s_ssid;
13558 }
vamsi krishna89ad8c62017-09-19 12:51:18 +053013559
13560 if (wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013561 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not start "
13562 "scan");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013563 status = STATUS_SENT_ERROR;
13564 } else {
13565 status = SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013566 }
13567
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013568remove_s_ssid:
13569 if (short_ssid && wpa_command(intf, "VENDOR_ELEM_REMOVE 14 *"))
13570 sigma_dut_print(dut, DUT_MSG_ERROR,
13571 "Failed to delete vendor element");
13572
Jouni Malinen228a2fc2020-06-22 23:37:45 +030013573 if (ctrl) {
13574 if (status == SUCCESS_SEND_STATUS) {
13575 res = get_wpa_cli_event(dut, ctrl,
13576 "CTRL-EVENT-SCAN-RESULTS",
13577 buf, sizeof(buf));
13578 if (res < 0) {
13579 send_resp(dut, conn, SIGMA_ERROR,
13580 "ErrorCode,scan did not complete");
13581 status = STATUS_SENT_ERROR;
13582 }
13583 }
13584
13585 wpa_ctrl_detach(ctrl);
13586 wpa_ctrl_close(ctrl);
13587 }
13588
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013589 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013590}
13591
13592
Jouni Malinenf7222712019-06-13 01:50:21 +030013593static enum sigma_cmd_result cmd_sta_scan_bss(struct sigma_dut *dut,
13594 struct sigma_conn *conn,
13595 struct sigma_cmd *cmd)
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020013596{
13597 const char *intf = get_param(cmd, "Interface");
13598 const char *bssid;
13599 char buf[4096], *pos;
13600 int freq, chan;
13601 char *ssid;
13602 char resp[100];
13603 int res;
13604 struct wpa_ctrl *ctrl;
13605
13606 bssid = get_param(cmd, "BSSID");
13607 if (!bssid) {
13608 send_resp(dut, conn, SIGMA_INVALID,
13609 "errorCode,BSSID argument is missing");
13610 return 0;
13611 }
13612
13613 ctrl = open_wpa_mon(intf);
13614 if (!ctrl) {
13615 sigma_dut_print(dut, DUT_MSG_ERROR,
13616 "Failed to open wpa_supplicant monitor connection");
13617 return -1;
13618 }
13619
13620 if (wpa_command(intf, "SCAN TYPE=ONLY")) {
13621 send_resp(dut, conn, SIGMA_ERROR,
13622 "errorCode,Could not start scan");
13623 wpa_ctrl_detach(ctrl);
13624 wpa_ctrl_close(ctrl);
13625 return 0;
13626 }
13627
13628 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
13629 buf, sizeof(buf));
13630
13631 wpa_ctrl_detach(ctrl);
13632 wpa_ctrl_close(ctrl);
13633
13634 if (res < 0) {
13635 send_resp(dut, conn, SIGMA_ERROR,
13636 "errorCode,Scan did not complete");
13637 return 0;
13638 }
13639
13640 snprintf(buf, sizeof(buf), "BSS %s", bssid);
13641 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
13642 strncmp(buf, "id=", 3) != 0) {
13643 send_resp(dut, conn, SIGMA_ERROR,
13644 "errorCode,Specified BSSID not found");
13645 return 0;
13646 }
13647
13648 pos = strstr(buf, "\nfreq=");
13649 if (!pos) {
13650 send_resp(dut, conn, SIGMA_ERROR,
13651 "errorCode,Channel not found");
13652 return 0;
13653 }
13654 freq = atoi(pos + 6);
13655 chan = freq_to_channel(freq);
13656
13657 pos = strstr(buf, "\nssid=");
13658 if (!pos) {
13659 send_resp(dut, conn, SIGMA_ERROR,
13660 "errorCode,SSID not found");
13661 return 0;
13662 }
13663 ssid = pos + 6;
13664 pos = strchr(ssid, '\n');
13665 if (pos)
13666 *pos = '\0';
13667 snprintf(resp, sizeof(resp), "ssid,%s,bsschannel,%d", ssid, chan);
13668 send_resp(dut, conn, SIGMA_COMPLETE, resp);
13669 return 0;
13670}
13671
13672
Jouni Malinenf7222712019-06-13 01:50:21 +030013673static enum sigma_cmd_result cmd_sta_set_systime(struct sigma_dut *dut,
13674 struct sigma_conn *conn,
13675 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013676{
13677#ifdef __linux__
13678 struct timeval tv;
13679 struct tm tm;
13680 time_t t;
13681 const char *val;
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053013682 int v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013683
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013684 wpa_command(get_station_ifname(dut), "PMKSA_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013685
13686 memset(&tm, 0, sizeof(tm));
13687 val = get_param(cmd, "seconds");
13688 if (val)
13689 tm.tm_sec = atoi(val);
13690 val = get_param(cmd, "minutes");
13691 if (val)
13692 tm.tm_min = atoi(val);
13693 val = get_param(cmd, "hours");
13694 if (val)
13695 tm.tm_hour = atoi(val);
13696 val = get_param(cmd, "date");
13697 if (val)
13698 tm.tm_mday = atoi(val);
13699 val = get_param(cmd, "month");
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053013700 if (val) {
13701 v = atoi(val);
13702 if (v < 1 || v > 12) {
13703 send_resp(dut, conn, SIGMA_INVALID,
13704 "errorCode,Invalid month");
13705 return 0;
13706 }
13707 tm.tm_mon = v - 1;
13708 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013709 val = get_param(cmd, "year");
13710 if (val) {
13711 int year = atoi(val);
13712#ifdef ANDROID
13713 if (year > 2035)
13714 year = 2035; /* years beyond 2035 not supported */
13715#endif /* ANDROID */
13716 tm.tm_year = year - 1900;
13717 }
13718 t = mktime(&tm);
13719 if (t == (time_t) -1) {
13720 send_resp(dut, conn, SIGMA_ERROR,
13721 "errorCode,Invalid date or time");
13722 return 0;
13723 }
13724
13725 memset(&tv, 0, sizeof(tv));
13726 tv.tv_sec = t;
13727
13728 if (settimeofday(&tv, NULL) < 0) {
13729 sigma_dut_print(dut, DUT_MSG_INFO, "settimeofday failed: %s",
13730 strerror(errno));
13731 send_resp(dut, conn, SIGMA_ERROR,
13732 "errorCode,Failed to set time");
13733 return 0;
13734 }
13735
13736 return 1;
13737#endif /* __linux__ */
13738
13739 return -1;
13740}
13741
13742
Jouni Malinenf7222712019-06-13 01:50:21 +030013743static enum sigma_cmd_result cmd_sta_osu(struct sigma_dut *dut,
13744 struct sigma_conn *conn,
13745 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013746{
13747 const char *intf = get_param(cmd, "Interface");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013748 const char *name, *osu_ssid, *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013749 int prod_ess_assoc = 1;
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013750 char buf[300], bssid[100], ssid[100];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013751 int res;
13752 struct wpa_ctrl *ctrl;
13753
13754 name = get_param(cmd, "osuFriendlyName");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013755 osu_ssid = get_param(cmd, "osu_ssid");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013756
13757 val = get_param(cmd, "ProdESSAssoc");
13758 if (val)
13759 prod_ess_assoc = atoi(val);
13760
13761 kill_dhcp_client(dut, intf);
13762 if (start_dhcp_client(dut, intf) < 0)
13763 return -2;
13764
13765 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger OSU");
13766 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
13767 res = snprintf(buf, sizeof(buf),
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013768 "%s %s%s%s %s%s%s signup osu-ca.pem",
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013769 prod_ess_assoc ? "" : "-N",
13770 name ? "-O'" : "", name ? name : "",
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013771 name ? "'" : "",
13772 osu_ssid ? "-o'" : "", osu_ssid ? osu_ssid : "",
13773 osu_ssid ? "'" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013774
Kanchanapally, Vidyullatha12b66762015-12-31 16:46:42 +053013775 hs2_set_policy(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013776 if (run_hs20_osu(dut, buf) < 0) {
13777 FILE *f;
13778
13779 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to complete OSU");
13780
13781 f = fopen("hs20-osu-client.res", "r");
13782 if (f) {
13783 char resp[400], res[300], *pos;
13784 if (!fgets(res, sizeof(res), f))
13785 res[0] = '\0';
13786 pos = strchr(res, '\n');
13787 if (pos)
13788 *pos = '\0';
13789 fclose(f);
13790 sigma_dut_summary(dut, "hs20-osu-client provisioning failed: %s",
13791 res);
13792 snprintf(resp, sizeof(resp), "notify-send '%s'", res);
13793 if (system(resp) != 0) {
13794 }
13795 snprintf(resp, sizeof(resp),
13796 "SSID,,BSSID,,failureReason,%s", res);
13797 send_resp(dut, conn, SIGMA_COMPLETE, resp);
13798 return 0;
13799 }
13800
13801 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
13802 return 0;
13803 }
13804
13805 if (!prod_ess_assoc)
13806 goto report;
13807
13808 ctrl = open_wpa_mon(intf);
13809 if (ctrl == NULL) {
13810 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
13811 "wpa_supplicant monitor connection");
13812 return -1;
13813 }
13814
13815 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
13816 buf, sizeof(buf));
13817
13818 wpa_ctrl_detach(ctrl);
13819 wpa_ctrl_close(ctrl);
13820
13821 if (res < 0) {
13822 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to connect to "
13823 "network after OSU");
13824 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
13825 return 0;
13826 }
13827
13828report:
13829 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
13830 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
13831 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get BSSID/SSID");
13832 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
13833 return 0;
13834 }
13835
13836 snprintf(buf, sizeof(buf), "SSID,%s,BSSID,%s", ssid, bssid);
13837 send_resp(dut, conn, SIGMA_COMPLETE, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013838 return 0;
13839}
13840
13841
Jouni Malinenf7222712019-06-13 01:50:21 +030013842static enum sigma_cmd_result cmd_sta_policy_update(struct sigma_dut *dut,
13843 struct sigma_conn *conn,
13844 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013845{
13846 const char *val;
13847 int timeout = 120;
13848
13849 val = get_param(cmd, "PolicyUpdate");
13850 if (val == NULL || atoi(val) == 0)
13851 return 1; /* No operation requested */
13852
13853 val = get_param(cmd, "Timeout");
13854 if (val)
13855 timeout = atoi(val);
13856
13857 if (timeout) {
13858 /* TODO: time out the command and return
13859 * PolicyUpdateStatus,TIMEOUT if needed. */
13860 }
13861
13862 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger policy update");
13863 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
13864 if (run_hs20_osu(dut, "pol_upd fqdn=wi-fi.org") < 0) {
13865 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,FAIL");
13866 return 0;
13867 }
13868
13869 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,SUCCESS");
13870 return 0;
13871}
13872
13873
Jouni Malinenf7222712019-06-13 01:50:21 +030013874static enum sigma_cmd_result cmd_sta_er_config(struct sigma_dut *dut,
13875 struct sigma_conn *conn,
13876 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013877{
13878 struct wpa_ctrl *ctrl;
13879 const char *intf = get_param(cmd, "Interface");
13880 const char *bssid = get_param(cmd, "Bssid");
13881 const char *ssid = get_param(cmd, "SSID");
13882 const char *security = get_param(cmd, "Security");
13883 const char *passphrase = get_param(cmd, "Passphrase");
13884 const char *pin = get_param(cmd, "PIN");
13885 char buf[1000];
13886 char ssid_hex[200], passphrase_hex[200];
13887 const char *keymgmt, *cipher;
13888
13889 if (intf == NULL)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013890 intf = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013891
13892 if (!bssid) {
13893 send_resp(dut, conn, SIGMA_ERROR,
13894 "ErrorCode,Missing Bssid argument");
13895 return 0;
13896 }
13897
13898 if (!ssid) {
13899 send_resp(dut, conn, SIGMA_ERROR,
13900 "ErrorCode,Missing SSID argument");
13901 return 0;
13902 }
13903
13904 if (!security) {
13905 send_resp(dut, conn, SIGMA_ERROR,
13906 "ErrorCode,Missing Security argument");
13907 return 0;
13908 }
13909
13910 if (!passphrase) {
13911 send_resp(dut, conn, SIGMA_ERROR,
13912 "ErrorCode,Missing Passphrase argument");
13913 return 0;
13914 }
13915
13916 if (!pin) {
13917 send_resp(dut, conn, SIGMA_ERROR,
13918 "ErrorCode,Missing PIN argument");
13919 return 0;
13920 }
13921
vamsi krishna8c9c1562017-05-12 15:51:46 +053013922 if (2 * strlen(ssid) >= sizeof(ssid_hex) ||
13923 2 * strlen(passphrase) >= sizeof(passphrase_hex)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013924 send_resp(dut, conn, SIGMA_ERROR,
13925 "ErrorCode,Too long SSID/passphrase");
13926 return 0;
13927 }
13928
13929 ctrl = open_wpa_mon(intf);
13930 if (ctrl == NULL) {
13931 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
13932 "wpa_supplicant monitor connection");
13933 return -2;
13934 }
13935
13936 if (strcasecmp(security, "wpa2-psk") == 0) {
13937 keymgmt = "WPA2PSK";
13938 cipher = "CCMP";
13939 } else {
13940 wpa_ctrl_detach(ctrl);
13941 wpa_ctrl_close(ctrl);
13942 send_resp(dut, conn, SIGMA_ERROR,
13943 "ErrorCode,Unsupported Security value");
13944 return 0;
13945 }
13946
13947 ascii2hexstr(ssid, ssid_hex);
13948 ascii2hexstr(passphrase, passphrase_hex);
13949 snprintf(buf, sizeof(buf), "WPS_REG %s %s %s %s %s %s",
13950 bssid, pin, ssid_hex, keymgmt, cipher, passphrase_hex);
13951
13952 if (wpa_command(intf, buf) < 0) {
13953 wpa_ctrl_detach(ctrl);
13954 wpa_ctrl_close(ctrl);
13955 send_resp(dut, conn, SIGMA_ERROR,
13956 "ErrorCode,Failed to start registrar");
13957 return 0;
13958 }
13959
13960 snprintf(dut->er_oper_bssid, sizeof(dut->er_oper_bssid), "%s", bssid);
13961 dut->er_oper_performed = 1;
13962
13963 return wps_connection_event(dut, conn, ctrl, intf, 0);
13964}
13965
13966
Jouni Malinenf7222712019-06-13 01:50:21 +030013967static enum sigma_cmd_result
13968cmd_sta_wps_connect_pw_token(struct sigma_dut *dut, struct sigma_conn *conn,
13969 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013970{
13971 struct wpa_ctrl *ctrl;
13972 const char *intf = get_param(cmd, "Interface");
13973 const char *bssid = get_param(cmd, "Bssid");
13974 char buf[100];
13975
13976 if (!bssid) {
13977 send_resp(dut, conn, SIGMA_ERROR,
13978 "ErrorCode,Missing Bssid argument");
13979 return 0;
13980 }
13981
13982 ctrl = open_wpa_mon(intf);
13983 if (ctrl == NULL) {
13984 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
13985 "wpa_supplicant monitor connection");
13986 return -2;
13987 }
13988
13989 snprintf(buf, sizeof(buf), "WPS_NFC %s", bssid);
13990
13991 if (wpa_command(intf, buf) < 0) {
13992 wpa_ctrl_detach(ctrl);
13993 wpa_ctrl_close(ctrl);
13994 send_resp(dut, conn, SIGMA_ERROR,
13995 "ErrorCode,Failed to start registrar");
13996 return 0;
13997 }
13998
13999 return wps_connection_event(dut, conn, ctrl, intf, 0);
14000}
14001
14002
Jouni Malinenf7222712019-06-13 01:50:21 +030014003static enum sigma_cmd_result cmd_start_wps_registration(struct sigma_dut *dut,
14004 struct sigma_conn *conn,
14005 struct sigma_cmd *cmd)
vamsi krishna9b144002017-09-20 13:28:13 +053014006{
14007 struct wpa_ctrl *ctrl;
14008 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020014009 const char *network_mode = get_param(cmd, "network_mode");
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020014010 const char *config_method = get_param(cmd, "WPSConfigMethod");
14011 const char *role;
vamsi krishna9b144002017-09-20 13:28:13 +053014012 int res;
14013 char buf[256];
14014 const char *events[] = {
14015 "CTRL-EVENT-CONNECTED",
14016 "WPS-OVERLAP-DETECTED",
14017 "WPS-TIMEOUT",
14018 "WPS-FAIL",
14019 NULL
14020 };
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020014021 int id = 0;
vamsi krishna9b144002017-09-20 13:28:13 +053014022
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020014023 /* 60G WPS tests do not pass Interface parameter */
14024 if (!intf)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020014025 intf = get_main_ifname(dut);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020014026
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020014027 if (dut->mode == SIGMA_MODE_AP)
14028 return ap_wps_registration(dut, conn, cmd);
14029
14030 if (config_method) {
14031 /* WFA_CS_WPS_PIN_KEYPAD mode is set when using the
14032 * sta_wps_enter_pin before calling start_wps_registration. */
14033 if (strcasecmp(config_method, "PBC") == 0)
14034 dut->wps_method = WFA_CS_WPS_PBC;
14035 }
14036 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
14037 send_resp(dut, conn, SIGMA_ERROR,
14038 "ErrorCode,WPS parameters not yet set");
14039 return STATUS_SENT;
14040 }
14041
14042 /* Make sure WPS is enabled (also for STA mode) */
14043 dut->wps_disable = 0;
14044
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020014045 if (dut->band == WPS_BAND_60G && network_mode &&
14046 strcasecmp(network_mode, "PBSS") == 0) {
14047 sigma_dut_print(dut, DUT_MSG_DEBUG,
14048 "Set PBSS network mode, network id %d", id);
Jouni Malinen016ae6c2019-11-04 17:00:01 +020014049 if (set_network(get_station_ifname(dut), id, "pbss", "1") < 0)
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020014050 return -2;
14051 }
14052
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020014053 if (dut->force_rsn_ie) {
14054 sigma_dut_print(dut, DUT_MSG_DEBUG, "Force RSN_IE: %d",
14055 dut->force_rsn_ie);
14056 if (sta_60g_force_rsn_ie(dut, dut->force_rsn_ie) < 0) {
14057 sigma_dut_print(dut, DUT_MSG_INFO,
14058 "Failed to force RSN_IE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020014059 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020014060 }
14061 }
14062
vamsi krishna9b144002017-09-20 13:28:13 +053014063 ctrl = open_wpa_mon(intf);
14064 if (!ctrl) {
14065 sigma_dut_print(dut, DUT_MSG_ERROR,
14066 "Failed to open wpa_supplicant monitor connection");
14067 return -2;
14068 }
14069
14070 role = get_param(cmd, "WpsRole");
14071 if (!role) {
14072 send_resp(dut, conn, SIGMA_INVALID,
14073 "ErrorCode,WpsRole not provided");
14074 goto fail;
14075 }
14076
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020014077 if (strcasecmp(role, "Enrollee") != 0) {
14078 /* Registrar role for STA not supported */
14079 send_resp(dut, conn, SIGMA_ERROR,
14080 "ErrorCode,Unsupported WpsRole value");
14081 goto fail;
14082 }
14083
14084 if (is_60g_sigma_dut(dut)) {
14085 if (dut->wps_method == WFA_CS_WPS_PBC)
14086 snprintf(buf, sizeof(buf), "WPS_PBC");
14087 else /* WFA_CS_WPS_PIN_KEYPAD */
14088 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
14089 dut->wps_pin);
14090 if (wpa_command(intf, buf) < 0) {
14091 send_resp(dut, conn, SIGMA_ERROR,
14092 "ErrorCode,Failed to start WPS");
vamsi krishna9b144002017-09-20 13:28:13 +053014093 goto fail;
14094 }
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020014095 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
14096 if (res < 0) {
14097 send_resp(dut, conn, SIGMA_ERROR,
14098 "ErrorCode,WPS connection did not complete");
14099 goto fail;
14100 }
14101 if (strstr(buf, "WPS-TIMEOUT")) {
14102 send_resp(dut, conn, SIGMA_COMPLETE, "WpsState,NoPeer");
14103 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
14104 send_resp(dut, conn, SIGMA_COMPLETE,
14105 "WpsState,OverlapSession");
14106 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
14107 send_resp(dut, conn, SIGMA_COMPLETE,
14108 "WpsState,Successful");
14109 } else {
14110 send_resp(dut, conn, SIGMA_COMPLETE,
14111 "WpsState,Failure");
14112 }
14113 } else {
14114 if (dut->wps_method == WFA_CS_WPS_PBC) {
vamsi krishna9b144002017-09-20 13:28:13 +053014115 if (wpa_command(intf, "WPS_PBC") < 0) {
14116 send_resp(dut, conn, SIGMA_ERROR,
14117 "ErrorCode,Failed to enable PBC");
14118 goto fail;
14119 }
14120 } else {
14121 /* TODO: PIN method */
14122 send_resp(dut, conn, SIGMA_ERROR,
14123 "ErrorCode,Unsupported WpsConfigMethod value");
14124 goto fail;
14125 }
14126 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
14127 if (res < 0) {
14128 send_resp(dut, conn, SIGMA_ERROR,
14129 "ErrorCode,WPS connection did not complete");
14130 goto fail;
14131 }
14132 if (strstr(buf, "WPS-TIMEOUT")) {
14133 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,NoPeer");
14134 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
14135 send_resp(dut, conn, SIGMA_ERROR,
14136 "ErrorCode,OverlapSession");
14137 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
14138 send_resp(dut, conn, SIGMA_COMPLETE, "Successful");
14139 } else {
14140 send_resp(dut, conn, SIGMA_ERROR,
14141 "ErrorCode,WPS operation failed");
14142 }
vamsi krishna9b144002017-09-20 13:28:13 +053014143 }
14144
14145fail:
14146 wpa_ctrl_detach(ctrl);
14147 wpa_ctrl_close(ctrl);
14148 return 0;
14149}
14150
14151
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014152static int req_intf(struct sigma_cmd *cmd)
14153{
14154 return get_param(cmd, "interface") == NULL ? -1 : 0;
14155}
14156
14157
14158void sta_register_cmds(void)
14159{
14160 sigma_dut_reg_cmd("sta_get_ip_config", req_intf,
14161 cmd_sta_get_ip_config);
14162 sigma_dut_reg_cmd("sta_set_ip_config", req_intf,
14163 cmd_sta_set_ip_config);
14164 sigma_dut_reg_cmd("sta_get_info", req_intf, cmd_sta_get_info);
14165 sigma_dut_reg_cmd("sta_get_mac_address", req_intf,
14166 cmd_sta_get_mac_address);
14167 sigma_dut_reg_cmd("sta_is_connected", req_intf, cmd_sta_is_connected);
14168 sigma_dut_reg_cmd("sta_verify_ip_connection", req_intf,
14169 cmd_sta_verify_ip_connection);
14170 sigma_dut_reg_cmd("sta_get_bssid", req_intf, cmd_sta_get_bssid);
14171 sigma_dut_reg_cmd("sta_set_encryption", req_intf,
14172 cmd_sta_set_encryption);
14173 sigma_dut_reg_cmd("sta_set_psk", req_intf, cmd_sta_set_psk);
14174 sigma_dut_reg_cmd("sta_set_eaptls", req_intf, cmd_sta_set_eaptls);
14175 sigma_dut_reg_cmd("sta_set_eapttls", req_intf, cmd_sta_set_eapttls);
14176 sigma_dut_reg_cmd("sta_set_eapsim", req_intf, cmd_sta_set_eapsim);
14177 sigma_dut_reg_cmd("sta_set_peap", req_intf, cmd_sta_set_peap);
14178 sigma_dut_reg_cmd("sta_set_eapfast", req_intf, cmd_sta_set_eapfast);
14179 sigma_dut_reg_cmd("sta_set_eapaka", req_intf, cmd_sta_set_eapaka);
14180 sigma_dut_reg_cmd("sta_set_eapakaprime", req_intf,
14181 cmd_sta_set_eapakaprime);
14182 sigma_dut_reg_cmd("sta_set_security", req_intf, cmd_sta_set_security);
14183 sigma_dut_reg_cmd("sta_set_uapsd", req_intf, cmd_sta_set_uapsd);
14184 /* TODO: sta_set_ibss */
14185 /* TODO: sta_set_mode */
14186 sigma_dut_reg_cmd("sta_set_wmm", req_intf, cmd_sta_set_wmm);
14187 sigma_dut_reg_cmd("sta_associate", req_intf, cmd_sta_associate);
14188 /* TODO: sta_up_load */
14189 sigma_dut_reg_cmd("sta_preset_testparameters", req_intf,
14190 cmd_sta_preset_testparameters);
14191 /* TODO: sta_set_system */
14192 sigma_dut_reg_cmd("sta_set_11n", req_intf, cmd_sta_set_11n);
14193 /* TODO: sta_set_rifs_test */
14194 sigma_dut_reg_cmd("sta_set_wireless", req_intf, cmd_sta_set_wireless);
14195 sigma_dut_reg_cmd("sta_send_addba", req_intf, cmd_sta_send_addba);
14196 /* TODO: sta_send_coexist_mgmt */
14197 sigma_dut_reg_cmd("sta_disconnect", req_intf, cmd_sta_disconnect);
14198 sigma_dut_reg_cmd("sta_reassoc", req_intf, cmd_sta_reassoc);
14199 sigma_dut_reg_cmd("sta_reassociate", req_intf, cmd_sta_reassoc);
14200 sigma_dut_reg_cmd("sta_reset_default", req_intf,
14201 cmd_sta_reset_default);
14202 sigma_dut_reg_cmd("sta_send_frame", req_intf, cmd_sta_send_frame);
14203 sigma_dut_reg_cmd("sta_set_macaddr", req_intf, cmd_sta_set_macaddr);
14204 sigma_dut_reg_cmd("sta_set_rfeature", req_intf, cmd_sta_set_rfeature);
14205 sigma_dut_reg_cmd("sta_set_radio", req_intf, cmd_sta_set_radio);
14206 sigma_dut_reg_cmd("sta_set_pwrsave", req_intf, cmd_sta_set_pwrsave);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020014207 sigma_dut_reg_cmd("sta_set_power_save", req_intf, cmd_sta_set_pwrsave);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014208 sigma_dut_reg_cmd("sta_bssid_pool", req_intf, cmd_sta_bssid_pool);
14209 sigma_dut_reg_cmd("sta_reset_parm", req_intf, cmd_sta_reset_parm);
14210 sigma_dut_reg_cmd("sta_get_key", req_intf, cmd_sta_get_key);
14211 sigma_dut_reg_cmd("sta_hs2_associate", req_intf,
14212 cmd_sta_hs2_associate);
Jouni Malinenb639f1c2018-09-13 02:39:46 +030014213 sigma_dut_reg_cmd("sta_hs2_venue_info", req_intf,
14214 cmd_sta_hs2_venue_info);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014215 sigma_dut_reg_cmd("sta_add_credential", req_intf,
14216 cmd_sta_add_credential);
14217 sigma_dut_reg_cmd("sta_scan", req_intf, cmd_sta_scan);
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020014218 sigma_dut_reg_cmd("sta_scan_bss", req_intf, cmd_sta_scan_bss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014219 sigma_dut_reg_cmd("sta_set_systime", NULL, cmd_sta_set_systime);
14220 sigma_dut_reg_cmd("sta_osu", req_intf, cmd_sta_osu);
14221 sigma_dut_reg_cmd("sta_policy_update", req_intf, cmd_sta_policy_update);
14222 sigma_dut_reg_cmd("sta_er_config", NULL, cmd_sta_er_config);
14223 sigma_dut_reg_cmd("sta_wps_connect_pw_token", req_intf,
14224 cmd_sta_wps_connect_pw_token);
Jouni Malinen82905202018-04-29 17:20:10 +030014225 sigma_dut_reg_cmd("sta_exec_action", NULL, cmd_sta_exec_action);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014226 sigma_dut_reg_cmd("sta_get_events", req_intf, cmd_sta_get_events);
14227 sigma_dut_reg_cmd("sta_get_parameter", req_intf, cmd_sta_get_parameter);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020014228 sigma_dut_reg_cmd("start_wps_registration", NULL,
vamsi krishna9b144002017-09-20 13:28:13 +053014229 cmd_start_wps_registration);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014230}