blob: 949db7f6ceb801ae7ac829cea271317732e14da0 [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");
Veerendranath Jakkamc1f71b62021-01-23 03:09:51 +05302099 if (val)
2100 dut->beacon_prot = atoi(val);
2101 if (dut->beacon_prot && set_network(ifname, id, "beacon_prot", "1") < 0)
Jouni Malinen0165c7f2020-03-26 11:51:58 +02002102 return ERROR_SEND_STATUS;
2103
Veerendranath Jakkam54fd51c2020-12-21 01:36:04 +05302104 if (dut->ocvc && set_network(ifname, id, "ocv", "1") < 0)
2105 return ERROR_SEND_STATUS;
2106
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002107 return id;
2108}
2109
2110
Jouni Malinenf7222712019-06-13 01:50:21 +03002111static enum sigma_cmd_result cmd_sta_set_psk(struct sigma_dut *dut,
2112 struct sigma_conn *conn,
2113 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002114{
2115 const char *intf = get_param(cmd, "Interface");
Jouni Malinen992a81e2017-08-22 13:57:47 +03002116 const char *type = get_param(cmd, "Type");
Jouni Malinen1287cd72018-01-04 17:08:01 +02002117 const char *pmf = get_param(cmd, "PMF");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002118 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinene4fde732019-03-25 22:29:37 +02002119 const char *akm = get_param(cmd, "AKMSuiteType");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002120 const char *ifname, *val, *alg;
2121 int id;
Jouni Malinen4b3769d2019-10-10 16:20:29 +03002122 char buf[50];
Jouni Malinen11e55212019-11-22 21:46:59 +02002123 int sae_pwe = -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002124
2125 if (intf == NULL)
2126 return -1;
2127
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002128 if (strcmp(intf, get_main_ifname(dut)) == 0)
2129 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002130 else
2131 ifname = intf;
2132
2133 id = set_wpa_common(dut, conn, ifname, cmd);
2134 if (id < 0)
2135 return id;
2136
2137 val = get_param(cmd, "keyMgmtType");
2138 alg = get_param(cmd, "micAlg");
2139
Jouni Malinen992a81e2017-08-22 13:57:47 +03002140 if (type && strcasecmp(type, "SAE") == 0) {
Jouni Malinene4fde732019-03-25 22:29:37 +02002141 if (!akm && val && strcasecmp(val, "wpa2-ft") == 0) {
Jouni Malinen992a81e2017-08-22 13:57:47 +03002142 if (set_network(ifname, id, "key_mgmt", "FT-SAE") < 0)
2143 return -2;
Jouni Malinene4fde732019-03-25 22:29:37 +02002144 } else if (!akm) {
Jouni Malinen992a81e2017-08-22 13:57:47 +03002145 if (set_network(ifname, id, "key_mgmt", "SAE") < 0)
2146 return -2;
2147 }
2148 if (wpa_command(ifname, "SET sae_groups ") != 0) {
2149 sigma_dut_print(dut, DUT_MSG_ERROR,
2150 "Failed to clear sae_groups to default");
2151 return -2;
2152 }
Jouni Malinen1287cd72018-01-04 17:08:01 +02002153 if (!pmf) {
2154 dut->sta_pmf = STA_PMF_REQUIRED;
2155 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2156 return -2;
2157 }
Jouni Malinen0ab50f42017-08-31 01:34:59 +03002158 } else if (type && strcasecmp(type, "PSK-SAE") == 0) {
2159 if (val && strcasecmp(val, "wpa2-ft") == 0) {
2160 if (set_network(ifname, id, "key_mgmt",
2161 "FT-SAE FT-PSK") < 0)
2162 return -2;
Jouni Malinen3b73d872019-06-12 03:13:25 +03002163 } else if (!akm) {
Jouni Malinen0ab50f42017-08-31 01:34:59 +03002164 if (set_network(ifname, id, "key_mgmt",
2165 "SAE WPA-PSK") < 0)
2166 return -2;
2167 }
2168 if (wpa_command(ifname, "SET sae_groups ") != 0) {
2169 sigma_dut_print(dut, DUT_MSG_ERROR,
2170 "Failed to clear sae_groups to default");
2171 return -2;
2172 }
Jouni Malinen1287cd72018-01-04 17:08:01 +02002173 if (!pmf) {
2174 dut->sta_pmf = STA_PMF_OPTIONAL;
2175 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2176 return -2;
2177 }
Jouni Malinen992a81e2017-08-22 13:57:47 +03002178 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002179 if (set_network(ifname, id, "key_mgmt", "WPA-PSK-SHA256") < 0)
2180 return -2;
2181 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
2182 if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0)
2183 return -2;
Ashwini Patil6dbf7b02017-03-20 13:42:11 +05302184 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
2185 if (set_network(ifname, id, "key_mgmt", "FT-PSK") < 0)
2186 return -2;
Jouni Malinen3b73d872019-06-12 03:13:25 +03002187 } else if (!akm &&
2188 ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
2189 dut->sta_pmf == STA_PMF_REQUIRED)) {
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 && dut->sta_pmf == STA_PMF_OPTIONAL) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002194 if (set_network(ifname, id, "key_mgmt",
2195 "WPA-PSK WPA-PSK-SHA256") < 0)
2196 return -2;
Jouni Malinen77ff3f02019-03-28 03:45:40 +02002197 } else if (!akm) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002198 if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0)
2199 return -2;
2200 }
2201
2202 val = get_param(cmd, "passPhrase");
2203 if (val == NULL)
2204 return -1;
Jouni Malinen2126f422017-10-11 23:24:33 +03002205 if (type && strcasecmp(type, "SAE") == 0) {
2206 if (set_network_quoted(ifname, id, "sae_password", val) < 0)
2207 return -2;
2208 } else {
2209 if (set_network_quoted(ifname, id, "psk", val) < 0)
2210 return -2;
2211 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002212
Jouni Malinen78d10c42019-03-25 22:34:32 +02002213 val = get_param(cmd, "PasswordId");
2214 if (val && set_network_quoted(ifname, id, "sae_password_id", val) < 0)
2215 return ERROR_SEND_STATUS;
2216
Jouni Malinen992a81e2017-08-22 13:57:47 +03002217 val = get_param(cmd, "ECGroupID");
2218 if (val) {
Jouni Malinenb54f0df2019-12-12 01:57:29 +02002219 snprintf(buf, sizeof(buf), "SET sae_groups %s", val);
Jouni Malinen992a81e2017-08-22 13:57:47 +03002220 if (wpa_command(ifname, buf) != 0) {
2221 sigma_dut_print(dut, DUT_MSG_ERROR,
2222 "Failed to clear sae_groups");
2223 return -2;
2224 }
2225 }
2226
Jouni Malinen68143132017-09-02 02:34:08 +03002227 val = get_param(cmd, "InvalidSAEElement");
2228 if (val) {
2229 free(dut->sae_commit_override);
2230 dut->sae_commit_override = strdup(val);
2231 }
2232
Jouni Malinen4b3769d2019-10-10 16:20:29 +03002233 val = get_param(cmd, "PMKID_Include");
2234 if (val) {
2235 snprintf(buf, sizeof(buf), "SET sae_pmkid_in_assoc %d",
2236 get_enable_disable(val));
2237 wpa_command(intf, buf);
2238 }
2239
Jouni Malineneeb43d32019-12-06 17:40:07 +02002240 val = get_param(cmd, "IgnoreH2E_RSNXE_BSSMemSel");
2241 if (val) {
2242 snprintf(buf, sizeof(buf), "SET ignore_sae_h2e_only %d",
2243 get_enable_disable(val));
2244 wpa_command(intf, buf);
2245 }
2246
Jouni Malinenf2348d22019-12-07 11:52:55 +02002247 val = get_param(cmd, "ECGroupID_RGE");
2248 if (val) {
2249 snprintf(buf, sizeof(buf), "SET extra_sae_rejected_groups %s",
2250 val);
2251 wpa_command(intf, buf);
2252 }
2253
Jouni Malinen99e55022019-12-07 13:59:41 +02002254 val = get_param(cmd, "RSNXE_Content");
2255 if (val) {
2256 const char *param;
2257
2258 if (strncasecmp(val, "AssocReq:", 9) == 0) {
2259 val += 9;
2260 param = "rsnxe_override_assoc";
2261 } else if (strncasecmp(val, "EapolM2:", 8) == 0) {
2262 val += 8;
2263 param = "rsnxe_override_eapol";
2264 } else {
2265 send_resp(dut, conn, SIGMA_ERROR,
2266 "errorCode,Unsupported RSNXE_Content value");
2267 return STATUS_SENT_ERROR;
2268 }
2269 snprintf(buf, sizeof(buf), "SET %s %s", param, val);
2270 wpa_command(intf, buf);
2271 }
2272
Jouni Malinen11e55212019-11-22 21:46:59 +02002273 val = get_param(cmd, "sae_pwe");
2274 if (val) {
2275 if (strcasecmp(val, "h2e") == 0) {
2276 dut->sae_pwe = SAE_PWE_H2E;
Jouni Malinen7244a412019-12-07 11:54:10 +02002277 } else if (strcasecmp(val, "loop") == 0 ||
2278 strcasecmp(val, "looping") == 0) {
Jouni Malinen11e55212019-11-22 21:46:59 +02002279 dut->sae_pwe = SAE_PWE_LOOP;
2280 } else {
2281 send_resp(dut, conn, SIGMA_ERROR,
2282 "errorCode,Unsupported sae_pwe value");
2283 return STATUS_SENT_ERROR;
2284 }
2285 }
Vinita S. Maloo6d7454f2020-04-02 15:03:26 +05302286
2287 val = get_param(cmd, "Clear_RSNXE");
2288 if (val && strcmp(val, "1") == 0 &&
2289 (wpa_command(intf, "SET rsnxe_override_assoc ") ||
2290 wpa_command(intf, "SET rsnxe_override_eapol "))) {
2291 send_resp(dut, conn, SIGMA_ERROR,
2292 "errorCode,Failed to clear RSNXE");
Jouni Malinenb11498c2020-08-03 11:05:53 +03002293 return STATUS_SENT_ERROR;
Vinita S. Maloo6d7454f2020-04-02 15:03:26 +05302294 }
2295
Jouni Malinenc0078772020-03-04 21:23:16 +02002296 if (dut->sae_pwe == SAE_PWE_LOOP && get_param(cmd, "PasswordId"))
2297 sae_pwe = 3;
2298 else if (dut->sae_pwe == SAE_PWE_LOOP)
Jouni Malinen11e55212019-11-22 21:46:59 +02002299 sae_pwe = 0;
2300 else if (dut->sae_pwe == SAE_PWE_H2E)
2301 sae_pwe = 1;
2302 else if (dut->sae_h2e_default)
2303 sae_pwe = 2;
2304 snprintf(buf, sizeof(buf), "SET sae_pwe %d", sae_pwe);
2305 if (sae_pwe >= 0 && wpa_command(ifname, buf) != 0)
2306 return ERROR_SEND_STATUS;
2307
Veerendranath Jakkam0316be12020-06-23 20:11:41 +05302308 val = get_param(cmd, "sae_pk");
2309 if (val && strcmp(val, "0") == 0 &&
2310 set_network(ifname, id, "sae_pk", "2") < 0)
2311 return ERROR_SEND_STATUS;
2312
Veerendranath Jakkama9177042020-08-10 00:14:03 +05302313 val = get_param(cmd, "sae_pk_only");
2314 if (val && strcmp(val, "1") == 0 &&
2315 set_network(ifname, id, "sae_pk", "1") < 0)
2316 return ERROR_SEND_STATUS;
2317
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002318 if (dut->program == PROGRAM_60GHZ && network_mode &&
2319 strcasecmp(network_mode, "PBSS") == 0 &&
2320 set_network(ifname, id, "pbss", "1") < 0)
2321 return -2;
2322
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002323 return 1;
2324}
2325
2326
Jouni Malinen8ac93452019-08-14 15:19:13 +03002327static enum sigma_cmd_result set_trust_root_system(struct sigma_dut *dut,
2328 struct sigma_conn *conn,
2329 const char *ifname, int id)
2330{
2331 char buf[200];
2332
2333 snprintf(buf, sizeof(buf), "%s/certs", sigma_cert_path);
2334 if (!file_exists(buf))
2335 strlcpy(buf, "/system/etc/security/cacerts", sizeof(buf));
2336 if (!file_exists(buf))
2337 strlcpy(buf, "/etc/ssl/certs", sizeof(buf));
2338 if (!file_exists(buf)) {
2339 char msg[300];
2340
2341 snprintf(msg, sizeof(msg),
2342 "ErrorCode,trustedRootCA system store (%s) not found",
2343 buf);
2344 send_resp(dut, conn, SIGMA_ERROR, msg);
2345 return STATUS_SENT_ERROR;
2346 }
2347
2348 if (set_network_quoted(ifname, id, "ca_path", buf) < 0)
2349 return ERROR_SEND_STATUS;
2350
2351 return SUCCESS_SEND_STATUS;
2352}
2353
2354
2355static enum sigma_cmd_result set_trust_root(struct sigma_dut *dut,
2356 struct sigma_conn *conn,
2357 const char *ifname, int id,
2358 const char *val)
2359{
2360 char buf[200];
2361#ifdef ANDROID
2362 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
2363 int length;
2364#endif /* ANDROID */
2365
2366 if (strcmp(val, "DEFAULT") == 0)
2367 return set_trust_root_system(dut, conn, ifname, id);
2368
2369#ifdef ANDROID
2370 snprintf(buf, sizeof(buf), "CACERT_%s", val);
2371 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
2372 if (length > 0) {
2373 sigma_dut_print(dut, DUT_MSG_INFO, "Use Android keystore [%s]",
2374 buf);
2375 snprintf(buf, sizeof(buf), "keystore://CACERT_%s", val);
2376 goto ca_cert_selected;
2377 }
2378#endif /* ANDROID */
2379
2380 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
2381#ifdef __linux__
2382 if (!file_exists(buf)) {
2383 char msg[300];
2384
2385 snprintf(msg, sizeof(msg),
2386 "ErrorCode,trustedRootCA file (%s) not found", buf);
2387 send_resp(dut, conn, SIGMA_ERROR, msg);
2388 return STATUS_SENT_ERROR;
2389 }
2390#endif /* __linux__ */
2391#ifdef ANDROID
2392ca_cert_selected:
2393#endif /* ANDROID */
2394 if (set_network_quoted(ifname, id, "ca_cert", buf) < 0)
2395 return ERROR_SEND_STATUS;
2396
2397 return SUCCESS_SEND_STATUS;
2398}
2399
2400
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002401static int set_eap_common(struct sigma_dut *dut, struct sigma_conn *conn,
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302402 const char *ifname, int username_identity,
2403 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002404{
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002405 const char *val, *alg, *akm, *trust_root, *domain, *domain_suffix;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002406 int id;
Jouni Malinen53264f62019-05-03 13:04:40 +03002407 char buf[200], buf2[300];
Jouni Malinen8179fee2019-03-28 03:19:47 +02002408 int erp = 0;
Jouni Malinen8ac93452019-08-14 15:19:13 +03002409 enum sigma_cmd_result res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002410
2411 id = set_wpa_common(dut, conn, ifname, cmd);
2412 if (id < 0)
2413 return id;
2414
2415 val = get_param(cmd, "keyMgmtType");
2416 alg = get_param(cmd, "micAlg");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302417 akm = get_param(cmd, "AKMSuiteType");
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002418 trust_root = get_param(cmd, "trustedRootCA");
2419 domain = get_param(cmd, "Domain");
2420 domain_suffix = get_param(cmd, "DomainSuffix");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002421
Jouni Malinenad395a22017-09-01 21:13:46 +03002422 if (val && strcasecmp(val, "SuiteB") == 0) {
2423 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SUITE-B-192") <
2424 0)
2425 return -2;
2426 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002427 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SHA256") < 0)
2428 return -2;
2429 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
2430 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
2431 return -2;
2432 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
2433 if (set_network(ifname, id, "key_mgmt", "FT-EAP") < 0)
2434 return -2;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002435 } else if (!akm &&
2436 ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
2437 dut->sta_pmf == STA_PMF_REQUIRED)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002438 if (set_network(ifname, id, "key_mgmt",
2439 "WPA-EAP WPA-EAP-SHA256") < 0)
2440 return -2;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302441 } else if (akm && atoi(akm) == 14) {
2442 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
2443 dut->sta_pmf == STA_PMF_REQUIRED) {
2444 if (set_network(ifname, id, "key_mgmt",
2445 "WPA-EAP-SHA256 FILS-SHA256") < 0)
2446 return -2;
2447 } else {
2448 if (set_network(ifname, id, "key_mgmt",
2449 "WPA-EAP FILS-SHA256") < 0)
2450 return -2;
2451 }
2452
Jouni Malinen8179fee2019-03-28 03:19:47 +02002453 erp = 1;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302454 } else if (akm && atoi(akm) == 15) {
2455 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
2456 dut->sta_pmf == STA_PMF_REQUIRED) {
2457 if (set_network(ifname, id, "key_mgmt",
2458 "WPA-EAP-SHA256 FILS-SHA384") < 0)
2459 return -2;
2460 } else {
2461 if (set_network(ifname, id, "key_mgmt",
2462 "WPA-EAP FILS-SHA384") < 0)
2463 return -2;
2464 }
2465
Jouni Malinen8179fee2019-03-28 03:19:47 +02002466 erp = 1;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002467 } else if (!akm && dut->sta_pmf == STA_PMF_OPTIONAL) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002468 if (set_network(ifname, id, "key_mgmt",
2469 "WPA-EAP WPA-EAP-SHA256") < 0)
2470 return -2;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002471 } else if (!akm) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002472 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
2473 return -2;
2474 }
2475
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002476 if (trust_root) {
2477 if (strcmp(trust_root, "DEFAULT") == 0 && !domain &&
2478 !domain_suffix) {
2479 send_resp(dut, conn, SIGMA_ERROR,
2480 "errorCode,trustRootCA DEFAULT used without specifying Domain or DomainSuffix");
2481 return STATUS_SENT_ERROR;
2482 }
2483 res = set_trust_root(dut, conn, ifname, id, trust_root);
Jouni Malinen8ac93452019-08-14 15:19:13 +03002484 if (res != SUCCESS_SEND_STATUS)
2485 return res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002486 }
2487
Jouni Malinen53264f62019-05-03 13:04:40 +03002488 val = get_param(cmd, "ServerCert");
2489 if (val) {
2490 FILE *f;
2491 char *result = NULL, *pos;
2492
2493 snprintf(buf, sizeof(buf), "%s/%s.sha256", sigma_cert_path,
2494 val);
2495 f = fopen(buf, "r");
2496 if (f) {
2497 result = fgets(buf, sizeof(buf), f);
2498 fclose(f);
2499 }
2500 if (!result) {
2501 snprintf(buf2, sizeof(buf2),
2502 "ErrorCode,ServerCert hash could not be read from %s",
2503 buf);
2504 send_resp(dut, conn, SIGMA_ERROR, buf2);
2505 return STATUS_SENT_ERROR;
2506 }
2507 pos = strchr(buf, '\n');
2508 if (pos)
2509 *pos = '\0';
Jouni Malinen0572a742020-10-08 13:53:25 +03002510 pos = strchr(buf, '\r');
2511 if (pos)
2512 *pos = '\0';
Jouni Malinen53264f62019-05-03 13:04:40 +03002513 snprintf(buf2, sizeof(buf2), "hash://server/sha256/%s", buf);
2514 if (set_network_quoted(ifname, id, "ca_cert", buf2) < 0)
2515 return ERROR_SEND_STATUS;
Jouni Malinen29108dc2019-06-13 23:42:11 +03002516
2517 snprintf(buf, sizeof(buf), "%s/%s.tod", sigma_cert_path, val);
2518 if (file_exists(buf)) {
2519 sigma_dut_print(dut, DUT_MSG_DEBUG,
2520 "TOD policy enabled for the configured ServerCert hash");
2521 dut->sta_tod_policy = 1;
2522 }
Jouni Malinen53264f62019-05-03 13:04:40 +03002523 }
2524
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002525 if (domain &&
2526 set_network_quoted(ifname, id, "domain_match", domain) < 0)
Jouni Malinen96f84b02019-05-03 12:32:56 +03002527 return ERROR_SEND_STATUS;
2528
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002529 if (domain_suffix &&
2530 set_network_quoted(ifname, id, "domain_suffix_match",
2531 domain_suffix) < 0)
Jouni Malinen96f84b02019-05-03 12:32:56 +03002532 return ERROR_SEND_STATUS;
2533
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302534 if (username_identity) {
2535 val = get_param(cmd, "username");
2536 if (val) {
2537 if (set_network_quoted(ifname, id, "identity", val) < 0)
2538 return -2;
2539 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002540
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302541 val = get_param(cmd, "password");
2542 if (val) {
2543 if (set_network_quoted(ifname, id, "password", val) < 0)
2544 return -2;
2545 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002546 }
2547
Jouni Malinen8179fee2019-03-28 03:19:47 +02002548 if (dut->akm_values &
2549 ((1 << AKM_FILS_SHA256) |
2550 (1 << AKM_FILS_SHA384) |
2551 (1 << AKM_FT_FILS_SHA256) |
2552 (1 << AKM_FT_FILS_SHA384)))
2553 erp = 1;
2554 if (erp && set_network(ifname, id, "erp", "1") < 0)
2555 return ERROR_SEND_STATUS;
2556
Jouni Malinen134fe3c2019-06-12 04:16:49 +03002557 dut->sta_associate_wait_connect = 1;
2558
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002559 return id;
2560}
2561
2562
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002563static int set_tls_cipher(const char *ifname, int id, const char *cipher)
2564{
2565 const char *val;
2566
2567 if (!cipher)
2568 return 0;
2569
2570 if (strcasecmp(cipher, "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384") == 0)
2571 val = "ECDHE-ECDSA-AES256-GCM-SHA384";
2572 else if (strcasecmp(cipher,
2573 "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
2574 val = "ECDHE-RSA-AES256-GCM-SHA384";
2575 else if (strcasecmp(cipher, "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
2576 val = "DHE-RSA-AES256-GCM-SHA384";
2577 else if (strcasecmp(cipher,
2578 "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256") == 0)
2579 val = "ECDHE-ECDSA-AES128-GCM-SHA256";
2580 else
2581 return -1;
2582
2583 /* Need to clear phase1="tls_suiteb=1" to allow cipher enforcement */
2584 set_network_quoted(ifname, id, "phase1", "");
2585
2586 return set_network_quoted(ifname, id, "openssl_ciphers", val);
2587}
2588
2589
Jouni Malinenf7222712019-06-13 01:50:21 +03002590static enum sigma_cmd_result cmd_sta_set_eaptls(struct sigma_dut *dut,
2591 struct sigma_conn *conn,
2592 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002593{
2594 const char *intf = get_param(cmd, "Interface");
2595 const char *ifname, *val;
2596 int id;
2597 char buf[200];
2598#ifdef ANDROID
2599 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
2600 int length;
2601 int jb_or_newer = 0;
2602 char prop[PROPERTY_VALUE_MAX];
2603#endif /* ANDROID */
2604
2605 if (intf == NULL)
2606 return -1;
2607
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002608 if (strcmp(intf, get_main_ifname(dut)) == 0)
2609 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002610 else
2611 ifname = intf;
2612
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302613 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002614 if (id < 0)
2615 return id;
2616
2617 if (set_network(ifname, id, "eap", "TLS") < 0)
2618 return -2;
2619
Pradeep Reddy POTTETI9f6c2132016-05-05 16:28:19 +05302620 if (!get_param(cmd, "username") &&
2621 set_network_quoted(ifname, id, "identity",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002622 "wifi-user@wifilabs.local") < 0)
2623 return -2;
2624
2625 val = get_param(cmd, "clientCertificate");
2626 if (val == NULL)
2627 return -1;
2628#ifdef ANDROID
2629 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2630 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
2631 if (length < 0) {
2632 /*
2633 * JB started reporting keystore type mismatches, so retry with
2634 * the GET_PUBKEY command if the generic GET fails.
2635 */
2636 length = android_keystore_get(ANDROID_KEYSTORE_GET_PUBKEY,
2637 buf, kvalue);
2638 }
2639
2640 if (property_get("ro.build.version.release", prop, NULL) != 0) {
2641 sigma_dut_print(dut, DUT_MSG_DEBUG, "Android release %s", prop);
2642 if (strncmp(prop, "4.0", 3) != 0)
2643 jb_or_newer = 1;
2644 } else
2645 jb_or_newer = 1; /* assume newer */
2646
2647 if (jb_or_newer && length > 0) {
2648 sigma_dut_print(dut, DUT_MSG_INFO,
2649 "Use Android keystore [%s]", buf);
2650 if (set_network(ifname, id, "engine", "1") < 0)
2651 return -2;
2652 if (set_network_quoted(ifname, id, "engine_id", "keystore") < 0)
2653 return -2;
2654 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2655 if (set_network_quoted(ifname, id, "key_id", buf) < 0)
2656 return -2;
2657 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2658 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2659 return -2;
2660 return 1;
2661 } else if (length > 0) {
2662 sigma_dut_print(dut, DUT_MSG_INFO,
2663 "Use Android keystore [%s]", buf);
2664 snprintf(buf, sizeof(buf), "keystore://USRPKEY_%s", val);
2665 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2666 return -2;
2667 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2668 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2669 return -2;
2670 return 1;
2671 }
2672#endif /* ANDROID */
2673
2674 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
2675#ifdef __linux__
2676 if (!file_exists(buf)) {
2677 char msg[300];
2678 snprintf(msg, sizeof(msg), "ErrorCode,clientCertificate file "
2679 "(%s) not found", buf);
2680 send_resp(dut, conn, SIGMA_ERROR, msg);
2681 return -3;
2682 }
2683#endif /* __linux__ */
2684 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2685 return -2;
2686 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2687 return -2;
2688
2689 if (set_network_quoted(ifname, id, "private_key_passwd", "wifi") < 0)
2690 return -2;
2691
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002692 val = get_param(cmd, "keyMgmtType");
2693 if (val && strcasecmp(val, "SuiteB") == 0) {
2694 val = get_param(cmd, "CertType");
2695 if (val && strcasecmp(val, "RSA") == 0) {
2696 if (set_network_quoted(ifname, id, "phase1",
2697 "tls_suiteb=1") < 0)
2698 return -2;
2699 } else {
2700 if (set_network_quoted(ifname, id, "openssl_ciphers",
2701 "SUITEB192") < 0)
2702 return -2;
2703 }
2704
2705 val = get_param(cmd, "TLSCipher");
2706 if (set_tls_cipher(ifname, id, val) < 0) {
2707 send_resp(dut, conn, SIGMA_ERROR,
2708 "ErrorCode,Unsupported TLSCipher value");
2709 return -3;
2710 }
2711 }
2712
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002713 return 1;
2714}
2715
2716
Jouni Malinenf7222712019-06-13 01:50:21 +03002717static enum sigma_cmd_result cmd_sta_set_eapttls(struct sigma_dut *dut,
2718 struct sigma_conn *conn,
2719 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002720{
2721 const char *intf = get_param(cmd, "Interface");
2722 const char *ifname;
2723 int id;
2724
2725 if (intf == NULL)
2726 return -1;
2727
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002728 if (strcmp(intf, get_main_ifname(dut)) == 0)
2729 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002730 else
2731 ifname = intf;
2732
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302733 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002734 if (id < 0)
2735 return id;
2736
2737 if (set_network(ifname, id, "eap", "TTLS") < 0) {
2738 send_resp(dut, conn, SIGMA_ERROR,
2739 "errorCode,Failed to set TTLS method");
2740 return 0;
2741 }
2742
2743 if (set_network_quoted(ifname, id, "phase2", "auth=MSCHAPV2") < 0) {
2744 send_resp(dut, conn, SIGMA_ERROR,
2745 "errorCode,Failed to set MSCHAPv2 for TTLS Phase 2");
2746 return 0;
2747 }
2748
2749 return 1;
2750}
2751
2752
Jouni Malinenf7222712019-06-13 01:50:21 +03002753static enum sigma_cmd_result cmd_sta_set_eapsim(struct sigma_dut *dut,
2754 struct sigma_conn *conn,
2755 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002756{
2757 const char *intf = get_param(cmd, "Interface");
2758 const char *ifname;
2759 int id;
2760
2761 if (intf == NULL)
2762 return -1;
2763
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002764 if (strcmp(intf, get_main_ifname(dut)) == 0)
2765 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002766 else
2767 ifname = intf;
2768
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302769 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002770 if (id < 0)
2771 return id;
2772
2773 if (set_network(ifname, id, "eap", "SIM") < 0)
2774 return -2;
2775
2776 return 1;
2777}
2778
2779
Jouni Malinenf7222712019-06-13 01:50:21 +03002780static enum sigma_cmd_result cmd_sta_set_peap(struct sigma_dut *dut,
2781 struct sigma_conn *conn,
2782 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002783{
2784 const char *intf = get_param(cmd, "Interface");
2785 const char *ifname, *val;
2786 int id;
2787 char buf[100];
2788
2789 if (intf == NULL)
2790 return -1;
2791
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002792 if (strcmp(intf, get_main_ifname(dut)) == 0)
2793 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002794 else
2795 ifname = intf;
2796
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302797 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002798 if (id < 0)
2799 return id;
2800
2801 if (set_network(ifname, id, "eap", "PEAP") < 0)
2802 return -2;
2803
2804 val = get_param(cmd, "innerEAP");
2805 if (val) {
2806 if (strcasecmp(val, "MSCHAPv2") == 0) {
2807 if (set_network_quoted(ifname, id, "phase2",
2808 "auth=MSCHAPV2") < 0)
2809 return -2;
2810 } else if (strcasecmp(val, "GTC") == 0) {
2811 if (set_network_quoted(ifname, id, "phase2",
2812 "auth=GTC") < 0)
2813 return -2;
2814 } else
2815 return -1;
2816 }
2817
2818 val = get_param(cmd, "peapVersion");
2819 if (val) {
2820 int ver = atoi(val);
2821 if (ver < 0 || ver > 1)
2822 return -1;
2823 snprintf(buf, sizeof(buf), "peapver=%d", ver);
2824 if (set_network_quoted(ifname, id, "phase1", buf) < 0)
2825 return -2;
2826 }
2827
2828 return 1;
2829}
2830
2831
Jouni Malinenf7222712019-06-13 01:50:21 +03002832static enum sigma_cmd_result cmd_sta_set_eapfast(struct sigma_dut *dut,
2833 struct sigma_conn *conn,
2834 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002835{
2836 const char *intf = get_param(cmd, "Interface");
2837 const char *ifname, *val;
2838 int id;
2839 char buf[100];
2840
2841 if (intf == NULL)
2842 return -1;
2843
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002844 if (strcmp(intf, get_main_ifname(dut)) == 0)
2845 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002846 else
2847 ifname = intf;
2848
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302849 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002850 if (id < 0)
2851 return id;
2852
2853 if (set_network(ifname, id, "eap", "FAST") < 0)
2854 return -2;
2855
2856 val = get_param(cmd, "innerEAP");
2857 if (val) {
2858 if (strcasecmp(val, "MSCHAPV2") == 0) {
2859 if (set_network_quoted(ifname, id, "phase2",
2860 "auth=MSCHAPV2") < 0)
2861 return -2;
2862 } else if (strcasecmp(val, "GTC") == 0) {
2863 if (set_network_quoted(ifname, id, "phase2",
2864 "auth=GTC") < 0)
2865 return -2;
2866 } else
2867 return -1;
2868 }
2869
2870 val = get_param(cmd, "validateServer");
2871 if (val) {
2872 /* TODO */
2873 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored EAP-FAST "
2874 "validateServer=%s", val);
2875 }
2876
2877 val = get_param(cmd, "pacFile");
2878 if (val) {
2879 snprintf(buf, sizeof(buf), "blob://%s", val);
2880 if (set_network_quoted(ifname, id, "pac_file", buf) < 0)
2881 return -2;
2882 }
2883
2884 if (set_network_quoted(ifname, id, "phase1", "fast_provisioning=2") <
2885 0)
2886 return -2;
2887
2888 return 1;
2889}
2890
2891
Jouni Malinenf7222712019-06-13 01:50:21 +03002892static enum sigma_cmd_result cmd_sta_set_eapaka(struct sigma_dut *dut,
2893 struct sigma_conn *conn,
2894 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002895{
2896 const char *intf = get_param(cmd, "Interface");
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302897 const char *username = get_param(cmd, "Username");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002898 const char *ifname;
2899 int id;
2900
2901 if (intf == NULL)
2902 return -1;
2903
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002904 if (strcmp(intf, get_main_ifname(dut)) == 0)
2905 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002906 else
2907 ifname = intf;
2908
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302909 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002910 if (id < 0)
2911 return id;
2912
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302913 /* RFC 5448: EAP-AKA' MUST use the leading character "6" (ASCII 36
2914 * hexadecimal).
2915 */
2916 if (username && username[0] == '6') {
2917 if (set_network(ifname, id, "eap", "AKA'") < 0)
2918 return -2;
2919 } else if (set_network(ifname, id, "eap", "AKA") < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002920 return -2;
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302921 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002922
2923 return 1;
2924}
2925
2926
Jouni Malinenf7222712019-06-13 01:50:21 +03002927static enum sigma_cmd_result cmd_sta_set_eapakaprime(struct sigma_dut *dut,
2928 struct sigma_conn *conn,
2929 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002930{
2931 const char *intf = get_param(cmd, "Interface");
2932 const char *ifname;
2933 int id;
2934
2935 if (intf == NULL)
2936 return -1;
2937
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002938 if (strcmp(intf, get_main_ifname(dut)) == 0)
2939 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002940 else
2941 ifname = intf;
2942
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302943 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002944 if (id < 0)
2945 return id;
2946
2947 if (set_network(ifname, id, "eap", "AKA'") < 0)
2948 return -2;
2949
2950 return 1;
2951}
2952
2953
2954static int sta_set_open(struct sigma_dut *dut, struct sigma_conn *conn,
2955 struct sigma_cmd *cmd)
2956{
2957 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002958 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002959 const char *ifname;
2960 int id;
2961
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002962 if (strcmp(intf, get_main_ifname(dut)) == 0)
2963 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002964 else
2965 ifname = intf;
2966
2967 id = add_network_common(dut, conn, ifname, cmd);
2968 if (id < 0)
2969 return id;
2970
2971 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
2972 return -2;
2973
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002974 if (dut->program == PROGRAM_60GHZ && network_mode &&
2975 strcasecmp(network_mode, "PBSS") == 0 &&
2976 set_network(ifname, id, "pbss", "1") < 0)
2977 return -2;
2978
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002979 return 1;
2980}
2981
2982
Jouni Malinen8e3f8812020-10-05 10:02:03 +03002983static enum sigma_cmd_result sta_set_owe(struct sigma_dut *dut,
2984 struct sigma_conn *conn,
2985 struct sigma_cmd *cmd)
Jouni Malinen47dcc952017-10-09 16:43:24 +03002986{
2987 const char *intf = get_param(cmd, "Interface");
2988 const char *ifname, *val;
2989 int id;
2990
2991 if (intf == NULL)
Jouni Malinen8e3f8812020-10-05 10:02:03 +03002992 return INVALID_SEND_STATUS;
Jouni Malinen47dcc952017-10-09 16:43:24 +03002993
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002994 if (strcmp(intf, get_main_ifname(dut)) == 0)
2995 ifname = get_station_ifname(dut);
Jouni Malinen47dcc952017-10-09 16:43:24 +03002996 else
2997 ifname = intf;
2998
2999 id = set_wpa_common(dut, conn, ifname, cmd);
3000 if (id < 0)
3001 return id;
3002
3003 if (set_network(ifname, id, "key_mgmt", "OWE") < 0)
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003004 return ERROR_SEND_STATUS;
Jouni Malinen47dcc952017-10-09 16:43:24 +03003005
Hu Wangdd5eed22020-07-16 12:18:03 +08003006 if (dut->owe_ptk_workaround &&
3007 set_network(ifname, id, "owe_ptk_workaround", "1") < 0) {
3008 sigma_dut_print(dut, DUT_MSG_ERROR,
3009 "Failed to set owe_ptk_workaround to 1");
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003010 return ERROR_SEND_STATUS;
Hu Wangdd5eed22020-07-16 12:18:03 +08003011 }
3012
Jouni Malinen47dcc952017-10-09 16:43:24 +03003013 val = get_param(cmd, "ECGroupID");
Jouni Malinenfac9cad2017-10-10 18:35:55 +03003014 if (val && strcmp(val, "0") == 0) {
3015 if (wpa_command(ifname,
3016 "VENDOR_ELEM_ADD 13 ff23200000783590fb7440e03d5b3b33911f86affdcc6b4411b707846ac4ff08ddc8831ccd") != 0) {
3017 sigma_dut_print(dut, DUT_MSG_ERROR,
3018 "Failed to set OWE DH Param element override");
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003019 return ERROR_SEND_STATUS;
Jouni Malinenfac9cad2017-10-10 18:35:55 +03003020 }
Hu Wangdd5eed22020-07-16 12:18:03 +08003021 } else if (val && set_network(ifname, id, "owe_group", val) < 0) {
Jouni Malinen47dcc952017-10-09 16:43:24 +03003022 sigma_dut_print(dut, DUT_MSG_ERROR,
Hu Wang6010ce72020-03-05 19:33:53 +08003023 "Failed to set owe_group");
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003024 return ERROR_SEND_STATUS;
Jouni Malinen47dcc952017-10-09 16:43:24 +03003025 }
3026
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003027 return SUCCESS_SEND_STATUS;
Jouni Malinen47dcc952017-10-09 16:43:24 +03003028}
3029
3030
Jouni Malinenf7222712019-06-13 01:50:21 +03003031static enum sigma_cmd_result cmd_sta_set_security(struct sigma_dut *dut,
3032 struct sigma_conn *conn,
3033 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003034{
3035 const char *type = get_param(cmd, "Type");
3036
3037 if (type == NULL) {
3038 send_resp(dut, conn, SIGMA_ERROR,
3039 "ErrorCode,Missing Type argument");
3040 return 0;
3041 }
3042
3043 if (strcasecmp(type, "OPEN") == 0)
3044 return sta_set_open(dut, conn, cmd);
Jouni Malinen47dcc952017-10-09 16:43:24 +03003045 if (strcasecmp(type, "OWE") == 0)
3046 return sta_set_owe(dut, conn, cmd);
Jouni Malinen992a81e2017-08-22 13:57:47 +03003047 if (strcasecmp(type, "PSK") == 0 ||
Jouni Malinen0ab50f42017-08-31 01:34:59 +03003048 strcasecmp(type, "PSK-SAE") == 0 ||
Jouni Malinen992a81e2017-08-22 13:57:47 +03003049 strcasecmp(type, "SAE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003050 return cmd_sta_set_psk(dut, conn, cmd);
3051 if (strcasecmp(type, "EAPTLS") == 0)
3052 return cmd_sta_set_eaptls(dut, conn, cmd);
3053 if (strcasecmp(type, "EAPTTLS") == 0)
3054 return cmd_sta_set_eapttls(dut, conn, cmd);
3055 if (strcasecmp(type, "EAPPEAP") == 0)
3056 return cmd_sta_set_peap(dut, conn, cmd);
3057 if (strcasecmp(type, "EAPSIM") == 0)
3058 return cmd_sta_set_eapsim(dut, conn, cmd);
3059 if (strcasecmp(type, "EAPFAST") == 0)
3060 return cmd_sta_set_eapfast(dut, conn, cmd);
3061 if (strcasecmp(type, "EAPAKA") == 0)
3062 return cmd_sta_set_eapaka(dut, conn, cmd);
3063 if (strcasecmp(type, "EAPAKAPRIME") == 0)
3064 return cmd_sta_set_eapakaprime(dut, conn, cmd);
Amarnath Hullur Subramanyam81b11cd2018-01-30 19:07:17 -08003065 if (strcasecmp(type, "wep") == 0)
3066 return cmd_sta_set_encryption(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003067
3068 send_resp(dut, conn, SIGMA_ERROR,
3069 "ErrorCode,Unsupported Type value");
3070 return 0;
3071}
3072
3073
3074int ath6kl_client_uapsd(struct sigma_dut *dut, const char *intf, int uapsd)
3075{
3076#ifdef __linux__
3077 /* special handling for ath6kl */
3078 char path[128], fname[128], *pos;
3079 ssize_t res;
3080 FILE *f;
3081
Jouni Malinene39cd562019-05-29 23:39:56 +03003082 res = snprintf(fname, sizeof(fname), "/sys/class/net/%s/phy80211",
3083 intf);
3084 if (res < 0 || res >= sizeof(fname))
3085 return 0;
3086 res = readlink(fname, path, sizeof(path));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003087 if (res < 0)
3088 return 0; /* not ath6kl */
3089
3090 if (res >= (int) sizeof(path))
3091 res = sizeof(path) - 1;
3092 path[res] = '\0';
3093 pos = strrchr(path, '/');
3094 if (pos == NULL)
3095 pos = path;
3096 else
3097 pos++;
Jouni Malinen77dda642020-01-07 11:21:55 +02003098 res = snprintf(fname, sizeof(fname),
3099 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
3100 "create_qos", pos);
3101 if (res < 0 || res >= sizeof(fname) || !file_exists(fname))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003102 return 0; /* not ath6kl */
3103
3104 if (uapsd) {
3105 f = fopen(fname, "w");
3106 if (f == NULL)
3107 return -1;
3108
3109 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl create_qos");
3110 fprintf(f, "4 2 2 1 2 9999999 9999999 9999999 7777777 0 4 "
3111 "45000 200 56789000 56789000 5678900 0 0 9999999 "
3112 "20000 0\n");
3113 fclose(f);
3114 } else {
Jouni Malinen77dda642020-01-07 11:21:55 +02003115 res = snprintf(fname, sizeof(fname),
3116 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
3117 "delete_qos", pos);
3118 if (res < 0 || res >= sizeof(fname))
3119 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003120
3121 f = fopen(fname, "w");
3122 if (f == NULL)
3123 return -1;
3124
3125 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl delete_qos");
3126 fprintf(f, "2 4\n");
3127 fclose(f);
3128 }
3129#endif /* __linux__ */
3130
3131 return 0;
3132}
3133
3134
Jouni Malinenf7222712019-06-13 01:50:21 +03003135static enum sigma_cmd_result cmd_sta_set_uapsd(struct sigma_dut *dut,
3136 struct sigma_conn *conn,
3137 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003138{
3139 const char *intf = get_param(cmd, "Interface");
3140 /* const char *ssid = get_param(cmd, "ssid"); */
3141 const char *val;
3142 int max_sp_len = 4;
3143 int ac_be = 1, ac_bk = 1, ac_vi = 1, ac_vo = 1;
3144 char buf[100];
3145 int ret1, ret2;
3146
3147 val = get_param(cmd, "maxSPLength");
3148 if (val) {
3149 max_sp_len = atoi(val);
3150 if (max_sp_len != 0 && max_sp_len != 1 && max_sp_len != 2 &&
3151 max_sp_len != 4)
3152 return -1;
3153 }
3154
3155 val = get_param(cmd, "acBE");
3156 if (val)
3157 ac_be = atoi(val);
3158
3159 val = get_param(cmd, "acBK");
3160 if (val)
3161 ac_bk = atoi(val);
3162
3163 val = get_param(cmd, "acVI");
3164 if (val)
3165 ac_vi = atoi(val);
3166
3167 val = get_param(cmd, "acVO");
3168 if (val)
3169 ac_vo = atoi(val);
3170
3171 dut->client_uapsd = ac_be || ac_bk || ac_vi || ac_vo;
3172
3173 snprintf(buf, sizeof(buf), "P2P_SET client_apsd %d,%d,%d,%d;%d",
3174 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
3175 ret1 = wpa_command(intf, buf);
3176
3177 snprintf(buf, sizeof(buf), "SET uapsd %d,%d,%d,%d;%d",
3178 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
3179 ret2 = wpa_command(intf, buf);
3180
3181 if (ret1 && ret2) {
3182 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to set client mode "
3183 "UAPSD parameters.");
3184 return -2;
3185 }
3186
3187 if (ath6kl_client_uapsd(dut, intf, dut->client_uapsd) < 0) {
3188 send_resp(dut, conn, SIGMA_ERROR,
3189 "ErrorCode,Failed to set ath6kl QoS parameters");
3190 return 0;
3191 }
3192
3193 return 1;
3194}
3195
3196
Jouni Malinenf7222712019-06-13 01:50:21 +03003197static enum sigma_cmd_result cmd_sta_set_wmm(struct sigma_dut *dut,
3198 struct sigma_conn *conn,
3199 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003200{
3201 char buf[1000];
3202 const char *intf = get_param(cmd, "Interface");
3203 const char *grp = get_param(cmd, "Group");
3204 const char *act = get_param(cmd, "Action");
3205 const char *tid = get_param(cmd, "Tid");
3206 const char *dir = get_param(cmd, "Direction");
3207 const char *psb = get_param(cmd, "Psb");
3208 const char *up = get_param(cmd, "Up");
3209 const char *fixed = get_param(cmd, "Fixed");
3210 const char *size = get_param(cmd, "Size");
3211 const char *msize = get_param(cmd, "Maxsize");
3212 const char *minsi = get_param(cmd, "Min_srvc_intrvl");
3213 const char *maxsi = get_param(cmd, "Max_srvc_intrvl");
3214 const char *inact = get_param(cmd, "Inactivity");
3215 const char *sus = get_param(cmd, "Suspension");
3216 const char *mindr = get_param(cmd, "Mindatarate");
3217 const char *meandr = get_param(cmd, "Meandatarate");
3218 const char *peakdr = get_param(cmd, "Peakdatarate");
3219 const char *phyrate = get_param(cmd, "Phyrate");
3220 const char *burstsize = get_param(cmd, "Burstsize");
3221 const char *sba = get_param(cmd, "Sba");
3222 int direction;
3223 int handle;
Peng Xu93319622017-10-04 17:58:16 -07003224 float sba_fv = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003225 int fixed_int;
3226 int psb_ts;
3227
3228 if (intf == NULL || grp == NULL || act == NULL )
3229 return -1;
3230
3231 if (strcasecmp(act, "addts") == 0) {
3232 if (tid == NULL || dir == NULL || psb == NULL ||
3233 up == NULL || fixed == NULL || size == NULL)
3234 return -1;
3235
3236 /*
3237 * Note: Sigma CAPI spec lists uplink, downlink, and bidi as the
3238 * possible values, but WMM-AC and V-E test scripts use "UP,
3239 * "DOWN", and "BIDI".
3240 */
3241 if (strcasecmp(dir, "uplink") == 0 ||
3242 strcasecmp(dir, "up") == 0) {
3243 direction = 0;
3244 } else if (strcasecmp(dir, "downlink") == 0 ||
3245 strcasecmp(dir, "down") == 0) {
3246 direction = 1;
3247 } else if (strcasecmp(dir, "bidi") == 0) {
3248 direction = 2;
3249 } else {
3250 sigma_dut_print(dut, DUT_MSG_ERROR,
3251 "Direction %s not supported", dir);
3252 return -1;
3253 }
3254
3255 if (strcasecmp(psb, "legacy") == 0) {
3256 psb_ts = 0;
3257 } else if (strcasecmp(psb, "uapsd") == 0) {
3258 psb_ts = 1;
3259 } else {
3260 sigma_dut_print(dut, DUT_MSG_ERROR,
3261 "PSB %s not supported", psb);
3262 return -1;
3263 }
3264
3265 if (atoi(tid) < 0 || atoi(tid) > 7) {
3266 sigma_dut_print(dut, DUT_MSG_ERROR,
3267 "TID %s not supported", tid);
3268 return -1;
3269 }
3270
3271 if (strcasecmp(fixed, "true") == 0) {
3272 fixed_int = 1;
3273 } else {
3274 fixed_int = 0;
3275 }
3276
Peng Xu93319622017-10-04 17:58:16 -07003277 if (sba)
3278 sba_fv = atof(sba);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003279
3280 dut->dialog_token++;
3281 handle = 7000 + dut->dialog_token;
3282
3283 /*
3284 * size: convert to hex
3285 * maxsi: convert to hex
3286 * mindr: convert to hex
3287 * meandr: convert to hex
3288 * peakdr: convert to hex
3289 * burstsize: convert to hex
3290 * phyrate: convert to hex
3291 * sba: convert to hex with modification
3292 * minsi: convert to integer
3293 * sus: convert to integer
3294 * inact: convert to integer
3295 * maxsi: convert to integer
3296 */
3297
3298 /*
3299 * The Nominal MSDU Size field is 2 octets long and contains an
3300 * unsigned integer that specifies the nominal size, in octets,
3301 * of MSDUs belonging to the traffic under this traffic
3302 * specification and is defined in Figure 16. If the Fixed
3303 * subfield is set to 1, then the size of the MSDU is fixed and
3304 * is indicated by the Size Subfield. If the Fixed subfield is
3305 * set to 0, then the size of the MSDU might not be fixed and
3306 * the Size indicates the nominal MSDU size.
3307 *
3308 * The Surplus Bandwidth Allowance Factor field is 2 octets long
3309 * and specifies the excess allocation of time (and bandwidth)
3310 * over and above the stated rates required to transport an MSDU
3311 * belonging to the traffic in this TSPEC. This field is
3312 * represented as an unsigned binary number with an implicit
3313 * binary point after the leftmost 3 bits. For example, an SBA
3314 * of 1.75 is represented as 0x3800. This field is included to
3315 * account for retransmissions. As such, the value of this field
3316 * must be greater than unity.
3317 */
3318
3319 snprintf(buf, sizeof(buf),
3320 "iwpriv %s addTspec %d %s %d %d %s 0x%X"
3321 " 0x%X 0x%X 0x%X"
3322 " 0x%X 0x%X 0x%X"
3323 " 0x%X %d %d %d %d"
3324 " %d %d",
3325 intf, handle, tid, direction, psb_ts, up,
3326 (unsigned int) ((fixed_int << 15) | atoi(size)),
3327 msize ? atoi(msize) : 0,
3328 mindr ? atoi(mindr) : 0,
3329 meandr ? atoi(meandr) : 0,
3330 peakdr ? atoi(peakdr) : 0,
3331 burstsize ? atoi(burstsize) : 0,
3332 phyrate ? atoi(phyrate) : 0,
3333 sba ? ((unsigned int) (((int) sba_fv << 13) |
3334 (int)((sba_fv - (int) sba_fv) *
3335 8192))) : 0,
3336 minsi ? atoi(minsi) : 0,
3337 sus ? atoi(sus) : 0,
3338 0, 0,
3339 inact ? atoi(inact) : 0,
3340 maxsi ? atoi(maxsi) : 0);
3341
3342 if (system(buf) != 0) {
3343 sigma_dut_print(dut, DUT_MSG_ERROR,
3344 "iwpriv addtspec request failed");
3345 send_resp(dut, conn, SIGMA_ERROR,
3346 "errorCode,Failed to execute addTspec command");
3347 return 0;
3348 }
3349
3350 sigma_dut_print(dut, DUT_MSG_INFO,
3351 "iwpriv addtspec request send");
3352
3353 /* Mapping handle to a TID */
3354 dut->tid_to_handle[atoi(tid)] = handle;
3355 } else if (strcasecmp(act, "delts") == 0) {
3356 if (tid == NULL)
3357 return -1;
3358
3359 if (atoi(tid) < 0 || atoi(tid) > 7) {
3360 sigma_dut_print(dut, DUT_MSG_ERROR,
3361 "TID %s not supported", tid);
3362 send_resp(dut, conn, SIGMA_ERROR,
3363 "errorCode,Unsupported TID");
3364 return 0;
3365 }
3366
3367 handle = dut->tid_to_handle[atoi(tid)];
3368
3369 if (handle < 7000 || handle > 7255) {
3370 /* Invalid handle ie no mapping for that TID */
3371 sigma_dut_print(dut, DUT_MSG_ERROR,
3372 "handle-> %d not found", handle);
3373 }
3374
3375 snprintf(buf, sizeof(buf), "iwpriv %s delTspec %d",
3376 intf, handle);
3377
3378 if (system(buf) != 0) {
3379 sigma_dut_print(dut, DUT_MSG_ERROR,
3380 "iwpriv deltspec request failed");
3381 send_resp(dut, conn, SIGMA_ERROR,
3382 "errorCode,Failed to execute delTspec command");
3383 return 0;
3384 }
3385
3386 sigma_dut_print(dut, DUT_MSG_INFO,
3387 "iwpriv deltspec request send");
3388
3389 dut->tid_to_handle[atoi(tid)] = 0;
3390 } else {
3391 sigma_dut_print(dut, DUT_MSG_ERROR,
3392 "Action type %s not supported", act);
3393 send_resp(dut, conn, SIGMA_ERROR,
3394 "errorCode,Unsupported Action");
3395 return 0;
3396 }
3397
3398 return 1;
3399}
3400
3401
vamsi krishna52e16f92017-08-29 12:37:34 +05303402static int find_network(struct sigma_dut *dut, const char *ssid)
3403{
3404 char list[4096];
3405 char *pos;
3406
3407 sigma_dut_print(dut, DUT_MSG_DEBUG,
3408 "Search for profile based on SSID: '%s'", ssid);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003409 if (wpa_command_resp(get_station_ifname(dut), "LIST_NETWORKS",
vamsi krishna52e16f92017-08-29 12:37:34 +05303410 list, sizeof(list)) < 0)
3411 return -1;
3412 pos = strstr(list, ssid);
3413 if (!pos || pos == list || pos[-1] != '\t' || pos[strlen(ssid)] != '\t')
3414 return -1;
3415
3416 while (pos > list && pos[-1] != '\n')
3417 pos--;
3418 dut->infra_network_id = atoi(pos);
3419 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
3420 return 0;
3421}
3422
3423
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303424/**
3425 * enum qca_sta_helper_config_params - This helper enum defines the config
3426 * parameters which can be delivered to sta.
3427 */
3428enum qca_sta_helper_config_params {
3429 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE */
3430 STA_SET_RSNIE,
3431
3432 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_LDPC */
3433 STA_SET_LDPC,
3434
3435 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_TX_STBC */
3436 STA_SET_TX_STBC,
3437
3438 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_RX_STBC */
3439 STA_SET_RX_STBC,
3440
3441 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_TX_MSDU_AGGREGATION */
3442 STA_SET_TX_MSDU,
3443
3444 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_RX_MSDU_AGGREGATION */
3445 STA_SET_RX_MSDU,
3446};
3447
3448
3449static int sta_config_params(struct sigma_dut *dut, const char *intf,
3450 enum qca_sta_helper_config_params config_cmd,
3451 int value)
Sunil Dutt44595082018-02-12 19:41:45 +05303452{
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303453#ifdef NL80211_SUPPORT
Sunil Dutt44595082018-02-12 19:41:45 +05303454 struct nl_msg *msg;
3455 int ret;
3456 struct nlattr *params;
3457 int ifindex;
3458
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303459 ifindex = if_nametoindex(intf);
3460 if (ifindex == 0) {
3461 sigma_dut_print(dut, DUT_MSG_ERROR,
3462 "%s: Interface %s does not exist",
3463 __func__, intf);
3464 return -1;
3465 }
3466
Sunil Dutt44595082018-02-12 19:41:45 +05303467 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
3468 NL80211_CMD_VENDOR)) ||
3469 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
3470 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
3471 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
3472 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) ||
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303473 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)))
3474 goto fail;
3475
3476 switch (config_cmd) {
3477 case STA_SET_RSNIE:
3478 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE, value))
3479 goto fail;
3480 break;
3481 case STA_SET_LDPC:
3482 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_LDPC, value))
3483 goto fail;
3484 break;
3485 case STA_SET_TX_STBC:
3486 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TX_STBC, value))
3487 goto fail;
3488 break;
3489 case STA_SET_RX_STBC:
3490 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_RX_STBC, value))
3491 goto fail;
3492 break;
3493 case STA_SET_TX_MSDU:
3494 if (nla_put_u8(msg,
3495 QCA_WLAN_VENDOR_ATTR_CONFIG_TX_MSDU_AGGREGATION,
3496 value))
3497 goto fail;
3498 break;
3499 case STA_SET_RX_MSDU:
3500 if (nla_put_u8(msg,
3501 QCA_WLAN_VENDOR_ATTR_CONFIG_RX_MSDU_AGGREGATION,
3502 value))
3503 goto fail;
3504 break;
Sunil Dutt44595082018-02-12 19:41:45 +05303505 }
3506 nla_nest_end(msg, params);
3507
3508 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
3509 if (ret) {
3510 sigma_dut_print(dut, DUT_MSG_ERROR,
3511 "%s: err in send_and_recv_msgs, ret=%d",
3512 __func__, ret);
3513 return ret;
3514 }
3515
3516 return 0;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303517
3518fail:
3519 sigma_dut_print(dut, DUT_MSG_ERROR,
3520 "%s: err in adding vendor_cmd and vendor_data",
3521 __func__);
3522 nlmsg_free(msg);
Sunil Dutt44595082018-02-12 19:41:45 +05303523#endif /* NL80211_SUPPORT */
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303524 return -1;
3525}
Sunil Dutt44595082018-02-12 19:41:45 +05303526
3527
Jouni Malinenf7222712019-06-13 01:50:21 +03003528static enum sigma_cmd_result cmd_sta_associate(struct sigma_dut *dut,
3529 struct sigma_conn *conn,
3530 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003531{
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303532#ifdef NL80211_SUPPORT
3533 const char *intf = get_param(cmd, "Interface");
3534#endif /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003535 const char *ssid = get_param(cmd, "ssid");
3536 const char *wps_param = get_param(cmd, "WPS");
3537 const char *bssid = get_param(cmd, "bssid");
Jouni Malinen46a19b62017-06-23 14:31:27 +03003538 const char *chan = get_param(cmd, "channel");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003539 const char *network_mode = get_param(cmd, "network_mode");
Veerendranath Jakkama082e342020-05-16 00:19:21 +05303540 const char *ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003541 int wps = 0;
Jouni Malinen3c367e82017-06-23 17:01:47 +03003542 char buf[1000], extra[50];
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003543 int e;
3544 enum sigma_cmd_result ret = SUCCESS_SEND_STATUS;
3545 struct wpa_ctrl *ctrl = NULL;
3546 int num_network_not_found = 0;
3547 int num_disconnected = 0;
3548 int tod = -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003549
3550 if (ssid == NULL)
3551 return -1;
3552
Jouni Malinen37d5c692019-08-19 16:56:55 +03003553 dut->server_cert_tod = 0;
3554
Jouni Malinen3c367e82017-06-23 17:01:47 +03003555 if (dut->rsne_override) {
Sunil Dutt44595082018-02-12 19:41:45 +05303556#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003557 if (get_driver_type(dut) == DRIVER_WCN) {
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303558 sta_config_params(dut, intf, STA_SET_RSNIE, 1);
Sunil Dutt44595082018-02-12 19:41:45 +05303559 dut->config_rsnie = 1;
3560 }
3561#endif /* NL80211_SUPPORT */
Jouni Malinen3c367e82017-06-23 17:01:47 +03003562 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
3563 dut->rsne_override);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003564 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinen3c367e82017-06-23 17:01:47 +03003565 send_resp(dut, conn, SIGMA_ERROR,
3566 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
3567 return 0;
3568 }
3569 }
3570
Jouni Malinen68143132017-09-02 02:34:08 +03003571 if (dut->sae_commit_override) {
3572 snprintf(buf, sizeof(buf), "SET sae_commit_override %s",
3573 dut->sae_commit_override);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003574 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinen68143132017-09-02 02:34:08 +03003575 send_resp(dut, conn, SIGMA_ERROR,
3576 "ErrorCode,Failed to set SAE commit override");
3577 return 0;
3578 }
3579 }
Ankita Bajaj1bde7942018-01-09 19:15:01 +05303580#ifdef ANDROID
3581 if (dut->fils_hlp)
3582 process_fils_hlp(dut);
3583#endif /* ANDROID */
Jouni Malinen68143132017-09-02 02:34:08 +03003584
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003585 if (wps_param &&
3586 (strcmp(wps_param, "1") == 0 || strcasecmp(wps_param, "On") == 0))
3587 wps = 1;
3588
3589 if (wps) {
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003590 if (dut->program == PROGRAM_60GHZ && network_mode &&
3591 strcasecmp(network_mode, "PBSS") == 0 &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003592 set_network(get_station_ifname(dut), dut->infra_network_id,
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003593 "pbss", "1") < 0)
3594 return -2;
3595
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003596 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
3597 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,WPS "
3598 "parameters not yet set");
3599 return 0;
3600 }
3601 if (dut->wps_method == WFA_CS_WPS_PBC) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003602 if (wpa_command(get_station_ifname(dut), "WPS_PBC") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003603 return -2;
3604 } else {
3605 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
3606 dut->wps_pin);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003607 if (wpa_command(get_station_ifname(dut), buf) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003608 return -2;
3609 }
3610 } else {
vamsi krishna52e16f92017-08-29 12:37:34 +05303611 if (strcmp(ssid, dut->infra_ssid) == 0) {
3612 sigma_dut_print(dut, DUT_MSG_DEBUG,
3613 "sta_associate for the most recently added network");
3614 } else if (find_network(dut, ssid) < 0) {
3615 sigma_dut_print(dut, DUT_MSG_DEBUG,
3616 "sta_associate for a previously stored network profile");
3617 send_resp(dut, conn, SIGMA_ERROR,
3618 "ErrorCode,Profile not found");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003619 return 0;
3620 }
3621
3622 if (bssid &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003623 set_network(get_station_ifname(dut), dut->infra_network_id,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003624 "bssid", bssid) < 0) {
3625 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3626 "Invalid bssid argument");
3627 return 0;
3628 }
3629
Veerendranath Jakkama082e342020-05-16 00:19:21 +05303630 if ((dut->program == PROGRAM_WPA3 &&
3631 dut->sta_associate_wait_connect) ||
3632 dut->program == PROGRAM_QM) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003633 ctrl = open_wpa_mon(get_station_ifname(dut));
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003634 if (!ctrl)
3635 return ERROR_SEND_STATUS;
3636 }
3637
Jouni Malinen46a19b62017-06-23 14:31:27 +03003638 extra[0] = '\0';
3639 if (chan)
3640 snprintf(extra, sizeof(extra), " freq=%u",
Alexei Avshalom Lazar093569f2018-11-13 14:08:17 +02003641 channel_to_freq(dut, atoi(chan)));
Jouni Malinen46a19b62017-06-23 14:31:27 +03003642 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d%s",
3643 dut->infra_network_id, extra);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003644 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003645 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to select "
3646 "network id %d on %s",
3647 dut->infra_network_id,
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003648 get_station_ifname(dut));
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003649 ret = ERROR_SEND_STATUS;
3650 goto done;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003651 }
3652 }
3653
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003654 if (!ctrl)
3655 return SUCCESS_SEND_STATUS;
3656
3657 /* Wait for connection result to be able to store server certificate
3658 * hash for trust root override testing
3659 * (dev_exec_action,ServerCertTrust). */
3660
3661 for (e = 0; e < 20; e++) {
3662 const char *events[] = {
3663 "CTRL-EVENT-EAP-PEER-CERT",
3664 "CTRL-EVENT-EAP-TLS-CERT-ERROR",
3665 "CTRL-EVENT-DISCONNECTED",
3666 "CTRL-EVENT-CONNECTED",
3667 "CTRL-EVENT-NETWORK-NOT-FOUND",
3668 NULL
3669 };
3670 char buf[1024];
3671 int res;
3672
3673 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
3674 if (res < 0) {
Jouni Malinenf1f16642019-11-15 21:19:04 +02003675 send_resp(dut, conn, SIGMA_COMPLETE,
3676 "Result,Association did not complete");
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003677 ret = STATUS_SENT_ERROR;
3678 break;
3679 }
3680 sigma_dut_print(dut, DUT_MSG_DEBUG, "Connection event: %s",
3681 buf);
3682
3683 if (strstr(buf, "CTRL-EVENT-EAP-PEER-CERT") &&
3684 strstr(buf, " depth=0")) {
3685 char *pos = strstr(buf, " hash=");
3686
3687 if (pos) {
3688 char *end;
3689
Jouni Malinen34b19cb2019-08-16 16:37:17 +03003690 if (strstr(buf, " tod=1"))
3691 tod = 1;
3692 else if (strstr(buf, " tod=2"))
3693 tod = 2;
3694 else
3695 tod = 0;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003696 sigma_dut_print(dut, DUT_MSG_DEBUG,
3697 "Server certificate TOD policy: %d",
3698 tod);
Jouni Malinen37d5c692019-08-19 16:56:55 +03003699 dut->server_cert_tod = tod;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003700
3701 pos += 6;
3702 end = strchr(pos, ' ');
3703 if (end)
3704 *end = '\0';
3705 strlcpy(dut->server_cert_hash, pos,
3706 sizeof(dut->server_cert_hash));
3707 sigma_dut_print(dut, DUT_MSG_DEBUG,
3708 "Server certificate hash: %s",
3709 dut->server_cert_hash);
3710 }
3711 }
3712
3713 if (strstr(buf, "CTRL-EVENT-EAP-TLS-CERT-ERROR")) {
3714 send_resp(dut, conn, SIGMA_COMPLETE,
3715 "Result,TLS server certificate validation failed");
3716 ret = STATUS_SENT_ERROR;
3717 break;
3718 }
3719
3720 if (strstr(buf, "CTRL-EVENT-NETWORK-NOT-FOUND")) {
3721 num_network_not_found++;
3722
3723 if (num_network_not_found > 2) {
3724 send_resp(dut, conn, SIGMA_COMPLETE,
3725 "Result,Network not found");
3726 ret = STATUS_SENT_ERROR;
3727 break;
3728 }
3729 }
3730
3731 if (strstr(buf, "CTRL-EVENT-DISCONNECTED")) {
3732 num_disconnected++;
3733
3734 if (num_disconnected > 2) {
3735 send_resp(dut, conn, SIGMA_COMPLETE,
3736 "Result,Connection failed");
3737 ret = STATUS_SENT_ERROR;
3738 break;
3739 }
3740 }
3741
3742 if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
3743 if (tod >= 0) {
3744 sigma_dut_print(dut, DUT_MSG_DEBUG,
3745 "Network profile TOD policy update: %d -> %d",
3746 dut->sta_tod_policy, tod);
3747 dut->sta_tod_policy = tod;
3748 }
Veerendranath Jakkama082e342020-05-16 00:19:21 +05303749 if (dut->program == PROGRAM_QM) {
3750 unsigned char iface_mac_addr[ETH_ALEN];
3751 char ipv6[100];
3752
3753 if (get_hwaddr(ifname, iface_mac_addr) < 0) {
3754 sigma_dut_print(dut, DUT_MSG_ERROR,
3755 "%s: get_hwaddr %s failed",
3756 __func__, ifname);
3757 ret = ERROR_SEND_STATUS;
3758 break;
3759 }
3760
3761 convert_mac_addr_to_ipv6_lladdr(iface_mac_addr,
3762 ipv6,
3763 sizeof(ipv6));
3764
3765 if (set_ipv6_addr(dut, ipv6, "64", ifname) !=
3766 0) {
3767 ret = ERROR_SEND_STATUS;
3768 break;
3769 }
3770 }
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003771 break;
3772 }
3773 }
3774done:
3775 if (ctrl) {
3776 wpa_ctrl_detach(ctrl);
3777 wpa_ctrl_close(ctrl);
3778 }
3779 return ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003780}
3781
3782
3783static int run_hs20_osu(struct sigma_dut *dut, const char *params)
3784{
3785 char buf[500], cmd[200];
3786 int res;
3787
3788 /* Use hs20-osu-client file at the current dir, if found; otherwise use
3789 * default path */
3790 res = snprintf(cmd, sizeof(cmd),
3791 "%s -w \"%s\" -r hs20-osu-client.res %s%s -dddKt -f Logs/hs20-osu-client.txt",
3792 file_exists("./hs20-osu-client") ?
3793 "./hs20-osu-client" : "hs20-osu-client",
3794 sigma_wpas_ctrl,
3795 dut->summary_log ? "-s " : "",
3796 dut->summary_log ? dut->summary_log : "");
3797 if (res < 0 || res >= (int) sizeof(cmd))
3798 return -1;
3799
3800 res = snprintf(buf, sizeof(buf), "%s %s", cmd, params);
3801 if (res < 0 || res >= (int) sizeof(buf))
3802 return -1;
3803 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
3804
3805 if (system(buf) != 0) {
3806 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run: %s", buf);
3807 return -1;
3808 }
3809 sigma_dut_print(dut, DUT_MSG_DEBUG,
3810 "Completed hs20-osu-client operation");
3811
3812 return 0;
3813}
3814
3815
3816static int download_ppsmo(struct sigma_dut *dut,
3817 struct sigma_conn *conn,
3818 const char *intf,
3819 struct sigma_cmd *cmd)
3820{
3821 const char *name, *path, *val;
3822 char url[500], buf[600], fbuf[100];
3823 char *fqdn = NULL;
3824
3825 name = get_param(cmd, "FileName");
3826 path = get_param(cmd, "FilePath");
3827 if (name == NULL || path == NULL)
3828 return -1;
3829
3830 if (strcasecmp(path, "VendorSpecific") == 0) {
3831 snprintf(url, sizeof(url), "PPS/%s", name);
3832 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured PPS MO "
3833 "from the device (%s)", url);
3834 if (!file_exists(url)) {
3835 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
3836 "PPS MO file does not exist");
3837 return 0;
3838 }
3839 snprintf(buf, sizeof(buf), "cp %s pps-tnds.xml", url);
3840 if (system(buf) != 0) {
3841 send_resp(dut, conn, SIGMA_ERROR,
3842 "errorCode,Failed to copy PPS MO");
3843 return 0;
3844 }
3845 } else if (strncasecmp(path, "http:", 5) != 0 &&
3846 strncasecmp(path, "https:", 6) != 0) {
3847 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3848 "Unsupported FilePath value");
3849 return 0;
3850 } else {
3851 snprintf(url, sizeof(url), "%s/%s", path, name);
3852 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading PPS MO from %s",
3853 url);
3854 snprintf(buf, sizeof(buf), "wget -T 10 -t 3 -O pps-tnds.xml '%s'", url);
3855 remove("pps-tnds.xml");
3856 if (system(buf) != 0) {
3857 send_resp(dut, conn, SIGMA_ERROR,
3858 "errorCode,Failed to download PPS MO");
3859 return 0;
3860 }
3861 }
3862
3863 if (run_hs20_osu(dut, "from_tnds pps-tnds.xml pps.xml") < 0) {
3864 send_resp(dut, conn, SIGMA_ERROR,
3865 "errorCode,Failed to parse downloaded PPSMO");
3866 return 0;
3867 }
3868 unlink("pps-tnds.xml");
3869
3870 val = get_param(cmd, "managementTreeURI");
3871 if (val) {
3872 const char *pos, *end;
3873 sigma_dut_print(dut, DUT_MSG_DEBUG, "managementTreeURI: %s",
3874 val);
3875 if (strncmp(val, "./Wi-Fi/", 8) != 0) {
3876 send_resp(dut, conn, SIGMA_ERROR,
3877 "errorCode,Invalid managementTreeURI prefix");
3878 return 0;
3879 }
3880 pos = val + 8;
3881 end = strchr(pos, '/');
3882 if (end == NULL ||
3883 strcmp(end, "/PerProviderSubscription") != 0) {
3884 send_resp(dut, conn, SIGMA_ERROR,
3885 "errorCode,Invalid managementTreeURI postfix");
3886 return 0;
3887 }
3888 if (end - pos >= (int) sizeof(fbuf)) {
3889 send_resp(dut, conn, SIGMA_ERROR,
3890 "errorCode,Too long FQDN in managementTreeURI");
3891 return 0;
3892 }
3893 memcpy(fbuf, pos, end - pos);
3894 fbuf[end - pos] = '\0';
3895 fqdn = fbuf;
3896 sigma_dut_print(dut, DUT_MSG_INFO,
3897 "FQDN from managementTreeURI: %s", fqdn);
3898 } else if (run_hs20_osu(dut, "get_fqdn pps.xml") == 0) {
3899 FILE *f = fopen("pps-fqdn", "r");
3900 if (f) {
3901 if (fgets(fbuf, sizeof(fbuf), f)) {
3902 fbuf[sizeof(fbuf) - 1] = '\0';
3903 fqdn = fbuf;
3904 sigma_dut_print(dut, DUT_MSG_DEBUG,
3905 "Use FQDN %s", fqdn);
3906 }
3907 fclose(f);
3908 }
3909 }
3910
3911 if (fqdn == NULL) {
3912 send_resp(dut, conn, SIGMA_ERROR,
3913 "errorCode,No FQDN specified");
3914 return 0;
3915 }
3916
3917 mkdir("SP", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
3918 snprintf(buf, sizeof(buf), "SP/%s", fqdn);
3919 mkdir(buf, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
3920
3921 snprintf(buf, sizeof(buf), "SP/%s/pps.xml", fqdn);
3922 if (rename("pps.xml", buf) < 0) {
3923 send_resp(dut, conn, SIGMA_ERROR,
3924 "errorCode,Could not move PPS MO");
3925 return 0;
3926 }
3927
3928 if (strcasecmp(path, "VendorSpecific") == 0) {
3929 snprintf(buf, sizeof(buf), "cp Certs/ca.pem SP/%s/ca.pem",
3930 fqdn);
3931 if (system(buf)) {
3932 send_resp(dut, conn, SIGMA_ERROR,
3933 "errorCode,Failed to copy OSU CA cert");
3934 return 0;
3935 }
3936
3937 snprintf(buf, sizeof(buf),
3938 "cp Certs/aaa-ca.pem SP/%s/aaa-ca.pem",
3939 fqdn);
3940 if (system(buf)) {
3941 send_resp(dut, conn, SIGMA_ERROR,
3942 "errorCode,Failed to copy AAA CA cert");
3943 return 0;
3944 }
3945 } else {
3946 snprintf(buf, sizeof(buf),
3947 "dl_osu_ca SP/%s/pps.xml SP/%s/ca.pem",
3948 fqdn, fqdn);
3949 if (run_hs20_osu(dut, buf) < 0) {
3950 send_resp(dut, conn, SIGMA_ERROR,
3951 "errorCode,Failed to download OSU CA cert");
3952 return 0;
3953 }
3954
3955 snprintf(buf, sizeof(buf),
3956 "dl_aaa_ca SP/%s/pps.xml SP/%s/aaa-ca.pem",
3957 fqdn, fqdn);
3958 if (run_hs20_osu(dut, buf) < 0) {
3959 sigma_dut_print(dut, DUT_MSG_INFO,
3960 "Failed to download AAA CA cert");
3961 }
3962 }
3963
3964 if (file_exists("next-client-cert.pem")) {
3965 snprintf(buf, sizeof(buf), "SP/%s/client-cert.pem", fqdn);
3966 if (rename("next-client-cert.pem", buf) < 0) {
3967 send_resp(dut, conn, SIGMA_ERROR,
3968 "errorCode,Could not move client certificate");
3969 return 0;
3970 }
3971 }
3972
3973 if (file_exists("next-client-key.pem")) {
3974 snprintf(buf, sizeof(buf), "SP/%s/client-key.pem", fqdn);
3975 if (rename("next-client-key.pem", buf) < 0) {
3976 send_resp(dut, conn, SIGMA_ERROR,
3977 "errorCode,Could not move client key");
3978 return 0;
3979 }
3980 }
3981
3982 snprintf(buf, sizeof(buf), "set_pps SP/%s/pps.xml", fqdn);
3983 if (run_hs20_osu(dut, buf) < 0) {
3984 send_resp(dut, conn, SIGMA_ERROR,
3985 "errorCode,Failed to configure credential from "
3986 "PPSMO");
3987 return 0;
3988 }
3989
3990 return 1;
3991}
3992
3993
3994static int download_cert(struct sigma_dut *dut,
3995 struct sigma_conn *conn,
3996 const char *intf,
3997 struct sigma_cmd *cmd)
3998{
3999 const char *name, *path;
4000 char url[500], buf[600];
4001
4002 name = get_param(cmd, "FileName");
4003 path = get_param(cmd, "FilePath");
4004 if (name == NULL || path == NULL)
4005 return -1;
4006
4007 if (strcasecmp(path, "VendorSpecific") == 0) {
4008 snprintf(url, sizeof(url), "Certs/%s-cert.pem", name);
4009 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
4010 "certificate from the device (%s)", url);
4011 if (!file_exists(url)) {
4012 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
4013 "certificate file does not exist");
4014 return 0;
4015 }
4016 snprintf(buf, sizeof(buf), "cp %s next-client-cert.pem", url);
4017 if (system(buf) != 0) {
4018 send_resp(dut, conn, SIGMA_ERROR,
4019 "errorCode,Failed to copy client "
4020 "certificate");
4021 return 0;
4022 }
4023
4024 snprintf(url, sizeof(url), "Certs/%s-key.pem", name);
4025 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
4026 "private key from the device (%s)", url);
4027 if (!file_exists(url)) {
4028 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
4029 "private key file does not exist");
4030 return 0;
4031 }
4032 snprintf(buf, sizeof(buf), "cp %s next-client-key.pem", url);
4033 if (system(buf) != 0) {
4034 send_resp(dut, conn, SIGMA_ERROR,
4035 "errorCode,Failed to copy client key");
4036 return 0;
4037 }
4038 } else if (strncasecmp(path, "http:", 5) != 0 &&
4039 strncasecmp(path, "https:", 6) != 0) {
4040 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
4041 "Unsupported FilePath value");
4042 return 0;
4043 } else {
4044 snprintf(url, sizeof(url), "%s/%s.pem", path, name);
4045 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading client "
4046 "certificate/key from %s", url);
4047 snprintf(buf, sizeof(buf),
4048 "wget -T 10 -t 3 -O next-client-cert.pem '%s'", url);
4049 if (system(buf) != 0) {
4050 send_resp(dut, conn, SIGMA_ERROR,
4051 "errorCode,Failed to download client "
4052 "certificate");
4053 return 0;
4054 }
4055
4056 if (system("cp next-client-cert.pem next-client-key.pem") != 0)
4057 {
4058 send_resp(dut, conn, SIGMA_ERROR,
4059 "errorCode,Failed to copy client key");
4060 return 0;
4061 }
4062 }
4063
4064 return 1;
4065}
4066
4067
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02004068static int cmd_sta_preset_testparameters_60ghz(struct sigma_dut *dut,
4069 struct sigma_conn *conn,
4070 struct sigma_cmd *cmd)
4071{
4072 const char *val;
4073 const char *intf = get_param(cmd, "interface");
4074
4075 if (!intf)
4076 return -1;
4077
4078 val = get_param(cmd, "WscIEFragment");
4079 if (val && strcasecmp(val, "enable") == 0) {
4080 sigma_dut_print(dut, DUT_MSG_DEBUG,
4081 "Enable WSC IE fragmentation");
4082
4083 dut->wsc_fragment = 1;
4084 /* set long attributes to force fragmentation */
4085 if (wpa_command(intf, "SET device_name "
4086 WPS_LONG_DEVICE_NAME) < 0)
4087 return -2;
4088 if (wpa_command(intf, "SET manufacturer "
4089 WPS_LONG_MANUFACTURER) < 0)
4090 return -2;
4091 if (wpa_command(intf, "SET model_name "
4092 WPS_LONG_MODEL_NAME) < 0)
4093 return -2;
4094 if (wpa_command(intf, "SET model_number "
4095 WPS_LONG_MODEL_NUMBER) < 0)
4096 return -2;
4097 if (wpa_command(intf, "SET serial_number "
4098 WPS_LONG_SERIAL_NUMBER) < 0)
4099 return -2;
4100 }
4101
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02004102 val = get_param(cmd, "RSN_IE");
4103 if (val) {
4104 if (strcasecmp(val, "disable") == 0)
4105 dut->force_rsn_ie = FORCE_RSN_IE_REMOVE;
4106 else if (strcasecmp(val, "enable") == 0)
4107 dut->force_rsn_ie = FORCE_RSN_IE_ADD;
4108 }
4109
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02004110 val = get_param(cmd, "WpsVersion");
4111 if (val)
4112 dut->wps_forced_version = get_wps_forced_version(dut, val);
4113
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02004114 val = get_param(cmd, "WscEAPFragment");
4115 if (val && strcasecmp(val, "enable") == 0)
4116 dut->eap_fragment = 1;
4117
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02004118 return 1;
4119}
4120
4121
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004122static int cmd_sta_preset_testparameters_hs2_r2(struct sigma_dut *dut,
4123 struct sigma_conn *conn,
4124 const char *intf,
4125 struct sigma_cmd *cmd)
4126{
4127 const char *val;
4128
4129 val = get_param(cmd, "FileType");
4130 if (val && strcasecmp(val, "PPSMO") == 0)
4131 return download_ppsmo(dut, conn, intf, cmd);
4132 if (val && strcasecmp(val, "CERT") == 0)
4133 return download_cert(dut, conn, intf, cmd);
4134 if (val) {
4135 send_resp(dut, conn, SIGMA_ERROR,
4136 "ErrorCode,Unsupported FileType");
4137 return 0;
4138 }
4139
4140 return 1;
4141}
4142
4143
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304144static int cmd_sta_preset_testparameters_oce(struct sigma_dut *dut,
4145 struct sigma_conn *conn,
4146 const char *intf,
4147 struct sigma_cmd *cmd)
4148{
4149 const char *val;
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304150 char buf[1000];
4151 char text[20];
4152 unsigned char addr[ETH_ALEN];
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304153
4154 val = get_param(cmd, "OCESupport");
4155 if (val && strcasecmp(val, "Disable") == 0) {
4156 if (wpa_command(intf, "SET oce 0") < 0) {
4157 send_resp(dut, conn, SIGMA_ERROR,
4158 "ErrorCode,Failed to disable OCE");
4159 return 0;
4160 }
4161 } else if (val && strcasecmp(val, "Enable") == 0) {
4162 if (wpa_command(intf, "SET oce 1") < 0) {
4163 send_resp(dut, conn, SIGMA_ERROR,
4164 "ErrorCode,Failed to enable OCE");
4165 return 0;
4166 }
4167 }
4168
vamsi krishnaa2799492017-12-05 14:28:01 +05304169 val = get_param(cmd, "FILScap");
4170 if (val && (atoi(val) == 1)) {
4171 if (wpa_command(intf, "SET disable_fils 0") < 0) {
4172 send_resp(dut, conn, SIGMA_ERROR,
4173 "ErrorCode,Failed to enable FILS");
4174 return 0;
4175 }
4176 } else if (val && (atoi(val) == 0)) {
4177 if (wpa_command(intf, "SET disable_fils 1") < 0) {
4178 send_resp(dut, conn, SIGMA_ERROR,
4179 "ErrorCode,Failed to disable FILS");
4180 return 0;
4181 }
4182 }
4183
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304184 val = get_param(cmd, "FILSHLP");
4185 if (val && strcasecmp(val, "Enable") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004186 if (get_wpa_status(get_station_ifname(dut), "address", text,
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304187 sizeof(text)) < 0)
4188 return -2;
4189 hwaddr_aton(text, addr);
4190 snprintf(buf, sizeof(buf),
4191 "FILS_HLP_REQ_ADD ff:ff:ff:ff:ff:ff "
4192 "080045100140000040004011399e00000000ffffffff00440043"
4193 "012cb30001010600fd4f46410000000000000000000000000000"
4194 "000000000000"
4195 "%02x%02x%02x%02x%02x%02x"
4196 "0000000000000000000000000000000000000000000000000000"
4197 "0000000000000000000000000000000000000000000000000000"
4198 "0000000000000000000000000000000000000000000000000000"
4199 "0000000000000000000000000000000000000000000000000000"
4200 "0000000000000000000000000000000000000000000000000000"
4201 "0000000000000000000000000000000000000000000000000000"
4202 "0000000000000000000000000000000000000000000000000000"
4203 "0000000000000000000000000000000000000000638253633501"
4204 "013d0701000af549d29b390205dc3c12616e64726f69642d6468"
4205 "63702d382e302e30370a0103060f1a1c333a3b2b5000ff00",
4206 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
4207 if (wpa_command(intf, buf)) {
4208 send_resp(dut, conn, SIGMA_ERROR,
4209 "ErrorCode,Failed to add HLP");
4210 return 0;
4211 }
4212 dut->fils_hlp = 1;
4213 }
4214
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304215 return 1;
4216}
4217
4218
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004219static void ath_sta_set_noack(struct sigma_dut *dut, const char *intf,
4220 const char *val)
4221{
4222 int counter = 0;
4223 char token[50];
4224 char *result;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304225 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004226
Peng Xub8fc5cc2017-05-10 17:27:28 -07004227 strlcpy(token, val, sizeof(token));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004228 token[sizeof(token) - 1] = '\0';
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304229 result = strtok_r(token, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004230 while (result) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004231 if (strcmp(result, "disable") == 0)
4232 run_iwpriv(dut, intf, "noackpolicy %d 1 0", counter);
4233 else
4234 run_iwpriv(dut, intf, "noackpolicy %d 1 1", counter);
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304235 result = strtok_r(NULL, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004236 counter++;
4237 }
4238}
4239
4240
4241static void ath_sta_set_rts(struct sigma_dut *dut, const char *intf,
4242 const char *val)
4243{
4244 char buf[100];
4245
4246 snprintf(buf, sizeof(buf), "iwconfig %s rts %s", intf, val);
4247 if (system(buf) != 0) {
4248 sigma_dut_print(dut, DUT_MSG_ERROR, "iwconfig RTS failed");
4249 }
4250}
4251
4252
4253static void ath_sta_set_wmm(struct sigma_dut *dut, const char *intf,
4254 const char *val)
4255{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004256 if (strcasecmp(val, "off") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004257 run_iwpriv(dut, intf, "wmm 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004258 }
4259}
4260
4261
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08004262static int wcn_sta_set_wmm(struct sigma_dut *dut, const char *intf,
4263 const char *val)
4264{
4265#ifdef NL80211_SUPPORT
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08004266 int wmmenable = 1;
4267
4268 if (val &&
4269 (strcasecmp(val, "off") == 0 || strcmp(val, "0") == 0))
4270 wmmenable = 0;
4271
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05304272 return wcn_wifi_test_config_set_u8(
4273 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WMM_ENABLE,
4274 wmmenable);
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08004275#else /* NL80211_SUPPORT */
4276 sigma_dut_print(dut, DUT_MSG_ERROR,
4277 "WMM cannot be changed without NL80211_SUPPORT defined");
4278 return -1;
4279#endif /* NL80211_SUPPORT */
4280}
4281
4282
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004283static void ath_sta_set_sgi(struct sigma_dut *dut, const char *intf,
4284 const char *val)
4285{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004286 int sgi20;
4287
4288 sgi20 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
4289
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004290 run_iwpriv(dut, intf, "shortgi %d", sgi20);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004291}
4292
4293
4294static void ath_sta_set_11nrates(struct sigma_dut *dut, const char *intf,
4295 const char *val)
4296{
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05304297 int rate_code, v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004298
4299 /* Disable Tx Beam forming when using a fixed rate */
4300 ath_disable_txbf(dut, intf);
4301
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05304302 v = atoi(val);
4303 if (v < 0 || v > 32) {
4304 sigma_dut_print(dut, DUT_MSG_ERROR,
4305 "Invalid Fixed MCS rate: %d", v);
4306 return;
4307 }
4308 rate_code = 0x80 + v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004309
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004310 run_iwpriv(dut, intf, "set11NRates 0x%x", rate_code);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004311
4312 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004313 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004314}
4315
4316
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08004317static void iwpriv_sta_set_amsdu(struct sigma_dut *dut, const char *intf,
4318 const char *val)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004319{
4320 char buf[60];
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304321 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004322
4323 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)
4324 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 2", intf);
4325 else
4326 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf);
4327
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304328 ret = system(buf);
4329#ifdef NL80211_SUPPORT
4330 if (ret) {
4331 int value = (strcasecmp(val, "Enable") == 0) ? 2 : 1;
4332
4333 ret = sta_config_params(dut, intf, STA_SET_TX_MSDU, value);
4334 ret |= sta_config_params(dut, intf, STA_SET_RX_MSDU, value);
4335 }
4336#endif /* NL80211_SUPPORT */
4337 if (ret)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004338 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv amsdu failed");
4339}
4340
4341
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004342static int iwpriv_sta_set_ampdu(struct sigma_dut *dut, const char *intf,
4343 int ampdu)
4344{
4345 char buf[60];
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08004346 int maxaggregation = 63;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004347
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08004348 if (ampdu)
4349 ampdu = maxaggregation;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004350 snprintf(buf, sizeof(buf), "iwpriv %s ampdu %d", intf, ampdu);
4351 if (system(buf) != 0) {
4352 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv ampdu failed");
4353 return -1;
4354 }
4355
4356 return 0;
4357}
4358
4359
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004360static void ath_sta_set_stbc(struct sigma_dut *dut, const char *intf,
4361 const char *val)
4362{
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004363 run_iwpriv(dut, intf, "tx_stbc %s", val);
4364 run_iwpriv(dut, intf, "rx_stbc %s", val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004365}
4366
4367
4368static int wcn_sta_set_cts_width(struct sigma_dut *dut, const char *intf,
4369 const char *val)
4370{
4371 char buf[60];
4372
Peng Xucc317ed2017-05-18 16:44:37 -07004373 if (strcmp(val, "160") == 0) {
4374 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 5", intf);
4375 } else if (strcmp(val, "80") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004376 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
4377 } else if (strcmp(val, "40") == 0) {
4378 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 2", intf);
4379 } else if (strcmp(val, "20") == 0) {
4380 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 1", intf);
4381 } else if (strcasecmp(val, "Auto") == 0) {
4382 buf[0] = '\0';
4383 } else {
4384 sigma_dut_print(dut, DUT_MSG_ERROR,
4385 "WIDTH/CTS_WIDTH value not supported");
4386 return -1;
4387 }
4388
4389 if (buf[0] != '\0' && system(buf) != 0) {
4390 sigma_dut_print(dut, DUT_MSG_ERROR,
4391 "Failed to set WIDTH/CTS_WIDTH");
4392 return -1;
4393 }
4394
4395 return 0;
4396}
4397
4398
4399int ath_set_width(struct sigma_dut *dut, struct sigma_conn *conn,
4400 const char *intf, const char *val)
4401{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004402 if (strcasecmp(val, "Auto") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004403 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004404 dut->chwidth = 0;
4405 } else if (strcasecmp(val, "20") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004406 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004407 dut->chwidth = 0;
4408 } else if (strcasecmp(val, "40") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004409 run_iwpriv(dut, intf, "chwidth 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004410 dut->chwidth = 1;
4411 } else if (strcasecmp(val, "80") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004412 run_iwpriv(dut, intf, "chwidth 2");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004413 dut->chwidth = 2;
4414 } else if (strcasecmp(val, "160") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004415 run_iwpriv(dut, intf, "chwidth 3");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004416 dut->chwidth = 3;
4417 } else {
4418 send_resp(dut, conn, SIGMA_ERROR,
4419 "ErrorCode,WIDTH not supported");
4420 return -1;
4421 }
4422
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004423 return 0;
4424}
4425
4426
4427static int wcn_sta_set_sp_stream(struct sigma_dut *dut, const char *intf,
4428 const char *val)
4429{
4430 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07004431 int sta_nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004432
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08004433 if (strcmp(val, "1SS") == 0 || strcmp(val, "1") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004434 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07004435 sta_nss = 1;
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08004436 } else if (strcmp(val, "2SS") == 0 || strcmp(val, "2") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004437 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07004438 sta_nss = 2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004439 } else {
4440 sigma_dut_print(dut, DUT_MSG_ERROR,
4441 "SP_STREAM value not supported");
4442 return -1;
4443 }
4444
4445 if (system(buf) != 0) {
4446 sigma_dut_print(dut, DUT_MSG_ERROR,
4447 "Failed to set SP_STREAM");
4448 return -1;
4449 }
4450
Arif Hussainac6c5112018-05-25 17:34:00 -07004451 dut->sta_nss = sta_nss;
4452
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004453 return 0;
4454}
4455
4456
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304457static void wcn_sta_set_stbc(struct sigma_dut *dut, const char *intf,
4458 const char *val)
4459{
4460 char buf[60];
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304461 int ret;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304462
4463 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc %s", intf, val);
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304464 ret = system(buf);
4465#ifdef NL80211_SUPPORT
4466 if (ret)
4467 ret = sta_config_params(dut, intf, STA_SET_TX_STBC,
4468 strcmp(val, "0") == 0 ? 0 : 1);
4469#endif /* NL80211_SUPPORT */
4470 if (ret)
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304471 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv tx_stbc failed");
4472
4473 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc %s", intf, val);
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304474 ret = system(buf);
4475#ifdef NL80211_SUPPORT
4476 if (ret)
4477 ret = sta_config_params(dut, intf, STA_SET_RX_STBC,
4478 strcmp(val, "0") == 0 ? 0 : 1);
4479#endif /* NL80211_SUPPORT */
4480 if (ret)
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304481 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv rx_stbc failed");
4482}
4483
4484
Ashwini Patil68d02cd2017-01-10 15:39:16 +05304485static int mbo_set_cellular_data_capa(struct sigma_dut *dut,
4486 struct sigma_conn *conn,
4487 const char *intf, int capa)
4488{
4489 char buf[32];
4490
4491 if (capa > 0 && capa < 4) {
4492 snprintf(buf, sizeof(buf), "SET mbo_cell_capa %d", capa);
4493 if (wpa_command(intf, buf) < 0) {
4494 send_resp(dut, conn, SIGMA_ERROR,
4495 "ErrorCode, Failed to set cellular data capability");
4496 return 0;
4497 }
4498 return 1;
4499 }
4500
4501 sigma_dut_print(dut, DUT_MSG_ERROR,
4502 "Invalid Cellular data capability: %d", capa);
4503 send_resp(dut, conn, SIGMA_INVALID,
4504 "ErrorCode,Invalid cellular data capability");
4505 return 0;
4506}
4507
4508
Ashwini Patil9183fdb2017-04-13 16:58:25 +05304509static int mbo_set_roaming(struct sigma_dut *dut, struct sigma_conn *conn,
4510 const char *intf, const char *val)
4511{
4512 if (strcasecmp(val, "Disable") == 0) {
4513 if (wpa_command(intf, "SET roaming 0") < 0) {
4514 send_resp(dut, conn, SIGMA_ERROR,
4515 "ErrorCode,Failed to disable roaming");
4516 return 0;
4517 }
4518 return 1;
4519 }
4520
4521 if (strcasecmp(val, "Enable") == 0) {
4522 if (wpa_command(intf, "SET roaming 1") < 0) {
4523 send_resp(dut, conn, SIGMA_ERROR,
4524 "ErrorCode,Failed to enable roaming");
4525 return 0;
4526 }
4527 return 1;
4528 }
4529
4530 sigma_dut_print(dut, DUT_MSG_ERROR,
4531 "Invalid value provided for roaming: %s", val);
4532 send_resp(dut, conn, SIGMA_INVALID,
4533 "ErrorCode,Unknown value provided for Roaming");
4534 return 0;
4535}
4536
4537
Ashwini Patila75de5a2017-04-13 16:35:05 +05304538static int mbo_set_assoc_disallow(struct sigma_dut *dut,
4539 struct sigma_conn *conn,
4540 const char *intf, const char *val)
4541{
4542 if (strcasecmp(val, "Disable") == 0) {
4543 if (wpa_command(intf, "SET ignore_assoc_disallow 1") < 0) {
4544 send_resp(dut, conn, SIGMA_ERROR,
4545 "ErrorCode,Failed to disable Assoc_disallow");
4546 return 0;
4547 }
4548 return 1;
4549 }
4550
4551 if (strcasecmp(val, "Enable") == 0) {
4552 if (wpa_command(intf, "SET ignore_assoc_disallow 0") < 0) {
4553 send_resp(dut, conn, SIGMA_ERROR,
4554 "ErrorCode,Failed to enable Assoc_disallow");
4555 return 0;
4556 }
4557 return 1;
4558 }
4559
4560 sigma_dut_print(dut, DUT_MSG_ERROR,
4561 "Invalid value provided for Assoc_disallow: %s", val);
4562 send_resp(dut, conn, SIGMA_INVALID,
4563 "ErrorCode,Unknown value provided for Assoc_disallow");
4564 return 0;
4565}
4566
4567
Ashwini Patilc63161e2017-04-13 16:30:23 +05304568static int mbo_set_bss_trans_req(struct sigma_dut *dut, struct sigma_conn *conn,
4569 const char *intf, const char *val)
4570{
4571 if (strcasecmp(val, "Reject") == 0) {
4572 if (wpa_command(intf, "SET reject_btm_req_reason 1") < 0) {
4573 send_resp(dut, conn, SIGMA_ERROR,
4574 "ErrorCode,Failed to Reject BTM Request");
4575 return 0;
4576 }
4577 return 1;
4578 }
4579
4580 if (strcasecmp(val, "Accept") == 0) {
4581 if (wpa_command(intf, "SET reject_btm_req_reason 0") < 0) {
4582 send_resp(dut, conn, SIGMA_ERROR,
4583 "ErrorCode,Failed to Accept BTM Request");
4584 return 0;
4585 }
4586 return 1;
4587 }
4588
4589 sigma_dut_print(dut, DUT_MSG_ERROR,
4590 "Invalid value provided for BSS_Transition: %s", val);
4591 send_resp(dut, conn, SIGMA_INVALID,
4592 "ErrorCode,Unknown value provided for BSS_Transition");
4593 return 0;
4594}
4595
4596
Ashwini Patil00402582017-04-13 12:29:39 +05304597static int mbo_set_non_pref_ch_list(struct sigma_dut *dut,
4598 struct sigma_conn *conn,
4599 const char *intf,
4600 struct sigma_cmd *cmd)
4601{
4602 const char *ch, *pref, *op_class, *reason;
4603 char buf[120];
4604 int len, ret;
4605
4606 pref = get_param(cmd, "Ch_Pref");
4607 if (!pref)
4608 return 1;
4609
4610 if (strcasecmp(pref, "clear") == 0) {
4611 free(dut->non_pref_ch_list);
4612 dut->non_pref_ch_list = NULL;
4613 } else {
4614 op_class = get_param(cmd, "Ch_Op_Class");
4615 if (!op_class) {
4616 send_resp(dut, conn, SIGMA_INVALID,
4617 "ErrorCode,Ch_Op_Class not provided");
4618 return 0;
4619 }
4620
4621 ch = get_param(cmd, "Ch_Pref_Num");
4622 if (!ch) {
4623 send_resp(dut, conn, SIGMA_INVALID,
4624 "ErrorCode,Ch_Pref_Num not provided");
4625 return 0;
4626 }
4627
4628 reason = get_param(cmd, "Ch_Reason_Code");
4629 if (!reason) {
4630 send_resp(dut, conn, SIGMA_INVALID,
4631 "ErrorCode,Ch_Reason_Code not provided");
4632 return 0;
4633 }
4634
4635 if (!dut->non_pref_ch_list) {
4636 dut->non_pref_ch_list =
4637 calloc(1, NON_PREF_CH_LIST_SIZE);
4638 if (!dut->non_pref_ch_list) {
4639 send_resp(dut, conn, SIGMA_ERROR,
4640 "ErrorCode,Failed to allocate memory for non_pref_ch_list");
4641 return 0;
4642 }
4643 }
4644 len = strlen(dut->non_pref_ch_list);
4645 ret = snprintf(dut->non_pref_ch_list + len,
4646 NON_PREF_CH_LIST_SIZE - len,
4647 " %s:%s:%s:%s", op_class, ch, pref, reason);
4648 if (ret > 0 && ret < NON_PREF_CH_LIST_SIZE - len) {
4649 sigma_dut_print(dut, DUT_MSG_DEBUG, "non_pref_list: %s",
4650 dut->non_pref_ch_list);
4651 } else {
4652 sigma_dut_print(dut, DUT_MSG_ERROR,
4653 "snprintf failed for non_pref_list, ret = %d",
4654 ret);
4655 send_resp(dut, conn, SIGMA_ERROR,
4656 "ErrorCode,snprintf failed");
4657 free(dut->non_pref_ch_list);
4658 dut->non_pref_ch_list = NULL;
4659 return 0;
4660 }
4661 }
4662
4663 ret = snprintf(buf, sizeof(buf), "SET non_pref_chan%s",
4664 dut->non_pref_ch_list ? dut->non_pref_ch_list : " ");
4665 if (ret < 0 || ret >= (int) sizeof(buf)) {
4666 sigma_dut_print(dut, DUT_MSG_DEBUG,
4667 "snprintf failed for set non_pref_chan, ret: %d",
4668 ret);
4669 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,snprint failed");
4670 return 0;
4671 }
4672
4673 if (wpa_command(intf, buf) < 0) {
4674 send_resp(dut, conn, SIGMA_ERROR,
4675 "ErrorCode,Failed to set non-preferred channel list");
4676 return 0;
4677 }
4678
4679 return 1;
4680}
4681
4682
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004683#ifdef NL80211_SUPPORT
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004684
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08004685static int sta_set_he_htc_supp(struct sigma_dut *dut, const char *intf,
4686 uint8_t cfg)
4687{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05304688 return wcn_wifi_test_config_set_u8(
4689 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_HTC_HE_SUPP,
4690 cfg);
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08004691}
4692
4693
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004694static int sta_set_he_fragmentation(struct sigma_dut *dut, const char *intf,
4695 enum he_fragmentation_val frag)
4696{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05304697 return wcn_wifi_test_config_set_u8(
4698 dut, intf,
4699 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_FRAGMENTATION, frag);
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004700}
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004701
4702
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -08004703int wcn_set_he_ltf(struct sigma_dut *dut, const char *intf,
4704 enum qca_wlan_he_ltf_cfg ltf)
Subhani Shaik8e7a3052018-04-24 14:03:00 -07004705{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05304706 return wcn_wifi_test_config_set_u8(
4707 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_LTF, ltf);
Subhani Shaik8e7a3052018-04-24 14:03:00 -07004708}
4709
4710
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004711static int nlvendor_sta_set_noack(struct sigma_dut *dut, const char *intf,
4712 int noack, enum qca_wlan_ac_type ac)
4713{
4714 struct nl_msg *msg;
4715 int ret = 0;
4716 struct nlattr *params;
4717 int ifindex;
4718
4719 ifindex = if_nametoindex(intf);
4720 if (ifindex == 0) {
4721 sigma_dut_print(dut, DUT_MSG_ERROR,
4722 "%s: Index for interface %s failed",
4723 __func__, intf);
4724 return -1;
4725 }
4726
4727 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4728 NL80211_CMD_VENDOR)) ||
4729 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4730 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4731 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4732 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4733 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4734 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_NO_ACK,
4735 noack) ||
4736 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_NO_ACK_AC,
4737 ac)) {
4738 sigma_dut_print(dut, DUT_MSG_ERROR,
4739 "%s: err in adding vendor_cmd and vendor_data",
4740 __func__);
4741 nlmsg_free(msg);
4742 return -1;
4743 }
4744 nla_nest_end(msg, params);
4745
4746 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4747 if (ret) {
4748 sigma_dut_print(dut, DUT_MSG_ERROR,
4749 "%s: err in send_and_recv_msgs, ret=%d",
4750 __func__, ret);
4751 }
4752 return ret;
4753}
4754
4755
4756static void wcn_sta_set_noack(struct sigma_dut *dut, const char *intf,
4757 const char *val)
4758{
4759 int noack, ret;
4760 char token[100];
4761 char *result;
4762 char *saveptr;
4763 enum qca_wlan_ac_type ac = QCA_WLAN_AC_BE;
4764
4765 strlcpy(token, val, sizeof(token));
4766 token[sizeof(token) - 1] = '\0';
4767 result = strtok_r(token, ":", &saveptr);
4768 while (result) {
4769 noack = strcasecmp(result, "Disable") != 0;
4770 ret = nlvendor_sta_set_noack(dut, intf, noack, ac);
4771 if (ret) {
4772 sigma_dut_print(dut, DUT_MSG_ERROR,
4773 "nlvendor_sta_set_noack failed for ac:%d, ret:%d",
4774 ac, ret);
4775 }
4776 result = strtok_r(NULL, ":", &saveptr);
4777 ac++;
4778 }
4779}
4780
Vinita S. Maloo7462e812020-05-22 15:16:04 +05304781
4782static int nlvendor_sta_set_phymode(struct sigma_dut *dut, const char *intf,
4783 enum qca_wlan_vendor_phy_mode val)
4784{
4785 struct nl_msg *msg;
4786 struct nlattr *params;
4787 int ifindex, ret;
4788
4789 ifindex = if_nametoindex(intf);
4790 if (ifindex == 0) {
4791 sigma_dut_print(dut, DUT_MSG_ERROR,
4792 "%s: Index for interface %s not found",
4793 __func__, intf);
4794 return -1;
4795 }
4796
4797 msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4798 NL80211_CMD_VENDOR);
4799 if (!msg) {
4800 sigma_dut_print(dut, DUT_MSG_ERROR,
4801 "%s: err in adding vendor_cmd", __func__);
4802 return -1;
4803 }
4804
4805 if (nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4806 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4807 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION)) {
4808 sigma_dut_print(dut, DUT_MSG_ERROR,
4809 "%s: err in adding vendor_attr", __func__);
4810 nlmsg_free(msg);
4811 return -1;
4812 }
4813
4814 params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
4815 if (!params || nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_PHY_MODE,
4816 val)) {
4817 sigma_dut_print(dut, DUT_MSG_ERROR,
4818 "%s: err in adding vendor_data", __func__);
4819 nlmsg_free(msg);
4820 return -1;
4821 }
4822
4823 nla_nest_end(msg, params);
4824 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4825 if (ret) {
4826 sigma_dut_print(dut, DUT_MSG_ERROR,
4827 "%s: err in send_and_recv_msgs, ret=%d (%s)",
4828 __func__, ret, strerror(-ret));
4829 return ret;
4830 }
4831
4832 return 0;
4833}
4834
4835
4836static enum qca_wlan_vendor_phy_mode get_qca_vendor_phymode(const char *val)
4837{
4838 if (strcmp(val, "11a") == 0) {
4839 /* IEEE80211_MODE_11A */
4840 return QCA_WLAN_VENDOR_PHY_MODE_11A;
4841 }
4842
4843 if (strcmp(val, "11g") == 0) {
4844 /* IEEE80211_MODE_11G */
4845 return QCA_WLAN_VENDOR_PHY_MODE_11G;
4846 }
4847
4848 if (strcmp(val, "11b") == 0) {
4849 /* IEEE80211_MODE_11B */
4850 return QCA_WLAN_VENDOR_PHY_MODE_11B;
4851 }
4852
4853 if (strcmp(val, "11n") == 0 ||
4854 strcmp(val, "11nl") == 0 ||
4855 strcmp(val, "11nl(nabg)") == 0) {
4856 /* IEEE80211_MODE_11AGN */
4857 return QCA_WLAN_VENDOR_PHY_MODE_11AGN;
4858 }
4859
4860 if (strcmp(val, "11ng") == 0) {
4861 /* IEEE80211_MODE_11NG_HT40 */
4862 return QCA_WLAN_VENDOR_PHY_MODE_11NG_HT40;
4863 }
4864
4865 if (strcmp(val, "AC") == 0 ||
4866 strcasecmp(val, "11AC") == 0) {
4867 /* IEEE80211_MODE_11AC_VHT80 */
4868 return QCA_WLAN_VENDOR_PHY_MODE_11AC_VHT80;
4869 }
4870
4871 if (strcmp(val, "11na") == 0 ||
4872 strcasecmp(val, "11an") == 0) {
4873 /* IEEE80211_MODE_11NA_HT40 */
4874 return QCA_WLAN_VENDOR_PHY_MODE_11NA_HT40;
4875 }
4876
4877 if (strcmp(val, "11ax") == 0 ||
4878 strcmp(val, "auto") == 0) {
4879 /* IEEE80211_MODE_AUTO */
4880 return QCA_WLAN_VENDOR_PHY_MODE_AUTO;
4881 }
4882
4883 return -1;
4884}
4885
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004886#endif /* NL80211_SUPPORT */
4887
4888
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05304889static int get_phymode(const char *val)
4890{
4891 if (strcmp(val, "11a") == 0)
4892 return 1; /* IEEE80211_MODE_11A */
4893 if (strcmp(val, "11g") == 0)
4894 return 3; /* IEEE80211_MODE_11G */
4895 if (strcmp(val, "11b") == 0)
4896 return 2; /* IEEE80211_MODE_11B */
4897 if (strcmp(val, "11n") == 0 ||
4898 strcmp(val, "11nl") == 0 ||
4899 strcmp(val, "11nl(nabg)") == 0)
4900 return 22; /* IEEE80211_MODE_11AGN */
4901 if (strcmp(val, "11ng") == 0)
4902 return 13; /* IEEE80211_MODE_11NG_HT40 */
4903 if (strcmp(val, "AC") == 0 ||
4904 strcasecmp(val, "11AC") == 0)
4905 return 19; /* IEEE80211_MODE_11AC_VHT80 */
4906 if (strcmp(val, "11na") == 0 ||
4907 strcasecmp(val, "11an") == 0)
4908 return 14; /* IEEE80211_MODE_11NA_HT40 */
4909 if (strcmp(val, "11ax") == 0 ||
4910 strcmp(val, "auto") == 0)
4911 return 0; /* IEEE80211_MODE_AUTO */
4912 return -1;
4913}
4914
4915
4916static void sta_set_phymode(struct sigma_dut *dut, const char *intf,
4917 const char *val)
4918{
4919 char buf[100];
4920 int len, phymode;
Vinita S. Maloo7462e812020-05-22 15:16:04 +05304921#ifdef NL80211_SUPPORT
4922 enum qca_wlan_vendor_phy_mode qca_phymode;
4923
4924 qca_phymode = get_qca_vendor_phymode(val);
4925 if (qca_phymode == -1) {
4926 sigma_dut_print(dut, DUT_MSG_DEBUG,
4927 "Ignoring mode change for mode: %s",
4928 val);
4929 return;
4930 }
4931
4932 if (nlvendor_sta_set_phymode(dut, intf, qca_phymode) == 0)
4933 return;
4934#endif /* NL80211_SUPPORT */
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05304935
4936 phymode = get_phymode(val);
4937 if (phymode == -1) {
4938 sigma_dut_print(dut, DUT_MSG_DEBUG,
4939 "Ignoring mode change for mode: %s",
4940 val);
4941 return;
4942 }
4943
4944 len = snprintf(buf, sizeof(buf), "iwpriv %s setphymode %d", intf,
4945 phymode);
4946 if (len < 0 || len >= sizeof(buf)) {
4947 sigma_dut_print(dut, DUT_MSG_ERROR,
4948 "Failed to set phymode");
4949 return;
4950 }
4951
4952 if (system(buf) != 0)
4953 sigma_dut_print(dut, DUT_MSG_ERROR,
4954 "iwpriv setting of phymode failed");
4955}
4956
4957
Jouni Malinenf7222712019-06-13 01:50:21 +03004958static enum sigma_cmd_result
4959cmd_sta_preset_testparameters(struct sigma_dut *dut, struct sigma_conn *conn,
4960 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004961{
4962 const char *intf = get_param(cmd, "Interface");
4963 const char *val;
4964
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03004965 val = get_param(cmd, "FT_DS");
4966 if (val) {
4967 if (strcasecmp(val, "Enable") == 0) {
4968 dut->sta_ft_ds = 1;
4969 } else if (strcasecmp(val, "Disable") == 0) {
4970 dut->sta_ft_ds = 0;
4971 } else {
4972 send_resp(dut, conn, SIGMA_ERROR,
4973 "errorCode,Unsupported value for FT_DS");
4974 return STATUS_SENT_ERROR;
4975 }
4976 }
4977
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004978 val = get_param(cmd, "Program");
Jouni Malinen1f6ae642018-06-07 23:56:13 +03004979 if (val && (strcasecmp(val, "HS2-R2") == 0 ||
4980 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004981 return cmd_sta_preset_testparameters_hs2_r2(dut, conn, intf,
4982 cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004983
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07004984 if (val && strcasecmp(val, "LOC") == 0)
4985 return loc_cmd_sta_preset_testparameters(dut, conn, cmd);
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02004986 if (val && strcasecmp(val, "60GHZ") == 0) {
4987 val = get_param(cmd, "WPS");
4988 if (val && strcasecmp(val, "disable") == 0) {
4989 dut->wps_disable = 1;
4990 sigma_dut_print(dut, DUT_MSG_INFO, "WPS disabled");
4991 } else {
4992 /* wps_disable can have other value from the previous
4993 * test, so make sure it has the correct value.
4994 */
4995 dut->wps_disable = 0;
4996 }
4997
4998 val = get_param(cmd, "P2P");
4999 if (val && strcasecmp(val, "disable") == 0)
5000 sigma_dut_print(dut, DUT_MSG_INFO, "P2P disabled");
5001 }
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07005002
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02005003 if (dut->program == PROGRAM_WPS && dut->band == WPS_BAND_60G)
5004 return cmd_sta_preset_testparameters_60ghz(dut, conn, cmd);
5005
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005006#ifdef ANDROID_NAN
5007 if (val && strcasecmp(val, "NAN") == 0)
5008 return nan_cmd_sta_preset_testparameters(dut, conn, cmd);
5009#endif /* ANDROID_NAN */
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07005010#ifdef MIRACAST
5011 if (val && (strcasecmp(val, "WFD") == 0 ||
5012 strcasecmp(val, "DisplayR2") == 0))
5013 return miracast_preset_testparameters(dut, conn, cmd);
5014#endif /* MIRACAST */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005015
Kiran Kumar Lokeredd086642020-06-04 00:29:26 -07005016 if (val &&
5017 (strcasecmp(val, "MBO") == 0 || strcasecmp(val, "HE") == 0)) {
Ashwini Patil68d02cd2017-01-10 15:39:16 +05305018 val = get_param(cmd, "Cellular_Data_Cap");
5019 if (val &&
5020 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
5021 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +05305022
5023 val = get_param(cmd, "Ch_Pref");
5024 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
5025 return 0;
5026
Ashwini Patilc63161e2017-04-13 16:30:23 +05305027 val = get_param(cmd, "BSS_Transition");
5028 if (val && mbo_set_bss_trans_req(dut, conn, intf, val) == 0)
5029 return 0;
5030
Ashwini Patila75de5a2017-04-13 16:35:05 +05305031 val = get_param(cmd, "Assoc_Disallow");
5032 if (val && mbo_set_assoc_disallow(dut, conn, intf, val) == 0)
5033 return 0;
5034
Ashwini Patil9183fdb2017-04-13 16:58:25 +05305035 val = get_param(cmd, "Roaming");
5036 if (val && mbo_set_roaming(dut, conn, intf, val) == 0)
5037 return 0;
5038
Ashwini Patil68d02cd2017-01-10 15:39:16 +05305039 return 1;
5040 }
5041
Ankita Bajaja2cb5672017-10-25 16:08:28 +05305042 if (val && strcasecmp(val, "OCE") == 0)
5043 return cmd_sta_preset_testparameters_oce(dut, conn, intf, cmd);
5044
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005045#if 0
5046 val = get_param(cmd, "Supplicant");
5047 if (val && strcasecmp(val, "Default") != 0) {
5048 send_resp(dut, conn, SIGMA_ERROR,
5049 "ErrorCode,Only default(Vendor) supplicant "
5050 "supported");
5051 return 0;
5052 }
5053#endif
5054
5055 val = get_param(cmd, "RTS");
5056 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005057 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005058 case DRIVER_ATHEROS:
5059 ath_sta_set_rts(dut, intf, val);
5060 break;
5061 default:
5062#if 0
5063 send_resp(dut, conn, SIGMA_ERROR,
5064 "ErrorCode,Setting RTS not supported");
5065 return 0;
5066#else
5067 sigma_dut_print(dut, DUT_MSG_DEBUG,
5068 "Setting RTS not supported");
5069 break;
5070#endif
5071 }
5072 }
5073
5074#if 0
5075 val = get_param(cmd, "FRGMNT");
5076 if (val) {
5077 /* TODO */
5078 send_resp(dut, conn, SIGMA_ERROR,
5079 "ErrorCode,Setting FRGMNT not supported");
5080 return 0;
5081 }
5082#endif
5083
5084#if 0
5085 val = get_param(cmd, "Preamble");
5086 if (val) {
5087 /* TODO: Long/Short */
5088 send_resp(dut, conn, SIGMA_ERROR,
5089 "ErrorCode,Setting Preamble not supported");
5090 return 0;
5091 }
5092#endif
5093
5094 val = get_param(cmd, "Mode");
5095 if (val) {
5096 if (strcmp(val, "11b") == 0 ||
5097 strcmp(val, "11g") == 0 ||
5098 strcmp(val, "11a") == 0 ||
5099 strcmp(val, "11n") == 0 ||
5100 strcmp(val, "11ng") == 0 ||
5101 strcmp(val, "11nl") == 0 ||
5102 strcmp(val, "11nl(nabg)") == 0 ||
5103 strcmp(val, "AC") == 0 ||
5104 strcmp(val, "11AC") == 0 ||
5105 strcmp(val, "11ac") == 0 ||
5106 strcmp(val, "11na") == 0 ||
Amarnath Hullur Subramanyamb0db2712018-01-30 19:40:35 -08005107 strcmp(val, "11an") == 0 ||
5108 strcmp(val, "11ax") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005109 /* STA supports all modes by default */
5110 } else {
5111 send_resp(dut, conn, SIGMA_ERROR,
5112 "ErrorCode,Setting Mode not supported");
5113 return 0;
5114 }
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08005115
5116 /* Change the mode only in case of testbed for HE program
5117 * and for 11a and 11g modes only. */
5118 if (dut->program == PROGRAM_HE &&
5119 dut->device_type == STA_testbed) {
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05305120 sta_set_phymode(dut, intf, val);
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08005121 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005122 }
5123
5124 val = get_param(cmd, "wmm");
5125 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005126 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005127 case DRIVER_ATHEROS:
5128 ath_sta_set_wmm(dut, intf, val);
5129 break;
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08005130 case DRIVER_WCN:
5131 wcn_sta_set_wmm(dut, intf, val);
5132 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005133 default:
5134 sigma_dut_print(dut, DUT_MSG_DEBUG,
5135 "Setting wmm not supported");
5136 break;
5137 }
5138 }
5139
5140 val = get_param(cmd, "Powersave");
5141 if (val) {
5142 if (strcmp(val, "0") == 0 || strcasecmp(val, "off") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005143 if (get_driver_type(dut) == DRIVER_WCN) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +05305144 if (set_power_save_wcn(dut, intf, 2) < 0)
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005145 return 0;
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005146 }
5147
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005148 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005149 "P2P_SET ps 0") < 0)
5150 return -2;
5151 /* Make sure test modes are disabled */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005152 wpa_command(get_station_ifname(dut), "P2P_SET ps 98");
5153 wpa_command(get_station_ifname(dut), "P2P_SET ps 96");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005154 } else if (strcmp(val, "1") == 0 ||
5155 strcasecmp(val, "PSPoll") == 0 ||
5156 strcasecmp(val, "on") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005157 if (get_driver_type(dut) == DRIVER_WCN) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +05305158 if (set_power_save_wcn(dut, intf, 1) < 0)
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005159 return 0;
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005160 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005161 /* Disable default power save mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005162 wpa_command(get_station_ifname(dut), "P2P_SET ps 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005163 /* Enable PS-Poll test mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005164 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005165 "P2P_SET ps 97") < 0 ||
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005166 wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005167 "P2P_SET ps 99") < 0)
5168 return -2;
5169 } else if (strcmp(val, "2") == 0 ||
5170 strcasecmp(val, "Fast") == 0) {
5171 /* TODO */
5172 send_resp(dut, conn, SIGMA_ERROR,
5173 "ErrorCode,Powersave=Fast not supported");
5174 return 0;
5175 } else if (strcmp(val, "3") == 0 ||
5176 strcasecmp(val, "PSNonPoll") == 0) {
5177 /* Make sure test modes are disabled */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005178 wpa_command(get_station_ifname(dut), "P2P_SET ps 98");
5179 wpa_command(get_station_ifname(dut), "P2P_SET ps 96");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005180
5181 /* Enable default power save mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005182 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005183 "P2P_SET ps 1") < 0)
5184 return -2;
5185 } else
5186 return -1;
5187 }
5188
5189 val = get_param(cmd, "NoAck");
5190 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005191 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005192 case DRIVER_ATHEROS:
5193 ath_sta_set_noack(dut, intf, val);
5194 break;
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08005195#ifdef NL80211_SUPPORT
5196 case DRIVER_WCN:
5197 wcn_sta_set_noack(dut, intf, val);
5198 break;
5199#endif /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005200 default:
5201 send_resp(dut, conn, SIGMA_ERROR,
5202 "ErrorCode,Setting NoAck not supported");
5203 return 0;
5204 }
5205 }
5206
5207 val = get_param(cmd, "IgnoreChswitchProhibit");
5208 if (val) {
5209 /* TODO: Enabled/disabled */
5210 if (strcasecmp(val, "Enabled") == 0) {
5211 send_resp(dut, conn, SIGMA_ERROR,
5212 "ErrorCode,Enabling IgnoreChswitchProhibit "
5213 "not supported");
5214 return 0;
5215 }
5216 }
5217
5218 val = get_param(cmd, "TDLS");
5219 if (val) {
5220 if (strcasecmp(val, "Disabled") == 0) {
5221 if (wpa_command(intf, "SET tdls_disabled 1")) {
5222 send_resp(dut, conn, SIGMA_ERROR,
5223 "ErrorCode,Failed to disable TDLS");
5224 return 0;
5225 }
5226 } else if (strcasecmp(val, "Enabled") == 0) {
5227 if (wpa_command(intf, "SET tdls_disabled 0")) {
5228 send_resp(dut, conn, SIGMA_ERROR,
5229 "ErrorCode,Failed to enable TDLS");
5230 return 0;
5231 }
5232 } else {
5233 send_resp(dut, conn, SIGMA_ERROR,
5234 "ErrorCode,Unsupported TDLS value");
5235 return 0;
5236 }
5237 }
5238
5239 val = get_param(cmd, "TDLSmode");
5240 if (val) {
5241 if (strcasecmp(val, "Default") == 0) {
5242 wpa_command(intf, "SET tdls_testing 0");
5243 } else if (strcasecmp(val, "APProhibit") == 0) {
5244 if (wpa_command(intf, "SET tdls_testing 0x400")) {
5245 send_resp(dut, conn, SIGMA_ERROR,
5246 "ErrorCode,Failed to enable ignore "
5247 "APProhibit TDLS mode");
5248 return 0;
5249 }
5250 } else if (strcasecmp(val, "HiLoMac") == 0) {
5251 /* STA should respond with TDLS setup req for a TDLS
5252 * setup req */
5253 if (wpa_command(intf, "SET tdls_testing 0x80")) {
5254 send_resp(dut, conn, SIGMA_ERROR,
5255 "ErrorCode,Failed to enable HiLoMac "
5256 "TDLS mode");
5257 return 0;
5258 }
5259 } else if (strcasecmp(val, "WeakSecurity") == 0) {
5260 /*
5261 * Since all security modes are enabled by default when
5262 * Sigma control is used, there is no need to do
5263 * anything here.
5264 */
5265 } else if (strcasecmp(val, "ExistLink") == 0) {
5266 /*
5267 * Since we allow new TDLS Setup Request even if there
5268 * is an existing link, nothing needs to be done for
5269 * this.
5270 */
5271 } else {
5272 /* TODO:
5273 * ExistLink: STA should send TDLS setup req even if
5274 * direct link already exists
5275 */
5276 send_resp(dut, conn, SIGMA_ERROR,
5277 "ErrorCode,Unsupported TDLSmode value");
5278 return 0;
5279 }
5280 }
5281
5282 val = get_param(cmd, "FakePubKey");
5283 if (val && atoi(val) && wpa_command(intf, "SET wps_corrupt_pkhash 1")) {
5284 send_resp(dut, conn, SIGMA_ERROR,
5285 "ErrorCode,Failed to enable FakePubKey");
5286 return 0;
5287 }
5288
Amarnath Hullur Subramanyamae1042b2018-02-22 21:52:52 -08005289#ifdef NL80211_SUPPORT
5290 val = get_param(cmd, "FrgmntSupport");
5291 if (val) {
5292 if (strcasecmp(val, "Enable") == 0) {
5293 if (sta_set_he_fragmentation(dut, intf,
5294 HE_FRAG_LEVEL1)) {
5295 send_resp(dut, conn, SIGMA_ERROR,
5296 "ErrorCode,Failed to enable HE Fragmentation");
5297 return 0;
5298 }
5299 } else if (strcasecmp(val, "Disable") == 0) {
5300 if (sta_set_he_fragmentation(dut, intf,
5301 HE_FRAG_DISABLE)) {
5302 send_resp(dut, conn, SIGMA_ERROR,
5303 "ErrorCode,Failed to disable HE Fragmentation");
5304 return 0;
5305 }
5306 }
5307 }
5308#endif /* NL80211_SUPPORT */
5309
Vinita S. Maloo8a4779c2020-06-22 19:32:37 +05305310 val = get_param(cmd, "IncludeMSCSDescriptor");
5311 if (val && strcasecmp(val, "1") == 0) {
5312 char buf[128];
5313 int len;
5314
5315 len = snprintf(buf, sizeof(buf),
Veerendranath Jakkam62cde372020-08-19 18:03:06 +05305316 "MSCS add up_bitmap=F0 up_limit=7 stream_timeout=60000 frame_classifier=045F%032x",
Vinita S. Maloo8a4779c2020-06-22 19:32:37 +05305317 0);
5318
5319 if (len < 0 || len >= sizeof(buf)) {
5320 sigma_dut_print(dut, DUT_MSG_ERROR,
5321 "Failed to build MSCS Descriptor IE");
5322 return ERROR_SEND_STATUS;
5323 }
5324
5325 if (wpa_command(intf, buf) != 0) {
5326 send_resp(dut, conn, SIGMA_ERROR,
5327 "ErrorCode,Failed to include MSCS descriptor");
5328 return STATUS_SENT_ERROR;
5329 }
5330 }
5331
Vinita S. Maloo2287f142021-02-01 16:17:09 +05305332 val = get_param(cmd, "SCSSupport");
5333 if (val) {
5334 char buf[30];
5335 int disable_scs, len;
5336
5337 if (strcasecmp(val, "Enable") == 0) {
5338 disable_scs = 0;
5339 } else if (strcasecmp(val, "Disable") == 0) {
5340 disable_scs = 1;
5341 } else {
5342 sigma_dut_print(dut, DUT_MSG_ERROR,
5343 "Invalid SCSsupport parameter");
5344 return INVALID_SEND_STATUS;
5345 }
5346
5347 len = snprintf(buf, sizeof(buf), "SET disable_scs_support %d",
5348 disable_scs);
5349 if (len < 0 || len >= sizeof(buf) ||
5350 wpa_command(intf, buf) != 0) {
5351 send_resp(dut, conn, SIGMA_ERROR,
5352 "ErrorCode,Failed to update SCS support");
5353 return STATUS_SENT_ERROR;
5354 }
5355 }
5356
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005357 return 1;
5358}
5359
5360
5361static const char * ath_get_radio_name(const char *radio_name)
5362{
5363 if (radio_name == NULL)
5364 return "wifi0";
5365 if (strcmp(radio_name, "wifi1") == 0)
5366 return "wifi1";
5367 if (strcmp(radio_name, "wifi2") == 0)
5368 return "wifi2";
5369 return "wifi0";
5370}
5371
5372
5373static void ath_sta_set_txsp_stream(struct sigma_dut *dut, const char *intf,
5374 const char *val)
5375{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005376 unsigned int vht_mcsmap = 0;
5377 int txchainmask = 0;
5378 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
5379
5380 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
5381 if (dut->testbed_flag_txsp == 1) {
5382 vht_mcsmap = 0xfffc;
5383 dut->testbed_flag_txsp = 0;
5384 } else {
5385 vht_mcsmap = 0xfffe;
5386 }
5387 txchainmask = 1;
5388 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
5389 if (dut->testbed_flag_txsp == 1) {
5390 vht_mcsmap = 0xfff0;
5391 dut->testbed_flag_txsp = 0;
5392 } else {
5393 vht_mcsmap = 0xfffa;
5394 }
5395 txchainmask = 3;
5396 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
5397 if (dut->testbed_flag_txsp == 1) {
5398 vht_mcsmap = 0xffc0;
5399 dut->testbed_flag_txsp = 0;
5400 } else {
5401 vht_mcsmap = 0xffea;
5402 }
5403 txchainmask = 7;
5404 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
5405 if (dut->testbed_flag_txsp == 1) {
5406 vht_mcsmap = 0xff00;
5407 dut->testbed_flag_txsp = 0;
5408 } else {
5409 vht_mcsmap = 0xffaa;
5410 }
5411 txchainmask = 15;
5412 } else {
5413 if (dut->testbed_flag_txsp == 1) {
5414 vht_mcsmap = 0xffc0;
5415 dut->testbed_flag_txsp = 0;
5416 } else {
5417 vht_mcsmap = 0xffea;
5418 }
5419 }
5420
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005421 if (txchainmask)
5422 run_iwpriv(dut, basedev, "txchainmask %d", txchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005423
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005424 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005425}
5426
5427
5428static void ath_sta_set_rxsp_stream(struct sigma_dut *dut, const char *intf,
5429 const char *val)
5430{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005431 unsigned int vht_mcsmap = 0;
5432 int rxchainmask = 0;
5433 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
5434
5435 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
5436 if (dut->testbed_flag_rxsp == 1) {
5437 vht_mcsmap = 0xfffc;
5438 dut->testbed_flag_rxsp = 0;
5439 } else {
5440 vht_mcsmap = 0xfffe;
5441 }
5442 rxchainmask = 1;
5443 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
5444 if (dut->testbed_flag_rxsp == 1) {
5445 vht_mcsmap = 0xfff0;
5446 dut->testbed_flag_rxsp = 0;
5447 } else {
5448 vht_mcsmap = 0xfffa;
5449 }
5450 rxchainmask = 3;
5451 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
5452 if (dut->testbed_flag_rxsp == 1) {
5453 vht_mcsmap = 0xffc0;
5454 dut->testbed_flag_rxsp = 0;
5455 } else {
5456 vht_mcsmap = 0xffea;
5457 }
5458 rxchainmask = 7;
5459 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
5460 if (dut->testbed_flag_rxsp == 1) {
5461 vht_mcsmap = 0xff00;
5462 dut->testbed_flag_rxsp = 0;
5463 } else {
5464 vht_mcsmap = 0xffaa;
5465 }
5466 rxchainmask = 15;
5467 } else {
5468 if (dut->testbed_flag_rxsp == 1) {
5469 vht_mcsmap = 0xffc0;
5470 dut->testbed_flag_rxsp = 0;
5471 } else {
5472 vht_mcsmap = 0xffea;
5473 }
5474 }
5475
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005476 if (rxchainmask)
5477 run_iwpriv(dut, basedev, "rxchainmask %d", rxchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005478
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005479 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005480}
5481
5482
5483void ath_set_zero_crc(struct sigma_dut *dut, const char *val)
5484{
5485 if (strcasecmp(val, "enable") == 0) {
5486 if (system("athdiag --set --address=0x2a204 --and=0xbfffffff")
5487 != 0) {
5488 sigma_dut_print(dut, DUT_MSG_ERROR,
5489 "Disable BB_VHTSIGB_CRC_CALC failed");
5490 }
5491
5492 if (system("athdiag --set --address=0x2a204 --or=0x80000000")
5493 != 0) {
5494 sigma_dut_print(dut, DUT_MSG_ERROR,
5495 "Enable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
5496 }
5497 } else {
5498 if (system("athdiag --set --address=0x2a204 --and=0x7fffffff")
5499 != 0) {
5500 sigma_dut_print(dut, DUT_MSG_ERROR,
5501 "Disable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
5502 }
5503
5504 if (system("athdiag --set --address=0x2a204 --or=0x40000000")
5505 != 0) {
5506 sigma_dut_print(dut, DUT_MSG_ERROR,
5507 "Enable BB_VHTSIGB_CRC_CALC failed");
5508 }
5509 }
5510}
5511
5512
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005513static int wcn_sta_set_width(struct sigma_dut *dut, const char *intf,
5514 const char *val)
5515{
5516 char buf[60];
5517
5518 if (strcmp(val, "20") == 0) {
5519 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
5520 dut->chwidth = 0;
5521 } else if (strcmp(val, "40") == 0) {
5522 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 1", intf);
5523 dut->chwidth = 1;
5524 } else if (strcmp(val, "80") == 0) {
5525 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
5526 dut->chwidth = 2;
Sunil Duttb1cccac2018-05-22 21:03:12 +05305527 } else if (strcasecmp(val, "Auto") == 0) {
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005528 buf[0] = '\0';
5529 } else {
5530 sigma_dut_print(dut, DUT_MSG_ERROR, "WIDTH %s not supported",
5531 val);
5532 return -1;
5533 }
5534
5535 if (buf[0] != '\0' && system(buf) != 0) {
5536 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv chwidth failed");
5537 return -1;
5538 }
5539
5540 return 0;
5541}
5542
5543
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005544static int nlvendor_sta_set_addba_reject(struct sigma_dut *dut,
5545 const char *intf, int addbareject)
5546{
5547#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05305548 return wcn_wifi_test_config_set_u8(
5549 dut, intf,
5550 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ACCEPT_ADDBA_REQ,
5551 !addbareject);
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005552#else /* NL80211_SUPPORT */
5553 sigma_dut_print(dut, DUT_MSG_ERROR,
5554 "ADDBA_REJECT cannot be set without NL80211_SUPPORT defined");
5555 return -1;
5556#endif /* NL80211_SUPPORT */
5557}
5558
5559
5560static int sta_set_addba_reject(struct sigma_dut *dut, const char *intf,
5561 int addbareject)
5562{
5563 int ret;
5564
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005565 switch (get_driver_type(dut)) {
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005566 case DRIVER_WCN:
5567 ret = nlvendor_sta_set_addba_reject(dut, intf, addbareject);
5568 if (ret) {
5569 sigma_dut_print(dut, DUT_MSG_ERROR,
5570 "nlvendor_sta_set_addba_reject failed, ret:%d",
5571 ret);
5572 return ret;
5573 }
5574 break;
5575 default:
5576 sigma_dut_print(dut, DUT_MSG_ERROR,
5577 "errorCode,Unsupported ADDBA_REJECT with the current driver");
5578 ret = -1;
5579 break;
5580 }
5581
5582 return ret;
5583}
5584
5585
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005586static int nlvendor_config_send_addba(struct sigma_dut *dut, const char *intf,
5587 int enable)
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005588{
5589#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05305590 return wcn_wifi_test_config_set_u8(
5591 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SEND_ADDBA_REQ,
5592 enable);
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005593#else /* NL80211_SUPPORT */
5594 sigma_dut_print(dut, DUT_MSG_ERROR,
5595 "Disable addba not possible without NL80211_SUPPORT defined");
5596 return -1;
5597#endif /* NL80211_SUPPORT */
5598}
5599
5600
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305601#ifdef NL80211_SUPPORT
5602static int nl80211_sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
5603{
5604 struct nl_msg *msg;
5605 int ret = 0;
5606 int ifindex;
5607
5608 ifindex = if_nametoindex(intf);
5609 if (ifindex == 0) {
5610 sigma_dut_print(dut, DUT_MSG_ERROR,
5611 "%s: Index for interface %s failed",
5612 __func__, intf);
5613 return -1;
5614 }
5615
5616 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5617 NL80211_CMD_SET_WIPHY)) ||
5618 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) {
5619 sigma_dut_print(dut, DUT_MSG_ERROR,
5620 "%s: err in adding RTS threshold",
5621 __func__);
5622 nlmsg_free(msg);
5623 return -1;
5624 }
5625
5626 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5627 if (ret) {
5628 sigma_dut_print(dut, DUT_MSG_ERROR,
5629 "%s: err in send_and_recv_msgs, ret=%d",
5630 __func__, ret);
5631 }
5632 return ret;
5633}
5634#endif /* NL80211_SUPPORT */
5635
5636
5637static int sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
5638{
5639 char buf[100];
5640
5641#ifdef NL80211_SUPPORT
5642 if (nl80211_sta_set_rts(dut, intf, val) == 0)
5643 return 0;
5644 sigma_dut_print(dut, DUT_MSG_DEBUG,
5645 "Fall back to using iwconfig for setting RTS threshold");
5646#endif /* NL80211_SUPPORT */
5647
5648 snprintf(buf, sizeof(buf), "iwconfig %s rts %d", intf, val);
5649 if (system(buf) != 0) {
5650 sigma_dut_print(dut, DUT_MSG_ERROR,
5651 "Failed to set RTS threshold %d", val);
5652 return -1;
5653 }
5654 return 0;
5655}
5656
5657
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03005658static enum sigma_cmd_result
5659cmd_sta_set_wireless_common(const char *intf, struct sigma_dut *dut,
5660 struct sigma_conn *conn, struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005661{
5662 const char *val;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005663 int ampdu = -1, addbareject = -1;
Jouni Malinen3aa72862019-05-29 23:14:51 +03005664 char buf[128];
5665 int res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005666
5667 val = get_param(cmd, "40_INTOLERANT");
5668 if (val) {
5669 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5670 /* TODO: iwpriv ht40intol through wpa_supplicant */
5671 send_resp(dut, conn, SIGMA_ERROR,
5672 "ErrorCode,40_INTOLERANT not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03005673 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005674 }
5675 }
5676
5677 val = get_param(cmd, "ADDBA_REJECT");
5678 if (val) {
5679 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5680 /* reject any ADDBA with status "decline" */
5681 ampdu = 0;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005682 addbareject = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005683 } else {
5684 /* accept ADDBA */
5685 ampdu = 1;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005686 addbareject = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005687 }
5688 }
5689
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005690 if (addbareject >= 0 &&
5691 sta_set_addba_reject(dut, intf, addbareject) < 0) {
5692 send_resp(dut, conn, SIGMA_ERROR,
5693 "ErrorCode,set addba_reject failed");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03005694 return STATUS_SENT_ERROR;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005695 }
5696
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005697 val = get_param(cmd, "AMPDU");
5698 if (val) {
5699 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5700 /* enable AMPDU Aggregation */
5701 if (ampdu == 0) {
5702 send_resp(dut, conn, SIGMA_ERROR,
5703 "ErrorCode,Mismatch in "
5704 "addba_reject/ampdu - "
5705 "not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03005706 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005707 }
5708 ampdu = 1;
5709 } else {
5710 /* disable AMPDU Aggregation */
5711 if (ampdu == 1) {
5712 send_resp(dut, conn, SIGMA_ERROR,
5713 "ErrorCode,Mismatch in "
5714 "addba_reject/ampdu - "
5715 "not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03005716 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005717 }
5718 ampdu = 0;
5719 }
5720 }
5721
5722 if (ampdu >= 0) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005723 int ret;
5724
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005725 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s A-MPDU aggregation",
5726 ampdu ? "Enabling" : "Disabling");
5727 snprintf(buf, sizeof(buf), "SET ampdu %d", ampdu);
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07005728 if (wpa_command(intf, buf) < 0 &&
5729 iwpriv_sta_set_ampdu(dut, intf, ampdu) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005730 send_resp(dut, conn, SIGMA_ERROR,
5731 "ErrorCode,set aggr failed");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03005732 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005733 }
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005734
5735 if (ampdu == 0) {
5736 /* Disable sending of addba using nl vendor command */
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005737 ret = nlvendor_config_send_addba(dut, intf, 0);
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005738 if (ret) {
5739 sigma_dut_print(dut, DUT_MSG_ERROR,
5740 "Failed to disable addba, ret:%d",
5741 ret);
5742 }
5743 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005744 }
5745
5746 val = get_param(cmd, "AMSDU");
5747 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005748 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005749 case DRIVER_ATHEROS:
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08005750 case DRIVER_WCN:
5751 iwpriv_sta_set_amsdu(dut, intf, val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005752 break;
5753 default:
5754 if (strcmp(val, "1") == 0 ||
5755 strcasecmp(val, "Enable") == 0) {
5756 /* Enable AMSDU Aggregation */
5757 send_resp(dut, conn, SIGMA_ERROR,
5758 "ErrorCode,AMSDU aggregation not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03005759 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005760 }
5761 break;
5762 }
5763 }
5764
5765 val = get_param(cmd, "STBC_RX");
5766 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005767 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005768 case DRIVER_ATHEROS:
5769 ath_sta_set_stbc(dut, intf, val);
5770 break;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05305771 case DRIVER_WCN:
5772 wcn_sta_set_stbc(dut, intf, val);
5773 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005774 default:
5775 send_resp(dut, conn, SIGMA_ERROR,
5776 "ErrorCode,STBC_RX not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03005777 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005778 }
5779 }
5780
5781 val = get_param(cmd, "WIDTH");
5782 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005783 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005784 case DRIVER_WCN:
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005785 if (wcn_sta_set_width(dut, intf, val) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005786 send_resp(dut, conn, SIGMA_ERROR,
5787 "ErrorCode,Failed to set WIDTH");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03005788 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005789 }
5790 break;
5791 case DRIVER_ATHEROS:
5792 if (ath_set_width(dut, conn, intf, val) < 0)
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03005793 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005794 break;
5795 default:
5796 sigma_dut_print(dut, DUT_MSG_ERROR,
5797 "Setting WIDTH not supported");
5798 break;
5799 }
5800 }
5801
5802 val = get_param(cmd, "SMPS");
5803 if (val) {
5804 /* TODO: Dynamic/0, Static/1, No Limit/2 */
5805 send_resp(dut, conn, SIGMA_ERROR,
5806 "ErrorCode,SMPS not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03005807 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005808 }
5809
5810 val = get_param(cmd, "TXSP_STREAM");
5811 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005812 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005813 case DRIVER_WCN:
5814 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
5815 send_resp(dut, conn, SIGMA_ERROR,
5816 "ErrorCode,Failed to set TXSP_STREAM");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03005817 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005818 }
5819 break;
5820 case DRIVER_ATHEROS:
5821 ath_sta_set_txsp_stream(dut, intf, val);
5822 break;
5823 default:
5824 sigma_dut_print(dut, DUT_MSG_ERROR,
5825 "Setting TXSP_STREAM not supported");
5826 break;
5827 }
5828 }
5829
5830 val = get_param(cmd, "RXSP_STREAM");
5831 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005832 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005833 case DRIVER_WCN:
5834 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
5835 send_resp(dut, conn, SIGMA_ERROR,
5836 "ErrorCode,Failed to set RXSP_STREAM");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03005837 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005838 }
5839 break;
5840 case DRIVER_ATHEROS:
5841 ath_sta_set_rxsp_stream(dut, intf, val);
5842 break;
5843 default:
5844 sigma_dut_print(dut, DUT_MSG_ERROR,
5845 "Setting RXSP_STREAM not supported");
5846 break;
5847 }
5848 }
5849
5850 val = get_param(cmd, "DYN_BW_SGNL");
5851 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005852 switch (get_driver_type(dut)) {
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005853 case DRIVER_WCN:
Peng Xuc59afd32016-11-21 15:01:11 -08005854 if (strcasecmp(val, "enable") == 0) {
5855 snprintf(buf, sizeof(buf),
5856 "iwpriv %s cwmenable 1", intf);
5857 if (system(buf) != 0) {
5858 sigma_dut_print(dut, DUT_MSG_ERROR,
5859 "iwpriv cwmenable 1 failed");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03005860 return ERROR_SEND_STATUS;
Peng Xuc59afd32016-11-21 15:01:11 -08005861 }
5862 } else if (strcasecmp(val, "disable") == 0) {
5863 snprintf(buf, sizeof(buf),
5864 "iwpriv %s cwmenable 0", intf);
5865 if (system(buf) != 0) {
5866 sigma_dut_print(dut, DUT_MSG_ERROR,
5867 "iwpriv cwmenable 0 failed");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03005868 return ERROR_SEND_STATUS;
Peng Xuc59afd32016-11-21 15:01:11 -08005869 }
5870 } else {
5871 sigma_dut_print(dut, DUT_MSG_ERROR,
5872 "Unsupported DYN_BW_SGL");
5873 }
5874
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005875 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
5876 if (system(buf) != 0) {
5877 sigma_dut_print(dut, DUT_MSG_ERROR,
5878 "Failed to set cts_cbw in DYN_BW_SGNL");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03005879 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005880 }
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005881 break;
5882 case DRIVER_ATHEROS:
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07005883 novap_reset(dut, intf, 1);
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005884 ath_config_dyn_bw_sig(dut, intf, val);
5885 break;
5886 default:
5887 sigma_dut_print(dut, DUT_MSG_ERROR,
5888 "Failed to set DYN_BW_SGNL");
5889 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005890 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005891 }
5892
5893 val = get_param(cmd, "RTS_FORCE");
5894 if (val) {
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07005895 novap_reset(dut, intf, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005896 if (strcasecmp(val, "Enable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305897 if (sta_set_rts(dut, intf, 64) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02005898 sigma_dut_print(dut, DUT_MSG_ERROR,
5899 "Failed to set RTS_FORCE 64");
5900 }
Jouni Malinen3aa72862019-05-29 23:14:51 +03005901 res = snprintf(buf, sizeof(buf),
5902 "wifitool %s beeliner_fw_test 100 1",
5903 intf);
5904 if (res < 0 || res >= sizeof(buf) || system(buf) != 0) {
priyadharshini gowthaman270870e2015-12-09 10:10:23 -08005905 sigma_dut_print(dut, DUT_MSG_ERROR,
5906 "wifitool beeliner_fw_test 100 1 failed");
5907 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005908 } else if (strcasecmp(val, "Disable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305909 if (sta_set_rts(dut, intf, 2347) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02005910 sigma_dut_print(dut, DUT_MSG_ERROR,
5911 "Failed to set RTS_FORCE 2347");
5912 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005913 } else {
5914 send_resp(dut, conn, SIGMA_ERROR,
5915 "ErrorCode,RTS_FORCE value not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03005916 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005917 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005918 }
5919
5920 val = get_param(cmd, "CTS_WIDTH");
5921 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005922 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005923 case DRIVER_WCN:
5924 if (wcn_sta_set_cts_width(dut, intf, val) < 0) {
5925 send_resp(dut, conn, SIGMA_ERROR,
5926 "ErrorCode,Failed to set CTS_WIDTH");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03005927 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005928 }
5929 break;
5930 case DRIVER_ATHEROS:
5931 ath_set_cts_width(dut, intf, val);
5932 break;
5933 default:
5934 sigma_dut_print(dut, DUT_MSG_ERROR,
5935 "Setting CTS_WIDTH not supported");
5936 break;
5937 }
5938 }
5939
5940 val = get_param(cmd, "BW_SGNL");
5941 if (val) {
5942 if (strcasecmp(val, "Enable") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005943 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005944 } else if (strcasecmp(val, "Disable") == 0) {
5945 /* TODO: Disable */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005946 } else {
5947 send_resp(dut, conn, SIGMA_ERROR,
5948 "ErrorCode,BW_SGNL value not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03005949 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005950 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005951 }
5952
5953 val = get_param(cmd, "Band");
5954 if (val) {
5955 if (strcmp(val, "2.4") == 0 || strcmp(val, "5") == 0) {
5956 /* STA supports all bands by default */
5957 } else {
5958 send_resp(dut, conn, SIGMA_ERROR,
5959 "ErrorCode,Unsupported Band");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03005960 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005961 }
5962 }
5963
5964 val = get_param(cmd, "zero_crc");
5965 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005966 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005967 case DRIVER_ATHEROS:
5968 ath_set_zero_crc(dut, val);
5969 break;
5970 default:
5971 break;
5972 }
5973 }
5974
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03005975 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005976}
5977
5978
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005979static int sta_set_force_mcs(struct sigma_dut *dut, int force, int mcs)
5980{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005981 switch (get_driver_type(dut)) {
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005982#ifdef __linux__
5983 case DRIVER_WIL6210:
5984 return wil6210_set_force_mcs(dut, force, mcs);
5985#endif /* __linux__ */
5986 default:
5987 sigma_dut_print(dut, DUT_MSG_ERROR,
5988 "Unsupported sta_set_force_mcs with the current driver");
5989 return -1;
5990 }
5991}
5992
5993
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02005994static int sta_60g_force_rsn_ie(struct sigma_dut *dut, int state)
5995{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005996 switch (get_driver_type(dut)) {
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02005997#ifdef __linux__
5998 case DRIVER_WIL6210:
5999 return wil6210_force_rsn_ie(dut, state);
6000#endif /* __linux__ */
6001 default:
6002 sigma_dut_print(dut, DUT_MSG_ERROR,
6003 "Unsupported sta_60g_force_rsn_ie with the current driver");
6004 return -1;
6005 }
6006}
6007
6008
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006009static int sta_set_60g_common(struct sigma_dut *dut, struct sigma_conn *conn,
6010 struct sigma_cmd *cmd)
6011{
6012 const char *val;
6013 char buf[100];
6014
6015 val = get_param(cmd, "MSDUSize");
6016 if (val) {
6017 int mtu;
6018
6019 dut->amsdu_size = atoi(val);
6020 if (dut->amsdu_size > IEEE80211_MAX_DATA_LEN_DMG ||
6021 dut->amsdu_size < IEEE80211_SNAP_LEN_DMG) {
6022 sigma_dut_print(dut, DUT_MSG_ERROR,
6023 "MSDUSize %d is above max %d or below min %d",
6024 dut->amsdu_size,
6025 IEEE80211_MAX_DATA_LEN_DMG,
6026 IEEE80211_SNAP_LEN_DMG);
6027 dut->amsdu_size = 0;
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006028 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006029 }
6030
6031 mtu = dut->amsdu_size - IEEE80211_SNAP_LEN_DMG;
6032 sigma_dut_print(dut, DUT_MSG_DEBUG,
6033 "Setting amsdu_size to %d", mtu);
6034 snprintf(buf, sizeof(buf), "ifconfig %s mtu %d",
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006035 get_station_ifname(dut), mtu);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006036
6037 if (system(buf) != 0) {
6038 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
6039 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006040 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006041 }
6042 }
6043
6044 val = get_param(cmd, "BAckRcvBuf");
6045 if (val) {
6046 dut->back_rcv_buf = atoi(val);
6047 if (dut->back_rcv_buf == 0) {
6048 sigma_dut_print(dut, DUT_MSG_ERROR,
6049 "Failed to convert %s or value is 0",
6050 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006051 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006052 }
6053
6054 sigma_dut_print(dut, DUT_MSG_DEBUG,
6055 "Setting BAckRcvBuf to %s", val);
6056 }
6057
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006058 val = get_param(cmd, "MCS_FixedRate");
6059 if (val) {
6060 if (sta_set_force_mcs(dut, 1, atoi(val))) {
6061 sigma_dut_print(dut, DUT_MSG_ERROR,
6062 "Failed to force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006063 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006064 }
6065 }
6066
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006067 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006068}
6069
6070
6071static int sta_pcp_start(struct sigma_dut *dut, struct sigma_conn *conn,
6072 struct sigma_cmd *cmd)
6073{
6074 int net_id;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006075 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006076 const char *val;
6077 char buf[100];
6078
6079 dut->mode = SIGMA_MODE_STATION;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006080 ifname = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006081 if (wpa_command(ifname, "PING") != 0) {
6082 sigma_dut_print(dut, DUT_MSG_ERROR, "Supplicant not running");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006083 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006084 }
6085
6086 wpa_command(ifname, "FLUSH");
6087 net_id = add_network_common(dut, conn, ifname, cmd);
6088 if (net_id < 0) {
6089 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add network");
6090 return net_id;
6091 }
6092
6093 /* TODO: mode=2 for the AP; in the future, replace for mode PCP */
6094 if (set_network(ifname, net_id, "mode", "2") < 0) {
6095 sigma_dut_print(dut, DUT_MSG_ERROR,
6096 "Failed to set supplicant network mode");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006097 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006098 }
6099
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02006100 if (set_network(ifname, net_id, "pbss", "1") < 0)
6101 return -2;
6102
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006103 sigma_dut_print(dut, DUT_MSG_DEBUG,
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02006104 "Supplicant set network with mode 2. network_id %d",
6105 net_id);
6106
6107 if (set_network(ifname, net_id, "wps_disabled", "0") < 0) {
6108 sigma_dut_print(dut, DUT_MSG_INFO,
6109 "Failed to set supplicant to WPS ENABLE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006110 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02006111 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006112
6113 val = get_param(cmd, "Security");
6114 if (val && strcasecmp(val, "OPEN") == 0) {
6115 dut->ap_key_mgmt = AP_OPEN;
6116 if (set_network(ifname, net_id, "key_mgmt", "NONE") < 0) {
6117 sigma_dut_print(dut, DUT_MSG_ERROR,
6118 "Failed to set supplicant to %s security",
6119 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006120 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006121 }
6122 } else if (val && strcasecmp(val, "WPA2-PSK") == 0) {
6123 dut->ap_key_mgmt = AP_WPA2_PSK;
6124 if (set_network(ifname, net_id, "key_mgmt", "WPA-PSK") < 0) {
6125 sigma_dut_print(dut, DUT_MSG_ERROR,
6126 "Failed to set supplicant to %s security",
6127 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006128 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006129 }
6130
6131 if (set_network(ifname, net_id, "proto", "RSN") < 0) {
6132 sigma_dut_print(dut, DUT_MSG_ERROR,
6133 "Failed to set supplicant to proto RSN");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006134 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006135 }
6136 } else if (val) {
6137 sigma_dut_print(dut, DUT_MSG_ERROR,
6138 "Requested Security %s is not supported on 60GHz",
6139 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006140 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006141 }
6142
6143 val = get_param(cmd, "Encrypt");
6144 if (val && strcasecmp(val, "AES-GCMP") == 0) {
6145 if (set_network(ifname, net_id, "pairwise", "GCMP") < 0) {
6146 sigma_dut_print(dut, DUT_MSG_ERROR,
6147 "Failed to set supplicant to pairwise GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006148 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006149 }
6150 if (set_network(ifname, net_id, "group", "GCMP") < 0) {
6151 sigma_dut_print(dut, DUT_MSG_ERROR,
6152 "Failed to set supplicant to group GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006153 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006154 }
6155 } else if (val) {
6156 sigma_dut_print(dut, DUT_MSG_ERROR,
6157 "Requested Encrypt %s is not supported on 60 GHz",
6158 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006159 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006160 }
6161
6162 val = get_param(cmd, "PSK");
6163 if (val && set_network_quoted(ifname, net_id, "psk", val) < 0) {
6164 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set psk %s",
6165 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006166 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006167 }
6168
6169 /* Convert 60G channel to freq */
6170 switch (dut->ap_channel) {
6171 case 1:
6172 val = "58320";
6173 break;
6174 case 2:
6175 val = "60480";
6176 break;
6177 case 3:
6178 val = "62640";
6179 break;
6180 default:
6181 sigma_dut_print(dut, DUT_MSG_ERROR,
6182 "Failed to configure channel %d. Not supported",
6183 dut->ap_channel);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006184 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006185 }
6186
6187 if (set_network(ifname, net_id, "frequency", val) < 0) {
6188 sigma_dut_print(dut, DUT_MSG_ERROR,
6189 "Failed to set supplicant network frequency");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006190 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006191 }
6192
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02006193 if (dut->eap_fragment) {
6194 sigma_dut_print(dut, DUT_MSG_DEBUG,
6195 "Set EAP fragment size to 128 bytes.");
6196 if (set_network(ifname, net_id, "fragment_size", "128") < 0)
6197 return ERROR_SEND_STATUS;
6198 }
6199
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006200 sigma_dut_print(dut, DUT_MSG_DEBUG,
6201 "Supplicant set network with frequency");
6202
6203 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d", net_id);
6204 if (wpa_command(ifname, buf) < 0) {
6205 sigma_dut_print(dut, DUT_MSG_INFO,
6206 "Failed to select network id %d on %s",
6207 net_id, ifname);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006208 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006209 }
6210
6211 sigma_dut_print(dut, DUT_MSG_DEBUG, "Selected network");
6212
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006213 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006214}
6215
6216
Lior David67543f52017-01-03 19:04:22 +02006217static int wil6210_set_abft_len(struct sigma_dut *dut, int abft_len)
6218{
6219 char buf[128], fname[128];
6220 FILE *f;
Jouni Malinen3aa72862019-05-29 23:14:51 +03006221 int res;
Lior David67543f52017-01-03 19:04:22 +02006222
6223 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
6224 sigma_dut_print(dut, DUT_MSG_ERROR,
6225 "failed to get wil6210 debugfs dir");
6226 return -1;
6227 }
6228
Jouni Malinen3aa72862019-05-29 23:14:51 +03006229 res = snprintf(fname, sizeof(fname), "%s/abft_len", buf);
6230 if (res < 0 || res >= sizeof(fname))
6231 return -1;
Lior David67543f52017-01-03 19:04:22 +02006232 f = fopen(fname, "w");
6233 if (!f) {
6234 sigma_dut_print(dut, DUT_MSG_ERROR,
6235 "failed to open: %s", fname);
6236 return -1;
6237 }
6238
6239 fprintf(f, "%d\n", abft_len);
6240 fclose(f);
6241
6242 return 0;
6243}
6244
6245
Alexei Avshalom Lazar49498b82019-01-31 15:16:32 +02006246int sta_set_60g_abft_len(struct sigma_dut *dut, struct sigma_conn *conn,
6247 int abft_len)
Lior David67543f52017-01-03 19:04:22 +02006248{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006249 switch (get_driver_type(dut)) {
Lior David67543f52017-01-03 19:04:22 +02006250 case DRIVER_WIL6210:
6251 return wil6210_set_abft_len(dut, abft_len);
6252 default:
6253 sigma_dut_print(dut, DUT_MSG_ERROR,
6254 "set abft_len not supported");
6255 return -1;
6256 }
6257}
6258
6259
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006260static int sta_set_60g_pcp(struct sigma_dut *dut, struct sigma_conn *conn,
6261 struct sigma_cmd *cmd)
6262{
6263 const char *val;
Lior David67543f52017-01-03 19:04:22 +02006264 unsigned int abft_len = 1; /* default is one slot */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006265
6266 if (dut->dev_role != DEVROLE_PCP) {
6267 send_resp(dut, conn, SIGMA_INVALID,
6268 "ErrorCode,Invalid DevRole");
6269 return 0;
6270 }
6271
6272 val = get_param(cmd, "SSID");
6273 if (val) {
6274 if (strlen(val) > sizeof(dut->ap_ssid) - 1) {
6275 send_resp(dut, conn, SIGMA_INVALID,
6276 "ErrorCode,Invalid SSID");
6277 return -1;
6278 }
6279
Peng Xub8fc5cc2017-05-10 17:27:28 -07006280 strlcpy(dut->ap_ssid, val, sizeof(dut->ap_ssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006281 }
6282
6283 val = get_param(cmd, "CHANNEL");
6284 if (val) {
6285 const char *pos;
6286
6287 dut->ap_channel = atoi(val);
6288 pos = strchr(val, ';');
6289 if (pos) {
6290 pos++;
6291 dut->ap_channel_1 = atoi(pos);
6292 }
6293 }
6294
6295 switch (dut->ap_channel) {
6296 case 1:
6297 case 2:
6298 case 3:
6299 break;
6300 default:
6301 sigma_dut_print(dut, DUT_MSG_ERROR,
6302 "Channel %d is not supported", dut->ap_channel);
6303 send_resp(dut, conn, SIGMA_ERROR,
6304 "Requested channel is not supported");
6305 return -1;
6306 }
6307
6308 val = get_param(cmd, "BCNINT");
6309 if (val)
6310 dut->ap_bcnint = atoi(val);
6311
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006312 val = get_param(cmd, "AllocType");
6313 if (val) {
6314 send_resp(dut, conn, SIGMA_ERROR,
6315 "ErrorCode,AllocType is not supported yet");
6316 return -1;
6317 }
6318
6319 val = get_param(cmd, "PercentBI");
6320 if (val) {
6321 send_resp(dut, conn, SIGMA_ERROR,
6322 "ErrorCode,PercentBI is not supported yet");
6323 return -1;
6324 }
6325
6326 val = get_param(cmd, "CBAPOnly");
6327 if (val) {
6328 send_resp(dut, conn, SIGMA_ERROR,
6329 "ErrorCode,CBAPOnly is not supported yet");
6330 return -1;
6331 }
6332
6333 val = get_param(cmd, "AMPDU");
6334 if (val) {
6335 if (strcasecmp(val, "Enable") == 0)
6336 dut->ap_ampdu = 1;
6337 else if (strcasecmp(val, "Disable") == 0)
6338 dut->ap_ampdu = 2;
6339 else {
6340 send_resp(dut, conn, SIGMA_ERROR,
6341 "ErrorCode,AMPDU value is not Enable nor Disabled");
6342 return -1;
6343 }
6344 }
6345
6346 val = get_param(cmd, "AMSDU");
6347 if (val) {
6348 if (strcasecmp(val, "Enable") == 0)
6349 dut->ap_amsdu = 1;
6350 else if (strcasecmp(val, "Disable") == 0)
6351 dut->ap_amsdu = 2;
6352 }
6353
6354 val = get_param(cmd, "NumMSDU");
6355 if (val) {
6356 send_resp(dut, conn, SIGMA_ERROR,
6357 "ErrorCode, NumMSDU is not supported yet");
6358 return -1;
6359 }
6360
6361 val = get_param(cmd, "ABFTLRang");
6362 if (val) {
6363 sigma_dut_print(dut, DUT_MSG_DEBUG,
Lior David67543f52017-01-03 19:04:22 +02006364 "ABFTLRang parameter %s", val);
6365 if (strcmp(val, "Gt1") == 0)
6366 abft_len = 2; /* 2 slots in this case */
6367 }
6368
6369 if (sta_set_60g_abft_len(dut, conn, abft_len)) {
6370 send_resp(dut, conn, SIGMA_ERROR,
6371 "ErrorCode, Can't set ABFT length");
6372 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006373 }
6374
6375 if (sta_pcp_start(dut, conn, cmd) < 0) {
6376 send_resp(dut, conn, SIGMA_ERROR,
6377 "ErrorCode, Can't start PCP role");
6378 return -1;
6379 }
6380
6381 return sta_set_60g_common(dut, conn, cmd);
6382}
6383
6384
6385static int sta_set_60g_sta(struct sigma_dut *dut, struct sigma_conn *conn,
6386 struct sigma_cmd *cmd)
6387{
6388 const char *val = get_param(cmd, "DiscoveryMode");
6389
6390 if (dut->dev_role != DEVROLE_STA) {
6391 send_resp(dut, conn, SIGMA_INVALID,
6392 "ErrorCode,Invalid DevRole");
6393 return 0;
6394 }
6395
6396 if (val) {
6397 sigma_dut_print(dut, DUT_MSG_DEBUG, "Discovery: %s", val);
6398 /* Ignore Discovery mode till Driver expose API. */
6399#if 0
6400 if (strcasecmp(val, "1") == 0) {
6401 send_resp(dut, conn, SIGMA_INVALID,
6402 "ErrorCode,DiscoveryMode 1 not supported");
6403 return 0;
6404 }
6405
6406 if (strcasecmp(val, "0") == 0) {
6407 /* OK */
6408 } else {
6409 send_resp(dut, conn, SIGMA_INVALID,
6410 "ErrorCode,DiscoveryMode not supported");
6411 return 0;
6412 }
6413#endif
6414 }
6415
6416 if (start_sta_mode(dut) != 0)
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006417 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006418 return sta_set_60g_common(dut, conn, cmd);
6419}
6420
6421
Jouni Malinenf7222712019-06-13 01:50:21 +03006422static enum sigma_cmd_result cmd_sta_disconnect(struct sigma_dut *dut,
6423 struct sigma_conn *conn,
6424 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006425{
6426 const char *intf = get_param(cmd, "Interface");
Jouni Malinened77e672018-01-10 16:45:13 +02006427 const char *val = get_param(cmd, "maintain_profile");
vamsi krishnad605c422017-09-20 14:56:31 +05306428
Jouni Malinened77e672018-01-10 16:45:13 +02006429 if (dut->program == PROGRAM_OCE ||
Amarnath Hullur Subramanyamebeda9e2018-01-31 03:21:48 -08006430 dut->program == PROGRAM_HE ||
Jouni Malinened77e672018-01-10 16:45:13 +02006431 (val && atoi(val) == 1)) {
vamsi krishnad605c422017-09-20 14:56:31 +05306432 wpa_command(intf, "DISCONNECT");
6433 return 1;
6434 }
6435
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006436 disconnect_station(dut);
6437 /* Try to ignore old scan results to avoid HS 2.0R2 test case failures
6438 * due to cached results. */
6439 wpa_command(intf, "SET ignore_old_scan_res 1");
6440 wpa_command(intf, "BSS_FLUSH");
6441 return 1;
6442}
6443
6444
Jouni Malinenf7222712019-06-13 01:50:21 +03006445static enum sigma_cmd_result cmd_sta_reassoc(struct sigma_dut *dut,
6446 struct sigma_conn *conn,
6447 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006448{
6449 const char *intf = get_param(cmd, "Interface");
6450 const char *bssid = get_param(cmd, "bssid");
6451 const char *val = get_param(cmd, "CHANNEL");
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006452 const char *freq_val = get_param(cmd, "ChnlFreq");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006453 struct wpa_ctrl *ctrl;
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306454 char buf[1000];
Sunil Duttd30ce092018-01-11 23:56:29 +05306455 char result[32];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006456 int res;
6457 int chan = 0;
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006458 int freq = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006459 enum sigma_cmd_result status = STATUS_SENT;
Sunil Duttd30ce092018-01-11 23:56:29 +05306460 int fastreassoc = 1;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006461 int ft_ds = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006462
6463 if (bssid == NULL) {
6464 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing bssid "
6465 "argument");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006466 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006467 }
6468
6469 if (val)
6470 chan = atoi(val);
6471
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006472 if (freq_val)
6473 freq = atoi(freq_val);
6474
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006475 if (wifi_chip_type != DRIVER_WCN && wifi_chip_type != DRIVER_AR6003) {
6476 /* The current network may be from sta_associate or
6477 * sta_hs2_associate
6478 */
6479 if (set_network(intf, dut->infra_network_id, "bssid", bssid) <
6480 0 ||
6481 set_network(intf, 0, "bssid", bssid) < 0)
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006482 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006483 }
6484
6485 ctrl = open_wpa_mon(intf);
6486 if (ctrl == NULL) {
6487 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
6488 "wpa_supplicant monitor connection");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006489 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006490 }
6491
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006492 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Sunil Duttd30ce092018-01-11 23:56:29 +05306493 sizeof(result)) < 0 ||
6494 strncmp(result, "COMPLETED", 9) != 0) {
6495 sigma_dut_print(dut, DUT_MSG_DEBUG,
6496 "sta_reassoc: Not connected");
6497 fastreassoc = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006498 } else if (dut->sta_ft_ds) {
6499 sigma_dut_print(dut, DUT_MSG_DEBUG,
6500 "sta_reassoc: Use FT-over-DS");
6501 ft_ds = 1;
Sunil Duttd30ce092018-01-11 23:56:29 +05306502 }
6503
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306504 if (dut->rsne_override) {
6505#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006506 if (get_driver_type(dut) == DRIVER_WCN &&
6507 dut->config_rsnie == 0) {
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05306508 sta_config_params(dut, intf, STA_SET_RSNIE, 1);
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306509 dut->config_rsnie = 1;
6510 }
6511#endif /* NL80211_SUPPORT */
6512 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
6513 dut->rsne_override);
6514 if (wpa_command(intf, buf) < 0) {
6515 send_resp(dut, conn, SIGMA_ERROR,
6516 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
6517 return 0;
6518 }
6519 }
6520
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006521 if (ft_ds) {
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006522 if (chan || freq) {
6523 if (!freq)
6524 freq = channel_to_freq(dut, chan);
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006525 if (!freq) {
6526 sigma_dut_print(dut, DUT_MSG_ERROR,
6527 "Invalid channel number provided: %d",
6528 chan);
6529 send_resp(dut, conn, SIGMA_INVALID,
6530 "ErrorCode,Invalid channel number");
6531 goto close_mon_conn;
6532 }
6533 res = snprintf(buf, sizeof(buf),
6534 "SCAN TYPE=ONLY freq=%d", freq);
6535 } else {
6536 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
6537 }
6538 if (res < 0 || res >= (int) sizeof(buf)) {
6539 send_resp(dut, conn, SIGMA_ERROR,
6540 "ErrorCode,snprintf failed");
6541 goto close_mon_conn;
6542 }
6543 if (wpa_command(intf, buf) < 0) {
6544 sigma_dut_print(dut, DUT_MSG_INFO,
6545 "Failed to start scan");
6546 send_resp(dut, conn, SIGMA_ERROR,
6547 "ErrorCode,scan failed");
6548 goto close_mon_conn;
6549 }
6550
6551 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
6552 buf, sizeof(buf));
6553 if (res < 0) {
6554 sigma_dut_print(dut, DUT_MSG_INFO,
6555 "Scan did not complete");
6556 send_resp(dut, conn, SIGMA_ERROR,
6557 "ErrorCode,scan did not complete");
6558 goto close_mon_conn;
6559 }
6560
6561 res = snprintf(buf, sizeof(buf), "FT_DS %s", bssid);
6562 if (res > 0 && res < (int) sizeof(buf))
6563 res = wpa_command(intf, buf);
6564
6565 if (res < 0 || res >= (int) sizeof(buf)) {
6566 send_resp(dut, conn, SIGMA_ERROR,
6567 "errorCode,FT_DS command failed");
6568 status = STATUS_SENT_ERROR;
6569 goto close_mon_conn;
6570 }
6571 } else if (wifi_chip_type == DRIVER_WCN && fastreassoc) {
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006572 if (chan || freq) {
6573 if (!freq)
6574 freq = channel_to_freq(dut, chan);
Ashwini Patil4c8158f2017-05-25 12:49:21 +05306575 if (!freq) {
6576 sigma_dut_print(dut, DUT_MSG_ERROR,
6577 "Invalid channel number provided: %d",
6578 chan);
6579 send_resp(dut, conn, SIGMA_INVALID,
6580 "ErrorCode,Invalid channel number");
6581 goto close_mon_conn;
6582 }
6583 res = snprintf(buf, sizeof(buf),
6584 "SCAN TYPE=ONLY freq=%d", freq);
6585 } else {
6586 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
6587 }
6588 if (res < 0 || res >= (int) sizeof(buf)) {
6589 send_resp(dut, conn, SIGMA_ERROR,
6590 "ErrorCode,snprintf failed");
6591 goto close_mon_conn;
6592 }
6593 if (wpa_command(intf, buf) < 0) {
6594 sigma_dut_print(dut, DUT_MSG_INFO,
6595 "Failed to start scan");
6596 send_resp(dut, conn, SIGMA_ERROR,
6597 "ErrorCode,scan failed");
6598 goto close_mon_conn;
6599 }
6600
6601 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
6602 buf, sizeof(buf));
6603 if (res < 0) {
6604 sigma_dut_print(dut, DUT_MSG_INFO,
6605 "Scan did not complete");
6606 send_resp(dut, conn, SIGMA_ERROR,
6607 "ErrorCode,scan did not complete");
6608 goto close_mon_conn;
6609 }
6610
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006611 if (set_network(intf, dut->infra_network_id, "bssid", "any")
6612 < 0) {
6613 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
6614 "bssid to any during FASTREASSOC");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006615 status = ERROR_SEND_STATUS;
Ashwini Patil467efef2017-05-25 12:18:27 +05306616 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006617 }
Vinita Maloo54b78cf2020-03-30 12:18:19 +05306618 res = snprintf(buf, sizeof(buf), "FASTREASSOC %s %d",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006619 bssid, chan);
Vinita Maloo54b78cf2020-03-30 12:18:19 +05306620 if (res < 0 || res >= (int) sizeof(buf) ||
6621 wcn_driver_cmd(intf, buf) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006622 send_resp(dut, conn, SIGMA_ERROR,
Vinita Maloo54b78cf2020-03-30 12:18:19 +05306623 "errorCode,Failed to run FASTREASSOC");
Ashwini Patil467efef2017-05-25 12:18:27 +05306624 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006625 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006626 sigma_dut_print(dut, DUT_MSG_INFO,
6627 "sta_reassoc: Run %s successful", buf);
6628 } else if (wpa_command(intf, "REASSOCIATE")) {
6629 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
6630 "request reassociation");
Ashwini Patil467efef2017-05-25 12:18:27 +05306631 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006632 }
6633
6634 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
6635 buf, sizeof(buf));
Ashwini Patil467efef2017-05-25 12:18:27 +05306636 if (res < 0) {
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006637 send_resp(dut, conn, SIGMA_ERROR,
6638 "errorCode,Connection did not complete");
6639 status = STATUS_SENT_ERROR;
Ashwini Patil467efef2017-05-25 12:18:27 +05306640 goto close_mon_conn;
6641 }
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006642 status = SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006643
Ashwini Patil467efef2017-05-25 12:18:27 +05306644close_mon_conn:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006645 wpa_ctrl_detach(ctrl);
6646 wpa_ctrl_close(ctrl);
Ashwini Patil467efef2017-05-25 12:18:27 +05306647 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006648}
6649
6650
6651static void hs2_clear_credentials(const char *intf)
6652{
6653 wpa_command(intf, "REMOVE_CRED all");
6654}
6655
6656
Lior Davidcc88b562017-01-03 18:52:09 +02006657#ifdef __linux__
6658static int wil6210_get_aid(struct sigma_dut *dut, const char *bssid,
6659 unsigned int *aid)
6660{
Lior David0fe101e2017-03-09 16:09:50 +02006661 const char *pattern = "AID[ \t]+([0-9]+)";
Lior Davidcc88b562017-01-03 18:52:09 +02006662
Lior David0fe101e2017-03-09 16:09:50 +02006663 return wil6210_get_sta_info_field(dut, bssid, pattern, aid);
Lior Davidcc88b562017-01-03 18:52:09 +02006664}
6665#endif /* __linux__ */
6666
6667
6668static int sta_get_aid_60g(struct sigma_dut *dut, const char *bssid,
6669 unsigned int *aid)
6670{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006671 switch (get_driver_type(dut)) {
Lior Davidcc88b562017-01-03 18:52:09 +02006672#ifdef __linux__
6673 case DRIVER_WIL6210:
6674 return wil6210_get_aid(dut, bssid, aid);
6675#endif /* __linux__ */
6676 default:
6677 sigma_dut_print(dut, DUT_MSG_ERROR, "get AID not supported");
6678 return -1;
6679 }
6680}
6681
6682
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006683static int sta_get_parameter_60g(struct sigma_dut *dut, struct sigma_conn *conn,
6684 struct sigma_cmd *cmd)
6685{
6686 char buf[MAX_CMD_LEN];
6687 char bss_list[MAX_CMD_LEN];
6688 const char *parameter = get_param(cmd, "Parameter");
6689
6690 if (parameter == NULL)
6691 return -1;
6692
Lior Davidcc88b562017-01-03 18:52:09 +02006693 if (strcasecmp(parameter, "AID") == 0) {
6694 unsigned int aid = 0;
6695 char bssid[20];
6696
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006697 if (get_wpa_status(get_station_ifname(dut), "bssid",
Lior Davidcc88b562017-01-03 18:52:09 +02006698 bssid, sizeof(bssid)) < 0) {
6699 sigma_dut_print(dut, DUT_MSG_ERROR,
6700 "could not get bssid");
6701 return -2;
6702 }
6703
6704 if (sta_get_aid_60g(dut, bssid, &aid))
6705 return -2;
6706
6707 snprintf(buf, sizeof(buf), "aid,%d", aid);
6708 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
6709 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6710 return 0;
6711 }
6712
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006713 if (strcasecmp(parameter, "DiscoveredDevList") == 0) {
6714 char *bss_line;
6715 char *bss_id = NULL;
6716 const char *ifname = get_param(cmd, "Interface");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306717 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006718
6719 if (ifname == NULL) {
6720 sigma_dut_print(dut, DUT_MSG_INFO,
6721 "For get DiscoveredDevList need Interface name.");
6722 return -1;
6723 }
6724
6725 /*
6726 * Use "BSS RANGE=ALL MASK=0x2" which provides a list
6727 * of BSSIDs in "bssid=<BSSID>\n"
6728 */
6729 if (wpa_command_resp(ifname, "BSS RANGE=ALL MASK=0x2",
6730 bss_list,
6731 sizeof(bss_list)) < 0) {
6732 sigma_dut_print(dut, DUT_MSG_ERROR,
6733 "Failed to get bss list");
6734 return -1;
6735 }
6736
6737 sigma_dut_print(dut, DUT_MSG_DEBUG,
6738 "bss list for ifname:%s is:%s",
6739 ifname, bss_list);
6740
6741 snprintf(buf, sizeof(buf), "DeviceList");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306742 bss_line = strtok_r(bss_list, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006743 while (bss_line) {
6744 if (sscanf(bss_line, "bssid=%ms", &bss_id) > 0 &&
6745 bss_id) {
6746 int len;
6747
6748 len = snprintf(buf + strlen(buf),
6749 sizeof(buf) - strlen(buf),
6750 ",%s", bss_id);
6751 free(bss_id);
6752 bss_id = NULL;
6753 if (len < 0) {
6754 sigma_dut_print(dut,
6755 DUT_MSG_ERROR,
6756 "Failed to read BSSID");
6757 send_resp(dut, conn, SIGMA_ERROR,
6758 "ErrorCode,Failed to read BSS ID");
6759 return 0;
6760 }
6761
6762 if ((size_t) len >= sizeof(buf) - strlen(buf)) {
6763 sigma_dut_print(dut,
6764 DUT_MSG_ERROR,
6765 "Response buf too small for list");
6766 send_resp(dut, conn,
6767 SIGMA_ERROR,
6768 "ErrorCode,Response buf too small for list");
6769 return 0;
6770 }
6771 }
6772
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306773 bss_line = strtok_r(NULL, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006774 }
6775
6776 sigma_dut_print(dut, DUT_MSG_INFO, "DiscoveredDevList is %s",
6777 buf);
6778 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6779 return 0;
6780 }
6781
6782 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6783 return 0;
6784}
6785
6786
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006787static int sta_get_parameter_he(struct sigma_dut *dut, struct sigma_conn *conn,
6788 struct sigma_cmd *cmd)
6789{
6790 char buf[MAX_CMD_LEN];
6791 const char *parameter = get_param(cmd, "Parameter");
6792
6793 if (!parameter)
6794 return -1;
6795
6796 if (strcasecmp(parameter, "RSSI") == 0) {
6797 char rssi[10];
6798
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006799 if (get_wpa_signal_poll(dut, get_station_ifname(dut), "RSSI",
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006800 rssi, sizeof(rssi)) < 0) {
6801 sigma_dut_print(dut, DUT_MSG_ERROR,
6802 "Could not get RSSI");
6803 return -2;
6804 }
6805
6806 snprintf(buf, sizeof(buf), "rssi,%s", rssi);
6807 sigma_dut_print(dut, DUT_MSG_INFO, "RSSI %s", buf);
6808 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6809 return 0;
6810 }
6811
6812 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6813 return 0;
6814}
6815
6816
Veerendranath Jakkamd0ad6ef2020-05-21 17:09:26 +05306817#ifdef NL80211_SUPPORT
6818
6819struct station_info {
6820 uint64_t filled;
6821 uint32_t beacon_mic_error_count;
6822 uint32_t beacon_replay_count;
6823};
6824
6825
6826static int qca_get_sta_info_handler(struct nl_msg *msg, void *arg)
6827{
6828 struct nlattr *tb[NL80211_ATTR_MAX + 1];
6829 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
6830 struct station_info *data = arg;
6831 struct nlattr *info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_MAX + 1];
6832 static struct nla_policy info_policy[
6833 QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_MAX + 1] = {
6834 [QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT] = {
6835 .type = NLA_U32
6836 },
6837 [QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT] = {
6838 .type = NLA_U32
6839 },
6840 };
6841
6842 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
6843 genlmsg_attrlen(gnlh, 0), NULL);
6844
6845 if (!tb[NL80211_ATTR_VENDOR_DATA])
6846 return NL_SKIP;
6847
6848 if (nla_parse_nested(info, QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_MAX,
6849 tb[NL80211_ATTR_VENDOR_DATA], info_policy)) {
6850 return NL_SKIP;
6851 }
6852
6853 if (info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT]) {
6854 data->filled |=
6855 BIT_ULL(QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT);
6856 data->beacon_mic_error_count =
6857 nla_get_u32(info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT]);
6858 }
6859
6860 if (info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT]) {
6861 data->filled |=
6862 BIT_ULL(QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT);
6863 data->beacon_replay_count =
6864 nla_get_u32(info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT]);
6865 }
6866
6867 return NL_SKIP;
6868}
6869
6870
6871static int qca_nl80211_get_sta_info(struct sigma_dut *dut, const char *intf,
6872 struct station_info *sta_data)
6873{
6874 struct nl_msg *msg;
6875 int ifindex, ret;
6876
6877 ifindex = if_nametoindex(intf);
6878 if (ifindex == 0) {
6879 sigma_dut_print(dut, DUT_MSG_ERROR,
6880 "%s: Index for interface %s not found",
6881 __func__, intf);
6882 return -1;
6883 }
6884
6885 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6886 NL80211_CMD_VENDOR)) ||
6887 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6888 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6889 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6890 QCA_NL80211_VENDOR_SUBCMD_GET_STA_INFO)) {
6891 sigma_dut_print(dut, DUT_MSG_ERROR,
6892 "%s: err in adding vendor_cmd", __func__);
6893 nlmsg_free(msg);
6894 return -1;
6895 }
6896
6897 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg,
6898 qca_get_sta_info_handler, sta_data);
6899 if (ret) {
6900 sigma_dut_print(dut, DUT_MSG_ERROR,
6901 "%s: err in send_and_recv_msgs, ret=%d",
6902 __func__, ret);
6903 }
6904 return ret;
6905}
6906#endif /* NL80211_SUPPORT */
6907
6908
6909static int get_bip_mic_error_count(struct sigma_dut *dut,
6910 const char *ifname,
6911 unsigned int *count)
6912{
6913#ifdef NL80211_SUPPORT
6914 struct station_info sta_data;
6915#endif /* NL80211_SUPPORT */
6916
6917 if (get_driver_type(dut) != DRIVER_WCN) {
6918 sigma_dut_print(dut, DUT_MSG_ERROR,
6919 "BIP MIC error count not supported");
6920 return -1;
6921 }
6922
6923#ifdef NL80211_SUPPORT
6924 if (qca_nl80211_get_sta_info(dut, ifname, &sta_data) != 0 ||
6925 !(sta_data.filled &
6926 BIT_ULL(QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT))) {
6927 sigma_dut_print(dut, DUT_MSG_ERROR,
6928 "BIP MIC error count fetching failed");
6929 return -1;
6930 }
6931
6932 *count = sta_data.beacon_mic_error_count;
6933 return 0;
6934#else /* NL80211_SUPPORT */
6935 sigma_dut_print(dut, DUT_MSG_ERROR,
6936 "BIP MIC error count cannot be fetched without NL80211_SUPPORT defined");
6937 return -1;
6938#endif /* NL80211_SUPPORT */
6939}
6940
6941
6942static int get_cmac_replay_count(struct sigma_dut *dut, const char *ifname,
6943 unsigned int *count)
6944{
6945#ifdef NL80211_SUPPORT
6946 struct station_info sta_data;
6947#endif /* NL80211_SUPPORT */
6948
6949 if (get_driver_type(dut) != DRIVER_WCN) {
6950 sigma_dut_print(dut, DUT_MSG_ERROR,
6951 "CMAC reply count not supported");
6952 return -1;
6953 }
6954
6955#ifdef NL80211_SUPPORT
6956 if (qca_nl80211_get_sta_info(dut, ifname, &sta_data) != 0 ||
6957 !(sta_data.filled &
6958 BIT_ULL(QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT))) {
6959 sigma_dut_print(dut, DUT_MSG_ERROR,
6960 "CMAC replay count fetching failed");
6961 return -1;
6962 }
6963
6964 *count = sta_data.beacon_replay_count;
6965 return 0;
6966#else /* NL80211_SUPPORT */
6967 sigma_dut_print(dut, DUT_MSG_ERROR,
6968 "CMAC replay count cannot be fetched without NL80211_SUPPORT defined");
6969 return -1;
6970#endif /* NL80211_SUPPORT */
6971}
6972
6973
6974static enum sigma_cmd_result sta_get_parameter_wpa3(struct sigma_dut *dut,
6975 struct sigma_conn *conn,
6976 struct sigma_cmd *cmd)
6977{
6978 char buf[MAX_CMD_LEN];
6979 const char *ifname = get_param(cmd, "interface");
6980 const char *parameter = get_param(cmd, "Parameter");
6981 unsigned int val;
6982
6983 if (!ifname || !parameter)
6984 return INVALID_SEND_STATUS;
6985
6986 if (strcasecmp(parameter, "BIPMICErrors") == 0) {
6987 if (get_bip_mic_error_count(dut, ifname, &val)) {
6988 send_resp(dut, conn, SIGMA_ERROR,
6989 "ErrorCode,Failed to get BIPMICErrors");
6990 return STATUS_SENT_ERROR;
6991 }
6992 snprintf(buf, sizeof(buf), "BIPMICErrors,%d", val);
6993 sigma_dut_print(dut, DUT_MSG_INFO, "BIPMICErrors %s", buf);
6994 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6995 return STATUS_SENT;
6996 }
6997
6998 if (strcasecmp(parameter, "CMACReplays") == 0) {
6999 if (get_cmac_replay_count(dut, ifname, &val)) {
7000 send_resp(dut, conn, SIGMA_ERROR,
7001 "ErrorCode,Failed to get CMACReplays");
7002 return STATUS_SENT_ERROR;
7003 }
7004 snprintf(buf, sizeof(buf), "CMACReplays,%d", val);
7005 sigma_dut_print(dut, DUT_MSG_INFO, "CMACReplays %s", buf);
7006 send_resp(dut, conn, SIGMA_COMPLETE, buf);
7007 return STATUS_SENT;
7008 }
7009
7010 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7011 return STATUS_SENT_ERROR;
7012}
7013
7014
Jouni Malinenca0abd32020-02-09 20:18:10 +02007015static enum sigma_cmd_result sta_get_pmk(struct sigma_dut *dut,
7016 struct sigma_conn *conn,
7017 struct sigma_cmd *cmd)
7018{
7019 const char *intf = get_param(cmd, "Interface");
7020 char buf[4096], bssid[20], resp[200], *pos, *tmp;
7021
7022 snprintf(buf, sizeof(buf), "PMKSA_GET %d", dut->infra_network_id);
7023 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
7024 strncmp(buf, "UNKNOWN COMMAND", 15) == 0) {
7025 send_resp(dut, conn, SIGMA_ERROR,
7026 "ErrorCode,PMKSA_GET not supported");
7027 return STATUS_SENT_ERROR;
7028 }
7029
7030 if (strncmp(buf, "FAIL", 4) == 0 ||
7031 get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
7032 send_resp(dut, conn, SIGMA_ERROR,
7033 "ErrorCode,Could not find current network");
7034 return STATUS_SENT_ERROR;
7035 }
7036
7037 pos = buf;
7038 while (pos) {
7039 if (strncmp(pos, bssid, 17) == 0) {
7040 pos = strchr(pos, ' ');
7041 if (!pos)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05307042 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02007043 pos++;
7044 pos = strchr(pos, ' ');
7045 if (!pos)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05307046 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02007047 pos++;
7048 tmp = strchr(pos, ' ');
7049 if (!tmp)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05307050 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02007051 *tmp = '\0';
7052 break;
7053 }
Jouni Malinenca0abd32020-02-09 20:18:10 +02007054 pos = strchr(pos, '\n');
7055 if (pos)
7056 pos++;
7057 }
7058
7059 if (!pos) {
7060 send_resp(dut, conn, SIGMA_ERROR,
7061 "ErrorCode,PMK not available");
7062 return STATUS_SENT_ERROR;
7063 }
7064
7065 snprintf(resp, sizeof(resp), "PMK,%s", pos);
7066 send_resp(dut, conn, SIGMA_COMPLETE, resp);
7067 return STATUS_SENT;
7068}
7069
7070
Jouni Malinenf7222712019-06-13 01:50:21 +03007071static enum sigma_cmd_result cmd_sta_get_parameter(struct sigma_dut *dut,
7072 struct sigma_conn *conn,
7073 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007074{
7075 const char *program = get_param(cmd, "Program");
Jouni Malinenca0abd32020-02-09 20:18:10 +02007076 const char *parameter = get_param(cmd, "Parameter");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007077
Jouni Malinenca0abd32020-02-09 20:18:10 +02007078 if (!parameter)
7079 return INVALID_SEND_STATUS;
7080
7081 if (strcasecmp(parameter, "PMK") == 0)
7082 return sta_get_pmk(dut, conn, cmd);
7083
7084 if (!program)
7085 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007086
7087 if (strcasecmp(program, "P2PNFC") == 0)
7088 return p2p_cmd_sta_get_parameter(dut, conn, cmd);
7089
7090 if (strcasecmp(program, "60ghz") == 0)
7091 return sta_get_parameter_60g(dut, conn, cmd);
7092
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07007093 if (strcasecmp(program, "he") == 0)
7094 return sta_get_parameter_he(dut, conn, cmd);
7095
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007096#ifdef ANDROID_NAN
7097 if (strcasecmp(program, "NAN") == 0)
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07007098 return nan_cmd_sta_get_parameter(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007099#endif /* ANDROID_NAN */
7100
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007101#ifdef MIRACAST
7102 if (strcasecmp(program, "WFD") == 0 ||
7103 strcasecmp(program, "DisplayR2") == 0)
7104 return miracast_cmd_sta_get_parameter(dut, conn, cmd);
7105#endif /* MIRACAST */
Veerendranath Jakkamd0ad6ef2020-05-21 17:09:26 +05307106 if (strcasecmp(program, "WPA3") == 0)
7107 return sta_get_parameter_wpa3(dut, conn, cmd);
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007108
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007109 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7110 return 0;
7111}
7112
7113
7114static void sta_reset_default_ath(struct sigma_dut *dut, const char *intf,
7115 const char *type)
7116{
7117 char buf[100];
7118
7119 if (dut->program == PROGRAM_VHT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007120 run_iwpriv(dut, intf, "chwidth 2");
7121 run_iwpriv(dut, intf, "mode 11ACVHT80");
7122 run_iwpriv(dut, intf, "vhtmcs -1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007123 }
7124
7125 if (dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007126 run_iwpriv(dut, intf, "chwidth 0");
7127 run_iwpriv(dut, intf, "mode 11naht40");
7128 run_iwpriv(dut, intf, "set11NRates 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007129 }
7130
7131 if (dut->program == PROGRAM_VHT || dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007132 run_iwpriv(dut, intf, "powersave 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007133
7134 /* Reset CTS width */
7135 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 54 0",
7136 intf);
7137 if (system(buf) != 0) {
7138 sigma_dut_print(dut, DUT_MSG_ERROR,
7139 "wifitool %s beeliner_fw_test 54 0 failed",
7140 intf);
7141 }
7142
7143 /* Enable Dynamic Bandwidth signalling by default */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007144 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007145
7146 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", intf);
7147 if (system(buf) != 0) {
7148 sigma_dut_print(dut, DUT_MSG_ERROR,
7149 "iwpriv rts failed");
7150 }
7151 }
7152
7153 if (type && strcasecmp(type, "Testbed") == 0) {
7154 dut->testbed_flag_txsp = 1;
7155 dut->testbed_flag_rxsp = 1;
7156 /* STA has to set spatial stream to 2 per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007157 run_iwpriv(dut, intf, "vht_mcsmap 0xfff0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007158
7159 /* Disable LDPC per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007160 run_iwpriv(dut, intf, "ldpc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007161
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007162 run_iwpriv(dut, intf, "amsdu 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007163
7164 /* TODO: Disable STBC 2x1 transmit and receive */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007165 run_iwpriv(dut, intf, "tx_stbc 0");
7166 run_iwpriv(dut, intf, "rx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007167
7168 /* STA has to disable Short GI per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007169 run_iwpriv(dut, intf, "shortgi 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007170 }
7171
7172 if (type && strcasecmp(type, "DUT") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007173 run_iwpriv(dut, intf, "nss 3");
Arif Hussainac6c5112018-05-25 17:34:00 -07007174 dut->sta_nss = 3;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007175
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007176 run_iwpriv(dut, intf, "shortgi 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007177 }
7178}
7179
7180
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007181#ifdef NL80211_SUPPORT
7182static int sta_set_he_mcs(struct sigma_dut *dut, const char *intf,
7183 enum he_mcs_config mcs)
7184{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307185 return wcn_wifi_test_config_set_u8(
7186 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MCS, mcs);
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007187}
7188#endif /* NL80211_SUPPORT */
7189
7190
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07007191static int sta_set_action_tx_in_he_tb_ppdu(struct sigma_dut *dut,
7192 const char *intf, int enable)
7193{
7194#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307195 return wcn_wifi_test_config_set_u8(
7196 dut, intf,
7197 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_ACTION_TX_TB_PPDU,
7198 enable);
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07007199#else /* NL80211_SUPPORT */
7200 sigma_dut_print(dut, DUT_MSG_ERROR,
7201 "HE action Tx TB PPDU cannot be set without NL80211_SUPPORT defined");
7202 return -1;
7203#endif /* NL80211_SUPPORT */
7204}
7205
7206
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08007207static int sta_set_heconfig_and_wep_tkip(struct sigma_dut *dut,
7208 const char *intf, int enable)
7209{
7210#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307211 return wcn_wifi_test_config_set_u8(
7212 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WEP_TKIP_IN_HE,
7213 enable);
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08007214#else /* NL80211_SUPPORT */
7215 sigma_dut_print(dut, DUT_MSG_ERROR,
7216 "HE config enablement cannot be changed without NL80211_SUPPORT defined");
7217 return -1;
7218#endif /* NL80211_SUPPORT */
7219}
7220
7221
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007222#ifdef NL80211_SUPPORT
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007223
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007224static int sta_set_he_testbed_def(struct sigma_dut *dut,
7225 const char *intf, int cfg)
7226{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307227 return wcn_wifi_test_config_set_u8(
7228 dut, intf,
7229 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SET_HE_TESTBED_DEFAULTS,
7230 cfg);
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007231}
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007232
7233
7234static int sta_set_2g_vht_supp(struct sigma_dut *dut, const char *intf, int cfg)
7235{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307236 return wcn_wifi_test_config_set_u8(
7237 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_2G_VHT,
7238 cfg);
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007239}
7240
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007241#endif /* NL80211_SUPPORT */
7242
7243
Qiwei Caib6806972020-01-15 13:52:11 +08007244int sta_set_addba_buf_size(struct sigma_dut *dut,
7245 const char *intf, int bufsize)
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007246{
7247#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307248 return wcn_wifi_test_config_set_u16(
7249 dut, intf,
7250 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE, bufsize);
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007251#else /* NL80211_SUPPORT */
7252 sigma_dut_print(dut, DUT_MSG_ERROR,
7253 "AddBA bufsize cannot be changed without NL80211_SUPPORT defined");
7254 return -1;
7255#endif /* NL80211_SUPPORT */
7256}
7257
7258
Kiran Kumar Lokere69d89952021-08-08 23:41:46 -07007259static int sta_set_scan_unicast_probe(struct sigma_dut *dut,
7260 const char *intf, int val)
7261{
7262#ifdef NL80211_SUPPORT
7263 return wcn_wifi_test_config_set_u8(
7264 dut, intf,
7265 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_USE_BSSID_IN_PROBE_REQ_RA,
7266 val);
7267#else /* NL80211_SUPPORT */
7268 sigma_dut_print(dut, DUT_MSG_ERROR,
7269 "Unicast RA in Probe Request frame cannot be set without NL80211_SUPPORT defined");
7270 return -1;
7271#endif /* NL80211_SUPPORT */
7272}
7273
7274
Kiran Kumar Lokere09dbcef2021-08-09 00:01:41 -07007275static int sta_set_rx_ctrl_multi_bss(struct sigma_dut *dut, const char *intf,
7276 int enable)
7277{
7278#ifdef NL80211_SUPPORT
7279 return wcn_wifi_test_config_set_u8(
7280 dut, intf,
7281 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_RX_CTRL_FRAME_TO_MBSS,
7282 enable);
7283#else /* NL80211_SUPPORT */
7284 sigma_dut_print(dut, DUT_MSG_ERROR,
7285 "Rx ctrl frame to Multi-BSS cannot be changed without NL80211_SUPPORT defined");
7286 return -1;
7287#endif /* NL80211_SUPPORT */
7288}
7289
7290
7291static int sta_set_bcast_twt_support(struct sigma_dut *dut, const char *intf,
7292 int enable)
7293{
7294#ifdef NL80211_SUPPORT
7295 return wcn_wifi_test_config_set_u8(
7296 dut, intf,
7297 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BCAST_TWT_SUPPORT,
7298 enable);
7299#else /* NL80211_SUPPORT */
7300 sigma_dut_print(dut, DUT_MSG_ERROR,
7301 "BCAST TWT cannot be changed without NL80211_SUPPORT defined");
7302 return -1;
7303#endif /* NL80211_SUPPORT */
7304}
7305
7306
Arif Hussain8d5b27b2018-05-14 14:31:03 -07007307static int sta_set_tx_beamformee(struct sigma_dut *dut, const char *intf,
7308 int enable)
7309{
7310#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307311 return wcn_wifi_test_config_set_u8(
7312 dut, intf,
7313 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_TX_BEAMFORMEE,
7314 enable);
Arif Hussain8d5b27b2018-05-14 14:31:03 -07007315#else /* NL80211_SUPPORT */
7316 sigma_dut_print(dut, DUT_MSG_ERROR,
7317 "tx beamformee cannot be changed without NL80211_SUPPORT defined");
7318 return -1;
7319#endif /* NL80211_SUPPORT */
7320}
7321
7322
Arif Hussain9765f7d2018-07-03 08:28:26 -07007323static int sta_set_beamformee_sts(struct sigma_dut *dut, const char *intf,
7324 int val)
7325{
7326#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307327 return wcn_wifi_test_config_set_u8(
7328 dut, intf,
7329 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_BEAMFORMEE_NSTS,
7330 val);
Arif Hussain9765f7d2018-07-03 08:28:26 -07007331#else /* NL80211_SUPPORT */
7332 sigma_dut_print(dut, DUT_MSG_ERROR,
7333 "beamformee sts cannot be changed without NL80211_SUPPORT defined");
7334 return -1;
7335#endif /* NL80211_SUPPORT */
7336}
7337
7338
Arif Hussain68d23f52018-07-11 13:39:08 -07007339#ifdef NL80211_SUPPORT
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007340static int sta_set_mac_padding_duration(struct sigma_dut *dut, const char *intf,
7341 enum qca_wlan_he_mac_padding_dur val)
7342{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307343 return wcn_wifi_test_config_set_u8(
7344 dut, intf,
7345 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MAC_PADDING_DUR, val);
Arif Hussain68d23f52018-07-11 13:39:08 -07007346}
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007347#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07007348
7349
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07007350static int sta_set_tx_su_ppdu_cfg(struct sigma_dut *dut, const char *intf,
7351 int val)
7352{
7353#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307354 return wcn_wifi_test_config_set_u8(
7355 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_SUPPDU,
7356 val);
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07007357#else /* NL80211_SUPPORT */
7358 sigma_dut_print(dut, DUT_MSG_ERROR,
7359 "Tx SU PPDU cannot be set without NL80211_SUPPORT defined");
7360 return -1;
7361#endif /* NL80211_SUPPORT */
7362}
7363
7364
Kiran Kumar Lokere54b72522021-04-01 00:22:44 -07007365static int sta_set_mgmt_data_tx_disable_cfg(struct sigma_dut *dut,
7366 const char *intf, int val)
7367{
7368#ifdef NL80211_SUPPORT
7369 return wcn_wifi_test_config_set_u8(
7370 dut, intf,
7371 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_DISABLE_DATA_MGMT_RSP_TX,
7372 val);
7373#else /* NL80211_SUPPORT */
7374 sigma_dut_print(dut, DUT_MSG_ERROR,
7375 "Tx disable config cannot be set without NL80211_SUPPORT defined");
7376 return -1;
7377#endif /* NL80211_SUPPORT */
7378}
7379
7380
Kiran Kumar Lokere1809da12021-06-24 00:45:38 -07007381static int sta_set_keep_alive_data_cfg(struct sigma_dut *dut, const char *intf,
7382 int val)
7383{
7384#ifdef NL80211_SUPPORT
7385 return wcn_wifi_test_config_set_u8(
7386 dut, intf,
7387 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_KEEP_ALIVE_FRAME_TYPE,
7388 val);
7389#else /* NL80211_SUPPORT */
7390 sigma_dut_print(dut, DUT_MSG_ERROR,
7391 "Keep alive data type cannot be set without NL80211_SUPPORT defined");
7392 return -1;
7393#endif /* NL80211_SUPPORT */
7394}
7395
7396
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007397#ifdef NL80211_SUPPORT
7398static int sta_set_he_om_ctrl_reset(struct sigma_dut *dut, const char *intf)
7399{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307400 return wcn_wifi_test_config_set_flag(
7401 dut, intf,
7402 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_CLEAR_HE_OM_CTRL_CONFIG);
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007403}
7404#endif /* NL80211_SUPPORT */
7405
7406
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07007407static int sta_set_mu_edca_override(struct sigma_dut *dut, const char *intf,
7408 int val)
7409{
7410#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307411 return wcn_wifi_test_config_set_u8(
7412 dut, intf,
7413 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_OVERRIDE_MU_EDCA, val);
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07007414#else /* NL80211_SUPPORT */
7415 sigma_dut_print(dut, DUT_MSG_ERROR,
7416 "MU EDCA override cannot be changed without NL80211_SUPPORT defined");
7417 return -1;
7418#endif /* NL80211_SUPPORT */
7419}
7420
7421
Kiran Kumar Lokerefa7c7b92021-08-09 00:50:55 -07007422static int sta_set_er_su_ppdu_type_tx(struct sigma_dut *dut, const char *intf,
7423 int val)
7424{
7425#ifdef NL80211_SUPPORT
7426 return wcn_wifi_test_config_set_u8(
7427 dut, intf,
7428 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ER_SU_PPDU_TYPE, val);
7429#else /* NL80211_SUPPORT */
7430 sigma_dut_print(dut, DUT_MSG_ERROR,
7431 "ER-SU PPDU type cannot be set without NL80211_SUPPORT defined");
7432 return -1;
7433#endif /* NL80211_SUPPORT */
7434}
7435
7436
7437static int sta_set_ru_242_tone_tx(struct sigma_dut *dut, const char *intf,
7438 int val)
7439{
7440#ifdef NL80211_SUPPORT
7441 return wcn_wifi_test_config_set_u8(
7442 dut, intf,
7443 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_RU_242_TONE_TX, val);
7444#else /* NL80211_SUPPORT */
7445 sigma_dut_print(dut, DUT_MSG_ERROR,
7446 "RU 242 tone cannot be set without NL80211_SUPPORT defined");
7447 return -1;
7448#endif /* NL80211_SUPPORT */
7449}
7450
7451
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007452static int sta_set_om_ctrl_supp(struct sigma_dut *dut, const char *intf,
7453 int val)
7454{
7455#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307456 return wcn_wifi_test_config_set_u8(
7457 dut, intf,
7458 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OM_CTRL_SUPP, val);
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007459#else /* NL80211_SUPPORT */
7460 sigma_dut_print(dut, DUT_MSG_ERROR,
7461 "HE OM ctrl cannot be changed without NL80211_SUPPORT defined");
7462 return -1;
7463#endif /* NL80211_SUPPORT */
7464}
7465
7466
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07007467#ifdef NL80211_SUPPORT
7468
7469struct features_info {
7470 unsigned char flags[8];
7471 size_t flags_len;
7472};
7473
7474static int features_info_handler(struct nl_msg *msg, void *arg)
7475{
7476 struct nlattr *tb[NL80211_ATTR_MAX + 1];
7477 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
7478 struct features_info *info = arg;
7479 struct nlattr *nl_vend, *attr;
7480
7481 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
7482 genlmsg_attrlen(gnlh, 0), NULL);
7483
7484 nl_vend = tb[NL80211_ATTR_VENDOR_DATA];
7485 if (nl_vend) {
7486 struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1];
7487
7488 nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX,
7489 nla_data(nl_vend), nla_len(nl_vend), NULL);
7490
7491 attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_FEATURE_FLAGS];
7492 if (attr) {
7493 int len = nla_len(attr);
7494
Vamsi Krishna79a91132021-08-16 21:40:22 +05307495 if (info && len <= sizeof(info->flags)) {
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07007496 memcpy(info->flags, nla_data(attr), len);
7497 info->flags_len = len;
7498 }
7499 }
7500 }
7501
7502 return NL_SKIP;
7503}
7504
7505
7506static int check_feature(enum qca_wlan_vendor_features feature,
7507 struct features_info *info)
7508{
7509 size_t idx = feature / 8;
7510
Vamsi Krishna79a91132021-08-16 21:40:22 +05307511 if (!info)
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07007512 return 0;
7513
7514 return (idx < info->flags_len) &&
7515 (info->flags[idx] & BIT(feature % 8));
7516}
7517
7518#endif /* NL80211_SUPPORT */
7519
7520
7521static void sta_get_twt_feature_async_supp(struct sigma_dut *dut,
7522 const char *intf)
7523{
7524#ifdef NL80211_SUPPORT
7525 struct nl_msg *msg;
7526 struct features_info info = { 0 };
7527 int ifindex, ret;
7528
7529 ifindex = if_nametoindex(intf);
7530 if (ifindex == 0) {
7531 sigma_dut_print(dut, DUT_MSG_ERROR,
7532 "%s: Index for interface %s failed",
7533 __func__, intf);
7534 return;
7535 }
7536
7537 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7538 NL80211_CMD_VENDOR)) ||
7539 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7540 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7541 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7542 QCA_NL80211_VENDOR_SUBCMD_GET_FEATURES)) {
7543 sigma_dut_print(dut, DUT_MSG_ERROR,
7544 "%s: err in adding vendor_cmd and vendor_data",
7545 __func__);
7546 nlmsg_free(msg);
7547 return;
7548 }
7549
7550 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, features_info_handler,
7551 &info);
7552 if (ret) {
7553 sigma_dut_print(dut, DUT_MSG_ERROR,
7554 "%s: err in send_and_recv_msgs, ret=%d",
7555 __func__, ret);
7556 return;
7557 }
7558
7559 if (check_feature(QCA_WLAN_VENDOR_FEATURE_TWT_ASYNC_SUPPORT, &info))
7560 dut->sta_async_twt_supp = 1;
7561 else
7562 dut->sta_async_twt_supp = 0;
7563
7564 sigma_dut_print(dut, DUT_MSG_DEBUG,
7565 "%s: sta_async_twt_supp %d",
7566 __func__, dut->sta_async_twt_supp);
7567#else /* NL80211_SUPPORT */
7568 sigma_dut_print(dut, DUT_MSG_INFO,
7569 "TWT async supp get cannot be done without NL80211_SUPPORT defined");
7570 dut->sta_async_twt_supp = 0;
7571#endif /* NL80211_SUPPORT */
7572}
7573
7574
Arif Hussain480d5f42019-03-12 14:40:42 -07007575static int sta_set_twt_req_support(struct sigma_dut *dut, const char *intf,
7576 int val)
7577{
7578#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307579 return wcn_wifi_test_config_set_u8(
7580 dut, intf,
7581 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TWT_REQ_SUPPORT, val);
Arif Hussain480d5f42019-03-12 14:40:42 -07007582#else /* NL80211_SUPPORT */
7583 sigma_dut_print(dut, DUT_MSG_ERROR,
7584 "TWT Request cannot be changed without NL80211_SUPPORT defined");
7585 return -1;
7586#endif /* NL80211_SUPPORT */
7587}
7588
7589
Kiran Kumar Lokere4f2d4b02021-04-01 00:07:39 -07007590static int sta_set_bss_max_idle_period(struct sigma_dut *dut, const char *intf,
7591 int val)
7592{
7593#ifdef NL80211_SUPPORT
7594 return wcn_wifi_test_config_set_u16(
7595 dut, intf,
7596 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BSS_MAX_IDLE_PERIOD, val);
7597#else /* NL80211_SUPPORT */
7598 sigma_dut_print(dut, DUT_MSG_ERROR,
7599 "BSS max idle period cannot be set without NL80211_SUPPORT defined");
7600 return -1;
7601#endif /* NL80211_SUPPORT */
7602}
7603
7604
Kiran Kumar Lokere07ad92b2021-08-09 00:27:14 -07007605static int sta_set_bss_max_idle_support(struct sigma_dut *dut, const char *intf,
7606 int val)
7607{
7608#ifdef NL80211_SUPPORT
7609 return wcn_wifi_test_config_set_u8(
7610 dut, intf,
7611 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BSS_MAX_IDLE_PERIOD_ENABLE,
7612 val);
7613#else /* NL80211_SUPPORT */
7614 sigma_dut_print(dut, DUT_MSG_ERROR,
7615 "BSS max idle support cannot be set without NL80211_SUPPORT defined");
7616 return -1;
7617#endif /* NL80211_SUPPORT */
7618}
7619
7620
Srinivas Girigowda0525e292020-11-12 13:28:21 -08007621static int sta_set_fullbw_ulmumimo(struct sigma_dut *dut, const char *intf,
7622 int val)
7623{
7624#ifdef NL80211_SUPPORT
7625 return wcn_wifi_test_config_set_u8(
7626 dut, intf,
7627 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_FULL_BW_UL_MU_MIMO, val);
7628#else /* NL80211_SUPPORT */
7629 sigma_dut_print(dut, DUT_MSG_ERROR,
7630 "Full BW UL MU MIMO cannot be changed without NL80211_SUPPORT defined");
7631 return -1;
7632#endif /* NL80211_SUPPORT */
7633}
7634
7635
Kiran Kumar Lokered0ec5ed2021-04-01 00:15:04 -07007636static int sta_set_punctured_preamble_rx(struct sigma_dut *dut,
7637 const char *intf, int val)
7638{
7639#ifdef NL80211_SUPPORT
7640 return wcn_wifi_test_config_set_u8(
7641 dut, intf,
7642 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_PUNCTURED_PREAMBLE_RX,
7643 val);
7644#else /* NL80211_SUPPORT */
7645 sigma_dut_print(dut, DUT_MSG_ERROR,
7646 "Punctured preamble Rx cannot be set without NL80211_SUPPORT defined");
7647 return -1;
7648#endif /* NL80211_SUPPORT */
7649}
7650
7651
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007652static void sta_reset_default_wcn(struct sigma_dut *dut, const char *intf,
7653 const char *type)
7654{
7655 char buf[60];
7656
7657 if (dut->program == PROGRAM_HE) {
7658 /* resetting phymode to auto in case of HE program */
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05307659 sta_set_phymode(dut, intf, "auto");
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007660
Amarnath Hullur Subramanyam9cecb502018-04-25 13:26:30 -07007661 /* reset the rate to Auto rate */
7662 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0xff",
7663 intf);
7664 if (system(buf) != 0) {
7665 sigma_dut_print(dut, DUT_MSG_ERROR,
7666 "iwpriv %s set_11ax_rate 0xff failed",
7667 intf);
7668 }
7669
Kiran Kumar Lokere86cfe3a2018-06-01 11:55:15 -07007670 /* reset the LDPC setting */
7671 snprintf(buf, sizeof(buf), "iwpriv %s ldpc 1", intf);
7672 if (system(buf) != 0) {
7673 sigma_dut_print(dut, DUT_MSG_ERROR,
7674 "iwpriv %s ldpc 1 failed", intf);
7675 }
7676
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08007677 /* reset the power save setting */
Vinita S. Malooa8b62722020-04-23 01:45:41 +05307678 set_power_save_wcn(dut, intf, 2);
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08007679
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007680 /* remove all network profiles */
7681 remove_wpa_networks(intf);
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007682
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007683 /* Configure ADDBA Req/Rsp buffer size to be 64 */
7684 sta_set_addba_buf_size(dut, intf, 64);
7685
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07007686 if (dut->sta_async_twt_supp == -1)
7687 sta_get_twt_feature_async_supp(dut, intf);
7688
Kiran Kumar Lokere69d89952021-08-08 23:41:46 -07007689 sta_set_scan_unicast_probe(dut, intf, 0);
7690
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08007691#ifdef NL80211_SUPPORT
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007692 /* Reset the device HE capabilities to its default supported
7693 * configuration. */
7694 sta_set_he_testbed_def(dut, intf, 0);
7695
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08007696 /* Disable noackpolicy for all AC */
7697 if (nlvendor_sta_set_noack(dut, intf, 0, QCA_WLAN_AC_ALL)) {
7698 sigma_dut_print(dut, DUT_MSG_ERROR,
7699 "Disable of noackpolicy for all AC failed");
7700 }
7701#endif /* NL80211_SUPPORT */
7702
Amarnath Hullur Subramanyamb1724a52018-03-07 14:31:46 -08007703 /* Enable WMM by default */
7704 if (wcn_sta_set_wmm(dut, intf, "on")) {
7705 sigma_dut_print(dut, DUT_MSG_ERROR,
7706 "Enable of WMM in sta_reset_default_wcn failed");
7707 }
7708
7709 /* Disable ADDBA_REJECT by default */
7710 if (nlvendor_sta_set_addba_reject(dut, intf, 0)) {
7711 sigma_dut_print(dut, DUT_MSG_ERROR,
7712 "Disable of addba_reject in sta_reset_default_wcn failed");
7713 }
7714
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08007715 /* Enable sending of ADDBA by default */
7716 if (nlvendor_config_send_addba(dut, intf, 1)) {
7717 sigma_dut_print(dut, DUT_MSG_ERROR,
7718 "Enable sending of ADDBA in sta_reset_default_wcn failed");
7719 }
7720
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08007721 /* Enable AMPDU by default */
7722 iwpriv_sta_set_ampdu(dut, intf, 1);
7723
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007724#ifdef NL80211_SUPPORT
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -08007725 if (wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_AUTO)) {
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007726 sigma_dut_print(dut, DUT_MSG_ERROR,
7727 "Set LTF config to default in sta_reset_default_wcn failed");
7728 }
Arif Hussain9765f7d2018-07-03 08:28:26 -07007729
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08007730 /* set the beamformee NSTS(maximum number of
7731 * space-time streams) to default DUT config
7732 */
7733 if (sta_set_beamformee_sts(dut, intf, 7)) {
Arif Hussain9765f7d2018-07-03 08:28:26 -07007734 sigma_dut_print(dut, DUT_MSG_ERROR,
7735 "Failed to set BeamformeeSTS");
7736 }
Arif Hussain68d23f52018-07-11 13:39:08 -07007737
Kiran Kumar Lokere54b72522021-04-01 00:22:44 -07007738 if (sta_set_mgmt_data_tx_disable_cfg(dut, intf, 0)) {
7739 sigma_dut_print(dut, DUT_MSG_ERROR,
7740 "Failed to reset mgmt/data Tx disable config");
7741 }
7742
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007743 if (sta_set_mac_padding_duration(
7744 dut, intf,
7745 QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07007746 sigma_dut_print(dut, DUT_MSG_ERROR,
7747 "Failed to set MAC padding duration");
7748 }
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07007749
7750 if (sta_set_mu_edca_override(dut, intf, 0)) {
7751 sigma_dut_print(dut, DUT_MSG_ERROR,
7752 "ErrorCode,Failed to set MU EDCA override disable");
7753 }
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007754
Kiran Kumar Lokerefa7c7b92021-08-09 00:50:55 -07007755 if (sta_set_ru_242_tone_tx(dut, intf, 0)) {
7756 sigma_dut_print(dut, DUT_MSG_ERROR,
7757 "Failed to set RU 242 tone Tx");
7758 }
7759
7760 if (sta_set_er_su_ppdu_type_tx(dut, intf, 0)) {
7761 sigma_dut_print(dut, DUT_MSG_ERROR,
7762 "Failed to set ER-SU PPDU type Tx");
7763 }
7764
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007765 if (sta_set_om_ctrl_supp(dut, intf, 1)) {
7766 sigma_dut_print(dut, DUT_MSG_ERROR,
7767 "Failed to set OM ctrl supp");
7768 }
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07007769
7770 if (sta_set_tx_su_ppdu_cfg(dut, intf, 1)) {
7771 sigma_dut_print(dut, DUT_MSG_ERROR,
7772 "Failed to set Tx SU PPDU enable");
7773 }
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007774
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07007775 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 0)) {
7776 sigma_dut_print(dut, DUT_MSG_ERROR,
7777 "failed to send TB PPDU Tx cfg");
7778 }
7779
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007780 if (sta_set_he_om_ctrl_reset(dut, intf)) {
7781 sigma_dut_print(dut, DUT_MSG_ERROR,
7782 "Failed to set OM ctrl reset");
7783 }
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08007784
7785 /* +HTC-HE support default on */
7786 if (sta_set_he_htc_supp(dut, intf, 1)) {
7787 sigma_dut_print(dut, DUT_MSG_ERROR,
7788 "Setting of +HTC-HE support failed");
7789 }
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007790#endif /* NL80211_SUPPORT */
7791
Arif Hussain8d5b27b2018-05-14 14:31:03 -07007792 if (sta_set_tx_beamformee(dut, intf, 1)) {
7793 sigma_dut_print(dut, DUT_MSG_ERROR,
7794 "Set tx beamformee enable by default in sta_reset_default_wcn failed");
7795 }
7796
Kiran Kumar Lokereb55ff442020-07-15 00:20:40 -07007797 wpa_command(intf, "SET oce 1");
7798
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007799 /* Set nss to 1 and MCS 0-7 in case of testbed */
7800 if (type && strcasecmp(type, "Testbed") == 0) {
7801#ifdef NL80211_SUPPORT
7802 int ret;
7803#endif /* NL80211_SUPPORT */
7804
Kiran Kumar Lokereb55ff442020-07-15 00:20:40 -07007805 wpa_command(intf, "SET oce 0");
7806
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007807 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
7808 if (system(buf) != 0) {
7809 sigma_dut_print(dut, DUT_MSG_ERROR,
7810 "iwpriv %s nss failed", intf);
7811 }
7812
7813#ifdef NL80211_SUPPORT
7814 ret = sta_set_he_mcs(dut, intf, HE_80_MCS0_7);
7815 if (ret) {
7816 sigma_dut_print(dut, DUT_MSG_ERROR,
7817 "Setting of MCS failed, ret:%d",
7818 ret);
7819 }
7820#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyamc67621d2018-02-04 23:18:01 -08007821
7822 /* Disable STBC as default */
7823 wcn_sta_set_stbc(dut, intf, "0");
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08007824
7825 /* Disable AMSDU as default */
7826 iwpriv_sta_set_amsdu(dut, intf, "0");
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08007827
7828#ifdef NL80211_SUPPORT
7829 /* HE fragmentation default off */
7830 if (sta_set_he_fragmentation(dut, intf,
7831 HE_FRAG_DISABLE)) {
7832 sigma_dut_print(dut, DUT_MSG_ERROR,
7833 "Setting of HE fragmentation failed");
7834 }
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08007835
7836 /* set the beamformee NSTS(maximum number of
7837 * space-time streams) to default testbed config
7838 */
7839 if (sta_set_beamformee_sts(dut, intf, 3)) {
7840 sigma_dut_print(dut, DUT_MSG_ERROR,
7841 "Failed to set BeamformeeSTS");
7842 }
7843
Kiran Kumar Lokered0ec5ed2021-04-01 00:15:04 -07007844 if (sta_set_punctured_preamble_rx(dut, intf, 0)) {
7845 sigma_dut_print(dut, DUT_MSG_ERROR,
7846 "Failed to reset PreamblePunctRx support");
7847 }
7848
Kiran Kumar Lokere727687f2021-06-24 00:35:49 -07007849 if (sta_set_bss_max_idle_period(dut, intf, 0)) {
7850 sigma_dut_print(dut, DUT_MSG_ERROR,
7851 "Failed to reset BSS max idle period");
7852 }
7853
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08007854 /* +HTC-HE support default off */
7855 if (sta_set_he_htc_supp(dut, intf, 0)) {
7856 sigma_dut_print(dut, DUT_MSG_ERROR,
7857 "Setting of +HTC-HE support failed");
7858 }
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007859
7860 /* Set device HE capabilities to testbed default
7861 * configuration. */
7862 if (sta_set_he_testbed_def(dut, intf, 1)) {
7863 sigma_dut_print(dut, DUT_MSG_DEBUG,
7864 "Failed to set HE defaults");
7865 }
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007866
7867 /* Disable VHT support in 2.4 GHz for testbed */
7868 sta_set_2g_vht_supp(dut, intf, 0);
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08007869#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08007870
7871 /* Enable WEP/TKIP with HE capability in testbed */
7872 if (sta_set_heconfig_and_wep_tkip(dut, intf, 1)) {
7873 sigma_dut_print(dut, DUT_MSG_ERROR,
7874 "Enabling HE config with WEP/TKIP failed");
7875 }
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007876 }
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007877
7878 /* Defaults in case of DUT */
7879 if (type && strcasecmp(type, "DUT") == 0) {
Arif Hussaind48fcc72018-05-01 18:34:18 -07007880 /* Enable STBC by default */
7881 wcn_sta_set_stbc(dut, intf, "1");
7882
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007883 /* set nss to 2 */
7884 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
7885 if (system(buf) != 0) {
7886 sigma_dut_print(dut, DUT_MSG_ERROR,
7887 "iwpriv %s nss 2 failed", intf);
7888 }
Arif Hussainac6c5112018-05-25 17:34:00 -07007889 dut->sta_nss = 2;
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007890
7891#ifdef NL80211_SUPPORT
Arif Hussainae239842018-05-01 18:20:05 -07007892 /* Set HE_MCS to 0-11 */
7893 if (sta_set_he_mcs(dut, intf, HE_80_MCS0_11)) {
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007894 sigma_dut_print(dut, DUT_MSG_ERROR,
7895 "Setting of MCS failed");
7896 }
7897#endif /* NL80211_SUPPORT */
7898
7899 /* Disable WEP/TKIP with HE capability in DUT */
7900 if (sta_set_heconfig_and_wep_tkip(dut, intf, 0)) {
7901 sigma_dut_print(dut, DUT_MSG_ERROR,
7902 "Enabling HE config with WEP/TKIP failed");
7903 }
7904 }
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007905 }
7906}
7907
7908
Veerendranath Jakkam47867202020-12-21 01:53:52 +05307909static int sta_set_client_privacy(struct sigma_dut *dut,
7910 struct sigma_conn *conn, const char *intf,
7911 int enable)
7912{
7913 if (enable &&
7914 (wpa_command(intf, "SET mac_addr 1") < 0 ||
7915 wpa_command(intf, "SET rand_addr_lifetime 1") < 0 ||
Veerendranath Jakkam39fd5c42020-12-21 02:02:21 +05307916 (wpa_command(intf, "MAC_RAND_SCAN enable=1 all") < 0 &&
7917 wpa_command(intf, "SET preassoc_mac_addr 1") < 0) ||
Veerendranath Jakkam47867202020-12-21 01:53:52 +05307918 wpa_command(intf, "SET gas_rand_mac_addr 1") < 0 ||
7919 wpa_command(intf, "SET gas_rand_addr_lifetime 1") < 0))
7920 return -1;
7921
7922 if (!enable &&
7923 (wpa_command(intf, "SET mac_addr 0") < 0 ||
Veerendranath Jakkam39fd5c42020-12-21 02:02:21 +05307924 (wpa_command(intf, "MAC_RAND_SCAN enable=0 all") < 0 &&
7925 wpa_command(intf, "SET preassoc_mac_addr 0") < 0) ||
Veerendranath Jakkam47867202020-12-21 01:53:52 +05307926 wpa_command(intf, "SET gas_rand_mac_addr 0") < 0))
7927 return -1;
7928
7929 dut->client_privacy = enable;
7930 return 0;
7931}
7932
7933
Jouni Malinenf7222712019-06-13 01:50:21 +03007934static enum sigma_cmd_result cmd_sta_reset_default(struct sigma_dut *dut,
7935 struct sigma_conn *conn,
7936 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007937{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007938 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007939 const char *band = get_param(cmd, "band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007940 const char *type;
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007941 const char *program = get_param(cmd, "program");
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05307942 const char *dev_role = get_param(cmd, "DevRole");
Veerendranath Jakkamc1f71b62021-01-23 03:09:51 +05307943 char resp[20];
Veerendranath Jakkamea7f0692021-08-11 19:13:12 +05307944 char buf[100];
Veerendranath Jakkamc1f71b62021-01-23 03:09:51 +05307945 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007946
Jouni Malinenb21f0542019-11-04 17:53:38 +02007947 if (dut->station_ifname_2g &&
7948 strcmp(dut->station_ifname_2g, intf) == 0)
7949 dut->use_5g = 0;
7950 else if (dut->station_ifname_5g &&
7951 strcmp(dut->station_ifname_5g, intf) == 0)
7952 dut->use_5g = 1;
7953
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007954 if (!program)
7955 program = get_param(cmd, "prog");
7956 dut->program = sigma_program_to_enum(program);
Vinita S. Maloof7a2cbf2020-11-18 19:29:44 +05307957
7958 if (dut->program == PROGRAM_WFD && dut->user_config_timeout)
7959 dut->default_timeout = dut->user_config_timeout;
7960
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007961 dut->device_type = STA_unknown;
7962 type = get_param(cmd, "type");
7963 if (type && strcasecmp(type, "Testbed") == 0)
7964 dut->device_type = STA_testbed;
7965 if (type && strcasecmp(type, "DUT") == 0)
7966 dut->device_type = STA_dut;
7967
7968 if (dut->program == PROGRAM_TDLS) {
7969 /* Clear TDLS testing mode */
7970 wpa_command(intf, "SET tdls_disabled 0");
7971 wpa_command(intf, "SET tdls_testing 0");
7972 dut->no_tpk_expiration = 0;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007973 if (get_driver_type(dut) == DRIVER_WCN) {
Pradeep Reddy POTTETI8ce2a232016-10-28 12:17:32 +05307974 /* Enable the WCN driver in TDLS Explicit trigger mode
7975 */
7976 wpa_command(intf, "SET tdls_external_control 0");
7977 wpa_command(intf, "SET tdls_trigger_control 0");
7978 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007979 }
7980
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007981#ifdef MIRACAST
7982 if (dut->program == PROGRAM_WFD ||
7983 dut->program == PROGRAM_DISPLAYR2)
7984 miracast_sta_reset_default(dut, conn, cmd);
7985#endif /* MIRACAST */
7986
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007987 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007988 case DRIVER_ATHEROS:
7989 sta_reset_default_ath(dut, intf, type);
7990 break;
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007991 case DRIVER_WCN:
7992 sta_reset_default_wcn(dut, intf, type);
7993 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007994 default:
7995 break;
7996 }
7997
7998#ifdef ANDROID_NAN
7999 if (dut->program == PROGRAM_NAN)
8000 nan_cmd_sta_reset_default(dut, conn, cmd);
8001#endif /* ANDROID_NAN */
8002
Vinay Gannevaram3b9fdd32019-06-14 17:55:44 +05308003 if (dut->program == PROGRAM_LOC &&
8004 lowi_cmd_sta_reset_default(dut, conn, cmd) < 0)
8005 return ERROR_SEND_STATUS;
8006
Jouni Malinenba630452018-06-22 11:49:59 +03008007 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008008 unlink("SP/wi-fi.org/pps.xml");
8009 if (system("rm -r SP/*") != 0) {
8010 }
8011 unlink("next-client-cert.pem");
8012 unlink("next-client-key.pem");
8013 }
8014
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008015 /* For WPS program of the 60 GHz band the band type needs to be saved */
8016 if (dut->program == PROGRAM_WPS) {
8017 if (band && strcasecmp(band, "60GHz") == 0) {
8018 dut->band = WPS_BAND_60G;
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02008019 /* For 60 GHz enable WPS for WPS TCs */
8020 dut->wps_disable = 0;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008021 } else {
8022 dut->band = WPS_BAND_NON_60G;
8023 }
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02008024 } else if (dut->program == PROGRAM_60GHZ) {
8025 /* For 60 GHz MAC/PHY TCs WPS must be disabled */
8026 dut->wps_disable = 1;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008027 }
8028
Alexei Avshalom Lazar157ba062018-12-23 16:15:26 +02008029 if (is_60g_sigma_dut(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008030 const char *dev_role = get_param(cmd, "DevRole");
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02008031 char buf[256];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008032
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02008033 sigma_dut_print(dut, DUT_MSG_INFO,
8034 "WPS 60 GHz program, wps_disable = %d",
8035 dut->wps_disable);
8036
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008037 if (!dev_role) {
8038 send_resp(dut, conn, SIGMA_ERROR,
8039 "errorCode,Missing DevRole argument");
8040 return 0;
8041 }
8042
8043 if (strcasecmp(dev_role, "STA") == 0)
8044 dut->dev_role = DEVROLE_STA;
8045 else if (strcasecmp(dev_role, "PCP") == 0)
8046 dut->dev_role = DEVROLE_PCP;
8047 else {
8048 send_resp(dut, conn, SIGMA_ERROR,
8049 "errorCode,Unknown DevRole");
8050 return 0;
8051 }
8052
8053 if (dut->device_type == STA_unknown) {
8054 sigma_dut_print(dut, DUT_MSG_ERROR,
8055 "Device type is not STA testbed or DUT");
8056 send_resp(dut, conn, SIGMA_ERROR,
8057 "errorCode,Unknown device type");
8058 return 0;
8059 }
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02008060
8061 sigma_dut_print(dut, DUT_MSG_DEBUG,
8062 "Setting msdu_size to MAX: 7912");
8063 snprintf(buf, sizeof(buf), "ifconfig %s mtu 7912",
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008064 get_station_ifname(dut));
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02008065
8066 if (system(buf) != 0) {
8067 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
8068 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02008069 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02008070 }
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02008071
8072 if (sta_set_force_mcs(dut, 0, 1)) {
8073 sigma_dut_print(dut, DUT_MSG_ERROR,
8074 "Failed to reset force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02008075 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02008076 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008077 }
8078
8079 wpa_command(intf, "WPS_ER_STOP");
8080 wpa_command(intf, "FLUSH");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05308081 wpa_command(intf, "ERP_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008082 wpa_command(intf, "SET radio_disabled 0");
8083
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02008084 dut->wps_forced_version = 0;
8085
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008086 if (dut->wsc_fragment) {
8087 dut->wsc_fragment = 0;
8088 wpa_command(intf, "SET device_name Test client");
8089 wpa_command(intf, "SET manufacturer ");
8090 wpa_command(intf, "SET model_name ");
8091 wpa_command(intf, "SET model_number ");
8092 wpa_command(intf, "SET serial_number ");
8093 }
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02008094 if (is_60g_sigma_dut(dut) && dut->force_rsn_ie) {
8095 dut->force_rsn_ie = FORCE_RSN_IE_NONE;
8096 sta_60g_force_rsn_ie(dut, FORCE_RSN_IE_NONE);
8097 }
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008098
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008099 if (dut->tmp_mac_addr && dut->set_macaddr) {
8100 dut->tmp_mac_addr = 0;
8101 if (system(dut->set_macaddr) != 0) {
8102 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to clear "
8103 "temporary MAC address");
8104 }
8105 }
8106
8107 set_ps(intf, dut, 0);
8108
Jouni Malinenba630452018-06-22 11:49:59 +03008109 if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2 ||
8110 dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008111 wpa_command(intf, "SET interworking 1");
8112 wpa_command(intf, "SET hs20 1");
8113 }
8114
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08008115 if (dut->program == PROGRAM_HS2_R2 ||
Jouni Malinenba630452018-06-22 11:49:59 +03008116 dut->program == PROGRAM_HS2_R3 ||
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08008117 dut->program == PROGRAM_OCE) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008118 wpa_command(intf, "SET pmf 1");
8119 } else {
8120 wpa_command(intf, "SET pmf 0");
8121 }
8122
8123 hs2_clear_credentials(intf);
8124 wpa_command(intf, "SET hessid 00:00:00:00:00:00");
8125 wpa_command(intf, "SET access_network_type 15");
8126
8127 static_ip_file(0, NULL, NULL, NULL);
8128 kill_dhcp_client(dut, intf);
8129 clear_ip_addr(dut, intf);
8130
8131 dut->er_oper_performed = 0;
8132 dut->er_oper_bssid[0] = '\0';
8133
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07008134 if (dut->program == PROGRAM_LOC) {
8135 /* Disable Interworking by default */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008136 wpa_command(get_station_ifname(dut), "SET interworking 0");
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07008137 }
8138
Kiran Kumar Lokeredd086642020-06-04 00:29:26 -07008139 if (dut->program == PROGRAM_MBO || dut->program == PROGRAM_HE) {
Ashwini Patil00402582017-04-13 12:29:39 +05308140 free(dut->non_pref_ch_list);
8141 dut->non_pref_ch_list = NULL;
Ashwini Patil5acd7382017-04-13 15:55:04 +05308142 free(dut->btm_query_cand_list);
8143 dut->btm_query_cand_list = NULL;
Ashwini Patilc63161e2017-04-13 16:30:23 +05308144 wpa_command(intf, "SET reject_btm_req_reason 0");
Ashwini Patila75de5a2017-04-13 16:35:05 +05308145 wpa_command(intf, "SET ignore_assoc_disallow 0");
Ashwini Patild174f2c2017-04-13 16:49:46 +05308146 wpa_command(intf, "SET gas_address3 0");
Ashwini Patil9183fdb2017-04-13 16:58:25 +05308147 wpa_command(intf, "SET roaming 1");
Ankita Bajaj1d974552018-09-18 16:56:44 +05308148 wpa_command(intf, "SET interworking 1");
Ashwini Patil00402582017-04-13 12:29:39 +05308149 }
8150
Jouni Malinen3c367e82017-06-23 17:01:47 +03008151 free(dut->rsne_override);
8152 dut->rsne_override = NULL;
8153
Jouni Malinen68143132017-09-02 02:34:08 +03008154 free(dut->sae_commit_override);
8155 dut->sae_commit_override = NULL;
Jouni Malinen4b3769d2019-10-10 16:20:29 +03008156 wpa_command(intf, "SET sae_pmkid_in_assoc 0");
Jouni Malinen11e55212019-11-22 21:46:59 +02008157 dut->sae_pwe = SAE_PWE_DEFAULT;
Jouni Malinen68143132017-09-02 02:34:08 +03008158
Jouni Malinen134fe3c2019-06-12 04:16:49 +03008159 dut->sta_associate_wait_connect = 0;
8160 dut->server_cert_hash[0] = '\0';
Jouni Malinen37d5c692019-08-19 16:56:55 +03008161 dut->server_cert_tod = 0;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03008162 dut->sta_tod_policy = 0;
8163
Jouni Malinend86e5822017-08-29 03:55:32 +03008164 dut->dpp_conf_id = -1;
Jouni Malinenb1dd21f2017-11-13 19:14:29 +02008165 free(dut->dpp_peer_uri);
8166 dut->dpp_peer_uri = NULL;
Jouni Malinen63d50412017-11-24 11:55:38 +02008167 dut->dpp_local_bootstrap = -1;
Jouni Malinen5011fb52017-12-05 21:00:15 +02008168 wpa_command(intf, "SET dpp_config_processing 2");
Jouni Malinen90776b12020-05-04 15:34:46 +03008169 wpa_command(intf, "SET dpp_mud_url ");
Jouni Malinend86e5822017-08-29 03:55:32 +03008170
Jouni Malinenfac9cad2017-10-10 18:35:55 +03008171 wpa_command(intf, "VENDOR_ELEM_REMOVE 13 *");
8172
vamsi krishnaa2799492017-12-05 14:28:01 +05308173 if (dut->program == PROGRAM_OCE) {
Ankita Bajaja2cb5672017-10-25 16:08:28 +05308174 wpa_command(intf, "SET oce 1");
vamsi krishnaa2799492017-12-05 14:28:01 +05308175 wpa_command(intf, "SET disable_fils 0");
Ankita Bajaj1bde7942018-01-09 19:15:01 +05308176 wpa_command(intf, "FILS_HLP_REQ_FLUSH");
8177 dut->fils_hlp = 0;
8178#ifdef ANDROID
8179 hlp_thread_cleanup(dut);
8180#endif /* ANDROID */
vamsi krishnaa2799492017-12-05 14:28:01 +05308181 }
Ankita Bajaja2cb5672017-10-25 16:08:28 +05308182
Veerendranath Jakkamea7f0692021-08-11 19:13:12 +05308183 if (dut->program == PROGRAM_QM) {
Vamsi Krishnaf642d6a2020-03-27 12:33:14 +05308184 wpa_command(intf, "SET interworking 1");
Vinita S. Maloo2287f142021-02-01 16:17:09 +05308185 wpa_command(intf, "SET disable_scs_support 0");
Veerendranath Jakkamea7f0692021-08-11 19:13:12 +05308186 snprintf(buf, sizeof(buf),
8187 "ip -6 route replace fe80::/64 dev %s table local",
8188 intf);
8189 if (system(buf) != 0)
8190 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run: %s",
8191 buf);
8192 }
Vamsi Krishnaf642d6a2020-03-27 12:33:14 +05308193
Jouni Malinen8179fee2019-03-28 03:19:47 +02008194 dut->akm_values = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03008195 dut->sta_ft_ds = 0;
Jouni Malinen8179fee2019-03-28 03:19:47 +02008196
Sunil Dutt076081f2018-02-05 19:45:50 +05308197#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008198 if (get_driver_type(dut) == DRIVER_WCN &&
Sunil Dutt44595082018-02-12 19:41:45 +05308199 dut->config_rsnie == 1) {
8200 dut->config_rsnie = 0;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05308201 sta_config_params(dut, intf, STA_SET_RSNIE, 0);
Sunil Dutt076081f2018-02-05 19:45:50 +05308202 }
8203#endif /* NL80211_SUPPORT */
8204
Sunil Duttfebf8a82018-02-09 18:50:13 +05308205 if (dev_role && strcasecmp(dev_role, "STA-CFON") == 0) {
8206 dut->dev_role = DEVROLE_STA_CFON;
8207 return sta_cfon_reset_default(dut, conn, cmd);
8208 }
8209
Jouni Malinen439352d2018-09-13 03:42:23 +03008210 wpa_command(intf, "SET setband AUTO");
8211
Veerendranath Jakkamc1f71b62021-01-23 03:09:51 +05308212 ret = wpa_command_resp(intf, "GET_CAPABILITY ocv", resp, sizeof(resp));
8213 dut->ocvc = ret == 0 && strncmp(resp, "supported", 9) == 0;
8214
8215 ret = wpa_command_resp(intf, "GET_CAPABILITY beacon_prot", resp,
8216 sizeof(resp));
8217 dut->beacon_prot = ret == 0 && strncmp(resp, "supported", 9) == 0;
8218
Veerendranath Jakkam47867202020-12-21 01:53:52 +05308219 if (sta_set_client_privacy(dut, conn, intf,
8220 dut->program == PROGRAM_WPA3 &&
8221 dut->device_type == STA_dut &&
8222 dut->client_privacy_default)) {
8223 sigma_dut_print(dut, DUT_MSG_ERROR,
8224 "Failed to set client privacy functionality");
8225 /* sta_reset_default command is not really supposed to fail,
8226 * so allow this to continue. */
8227 }
8228
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +05308229 dut->saquery_oci_freq = 0;
Vamsi Krishnac1633d22020-05-06 18:31:21 +05308230
Sunil Duttfebf8a82018-02-09 18:50:13 +05308231 if (dut->program != PROGRAM_VHT)
8232 return cmd_sta_p2p_reset(dut, conn, cmd);
8233
Priyadharshini Gowthamana7dfd492015-11-09 14:34:08 -08008234 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008235}
8236
8237
Jouni Malinenf7222712019-06-13 01:50:21 +03008238static enum sigma_cmd_result cmd_sta_get_events(struct sigma_dut *dut,
8239 struct sigma_conn *conn,
8240 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008241{
8242 const char *program = get_param(cmd, "Program");
8243
8244 if (program == NULL)
8245 return -1;
8246#ifdef ANDROID_NAN
8247 if (strcasecmp(program, "NAN") == 0)
8248 return nan_cmd_sta_get_events(dut, conn, cmd);
8249#endif /* ANDROID_NAN */
8250 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
8251 return 0;
8252}
8253
8254
Jouni Malinen82905202018-04-29 17:20:10 +03008255static int sta_exec_action_url(struct sigma_dut *dut, struct sigma_conn *conn,
8256 struct sigma_cmd *cmd)
8257{
8258 const char *url = get_param(cmd, "url");
8259 const char *method = get_param(cmd, "method");
8260 pid_t pid;
8261 int status;
8262
8263 if (!url || !method)
8264 return -1;
8265
8266 /* TODO: Add support for method,post */
8267 if (strcasecmp(method, "get") != 0) {
8268 send_resp(dut, conn, SIGMA_ERROR,
8269 "ErrorCode,Unsupported method");
8270 return 0;
8271 }
8272
8273 pid = fork();
8274 if (pid < 0) {
8275 perror("fork");
8276 return -1;
8277 }
8278
8279 if (pid == 0) {
8280 char * argv[5] = { "wget", "-O", "/dev/null",
8281 (char *) url, NULL };
8282
8283 execv("/usr/bin/wget", argv);
8284 perror("execv");
8285 exit(0);
8286 return -1;
8287 }
8288
8289 if (waitpid(pid, &status, 0) < 0) {
8290 perror("waitpid");
8291 return -1;
8292 }
8293
8294 if (WIFEXITED(status)) {
8295 const char *errmsg;
8296
8297 if (WEXITSTATUS(status) == 0)
8298 return 1;
8299 sigma_dut_print(dut, DUT_MSG_INFO, "wget exit status %d",
8300 WEXITSTATUS(status));
8301 switch (WEXITSTATUS(status)) {
8302 case 4:
8303 errmsg = "errmsg,Network failure";
8304 break;
8305 case 8:
8306 errmsg = "errmsg,Server issued an error response";
8307 break;
8308 default:
8309 errmsg = "errmsg,Unknown failure from wget";
8310 break;
8311 }
8312 send_resp(dut, conn, SIGMA_ERROR, errmsg);
8313 return 0;
8314 }
8315
8316 send_resp(dut, conn, SIGMA_ERROR, "errmsg,Unknown failure");
8317 return 0;
8318}
8319
8320
Jouni Malinenf7222712019-06-13 01:50:21 +03008321static enum sigma_cmd_result cmd_sta_exec_action(struct sigma_dut *dut,
8322 struct sigma_conn *conn,
8323 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008324{
8325 const char *program = get_param(cmd, "Prog");
8326
Jouni Malinen82905202018-04-29 17:20:10 +03008327 if (program && !get_param(cmd, "interface"))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008328 return -1;
8329#ifdef ANDROID_NAN
Jouni Malinen82905202018-04-29 17:20:10 +03008330 if (program && strcasecmp(program, "NAN") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008331 return nan_cmd_sta_exec_action(dut, conn, cmd);
8332#endif /* ANDROID_NAN */
Jouni Malinen82905202018-04-29 17:20:10 +03008333
8334 if (program && strcasecmp(program, "Loc") == 0)
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07008335 return loc_cmd_sta_exec_action(dut, conn, cmd);
Jouni Malinen82905202018-04-29 17:20:10 +03008336
8337 if (get_param(cmd, "url"))
8338 return sta_exec_action_url(dut, conn, cmd);
8339
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008340 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
8341 return 0;
8342}
8343
8344
Jouni Malinenf7222712019-06-13 01:50:21 +03008345static enum sigma_cmd_result cmd_sta_set_11n(struct sigma_dut *dut,
8346 struct sigma_conn *conn,
8347 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008348{
8349 const char *intf = get_param(cmd, "Interface");
8350 const char *val, *mcs32, *rate;
8351
8352 val = get_param(cmd, "GREENFIELD");
8353 if (val) {
8354 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
8355 /* Enable GD */
8356 send_resp(dut, conn, SIGMA_ERROR,
8357 "ErrorCode,GF not supported");
8358 return 0;
8359 }
8360 }
8361
8362 val = get_param(cmd, "SGI20");
8363 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008364 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008365 case DRIVER_ATHEROS:
8366 ath_sta_set_sgi(dut, intf, val);
8367 break;
8368 default:
8369 send_resp(dut, conn, SIGMA_ERROR,
8370 "ErrorCode,SGI20 not supported");
8371 return 0;
8372 }
8373 }
8374
8375 mcs32 = get_param(cmd, "MCS32"); /* HT Duplicate Mode Enable/Disable */
8376 rate = get_param(cmd, "MCS_FIXEDRATE"); /* Fixed MCS rate (0..31) */
8377 if (mcs32 && rate) {
8378 /* TODO */
8379 send_resp(dut, conn, SIGMA_ERROR,
8380 "ErrorCode,MCS32,MCS_FIXEDRATE not supported");
8381 return 0;
8382 } else if (mcs32 && !rate) {
8383 /* TODO */
8384 send_resp(dut, conn, SIGMA_ERROR,
8385 "ErrorCode,MCS32 not supported");
8386 return 0;
8387 } else if (!mcs32 && rate) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008388 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008389 case DRIVER_ATHEROS:
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07008390 novap_reset(dut, intf, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008391 ath_sta_set_11nrates(dut, intf, rate);
8392 break;
8393 default:
8394 send_resp(dut, conn, SIGMA_ERROR,
8395 "ErrorCode,MCS32_FIXEDRATE not supported");
8396 return 0;
8397 }
8398 }
8399
8400 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
8401}
8402
8403
Arif Hussain7b47d2d2018-05-09 10:44:02 -07008404static void cmd_set_max_he_mcs(struct sigma_dut *dut, const char *intf,
8405 int mcs_config)
8406{
8407#ifdef NL80211_SUPPORT
8408 int ret;
8409
8410 switch (mcs_config) {
8411 case HE_80_MCS0_7:
8412 case HE_80_MCS0_9:
8413 case HE_80_MCS0_11:
8414 ret = sta_set_he_mcs(dut, intf, mcs_config);
8415 if (ret) {
8416 sigma_dut_print(dut, DUT_MSG_ERROR,
8417 "cmd_set_max_he_mcs: Setting of MCS:%d failed, ret:%d",
8418 mcs_config, ret);
8419 }
8420 break;
8421 default:
8422 sigma_dut_print(dut, DUT_MSG_ERROR,
8423 "cmd_set_max_he_mcs: Invalid mcs %d",
8424 mcs_config);
8425 break;
8426 }
8427#else /* NL80211_SUPPORT */
8428 sigma_dut_print(dut, DUT_MSG_ERROR,
8429 "max HE MCS cannot be changed without NL80211_SUPPORT defined");
8430#endif /* NL80211_SUPPORT */
8431}
8432
8433
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07008434struct wait_event {
8435 struct sigma_dut *dut;
8436 int cmd;
8437 unsigned int twt_op;
8438};
8439
8440#ifdef NL80211_SUPPORT
8441
8442static int twt_event_handler(struct nl_msg *msg, void *arg)
8443{
8444 struct wait_event *wait = arg;
8445 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
8446 struct nlattr *tb[NL80211_ATTR_MAX + 1];
8447 uint32_t subcmd;
8448 uint8_t *data = NULL;
8449 size_t len = 0;
8450 struct nlattr *twt_rsp[QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_MAX + 1];
8451 struct nlattr *twt_status[QCA_WLAN_VENDOR_ATTR_TWT_SETUP_MAX + 1];
8452 int cmd_id;
8453 unsigned char val;
8454
8455 if (!wait)
8456 return NL_SKIP;
8457
8458 if (gnlh->cmd != NL80211_CMD_VENDOR) {
8459 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
8460 "%s: NL cmd is not vendor %d", __func__,
8461 gnlh->cmd);
8462 return NL_SKIP;
8463 }
8464
8465 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
8466 genlmsg_attrlen(gnlh, 0), NULL);
8467
8468 if (!tb[NL80211_ATTR_VENDOR_ID] || !tb[NL80211_ATTR_VENDOR_SUBCMD]) {
8469 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
8470 "%s: vendor ID not found", __func__);
8471 return NL_SKIP;
8472 }
8473 subcmd = nla_get_u32(tb[NL80211_ATTR_VENDOR_SUBCMD]);
8474
8475 if (subcmd != QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) {
8476 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
8477 "%s: Not a TWT_cmd %d", __func__, subcmd);
8478 return NL_SKIP;
8479 }
8480 if (tb[NL80211_ATTR_VENDOR_DATA]) {
8481 data = nla_data(tb[NL80211_ATTR_VENDOR_DATA]);
8482 len = nla_len(tb[NL80211_ATTR_VENDOR_DATA]);
8483 } else {
8484 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
8485 "%s: vendor data not present", __func__);
8486 return NL_SKIP;
8487 }
8488 if (!data || !len) {
8489 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
8490 "Invalid vendor data or len");
8491 return NL_SKIP;
8492 }
8493 sigma_dut_print(wait->dut, DUT_MSG_DEBUG,
8494 "event data len %ld", len);
8495 hex_dump(wait->dut, data, len);
8496 if (nla_parse(twt_rsp, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_MAX,
8497 (struct nlattr *) data, len, NULL)) {
8498 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
8499 "vendor data parse error");
8500 return NL_SKIP;
8501 }
8502
8503 val = nla_get_u8(twt_rsp[QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION]);
8504 if (val != wait->twt_op) {
8505 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
8506 "Invalid TWT operation, expected %d, rcvd %d",
8507 wait->twt_op, val);
8508 return NL_SKIP;
8509 }
8510 if (nla_parse_nested(twt_status, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_MAX,
8511 twt_rsp[QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS],
8512 NULL)) {
8513 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
8514 "nla_parse failed for TWT event");
8515 return NL_SKIP;
8516 }
8517
8518 cmd_id = QCA_WLAN_VENDOR_ATTR_TWT_SETUP_STATUS;
8519 if (!twt_status[cmd_id]) {
8520 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
8521 "%s TWT resp status missing", __func__);
8522 wait->cmd = -1;
8523 } else {
8524 val = nla_get_u8(twt_status[cmd_id]);
8525 if (val != QCA_WLAN_VENDOR_TWT_STATUS_OK) {
8526 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
8527 "%s TWT resp status %d", __func__, val);
8528 wait->cmd = -1;
8529 } else {
8530 wait->cmd = 1;
8531 }
8532 }
8533
8534 return NL_SKIP;
8535}
8536
8537
8538static int wait_on_nl_socket(struct nl_sock *sock, struct sigma_dut *dut,
8539 unsigned int timeout)
8540{
8541 fd_set read_fd_set;
8542 int retval;
8543 int sock_fd;
8544 struct timeval time_out;
8545
8546 time_out.tv_sec = timeout;
8547 time_out.tv_usec = 0;
8548
8549 FD_ZERO(&read_fd_set);
8550
8551 if (!sock)
8552 return -1;
8553
8554 sock_fd = nl_socket_get_fd(sock);
8555 FD_SET(sock_fd, &read_fd_set);
8556
8557 retval = select(sock_fd + 1, &read_fd_set, NULL, NULL, &time_out);
8558
8559 if (retval == 0)
8560 sigma_dut_print(dut, DUT_MSG_ERROR,
8561 "%s: TWT event response timedout", __func__);
8562
8563 if (retval < 0)
8564 sigma_dut_print(dut, DUT_MSG_ERROR, "%s:no NL msgs, ret=%d",
8565 __func__, retval);
8566
8567 return retval;
8568}
8569
8570
8571#define TWT_ASYNC_EVENT_WAIT_TIME_SEC 6
8572
8573static int twt_async_event_wait(struct sigma_dut *dut, unsigned int twt_op)
8574{
8575 struct nl_cb *cb;
8576 int err_code = 0, select_retval = 0;
8577 struct wait_event wait_info;
8578
8579 cb = nl_socket_get_cb(dut->nl_ctx->event_sock);
8580 if (!cb) {
8581 sigma_dut_print(dut, DUT_MSG_ERROR,
8582 "event callback not found");
8583 return ERROR_SEND_STATUS;
8584 }
8585
8586 wait_info.cmd = 0;
8587 wait_info.dut = dut;
8588 wait_info.twt_op = twt_op;
8589
8590 nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, twt_event_handler, &wait_info);
8591
8592 while (!wait_info.cmd) {
8593 select_retval = wait_on_nl_socket(
8594 dut->nl_ctx->event_sock, dut,
8595 TWT_ASYNC_EVENT_WAIT_TIME_SEC);
8596
8597 if (select_retval > 0) {
8598 err_code = nl_recvmsgs(dut->nl_ctx->event_sock, cb);
8599 if (err_code < 0) {
8600 sigma_dut_print(dut, DUT_MSG_ERROR,
8601 "%s: nl rcv failed, err_code %d",
8602 __func__, err_code);
8603 break;
8604 }
8605 } else {
8606 sigma_dut_print(dut, DUT_MSG_ERROR,
8607 "%s: wait on socket failed %d",
8608 __func__, select_retval);
8609 err_code = 1;
8610 break;
8611 }
8612
8613 }
8614 nl_cb_put(cb);
8615
8616 if (wait_info.cmd < 0)
8617 err_code = 1;
8618
8619 sigma_dut_print(dut, DUT_MSG_DEBUG,
8620 "%s: rcvd cmd %d, err_code %d, s_ret %d",
8621 __func__, wait_info.cmd, err_code, select_retval);
8622
8623 return err_code;
8624}
8625
8626#endif /* NL80211_SUPPORT */
8627
8628
Srinivas Girigowda6707f032020-10-26 15:24:46 -07008629static int sta_twt_send_suspend(struct sigma_dut *dut, struct sigma_conn *conn,
8630 struct sigma_cmd *cmd)
8631{
8632#ifdef NL80211_SUPPORT
8633 struct nlattr *attr, *attr1;
8634 struct nl_msg *msg;
8635 int ifindex, ret;
8636 const char *intf = get_param(cmd, "Interface");
8637
8638 ifindex = if_nametoindex(intf);
8639 if (ifindex == 0) {
8640 sigma_dut_print(dut, DUT_MSG_ERROR,
8641 "%s: Index for interface %s failed",
8642 __func__, intf);
8643 return ERROR_SEND_STATUS;
8644 }
8645
8646 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8647 NL80211_CMD_VENDOR)) ||
8648 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8649 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8650 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8651 QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) ||
8652 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8653 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION,
8654 QCA_WLAN_TWT_SUSPEND) ||
8655 !(attr1 = nla_nest_start(msg,
Kiran Kumar Lokere7ede00c2021-08-09 00:59:52 -07008656 QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS))) {
Srinivas Girigowda6707f032020-10-26 15:24:46 -07008657 sigma_dut_print(dut, DUT_MSG_ERROR,
8658 "%s: err in adding vendor_cmd and vendor_data",
8659 __func__);
8660 nlmsg_free(msg);
8661 return ERROR_SEND_STATUS;
8662 }
8663 nla_nest_end(msg, attr1);
8664 nla_nest_end(msg, attr);
8665
8666 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8667 if (ret) {
8668 sigma_dut_print(dut, DUT_MSG_ERROR,
8669 "%s: err in send_and_recv_msgs, ret=%d",
8670 __func__, ret);
8671 }
8672
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07008673 if (!dut->sta_async_twt_supp)
8674 return ret;
8675
8676 return twt_async_event_wait(dut, QCA_WLAN_TWT_SUSPEND);
Srinivas Girigowda6707f032020-10-26 15:24:46 -07008677#else /* NL80211_SUPPORT */
8678 sigma_dut_print(dut, DUT_MSG_ERROR,
8679 "TWT suspend cannot be done without NL80211_SUPPORT defined");
8680 return ERROR_SEND_STATUS;
8681#endif /* NL80211_SUPPORT */
8682}
8683
8684
8685static int sta_twt_send_nudge(struct sigma_dut *dut, struct sigma_conn *conn,
8686 struct sigma_cmd *cmd,
8687 unsigned int suspend_duration)
8688{
8689#ifdef NL80211_SUPPORT
8690 struct nlattr *attr, *attr1;
8691 struct nl_msg *msg;
8692 int ifindex, ret;
8693 const char *intf = get_param(cmd, "Interface");
8694 int next_twt_size = 1;
8695
8696 ifindex = if_nametoindex(intf);
8697 if (ifindex == 0) {
8698 sigma_dut_print(dut, DUT_MSG_ERROR,
8699 "%s: Index for interface %s failed",
8700 __func__, intf);
8701 return ERROR_SEND_STATUS;
8702 }
8703
8704 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8705 NL80211_CMD_VENDOR)) ||
8706 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8707 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8708 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8709 QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) ||
8710 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8711 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION,
8712 QCA_WLAN_TWT_NUDGE) ||
8713 !(attr1 = nla_nest_start(msg,
8714 QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS)) ||
8715 (suspend_duration &&
8716 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_NUDGE_WAKE_TIME,
8717 suspend_duration)) ||
8718 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_NUDGE_NEXT_TWT_SIZE,
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -07008719 next_twt_size) ||
8720 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_NUDGE_FLOW_ID, 0)) {
Srinivas Girigowda6707f032020-10-26 15:24:46 -07008721 sigma_dut_print(dut, DUT_MSG_ERROR,
8722 "%s: err in adding vendor_cmd and vendor_data",
8723 __func__);
8724 nlmsg_free(msg);
8725 return ERROR_SEND_STATUS;
8726 }
8727 nla_nest_end(msg, attr1);
8728 nla_nest_end(msg, attr);
8729
8730 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8731 if (ret) {
8732 sigma_dut_print(dut, DUT_MSG_ERROR,
8733 "%s: err in send_and_recv_msgs, ret=%d",
8734 __func__, ret);
8735 }
8736
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07008737 if (!dut->sta_async_twt_supp)
8738 return ret;
8739
8740 return twt_async_event_wait(dut, QCA_WLAN_TWT_NUDGE);
Srinivas Girigowda6707f032020-10-26 15:24:46 -07008741#else /* NL80211_SUPPORT */
8742 sigma_dut_print(dut, DUT_MSG_ERROR,
8743 "TWT suspend cannot be done without NL80211_SUPPORT defined");
8744 return ERROR_SEND_STATUS;
8745#endif /* NL80211_SUPPORT */
8746}
8747
8748
8749static int sta_twt_suspend_or_nudge(struct sigma_dut *dut,
8750 struct sigma_conn *conn,
8751 struct sigma_cmd *cmd)
8752{
8753 const char *val;
8754
8755 val = get_param(cmd, "TWT_SuspendDuration");
8756 if (val) {
8757 unsigned int suspend_duration;
8758
8759 suspend_duration = atoi(val);
8760 suspend_duration = suspend_duration * 1000 * 1000;
8761 return sta_twt_send_nudge(dut, conn, cmd, suspend_duration);
8762 }
8763
8764 return sta_twt_send_suspend(dut, conn, cmd);
8765}
8766
8767
8768static int sta_twt_resume(struct sigma_dut *dut, struct sigma_conn *conn,
8769 struct sigma_cmd *cmd)
8770{
8771#ifdef NL80211_SUPPORT
8772 struct nlattr *attr, *attr1;
8773 struct nl_msg *msg;
8774 int ifindex, ret;
8775 const char *intf = get_param(cmd, "Interface");
8776 int next2_twt_size = 1;
8777 unsigned int resume_duration = 0;
8778 const char *val;
8779
8780 ifindex = if_nametoindex(intf);
8781 if (ifindex == 0) {
8782 sigma_dut_print(dut, DUT_MSG_ERROR,
8783 "%s: Index for interface %s failed",
8784 __func__, intf);
8785 return ERROR_SEND_STATUS;
8786 }
8787
8788 val = get_param(cmd, "TWT_ResumeDuration");
8789 if (val) {
8790 resume_duration = atoi(val);
8791 resume_duration = resume_duration * 1000 * 1000;
8792 }
8793
8794 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8795 NL80211_CMD_VENDOR)) ||
8796 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8797 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8798 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8799 QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) ||
8800 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8801 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION,
8802 QCA_WLAN_TWT_RESUME) ||
8803 !(attr1 = nla_nest_start(msg,
8804 QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS)) ||
8805 (resume_duration &&
8806 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_RESUME_NEXT2_TWT,
8807 resume_duration)) ||
8808 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_RESUME_NEXT_TWT_SIZE,
8809 next2_twt_size)) {
8810 sigma_dut_print(dut, DUT_MSG_ERROR,
8811 "%s: err in adding vendor_cmd and vendor_data",
8812 __func__);
8813 nlmsg_free(msg);
8814 return ERROR_SEND_STATUS;
8815 }
8816 nla_nest_end(msg, attr1);
8817 nla_nest_end(msg, attr);
8818
8819 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8820 if (ret) {
8821 sigma_dut_print(dut, DUT_MSG_ERROR,
8822 "%s: err in send_and_recv_msgs, ret=%d",
8823 __func__, ret);
8824 }
8825
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07008826 if (!dut->sta_async_twt_supp)
8827 return ret;
8828
8829 return twt_async_event_wait(dut, QCA_WLAN_TWT_RESUME);
Srinivas Girigowda6707f032020-10-26 15:24:46 -07008830#else /* NL80211_SUPPORT */
8831 sigma_dut_print(dut, DUT_MSG_ERROR,
8832 "TWT resume cannot be done without NL80211_SUPPORT defined");
8833 return ERROR_SEND_STATUS;
8834#endif /* NL80211_SUPPORT */
8835}
8836
8837
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07008838#define TWT_REQUEST_CMD 0
8839#define TWT_SUGGEST_CMD 1
8840#define TWT_DEMAND_CMD 2
8841
Arif Hussain480d5f42019-03-12 14:40:42 -07008842static int sta_twt_request(struct sigma_dut *dut, struct sigma_conn *conn,
8843 struct sigma_cmd *cmd)
8844{
8845#ifdef NL80211_SUPPORT
8846 struct nlattr *params;
8847 struct nlattr *attr;
Arif Hussain480d5f42019-03-12 14:40:42 -07008848 struct nl_msg *msg;
8849 int ifindex, ret;
8850 const char *val;
8851 const char *intf = get_param(cmd, "Interface");
8852 int wake_interval_exp = 10, nominal_min_wake_dur = 255,
8853 wake_interval_mantissa = 512;
8854 int flow_type = 0, twt_trigger = 0, target_wake_time = 0,
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07008855 protection = 0, cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_SUGGEST;
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -07008856 int bcast_twt = 0;
8857 int bcast_twt_id = 0, bcast_twt_recommdn = 0, bcast_twt_persis = 0;
Arif Hussain480d5f42019-03-12 14:40:42 -07008858
8859 ifindex = if_nametoindex(intf);
8860 if (ifindex == 0) {
8861 sigma_dut_print(dut, DUT_MSG_ERROR,
8862 "%s: Index for interface %s failed",
8863 __func__, intf);
8864 return -1;
8865 }
8866
8867 val = get_param(cmd, "FlowType");
8868 if (val) {
8869 flow_type = atoi(val);
8870 if (flow_type != 0 && flow_type != 1) {
8871 sigma_dut_print(dut, DUT_MSG_ERROR,
8872 "TWT: Invalid FlowType %d", flow_type);
8873 return -1;
8874 }
8875 }
8876
8877 val = get_param(cmd, "TWT_Trigger");
8878 if (val) {
8879 twt_trigger = atoi(val);
8880 if (twt_trigger != 0 && twt_trigger != 1) {
8881 sigma_dut_print(dut, DUT_MSG_ERROR,
8882 "TWT: Invalid TWT_Trigger %d",
8883 twt_trigger);
8884 return -1;
8885 }
8886 }
8887
8888 val = get_param(cmd, "Protection");
8889 if (val) {
8890 protection = atoi(val);
8891 if (protection != 0 && protection != 1) {
8892 sigma_dut_print(dut, DUT_MSG_ERROR,
8893 "TWT: Invalid Protection %d",
8894 protection);
8895 return -1;
8896 }
8897 }
8898
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07008899 val = get_param(cmd, "SetupCommand");
8900 if (val) {
8901 cmd_type = atoi(val);
8902 if (cmd_type == TWT_REQUEST_CMD)
8903 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_REQUEST;
8904 else if (cmd_type == TWT_SUGGEST_CMD)
8905 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_SUGGEST;
8906 else if (cmd_type == TWT_DEMAND_CMD)
8907 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_DEMAND;
8908 else
8909 sigma_dut_print(dut, DUT_MSG_ERROR,
8910 "Default suggest is used for cmd %d",
8911 cmd_type);
8912 }
8913
Arif Hussain480d5f42019-03-12 14:40:42 -07008914 val = get_param(cmd, "TargetWakeTime");
8915 if (val)
8916 target_wake_time = atoi(val);
8917
8918 val = get_param(cmd, "WakeIntervalMantissa");
8919 if (val)
8920 wake_interval_mantissa = atoi(val);
8921
8922 val = get_param(cmd, "WakeIntervalExp");
8923 if (val)
8924 wake_interval_exp = atoi(val);
8925
8926 val = get_param(cmd, "NominalMinWakeDur");
8927 if (val)
8928 nominal_min_wake_dur = atoi(val);
8929
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -07008930 val = get_param(cmd, "BTWT_ID");
8931 if (val) {
8932 bcast_twt_id = atoi(val);
8933 bcast_twt = 1;
8934 }
8935
8936 val = get_param(cmd, "BTWT_Persistence");
8937 if (val) {
8938 bcast_twt_persis = atoi(val);
8939 bcast_twt = 1;
8940 }
8941
8942 val = get_param(cmd, "BTWT_Recommendation");
8943 if (val) {
8944 bcast_twt_recommdn = atoi(val);
8945 bcast_twt = 1;
8946 }
8947
8948 if (bcast_twt)
8949 sigma_dut_print(dut, DUT_MSG_DEBUG,
8950 "BCAST_TWT: ID %d, RECOMM %d, PERSIS %d",
8951 bcast_twt_id, bcast_twt_recommdn,
8952 bcast_twt_persis);
8953
Arif Hussain480d5f42019-03-12 14:40:42 -07008954 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8955 NL80211_CMD_VENDOR)) ||
8956 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8957 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8958 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
Srinivas Girigowda6707f032020-10-26 15:24:46 -07008959 QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008960 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
Srinivas Girigowda6707f032020-10-26 15:24:46 -07008961 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION,
8962 QCA_WLAN_TWT_SET) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008963 !(params = nla_nest_start(
Srinivas Girigowda6707f032020-10-26 15:24:46 -07008964 msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008965 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_EXP,
8966 wake_interval_exp) ||
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07008967 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_REQ_TYPE, cmd_type) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -07008968 (twt_trigger &&
8969 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_TRIGGER)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008970 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE,
8971 flow_type) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -07008972 (protection &&
8973 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_PROTECTION)) ||
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -07008974 (bcast_twt &&
8975 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_BCAST)) ||
8976 (bcast_twt &&
8977 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_BCAST_ID,
8978 bcast_twt_id)) ||
8979 (bcast_twt &&
8980 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_BCAST_PERSISTENCE,
8981 bcast_twt_persis)) ||
8982 (bcast_twt &&
8983 nla_put_u8(msg,
8984 QCA_WLAN_VENDOR_ATTR_TWT_SETUP_BCAST_RECOMMENDATION,
8985 bcast_twt_recommdn)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008986 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_TIME,
8987 target_wake_time) ||
8988 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_DURATION,
8989 nominal_min_wake_dur) ||
8990 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_MANTISSA,
8991 wake_interval_mantissa)) {
8992 sigma_dut_print(dut, DUT_MSG_ERROR,
8993 "%s: err in adding vendor_cmd and vendor_data",
8994 __func__);
8995 nlmsg_free(msg);
8996 return -1;
8997 }
Arif Hussain480d5f42019-03-12 14:40:42 -07008998 nla_nest_end(msg, params);
8999 nla_nest_end(msg, attr);
9000
9001 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9002 if (ret) {
9003 sigma_dut_print(dut, DUT_MSG_ERROR,
9004 "%s: err in send_and_recv_msgs, ret=%d",
9005 __func__, ret);
9006 }
9007
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07009008 if (!dut->sta_async_twt_supp)
9009 return ret;
9010
9011 return twt_async_event_wait(dut, QCA_WLAN_TWT_SET);
Arif Hussain480d5f42019-03-12 14:40:42 -07009012#else /* NL80211_SUPPORT */
9013 sigma_dut_print(dut, DUT_MSG_ERROR,
9014 "TWT request cannot be done without NL80211_SUPPORT defined");
9015 return -1;
9016#endif /* NL80211_SUPPORT */
9017}
9018
9019
9020static int sta_twt_teardown(struct sigma_dut *dut, struct sigma_conn *conn,
9021 struct sigma_cmd *cmd)
9022{
9023 #ifdef NL80211_SUPPORT
9024 struct nlattr *params;
9025 struct nlattr *attr;
Arif Hussain480d5f42019-03-12 14:40:42 -07009026 int ifindex, ret;
9027 struct nl_msg *msg;
9028 const char *intf = get_param(cmd, "Interface");
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -07009029 int bcast_twt = 0;
9030 int bcast_twt_id = 0;
9031 const char *val;
Arif Hussain480d5f42019-03-12 14:40:42 -07009032
9033 ifindex = if_nametoindex(intf);
9034 if (ifindex == 0) {
9035 sigma_dut_print(dut, DUT_MSG_ERROR,
9036 "%s: Index for interface %s failed",
9037 __func__, intf);
9038 return -1;
9039 }
9040
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -07009041 val = get_param(cmd, "BTWT_ID");
9042 if (val) {
9043 bcast_twt_id = atoi(val);
9044 bcast_twt = 1;
9045 }
9046
Arif Hussain480d5f42019-03-12 14:40:42 -07009047 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9048 NL80211_CMD_VENDOR)) ||
9049 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9050 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9051 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009052 QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07009053 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009054 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION,
9055 QCA_WLAN_TWT_TERMINATE) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07009056 !(params = nla_nest_start(
9057 msg,
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009058 QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS)) ||
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -07009059 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE, 0) ||
9060 (bcast_twt &&
9061 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_BCAST)) ||
9062 (bcast_twt &&
9063 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_BCAST_ID,
9064 bcast_twt_id))) {
Arif Hussain480d5f42019-03-12 14:40:42 -07009065 sigma_dut_print(dut, DUT_MSG_ERROR,
9066 "%s: err in adding vendor_cmd and vendor_data",
9067 __func__);
9068 nlmsg_free(msg);
9069 return -1;
9070 }
Arif Hussain480d5f42019-03-12 14:40:42 -07009071 nla_nest_end(msg, params);
9072 nla_nest_end(msg, attr);
9073
9074 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9075 if (ret) {
9076 sigma_dut_print(dut, DUT_MSG_ERROR,
9077 "%s: err in send_and_recv_msgs, ret=%d",
9078 __func__, ret);
9079 }
9080
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07009081 if (!dut->sta_async_twt_supp)
9082 return ret;
9083
9084 return twt_async_event_wait(dut, QCA_WLAN_TWT_TERMINATE);
Arif Hussain480d5f42019-03-12 14:40:42 -07009085#else /* NL80211_SUPPORT */
9086 sigma_dut_print(dut, DUT_MSG_ERROR,
9087 "TWT teardown cannot be done without NL80211_SUPPORT defined");
9088 return -1;
9089#endif /* NL80211_SUPPORT */
9090}
9091
9092
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -08009093static int sta_transmit_omi(struct sigma_dut *dut, struct sigma_conn *conn,
9094 struct sigma_cmd *cmd)
9095{
9096#ifdef NL80211_SUPPORT
9097 struct nlattr *params;
9098 struct nlattr *attr;
9099 struct nlattr *attr1;
9100 struct nl_msg *msg;
9101 int ifindex, ret;
9102 const char *val;
9103 const char *intf = get_param(cmd, "Interface");
9104 uint8_t rx_nss = 0xFF, ch_bw = 0xFF, tx_nsts = 0xFF, ulmu_dis = 0,
9105 ulmu_data_dis = 0;
9106
9107 ifindex = if_nametoindex(intf);
9108 if (ifindex == 0) {
9109 sigma_dut_print(dut, DUT_MSG_ERROR,
9110 "%s: Index for interface %s failed",
9111 __func__, intf);
9112 return -1;
9113 }
9114 val = get_param(cmd, "OMCtrl_RxNSS");
9115 if (val)
9116 rx_nss = atoi(val);
9117
9118 val = get_param(cmd, "OMCtrl_ChnlWidth");
9119 if (val)
9120 ch_bw = atoi(val);
9121
9122 val = get_param(cmd, "OMCtrl_ULMUDisable");
9123 if (val)
9124 ulmu_dis = atoi(val);
9125
9126 val = get_param(cmd, "OMCtrl_TxNSTS");
9127 if (val)
9128 tx_nsts = atoi(val);
9129
9130 val = get_param(cmd, "OMCtrl_ULMUDataDisable");
9131 if (val)
9132 ulmu_data_dis = atoi(val);
9133
9134 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9135 NL80211_CMD_VENDOR)) ||
9136 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9137 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9138 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9139 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
9140 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9141 !(params = nla_nest_start(
9142 msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OMI_TX)) ||
9143 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9144 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_RX_NSS, rx_nss) ||
9145 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_CH_BW, ch_bw) ||
9146 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_TX_NSTS, tx_nsts) ||
9147 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DATA_DISABLE,
9148 ulmu_data_dis) ||
9149 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DISABLE,
9150 ulmu_dis)) {
9151 sigma_dut_print(dut, DUT_MSG_ERROR,
9152 "%s: err in adding vendor_cmd and vendor_data",
9153 __func__);
9154 nlmsg_free(msg);
9155 return -1;
9156 }
9157 nla_nest_end(msg, attr1);
9158 nla_nest_end(msg, params);
9159 nla_nest_end(msg, attr);
9160
9161 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9162 if (ret) {
9163 sigma_dut_print(dut, DUT_MSG_ERROR,
9164 "%s: err in send_and_recv_msgs, ret=%d",
9165 __func__, ret);
9166 }
9167
9168 return ret;
9169#else /* NL80211_SUPPORT */
9170 sigma_dut_print(dut, DUT_MSG_ERROR,
9171 "OMI TX cannot be processed without NL80211_SUPPORT defined");
9172 return -1;
9173#endif /* NL80211_SUPPORT */
9174}
9175
9176
Jouni Malinen224e3902021-06-09 16:41:27 +03009177static enum sigma_cmd_result
9178cmd_sta_set_wireless_vht(struct sigma_dut *dut, struct sigma_conn *conn,
9179 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009180{
9181 const char *intf = get_param(cmd, "Interface");
9182 const char *val;
Arif Hussaina37e9552018-06-20 17:05:59 -07009183 const char *program;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009184 int tkip = -1;
9185 int wep = -1;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05309186 int iwpriv_status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009187
Arif Hussaina37e9552018-06-20 17:05:59 -07009188 program = get_param(cmd, "Program");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009189 val = get_param(cmd, "SGI80");
9190 if (val) {
9191 int sgi80;
9192
9193 sgi80 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009194 run_iwpriv(dut, intf, "shortgi %d", sgi80);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009195 }
9196
9197 val = get_param(cmd, "TxBF");
9198 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009199 switch (get_driver_type(dut)) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009200 case DRIVER_WCN:
9201 if (sta_set_tx_beamformee(dut, intf, 1)) {
9202 send_resp(dut, conn, SIGMA_ERROR,
9203 "ErrorCode,Failed to set TX beamformee enable");
Jouni Malinen224e3902021-06-09 16:41:27 +03009204 return STATUS_SENT_ERROR;
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009205 }
9206 break;
9207 case DRIVER_ATHEROS:
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009208 if (run_iwpriv(dut, intf, "vhtsubfee 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009209 send_resp(dut, conn, SIGMA_ERROR,
9210 "ErrorCode,Setting vhtsubfee failed");
Jouni Malinen224e3902021-06-09 16:41:27 +03009211 return STATUS_SENT_ERROR;
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009212 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009213 if (run_iwpriv(dut, intf, "vhtsubfer 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009214 send_resp(dut, conn, SIGMA_ERROR,
9215 "ErrorCode,Setting vhtsubfer failed");
Jouni Malinen224e3902021-06-09 16:41:27 +03009216 return STATUS_SENT_ERROR;
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009217 }
9218 break;
9219 default:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009220 sigma_dut_print(dut, DUT_MSG_ERROR,
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009221 "Unsupported driver type");
9222 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009223 }
9224 }
9225
9226 val = get_param(cmd, "MU_TxBF");
9227 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009228 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009229 case DRIVER_ATHEROS:
9230 ath_sta_set_txsp_stream(dut, intf, "1SS");
9231 ath_sta_set_rxsp_stream(dut, intf, "1SS");
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009232 run_iwpriv(dut, intf, "vhtmubfee 1");
9233 run_iwpriv(dut, intf, "vhtmubfer 1");
Sunil Duttae9e5d12018-06-29 11:50:47 +05309234 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009235 case DRIVER_WCN:
9236 if (wcn_sta_set_sp_stream(dut, intf, "1SS") < 0) {
9237 send_resp(dut, conn, SIGMA_ERROR,
9238 "ErrorCode,Failed to set RX/TXSP_STREAM");
Jouni Malinen224e3902021-06-09 16:41:27 +03009239 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009240 }
Sunil Duttae9e5d12018-06-29 11:50:47 +05309241 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009242 default:
9243 sigma_dut_print(dut, DUT_MSG_ERROR,
9244 "Setting SP_STREAM not supported");
9245 break;
9246 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009247 }
9248
9249 val = get_param(cmd, "LDPC");
9250 if (val) {
9251 int ldpc;
9252
9253 ldpc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05309254 iwpriv_status = run_iwpriv(dut, intf, "ldpc %d", ldpc);
9255 if (iwpriv_status)
9256 sta_config_params(dut, intf, STA_SET_LDPC, ldpc);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009257 }
9258
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08009259 val = get_param(cmd, "BCC");
9260 if (val) {
9261 int bcc;
9262
9263 bcc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
9264 /* use LDPC iwpriv itself to set bcc coding, bcc coding
9265 * is mutually exclusive to bcc */
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05309266 iwpriv_status = run_iwpriv(dut, intf, "ldpc %d", !bcc);
9267 if (iwpriv_status)
9268 sta_config_params(dut, intf, STA_SET_LDPC, !bcc);
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08009269 }
9270
Arif Hussain7b47d2d2018-05-09 10:44:02 -07009271 val = get_param(cmd, "MaxHE-MCS_1SS_RxMapLTE80");
9272 if (val && dut->sta_nss == 1)
9273 cmd_set_max_he_mcs(dut, intf, atoi(val));
9274
9275 val = get_param(cmd, "MaxHE-MCS_2SS_RxMapLTE80");
9276 if (val && dut->sta_nss == 2)
9277 cmd_set_max_he_mcs(dut, intf, atoi(val));
9278
Arif Hussainac6c5112018-05-25 17:34:00 -07009279 val = get_param(cmd, "MCS_FixedRate");
9280 if (val) {
9281#ifdef NL80211_SUPPORT
9282 int mcs, ratecode = 0;
9283 enum he_mcs_config mcs_config;
9284 int ret;
Jouni Malinenb9b671d2019-04-26 13:23:17 +03009285 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07009286
9287 ratecode = (0x07 & dut->sta_nss) << 5;
9288 mcs = atoi(val);
9289 /* Add the MCS to the ratecode */
9290 if (mcs >= 0 && mcs <= 11) {
9291 ratecode += mcs;
9292 if (dut->device_type == STA_testbed &&
9293 mcs > 7 && mcs <= 11) {
9294 if (mcs <= 9)
9295 mcs_config = HE_80_MCS0_9;
9296 else
9297 mcs_config = HE_80_MCS0_11;
9298 ret = sta_set_he_mcs(dut, intf, mcs_config);
9299 if (ret) {
9300 sigma_dut_print(dut, DUT_MSG_ERROR,
9301 "MCS_FixedRate: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
9302 mcs, mcs_config, ret);
9303 }
9304 }
9305 snprintf(buf, sizeof(buf),
9306 "iwpriv %s set_11ax_rate 0x%03x",
9307 intf, ratecode);
9308 if (system(buf) != 0) {
9309 sigma_dut_print(dut, DUT_MSG_ERROR,
9310 "MCS_FixedRate: iwpriv setting of 11ax rates 0x%03x failed",
9311 ratecode);
9312 }
9313 } else {
9314 sigma_dut_print(dut, DUT_MSG_ERROR,
9315 "MCS_FixedRate: HE MCS %d not supported",
9316 mcs);
9317 }
9318#else /* NL80211_SUPPORT */
9319 sigma_dut_print(dut, DUT_MSG_ERROR,
9320 "MCS_FixedRate cannot be changed without NL80211_SUPPORT defined");
9321#endif /* NL80211_SUPPORT */
9322 }
9323
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009324 val = get_param(cmd, "opt_md_notif_ie");
9325 if (val) {
9326 char *result = NULL;
9327 char delim[] = ";";
9328 char token[30];
9329 int value, config_val = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309330 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009331
Peng Xub8fc5cc2017-05-10 17:27:28 -07009332 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309333 result = strtok_r(token, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009334
9335 /* Extract the NSS information */
9336 if (result) {
9337 value = atoi(result);
9338 switch (value) {
9339 case 1:
9340 config_val = 1;
9341 break;
9342 case 2:
9343 config_val = 3;
9344 break;
9345 case 3:
9346 config_val = 7;
9347 break;
9348 case 4:
9349 config_val = 15;
9350 break;
9351 default:
9352 config_val = 3;
9353 break;
9354 }
9355
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009356 run_iwpriv(dut, intf, "rxchainmask %d", config_val);
9357 run_iwpriv(dut, intf, "txchainmask %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009358
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009359 }
9360
9361 /* Extract the channel width information */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309362 result = strtok_r(NULL, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009363 if (result) {
9364 value = atoi(result);
9365 switch (value) {
9366 case 20:
9367 config_val = 0;
9368 break;
9369 case 40:
9370 config_val = 1;
9371 break;
9372 case 80:
9373 config_val = 2;
9374 break;
9375 case 160:
9376 config_val = 3;
9377 break;
9378 default:
9379 config_val = 2;
9380 break;
9381 }
9382
9383 dut->chwidth = config_val;
9384
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009385 run_iwpriv(dut, intf, "chwidth %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009386 }
9387
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009388 run_iwpriv(dut, intf, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009389 }
9390
9391 val = get_param(cmd, "nss_mcs_cap");
9392 if (val) {
9393 int nss, mcs;
9394 char token[20];
9395 char *result = NULL;
9396 unsigned int vht_mcsmap = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309397 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009398
Peng Xub8fc5cc2017-05-10 17:27:28 -07009399 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309400 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05309401 if (!result) {
9402 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07009403 "NSS not specified");
9404 send_resp(dut, conn, SIGMA_ERROR,
9405 "errorCode,NSS not specified");
Jouni Malinen224e3902021-06-09 16:41:27 +03009406 return STATUS_SENT_ERROR;
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05309407 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009408 nss = atoi(result);
9409
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009410 run_iwpriv(dut, intf, "nss %d", nss);
Arif Hussainac6c5112018-05-25 17:34:00 -07009411 dut->sta_nss = nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009412
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309413 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009414 if (result == NULL) {
9415 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07009416 "MCS not specified");
9417 send_resp(dut, conn, SIGMA_ERROR,
9418 "errorCode,MCS not specified");
Jouni Malinen224e3902021-06-09 16:41:27 +03009419 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009420 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309421 result = strtok_r(result, "-", &saveptr);
9422 result = strtok_r(NULL, "-", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05309423 if (!result) {
9424 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07009425 "MCS not specified");
9426 send_resp(dut, conn, SIGMA_ERROR,
9427 "errorCode,MCS not specified");
Jouni Malinen224e3902021-06-09 16:41:27 +03009428 return STATUS_SENT_ERROR;
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05309429 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009430 mcs = atoi(result);
9431
Arif Hussaina37e9552018-06-20 17:05:59 -07009432 if (program && strcasecmp(program, "HE") == 0) {
9433#ifdef NL80211_SUPPORT
9434 enum he_mcs_config mcs_config;
9435 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009436
Arif Hussaina37e9552018-06-20 17:05:59 -07009437 if (mcs >= 0 && mcs <= 7) {
9438 mcs_config = HE_80_MCS0_7;
9439 } else if (mcs > 7 && mcs <= 9) {
9440 mcs_config = HE_80_MCS0_9;
9441 } else if (mcs > 9 && mcs <= 11) {
9442 mcs_config = HE_80_MCS0_11;
9443 } else {
9444 sigma_dut_print(dut, DUT_MSG_ERROR,
9445 "nss_mcs_cap: HE: Invalid mcs: %d",
9446 mcs);
9447 send_resp(dut, conn, SIGMA_ERROR,
9448 "errorCode,Invalid MCS");
Jouni Malinen224e3902021-06-09 16:41:27 +03009449 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009450 }
Arif Hussaina37e9552018-06-20 17:05:59 -07009451
9452 ret = sta_set_he_mcs(dut, intf, mcs_config);
9453 if (ret) {
9454 sigma_dut_print(dut, DUT_MSG_ERROR,
9455 "nss_mcs_cap: HE: Setting of MCS failed, mcs_config: %d, ret: %d",
9456 mcs_config, ret);
9457 send_resp(dut, conn, SIGMA_ERROR,
9458 "errorCode,Failed to set MCS");
Jouni Malinen224e3902021-06-09 16:41:27 +03009459 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009460 }
Arif Hussaina37e9552018-06-20 17:05:59 -07009461#else /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009462 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07009463 "nss_mcs_cap: HE: MCS cannot be changed without NL80211_SUPPORT defined");
9464#endif /* NL80211_SUPPORT */
9465 } else {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009466 run_iwpriv(dut, intf, "vhtmcs %d", mcs);
Arif Hussaina37e9552018-06-20 17:05:59 -07009467
9468 switch (nss) {
9469 case 1:
9470 switch (mcs) {
9471 case 7:
9472 vht_mcsmap = 0xfffc;
9473 break;
9474 case 8:
9475 vht_mcsmap = 0xfffd;
9476 break;
9477 case 9:
9478 vht_mcsmap = 0xfffe;
9479 break;
9480 default:
9481 vht_mcsmap = 0xfffe;
9482 break;
9483 }
9484 break;
9485 case 2:
9486 switch (mcs) {
9487 case 7:
9488 vht_mcsmap = 0xfff0;
9489 break;
9490 case 8:
9491 vht_mcsmap = 0xfff5;
9492 break;
9493 case 9:
9494 vht_mcsmap = 0xfffa;
9495 break;
9496 default:
9497 vht_mcsmap = 0xfffa;
9498 break;
9499 }
9500 break;
9501 case 3:
9502 switch (mcs) {
9503 case 7:
9504 vht_mcsmap = 0xffc0;
9505 break;
9506 case 8:
9507 vht_mcsmap = 0xffd5;
9508 break;
9509 case 9:
9510 vht_mcsmap = 0xffea;
9511 break;
9512 default:
9513 vht_mcsmap = 0xffea;
9514 break;
9515 }
9516 break;
9517 default:
9518 vht_mcsmap = 0xffea;
9519 break;
9520 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009521 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009522 }
9523 }
9524
9525 /* UNSUPPORTED: val = get_param(cmd, "Tx_lgi_rate"); */
9526
9527 val = get_param(cmd, "Vht_tkip");
9528 if (val)
9529 tkip = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
9530
9531 val = get_param(cmd, "Vht_wep");
9532 if (val)
9533 wep = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
9534
9535 if (tkip != -1 || wep != -1) {
9536 if ((tkip == 1 && wep != 0) || (wep == 1 && tkip != 0)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009537 run_iwpriv(dut, intf, "htweptkip 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009538 } else if ((tkip == 0 && wep != 1) || (wep == 0 && tkip != 1)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009539 run_iwpriv(dut, intf, "htweptkip 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009540 } else {
Jouni Malinen224e3902021-06-09 16:41:27 +03009541 send_resp(dut, conn, SIGMA_ERROR,
9542 "ErrorCode,mixed mode of VHT TKIP/WEP not supported");
9543 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009544 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009545 }
9546
Kiran Kumar Lokere09dbcef2021-08-09 00:01:41 -07009547 val = get_param(cmd, "TWTSchedSTASupport");
9548 if (val) {
9549 int set_val;
9550
9551 switch (get_driver_type(dut)) {
9552 case DRIVER_WCN:
9553 if (strcasecmp(val, "Enable") == 0) {
9554 set_val = 1;
9555 } else if (strcasecmp(val, "Disable") == 0) {
9556 set_val = 0;
9557 } else {
9558 send_resp(dut, conn, SIGMA_ERROR,
9559 "ErrorCode,Invalid TWTSchedSTASupport");
9560 return STATUS_SENT_ERROR;
9561 }
9562
9563 if (sta_set_bcast_twt_support(dut, intf, set_val)) {
9564 send_resp(dut, conn, SIGMA_ERROR,
9565 "ErrorCode,Failed to set TWTSchedSTASupport");
9566 return STATUS_SENT_ERROR;
9567 }
9568 break;
9569 default:
9570 sigma_dut_print(dut, DUT_MSG_ERROR,
9571 "Setting TWTSchedSTASupport not supported");
9572 break;
9573 }
9574 }
9575
9576 val = get_param(cmd, "MBSSID_RxCtrl");
9577 if (val) {
9578 int set_val;
9579
9580 switch (get_driver_type(dut)) {
9581 case DRIVER_WCN:
9582 if (strcasecmp(val, "Enable") == 0) {
9583 set_val = 1;
9584 } else if (strcasecmp(val, "Disable") == 0) {
9585 set_val = 0;
9586 } else {
9587 send_resp(dut, conn, SIGMA_ERROR,
9588 "ErrorCode,Invalid MBSSID_RxCtrl");
9589 return STATUS_SENT_ERROR;
9590 }
9591
9592 if (sta_set_rx_ctrl_multi_bss(dut, intf, set_val)) {
9593 send_resp(dut, conn, SIGMA_ERROR,
9594 "ErrorCode,Failed to set MBSSID_RxCtrl");
9595 return STATUS_SENT_ERROR;
9596 }
9597 break;
9598 default:
9599 sigma_dut_print(dut, DUT_MSG_ERROR,
9600 "Setting MBSSID_RxCtrl not supported");
9601 break;
9602 }
9603 }
9604
Arif Hussain55f00da2018-07-03 08:28:26 -07009605 val = get_param(cmd, "txBandwidth");
9606 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009607 switch (get_driver_type(dut)) {
Arif Hussain55f00da2018-07-03 08:28:26 -07009608 case DRIVER_WCN:
9609 if (wcn_sta_set_width(dut, intf, val) < 0) {
9610 send_resp(dut, conn, SIGMA_ERROR,
9611 "ErrorCode,Failed to set txBandwidth");
Jouni Malinen224e3902021-06-09 16:41:27 +03009612 return STATUS_SENT_ERROR;
Arif Hussain55f00da2018-07-03 08:28:26 -07009613 }
9614 break;
9615 case DRIVER_ATHEROS:
9616 if (ath_set_width(dut, conn, intf, val) < 0) {
9617 send_resp(dut, conn, SIGMA_ERROR,
9618 "ErrorCode,Failed to set txBandwidth");
Jouni Malinen224e3902021-06-09 16:41:27 +03009619 return STATUS_SENT_ERROR;
Arif Hussain55f00da2018-07-03 08:28:26 -07009620 }
9621 break;
9622 default:
9623 sigma_dut_print(dut, DUT_MSG_ERROR,
9624 "Setting txBandwidth not supported");
9625 break;
9626 }
9627 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009628
Arif Hussain9765f7d2018-07-03 08:28:26 -07009629 val = get_param(cmd, "BeamformeeSTS");
9630 if (val) {
Kiran Kumar Lokerebc89d432018-07-10 12:20:13 -07009631 if (sta_set_tx_beamformee(dut, intf, 1)) {
9632 send_resp(dut, conn, SIGMA_ERROR,
9633 "ErrorCode,Failed to set TX beamformee enable");
Jouni Malinen224e3902021-06-09 16:41:27 +03009634 return STATUS_SENT_ERROR;
Kiran Kumar Lokerebc89d432018-07-10 12:20:13 -07009635 }
9636
Arif Hussain9765f7d2018-07-03 08:28:26 -07009637 if (sta_set_beamformee_sts(dut, intf, atoi(val))) {
9638 send_resp(dut, conn, SIGMA_ERROR,
9639 "ErrorCode,Failed to set BeamformeeSTS");
Jouni Malinen224e3902021-06-09 16:41:27 +03009640 return STATUS_SENT_ERROR;
Arif Hussain9765f7d2018-07-03 08:28:26 -07009641 }
9642 }
9643
Arif Hussain68d23f52018-07-11 13:39:08 -07009644 val = get_param(cmd, "Trig_MAC_Padding_Dur");
9645 if (val) {
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07009646#ifdef NL80211_SUPPORT
9647 enum qca_wlan_he_mac_padding_dur set_val;
9648
9649 switch (atoi(val)) {
9650 case 16:
9651 set_val = QCA_WLAN_HE_16US_OF_PROCESS_TIME;
9652 break;
9653 case 8:
9654 set_val = QCA_WLAN_HE_8US_OF_PROCESS_TIME;
9655 break;
9656 default:
9657 set_val = QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME;
9658 break;
9659 }
9660 if (sta_set_mac_padding_duration(dut, intf, set_val)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07009661 send_resp(dut, conn, SIGMA_ERROR,
9662 "ErrorCode,Failed to set MAC padding duration");
Jouni Malinen224e3902021-06-09 16:41:27 +03009663 return STATUS_SENT_ERROR;
Arif Hussain68d23f52018-07-11 13:39:08 -07009664 }
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07009665#else /* NL80211_SUPPORT */
9666 sigma_dut_print(dut, DUT_MSG_ERROR,
9667 "MAC padding duration cannot be changed without NL80211_SUPPORT defined");
9668#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07009669 }
9670
Arif Hussain480d5f42019-03-12 14:40:42 -07009671 val = get_param(cmd, "TWT_ReqSupport");
9672 if (val) {
9673 int set_val;
9674
9675 if (strcasecmp(val, "Enable") == 0) {
9676 set_val = 1;
9677 } else if (strcasecmp(val, "Disable") == 0) {
9678 set_val = 0;
9679 } else {
9680 send_resp(dut, conn, SIGMA_ERROR,
9681 "ErrorCode,Invalid TWT_ReqSupport");
Jouni Malinen224e3902021-06-09 16:41:27 +03009682 return STATUS_SENT_ERROR;
Arif Hussain480d5f42019-03-12 14:40:42 -07009683 }
9684
9685 if (sta_set_twt_req_support(dut, intf, set_val)) {
9686 sigma_dut_print(dut, DUT_MSG_ERROR,
9687 "Failed to set TWT req support %d",
9688 set_val);
9689 send_resp(dut, conn, SIGMA_ERROR,
9690 "ErrorCode,Failed to set TWT_ReqSupport");
Jouni Malinen224e3902021-06-09 16:41:27 +03009691 return STATUS_SENT_ERROR;
Arif Hussain480d5f42019-03-12 14:40:42 -07009692 }
9693 }
9694
Kiran Kumar Lokered0ec5ed2021-04-01 00:15:04 -07009695 val = get_param(cmd, "PreamblePunctRx");
9696 if (val && get_driver_type(dut) == DRIVER_WCN) {
9697 int set_val;
9698
9699 if (strcasecmp(val, "Enable") == 0) {
9700 set_val = 1;
9701 } else if (strcasecmp(val, "Disable") == 0) {
9702 set_val = 0;
9703 } else {
9704 send_resp(dut, conn, SIGMA_ERROR,
9705 "ErrorCode,Invalid PreamblePunctRx");
9706 return STATUS_SENT_ERROR;
9707 }
9708
9709 if (sta_set_punctured_preamble_rx(dut, intf, set_val)) {
9710 sigma_dut_print(dut, DUT_MSG_ERROR,
9711 "Failed to set PreamblePunctRx support %d",
9712 set_val);
9713 send_resp(dut, conn, SIGMA_ERROR,
9714 "ErrorCode,Failed to set PreamblePunctRx");
9715 return STATUS_SENT_ERROR;
9716 }
9717 }
9718
Srinivas Girigowda0525e292020-11-12 13:28:21 -08009719 val = get_param(cmd, "FullBW_ULMUMIMO");
9720 if (val) {
9721 int set_val;
9722
9723 if (strcasecmp(val, "Enable") == 0) {
9724 set_val = 1;
9725 } else if (strcasecmp(val, "Disable") == 0) {
9726 set_val = 0;
9727 } else {
9728 send_resp(dut, conn, SIGMA_ERROR,
9729 "ErrorCode,Invalid FullBW_ULMUMIMO");
9730 return STATUS_SENT_ERROR;
9731 }
9732
9733 if (sta_set_fullbw_ulmumimo(dut, intf, set_val)) {
9734 sigma_dut_print(dut, DUT_MSG_ERROR,
9735 "Failed to set FullBW_ULMUMIMO %d",
9736 set_val);
9737 send_resp(dut, conn, SIGMA_ERROR,
9738 "ErrorCode,Failed to set FullBW_ULMUMIMO");
9739 return STATUS_SENT_ERROR;
9740 }
9741 }
9742
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009743 val = get_param(cmd, "TWTInfoFrameTx");
9744 if (val) {
9745 if (strcasecmp(val, "Enable") == 0) {
9746 /* No-op */
9747 } else if (strcasecmp(val, "Disable") == 0) {
9748 /* No-op */
9749 } else {
9750 send_resp(dut, conn, SIGMA_ERROR,
9751 "ErrorCode,Invalid TWTInfoFrameTx");
9752 return STATUS_SENT_ERROR;
9753 }
9754 }
9755
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07009756 val = get_param(cmd, "MU_EDCA");
9757 if (val && (strcasecmp(val, "Override") == 0)) {
9758 if (sta_set_mu_edca_override(dut, intf, 1)) {
9759 send_resp(dut, conn, SIGMA_ERROR,
9760 "ErrorCode,Failed to set MU EDCA override");
Jouni Malinen224e3902021-06-09 16:41:27 +03009761 return STATUS_SENT_ERROR;
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07009762 }
9763 }
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009764
Kiran Kumar Lokerefa7c7b92021-08-09 00:50:55 -07009765 val = get_param(cmd, "PPDUTxType");
9766 if (val && strcasecmp(val, "ER-SU") == 0) {
9767 if (sta_set_er_su_ppdu_type_tx(dut, intf, 1)) {
9768 send_resp(dut, conn, SIGMA_ERROR,
9769 "ErrorCode,Failed to set ER-SU PPDU type Tx");
9770 return STATUS_SENT_ERROR;
9771 }
9772 }
9773
9774 val = get_param(cmd, "RUAllocTone");
9775 if (val && strcasecmp(val, "242") == 0) {
9776 if (sta_set_ru_242_tone_tx(dut, intf, 1)) {
9777 send_resp(dut, conn, SIGMA_ERROR,
9778 "ErrorCode,Failed to set RU 242 tone Tx");
9779 return STATUS_SENT_ERROR;
9780 }
9781 }
9782
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07009783 val = get_param(cmd, "OMControl");
9784 if (val) {
9785 int set_val = 1;
9786
9787 if (strcasecmp(val, "Enable") == 0)
9788 set_val = 1;
9789 else if (strcasecmp(val, "Disable") == 0)
9790 set_val = 0;
9791
9792 if (sta_set_om_ctrl_supp(dut, intf, set_val)) {
9793 send_resp(dut, conn, SIGMA_ERROR,
9794 "ErrorCode,Failed to set OM ctrl supp");
Jouni Malinen224e3902021-06-09 16:41:27 +03009795 return STATUS_SENT_ERROR;
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07009796 }
9797 }
9798
Kiran Kumar Lokere4f2d4b02021-04-01 00:07:39 -07009799 val = get_param(cmd, "BSSMaxIdlePeriod");
9800 if (val && sta_set_bss_max_idle_period(dut, intf, atoi(val))) {
9801 send_resp(dut, conn, SIGMA_ERROR,
9802 "ErrorCode,Failed to set BSS max idle period");
9803 return STATUS_SENT_ERROR;
9804 }
9805
Kiran Kumar Lokere07ad92b2021-08-09 00:27:14 -07009806 val = get_param(cmd, "BSS_max_idle");
9807 if (val) {
9808 int set_val = 0;
9809
9810 if (strcasecmp(val, "Enable") == 0)
9811 set_val = 1;
9812 else if (strcasecmp(val, "Disable") == 0)
9813 set_val = 0;
9814 if (sta_set_bss_max_idle_support(dut, intf, set_val)) {
9815 send_resp(dut, conn, SIGMA_ERROR,
9816 "ErrorCode,Failed to set BSS max idle support");
9817 return STATUS_SENT_ERROR;
9818 }
9819 }
9820
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009821 val = get_param(cmd, "ADDBAResp_BufSize");
9822 if (val) {
9823 int buf_size;
9824
9825 if (strcasecmp(val, "gt64") == 0)
9826 buf_size = 256;
9827 else
9828 buf_size = 64;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009829 if (get_driver_type(dut) == DRIVER_WCN &&
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009830 sta_set_addba_buf_size(dut, intf, buf_size)) {
9831 send_resp(dut, conn, SIGMA_ERROR,
9832 "ErrorCode,set addbaresp_buff_size failed");
Jouni Malinen224e3902021-06-09 16:41:27 +03009833 return STATUS_SENT_ERROR;
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009834 }
9835 }
9836
9837 val = get_param(cmd, "ADDBAReq_BufSize");
9838 if (val) {
9839 int buf_size;
9840
9841 if (strcasecmp(val, "gt64") == 0)
9842 buf_size = 256;
9843 else
9844 buf_size = 64;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009845 if (get_driver_type(dut) == DRIVER_WCN &&
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009846 sta_set_addba_buf_size(dut, intf, buf_size)) {
9847 send_resp(dut, conn, SIGMA_ERROR,
9848 "ErrorCode,set addbareq_buff_size failed");
Jouni Malinen224e3902021-06-09 16:41:27 +03009849 return STATUS_SENT_ERROR;
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009850 }
9851 }
9852
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009853 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
9854}
9855
9856
9857static int sta_set_wireless_60g(struct sigma_dut *dut,
9858 struct sigma_conn *conn,
9859 struct sigma_cmd *cmd)
9860{
9861 const char *dev_role = get_param(cmd, "DevRole");
9862
9863 if (!dev_role) {
9864 send_resp(dut, conn, SIGMA_INVALID,
9865 "ErrorCode,DevRole not specified");
9866 return 0;
9867 }
9868
9869 if (strcasecmp(dev_role, "PCP") == 0)
9870 return sta_set_60g_pcp(dut, conn, cmd);
9871 if (strcasecmp(dev_role, "STA") == 0)
9872 return sta_set_60g_sta(dut, conn, cmd);
9873 send_resp(dut, conn, SIGMA_INVALID,
9874 "ErrorCode,DevRole not supported");
9875 return 0;
9876}
9877
9878
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05309879static int sta_set_wireless_oce(struct sigma_dut *dut, struct sigma_conn *conn,
9880 struct sigma_cmd *cmd)
9881{
9882 int status;
9883 const char *intf = get_param(cmd, "Interface");
9884 const char *val = get_param(cmd, "DevRole");
9885
9886 if (val && strcasecmp(val, "STA-CFON") == 0) {
9887 status = sta_cfon_set_wireless(dut, conn, cmd);
9888 if (status)
9889 return status;
9890 }
9891 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
9892}
9893
9894
Jouni Malinen67433fc2020-06-26 22:50:33 +03009895static enum sigma_cmd_result
9896sta_set_wireless_wpa3(struct sigma_dut *dut, struct sigma_conn *conn,
9897 struct sigma_cmd *cmd)
Vamsi Krishnac1633d22020-05-06 18:31:21 +05309898{
9899 const char *intf = get_param(cmd, "Interface");
9900 const char *val;
9901
9902 val = get_param(cmd, "ocvc");
9903 if (val)
9904 dut->ocvc = atoi(val);
9905
Jouni Malinen67433fc2020-06-26 22:50:33 +03009906 val = get_param(cmd, "ClientPrivacy");
Veerendranath Jakkam47867202020-12-21 01:53:52 +05309907 if (val && dut->client_privacy != atoi(val) &&
9908 sta_set_client_privacy(dut, conn, intf, atoi(val))) {
9909 send_resp(dut, conn, SIGMA_ERROR,
9910 "errorCode,Failed to configure random MAC address use");
9911 return STATUS_SENT_ERROR;
Jouni Malinen67433fc2020-06-26 22:50:33 +03009912 }
9913
Vamsi Krishnac1633d22020-05-06 18:31:21 +05309914 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
9915}
9916
9917
Jouni Malinenf7222712019-06-13 01:50:21 +03009918static enum sigma_cmd_result cmd_sta_set_wireless(struct sigma_dut *dut,
9919 struct sigma_conn *conn,
9920 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009921{
9922 const char *val;
9923
9924 val = get_param(cmd, "Program");
9925 if (val) {
9926 if (strcasecmp(val, "11n") == 0)
9927 return cmd_sta_set_11n(dut, conn, cmd);
Amarnath Hullur Subramanyam4f860292018-01-31 03:49:35 -08009928 if (strcasecmp(val, "VHT") == 0 || strcasecmp(val, "HE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009929 return cmd_sta_set_wireless_vht(dut, conn, cmd);
9930 if (strcasecmp(val, "60ghz") == 0)
9931 return sta_set_wireless_60g(dut, conn, cmd);
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05309932 if (strcasecmp(val, "OCE") == 0)
9933 return sta_set_wireless_oce(dut, conn, cmd);
Alexei Avshalom Lazar66bb9972018-12-18 16:01:43 +02009934 /* sta_set_wireless in WPS program is only used for 60G */
9935 if (is_60g_sigma_dut(dut))
9936 return sta_set_wireless_60g(dut, conn, cmd);
Vamsi Krishnac1633d22020-05-06 18:31:21 +05309937 if (strcasecmp(val, "WPA3") == 0)
9938 return sta_set_wireless_wpa3(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009939 send_resp(dut, conn, SIGMA_ERROR,
9940 "ErrorCode,Program value not supported");
9941 } else {
9942 send_resp(dut, conn, SIGMA_ERROR,
9943 "ErrorCode,Program argument not available");
9944 }
9945
9946 return 0;
9947}
9948
9949
9950static void ath_sta_inject_frame(struct sigma_dut *dut, const char *intf,
9951 int tid)
9952{
9953 char buf[100];
9954 int tid_to_dscp [] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 };
9955
Pradeep Reddy POTTETId31d1322016-10-13 17:22:03 +05309956 if (tid < 0 ||
9957 tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) {
9958 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid);
9959 return;
9960 }
9961
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009962 /*
9963 * Two ways to ensure that addba request with a
9964 * non zero TID could be sent out. EV 117296
9965 */
9966 snprintf(buf, sizeof(buf),
9967 "ping -c 8 -Q %d `arp -a | grep wlan0 | awk '{print $2}' | tr -d '()'`",
9968 tid);
9969 if (system(buf) != 0) {
9970 sigma_dut_print(dut, DUT_MSG_ERROR,
9971 "Ping did not send out");
9972 }
9973
9974 snprintf(buf, sizeof(buf),
9975 "iwconfig %s | grep Access | awk '{print $6}' > %s",
9976 intf, VI_QOS_TMP_FILE);
9977 if (system(buf) != 0)
9978 return;
9979
9980 snprintf(buf, sizeof(buf),
9981 "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s",
9982 intf, VI_QOS_TMP_FILE);
9983 if (system(buf) != 0)
9984 sigma_dut_print(dut, DUT_MSG_ERROR, "HWaddr matching failed");
9985
9986 snprintf(buf,sizeof(buf), "sed -n '3,$p' %s >> %s",
9987 VI_QOS_REFFILE, VI_QOS_TMP_FILE);
9988 if (system(buf) != 0) {
9989 sigma_dut_print(dut, DUT_MSG_ERROR,
9990 "VI_QOS_TEMP_FILE generation error failed");
9991 }
9992 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
9993 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
9994 if (system(buf) != 0) {
9995 sigma_dut_print(dut, DUT_MSG_ERROR,
9996 "VI_QOS_FILE generation failed");
9997 }
9998
9999 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
10000 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
10001 if (system(buf) != 0) {
10002 sigma_dut_print(dut, DUT_MSG_ERROR,
10003 "VI_QOS_FILE generation failed");
10004 }
10005
10006 snprintf(buf, sizeof(buf), "ethinject %s %s", intf, VI_QOS_FILE);
10007 if (system(buf) != 0) {
10008 }
10009}
10010
10011
10012static int ath_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
10013 struct sigma_cmd *cmd)
10014{
10015 const char *intf = get_param(cmd, "Interface");
10016 const char *val;
10017 int tid = 0;
10018 char buf[100];
10019
10020 val = get_param(cmd, "TID");
10021 if (val) {
10022 tid = atoi(val);
10023 if (tid)
10024 ath_sta_inject_frame(dut, intf, tid);
10025 }
10026
10027 /* Command sequence for ADDBA request on Peregrine based devices */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010028 run_iwpriv(dut, intf, "setaddbaoper 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010029
10030 snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4", intf, tid);
10031 if (system(buf) != 0) {
10032 sigma_dut_print(dut, DUT_MSG_ERROR,
10033 "wifitool senddelba failed");
10034 }
10035
10036 snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64", intf, tid);
10037 if (system(buf) != 0) {
10038 sigma_dut_print(dut, DUT_MSG_ERROR,
10039 "wifitool sendaddba failed");
10040 }
10041
10042 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
10043
10044 return 1;
10045}
10046
10047
Lior David9981b512017-01-20 13:16:40 +020010048#ifdef __linux__
10049
10050static int wil6210_send_addba(struct sigma_dut *dut, const char *dest_mac,
10051 int agg_size)
10052{
10053 char dir[128], buf[128];
10054 FILE *f;
10055 regex_t re;
10056 regmatch_t m[2];
Jouni Malinen3aa72862019-05-29 23:14:51 +030010057 int rc, ret = -1, vring_id, found, res;
Lior David9981b512017-01-20 13:16:40 +020010058
10059 if (wil6210_get_debugfs_dir(dut, dir, sizeof(dir))) {
10060 sigma_dut_print(dut, DUT_MSG_ERROR,
10061 "failed to get wil6210 debugfs dir");
10062 return -1;
10063 }
10064
Jouni Malinen3aa72862019-05-29 23:14:51 +030010065 res = snprintf(buf, sizeof(buf), "%s/vrings", dir);
10066 if (res < 0 || res >= sizeof(buf))
10067 return -1;
Lior David9981b512017-01-20 13:16:40 +020010068 f = fopen(buf, "r");
10069 if (!f) {
10070 sigma_dut_print(dut, DUT_MSG_ERROR, "failed to open: %s", buf);
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +020010071 /* newer wil6210 driver renamed file to "rings" */
Jouni Malinen3aa72862019-05-29 23:14:51 +030010072 res = snprintf(buf, sizeof(buf), "%s/rings", dir);
10073 if (res < 0 || res >= sizeof(buf))
10074 return -1;
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +020010075 f = fopen(buf, "r");
10076 if (!f) {
10077 sigma_dut_print(dut, DUT_MSG_ERROR,
10078 "failed to open: %s", buf);
10079 return -1;
10080 }
Lior David9981b512017-01-20 13:16:40 +020010081 }
10082
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +020010083 /* can be either VRING tx... or RING... */
10084 if (regcomp(&re, "RING tx_[ \t]*([0-9]+)", REG_EXTENDED)) {
Lior David9981b512017-01-20 13:16:40 +020010085 sigma_dut_print(dut, DUT_MSG_ERROR, "regcomp failed");
10086 goto out;
10087 }
10088
10089 /* find TX VRING for the mac address */
10090 found = 0;
10091 while (fgets(buf, sizeof(buf), f)) {
10092 if (strcasestr(buf, dest_mac)) {
10093 found = 1;
10094 break;
10095 }
10096 }
10097
10098 if (!found) {
10099 sigma_dut_print(dut, DUT_MSG_ERROR,
10100 "no TX VRING for %s", dest_mac);
10101 goto out;
10102 }
10103
10104 /* extract VRING ID, "VRING tx_<id> = {" */
10105 if (!fgets(buf, sizeof(buf), f)) {
10106 sigma_dut_print(dut, DUT_MSG_ERROR,
10107 "no VRING start line for %s", dest_mac);
10108 goto out;
10109 }
10110
10111 rc = regexec(&re, buf, 2, m, 0);
10112 regfree(&re);
10113 if (rc || m[1].rm_so < 0) {
10114 sigma_dut_print(dut, DUT_MSG_ERROR,
10115 "no VRING TX ID for %s", dest_mac);
10116 goto out;
10117 }
10118 buf[m[1].rm_eo] = 0;
10119 vring_id = atoi(&buf[m[1].rm_so]);
10120
10121 /* send the addba command */
10122 fclose(f);
Jouni Malinen3aa72862019-05-29 23:14:51 +030010123 res = snprintf(buf, sizeof(buf), "%s/back", dir);
10124 if (res < 0 || res >= sizeof(buf))
10125 return -1;
Lior David9981b512017-01-20 13:16:40 +020010126 f = fopen(buf, "w");
10127 if (!f) {
10128 sigma_dut_print(dut, DUT_MSG_ERROR,
10129 "failed to open: %s", buf);
10130 return -1;
10131 }
10132
10133 fprintf(f, "add %d %d\n", vring_id, agg_size);
10134
10135 ret = 0;
10136
10137out:
10138 fclose(f);
10139
10140 return ret;
10141}
10142
10143
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +020010144int send_addba_60g(struct sigma_dut *dut, struct sigma_conn *conn,
10145 struct sigma_cmd *cmd, const char *mac_param)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010146{
10147 const char *val;
10148 int tid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010149
10150 val = get_param(cmd, "TID");
10151 if (val) {
10152 tid = atoi(val);
10153 if (tid != 0) {
10154 sigma_dut_print(dut, DUT_MSG_ERROR,
10155 "Ignore TID %d for send_addba use TID 0 for 60g since only 0 required on TX",
10156 tid);
10157 }
10158 }
10159
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +020010160 val = get_param(cmd, mac_param);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010161 if (!val) {
10162 sigma_dut_print(dut, DUT_MSG_ERROR,
10163 "Currently not supporting addba for 60G without Dest_mac");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020010164 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010165 }
10166
Lior David9981b512017-01-20 13:16:40 +020010167 if (wil6210_send_addba(dut, val, dut->back_rcv_buf))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010168 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010169
10170 return 1;
10171}
10172
Lior David9981b512017-01-20 13:16:40 +020010173#endif /* __linux__ */
10174
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010175
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080010176static int wcn_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
10177 struct sigma_cmd *cmd)
10178{
10179#ifdef NL80211_SUPPORT
10180 const char *intf = get_param(cmd, "Interface");
10181 const char *val;
10182 int tid = -1;
10183 int bufsize = 64;
10184 struct nl_msg *msg;
10185 int ret = 0;
10186 struct nlattr *params;
10187 int ifindex;
10188
10189 val = get_param(cmd, "TID");
10190 if (val)
10191 tid = atoi(val);
10192
10193 if (tid == -1) {
10194 send_resp(dut, conn, SIGMA_ERROR,
10195 "ErrorCode,sta_send_addba tid invalid");
10196 return 0;
10197 }
10198
10199 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
10200
10201 ifindex = if_nametoindex(intf);
10202 if (ifindex == 0) {
10203 sigma_dut_print(dut, DUT_MSG_ERROR,
10204 "%s: Index for interface %s failed",
10205 __func__, intf);
10206 send_resp(dut, conn, SIGMA_ERROR,
10207 "ErrorCode,sta_send_addba interface invalid");
10208 return 0;
10209 }
10210
10211 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
10212 NL80211_CMD_VENDOR)) ||
10213 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
10214 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
10215 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
10216 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
10217 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
10218 nla_put_u8(msg,
10219 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADD_DEL_BA_SESSION,
10220 QCA_WLAN_ADD_BA) ||
10221 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BA_TID,
10222 tid) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -070010223 nla_put_u16(msg,
10224 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
10225 bufsize)) {
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080010226 sigma_dut_print(dut, DUT_MSG_ERROR,
10227 "%s: err in adding vendor_cmd and vendor_data",
10228 __func__);
10229 nlmsg_free(msg);
10230 send_resp(dut, conn, SIGMA_ERROR,
10231 "ErrorCode,sta_send_addba err in adding vendor_cmd and vendor_data");
10232 return 0;
10233 }
10234 nla_nest_end(msg, params);
10235
10236 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
10237 if (ret) {
10238 sigma_dut_print(dut, DUT_MSG_ERROR,
10239 "%s: err in send_and_recv_msgs, ret=%d",
10240 __func__, ret);
Sunil Dutt30605592018-05-04 20:35:50 +053010241 if (ret == -EOPNOTSUPP)
10242 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080010243 send_resp(dut, conn, SIGMA_ERROR,
10244 "ErrorCode,sta_send_addba err in send_and_recv_msgs");
10245 return 0;
10246 }
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080010247#else /* NL80211_SUPPORT */
10248 sigma_dut_print(dut, DUT_MSG_ERROR,
10249 "sta_send_addba not supported without NL80211_SUPPORT defined");
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080010250#endif /* NL80211_SUPPORT */
Sunil Dutt30605592018-05-04 20:35:50 +053010251
10252 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080010253}
10254
10255
Jouni Malinenf7222712019-06-13 01:50:21 +030010256static enum sigma_cmd_result cmd_sta_send_addba(struct sigma_dut *dut,
10257 struct sigma_conn *conn,
10258 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010259{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010260 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010261 case DRIVER_ATHEROS:
10262 return ath_sta_send_addba(dut, conn, cmd);
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080010263 case DRIVER_WCN:
10264 return wcn_sta_send_addba(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +020010265#ifdef __linux__
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010266 case DRIVER_WIL6210:
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +020010267 return send_addba_60g(dut, conn, cmd, "Dest_mac");
Lior David9981b512017-01-20 13:16:40 +020010268#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010269 default:
10270 /*
10271 * There is no driver specific implementation for other drivers.
10272 * Ignore the command and report COMPLETE since the following
10273 * throughput test operation will end up sending ADDBA anyway.
10274 */
10275 return 1;
10276 }
10277}
10278
10279
10280int inject_eth_frame(int s, const void *data, size_t len,
10281 unsigned short ethtype, char *dst, char *src)
10282{
10283 struct iovec iov[4] = {
10284 {
10285 .iov_base = dst,
10286 .iov_len = ETH_ALEN,
10287 },
10288 {
10289 .iov_base = src,
10290 .iov_len = ETH_ALEN,
10291 },
10292 {
10293 .iov_base = &ethtype,
10294 .iov_len = sizeof(unsigned short),
10295 },
10296 {
10297 .iov_base = (void *) data,
10298 .iov_len = len,
10299 }
10300 };
10301 struct msghdr msg = {
10302 .msg_name = NULL,
10303 .msg_namelen = 0,
10304 .msg_iov = iov,
10305 .msg_iovlen = 4,
10306 .msg_control = NULL,
10307 .msg_controllen = 0,
10308 .msg_flags = 0,
10309 };
10310
10311 return sendmsg(s, &msg, 0);
10312}
10313
10314#if defined(__linux__) || defined(__QNXNTO__)
10315
10316int inject_frame(int s, const void *data, size_t len, int encrypt)
10317{
10318#define IEEE80211_RADIOTAP_F_WEP 0x04
10319#define IEEE80211_RADIOTAP_F_FRAG 0x08
10320 unsigned char rtap_hdr[] = {
10321 0x00, 0x00, /* radiotap version */
10322 0x0e, 0x00, /* radiotap length */
10323 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
10324 IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */
10325 0x00, /* padding */
10326 0x00, 0x00, /* RX and TX flags to indicate that */
10327 0x00, 0x00, /* this is the injected frame directly */
10328 };
10329 struct iovec iov[2] = {
10330 {
10331 .iov_base = &rtap_hdr,
10332 .iov_len = sizeof(rtap_hdr),
10333 },
10334 {
10335 .iov_base = (void *) data,
10336 .iov_len = len,
10337 }
10338 };
10339 struct msghdr msg = {
10340 .msg_name = NULL,
10341 .msg_namelen = 0,
10342 .msg_iov = iov,
10343 .msg_iovlen = 2,
10344 .msg_control = NULL,
10345 .msg_controllen = 0,
10346 .msg_flags = 0,
10347 };
10348
10349 if (encrypt)
10350 rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP;
10351
10352 return sendmsg(s, &msg, 0);
10353}
10354
10355
10356int open_monitor(const char *ifname)
10357{
10358#ifdef __QNXNTO__
10359 struct sockaddr_dl ll;
10360 int s;
10361
10362 memset(&ll, 0, sizeof(ll));
10363 ll.sdl_family = AF_LINK;
10364 ll.sdl_index = if_nametoindex(ifname);
10365 if (ll.sdl_index == 0) {
10366 perror("if_nametoindex");
10367 return -1;
10368 }
10369 s = socket(PF_INET, SOCK_RAW, 0);
10370#else /* __QNXNTO__ */
10371 struct sockaddr_ll ll;
10372 int s;
10373
10374 memset(&ll, 0, sizeof(ll));
10375 ll.sll_family = AF_PACKET;
10376 ll.sll_ifindex = if_nametoindex(ifname);
10377 if (ll.sll_ifindex == 0) {
10378 perror("if_nametoindex");
10379 return -1;
10380 }
10381 s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
10382#endif /* __QNXNTO__ */
10383 if (s < 0) {
10384 perror("socket[PF_PACKET,SOCK_RAW]");
10385 return -1;
10386 }
10387
10388 if (bind(s, (struct sockaddr *) &ll, sizeof(ll)) < 0) {
10389 perror("monitor socket bind");
10390 close(s);
10391 return -1;
10392 }
10393
10394 return s;
10395}
10396
10397
10398static int hex2num(char c)
10399{
10400 if (c >= '0' && c <= '9')
10401 return c - '0';
10402 if (c >= 'a' && c <= 'f')
10403 return c - 'a' + 10;
10404 if (c >= 'A' && c <= 'F')
10405 return c - 'A' + 10;
10406 return -1;
10407}
10408
10409
10410int hwaddr_aton(const char *txt, unsigned char *addr)
10411{
10412 int i;
10413
10414 for (i = 0; i < 6; i++) {
10415 int a, b;
10416
10417 a = hex2num(*txt++);
10418 if (a < 0)
10419 return -1;
10420 b = hex2num(*txt++);
10421 if (b < 0)
10422 return -1;
10423 *addr++ = (a << 4) | b;
10424 if (i < 5 && *txt++ != ':')
10425 return -1;
10426 }
10427
10428 return 0;
10429}
10430
10431#endif /* defined(__linux__) || defined(__QNXNTO__) */
10432
Veerendranath Jakkam49774122020-07-05 09:52:18 +053010433
10434#ifdef NL80211_SUPPORT
10435static int nl80211_send_frame_cmd(struct sigma_dut *dut, const char *intf,
10436 const u8 *data, size_t data_len, int freq)
10437{
10438 struct nl_msg *msg;
10439 int ret = 0;
10440 int ifindex;
10441
10442 ifindex = if_nametoindex(intf);
10443 if (ifindex == 0) {
10444 sigma_dut_print(dut, DUT_MSG_ERROR,
10445 "%s: Index for interface %s failed",
10446 __func__, intf);
10447 return -1;
10448 }
10449
10450 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
10451 NL80211_CMD_FRAME)) ||
10452 (freq && nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
10453 nla_put(msg, NL80211_ATTR_FRAME, data_len, data)) {
10454 sigma_dut_print(dut, DUT_MSG_ERROR,
10455 "%s: Error in adding NL80211_CMD_FRAME",
10456 __func__);
10457 nlmsg_free(msg);
10458 return -1;
10459 }
10460
10461 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
10462 if (ret) {
10463 sigma_dut_print(dut, DUT_MSG_ERROR,
10464 "nl80211: Frame command failed: ret=%d (%s) req=%u",
10465 ret, strerror(-ret), freq);
10466 return -1;
10467 }
10468
10469 return 0;
10470}
10471#endif /* NL80211_SUPPORT */
10472
10473
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010474enum send_frame_type {
10475 DISASSOC, DEAUTH, SAQUERY, AUTH, ASSOCREQ, REASSOCREQ, DLS_REQ
10476};
10477enum send_frame_protection {
10478 CORRECT_KEY, INCORRECT_KEY, UNPROTECTED
10479};
10480
10481
10482static int sta_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn,
Veerendranath Jakkam49774122020-07-05 09:52:18 +053010483 const char *intf, enum send_frame_type frame,
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010484 enum send_frame_protection protected,
Veerendranath Jakkam49774122020-07-05 09:52:18 +053010485 const char *dest, int use_monitor)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010486{
10487#ifdef __linux__
10488 unsigned char buf[1000], *pos;
10489 int s, res;
10490 char bssid[20], addr[20];
10491 char result[32], ssid[100];
10492 size_t ssid_len;
10493
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010494 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010495 sizeof(result)) < 0 ||
10496 strncmp(result, "COMPLETED", 9) != 0) {
10497 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Not connected");
10498 return 0;
10499 }
10500
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010501 if (get_wpa_status(get_station_ifname(dut), "bssid",
10502 bssid, sizeof(bssid)) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010503 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
10504 "current BSSID");
10505 return 0;
10506 }
10507
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010508 if (get_wpa_status(get_station_ifname(dut), "address",
10509 addr, sizeof(addr)) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010510 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
10511 "own MAC address");
10512 return 0;
10513 }
10514
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010515 if (get_wpa_status(get_station_ifname(dut), "ssid", ssid, sizeof(ssid))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010516 < 0) {
10517 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
10518 "current SSID");
10519 return 0;
10520 }
10521 ssid_len = strlen(ssid);
10522
10523 pos = buf;
10524
10525 /* Frame Control */
10526 switch (frame) {
10527 case DISASSOC:
10528 *pos++ = 0xa0;
10529 break;
10530 case DEAUTH:
10531 *pos++ = 0xc0;
10532 break;
10533 case SAQUERY:
10534 *pos++ = 0xd0;
10535 break;
10536 case AUTH:
10537 *pos++ = 0xb0;
10538 break;
10539 case ASSOCREQ:
10540 *pos++ = 0x00;
10541 break;
10542 case REASSOCREQ:
10543 *pos++ = 0x20;
10544 break;
10545 case DLS_REQ:
10546 *pos++ = 0xd0;
10547 break;
10548 }
10549
10550 if (protected == INCORRECT_KEY)
10551 *pos++ = 0x40; /* Set Protected field to 1 */
10552 else
10553 *pos++ = 0x00;
10554
10555 /* Duration */
10556 *pos++ = 0x00;
10557 *pos++ = 0x00;
10558
10559 /* addr1 = DA (current AP) */
10560 hwaddr_aton(bssid, pos);
10561 pos += 6;
10562 /* addr2 = SA (own address) */
10563 hwaddr_aton(addr, pos);
10564 pos += 6;
10565 /* addr3 = BSSID (current AP) */
10566 hwaddr_aton(bssid, pos);
10567 pos += 6;
10568
10569 /* Seq# (to be filled by driver/mac80211) */
10570 *pos++ = 0x00;
10571 *pos++ = 0x00;
10572
10573 if (protected == INCORRECT_KEY) {
10574 /* CCMP parameters */
10575 memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8);
10576 pos += 8;
10577 }
10578
10579 if (protected == INCORRECT_KEY) {
10580 switch (frame) {
10581 case DEAUTH:
10582 /* Reason code (encrypted) */
10583 memcpy(pos, "\xa7\x39", 2);
10584 pos += 2;
10585 break;
10586 case DISASSOC:
10587 /* Reason code (encrypted) */
10588 memcpy(pos, "\xa7\x39", 2);
10589 pos += 2;
10590 break;
10591 case SAQUERY:
10592 /* Category|Action|TransID (encrypted) */
10593 memcpy(pos, "\x6f\xbd\xe9\x4d", 4);
10594 pos += 4;
10595 break;
10596 default:
10597 return -1;
10598 }
10599
10600 /* CCMP MIC */
10601 memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8);
10602 pos += 8;
10603 } else {
10604 switch (frame) {
10605 case DEAUTH:
10606 /* reason code = 8 */
10607 *pos++ = 0x08;
10608 *pos++ = 0x00;
10609 break;
10610 case DISASSOC:
10611 /* reason code = 8 */
10612 *pos++ = 0x08;
10613 *pos++ = 0x00;
10614 break;
10615 case SAQUERY:
10616 /* Category - SA Query */
10617 *pos++ = 0x08;
10618 /* SA query Action - Request */
10619 *pos++ = 0x00;
10620 /* Transaction ID */
10621 *pos++ = 0x12;
10622 *pos++ = 0x34;
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053010623 if (dut->saquery_oci_freq) {
10624 /* OCI IE - Extended ID */
10625 *pos++ = 0xFF;
10626 *pos++ = 0x04;
10627 *pos++ = 0x36;
10628 /* Operating Class */
10629 *pos++ = 0x74;
10630 /* Primary Channel */
10631 *pos++ = freq_to_channel(dut->saquery_oci_freq);
10632 /* Frequency Segment 1 Channel Number */
10633 *pos++ = 0x00;
10634 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010635 break;
10636 case AUTH:
10637 /* Auth Alg (Open) */
10638 *pos++ = 0x00;
10639 *pos++ = 0x00;
10640 /* Seq# */
10641 *pos++ = 0x01;
10642 *pos++ = 0x00;
10643 /* Status code */
10644 *pos++ = 0x00;
10645 *pos++ = 0x00;
10646 break;
10647 case ASSOCREQ:
10648 /* Capability Information */
10649 *pos++ = 0x31;
10650 *pos++ = 0x04;
10651 /* Listen Interval */
10652 *pos++ = 0x0a;
10653 *pos++ = 0x00;
10654 /* SSID */
10655 *pos++ = 0x00;
10656 *pos++ = ssid_len;
10657 memcpy(pos, ssid, ssid_len);
10658 pos += ssid_len;
10659 /* Supported Rates */
10660 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
10661 10);
10662 pos += 10;
10663 /* Extended Supported Rates */
10664 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
10665 pos += 6;
10666 /* RSN */
10667 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
10668 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
10669 "\x00\x00\x00\x00\x0f\xac\x06", 28);
10670 pos += 28;
10671 break;
10672 case REASSOCREQ:
10673 /* Capability Information */
10674 *pos++ = 0x31;
10675 *pos++ = 0x04;
10676 /* Listen Interval */
10677 *pos++ = 0x0a;
10678 *pos++ = 0x00;
10679 /* Current AP */
10680 hwaddr_aton(bssid, pos);
10681 pos += 6;
10682 /* SSID */
10683 *pos++ = 0x00;
10684 *pos++ = ssid_len;
10685 memcpy(pos, ssid, ssid_len);
10686 pos += ssid_len;
10687 /* Supported Rates */
10688 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
10689 10);
10690 pos += 10;
10691 /* Extended Supported Rates */
10692 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
10693 pos += 6;
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053010694 /* RSNE - Group and Pairwise ciphers */
10695 memcpy(pos,
10696 "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x04",
10697 14);
10698 pos += 14;
10699 /* RSNE - AKM Suite count */
10700 *pos++ = 0x01;
10701 *pos++ = 0x00;
10702 /* RSNE - AKM Suites */
10703 if (dut->program == PROGRAM_WPA3)
10704 memcpy(pos, "\x00\x0f\xac\x08", 4);
10705 else
10706 memcpy(pos, "\x00\x0f\xac\x02", 4);
10707 pos += 4;
10708 /* RSNE - Capabilities */
10709 *pos++ = 0xc0;
10710 if (dut->ocvc)
10711 *pos++ = 0x40;
10712 else
10713 *pos++ = 0x00;
10714 /* RSNE - PMKID list and Group Management Ciphers */
10715 memcpy(pos, "\x00\x00\x00\x0f\xac\x06", 6);
10716 pos += 6;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010717 break;
10718 case DLS_REQ:
10719 /* Category - DLS */
10720 *pos++ = 0x02;
10721 /* DLS Action - Request */
10722 *pos++ = 0x00;
10723 /* Destination MACAddress */
10724 if (dest)
10725 hwaddr_aton(dest, pos);
10726 else
10727 memset(pos, 0, 6);
10728 pos += 6;
10729 /* Source MACAddress */
10730 hwaddr_aton(addr, pos);
10731 pos += 6;
10732 /* Capability Information */
10733 *pos++ = 0x10; /* Privacy */
10734 *pos++ = 0x06; /* QoS */
10735 /* DLS Timeout Value */
10736 *pos++ = 0x00;
10737 *pos++ = 0x01;
10738 /* Supported rates */
10739 *pos++ = 0x01;
10740 *pos++ = 0x08;
10741 *pos++ = 0x0c; /* 6 Mbps */
10742 *pos++ = 0x12; /* 9 Mbps */
10743 *pos++ = 0x18; /* 12 Mbps */
10744 *pos++ = 0x24; /* 18 Mbps */
10745 *pos++ = 0x30; /* 24 Mbps */
10746 *pos++ = 0x48; /* 36 Mbps */
10747 *pos++ = 0x60; /* 48 Mbps */
10748 *pos++ = 0x6c; /* 54 Mbps */
10749 /* TODO: Extended Supported Rates */
10750 /* TODO: HT Capabilities */
10751 break;
10752 }
10753 }
10754
Veerendranath Jakkam49774122020-07-05 09:52:18 +053010755 if (use_monitor) {
10756 s = open_monitor("sigmadut");
10757 if (s < 0) {
10758 send_resp(dut, conn, SIGMA_ERROR,
10759 "errorCode,Failed to open monitor socket");
10760 return 0;
10761 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010762
Veerendranath Jakkam49774122020-07-05 09:52:18 +053010763 res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY);
10764 if (res < 0) {
10765 send_resp(dut, conn, SIGMA_ERROR,
10766 "errorCode,Failed to inject frame");
10767 close(s);
10768 return 0;
10769 }
10770 if (res < pos - buf) {
10771 send_resp(dut, conn, SIGMA_ERROR,
10772 "errorCode,Only partial frame sent");
10773 close(s);
10774 return 0;
10775 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010776
Veerendranath Jakkam49774122020-07-05 09:52:18 +053010777 close(s);
10778 } else {
10779#ifdef NL80211_SUPPORT
10780 int freq;
10781 char freq_str[10];
10782
10783 if (get_wpa_status(get_station_ifname(dut), "freq",
10784 freq_str, sizeof(freq_str)) < 0) {
10785 send_resp(dut, conn, SIGMA_ERROR,
10786 "errorCode,Could not get current operating frequency");
10787 return 0;
10788 }
10789 freq = atoi(freq_str);
10790
10791 if (nl80211_send_frame_cmd(dut, intf, buf, pos - buf, freq)) {
10792 send_resp(dut, conn, SIGMA_ERROR,
10793 "errorCode,Failed to inject frame");
10794 return 0;
10795 }
10796#else /* NL80211_SUPPORT */
10797 send_resp(dut, conn, SIGMA_ERROR,
10798 "errorCode,Failed to inject frame (no NL80211_SUPPORT)");
10799 return 0;
10800#endif /* NL80211_SUPPORT */
10801 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010802
10803 return 1;
10804#else /* __linux__ */
10805 send_resp(dut, conn, SIGMA_ERROR, "errorCode,sta_send_frame not "
10806 "yet supported");
10807 return 0;
10808#endif /* __linux__ */
10809}
10810
10811
10812static int cmd_sta_send_frame_tdls(struct sigma_dut *dut,
10813 struct sigma_conn *conn,
10814 struct sigma_cmd *cmd)
10815{
10816 const char *intf = get_param(cmd, "Interface");
10817 const char *sta, *val;
10818 unsigned char addr[ETH_ALEN];
10819 char buf[100];
10820
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030010821 if (!intf)
10822 return -1;
10823
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010824 sta = get_param(cmd, "peer");
10825 if (sta == NULL)
10826 sta = get_param(cmd, "station");
10827 if (sta == NULL) {
10828 send_resp(dut, conn, SIGMA_ERROR,
10829 "ErrorCode,Missing peer address");
10830 return 0;
10831 }
10832 if (hwaddr_aton(sta, addr) < 0) {
10833 send_resp(dut, conn, SIGMA_ERROR,
10834 "ErrorCode,Invalid peer address");
10835 return 0;
10836 }
10837
10838 val = get_param(cmd, "type");
10839 if (val == NULL)
10840 return -1;
10841
10842 if (strcasecmp(val, "DISCOVERY") == 0) {
10843 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", sta);
10844 if (wpa_command(intf, buf) < 0) {
10845 send_resp(dut, conn, SIGMA_ERROR,
10846 "ErrorCode,Failed to send TDLS discovery");
10847 return 0;
10848 }
10849 return 1;
10850 }
10851
10852 if (strcasecmp(val, "SETUP") == 0) {
10853 int status = 0, timeout = 0;
10854
10855 val = get_param(cmd, "Status");
10856 if (val)
10857 status = atoi(val);
10858
10859 val = get_param(cmd, "Timeout");
10860 if (val)
10861 timeout = atoi(val);
10862
10863 if (status != 0 && status != 37) {
10864 send_resp(dut, conn, SIGMA_ERROR,
10865 "ErrorCode,Unsupported status value");
10866 return 0;
10867 }
10868
10869 if (timeout != 0 && timeout != 301) {
10870 send_resp(dut, conn, SIGMA_ERROR,
10871 "ErrorCode,Unsupported timeout value");
10872 return 0;
10873 }
10874
10875 if (status && timeout) {
10876 send_resp(dut, conn, SIGMA_ERROR,
10877 "ErrorCode,Unsupported timeout+status "
10878 "combination");
10879 return 0;
10880 }
10881
10882 if (status == 37 &&
10883 wpa_command(intf, "SET tdls_testing 0x200")) {
10884 send_resp(dut, conn, SIGMA_ERROR,
10885 "ErrorCode,Failed to enable "
10886 "decline setup response test mode");
10887 return 0;
10888 }
10889
10890 if (timeout == 301) {
10891 int res;
10892 if (dut->no_tpk_expiration)
10893 res = wpa_command(intf,
10894 "SET tdls_testing 0x108");
10895 else
10896 res = wpa_command(intf,
10897 "SET tdls_testing 0x8");
10898 if (res) {
10899 send_resp(dut, conn, SIGMA_ERROR,
10900 "ErrorCode,Failed to set short TPK "
10901 "lifetime");
10902 return 0;
10903 }
10904 }
10905
10906 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", sta);
10907 if (wpa_command(intf, buf) < 0) {
10908 send_resp(dut, conn, SIGMA_ERROR,
10909 "ErrorCode,Failed to send TDLS setup");
10910 return 0;
10911 }
10912 return 1;
10913 }
10914
10915 if (strcasecmp(val, "TEARDOWN") == 0) {
10916 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", sta);
10917 if (wpa_command(intf, buf) < 0) {
10918 send_resp(dut, conn, SIGMA_ERROR,
10919 "ErrorCode,Failed to send TDLS teardown");
10920 return 0;
10921 }
10922 return 1;
10923 }
10924
10925 send_resp(dut, conn, SIGMA_ERROR,
10926 "ErrorCode,Unsupported TDLS frame");
10927 return 0;
10928}
10929
10930
10931static int sta_ap_known(const char *ifname, const char *bssid)
10932{
10933 char buf[4096];
10934
Jouni Malinendd32f192018-09-15 02:55:19 +030010935 snprintf(buf, sizeof(buf), "BSS MASK=1 %s", bssid);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010936 if (wpa_command_resp(ifname, buf, buf, sizeof(buf)) < 0)
10937 return 0;
10938 if (strncmp(buf, "id=", 3) != 0)
10939 return 0;
10940 return 1;
10941}
10942
10943
10944static int sta_scan_ap(struct sigma_dut *dut, const char *ifname,
10945 const char *bssid)
10946{
10947 int res;
10948 struct wpa_ctrl *ctrl;
10949 char buf[256];
10950
10951 if (sta_ap_known(ifname, bssid))
10952 return 0;
10953 sigma_dut_print(dut, DUT_MSG_DEBUG,
10954 "AP not in BSS table - start scan");
10955
10956 ctrl = open_wpa_mon(ifname);
10957 if (ctrl == NULL) {
10958 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
10959 "wpa_supplicant monitor connection");
10960 return -1;
10961 }
10962
10963 if (wpa_command(ifname, "SCAN") < 0) {
10964 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to start scan");
10965 wpa_ctrl_detach(ctrl);
10966 wpa_ctrl_close(ctrl);
10967 return -1;
10968 }
10969
10970 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
10971 buf, sizeof(buf));
10972
10973 wpa_ctrl_detach(ctrl);
10974 wpa_ctrl_close(ctrl);
10975
10976 if (res < 0) {
10977 sigma_dut_print(dut, DUT_MSG_INFO, "Scan did not complete");
10978 return -1;
10979 }
10980
10981 if (sta_ap_known(ifname, bssid))
10982 return 0;
10983 sigma_dut_print(dut, DUT_MSG_INFO, "AP not in BSS table");
10984 return -1;
10985}
10986
10987
10988static int cmd_sta_send_frame_hs2_neighadv(struct sigma_dut *dut,
10989 struct sigma_conn *conn,
10990 struct sigma_cmd *cmd,
10991 const char *intf)
10992{
10993 char buf[200];
10994
10995 snprintf(buf, sizeof(buf), "ndsend 2001:DB8::1 %s", intf);
10996 if (system(buf) != 0) {
10997 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Failed to run "
10998 "ndsend");
10999 return 0;
11000 }
11001
11002 return 1;
11003}
11004
11005
11006static int cmd_sta_send_frame_hs2_neighsolreq(struct sigma_dut *dut,
11007 struct sigma_conn *conn,
11008 struct sigma_cmd *cmd,
11009 const char *intf)
11010{
11011 char buf[200];
11012 const char *ip = get_param(cmd, "SenderIP");
11013
Peng Xu26b356d2017-10-04 17:58:16 -070011014 if (!ip)
11015 return 0;
11016
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011017 snprintf(buf, sizeof(buf), "ndisc6 -nm %s %s -r 4", ip, intf);
11018 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11019 if (system(buf) == 0) {
11020 sigma_dut_print(dut, DUT_MSG_INFO,
11021 "Neighbor Solicitation got a response "
11022 "for %s@%s", ip, intf);
11023 }
11024
11025 return 1;
11026}
11027
11028
11029static int cmd_sta_send_frame_hs2_arpprobe(struct sigma_dut *dut,
11030 struct sigma_conn *conn,
11031 struct sigma_cmd *cmd,
11032 const char *ifname)
11033{
11034 char buf[200];
11035 const char *ip = get_param(cmd, "SenderIP");
11036
11037 if (ip == NULL) {
11038 send_resp(dut, conn, SIGMA_ERROR,
11039 "ErrorCode,Missing SenderIP parameter");
11040 return 0;
11041 }
11042 snprintf(buf, sizeof(buf), "arping -I %s -D %s -c 4", ifname, ip);
11043 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11044 if (system(buf) != 0) {
11045 sigma_dut_print(dut, DUT_MSG_INFO, "arping DAD got a response "
11046 "for %s@%s", ip, ifname);
11047 }
11048
11049 return 1;
11050}
11051
11052
11053static int cmd_sta_send_frame_hs2_arpannounce(struct sigma_dut *dut,
11054 struct sigma_conn *conn,
11055 struct sigma_cmd *cmd,
11056 const char *ifname)
11057{
11058 char buf[200];
11059 char ip[16];
11060 int s;
Peng Xub3756882017-10-04 14:39:09 -070011061 struct ifreq ifr;
11062 struct sockaddr_in saddr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011063
11064 s = socket(PF_INET, SOCK_DGRAM, 0);
Peng Xub3756882017-10-04 14:39:09 -070011065 if (s < 0) {
11066 perror("socket");
11067 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011068 }
11069
Peng Xub3756882017-10-04 14:39:09 -070011070 memset(&ifr, 0, sizeof(ifr));
11071 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
11072 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
11073 sigma_dut_print(dut, DUT_MSG_INFO,
11074 "Failed to get %s IP address: %s",
11075 ifname, strerror(errno));
11076 close(s);
11077 return -1;
11078 }
11079 close(s);
11080
11081 memcpy(&saddr, &ifr.ifr_addr, sizeof(struct sockaddr_in));
11082 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
11083
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011084 snprintf(buf, sizeof(buf), "arping -I %s -s %s %s -c 4", ifname, ip,
11085 ip);
11086 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11087 if (system(buf) != 0) {
11088 }
11089
11090 return 1;
11091}
11092
11093
11094static int cmd_sta_send_frame_hs2_arpreply(struct sigma_dut *dut,
11095 struct sigma_conn *conn,
11096 struct sigma_cmd *cmd,
11097 const char *ifname)
11098{
11099 char buf[200], addr[20];
11100 char dst[ETH_ALEN], src[ETH_ALEN];
11101 short ethtype = htons(ETH_P_ARP);
11102 char *pos;
11103 int s, res;
11104 const char *val;
11105 struct sockaddr_in taddr;
11106
11107 val = get_param(cmd, "dest");
11108 if (val)
11109 hwaddr_aton(val, (unsigned char *) dst);
11110
11111 val = get_param(cmd, "DestIP");
11112 if (val)
11113 inet_aton(val, &taddr.sin_addr);
Peng Xu151c9e12017-10-04 14:39:09 -070011114 else
11115 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011116
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011117 if (get_wpa_status(get_station_ifname(dut), "address", addr,
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011118 sizeof(addr)) < 0)
11119 return -2;
11120 hwaddr_aton(addr, (unsigned char *) src);
11121
11122 pos = buf;
11123 *pos++ = 0x00;
11124 *pos++ = 0x01;
11125 *pos++ = 0x08;
11126 *pos++ = 0x00;
11127 *pos++ = 0x06;
11128 *pos++ = 0x04;
11129 *pos++ = 0x00;
11130 *pos++ = 0x02;
11131 memcpy(pos, src, ETH_ALEN);
11132 pos += ETH_ALEN;
11133 memcpy(pos, &taddr.sin_addr, 4);
11134 pos += 4;
11135 memcpy(pos, dst, ETH_ALEN);
11136 pos += ETH_ALEN;
11137 memcpy(pos, &taddr.sin_addr, 4);
11138 pos += 4;
11139
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011140 s = open_monitor(get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011141 if (s < 0) {
11142 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
11143 "monitor socket");
11144 return 0;
11145 }
11146
11147 res = inject_eth_frame(s, buf, pos - buf, ethtype, dst, src);
11148 if (res < 0) {
11149 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
11150 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +053011151 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011152 return 0;
11153 }
11154
11155 close(s);
11156
11157 return 1;
11158}
11159
11160
11161static int cmd_sta_send_frame_hs2_dls_req(struct sigma_dut *dut,
11162 struct sigma_conn *conn,
11163 struct sigma_cmd *cmd,
11164 const char *intf, const char *dest)
11165{
11166 char buf[100];
11167
11168 if (if_nametoindex("sigmadut") == 0) {
11169 snprintf(buf, sizeof(buf),
11170 "iw dev %s interface add sigmadut type monitor",
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011171 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011172 if (system(buf) != 0 ||
11173 if_nametoindex("sigmadut") == 0) {
11174 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
11175 "monitor interface with '%s'", buf);
11176 return -2;
11177 }
11178 }
11179
11180 if (system("ifconfig sigmadut up") != 0) {
11181 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
11182 "monitor interface up");
11183 return -2;
11184 }
11185
Veerendranath Jakkam49774122020-07-05 09:52:18 +053011186 return sta_inject_frame(dut, conn, intf, DLS_REQ, UNPROTECTED, dest, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011187}
11188
11189
11190static int cmd_sta_send_frame_hs2(struct sigma_dut *dut,
11191 struct sigma_conn *conn,
11192 struct sigma_cmd *cmd)
11193{
11194 const char *intf = get_param(cmd, "Interface");
11195 const char *dest = get_param(cmd, "Dest");
11196 const char *type = get_param(cmd, "FrameName");
11197 const char *val;
11198 char buf[200], *pos, *end;
11199 int count, count2;
11200
11201 if (type == NULL)
11202 type = get_param(cmd, "Type");
11203
11204 if (intf == NULL || dest == NULL || type == NULL)
11205 return -1;
11206
11207 if (strcasecmp(type, "NeighAdv") == 0)
11208 return cmd_sta_send_frame_hs2_neighadv(dut, conn, cmd, intf);
11209
11210 if (strcasecmp(type, "NeighSolicitReq") == 0)
11211 return cmd_sta_send_frame_hs2_neighsolreq(dut, conn, cmd, intf);
11212
11213 if (strcasecmp(type, "ARPProbe") == 0)
11214 return cmd_sta_send_frame_hs2_arpprobe(dut, conn, cmd, intf);
11215
11216 if (strcasecmp(type, "ARPAnnounce") == 0)
11217 return cmd_sta_send_frame_hs2_arpannounce(dut, conn, cmd, intf);
11218
11219 if (strcasecmp(type, "ARPReply") == 0)
11220 return cmd_sta_send_frame_hs2_arpreply(dut, conn, cmd, intf);
11221
11222 if (strcasecmp(type, "DLS-request") == 0 ||
11223 strcasecmp(type, "DLSrequest") == 0)
11224 return cmd_sta_send_frame_hs2_dls_req(dut, conn, cmd, intf,
11225 dest);
11226
11227 if (strcasecmp(type, "ANQPQuery") != 0 &&
11228 strcasecmp(type, "Query") != 0) {
11229 send_resp(dut, conn, SIGMA_ERROR,
11230 "ErrorCode,Unsupported HS 2.0 send frame type");
11231 return 0;
11232 }
11233
11234 if (sta_scan_ap(dut, intf, dest) < 0) {
11235 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not find "
11236 "the requested AP");
11237 return 0;
11238 }
11239
11240 pos = buf;
11241 end = buf + sizeof(buf);
11242 count = 0;
11243 pos += snprintf(pos, end - pos, "ANQP_GET %s ", dest);
11244
11245 val = get_param(cmd, "ANQP_CAP_LIST");
11246 if (val && atoi(val)) {
11247 pos += snprintf(pos, end - pos, "%s257", count > 0 ? "," : "");
11248 count++;
11249 }
11250
11251 val = get_param(cmd, "VENUE_NAME");
11252 if (val && atoi(val)) {
11253 pos += snprintf(pos, end - pos, "%s258", count > 0 ? "," : "");
11254 count++;
11255 }
11256
11257 val = get_param(cmd, "NETWORK_AUTH_TYPE");
11258 if (val && atoi(val)) {
11259 pos += snprintf(pos, end - pos, "%s260", count > 0 ? "," : "");
11260 count++;
11261 }
11262
11263 val = get_param(cmd, "ROAMING_CONS");
11264 if (val && atoi(val)) {
11265 pos += snprintf(pos, end - pos, "%s261", count > 0 ? "," : "");
11266 count++;
11267 }
11268
11269 val = get_param(cmd, "IP_ADDR_TYPE_AVAILABILITY");
11270 if (val && atoi(val)) {
11271 pos += snprintf(pos, end - pos, "%s262", count > 0 ? "," : "");
11272 count++;
11273 }
11274
11275 val = get_param(cmd, "NAI_REALM_LIST");
11276 if (val && atoi(val)) {
11277 pos += snprintf(pos, end - pos, "%s263", count > 0 ? "," : "");
11278 count++;
11279 }
11280
11281 val = get_param(cmd, "3GPP_INFO");
11282 if (val && atoi(val)) {
11283 pos += snprintf(pos, end - pos, "%s264", count > 0 ? "," : "");
11284 count++;
11285 }
11286
11287 val = get_param(cmd, "DOMAIN_LIST");
11288 if (val && atoi(val)) {
11289 pos += snprintf(pos, end - pos, "%s268", count > 0 ? "," : "");
11290 count++;
11291 }
11292
Jouni Malinen34cf9532018-04-29 19:26:33 +030011293 val = get_param(cmd, "Venue_URL");
11294 if (val && atoi(val)) {
11295 pos += snprintf(pos, end - pos, "%s277", count > 0 ? "," : "");
11296 count++;
11297 }
11298
Jouni Malinend3bca5d2018-04-29 17:25:23 +030011299 val = get_param(cmd, "Advice_Of_Charge");
11300 if (val && atoi(val)) {
11301 pos += snprintf(pos, end - pos, "%s278", count > 0 ? "," : "");
11302 count++;
11303 }
11304
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011305 if (count && wpa_command(intf, buf)) {
11306 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,ANQP_GET failed");
11307 return 0;
11308 }
11309
11310 pos = buf;
11311 end = buf + sizeof(buf);
11312 count2 = 0;
11313 pos += snprintf(pos, end - pos, "HS20_ANQP_GET %s ", dest);
11314
11315 val = get_param(cmd, "HS_CAP_LIST");
11316 if (val && atoi(val)) {
11317 pos += snprintf(pos, end - pos, "%s2", count2 > 0 ? "," : "");
11318 count2++;
11319 }
11320
11321 val = get_param(cmd, "OPER_NAME");
11322 if (val && atoi(val)) {
11323 pos += snprintf(pos, end - pos, "%s3", count2 > 0 ? "," : "");
11324 count2++;
11325 }
11326
11327 val = get_param(cmd, "WAN_METRICS");
11328 if (!val)
11329 val = get_param(cmd, "WAN_MAT");
11330 if (!val)
11331 val = get_param(cmd, "WAN_MET");
11332 if (val && atoi(val)) {
11333 pos += snprintf(pos, end - pos, "%s4", count2 > 0 ? "," : "");
11334 count2++;
11335 }
11336
11337 val = get_param(cmd, "CONNECTION_CAPABILITY");
11338 if (val && atoi(val)) {
11339 pos += snprintf(pos, end - pos, "%s5", count2 > 0 ? "," : "");
11340 count2++;
11341 }
11342
11343 val = get_param(cmd, "OP_CLASS");
11344 if (val && atoi(val)) {
11345 pos += snprintf(pos, end - pos, "%s7", count2 > 0 ? "," : "");
11346 count2++;
11347 }
11348
11349 val = get_param(cmd, "OSU_PROVIDER_LIST");
11350 if (val && atoi(val)) {
11351 pos += snprintf(pos, end - pos, "%s8", count2 > 0 ? "," : "");
11352 count2++;
11353 }
11354
Jouni Malinenf67afec2018-04-29 19:24:58 +030011355 val = get_param(cmd, "OPER_ICON_METADATA");
11356 if (!val)
11357 val = get_param(cmd, "OPERATOR_ICON_METADATA");
11358 if (val && atoi(val)) {
11359 pos += snprintf(pos, end - pos, "%s12", count2 > 0 ? "," : "");
11360 count2++;
11361 }
11362
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011363 if (count && count2) {
11364 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before sending out "
11365 "second query");
11366 sleep(1);
11367 }
11368
11369 if (count2 && wpa_command(intf, buf)) {
11370 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,HS20_ANQP_GET "
11371 "failed");
11372 return 0;
11373 }
11374
11375 val = get_param(cmd, "NAI_HOME_REALM_LIST");
11376 if (val) {
11377 if (count || count2) {
11378 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
11379 "sending out second query");
11380 sleep(1);
11381 }
11382
11383 if (strcmp(val, "1") == 0)
11384 val = "mail.example.com";
11385 snprintf(buf, end - pos,
11386 "HS20_GET_NAI_HOME_REALM_LIST %s realm=%s",
11387 dest, val);
11388 if (wpa_command(intf, buf)) {
11389 send_resp(dut, conn, SIGMA_ERROR,
11390 "ErrorCode,HS20_GET_NAI_HOME_REALM_LIST "
11391 "failed");
11392 return 0;
11393 }
11394 }
11395
11396 val = get_param(cmd, "ICON_REQUEST");
11397 if (val) {
11398 if (count || count2) {
11399 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
11400 "sending out second query");
11401 sleep(1);
11402 }
11403
11404 snprintf(buf, end - pos,
11405 "HS20_ICON_REQUEST %s %s", dest, val);
11406 if (wpa_command(intf, buf)) {
11407 send_resp(dut, conn, SIGMA_ERROR,
11408 "ErrorCode,HS20_ICON_REQUEST failed");
11409 return 0;
11410 }
11411 }
11412
11413 return 1;
11414}
11415
11416
11417static int ath_sta_send_frame_vht(struct sigma_dut *dut,
11418 struct sigma_conn *conn,
11419 struct sigma_cmd *cmd)
11420{
11421 const char *val;
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011422 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011423 int chwidth, nss;
11424
11425 val = get_param(cmd, "framename");
11426 if (!val)
11427 return -1;
11428 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
11429
11430 /* Command sequence to generate Op mode notification */
11431 if (val && strcasecmp(val, "Op_md_notif_frm") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011432 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011433
11434 /* Disable STBC */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011435 run_iwpriv(dut, ifname, "tx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011436
11437 /* Extract Channel width */
11438 val = get_param(cmd, "Channel_width");
11439 if (val) {
11440 switch (atoi(val)) {
11441 case 20:
11442 chwidth = 0;
11443 break;
11444 case 40:
11445 chwidth = 1;
11446 break;
11447 case 80:
11448 chwidth = 2;
11449 break;
11450 case 160:
11451 chwidth = 3;
11452 break;
11453 default:
11454 chwidth = 2;
11455 break;
11456 }
11457
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011458 run_iwpriv(dut, ifname, "chwidth %d", chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011459 }
11460
11461 /* Extract NSS */
11462 val = get_param(cmd, "NSS");
11463 if (val) {
11464 switch (atoi(val)) {
11465 case 1:
11466 nss = 1;
11467 break;
11468 case 2:
11469 nss = 3;
11470 break;
11471 case 3:
11472 nss = 7;
11473 break;
11474 default:
11475 /* We do not support NSS > 3 */
11476 nss = 3;
11477 break;
11478 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011479 run_iwpriv(dut, ifname, "rxchainmask %d", nss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011480 }
11481
11482 /* Opmode notify */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011483 run_iwpriv(dut, ifname, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011484 }
11485
11486 return 1;
11487}
11488
11489
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070011490static int wcn_sta_set_pmf_config(struct sigma_dut *dut, const char *intf,
11491 enum send_frame_protection protected)
11492{
11493#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +053011494 return wcn_wifi_test_config_set_u8(
11495 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_PMF_PROTECTION,
11496 protected);
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070011497#else /* NL80211_SUPPORT */
11498 sigma_dut_print(dut, DUT_MSG_ERROR,
11499 "PMF config cannot be set without NL80211_SUPPORT defined");
11500 return -1;
11501#endif /* NL80211_SUPPORT */
11502}
11503
11504
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011505static int cmd_sta_send_frame_vht(struct sigma_dut *dut,
11506 struct sigma_conn *conn,
11507 struct sigma_cmd *cmd)
11508{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011509 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011510 case DRIVER_ATHEROS:
11511 return ath_sta_send_frame_vht(dut, conn, cmd);
11512 default:
11513 send_resp(dut, conn, SIGMA_ERROR,
11514 "errorCode,Unsupported sta_set_frame(VHT) with the current driver");
11515 return 0;
11516 }
11517}
11518
11519
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070011520static int wcn_sta_send_disassoc(struct sigma_dut *dut, const char *intf)
11521{
11522#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +053011523 return wcn_wifi_test_config_set_flag(
11524 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_DISASSOC_TX);
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070011525#else /* NL80211_SUPPORT */
11526 sigma_dut_print(dut, DUT_MSG_ERROR,
11527 "Disassoc Tx cannot be done without NL80211_SUPPORT defined");
11528 return -1;
11529#endif /* NL80211_SUPPORT */
11530}
11531
11532
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011533static int wcn_sta_send_frame_he(struct sigma_dut *dut, struct sigma_conn *conn,
11534 struct sigma_cmd *cmd)
11535{
11536 const char *val;
11537 const char *intf = get_param(cmd, "Interface");
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070011538 enum send_frame_protection protected;
11539 const char *pmf;
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011540
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030011541 if (!intf)
11542 return -1;
11543
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011544 val = get_param(cmd, "framename");
11545 if (!val)
11546 return -1;
11547 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
11548
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070011549 pmf = get_param(cmd, "PMFProtected");
11550 if (!pmf)
11551 pmf = get_param(cmd, "Protected");
11552 if (pmf) {
11553 if (strcasecmp(pmf, "Correct-key") == 0 ||
11554 strcasecmp(pmf, "CorrectKey") == 0) {
11555 protected = CORRECT_KEY;
11556 } else if (strcasecmp(pmf, "IncorrectKey") == 0) {
11557 protected = INCORRECT_KEY;
11558 } else if (strcasecmp(pmf, "Unprotected") == 0) {
11559 protected = UNPROTECTED;
11560 } else {
11561 send_resp(dut, conn, SIGMA_ERROR,
11562 "errorCode,Unsupported PMFProtected");
11563 return STATUS_SENT_ERROR;
11564 }
11565 sigma_dut_print(dut, DUT_MSG_DEBUG, "Config PMF protection %d",
11566 protected);
11567 wcn_sta_set_pmf_config(dut, intf, protected);
11568 }
11569
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011570 /* Command sequence to generate Op mode notification */
11571 if (val && strcasecmp(val, "action") == 0) {
11572 val = get_param(cmd, "PPDUTxType");
11573 if (val && strcasecmp(val, "TB") == 0) {
11574 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 1)) {
11575 sigma_dut_print(dut, DUT_MSG_ERROR,
11576 "failed to send TB PPDU Tx cfg");
11577 send_resp(dut, conn, SIGMA_ERROR,
11578 "ErrorCode,set TB PPDU Tx cfg failed");
11579 return 0;
11580 }
11581 return 1;
11582 }
11583
11584 sigma_dut_print(dut, DUT_MSG_ERROR,
11585 "Action Tx type is not defined");
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070011586
11587 return SUCCESS_SEND_STATUS;
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011588 }
11589
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070011590 if (strcasecmp(val, "disassoc") == 0)
11591 wcn_sta_send_disassoc(dut, intf);
11592
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011593 return 1;
11594}
11595
11596
11597static int cmd_sta_send_frame_he(struct sigma_dut *dut,
11598 struct sigma_conn *conn,
11599 struct sigma_cmd *cmd)
11600{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011601 switch (get_driver_type(dut)) {
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011602 case DRIVER_WCN:
11603 return wcn_sta_send_frame_he(dut, conn, cmd);
11604 default:
11605 send_resp(dut, conn, SIGMA_ERROR,
11606 "errorCode,Unsupported sta_set_frame(HE) with the current driver");
11607 return 0;
11608 }
11609}
11610
11611
Lior David0fe101e2017-03-09 16:09:50 +020011612#ifdef __linux__
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030011613
11614static int
11615wil6210_send_p2p_frame_60g(struct sigma_dut *dut, struct sigma_cmd *cmd,
11616 const char *frame_name, const char *dest_mac)
11617{
11618 int isprobereq = strcasecmp(frame_name, "probereq") == 0;
11619 const char *ssid = get_param(cmd, "ssid");
11620 const char *countstr = get_param(cmd, "count");
11621 const char *channelstr = get_param(cmd, "channel");
11622 const char *group_id = get_param(cmd, "groupid");
11623 const char *client_id = get_param(cmd, "clientmac");
11624 int count, channel, freq, i;
11625 const char *fname;
11626 char frame[1024], src_mac[20], group_id_attr[25],
11627 device_macstr[3 * ETH_ALEN], client_mac[ETH_ALEN];
11628 const char *group_ssid;
11629 const int group_ssid_prefix_len = 9;
11630 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *) frame;
11631 size_t framelen = sizeof(frame);
11632 struct template_frame_tag tags[2];
11633 size_t tags_total = ARRAY_SIZE(tags);
11634 int tag_index, len, dst_len;
11635
11636 if (!countstr || !channelstr) {
11637 sigma_dut_print(dut, DUT_MSG_ERROR,
11638 "Missing argument: count, channel");
11639 return -1;
11640 }
11641 if (isprobereq && !ssid) {
11642 sigma_dut_print(dut, DUT_MSG_ERROR,
11643 "Missing argument: ssid");
11644 return -1;
11645 }
11646 if (!isprobereq && (!group_id || !client_id)) {
11647 sigma_dut_print(dut, DUT_MSG_ERROR,
11648 "Missing argument: group_id, client_id");
11649 return -1;
11650 }
11651
11652 count = atoi(countstr);
11653 channel = atoi(channelstr);
11654 freq = channel_to_freq(dut, channel);
11655
11656 if (!freq) {
11657 sigma_dut_print(dut, DUT_MSG_ERROR,
11658 "invalid channel: %s", channelstr);
11659 return -1;
11660 }
11661
11662 if (isprobereq) {
11663 if (strcasecmp(ssid, "wildcard") == 0) {
11664 fname = "probe_req_wildcard.txt";
11665 } else if (strcasecmp(ssid, "P2P_Wildcard") == 0) {
11666 fname = "probe_req_P2P_Wildcard.txt";
11667 } else {
11668 sigma_dut_print(dut, DUT_MSG_ERROR,
11669 "invalid probe request type");
11670 return -1;
11671 }
11672 } else {
11673 fname = "P2P_device_discovery_req.txt";
11674 }
11675
11676 if (parse_template_frame_file(dut, fname, frame, &framelen,
11677 tags, &tags_total)) {
11678 sigma_dut_print(dut, DUT_MSG_ERROR,
11679 "invalid frame template: %s", fname);
11680 return -1;
11681 }
11682
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011683 if (get_wpa_status(get_station_ifname(dut), "address",
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030011684 src_mac, sizeof(src_mac)) < 0 ||
11685 parse_mac_address(dut, src_mac, &hdr->addr2[0]) ||
11686 parse_mac_address(dut, dest_mac, &hdr->addr1[0]))
11687 return -1;
11688 /* Use wildcard BSSID, since we are in PBSS */
11689 memset(&hdr->addr3, 0xFF, ETH_ALEN);
11690
11691 if (!isprobereq) {
11692 tag_index = find_template_frame_tag(tags, tags_total, 1);
11693 if (tag_index < 0) {
11694 sigma_dut_print(dut, DUT_MSG_ERROR,
11695 "can't find device id attribute");
11696 return -1;
11697 }
11698 if (parse_mac_address(dut, client_id,
11699 (unsigned char *) client_mac)) {
11700 sigma_dut_print(dut, DUT_MSG_ERROR,
11701 "invalid client_id: %s", client_id);
11702 return -1;
11703 }
11704 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
11705 framelen - tags[tag_index].offset,
11706 IEEE80211_P2P_ATTR_DEVICE_ID,
11707 client_mac, ETH_ALEN)) {
11708 sigma_dut_print(dut, DUT_MSG_ERROR,
11709 "fail to replace device id attribute");
11710 return -1;
11711 }
11712
11713 /*
11714 * group_id arg contains device MAC address followed by
11715 * space and SSID (DIRECT-somessid).
11716 * group id attribute contains device address (6 bytes)
11717 * followed by SSID prefix DIRECT-XX (9 bytes)
11718 */
11719 if (strlen(group_id) < sizeof(device_macstr)) {
11720 sigma_dut_print(dut, DUT_MSG_ERROR,
11721 "group_id arg too short");
11722 return -1;
11723 }
11724 memcpy(device_macstr, group_id, sizeof(device_macstr));
11725 device_macstr[sizeof(device_macstr) - 1] = '\0';
11726 if (parse_mac_address(dut, device_macstr,
11727 (unsigned char *) group_id_attr)) {
11728 sigma_dut_print(dut, DUT_MSG_ERROR,
11729 "fail to parse device address from group_id");
11730 return -1;
11731 }
11732 group_ssid = strchr(group_id, ' ');
11733 if (!group_ssid) {
11734 sigma_dut_print(dut, DUT_MSG_ERROR,
11735 "invalid group_id arg, no ssid");
11736 return -1;
11737 }
11738 group_ssid++;
11739 len = strlen(group_ssid);
11740 if (len < group_ssid_prefix_len) {
11741 sigma_dut_print(dut, DUT_MSG_ERROR,
11742 "group_id SSID too short");
11743 return -1;
11744 }
11745 dst_len = sizeof(group_id_attr) - ETH_ALEN;
11746 if (len > dst_len) {
11747 sigma_dut_print(dut, DUT_MSG_ERROR,
11748 "group_id SSID (%s) too long",
11749 group_ssid);
11750 return -1;
11751 }
11752
11753 memcpy(group_id_attr + ETH_ALEN, group_ssid, len);
11754 tag_index = find_template_frame_tag(tags, tags_total, 2);
11755 if (tag_index < 0) {
11756 sigma_dut_print(dut, DUT_MSG_ERROR,
11757 "can't find group id attribute");
11758 return -1;
11759 }
11760 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
11761 framelen - tags[tag_index].offset,
11762 IEEE80211_P2P_ATTR_GROUP_ID,
11763 group_id_attr,
11764 sizeof(group_id_attr))) {
11765 sigma_dut_print(dut, DUT_MSG_ERROR,
11766 "fail to replace group id attribute");
11767 return -1;
11768 }
11769 }
11770
11771 for (i = 0; i < count; i++) {
11772 if (wil6210_transmit_frame(dut, freq,
11773 WIL_TRANSMIT_FRAME_DEFAULT_ROC,
11774 frame, framelen)) {
11775 sigma_dut_print(dut, DUT_MSG_ERROR,
11776 "fail to transmit probe request frame");
11777 return -1;
11778 }
11779 }
11780
11781 return 0;
11782}
11783
11784
Lior David0fe101e2017-03-09 16:09:50 +020011785int wil6210_send_frame_60g(struct sigma_dut *dut, struct sigma_conn *conn,
11786 struct sigma_cmd *cmd)
11787{
11788 const char *frame_name = get_param(cmd, "framename");
11789 const char *mac = get_param(cmd, "dest_mac");
11790
11791 if (!frame_name || !mac) {
11792 sigma_dut_print(dut, DUT_MSG_ERROR,
11793 "framename and dest_mac must be provided");
11794 return -1;
11795 }
11796
11797 if (strcasecmp(frame_name, "brp") == 0) {
11798 const char *l_rx = get_param(cmd, "L-RX");
11799 int l_rx_i;
11800
11801 if (!l_rx) {
11802 sigma_dut_print(dut, DUT_MSG_ERROR,
11803 "L-RX must be provided");
11804 return -1;
11805 }
11806 l_rx_i = atoi(l_rx);
11807
11808 sigma_dut_print(dut, DUT_MSG_INFO,
11809 "dev_send_frame: BRP-RX, dest_mac %s, L-RX %s",
11810 mac, l_rx);
11811 if (l_rx_i != 16) {
11812 sigma_dut_print(dut, DUT_MSG_ERROR,
11813 "unsupported L-RX: %s", l_rx);
11814 return -1;
11815 }
11816
11817 if (wil6210_send_brp_rx(dut, mac, l_rx_i))
11818 return -1;
11819 } else if (strcasecmp(frame_name, "ssw") == 0) {
11820 sigma_dut_print(dut, DUT_MSG_INFO,
11821 "dev_send_frame: SLS, dest_mac %s", mac);
11822 if (wil6210_send_sls(dut, mac))
11823 return -1;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030011824 } else if ((strcasecmp(frame_name, "probereq") == 0) ||
11825 (strcasecmp(frame_name, "devdiscreq") == 0)) {
11826 sigma_dut_print(dut, DUT_MSG_INFO,
11827 "dev_send_frame: %s, dest_mac %s", frame_name,
11828 mac);
11829 if (wil6210_send_p2p_frame_60g(dut, cmd, frame_name, mac))
11830 return -1;
Lior David0fe101e2017-03-09 16:09:50 +020011831 } else {
11832 sigma_dut_print(dut, DUT_MSG_ERROR,
11833 "unsupported frame type: %s", frame_name);
11834 return -1;
11835 }
11836
11837 return 1;
11838}
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030011839
Lior David0fe101e2017-03-09 16:09:50 +020011840#endif /* __linux__ */
11841
11842
11843static int cmd_sta_send_frame_60g(struct sigma_dut *dut,
11844 struct sigma_conn *conn,
11845 struct sigma_cmd *cmd)
11846{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011847 switch (get_driver_type(dut)) {
Lior David0fe101e2017-03-09 16:09:50 +020011848#ifdef __linux__
11849 case DRIVER_WIL6210:
11850 return wil6210_send_frame_60g(dut, conn, cmd);
11851#endif /* __linux__ */
11852 default:
11853 send_resp(dut, conn, SIGMA_ERROR,
11854 "errorCode,Unsupported sta_set_frame(60G) with the current driver");
11855 return 0;
11856 }
11857}
11858
11859
Ashwini Patildb59b3c2017-04-13 15:19:23 +053011860static int mbo_send_anqp_query(struct sigma_dut *dut, struct sigma_conn *conn,
11861 const char *intf, struct sigma_cmd *cmd)
11862{
11863 const char *val, *addr;
11864 char buf[100];
11865
11866 addr = get_param(cmd, "DestMac");
11867 if (!addr) {
11868 send_resp(dut, conn, SIGMA_INVALID,
11869 "ErrorCode,AP MAC address is missing");
11870 return 0;
11871 }
11872
11873 val = get_param(cmd, "ANQPQuery_ID");
11874 if (!val) {
11875 send_resp(dut, conn, SIGMA_INVALID,
11876 "ErrorCode,Missing ANQPQuery_ID");
11877 return 0;
11878 }
11879
11880 if (strcasecmp(val, "NeighborReportReq") == 0) {
11881 snprintf(buf, sizeof(buf), "ANQP_GET %s 272", addr);
11882 } else if (strcasecmp(val, "QueryListWithCellPref") == 0) {
11883 snprintf(buf, sizeof(buf), "ANQP_GET %s 272,mbo:2", addr);
11884 } else {
11885 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid ANQPQuery_ID: %s",
11886 val);
11887 send_resp(dut, conn, SIGMA_INVALID,
11888 "ErrorCode,Invalid ANQPQuery_ID");
11889 return 0;
11890 }
11891
Ashwini Patild174f2c2017-04-13 16:49:46 +053011892 /* Set gas_address3 field to IEEE 802.11-2012 standard compliant form
11893 * (Address3 = Wildcard BSSID when sent to not-associated AP;
11894 * if associated, AP BSSID).
11895 */
11896 if (wpa_command(intf, "SET gas_address3 1") < 0) {
11897 send_resp(dut, conn, SIGMA_ERROR,
11898 "ErrorCode,Failed to set gas_address3");
11899 return 0;
11900 }
11901
Ashwini Patildb59b3c2017-04-13 15:19:23 +053011902 if (wpa_command(intf, buf) < 0) {
11903 send_resp(dut, conn, SIGMA_ERROR,
11904 "ErrorCode,Failed to send ANQP query");
11905 return 0;
11906 }
11907
11908 return 1;
11909}
11910
11911
11912static int mbo_cmd_sta_send_frame(struct sigma_dut *dut,
11913 struct sigma_conn *conn,
11914 const char *intf,
11915 struct sigma_cmd *cmd)
11916{
11917 const char *val = get_param(cmd, "FrameName");
11918
11919 if (val && strcasecmp(val, "ANQPQuery") == 0)
11920 return mbo_send_anqp_query(dut, conn, intf, cmd);
11921
11922 return 2;
11923}
11924
11925
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053011926static enum sigma_cmd_result cmd_sta_send_frame_wpa3(struct sigma_dut *dut,
11927 struct sigma_conn *conn,
11928 const char *intf,
11929 struct sigma_cmd *cmd)
11930{
11931 const char *val = get_param(cmd, "framename");
11932
11933 if (!val)
11934 return INVALID_SEND_STATUS;
11935
11936 if (strcasecmp(val, "SAQueryReq") == 0) {
11937 val = get_param(cmd, "OCIChannel");
11938
11939 if (!val) {
11940 send_resp(dut, conn, SIGMA_ERROR,
11941 "errorCode,OCIChannel not present");
11942 return STATUS_SENT_ERROR;
11943 }
11944
11945 dut->saquery_oci_freq = channel_to_freq(dut, atoi(val));
11946 if (!dut->saquery_oci_freq) {
11947 send_resp(dut, conn, SIGMA_ERROR,
11948 "errorCode,Invalid OCIChannel number");
11949 return STATUS_SENT_ERROR;
11950 }
11951
11952 return sta_inject_frame(dut, conn, intf, SAQUERY, CORRECT_KEY,
11953 NULL, 0);
11954 }
11955
11956 if (strcasecmp(val, "reassocreq") == 0)
11957 return sta_inject_frame(dut, conn, intf, REASSOCREQ,
11958 CORRECT_KEY, NULL, 0);
11959
Veerendranath9f81dfb2020-08-10 01:21:29 -070011960 if (strcasecmp(val, "ANQPQuery") == 0) {
11961 char buf[50];
11962 const char *dest = get_param(cmd, "DestMac");
11963 const char *chan = get_param(cmd, "channel");
Veerendranath Jakkam78862fc2020-11-19 21:23:27 +053011964 const char *freq_str = get_param(cmd, "ChnlFreq");
Veerendranath9f81dfb2020-08-10 01:21:29 -070011965 int len, freq;
11966
Veerendranath Jakkam78862fc2020-11-19 21:23:27 +053011967 if (freq_str)
11968 freq = atoi(freq_str);
11969 else
11970 freq = chan ? channel_to_freq(dut, atoi(chan)) : 0;
11971
Veerendranath9f81dfb2020-08-10 01:21:29 -070011972 if (!dest || !freq)
11973 return INVALID_SEND_STATUS;
11974
11975 len = snprintf(buf, sizeof(buf), "ANQP_GET %s freq=%d 257",
11976 dest, freq);
11977 if (len < 0 || len >= sizeof(buf)) {
11978 sigma_dut_print(dut, DUT_MSG_ERROR,
11979 "Failed to allocate buf");
11980 return ERROR_SEND_STATUS;
11981 }
11982
11983 if (wpa_command(intf, buf) != 0) {
11984 send_resp(dut, conn, SIGMA_ERROR,
11985 "ErrorCode,Failed to send ANQP Query frame");
11986 return STATUS_SENT_ERROR;
11987 }
11988
11989 sigma_dut_print(dut, DUT_MSG_DEBUG,
11990 "ANQP Query sent: %s", buf);
11991
11992 return SUCCESS_SEND_STATUS;
11993 }
11994
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053011995 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported framename");
11996 return STATUS_SENT_ERROR;
11997}
11998
11999
Vinita S. Malooca85fd22021-01-15 02:54:34 +053012000static int
12001get_type4_frame_classifier(struct sigma_dut *dut, struct sigma_cmd *cmd,
12002 char *pos, int rem_len, int num_of_scs_desc,
12003 int num_of_tclas_elem)
12004{
12005 const char *val;
12006 int ipv6;
12007 int len, total_len = 0;
12008
12009 val = get_param_fmt(cmd, "TCLASElem_Version_%d_%d", num_of_scs_desc,
12010 num_of_tclas_elem);
12011 if (!val) {
12012 sigma_dut_print(dut, DUT_MSG_ERROR, "%s: ip_version empty",
12013 __func__);
12014 return -1;
12015 }
12016
12017 if (strcmp(val, "6") == 0) {
12018 ipv6 = 1;
12019 } else if (strcmp(val, "4") == 0) {
12020 ipv6 = 0;
12021 } else {
12022 sigma_dut_print(dut, DUT_MSG_ERROR, "%s: ip_version invalid",
12023 __func__);
12024 return -1;
12025 }
12026
12027 len = snprintf(pos, rem_len, " ip_version=%s", ipv6 ? "ipv6" : "ipv4");
12028 if (len < 0 || len >= rem_len)
12029 return -1;
12030
12031 pos += len;
12032 rem_len -= len;
12033 total_len += len;
12034
12035 val = get_param_fmt(cmd, "TCLASElem_SourceIPAddr_%d_%d",
12036 num_of_scs_desc, num_of_tclas_elem);
12037 if (val) {
12038 len = snprintf(pos, rem_len, " src_ip=%s", val);
12039 if (len < 0 || len >= rem_len)
12040 return -1;
12041
12042 pos += len;
12043 rem_len -= len;
12044 total_len += len;
12045 }
12046
12047 val = get_param_fmt(cmd, "TCLASElem_DestinationIPAddr_%d_%d",
12048 num_of_scs_desc, num_of_tclas_elem);
12049 if (val) {
12050 len = snprintf(pos, rem_len, " dst_ip=%s", val);
12051 if (len < 0 || len >= rem_len)
12052 return -1;
12053
12054 pos += len;
12055 rem_len -= len;
12056 total_len += len;
12057 }
12058
12059 val = get_param_fmt(cmd, "TCLASElem_SourcePort_%d_%d", num_of_scs_desc,
12060 num_of_tclas_elem);
12061 if (val) {
12062 len = snprintf(pos, rem_len, " src_port=%s", val);
12063 if (len < 0 || len >= rem_len)
12064 return -1;
12065
12066 pos += len;
12067 rem_len -= len;
12068 total_len += len;
12069 }
12070
12071 val = get_param_fmt(cmd, "TCLASElem_DestinationPort_%d_%d",
12072 num_of_scs_desc, num_of_tclas_elem);
12073 if (val) {
12074 len = snprintf(pos, rem_len, " dst_port=%s", val);
12075 if (len < 0 || len >= rem_len)
12076 return -1;
12077
12078 pos += len;
12079 rem_len -= len;
12080 total_len += len;
12081 }
12082
12083 val = get_param_fmt(cmd, "TCLASElem_DSCP_%d_%d", num_of_scs_desc,
12084 num_of_tclas_elem);
12085 if (val) {
12086 len = snprintf(pos, rem_len, " dscp=%s", val);
12087 if (len < 0 || len >= rem_len)
12088 return -1;
12089
12090 pos += len;
12091 rem_len -= len;
12092 total_len += len;
12093 }
12094
12095 val = get_param_fmt(cmd, "TCLASElem_ProtocolNxtHeader_%d_%d",
12096 num_of_scs_desc, num_of_tclas_elem);
12097 if (val) {
12098 char *prot;
12099
12100 switch (atoi(val)) {
12101 case 17:
12102 prot = "udp";
12103 break;
12104 case 6:
12105 prot = "tcp";
12106 break;
12107 case 50:
12108 prot = "esp";
12109 break;
12110 default:
12111 sigma_dut_print(dut, DUT_MSG_ERROR,
12112 "Invalid protocol %d", atoi(val));
12113 return -1;
12114 }
12115
12116 if (ipv6)
12117 len = snprintf(pos, rem_len, " next_header=%s", prot);
12118 else
12119 len = snprintf(pos, rem_len, " protocol=%s", prot);
12120 if (len < 0 || len >= rem_len)
12121 return -1;
12122
12123 pos += len;
12124 rem_len -= len;
12125 total_len += len;
12126 }
12127
12128 return total_len;
12129}
12130
12131
12132static int
12133get_type10_frame_classifier(struct sigma_dut *dut, struct sigma_cmd *cmd,
12134 char *pos, int rem_len, int num_of_scs_desc,
12135 int num_of_tclas_elem)
12136{
12137 const char *val;
12138 int len, total_len = 0;
12139
12140 val = get_param_fmt(cmd, "TCLASElem_ProtoInstance_%d_%d",
12141 num_of_scs_desc, num_of_tclas_elem);
12142 if (val) {
12143 len = snprintf(pos, rem_len, " prot_instance=%s",
12144 val);
12145 if (len < 0 || len >= rem_len)
12146 return -1;
12147
12148 pos += len;
12149 rem_len -= len;
12150 total_len += len;
12151 }
12152
12153 val = get_param_fmt(cmd, "TCLASElem_ProtoNumNextHeader_%d_%d",
12154 num_of_scs_desc, num_of_tclas_elem);
12155 if (val) {
12156 char *prot;
12157
12158 switch (atoi(val)) {
12159 case 17:
12160 prot = "udp";
12161 break;
12162 case 6:
12163 prot = "tcp";
12164 break;
12165 case 50:
12166 prot = "esp";
12167 break;
12168 default:
12169 sigma_dut_print(dut, DUT_MSG_ERROR,
12170 "Invalid protocol %d",
12171 atoi(val));
12172 return -1;
12173 }
12174
12175 len = snprintf(pos, rem_len, " prot_number=%s", prot);
12176 if (len < 0 || len >= rem_len)
12177 return -1;
12178
12179 pos += len;
12180 rem_len -= len;
12181 total_len += len;
12182 }
12183
12184 val = get_param_fmt(cmd, "TCLASElem_FilterValue_%d_%d",
12185 num_of_scs_desc, num_of_tclas_elem);
12186 if (val) {
12187 len = snprintf(pos, rem_len, " filter_value=%s", (val + 2));
12188 if (len < 0 || len >= rem_len)
12189 return -1;
12190
12191 pos += len;
12192 rem_len -= len;
12193 total_len += len;
12194 }
12195
12196 val = get_param_fmt(cmd, "TCLASElem_FilterMask_%d_%d", num_of_scs_desc,
12197 num_of_tclas_elem);
12198 if (val && strlen(val) >= 2) {
12199 len = snprintf(pos, rem_len, " filter_mask=%s", val + 2);
12200 if (len < 0 || len >= rem_len)
12201 return -1;
12202
12203 pos += len;
12204 rem_len -= len;
12205 total_len += len;
12206 }
12207
12208 return total_len;
12209}
12210
12211
12212static enum sigma_cmd_result
12213cmd_sta_send_frame_scs(struct sigma_dut *dut, struct sigma_conn *conn,
12214 const char *intf, struct sigma_cmd *cmd)
12215{
12216 char buf[4096], *pos;
12217 const char *val, *scs_id, *classifier_type;
12218 int len, rem_len, total_bytes;
12219 int num_of_scs_desc = 0, num_of_tclas_elem = 0;
12220
12221 scs_id = get_param(cmd, "SCSDescrElem_SCSID_1");
12222 if (!scs_id) {
12223 sigma_dut_print(dut, DUT_MSG_ERROR, "SCS ID empty");
12224 return INVALID_SEND_STATUS;
12225 }
12226
12227 rem_len = sizeof(buf);
12228 pos = buf;
12229
12230 len = snprintf(buf, sizeof(buf), "SCS");
12231 if (len < 0 || len > rem_len)
12232 goto fail;
12233
12234 pos += len;
12235 rem_len -= len;
12236
12237 while (scs_id) {
12238 num_of_scs_desc++;
12239
12240 val = get_param_fmt(cmd, "SCSDescrElem_RequestType_%d",
12241 num_of_scs_desc);
12242 if (!val)
12243 return INVALID_SEND_STATUS;
12244
12245 if (strcasecmp(val, "Add") == 0) {
12246 len = snprintf(pos, rem_len, " scs_id=%s add",
12247 scs_id);
12248 } else if (strcasecmp(val, "Change") == 0) {
12249 len = snprintf(pos, rem_len, " scs_id=%s change",
12250 scs_id);
12251 } else if (strcasecmp(val, "Remove") == 0) {
12252 len = snprintf(pos, rem_len, " scs_id=%s remove",
12253 scs_id);
12254 if (len < 0 || len >= rem_len)
12255 goto fail;
12256
12257 pos += len;
12258 rem_len -= len;
12259 goto scs_desc_end;
12260 } else {
12261 sigma_dut_print(dut, DUT_MSG_ERROR,
12262 "%s: request type - %s is invalid",
12263 __func__, val);
12264 return INVALID_SEND_STATUS;
12265 }
12266
12267 if (len < 0 || len >= rem_len)
12268 goto fail;
12269
12270 pos += len;
12271 rem_len -= len;
12272
12273 val = get_param_fmt(cmd, "IntraAccessCatElem_UP_%d",
12274 num_of_scs_desc);
12275 if (!val) {
12276 sigma_dut_print(dut, DUT_MSG_ERROR,
12277 "IntraAccess Priority empty");
12278 return INVALID_SEND_STATUS;
12279 }
12280
12281 len = snprintf(pos, rem_len, " scs_up=%s", val);
12282 if (len < 0 || len >= rem_len)
12283 goto fail;
12284
12285 pos += len;
12286 rem_len -= len;
12287
12288 classifier_type = get_param_fmt(cmd,
12289 "TCLASElem_ClassifierType_%d_1",
12290 num_of_scs_desc);
12291 if (!classifier_type) {
12292 sigma_dut_print(dut, DUT_MSG_ERROR,
12293 "classifier type missing");
12294 return INVALID_SEND_STATUS;
12295 }
12296
12297 while (classifier_type) {
12298 num_of_tclas_elem++;
12299
12300 len = snprintf(pos, rem_len, " classifier_type=%s",
12301 classifier_type);
12302 if (len < 0 || len >= rem_len)
12303 goto fail;
12304
12305 pos += len;
12306 rem_len -= len;
12307
12308 if (strcmp(classifier_type, "10") == 0) {
12309 total_bytes = get_type10_frame_classifier(
12310 dut, cmd, pos, rem_len,
12311 num_of_scs_desc,
12312 num_of_tclas_elem);
12313 } else if (strcmp(classifier_type, "4") == 0) {
12314 total_bytes = get_type4_frame_classifier(
12315 dut, cmd, pos, rem_len,
12316 num_of_scs_desc,
12317 num_of_tclas_elem);
12318 } else {
12319 sigma_dut_print(dut, DUT_MSG_ERROR,
12320 "classifier_type invalid");
12321 goto fail;
12322 }
12323
12324 if (total_bytes < 0)
12325 goto fail;
12326
12327 pos += total_bytes;
12328 rem_len -= total_bytes;
12329
12330 classifier_type = get_param_fmt(
12331 cmd, "TCLASElem_ClassifierType_%d_%d",
12332 num_of_scs_desc, num_of_tclas_elem + 1);
12333 }
12334
12335 if (num_of_tclas_elem > 1) {
12336 val = get_param_fmt(cmd,
12337 "TCLASProcessingElem_Processing_%d",
12338 num_of_scs_desc);
12339 if (!val) {
12340 sigma_dut_print(dut, DUT_MSG_ERROR,
12341 "Tclas_processing element %d empty",
12342 num_of_scs_desc);
12343 goto fail;
12344 }
12345
12346 len = snprintf(pos, rem_len,
12347 " tclas_processing=%s", val);
12348 if (len < 0 || len >= rem_len)
12349 goto fail;
12350
12351 pos += len;
12352 rem_len -= len;
12353 }
12354scs_desc_end:
12355 num_of_tclas_elem = 0;
12356 scs_id = get_param_fmt(cmd, "SCSDescrElem_SCSID_%d",
12357 num_of_scs_desc + 1);
12358 }
12359
12360 if (wpa_command(intf, buf) != 0) {
12361 send_resp(dut, conn, SIGMA_ERROR,
12362 "ErrorCode,Failed to send SCS frame request");
12363 return STATUS_SENT_ERROR;
12364 }
12365
12366 sigma_dut_print(dut, DUT_MSG_DEBUG,
12367 "SCS frame request sent: %s", buf);
12368
12369 return SUCCESS_SEND_STATUS;
12370fail:
12371 sigma_dut_print(dut, DUT_MSG_ERROR,
12372 "Failed to create SCS frame request");
12373 return ERROR_SEND_STATUS;
12374}
12375
12376
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053012377static enum sigma_cmd_result
12378cmd_sta_send_frame_mscs(struct sigma_dut *dut, struct sigma_conn *conn,
12379 const char *intf, struct sigma_cmd *cmd)
12380{
12381 char buf[128], *pos;
12382 const char *val, *classifier_type = "04", *type;
12383 int len, rem_len;
12384 u8 up_bitmap;
12385
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053012386 type = get_param(cmd, "Request_Type");
Vinita S. Malooca85fd22021-01-15 02:54:34 +053012387 if (!type) {
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053012388 sigma_dut_print(dut, DUT_MSG_ERROR,
Vinita S. Malooca85fd22021-01-15 02:54:34 +053012389 "%s: type not valid", __func__);
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053012390 return INVALID_SEND_STATUS;
12391 }
12392
12393 rem_len = sizeof(buf);
12394 pos = buf;
12395 if (strcasecmp(type, "add") == 0) {
12396 len = snprintf(pos, rem_len, "MSCS add");
12397 } else if (strcasecmp(type, "update") == 0) {
12398 len = snprintf(pos, rem_len, "MSCS change");
12399 } else if (strcasecmp(type, "remove") == 0) {
12400 if (wpa_command(intf, "MSCS remove") != 0) {
12401 send_resp(dut, conn, SIGMA_ERROR,
12402 "ErrorCode,Failed to send MSCS frame req");
12403 return STATUS_SENT_ERROR;
12404 }
12405 return SUCCESS_SEND_STATUS;
12406 } else {
12407 sigma_dut_print(dut, DUT_MSG_ERROR,
12408 "%s: request type invalid", __func__);
12409 return INVALID_SEND_STATUS;
12410 }
12411
12412 if (len < 0 || len >= rem_len)
12413 goto fail;
12414
12415 pos += len;
12416 rem_len -= len;
12417
12418 val = get_param(cmd, "User_Priority_Bitmap");
12419 if (!val) {
12420 sigma_dut_print(dut, DUT_MSG_ERROR,
12421 "%s: user priority bitmap empty", __func__);
12422 return INVALID_SEND_STATUS;
12423 }
12424
12425 switch (atoi(val)) {
12426 case 0:
12427 up_bitmap = 0x00;
12428 break;
12429 case 1:
12430 up_bitmap = 0xF0;
12431 break;
12432 case 2:
12433 up_bitmap = 0xF6;
12434 break;
12435 default:
12436 sigma_dut_print(dut, DUT_MSG_ERROR,
12437 "%s: Unknown User_Priority_Bitmap value %d",
12438 __func__, atoi(val));
12439 return INVALID_SEND_STATUS;
12440 }
12441
12442 len = snprintf(pos, rem_len, " up_bitmap=%02x", up_bitmap);
12443 if (len < 0 || len >= rem_len)
12444 goto fail;
12445
12446 pos += len;
12447 rem_len -= len;
12448
12449 val = get_param(cmd, "User_Priority_Limit");
12450 if (!val) {
12451 sigma_dut_print(dut, DUT_MSG_ERROR,
12452 "%s: invalid user priority limit", __func__);
12453 return INVALID_SEND_STATUS;
12454 }
12455
12456 len = snprintf(pos, rem_len, " up_limit=%s", val);
12457 if (len < 0 || len >= rem_len)
12458 goto fail;
12459
12460 pos += len;
12461 rem_len -= len;
12462
12463 val = get_param(cmd, "Stream_Timeout");
12464 if (!val)
12465 val = get_param(cmd, "Stream_Timtout");
12466 if (!val) {
12467 sigma_dut_print(dut, DUT_MSG_ERROR,
12468 "%s: invalid stream timeout", __func__);
12469 return INVALID_SEND_STATUS;
12470 }
12471
12472 len = snprintf(pos, rem_len, " stream_timeout=%s", val);
12473 if (len < 0 || len >= rem_len)
12474 goto fail;
12475
12476 pos += len;
12477 rem_len -= len;
12478
12479 val = get_param(cmd, "TCLAS_Mask");
12480 if (!val) {
12481 sigma_dut_print(dut, DUT_MSG_ERROR,
12482 "%s: invalid tclas mask", __func__);
12483 return INVALID_SEND_STATUS;
12484 }
12485
12486 len = snprintf(pos, rem_len, " frame_classifier=%s%lx%032x",
12487 classifier_type, strtol(val, NULL, 2), 0);
12488 if (len < 0 || len >= rem_len)
12489 goto fail;
12490
12491 if (wpa_command(intf, buf) != 0) {
12492 send_resp(dut, conn, SIGMA_ERROR,
12493 "ErrorCode,Failed to send MSCS frame req");
12494 return STATUS_SENT_ERROR;
12495 }
12496
12497 sigma_dut_print(dut, DUT_MSG_DEBUG,
12498 "MSCS frame request sent: %s", buf);
12499
12500 return SUCCESS_SEND_STATUS;
12501fail:
12502 sigma_dut_print(dut, DUT_MSG_ERROR,
12503 "Failed to create MSCS frame req");
12504 return ERROR_SEND_STATUS;
12505}
12506
12507
Vinita S. Malooca85fd22021-01-15 02:54:34 +053012508static enum sigma_cmd_result
12509cmd_sta_send_frame_qm(struct sigma_dut *dut, struct sigma_conn *conn,
12510 const char *intf, struct sigma_cmd *cmd)
12511{
12512 const char *val;
12513
12514 val = get_param(cmd, "FrameName");
12515 if (val) {
12516 if (strcasecmp(val, "MSCSReq") == 0)
12517 return cmd_sta_send_frame_mscs(dut, conn, intf, cmd);
12518 if (strcasecmp(val, "SCSReq") == 0)
12519 return cmd_sta_send_frame_scs(dut, conn, intf, cmd);
12520
12521 sigma_dut_print(dut, DUT_MSG_ERROR,
12522 "%s: frame name - %s is invalid",
12523 __func__, val);
12524 }
12525
12526 return INVALID_SEND_STATUS;
12527}
12528
12529
Jouni Malinenf7222712019-06-13 01:50:21 +030012530enum sigma_cmd_result cmd_sta_send_frame(struct sigma_dut *dut,
12531 struct sigma_conn *conn,
12532 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012533{
12534 const char *intf = get_param(cmd, "Interface");
12535 const char *val;
12536 enum send_frame_type frame;
12537 enum send_frame_protection protected;
12538 char buf[100];
12539 unsigned char addr[ETH_ALEN];
12540 int res;
12541
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030012542 if (!intf)
12543 return -1;
12544
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012545 val = get_param(cmd, "program");
12546 if (val == NULL)
12547 val = get_param(cmd, "frame");
12548 if (val && strcasecmp(val, "TDLS") == 0)
12549 return cmd_sta_send_frame_tdls(dut, conn, cmd);
12550 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030012551 strcasecmp(val, "HS2-R2") == 0 ||
12552 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012553 return cmd_sta_send_frame_hs2(dut, conn, cmd);
12554 if (val && strcasecmp(val, "VHT") == 0)
12555 return cmd_sta_send_frame_vht(dut, conn, cmd);
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070012556 if (val && strcasecmp(val, "HE") == 0)
12557 return cmd_sta_send_frame_he(dut, conn, cmd);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -070012558 if (val && strcasecmp(val, "LOC") == 0)
12559 return loc_cmd_sta_send_frame(dut, conn, cmd);
Lior David0fe101e2017-03-09 16:09:50 +020012560 if (val && strcasecmp(val, "60GHz") == 0)
12561 return cmd_sta_send_frame_60g(dut, conn, cmd);
Ashwini Patildb59b3c2017-04-13 15:19:23 +053012562 if (val && strcasecmp(val, "MBO") == 0) {
12563 res = mbo_cmd_sta_send_frame(dut, conn, intf, cmd);
12564 if (res != 2)
12565 return res;
12566 }
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053012567 if (val && strcasecmp(val, "WPA3") == 0)
12568 return cmd_sta_send_frame_wpa3(dut, conn, intf, cmd);
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053012569 if (val && strcasecmp(val, "QM") == 0)
Vinita S. Malooca85fd22021-01-15 02:54:34 +053012570 return cmd_sta_send_frame_qm(dut, conn, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012571
12572 val = get_param(cmd, "TD_DISC");
12573 if (val) {
12574 if (hwaddr_aton(val, addr) < 0)
12575 return -1;
12576 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", val);
12577 if (wpa_command(intf, buf) < 0) {
12578 send_resp(dut, conn, SIGMA_ERROR,
12579 "ErrorCode,Failed to send TDLS discovery");
12580 return 0;
12581 }
12582 return 1;
12583 }
12584
12585 val = get_param(cmd, "TD_Setup");
12586 if (val) {
12587 if (hwaddr_aton(val, addr) < 0)
12588 return -1;
12589 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", val);
12590 if (wpa_command(intf, buf) < 0) {
12591 send_resp(dut, conn, SIGMA_ERROR,
12592 "ErrorCode,Failed to start TDLS setup");
12593 return 0;
12594 }
12595 return 1;
12596 }
12597
12598 val = get_param(cmd, "TD_TearDown");
12599 if (val) {
12600 if (hwaddr_aton(val, addr) < 0)
12601 return -1;
12602 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", val);
12603 if (wpa_command(intf, buf) < 0) {
12604 send_resp(dut, conn, SIGMA_ERROR,
12605 "ErrorCode,Failed to tear down TDLS link");
12606 return 0;
12607 }
12608 return 1;
12609 }
12610
12611 val = get_param(cmd, "TD_ChannelSwitch");
12612 if (val) {
12613 /* TODO */
12614 send_resp(dut, conn, SIGMA_ERROR,
12615 "ErrorCode,TD_ChannelSwitch not yet supported");
12616 return 0;
12617 }
12618
12619 val = get_param(cmd, "TD_NF");
12620 if (val) {
12621 /* TODO */
12622 send_resp(dut, conn, SIGMA_ERROR,
12623 "ErrorCode,TD_NF not yet supported");
12624 return 0;
12625 }
12626
12627 val = get_param(cmd, "PMFFrameType");
12628 if (val == NULL)
12629 val = get_param(cmd, "FrameName");
12630 if (val == NULL)
12631 val = get_param(cmd, "Type");
12632 if (val == NULL)
12633 return -1;
12634 if (strcasecmp(val, "disassoc") == 0)
12635 frame = DISASSOC;
12636 else if (strcasecmp(val, "deauth") == 0)
12637 frame = DEAUTH;
12638 else if (strcasecmp(val, "saquery") == 0)
12639 frame = SAQUERY;
12640 else if (strcasecmp(val, "auth") == 0)
12641 frame = AUTH;
12642 else if (strcasecmp(val, "assocreq") == 0)
12643 frame = ASSOCREQ;
12644 else if (strcasecmp(val, "reassocreq") == 0)
12645 frame = REASSOCREQ;
12646 else if (strcasecmp(val, "neigreq") == 0) {
12647 sigma_dut_print(dut, DUT_MSG_INFO, "Got neighbor request");
12648
12649 val = get_param(cmd, "ssid");
12650 if (val == NULL)
12651 return -1;
12652
12653 res = send_neighbor_request(dut, intf, val);
12654 if (res) {
12655 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
12656 "Failed to send neighbor report request");
12657 return 0;
12658 }
12659
12660 return 1;
Ashwini Patil5acd7382017-04-13 15:55:04 +053012661 } else if (strcasecmp(val, "transmgmtquery") == 0 ||
12662 strcasecmp(val, "BTMQuery") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012663 sigma_dut_print(dut, DUT_MSG_DEBUG,
12664 "Got Transition Management Query");
12665
Ashwini Patil5acd7382017-04-13 15:55:04 +053012666 res = send_trans_mgmt_query(dut, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012667 if (res) {
12668 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
12669 "Failed to send Transition Management Query");
12670 return 0;
12671 }
12672
12673 return 1;
12674 } else {
12675 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
12676 "PMFFrameType");
12677 return 0;
12678 }
12679
12680 val = get_param(cmd, "PMFProtected");
12681 if (val == NULL)
12682 val = get_param(cmd, "Protected");
12683 if (val == NULL)
12684 return -1;
12685 if (strcasecmp(val, "Correct-key") == 0 ||
12686 strcasecmp(val, "CorrectKey") == 0)
12687 protected = CORRECT_KEY;
12688 else if (strcasecmp(val, "IncorrectKey") == 0)
12689 protected = INCORRECT_KEY;
12690 else if (strcasecmp(val, "Unprotected") == 0)
12691 protected = UNPROTECTED;
12692 else {
12693 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
12694 "PMFProtected");
12695 return 0;
12696 }
12697
12698 if (protected != UNPROTECTED &&
12699 (frame == AUTH || frame == ASSOCREQ || frame == REASSOCREQ)) {
12700 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Impossible "
12701 "PMFProtected for auth/assocreq/reassocreq");
12702 return 0;
12703 }
12704
12705 if (if_nametoindex("sigmadut") == 0) {
12706 snprintf(buf, sizeof(buf),
12707 "iw dev %s interface add sigmadut type monitor",
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012708 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012709 if (system(buf) != 0 ||
12710 if_nametoindex("sigmadut") == 0) {
12711 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
12712 "monitor interface with '%s'", buf);
12713 return -2;
12714 }
12715 }
12716
12717 if (system("ifconfig sigmadut up") != 0) {
12718 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
12719 "monitor interface up");
12720 return -2;
12721 }
12722
Veerendranath Jakkam49774122020-07-05 09:52:18 +053012723 return sta_inject_frame(dut, conn, intf, frame, protected, NULL, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012724}
12725
12726
12727static int cmd_sta_set_parameter_hs2(struct sigma_dut *dut,
12728 struct sigma_conn *conn,
12729 struct sigma_cmd *cmd,
12730 const char *ifname)
12731{
12732 char buf[200];
12733 const char *val;
12734
12735 val = get_param(cmd, "ClearARP");
12736 if (val && atoi(val) == 1) {
12737 snprintf(buf, sizeof(buf), "ip neigh flush dev %s", ifname);
12738 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
12739 if (system(buf) != 0) {
12740 send_resp(dut, conn, SIGMA_ERROR,
12741 "errorCode,Failed to clear ARP cache");
12742 return 0;
12743 }
12744 }
12745
12746 return 1;
12747}
12748
12749
12750int cmd_sta_set_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
12751 struct sigma_cmd *cmd)
12752{
12753 const char *intf = get_param(cmd, "Interface");
12754 const char *val;
12755
12756 if (intf == NULL)
12757 return -1;
12758
12759 val = get_param(cmd, "program");
12760 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030012761 strcasecmp(val, "HS2-R2") == 0 ||
12762 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012763 return cmd_sta_set_parameter_hs2(dut, conn, cmd, intf);
12764
12765 return -1;
12766}
12767
12768
Jouni Malinenf7222712019-06-13 01:50:21 +030012769static enum sigma_cmd_result cmd_sta_set_macaddr(struct sigma_dut *dut,
12770 struct sigma_conn *conn,
12771 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012772{
12773 const char *intf = get_param(cmd, "Interface");
12774 const char *mac = get_param(cmd, "MAC");
12775
12776 if (intf == NULL || mac == NULL)
12777 return -1;
12778
12779 sigma_dut_print(dut, DUT_MSG_INFO, "Change local MAC address for "
12780 "interface %s to %s", intf, mac);
12781
12782 if (dut->set_macaddr) {
12783 char buf[128];
12784 int res;
12785 if (strcasecmp(mac, "default") == 0) {
12786 res = snprintf(buf, sizeof(buf), "%s",
12787 dut->set_macaddr);
12788 dut->tmp_mac_addr = 0;
12789 } else {
12790 res = snprintf(buf, sizeof(buf), "%s %s",
12791 dut->set_macaddr, mac);
12792 dut->tmp_mac_addr = 1;
12793 }
12794 if (res < 0 || res >= (int) sizeof(buf))
12795 return -1;
12796 if (system(buf) != 0) {
12797 send_resp(dut, conn, SIGMA_ERROR,
12798 "errorCode,Failed to set MAC "
12799 "address");
12800 return 0;
12801 }
12802 return 1;
12803 }
12804
12805 if (strcasecmp(mac, "default") == 0)
12806 return 1;
12807
12808 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
12809 "command");
12810 return 0;
12811}
12812
12813
12814static int iwpriv_tdlsoffchnmode(struct sigma_dut *dut,
12815 struct sigma_conn *conn, const char *intf,
12816 int val)
12817{
12818 char buf[200];
12819 int res;
12820
12821 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchnmode %d",
12822 intf, val);
12823 if (res < 0 || res >= (int) sizeof(buf))
12824 return -1;
12825 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
12826 if (system(buf) != 0) {
12827 send_resp(dut, conn, SIGMA_ERROR,
12828 "errorCode,Failed to configure offchannel mode");
12829 return 0;
12830 }
12831
12832 return 1;
12833}
12834
12835
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012836static int off_chan_val(enum sec_ch_offset off)
12837{
12838 switch (off) {
12839 case SEC_CH_NO:
12840 return 0;
12841 case SEC_CH_40ABOVE:
12842 return 40;
12843 case SEC_CH_40BELOW:
12844 return -40;
12845 }
12846
12847 return 0;
12848}
12849
12850
12851static int iwpriv_set_offchan(struct sigma_dut *dut, struct sigma_conn *conn,
12852 const char *intf, int off_ch_num,
12853 enum sec_ch_offset sec)
12854{
12855 char buf[200];
12856 int res;
12857
12858 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchan %d",
12859 intf, off_ch_num);
12860 if (res < 0 || res >= (int) sizeof(buf))
12861 return -1;
12862 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
12863 if (system(buf) != 0) {
12864 send_resp(dut, conn, SIGMA_ERROR,
12865 "errorCode,Failed to set offchan");
12866 return 0;
12867 }
12868
12869 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsecchnoffst %d",
12870 intf, off_chan_val(sec));
12871 if (res < 0 || res >= (int) sizeof(buf))
12872 return -1;
12873 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
12874 if (system(buf) != 0) {
12875 send_resp(dut, conn, SIGMA_ERROR,
12876 "errorCode,Failed to set sec chan offset");
12877 return 0;
12878 }
12879
12880 return 1;
12881}
12882
12883
12884static int tdls_set_offchannel_offset(struct sigma_dut *dut,
12885 struct sigma_conn *conn,
12886 const char *intf, int off_ch_num,
12887 enum sec_ch_offset sec)
12888{
12889 char buf[200];
12890 int res;
12891
12892 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNEL %d",
12893 off_ch_num);
12894 if (res < 0 || res >= (int) sizeof(buf))
12895 return -1;
12896 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
12897
12898 if (wpa_command(intf, buf) < 0) {
12899 send_resp(dut, conn, SIGMA_ERROR,
12900 "ErrorCode,Failed to set offchan");
12901 return 0;
12902 }
12903 res = snprintf(buf, sizeof(buf), "DRIVER TDLSSECONDARYCHANNELOFFSET %d",
12904 off_chan_val(sec));
12905 if (res < 0 || res >= (int) sizeof(buf))
12906 return -1;
12907
12908 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
12909
12910 if (wpa_command(intf, buf) < 0) {
12911 send_resp(dut, conn, SIGMA_ERROR,
12912 "ErrorCode,Failed to set sec chan offset");
12913 return 0;
12914 }
12915
12916 return 1;
12917}
12918
12919
12920static int tdls_set_offchannel_mode(struct sigma_dut *dut,
12921 struct sigma_conn *conn,
12922 const char *intf, int val)
12923{
12924 char buf[200];
12925 int res;
12926
12927 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNELMODE %d",
12928 val);
12929 if (res < 0 || res >= (int) sizeof(buf))
12930 return -1;
12931 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
12932
12933 if (wpa_command(intf, buf) < 0) {
12934 send_resp(dut, conn, SIGMA_ERROR,
12935 "ErrorCode,Failed to configure offchannel mode");
12936 return 0;
12937 }
12938
12939 return 1;
12940}
12941
12942
12943static int cmd_sta_set_rfeature_tdls(const char *intf, struct sigma_dut *dut,
12944 struct sigma_conn *conn,
12945 struct sigma_cmd *cmd)
12946{
12947 const char *val;
12948 enum {
12949 CHSM_NOT_SET,
12950 CHSM_ENABLE,
12951 CHSM_DISABLE,
12952 CHSM_REJREQ,
12953 CHSM_UNSOLRESP
12954 } chsm = CHSM_NOT_SET;
12955 int off_ch_num = -1;
12956 enum sec_ch_offset sec_ch = SEC_CH_NO;
12957 int res;
12958
12959 val = get_param(cmd, "Uapsd");
12960 if (val) {
12961 char buf[100];
12962 if (strcasecmp(val, "Enable") == 0)
12963 snprintf(buf, sizeof(buf), "SET ps 99");
12964 else if (strcasecmp(val, "Disable") == 0)
12965 snprintf(buf, sizeof(buf), "SET ps 98");
12966 else {
12967 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
12968 "Unsupported uapsd parameter value");
12969 return 0;
12970 }
12971 if (wpa_command(intf, buf)) {
12972 send_resp(dut, conn, SIGMA_ERROR,
12973 "ErrorCode,Failed to change U-APSD "
12974 "powersave mode");
12975 return 0;
12976 }
12977 }
12978
12979 val = get_param(cmd, "TPKTIMER");
12980 if (val && strcasecmp(val, "DISABLE") == 0) {
12981 if (wpa_command(intf, "SET tdls_testing 0x100")) {
12982 send_resp(dut, conn, SIGMA_ERROR,
12983 "ErrorCode,Failed to enable no TPK "
12984 "expiration test mode");
12985 return 0;
12986 }
12987 dut->no_tpk_expiration = 1;
12988 }
12989
12990 val = get_param(cmd, "ChSwitchMode");
12991 if (val) {
12992 if (strcasecmp(val, "Enable") == 0 ||
12993 strcasecmp(val, "Initiate") == 0)
12994 chsm = CHSM_ENABLE;
12995 else if (strcasecmp(val, "Disable") == 0 ||
12996 strcasecmp(val, "passive") == 0)
12997 chsm = CHSM_DISABLE;
12998 else if (strcasecmp(val, "RejReq") == 0)
12999 chsm = CHSM_REJREQ;
13000 else if (strcasecmp(val, "UnSolResp") == 0)
13001 chsm = CHSM_UNSOLRESP;
13002 else {
13003 send_resp(dut, conn, SIGMA_ERROR,
13004 "ErrorCode,Unknown ChSwitchMode value");
13005 return 0;
13006 }
13007 }
13008
13009 val = get_param(cmd, "OffChNum");
13010 if (val) {
13011 off_ch_num = atoi(val);
13012 if (off_ch_num == 0) {
13013 send_resp(dut, conn, SIGMA_ERROR,
13014 "ErrorCode,Invalid OffChNum");
13015 return 0;
13016 }
13017 }
13018
13019 val = get_param(cmd, "SecChOffset");
13020 if (val) {
13021 if (strcmp(val, "20") == 0)
13022 sec_ch = SEC_CH_NO;
13023 else if (strcasecmp(val, "40above") == 0)
13024 sec_ch = SEC_CH_40ABOVE;
13025 else if (strcasecmp(val, "40below") == 0)
13026 sec_ch = SEC_CH_40BELOW;
13027 else {
13028 send_resp(dut, conn, SIGMA_ERROR,
13029 "ErrorCode,Unknown SecChOffset value");
13030 return 0;
13031 }
13032 }
13033
13034 if (chsm == CHSM_NOT_SET) {
13035 /* no offchannel changes requested */
13036 return 1;
13037 }
13038
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013039 if (strcmp(intf, get_main_ifname(dut)) != 0 &&
13040 strcmp(intf, get_station_ifname(dut)) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013041 send_resp(dut, conn, SIGMA_ERROR,
13042 "ErrorCode,Unknown interface");
13043 return 0;
13044 }
13045
13046 switch (chsm) {
13047 case CHSM_NOT_SET:
Jouni Malinen280f5ba2016-08-29 21:33:10 +030013048 res = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013049 break;
13050 case CHSM_ENABLE:
13051 if (off_ch_num < 0) {
13052 send_resp(dut, conn, SIGMA_ERROR,
13053 "ErrorCode,Missing OffChNum argument");
13054 return 0;
13055 }
13056 if (wifi_chip_type == DRIVER_WCN) {
13057 res = tdls_set_offchannel_offset(dut, conn, intf,
13058 off_ch_num, sec_ch);
13059 } else {
13060 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
13061 sec_ch);
13062 }
13063 if (res != 1)
13064 return res;
13065 if (wifi_chip_type == DRIVER_WCN)
13066 res = tdls_set_offchannel_mode(dut, conn, intf, 1);
13067 else
13068 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 1);
13069 break;
13070 case CHSM_DISABLE:
13071 if (wifi_chip_type == DRIVER_WCN)
13072 res = tdls_set_offchannel_mode(dut, conn, intf, 2);
13073 else
13074 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 2);
13075 break;
13076 case CHSM_REJREQ:
13077 if (wifi_chip_type == DRIVER_WCN)
13078 res = tdls_set_offchannel_mode(dut, conn, intf, 3);
13079 else
13080 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 3);
13081 break;
13082 case CHSM_UNSOLRESP:
13083 if (off_ch_num < 0) {
13084 send_resp(dut, conn, SIGMA_ERROR,
13085 "ErrorCode,Missing OffChNum argument");
13086 return 0;
13087 }
13088 if (wifi_chip_type == DRIVER_WCN) {
13089 res = tdls_set_offchannel_offset(dut, conn, intf,
13090 off_ch_num, sec_ch);
13091 } else {
13092 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
13093 sec_ch);
13094 }
13095 if (res != 1)
13096 return res;
13097 if (wifi_chip_type == DRIVER_WCN)
13098 res = tdls_set_offchannel_mode(dut, conn, intf, 4);
13099 else
13100 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 4);
13101 break;
13102 }
13103
13104 return res;
13105}
13106
13107
13108static int ath_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
13109 struct sigma_conn *conn,
13110 struct sigma_cmd *cmd)
13111{
13112 const char *val;
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053013113 char *token = NULL, *result;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013114
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -070013115 novap_reset(dut, intf, 1);
priyadharshini gowthamane5e25172015-12-08 14:53:48 -080013116
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013117 val = get_param(cmd, "nss_mcs_opt");
13118 if (val) {
13119 /* String (nss_operating_mode; mcs_operating_mode) */
13120 int nss, mcs;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053013121 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013122
13123 token = strdup(val);
13124 if (!token)
13125 return 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053013126 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053013127 if (!result) {
13128 sigma_dut_print(dut, DUT_MSG_ERROR,
13129 "VHT NSS not specified");
13130 goto failed;
13131 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013132 if (strcasecmp(result, "def") != 0) {
13133 nss = atoi(result);
13134 if (nss == 4)
13135 ath_disable_txbf(dut, intf);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070013136 if (run_iwpriv(dut, intf, "nss %d", nss) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013137 goto failed;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070013138
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013139 }
13140
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053013141 result = strtok_r(NULL, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053013142 if (!result) {
13143 sigma_dut_print(dut, DUT_MSG_ERROR,
13144 "VHT MCS not specified");
13145 goto failed;
13146 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013147 if (strcasecmp(result, "def") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070013148 if (run_iwpriv(dut, intf, "set11NRates 0") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013149 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013150 } else {
13151 mcs = atoi(result);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070013152 if (run_iwpriv(dut, intf, "vhtmcs %d", mcs) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013153 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013154 }
13155 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070013156 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013157 }
13158
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053013159 free(token);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013160 return 1;
13161failed:
13162 free(token);
13163 return 0;
13164}
13165
13166
13167static int cmd_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
13168 struct sigma_conn *conn,
13169 struct sigma_cmd *cmd)
13170{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013171 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013172 case DRIVER_ATHEROS:
13173 return ath_sta_set_rfeature_vht(intf, dut, conn, cmd);
13174 default:
13175 send_resp(dut, conn, SIGMA_ERROR,
13176 "errorCode,Unsupported sta_set_rfeature(VHT) with the current driver");
13177 return 0;
13178 }
13179}
13180
13181
Jouni Malinen1702fe32021-06-08 19:08:01 +030013182static enum sigma_cmd_result
13183wcn_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
13184 struct sigma_conn *conn, struct sigma_cmd *cmd)
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080013185{
13186 const char *val;
13187 char *token = NULL, *result;
13188 char buf[60];
13189
13190 val = get_param(cmd, "nss_mcs_opt");
13191 if (val) {
13192 /* String (nss_operating_mode; mcs_operating_mode) */
13193 int nss, mcs, ratecode;
13194 char *saveptr;
13195
13196 token = strdup(val);
13197 if (!token)
Jouni Malinen1702fe32021-06-08 19:08:01 +030013198 return ERROR_SEND_STATUS;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080013199
13200 result = strtok_r(token, ";", &saveptr);
13201 if (!result) {
13202 sigma_dut_print(dut, DUT_MSG_ERROR,
13203 "HE NSS not specified");
13204 goto failed;
13205 }
13206 nss = 1;
13207 if (strcasecmp(result, "def") != 0)
13208 nss = atoi(result);
13209
13210 result = strtok_r(NULL, ";", &saveptr);
13211 if (!result) {
13212 sigma_dut_print(dut, DUT_MSG_ERROR,
13213 "HE MCS not specified");
13214 goto failed;
13215 }
13216 mcs = 7;
13217 if (strcasecmp(result, "def") != 0)
13218 mcs = atoi(result);
13219
Arif Hussain557bf412018-05-25 17:29:36 -070013220 ratecode = 0x20; /* for nss:1 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080013221 if (nss == 2) {
Arif Hussain557bf412018-05-25 17:29:36 -070013222 ratecode = 0x40; /* for nss:2 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080013223 } else if (nss > 2) {
13224 sigma_dut_print(dut, DUT_MSG_ERROR,
13225 "HE NSS %d not supported", nss);
13226 goto failed;
13227 }
13228
Arif Hussain557bf412018-05-25 17:29:36 -070013229 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss);
13230 if (system(buf) != 0) {
13231 sigma_dut_print(dut, DUT_MSG_ERROR,
13232 "nss_mcs_opt: iwpriv %s nss %d failed",
13233 intf, nss);
13234 goto failed;
13235 }
Arif Hussainac6c5112018-05-25 17:34:00 -070013236 dut->sta_nss = nss;
Arif Hussain557bf412018-05-25 17:29:36 -070013237
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080013238 /* Add the MCS to the ratecode */
13239 if (mcs >= 0 && mcs <= 11) {
13240 ratecode += mcs;
Arif Hussain557bf412018-05-25 17:29:36 -070013241#ifdef NL80211_SUPPORT
13242 if (dut->device_type == STA_testbed) {
13243 enum he_mcs_config mcs_config;
13244 int ret;
13245
13246 if (mcs <= 7)
13247 mcs_config = HE_80_MCS0_7;
13248 else if (mcs <= 9)
13249 mcs_config = HE_80_MCS0_9;
13250 else
13251 mcs_config = HE_80_MCS0_11;
13252 ret = sta_set_he_mcs(dut, intf, mcs_config);
13253 if (ret) {
13254 sigma_dut_print(dut, DUT_MSG_ERROR,
13255 "nss_mcs_opt: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
13256 mcs, mcs_config, ret);
13257 goto failed;
13258 }
13259 }
13260#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080013261 } else {
13262 sigma_dut_print(dut, DUT_MSG_ERROR,
13263 "HE MCS %d not supported", mcs);
13264 goto failed;
13265 }
13266 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0x%03x",
13267 intf, ratecode);
13268 if (system(buf) != 0) {
13269 sigma_dut_print(dut, DUT_MSG_ERROR,
13270 "iwpriv setting of 11ax rates failed");
13271 goto failed;
13272 }
13273 free(token);
13274 }
13275
13276 val = get_param(cmd, "GI");
13277 if (val) {
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080013278 int fix_rate_sgi;
13279
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080013280 if (strcmp(val, "0.8") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070013281 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 9", intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080013282 fix_rate_sgi = 1;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080013283 } else if (strcmp(val, "1.6") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070013284 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 10",
13285 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080013286 fix_rate_sgi = 2;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080013287 } else if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070013288 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 11",
13289 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080013290 fix_rate_sgi = 3;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080013291 } else {
13292 send_resp(dut, conn, SIGMA_ERROR,
13293 "errorCode,GI value not supported");
Jouni Malinen1702fe32021-06-08 19:08:01 +030013294 return STATUS_SENT_ERROR;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080013295 }
13296 if (system(buf) != 0) {
13297 send_resp(dut, conn, SIGMA_ERROR,
13298 "errorCode,Failed to set shortgi");
Jouni Malinen1702fe32021-06-08 19:08:01 +030013299 return STATUS_SENT_ERROR;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080013300 }
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080013301 snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d",
13302 intf, fix_rate_sgi);
13303 if (system(buf) != 0) {
13304 send_resp(dut, conn, SIGMA_ERROR,
13305 "errorCode,Failed to set fix rate shortgi");
Jouni Malinen1702fe32021-06-08 19:08:01 +030013306 return STATUS_SENT_ERROR;
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080013307 }
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080013308 }
13309
Subhani Shaik8e7a3052018-04-24 14:03:00 -070013310 val = get_param(cmd, "LTF");
13311 if (val) {
13312#ifdef NL80211_SUPPORT
13313 if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080013314 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_1X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070013315 } if (strcmp(val, "6.4") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080013316 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_2X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070013317 } else if (strcmp(val, "12.8") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080013318 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_4X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070013319 } else {
13320 send_resp(dut, conn, SIGMA_ERROR,
13321 "errorCode, LTF value not supported");
Jouni Malinen1702fe32021-06-08 19:08:01 +030013322 return STATUS_SENT_ERROR;
Subhani Shaik8e7a3052018-04-24 14:03:00 -070013323 }
13324#else /* NL80211_SUPPORT */
13325 sigma_dut_print(dut, DUT_MSG_ERROR,
13326 "LTF cannot be set without NL80211_SUPPORT defined");
Jouni Malinen1702fe32021-06-08 19:08:01 +030013327 return ERROR_SEND_STATUS;
Subhani Shaik8e7a3052018-04-24 14:03:00 -070013328#endif /* NL80211_SUPPORT */
13329 }
13330
Kiran Kumar Lokere1809da12021-06-24 00:45:38 -070013331 val = get_param(cmd, "KeepAlive");
13332 if (val) {
13333 int set_val = QCA_WLAN_KEEP_ALIVE_DEFAULT;
13334
13335 if (strcasecmp(val, "Data") == 0)
13336 set_val = QCA_WLAN_KEEP_ALIVE_DATA;
13337 else if (strcasecmp(val, "Mgmt") == 0)
13338 set_val = QCA_WLAN_KEEP_ALIVE_MGMT;
13339
13340 if (sta_set_keep_alive_data_cfg(dut, intf, set_val)) {
13341 send_resp(dut, conn, SIGMA_ERROR,
13342 "ErrorCode,Failed to set keep alive type config");
13343 return STATUS_SENT_ERROR;
13344 }
13345 }
13346
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -070013347 val = get_param(cmd, "TxSUPPDU");
13348 if (val) {
13349 int set_val = 1;
13350
13351 if (strcasecmp(val, "Enable") == 0)
13352 set_val = 1;
13353 else if (strcasecmp(val, "Disable") == 0)
13354 set_val = 0;
13355
13356 if (sta_set_tx_su_ppdu_cfg(dut, intf, set_val)) {
13357 send_resp(dut, conn, SIGMA_ERROR,
13358 "ErrorCode,Failed to set Tx SU PPDU config");
Jouni Malinen1702fe32021-06-08 19:08:01 +030013359 return STATUS_SENT_ERROR;
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -070013360 }
13361 }
13362
Kiran Kumar Lokere54b72522021-04-01 00:22:44 -070013363 val = get_param(cmd, "Mgmt_Data_TX_Resp_Frame");
13364 if (val) {
13365 int set_val = 0;
13366
13367 if (strcasecmp(val, "Enable") == 0)
13368 set_val = 0;
13369 else if (strcasecmp(val, "Disable") == 0)
13370 set_val = 1;
13371
13372 if (sta_set_mgmt_data_tx_disable_cfg(dut, intf, set_val)) {
13373 send_resp(dut, conn, SIGMA_ERROR,
13374 "ErrorCode,Failed to set mgmt/data Tx disable config");
13375 return STATUS_SENT_ERROR;
13376 }
13377 }
13378
Arif Hussain480d5f42019-03-12 14:40:42 -070013379 val = get_param(cmd, "TWT_Setup");
13380 if (val) {
13381 if (strcasecmp(val, "Request") == 0) {
13382 if (sta_twt_request(dut, conn, cmd)) {
13383 send_resp(dut, conn, SIGMA_ERROR,
Srinivas Girigowda6707f032020-10-26 15:24:46 -070013384 "ErrorCode,TWT setup failed");
Jouni Malinen1702fe32021-06-08 19:08:01 +030013385 return STATUS_SENT_ERROR;
Arif Hussain480d5f42019-03-12 14:40:42 -070013386 }
13387 } else if (strcasecmp(val, "Teardown") == 0) {
13388 if (sta_twt_teardown(dut, conn, cmd)) {
13389 send_resp(dut, conn, SIGMA_ERROR,
Srinivas Girigowda6707f032020-10-26 15:24:46 -070013390 "ErrorCode,TWT teardown failed");
Jouni Malinen1702fe32021-06-08 19:08:01 +030013391 return STATUS_SENT_ERROR;
Arif Hussain480d5f42019-03-12 14:40:42 -070013392 }
13393 }
13394 }
13395
Srinivas Girigowda6707f032020-10-26 15:24:46 -070013396 val = get_param(cmd, "TWT_Operation");
13397 if (val) {
13398 if (strcasecmp(val, "Suspend") == 0) {
13399 if (sta_twt_suspend_or_nudge(dut, conn, cmd)) {
13400 send_resp(dut, conn, SIGMA_ERROR,
13401 "ErrorCode,TWT suspend failed");
13402 return STATUS_SENT_ERROR;
13403 }
13404 } else if (strcasecmp(val, "Resume") == 0) {
13405 if (sta_twt_resume(dut, conn, cmd)) {
13406 send_resp(dut, conn, SIGMA_ERROR,
13407 "ErrorCode,TWT resume failed");
13408 return STATUS_SENT_ERROR;
13409 }
13410 }
13411 }
13412
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -080013413 val = get_param(cmd, "transmitOMI");
13414 if (val && sta_transmit_omi(dut, conn, cmd)) {
13415 send_resp(dut, conn, SIGMA_ERROR,
13416 "ErrorCode,sta_transmit_omi failed");
Jouni Malinen1702fe32021-06-08 19:08:01 +030013417 return STATUS_SENT_ERROR;
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -070013418 }
13419
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080013420 val = get_param(cmd, "Powersave");
13421 if (val) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053013422 int ps;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080013423
13424 if (strcasecmp(val, "off") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053013425 ps = 2;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080013426 } else if (strcasecmp(val, "on") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053013427 ps = 1;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080013428 } else {
13429 sigma_dut_print(dut, DUT_MSG_ERROR,
13430 "Unsupported Powersave value '%s'",
13431 val);
Jouni Malinen1702fe32021-06-08 19:08:01 +030013432 return INVALID_SEND_STATUS;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080013433 }
Vinita S. Malooa8b62722020-04-23 01:45:41 +053013434 if (set_power_save_wcn(dut, intf, ps) < 0)
Jouni Malinen1702fe32021-06-08 19:08:01 +030013435 return ERROR_SEND_STATUS;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080013436 }
13437
Kiran Kumar Lokere2c4b7ce2019-01-30 12:02:28 -080013438 val = get_param(cmd, "MU_EDCA");
13439 if (val) {
13440 if (strcasecmp(val, "Override") == 0) {
13441 if (sta_set_mu_edca_override(dut, intf, 1)) {
13442 send_resp(dut, conn, SIGMA_ERROR,
13443 "errorCode,MU EDCA override set failed");
13444 return STATUS_SENT;
13445 }
13446 } else if (strcasecmp(val, "Disable") == 0) {
13447 if (sta_set_mu_edca_override(dut, intf, 0)) {
13448 send_resp(dut, conn, SIGMA_ERROR,
13449 "errorCode,MU EDCA override disable failed");
13450 return STATUS_SENT;
13451 }
13452 }
13453 }
13454
Kiran Kumar Lokerefa7c7b92021-08-09 00:50:55 -070013455 val = get_param(cmd, "RUAllocTone");
13456 if (val && strcasecmp(val, "242") == 0) {
13457 if (sta_set_ru_242_tone_tx(dut, intf, 1)) {
13458 send_resp(dut, conn, SIGMA_ERROR,
13459 "ErrorCode,Failed to set RU 242 tone Tx");
13460 return STATUS_SENT_ERROR;
13461 }
13462 }
13463
13464 val = get_param(cmd, "PPDUTxType");
13465 if (val && strcasecmp(val, "ER-SU") == 0) {
13466 if (sta_set_er_su_ppdu_type_tx(dut, intf, 1)) {
13467 send_resp(dut, conn, SIGMA_ERROR,
13468 "ErrorCode,Failed to set ER-SU PPDU type Tx");
13469 return STATUS_SENT_ERROR;
13470 }
13471 }
13472
Kiran Kumar Lokeredd086642020-06-04 00:29:26 -070013473 val = get_param(cmd, "Ch_Pref");
13474 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
13475 return STATUS_SENT;
13476
13477 val = get_param(cmd, "Cellular_Data_Cap");
13478 if (val && mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
13479 return STATUS_SENT;
13480
Jouni Malinen1702fe32021-06-08 19:08:01 +030013481 return SUCCESS_SEND_STATUS;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080013482
13483failed:
13484 free(token);
Jouni Malinen1702fe32021-06-08 19:08:01 +030013485 return ERROR_SEND_STATUS;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080013486}
13487
13488
Jouni Malinen1702fe32021-06-08 19:08:01 +030013489static enum sigma_cmd_result
13490cmd_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
13491 struct sigma_conn *conn, struct sigma_cmd *cmd)
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080013492{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013493 switch (get_driver_type(dut)) {
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080013494 case DRIVER_WCN:
13495 return wcn_sta_set_rfeature_he(intf, dut, conn, cmd);
13496 default:
13497 send_resp(dut, conn, SIGMA_ERROR,
13498 "errorCode,Unsupported sta_set_rfeature(HE) with the current driver");
Jouni Malinen1702fe32021-06-08 19:08:01 +030013499 return STATUS_SENT_ERROR;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080013500 }
13501}
13502
13503
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080013504static int cmd_sta_set_power_save_he(const char *intf, struct sigma_dut *dut,
13505 struct sigma_conn *conn,
13506 struct sigma_cmd *cmd)
13507{
13508 const char *val;
13509
13510 val = get_param(cmd, "powersave");
13511 if (val) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053013512 int ps;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080013513
13514 if (strcasecmp(val, "off") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053013515 ps = 2;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080013516 } else if (strcasecmp(val, "on") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053013517 ps = 1;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080013518 } else {
13519 sigma_dut_print(dut, DUT_MSG_ERROR,
13520 "Unsupported power save config");
13521 return -1;
13522 }
Vinita S. Malooa8b62722020-04-23 01:45:41 +053013523 if (set_power_save_wcn(dut, intf, ps) < 0)
13524 return 0;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080013525 return 1;
13526 }
13527
13528 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported command");
13529
13530 return 0;
13531}
13532
13533
Ashwini Patil5acd7382017-04-13 15:55:04 +053013534static int btm_query_candidate_list(struct sigma_dut *dut,
13535 struct sigma_conn *conn,
13536 struct sigma_cmd *cmd)
13537{
13538 const char *bssid, *info, *op_class, *ch, *phy_type, *pref;
13539 int len, ret;
13540 char buf[10];
13541
13542 /*
13543 * Neighbor Report elements format:
13544 * neighbor=<BSSID>,<BSSID Information>,<Operating Class>,
13545 * <Channel Number>,<PHY Type>[,<hexdump of Optional Subelements>]
13546 * eg: neighbor=aa:bb:cc:dd:ee:ff,17,81,6,1,030101
13547 */
13548
13549 bssid = get_param(cmd, "Nebor_BSSID");
13550 if (!bssid) {
13551 send_resp(dut, conn, SIGMA_INVALID,
13552 "errorCode,Nebor_BSSID is missing");
13553 return 0;
13554 }
13555
13556 info = get_param(cmd, "Nebor_Bssid_Info");
13557 if (!info) {
13558 sigma_dut_print(dut, DUT_MSG_INFO,
13559 "Using default value for Nebor_Bssid_Info: %s",
13560 DEFAULT_NEIGHBOR_BSSID_INFO);
13561 info = DEFAULT_NEIGHBOR_BSSID_INFO;
13562 }
13563
13564 op_class = get_param(cmd, "Nebor_Op_Class");
13565 if (!op_class) {
13566 send_resp(dut, conn, SIGMA_INVALID,
13567 "errorCode,Nebor_Op_Class is missing");
13568 return 0;
13569 }
13570
13571 ch = get_param(cmd, "Nebor_Op_Ch");
13572 if (!ch) {
13573 send_resp(dut, conn, SIGMA_INVALID,
13574 "errorCode,Nebor_Op_Ch is missing");
13575 return 0;
13576 }
13577
13578 phy_type = get_param(cmd, "Nebor_Phy_Type");
13579 if (!phy_type) {
13580 sigma_dut_print(dut, DUT_MSG_INFO,
13581 "Using default value for Nebor_Phy_Type: %s",
13582 DEFAULT_NEIGHBOR_PHY_TYPE);
13583 phy_type = DEFAULT_NEIGHBOR_PHY_TYPE;
13584 }
13585
13586 /* Parse optional subelements */
13587 buf[0] = '\0';
13588 pref = get_param(cmd, "Nebor_Pref");
13589 if (pref) {
13590 /* hexdump for preferrence subelement */
13591 ret = snprintf(buf, sizeof(buf), ",0301%02x", atoi(pref));
13592 if (ret < 0 || ret >= (int) sizeof(buf)) {
13593 sigma_dut_print(dut, DUT_MSG_ERROR,
13594 "snprintf failed for optional subelement ret: %d",
13595 ret);
13596 send_resp(dut, conn, SIGMA_ERROR,
13597 "errorCode,snprintf failed for subelement");
13598 return 0;
13599 }
13600 }
13601
13602 if (!dut->btm_query_cand_list) {
13603 dut->btm_query_cand_list = calloc(1, NEIGHBOR_REPORT_SIZE);
13604 if (!dut->btm_query_cand_list) {
13605 send_resp(dut, conn, SIGMA_ERROR,
13606 "errorCode,Failed to allocate memory for btm_query_cand_list");
13607 return 0;
13608 }
13609 }
13610
13611 len = strlen(dut->btm_query_cand_list);
13612 ret = snprintf(dut->btm_query_cand_list + len,
13613 NEIGHBOR_REPORT_SIZE - len, " neighbor=%s,%s,%s,%s,%s%s",
13614 bssid, info, op_class, ch, phy_type, buf);
13615 if (ret < 0 || ret >= NEIGHBOR_REPORT_SIZE - len) {
13616 sigma_dut_print(dut, DUT_MSG_ERROR,
13617 "snprintf failed for neighbor report list ret: %d",
13618 ret);
13619 send_resp(dut, conn, SIGMA_ERROR,
13620 "errorCode,snprintf failed for neighbor report");
13621 free(dut->btm_query_cand_list);
13622 dut->btm_query_cand_list = NULL;
13623 return 0;
13624 }
13625
13626 return 1;
13627}
13628
13629
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020013630int sta_extract_60g_ese(struct sigma_dut *dut, struct sigma_cmd *cmd,
13631 struct sigma_ese_alloc *allocs, int *allocs_size)
13632{
13633 int max_count = *allocs_size;
13634 int count = 0, i;
13635 const char *val;
13636
13637 do {
13638 val = get_param_indexed(cmd, "AllocID", count);
13639 if (val)
13640 count++;
13641 } while (val);
13642
13643 if (count == 0 || count > max_count) {
13644 sigma_dut_print(dut, DUT_MSG_ERROR,
13645 "Invalid number of allocations(%d)", count);
13646 return -1;
13647 }
13648
13649 for (i = 0; i < count; i++) {
13650 val = get_param_indexed(cmd, "PercentBI", i);
13651 if (!val) {
13652 sigma_dut_print(dut, DUT_MSG_ERROR,
13653 "Missing PercentBI parameter at index %d",
13654 i);
13655 return -1;
13656 }
13657 allocs[i].percent_bi = atoi(val);
13658
13659 val = get_param_indexed(cmd, "SrcAID", i);
13660 if (val)
13661 allocs[i].src_aid = strtol(val, NULL, 0);
13662 else
13663 allocs[i].src_aid = ESE_BCAST_AID;
13664
13665 val = get_param_indexed(cmd, "DestAID", i);
13666 if (val)
13667 allocs[i].dst_aid = strtol(val, NULL, 0);
13668 else
13669 allocs[i].dst_aid = ESE_BCAST_AID;
13670
13671 allocs[i].type = ESE_CBAP;
13672 sigma_dut_print(dut, DUT_MSG_INFO,
13673 "Alloc %d PercentBI %d SrcAID %d DstAID %d",
13674 i, allocs[i].percent_bi, allocs[i].src_aid,
13675 allocs[i].dst_aid);
13676 }
13677
13678 *allocs_size = count;
13679 return 0;
13680}
13681
13682
13683static int sta_set_60g_ese(struct sigma_dut *dut, int count,
13684 struct sigma_ese_alloc *allocs)
13685{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013686 switch (get_driver_type(dut)) {
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020013687#ifdef __linux__
13688 case DRIVER_WIL6210:
13689 if (wil6210_set_ese(dut, count, allocs))
13690 return -1;
13691 return 1;
13692#endif /* __linux__ */
13693 default:
13694 sigma_dut_print(dut, DUT_MSG_ERROR,
13695 "Unsupported sta_set_60g_ese with the current driver");
13696 return -1;
13697 }
13698}
13699
13700
13701static int cmd_sta_set_rfeature_60g(const char *intf, struct sigma_dut *dut,
13702 struct sigma_conn *conn,
13703 struct sigma_cmd *cmd)
13704{
13705 const char *val;
13706
13707 val = get_param(cmd, "ExtSchIE");
13708 if (val && !strcasecmp(val, "Enable")) {
13709 struct sigma_ese_alloc allocs[MAX_ESE_ALLOCS];
13710 int count = MAX_ESE_ALLOCS;
13711
13712 if (sta_extract_60g_ese(dut, cmd, allocs, &count))
13713 return -1;
13714 return sta_set_60g_ese(dut, count, allocs);
13715 }
13716
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020013717 val = get_param(cmd, "MCS_FixedRate");
13718 if (val) {
13719 int sta_mcs = atoi(val);
13720
13721 sigma_dut_print(dut, DUT_MSG_INFO, "Force STA MCS to %d",
13722 sta_mcs);
13723 wil6210_set_force_mcs(dut, 1, sta_mcs);
13724
Jouni Malinen0e29cf22019-02-19 01:13:21 +020013725 return SUCCESS_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020013726 }
13727
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020013728 send_resp(dut, conn, SIGMA_ERROR,
13729 "errorCode,Invalid sta_set_rfeature(60G)");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020013730 return STATUS_SENT;
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020013731}
13732
13733
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053013734static int wcn_sta_override_oci(struct sigma_dut *dut, const char *intf,
13735 const char *oci_frametype, uint32_t oci_freq)
13736{
13737#ifdef NL80211_SUPPORT
13738 struct nl_msg *msg;
13739 int ret = 0;
13740 struct nlattr *params;
13741 struct nlattr *attr;
13742 int ifindex;
13743 u8 frame_type;
13744
13745 ifindex = if_nametoindex(intf);
13746 if (ifindex == 0) {
13747 sigma_dut_print(dut, DUT_MSG_ERROR,
13748 "%s: Index for interface %s failed",
13749 __func__, intf);
13750 return -1;
13751 }
13752
13753 if (strcasecmp(oci_frametype, "SAQueryReq") == 0) {
13754 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_SA_QUERY_REQ;
13755 } else if (strcasecmp(oci_frametype, "SAQueryResp") == 0) {
13756 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_SA_QUERY_RESP;
13757 } else if (strcasecmp(oci_frametype, "Reassocreq") == 0) {
13758 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_FT_REASSOC_REQ;
13759 } else {
13760 sigma_dut_print(dut, DUT_MSG_ERROR, "%s: Unknown frametype %s",
13761 __func__, oci_frametype);
13762 return -1;
13763 }
13764
13765
13766 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
13767 NL80211_CMD_VENDOR)) ||
13768 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
13769 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
13770 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
13771 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
13772 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
13773 !(params = nla_nest_start(
13774 msg,
13775 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_OCI_OVERRIDE)) ||
13776 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_OCI_OVERRIDE_FRAME_TYPE,
13777 frame_type) ||
13778 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_OCI_OVERRIDE_FREQUENCY,
13779 oci_freq)) {
13780 sigma_dut_print(dut, DUT_MSG_ERROR,
13781 "%s: err in adding vendor_cmd and vendor_data",
13782 __func__);
13783 nlmsg_free(msg);
13784 return -1;
13785 }
13786 nla_nest_end(msg, params);
13787 nla_nest_end(msg, attr);
13788
13789 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
13790 if (ret) {
13791 sigma_dut_print(dut, DUT_MSG_ERROR,
13792 "%s: err in send_and_recv_msgs, ret=%d",
13793 __func__, ret);
13794 }
13795 return ret;
13796#else /* NL80211_SUPPORT */
13797 sigma_dut_print(dut, DUT_MSG_ERROR,
13798 "OCI override not possible without NL80211_SUPPORT defined");
13799 return -1;
13800#endif /* NL80211_SUPPORT */
13801}
13802
13803
Veerendranath Jakkam50d5c782020-07-22 01:59:01 +053013804static int wcn_sta_ignore_csa(struct sigma_dut *dut, const char *intf,
13805 uint8_t ignore_csa)
13806{
13807#ifdef NL80211_SUPPORT
13808 return wcn_wifi_test_config_set_u8(
13809 dut, intf,
13810 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_IGNORE_CSA, ignore_csa);
13811#else /* NL80211_SUPPORT */
13812 sigma_dut_print(dut, DUT_MSG_ERROR,
13813 "IgnoreCSA can't be set without NL80211_SUPPORT defined");
13814 return -1;
13815#endif /* NL80211_SUPPORT */
13816}
13817
13818
Veerendranath Jakkamc771fac2020-07-22 01:32:56 +053013819static int wcn_sta_set_rsnxe_used(struct sigma_dut *dut, const char *intf,
13820 uint8_t rsnxe_used)
13821{
13822#ifdef NL80211_SUPPORT
13823 return wcn_wifi_test_config_set_u8(
13824 dut, intf,
13825 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_FT_REASSOCREQ_RSNXE_USED,
13826 rsnxe_used);
13827#else /* NL80211_SUPPORT */
13828 sigma_dut_print(dut, DUT_MSG_ERROR,
13829 "RSNXE_Used can't be set without NL80211_SUPPORT defined");
13830 return -1;
13831#endif /* NL80211_SUPPORT */
13832}
13833
13834
Veerendranath Jakkam1e1e5fd2020-09-10 07:12:37 +053013835static int wcn_sta_ignore_sa_query_timeout(struct sigma_dut *dut,
13836 const char *intf,
13837 uint8_t ignore_sa_query_timeout)
13838{
13839#ifdef NL80211_SUPPORT
13840 return wcn_wifi_test_config_set_u8(
13841 dut, intf,
13842 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_IGNORE_SA_QUERY_TIMEOUT,
13843 ignore_sa_query_timeout);
13844#else /* NL80211_SUPPORT */
13845 sigma_dut_print(dut, DUT_MSG_ERROR,
13846 "Ignore SA Query timeout can't be set without NL80211_SUPPORT defined");
13847 return -1;
13848#endif /* NL80211_SUPPORT */
13849}
13850
13851
Jouni Malinen6250cb02020-04-15 13:54:45 +030013852static enum sigma_cmd_result
13853cmd_sta_set_rfeature_wpa3(const char *intf, struct sigma_dut *dut,
13854 struct sigma_conn *conn,
13855 struct sigma_cmd *cmd)
13856{
Vamsi Krishnad29bc762020-05-08 23:23:30 +053013857 const char *val, *oci_chan, *oci_frametype;
Jouni Malinen6250cb02020-04-15 13:54:45 +030013858
Veerendranath Jakkam30bf9072020-04-16 14:37:57 +053013859 val = get_param(cmd, "ReassocReq_RSNXE_Used");
Jouni Malinen6250cb02020-04-15 13:54:45 +030013860 if (val && atoi(val) == 1) {
Veerendranath Jakkamc771fac2020-07-22 01:32:56 +053013861 if (wifi_chip_type == DRIVER_WCN) {
13862 if (wcn_sta_set_rsnxe_used(dut, intf, 1)) {
13863 send_resp(dut, conn, SIGMA_ERROR,
13864 "errorCode,Failed to set ft_rsnxe_used");
13865 return STATUS_SENT_ERROR;
13866 }
13867 return SUCCESS_SEND_STATUS;
13868 } else if (wpa_command(intf, "SET ft_rsnxe_used 1") < 0) {
Jouni Malinen6250cb02020-04-15 13:54:45 +030013869 send_resp(dut, conn, SIGMA_ERROR,
13870 "errorCode,Failed to set ft_rsnxe_used");
13871 return STATUS_SENT_ERROR;
13872 }
13873 return SUCCESS_SEND_STATUS;
13874 }
Vamsi Krishnad29bc762020-05-08 23:23:30 +053013875
13876 oci_chan = get_param(cmd, "OCIChannel");
13877 oci_frametype = get_param(cmd, "OCIFrameType");
13878 if (oci_chan && oci_frametype) {
13879 unsigned int oci_freq = channel_to_freq(dut, atoi(oci_chan));
13880 char buf[100];
13881
13882 if (!oci_freq) {
13883 send_resp(dut, conn, SIGMA_ERROR,
13884 "errorCode,Invalid OCIChannel number");
13885 return STATUS_SENT_ERROR;
13886 }
13887
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053013888 if (wifi_chip_type == DRIVER_WCN &&
13889 (strcasecmp(oci_frametype, "SAQueryReq") == 0 ||
13890 strcasecmp(oci_frametype, "SAQueryResp") == 0 ||
13891 strcasecmp(oci_frametype, "Reassocreq") == 0)) {
13892 if (wcn_sta_override_oci(dut, intf, oci_frametype,
13893 oci_freq)) {
13894 send_resp(dut, conn, SIGMA_ERROR,
13895 "errorCode,Failed to override OCI");
13896 return STATUS_SENT_ERROR;
13897 }
13898 return SUCCESS_SEND_STATUS;
13899 }
13900
Vamsi Krishnad29bc762020-05-08 23:23:30 +053013901 if (strcasecmp(oci_frametype, "eapolM2") == 0) {
13902 snprintf(buf, sizeof(buf),
13903 "SET oci_freq_override_eapol %d", oci_freq);
13904 } else if (strcasecmp(oci_frametype, "SAQueryReq") == 0) {
13905 snprintf(buf, sizeof(buf),
13906 "SET oci_freq_override_saquery_req %d",
13907 oci_freq);
13908 } else if (strcasecmp(oci_frametype, "SAQueryResp") == 0) {
13909 snprintf(buf, sizeof(buf),
13910 "SET oci_freq_override_saquery_resp %d",
13911 oci_freq);
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053013912 } else if (strcasecmp(oci_frametype, "GrpKeyM2") == 0) {
13913 snprintf(buf, sizeof(buf),
13914 "SET oci_freq_override_eapol_g2 %d",
13915 oci_freq);
13916 } else if (strcasecmp(oci_frametype, "Reassocreq") == 0) {
13917 snprintf(buf, sizeof(buf),
13918 "SET oci_freq_override_ft_assoc %d",
13919 oci_freq);
Vamsi Krishnad29bc762020-05-08 23:23:30 +053013920 } else {
13921 send_resp(dut, conn, SIGMA_ERROR,
13922 "errorCode,Unsupported OCIFrameType");
13923 return STATUS_SENT_ERROR;
13924 }
13925 if (wpa_command(intf, buf) < 0) {
13926 send_resp(dut, conn, SIGMA_ERROR,
13927 "errorCode,Failed to set oci_freq_override");
13928 return STATUS_SENT_ERROR;
13929 }
13930 return SUCCESS_SEND_STATUS;
13931 }
13932
Veerendranath Jakkam50d5c782020-07-22 01:59:01 +053013933 val = get_param(cmd, "IgnoreCSA");
13934 if (val && atoi(val) == 1) {
13935 if (wifi_chip_type == DRIVER_WCN) {
13936 if (wcn_sta_ignore_csa(dut, intf, 1)) {
13937 send_resp(dut, conn, SIGMA_ERROR,
13938 "errorCode,Failed to set ignore CSA");
13939 return STATUS_SENT_ERROR;
13940 }
13941 return SUCCESS_SEND_STATUS;
13942 }
13943 }
13944
Veerendranath Jakkam1e1e5fd2020-09-10 07:12:37 +053013945 val = get_param(cmd, "Deauth_Per_SAQueryResp");
13946 if (val && atoi(val) == 0) {
13947 if (wifi_chip_type == DRIVER_WCN) {
13948 if (wcn_sta_ignore_sa_query_timeout(dut, intf, 1)) {
13949 send_resp(dut, conn, SIGMA_ERROR,
13950 "errorCode,Failed to set ignore SA Query timeout");
13951 return STATUS_SENT_ERROR;
13952 }
13953 return SUCCESS_SEND_STATUS;
13954 }
13955 }
13956
Jouni Malinen6250cb02020-04-15 13:54:45 +030013957 send_resp(dut, conn, SIGMA_ERROR,
13958 "errorCode,Unsupported WPA3 rfeature");
13959 return STATUS_SENT_ERROR;
13960}
13961
13962
Jouni Malinenf7222712019-06-13 01:50:21 +030013963static enum sigma_cmd_result cmd_sta_set_rfeature(struct sigma_dut *dut,
13964 struct sigma_conn *conn,
13965 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013966{
13967 const char *intf = get_param(cmd, "Interface");
13968 const char *prog = get_param(cmd, "Prog");
Ashwini Patil68d02cd2017-01-10 15:39:16 +053013969 const char *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013970
13971 if (intf == NULL || prog == NULL)
13972 return -1;
13973
Ashwini Patil5acd7382017-04-13 15:55:04 +053013974 /* BSS Transition candidate list for BTM query */
13975 val = get_param(cmd, "Nebor_BSSID");
13976 if (val && btm_query_candidate_list(dut, conn, cmd) == 0)
13977 return 0;
13978
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013979 if (strcasecmp(prog, "TDLS") == 0)
13980 return cmd_sta_set_rfeature_tdls(intf, dut, conn, cmd);
13981
13982 if (strcasecmp(prog, "VHT") == 0)
13983 return cmd_sta_set_rfeature_vht(intf, dut, conn, cmd);
13984
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080013985 if (strcasecmp(prog, "HE") == 0)
13986 return cmd_sta_set_rfeature_he(intf, dut, conn, cmd);
13987
Ashwini Patil68d02cd2017-01-10 15:39:16 +053013988 if (strcasecmp(prog, "MBO") == 0) {
13989 val = get_param(cmd, "Cellular_Data_Cap");
13990 if (val &&
13991 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
13992 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +053013993
13994 val = get_param(cmd, "Ch_Pref");
13995 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
13996 return 0;
13997
Ashwini Patil68d02cd2017-01-10 15:39:16 +053013998 return 1;
13999 }
14000
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020014001 if (strcasecmp(prog, "60GHz") == 0)
14002 return cmd_sta_set_rfeature_60g(intf, dut, conn, cmd);
14003
Jouni Malinen6250cb02020-04-15 13:54:45 +030014004 if (strcasecmp(prog, "WPA3") == 0)
14005 return cmd_sta_set_rfeature_wpa3(intf, dut, conn, cmd);
14006
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014007 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported Prog");
14008 return 0;
14009}
14010
14011
Jouni Malinenf7222712019-06-13 01:50:21 +030014012static enum sigma_cmd_result cmd_sta_set_radio(struct sigma_dut *dut,
14013 struct sigma_conn *conn,
14014 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014015{
14016 const char *intf = get_param(cmd, "Interface");
14017 const char *mode = get_param(cmd, "Mode");
14018 int res;
14019
14020 if (intf == NULL || mode == NULL)
14021 return -1;
14022
14023 if (strcasecmp(mode, "On") == 0)
14024 res = wpa_command(intf, "SET radio_disabled 0");
14025 else if (strcasecmp(mode, "Off") == 0)
14026 res = wpa_command(intf, "SET radio_disabled 1");
14027 else
14028 return -1;
14029
14030 if (res) {
14031 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
14032 "radio mode");
14033 return 0;
14034 }
14035
14036 return 1;
14037}
14038
14039
Jouni Malinenf7222712019-06-13 01:50:21 +030014040static enum sigma_cmd_result cmd_sta_set_pwrsave(struct sigma_dut *dut,
14041 struct sigma_conn *conn,
14042 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014043{
14044 const char *intf = get_param(cmd, "Interface");
14045 const char *mode = get_param(cmd, "Mode");
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020014046 const char *prog = get_param(cmd, "program");
14047 const char *powersave = get_param(cmd, "powersave");
14048 int res = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014049
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020014050 if (intf == NULL)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014051 return -1;
14052
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020014053 if (prog && strcasecmp(prog, "60GHz") == 0) {
14054 /*
14055 * The CAPI mode parameter does not exist in 60G
14056 * unscheduled PS.
14057 */
Hu Wang5dc3ff12019-06-14 15:14:26 +080014058 if (powersave && strcasecmp(powersave, "unscheduled") == 0)
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020014059 res = set_ps(intf, dut, 1);
Jouni Malinen016ae6c2019-11-04 17:00:01 +020014060 } else if (prog && get_driver_type(dut) == DRIVER_WCN &&
Alexei Avshalom Lazar2f6fdb42019-02-04 14:16:08 +020014061 strcasecmp(prog, "HE") == 0) {
14062 return cmd_sta_set_power_save_he(intf, dut, conn, cmd);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020014063 } else {
14064 if (mode == NULL)
14065 return -1;
14066
14067 if (strcasecmp(mode, "On") == 0)
14068 res = set_ps(intf, dut, 1);
14069 else if (strcasecmp(mode, "Off") == 0)
14070 res = set_ps(intf, dut, 0);
14071 else
14072 return -1;
14073 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014074
14075 if (res) {
14076 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
14077 "power save mode");
14078 return 0;
14079 }
14080
14081 return 1;
14082}
14083
14084
Jouni Malinenf7222712019-06-13 01:50:21 +030014085static enum sigma_cmd_result cmd_sta_bssid_pool(struct sigma_dut *dut,
14086 struct sigma_conn *conn,
14087 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014088{
14089 const char *intf = get_param(cmd, "Interface");
14090 const char *val, *bssid;
14091 int res;
14092 char *buf;
14093 size_t buf_len;
14094
14095 val = get_param(cmd, "BSSID_FILTER");
14096 if (val == NULL)
14097 return -1;
14098
14099 bssid = get_param(cmd, "BSSID_List");
14100 if (atoi(val) == 0 || bssid == NULL) {
14101 /* Disable BSSID filter */
14102 if (wpa_command(intf, "SET bssid_filter ")) {
14103 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed "
14104 "to disable BSSID filter");
14105 return 0;
14106 }
14107
14108 return 1;
14109 }
14110
14111 buf_len = 100 + strlen(bssid);
14112 buf = malloc(buf_len);
14113 if (buf == NULL)
14114 return -1;
14115
14116 snprintf(buf, buf_len, "SET bssid_filter %s", bssid);
14117 res = wpa_command(intf, buf);
14118 free(buf);
14119 if (res) {
14120 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to enable "
14121 "BSSID filter");
14122 return 0;
14123 }
14124
14125 return 1;
14126}
14127
14128
Jouni Malinenf7222712019-06-13 01:50:21 +030014129static enum sigma_cmd_result cmd_sta_reset_parm(struct sigma_dut *dut,
14130 struct sigma_conn *conn,
14131 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014132{
14133 const char *intf = get_param(cmd, "Interface");
14134 const char *val;
14135
14136 /* TODO: ARP */
14137
14138 val = get_param(cmd, "HS2_CACHE_PROFILE");
14139 if (val && strcasecmp(val, "All") == 0)
14140 hs2_clear_credentials(intf);
14141
14142 return 1;
14143}
14144
14145
Jouni Malinenf7222712019-06-13 01:50:21 +030014146static enum sigma_cmd_result cmd_sta_get_key(struct sigma_dut *dut,
14147 struct sigma_conn *conn,
14148 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014149{
14150 const char *intf = get_param(cmd, "Interface");
14151 const char *key_type = get_param(cmd, "KeyType");
14152 char buf[100], resp[200];
14153
14154 if (key_type == NULL)
14155 return -1;
14156
14157 if (strcasecmp(key_type, "GTK") == 0) {
14158 if (wpa_command_resp(intf, "GET gtk", buf, sizeof(buf)) < 0 ||
14159 strncmp(buf, "FAIL", 4) == 0) {
14160 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
14161 "not fetch current GTK");
14162 return 0;
14163 }
14164 snprintf(resp, sizeof(resp), "KeyValue,%s", buf);
14165 send_resp(dut, conn, SIGMA_COMPLETE, resp);
14166 return 0;
14167 } else {
14168 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
14169 "KeyType");
14170 return 0;
14171 }
14172
14173 return 1;
14174}
14175
14176
14177static int hs2_set_policy(struct sigma_dut *dut)
14178{
14179#ifdef ANDROID
14180 system("ip rule del prio 23000");
14181 if (system("ip rule add from all lookup main prio 23000") != 0) {
14182 sigma_dut_print(dut, DUT_MSG_ERROR,
14183 "Failed to run:ip rule add from all lookup main prio");
14184 return -1;
14185 }
14186 if (system("ip route flush cache") != 0) {
14187 sigma_dut_print(dut, DUT_MSG_ERROR,
14188 "Failed to run ip route flush cache");
14189 return -1;
14190 }
14191 return 1;
14192#else /* ANDROID */
14193 return 0;
14194#endif /* ANDROID */
14195}
14196
14197
Jouni Malinenf7222712019-06-13 01:50:21 +030014198static enum sigma_cmd_result cmd_sta_hs2_associate(struct sigma_dut *dut,
14199 struct sigma_conn *conn,
14200 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014201{
14202 const char *intf = get_param(cmd, "Interface");
14203 const char *val = get_param(cmd, "Ignore_blacklist");
Jouni Malinen439352d2018-09-13 03:42:23 +030014204 const char *band = get_param(cmd, "Band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014205 struct wpa_ctrl *ctrl;
Jouni Malinen3aa72862019-05-29 23:14:51 +030014206 int res, r;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014207 char bssid[20], ssid[40], resp[100], buf[100], blacklisted[100];
14208 int tries = 0;
14209 int ignore_blacklist = 0;
14210 const char *events[] = {
14211 "CTRL-EVENT-CONNECTED",
14212 "INTERWORKING-BLACKLISTED",
14213 "INTERWORKING-NO-MATCH",
14214 NULL
14215 };
14216
14217 start_sta_mode(dut);
14218
Jouni Malinen439352d2018-09-13 03:42:23 +030014219 if (band) {
14220 if (strcmp(band, "2.4") == 0) {
14221 wpa_command(intf, "SET setband 2G");
14222 } else if (strcmp(band, "5") == 0) {
14223 wpa_command(intf, "SET setband 5G");
14224 } else {
14225 send_resp(dut, conn, SIGMA_ERROR,
14226 "errorCode,Unsupported band");
14227 return 0;
14228 }
14229 }
14230
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014231 blacklisted[0] = '\0';
14232 if (val && atoi(val))
14233 ignore_blacklist = 1;
14234
14235try_again:
14236 ctrl = open_wpa_mon(intf);
14237 if (ctrl == NULL) {
14238 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
14239 "wpa_supplicant monitor connection");
14240 return -2;
14241 }
14242
14243 tries++;
14244 if (wpa_command(intf, "INTERWORKING_SELECT auto")) {
14245 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start "
14246 "Interworking connection");
14247 wpa_ctrl_detach(ctrl);
14248 wpa_ctrl_close(ctrl);
14249 return 0;
14250 }
14251
14252 buf[0] = '\0';
14253 while (1) {
14254 char *pos;
14255 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
14256 pos = strstr(buf, "INTERWORKING-BLACKLISTED");
14257 if (!pos)
14258 break;
14259 pos += 25;
14260 sigma_dut_print(dut, DUT_MSG_DEBUG, "Found blacklisted AP: %s",
14261 pos);
14262 if (!blacklisted[0])
14263 memcpy(blacklisted, pos, strlen(pos) + 1);
14264 }
14265
14266 if (ignore_blacklist && blacklisted[0]) {
14267 char *end;
14268 end = strchr(blacklisted, ' ');
14269 if (end)
14270 *end = '\0';
14271 sigma_dut_print(dut, DUT_MSG_DEBUG, "Try to connect to a blacklisted network: %s",
14272 blacklisted);
Jouni Malinen3aa72862019-05-29 23:14:51 +030014273 r = snprintf(buf, sizeof(buf), "INTERWORKING_CONNECT %s",
14274 blacklisted);
14275 if (r < 0 || r >= sizeof(buf) || wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014276 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start Interworking connection to blacklisted network");
14277 wpa_ctrl_detach(ctrl);
14278 wpa_ctrl_close(ctrl);
14279 return 0;
14280 }
14281 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
14282 buf, sizeof(buf));
14283 }
14284
14285 wpa_ctrl_detach(ctrl);
14286 wpa_ctrl_close(ctrl);
14287
14288 if (res < 0) {
14289 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
14290 "connect");
14291 return 0;
14292 }
14293
14294 if (strstr(buf, "INTERWORKING-NO-MATCH") ||
14295 strstr(buf, "INTERWORKING-BLACKLISTED")) {
14296 if (tries < 2) {
14297 sigma_dut_print(dut, DUT_MSG_INFO, "No match found - try again to verify no APs were missed in the scan");
14298 goto try_again;
14299 }
14300 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,No network with "
14301 "matching credentials found");
14302 return 0;
14303 }
14304
14305 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
14306 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
14307 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
14308 "get current BSSID/SSID");
14309 return 0;
14310 }
14311
14312 snprintf(resp, sizeof(resp), "SSID,%s,BSSID,%s", ssid, bssid);
14313 send_resp(dut, conn, SIGMA_COMPLETE, resp);
14314 hs2_set_policy(dut);
14315 return 0;
14316}
14317
14318
Jouni Malinenf7222712019-06-13 01:50:21 +030014319static enum sigma_cmd_result cmd_sta_hs2_venue_info(struct sigma_dut *dut,
14320 struct sigma_conn *conn,
14321 struct sigma_cmd *cmd)
Jouni Malinenb639f1c2018-09-13 02:39:46 +030014322{
14323 const char *intf = get_param(cmd, "Interface");
14324 const char *display = get_param(cmd, "Display");
14325 struct wpa_ctrl *ctrl;
14326 char buf[300], params[400], *pos;
14327 char bssid[20];
14328 int info_avail = 0;
14329 unsigned int old_timeout;
14330 int res;
14331
14332 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
14333 send_resp(dut, conn, SIGMA_ERROR,
14334 "ErrorCode,Could not get current BSSID");
14335 return 0;
14336 }
14337 ctrl = open_wpa_mon(intf);
14338 if (!ctrl) {
14339 sigma_dut_print(dut, DUT_MSG_ERROR,
14340 "Failed to open wpa_supplicant monitor connection");
14341 return -2;
14342 }
14343
14344 snprintf(buf, sizeof(buf), "ANQP_GET %s 277", bssid);
14345 wpa_command(intf, buf);
14346
14347 res = get_wpa_cli_event(dut, ctrl, "GAS-QUERY-DONE", buf, sizeof(buf));
14348 if (res < 0) {
14349 send_resp(dut, conn, SIGMA_ERROR,
14350 "ErrorCode,Could not complete GAS query");
14351 goto fail;
14352 }
14353
14354 old_timeout = dut->default_timeout;
14355 dut->default_timeout = 2;
14356 res = get_wpa_cli_event(dut, ctrl, "RX-VENUE-URL", buf, sizeof(buf));
14357 dut->default_timeout = old_timeout;
14358 if (res < 0)
14359 goto done;
14360 pos = strchr(buf, ' ');
14361 if (!pos)
14362 goto done;
14363 pos++;
14364 pos = strchr(pos, ' ');
14365 if (!pos)
14366 goto done;
14367 pos++;
14368 info_avail = 1;
14369 snprintf(params, sizeof(params), "browser %s", pos);
14370
14371 if (display && strcasecmp(display, "Yes") == 0) {
14372 pid_t pid;
14373
14374 pid = fork();
14375 if (pid < 0) {
14376 perror("fork");
14377 return -1;
14378 }
14379
14380 if (pid == 0) {
14381 run_hs20_osu(dut, params);
14382 exit(0);
14383 }
14384 }
14385
14386done:
14387 snprintf(buf, sizeof(buf), "Info_available,%s",
14388 info_avail ? "Yes" : "No");
14389 send_resp(dut, conn, SIGMA_COMPLETE, buf);
14390fail:
14391 wpa_ctrl_detach(ctrl);
14392 wpa_ctrl_close(ctrl);
14393 return 0;
14394}
14395
14396
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014397static int sta_add_credential_uname_pwd(struct sigma_dut *dut,
14398 struct sigma_conn *conn,
14399 const char *ifname,
14400 struct sigma_cmd *cmd)
14401{
14402 const char *val;
14403 int id;
14404
14405 id = add_cred(ifname);
14406 if (id < 0)
14407 return -2;
14408 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
14409
14410 val = get_param(cmd, "prefer");
14411 if (val && atoi(val) > 0)
14412 set_cred(ifname, id, "priority", "1");
14413
14414 val = get_param(cmd, "REALM");
14415 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
14416 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
14417 "realm");
14418 return 0;
14419 }
14420
14421 val = get_param(cmd, "HOME_FQDN");
14422 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
14423 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
14424 "home_fqdn");
14425 return 0;
14426 }
14427
14428 val = get_param(cmd, "Username");
14429 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
14430 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
14431 "username");
14432 return 0;
14433 }
14434
14435 val = get_param(cmd, "Password");
14436 if (val && set_cred_quoted(ifname, id, "password", val) < 0) {
14437 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
14438 "password");
14439 return 0;
14440 }
14441
14442 val = get_param(cmd, "ROOT_CA");
14443 if (val) {
14444 char fname[200];
14445 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
14446#ifdef __linux__
14447 if (!file_exists(fname)) {
14448 char msg[300];
14449 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
14450 "file (%s) not found", fname);
14451 send_resp(dut, conn, SIGMA_ERROR, msg);
14452 return 0;
14453 }
14454#endif /* __linux__ */
14455 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
14456 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
14457 "not set root CA");
14458 return 0;
14459 }
14460 }
14461
14462 return 1;
14463}
14464
14465
14466static int update_devdetail_imsi(struct sigma_dut *dut, const char *imsi)
14467{
14468 FILE *in, *out;
14469 char buf[500];
14470 int found = 0;
14471
14472 in = fopen("devdetail.xml", "r");
14473 if (in == NULL)
14474 return -1;
14475 out = fopen("devdetail.xml.tmp", "w");
14476 if (out == NULL) {
14477 fclose(in);
14478 return -1;
14479 }
14480
14481 while (fgets(buf, sizeof(buf), in)) {
14482 char *pos = strstr(buf, "<IMSI>");
14483 if (pos) {
14484 sigma_dut_print(dut, DUT_MSG_INFO, "Updated DevDetail IMSI to %s",
14485 imsi);
14486 pos += 6;
14487 *pos = '\0';
14488 fprintf(out, "%s%s</IMSI>\n", buf, imsi);
14489 found++;
14490 } else {
14491 fprintf(out, "%s", buf);
14492 }
14493 }
14494
14495 fclose(out);
14496 fclose(in);
14497 if (found)
14498 rename("devdetail.xml.tmp", "devdetail.xml");
14499 else
14500 unlink("devdetail.xml.tmp");
14501
14502 return 0;
14503}
14504
14505
14506static int sta_add_credential_sim(struct sigma_dut *dut,
14507 struct sigma_conn *conn,
14508 const char *ifname, struct sigma_cmd *cmd)
14509{
14510 const char *val, *imsi = NULL;
14511 int id;
14512 char buf[200];
14513 int res;
14514 const char *pos;
14515 size_t mnc_len;
14516 char plmn_mcc[4];
14517 char plmn_mnc[4];
14518
14519 id = add_cred(ifname);
14520 if (id < 0)
14521 return -2;
14522 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
14523
14524 val = get_param(cmd, "prefer");
14525 if (val && atoi(val) > 0)
14526 set_cred(ifname, id, "priority", "1");
14527
14528 val = get_param(cmd, "PLMN_MCC");
14529 if (val == NULL) {
14530 send_resp(dut, conn, SIGMA_ERROR,
14531 "errorCode,Missing PLMN_MCC");
14532 return 0;
14533 }
14534 if (strlen(val) != 3) {
14535 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MCC");
14536 return 0;
14537 }
14538 snprintf(plmn_mcc, sizeof(plmn_mcc), "%s", val);
14539
14540 val = get_param(cmd, "PLMN_MNC");
14541 if (val == NULL) {
14542 send_resp(dut, conn, SIGMA_ERROR,
14543 "errorCode,Missing PLMN_MNC");
14544 return 0;
14545 }
14546 if (strlen(val) != 2 && strlen(val) != 3) {
14547 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MNC");
14548 return 0;
14549 }
14550 snprintf(plmn_mnc, sizeof(plmn_mnc), "%s", val);
14551
14552 val = get_param(cmd, "IMSI");
14553 if (val == NULL) {
14554 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing SIM "
14555 "IMSI");
14556 return 0;
14557 }
14558
14559 imsi = pos = val;
14560
14561 if (strncmp(plmn_mcc, pos, 3) != 0) {
14562 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MCC mismatch");
14563 return 0;
14564 }
14565 pos += 3;
14566
14567 mnc_len = strlen(plmn_mnc);
14568 if (mnc_len < 2) {
14569 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC not set");
14570 return 0;
14571 }
14572
14573 if (strncmp(plmn_mnc, pos, mnc_len) != 0) {
14574 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC mismatch");
14575 return 0;
14576 }
14577 pos += mnc_len;
14578
14579 res = snprintf(buf, sizeof(buf), "%s%s-%s",plmn_mcc, plmn_mnc, pos);
14580 if (res < 0 || res >= (int) sizeof(buf))
14581 return -1;
14582 if (set_cred_quoted(ifname, id, "imsi", buf) < 0) {
14583 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
14584 "not set IMSI");
14585 return 0;
14586 }
14587
14588 val = get_param(cmd, "Password");
14589 if (val && set_cred_quoted(ifname, id, "milenage", val) < 0) {
14590 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
14591 "not set password");
14592 return 0;
14593 }
14594
Jouni Malinenba630452018-06-22 11:49:59 +030014595 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014596 /*
14597 * Set provisioning_sp for the test cases where SIM/USIM
14598 * provisioning is used.
14599 */
14600 if (val && set_cred_quoted(ifname, id, "provisioning_sp",
14601 "wi-fi.org") < 0) {
14602 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
14603 "not set provisioning_sp");
14604 return 0;
14605 }
14606
14607 update_devdetail_imsi(dut, imsi);
14608 }
14609
14610 return 1;
14611}
14612
14613
14614static int sta_add_credential_cert(struct sigma_dut *dut,
14615 struct sigma_conn *conn,
14616 const char *ifname,
14617 struct sigma_cmd *cmd)
14618{
14619 const char *val;
14620 int id;
14621
14622 id = add_cred(ifname);
14623 if (id < 0)
14624 return -2;
14625 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
14626
14627 val = get_param(cmd, "prefer");
14628 if (val && atoi(val) > 0)
14629 set_cred(ifname, id, "priority", "1");
14630
14631 val = get_param(cmd, "REALM");
14632 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
14633 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
14634 "realm");
14635 return 0;
14636 }
14637
14638 val = get_param(cmd, "HOME_FQDN");
14639 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
14640 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
14641 "home_fqdn");
14642 return 0;
14643 }
14644
14645 val = get_param(cmd, "Username");
14646 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
14647 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
14648 "username");
14649 return 0;
14650 }
14651
14652 val = get_param(cmd, "clientCertificate");
14653 if (val) {
14654 char fname[200];
14655 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
14656#ifdef __linux__
14657 if (!file_exists(fname)) {
14658 char msg[300];
14659 snprintf(msg, sizeof(msg),
14660 "ErrorCode,clientCertificate "
14661 "file (%s) not found", fname);
14662 send_resp(dut, conn, SIGMA_ERROR, msg);
14663 return 0;
14664 }
14665#endif /* __linux__ */
14666 if (set_cred_quoted(ifname, id, "client_cert", fname) < 0) {
14667 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
14668 "not set client_cert");
14669 return 0;
14670 }
14671 if (set_cred_quoted(ifname, id, "private_key", fname) < 0) {
14672 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
14673 "not set private_key");
14674 return 0;
14675 }
14676 }
14677
14678 val = get_param(cmd, "ROOT_CA");
14679 if (val) {
14680 char fname[200];
14681 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
14682#ifdef __linux__
14683 if (!file_exists(fname)) {
14684 char msg[300];
14685 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
14686 "file (%s) not found", fname);
14687 send_resp(dut, conn, SIGMA_ERROR, msg);
14688 return 0;
14689 }
14690#endif /* __linux__ */
14691 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
14692 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
14693 "not set root CA");
14694 return 0;
14695 }
14696 }
14697
14698 return 1;
14699}
14700
14701
Jouni Malinenf7222712019-06-13 01:50:21 +030014702static enum sigma_cmd_result cmd_sta_add_credential(struct sigma_dut *dut,
14703 struct sigma_conn *conn,
14704 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014705{
14706 const char *intf = get_param(cmd, "Interface");
14707 const char *type;
14708
14709 start_sta_mode(dut);
14710
14711 type = get_param(cmd, "Type");
14712 if (!type)
14713 return -1;
14714
14715 if (strcasecmp(type, "uname_pwd") == 0)
14716 return sta_add_credential_uname_pwd(dut, conn, intf, cmd);
14717
14718 if (strcasecmp(type, "sim") == 0)
14719 return sta_add_credential_sim(dut, conn, intf, cmd);
14720
14721 if (strcasecmp(type, "cert") == 0)
14722 return sta_add_credential_cert(dut, conn, intf, cmd);
14723
14724 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported credential "
14725 "type");
14726 return 0;
14727}
14728
14729
Jouni Malinenf7222712019-06-13 01:50:21 +030014730static enum sigma_cmd_result cmd_sta_scan(struct sigma_dut *dut,
14731 struct sigma_conn *conn,
14732 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014733{
14734 const char *intf = get_param(cmd, "Interface");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080014735 const char *val, *bssid, *ssid, *scan_freq, *short_ssid;
Veerendranathdc581b52020-08-10 03:29:08 -070014736 char buf[4096], scan_res[20];
vamsi krishna89ad8c62017-09-19 12:51:18 +053014737 char ssid_hex[65];
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080014738 int wildcard_ssid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014739 int res;
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080014740 enum sigma_cmd_result status;
Jouni Malinen228a2fc2020-06-22 23:37:45 +030014741 struct wpa_ctrl *ctrl = NULL;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014742
Jouni Malinen8c1abeb2019-11-06 18:48:34 +020014743 start_sta_mode(dut);
14744
Arif Hussain66a4af02019-02-07 15:04:51 -080014745 val = get_param(cmd, "GetParameter");
14746 if (val && strcmp(val, "SSID_BSSID") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020014747 if (get_wpa_ssid_bssid(dut, get_station_ifname(dut),
Arif Hussain66a4af02019-02-07 15:04:51 -080014748 buf, sizeof(buf)) < 0) {
14749 sigma_dut_print(dut, DUT_MSG_ERROR,
14750 "Could not get ssid bssid");
14751 return ERROR_SEND_STATUS;
14752 }
14753
14754 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
14755 send_resp(dut, conn, SIGMA_COMPLETE, buf);
14756 return STATUS_SENT;
14757 }
14758
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014759 val = get_param(cmd, "HESSID");
14760 if (val) {
14761 res = snprintf(buf, sizeof(buf), "SET hessid %s", val);
14762 if (res < 0 || res >= (int) sizeof(buf))
14763 return -1;
14764 wpa_command(intf, buf);
14765 }
14766
14767 val = get_param(cmd, "ACCS_NET_TYPE");
14768 if (val) {
14769 res = snprintf(buf, sizeof(buf), "SET access_network_type %s",
14770 val);
14771 if (res < 0 || res >= (int) sizeof(buf))
14772 return -1;
14773 wpa_command(intf, buf);
14774 }
14775
Kiran Kumar Lokere69d89952021-08-08 23:41:46 -070014776 if (get_param(cmd, "RxMac"))
14777 sta_set_scan_unicast_probe(dut, intf, 1);
14778
vamsi krishna89ad8c62017-09-19 12:51:18 +053014779 bssid = get_param(cmd, "Bssid");
14780 ssid = get_param(cmd, "Ssid");
Kiran Kumar Lokere69d89952021-08-08 23:41:46 -070014781 if (!bssid)
14782 bssid = get_param(cmd, "RxMac");
vamsi krishna89ad8c62017-09-19 12:51:18 +053014783
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080014784 if (ssid && strcasecmp(ssid, "ZeroLength") == 0 &&
14785 dut->device_type == STA_testbed) {
14786 ssid = NULL;
14787 wildcard_ssid = 1;
14788 }
14789
vamsi krishna89ad8c62017-09-19 12:51:18 +053014790 if (ssid) {
14791 if (2 * strlen(ssid) >= sizeof(ssid_hex)) {
14792 send_resp(dut, conn, SIGMA_ERROR,
14793 "ErrorCode,Too long SSID");
14794 return 0;
14795 }
14796 ascii2hexstr(ssid, ssid_hex);
14797 }
14798
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080014799 short_ssid = get_param(cmd, "ShortSSID");
14800 if (short_ssid) {
14801 uint32_t short_ssid_hex;
14802
14803 short_ssid_hex = strtoul(short_ssid, NULL, 16);
14804 short_ssid_hex = ((short_ssid_hex & 0xFF) << 24) |
14805 (((short_ssid_hex >> 8) & 0xFF) << 16) |
14806 (((short_ssid_hex >> 16) & 0xFF) << 8) |
14807 ((short_ssid_hex >> 24) & 0xFF);
14808
14809 res = snprintf(buf, sizeof(buf),
14810 "VENDOR_ELEM_ADD 14 ff053a%08x",
14811 short_ssid_hex);
14812 if (res < 0 || res >= (int) sizeof(buf) ||
14813 wpa_command(intf, buf)) {
14814 send_resp(dut, conn, SIGMA_ERROR,
14815 "errorCode,Failed to add short SSID");
14816 return STATUS_SENT_ERROR;
14817 }
14818 }
14819
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080014820 scan_freq = get_param(cmd, "ChnlFreq");
Veerendranath Jakkam132c4b42020-08-10 00:29:03 +053014821 if (scan_freq) {
14822 if (strcasecmp(scan_freq, "2G") == 0)
14823 scan_freq = "2412-2462";
14824 else if (strcasecmp(scan_freq, "5G") == 0)
14825 scan_freq = "5180-5925";
14826 }
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080014827
Jouni Malinen228a2fc2020-06-22 23:37:45 +030014828 val = get_param(cmd, "WaitCompletion");
14829 if (val && atoi(val) == 1) {
14830 ctrl = open_wpa_mon(intf);
14831 if (!ctrl) {
14832 send_resp(dut, conn, SIGMA_ERROR,
14833 "errorCode,Failed to open monitor socket");
14834 return STATUS_SENT_ERROR;
14835 }
14836 }
14837
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080014838 res = snprintf(buf, sizeof(buf), "SCAN%s%s%s%s%s%s%s",
vamsi krishna89ad8c62017-09-19 12:51:18 +053014839 bssid ? " bssid=": "",
14840 bssid ? bssid : "",
14841 ssid ? " ssid " : "",
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080014842 ssid ? ssid_hex : "",
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080014843 wildcard_ssid ? " wildcard_ssid=1" : "",
14844 scan_freq ? " freq=" : "",
14845 scan_freq ? scan_freq : "");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080014846 if (res < 0 || res >= (int) sizeof(buf)) {
14847 send_resp(dut, conn, SIGMA_ERROR,
14848 "errorCode,Could not build scan command");
14849 status = STATUS_SENT_ERROR;
14850 goto remove_s_ssid;
14851 }
vamsi krishna89ad8c62017-09-19 12:51:18 +053014852
Veerendranathdc581b52020-08-10 03:29:08 -070014853 res = wpa_command_resp(intf, buf, scan_res, sizeof(scan_res));
14854 if (strncmp(scan_res, "FAIL-BUSY", 9) == 0) {
14855 sigma_dut_print(dut, DUT_MSG_DEBUG,
14856 "Scan request rejected with busy status, abort ongoing scan and try again");
14857 wpa_command(intf, "ABORT_SCAN");
14858 res = wpa_command(intf, buf);
14859 }
14860
14861 if (res < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014862 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not start "
14863 "scan");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080014864 status = STATUS_SENT_ERROR;
14865 } else {
14866 status = SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014867 }
14868
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080014869remove_s_ssid:
14870 if (short_ssid && wpa_command(intf, "VENDOR_ELEM_REMOVE 14 *"))
14871 sigma_dut_print(dut, DUT_MSG_ERROR,
14872 "Failed to delete vendor element");
14873
Jouni Malinen228a2fc2020-06-22 23:37:45 +030014874 if (ctrl) {
14875 if (status == SUCCESS_SEND_STATUS) {
14876 res = get_wpa_cli_event(dut, ctrl,
14877 "CTRL-EVENT-SCAN-RESULTS",
14878 buf, sizeof(buf));
14879 if (res < 0) {
14880 send_resp(dut, conn, SIGMA_ERROR,
14881 "ErrorCode,scan did not complete");
14882 status = STATUS_SENT_ERROR;
14883 }
14884 }
14885
14886 wpa_ctrl_detach(ctrl);
14887 wpa_ctrl_close(ctrl);
14888 }
14889
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080014890 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014891}
14892
14893
Jouni Malinenf7222712019-06-13 01:50:21 +030014894static enum sigma_cmd_result cmd_sta_scan_bss(struct sigma_dut *dut,
14895 struct sigma_conn *conn,
14896 struct sigma_cmd *cmd)
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020014897{
14898 const char *intf = get_param(cmd, "Interface");
14899 const char *bssid;
14900 char buf[4096], *pos;
14901 int freq, chan;
14902 char *ssid;
14903 char resp[100];
14904 int res;
14905 struct wpa_ctrl *ctrl;
14906
14907 bssid = get_param(cmd, "BSSID");
14908 if (!bssid) {
14909 send_resp(dut, conn, SIGMA_INVALID,
14910 "errorCode,BSSID argument is missing");
14911 return 0;
14912 }
14913
14914 ctrl = open_wpa_mon(intf);
14915 if (!ctrl) {
14916 sigma_dut_print(dut, DUT_MSG_ERROR,
14917 "Failed to open wpa_supplicant monitor connection");
14918 return -1;
14919 }
14920
14921 if (wpa_command(intf, "SCAN TYPE=ONLY")) {
14922 send_resp(dut, conn, SIGMA_ERROR,
14923 "errorCode,Could not start scan");
14924 wpa_ctrl_detach(ctrl);
14925 wpa_ctrl_close(ctrl);
14926 return 0;
14927 }
14928
14929 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
14930 buf, sizeof(buf));
14931
14932 wpa_ctrl_detach(ctrl);
14933 wpa_ctrl_close(ctrl);
14934
14935 if (res < 0) {
14936 send_resp(dut, conn, SIGMA_ERROR,
14937 "errorCode,Scan did not complete");
14938 return 0;
14939 }
14940
14941 snprintf(buf, sizeof(buf), "BSS %s", bssid);
14942 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
14943 strncmp(buf, "id=", 3) != 0) {
14944 send_resp(dut, conn, SIGMA_ERROR,
14945 "errorCode,Specified BSSID not found");
14946 return 0;
14947 }
14948
14949 pos = strstr(buf, "\nfreq=");
14950 if (!pos) {
14951 send_resp(dut, conn, SIGMA_ERROR,
14952 "errorCode,Channel not found");
14953 return 0;
14954 }
14955 freq = atoi(pos + 6);
14956 chan = freq_to_channel(freq);
14957
14958 pos = strstr(buf, "\nssid=");
14959 if (!pos) {
14960 send_resp(dut, conn, SIGMA_ERROR,
14961 "errorCode,SSID not found");
14962 return 0;
14963 }
14964 ssid = pos + 6;
14965 pos = strchr(ssid, '\n');
14966 if (pos)
14967 *pos = '\0';
14968 snprintf(resp, sizeof(resp), "ssid,%s,bsschannel,%d", ssid, chan);
14969 send_resp(dut, conn, SIGMA_COMPLETE, resp);
14970 return 0;
14971}
14972
14973
Jouni Malinenf7222712019-06-13 01:50:21 +030014974static enum sigma_cmd_result cmd_sta_set_systime(struct sigma_dut *dut,
14975 struct sigma_conn *conn,
14976 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014977{
14978#ifdef __linux__
14979 struct timeval tv;
14980 struct tm tm;
14981 time_t t;
14982 const char *val;
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053014983 int v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014984
Jouni Malinen016ae6c2019-11-04 17:00:01 +020014985 wpa_command(get_station_ifname(dut), "PMKSA_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014986
14987 memset(&tm, 0, sizeof(tm));
14988 val = get_param(cmd, "seconds");
14989 if (val)
14990 tm.tm_sec = atoi(val);
14991 val = get_param(cmd, "minutes");
14992 if (val)
14993 tm.tm_min = atoi(val);
14994 val = get_param(cmd, "hours");
14995 if (val)
14996 tm.tm_hour = atoi(val);
14997 val = get_param(cmd, "date");
14998 if (val)
14999 tm.tm_mday = atoi(val);
15000 val = get_param(cmd, "month");
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053015001 if (val) {
15002 v = atoi(val);
15003 if (v < 1 || v > 12) {
15004 send_resp(dut, conn, SIGMA_INVALID,
15005 "errorCode,Invalid month");
15006 return 0;
15007 }
15008 tm.tm_mon = v - 1;
15009 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015010 val = get_param(cmd, "year");
15011 if (val) {
15012 int year = atoi(val);
15013#ifdef ANDROID
15014 if (year > 2035)
15015 year = 2035; /* years beyond 2035 not supported */
15016#endif /* ANDROID */
15017 tm.tm_year = year - 1900;
15018 }
15019 t = mktime(&tm);
15020 if (t == (time_t) -1) {
15021 send_resp(dut, conn, SIGMA_ERROR,
15022 "errorCode,Invalid date or time");
15023 return 0;
15024 }
15025
15026 memset(&tv, 0, sizeof(tv));
15027 tv.tv_sec = t;
15028
15029 if (settimeofday(&tv, NULL) < 0) {
15030 sigma_dut_print(dut, DUT_MSG_INFO, "settimeofday failed: %s",
15031 strerror(errno));
15032 send_resp(dut, conn, SIGMA_ERROR,
15033 "errorCode,Failed to set time");
15034 return 0;
15035 }
15036
15037 return 1;
15038#endif /* __linux__ */
15039
15040 return -1;
15041}
15042
15043
Jouni Malinenf7222712019-06-13 01:50:21 +030015044static enum sigma_cmd_result cmd_sta_osu(struct sigma_dut *dut,
15045 struct sigma_conn *conn,
15046 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015047{
15048 const char *intf = get_param(cmd, "Interface");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030015049 const char *name, *osu_ssid, *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015050 int prod_ess_assoc = 1;
Jouni Malinen4c8681c2018-09-12 23:28:11 +030015051 char buf[300], bssid[100], ssid[100];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015052 int res;
15053 struct wpa_ctrl *ctrl;
15054
15055 name = get_param(cmd, "osuFriendlyName");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030015056 osu_ssid = get_param(cmd, "osu_ssid");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015057
15058 val = get_param(cmd, "ProdESSAssoc");
15059 if (val)
15060 prod_ess_assoc = atoi(val);
15061
15062 kill_dhcp_client(dut, intf);
15063 if (start_dhcp_client(dut, intf) < 0)
15064 return -2;
15065
15066 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger OSU");
15067 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
15068 res = snprintf(buf, sizeof(buf),
Jouni Malinen4c8681c2018-09-12 23:28:11 +030015069 "%s %s%s%s %s%s%s signup osu-ca.pem",
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015070 prod_ess_assoc ? "" : "-N",
15071 name ? "-O'" : "", name ? name : "",
Jouni Malinen4c8681c2018-09-12 23:28:11 +030015072 name ? "'" : "",
15073 osu_ssid ? "-o'" : "", osu_ssid ? osu_ssid : "",
15074 osu_ssid ? "'" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015075
Kanchanapally, Vidyullatha12b66762015-12-31 16:46:42 +053015076 hs2_set_policy(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015077 if (run_hs20_osu(dut, buf) < 0) {
15078 FILE *f;
15079
15080 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to complete OSU");
15081
15082 f = fopen("hs20-osu-client.res", "r");
15083 if (f) {
15084 char resp[400], res[300], *pos;
15085 if (!fgets(res, sizeof(res), f))
15086 res[0] = '\0';
15087 pos = strchr(res, '\n');
15088 if (pos)
15089 *pos = '\0';
15090 fclose(f);
15091 sigma_dut_summary(dut, "hs20-osu-client provisioning failed: %s",
15092 res);
15093 snprintf(resp, sizeof(resp), "notify-send '%s'", res);
15094 if (system(resp) != 0) {
15095 }
15096 snprintf(resp, sizeof(resp),
15097 "SSID,,BSSID,,failureReason,%s", res);
15098 send_resp(dut, conn, SIGMA_COMPLETE, resp);
15099 return 0;
15100 }
15101
15102 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
15103 return 0;
15104 }
15105
15106 if (!prod_ess_assoc)
15107 goto report;
15108
15109 ctrl = open_wpa_mon(intf);
15110 if (ctrl == NULL) {
15111 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
15112 "wpa_supplicant monitor connection");
15113 return -1;
15114 }
15115
15116 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
15117 buf, sizeof(buf));
15118
15119 wpa_ctrl_detach(ctrl);
15120 wpa_ctrl_close(ctrl);
15121
15122 if (res < 0) {
15123 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to connect to "
15124 "network after OSU");
15125 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
15126 return 0;
15127 }
15128
15129report:
15130 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
15131 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
15132 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get BSSID/SSID");
15133 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
15134 return 0;
15135 }
15136
15137 snprintf(buf, sizeof(buf), "SSID,%s,BSSID,%s", ssid, bssid);
15138 send_resp(dut, conn, SIGMA_COMPLETE, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015139 return 0;
15140}
15141
15142
Jouni Malinenf7222712019-06-13 01:50:21 +030015143static enum sigma_cmd_result cmd_sta_policy_update(struct sigma_dut *dut,
15144 struct sigma_conn *conn,
15145 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015146{
15147 const char *val;
15148 int timeout = 120;
15149
15150 val = get_param(cmd, "PolicyUpdate");
15151 if (val == NULL || atoi(val) == 0)
15152 return 1; /* No operation requested */
15153
15154 val = get_param(cmd, "Timeout");
15155 if (val)
15156 timeout = atoi(val);
15157
15158 if (timeout) {
15159 /* TODO: time out the command and return
15160 * PolicyUpdateStatus,TIMEOUT if needed. */
15161 }
15162
15163 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger policy update");
15164 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
15165 if (run_hs20_osu(dut, "pol_upd fqdn=wi-fi.org") < 0) {
15166 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,FAIL");
15167 return 0;
15168 }
15169
15170 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,SUCCESS");
15171 return 0;
15172}
15173
15174
Jouni Malinenf7222712019-06-13 01:50:21 +030015175static enum sigma_cmd_result cmd_sta_er_config(struct sigma_dut *dut,
15176 struct sigma_conn *conn,
15177 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015178{
15179 struct wpa_ctrl *ctrl;
15180 const char *intf = get_param(cmd, "Interface");
15181 const char *bssid = get_param(cmd, "Bssid");
15182 const char *ssid = get_param(cmd, "SSID");
15183 const char *security = get_param(cmd, "Security");
15184 const char *passphrase = get_param(cmd, "Passphrase");
15185 const char *pin = get_param(cmd, "PIN");
15186 char buf[1000];
15187 char ssid_hex[200], passphrase_hex[200];
15188 const char *keymgmt, *cipher;
15189
15190 if (intf == NULL)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020015191 intf = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015192
15193 if (!bssid) {
15194 send_resp(dut, conn, SIGMA_ERROR,
15195 "ErrorCode,Missing Bssid argument");
15196 return 0;
15197 }
15198
15199 if (!ssid) {
15200 send_resp(dut, conn, SIGMA_ERROR,
15201 "ErrorCode,Missing SSID argument");
15202 return 0;
15203 }
15204
15205 if (!security) {
15206 send_resp(dut, conn, SIGMA_ERROR,
15207 "ErrorCode,Missing Security argument");
15208 return 0;
15209 }
15210
15211 if (!passphrase) {
15212 send_resp(dut, conn, SIGMA_ERROR,
15213 "ErrorCode,Missing Passphrase argument");
15214 return 0;
15215 }
15216
15217 if (!pin) {
15218 send_resp(dut, conn, SIGMA_ERROR,
15219 "ErrorCode,Missing PIN argument");
15220 return 0;
15221 }
15222
vamsi krishna8c9c1562017-05-12 15:51:46 +053015223 if (2 * strlen(ssid) >= sizeof(ssid_hex) ||
15224 2 * strlen(passphrase) >= sizeof(passphrase_hex)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015225 send_resp(dut, conn, SIGMA_ERROR,
15226 "ErrorCode,Too long SSID/passphrase");
15227 return 0;
15228 }
15229
15230 ctrl = open_wpa_mon(intf);
15231 if (ctrl == NULL) {
15232 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
15233 "wpa_supplicant monitor connection");
15234 return -2;
15235 }
15236
15237 if (strcasecmp(security, "wpa2-psk") == 0) {
15238 keymgmt = "WPA2PSK";
15239 cipher = "CCMP";
15240 } else {
15241 wpa_ctrl_detach(ctrl);
15242 wpa_ctrl_close(ctrl);
15243 send_resp(dut, conn, SIGMA_ERROR,
15244 "ErrorCode,Unsupported Security value");
15245 return 0;
15246 }
15247
15248 ascii2hexstr(ssid, ssid_hex);
15249 ascii2hexstr(passphrase, passphrase_hex);
15250 snprintf(buf, sizeof(buf), "WPS_REG %s %s %s %s %s %s",
15251 bssid, pin, ssid_hex, keymgmt, cipher, passphrase_hex);
15252
15253 if (wpa_command(intf, buf) < 0) {
15254 wpa_ctrl_detach(ctrl);
15255 wpa_ctrl_close(ctrl);
15256 send_resp(dut, conn, SIGMA_ERROR,
15257 "ErrorCode,Failed to start registrar");
15258 return 0;
15259 }
15260
15261 snprintf(dut->er_oper_bssid, sizeof(dut->er_oper_bssid), "%s", bssid);
15262 dut->er_oper_performed = 1;
15263
15264 return wps_connection_event(dut, conn, ctrl, intf, 0);
15265}
15266
15267
Jouni Malinenf7222712019-06-13 01:50:21 +030015268static enum sigma_cmd_result
15269cmd_sta_wps_connect_pw_token(struct sigma_dut *dut, struct sigma_conn *conn,
15270 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015271{
15272 struct wpa_ctrl *ctrl;
15273 const char *intf = get_param(cmd, "Interface");
15274 const char *bssid = get_param(cmd, "Bssid");
15275 char buf[100];
15276
15277 if (!bssid) {
15278 send_resp(dut, conn, SIGMA_ERROR,
15279 "ErrorCode,Missing Bssid argument");
15280 return 0;
15281 }
15282
15283 ctrl = open_wpa_mon(intf);
15284 if (ctrl == NULL) {
15285 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
15286 "wpa_supplicant monitor connection");
15287 return -2;
15288 }
15289
15290 snprintf(buf, sizeof(buf), "WPS_NFC %s", bssid);
15291
15292 if (wpa_command(intf, buf) < 0) {
15293 wpa_ctrl_detach(ctrl);
15294 wpa_ctrl_close(ctrl);
15295 send_resp(dut, conn, SIGMA_ERROR,
15296 "ErrorCode,Failed to start registrar");
15297 return 0;
15298 }
15299
15300 return wps_connection_event(dut, conn, ctrl, intf, 0);
15301}
15302
15303
Jouni Malinenf7222712019-06-13 01:50:21 +030015304static enum sigma_cmd_result cmd_start_wps_registration(struct sigma_dut *dut,
15305 struct sigma_conn *conn,
15306 struct sigma_cmd *cmd)
vamsi krishna9b144002017-09-20 13:28:13 +053015307{
15308 struct wpa_ctrl *ctrl;
15309 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020015310 const char *network_mode = get_param(cmd, "network_mode");
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020015311 const char *config_method = get_param(cmd, "WPSConfigMethod");
15312 const char *role;
vamsi krishna9b144002017-09-20 13:28:13 +053015313 int res;
15314 char buf[256];
15315 const char *events[] = {
15316 "CTRL-EVENT-CONNECTED",
15317 "WPS-OVERLAP-DETECTED",
15318 "WPS-TIMEOUT",
15319 "WPS-FAIL",
15320 NULL
15321 };
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020015322 int id = 0;
vamsi krishna9b144002017-09-20 13:28:13 +053015323
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020015324 /* 60G WPS tests do not pass Interface parameter */
15325 if (!intf)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020015326 intf = get_main_ifname(dut);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020015327
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020015328 if (dut->mode == SIGMA_MODE_AP)
15329 return ap_wps_registration(dut, conn, cmd);
15330
15331 if (config_method) {
15332 /* WFA_CS_WPS_PIN_KEYPAD mode is set when using the
15333 * sta_wps_enter_pin before calling start_wps_registration. */
15334 if (strcasecmp(config_method, "PBC") == 0)
15335 dut->wps_method = WFA_CS_WPS_PBC;
15336 }
15337 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
15338 send_resp(dut, conn, SIGMA_ERROR,
15339 "ErrorCode,WPS parameters not yet set");
15340 return STATUS_SENT;
15341 }
15342
15343 /* Make sure WPS is enabled (also for STA mode) */
15344 dut->wps_disable = 0;
15345
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020015346 if (dut->band == WPS_BAND_60G && network_mode &&
15347 strcasecmp(network_mode, "PBSS") == 0) {
15348 sigma_dut_print(dut, DUT_MSG_DEBUG,
15349 "Set PBSS network mode, network id %d", id);
Jouni Malinen016ae6c2019-11-04 17:00:01 +020015350 if (set_network(get_station_ifname(dut), id, "pbss", "1") < 0)
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020015351 return -2;
15352 }
15353
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020015354 if (dut->force_rsn_ie) {
15355 sigma_dut_print(dut, DUT_MSG_DEBUG, "Force RSN_IE: %d",
15356 dut->force_rsn_ie);
15357 if (sta_60g_force_rsn_ie(dut, dut->force_rsn_ie) < 0) {
15358 sigma_dut_print(dut, DUT_MSG_INFO,
15359 "Failed to force RSN_IE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020015360 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020015361 }
15362 }
15363
vamsi krishna9b144002017-09-20 13:28:13 +053015364 ctrl = open_wpa_mon(intf);
15365 if (!ctrl) {
15366 sigma_dut_print(dut, DUT_MSG_ERROR,
15367 "Failed to open wpa_supplicant monitor connection");
15368 return -2;
15369 }
15370
15371 role = get_param(cmd, "WpsRole");
15372 if (!role) {
15373 send_resp(dut, conn, SIGMA_INVALID,
15374 "ErrorCode,WpsRole not provided");
15375 goto fail;
15376 }
15377
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020015378 if (strcasecmp(role, "Enrollee") != 0) {
15379 /* Registrar role for STA not supported */
15380 send_resp(dut, conn, SIGMA_ERROR,
15381 "ErrorCode,Unsupported WpsRole value");
15382 goto fail;
15383 }
15384
15385 if (is_60g_sigma_dut(dut)) {
15386 if (dut->wps_method == WFA_CS_WPS_PBC)
15387 snprintf(buf, sizeof(buf), "WPS_PBC");
15388 else /* WFA_CS_WPS_PIN_KEYPAD */
15389 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
15390 dut->wps_pin);
15391 if (wpa_command(intf, buf) < 0) {
15392 send_resp(dut, conn, SIGMA_ERROR,
15393 "ErrorCode,Failed to start WPS");
vamsi krishna9b144002017-09-20 13:28:13 +053015394 goto fail;
15395 }
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020015396 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
15397 if (res < 0) {
15398 send_resp(dut, conn, SIGMA_ERROR,
15399 "ErrorCode,WPS connection did not complete");
15400 goto fail;
15401 }
15402 if (strstr(buf, "WPS-TIMEOUT")) {
15403 send_resp(dut, conn, SIGMA_COMPLETE, "WpsState,NoPeer");
15404 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
15405 send_resp(dut, conn, SIGMA_COMPLETE,
15406 "WpsState,OverlapSession");
15407 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
15408 send_resp(dut, conn, SIGMA_COMPLETE,
15409 "WpsState,Successful");
15410 } else {
15411 send_resp(dut, conn, SIGMA_COMPLETE,
15412 "WpsState,Failure");
15413 }
15414 } else {
15415 if (dut->wps_method == WFA_CS_WPS_PBC) {
vamsi krishna9b144002017-09-20 13:28:13 +053015416 if (wpa_command(intf, "WPS_PBC") < 0) {
15417 send_resp(dut, conn, SIGMA_ERROR,
15418 "ErrorCode,Failed to enable PBC");
15419 goto fail;
15420 }
15421 } else {
15422 /* TODO: PIN method */
15423 send_resp(dut, conn, SIGMA_ERROR,
15424 "ErrorCode,Unsupported WpsConfigMethod value");
15425 goto fail;
15426 }
15427 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
15428 if (res < 0) {
15429 send_resp(dut, conn, SIGMA_ERROR,
15430 "ErrorCode,WPS connection did not complete");
15431 goto fail;
15432 }
15433 if (strstr(buf, "WPS-TIMEOUT")) {
15434 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,NoPeer");
15435 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
15436 send_resp(dut, conn, SIGMA_ERROR,
15437 "ErrorCode,OverlapSession");
15438 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
15439 send_resp(dut, conn, SIGMA_COMPLETE, "Successful");
15440 } else {
15441 send_resp(dut, conn, SIGMA_ERROR,
15442 "ErrorCode,WPS operation failed");
15443 }
vamsi krishna9b144002017-09-20 13:28:13 +053015444 }
15445
15446fail:
15447 wpa_ctrl_detach(ctrl);
15448 wpa_ctrl_close(ctrl);
15449 return 0;
15450}
15451
15452
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015453static int req_intf(struct sigma_cmd *cmd)
15454{
15455 return get_param(cmd, "interface") == NULL ? -1 : 0;
15456}
15457
15458
15459void sta_register_cmds(void)
15460{
15461 sigma_dut_reg_cmd("sta_get_ip_config", req_intf,
15462 cmd_sta_get_ip_config);
15463 sigma_dut_reg_cmd("sta_set_ip_config", req_intf,
15464 cmd_sta_set_ip_config);
15465 sigma_dut_reg_cmd("sta_get_info", req_intf, cmd_sta_get_info);
15466 sigma_dut_reg_cmd("sta_get_mac_address", req_intf,
15467 cmd_sta_get_mac_address);
15468 sigma_dut_reg_cmd("sta_is_connected", req_intf, cmd_sta_is_connected);
15469 sigma_dut_reg_cmd("sta_verify_ip_connection", req_intf,
15470 cmd_sta_verify_ip_connection);
15471 sigma_dut_reg_cmd("sta_get_bssid", req_intf, cmd_sta_get_bssid);
15472 sigma_dut_reg_cmd("sta_set_encryption", req_intf,
15473 cmd_sta_set_encryption);
15474 sigma_dut_reg_cmd("sta_set_psk", req_intf, cmd_sta_set_psk);
15475 sigma_dut_reg_cmd("sta_set_eaptls", req_intf, cmd_sta_set_eaptls);
15476 sigma_dut_reg_cmd("sta_set_eapttls", req_intf, cmd_sta_set_eapttls);
15477 sigma_dut_reg_cmd("sta_set_eapsim", req_intf, cmd_sta_set_eapsim);
15478 sigma_dut_reg_cmd("sta_set_peap", req_intf, cmd_sta_set_peap);
15479 sigma_dut_reg_cmd("sta_set_eapfast", req_intf, cmd_sta_set_eapfast);
15480 sigma_dut_reg_cmd("sta_set_eapaka", req_intf, cmd_sta_set_eapaka);
15481 sigma_dut_reg_cmd("sta_set_eapakaprime", req_intf,
15482 cmd_sta_set_eapakaprime);
15483 sigma_dut_reg_cmd("sta_set_security", req_intf, cmd_sta_set_security);
15484 sigma_dut_reg_cmd("sta_set_uapsd", req_intf, cmd_sta_set_uapsd);
15485 /* TODO: sta_set_ibss */
15486 /* TODO: sta_set_mode */
15487 sigma_dut_reg_cmd("sta_set_wmm", req_intf, cmd_sta_set_wmm);
15488 sigma_dut_reg_cmd("sta_associate", req_intf, cmd_sta_associate);
15489 /* TODO: sta_up_load */
15490 sigma_dut_reg_cmd("sta_preset_testparameters", req_intf,
15491 cmd_sta_preset_testparameters);
15492 /* TODO: sta_set_system */
15493 sigma_dut_reg_cmd("sta_set_11n", req_intf, cmd_sta_set_11n);
15494 /* TODO: sta_set_rifs_test */
15495 sigma_dut_reg_cmd("sta_set_wireless", req_intf, cmd_sta_set_wireless);
15496 sigma_dut_reg_cmd("sta_send_addba", req_intf, cmd_sta_send_addba);
15497 /* TODO: sta_send_coexist_mgmt */
15498 sigma_dut_reg_cmd("sta_disconnect", req_intf, cmd_sta_disconnect);
15499 sigma_dut_reg_cmd("sta_reassoc", req_intf, cmd_sta_reassoc);
15500 sigma_dut_reg_cmd("sta_reassociate", req_intf, cmd_sta_reassoc);
15501 sigma_dut_reg_cmd("sta_reset_default", req_intf,
15502 cmd_sta_reset_default);
15503 sigma_dut_reg_cmd("sta_send_frame", req_intf, cmd_sta_send_frame);
15504 sigma_dut_reg_cmd("sta_set_macaddr", req_intf, cmd_sta_set_macaddr);
15505 sigma_dut_reg_cmd("sta_set_rfeature", req_intf, cmd_sta_set_rfeature);
15506 sigma_dut_reg_cmd("sta_set_radio", req_intf, cmd_sta_set_radio);
15507 sigma_dut_reg_cmd("sta_set_pwrsave", req_intf, cmd_sta_set_pwrsave);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020015508 sigma_dut_reg_cmd("sta_set_power_save", req_intf, cmd_sta_set_pwrsave);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015509 sigma_dut_reg_cmd("sta_bssid_pool", req_intf, cmd_sta_bssid_pool);
15510 sigma_dut_reg_cmd("sta_reset_parm", req_intf, cmd_sta_reset_parm);
15511 sigma_dut_reg_cmd("sta_get_key", req_intf, cmd_sta_get_key);
15512 sigma_dut_reg_cmd("sta_hs2_associate", req_intf,
15513 cmd_sta_hs2_associate);
Jouni Malinenb639f1c2018-09-13 02:39:46 +030015514 sigma_dut_reg_cmd("sta_hs2_venue_info", req_intf,
15515 cmd_sta_hs2_venue_info);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015516 sigma_dut_reg_cmd("sta_add_credential", req_intf,
15517 cmd_sta_add_credential);
15518 sigma_dut_reg_cmd("sta_scan", req_intf, cmd_sta_scan);
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020015519 sigma_dut_reg_cmd("sta_scan_bss", req_intf, cmd_sta_scan_bss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015520 sigma_dut_reg_cmd("sta_set_systime", NULL, cmd_sta_set_systime);
15521 sigma_dut_reg_cmd("sta_osu", req_intf, cmd_sta_osu);
15522 sigma_dut_reg_cmd("sta_policy_update", req_intf, cmd_sta_policy_update);
15523 sigma_dut_reg_cmd("sta_er_config", NULL, cmd_sta_er_config);
15524 sigma_dut_reg_cmd("sta_wps_connect_pw_token", req_intf,
15525 cmd_sta_wps_connect_pw_token);
Jouni Malinen82905202018-04-29 17:20:10 +030015526 sigma_dut_reg_cmd("sta_exec_action", NULL, cmd_sta_exec_action);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015527 sigma_dut_reg_cmd("sta_get_events", req_intf, cmd_sta_get_events);
15528 sigma_dut_reg_cmd("sta_get_parameter", req_intf, cmd_sta_get_parameter);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020015529 sigma_dut_reg_cmd("start_wps_registration", NULL,
vamsi krishna9b144002017-09-20 13:28:13 +053015530 cmd_start_wps_registration);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015531}