blob: 690740f1dce0ffdc373790cd57b3ded759b22afc [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
Veerendranath Jakkama9177042020-08-10 00:14:03 +05302309 val = get_param(cmd, "sae_pk_only");
2310 if (val && strcmp(val, "1") == 0 &&
2311 set_network(ifname, id, "sae_pk", "1") < 0)
2312 return ERROR_SEND_STATUS;
2313
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002314 if (dut->program == PROGRAM_60GHZ && network_mode &&
2315 strcasecmp(network_mode, "PBSS") == 0 &&
2316 set_network(ifname, id, "pbss", "1") < 0)
2317 return -2;
2318
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002319 return 1;
2320}
2321
2322
Jouni Malinen8ac93452019-08-14 15:19:13 +03002323static enum sigma_cmd_result set_trust_root_system(struct sigma_dut *dut,
2324 struct sigma_conn *conn,
2325 const char *ifname, int id)
2326{
2327 char buf[200];
2328
2329 snprintf(buf, sizeof(buf), "%s/certs", sigma_cert_path);
2330 if (!file_exists(buf))
2331 strlcpy(buf, "/system/etc/security/cacerts", sizeof(buf));
2332 if (!file_exists(buf))
2333 strlcpy(buf, "/etc/ssl/certs", sizeof(buf));
2334 if (!file_exists(buf)) {
2335 char msg[300];
2336
2337 snprintf(msg, sizeof(msg),
2338 "ErrorCode,trustedRootCA system store (%s) not found",
2339 buf);
2340 send_resp(dut, conn, SIGMA_ERROR, msg);
2341 return STATUS_SENT_ERROR;
2342 }
2343
2344 if (set_network_quoted(ifname, id, "ca_path", buf) < 0)
2345 return ERROR_SEND_STATUS;
2346
2347 return SUCCESS_SEND_STATUS;
2348}
2349
2350
2351static enum sigma_cmd_result set_trust_root(struct sigma_dut *dut,
2352 struct sigma_conn *conn,
2353 const char *ifname, int id,
2354 const char *val)
2355{
2356 char buf[200];
2357#ifdef ANDROID
2358 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
2359 int length;
2360#endif /* ANDROID */
2361
2362 if (strcmp(val, "DEFAULT") == 0)
2363 return set_trust_root_system(dut, conn, ifname, id);
2364
2365#ifdef ANDROID
2366 snprintf(buf, sizeof(buf), "CACERT_%s", val);
2367 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
2368 if (length > 0) {
2369 sigma_dut_print(dut, DUT_MSG_INFO, "Use Android keystore [%s]",
2370 buf);
2371 snprintf(buf, sizeof(buf), "keystore://CACERT_%s", val);
2372 goto ca_cert_selected;
2373 }
2374#endif /* ANDROID */
2375
2376 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
2377#ifdef __linux__
2378 if (!file_exists(buf)) {
2379 char msg[300];
2380
2381 snprintf(msg, sizeof(msg),
2382 "ErrorCode,trustedRootCA file (%s) not found", buf);
2383 send_resp(dut, conn, SIGMA_ERROR, msg);
2384 return STATUS_SENT_ERROR;
2385 }
2386#endif /* __linux__ */
2387#ifdef ANDROID
2388ca_cert_selected:
2389#endif /* ANDROID */
2390 if (set_network_quoted(ifname, id, "ca_cert", buf) < 0)
2391 return ERROR_SEND_STATUS;
2392
2393 return SUCCESS_SEND_STATUS;
2394}
2395
2396
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002397static int set_eap_common(struct sigma_dut *dut, struct sigma_conn *conn,
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302398 const char *ifname, int username_identity,
2399 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002400{
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002401 const char *val, *alg, *akm, *trust_root, *domain, *domain_suffix;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002402 int id;
Jouni Malinen53264f62019-05-03 13:04:40 +03002403 char buf[200], buf2[300];
Jouni Malinen8179fee2019-03-28 03:19:47 +02002404 int erp = 0;
Jouni Malinen8ac93452019-08-14 15:19:13 +03002405 enum sigma_cmd_result res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002406
2407 id = set_wpa_common(dut, conn, ifname, cmd);
2408 if (id < 0)
2409 return id;
2410
2411 val = get_param(cmd, "keyMgmtType");
2412 alg = get_param(cmd, "micAlg");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302413 akm = get_param(cmd, "AKMSuiteType");
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002414 trust_root = get_param(cmd, "trustedRootCA");
2415 domain = get_param(cmd, "Domain");
2416 domain_suffix = get_param(cmd, "DomainSuffix");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002417
Jouni Malinenad395a22017-09-01 21:13:46 +03002418 if (val && strcasecmp(val, "SuiteB") == 0) {
2419 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SUITE-B-192") <
2420 0)
2421 return -2;
2422 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002423 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SHA256") < 0)
2424 return -2;
2425 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
2426 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
2427 return -2;
2428 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
2429 if (set_network(ifname, id, "key_mgmt", "FT-EAP") < 0)
2430 return -2;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002431 } else if (!akm &&
2432 ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
2433 dut->sta_pmf == STA_PMF_REQUIRED)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002434 if (set_network(ifname, id, "key_mgmt",
2435 "WPA-EAP WPA-EAP-SHA256") < 0)
2436 return -2;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302437 } else if (akm && atoi(akm) == 14) {
2438 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
2439 dut->sta_pmf == STA_PMF_REQUIRED) {
2440 if (set_network(ifname, id, "key_mgmt",
2441 "WPA-EAP-SHA256 FILS-SHA256") < 0)
2442 return -2;
2443 } else {
2444 if (set_network(ifname, id, "key_mgmt",
2445 "WPA-EAP FILS-SHA256") < 0)
2446 return -2;
2447 }
2448
Jouni Malinen8179fee2019-03-28 03:19:47 +02002449 erp = 1;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302450 } else if (akm && atoi(akm) == 15) {
2451 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
2452 dut->sta_pmf == STA_PMF_REQUIRED) {
2453 if (set_network(ifname, id, "key_mgmt",
2454 "WPA-EAP-SHA256 FILS-SHA384") < 0)
2455 return -2;
2456 } else {
2457 if (set_network(ifname, id, "key_mgmt",
2458 "WPA-EAP FILS-SHA384") < 0)
2459 return -2;
2460 }
2461
Jouni Malinen8179fee2019-03-28 03:19:47 +02002462 erp = 1;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002463 } else if (!akm && dut->sta_pmf == STA_PMF_OPTIONAL) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002464 if (set_network(ifname, id, "key_mgmt",
2465 "WPA-EAP WPA-EAP-SHA256") < 0)
2466 return -2;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002467 } else if (!akm) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002468 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
2469 return -2;
2470 }
2471
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002472 if (trust_root) {
2473 if (strcmp(trust_root, "DEFAULT") == 0 && !domain &&
2474 !domain_suffix) {
2475 send_resp(dut, conn, SIGMA_ERROR,
2476 "errorCode,trustRootCA DEFAULT used without specifying Domain or DomainSuffix");
2477 return STATUS_SENT_ERROR;
2478 }
2479 res = set_trust_root(dut, conn, ifname, id, trust_root);
Jouni Malinen8ac93452019-08-14 15:19:13 +03002480 if (res != SUCCESS_SEND_STATUS)
2481 return res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002482 }
2483
Jouni Malinen53264f62019-05-03 13:04:40 +03002484 val = get_param(cmd, "ServerCert");
2485 if (val) {
2486 FILE *f;
2487 char *result = NULL, *pos;
2488
2489 snprintf(buf, sizeof(buf), "%s/%s.sha256", sigma_cert_path,
2490 val);
2491 f = fopen(buf, "r");
2492 if (f) {
2493 result = fgets(buf, sizeof(buf), f);
2494 fclose(f);
2495 }
2496 if (!result) {
2497 snprintf(buf2, sizeof(buf2),
2498 "ErrorCode,ServerCert hash could not be read from %s",
2499 buf);
2500 send_resp(dut, conn, SIGMA_ERROR, buf2);
2501 return STATUS_SENT_ERROR;
2502 }
2503 pos = strchr(buf, '\n');
2504 if (pos)
2505 *pos = '\0';
Jouni Malinen0572a742020-10-08 13:53:25 +03002506 pos = strchr(buf, '\r');
2507 if (pos)
2508 *pos = '\0';
Jouni Malinen53264f62019-05-03 13:04:40 +03002509 snprintf(buf2, sizeof(buf2), "hash://server/sha256/%s", buf);
2510 if (set_network_quoted(ifname, id, "ca_cert", buf2) < 0)
2511 return ERROR_SEND_STATUS;
Jouni Malinen29108dc2019-06-13 23:42:11 +03002512
2513 snprintf(buf, sizeof(buf), "%s/%s.tod", sigma_cert_path, val);
2514 if (file_exists(buf)) {
2515 sigma_dut_print(dut, DUT_MSG_DEBUG,
2516 "TOD policy enabled for the configured ServerCert hash");
2517 dut->sta_tod_policy = 1;
2518 }
Jouni Malinen53264f62019-05-03 13:04:40 +03002519 }
2520
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002521 if (domain &&
2522 set_network_quoted(ifname, id, "domain_match", domain) < 0)
Jouni Malinen96f84b02019-05-03 12:32:56 +03002523 return ERROR_SEND_STATUS;
2524
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002525 if (domain_suffix &&
2526 set_network_quoted(ifname, id, "domain_suffix_match",
2527 domain_suffix) < 0)
Jouni Malinen96f84b02019-05-03 12:32:56 +03002528 return ERROR_SEND_STATUS;
2529
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302530 if (username_identity) {
2531 val = get_param(cmd, "username");
2532 if (val) {
2533 if (set_network_quoted(ifname, id, "identity", val) < 0)
2534 return -2;
2535 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002536
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302537 val = get_param(cmd, "password");
2538 if (val) {
2539 if (set_network_quoted(ifname, id, "password", val) < 0)
2540 return -2;
2541 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002542 }
2543
Jouni Malinen8179fee2019-03-28 03:19:47 +02002544 if (dut->akm_values &
2545 ((1 << AKM_FILS_SHA256) |
2546 (1 << AKM_FILS_SHA384) |
2547 (1 << AKM_FT_FILS_SHA256) |
2548 (1 << AKM_FT_FILS_SHA384)))
2549 erp = 1;
2550 if (erp && set_network(ifname, id, "erp", "1") < 0)
2551 return ERROR_SEND_STATUS;
2552
Jouni Malinen134fe3c2019-06-12 04:16:49 +03002553 dut->sta_associate_wait_connect = 1;
2554
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002555 return id;
2556}
2557
2558
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002559static int set_tls_cipher(const char *ifname, int id, const char *cipher)
2560{
2561 const char *val;
2562
2563 if (!cipher)
2564 return 0;
2565
2566 if (strcasecmp(cipher, "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384") == 0)
2567 val = "ECDHE-ECDSA-AES256-GCM-SHA384";
2568 else if (strcasecmp(cipher,
2569 "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
2570 val = "ECDHE-RSA-AES256-GCM-SHA384";
2571 else if (strcasecmp(cipher, "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
2572 val = "DHE-RSA-AES256-GCM-SHA384";
2573 else if (strcasecmp(cipher,
2574 "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256") == 0)
2575 val = "ECDHE-ECDSA-AES128-GCM-SHA256";
2576 else
2577 return -1;
2578
2579 /* Need to clear phase1="tls_suiteb=1" to allow cipher enforcement */
2580 set_network_quoted(ifname, id, "phase1", "");
2581
2582 return set_network_quoted(ifname, id, "openssl_ciphers", val);
2583}
2584
2585
Jouni Malinenf7222712019-06-13 01:50:21 +03002586static enum sigma_cmd_result cmd_sta_set_eaptls(struct sigma_dut *dut,
2587 struct sigma_conn *conn,
2588 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002589{
2590 const char *intf = get_param(cmd, "Interface");
2591 const char *ifname, *val;
2592 int id;
2593 char buf[200];
2594#ifdef ANDROID
2595 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
2596 int length;
2597 int jb_or_newer = 0;
2598 char prop[PROPERTY_VALUE_MAX];
2599#endif /* ANDROID */
2600
2601 if (intf == NULL)
2602 return -1;
2603
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002604 if (strcmp(intf, get_main_ifname(dut)) == 0)
2605 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002606 else
2607 ifname = intf;
2608
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302609 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002610 if (id < 0)
2611 return id;
2612
2613 if (set_network(ifname, id, "eap", "TLS") < 0)
2614 return -2;
2615
Pradeep Reddy POTTETI9f6c2132016-05-05 16:28:19 +05302616 if (!get_param(cmd, "username") &&
2617 set_network_quoted(ifname, id, "identity",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002618 "wifi-user@wifilabs.local") < 0)
2619 return -2;
2620
2621 val = get_param(cmd, "clientCertificate");
2622 if (val == NULL)
2623 return -1;
2624#ifdef ANDROID
2625 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2626 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
2627 if (length < 0) {
2628 /*
2629 * JB started reporting keystore type mismatches, so retry with
2630 * the GET_PUBKEY command if the generic GET fails.
2631 */
2632 length = android_keystore_get(ANDROID_KEYSTORE_GET_PUBKEY,
2633 buf, kvalue);
2634 }
2635
2636 if (property_get("ro.build.version.release", prop, NULL) != 0) {
2637 sigma_dut_print(dut, DUT_MSG_DEBUG, "Android release %s", prop);
2638 if (strncmp(prop, "4.0", 3) != 0)
2639 jb_or_newer = 1;
2640 } else
2641 jb_or_newer = 1; /* assume newer */
2642
2643 if (jb_or_newer && length > 0) {
2644 sigma_dut_print(dut, DUT_MSG_INFO,
2645 "Use Android keystore [%s]", buf);
2646 if (set_network(ifname, id, "engine", "1") < 0)
2647 return -2;
2648 if (set_network_quoted(ifname, id, "engine_id", "keystore") < 0)
2649 return -2;
2650 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2651 if (set_network_quoted(ifname, id, "key_id", buf) < 0)
2652 return -2;
2653 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2654 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2655 return -2;
2656 return 1;
2657 } else if (length > 0) {
2658 sigma_dut_print(dut, DUT_MSG_INFO,
2659 "Use Android keystore [%s]", buf);
2660 snprintf(buf, sizeof(buf), "keystore://USRPKEY_%s", val);
2661 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2662 return -2;
2663 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2664 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2665 return -2;
2666 return 1;
2667 }
2668#endif /* ANDROID */
2669
2670 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
2671#ifdef __linux__
2672 if (!file_exists(buf)) {
2673 char msg[300];
2674 snprintf(msg, sizeof(msg), "ErrorCode,clientCertificate file "
2675 "(%s) not found", buf);
2676 send_resp(dut, conn, SIGMA_ERROR, msg);
2677 return -3;
2678 }
2679#endif /* __linux__ */
2680 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2681 return -2;
2682 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2683 return -2;
2684
2685 if (set_network_quoted(ifname, id, "private_key_passwd", "wifi") < 0)
2686 return -2;
2687
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002688 val = get_param(cmd, "keyMgmtType");
2689 if (val && strcasecmp(val, "SuiteB") == 0) {
2690 val = get_param(cmd, "CertType");
2691 if (val && strcasecmp(val, "RSA") == 0) {
2692 if (set_network_quoted(ifname, id, "phase1",
2693 "tls_suiteb=1") < 0)
2694 return -2;
2695 } else {
2696 if (set_network_quoted(ifname, id, "openssl_ciphers",
2697 "SUITEB192") < 0)
2698 return -2;
2699 }
2700
2701 val = get_param(cmd, "TLSCipher");
2702 if (set_tls_cipher(ifname, id, val) < 0) {
2703 send_resp(dut, conn, SIGMA_ERROR,
2704 "ErrorCode,Unsupported TLSCipher value");
2705 return -3;
2706 }
2707 }
2708
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002709 return 1;
2710}
2711
2712
Jouni Malinenf7222712019-06-13 01:50:21 +03002713static enum sigma_cmd_result cmd_sta_set_eapttls(struct sigma_dut *dut,
2714 struct sigma_conn *conn,
2715 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002716{
2717 const char *intf = get_param(cmd, "Interface");
2718 const char *ifname;
2719 int id;
2720
2721 if (intf == NULL)
2722 return -1;
2723
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002724 if (strcmp(intf, get_main_ifname(dut)) == 0)
2725 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002726 else
2727 ifname = intf;
2728
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302729 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002730 if (id < 0)
2731 return id;
2732
2733 if (set_network(ifname, id, "eap", "TTLS") < 0) {
2734 send_resp(dut, conn, SIGMA_ERROR,
2735 "errorCode,Failed to set TTLS method");
2736 return 0;
2737 }
2738
2739 if (set_network_quoted(ifname, id, "phase2", "auth=MSCHAPV2") < 0) {
2740 send_resp(dut, conn, SIGMA_ERROR,
2741 "errorCode,Failed to set MSCHAPv2 for TTLS Phase 2");
2742 return 0;
2743 }
2744
2745 return 1;
2746}
2747
2748
Jouni Malinenf7222712019-06-13 01:50:21 +03002749static enum sigma_cmd_result cmd_sta_set_eapsim(struct sigma_dut *dut,
2750 struct sigma_conn *conn,
2751 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002752{
2753 const char *intf = get_param(cmd, "Interface");
2754 const char *ifname;
2755 int id;
2756
2757 if (intf == NULL)
2758 return -1;
2759
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002760 if (strcmp(intf, get_main_ifname(dut)) == 0)
2761 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002762 else
2763 ifname = intf;
2764
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302765 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002766 if (id < 0)
2767 return id;
2768
2769 if (set_network(ifname, id, "eap", "SIM") < 0)
2770 return -2;
2771
2772 return 1;
2773}
2774
2775
Jouni Malinenf7222712019-06-13 01:50:21 +03002776static enum sigma_cmd_result cmd_sta_set_peap(struct sigma_dut *dut,
2777 struct sigma_conn *conn,
2778 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002779{
2780 const char *intf = get_param(cmd, "Interface");
2781 const char *ifname, *val;
2782 int id;
2783 char buf[100];
2784
2785 if (intf == NULL)
2786 return -1;
2787
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002788 if (strcmp(intf, get_main_ifname(dut)) == 0)
2789 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002790 else
2791 ifname = intf;
2792
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302793 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002794 if (id < 0)
2795 return id;
2796
2797 if (set_network(ifname, id, "eap", "PEAP") < 0)
2798 return -2;
2799
2800 val = get_param(cmd, "innerEAP");
2801 if (val) {
2802 if (strcasecmp(val, "MSCHAPv2") == 0) {
2803 if (set_network_quoted(ifname, id, "phase2",
2804 "auth=MSCHAPV2") < 0)
2805 return -2;
2806 } else if (strcasecmp(val, "GTC") == 0) {
2807 if (set_network_quoted(ifname, id, "phase2",
2808 "auth=GTC") < 0)
2809 return -2;
2810 } else
2811 return -1;
2812 }
2813
2814 val = get_param(cmd, "peapVersion");
2815 if (val) {
2816 int ver = atoi(val);
2817 if (ver < 0 || ver > 1)
2818 return -1;
2819 snprintf(buf, sizeof(buf), "peapver=%d", ver);
2820 if (set_network_quoted(ifname, id, "phase1", buf) < 0)
2821 return -2;
2822 }
2823
2824 return 1;
2825}
2826
2827
Jouni Malinenf7222712019-06-13 01:50:21 +03002828static enum sigma_cmd_result cmd_sta_set_eapfast(struct sigma_dut *dut,
2829 struct sigma_conn *conn,
2830 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002831{
2832 const char *intf = get_param(cmd, "Interface");
2833 const char *ifname, *val;
2834 int id;
2835 char buf[100];
2836
2837 if (intf == NULL)
2838 return -1;
2839
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002840 if (strcmp(intf, get_main_ifname(dut)) == 0)
2841 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002842 else
2843 ifname = intf;
2844
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302845 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002846 if (id < 0)
2847 return id;
2848
2849 if (set_network(ifname, id, "eap", "FAST") < 0)
2850 return -2;
2851
2852 val = get_param(cmd, "innerEAP");
2853 if (val) {
2854 if (strcasecmp(val, "MSCHAPV2") == 0) {
2855 if (set_network_quoted(ifname, id, "phase2",
2856 "auth=MSCHAPV2") < 0)
2857 return -2;
2858 } else if (strcasecmp(val, "GTC") == 0) {
2859 if (set_network_quoted(ifname, id, "phase2",
2860 "auth=GTC") < 0)
2861 return -2;
2862 } else
2863 return -1;
2864 }
2865
2866 val = get_param(cmd, "validateServer");
2867 if (val) {
2868 /* TODO */
2869 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored EAP-FAST "
2870 "validateServer=%s", val);
2871 }
2872
2873 val = get_param(cmd, "pacFile");
2874 if (val) {
2875 snprintf(buf, sizeof(buf), "blob://%s", val);
2876 if (set_network_quoted(ifname, id, "pac_file", buf) < 0)
2877 return -2;
2878 }
2879
2880 if (set_network_quoted(ifname, id, "phase1", "fast_provisioning=2") <
2881 0)
2882 return -2;
2883
2884 return 1;
2885}
2886
2887
Jouni Malinenf7222712019-06-13 01:50:21 +03002888static enum sigma_cmd_result cmd_sta_set_eapaka(struct sigma_dut *dut,
2889 struct sigma_conn *conn,
2890 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002891{
2892 const char *intf = get_param(cmd, "Interface");
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302893 const char *username = get_param(cmd, "Username");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002894 const char *ifname;
2895 int id;
2896
2897 if (intf == NULL)
2898 return -1;
2899
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002900 if (strcmp(intf, get_main_ifname(dut)) == 0)
2901 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002902 else
2903 ifname = intf;
2904
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302905 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002906 if (id < 0)
2907 return id;
2908
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302909 /* RFC 5448: EAP-AKA' MUST use the leading character "6" (ASCII 36
2910 * hexadecimal).
2911 */
2912 if (username && username[0] == '6') {
2913 if (set_network(ifname, id, "eap", "AKA'") < 0)
2914 return -2;
2915 } else if (set_network(ifname, id, "eap", "AKA") < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002916 return -2;
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302917 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002918
2919 return 1;
2920}
2921
2922
Jouni Malinenf7222712019-06-13 01:50:21 +03002923static enum sigma_cmd_result cmd_sta_set_eapakaprime(struct sigma_dut *dut,
2924 struct sigma_conn *conn,
2925 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002926{
2927 const char *intf = get_param(cmd, "Interface");
2928 const char *ifname;
2929 int id;
2930
2931 if (intf == NULL)
2932 return -1;
2933
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002934 if (strcmp(intf, get_main_ifname(dut)) == 0)
2935 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002936 else
2937 ifname = intf;
2938
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302939 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002940 if (id < 0)
2941 return id;
2942
2943 if (set_network(ifname, id, "eap", "AKA'") < 0)
2944 return -2;
2945
2946 return 1;
2947}
2948
2949
2950static int sta_set_open(struct sigma_dut *dut, struct sigma_conn *conn,
2951 struct sigma_cmd *cmd)
2952{
2953 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002954 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002955 const char *ifname;
2956 int id;
2957
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002958 if (strcmp(intf, get_main_ifname(dut)) == 0)
2959 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002960 else
2961 ifname = intf;
2962
2963 id = add_network_common(dut, conn, ifname, cmd);
2964 if (id < 0)
2965 return id;
2966
2967 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
2968 return -2;
2969
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002970 if (dut->program == PROGRAM_60GHZ && network_mode &&
2971 strcasecmp(network_mode, "PBSS") == 0 &&
2972 set_network(ifname, id, "pbss", "1") < 0)
2973 return -2;
2974
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002975 return 1;
2976}
2977
2978
Jouni Malinen8e3f8812020-10-05 10:02:03 +03002979static enum sigma_cmd_result sta_set_owe(struct sigma_dut *dut,
2980 struct sigma_conn *conn,
2981 struct sigma_cmd *cmd)
Jouni Malinen47dcc952017-10-09 16:43:24 +03002982{
2983 const char *intf = get_param(cmd, "Interface");
2984 const char *ifname, *val;
2985 int id;
2986
2987 if (intf == NULL)
Jouni Malinen8e3f8812020-10-05 10:02:03 +03002988 return INVALID_SEND_STATUS;
Jouni Malinen47dcc952017-10-09 16:43:24 +03002989
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002990 if (strcmp(intf, get_main_ifname(dut)) == 0)
2991 ifname = get_station_ifname(dut);
Jouni Malinen47dcc952017-10-09 16:43:24 +03002992 else
2993 ifname = intf;
2994
2995 id = set_wpa_common(dut, conn, ifname, cmd);
2996 if (id < 0)
2997 return id;
2998
2999 if (set_network(ifname, id, "key_mgmt", "OWE") < 0)
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003000 return ERROR_SEND_STATUS;
Jouni Malinen47dcc952017-10-09 16:43:24 +03003001
Hu Wangdd5eed22020-07-16 12:18:03 +08003002 if (dut->owe_ptk_workaround &&
3003 set_network(ifname, id, "owe_ptk_workaround", "1") < 0) {
3004 sigma_dut_print(dut, DUT_MSG_ERROR,
3005 "Failed to set owe_ptk_workaround to 1");
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003006 return ERROR_SEND_STATUS;
Hu Wangdd5eed22020-07-16 12:18:03 +08003007 }
3008
Jouni Malinen47dcc952017-10-09 16:43:24 +03003009 val = get_param(cmd, "ECGroupID");
Jouni Malinenfac9cad2017-10-10 18:35:55 +03003010 if (val && strcmp(val, "0") == 0) {
3011 if (wpa_command(ifname,
3012 "VENDOR_ELEM_ADD 13 ff23200000783590fb7440e03d5b3b33911f86affdcc6b4411b707846ac4ff08ddc8831ccd") != 0) {
3013 sigma_dut_print(dut, DUT_MSG_ERROR,
3014 "Failed to set OWE DH Param element override");
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003015 return ERROR_SEND_STATUS;
Jouni Malinenfac9cad2017-10-10 18:35:55 +03003016 }
Hu Wangdd5eed22020-07-16 12:18:03 +08003017 } else if (val && set_network(ifname, id, "owe_group", val) < 0) {
Jouni Malinen47dcc952017-10-09 16:43:24 +03003018 sigma_dut_print(dut, DUT_MSG_ERROR,
Hu Wang6010ce72020-03-05 19:33:53 +08003019 "Failed to set owe_group");
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003020 return ERROR_SEND_STATUS;
Jouni Malinen47dcc952017-10-09 16:43:24 +03003021 }
3022
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003023 return SUCCESS_SEND_STATUS;
Jouni Malinen47dcc952017-10-09 16:43:24 +03003024}
3025
3026
Jouni Malinenf7222712019-06-13 01:50:21 +03003027static enum sigma_cmd_result cmd_sta_set_security(struct sigma_dut *dut,
3028 struct sigma_conn *conn,
3029 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003030{
3031 const char *type = get_param(cmd, "Type");
3032
3033 if (type == NULL) {
3034 send_resp(dut, conn, SIGMA_ERROR,
3035 "ErrorCode,Missing Type argument");
3036 return 0;
3037 }
3038
3039 if (strcasecmp(type, "OPEN") == 0)
3040 return sta_set_open(dut, conn, cmd);
Jouni Malinen47dcc952017-10-09 16:43:24 +03003041 if (strcasecmp(type, "OWE") == 0)
3042 return sta_set_owe(dut, conn, cmd);
Jouni Malinen992a81e2017-08-22 13:57:47 +03003043 if (strcasecmp(type, "PSK") == 0 ||
Jouni Malinen0ab50f42017-08-31 01:34:59 +03003044 strcasecmp(type, "PSK-SAE") == 0 ||
Jouni Malinen992a81e2017-08-22 13:57:47 +03003045 strcasecmp(type, "SAE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003046 return cmd_sta_set_psk(dut, conn, cmd);
3047 if (strcasecmp(type, "EAPTLS") == 0)
3048 return cmd_sta_set_eaptls(dut, conn, cmd);
3049 if (strcasecmp(type, "EAPTTLS") == 0)
3050 return cmd_sta_set_eapttls(dut, conn, cmd);
3051 if (strcasecmp(type, "EAPPEAP") == 0)
3052 return cmd_sta_set_peap(dut, conn, cmd);
3053 if (strcasecmp(type, "EAPSIM") == 0)
3054 return cmd_sta_set_eapsim(dut, conn, cmd);
3055 if (strcasecmp(type, "EAPFAST") == 0)
3056 return cmd_sta_set_eapfast(dut, conn, cmd);
3057 if (strcasecmp(type, "EAPAKA") == 0)
3058 return cmd_sta_set_eapaka(dut, conn, cmd);
3059 if (strcasecmp(type, "EAPAKAPRIME") == 0)
3060 return cmd_sta_set_eapakaprime(dut, conn, cmd);
Amarnath Hullur Subramanyam81b11cd2018-01-30 19:07:17 -08003061 if (strcasecmp(type, "wep") == 0)
3062 return cmd_sta_set_encryption(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003063
3064 send_resp(dut, conn, SIGMA_ERROR,
3065 "ErrorCode,Unsupported Type value");
3066 return 0;
3067}
3068
3069
3070int ath6kl_client_uapsd(struct sigma_dut *dut, const char *intf, int uapsd)
3071{
3072#ifdef __linux__
3073 /* special handling for ath6kl */
3074 char path[128], fname[128], *pos;
3075 ssize_t res;
3076 FILE *f;
3077
Jouni Malinene39cd562019-05-29 23:39:56 +03003078 res = snprintf(fname, sizeof(fname), "/sys/class/net/%s/phy80211",
3079 intf);
3080 if (res < 0 || res >= sizeof(fname))
3081 return 0;
3082 res = readlink(fname, path, sizeof(path));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003083 if (res < 0)
3084 return 0; /* not ath6kl */
3085
3086 if (res >= (int) sizeof(path))
3087 res = sizeof(path) - 1;
3088 path[res] = '\0';
3089 pos = strrchr(path, '/');
3090 if (pos == NULL)
3091 pos = path;
3092 else
3093 pos++;
Jouni Malinen77dda642020-01-07 11:21:55 +02003094 res = snprintf(fname, sizeof(fname),
3095 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
3096 "create_qos", pos);
3097 if (res < 0 || res >= sizeof(fname) || !file_exists(fname))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003098 return 0; /* not ath6kl */
3099
3100 if (uapsd) {
3101 f = fopen(fname, "w");
3102 if (f == NULL)
3103 return -1;
3104
3105 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl create_qos");
3106 fprintf(f, "4 2 2 1 2 9999999 9999999 9999999 7777777 0 4 "
3107 "45000 200 56789000 56789000 5678900 0 0 9999999 "
3108 "20000 0\n");
3109 fclose(f);
3110 } else {
Jouni Malinen77dda642020-01-07 11:21:55 +02003111 res = snprintf(fname, sizeof(fname),
3112 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
3113 "delete_qos", pos);
3114 if (res < 0 || res >= sizeof(fname))
3115 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003116
3117 f = fopen(fname, "w");
3118 if (f == NULL)
3119 return -1;
3120
3121 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl delete_qos");
3122 fprintf(f, "2 4\n");
3123 fclose(f);
3124 }
3125#endif /* __linux__ */
3126
3127 return 0;
3128}
3129
3130
Jouni Malinenf7222712019-06-13 01:50:21 +03003131static enum sigma_cmd_result cmd_sta_set_uapsd(struct sigma_dut *dut,
3132 struct sigma_conn *conn,
3133 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003134{
3135 const char *intf = get_param(cmd, "Interface");
3136 /* const char *ssid = get_param(cmd, "ssid"); */
3137 const char *val;
3138 int max_sp_len = 4;
3139 int ac_be = 1, ac_bk = 1, ac_vi = 1, ac_vo = 1;
3140 char buf[100];
3141 int ret1, ret2;
3142
3143 val = get_param(cmd, "maxSPLength");
3144 if (val) {
3145 max_sp_len = atoi(val);
3146 if (max_sp_len != 0 && max_sp_len != 1 && max_sp_len != 2 &&
3147 max_sp_len != 4)
3148 return -1;
3149 }
3150
3151 val = get_param(cmd, "acBE");
3152 if (val)
3153 ac_be = atoi(val);
3154
3155 val = get_param(cmd, "acBK");
3156 if (val)
3157 ac_bk = atoi(val);
3158
3159 val = get_param(cmd, "acVI");
3160 if (val)
3161 ac_vi = atoi(val);
3162
3163 val = get_param(cmd, "acVO");
3164 if (val)
3165 ac_vo = atoi(val);
3166
3167 dut->client_uapsd = ac_be || ac_bk || ac_vi || ac_vo;
3168
3169 snprintf(buf, sizeof(buf), "P2P_SET client_apsd %d,%d,%d,%d;%d",
3170 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
3171 ret1 = wpa_command(intf, buf);
3172
3173 snprintf(buf, sizeof(buf), "SET uapsd %d,%d,%d,%d;%d",
3174 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
3175 ret2 = wpa_command(intf, buf);
3176
3177 if (ret1 && ret2) {
3178 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to set client mode "
3179 "UAPSD parameters.");
3180 return -2;
3181 }
3182
3183 if (ath6kl_client_uapsd(dut, intf, dut->client_uapsd) < 0) {
3184 send_resp(dut, conn, SIGMA_ERROR,
3185 "ErrorCode,Failed to set ath6kl QoS parameters");
3186 return 0;
3187 }
3188
3189 return 1;
3190}
3191
3192
Jouni Malinenf7222712019-06-13 01:50:21 +03003193static enum sigma_cmd_result cmd_sta_set_wmm(struct sigma_dut *dut,
3194 struct sigma_conn *conn,
3195 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003196{
3197 char buf[1000];
3198 const char *intf = get_param(cmd, "Interface");
3199 const char *grp = get_param(cmd, "Group");
3200 const char *act = get_param(cmd, "Action");
3201 const char *tid = get_param(cmd, "Tid");
3202 const char *dir = get_param(cmd, "Direction");
3203 const char *psb = get_param(cmd, "Psb");
3204 const char *up = get_param(cmd, "Up");
3205 const char *fixed = get_param(cmd, "Fixed");
3206 const char *size = get_param(cmd, "Size");
3207 const char *msize = get_param(cmd, "Maxsize");
3208 const char *minsi = get_param(cmd, "Min_srvc_intrvl");
3209 const char *maxsi = get_param(cmd, "Max_srvc_intrvl");
3210 const char *inact = get_param(cmd, "Inactivity");
3211 const char *sus = get_param(cmd, "Suspension");
3212 const char *mindr = get_param(cmd, "Mindatarate");
3213 const char *meandr = get_param(cmd, "Meandatarate");
3214 const char *peakdr = get_param(cmd, "Peakdatarate");
3215 const char *phyrate = get_param(cmd, "Phyrate");
3216 const char *burstsize = get_param(cmd, "Burstsize");
3217 const char *sba = get_param(cmd, "Sba");
3218 int direction;
3219 int handle;
Peng Xu93319622017-10-04 17:58:16 -07003220 float sba_fv = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003221 int fixed_int;
3222 int psb_ts;
3223
3224 if (intf == NULL || grp == NULL || act == NULL )
3225 return -1;
3226
3227 if (strcasecmp(act, "addts") == 0) {
3228 if (tid == NULL || dir == NULL || psb == NULL ||
3229 up == NULL || fixed == NULL || size == NULL)
3230 return -1;
3231
3232 /*
3233 * Note: Sigma CAPI spec lists uplink, downlink, and bidi as the
3234 * possible values, but WMM-AC and V-E test scripts use "UP,
3235 * "DOWN", and "BIDI".
3236 */
3237 if (strcasecmp(dir, "uplink") == 0 ||
3238 strcasecmp(dir, "up") == 0) {
3239 direction = 0;
3240 } else if (strcasecmp(dir, "downlink") == 0 ||
3241 strcasecmp(dir, "down") == 0) {
3242 direction = 1;
3243 } else if (strcasecmp(dir, "bidi") == 0) {
3244 direction = 2;
3245 } else {
3246 sigma_dut_print(dut, DUT_MSG_ERROR,
3247 "Direction %s not supported", dir);
3248 return -1;
3249 }
3250
3251 if (strcasecmp(psb, "legacy") == 0) {
3252 psb_ts = 0;
3253 } else if (strcasecmp(psb, "uapsd") == 0) {
3254 psb_ts = 1;
3255 } else {
3256 sigma_dut_print(dut, DUT_MSG_ERROR,
3257 "PSB %s not supported", psb);
3258 return -1;
3259 }
3260
3261 if (atoi(tid) < 0 || atoi(tid) > 7) {
3262 sigma_dut_print(dut, DUT_MSG_ERROR,
3263 "TID %s not supported", tid);
3264 return -1;
3265 }
3266
3267 if (strcasecmp(fixed, "true") == 0) {
3268 fixed_int = 1;
3269 } else {
3270 fixed_int = 0;
3271 }
3272
Peng Xu93319622017-10-04 17:58:16 -07003273 if (sba)
3274 sba_fv = atof(sba);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003275
3276 dut->dialog_token++;
3277 handle = 7000 + dut->dialog_token;
3278
3279 /*
3280 * size: convert to hex
3281 * maxsi: convert to hex
3282 * mindr: convert to hex
3283 * meandr: convert to hex
3284 * peakdr: convert to hex
3285 * burstsize: convert to hex
3286 * phyrate: convert to hex
3287 * sba: convert to hex with modification
3288 * minsi: convert to integer
3289 * sus: convert to integer
3290 * inact: convert to integer
3291 * maxsi: convert to integer
3292 */
3293
3294 /*
3295 * The Nominal MSDU Size field is 2 octets long and contains an
3296 * unsigned integer that specifies the nominal size, in octets,
3297 * of MSDUs belonging to the traffic under this traffic
3298 * specification and is defined in Figure 16. If the Fixed
3299 * subfield is set to 1, then the size of the MSDU is fixed and
3300 * is indicated by the Size Subfield. If the Fixed subfield is
3301 * set to 0, then the size of the MSDU might not be fixed and
3302 * the Size indicates the nominal MSDU size.
3303 *
3304 * The Surplus Bandwidth Allowance Factor field is 2 octets long
3305 * and specifies the excess allocation of time (and bandwidth)
3306 * over and above the stated rates required to transport an MSDU
3307 * belonging to the traffic in this TSPEC. This field is
3308 * represented as an unsigned binary number with an implicit
3309 * binary point after the leftmost 3 bits. For example, an SBA
3310 * of 1.75 is represented as 0x3800. This field is included to
3311 * account for retransmissions. As such, the value of this field
3312 * must be greater than unity.
3313 */
3314
3315 snprintf(buf, sizeof(buf),
3316 "iwpriv %s addTspec %d %s %d %d %s 0x%X"
3317 " 0x%X 0x%X 0x%X"
3318 " 0x%X 0x%X 0x%X"
3319 " 0x%X %d %d %d %d"
3320 " %d %d",
3321 intf, handle, tid, direction, psb_ts, up,
3322 (unsigned int) ((fixed_int << 15) | atoi(size)),
3323 msize ? atoi(msize) : 0,
3324 mindr ? atoi(mindr) : 0,
3325 meandr ? atoi(meandr) : 0,
3326 peakdr ? atoi(peakdr) : 0,
3327 burstsize ? atoi(burstsize) : 0,
3328 phyrate ? atoi(phyrate) : 0,
3329 sba ? ((unsigned int) (((int) sba_fv << 13) |
3330 (int)((sba_fv - (int) sba_fv) *
3331 8192))) : 0,
3332 minsi ? atoi(minsi) : 0,
3333 sus ? atoi(sus) : 0,
3334 0, 0,
3335 inact ? atoi(inact) : 0,
3336 maxsi ? atoi(maxsi) : 0);
3337
3338 if (system(buf) != 0) {
3339 sigma_dut_print(dut, DUT_MSG_ERROR,
3340 "iwpriv addtspec request failed");
3341 send_resp(dut, conn, SIGMA_ERROR,
3342 "errorCode,Failed to execute addTspec command");
3343 return 0;
3344 }
3345
3346 sigma_dut_print(dut, DUT_MSG_INFO,
3347 "iwpriv addtspec request send");
3348
3349 /* Mapping handle to a TID */
3350 dut->tid_to_handle[atoi(tid)] = handle;
3351 } else if (strcasecmp(act, "delts") == 0) {
3352 if (tid == NULL)
3353 return -1;
3354
3355 if (atoi(tid) < 0 || atoi(tid) > 7) {
3356 sigma_dut_print(dut, DUT_MSG_ERROR,
3357 "TID %s not supported", tid);
3358 send_resp(dut, conn, SIGMA_ERROR,
3359 "errorCode,Unsupported TID");
3360 return 0;
3361 }
3362
3363 handle = dut->tid_to_handle[atoi(tid)];
3364
3365 if (handle < 7000 || handle > 7255) {
3366 /* Invalid handle ie no mapping for that TID */
3367 sigma_dut_print(dut, DUT_MSG_ERROR,
3368 "handle-> %d not found", handle);
3369 }
3370
3371 snprintf(buf, sizeof(buf), "iwpriv %s delTspec %d",
3372 intf, handle);
3373
3374 if (system(buf) != 0) {
3375 sigma_dut_print(dut, DUT_MSG_ERROR,
3376 "iwpriv deltspec request failed");
3377 send_resp(dut, conn, SIGMA_ERROR,
3378 "errorCode,Failed to execute delTspec command");
3379 return 0;
3380 }
3381
3382 sigma_dut_print(dut, DUT_MSG_INFO,
3383 "iwpriv deltspec request send");
3384
3385 dut->tid_to_handle[atoi(tid)] = 0;
3386 } else {
3387 sigma_dut_print(dut, DUT_MSG_ERROR,
3388 "Action type %s not supported", act);
3389 send_resp(dut, conn, SIGMA_ERROR,
3390 "errorCode,Unsupported Action");
3391 return 0;
3392 }
3393
3394 return 1;
3395}
3396
3397
vamsi krishna52e16f92017-08-29 12:37:34 +05303398static int find_network(struct sigma_dut *dut, const char *ssid)
3399{
3400 char list[4096];
3401 char *pos;
3402
3403 sigma_dut_print(dut, DUT_MSG_DEBUG,
3404 "Search for profile based on SSID: '%s'", ssid);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003405 if (wpa_command_resp(get_station_ifname(dut), "LIST_NETWORKS",
vamsi krishna52e16f92017-08-29 12:37:34 +05303406 list, sizeof(list)) < 0)
3407 return -1;
3408 pos = strstr(list, ssid);
3409 if (!pos || pos == list || pos[-1] != '\t' || pos[strlen(ssid)] != '\t')
3410 return -1;
3411
3412 while (pos > list && pos[-1] != '\n')
3413 pos--;
3414 dut->infra_network_id = atoi(pos);
3415 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
3416 return 0;
3417}
3418
3419
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303420/**
3421 * enum qca_sta_helper_config_params - This helper enum defines the config
3422 * parameters which can be delivered to sta.
3423 */
3424enum qca_sta_helper_config_params {
3425 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE */
3426 STA_SET_RSNIE,
3427
3428 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_LDPC */
3429 STA_SET_LDPC,
3430
3431 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_TX_STBC */
3432 STA_SET_TX_STBC,
3433
3434 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_RX_STBC */
3435 STA_SET_RX_STBC,
3436
3437 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_TX_MSDU_AGGREGATION */
3438 STA_SET_TX_MSDU,
3439
3440 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_RX_MSDU_AGGREGATION */
3441 STA_SET_RX_MSDU,
3442};
3443
3444
3445static int sta_config_params(struct sigma_dut *dut, const char *intf,
3446 enum qca_sta_helper_config_params config_cmd,
3447 int value)
Sunil Dutt44595082018-02-12 19:41:45 +05303448{
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303449#ifdef NL80211_SUPPORT
Sunil Dutt44595082018-02-12 19:41:45 +05303450 struct nl_msg *msg;
3451 int ret;
3452 struct nlattr *params;
3453 int ifindex;
3454
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303455 ifindex = if_nametoindex(intf);
3456 if (ifindex == 0) {
3457 sigma_dut_print(dut, DUT_MSG_ERROR,
3458 "%s: Interface %s does not exist",
3459 __func__, intf);
3460 return -1;
3461 }
3462
Sunil Dutt44595082018-02-12 19:41:45 +05303463 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
3464 NL80211_CMD_VENDOR)) ||
3465 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
3466 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
3467 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
3468 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) ||
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303469 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)))
3470 goto fail;
3471
3472 switch (config_cmd) {
3473 case STA_SET_RSNIE:
3474 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE, value))
3475 goto fail;
3476 break;
3477 case STA_SET_LDPC:
3478 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_LDPC, value))
3479 goto fail;
3480 break;
3481 case STA_SET_TX_STBC:
3482 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TX_STBC, value))
3483 goto fail;
3484 break;
3485 case STA_SET_RX_STBC:
3486 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_RX_STBC, value))
3487 goto fail;
3488 break;
3489 case STA_SET_TX_MSDU:
3490 if (nla_put_u8(msg,
3491 QCA_WLAN_VENDOR_ATTR_CONFIG_TX_MSDU_AGGREGATION,
3492 value))
3493 goto fail;
3494 break;
3495 case STA_SET_RX_MSDU:
3496 if (nla_put_u8(msg,
3497 QCA_WLAN_VENDOR_ATTR_CONFIG_RX_MSDU_AGGREGATION,
3498 value))
3499 goto fail;
3500 break;
Sunil Dutt44595082018-02-12 19:41:45 +05303501 }
3502 nla_nest_end(msg, params);
3503
3504 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
3505 if (ret) {
3506 sigma_dut_print(dut, DUT_MSG_ERROR,
3507 "%s: err in send_and_recv_msgs, ret=%d",
3508 __func__, ret);
3509 return ret;
3510 }
3511
3512 return 0;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303513
3514fail:
3515 sigma_dut_print(dut, DUT_MSG_ERROR,
3516 "%s: err in adding vendor_cmd and vendor_data",
3517 __func__);
3518 nlmsg_free(msg);
Sunil Dutt44595082018-02-12 19:41:45 +05303519#endif /* NL80211_SUPPORT */
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303520 return -1;
3521}
Sunil Dutt44595082018-02-12 19:41:45 +05303522
3523
Jouni Malinenf7222712019-06-13 01:50:21 +03003524static enum sigma_cmd_result cmd_sta_associate(struct sigma_dut *dut,
3525 struct sigma_conn *conn,
3526 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003527{
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303528#ifdef NL80211_SUPPORT
3529 const char *intf = get_param(cmd, "Interface");
3530#endif /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003531 const char *ssid = get_param(cmd, "ssid");
3532 const char *wps_param = get_param(cmd, "WPS");
3533 const char *bssid = get_param(cmd, "bssid");
Jouni Malinen46a19b62017-06-23 14:31:27 +03003534 const char *chan = get_param(cmd, "channel");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003535 const char *network_mode = get_param(cmd, "network_mode");
Veerendranath Jakkama082e342020-05-16 00:19:21 +05303536 const char *ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003537 int wps = 0;
Jouni Malinen3c367e82017-06-23 17:01:47 +03003538 char buf[1000], extra[50];
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003539 int e;
3540 enum sigma_cmd_result ret = SUCCESS_SEND_STATUS;
3541 struct wpa_ctrl *ctrl = NULL;
3542 int num_network_not_found = 0;
3543 int num_disconnected = 0;
3544 int tod = -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003545
3546 if (ssid == NULL)
3547 return -1;
3548
Jouni Malinen37d5c692019-08-19 16:56:55 +03003549 dut->server_cert_tod = 0;
3550
Jouni Malinen3c367e82017-06-23 17:01:47 +03003551 if (dut->rsne_override) {
Sunil Dutt44595082018-02-12 19:41:45 +05303552#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003553 if (get_driver_type(dut) == DRIVER_WCN) {
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303554 sta_config_params(dut, intf, STA_SET_RSNIE, 1);
Sunil Dutt44595082018-02-12 19:41:45 +05303555 dut->config_rsnie = 1;
3556 }
3557#endif /* NL80211_SUPPORT */
Jouni Malinen3c367e82017-06-23 17:01:47 +03003558 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
3559 dut->rsne_override);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003560 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinen3c367e82017-06-23 17:01:47 +03003561 send_resp(dut, conn, SIGMA_ERROR,
3562 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
3563 return 0;
3564 }
3565 }
3566
Jouni Malinen68143132017-09-02 02:34:08 +03003567 if (dut->sae_commit_override) {
3568 snprintf(buf, sizeof(buf), "SET sae_commit_override %s",
3569 dut->sae_commit_override);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003570 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinen68143132017-09-02 02:34:08 +03003571 send_resp(dut, conn, SIGMA_ERROR,
3572 "ErrorCode,Failed to set SAE commit override");
3573 return 0;
3574 }
3575 }
Ankita Bajaj1bde7942018-01-09 19:15:01 +05303576#ifdef ANDROID
3577 if (dut->fils_hlp)
3578 process_fils_hlp(dut);
3579#endif /* ANDROID */
Jouni Malinen68143132017-09-02 02:34:08 +03003580
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003581 if (wps_param &&
3582 (strcmp(wps_param, "1") == 0 || strcasecmp(wps_param, "On") == 0))
3583 wps = 1;
3584
Vamsi Krishnac1633d22020-05-06 18:31:21 +05303585 if (dut->ocvc &&
3586 set_network(get_station_ifname(dut), dut->infra_network_id,
3587 "ocv", "1") < 0)
3588 return ERROR_SEND_STATUS;
3589
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003590 if (wps) {
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003591 if (dut->program == PROGRAM_60GHZ && network_mode &&
3592 strcasecmp(network_mode, "PBSS") == 0 &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003593 set_network(get_station_ifname(dut), dut->infra_network_id,
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003594 "pbss", "1") < 0)
3595 return -2;
3596
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003597 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
3598 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,WPS "
3599 "parameters not yet set");
3600 return 0;
3601 }
3602 if (dut->wps_method == WFA_CS_WPS_PBC) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003603 if (wpa_command(get_station_ifname(dut), "WPS_PBC") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003604 return -2;
3605 } else {
3606 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
3607 dut->wps_pin);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003608 if (wpa_command(get_station_ifname(dut), buf) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003609 return -2;
3610 }
3611 } else {
vamsi krishna52e16f92017-08-29 12:37:34 +05303612 if (strcmp(ssid, dut->infra_ssid) == 0) {
3613 sigma_dut_print(dut, DUT_MSG_DEBUG,
3614 "sta_associate for the most recently added network");
3615 } else if (find_network(dut, ssid) < 0) {
3616 sigma_dut_print(dut, DUT_MSG_DEBUG,
3617 "sta_associate for a previously stored network profile");
3618 send_resp(dut, conn, SIGMA_ERROR,
3619 "ErrorCode,Profile not found");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003620 return 0;
3621 }
3622
3623 if (bssid &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003624 set_network(get_station_ifname(dut), dut->infra_network_id,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003625 "bssid", bssid) < 0) {
3626 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3627 "Invalid bssid argument");
3628 return 0;
3629 }
3630
Veerendranath Jakkama082e342020-05-16 00:19:21 +05303631 if ((dut->program == PROGRAM_WPA3 &&
3632 dut->sta_associate_wait_connect) ||
3633 dut->program == PROGRAM_QM) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003634 ctrl = open_wpa_mon(get_station_ifname(dut));
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003635 if (!ctrl)
3636 return ERROR_SEND_STATUS;
3637 }
3638
Jouni Malinen46a19b62017-06-23 14:31:27 +03003639 extra[0] = '\0';
3640 if (chan)
3641 snprintf(extra, sizeof(extra), " freq=%u",
Alexei Avshalom Lazar093569f2018-11-13 14:08:17 +02003642 channel_to_freq(dut, atoi(chan)));
Jouni Malinen46a19b62017-06-23 14:31:27 +03003643 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d%s",
3644 dut->infra_network_id, extra);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003645 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003646 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to select "
3647 "network id %d on %s",
3648 dut->infra_network_id,
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003649 get_station_ifname(dut));
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003650 ret = ERROR_SEND_STATUS;
3651 goto done;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003652 }
3653 }
3654
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003655 if (!ctrl)
3656 return SUCCESS_SEND_STATUS;
3657
3658 /* Wait for connection result to be able to store server certificate
3659 * hash for trust root override testing
3660 * (dev_exec_action,ServerCertTrust). */
3661
3662 for (e = 0; e < 20; e++) {
3663 const char *events[] = {
3664 "CTRL-EVENT-EAP-PEER-CERT",
3665 "CTRL-EVENT-EAP-TLS-CERT-ERROR",
3666 "CTRL-EVENT-DISCONNECTED",
3667 "CTRL-EVENT-CONNECTED",
3668 "CTRL-EVENT-NETWORK-NOT-FOUND",
3669 NULL
3670 };
3671 char buf[1024];
3672 int res;
3673
3674 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
3675 if (res < 0) {
Jouni Malinenf1f16642019-11-15 21:19:04 +02003676 send_resp(dut, conn, SIGMA_COMPLETE,
3677 "Result,Association did not complete");
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003678 ret = STATUS_SENT_ERROR;
3679 break;
3680 }
3681 sigma_dut_print(dut, DUT_MSG_DEBUG, "Connection event: %s",
3682 buf);
3683
3684 if (strstr(buf, "CTRL-EVENT-EAP-PEER-CERT") &&
3685 strstr(buf, " depth=0")) {
3686 char *pos = strstr(buf, " hash=");
3687
3688 if (pos) {
3689 char *end;
3690
Jouni Malinen34b19cb2019-08-16 16:37:17 +03003691 if (strstr(buf, " tod=1"))
3692 tod = 1;
3693 else if (strstr(buf, " tod=2"))
3694 tod = 2;
3695 else
3696 tod = 0;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003697 sigma_dut_print(dut, DUT_MSG_DEBUG,
3698 "Server certificate TOD policy: %d",
3699 tod);
Jouni Malinen37d5c692019-08-19 16:56:55 +03003700 dut->server_cert_tod = tod;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003701
3702 pos += 6;
3703 end = strchr(pos, ' ');
3704 if (end)
3705 *end = '\0';
3706 strlcpy(dut->server_cert_hash, pos,
3707 sizeof(dut->server_cert_hash));
3708 sigma_dut_print(dut, DUT_MSG_DEBUG,
3709 "Server certificate hash: %s",
3710 dut->server_cert_hash);
3711 }
3712 }
3713
3714 if (strstr(buf, "CTRL-EVENT-EAP-TLS-CERT-ERROR")) {
3715 send_resp(dut, conn, SIGMA_COMPLETE,
3716 "Result,TLS server certificate validation failed");
3717 ret = STATUS_SENT_ERROR;
3718 break;
3719 }
3720
3721 if (strstr(buf, "CTRL-EVENT-NETWORK-NOT-FOUND")) {
3722 num_network_not_found++;
3723
3724 if (num_network_not_found > 2) {
3725 send_resp(dut, conn, SIGMA_COMPLETE,
3726 "Result,Network not found");
3727 ret = STATUS_SENT_ERROR;
3728 break;
3729 }
3730 }
3731
3732 if (strstr(buf, "CTRL-EVENT-DISCONNECTED")) {
3733 num_disconnected++;
3734
3735 if (num_disconnected > 2) {
3736 send_resp(dut, conn, SIGMA_COMPLETE,
3737 "Result,Connection failed");
3738 ret = STATUS_SENT_ERROR;
3739 break;
3740 }
3741 }
3742
3743 if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
3744 if (tod >= 0) {
3745 sigma_dut_print(dut, DUT_MSG_DEBUG,
3746 "Network profile TOD policy update: %d -> %d",
3747 dut->sta_tod_policy, tod);
3748 dut->sta_tod_policy = tod;
3749 }
Veerendranath Jakkama082e342020-05-16 00:19:21 +05303750 if (dut->program == PROGRAM_QM) {
3751 unsigned char iface_mac_addr[ETH_ALEN];
3752 char ipv6[100];
3753
3754 if (get_hwaddr(ifname, iface_mac_addr) < 0) {
3755 sigma_dut_print(dut, DUT_MSG_ERROR,
3756 "%s: get_hwaddr %s failed",
3757 __func__, ifname);
3758 ret = ERROR_SEND_STATUS;
3759 break;
3760 }
3761
3762 convert_mac_addr_to_ipv6_lladdr(iface_mac_addr,
3763 ipv6,
3764 sizeof(ipv6));
3765
3766 if (set_ipv6_addr(dut, ipv6, "64", ifname) !=
3767 0) {
3768 ret = ERROR_SEND_STATUS;
3769 break;
3770 }
3771 }
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003772 break;
3773 }
3774 }
3775done:
3776 if (ctrl) {
3777 wpa_ctrl_detach(ctrl);
3778 wpa_ctrl_close(ctrl);
3779 }
3780 return ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003781}
3782
3783
3784static int run_hs20_osu(struct sigma_dut *dut, const char *params)
3785{
3786 char buf[500], cmd[200];
3787 int res;
3788
3789 /* Use hs20-osu-client file at the current dir, if found; otherwise use
3790 * default path */
3791 res = snprintf(cmd, sizeof(cmd),
3792 "%s -w \"%s\" -r hs20-osu-client.res %s%s -dddKt -f Logs/hs20-osu-client.txt",
3793 file_exists("./hs20-osu-client") ?
3794 "./hs20-osu-client" : "hs20-osu-client",
3795 sigma_wpas_ctrl,
3796 dut->summary_log ? "-s " : "",
3797 dut->summary_log ? dut->summary_log : "");
3798 if (res < 0 || res >= (int) sizeof(cmd))
3799 return -1;
3800
3801 res = snprintf(buf, sizeof(buf), "%s %s", cmd, params);
3802 if (res < 0 || res >= (int) sizeof(buf))
3803 return -1;
3804 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
3805
3806 if (system(buf) != 0) {
3807 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run: %s", buf);
3808 return -1;
3809 }
3810 sigma_dut_print(dut, DUT_MSG_DEBUG,
3811 "Completed hs20-osu-client operation");
3812
3813 return 0;
3814}
3815
3816
3817static int download_ppsmo(struct sigma_dut *dut,
3818 struct sigma_conn *conn,
3819 const char *intf,
3820 struct sigma_cmd *cmd)
3821{
3822 const char *name, *path, *val;
3823 char url[500], buf[600], fbuf[100];
3824 char *fqdn = NULL;
3825
3826 name = get_param(cmd, "FileName");
3827 path = get_param(cmd, "FilePath");
3828 if (name == NULL || path == NULL)
3829 return -1;
3830
3831 if (strcasecmp(path, "VendorSpecific") == 0) {
3832 snprintf(url, sizeof(url), "PPS/%s", name);
3833 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured PPS MO "
3834 "from the device (%s)", url);
3835 if (!file_exists(url)) {
3836 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
3837 "PPS MO file does not exist");
3838 return 0;
3839 }
3840 snprintf(buf, sizeof(buf), "cp %s pps-tnds.xml", url);
3841 if (system(buf) != 0) {
3842 send_resp(dut, conn, SIGMA_ERROR,
3843 "errorCode,Failed to copy PPS MO");
3844 return 0;
3845 }
3846 } else if (strncasecmp(path, "http:", 5) != 0 &&
3847 strncasecmp(path, "https:", 6) != 0) {
3848 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3849 "Unsupported FilePath value");
3850 return 0;
3851 } else {
3852 snprintf(url, sizeof(url), "%s/%s", path, name);
3853 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading PPS MO from %s",
3854 url);
3855 snprintf(buf, sizeof(buf), "wget -T 10 -t 3 -O pps-tnds.xml '%s'", url);
3856 remove("pps-tnds.xml");
3857 if (system(buf) != 0) {
3858 send_resp(dut, conn, SIGMA_ERROR,
3859 "errorCode,Failed to download PPS MO");
3860 return 0;
3861 }
3862 }
3863
3864 if (run_hs20_osu(dut, "from_tnds pps-tnds.xml pps.xml") < 0) {
3865 send_resp(dut, conn, SIGMA_ERROR,
3866 "errorCode,Failed to parse downloaded PPSMO");
3867 return 0;
3868 }
3869 unlink("pps-tnds.xml");
3870
3871 val = get_param(cmd, "managementTreeURI");
3872 if (val) {
3873 const char *pos, *end;
3874 sigma_dut_print(dut, DUT_MSG_DEBUG, "managementTreeURI: %s",
3875 val);
3876 if (strncmp(val, "./Wi-Fi/", 8) != 0) {
3877 send_resp(dut, conn, SIGMA_ERROR,
3878 "errorCode,Invalid managementTreeURI prefix");
3879 return 0;
3880 }
3881 pos = val + 8;
3882 end = strchr(pos, '/');
3883 if (end == NULL ||
3884 strcmp(end, "/PerProviderSubscription") != 0) {
3885 send_resp(dut, conn, SIGMA_ERROR,
3886 "errorCode,Invalid managementTreeURI postfix");
3887 return 0;
3888 }
3889 if (end - pos >= (int) sizeof(fbuf)) {
3890 send_resp(dut, conn, SIGMA_ERROR,
3891 "errorCode,Too long FQDN in managementTreeURI");
3892 return 0;
3893 }
3894 memcpy(fbuf, pos, end - pos);
3895 fbuf[end - pos] = '\0';
3896 fqdn = fbuf;
3897 sigma_dut_print(dut, DUT_MSG_INFO,
3898 "FQDN from managementTreeURI: %s", fqdn);
3899 } else if (run_hs20_osu(dut, "get_fqdn pps.xml") == 0) {
3900 FILE *f = fopen("pps-fqdn", "r");
3901 if (f) {
3902 if (fgets(fbuf, sizeof(fbuf), f)) {
3903 fbuf[sizeof(fbuf) - 1] = '\0';
3904 fqdn = fbuf;
3905 sigma_dut_print(dut, DUT_MSG_DEBUG,
3906 "Use FQDN %s", fqdn);
3907 }
3908 fclose(f);
3909 }
3910 }
3911
3912 if (fqdn == NULL) {
3913 send_resp(dut, conn, SIGMA_ERROR,
3914 "errorCode,No FQDN specified");
3915 return 0;
3916 }
3917
3918 mkdir("SP", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
3919 snprintf(buf, sizeof(buf), "SP/%s", fqdn);
3920 mkdir(buf, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
3921
3922 snprintf(buf, sizeof(buf), "SP/%s/pps.xml", fqdn);
3923 if (rename("pps.xml", buf) < 0) {
3924 send_resp(dut, conn, SIGMA_ERROR,
3925 "errorCode,Could not move PPS MO");
3926 return 0;
3927 }
3928
3929 if (strcasecmp(path, "VendorSpecific") == 0) {
3930 snprintf(buf, sizeof(buf), "cp Certs/ca.pem SP/%s/ca.pem",
3931 fqdn);
3932 if (system(buf)) {
3933 send_resp(dut, conn, SIGMA_ERROR,
3934 "errorCode,Failed to copy OSU CA cert");
3935 return 0;
3936 }
3937
3938 snprintf(buf, sizeof(buf),
3939 "cp Certs/aaa-ca.pem SP/%s/aaa-ca.pem",
3940 fqdn);
3941 if (system(buf)) {
3942 send_resp(dut, conn, SIGMA_ERROR,
3943 "errorCode,Failed to copy AAA CA cert");
3944 return 0;
3945 }
3946 } else {
3947 snprintf(buf, sizeof(buf),
3948 "dl_osu_ca SP/%s/pps.xml SP/%s/ca.pem",
3949 fqdn, fqdn);
3950 if (run_hs20_osu(dut, buf) < 0) {
3951 send_resp(dut, conn, SIGMA_ERROR,
3952 "errorCode,Failed to download OSU CA cert");
3953 return 0;
3954 }
3955
3956 snprintf(buf, sizeof(buf),
3957 "dl_aaa_ca SP/%s/pps.xml SP/%s/aaa-ca.pem",
3958 fqdn, fqdn);
3959 if (run_hs20_osu(dut, buf) < 0) {
3960 sigma_dut_print(dut, DUT_MSG_INFO,
3961 "Failed to download AAA CA cert");
3962 }
3963 }
3964
3965 if (file_exists("next-client-cert.pem")) {
3966 snprintf(buf, sizeof(buf), "SP/%s/client-cert.pem", fqdn);
3967 if (rename("next-client-cert.pem", buf) < 0) {
3968 send_resp(dut, conn, SIGMA_ERROR,
3969 "errorCode,Could not move client certificate");
3970 return 0;
3971 }
3972 }
3973
3974 if (file_exists("next-client-key.pem")) {
3975 snprintf(buf, sizeof(buf), "SP/%s/client-key.pem", fqdn);
3976 if (rename("next-client-key.pem", buf) < 0) {
3977 send_resp(dut, conn, SIGMA_ERROR,
3978 "errorCode,Could not move client key");
3979 return 0;
3980 }
3981 }
3982
3983 snprintf(buf, sizeof(buf), "set_pps SP/%s/pps.xml", fqdn);
3984 if (run_hs20_osu(dut, buf) < 0) {
3985 send_resp(dut, conn, SIGMA_ERROR,
3986 "errorCode,Failed to configure credential from "
3987 "PPSMO");
3988 return 0;
3989 }
3990
3991 return 1;
3992}
3993
3994
3995static int download_cert(struct sigma_dut *dut,
3996 struct sigma_conn *conn,
3997 const char *intf,
3998 struct sigma_cmd *cmd)
3999{
4000 const char *name, *path;
4001 char url[500], buf[600];
4002
4003 name = get_param(cmd, "FileName");
4004 path = get_param(cmd, "FilePath");
4005 if (name == NULL || path == NULL)
4006 return -1;
4007
4008 if (strcasecmp(path, "VendorSpecific") == 0) {
4009 snprintf(url, sizeof(url), "Certs/%s-cert.pem", name);
4010 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
4011 "certificate from the device (%s)", url);
4012 if (!file_exists(url)) {
4013 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
4014 "certificate file does not exist");
4015 return 0;
4016 }
4017 snprintf(buf, sizeof(buf), "cp %s next-client-cert.pem", url);
4018 if (system(buf) != 0) {
4019 send_resp(dut, conn, SIGMA_ERROR,
4020 "errorCode,Failed to copy client "
4021 "certificate");
4022 return 0;
4023 }
4024
4025 snprintf(url, sizeof(url), "Certs/%s-key.pem", name);
4026 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
4027 "private key from the device (%s)", url);
4028 if (!file_exists(url)) {
4029 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
4030 "private key file does not exist");
4031 return 0;
4032 }
4033 snprintf(buf, sizeof(buf), "cp %s next-client-key.pem", url);
4034 if (system(buf) != 0) {
4035 send_resp(dut, conn, SIGMA_ERROR,
4036 "errorCode,Failed to copy client key");
4037 return 0;
4038 }
4039 } else if (strncasecmp(path, "http:", 5) != 0 &&
4040 strncasecmp(path, "https:", 6) != 0) {
4041 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
4042 "Unsupported FilePath value");
4043 return 0;
4044 } else {
4045 snprintf(url, sizeof(url), "%s/%s.pem", path, name);
4046 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading client "
4047 "certificate/key from %s", url);
4048 snprintf(buf, sizeof(buf),
4049 "wget -T 10 -t 3 -O next-client-cert.pem '%s'", url);
4050 if (system(buf) != 0) {
4051 send_resp(dut, conn, SIGMA_ERROR,
4052 "errorCode,Failed to download client "
4053 "certificate");
4054 return 0;
4055 }
4056
4057 if (system("cp next-client-cert.pem next-client-key.pem") != 0)
4058 {
4059 send_resp(dut, conn, SIGMA_ERROR,
4060 "errorCode,Failed to copy client key");
4061 return 0;
4062 }
4063 }
4064
4065 return 1;
4066}
4067
4068
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02004069static int cmd_sta_preset_testparameters_60ghz(struct sigma_dut *dut,
4070 struct sigma_conn *conn,
4071 struct sigma_cmd *cmd)
4072{
4073 const char *val;
4074 const char *intf = get_param(cmd, "interface");
4075
4076 if (!intf)
4077 return -1;
4078
4079 val = get_param(cmd, "WscIEFragment");
4080 if (val && strcasecmp(val, "enable") == 0) {
4081 sigma_dut_print(dut, DUT_MSG_DEBUG,
4082 "Enable WSC IE fragmentation");
4083
4084 dut->wsc_fragment = 1;
4085 /* set long attributes to force fragmentation */
4086 if (wpa_command(intf, "SET device_name "
4087 WPS_LONG_DEVICE_NAME) < 0)
4088 return -2;
4089 if (wpa_command(intf, "SET manufacturer "
4090 WPS_LONG_MANUFACTURER) < 0)
4091 return -2;
4092 if (wpa_command(intf, "SET model_name "
4093 WPS_LONG_MODEL_NAME) < 0)
4094 return -2;
4095 if (wpa_command(intf, "SET model_number "
4096 WPS_LONG_MODEL_NUMBER) < 0)
4097 return -2;
4098 if (wpa_command(intf, "SET serial_number "
4099 WPS_LONG_SERIAL_NUMBER) < 0)
4100 return -2;
4101 }
4102
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02004103 val = get_param(cmd, "RSN_IE");
4104 if (val) {
4105 if (strcasecmp(val, "disable") == 0)
4106 dut->force_rsn_ie = FORCE_RSN_IE_REMOVE;
4107 else if (strcasecmp(val, "enable") == 0)
4108 dut->force_rsn_ie = FORCE_RSN_IE_ADD;
4109 }
4110
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02004111 val = get_param(cmd, "WpsVersion");
4112 if (val)
4113 dut->wps_forced_version = get_wps_forced_version(dut, val);
4114
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02004115 val = get_param(cmd, "WscEAPFragment");
4116 if (val && strcasecmp(val, "enable") == 0)
4117 dut->eap_fragment = 1;
4118
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02004119 return 1;
4120}
4121
4122
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004123static int cmd_sta_preset_testparameters_hs2_r2(struct sigma_dut *dut,
4124 struct sigma_conn *conn,
4125 const char *intf,
4126 struct sigma_cmd *cmd)
4127{
4128 const char *val;
4129
4130 val = get_param(cmd, "FileType");
4131 if (val && strcasecmp(val, "PPSMO") == 0)
4132 return download_ppsmo(dut, conn, intf, cmd);
4133 if (val && strcasecmp(val, "CERT") == 0)
4134 return download_cert(dut, conn, intf, cmd);
4135 if (val) {
4136 send_resp(dut, conn, SIGMA_ERROR,
4137 "ErrorCode,Unsupported FileType");
4138 return 0;
4139 }
4140
4141 return 1;
4142}
4143
4144
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304145static int cmd_sta_preset_testparameters_oce(struct sigma_dut *dut,
4146 struct sigma_conn *conn,
4147 const char *intf,
4148 struct sigma_cmd *cmd)
4149{
4150 const char *val;
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304151 char buf[1000];
4152 char text[20];
4153 unsigned char addr[ETH_ALEN];
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304154
4155 val = get_param(cmd, "OCESupport");
4156 if (val && strcasecmp(val, "Disable") == 0) {
4157 if (wpa_command(intf, "SET oce 0") < 0) {
4158 send_resp(dut, conn, SIGMA_ERROR,
4159 "ErrorCode,Failed to disable OCE");
4160 return 0;
4161 }
4162 } else if (val && strcasecmp(val, "Enable") == 0) {
4163 if (wpa_command(intf, "SET oce 1") < 0) {
4164 send_resp(dut, conn, SIGMA_ERROR,
4165 "ErrorCode,Failed to enable OCE");
4166 return 0;
4167 }
4168 }
4169
vamsi krishnaa2799492017-12-05 14:28:01 +05304170 val = get_param(cmd, "FILScap");
4171 if (val && (atoi(val) == 1)) {
4172 if (wpa_command(intf, "SET disable_fils 0") < 0) {
4173 send_resp(dut, conn, SIGMA_ERROR,
4174 "ErrorCode,Failed to enable FILS");
4175 return 0;
4176 }
4177 } else if (val && (atoi(val) == 0)) {
4178 if (wpa_command(intf, "SET disable_fils 1") < 0) {
4179 send_resp(dut, conn, SIGMA_ERROR,
4180 "ErrorCode,Failed to disable FILS");
4181 return 0;
4182 }
4183 }
4184
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304185 val = get_param(cmd, "FILSHLP");
4186 if (val && strcasecmp(val, "Enable") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004187 if (get_wpa_status(get_station_ifname(dut), "address", text,
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304188 sizeof(text)) < 0)
4189 return -2;
4190 hwaddr_aton(text, addr);
4191 snprintf(buf, sizeof(buf),
4192 "FILS_HLP_REQ_ADD ff:ff:ff:ff:ff:ff "
4193 "080045100140000040004011399e00000000ffffffff00440043"
4194 "012cb30001010600fd4f46410000000000000000000000000000"
4195 "000000000000"
4196 "%02x%02x%02x%02x%02x%02x"
4197 "0000000000000000000000000000000000000000000000000000"
4198 "0000000000000000000000000000000000000000000000000000"
4199 "0000000000000000000000000000000000000000000000000000"
4200 "0000000000000000000000000000000000000000000000000000"
4201 "0000000000000000000000000000000000000000000000000000"
4202 "0000000000000000000000000000000000000000000000000000"
4203 "0000000000000000000000000000000000000000000000000000"
4204 "0000000000000000000000000000000000000000638253633501"
4205 "013d0701000af549d29b390205dc3c12616e64726f69642d6468"
4206 "63702d382e302e30370a0103060f1a1c333a3b2b5000ff00",
4207 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
4208 if (wpa_command(intf, buf)) {
4209 send_resp(dut, conn, SIGMA_ERROR,
4210 "ErrorCode,Failed to add HLP");
4211 return 0;
4212 }
4213 dut->fils_hlp = 1;
4214 }
4215
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304216 return 1;
4217}
4218
4219
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004220static void ath_sta_set_noack(struct sigma_dut *dut, const char *intf,
4221 const char *val)
4222{
4223 int counter = 0;
4224 char token[50];
4225 char *result;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304226 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004227
Peng Xub8fc5cc2017-05-10 17:27:28 -07004228 strlcpy(token, val, sizeof(token));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004229 token[sizeof(token) - 1] = '\0';
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304230 result = strtok_r(token, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004231 while (result) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004232 if (strcmp(result, "disable") == 0)
4233 run_iwpriv(dut, intf, "noackpolicy %d 1 0", counter);
4234 else
4235 run_iwpriv(dut, intf, "noackpolicy %d 1 1", counter);
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304236 result = strtok_r(NULL, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004237 counter++;
4238 }
4239}
4240
4241
4242static void ath_sta_set_rts(struct sigma_dut *dut, const char *intf,
4243 const char *val)
4244{
4245 char buf[100];
4246
4247 snprintf(buf, sizeof(buf), "iwconfig %s rts %s", intf, val);
4248 if (system(buf) != 0) {
4249 sigma_dut_print(dut, DUT_MSG_ERROR, "iwconfig RTS failed");
4250 }
4251}
4252
4253
4254static void ath_sta_set_wmm(struct sigma_dut *dut, const char *intf,
4255 const char *val)
4256{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004257 if (strcasecmp(val, "off") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004258 run_iwpriv(dut, intf, "wmm 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004259 }
4260}
4261
4262
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08004263static int wcn_sta_set_wmm(struct sigma_dut *dut, const char *intf,
4264 const char *val)
4265{
4266#ifdef NL80211_SUPPORT
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08004267 int wmmenable = 1;
4268
4269 if (val &&
4270 (strcasecmp(val, "off") == 0 || strcmp(val, "0") == 0))
4271 wmmenable = 0;
4272
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05304273 return wcn_wifi_test_config_set_u8(
4274 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WMM_ENABLE,
4275 wmmenable);
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08004276#else /* NL80211_SUPPORT */
4277 sigma_dut_print(dut, DUT_MSG_ERROR,
4278 "WMM cannot be changed without NL80211_SUPPORT defined");
4279 return -1;
4280#endif /* NL80211_SUPPORT */
4281}
4282
4283
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004284static void ath_sta_set_sgi(struct sigma_dut *dut, const char *intf,
4285 const char *val)
4286{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004287 int sgi20;
4288
4289 sgi20 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
4290
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004291 run_iwpriv(dut, intf, "shortgi %d", sgi20);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004292}
4293
4294
4295static void ath_sta_set_11nrates(struct sigma_dut *dut, const char *intf,
4296 const char *val)
4297{
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05304298 int rate_code, v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004299
4300 /* Disable Tx Beam forming when using a fixed rate */
4301 ath_disable_txbf(dut, intf);
4302
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05304303 v = atoi(val);
4304 if (v < 0 || v > 32) {
4305 sigma_dut_print(dut, DUT_MSG_ERROR,
4306 "Invalid Fixed MCS rate: %d", v);
4307 return;
4308 }
4309 rate_code = 0x80 + v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004310
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004311 run_iwpriv(dut, intf, "set11NRates 0x%x", rate_code);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004312
4313 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004314 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004315}
4316
4317
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08004318static void iwpriv_sta_set_amsdu(struct sigma_dut *dut, const char *intf,
4319 const char *val)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004320{
4321 char buf[60];
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304322 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004323
4324 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)
4325 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 2", intf);
4326 else
4327 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf);
4328
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304329 ret = system(buf);
4330#ifdef NL80211_SUPPORT
4331 if (ret) {
4332 int value = (strcasecmp(val, "Enable") == 0) ? 2 : 1;
4333
4334 ret = sta_config_params(dut, intf, STA_SET_TX_MSDU, value);
4335 ret |= sta_config_params(dut, intf, STA_SET_RX_MSDU, value);
4336 }
4337#endif /* NL80211_SUPPORT */
4338 if (ret)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004339 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv amsdu failed");
4340}
4341
4342
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004343static int iwpriv_sta_set_ampdu(struct sigma_dut *dut, const char *intf,
4344 int ampdu)
4345{
4346 char buf[60];
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08004347 int maxaggregation = 63;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004348
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08004349 if (ampdu)
4350 ampdu = maxaggregation;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004351 snprintf(buf, sizeof(buf), "iwpriv %s ampdu %d", intf, ampdu);
4352 if (system(buf) != 0) {
4353 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv ampdu failed");
4354 return -1;
4355 }
4356
4357 return 0;
4358}
4359
4360
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004361static void ath_sta_set_stbc(struct sigma_dut *dut, const char *intf,
4362 const char *val)
4363{
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004364 run_iwpriv(dut, intf, "tx_stbc %s", val);
4365 run_iwpriv(dut, intf, "rx_stbc %s", val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004366}
4367
4368
4369static int wcn_sta_set_cts_width(struct sigma_dut *dut, const char *intf,
4370 const char *val)
4371{
4372 char buf[60];
4373
Peng Xucc317ed2017-05-18 16:44:37 -07004374 if (strcmp(val, "160") == 0) {
4375 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 5", intf);
4376 } else if (strcmp(val, "80") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004377 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
4378 } else if (strcmp(val, "40") == 0) {
4379 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 2", intf);
4380 } else if (strcmp(val, "20") == 0) {
4381 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 1", intf);
4382 } else if (strcasecmp(val, "Auto") == 0) {
4383 buf[0] = '\0';
4384 } else {
4385 sigma_dut_print(dut, DUT_MSG_ERROR,
4386 "WIDTH/CTS_WIDTH value not supported");
4387 return -1;
4388 }
4389
4390 if (buf[0] != '\0' && system(buf) != 0) {
4391 sigma_dut_print(dut, DUT_MSG_ERROR,
4392 "Failed to set WIDTH/CTS_WIDTH");
4393 return -1;
4394 }
4395
4396 return 0;
4397}
4398
4399
4400int ath_set_width(struct sigma_dut *dut, struct sigma_conn *conn,
4401 const char *intf, const char *val)
4402{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004403 if (strcasecmp(val, "Auto") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004404 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004405 dut->chwidth = 0;
4406 } else if (strcasecmp(val, "20") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004407 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004408 dut->chwidth = 0;
4409 } else if (strcasecmp(val, "40") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004410 run_iwpriv(dut, intf, "chwidth 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004411 dut->chwidth = 1;
4412 } else if (strcasecmp(val, "80") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004413 run_iwpriv(dut, intf, "chwidth 2");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004414 dut->chwidth = 2;
4415 } else if (strcasecmp(val, "160") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004416 run_iwpriv(dut, intf, "chwidth 3");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004417 dut->chwidth = 3;
4418 } else {
4419 send_resp(dut, conn, SIGMA_ERROR,
4420 "ErrorCode,WIDTH not supported");
4421 return -1;
4422 }
4423
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004424 return 0;
4425}
4426
4427
4428static int wcn_sta_set_sp_stream(struct sigma_dut *dut, const char *intf,
4429 const char *val)
4430{
4431 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07004432 int sta_nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004433
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08004434 if (strcmp(val, "1SS") == 0 || strcmp(val, "1") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004435 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07004436 sta_nss = 1;
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08004437 } else if (strcmp(val, "2SS") == 0 || strcmp(val, "2") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004438 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07004439 sta_nss = 2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004440 } else {
4441 sigma_dut_print(dut, DUT_MSG_ERROR,
4442 "SP_STREAM value not supported");
4443 return -1;
4444 }
4445
4446 if (system(buf) != 0) {
4447 sigma_dut_print(dut, DUT_MSG_ERROR,
4448 "Failed to set SP_STREAM");
4449 return -1;
4450 }
4451
Arif Hussainac6c5112018-05-25 17:34:00 -07004452 dut->sta_nss = sta_nss;
4453
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004454 return 0;
4455}
4456
4457
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304458static void wcn_sta_set_stbc(struct sigma_dut *dut, const char *intf,
4459 const char *val)
4460{
4461 char buf[60];
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304462 int ret;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304463
4464 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc %s", intf, val);
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304465 ret = system(buf);
4466#ifdef NL80211_SUPPORT
4467 if (ret)
4468 ret = sta_config_params(dut, intf, STA_SET_TX_STBC,
4469 strcmp(val, "0") == 0 ? 0 : 1);
4470#endif /* NL80211_SUPPORT */
4471 if (ret)
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304472 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv tx_stbc failed");
4473
4474 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc %s", intf, val);
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304475 ret = system(buf);
4476#ifdef NL80211_SUPPORT
4477 if (ret)
4478 ret = sta_config_params(dut, intf, STA_SET_RX_STBC,
4479 strcmp(val, "0") == 0 ? 0 : 1);
4480#endif /* NL80211_SUPPORT */
4481 if (ret)
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304482 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv rx_stbc failed");
4483}
4484
4485
Ashwini Patil68d02cd2017-01-10 15:39:16 +05304486static int mbo_set_cellular_data_capa(struct sigma_dut *dut,
4487 struct sigma_conn *conn,
4488 const char *intf, int capa)
4489{
4490 char buf[32];
4491
4492 if (capa > 0 && capa < 4) {
4493 snprintf(buf, sizeof(buf), "SET mbo_cell_capa %d", capa);
4494 if (wpa_command(intf, buf) < 0) {
4495 send_resp(dut, conn, SIGMA_ERROR,
4496 "ErrorCode, Failed to set cellular data capability");
4497 return 0;
4498 }
4499 return 1;
4500 }
4501
4502 sigma_dut_print(dut, DUT_MSG_ERROR,
4503 "Invalid Cellular data capability: %d", capa);
4504 send_resp(dut, conn, SIGMA_INVALID,
4505 "ErrorCode,Invalid cellular data capability");
4506 return 0;
4507}
4508
4509
Ashwini Patil9183fdb2017-04-13 16:58:25 +05304510static int mbo_set_roaming(struct sigma_dut *dut, struct sigma_conn *conn,
4511 const char *intf, const char *val)
4512{
4513 if (strcasecmp(val, "Disable") == 0) {
4514 if (wpa_command(intf, "SET roaming 0") < 0) {
4515 send_resp(dut, conn, SIGMA_ERROR,
4516 "ErrorCode,Failed to disable roaming");
4517 return 0;
4518 }
4519 return 1;
4520 }
4521
4522 if (strcasecmp(val, "Enable") == 0) {
4523 if (wpa_command(intf, "SET roaming 1") < 0) {
4524 send_resp(dut, conn, SIGMA_ERROR,
4525 "ErrorCode,Failed to enable roaming");
4526 return 0;
4527 }
4528 return 1;
4529 }
4530
4531 sigma_dut_print(dut, DUT_MSG_ERROR,
4532 "Invalid value provided for roaming: %s", val);
4533 send_resp(dut, conn, SIGMA_INVALID,
4534 "ErrorCode,Unknown value provided for Roaming");
4535 return 0;
4536}
4537
4538
Ashwini Patila75de5a2017-04-13 16:35:05 +05304539static int mbo_set_assoc_disallow(struct sigma_dut *dut,
4540 struct sigma_conn *conn,
4541 const char *intf, const char *val)
4542{
4543 if (strcasecmp(val, "Disable") == 0) {
4544 if (wpa_command(intf, "SET ignore_assoc_disallow 1") < 0) {
4545 send_resp(dut, conn, SIGMA_ERROR,
4546 "ErrorCode,Failed to disable Assoc_disallow");
4547 return 0;
4548 }
4549 return 1;
4550 }
4551
4552 if (strcasecmp(val, "Enable") == 0) {
4553 if (wpa_command(intf, "SET ignore_assoc_disallow 0") < 0) {
4554 send_resp(dut, conn, SIGMA_ERROR,
4555 "ErrorCode,Failed to enable Assoc_disallow");
4556 return 0;
4557 }
4558 return 1;
4559 }
4560
4561 sigma_dut_print(dut, DUT_MSG_ERROR,
4562 "Invalid value provided for Assoc_disallow: %s", val);
4563 send_resp(dut, conn, SIGMA_INVALID,
4564 "ErrorCode,Unknown value provided for Assoc_disallow");
4565 return 0;
4566}
4567
4568
Ashwini Patilc63161e2017-04-13 16:30:23 +05304569static int mbo_set_bss_trans_req(struct sigma_dut *dut, struct sigma_conn *conn,
4570 const char *intf, const char *val)
4571{
4572 if (strcasecmp(val, "Reject") == 0) {
4573 if (wpa_command(intf, "SET reject_btm_req_reason 1") < 0) {
4574 send_resp(dut, conn, SIGMA_ERROR,
4575 "ErrorCode,Failed to Reject BTM Request");
4576 return 0;
4577 }
4578 return 1;
4579 }
4580
4581 if (strcasecmp(val, "Accept") == 0) {
4582 if (wpa_command(intf, "SET reject_btm_req_reason 0") < 0) {
4583 send_resp(dut, conn, SIGMA_ERROR,
4584 "ErrorCode,Failed to Accept BTM Request");
4585 return 0;
4586 }
4587 return 1;
4588 }
4589
4590 sigma_dut_print(dut, DUT_MSG_ERROR,
4591 "Invalid value provided for BSS_Transition: %s", val);
4592 send_resp(dut, conn, SIGMA_INVALID,
4593 "ErrorCode,Unknown value provided for BSS_Transition");
4594 return 0;
4595}
4596
4597
Ashwini Patil00402582017-04-13 12:29:39 +05304598static int mbo_set_non_pref_ch_list(struct sigma_dut *dut,
4599 struct sigma_conn *conn,
4600 const char *intf,
4601 struct sigma_cmd *cmd)
4602{
4603 const char *ch, *pref, *op_class, *reason;
4604 char buf[120];
4605 int len, ret;
4606
4607 pref = get_param(cmd, "Ch_Pref");
4608 if (!pref)
4609 return 1;
4610
4611 if (strcasecmp(pref, "clear") == 0) {
4612 free(dut->non_pref_ch_list);
4613 dut->non_pref_ch_list = NULL;
4614 } else {
4615 op_class = get_param(cmd, "Ch_Op_Class");
4616 if (!op_class) {
4617 send_resp(dut, conn, SIGMA_INVALID,
4618 "ErrorCode,Ch_Op_Class not provided");
4619 return 0;
4620 }
4621
4622 ch = get_param(cmd, "Ch_Pref_Num");
4623 if (!ch) {
4624 send_resp(dut, conn, SIGMA_INVALID,
4625 "ErrorCode,Ch_Pref_Num not provided");
4626 return 0;
4627 }
4628
4629 reason = get_param(cmd, "Ch_Reason_Code");
4630 if (!reason) {
4631 send_resp(dut, conn, SIGMA_INVALID,
4632 "ErrorCode,Ch_Reason_Code not provided");
4633 return 0;
4634 }
4635
4636 if (!dut->non_pref_ch_list) {
4637 dut->non_pref_ch_list =
4638 calloc(1, NON_PREF_CH_LIST_SIZE);
4639 if (!dut->non_pref_ch_list) {
4640 send_resp(dut, conn, SIGMA_ERROR,
4641 "ErrorCode,Failed to allocate memory for non_pref_ch_list");
4642 return 0;
4643 }
4644 }
4645 len = strlen(dut->non_pref_ch_list);
4646 ret = snprintf(dut->non_pref_ch_list + len,
4647 NON_PREF_CH_LIST_SIZE - len,
4648 " %s:%s:%s:%s", op_class, ch, pref, reason);
4649 if (ret > 0 && ret < NON_PREF_CH_LIST_SIZE - len) {
4650 sigma_dut_print(dut, DUT_MSG_DEBUG, "non_pref_list: %s",
4651 dut->non_pref_ch_list);
4652 } else {
4653 sigma_dut_print(dut, DUT_MSG_ERROR,
4654 "snprintf failed for non_pref_list, ret = %d",
4655 ret);
4656 send_resp(dut, conn, SIGMA_ERROR,
4657 "ErrorCode,snprintf failed");
4658 free(dut->non_pref_ch_list);
4659 dut->non_pref_ch_list = NULL;
4660 return 0;
4661 }
4662 }
4663
4664 ret = snprintf(buf, sizeof(buf), "SET non_pref_chan%s",
4665 dut->non_pref_ch_list ? dut->non_pref_ch_list : " ");
4666 if (ret < 0 || ret >= (int) sizeof(buf)) {
4667 sigma_dut_print(dut, DUT_MSG_DEBUG,
4668 "snprintf failed for set non_pref_chan, ret: %d",
4669 ret);
4670 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,snprint failed");
4671 return 0;
4672 }
4673
4674 if (wpa_command(intf, buf) < 0) {
4675 send_resp(dut, conn, SIGMA_ERROR,
4676 "ErrorCode,Failed to set non-preferred channel list");
4677 return 0;
4678 }
4679
4680 return 1;
4681}
4682
4683
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004684#ifdef NL80211_SUPPORT
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004685
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08004686static int sta_set_he_htc_supp(struct sigma_dut *dut, const char *intf,
4687 uint8_t cfg)
4688{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05304689 return wcn_wifi_test_config_set_u8(
4690 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_HTC_HE_SUPP,
4691 cfg);
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08004692}
4693
4694
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004695static int sta_set_he_fragmentation(struct sigma_dut *dut, const char *intf,
4696 enum he_fragmentation_val frag)
4697{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05304698 return wcn_wifi_test_config_set_u8(
4699 dut, intf,
4700 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_FRAGMENTATION, frag);
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004701}
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004702
4703
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -08004704int wcn_set_he_ltf(struct sigma_dut *dut, const char *intf,
4705 enum qca_wlan_he_ltf_cfg ltf)
Subhani Shaik8e7a3052018-04-24 14:03:00 -07004706{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05304707 return wcn_wifi_test_config_set_u8(
4708 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_LTF, ltf);
Subhani Shaik8e7a3052018-04-24 14:03:00 -07004709}
4710
4711
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004712static int nlvendor_sta_set_noack(struct sigma_dut *dut, const char *intf,
4713 int noack, enum qca_wlan_ac_type ac)
4714{
4715 struct nl_msg *msg;
4716 int ret = 0;
4717 struct nlattr *params;
4718 int ifindex;
4719
4720 ifindex = if_nametoindex(intf);
4721 if (ifindex == 0) {
4722 sigma_dut_print(dut, DUT_MSG_ERROR,
4723 "%s: Index for interface %s failed",
4724 __func__, intf);
4725 return -1;
4726 }
4727
4728 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4729 NL80211_CMD_VENDOR)) ||
4730 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4731 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4732 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4733 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4734 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4735 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_NO_ACK,
4736 noack) ||
4737 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_NO_ACK_AC,
4738 ac)) {
4739 sigma_dut_print(dut, DUT_MSG_ERROR,
4740 "%s: err in adding vendor_cmd and vendor_data",
4741 __func__);
4742 nlmsg_free(msg);
4743 return -1;
4744 }
4745 nla_nest_end(msg, params);
4746
4747 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4748 if (ret) {
4749 sigma_dut_print(dut, DUT_MSG_ERROR,
4750 "%s: err in send_and_recv_msgs, ret=%d",
4751 __func__, ret);
4752 }
4753 return ret;
4754}
4755
4756
4757static void wcn_sta_set_noack(struct sigma_dut *dut, const char *intf,
4758 const char *val)
4759{
4760 int noack, ret;
4761 char token[100];
4762 char *result;
4763 char *saveptr;
4764 enum qca_wlan_ac_type ac = QCA_WLAN_AC_BE;
4765
4766 strlcpy(token, val, sizeof(token));
4767 token[sizeof(token) - 1] = '\0';
4768 result = strtok_r(token, ":", &saveptr);
4769 while (result) {
4770 noack = strcasecmp(result, "Disable") != 0;
4771 ret = nlvendor_sta_set_noack(dut, intf, noack, ac);
4772 if (ret) {
4773 sigma_dut_print(dut, DUT_MSG_ERROR,
4774 "nlvendor_sta_set_noack failed for ac:%d, ret:%d",
4775 ac, ret);
4776 }
4777 result = strtok_r(NULL, ":", &saveptr);
4778 ac++;
4779 }
4780}
4781
Vinita S. Maloo7462e812020-05-22 15:16:04 +05304782
4783static int nlvendor_sta_set_phymode(struct sigma_dut *dut, const char *intf,
4784 enum qca_wlan_vendor_phy_mode val)
4785{
4786 struct nl_msg *msg;
4787 struct nlattr *params;
4788 int ifindex, ret;
4789
4790 ifindex = if_nametoindex(intf);
4791 if (ifindex == 0) {
4792 sigma_dut_print(dut, DUT_MSG_ERROR,
4793 "%s: Index for interface %s not found",
4794 __func__, intf);
4795 return -1;
4796 }
4797
4798 msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4799 NL80211_CMD_VENDOR);
4800 if (!msg) {
4801 sigma_dut_print(dut, DUT_MSG_ERROR,
4802 "%s: err in adding vendor_cmd", __func__);
4803 return -1;
4804 }
4805
4806 if (nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4807 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4808 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION)) {
4809 sigma_dut_print(dut, DUT_MSG_ERROR,
4810 "%s: err in adding vendor_attr", __func__);
4811 nlmsg_free(msg);
4812 return -1;
4813 }
4814
4815 params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
4816 if (!params || nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_PHY_MODE,
4817 val)) {
4818 sigma_dut_print(dut, DUT_MSG_ERROR,
4819 "%s: err in adding vendor_data", __func__);
4820 nlmsg_free(msg);
4821 return -1;
4822 }
4823
4824 nla_nest_end(msg, params);
4825 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4826 if (ret) {
4827 sigma_dut_print(dut, DUT_MSG_ERROR,
4828 "%s: err in send_and_recv_msgs, ret=%d (%s)",
4829 __func__, ret, strerror(-ret));
4830 return ret;
4831 }
4832
4833 return 0;
4834}
4835
4836
4837static enum qca_wlan_vendor_phy_mode get_qca_vendor_phymode(const char *val)
4838{
4839 if (strcmp(val, "11a") == 0) {
4840 /* IEEE80211_MODE_11A */
4841 return QCA_WLAN_VENDOR_PHY_MODE_11A;
4842 }
4843
4844 if (strcmp(val, "11g") == 0) {
4845 /* IEEE80211_MODE_11G */
4846 return QCA_WLAN_VENDOR_PHY_MODE_11G;
4847 }
4848
4849 if (strcmp(val, "11b") == 0) {
4850 /* IEEE80211_MODE_11B */
4851 return QCA_WLAN_VENDOR_PHY_MODE_11B;
4852 }
4853
4854 if (strcmp(val, "11n") == 0 ||
4855 strcmp(val, "11nl") == 0 ||
4856 strcmp(val, "11nl(nabg)") == 0) {
4857 /* IEEE80211_MODE_11AGN */
4858 return QCA_WLAN_VENDOR_PHY_MODE_11AGN;
4859 }
4860
4861 if (strcmp(val, "11ng") == 0) {
4862 /* IEEE80211_MODE_11NG_HT40 */
4863 return QCA_WLAN_VENDOR_PHY_MODE_11NG_HT40;
4864 }
4865
4866 if (strcmp(val, "AC") == 0 ||
4867 strcasecmp(val, "11AC") == 0) {
4868 /* IEEE80211_MODE_11AC_VHT80 */
4869 return QCA_WLAN_VENDOR_PHY_MODE_11AC_VHT80;
4870 }
4871
4872 if (strcmp(val, "11na") == 0 ||
4873 strcasecmp(val, "11an") == 0) {
4874 /* IEEE80211_MODE_11NA_HT40 */
4875 return QCA_WLAN_VENDOR_PHY_MODE_11NA_HT40;
4876 }
4877
4878 if (strcmp(val, "11ax") == 0 ||
4879 strcmp(val, "auto") == 0) {
4880 /* IEEE80211_MODE_AUTO */
4881 return QCA_WLAN_VENDOR_PHY_MODE_AUTO;
4882 }
4883
4884 return -1;
4885}
4886
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004887#endif /* NL80211_SUPPORT */
4888
4889
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05304890static int get_phymode(const char *val)
4891{
4892 if (strcmp(val, "11a") == 0)
4893 return 1; /* IEEE80211_MODE_11A */
4894 if (strcmp(val, "11g") == 0)
4895 return 3; /* IEEE80211_MODE_11G */
4896 if (strcmp(val, "11b") == 0)
4897 return 2; /* IEEE80211_MODE_11B */
4898 if (strcmp(val, "11n") == 0 ||
4899 strcmp(val, "11nl") == 0 ||
4900 strcmp(val, "11nl(nabg)") == 0)
4901 return 22; /* IEEE80211_MODE_11AGN */
4902 if (strcmp(val, "11ng") == 0)
4903 return 13; /* IEEE80211_MODE_11NG_HT40 */
4904 if (strcmp(val, "AC") == 0 ||
4905 strcasecmp(val, "11AC") == 0)
4906 return 19; /* IEEE80211_MODE_11AC_VHT80 */
4907 if (strcmp(val, "11na") == 0 ||
4908 strcasecmp(val, "11an") == 0)
4909 return 14; /* IEEE80211_MODE_11NA_HT40 */
4910 if (strcmp(val, "11ax") == 0 ||
4911 strcmp(val, "auto") == 0)
4912 return 0; /* IEEE80211_MODE_AUTO */
4913 return -1;
4914}
4915
4916
4917static void sta_set_phymode(struct sigma_dut *dut, const char *intf,
4918 const char *val)
4919{
4920 char buf[100];
4921 int len, phymode;
Vinita S. Maloo7462e812020-05-22 15:16:04 +05304922#ifdef NL80211_SUPPORT
4923 enum qca_wlan_vendor_phy_mode qca_phymode;
4924
4925 qca_phymode = get_qca_vendor_phymode(val);
4926 if (qca_phymode == -1) {
4927 sigma_dut_print(dut, DUT_MSG_DEBUG,
4928 "Ignoring mode change for mode: %s",
4929 val);
4930 return;
4931 }
4932
4933 if (nlvendor_sta_set_phymode(dut, intf, qca_phymode) == 0)
4934 return;
4935#endif /* NL80211_SUPPORT */
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05304936
4937 phymode = get_phymode(val);
4938 if (phymode == -1) {
4939 sigma_dut_print(dut, DUT_MSG_DEBUG,
4940 "Ignoring mode change for mode: %s",
4941 val);
4942 return;
4943 }
4944
4945 len = snprintf(buf, sizeof(buf), "iwpriv %s setphymode %d", intf,
4946 phymode);
4947 if (len < 0 || len >= sizeof(buf)) {
4948 sigma_dut_print(dut, DUT_MSG_ERROR,
4949 "Failed to set phymode");
4950 return;
4951 }
4952
4953 if (system(buf) != 0)
4954 sigma_dut_print(dut, DUT_MSG_ERROR,
4955 "iwpriv setting of phymode failed");
4956}
4957
4958
Jouni Malinenf7222712019-06-13 01:50:21 +03004959static enum sigma_cmd_result
4960cmd_sta_preset_testparameters(struct sigma_dut *dut, struct sigma_conn *conn,
4961 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004962{
4963 const char *intf = get_param(cmd, "Interface");
4964 const char *val;
4965
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03004966 val = get_param(cmd, "FT_DS");
4967 if (val) {
4968 if (strcasecmp(val, "Enable") == 0) {
4969 dut->sta_ft_ds = 1;
4970 } else if (strcasecmp(val, "Disable") == 0) {
4971 dut->sta_ft_ds = 0;
4972 } else {
4973 send_resp(dut, conn, SIGMA_ERROR,
4974 "errorCode,Unsupported value for FT_DS");
4975 return STATUS_SENT_ERROR;
4976 }
4977 }
4978
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004979 val = get_param(cmd, "Program");
Jouni Malinen1f6ae642018-06-07 23:56:13 +03004980 if (val && (strcasecmp(val, "HS2-R2") == 0 ||
4981 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004982 return cmd_sta_preset_testparameters_hs2_r2(dut, conn, intf,
4983 cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004984
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07004985 if (val && strcasecmp(val, "LOC") == 0)
4986 return loc_cmd_sta_preset_testparameters(dut, conn, cmd);
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02004987 if (val && strcasecmp(val, "60GHZ") == 0) {
4988 val = get_param(cmd, "WPS");
4989 if (val && strcasecmp(val, "disable") == 0) {
4990 dut->wps_disable = 1;
4991 sigma_dut_print(dut, DUT_MSG_INFO, "WPS disabled");
4992 } else {
4993 /* wps_disable can have other value from the previous
4994 * test, so make sure it has the correct value.
4995 */
4996 dut->wps_disable = 0;
4997 }
4998
4999 val = get_param(cmd, "P2P");
5000 if (val && strcasecmp(val, "disable") == 0)
5001 sigma_dut_print(dut, DUT_MSG_INFO, "P2P disabled");
5002 }
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07005003
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02005004 if (dut->program == PROGRAM_WPS && dut->band == WPS_BAND_60G)
5005 return cmd_sta_preset_testparameters_60ghz(dut, conn, cmd);
5006
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005007#ifdef ANDROID_NAN
5008 if (val && strcasecmp(val, "NAN") == 0)
5009 return nan_cmd_sta_preset_testparameters(dut, conn, cmd);
5010#endif /* ANDROID_NAN */
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07005011#ifdef MIRACAST
5012 if (val && (strcasecmp(val, "WFD") == 0 ||
5013 strcasecmp(val, "DisplayR2") == 0))
5014 return miracast_preset_testparameters(dut, conn, cmd);
5015#endif /* MIRACAST */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005016
Kiran Kumar Lokeredd086642020-06-04 00:29:26 -07005017 if (val &&
5018 (strcasecmp(val, "MBO") == 0 || strcasecmp(val, "HE") == 0)) {
Ashwini Patil68d02cd2017-01-10 15:39:16 +05305019 val = get_param(cmd, "Cellular_Data_Cap");
5020 if (val &&
5021 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
5022 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +05305023
5024 val = get_param(cmd, "Ch_Pref");
5025 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
5026 return 0;
5027
Ashwini Patilc63161e2017-04-13 16:30:23 +05305028 val = get_param(cmd, "BSS_Transition");
5029 if (val && mbo_set_bss_trans_req(dut, conn, intf, val) == 0)
5030 return 0;
5031
Ashwini Patila75de5a2017-04-13 16:35:05 +05305032 val = get_param(cmd, "Assoc_Disallow");
5033 if (val && mbo_set_assoc_disallow(dut, conn, intf, val) == 0)
5034 return 0;
5035
Ashwini Patil9183fdb2017-04-13 16:58:25 +05305036 val = get_param(cmd, "Roaming");
5037 if (val && mbo_set_roaming(dut, conn, intf, val) == 0)
5038 return 0;
5039
Ashwini Patil68d02cd2017-01-10 15:39:16 +05305040 return 1;
5041 }
5042
Ankita Bajaja2cb5672017-10-25 16:08:28 +05305043 if (val && strcasecmp(val, "OCE") == 0)
5044 return cmd_sta_preset_testparameters_oce(dut, conn, intf, cmd);
5045
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005046#if 0
5047 val = get_param(cmd, "Supplicant");
5048 if (val && strcasecmp(val, "Default") != 0) {
5049 send_resp(dut, conn, SIGMA_ERROR,
5050 "ErrorCode,Only default(Vendor) supplicant "
5051 "supported");
5052 return 0;
5053 }
5054#endif
5055
5056 val = get_param(cmd, "RTS");
5057 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005058 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005059 case DRIVER_ATHEROS:
5060 ath_sta_set_rts(dut, intf, val);
5061 break;
5062 default:
5063#if 0
5064 send_resp(dut, conn, SIGMA_ERROR,
5065 "ErrorCode,Setting RTS not supported");
5066 return 0;
5067#else
5068 sigma_dut_print(dut, DUT_MSG_DEBUG,
5069 "Setting RTS not supported");
5070 break;
5071#endif
5072 }
5073 }
5074
5075#if 0
5076 val = get_param(cmd, "FRGMNT");
5077 if (val) {
5078 /* TODO */
5079 send_resp(dut, conn, SIGMA_ERROR,
5080 "ErrorCode,Setting FRGMNT not supported");
5081 return 0;
5082 }
5083#endif
5084
5085#if 0
5086 val = get_param(cmd, "Preamble");
5087 if (val) {
5088 /* TODO: Long/Short */
5089 send_resp(dut, conn, SIGMA_ERROR,
5090 "ErrorCode,Setting Preamble not supported");
5091 return 0;
5092 }
5093#endif
5094
5095 val = get_param(cmd, "Mode");
5096 if (val) {
5097 if (strcmp(val, "11b") == 0 ||
5098 strcmp(val, "11g") == 0 ||
5099 strcmp(val, "11a") == 0 ||
5100 strcmp(val, "11n") == 0 ||
5101 strcmp(val, "11ng") == 0 ||
5102 strcmp(val, "11nl") == 0 ||
5103 strcmp(val, "11nl(nabg)") == 0 ||
5104 strcmp(val, "AC") == 0 ||
5105 strcmp(val, "11AC") == 0 ||
5106 strcmp(val, "11ac") == 0 ||
5107 strcmp(val, "11na") == 0 ||
Amarnath Hullur Subramanyamb0db2712018-01-30 19:40:35 -08005108 strcmp(val, "11an") == 0 ||
5109 strcmp(val, "11ax") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005110 /* STA supports all modes by default */
5111 } else {
5112 send_resp(dut, conn, SIGMA_ERROR,
5113 "ErrorCode,Setting Mode not supported");
5114 return 0;
5115 }
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08005116
5117 /* Change the mode only in case of testbed for HE program
5118 * and for 11a and 11g modes only. */
5119 if (dut->program == PROGRAM_HE &&
5120 dut->device_type == STA_testbed) {
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05305121 sta_set_phymode(dut, intf, val);
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08005122 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005123 }
5124
5125 val = get_param(cmd, "wmm");
5126 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005127 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005128 case DRIVER_ATHEROS:
5129 ath_sta_set_wmm(dut, intf, val);
5130 break;
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08005131 case DRIVER_WCN:
5132 wcn_sta_set_wmm(dut, intf, val);
5133 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005134 default:
5135 sigma_dut_print(dut, DUT_MSG_DEBUG,
5136 "Setting wmm not supported");
5137 break;
5138 }
5139 }
5140
5141 val = get_param(cmd, "Powersave");
5142 if (val) {
5143 if (strcmp(val, "0") == 0 || strcasecmp(val, "off") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005144 if (get_driver_type(dut) == DRIVER_WCN) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +05305145 if (set_power_save_wcn(dut, intf, 2) < 0)
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005146 return 0;
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005147 }
5148
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005149 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005150 "P2P_SET ps 0") < 0)
5151 return -2;
5152 /* Make sure test modes are disabled */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005153 wpa_command(get_station_ifname(dut), "P2P_SET ps 98");
5154 wpa_command(get_station_ifname(dut), "P2P_SET ps 96");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005155 } else if (strcmp(val, "1") == 0 ||
5156 strcasecmp(val, "PSPoll") == 0 ||
5157 strcasecmp(val, "on") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005158 if (get_driver_type(dut) == DRIVER_WCN) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +05305159 if (set_power_save_wcn(dut, intf, 1) < 0)
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005160 return 0;
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005161 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005162 /* Disable default power save mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005163 wpa_command(get_station_ifname(dut), "P2P_SET ps 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005164 /* Enable PS-Poll test mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005165 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005166 "P2P_SET ps 97") < 0 ||
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005167 wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005168 "P2P_SET ps 99") < 0)
5169 return -2;
5170 } else if (strcmp(val, "2") == 0 ||
5171 strcasecmp(val, "Fast") == 0) {
5172 /* TODO */
5173 send_resp(dut, conn, SIGMA_ERROR,
5174 "ErrorCode,Powersave=Fast not supported");
5175 return 0;
5176 } else if (strcmp(val, "3") == 0 ||
5177 strcasecmp(val, "PSNonPoll") == 0) {
5178 /* Make sure test modes are disabled */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005179 wpa_command(get_station_ifname(dut), "P2P_SET ps 98");
5180 wpa_command(get_station_ifname(dut), "P2P_SET ps 96");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005181
5182 /* Enable default power save mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005183 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005184 "P2P_SET ps 1") < 0)
5185 return -2;
5186 } else
5187 return -1;
5188 }
5189
5190 val = get_param(cmd, "NoAck");
5191 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005192 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005193 case DRIVER_ATHEROS:
5194 ath_sta_set_noack(dut, intf, val);
5195 break;
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08005196#ifdef NL80211_SUPPORT
5197 case DRIVER_WCN:
5198 wcn_sta_set_noack(dut, intf, val);
5199 break;
5200#endif /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005201 default:
5202 send_resp(dut, conn, SIGMA_ERROR,
5203 "ErrorCode,Setting NoAck not supported");
5204 return 0;
5205 }
5206 }
5207
5208 val = get_param(cmd, "IgnoreChswitchProhibit");
5209 if (val) {
5210 /* TODO: Enabled/disabled */
5211 if (strcasecmp(val, "Enabled") == 0) {
5212 send_resp(dut, conn, SIGMA_ERROR,
5213 "ErrorCode,Enabling IgnoreChswitchProhibit "
5214 "not supported");
5215 return 0;
5216 }
5217 }
5218
5219 val = get_param(cmd, "TDLS");
5220 if (val) {
5221 if (strcasecmp(val, "Disabled") == 0) {
5222 if (wpa_command(intf, "SET tdls_disabled 1")) {
5223 send_resp(dut, conn, SIGMA_ERROR,
5224 "ErrorCode,Failed to disable TDLS");
5225 return 0;
5226 }
5227 } else if (strcasecmp(val, "Enabled") == 0) {
5228 if (wpa_command(intf, "SET tdls_disabled 0")) {
5229 send_resp(dut, conn, SIGMA_ERROR,
5230 "ErrorCode,Failed to enable TDLS");
5231 return 0;
5232 }
5233 } else {
5234 send_resp(dut, conn, SIGMA_ERROR,
5235 "ErrorCode,Unsupported TDLS value");
5236 return 0;
5237 }
5238 }
5239
5240 val = get_param(cmd, "TDLSmode");
5241 if (val) {
5242 if (strcasecmp(val, "Default") == 0) {
5243 wpa_command(intf, "SET tdls_testing 0");
5244 } else if (strcasecmp(val, "APProhibit") == 0) {
5245 if (wpa_command(intf, "SET tdls_testing 0x400")) {
5246 send_resp(dut, conn, SIGMA_ERROR,
5247 "ErrorCode,Failed to enable ignore "
5248 "APProhibit TDLS mode");
5249 return 0;
5250 }
5251 } else if (strcasecmp(val, "HiLoMac") == 0) {
5252 /* STA should respond with TDLS setup req for a TDLS
5253 * setup req */
5254 if (wpa_command(intf, "SET tdls_testing 0x80")) {
5255 send_resp(dut, conn, SIGMA_ERROR,
5256 "ErrorCode,Failed to enable HiLoMac "
5257 "TDLS mode");
5258 return 0;
5259 }
5260 } else if (strcasecmp(val, "WeakSecurity") == 0) {
5261 /*
5262 * Since all security modes are enabled by default when
5263 * Sigma control is used, there is no need to do
5264 * anything here.
5265 */
5266 } else if (strcasecmp(val, "ExistLink") == 0) {
5267 /*
5268 * Since we allow new TDLS Setup Request even if there
5269 * is an existing link, nothing needs to be done for
5270 * this.
5271 */
5272 } else {
5273 /* TODO:
5274 * ExistLink: STA should send TDLS setup req even if
5275 * direct link already exists
5276 */
5277 send_resp(dut, conn, SIGMA_ERROR,
5278 "ErrorCode,Unsupported TDLSmode value");
5279 return 0;
5280 }
5281 }
5282
5283 val = get_param(cmd, "FakePubKey");
5284 if (val && atoi(val) && wpa_command(intf, "SET wps_corrupt_pkhash 1")) {
5285 send_resp(dut, conn, SIGMA_ERROR,
5286 "ErrorCode,Failed to enable FakePubKey");
5287 return 0;
5288 }
5289
Amarnath Hullur Subramanyamae1042b2018-02-22 21:52:52 -08005290#ifdef NL80211_SUPPORT
5291 val = get_param(cmd, "FrgmntSupport");
5292 if (val) {
5293 if (strcasecmp(val, "Enable") == 0) {
5294 if (sta_set_he_fragmentation(dut, intf,
5295 HE_FRAG_LEVEL1)) {
5296 send_resp(dut, conn, SIGMA_ERROR,
5297 "ErrorCode,Failed to enable HE Fragmentation");
5298 return 0;
5299 }
5300 } else if (strcasecmp(val, "Disable") == 0) {
5301 if (sta_set_he_fragmentation(dut, intf,
5302 HE_FRAG_DISABLE)) {
5303 send_resp(dut, conn, SIGMA_ERROR,
5304 "ErrorCode,Failed to disable HE Fragmentation");
5305 return 0;
5306 }
5307 }
5308 }
5309#endif /* NL80211_SUPPORT */
5310
Vinita S. Maloo8a4779c2020-06-22 19:32:37 +05305311 val = get_param(cmd, "IncludeMSCSDescriptor");
5312 if (val && strcasecmp(val, "1") == 0) {
5313 char buf[128];
5314 int len;
5315
5316 len = snprintf(buf, sizeof(buf),
Veerendranath Jakkam62cde372020-08-19 18:03:06 +05305317 "MSCS add up_bitmap=F0 up_limit=7 stream_timeout=60000 frame_classifier=045F%032x",
Vinita S. Maloo8a4779c2020-06-22 19:32:37 +05305318 0);
5319
5320 if (len < 0 || len >= sizeof(buf)) {
5321 sigma_dut_print(dut, DUT_MSG_ERROR,
5322 "Failed to build MSCS Descriptor IE");
5323 return ERROR_SEND_STATUS;
5324 }
5325
5326 if (wpa_command(intf, buf) != 0) {
5327 send_resp(dut, conn, SIGMA_ERROR,
5328 "ErrorCode,Failed to include MSCS descriptor");
5329 return STATUS_SENT_ERROR;
5330 }
5331 }
5332
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005333 return 1;
5334}
5335
5336
5337static const char * ath_get_radio_name(const char *radio_name)
5338{
5339 if (radio_name == NULL)
5340 return "wifi0";
5341 if (strcmp(radio_name, "wifi1") == 0)
5342 return "wifi1";
5343 if (strcmp(radio_name, "wifi2") == 0)
5344 return "wifi2";
5345 return "wifi0";
5346}
5347
5348
5349static void ath_sta_set_txsp_stream(struct sigma_dut *dut, const char *intf,
5350 const char *val)
5351{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005352 unsigned int vht_mcsmap = 0;
5353 int txchainmask = 0;
5354 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
5355
5356 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
5357 if (dut->testbed_flag_txsp == 1) {
5358 vht_mcsmap = 0xfffc;
5359 dut->testbed_flag_txsp = 0;
5360 } else {
5361 vht_mcsmap = 0xfffe;
5362 }
5363 txchainmask = 1;
5364 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
5365 if (dut->testbed_flag_txsp == 1) {
5366 vht_mcsmap = 0xfff0;
5367 dut->testbed_flag_txsp = 0;
5368 } else {
5369 vht_mcsmap = 0xfffa;
5370 }
5371 txchainmask = 3;
5372 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
5373 if (dut->testbed_flag_txsp == 1) {
5374 vht_mcsmap = 0xffc0;
5375 dut->testbed_flag_txsp = 0;
5376 } else {
5377 vht_mcsmap = 0xffea;
5378 }
5379 txchainmask = 7;
5380 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
5381 if (dut->testbed_flag_txsp == 1) {
5382 vht_mcsmap = 0xff00;
5383 dut->testbed_flag_txsp = 0;
5384 } else {
5385 vht_mcsmap = 0xffaa;
5386 }
5387 txchainmask = 15;
5388 } else {
5389 if (dut->testbed_flag_txsp == 1) {
5390 vht_mcsmap = 0xffc0;
5391 dut->testbed_flag_txsp = 0;
5392 } else {
5393 vht_mcsmap = 0xffea;
5394 }
5395 }
5396
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005397 if (txchainmask)
5398 run_iwpriv(dut, basedev, "txchainmask %d", txchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005399
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005400 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005401}
5402
5403
5404static void ath_sta_set_rxsp_stream(struct sigma_dut *dut, const char *intf,
5405 const char *val)
5406{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005407 unsigned int vht_mcsmap = 0;
5408 int rxchainmask = 0;
5409 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
5410
5411 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
5412 if (dut->testbed_flag_rxsp == 1) {
5413 vht_mcsmap = 0xfffc;
5414 dut->testbed_flag_rxsp = 0;
5415 } else {
5416 vht_mcsmap = 0xfffe;
5417 }
5418 rxchainmask = 1;
5419 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
5420 if (dut->testbed_flag_rxsp == 1) {
5421 vht_mcsmap = 0xfff0;
5422 dut->testbed_flag_rxsp = 0;
5423 } else {
5424 vht_mcsmap = 0xfffa;
5425 }
5426 rxchainmask = 3;
5427 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
5428 if (dut->testbed_flag_rxsp == 1) {
5429 vht_mcsmap = 0xffc0;
5430 dut->testbed_flag_rxsp = 0;
5431 } else {
5432 vht_mcsmap = 0xffea;
5433 }
5434 rxchainmask = 7;
5435 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
5436 if (dut->testbed_flag_rxsp == 1) {
5437 vht_mcsmap = 0xff00;
5438 dut->testbed_flag_rxsp = 0;
5439 } else {
5440 vht_mcsmap = 0xffaa;
5441 }
5442 rxchainmask = 15;
5443 } else {
5444 if (dut->testbed_flag_rxsp == 1) {
5445 vht_mcsmap = 0xffc0;
5446 dut->testbed_flag_rxsp = 0;
5447 } else {
5448 vht_mcsmap = 0xffea;
5449 }
5450 }
5451
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005452 if (rxchainmask)
5453 run_iwpriv(dut, basedev, "rxchainmask %d", rxchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005454
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005455 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005456}
5457
5458
5459void ath_set_zero_crc(struct sigma_dut *dut, const char *val)
5460{
5461 if (strcasecmp(val, "enable") == 0) {
5462 if (system("athdiag --set --address=0x2a204 --and=0xbfffffff")
5463 != 0) {
5464 sigma_dut_print(dut, DUT_MSG_ERROR,
5465 "Disable BB_VHTSIGB_CRC_CALC failed");
5466 }
5467
5468 if (system("athdiag --set --address=0x2a204 --or=0x80000000")
5469 != 0) {
5470 sigma_dut_print(dut, DUT_MSG_ERROR,
5471 "Enable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
5472 }
5473 } else {
5474 if (system("athdiag --set --address=0x2a204 --and=0x7fffffff")
5475 != 0) {
5476 sigma_dut_print(dut, DUT_MSG_ERROR,
5477 "Disable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
5478 }
5479
5480 if (system("athdiag --set --address=0x2a204 --or=0x40000000")
5481 != 0) {
5482 sigma_dut_print(dut, DUT_MSG_ERROR,
5483 "Enable BB_VHTSIGB_CRC_CALC failed");
5484 }
5485 }
5486}
5487
5488
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005489static int wcn_sta_set_width(struct sigma_dut *dut, const char *intf,
5490 const char *val)
5491{
5492 char buf[60];
5493
5494 if (strcmp(val, "20") == 0) {
5495 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
5496 dut->chwidth = 0;
5497 } else if (strcmp(val, "40") == 0) {
5498 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 1", intf);
5499 dut->chwidth = 1;
5500 } else if (strcmp(val, "80") == 0) {
5501 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
5502 dut->chwidth = 2;
Sunil Duttb1cccac2018-05-22 21:03:12 +05305503 } else if (strcasecmp(val, "Auto") == 0) {
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005504 buf[0] = '\0';
5505 } else {
5506 sigma_dut_print(dut, DUT_MSG_ERROR, "WIDTH %s not supported",
5507 val);
5508 return -1;
5509 }
5510
5511 if (buf[0] != '\0' && system(buf) != 0) {
5512 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv chwidth failed");
5513 return -1;
5514 }
5515
5516 return 0;
5517}
5518
5519
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005520static int nlvendor_sta_set_addba_reject(struct sigma_dut *dut,
5521 const char *intf, int addbareject)
5522{
5523#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05305524 return wcn_wifi_test_config_set_u8(
5525 dut, intf,
5526 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ACCEPT_ADDBA_REQ,
5527 !addbareject);
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005528#else /* NL80211_SUPPORT */
5529 sigma_dut_print(dut, DUT_MSG_ERROR,
5530 "ADDBA_REJECT cannot be set without NL80211_SUPPORT defined");
5531 return -1;
5532#endif /* NL80211_SUPPORT */
5533}
5534
5535
5536static int sta_set_addba_reject(struct sigma_dut *dut, const char *intf,
5537 int addbareject)
5538{
5539 int ret;
5540
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005541 switch (get_driver_type(dut)) {
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005542 case DRIVER_WCN:
5543 ret = nlvendor_sta_set_addba_reject(dut, intf, addbareject);
5544 if (ret) {
5545 sigma_dut_print(dut, DUT_MSG_ERROR,
5546 "nlvendor_sta_set_addba_reject failed, ret:%d",
5547 ret);
5548 return ret;
5549 }
5550 break;
5551 default:
5552 sigma_dut_print(dut, DUT_MSG_ERROR,
5553 "errorCode,Unsupported ADDBA_REJECT with the current driver");
5554 ret = -1;
5555 break;
5556 }
5557
5558 return ret;
5559}
5560
5561
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005562static int nlvendor_config_send_addba(struct sigma_dut *dut, const char *intf,
5563 int enable)
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005564{
5565#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05305566 return wcn_wifi_test_config_set_u8(
5567 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SEND_ADDBA_REQ,
5568 enable);
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005569#else /* NL80211_SUPPORT */
5570 sigma_dut_print(dut, DUT_MSG_ERROR,
5571 "Disable addba not possible without NL80211_SUPPORT defined");
5572 return -1;
5573#endif /* NL80211_SUPPORT */
5574}
5575
5576
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305577#ifdef NL80211_SUPPORT
5578static int nl80211_sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
5579{
5580 struct nl_msg *msg;
5581 int ret = 0;
5582 int ifindex;
5583
5584 ifindex = if_nametoindex(intf);
5585 if (ifindex == 0) {
5586 sigma_dut_print(dut, DUT_MSG_ERROR,
5587 "%s: Index for interface %s failed",
5588 __func__, intf);
5589 return -1;
5590 }
5591
5592 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5593 NL80211_CMD_SET_WIPHY)) ||
5594 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) {
5595 sigma_dut_print(dut, DUT_MSG_ERROR,
5596 "%s: err in adding RTS threshold",
5597 __func__);
5598 nlmsg_free(msg);
5599 return -1;
5600 }
5601
5602 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5603 if (ret) {
5604 sigma_dut_print(dut, DUT_MSG_ERROR,
5605 "%s: err in send_and_recv_msgs, ret=%d",
5606 __func__, ret);
5607 }
5608 return ret;
5609}
5610#endif /* NL80211_SUPPORT */
5611
5612
5613static int sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
5614{
5615 char buf[100];
5616
5617#ifdef NL80211_SUPPORT
5618 if (nl80211_sta_set_rts(dut, intf, val) == 0)
5619 return 0;
5620 sigma_dut_print(dut, DUT_MSG_DEBUG,
5621 "Fall back to using iwconfig for setting RTS threshold");
5622#endif /* NL80211_SUPPORT */
5623
5624 snprintf(buf, sizeof(buf), "iwconfig %s rts %d", intf, val);
5625 if (system(buf) != 0) {
5626 sigma_dut_print(dut, DUT_MSG_ERROR,
5627 "Failed to set RTS threshold %d", val);
5628 return -1;
5629 }
5630 return 0;
5631}
5632
5633
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005634static int cmd_sta_set_wireless_common(const char *intf, struct sigma_dut *dut,
5635 struct sigma_conn *conn,
5636 struct sigma_cmd *cmd)
5637{
5638 const char *val;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005639 int ampdu = -1, addbareject = -1;
Jouni Malinen3aa72862019-05-29 23:14:51 +03005640 char buf[128];
5641 int res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005642
5643 val = get_param(cmd, "40_INTOLERANT");
5644 if (val) {
5645 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5646 /* TODO: iwpriv ht40intol through wpa_supplicant */
5647 send_resp(dut, conn, SIGMA_ERROR,
5648 "ErrorCode,40_INTOLERANT not supported");
5649 return 0;
5650 }
5651 }
5652
5653 val = get_param(cmd, "ADDBA_REJECT");
5654 if (val) {
5655 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5656 /* reject any ADDBA with status "decline" */
5657 ampdu = 0;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005658 addbareject = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005659 } else {
5660 /* accept ADDBA */
5661 ampdu = 1;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005662 addbareject = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005663 }
5664 }
5665
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005666 if (addbareject >= 0 &&
5667 sta_set_addba_reject(dut, intf, addbareject) < 0) {
5668 send_resp(dut, conn, SIGMA_ERROR,
5669 "ErrorCode,set addba_reject failed");
5670 return 0;
5671 }
5672
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005673 val = get_param(cmd, "AMPDU");
5674 if (val) {
5675 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5676 /* enable AMPDU Aggregation */
5677 if (ampdu == 0) {
5678 send_resp(dut, conn, SIGMA_ERROR,
5679 "ErrorCode,Mismatch in "
5680 "addba_reject/ampdu - "
5681 "not supported");
5682 return 0;
5683 }
5684 ampdu = 1;
5685 } else {
5686 /* disable AMPDU Aggregation */
5687 if (ampdu == 1) {
5688 send_resp(dut, conn, SIGMA_ERROR,
5689 "ErrorCode,Mismatch in "
5690 "addba_reject/ampdu - "
5691 "not supported");
5692 return 0;
5693 }
5694 ampdu = 0;
5695 }
5696 }
5697
5698 if (ampdu >= 0) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005699 int ret;
5700
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005701 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s A-MPDU aggregation",
5702 ampdu ? "Enabling" : "Disabling");
5703 snprintf(buf, sizeof(buf), "SET ampdu %d", ampdu);
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07005704 if (wpa_command(intf, buf) < 0 &&
5705 iwpriv_sta_set_ampdu(dut, intf, ampdu) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005706 send_resp(dut, conn, SIGMA_ERROR,
5707 "ErrorCode,set aggr failed");
5708 return 0;
5709 }
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005710
5711 if (ampdu == 0) {
5712 /* Disable sending of addba using nl vendor command */
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005713 ret = nlvendor_config_send_addba(dut, intf, 0);
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005714 if (ret) {
5715 sigma_dut_print(dut, DUT_MSG_ERROR,
5716 "Failed to disable addba, ret:%d",
5717 ret);
5718 }
5719 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005720 }
5721
5722 val = get_param(cmd, "AMSDU");
5723 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005724 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005725 case DRIVER_ATHEROS:
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08005726 case DRIVER_WCN:
5727 iwpriv_sta_set_amsdu(dut, intf, val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005728 break;
5729 default:
5730 if (strcmp(val, "1") == 0 ||
5731 strcasecmp(val, "Enable") == 0) {
5732 /* Enable AMSDU Aggregation */
5733 send_resp(dut, conn, SIGMA_ERROR,
5734 "ErrorCode,AMSDU aggregation not supported");
5735 return 0;
5736 }
5737 break;
5738 }
5739 }
5740
5741 val = get_param(cmd, "STBC_RX");
5742 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005743 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005744 case DRIVER_ATHEROS:
5745 ath_sta_set_stbc(dut, intf, val);
5746 break;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05305747 case DRIVER_WCN:
5748 wcn_sta_set_stbc(dut, intf, val);
5749 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005750 default:
5751 send_resp(dut, conn, SIGMA_ERROR,
5752 "ErrorCode,STBC_RX not supported");
5753 return 0;
5754 }
5755 }
5756
5757 val = get_param(cmd, "WIDTH");
5758 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005759 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005760 case DRIVER_WCN:
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005761 if (wcn_sta_set_width(dut, intf, val) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005762 send_resp(dut, conn, SIGMA_ERROR,
5763 "ErrorCode,Failed to set WIDTH");
5764 return 0;
5765 }
5766 break;
5767 case DRIVER_ATHEROS:
5768 if (ath_set_width(dut, conn, intf, val) < 0)
5769 return 0;
5770 break;
5771 default:
5772 sigma_dut_print(dut, DUT_MSG_ERROR,
5773 "Setting WIDTH not supported");
5774 break;
5775 }
5776 }
5777
5778 val = get_param(cmd, "SMPS");
5779 if (val) {
5780 /* TODO: Dynamic/0, Static/1, No Limit/2 */
5781 send_resp(dut, conn, SIGMA_ERROR,
5782 "ErrorCode,SMPS not supported");
5783 return 0;
5784 }
5785
5786 val = get_param(cmd, "TXSP_STREAM");
5787 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005788 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005789 case DRIVER_WCN:
5790 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
5791 send_resp(dut, conn, SIGMA_ERROR,
5792 "ErrorCode,Failed to set TXSP_STREAM");
5793 return 0;
5794 }
5795 break;
5796 case DRIVER_ATHEROS:
5797 ath_sta_set_txsp_stream(dut, intf, val);
5798 break;
5799 default:
5800 sigma_dut_print(dut, DUT_MSG_ERROR,
5801 "Setting TXSP_STREAM not supported");
5802 break;
5803 }
5804 }
5805
5806 val = get_param(cmd, "RXSP_STREAM");
5807 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005808 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005809 case DRIVER_WCN:
5810 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
5811 send_resp(dut, conn, SIGMA_ERROR,
5812 "ErrorCode,Failed to set RXSP_STREAM");
5813 return 0;
5814 }
5815 break;
5816 case DRIVER_ATHEROS:
5817 ath_sta_set_rxsp_stream(dut, intf, val);
5818 break;
5819 default:
5820 sigma_dut_print(dut, DUT_MSG_ERROR,
5821 "Setting RXSP_STREAM not supported");
5822 break;
5823 }
5824 }
5825
5826 val = get_param(cmd, "DYN_BW_SGNL");
5827 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005828 switch (get_driver_type(dut)) {
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005829 case DRIVER_WCN:
Peng Xuc59afd32016-11-21 15:01:11 -08005830 if (strcasecmp(val, "enable") == 0) {
5831 snprintf(buf, sizeof(buf),
5832 "iwpriv %s cwmenable 1", intf);
5833 if (system(buf) != 0) {
5834 sigma_dut_print(dut, DUT_MSG_ERROR,
5835 "iwpriv cwmenable 1 failed");
5836 return 0;
5837 }
5838 } else if (strcasecmp(val, "disable") == 0) {
5839 snprintf(buf, sizeof(buf),
5840 "iwpriv %s cwmenable 0", intf);
5841 if (system(buf) != 0) {
5842 sigma_dut_print(dut, DUT_MSG_ERROR,
5843 "iwpriv cwmenable 0 failed");
5844 return 0;
5845 }
5846 } else {
5847 sigma_dut_print(dut, DUT_MSG_ERROR,
5848 "Unsupported DYN_BW_SGL");
5849 }
5850
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005851 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
5852 if (system(buf) != 0) {
5853 sigma_dut_print(dut, DUT_MSG_ERROR,
5854 "Failed to set cts_cbw in DYN_BW_SGNL");
5855 return 0;
5856 }
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005857 break;
5858 case DRIVER_ATHEROS:
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07005859 novap_reset(dut, intf, 1);
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005860 ath_config_dyn_bw_sig(dut, intf, val);
5861 break;
5862 default:
5863 sigma_dut_print(dut, DUT_MSG_ERROR,
5864 "Failed to set DYN_BW_SGNL");
5865 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005866 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005867 }
5868
5869 val = get_param(cmd, "RTS_FORCE");
5870 if (val) {
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07005871 novap_reset(dut, intf, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005872 if (strcasecmp(val, "Enable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305873 if (sta_set_rts(dut, intf, 64) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02005874 sigma_dut_print(dut, DUT_MSG_ERROR,
5875 "Failed to set RTS_FORCE 64");
5876 }
Jouni Malinen3aa72862019-05-29 23:14:51 +03005877 res = snprintf(buf, sizeof(buf),
5878 "wifitool %s beeliner_fw_test 100 1",
5879 intf);
5880 if (res < 0 || res >= sizeof(buf) || system(buf) != 0) {
priyadharshini gowthaman270870e2015-12-09 10:10:23 -08005881 sigma_dut_print(dut, DUT_MSG_ERROR,
5882 "wifitool beeliner_fw_test 100 1 failed");
5883 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005884 } else if (strcasecmp(val, "Disable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305885 if (sta_set_rts(dut, intf, 2347) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02005886 sigma_dut_print(dut, DUT_MSG_ERROR,
5887 "Failed to set RTS_FORCE 2347");
5888 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005889 } else {
5890 send_resp(dut, conn, SIGMA_ERROR,
5891 "ErrorCode,RTS_FORCE value not supported");
5892 return 0;
5893 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005894 }
5895
5896 val = get_param(cmd, "CTS_WIDTH");
5897 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005898 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005899 case DRIVER_WCN:
5900 if (wcn_sta_set_cts_width(dut, intf, val) < 0) {
5901 send_resp(dut, conn, SIGMA_ERROR,
5902 "ErrorCode,Failed to set CTS_WIDTH");
5903 return 0;
5904 }
5905 break;
5906 case DRIVER_ATHEROS:
5907 ath_set_cts_width(dut, intf, val);
5908 break;
5909 default:
5910 sigma_dut_print(dut, DUT_MSG_ERROR,
5911 "Setting CTS_WIDTH not supported");
5912 break;
5913 }
5914 }
5915
5916 val = get_param(cmd, "BW_SGNL");
5917 if (val) {
5918 if (strcasecmp(val, "Enable") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005919 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005920 } else if (strcasecmp(val, "Disable") == 0) {
5921 /* TODO: Disable */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005922 } else {
5923 send_resp(dut, conn, SIGMA_ERROR,
5924 "ErrorCode,BW_SGNL value not supported");
5925 return 0;
5926 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005927 }
5928
5929 val = get_param(cmd, "Band");
5930 if (val) {
5931 if (strcmp(val, "2.4") == 0 || strcmp(val, "5") == 0) {
5932 /* STA supports all bands by default */
5933 } else {
5934 send_resp(dut, conn, SIGMA_ERROR,
5935 "ErrorCode,Unsupported Band");
5936 return 0;
5937 }
5938 }
5939
5940 val = get_param(cmd, "zero_crc");
5941 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005942 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005943 case DRIVER_ATHEROS:
5944 ath_set_zero_crc(dut, val);
5945 break;
5946 default:
5947 break;
5948 }
5949 }
5950
5951 return 1;
5952}
5953
5954
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005955static int sta_set_force_mcs(struct sigma_dut *dut, int force, int mcs)
5956{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005957 switch (get_driver_type(dut)) {
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005958#ifdef __linux__
5959 case DRIVER_WIL6210:
5960 return wil6210_set_force_mcs(dut, force, mcs);
5961#endif /* __linux__ */
5962 default:
5963 sigma_dut_print(dut, DUT_MSG_ERROR,
5964 "Unsupported sta_set_force_mcs with the current driver");
5965 return -1;
5966 }
5967}
5968
5969
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02005970static int sta_60g_force_rsn_ie(struct sigma_dut *dut, int state)
5971{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005972 switch (get_driver_type(dut)) {
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02005973#ifdef __linux__
5974 case DRIVER_WIL6210:
5975 return wil6210_force_rsn_ie(dut, state);
5976#endif /* __linux__ */
5977 default:
5978 sigma_dut_print(dut, DUT_MSG_ERROR,
5979 "Unsupported sta_60g_force_rsn_ie with the current driver");
5980 return -1;
5981 }
5982}
5983
5984
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005985static int sta_set_60g_common(struct sigma_dut *dut, struct sigma_conn *conn,
5986 struct sigma_cmd *cmd)
5987{
5988 const char *val;
5989 char buf[100];
5990
5991 val = get_param(cmd, "MSDUSize");
5992 if (val) {
5993 int mtu;
5994
5995 dut->amsdu_size = atoi(val);
5996 if (dut->amsdu_size > IEEE80211_MAX_DATA_LEN_DMG ||
5997 dut->amsdu_size < IEEE80211_SNAP_LEN_DMG) {
5998 sigma_dut_print(dut, DUT_MSG_ERROR,
5999 "MSDUSize %d is above max %d or below min %d",
6000 dut->amsdu_size,
6001 IEEE80211_MAX_DATA_LEN_DMG,
6002 IEEE80211_SNAP_LEN_DMG);
6003 dut->amsdu_size = 0;
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006004 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006005 }
6006
6007 mtu = dut->amsdu_size - IEEE80211_SNAP_LEN_DMG;
6008 sigma_dut_print(dut, DUT_MSG_DEBUG,
6009 "Setting amsdu_size to %d", mtu);
6010 snprintf(buf, sizeof(buf), "ifconfig %s mtu %d",
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006011 get_station_ifname(dut), mtu);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006012
6013 if (system(buf) != 0) {
6014 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
6015 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006016 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006017 }
6018 }
6019
6020 val = get_param(cmd, "BAckRcvBuf");
6021 if (val) {
6022 dut->back_rcv_buf = atoi(val);
6023 if (dut->back_rcv_buf == 0) {
6024 sigma_dut_print(dut, DUT_MSG_ERROR,
6025 "Failed to convert %s or value is 0",
6026 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006027 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006028 }
6029
6030 sigma_dut_print(dut, DUT_MSG_DEBUG,
6031 "Setting BAckRcvBuf to %s", val);
6032 }
6033
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006034 val = get_param(cmd, "MCS_FixedRate");
6035 if (val) {
6036 if (sta_set_force_mcs(dut, 1, atoi(val))) {
6037 sigma_dut_print(dut, DUT_MSG_ERROR,
6038 "Failed to force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006039 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006040 }
6041 }
6042
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006043 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006044}
6045
6046
6047static int sta_pcp_start(struct sigma_dut *dut, struct sigma_conn *conn,
6048 struct sigma_cmd *cmd)
6049{
6050 int net_id;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006051 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006052 const char *val;
6053 char buf[100];
6054
6055 dut->mode = SIGMA_MODE_STATION;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006056 ifname = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006057 if (wpa_command(ifname, "PING") != 0) {
6058 sigma_dut_print(dut, DUT_MSG_ERROR, "Supplicant not running");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006059 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006060 }
6061
6062 wpa_command(ifname, "FLUSH");
6063 net_id = add_network_common(dut, conn, ifname, cmd);
6064 if (net_id < 0) {
6065 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add network");
6066 return net_id;
6067 }
6068
6069 /* TODO: mode=2 for the AP; in the future, replace for mode PCP */
6070 if (set_network(ifname, net_id, "mode", "2") < 0) {
6071 sigma_dut_print(dut, DUT_MSG_ERROR,
6072 "Failed to set supplicant network mode");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006073 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006074 }
6075
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02006076 if (set_network(ifname, net_id, "pbss", "1") < 0)
6077 return -2;
6078
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006079 sigma_dut_print(dut, DUT_MSG_DEBUG,
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02006080 "Supplicant set network with mode 2. network_id %d",
6081 net_id);
6082
6083 if (set_network(ifname, net_id, "wps_disabled", "0") < 0) {
6084 sigma_dut_print(dut, DUT_MSG_INFO,
6085 "Failed to set supplicant to WPS ENABLE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006086 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02006087 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006088
6089 val = get_param(cmd, "Security");
6090 if (val && strcasecmp(val, "OPEN") == 0) {
6091 dut->ap_key_mgmt = AP_OPEN;
6092 if (set_network(ifname, net_id, "key_mgmt", "NONE") < 0) {
6093 sigma_dut_print(dut, DUT_MSG_ERROR,
6094 "Failed to set supplicant to %s security",
6095 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006096 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006097 }
6098 } else if (val && strcasecmp(val, "WPA2-PSK") == 0) {
6099 dut->ap_key_mgmt = AP_WPA2_PSK;
6100 if (set_network(ifname, net_id, "key_mgmt", "WPA-PSK") < 0) {
6101 sigma_dut_print(dut, DUT_MSG_ERROR,
6102 "Failed to set supplicant to %s security",
6103 val);
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, "proto", "RSN") < 0) {
6108 sigma_dut_print(dut, DUT_MSG_ERROR,
6109 "Failed to set supplicant to proto RSN");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006110 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006111 }
6112 } else if (val) {
6113 sigma_dut_print(dut, DUT_MSG_ERROR,
6114 "Requested Security %s is not supported on 60GHz",
6115 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006116 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006117 }
6118
6119 val = get_param(cmd, "Encrypt");
6120 if (val && strcasecmp(val, "AES-GCMP") == 0) {
6121 if (set_network(ifname, net_id, "pairwise", "GCMP") < 0) {
6122 sigma_dut_print(dut, DUT_MSG_ERROR,
6123 "Failed to set supplicant to pairwise GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006124 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006125 }
6126 if (set_network(ifname, net_id, "group", "GCMP") < 0) {
6127 sigma_dut_print(dut, DUT_MSG_ERROR,
6128 "Failed to set supplicant to group GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006129 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006130 }
6131 } else if (val) {
6132 sigma_dut_print(dut, DUT_MSG_ERROR,
6133 "Requested Encrypt %s is not supported on 60 GHz",
6134 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006135 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006136 }
6137
6138 val = get_param(cmd, "PSK");
6139 if (val && set_network_quoted(ifname, net_id, "psk", val) < 0) {
6140 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set psk %s",
6141 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006142 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006143 }
6144
6145 /* Convert 60G channel to freq */
6146 switch (dut->ap_channel) {
6147 case 1:
6148 val = "58320";
6149 break;
6150 case 2:
6151 val = "60480";
6152 break;
6153 case 3:
6154 val = "62640";
6155 break;
6156 default:
6157 sigma_dut_print(dut, DUT_MSG_ERROR,
6158 "Failed to configure channel %d. Not supported",
6159 dut->ap_channel);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006160 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006161 }
6162
6163 if (set_network(ifname, net_id, "frequency", val) < 0) {
6164 sigma_dut_print(dut, DUT_MSG_ERROR,
6165 "Failed to set supplicant network frequency");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006166 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006167 }
6168
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02006169 if (dut->eap_fragment) {
6170 sigma_dut_print(dut, DUT_MSG_DEBUG,
6171 "Set EAP fragment size to 128 bytes.");
6172 if (set_network(ifname, net_id, "fragment_size", "128") < 0)
6173 return ERROR_SEND_STATUS;
6174 }
6175
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006176 sigma_dut_print(dut, DUT_MSG_DEBUG,
6177 "Supplicant set network with frequency");
6178
6179 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d", net_id);
6180 if (wpa_command(ifname, buf) < 0) {
6181 sigma_dut_print(dut, DUT_MSG_INFO,
6182 "Failed to select network id %d on %s",
6183 net_id, ifname);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006184 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006185 }
6186
6187 sigma_dut_print(dut, DUT_MSG_DEBUG, "Selected network");
6188
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006189 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006190}
6191
6192
Lior David67543f52017-01-03 19:04:22 +02006193static int wil6210_set_abft_len(struct sigma_dut *dut, int abft_len)
6194{
6195 char buf[128], fname[128];
6196 FILE *f;
Jouni Malinen3aa72862019-05-29 23:14:51 +03006197 int res;
Lior David67543f52017-01-03 19:04:22 +02006198
6199 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
6200 sigma_dut_print(dut, DUT_MSG_ERROR,
6201 "failed to get wil6210 debugfs dir");
6202 return -1;
6203 }
6204
Jouni Malinen3aa72862019-05-29 23:14:51 +03006205 res = snprintf(fname, sizeof(fname), "%s/abft_len", buf);
6206 if (res < 0 || res >= sizeof(fname))
6207 return -1;
Lior David67543f52017-01-03 19:04:22 +02006208 f = fopen(fname, "w");
6209 if (!f) {
6210 sigma_dut_print(dut, DUT_MSG_ERROR,
6211 "failed to open: %s", fname);
6212 return -1;
6213 }
6214
6215 fprintf(f, "%d\n", abft_len);
6216 fclose(f);
6217
6218 return 0;
6219}
6220
6221
Alexei Avshalom Lazar49498b82019-01-31 15:16:32 +02006222int sta_set_60g_abft_len(struct sigma_dut *dut, struct sigma_conn *conn,
6223 int abft_len)
Lior David67543f52017-01-03 19:04:22 +02006224{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006225 switch (get_driver_type(dut)) {
Lior David67543f52017-01-03 19:04:22 +02006226 case DRIVER_WIL6210:
6227 return wil6210_set_abft_len(dut, abft_len);
6228 default:
6229 sigma_dut_print(dut, DUT_MSG_ERROR,
6230 "set abft_len not supported");
6231 return -1;
6232 }
6233}
6234
6235
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006236static int sta_set_60g_pcp(struct sigma_dut *dut, struct sigma_conn *conn,
6237 struct sigma_cmd *cmd)
6238{
6239 const char *val;
Lior David67543f52017-01-03 19:04:22 +02006240 unsigned int abft_len = 1; /* default is one slot */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006241
6242 if (dut->dev_role != DEVROLE_PCP) {
6243 send_resp(dut, conn, SIGMA_INVALID,
6244 "ErrorCode,Invalid DevRole");
6245 return 0;
6246 }
6247
6248 val = get_param(cmd, "SSID");
6249 if (val) {
6250 if (strlen(val) > sizeof(dut->ap_ssid) - 1) {
6251 send_resp(dut, conn, SIGMA_INVALID,
6252 "ErrorCode,Invalid SSID");
6253 return -1;
6254 }
6255
Peng Xub8fc5cc2017-05-10 17:27:28 -07006256 strlcpy(dut->ap_ssid, val, sizeof(dut->ap_ssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006257 }
6258
6259 val = get_param(cmd, "CHANNEL");
6260 if (val) {
6261 const char *pos;
6262
6263 dut->ap_channel = atoi(val);
6264 pos = strchr(val, ';');
6265 if (pos) {
6266 pos++;
6267 dut->ap_channel_1 = atoi(pos);
6268 }
6269 }
6270
6271 switch (dut->ap_channel) {
6272 case 1:
6273 case 2:
6274 case 3:
6275 break;
6276 default:
6277 sigma_dut_print(dut, DUT_MSG_ERROR,
6278 "Channel %d is not supported", dut->ap_channel);
6279 send_resp(dut, conn, SIGMA_ERROR,
6280 "Requested channel is not supported");
6281 return -1;
6282 }
6283
6284 val = get_param(cmd, "BCNINT");
6285 if (val)
6286 dut->ap_bcnint = atoi(val);
6287
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006288 val = get_param(cmd, "AllocType");
6289 if (val) {
6290 send_resp(dut, conn, SIGMA_ERROR,
6291 "ErrorCode,AllocType is not supported yet");
6292 return -1;
6293 }
6294
6295 val = get_param(cmd, "PercentBI");
6296 if (val) {
6297 send_resp(dut, conn, SIGMA_ERROR,
6298 "ErrorCode,PercentBI is not supported yet");
6299 return -1;
6300 }
6301
6302 val = get_param(cmd, "CBAPOnly");
6303 if (val) {
6304 send_resp(dut, conn, SIGMA_ERROR,
6305 "ErrorCode,CBAPOnly is not supported yet");
6306 return -1;
6307 }
6308
6309 val = get_param(cmd, "AMPDU");
6310 if (val) {
6311 if (strcasecmp(val, "Enable") == 0)
6312 dut->ap_ampdu = 1;
6313 else if (strcasecmp(val, "Disable") == 0)
6314 dut->ap_ampdu = 2;
6315 else {
6316 send_resp(dut, conn, SIGMA_ERROR,
6317 "ErrorCode,AMPDU value is not Enable nor Disabled");
6318 return -1;
6319 }
6320 }
6321
6322 val = get_param(cmd, "AMSDU");
6323 if (val) {
6324 if (strcasecmp(val, "Enable") == 0)
6325 dut->ap_amsdu = 1;
6326 else if (strcasecmp(val, "Disable") == 0)
6327 dut->ap_amsdu = 2;
6328 }
6329
6330 val = get_param(cmd, "NumMSDU");
6331 if (val) {
6332 send_resp(dut, conn, SIGMA_ERROR,
6333 "ErrorCode, NumMSDU is not supported yet");
6334 return -1;
6335 }
6336
6337 val = get_param(cmd, "ABFTLRang");
6338 if (val) {
6339 sigma_dut_print(dut, DUT_MSG_DEBUG,
Lior David67543f52017-01-03 19:04:22 +02006340 "ABFTLRang parameter %s", val);
6341 if (strcmp(val, "Gt1") == 0)
6342 abft_len = 2; /* 2 slots in this case */
6343 }
6344
6345 if (sta_set_60g_abft_len(dut, conn, abft_len)) {
6346 send_resp(dut, conn, SIGMA_ERROR,
6347 "ErrorCode, Can't set ABFT length");
6348 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006349 }
6350
6351 if (sta_pcp_start(dut, conn, cmd) < 0) {
6352 send_resp(dut, conn, SIGMA_ERROR,
6353 "ErrorCode, Can't start PCP role");
6354 return -1;
6355 }
6356
6357 return sta_set_60g_common(dut, conn, cmd);
6358}
6359
6360
6361static int sta_set_60g_sta(struct sigma_dut *dut, struct sigma_conn *conn,
6362 struct sigma_cmd *cmd)
6363{
6364 const char *val = get_param(cmd, "DiscoveryMode");
6365
6366 if (dut->dev_role != DEVROLE_STA) {
6367 send_resp(dut, conn, SIGMA_INVALID,
6368 "ErrorCode,Invalid DevRole");
6369 return 0;
6370 }
6371
6372 if (val) {
6373 sigma_dut_print(dut, DUT_MSG_DEBUG, "Discovery: %s", val);
6374 /* Ignore Discovery mode till Driver expose API. */
6375#if 0
6376 if (strcasecmp(val, "1") == 0) {
6377 send_resp(dut, conn, SIGMA_INVALID,
6378 "ErrorCode,DiscoveryMode 1 not supported");
6379 return 0;
6380 }
6381
6382 if (strcasecmp(val, "0") == 0) {
6383 /* OK */
6384 } else {
6385 send_resp(dut, conn, SIGMA_INVALID,
6386 "ErrorCode,DiscoveryMode not supported");
6387 return 0;
6388 }
6389#endif
6390 }
6391
6392 if (start_sta_mode(dut) != 0)
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006393 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006394 return sta_set_60g_common(dut, conn, cmd);
6395}
6396
6397
Jouni Malinenf7222712019-06-13 01:50:21 +03006398static enum sigma_cmd_result cmd_sta_disconnect(struct sigma_dut *dut,
6399 struct sigma_conn *conn,
6400 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006401{
6402 const char *intf = get_param(cmd, "Interface");
Jouni Malinened77e672018-01-10 16:45:13 +02006403 const char *val = get_param(cmd, "maintain_profile");
vamsi krishnad605c422017-09-20 14:56:31 +05306404
Jouni Malinened77e672018-01-10 16:45:13 +02006405 if (dut->program == PROGRAM_OCE ||
Amarnath Hullur Subramanyamebeda9e2018-01-31 03:21:48 -08006406 dut->program == PROGRAM_HE ||
Jouni Malinened77e672018-01-10 16:45:13 +02006407 (val && atoi(val) == 1)) {
vamsi krishnad605c422017-09-20 14:56:31 +05306408 wpa_command(intf, "DISCONNECT");
6409 return 1;
6410 }
6411
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006412 disconnect_station(dut);
6413 /* Try to ignore old scan results to avoid HS 2.0R2 test case failures
6414 * due to cached results. */
6415 wpa_command(intf, "SET ignore_old_scan_res 1");
6416 wpa_command(intf, "BSS_FLUSH");
6417 return 1;
6418}
6419
6420
Jouni Malinenf7222712019-06-13 01:50:21 +03006421static enum sigma_cmd_result cmd_sta_reassoc(struct sigma_dut *dut,
6422 struct sigma_conn *conn,
6423 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006424{
6425 const char *intf = get_param(cmd, "Interface");
6426 const char *bssid = get_param(cmd, "bssid");
6427 const char *val = get_param(cmd, "CHANNEL");
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006428 const char *freq_val = get_param(cmd, "ChnlFreq");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006429 struct wpa_ctrl *ctrl;
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306430 char buf[1000];
Sunil Duttd30ce092018-01-11 23:56:29 +05306431 char result[32];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006432 int res;
6433 int chan = 0;
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006434 int freq = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006435 enum sigma_cmd_result status = STATUS_SENT;
Sunil Duttd30ce092018-01-11 23:56:29 +05306436 int fastreassoc = 1;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006437 int ft_ds = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006438
6439 if (bssid == NULL) {
6440 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing bssid "
6441 "argument");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006442 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006443 }
6444
6445 if (val)
6446 chan = atoi(val);
6447
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006448 if (freq_val)
6449 freq = atoi(freq_val);
6450
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006451 if (wifi_chip_type != DRIVER_WCN && wifi_chip_type != DRIVER_AR6003) {
6452 /* The current network may be from sta_associate or
6453 * sta_hs2_associate
6454 */
6455 if (set_network(intf, dut->infra_network_id, "bssid", bssid) <
6456 0 ||
6457 set_network(intf, 0, "bssid", bssid) < 0)
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006458 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006459 }
6460
6461 ctrl = open_wpa_mon(intf);
6462 if (ctrl == NULL) {
6463 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
6464 "wpa_supplicant monitor connection");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006465 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006466 }
6467
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006468 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Sunil Duttd30ce092018-01-11 23:56:29 +05306469 sizeof(result)) < 0 ||
6470 strncmp(result, "COMPLETED", 9) != 0) {
6471 sigma_dut_print(dut, DUT_MSG_DEBUG,
6472 "sta_reassoc: Not connected");
6473 fastreassoc = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006474 } else if (dut->sta_ft_ds) {
6475 sigma_dut_print(dut, DUT_MSG_DEBUG,
6476 "sta_reassoc: Use FT-over-DS");
6477 ft_ds = 1;
Sunil Duttd30ce092018-01-11 23:56:29 +05306478 }
6479
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306480 if (dut->rsne_override) {
6481#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006482 if (get_driver_type(dut) == DRIVER_WCN &&
6483 dut->config_rsnie == 0) {
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05306484 sta_config_params(dut, intf, STA_SET_RSNIE, 1);
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306485 dut->config_rsnie = 1;
6486 }
6487#endif /* NL80211_SUPPORT */
6488 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
6489 dut->rsne_override);
6490 if (wpa_command(intf, buf) < 0) {
6491 send_resp(dut, conn, SIGMA_ERROR,
6492 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
6493 return 0;
6494 }
6495 }
6496
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006497 if (ft_ds) {
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006498 if (chan || freq) {
6499 if (!freq)
6500 freq = channel_to_freq(dut, chan);
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006501 if (!freq) {
6502 sigma_dut_print(dut, DUT_MSG_ERROR,
6503 "Invalid channel number provided: %d",
6504 chan);
6505 send_resp(dut, conn, SIGMA_INVALID,
6506 "ErrorCode,Invalid channel number");
6507 goto close_mon_conn;
6508 }
6509 res = snprintf(buf, sizeof(buf),
6510 "SCAN TYPE=ONLY freq=%d", freq);
6511 } else {
6512 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
6513 }
6514 if (res < 0 || res >= (int) sizeof(buf)) {
6515 send_resp(dut, conn, SIGMA_ERROR,
6516 "ErrorCode,snprintf failed");
6517 goto close_mon_conn;
6518 }
6519 if (wpa_command(intf, buf) < 0) {
6520 sigma_dut_print(dut, DUT_MSG_INFO,
6521 "Failed to start scan");
6522 send_resp(dut, conn, SIGMA_ERROR,
6523 "ErrorCode,scan failed");
6524 goto close_mon_conn;
6525 }
6526
6527 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
6528 buf, sizeof(buf));
6529 if (res < 0) {
6530 sigma_dut_print(dut, DUT_MSG_INFO,
6531 "Scan did not complete");
6532 send_resp(dut, conn, SIGMA_ERROR,
6533 "ErrorCode,scan did not complete");
6534 goto close_mon_conn;
6535 }
6536
6537 res = snprintf(buf, sizeof(buf), "FT_DS %s", bssid);
6538 if (res > 0 && res < (int) sizeof(buf))
6539 res = wpa_command(intf, buf);
6540
6541 if (res < 0 || res >= (int) sizeof(buf)) {
6542 send_resp(dut, conn, SIGMA_ERROR,
6543 "errorCode,FT_DS command failed");
6544 status = STATUS_SENT_ERROR;
6545 goto close_mon_conn;
6546 }
6547 } else if (wifi_chip_type == DRIVER_WCN && fastreassoc) {
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006548 if (chan || freq) {
6549 if (!freq)
6550 freq = channel_to_freq(dut, chan);
Ashwini Patil4c8158f2017-05-25 12:49:21 +05306551 if (!freq) {
6552 sigma_dut_print(dut, DUT_MSG_ERROR,
6553 "Invalid channel number provided: %d",
6554 chan);
6555 send_resp(dut, conn, SIGMA_INVALID,
6556 "ErrorCode,Invalid channel number");
6557 goto close_mon_conn;
6558 }
6559 res = snprintf(buf, sizeof(buf),
6560 "SCAN TYPE=ONLY freq=%d", freq);
6561 } else {
6562 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
6563 }
6564 if (res < 0 || res >= (int) sizeof(buf)) {
6565 send_resp(dut, conn, SIGMA_ERROR,
6566 "ErrorCode,snprintf failed");
6567 goto close_mon_conn;
6568 }
6569 if (wpa_command(intf, buf) < 0) {
6570 sigma_dut_print(dut, DUT_MSG_INFO,
6571 "Failed to start scan");
6572 send_resp(dut, conn, SIGMA_ERROR,
6573 "ErrorCode,scan failed");
6574 goto close_mon_conn;
6575 }
6576
6577 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
6578 buf, sizeof(buf));
6579 if (res < 0) {
6580 sigma_dut_print(dut, DUT_MSG_INFO,
6581 "Scan did not complete");
6582 send_resp(dut, conn, SIGMA_ERROR,
6583 "ErrorCode,scan did not complete");
6584 goto close_mon_conn;
6585 }
6586
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006587 if (set_network(intf, dut->infra_network_id, "bssid", "any")
6588 < 0) {
6589 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
6590 "bssid to any during FASTREASSOC");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006591 status = ERROR_SEND_STATUS;
Ashwini Patil467efef2017-05-25 12:18:27 +05306592 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006593 }
Vinita Maloo54b78cf2020-03-30 12:18:19 +05306594 res = snprintf(buf, sizeof(buf), "FASTREASSOC %s %d",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006595 bssid, chan);
Vinita Maloo54b78cf2020-03-30 12:18:19 +05306596 if (res < 0 || res >= (int) sizeof(buf) ||
6597 wcn_driver_cmd(intf, buf) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006598 send_resp(dut, conn, SIGMA_ERROR,
Vinita Maloo54b78cf2020-03-30 12:18:19 +05306599 "errorCode,Failed to run FASTREASSOC");
Ashwini Patil467efef2017-05-25 12:18:27 +05306600 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006601 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006602 sigma_dut_print(dut, DUT_MSG_INFO,
6603 "sta_reassoc: Run %s successful", buf);
6604 } else if (wpa_command(intf, "REASSOCIATE")) {
6605 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
6606 "request reassociation");
Ashwini Patil467efef2017-05-25 12:18:27 +05306607 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006608 }
6609
6610 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
6611 buf, sizeof(buf));
Ashwini Patil467efef2017-05-25 12:18:27 +05306612 if (res < 0) {
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006613 send_resp(dut, conn, SIGMA_ERROR,
6614 "errorCode,Connection did not complete");
6615 status = STATUS_SENT_ERROR;
Ashwini Patil467efef2017-05-25 12:18:27 +05306616 goto close_mon_conn;
6617 }
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006618 status = SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006619
Ashwini Patil467efef2017-05-25 12:18:27 +05306620close_mon_conn:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006621 wpa_ctrl_detach(ctrl);
6622 wpa_ctrl_close(ctrl);
Ashwini Patil467efef2017-05-25 12:18:27 +05306623 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006624}
6625
6626
6627static void hs2_clear_credentials(const char *intf)
6628{
6629 wpa_command(intf, "REMOVE_CRED all");
6630}
6631
6632
Lior Davidcc88b562017-01-03 18:52:09 +02006633#ifdef __linux__
6634static int wil6210_get_aid(struct sigma_dut *dut, const char *bssid,
6635 unsigned int *aid)
6636{
Lior David0fe101e2017-03-09 16:09:50 +02006637 const char *pattern = "AID[ \t]+([0-9]+)";
Lior Davidcc88b562017-01-03 18:52:09 +02006638
Lior David0fe101e2017-03-09 16:09:50 +02006639 return wil6210_get_sta_info_field(dut, bssid, pattern, aid);
Lior Davidcc88b562017-01-03 18:52:09 +02006640}
6641#endif /* __linux__ */
6642
6643
6644static int sta_get_aid_60g(struct sigma_dut *dut, const char *bssid,
6645 unsigned int *aid)
6646{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006647 switch (get_driver_type(dut)) {
Lior Davidcc88b562017-01-03 18:52:09 +02006648#ifdef __linux__
6649 case DRIVER_WIL6210:
6650 return wil6210_get_aid(dut, bssid, aid);
6651#endif /* __linux__ */
6652 default:
6653 sigma_dut_print(dut, DUT_MSG_ERROR, "get AID not supported");
6654 return -1;
6655 }
6656}
6657
6658
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006659static int sta_get_parameter_60g(struct sigma_dut *dut, struct sigma_conn *conn,
6660 struct sigma_cmd *cmd)
6661{
6662 char buf[MAX_CMD_LEN];
6663 char bss_list[MAX_CMD_LEN];
6664 const char *parameter = get_param(cmd, "Parameter");
6665
6666 if (parameter == NULL)
6667 return -1;
6668
Lior Davidcc88b562017-01-03 18:52:09 +02006669 if (strcasecmp(parameter, "AID") == 0) {
6670 unsigned int aid = 0;
6671 char bssid[20];
6672
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006673 if (get_wpa_status(get_station_ifname(dut), "bssid",
Lior Davidcc88b562017-01-03 18:52:09 +02006674 bssid, sizeof(bssid)) < 0) {
6675 sigma_dut_print(dut, DUT_MSG_ERROR,
6676 "could not get bssid");
6677 return -2;
6678 }
6679
6680 if (sta_get_aid_60g(dut, bssid, &aid))
6681 return -2;
6682
6683 snprintf(buf, sizeof(buf), "aid,%d", aid);
6684 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
6685 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6686 return 0;
6687 }
6688
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006689 if (strcasecmp(parameter, "DiscoveredDevList") == 0) {
6690 char *bss_line;
6691 char *bss_id = NULL;
6692 const char *ifname = get_param(cmd, "Interface");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306693 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006694
6695 if (ifname == NULL) {
6696 sigma_dut_print(dut, DUT_MSG_INFO,
6697 "For get DiscoveredDevList need Interface name.");
6698 return -1;
6699 }
6700
6701 /*
6702 * Use "BSS RANGE=ALL MASK=0x2" which provides a list
6703 * of BSSIDs in "bssid=<BSSID>\n"
6704 */
6705 if (wpa_command_resp(ifname, "BSS RANGE=ALL MASK=0x2",
6706 bss_list,
6707 sizeof(bss_list)) < 0) {
6708 sigma_dut_print(dut, DUT_MSG_ERROR,
6709 "Failed to get bss list");
6710 return -1;
6711 }
6712
6713 sigma_dut_print(dut, DUT_MSG_DEBUG,
6714 "bss list for ifname:%s is:%s",
6715 ifname, bss_list);
6716
6717 snprintf(buf, sizeof(buf), "DeviceList");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306718 bss_line = strtok_r(bss_list, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006719 while (bss_line) {
6720 if (sscanf(bss_line, "bssid=%ms", &bss_id) > 0 &&
6721 bss_id) {
6722 int len;
6723
6724 len = snprintf(buf + strlen(buf),
6725 sizeof(buf) - strlen(buf),
6726 ",%s", bss_id);
6727 free(bss_id);
6728 bss_id = NULL;
6729 if (len < 0) {
6730 sigma_dut_print(dut,
6731 DUT_MSG_ERROR,
6732 "Failed to read BSSID");
6733 send_resp(dut, conn, SIGMA_ERROR,
6734 "ErrorCode,Failed to read BSS ID");
6735 return 0;
6736 }
6737
6738 if ((size_t) len >= sizeof(buf) - strlen(buf)) {
6739 sigma_dut_print(dut,
6740 DUT_MSG_ERROR,
6741 "Response buf too small for list");
6742 send_resp(dut, conn,
6743 SIGMA_ERROR,
6744 "ErrorCode,Response buf too small for list");
6745 return 0;
6746 }
6747 }
6748
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306749 bss_line = strtok_r(NULL, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006750 }
6751
6752 sigma_dut_print(dut, DUT_MSG_INFO, "DiscoveredDevList is %s",
6753 buf);
6754 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6755 return 0;
6756 }
6757
6758 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6759 return 0;
6760}
6761
6762
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006763static int sta_get_parameter_he(struct sigma_dut *dut, struct sigma_conn *conn,
6764 struct sigma_cmd *cmd)
6765{
6766 char buf[MAX_CMD_LEN];
6767 const char *parameter = get_param(cmd, "Parameter");
6768
6769 if (!parameter)
6770 return -1;
6771
6772 if (strcasecmp(parameter, "RSSI") == 0) {
6773 char rssi[10];
6774
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006775 if (get_wpa_signal_poll(dut, get_station_ifname(dut), "RSSI",
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006776 rssi, sizeof(rssi)) < 0) {
6777 sigma_dut_print(dut, DUT_MSG_ERROR,
6778 "Could not get RSSI");
6779 return -2;
6780 }
6781
6782 snprintf(buf, sizeof(buf), "rssi,%s", rssi);
6783 sigma_dut_print(dut, DUT_MSG_INFO, "RSSI %s", buf);
6784 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6785 return 0;
6786 }
6787
6788 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6789 return 0;
6790}
6791
6792
Veerendranath Jakkamd0ad6ef2020-05-21 17:09:26 +05306793#ifdef NL80211_SUPPORT
6794
6795struct station_info {
6796 uint64_t filled;
6797 uint32_t beacon_mic_error_count;
6798 uint32_t beacon_replay_count;
6799};
6800
6801
6802static int qca_get_sta_info_handler(struct nl_msg *msg, void *arg)
6803{
6804 struct nlattr *tb[NL80211_ATTR_MAX + 1];
6805 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
6806 struct station_info *data = arg;
6807 struct nlattr *info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_MAX + 1];
6808 static struct nla_policy info_policy[
6809 QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_MAX + 1] = {
6810 [QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT] = {
6811 .type = NLA_U32
6812 },
6813 [QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT] = {
6814 .type = NLA_U32
6815 },
6816 };
6817
6818 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
6819 genlmsg_attrlen(gnlh, 0), NULL);
6820
6821 if (!tb[NL80211_ATTR_VENDOR_DATA])
6822 return NL_SKIP;
6823
6824 if (nla_parse_nested(info, QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_MAX,
6825 tb[NL80211_ATTR_VENDOR_DATA], info_policy)) {
6826 return NL_SKIP;
6827 }
6828
6829 if (info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT]) {
6830 data->filled |=
6831 BIT_ULL(QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT);
6832 data->beacon_mic_error_count =
6833 nla_get_u32(info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT]);
6834 }
6835
6836 if (info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT]) {
6837 data->filled |=
6838 BIT_ULL(QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT);
6839 data->beacon_replay_count =
6840 nla_get_u32(info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT]);
6841 }
6842
6843 return NL_SKIP;
6844}
6845
6846
6847static int qca_nl80211_get_sta_info(struct sigma_dut *dut, const char *intf,
6848 struct station_info *sta_data)
6849{
6850 struct nl_msg *msg;
6851 int ifindex, ret;
6852
6853 ifindex = if_nametoindex(intf);
6854 if (ifindex == 0) {
6855 sigma_dut_print(dut, DUT_MSG_ERROR,
6856 "%s: Index for interface %s not found",
6857 __func__, intf);
6858 return -1;
6859 }
6860
6861 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6862 NL80211_CMD_VENDOR)) ||
6863 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6864 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6865 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6866 QCA_NL80211_VENDOR_SUBCMD_GET_STA_INFO)) {
6867 sigma_dut_print(dut, DUT_MSG_ERROR,
6868 "%s: err in adding vendor_cmd", __func__);
6869 nlmsg_free(msg);
6870 return -1;
6871 }
6872
6873 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg,
6874 qca_get_sta_info_handler, sta_data);
6875 if (ret) {
6876 sigma_dut_print(dut, DUT_MSG_ERROR,
6877 "%s: err in send_and_recv_msgs, ret=%d",
6878 __func__, ret);
6879 }
6880 return ret;
6881}
6882#endif /* NL80211_SUPPORT */
6883
6884
6885static int get_bip_mic_error_count(struct sigma_dut *dut,
6886 const char *ifname,
6887 unsigned int *count)
6888{
6889#ifdef NL80211_SUPPORT
6890 struct station_info sta_data;
6891#endif /* NL80211_SUPPORT */
6892
6893 if (get_driver_type(dut) != DRIVER_WCN) {
6894 sigma_dut_print(dut, DUT_MSG_ERROR,
6895 "BIP MIC error count not supported");
6896 return -1;
6897 }
6898
6899#ifdef NL80211_SUPPORT
6900 if (qca_nl80211_get_sta_info(dut, ifname, &sta_data) != 0 ||
6901 !(sta_data.filled &
6902 BIT_ULL(QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT))) {
6903 sigma_dut_print(dut, DUT_MSG_ERROR,
6904 "BIP MIC error count fetching failed");
6905 return -1;
6906 }
6907
6908 *count = sta_data.beacon_mic_error_count;
6909 return 0;
6910#else /* NL80211_SUPPORT */
6911 sigma_dut_print(dut, DUT_MSG_ERROR,
6912 "BIP MIC error count cannot be fetched without NL80211_SUPPORT defined");
6913 return -1;
6914#endif /* NL80211_SUPPORT */
6915}
6916
6917
6918static int get_cmac_replay_count(struct sigma_dut *dut, const char *ifname,
6919 unsigned int *count)
6920{
6921#ifdef NL80211_SUPPORT
6922 struct station_info sta_data;
6923#endif /* NL80211_SUPPORT */
6924
6925 if (get_driver_type(dut) != DRIVER_WCN) {
6926 sigma_dut_print(dut, DUT_MSG_ERROR,
6927 "CMAC reply count not supported");
6928 return -1;
6929 }
6930
6931#ifdef NL80211_SUPPORT
6932 if (qca_nl80211_get_sta_info(dut, ifname, &sta_data) != 0 ||
6933 !(sta_data.filled &
6934 BIT_ULL(QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT))) {
6935 sigma_dut_print(dut, DUT_MSG_ERROR,
6936 "CMAC replay count fetching failed");
6937 return -1;
6938 }
6939
6940 *count = sta_data.beacon_replay_count;
6941 return 0;
6942#else /* NL80211_SUPPORT */
6943 sigma_dut_print(dut, DUT_MSG_ERROR,
6944 "CMAC replay count cannot be fetched without NL80211_SUPPORT defined");
6945 return -1;
6946#endif /* NL80211_SUPPORT */
6947}
6948
6949
6950static enum sigma_cmd_result sta_get_parameter_wpa3(struct sigma_dut *dut,
6951 struct sigma_conn *conn,
6952 struct sigma_cmd *cmd)
6953{
6954 char buf[MAX_CMD_LEN];
6955 const char *ifname = get_param(cmd, "interface");
6956 const char *parameter = get_param(cmd, "Parameter");
6957 unsigned int val;
6958
6959 if (!ifname || !parameter)
6960 return INVALID_SEND_STATUS;
6961
6962 if (strcasecmp(parameter, "BIPMICErrors") == 0) {
6963 if (get_bip_mic_error_count(dut, ifname, &val)) {
6964 send_resp(dut, conn, SIGMA_ERROR,
6965 "ErrorCode,Failed to get BIPMICErrors");
6966 return STATUS_SENT_ERROR;
6967 }
6968 snprintf(buf, sizeof(buf), "BIPMICErrors,%d", val);
6969 sigma_dut_print(dut, DUT_MSG_INFO, "BIPMICErrors %s", buf);
6970 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6971 return STATUS_SENT;
6972 }
6973
6974 if (strcasecmp(parameter, "CMACReplays") == 0) {
6975 if (get_cmac_replay_count(dut, ifname, &val)) {
6976 send_resp(dut, conn, SIGMA_ERROR,
6977 "ErrorCode,Failed to get CMACReplays");
6978 return STATUS_SENT_ERROR;
6979 }
6980 snprintf(buf, sizeof(buf), "CMACReplays,%d", val);
6981 sigma_dut_print(dut, DUT_MSG_INFO, "CMACReplays %s", buf);
6982 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6983 return STATUS_SENT;
6984 }
6985
6986 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6987 return STATUS_SENT_ERROR;
6988}
6989
6990
Jouni Malinenca0abd32020-02-09 20:18:10 +02006991static enum sigma_cmd_result sta_get_pmk(struct sigma_dut *dut,
6992 struct sigma_conn *conn,
6993 struct sigma_cmd *cmd)
6994{
6995 const char *intf = get_param(cmd, "Interface");
6996 char buf[4096], bssid[20], resp[200], *pos, *tmp;
6997
6998 snprintf(buf, sizeof(buf), "PMKSA_GET %d", dut->infra_network_id);
6999 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
7000 strncmp(buf, "UNKNOWN COMMAND", 15) == 0) {
7001 send_resp(dut, conn, SIGMA_ERROR,
7002 "ErrorCode,PMKSA_GET not supported");
7003 return STATUS_SENT_ERROR;
7004 }
7005
7006 if (strncmp(buf, "FAIL", 4) == 0 ||
7007 get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
7008 send_resp(dut, conn, SIGMA_ERROR,
7009 "ErrorCode,Could not find current network");
7010 return STATUS_SENT_ERROR;
7011 }
7012
7013 pos = buf;
7014 while (pos) {
7015 if (strncmp(pos, bssid, 17) == 0) {
7016 pos = strchr(pos, ' ');
7017 if (!pos)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05307018 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02007019 pos++;
7020 pos = strchr(pos, ' ');
7021 if (!pos)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05307022 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02007023 pos++;
7024 tmp = strchr(pos, ' ');
7025 if (!tmp)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05307026 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02007027 *tmp = '\0';
7028 break;
7029 }
Jouni Malinenca0abd32020-02-09 20:18:10 +02007030 pos = strchr(pos, '\n');
7031 if (pos)
7032 pos++;
7033 }
7034
7035 if (!pos) {
7036 send_resp(dut, conn, SIGMA_ERROR,
7037 "ErrorCode,PMK not available");
7038 return STATUS_SENT_ERROR;
7039 }
7040
7041 snprintf(resp, sizeof(resp), "PMK,%s", pos);
7042 send_resp(dut, conn, SIGMA_COMPLETE, resp);
7043 return STATUS_SENT;
7044}
7045
7046
Jouni Malinenf7222712019-06-13 01:50:21 +03007047static enum sigma_cmd_result cmd_sta_get_parameter(struct sigma_dut *dut,
7048 struct sigma_conn *conn,
7049 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007050{
7051 const char *program = get_param(cmd, "Program");
Jouni Malinenca0abd32020-02-09 20:18:10 +02007052 const char *parameter = get_param(cmd, "Parameter");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007053
Jouni Malinenca0abd32020-02-09 20:18:10 +02007054 if (!parameter)
7055 return INVALID_SEND_STATUS;
7056
7057 if (strcasecmp(parameter, "PMK") == 0)
7058 return sta_get_pmk(dut, conn, cmd);
7059
7060 if (!program)
7061 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007062
7063 if (strcasecmp(program, "P2PNFC") == 0)
7064 return p2p_cmd_sta_get_parameter(dut, conn, cmd);
7065
7066 if (strcasecmp(program, "60ghz") == 0)
7067 return sta_get_parameter_60g(dut, conn, cmd);
7068
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07007069 if (strcasecmp(program, "he") == 0)
7070 return sta_get_parameter_he(dut, conn, cmd);
7071
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007072#ifdef ANDROID_NAN
7073 if (strcasecmp(program, "NAN") == 0)
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07007074 return nan_cmd_sta_get_parameter(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007075#endif /* ANDROID_NAN */
7076
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007077#ifdef MIRACAST
7078 if (strcasecmp(program, "WFD") == 0 ||
7079 strcasecmp(program, "DisplayR2") == 0)
7080 return miracast_cmd_sta_get_parameter(dut, conn, cmd);
7081#endif /* MIRACAST */
Veerendranath Jakkamd0ad6ef2020-05-21 17:09:26 +05307082 if (strcasecmp(program, "WPA3") == 0)
7083 return sta_get_parameter_wpa3(dut, conn, cmd);
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007084
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007085 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7086 return 0;
7087}
7088
7089
7090static void sta_reset_default_ath(struct sigma_dut *dut, const char *intf,
7091 const char *type)
7092{
7093 char buf[100];
7094
7095 if (dut->program == PROGRAM_VHT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007096 run_iwpriv(dut, intf, "chwidth 2");
7097 run_iwpriv(dut, intf, "mode 11ACVHT80");
7098 run_iwpriv(dut, intf, "vhtmcs -1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007099 }
7100
7101 if (dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007102 run_iwpriv(dut, intf, "chwidth 0");
7103 run_iwpriv(dut, intf, "mode 11naht40");
7104 run_iwpriv(dut, intf, "set11NRates 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007105 }
7106
7107 if (dut->program == PROGRAM_VHT || dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007108 run_iwpriv(dut, intf, "powersave 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007109
7110 /* Reset CTS width */
7111 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 54 0",
7112 intf);
7113 if (system(buf) != 0) {
7114 sigma_dut_print(dut, DUT_MSG_ERROR,
7115 "wifitool %s beeliner_fw_test 54 0 failed",
7116 intf);
7117 }
7118
7119 /* Enable Dynamic Bandwidth signalling by default */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007120 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007121
7122 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", intf);
7123 if (system(buf) != 0) {
7124 sigma_dut_print(dut, DUT_MSG_ERROR,
7125 "iwpriv rts failed");
7126 }
7127 }
7128
7129 if (type && strcasecmp(type, "Testbed") == 0) {
7130 dut->testbed_flag_txsp = 1;
7131 dut->testbed_flag_rxsp = 1;
7132 /* STA has to set spatial stream to 2 per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007133 run_iwpriv(dut, intf, "vht_mcsmap 0xfff0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007134
7135 /* Disable LDPC per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007136 run_iwpriv(dut, intf, "ldpc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007137
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007138 run_iwpriv(dut, intf, "amsdu 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007139
7140 /* TODO: Disable STBC 2x1 transmit and receive */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007141 run_iwpriv(dut, intf, "tx_stbc 0");
7142 run_iwpriv(dut, intf, "rx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007143
7144 /* STA has to disable Short GI per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007145 run_iwpriv(dut, intf, "shortgi 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007146 }
7147
7148 if (type && strcasecmp(type, "DUT") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007149 run_iwpriv(dut, intf, "nss 3");
Arif Hussainac6c5112018-05-25 17:34:00 -07007150 dut->sta_nss = 3;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007151
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007152 run_iwpriv(dut, intf, "shortgi 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007153 }
7154}
7155
7156
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007157#ifdef NL80211_SUPPORT
7158static int sta_set_he_mcs(struct sigma_dut *dut, const char *intf,
7159 enum he_mcs_config mcs)
7160{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307161 return wcn_wifi_test_config_set_u8(
7162 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MCS, mcs);
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007163}
7164#endif /* NL80211_SUPPORT */
7165
7166
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07007167static int sta_set_action_tx_in_he_tb_ppdu(struct sigma_dut *dut,
7168 const char *intf, int enable)
7169{
7170#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307171 return wcn_wifi_test_config_set_u8(
7172 dut, intf,
7173 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_ACTION_TX_TB_PPDU,
7174 enable);
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07007175#else /* NL80211_SUPPORT */
7176 sigma_dut_print(dut, DUT_MSG_ERROR,
7177 "HE action Tx TB PPDU cannot be set without NL80211_SUPPORT defined");
7178 return -1;
7179#endif /* NL80211_SUPPORT */
7180}
7181
7182
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08007183static int sta_set_heconfig_and_wep_tkip(struct sigma_dut *dut,
7184 const char *intf, int enable)
7185{
7186#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307187 return wcn_wifi_test_config_set_u8(
7188 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WEP_TKIP_IN_HE,
7189 enable);
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08007190#else /* NL80211_SUPPORT */
7191 sigma_dut_print(dut, DUT_MSG_ERROR,
7192 "HE config enablement cannot be changed without NL80211_SUPPORT defined");
7193 return -1;
7194#endif /* NL80211_SUPPORT */
7195}
7196
7197
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007198#ifdef NL80211_SUPPORT
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007199
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007200static int sta_set_he_testbed_def(struct sigma_dut *dut,
7201 const char *intf, int cfg)
7202{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307203 return wcn_wifi_test_config_set_u8(
7204 dut, intf,
7205 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SET_HE_TESTBED_DEFAULTS,
7206 cfg);
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007207}
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007208
7209
7210static int sta_set_2g_vht_supp(struct sigma_dut *dut, const char *intf, int cfg)
7211{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307212 return wcn_wifi_test_config_set_u8(
7213 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_2G_VHT,
7214 cfg);
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007215}
7216
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007217#endif /* NL80211_SUPPORT */
7218
7219
Qiwei Caib6806972020-01-15 13:52:11 +08007220int sta_set_addba_buf_size(struct sigma_dut *dut,
7221 const char *intf, int bufsize)
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007222{
7223#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307224 return wcn_wifi_test_config_set_u16(
7225 dut, intf,
7226 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE, bufsize);
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007227#else /* NL80211_SUPPORT */
7228 sigma_dut_print(dut, DUT_MSG_ERROR,
7229 "AddBA bufsize cannot be changed without NL80211_SUPPORT defined");
7230 return -1;
7231#endif /* NL80211_SUPPORT */
7232}
7233
7234
Arif Hussain8d5b27b2018-05-14 14:31:03 -07007235static int sta_set_tx_beamformee(struct sigma_dut *dut, const char *intf,
7236 int enable)
7237{
7238#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307239 return wcn_wifi_test_config_set_u8(
7240 dut, intf,
7241 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_TX_BEAMFORMEE,
7242 enable);
Arif Hussain8d5b27b2018-05-14 14:31:03 -07007243#else /* NL80211_SUPPORT */
7244 sigma_dut_print(dut, DUT_MSG_ERROR,
7245 "tx beamformee cannot be changed without NL80211_SUPPORT defined");
7246 return -1;
7247#endif /* NL80211_SUPPORT */
7248}
7249
7250
Arif Hussain9765f7d2018-07-03 08:28:26 -07007251static int sta_set_beamformee_sts(struct sigma_dut *dut, const char *intf,
7252 int val)
7253{
7254#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307255 return wcn_wifi_test_config_set_u8(
7256 dut, intf,
7257 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_BEAMFORMEE_NSTS,
7258 val);
Arif Hussain9765f7d2018-07-03 08:28:26 -07007259#else /* NL80211_SUPPORT */
7260 sigma_dut_print(dut, DUT_MSG_ERROR,
7261 "beamformee sts cannot be changed without NL80211_SUPPORT defined");
7262 return -1;
7263#endif /* NL80211_SUPPORT */
7264}
7265
7266
Arif Hussain68d23f52018-07-11 13:39:08 -07007267#ifdef NL80211_SUPPORT
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007268static int sta_set_mac_padding_duration(struct sigma_dut *dut, const char *intf,
7269 enum qca_wlan_he_mac_padding_dur val)
7270{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307271 return wcn_wifi_test_config_set_u8(
7272 dut, intf,
7273 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MAC_PADDING_DUR, val);
Arif Hussain68d23f52018-07-11 13:39:08 -07007274}
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007275#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07007276
7277
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07007278static int sta_set_tx_su_ppdu_cfg(struct sigma_dut *dut, const char *intf,
7279 int val)
7280{
7281#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307282 return wcn_wifi_test_config_set_u8(
7283 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_SUPPDU,
7284 val);
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07007285#else /* NL80211_SUPPORT */
7286 sigma_dut_print(dut, DUT_MSG_ERROR,
7287 "Tx SU PPDU cannot be set without NL80211_SUPPORT defined");
7288 return -1;
7289#endif /* NL80211_SUPPORT */
7290}
7291
7292
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007293#ifdef NL80211_SUPPORT
7294static int sta_set_he_om_ctrl_reset(struct sigma_dut *dut, const char *intf)
7295{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307296 return wcn_wifi_test_config_set_flag(
7297 dut, intf,
7298 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_CLEAR_HE_OM_CTRL_CONFIG);
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007299}
7300#endif /* NL80211_SUPPORT */
7301
7302
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07007303static int sta_set_mu_edca_override(struct sigma_dut *dut, const char *intf,
7304 int val)
7305{
7306#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307307 return wcn_wifi_test_config_set_u8(
7308 dut, intf,
7309 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_OVERRIDE_MU_EDCA, val);
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07007310#else /* NL80211_SUPPORT */
7311 sigma_dut_print(dut, DUT_MSG_ERROR,
7312 "MU EDCA override cannot be changed without NL80211_SUPPORT defined");
7313 return -1;
7314#endif /* NL80211_SUPPORT */
7315}
7316
7317
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007318static int sta_set_om_ctrl_supp(struct sigma_dut *dut, const char *intf,
7319 int val)
7320{
7321#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307322 return wcn_wifi_test_config_set_u8(
7323 dut, intf,
7324 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OM_CTRL_SUPP, val);
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007325#else /* NL80211_SUPPORT */
7326 sigma_dut_print(dut, DUT_MSG_ERROR,
7327 "HE OM ctrl cannot be changed without NL80211_SUPPORT defined");
7328 return -1;
7329#endif /* NL80211_SUPPORT */
7330}
7331
7332
Arif Hussain480d5f42019-03-12 14:40:42 -07007333static int sta_set_twt_req_support(struct sigma_dut *dut, const char *intf,
7334 int val)
7335{
7336#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307337 return wcn_wifi_test_config_set_u8(
7338 dut, intf,
7339 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TWT_REQ_SUPPORT, val);
Arif Hussain480d5f42019-03-12 14:40:42 -07007340#else /* NL80211_SUPPORT */
7341 sigma_dut_print(dut, DUT_MSG_ERROR,
7342 "TWT Request cannot be changed without NL80211_SUPPORT defined");
7343 return -1;
7344#endif /* NL80211_SUPPORT */
7345}
7346
7347
Srinivas Girigowda0525e292020-11-12 13:28:21 -08007348static int sta_set_fullbw_ulmumimo(struct sigma_dut *dut, const char *intf,
7349 int val)
7350{
7351#ifdef NL80211_SUPPORT
7352 return wcn_wifi_test_config_set_u8(
7353 dut, intf,
7354 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_FULL_BW_UL_MU_MIMO, val);
7355#else /* NL80211_SUPPORT */
7356 sigma_dut_print(dut, DUT_MSG_ERROR,
7357 "Full BW UL MU MIMO cannot be changed without NL80211_SUPPORT defined");
7358 return -1;
7359#endif /* NL80211_SUPPORT */
7360}
7361
7362
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007363static void sta_reset_default_wcn(struct sigma_dut *dut, const char *intf,
7364 const char *type)
7365{
7366 char buf[60];
7367
7368 if (dut->program == PROGRAM_HE) {
7369 /* resetting phymode to auto in case of HE program */
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05307370 sta_set_phymode(dut, intf, "auto");
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007371
Amarnath Hullur Subramanyam9cecb502018-04-25 13:26:30 -07007372 /* reset the rate to Auto rate */
7373 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0xff",
7374 intf);
7375 if (system(buf) != 0) {
7376 sigma_dut_print(dut, DUT_MSG_ERROR,
7377 "iwpriv %s set_11ax_rate 0xff failed",
7378 intf);
7379 }
7380
Kiran Kumar Lokere86cfe3a2018-06-01 11:55:15 -07007381 /* reset the LDPC setting */
7382 snprintf(buf, sizeof(buf), "iwpriv %s ldpc 1", intf);
7383 if (system(buf) != 0) {
7384 sigma_dut_print(dut, DUT_MSG_ERROR,
7385 "iwpriv %s ldpc 1 failed", intf);
7386 }
7387
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08007388 /* reset the power save setting */
Vinita S. Malooa8b62722020-04-23 01:45:41 +05307389 set_power_save_wcn(dut, intf, 2);
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08007390
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007391 /* remove all network profiles */
7392 remove_wpa_networks(intf);
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007393
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007394 /* Configure ADDBA Req/Rsp buffer size to be 64 */
7395 sta_set_addba_buf_size(dut, intf, 64);
7396
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08007397#ifdef NL80211_SUPPORT
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007398 /* Reset the device HE capabilities to its default supported
7399 * configuration. */
7400 sta_set_he_testbed_def(dut, intf, 0);
7401
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08007402 /* Disable noackpolicy for all AC */
7403 if (nlvendor_sta_set_noack(dut, intf, 0, QCA_WLAN_AC_ALL)) {
7404 sigma_dut_print(dut, DUT_MSG_ERROR,
7405 "Disable of noackpolicy for all AC failed");
7406 }
7407#endif /* NL80211_SUPPORT */
7408
Amarnath Hullur Subramanyamb1724a52018-03-07 14:31:46 -08007409 /* Enable WMM by default */
7410 if (wcn_sta_set_wmm(dut, intf, "on")) {
7411 sigma_dut_print(dut, DUT_MSG_ERROR,
7412 "Enable of WMM in sta_reset_default_wcn failed");
7413 }
7414
7415 /* Disable ADDBA_REJECT by default */
7416 if (nlvendor_sta_set_addba_reject(dut, intf, 0)) {
7417 sigma_dut_print(dut, DUT_MSG_ERROR,
7418 "Disable of addba_reject in sta_reset_default_wcn failed");
7419 }
7420
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08007421 /* Enable sending of ADDBA by default */
7422 if (nlvendor_config_send_addba(dut, intf, 1)) {
7423 sigma_dut_print(dut, DUT_MSG_ERROR,
7424 "Enable sending of ADDBA in sta_reset_default_wcn failed");
7425 }
7426
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08007427 /* Enable AMPDU by default */
7428 iwpriv_sta_set_ampdu(dut, intf, 1);
7429
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007430#ifdef NL80211_SUPPORT
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -08007431 if (wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_AUTO)) {
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007432 sigma_dut_print(dut, DUT_MSG_ERROR,
7433 "Set LTF config to default in sta_reset_default_wcn failed");
7434 }
Arif Hussain9765f7d2018-07-03 08:28:26 -07007435
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08007436 /* set the beamformee NSTS(maximum number of
7437 * space-time streams) to default DUT config
7438 */
7439 if (sta_set_beamformee_sts(dut, intf, 7)) {
Arif Hussain9765f7d2018-07-03 08:28:26 -07007440 sigma_dut_print(dut, DUT_MSG_ERROR,
7441 "Failed to set BeamformeeSTS");
7442 }
Arif Hussain68d23f52018-07-11 13:39:08 -07007443
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007444 if (sta_set_mac_padding_duration(
7445 dut, intf,
7446 QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07007447 sigma_dut_print(dut, DUT_MSG_ERROR,
7448 "Failed to set MAC padding duration");
7449 }
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07007450
7451 if (sta_set_mu_edca_override(dut, intf, 0)) {
7452 sigma_dut_print(dut, DUT_MSG_ERROR,
7453 "ErrorCode,Failed to set MU EDCA override disable");
7454 }
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007455
7456 if (sta_set_om_ctrl_supp(dut, intf, 1)) {
7457 sigma_dut_print(dut, DUT_MSG_ERROR,
7458 "Failed to set OM ctrl supp");
7459 }
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07007460
7461 if (sta_set_tx_su_ppdu_cfg(dut, intf, 1)) {
7462 sigma_dut_print(dut, DUT_MSG_ERROR,
7463 "Failed to set Tx SU PPDU enable");
7464 }
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007465
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07007466 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 0)) {
7467 sigma_dut_print(dut, DUT_MSG_ERROR,
7468 "failed to send TB PPDU Tx cfg");
7469 }
7470
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007471 if (sta_set_he_om_ctrl_reset(dut, intf)) {
7472 sigma_dut_print(dut, DUT_MSG_ERROR,
7473 "Failed to set OM ctrl reset");
7474 }
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08007475
7476 /* +HTC-HE support default on */
7477 if (sta_set_he_htc_supp(dut, intf, 1)) {
7478 sigma_dut_print(dut, DUT_MSG_ERROR,
7479 "Setting of +HTC-HE support failed");
7480 }
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007481#endif /* NL80211_SUPPORT */
7482
Arif Hussain8d5b27b2018-05-14 14:31:03 -07007483 if (sta_set_tx_beamformee(dut, intf, 1)) {
7484 sigma_dut_print(dut, DUT_MSG_ERROR,
7485 "Set tx beamformee enable by default in sta_reset_default_wcn failed");
7486 }
7487
Kiran Kumar Lokereb55ff442020-07-15 00:20:40 -07007488 wpa_command(intf, "SET oce 1");
7489
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007490 /* Set nss to 1 and MCS 0-7 in case of testbed */
7491 if (type && strcasecmp(type, "Testbed") == 0) {
7492#ifdef NL80211_SUPPORT
7493 int ret;
7494#endif /* NL80211_SUPPORT */
7495
Kiran Kumar Lokereb55ff442020-07-15 00:20:40 -07007496 wpa_command(intf, "SET oce 0");
7497
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007498 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
7499 if (system(buf) != 0) {
7500 sigma_dut_print(dut, DUT_MSG_ERROR,
7501 "iwpriv %s nss failed", intf);
7502 }
7503
7504#ifdef NL80211_SUPPORT
7505 ret = sta_set_he_mcs(dut, intf, HE_80_MCS0_7);
7506 if (ret) {
7507 sigma_dut_print(dut, DUT_MSG_ERROR,
7508 "Setting of MCS failed, ret:%d",
7509 ret);
7510 }
7511#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyamc67621d2018-02-04 23:18:01 -08007512
7513 /* Disable STBC as default */
7514 wcn_sta_set_stbc(dut, intf, "0");
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08007515
7516 /* Disable AMSDU as default */
7517 iwpriv_sta_set_amsdu(dut, intf, "0");
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08007518
7519#ifdef NL80211_SUPPORT
7520 /* HE fragmentation default off */
7521 if (sta_set_he_fragmentation(dut, intf,
7522 HE_FRAG_DISABLE)) {
7523 sigma_dut_print(dut, DUT_MSG_ERROR,
7524 "Setting of HE fragmentation failed");
7525 }
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08007526
7527 /* set the beamformee NSTS(maximum number of
7528 * space-time streams) to default testbed config
7529 */
7530 if (sta_set_beamformee_sts(dut, intf, 3)) {
7531 sigma_dut_print(dut, DUT_MSG_ERROR,
7532 "Failed to set BeamformeeSTS");
7533 }
7534
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08007535 /* +HTC-HE support default off */
7536 if (sta_set_he_htc_supp(dut, intf, 0)) {
7537 sigma_dut_print(dut, DUT_MSG_ERROR,
7538 "Setting of +HTC-HE support failed");
7539 }
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007540
7541 /* Set device HE capabilities to testbed default
7542 * configuration. */
7543 if (sta_set_he_testbed_def(dut, intf, 1)) {
7544 sigma_dut_print(dut, DUT_MSG_DEBUG,
7545 "Failed to set HE defaults");
7546 }
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007547
7548 /* Disable VHT support in 2.4 GHz for testbed */
7549 sta_set_2g_vht_supp(dut, intf, 0);
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08007550#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08007551
7552 /* Enable WEP/TKIP with HE capability in testbed */
7553 if (sta_set_heconfig_and_wep_tkip(dut, intf, 1)) {
7554 sigma_dut_print(dut, DUT_MSG_ERROR,
7555 "Enabling HE config with WEP/TKIP failed");
7556 }
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007557 }
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007558
7559 /* Defaults in case of DUT */
7560 if (type && strcasecmp(type, "DUT") == 0) {
Arif Hussaind48fcc72018-05-01 18:34:18 -07007561 /* Enable STBC by default */
7562 wcn_sta_set_stbc(dut, intf, "1");
7563
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007564 /* set nss to 2 */
7565 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
7566 if (system(buf) != 0) {
7567 sigma_dut_print(dut, DUT_MSG_ERROR,
7568 "iwpriv %s nss 2 failed", intf);
7569 }
Arif Hussainac6c5112018-05-25 17:34:00 -07007570 dut->sta_nss = 2;
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007571
7572#ifdef NL80211_SUPPORT
Arif Hussainae239842018-05-01 18:20:05 -07007573 /* Set HE_MCS to 0-11 */
7574 if (sta_set_he_mcs(dut, intf, HE_80_MCS0_11)) {
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007575 sigma_dut_print(dut, DUT_MSG_ERROR,
7576 "Setting of MCS failed");
7577 }
7578#endif /* NL80211_SUPPORT */
7579
7580 /* Disable WEP/TKIP with HE capability in DUT */
7581 if (sta_set_heconfig_and_wep_tkip(dut, intf, 0)) {
7582 sigma_dut_print(dut, DUT_MSG_ERROR,
7583 "Enabling HE config with WEP/TKIP failed");
7584 }
7585 }
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007586 }
7587}
7588
7589
Jouni Malinenf7222712019-06-13 01:50:21 +03007590static enum sigma_cmd_result cmd_sta_reset_default(struct sigma_dut *dut,
7591 struct sigma_conn *conn,
7592 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007593{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007594 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007595 const char *band = get_param(cmd, "band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007596 const char *type;
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007597 const char *program = get_param(cmd, "program");
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05307598 const char *dev_role = get_param(cmd, "DevRole");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007599
Jouni Malinenb21f0542019-11-04 17:53:38 +02007600 if (dut->station_ifname_2g &&
7601 strcmp(dut->station_ifname_2g, intf) == 0)
7602 dut->use_5g = 0;
7603 else if (dut->station_ifname_5g &&
7604 strcmp(dut->station_ifname_5g, intf) == 0)
7605 dut->use_5g = 1;
7606
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007607 if (!program)
7608 program = get_param(cmd, "prog");
7609 dut->program = sigma_program_to_enum(program);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007610 dut->device_type = STA_unknown;
7611 type = get_param(cmd, "type");
7612 if (type && strcasecmp(type, "Testbed") == 0)
7613 dut->device_type = STA_testbed;
7614 if (type && strcasecmp(type, "DUT") == 0)
7615 dut->device_type = STA_dut;
7616
7617 if (dut->program == PROGRAM_TDLS) {
7618 /* Clear TDLS testing mode */
7619 wpa_command(intf, "SET tdls_disabled 0");
7620 wpa_command(intf, "SET tdls_testing 0");
7621 dut->no_tpk_expiration = 0;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007622 if (get_driver_type(dut) == DRIVER_WCN) {
Pradeep Reddy POTTETI8ce2a232016-10-28 12:17:32 +05307623 /* Enable the WCN driver in TDLS Explicit trigger mode
7624 */
7625 wpa_command(intf, "SET tdls_external_control 0");
7626 wpa_command(intf, "SET tdls_trigger_control 0");
7627 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007628 }
7629
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007630#ifdef MIRACAST
7631 if (dut->program == PROGRAM_WFD ||
7632 dut->program == PROGRAM_DISPLAYR2)
7633 miracast_sta_reset_default(dut, conn, cmd);
7634#endif /* MIRACAST */
7635
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007636 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007637 case DRIVER_ATHEROS:
7638 sta_reset_default_ath(dut, intf, type);
7639 break;
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007640 case DRIVER_WCN:
7641 sta_reset_default_wcn(dut, intf, type);
7642 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007643 default:
7644 break;
7645 }
7646
7647#ifdef ANDROID_NAN
7648 if (dut->program == PROGRAM_NAN)
7649 nan_cmd_sta_reset_default(dut, conn, cmd);
7650#endif /* ANDROID_NAN */
7651
Vinay Gannevaram3b9fdd32019-06-14 17:55:44 +05307652 if (dut->program == PROGRAM_LOC &&
7653 lowi_cmd_sta_reset_default(dut, conn, cmd) < 0)
7654 return ERROR_SEND_STATUS;
7655
Jouni Malinenba630452018-06-22 11:49:59 +03007656 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007657 unlink("SP/wi-fi.org/pps.xml");
7658 if (system("rm -r SP/*") != 0) {
7659 }
7660 unlink("next-client-cert.pem");
7661 unlink("next-client-key.pem");
7662 }
7663
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007664 /* For WPS program of the 60 GHz band the band type needs to be saved */
7665 if (dut->program == PROGRAM_WPS) {
7666 if (band && strcasecmp(band, "60GHz") == 0) {
7667 dut->band = WPS_BAND_60G;
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02007668 /* For 60 GHz enable WPS for WPS TCs */
7669 dut->wps_disable = 0;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007670 } else {
7671 dut->band = WPS_BAND_NON_60G;
7672 }
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02007673 } else if (dut->program == PROGRAM_60GHZ) {
7674 /* For 60 GHz MAC/PHY TCs WPS must be disabled */
7675 dut->wps_disable = 1;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007676 }
7677
Alexei Avshalom Lazar157ba062018-12-23 16:15:26 +02007678 if (is_60g_sigma_dut(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007679 const char *dev_role = get_param(cmd, "DevRole");
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007680 char buf[256];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007681
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02007682 sigma_dut_print(dut, DUT_MSG_INFO,
7683 "WPS 60 GHz program, wps_disable = %d",
7684 dut->wps_disable);
7685
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007686 if (!dev_role) {
7687 send_resp(dut, conn, SIGMA_ERROR,
7688 "errorCode,Missing DevRole argument");
7689 return 0;
7690 }
7691
7692 if (strcasecmp(dev_role, "STA") == 0)
7693 dut->dev_role = DEVROLE_STA;
7694 else if (strcasecmp(dev_role, "PCP") == 0)
7695 dut->dev_role = DEVROLE_PCP;
7696 else {
7697 send_resp(dut, conn, SIGMA_ERROR,
7698 "errorCode,Unknown DevRole");
7699 return 0;
7700 }
7701
7702 if (dut->device_type == STA_unknown) {
7703 sigma_dut_print(dut, DUT_MSG_ERROR,
7704 "Device type is not STA testbed or DUT");
7705 send_resp(dut, conn, SIGMA_ERROR,
7706 "errorCode,Unknown device type");
7707 return 0;
7708 }
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007709
7710 sigma_dut_print(dut, DUT_MSG_DEBUG,
7711 "Setting msdu_size to MAX: 7912");
7712 snprintf(buf, sizeof(buf), "ifconfig %s mtu 7912",
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007713 get_station_ifname(dut));
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007714
7715 if (system(buf) != 0) {
7716 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
7717 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007718 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007719 }
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02007720
7721 if (sta_set_force_mcs(dut, 0, 1)) {
7722 sigma_dut_print(dut, DUT_MSG_ERROR,
7723 "Failed to reset force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007724 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02007725 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007726 }
7727
7728 wpa_command(intf, "WPS_ER_STOP");
7729 wpa_command(intf, "FLUSH");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05307730 wpa_command(intf, "ERP_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007731 wpa_command(intf, "SET radio_disabled 0");
7732
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02007733 dut->wps_forced_version = 0;
7734
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007735 if (dut->wsc_fragment) {
7736 dut->wsc_fragment = 0;
7737 wpa_command(intf, "SET device_name Test client");
7738 wpa_command(intf, "SET manufacturer ");
7739 wpa_command(intf, "SET model_name ");
7740 wpa_command(intf, "SET model_number ");
7741 wpa_command(intf, "SET serial_number ");
7742 }
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02007743 if (is_60g_sigma_dut(dut) && dut->force_rsn_ie) {
7744 dut->force_rsn_ie = FORCE_RSN_IE_NONE;
7745 sta_60g_force_rsn_ie(dut, FORCE_RSN_IE_NONE);
7746 }
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007747
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007748 if (dut->tmp_mac_addr && dut->set_macaddr) {
7749 dut->tmp_mac_addr = 0;
7750 if (system(dut->set_macaddr) != 0) {
7751 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to clear "
7752 "temporary MAC address");
7753 }
7754 }
7755
7756 set_ps(intf, dut, 0);
7757
Jouni Malinenba630452018-06-22 11:49:59 +03007758 if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2 ||
7759 dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007760 wpa_command(intf, "SET interworking 1");
7761 wpa_command(intf, "SET hs20 1");
7762 }
7763
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08007764 if (dut->program == PROGRAM_HS2_R2 ||
Jouni Malinenba630452018-06-22 11:49:59 +03007765 dut->program == PROGRAM_HS2_R3 ||
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08007766 dut->program == PROGRAM_OCE) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007767 wpa_command(intf, "SET pmf 1");
7768 } else {
7769 wpa_command(intf, "SET pmf 0");
7770 }
7771
7772 hs2_clear_credentials(intf);
7773 wpa_command(intf, "SET hessid 00:00:00:00:00:00");
7774 wpa_command(intf, "SET access_network_type 15");
7775
7776 static_ip_file(0, NULL, NULL, NULL);
7777 kill_dhcp_client(dut, intf);
7778 clear_ip_addr(dut, intf);
7779
7780 dut->er_oper_performed = 0;
7781 dut->er_oper_bssid[0] = '\0';
7782
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07007783 if (dut->program == PROGRAM_LOC) {
7784 /* Disable Interworking by default */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007785 wpa_command(get_station_ifname(dut), "SET interworking 0");
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07007786 }
7787
Kiran Kumar Lokeredd086642020-06-04 00:29:26 -07007788 if (dut->program == PROGRAM_MBO || dut->program == PROGRAM_HE) {
Ashwini Patil00402582017-04-13 12:29:39 +05307789 free(dut->non_pref_ch_list);
7790 dut->non_pref_ch_list = NULL;
Ashwini Patil5acd7382017-04-13 15:55:04 +05307791 free(dut->btm_query_cand_list);
7792 dut->btm_query_cand_list = NULL;
Ashwini Patilc63161e2017-04-13 16:30:23 +05307793 wpa_command(intf, "SET reject_btm_req_reason 0");
Ashwini Patila75de5a2017-04-13 16:35:05 +05307794 wpa_command(intf, "SET ignore_assoc_disallow 0");
Ashwini Patild174f2c2017-04-13 16:49:46 +05307795 wpa_command(intf, "SET gas_address3 0");
Ashwini Patil9183fdb2017-04-13 16:58:25 +05307796 wpa_command(intf, "SET roaming 1");
Ankita Bajaj1d974552018-09-18 16:56:44 +05307797 wpa_command(intf, "SET interworking 1");
Ashwini Patil00402582017-04-13 12:29:39 +05307798 }
7799
Jouni Malinen3c367e82017-06-23 17:01:47 +03007800 free(dut->rsne_override);
7801 dut->rsne_override = NULL;
7802
Jouni Malinen68143132017-09-02 02:34:08 +03007803 free(dut->sae_commit_override);
7804 dut->sae_commit_override = NULL;
Jouni Malinen4b3769d2019-10-10 16:20:29 +03007805 wpa_command(intf, "SET sae_pmkid_in_assoc 0");
Jouni Malinen11e55212019-11-22 21:46:59 +02007806 dut->sae_pwe = SAE_PWE_DEFAULT;
Jouni Malinen68143132017-09-02 02:34:08 +03007807
Jouni Malinen134fe3c2019-06-12 04:16:49 +03007808 dut->sta_associate_wait_connect = 0;
7809 dut->server_cert_hash[0] = '\0';
Jouni Malinen37d5c692019-08-19 16:56:55 +03007810 dut->server_cert_tod = 0;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03007811 dut->sta_tod_policy = 0;
7812
Jouni Malinend86e5822017-08-29 03:55:32 +03007813 dut->dpp_conf_id = -1;
Jouni Malinenb1dd21f2017-11-13 19:14:29 +02007814 free(dut->dpp_peer_uri);
7815 dut->dpp_peer_uri = NULL;
Jouni Malinen63d50412017-11-24 11:55:38 +02007816 dut->dpp_local_bootstrap = -1;
Jouni Malinen5011fb52017-12-05 21:00:15 +02007817 wpa_command(intf, "SET dpp_config_processing 2");
Jouni Malinen90776b12020-05-04 15:34:46 +03007818 wpa_command(intf, "SET dpp_mud_url ");
Jouni Malinend86e5822017-08-29 03:55:32 +03007819
Jouni Malinenfac9cad2017-10-10 18:35:55 +03007820 wpa_command(intf, "VENDOR_ELEM_REMOVE 13 *");
7821
vamsi krishnaa2799492017-12-05 14:28:01 +05307822 if (dut->program == PROGRAM_OCE) {
Ankita Bajaja2cb5672017-10-25 16:08:28 +05307823 wpa_command(intf, "SET oce 1");
vamsi krishnaa2799492017-12-05 14:28:01 +05307824 wpa_command(intf, "SET disable_fils 0");
Ankita Bajaj1bde7942018-01-09 19:15:01 +05307825 wpa_command(intf, "FILS_HLP_REQ_FLUSH");
7826 dut->fils_hlp = 0;
7827#ifdef ANDROID
7828 hlp_thread_cleanup(dut);
7829#endif /* ANDROID */
vamsi krishnaa2799492017-12-05 14:28:01 +05307830 }
Ankita Bajaja2cb5672017-10-25 16:08:28 +05307831
Vamsi Krishnaf642d6a2020-03-27 12:33:14 +05307832 if (dut->program == PROGRAM_QM)
7833 wpa_command(intf, "SET interworking 1");
7834
Jouni Malinen8179fee2019-03-28 03:19:47 +02007835 dut->akm_values = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007836 dut->sta_ft_ds = 0;
Jouni Malinen8179fee2019-03-28 03:19:47 +02007837
Sunil Dutt076081f2018-02-05 19:45:50 +05307838#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007839 if (get_driver_type(dut) == DRIVER_WCN &&
Sunil Dutt44595082018-02-12 19:41:45 +05307840 dut->config_rsnie == 1) {
7841 dut->config_rsnie = 0;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05307842 sta_config_params(dut, intf, STA_SET_RSNIE, 0);
Sunil Dutt076081f2018-02-05 19:45:50 +05307843 }
7844#endif /* NL80211_SUPPORT */
7845
Sunil Duttfebf8a82018-02-09 18:50:13 +05307846 if (dev_role && strcasecmp(dev_role, "STA-CFON") == 0) {
7847 dut->dev_role = DEVROLE_STA_CFON;
7848 return sta_cfon_reset_default(dut, conn, cmd);
7849 }
7850
Jouni Malinen439352d2018-09-13 03:42:23 +03007851 wpa_command(intf, "SET setband AUTO");
7852
Vamsi Krishnac1633d22020-05-06 18:31:21 +05307853 dut->ocvc = 0;
Jouni Malinen67433fc2020-06-26 22:50:33 +03007854 dut->client_privacy = 0;
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +05307855 dut->saquery_oci_freq = 0;
Vamsi Krishnac1633d22020-05-06 18:31:21 +05307856
Sunil Duttfebf8a82018-02-09 18:50:13 +05307857 if (dut->program != PROGRAM_VHT)
7858 return cmd_sta_p2p_reset(dut, conn, cmd);
7859
Priyadharshini Gowthamana7dfd492015-11-09 14:34:08 -08007860 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007861}
7862
7863
Jouni Malinenf7222712019-06-13 01:50:21 +03007864static enum sigma_cmd_result cmd_sta_get_events(struct sigma_dut *dut,
7865 struct sigma_conn *conn,
7866 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007867{
7868 const char *program = get_param(cmd, "Program");
7869
7870 if (program == NULL)
7871 return -1;
7872#ifdef ANDROID_NAN
7873 if (strcasecmp(program, "NAN") == 0)
7874 return nan_cmd_sta_get_events(dut, conn, cmd);
7875#endif /* ANDROID_NAN */
7876 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7877 return 0;
7878}
7879
7880
Jouni Malinen82905202018-04-29 17:20:10 +03007881static int sta_exec_action_url(struct sigma_dut *dut, struct sigma_conn *conn,
7882 struct sigma_cmd *cmd)
7883{
7884 const char *url = get_param(cmd, "url");
7885 const char *method = get_param(cmd, "method");
7886 pid_t pid;
7887 int status;
7888
7889 if (!url || !method)
7890 return -1;
7891
7892 /* TODO: Add support for method,post */
7893 if (strcasecmp(method, "get") != 0) {
7894 send_resp(dut, conn, SIGMA_ERROR,
7895 "ErrorCode,Unsupported method");
7896 return 0;
7897 }
7898
7899 pid = fork();
7900 if (pid < 0) {
7901 perror("fork");
7902 return -1;
7903 }
7904
7905 if (pid == 0) {
7906 char * argv[5] = { "wget", "-O", "/dev/null",
7907 (char *) url, NULL };
7908
7909 execv("/usr/bin/wget", argv);
7910 perror("execv");
7911 exit(0);
7912 return -1;
7913 }
7914
7915 if (waitpid(pid, &status, 0) < 0) {
7916 perror("waitpid");
7917 return -1;
7918 }
7919
7920 if (WIFEXITED(status)) {
7921 const char *errmsg;
7922
7923 if (WEXITSTATUS(status) == 0)
7924 return 1;
7925 sigma_dut_print(dut, DUT_MSG_INFO, "wget exit status %d",
7926 WEXITSTATUS(status));
7927 switch (WEXITSTATUS(status)) {
7928 case 4:
7929 errmsg = "errmsg,Network failure";
7930 break;
7931 case 8:
7932 errmsg = "errmsg,Server issued an error response";
7933 break;
7934 default:
7935 errmsg = "errmsg,Unknown failure from wget";
7936 break;
7937 }
7938 send_resp(dut, conn, SIGMA_ERROR, errmsg);
7939 return 0;
7940 }
7941
7942 send_resp(dut, conn, SIGMA_ERROR, "errmsg,Unknown failure");
7943 return 0;
7944}
7945
7946
Jouni Malinenf7222712019-06-13 01:50:21 +03007947static enum sigma_cmd_result cmd_sta_exec_action(struct sigma_dut *dut,
7948 struct sigma_conn *conn,
7949 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007950{
7951 const char *program = get_param(cmd, "Prog");
7952
Jouni Malinen82905202018-04-29 17:20:10 +03007953 if (program && !get_param(cmd, "interface"))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007954 return -1;
7955#ifdef ANDROID_NAN
Jouni Malinen82905202018-04-29 17:20:10 +03007956 if (program && strcasecmp(program, "NAN") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007957 return nan_cmd_sta_exec_action(dut, conn, cmd);
7958#endif /* ANDROID_NAN */
Jouni Malinen82905202018-04-29 17:20:10 +03007959
7960 if (program && strcasecmp(program, "Loc") == 0)
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07007961 return loc_cmd_sta_exec_action(dut, conn, cmd);
Jouni Malinen82905202018-04-29 17:20:10 +03007962
7963 if (get_param(cmd, "url"))
7964 return sta_exec_action_url(dut, conn, cmd);
7965
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007966 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7967 return 0;
7968}
7969
7970
Jouni Malinenf7222712019-06-13 01:50:21 +03007971static enum sigma_cmd_result cmd_sta_set_11n(struct sigma_dut *dut,
7972 struct sigma_conn *conn,
7973 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007974{
7975 const char *intf = get_param(cmd, "Interface");
7976 const char *val, *mcs32, *rate;
7977
7978 val = get_param(cmd, "GREENFIELD");
7979 if (val) {
7980 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
7981 /* Enable GD */
7982 send_resp(dut, conn, SIGMA_ERROR,
7983 "ErrorCode,GF not supported");
7984 return 0;
7985 }
7986 }
7987
7988 val = get_param(cmd, "SGI20");
7989 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007990 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007991 case DRIVER_ATHEROS:
7992 ath_sta_set_sgi(dut, intf, val);
7993 break;
7994 default:
7995 send_resp(dut, conn, SIGMA_ERROR,
7996 "ErrorCode,SGI20 not supported");
7997 return 0;
7998 }
7999 }
8000
8001 mcs32 = get_param(cmd, "MCS32"); /* HT Duplicate Mode Enable/Disable */
8002 rate = get_param(cmd, "MCS_FIXEDRATE"); /* Fixed MCS rate (0..31) */
8003 if (mcs32 && rate) {
8004 /* TODO */
8005 send_resp(dut, conn, SIGMA_ERROR,
8006 "ErrorCode,MCS32,MCS_FIXEDRATE not supported");
8007 return 0;
8008 } else if (mcs32 && !rate) {
8009 /* TODO */
8010 send_resp(dut, conn, SIGMA_ERROR,
8011 "ErrorCode,MCS32 not supported");
8012 return 0;
8013 } else if (!mcs32 && rate) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008014 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008015 case DRIVER_ATHEROS:
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07008016 novap_reset(dut, intf, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008017 ath_sta_set_11nrates(dut, intf, rate);
8018 break;
8019 default:
8020 send_resp(dut, conn, SIGMA_ERROR,
8021 "ErrorCode,MCS32_FIXEDRATE not supported");
8022 return 0;
8023 }
8024 }
8025
8026 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
8027}
8028
8029
Arif Hussain7b47d2d2018-05-09 10:44:02 -07008030static void cmd_set_max_he_mcs(struct sigma_dut *dut, const char *intf,
8031 int mcs_config)
8032{
8033#ifdef NL80211_SUPPORT
8034 int ret;
8035
8036 switch (mcs_config) {
8037 case HE_80_MCS0_7:
8038 case HE_80_MCS0_9:
8039 case HE_80_MCS0_11:
8040 ret = sta_set_he_mcs(dut, intf, mcs_config);
8041 if (ret) {
8042 sigma_dut_print(dut, DUT_MSG_ERROR,
8043 "cmd_set_max_he_mcs: Setting of MCS:%d failed, ret:%d",
8044 mcs_config, ret);
8045 }
8046 break;
8047 default:
8048 sigma_dut_print(dut, DUT_MSG_ERROR,
8049 "cmd_set_max_he_mcs: Invalid mcs %d",
8050 mcs_config);
8051 break;
8052 }
8053#else /* NL80211_SUPPORT */
8054 sigma_dut_print(dut, DUT_MSG_ERROR,
8055 "max HE MCS cannot be changed without NL80211_SUPPORT defined");
8056#endif /* NL80211_SUPPORT */
8057}
8058
8059
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07008060#define TWT_REQUEST_CMD 0
8061#define TWT_SUGGEST_CMD 1
8062#define TWT_DEMAND_CMD 2
8063
Arif Hussain480d5f42019-03-12 14:40:42 -07008064static int sta_twt_request(struct sigma_dut *dut, struct sigma_conn *conn,
8065 struct sigma_cmd *cmd)
8066{
8067#ifdef NL80211_SUPPORT
8068 struct nlattr *params;
8069 struct nlattr *attr;
8070 struct nlattr *attr1;
8071 struct nl_msg *msg;
8072 int ifindex, ret;
8073 const char *val;
8074 const char *intf = get_param(cmd, "Interface");
8075 int wake_interval_exp = 10, nominal_min_wake_dur = 255,
8076 wake_interval_mantissa = 512;
8077 int flow_type = 0, twt_trigger = 0, target_wake_time = 0,
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07008078 protection = 0, cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_SUGGEST;
Arif Hussain480d5f42019-03-12 14:40:42 -07008079
8080 ifindex = if_nametoindex(intf);
8081 if (ifindex == 0) {
8082 sigma_dut_print(dut, DUT_MSG_ERROR,
8083 "%s: Index for interface %s failed",
8084 __func__, intf);
8085 return -1;
8086 }
8087
8088 val = get_param(cmd, "FlowType");
8089 if (val) {
8090 flow_type = atoi(val);
8091 if (flow_type != 0 && flow_type != 1) {
8092 sigma_dut_print(dut, DUT_MSG_ERROR,
8093 "TWT: Invalid FlowType %d", flow_type);
8094 return -1;
8095 }
8096 }
8097
8098 val = get_param(cmd, "TWT_Trigger");
8099 if (val) {
8100 twt_trigger = atoi(val);
8101 if (twt_trigger != 0 && twt_trigger != 1) {
8102 sigma_dut_print(dut, DUT_MSG_ERROR,
8103 "TWT: Invalid TWT_Trigger %d",
8104 twt_trigger);
8105 return -1;
8106 }
8107 }
8108
8109 val = get_param(cmd, "Protection");
8110 if (val) {
8111 protection = atoi(val);
8112 if (protection != 0 && protection != 1) {
8113 sigma_dut_print(dut, DUT_MSG_ERROR,
8114 "TWT: Invalid Protection %d",
8115 protection);
8116 return -1;
8117 }
8118 }
8119
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07008120 val = get_param(cmd, "SetupCommand");
8121 if (val) {
8122 cmd_type = atoi(val);
8123 if (cmd_type == TWT_REQUEST_CMD)
8124 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_REQUEST;
8125 else if (cmd_type == TWT_SUGGEST_CMD)
8126 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_SUGGEST;
8127 else if (cmd_type == TWT_DEMAND_CMD)
8128 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_DEMAND;
8129 else
8130 sigma_dut_print(dut, DUT_MSG_ERROR,
8131 "Default suggest is used for cmd %d",
8132 cmd_type);
8133 }
8134
Arif Hussain480d5f42019-03-12 14:40:42 -07008135 val = get_param(cmd, "TargetWakeTime");
8136 if (val)
8137 target_wake_time = atoi(val);
8138
8139 val = get_param(cmd, "WakeIntervalMantissa");
8140 if (val)
8141 wake_interval_mantissa = atoi(val);
8142
8143 val = get_param(cmd, "WakeIntervalExp");
8144 if (val)
8145 wake_interval_exp = atoi(val);
8146
8147 val = get_param(cmd, "NominalMinWakeDur");
8148 if (val)
8149 nominal_min_wake_dur = atoi(val);
8150
8151 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8152 NL80211_CMD_VENDOR)) ||
8153 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8154 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8155 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8156 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8157 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8158 !(params = nla_nest_start(
8159 msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_TWT_SETUP)) ||
8160 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8161 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_EXP,
8162 wake_interval_exp) ||
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07008163 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_REQ_TYPE, cmd_type) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -07008164 (twt_trigger &&
8165 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_TRIGGER)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008166 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE,
8167 flow_type) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -07008168 (protection &&
8169 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_PROTECTION)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008170 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_TIME,
8171 target_wake_time) ||
8172 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_DURATION,
8173 nominal_min_wake_dur) ||
8174 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_MANTISSA,
8175 wake_interval_mantissa)) {
8176 sigma_dut_print(dut, DUT_MSG_ERROR,
8177 "%s: err in adding vendor_cmd and vendor_data",
8178 __func__);
8179 nlmsg_free(msg);
8180 return -1;
8181 }
8182 nla_nest_end(msg, attr1);
8183 nla_nest_end(msg, params);
8184 nla_nest_end(msg, attr);
8185
8186 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8187 if (ret) {
8188 sigma_dut_print(dut, DUT_MSG_ERROR,
8189 "%s: err in send_and_recv_msgs, ret=%d",
8190 __func__, ret);
8191 }
8192
8193 return ret;
8194#else /* NL80211_SUPPORT */
8195 sigma_dut_print(dut, DUT_MSG_ERROR,
8196 "TWT request cannot be done without NL80211_SUPPORT defined");
8197 return -1;
8198#endif /* NL80211_SUPPORT */
8199}
8200
8201
8202static int sta_twt_teardown(struct sigma_dut *dut, struct sigma_conn *conn,
8203 struct sigma_cmd *cmd)
8204{
8205 #ifdef NL80211_SUPPORT
8206 struct nlattr *params;
8207 struct nlattr *attr;
8208 struct nlattr *attr1;
8209 int ifindex, ret;
8210 struct nl_msg *msg;
8211 const char *intf = get_param(cmd, "Interface");
8212
8213 ifindex = if_nametoindex(intf);
8214 if (ifindex == 0) {
8215 sigma_dut_print(dut, DUT_MSG_ERROR,
8216 "%s: Index for interface %s failed",
8217 __func__, intf);
8218 return -1;
8219 }
8220
8221 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8222 NL80211_CMD_VENDOR)) ||
8223 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8224 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8225 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8226 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8227 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8228 !(params = nla_nest_start(
8229 msg,
8230 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_TWT_TERMINATE)) ||
8231 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8232 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE, 0)) {
8233 sigma_dut_print(dut, DUT_MSG_ERROR,
8234 "%s: err in adding vendor_cmd and vendor_data",
8235 __func__);
8236 nlmsg_free(msg);
8237 return -1;
8238 }
8239 nla_nest_end(msg, attr1);
8240 nla_nest_end(msg, params);
8241 nla_nest_end(msg, attr);
8242
8243 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8244 if (ret) {
8245 sigma_dut_print(dut, DUT_MSG_ERROR,
8246 "%s: err in send_and_recv_msgs, ret=%d",
8247 __func__, ret);
8248 }
8249
8250 return ret;
8251#else /* NL80211_SUPPORT */
8252 sigma_dut_print(dut, DUT_MSG_ERROR,
8253 "TWT teardown cannot be done without NL80211_SUPPORT defined");
8254 return -1;
8255#endif /* NL80211_SUPPORT */
8256}
8257
8258
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -08008259static int sta_transmit_omi(struct sigma_dut *dut, struct sigma_conn *conn,
8260 struct sigma_cmd *cmd)
8261{
8262#ifdef NL80211_SUPPORT
8263 struct nlattr *params;
8264 struct nlattr *attr;
8265 struct nlattr *attr1;
8266 struct nl_msg *msg;
8267 int ifindex, ret;
8268 const char *val;
8269 const char *intf = get_param(cmd, "Interface");
8270 uint8_t rx_nss = 0xFF, ch_bw = 0xFF, tx_nsts = 0xFF, ulmu_dis = 0,
8271 ulmu_data_dis = 0;
8272
8273 ifindex = if_nametoindex(intf);
8274 if (ifindex == 0) {
8275 sigma_dut_print(dut, DUT_MSG_ERROR,
8276 "%s: Index for interface %s failed",
8277 __func__, intf);
8278 return -1;
8279 }
8280 val = get_param(cmd, "OMCtrl_RxNSS");
8281 if (val)
8282 rx_nss = atoi(val);
8283
8284 val = get_param(cmd, "OMCtrl_ChnlWidth");
8285 if (val)
8286 ch_bw = atoi(val);
8287
8288 val = get_param(cmd, "OMCtrl_ULMUDisable");
8289 if (val)
8290 ulmu_dis = atoi(val);
8291
8292 val = get_param(cmd, "OMCtrl_TxNSTS");
8293 if (val)
8294 tx_nsts = atoi(val);
8295
8296 val = get_param(cmd, "OMCtrl_ULMUDataDisable");
8297 if (val)
8298 ulmu_data_dis = atoi(val);
8299
8300 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8301 NL80211_CMD_VENDOR)) ||
8302 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8303 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8304 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8305 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8306 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8307 !(params = nla_nest_start(
8308 msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OMI_TX)) ||
8309 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8310 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_RX_NSS, rx_nss) ||
8311 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_CH_BW, ch_bw) ||
8312 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_TX_NSTS, tx_nsts) ||
8313 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DATA_DISABLE,
8314 ulmu_data_dis) ||
8315 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DISABLE,
8316 ulmu_dis)) {
8317 sigma_dut_print(dut, DUT_MSG_ERROR,
8318 "%s: err in adding vendor_cmd and vendor_data",
8319 __func__);
8320 nlmsg_free(msg);
8321 return -1;
8322 }
8323 nla_nest_end(msg, attr1);
8324 nla_nest_end(msg, params);
8325 nla_nest_end(msg, attr);
8326
8327 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8328 if (ret) {
8329 sigma_dut_print(dut, DUT_MSG_ERROR,
8330 "%s: err in send_and_recv_msgs, ret=%d",
8331 __func__, ret);
8332 }
8333
8334 return ret;
8335#else /* NL80211_SUPPORT */
8336 sigma_dut_print(dut, DUT_MSG_ERROR,
8337 "OMI TX cannot be processed without NL80211_SUPPORT defined");
8338 return -1;
8339#endif /* NL80211_SUPPORT */
8340}
8341
8342
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008343static int cmd_sta_set_wireless_vht(struct sigma_dut *dut,
8344 struct sigma_conn *conn,
8345 struct sigma_cmd *cmd)
8346{
8347 const char *intf = get_param(cmd, "Interface");
8348 const char *val;
Arif Hussaina37e9552018-06-20 17:05:59 -07008349 const char *program;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008350 int tkip = -1;
8351 int wep = -1;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05308352 int iwpriv_status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008353
Arif Hussaina37e9552018-06-20 17:05:59 -07008354 program = get_param(cmd, "Program");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008355 val = get_param(cmd, "SGI80");
8356 if (val) {
8357 int sgi80;
8358
8359 sgi80 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008360 run_iwpriv(dut, intf, "shortgi %d", sgi80);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008361 }
8362
8363 val = get_param(cmd, "TxBF");
8364 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008365 switch (get_driver_type(dut)) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008366 case DRIVER_WCN:
8367 if (sta_set_tx_beamformee(dut, intf, 1)) {
8368 send_resp(dut, conn, SIGMA_ERROR,
8369 "ErrorCode,Failed to set TX beamformee enable");
8370 return 0;
8371 }
8372 break;
8373 case DRIVER_ATHEROS:
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008374 if (run_iwpriv(dut, intf, "vhtsubfee 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008375 send_resp(dut, conn, SIGMA_ERROR,
8376 "ErrorCode,Setting vhtsubfee failed");
8377 return 0;
8378 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008379 if (run_iwpriv(dut, intf, "vhtsubfer 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008380 send_resp(dut, conn, SIGMA_ERROR,
8381 "ErrorCode,Setting vhtsubfer failed");
8382 return 0;
8383 }
8384 break;
8385 default:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008386 sigma_dut_print(dut, DUT_MSG_ERROR,
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008387 "Unsupported driver type");
8388 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008389 }
8390 }
8391
8392 val = get_param(cmd, "MU_TxBF");
8393 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008394 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008395 case DRIVER_ATHEROS:
8396 ath_sta_set_txsp_stream(dut, intf, "1SS");
8397 ath_sta_set_rxsp_stream(dut, intf, "1SS");
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008398 run_iwpriv(dut, intf, "vhtmubfee 1");
8399 run_iwpriv(dut, intf, "vhtmubfer 1");
Sunil Duttae9e5d12018-06-29 11:50:47 +05308400 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008401 case DRIVER_WCN:
8402 if (wcn_sta_set_sp_stream(dut, intf, "1SS") < 0) {
8403 send_resp(dut, conn, SIGMA_ERROR,
8404 "ErrorCode,Failed to set RX/TXSP_STREAM");
8405 return 0;
8406 }
Sunil Duttae9e5d12018-06-29 11:50:47 +05308407 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008408 default:
8409 sigma_dut_print(dut, DUT_MSG_ERROR,
8410 "Setting SP_STREAM not supported");
8411 break;
8412 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008413 }
8414
8415 val = get_param(cmd, "LDPC");
8416 if (val) {
8417 int ldpc;
8418
8419 ldpc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05308420 iwpriv_status = run_iwpriv(dut, intf, "ldpc %d", ldpc);
8421 if (iwpriv_status)
8422 sta_config_params(dut, intf, STA_SET_LDPC, ldpc);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008423 }
8424
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08008425 val = get_param(cmd, "BCC");
8426 if (val) {
8427 int bcc;
8428
8429 bcc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8430 /* use LDPC iwpriv itself to set bcc coding, bcc coding
8431 * is mutually exclusive to bcc */
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05308432 iwpriv_status = run_iwpriv(dut, intf, "ldpc %d", !bcc);
8433 if (iwpriv_status)
8434 sta_config_params(dut, intf, STA_SET_LDPC, !bcc);
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08008435 }
8436
Arif Hussain7b47d2d2018-05-09 10:44:02 -07008437 val = get_param(cmd, "MaxHE-MCS_1SS_RxMapLTE80");
8438 if (val && dut->sta_nss == 1)
8439 cmd_set_max_he_mcs(dut, intf, atoi(val));
8440
8441 val = get_param(cmd, "MaxHE-MCS_2SS_RxMapLTE80");
8442 if (val && dut->sta_nss == 2)
8443 cmd_set_max_he_mcs(dut, intf, atoi(val));
8444
Arif Hussainac6c5112018-05-25 17:34:00 -07008445 val = get_param(cmd, "MCS_FixedRate");
8446 if (val) {
8447#ifdef NL80211_SUPPORT
8448 int mcs, ratecode = 0;
8449 enum he_mcs_config mcs_config;
8450 int ret;
Jouni Malinenb9b671d2019-04-26 13:23:17 +03008451 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07008452
8453 ratecode = (0x07 & dut->sta_nss) << 5;
8454 mcs = atoi(val);
8455 /* Add the MCS to the ratecode */
8456 if (mcs >= 0 && mcs <= 11) {
8457 ratecode += mcs;
8458 if (dut->device_type == STA_testbed &&
8459 mcs > 7 && mcs <= 11) {
8460 if (mcs <= 9)
8461 mcs_config = HE_80_MCS0_9;
8462 else
8463 mcs_config = HE_80_MCS0_11;
8464 ret = sta_set_he_mcs(dut, intf, mcs_config);
8465 if (ret) {
8466 sigma_dut_print(dut, DUT_MSG_ERROR,
8467 "MCS_FixedRate: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
8468 mcs, mcs_config, ret);
8469 }
8470 }
8471 snprintf(buf, sizeof(buf),
8472 "iwpriv %s set_11ax_rate 0x%03x",
8473 intf, ratecode);
8474 if (system(buf) != 0) {
8475 sigma_dut_print(dut, DUT_MSG_ERROR,
8476 "MCS_FixedRate: iwpriv setting of 11ax rates 0x%03x failed",
8477 ratecode);
8478 }
8479 } else {
8480 sigma_dut_print(dut, DUT_MSG_ERROR,
8481 "MCS_FixedRate: HE MCS %d not supported",
8482 mcs);
8483 }
8484#else /* NL80211_SUPPORT */
8485 sigma_dut_print(dut, DUT_MSG_ERROR,
8486 "MCS_FixedRate cannot be changed without NL80211_SUPPORT defined");
8487#endif /* NL80211_SUPPORT */
8488 }
8489
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008490 val = get_param(cmd, "opt_md_notif_ie");
8491 if (val) {
8492 char *result = NULL;
8493 char delim[] = ";";
8494 char token[30];
8495 int value, config_val = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308496 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008497
Peng Xub8fc5cc2017-05-10 17:27:28 -07008498 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308499 result = strtok_r(token, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008500
8501 /* Extract the NSS information */
8502 if (result) {
8503 value = atoi(result);
8504 switch (value) {
8505 case 1:
8506 config_val = 1;
8507 break;
8508 case 2:
8509 config_val = 3;
8510 break;
8511 case 3:
8512 config_val = 7;
8513 break;
8514 case 4:
8515 config_val = 15;
8516 break;
8517 default:
8518 config_val = 3;
8519 break;
8520 }
8521
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008522 run_iwpriv(dut, intf, "rxchainmask %d", config_val);
8523 run_iwpriv(dut, intf, "txchainmask %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008524
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008525 }
8526
8527 /* Extract the channel width information */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308528 result = strtok_r(NULL, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008529 if (result) {
8530 value = atoi(result);
8531 switch (value) {
8532 case 20:
8533 config_val = 0;
8534 break;
8535 case 40:
8536 config_val = 1;
8537 break;
8538 case 80:
8539 config_val = 2;
8540 break;
8541 case 160:
8542 config_val = 3;
8543 break;
8544 default:
8545 config_val = 2;
8546 break;
8547 }
8548
8549 dut->chwidth = config_val;
8550
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008551 run_iwpriv(dut, intf, "chwidth %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008552 }
8553
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008554 run_iwpriv(dut, intf, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008555 }
8556
8557 val = get_param(cmd, "nss_mcs_cap");
8558 if (val) {
8559 int nss, mcs;
8560 char token[20];
8561 char *result = NULL;
8562 unsigned int vht_mcsmap = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308563 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008564
Peng Xub8fc5cc2017-05-10 17:27:28 -07008565 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308566 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308567 if (!result) {
8568 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008569 "NSS not specified");
8570 send_resp(dut, conn, SIGMA_ERROR,
8571 "errorCode,NSS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308572 return 0;
8573 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008574 nss = atoi(result);
8575
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008576 run_iwpriv(dut, intf, "nss %d", nss);
Arif Hussainac6c5112018-05-25 17:34:00 -07008577 dut->sta_nss = nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008578
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308579 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008580 if (result == NULL) {
8581 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008582 "MCS not specified");
8583 send_resp(dut, conn, SIGMA_ERROR,
8584 "errorCode,MCS not specified");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008585 return 0;
8586 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308587 result = strtok_r(result, "-", &saveptr);
8588 result = strtok_r(NULL, "-", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308589 if (!result) {
8590 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008591 "MCS not specified");
8592 send_resp(dut, conn, SIGMA_ERROR,
8593 "errorCode,MCS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308594 return 0;
8595 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008596 mcs = atoi(result);
8597
Arif Hussaina37e9552018-06-20 17:05:59 -07008598 if (program && strcasecmp(program, "HE") == 0) {
8599#ifdef NL80211_SUPPORT
8600 enum he_mcs_config mcs_config;
8601 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008602
Arif Hussaina37e9552018-06-20 17:05:59 -07008603 if (mcs >= 0 && mcs <= 7) {
8604 mcs_config = HE_80_MCS0_7;
8605 } else if (mcs > 7 && mcs <= 9) {
8606 mcs_config = HE_80_MCS0_9;
8607 } else if (mcs > 9 && mcs <= 11) {
8608 mcs_config = HE_80_MCS0_11;
8609 } else {
8610 sigma_dut_print(dut, DUT_MSG_ERROR,
8611 "nss_mcs_cap: HE: Invalid mcs: %d",
8612 mcs);
8613 send_resp(dut, conn, SIGMA_ERROR,
8614 "errorCode,Invalid MCS");
8615 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008616 }
Arif Hussaina37e9552018-06-20 17:05:59 -07008617
8618 ret = sta_set_he_mcs(dut, intf, mcs_config);
8619 if (ret) {
8620 sigma_dut_print(dut, DUT_MSG_ERROR,
8621 "nss_mcs_cap: HE: Setting of MCS failed, mcs_config: %d, ret: %d",
8622 mcs_config, ret);
8623 send_resp(dut, conn, SIGMA_ERROR,
8624 "errorCode,Failed to set MCS");
8625 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008626 }
Arif Hussaina37e9552018-06-20 17:05:59 -07008627#else /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008628 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008629 "nss_mcs_cap: HE: MCS cannot be changed without NL80211_SUPPORT defined");
8630#endif /* NL80211_SUPPORT */
8631 } else {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008632 run_iwpriv(dut, intf, "vhtmcs %d", mcs);
Arif Hussaina37e9552018-06-20 17:05:59 -07008633
8634 switch (nss) {
8635 case 1:
8636 switch (mcs) {
8637 case 7:
8638 vht_mcsmap = 0xfffc;
8639 break;
8640 case 8:
8641 vht_mcsmap = 0xfffd;
8642 break;
8643 case 9:
8644 vht_mcsmap = 0xfffe;
8645 break;
8646 default:
8647 vht_mcsmap = 0xfffe;
8648 break;
8649 }
8650 break;
8651 case 2:
8652 switch (mcs) {
8653 case 7:
8654 vht_mcsmap = 0xfff0;
8655 break;
8656 case 8:
8657 vht_mcsmap = 0xfff5;
8658 break;
8659 case 9:
8660 vht_mcsmap = 0xfffa;
8661 break;
8662 default:
8663 vht_mcsmap = 0xfffa;
8664 break;
8665 }
8666 break;
8667 case 3:
8668 switch (mcs) {
8669 case 7:
8670 vht_mcsmap = 0xffc0;
8671 break;
8672 case 8:
8673 vht_mcsmap = 0xffd5;
8674 break;
8675 case 9:
8676 vht_mcsmap = 0xffea;
8677 break;
8678 default:
8679 vht_mcsmap = 0xffea;
8680 break;
8681 }
8682 break;
8683 default:
8684 vht_mcsmap = 0xffea;
8685 break;
8686 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008687 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008688 }
8689 }
8690
8691 /* UNSUPPORTED: val = get_param(cmd, "Tx_lgi_rate"); */
8692
8693 val = get_param(cmd, "Vht_tkip");
8694 if (val)
8695 tkip = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8696
8697 val = get_param(cmd, "Vht_wep");
8698 if (val)
8699 wep = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8700
8701 if (tkip != -1 || wep != -1) {
8702 if ((tkip == 1 && wep != 0) || (wep == 1 && tkip != 0)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008703 run_iwpriv(dut, intf, "htweptkip 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008704 } else if ((tkip == 0 && wep != 1) || (wep == 0 && tkip != 1)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008705 run_iwpriv(dut, intf, "htweptkip 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008706 } else {
8707 sigma_dut_print(dut, DUT_MSG_ERROR,
8708 "ErrorCode,mixed mode of VHT TKIP/WEP not supported");
8709 return 0;
8710 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008711 }
8712
Arif Hussain55f00da2018-07-03 08:28:26 -07008713 val = get_param(cmd, "txBandwidth");
8714 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008715 switch (get_driver_type(dut)) {
Arif Hussain55f00da2018-07-03 08:28:26 -07008716 case DRIVER_WCN:
8717 if (wcn_sta_set_width(dut, intf, val) < 0) {
8718 send_resp(dut, conn, SIGMA_ERROR,
8719 "ErrorCode,Failed to set txBandwidth");
8720 return 0;
8721 }
8722 break;
8723 case DRIVER_ATHEROS:
8724 if (ath_set_width(dut, conn, intf, val) < 0) {
8725 send_resp(dut, conn, SIGMA_ERROR,
8726 "ErrorCode,Failed to set txBandwidth");
8727 return 0;
8728 }
8729 break;
8730 default:
8731 sigma_dut_print(dut, DUT_MSG_ERROR,
8732 "Setting txBandwidth not supported");
8733 break;
8734 }
8735 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008736
Arif Hussain9765f7d2018-07-03 08:28:26 -07008737 val = get_param(cmd, "BeamformeeSTS");
8738 if (val) {
Kiran Kumar Lokerebc89d432018-07-10 12:20:13 -07008739 if (sta_set_tx_beamformee(dut, intf, 1)) {
8740 send_resp(dut, conn, SIGMA_ERROR,
8741 "ErrorCode,Failed to set TX beamformee enable");
8742 return 0;
8743 }
8744
Arif Hussain9765f7d2018-07-03 08:28:26 -07008745 if (sta_set_beamformee_sts(dut, intf, atoi(val))) {
8746 send_resp(dut, conn, SIGMA_ERROR,
8747 "ErrorCode,Failed to set BeamformeeSTS");
8748 return 0;
8749 }
8750 }
8751
Arif Hussain68d23f52018-07-11 13:39:08 -07008752 val = get_param(cmd, "Trig_MAC_Padding_Dur");
8753 if (val) {
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07008754#ifdef NL80211_SUPPORT
8755 enum qca_wlan_he_mac_padding_dur set_val;
8756
8757 switch (atoi(val)) {
8758 case 16:
8759 set_val = QCA_WLAN_HE_16US_OF_PROCESS_TIME;
8760 break;
8761 case 8:
8762 set_val = QCA_WLAN_HE_8US_OF_PROCESS_TIME;
8763 break;
8764 default:
8765 set_val = QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME;
8766 break;
8767 }
8768 if (sta_set_mac_padding_duration(dut, intf, set_val)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07008769 send_resp(dut, conn, SIGMA_ERROR,
8770 "ErrorCode,Failed to set MAC padding duration");
8771 return 0;
8772 }
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07008773#else /* NL80211_SUPPORT */
8774 sigma_dut_print(dut, DUT_MSG_ERROR,
8775 "MAC padding duration cannot be changed without NL80211_SUPPORT defined");
8776#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07008777 }
8778
Arif Hussain480d5f42019-03-12 14:40:42 -07008779 val = get_param(cmd, "TWT_ReqSupport");
8780 if (val) {
8781 int set_val;
8782
8783 if (strcasecmp(val, "Enable") == 0) {
8784 set_val = 1;
8785 } else if (strcasecmp(val, "Disable") == 0) {
8786 set_val = 0;
8787 } else {
8788 send_resp(dut, conn, SIGMA_ERROR,
8789 "ErrorCode,Invalid TWT_ReqSupport");
8790 return STATUS_SENT;
8791 }
8792
8793 if (sta_set_twt_req_support(dut, intf, set_val)) {
8794 sigma_dut_print(dut, DUT_MSG_ERROR,
8795 "Failed to set TWT req support %d",
8796 set_val);
8797 send_resp(dut, conn, SIGMA_ERROR,
8798 "ErrorCode,Failed to set TWT_ReqSupport");
8799 return STATUS_SENT;
8800 }
8801 }
8802
Srinivas Girigowda0525e292020-11-12 13:28:21 -08008803 val = get_param(cmd, "FullBW_ULMUMIMO");
8804 if (val) {
8805 int set_val;
8806
8807 if (strcasecmp(val, "Enable") == 0) {
8808 set_val = 1;
8809 } else if (strcasecmp(val, "Disable") == 0) {
8810 set_val = 0;
8811 } else {
8812 send_resp(dut, conn, SIGMA_ERROR,
8813 "ErrorCode,Invalid FullBW_ULMUMIMO");
8814 return STATUS_SENT_ERROR;
8815 }
8816
8817 if (sta_set_fullbw_ulmumimo(dut, intf, set_val)) {
8818 sigma_dut_print(dut, DUT_MSG_ERROR,
8819 "Failed to set FullBW_ULMUMIMO %d",
8820 set_val);
8821 send_resp(dut, conn, SIGMA_ERROR,
8822 "ErrorCode,Failed to set FullBW_ULMUMIMO");
8823 return STATUS_SENT_ERROR;
8824 }
8825 }
8826
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07008827 val = get_param(cmd, "MU_EDCA");
8828 if (val && (strcasecmp(val, "Override") == 0)) {
8829 if (sta_set_mu_edca_override(dut, intf, 1)) {
8830 send_resp(dut, conn, SIGMA_ERROR,
8831 "ErrorCode,Failed to set MU EDCA override");
8832 return 0;
8833 }
8834 }
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07008835
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07008836 val = get_param(cmd, "OMControl");
8837 if (val) {
8838 int set_val = 1;
8839
8840 if (strcasecmp(val, "Enable") == 0)
8841 set_val = 1;
8842 else if (strcasecmp(val, "Disable") == 0)
8843 set_val = 0;
8844
8845 if (sta_set_om_ctrl_supp(dut, intf, set_val)) {
8846 send_resp(dut, conn, SIGMA_ERROR,
8847 "ErrorCode,Failed to set OM ctrl supp");
8848 return 0;
8849 }
8850 }
8851
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07008852 val = get_param(cmd, "ADDBAResp_BufSize");
8853 if (val) {
8854 int buf_size;
8855
8856 if (strcasecmp(val, "gt64") == 0)
8857 buf_size = 256;
8858 else
8859 buf_size = 64;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008860 if (get_driver_type(dut) == DRIVER_WCN &&
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07008861 sta_set_addba_buf_size(dut, intf, buf_size)) {
8862 send_resp(dut, conn, SIGMA_ERROR,
8863 "ErrorCode,set addbaresp_buff_size failed");
8864 return 0;
8865 }
8866 }
8867
8868 val = get_param(cmd, "ADDBAReq_BufSize");
8869 if (val) {
8870 int buf_size;
8871
8872 if (strcasecmp(val, "gt64") == 0)
8873 buf_size = 256;
8874 else
8875 buf_size = 64;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008876 if (get_driver_type(dut) == DRIVER_WCN &&
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07008877 sta_set_addba_buf_size(dut, intf, buf_size)) {
8878 send_resp(dut, conn, SIGMA_ERROR,
8879 "ErrorCode,set addbareq_buff_size failed");
8880 return 0;
8881 }
8882 }
8883
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008884 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
8885}
8886
8887
8888static int sta_set_wireless_60g(struct sigma_dut *dut,
8889 struct sigma_conn *conn,
8890 struct sigma_cmd *cmd)
8891{
8892 const char *dev_role = get_param(cmd, "DevRole");
8893
8894 if (!dev_role) {
8895 send_resp(dut, conn, SIGMA_INVALID,
8896 "ErrorCode,DevRole not specified");
8897 return 0;
8898 }
8899
8900 if (strcasecmp(dev_role, "PCP") == 0)
8901 return sta_set_60g_pcp(dut, conn, cmd);
8902 if (strcasecmp(dev_role, "STA") == 0)
8903 return sta_set_60g_sta(dut, conn, cmd);
8904 send_resp(dut, conn, SIGMA_INVALID,
8905 "ErrorCode,DevRole not supported");
8906 return 0;
8907}
8908
8909
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05308910static int sta_set_wireless_oce(struct sigma_dut *dut, struct sigma_conn *conn,
8911 struct sigma_cmd *cmd)
8912{
8913 int status;
8914 const char *intf = get_param(cmd, "Interface");
8915 const char *val = get_param(cmd, "DevRole");
8916
8917 if (val && strcasecmp(val, "STA-CFON") == 0) {
8918 status = sta_cfon_set_wireless(dut, conn, cmd);
8919 if (status)
8920 return status;
8921 }
8922 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
8923}
8924
8925
Jouni Malinen67433fc2020-06-26 22:50:33 +03008926static enum sigma_cmd_result
8927sta_set_wireless_wpa3(struct sigma_dut *dut, struct sigma_conn *conn,
8928 struct sigma_cmd *cmd)
Vamsi Krishnac1633d22020-05-06 18:31:21 +05308929{
8930 const char *intf = get_param(cmd, "Interface");
8931 const char *val;
8932
8933 val = get_param(cmd, "ocvc");
8934 if (val)
8935 dut->ocvc = atoi(val);
8936
Jouni Malinen67433fc2020-06-26 22:50:33 +03008937 val = get_param(cmd, "ClientPrivacy");
8938 if (val) {
8939 dut->client_privacy = atoi(val);
8940 if (dut->client_privacy &&
8941 (wpa_command(intf, "SET mac_addr 1") < 0 ||
8942 wpa_command(intf, "SET rand_addr_lifetime 1") < 0 ||
8943 wpa_command(intf, "SET preassoc_mac_addr 1") < 0 ||
8944 wpa_command(intf, "SET gas_rand_mac_addr 1") < 0 ||
8945 wpa_command(intf, "SET gas_rand_addr_lifetime 1") < 0)) {
8946 send_resp(dut, conn, SIGMA_ERROR,
8947 "errorCode,Failed to enable random MAC address use");
8948 return STATUS_SENT_ERROR;
8949 }
8950 }
8951
Vamsi Krishnac1633d22020-05-06 18:31:21 +05308952 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
8953}
8954
8955
Jouni Malinenf7222712019-06-13 01:50:21 +03008956static enum sigma_cmd_result cmd_sta_set_wireless(struct sigma_dut *dut,
8957 struct sigma_conn *conn,
8958 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008959{
8960 const char *val;
8961
8962 val = get_param(cmd, "Program");
8963 if (val) {
8964 if (strcasecmp(val, "11n") == 0)
8965 return cmd_sta_set_11n(dut, conn, cmd);
Amarnath Hullur Subramanyam4f860292018-01-31 03:49:35 -08008966 if (strcasecmp(val, "VHT") == 0 || strcasecmp(val, "HE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008967 return cmd_sta_set_wireless_vht(dut, conn, cmd);
8968 if (strcasecmp(val, "60ghz") == 0)
8969 return sta_set_wireless_60g(dut, conn, cmd);
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05308970 if (strcasecmp(val, "OCE") == 0)
8971 return sta_set_wireless_oce(dut, conn, cmd);
Alexei Avshalom Lazar66bb9972018-12-18 16:01:43 +02008972 /* sta_set_wireless in WPS program is only used for 60G */
8973 if (is_60g_sigma_dut(dut))
8974 return sta_set_wireless_60g(dut, conn, cmd);
Vamsi Krishnac1633d22020-05-06 18:31:21 +05308975 if (strcasecmp(val, "WPA3") == 0)
8976 return sta_set_wireless_wpa3(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008977 send_resp(dut, conn, SIGMA_ERROR,
8978 "ErrorCode,Program value not supported");
8979 } else {
8980 send_resp(dut, conn, SIGMA_ERROR,
8981 "ErrorCode,Program argument not available");
8982 }
8983
8984 return 0;
8985}
8986
8987
8988static void ath_sta_inject_frame(struct sigma_dut *dut, const char *intf,
8989 int tid)
8990{
8991 char buf[100];
8992 int tid_to_dscp [] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 };
8993
Pradeep Reddy POTTETId31d1322016-10-13 17:22:03 +05308994 if (tid < 0 ||
8995 tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) {
8996 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid);
8997 return;
8998 }
8999
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009000 /*
9001 * Two ways to ensure that addba request with a
9002 * non zero TID could be sent out. EV 117296
9003 */
9004 snprintf(buf, sizeof(buf),
9005 "ping -c 8 -Q %d `arp -a | grep wlan0 | awk '{print $2}' | tr -d '()'`",
9006 tid);
9007 if (system(buf) != 0) {
9008 sigma_dut_print(dut, DUT_MSG_ERROR,
9009 "Ping did not send out");
9010 }
9011
9012 snprintf(buf, sizeof(buf),
9013 "iwconfig %s | grep Access | awk '{print $6}' > %s",
9014 intf, VI_QOS_TMP_FILE);
9015 if (system(buf) != 0)
9016 return;
9017
9018 snprintf(buf, sizeof(buf),
9019 "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s",
9020 intf, VI_QOS_TMP_FILE);
9021 if (system(buf) != 0)
9022 sigma_dut_print(dut, DUT_MSG_ERROR, "HWaddr matching failed");
9023
9024 snprintf(buf,sizeof(buf), "sed -n '3,$p' %s >> %s",
9025 VI_QOS_REFFILE, VI_QOS_TMP_FILE);
9026 if (system(buf) != 0) {
9027 sigma_dut_print(dut, DUT_MSG_ERROR,
9028 "VI_QOS_TEMP_FILE generation error failed");
9029 }
9030 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
9031 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
9032 if (system(buf) != 0) {
9033 sigma_dut_print(dut, DUT_MSG_ERROR,
9034 "VI_QOS_FILE generation failed");
9035 }
9036
9037 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
9038 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
9039 if (system(buf) != 0) {
9040 sigma_dut_print(dut, DUT_MSG_ERROR,
9041 "VI_QOS_FILE generation failed");
9042 }
9043
9044 snprintf(buf, sizeof(buf), "ethinject %s %s", intf, VI_QOS_FILE);
9045 if (system(buf) != 0) {
9046 }
9047}
9048
9049
9050static int ath_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
9051 struct sigma_cmd *cmd)
9052{
9053 const char *intf = get_param(cmd, "Interface");
9054 const char *val;
9055 int tid = 0;
9056 char buf[100];
9057
9058 val = get_param(cmd, "TID");
9059 if (val) {
9060 tid = atoi(val);
9061 if (tid)
9062 ath_sta_inject_frame(dut, intf, tid);
9063 }
9064
9065 /* Command sequence for ADDBA request on Peregrine based devices */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009066 run_iwpriv(dut, intf, "setaddbaoper 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009067
9068 snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4", intf, tid);
9069 if (system(buf) != 0) {
9070 sigma_dut_print(dut, DUT_MSG_ERROR,
9071 "wifitool senddelba failed");
9072 }
9073
9074 snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64", intf, tid);
9075 if (system(buf) != 0) {
9076 sigma_dut_print(dut, DUT_MSG_ERROR,
9077 "wifitool sendaddba failed");
9078 }
9079
9080 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
9081
9082 return 1;
9083}
9084
9085
Lior David9981b512017-01-20 13:16:40 +02009086#ifdef __linux__
9087
9088static int wil6210_send_addba(struct sigma_dut *dut, const char *dest_mac,
9089 int agg_size)
9090{
9091 char dir[128], buf[128];
9092 FILE *f;
9093 regex_t re;
9094 regmatch_t m[2];
Jouni Malinen3aa72862019-05-29 23:14:51 +03009095 int rc, ret = -1, vring_id, found, res;
Lior David9981b512017-01-20 13:16:40 +02009096
9097 if (wil6210_get_debugfs_dir(dut, dir, sizeof(dir))) {
9098 sigma_dut_print(dut, DUT_MSG_ERROR,
9099 "failed to get wil6210 debugfs dir");
9100 return -1;
9101 }
9102
Jouni Malinen3aa72862019-05-29 23:14:51 +03009103 res = snprintf(buf, sizeof(buf), "%s/vrings", dir);
9104 if (res < 0 || res >= sizeof(buf))
9105 return -1;
Lior David9981b512017-01-20 13:16:40 +02009106 f = fopen(buf, "r");
9107 if (!f) {
9108 sigma_dut_print(dut, DUT_MSG_ERROR, "failed to open: %s", buf);
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009109 /* newer wil6210 driver renamed file to "rings" */
Jouni Malinen3aa72862019-05-29 23:14:51 +03009110 res = snprintf(buf, sizeof(buf), "%s/rings", dir);
9111 if (res < 0 || res >= sizeof(buf))
9112 return -1;
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009113 f = fopen(buf, "r");
9114 if (!f) {
9115 sigma_dut_print(dut, DUT_MSG_ERROR,
9116 "failed to open: %s", buf);
9117 return -1;
9118 }
Lior David9981b512017-01-20 13:16:40 +02009119 }
9120
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009121 /* can be either VRING tx... or RING... */
9122 if (regcomp(&re, "RING tx_[ \t]*([0-9]+)", REG_EXTENDED)) {
Lior David9981b512017-01-20 13:16:40 +02009123 sigma_dut_print(dut, DUT_MSG_ERROR, "regcomp failed");
9124 goto out;
9125 }
9126
9127 /* find TX VRING for the mac address */
9128 found = 0;
9129 while (fgets(buf, sizeof(buf), f)) {
9130 if (strcasestr(buf, dest_mac)) {
9131 found = 1;
9132 break;
9133 }
9134 }
9135
9136 if (!found) {
9137 sigma_dut_print(dut, DUT_MSG_ERROR,
9138 "no TX VRING for %s", dest_mac);
9139 goto out;
9140 }
9141
9142 /* extract VRING ID, "VRING tx_<id> = {" */
9143 if (!fgets(buf, sizeof(buf), f)) {
9144 sigma_dut_print(dut, DUT_MSG_ERROR,
9145 "no VRING start line for %s", dest_mac);
9146 goto out;
9147 }
9148
9149 rc = regexec(&re, buf, 2, m, 0);
9150 regfree(&re);
9151 if (rc || m[1].rm_so < 0) {
9152 sigma_dut_print(dut, DUT_MSG_ERROR,
9153 "no VRING TX ID for %s", dest_mac);
9154 goto out;
9155 }
9156 buf[m[1].rm_eo] = 0;
9157 vring_id = atoi(&buf[m[1].rm_so]);
9158
9159 /* send the addba command */
9160 fclose(f);
Jouni Malinen3aa72862019-05-29 23:14:51 +03009161 res = snprintf(buf, sizeof(buf), "%s/back", dir);
9162 if (res < 0 || res >= sizeof(buf))
9163 return -1;
Lior David9981b512017-01-20 13:16:40 +02009164 f = fopen(buf, "w");
9165 if (!f) {
9166 sigma_dut_print(dut, DUT_MSG_ERROR,
9167 "failed to open: %s", buf);
9168 return -1;
9169 }
9170
9171 fprintf(f, "add %d %d\n", vring_id, agg_size);
9172
9173 ret = 0;
9174
9175out:
9176 fclose(f);
9177
9178 return ret;
9179}
9180
9181
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009182int send_addba_60g(struct sigma_dut *dut, struct sigma_conn *conn,
9183 struct sigma_cmd *cmd, const char *mac_param)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009184{
9185 const char *val;
9186 int tid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009187
9188 val = get_param(cmd, "TID");
9189 if (val) {
9190 tid = atoi(val);
9191 if (tid != 0) {
9192 sigma_dut_print(dut, DUT_MSG_ERROR,
9193 "Ignore TID %d for send_addba use TID 0 for 60g since only 0 required on TX",
9194 tid);
9195 }
9196 }
9197
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009198 val = get_param(cmd, mac_param);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009199 if (!val) {
9200 sigma_dut_print(dut, DUT_MSG_ERROR,
9201 "Currently not supporting addba for 60G without Dest_mac");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02009202 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009203 }
9204
Lior David9981b512017-01-20 13:16:40 +02009205 if (wil6210_send_addba(dut, val, dut->back_rcv_buf))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009206 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009207
9208 return 1;
9209}
9210
Lior David9981b512017-01-20 13:16:40 +02009211#endif /* __linux__ */
9212
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009213
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009214static int wcn_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
9215 struct sigma_cmd *cmd)
9216{
9217#ifdef NL80211_SUPPORT
9218 const char *intf = get_param(cmd, "Interface");
9219 const char *val;
9220 int tid = -1;
9221 int bufsize = 64;
9222 struct nl_msg *msg;
9223 int ret = 0;
9224 struct nlattr *params;
9225 int ifindex;
9226
9227 val = get_param(cmd, "TID");
9228 if (val)
9229 tid = atoi(val);
9230
9231 if (tid == -1) {
9232 send_resp(dut, conn, SIGMA_ERROR,
9233 "ErrorCode,sta_send_addba tid invalid");
9234 return 0;
9235 }
9236
9237 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
9238
9239 ifindex = if_nametoindex(intf);
9240 if (ifindex == 0) {
9241 sigma_dut_print(dut, DUT_MSG_ERROR,
9242 "%s: Index for interface %s failed",
9243 __func__, intf);
9244 send_resp(dut, conn, SIGMA_ERROR,
9245 "ErrorCode,sta_send_addba interface invalid");
9246 return 0;
9247 }
9248
9249 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9250 NL80211_CMD_VENDOR)) ||
9251 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9252 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9253 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9254 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
9255 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9256 nla_put_u8(msg,
9257 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADD_DEL_BA_SESSION,
9258 QCA_WLAN_ADD_BA) ||
9259 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BA_TID,
9260 tid) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -07009261 nla_put_u16(msg,
9262 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
9263 bufsize)) {
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009264 sigma_dut_print(dut, DUT_MSG_ERROR,
9265 "%s: err in adding vendor_cmd and vendor_data",
9266 __func__);
9267 nlmsg_free(msg);
9268 send_resp(dut, conn, SIGMA_ERROR,
9269 "ErrorCode,sta_send_addba err in adding vendor_cmd and vendor_data");
9270 return 0;
9271 }
9272 nla_nest_end(msg, params);
9273
9274 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9275 if (ret) {
9276 sigma_dut_print(dut, DUT_MSG_ERROR,
9277 "%s: err in send_and_recv_msgs, ret=%d",
9278 __func__, ret);
Sunil Dutt30605592018-05-04 20:35:50 +05309279 if (ret == -EOPNOTSUPP)
9280 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009281 send_resp(dut, conn, SIGMA_ERROR,
9282 "ErrorCode,sta_send_addba err in send_and_recv_msgs");
9283 return 0;
9284 }
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009285#else /* NL80211_SUPPORT */
9286 sigma_dut_print(dut, DUT_MSG_ERROR,
9287 "sta_send_addba not supported without NL80211_SUPPORT defined");
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009288#endif /* NL80211_SUPPORT */
Sunil Dutt30605592018-05-04 20:35:50 +05309289
9290 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009291}
9292
9293
Jouni Malinenf7222712019-06-13 01:50:21 +03009294static enum sigma_cmd_result cmd_sta_send_addba(struct sigma_dut *dut,
9295 struct sigma_conn *conn,
9296 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009297{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009298 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009299 case DRIVER_ATHEROS:
9300 return ath_sta_send_addba(dut, conn, cmd);
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009301 case DRIVER_WCN:
9302 return wcn_sta_send_addba(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +02009303#ifdef __linux__
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009304 case DRIVER_WIL6210:
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009305 return send_addba_60g(dut, conn, cmd, "Dest_mac");
Lior David9981b512017-01-20 13:16:40 +02009306#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009307 default:
9308 /*
9309 * There is no driver specific implementation for other drivers.
9310 * Ignore the command and report COMPLETE since the following
9311 * throughput test operation will end up sending ADDBA anyway.
9312 */
9313 return 1;
9314 }
9315}
9316
9317
9318int inject_eth_frame(int s, const void *data, size_t len,
9319 unsigned short ethtype, char *dst, char *src)
9320{
9321 struct iovec iov[4] = {
9322 {
9323 .iov_base = dst,
9324 .iov_len = ETH_ALEN,
9325 },
9326 {
9327 .iov_base = src,
9328 .iov_len = ETH_ALEN,
9329 },
9330 {
9331 .iov_base = &ethtype,
9332 .iov_len = sizeof(unsigned short),
9333 },
9334 {
9335 .iov_base = (void *) data,
9336 .iov_len = len,
9337 }
9338 };
9339 struct msghdr msg = {
9340 .msg_name = NULL,
9341 .msg_namelen = 0,
9342 .msg_iov = iov,
9343 .msg_iovlen = 4,
9344 .msg_control = NULL,
9345 .msg_controllen = 0,
9346 .msg_flags = 0,
9347 };
9348
9349 return sendmsg(s, &msg, 0);
9350}
9351
9352#if defined(__linux__) || defined(__QNXNTO__)
9353
9354int inject_frame(int s, const void *data, size_t len, int encrypt)
9355{
9356#define IEEE80211_RADIOTAP_F_WEP 0x04
9357#define IEEE80211_RADIOTAP_F_FRAG 0x08
9358 unsigned char rtap_hdr[] = {
9359 0x00, 0x00, /* radiotap version */
9360 0x0e, 0x00, /* radiotap length */
9361 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
9362 IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */
9363 0x00, /* padding */
9364 0x00, 0x00, /* RX and TX flags to indicate that */
9365 0x00, 0x00, /* this is the injected frame directly */
9366 };
9367 struct iovec iov[2] = {
9368 {
9369 .iov_base = &rtap_hdr,
9370 .iov_len = sizeof(rtap_hdr),
9371 },
9372 {
9373 .iov_base = (void *) data,
9374 .iov_len = len,
9375 }
9376 };
9377 struct msghdr msg = {
9378 .msg_name = NULL,
9379 .msg_namelen = 0,
9380 .msg_iov = iov,
9381 .msg_iovlen = 2,
9382 .msg_control = NULL,
9383 .msg_controllen = 0,
9384 .msg_flags = 0,
9385 };
9386
9387 if (encrypt)
9388 rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP;
9389
9390 return sendmsg(s, &msg, 0);
9391}
9392
9393
9394int open_monitor(const char *ifname)
9395{
9396#ifdef __QNXNTO__
9397 struct sockaddr_dl ll;
9398 int s;
9399
9400 memset(&ll, 0, sizeof(ll));
9401 ll.sdl_family = AF_LINK;
9402 ll.sdl_index = if_nametoindex(ifname);
9403 if (ll.sdl_index == 0) {
9404 perror("if_nametoindex");
9405 return -1;
9406 }
9407 s = socket(PF_INET, SOCK_RAW, 0);
9408#else /* __QNXNTO__ */
9409 struct sockaddr_ll ll;
9410 int s;
9411
9412 memset(&ll, 0, sizeof(ll));
9413 ll.sll_family = AF_PACKET;
9414 ll.sll_ifindex = if_nametoindex(ifname);
9415 if (ll.sll_ifindex == 0) {
9416 perror("if_nametoindex");
9417 return -1;
9418 }
9419 s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
9420#endif /* __QNXNTO__ */
9421 if (s < 0) {
9422 perror("socket[PF_PACKET,SOCK_RAW]");
9423 return -1;
9424 }
9425
9426 if (bind(s, (struct sockaddr *) &ll, sizeof(ll)) < 0) {
9427 perror("monitor socket bind");
9428 close(s);
9429 return -1;
9430 }
9431
9432 return s;
9433}
9434
9435
9436static int hex2num(char c)
9437{
9438 if (c >= '0' && c <= '9')
9439 return c - '0';
9440 if (c >= 'a' && c <= 'f')
9441 return c - 'a' + 10;
9442 if (c >= 'A' && c <= 'F')
9443 return c - 'A' + 10;
9444 return -1;
9445}
9446
9447
9448int hwaddr_aton(const char *txt, unsigned char *addr)
9449{
9450 int i;
9451
9452 for (i = 0; i < 6; i++) {
9453 int a, b;
9454
9455 a = hex2num(*txt++);
9456 if (a < 0)
9457 return -1;
9458 b = hex2num(*txt++);
9459 if (b < 0)
9460 return -1;
9461 *addr++ = (a << 4) | b;
9462 if (i < 5 && *txt++ != ':')
9463 return -1;
9464 }
9465
9466 return 0;
9467}
9468
9469#endif /* defined(__linux__) || defined(__QNXNTO__) */
9470
Veerendranath Jakkam49774122020-07-05 09:52:18 +05309471
9472#ifdef NL80211_SUPPORT
9473static int nl80211_send_frame_cmd(struct sigma_dut *dut, const char *intf,
9474 const u8 *data, size_t data_len, int freq)
9475{
9476 struct nl_msg *msg;
9477 int ret = 0;
9478 int ifindex;
9479
9480 ifindex = if_nametoindex(intf);
9481 if (ifindex == 0) {
9482 sigma_dut_print(dut, DUT_MSG_ERROR,
9483 "%s: Index for interface %s failed",
9484 __func__, intf);
9485 return -1;
9486 }
9487
9488 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9489 NL80211_CMD_FRAME)) ||
9490 (freq && nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
9491 nla_put(msg, NL80211_ATTR_FRAME, data_len, data)) {
9492 sigma_dut_print(dut, DUT_MSG_ERROR,
9493 "%s: Error in adding NL80211_CMD_FRAME",
9494 __func__);
9495 nlmsg_free(msg);
9496 return -1;
9497 }
9498
9499 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9500 if (ret) {
9501 sigma_dut_print(dut, DUT_MSG_ERROR,
9502 "nl80211: Frame command failed: ret=%d (%s) req=%u",
9503 ret, strerror(-ret), freq);
9504 return -1;
9505 }
9506
9507 return 0;
9508}
9509#endif /* NL80211_SUPPORT */
9510
9511
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009512enum send_frame_type {
9513 DISASSOC, DEAUTH, SAQUERY, AUTH, ASSOCREQ, REASSOCREQ, DLS_REQ
9514};
9515enum send_frame_protection {
9516 CORRECT_KEY, INCORRECT_KEY, UNPROTECTED
9517};
9518
9519
9520static int sta_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn,
Veerendranath Jakkam49774122020-07-05 09:52:18 +05309521 const char *intf, enum send_frame_type frame,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009522 enum send_frame_protection protected,
Veerendranath Jakkam49774122020-07-05 09:52:18 +05309523 const char *dest, int use_monitor)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009524{
9525#ifdef __linux__
9526 unsigned char buf[1000], *pos;
9527 int s, res;
9528 char bssid[20], addr[20];
9529 char result[32], ssid[100];
9530 size_t ssid_len;
9531
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009532 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009533 sizeof(result)) < 0 ||
9534 strncmp(result, "COMPLETED", 9) != 0) {
9535 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Not connected");
9536 return 0;
9537 }
9538
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009539 if (get_wpa_status(get_station_ifname(dut), "bssid",
9540 bssid, sizeof(bssid)) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009541 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9542 "current BSSID");
9543 return 0;
9544 }
9545
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009546 if (get_wpa_status(get_station_ifname(dut), "address",
9547 addr, sizeof(addr)) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009548 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9549 "own MAC address");
9550 return 0;
9551 }
9552
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009553 if (get_wpa_status(get_station_ifname(dut), "ssid", ssid, sizeof(ssid))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009554 < 0) {
9555 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9556 "current SSID");
9557 return 0;
9558 }
9559 ssid_len = strlen(ssid);
9560
9561 pos = buf;
9562
9563 /* Frame Control */
9564 switch (frame) {
9565 case DISASSOC:
9566 *pos++ = 0xa0;
9567 break;
9568 case DEAUTH:
9569 *pos++ = 0xc0;
9570 break;
9571 case SAQUERY:
9572 *pos++ = 0xd0;
9573 break;
9574 case AUTH:
9575 *pos++ = 0xb0;
9576 break;
9577 case ASSOCREQ:
9578 *pos++ = 0x00;
9579 break;
9580 case REASSOCREQ:
9581 *pos++ = 0x20;
9582 break;
9583 case DLS_REQ:
9584 *pos++ = 0xd0;
9585 break;
9586 }
9587
9588 if (protected == INCORRECT_KEY)
9589 *pos++ = 0x40; /* Set Protected field to 1 */
9590 else
9591 *pos++ = 0x00;
9592
9593 /* Duration */
9594 *pos++ = 0x00;
9595 *pos++ = 0x00;
9596
9597 /* addr1 = DA (current AP) */
9598 hwaddr_aton(bssid, pos);
9599 pos += 6;
9600 /* addr2 = SA (own address) */
9601 hwaddr_aton(addr, pos);
9602 pos += 6;
9603 /* addr3 = BSSID (current AP) */
9604 hwaddr_aton(bssid, pos);
9605 pos += 6;
9606
9607 /* Seq# (to be filled by driver/mac80211) */
9608 *pos++ = 0x00;
9609 *pos++ = 0x00;
9610
9611 if (protected == INCORRECT_KEY) {
9612 /* CCMP parameters */
9613 memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8);
9614 pos += 8;
9615 }
9616
9617 if (protected == INCORRECT_KEY) {
9618 switch (frame) {
9619 case DEAUTH:
9620 /* Reason code (encrypted) */
9621 memcpy(pos, "\xa7\x39", 2);
9622 pos += 2;
9623 break;
9624 case DISASSOC:
9625 /* Reason code (encrypted) */
9626 memcpy(pos, "\xa7\x39", 2);
9627 pos += 2;
9628 break;
9629 case SAQUERY:
9630 /* Category|Action|TransID (encrypted) */
9631 memcpy(pos, "\x6f\xbd\xe9\x4d", 4);
9632 pos += 4;
9633 break;
9634 default:
9635 return -1;
9636 }
9637
9638 /* CCMP MIC */
9639 memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8);
9640 pos += 8;
9641 } else {
9642 switch (frame) {
9643 case DEAUTH:
9644 /* reason code = 8 */
9645 *pos++ = 0x08;
9646 *pos++ = 0x00;
9647 break;
9648 case DISASSOC:
9649 /* reason code = 8 */
9650 *pos++ = 0x08;
9651 *pos++ = 0x00;
9652 break;
9653 case SAQUERY:
9654 /* Category - SA Query */
9655 *pos++ = 0x08;
9656 /* SA query Action - Request */
9657 *pos++ = 0x00;
9658 /* Transaction ID */
9659 *pos++ = 0x12;
9660 *pos++ = 0x34;
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +05309661 if (dut->saquery_oci_freq) {
9662 /* OCI IE - Extended ID */
9663 *pos++ = 0xFF;
9664 *pos++ = 0x04;
9665 *pos++ = 0x36;
9666 /* Operating Class */
9667 *pos++ = 0x74;
9668 /* Primary Channel */
9669 *pos++ = freq_to_channel(dut->saquery_oci_freq);
9670 /* Frequency Segment 1 Channel Number */
9671 *pos++ = 0x00;
9672 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009673 break;
9674 case AUTH:
9675 /* Auth Alg (Open) */
9676 *pos++ = 0x00;
9677 *pos++ = 0x00;
9678 /* Seq# */
9679 *pos++ = 0x01;
9680 *pos++ = 0x00;
9681 /* Status code */
9682 *pos++ = 0x00;
9683 *pos++ = 0x00;
9684 break;
9685 case ASSOCREQ:
9686 /* Capability Information */
9687 *pos++ = 0x31;
9688 *pos++ = 0x04;
9689 /* Listen Interval */
9690 *pos++ = 0x0a;
9691 *pos++ = 0x00;
9692 /* SSID */
9693 *pos++ = 0x00;
9694 *pos++ = ssid_len;
9695 memcpy(pos, ssid, ssid_len);
9696 pos += ssid_len;
9697 /* Supported Rates */
9698 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
9699 10);
9700 pos += 10;
9701 /* Extended Supported Rates */
9702 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
9703 pos += 6;
9704 /* RSN */
9705 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
9706 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
9707 "\x00\x00\x00\x00\x0f\xac\x06", 28);
9708 pos += 28;
9709 break;
9710 case REASSOCREQ:
9711 /* Capability Information */
9712 *pos++ = 0x31;
9713 *pos++ = 0x04;
9714 /* Listen Interval */
9715 *pos++ = 0x0a;
9716 *pos++ = 0x00;
9717 /* Current AP */
9718 hwaddr_aton(bssid, pos);
9719 pos += 6;
9720 /* SSID */
9721 *pos++ = 0x00;
9722 *pos++ = ssid_len;
9723 memcpy(pos, ssid, ssid_len);
9724 pos += ssid_len;
9725 /* Supported Rates */
9726 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
9727 10);
9728 pos += 10;
9729 /* Extended Supported Rates */
9730 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
9731 pos += 6;
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +05309732 /* RSNE - Group and Pairwise ciphers */
9733 memcpy(pos,
9734 "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x04",
9735 14);
9736 pos += 14;
9737 /* RSNE - AKM Suite count */
9738 *pos++ = 0x01;
9739 *pos++ = 0x00;
9740 /* RSNE - AKM Suites */
9741 if (dut->program == PROGRAM_WPA3)
9742 memcpy(pos, "\x00\x0f\xac\x08", 4);
9743 else
9744 memcpy(pos, "\x00\x0f\xac\x02", 4);
9745 pos += 4;
9746 /* RSNE - Capabilities */
9747 *pos++ = 0xc0;
9748 if (dut->ocvc)
9749 *pos++ = 0x40;
9750 else
9751 *pos++ = 0x00;
9752 /* RSNE - PMKID list and Group Management Ciphers */
9753 memcpy(pos, "\x00\x00\x00\x0f\xac\x06", 6);
9754 pos += 6;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009755 break;
9756 case DLS_REQ:
9757 /* Category - DLS */
9758 *pos++ = 0x02;
9759 /* DLS Action - Request */
9760 *pos++ = 0x00;
9761 /* Destination MACAddress */
9762 if (dest)
9763 hwaddr_aton(dest, pos);
9764 else
9765 memset(pos, 0, 6);
9766 pos += 6;
9767 /* Source MACAddress */
9768 hwaddr_aton(addr, pos);
9769 pos += 6;
9770 /* Capability Information */
9771 *pos++ = 0x10; /* Privacy */
9772 *pos++ = 0x06; /* QoS */
9773 /* DLS Timeout Value */
9774 *pos++ = 0x00;
9775 *pos++ = 0x01;
9776 /* Supported rates */
9777 *pos++ = 0x01;
9778 *pos++ = 0x08;
9779 *pos++ = 0x0c; /* 6 Mbps */
9780 *pos++ = 0x12; /* 9 Mbps */
9781 *pos++ = 0x18; /* 12 Mbps */
9782 *pos++ = 0x24; /* 18 Mbps */
9783 *pos++ = 0x30; /* 24 Mbps */
9784 *pos++ = 0x48; /* 36 Mbps */
9785 *pos++ = 0x60; /* 48 Mbps */
9786 *pos++ = 0x6c; /* 54 Mbps */
9787 /* TODO: Extended Supported Rates */
9788 /* TODO: HT Capabilities */
9789 break;
9790 }
9791 }
9792
Veerendranath Jakkam49774122020-07-05 09:52:18 +05309793 if (use_monitor) {
9794 s = open_monitor("sigmadut");
9795 if (s < 0) {
9796 send_resp(dut, conn, SIGMA_ERROR,
9797 "errorCode,Failed to open monitor socket");
9798 return 0;
9799 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009800
Veerendranath Jakkam49774122020-07-05 09:52:18 +05309801 res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY);
9802 if (res < 0) {
9803 send_resp(dut, conn, SIGMA_ERROR,
9804 "errorCode,Failed to inject frame");
9805 close(s);
9806 return 0;
9807 }
9808 if (res < pos - buf) {
9809 send_resp(dut, conn, SIGMA_ERROR,
9810 "errorCode,Only partial frame sent");
9811 close(s);
9812 return 0;
9813 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009814
Veerendranath Jakkam49774122020-07-05 09:52:18 +05309815 close(s);
9816 } else {
9817#ifdef NL80211_SUPPORT
9818 int freq;
9819 char freq_str[10];
9820
9821 if (get_wpa_status(get_station_ifname(dut), "freq",
9822 freq_str, sizeof(freq_str)) < 0) {
9823 send_resp(dut, conn, SIGMA_ERROR,
9824 "errorCode,Could not get current operating frequency");
9825 return 0;
9826 }
9827 freq = atoi(freq_str);
9828
9829 if (nl80211_send_frame_cmd(dut, intf, buf, pos - buf, freq)) {
9830 send_resp(dut, conn, SIGMA_ERROR,
9831 "errorCode,Failed to inject frame");
9832 return 0;
9833 }
9834#else /* NL80211_SUPPORT */
9835 send_resp(dut, conn, SIGMA_ERROR,
9836 "errorCode,Failed to inject frame (no NL80211_SUPPORT)");
9837 return 0;
9838#endif /* NL80211_SUPPORT */
9839 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009840
9841 return 1;
9842#else /* __linux__ */
9843 send_resp(dut, conn, SIGMA_ERROR, "errorCode,sta_send_frame not "
9844 "yet supported");
9845 return 0;
9846#endif /* __linux__ */
9847}
9848
9849
9850static int cmd_sta_send_frame_tdls(struct sigma_dut *dut,
9851 struct sigma_conn *conn,
9852 struct sigma_cmd *cmd)
9853{
9854 const char *intf = get_param(cmd, "Interface");
9855 const char *sta, *val;
9856 unsigned char addr[ETH_ALEN];
9857 char buf[100];
9858
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +03009859 if (!intf)
9860 return -1;
9861
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009862 sta = get_param(cmd, "peer");
9863 if (sta == NULL)
9864 sta = get_param(cmd, "station");
9865 if (sta == NULL) {
9866 send_resp(dut, conn, SIGMA_ERROR,
9867 "ErrorCode,Missing peer address");
9868 return 0;
9869 }
9870 if (hwaddr_aton(sta, addr) < 0) {
9871 send_resp(dut, conn, SIGMA_ERROR,
9872 "ErrorCode,Invalid peer address");
9873 return 0;
9874 }
9875
9876 val = get_param(cmd, "type");
9877 if (val == NULL)
9878 return -1;
9879
9880 if (strcasecmp(val, "DISCOVERY") == 0) {
9881 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", sta);
9882 if (wpa_command(intf, buf) < 0) {
9883 send_resp(dut, conn, SIGMA_ERROR,
9884 "ErrorCode,Failed to send TDLS discovery");
9885 return 0;
9886 }
9887 return 1;
9888 }
9889
9890 if (strcasecmp(val, "SETUP") == 0) {
9891 int status = 0, timeout = 0;
9892
9893 val = get_param(cmd, "Status");
9894 if (val)
9895 status = atoi(val);
9896
9897 val = get_param(cmd, "Timeout");
9898 if (val)
9899 timeout = atoi(val);
9900
9901 if (status != 0 && status != 37) {
9902 send_resp(dut, conn, SIGMA_ERROR,
9903 "ErrorCode,Unsupported status value");
9904 return 0;
9905 }
9906
9907 if (timeout != 0 && timeout != 301) {
9908 send_resp(dut, conn, SIGMA_ERROR,
9909 "ErrorCode,Unsupported timeout value");
9910 return 0;
9911 }
9912
9913 if (status && timeout) {
9914 send_resp(dut, conn, SIGMA_ERROR,
9915 "ErrorCode,Unsupported timeout+status "
9916 "combination");
9917 return 0;
9918 }
9919
9920 if (status == 37 &&
9921 wpa_command(intf, "SET tdls_testing 0x200")) {
9922 send_resp(dut, conn, SIGMA_ERROR,
9923 "ErrorCode,Failed to enable "
9924 "decline setup response test mode");
9925 return 0;
9926 }
9927
9928 if (timeout == 301) {
9929 int res;
9930 if (dut->no_tpk_expiration)
9931 res = wpa_command(intf,
9932 "SET tdls_testing 0x108");
9933 else
9934 res = wpa_command(intf,
9935 "SET tdls_testing 0x8");
9936 if (res) {
9937 send_resp(dut, conn, SIGMA_ERROR,
9938 "ErrorCode,Failed to set short TPK "
9939 "lifetime");
9940 return 0;
9941 }
9942 }
9943
9944 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", sta);
9945 if (wpa_command(intf, buf) < 0) {
9946 send_resp(dut, conn, SIGMA_ERROR,
9947 "ErrorCode,Failed to send TDLS setup");
9948 return 0;
9949 }
9950 return 1;
9951 }
9952
9953 if (strcasecmp(val, "TEARDOWN") == 0) {
9954 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", sta);
9955 if (wpa_command(intf, buf) < 0) {
9956 send_resp(dut, conn, SIGMA_ERROR,
9957 "ErrorCode,Failed to send TDLS teardown");
9958 return 0;
9959 }
9960 return 1;
9961 }
9962
9963 send_resp(dut, conn, SIGMA_ERROR,
9964 "ErrorCode,Unsupported TDLS frame");
9965 return 0;
9966}
9967
9968
9969static int sta_ap_known(const char *ifname, const char *bssid)
9970{
9971 char buf[4096];
9972
Jouni Malinendd32f192018-09-15 02:55:19 +03009973 snprintf(buf, sizeof(buf), "BSS MASK=1 %s", bssid);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009974 if (wpa_command_resp(ifname, buf, buf, sizeof(buf)) < 0)
9975 return 0;
9976 if (strncmp(buf, "id=", 3) != 0)
9977 return 0;
9978 return 1;
9979}
9980
9981
9982static int sta_scan_ap(struct sigma_dut *dut, const char *ifname,
9983 const char *bssid)
9984{
9985 int res;
9986 struct wpa_ctrl *ctrl;
9987 char buf[256];
9988
9989 if (sta_ap_known(ifname, bssid))
9990 return 0;
9991 sigma_dut_print(dut, DUT_MSG_DEBUG,
9992 "AP not in BSS table - start scan");
9993
9994 ctrl = open_wpa_mon(ifname);
9995 if (ctrl == NULL) {
9996 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
9997 "wpa_supplicant monitor connection");
9998 return -1;
9999 }
10000
10001 if (wpa_command(ifname, "SCAN") < 0) {
10002 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to start scan");
10003 wpa_ctrl_detach(ctrl);
10004 wpa_ctrl_close(ctrl);
10005 return -1;
10006 }
10007
10008 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
10009 buf, sizeof(buf));
10010
10011 wpa_ctrl_detach(ctrl);
10012 wpa_ctrl_close(ctrl);
10013
10014 if (res < 0) {
10015 sigma_dut_print(dut, DUT_MSG_INFO, "Scan did not complete");
10016 return -1;
10017 }
10018
10019 if (sta_ap_known(ifname, bssid))
10020 return 0;
10021 sigma_dut_print(dut, DUT_MSG_INFO, "AP not in BSS table");
10022 return -1;
10023}
10024
10025
10026static int cmd_sta_send_frame_hs2_neighadv(struct sigma_dut *dut,
10027 struct sigma_conn *conn,
10028 struct sigma_cmd *cmd,
10029 const char *intf)
10030{
10031 char buf[200];
10032
10033 snprintf(buf, sizeof(buf), "ndsend 2001:DB8::1 %s", intf);
10034 if (system(buf) != 0) {
10035 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Failed to run "
10036 "ndsend");
10037 return 0;
10038 }
10039
10040 return 1;
10041}
10042
10043
10044static int cmd_sta_send_frame_hs2_neighsolreq(struct sigma_dut *dut,
10045 struct sigma_conn *conn,
10046 struct sigma_cmd *cmd,
10047 const char *intf)
10048{
10049 char buf[200];
10050 const char *ip = get_param(cmd, "SenderIP");
10051
Peng Xu26b356d2017-10-04 17:58:16 -070010052 if (!ip)
10053 return 0;
10054
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010055 snprintf(buf, sizeof(buf), "ndisc6 -nm %s %s -r 4", ip, intf);
10056 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10057 if (system(buf) == 0) {
10058 sigma_dut_print(dut, DUT_MSG_INFO,
10059 "Neighbor Solicitation got a response "
10060 "for %s@%s", ip, intf);
10061 }
10062
10063 return 1;
10064}
10065
10066
10067static int cmd_sta_send_frame_hs2_arpprobe(struct sigma_dut *dut,
10068 struct sigma_conn *conn,
10069 struct sigma_cmd *cmd,
10070 const char *ifname)
10071{
10072 char buf[200];
10073 const char *ip = get_param(cmd, "SenderIP");
10074
10075 if (ip == NULL) {
10076 send_resp(dut, conn, SIGMA_ERROR,
10077 "ErrorCode,Missing SenderIP parameter");
10078 return 0;
10079 }
10080 snprintf(buf, sizeof(buf), "arping -I %s -D %s -c 4", ifname, ip);
10081 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10082 if (system(buf) != 0) {
10083 sigma_dut_print(dut, DUT_MSG_INFO, "arping DAD got a response "
10084 "for %s@%s", ip, ifname);
10085 }
10086
10087 return 1;
10088}
10089
10090
10091static int cmd_sta_send_frame_hs2_arpannounce(struct sigma_dut *dut,
10092 struct sigma_conn *conn,
10093 struct sigma_cmd *cmd,
10094 const char *ifname)
10095{
10096 char buf[200];
10097 char ip[16];
10098 int s;
Peng Xub3756882017-10-04 14:39:09 -070010099 struct ifreq ifr;
10100 struct sockaddr_in saddr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010101
10102 s = socket(PF_INET, SOCK_DGRAM, 0);
Peng Xub3756882017-10-04 14:39:09 -070010103 if (s < 0) {
10104 perror("socket");
10105 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010106 }
10107
Peng Xub3756882017-10-04 14:39:09 -070010108 memset(&ifr, 0, sizeof(ifr));
10109 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
10110 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
10111 sigma_dut_print(dut, DUT_MSG_INFO,
10112 "Failed to get %s IP address: %s",
10113 ifname, strerror(errno));
10114 close(s);
10115 return -1;
10116 }
10117 close(s);
10118
10119 memcpy(&saddr, &ifr.ifr_addr, sizeof(struct sockaddr_in));
10120 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
10121
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010122 snprintf(buf, sizeof(buf), "arping -I %s -s %s %s -c 4", ifname, ip,
10123 ip);
10124 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10125 if (system(buf) != 0) {
10126 }
10127
10128 return 1;
10129}
10130
10131
10132static int cmd_sta_send_frame_hs2_arpreply(struct sigma_dut *dut,
10133 struct sigma_conn *conn,
10134 struct sigma_cmd *cmd,
10135 const char *ifname)
10136{
10137 char buf[200], addr[20];
10138 char dst[ETH_ALEN], src[ETH_ALEN];
10139 short ethtype = htons(ETH_P_ARP);
10140 char *pos;
10141 int s, res;
10142 const char *val;
10143 struct sockaddr_in taddr;
10144
10145 val = get_param(cmd, "dest");
10146 if (val)
10147 hwaddr_aton(val, (unsigned char *) dst);
10148
10149 val = get_param(cmd, "DestIP");
10150 if (val)
10151 inet_aton(val, &taddr.sin_addr);
Peng Xu151c9e12017-10-04 14:39:09 -070010152 else
10153 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010154
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010155 if (get_wpa_status(get_station_ifname(dut), "address", addr,
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010156 sizeof(addr)) < 0)
10157 return -2;
10158 hwaddr_aton(addr, (unsigned char *) src);
10159
10160 pos = buf;
10161 *pos++ = 0x00;
10162 *pos++ = 0x01;
10163 *pos++ = 0x08;
10164 *pos++ = 0x00;
10165 *pos++ = 0x06;
10166 *pos++ = 0x04;
10167 *pos++ = 0x00;
10168 *pos++ = 0x02;
10169 memcpy(pos, src, ETH_ALEN);
10170 pos += ETH_ALEN;
10171 memcpy(pos, &taddr.sin_addr, 4);
10172 pos += 4;
10173 memcpy(pos, dst, ETH_ALEN);
10174 pos += ETH_ALEN;
10175 memcpy(pos, &taddr.sin_addr, 4);
10176 pos += 4;
10177
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010178 s = open_monitor(get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010179 if (s < 0) {
10180 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
10181 "monitor socket");
10182 return 0;
10183 }
10184
10185 res = inject_eth_frame(s, buf, pos - buf, ethtype, dst, src);
10186 if (res < 0) {
10187 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
10188 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +053010189 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010190 return 0;
10191 }
10192
10193 close(s);
10194
10195 return 1;
10196}
10197
10198
10199static int cmd_sta_send_frame_hs2_dls_req(struct sigma_dut *dut,
10200 struct sigma_conn *conn,
10201 struct sigma_cmd *cmd,
10202 const char *intf, const char *dest)
10203{
10204 char buf[100];
10205
10206 if (if_nametoindex("sigmadut") == 0) {
10207 snprintf(buf, sizeof(buf),
10208 "iw dev %s interface add sigmadut type monitor",
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010209 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010210 if (system(buf) != 0 ||
10211 if_nametoindex("sigmadut") == 0) {
10212 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
10213 "monitor interface with '%s'", buf);
10214 return -2;
10215 }
10216 }
10217
10218 if (system("ifconfig sigmadut up") != 0) {
10219 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
10220 "monitor interface up");
10221 return -2;
10222 }
10223
Veerendranath Jakkam49774122020-07-05 09:52:18 +053010224 return sta_inject_frame(dut, conn, intf, DLS_REQ, UNPROTECTED, dest, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010225}
10226
10227
10228static int cmd_sta_send_frame_hs2(struct sigma_dut *dut,
10229 struct sigma_conn *conn,
10230 struct sigma_cmd *cmd)
10231{
10232 const char *intf = get_param(cmd, "Interface");
10233 const char *dest = get_param(cmd, "Dest");
10234 const char *type = get_param(cmd, "FrameName");
10235 const char *val;
10236 char buf[200], *pos, *end;
10237 int count, count2;
10238
10239 if (type == NULL)
10240 type = get_param(cmd, "Type");
10241
10242 if (intf == NULL || dest == NULL || type == NULL)
10243 return -1;
10244
10245 if (strcasecmp(type, "NeighAdv") == 0)
10246 return cmd_sta_send_frame_hs2_neighadv(dut, conn, cmd, intf);
10247
10248 if (strcasecmp(type, "NeighSolicitReq") == 0)
10249 return cmd_sta_send_frame_hs2_neighsolreq(dut, conn, cmd, intf);
10250
10251 if (strcasecmp(type, "ARPProbe") == 0)
10252 return cmd_sta_send_frame_hs2_arpprobe(dut, conn, cmd, intf);
10253
10254 if (strcasecmp(type, "ARPAnnounce") == 0)
10255 return cmd_sta_send_frame_hs2_arpannounce(dut, conn, cmd, intf);
10256
10257 if (strcasecmp(type, "ARPReply") == 0)
10258 return cmd_sta_send_frame_hs2_arpreply(dut, conn, cmd, intf);
10259
10260 if (strcasecmp(type, "DLS-request") == 0 ||
10261 strcasecmp(type, "DLSrequest") == 0)
10262 return cmd_sta_send_frame_hs2_dls_req(dut, conn, cmd, intf,
10263 dest);
10264
10265 if (strcasecmp(type, "ANQPQuery") != 0 &&
10266 strcasecmp(type, "Query") != 0) {
10267 send_resp(dut, conn, SIGMA_ERROR,
10268 "ErrorCode,Unsupported HS 2.0 send frame type");
10269 return 0;
10270 }
10271
10272 if (sta_scan_ap(dut, intf, dest) < 0) {
10273 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not find "
10274 "the requested AP");
10275 return 0;
10276 }
10277
10278 pos = buf;
10279 end = buf + sizeof(buf);
10280 count = 0;
10281 pos += snprintf(pos, end - pos, "ANQP_GET %s ", dest);
10282
10283 val = get_param(cmd, "ANQP_CAP_LIST");
10284 if (val && atoi(val)) {
10285 pos += snprintf(pos, end - pos, "%s257", count > 0 ? "," : "");
10286 count++;
10287 }
10288
10289 val = get_param(cmd, "VENUE_NAME");
10290 if (val && atoi(val)) {
10291 pos += snprintf(pos, end - pos, "%s258", count > 0 ? "," : "");
10292 count++;
10293 }
10294
10295 val = get_param(cmd, "NETWORK_AUTH_TYPE");
10296 if (val && atoi(val)) {
10297 pos += snprintf(pos, end - pos, "%s260", count > 0 ? "," : "");
10298 count++;
10299 }
10300
10301 val = get_param(cmd, "ROAMING_CONS");
10302 if (val && atoi(val)) {
10303 pos += snprintf(pos, end - pos, "%s261", count > 0 ? "," : "");
10304 count++;
10305 }
10306
10307 val = get_param(cmd, "IP_ADDR_TYPE_AVAILABILITY");
10308 if (val && atoi(val)) {
10309 pos += snprintf(pos, end - pos, "%s262", count > 0 ? "," : "");
10310 count++;
10311 }
10312
10313 val = get_param(cmd, "NAI_REALM_LIST");
10314 if (val && atoi(val)) {
10315 pos += snprintf(pos, end - pos, "%s263", count > 0 ? "," : "");
10316 count++;
10317 }
10318
10319 val = get_param(cmd, "3GPP_INFO");
10320 if (val && atoi(val)) {
10321 pos += snprintf(pos, end - pos, "%s264", count > 0 ? "," : "");
10322 count++;
10323 }
10324
10325 val = get_param(cmd, "DOMAIN_LIST");
10326 if (val && atoi(val)) {
10327 pos += snprintf(pos, end - pos, "%s268", count > 0 ? "," : "");
10328 count++;
10329 }
10330
Jouni Malinen34cf9532018-04-29 19:26:33 +030010331 val = get_param(cmd, "Venue_URL");
10332 if (val && atoi(val)) {
10333 pos += snprintf(pos, end - pos, "%s277", count > 0 ? "," : "");
10334 count++;
10335 }
10336
Jouni Malinend3bca5d2018-04-29 17:25:23 +030010337 val = get_param(cmd, "Advice_Of_Charge");
10338 if (val && atoi(val)) {
10339 pos += snprintf(pos, end - pos, "%s278", count > 0 ? "," : "");
10340 count++;
10341 }
10342
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010343 if (count && wpa_command(intf, buf)) {
10344 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,ANQP_GET failed");
10345 return 0;
10346 }
10347
10348 pos = buf;
10349 end = buf + sizeof(buf);
10350 count2 = 0;
10351 pos += snprintf(pos, end - pos, "HS20_ANQP_GET %s ", dest);
10352
10353 val = get_param(cmd, "HS_CAP_LIST");
10354 if (val && atoi(val)) {
10355 pos += snprintf(pos, end - pos, "%s2", count2 > 0 ? "," : "");
10356 count2++;
10357 }
10358
10359 val = get_param(cmd, "OPER_NAME");
10360 if (val && atoi(val)) {
10361 pos += snprintf(pos, end - pos, "%s3", count2 > 0 ? "," : "");
10362 count2++;
10363 }
10364
10365 val = get_param(cmd, "WAN_METRICS");
10366 if (!val)
10367 val = get_param(cmd, "WAN_MAT");
10368 if (!val)
10369 val = get_param(cmd, "WAN_MET");
10370 if (val && atoi(val)) {
10371 pos += snprintf(pos, end - pos, "%s4", count2 > 0 ? "," : "");
10372 count2++;
10373 }
10374
10375 val = get_param(cmd, "CONNECTION_CAPABILITY");
10376 if (val && atoi(val)) {
10377 pos += snprintf(pos, end - pos, "%s5", count2 > 0 ? "," : "");
10378 count2++;
10379 }
10380
10381 val = get_param(cmd, "OP_CLASS");
10382 if (val && atoi(val)) {
10383 pos += snprintf(pos, end - pos, "%s7", count2 > 0 ? "," : "");
10384 count2++;
10385 }
10386
10387 val = get_param(cmd, "OSU_PROVIDER_LIST");
10388 if (val && atoi(val)) {
10389 pos += snprintf(pos, end - pos, "%s8", count2 > 0 ? "," : "");
10390 count2++;
10391 }
10392
Jouni Malinenf67afec2018-04-29 19:24:58 +030010393 val = get_param(cmd, "OPER_ICON_METADATA");
10394 if (!val)
10395 val = get_param(cmd, "OPERATOR_ICON_METADATA");
10396 if (val && atoi(val)) {
10397 pos += snprintf(pos, end - pos, "%s12", count2 > 0 ? "," : "");
10398 count2++;
10399 }
10400
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010401 if (count && count2) {
10402 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before sending out "
10403 "second query");
10404 sleep(1);
10405 }
10406
10407 if (count2 && wpa_command(intf, buf)) {
10408 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,HS20_ANQP_GET "
10409 "failed");
10410 return 0;
10411 }
10412
10413 val = get_param(cmd, "NAI_HOME_REALM_LIST");
10414 if (val) {
10415 if (count || count2) {
10416 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
10417 "sending out second query");
10418 sleep(1);
10419 }
10420
10421 if (strcmp(val, "1") == 0)
10422 val = "mail.example.com";
10423 snprintf(buf, end - pos,
10424 "HS20_GET_NAI_HOME_REALM_LIST %s realm=%s",
10425 dest, val);
10426 if (wpa_command(intf, buf)) {
10427 send_resp(dut, conn, SIGMA_ERROR,
10428 "ErrorCode,HS20_GET_NAI_HOME_REALM_LIST "
10429 "failed");
10430 return 0;
10431 }
10432 }
10433
10434 val = get_param(cmd, "ICON_REQUEST");
10435 if (val) {
10436 if (count || count2) {
10437 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
10438 "sending out second query");
10439 sleep(1);
10440 }
10441
10442 snprintf(buf, end - pos,
10443 "HS20_ICON_REQUEST %s %s", dest, val);
10444 if (wpa_command(intf, buf)) {
10445 send_resp(dut, conn, SIGMA_ERROR,
10446 "ErrorCode,HS20_ICON_REQUEST failed");
10447 return 0;
10448 }
10449 }
10450
10451 return 1;
10452}
10453
10454
10455static int ath_sta_send_frame_vht(struct sigma_dut *dut,
10456 struct sigma_conn *conn,
10457 struct sigma_cmd *cmd)
10458{
10459 const char *val;
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010460 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010461 int chwidth, nss;
10462
10463 val = get_param(cmd, "framename");
10464 if (!val)
10465 return -1;
10466 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
10467
10468 /* Command sequence to generate Op mode notification */
10469 if (val && strcasecmp(val, "Op_md_notif_frm") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010470 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010471
10472 /* Disable STBC */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010473 run_iwpriv(dut, ifname, "tx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010474
10475 /* Extract Channel width */
10476 val = get_param(cmd, "Channel_width");
10477 if (val) {
10478 switch (atoi(val)) {
10479 case 20:
10480 chwidth = 0;
10481 break;
10482 case 40:
10483 chwidth = 1;
10484 break;
10485 case 80:
10486 chwidth = 2;
10487 break;
10488 case 160:
10489 chwidth = 3;
10490 break;
10491 default:
10492 chwidth = 2;
10493 break;
10494 }
10495
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010496 run_iwpriv(dut, ifname, "chwidth %d", chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010497 }
10498
10499 /* Extract NSS */
10500 val = get_param(cmd, "NSS");
10501 if (val) {
10502 switch (atoi(val)) {
10503 case 1:
10504 nss = 1;
10505 break;
10506 case 2:
10507 nss = 3;
10508 break;
10509 case 3:
10510 nss = 7;
10511 break;
10512 default:
10513 /* We do not support NSS > 3 */
10514 nss = 3;
10515 break;
10516 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010517 run_iwpriv(dut, ifname, "rxchainmask %d", nss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010518 }
10519
10520 /* Opmode notify */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010521 run_iwpriv(dut, ifname, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010522 }
10523
10524 return 1;
10525}
10526
10527
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070010528static int wcn_sta_set_pmf_config(struct sigma_dut *dut, const char *intf,
10529 enum send_frame_protection protected)
10530{
10531#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +053010532 return wcn_wifi_test_config_set_u8(
10533 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_PMF_PROTECTION,
10534 protected);
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070010535#else /* NL80211_SUPPORT */
10536 sigma_dut_print(dut, DUT_MSG_ERROR,
10537 "PMF config cannot be set without NL80211_SUPPORT defined");
10538 return -1;
10539#endif /* NL80211_SUPPORT */
10540}
10541
10542
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010543static int cmd_sta_send_frame_vht(struct sigma_dut *dut,
10544 struct sigma_conn *conn,
10545 struct sigma_cmd *cmd)
10546{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010547 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010548 case DRIVER_ATHEROS:
10549 return ath_sta_send_frame_vht(dut, conn, cmd);
10550 default:
10551 send_resp(dut, conn, SIGMA_ERROR,
10552 "errorCode,Unsupported sta_set_frame(VHT) with the current driver");
10553 return 0;
10554 }
10555}
10556
10557
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070010558static int wcn_sta_send_disassoc(struct sigma_dut *dut, const char *intf)
10559{
10560#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +053010561 return wcn_wifi_test_config_set_flag(
10562 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_DISASSOC_TX);
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070010563#else /* NL80211_SUPPORT */
10564 sigma_dut_print(dut, DUT_MSG_ERROR,
10565 "Disassoc Tx cannot be done without NL80211_SUPPORT defined");
10566 return -1;
10567#endif /* NL80211_SUPPORT */
10568}
10569
10570
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010571static int wcn_sta_send_frame_he(struct sigma_dut *dut, struct sigma_conn *conn,
10572 struct sigma_cmd *cmd)
10573{
10574 const char *val;
10575 const char *intf = get_param(cmd, "Interface");
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070010576 enum send_frame_protection protected;
10577 const char *pmf;
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010578
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030010579 if (!intf)
10580 return -1;
10581
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010582 val = get_param(cmd, "framename");
10583 if (!val)
10584 return -1;
10585 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
10586
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070010587 pmf = get_param(cmd, "PMFProtected");
10588 if (!pmf)
10589 pmf = get_param(cmd, "Protected");
10590 if (pmf) {
10591 if (strcasecmp(pmf, "Correct-key") == 0 ||
10592 strcasecmp(pmf, "CorrectKey") == 0) {
10593 protected = CORRECT_KEY;
10594 } else if (strcasecmp(pmf, "IncorrectKey") == 0) {
10595 protected = INCORRECT_KEY;
10596 } else if (strcasecmp(pmf, "Unprotected") == 0) {
10597 protected = UNPROTECTED;
10598 } else {
10599 send_resp(dut, conn, SIGMA_ERROR,
10600 "errorCode,Unsupported PMFProtected");
10601 return STATUS_SENT_ERROR;
10602 }
10603 sigma_dut_print(dut, DUT_MSG_DEBUG, "Config PMF protection %d",
10604 protected);
10605 wcn_sta_set_pmf_config(dut, intf, protected);
10606 }
10607
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010608 /* Command sequence to generate Op mode notification */
10609 if (val && strcasecmp(val, "action") == 0) {
10610 val = get_param(cmd, "PPDUTxType");
10611 if (val && strcasecmp(val, "TB") == 0) {
10612 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 1)) {
10613 sigma_dut_print(dut, DUT_MSG_ERROR,
10614 "failed to send TB PPDU Tx cfg");
10615 send_resp(dut, conn, SIGMA_ERROR,
10616 "ErrorCode,set TB PPDU Tx cfg failed");
10617 return 0;
10618 }
10619 return 1;
10620 }
10621
10622 sigma_dut_print(dut, DUT_MSG_ERROR,
10623 "Action Tx type is not defined");
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070010624
10625 return SUCCESS_SEND_STATUS;
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010626 }
10627
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070010628 if (strcasecmp(val, "disassoc") == 0)
10629 wcn_sta_send_disassoc(dut, intf);
10630
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010631 return 1;
10632}
10633
10634
10635static int cmd_sta_send_frame_he(struct sigma_dut *dut,
10636 struct sigma_conn *conn,
10637 struct sigma_cmd *cmd)
10638{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010639 switch (get_driver_type(dut)) {
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010640 case DRIVER_WCN:
10641 return wcn_sta_send_frame_he(dut, conn, cmd);
10642 default:
10643 send_resp(dut, conn, SIGMA_ERROR,
10644 "errorCode,Unsupported sta_set_frame(HE) with the current driver");
10645 return 0;
10646 }
10647}
10648
10649
Lior David0fe101e2017-03-09 16:09:50 +020010650#ifdef __linux__
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010651
10652static int
10653wil6210_send_p2p_frame_60g(struct sigma_dut *dut, struct sigma_cmd *cmd,
10654 const char *frame_name, const char *dest_mac)
10655{
10656 int isprobereq = strcasecmp(frame_name, "probereq") == 0;
10657 const char *ssid = get_param(cmd, "ssid");
10658 const char *countstr = get_param(cmd, "count");
10659 const char *channelstr = get_param(cmd, "channel");
10660 const char *group_id = get_param(cmd, "groupid");
10661 const char *client_id = get_param(cmd, "clientmac");
10662 int count, channel, freq, i;
10663 const char *fname;
10664 char frame[1024], src_mac[20], group_id_attr[25],
10665 device_macstr[3 * ETH_ALEN], client_mac[ETH_ALEN];
10666 const char *group_ssid;
10667 const int group_ssid_prefix_len = 9;
10668 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *) frame;
10669 size_t framelen = sizeof(frame);
10670 struct template_frame_tag tags[2];
10671 size_t tags_total = ARRAY_SIZE(tags);
10672 int tag_index, len, dst_len;
10673
10674 if (!countstr || !channelstr) {
10675 sigma_dut_print(dut, DUT_MSG_ERROR,
10676 "Missing argument: count, channel");
10677 return -1;
10678 }
10679 if (isprobereq && !ssid) {
10680 sigma_dut_print(dut, DUT_MSG_ERROR,
10681 "Missing argument: ssid");
10682 return -1;
10683 }
10684 if (!isprobereq && (!group_id || !client_id)) {
10685 sigma_dut_print(dut, DUT_MSG_ERROR,
10686 "Missing argument: group_id, client_id");
10687 return -1;
10688 }
10689
10690 count = atoi(countstr);
10691 channel = atoi(channelstr);
10692 freq = channel_to_freq(dut, channel);
10693
10694 if (!freq) {
10695 sigma_dut_print(dut, DUT_MSG_ERROR,
10696 "invalid channel: %s", channelstr);
10697 return -1;
10698 }
10699
10700 if (isprobereq) {
10701 if (strcasecmp(ssid, "wildcard") == 0) {
10702 fname = "probe_req_wildcard.txt";
10703 } else if (strcasecmp(ssid, "P2P_Wildcard") == 0) {
10704 fname = "probe_req_P2P_Wildcard.txt";
10705 } else {
10706 sigma_dut_print(dut, DUT_MSG_ERROR,
10707 "invalid probe request type");
10708 return -1;
10709 }
10710 } else {
10711 fname = "P2P_device_discovery_req.txt";
10712 }
10713
10714 if (parse_template_frame_file(dut, fname, frame, &framelen,
10715 tags, &tags_total)) {
10716 sigma_dut_print(dut, DUT_MSG_ERROR,
10717 "invalid frame template: %s", fname);
10718 return -1;
10719 }
10720
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010721 if (get_wpa_status(get_station_ifname(dut), "address",
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010722 src_mac, sizeof(src_mac)) < 0 ||
10723 parse_mac_address(dut, src_mac, &hdr->addr2[0]) ||
10724 parse_mac_address(dut, dest_mac, &hdr->addr1[0]))
10725 return -1;
10726 /* Use wildcard BSSID, since we are in PBSS */
10727 memset(&hdr->addr3, 0xFF, ETH_ALEN);
10728
10729 if (!isprobereq) {
10730 tag_index = find_template_frame_tag(tags, tags_total, 1);
10731 if (tag_index < 0) {
10732 sigma_dut_print(dut, DUT_MSG_ERROR,
10733 "can't find device id attribute");
10734 return -1;
10735 }
10736 if (parse_mac_address(dut, client_id,
10737 (unsigned char *) client_mac)) {
10738 sigma_dut_print(dut, DUT_MSG_ERROR,
10739 "invalid client_id: %s", client_id);
10740 return -1;
10741 }
10742 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
10743 framelen - tags[tag_index].offset,
10744 IEEE80211_P2P_ATTR_DEVICE_ID,
10745 client_mac, ETH_ALEN)) {
10746 sigma_dut_print(dut, DUT_MSG_ERROR,
10747 "fail to replace device id attribute");
10748 return -1;
10749 }
10750
10751 /*
10752 * group_id arg contains device MAC address followed by
10753 * space and SSID (DIRECT-somessid).
10754 * group id attribute contains device address (6 bytes)
10755 * followed by SSID prefix DIRECT-XX (9 bytes)
10756 */
10757 if (strlen(group_id) < sizeof(device_macstr)) {
10758 sigma_dut_print(dut, DUT_MSG_ERROR,
10759 "group_id arg too short");
10760 return -1;
10761 }
10762 memcpy(device_macstr, group_id, sizeof(device_macstr));
10763 device_macstr[sizeof(device_macstr) - 1] = '\0';
10764 if (parse_mac_address(dut, device_macstr,
10765 (unsigned char *) group_id_attr)) {
10766 sigma_dut_print(dut, DUT_MSG_ERROR,
10767 "fail to parse device address from group_id");
10768 return -1;
10769 }
10770 group_ssid = strchr(group_id, ' ');
10771 if (!group_ssid) {
10772 sigma_dut_print(dut, DUT_MSG_ERROR,
10773 "invalid group_id arg, no ssid");
10774 return -1;
10775 }
10776 group_ssid++;
10777 len = strlen(group_ssid);
10778 if (len < group_ssid_prefix_len) {
10779 sigma_dut_print(dut, DUT_MSG_ERROR,
10780 "group_id SSID too short");
10781 return -1;
10782 }
10783 dst_len = sizeof(group_id_attr) - ETH_ALEN;
10784 if (len > dst_len) {
10785 sigma_dut_print(dut, DUT_MSG_ERROR,
10786 "group_id SSID (%s) too long",
10787 group_ssid);
10788 return -1;
10789 }
10790
10791 memcpy(group_id_attr + ETH_ALEN, group_ssid, len);
10792 tag_index = find_template_frame_tag(tags, tags_total, 2);
10793 if (tag_index < 0) {
10794 sigma_dut_print(dut, DUT_MSG_ERROR,
10795 "can't find group id attribute");
10796 return -1;
10797 }
10798 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
10799 framelen - tags[tag_index].offset,
10800 IEEE80211_P2P_ATTR_GROUP_ID,
10801 group_id_attr,
10802 sizeof(group_id_attr))) {
10803 sigma_dut_print(dut, DUT_MSG_ERROR,
10804 "fail to replace group id attribute");
10805 return -1;
10806 }
10807 }
10808
10809 for (i = 0; i < count; i++) {
10810 if (wil6210_transmit_frame(dut, freq,
10811 WIL_TRANSMIT_FRAME_DEFAULT_ROC,
10812 frame, framelen)) {
10813 sigma_dut_print(dut, DUT_MSG_ERROR,
10814 "fail to transmit probe request frame");
10815 return -1;
10816 }
10817 }
10818
10819 return 0;
10820}
10821
10822
Lior David0fe101e2017-03-09 16:09:50 +020010823int wil6210_send_frame_60g(struct sigma_dut *dut, struct sigma_conn *conn,
10824 struct sigma_cmd *cmd)
10825{
10826 const char *frame_name = get_param(cmd, "framename");
10827 const char *mac = get_param(cmd, "dest_mac");
10828
10829 if (!frame_name || !mac) {
10830 sigma_dut_print(dut, DUT_MSG_ERROR,
10831 "framename and dest_mac must be provided");
10832 return -1;
10833 }
10834
10835 if (strcasecmp(frame_name, "brp") == 0) {
10836 const char *l_rx = get_param(cmd, "L-RX");
10837 int l_rx_i;
10838
10839 if (!l_rx) {
10840 sigma_dut_print(dut, DUT_MSG_ERROR,
10841 "L-RX must be provided");
10842 return -1;
10843 }
10844 l_rx_i = atoi(l_rx);
10845
10846 sigma_dut_print(dut, DUT_MSG_INFO,
10847 "dev_send_frame: BRP-RX, dest_mac %s, L-RX %s",
10848 mac, l_rx);
10849 if (l_rx_i != 16) {
10850 sigma_dut_print(dut, DUT_MSG_ERROR,
10851 "unsupported L-RX: %s", l_rx);
10852 return -1;
10853 }
10854
10855 if (wil6210_send_brp_rx(dut, mac, l_rx_i))
10856 return -1;
10857 } else if (strcasecmp(frame_name, "ssw") == 0) {
10858 sigma_dut_print(dut, DUT_MSG_INFO,
10859 "dev_send_frame: SLS, dest_mac %s", mac);
10860 if (wil6210_send_sls(dut, mac))
10861 return -1;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010862 } else if ((strcasecmp(frame_name, "probereq") == 0) ||
10863 (strcasecmp(frame_name, "devdiscreq") == 0)) {
10864 sigma_dut_print(dut, DUT_MSG_INFO,
10865 "dev_send_frame: %s, dest_mac %s", frame_name,
10866 mac);
10867 if (wil6210_send_p2p_frame_60g(dut, cmd, frame_name, mac))
10868 return -1;
Lior David0fe101e2017-03-09 16:09:50 +020010869 } else {
10870 sigma_dut_print(dut, DUT_MSG_ERROR,
10871 "unsupported frame type: %s", frame_name);
10872 return -1;
10873 }
10874
10875 return 1;
10876}
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010877
Lior David0fe101e2017-03-09 16:09:50 +020010878#endif /* __linux__ */
10879
10880
10881static int cmd_sta_send_frame_60g(struct sigma_dut *dut,
10882 struct sigma_conn *conn,
10883 struct sigma_cmd *cmd)
10884{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010885 switch (get_driver_type(dut)) {
Lior David0fe101e2017-03-09 16:09:50 +020010886#ifdef __linux__
10887 case DRIVER_WIL6210:
10888 return wil6210_send_frame_60g(dut, conn, cmd);
10889#endif /* __linux__ */
10890 default:
10891 send_resp(dut, conn, SIGMA_ERROR,
10892 "errorCode,Unsupported sta_set_frame(60G) with the current driver");
10893 return 0;
10894 }
10895}
10896
10897
Ashwini Patildb59b3c2017-04-13 15:19:23 +053010898static int mbo_send_anqp_query(struct sigma_dut *dut, struct sigma_conn *conn,
10899 const char *intf, struct sigma_cmd *cmd)
10900{
10901 const char *val, *addr;
10902 char buf[100];
10903
10904 addr = get_param(cmd, "DestMac");
10905 if (!addr) {
10906 send_resp(dut, conn, SIGMA_INVALID,
10907 "ErrorCode,AP MAC address is missing");
10908 return 0;
10909 }
10910
10911 val = get_param(cmd, "ANQPQuery_ID");
10912 if (!val) {
10913 send_resp(dut, conn, SIGMA_INVALID,
10914 "ErrorCode,Missing ANQPQuery_ID");
10915 return 0;
10916 }
10917
10918 if (strcasecmp(val, "NeighborReportReq") == 0) {
10919 snprintf(buf, sizeof(buf), "ANQP_GET %s 272", addr);
10920 } else if (strcasecmp(val, "QueryListWithCellPref") == 0) {
10921 snprintf(buf, sizeof(buf), "ANQP_GET %s 272,mbo:2", addr);
10922 } else {
10923 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid ANQPQuery_ID: %s",
10924 val);
10925 send_resp(dut, conn, SIGMA_INVALID,
10926 "ErrorCode,Invalid ANQPQuery_ID");
10927 return 0;
10928 }
10929
Ashwini Patild174f2c2017-04-13 16:49:46 +053010930 /* Set gas_address3 field to IEEE 802.11-2012 standard compliant form
10931 * (Address3 = Wildcard BSSID when sent to not-associated AP;
10932 * if associated, AP BSSID).
10933 */
10934 if (wpa_command(intf, "SET gas_address3 1") < 0) {
10935 send_resp(dut, conn, SIGMA_ERROR,
10936 "ErrorCode,Failed to set gas_address3");
10937 return 0;
10938 }
10939
Ashwini Patildb59b3c2017-04-13 15:19:23 +053010940 if (wpa_command(intf, buf) < 0) {
10941 send_resp(dut, conn, SIGMA_ERROR,
10942 "ErrorCode,Failed to send ANQP query");
10943 return 0;
10944 }
10945
10946 return 1;
10947}
10948
10949
10950static int mbo_cmd_sta_send_frame(struct sigma_dut *dut,
10951 struct sigma_conn *conn,
10952 const char *intf,
10953 struct sigma_cmd *cmd)
10954{
10955 const char *val = get_param(cmd, "FrameName");
10956
10957 if (val && strcasecmp(val, "ANQPQuery") == 0)
10958 return mbo_send_anqp_query(dut, conn, intf, cmd);
10959
10960 return 2;
10961}
10962
10963
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053010964static enum sigma_cmd_result cmd_sta_send_frame_wpa3(struct sigma_dut *dut,
10965 struct sigma_conn *conn,
10966 const char *intf,
10967 struct sigma_cmd *cmd)
10968{
10969 const char *val = get_param(cmd, "framename");
10970
10971 if (!val)
10972 return INVALID_SEND_STATUS;
10973
10974 if (strcasecmp(val, "SAQueryReq") == 0) {
10975 val = get_param(cmd, "OCIChannel");
10976
10977 if (!val) {
10978 send_resp(dut, conn, SIGMA_ERROR,
10979 "errorCode,OCIChannel not present");
10980 return STATUS_SENT_ERROR;
10981 }
10982
10983 dut->saquery_oci_freq = channel_to_freq(dut, atoi(val));
10984 if (!dut->saquery_oci_freq) {
10985 send_resp(dut, conn, SIGMA_ERROR,
10986 "errorCode,Invalid OCIChannel number");
10987 return STATUS_SENT_ERROR;
10988 }
10989
10990 return sta_inject_frame(dut, conn, intf, SAQUERY, CORRECT_KEY,
10991 NULL, 0);
10992 }
10993
10994 if (strcasecmp(val, "reassocreq") == 0)
10995 return sta_inject_frame(dut, conn, intf, REASSOCREQ,
10996 CORRECT_KEY, NULL, 0);
10997
Veerendranath9f81dfb2020-08-10 01:21:29 -070010998 if (strcasecmp(val, "ANQPQuery") == 0) {
10999 char buf[50];
11000 const char *dest = get_param(cmd, "DestMac");
11001 const char *chan = get_param(cmd, "channel");
11002 int len, freq;
11003
11004 freq = chan ? channel_to_freq(dut, atoi(chan)) : 0;
11005 if (!dest || !freq)
11006 return INVALID_SEND_STATUS;
11007
11008 len = snprintf(buf, sizeof(buf), "ANQP_GET %s freq=%d 257",
11009 dest, freq);
11010 if (len < 0 || len >= sizeof(buf)) {
11011 sigma_dut_print(dut, DUT_MSG_ERROR,
11012 "Failed to allocate buf");
11013 return ERROR_SEND_STATUS;
11014 }
11015
11016 if (wpa_command(intf, buf) != 0) {
11017 send_resp(dut, conn, SIGMA_ERROR,
11018 "ErrorCode,Failed to send ANQP Query frame");
11019 return STATUS_SENT_ERROR;
11020 }
11021
11022 sigma_dut_print(dut, DUT_MSG_DEBUG,
11023 "ANQP Query sent: %s", buf);
11024
11025 return SUCCESS_SEND_STATUS;
11026 }
11027
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053011028 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported framename");
11029 return STATUS_SENT_ERROR;
11030}
11031
11032
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053011033static enum sigma_cmd_result
11034cmd_sta_send_frame_mscs(struct sigma_dut *dut, struct sigma_conn *conn,
11035 const char *intf, struct sigma_cmd *cmd)
11036{
11037 char buf[128], *pos;
11038 const char *val, *classifier_type = "04", *type;
11039 int len, rem_len;
11040 u8 up_bitmap;
11041
11042 val = get_param(cmd, "FrameName");
11043 type = get_param(cmd, "Request_Type");
11044 if (!val || !type || strcasecmp(val, "MSCSReq") != 0) {
11045 sigma_dut_print(dut, DUT_MSG_ERROR,
11046 "%s: frame name or type not valid", __func__);
11047 return INVALID_SEND_STATUS;
11048 }
11049
11050 rem_len = sizeof(buf);
11051 pos = buf;
11052 if (strcasecmp(type, "add") == 0) {
11053 len = snprintf(pos, rem_len, "MSCS add");
11054 } else if (strcasecmp(type, "update") == 0) {
11055 len = snprintf(pos, rem_len, "MSCS change");
11056 } else if (strcasecmp(type, "remove") == 0) {
11057 if (wpa_command(intf, "MSCS remove") != 0) {
11058 send_resp(dut, conn, SIGMA_ERROR,
11059 "ErrorCode,Failed to send MSCS frame req");
11060 return STATUS_SENT_ERROR;
11061 }
11062 return SUCCESS_SEND_STATUS;
11063 } else {
11064 sigma_dut_print(dut, DUT_MSG_ERROR,
11065 "%s: request type invalid", __func__);
11066 return INVALID_SEND_STATUS;
11067 }
11068
11069 if (len < 0 || len >= rem_len)
11070 goto fail;
11071
11072 pos += len;
11073 rem_len -= len;
11074
11075 val = get_param(cmd, "User_Priority_Bitmap");
11076 if (!val) {
11077 sigma_dut_print(dut, DUT_MSG_ERROR,
11078 "%s: user priority bitmap empty", __func__);
11079 return INVALID_SEND_STATUS;
11080 }
11081
11082 switch (atoi(val)) {
11083 case 0:
11084 up_bitmap = 0x00;
11085 break;
11086 case 1:
11087 up_bitmap = 0xF0;
11088 break;
11089 case 2:
11090 up_bitmap = 0xF6;
11091 break;
11092 default:
11093 sigma_dut_print(dut, DUT_MSG_ERROR,
11094 "%s: Unknown User_Priority_Bitmap value %d",
11095 __func__, atoi(val));
11096 return INVALID_SEND_STATUS;
11097 }
11098
11099 len = snprintf(pos, rem_len, " up_bitmap=%02x", up_bitmap);
11100 if (len < 0 || len >= rem_len)
11101 goto fail;
11102
11103 pos += len;
11104 rem_len -= len;
11105
11106 val = get_param(cmd, "User_Priority_Limit");
11107 if (!val) {
11108 sigma_dut_print(dut, DUT_MSG_ERROR,
11109 "%s: invalid user priority limit", __func__);
11110 return INVALID_SEND_STATUS;
11111 }
11112
11113 len = snprintf(pos, rem_len, " up_limit=%s", val);
11114 if (len < 0 || len >= rem_len)
11115 goto fail;
11116
11117 pos += len;
11118 rem_len -= len;
11119
11120 val = get_param(cmd, "Stream_Timeout");
11121 if (!val)
11122 val = get_param(cmd, "Stream_Timtout");
11123 if (!val) {
11124 sigma_dut_print(dut, DUT_MSG_ERROR,
11125 "%s: invalid stream timeout", __func__);
11126 return INVALID_SEND_STATUS;
11127 }
11128
11129 len = snprintf(pos, rem_len, " stream_timeout=%s", val);
11130 if (len < 0 || len >= rem_len)
11131 goto fail;
11132
11133 pos += len;
11134 rem_len -= len;
11135
11136 val = get_param(cmd, "TCLAS_Mask");
11137 if (!val) {
11138 sigma_dut_print(dut, DUT_MSG_ERROR,
11139 "%s: invalid tclas mask", __func__);
11140 return INVALID_SEND_STATUS;
11141 }
11142
11143 len = snprintf(pos, rem_len, " frame_classifier=%s%lx%032x",
11144 classifier_type, strtol(val, NULL, 2), 0);
11145 if (len < 0 || len >= rem_len)
11146 goto fail;
11147
11148 if (wpa_command(intf, buf) != 0) {
11149 send_resp(dut, conn, SIGMA_ERROR,
11150 "ErrorCode,Failed to send MSCS frame req");
11151 return STATUS_SENT_ERROR;
11152 }
11153
11154 sigma_dut_print(dut, DUT_MSG_DEBUG,
11155 "MSCS frame request sent: %s", buf);
11156
11157 return SUCCESS_SEND_STATUS;
11158fail:
11159 sigma_dut_print(dut, DUT_MSG_ERROR,
11160 "Failed to create MSCS frame req");
11161 return ERROR_SEND_STATUS;
11162}
11163
11164
Jouni Malinenf7222712019-06-13 01:50:21 +030011165enum sigma_cmd_result cmd_sta_send_frame(struct sigma_dut *dut,
11166 struct sigma_conn *conn,
11167 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011168{
11169 const char *intf = get_param(cmd, "Interface");
11170 const char *val;
11171 enum send_frame_type frame;
11172 enum send_frame_protection protected;
11173 char buf[100];
11174 unsigned char addr[ETH_ALEN];
11175 int res;
11176
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030011177 if (!intf)
11178 return -1;
11179
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011180 val = get_param(cmd, "program");
11181 if (val == NULL)
11182 val = get_param(cmd, "frame");
11183 if (val && strcasecmp(val, "TDLS") == 0)
11184 return cmd_sta_send_frame_tdls(dut, conn, cmd);
11185 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030011186 strcasecmp(val, "HS2-R2") == 0 ||
11187 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011188 return cmd_sta_send_frame_hs2(dut, conn, cmd);
11189 if (val && strcasecmp(val, "VHT") == 0)
11190 return cmd_sta_send_frame_vht(dut, conn, cmd);
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011191 if (val && strcasecmp(val, "HE") == 0)
11192 return cmd_sta_send_frame_he(dut, conn, cmd);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -070011193 if (val && strcasecmp(val, "LOC") == 0)
11194 return loc_cmd_sta_send_frame(dut, conn, cmd);
Lior David0fe101e2017-03-09 16:09:50 +020011195 if (val && strcasecmp(val, "60GHz") == 0)
11196 return cmd_sta_send_frame_60g(dut, conn, cmd);
Ashwini Patildb59b3c2017-04-13 15:19:23 +053011197 if (val && strcasecmp(val, "MBO") == 0) {
11198 res = mbo_cmd_sta_send_frame(dut, conn, intf, cmd);
11199 if (res != 2)
11200 return res;
11201 }
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053011202 if (val && strcasecmp(val, "WPA3") == 0)
11203 return cmd_sta_send_frame_wpa3(dut, conn, intf, cmd);
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053011204 if (val && strcasecmp(val, "QM") == 0)
11205 return cmd_sta_send_frame_mscs(dut, conn, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011206
11207 val = get_param(cmd, "TD_DISC");
11208 if (val) {
11209 if (hwaddr_aton(val, addr) < 0)
11210 return -1;
11211 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", val);
11212 if (wpa_command(intf, buf) < 0) {
11213 send_resp(dut, conn, SIGMA_ERROR,
11214 "ErrorCode,Failed to send TDLS discovery");
11215 return 0;
11216 }
11217 return 1;
11218 }
11219
11220 val = get_param(cmd, "TD_Setup");
11221 if (val) {
11222 if (hwaddr_aton(val, addr) < 0)
11223 return -1;
11224 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", val);
11225 if (wpa_command(intf, buf) < 0) {
11226 send_resp(dut, conn, SIGMA_ERROR,
11227 "ErrorCode,Failed to start TDLS setup");
11228 return 0;
11229 }
11230 return 1;
11231 }
11232
11233 val = get_param(cmd, "TD_TearDown");
11234 if (val) {
11235 if (hwaddr_aton(val, addr) < 0)
11236 return -1;
11237 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", val);
11238 if (wpa_command(intf, buf) < 0) {
11239 send_resp(dut, conn, SIGMA_ERROR,
11240 "ErrorCode,Failed to tear down TDLS link");
11241 return 0;
11242 }
11243 return 1;
11244 }
11245
11246 val = get_param(cmd, "TD_ChannelSwitch");
11247 if (val) {
11248 /* TODO */
11249 send_resp(dut, conn, SIGMA_ERROR,
11250 "ErrorCode,TD_ChannelSwitch not yet supported");
11251 return 0;
11252 }
11253
11254 val = get_param(cmd, "TD_NF");
11255 if (val) {
11256 /* TODO */
11257 send_resp(dut, conn, SIGMA_ERROR,
11258 "ErrorCode,TD_NF not yet supported");
11259 return 0;
11260 }
11261
11262 val = get_param(cmd, "PMFFrameType");
11263 if (val == NULL)
11264 val = get_param(cmd, "FrameName");
11265 if (val == NULL)
11266 val = get_param(cmd, "Type");
11267 if (val == NULL)
11268 return -1;
11269 if (strcasecmp(val, "disassoc") == 0)
11270 frame = DISASSOC;
11271 else if (strcasecmp(val, "deauth") == 0)
11272 frame = DEAUTH;
11273 else if (strcasecmp(val, "saquery") == 0)
11274 frame = SAQUERY;
11275 else if (strcasecmp(val, "auth") == 0)
11276 frame = AUTH;
11277 else if (strcasecmp(val, "assocreq") == 0)
11278 frame = ASSOCREQ;
11279 else if (strcasecmp(val, "reassocreq") == 0)
11280 frame = REASSOCREQ;
11281 else if (strcasecmp(val, "neigreq") == 0) {
11282 sigma_dut_print(dut, DUT_MSG_INFO, "Got neighbor request");
11283
11284 val = get_param(cmd, "ssid");
11285 if (val == NULL)
11286 return -1;
11287
11288 res = send_neighbor_request(dut, intf, val);
11289 if (res) {
11290 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
11291 "Failed to send neighbor report request");
11292 return 0;
11293 }
11294
11295 return 1;
Ashwini Patil5acd7382017-04-13 15:55:04 +053011296 } else if (strcasecmp(val, "transmgmtquery") == 0 ||
11297 strcasecmp(val, "BTMQuery") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011298 sigma_dut_print(dut, DUT_MSG_DEBUG,
11299 "Got Transition Management Query");
11300
Ashwini Patil5acd7382017-04-13 15:55:04 +053011301 res = send_trans_mgmt_query(dut, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011302 if (res) {
11303 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
11304 "Failed to send Transition Management Query");
11305 return 0;
11306 }
11307
11308 return 1;
11309 } else {
11310 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
11311 "PMFFrameType");
11312 return 0;
11313 }
11314
11315 val = get_param(cmd, "PMFProtected");
11316 if (val == NULL)
11317 val = get_param(cmd, "Protected");
11318 if (val == NULL)
11319 return -1;
11320 if (strcasecmp(val, "Correct-key") == 0 ||
11321 strcasecmp(val, "CorrectKey") == 0)
11322 protected = CORRECT_KEY;
11323 else if (strcasecmp(val, "IncorrectKey") == 0)
11324 protected = INCORRECT_KEY;
11325 else if (strcasecmp(val, "Unprotected") == 0)
11326 protected = UNPROTECTED;
11327 else {
11328 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
11329 "PMFProtected");
11330 return 0;
11331 }
11332
11333 if (protected != UNPROTECTED &&
11334 (frame == AUTH || frame == ASSOCREQ || frame == REASSOCREQ)) {
11335 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Impossible "
11336 "PMFProtected for auth/assocreq/reassocreq");
11337 return 0;
11338 }
11339
11340 if (if_nametoindex("sigmadut") == 0) {
11341 snprintf(buf, sizeof(buf),
11342 "iw dev %s interface add sigmadut type monitor",
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011343 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011344 if (system(buf) != 0 ||
11345 if_nametoindex("sigmadut") == 0) {
11346 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
11347 "monitor interface with '%s'", buf);
11348 return -2;
11349 }
11350 }
11351
11352 if (system("ifconfig sigmadut up") != 0) {
11353 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
11354 "monitor interface up");
11355 return -2;
11356 }
11357
Veerendranath Jakkam49774122020-07-05 09:52:18 +053011358 return sta_inject_frame(dut, conn, intf, frame, protected, NULL, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011359}
11360
11361
11362static int cmd_sta_set_parameter_hs2(struct sigma_dut *dut,
11363 struct sigma_conn *conn,
11364 struct sigma_cmd *cmd,
11365 const char *ifname)
11366{
11367 char buf[200];
11368 const char *val;
11369
11370 val = get_param(cmd, "ClearARP");
11371 if (val && atoi(val) == 1) {
11372 snprintf(buf, sizeof(buf), "ip neigh flush dev %s", ifname);
11373 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11374 if (system(buf) != 0) {
11375 send_resp(dut, conn, SIGMA_ERROR,
11376 "errorCode,Failed to clear ARP cache");
11377 return 0;
11378 }
11379 }
11380
11381 return 1;
11382}
11383
11384
11385int cmd_sta_set_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
11386 struct sigma_cmd *cmd)
11387{
11388 const char *intf = get_param(cmd, "Interface");
11389 const char *val;
11390
11391 if (intf == NULL)
11392 return -1;
11393
11394 val = get_param(cmd, "program");
11395 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030011396 strcasecmp(val, "HS2-R2") == 0 ||
11397 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011398 return cmd_sta_set_parameter_hs2(dut, conn, cmd, intf);
11399
11400 return -1;
11401}
11402
11403
Jouni Malinenf7222712019-06-13 01:50:21 +030011404static enum sigma_cmd_result cmd_sta_set_macaddr(struct sigma_dut *dut,
11405 struct sigma_conn *conn,
11406 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011407{
11408 const char *intf = get_param(cmd, "Interface");
11409 const char *mac = get_param(cmd, "MAC");
11410
11411 if (intf == NULL || mac == NULL)
11412 return -1;
11413
11414 sigma_dut_print(dut, DUT_MSG_INFO, "Change local MAC address for "
11415 "interface %s to %s", intf, mac);
11416
11417 if (dut->set_macaddr) {
11418 char buf[128];
11419 int res;
11420 if (strcasecmp(mac, "default") == 0) {
11421 res = snprintf(buf, sizeof(buf), "%s",
11422 dut->set_macaddr);
11423 dut->tmp_mac_addr = 0;
11424 } else {
11425 res = snprintf(buf, sizeof(buf), "%s %s",
11426 dut->set_macaddr, mac);
11427 dut->tmp_mac_addr = 1;
11428 }
11429 if (res < 0 || res >= (int) sizeof(buf))
11430 return -1;
11431 if (system(buf) != 0) {
11432 send_resp(dut, conn, SIGMA_ERROR,
11433 "errorCode,Failed to set MAC "
11434 "address");
11435 return 0;
11436 }
11437 return 1;
11438 }
11439
11440 if (strcasecmp(mac, "default") == 0)
11441 return 1;
11442
11443 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
11444 "command");
11445 return 0;
11446}
11447
11448
11449static int iwpriv_tdlsoffchnmode(struct sigma_dut *dut,
11450 struct sigma_conn *conn, const char *intf,
11451 int val)
11452{
11453 char buf[200];
11454 int res;
11455
11456 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchnmode %d",
11457 intf, val);
11458 if (res < 0 || res >= (int) sizeof(buf))
11459 return -1;
11460 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11461 if (system(buf) != 0) {
11462 send_resp(dut, conn, SIGMA_ERROR,
11463 "errorCode,Failed to configure offchannel mode");
11464 return 0;
11465 }
11466
11467 return 1;
11468}
11469
11470
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011471static int off_chan_val(enum sec_ch_offset off)
11472{
11473 switch (off) {
11474 case SEC_CH_NO:
11475 return 0;
11476 case SEC_CH_40ABOVE:
11477 return 40;
11478 case SEC_CH_40BELOW:
11479 return -40;
11480 }
11481
11482 return 0;
11483}
11484
11485
11486static int iwpriv_set_offchan(struct sigma_dut *dut, struct sigma_conn *conn,
11487 const char *intf, int off_ch_num,
11488 enum sec_ch_offset sec)
11489{
11490 char buf[200];
11491 int res;
11492
11493 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchan %d",
11494 intf, off_ch_num);
11495 if (res < 0 || res >= (int) sizeof(buf))
11496 return -1;
11497 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11498 if (system(buf) != 0) {
11499 send_resp(dut, conn, SIGMA_ERROR,
11500 "errorCode,Failed to set offchan");
11501 return 0;
11502 }
11503
11504 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsecchnoffst %d",
11505 intf, off_chan_val(sec));
11506 if (res < 0 || res >= (int) sizeof(buf))
11507 return -1;
11508 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11509 if (system(buf) != 0) {
11510 send_resp(dut, conn, SIGMA_ERROR,
11511 "errorCode,Failed to set sec chan offset");
11512 return 0;
11513 }
11514
11515 return 1;
11516}
11517
11518
11519static int tdls_set_offchannel_offset(struct sigma_dut *dut,
11520 struct sigma_conn *conn,
11521 const char *intf, int off_ch_num,
11522 enum sec_ch_offset sec)
11523{
11524 char buf[200];
11525 int res;
11526
11527 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNEL %d",
11528 off_ch_num);
11529 if (res < 0 || res >= (int) sizeof(buf))
11530 return -1;
11531 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11532
11533 if (wpa_command(intf, buf) < 0) {
11534 send_resp(dut, conn, SIGMA_ERROR,
11535 "ErrorCode,Failed to set offchan");
11536 return 0;
11537 }
11538 res = snprintf(buf, sizeof(buf), "DRIVER TDLSSECONDARYCHANNELOFFSET %d",
11539 off_chan_val(sec));
11540 if (res < 0 || res >= (int) sizeof(buf))
11541 return -1;
11542
11543 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11544
11545 if (wpa_command(intf, buf) < 0) {
11546 send_resp(dut, conn, SIGMA_ERROR,
11547 "ErrorCode,Failed to set sec chan offset");
11548 return 0;
11549 }
11550
11551 return 1;
11552}
11553
11554
11555static int tdls_set_offchannel_mode(struct sigma_dut *dut,
11556 struct sigma_conn *conn,
11557 const char *intf, int val)
11558{
11559 char buf[200];
11560 int res;
11561
11562 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNELMODE %d",
11563 val);
11564 if (res < 0 || res >= (int) sizeof(buf))
11565 return -1;
11566 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11567
11568 if (wpa_command(intf, buf) < 0) {
11569 send_resp(dut, conn, SIGMA_ERROR,
11570 "ErrorCode,Failed to configure offchannel mode");
11571 return 0;
11572 }
11573
11574 return 1;
11575}
11576
11577
11578static int cmd_sta_set_rfeature_tdls(const char *intf, struct sigma_dut *dut,
11579 struct sigma_conn *conn,
11580 struct sigma_cmd *cmd)
11581{
11582 const char *val;
11583 enum {
11584 CHSM_NOT_SET,
11585 CHSM_ENABLE,
11586 CHSM_DISABLE,
11587 CHSM_REJREQ,
11588 CHSM_UNSOLRESP
11589 } chsm = CHSM_NOT_SET;
11590 int off_ch_num = -1;
11591 enum sec_ch_offset sec_ch = SEC_CH_NO;
11592 int res;
11593
11594 val = get_param(cmd, "Uapsd");
11595 if (val) {
11596 char buf[100];
11597 if (strcasecmp(val, "Enable") == 0)
11598 snprintf(buf, sizeof(buf), "SET ps 99");
11599 else if (strcasecmp(val, "Disable") == 0)
11600 snprintf(buf, sizeof(buf), "SET ps 98");
11601 else {
11602 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
11603 "Unsupported uapsd parameter value");
11604 return 0;
11605 }
11606 if (wpa_command(intf, buf)) {
11607 send_resp(dut, conn, SIGMA_ERROR,
11608 "ErrorCode,Failed to change U-APSD "
11609 "powersave mode");
11610 return 0;
11611 }
11612 }
11613
11614 val = get_param(cmd, "TPKTIMER");
11615 if (val && strcasecmp(val, "DISABLE") == 0) {
11616 if (wpa_command(intf, "SET tdls_testing 0x100")) {
11617 send_resp(dut, conn, SIGMA_ERROR,
11618 "ErrorCode,Failed to enable no TPK "
11619 "expiration test mode");
11620 return 0;
11621 }
11622 dut->no_tpk_expiration = 1;
11623 }
11624
11625 val = get_param(cmd, "ChSwitchMode");
11626 if (val) {
11627 if (strcasecmp(val, "Enable") == 0 ||
11628 strcasecmp(val, "Initiate") == 0)
11629 chsm = CHSM_ENABLE;
11630 else if (strcasecmp(val, "Disable") == 0 ||
11631 strcasecmp(val, "passive") == 0)
11632 chsm = CHSM_DISABLE;
11633 else if (strcasecmp(val, "RejReq") == 0)
11634 chsm = CHSM_REJREQ;
11635 else if (strcasecmp(val, "UnSolResp") == 0)
11636 chsm = CHSM_UNSOLRESP;
11637 else {
11638 send_resp(dut, conn, SIGMA_ERROR,
11639 "ErrorCode,Unknown ChSwitchMode value");
11640 return 0;
11641 }
11642 }
11643
11644 val = get_param(cmd, "OffChNum");
11645 if (val) {
11646 off_ch_num = atoi(val);
11647 if (off_ch_num == 0) {
11648 send_resp(dut, conn, SIGMA_ERROR,
11649 "ErrorCode,Invalid OffChNum");
11650 return 0;
11651 }
11652 }
11653
11654 val = get_param(cmd, "SecChOffset");
11655 if (val) {
11656 if (strcmp(val, "20") == 0)
11657 sec_ch = SEC_CH_NO;
11658 else if (strcasecmp(val, "40above") == 0)
11659 sec_ch = SEC_CH_40ABOVE;
11660 else if (strcasecmp(val, "40below") == 0)
11661 sec_ch = SEC_CH_40BELOW;
11662 else {
11663 send_resp(dut, conn, SIGMA_ERROR,
11664 "ErrorCode,Unknown SecChOffset value");
11665 return 0;
11666 }
11667 }
11668
11669 if (chsm == CHSM_NOT_SET) {
11670 /* no offchannel changes requested */
11671 return 1;
11672 }
11673
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011674 if (strcmp(intf, get_main_ifname(dut)) != 0 &&
11675 strcmp(intf, get_station_ifname(dut)) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011676 send_resp(dut, conn, SIGMA_ERROR,
11677 "ErrorCode,Unknown interface");
11678 return 0;
11679 }
11680
11681 switch (chsm) {
11682 case CHSM_NOT_SET:
Jouni Malinen280f5ba2016-08-29 21:33:10 +030011683 res = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011684 break;
11685 case CHSM_ENABLE:
11686 if (off_ch_num < 0) {
11687 send_resp(dut, conn, SIGMA_ERROR,
11688 "ErrorCode,Missing OffChNum argument");
11689 return 0;
11690 }
11691 if (wifi_chip_type == DRIVER_WCN) {
11692 res = tdls_set_offchannel_offset(dut, conn, intf,
11693 off_ch_num, sec_ch);
11694 } else {
11695 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
11696 sec_ch);
11697 }
11698 if (res != 1)
11699 return res;
11700 if (wifi_chip_type == DRIVER_WCN)
11701 res = tdls_set_offchannel_mode(dut, conn, intf, 1);
11702 else
11703 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 1);
11704 break;
11705 case CHSM_DISABLE:
11706 if (wifi_chip_type == DRIVER_WCN)
11707 res = tdls_set_offchannel_mode(dut, conn, intf, 2);
11708 else
11709 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 2);
11710 break;
11711 case CHSM_REJREQ:
11712 if (wifi_chip_type == DRIVER_WCN)
11713 res = tdls_set_offchannel_mode(dut, conn, intf, 3);
11714 else
11715 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 3);
11716 break;
11717 case CHSM_UNSOLRESP:
11718 if (off_ch_num < 0) {
11719 send_resp(dut, conn, SIGMA_ERROR,
11720 "ErrorCode,Missing OffChNum argument");
11721 return 0;
11722 }
11723 if (wifi_chip_type == DRIVER_WCN) {
11724 res = tdls_set_offchannel_offset(dut, conn, intf,
11725 off_ch_num, sec_ch);
11726 } else {
11727 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
11728 sec_ch);
11729 }
11730 if (res != 1)
11731 return res;
11732 if (wifi_chip_type == DRIVER_WCN)
11733 res = tdls_set_offchannel_mode(dut, conn, intf, 4);
11734 else
11735 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 4);
11736 break;
11737 }
11738
11739 return res;
11740}
11741
11742
11743static int ath_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
11744 struct sigma_conn *conn,
11745 struct sigma_cmd *cmd)
11746{
11747 const char *val;
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053011748 char *token = NULL, *result;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011749
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -070011750 novap_reset(dut, intf, 1);
priyadharshini gowthamane5e25172015-12-08 14:53:48 -080011751
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011752 val = get_param(cmd, "nss_mcs_opt");
11753 if (val) {
11754 /* String (nss_operating_mode; mcs_operating_mode) */
11755 int nss, mcs;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011756 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011757
11758 token = strdup(val);
11759 if (!token)
11760 return 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011761 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053011762 if (!result) {
11763 sigma_dut_print(dut, DUT_MSG_ERROR,
11764 "VHT NSS not specified");
11765 goto failed;
11766 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011767 if (strcasecmp(result, "def") != 0) {
11768 nss = atoi(result);
11769 if (nss == 4)
11770 ath_disable_txbf(dut, intf);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011771 if (run_iwpriv(dut, intf, "nss %d", nss) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011772 goto failed;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011773
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011774 }
11775
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011776 result = strtok_r(NULL, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053011777 if (!result) {
11778 sigma_dut_print(dut, DUT_MSG_ERROR,
11779 "VHT MCS not specified");
11780 goto failed;
11781 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011782 if (strcasecmp(result, "def") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011783 if (run_iwpriv(dut, intf, "set11NRates 0") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011784 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011785 } else {
11786 mcs = atoi(result);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011787 if (run_iwpriv(dut, intf, "vhtmcs %d", mcs) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011788 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011789 }
11790 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011791 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011792 }
11793
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053011794 free(token);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011795 return 1;
11796failed:
11797 free(token);
11798 return 0;
11799}
11800
11801
11802static int cmd_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
11803 struct sigma_conn *conn,
11804 struct sigma_cmd *cmd)
11805{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011806 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011807 case DRIVER_ATHEROS:
11808 return ath_sta_set_rfeature_vht(intf, dut, conn, cmd);
11809 default:
11810 send_resp(dut, conn, SIGMA_ERROR,
11811 "errorCode,Unsupported sta_set_rfeature(VHT) with the current driver");
11812 return 0;
11813 }
11814}
11815
11816
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011817static int wcn_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
11818 struct sigma_conn *conn,
11819 struct sigma_cmd *cmd)
11820{
11821 const char *val;
11822 char *token = NULL, *result;
11823 char buf[60];
11824
11825 val = get_param(cmd, "nss_mcs_opt");
11826 if (val) {
11827 /* String (nss_operating_mode; mcs_operating_mode) */
11828 int nss, mcs, ratecode;
11829 char *saveptr;
11830
11831 token = strdup(val);
11832 if (!token)
11833 return -2;
11834
11835 result = strtok_r(token, ";", &saveptr);
11836 if (!result) {
11837 sigma_dut_print(dut, DUT_MSG_ERROR,
11838 "HE NSS not specified");
11839 goto failed;
11840 }
11841 nss = 1;
11842 if (strcasecmp(result, "def") != 0)
11843 nss = atoi(result);
11844
11845 result = strtok_r(NULL, ";", &saveptr);
11846 if (!result) {
11847 sigma_dut_print(dut, DUT_MSG_ERROR,
11848 "HE MCS not specified");
11849 goto failed;
11850 }
11851 mcs = 7;
11852 if (strcasecmp(result, "def") != 0)
11853 mcs = atoi(result);
11854
Arif Hussain557bf412018-05-25 17:29:36 -070011855 ratecode = 0x20; /* for nss:1 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011856 if (nss == 2) {
Arif Hussain557bf412018-05-25 17:29:36 -070011857 ratecode = 0x40; /* for nss:2 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011858 } else if (nss > 2) {
11859 sigma_dut_print(dut, DUT_MSG_ERROR,
11860 "HE NSS %d not supported", nss);
11861 goto failed;
11862 }
11863
Arif Hussain557bf412018-05-25 17:29:36 -070011864 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss);
11865 if (system(buf) != 0) {
11866 sigma_dut_print(dut, DUT_MSG_ERROR,
11867 "nss_mcs_opt: iwpriv %s nss %d failed",
11868 intf, nss);
11869 goto failed;
11870 }
Arif Hussainac6c5112018-05-25 17:34:00 -070011871 dut->sta_nss = nss;
Arif Hussain557bf412018-05-25 17:29:36 -070011872
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011873 /* Add the MCS to the ratecode */
11874 if (mcs >= 0 && mcs <= 11) {
11875 ratecode += mcs;
Arif Hussain557bf412018-05-25 17:29:36 -070011876#ifdef NL80211_SUPPORT
11877 if (dut->device_type == STA_testbed) {
11878 enum he_mcs_config mcs_config;
11879 int ret;
11880
11881 if (mcs <= 7)
11882 mcs_config = HE_80_MCS0_7;
11883 else if (mcs <= 9)
11884 mcs_config = HE_80_MCS0_9;
11885 else
11886 mcs_config = HE_80_MCS0_11;
11887 ret = sta_set_he_mcs(dut, intf, mcs_config);
11888 if (ret) {
11889 sigma_dut_print(dut, DUT_MSG_ERROR,
11890 "nss_mcs_opt: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
11891 mcs, mcs_config, ret);
11892 goto failed;
11893 }
11894 }
11895#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011896 } else {
11897 sigma_dut_print(dut, DUT_MSG_ERROR,
11898 "HE MCS %d not supported", mcs);
11899 goto failed;
11900 }
11901 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0x%03x",
11902 intf, ratecode);
11903 if (system(buf) != 0) {
11904 sigma_dut_print(dut, DUT_MSG_ERROR,
11905 "iwpriv setting of 11ax rates failed");
11906 goto failed;
11907 }
11908 free(token);
11909 }
11910
11911 val = get_param(cmd, "GI");
11912 if (val) {
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011913 int fix_rate_sgi;
11914
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011915 if (strcmp(val, "0.8") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070011916 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 9", intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011917 fix_rate_sgi = 1;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011918 } else if (strcmp(val, "1.6") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070011919 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 10",
11920 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011921 fix_rate_sgi = 2;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011922 } else if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070011923 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 11",
11924 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011925 fix_rate_sgi = 3;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011926 } else {
11927 send_resp(dut, conn, SIGMA_ERROR,
11928 "errorCode,GI value not supported");
11929 return 0;
11930 }
11931 if (system(buf) != 0) {
11932 send_resp(dut, conn, SIGMA_ERROR,
11933 "errorCode,Failed to set shortgi");
11934 return 0;
11935 }
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011936 snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d",
11937 intf, fix_rate_sgi);
11938 if (system(buf) != 0) {
11939 send_resp(dut, conn, SIGMA_ERROR,
11940 "errorCode,Failed to set fix rate shortgi");
11941 return STATUS_SENT;
11942 }
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011943 }
11944
Subhani Shaik8e7a3052018-04-24 14:03:00 -070011945 val = get_param(cmd, "LTF");
11946 if (val) {
11947#ifdef NL80211_SUPPORT
11948 if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080011949 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_1X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070011950 } if (strcmp(val, "6.4") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080011951 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_2X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070011952 } else if (strcmp(val, "12.8") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080011953 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_4X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070011954 } else {
11955 send_resp(dut, conn, SIGMA_ERROR,
11956 "errorCode, LTF value not supported");
11957 return 0;
11958 }
11959#else /* NL80211_SUPPORT */
11960 sigma_dut_print(dut, DUT_MSG_ERROR,
11961 "LTF cannot be set without NL80211_SUPPORT defined");
11962 return -2;
11963#endif /* NL80211_SUPPORT */
11964 }
11965
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -070011966 val = get_param(cmd, "TxSUPPDU");
11967 if (val) {
11968 int set_val = 1;
11969
11970 if (strcasecmp(val, "Enable") == 0)
11971 set_val = 1;
11972 else if (strcasecmp(val, "Disable") == 0)
11973 set_val = 0;
11974
11975 if (sta_set_tx_su_ppdu_cfg(dut, intf, set_val)) {
11976 send_resp(dut, conn, SIGMA_ERROR,
11977 "ErrorCode,Failed to set Tx SU PPDU config");
11978 return 0;
11979 }
11980 }
11981
Arif Hussain480d5f42019-03-12 14:40:42 -070011982 val = get_param(cmd, "TWT_Setup");
11983 if (val) {
11984 if (strcasecmp(val, "Request") == 0) {
11985 if (sta_twt_request(dut, conn, cmd)) {
11986 send_resp(dut, conn, SIGMA_ERROR,
11987 "ErrorCode,sta_twt_request failed");
11988 return STATUS_SENT;
11989 }
11990 } else if (strcasecmp(val, "Teardown") == 0) {
11991 if (sta_twt_teardown(dut, conn, cmd)) {
11992 send_resp(dut, conn, SIGMA_ERROR,
11993 "ErrorCode,sta_twt_teardown failed");
11994 return STATUS_SENT;
11995 }
11996 }
11997 }
11998
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -080011999 val = get_param(cmd, "transmitOMI");
12000 if (val && sta_transmit_omi(dut, conn, cmd)) {
12001 send_resp(dut, conn, SIGMA_ERROR,
12002 "ErrorCode,sta_transmit_omi failed");
12003 return STATUS_SENT;
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -070012004 }
12005
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080012006 val = get_param(cmd, "Powersave");
12007 if (val) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012008 int ps;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080012009
12010 if (strcasecmp(val, "off") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012011 ps = 2;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080012012 } else if (strcasecmp(val, "on") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012013 ps = 1;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080012014 } else {
12015 sigma_dut_print(dut, DUT_MSG_ERROR,
12016 "Unsupported Powersave value '%s'",
12017 val);
12018 return -1;
12019 }
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012020 if (set_power_save_wcn(dut, intf, ps) < 0)
12021 return 0;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080012022 }
12023
Kiran Kumar Lokere2c4b7ce2019-01-30 12:02:28 -080012024 val = get_param(cmd, "MU_EDCA");
12025 if (val) {
12026 if (strcasecmp(val, "Override") == 0) {
12027 if (sta_set_mu_edca_override(dut, intf, 1)) {
12028 send_resp(dut, conn, SIGMA_ERROR,
12029 "errorCode,MU EDCA override set failed");
12030 return STATUS_SENT;
12031 }
12032 } else if (strcasecmp(val, "Disable") == 0) {
12033 if (sta_set_mu_edca_override(dut, intf, 0)) {
12034 send_resp(dut, conn, SIGMA_ERROR,
12035 "errorCode,MU EDCA override disable failed");
12036 return STATUS_SENT;
12037 }
12038 }
12039 }
12040
Kiran Kumar Lokeredd086642020-06-04 00:29:26 -070012041 val = get_param(cmd, "Ch_Pref");
12042 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
12043 return STATUS_SENT;
12044
12045 val = get_param(cmd, "Cellular_Data_Cap");
12046 if (val && mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
12047 return STATUS_SENT;
12048
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012049 return 1;
12050
12051failed:
12052 free(token);
12053 return -2;
12054}
12055
12056
12057static int cmd_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
12058 struct sigma_conn *conn,
12059 struct sigma_cmd *cmd)
12060{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012061 switch (get_driver_type(dut)) {
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012062 case DRIVER_WCN:
12063 return wcn_sta_set_rfeature_he(intf, dut, conn, cmd);
12064 default:
12065 send_resp(dut, conn, SIGMA_ERROR,
12066 "errorCode,Unsupported sta_set_rfeature(HE) with the current driver");
12067 return 0;
12068 }
12069}
12070
12071
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012072static int cmd_sta_set_power_save_he(const char *intf, struct sigma_dut *dut,
12073 struct sigma_conn *conn,
12074 struct sigma_cmd *cmd)
12075{
12076 const char *val;
12077
12078 val = get_param(cmd, "powersave");
12079 if (val) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012080 int ps;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012081
12082 if (strcasecmp(val, "off") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012083 ps = 2;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012084 } else if (strcasecmp(val, "on") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012085 ps = 1;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012086 } else {
12087 sigma_dut_print(dut, DUT_MSG_ERROR,
12088 "Unsupported power save config");
12089 return -1;
12090 }
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012091 if (set_power_save_wcn(dut, intf, ps) < 0)
12092 return 0;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012093 return 1;
12094 }
12095
12096 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported command");
12097
12098 return 0;
12099}
12100
12101
Ashwini Patil5acd7382017-04-13 15:55:04 +053012102static int btm_query_candidate_list(struct sigma_dut *dut,
12103 struct sigma_conn *conn,
12104 struct sigma_cmd *cmd)
12105{
12106 const char *bssid, *info, *op_class, *ch, *phy_type, *pref;
12107 int len, ret;
12108 char buf[10];
12109
12110 /*
12111 * Neighbor Report elements format:
12112 * neighbor=<BSSID>,<BSSID Information>,<Operating Class>,
12113 * <Channel Number>,<PHY Type>[,<hexdump of Optional Subelements>]
12114 * eg: neighbor=aa:bb:cc:dd:ee:ff,17,81,6,1,030101
12115 */
12116
12117 bssid = get_param(cmd, "Nebor_BSSID");
12118 if (!bssid) {
12119 send_resp(dut, conn, SIGMA_INVALID,
12120 "errorCode,Nebor_BSSID is missing");
12121 return 0;
12122 }
12123
12124 info = get_param(cmd, "Nebor_Bssid_Info");
12125 if (!info) {
12126 sigma_dut_print(dut, DUT_MSG_INFO,
12127 "Using default value for Nebor_Bssid_Info: %s",
12128 DEFAULT_NEIGHBOR_BSSID_INFO);
12129 info = DEFAULT_NEIGHBOR_BSSID_INFO;
12130 }
12131
12132 op_class = get_param(cmd, "Nebor_Op_Class");
12133 if (!op_class) {
12134 send_resp(dut, conn, SIGMA_INVALID,
12135 "errorCode,Nebor_Op_Class is missing");
12136 return 0;
12137 }
12138
12139 ch = get_param(cmd, "Nebor_Op_Ch");
12140 if (!ch) {
12141 send_resp(dut, conn, SIGMA_INVALID,
12142 "errorCode,Nebor_Op_Ch is missing");
12143 return 0;
12144 }
12145
12146 phy_type = get_param(cmd, "Nebor_Phy_Type");
12147 if (!phy_type) {
12148 sigma_dut_print(dut, DUT_MSG_INFO,
12149 "Using default value for Nebor_Phy_Type: %s",
12150 DEFAULT_NEIGHBOR_PHY_TYPE);
12151 phy_type = DEFAULT_NEIGHBOR_PHY_TYPE;
12152 }
12153
12154 /* Parse optional subelements */
12155 buf[0] = '\0';
12156 pref = get_param(cmd, "Nebor_Pref");
12157 if (pref) {
12158 /* hexdump for preferrence subelement */
12159 ret = snprintf(buf, sizeof(buf), ",0301%02x", atoi(pref));
12160 if (ret < 0 || ret >= (int) sizeof(buf)) {
12161 sigma_dut_print(dut, DUT_MSG_ERROR,
12162 "snprintf failed for optional subelement ret: %d",
12163 ret);
12164 send_resp(dut, conn, SIGMA_ERROR,
12165 "errorCode,snprintf failed for subelement");
12166 return 0;
12167 }
12168 }
12169
12170 if (!dut->btm_query_cand_list) {
12171 dut->btm_query_cand_list = calloc(1, NEIGHBOR_REPORT_SIZE);
12172 if (!dut->btm_query_cand_list) {
12173 send_resp(dut, conn, SIGMA_ERROR,
12174 "errorCode,Failed to allocate memory for btm_query_cand_list");
12175 return 0;
12176 }
12177 }
12178
12179 len = strlen(dut->btm_query_cand_list);
12180 ret = snprintf(dut->btm_query_cand_list + len,
12181 NEIGHBOR_REPORT_SIZE - len, " neighbor=%s,%s,%s,%s,%s%s",
12182 bssid, info, op_class, ch, phy_type, buf);
12183 if (ret < 0 || ret >= NEIGHBOR_REPORT_SIZE - len) {
12184 sigma_dut_print(dut, DUT_MSG_ERROR,
12185 "snprintf failed for neighbor report list ret: %d",
12186 ret);
12187 send_resp(dut, conn, SIGMA_ERROR,
12188 "errorCode,snprintf failed for neighbor report");
12189 free(dut->btm_query_cand_list);
12190 dut->btm_query_cand_list = NULL;
12191 return 0;
12192 }
12193
12194 return 1;
12195}
12196
12197
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012198int sta_extract_60g_ese(struct sigma_dut *dut, struct sigma_cmd *cmd,
12199 struct sigma_ese_alloc *allocs, int *allocs_size)
12200{
12201 int max_count = *allocs_size;
12202 int count = 0, i;
12203 const char *val;
12204
12205 do {
12206 val = get_param_indexed(cmd, "AllocID", count);
12207 if (val)
12208 count++;
12209 } while (val);
12210
12211 if (count == 0 || count > max_count) {
12212 sigma_dut_print(dut, DUT_MSG_ERROR,
12213 "Invalid number of allocations(%d)", count);
12214 return -1;
12215 }
12216
12217 for (i = 0; i < count; i++) {
12218 val = get_param_indexed(cmd, "PercentBI", i);
12219 if (!val) {
12220 sigma_dut_print(dut, DUT_MSG_ERROR,
12221 "Missing PercentBI parameter at index %d",
12222 i);
12223 return -1;
12224 }
12225 allocs[i].percent_bi = atoi(val);
12226
12227 val = get_param_indexed(cmd, "SrcAID", i);
12228 if (val)
12229 allocs[i].src_aid = strtol(val, NULL, 0);
12230 else
12231 allocs[i].src_aid = ESE_BCAST_AID;
12232
12233 val = get_param_indexed(cmd, "DestAID", i);
12234 if (val)
12235 allocs[i].dst_aid = strtol(val, NULL, 0);
12236 else
12237 allocs[i].dst_aid = ESE_BCAST_AID;
12238
12239 allocs[i].type = ESE_CBAP;
12240 sigma_dut_print(dut, DUT_MSG_INFO,
12241 "Alloc %d PercentBI %d SrcAID %d DstAID %d",
12242 i, allocs[i].percent_bi, allocs[i].src_aid,
12243 allocs[i].dst_aid);
12244 }
12245
12246 *allocs_size = count;
12247 return 0;
12248}
12249
12250
12251static int sta_set_60g_ese(struct sigma_dut *dut, int count,
12252 struct sigma_ese_alloc *allocs)
12253{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012254 switch (get_driver_type(dut)) {
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012255#ifdef __linux__
12256 case DRIVER_WIL6210:
12257 if (wil6210_set_ese(dut, count, allocs))
12258 return -1;
12259 return 1;
12260#endif /* __linux__ */
12261 default:
12262 sigma_dut_print(dut, DUT_MSG_ERROR,
12263 "Unsupported sta_set_60g_ese with the current driver");
12264 return -1;
12265 }
12266}
12267
12268
12269static int cmd_sta_set_rfeature_60g(const char *intf, struct sigma_dut *dut,
12270 struct sigma_conn *conn,
12271 struct sigma_cmd *cmd)
12272{
12273 const char *val;
12274
12275 val = get_param(cmd, "ExtSchIE");
12276 if (val && !strcasecmp(val, "Enable")) {
12277 struct sigma_ese_alloc allocs[MAX_ESE_ALLOCS];
12278 int count = MAX_ESE_ALLOCS;
12279
12280 if (sta_extract_60g_ese(dut, cmd, allocs, &count))
12281 return -1;
12282 return sta_set_60g_ese(dut, count, allocs);
12283 }
12284
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020012285 val = get_param(cmd, "MCS_FixedRate");
12286 if (val) {
12287 int sta_mcs = atoi(val);
12288
12289 sigma_dut_print(dut, DUT_MSG_INFO, "Force STA MCS to %d",
12290 sta_mcs);
12291 wil6210_set_force_mcs(dut, 1, sta_mcs);
12292
Jouni Malinen0e29cf22019-02-19 01:13:21 +020012293 return SUCCESS_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020012294 }
12295
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012296 send_resp(dut, conn, SIGMA_ERROR,
12297 "errorCode,Invalid sta_set_rfeature(60G)");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020012298 return STATUS_SENT;
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012299}
12300
12301
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053012302static int wcn_sta_override_oci(struct sigma_dut *dut, const char *intf,
12303 const char *oci_frametype, uint32_t oci_freq)
12304{
12305#ifdef NL80211_SUPPORT
12306 struct nl_msg *msg;
12307 int ret = 0;
12308 struct nlattr *params;
12309 struct nlattr *attr;
12310 int ifindex;
12311 u8 frame_type;
12312
12313 ifindex = if_nametoindex(intf);
12314 if (ifindex == 0) {
12315 sigma_dut_print(dut, DUT_MSG_ERROR,
12316 "%s: Index for interface %s failed",
12317 __func__, intf);
12318 return -1;
12319 }
12320
12321 if (strcasecmp(oci_frametype, "SAQueryReq") == 0) {
12322 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_SA_QUERY_REQ;
12323 } else if (strcasecmp(oci_frametype, "SAQueryResp") == 0) {
12324 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_SA_QUERY_RESP;
12325 } else if (strcasecmp(oci_frametype, "Reassocreq") == 0) {
12326 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_FT_REASSOC_REQ;
12327 } else {
12328 sigma_dut_print(dut, DUT_MSG_ERROR, "%s: Unknown frametype %s",
12329 __func__, oci_frametype);
12330 return -1;
12331 }
12332
12333
12334 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
12335 NL80211_CMD_VENDOR)) ||
12336 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
12337 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
12338 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
12339 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
12340 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
12341 !(params = nla_nest_start(
12342 msg,
12343 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_OCI_OVERRIDE)) ||
12344 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_OCI_OVERRIDE_FRAME_TYPE,
12345 frame_type) ||
12346 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_OCI_OVERRIDE_FREQUENCY,
12347 oci_freq)) {
12348 sigma_dut_print(dut, DUT_MSG_ERROR,
12349 "%s: err in adding vendor_cmd and vendor_data",
12350 __func__);
12351 nlmsg_free(msg);
12352 return -1;
12353 }
12354 nla_nest_end(msg, params);
12355 nla_nest_end(msg, attr);
12356
12357 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
12358 if (ret) {
12359 sigma_dut_print(dut, DUT_MSG_ERROR,
12360 "%s: err in send_and_recv_msgs, ret=%d",
12361 __func__, ret);
12362 }
12363 return ret;
12364#else /* NL80211_SUPPORT */
12365 sigma_dut_print(dut, DUT_MSG_ERROR,
12366 "OCI override not possible without NL80211_SUPPORT defined");
12367 return -1;
12368#endif /* NL80211_SUPPORT */
12369}
12370
12371
Veerendranath Jakkam50d5c782020-07-22 01:59:01 +053012372static int wcn_sta_ignore_csa(struct sigma_dut *dut, const char *intf,
12373 uint8_t ignore_csa)
12374{
12375#ifdef NL80211_SUPPORT
12376 return wcn_wifi_test_config_set_u8(
12377 dut, intf,
12378 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_IGNORE_CSA, ignore_csa);
12379#else /* NL80211_SUPPORT */
12380 sigma_dut_print(dut, DUT_MSG_ERROR,
12381 "IgnoreCSA can't be set without NL80211_SUPPORT defined");
12382 return -1;
12383#endif /* NL80211_SUPPORT */
12384}
12385
12386
Veerendranath Jakkamc771fac2020-07-22 01:32:56 +053012387static int wcn_sta_set_rsnxe_used(struct sigma_dut *dut, const char *intf,
12388 uint8_t rsnxe_used)
12389{
12390#ifdef NL80211_SUPPORT
12391 return wcn_wifi_test_config_set_u8(
12392 dut, intf,
12393 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_FT_REASSOCREQ_RSNXE_USED,
12394 rsnxe_used);
12395#else /* NL80211_SUPPORT */
12396 sigma_dut_print(dut, DUT_MSG_ERROR,
12397 "RSNXE_Used can't be set without NL80211_SUPPORT defined");
12398 return -1;
12399#endif /* NL80211_SUPPORT */
12400}
12401
12402
Veerendranath Jakkam1e1e5fd2020-09-10 07:12:37 +053012403static int wcn_sta_ignore_sa_query_timeout(struct sigma_dut *dut,
12404 const char *intf,
12405 uint8_t ignore_sa_query_timeout)
12406{
12407#ifdef NL80211_SUPPORT
12408 return wcn_wifi_test_config_set_u8(
12409 dut, intf,
12410 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_IGNORE_SA_QUERY_TIMEOUT,
12411 ignore_sa_query_timeout);
12412#else /* NL80211_SUPPORT */
12413 sigma_dut_print(dut, DUT_MSG_ERROR,
12414 "Ignore SA Query timeout can't be set without NL80211_SUPPORT defined");
12415 return -1;
12416#endif /* NL80211_SUPPORT */
12417}
12418
12419
Jouni Malinen6250cb02020-04-15 13:54:45 +030012420static enum sigma_cmd_result
12421cmd_sta_set_rfeature_wpa3(const char *intf, struct sigma_dut *dut,
12422 struct sigma_conn *conn,
12423 struct sigma_cmd *cmd)
12424{
Vamsi Krishnad29bc762020-05-08 23:23:30 +053012425 const char *val, *oci_chan, *oci_frametype;
Jouni Malinen6250cb02020-04-15 13:54:45 +030012426
Veerendranath Jakkam30bf9072020-04-16 14:37:57 +053012427 val = get_param(cmd, "ReassocReq_RSNXE_Used");
Jouni Malinen6250cb02020-04-15 13:54:45 +030012428 if (val && atoi(val) == 1) {
Veerendranath Jakkamc771fac2020-07-22 01:32:56 +053012429 if (wifi_chip_type == DRIVER_WCN) {
12430 if (wcn_sta_set_rsnxe_used(dut, intf, 1)) {
12431 send_resp(dut, conn, SIGMA_ERROR,
12432 "errorCode,Failed to set ft_rsnxe_used");
12433 return STATUS_SENT_ERROR;
12434 }
12435 return SUCCESS_SEND_STATUS;
12436 } else if (wpa_command(intf, "SET ft_rsnxe_used 1") < 0) {
Jouni Malinen6250cb02020-04-15 13:54:45 +030012437 send_resp(dut, conn, SIGMA_ERROR,
12438 "errorCode,Failed to set ft_rsnxe_used");
12439 return STATUS_SENT_ERROR;
12440 }
12441 return SUCCESS_SEND_STATUS;
12442 }
Vamsi Krishnad29bc762020-05-08 23:23:30 +053012443
12444 oci_chan = get_param(cmd, "OCIChannel");
12445 oci_frametype = get_param(cmd, "OCIFrameType");
12446 if (oci_chan && oci_frametype) {
12447 unsigned int oci_freq = channel_to_freq(dut, atoi(oci_chan));
12448 char buf[100];
12449
12450 if (!oci_freq) {
12451 send_resp(dut, conn, SIGMA_ERROR,
12452 "errorCode,Invalid OCIChannel number");
12453 return STATUS_SENT_ERROR;
12454 }
12455
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053012456 if (wifi_chip_type == DRIVER_WCN &&
12457 (strcasecmp(oci_frametype, "SAQueryReq") == 0 ||
12458 strcasecmp(oci_frametype, "SAQueryResp") == 0 ||
12459 strcasecmp(oci_frametype, "Reassocreq") == 0)) {
12460 if (wcn_sta_override_oci(dut, intf, oci_frametype,
12461 oci_freq)) {
12462 send_resp(dut, conn, SIGMA_ERROR,
12463 "errorCode,Failed to override OCI");
12464 return STATUS_SENT_ERROR;
12465 }
12466 return SUCCESS_SEND_STATUS;
12467 }
12468
Vamsi Krishnad29bc762020-05-08 23:23:30 +053012469 if (strcasecmp(oci_frametype, "eapolM2") == 0) {
12470 snprintf(buf, sizeof(buf),
12471 "SET oci_freq_override_eapol %d", oci_freq);
12472 } else if (strcasecmp(oci_frametype, "SAQueryReq") == 0) {
12473 snprintf(buf, sizeof(buf),
12474 "SET oci_freq_override_saquery_req %d",
12475 oci_freq);
12476 } else if (strcasecmp(oci_frametype, "SAQueryResp") == 0) {
12477 snprintf(buf, sizeof(buf),
12478 "SET oci_freq_override_saquery_resp %d",
12479 oci_freq);
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053012480 } else if (strcasecmp(oci_frametype, "GrpKeyM2") == 0) {
12481 snprintf(buf, sizeof(buf),
12482 "SET oci_freq_override_eapol_g2 %d",
12483 oci_freq);
12484 } else if (strcasecmp(oci_frametype, "Reassocreq") == 0) {
12485 snprintf(buf, sizeof(buf),
12486 "SET oci_freq_override_ft_assoc %d",
12487 oci_freq);
Vamsi Krishnad29bc762020-05-08 23:23:30 +053012488 } else {
12489 send_resp(dut, conn, SIGMA_ERROR,
12490 "errorCode,Unsupported OCIFrameType");
12491 return STATUS_SENT_ERROR;
12492 }
12493 if (wpa_command(intf, buf) < 0) {
12494 send_resp(dut, conn, SIGMA_ERROR,
12495 "errorCode,Failed to set oci_freq_override");
12496 return STATUS_SENT_ERROR;
12497 }
12498 return SUCCESS_SEND_STATUS;
12499 }
12500
Veerendranath Jakkam50d5c782020-07-22 01:59:01 +053012501 val = get_param(cmd, "IgnoreCSA");
12502 if (val && atoi(val) == 1) {
12503 if (wifi_chip_type == DRIVER_WCN) {
12504 if (wcn_sta_ignore_csa(dut, intf, 1)) {
12505 send_resp(dut, conn, SIGMA_ERROR,
12506 "errorCode,Failed to set ignore CSA");
12507 return STATUS_SENT_ERROR;
12508 }
12509 return SUCCESS_SEND_STATUS;
12510 }
12511 }
12512
Veerendranath Jakkam1e1e5fd2020-09-10 07:12:37 +053012513 val = get_param(cmd, "Deauth_Per_SAQueryResp");
12514 if (val && atoi(val) == 0) {
12515 if (wifi_chip_type == DRIVER_WCN) {
12516 if (wcn_sta_ignore_sa_query_timeout(dut, intf, 1)) {
12517 send_resp(dut, conn, SIGMA_ERROR,
12518 "errorCode,Failed to set ignore SA Query timeout");
12519 return STATUS_SENT_ERROR;
12520 }
12521 return SUCCESS_SEND_STATUS;
12522 }
12523 }
12524
Jouni Malinen6250cb02020-04-15 13:54:45 +030012525 send_resp(dut, conn, SIGMA_ERROR,
12526 "errorCode,Unsupported WPA3 rfeature");
12527 return STATUS_SENT_ERROR;
12528}
12529
12530
Jouni Malinenf7222712019-06-13 01:50:21 +030012531static enum sigma_cmd_result cmd_sta_set_rfeature(struct sigma_dut *dut,
12532 struct sigma_conn *conn,
12533 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012534{
12535 const char *intf = get_param(cmd, "Interface");
12536 const char *prog = get_param(cmd, "Prog");
Ashwini Patil68d02cd2017-01-10 15:39:16 +053012537 const char *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012538
12539 if (intf == NULL || prog == NULL)
12540 return -1;
12541
Ashwini Patil5acd7382017-04-13 15:55:04 +053012542 /* BSS Transition candidate list for BTM query */
12543 val = get_param(cmd, "Nebor_BSSID");
12544 if (val && btm_query_candidate_list(dut, conn, cmd) == 0)
12545 return 0;
12546
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012547 if (strcasecmp(prog, "TDLS") == 0)
12548 return cmd_sta_set_rfeature_tdls(intf, dut, conn, cmd);
12549
12550 if (strcasecmp(prog, "VHT") == 0)
12551 return cmd_sta_set_rfeature_vht(intf, dut, conn, cmd);
12552
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012553 if (strcasecmp(prog, "HE") == 0)
12554 return cmd_sta_set_rfeature_he(intf, dut, conn, cmd);
12555
Ashwini Patil68d02cd2017-01-10 15:39:16 +053012556 if (strcasecmp(prog, "MBO") == 0) {
12557 val = get_param(cmd, "Cellular_Data_Cap");
12558 if (val &&
12559 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
12560 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +053012561
12562 val = get_param(cmd, "Ch_Pref");
12563 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
12564 return 0;
12565
Ashwini Patil68d02cd2017-01-10 15:39:16 +053012566 return 1;
12567 }
12568
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012569 if (strcasecmp(prog, "60GHz") == 0)
12570 return cmd_sta_set_rfeature_60g(intf, dut, conn, cmd);
12571
Jouni Malinen6250cb02020-04-15 13:54:45 +030012572 if (strcasecmp(prog, "WPA3") == 0)
12573 return cmd_sta_set_rfeature_wpa3(intf, dut, conn, cmd);
12574
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012575 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported Prog");
12576 return 0;
12577}
12578
12579
Jouni Malinenf7222712019-06-13 01:50:21 +030012580static enum sigma_cmd_result cmd_sta_set_radio(struct sigma_dut *dut,
12581 struct sigma_conn *conn,
12582 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012583{
12584 const char *intf = get_param(cmd, "Interface");
12585 const char *mode = get_param(cmd, "Mode");
12586 int res;
12587
12588 if (intf == NULL || mode == NULL)
12589 return -1;
12590
12591 if (strcasecmp(mode, "On") == 0)
12592 res = wpa_command(intf, "SET radio_disabled 0");
12593 else if (strcasecmp(mode, "Off") == 0)
12594 res = wpa_command(intf, "SET radio_disabled 1");
12595 else
12596 return -1;
12597
12598 if (res) {
12599 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
12600 "radio mode");
12601 return 0;
12602 }
12603
12604 return 1;
12605}
12606
12607
Jouni Malinenf7222712019-06-13 01:50:21 +030012608static enum sigma_cmd_result cmd_sta_set_pwrsave(struct sigma_dut *dut,
12609 struct sigma_conn *conn,
12610 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012611{
12612 const char *intf = get_param(cmd, "Interface");
12613 const char *mode = get_param(cmd, "Mode");
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012614 const char *prog = get_param(cmd, "program");
12615 const char *powersave = get_param(cmd, "powersave");
12616 int res = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012617
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012618 if (intf == NULL)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012619 return -1;
12620
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012621 if (prog && strcasecmp(prog, "60GHz") == 0) {
12622 /*
12623 * The CAPI mode parameter does not exist in 60G
12624 * unscheduled PS.
12625 */
Hu Wang5dc3ff12019-06-14 15:14:26 +080012626 if (powersave && strcasecmp(powersave, "unscheduled") == 0)
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012627 res = set_ps(intf, dut, 1);
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012628 } else if (prog && get_driver_type(dut) == DRIVER_WCN &&
Alexei Avshalom Lazar2f6fdb42019-02-04 14:16:08 +020012629 strcasecmp(prog, "HE") == 0) {
12630 return cmd_sta_set_power_save_he(intf, dut, conn, cmd);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012631 } else {
12632 if (mode == NULL)
12633 return -1;
12634
12635 if (strcasecmp(mode, "On") == 0)
12636 res = set_ps(intf, dut, 1);
12637 else if (strcasecmp(mode, "Off") == 0)
12638 res = set_ps(intf, dut, 0);
12639 else
12640 return -1;
12641 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012642
12643 if (res) {
12644 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
12645 "power save mode");
12646 return 0;
12647 }
12648
12649 return 1;
12650}
12651
12652
Jouni Malinenf7222712019-06-13 01:50:21 +030012653static enum sigma_cmd_result cmd_sta_bssid_pool(struct sigma_dut *dut,
12654 struct sigma_conn *conn,
12655 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012656{
12657 const char *intf = get_param(cmd, "Interface");
12658 const char *val, *bssid;
12659 int res;
12660 char *buf;
12661 size_t buf_len;
12662
12663 val = get_param(cmd, "BSSID_FILTER");
12664 if (val == NULL)
12665 return -1;
12666
12667 bssid = get_param(cmd, "BSSID_List");
12668 if (atoi(val) == 0 || bssid == NULL) {
12669 /* Disable BSSID filter */
12670 if (wpa_command(intf, "SET bssid_filter ")) {
12671 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed "
12672 "to disable BSSID filter");
12673 return 0;
12674 }
12675
12676 return 1;
12677 }
12678
12679 buf_len = 100 + strlen(bssid);
12680 buf = malloc(buf_len);
12681 if (buf == NULL)
12682 return -1;
12683
12684 snprintf(buf, buf_len, "SET bssid_filter %s", bssid);
12685 res = wpa_command(intf, buf);
12686 free(buf);
12687 if (res) {
12688 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to enable "
12689 "BSSID filter");
12690 return 0;
12691 }
12692
12693 return 1;
12694}
12695
12696
Jouni Malinenf7222712019-06-13 01:50:21 +030012697static enum sigma_cmd_result cmd_sta_reset_parm(struct sigma_dut *dut,
12698 struct sigma_conn *conn,
12699 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012700{
12701 const char *intf = get_param(cmd, "Interface");
12702 const char *val;
12703
12704 /* TODO: ARP */
12705
12706 val = get_param(cmd, "HS2_CACHE_PROFILE");
12707 if (val && strcasecmp(val, "All") == 0)
12708 hs2_clear_credentials(intf);
12709
12710 return 1;
12711}
12712
12713
Jouni Malinenf7222712019-06-13 01:50:21 +030012714static enum sigma_cmd_result cmd_sta_get_key(struct sigma_dut *dut,
12715 struct sigma_conn *conn,
12716 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012717{
12718 const char *intf = get_param(cmd, "Interface");
12719 const char *key_type = get_param(cmd, "KeyType");
12720 char buf[100], resp[200];
12721
12722 if (key_type == NULL)
12723 return -1;
12724
12725 if (strcasecmp(key_type, "GTK") == 0) {
12726 if (wpa_command_resp(intf, "GET gtk", buf, sizeof(buf)) < 0 ||
12727 strncmp(buf, "FAIL", 4) == 0) {
12728 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12729 "not fetch current GTK");
12730 return 0;
12731 }
12732 snprintf(resp, sizeof(resp), "KeyValue,%s", buf);
12733 send_resp(dut, conn, SIGMA_COMPLETE, resp);
12734 return 0;
12735 } else {
12736 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
12737 "KeyType");
12738 return 0;
12739 }
12740
12741 return 1;
12742}
12743
12744
12745static int hs2_set_policy(struct sigma_dut *dut)
12746{
12747#ifdef ANDROID
12748 system("ip rule del prio 23000");
12749 if (system("ip rule add from all lookup main prio 23000") != 0) {
12750 sigma_dut_print(dut, DUT_MSG_ERROR,
12751 "Failed to run:ip rule add from all lookup main prio");
12752 return -1;
12753 }
12754 if (system("ip route flush cache") != 0) {
12755 sigma_dut_print(dut, DUT_MSG_ERROR,
12756 "Failed to run ip route flush cache");
12757 return -1;
12758 }
12759 return 1;
12760#else /* ANDROID */
12761 return 0;
12762#endif /* ANDROID */
12763}
12764
12765
Jouni Malinenf7222712019-06-13 01:50:21 +030012766static enum sigma_cmd_result cmd_sta_hs2_associate(struct sigma_dut *dut,
12767 struct sigma_conn *conn,
12768 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012769{
12770 const char *intf = get_param(cmd, "Interface");
12771 const char *val = get_param(cmd, "Ignore_blacklist");
Jouni Malinen439352d2018-09-13 03:42:23 +030012772 const char *band = get_param(cmd, "Band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012773 struct wpa_ctrl *ctrl;
Jouni Malinen3aa72862019-05-29 23:14:51 +030012774 int res, r;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012775 char bssid[20], ssid[40], resp[100], buf[100], blacklisted[100];
12776 int tries = 0;
12777 int ignore_blacklist = 0;
12778 const char *events[] = {
12779 "CTRL-EVENT-CONNECTED",
12780 "INTERWORKING-BLACKLISTED",
12781 "INTERWORKING-NO-MATCH",
12782 NULL
12783 };
12784
12785 start_sta_mode(dut);
12786
Jouni Malinen439352d2018-09-13 03:42:23 +030012787 if (band) {
12788 if (strcmp(band, "2.4") == 0) {
12789 wpa_command(intf, "SET setband 2G");
12790 } else if (strcmp(band, "5") == 0) {
12791 wpa_command(intf, "SET setband 5G");
12792 } else {
12793 send_resp(dut, conn, SIGMA_ERROR,
12794 "errorCode,Unsupported band");
12795 return 0;
12796 }
12797 }
12798
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012799 blacklisted[0] = '\0';
12800 if (val && atoi(val))
12801 ignore_blacklist = 1;
12802
12803try_again:
12804 ctrl = open_wpa_mon(intf);
12805 if (ctrl == NULL) {
12806 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
12807 "wpa_supplicant monitor connection");
12808 return -2;
12809 }
12810
12811 tries++;
12812 if (wpa_command(intf, "INTERWORKING_SELECT auto")) {
12813 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start "
12814 "Interworking connection");
12815 wpa_ctrl_detach(ctrl);
12816 wpa_ctrl_close(ctrl);
12817 return 0;
12818 }
12819
12820 buf[0] = '\0';
12821 while (1) {
12822 char *pos;
12823 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
12824 pos = strstr(buf, "INTERWORKING-BLACKLISTED");
12825 if (!pos)
12826 break;
12827 pos += 25;
12828 sigma_dut_print(dut, DUT_MSG_DEBUG, "Found blacklisted AP: %s",
12829 pos);
12830 if (!blacklisted[0])
12831 memcpy(blacklisted, pos, strlen(pos) + 1);
12832 }
12833
12834 if (ignore_blacklist && blacklisted[0]) {
12835 char *end;
12836 end = strchr(blacklisted, ' ');
12837 if (end)
12838 *end = '\0';
12839 sigma_dut_print(dut, DUT_MSG_DEBUG, "Try to connect to a blacklisted network: %s",
12840 blacklisted);
Jouni Malinen3aa72862019-05-29 23:14:51 +030012841 r = snprintf(buf, sizeof(buf), "INTERWORKING_CONNECT %s",
12842 blacklisted);
12843 if (r < 0 || r >= sizeof(buf) || wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012844 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start Interworking connection to blacklisted network");
12845 wpa_ctrl_detach(ctrl);
12846 wpa_ctrl_close(ctrl);
12847 return 0;
12848 }
12849 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
12850 buf, sizeof(buf));
12851 }
12852
12853 wpa_ctrl_detach(ctrl);
12854 wpa_ctrl_close(ctrl);
12855
12856 if (res < 0) {
12857 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
12858 "connect");
12859 return 0;
12860 }
12861
12862 if (strstr(buf, "INTERWORKING-NO-MATCH") ||
12863 strstr(buf, "INTERWORKING-BLACKLISTED")) {
12864 if (tries < 2) {
12865 sigma_dut_print(dut, DUT_MSG_INFO, "No match found - try again to verify no APs were missed in the scan");
12866 goto try_again;
12867 }
12868 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,No network with "
12869 "matching credentials found");
12870 return 0;
12871 }
12872
12873 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
12874 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
12875 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
12876 "get current BSSID/SSID");
12877 return 0;
12878 }
12879
12880 snprintf(resp, sizeof(resp), "SSID,%s,BSSID,%s", ssid, bssid);
12881 send_resp(dut, conn, SIGMA_COMPLETE, resp);
12882 hs2_set_policy(dut);
12883 return 0;
12884}
12885
12886
Jouni Malinenf7222712019-06-13 01:50:21 +030012887static enum sigma_cmd_result cmd_sta_hs2_venue_info(struct sigma_dut *dut,
12888 struct sigma_conn *conn,
12889 struct sigma_cmd *cmd)
Jouni Malinenb639f1c2018-09-13 02:39:46 +030012890{
12891 const char *intf = get_param(cmd, "Interface");
12892 const char *display = get_param(cmd, "Display");
12893 struct wpa_ctrl *ctrl;
12894 char buf[300], params[400], *pos;
12895 char bssid[20];
12896 int info_avail = 0;
12897 unsigned int old_timeout;
12898 int res;
12899
12900 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
12901 send_resp(dut, conn, SIGMA_ERROR,
12902 "ErrorCode,Could not get current BSSID");
12903 return 0;
12904 }
12905 ctrl = open_wpa_mon(intf);
12906 if (!ctrl) {
12907 sigma_dut_print(dut, DUT_MSG_ERROR,
12908 "Failed to open wpa_supplicant monitor connection");
12909 return -2;
12910 }
12911
12912 snprintf(buf, sizeof(buf), "ANQP_GET %s 277", bssid);
12913 wpa_command(intf, buf);
12914
12915 res = get_wpa_cli_event(dut, ctrl, "GAS-QUERY-DONE", buf, sizeof(buf));
12916 if (res < 0) {
12917 send_resp(dut, conn, SIGMA_ERROR,
12918 "ErrorCode,Could not complete GAS query");
12919 goto fail;
12920 }
12921
12922 old_timeout = dut->default_timeout;
12923 dut->default_timeout = 2;
12924 res = get_wpa_cli_event(dut, ctrl, "RX-VENUE-URL", buf, sizeof(buf));
12925 dut->default_timeout = old_timeout;
12926 if (res < 0)
12927 goto done;
12928 pos = strchr(buf, ' ');
12929 if (!pos)
12930 goto done;
12931 pos++;
12932 pos = strchr(pos, ' ');
12933 if (!pos)
12934 goto done;
12935 pos++;
12936 info_avail = 1;
12937 snprintf(params, sizeof(params), "browser %s", pos);
12938
12939 if (display && strcasecmp(display, "Yes") == 0) {
12940 pid_t pid;
12941
12942 pid = fork();
12943 if (pid < 0) {
12944 perror("fork");
12945 return -1;
12946 }
12947
12948 if (pid == 0) {
12949 run_hs20_osu(dut, params);
12950 exit(0);
12951 }
12952 }
12953
12954done:
12955 snprintf(buf, sizeof(buf), "Info_available,%s",
12956 info_avail ? "Yes" : "No");
12957 send_resp(dut, conn, SIGMA_COMPLETE, buf);
12958fail:
12959 wpa_ctrl_detach(ctrl);
12960 wpa_ctrl_close(ctrl);
12961 return 0;
12962}
12963
12964
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012965static int sta_add_credential_uname_pwd(struct sigma_dut *dut,
12966 struct sigma_conn *conn,
12967 const char *ifname,
12968 struct sigma_cmd *cmd)
12969{
12970 const char *val;
12971 int id;
12972
12973 id = add_cred(ifname);
12974 if (id < 0)
12975 return -2;
12976 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
12977
12978 val = get_param(cmd, "prefer");
12979 if (val && atoi(val) > 0)
12980 set_cred(ifname, id, "priority", "1");
12981
12982 val = get_param(cmd, "REALM");
12983 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
12984 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12985 "realm");
12986 return 0;
12987 }
12988
12989 val = get_param(cmd, "HOME_FQDN");
12990 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
12991 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12992 "home_fqdn");
12993 return 0;
12994 }
12995
12996 val = get_param(cmd, "Username");
12997 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
12998 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12999 "username");
13000 return 0;
13001 }
13002
13003 val = get_param(cmd, "Password");
13004 if (val && set_cred_quoted(ifname, id, "password", val) < 0) {
13005 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13006 "password");
13007 return 0;
13008 }
13009
13010 val = get_param(cmd, "ROOT_CA");
13011 if (val) {
13012 char fname[200];
13013 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
13014#ifdef __linux__
13015 if (!file_exists(fname)) {
13016 char msg[300];
13017 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
13018 "file (%s) not found", fname);
13019 send_resp(dut, conn, SIGMA_ERROR, msg);
13020 return 0;
13021 }
13022#endif /* __linux__ */
13023 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
13024 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13025 "not set root CA");
13026 return 0;
13027 }
13028 }
13029
13030 return 1;
13031}
13032
13033
13034static int update_devdetail_imsi(struct sigma_dut *dut, const char *imsi)
13035{
13036 FILE *in, *out;
13037 char buf[500];
13038 int found = 0;
13039
13040 in = fopen("devdetail.xml", "r");
13041 if (in == NULL)
13042 return -1;
13043 out = fopen("devdetail.xml.tmp", "w");
13044 if (out == NULL) {
13045 fclose(in);
13046 return -1;
13047 }
13048
13049 while (fgets(buf, sizeof(buf), in)) {
13050 char *pos = strstr(buf, "<IMSI>");
13051 if (pos) {
13052 sigma_dut_print(dut, DUT_MSG_INFO, "Updated DevDetail IMSI to %s",
13053 imsi);
13054 pos += 6;
13055 *pos = '\0';
13056 fprintf(out, "%s%s</IMSI>\n", buf, imsi);
13057 found++;
13058 } else {
13059 fprintf(out, "%s", buf);
13060 }
13061 }
13062
13063 fclose(out);
13064 fclose(in);
13065 if (found)
13066 rename("devdetail.xml.tmp", "devdetail.xml");
13067 else
13068 unlink("devdetail.xml.tmp");
13069
13070 return 0;
13071}
13072
13073
13074static int sta_add_credential_sim(struct sigma_dut *dut,
13075 struct sigma_conn *conn,
13076 const char *ifname, struct sigma_cmd *cmd)
13077{
13078 const char *val, *imsi = NULL;
13079 int id;
13080 char buf[200];
13081 int res;
13082 const char *pos;
13083 size_t mnc_len;
13084 char plmn_mcc[4];
13085 char plmn_mnc[4];
13086
13087 id = add_cred(ifname);
13088 if (id < 0)
13089 return -2;
13090 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
13091
13092 val = get_param(cmd, "prefer");
13093 if (val && atoi(val) > 0)
13094 set_cred(ifname, id, "priority", "1");
13095
13096 val = get_param(cmd, "PLMN_MCC");
13097 if (val == NULL) {
13098 send_resp(dut, conn, SIGMA_ERROR,
13099 "errorCode,Missing PLMN_MCC");
13100 return 0;
13101 }
13102 if (strlen(val) != 3) {
13103 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MCC");
13104 return 0;
13105 }
13106 snprintf(plmn_mcc, sizeof(plmn_mcc), "%s", val);
13107
13108 val = get_param(cmd, "PLMN_MNC");
13109 if (val == NULL) {
13110 send_resp(dut, conn, SIGMA_ERROR,
13111 "errorCode,Missing PLMN_MNC");
13112 return 0;
13113 }
13114 if (strlen(val) != 2 && strlen(val) != 3) {
13115 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MNC");
13116 return 0;
13117 }
13118 snprintf(plmn_mnc, sizeof(plmn_mnc), "%s", val);
13119
13120 val = get_param(cmd, "IMSI");
13121 if (val == NULL) {
13122 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing SIM "
13123 "IMSI");
13124 return 0;
13125 }
13126
13127 imsi = pos = val;
13128
13129 if (strncmp(plmn_mcc, pos, 3) != 0) {
13130 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MCC mismatch");
13131 return 0;
13132 }
13133 pos += 3;
13134
13135 mnc_len = strlen(plmn_mnc);
13136 if (mnc_len < 2) {
13137 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC not set");
13138 return 0;
13139 }
13140
13141 if (strncmp(plmn_mnc, pos, mnc_len) != 0) {
13142 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC mismatch");
13143 return 0;
13144 }
13145 pos += mnc_len;
13146
13147 res = snprintf(buf, sizeof(buf), "%s%s-%s",plmn_mcc, plmn_mnc, pos);
13148 if (res < 0 || res >= (int) sizeof(buf))
13149 return -1;
13150 if (set_cred_quoted(ifname, id, "imsi", buf) < 0) {
13151 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13152 "not set IMSI");
13153 return 0;
13154 }
13155
13156 val = get_param(cmd, "Password");
13157 if (val && set_cred_quoted(ifname, id, "milenage", val) < 0) {
13158 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13159 "not set password");
13160 return 0;
13161 }
13162
Jouni Malinenba630452018-06-22 11:49:59 +030013163 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013164 /*
13165 * Set provisioning_sp for the test cases where SIM/USIM
13166 * provisioning is used.
13167 */
13168 if (val && set_cred_quoted(ifname, id, "provisioning_sp",
13169 "wi-fi.org") < 0) {
13170 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13171 "not set provisioning_sp");
13172 return 0;
13173 }
13174
13175 update_devdetail_imsi(dut, imsi);
13176 }
13177
13178 return 1;
13179}
13180
13181
13182static int sta_add_credential_cert(struct sigma_dut *dut,
13183 struct sigma_conn *conn,
13184 const char *ifname,
13185 struct sigma_cmd *cmd)
13186{
13187 const char *val;
13188 int id;
13189
13190 id = add_cred(ifname);
13191 if (id < 0)
13192 return -2;
13193 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
13194
13195 val = get_param(cmd, "prefer");
13196 if (val && atoi(val) > 0)
13197 set_cred(ifname, id, "priority", "1");
13198
13199 val = get_param(cmd, "REALM");
13200 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
13201 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13202 "realm");
13203 return 0;
13204 }
13205
13206 val = get_param(cmd, "HOME_FQDN");
13207 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
13208 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13209 "home_fqdn");
13210 return 0;
13211 }
13212
13213 val = get_param(cmd, "Username");
13214 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
13215 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13216 "username");
13217 return 0;
13218 }
13219
13220 val = get_param(cmd, "clientCertificate");
13221 if (val) {
13222 char fname[200];
13223 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
13224#ifdef __linux__
13225 if (!file_exists(fname)) {
13226 char msg[300];
13227 snprintf(msg, sizeof(msg),
13228 "ErrorCode,clientCertificate "
13229 "file (%s) not found", fname);
13230 send_resp(dut, conn, SIGMA_ERROR, msg);
13231 return 0;
13232 }
13233#endif /* __linux__ */
13234 if (set_cred_quoted(ifname, id, "client_cert", fname) < 0) {
13235 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13236 "not set client_cert");
13237 return 0;
13238 }
13239 if (set_cred_quoted(ifname, id, "private_key", fname) < 0) {
13240 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13241 "not set private_key");
13242 return 0;
13243 }
13244 }
13245
13246 val = get_param(cmd, "ROOT_CA");
13247 if (val) {
13248 char fname[200];
13249 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
13250#ifdef __linux__
13251 if (!file_exists(fname)) {
13252 char msg[300];
13253 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
13254 "file (%s) not found", fname);
13255 send_resp(dut, conn, SIGMA_ERROR, msg);
13256 return 0;
13257 }
13258#endif /* __linux__ */
13259 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
13260 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13261 "not set root CA");
13262 return 0;
13263 }
13264 }
13265
13266 return 1;
13267}
13268
13269
Jouni Malinenf7222712019-06-13 01:50:21 +030013270static enum sigma_cmd_result cmd_sta_add_credential(struct sigma_dut *dut,
13271 struct sigma_conn *conn,
13272 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013273{
13274 const char *intf = get_param(cmd, "Interface");
13275 const char *type;
13276
13277 start_sta_mode(dut);
13278
13279 type = get_param(cmd, "Type");
13280 if (!type)
13281 return -1;
13282
13283 if (strcasecmp(type, "uname_pwd") == 0)
13284 return sta_add_credential_uname_pwd(dut, conn, intf, cmd);
13285
13286 if (strcasecmp(type, "sim") == 0)
13287 return sta_add_credential_sim(dut, conn, intf, cmd);
13288
13289 if (strcasecmp(type, "cert") == 0)
13290 return sta_add_credential_cert(dut, conn, intf, cmd);
13291
13292 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported credential "
13293 "type");
13294 return 0;
13295}
13296
13297
Jouni Malinenf7222712019-06-13 01:50:21 +030013298static enum sigma_cmd_result cmd_sta_scan(struct sigma_dut *dut,
13299 struct sigma_conn *conn,
13300 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013301{
13302 const char *intf = get_param(cmd, "Interface");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013303 const char *val, *bssid, *ssid, *scan_freq, *short_ssid;
Veerendranathdc581b52020-08-10 03:29:08 -070013304 char buf[4096], scan_res[20];
vamsi krishna89ad8c62017-09-19 12:51:18 +053013305 char ssid_hex[65];
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080013306 int wildcard_ssid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013307 int res;
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013308 enum sigma_cmd_result status;
Jouni Malinen228a2fc2020-06-22 23:37:45 +030013309 struct wpa_ctrl *ctrl = NULL;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013310
Jouni Malinen8c1abeb2019-11-06 18:48:34 +020013311 start_sta_mode(dut);
13312
Arif Hussain66a4af02019-02-07 15:04:51 -080013313 val = get_param(cmd, "GetParameter");
13314 if (val && strcmp(val, "SSID_BSSID") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013315 if (get_wpa_ssid_bssid(dut, get_station_ifname(dut),
Arif Hussain66a4af02019-02-07 15:04:51 -080013316 buf, sizeof(buf)) < 0) {
13317 sigma_dut_print(dut, DUT_MSG_ERROR,
13318 "Could not get ssid bssid");
13319 return ERROR_SEND_STATUS;
13320 }
13321
13322 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
13323 send_resp(dut, conn, SIGMA_COMPLETE, buf);
13324 return STATUS_SENT;
13325 }
13326
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013327 val = get_param(cmd, "HESSID");
13328 if (val) {
13329 res = snprintf(buf, sizeof(buf), "SET hessid %s", val);
13330 if (res < 0 || res >= (int) sizeof(buf))
13331 return -1;
13332 wpa_command(intf, buf);
13333 }
13334
13335 val = get_param(cmd, "ACCS_NET_TYPE");
13336 if (val) {
13337 res = snprintf(buf, sizeof(buf), "SET access_network_type %s",
13338 val);
13339 if (res < 0 || res >= (int) sizeof(buf))
13340 return -1;
13341 wpa_command(intf, buf);
13342 }
13343
vamsi krishna89ad8c62017-09-19 12:51:18 +053013344 bssid = get_param(cmd, "Bssid");
13345 ssid = get_param(cmd, "Ssid");
13346
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080013347 if (ssid && strcasecmp(ssid, "ZeroLength") == 0 &&
13348 dut->device_type == STA_testbed) {
13349 ssid = NULL;
13350 wildcard_ssid = 1;
13351 }
13352
vamsi krishna89ad8c62017-09-19 12:51:18 +053013353 if (ssid) {
13354 if (2 * strlen(ssid) >= sizeof(ssid_hex)) {
13355 send_resp(dut, conn, SIGMA_ERROR,
13356 "ErrorCode,Too long SSID");
13357 return 0;
13358 }
13359 ascii2hexstr(ssid, ssid_hex);
13360 }
13361
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013362 short_ssid = get_param(cmd, "ShortSSID");
13363 if (short_ssid) {
13364 uint32_t short_ssid_hex;
13365
13366 short_ssid_hex = strtoul(short_ssid, NULL, 16);
13367 short_ssid_hex = ((short_ssid_hex & 0xFF) << 24) |
13368 (((short_ssid_hex >> 8) & 0xFF) << 16) |
13369 (((short_ssid_hex >> 16) & 0xFF) << 8) |
13370 ((short_ssid_hex >> 24) & 0xFF);
13371
13372 res = snprintf(buf, sizeof(buf),
13373 "VENDOR_ELEM_ADD 14 ff053a%08x",
13374 short_ssid_hex);
13375 if (res < 0 || res >= (int) sizeof(buf) ||
13376 wpa_command(intf, buf)) {
13377 send_resp(dut, conn, SIGMA_ERROR,
13378 "errorCode,Failed to add short SSID");
13379 return STATUS_SENT_ERROR;
13380 }
13381 }
13382
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080013383 scan_freq = get_param(cmd, "ChnlFreq");
Veerendranath Jakkam132c4b42020-08-10 00:29:03 +053013384 if (scan_freq) {
13385 if (strcasecmp(scan_freq, "2G") == 0)
13386 scan_freq = "2412-2462";
13387 else if (strcasecmp(scan_freq, "5G") == 0)
13388 scan_freq = "5180-5925";
13389 }
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080013390
Jouni Malinen228a2fc2020-06-22 23:37:45 +030013391 val = get_param(cmd, "WaitCompletion");
13392 if (val && atoi(val) == 1) {
13393 ctrl = open_wpa_mon(intf);
13394 if (!ctrl) {
13395 send_resp(dut, conn, SIGMA_ERROR,
13396 "errorCode,Failed to open monitor socket");
13397 return STATUS_SENT_ERROR;
13398 }
13399 }
13400
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080013401 res = snprintf(buf, sizeof(buf), "SCAN%s%s%s%s%s%s%s",
vamsi krishna89ad8c62017-09-19 12:51:18 +053013402 bssid ? " bssid=": "",
13403 bssid ? bssid : "",
13404 ssid ? " ssid " : "",
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080013405 ssid ? ssid_hex : "",
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080013406 wildcard_ssid ? " wildcard_ssid=1" : "",
13407 scan_freq ? " freq=" : "",
13408 scan_freq ? scan_freq : "");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013409 if (res < 0 || res >= (int) sizeof(buf)) {
13410 send_resp(dut, conn, SIGMA_ERROR,
13411 "errorCode,Could not build scan command");
13412 status = STATUS_SENT_ERROR;
13413 goto remove_s_ssid;
13414 }
vamsi krishna89ad8c62017-09-19 12:51:18 +053013415
Veerendranathdc581b52020-08-10 03:29:08 -070013416 res = wpa_command_resp(intf, buf, scan_res, sizeof(scan_res));
13417 if (strncmp(scan_res, "FAIL-BUSY", 9) == 0) {
13418 sigma_dut_print(dut, DUT_MSG_DEBUG,
13419 "Scan request rejected with busy status, abort ongoing scan and try again");
13420 wpa_command(intf, "ABORT_SCAN");
13421 res = wpa_command(intf, buf);
13422 }
13423
13424 if (res < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013425 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not start "
13426 "scan");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013427 status = STATUS_SENT_ERROR;
13428 } else {
13429 status = SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013430 }
13431
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013432remove_s_ssid:
13433 if (short_ssid && wpa_command(intf, "VENDOR_ELEM_REMOVE 14 *"))
13434 sigma_dut_print(dut, DUT_MSG_ERROR,
13435 "Failed to delete vendor element");
13436
Jouni Malinen228a2fc2020-06-22 23:37:45 +030013437 if (ctrl) {
13438 if (status == SUCCESS_SEND_STATUS) {
13439 res = get_wpa_cli_event(dut, ctrl,
13440 "CTRL-EVENT-SCAN-RESULTS",
13441 buf, sizeof(buf));
13442 if (res < 0) {
13443 send_resp(dut, conn, SIGMA_ERROR,
13444 "ErrorCode,scan did not complete");
13445 status = STATUS_SENT_ERROR;
13446 }
13447 }
13448
13449 wpa_ctrl_detach(ctrl);
13450 wpa_ctrl_close(ctrl);
13451 }
13452
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013453 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013454}
13455
13456
Jouni Malinenf7222712019-06-13 01:50:21 +030013457static enum sigma_cmd_result cmd_sta_scan_bss(struct sigma_dut *dut,
13458 struct sigma_conn *conn,
13459 struct sigma_cmd *cmd)
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020013460{
13461 const char *intf = get_param(cmd, "Interface");
13462 const char *bssid;
13463 char buf[4096], *pos;
13464 int freq, chan;
13465 char *ssid;
13466 char resp[100];
13467 int res;
13468 struct wpa_ctrl *ctrl;
13469
13470 bssid = get_param(cmd, "BSSID");
13471 if (!bssid) {
13472 send_resp(dut, conn, SIGMA_INVALID,
13473 "errorCode,BSSID argument is missing");
13474 return 0;
13475 }
13476
13477 ctrl = open_wpa_mon(intf);
13478 if (!ctrl) {
13479 sigma_dut_print(dut, DUT_MSG_ERROR,
13480 "Failed to open wpa_supplicant monitor connection");
13481 return -1;
13482 }
13483
13484 if (wpa_command(intf, "SCAN TYPE=ONLY")) {
13485 send_resp(dut, conn, SIGMA_ERROR,
13486 "errorCode,Could not start scan");
13487 wpa_ctrl_detach(ctrl);
13488 wpa_ctrl_close(ctrl);
13489 return 0;
13490 }
13491
13492 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
13493 buf, sizeof(buf));
13494
13495 wpa_ctrl_detach(ctrl);
13496 wpa_ctrl_close(ctrl);
13497
13498 if (res < 0) {
13499 send_resp(dut, conn, SIGMA_ERROR,
13500 "errorCode,Scan did not complete");
13501 return 0;
13502 }
13503
13504 snprintf(buf, sizeof(buf), "BSS %s", bssid);
13505 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
13506 strncmp(buf, "id=", 3) != 0) {
13507 send_resp(dut, conn, SIGMA_ERROR,
13508 "errorCode,Specified BSSID not found");
13509 return 0;
13510 }
13511
13512 pos = strstr(buf, "\nfreq=");
13513 if (!pos) {
13514 send_resp(dut, conn, SIGMA_ERROR,
13515 "errorCode,Channel not found");
13516 return 0;
13517 }
13518 freq = atoi(pos + 6);
13519 chan = freq_to_channel(freq);
13520
13521 pos = strstr(buf, "\nssid=");
13522 if (!pos) {
13523 send_resp(dut, conn, SIGMA_ERROR,
13524 "errorCode,SSID not found");
13525 return 0;
13526 }
13527 ssid = pos + 6;
13528 pos = strchr(ssid, '\n');
13529 if (pos)
13530 *pos = '\0';
13531 snprintf(resp, sizeof(resp), "ssid,%s,bsschannel,%d", ssid, chan);
13532 send_resp(dut, conn, SIGMA_COMPLETE, resp);
13533 return 0;
13534}
13535
13536
Jouni Malinenf7222712019-06-13 01:50:21 +030013537static enum sigma_cmd_result cmd_sta_set_systime(struct sigma_dut *dut,
13538 struct sigma_conn *conn,
13539 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013540{
13541#ifdef __linux__
13542 struct timeval tv;
13543 struct tm tm;
13544 time_t t;
13545 const char *val;
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053013546 int v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013547
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013548 wpa_command(get_station_ifname(dut), "PMKSA_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013549
13550 memset(&tm, 0, sizeof(tm));
13551 val = get_param(cmd, "seconds");
13552 if (val)
13553 tm.tm_sec = atoi(val);
13554 val = get_param(cmd, "minutes");
13555 if (val)
13556 tm.tm_min = atoi(val);
13557 val = get_param(cmd, "hours");
13558 if (val)
13559 tm.tm_hour = atoi(val);
13560 val = get_param(cmd, "date");
13561 if (val)
13562 tm.tm_mday = atoi(val);
13563 val = get_param(cmd, "month");
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053013564 if (val) {
13565 v = atoi(val);
13566 if (v < 1 || v > 12) {
13567 send_resp(dut, conn, SIGMA_INVALID,
13568 "errorCode,Invalid month");
13569 return 0;
13570 }
13571 tm.tm_mon = v - 1;
13572 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013573 val = get_param(cmd, "year");
13574 if (val) {
13575 int year = atoi(val);
13576#ifdef ANDROID
13577 if (year > 2035)
13578 year = 2035; /* years beyond 2035 not supported */
13579#endif /* ANDROID */
13580 tm.tm_year = year - 1900;
13581 }
13582 t = mktime(&tm);
13583 if (t == (time_t) -1) {
13584 send_resp(dut, conn, SIGMA_ERROR,
13585 "errorCode,Invalid date or time");
13586 return 0;
13587 }
13588
13589 memset(&tv, 0, sizeof(tv));
13590 tv.tv_sec = t;
13591
13592 if (settimeofday(&tv, NULL) < 0) {
13593 sigma_dut_print(dut, DUT_MSG_INFO, "settimeofday failed: %s",
13594 strerror(errno));
13595 send_resp(dut, conn, SIGMA_ERROR,
13596 "errorCode,Failed to set time");
13597 return 0;
13598 }
13599
13600 return 1;
13601#endif /* __linux__ */
13602
13603 return -1;
13604}
13605
13606
Jouni Malinenf7222712019-06-13 01:50:21 +030013607static enum sigma_cmd_result cmd_sta_osu(struct sigma_dut *dut,
13608 struct sigma_conn *conn,
13609 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013610{
13611 const char *intf = get_param(cmd, "Interface");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013612 const char *name, *osu_ssid, *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013613 int prod_ess_assoc = 1;
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013614 char buf[300], bssid[100], ssid[100];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013615 int res;
13616 struct wpa_ctrl *ctrl;
13617
13618 name = get_param(cmd, "osuFriendlyName");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013619 osu_ssid = get_param(cmd, "osu_ssid");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013620
13621 val = get_param(cmd, "ProdESSAssoc");
13622 if (val)
13623 prod_ess_assoc = atoi(val);
13624
13625 kill_dhcp_client(dut, intf);
13626 if (start_dhcp_client(dut, intf) < 0)
13627 return -2;
13628
13629 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger OSU");
13630 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
13631 res = snprintf(buf, sizeof(buf),
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013632 "%s %s%s%s %s%s%s signup osu-ca.pem",
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013633 prod_ess_assoc ? "" : "-N",
13634 name ? "-O'" : "", name ? name : "",
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013635 name ? "'" : "",
13636 osu_ssid ? "-o'" : "", osu_ssid ? osu_ssid : "",
13637 osu_ssid ? "'" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013638
Kanchanapally, Vidyullatha12b66762015-12-31 16:46:42 +053013639 hs2_set_policy(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013640 if (run_hs20_osu(dut, buf) < 0) {
13641 FILE *f;
13642
13643 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to complete OSU");
13644
13645 f = fopen("hs20-osu-client.res", "r");
13646 if (f) {
13647 char resp[400], res[300], *pos;
13648 if (!fgets(res, sizeof(res), f))
13649 res[0] = '\0';
13650 pos = strchr(res, '\n');
13651 if (pos)
13652 *pos = '\0';
13653 fclose(f);
13654 sigma_dut_summary(dut, "hs20-osu-client provisioning failed: %s",
13655 res);
13656 snprintf(resp, sizeof(resp), "notify-send '%s'", res);
13657 if (system(resp) != 0) {
13658 }
13659 snprintf(resp, sizeof(resp),
13660 "SSID,,BSSID,,failureReason,%s", res);
13661 send_resp(dut, conn, SIGMA_COMPLETE, resp);
13662 return 0;
13663 }
13664
13665 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
13666 return 0;
13667 }
13668
13669 if (!prod_ess_assoc)
13670 goto report;
13671
13672 ctrl = open_wpa_mon(intf);
13673 if (ctrl == NULL) {
13674 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
13675 "wpa_supplicant monitor connection");
13676 return -1;
13677 }
13678
13679 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
13680 buf, sizeof(buf));
13681
13682 wpa_ctrl_detach(ctrl);
13683 wpa_ctrl_close(ctrl);
13684
13685 if (res < 0) {
13686 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to connect to "
13687 "network after OSU");
13688 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
13689 return 0;
13690 }
13691
13692report:
13693 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
13694 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
13695 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get BSSID/SSID");
13696 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
13697 return 0;
13698 }
13699
13700 snprintf(buf, sizeof(buf), "SSID,%s,BSSID,%s", ssid, bssid);
13701 send_resp(dut, conn, SIGMA_COMPLETE, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013702 return 0;
13703}
13704
13705
Jouni Malinenf7222712019-06-13 01:50:21 +030013706static enum sigma_cmd_result cmd_sta_policy_update(struct sigma_dut *dut,
13707 struct sigma_conn *conn,
13708 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013709{
13710 const char *val;
13711 int timeout = 120;
13712
13713 val = get_param(cmd, "PolicyUpdate");
13714 if (val == NULL || atoi(val) == 0)
13715 return 1; /* No operation requested */
13716
13717 val = get_param(cmd, "Timeout");
13718 if (val)
13719 timeout = atoi(val);
13720
13721 if (timeout) {
13722 /* TODO: time out the command and return
13723 * PolicyUpdateStatus,TIMEOUT if needed. */
13724 }
13725
13726 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger policy update");
13727 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
13728 if (run_hs20_osu(dut, "pol_upd fqdn=wi-fi.org") < 0) {
13729 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,FAIL");
13730 return 0;
13731 }
13732
13733 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,SUCCESS");
13734 return 0;
13735}
13736
13737
Jouni Malinenf7222712019-06-13 01:50:21 +030013738static enum sigma_cmd_result cmd_sta_er_config(struct sigma_dut *dut,
13739 struct sigma_conn *conn,
13740 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013741{
13742 struct wpa_ctrl *ctrl;
13743 const char *intf = get_param(cmd, "Interface");
13744 const char *bssid = get_param(cmd, "Bssid");
13745 const char *ssid = get_param(cmd, "SSID");
13746 const char *security = get_param(cmd, "Security");
13747 const char *passphrase = get_param(cmd, "Passphrase");
13748 const char *pin = get_param(cmd, "PIN");
13749 char buf[1000];
13750 char ssid_hex[200], passphrase_hex[200];
13751 const char *keymgmt, *cipher;
13752
13753 if (intf == NULL)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013754 intf = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013755
13756 if (!bssid) {
13757 send_resp(dut, conn, SIGMA_ERROR,
13758 "ErrorCode,Missing Bssid argument");
13759 return 0;
13760 }
13761
13762 if (!ssid) {
13763 send_resp(dut, conn, SIGMA_ERROR,
13764 "ErrorCode,Missing SSID argument");
13765 return 0;
13766 }
13767
13768 if (!security) {
13769 send_resp(dut, conn, SIGMA_ERROR,
13770 "ErrorCode,Missing Security argument");
13771 return 0;
13772 }
13773
13774 if (!passphrase) {
13775 send_resp(dut, conn, SIGMA_ERROR,
13776 "ErrorCode,Missing Passphrase argument");
13777 return 0;
13778 }
13779
13780 if (!pin) {
13781 send_resp(dut, conn, SIGMA_ERROR,
13782 "ErrorCode,Missing PIN argument");
13783 return 0;
13784 }
13785
vamsi krishna8c9c1562017-05-12 15:51:46 +053013786 if (2 * strlen(ssid) >= sizeof(ssid_hex) ||
13787 2 * strlen(passphrase) >= sizeof(passphrase_hex)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013788 send_resp(dut, conn, SIGMA_ERROR,
13789 "ErrorCode,Too long SSID/passphrase");
13790 return 0;
13791 }
13792
13793 ctrl = open_wpa_mon(intf);
13794 if (ctrl == NULL) {
13795 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
13796 "wpa_supplicant monitor connection");
13797 return -2;
13798 }
13799
13800 if (strcasecmp(security, "wpa2-psk") == 0) {
13801 keymgmt = "WPA2PSK";
13802 cipher = "CCMP";
13803 } else {
13804 wpa_ctrl_detach(ctrl);
13805 wpa_ctrl_close(ctrl);
13806 send_resp(dut, conn, SIGMA_ERROR,
13807 "ErrorCode,Unsupported Security value");
13808 return 0;
13809 }
13810
13811 ascii2hexstr(ssid, ssid_hex);
13812 ascii2hexstr(passphrase, passphrase_hex);
13813 snprintf(buf, sizeof(buf), "WPS_REG %s %s %s %s %s %s",
13814 bssid, pin, ssid_hex, keymgmt, cipher, passphrase_hex);
13815
13816 if (wpa_command(intf, buf) < 0) {
13817 wpa_ctrl_detach(ctrl);
13818 wpa_ctrl_close(ctrl);
13819 send_resp(dut, conn, SIGMA_ERROR,
13820 "ErrorCode,Failed to start registrar");
13821 return 0;
13822 }
13823
13824 snprintf(dut->er_oper_bssid, sizeof(dut->er_oper_bssid), "%s", bssid);
13825 dut->er_oper_performed = 1;
13826
13827 return wps_connection_event(dut, conn, ctrl, intf, 0);
13828}
13829
13830
Jouni Malinenf7222712019-06-13 01:50:21 +030013831static enum sigma_cmd_result
13832cmd_sta_wps_connect_pw_token(struct sigma_dut *dut, struct sigma_conn *conn,
13833 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013834{
13835 struct wpa_ctrl *ctrl;
13836 const char *intf = get_param(cmd, "Interface");
13837 const char *bssid = get_param(cmd, "Bssid");
13838 char buf[100];
13839
13840 if (!bssid) {
13841 send_resp(dut, conn, SIGMA_ERROR,
13842 "ErrorCode,Missing Bssid argument");
13843 return 0;
13844 }
13845
13846 ctrl = open_wpa_mon(intf);
13847 if (ctrl == NULL) {
13848 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
13849 "wpa_supplicant monitor connection");
13850 return -2;
13851 }
13852
13853 snprintf(buf, sizeof(buf), "WPS_NFC %s", bssid);
13854
13855 if (wpa_command(intf, buf) < 0) {
13856 wpa_ctrl_detach(ctrl);
13857 wpa_ctrl_close(ctrl);
13858 send_resp(dut, conn, SIGMA_ERROR,
13859 "ErrorCode,Failed to start registrar");
13860 return 0;
13861 }
13862
13863 return wps_connection_event(dut, conn, ctrl, intf, 0);
13864}
13865
13866
Jouni Malinenf7222712019-06-13 01:50:21 +030013867static enum sigma_cmd_result cmd_start_wps_registration(struct sigma_dut *dut,
13868 struct sigma_conn *conn,
13869 struct sigma_cmd *cmd)
vamsi krishna9b144002017-09-20 13:28:13 +053013870{
13871 struct wpa_ctrl *ctrl;
13872 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020013873 const char *network_mode = get_param(cmd, "network_mode");
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020013874 const char *config_method = get_param(cmd, "WPSConfigMethod");
13875 const char *role;
vamsi krishna9b144002017-09-20 13:28:13 +053013876 int res;
13877 char buf[256];
13878 const char *events[] = {
13879 "CTRL-EVENT-CONNECTED",
13880 "WPS-OVERLAP-DETECTED",
13881 "WPS-TIMEOUT",
13882 "WPS-FAIL",
13883 NULL
13884 };
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020013885 int id = 0;
vamsi krishna9b144002017-09-20 13:28:13 +053013886
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020013887 /* 60G WPS tests do not pass Interface parameter */
13888 if (!intf)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013889 intf = get_main_ifname(dut);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020013890
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020013891 if (dut->mode == SIGMA_MODE_AP)
13892 return ap_wps_registration(dut, conn, cmd);
13893
13894 if (config_method) {
13895 /* WFA_CS_WPS_PIN_KEYPAD mode is set when using the
13896 * sta_wps_enter_pin before calling start_wps_registration. */
13897 if (strcasecmp(config_method, "PBC") == 0)
13898 dut->wps_method = WFA_CS_WPS_PBC;
13899 }
13900 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
13901 send_resp(dut, conn, SIGMA_ERROR,
13902 "ErrorCode,WPS parameters not yet set");
13903 return STATUS_SENT;
13904 }
13905
13906 /* Make sure WPS is enabled (also for STA mode) */
13907 dut->wps_disable = 0;
13908
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020013909 if (dut->band == WPS_BAND_60G && network_mode &&
13910 strcasecmp(network_mode, "PBSS") == 0) {
13911 sigma_dut_print(dut, DUT_MSG_DEBUG,
13912 "Set PBSS network mode, network id %d", id);
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013913 if (set_network(get_station_ifname(dut), id, "pbss", "1") < 0)
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020013914 return -2;
13915 }
13916
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020013917 if (dut->force_rsn_ie) {
13918 sigma_dut_print(dut, DUT_MSG_DEBUG, "Force RSN_IE: %d",
13919 dut->force_rsn_ie);
13920 if (sta_60g_force_rsn_ie(dut, dut->force_rsn_ie) < 0) {
13921 sigma_dut_print(dut, DUT_MSG_INFO,
13922 "Failed to force RSN_IE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020013923 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020013924 }
13925 }
13926
vamsi krishna9b144002017-09-20 13:28:13 +053013927 ctrl = open_wpa_mon(intf);
13928 if (!ctrl) {
13929 sigma_dut_print(dut, DUT_MSG_ERROR,
13930 "Failed to open wpa_supplicant monitor connection");
13931 return -2;
13932 }
13933
13934 role = get_param(cmd, "WpsRole");
13935 if (!role) {
13936 send_resp(dut, conn, SIGMA_INVALID,
13937 "ErrorCode,WpsRole not provided");
13938 goto fail;
13939 }
13940
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020013941 if (strcasecmp(role, "Enrollee") != 0) {
13942 /* Registrar role for STA not supported */
13943 send_resp(dut, conn, SIGMA_ERROR,
13944 "ErrorCode,Unsupported WpsRole value");
13945 goto fail;
13946 }
13947
13948 if (is_60g_sigma_dut(dut)) {
13949 if (dut->wps_method == WFA_CS_WPS_PBC)
13950 snprintf(buf, sizeof(buf), "WPS_PBC");
13951 else /* WFA_CS_WPS_PIN_KEYPAD */
13952 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
13953 dut->wps_pin);
13954 if (wpa_command(intf, buf) < 0) {
13955 send_resp(dut, conn, SIGMA_ERROR,
13956 "ErrorCode,Failed to start WPS");
vamsi krishna9b144002017-09-20 13:28:13 +053013957 goto fail;
13958 }
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020013959 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
13960 if (res < 0) {
13961 send_resp(dut, conn, SIGMA_ERROR,
13962 "ErrorCode,WPS connection did not complete");
13963 goto fail;
13964 }
13965 if (strstr(buf, "WPS-TIMEOUT")) {
13966 send_resp(dut, conn, SIGMA_COMPLETE, "WpsState,NoPeer");
13967 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
13968 send_resp(dut, conn, SIGMA_COMPLETE,
13969 "WpsState,OverlapSession");
13970 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
13971 send_resp(dut, conn, SIGMA_COMPLETE,
13972 "WpsState,Successful");
13973 } else {
13974 send_resp(dut, conn, SIGMA_COMPLETE,
13975 "WpsState,Failure");
13976 }
13977 } else {
13978 if (dut->wps_method == WFA_CS_WPS_PBC) {
vamsi krishna9b144002017-09-20 13:28:13 +053013979 if (wpa_command(intf, "WPS_PBC") < 0) {
13980 send_resp(dut, conn, SIGMA_ERROR,
13981 "ErrorCode,Failed to enable PBC");
13982 goto fail;
13983 }
13984 } else {
13985 /* TODO: PIN method */
13986 send_resp(dut, conn, SIGMA_ERROR,
13987 "ErrorCode,Unsupported WpsConfigMethod value");
13988 goto fail;
13989 }
13990 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
13991 if (res < 0) {
13992 send_resp(dut, conn, SIGMA_ERROR,
13993 "ErrorCode,WPS connection did not complete");
13994 goto fail;
13995 }
13996 if (strstr(buf, "WPS-TIMEOUT")) {
13997 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,NoPeer");
13998 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
13999 send_resp(dut, conn, SIGMA_ERROR,
14000 "ErrorCode,OverlapSession");
14001 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
14002 send_resp(dut, conn, SIGMA_COMPLETE, "Successful");
14003 } else {
14004 send_resp(dut, conn, SIGMA_ERROR,
14005 "ErrorCode,WPS operation failed");
14006 }
vamsi krishna9b144002017-09-20 13:28:13 +053014007 }
14008
14009fail:
14010 wpa_ctrl_detach(ctrl);
14011 wpa_ctrl_close(ctrl);
14012 return 0;
14013}
14014
14015
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014016static int req_intf(struct sigma_cmd *cmd)
14017{
14018 return get_param(cmd, "interface") == NULL ? -1 : 0;
14019}
14020
14021
14022void sta_register_cmds(void)
14023{
14024 sigma_dut_reg_cmd("sta_get_ip_config", req_intf,
14025 cmd_sta_get_ip_config);
14026 sigma_dut_reg_cmd("sta_set_ip_config", req_intf,
14027 cmd_sta_set_ip_config);
14028 sigma_dut_reg_cmd("sta_get_info", req_intf, cmd_sta_get_info);
14029 sigma_dut_reg_cmd("sta_get_mac_address", req_intf,
14030 cmd_sta_get_mac_address);
14031 sigma_dut_reg_cmd("sta_is_connected", req_intf, cmd_sta_is_connected);
14032 sigma_dut_reg_cmd("sta_verify_ip_connection", req_intf,
14033 cmd_sta_verify_ip_connection);
14034 sigma_dut_reg_cmd("sta_get_bssid", req_intf, cmd_sta_get_bssid);
14035 sigma_dut_reg_cmd("sta_set_encryption", req_intf,
14036 cmd_sta_set_encryption);
14037 sigma_dut_reg_cmd("sta_set_psk", req_intf, cmd_sta_set_psk);
14038 sigma_dut_reg_cmd("sta_set_eaptls", req_intf, cmd_sta_set_eaptls);
14039 sigma_dut_reg_cmd("sta_set_eapttls", req_intf, cmd_sta_set_eapttls);
14040 sigma_dut_reg_cmd("sta_set_eapsim", req_intf, cmd_sta_set_eapsim);
14041 sigma_dut_reg_cmd("sta_set_peap", req_intf, cmd_sta_set_peap);
14042 sigma_dut_reg_cmd("sta_set_eapfast", req_intf, cmd_sta_set_eapfast);
14043 sigma_dut_reg_cmd("sta_set_eapaka", req_intf, cmd_sta_set_eapaka);
14044 sigma_dut_reg_cmd("sta_set_eapakaprime", req_intf,
14045 cmd_sta_set_eapakaprime);
14046 sigma_dut_reg_cmd("sta_set_security", req_intf, cmd_sta_set_security);
14047 sigma_dut_reg_cmd("sta_set_uapsd", req_intf, cmd_sta_set_uapsd);
14048 /* TODO: sta_set_ibss */
14049 /* TODO: sta_set_mode */
14050 sigma_dut_reg_cmd("sta_set_wmm", req_intf, cmd_sta_set_wmm);
14051 sigma_dut_reg_cmd("sta_associate", req_intf, cmd_sta_associate);
14052 /* TODO: sta_up_load */
14053 sigma_dut_reg_cmd("sta_preset_testparameters", req_intf,
14054 cmd_sta_preset_testparameters);
14055 /* TODO: sta_set_system */
14056 sigma_dut_reg_cmd("sta_set_11n", req_intf, cmd_sta_set_11n);
14057 /* TODO: sta_set_rifs_test */
14058 sigma_dut_reg_cmd("sta_set_wireless", req_intf, cmd_sta_set_wireless);
14059 sigma_dut_reg_cmd("sta_send_addba", req_intf, cmd_sta_send_addba);
14060 /* TODO: sta_send_coexist_mgmt */
14061 sigma_dut_reg_cmd("sta_disconnect", req_intf, cmd_sta_disconnect);
14062 sigma_dut_reg_cmd("sta_reassoc", req_intf, cmd_sta_reassoc);
14063 sigma_dut_reg_cmd("sta_reassociate", req_intf, cmd_sta_reassoc);
14064 sigma_dut_reg_cmd("sta_reset_default", req_intf,
14065 cmd_sta_reset_default);
14066 sigma_dut_reg_cmd("sta_send_frame", req_intf, cmd_sta_send_frame);
14067 sigma_dut_reg_cmd("sta_set_macaddr", req_intf, cmd_sta_set_macaddr);
14068 sigma_dut_reg_cmd("sta_set_rfeature", req_intf, cmd_sta_set_rfeature);
14069 sigma_dut_reg_cmd("sta_set_radio", req_intf, cmd_sta_set_radio);
14070 sigma_dut_reg_cmd("sta_set_pwrsave", req_intf, cmd_sta_set_pwrsave);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020014071 sigma_dut_reg_cmd("sta_set_power_save", req_intf, cmd_sta_set_pwrsave);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014072 sigma_dut_reg_cmd("sta_bssid_pool", req_intf, cmd_sta_bssid_pool);
14073 sigma_dut_reg_cmd("sta_reset_parm", req_intf, cmd_sta_reset_parm);
14074 sigma_dut_reg_cmd("sta_get_key", req_intf, cmd_sta_get_key);
14075 sigma_dut_reg_cmd("sta_hs2_associate", req_intf,
14076 cmd_sta_hs2_associate);
Jouni Malinenb639f1c2018-09-13 02:39:46 +030014077 sigma_dut_reg_cmd("sta_hs2_venue_info", req_intf,
14078 cmd_sta_hs2_venue_info);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014079 sigma_dut_reg_cmd("sta_add_credential", req_intf,
14080 cmd_sta_add_credential);
14081 sigma_dut_reg_cmd("sta_scan", req_intf, cmd_sta_scan);
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020014082 sigma_dut_reg_cmd("sta_scan_bss", req_intf, cmd_sta_scan_bss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014083 sigma_dut_reg_cmd("sta_set_systime", NULL, cmd_sta_set_systime);
14084 sigma_dut_reg_cmd("sta_osu", req_intf, cmd_sta_osu);
14085 sigma_dut_reg_cmd("sta_policy_update", req_intf, cmd_sta_policy_update);
14086 sigma_dut_reg_cmd("sta_er_config", NULL, cmd_sta_er_config);
14087 sigma_dut_reg_cmd("sta_wps_connect_pw_token", req_intf,
14088 cmd_sta_wps_connect_pw_token);
Jouni Malinen82905202018-04-29 17:20:10 +030014089 sigma_dut_reg_cmd("sta_exec_action", NULL, cmd_sta_exec_action);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014090 sigma_dut_reg_cmd("sta_get_events", req_intf, cmd_sta_get_events);
14091 sigma_dut_reg_cmd("sta_get_parameter", req_intf, cmd_sta_get_parameter);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020014092 sigma_dut_reg_cmd("start_wps_registration", NULL,
vamsi krishna9b144002017-09-20 13:28:13 +053014093 cmd_start_wps_registration);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014094}