blob: 994a1838b5bb31036a1290482034dc64eef1c5eb [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 Malinen2feb9132021-11-16 00:53:06 +02005 * Copyright (c) 2018-2021, 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) {
Vinita S. Maloo069e8d42021-04-29 13:15:08 +05301586#ifdef ANDROID
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001587 /* TODO */
1588 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored primary-dns %s "
1589 "setting", val);
Vinita S. Maloo069e8d42021-04-29 13:15:08 +05301590#else /* ANDROID */
1591 char dns_cmd[200];
1592 int len;
1593
1594 if (system("sed -i '/nameserver/d' /etc/resolv.conf") != 0) {
1595 sigma_dut_print(dut, DUT_MSG_ERROR,
1596 "Failed to clear nameserver entries in /etc/resolv.conf");
1597 return ERROR_SEND_STATUS;
1598 }
1599
1600 len = snprintf(dns_cmd, sizeof(dns_cmd),
1601 "sed -i '1 i nameserver %s' /etc/resolv.conf", val);
1602 if (len < 0 || len >= sizeof(dns_cmd))
1603 return ERROR_SEND_STATUS;
1604
1605 sigma_dut_print(dut, DUT_MSG_DEBUG, "Running %s", dns_cmd);
1606 if (system(dns_cmd) != 0) {
1607 send_resp(dut, conn, SIGMA_ERROR,
1608 "ErrorCode,Failed to set primary-dns");
1609 return STATUS_SENT_ERROR;
1610 }
1611#endif /* ANDROID */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001612 }
1613
1614 val = get_param(cmd, "secondary-dns");
1615 if (val) {
1616 /* TODO */
1617 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored secondary-dns %s "
1618 "setting", val);
1619 }
1620
1621 static_ip_file(4, ip, mask, gw);
1622
1623 return 1;
1624}
1625
1626
Jouni Malinenf7222712019-06-13 01:50:21 +03001627static enum sigma_cmd_result cmd_sta_get_info(struct sigma_dut *dut,
1628 struct sigma_conn *conn,
1629 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001630{
1631 /* const char *intf = get_param(cmd, "Interface"); */
1632 /* TODO: could report more details here */
1633 send_resp(dut, conn, SIGMA_COMPLETE, "vendor,Atheros");
1634 return 0;
1635}
1636
1637
Jouni Malinenf7222712019-06-13 01:50:21 +03001638static enum sigma_cmd_result cmd_sta_get_mac_address(struct sigma_dut *dut,
1639 struct sigma_conn *conn,
1640 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001641{
1642 /* const char *intf = get_param(cmd, "Interface"); */
1643 char addr[20], resp[50];
1644
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05301645 if (dut->dev_role == DEVROLE_STA_CFON)
1646 return sta_cfon_get_mac_address(dut, conn, cmd);
1647
Jouni Malinen9540e012019-11-05 17:08:42 +02001648 start_sta_mode(dut);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001649 if (get_wpa_status(get_station_ifname(dut), "address",
1650 addr, sizeof(addr)) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001651 return -2;
1652
1653 snprintf(resp, sizeof(resp), "mac,%s", addr);
1654 send_resp(dut, conn, SIGMA_COMPLETE, resp);
1655 return 0;
1656}
1657
1658
Jouni Malinenf7222712019-06-13 01:50:21 +03001659static enum sigma_cmd_result cmd_sta_is_connected(struct sigma_dut *dut,
1660 struct sigma_conn *conn,
1661 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001662{
1663 /* const char *intf = get_param(cmd, "Interface"); */
1664 int connected = 0;
1665 char result[32];
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001666 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001667 sizeof(result)) < 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001668 sigma_dut_print(dut, DUT_MSG_INFO,
1669 "Could not get interface %s status",
1670 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001671 return -2;
1672 }
1673
1674 sigma_dut_print(dut, DUT_MSG_DEBUG, "wpa_state=%s", result);
1675 if (strncmp(result, "COMPLETED", 9) == 0)
1676 connected = 1;
1677
1678 if (connected)
1679 send_resp(dut, conn, SIGMA_COMPLETE, "connected,1");
1680 else
1681 send_resp(dut, conn, SIGMA_COMPLETE, "connected,0");
1682
1683 return 0;
1684}
1685
1686
Jouni Malinenf7222712019-06-13 01:50:21 +03001687static enum sigma_cmd_result
1688cmd_sta_verify_ip_connection(struct sigma_dut *dut, struct sigma_conn *conn,
1689 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001690{
1691 /* const char *intf = get_param(cmd, "Interface"); */
1692 const char *dst, *timeout;
1693 int wait_time = 90;
1694 char buf[100];
1695 int res;
1696
1697 dst = get_param(cmd, "destination");
1698 if (dst == NULL || !is_ip_addr(dst))
1699 return -1;
1700
1701 timeout = get_param(cmd, "timeout");
1702 if (timeout) {
1703 wait_time = atoi(timeout);
1704 if (wait_time < 1)
1705 wait_time = 1;
1706 }
1707
1708 /* TODO: force renewal of IP lease if DHCP is enabled */
1709
1710 snprintf(buf, sizeof(buf), "ping %s -c 3 -W %d", dst, wait_time);
1711 res = system(buf);
1712 sigma_dut_print(dut, DUT_MSG_DEBUG, "ping returned: %d", res);
1713 if (res == 0)
1714 send_resp(dut, conn, SIGMA_COMPLETE, "connected,1");
1715 else if (res == 256)
1716 send_resp(dut, conn, SIGMA_COMPLETE, "connected,0");
1717 else
1718 return -2;
1719
1720 return 0;
1721}
1722
1723
Jouni Malinenf7222712019-06-13 01:50:21 +03001724static enum sigma_cmd_result cmd_sta_get_bssid(struct sigma_dut *dut,
1725 struct sigma_conn *conn,
1726 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001727{
1728 /* const char *intf = get_param(cmd, "Interface"); */
1729 char bssid[20], resp[50];
1730
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001731 if (get_wpa_status(get_station_ifname(dut), "bssid",
1732 bssid, sizeof(bssid)) < 0)
Peng Xub8fc5cc2017-05-10 17:27:28 -07001733 strlcpy(bssid, "00:00:00:00:00:00", sizeof(bssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001734
1735 snprintf(resp, sizeof(resp), "bssid,%s", bssid);
1736 send_resp(dut, conn, SIGMA_COMPLETE, resp);
1737 return 0;
1738}
1739
1740
1741#ifdef __SAMSUNG__
1742static int add_use_network(const char *ifname)
1743{
1744 char buf[100];
1745
1746 snprintf(buf, sizeof(buf), "USE_NETWORK ON");
1747 wpa_command(ifname, buf);
1748 return 0;
1749}
1750#endif /* __SAMSUNG__ */
1751
1752
1753static int add_network_common(struct sigma_dut *dut, struct sigma_conn *conn,
1754 const char *ifname, struct sigma_cmd *cmd)
1755{
1756 const char *ssid = get_param(cmd, "ssid");
1757 int id;
1758 const char *val;
1759
1760 if (ssid == NULL)
1761 return -1;
1762
1763 start_sta_mode(dut);
1764
1765#ifdef __SAMSUNG__
1766 add_use_network(ifname);
1767#endif /* __SAMSUNG__ */
1768
1769 id = add_network(ifname);
1770 if (id < 0)
1771 return -2;
1772 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding network %d", id);
1773
1774 if (set_network_quoted(ifname, id, "ssid", ssid) < 0)
1775 return -2;
1776
1777 dut->infra_network_id = id;
1778 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
1779
1780 val = get_param(cmd, "program");
1781 if (!val)
1782 val = get_param(cmd, "prog");
1783 if (val && strcasecmp(val, "hs2") == 0) {
1784 char buf[100];
1785 snprintf(buf, sizeof(buf), "ENABLE_NETWORK %d no-connect", id);
1786 wpa_command(ifname, buf);
1787
1788 val = get_param(cmd, "prefer");
1789 if (val && atoi(val) > 0)
1790 set_network(ifname, id, "priority", "1");
1791 }
1792
1793 return id;
1794}
1795
1796
Jouni Malinenf7222712019-06-13 01:50:21 +03001797static enum sigma_cmd_result cmd_sta_set_encryption(struct sigma_dut *dut,
1798 struct sigma_conn *conn,
1799 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001800{
1801 const char *intf = get_param(cmd, "Interface");
1802 const char *ssid = get_param(cmd, "ssid");
1803 const char *type = get_param(cmd, "encpType");
1804 const char *ifname;
1805 char buf[200];
1806 int id;
1807
1808 if (intf == NULL || ssid == NULL)
1809 return -1;
1810
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001811 if (strcmp(intf, get_main_ifname(dut)) == 0)
1812 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001813 else
1814 ifname = intf;
1815
1816 id = add_network_common(dut, conn, ifname, cmd);
1817 if (id < 0)
1818 return id;
1819
1820 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
1821 return -2;
1822
1823 if (type && strcasecmp(type, "wep") == 0) {
1824 const char *val;
1825 int i;
1826
1827 val = get_param(cmd, "activeKey");
1828 if (val) {
1829 int keyid;
1830 keyid = atoi(val);
1831 if (keyid < 1 || keyid > 4)
1832 return -1;
1833 snprintf(buf, sizeof(buf), "%d", keyid - 1);
1834 if (set_network(ifname, id, "wep_tx_keyidx", buf) < 0)
1835 return -2;
1836 }
1837
1838 for (i = 0; i < 4; i++) {
1839 snprintf(buf, sizeof(buf), "key%d", i + 1);
1840 val = get_param(cmd, buf);
1841 if (val == NULL)
1842 continue;
1843 snprintf(buf, sizeof(buf), "wep_key%d", i);
1844 if (set_network(ifname, id, buf, val) < 0)
1845 return -2;
1846 }
1847 }
1848
1849 return 1;
1850}
1851
1852
Jouni Malinene4fde732019-03-25 22:29:37 +02001853static int set_akm_suites(struct sigma_dut *dut, const char *ifname,
1854 int id, const char *val)
1855{
1856 char key_mgmt[200], *end, *pos;
1857 const char *in_pos = val;
1858
Jouni Malinen8179fee2019-03-28 03:19:47 +02001859 dut->akm_values = 0;
Jouni Malinene4fde732019-03-25 22:29:37 +02001860 pos = key_mgmt;
1861 end = pos + sizeof(key_mgmt);
1862 while (*in_pos) {
1863 int res, akm = atoi(in_pos);
1864 const char *str;
1865
Jouni Malinen8179fee2019-03-28 03:19:47 +02001866 if (akm >= 0 && akm < 32)
1867 dut->akm_values |= 1 << akm;
1868
Jouni Malinene4fde732019-03-25 22:29:37 +02001869 switch (akm) {
1870 case AKM_WPA_EAP:
1871 str = "WPA-EAP";
1872 break;
1873 case AKM_WPA_PSK:
1874 str = "WPA-PSK";
1875 break;
1876 case AKM_FT_EAP:
1877 str = "FT-EAP";
1878 break;
1879 case AKM_FT_PSK:
1880 str = "FT-PSK";
1881 break;
1882 case AKM_EAP_SHA256:
1883 str = "WPA-EAP-SHA256";
1884 break;
1885 case AKM_PSK_SHA256:
1886 str = "WPA-PSK-SHA256";
1887 break;
1888 case AKM_SAE:
1889 str = "SAE";
1890 break;
1891 case AKM_FT_SAE:
1892 str = "FT-SAE";
1893 break;
1894 case AKM_SUITE_B:
1895 str = "WPA-EAP-SUITE-B-192";
1896 break;
1897 case AKM_FT_SUITE_B:
1898 str = "FT-EAP-SHA384";
1899 break;
1900 case AKM_FILS_SHA256:
1901 str = "FILS-SHA256";
1902 break;
1903 case AKM_FILS_SHA384:
1904 str = "FILS-SHA384";
1905 break;
1906 case AKM_FT_FILS_SHA256:
1907 str = "FT-FILS-SHA256";
1908 break;
1909 case AKM_FT_FILS_SHA384:
1910 str = "FT-FILS-SHA384";
1911 break;
1912 default:
1913 sigma_dut_print(dut, DUT_MSG_ERROR,
1914 "Unsupported AKMSuitetype %d", akm);
1915 return -1;
1916 }
1917
1918 res = snprintf(pos, end - pos, "%s%s",
1919 pos == key_mgmt ? "" : " ", str);
1920 if (res < 0 || res >= end - pos)
1921 return -1;
1922 pos += res;
1923
1924 in_pos = strchr(in_pos, ';');
1925 if (!in_pos)
1926 break;
1927 while (*in_pos == ';')
1928 in_pos++;
1929 }
1930 sigma_dut_print(dut, DUT_MSG_DEBUG, "AKMSuiteType %s --> %s",
1931 val, key_mgmt);
1932 return set_network(ifname, id, "key_mgmt", key_mgmt);
1933}
1934
1935
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001936static int set_wpa_common(struct sigma_dut *dut, struct sigma_conn *conn,
1937 const char *ifname, struct sigma_cmd *cmd)
1938{
1939 const char *val;
1940 int id;
Jouni Malinenad395a22017-09-01 21:13:46 +03001941 int cipher_set = 0;
Jouni Malinen47dcc952017-10-09 16:43:24 +03001942 int owe;
Sunil Duttc75a1e62018-01-11 20:47:50 +05301943 int suite_b = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001944
1945 id = add_network_common(dut, conn, ifname, cmd);
1946 if (id < 0)
1947 return id;
1948
Jouni Malinen47dcc952017-10-09 16:43:24 +03001949 val = get_param(cmd, "Type");
1950 owe = val && strcasecmp(val, "OWE") == 0;
1951
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001952 val = get_param(cmd, "keyMgmtType");
Jouni Malinen47dcc952017-10-09 16:43:24 +03001953 if (!val && owe)
1954 val = "OWE";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001955 if (val == NULL) {
Jouni Malinene4fde732019-03-25 22:29:37 +02001956 /* keyMgmtType is being replaced with AKMSuiteType, so ignore
1957 * this missing parameter and assume proto=WPA2. */
1958 if (set_network(ifname, id, "proto", "WPA2") < 0)
1959 return ERROR_SEND_STATUS;
1960 } else if (strcasecmp(val, "wpa") == 0 ||
1961 strcasecmp(val, "wpa-psk") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001962 if (set_network(ifname, id, "proto", "WPA") < 0)
1963 return -2;
1964 } else if (strcasecmp(val, "wpa2") == 0 ||
1965 strcasecmp(val, "wpa2-psk") == 0 ||
1966 strcasecmp(val, "wpa2-ft") == 0 ||
1967 strcasecmp(val, "wpa2-sha256") == 0) {
1968 if (set_network(ifname, id, "proto", "WPA2") < 0)
1969 return -2;
Pradeep Reddy POTTETI6d04b3b2016-11-15 14:51:26 +05301970 } else if (strcasecmp(val, "wpa2-wpa-psk") == 0 ||
1971 strcasecmp(val, "wpa2-wpa-ent") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001972 if (set_network(ifname, id, "proto", "WPA WPA2") < 0)
1973 return -2;
Jouni Malinenad395a22017-09-01 21:13:46 +03001974 } else if (strcasecmp(val, "SuiteB") == 0) {
Sunil Duttc75a1e62018-01-11 20:47:50 +05301975 suite_b = 1;
Jouni Malinenad395a22017-09-01 21:13:46 +03001976 if (set_network(ifname, id, "proto", "WPA2") < 0)
1977 return -2;
Jouni Malinen47dcc952017-10-09 16:43:24 +03001978 } else if (strcasecmp(val, "OWE") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001979 } else {
1980 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized keyMgmtType value");
1981 return 0;
1982 }
1983
1984 val = get_param(cmd, "encpType");
Jouni Malinenad395a22017-09-01 21:13:46 +03001985 if (val) {
1986 cipher_set = 1;
1987 if (strcasecmp(val, "tkip") == 0) {
1988 if (set_network(ifname, id, "pairwise", "TKIP") < 0)
1989 return -2;
1990 } else if (strcasecmp(val, "aes-ccmp") == 0) {
1991 if (set_network(ifname, id, "pairwise", "CCMP") < 0)
1992 return -2;
1993 } else if (strcasecmp(val, "aes-ccmp-tkip") == 0) {
1994 if (set_network(ifname, id, "pairwise",
1995 "CCMP TKIP") < 0)
1996 return -2;
1997 } else if (strcasecmp(val, "aes-gcmp") == 0) {
1998 if (set_network(ifname, id, "pairwise", "GCMP") < 0)
1999 return -2;
2000 if (set_network(ifname, id, "group", "GCMP") < 0)
2001 return -2;
2002 } else {
2003 send_resp(dut, conn, SIGMA_ERROR,
2004 "errorCode,Unrecognized encpType value");
2005 return 0;
2006 }
2007 }
2008
2009 val = get_param(cmd, "PairwiseCipher");
2010 if (val) {
2011 cipher_set = 1;
2012 /* TODO: Support space separated list */
2013 if (strcasecmp(val, "AES-GCMP-256") == 0) {
2014 if (set_network(ifname, id, "pairwise", "GCMP-256") < 0)
2015 return -2;
2016 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
2017 if (set_network(ifname, id, "pairwise",
2018 "CCMP-256") < 0)
2019 return -2;
2020 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
2021 if (set_network(ifname, id, "pairwise", "GCMP") < 0)
2022 return -2;
2023 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
2024 if (set_network(ifname, id, "pairwise", "CCMP") < 0)
2025 return -2;
2026 } else {
2027 send_resp(dut, conn, SIGMA_ERROR,
2028 "errorCode,Unrecognized PairwiseCipher value");
2029 return 0;
2030 }
2031 }
2032
Jouni Malinen47dcc952017-10-09 16:43:24 +03002033 if (!cipher_set && !owe) {
Jouni Malinenad395a22017-09-01 21:13:46 +03002034 send_resp(dut, conn, SIGMA_ERROR,
2035 "errorCode,Missing encpType and PairwiseCipher");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002036 return 0;
2037 }
Jouni Malinenad395a22017-09-01 21:13:46 +03002038
2039 val = get_param(cmd, "GroupCipher");
2040 if (val) {
2041 if (strcasecmp(val, "AES-GCMP-256") == 0) {
2042 if (set_network(ifname, id, "group", "GCMP-256") < 0)
2043 return -2;
2044 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
2045 if (set_network(ifname, id, "group", "CCMP-256") < 0)
2046 return -2;
2047 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
2048 if (set_network(ifname, id, "group", "GCMP") < 0)
2049 return -2;
2050 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
2051 if (set_network(ifname, id, "group", "CCMP") < 0)
2052 return -2;
2053 } else {
2054 send_resp(dut, conn, SIGMA_ERROR,
2055 "errorCode,Unrecognized GroupCipher value");
2056 return 0;
2057 }
2058 }
2059
Jouni Malinen7b239522017-09-14 21:37:18 +03002060 val = get_param(cmd, "GroupMgntCipher");
Jouni Malinenad395a22017-09-01 21:13:46 +03002061 if (val) {
Jouni Malinene8898cb2017-09-26 17:55:26 +03002062 const char *cipher;
2063
2064 if (strcasecmp(val, "BIP-GMAC-256") == 0) {
2065 cipher = "BIP-GMAC-256";
2066 } else if (strcasecmp(val, "BIP-CMAC-256") == 0) {
2067 cipher = "BIP-CMAC-256";
2068 } else if (strcasecmp(val, "BIP-GMAC-128") == 0) {
2069 cipher = "BIP-GMAC-128";
2070 } else if (strcasecmp(val, "BIP-CMAC-128") == 0) {
2071 cipher = "AES-128-CMAC";
2072 } else {
2073 send_resp(dut, conn, SIGMA_INVALID,
2074 "errorCode,Unsupported GroupMgntCipher");
2075 return 0;
2076 }
2077 if (set_network(ifname, id, "group_mgmt", cipher) < 0) {
2078 send_resp(dut, conn, SIGMA_INVALID,
2079 "errorCode,Failed to set GroupMgntCipher");
2080 return 0;
2081 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002082 }
2083
Jouni Malinene4fde732019-03-25 22:29:37 +02002084 val = get_param(cmd, "AKMSuiteType");
2085 if (val && set_akm_suites(dut, ifname, id, val) < 0)
2086 return ERROR_SEND_STATUS;
2087
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002088 dut->sta_pmf = STA_PMF_DISABLED;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302089
2090 if (dut->program == PROGRAM_OCE) {
2091 dut->sta_pmf = STA_PMF_OPTIONAL;
2092 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2093 return -2;
2094 }
2095
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002096 val = get_param(cmd, "PMF");
2097 if (val) {
2098 if (strcasecmp(val, "Required") == 0 ||
2099 strcasecmp(val, "Forced_Required") == 0) {
2100 dut->sta_pmf = STA_PMF_REQUIRED;
2101 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2102 return -2;
2103 } else if (strcasecmp(val, "Optional") == 0) {
2104 dut->sta_pmf = STA_PMF_OPTIONAL;
2105 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2106 return -2;
2107 } else if (strcasecmp(val, "Disabled") == 0 ||
Kiran Kumar Lokere07da3b22018-12-16 22:42:49 -08002108 strcasecmp(val, "Disable") == 0 ||
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002109 strcasecmp(val, "Forced_Disabled") == 0) {
2110 dut->sta_pmf = STA_PMF_DISABLED;
2111 } else {
2112 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized PMF value");
2113 return 0;
2114 }
Sunil Duttc75a1e62018-01-11 20:47:50 +05302115 } else if (owe || suite_b) {
Jouni Malinen1287cd72018-01-04 17:08:01 +02002116 dut->sta_pmf = STA_PMF_REQUIRED;
2117 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2118 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002119 }
2120
Jouni Malinen0165c7f2020-03-26 11:51:58 +02002121 val = get_param(cmd, "BeaconProtection");
Veerendranath Jakkamc1f71b62021-01-23 03:09:51 +05302122 if (val)
2123 dut->beacon_prot = atoi(val);
2124 if (dut->beacon_prot && set_network(ifname, id, "beacon_prot", "1") < 0)
Jouni Malinen0165c7f2020-03-26 11:51:58 +02002125 return ERROR_SEND_STATUS;
2126
Veerendranath Jakkam54fd51c2020-12-21 01:36:04 +05302127 if (dut->ocvc && set_network(ifname, id, "ocv", "1") < 0)
2128 return ERROR_SEND_STATUS;
2129
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002130 return id;
2131}
2132
2133
Veerendranath Jakkamca239592021-10-11 20:48:00 +05302134static int wcn_set_ignore_h2e_rsnxe(struct sigma_dut *dut, const char *intf,
2135 uint8_t cfg)
2136{
2137#ifdef NL80211_SUPPORT
2138 return wcn_wifi_test_config_set_u8(
2139 dut, intf,
2140 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_IGNORE_H2E_RSNXE, cfg);
2141#else /* NL80211_SUPPORT */
2142 sigma_dut_print(dut, DUT_MSG_ERROR,
2143 "Ignore SAE H2E requirement mismatch can't be set without NL80211_SUPPORT defined");
2144 return -1;
2145#endif /* NL80211_SUPPORT */
2146}
2147
2148
Jouni Malinenf7222712019-06-13 01:50:21 +03002149static enum sigma_cmd_result cmd_sta_set_psk(struct sigma_dut *dut,
2150 struct sigma_conn *conn,
2151 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002152{
2153 const char *intf = get_param(cmd, "Interface");
Jouni Malinen992a81e2017-08-22 13:57:47 +03002154 const char *type = get_param(cmd, "Type");
Jouni Malinen1287cd72018-01-04 17:08:01 +02002155 const char *pmf = get_param(cmd, "PMF");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002156 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinene4fde732019-03-25 22:29:37 +02002157 const char *akm = get_param(cmd, "AKMSuiteType");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002158 const char *ifname, *val, *alg;
2159 int id;
Jouni Malinen4b3769d2019-10-10 16:20:29 +03002160 char buf[50];
Jouni Malinen11e55212019-11-22 21:46:59 +02002161 int sae_pwe = -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002162
2163 if (intf == NULL)
2164 return -1;
2165
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002166 if (strcmp(intf, get_main_ifname(dut)) == 0)
2167 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002168 else
2169 ifname = intf;
2170
2171 id = set_wpa_common(dut, conn, ifname, cmd);
2172 if (id < 0)
2173 return id;
2174
2175 val = get_param(cmd, "keyMgmtType");
2176 alg = get_param(cmd, "micAlg");
2177
Jouni Malinen992a81e2017-08-22 13:57:47 +03002178 if (type && strcasecmp(type, "SAE") == 0) {
Jouni Malinene4fde732019-03-25 22:29:37 +02002179 if (!akm && val && strcasecmp(val, "wpa2-ft") == 0) {
Jouni Malinen992a81e2017-08-22 13:57:47 +03002180 if (set_network(ifname, id, "key_mgmt", "FT-SAE") < 0)
2181 return -2;
Jouni Malinene4fde732019-03-25 22:29:37 +02002182 } else if (!akm) {
Jouni Malinen992a81e2017-08-22 13:57:47 +03002183 if (set_network(ifname, id, "key_mgmt", "SAE") < 0)
2184 return -2;
2185 }
2186 if (wpa_command(ifname, "SET sae_groups ") != 0) {
2187 sigma_dut_print(dut, DUT_MSG_ERROR,
2188 "Failed to clear sae_groups to default");
2189 return -2;
2190 }
Jouni Malinen1287cd72018-01-04 17:08:01 +02002191 if (!pmf) {
2192 dut->sta_pmf = STA_PMF_REQUIRED;
2193 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2194 return -2;
2195 }
Jouni Malinen0ab50f42017-08-31 01:34:59 +03002196 } else if (type && strcasecmp(type, "PSK-SAE") == 0) {
2197 if (val && strcasecmp(val, "wpa2-ft") == 0) {
2198 if (set_network(ifname, id, "key_mgmt",
2199 "FT-SAE FT-PSK") < 0)
2200 return -2;
Jouni Malinen3b73d872019-06-12 03:13:25 +03002201 } else if (!akm) {
Jouni Malinen0ab50f42017-08-31 01:34:59 +03002202 if (set_network(ifname, id, "key_mgmt",
2203 "SAE WPA-PSK") < 0)
2204 return -2;
2205 }
2206 if (wpa_command(ifname, "SET sae_groups ") != 0) {
2207 sigma_dut_print(dut, DUT_MSG_ERROR,
2208 "Failed to clear sae_groups to default");
2209 return -2;
2210 }
Jouni Malinen1287cd72018-01-04 17:08:01 +02002211 if (!pmf) {
2212 dut->sta_pmf = STA_PMF_OPTIONAL;
2213 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2214 return -2;
2215 }
Jouni Malinen992a81e2017-08-22 13:57:47 +03002216 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002217 if (set_network(ifname, id, "key_mgmt", "WPA-PSK-SHA256") < 0)
2218 return -2;
2219 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
2220 if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0)
2221 return -2;
Ashwini Patil6dbf7b02017-03-20 13:42:11 +05302222 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
2223 if (set_network(ifname, id, "key_mgmt", "FT-PSK") < 0)
2224 return -2;
Jouni Malinen3b73d872019-06-12 03:13:25 +03002225 } else if (!akm &&
2226 ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
2227 dut->sta_pmf == STA_PMF_REQUIRED)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002228 if (set_network(ifname, id, "key_mgmt",
2229 "WPA-PSK WPA-PSK-SHA256") < 0)
2230 return -2;
Jouni Malinen77ff3f02019-03-28 03:45:40 +02002231 } else if (!akm && dut->sta_pmf == STA_PMF_OPTIONAL) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002232 if (set_network(ifname, id, "key_mgmt",
2233 "WPA-PSK WPA-PSK-SHA256") < 0)
2234 return -2;
Jouni Malinen77ff3f02019-03-28 03:45:40 +02002235 } else if (!akm) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002236 if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0)
2237 return -2;
2238 }
2239
2240 val = get_param(cmd, "passPhrase");
2241 if (val == NULL)
2242 return -1;
Jouni Malinen2126f422017-10-11 23:24:33 +03002243 if (type && strcasecmp(type, "SAE") == 0) {
2244 if (set_network_quoted(ifname, id, "sae_password", val) < 0)
2245 return -2;
2246 } else {
2247 if (set_network_quoted(ifname, id, "psk", val) < 0)
2248 return -2;
2249 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002250
Jouni Malinen78d10c42019-03-25 22:34:32 +02002251 val = get_param(cmd, "PasswordId");
2252 if (val && set_network_quoted(ifname, id, "sae_password_id", val) < 0)
2253 return ERROR_SEND_STATUS;
2254
Jouni Malinen992a81e2017-08-22 13:57:47 +03002255 val = get_param(cmd, "ECGroupID");
2256 if (val) {
Jouni Malinenb54f0df2019-12-12 01:57:29 +02002257 snprintf(buf, sizeof(buf), "SET sae_groups %s", val);
Jouni Malinen992a81e2017-08-22 13:57:47 +03002258 if (wpa_command(ifname, buf) != 0) {
2259 sigma_dut_print(dut, DUT_MSG_ERROR,
2260 "Failed to clear sae_groups");
2261 return -2;
2262 }
2263 }
2264
Jouni Malinen68143132017-09-02 02:34:08 +03002265 val = get_param(cmd, "InvalidSAEElement");
2266 if (val) {
2267 free(dut->sae_commit_override);
2268 dut->sae_commit_override = strdup(val);
2269 }
2270
Jouni Malinen4b3769d2019-10-10 16:20:29 +03002271 val = get_param(cmd, "PMKID_Include");
2272 if (val) {
2273 snprintf(buf, sizeof(buf), "SET sae_pmkid_in_assoc %d",
2274 get_enable_disable(val));
2275 wpa_command(intf, buf);
2276 }
2277
Jouni Malineneeb43d32019-12-06 17:40:07 +02002278 val = get_param(cmd, "IgnoreH2E_RSNXE_BSSMemSel");
2279 if (val) {
2280 snprintf(buf, sizeof(buf), "SET ignore_sae_h2e_only %d",
2281 get_enable_disable(val));
2282 wpa_command(intf, buf);
Veerendranath Jakkamca239592021-10-11 20:48:00 +05302283 if (get_driver_type(dut) == DRIVER_WCN)
2284 wcn_set_ignore_h2e_rsnxe(dut, intf,
2285 get_enable_disable(val));
Jouni Malineneeb43d32019-12-06 17:40:07 +02002286 }
2287
Jouni Malinenf2348d22019-12-07 11:52:55 +02002288 val = get_param(cmd, "ECGroupID_RGE");
2289 if (val) {
2290 snprintf(buf, sizeof(buf), "SET extra_sae_rejected_groups %s",
2291 val);
2292 wpa_command(intf, buf);
2293 }
2294
Jouni Malinen99e55022019-12-07 13:59:41 +02002295 val = get_param(cmd, "RSNXE_Content");
2296 if (val) {
2297 const char *param;
2298
2299 if (strncasecmp(val, "AssocReq:", 9) == 0) {
2300 val += 9;
2301 param = "rsnxe_override_assoc";
2302 } else if (strncasecmp(val, "EapolM2:", 8) == 0) {
2303 val += 8;
2304 param = "rsnxe_override_eapol";
2305 } else {
2306 send_resp(dut, conn, SIGMA_ERROR,
2307 "errorCode,Unsupported RSNXE_Content value");
2308 return STATUS_SENT_ERROR;
2309 }
2310 snprintf(buf, sizeof(buf), "SET %s %s", param, val);
2311 wpa_command(intf, buf);
2312 }
2313
Jouni Malinen11e55212019-11-22 21:46:59 +02002314 val = get_param(cmd, "sae_pwe");
2315 if (val) {
2316 if (strcasecmp(val, "h2e") == 0) {
2317 dut->sae_pwe = SAE_PWE_H2E;
Jouni Malinen7244a412019-12-07 11:54:10 +02002318 } else if (strcasecmp(val, "loop") == 0 ||
2319 strcasecmp(val, "looping") == 0) {
Jouni Malinen11e55212019-11-22 21:46:59 +02002320 dut->sae_pwe = SAE_PWE_LOOP;
2321 } else {
2322 send_resp(dut, conn, SIGMA_ERROR,
2323 "errorCode,Unsupported sae_pwe value");
2324 return STATUS_SENT_ERROR;
2325 }
2326 }
Vinita S. Maloo6d7454f2020-04-02 15:03:26 +05302327
2328 val = get_param(cmd, "Clear_RSNXE");
2329 if (val && strcmp(val, "1") == 0 &&
2330 (wpa_command(intf, "SET rsnxe_override_assoc ") ||
2331 wpa_command(intf, "SET rsnxe_override_eapol "))) {
2332 send_resp(dut, conn, SIGMA_ERROR,
2333 "errorCode,Failed to clear RSNXE");
Jouni Malinenb11498c2020-08-03 11:05:53 +03002334 return STATUS_SENT_ERROR;
Vinita S. Maloo6d7454f2020-04-02 15:03:26 +05302335 }
2336
Jouni Malinenc0078772020-03-04 21:23:16 +02002337 if (dut->sae_pwe == SAE_PWE_LOOP && get_param(cmd, "PasswordId"))
2338 sae_pwe = 3;
2339 else if (dut->sae_pwe == SAE_PWE_LOOP)
Jouni Malinen11e55212019-11-22 21:46:59 +02002340 sae_pwe = 0;
2341 else if (dut->sae_pwe == SAE_PWE_H2E)
2342 sae_pwe = 1;
2343 else if (dut->sae_h2e_default)
2344 sae_pwe = 2;
2345 snprintf(buf, sizeof(buf), "SET sae_pwe %d", sae_pwe);
2346 if (sae_pwe >= 0 && wpa_command(ifname, buf) != 0)
2347 return ERROR_SEND_STATUS;
2348
Veerendranath Jakkam0316be12020-06-23 20:11:41 +05302349 val = get_param(cmd, "sae_pk");
2350 if (val && strcmp(val, "0") == 0 &&
2351 set_network(ifname, id, "sae_pk", "2") < 0)
2352 return ERROR_SEND_STATUS;
2353
Veerendranath Jakkama9177042020-08-10 00:14:03 +05302354 val = get_param(cmd, "sae_pk_only");
2355 if (val && strcmp(val, "1") == 0 &&
2356 set_network(ifname, id, "sae_pk", "1") < 0)
2357 return ERROR_SEND_STATUS;
2358
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002359 if (dut->program == PROGRAM_60GHZ && network_mode &&
2360 strcasecmp(network_mode, "PBSS") == 0 &&
2361 set_network(ifname, id, "pbss", "1") < 0)
2362 return -2;
2363
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002364 return 1;
2365}
2366
2367
Jouni Malinen8ac93452019-08-14 15:19:13 +03002368static enum sigma_cmd_result set_trust_root_system(struct sigma_dut *dut,
2369 struct sigma_conn *conn,
2370 const char *ifname, int id)
2371{
2372 char buf[200];
2373
2374 snprintf(buf, sizeof(buf), "%s/certs", sigma_cert_path);
2375 if (!file_exists(buf))
2376 strlcpy(buf, "/system/etc/security/cacerts", sizeof(buf));
2377 if (!file_exists(buf))
2378 strlcpy(buf, "/etc/ssl/certs", sizeof(buf));
2379 if (!file_exists(buf)) {
2380 char msg[300];
2381
2382 snprintf(msg, sizeof(msg),
2383 "ErrorCode,trustedRootCA system store (%s) not found",
2384 buf);
2385 send_resp(dut, conn, SIGMA_ERROR, msg);
2386 return STATUS_SENT_ERROR;
2387 }
2388
2389 if (set_network_quoted(ifname, id, "ca_path", buf) < 0)
2390 return ERROR_SEND_STATUS;
2391
2392 return SUCCESS_SEND_STATUS;
2393}
2394
2395
2396static enum sigma_cmd_result set_trust_root(struct sigma_dut *dut,
2397 struct sigma_conn *conn,
2398 const char *ifname, int id,
2399 const char *val)
2400{
2401 char buf[200];
2402#ifdef ANDROID
2403 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
2404 int length;
2405#endif /* ANDROID */
2406
2407 if (strcmp(val, "DEFAULT") == 0)
2408 return set_trust_root_system(dut, conn, ifname, id);
2409
2410#ifdef ANDROID
2411 snprintf(buf, sizeof(buf), "CACERT_%s", val);
2412 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
2413 if (length > 0) {
2414 sigma_dut_print(dut, DUT_MSG_INFO, "Use Android keystore [%s]",
2415 buf);
2416 snprintf(buf, sizeof(buf), "keystore://CACERT_%s", val);
2417 goto ca_cert_selected;
2418 }
2419#endif /* ANDROID */
2420
2421 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
2422#ifdef __linux__
2423 if (!file_exists(buf)) {
2424 char msg[300];
2425
2426 snprintf(msg, sizeof(msg),
2427 "ErrorCode,trustedRootCA file (%s) not found", buf);
2428 send_resp(dut, conn, SIGMA_ERROR, msg);
2429 return STATUS_SENT_ERROR;
2430 }
2431#endif /* __linux__ */
2432#ifdef ANDROID
2433ca_cert_selected:
2434#endif /* ANDROID */
2435 if (set_network_quoted(ifname, id, "ca_cert", buf) < 0)
2436 return ERROR_SEND_STATUS;
2437
2438 return SUCCESS_SEND_STATUS;
2439}
2440
2441
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002442static int set_eap_common(struct sigma_dut *dut, struct sigma_conn *conn,
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302443 const char *ifname, int username_identity,
2444 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002445{
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002446 const char *val, *alg, *akm, *trust_root, *domain, *domain_suffix;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002447 int id;
Jouni Malinen53264f62019-05-03 13:04:40 +03002448 char buf[200], buf2[300];
Jouni Malinen8179fee2019-03-28 03:19:47 +02002449 int erp = 0;
Jouni Malinen8ac93452019-08-14 15:19:13 +03002450 enum sigma_cmd_result res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002451
2452 id = set_wpa_common(dut, conn, ifname, cmd);
2453 if (id < 0)
2454 return id;
2455
2456 val = get_param(cmd, "keyMgmtType");
2457 alg = get_param(cmd, "micAlg");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302458 akm = get_param(cmd, "AKMSuiteType");
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002459 trust_root = get_param(cmd, "trustedRootCA");
2460 domain = get_param(cmd, "Domain");
2461 domain_suffix = get_param(cmd, "DomainSuffix");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002462
Jouni Malinenad395a22017-09-01 21:13:46 +03002463 if (val && strcasecmp(val, "SuiteB") == 0) {
2464 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SUITE-B-192") <
2465 0)
2466 return -2;
2467 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002468 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SHA256") < 0)
2469 return -2;
2470 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
2471 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
2472 return -2;
2473 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
2474 if (set_network(ifname, id, "key_mgmt", "FT-EAP") < 0)
2475 return -2;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002476 } else if (!akm &&
2477 ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
2478 dut->sta_pmf == STA_PMF_REQUIRED)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002479 if (set_network(ifname, id, "key_mgmt",
2480 "WPA-EAP WPA-EAP-SHA256") < 0)
2481 return -2;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302482 } else if (akm && atoi(akm) == 14) {
2483 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
2484 dut->sta_pmf == STA_PMF_REQUIRED) {
2485 if (set_network(ifname, id, "key_mgmt",
2486 "WPA-EAP-SHA256 FILS-SHA256") < 0)
2487 return -2;
2488 } else {
2489 if (set_network(ifname, id, "key_mgmt",
2490 "WPA-EAP FILS-SHA256") < 0)
2491 return -2;
2492 }
2493
Jouni Malinen8179fee2019-03-28 03:19:47 +02002494 erp = 1;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302495 } else if (akm && atoi(akm) == 15) {
2496 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
2497 dut->sta_pmf == STA_PMF_REQUIRED) {
2498 if (set_network(ifname, id, "key_mgmt",
2499 "WPA-EAP-SHA256 FILS-SHA384") < 0)
2500 return -2;
2501 } else {
2502 if (set_network(ifname, id, "key_mgmt",
2503 "WPA-EAP FILS-SHA384") < 0)
2504 return -2;
2505 }
2506
Jouni Malinen8179fee2019-03-28 03:19:47 +02002507 erp = 1;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002508 } else if (!akm && dut->sta_pmf == STA_PMF_OPTIONAL) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002509 if (set_network(ifname, id, "key_mgmt",
2510 "WPA-EAP WPA-EAP-SHA256") < 0)
2511 return -2;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002512 } else if (!akm) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002513 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
2514 return -2;
2515 }
2516
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002517 if (trust_root) {
2518 if (strcmp(trust_root, "DEFAULT") == 0 && !domain &&
2519 !domain_suffix) {
2520 send_resp(dut, conn, SIGMA_ERROR,
2521 "errorCode,trustRootCA DEFAULT used without specifying Domain or DomainSuffix");
2522 return STATUS_SENT_ERROR;
2523 }
2524 res = set_trust_root(dut, conn, ifname, id, trust_root);
Jouni Malinen8ac93452019-08-14 15:19:13 +03002525 if (res != SUCCESS_SEND_STATUS)
2526 return res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002527 }
2528
Jouni Malinen53264f62019-05-03 13:04:40 +03002529 val = get_param(cmd, "ServerCert");
2530 if (val) {
2531 FILE *f;
2532 char *result = NULL, *pos;
2533
2534 snprintf(buf, sizeof(buf), "%s/%s.sha256", sigma_cert_path,
2535 val);
2536 f = fopen(buf, "r");
2537 if (f) {
2538 result = fgets(buf, sizeof(buf), f);
2539 fclose(f);
2540 }
2541 if (!result) {
2542 snprintf(buf2, sizeof(buf2),
2543 "ErrorCode,ServerCert hash could not be read from %s",
2544 buf);
2545 send_resp(dut, conn, SIGMA_ERROR, buf2);
2546 return STATUS_SENT_ERROR;
2547 }
2548 pos = strchr(buf, '\n');
2549 if (pos)
2550 *pos = '\0';
Jouni Malinen0572a742020-10-08 13:53:25 +03002551 pos = strchr(buf, '\r');
2552 if (pos)
2553 *pos = '\0';
Jouni Malinen53264f62019-05-03 13:04:40 +03002554 snprintf(buf2, sizeof(buf2), "hash://server/sha256/%s", buf);
2555 if (set_network_quoted(ifname, id, "ca_cert", buf2) < 0)
2556 return ERROR_SEND_STATUS;
Jouni Malinen29108dc2019-06-13 23:42:11 +03002557
2558 snprintf(buf, sizeof(buf), "%s/%s.tod", sigma_cert_path, val);
2559 if (file_exists(buf)) {
2560 sigma_dut_print(dut, DUT_MSG_DEBUG,
2561 "TOD policy enabled for the configured ServerCert hash");
2562 dut->sta_tod_policy = 1;
2563 }
Jouni Malinen53264f62019-05-03 13:04:40 +03002564 }
2565
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002566 if (domain &&
2567 set_network_quoted(ifname, id, "domain_match", domain) < 0)
Jouni Malinen96f84b02019-05-03 12:32:56 +03002568 return ERROR_SEND_STATUS;
2569
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002570 if (domain_suffix &&
2571 set_network_quoted(ifname, id, "domain_suffix_match",
2572 domain_suffix) < 0)
Jouni Malinen96f84b02019-05-03 12:32:56 +03002573 return ERROR_SEND_STATUS;
2574
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302575 if (username_identity) {
2576 val = get_param(cmd, "username");
2577 if (val) {
2578 if (set_network_quoted(ifname, id, "identity", val) < 0)
2579 return -2;
2580 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002581
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302582 val = get_param(cmd, "password");
2583 if (val) {
2584 if (set_network_quoted(ifname, id, "password", val) < 0)
2585 return -2;
2586 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002587 }
2588
Jouni Malinen8179fee2019-03-28 03:19:47 +02002589 if (dut->akm_values &
2590 ((1 << AKM_FILS_SHA256) |
2591 (1 << AKM_FILS_SHA384) |
2592 (1 << AKM_FT_FILS_SHA256) |
2593 (1 << AKM_FT_FILS_SHA384)))
2594 erp = 1;
2595 if (erp && set_network(ifname, id, "erp", "1") < 0)
2596 return ERROR_SEND_STATUS;
2597
Jouni Malinen134fe3c2019-06-12 04:16:49 +03002598 dut->sta_associate_wait_connect = 1;
2599
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002600 return id;
2601}
2602
2603
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002604static int set_tls_cipher(const char *ifname, int id, const char *cipher)
2605{
2606 const char *val;
2607
2608 if (!cipher)
2609 return 0;
2610
2611 if (strcasecmp(cipher, "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384") == 0)
2612 val = "ECDHE-ECDSA-AES256-GCM-SHA384";
2613 else if (strcasecmp(cipher,
2614 "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
2615 val = "ECDHE-RSA-AES256-GCM-SHA384";
2616 else if (strcasecmp(cipher, "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
2617 val = "DHE-RSA-AES256-GCM-SHA384";
2618 else if (strcasecmp(cipher,
2619 "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256") == 0)
2620 val = "ECDHE-ECDSA-AES128-GCM-SHA256";
2621 else
2622 return -1;
2623
2624 /* Need to clear phase1="tls_suiteb=1" to allow cipher enforcement */
2625 set_network_quoted(ifname, id, "phase1", "");
2626
2627 return set_network_quoted(ifname, id, "openssl_ciphers", val);
2628}
2629
2630
Jouni Malinenf7222712019-06-13 01:50:21 +03002631static enum sigma_cmd_result cmd_sta_set_eaptls(struct sigma_dut *dut,
2632 struct sigma_conn *conn,
2633 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002634{
2635 const char *intf = get_param(cmd, "Interface");
2636 const char *ifname, *val;
2637 int id;
2638 char buf[200];
2639#ifdef ANDROID
2640 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
2641 int length;
2642 int jb_or_newer = 0;
2643 char prop[PROPERTY_VALUE_MAX];
2644#endif /* ANDROID */
2645
2646 if (intf == NULL)
2647 return -1;
2648
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002649 if (strcmp(intf, get_main_ifname(dut)) == 0)
2650 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002651 else
2652 ifname = intf;
2653
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302654 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002655 if (id < 0)
2656 return id;
2657
2658 if (set_network(ifname, id, "eap", "TLS") < 0)
2659 return -2;
2660
Pradeep Reddy POTTETI9f6c2132016-05-05 16:28:19 +05302661 if (!get_param(cmd, "username") &&
2662 set_network_quoted(ifname, id, "identity",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002663 "wifi-user@wifilabs.local") < 0)
2664 return -2;
2665
2666 val = get_param(cmd, "clientCertificate");
2667 if (val == NULL)
2668 return -1;
2669#ifdef ANDROID
2670 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2671 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
2672 if (length < 0) {
2673 /*
2674 * JB started reporting keystore type mismatches, so retry with
2675 * the GET_PUBKEY command if the generic GET fails.
2676 */
2677 length = android_keystore_get(ANDROID_KEYSTORE_GET_PUBKEY,
2678 buf, kvalue);
2679 }
2680
2681 if (property_get("ro.build.version.release", prop, NULL) != 0) {
2682 sigma_dut_print(dut, DUT_MSG_DEBUG, "Android release %s", prop);
2683 if (strncmp(prop, "4.0", 3) != 0)
2684 jb_or_newer = 1;
2685 } else
2686 jb_or_newer = 1; /* assume newer */
2687
2688 if (jb_or_newer && length > 0) {
2689 sigma_dut_print(dut, DUT_MSG_INFO,
2690 "Use Android keystore [%s]", buf);
2691 if (set_network(ifname, id, "engine", "1") < 0)
2692 return -2;
2693 if (set_network_quoted(ifname, id, "engine_id", "keystore") < 0)
2694 return -2;
2695 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2696 if (set_network_quoted(ifname, id, "key_id", buf) < 0)
2697 return -2;
2698 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2699 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2700 return -2;
2701 return 1;
2702 } else if (length > 0) {
2703 sigma_dut_print(dut, DUT_MSG_INFO,
2704 "Use Android keystore [%s]", buf);
2705 snprintf(buf, sizeof(buf), "keystore://USRPKEY_%s", val);
2706 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2707 return -2;
2708 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2709 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2710 return -2;
2711 return 1;
2712 }
2713#endif /* ANDROID */
2714
2715 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
2716#ifdef __linux__
2717 if (!file_exists(buf)) {
2718 char msg[300];
2719 snprintf(msg, sizeof(msg), "ErrorCode,clientCertificate file "
2720 "(%s) not found", buf);
2721 send_resp(dut, conn, SIGMA_ERROR, msg);
2722 return -3;
2723 }
2724#endif /* __linux__ */
2725 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2726 return -2;
2727 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2728 return -2;
2729
2730 if (set_network_quoted(ifname, id, "private_key_passwd", "wifi") < 0)
2731 return -2;
2732
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002733 val = get_param(cmd, "keyMgmtType");
2734 if (val && strcasecmp(val, "SuiteB") == 0) {
2735 val = get_param(cmd, "CertType");
2736 if (val && strcasecmp(val, "RSA") == 0) {
2737 if (set_network_quoted(ifname, id, "phase1",
2738 "tls_suiteb=1") < 0)
2739 return -2;
2740 } else {
2741 if (set_network_quoted(ifname, id, "openssl_ciphers",
2742 "SUITEB192") < 0)
2743 return -2;
2744 }
2745
2746 val = get_param(cmd, "TLSCipher");
2747 if (set_tls_cipher(ifname, id, val) < 0) {
2748 send_resp(dut, conn, SIGMA_ERROR,
2749 "ErrorCode,Unsupported TLSCipher value");
2750 return -3;
2751 }
2752 }
2753
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002754 return 1;
2755}
2756
2757
Jouni Malinenf7222712019-06-13 01:50:21 +03002758static enum sigma_cmd_result cmd_sta_set_eapttls(struct sigma_dut *dut,
2759 struct sigma_conn *conn,
2760 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002761{
2762 const char *intf = get_param(cmd, "Interface");
2763 const char *ifname;
2764 int id;
2765
2766 if (intf == NULL)
2767 return -1;
2768
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002769 if (strcmp(intf, get_main_ifname(dut)) == 0)
2770 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002771 else
2772 ifname = intf;
2773
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302774 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002775 if (id < 0)
2776 return id;
2777
2778 if (set_network(ifname, id, "eap", "TTLS") < 0) {
2779 send_resp(dut, conn, SIGMA_ERROR,
2780 "errorCode,Failed to set TTLS method");
2781 return 0;
2782 }
2783
2784 if (set_network_quoted(ifname, id, "phase2", "auth=MSCHAPV2") < 0) {
2785 send_resp(dut, conn, SIGMA_ERROR,
2786 "errorCode,Failed to set MSCHAPv2 for TTLS Phase 2");
2787 return 0;
2788 }
2789
2790 return 1;
2791}
2792
2793
Jouni Malinenf7222712019-06-13 01:50:21 +03002794static enum sigma_cmd_result cmd_sta_set_eapsim(struct sigma_dut *dut,
2795 struct sigma_conn *conn,
2796 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002797{
2798 const char *intf = get_param(cmd, "Interface");
2799 const char *ifname;
2800 int id;
2801
2802 if (intf == NULL)
2803 return -1;
2804
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002805 if (strcmp(intf, get_main_ifname(dut)) == 0)
2806 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002807 else
2808 ifname = intf;
2809
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302810 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002811 if (id < 0)
2812 return id;
2813
2814 if (set_network(ifname, id, "eap", "SIM") < 0)
2815 return -2;
2816
2817 return 1;
2818}
2819
2820
Jouni Malinenf7222712019-06-13 01:50:21 +03002821static enum sigma_cmd_result cmd_sta_set_peap(struct sigma_dut *dut,
2822 struct sigma_conn *conn,
2823 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002824{
2825 const char *intf = get_param(cmd, "Interface");
2826 const char *ifname, *val;
2827 int id;
2828 char buf[100];
2829
2830 if (intf == NULL)
2831 return -1;
2832
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002833 if (strcmp(intf, get_main_ifname(dut)) == 0)
2834 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002835 else
2836 ifname = intf;
2837
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302838 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002839 if (id < 0)
2840 return id;
2841
2842 if (set_network(ifname, id, "eap", "PEAP") < 0)
2843 return -2;
2844
2845 val = get_param(cmd, "innerEAP");
2846 if (val) {
2847 if (strcasecmp(val, "MSCHAPv2") == 0) {
2848 if (set_network_quoted(ifname, id, "phase2",
2849 "auth=MSCHAPV2") < 0)
2850 return -2;
2851 } else if (strcasecmp(val, "GTC") == 0) {
2852 if (set_network_quoted(ifname, id, "phase2",
2853 "auth=GTC") < 0)
2854 return -2;
2855 } else
2856 return -1;
2857 }
2858
2859 val = get_param(cmd, "peapVersion");
2860 if (val) {
2861 int ver = atoi(val);
2862 if (ver < 0 || ver > 1)
2863 return -1;
2864 snprintf(buf, sizeof(buf), "peapver=%d", ver);
2865 if (set_network_quoted(ifname, id, "phase1", buf) < 0)
2866 return -2;
2867 }
2868
2869 return 1;
2870}
2871
2872
Jouni Malinenf7222712019-06-13 01:50:21 +03002873static enum sigma_cmd_result cmd_sta_set_eapfast(struct sigma_dut *dut,
2874 struct sigma_conn *conn,
2875 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002876{
2877 const char *intf = get_param(cmd, "Interface");
2878 const char *ifname, *val;
2879 int id;
2880 char buf[100];
2881
2882 if (intf == NULL)
2883 return -1;
2884
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002885 if (strcmp(intf, get_main_ifname(dut)) == 0)
2886 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002887 else
2888 ifname = intf;
2889
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302890 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002891 if (id < 0)
2892 return id;
2893
2894 if (set_network(ifname, id, "eap", "FAST") < 0)
2895 return -2;
2896
2897 val = get_param(cmd, "innerEAP");
2898 if (val) {
2899 if (strcasecmp(val, "MSCHAPV2") == 0) {
2900 if (set_network_quoted(ifname, id, "phase2",
2901 "auth=MSCHAPV2") < 0)
2902 return -2;
2903 } else if (strcasecmp(val, "GTC") == 0) {
2904 if (set_network_quoted(ifname, id, "phase2",
2905 "auth=GTC") < 0)
2906 return -2;
2907 } else
2908 return -1;
2909 }
2910
2911 val = get_param(cmd, "validateServer");
2912 if (val) {
2913 /* TODO */
2914 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored EAP-FAST "
2915 "validateServer=%s", val);
2916 }
2917
2918 val = get_param(cmd, "pacFile");
2919 if (val) {
2920 snprintf(buf, sizeof(buf), "blob://%s", val);
2921 if (set_network_quoted(ifname, id, "pac_file", buf) < 0)
2922 return -2;
2923 }
2924
2925 if (set_network_quoted(ifname, id, "phase1", "fast_provisioning=2") <
2926 0)
2927 return -2;
2928
2929 return 1;
2930}
2931
2932
Jouni Malinenf7222712019-06-13 01:50:21 +03002933static enum sigma_cmd_result cmd_sta_set_eapaka(struct sigma_dut *dut,
2934 struct sigma_conn *conn,
2935 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002936{
2937 const char *intf = get_param(cmd, "Interface");
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302938 const char *username = get_param(cmd, "Username");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002939 const char *ifname;
2940 int id;
2941
2942 if (intf == NULL)
2943 return -1;
2944
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002945 if (strcmp(intf, get_main_ifname(dut)) == 0)
2946 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002947 else
2948 ifname = intf;
2949
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302950 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002951 if (id < 0)
2952 return id;
2953
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302954 /* RFC 5448: EAP-AKA' MUST use the leading character "6" (ASCII 36
2955 * hexadecimal).
2956 */
2957 if (username && username[0] == '6') {
2958 if (set_network(ifname, id, "eap", "AKA'") < 0)
2959 return -2;
2960 } else if (set_network(ifname, id, "eap", "AKA") < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002961 return -2;
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302962 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002963
2964 return 1;
2965}
2966
2967
Jouni Malinenf7222712019-06-13 01:50:21 +03002968static enum sigma_cmd_result cmd_sta_set_eapakaprime(struct sigma_dut *dut,
2969 struct sigma_conn *conn,
2970 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002971{
2972 const char *intf = get_param(cmd, "Interface");
2973 const char *ifname;
2974 int id;
2975
2976 if (intf == NULL)
2977 return -1;
2978
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002979 if (strcmp(intf, get_main_ifname(dut)) == 0)
2980 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002981 else
2982 ifname = intf;
2983
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302984 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002985 if (id < 0)
2986 return id;
2987
2988 if (set_network(ifname, id, "eap", "AKA'") < 0)
2989 return -2;
2990
2991 return 1;
2992}
2993
2994
2995static int sta_set_open(struct sigma_dut *dut, struct sigma_conn *conn,
2996 struct sigma_cmd *cmd)
2997{
2998 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002999 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003000 const char *ifname;
3001 int id;
3002
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003003 if (strcmp(intf, get_main_ifname(dut)) == 0)
3004 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003005 else
3006 ifname = intf;
3007
3008 id = add_network_common(dut, conn, ifname, cmd);
3009 if (id < 0)
3010 return id;
3011
3012 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
3013 return -2;
3014
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003015 if (dut->program == PROGRAM_60GHZ && network_mode &&
3016 strcasecmp(network_mode, "PBSS") == 0 &&
3017 set_network(ifname, id, "pbss", "1") < 0)
3018 return -2;
3019
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003020 return 1;
3021}
3022
3023
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003024static enum sigma_cmd_result sta_set_owe(struct sigma_dut *dut,
3025 struct sigma_conn *conn,
3026 struct sigma_cmd *cmd)
Jouni Malinen47dcc952017-10-09 16:43:24 +03003027{
3028 const char *intf = get_param(cmd, "Interface");
3029 const char *ifname, *val;
3030 int id;
3031
3032 if (intf == NULL)
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003033 return INVALID_SEND_STATUS;
Jouni Malinen47dcc952017-10-09 16:43:24 +03003034
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003035 if (strcmp(intf, get_main_ifname(dut)) == 0)
3036 ifname = get_station_ifname(dut);
Jouni Malinen47dcc952017-10-09 16:43:24 +03003037 else
3038 ifname = intf;
3039
3040 id = set_wpa_common(dut, conn, ifname, cmd);
3041 if (id < 0)
3042 return id;
3043
3044 if (set_network(ifname, id, "key_mgmt", "OWE") < 0)
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003045 return ERROR_SEND_STATUS;
Jouni Malinen47dcc952017-10-09 16:43:24 +03003046
Hu Wangdd5eed22020-07-16 12:18:03 +08003047 if (dut->owe_ptk_workaround &&
3048 set_network(ifname, id, "owe_ptk_workaround", "1") < 0) {
3049 sigma_dut_print(dut, DUT_MSG_ERROR,
3050 "Failed to set owe_ptk_workaround to 1");
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003051 return ERROR_SEND_STATUS;
Hu Wangdd5eed22020-07-16 12:18:03 +08003052 }
3053
Jouni Malinen47dcc952017-10-09 16:43:24 +03003054 val = get_param(cmd, "ECGroupID");
Jouni Malinenfac9cad2017-10-10 18:35:55 +03003055 if (val && strcmp(val, "0") == 0) {
3056 if (wpa_command(ifname,
3057 "VENDOR_ELEM_ADD 13 ff23200000783590fb7440e03d5b3b33911f86affdcc6b4411b707846ac4ff08ddc8831ccd") != 0) {
3058 sigma_dut_print(dut, DUT_MSG_ERROR,
3059 "Failed to set OWE DH Param element override");
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003060 return ERROR_SEND_STATUS;
Jouni Malinenfac9cad2017-10-10 18:35:55 +03003061 }
Hu Wangdd5eed22020-07-16 12:18:03 +08003062 } else if (val && set_network(ifname, id, "owe_group", val) < 0) {
Jouni Malinen47dcc952017-10-09 16:43:24 +03003063 sigma_dut_print(dut, DUT_MSG_ERROR,
Hu Wang6010ce72020-03-05 19:33:53 +08003064 "Failed to set owe_group");
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003065 return ERROR_SEND_STATUS;
Jouni Malinen47dcc952017-10-09 16:43:24 +03003066 }
3067
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003068 return SUCCESS_SEND_STATUS;
Jouni Malinen47dcc952017-10-09 16:43:24 +03003069}
3070
3071
Jouni Malinenf7222712019-06-13 01:50:21 +03003072static enum sigma_cmd_result cmd_sta_set_security(struct sigma_dut *dut,
3073 struct sigma_conn *conn,
3074 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003075{
3076 const char *type = get_param(cmd, "Type");
3077
3078 if (type == NULL) {
3079 send_resp(dut, conn, SIGMA_ERROR,
3080 "ErrorCode,Missing Type argument");
3081 return 0;
3082 }
3083
3084 if (strcasecmp(type, "OPEN") == 0)
3085 return sta_set_open(dut, conn, cmd);
Jouni Malinen47dcc952017-10-09 16:43:24 +03003086 if (strcasecmp(type, "OWE") == 0)
3087 return sta_set_owe(dut, conn, cmd);
Jouni Malinen992a81e2017-08-22 13:57:47 +03003088 if (strcasecmp(type, "PSK") == 0 ||
Jouni Malinen0ab50f42017-08-31 01:34:59 +03003089 strcasecmp(type, "PSK-SAE") == 0 ||
Jouni Malinen992a81e2017-08-22 13:57:47 +03003090 strcasecmp(type, "SAE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003091 return cmd_sta_set_psk(dut, conn, cmd);
3092 if (strcasecmp(type, "EAPTLS") == 0)
3093 return cmd_sta_set_eaptls(dut, conn, cmd);
3094 if (strcasecmp(type, "EAPTTLS") == 0)
3095 return cmd_sta_set_eapttls(dut, conn, cmd);
3096 if (strcasecmp(type, "EAPPEAP") == 0)
3097 return cmd_sta_set_peap(dut, conn, cmd);
3098 if (strcasecmp(type, "EAPSIM") == 0)
3099 return cmd_sta_set_eapsim(dut, conn, cmd);
3100 if (strcasecmp(type, "EAPFAST") == 0)
3101 return cmd_sta_set_eapfast(dut, conn, cmd);
3102 if (strcasecmp(type, "EAPAKA") == 0)
3103 return cmd_sta_set_eapaka(dut, conn, cmd);
3104 if (strcasecmp(type, "EAPAKAPRIME") == 0)
3105 return cmd_sta_set_eapakaprime(dut, conn, cmd);
Amarnath Hullur Subramanyam81b11cd2018-01-30 19:07:17 -08003106 if (strcasecmp(type, "wep") == 0)
3107 return cmd_sta_set_encryption(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003108
3109 send_resp(dut, conn, SIGMA_ERROR,
3110 "ErrorCode,Unsupported Type value");
3111 return 0;
3112}
3113
3114
3115int ath6kl_client_uapsd(struct sigma_dut *dut, const char *intf, int uapsd)
3116{
3117#ifdef __linux__
3118 /* special handling for ath6kl */
3119 char path[128], fname[128], *pos;
3120 ssize_t res;
3121 FILE *f;
3122
Jouni Malinene39cd562019-05-29 23:39:56 +03003123 res = snprintf(fname, sizeof(fname), "/sys/class/net/%s/phy80211",
3124 intf);
3125 if (res < 0 || res >= sizeof(fname))
3126 return 0;
3127 res = readlink(fname, path, sizeof(path));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003128 if (res < 0)
3129 return 0; /* not ath6kl */
3130
3131 if (res >= (int) sizeof(path))
3132 res = sizeof(path) - 1;
3133 path[res] = '\0';
3134 pos = strrchr(path, '/');
3135 if (pos == NULL)
3136 pos = path;
3137 else
3138 pos++;
Jouni Malinen77dda642020-01-07 11:21:55 +02003139 res = snprintf(fname, sizeof(fname),
3140 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
3141 "create_qos", pos);
3142 if (res < 0 || res >= sizeof(fname) || !file_exists(fname))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003143 return 0; /* not ath6kl */
3144
3145 if (uapsd) {
3146 f = fopen(fname, "w");
3147 if (f == NULL)
3148 return -1;
3149
3150 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl create_qos");
3151 fprintf(f, "4 2 2 1 2 9999999 9999999 9999999 7777777 0 4 "
3152 "45000 200 56789000 56789000 5678900 0 0 9999999 "
3153 "20000 0\n");
3154 fclose(f);
3155 } else {
Jouni Malinen77dda642020-01-07 11:21:55 +02003156 res = snprintf(fname, sizeof(fname),
3157 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
3158 "delete_qos", pos);
3159 if (res < 0 || res >= sizeof(fname))
3160 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003161
3162 f = fopen(fname, "w");
3163 if (f == NULL)
3164 return -1;
3165
3166 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl delete_qos");
3167 fprintf(f, "2 4\n");
3168 fclose(f);
3169 }
3170#endif /* __linux__ */
3171
3172 return 0;
3173}
3174
3175
Jouni Malinenf7222712019-06-13 01:50:21 +03003176static enum sigma_cmd_result cmd_sta_set_uapsd(struct sigma_dut *dut,
3177 struct sigma_conn *conn,
3178 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003179{
3180 const char *intf = get_param(cmd, "Interface");
3181 /* const char *ssid = get_param(cmd, "ssid"); */
3182 const char *val;
3183 int max_sp_len = 4;
3184 int ac_be = 1, ac_bk = 1, ac_vi = 1, ac_vo = 1;
3185 char buf[100];
3186 int ret1, ret2;
3187
3188 val = get_param(cmd, "maxSPLength");
3189 if (val) {
3190 max_sp_len = atoi(val);
3191 if (max_sp_len != 0 && max_sp_len != 1 && max_sp_len != 2 &&
3192 max_sp_len != 4)
3193 return -1;
3194 }
3195
3196 val = get_param(cmd, "acBE");
3197 if (val)
3198 ac_be = atoi(val);
3199
3200 val = get_param(cmd, "acBK");
3201 if (val)
3202 ac_bk = atoi(val);
3203
3204 val = get_param(cmd, "acVI");
3205 if (val)
3206 ac_vi = atoi(val);
3207
3208 val = get_param(cmd, "acVO");
3209 if (val)
3210 ac_vo = atoi(val);
3211
3212 dut->client_uapsd = ac_be || ac_bk || ac_vi || ac_vo;
3213
3214 snprintf(buf, sizeof(buf), "P2P_SET client_apsd %d,%d,%d,%d;%d",
3215 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
3216 ret1 = wpa_command(intf, buf);
3217
3218 snprintf(buf, sizeof(buf), "SET uapsd %d,%d,%d,%d;%d",
3219 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
3220 ret2 = wpa_command(intf, buf);
3221
3222 if (ret1 && ret2) {
3223 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to set client mode "
3224 "UAPSD parameters.");
3225 return -2;
3226 }
3227
3228 if (ath6kl_client_uapsd(dut, intf, dut->client_uapsd) < 0) {
3229 send_resp(dut, conn, SIGMA_ERROR,
3230 "ErrorCode,Failed to set ath6kl QoS parameters");
3231 return 0;
3232 }
3233
3234 return 1;
3235}
3236
3237
Jouni Malinenf7222712019-06-13 01:50:21 +03003238static enum sigma_cmd_result cmd_sta_set_wmm(struct sigma_dut *dut,
3239 struct sigma_conn *conn,
3240 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003241{
3242 char buf[1000];
3243 const char *intf = get_param(cmd, "Interface");
3244 const char *grp = get_param(cmd, "Group");
3245 const char *act = get_param(cmd, "Action");
3246 const char *tid = get_param(cmd, "Tid");
3247 const char *dir = get_param(cmd, "Direction");
3248 const char *psb = get_param(cmd, "Psb");
3249 const char *up = get_param(cmd, "Up");
3250 const char *fixed = get_param(cmd, "Fixed");
3251 const char *size = get_param(cmd, "Size");
3252 const char *msize = get_param(cmd, "Maxsize");
3253 const char *minsi = get_param(cmd, "Min_srvc_intrvl");
3254 const char *maxsi = get_param(cmd, "Max_srvc_intrvl");
3255 const char *inact = get_param(cmd, "Inactivity");
3256 const char *sus = get_param(cmd, "Suspension");
3257 const char *mindr = get_param(cmd, "Mindatarate");
3258 const char *meandr = get_param(cmd, "Meandatarate");
3259 const char *peakdr = get_param(cmd, "Peakdatarate");
3260 const char *phyrate = get_param(cmd, "Phyrate");
3261 const char *burstsize = get_param(cmd, "Burstsize");
3262 const char *sba = get_param(cmd, "Sba");
3263 int direction;
3264 int handle;
Peng Xu93319622017-10-04 17:58:16 -07003265 float sba_fv = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003266 int fixed_int;
3267 int psb_ts;
3268
3269 if (intf == NULL || grp == NULL || act == NULL )
3270 return -1;
3271
3272 if (strcasecmp(act, "addts") == 0) {
3273 if (tid == NULL || dir == NULL || psb == NULL ||
3274 up == NULL || fixed == NULL || size == NULL)
3275 return -1;
3276
3277 /*
3278 * Note: Sigma CAPI spec lists uplink, downlink, and bidi as the
3279 * possible values, but WMM-AC and V-E test scripts use "UP,
3280 * "DOWN", and "BIDI".
3281 */
3282 if (strcasecmp(dir, "uplink") == 0 ||
3283 strcasecmp(dir, "up") == 0) {
3284 direction = 0;
3285 } else if (strcasecmp(dir, "downlink") == 0 ||
3286 strcasecmp(dir, "down") == 0) {
3287 direction = 1;
3288 } else if (strcasecmp(dir, "bidi") == 0) {
3289 direction = 2;
3290 } else {
3291 sigma_dut_print(dut, DUT_MSG_ERROR,
3292 "Direction %s not supported", dir);
3293 return -1;
3294 }
3295
3296 if (strcasecmp(psb, "legacy") == 0) {
3297 psb_ts = 0;
3298 } else if (strcasecmp(psb, "uapsd") == 0) {
3299 psb_ts = 1;
3300 } else {
3301 sigma_dut_print(dut, DUT_MSG_ERROR,
3302 "PSB %s not supported", psb);
3303 return -1;
3304 }
3305
3306 if (atoi(tid) < 0 || atoi(tid) > 7) {
3307 sigma_dut_print(dut, DUT_MSG_ERROR,
3308 "TID %s not supported", tid);
3309 return -1;
3310 }
3311
3312 if (strcasecmp(fixed, "true") == 0) {
3313 fixed_int = 1;
3314 } else {
3315 fixed_int = 0;
3316 }
3317
Peng Xu93319622017-10-04 17:58:16 -07003318 if (sba)
3319 sba_fv = atof(sba);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003320
3321 dut->dialog_token++;
3322 handle = 7000 + dut->dialog_token;
3323
3324 /*
3325 * size: convert to hex
3326 * maxsi: convert to hex
3327 * mindr: convert to hex
3328 * meandr: convert to hex
3329 * peakdr: convert to hex
3330 * burstsize: convert to hex
3331 * phyrate: convert to hex
3332 * sba: convert to hex with modification
3333 * minsi: convert to integer
3334 * sus: convert to integer
3335 * inact: convert to integer
3336 * maxsi: convert to integer
3337 */
3338
3339 /*
3340 * The Nominal MSDU Size field is 2 octets long and contains an
3341 * unsigned integer that specifies the nominal size, in octets,
3342 * of MSDUs belonging to the traffic under this traffic
3343 * specification and is defined in Figure 16. If the Fixed
3344 * subfield is set to 1, then the size of the MSDU is fixed and
3345 * is indicated by the Size Subfield. If the Fixed subfield is
3346 * set to 0, then the size of the MSDU might not be fixed and
3347 * the Size indicates the nominal MSDU size.
3348 *
3349 * The Surplus Bandwidth Allowance Factor field is 2 octets long
3350 * and specifies the excess allocation of time (and bandwidth)
3351 * over and above the stated rates required to transport an MSDU
3352 * belonging to the traffic in this TSPEC. This field is
3353 * represented as an unsigned binary number with an implicit
3354 * binary point after the leftmost 3 bits. For example, an SBA
3355 * of 1.75 is represented as 0x3800. This field is included to
3356 * account for retransmissions. As such, the value of this field
3357 * must be greater than unity.
3358 */
3359
3360 snprintf(buf, sizeof(buf),
3361 "iwpriv %s addTspec %d %s %d %d %s 0x%X"
3362 " 0x%X 0x%X 0x%X"
3363 " 0x%X 0x%X 0x%X"
3364 " 0x%X %d %d %d %d"
3365 " %d %d",
3366 intf, handle, tid, direction, psb_ts, up,
3367 (unsigned int) ((fixed_int << 15) | atoi(size)),
3368 msize ? atoi(msize) : 0,
3369 mindr ? atoi(mindr) : 0,
3370 meandr ? atoi(meandr) : 0,
3371 peakdr ? atoi(peakdr) : 0,
3372 burstsize ? atoi(burstsize) : 0,
3373 phyrate ? atoi(phyrate) : 0,
3374 sba ? ((unsigned int) (((int) sba_fv << 13) |
3375 (int)((sba_fv - (int) sba_fv) *
3376 8192))) : 0,
3377 minsi ? atoi(minsi) : 0,
3378 sus ? atoi(sus) : 0,
3379 0, 0,
3380 inact ? atoi(inact) : 0,
3381 maxsi ? atoi(maxsi) : 0);
3382
3383 if (system(buf) != 0) {
3384 sigma_dut_print(dut, DUT_MSG_ERROR,
3385 "iwpriv addtspec request failed");
3386 send_resp(dut, conn, SIGMA_ERROR,
3387 "errorCode,Failed to execute addTspec command");
3388 return 0;
3389 }
3390
3391 sigma_dut_print(dut, DUT_MSG_INFO,
3392 "iwpriv addtspec request send");
3393
3394 /* Mapping handle to a TID */
3395 dut->tid_to_handle[atoi(tid)] = handle;
3396 } else if (strcasecmp(act, "delts") == 0) {
3397 if (tid == NULL)
3398 return -1;
3399
3400 if (atoi(tid) < 0 || atoi(tid) > 7) {
3401 sigma_dut_print(dut, DUT_MSG_ERROR,
3402 "TID %s not supported", tid);
3403 send_resp(dut, conn, SIGMA_ERROR,
3404 "errorCode,Unsupported TID");
3405 return 0;
3406 }
3407
3408 handle = dut->tid_to_handle[atoi(tid)];
3409
3410 if (handle < 7000 || handle > 7255) {
3411 /* Invalid handle ie no mapping for that TID */
3412 sigma_dut_print(dut, DUT_MSG_ERROR,
3413 "handle-> %d not found", handle);
3414 }
3415
3416 snprintf(buf, sizeof(buf), "iwpriv %s delTspec %d",
3417 intf, handle);
3418
3419 if (system(buf) != 0) {
3420 sigma_dut_print(dut, DUT_MSG_ERROR,
3421 "iwpriv deltspec request failed");
3422 send_resp(dut, conn, SIGMA_ERROR,
3423 "errorCode,Failed to execute delTspec command");
3424 return 0;
3425 }
3426
3427 sigma_dut_print(dut, DUT_MSG_INFO,
3428 "iwpriv deltspec request send");
3429
3430 dut->tid_to_handle[atoi(tid)] = 0;
3431 } else {
3432 sigma_dut_print(dut, DUT_MSG_ERROR,
3433 "Action type %s not supported", act);
3434 send_resp(dut, conn, SIGMA_ERROR,
3435 "errorCode,Unsupported Action");
3436 return 0;
3437 }
3438
3439 return 1;
3440}
3441
3442
vamsi krishna52e16f92017-08-29 12:37:34 +05303443static int find_network(struct sigma_dut *dut, const char *ssid)
3444{
3445 char list[4096];
3446 char *pos;
3447
3448 sigma_dut_print(dut, DUT_MSG_DEBUG,
3449 "Search for profile based on SSID: '%s'", ssid);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003450 if (wpa_command_resp(get_station_ifname(dut), "LIST_NETWORKS",
vamsi krishna52e16f92017-08-29 12:37:34 +05303451 list, sizeof(list)) < 0)
3452 return -1;
3453 pos = strstr(list, ssid);
3454 if (!pos || pos == list || pos[-1] != '\t' || pos[strlen(ssid)] != '\t')
3455 return -1;
3456
3457 while (pos > list && pos[-1] != '\n')
3458 pos--;
3459 dut->infra_network_id = atoi(pos);
3460 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
3461 return 0;
3462}
3463
3464
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303465/**
3466 * enum qca_sta_helper_config_params - This helper enum defines the config
3467 * parameters which can be delivered to sta.
3468 */
3469enum qca_sta_helper_config_params {
3470 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE */
3471 STA_SET_RSNIE,
3472
3473 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_LDPC */
3474 STA_SET_LDPC,
3475
3476 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_TX_STBC */
3477 STA_SET_TX_STBC,
3478
3479 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_RX_STBC */
3480 STA_SET_RX_STBC,
3481
3482 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_TX_MSDU_AGGREGATION */
3483 STA_SET_TX_MSDU,
3484
3485 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_RX_MSDU_AGGREGATION */
3486 STA_SET_RX_MSDU,
Shivani Baranwal2a572842021-09-16 12:27:15 +05303487
3488 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_CHANNEL_WIDTH */
3489 STA_SET_CHAN_WIDTH,
Shivani Baranwal7aa48602021-09-29 10:53:38 +05303490
3491 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_FT_OVER_DS */
3492 STA_SET_FT_DS,
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303493};
3494
3495
3496static int sta_config_params(struct sigma_dut *dut, const char *intf,
3497 enum qca_sta_helper_config_params config_cmd,
3498 int value)
Sunil Dutt44595082018-02-12 19:41:45 +05303499{
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303500#ifdef NL80211_SUPPORT
Sunil Dutt44595082018-02-12 19:41:45 +05303501 struct nl_msg *msg;
3502 int ret;
3503 struct nlattr *params;
3504 int ifindex;
3505
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303506 ifindex = if_nametoindex(intf);
3507 if (ifindex == 0) {
3508 sigma_dut_print(dut, DUT_MSG_ERROR,
3509 "%s: Interface %s does not exist",
3510 __func__, intf);
3511 return -1;
3512 }
3513
Sunil Dutt44595082018-02-12 19:41:45 +05303514 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
3515 NL80211_CMD_VENDOR)) ||
3516 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
3517 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
3518 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
3519 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) ||
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303520 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)))
3521 goto fail;
3522
3523 switch (config_cmd) {
3524 case STA_SET_RSNIE:
3525 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE, value))
3526 goto fail;
3527 break;
3528 case STA_SET_LDPC:
3529 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_LDPC, value))
3530 goto fail;
3531 break;
3532 case STA_SET_TX_STBC:
3533 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TX_STBC, value))
3534 goto fail;
3535 break;
3536 case STA_SET_RX_STBC:
3537 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_RX_STBC, value))
3538 goto fail;
3539 break;
3540 case STA_SET_TX_MSDU:
3541 if (nla_put_u8(msg,
3542 QCA_WLAN_VENDOR_ATTR_CONFIG_TX_MSDU_AGGREGATION,
3543 value))
3544 goto fail;
3545 break;
3546 case STA_SET_RX_MSDU:
3547 if (nla_put_u8(msg,
3548 QCA_WLAN_VENDOR_ATTR_CONFIG_RX_MSDU_AGGREGATION,
3549 value))
3550 goto fail;
3551 break;
Shivani Baranwal2a572842021-09-16 12:27:15 +05303552 case STA_SET_CHAN_WIDTH:
3553 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_CHANNEL_WIDTH,
3554 value))
3555 goto fail;
3556 break;
Shivani Baranwal7aa48602021-09-29 10:53:38 +05303557 case STA_SET_FT_DS:
3558 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_FT_OVER_DS,
3559 value))
3560 goto fail;
3561 break;
Sunil Dutt44595082018-02-12 19:41:45 +05303562 }
3563 nla_nest_end(msg, params);
3564
3565 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
3566 if (ret) {
3567 sigma_dut_print(dut, DUT_MSG_ERROR,
3568 "%s: err in send_and_recv_msgs, ret=%d",
3569 __func__, ret);
3570 return ret;
3571 }
3572
3573 return 0;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303574
3575fail:
3576 sigma_dut_print(dut, DUT_MSG_ERROR,
3577 "%s: err in adding vendor_cmd and vendor_data",
3578 __func__);
3579 nlmsg_free(msg);
Sunil Dutt44595082018-02-12 19:41:45 +05303580#endif /* NL80211_SUPPORT */
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303581 return -1;
3582}
Sunil Dutt44595082018-02-12 19:41:45 +05303583
3584
Veerendranath Jakkam9ceb3b12021-09-10 03:18:17 +05303585void free_dscp_policy_table(struct sigma_dut *dut)
3586{
3587 struct dscp_policy_data *dscp_policy;
3588
3589 while (dut->dscp_policy_table) {
3590 dscp_policy = dut->dscp_policy_table;
3591 dut->dscp_policy_table = dscp_policy->next;
3592 free(dscp_policy);
3593 }
3594}
3595
3596
3597static int delete_nft_table(struct sigma_dut *dut, const char *table,
3598 const char *ip_type)
3599{
3600 int res;
3601 char cmd[200];
3602
3603 res = snprintf(cmd, sizeof(cmd), "nft delete table %s %s_%s", ip_type,
3604 table, ip_type);
3605 if (snprintf_error(sizeof(cmd), res)) {
3606 sigma_dut_print(dut, DUT_MSG_ERROR,
3607 "Failed to create delete table command");
3608 return -1;
3609 }
3610
3611 if (system(cmd) != 0) {
3612 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run %s", cmd);
3613 return -1;
3614 }
3615
3616 return 0;
3617}
3618
3619
3620static int remove_nft_rule(struct sigma_dut *dut, int policy_id,
3621 enum ip_version ip_ver)
3622{
3623 int res;
3624 char table[50];
3625
3626 res = snprintf(table, sizeof(table), "wifi_%s_dscp_policy_%d",
3627 dut->station_ifname, policy_id);
3628 if (snprintf_error(sizeof(table), res)) {
3629 sigma_dut_print(dut, DUT_MSG_INFO,
3630 "Failed to create table name for policy %d",
3631 policy_id);
3632 return -1;
3633 }
3634
3635
3636 if (ip_ver == IPV6)
3637 return delete_nft_table(dut, table, "ip6");
3638 else
3639 return delete_nft_table(dut, table, "ip");
3640}
3641
3642
3643static int create_nft_table(struct sigma_dut *dut, int policy_id,
3644 const char *table_name, enum ip_version ip_ver)
3645{
3646 char cmd[200];
3647 int res;
3648
3649 res = snprintf(cmd, sizeof(cmd), "nft add table %s %s",
3650 ip_ver == IPV6 ? "ip6" : "ip", table_name);
3651 if (snprintf_error(sizeof(cmd), res)) {
3652 sigma_dut_print(dut, DUT_MSG_INFO,
3653 "Failed to add rule to create table for policy id %d",
3654 policy_id);
3655 return -1;
3656 }
3657
3658 if (system(cmd) != 0) {
3659 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run %s", cmd);
3660 return -1;
3661 }
3662
3663 res = snprintf(cmd, sizeof(cmd),
3664 "nft add chain %s %s OUTPUT { type filter hook output priority 0 \\; }",
3665 ip_ver == IPV6 ? "ip6" : "ip", table_name);
3666 if (snprintf_error(sizeof(cmd), res)) {
3667 sigma_dut_print(dut, DUT_MSG_INFO,
3668 "Failed to add rule to create chain for table = %s",
3669 table_name);
3670 return -1;
3671 }
3672
3673 if (system(cmd) != 0) {
3674 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run %s", cmd);
3675 return -1;
3676 }
3677
3678 return 0;
3679}
3680
3681
3682static char * protocol_to_str(int proto)
3683{
3684 switch (proto) {
3685 case 6:
3686 return "tcp";
3687 case 17:
3688 return "udp";
3689 case 50:
3690 return "esp";
3691 default:
3692 return "unknown";
3693 }
3694}
3695
3696
3697static int remove_dscp_policy(struct sigma_dut *dut, u8 policy_id)
3698{
3699 struct dscp_policy_data *dscp_policy = dut->dscp_policy_table;
3700 struct dscp_policy_data *prev = NULL;
3701
3702 while (dscp_policy) {
3703 if (dscp_policy->policy_id == policy_id)
3704 break;
3705
3706 prev = dscp_policy;
3707 dscp_policy = dscp_policy->next;
3708 }
3709
3710 /*
3711 * Consider remove request for a policy id which does not exist as
3712 * success.
3713 */
3714 if (!dscp_policy)
3715 return 0;
3716
3717 if (strlen(dscp_policy->domain_name) == 0 &&
3718 remove_nft_rule(dut, policy_id, dscp_policy->ip_version))
3719 return -1;
3720
3721 if (prev)
3722 prev->next = dscp_policy->next;
3723 else
3724 dut->dscp_policy_table = dscp_policy->next;
3725
3726 free(dscp_policy);
3727 return 0;
3728}
3729
3730
3731static int add_nft_rule(struct sigma_dut *dut,
3732 struct dscp_policy_data *dscp_policy)
3733{
3734 char nft_cmd[1000], ip[4], table_name[100];
3735 char *pos;
3736 int ret, len, policy_id = dscp_policy->policy_id;
3737 enum ip_version ip_ver = dscp_policy->ip_version;
3738
3739 if (ip_ver == IPV6)
3740 strlcpy(ip, "ip6", sizeof(ip));
3741 else
3742 strlcpy(ip, "ip", sizeof(ip));
3743
3744 ret = snprintf(table_name, sizeof(table_name),
3745 "wifi_%s_dscp_policy_%d_%s",
3746 dut->station_ifname, policy_id, ip);
3747 if (snprintf_error(sizeof(table_name), ret))
3748 return -1;
3749
3750 if (create_nft_table(dut, policy_id, table_name, ip_ver)) {
3751 sigma_dut_print(dut, DUT_MSG_INFO,
3752 "Failed to create nft table");
3753 return -1;
3754 }
3755
3756 pos = nft_cmd;
3757 len = sizeof(nft_cmd);
3758
3759 ret = snprintf(pos, len,
3760 "nft add rule %s %s OUTPUT oifname \"%s\"",
3761 ip, table_name, dut->station_ifname);
3762 if (snprintf_error(len, ret)) {
3763 sigma_dut_print(dut, DUT_MSG_INFO,
3764 "Failed to create nft cmd %s", nft_cmd);
3765 return -1;
3766 }
3767
3768 pos += ret;
3769 len -= ret;
3770
3771 if (strlen(dscp_policy->src_ip)) {
3772 ret = snprintf(pos, len, " %s saddr %s", ip,
3773 dscp_policy->src_ip);
3774 if (snprintf_error(len, ret))
3775 return -1;
3776
3777 pos += ret;
3778 len -= ret;
3779 }
3780
3781 if (strlen(dscp_policy->dst_ip)) {
3782 ret = snprintf(pos, len, " %s daddr %s", ip,
3783 dscp_policy->dst_ip);
3784 if (snprintf_error(len, ret))
3785 return -1;
3786
3787 pos += ret;
3788 len -= ret;
3789 }
3790
3791 if (dscp_policy->src_port) {
3792 ret = snprintf(pos, len, " %s sport %d",
3793 protocol_to_str(dscp_policy->protocol),
3794 dscp_policy->src_port);
3795 if (snprintf_error(len, ret))
3796 return -1;
3797
3798 pos += ret;
3799 len -= ret;
3800 }
3801
3802 if (dscp_policy->dst_port) {
3803 ret = snprintf(pos, len, " %s dport %d",
3804 protocol_to_str(dscp_policy->protocol),
3805 dscp_policy->dst_port);
3806 if (snprintf_error(len, ret))
3807 return -1;
3808
3809 pos += ret;
3810 len -= ret;
3811 }
3812
3813 if (dscp_policy->start_port && dscp_policy->end_port) {
3814 ret = snprintf(pos, len, " %s dport %d-%d",
3815 protocol_to_str(dscp_policy->protocol),
3816 dscp_policy->start_port,
3817 dscp_policy->end_port);
3818 if (snprintf_error(len, ret))
3819 return -1;
3820
3821 pos += ret;
3822 len -= ret;
3823 }
3824
3825 ret = snprintf(pos, len, " counter %s dscp set 0x%0x", ip,
3826 dscp_policy->dscp);
3827 if (snprintf_error(len, ret))
3828 return -1;
3829
3830 ret = system(nft_cmd);
3831 sigma_dut_print(dut, DUT_MSG_INFO, "nft rule: %s err: %d",
3832 nft_cmd, ret);
3833
3834 return ret;
3835}
3836
3837
3838static void clear_all_dscp_policies(struct sigma_dut *dut)
3839{
3840 free_dscp_policy_table(dut);
3841
3842 if (system("nft flush ruleset") != 0)
3843 sigma_dut_print(dut, DUT_MSG_ERROR,
3844 "Failed to flush DSCP policy");
3845}
3846
3847
3848static int send_dscp_response(struct sigma_dut *dut,
3849 struct dscp_policy_status *status_list,
3850 int num_status)
3851{
3852 int rem_len, ret;
3853 char buf[200] = "", *pos, cmd[256];
3854
3855 pos = buf;
3856 rem_len = sizeof(buf);
3857
3858 ret = snprintf(pos, rem_len, " solicited");
3859 if (snprintf_error(rem_len, ret)) {
3860 sigma_dut_print(dut, DUT_MSG_ERROR,
3861 "Failed to write DSCP policy response command");
3862 return -1;
3863 }
3864 pos += ret;
3865 rem_len -= ret;
3866
3867 for (int i = 0; i < num_status; i++) {
3868 ret = snprintf(pos, rem_len, " policy_id=%d status=%d",
3869 status_list[i].id, status_list[i].status);
3870 if (snprintf_error(rem_len, ret)) {
3871 sigma_dut_print(dut, DUT_MSG_ERROR,
3872 "Failed to wite DSCP policy response");
3873 return -1;
3874 }
3875
3876 pos += ret;
3877 rem_len -= ret;
3878 }
3879
3880 ret = snprintf(cmd, sizeof(cmd), "DSCP_RESP%s", buf);
3881 if (snprintf_error(sizeof(cmd), ret)) {
3882 sigma_dut_print(dut, DUT_MSG_ERROR,
3883 "Failed to create DSCP Policy Response frame");
3884 return -1;
3885 }
3886
3887 if (wpa_command(dut->station_ifname, cmd) != 0) {
3888 sigma_dut_print(dut, DUT_MSG_ERROR,
3889 "Failed to send DSCP Policy Response frame");
3890 return -1;
3891 }
3892
3893 sigma_dut_print(dut, DUT_MSG_DEBUG,
3894 "DSCP Policy Response frame sent: %s", cmd);
3895 return 0;
3896}
3897
3898
3899#ifdef ANDROID
3900static void thread_cancel_handler(int sig)
3901{
3902 if (sig == SIGUSR1)
3903 pthread_exit(0);
3904}
3905#endif /* ANDROID */
3906
3907
3908static void * mon_dscp_policies(void *ptr)
3909{
3910 struct sigma_dut *dut = ptr;
3911 int ret, policy_id;
3912 struct wpa_ctrl *ctrl;
3913 char buf[4096], *pos, *end;
3914 struct dscp_policy_data *policy = NULL, *policy_table;
3915 struct dscp_policy_status status_list[10];
3916 int num_status = 0;
3917 const char *events[] = {
3918 "CTRL-EVENT-DISCONNECTED",
3919 "CTRL-EVENT-DSCP-POLICY",
3920 NULL
3921 };
3922#ifdef ANDROID
3923 struct sigaction actions;
3924#endif /* ANDROID */
3925
3926 ctrl = open_wpa_mon(get_station_ifname(dut));
3927 if (!ctrl) {
3928 sigma_dut_print(dut, DUT_MSG_ERROR,
3929 "Failed to open wpa_supplicant monitor connection");
3930 return NULL;
3931 }
3932
3933#ifdef ANDROID
3934 memset(&actions, 0, sizeof(actions));
3935 sigemptyset(&actions.sa_mask);
3936 actions.sa_flags = 0;
3937 actions.sa_handler = thread_cancel_handler;
3938 if (sigaction(SIGUSR1, &actions, NULL) == -1) {
3939 sigma_dut_print(dut, DUT_MSG_ERROR,
3940 "Failed to register exit handler for %s",
3941 __func__);
3942 wpa_ctrl_detach(ctrl);
3943 wpa_ctrl_close(ctrl);
3944 return NULL;
3945 }
3946#endif /* ANDROID */
3947
3948 while (1) {
3949 ret = get_wpa_cli_events_timeout(dut, ctrl, events,
3950 buf, sizeof(buf), 0);
3951
3952 if (ret || strlen(buf) == 0) {
3953 sigma_dut_print(dut, DUT_MSG_INFO,
3954 "Did not receive any event");
3955 continue;
3956 }
3957
3958 if (strstr(buf, "CTRL-EVENT-DISCONNECTED")) {
3959 clear_all_dscp_policies(dut);
3960 break;
3961 }
3962
3963 if (strstr(buf, "request_start")) {
3964 num_status = 0;
3965 if (strstr(buf, "clear_all"))
3966 clear_all_dscp_policies(dut);
3967 continue;
3968 }
3969
3970 if (strstr(buf, "request_end")) {
3971 send_dscp_response(dut, status_list, num_status);
3972 continue;
3973 }
3974
3975 if (!strstr(buf, "add") && !strstr(buf, "remove") &&
3976 !strstr(buf, "reject")) {
3977 sigma_dut_print(dut, DUT_MSG_DEBUG, "Ignore event: %s",
3978 buf);
3979 continue;
3980 }
3981
3982 pos = strstr(buf, "policy_id=");
3983 if (!pos) {
3984 sigma_dut_print(dut, DUT_MSG_INFO,
3985 "Policy id not present");
3986 continue;
3987 }
3988 policy_id = atoi(pos + 10);
3989
3990 if (num_status >= ARRAY_SIZE(status_list)) {
3991 sigma_dut_print(dut, DUT_MSG_INFO,
3992 "Max policies allowed per DSCP request reached. Drop policy id %d request",
3993 policy_id);
3994 continue;
3995 }
3996 status_list[num_status].id = policy_id;
3997
Veerendranath Jakkama16cdc82021-09-12 16:44:22 +05303998 if (dut->reject_dscp_policies) {
3999 status_list[num_status].status =
4000 dut->dscp_reject_resp_code;
4001 num_status++;
4002 continue;
4003 }
4004
Veerendranath Jakkam9ceb3b12021-09-10 03:18:17 +05304005 if (strstr(buf, "reject"))
4006 goto reject;
4007
4008 /*
4009 * In case of "add" also if policy with same policy id exist it
4010 * shall be removed. So always call remove_dscp_policy().
4011 */
4012 if (remove_dscp_policy(dut, policy_id))
4013 goto reject;
4014
4015 if (strstr(buf, "remove"))
4016 goto success;
4017
4018 policy = malloc(sizeof(*policy));
4019 if (!policy)
4020 goto reject;
4021
4022 memset(policy, 0, sizeof(*policy));
4023
4024 policy->policy_id = policy_id;
4025
4026 pos = strstr(buf, "dscp=");
4027 if (!pos) {
4028 sigma_dut_print(dut, DUT_MSG_ERROR,
4029 "DSCP info not present");
4030 goto reject;
4031 }
4032 policy->dscp = atoi(pos + 5);
4033
4034 pos = strstr(buf, "ip_version=");
4035 if (!pos) {
4036 sigma_dut_print(dut, DUT_MSG_ERROR,
4037 "IP version info not present");
4038 goto reject;
4039 }
4040 policy->ip_version = atoi(pos + 11);
4041
4042 pos = strstr(buf, "domain_name=");
4043 if (pos) {
4044 pos += 12;
4045 end = strchr(pos, ' ');
4046 if (!end)
4047 end = pos + strlen(pos);
4048
4049 if (end - pos >= (int) sizeof(policy->domain_name))
4050 goto reject;
4051
4052 memcpy(policy->domain_name, pos, end - pos);
4053 policy->domain_name[end - pos] = '\0';
4054 }
4055
4056 pos = strstr(buf, "start_port=");
4057 if (pos) {
4058 pos += 11;
4059 policy->start_port = atoi(pos);
4060 }
4061
4062 pos = strstr(buf, "end_port=");
4063 if (pos) {
4064 pos += 9;
4065 policy->end_port = atoi(pos);
4066 }
4067
4068 pos = strstr(buf, "src_ip=");
4069 if (pos) {
4070 pos += 7;
4071 end = strchr(pos, ' ');
4072 if (!end)
4073 end = pos + strlen(pos);
4074
4075 if (end - pos >= (int) sizeof(policy->src_ip))
4076 goto reject;
4077
4078 memcpy(policy->src_ip, pos, end - pos);
4079 policy->src_ip[end - pos] = '\0';
4080 }
4081
4082 pos = strstr(buf, "dst_ip=");
4083 if (pos) {
4084 pos += 7;
4085 end = strchr(pos, ' ');
4086 if (!end)
4087 end = pos + strlen(pos);
4088
4089 if (end - pos >= (int) sizeof(policy->dst_ip))
4090 goto reject;
4091
4092 memcpy(policy->dst_ip, pos, end - pos);
4093 policy->dst_ip[end - pos] = '\0';
4094 }
4095
4096 pos = strstr(buf, "src_port=");
4097 if (pos) {
4098 pos += 9;
4099 policy->src_port = atoi(pos);
4100 }
4101
4102 pos = strstr(buf, "dst_port=");
4103 if (pos) {
4104 pos += 9;
4105 policy->dst_port = atoi(pos);
4106 }
4107
4108 pos = strstr(buf, "protocol=");
4109 if (pos) {
4110 pos += 9;
4111 policy->protocol = atoi(pos);
4112 }
4113
4114 /*
4115 * Skip adding nft rules for doman name policies.
4116 * Domain name rules are applied in sigma_dut itself.
4117 */
4118 if (!strlen(policy->domain_name) && add_nft_rule(dut, policy))
4119 goto reject;
4120
4121 if (dut->dscp_policy_table) {
4122 policy_table = dut->dscp_policy_table;
4123 while (policy_table->next != NULL)
4124 policy_table = policy_table->next;
4125
4126 policy_table->next = policy;
4127 } else
4128 dut->dscp_policy_table = policy;
4129
4130success:
4131 status_list[num_status].status = DSCP_POLICY_SUCCESS;
4132 num_status++;
4133 policy = NULL;
4134 continue;
4135reject:
4136 status_list[num_status].status = DSCP_POLICY_REJECT;
4137 num_status++;
4138 free(policy);
4139 policy = NULL;
4140 }
4141
4142 free_dscp_policy_table(dut);
4143 wpa_ctrl_detach(ctrl);
4144 wpa_ctrl_close(ctrl);
4145
4146 pthread_exit(0);
4147 return NULL;
4148}
4149
4150
4151static void start_dscp_policy_mon_thread(struct sigma_dut *dut)
4152{
4153 /* Create event thread */
4154 pthread_create(&dut->dscp_policy_mon_thread, NULL, &mon_dscp_policies,
4155 (void *) dut);
4156}
4157
4158
4159void stop_dscp_policy_mon_thread(struct sigma_dut *dut)
4160{
4161 if (dut->dscp_policy_mon_thread) {
4162#ifdef ANDROID
4163 /* pthread_cancel not supported in Android */
4164 pthread_kill(dut->dscp_policy_mon_thread, SIGUSR1);
4165#else /* ANDROID */
4166 pthread_cancel(dut->dscp_policy_mon_thread);
4167#endif /* ANDROID */
4168 dut->dscp_policy_mon_thread = 0;
4169 }
4170}
4171
4172
Jouni Malinenf7222712019-06-13 01:50:21 +03004173static enum sigma_cmd_result cmd_sta_associate(struct sigma_dut *dut,
4174 struct sigma_conn *conn,
4175 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004176{
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304177#ifdef NL80211_SUPPORT
4178 const char *intf = get_param(cmd, "Interface");
4179#endif /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004180 const char *ssid = get_param(cmd, "ssid");
4181 const char *wps_param = get_param(cmd, "WPS");
4182 const char *bssid = get_param(cmd, "bssid");
Jouni Malinen46a19b62017-06-23 14:31:27 +03004183 const char *chan = get_param(cmd, "channel");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02004184 const char *network_mode = get_param(cmd, "network_mode");
Veerendranath Jakkama082e342020-05-16 00:19:21 +05304185 const char *ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004186 int wps = 0;
Jouni Malinen3c367e82017-06-23 17:01:47 +03004187 char buf[1000], extra[50];
Jouni Malinen134fe3c2019-06-12 04:16:49 +03004188 int e;
4189 enum sigma_cmd_result ret = SUCCESS_SEND_STATUS;
4190 struct wpa_ctrl *ctrl = NULL;
4191 int num_network_not_found = 0;
4192 int num_disconnected = 0;
4193 int tod = -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004194
4195 if (ssid == NULL)
4196 return -1;
4197
Jouni Malinen37d5c692019-08-19 16:56:55 +03004198 dut->server_cert_tod = 0;
4199
Jouni Malinen3c367e82017-06-23 17:01:47 +03004200 if (dut->rsne_override) {
Sunil Dutt44595082018-02-12 19:41:45 +05304201#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004202 if (get_driver_type(dut) == DRIVER_WCN) {
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304203 sta_config_params(dut, intf, STA_SET_RSNIE, 1);
Sunil Dutt44595082018-02-12 19:41:45 +05304204 dut->config_rsnie = 1;
4205 }
4206#endif /* NL80211_SUPPORT */
Jouni Malinen3c367e82017-06-23 17:01:47 +03004207 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
4208 dut->rsne_override);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004209 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinen3c367e82017-06-23 17:01:47 +03004210 send_resp(dut, conn, SIGMA_ERROR,
4211 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
4212 return 0;
4213 }
4214 }
4215
Jouni Malinen68143132017-09-02 02:34:08 +03004216 if (dut->sae_commit_override) {
4217 snprintf(buf, sizeof(buf), "SET sae_commit_override %s",
4218 dut->sae_commit_override);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004219 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinen68143132017-09-02 02:34:08 +03004220 send_resp(dut, conn, SIGMA_ERROR,
4221 "ErrorCode,Failed to set SAE commit override");
4222 return 0;
4223 }
4224 }
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304225#ifdef ANDROID
4226 if (dut->fils_hlp)
4227 process_fils_hlp(dut);
4228#endif /* ANDROID */
Jouni Malinen68143132017-09-02 02:34:08 +03004229
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004230 if (wps_param &&
4231 (strcmp(wps_param, "1") == 0 || strcasecmp(wps_param, "On") == 0))
4232 wps = 1;
4233
4234 if (wps) {
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02004235 if (dut->program == PROGRAM_60GHZ && network_mode &&
4236 strcasecmp(network_mode, "PBSS") == 0 &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004237 set_network(get_station_ifname(dut), dut->infra_network_id,
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02004238 "pbss", "1") < 0)
4239 return -2;
4240
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004241 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
4242 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,WPS "
4243 "parameters not yet set");
4244 return 0;
4245 }
4246 if (dut->wps_method == WFA_CS_WPS_PBC) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004247 if (wpa_command(get_station_ifname(dut), "WPS_PBC") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004248 return -2;
4249 } else {
4250 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
4251 dut->wps_pin);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004252 if (wpa_command(get_station_ifname(dut), buf) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004253 return -2;
4254 }
4255 } else {
vamsi krishna52e16f92017-08-29 12:37:34 +05304256 if (strcmp(ssid, dut->infra_ssid) == 0) {
4257 sigma_dut_print(dut, DUT_MSG_DEBUG,
4258 "sta_associate for the most recently added network");
4259 } else if (find_network(dut, ssid) < 0) {
4260 sigma_dut_print(dut, DUT_MSG_DEBUG,
4261 "sta_associate for a previously stored network profile");
4262 send_resp(dut, conn, SIGMA_ERROR,
4263 "ErrorCode,Profile not found");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004264 return 0;
4265 }
4266
4267 if (bssid &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004268 set_network(get_station_ifname(dut), dut->infra_network_id,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004269 "bssid", bssid) < 0) {
4270 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
4271 "Invalid bssid argument");
4272 return 0;
4273 }
4274
Veerendranath Jakkama082e342020-05-16 00:19:21 +05304275 if ((dut->program == PROGRAM_WPA3 &&
4276 dut->sta_associate_wait_connect) ||
4277 dut->program == PROGRAM_QM) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004278 ctrl = open_wpa_mon(get_station_ifname(dut));
Jouni Malinen134fe3c2019-06-12 04:16:49 +03004279 if (!ctrl)
4280 return ERROR_SEND_STATUS;
4281 }
4282
Jouni Malinen46a19b62017-06-23 14:31:27 +03004283 extra[0] = '\0';
4284 if (chan)
4285 snprintf(extra, sizeof(extra), " freq=%u",
Alexei Avshalom Lazar093569f2018-11-13 14:08:17 +02004286 channel_to_freq(dut, atoi(chan)));
Jouni Malinen46a19b62017-06-23 14:31:27 +03004287 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d%s",
4288 dut->infra_network_id, extra);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004289 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004290 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to select "
4291 "network id %d on %s",
4292 dut->infra_network_id,
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004293 get_station_ifname(dut));
Jouni Malinen134fe3c2019-06-12 04:16:49 +03004294 ret = ERROR_SEND_STATUS;
4295 goto done;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004296 }
4297 }
4298
Jouni Malinen134fe3c2019-06-12 04:16:49 +03004299 if (!ctrl)
4300 return SUCCESS_SEND_STATUS;
4301
4302 /* Wait for connection result to be able to store server certificate
4303 * hash for trust root override testing
4304 * (dev_exec_action,ServerCertTrust). */
4305
4306 for (e = 0; e < 20; e++) {
4307 const char *events[] = {
4308 "CTRL-EVENT-EAP-PEER-CERT",
4309 "CTRL-EVENT-EAP-TLS-CERT-ERROR",
4310 "CTRL-EVENT-DISCONNECTED",
4311 "CTRL-EVENT-CONNECTED",
4312 "CTRL-EVENT-NETWORK-NOT-FOUND",
4313 NULL
4314 };
4315 char buf[1024];
4316 int res;
4317
4318 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
4319 if (res < 0) {
Jouni Malinenf1f16642019-11-15 21:19:04 +02004320 send_resp(dut, conn, SIGMA_COMPLETE,
4321 "Result,Association did not complete");
Jouni Malinen134fe3c2019-06-12 04:16:49 +03004322 ret = STATUS_SENT_ERROR;
4323 break;
4324 }
4325 sigma_dut_print(dut, DUT_MSG_DEBUG, "Connection event: %s",
4326 buf);
4327
4328 if (strstr(buf, "CTRL-EVENT-EAP-PEER-CERT") &&
4329 strstr(buf, " depth=0")) {
4330 char *pos = strstr(buf, " hash=");
4331
4332 if (pos) {
4333 char *end;
4334
Jouni Malinen34b19cb2019-08-16 16:37:17 +03004335 if (strstr(buf, " tod=1"))
4336 tod = 1;
4337 else if (strstr(buf, " tod=2"))
4338 tod = 2;
4339 else
4340 tod = 0;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03004341 sigma_dut_print(dut, DUT_MSG_DEBUG,
4342 "Server certificate TOD policy: %d",
4343 tod);
Jouni Malinen37d5c692019-08-19 16:56:55 +03004344 dut->server_cert_tod = tod;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03004345
4346 pos += 6;
4347 end = strchr(pos, ' ');
4348 if (end)
4349 *end = '\0';
4350 strlcpy(dut->server_cert_hash, pos,
4351 sizeof(dut->server_cert_hash));
4352 sigma_dut_print(dut, DUT_MSG_DEBUG,
4353 "Server certificate hash: %s",
4354 dut->server_cert_hash);
4355 }
4356 }
4357
4358 if (strstr(buf, "CTRL-EVENT-EAP-TLS-CERT-ERROR")) {
4359 send_resp(dut, conn, SIGMA_COMPLETE,
4360 "Result,TLS server certificate validation failed");
4361 ret = STATUS_SENT_ERROR;
4362 break;
4363 }
4364
4365 if (strstr(buf, "CTRL-EVENT-NETWORK-NOT-FOUND")) {
4366 num_network_not_found++;
4367
4368 if (num_network_not_found > 2) {
4369 send_resp(dut, conn, SIGMA_COMPLETE,
4370 "Result,Network not found");
4371 ret = STATUS_SENT_ERROR;
4372 break;
4373 }
4374 }
4375
4376 if (strstr(buf, "CTRL-EVENT-DISCONNECTED")) {
4377 num_disconnected++;
4378
4379 if (num_disconnected > 2) {
4380 send_resp(dut, conn, SIGMA_COMPLETE,
4381 "Result,Connection failed");
4382 ret = STATUS_SENT_ERROR;
4383 break;
4384 }
4385 }
4386
4387 if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
4388 if (tod >= 0) {
4389 sigma_dut_print(dut, DUT_MSG_DEBUG,
4390 "Network profile TOD policy update: %d -> %d",
4391 dut->sta_tod_policy, tod);
4392 dut->sta_tod_policy = tod;
4393 }
Veerendranath Jakkama082e342020-05-16 00:19:21 +05304394 if (dut->program == PROGRAM_QM) {
4395 unsigned char iface_mac_addr[ETH_ALEN];
4396 char ipv6[100];
4397
4398 if (get_hwaddr(ifname, iface_mac_addr) < 0) {
4399 sigma_dut_print(dut, DUT_MSG_ERROR,
4400 "%s: get_hwaddr %s failed",
4401 __func__, ifname);
4402 ret = ERROR_SEND_STATUS;
4403 break;
4404 }
4405
4406 convert_mac_addr_to_ipv6_lladdr(iface_mac_addr,
4407 ipv6,
4408 sizeof(ipv6));
4409
4410 if (set_ipv6_addr(dut, ipv6, "64", ifname) !=
4411 0) {
4412 ret = ERROR_SEND_STATUS;
4413 break;
4414 }
Veerendranath Jakkam9ceb3b12021-09-10 03:18:17 +05304415 start_dscp_policy_mon_thread(dut);
Veerendranath Jakkama082e342020-05-16 00:19:21 +05304416 }
Jouni Malinen134fe3c2019-06-12 04:16:49 +03004417 break;
4418 }
4419 }
4420done:
4421 if (ctrl) {
4422 wpa_ctrl_detach(ctrl);
4423 wpa_ctrl_close(ctrl);
4424 }
4425 return ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004426}
4427
4428
4429static int run_hs20_osu(struct sigma_dut *dut, const char *params)
4430{
4431 char buf[500], cmd[200];
4432 int res;
4433
4434 /* Use hs20-osu-client file at the current dir, if found; otherwise use
4435 * default path */
4436 res = snprintf(cmd, sizeof(cmd),
4437 "%s -w \"%s\" -r hs20-osu-client.res %s%s -dddKt -f Logs/hs20-osu-client.txt",
4438 file_exists("./hs20-osu-client") ?
4439 "./hs20-osu-client" : "hs20-osu-client",
4440 sigma_wpas_ctrl,
4441 dut->summary_log ? "-s " : "",
4442 dut->summary_log ? dut->summary_log : "");
4443 if (res < 0 || res >= (int) sizeof(cmd))
4444 return -1;
4445
4446 res = snprintf(buf, sizeof(buf), "%s %s", cmd, params);
4447 if (res < 0 || res >= (int) sizeof(buf))
4448 return -1;
4449 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
4450
4451 if (system(buf) != 0) {
4452 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run: %s", buf);
4453 return -1;
4454 }
4455 sigma_dut_print(dut, DUT_MSG_DEBUG,
4456 "Completed hs20-osu-client operation");
4457
4458 return 0;
4459}
4460
4461
4462static int download_ppsmo(struct sigma_dut *dut,
4463 struct sigma_conn *conn,
4464 const char *intf,
4465 struct sigma_cmd *cmd)
4466{
4467 const char *name, *path, *val;
4468 char url[500], buf[600], fbuf[100];
4469 char *fqdn = NULL;
4470
4471 name = get_param(cmd, "FileName");
4472 path = get_param(cmd, "FilePath");
4473 if (name == NULL || path == NULL)
4474 return -1;
4475
4476 if (strcasecmp(path, "VendorSpecific") == 0) {
4477 snprintf(url, sizeof(url), "PPS/%s", name);
4478 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured PPS MO "
4479 "from the device (%s)", url);
4480 if (!file_exists(url)) {
4481 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
4482 "PPS MO file does not exist");
4483 return 0;
4484 }
4485 snprintf(buf, sizeof(buf), "cp %s pps-tnds.xml", url);
4486 if (system(buf) != 0) {
4487 send_resp(dut, conn, SIGMA_ERROR,
4488 "errorCode,Failed to copy PPS MO");
4489 return 0;
4490 }
4491 } else if (strncasecmp(path, "http:", 5) != 0 &&
4492 strncasecmp(path, "https:", 6) != 0) {
4493 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
4494 "Unsupported FilePath value");
4495 return 0;
4496 } else {
4497 snprintf(url, sizeof(url), "%s/%s", path, name);
4498 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading PPS MO from %s",
4499 url);
4500 snprintf(buf, sizeof(buf), "wget -T 10 -t 3 -O pps-tnds.xml '%s'", url);
4501 remove("pps-tnds.xml");
4502 if (system(buf) != 0) {
4503 send_resp(dut, conn, SIGMA_ERROR,
4504 "errorCode,Failed to download PPS MO");
4505 return 0;
4506 }
4507 }
4508
4509 if (run_hs20_osu(dut, "from_tnds pps-tnds.xml pps.xml") < 0) {
4510 send_resp(dut, conn, SIGMA_ERROR,
4511 "errorCode,Failed to parse downloaded PPSMO");
4512 return 0;
4513 }
4514 unlink("pps-tnds.xml");
4515
4516 val = get_param(cmd, "managementTreeURI");
4517 if (val) {
4518 const char *pos, *end;
4519 sigma_dut_print(dut, DUT_MSG_DEBUG, "managementTreeURI: %s",
4520 val);
4521 if (strncmp(val, "./Wi-Fi/", 8) != 0) {
4522 send_resp(dut, conn, SIGMA_ERROR,
4523 "errorCode,Invalid managementTreeURI prefix");
4524 return 0;
4525 }
4526 pos = val + 8;
4527 end = strchr(pos, '/');
4528 if (end == NULL ||
4529 strcmp(end, "/PerProviderSubscription") != 0) {
4530 send_resp(dut, conn, SIGMA_ERROR,
4531 "errorCode,Invalid managementTreeURI postfix");
4532 return 0;
4533 }
4534 if (end - pos >= (int) sizeof(fbuf)) {
4535 send_resp(dut, conn, SIGMA_ERROR,
4536 "errorCode,Too long FQDN in managementTreeURI");
4537 return 0;
4538 }
4539 memcpy(fbuf, pos, end - pos);
4540 fbuf[end - pos] = '\0';
4541 fqdn = fbuf;
4542 sigma_dut_print(dut, DUT_MSG_INFO,
4543 "FQDN from managementTreeURI: %s", fqdn);
4544 } else if (run_hs20_osu(dut, "get_fqdn pps.xml") == 0) {
4545 FILE *f = fopen("pps-fqdn", "r");
4546 if (f) {
4547 if (fgets(fbuf, sizeof(fbuf), f)) {
4548 fbuf[sizeof(fbuf) - 1] = '\0';
4549 fqdn = fbuf;
4550 sigma_dut_print(dut, DUT_MSG_DEBUG,
4551 "Use FQDN %s", fqdn);
4552 }
4553 fclose(f);
4554 }
4555 }
4556
4557 if (fqdn == NULL) {
4558 send_resp(dut, conn, SIGMA_ERROR,
4559 "errorCode,No FQDN specified");
4560 return 0;
4561 }
4562
4563 mkdir("SP", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
4564 snprintf(buf, sizeof(buf), "SP/%s", fqdn);
4565 mkdir(buf, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
4566
4567 snprintf(buf, sizeof(buf), "SP/%s/pps.xml", fqdn);
4568 if (rename("pps.xml", buf) < 0) {
4569 send_resp(dut, conn, SIGMA_ERROR,
4570 "errorCode,Could not move PPS MO");
4571 return 0;
4572 }
4573
4574 if (strcasecmp(path, "VendorSpecific") == 0) {
4575 snprintf(buf, sizeof(buf), "cp Certs/ca.pem SP/%s/ca.pem",
4576 fqdn);
4577 if (system(buf)) {
4578 send_resp(dut, conn, SIGMA_ERROR,
4579 "errorCode,Failed to copy OSU CA cert");
4580 return 0;
4581 }
4582
4583 snprintf(buf, sizeof(buf),
4584 "cp Certs/aaa-ca.pem SP/%s/aaa-ca.pem",
4585 fqdn);
4586 if (system(buf)) {
4587 send_resp(dut, conn, SIGMA_ERROR,
4588 "errorCode,Failed to copy AAA CA cert");
4589 return 0;
4590 }
4591 } else {
4592 snprintf(buf, sizeof(buf),
4593 "dl_osu_ca SP/%s/pps.xml SP/%s/ca.pem",
4594 fqdn, fqdn);
4595 if (run_hs20_osu(dut, buf) < 0) {
4596 send_resp(dut, conn, SIGMA_ERROR,
4597 "errorCode,Failed to download OSU CA cert");
4598 return 0;
4599 }
4600
4601 snprintf(buf, sizeof(buf),
4602 "dl_aaa_ca SP/%s/pps.xml SP/%s/aaa-ca.pem",
4603 fqdn, fqdn);
4604 if (run_hs20_osu(dut, buf) < 0) {
4605 sigma_dut_print(dut, DUT_MSG_INFO,
4606 "Failed to download AAA CA cert");
4607 }
4608 }
4609
4610 if (file_exists("next-client-cert.pem")) {
4611 snprintf(buf, sizeof(buf), "SP/%s/client-cert.pem", fqdn);
4612 if (rename("next-client-cert.pem", buf) < 0) {
4613 send_resp(dut, conn, SIGMA_ERROR,
4614 "errorCode,Could not move client certificate");
4615 return 0;
4616 }
4617 }
4618
4619 if (file_exists("next-client-key.pem")) {
4620 snprintf(buf, sizeof(buf), "SP/%s/client-key.pem", fqdn);
4621 if (rename("next-client-key.pem", buf) < 0) {
4622 send_resp(dut, conn, SIGMA_ERROR,
4623 "errorCode,Could not move client key");
4624 return 0;
4625 }
4626 }
4627
4628 snprintf(buf, sizeof(buf), "set_pps SP/%s/pps.xml", fqdn);
4629 if (run_hs20_osu(dut, buf) < 0) {
4630 send_resp(dut, conn, SIGMA_ERROR,
4631 "errorCode,Failed to configure credential from "
4632 "PPSMO");
4633 return 0;
4634 }
4635
4636 return 1;
4637}
4638
4639
4640static int download_cert(struct sigma_dut *dut,
4641 struct sigma_conn *conn,
4642 const char *intf,
4643 struct sigma_cmd *cmd)
4644{
4645 const char *name, *path;
4646 char url[500], buf[600];
4647
4648 name = get_param(cmd, "FileName");
4649 path = get_param(cmd, "FilePath");
4650 if (name == NULL || path == NULL)
4651 return -1;
4652
4653 if (strcasecmp(path, "VendorSpecific") == 0) {
4654 snprintf(url, sizeof(url), "Certs/%s-cert.pem", name);
4655 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
4656 "certificate from the device (%s)", url);
4657 if (!file_exists(url)) {
4658 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
4659 "certificate file does not exist");
4660 return 0;
4661 }
4662 snprintf(buf, sizeof(buf), "cp %s next-client-cert.pem", url);
4663 if (system(buf) != 0) {
4664 send_resp(dut, conn, SIGMA_ERROR,
4665 "errorCode,Failed to copy client "
4666 "certificate");
4667 return 0;
4668 }
4669
4670 snprintf(url, sizeof(url), "Certs/%s-key.pem", name);
4671 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
4672 "private key from the device (%s)", url);
4673 if (!file_exists(url)) {
4674 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
4675 "private key file does not exist");
4676 return 0;
4677 }
4678 snprintf(buf, sizeof(buf), "cp %s next-client-key.pem", url);
4679 if (system(buf) != 0) {
4680 send_resp(dut, conn, SIGMA_ERROR,
4681 "errorCode,Failed to copy client key");
4682 return 0;
4683 }
4684 } else if (strncasecmp(path, "http:", 5) != 0 &&
4685 strncasecmp(path, "https:", 6) != 0) {
4686 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
4687 "Unsupported FilePath value");
4688 return 0;
4689 } else {
4690 snprintf(url, sizeof(url), "%s/%s.pem", path, name);
4691 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading client "
4692 "certificate/key from %s", url);
4693 snprintf(buf, sizeof(buf),
4694 "wget -T 10 -t 3 -O next-client-cert.pem '%s'", url);
4695 if (system(buf) != 0) {
4696 send_resp(dut, conn, SIGMA_ERROR,
4697 "errorCode,Failed to download client "
4698 "certificate");
4699 return 0;
4700 }
4701
4702 if (system("cp next-client-cert.pem next-client-key.pem") != 0)
4703 {
4704 send_resp(dut, conn, SIGMA_ERROR,
4705 "errorCode,Failed to copy client key");
4706 return 0;
4707 }
4708 }
4709
4710 return 1;
4711}
4712
4713
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02004714static int cmd_sta_preset_testparameters_60ghz(struct sigma_dut *dut,
4715 struct sigma_conn *conn,
4716 struct sigma_cmd *cmd)
4717{
4718 const char *val;
4719 const char *intf = get_param(cmd, "interface");
4720
4721 if (!intf)
4722 return -1;
4723
4724 val = get_param(cmd, "WscIEFragment");
4725 if (val && strcasecmp(val, "enable") == 0) {
4726 sigma_dut_print(dut, DUT_MSG_DEBUG,
4727 "Enable WSC IE fragmentation");
4728
4729 dut->wsc_fragment = 1;
4730 /* set long attributes to force fragmentation */
4731 if (wpa_command(intf, "SET device_name "
4732 WPS_LONG_DEVICE_NAME) < 0)
4733 return -2;
4734 if (wpa_command(intf, "SET manufacturer "
4735 WPS_LONG_MANUFACTURER) < 0)
4736 return -2;
4737 if (wpa_command(intf, "SET model_name "
4738 WPS_LONG_MODEL_NAME) < 0)
4739 return -2;
4740 if (wpa_command(intf, "SET model_number "
4741 WPS_LONG_MODEL_NUMBER) < 0)
4742 return -2;
4743 if (wpa_command(intf, "SET serial_number "
4744 WPS_LONG_SERIAL_NUMBER) < 0)
4745 return -2;
4746 }
4747
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02004748 val = get_param(cmd, "RSN_IE");
4749 if (val) {
4750 if (strcasecmp(val, "disable") == 0)
4751 dut->force_rsn_ie = FORCE_RSN_IE_REMOVE;
4752 else if (strcasecmp(val, "enable") == 0)
4753 dut->force_rsn_ie = FORCE_RSN_IE_ADD;
4754 }
4755
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02004756 val = get_param(cmd, "WpsVersion");
4757 if (val)
4758 dut->wps_forced_version = get_wps_forced_version(dut, val);
4759
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02004760 val = get_param(cmd, "WscEAPFragment");
4761 if (val && strcasecmp(val, "enable") == 0)
4762 dut->eap_fragment = 1;
4763
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02004764 return 1;
4765}
4766
4767
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004768static int cmd_sta_preset_testparameters_hs2_r2(struct sigma_dut *dut,
4769 struct sigma_conn *conn,
4770 const char *intf,
4771 struct sigma_cmd *cmd)
4772{
4773 const char *val;
4774
4775 val = get_param(cmd, "FileType");
4776 if (val && strcasecmp(val, "PPSMO") == 0)
4777 return download_ppsmo(dut, conn, intf, cmd);
4778 if (val && strcasecmp(val, "CERT") == 0)
4779 return download_cert(dut, conn, intf, cmd);
4780 if (val) {
4781 send_resp(dut, conn, SIGMA_ERROR,
4782 "ErrorCode,Unsupported FileType");
4783 return 0;
4784 }
4785
4786 return 1;
4787}
4788
4789
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304790static int cmd_sta_preset_testparameters_oce(struct sigma_dut *dut,
4791 struct sigma_conn *conn,
4792 const char *intf,
4793 struct sigma_cmd *cmd)
4794{
4795 const char *val;
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304796 char buf[1000];
4797 char text[20];
4798 unsigned char addr[ETH_ALEN];
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304799
4800 val = get_param(cmd, "OCESupport");
4801 if (val && strcasecmp(val, "Disable") == 0) {
4802 if (wpa_command(intf, "SET oce 0") < 0) {
4803 send_resp(dut, conn, SIGMA_ERROR,
4804 "ErrorCode,Failed to disable OCE");
4805 return 0;
4806 }
4807 } else if (val && strcasecmp(val, "Enable") == 0) {
4808 if (wpa_command(intf, "SET oce 1") < 0) {
4809 send_resp(dut, conn, SIGMA_ERROR,
4810 "ErrorCode,Failed to enable OCE");
4811 return 0;
4812 }
4813 }
4814
vamsi krishnaa2799492017-12-05 14:28:01 +05304815 val = get_param(cmd, "FILScap");
4816 if (val && (atoi(val) == 1)) {
4817 if (wpa_command(intf, "SET disable_fils 0") < 0) {
4818 send_resp(dut, conn, SIGMA_ERROR,
4819 "ErrorCode,Failed to enable FILS");
4820 return 0;
4821 }
4822 } else if (val && (atoi(val) == 0)) {
4823 if (wpa_command(intf, "SET disable_fils 1") < 0) {
4824 send_resp(dut, conn, SIGMA_ERROR,
4825 "ErrorCode,Failed to disable FILS");
4826 return 0;
4827 }
4828 }
4829
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304830 val = get_param(cmd, "FILSHLP");
4831 if (val && strcasecmp(val, "Enable") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004832 if (get_wpa_status(get_station_ifname(dut), "address", text,
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304833 sizeof(text)) < 0)
4834 return -2;
4835 hwaddr_aton(text, addr);
4836 snprintf(buf, sizeof(buf),
4837 "FILS_HLP_REQ_ADD ff:ff:ff:ff:ff:ff "
4838 "080045100140000040004011399e00000000ffffffff00440043"
4839 "012cb30001010600fd4f46410000000000000000000000000000"
4840 "000000000000"
4841 "%02x%02x%02x%02x%02x%02x"
4842 "0000000000000000000000000000000000000000000000000000"
4843 "0000000000000000000000000000000000000000000000000000"
4844 "0000000000000000000000000000000000000000000000000000"
4845 "0000000000000000000000000000000000000000000000000000"
4846 "0000000000000000000000000000000000000000000000000000"
4847 "0000000000000000000000000000000000000000000000000000"
4848 "0000000000000000000000000000000000000000000000000000"
4849 "0000000000000000000000000000000000000000638253633501"
4850 "013d0701000af549d29b390205dc3c12616e64726f69642d6468"
4851 "63702d382e302e30370a0103060f1a1c333a3b2b5000ff00",
4852 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
4853 if (wpa_command(intf, buf)) {
4854 send_resp(dut, conn, SIGMA_ERROR,
4855 "ErrorCode,Failed to add HLP");
4856 return 0;
4857 }
4858 dut->fils_hlp = 1;
4859 }
4860
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304861 return 1;
4862}
4863
4864
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004865static void ath_sta_set_noack(struct sigma_dut *dut, const char *intf,
4866 const char *val)
4867{
4868 int counter = 0;
4869 char token[50];
4870 char *result;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304871 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004872
Peng Xub8fc5cc2017-05-10 17:27:28 -07004873 strlcpy(token, val, sizeof(token));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004874 token[sizeof(token) - 1] = '\0';
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304875 result = strtok_r(token, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004876 while (result) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004877 if (strcmp(result, "disable") == 0)
4878 run_iwpriv(dut, intf, "noackpolicy %d 1 0", counter);
4879 else
4880 run_iwpriv(dut, intf, "noackpolicy %d 1 1", counter);
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304881 result = strtok_r(NULL, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004882 counter++;
4883 }
4884}
4885
4886
4887static void ath_sta_set_rts(struct sigma_dut *dut, const char *intf,
4888 const char *val)
4889{
4890 char buf[100];
4891
4892 snprintf(buf, sizeof(buf), "iwconfig %s rts %s", intf, val);
4893 if (system(buf) != 0) {
4894 sigma_dut_print(dut, DUT_MSG_ERROR, "iwconfig RTS failed");
4895 }
4896}
4897
4898
4899static void ath_sta_set_wmm(struct sigma_dut *dut, const char *intf,
4900 const char *val)
4901{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004902 if (strcasecmp(val, "off") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004903 run_iwpriv(dut, intf, "wmm 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004904 }
4905}
4906
4907
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08004908static int wcn_sta_set_wmm(struct sigma_dut *dut, const char *intf,
4909 const char *val)
4910{
4911#ifdef NL80211_SUPPORT
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08004912 int wmmenable = 1;
4913
4914 if (val &&
4915 (strcasecmp(val, "off") == 0 || strcmp(val, "0") == 0))
4916 wmmenable = 0;
4917
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05304918 return wcn_wifi_test_config_set_u8(
4919 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WMM_ENABLE,
4920 wmmenable);
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08004921#else /* NL80211_SUPPORT */
4922 sigma_dut_print(dut, DUT_MSG_ERROR,
4923 "WMM cannot be changed without NL80211_SUPPORT defined");
4924 return -1;
4925#endif /* NL80211_SUPPORT */
4926}
4927
4928
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004929static void ath_sta_set_sgi(struct sigma_dut *dut, const char *intf,
4930 const char *val)
4931{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004932 int sgi20;
4933
4934 sgi20 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
4935
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004936 run_iwpriv(dut, intf, "shortgi %d", sgi20);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004937}
4938
4939
4940static void ath_sta_set_11nrates(struct sigma_dut *dut, const char *intf,
4941 const char *val)
4942{
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05304943 int rate_code, v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004944
4945 /* Disable Tx Beam forming when using a fixed rate */
4946 ath_disable_txbf(dut, intf);
4947
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05304948 v = atoi(val);
4949 if (v < 0 || v > 32) {
4950 sigma_dut_print(dut, DUT_MSG_ERROR,
4951 "Invalid Fixed MCS rate: %d", v);
4952 return;
4953 }
4954 rate_code = 0x80 + v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004955
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004956 run_iwpriv(dut, intf, "set11NRates 0x%x", rate_code);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004957
4958 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004959 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004960}
4961
4962
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08004963static void iwpriv_sta_set_amsdu(struct sigma_dut *dut, const char *intf,
4964 const char *val)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004965{
4966 char buf[60];
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304967 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004968
4969 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)
4970 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 2", intf);
4971 else
4972 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf);
4973
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304974 ret = system(buf);
4975#ifdef NL80211_SUPPORT
4976 if (ret) {
4977 int value = (strcasecmp(val, "Enable") == 0) ? 2 : 1;
4978
4979 ret = sta_config_params(dut, intf, STA_SET_TX_MSDU, value);
4980 ret |= sta_config_params(dut, intf, STA_SET_RX_MSDU, value);
4981 }
4982#endif /* NL80211_SUPPORT */
4983 if (ret)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004984 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv amsdu failed");
4985}
4986
4987
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004988static int iwpriv_sta_set_ampdu(struct sigma_dut *dut, const char *intf,
4989 int ampdu)
4990{
4991 char buf[60];
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08004992 int maxaggregation = 63;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004993
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08004994 if (ampdu)
4995 ampdu = maxaggregation;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004996 snprintf(buf, sizeof(buf), "iwpriv %s ampdu %d", intf, ampdu);
4997 if (system(buf) != 0) {
4998 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv ampdu failed");
4999 return -1;
5000 }
5001
5002 return 0;
5003}
5004
5005
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005006static void ath_sta_set_stbc(struct sigma_dut *dut, const char *intf,
5007 const char *val)
5008{
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005009 run_iwpriv(dut, intf, "tx_stbc %s", val);
5010 run_iwpriv(dut, intf, "rx_stbc %s", val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005011}
5012
5013
5014static int wcn_sta_set_cts_width(struct sigma_dut *dut, const char *intf,
5015 const char *val)
5016{
5017 char buf[60];
5018
Peng Xucc317ed2017-05-18 16:44:37 -07005019 if (strcmp(val, "160") == 0) {
5020 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 5", intf);
5021 } else if (strcmp(val, "80") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005022 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
5023 } else if (strcmp(val, "40") == 0) {
5024 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 2", intf);
5025 } else if (strcmp(val, "20") == 0) {
5026 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 1", intf);
5027 } else if (strcasecmp(val, "Auto") == 0) {
5028 buf[0] = '\0';
5029 } else {
5030 sigma_dut_print(dut, DUT_MSG_ERROR,
5031 "WIDTH/CTS_WIDTH value not supported");
5032 return -1;
5033 }
5034
5035 if (buf[0] != '\0' && system(buf) != 0) {
5036 sigma_dut_print(dut, DUT_MSG_ERROR,
5037 "Failed to set WIDTH/CTS_WIDTH");
5038 return -1;
5039 }
5040
5041 return 0;
5042}
5043
5044
5045int ath_set_width(struct sigma_dut *dut, struct sigma_conn *conn,
5046 const char *intf, const char *val)
5047{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005048 if (strcasecmp(val, "Auto") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005049 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005050 dut->chwidth = 0;
5051 } else if (strcasecmp(val, "20") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005052 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005053 dut->chwidth = 0;
5054 } else if (strcasecmp(val, "40") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005055 run_iwpriv(dut, intf, "chwidth 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005056 dut->chwidth = 1;
5057 } else if (strcasecmp(val, "80") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005058 run_iwpriv(dut, intf, "chwidth 2");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005059 dut->chwidth = 2;
5060 } else if (strcasecmp(val, "160") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005061 run_iwpriv(dut, intf, "chwidth 3");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005062 dut->chwidth = 3;
5063 } else {
5064 send_resp(dut, conn, SIGMA_ERROR,
5065 "ErrorCode,WIDTH not supported");
5066 return -1;
5067 }
5068
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005069 return 0;
5070}
5071
5072
5073static int wcn_sta_set_sp_stream(struct sigma_dut *dut, const char *intf,
5074 const char *val)
5075{
5076 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07005077 int sta_nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005078
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08005079 if (strcmp(val, "1SS") == 0 || strcmp(val, "1") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005080 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07005081 sta_nss = 1;
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08005082 } else if (strcmp(val, "2SS") == 0 || strcmp(val, "2") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005083 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07005084 sta_nss = 2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005085 } else {
5086 sigma_dut_print(dut, DUT_MSG_ERROR,
5087 "SP_STREAM value not supported");
5088 return -1;
5089 }
5090
5091 if (system(buf) != 0) {
5092 sigma_dut_print(dut, DUT_MSG_ERROR,
5093 "Failed to set SP_STREAM");
5094 return -1;
5095 }
5096
Arif Hussainac6c5112018-05-25 17:34:00 -07005097 dut->sta_nss = sta_nss;
5098
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005099 return 0;
5100}
5101
5102
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05305103static void wcn_sta_set_stbc(struct sigma_dut *dut, const char *intf,
5104 const char *val)
5105{
5106 char buf[60];
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05305107 int ret;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05305108
5109 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc %s", intf, val);
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05305110 ret = system(buf);
5111#ifdef NL80211_SUPPORT
5112 if (ret)
5113 ret = sta_config_params(dut, intf, STA_SET_TX_STBC,
5114 strcmp(val, "0") == 0 ? 0 : 1);
5115#endif /* NL80211_SUPPORT */
5116 if (ret)
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05305117 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv tx_stbc failed");
5118
5119 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc %s", intf, val);
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05305120 ret = system(buf);
5121#ifdef NL80211_SUPPORT
5122 if (ret)
5123 ret = sta_config_params(dut, intf, STA_SET_RX_STBC,
5124 strcmp(val, "0") == 0 ? 0 : 1);
5125#endif /* NL80211_SUPPORT */
5126 if (ret)
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05305127 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv rx_stbc failed");
5128}
5129
5130
Ashwini Patil68d02cd2017-01-10 15:39:16 +05305131static int mbo_set_cellular_data_capa(struct sigma_dut *dut,
5132 struct sigma_conn *conn,
5133 const char *intf, int capa)
5134{
5135 char buf[32];
5136
5137 if (capa > 0 && capa < 4) {
5138 snprintf(buf, sizeof(buf), "SET mbo_cell_capa %d", capa);
5139 if (wpa_command(intf, buf) < 0) {
5140 send_resp(dut, conn, SIGMA_ERROR,
5141 "ErrorCode, Failed to set cellular data capability");
5142 return 0;
5143 }
5144 return 1;
5145 }
5146
5147 sigma_dut_print(dut, DUT_MSG_ERROR,
5148 "Invalid Cellular data capability: %d", capa);
5149 send_resp(dut, conn, SIGMA_INVALID,
5150 "ErrorCode,Invalid cellular data capability");
5151 return 0;
5152}
5153
5154
Ashwini Patil9183fdb2017-04-13 16:58:25 +05305155static int mbo_set_roaming(struct sigma_dut *dut, struct sigma_conn *conn,
5156 const char *intf, const char *val)
5157{
5158 if (strcasecmp(val, "Disable") == 0) {
5159 if (wpa_command(intf, "SET roaming 0") < 0) {
5160 send_resp(dut, conn, SIGMA_ERROR,
5161 "ErrorCode,Failed to disable roaming");
5162 return 0;
5163 }
5164 return 1;
5165 }
5166
5167 if (strcasecmp(val, "Enable") == 0) {
5168 if (wpa_command(intf, "SET roaming 1") < 0) {
5169 send_resp(dut, conn, SIGMA_ERROR,
5170 "ErrorCode,Failed to enable roaming");
5171 return 0;
5172 }
5173 return 1;
5174 }
5175
5176 sigma_dut_print(dut, DUT_MSG_ERROR,
5177 "Invalid value provided for roaming: %s", val);
5178 send_resp(dut, conn, SIGMA_INVALID,
5179 "ErrorCode,Unknown value provided for Roaming");
5180 return 0;
5181}
5182
5183
Ashwini Patila75de5a2017-04-13 16:35:05 +05305184static int mbo_set_assoc_disallow(struct sigma_dut *dut,
5185 struct sigma_conn *conn,
5186 const char *intf, const char *val)
5187{
5188 if (strcasecmp(val, "Disable") == 0) {
5189 if (wpa_command(intf, "SET ignore_assoc_disallow 1") < 0) {
5190 send_resp(dut, conn, SIGMA_ERROR,
5191 "ErrorCode,Failed to disable Assoc_disallow");
5192 return 0;
5193 }
5194 return 1;
5195 }
5196
5197 if (strcasecmp(val, "Enable") == 0) {
5198 if (wpa_command(intf, "SET ignore_assoc_disallow 0") < 0) {
5199 send_resp(dut, conn, SIGMA_ERROR,
5200 "ErrorCode,Failed to enable Assoc_disallow");
5201 return 0;
5202 }
5203 return 1;
5204 }
5205
5206 sigma_dut_print(dut, DUT_MSG_ERROR,
5207 "Invalid value provided for Assoc_disallow: %s", val);
5208 send_resp(dut, conn, SIGMA_INVALID,
5209 "ErrorCode,Unknown value provided for Assoc_disallow");
5210 return 0;
5211}
5212
5213
Ashwini Patilc63161e2017-04-13 16:30:23 +05305214static int mbo_set_bss_trans_req(struct sigma_dut *dut, struct sigma_conn *conn,
5215 const char *intf, const char *val)
5216{
5217 if (strcasecmp(val, "Reject") == 0) {
5218 if (wpa_command(intf, "SET reject_btm_req_reason 1") < 0) {
5219 send_resp(dut, conn, SIGMA_ERROR,
5220 "ErrorCode,Failed to Reject BTM Request");
5221 return 0;
5222 }
5223 return 1;
5224 }
5225
5226 if (strcasecmp(val, "Accept") == 0) {
5227 if (wpa_command(intf, "SET reject_btm_req_reason 0") < 0) {
5228 send_resp(dut, conn, SIGMA_ERROR,
5229 "ErrorCode,Failed to Accept BTM Request");
5230 return 0;
5231 }
5232 return 1;
5233 }
5234
5235 sigma_dut_print(dut, DUT_MSG_ERROR,
5236 "Invalid value provided for BSS_Transition: %s", val);
5237 send_resp(dut, conn, SIGMA_INVALID,
5238 "ErrorCode,Unknown value provided for BSS_Transition");
5239 return 0;
5240}
5241
5242
Ashwini Patil00402582017-04-13 12:29:39 +05305243static int mbo_set_non_pref_ch_list(struct sigma_dut *dut,
5244 struct sigma_conn *conn,
5245 const char *intf,
5246 struct sigma_cmd *cmd)
5247{
5248 const char *ch, *pref, *op_class, *reason;
5249 char buf[120];
5250 int len, ret;
5251
5252 pref = get_param(cmd, "Ch_Pref");
5253 if (!pref)
5254 return 1;
5255
5256 if (strcasecmp(pref, "clear") == 0) {
5257 free(dut->non_pref_ch_list);
5258 dut->non_pref_ch_list = NULL;
5259 } else {
5260 op_class = get_param(cmd, "Ch_Op_Class");
5261 if (!op_class) {
5262 send_resp(dut, conn, SIGMA_INVALID,
5263 "ErrorCode,Ch_Op_Class not provided");
5264 return 0;
5265 }
5266
5267 ch = get_param(cmd, "Ch_Pref_Num");
5268 if (!ch) {
5269 send_resp(dut, conn, SIGMA_INVALID,
5270 "ErrorCode,Ch_Pref_Num not provided");
5271 return 0;
5272 }
5273
5274 reason = get_param(cmd, "Ch_Reason_Code");
5275 if (!reason) {
5276 send_resp(dut, conn, SIGMA_INVALID,
5277 "ErrorCode,Ch_Reason_Code not provided");
5278 return 0;
5279 }
5280
5281 if (!dut->non_pref_ch_list) {
5282 dut->non_pref_ch_list =
5283 calloc(1, NON_PREF_CH_LIST_SIZE);
5284 if (!dut->non_pref_ch_list) {
5285 send_resp(dut, conn, SIGMA_ERROR,
5286 "ErrorCode,Failed to allocate memory for non_pref_ch_list");
5287 return 0;
5288 }
5289 }
5290 len = strlen(dut->non_pref_ch_list);
5291 ret = snprintf(dut->non_pref_ch_list + len,
5292 NON_PREF_CH_LIST_SIZE - len,
5293 " %s:%s:%s:%s", op_class, ch, pref, reason);
5294 if (ret > 0 && ret < NON_PREF_CH_LIST_SIZE - len) {
5295 sigma_dut_print(dut, DUT_MSG_DEBUG, "non_pref_list: %s",
5296 dut->non_pref_ch_list);
5297 } else {
5298 sigma_dut_print(dut, DUT_MSG_ERROR,
5299 "snprintf failed for non_pref_list, ret = %d",
5300 ret);
5301 send_resp(dut, conn, SIGMA_ERROR,
5302 "ErrorCode,snprintf failed");
5303 free(dut->non_pref_ch_list);
5304 dut->non_pref_ch_list = NULL;
5305 return 0;
5306 }
5307 }
5308
5309 ret = snprintf(buf, sizeof(buf), "SET non_pref_chan%s",
5310 dut->non_pref_ch_list ? dut->non_pref_ch_list : " ");
5311 if (ret < 0 || ret >= (int) sizeof(buf)) {
5312 sigma_dut_print(dut, DUT_MSG_DEBUG,
5313 "snprintf failed for set non_pref_chan, ret: %d",
5314 ret);
5315 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,snprint failed");
5316 return 0;
5317 }
5318
5319 if (wpa_command(intf, buf) < 0) {
5320 send_resp(dut, conn, SIGMA_ERROR,
5321 "ErrorCode,Failed to set non-preferred channel list");
5322 return 0;
5323 }
5324
5325 return 1;
5326}
5327
5328
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08005329#ifdef NL80211_SUPPORT
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08005330
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08005331static int sta_set_he_htc_supp(struct sigma_dut *dut, const char *intf,
5332 uint8_t cfg)
5333{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05305334 return wcn_wifi_test_config_set_u8(
5335 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_HTC_HE_SUPP,
5336 cfg);
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08005337}
5338
5339
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08005340static int sta_set_he_fragmentation(struct sigma_dut *dut, const char *intf,
5341 enum he_fragmentation_val frag)
5342{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05305343 return wcn_wifi_test_config_set_u8(
5344 dut, intf,
5345 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_FRAGMENTATION, frag);
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08005346}
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08005347
5348
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -08005349int wcn_set_he_ltf(struct sigma_dut *dut, const char *intf,
5350 enum qca_wlan_he_ltf_cfg ltf)
Subhani Shaik8e7a3052018-04-24 14:03:00 -07005351{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05305352 return wcn_wifi_test_config_set_u8(
5353 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_LTF, ltf);
Subhani Shaik8e7a3052018-04-24 14:03:00 -07005354}
5355
5356
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08005357static int nlvendor_sta_set_noack(struct sigma_dut *dut, const char *intf,
5358 int noack, enum qca_wlan_ac_type ac)
5359{
5360 struct nl_msg *msg;
5361 int ret = 0;
5362 struct nlattr *params;
5363 int ifindex;
5364
5365 ifindex = if_nametoindex(intf);
5366 if (ifindex == 0) {
5367 sigma_dut_print(dut, DUT_MSG_ERROR,
5368 "%s: Index for interface %s failed",
5369 __func__, intf);
5370 return -1;
5371 }
5372
5373 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5374 NL80211_CMD_VENDOR)) ||
5375 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5376 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5377 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5378 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5379 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5380 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_NO_ACK,
5381 noack) ||
5382 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_NO_ACK_AC,
5383 ac)) {
5384 sigma_dut_print(dut, DUT_MSG_ERROR,
5385 "%s: err in adding vendor_cmd and vendor_data",
5386 __func__);
5387 nlmsg_free(msg);
5388 return -1;
5389 }
5390 nla_nest_end(msg, params);
5391
5392 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5393 if (ret) {
5394 sigma_dut_print(dut, DUT_MSG_ERROR,
5395 "%s: err in send_and_recv_msgs, ret=%d",
5396 __func__, ret);
5397 }
5398 return ret;
5399}
5400
5401
5402static void wcn_sta_set_noack(struct sigma_dut *dut, const char *intf,
5403 const char *val)
5404{
5405 int noack, ret;
5406 char token[100];
5407 char *result;
5408 char *saveptr;
5409 enum qca_wlan_ac_type ac = QCA_WLAN_AC_BE;
5410
5411 strlcpy(token, val, sizeof(token));
5412 token[sizeof(token) - 1] = '\0';
5413 result = strtok_r(token, ":", &saveptr);
5414 while (result) {
5415 noack = strcasecmp(result, "Disable") != 0;
5416 ret = nlvendor_sta_set_noack(dut, intf, noack, ac);
5417 if (ret) {
5418 sigma_dut_print(dut, DUT_MSG_ERROR,
5419 "nlvendor_sta_set_noack failed for ac:%d, ret:%d",
5420 ac, ret);
5421 }
5422 result = strtok_r(NULL, ":", &saveptr);
5423 ac++;
5424 }
5425}
5426
Vinita S. Maloo7462e812020-05-22 15:16:04 +05305427
5428static int nlvendor_sta_set_phymode(struct sigma_dut *dut, const char *intf,
5429 enum qca_wlan_vendor_phy_mode val)
5430{
5431 struct nl_msg *msg;
5432 struct nlattr *params;
5433 int ifindex, ret;
5434
5435 ifindex = if_nametoindex(intf);
5436 if (ifindex == 0) {
5437 sigma_dut_print(dut, DUT_MSG_ERROR,
5438 "%s: Index for interface %s not found",
5439 __func__, intf);
5440 return -1;
5441 }
5442
5443 msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5444 NL80211_CMD_VENDOR);
5445 if (!msg) {
5446 sigma_dut_print(dut, DUT_MSG_ERROR,
5447 "%s: err in adding vendor_cmd", __func__);
5448 return -1;
5449 }
5450
5451 if (nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5452 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5453 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION)) {
5454 sigma_dut_print(dut, DUT_MSG_ERROR,
5455 "%s: err in adding vendor_attr", __func__);
5456 nlmsg_free(msg);
5457 return -1;
5458 }
5459
5460 params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
5461 if (!params || nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_PHY_MODE,
5462 val)) {
5463 sigma_dut_print(dut, DUT_MSG_ERROR,
5464 "%s: err in adding vendor_data", __func__);
5465 nlmsg_free(msg);
5466 return -1;
5467 }
5468
5469 nla_nest_end(msg, params);
5470 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5471 if (ret) {
5472 sigma_dut_print(dut, DUT_MSG_ERROR,
5473 "%s: err in send_and_recv_msgs, ret=%d (%s)",
5474 __func__, ret, strerror(-ret));
5475 return ret;
5476 }
5477
5478 return 0;
5479}
5480
5481
5482static enum qca_wlan_vendor_phy_mode get_qca_vendor_phymode(const char *val)
5483{
5484 if (strcmp(val, "11a") == 0) {
5485 /* IEEE80211_MODE_11A */
5486 return QCA_WLAN_VENDOR_PHY_MODE_11A;
5487 }
5488
5489 if (strcmp(val, "11g") == 0) {
5490 /* IEEE80211_MODE_11G */
5491 return QCA_WLAN_VENDOR_PHY_MODE_11G;
5492 }
5493
5494 if (strcmp(val, "11b") == 0) {
5495 /* IEEE80211_MODE_11B */
5496 return QCA_WLAN_VENDOR_PHY_MODE_11B;
5497 }
5498
5499 if (strcmp(val, "11n") == 0 ||
5500 strcmp(val, "11nl") == 0 ||
5501 strcmp(val, "11nl(nabg)") == 0) {
5502 /* IEEE80211_MODE_11AGN */
5503 return QCA_WLAN_VENDOR_PHY_MODE_11AGN;
5504 }
5505
5506 if (strcmp(val, "11ng") == 0) {
5507 /* IEEE80211_MODE_11NG_HT40 */
5508 return QCA_WLAN_VENDOR_PHY_MODE_11NG_HT40;
5509 }
5510
5511 if (strcmp(val, "AC") == 0 ||
5512 strcasecmp(val, "11AC") == 0) {
5513 /* IEEE80211_MODE_11AC_VHT80 */
5514 return QCA_WLAN_VENDOR_PHY_MODE_11AC_VHT80;
5515 }
5516
5517 if (strcmp(val, "11na") == 0 ||
5518 strcasecmp(val, "11an") == 0) {
5519 /* IEEE80211_MODE_11NA_HT40 */
5520 return QCA_WLAN_VENDOR_PHY_MODE_11NA_HT40;
5521 }
5522
5523 if (strcmp(val, "11ax") == 0 ||
5524 strcmp(val, "auto") == 0) {
5525 /* IEEE80211_MODE_AUTO */
5526 return QCA_WLAN_VENDOR_PHY_MODE_AUTO;
5527 }
5528
5529 return -1;
5530}
5531
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08005532#endif /* NL80211_SUPPORT */
5533
5534
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05305535static int get_phymode(const char *val)
5536{
5537 if (strcmp(val, "11a") == 0)
5538 return 1; /* IEEE80211_MODE_11A */
5539 if (strcmp(val, "11g") == 0)
5540 return 3; /* IEEE80211_MODE_11G */
5541 if (strcmp(val, "11b") == 0)
5542 return 2; /* IEEE80211_MODE_11B */
5543 if (strcmp(val, "11n") == 0 ||
5544 strcmp(val, "11nl") == 0 ||
5545 strcmp(val, "11nl(nabg)") == 0)
5546 return 22; /* IEEE80211_MODE_11AGN */
5547 if (strcmp(val, "11ng") == 0)
5548 return 13; /* IEEE80211_MODE_11NG_HT40 */
5549 if (strcmp(val, "AC") == 0 ||
5550 strcasecmp(val, "11AC") == 0)
5551 return 19; /* IEEE80211_MODE_11AC_VHT80 */
5552 if (strcmp(val, "11na") == 0 ||
5553 strcasecmp(val, "11an") == 0)
5554 return 14; /* IEEE80211_MODE_11NA_HT40 */
5555 if (strcmp(val, "11ax") == 0 ||
5556 strcmp(val, "auto") == 0)
5557 return 0; /* IEEE80211_MODE_AUTO */
5558 return -1;
5559}
5560
5561
5562static void sta_set_phymode(struct sigma_dut *dut, const char *intf,
5563 const char *val)
5564{
5565 char buf[100];
5566 int len, phymode;
Vinita S. Maloo7462e812020-05-22 15:16:04 +05305567#ifdef NL80211_SUPPORT
5568 enum qca_wlan_vendor_phy_mode qca_phymode;
5569
5570 qca_phymode = get_qca_vendor_phymode(val);
5571 if (qca_phymode == -1) {
5572 sigma_dut_print(dut, DUT_MSG_DEBUG,
5573 "Ignoring mode change for mode: %s",
5574 val);
5575 return;
5576 }
5577
5578 if (nlvendor_sta_set_phymode(dut, intf, qca_phymode) == 0)
5579 return;
5580#endif /* NL80211_SUPPORT */
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05305581
5582 phymode = get_phymode(val);
5583 if (phymode == -1) {
5584 sigma_dut_print(dut, DUT_MSG_DEBUG,
5585 "Ignoring mode change for mode: %s",
5586 val);
5587 return;
5588 }
5589
5590 len = snprintf(buf, sizeof(buf), "iwpriv %s setphymode %d", intf,
5591 phymode);
5592 if (len < 0 || len >= sizeof(buf)) {
5593 sigma_dut_print(dut, DUT_MSG_ERROR,
5594 "Failed to set phymode");
5595 return;
5596 }
5597
5598 if (system(buf) != 0)
5599 sigma_dut_print(dut, DUT_MSG_ERROR,
5600 "iwpriv setting of phymode failed");
5601}
5602
5603
Jouni Malinenf7222712019-06-13 01:50:21 +03005604static enum sigma_cmd_result
5605cmd_sta_preset_testparameters(struct sigma_dut *dut, struct sigma_conn *conn,
5606 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005607{
5608 const char *intf = get_param(cmd, "Interface");
5609 const char *val;
5610
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03005611 val = get_param(cmd, "FT_DS");
5612 if (val) {
5613 if (strcasecmp(val, "Enable") == 0) {
5614 dut->sta_ft_ds = 1;
5615 } else if (strcasecmp(val, "Disable") == 0) {
5616 dut->sta_ft_ds = 0;
5617 } else {
5618 send_resp(dut, conn, SIGMA_ERROR,
5619 "errorCode,Unsupported value for FT_DS");
5620 return STATUS_SENT_ERROR;
5621 }
Shivani Baranwal7aa48602021-09-29 10:53:38 +05305622 if (get_driver_type(dut) == DRIVER_WCN &&
5623 sta_config_params(dut, intf, STA_SET_FT_DS,
5624 dut->sta_ft_ds) != 0) {
5625 send_resp(dut, conn, SIGMA_ERROR,
5626 "errorCode,Failed to enable/disable FT_DS");
5627 return STATUS_SENT_ERROR;
5628 }
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03005629 }
5630
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005631 val = get_param(cmd, "Program");
Jouni Malinen1f6ae642018-06-07 23:56:13 +03005632 if (val && (strcasecmp(val, "HS2-R2") == 0 ||
5633 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005634 return cmd_sta_preset_testparameters_hs2_r2(dut, conn, intf,
5635 cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005636
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07005637 if (val && strcasecmp(val, "LOC") == 0)
5638 return loc_cmd_sta_preset_testparameters(dut, conn, cmd);
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02005639 if (val && strcasecmp(val, "60GHZ") == 0) {
5640 val = get_param(cmd, "WPS");
5641 if (val && strcasecmp(val, "disable") == 0) {
5642 dut->wps_disable = 1;
5643 sigma_dut_print(dut, DUT_MSG_INFO, "WPS disabled");
5644 } else {
5645 /* wps_disable can have other value from the previous
5646 * test, so make sure it has the correct value.
5647 */
5648 dut->wps_disable = 0;
5649 }
5650
5651 val = get_param(cmd, "P2P");
5652 if (val && strcasecmp(val, "disable") == 0)
5653 sigma_dut_print(dut, DUT_MSG_INFO, "P2P disabled");
5654 }
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07005655
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02005656 if (dut->program == PROGRAM_WPS && dut->band == WPS_BAND_60G)
5657 return cmd_sta_preset_testparameters_60ghz(dut, conn, cmd);
5658
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005659#ifdef ANDROID_NAN
5660 if (val && strcasecmp(val, "NAN") == 0)
5661 return nan_cmd_sta_preset_testparameters(dut, conn, cmd);
5662#endif /* ANDROID_NAN */
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07005663#ifdef MIRACAST
5664 if (val && (strcasecmp(val, "WFD") == 0 ||
5665 strcasecmp(val, "DisplayR2") == 0))
5666 return miracast_preset_testparameters(dut, conn, cmd);
5667#endif /* MIRACAST */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005668
Kiran Kumar Lokeredd086642020-06-04 00:29:26 -07005669 if (val &&
5670 (strcasecmp(val, "MBO") == 0 || strcasecmp(val, "HE") == 0)) {
Ashwini Patil68d02cd2017-01-10 15:39:16 +05305671 val = get_param(cmd, "Cellular_Data_Cap");
5672 if (val &&
5673 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
5674 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +05305675
5676 val = get_param(cmd, "Ch_Pref");
5677 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
5678 return 0;
5679
Ashwini Patilc63161e2017-04-13 16:30:23 +05305680 val = get_param(cmd, "BSS_Transition");
5681 if (val && mbo_set_bss_trans_req(dut, conn, intf, val) == 0)
5682 return 0;
5683
Ashwini Patila75de5a2017-04-13 16:35:05 +05305684 val = get_param(cmd, "Assoc_Disallow");
5685 if (val && mbo_set_assoc_disallow(dut, conn, intf, val) == 0)
5686 return 0;
5687
Ashwini Patil9183fdb2017-04-13 16:58:25 +05305688 val = get_param(cmd, "Roaming");
5689 if (val && mbo_set_roaming(dut, conn, intf, val) == 0)
5690 return 0;
5691
Ashwini Patil68d02cd2017-01-10 15:39:16 +05305692 return 1;
5693 }
5694
Ankita Bajaja2cb5672017-10-25 16:08:28 +05305695 if (val && strcasecmp(val, "OCE") == 0)
5696 return cmd_sta_preset_testparameters_oce(dut, conn, intf, cmd);
5697
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005698#if 0
5699 val = get_param(cmd, "Supplicant");
5700 if (val && strcasecmp(val, "Default") != 0) {
5701 send_resp(dut, conn, SIGMA_ERROR,
5702 "ErrorCode,Only default(Vendor) supplicant "
5703 "supported");
5704 return 0;
5705 }
5706#endif
5707
5708 val = get_param(cmd, "RTS");
5709 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005710 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005711 case DRIVER_ATHEROS:
5712 ath_sta_set_rts(dut, intf, val);
5713 break;
5714 default:
5715#if 0
5716 send_resp(dut, conn, SIGMA_ERROR,
5717 "ErrorCode,Setting RTS not supported");
5718 return 0;
5719#else
5720 sigma_dut_print(dut, DUT_MSG_DEBUG,
5721 "Setting RTS not supported");
5722 break;
5723#endif
5724 }
5725 }
5726
5727#if 0
5728 val = get_param(cmd, "FRGMNT");
5729 if (val) {
5730 /* TODO */
5731 send_resp(dut, conn, SIGMA_ERROR,
5732 "ErrorCode,Setting FRGMNT not supported");
5733 return 0;
5734 }
5735#endif
5736
5737#if 0
5738 val = get_param(cmd, "Preamble");
5739 if (val) {
5740 /* TODO: Long/Short */
5741 send_resp(dut, conn, SIGMA_ERROR,
5742 "ErrorCode,Setting Preamble not supported");
5743 return 0;
5744 }
5745#endif
5746
5747 val = get_param(cmd, "Mode");
5748 if (val) {
5749 if (strcmp(val, "11b") == 0 ||
5750 strcmp(val, "11g") == 0 ||
5751 strcmp(val, "11a") == 0 ||
5752 strcmp(val, "11n") == 0 ||
5753 strcmp(val, "11ng") == 0 ||
5754 strcmp(val, "11nl") == 0 ||
5755 strcmp(val, "11nl(nabg)") == 0 ||
5756 strcmp(val, "AC") == 0 ||
5757 strcmp(val, "11AC") == 0 ||
5758 strcmp(val, "11ac") == 0 ||
5759 strcmp(val, "11na") == 0 ||
Amarnath Hullur Subramanyamb0db2712018-01-30 19:40:35 -08005760 strcmp(val, "11an") == 0 ||
5761 strcmp(val, "11ax") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005762 /* STA supports all modes by default */
5763 } else {
5764 send_resp(dut, conn, SIGMA_ERROR,
5765 "ErrorCode,Setting Mode not supported");
5766 return 0;
5767 }
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08005768
5769 /* Change the mode only in case of testbed for HE program
5770 * and for 11a and 11g modes only. */
5771 if (dut->program == PROGRAM_HE &&
5772 dut->device_type == STA_testbed) {
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05305773 sta_set_phymode(dut, intf, val);
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08005774 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005775 }
5776
5777 val = get_param(cmd, "wmm");
5778 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005779 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005780 case DRIVER_ATHEROS:
5781 ath_sta_set_wmm(dut, intf, val);
5782 break;
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08005783 case DRIVER_WCN:
5784 wcn_sta_set_wmm(dut, intf, val);
5785 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005786 default:
5787 sigma_dut_print(dut, DUT_MSG_DEBUG,
5788 "Setting wmm not supported");
5789 break;
5790 }
5791 }
5792
5793 val = get_param(cmd, "Powersave");
5794 if (val) {
5795 if (strcmp(val, "0") == 0 || strcasecmp(val, "off") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005796 if (get_driver_type(dut) == DRIVER_WCN) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +05305797 if (set_power_save_wcn(dut, intf, 2) < 0)
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005798 return 0;
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005799 }
5800
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005801 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005802 "P2P_SET ps 0") < 0)
5803 return -2;
5804 /* Make sure test modes are disabled */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005805 wpa_command(get_station_ifname(dut), "P2P_SET ps 98");
5806 wpa_command(get_station_ifname(dut), "P2P_SET ps 96");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005807 } else if (strcmp(val, "1") == 0 ||
5808 strcasecmp(val, "PSPoll") == 0 ||
5809 strcasecmp(val, "on") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005810 if (get_driver_type(dut) == DRIVER_WCN) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +05305811 if (set_power_save_wcn(dut, intf, 1) < 0)
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005812 return 0;
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005813 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005814 /* Disable default power save mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005815 wpa_command(get_station_ifname(dut), "P2P_SET ps 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005816 /* Enable PS-Poll test mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005817 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005818 "P2P_SET ps 97") < 0 ||
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005819 wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005820 "P2P_SET ps 99") < 0)
5821 return -2;
5822 } else if (strcmp(val, "2") == 0 ||
5823 strcasecmp(val, "Fast") == 0) {
5824 /* TODO */
5825 send_resp(dut, conn, SIGMA_ERROR,
5826 "ErrorCode,Powersave=Fast not supported");
5827 return 0;
5828 } else if (strcmp(val, "3") == 0 ||
5829 strcasecmp(val, "PSNonPoll") == 0) {
5830 /* Make sure test modes are disabled */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005831 wpa_command(get_station_ifname(dut), "P2P_SET ps 98");
5832 wpa_command(get_station_ifname(dut), "P2P_SET ps 96");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005833
5834 /* Enable default power save mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005835 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005836 "P2P_SET ps 1") < 0)
5837 return -2;
5838 } else
5839 return -1;
5840 }
5841
5842 val = get_param(cmd, "NoAck");
5843 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005844 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005845 case DRIVER_ATHEROS:
5846 ath_sta_set_noack(dut, intf, val);
5847 break;
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08005848#ifdef NL80211_SUPPORT
5849 case DRIVER_WCN:
5850 wcn_sta_set_noack(dut, intf, val);
5851 break;
5852#endif /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005853 default:
5854 send_resp(dut, conn, SIGMA_ERROR,
5855 "ErrorCode,Setting NoAck not supported");
5856 return 0;
5857 }
5858 }
5859
5860 val = get_param(cmd, "IgnoreChswitchProhibit");
5861 if (val) {
5862 /* TODO: Enabled/disabled */
5863 if (strcasecmp(val, "Enabled") == 0) {
5864 send_resp(dut, conn, SIGMA_ERROR,
5865 "ErrorCode,Enabling IgnoreChswitchProhibit "
5866 "not supported");
5867 return 0;
5868 }
5869 }
5870
5871 val = get_param(cmd, "TDLS");
5872 if (val) {
5873 if (strcasecmp(val, "Disabled") == 0) {
5874 if (wpa_command(intf, "SET tdls_disabled 1")) {
5875 send_resp(dut, conn, SIGMA_ERROR,
5876 "ErrorCode,Failed to disable TDLS");
5877 return 0;
5878 }
5879 } else if (strcasecmp(val, "Enabled") == 0) {
5880 if (wpa_command(intf, "SET tdls_disabled 0")) {
5881 send_resp(dut, conn, SIGMA_ERROR,
5882 "ErrorCode,Failed to enable TDLS");
5883 return 0;
5884 }
5885 } else {
5886 send_resp(dut, conn, SIGMA_ERROR,
5887 "ErrorCode,Unsupported TDLS value");
5888 return 0;
5889 }
5890 }
5891
5892 val = get_param(cmd, "TDLSmode");
5893 if (val) {
5894 if (strcasecmp(val, "Default") == 0) {
5895 wpa_command(intf, "SET tdls_testing 0");
5896 } else if (strcasecmp(val, "APProhibit") == 0) {
5897 if (wpa_command(intf, "SET tdls_testing 0x400")) {
5898 send_resp(dut, conn, SIGMA_ERROR,
5899 "ErrorCode,Failed to enable ignore "
5900 "APProhibit TDLS mode");
5901 return 0;
5902 }
5903 } else if (strcasecmp(val, "HiLoMac") == 0) {
5904 /* STA should respond with TDLS setup req for a TDLS
5905 * setup req */
5906 if (wpa_command(intf, "SET tdls_testing 0x80")) {
5907 send_resp(dut, conn, SIGMA_ERROR,
5908 "ErrorCode,Failed to enable HiLoMac "
5909 "TDLS mode");
5910 return 0;
5911 }
5912 } else if (strcasecmp(val, "WeakSecurity") == 0) {
5913 /*
5914 * Since all security modes are enabled by default when
5915 * Sigma control is used, there is no need to do
5916 * anything here.
5917 */
5918 } else if (strcasecmp(val, "ExistLink") == 0) {
5919 /*
5920 * Since we allow new TDLS Setup Request even if there
5921 * is an existing link, nothing needs to be done for
5922 * this.
5923 */
5924 } else {
5925 /* TODO:
5926 * ExistLink: STA should send TDLS setup req even if
5927 * direct link already exists
5928 */
5929 send_resp(dut, conn, SIGMA_ERROR,
5930 "ErrorCode,Unsupported TDLSmode value");
5931 return 0;
5932 }
5933 }
5934
5935 val = get_param(cmd, "FakePubKey");
5936 if (val && atoi(val) && wpa_command(intf, "SET wps_corrupt_pkhash 1")) {
5937 send_resp(dut, conn, SIGMA_ERROR,
5938 "ErrorCode,Failed to enable FakePubKey");
5939 return 0;
5940 }
5941
Amarnath Hullur Subramanyamae1042b2018-02-22 21:52:52 -08005942#ifdef NL80211_SUPPORT
5943 val = get_param(cmd, "FrgmntSupport");
5944 if (val) {
5945 if (strcasecmp(val, "Enable") == 0) {
5946 if (sta_set_he_fragmentation(dut, intf,
5947 HE_FRAG_LEVEL1)) {
5948 send_resp(dut, conn, SIGMA_ERROR,
5949 "ErrorCode,Failed to enable HE Fragmentation");
5950 return 0;
5951 }
5952 } else if (strcasecmp(val, "Disable") == 0) {
5953 if (sta_set_he_fragmentation(dut, intf,
5954 HE_FRAG_DISABLE)) {
5955 send_resp(dut, conn, SIGMA_ERROR,
5956 "ErrorCode,Failed to disable HE Fragmentation");
5957 return 0;
5958 }
5959 }
5960 }
5961#endif /* NL80211_SUPPORT */
5962
Vinita S. Maloo8a4779c2020-06-22 19:32:37 +05305963 val = get_param(cmd, "IncludeMSCSDescriptor");
5964 if (val && strcasecmp(val, "1") == 0) {
5965 char buf[128];
5966 int len;
5967
5968 len = snprintf(buf, sizeof(buf),
Veerendranath Jakkam62cde372020-08-19 18:03:06 +05305969 "MSCS add up_bitmap=F0 up_limit=7 stream_timeout=60000 frame_classifier=045F%032x",
Vinita S. Maloo8a4779c2020-06-22 19:32:37 +05305970 0);
5971
5972 if (len < 0 || len >= sizeof(buf)) {
5973 sigma_dut_print(dut, DUT_MSG_ERROR,
5974 "Failed to build MSCS Descriptor IE");
5975 return ERROR_SEND_STATUS;
5976 }
5977
5978 if (wpa_command(intf, buf) != 0) {
5979 send_resp(dut, conn, SIGMA_ERROR,
5980 "ErrorCode,Failed to include MSCS descriptor");
5981 return STATUS_SENT_ERROR;
5982 }
5983 }
5984
Vinita S. Maloo2287f142021-02-01 16:17:09 +05305985 val = get_param(cmd, "SCSSupport");
5986 if (val) {
5987 char buf[30];
5988 int disable_scs, len;
5989
5990 if (strcasecmp(val, "Enable") == 0) {
5991 disable_scs = 0;
5992 } else if (strcasecmp(val, "Disable") == 0) {
5993 disable_scs = 1;
5994 } else {
5995 sigma_dut_print(dut, DUT_MSG_ERROR,
5996 "Invalid SCSsupport parameter");
5997 return INVALID_SEND_STATUS;
5998 }
5999
Shivani Baranwalebde8f62021-10-19 12:26:02 +05306000 if (disable_scs || dut->prev_disable_scs_support) {
6001 len = snprintf(buf, sizeof(buf),
6002 "SET disable_scs_support %d",
6003 disable_scs);
6004 if (len < 0 || len >= sizeof(buf) ||
6005 wpa_command(intf, buf) != 0) {
6006 send_resp(dut, conn, SIGMA_ERROR,
6007 "ErrorCode,Failed to update SCS support");
6008 return STATUS_SENT_ERROR;
6009 }
6010 dut->prev_disable_scs_support = disable_scs;
Vinita S. Maloo2287f142021-02-01 16:17:09 +05306011 }
6012 }
6013
Vinita S. Maloo83dee552021-04-12 16:47:47 +05306014 val = get_param(cmd, "MSCSSupport");
6015 if (val) {
6016 char buf[30];
6017 int disable_mscs, len;
6018
6019 if (strcasecmp(val, "Enable") == 0) {
6020 disable_mscs = 0;
6021 } else if (strcasecmp(val, "Disable") == 0) {
6022 disable_mscs = 1;
6023 } else {
6024 sigma_dut_print(dut, DUT_MSG_ERROR,
6025 "Invalid MSCSsupport parameter");
6026 return INVALID_SEND_STATUS;
6027 }
6028
Shivani Baranwalebde8f62021-10-19 12:26:02 +05306029 if (disable_mscs || dut->prev_disable_mscs_support) {
6030 len = snprintf(buf, sizeof(buf),
6031 "SET disable_mscs_support %d",
6032 disable_mscs);
6033 if (len < 0 || len >= sizeof(buf) ||
6034 wpa_command(intf, buf) != 0) {
6035 send_resp(dut, conn, SIGMA_ERROR,
6036 "ErrorCode,Failed to update MSCS support");
6037 return STATUS_SENT_ERROR;
6038 }
6039 dut->prev_disable_mscs_support = disable_mscs;
Vinita S. Maloo83dee552021-04-12 16:47:47 +05306040 }
6041 }
6042
Veerendranath Jakkama16cdc82021-09-12 16:44:22 +05306043 val = get_param(cmd, "DSCPPolicyCapability");
6044 if (val) {
6045 char buf[35];
6046 int len;
6047
6048 if (strcasecmp(val, "Enable") == 0) {
6049 len = snprintf(buf, sizeof(buf),
6050 "SET enable_dscp_policy_capa 1");
6051 } else if (strcasecmp(val, "Disable") == 0) {
6052 len = snprintf(buf, sizeof(buf),
6053 "SET enable_dscp_policy_capa 0");
6054 } else {
6055 sigma_dut_print(dut, DUT_MSG_ERROR,
6056 "Invalid DSCP policy parameter");
6057 return INVALID_SEND_STATUS;
6058 }
6059
6060 if (len < 0 || len >= sizeof(buf) ||
6061 wpa_command(intf, buf) != 0) {
6062 send_resp(dut, conn, SIGMA_ERROR,
6063 "ErrorCode,Failed to update DSCP policy capability");
6064 return STATUS_SENT_ERROR;
6065 }
6066 }
6067
6068 val = get_param(cmd, "DSCPPolicyRespParams");
6069 if (val) {
6070 if (strcasecmp(val, "RejectAll") == 0) {
6071 dut->reject_dscp_policies = 1;
6072 dut->dscp_reject_resp_code = DSCP_POLICY_REJECT;
6073 } else if (strcasecmp(val, "AcceptAll") == 0) {
6074 dut->reject_dscp_policies = 0;
6075 }
6076 }
6077
6078 val = get_param(cmd, "DSCPPolicyResp_StatusCode");
6079 if (val)
6080 dut->dscp_reject_resp_code = atoi(val);
6081
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006082 return 1;
6083}
6084
6085
6086static const char * ath_get_radio_name(const char *radio_name)
6087{
6088 if (radio_name == NULL)
6089 return "wifi0";
6090 if (strcmp(radio_name, "wifi1") == 0)
6091 return "wifi1";
6092 if (strcmp(radio_name, "wifi2") == 0)
6093 return "wifi2";
6094 return "wifi0";
6095}
6096
6097
6098static void ath_sta_set_txsp_stream(struct sigma_dut *dut, const char *intf,
6099 const char *val)
6100{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006101 unsigned int vht_mcsmap = 0;
6102 int txchainmask = 0;
6103 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
6104
6105 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
6106 if (dut->testbed_flag_txsp == 1) {
6107 vht_mcsmap = 0xfffc;
6108 dut->testbed_flag_txsp = 0;
6109 } else {
6110 vht_mcsmap = 0xfffe;
6111 }
6112 txchainmask = 1;
6113 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
6114 if (dut->testbed_flag_txsp == 1) {
6115 vht_mcsmap = 0xfff0;
6116 dut->testbed_flag_txsp = 0;
6117 } else {
6118 vht_mcsmap = 0xfffa;
6119 }
6120 txchainmask = 3;
6121 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
6122 if (dut->testbed_flag_txsp == 1) {
6123 vht_mcsmap = 0xffc0;
6124 dut->testbed_flag_txsp = 0;
6125 } else {
6126 vht_mcsmap = 0xffea;
6127 }
6128 txchainmask = 7;
6129 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
6130 if (dut->testbed_flag_txsp == 1) {
6131 vht_mcsmap = 0xff00;
6132 dut->testbed_flag_txsp = 0;
6133 } else {
6134 vht_mcsmap = 0xffaa;
6135 }
6136 txchainmask = 15;
6137 } else {
6138 if (dut->testbed_flag_txsp == 1) {
6139 vht_mcsmap = 0xffc0;
6140 dut->testbed_flag_txsp = 0;
6141 } else {
6142 vht_mcsmap = 0xffea;
6143 }
6144 }
6145
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006146 if (txchainmask)
6147 run_iwpriv(dut, basedev, "txchainmask %d", txchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006148
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006149 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006150}
6151
6152
6153static void ath_sta_set_rxsp_stream(struct sigma_dut *dut, const char *intf,
6154 const char *val)
6155{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006156 unsigned int vht_mcsmap = 0;
6157 int rxchainmask = 0;
6158 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
6159
6160 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
6161 if (dut->testbed_flag_rxsp == 1) {
6162 vht_mcsmap = 0xfffc;
6163 dut->testbed_flag_rxsp = 0;
6164 } else {
6165 vht_mcsmap = 0xfffe;
6166 }
6167 rxchainmask = 1;
6168 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
6169 if (dut->testbed_flag_rxsp == 1) {
6170 vht_mcsmap = 0xfff0;
6171 dut->testbed_flag_rxsp = 0;
6172 } else {
6173 vht_mcsmap = 0xfffa;
6174 }
6175 rxchainmask = 3;
6176 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
6177 if (dut->testbed_flag_rxsp == 1) {
6178 vht_mcsmap = 0xffc0;
6179 dut->testbed_flag_rxsp = 0;
6180 } else {
6181 vht_mcsmap = 0xffea;
6182 }
6183 rxchainmask = 7;
6184 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
6185 if (dut->testbed_flag_rxsp == 1) {
6186 vht_mcsmap = 0xff00;
6187 dut->testbed_flag_rxsp = 0;
6188 } else {
6189 vht_mcsmap = 0xffaa;
6190 }
6191 rxchainmask = 15;
6192 } else {
6193 if (dut->testbed_flag_rxsp == 1) {
6194 vht_mcsmap = 0xffc0;
6195 dut->testbed_flag_rxsp = 0;
6196 } else {
6197 vht_mcsmap = 0xffea;
6198 }
6199 }
6200
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006201 if (rxchainmask)
6202 run_iwpriv(dut, basedev, "rxchainmask %d", rxchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006203
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006204 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006205}
6206
6207
6208void ath_set_zero_crc(struct sigma_dut *dut, const char *val)
6209{
6210 if (strcasecmp(val, "enable") == 0) {
6211 if (system("athdiag --set --address=0x2a204 --and=0xbfffffff")
6212 != 0) {
6213 sigma_dut_print(dut, DUT_MSG_ERROR,
6214 "Disable BB_VHTSIGB_CRC_CALC failed");
6215 }
6216
6217 if (system("athdiag --set --address=0x2a204 --or=0x80000000")
6218 != 0) {
6219 sigma_dut_print(dut, DUT_MSG_ERROR,
6220 "Enable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
6221 }
6222 } else {
6223 if (system("athdiag --set --address=0x2a204 --and=0x7fffffff")
6224 != 0) {
6225 sigma_dut_print(dut, DUT_MSG_ERROR,
6226 "Disable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
6227 }
6228
6229 if (system("athdiag --set --address=0x2a204 --or=0x40000000")
6230 != 0) {
6231 sigma_dut_print(dut, DUT_MSG_ERROR,
6232 "Enable BB_VHTSIGB_CRC_CALC failed");
6233 }
6234 }
6235}
6236
6237
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08006238static int wcn_sta_set_width(struct sigma_dut *dut, const char *intf,
6239 const char *val)
6240{
6241 char buf[60];
6242
Shivani Baranwal2a572842021-09-16 12:27:15 +05306243#ifdef NL80211_SUPPORT
6244 enum nl80211_chan_width qca_channel_width;
6245
6246 if (strcmp(val, "20") == 0) {
6247 qca_channel_width = NL80211_CHAN_WIDTH_20;
6248 dut->chwidth = 0;
6249 } else if (strcmp(val, "40") == 0) {
6250 qca_channel_width = NL80211_CHAN_WIDTH_40;
6251 dut->chwidth = 1;
6252 } else if (strcmp(val, "80") == 0) {
6253 qca_channel_width = NL80211_CHAN_WIDTH_80;
6254 dut->chwidth = 2;
6255 } else if (strcmp(val, "160") == 0) {
6256 qca_channel_width = NL80211_CHAN_WIDTH_160;
6257 dut->chwidth = 3;
6258 } else if (strcasecmp(val, "Auto") == 0) {
6259 return 0;
6260 } else {
6261 sigma_dut_print(dut, DUT_MSG_ERROR, "WIDTH %s not supported",
6262 val);
6263 return -1;
6264 }
6265 if (sta_config_params(dut, intf, STA_SET_CHAN_WIDTH,
6266 qca_channel_width) == 0)
6267 return 0;
6268#endif /* NL80211_SUPPORT */
6269
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08006270 if (strcmp(val, "20") == 0) {
6271 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
6272 dut->chwidth = 0;
6273 } else if (strcmp(val, "40") == 0) {
6274 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 1", intf);
6275 dut->chwidth = 1;
6276 } else if (strcmp(val, "80") == 0) {
6277 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
6278 dut->chwidth = 2;
Sunil Duttb1cccac2018-05-22 21:03:12 +05306279 } else if (strcasecmp(val, "Auto") == 0) {
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08006280 buf[0] = '\0';
6281 } else {
6282 sigma_dut_print(dut, DUT_MSG_ERROR, "WIDTH %s not supported",
6283 val);
6284 return -1;
6285 }
6286
6287 if (buf[0] != '\0' && system(buf) != 0) {
6288 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv chwidth failed");
6289 return -1;
6290 }
6291
6292 return 0;
6293}
6294
6295
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08006296static int nlvendor_sta_set_addba_reject(struct sigma_dut *dut,
6297 const char *intf, int addbareject)
6298{
6299#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05306300 return wcn_wifi_test_config_set_u8(
6301 dut, intf,
6302 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ACCEPT_ADDBA_REQ,
6303 !addbareject);
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08006304#else /* NL80211_SUPPORT */
6305 sigma_dut_print(dut, DUT_MSG_ERROR,
6306 "ADDBA_REJECT cannot be set without NL80211_SUPPORT defined");
6307 return -1;
6308#endif /* NL80211_SUPPORT */
6309}
6310
6311
6312static int sta_set_addba_reject(struct sigma_dut *dut, const char *intf,
6313 int addbareject)
6314{
6315 int ret;
6316
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006317 switch (get_driver_type(dut)) {
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08006318 case DRIVER_WCN:
6319 ret = nlvendor_sta_set_addba_reject(dut, intf, addbareject);
6320 if (ret) {
6321 sigma_dut_print(dut, DUT_MSG_ERROR,
6322 "nlvendor_sta_set_addba_reject failed, ret:%d",
6323 ret);
6324 return ret;
6325 }
6326 break;
6327 default:
6328 sigma_dut_print(dut, DUT_MSG_ERROR,
6329 "errorCode,Unsupported ADDBA_REJECT with the current driver");
6330 ret = -1;
6331 break;
6332 }
6333
6334 return ret;
6335}
6336
6337
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08006338static int nlvendor_config_send_addba(struct sigma_dut *dut, const char *intf,
6339 int enable)
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08006340{
6341#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05306342 return wcn_wifi_test_config_set_u8(
6343 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SEND_ADDBA_REQ,
6344 enable);
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08006345#else /* NL80211_SUPPORT */
6346 sigma_dut_print(dut, DUT_MSG_ERROR,
6347 "Disable addba not possible without NL80211_SUPPORT defined");
6348 return -1;
6349#endif /* NL80211_SUPPORT */
6350}
6351
6352
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05306353#ifdef NL80211_SUPPORT
6354static int nl80211_sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
6355{
6356 struct nl_msg *msg;
6357 int ret = 0;
6358 int ifindex;
6359
6360 ifindex = if_nametoindex(intf);
6361 if (ifindex == 0) {
6362 sigma_dut_print(dut, DUT_MSG_ERROR,
6363 "%s: Index for interface %s failed",
6364 __func__, intf);
6365 return -1;
6366 }
6367
6368 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6369 NL80211_CMD_SET_WIPHY)) ||
6370 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) {
6371 sigma_dut_print(dut, DUT_MSG_ERROR,
6372 "%s: err in adding RTS threshold",
6373 __func__);
6374 nlmsg_free(msg);
6375 return -1;
6376 }
6377
6378 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6379 if (ret) {
6380 sigma_dut_print(dut, DUT_MSG_ERROR,
6381 "%s: err in send_and_recv_msgs, ret=%d",
6382 __func__, ret);
6383 }
6384 return ret;
6385}
6386#endif /* NL80211_SUPPORT */
6387
6388
6389static int sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
6390{
6391 char buf[100];
6392
6393#ifdef NL80211_SUPPORT
6394 if (nl80211_sta_set_rts(dut, intf, val) == 0)
6395 return 0;
6396 sigma_dut_print(dut, DUT_MSG_DEBUG,
6397 "Fall back to using iwconfig for setting RTS threshold");
6398#endif /* NL80211_SUPPORT */
6399
6400 snprintf(buf, sizeof(buf), "iwconfig %s rts %d", intf, val);
6401 if (system(buf) != 0) {
6402 sigma_dut_print(dut, DUT_MSG_ERROR,
6403 "Failed to set RTS threshold %d", val);
6404 return -1;
6405 }
6406 return 0;
6407}
6408
6409
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006410static enum sigma_cmd_result
6411cmd_sta_set_wireless_common(const char *intf, struct sigma_dut *dut,
6412 struct sigma_conn *conn, struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006413{
6414 const char *val;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08006415 int ampdu = -1, addbareject = -1;
Jouni Malinen3aa72862019-05-29 23:14:51 +03006416 char buf[128];
6417 int res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006418
6419 val = get_param(cmd, "40_INTOLERANT");
6420 if (val) {
6421 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
6422 /* TODO: iwpriv ht40intol through wpa_supplicant */
6423 send_resp(dut, conn, SIGMA_ERROR,
6424 "ErrorCode,40_INTOLERANT not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006425 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006426 }
6427 }
6428
6429 val = get_param(cmd, "ADDBA_REJECT");
6430 if (val) {
6431 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
6432 /* reject any ADDBA with status "decline" */
6433 ampdu = 0;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08006434 addbareject = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006435 } else {
6436 /* accept ADDBA */
6437 ampdu = 1;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08006438 addbareject = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006439 }
6440 }
6441
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08006442 if (addbareject >= 0 &&
6443 sta_set_addba_reject(dut, intf, addbareject) < 0) {
6444 send_resp(dut, conn, SIGMA_ERROR,
6445 "ErrorCode,set addba_reject failed");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006446 return STATUS_SENT_ERROR;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08006447 }
6448
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006449 val = get_param(cmd, "AMPDU");
6450 if (val) {
6451 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
6452 /* enable AMPDU Aggregation */
6453 if (ampdu == 0) {
6454 send_resp(dut, conn, SIGMA_ERROR,
6455 "ErrorCode,Mismatch in "
6456 "addba_reject/ampdu - "
6457 "not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006458 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006459 }
6460 ampdu = 1;
6461 } else {
6462 /* disable AMPDU Aggregation */
6463 if (ampdu == 1) {
6464 send_resp(dut, conn, SIGMA_ERROR,
6465 "ErrorCode,Mismatch in "
6466 "addba_reject/ampdu - "
6467 "not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006468 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006469 }
6470 ampdu = 0;
6471 }
6472 }
6473
6474 if (ampdu >= 0) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08006475 int ret;
6476
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006477 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s A-MPDU aggregation",
6478 ampdu ? "Enabling" : "Disabling");
6479 snprintf(buf, sizeof(buf), "SET ampdu %d", ampdu);
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07006480 if (wpa_command(intf, buf) < 0 &&
6481 iwpriv_sta_set_ampdu(dut, intf, ampdu) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006482 send_resp(dut, conn, SIGMA_ERROR,
6483 "ErrorCode,set aggr failed");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006484 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006485 }
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08006486
6487 if (ampdu == 0) {
6488 /* Disable sending of addba using nl vendor command */
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08006489 ret = nlvendor_config_send_addba(dut, intf, 0);
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08006490 if (ret) {
6491 sigma_dut_print(dut, DUT_MSG_ERROR,
6492 "Failed to disable addba, ret:%d",
6493 ret);
6494 }
6495 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006496 }
6497
6498 val = get_param(cmd, "AMSDU");
6499 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006500 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006501 case DRIVER_ATHEROS:
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08006502 case DRIVER_WCN:
6503 iwpriv_sta_set_amsdu(dut, intf, val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006504 break;
6505 default:
6506 if (strcmp(val, "1") == 0 ||
6507 strcasecmp(val, "Enable") == 0) {
6508 /* Enable AMSDU Aggregation */
6509 send_resp(dut, conn, SIGMA_ERROR,
6510 "ErrorCode,AMSDU aggregation not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006511 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006512 }
6513 break;
6514 }
6515 }
6516
6517 val = get_param(cmd, "STBC_RX");
6518 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006519 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006520 case DRIVER_ATHEROS:
6521 ath_sta_set_stbc(dut, intf, val);
6522 break;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05306523 case DRIVER_WCN:
6524 wcn_sta_set_stbc(dut, intf, val);
6525 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006526 default:
6527 send_resp(dut, conn, SIGMA_ERROR,
6528 "ErrorCode,STBC_RX not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006529 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006530 }
6531 }
6532
6533 val = get_param(cmd, "WIDTH");
6534 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006535 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006536 case DRIVER_WCN:
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08006537 if (wcn_sta_set_width(dut, intf, val) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006538 send_resp(dut, conn, SIGMA_ERROR,
6539 "ErrorCode,Failed to set WIDTH");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006540 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006541 }
6542 break;
6543 case DRIVER_ATHEROS:
6544 if (ath_set_width(dut, conn, intf, val) < 0)
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006545 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006546 break;
6547 default:
6548 sigma_dut_print(dut, DUT_MSG_ERROR,
6549 "Setting WIDTH not supported");
6550 break;
6551 }
6552 }
6553
6554 val = get_param(cmd, "SMPS");
6555 if (val) {
6556 /* TODO: Dynamic/0, Static/1, No Limit/2 */
6557 send_resp(dut, conn, SIGMA_ERROR,
6558 "ErrorCode,SMPS not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006559 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006560 }
6561
6562 val = get_param(cmd, "TXSP_STREAM");
6563 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006564 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006565 case DRIVER_WCN:
6566 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
6567 send_resp(dut, conn, SIGMA_ERROR,
6568 "ErrorCode,Failed to set TXSP_STREAM");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006569 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006570 }
6571 break;
6572 case DRIVER_ATHEROS:
6573 ath_sta_set_txsp_stream(dut, intf, val);
6574 break;
6575 default:
6576 sigma_dut_print(dut, DUT_MSG_ERROR,
6577 "Setting TXSP_STREAM not supported");
6578 break;
6579 }
6580 }
6581
6582 val = get_param(cmd, "RXSP_STREAM");
6583 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006584 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006585 case DRIVER_WCN:
6586 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
6587 send_resp(dut, conn, SIGMA_ERROR,
6588 "ErrorCode,Failed to set RXSP_STREAM");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006589 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006590 }
6591 break;
6592 case DRIVER_ATHEROS:
6593 ath_sta_set_rxsp_stream(dut, intf, val);
6594 break;
6595 default:
6596 sigma_dut_print(dut, DUT_MSG_ERROR,
6597 "Setting RXSP_STREAM not supported");
6598 break;
6599 }
6600 }
6601
6602 val = get_param(cmd, "DYN_BW_SGNL");
6603 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006604 switch (get_driver_type(dut)) {
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08006605 case DRIVER_WCN:
Peng Xuc59afd32016-11-21 15:01:11 -08006606 if (strcasecmp(val, "enable") == 0) {
6607 snprintf(buf, sizeof(buf),
6608 "iwpriv %s cwmenable 1", intf);
6609 if (system(buf) != 0) {
6610 sigma_dut_print(dut, DUT_MSG_ERROR,
6611 "iwpriv cwmenable 1 failed");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006612 return ERROR_SEND_STATUS;
Peng Xuc59afd32016-11-21 15:01:11 -08006613 }
6614 } else if (strcasecmp(val, "disable") == 0) {
6615 snprintf(buf, sizeof(buf),
6616 "iwpriv %s cwmenable 0", intf);
6617 if (system(buf) != 0) {
6618 sigma_dut_print(dut, DUT_MSG_ERROR,
6619 "iwpriv cwmenable 0 failed");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006620 return ERROR_SEND_STATUS;
Peng Xuc59afd32016-11-21 15:01:11 -08006621 }
6622 } else {
6623 sigma_dut_print(dut, DUT_MSG_ERROR,
6624 "Unsupported DYN_BW_SGL");
6625 }
6626
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006627 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
6628 if (system(buf) != 0) {
6629 sigma_dut_print(dut, DUT_MSG_ERROR,
6630 "Failed to set cts_cbw in DYN_BW_SGNL");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006631 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006632 }
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08006633 break;
6634 case DRIVER_ATHEROS:
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07006635 novap_reset(dut, intf, 1);
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08006636 ath_config_dyn_bw_sig(dut, intf, val);
6637 break;
6638 default:
6639 sigma_dut_print(dut, DUT_MSG_ERROR,
6640 "Failed to set DYN_BW_SGNL");
6641 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006642 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006643 }
6644
6645 val = get_param(cmd, "RTS_FORCE");
6646 if (val) {
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07006647 novap_reset(dut, intf, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006648 if (strcasecmp(val, "Enable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05306649 if (sta_set_rts(dut, intf, 64) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02006650 sigma_dut_print(dut, DUT_MSG_ERROR,
6651 "Failed to set RTS_FORCE 64");
6652 }
Jouni Malinen3aa72862019-05-29 23:14:51 +03006653 res = snprintf(buf, sizeof(buf),
6654 "wifitool %s beeliner_fw_test 100 1",
6655 intf);
6656 if (res < 0 || res >= sizeof(buf) || system(buf) != 0) {
priyadharshini gowthaman270870e2015-12-09 10:10:23 -08006657 sigma_dut_print(dut, DUT_MSG_ERROR,
6658 "wifitool beeliner_fw_test 100 1 failed");
6659 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006660 } else if (strcasecmp(val, "Disable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05306661 if (sta_set_rts(dut, intf, 2347) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02006662 sigma_dut_print(dut, DUT_MSG_ERROR,
6663 "Failed to set RTS_FORCE 2347");
6664 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006665 } else {
6666 send_resp(dut, conn, SIGMA_ERROR,
6667 "ErrorCode,RTS_FORCE value not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006668 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006669 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006670 }
6671
6672 val = get_param(cmd, "CTS_WIDTH");
6673 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006674 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006675 case DRIVER_WCN:
6676 if (wcn_sta_set_cts_width(dut, intf, val) < 0) {
6677 send_resp(dut, conn, SIGMA_ERROR,
6678 "ErrorCode,Failed to set CTS_WIDTH");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006679 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006680 }
6681 break;
6682 case DRIVER_ATHEROS:
6683 ath_set_cts_width(dut, intf, val);
6684 break;
6685 default:
6686 sigma_dut_print(dut, DUT_MSG_ERROR,
6687 "Setting CTS_WIDTH not supported");
6688 break;
6689 }
6690 }
6691
6692 val = get_param(cmd, "BW_SGNL");
6693 if (val) {
6694 if (strcasecmp(val, "Enable") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006695 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006696 } else if (strcasecmp(val, "Disable") == 0) {
6697 /* TODO: Disable */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006698 } else {
6699 send_resp(dut, conn, SIGMA_ERROR,
6700 "ErrorCode,BW_SGNL value not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006701 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006702 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006703 }
6704
6705 val = get_param(cmd, "Band");
6706 if (val) {
6707 if (strcmp(val, "2.4") == 0 || strcmp(val, "5") == 0) {
6708 /* STA supports all bands by default */
6709 } else {
6710 send_resp(dut, conn, SIGMA_ERROR,
6711 "ErrorCode,Unsupported Band");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006712 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006713 }
6714 }
6715
6716 val = get_param(cmd, "zero_crc");
6717 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006718 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006719 case DRIVER_ATHEROS:
6720 ath_set_zero_crc(dut, val);
6721 break;
6722 default:
6723 break;
6724 }
6725 }
6726
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006727 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006728}
6729
6730
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006731static int sta_set_force_mcs(struct sigma_dut *dut, int force, int mcs)
6732{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006733 switch (get_driver_type(dut)) {
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006734#ifdef __linux__
6735 case DRIVER_WIL6210:
6736 return wil6210_set_force_mcs(dut, force, mcs);
6737#endif /* __linux__ */
6738 default:
6739 sigma_dut_print(dut, DUT_MSG_ERROR,
6740 "Unsupported sta_set_force_mcs with the current driver");
6741 return -1;
6742 }
6743}
6744
6745
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02006746static int sta_60g_force_rsn_ie(struct sigma_dut *dut, int state)
6747{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006748 switch (get_driver_type(dut)) {
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02006749#ifdef __linux__
6750 case DRIVER_WIL6210:
6751 return wil6210_force_rsn_ie(dut, state);
6752#endif /* __linux__ */
6753 default:
6754 sigma_dut_print(dut, DUT_MSG_ERROR,
6755 "Unsupported sta_60g_force_rsn_ie with the current driver");
6756 return -1;
6757 }
6758}
6759
6760
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006761static int sta_set_60g_common(struct sigma_dut *dut, struct sigma_conn *conn,
6762 struct sigma_cmd *cmd)
6763{
6764 const char *val;
6765 char buf[100];
6766
6767 val = get_param(cmd, "MSDUSize");
6768 if (val) {
6769 int mtu;
6770
6771 dut->amsdu_size = atoi(val);
6772 if (dut->amsdu_size > IEEE80211_MAX_DATA_LEN_DMG ||
6773 dut->amsdu_size < IEEE80211_SNAP_LEN_DMG) {
6774 sigma_dut_print(dut, DUT_MSG_ERROR,
6775 "MSDUSize %d is above max %d or below min %d",
6776 dut->amsdu_size,
6777 IEEE80211_MAX_DATA_LEN_DMG,
6778 IEEE80211_SNAP_LEN_DMG);
6779 dut->amsdu_size = 0;
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006780 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006781 }
6782
6783 mtu = dut->amsdu_size - IEEE80211_SNAP_LEN_DMG;
6784 sigma_dut_print(dut, DUT_MSG_DEBUG,
6785 "Setting amsdu_size to %d", mtu);
6786 snprintf(buf, sizeof(buf), "ifconfig %s mtu %d",
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006787 get_station_ifname(dut), mtu);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006788
6789 if (system(buf) != 0) {
6790 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
6791 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006792 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006793 }
6794 }
6795
6796 val = get_param(cmd, "BAckRcvBuf");
6797 if (val) {
6798 dut->back_rcv_buf = atoi(val);
6799 if (dut->back_rcv_buf == 0) {
6800 sigma_dut_print(dut, DUT_MSG_ERROR,
6801 "Failed to convert %s or value is 0",
6802 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006803 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006804 }
6805
6806 sigma_dut_print(dut, DUT_MSG_DEBUG,
6807 "Setting BAckRcvBuf to %s", val);
6808 }
6809
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006810 val = get_param(cmd, "MCS_FixedRate");
6811 if (val) {
6812 if (sta_set_force_mcs(dut, 1, atoi(val))) {
6813 sigma_dut_print(dut, DUT_MSG_ERROR,
6814 "Failed to force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006815 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006816 }
6817 }
6818
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006819 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006820}
6821
6822
6823static int sta_pcp_start(struct sigma_dut *dut, struct sigma_conn *conn,
6824 struct sigma_cmd *cmd)
6825{
6826 int net_id;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006827 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006828 const char *val;
6829 char buf[100];
6830
6831 dut->mode = SIGMA_MODE_STATION;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006832 ifname = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006833 if (wpa_command(ifname, "PING") != 0) {
6834 sigma_dut_print(dut, DUT_MSG_ERROR, "Supplicant not running");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006835 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006836 }
6837
6838 wpa_command(ifname, "FLUSH");
6839 net_id = add_network_common(dut, conn, ifname, cmd);
6840 if (net_id < 0) {
6841 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add network");
6842 return net_id;
6843 }
6844
6845 /* TODO: mode=2 for the AP; in the future, replace for mode PCP */
6846 if (set_network(ifname, net_id, "mode", "2") < 0) {
6847 sigma_dut_print(dut, DUT_MSG_ERROR,
6848 "Failed to set supplicant network mode");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006849 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006850 }
6851
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02006852 if (set_network(ifname, net_id, "pbss", "1") < 0)
6853 return -2;
6854
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006855 sigma_dut_print(dut, DUT_MSG_DEBUG,
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02006856 "Supplicant set network with mode 2. network_id %d",
6857 net_id);
6858
6859 if (set_network(ifname, net_id, "wps_disabled", "0") < 0) {
6860 sigma_dut_print(dut, DUT_MSG_INFO,
6861 "Failed to set supplicant to WPS ENABLE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006862 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02006863 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006864
6865 val = get_param(cmd, "Security");
6866 if (val && strcasecmp(val, "OPEN") == 0) {
6867 dut->ap_key_mgmt = AP_OPEN;
6868 if (set_network(ifname, net_id, "key_mgmt", "NONE") < 0) {
6869 sigma_dut_print(dut, DUT_MSG_ERROR,
6870 "Failed to set supplicant to %s security",
6871 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006872 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006873 }
6874 } else if (val && strcasecmp(val, "WPA2-PSK") == 0) {
6875 dut->ap_key_mgmt = AP_WPA2_PSK;
6876 if (set_network(ifname, net_id, "key_mgmt", "WPA-PSK") < 0) {
6877 sigma_dut_print(dut, DUT_MSG_ERROR,
6878 "Failed to set supplicant to %s security",
6879 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006880 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006881 }
6882
6883 if (set_network(ifname, net_id, "proto", "RSN") < 0) {
6884 sigma_dut_print(dut, DUT_MSG_ERROR,
6885 "Failed to set supplicant to proto RSN");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006886 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006887 }
6888 } else if (val) {
6889 sigma_dut_print(dut, DUT_MSG_ERROR,
6890 "Requested Security %s is not supported on 60GHz",
6891 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006892 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006893 }
6894
6895 val = get_param(cmd, "Encrypt");
6896 if (val && strcasecmp(val, "AES-GCMP") == 0) {
6897 if (set_network(ifname, net_id, "pairwise", "GCMP") < 0) {
6898 sigma_dut_print(dut, DUT_MSG_ERROR,
6899 "Failed to set supplicant to pairwise GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006900 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006901 }
6902 if (set_network(ifname, net_id, "group", "GCMP") < 0) {
6903 sigma_dut_print(dut, DUT_MSG_ERROR,
6904 "Failed to set supplicant to group GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006905 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006906 }
6907 } else if (val) {
6908 sigma_dut_print(dut, DUT_MSG_ERROR,
6909 "Requested Encrypt %s is not supported on 60 GHz",
6910 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006911 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006912 }
6913
6914 val = get_param(cmd, "PSK");
6915 if (val && set_network_quoted(ifname, net_id, "psk", val) < 0) {
6916 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set psk %s",
6917 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006918 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006919 }
6920
6921 /* Convert 60G channel to freq */
6922 switch (dut->ap_channel) {
6923 case 1:
6924 val = "58320";
6925 break;
6926 case 2:
6927 val = "60480";
6928 break;
6929 case 3:
6930 val = "62640";
6931 break;
6932 default:
6933 sigma_dut_print(dut, DUT_MSG_ERROR,
6934 "Failed to configure channel %d. Not supported",
6935 dut->ap_channel);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006936 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006937 }
6938
6939 if (set_network(ifname, net_id, "frequency", val) < 0) {
6940 sigma_dut_print(dut, DUT_MSG_ERROR,
6941 "Failed to set supplicant network frequency");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006942 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006943 }
6944
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02006945 if (dut->eap_fragment) {
6946 sigma_dut_print(dut, DUT_MSG_DEBUG,
6947 "Set EAP fragment size to 128 bytes.");
6948 if (set_network(ifname, net_id, "fragment_size", "128") < 0)
6949 return ERROR_SEND_STATUS;
6950 }
6951
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006952 sigma_dut_print(dut, DUT_MSG_DEBUG,
6953 "Supplicant set network with frequency");
6954
6955 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d", net_id);
6956 if (wpa_command(ifname, buf) < 0) {
6957 sigma_dut_print(dut, DUT_MSG_INFO,
6958 "Failed to select network id %d on %s",
6959 net_id, ifname);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006960 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006961 }
6962
6963 sigma_dut_print(dut, DUT_MSG_DEBUG, "Selected network");
6964
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006965 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006966}
6967
6968
Lior David67543f52017-01-03 19:04:22 +02006969static int wil6210_set_abft_len(struct sigma_dut *dut, int abft_len)
6970{
6971 char buf[128], fname[128];
6972 FILE *f;
Jouni Malinen3aa72862019-05-29 23:14:51 +03006973 int res;
Lior David67543f52017-01-03 19:04:22 +02006974
6975 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
6976 sigma_dut_print(dut, DUT_MSG_ERROR,
6977 "failed to get wil6210 debugfs dir");
6978 return -1;
6979 }
6980
Jouni Malinen3aa72862019-05-29 23:14:51 +03006981 res = snprintf(fname, sizeof(fname), "%s/abft_len", buf);
6982 if (res < 0 || res >= sizeof(fname))
6983 return -1;
Lior David67543f52017-01-03 19:04:22 +02006984 f = fopen(fname, "w");
6985 if (!f) {
6986 sigma_dut_print(dut, DUT_MSG_ERROR,
6987 "failed to open: %s", fname);
6988 return -1;
6989 }
6990
6991 fprintf(f, "%d\n", abft_len);
6992 fclose(f);
6993
6994 return 0;
6995}
6996
6997
Alexei Avshalom Lazar49498b82019-01-31 15:16:32 +02006998int sta_set_60g_abft_len(struct sigma_dut *dut, struct sigma_conn *conn,
6999 int abft_len)
Lior David67543f52017-01-03 19:04:22 +02007000{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007001 switch (get_driver_type(dut)) {
Lior David67543f52017-01-03 19:04:22 +02007002 case DRIVER_WIL6210:
7003 return wil6210_set_abft_len(dut, abft_len);
7004 default:
7005 sigma_dut_print(dut, DUT_MSG_ERROR,
7006 "set abft_len not supported");
7007 return -1;
7008 }
7009}
7010
7011
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007012static int sta_set_60g_pcp(struct sigma_dut *dut, struct sigma_conn *conn,
7013 struct sigma_cmd *cmd)
7014{
7015 const char *val;
Lior David67543f52017-01-03 19:04:22 +02007016 unsigned int abft_len = 1; /* default is one slot */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007017
7018 if (dut->dev_role != DEVROLE_PCP) {
7019 send_resp(dut, conn, SIGMA_INVALID,
7020 "ErrorCode,Invalid DevRole");
7021 return 0;
7022 }
7023
7024 val = get_param(cmd, "SSID");
7025 if (val) {
7026 if (strlen(val) > sizeof(dut->ap_ssid) - 1) {
7027 send_resp(dut, conn, SIGMA_INVALID,
7028 "ErrorCode,Invalid SSID");
7029 return -1;
7030 }
7031
Peng Xub8fc5cc2017-05-10 17:27:28 -07007032 strlcpy(dut->ap_ssid, val, sizeof(dut->ap_ssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007033 }
7034
7035 val = get_param(cmd, "CHANNEL");
7036 if (val) {
7037 const char *pos;
7038
7039 dut->ap_channel = atoi(val);
7040 pos = strchr(val, ';');
7041 if (pos) {
7042 pos++;
7043 dut->ap_channel_1 = atoi(pos);
7044 }
7045 }
7046
7047 switch (dut->ap_channel) {
7048 case 1:
7049 case 2:
7050 case 3:
7051 break;
7052 default:
7053 sigma_dut_print(dut, DUT_MSG_ERROR,
7054 "Channel %d is not supported", dut->ap_channel);
7055 send_resp(dut, conn, SIGMA_ERROR,
7056 "Requested channel is not supported");
7057 return -1;
7058 }
7059
7060 val = get_param(cmd, "BCNINT");
7061 if (val)
7062 dut->ap_bcnint = atoi(val);
7063
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007064 val = get_param(cmd, "AllocType");
7065 if (val) {
7066 send_resp(dut, conn, SIGMA_ERROR,
7067 "ErrorCode,AllocType is not supported yet");
7068 return -1;
7069 }
7070
7071 val = get_param(cmd, "PercentBI");
7072 if (val) {
7073 send_resp(dut, conn, SIGMA_ERROR,
7074 "ErrorCode,PercentBI is not supported yet");
7075 return -1;
7076 }
7077
7078 val = get_param(cmd, "CBAPOnly");
7079 if (val) {
7080 send_resp(dut, conn, SIGMA_ERROR,
7081 "ErrorCode,CBAPOnly is not supported yet");
7082 return -1;
7083 }
7084
7085 val = get_param(cmd, "AMPDU");
7086 if (val) {
7087 if (strcasecmp(val, "Enable") == 0)
7088 dut->ap_ampdu = 1;
7089 else if (strcasecmp(val, "Disable") == 0)
7090 dut->ap_ampdu = 2;
7091 else {
7092 send_resp(dut, conn, SIGMA_ERROR,
7093 "ErrorCode,AMPDU value is not Enable nor Disabled");
7094 return -1;
7095 }
7096 }
7097
7098 val = get_param(cmd, "AMSDU");
7099 if (val) {
7100 if (strcasecmp(val, "Enable") == 0)
7101 dut->ap_amsdu = 1;
7102 else if (strcasecmp(val, "Disable") == 0)
7103 dut->ap_amsdu = 2;
7104 }
7105
7106 val = get_param(cmd, "NumMSDU");
7107 if (val) {
7108 send_resp(dut, conn, SIGMA_ERROR,
7109 "ErrorCode, NumMSDU is not supported yet");
7110 return -1;
7111 }
7112
7113 val = get_param(cmd, "ABFTLRang");
7114 if (val) {
7115 sigma_dut_print(dut, DUT_MSG_DEBUG,
Lior David67543f52017-01-03 19:04:22 +02007116 "ABFTLRang parameter %s", val);
7117 if (strcmp(val, "Gt1") == 0)
7118 abft_len = 2; /* 2 slots in this case */
7119 }
7120
7121 if (sta_set_60g_abft_len(dut, conn, abft_len)) {
7122 send_resp(dut, conn, SIGMA_ERROR,
7123 "ErrorCode, Can't set ABFT length");
7124 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007125 }
7126
7127 if (sta_pcp_start(dut, conn, cmd) < 0) {
7128 send_resp(dut, conn, SIGMA_ERROR,
7129 "ErrorCode, Can't start PCP role");
7130 return -1;
7131 }
7132
7133 return sta_set_60g_common(dut, conn, cmd);
7134}
7135
7136
7137static int sta_set_60g_sta(struct sigma_dut *dut, struct sigma_conn *conn,
7138 struct sigma_cmd *cmd)
7139{
7140 const char *val = get_param(cmd, "DiscoveryMode");
7141
7142 if (dut->dev_role != DEVROLE_STA) {
7143 send_resp(dut, conn, SIGMA_INVALID,
7144 "ErrorCode,Invalid DevRole");
7145 return 0;
7146 }
7147
7148 if (val) {
7149 sigma_dut_print(dut, DUT_MSG_DEBUG, "Discovery: %s", val);
7150 /* Ignore Discovery mode till Driver expose API. */
7151#if 0
7152 if (strcasecmp(val, "1") == 0) {
7153 send_resp(dut, conn, SIGMA_INVALID,
7154 "ErrorCode,DiscoveryMode 1 not supported");
7155 return 0;
7156 }
7157
7158 if (strcasecmp(val, "0") == 0) {
7159 /* OK */
7160 } else {
7161 send_resp(dut, conn, SIGMA_INVALID,
7162 "ErrorCode,DiscoveryMode not supported");
7163 return 0;
7164 }
7165#endif
7166 }
7167
7168 if (start_sta_mode(dut) != 0)
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007169 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007170 return sta_set_60g_common(dut, conn, cmd);
7171}
7172
7173
Jouni Malinenf7222712019-06-13 01:50:21 +03007174static enum sigma_cmd_result cmd_sta_disconnect(struct sigma_dut *dut,
7175 struct sigma_conn *conn,
7176 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007177{
7178 const char *intf = get_param(cmd, "Interface");
Jouni Malinened77e672018-01-10 16:45:13 +02007179 const char *val = get_param(cmd, "maintain_profile");
vamsi krishnad605c422017-09-20 14:56:31 +05307180
Jouni Malinened77e672018-01-10 16:45:13 +02007181 if (dut->program == PROGRAM_OCE ||
Amarnath Hullur Subramanyamebeda9e2018-01-31 03:21:48 -08007182 dut->program == PROGRAM_HE ||
Jouni Malinened77e672018-01-10 16:45:13 +02007183 (val && atoi(val) == 1)) {
vamsi krishnad605c422017-09-20 14:56:31 +05307184 wpa_command(intf, "DISCONNECT");
7185 return 1;
7186 }
7187
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007188 disconnect_station(dut);
7189 /* Try to ignore old scan results to avoid HS 2.0R2 test case failures
7190 * due to cached results. */
7191 wpa_command(intf, "SET ignore_old_scan_res 1");
7192 wpa_command(intf, "BSS_FLUSH");
7193 return 1;
7194}
7195
7196
Jouni Malinenf7222712019-06-13 01:50:21 +03007197static enum sigma_cmd_result cmd_sta_reassoc(struct sigma_dut *dut,
7198 struct sigma_conn *conn,
7199 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007200{
7201 const char *intf = get_param(cmd, "Interface");
7202 const char *bssid = get_param(cmd, "bssid");
7203 const char *val = get_param(cmd, "CHANNEL");
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07007204 const char *freq_val = get_param(cmd, "ChnlFreq");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007205 struct wpa_ctrl *ctrl;
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05307206 char buf[1000];
Sunil Duttd30ce092018-01-11 23:56:29 +05307207 char result[32];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007208 int res;
7209 int chan = 0;
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07007210 int freq = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007211 enum sigma_cmd_result status = STATUS_SENT;
Sunil Duttd30ce092018-01-11 23:56:29 +05307212 int fastreassoc = 1;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007213 int ft_ds = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007214
7215 if (bssid == NULL) {
7216 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing bssid "
7217 "argument");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007218 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007219 }
7220
7221 if (val)
7222 chan = atoi(val);
7223
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07007224 if (freq_val)
7225 freq = atoi(freq_val);
7226
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007227 if (wifi_chip_type != DRIVER_WCN && wifi_chip_type != DRIVER_AR6003) {
7228 /* The current network may be from sta_associate or
7229 * sta_hs2_associate
7230 */
7231 if (set_network(intf, dut->infra_network_id, "bssid", bssid) <
7232 0 ||
7233 set_network(intf, 0, "bssid", bssid) < 0)
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007234 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007235 }
7236
7237 ctrl = open_wpa_mon(intf);
7238 if (ctrl == NULL) {
7239 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
7240 "wpa_supplicant monitor connection");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007241 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007242 }
7243
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007244 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Sunil Duttd30ce092018-01-11 23:56:29 +05307245 sizeof(result)) < 0 ||
7246 strncmp(result, "COMPLETED", 9) != 0) {
7247 sigma_dut_print(dut, DUT_MSG_DEBUG,
7248 "sta_reassoc: Not connected");
7249 fastreassoc = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007250 } else if (dut->sta_ft_ds) {
7251 sigma_dut_print(dut, DUT_MSG_DEBUG,
7252 "sta_reassoc: Use FT-over-DS");
7253 ft_ds = 1;
Sunil Duttd30ce092018-01-11 23:56:29 +05307254 }
7255
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05307256 if (dut->rsne_override) {
7257#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007258 if (get_driver_type(dut) == DRIVER_WCN &&
7259 dut->config_rsnie == 0) {
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05307260 sta_config_params(dut, intf, STA_SET_RSNIE, 1);
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05307261 dut->config_rsnie = 1;
7262 }
7263#endif /* NL80211_SUPPORT */
7264 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
7265 dut->rsne_override);
7266 if (wpa_command(intf, buf) < 0) {
7267 send_resp(dut, conn, SIGMA_ERROR,
7268 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
7269 return 0;
7270 }
7271 }
7272
Shivani Baranwal7aa48602021-09-29 10:53:38 +05307273 if (ft_ds && get_driver_type(dut) != DRIVER_WCN) {
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07007274 if (chan || freq) {
7275 if (!freq)
7276 freq = channel_to_freq(dut, chan);
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007277 if (!freq) {
7278 sigma_dut_print(dut, DUT_MSG_ERROR,
7279 "Invalid channel number provided: %d",
7280 chan);
7281 send_resp(dut, conn, SIGMA_INVALID,
7282 "ErrorCode,Invalid channel number");
7283 goto close_mon_conn;
7284 }
7285 res = snprintf(buf, sizeof(buf),
7286 "SCAN TYPE=ONLY freq=%d", freq);
7287 } else {
7288 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
7289 }
7290 if (res < 0 || res >= (int) sizeof(buf)) {
7291 send_resp(dut, conn, SIGMA_ERROR,
7292 "ErrorCode,snprintf failed");
7293 goto close_mon_conn;
7294 }
7295 if (wpa_command(intf, buf) < 0) {
7296 sigma_dut_print(dut, DUT_MSG_INFO,
7297 "Failed to start scan");
7298 send_resp(dut, conn, SIGMA_ERROR,
7299 "ErrorCode,scan failed");
7300 goto close_mon_conn;
7301 }
7302
7303 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
7304 buf, sizeof(buf));
7305 if (res < 0) {
7306 sigma_dut_print(dut, DUT_MSG_INFO,
7307 "Scan did not complete");
7308 send_resp(dut, conn, SIGMA_ERROR,
7309 "ErrorCode,scan did not complete");
7310 goto close_mon_conn;
7311 }
7312
7313 res = snprintf(buf, sizeof(buf), "FT_DS %s", bssid);
7314 if (res > 0 && res < (int) sizeof(buf))
7315 res = wpa_command(intf, buf);
7316
7317 if (res < 0 || res >= (int) sizeof(buf)) {
7318 send_resp(dut, conn, SIGMA_ERROR,
7319 "errorCode,FT_DS command failed");
7320 status = STATUS_SENT_ERROR;
7321 goto close_mon_conn;
7322 }
7323 } else if (wifi_chip_type == DRIVER_WCN && fastreassoc) {
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07007324 if (chan || freq) {
7325 if (!freq)
7326 freq = channel_to_freq(dut, chan);
Ashwini Patil4c8158f2017-05-25 12:49:21 +05307327 if (!freq) {
7328 sigma_dut_print(dut, DUT_MSG_ERROR,
7329 "Invalid channel number provided: %d",
7330 chan);
7331 send_resp(dut, conn, SIGMA_INVALID,
7332 "ErrorCode,Invalid channel number");
7333 goto close_mon_conn;
7334 }
7335 res = snprintf(buf, sizeof(buf),
7336 "SCAN TYPE=ONLY freq=%d", freq);
7337 } else {
7338 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
7339 }
7340 if (res < 0 || res >= (int) sizeof(buf)) {
7341 send_resp(dut, conn, SIGMA_ERROR,
7342 "ErrorCode,snprintf failed");
7343 goto close_mon_conn;
7344 }
7345 if (wpa_command(intf, buf) < 0) {
7346 sigma_dut_print(dut, DUT_MSG_INFO,
7347 "Failed to start scan");
7348 send_resp(dut, conn, SIGMA_ERROR,
7349 "ErrorCode,scan failed");
7350 goto close_mon_conn;
7351 }
7352
7353 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
7354 buf, sizeof(buf));
7355 if (res < 0) {
7356 sigma_dut_print(dut, DUT_MSG_INFO,
7357 "Scan did not complete");
7358 send_resp(dut, conn, SIGMA_ERROR,
7359 "ErrorCode,scan did not complete");
7360 goto close_mon_conn;
7361 }
7362
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007363 if (set_network(intf, dut->infra_network_id, "bssid", "any")
7364 < 0) {
7365 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
7366 "bssid to any during FASTREASSOC");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007367 status = ERROR_SEND_STATUS;
Ashwini Patil467efef2017-05-25 12:18:27 +05307368 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007369 }
Vinita Maloo54b78cf2020-03-30 12:18:19 +05307370 res = snprintf(buf, sizeof(buf), "FASTREASSOC %s %d",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007371 bssid, chan);
Vinita Maloo54b78cf2020-03-30 12:18:19 +05307372 if (res < 0 || res >= (int) sizeof(buf) ||
7373 wcn_driver_cmd(intf, buf) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007374 send_resp(dut, conn, SIGMA_ERROR,
Vinita Maloo54b78cf2020-03-30 12:18:19 +05307375 "errorCode,Failed to run FASTREASSOC");
Ashwini Patil467efef2017-05-25 12:18:27 +05307376 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007377 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007378 sigma_dut_print(dut, DUT_MSG_INFO,
7379 "sta_reassoc: Run %s successful", buf);
7380 } else if (wpa_command(intf, "REASSOCIATE")) {
7381 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
7382 "request reassociation");
Ashwini Patil467efef2017-05-25 12:18:27 +05307383 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007384 }
7385
7386 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
7387 buf, sizeof(buf));
Ashwini Patil467efef2017-05-25 12:18:27 +05307388 if (res < 0) {
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007389 send_resp(dut, conn, SIGMA_ERROR,
7390 "errorCode,Connection did not complete");
7391 status = STATUS_SENT_ERROR;
Ashwini Patil467efef2017-05-25 12:18:27 +05307392 goto close_mon_conn;
7393 }
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007394 status = SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007395
Ashwini Patil467efef2017-05-25 12:18:27 +05307396close_mon_conn:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007397 wpa_ctrl_detach(ctrl);
7398 wpa_ctrl_close(ctrl);
Ashwini Patil467efef2017-05-25 12:18:27 +05307399 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007400}
7401
7402
7403static void hs2_clear_credentials(const char *intf)
7404{
7405 wpa_command(intf, "REMOVE_CRED all");
7406}
7407
7408
Lior Davidcc88b562017-01-03 18:52:09 +02007409#ifdef __linux__
7410static int wil6210_get_aid(struct sigma_dut *dut, const char *bssid,
7411 unsigned int *aid)
7412{
Lior David0fe101e2017-03-09 16:09:50 +02007413 const char *pattern = "AID[ \t]+([0-9]+)";
Lior Davidcc88b562017-01-03 18:52:09 +02007414
Lior David0fe101e2017-03-09 16:09:50 +02007415 return wil6210_get_sta_info_field(dut, bssid, pattern, aid);
Lior Davidcc88b562017-01-03 18:52:09 +02007416}
7417#endif /* __linux__ */
7418
7419
7420static int sta_get_aid_60g(struct sigma_dut *dut, const char *bssid,
7421 unsigned int *aid)
7422{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007423 switch (get_driver_type(dut)) {
Lior Davidcc88b562017-01-03 18:52:09 +02007424#ifdef __linux__
7425 case DRIVER_WIL6210:
7426 return wil6210_get_aid(dut, bssid, aid);
7427#endif /* __linux__ */
7428 default:
7429 sigma_dut_print(dut, DUT_MSG_ERROR, "get AID not supported");
7430 return -1;
7431 }
7432}
7433
7434
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007435static int sta_get_parameter_60g(struct sigma_dut *dut, struct sigma_conn *conn,
7436 struct sigma_cmd *cmd)
7437{
7438 char buf[MAX_CMD_LEN];
7439 char bss_list[MAX_CMD_LEN];
7440 const char *parameter = get_param(cmd, "Parameter");
7441
7442 if (parameter == NULL)
7443 return -1;
7444
Lior Davidcc88b562017-01-03 18:52:09 +02007445 if (strcasecmp(parameter, "AID") == 0) {
7446 unsigned int aid = 0;
7447 char bssid[20];
7448
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007449 if (get_wpa_status(get_station_ifname(dut), "bssid",
Lior Davidcc88b562017-01-03 18:52:09 +02007450 bssid, sizeof(bssid)) < 0) {
7451 sigma_dut_print(dut, DUT_MSG_ERROR,
7452 "could not get bssid");
7453 return -2;
7454 }
7455
7456 if (sta_get_aid_60g(dut, bssid, &aid))
7457 return -2;
7458
7459 snprintf(buf, sizeof(buf), "aid,%d", aid);
7460 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
7461 send_resp(dut, conn, SIGMA_COMPLETE, buf);
7462 return 0;
7463 }
7464
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007465 if (strcasecmp(parameter, "DiscoveredDevList") == 0) {
7466 char *bss_line;
7467 char *bss_id = NULL;
7468 const char *ifname = get_param(cmd, "Interface");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05307469 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007470
7471 if (ifname == NULL) {
7472 sigma_dut_print(dut, DUT_MSG_INFO,
7473 "For get DiscoveredDevList need Interface name.");
7474 return -1;
7475 }
7476
7477 /*
7478 * Use "BSS RANGE=ALL MASK=0x2" which provides a list
7479 * of BSSIDs in "bssid=<BSSID>\n"
7480 */
7481 if (wpa_command_resp(ifname, "BSS RANGE=ALL MASK=0x2",
7482 bss_list,
7483 sizeof(bss_list)) < 0) {
7484 sigma_dut_print(dut, DUT_MSG_ERROR,
7485 "Failed to get bss list");
7486 return -1;
7487 }
7488
7489 sigma_dut_print(dut, DUT_MSG_DEBUG,
7490 "bss list for ifname:%s is:%s",
7491 ifname, bss_list);
7492
7493 snprintf(buf, sizeof(buf), "DeviceList");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05307494 bss_line = strtok_r(bss_list, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007495 while (bss_line) {
7496 if (sscanf(bss_line, "bssid=%ms", &bss_id) > 0 &&
7497 bss_id) {
7498 int len;
7499
7500 len = snprintf(buf + strlen(buf),
7501 sizeof(buf) - strlen(buf),
7502 ",%s", bss_id);
7503 free(bss_id);
7504 bss_id = NULL;
7505 if (len < 0) {
7506 sigma_dut_print(dut,
7507 DUT_MSG_ERROR,
7508 "Failed to read BSSID");
7509 send_resp(dut, conn, SIGMA_ERROR,
7510 "ErrorCode,Failed to read BSS ID");
7511 return 0;
7512 }
7513
7514 if ((size_t) len >= sizeof(buf) - strlen(buf)) {
7515 sigma_dut_print(dut,
7516 DUT_MSG_ERROR,
7517 "Response buf too small for list");
7518 send_resp(dut, conn,
7519 SIGMA_ERROR,
7520 "ErrorCode,Response buf too small for list");
7521 return 0;
7522 }
7523 }
7524
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05307525 bss_line = strtok_r(NULL, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007526 }
7527
7528 sigma_dut_print(dut, DUT_MSG_INFO, "DiscoveredDevList is %s",
7529 buf);
7530 send_resp(dut, conn, SIGMA_COMPLETE, buf);
7531 return 0;
7532 }
7533
7534 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7535 return 0;
7536}
7537
7538
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07007539static int sta_get_parameter_he(struct sigma_dut *dut, struct sigma_conn *conn,
7540 struct sigma_cmd *cmd)
7541{
7542 char buf[MAX_CMD_LEN];
7543 const char *parameter = get_param(cmd, "Parameter");
7544
7545 if (!parameter)
7546 return -1;
7547
7548 if (strcasecmp(parameter, "RSSI") == 0) {
7549 char rssi[10];
7550
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007551 if (get_wpa_signal_poll(dut, get_station_ifname(dut), "RSSI",
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07007552 rssi, sizeof(rssi)) < 0) {
7553 sigma_dut_print(dut, DUT_MSG_ERROR,
7554 "Could not get RSSI");
7555 return -2;
7556 }
7557
7558 snprintf(buf, sizeof(buf), "rssi,%s", rssi);
7559 sigma_dut_print(dut, DUT_MSG_INFO, "RSSI %s", buf);
7560 send_resp(dut, conn, SIGMA_COMPLETE, buf);
7561 return 0;
7562 }
7563
7564 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7565 return 0;
7566}
7567
7568
Veerendranath Jakkamd0ad6ef2020-05-21 17:09:26 +05307569#ifdef NL80211_SUPPORT
7570
7571struct station_info {
7572 uint64_t filled;
7573 uint32_t beacon_mic_error_count;
7574 uint32_t beacon_replay_count;
7575};
7576
7577
7578static int qca_get_sta_info_handler(struct nl_msg *msg, void *arg)
7579{
7580 struct nlattr *tb[NL80211_ATTR_MAX + 1];
7581 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
7582 struct station_info *data = arg;
7583 struct nlattr *info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_MAX + 1];
7584 static struct nla_policy info_policy[
7585 QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_MAX + 1] = {
7586 [QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT] = {
7587 .type = NLA_U32
7588 },
7589 [QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT] = {
7590 .type = NLA_U32
7591 },
7592 };
7593
7594 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
7595 genlmsg_attrlen(gnlh, 0), NULL);
7596
7597 if (!tb[NL80211_ATTR_VENDOR_DATA])
7598 return NL_SKIP;
7599
7600 if (nla_parse_nested(info, QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_MAX,
7601 tb[NL80211_ATTR_VENDOR_DATA], info_policy)) {
7602 return NL_SKIP;
7603 }
7604
7605 if (info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT]) {
7606 data->filled |=
7607 BIT_ULL(QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT);
7608 data->beacon_mic_error_count =
7609 nla_get_u32(info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT]);
7610 }
7611
7612 if (info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT]) {
7613 data->filled |=
7614 BIT_ULL(QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT);
7615 data->beacon_replay_count =
7616 nla_get_u32(info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT]);
7617 }
7618
7619 return NL_SKIP;
7620}
7621
7622
7623static int qca_nl80211_get_sta_info(struct sigma_dut *dut, const char *intf,
7624 struct station_info *sta_data)
7625{
7626 struct nl_msg *msg;
7627 int ifindex, ret;
7628
7629 ifindex = if_nametoindex(intf);
7630 if (ifindex == 0) {
7631 sigma_dut_print(dut, DUT_MSG_ERROR,
7632 "%s: Index for interface %s not found",
7633 __func__, intf);
7634 return -1;
7635 }
7636
7637 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7638 NL80211_CMD_VENDOR)) ||
7639 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7640 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7641 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7642 QCA_NL80211_VENDOR_SUBCMD_GET_STA_INFO)) {
7643 sigma_dut_print(dut, DUT_MSG_ERROR,
7644 "%s: err in adding vendor_cmd", __func__);
7645 nlmsg_free(msg);
7646 return -1;
7647 }
7648
7649 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg,
7650 qca_get_sta_info_handler, sta_data);
7651 if (ret) {
7652 sigma_dut_print(dut, DUT_MSG_ERROR,
7653 "%s: err in send_and_recv_msgs, ret=%d",
7654 __func__, ret);
7655 }
7656 return ret;
7657}
7658#endif /* NL80211_SUPPORT */
7659
7660
7661static int get_bip_mic_error_count(struct sigma_dut *dut,
7662 const char *ifname,
7663 unsigned int *count)
7664{
7665#ifdef NL80211_SUPPORT
7666 struct station_info sta_data;
7667#endif /* NL80211_SUPPORT */
7668
7669 if (get_driver_type(dut) != DRIVER_WCN) {
7670 sigma_dut_print(dut, DUT_MSG_ERROR,
7671 "BIP MIC error count not supported");
7672 return -1;
7673 }
7674
7675#ifdef NL80211_SUPPORT
7676 if (qca_nl80211_get_sta_info(dut, ifname, &sta_data) != 0 ||
7677 !(sta_data.filled &
7678 BIT_ULL(QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT))) {
7679 sigma_dut_print(dut, DUT_MSG_ERROR,
7680 "BIP MIC error count fetching failed");
7681 return -1;
7682 }
7683
7684 *count = sta_data.beacon_mic_error_count;
7685 return 0;
7686#else /* NL80211_SUPPORT */
7687 sigma_dut_print(dut, DUT_MSG_ERROR,
7688 "BIP MIC error count cannot be fetched without NL80211_SUPPORT defined");
7689 return -1;
7690#endif /* NL80211_SUPPORT */
7691}
7692
7693
7694static int get_cmac_replay_count(struct sigma_dut *dut, const char *ifname,
7695 unsigned int *count)
7696{
7697#ifdef NL80211_SUPPORT
7698 struct station_info sta_data;
7699#endif /* NL80211_SUPPORT */
7700
7701 if (get_driver_type(dut) != DRIVER_WCN) {
7702 sigma_dut_print(dut, DUT_MSG_ERROR,
7703 "CMAC reply count not supported");
7704 return -1;
7705 }
7706
7707#ifdef NL80211_SUPPORT
7708 if (qca_nl80211_get_sta_info(dut, ifname, &sta_data) != 0 ||
7709 !(sta_data.filled &
7710 BIT_ULL(QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT))) {
7711 sigma_dut_print(dut, DUT_MSG_ERROR,
7712 "CMAC replay count fetching failed");
7713 return -1;
7714 }
7715
7716 *count = sta_data.beacon_replay_count;
7717 return 0;
7718#else /* NL80211_SUPPORT */
7719 sigma_dut_print(dut, DUT_MSG_ERROR,
7720 "CMAC replay count cannot be fetched without NL80211_SUPPORT defined");
7721 return -1;
7722#endif /* NL80211_SUPPORT */
7723}
7724
7725
7726static enum sigma_cmd_result sta_get_parameter_wpa3(struct sigma_dut *dut,
7727 struct sigma_conn *conn,
7728 struct sigma_cmd *cmd)
7729{
7730 char buf[MAX_CMD_LEN];
7731 const char *ifname = get_param(cmd, "interface");
7732 const char *parameter = get_param(cmd, "Parameter");
7733 unsigned int val;
7734
7735 if (!ifname || !parameter)
7736 return INVALID_SEND_STATUS;
7737
7738 if (strcasecmp(parameter, "BIPMICErrors") == 0) {
7739 if (get_bip_mic_error_count(dut, ifname, &val)) {
7740 send_resp(dut, conn, SIGMA_ERROR,
7741 "ErrorCode,Failed to get BIPMICErrors");
7742 return STATUS_SENT_ERROR;
7743 }
7744 snprintf(buf, sizeof(buf), "BIPMICErrors,%d", val);
7745 sigma_dut_print(dut, DUT_MSG_INFO, "BIPMICErrors %s", buf);
7746 send_resp(dut, conn, SIGMA_COMPLETE, buf);
7747 return STATUS_SENT;
7748 }
7749
7750 if (strcasecmp(parameter, "CMACReplays") == 0) {
7751 if (get_cmac_replay_count(dut, ifname, &val)) {
7752 send_resp(dut, conn, SIGMA_ERROR,
7753 "ErrorCode,Failed to get CMACReplays");
7754 return STATUS_SENT_ERROR;
7755 }
7756 snprintf(buf, sizeof(buf), "CMACReplays,%d", val);
7757 sigma_dut_print(dut, DUT_MSG_INFO, "CMACReplays %s", buf);
7758 send_resp(dut, conn, SIGMA_COMPLETE, buf);
7759 return STATUS_SENT;
7760 }
7761
7762 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7763 return STATUS_SENT_ERROR;
7764}
7765
7766
Jouni Malinenca0abd32020-02-09 20:18:10 +02007767static enum sigma_cmd_result sta_get_pmk(struct sigma_dut *dut,
7768 struct sigma_conn *conn,
7769 struct sigma_cmd *cmd)
7770{
7771 const char *intf = get_param(cmd, "Interface");
7772 char buf[4096], bssid[20], resp[200], *pos, *tmp;
7773
7774 snprintf(buf, sizeof(buf), "PMKSA_GET %d", dut->infra_network_id);
7775 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
7776 strncmp(buf, "UNKNOWN COMMAND", 15) == 0) {
7777 send_resp(dut, conn, SIGMA_ERROR,
7778 "ErrorCode,PMKSA_GET not supported");
7779 return STATUS_SENT_ERROR;
7780 }
7781
7782 if (strncmp(buf, "FAIL", 4) == 0 ||
7783 get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
7784 send_resp(dut, conn, SIGMA_ERROR,
7785 "ErrorCode,Could not find current network");
7786 return STATUS_SENT_ERROR;
7787 }
7788
7789 pos = buf;
7790 while (pos) {
7791 if (strncmp(pos, bssid, 17) == 0) {
7792 pos = strchr(pos, ' ');
7793 if (!pos)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05307794 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02007795 pos++;
7796 pos = strchr(pos, ' ');
7797 if (!pos)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05307798 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02007799 pos++;
7800 tmp = strchr(pos, ' ');
7801 if (!tmp)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05307802 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02007803 *tmp = '\0';
7804 break;
7805 }
Jouni Malinenca0abd32020-02-09 20:18:10 +02007806 pos = strchr(pos, '\n');
7807 if (pos)
7808 pos++;
7809 }
7810
7811 if (!pos) {
7812 send_resp(dut, conn, SIGMA_ERROR,
7813 "ErrorCode,PMK not available");
7814 return STATUS_SENT_ERROR;
7815 }
7816
7817 snprintf(resp, sizeof(resp), "PMK,%s", pos);
7818 send_resp(dut, conn, SIGMA_COMPLETE, resp);
7819 return STATUS_SENT;
7820}
7821
7822
Jouni Malinenf7222712019-06-13 01:50:21 +03007823static enum sigma_cmd_result cmd_sta_get_parameter(struct sigma_dut *dut,
7824 struct sigma_conn *conn,
7825 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007826{
7827 const char *program = get_param(cmd, "Program");
Jouni Malinenca0abd32020-02-09 20:18:10 +02007828 const char *parameter = get_param(cmd, "Parameter");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007829
Jouni Malinenca0abd32020-02-09 20:18:10 +02007830 if (!parameter)
7831 return INVALID_SEND_STATUS;
7832
7833 if (strcasecmp(parameter, "PMK") == 0)
7834 return sta_get_pmk(dut, conn, cmd);
7835
7836 if (!program)
7837 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007838
7839 if (strcasecmp(program, "P2PNFC") == 0)
7840 return p2p_cmd_sta_get_parameter(dut, conn, cmd);
7841
7842 if (strcasecmp(program, "60ghz") == 0)
7843 return sta_get_parameter_60g(dut, conn, cmd);
7844
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07007845 if (strcasecmp(program, "he") == 0)
7846 return sta_get_parameter_he(dut, conn, cmd);
7847
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007848#ifdef ANDROID_NAN
7849 if (strcasecmp(program, "NAN") == 0)
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07007850 return nan_cmd_sta_get_parameter(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007851#endif /* ANDROID_NAN */
7852
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007853#ifdef MIRACAST
7854 if (strcasecmp(program, "WFD") == 0 ||
7855 strcasecmp(program, "DisplayR2") == 0)
7856 return miracast_cmd_sta_get_parameter(dut, conn, cmd);
7857#endif /* MIRACAST */
Veerendranath Jakkamd0ad6ef2020-05-21 17:09:26 +05307858 if (strcasecmp(program, "WPA3") == 0)
7859 return sta_get_parameter_wpa3(dut, conn, cmd);
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007860
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007861 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7862 return 0;
7863}
7864
7865
7866static void sta_reset_default_ath(struct sigma_dut *dut, const char *intf,
7867 const char *type)
7868{
7869 char buf[100];
7870
7871 if (dut->program == PROGRAM_VHT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007872 run_iwpriv(dut, intf, "chwidth 2");
7873 run_iwpriv(dut, intf, "mode 11ACVHT80");
7874 run_iwpriv(dut, intf, "vhtmcs -1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007875 }
7876
7877 if (dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007878 run_iwpriv(dut, intf, "chwidth 0");
7879 run_iwpriv(dut, intf, "mode 11naht40");
7880 run_iwpriv(dut, intf, "set11NRates 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007881 }
7882
7883 if (dut->program == PROGRAM_VHT || dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007884 run_iwpriv(dut, intf, "powersave 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007885
7886 /* Reset CTS width */
7887 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 54 0",
7888 intf);
7889 if (system(buf) != 0) {
7890 sigma_dut_print(dut, DUT_MSG_ERROR,
7891 "wifitool %s beeliner_fw_test 54 0 failed",
7892 intf);
7893 }
7894
7895 /* Enable Dynamic Bandwidth signalling by default */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007896 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007897
7898 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", intf);
7899 if (system(buf) != 0) {
7900 sigma_dut_print(dut, DUT_MSG_ERROR,
7901 "iwpriv rts failed");
7902 }
7903 }
7904
7905 if (type && strcasecmp(type, "Testbed") == 0) {
7906 dut->testbed_flag_txsp = 1;
7907 dut->testbed_flag_rxsp = 1;
7908 /* STA has to set spatial stream to 2 per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007909 run_iwpriv(dut, intf, "vht_mcsmap 0xfff0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007910
7911 /* Disable LDPC per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007912 run_iwpriv(dut, intf, "ldpc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007913
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007914 run_iwpriv(dut, intf, "amsdu 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007915
7916 /* TODO: Disable STBC 2x1 transmit and receive */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007917 run_iwpriv(dut, intf, "tx_stbc 0");
7918 run_iwpriv(dut, intf, "rx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007919
7920 /* STA has to disable Short GI per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007921 run_iwpriv(dut, intf, "shortgi 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007922 }
7923
7924 if (type && strcasecmp(type, "DUT") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007925 run_iwpriv(dut, intf, "nss 3");
Arif Hussainac6c5112018-05-25 17:34:00 -07007926 dut->sta_nss = 3;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007927
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007928 run_iwpriv(dut, intf, "shortgi 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007929 }
7930}
7931
7932
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007933#ifdef NL80211_SUPPORT
7934static int sta_set_he_mcs(struct sigma_dut *dut, const char *intf,
7935 enum he_mcs_config mcs)
7936{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307937 return wcn_wifi_test_config_set_u8(
7938 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MCS, mcs);
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007939}
7940#endif /* NL80211_SUPPORT */
7941
7942
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07007943static int sta_set_action_tx_in_he_tb_ppdu(struct sigma_dut *dut,
7944 const char *intf, int enable)
7945{
7946#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307947 return wcn_wifi_test_config_set_u8(
7948 dut, intf,
7949 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_ACTION_TX_TB_PPDU,
7950 enable);
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07007951#else /* NL80211_SUPPORT */
7952 sigma_dut_print(dut, DUT_MSG_ERROR,
7953 "HE action Tx TB PPDU cannot be set without NL80211_SUPPORT defined");
7954 return -1;
7955#endif /* NL80211_SUPPORT */
7956}
7957
7958
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08007959static int sta_set_heconfig_and_wep_tkip(struct sigma_dut *dut,
7960 const char *intf, int enable)
7961{
7962#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307963 return wcn_wifi_test_config_set_u8(
7964 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WEP_TKIP_IN_HE,
7965 enable);
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08007966#else /* NL80211_SUPPORT */
7967 sigma_dut_print(dut, DUT_MSG_ERROR,
7968 "HE config enablement cannot be changed without NL80211_SUPPORT defined");
7969 return -1;
7970#endif /* NL80211_SUPPORT */
7971}
7972
7973
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007974#ifdef NL80211_SUPPORT
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007975
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007976static int sta_set_he_testbed_def(struct sigma_dut *dut,
7977 const char *intf, int cfg)
7978{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307979 return wcn_wifi_test_config_set_u8(
7980 dut, intf,
7981 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SET_HE_TESTBED_DEFAULTS,
7982 cfg);
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007983}
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007984
7985
7986static int sta_set_2g_vht_supp(struct sigma_dut *dut, const char *intf, int cfg)
7987{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307988 return wcn_wifi_test_config_set_u8(
7989 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_2G_VHT,
7990 cfg);
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007991}
7992
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007993#endif /* NL80211_SUPPORT */
7994
7995
Qiwei Caib6806972020-01-15 13:52:11 +08007996int sta_set_addba_buf_size(struct sigma_dut *dut,
7997 const char *intf, int bufsize)
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007998{
7999#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05308000 return wcn_wifi_test_config_set_u16(
8001 dut, intf,
8002 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE, bufsize);
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08008003#else /* NL80211_SUPPORT */
8004 sigma_dut_print(dut, DUT_MSG_ERROR,
8005 "AddBA bufsize cannot be changed without NL80211_SUPPORT defined");
8006 return -1;
8007#endif /* NL80211_SUPPORT */
8008}
8009
8010
Kiran Kumar Lokere69d89952021-08-08 23:41:46 -07008011static int sta_set_scan_unicast_probe(struct sigma_dut *dut,
8012 const char *intf, int val)
8013{
8014#ifdef NL80211_SUPPORT
8015 return wcn_wifi_test_config_set_u8(
8016 dut, intf,
8017 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_USE_BSSID_IN_PROBE_REQ_RA,
8018 val);
8019#else /* NL80211_SUPPORT */
8020 sigma_dut_print(dut, DUT_MSG_ERROR,
8021 "Unicast RA in Probe Request frame cannot be set without NL80211_SUPPORT defined");
8022 return -1;
8023#endif /* NL80211_SUPPORT */
8024}
8025
8026
Kiran Kumar Lokere09dbcef2021-08-09 00:01:41 -07008027static int sta_set_rx_ctrl_multi_bss(struct sigma_dut *dut, const char *intf,
8028 int enable)
8029{
8030#ifdef NL80211_SUPPORT
8031 return wcn_wifi_test_config_set_u8(
8032 dut, intf,
8033 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_RX_CTRL_FRAME_TO_MBSS,
8034 enable);
8035#else /* NL80211_SUPPORT */
8036 sigma_dut_print(dut, DUT_MSG_ERROR,
8037 "Rx ctrl frame to Multi-BSS cannot be changed without NL80211_SUPPORT defined");
8038 return -1;
8039#endif /* NL80211_SUPPORT */
8040}
8041
8042
8043static int sta_set_bcast_twt_support(struct sigma_dut *dut, const char *intf,
8044 int enable)
8045{
8046#ifdef NL80211_SUPPORT
8047 return wcn_wifi_test_config_set_u8(
8048 dut, intf,
8049 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BCAST_TWT_SUPPORT,
8050 enable);
8051#else /* NL80211_SUPPORT */
8052 sigma_dut_print(dut, DUT_MSG_ERROR,
8053 "BCAST TWT cannot be changed without NL80211_SUPPORT defined");
8054 return -1;
8055#endif /* NL80211_SUPPORT */
8056}
8057
8058
Arif Hussain8d5b27b2018-05-14 14:31:03 -07008059static int sta_set_tx_beamformee(struct sigma_dut *dut, const char *intf,
8060 int enable)
8061{
8062#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05308063 return wcn_wifi_test_config_set_u8(
8064 dut, intf,
8065 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_TX_BEAMFORMEE,
8066 enable);
Arif Hussain8d5b27b2018-05-14 14:31:03 -07008067#else /* NL80211_SUPPORT */
8068 sigma_dut_print(dut, DUT_MSG_ERROR,
8069 "tx beamformee cannot be changed without NL80211_SUPPORT defined");
8070 return -1;
8071#endif /* NL80211_SUPPORT */
8072}
8073
8074
Arif Hussain9765f7d2018-07-03 08:28:26 -07008075static int sta_set_beamformee_sts(struct sigma_dut *dut, const char *intf,
8076 int val)
8077{
8078#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05308079 return wcn_wifi_test_config_set_u8(
8080 dut, intf,
8081 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_BEAMFORMEE_NSTS,
8082 val);
Arif Hussain9765f7d2018-07-03 08:28:26 -07008083#else /* NL80211_SUPPORT */
8084 sigma_dut_print(dut, DUT_MSG_ERROR,
8085 "beamformee sts cannot be changed without NL80211_SUPPORT defined");
8086 return -1;
8087#endif /* NL80211_SUPPORT */
8088}
8089
8090
Arif Hussain68d23f52018-07-11 13:39:08 -07008091#ifdef NL80211_SUPPORT
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07008092static int sta_set_mac_padding_duration(struct sigma_dut *dut, const char *intf,
8093 enum qca_wlan_he_mac_padding_dur val)
8094{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05308095 return wcn_wifi_test_config_set_u8(
8096 dut, intf,
8097 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MAC_PADDING_DUR, val);
Arif Hussain68d23f52018-07-11 13:39:08 -07008098}
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07008099#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07008100
8101
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07008102static int sta_set_tx_su_ppdu_cfg(struct sigma_dut *dut, const char *intf,
8103 int val)
8104{
8105#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05308106 return wcn_wifi_test_config_set_u8(
8107 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_SUPPDU,
8108 val);
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07008109#else /* NL80211_SUPPORT */
8110 sigma_dut_print(dut, DUT_MSG_ERROR,
8111 "Tx SU PPDU cannot be set without NL80211_SUPPORT defined");
8112 return -1;
8113#endif /* NL80211_SUPPORT */
8114}
8115
8116
Kiran Kumar Lokere54b72522021-04-01 00:22:44 -07008117static int sta_set_mgmt_data_tx_disable_cfg(struct sigma_dut *dut,
8118 const char *intf, int val)
8119{
8120#ifdef NL80211_SUPPORT
8121 return wcn_wifi_test_config_set_u8(
8122 dut, intf,
8123 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_DISABLE_DATA_MGMT_RSP_TX,
8124 val);
8125#else /* NL80211_SUPPORT */
8126 sigma_dut_print(dut, DUT_MSG_ERROR,
8127 "Tx disable config cannot be set without NL80211_SUPPORT defined");
8128 return -1;
8129#endif /* NL80211_SUPPORT */
8130}
8131
8132
Kiran Kumar Lokere1809da12021-06-24 00:45:38 -07008133static int sta_set_keep_alive_data_cfg(struct sigma_dut *dut, const char *intf,
8134 int val)
8135{
8136#ifdef NL80211_SUPPORT
8137 return wcn_wifi_test_config_set_u8(
8138 dut, intf,
8139 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_KEEP_ALIVE_FRAME_TYPE,
8140 val);
8141#else /* NL80211_SUPPORT */
8142 sigma_dut_print(dut, DUT_MSG_ERROR,
8143 "Keep alive data type cannot be set without NL80211_SUPPORT defined");
8144 return -1;
8145#endif /* NL80211_SUPPORT */
8146}
8147
8148
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07008149#ifdef NL80211_SUPPORT
8150static int sta_set_he_om_ctrl_reset(struct sigma_dut *dut, const char *intf)
8151{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05308152 return wcn_wifi_test_config_set_flag(
8153 dut, intf,
8154 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_CLEAR_HE_OM_CTRL_CONFIG);
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07008155}
8156#endif /* NL80211_SUPPORT */
8157
8158
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07008159static int sta_set_mu_edca_override(struct sigma_dut *dut, const char *intf,
8160 int val)
8161{
8162#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05308163 return wcn_wifi_test_config_set_u8(
8164 dut, intf,
8165 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_OVERRIDE_MU_EDCA, val);
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07008166#else /* NL80211_SUPPORT */
8167 sigma_dut_print(dut, DUT_MSG_ERROR,
8168 "MU EDCA override cannot be changed without NL80211_SUPPORT defined");
8169 return -1;
8170#endif /* NL80211_SUPPORT */
8171}
8172
8173
Kiran Kumar Lokerefa7c7b92021-08-09 00:50:55 -07008174static int sta_set_er_su_ppdu_type_tx(struct sigma_dut *dut, const char *intf,
8175 int val)
8176{
8177#ifdef NL80211_SUPPORT
8178 return wcn_wifi_test_config_set_u8(
8179 dut, intf,
8180 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ER_SU_PPDU_TYPE, val);
8181#else /* NL80211_SUPPORT */
8182 sigma_dut_print(dut, DUT_MSG_ERROR,
8183 "ER-SU PPDU type cannot be set without NL80211_SUPPORT defined");
8184 return -1;
8185#endif /* NL80211_SUPPORT */
8186}
8187
8188
8189static int sta_set_ru_242_tone_tx(struct sigma_dut *dut, const char *intf,
8190 int val)
8191{
8192#ifdef NL80211_SUPPORT
8193 return wcn_wifi_test_config_set_u8(
8194 dut, intf,
8195 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_RU_242_TONE_TX, val);
8196#else /* NL80211_SUPPORT */
8197 sigma_dut_print(dut, DUT_MSG_ERROR,
8198 "RU 242 tone cannot be set without NL80211_SUPPORT defined");
8199 return -1;
8200#endif /* NL80211_SUPPORT */
8201}
8202
8203
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07008204static int sta_set_om_ctrl_supp(struct sigma_dut *dut, const char *intf,
8205 int val)
8206{
8207#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05308208 return wcn_wifi_test_config_set_u8(
8209 dut, intf,
8210 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OM_CTRL_SUPP, val);
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07008211#else /* NL80211_SUPPORT */
8212 sigma_dut_print(dut, DUT_MSG_ERROR,
8213 "HE OM ctrl cannot be changed without NL80211_SUPPORT defined");
8214 return -1;
8215#endif /* NL80211_SUPPORT */
8216}
8217
8218
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07008219#ifdef NL80211_SUPPORT
8220
8221struct features_info {
8222 unsigned char flags[8];
8223 size_t flags_len;
8224};
8225
8226static int features_info_handler(struct nl_msg *msg, void *arg)
8227{
8228 struct nlattr *tb[NL80211_ATTR_MAX + 1];
8229 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
8230 struct features_info *info = arg;
8231 struct nlattr *nl_vend, *attr;
8232
8233 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
8234 genlmsg_attrlen(gnlh, 0), NULL);
8235
8236 nl_vend = tb[NL80211_ATTR_VENDOR_DATA];
8237 if (nl_vend) {
8238 struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1];
8239
8240 nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX,
8241 nla_data(nl_vend), nla_len(nl_vend), NULL);
8242
8243 attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_FEATURE_FLAGS];
8244 if (attr) {
8245 int len = nla_len(attr);
8246
Vamsi Krishna79a91132021-08-16 21:40:22 +05308247 if (info && len <= sizeof(info->flags)) {
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07008248 memcpy(info->flags, nla_data(attr), len);
8249 info->flags_len = len;
8250 }
8251 }
8252 }
8253
8254 return NL_SKIP;
8255}
8256
8257
8258static int check_feature(enum qca_wlan_vendor_features feature,
8259 struct features_info *info)
8260{
8261 size_t idx = feature / 8;
8262
Vamsi Krishna79a91132021-08-16 21:40:22 +05308263 if (!info)
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07008264 return 0;
8265
8266 return (idx < info->flags_len) &&
8267 (info->flags[idx] & BIT(feature % 8));
8268}
8269
8270#endif /* NL80211_SUPPORT */
8271
8272
8273static void sta_get_twt_feature_async_supp(struct sigma_dut *dut,
8274 const char *intf)
8275{
8276#ifdef NL80211_SUPPORT
8277 struct nl_msg *msg;
8278 struct features_info info = { 0 };
8279 int ifindex, ret;
8280
8281 ifindex = if_nametoindex(intf);
8282 if (ifindex == 0) {
8283 sigma_dut_print(dut, DUT_MSG_ERROR,
8284 "%s: Index for interface %s failed",
8285 __func__, intf);
8286 return;
8287 }
8288
8289 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8290 NL80211_CMD_VENDOR)) ||
8291 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8292 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8293 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8294 QCA_NL80211_VENDOR_SUBCMD_GET_FEATURES)) {
8295 sigma_dut_print(dut, DUT_MSG_ERROR,
8296 "%s: err in adding vendor_cmd and vendor_data",
8297 __func__);
8298 nlmsg_free(msg);
8299 return;
8300 }
8301
8302 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, features_info_handler,
8303 &info);
8304 if (ret) {
8305 sigma_dut_print(dut, DUT_MSG_ERROR,
8306 "%s: err in send_and_recv_msgs, ret=%d",
8307 __func__, ret);
8308 return;
8309 }
8310
8311 if (check_feature(QCA_WLAN_VENDOR_FEATURE_TWT_ASYNC_SUPPORT, &info))
8312 dut->sta_async_twt_supp = 1;
8313 else
8314 dut->sta_async_twt_supp = 0;
8315
8316 sigma_dut_print(dut, DUT_MSG_DEBUG,
8317 "%s: sta_async_twt_supp %d",
8318 __func__, dut->sta_async_twt_supp);
8319#else /* NL80211_SUPPORT */
8320 sigma_dut_print(dut, DUT_MSG_INFO,
8321 "TWT async supp get cannot be done without NL80211_SUPPORT defined");
8322 dut->sta_async_twt_supp = 0;
8323#endif /* NL80211_SUPPORT */
8324}
8325
8326
Arif Hussain480d5f42019-03-12 14:40:42 -07008327static int sta_set_twt_req_support(struct sigma_dut *dut, const char *intf,
8328 int val)
8329{
8330#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05308331 return wcn_wifi_test_config_set_u8(
8332 dut, intf,
8333 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TWT_REQ_SUPPORT, val);
Arif Hussain480d5f42019-03-12 14:40:42 -07008334#else /* NL80211_SUPPORT */
8335 sigma_dut_print(dut, DUT_MSG_ERROR,
8336 "TWT Request cannot be changed without NL80211_SUPPORT defined");
8337 return -1;
8338#endif /* NL80211_SUPPORT */
8339}
8340
8341
Kiran Kumar Lokere4f2d4b02021-04-01 00:07:39 -07008342static int sta_set_bss_max_idle_period(struct sigma_dut *dut, const char *intf,
8343 int val)
8344{
8345#ifdef NL80211_SUPPORT
8346 return wcn_wifi_test_config_set_u16(
8347 dut, intf,
8348 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BSS_MAX_IDLE_PERIOD, val);
8349#else /* NL80211_SUPPORT */
8350 sigma_dut_print(dut, DUT_MSG_ERROR,
8351 "BSS max idle period cannot be set without NL80211_SUPPORT defined");
8352 return -1;
8353#endif /* NL80211_SUPPORT */
8354}
8355
8356
Kiran Kumar Lokere07ad92b2021-08-09 00:27:14 -07008357static int sta_set_bss_max_idle_support(struct sigma_dut *dut, const char *intf,
8358 int val)
8359{
8360#ifdef NL80211_SUPPORT
8361 return wcn_wifi_test_config_set_u8(
8362 dut, intf,
8363 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BSS_MAX_IDLE_PERIOD_ENABLE,
8364 val);
8365#else /* NL80211_SUPPORT */
8366 sigma_dut_print(dut, DUT_MSG_ERROR,
8367 "BSS max idle support cannot be set without NL80211_SUPPORT defined");
8368 return -1;
8369#endif /* NL80211_SUPPORT */
8370}
8371
8372
Srinivas Girigowda0525e292020-11-12 13:28:21 -08008373static int sta_set_fullbw_ulmumimo(struct sigma_dut *dut, const char *intf,
8374 int val)
8375{
8376#ifdef NL80211_SUPPORT
8377 return wcn_wifi_test_config_set_u8(
8378 dut, intf,
8379 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_FULL_BW_UL_MU_MIMO, val);
8380#else /* NL80211_SUPPORT */
8381 sigma_dut_print(dut, DUT_MSG_ERROR,
8382 "Full BW UL MU MIMO cannot be changed without NL80211_SUPPORT defined");
8383 return -1;
8384#endif /* NL80211_SUPPORT */
8385}
8386
8387
Kiran Kumar Lokered0ec5ed2021-04-01 00:15:04 -07008388static int sta_set_punctured_preamble_rx(struct sigma_dut *dut,
8389 const char *intf, int val)
8390{
8391#ifdef NL80211_SUPPORT
8392 return wcn_wifi_test_config_set_u8(
8393 dut, intf,
8394 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_PUNCTURED_PREAMBLE_RX,
8395 val);
8396#else /* NL80211_SUPPORT */
8397 sigma_dut_print(dut, DUT_MSG_ERROR,
8398 "Punctured preamble Rx cannot be set without NL80211_SUPPORT defined");
8399 return -1;
8400#endif /* NL80211_SUPPORT */
8401}
8402
8403
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08008404static void sta_reset_default_wcn(struct sigma_dut *dut, const char *intf,
8405 const char *type)
8406{
8407 char buf[60];
8408
8409 if (dut->program == PROGRAM_HE) {
8410 /* resetting phymode to auto in case of HE program */
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05308411 sta_set_phymode(dut, intf, "auto");
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08008412
Amarnath Hullur Subramanyam9cecb502018-04-25 13:26:30 -07008413 /* reset the rate to Auto rate */
8414 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0xff",
8415 intf);
8416 if (system(buf) != 0) {
8417 sigma_dut_print(dut, DUT_MSG_ERROR,
8418 "iwpriv %s set_11ax_rate 0xff failed",
8419 intf);
8420 }
8421
Kiran Kumar Lokere86cfe3a2018-06-01 11:55:15 -07008422 /* reset the LDPC setting */
8423 snprintf(buf, sizeof(buf), "iwpriv %s ldpc 1", intf);
8424 if (system(buf) != 0) {
8425 sigma_dut_print(dut, DUT_MSG_ERROR,
8426 "iwpriv %s ldpc 1 failed", intf);
8427 }
8428
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08008429 /* reset the power save setting */
Vinita S. Malooa8b62722020-04-23 01:45:41 +05308430 set_power_save_wcn(dut, intf, 2);
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08008431
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08008432 /* remove all network profiles */
8433 remove_wpa_networks(intf);
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08008434
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08008435 /* Configure ADDBA Req/Rsp buffer size to be 64 */
8436 sta_set_addba_buf_size(dut, intf, 64);
8437
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07008438 if (dut->sta_async_twt_supp == -1)
8439 sta_get_twt_feature_async_supp(dut, intf);
8440
Kiran Kumar Lokere69d89952021-08-08 23:41:46 -07008441 sta_set_scan_unicast_probe(dut, intf, 0);
8442
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08008443#ifdef NL80211_SUPPORT
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08008444 /* Reset the device HE capabilities to its default supported
8445 * configuration. */
8446 sta_set_he_testbed_def(dut, intf, 0);
8447
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08008448 /* Disable noackpolicy for all AC */
8449 if (nlvendor_sta_set_noack(dut, intf, 0, QCA_WLAN_AC_ALL)) {
8450 sigma_dut_print(dut, DUT_MSG_ERROR,
8451 "Disable of noackpolicy for all AC failed");
8452 }
8453#endif /* NL80211_SUPPORT */
8454
Amarnath Hullur Subramanyamb1724a52018-03-07 14:31:46 -08008455 /* Enable WMM by default */
8456 if (wcn_sta_set_wmm(dut, intf, "on")) {
8457 sigma_dut_print(dut, DUT_MSG_ERROR,
8458 "Enable of WMM in sta_reset_default_wcn failed");
8459 }
8460
8461 /* Disable ADDBA_REJECT by default */
8462 if (nlvendor_sta_set_addba_reject(dut, intf, 0)) {
8463 sigma_dut_print(dut, DUT_MSG_ERROR,
8464 "Disable of addba_reject in sta_reset_default_wcn failed");
8465 }
8466
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08008467 /* Enable sending of ADDBA by default */
8468 if (nlvendor_config_send_addba(dut, intf, 1)) {
8469 sigma_dut_print(dut, DUT_MSG_ERROR,
8470 "Enable sending of ADDBA in sta_reset_default_wcn failed");
8471 }
8472
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08008473 /* Enable AMPDU by default */
8474 iwpriv_sta_set_ampdu(dut, intf, 1);
8475
Subhani Shaik8e7a3052018-04-24 14:03:00 -07008476#ifdef NL80211_SUPPORT
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -08008477 if (wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_AUTO)) {
Subhani Shaik8e7a3052018-04-24 14:03:00 -07008478 sigma_dut_print(dut, DUT_MSG_ERROR,
8479 "Set LTF config to default in sta_reset_default_wcn failed");
8480 }
Arif Hussain9765f7d2018-07-03 08:28:26 -07008481
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08008482 /* set the beamformee NSTS(maximum number of
8483 * space-time streams) to default DUT config
8484 */
8485 if (sta_set_beamformee_sts(dut, intf, 7)) {
Arif Hussain9765f7d2018-07-03 08:28:26 -07008486 sigma_dut_print(dut, DUT_MSG_ERROR,
8487 "Failed to set BeamformeeSTS");
8488 }
Arif Hussain68d23f52018-07-11 13:39:08 -07008489
Kiran Kumar Lokere54b72522021-04-01 00:22:44 -07008490 if (sta_set_mgmt_data_tx_disable_cfg(dut, intf, 0)) {
8491 sigma_dut_print(dut, DUT_MSG_ERROR,
8492 "Failed to reset mgmt/data Tx disable config");
8493 }
8494
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07008495 if (sta_set_mac_padding_duration(
8496 dut, intf,
8497 QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07008498 sigma_dut_print(dut, DUT_MSG_ERROR,
8499 "Failed to set MAC padding duration");
8500 }
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07008501
8502 if (sta_set_mu_edca_override(dut, intf, 0)) {
8503 sigma_dut_print(dut, DUT_MSG_ERROR,
8504 "ErrorCode,Failed to set MU EDCA override disable");
8505 }
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07008506
Kiran Kumar Lokerefa7c7b92021-08-09 00:50:55 -07008507 if (sta_set_ru_242_tone_tx(dut, intf, 0)) {
8508 sigma_dut_print(dut, DUT_MSG_ERROR,
8509 "Failed to set RU 242 tone Tx");
8510 }
8511
8512 if (sta_set_er_su_ppdu_type_tx(dut, intf, 0)) {
8513 sigma_dut_print(dut, DUT_MSG_ERROR,
8514 "Failed to set ER-SU PPDU type Tx");
8515 }
8516
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07008517 if (sta_set_om_ctrl_supp(dut, intf, 1)) {
8518 sigma_dut_print(dut, DUT_MSG_ERROR,
8519 "Failed to set OM ctrl supp");
8520 }
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07008521
8522 if (sta_set_tx_su_ppdu_cfg(dut, intf, 1)) {
8523 sigma_dut_print(dut, DUT_MSG_ERROR,
8524 "Failed to set Tx SU PPDU enable");
8525 }
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07008526
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07008527 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 0)) {
8528 sigma_dut_print(dut, DUT_MSG_ERROR,
8529 "failed to send TB PPDU Tx cfg");
8530 }
8531
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07008532 if (sta_set_he_om_ctrl_reset(dut, intf)) {
8533 sigma_dut_print(dut, DUT_MSG_ERROR,
8534 "Failed to set OM ctrl reset");
8535 }
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08008536
8537 /* +HTC-HE support default on */
8538 if (sta_set_he_htc_supp(dut, intf, 1)) {
8539 sigma_dut_print(dut, DUT_MSG_ERROR,
8540 "Setting of +HTC-HE support failed");
8541 }
Subhani Shaik8e7a3052018-04-24 14:03:00 -07008542#endif /* NL80211_SUPPORT */
8543
Arif Hussain8d5b27b2018-05-14 14:31:03 -07008544 if (sta_set_tx_beamformee(dut, intf, 1)) {
8545 sigma_dut_print(dut, DUT_MSG_ERROR,
8546 "Set tx beamformee enable by default in sta_reset_default_wcn failed");
8547 }
8548
Kiran Kumar Lokereb55ff442020-07-15 00:20:40 -07008549 wpa_command(intf, "SET oce 1");
8550
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08008551 /* Set nss to 1 and MCS 0-7 in case of testbed */
8552 if (type && strcasecmp(type, "Testbed") == 0) {
8553#ifdef NL80211_SUPPORT
8554 int ret;
8555#endif /* NL80211_SUPPORT */
8556
Kiran Kumar Lokereb55ff442020-07-15 00:20:40 -07008557 wpa_command(intf, "SET oce 0");
8558
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08008559 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
8560 if (system(buf) != 0) {
8561 sigma_dut_print(dut, DUT_MSG_ERROR,
8562 "iwpriv %s nss failed", intf);
8563 }
8564
8565#ifdef NL80211_SUPPORT
8566 ret = sta_set_he_mcs(dut, intf, HE_80_MCS0_7);
8567 if (ret) {
8568 sigma_dut_print(dut, DUT_MSG_ERROR,
8569 "Setting of MCS failed, ret:%d",
8570 ret);
8571 }
8572#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyamc67621d2018-02-04 23:18:01 -08008573
8574 /* Disable STBC as default */
8575 wcn_sta_set_stbc(dut, intf, "0");
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08008576
8577 /* Disable AMSDU as default */
8578 iwpriv_sta_set_amsdu(dut, intf, "0");
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08008579
8580#ifdef NL80211_SUPPORT
8581 /* HE fragmentation default off */
8582 if (sta_set_he_fragmentation(dut, intf,
8583 HE_FRAG_DISABLE)) {
8584 sigma_dut_print(dut, DUT_MSG_ERROR,
8585 "Setting of HE fragmentation failed");
8586 }
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08008587
8588 /* set the beamformee NSTS(maximum number of
8589 * space-time streams) to default testbed config
8590 */
8591 if (sta_set_beamformee_sts(dut, intf, 3)) {
8592 sigma_dut_print(dut, DUT_MSG_ERROR,
8593 "Failed to set BeamformeeSTS");
8594 }
8595
Kiran Kumar Lokered0ec5ed2021-04-01 00:15:04 -07008596 if (sta_set_punctured_preamble_rx(dut, intf, 0)) {
8597 sigma_dut_print(dut, DUT_MSG_ERROR,
8598 "Failed to reset PreamblePunctRx support");
8599 }
8600
Kiran Kumar Lokere727687f2021-06-24 00:35:49 -07008601 if (sta_set_bss_max_idle_period(dut, intf, 0)) {
8602 sigma_dut_print(dut, DUT_MSG_ERROR,
8603 "Failed to reset BSS max idle period");
8604 }
8605
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08008606 /* +HTC-HE support default off */
8607 if (sta_set_he_htc_supp(dut, intf, 0)) {
8608 sigma_dut_print(dut, DUT_MSG_ERROR,
8609 "Setting of +HTC-HE support failed");
8610 }
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08008611
8612 /* Set device HE capabilities to testbed default
8613 * configuration. */
8614 if (sta_set_he_testbed_def(dut, intf, 1)) {
8615 sigma_dut_print(dut, DUT_MSG_DEBUG,
8616 "Failed to set HE defaults");
8617 }
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08008618
8619 /* Disable VHT support in 2.4 GHz for testbed */
8620 sta_set_2g_vht_supp(dut, intf, 0);
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08008621#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08008622
8623 /* Enable WEP/TKIP with HE capability in testbed */
8624 if (sta_set_heconfig_and_wep_tkip(dut, intf, 1)) {
8625 sigma_dut_print(dut, DUT_MSG_ERROR,
8626 "Enabling HE config with WEP/TKIP failed");
8627 }
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08008628 }
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08008629
8630 /* Defaults in case of DUT */
8631 if (type && strcasecmp(type, "DUT") == 0) {
Arif Hussaind48fcc72018-05-01 18:34:18 -07008632 /* Enable STBC by default */
8633 wcn_sta_set_stbc(dut, intf, "1");
8634
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08008635 /* set nss to 2 */
8636 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
8637 if (system(buf) != 0) {
8638 sigma_dut_print(dut, DUT_MSG_ERROR,
8639 "iwpriv %s nss 2 failed", intf);
8640 }
Arif Hussainac6c5112018-05-25 17:34:00 -07008641 dut->sta_nss = 2;
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08008642
8643#ifdef NL80211_SUPPORT
Arif Hussainae239842018-05-01 18:20:05 -07008644 /* Set HE_MCS to 0-11 */
8645 if (sta_set_he_mcs(dut, intf, HE_80_MCS0_11)) {
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08008646 sigma_dut_print(dut, DUT_MSG_ERROR,
8647 "Setting of MCS failed");
8648 }
8649#endif /* NL80211_SUPPORT */
8650
8651 /* Disable WEP/TKIP with HE capability in DUT */
8652 if (sta_set_heconfig_and_wep_tkip(dut, intf, 0)) {
8653 sigma_dut_print(dut, DUT_MSG_ERROR,
8654 "Enabling HE config with WEP/TKIP failed");
8655 }
8656 }
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08008657 }
8658}
8659
8660
Veerendranath Jakkam47867202020-12-21 01:53:52 +05308661static int sta_set_client_privacy(struct sigma_dut *dut,
8662 struct sigma_conn *conn, const char *intf,
8663 int enable)
8664{
8665 if (enable &&
8666 (wpa_command(intf, "SET mac_addr 1") < 0 ||
8667 wpa_command(intf, "SET rand_addr_lifetime 1") < 0 ||
Veerendranath Jakkam39fd5c42020-12-21 02:02:21 +05308668 (wpa_command(intf, "MAC_RAND_SCAN enable=1 all") < 0 &&
8669 wpa_command(intf, "SET preassoc_mac_addr 1") < 0) ||
Veerendranath Jakkam47867202020-12-21 01:53:52 +05308670 wpa_command(intf, "SET gas_rand_mac_addr 1") < 0 ||
8671 wpa_command(intf, "SET gas_rand_addr_lifetime 1") < 0))
8672 return -1;
8673
8674 if (!enable &&
8675 (wpa_command(intf, "SET mac_addr 0") < 0 ||
Veerendranath Jakkam39fd5c42020-12-21 02:02:21 +05308676 (wpa_command(intf, "MAC_RAND_SCAN enable=0 all") < 0 &&
8677 wpa_command(intf, "SET preassoc_mac_addr 0") < 0) ||
Veerendranath Jakkam47867202020-12-21 01:53:52 +05308678 wpa_command(intf, "SET gas_rand_mac_addr 0") < 0))
8679 return -1;
8680
8681 dut->client_privacy = enable;
8682 return 0;
8683}
8684
8685
Jouni Malinenf7222712019-06-13 01:50:21 +03008686static enum sigma_cmd_result cmd_sta_reset_default(struct sigma_dut *dut,
8687 struct sigma_conn *conn,
8688 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008689{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008690 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008691 const char *band = get_param(cmd, "band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008692 const char *type;
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07008693 const char *program = get_param(cmd, "program");
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05308694 const char *dev_role = get_param(cmd, "DevRole");
Veerendranath Jakkamc1f71b62021-01-23 03:09:51 +05308695 char resp[20];
Veerendranath Jakkamea7f0692021-08-11 19:13:12 +05308696 char buf[100];
Veerendranath Jakkamc1f71b62021-01-23 03:09:51 +05308697 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008698
Jouni Malinenb21f0542019-11-04 17:53:38 +02008699 if (dut->station_ifname_2g &&
8700 strcmp(dut->station_ifname_2g, intf) == 0)
8701 dut->use_5g = 0;
8702 else if (dut->station_ifname_5g &&
8703 strcmp(dut->station_ifname_5g, intf) == 0)
8704 dut->use_5g = 1;
8705
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07008706 if (!program)
8707 program = get_param(cmd, "prog");
8708 dut->program = sigma_program_to_enum(program);
Vinita S. Maloof7a2cbf2020-11-18 19:29:44 +05308709
8710 if (dut->program == PROGRAM_WFD && dut->user_config_timeout)
8711 dut->default_timeout = dut->user_config_timeout;
8712
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008713 dut->device_type = STA_unknown;
8714 type = get_param(cmd, "type");
8715 if (type && strcasecmp(type, "Testbed") == 0)
8716 dut->device_type = STA_testbed;
8717 if (type && strcasecmp(type, "DUT") == 0)
8718 dut->device_type = STA_dut;
8719
8720 if (dut->program == PROGRAM_TDLS) {
8721 /* Clear TDLS testing mode */
8722 wpa_command(intf, "SET tdls_disabled 0");
8723 wpa_command(intf, "SET tdls_testing 0");
8724 dut->no_tpk_expiration = 0;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008725 if (get_driver_type(dut) == DRIVER_WCN) {
Pradeep Reddy POTTETI8ce2a232016-10-28 12:17:32 +05308726 /* Enable the WCN driver in TDLS Explicit trigger mode
8727 */
8728 wpa_command(intf, "SET tdls_external_control 0");
8729 wpa_command(intf, "SET tdls_trigger_control 0");
8730 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008731 }
8732
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07008733#ifdef MIRACAST
8734 if (dut->program == PROGRAM_WFD ||
8735 dut->program == PROGRAM_DISPLAYR2)
8736 miracast_sta_reset_default(dut, conn, cmd);
8737#endif /* MIRACAST */
8738
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008739 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008740 case DRIVER_ATHEROS:
8741 sta_reset_default_ath(dut, intf, type);
8742 break;
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08008743 case DRIVER_WCN:
8744 sta_reset_default_wcn(dut, intf, type);
8745 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008746 default:
8747 break;
8748 }
8749
8750#ifdef ANDROID_NAN
8751 if (dut->program == PROGRAM_NAN)
8752 nan_cmd_sta_reset_default(dut, conn, cmd);
8753#endif /* ANDROID_NAN */
8754
Vinay Gannevaram3b9fdd32019-06-14 17:55:44 +05308755 if (dut->program == PROGRAM_LOC &&
8756 lowi_cmd_sta_reset_default(dut, conn, cmd) < 0)
8757 return ERROR_SEND_STATUS;
8758
Jouni Malinenba630452018-06-22 11:49:59 +03008759 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008760 unlink("SP/wi-fi.org/pps.xml");
8761 if (system("rm -r SP/*") != 0) {
8762 }
8763 unlink("next-client-cert.pem");
8764 unlink("next-client-key.pem");
8765 }
8766
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008767 /* For WPS program of the 60 GHz band the band type needs to be saved */
8768 if (dut->program == PROGRAM_WPS) {
8769 if (band && strcasecmp(band, "60GHz") == 0) {
8770 dut->band = WPS_BAND_60G;
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02008771 /* For 60 GHz enable WPS for WPS TCs */
8772 dut->wps_disable = 0;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008773 } else {
8774 dut->band = WPS_BAND_NON_60G;
8775 }
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02008776 } else if (dut->program == PROGRAM_60GHZ) {
8777 /* For 60 GHz MAC/PHY TCs WPS must be disabled */
8778 dut->wps_disable = 1;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008779 }
8780
Alexei Avshalom Lazar157ba062018-12-23 16:15:26 +02008781 if (is_60g_sigma_dut(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008782 const char *dev_role = get_param(cmd, "DevRole");
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02008783 char buf[256];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008784
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02008785 sigma_dut_print(dut, DUT_MSG_INFO,
8786 "WPS 60 GHz program, wps_disable = %d",
8787 dut->wps_disable);
8788
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008789 if (!dev_role) {
8790 send_resp(dut, conn, SIGMA_ERROR,
8791 "errorCode,Missing DevRole argument");
8792 return 0;
8793 }
8794
8795 if (strcasecmp(dev_role, "STA") == 0)
8796 dut->dev_role = DEVROLE_STA;
8797 else if (strcasecmp(dev_role, "PCP") == 0)
8798 dut->dev_role = DEVROLE_PCP;
8799 else {
8800 send_resp(dut, conn, SIGMA_ERROR,
8801 "errorCode,Unknown DevRole");
8802 return 0;
8803 }
8804
8805 if (dut->device_type == STA_unknown) {
8806 sigma_dut_print(dut, DUT_MSG_ERROR,
8807 "Device type is not STA testbed or DUT");
8808 send_resp(dut, conn, SIGMA_ERROR,
8809 "errorCode,Unknown device type");
8810 return 0;
8811 }
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02008812
8813 sigma_dut_print(dut, DUT_MSG_DEBUG,
8814 "Setting msdu_size to MAX: 7912");
8815 snprintf(buf, sizeof(buf), "ifconfig %s mtu 7912",
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008816 get_station_ifname(dut));
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02008817
8818 if (system(buf) != 0) {
8819 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
8820 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02008821 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02008822 }
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02008823
8824 if (sta_set_force_mcs(dut, 0, 1)) {
8825 sigma_dut_print(dut, DUT_MSG_ERROR,
8826 "Failed to reset force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02008827 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02008828 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008829 }
8830
8831 wpa_command(intf, "WPS_ER_STOP");
8832 wpa_command(intf, "FLUSH");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05308833 wpa_command(intf, "ERP_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008834 wpa_command(intf, "SET radio_disabled 0");
8835
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02008836 dut->wps_forced_version = 0;
8837
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008838 if (dut->wsc_fragment) {
8839 dut->wsc_fragment = 0;
8840 wpa_command(intf, "SET device_name Test client");
8841 wpa_command(intf, "SET manufacturer ");
8842 wpa_command(intf, "SET model_name ");
8843 wpa_command(intf, "SET model_number ");
8844 wpa_command(intf, "SET serial_number ");
8845 }
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02008846 if (is_60g_sigma_dut(dut) && dut->force_rsn_ie) {
8847 dut->force_rsn_ie = FORCE_RSN_IE_NONE;
8848 sta_60g_force_rsn_ie(dut, FORCE_RSN_IE_NONE);
8849 }
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008850
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008851 if (dut->tmp_mac_addr && dut->set_macaddr) {
8852 dut->tmp_mac_addr = 0;
8853 if (system(dut->set_macaddr) != 0) {
8854 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to clear "
8855 "temporary MAC address");
8856 }
8857 }
8858
8859 set_ps(intf, dut, 0);
8860
Jouni Malinenba630452018-06-22 11:49:59 +03008861 if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2 ||
8862 dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008863 wpa_command(intf, "SET interworking 1");
8864 wpa_command(intf, "SET hs20 1");
8865 }
8866
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08008867 if (dut->program == PROGRAM_HS2_R2 ||
Jouni Malinenba630452018-06-22 11:49:59 +03008868 dut->program == PROGRAM_HS2_R3 ||
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08008869 dut->program == PROGRAM_OCE) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008870 wpa_command(intf, "SET pmf 1");
8871 } else {
8872 wpa_command(intf, "SET pmf 0");
8873 }
8874
8875 hs2_clear_credentials(intf);
8876 wpa_command(intf, "SET hessid 00:00:00:00:00:00");
8877 wpa_command(intf, "SET access_network_type 15");
8878
8879 static_ip_file(0, NULL, NULL, NULL);
8880 kill_dhcp_client(dut, intf);
8881 clear_ip_addr(dut, intf);
8882
8883 dut->er_oper_performed = 0;
8884 dut->er_oper_bssid[0] = '\0';
8885
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07008886 if (dut->program == PROGRAM_LOC) {
8887 /* Disable Interworking by default */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008888 wpa_command(get_station_ifname(dut), "SET interworking 0");
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07008889 }
8890
Kiran Kumar Lokeredd086642020-06-04 00:29:26 -07008891 if (dut->program == PROGRAM_MBO || dut->program == PROGRAM_HE) {
Ashwini Patil00402582017-04-13 12:29:39 +05308892 free(dut->non_pref_ch_list);
8893 dut->non_pref_ch_list = NULL;
Ashwini Patil5acd7382017-04-13 15:55:04 +05308894 free(dut->btm_query_cand_list);
8895 dut->btm_query_cand_list = NULL;
Ashwini Patilc63161e2017-04-13 16:30:23 +05308896 wpa_command(intf, "SET reject_btm_req_reason 0");
Ashwini Patila75de5a2017-04-13 16:35:05 +05308897 wpa_command(intf, "SET ignore_assoc_disallow 0");
Ashwini Patild174f2c2017-04-13 16:49:46 +05308898 wpa_command(intf, "SET gas_address3 0");
Ashwini Patil9183fdb2017-04-13 16:58:25 +05308899 wpa_command(intf, "SET roaming 1");
Ankita Bajaj1d974552018-09-18 16:56:44 +05308900 wpa_command(intf, "SET interworking 1");
Ashwini Patil00402582017-04-13 12:29:39 +05308901 }
8902
Jouni Malinen3c367e82017-06-23 17:01:47 +03008903 free(dut->rsne_override);
8904 dut->rsne_override = NULL;
8905
Jouni Malinen68143132017-09-02 02:34:08 +03008906 free(dut->sae_commit_override);
8907 dut->sae_commit_override = NULL;
Jouni Malinen4b3769d2019-10-10 16:20:29 +03008908 wpa_command(intf, "SET sae_pmkid_in_assoc 0");
Jouni Malinen11e55212019-11-22 21:46:59 +02008909 dut->sae_pwe = SAE_PWE_DEFAULT;
Jouni Malinen68143132017-09-02 02:34:08 +03008910
Jouni Malinen134fe3c2019-06-12 04:16:49 +03008911 dut->sta_associate_wait_connect = 0;
8912 dut->server_cert_hash[0] = '\0';
Jouni Malinen37d5c692019-08-19 16:56:55 +03008913 dut->server_cert_tod = 0;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03008914 dut->sta_tod_policy = 0;
8915
Jouni Malinend86e5822017-08-29 03:55:32 +03008916 dut->dpp_conf_id = -1;
Jouni Malinenb1dd21f2017-11-13 19:14:29 +02008917 free(dut->dpp_peer_uri);
8918 dut->dpp_peer_uri = NULL;
Jouni Malinen63d50412017-11-24 11:55:38 +02008919 dut->dpp_local_bootstrap = -1;
Jouni Malinen5011fb52017-12-05 21:00:15 +02008920 wpa_command(intf, "SET dpp_config_processing 2");
Jouni Malinen90776b12020-05-04 15:34:46 +03008921 wpa_command(intf, "SET dpp_mud_url ");
Jouni Malinend86e5822017-08-29 03:55:32 +03008922
Jouni Malinenfac9cad2017-10-10 18:35:55 +03008923 wpa_command(intf, "VENDOR_ELEM_REMOVE 13 *");
8924
vamsi krishnaa2799492017-12-05 14:28:01 +05308925 if (dut->program == PROGRAM_OCE) {
Ankita Bajaja2cb5672017-10-25 16:08:28 +05308926 wpa_command(intf, "SET oce 1");
vamsi krishnaa2799492017-12-05 14:28:01 +05308927 wpa_command(intf, "SET disable_fils 0");
Ankita Bajaj1bde7942018-01-09 19:15:01 +05308928 wpa_command(intf, "FILS_HLP_REQ_FLUSH");
8929 dut->fils_hlp = 0;
8930#ifdef ANDROID
8931 hlp_thread_cleanup(dut);
8932#endif /* ANDROID */
vamsi krishnaa2799492017-12-05 14:28:01 +05308933 }
Ankita Bajaja2cb5672017-10-25 16:08:28 +05308934
Veerendranath Jakkamea7f0692021-08-11 19:13:12 +05308935 if (dut->program == PROGRAM_QM) {
Vamsi Krishnaf642d6a2020-03-27 12:33:14 +05308936 wpa_command(intf, "SET interworking 1");
Veerendranath Jakkama16cdc82021-09-12 16:44:22 +05308937 wpa_command(intf, "SET enable_dscp_policy_capa 1");
Veerendranath Jakkam329a3cd2021-09-11 18:10:13 +05308938 dut->qm_domain_name[0] = '\0';
Veerendranath Jakkama16cdc82021-09-12 16:44:22 +05308939 dut->reject_dscp_policies = 0;
Veerendranath Jakkam1bf1bd62021-09-12 16:35:55 +05308940 dut->num_dscp_status = 0;
Veerendranath Jakkamea7f0692021-08-11 19:13:12 +05308941 snprintf(buf, sizeof(buf),
8942 "ip -6 route replace fe80::/64 dev %s table local",
8943 intf);
8944 if (system(buf) != 0)
8945 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run: %s",
8946 buf);
Veerendranath Jakkam9ceb3b12021-09-10 03:18:17 +05308947
8948 stop_dscp_policy_mon_thread(dut);
8949 clear_all_dscp_policies(dut);
Veerendranath Jakkamea7f0692021-08-11 19:13:12 +05308950 }
Vamsi Krishnaf642d6a2020-03-27 12:33:14 +05308951
Jouni Malinen8179fee2019-03-28 03:19:47 +02008952 dut->akm_values = 0;
Shivani Baranwal7aa48602021-09-29 10:53:38 +05308953
8954#ifdef NL80211_SUPPORT
8955 if (get_driver_type(dut) == DRIVER_WCN)
8956 sta_config_params(dut, intf, STA_SET_FT_DS, 0);
8957#endif /* NL80211_SUPPORT */
8958
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03008959 dut->sta_ft_ds = 0;
Jouni Malinen8179fee2019-03-28 03:19:47 +02008960
Sunil Dutt076081f2018-02-05 19:45:50 +05308961#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008962 if (get_driver_type(dut) == DRIVER_WCN &&
Sunil Dutt44595082018-02-12 19:41:45 +05308963 dut->config_rsnie == 1) {
8964 dut->config_rsnie = 0;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05308965 sta_config_params(dut, intf, STA_SET_RSNIE, 0);
Sunil Dutt076081f2018-02-05 19:45:50 +05308966 }
8967#endif /* NL80211_SUPPORT */
8968
Sunil Duttfebf8a82018-02-09 18:50:13 +05308969 if (dev_role && strcasecmp(dev_role, "STA-CFON") == 0) {
8970 dut->dev_role = DEVROLE_STA_CFON;
8971 return sta_cfon_reset_default(dut, conn, cmd);
8972 }
8973
Jouni Malinen439352d2018-09-13 03:42:23 +03008974 wpa_command(intf, "SET setband AUTO");
8975
Veerendranath Jakkamc1f71b62021-01-23 03:09:51 +05308976 ret = wpa_command_resp(intf, "GET_CAPABILITY ocv", resp, sizeof(resp));
8977 dut->ocvc = ret == 0 && strncmp(resp, "supported", 9) == 0;
8978
8979 ret = wpa_command_resp(intf, "GET_CAPABILITY beacon_prot", resp,
8980 sizeof(resp));
8981 dut->beacon_prot = ret == 0 && strncmp(resp, "supported", 9) == 0;
8982
Veerendranath Jakkam47867202020-12-21 01:53:52 +05308983 if (sta_set_client_privacy(dut, conn, intf,
8984 dut->program == PROGRAM_WPA3 &&
8985 dut->device_type == STA_dut &&
8986 dut->client_privacy_default)) {
8987 sigma_dut_print(dut, DUT_MSG_ERROR,
8988 "Failed to set client privacy functionality");
8989 /* sta_reset_default command is not really supposed to fail,
8990 * so allow this to continue. */
8991 }
8992
Veerendranath Jakkamca239592021-10-11 20:48:00 +05308993 if (get_driver_type(dut) == DRIVER_WCN)
8994 wcn_set_ignore_h2e_rsnxe(dut, intf, 0);
8995
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +05308996 dut->saquery_oci_freq = 0;
Shivani Baranwalebde8f62021-10-19 12:26:02 +05308997 dut->prev_disable_scs_support = 0;
8998 dut->prev_disable_mscs_support = 0;
Vamsi Krishnac1633d22020-05-06 18:31:21 +05308999
Sunil Duttfebf8a82018-02-09 18:50:13 +05309000 if (dut->program != PROGRAM_VHT)
9001 return cmd_sta_p2p_reset(dut, conn, cmd);
9002
Priyadharshini Gowthamana7dfd492015-11-09 14:34:08 -08009003 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009004}
9005
9006
Jouni Malinenf7222712019-06-13 01:50:21 +03009007static enum sigma_cmd_result cmd_sta_get_events(struct sigma_dut *dut,
9008 struct sigma_conn *conn,
9009 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009010{
9011 const char *program = get_param(cmd, "Program");
9012
9013 if (program == NULL)
9014 return -1;
9015#ifdef ANDROID_NAN
9016 if (strcasecmp(program, "NAN") == 0)
9017 return nan_cmd_sta_get_events(dut, conn, cmd);
9018#endif /* ANDROID_NAN */
9019 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
9020 return 0;
9021}
9022
9023
Jouni Malinen82905202018-04-29 17:20:10 +03009024static int sta_exec_action_url(struct sigma_dut *dut, struct sigma_conn *conn,
9025 struct sigma_cmd *cmd)
9026{
9027 const char *url = get_param(cmd, "url");
9028 const char *method = get_param(cmd, "method");
9029 pid_t pid;
9030 int status;
9031
9032 if (!url || !method)
9033 return -1;
9034
9035 /* TODO: Add support for method,post */
9036 if (strcasecmp(method, "get") != 0) {
9037 send_resp(dut, conn, SIGMA_ERROR,
9038 "ErrorCode,Unsupported method");
9039 return 0;
9040 }
9041
9042 pid = fork();
9043 if (pid < 0) {
9044 perror("fork");
9045 return -1;
9046 }
9047
9048 if (pid == 0) {
9049 char * argv[5] = { "wget", "-O", "/dev/null",
9050 (char *) url, NULL };
9051
9052 execv("/usr/bin/wget", argv);
9053 perror("execv");
9054 exit(0);
9055 return -1;
9056 }
9057
9058 if (waitpid(pid, &status, 0) < 0) {
9059 perror("waitpid");
9060 return -1;
9061 }
9062
9063 if (WIFEXITED(status)) {
9064 const char *errmsg;
9065
9066 if (WEXITSTATUS(status) == 0)
9067 return 1;
9068 sigma_dut_print(dut, DUT_MSG_INFO, "wget exit status %d",
9069 WEXITSTATUS(status));
9070 switch (WEXITSTATUS(status)) {
9071 case 4:
9072 errmsg = "errmsg,Network failure";
9073 break;
9074 case 8:
9075 errmsg = "errmsg,Server issued an error response";
9076 break;
9077 default:
9078 errmsg = "errmsg,Unknown failure from wget";
9079 break;
9080 }
9081 send_resp(dut, conn, SIGMA_ERROR, errmsg);
9082 return 0;
9083 }
9084
9085 send_resp(dut, conn, SIGMA_ERROR, "errmsg,Unknown failure");
9086 return 0;
9087}
9088
9089
Jouni Malinenf7222712019-06-13 01:50:21 +03009090static enum sigma_cmd_result cmd_sta_exec_action(struct sigma_dut *dut,
9091 struct sigma_conn *conn,
9092 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009093{
9094 const char *program = get_param(cmd, "Prog");
9095
Jouni Malinen82905202018-04-29 17:20:10 +03009096 if (program && !get_param(cmd, "interface"))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009097 return -1;
9098#ifdef ANDROID_NAN
Jouni Malinen82905202018-04-29 17:20:10 +03009099 if (program && strcasecmp(program, "NAN") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009100 return nan_cmd_sta_exec_action(dut, conn, cmd);
9101#endif /* ANDROID_NAN */
Jouni Malinen82905202018-04-29 17:20:10 +03009102
9103 if (program && strcasecmp(program, "Loc") == 0)
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07009104 return loc_cmd_sta_exec_action(dut, conn, cmd);
Jouni Malinen82905202018-04-29 17:20:10 +03009105
9106 if (get_param(cmd, "url"))
9107 return sta_exec_action_url(dut, conn, cmd);
9108
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009109 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
9110 return 0;
9111}
9112
9113
Jouni Malinenf7222712019-06-13 01:50:21 +03009114static enum sigma_cmd_result cmd_sta_set_11n(struct sigma_dut *dut,
9115 struct sigma_conn *conn,
9116 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009117{
9118 const char *intf = get_param(cmd, "Interface");
9119 const char *val, *mcs32, *rate;
9120
9121 val = get_param(cmd, "GREENFIELD");
9122 if (val) {
9123 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
9124 /* Enable GD */
9125 send_resp(dut, conn, SIGMA_ERROR,
9126 "ErrorCode,GF not supported");
9127 return 0;
9128 }
9129 }
9130
9131 val = get_param(cmd, "SGI20");
9132 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009133 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009134 case DRIVER_ATHEROS:
9135 ath_sta_set_sgi(dut, intf, val);
9136 break;
9137 default:
9138 send_resp(dut, conn, SIGMA_ERROR,
9139 "ErrorCode,SGI20 not supported");
9140 return 0;
9141 }
9142 }
9143
9144 mcs32 = get_param(cmd, "MCS32"); /* HT Duplicate Mode Enable/Disable */
9145 rate = get_param(cmd, "MCS_FIXEDRATE"); /* Fixed MCS rate (0..31) */
9146 if (mcs32 && rate) {
9147 /* TODO */
9148 send_resp(dut, conn, SIGMA_ERROR,
9149 "ErrorCode,MCS32,MCS_FIXEDRATE not supported");
9150 return 0;
9151 } else if (mcs32 && !rate) {
9152 /* TODO */
9153 send_resp(dut, conn, SIGMA_ERROR,
9154 "ErrorCode,MCS32 not supported");
9155 return 0;
9156 } else if (!mcs32 && rate) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009157 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009158 case DRIVER_ATHEROS:
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07009159 novap_reset(dut, intf, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009160 ath_sta_set_11nrates(dut, intf, rate);
9161 break;
9162 default:
9163 send_resp(dut, conn, SIGMA_ERROR,
9164 "ErrorCode,MCS32_FIXEDRATE not supported");
9165 return 0;
9166 }
9167 }
9168
9169 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
9170}
9171
9172
Arif Hussain7b47d2d2018-05-09 10:44:02 -07009173static void cmd_set_max_he_mcs(struct sigma_dut *dut, const char *intf,
9174 int mcs_config)
9175{
9176#ifdef NL80211_SUPPORT
9177 int ret;
9178
9179 switch (mcs_config) {
9180 case HE_80_MCS0_7:
9181 case HE_80_MCS0_9:
9182 case HE_80_MCS0_11:
9183 ret = sta_set_he_mcs(dut, intf, mcs_config);
9184 if (ret) {
9185 sigma_dut_print(dut, DUT_MSG_ERROR,
9186 "cmd_set_max_he_mcs: Setting of MCS:%d failed, ret:%d",
9187 mcs_config, ret);
9188 }
9189 break;
9190 default:
9191 sigma_dut_print(dut, DUT_MSG_ERROR,
9192 "cmd_set_max_he_mcs: Invalid mcs %d",
9193 mcs_config);
9194 break;
9195 }
9196#else /* NL80211_SUPPORT */
9197 sigma_dut_print(dut, DUT_MSG_ERROR,
9198 "max HE MCS cannot be changed without NL80211_SUPPORT defined");
9199#endif /* NL80211_SUPPORT */
9200}
9201
9202
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07009203struct wait_event {
9204 struct sigma_dut *dut;
9205 int cmd;
9206 unsigned int twt_op;
9207};
9208
9209#ifdef NL80211_SUPPORT
9210
9211static int twt_event_handler(struct nl_msg *msg, void *arg)
9212{
9213 struct wait_event *wait = arg;
9214 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
9215 struct nlattr *tb[NL80211_ATTR_MAX + 1];
9216 uint32_t subcmd;
9217 uint8_t *data = NULL;
9218 size_t len = 0;
9219 struct nlattr *twt_rsp[QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_MAX + 1];
9220 struct nlattr *twt_status[QCA_WLAN_VENDOR_ATTR_TWT_SETUP_MAX + 1];
9221 int cmd_id;
9222 unsigned char val;
9223
9224 if (!wait)
9225 return NL_SKIP;
9226
9227 if (gnlh->cmd != NL80211_CMD_VENDOR) {
9228 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9229 "%s: NL cmd is not vendor %d", __func__,
9230 gnlh->cmd);
9231 return NL_SKIP;
9232 }
9233
9234 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
9235 genlmsg_attrlen(gnlh, 0), NULL);
9236
9237 if (!tb[NL80211_ATTR_VENDOR_ID] || !tb[NL80211_ATTR_VENDOR_SUBCMD]) {
9238 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9239 "%s: vendor ID not found", __func__);
9240 return NL_SKIP;
9241 }
9242 subcmd = nla_get_u32(tb[NL80211_ATTR_VENDOR_SUBCMD]);
9243
9244 if (subcmd != QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) {
9245 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9246 "%s: Not a TWT_cmd %d", __func__, subcmd);
9247 return NL_SKIP;
9248 }
9249 if (tb[NL80211_ATTR_VENDOR_DATA]) {
9250 data = nla_data(tb[NL80211_ATTR_VENDOR_DATA]);
9251 len = nla_len(tb[NL80211_ATTR_VENDOR_DATA]);
9252 } else {
9253 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9254 "%s: vendor data not present", __func__);
9255 return NL_SKIP;
9256 }
9257 if (!data || !len) {
9258 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9259 "Invalid vendor data or len");
9260 return NL_SKIP;
9261 }
9262 sigma_dut_print(wait->dut, DUT_MSG_DEBUG,
9263 "event data len %ld", len);
9264 hex_dump(wait->dut, data, len);
9265 if (nla_parse(twt_rsp, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_MAX,
9266 (struct nlattr *) data, len, NULL)) {
9267 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9268 "vendor data parse error");
9269 return NL_SKIP;
9270 }
9271
9272 val = nla_get_u8(twt_rsp[QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION]);
9273 if (val != wait->twt_op) {
9274 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9275 "Invalid TWT operation, expected %d, rcvd %d",
9276 wait->twt_op, val);
9277 return NL_SKIP;
9278 }
9279 if (nla_parse_nested(twt_status, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_MAX,
9280 twt_rsp[QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS],
9281 NULL)) {
9282 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9283 "nla_parse failed for TWT event");
9284 return NL_SKIP;
9285 }
9286
9287 cmd_id = QCA_WLAN_VENDOR_ATTR_TWT_SETUP_STATUS;
9288 if (!twt_status[cmd_id]) {
9289 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9290 "%s TWT resp status missing", __func__);
9291 wait->cmd = -1;
9292 } else {
9293 val = nla_get_u8(twt_status[cmd_id]);
9294 if (val != QCA_WLAN_VENDOR_TWT_STATUS_OK) {
9295 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9296 "%s TWT resp status %d", __func__, val);
9297 wait->cmd = -1;
9298 } else {
9299 wait->cmd = 1;
9300 }
9301 }
9302
9303 return NL_SKIP;
9304}
9305
9306
9307static int wait_on_nl_socket(struct nl_sock *sock, struct sigma_dut *dut,
9308 unsigned int timeout)
9309{
9310 fd_set read_fd_set;
9311 int retval;
9312 int sock_fd;
9313 struct timeval time_out;
9314
9315 time_out.tv_sec = timeout;
9316 time_out.tv_usec = 0;
9317
9318 FD_ZERO(&read_fd_set);
9319
9320 if (!sock)
9321 return -1;
9322
9323 sock_fd = nl_socket_get_fd(sock);
9324 FD_SET(sock_fd, &read_fd_set);
9325
9326 retval = select(sock_fd + 1, &read_fd_set, NULL, NULL, &time_out);
9327
9328 if (retval == 0)
9329 sigma_dut_print(dut, DUT_MSG_ERROR,
9330 "%s: TWT event response timedout", __func__);
9331
9332 if (retval < 0)
9333 sigma_dut_print(dut, DUT_MSG_ERROR, "%s:no NL msgs, ret=%d",
9334 __func__, retval);
9335
9336 return retval;
9337}
9338
9339
9340#define TWT_ASYNC_EVENT_WAIT_TIME_SEC 6
9341
9342static int twt_async_event_wait(struct sigma_dut *dut, unsigned int twt_op)
9343{
9344 struct nl_cb *cb;
9345 int err_code = 0, select_retval = 0;
9346 struct wait_event wait_info;
9347
9348 cb = nl_socket_get_cb(dut->nl_ctx->event_sock);
9349 if (!cb) {
9350 sigma_dut_print(dut, DUT_MSG_ERROR,
9351 "event callback not found");
9352 return ERROR_SEND_STATUS;
9353 }
9354
9355 wait_info.cmd = 0;
9356 wait_info.dut = dut;
9357 wait_info.twt_op = twt_op;
9358
9359 nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, twt_event_handler, &wait_info);
9360
9361 while (!wait_info.cmd) {
9362 select_retval = wait_on_nl_socket(
9363 dut->nl_ctx->event_sock, dut,
9364 TWT_ASYNC_EVENT_WAIT_TIME_SEC);
9365
9366 if (select_retval > 0) {
9367 err_code = nl_recvmsgs(dut->nl_ctx->event_sock, cb);
9368 if (err_code < 0) {
9369 sigma_dut_print(dut, DUT_MSG_ERROR,
9370 "%s: nl rcv failed, err_code %d",
9371 __func__, err_code);
9372 break;
9373 }
9374 } else {
9375 sigma_dut_print(dut, DUT_MSG_ERROR,
9376 "%s: wait on socket failed %d",
9377 __func__, select_retval);
9378 err_code = 1;
9379 break;
9380 }
9381
9382 }
9383 nl_cb_put(cb);
9384
9385 if (wait_info.cmd < 0)
9386 err_code = 1;
9387
9388 sigma_dut_print(dut, DUT_MSG_DEBUG,
9389 "%s: rcvd cmd %d, err_code %d, s_ret %d",
9390 __func__, wait_info.cmd, err_code, select_retval);
9391
9392 return err_code;
9393}
9394
9395#endif /* NL80211_SUPPORT */
9396
9397
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009398static int sta_twt_send_suspend(struct sigma_dut *dut, struct sigma_conn *conn,
9399 struct sigma_cmd *cmd)
9400{
9401#ifdef NL80211_SUPPORT
9402 struct nlattr *attr, *attr1;
9403 struct nl_msg *msg;
9404 int ifindex, ret;
9405 const char *intf = get_param(cmd, "Interface");
9406
9407 ifindex = if_nametoindex(intf);
9408 if (ifindex == 0) {
9409 sigma_dut_print(dut, DUT_MSG_ERROR,
9410 "%s: Index for interface %s failed",
9411 __func__, intf);
9412 return ERROR_SEND_STATUS;
9413 }
9414
9415 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9416 NL80211_CMD_VENDOR)) ||
9417 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9418 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9419 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9420 QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) ||
9421 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9422 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION,
9423 QCA_WLAN_TWT_SUSPEND) ||
9424 !(attr1 = nla_nest_start(msg,
Kiran Kumar Lokere7ede00c2021-08-09 00:59:52 -07009425 QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS))) {
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009426 sigma_dut_print(dut, DUT_MSG_ERROR,
9427 "%s: err in adding vendor_cmd and vendor_data",
9428 __func__);
9429 nlmsg_free(msg);
9430 return ERROR_SEND_STATUS;
9431 }
9432 nla_nest_end(msg, attr1);
9433 nla_nest_end(msg, attr);
9434
9435 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9436 if (ret) {
9437 sigma_dut_print(dut, DUT_MSG_ERROR,
9438 "%s: err in send_and_recv_msgs, ret=%d",
9439 __func__, ret);
9440 }
9441
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07009442 if (!dut->sta_async_twt_supp)
9443 return ret;
9444
9445 return twt_async_event_wait(dut, QCA_WLAN_TWT_SUSPEND);
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009446#else /* NL80211_SUPPORT */
9447 sigma_dut_print(dut, DUT_MSG_ERROR,
9448 "TWT suspend cannot be done without NL80211_SUPPORT defined");
9449 return ERROR_SEND_STATUS;
9450#endif /* NL80211_SUPPORT */
9451}
9452
9453
9454static int sta_twt_send_nudge(struct sigma_dut *dut, struct sigma_conn *conn,
9455 struct sigma_cmd *cmd,
9456 unsigned int suspend_duration)
9457{
9458#ifdef NL80211_SUPPORT
9459 struct nlattr *attr, *attr1;
9460 struct nl_msg *msg;
9461 int ifindex, ret;
9462 const char *intf = get_param(cmd, "Interface");
9463 int next_twt_size = 1;
9464
9465 ifindex = if_nametoindex(intf);
9466 if (ifindex == 0) {
9467 sigma_dut_print(dut, DUT_MSG_ERROR,
9468 "%s: Index for interface %s failed",
9469 __func__, intf);
9470 return ERROR_SEND_STATUS;
9471 }
9472
9473 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9474 NL80211_CMD_VENDOR)) ||
9475 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9476 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9477 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9478 QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) ||
9479 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9480 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION,
9481 QCA_WLAN_TWT_NUDGE) ||
9482 !(attr1 = nla_nest_start(msg,
9483 QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS)) ||
9484 (suspend_duration &&
9485 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_NUDGE_WAKE_TIME,
9486 suspend_duration)) ||
9487 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_NUDGE_NEXT_TWT_SIZE,
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -07009488 next_twt_size) ||
9489 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_NUDGE_FLOW_ID, 0)) {
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009490 sigma_dut_print(dut, DUT_MSG_ERROR,
9491 "%s: err in adding vendor_cmd and vendor_data",
9492 __func__);
9493 nlmsg_free(msg);
9494 return ERROR_SEND_STATUS;
9495 }
9496 nla_nest_end(msg, attr1);
9497 nla_nest_end(msg, attr);
9498
9499 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9500 if (ret) {
9501 sigma_dut_print(dut, DUT_MSG_ERROR,
9502 "%s: err in send_and_recv_msgs, ret=%d",
9503 __func__, ret);
9504 }
9505
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07009506 if (!dut->sta_async_twt_supp)
9507 return ret;
9508
9509 return twt_async_event_wait(dut, QCA_WLAN_TWT_NUDGE);
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009510#else /* NL80211_SUPPORT */
9511 sigma_dut_print(dut, DUT_MSG_ERROR,
9512 "TWT suspend cannot be done without NL80211_SUPPORT defined");
9513 return ERROR_SEND_STATUS;
9514#endif /* NL80211_SUPPORT */
9515}
9516
9517
9518static int sta_twt_suspend_or_nudge(struct sigma_dut *dut,
9519 struct sigma_conn *conn,
9520 struct sigma_cmd *cmd)
9521{
9522 const char *val;
9523
9524 val = get_param(cmd, "TWT_SuspendDuration");
9525 if (val) {
9526 unsigned int suspend_duration;
9527
9528 suspend_duration = atoi(val);
9529 suspend_duration = suspend_duration * 1000 * 1000;
9530 return sta_twt_send_nudge(dut, conn, cmd, suspend_duration);
9531 }
9532
9533 return sta_twt_send_suspend(dut, conn, cmd);
9534}
9535
9536
9537static int sta_twt_resume(struct sigma_dut *dut, struct sigma_conn *conn,
9538 struct sigma_cmd *cmd)
9539{
9540#ifdef NL80211_SUPPORT
9541 struct nlattr *attr, *attr1;
9542 struct nl_msg *msg;
9543 int ifindex, ret;
9544 const char *intf = get_param(cmd, "Interface");
9545 int next2_twt_size = 1;
9546 unsigned int resume_duration = 0;
9547 const char *val;
9548
9549 ifindex = if_nametoindex(intf);
9550 if (ifindex == 0) {
9551 sigma_dut_print(dut, DUT_MSG_ERROR,
9552 "%s: Index for interface %s failed",
9553 __func__, intf);
9554 return ERROR_SEND_STATUS;
9555 }
9556
9557 val = get_param(cmd, "TWT_ResumeDuration");
9558 if (val) {
9559 resume_duration = atoi(val);
9560 resume_duration = resume_duration * 1000 * 1000;
9561 }
9562
9563 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9564 NL80211_CMD_VENDOR)) ||
9565 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9566 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9567 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9568 QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) ||
9569 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9570 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION,
9571 QCA_WLAN_TWT_RESUME) ||
9572 !(attr1 = nla_nest_start(msg,
9573 QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS)) ||
9574 (resume_duration &&
9575 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_RESUME_NEXT2_TWT,
9576 resume_duration)) ||
9577 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_RESUME_NEXT_TWT_SIZE,
9578 next2_twt_size)) {
9579 sigma_dut_print(dut, DUT_MSG_ERROR,
9580 "%s: err in adding vendor_cmd and vendor_data",
9581 __func__);
9582 nlmsg_free(msg);
9583 return ERROR_SEND_STATUS;
9584 }
9585 nla_nest_end(msg, attr1);
9586 nla_nest_end(msg, attr);
9587
9588 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9589 if (ret) {
9590 sigma_dut_print(dut, DUT_MSG_ERROR,
9591 "%s: err in send_and_recv_msgs, ret=%d",
9592 __func__, ret);
9593 }
9594
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07009595 if (!dut->sta_async_twt_supp)
9596 return ret;
9597
9598 return twt_async_event_wait(dut, QCA_WLAN_TWT_RESUME);
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009599#else /* NL80211_SUPPORT */
9600 sigma_dut_print(dut, DUT_MSG_ERROR,
9601 "TWT resume cannot be done without NL80211_SUPPORT defined");
9602 return ERROR_SEND_STATUS;
9603#endif /* NL80211_SUPPORT */
9604}
9605
9606
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07009607#define TWT_REQUEST_CMD 0
9608#define TWT_SUGGEST_CMD 1
9609#define TWT_DEMAND_CMD 2
9610
Arif Hussain480d5f42019-03-12 14:40:42 -07009611static int sta_twt_request(struct sigma_dut *dut, struct sigma_conn *conn,
9612 struct sigma_cmd *cmd)
9613{
9614#ifdef NL80211_SUPPORT
9615 struct nlattr *params;
9616 struct nlattr *attr;
Arif Hussain480d5f42019-03-12 14:40:42 -07009617 struct nl_msg *msg;
9618 int ifindex, ret;
9619 const char *val;
9620 const char *intf = get_param(cmd, "Interface");
9621 int wake_interval_exp = 10, nominal_min_wake_dur = 255,
9622 wake_interval_mantissa = 512;
9623 int flow_type = 0, twt_trigger = 0, target_wake_time = 0,
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07009624 protection = 0, cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_SUGGEST;
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -07009625 int bcast_twt = 0;
9626 int bcast_twt_id = 0, bcast_twt_recommdn = 0, bcast_twt_persis = 0;
Arif Hussain480d5f42019-03-12 14:40:42 -07009627
9628 ifindex = if_nametoindex(intf);
9629 if (ifindex == 0) {
9630 sigma_dut_print(dut, DUT_MSG_ERROR,
9631 "%s: Index for interface %s failed",
9632 __func__, intf);
9633 return -1;
9634 }
9635
9636 val = get_param(cmd, "FlowType");
9637 if (val) {
9638 flow_type = atoi(val);
9639 if (flow_type != 0 && flow_type != 1) {
9640 sigma_dut_print(dut, DUT_MSG_ERROR,
9641 "TWT: Invalid FlowType %d", flow_type);
9642 return -1;
9643 }
9644 }
9645
9646 val = get_param(cmd, "TWT_Trigger");
9647 if (val) {
9648 twt_trigger = atoi(val);
9649 if (twt_trigger != 0 && twt_trigger != 1) {
9650 sigma_dut_print(dut, DUT_MSG_ERROR,
9651 "TWT: Invalid TWT_Trigger %d",
9652 twt_trigger);
9653 return -1;
9654 }
9655 }
9656
9657 val = get_param(cmd, "Protection");
9658 if (val) {
9659 protection = atoi(val);
9660 if (protection != 0 && protection != 1) {
9661 sigma_dut_print(dut, DUT_MSG_ERROR,
9662 "TWT: Invalid Protection %d",
9663 protection);
9664 return -1;
9665 }
9666 }
9667
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07009668 val = get_param(cmd, "SetupCommand");
9669 if (val) {
9670 cmd_type = atoi(val);
9671 if (cmd_type == TWT_REQUEST_CMD)
9672 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_REQUEST;
9673 else if (cmd_type == TWT_SUGGEST_CMD)
9674 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_SUGGEST;
9675 else if (cmd_type == TWT_DEMAND_CMD)
9676 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_DEMAND;
9677 else
9678 sigma_dut_print(dut, DUT_MSG_ERROR,
9679 "Default suggest is used for cmd %d",
9680 cmd_type);
9681 }
9682
Arif Hussain480d5f42019-03-12 14:40:42 -07009683 val = get_param(cmd, "TargetWakeTime");
9684 if (val)
9685 target_wake_time = atoi(val);
9686
9687 val = get_param(cmd, "WakeIntervalMantissa");
9688 if (val)
9689 wake_interval_mantissa = atoi(val);
9690
9691 val = get_param(cmd, "WakeIntervalExp");
9692 if (val)
9693 wake_interval_exp = atoi(val);
9694
9695 val = get_param(cmd, "NominalMinWakeDur");
9696 if (val)
9697 nominal_min_wake_dur = atoi(val);
9698
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -07009699 val = get_param(cmd, "BTWT_ID");
9700 if (val) {
9701 bcast_twt_id = atoi(val);
9702 bcast_twt = 1;
9703 }
9704
9705 val = get_param(cmd, "BTWT_Persistence");
9706 if (val) {
9707 bcast_twt_persis = atoi(val);
9708 bcast_twt = 1;
9709 }
9710
9711 val = get_param(cmd, "BTWT_Recommendation");
9712 if (val) {
9713 bcast_twt_recommdn = atoi(val);
9714 bcast_twt = 1;
9715 }
9716
9717 if (bcast_twt)
9718 sigma_dut_print(dut, DUT_MSG_DEBUG,
9719 "BCAST_TWT: ID %d, RECOMM %d, PERSIS %d",
9720 bcast_twt_id, bcast_twt_recommdn,
9721 bcast_twt_persis);
9722
Arif Hussain480d5f42019-03-12 14:40:42 -07009723 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9724 NL80211_CMD_VENDOR)) ||
9725 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9726 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9727 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009728 QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07009729 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009730 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION,
9731 QCA_WLAN_TWT_SET) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07009732 !(params = nla_nest_start(
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009733 msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07009734 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_EXP,
9735 wake_interval_exp) ||
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07009736 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_REQ_TYPE, cmd_type) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -07009737 (twt_trigger &&
9738 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_TRIGGER)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07009739 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE,
9740 flow_type) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -07009741 (protection &&
9742 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_PROTECTION)) ||
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -07009743 (bcast_twt &&
9744 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_BCAST)) ||
9745 (bcast_twt &&
9746 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_BCAST_ID,
9747 bcast_twt_id)) ||
9748 (bcast_twt &&
9749 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_BCAST_PERSISTENCE,
9750 bcast_twt_persis)) ||
9751 (bcast_twt &&
9752 nla_put_u8(msg,
9753 QCA_WLAN_VENDOR_ATTR_TWT_SETUP_BCAST_RECOMMENDATION,
9754 bcast_twt_recommdn)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07009755 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_TIME,
9756 target_wake_time) ||
9757 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_DURATION,
9758 nominal_min_wake_dur) ||
9759 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_MANTISSA,
9760 wake_interval_mantissa)) {
9761 sigma_dut_print(dut, DUT_MSG_ERROR,
9762 "%s: err in adding vendor_cmd and vendor_data",
9763 __func__);
9764 nlmsg_free(msg);
9765 return -1;
9766 }
Arif Hussain480d5f42019-03-12 14:40:42 -07009767 nla_nest_end(msg, params);
9768 nla_nest_end(msg, attr);
9769
9770 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9771 if (ret) {
9772 sigma_dut_print(dut, DUT_MSG_ERROR,
9773 "%s: err in send_and_recv_msgs, ret=%d",
9774 __func__, ret);
9775 }
9776
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07009777 if (!dut->sta_async_twt_supp)
9778 return ret;
9779
9780 return twt_async_event_wait(dut, QCA_WLAN_TWT_SET);
Arif Hussain480d5f42019-03-12 14:40:42 -07009781#else /* NL80211_SUPPORT */
9782 sigma_dut_print(dut, DUT_MSG_ERROR,
9783 "TWT request cannot be done without NL80211_SUPPORT defined");
9784 return -1;
9785#endif /* NL80211_SUPPORT */
9786}
9787
9788
9789static int sta_twt_teardown(struct sigma_dut *dut, struct sigma_conn *conn,
9790 struct sigma_cmd *cmd)
9791{
9792 #ifdef NL80211_SUPPORT
9793 struct nlattr *params;
9794 struct nlattr *attr;
Arif Hussain480d5f42019-03-12 14:40:42 -07009795 int ifindex, ret;
9796 struct nl_msg *msg;
9797 const char *intf = get_param(cmd, "Interface");
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -07009798 int bcast_twt = 0;
9799 int bcast_twt_id = 0;
9800 const char *val;
Arif Hussain480d5f42019-03-12 14:40:42 -07009801
9802 ifindex = if_nametoindex(intf);
9803 if (ifindex == 0) {
9804 sigma_dut_print(dut, DUT_MSG_ERROR,
9805 "%s: Index for interface %s failed",
9806 __func__, intf);
9807 return -1;
9808 }
9809
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -07009810 val = get_param(cmd, "BTWT_ID");
9811 if (val) {
9812 bcast_twt_id = atoi(val);
9813 bcast_twt = 1;
9814 }
9815
Arif Hussain480d5f42019-03-12 14:40:42 -07009816 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9817 NL80211_CMD_VENDOR)) ||
9818 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9819 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9820 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009821 QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07009822 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009823 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION,
9824 QCA_WLAN_TWT_TERMINATE) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07009825 !(params = nla_nest_start(
9826 msg,
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009827 QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS)) ||
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -07009828 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE, 0) ||
9829 (bcast_twt &&
9830 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_BCAST)) ||
9831 (bcast_twt &&
9832 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_BCAST_ID,
9833 bcast_twt_id))) {
Arif Hussain480d5f42019-03-12 14:40:42 -07009834 sigma_dut_print(dut, DUT_MSG_ERROR,
9835 "%s: err in adding vendor_cmd and vendor_data",
9836 __func__);
9837 nlmsg_free(msg);
9838 return -1;
9839 }
Arif Hussain480d5f42019-03-12 14:40:42 -07009840 nla_nest_end(msg, params);
9841 nla_nest_end(msg, attr);
9842
9843 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9844 if (ret) {
9845 sigma_dut_print(dut, DUT_MSG_ERROR,
9846 "%s: err in send_and_recv_msgs, ret=%d",
9847 __func__, ret);
9848 }
9849
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07009850 if (!dut->sta_async_twt_supp)
9851 return ret;
9852
9853 return twt_async_event_wait(dut, QCA_WLAN_TWT_TERMINATE);
Arif Hussain480d5f42019-03-12 14:40:42 -07009854#else /* NL80211_SUPPORT */
9855 sigma_dut_print(dut, DUT_MSG_ERROR,
9856 "TWT teardown cannot be done without NL80211_SUPPORT defined");
9857 return -1;
9858#endif /* NL80211_SUPPORT */
9859}
9860
9861
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -08009862static int sta_transmit_omi(struct sigma_dut *dut, struct sigma_conn *conn,
9863 struct sigma_cmd *cmd)
9864{
9865#ifdef NL80211_SUPPORT
9866 struct nlattr *params;
9867 struct nlattr *attr;
9868 struct nlattr *attr1;
9869 struct nl_msg *msg;
9870 int ifindex, ret;
9871 const char *val;
9872 const char *intf = get_param(cmd, "Interface");
9873 uint8_t rx_nss = 0xFF, ch_bw = 0xFF, tx_nsts = 0xFF, ulmu_dis = 0,
9874 ulmu_data_dis = 0;
9875
9876 ifindex = if_nametoindex(intf);
9877 if (ifindex == 0) {
9878 sigma_dut_print(dut, DUT_MSG_ERROR,
9879 "%s: Index for interface %s failed",
9880 __func__, intf);
9881 return -1;
9882 }
9883 val = get_param(cmd, "OMCtrl_RxNSS");
9884 if (val)
9885 rx_nss = atoi(val);
9886
9887 val = get_param(cmd, "OMCtrl_ChnlWidth");
9888 if (val)
9889 ch_bw = atoi(val);
9890
9891 val = get_param(cmd, "OMCtrl_ULMUDisable");
9892 if (val)
9893 ulmu_dis = atoi(val);
9894
9895 val = get_param(cmd, "OMCtrl_TxNSTS");
9896 if (val)
9897 tx_nsts = atoi(val);
9898
9899 val = get_param(cmd, "OMCtrl_ULMUDataDisable");
9900 if (val)
9901 ulmu_data_dis = atoi(val);
9902
9903 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9904 NL80211_CMD_VENDOR)) ||
9905 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9906 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9907 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9908 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
9909 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9910 !(params = nla_nest_start(
9911 msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OMI_TX)) ||
9912 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9913 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_RX_NSS, rx_nss) ||
9914 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_CH_BW, ch_bw) ||
9915 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_TX_NSTS, tx_nsts) ||
9916 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DATA_DISABLE,
9917 ulmu_data_dis) ||
9918 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DISABLE,
9919 ulmu_dis)) {
9920 sigma_dut_print(dut, DUT_MSG_ERROR,
9921 "%s: err in adding vendor_cmd and vendor_data",
9922 __func__);
9923 nlmsg_free(msg);
9924 return -1;
9925 }
9926 nla_nest_end(msg, attr1);
9927 nla_nest_end(msg, params);
9928 nla_nest_end(msg, attr);
9929
9930 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9931 if (ret) {
9932 sigma_dut_print(dut, DUT_MSG_ERROR,
9933 "%s: err in send_and_recv_msgs, ret=%d",
9934 __func__, ret);
9935 }
9936
9937 return ret;
9938#else /* NL80211_SUPPORT */
9939 sigma_dut_print(dut, DUT_MSG_ERROR,
9940 "OMI TX cannot be processed without NL80211_SUPPORT defined");
9941 return -1;
9942#endif /* NL80211_SUPPORT */
9943}
9944
9945
Jouni Malinen224e3902021-06-09 16:41:27 +03009946static enum sigma_cmd_result
9947cmd_sta_set_wireless_vht(struct sigma_dut *dut, struct sigma_conn *conn,
9948 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009949{
9950 const char *intf = get_param(cmd, "Interface");
9951 const char *val;
Arif Hussaina37e9552018-06-20 17:05:59 -07009952 const char *program;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009953 int tkip = -1;
9954 int wep = -1;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05309955 int iwpriv_status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009956
Arif Hussaina37e9552018-06-20 17:05:59 -07009957 program = get_param(cmd, "Program");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009958 val = get_param(cmd, "SGI80");
9959 if (val) {
9960 int sgi80;
9961
9962 sgi80 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009963 run_iwpriv(dut, intf, "shortgi %d", sgi80);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009964 }
9965
9966 val = get_param(cmd, "TxBF");
9967 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009968 switch (get_driver_type(dut)) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009969 case DRIVER_WCN:
9970 if (sta_set_tx_beamformee(dut, intf, 1)) {
9971 send_resp(dut, conn, SIGMA_ERROR,
9972 "ErrorCode,Failed to set TX beamformee enable");
Jouni Malinen224e3902021-06-09 16:41:27 +03009973 return STATUS_SENT_ERROR;
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009974 }
9975 break;
9976 case DRIVER_ATHEROS:
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009977 if (run_iwpriv(dut, intf, "vhtsubfee 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009978 send_resp(dut, conn, SIGMA_ERROR,
9979 "ErrorCode,Setting vhtsubfee failed");
Jouni Malinen224e3902021-06-09 16:41:27 +03009980 return STATUS_SENT_ERROR;
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009981 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009982 if (run_iwpriv(dut, intf, "vhtsubfer 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009983 send_resp(dut, conn, SIGMA_ERROR,
9984 "ErrorCode,Setting vhtsubfer failed");
Jouni Malinen224e3902021-06-09 16:41:27 +03009985 return STATUS_SENT_ERROR;
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009986 }
9987 break;
9988 default:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009989 sigma_dut_print(dut, DUT_MSG_ERROR,
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009990 "Unsupported driver type");
9991 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009992 }
9993 }
9994
9995 val = get_param(cmd, "MU_TxBF");
9996 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009997 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009998 case DRIVER_ATHEROS:
9999 ath_sta_set_txsp_stream(dut, intf, "1SS");
10000 ath_sta_set_rxsp_stream(dut, intf, "1SS");
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010001 run_iwpriv(dut, intf, "vhtmubfee 1");
10002 run_iwpriv(dut, intf, "vhtmubfer 1");
Sunil Duttae9e5d12018-06-29 11:50:47 +053010003 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010004 case DRIVER_WCN:
10005 if (wcn_sta_set_sp_stream(dut, intf, "1SS") < 0) {
10006 send_resp(dut, conn, SIGMA_ERROR,
10007 "ErrorCode,Failed to set RX/TXSP_STREAM");
Jouni Malinen224e3902021-06-09 16:41:27 +030010008 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010009 }
Sunil Duttae9e5d12018-06-29 11:50:47 +053010010 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010011 default:
10012 sigma_dut_print(dut, DUT_MSG_ERROR,
10013 "Setting SP_STREAM not supported");
10014 break;
10015 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010016 }
10017
10018 val = get_param(cmd, "LDPC");
10019 if (val) {
10020 int ldpc;
10021
10022 ldpc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +053010023 iwpriv_status = run_iwpriv(dut, intf, "ldpc %d", ldpc);
10024 if (iwpriv_status)
10025 sta_config_params(dut, intf, STA_SET_LDPC, ldpc);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010026 }
10027
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -080010028 val = get_param(cmd, "BCC");
10029 if (val) {
10030 int bcc;
10031
10032 bcc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
10033 /* use LDPC iwpriv itself to set bcc coding, bcc coding
10034 * is mutually exclusive to bcc */
Mohammad Asaad Akram50848402020-05-28 14:10:24 +053010035 iwpriv_status = run_iwpriv(dut, intf, "ldpc %d", !bcc);
10036 if (iwpriv_status)
10037 sta_config_params(dut, intf, STA_SET_LDPC, !bcc);
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -080010038 }
10039
Arif Hussain7b47d2d2018-05-09 10:44:02 -070010040 val = get_param(cmd, "MaxHE-MCS_1SS_RxMapLTE80");
10041 if (val && dut->sta_nss == 1)
10042 cmd_set_max_he_mcs(dut, intf, atoi(val));
10043
10044 val = get_param(cmd, "MaxHE-MCS_2SS_RxMapLTE80");
10045 if (val && dut->sta_nss == 2)
10046 cmd_set_max_he_mcs(dut, intf, atoi(val));
10047
Arif Hussainac6c5112018-05-25 17:34:00 -070010048 val = get_param(cmd, "MCS_FixedRate");
10049 if (val) {
10050#ifdef NL80211_SUPPORT
10051 int mcs, ratecode = 0;
10052 enum he_mcs_config mcs_config;
10053 int ret;
Jouni Malinenb9b671d2019-04-26 13:23:17 +030010054 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -070010055
10056 ratecode = (0x07 & dut->sta_nss) << 5;
10057 mcs = atoi(val);
10058 /* Add the MCS to the ratecode */
10059 if (mcs >= 0 && mcs <= 11) {
10060 ratecode += mcs;
10061 if (dut->device_type == STA_testbed &&
10062 mcs > 7 && mcs <= 11) {
10063 if (mcs <= 9)
10064 mcs_config = HE_80_MCS0_9;
10065 else
10066 mcs_config = HE_80_MCS0_11;
10067 ret = sta_set_he_mcs(dut, intf, mcs_config);
10068 if (ret) {
10069 sigma_dut_print(dut, DUT_MSG_ERROR,
10070 "MCS_FixedRate: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
10071 mcs, mcs_config, ret);
10072 }
10073 }
10074 snprintf(buf, sizeof(buf),
10075 "iwpriv %s set_11ax_rate 0x%03x",
10076 intf, ratecode);
10077 if (system(buf) != 0) {
10078 sigma_dut_print(dut, DUT_MSG_ERROR,
10079 "MCS_FixedRate: iwpriv setting of 11ax rates 0x%03x failed",
10080 ratecode);
10081 }
10082 } else {
10083 sigma_dut_print(dut, DUT_MSG_ERROR,
10084 "MCS_FixedRate: HE MCS %d not supported",
10085 mcs);
10086 }
10087#else /* NL80211_SUPPORT */
10088 sigma_dut_print(dut, DUT_MSG_ERROR,
10089 "MCS_FixedRate cannot be changed without NL80211_SUPPORT defined");
10090#endif /* NL80211_SUPPORT */
10091 }
10092
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010093 val = get_param(cmd, "opt_md_notif_ie");
10094 if (val) {
10095 char *result = NULL;
10096 char delim[] = ";";
10097 char token[30];
10098 int value, config_val = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010099 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010100
Peng Xub8fc5cc2017-05-10 17:27:28 -070010101 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010102 result = strtok_r(token, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010103
10104 /* Extract the NSS information */
10105 if (result) {
10106 value = atoi(result);
10107 switch (value) {
10108 case 1:
10109 config_val = 1;
10110 break;
10111 case 2:
10112 config_val = 3;
10113 break;
10114 case 3:
10115 config_val = 7;
10116 break;
10117 case 4:
10118 config_val = 15;
10119 break;
10120 default:
10121 config_val = 3;
10122 break;
10123 }
10124
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010125 run_iwpriv(dut, intf, "rxchainmask %d", config_val);
10126 run_iwpriv(dut, intf, "txchainmask %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010127
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010128 }
10129
10130 /* Extract the channel width information */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010131 result = strtok_r(NULL, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010132 if (result) {
10133 value = atoi(result);
10134 switch (value) {
10135 case 20:
10136 config_val = 0;
10137 break;
10138 case 40:
10139 config_val = 1;
10140 break;
10141 case 80:
10142 config_val = 2;
10143 break;
10144 case 160:
10145 config_val = 3;
10146 break;
10147 default:
10148 config_val = 2;
10149 break;
10150 }
10151
10152 dut->chwidth = config_val;
10153
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010154 run_iwpriv(dut, intf, "chwidth %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010155 }
10156
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010157 run_iwpriv(dut, intf, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010158 }
10159
10160 val = get_param(cmd, "nss_mcs_cap");
10161 if (val) {
10162 int nss, mcs;
10163 char token[20];
10164 char *result = NULL;
10165 unsigned int vht_mcsmap = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010166 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010167
Peng Xub8fc5cc2017-05-10 17:27:28 -070010168 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010169 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +053010170 if (!result) {
10171 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -070010172 "NSS not specified");
10173 send_resp(dut, conn, SIGMA_ERROR,
10174 "errorCode,NSS not specified");
Jouni Malinen224e3902021-06-09 16:41:27 +030010175 return STATUS_SENT_ERROR;
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +053010176 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010177 nss = atoi(result);
10178
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010179 run_iwpriv(dut, intf, "nss %d", nss);
Arif Hussainac6c5112018-05-25 17:34:00 -070010180 dut->sta_nss = nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010181
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010182 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010183 if (result == NULL) {
10184 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -070010185 "MCS not specified");
10186 send_resp(dut, conn, SIGMA_ERROR,
10187 "errorCode,MCS not specified");
Jouni Malinen224e3902021-06-09 16:41:27 +030010188 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010189 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010190 result = strtok_r(result, "-", &saveptr);
10191 result = strtok_r(NULL, "-", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +053010192 if (!result) {
10193 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -070010194 "MCS not specified");
10195 send_resp(dut, conn, SIGMA_ERROR,
10196 "errorCode,MCS not specified");
Jouni Malinen224e3902021-06-09 16:41:27 +030010197 return STATUS_SENT_ERROR;
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +053010198 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010199 mcs = atoi(result);
10200
Arif Hussaina37e9552018-06-20 17:05:59 -070010201 if (program && strcasecmp(program, "HE") == 0) {
10202#ifdef NL80211_SUPPORT
10203 enum he_mcs_config mcs_config;
10204 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010205
Arif Hussaina37e9552018-06-20 17:05:59 -070010206 if (mcs >= 0 && mcs <= 7) {
10207 mcs_config = HE_80_MCS0_7;
10208 } else if (mcs > 7 && mcs <= 9) {
10209 mcs_config = HE_80_MCS0_9;
10210 } else if (mcs > 9 && mcs <= 11) {
10211 mcs_config = HE_80_MCS0_11;
10212 } else {
10213 sigma_dut_print(dut, DUT_MSG_ERROR,
10214 "nss_mcs_cap: HE: Invalid mcs: %d",
10215 mcs);
10216 send_resp(dut, conn, SIGMA_ERROR,
10217 "errorCode,Invalid MCS");
Jouni Malinen224e3902021-06-09 16:41:27 +030010218 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010219 }
Arif Hussaina37e9552018-06-20 17:05:59 -070010220
10221 ret = sta_set_he_mcs(dut, intf, mcs_config);
10222 if (ret) {
10223 sigma_dut_print(dut, DUT_MSG_ERROR,
10224 "nss_mcs_cap: HE: Setting of MCS failed, mcs_config: %d, ret: %d",
10225 mcs_config, ret);
10226 send_resp(dut, conn, SIGMA_ERROR,
10227 "errorCode,Failed to set MCS");
Jouni Malinen224e3902021-06-09 16:41:27 +030010228 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010229 }
Arif Hussaina37e9552018-06-20 17:05:59 -070010230#else /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010231 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -070010232 "nss_mcs_cap: HE: MCS cannot be changed without NL80211_SUPPORT defined");
10233#endif /* NL80211_SUPPORT */
10234 } else {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010235 run_iwpriv(dut, intf, "vhtmcs %d", mcs);
Arif Hussaina37e9552018-06-20 17:05:59 -070010236
10237 switch (nss) {
10238 case 1:
10239 switch (mcs) {
10240 case 7:
10241 vht_mcsmap = 0xfffc;
10242 break;
10243 case 8:
10244 vht_mcsmap = 0xfffd;
10245 break;
10246 case 9:
10247 vht_mcsmap = 0xfffe;
10248 break;
10249 default:
10250 vht_mcsmap = 0xfffe;
10251 break;
10252 }
10253 break;
10254 case 2:
10255 switch (mcs) {
10256 case 7:
10257 vht_mcsmap = 0xfff0;
10258 break;
10259 case 8:
10260 vht_mcsmap = 0xfff5;
10261 break;
10262 case 9:
10263 vht_mcsmap = 0xfffa;
10264 break;
10265 default:
10266 vht_mcsmap = 0xfffa;
10267 break;
10268 }
10269 break;
10270 case 3:
10271 switch (mcs) {
10272 case 7:
10273 vht_mcsmap = 0xffc0;
10274 break;
10275 case 8:
10276 vht_mcsmap = 0xffd5;
10277 break;
10278 case 9:
10279 vht_mcsmap = 0xffea;
10280 break;
10281 default:
10282 vht_mcsmap = 0xffea;
10283 break;
10284 }
10285 break;
10286 default:
10287 vht_mcsmap = 0xffea;
10288 break;
10289 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010290 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010291 }
10292 }
10293
10294 /* UNSUPPORTED: val = get_param(cmd, "Tx_lgi_rate"); */
10295
10296 val = get_param(cmd, "Vht_tkip");
10297 if (val)
10298 tkip = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
10299
10300 val = get_param(cmd, "Vht_wep");
10301 if (val)
10302 wep = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
10303
10304 if (tkip != -1 || wep != -1) {
10305 if ((tkip == 1 && wep != 0) || (wep == 1 && tkip != 0)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010306 run_iwpriv(dut, intf, "htweptkip 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010307 } else if ((tkip == 0 && wep != 1) || (wep == 0 && tkip != 1)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010308 run_iwpriv(dut, intf, "htweptkip 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010309 } else {
Jouni Malinen224e3902021-06-09 16:41:27 +030010310 send_resp(dut, conn, SIGMA_ERROR,
10311 "ErrorCode,mixed mode of VHT TKIP/WEP not supported");
10312 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010313 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010314 }
10315
Kiran Kumar Lokere09dbcef2021-08-09 00:01:41 -070010316 val = get_param(cmd, "TWTSchedSTASupport");
10317 if (val) {
10318 int set_val;
10319
10320 switch (get_driver_type(dut)) {
10321 case DRIVER_WCN:
10322 if (strcasecmp(val, "Enable") == 0) {
10323 set_val = 1;
10324 } else if (strcasecmp(val, "Disable") == 0) {
10325 set_val = 0;
10326 } else {
10327 send_resp(dut, conn, SIGMA_ERROR,
10328 "ErrorCode,Invalid TWTSchedSTASupport");
10329 return STATUS_SENT_ERROR;
10330 }
10331
10332 if (sta_set_bcast_twt_support(dut, intf, set_val)) {
10333 send_resp(dut, conn, SIGMA_ERROR,
10334 "ErrorCode,Failed to set TWTSchedSTASupport");
10335 return STATUS_SENT_ERROR;
10336 }
10337 break;
10338 default:
10339 sigma_dut_print(dut, DUT_MSG_ERROR,
10340 "Setting TWTSchedSTASupport not supported");
10341 break;
10342 }
10343 }
10344
10345 val = get_param(cmd, "MBSSID_RxCtrl");
10346 if (val) {
10347 int set_val;
10348
10349 switch (get_driver_type(dut)) {
10350 case DRIVER_WCN:
10351 if (strcasecmp(val, "Enable") == 0) {
10352 set_val = 1;
10353 } else if (strcasecmp(val, "Disable") == 0) {
10354 set_val = 0;
10355 } else {
10356 send_resp(dut, conn, SIGMA_ERROR,
10357 "ErrorCode,Invalid MBSSID_RxCtrl");
10358 return STATUS_SENT_ERROR;
10359 }
10360
10361 if (sta_set_rx_ctrl_multi_bss(dut, intf, set_val)) {
10362 send_resp(dut, conn, SIGMA_ERROR,
10363 "ErrorCode,Failed to set MBSSID_RxCtrl");
10364 return STATUS_SENT_ERROR;
10365 }
10366 break;
10367 default:
10368 sigma_dut_print(dut, DUT_MSG_ERROR,
10369 "Setting MBSSID_RxCtrl not supported");
10370 break;
10371 }
10372 }
10373
Arif Hussain55f00da2018-07-03 08:28:26 -070010374 val = get_param(cmd, "txBandwidth");
10375 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010376 switch (get_driver_type(dut)) {
Arif Hussain55f00da2018-07-03 08:28:26 -070010377 case DRIVER_WCN:
10378 if (wcn_sta_set_width(dut, intf, val) < 0) {
10379 send_resp(dut, conn, SIGMA_ERROR,
10380 "ErrorCode,Failed to set txBandwidth");
Jouni Malinen224e3902021-06-09 16:41:27 +030010381 return STATUS_SENT_ERROR;
Arif Hussain55f00da2018-07-03 08:28:26 -070010382 }
10383 break;
10384 case DRIVER_ATHEROS:
10385 if (ath_set_width(dut, conn, intf, val) < 0) {
10386 send_resp(dut, conn, SIGMA_ERROR,
10387 "ErrorCode,Failed to set txBandwidth");
Jouni Malinen224e3902021-06-09 16:41:27 +030010388 return STATUS_SENT_ERROR;
Arif Hussain55f00da2018-07-03 08:28:26 -070010389 }
10390 break;
10391 default:
10392 sigma_dut_print(dut, DUT_MSG_ERROR,
10393 "Setting txBandwidth not supported");
10394 break;
10395 }
10396 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010397
Arif Hussain9765f7d2018-07-03 08:28:26 -070010398 val = get_param(cmd, "BeamformeeSTS");
10399 if (val) {
Kiran Kumar Lokerebc89d432018-07-10 12:20:13 -070010400 if (sta_set_tx_beamformee(dut, intf, 1)) {
10401 send_resp(dut, conn, SIGMA_ERROR,
10402 "ErrorCode,Failed to set TX beamformee enable");
Jouni Malinen224e3902021-06-09 16:41:27 +030010403 return STATUS_SENT_ERROR;
Kiran Kumar Lokerebc89d432018-07-10 12:20:13 -070010404 }
10405
Arif Hussain9765f7d2018-07-03 08:28:26 -070010406 if (sta_set_beamformee_sts(dut, intf, atoi(val))) {
10407 send_resp(dut, conn, SIGMA_ERROR,
10408 "ErrorCode,Failed to set BeamformeeSTS");
Jouni Malinen224e3902021-06-09 16:41:27 +030010409 return STATUS_SENT_ERROR;
Arif Hussain9765f7d2018-07-03 08:28:26 -070010410 }
10411 }
10412
Arif Hussain68d23f52018-07-11 13:39:08 -070010413 val = get_param(cmd, "Trig_MAC_Padding_Dur");
10414 if (val) {
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -070010415#ifdef NL80211_SUPPORT
10416 enum qca_wlan_he_mac_padding_dur set_val;
10417
10418 switch (atoi(val)) {
10419 case 16:
10420 set_val = QCA_WLAN_HE_16US_OF_PROCESS_TIME;
10421 break;
10422 case 8:
10423 set_val = QCA_WLAN_HE_8US_OF_PROCESS_TIME;
10424 break;
10425 default:
10426 set_val = QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME;
10427 break;
10428 }
10429 if (sta_set_mac_padding_duration(dut, intf, set_val)) {
Arif Hussain68d23f52018-07-11 13:39:08 -070010430 send_resp(dut, conn, SIGMA_ERROR,
10431 "ErrorCode,Failed to set MAC padding duration");
Jouni Malinen224e3902021-06-09 16:41:27 +030010432 return STATUS_SENT_ERROR;
Arif Hussain68d23f52018-07-11 13:39:08 -070010433 }
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -070010434#else /* NL80211_SUPPORT */
10435 sigma_dut_print(dut, DUT_MSG_ERROR,
10436 "MAC padding duration cannot be changed without NL80211_SUPPORT defined");
10437#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -070010438 }
10439
Arif Hussain480d5f42019-03-12 14:40:42 -070010440 val = get_param(cmd, "TWT_ReqSupport");
10441 if (val) {
10442 int set_val;
10443
10444 if (strcasecmp(val, "Enable") == 0) {
10445 set_val = 1;
10446 } else if (strcasecmp(val, "Disable") == 0) {
10447 set_val = 0;
10448 } else {
10449 send_resp(dut, conn, SIGMA_ERROR,
10450 "ErrorCode,Invalid TWT_ReqSupport");
Jouni Malinen224e3902021-06-09 16:41:27 +030010451 return STATUS_SENT_ERROR;
Arif Hussain480d5f42019-03-12 14:40:42 -070010452 }
10453
10454 if (sta_set_twt_req_support(dut, intf, set_val)) {
10455 sigma_dut_print(dut, DUT_MSG_ERROR,
10456 "Failed to set TWT req support %d",
10457 set_val);
10458 send_resp(dut, conn, SIGMA_ERROR,
10459 "ErrorCode,Failed to set TWT_ReqSupport");
Jouni Malinen224e3902021-06-09 16:41:27 +030010460 return STATUS_SENT_ERROR;
Arif Hussain480d5f42019-03-12 14:40:42 -070010461 }
10462 }
10463
Kiran Kumar Lokered0ec5ed2021-04-01 00:15:04 -070010464 val = get_param(cmd, "PreamblePunctRx");
10465 if (val && get_driver_type(dut) == DRIVER_WCN) {
10466 int set_val;
10467
10468 if (strcasecmp(val, "Enable") == 0) {
10469 set_val = 1;
10470 } else if (strcasecmp(val, "Disable") == 0) {
10471 set_val = 0;
10472 } else {
10473 send_resp(dut, conn, SIGMA_ERROR,
10474 "ErrorCode,Invalid PreamblePunctRx");
10475 return STATUS_SENT_ERROR;
10476 }
10477
10478 if (sta_set_punctured_preamble_rx(dut, intf, set_val)) {
10479 sigma_dut_print(dut, DUT_MSG_ERROR,
10480 "Failed to set PreamblePunctRx support %d",
10481 set_val);
10482 send_resp(dut, conn, SIGMA_ERROR,
10483 "ErrorCode,Failed to set PreamblePunctRx");
10484 return STATUS_SENT_ERROR;
10485 }
10486 }
10487
Srinivas Girigowda0525e292020-11-12 13:28:21 -080010488 val = get_param(cmd, "FullBW_ULMUMIMO");
10489 if (val) {
10490 int set_val;
10491
10492 if (strcasecmp(val, "Enable") == 0) {
10493 set_val = 1;
10494 } else if (strcasecmp(val, "Disable") == 0) {
10495 set_val = 0;
10496 } else {
10497 send_resp(dut, conn, SIGMA_ERROR,
10498 "ErrorCode,Invalid FullBW_ULMUMIMO");
10499 return STATUS_SENT_ERROR;
10500 }
10501
10502 if (sta_set_fullbw_ulmumimo(dut, intf, set_val)) {
10503 sigma_dut_print(dut, DUT_MSG_ERROR,
10504 "Failed to set FullBW_ULMUMIMO %d",
10505 set_val);
10506 send_resp(dut, conn, SIGMA_ERROR,
10507 "ErrorCode,Failed to set FullBW_ULMUMIMO");
10508 return STATUS_SENT_ERROR;
10509 }
10510 }
10511
Srinivas Girigowda6707f032020-10-26 15:24:46 -070010512 val = get_param(cmd, "TWTInfoFrameTx");
10513 if (val) {
10514 if (strcasecmp(val, "Enable") == 0) {
10515 /* No-op */
10516 } else if (strcasecmp(val, "Disable") == 0) {
10517 /* No-op */
10518 } else {
10519 send_resp(dut, conn, SIGMA_ERROR,
10520 "ErrorCode,Invalid TWTInfoFrameTx");
10521 return STATUS_SENT_ERROR;
10522 }
10523 }
10524
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -070010525 val = get_param(cmd, "MU_EDCA");
10526 if (val && (strcasecmp(val, "Override") == 0)) {
10527 if (sta_set_mu_edca_override(dut, intf, 1)) {
10528 send_resp(dut, conn, SIGMA_ERROR,
10529 "ErrorCode,Failed to set MU EDCA override");
Jouni Malinen224e3902021-06-09 16:41:27 +030010530 return STATUS_SENT_ERROR;
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -070010531 }
10532 }
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -070010533
Kiran Kumar Lokerefa7c7b92021-08-09 00:50:55 -070010534 val = get_param(cmd, "PPDUTxType");
10535 if (val && strcasecmp(val, "ER-SU") == 0) {
10536 if (sta_set_er_su_ppdu_type_tx(dut, intf, 1)) {
10537 send_resp(dut, conn, SIGMA_ERROR,
10538 "ErrorCode,Failed to set ER-SU PPDU type Tx");
10539 return STATUS_SENT_ERROR;
10540 }
10541 }
10542
10543 val = get_param(cmd, "RUAllocTone");
10544 if (val && strcasecmp(val, "242") == 0) {
10545 if (sta_set_ru_242_tone_tx(dut, intf, 1)) {
10546 send_resp(dut, conn, SIGMA_ERROR,
10547 "ErrorCode,Failed to set RU 242 tone Tx");
10548 return STATUS_SENT_ERROR;
10549 }
10550 }
10551
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -070010552 val = get_param(cmd, "OMControl");
10553 if (val) {
10554 int set_val = 1;
10555
10556 if (strcasecmp(val, "Enable") == 0)
10557 set_val = 1;
10558 else if (strcasecmp(val, "Disable") == 0)
10559 set_val = 0;
10560
10561 if (sta_set_om_ctrl_supp(dut, intf, set_val)) {
10562 send_resp(dut, conn, SIGMA_ERROR,
10563 "ErrorCode,Failed to set OM ctrl supp");
Jouni Malinen224e3902021-06-09 16:41:27 +030010564 return STATUS_SENT_ERROR;
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -070010565 }
10566 }
10567
Kiran Kumar Lokere4f2d4b02021-04-01 00:07:39 -070010568 val = get_param(cmd, "BSSMaxIdlePeriod");
10569 if (val && sta_set_bss_max_idle_period(dut, intf, atoi(val))) {
10570 send_resp(dut, conn, SIGMA_ERROR,
10571 "ErrorCode,Failed to set BSS max idle period");
10572 return STATUS_SENT_ERROR;
10573 }
10574
Kiran Kumar Lokere07ad92b2021-08-09 00:27:14 -070010575 val = get_param(cmd, "BSS_max_idle");
10576 if (val) {
10577 int set_val = 0;
10578
10579 if (strcasecmp(val, "Enable") == 0)
10580 set_val = 1;
10581 else if (strcasecmp(val, "Disable") == 0)
10582 set_val = 0;
10583 if (sta_set_bss_max_idle_support(dut, intf, set_val)) {
10584 send_resp(dut, conn, SIGMA_ERROR,
10585 "ErrorCode,Failed to set BSS max idle support");
10586 return STATUS_SENT_ERROR;
10587 }
10588 }
10589
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -070010590 val = get_param(cmd, "ADDBAResp_BufSize");
10591 if (val) {
10592 int buf_size;
10593
10594 if (strcasecmp(val, "gt64") == 0)
10595 buf_size = 256;
10596 else
10597 buf_size = 64;
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010598 if (get_driver_type(dut) == DRIVER_WCN &&
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -070010599 sta_set_addba_buf_size(dut, intf, buf_size)) {
10600 send_resp(dut, conn, SIGMA_ERROR,
10601 "ErrorCode,set addbaresp_buff_size failed");
Jouni Malinen224e3902021-06-09 16:41:27 +030010602 return STATUS_SENT_ERROR;
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -070010603 }
10604 }
10605
10606 val = get_param(cmd, "ADDBAReq_BufSize");
10607 if (val) {
10608 int buf_size;
10609
10610 if (strcasecmp(val, "gt64") == 0)
10611 buf_size = 256;
10612 else
10613 buf_size = 64;
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010614 if (get_driver_type(dut) == DRIVER_WCN &&
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -070010615 sta_set_addba_buf_size(dut, intf, buf_size)) {
10616 send_resp(dut, conn, SIGMA_ERROR,
10617 "ErrorCode,set addbareq_buff_size failed");
Jouni Malinen224e3902021-06-09 16:41:27 +030010618 return STATUS_SENT_ERROR;
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -070010619 }
10620 }
10621
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010622 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
10623}
10624
10625
10626static int sta_set_wireless_60g(struct sigma_dut *dut,
10627 struct sigma_conn *conn,
10628 struct sigma_cmd *cmd)
10629{
10630 const char *dev_role = get_param(cmd, "DevRole");
10631
10632 if (!dev_role) {
10633 send_resp(dut, conn, SIGMA_INVALID,
10634 "ErrorCode,DevRole not specified");
10635 return 0;
10636 }
10637
10638 if (strcasecmp(dev_role, "PCP") == 0)
10639 return sta_set_60g_pcp(dut, conn, cmd);
10640 if (strcasecmp(dev_role, "STA") == 0)
10641 return sta_set_60g_sta(dut, conn, cmd);
10642 send_resp(dut, conn, SIGMA_INVALID,
10643 "ErrorCode,DevRole not supported");
10644 return 0;
10645}
10646
10647
Ankita Bajaj0d5825b2017-10-25 16:20:17 +053010648static int sta_set_wireless_oce(struct sigma_dut *dut, struct sigma_conn *conn,
10649 struct sigma_cmd *cmd)
10650{
10651 int status;
10652 const char *intf = get_param(cmd, "Interface");
10653 const char *val = get_param(cmd, "DevRole");
10654
10655 if (val && strcasecmp(val, "STA-CFON") == 0) {
10656 status = sta_cfon_set_wireless(dut, conn, cmd);
10657 if (status)
10658 return status;
10659 }
10660 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
10661}
10662
10663
Jouni Malinen67433fc2020-06-26 22:50:33 +030010664static enum sigma_cmd_result
10665sta_set_wireless_wpa3(struct sigma_dut *dut, struct sigma_conn *conn,
10666 struct sigma_cmd *cmd)
Vamsi Krishnac1633d22020-05-06 18:31:21 +053010667{
10668 const char *intf = get_param(cmd, "Interface");
10669 const char *val;
10670
10671 val = get_param(cmd, "ocvc");
10672 if (val)
10673 dut->ocvc = atoi(val);
10674
Jouni Malinen67433fc2020-06-26 22:50:33 +030010675 val = get_param(cmd, "ClientPrivacy");
Veerendranath Jakkam47867202020-12-21 01:53:52 +053010676 if (val && dut->client_privacy != atoi(val) &&
10677 sta_set_client_privacy(dut, conn, intf, atoi(val))) {
10678 send_resp(dut, conn, SIGMA_ERROR,
10679 "errorCode,Failed to configure random MAC address use");
10680 return STATUS_SENT_ERROR;
Jouni Malinen67433fc2020-06-26 22:50:33 +030010681 }
10682
Vamsi Krishnac1633d22020-05-06 18:31:21 +053010683 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
10684}
10685
10686
Jouni Malinenf7222712019-06-13 01:50:21 +030010687static enum sigma_cmd_result cmd_sta_set_wireless(struct sigma_dut *dut,
10688 struct sigma_conn *conn,
10689 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010690{
10691 const char *val;
10692
10693 val = get_param(cmd, "Program");
10694 if (val) {
10695 if (strcasecmp(val, "11n") == 0)
10696 return cmd_sta_set_11n(dut, conn, cmd);
Amarnath Hullur Subramanyam4f860292018-01-31 03:49:35 -080010697 if (strcasecmp(val, "VHT") == 0 || strcasecmp(val, "HE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010698 return cmd_sta_set_wireless_vht(dut, conn, cmd);
10699 if (strcasecmp(val, "60ghz") == 0)
10700 return sta_set_wireless_60g(dut, conn, cmd);
Ankita Bajaj0d5825b2017-10-25 16:20:17 +053010701 if (strcasecmp(val, "OCE") == 0)
10702 return sta_set_wireless_oce(dut, conn, cmd);
Alexei Avshalom Lazar66bb9972018-12-18 16:01:43 +020010703 /* sta_set_wireless in WPS program is only used for 60G */
10704 if (is_60g_sigma_dut(dut))
10705 return sta_set_wireless_60g(dut, conn, cmd);
Vamsi Krishnac1633d22020-05-06 18:31:21 +053010706 if (strcasecmp(val, "WPA3") == 0)
10707 return sta_set_wireless_wpa3(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010708 send_resp(dut, conn, SIGMA_ERROR,
10709 "ErrorCode,Program value not supported");
10710 } else {
10711 send_resp(dut, conn, SIGMA_ERROR,
10712 "ErrorCode,Program argument not available");
10713 }
10714
10715 return 0;
10716}
10717
10718
10719static void ath_sta_inject_frame(struct sigma_dut *dut, const char *intf,
10720 int tid)
10721{
10722 char buf[100];
10723 int tid_to_dscp [] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 };
10724
Pradeep Reddy POTTETId31d1322016-10-13 17:22:03 +053010725 if (tid < 0 ||
10726 tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) {
10727 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid);
10728 return;
10729 }
10730
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010731 /*
10732 * Two ways to ensure that addba request with a
10733 * non zero TID could be sent out. EV 117296
10734 */
10735 snprintf(buf, sizeof(buf),
10736 "ping -c 8 -Q %d `arp -a | grep wlan0 | awk '{print $2}' | tr -d '()'`",
10737 tid);
10738 if (system(buf) != 0) {
10739 sigma_dut_print(dut, DUT_MSG_ERROR,
10740 "Ping did not send out");
10741 }
10742
10743 snprintf(buf, sizeof(buf),
10744 "iwconfig %s | grep Access | awk '{print $6}' > %s",
10745 intf, VI_QOS_TMP_FILE);
10746 if (system(buf) != 0)
10747 return;
10748
10749 snprintf(buf, sizeof(buf),
10750 "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s",
10751 intf, VI_QOS_TMP_FILE);
10752 if (system(buf) != 0)
10753 sigma_dut_print(dut, DUT_MSG_ERROR, "HWaddr matching failed");
10754
10755 snprintf(buf,sizeof(buf), "sed -n '3,$p' %s >> %s",
10756 VI_QOS_REFFILE, VI_QOS_TMP_FILE);
10757 if (system(buf) != 0) {
10758 sigma_dut_print(dut, DUT_MSG_ERROR,
10759 "VI_QOS_TEMP_FILE generation error failed");
10760 }
10761 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
10762 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
10763 if (system(buf) != 0) {
10764 sigma_dut_print(dut, DUT_MSG_ERROR,
10765 "VI_QOS_FILE generation failed");
10766 }
10767
10768 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
10769 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
10770 if (system(buf) != 0) {
10771 sigma_dut_print(dut, DUT_MSG_ERROR,
10772 "VI_QOS_FILE generation failed");
10773 }
10774
10775 snprintf(buf, sizeof(buf), "ethinject %s %s", intf, VI_QOS_FILE);
10776 if (system(buf) != 0) {
10777 }
10778}
10779
10780
10781static int ath_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
10782 struct sigma_cmd *cmd)
10783{
10784 const char *intf = get_param(cmd, "Interface");
10785 const char *val;
10786 int tid = 0;
10787 char buf[100];
10788
10789 val = get_param(cmd, "TID");
10790 if (val) {
10791 tid = atoi(val);
10792 if (tid)
10793 ath_sta_inject_frame(dut, intf, tid);
10794 }
10795
10796 /* Command sequence for ADDBA request on Peregrine based devices */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010797 run_iwpriv(dut, intf, "setaddbaoper 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010798
10799 snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4", intf, tid);
10800 if (system(buf) != 0) {
10801 sigma_dut_print(dut, DUT_MSG_ERROR,
10802 "wifitool senddelba failed");
10803 }
10804
10805 snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64", intf, tid);
10806 if (system(buf) != 0) {
10807 sigma_dut_print(dut, DUT_MSG_ERROR,
10808 "wifitool sendaddba failed");
10809 }
10810
10811 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
10812
10813 return 1;
10814}
10815
10816
Lior David9981b512017-01-20 13:16:40 +020010817#ifdef __linux__
10818
10819static int wil6210_send_addba(struct sigma_dut *dut, const char *dest_mac,
10820 int agg_size)
10821{
10822 char dir[128], buf[128];
10823 FILE *f;
10824 regex_t re;
10825 regmatch_t m[2];
Jouni Malinen3aa72862019-05-29 23:14:51 +030010826 int rc, ret = -1, vring_id, found, res;
Lior David9981b512017-01-20 13:16:40 +020010827
10828 if (wil6210_get_debugfs_dir(dut, dir, sizeof(dir))) {
10829 sigma_dut_print(dut, DUT_MSG_ERROR,
10830 "failed to get wil6210 debugfs dir");
10831 return -1;
10832 }
10833
Jouni Malinen3aa72862019-05-29 23:14:51 +030010834 res = snprintf(buf, sizeof(buf), "%s/vrings", dir);
10835 if (res < 0 || res >= sizeof(buf))
10836 return -1;
Lior David9981b512017-01-20 13:16:40 +020010837 f = fopen(buf, "r");
10838 if (!f) {
10839 sigma_dut_print(dut, DUT_MSG_ERROR, "failed to open: %s", buf);
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +020010840 /* newer wil6210 driver renamed file to "rings" */
Jouni Malinen3aa72862019-05-29 23:14:51 +030010841 res = snprintf(buf, sizeof(buf), "%s/rings", dir);
10842 if (res < 0 || res >= sizeof(buf))
10843 return -1;
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +020010844 f = fopen(buf, "r");
10845 if (!f) {
10846 sigma_dut_print(dut, DUT_MSG_ERROR,
10847 "failed to open: %s", buf);
10848 return -1;
10849 }
Lior David9981b512017-01-20 13:16:40 +020010850 }
10851
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +020010852 /* can be either VRING tx... or RING... */
10853 if (regcomp(&re, "RING tx_[ \t]*([0-9]+)", REG_EXTENDED)) {
Lior David9981b512017-01-20 13:16:40 +020010854 sigma_dut_print(dut, DUT_MSG_ERROR, "regcomp failed");
10855 goto out;
10856 }
10857
10858 /* find TX VRING for the mac address */
10859 found = 0;
10860 while (fgets(buf, sizeof(buf), f)) {
10861 if (strcasestr(buf, dest_mac)) {
10862 found = 1;
10863 break;
10864 }
10865 }
10866
10867 if (!found) {
10868 sigma_dut_print(dut, DUT_MSG_ERROR,
10869 "no TX VRING for %s", dest_mac);
10870 goto out;
10871 }
10872
10873 /* extract VRING ID, "VRING tx_<id> = {" */
10874 if (!fgets(buf, sizeof(buf), f)) {
10875 sigma_dut_print(dut, DUT_MSG_ERROR,
10876 "no VRING start line for %s", dest_mac);
10877 goto out;
10878 }
10879
10880 rc = regexec(&re, buf, 2, m, 0);
10881 regfree(&re);
10882 if (rc || m[1].rm_so < 0) {
10883 sigma_dut_print(dut, DUT_MSG_ERROR,
10884 "no VRING TX ID for %s", dest_mac);
10885 goto out;
10886 }
10887 buf[m[1].rm_eo] = 0;
10888 vring_id = atoi(&buf[m[1].rm_so]);
10889
10890 /* send the addba command */
10891 fclose(f);
Jouni Malinen3aa72862019-05-29 23:14:51 +030010892 res = snprintf(buf, sizeof(buf), "%s/back", dir);
10893 if (res < 0 || res >= sizeof(buf))
10894 return -1;
Lior David9981b512017-01-20 13:16:40 +020010895 f = fopen(buf, "w");
10896 if (!f) {
10897 sigma_dut_print(dut, DUT_MSG_ERROR,
10898 "failed to open: %s", buf);
10899 return -1;
10900 }
10901
10902 fprintf(f, "add %d %d\n", vring_id, agg_size);
10903
10904 ret = 0;
10905
10906out:
10907 fclose(f);
10908
10909 return ret;
10910}
10911
10912
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +020010913int send_addba_60g(struct sigma_dut *dut, struct sigma_conn *conn,
10914 struct sigma_cmd *cmd, const char *mac_param)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010915{
10916 const char *val;
10917 int tid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010918
10919 val = get_param(cmd, "TID");
10920 if (val) {
10921 tid = atoi(val);
10922 if (tid != 0) {
10923 sigma_dut_print(dut, DUT_MSG_ERROR,
10924 "Ignore TID %d for send_addba use TID 0 for 60g since only 0 required on TX",
10925 tid);
10926 }
10927 }
10928
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +020010929 val = get_param(cmd, mac_param);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010930 if (!val) {
10931 sigma_dut_print(dut, DUT_MSG_ERROR,
10932 "Currently not supporting addba for 60G without Dest_mac");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020010933 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010934 }
10935
Lior David9981b512017-01-20 13:16:40 +020010936 if (wil6210_send_addba(dut, val, dut->back_rcv_buf))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010937 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010938
10939 return 1;
10940}
10941
Lior David9981b512017-01-20 13:16:40 +020010942#endif /* __linux__ */
10943
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010944
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080010945static int wcn_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
10946 struct sigma_cmd *cmd)
10947{
10948#ifdef NL80211_SUPPORT
10949 const char *intf = get_param(cmd, "Interface");
10950 const char *val;
10951 int tid = -1;
10952 int bufsize = 64;
10953 struct nl_msg *msg;
10954 int ret = 0;
10955 struct nlattr *params;
10956 int ifindex;
10957
10958 val = get_param(cmd, "TID");
10959 if (val)
10960 tid = atoi(val);
10961
10962 if (tid == -1) {
10963 send_resp(dut, conn, SIGMA_ERROR,
10964 "ErrorCode,sta_send_addba tid invalid");
10965 return 0;
10966 }
10967
10968 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
10969
10970 ifindex = if_nametoindex(intf);
10971 if (ifindex == 0) {
10972 sigma_dut_print(dut, DUT_MSG_ERROR,
10973 "%s: Index for interface %s failed",
10974 __func__, intf);
10975 send_resp(dut, conn, SIGMA_ERROR,
10976 "ErrorCode,sta_send_addba interface invalid");
10977 return 0;
10978 }
10979
10980 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
10981 NL80211_CMD_VENDOR)) ||
10982 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
10983 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
10984 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
10985 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
10986 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
10987 nla_put_u8(msg,
10988 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADD_DEL_BA_SESSION,
10989 QCA_WLAN_ADD_BA) ||
10990 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BA_TID,
10991 tid) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -070010992 nla_put_u16(msg,
10993 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
10994 bufsize)) {
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080010995 sigma_dut_print(dut, DUT_MSG_ERROR,
10996 "%s: err in adding vendor_cmd and vendor_data",
10997 __func__);
10998 nlmsg_free(msg);
10999 send_resp(dut, conn, SIGMA_ERROR,
11000 "ErrorCode,sta_send_addba err in adding vendor_cmd and vendor_data");
11001 return 0;
11002 }
11003 nla_nest_end(msg, params);
11004
11005 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
11006 if (ret) {
11007 sigma_dut_print(dut, DUT_MSG_ERROR,
11008 "%s: err in send_and_recv_msgs, ret=%d",
11009 __func__, ret);
Sunil Dutt30605592018-05-04 20:35:50 +053011010 if (ret == -EOPNOTSUPP)
11011 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080011012 send_resp(dut, conn, SIGMA_ERROR,
11013 "ErrorCode,sta_send_addba err in send_and_recv_msgs");
11014 return 0;
11015 }
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080011016#else /* NL80211_SUPPORT */
11017 sigma_dut_print(dut, DUT_MSG_ERROR,
11018 "sta_send_addba not supported without NL80211_SUPPORT defined");
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080011019#endif /* NL80211_SUPPORT */
Sunil Dutt30605592018-05-04 20:35:50 +053011020
11021 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080011022}
11023
11024
Jouni Malinenf7222712019-06-13 01:50:21 +030011025static enum sigma_cmd_result cmd_sta_send_addba(struct sigma_dut *dut,
11026 struct sigma_conn *conn,
11027 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011028{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011029 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011030 case DRIVER_ATHEROS:
11031 return ath_sta_send_addba(dut, conn, cmd);
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080011032 case DRIVER_WCN:
11033 return wcn_sta_send_addba(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +020011034#ifdef __linux__
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011035 case DRIVER_WIL6210:
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +020011036 return send_addba_60g(dut, conn, cmd, "Dest_mac");
Lior David9981b512017-01-20 13:16:40 +020011037#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011038 default:
11039 /*
11040 * There is no driver specific implementation for other drivers.
11041 * Ignore the command and report COMPLETE since the following
11042 * throughput test operation will end up sending ADDBA anyway.
11043 */
11044 return 1;
11045 }
11046}
11047
11048
11049int inject_eth_frame(int s, const void *data, size_t len,
11050 unsigned short ethtype, char *dst, char *src)
11051{
11052 struct iovec iov[4] = {
11053 {
11054 .iov_base = dst,
11055 .iov_len = ETH_ALEN,
11056 },
11057 {
11058 .iov_base = src,
11059 .iov_len = ETH_ALEN,
11060 },
11061 {
11062 .iov_base = &ethtype,
11063 .iov_len = sizeof(unsigned short),
11064 },
11065 {
11066 .iov_base = (void *) data,
11067 .iov_len = len,
11068 }
11069 };
11070 struct msghdr msg = {
11071 .msg_name = NULL,
11072 .msg_namelen = 0,
11073 .msg_iov = iov,
11074 .msg_iovlen = 4,
11075 .msg_control = NULL,
11076 .msg_controllen = 0,
11077 .msg_flags = 0,
11078 };
11079
11080 return sendmsg(s, &msg, 0);
11081}
11082
11083#if defined(__linux__) || defined(__QNXNTO__)
11084
11085int inject_frame(int s, const void *data, size_t len, int encrypt)
11086{
11087#define IEEE80211_RADIOTAP_F_WEP 0x04
11088#define IEEE80211_RADIOTAP_F_FRAG 0x08
11089 unsigned char rtap_hdr[] = {
11090 0x00, 0x00, /* radiotap version */
11091 0x0e, 0x00, /* radiotap length */
11092 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
11093 IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */
11094 0x00, /* padding */
11095 0x00, 0x00, /* RX and TX flags to indicate that */
11096 0x00, 0x00, /* this is the injected frame directly */
11097 };
11098 struct iovec iov[2] = {
11099 {
11100 .iov_base = &rtap_hdr,
11101 .iov_len = sizeof(rtap_hdr),
11102 },
11103 {
11104 .iov_base = (void *) data,
11105 .iov_len = len,
11106 }
11107 };
11108 struct msghdr msg = {
11109 .msg_name = NULL,
11110 .msg_namelen = 0,
11111 .msg_iov = iov,
11112 .msg_iovlen = 2,
11113 .msg_control = NULL,
11114 .msg_controllen = 0,
11115 .msg_flags = 0,
11116 };
11117
11118 if (encrypt)
11119 rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP;
11120
11121 return sendmsg(s, &msg, 0);
11122}
11123
11124
11125int open_monitor(const char *ifname)
11126{
11127#ifdef __QNXNTO__
11128 struct sockaddr_dl ll;
11129 int s;
11130
11131 memset(&ll, 0, sizeof(ll));
11132 ll.sdl_family = AF_LINK;
11133 ll.sdl_index = if_nametoindex(ifname);
11134 if (ll.sdl_index == 0) {
11135 perror("if_nametoindex");
11136 return -1;
11137 }
11138 s = socket(PF_INET, SOCK_RAW, 0);
11139#else /* __QNXNTO__ */
11140 struct sockaddr_ll ll;
11141 int s;
11142
11143 memset(&ll, 0, sizeof(ll));
11144 ll.sll_family = AF_PACKET;
11145 ll.sll_ifindex = if_nametoindex(ifname);
11146 if (ll.sll_ifindex == 0) {
11147 perror("if_nametoindex");
11148 return -1;
11149 }
11150 s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
11151#endif /* __QNXNTO__ */
11152 if (s < 0) {
11153 perror("socket[PF_PACKET,SOCK_RAW]");
11154 return -1;
11155 }
11156
11157 if (bind(s, (struct sockaddr *) &ll, sizeof(ll)) < 0) {
11158 perror("monitor socket bind");
11159 close(s);
11160 return -1;
11161 }
11162
11163 return s;
11164}
11165
11166
11167static int hex2num(char c)
11168{
11169 if (c >= '0' && c <= '9')
11170 return c - '0';
11171 if (c >= 'a' && c <= 'f')
11172 return c - 'a' + 10;
11173 if (c >= 'A' && c <= 'F')
11174 return c - 'A' + 10;
11175 return -1;
11176}
11177
11178
11179int hwaddr_aton(const char *txt, unsigned char *addr)
11180{
11181 int i;
11182
11183 for (i = 0; i < 6; i++) {
11184 int a, b;
11185
11186 a = hex2num(*txt++);
11187 if (a < 0)
11188 return -1;
11189 b = hex2num(*txt++);
11190 if (b < 0)
11191 return -1;
11192 *addr++ = (a << 4) | b;
11193 if (i < 5 && *txt++ != ':')
11194 return -1;
11195 }
11196
11197 return 0;
11198}
11199
11200#endif /* defined(__linux__) || defined(__QNXNTO__) */
11201
Veerendranath Jakkam49774122020-07-05 09:52:18 +053011202
11203#ifdef NL80211_SUPPORT
11204static int nl80211_send_frame_cmd(struct sigma_dut *dut, const char *intf,
11205 const u8 *data, size_t data_len, int freq)
11206{
11207 struct nl_msg *msg;
11208 int ret = 0;
11209 int ifindex;
11210
11211 ifindex = if_nametoindex(intf);
11212 if (ifindex == 0) {
11213 sigma_dut_print(dut, DUT_MSG_ERROR,
11214 "%s: Index for interface %s failed",
11215 __func__, intf);
11216 return -1;
11217 }
11218
11219 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
11220 NL80211_CMD_FRAME)) ||
11221 (freq && nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
11222 nla_put(msg, NL80211_ATTR_FRAME, data_len, data)) {
11223 sigma_dut_print(dut, DUT_MSG_ERROR,
11224 "%s: Error in adding NL80211_CMD_FRAME",
11225 __func__);
11226 nlmsg_free(msg);
11227 return -1;
11228 }
11229
11230 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
11231 if (ret) {
11232 sigma_dut_print(dut, DUT_MSG_ERROR,
11233 "nl80211: Frame command failed: ret=%d (%s) req=%u",
11234 ret, strerror(-ret), freq);
11235 return -1;
11236 }
11237
11238 return 0;
11239}
11240#endif /* NL80211_SUPPORT */
11241
11242
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011243enum send_frame_type {
11244 DISASSOC, DEAUTH, SAQUERY, AUTH, ASSOCREQ, REASSOCREQ, DLS_REQ
11245};
11246enum send_frame_protection {
11247 CORRECT_KEY, INCORRECT_KEY, UNPROTECTED
11248};
11249
11250
11251static int sta_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn,
Veerendranath Jakkam49774122020-07-05 09:52:18 +053011252 const char *intf, enum send_frame_type frame,
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011253 enum send_frame_protection protected,
Veerendranath Jakkam49774122020-07-05 09:52:18 +053011254 const char *dest, int use_monitor)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011255{
11256#ifdef __linux__
11257 unsigned char buf[1000], *pos;
11258 int s, res;
11259 char bssid[20], addr[20];
11260 char result[32], ssid[100];
11261 size_t ssid_len;
11262
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011263 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011264 sizeof(result)) < 0 ||
11265 strncmp(result, "COMPLETED", 9) != 0) {
11266 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Not connected");
11267 return 0;
11268 }
11269
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011270 if (get_wpa_status(get_station_ifname(dut), "bssid",
11271 bssid, sizeof(bssid)) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011272 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
11273 "current BSSID");
11274 return 0;
11275 }
11276
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011277 if (get_wpa_status(get_station_ifname(dut), "address",
11278 addr, sizeof(addr)) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011279 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
11280 "own MAC address");
11281 return 0;
11282 }
11283
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011284 if (get_wpa_status(get_station_ifname(dut), "ssid", ssid, sizeof(ssid))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011285 < 0) {
11286 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
11287 "current SSID");
11288 return 0;
11289 }
11290 ssid_len = strlen(ssid);
11291
11292 pos = buf;
11293
11294 /* Frame Control */
11295 switch (frame) {
11296 case DISASSOC:
11297 *pos++ = 0xa0;
11298 break;
11299 case DEAUTH:
11300 *pos++ = 0xc0;
11301 break;
11302 case SAQUERY:
11303 *pos++ = 0xd0;
11304 break;
11305 case AUTH:
11306 *pos++ = 0xb0;
11307 break;
11308 case ASSOCREQ:
11309 *pos++ = 0x00;
11310 break;
11311 case REASSOCREQ:
11312 *pos++ = 0x20;
11313 break;
11314 case DLS_REQ:
11315 *pos++ = 0xd0;
11316 break;
11317 }
11318
11319 if (protected == INCORRECT_KEY)
11320 *pos++ = 0x40; /* Set Protected field to 1 */
11321 else
11322 *pos++ = 0x00;
11323
11324 /* Duration */
11325 *pos++ = 0x00;
11326 *pos++ = 0x00;
11327
11328 /* addr1 = DA (current AP) */
11329 hwaddr_aton(bssid, pos);
11330 pos += 6;
11331 /* addr2 = SA (own address) */
11332 hwaddr_aton(addr, pos);
11333 pos += 6;
11334 /* addr3 = BSSID (current AP) */
11335 hwaddr_aton(bssid, pos);
11336 pos += 6;
11337
11338 /* Seq# (to be filled by driver/mac80211) */
11339 *pos++ = 0x00;
11340 *pos++ = 0x00;
11341
11342 if (protected == INCORRECT_KEY) {
11343 /* CCMP parameters */
11344 memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8);
11345 pos += 8;
11346 }
11347
11348 if (protected == INCORRECT_KEY) {
11349 switch (frame) {
11350 case DEAUTH:
11351 /* Reason code (encrypted) */
11352 memcpy(pos, "\xa7\x39", 2);
11353 pos += 2;
11354 break;
11355 case DISASSOC:
11356 /* Reason code (encrypted) */
11357 memcpy(pos, "\xa7\x39", 2);
11358 pos += 2;
11359 break;
11360 case SAQUERY:
11361 /* Category|Action|TransID (encrypted) */
11362 memcpy(pos, "\x6f\xbd\xe9\x4d", 4);
11363 pos += 4;
11364 break;
11365 default:
11366 return -1;
11367 }
11368
11369 /* CCMP MIC */
11370 memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8);
11371 pos += 8;
11372 } else {
11373 switch (frame) {
11374 case DEAUTH:
11375 /* reason code = 8 */
11376 *pos++ = 0x08;
11377 *pos++ = 0x00;
11378 break;
11379 case DISASSOC:
11380 /* reason code = 8 */
11381 *pos++ = 0x08;
11382 *pos++ = 0x00;
11383 break;
11384 case SAQUERY:
11385 /* Category - SA Query */
11386 *pos++ = 0x08;
11387 /* SA query Action - Request */
11388 *pos++ = 0x00;
11389 /* Transaction ID */
11390 *pos++ = 0x12;
11391 *pos++ = 0x34;
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053011392 if (dut->saquery_oci_freq) {
11393 /* OCI IE - Extended ID */
11394 *pos++ = 0xFF;
11395 *pos++ = 0x04;
11396 *pos++ = 0x36;
11397 /* Operating Class */
11398 *pos++ = 0x74;
11399 /* Primary Channel */
11400 *pos++ = freq_to_channel(dut->saquery_oci_freq);
11401 /* Frequency Segment 1 Channel Number */
11402 *pos++ = 0x00;
11403 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011404 break;
11405 case AUTH:
11406 /* Auth Alg (Open) */
11407 *pos++ = 0x00;
11408 *pos++ = 0x00;
11409 /* Seq# */
11410 *pos++ = 0x01;
11411 *pos++ = 0x00;
11412 /* Status code */
11413 *pos++ = 0x00;
11414 *pos++ = 0x00;
11415 break;
11416 case ASSOCREQ:
11417 /* Capability Information */
11418 *pos++ = 0x31;
11419 *pos++ = 0x04;
11420 /* Listen Interval */
11421 *pos++ = 0x0a;
11422 *pos++ = 0x00;
11423 /* SSID */
11424 *pos++ = 0x00;
11425 *pos++ = ssid_len;
11426 memcpy(pos, ssid, ssid_len);
11427 pos += ssid_len;
11428 /* Supported Rates */
11429 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
11430 10);
11431 pos += 10;
11432 /* Extended Supported Rates */
11433 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
11434 pos += 6;
11435 /* RSN */
11436 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
11437 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
11438 "\x00\x00\x00\x00\x0f\xac\x06", 28);
11439 pos += 28;
11440 break;
11441 case REASSOCREQ:
11442 /* Capability Information */
11443 *pos++ = 0x31;
11444 *pos++ = 0x04;
11445 /* Listen Interval */
11446 *pos++ = 0x0a;
11447 *pos++ = 0x00;
11448 /* Current AP */
11449 hwaddr_aton(bssid, pos);
11450 pos += 6;
11451 /* SSID */
11452 *pos++ = 0x00;
11453 *pos++ = ssid_len;
11454 memcpy(pos, ssid, ssid_len);
11455 pos += ssid_len;
11456 /* Supported Rates */
11457 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
11458 10);
11459 pos += 10;
11460 /* Extended Supported Rates */
11461 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
11462 pos += 6;
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053011463 /* RSNE - Group and Pairwise ciphers */
11464 memcpy(pos,
11465 "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x04",
11466 14);
11467 pos += 14;
11468 /* RSNE - AKM Suite count */
11469 *pos++ = 0x01;
11470 *pos++ = 0x00;
11471 /* RSNE - AKM Suites */
11472 if (dut->program == PROGRAM_WPA3)
11473 memcpy(pos, "\x00\x0f\xac\x08", 4);
11474 else
11475 memcpy(pos, "\x00\x0f\xac\x02", 4);
11476 pos += 4;
11477 /* RSNE - Capabilities */
11478 *pos++ = 0xc0;
11479 if (dut->ocvc)
11480 *pos++ = 0x40;
11481 else
11482 *pos++ = 0x00;
11483 /* RSNE - PMKID list and Group Management Ciphers */
11484 memcpy(pos, "\x00\x00\x00\x0f\xac\x06", 6);
11485 pos += 6;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011486 break;
11487 case DLS_REQ:
11488 /* Category - DLS */
11489 *pos++ = 0x02;
11490 /* DLS Action - Request */
11491 *pos++ = 0x00;
11492 /* Destination MACAddress */
11493 if (dest)
11494 hwaddr_aton(dest, pos);
11495 else
11496 memset(pos, 0, 6);
11497 pos += 6;
11498 /* Source MACAddress */
11499 hwaddr_aton(addr, pos);
11500 pos += 6;
11501 /* Capability Information */
11502 *pos++ = 0x10; /* Privacy */
11503 *pos++ = 0x06; /* QoS */
11504 /* DLS Timeout Value */
11505 *pos++ = 0x00;
11506 *pos++ = 0x01;
11507 /* Supported rates */
11508 *pos++ = 0x01;
11509 *pos++ = 0x08;
11510 *pos++ = 0x0c; /* 6 Mbps */
11511 *pos++ = 0x12; /* 9 Mbps */
11512 *pos++ = 0x18; /* 12 Mbps */
11513 *pos++ = 0x24; /* 18 Mbps */
11514 *pos++ = 0x30; /* 24 Mbps */
11515 *pos++ = 0x48; /* 36 Mbps */
11516 *pos++ = 0x60; /* 48 Mbps */
11517 *pos++ = 0x6c; /* 54 Mbps */
11518 /* TODO: Extended Supported Rates */
11519 /* TODO: HT Capabilities */
11520 break;
11521 }
11522 }
11523
Veerendranath Jakkam49774122020-07-05 09:52:18 +053011524 if (use_monitor) {
11525 s = open_monitor("sigmadut");
11526 if (s < 0) {
11527 send_resp(dut, conn, SIGMA_ERROR,
11528 "errorCode,Failed to open monitor socket");
11529 return 0;
11530 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011531
Veerendranath Jakkam49774122020-07-05 09:52:18 +053011532 res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY);
11533 if (res < 0) {
11534 send_resp(dut, conn, SIGMA_ERROR,
11535 "errorCode,Failed to inject frame");
11536 close(s);
11537 return 0;
11538 }
11539 if (res < pos - buf) {
11540 send_resp(dut, conn, SIGMA_ERROR,
11541 "errorCode,Only partial frame sent");
11542 close(s);
11543 return 0;
11544 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011545
Veerendranath Jakkam49774122020-07-05 09:52:18 +053011546 close(s);
11547 } else {
11548#ifdef NL80211_SUPPORT
11549 int freq;
11550 char freq_str[10];
11551
11552 if (get_wpa_status(get_station_ifname(dut), "freq",
11553 freq_str, sizeof(freq_str)) < 0) {
11554 send_resp(dut, conn, SIGMA_ERROR,
11555 "errorCode,Could not get current operating frequency");
11556 return 0;
11557 }
11558 freq = atoi(freq_str);
11559
11560 if (nl80211_send_frame_cmd(dut, intf, buf, pos - buf, freq)) {
11561 send_resp(dut, conn, SIGMA_ERROR,
11562 "errorCode,Failed to inject frame");
11563 return 0;
11564 }
11565#else /* NL80211_SUPPORT */
11566 send_resp(dut, conn, SIGMA_ERROR,
11567 "errorCode,Failed to inject frame (no NL80211_SUPPORT)");
11568 return 0;
11569#endif /* NL80211_SUPPORT */
11570 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011571
11572 return 1;
11573#else /* __linux__ */
11574 send_resp(dut, conn, SIGMA_ERROR, "errorCode,sta_send_frame not "
11575 "yet supported");
11576 return 0;
11577#endif /* __linux__ */
11578}
11579
11580
11581static int cmd_sta_send_frame_tdls(struct sigma_dut *dut,
11582 struct sigma_conn *conn,
11583 struct sigma_cmd *cmd)
11584{
11585 const char *intf = get_param(cmd, "Interface");
11586 const char *sta, *val;
11587 unsigned char addr[ETH_ALEN];
11588 char buf[100];
11589
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030011590 if (!intf)
11591 return -1;
11592
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011593 sta = get_param(cmd, "peer");
11594 if (sta == NULL)
11595 sta = get_param(cmd, "station");
11596 if (sta == NULL) {
11597 send_resp(dut, conn, SIGMA_ERROR,
11598 "ErrorCode,Missing peer address");
11599 return 0;
11600 }
11601 if (hwaddr_aton(sta, addr) < 0) {
11602 send_resp(dut, conn, SIGMA_ERROR,
11603 "ErrorCode,Invalid peer address");
11604 return 0;
11605 }
11606
11607 val = get_param(cmd, "type");
11608 if (val == NULL)
11609 return -1;
11610
11611 if (strcasecmp(val, "DISCOVERY") == 0) {
11612 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", sta);
11613 if (wpa_command(intf, buf) < 0) {
11614 send_resp(dut, conn, SIGMA_ERROR,
11615 "ErrorCode,Failed to send TDLS discovery");
11616 return 0;
11617 }
11618 return 1;
11619 }
11620
11621 if (strcasecmp(val, "SETUP") == 0) {
11622 int status = 0, timeout = 0;
11623
11624 val = get_param(cmd, "Status");
11625 if (val)
11626 status = atoi(val);
11627
11628 val = get_param(cmd, "Timeout");
11629 if (val)
11630 timeout = atoi(val);
11631
11632 if (status != 0 && status != 37) {
11633 send_resp(dut, conn, SIGMA_ERROR,
11634 "ErrorCode,Unsupported status value");
11635 return 0;
11636 }
11637
11638 if (timeout != 0 && timeout != 301) {
11639 send_resp(dut, conn, SIGMA_ERROR,
11640 "ErrorCode,Unsupported timeout value");
11641 return 0;
11642 }
11643
11644 if (status && timeout) {
11645 send_resp(dut, conn, SIGMA_ERROR,
11646 "ErrorCode,Unsupported timeout+status "
11647 "combination");
11648 return 0;
11649 }
11650
11651 if (status == 37 &&
11652 wpa_command(intf, "SET tdls_testing 0x200")) {
11653 send_resp(dut, conn, SIGMA_ERROR,
11654 "ErrorCode,Failed to enable "
11655 "decline setup response test mode");
11656 return 0;
11657 }
11658
11659 if (timeout == 301) {
11660 int res;
11661 if (dut->no_tpk_expiration)
11662 res = wpa_command(intf,
11663 "SET tdls_testing 0x108");
11664 else
11665 res = wpa_command(intf,
11666 "SET tdls_testing 0x8");
11667 if (res) {
11668 send_resp(dut, conn, SIGMA_ERROR,
11669 "ErrorCode,Failed to set short TPK "
11670 "lifetime");
11671 return 0;
11672 }
11673 }
11674
11675 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", sta);
11676 if (wpa_command(intf, buf) < 0) {
11677 send_resp(dut, conn, SIGMA_ERROR,
11678 "ErrorCode,Failed to send TDLS setup");
11679 return 0;
11680 }
11681 return 1;
11682 }
11683
11684 if (strcasecmp(val, "TEARDOWN") == 0) {
11685 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", sta);
11686 if (wpa_command(intf, buf) < 0) {
11687 send_resp(dut, conn, SIGMA_ERROR,
11688 "ErrorCode,Failed to send TDLS teardown");
11689 return 0;
11690 }
11691 return 1;
11692 }
11693
11694 send_resp(dut, conn, SIGMA_ERROR,
11695 "ErrorCode,Unsupported TDLS frame");
11696 return 0;
11697}
11698
11699
11700static int sta_ap_known(const char *ifname, const char *bssid)
11701{
11702 char buf[4096];
11703
Jouni Malinendd32f192018-09-15 02:55:19 +030011704 snprintf(buf, sizeof(buf), "BSS MASK=1 %s", bssid);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011705 if (wpa_command_resp(ifname, buf, buf, sizeof(buf)) < 0)
11706 return 0;
11707 if (strncmp(buf, "id=", 3) != 0)
11708 return 0;
11709 return 1;
11710}
11711
11712
11713static int sta_scan_ap(struct sigma_dut *dut, const char *ifname,
11714 const char *bssid)
11715{
11716 int res;
11717 struct wpa_ctrl *ctrl;
11718 char buf[256];
11719
11720 if (sta_ap_known(ifname, bssid))
11721 return 0;
11722 sigma_dut_print(dut, DUT_MSG_DEBUG,
11723 "AP not in BSS table - start scan");
11724
11725 ctrl = open_wpa_mon(ifname);
11726 if (ctrl == NULL) {
11727 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
11728 "wpa_supplicant monitor connection");
11729 return -1;
11730 }
11731
11732 if (wpa_command(ifname, "SCAN") < 0) {
11733 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to start scan");
11734 wpa_ctrl_detach(ctrl);
11735 wpa_ctrl_close(ctrl);
11736 return -1;
11737 }
11738
11739 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
11740 buf, sizeof(buf));
11741
11742 wpa_ctrl_detach(ctrl);
11743 wpa_ctrl_close(ctrl);
11744
11745 if (res < 0) {
11746 sigma_dut_print(dut, DUT_MSG_INFO, "Scan did not complete");
11747 return -1;
11748 }
11749
11750 if (sta_ap_known(ifname, bssid))
11751 return 0;
11752 sigma_dut_print(dut, DUT_MSG_INFO, "AP not in BSS table");
11753 return -1;
11754}
11755
11756
11757static int cmd_sta_send_frame_hs2_neighadv(struct sigma_dut *dut,
11758 struct sigma_conn *conn,
11759 struct sigma_cmd *cmd,
11760 const char *intf)
11761{
11762 char buf[200];
11763
11764 snprintf(buf, sizeof(buf), "ndsend 2001:DB8::1 %s", intf);
11765 if (system(buf) != 0) {
11766 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Failed to run "
11767 "ndsend");
11768 return 0;
11769 }
11770
11771 return 1;
11772}
11773
11774
11775static int cmd_sta_send_frame_hs2_neighsolreq(struct sigma_dut *dut,
11776 struct sigma_conn *conn,
11777 struct sigma_cmd *cmd,
11778 const char *intf)
11779{
11780 char buf[200];
11781 const char *ip = get_param(cmd, "SenderIP");
11782
Peng Xu26b356d2017-10-04 17:58:16 -070011783 if (!ip)
11784 return 0;
11785
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011786 snprintf(buf, sizeof(buf), "ndisc6 -nm %s %s -r 4", ip, intf);
11787 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11788 if (system(buf) == 0) {
11789 sigma_dut_print(dut, DUT_MSG_INFO,
11790 "Neighbor Solicitation got a response "
11791 "for %s@%s", ip, intf);
11792 }
11793
11794 return 1;
11795}
11796
11797
11798static int cmd_sta_send_frame_hs2_arpprobe(struct sigma_dut *dut,
11799 struct sigma_conn *conn,
11800 struct sigma_cmd *cmd,
11801 const char *ifname)
11802{
11803 char buf[200];
11804 const char *ip = get_param(cmd, "SenderIP");
11805
11806 if (ip == NULL) {
11807 send_resp(dut, conn, SIGMA_ERROR,
11808 "ErrorCode,Missing SenderIP parameter");
11809 return 0;
11810 }
11811 snprintf(buf, sizeof(buf), "arping -I %s -D %s -c 4", ifname, ip);
11812 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11813 if (system(buf) != 0) {
11814 sigma_dut_print(dut, DUT_MSG_INFO, "arping DAD got a response "
11815 "for %s@%s", ip, ifname);
11816 }
11817
11818 return 1;
11819}
11820
11821
11822static int cmd_sta_send_frame_hs2_arpannounce(struct sigma_dut *dut,
11823 struct sigma_conn *conn,
11824 struct sigma_cmd *cmd,
11825 const char *ifname)
11826{
11827 char buf[200];
11828 char ip[16];
11829 int s;
Peng Xub3756882017-10-04 14:39:09 -070011830 struct ifreq ifr;
11831 struct sockaddr_in saddr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011832
11833 s = socket(PF_INET, SOCK_DGRAM, 0);
Peng Xub3756882017-10-04 14:39:09 -070011834 if (s < 0) {
11835 perror("socket");
11836 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011837 }
11838
Peng Xub3756882017-10-04 14:39:09 -070011839 memset(&ifr, 0, sizeof(ifr));
11840 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
11841 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
11842 sigma_dut_print(dut, DUT_MSG_INFO,
11843 "Failed to get %s IP address: %s",
11844 ifname, strerror(errno));
11845 close(s);
11846 return -1;
11847 }
11848 close(s);
11849
11850 memcpy(&saddr, &ifr.ifr_addr, sizeof(struct sockaddr_in));
11851 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
11852
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011853 snprintf(buf, sizeof(buf), "arping -I %s -s %s %s -c 4", ifname, ip,
11854 ip);
11855 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11856 if (system(buf) != 0) {
11857 }
11858
11859 return 1;
11860}
11861
11862
11863static int cmd_sta_send_frame_hs2_arpreply(struct sigma_dut *dut,
11864 struct sigma_conn *conn,
11865 struct sigma_cmd *cmd,
11866 const char *ifname)
11867{
11868 char buf[200], addr[20];
11869 char dst[ETH_ALEN], src[ETH_ALEN];
11870 short ethtype = htons(ETH_P_ARP);
11871 char *pos;
11872 int s, res;
11873 const char *val;
11874 struct sockaddr_in taddr;
11875
11876 val = get_param(cmd, "dest");
11877 if (val)
11878 hwaddr_aton(val, (unsigned char *) dst);
11879
11880 val = get_param(cmd, "DestIP");
11881 if (val)
11882 inet_aton(val, &taddr.sin_addr);
Peng Xu151c9e12017-10-04 14:39:09 -070011883 else
11884 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011885
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011886 if (get_wpa_status(get_station_ifname(dut), "address", addr,
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011887 sizeof(addr)) < 0)
11888 return -2;
11889 hwaddr_aton(addr, (unsigned char *) src);
11890
11891 pos = buf;
11892 *pos++ = 0x00;
11893 *pos++ = 0x01;
11894 *pos++ = 0x08;
11895 *pos++ = 0x00;
11896 *pos++ = 0x06;
11897 *pos++ = 0x04;
11898 *pos++ = 0x00;
11899 *pos++ = 0x02;
11900 memcpy(pos, src, ETH_ALEN);
11901 pos += ETH_ALEN;
11902 memcpy(pos, &taddr.sin_addr, 4);
11903 pos += 4;
11904 memcpy(pos, dst, ETH_ALEN);
11905 pos += ETH_ALEN;
11906 memcpy(pos, &taddr.sin_addr, 4);
11907 pos += 4;
11908
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011909 s = open_monitor(get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011910 if (s < 0) {
11911 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
11912 "monitor socket");
11913 return 0;
11914 }
11915
11916 res = inject_eth_frame(s, buf, pos - buf, ethtype, dst, src);
11917 if (res < 0) {
11918 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
11919 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +053011920 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011921 return 0;
11922 }
11923
11924 close(s);
11925
11926 return 1;
11927}
11928
11929
11930static int cmd_sta_send_frame_hs2_dls_req(struct sigma_dut *dut,
11931 struct sigma_conn *conn,
11932 struct sigma_cmd *cmd,
11933 const char *intf, const char *dest)
11934{
11935 char buf[100];
11936
11937 if (if_nametoindex("sigmadut") == 0) {
11938 snprintf(buf, sizeof(buf),
11939 "iw dev %s interface add sigmadut type monitor",
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011940 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011941 if (system(buf) != 0 ||
11942 if_nametoindex("sigmadut") == 0) {
11943 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
11944 "monitor interface with '%s'", buf);
11945 return -2;
11946 }
11947 }
11948
11949 if (system("ifconfig sigmadut up") != 0) {
11950 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
11951 "monitor interface up");
11952 return -2;
11953 }
11954
Veerendranath Jakkam49774122020-07-05 09:52:18 +053011955 return sta_inject_frame(dut, conn, intf, DLS_REQ, UNPROTECTED, dest, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011956}
11957
11958
11959static int cmd_sta_send_frame_hs2(struct sigma_dut *dut,
11960 struct sigma_conn *conn,
11961 struct sigma_cmd *cmd)
11962{
11963 const char *intf = get_param(cmd, "Interface");
11964 const char *dest = get_param(cmd, "Dest");
11965 const char *type = get_param(cmd, "FrameName");
11966 const char *val;
11967 char buf[200], *pos, *end;
11968 int count, count2;
11969
11970 if (type == NULL)
11971 type = get_param(cmd, "Type");
11972
11973 if (intf == NULL || dest == NULL || type == NULL)
11974 return -1;
11975
11976 if (strcasecmp(type, "NeighAdv") == 0)
11977 return cmd_sta_send_frame_hs2_neighadv(dut, conn, cmd, intf);
11978
11979 if (strcasecmp(type, "NeighSolicitReq") == 0)
11980 return cmd_sta_send_frame_hs2_neighsolreq(dut, conn, cmd, intf);
11981
11982 if (strcasecmp(type, "ARPProbe") == 0)
11983 return cmd_sta_send_frame_hs2_arpprobe(dut, conn, cmd, intf);
11984
11985 if (strcasecmp(type, "ARPAnnounce") == 0)
11986 return cmd_sta_send_frame_hs2_arpannounce(dut, conn, cmd, intf);
11987
11988 if (strcasecmp(type, "ARPReply") == 0)
11989 return cmd_sta_send_frame_hs2_arpreply(dut, conn, cmd, intf);
11990
11991 if (strcasecmp(type, "DLS-request") == 0 ||
11992 strcasecmp(type, "DLSrequest") == 0)
11993 return cmd_sta_send_frame_hs2_dls_req(dut, conn, cmd, intf,
11994 dest);
11995
11996 if (strcasecmp(type, "ANQPQuery") != 0 &&
11997 strcasecmp(type, "Query") != 0) {
11998 send_resp(dut, conn, SIGMA_ERROR,
11999 "ErrorCode,Unsupported HS 2.0 send frame type");
12000 return 0;
12001 }
12002
12003 if (sta_scan_ap(dut, intf, dest) < 0) {
12004 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not find "
12005 "the requested AP");
12006 return 0;
12007 }
12008
12009 pos = buf;
12010 end = buf + sizeof(buf);
12011 count = 0;
12012 pos += snprintf(pos, end - pos, "ANQP_GET %s ", dest);
12013
12014 val = get_param(cmd, "ANQP_CAP_LIST");
12015 if (val && atoi(val)) {
12016 pos += snprintf(pos, end - pos, "%s257", count > 0 ? "," : "");
12017 count++;
12018 }
12019
12020 val = get_param(cmd, "VENUE_NAME");
12021 if (val && atoi(val)) {
12022 pos += snprintf(pos, end - pos, "%s258", count > 0 ? "," : "");
12023 count++;
12024 }
12025
12026 val = get_param(cmd, "NETWORK_AUTH_TYPE");
12027 if (val && atoi(val)) {
12028 pos += snprintf(pos, end - pos, "%s260", count > 0 ? "," : "");
12029 count++;
12030 }
12031
12032 val = get_param(cmd, "ROAMING_CONS");
12033 if (val && atoi(val)) {
12034 pos += snprintf(pos, end - pos, "%s261", count > 0 ? "," : "");
12035 count++;
12036 }
12037
12038 val = get_param(cmd, "IP_ADDR_TYPE_AVAILABILITY");
12039 if (val && atoi(val)) {
12040 pos += snprintf(pos, end - pos, "%s262", count > 0 ? "," : "");
12041 count++;
12042 }
12043
12044 val = get_param(cmd, "NAI_REALM_LIST");
12045 if (val && atoi(val)) {
12046 pos += snprintf(pos, end - pos, "%s263", count > 0 ? "," : "");
12047 count++;
12048 }
12049
12050 val = get_param(cmd, "3GPP_INFO");
12051 if (val && atoi(val)) {
12052 pos += snprintf(pos, end - pos, "%s264", count > 0 ? "," : "");
12053 count++;
12054 }
12055
12056 val = get_param(cmd, "DOMAIN_LIST");
12057 if (val && atoi(val)) {
12058 pos += snprintf(pos, end - pos, "%s268", count > 0 ? "," : "");
12059 count++;
12060 }
12061
Jouni Malinen34cf9532018-04-29 19:26:33 +030012062 val = get_param(cmd, "Venue_URL");
12063 if (val && atoi(val)) {
12064 pos += snprintf(pos, end - pos, "%s277", count > 0 ? "," : "");
12065 count++;
12066 }
12067
Jouni Malinend3bca5d2018-04-29 17:25:23 +030012068 val = get_param(cmd, "Advice_Of_Charge");
12069 if (val && atoi(val)) {
12070 pos += snprintf(pos, end - pos, "%s278", count > 0 ? "," : "");
12071 count++;
12072 }
12073
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012074 if (count && wpa_command(intf, buf)) {
12075 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,ANQP_GET failed");
12076 return 0;
12077 }
12078
12079 pos = buf;
12080 end = buf + sizeof(buf);
12081 count2 = 0;
12082 pos += snprintf(pos, end - pos, "HS20_ANQP_GET %s ", dest);
12083
12084 val = get_param(cmd, "HS_CAP_LIST");
12085 if (val && atoi(val)) {
12086 pos += snprintf(pos, end - pos, "%s2", count2 > 0 ? "," : "");
12087 count2++;
12088 }
12089
12090 val = get_param(cmd, "OPER_NAME");
12091 if (val && atoi(val)) {
12092 pos += snprintf(pos, end - pos, "%s3", count2 > 0 ? "," : "");
12093 count2++;
12094 }
12095
12096 val = get_param(cmd, "WAN_METRICS");
12097 if (!val)
12098 val = get_param(cmd, "WAN_MAT");
12099 if (!val)
12100 val = get_param(cmd, "WAN_MET");
12101 if (val && atoi(val)) {
12102 pos += snprintf(pos, end - pos, "%s4", count2 > 0 ? "," : "");
12103 count2++;
12104 }
12105
12106 val = get_param(cmd, "CONNECTION_CAPABILITY");
12107 if (val && atoi(val)) {
12108 pos += snprintf(pos, end - pos, "%s5", count2 > 0 ? "," : "");
12109 count2++;
12110 }
12111
12112 val = get_param(cmd, "OP_CLASS");
12113 if (val && atoi(val)) {
12114 pos += snprintf(pos, end - pos, "%s7", count2 > 0 ? "," : "");
12115 count2++;
12116 }
12117
12118 val = get_param(cmd, "OSU_PROVIDER_LIST");
12119 if (val && atoi(val)) {
12120 pos += snprintf(pos, end - pos, "%s8", count2 > 0 ? "," : "");
12121 count2++;
12122 }
12123
Jouni Malinenf67afec2018-04-29 19:24:58 +030012124 val = get_param(cmd, "OPER_ICON_METADATA");
12125 if (!val)
12126 val = get_param(cmd, "OPERATOR_ICON_METADATA");
12127 if (val && atoi(val)) {
12128 pos += snprintf(pos, end - pos, "%s12", count2 > 0 ? "," : "");
12129 count2++;
12130 }
12131
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012132 if (count && count2) {
12133 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before sending out "
12134 "second query");
12135 sleep(1);
12136 }
12137
12138 if (count2 && wpa_command(intf, buf)) {
12139 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,HS20_ANQP_GET "
12140 "failed");
12141 return 0;
12142 }
12143
12144 val = get_param(cmd, "NAI_HOME_REALM_LIST");
12145 if (val) {
12146 if (count || count2) {
12147 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
12148 "sending out second query");
12149 sleep(1);
12150 }
12151
12152 if (strcmp(val, "1") == 0)
12153 val = "mail.example.com";
12154 snprintf(buf, end - pos,
12155 "HS20_GET_NAI_HOME_REALM_LIST %s realm=%s",
12156 dest, val);
12157 if (wpa_command(intf, buf)) {
12158 send_resp(dut, conn, SIGMA_ERROR,
12159 "ErrorCode,HS20_GET_NAI_HOME_REALM_LIST "
12160 "failed");
12161 return 0;
12162 }
12163 }
12164
12165 val = get_param(cmd, "ICON_REQUEST");
12166 if (val) {
12167 if (count || count2) {
12168 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
12169 "sending out second query");
12170 sleep(1);
12171 }
12172
12173 snprintf(buf, end - pos,
12174 "HS20_ICON_REQUEST %s %s", dest, val);
12175 if (wpa_command(intf, buf)) {
12176 send_resp(dut, conn, SIGMA_ERROR,
12177 "ErrorCode,HS20_ICON_REQUEST failed");
12178 return 0;
12179 }
12180 }
12181
12182 return 1;
12183}
12184
12185
12186static int ath_sta_send_frame_vht(struct sigma_dut *dut,
12187 struct sigma_conn *conn,
12188 struct sigma_cmd *cmd)
12189{
12190 const char *val;
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012191 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012192 int chwidth, nss;
12193
12194 val = get_param(cmd, "framename");
12195 if (!val)
12196 return -1;
12197 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
12198
12199 /* Command sequence to generate Op mode notification */
12200 if (val && strcasecmp(val, "Op_md_notif_frm") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012201 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012202
12203 /* Disable STBC */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012204 run_iwpriv(dut, ifname, "tx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012205
12206 /* Extract Channel width */
12207 val = get_param(cmd, "Channel_width");
12208 if (val) {
12209 switch (atoi(val)) {
12210 case 20:
12211 chwidth = 0;
12212 break;
12213 case 40:
12214 chwidth = 1;
12215 break;
12216 case 80:
12217 chwidth = 2;
12218 break;
12219 case 160:
12220 chwidth = 3;
12221 break;
12222 default:
12223 chwidth = 2;
12224 break;
12225 }
12226
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012227 run_iwpriv(dut, ifname, "chwidth %d", chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012228 }
12229
12230 /* Extract NSS */
12231 val = get_param(cmd, "NSS");
12232 if (val) {
12233 switch (atoi(val)) {
12234 case 1:
12235 nss = 1;
12236 break;
12237 case 2:
12238 nss = 3;
12239 break;
12240 case 3:
12241 nss = 7;
12242 break;
12243 default:
12244 /* We do not support NSS > 3 */
12245 nss = 3;
12246 break;
12247 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012248 run_iwpriv(dut, ifname, "rxchainmask %d", nss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012249 }
12250
12251 /* Opmode notify */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012252 run_iwpriv(dut, ifname, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012253 }
12254
12255 return 1;
12256}
12257
12258
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070012259static int wcn_sta_set_pmf_config(struct sigma_dut *dut, const char *intf,
12260 enum send_frame_protection protected)
12261{
12262#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +053012263 return wcn_wifi_test_config_set_u8(
12264 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_PMF_PROTECTION,
12265 protected);
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070012266#else /* NL80211_SUPPORT */
12267 sigma_dut_print(dut, DUT_MSG_ERROR,
12268 "PMF config cannot be set without NL80211_SUPPORT defined");
12269 return -1;
12270#endif /* NL80211_SUPPORT */
12271}
12272
12273
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012274static int cmd_sta_send_frame_vht(struct sigma_dut *dut,
12275 struct sigma_conn *conn,
12276 struct sigma_cmd *cmd)
12277{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012278 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012279 case DRIVER_ATHEROS:
12280 return ath_sta_send_frame_vht(dut, conn, cmd);
12281 default:
12282 send_resp(dut, conn, SIGMA_ERROR,
12283 "errorCode,Unsupported sta_set_frame(VHT) with the current driver");
12284 return 0;
12285 }
12286}
12287
12288
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070012289static int wcn_sta_send_disassoc(struct sigma_dut *dut, const char *intf)
12290{
12291#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +053012292 return wcn_wifi_test_config_set_flag(
12293 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_DISASSOC_TX);
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070012294#else /* NL80211_SUPPORT */
12295 sigma_dut_print(dut, DUT_MSG_ERROR,
12296 "Disassoc Tx cannot be done without NL80211_SUPPORT defined");
12297 return -1;
12298#endif /* NL80211_SUPPORT */
12299}
12300
12301
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070012302static int wcn_sta_send_frame_he(struct sigma_dut *dut, struct sigma_conn *conn,
12303 struct sigma_cmd *cmd)
12304{
12305 const char *val;
12306 const char *intf = get_param(cmd, "Interface");
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070012307 enum send_frame_protection protected;
12308 const char *pmf;
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070012309
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030012310 if (!intf)
12311 return -1;
12312
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070012313 val = get_param(cmd, "framename");
12314 if (!val)
12315 return -1;
12316 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
12317
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070012318 pmf = get_param(cmd, "PMFProtected");
12319 if (!pmf)
12320 pmf = get_param(cmd, "Protected");
12321 if (pmf) {
12322 if (strcasecmp(pmf, "Correct-key") == 0 ||
12323 strcasecmp(pmf, "CorrectKey") == 0) {
12324 protected = CORRECT_KEY;
12325 } else if (strcasecmp(pmf, "IncorrectKey") == 0) {
12326 protected = INCORRECT_KEY;
12327 } else if (strcasecmp(pmf, "Unprotected") == 0) {
12328 protected = UNPROTECTED;
12329 } else {
12330 send_resp(dut, conn, SIGMA_ERROR,
12331 "errorCode,Unsupported PMFProtected");
12332 return STATUS_SENT_ERROR;
12333 }
12334 sigma_dut_print(dut, DUT_MSG_DEBUG, "Config PMF protection %d",
12335 protected);
12336 wcn_sta_set_pmf_config(dut, intf, protected);
12337 }
12338
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070012339 /* Command sequence to generate Op mode notification */
12340 if (val && strcasecmp(val, "action") == 0) {
12341 val = get_param(cmd, "PPDUTxType");
12342 if (val && strcasecmp(val, "TB") == 0) {
12343 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 1)) {
12344 sigma_dut_print(dut, DUT_MSG_ERROR,
12345 "failed to send TB PPDU Tx cfg");
12346 send_resp(dut, conn, SIGMA_ERROR,
12347 "ErrorCode,set TB PPDU Tx cfg failed");
12348 return 0;
12349 }
12350 return 1;
12351 }
12352
12353 sigma_dut_print(dut, DUT_MSG_ERROR,
12354 "Action Tx type is not defined");
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070012355
12356 return SUCCESS_SEND_STATUS;
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070012357 }
12358
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070012359 if (strcasecmp(val, "disassoc") == 0)
12360 wcn_sta_send_disassoc(dut, intf);
12361
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070012362 return 1;
12363}
12364
12365
12366static int cmd_sta_send_frame_he(struct sigma_dut *dut,
12367 struct sigma_conn *conn,
12368 struct sigma_cmd *cmd)
12369{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012370 switch (get_driver_type(dut)) {
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070012371 case DRIVER_WCN:
12372 return wcn_sta_send_frame_he(dut, conn, cmd);
12373 default:
12374 send_resp(dut, conn, SIGMA_ERROR,
12375 "errorCode,Unsupported sta_set_frame(HE) with the current driver");
12376 return 0;
12377 }
12378}
12379
12380
Lior David0fe101e2017-03-09 16:09:50 +020012381#ifdef __linux__
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030012382
12383static int
12384wil6210_send_p2p_frame_60g(struct sigma_dut *dut, struct sigma_cmd *cmd,
12385 const char *frame_name, const char *dest_mac)
12386{
12387 int isprobereq = strcasecmp(frame_name, "probereq") == 0;
12388 const char *ssid = get_param(cmd, "ssid");
12389 const char *countstr = get_param(cmd, "count");
12390 const char *channelstr = get_param(cmd, "channel");
12391 const char *group_id = get_param(cmd, "groupid");
12392 const char *client_id = get_param(cmd, "clientmac");
12393 int count, channel, freq, i;
12394 const char *fname;
12395 char frame[1024], src_mac[20], group_id_attr[25],
12396 device_macstr[3 * ETH_ALEN], client_mac[ETH_ALEN];
12397 const char *group_ssid;
12398 const int group_ssid_prefix_len = 9;
12399 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *) frame;
12400 size_t framelen = sizeof(frame);
12401 struct template_frame_tag tags[2];
12402 size_t tags_total = ARRAY_SIZE(tags);
12403 int tag_index, len, dst_len;
12404
12405 if (!countstr || !channelstr) {
12406 sigma_dut_print(dut, DUT_MSG_ERROR,
12407 "Missing argument: count, channel");
12408 return -1;
12409 }
12410 if (isprobereq && !ssid) {
12411 sigma_dut_print(dut, DUT_MSG_ERROR,
12412 "Missing argument: ssid");
12413 return -1;
12414 }
12415 if (!isprobereq && (!group_id || !client_id)) {
12416 sigma_dut_print(dut, DUT_MSG_ERROR,
12417 "Missing argument: group_id, client_id");
12418 return -1;
12419 }
12420
12421 count = atoi(countstr);
12422 channel = atoi(channelstr);
12423 freq = channel_to_freq(dut, channel);
12424
12425 if (!freq) {
12426 sigma_dut_print(dut, DUT_MSG_ERROR,
12427 "invalid channel: %s", channelstr);
12428 return -1;
12429 }
12430
12431 if (isprobereq) {
12432 if (strcasecmp(ssid, "wildcard") == 0) {
12433 fname = "probe_req_wildcard.txt";
12434 } else if (strcasecmp(ssid, "P2P_Wildcard") == 0) {
12435 fname = "probe_req_P2P_Wildcard.txt";
12436 } else {
12437 sigma_dut_print(dut, DUT_MSG_ERROR,
12438 "invalid probe request type");
12439 return -1;
12440 }
12441 } else {
12442 fname = "P2P_device_discovery_req.txt";
12443 }
12444
12445 if (parse_template_frame_file(dut, fname, frame, &framelen,
12446 tags, &tags_total)) {
12447 sigma_dut_print(dut, DUT_MSG_ERROR,
12448 "invalid frame template: %s", fname);
12449 return -1;
12450 }
12451
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012452 if (get_wpa_status(get_station_ifname(dut), "address",
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030012453 src_mac, sizeof(src_mac)) < 0 ||
12454 parse_mac_address(dut, src_mac, &hdr->addr2[0]) ||
12455 parse_mac_address(dut, dest_mac, &hdr->addr1[0]))
12456 return -1;
12457 /* Use wildcard BSSID, since we are in PBSS */
12458 memset(&hdr->addr3, 0xFF, ETH_ALEN);
12459
12460 if (!isprobereq) {
12461 tag_index = find_template_frame_tag(tags, tags_total, 1);
12462 if (tag_index < 0) {
12463 sigma_dut_print(dut, DUT_MSG_ERROR,
12464 "can't find device id attribute");
12465 return -1;
12466 }
12467 if (parse_mac_address(dut, client_id,
12468 (unsigned char *) client_mac)) {
12469 sigma_dut_print(dut, DUT_MSG_ERROR,
12470 "invalid client_id: %s", client_id);
12471 return -1;
12472 }
12473 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
12474 framelen - tags[tag_index].offset,
12475 IEEE80211_P2P_ATTR_DEVICE_ID,
12476 client_mac, ETH_ALEN)) {
12477 sigma_dut_print(dut, DUT_MSG_ERROR,
12478 "fail to replace device id attribute");
12479 return -1;
12480 }
12481
12482 /*
12483 * group_id arg contains device MAC address followed by
12484 * space and SSID (DIRECT-somessid).
12485 * group id attribute contains device address (6 bytes)
12486 * followed by SSID prefix DIRECT-XX (9 bytes)
12487 */
12488 if (strlen(group_id) < sizeof(device_macstr)) {
12489 sigma_dut_print(dut, DUT_MSG_ERROR,
12490 "group_id arg too short");
12491 return -1;
12492 }
12493 memcpy(device_macstr, group_id, sizeof(device_macstr));
12494 device_macstr[sizeof(device_macstr) - 1] = '\0';
12495 if (parse_mac_address(dut, device_macstr,
12496 (unsigned char *) group_id_attr)) {
12497 sigma_dut_print(dut, DUT_MSG_ERROR,
12498 "fail to parse device address from group_id");
12499 return -1;
12500 }
12501 group_ssid = strchr(group_id, ' ');
12502 if (!group_ssid) {
12503 sigma_dut_print(dut, DUT_MSG_ERROR,
12504 "invalid group_id arg, no ssid");
12505 return -1;
12506 }
12507 group_ssid++;
12508 len = strlen(group_ssid);
12509 if (len < group_ssid_prefix_len) {
12510 sigma_dut_print(dut, DUT_MSG_ERROR,
12511 "group_id SSID too short");
12512 return -1;
12513 }
12514 dst_len = sizeof(group_id_attr) - ETH_ALEN;
12515 if (len > dst_len) {
12516 sigma_dut_print(dut, DUT_MSG_ERROR,
12517 "group_id SSID (%s) too long",
12518 group_ssid);
12519 return -1;
12520 }
12521
12522 memcpy(group_id_attr + ETH_ALEN, group_ssid, len);
12523 tag_index = find_template_frame_tag(tags, tags_total, 2);
12524 if (tag_index < 0) {
12525 sigma_dut_print(dut, DUT_MSG_ERROR,
12526 "can't find group id attribute");
12527 return -1;
12528 }
12529 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
12530 framelen - tags[tag_index].offset,
12531 IEEE80211_P2P_ATTR_GROUP_ID,
12532 group_id_attr,
12533 sizeof(group_id_attr))) {
12534 sigma_dut_print(dut, DUT_MSG_ERROR,
12535 "fail to replace group id attribute");
12536 return -1;
12537 }
12538 }
12539
12540 for (i = 0; i < count; i++) {
12541 if (wil6210_transmit_frame(dut, freq,
12542 WIL_TRANSMIT_FRAME_DEFAULT_ROC,
12543 frame, framelen)) {
12544 sigma_dut_print(dut, DUT_MSG_ERROR,
12545 "fail to transmit probe request frame");
12546 return -1;
12547 }
12548 }
12549
12550 return 0;
12551}
12552
12553
Lior David0fe101e2017-03-09 16:09:50 +020012554int wil6210_send_frame_60g(struct sigma_dut *dut, struct sigma_conn *conn,
12555 struct sigma_cmd *cmd)
12556{
12557 const char *frame_name = get_param(cmd, "framename");
12558 const char *mac = get_param(cmd, "dest_mac");
12559
12560 if (!frame_name || !mac) {
12561 sigma_dut_print(dut, DUT_MSG_ERROR,
12562 "framename and dest_mac must be provided");
12563 return -1;
12564 }
12565
12566 if (strcasecmp(frame_name, "brp") == 0) {
12567 const char *l_rx = get_param(cmd, "L-RX");
12568 int l_rx_i;
12569
12570 if (!l_rx) {
12571 sigma_dut_print(dut, DUT_MSG_ERROR,
12572 "L-RX must be provided");
12573 return -1;
12574 }
12575 l_rx_i = atoi(l_rx);
12576
12577 sigma_dut_print(dut, DUT_MSG_INFO,
12578 "dev_send_frame: BRP-RX, dest_mac %s, L-RX %s",
12579 mac, l_rx);
12580 if (l_rx_i != 16) {
12581 sigma_dut_print(dut, DUT_MSG_ERROR,
12582 "unsupported L-RX: %s", l_rx);
12583 return -1;
12584 }
12585
12586 if (wil6210_send_brp_rx(dut, mac, l_rx_i))
12587 return -1;
12588 } else if (strcasecmp(frame_name, "ssw") == 0) {
12589 sigma_dut_print(dut, DUT_MSG_INFO,
12590 "dev_send_frame: SLS, dest_mac %s", mac);
12591 if (wil6210_send_sls(dut, mac))
12592 return -1;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030012593 } else if ((strcasecmp(frame_name, "probereq") == 0) ||
12594 (strcasecmp(frame_name, "devdiscreq") == 0)) {
12595 sigma_dut_print(dut, DUT_MSG_INFO,
12596 "dev_send_frame: %s, dest_mac %s", frame_name,
12597 mac);
12598 if (wil6210_send_p2p_frame_60g(dut, cmd, frame_name, mac))
12599 return -1;
Lior David0fe101e2017-03-09 16:09:50 +020012600 } else {
12601 sigma_dut_print(dut, DUT_MSG_ERROR,
12602 "unsupported frame type: %s", frame_name);
12603 return -1;
12604 }
12605
12606 return 1;
12607}
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030012608
Lior David0fe101e2017-03-09 16:09:50 +020012609#endif /* __linux__ */
12610
12611
12612static int cmd_sta_send_frame_60g(struct sigma_dut *dut,
12613 struct sigma_conn *conn,
12614 struct sigma_cmd *cmd)
12615{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012616 switch (get_driver_type(dut)) {
Lior David0fe101e2017-03-09 16:09:50 +020012617#ifdef __linux__
12618 case DRIVER_WIL6210:
12619 return wil6210_send_frame_60g(dut, conn, cmd);
12620#endif /* __linux__ */
12621 default:
12622 send_resp(dut, conn, SIGMA_ERROR,
12623 "errorCode,Unsupported sta_set_frame(60G) with the current driver");
12624 return 0;
12625 }
12626}
12627
12628
Ashwini Patildb59b3c2017-04-13 15:19:23 +053012629static int mbo_send_anqp_query(struct sigma_dut *dut, struct sigma_conn *conn,
12630 const char *intf, struct sigma_cmd *cmd)
12631{
12632 const char *val, *addr;
12633 char buf[100];
12634
12635 addr = get_param(cmd, "DestMac");
12636 if (!addr) {
12637 send_resp(dut, conn, SIGMA_INVALID,
12638 "ErrorCode,AP MAC address is missing");
12639 return 0;
12640 }
12641
12642 val = get_param(cmd, "ANQPQuery_ID");
12643 if (!val) {
12644 send_resp(dut, conn, SIGMA_INVALID,
12645 "ErrorCode,Missing ANQPQuery_ID");
12646 return 0;
12647 }
12648
12649 if (strcasecmp(val, "NeighborReportReq") == 0) {
12650 snprintf(buf, sizeof(buf), "ANQP_GET %s 272", addr);
12651 } else if (strcasecmp(val, "QueryListWithCellPref") == 0) {
12652 snprintf(buf, sizeof(buf), "ANQP_GET %s 272,mbo:2", addr);
12653 } else {
12654 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid ANQPQuery_ID: %s",
12655 val);
12656 send_resp(dut, conn, SIGMA_INVALID,
12657 "ErrorCode,Invalid ANQPQuery_ID");
12658 return 0;
12659 }
12660
Ashwini Patild174f2c2017-04-13 16:49:46 +053012661 /* Set gas_address3 field to IEEE 802.11-2012 standard compliant form
12662 * (Address3 = Wildcard BSSID when sent to not-associated AP;
12663 * if associated, AP BSSID).
12664 */
12665 if (wpa_command(intf, "SET gas_address3 1") < 0) {
12666 send_resp(dut, conn, SIGMA_ERROR,
12667 "ErrorCode,Failed to set gas_address3");
12668 return 0;
12669 }
12670
Ashwini Patildb59b3c2017-04-13 15:19:23 +053012671 if (wpa_command(intf, buf) < 0) {
12672 send_resp(dut, conn, SIGMA_ERROR,
12673 "ErrorCode,Failed to send ANQP query");
12674 return 0;
12675 }
12676
12677 return 1;
12678}
12679
12680
12681static int mbo_cmd_sta_send_frame(struct sigma_dut *dut,
12682 struct sigma_conn *conn,
12683 const char *intf,
12684 struct sigma_cmd *cmd)
12685{
12686 const char *val = get_param(cmd, "FrameName");
12687
12688 if (val && strcasecmp(val, "ANQPQuery") == 0)
12689 return mbo_send_anqp_query(dut, conn, intf, cmd);
12690
12691 return 2;
12692}
12693
12694
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053012695static enum sigma_cmd_result cmd_sta_send_frame_wpa3(struct sigma_dut *dut,
12696 struct sigma_conn *conn,
12697 const char *intf,
12698 struct sigma_cmd *cmd)
12699{
12700 const char *val = get_param(cmd, "framename");
12701
12702 if (!val)
12703 return INVALID_SEND_STATUS;
12704
12705 if (strcasecmp(val, "SAQueryReq") == 0) {
12706 val = get_param(cmd, "OCIChannel");
12707
12708 if (!val) {
12709 send_resp(dut, conn, SIGMA_ERROR,
12710 "errorCode,OCIChannel not present");
12711 return STATUS_SENT_ERROR;
12712 }
12713
12714 dut->saquery_oci_freq = channel_to_freq(dut, atoi(val));
12715 if (!dut->saquery_oci_freq) {
12716 send_resp(dut, conn, SIGMA_ERROR,
12717 "errorCode,Invalid OCIChannel number");
12718 return STATUS_SENT_ERROR;
12719 }
12720
12721 return sta_inject_frame(dut, conn, intf, SAQUERY, CORRECT_KEY,
12722 NULL, 0);
12723 }
12724
12725 if (strcasecmp(val, "reassocreq") == 0)
12726 return sta_inject_frame(dut, conn, intf, REASSOCREQ,
12727 CORRECT_KEY, NULL, 0);
12728
Veerendranath9f81dfb2020-08-10 01:21:29 -070012729 if (strcasecmp(val, "ANQPQuery") == 0) {
12730 char buf[50];
12731 const char *dest = get_param(cmd, "DestMac");
12732 const char *chan = get_param(cmd, "channel");
Veerendranath Jakkam78862fc2020-11-19 21:23:27 +053012733 const char *freq_str = get_param(cmd, "ChnlFreq");
Veerendranath9f81dfb2020-08-10 01:21:29 -070012734 int len, freq;
12735
Veerendranath Jakkam78862fc2020-11-19 21:23:27 +053012736 if (freq_str)
12737 freq = atoi(freq_str);
12738 else
12739 freq = chan ? channel_to_freq(dut, atoi(chan)) : 0;
12740
Veerendranath9f81dfb2020-08-10 01:21:29 -070012741 if (!dest || !freq)
12742 return INVALID_SEND_STATUS;
12743
12744 len = snprintf(buf, sizeof(buf), "ANQP_GET %s freq=%d 257",
12745 dest, freq);
12746 if (len < 0 || len >= sizeof(buf)) {
12747 sigma_dut_print(dut, DUT_MSG_ERROR,
12748 "Failed to allocate buf");
12749 return ERROR_SEND_STATUS;
12750 }
12751
12752 if (wpa_command(intf, buf) != 0) {
12753 send_resp(dut, conn, SIGMA_ERROR,
12754 "ErrorCode,Failed to send ANQP Query frame");
12755 return STATUS_SENT_ERROR;
12756 }
12757
12758 sigma_dut_print(dut, DUT_MSG_DEBUG,
12759 "ANQP Query sent: %s", buf);
12760
12761 return SUCCESS_SEND_STATUS;
12762 }
12763
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053012764 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported framename");
12765 return STATUS_SENT_ERROR;
12766}
12767
12768
Vinita S. Malooca85fd22021-01-15 02:54:34 +053012769static int
12770get_type4_frame_classifier(struct sigma_dut *dut, struct sigma_cmd *cmd,
12771 char *pos, int rem_len, int num_of_scs_desc,
12772 int num_of_tclas_elem)
12773{
12774 const char *val;
12775 int ipv6;
12776 int len, total_len = 0;
12777
12778 val = get_param_fmt(cmd, "TCLASElem_Version_%d_%d", num_of_scs_desc,
12779 num_of_tclas_elem);
12780 if (!val) {
12781 sigma_dut_print(dut, DUT_MSG_ERROR, "%s: ip_version empty",
12782 __func__);
12783 return -1;
12784 }
12785
12786 if (strcmp(val, "6") == 0) {
12787 ipv6 = 1;
12788 } else if (strcmp(val, "4") == 0) {
12789 ipv6 = 0;
12790 } else {
12791 sigma_dut_print(dut, DUT_MSG_ERROR, "%s: ip_version invalid",
12792 __func__);
12793 return -1;
12794 }
12795
12796 len = snprintf(pos, rem_len, " ip_version=%s", ipv6 ? "ipv6" : "ipv4");
12797 if (len < 0 || len >= rem_len)
12798 return -1;
12799
12800 pos += len;
12801 rem_len -= len;
12802 total_len += len;
12803
12804 val = get_param_fmt(cmd, "TCLASElem_SourceIPAddr_%d_%d",
12805 num_of_scs_desc, num_of_tclas_elem);
12806 if (val) {
12807 len = snprintf(pos, rem_len, " src_ip=%s", val);
12808 if (len < 0 || len >= rem_len)
12809 return -1;
12810
12811 pos += len;
12812 rem_len -= len;
12813 total_len += len;
12814 }
12815
12816 val = get_param_fmt(cmd, "TCLASElem_DestinationIPAddr_%d_%d",
12817 num_of_scs_desc, num_of_tclas_elem);
12818 if (val) {
12819 len = snprintf(pos, rem_len, " dst_ip=%s", val);
12820 if (len < 0 || len >= rem_len)
12821 return -1;
12822
12823 pos += len;
12824 rem_len -= len;
12825 total_len += len;
12826 }
12827
12828 val = get_param_fmt(cmd, "TCLASElem_SourcePort_%d_%d", num_of_scs_desc,
12829 num_of_tclas_elem);
12830 if (val) {
12831 len = snprintf(pos, rem_len, " src_port=%s", val);
12832 if (len < 0 || len >= rem_len)
12833 return -1;
12834
12835 pos += len;
12836 rem_len -= len;
12837 total_len += len;
12838 }
12839
12840 val = get_param_fmt(cmd, "TCLASElem_DestinationPort_%d_%d",
12841 num_of_scs_desc, num_of_tclas_elem);
12842 if (val) {
12843 len = snprintf(pos, rem_len, " dst_port=%s", val);
12844 if (len < 0 || len >= rem_len)
12845 return -1;
12846
12847 pos += len;
12848 rem_len -= len;
12849 total_len += len;
12850 }
12851
12852 val = get_param_fmt(cmd, "TCLASElem_DSCP_%d_%d", num_of_scs_desc,
12853 num_of_tclas_elem);
12854 if (val) {
12855 len = snprintf(pos, rem_len, " dscp=%s", val);
12856 if (len < 0 || len >= rem_len)
12857 return -1;
12858
12859 pos += len;
12860 rem_len -= len;
12861 total_len += len;
12862 }
12863
12864 val = get_param_fmt(cmd, "TCLASElem_ProtocolNxtHeader_%d_%d",
12865 num_of_scs_desc, num_of_tclas_elem);
12866 if (val) {
12867 char *prot;
12868
12869 switch (atoi(val)) {
12870 case 17:
12871 prot = "udp";
12872 break;
12873 case 6:
12874 prot = "tcp";
12875 break;
12876 case 50:
12877 prot = "esp";
12878 break;
12879 default:
12880 sigma_dut_print(dut, DUT_MSG_ERROR,
12881 "Invalid protocol %d", atoi(val));
12882 return -1;
12883 }
12884
12885 if (ipv6)
12886 len = snprintf(pos, rem_len, " next_header=%s", prot);
12887 else
12888 len = snprintf(pos, rem_len, " protocol=%s", prot);
12889 if (len < 0 || len >= rem_len)
12890 return -1;
12891
12892 pos += len;
12893 rem_len -= len;
12894 total_len += len;
12895 }
12896
12897 return total_len;
12898}
12899
12900
12901static int
12902get_type10_frame_classifier(struct sigma_dut *dut, struct sigma_cmd *cmd,
12903 char *pos, int rem_len, int num_of_scs_desc,
12904 int num_of_tclas_elem)
12905{
12906 const char *val;
12907 int len, total_len = 0;
12908
12909 val = get_param_fmt(cmd, "TCLASElem_ProtoInstance_%d_%d",
12910 num_of_scs_desc, num_of_tclas_elem);
12911 if (val) {
12912 len = snprintf(pos, rem_len, " prot_instance=%s",
12913 val);
12914 if (len < 0 || len >= rem_len)
12915 return -1;
12916
12917 pos += len;
12918 rem_len -= len;
12919 total_len += len;
12920 }
12921
12922 val = get_param_fmt(cmd, "TCLASElem_ProtoNumNextHeader_%d_%d",
12923 num_of_scs_desc, num_of_tclas_elem);
12924 if (val) {
12925 char *prot;
12926
12927 switch (atoi(val)) {
12928 case 17:
12929 prot = "udp";
12930 break;
12931 case 6:
12932 prot = "tcp";
12933 break;
12934 case 50:
12935 prot = "esp";
12936 break;
12937 default:
12938 sigma_dut_print(dut, DUT_MSG_ERROR,
12939 "Invalid protocol %d",
12940 atoi(val));
12941 return -1;
12942 }
12943
12944 len = snprintf(pos, rem_len, " prot_number=%s", prot);
12945 if (len < 0 || len >= rem_len)
12946 return -1;
12947
12948 pos += len;
12949 rem_len -= len;
12950 total_len += len;
12951 }
12952
12953 val = get_param_fmt(cmd, "TCLASElem_FilterValue_%d_%d",
12954 num_of_scs_desc, num_of_tclas_elem);
12955 if (val) {
12956 len = snprintf(pos, rem_len, " filter_value=%s", (val + 2));
12957 if (len < 0 || len >= rem_len)
12958 return -1;
12959
12960 pos += len;
12961 rem_len -= len;
12962 total_len += len;
12963 }
12964
12965 val = get_param_fmt(cmd, "TCLASElem_FilterMask_%d_%d", num_of_scs_desc,
12966 num_of_tclas_elem);
12967 if (val && strlen(val) >= 2) {
12968 len = snprintf(pos, rem_len, " filter_mask=%s", val + 2);
12969 if (len < 0 || len >= rem_len)
12970 return -1;
12971
12972 pos += len;
12973 rem_len -= len;
12974 total_len += len;
12975 }
12976
12977 return total_len;
12978}
12979
12980
12981static enum sigma_cmd_result
12982cmd_sta_send_frame_scs(struct sigma_dut *dut, struct sigma_conn *conn,
12983 const char *intf, struct sigma_cmd *cmd)
12984{
12985 char buf[4096], *pos;
12986 const char *val, *scs_id, *classifier_type;
12987 int len, rem_len, total_bytes;
12988 int num_of_scs_desc = 0, num_of_tclas_elem = 0;
12989
12990 scs_id = get_param(cmd, "SCSDescrElem_SCSID_1");
12991 if (!scs_id) {
12992 sigma_dut_print(dut, DUT_MSG_ERROR, "SCS ID empty");
12993 return INVALID_SEND_STATUS;
12994 }
12995
12996 rem_len = sizeof(buf);
12997 pos = buf;
12998
12999 len = snprintf(buf, sizeof(buf), "SCS");
13000 if (len < 0 || len > rem_len)
13001 goto fail;
13002
13003 pos += len;
13004 rem_len -= len;
13005
13006 while (scs_id) {
13007 num_of_scs_desc++;
13008
13009 val = get_param_fmt(cmd, "SCSDescrElem_RequestType_%d",
13010 num_of_scs_desc);
13011 if (!val)
13012 return INVALID_SEND_STATUS;
13013
13014 if (strcasecmp(val, "Add") == 0) {
13015 len = snprintf(pos, rem_len, " scs_id=%s add",
13016 scs_id);
13017 } else if (strcasecmp(val, "Change") == 0) {
13018 len = snprintf(pos, rem_len, " scs_id=%s change",
13019 scs_id);
13020 } else if (strcasecmp(val, "Remove") == 0) {
13021 len = snprintf(pos, rem_len, " scs_id=%s remove",
13022 scs_id);
13023 if (len < 0 || len >= rem_len)
13024 goto fail;
13025
13026 pos += len;
13027 rem_len -= len;
13028 goto scs_desc_end;
13029 } else {
13030 sigma_dut_print(dut, DUT_MSG_ERROR,
13031 "%s: request type - %s is invalid",
13032 __func__, val);
13033 return INVALID_SEND_STATUS;
13034 }
13035
13036 if (len < 0 || len >= rem_len)
13037 goto fail;
13038
13039 pos += len;
13040 rem_len -= len;
13041
13042 val = get_param_fmt(cmd, "IntraAccessCatElem_UP_%d",
13043 num_of_scs_desc);
13044 if (!val) {
13045 sigma_dut_print(dut, DUT_MSG_ERROR,
13046 "IntraAccess Priority empty");
13047 return INVALID_SEND_STATUS;
13048 }
13049
13050 len = snprintf(pos, rem_len, " scs_up=%s", val);
13051 if (len < 0 || len >= rem_len)
13052 goto fail;
13053
13054 pos += len;
13055 rem_len -= len;
13056
13057 classifier_type = get_param_fmt(cmd,
13058 "TCLASElem_ClassifierType_%d_1",
13059 num_of_scs_desc);
13060 if (!classifier_type) {
13061 sigma_dut_print(dut, DUT_MSG_ERROR,
13062 "classifier type missing");
13063 return INVALID_SEND_STATUS;
13064 }
13065
13066 while (classifier_type) {
13067 num_of_tclas_elem++;
13068
13069 len = snprintf(pos, rem_len, " classifier_type=%s",
13070 classifier_type);
13071 if (len < 0 || len >= rem_len)
13072 goto fail;
13073
13074 pos += len;
13075 rem_len -= len;
13076
13077 if (strcmp(classifier_type, "10") == 0) {
13078 total_bytes = get_type10_frame_classifier(
13079 dut, cmd, pos, rem_len,
13080 num_of_scs_desc,
13081 num_of_tclas_elem);
13082 } else if (strcmp(classifier_type, "4") == 0) {
13083 total_bytes = get_type4_frame_classifier(
13084 dut, cmd, pos, rem_len,
13085 num_of_scs_desc,
13086 num_of_tclas_elem);
13087 } else {
13088 sigma_dut_print(dut, DUT_MSG_ERROR,
13089 "classifier_type invalid");
13090 goto fail;
13091 }
13092
13093 if (total_bytes < 0)
13094 goto fail;
13095
13096 pos += total_bytes;
13097 rem_len -= total_bytes;
13098
13099 classifier_type = get_param_fmt(
13100 cmd, "TCLASElem_ClassifierType_%d_%d",
13101 num_of_scs_desc, num_of_tclas_elem + 1);
13102 }
13103
13104 if (num_of_tclas_elem > 1) {
13105 val = get_param_fmt(cmd,
13106 "TCLASProcessingElem_Processing_%d",
13107 num_of_scs_desc);
13108 if (!val) {
13109 sigma_dut_print(dut, DUT_MSG_ERROR,
13110 "Tclas_processing element %d empty",
13111 num_of_scs_desc);
13112 goto fail;
13113 }
13114
13115 len = snprintf(pos, rem_len,
13116 " tclas_processing=%s", val);
13117 if (len < 0 || len >= rem_len)
13118 goto fail;
13119
13120 pos += len;
13121 rem_len -= len;
13122 }
13123scs_desc_end:
13124 num_of_tclas_elem = 0;
13125 scs_id = get_param_fmt(cmd, "SCSDescrElem_SCSID_%d",
13126 num_of_scs_desc + 1);
13127 }
13128
13129 if (wpa_command(intf, buf) != 0) {
13130 send_resp(dut, conn, SIGMA_ERROR,
13131 "ErrorCode,Failed to send SCS frame request");
13132 return STATUS_SENT_ERROR;
13133 }
13134
13135 sigma_dut_print(dut, DUT_MSG_DEBUG,
13136 "SCS frame request sent: %s", buf);
13137
13138 return SUCCESS_SEND_STATUS;
13139fail:
13140 sigma_dut_print(dut, DUT_MSG_ERROR,
13141 "Failed to create SCS frame request");
13142 return ERROR_SEND_STATUS;
13143}
13144
13145
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053013146static enum sigma_cmd_result
13147cmd_sta_send_frame_mscs(struct sigma_dut *dut, struct sigma_conn *conn,
13148 const char *intf, struct sigma_cmd *cmd)
13149{
13150 char buf[128], *pos;
13151 const char *val, *classifier_type = "04", *type;
13152 int len, rem_len;
13153 u8 up_bitmap;
13154
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053013155 type = get_param(cmd, "Request_Type");
Vinita S. Malooca85fd22021-01-15 02:54:34 +053013156 if (!type) {
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053013157 sigma_dut_print(dut, DUT_MSG_ERROR,
Vinita S. Malooca85fd22021-01-15 02:54:34 +053013158 "%s: type not valid", __func__);
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053013159 return INVALID_SEND_STATUS;
13160 }
13161
13162 rem_len = sizeof(buf);
13163 pos = buf;
13164 if (strcasecmp(type, "add") == 0) {
13165 len = snprintf(pos, rem_len, "MSCS add");
13166 } else if (strcasecmp(type, "update") == 0) {
13167 len = snprintf(pos, rem_len, "MSCS change");
13168 } else if (strcasecmp(type, "remove") == 0) {
13169 if (wpa_command(intf, "MSCS remove") != 0) {
13170 send_resp(dut, conn, SIGMA_ERROR,
13171 "ErrorCode,Failed to send MSCS frame req");
13172 return STATUS_SENT_ERROR;
13173 }
13174 return SUCCESS_SEND_STATUS;
13175 } else {
13176 sigma_dut_print(dut, DUT_MSG_ERROR,
13177 "%s: request type invalid", __func__);
13178 return INVALID_SEND_STATUS;
13179 }
13180
13181 if (len < 0 || len >= rem_len)
13182 goto fail;
13183
13184 pos += len;
13185 rem_len -= len;
13186
13187 val = get_param(cmd, "User_Priority_Bitmap");
13188 if (!val) {
13189 sigma_dut_print(dut, DUT_MSG_ERROR,
13190 "%s: user priority bitmap empty", __func__);
13191 return INVALID_SEND_STATUS;
13192 }
13193
13194 switch (atoi(val)) {
13195 case 0:
13196 up_bitmap = 0x00;
13197 break;
13198 case 1:
13199 up_bitmap = 0xF0;
13200 break;
13201 case 2:
13202 up_bitmap = 0xF6;
13203 break;
13204 default:
13205 sigma_dut_print(dut, DUT_MSG_ERROR,
13206 "%s: Unknown User_Priority_Bitmap value %d",
13207 __func__, atoi(val));
13208 return INVALID_SEND_STATUS;
13209 }
13210
13211 len = snprintf(pos, rem_len, " up_bitmap=%02x", up_bitmap);
13212 if (len < 0 || len >= rem_len)
13213 goto fail;
13214
13215 pos += len;
13216 rem_len -= len;
13217
13218 val = get_param(cmd, "User_Priority_Limit");
13219 if (!val) {
13220 sigma_dut_print(dut, DUT_MSG_ERROR,
13221 "%s: invalid user priority limit", __func__);
13222 return INVALID_SEND_STATUS;
13223 }
13224
13225 len = snprintf(pos, rem_len, " up_limit=%s", val);
13226 if (len < 0 || len >= rem_len)
13227 goto fail;
13228
13229 pos += len;
13230 rem_len -= len;
13231
13232 val = get_param(cmd, "Stream_Timeout");
13233 if (!val)
13234 val = get_param(cmd, "Stream_Timtout");
13235 if (!val) {
13236 sigma_dut_print(dut, DUT_MSG_ERROR,
13237 "%s: invalid stream timeout", __func__);
13238 return INVALID_SEND_STATUS;
13239 }
13240
13241 len = snprintf(pos, rem_len, " stream_timeout=%s", val);
13242 if (len < 0 || len >= rem_len)
13243 goto fail;
13244
13245 pos += len;
13246 rem_len -= len;
13247
13248 val = get_param(cmd, "TCLAS_Mask");
13249 if (!val) {
13250 sigma_dut_print(dut, DUT_MSG_ERROR,
13251 "%s: invalid tclas mask", __func__);
13252 return INVALID_SEND_STATUS;
13253 }
13254
13255 len = snprintf(pos, rem_len, " frame_classifier=%s%lx%032x",
13256 classifier_type, strtol(val, NULL, 2), 0);
13257 if (len < 0 || len >= rem_len)
13258 goto fail;
13259
13260 if (wpa_command(intf, buf) != 0) {
13261 send_resp(dut, conn, SIGMA_ERROR,
13262 "ErrorCode,Failed to send MSCS frame req");
13263 return STATUS_SENT_ERROR;
13264 }
13265
13266 sigma_dut_print(dut, DUT_MSG_DEBUG,
13267 "MSCS frame request sent: %s", buf);
13268
13269 return SUCCESS_SEND_STATUS;
13270fail:
13271 sigma_dut_print(dut, DUT_MSG_ERROR,
13272 "Failed to create MSCS frame req");
13273 return ERROR_SEND_STATUS;
13274}
13275
13276
Vinita S. Malooca85fd22021-01-15 02:54:34 +053013277static enum sigma_cmd_result
Veerendranath Jakkam329a3cd2021-09-11 18:10:13 +053013278cmd_sta_send_frame_dscp_query(struct sigma_dut *dut, struct sigma_conn *conn,
13279 const char *intf, struct sigma_cmd *cmd)
13280{
13281 char buf[150], *pos;
13282 const char *val;
13283 int len, rem_len;
13284
13285 rem_len = sizeof(buf);
13286 pos = buf;
13287
13288 len = snprintf(pos, rem_len, "DSCP_QUERY");
13289 if (len < 0 || len >= rem_len)
13290 goto fail;
13291
13292 pos += len;
13293 rem_len -= len;
13294
13295 val = get_param(cmd, "Wildcard");
13296 if (val && strcasecmp(val, "Yes") == 0) {
13297 len = snprintf(pos, rem_len, " wildcard");
13298 if (len < 0 || len >= rem_len)
13299 goto fail;
13300 } else if (strlen(dut->qm_domain_name)) {
13301 len = snprintf(pos, rem_len, " domain_name=%s",
13302 dut->qm_domain_name);
13303 if (len < 0 || len >= rem_len)
13304 goto fail;
13305 } else {
13306 sigma_dut_print(dut, DUT_MSG_ERROR,
13307 "Invalid DSCP Query configuration");
13308 return INVALID_SEND_STATUS;
13309 }
13310
13311 if (wpa_command(intf, buf) != 0) {
13312 send_resp(dut, conn, SIGMA_ERROR,
13313 "ErrorCode,Failed to send DSCP policy query frame");
13314 return STATUS_SENT_ERROR;
13315 }
13316
13317 sigma_dut_print(dut, DUT_MSG_DEBUG,
13318 "DSCP policy query frame sent: %s", buf);
13319 return SUCCESS_SEND_STATUS;
13320fail:
13321 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to send DSCP query");
13322 return ERROR_SEND_STATUS;
13323}
13324
13325
13326static enum sigma_cmd_result
Veerendranath Jakkam1bf1bd62021-09-12 16:35:55 +053013327cmd_sta_send_frame_dscp_response(struct sigma_dut *dut, struct sigma_conn *conn,
13328 const char *intf, struct sigma_cmd *cmd)
13329{
13330 char buf[256], *pos, *item, *list, *saveptr;
13331 const char *val;
13332 int len, rem_len;
13333
13334 pos = buf;
13335 rem_len = sizeof(buf);
13336
13337 len = snprintf(pos, rem_len, "DSCP_RESP");
13338 if (snprintf_error(rem_len, len)) {
13339 sigma_dut_print(dut, DUT_MSG_ERROR,
13340 "Failed to create DSCP Policy Response command");
13341 return ERROR_SEND_STATUS;
13342 }
13343
13344 pos += len;
13345 rem_len -= len;
13346
13347 val = get_param(cmd, "PolicyID_List");
13348 if (!val) {
13349 sigma_dut_print(dut, DUT_MSG_ERROR,
13350 "DSCP policy ID list missing");
13351 return INVALID_SEND_STATUS;
13352 }
13353
13354 list = strdup(val);
13355 if (!list)
13356 return ERROR_SEND_STATUS;
13357
13358 item = strtok_r(list, "_", &saveptr);
13359 while (item) {
13360 unsigned int i;
13361 int policy_id = atoi(item);
13362
13363 for (i = 0; i < dut->num_dscp_status; i++)
13364 if (dut->dscp_status[i].id == policy_id)
13365 break;
13366
13367 if (i == dut->num_dscp_status) {
13368 free(list);
13369 send_resp(dut, conn, SIGMA_ERROR,
13370 "ErrorCode,DSCP policy id not found in status list");
13371 return STATUS_SENT_ERROR;
13372 }
13373
13374 len = snprintf(pos, rem_len, " policy_id=%d status=%d",
13375 policy_id, dut->dscp_status[i].status);
13376 if (snprintf_error(rem_len, len)) {
13377 free(list);
13378 sigma_dut_print(dut, DUT_MSG_ERROR,
13379 "Failed to write DSCP policy list");
13380 return ERROR_SEND_STATUS;
13381 }
13382
13383 pos += len;
13384 rem_len -= len;
13385
13386 if (dut->dscp_status[i].status)
13387 remove_dscp_policy(dut, policy_id);
13388
13389 item = strtok_r(NULL, "_", &saveptr);
13390 }
13391
13392 free(list);
13393
13394 if (wpa_command(intf, buf) != 0) {
13395 send_resp(dut, conn, SIGMA_ERROR,
13396 "ErrorCode,Failed to send DSCP Policy Response frame");
13397 return STATUS_SENT_ERROR;
13398 }
13399
13400 sigma_dut_print(dut, DUT_MSG_DEBUG,
13401 "DSCP Policy Response frame sent: %s", buf);
13402 return SUCCESS_SEND_STATUS;
13403}
13404
13405
13406static enum sigma_cmd_result
Vinita S. Malooca85fd22021-01-15 02:54:34 +053013407cmd_sta_send_frame_qm(struct sigma_dut *dut, struct sigma_conn *conn,
13408 const char *intf, struct sigma_cmd *cmd)
13409{
13410 const char *val;
13411
13412 val = get_param(cmd, "FrameName");
13413 if (val) {
13414 if (strcasecmp(val, "MSCSReq") == 0)
13415 return cmd_sta_send_frame_mscs(dut, conn, intf, cmd);
13416 if (strcasecmp(val, "SCSReq") == 0)
13417 return cmd_sta_send_frame_scs(dut, conn, intf, cmd);
Veerendranath Jakkam329a3cd2021-09-11 18:10:13 +053013418 if (strcasecmp(val, "DSCPPolicyQuery") == 0)
13419 return cmd_sta_send_frame_dscp_query(dut, conn, intf,
13420 cmd);
Veerendranath Jakkam1bf1bd62021-09-12 16:35:55 +053013421 if (strcasecmp(val, "DSCPPolicyResponse") == 0)
13422 return cmd_sta_send_frame_dscp_response(dut, conn, intf,
13423 cmd);
Vinita S. Malooca85fd22021-01-15 02:54:34 +053013424
13425 sigma_dut_print(dut, DUT_MSG_ERROR,
13426 "%s: frame name - %s is invalid",
13427 __func__, val);
13428 }
13429
13430 return INVALID_SEND_STATUS;
13431}
13432
13433
Jouni Malinenf7222712019-06-13 01:50:21 +030013434enum sigma_cmd_result cmd_sta_send_frame(struct sigma_dut *dut,
13435 struct sigma_conn *conn,
13436 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013437{
13438 const char *intf = get_param(cmd, "Interface");
13439 const char *val;
13440 enum send_frame_type frame;
13441 enum send_frame_protection protected;
13442 char buf[100];
13443 unsigned char addr[ETH_ALEN];
13444 int res;
13445
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030013446 if (!intf)
13447 return -1;
13448
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013449 val = get_param(cmd, "program");
13450 if (val == NULL)
13451 val = get_param(cmd, "frame");
13452 if (val && strcasecmp(val, "TDLS") == 0)
13453 return cmd_sta_send_frame_tdls(dut, conn, cmd);
13454 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030013455 strcasecmp(val, "HS2-R2") == 0 ||
13456 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013457 return cmd_sta_send_frame_hs2(dut, conn, cmd);
13458 if (val && strcasecmp(val, "VHT") == 0)
13459 return cmd_sta_send_frame_vht(dut, conn, cmd);
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070013460 if (val && strcasecmp(val, "HE") == 0)
13461 return cmd_sta_send_frame_he(dut, conn, cmd);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -070013462 if (val && strcasecmp(val, "LOC") == 0)
13463 return loc_cmd_sta_send_frame(dut, conn, cmd);
Lior David0fe101e2017-03-09 16:09:50 +020013464 if (val && strcasecmp(val, "60GHz") == 0)
13465 return cmd_sta_send_frame_60g(dut, conn, cmd);
Ashwini Patildb59b3c2017-04-13 15:19:23 +053013466 if (val && strcasecmp(val, "MBO") == 0) {
13467 res = mbo_cmd_sta_send_frame(dut, conn, intf, cmd);
13468 if (res != 2)
13469 return res;
13470 }
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053013471 if (val && strcasecmp(val, "WPA3") == 0)
13472 return cmd_sta_send_frame_wpa3(dut, conn, intf, cmd);
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053013473 if (val && strcasecmp(val, "QM") == 0)
Vinita S. Malooca85fd22021-01-15 02:54:34 +053013474 return cmd_sta_send_frame_qm(dut, conn, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013475
13476 val = get_param(cmd, "TD_DISC");
13477 if (val) {
13478 if (hwaddr_aton(val, addr) < 0)
13479 return -1;
13480 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", val);
13481 if (wpa_command(intf, buf) < 0) {
13482 send_resp(dut, conn, SIGMA_ERROR,
13483 "ErrorCode,Failed to send TDLS discovery");
13484 return 0;
13485 }
13486 return 1;
13487 }
13488
13489 val = get_param(cmd, "TD_Setup");
13490 if (val) {
13491 if (hwaddr_aton(val, addr) < 0)
13492 return -1;
13493 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", val);
13494 if (wpa_command(intf, buf) < 0) {
13495 send_resp(dut, conn, SIGMA_ERROR,
13496 "ErrorCode,Failed to start TDLS setup");
13497 return 0;
13498 }
13499 return 1;
13500 }
13501
13502 val = get_param(cmd, "TD_TearDown");
13503 if (val) {
13504 if (hwaddr_aton(val, addr) < 0)
13505 return -1;
13506 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", val);
13507 if (wpa_command(intf, buf) < 0) {
13508 send_resp(dut, conn, SIGMA_ERROR,
13509 "ErrorCode,Failed to tear down TDLS link");
13510 return 0;
13511 }
13512 return 1;
13513 }
13514
13515 val = get_param(cmd, "TD_ChannelSwitch");
13516 if (val) {
13517 /* TODO */
13518 send_resp(dut, conn, SIGMA_ERROR,
13519 "ErrorCode,TD_ChannelSwitch not yet supported");
13520 return 0;
13521 }
13522
13523 val = get_param(cmd, "TD_NF");
13524 if (val) {
13525 /* TODO */
13526 send_resp(dut, conn, SIGMA_ERROR,
13527 "ErrorCode,TD_NF not yet supported");
13528 return 0;
13529 }
13530
13531 val = get_param(cmd, "PMFFrameType");
13532 if (val == NULL)
13533 val = get_param(cmd, "FrameName");
13534 if (val == NULL)
13535 val = get_param(cmd, "Type");
13536 if (val == NULL)
13537 return -1;
13538 if (strcasecmp(val, "disassoc") == 0)
13539 frame = DISASSOC;
13540 else if (strcasecmp(val, "deauth") == 0)
13541 frame = DEAUTH;
13542 else if (strcasecmp(val, "saquery") == 0)
13543 frame = SAQUERY;
13544 else if (strcasecmp(val, "auth") == 0)
13545 frame = AUTH;
13546 else if (strcasecmp(val, "assocreq") == 0)
13547 frame = ASSOCREQ;
13548 else if (strcasecmp(val, "reassocreq") == 0)
13549 frame = REASSOCREQ;
13550 else if (strcasecmp(val, "neigreq") == 0) {
13551 sigma_dut_print(dut, DUT_MSG_INFO, "Got neighbor request");
13552
13553 val = get_param(cmd, "ssid");
13554 if (val == NULL)
13555 return -1;
13556
13557 res = send_neighbor_request(dut, intf, val);
13558 if (res) {
13559 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
13560 "Failed to send neighbor report request");
13561 return 0;
13562 }
13563
13564 return 1;
Ashwini Patil5acd7382017-04-13 15:55:04 +053013565 } else if (strcasecmp(val, "transmgmtquery") == 0 ||
13566 strcasecmp(val, "BTMQuery") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013567 sigma_dut_print(dut, DUT_MSG_DEBUG,
13568 "Got Transition Management Query");
13569
Ashwini Patil5acd7382017-04-13 15:55:04 +053013570 res = send_trans_mgmt_query(dut, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013571 if (res) {
13572 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
13573 "Failed to send Transition Management Query");
13574 return 0;
13575 }
13576
13577 return 1;
13578 } else {
13579 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
13580 "PMFFrameType");
13581 return 0;
13582 }
13583
13584 val = get_param(cmd, "PMFProtected");
13585 if (val == NULL)
13586 val = get_param(cmd, "Protected");
13587 if (val == NULL)
13588 return -1;
13589 if (strcasecmp(val, "Correct-key") == 0 ||
13590 strcasecmp(val, "CorrectKey") == 0)
13591 protected = CORRECT_KEY;
13592 else if (strcasecmp(val, "IncorrectKey") == 0)
13593 protected = INCORRECT_KEY;
13594 else if (strcasecmp(val, "Unprotected") == 0)
13595 protected = UNPROTECTED;
13596 else {
13597 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
13598 "PMFProtected");
13599 return 0;
13600 }
13601
13602 if (protected != UNPROTECTED &&
13603 (frame == AUTH || frame == ASSOCREQ || frame == REASSOCREQ)) {
13604 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Impossible "
13605 "PMFProtected for auth/assocreq/reassocreq");
13606 return 0;
13607 }
13608
13609 if (if_nametoindex("sigmadut") == 0) {
13610 snprintf(buf, sizeof(buf),
13611 "iw dev %s interface add sigmadut type monitor",
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013612 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013613 if (system(buf) != 0 ||
13614 if_nametoindex("sigmadut") == 0) {
13615 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
13616 "monitor interface with '%s'", buf);
13617 return -2;
13618 }
13619 }
13620
13621 if (system("ifconfig sigmadut up") != 0) {
13622 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
13623 "monitor interface up");
13624 return -2;
13625 }
13626
Veerendranath Jakkam49774122020-07-05 09:52:18 +053013627 return sta_inject_frame(dut, conn, intf, frame, protected, NULL, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013628}
13629
13630
13631static int cmd_sta_set_parameter_hs2(struct sigma_dut *dut,
13632 struct sigma_conn *conn,
13633 struct sigma_cmd *cmd,
13634 const char *ifname)
13635{
13636 char buf[200];
13637 const char *val;
13638
13639 val = get_param(cmd, "ClearARP");
13640 if (val && atoi(val) == 1) {
13641 snprintf(buf, sizeof(buf), "ip neigh flush dev %s", ifname);
13642 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
13643 if (system(buf) != 0) {
13644 send_resp(dut, conn, SIGMA_ERROR,
13645 "errorCode,Failed to clear ARP cache");
13646 return 0;
13647 }
13648 }
13649
13650 return 1;
13651}
13652
13653
13654int cmd_sta_set_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
13655 struct sigma_cmd *cmd)
13656{
13657 const char *intf = get_param(cmd, "Interface");
13658 const char *val;
13659
13660 if (intf == NULL)
13661 return -1;
13662
13663 val = get_param(cmd, "program");
13664 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030013665 strcasecmp(val, "HS2-R2") == 0 ||
13666 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013667 return cmd_sta_set_parameter_hs2(dut, conn, cmd, intf);
13668
13669 return -1;
13670}
13671
13672
Jouni Malinenf7222712019-06-13 01:50:21 +030013673static enum sigma_cmd_result cmd_sta_set_macaddr(struct sigma_dut *dut,
13674 struct sigma_conn *conn,
13675 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013676{
13677 const char *intf = get_param(cmd, "Interface");
13678 const char *mac = get_param(cmd, "MAC");
13679
13680 if (intf == NULL || mac == NULL)
13681 return -1;
13682
13683 sigma_dut_print(dut, DUT_MSG_INFO, "Change local MAC address for "
13684 "interface %s to %s", intf, mac);
13685
13686 if (dut->set_macaddr) {
13687 char buf[128];
13688 int res;
13689 if (strcasecmp(mac, "default") == 0) {
13690 res = snprintf(buf, sizeof(buf), "%s",
13691 dut->set_macaddr);
13692 dut->tmp_mac_addr = 0;
13693 } else {
13694 res = snprintf(buf, sizeof(buf), "%s %s",
13695 dut->set_macaddr, mac);
13696 dut->tmp_mac_addr = 1;
13697 }
13698 if (res < 0 || res >= (int) sizeof(buf))
13699 return -1;
13700 if (system(buf) != 0) {
13701 send_resp(dut, conn, SIGMA_ERROR,
13702 "errorCode,Failed to set MAC "
13703 "address");
13704 return 0;
13705 }
13706 return 1;
13707 }
13708
13709 if (strcasecmp(mac, "default") == 0)
13710 return 1;
13711
13712 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
13713 "command");
13714 return 0;
13715}
13716
13717
13718static int iwpriv_tdlsoffchnmode(struct sigma_dut *dut,
13719 struct sigma_conn *conn, const char *intf,
13720 int val)
13721{
13722 char buf[200];
13723 int res;
13724
13725 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchnmode %d",
13726 intf, val);
13727 if (res < 0 || res >= (int) sizeof(buf))
13728 return -1;
13729 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
13730 if (system(buf) != 0) {
13731 send_resp(dut, conn, SIGMA_ERROR,
13732 "errorCode,Failed to configure offchannel mode");
13733 return 0;
13734 }
13735
13736 return 1;
13737}
13738
13739
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013740static int off_chan_val(enum sec_ch_offset off)
13741{
13742 switch (off) {
13743 case SEC_CH_NO:
13744 return 0;
13745 case SEC_CH_40ABOVE:
13746 return 40;
13747 case SEC_CH_40BELOW:
13748 return -40;
13749 }
13750
13751 return 0;
13752}
13753
13754
13755static int iwpriv_set_offchan(struct sigma_dut *dut, struct sigma_conn *conn,
13756 const char *intf, int off_ch_num,
13757 enum sec_ch_offset sec)
13758{
13759 char buf[200];
13760 int res;
13761
13762 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchan %d",
13763 intf, off_ch_num);
13764 if (res < 0 || res >= (int) sizeof(buf))
13765 return -1;
13766 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
13767 if (system(buf) != 0) {
13768 send_resp(dut, conn, SIGMA_ERROR,
13769 "errorCode,Failed to set offchan");
13770 return 0;
13771 }
13772
13773 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsecchnoffst %d",
13774 intf, off_chan_val(sec));
13775 if (res < 0 || res >= (int) sizeof(buf))
13776 return -1;
13777 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
13778 if (system(buf) != 0) {
13779 send_resp(dut, conn, SIGMA_ERROR,
13780 "errorCode,Failed to set sec chan offset");
13781 return 0;
13782 }
13783
13784 return 1;
13785}
13786
13787
13788static int tdls_set_offchannel_offset(struct sigma_dut *dut,
13789 struct sigma_conn *conn,
13790 const char *intf, int off_ch_num,
13791 enum sec_ch_offset sec)
13792{
13793 char buf[200];
13794 int res;
13795
13796 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNEL %d",
13797 off_ch_num);
13798 if (res < 0 || res >= (int) sizeof(buf))
13799 return -1;
13800 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
13801
13802 if (wpa_command(intf, buf) < 0) {
13803 send_resp(dut, conn, SIGMA_ERROR,
13804 "ErrorCode,Failed to set offchan");
13805 return 0;
13806 }
13807 res = snprintf(buf, sizeof(buf), "DRIVER TDLSSECONDARYCHANNELOFFSET %d",
13808 off_chan_val(sec));
13809 if (res < 0 || res >= (int) sizeof(buf))
13810 return -1;
13811
13812 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
13813
13814 if (wpa_command(intf, buf) < 0) {
13815 send_resp(dut, conn, SIGMA_ERROR,
13816 "ErrorCode,Failed to set sec chan offset");
13817 return 0;
13818 }
13819
13820 return 1;
13821}
13822
13823
13824static int tdls_set_offchannel_mode(struct sigma_dut *dut,
13825 struct sigma_conn *conn,
13826 const char *intf, int val)
13827{
13828 char buf[200];
13829 int res;
13830
13831 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNELMODE %d",
13832 val);
13833 if (res < 0 || res >= (int) sizeof(buf))
13834 return -1;
13835 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
13836
13837 if (wpa_command(intf, buf) < 0) {
13838 send_resp(dut, conn, SIGMA_ERROR,
13839 "ErrorCode,Failed to configure offchannel mode");
13840 return 0;
13841 }
13842
13843 return 1;
13844}
13845
13846
13847static int cmd_sta_set_rfeature_tdls(const char *intf, struct sigma_dut *dut,
13848 struct sigma_conn *conn,
13849 struct sigma_cmd *cmd)
13850{
13851 const char *val;
13852 enum {
13853 CHSM_NOT_SET,
13854 CHSM_ENABLE,
13855 CHSM_DISABLE,
13856 CHSM_REJREQ,
13857 CHSM_UNSOLRESP
13858 } chsm = CHSM_NOT_SET;
13859 int off_ch_num = -1;
13860 enum sec_ch_offset sec_ch = SEC_CH_NO;
13861 int res;
13862
13863 val = get_param(cmd, "Uapsd");
13864 if (val) {
13865 char buf[100];
13866 if (strcasecmp(val, "Enable") == 0)
13867 snprintf(buf, sizeof(buf), "SET ps 99");
13868 else if (strcasecmp(val, "Disable") == 0)
13869 snprintf(buf, sizeof(buf), "SET ps 98");
13870 else {
13871 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
13872 "Unsupported uapsd parameter value");
13873 return 0;
13874 }
13875 if (wpa_command(intf, buf)) {
13876 send_resp(dut, conn, SIGMA_ERROR,
13877 "ErrorCode,Failed to change U-APSD "
13878 "powersave mode");
13879 return 0;
13880 }
13881 }
13882
13883 val = get_param(cmd, "TPKTIMER");
13884 if (val && strcasecmp(val, "DISABLE") == 0) {
13885 if (wpa_command(intf, "SET tdls_testing 0x100")) {
13886 send_resp(dut, conn, SIGMA_ERROR,
13887 "ErrorCode,Failed to enable no TPK "
13888 "expiration test mode");
13889 return 0;
13890 }
13891 dut->no_tpk_expiration = 1;
13892 }
13893
13894 val = get_param(cmd, "ChSwitchMode");
13895 if (val) {
13896 if (strcasecmp(val, "Enable") == 0 ||
13897 strcasecmp(val, "Initiate") == 0)
13898 chsm = CHSM_ENABLE;
13899 else if (strcasecmp(val, "Disable") == 0 ||
13900 strcasecmp(val, "passive") == 0)
13901 chsm = CHSM_DISABLE;
13902 else if (strcasecmp(val, "RejReq") == 0)
13903 chsm = CHSM_REJREQ;
13904 else if (strcasecmp(val, "UnSolResp") == 0)
13905 chsm = CHSM_UNSOLRESP;
13906 else {
13907 send_resp(dut, conn, SIGMA_ERROR,
13908 "ErrorCode,Unknown ChSwitchMode value");
13909 return 0;
13910 }
13911 }
13912
13913 val = get_param(cmd, "OffChNum");
13914 if (val) {
13915 off_ch_num = atoi(val);
13916 if (off_ch_num == 0) {
13917 send_resp(dut, conn, SIGMA_ERROR,
13918 "ErrorCode,Invalid OffChNum");
13919 return 0;
13920 }
13921 }
13922
13923 val = get_param(cmd, "SecChOffset");
13924 if (val) {
13925 if (strcmp(val, "20") == 0)
13926 sec_ch = SEC_CH_NO;
13927 else if (strcasecmp(val, "40above") == 0)
13928 sec_ch = SEC_CH_40ABOVE;
13929 else if (strcasecmp(val, "40below") == 0)
13930 sec_ch = SEC_CH_40BELOW;
13931 else {
13932 send_resp(dut, conn, SIGMA_ERROR,
13933 "ErrorCode,Unknown SecChOffset value");
13934 return 0;
13935 }
13936 }
13937
13938 if (chsm == CHSM_NOT_SET) {
13939 /* no offchannel changes requested */
13940 return 1;
13941 }
13942
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013943 if (strcmp(intf, get_main_ifname(dut)) != 0 &&
13944 strcmp(intf, get_station_ifname(dut)) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013945 send_resp(dut, conn, SIGMA_ERROR,
13946 "ErrorCode,Unknown interface");
13947 return 0;
13948 }
13949
13950 switch (chsm) {
13951 case CHSM_NOT_SET:
Jouni Malinen280f5ba2016-08-29 21:33:10 +030013952 res = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013953 break;
13954 case CHSM_ENABLE:
13955 if (off_ch_num < 0) {
13956 send_resp(dut, conn, SIGMA_ERROR,
13957 "ErrorCode,Missing OffChNum argument");
13958 return 0;
13959 }
13960 if (wifi_chip_type == DRIVER_WCN) {
13961 res = tdls_set_offchannel_offset(dut, conn, intf,
13962 off_ch_num, sec_ch);
13963 } else {
13964 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
13965 sec_ch);
13966 }
13967 if (res != 1)
13968 return res;
13969 if (wifi_chip_type == DRIVER_WCN)
13970 res = tdls_set_offchannel_mode(dut, conn, intf, 1);
13971 else
13972 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 1);
13973 break;
13974 case CHSM_DISABLE:
13975 if (wifi_chip_type == DRIVER_WCN)
13976 res = tdls_set_offchannel_mode(dut, conn, intf, 2);
13977 else
13978 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 2);
13979 break;
13980 case CHSM_REJREQ:
13981 if (wifi_chip_type == DRIVER_WCN)
13982 res = tdls_set_offchannel_mode(dut, conn, intf, 3);
13983 else
13984 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 3);
13985 break;
13986 case CHSM_UNSOLRESP:
13987 if (off_ch_num < 0) {
13988 send_resp(dut, conn, SIGMA_ERROR,
13989 "ErrorCode,Missing OffChNum argument");
13990 return 0;
13991 }
13992 if (wifi_chip_type == DRIVER_WCN) {
13993 res = tdls_set_offchannel_offset(dut, conn, intf,
13994 off_ch_num, sec_ch);
13995 } else {
13996 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
13997 sec_ch);
13998 }
13999 if (res != 1)
14000 return res;
14001 if (wifi_chip_type == DRIVER_WCN)
14002 res = tdls_set_offchannel_mode(dut, conn, intf, 4);
14003 else
14004 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 4);
14005 break;
14006 }
14007
14008 return res;
14009}
14010
14011
14012static int ath_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
14013 struct sigma_conn *conn,
14014 struct sigma_cmd *cmd)
14015{
14016 const char *val;
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053014017 char *token = NULL, *result;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014018
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -070014019 novap_reset(dut, intf, 1);
priyadharshini gowthamane5e25172015-12-08 14:53:48 -080014020
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014021 val = get_param(cmd, "nss_mcs_opt");
14022 if (val) {
14023 /* String (nss_operating_mode; mcs_operating_mode) */
14024 int nss, mcs;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053014025 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014026
14027 token = strdup(val);
14028 if (!token)
14029 return 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053014030 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053014031 if (!result) {
14032 sigma_dut_print(dut, DUT_MSG_ERROR,
14033 "VHT NSS not specified");
14034 goto failed;
14035 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014036 if (strcasecmp(result, "def") != 0) {
14037 nss = atoi(result);
14038 if (nss == 4)
14039 ath_disable_txbf(dut, intf);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070014040 if (run_iwpriv(dut, intf, "nss %d", nss) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014041 goto failed;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070014042
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014043 }
14044
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053014045 result = strtok_r(NULL, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053014046 if (!result) {
14047 sigma_dut_print(dut, DUT_MSG_ERROR,
14048 "VHT MCS not specified");
14049 goto failed;
14050 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014051 if (strcasecmp(result, "def") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070014052 if (run_iwpriv(dut, intf, "set11NRates 0") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014053 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014054 } else {
14055 mcs = atoi(result);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070014056 if (run_iwpriv(dut, intf, "vhtmcs %d", mcs) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014057 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014058 }
14059 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070014060 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014061 }
14062
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053014063 free(token);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014064 return 1;
14065failed:
14066 free(token);
14067 return 0;
14068}
14069
14070
14071static int cmd_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
14072 struct sigma_conn *conn,
14073 struct sigma_cmd *cmd)
14074{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020014075 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014076 case DRIVER_ATHEROS:
14077 return ath_sta_set_rfeature_vht(intf, dut, conn, cmd);
14078 default:
14079 send_resp(dut, conn, SIGMA_ERROR,
14080 "errorCode,Unsupported sta_set_rfeature(VHT) with the current driver");
14081 return 0;
14082 }
14083}
14084
14085
Jouni Malinen1702fe32021-06-08 19:08:01 +030014086static enum sigma_cmd_result
14087wcn_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
14088 struct sigma_conn *conn, struct sigma_cmd *cmd)
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014089{
14090 const char *val;
14091 char *token = NULL, *result;
14092 char buf[60];
14093
14094 val = get_param(cmd, "nss_mcs_opt");
14095 if (val) {
14096 /* String (nss_operating_mode; mcs_operating_mode) */
14097 int nss, mcs, ratecode;
14098 char *saveptr;
14099
14100 token = strdup(val);
14101 if (!token)
Jouni Malinen1702fe32021-06-08 19:08:01 +030014102 return ERROR_SEND_STATUS;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014103
14104 result = strtok_r(token, ";", &saveptr);
14105 if (!result) {
14106 sigma_dut_print(dut, DUT_MSG_ERROR,
14107 "HE NSS not specified");
14108 goto failed;
14109 }
14110 nss = 1;
14111 if (strcasecmp(result, "def") != 0)
14112 nss = atoi(result);
14113
14114 result = strtok_r(NULL, ";", &saveptr);
14115 if (!result) {
14116 sigma_dut_print(dut, DUT_MSG_ERROR,
14117 "HE MCS not specified");
14118 goto failed;
14119 }
14120 mcs = 7;
14121 if (strcasecmp(result, "def") != 0)
14122 mcs = atoi(result);
14123
Arif Hussain557bf412018-05-25 17:29:36 -070014124 ratecode = 0x20; /* for nss:1 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014125 if (nss == 2) {
Arif Hussain557bf412018-05-25 17:29:36 -070014126 ratecode = 0x40; /* for nss:2 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014127 } else if (nss > 2) {
14128 sigma_dut_print(dut, DUT_MSG_ERROR,
14129 "HE NSS %d not supported", nss);
14130 goto failed;
14131 }
14132
Arif Hussain557bf412018-05-25 17:29:36 -070014133 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss);
14134 if (system(buf) != 0) {
14135 sigma_dut_print(dut, DUT_MSG_ERROR,
14136 "nss_mcs_opt: iwpriv %s nss %d failed",
14137 intf, nss);
14138 goto failed;
14139 }
Arif Hussainac6c5112018-05-25 17:34:00 -070014140 dut->sta_nss = nss;
Arif Hussain557bf412018-05-25 17:29:36 -070014141
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014142 /* Add the MCS to the ratecode */
14143 if (mcs >= 0 && mcs <= 11) {
14144 ratecode += mcs;
Arif Hussain557bf412018-05-25 17:29:36 -070014145#ifdef NL80211_SUPPORT
14146 if (dut->device_type == STA_testbed) {
14147 enum he_mcs_config mcs_config;
14148 int ret;
14149
14150 if (mcs <= 7)
14151 mcs_config = HE_80_MCS0_7;
14152 else if (mcs <= 9)
14153 mcs_config = HE_80_MCS0_9;
14154 else
14155 mcs_config = HE_80_MCS0_11;
14156 ret = sta_set_he_mcs(dut, intf, mcs_config);
14157 if (ret) {
14158 sigma_dut_print(dut, DUT_MSG_ERROR,
14159 "nss_mcs_opt: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
14160 mcs, mcs_config, ret);
14161 goto failed;
14162 }
14163 }
14164#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014165 } else {
14166 sigma_dut_print(dut, DUT_MSG_ERROR,
14167 "HE MCS %d not supported", mcs);
14168 goto failed;
14169 }
14170 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0x%03x",
14171 intf, ratecode);
14172 if (system(buf) != 0) {
14173 sigma_dut_print(dut, DUT_MSG_ERROR,
14174 "iwpriv setting of 11ax rates failed");
14175 goto failed;
14176 }
14177 free(token);
14178 }
14179
14180 val = get_param(cmd, "GI");
14181 if (val) {
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080014182 int fix_rate_sgi;
14183
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014184 if (strcmp(val, "0.8") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070014185 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 9", intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080014186 fix_rate_sgi = 1;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014187 } else if (strcmp(val, "1.6") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070014188 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 10",
14189 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080014190 fix_rate_sgi = 2;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014191 } else if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070014192 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 11",
14193 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080014194 fix_rate_sgi = 3;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014195 } else {
14196 send_resp(dut, conn, SIGMA_ERROR,
14197 "errorCode,GI value not supported");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014198 return STATUS_SENT_ERROR;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014199 }
14200 if (system(buf) != 0) {
14201 send_resp(dut, conn, SIGMA_ERROR,
14202 "errorCode,Failed to set shortgi");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014203 return STATUS_SENT_ERROR;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014204 }
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080014205 snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d",
14206 intf, fix_rate_sgi);
14207 if (system(buf) != 0) {
14208 send_resp(dut, conn, SIGMA_ERROR,
14209 "errorCode,Failed to set fix rate shortgi");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014210 return STATUS_SENT_ERROR;
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080014211 }
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014212 }
14213
Subhani Shaik8e7a3052018-04-24 14:03:00 -070014214 val = get_param(cmd, "LTF");
14215 if (val) {
14216#ifdef NL80211_SUPPORT
14217 if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080014218 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_1X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070014219 } if (strcmp(val, "6.4") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080014220 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_2X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070014221 } else if (strcmp(val, "12.8") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080014222 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_4X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070014223 } else {
14224 send_resp(dut, conn, SIGMA_ERROR,
14225 "errorCode, LTF value not supported");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014226 return STATUS_SENT_ERROR;
Subhani Shaik8e7a3052018-04-24 14:03:00 -070014227 }
14228#else /* NL80211_SUPPORT */
14229 sigma_dut_print(dut, DUT_MSG_ERROR,
14230 "LTF cannot be set without NL80211_SUPPORT defined");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014231 return ERROR_SEND_STATUS;
Subhani Shaik8e7a3052018-04-24 14:03:00 -070014232#endif /* NL80211_SUPPORT */
14233 }
14234
Kiran Kumar Lokere1809da12021-06-24 00:45:38 -070014235 val = get_param(cmd, "KeepAlive");
14236 if (val) {
14237 int set_val = QCA_WLAN_KEEP_ALIVE_DEFAULT;
14238
14239 if (strcasecmp(val, "Data") == 0)
14240 set_val = QCA_WLAN_KEEP_ALIVE_DATA;
14241 else if (strcasecmp(val, "Mgmt") == 0)
14242 set_val = QCA_WLAN_KEEP_ALIVE_MGMT;
14243
14244 if (sta_set_keep_alive_data_cfg(dut, intf, set_val)) {
14245 send_resp(dut, conn, SIGMA_ERROR,
14246 "ErrorCode,Failed to set keep alive type config");
14247 return STATUS_SENT_ERROR;
14248 }
14249 }
14250
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -070014251 val = get_param(cmd, "TxSUPPDU");
14252 if (val) {
14253 int set_val = 1;
14254
14255 if (strcasecmp(val, "Enable") == 0)
14256 set_val = 1;
14257 else if (strcasecmp(val, "Disable") == 0)
14258 set_val = 0;
14259
14260 if (sta_set_tx_su_ppdu_cfg(dut, intf, set_val)) {
14261 send_resp(dut, conn, SIGMA_ERROR,
14262 "ErrorCode,Failed to set Tx SU PPDU config");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014263 return STATUS_SENT_ERROR;
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -070014264 }
14265 }
14266
Kiran Kumar Lokere54b72522021-04-01 00:22:44 -070014267 val = get_param(cmd, "Mgmt_Data_TX_Resp_Frame");
14268 if (val) {
14269 int set_val = 0;
14270
14271 if (strcasecmp(val, "Enable") == 0)
14272 set_val = 0;
14273 else if (strcasecmp(val, "Disable") == 0)
14274 set_val = 1;
14275
14276 if (sta_set_mgmt_data_tx_disable_cfg(dut, intf, set_val)) {
14277 send_resp(dut, conn, SIGMA_ERROR,
14278 "ErrorCode,Failed to set mgmt/data Tx disable config");
14279 return STATUS_SENT_ERROR;
14280 }
14281 }
14282
Arif Hussain480d5f42019-03-12 14:40:42 -070014283 val = get_param(cmd, "TWT_Setup");
14284 if (val) {
14285 if (strcasecmp(val, "Request") == 0) {
Kiran Kumar Lokereafac46a2021-11-29 14:03:20 -080014286 if (set_power_save_wcn(dut, intf, 1) < 0)
14287 sigma_dut_print(dut, DUT_MSG_ERROR,
14288 "Failed to enable power save");
Arif Hussain480d5f42019-03-12 14:40:42 -070014289 if (sta_twt_request(dut, conn, cmd)) {
14290 send_resp(dut, conn, SIGMA_ERROR,
Srinivas Girigowda6707f032020-10-26 15:24:46 -070014291 "ErrorCode,TWT setup failed");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014292 return STATUS_SENT_ERROR;
Arif Hussain480d5f42019-03-12 14:40:42 -070014293 }
14294 } else if (strcasecmp(val, "Teardown") == 0) {
14295 if (sta_twt_teardown(dut, conn, cmd)) {
14296 send_resp(dut, conn, SIGMA_ERROR,
Srinivas Girigowda6707f032020-10-26 15:24:46 -070014297 "ErrorCode,TWT teardown failed");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014298 return STATUS_SENT_ERROR;
Arif Hussain480d5f42019-03-12 14:40:42 -070014299 }
14300 }
14301 }
14302
Srinivas Girigowda6707f032020-10-26 15:24:46 -070014303 val = get_param(cmd, "TWT_Operation");
14304 if (val) {
14305 if (strcasecmp(val, "Suspend") == 0) {
14306 if (sta_twt_suspend_or_nudge(dut, conn, cmd)) {
14307 send_resp(dut, conn, SIGMA_ERROR,
14308 "ErrorCode,TWT suspend failed");
14309 return STATUS_SENT_ERROR;
14310 }
14311 } else if (strcasecmp(val, "Resume") == 0) {
14312 if (sta_twt_resume(dut, conn, cmd)) {
14313 send_resp(dut, conn, SIGMA_ERROR,
14314 "ErrorCode,TWT resume failed");
14315 return STATUS_SENT_ERROR;
14316 }
14317 }
14318 }
14319
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -080014320 val = get_param(cmd, "transmitOMI");
14321 if (val && sta_transmit_omi(dut, conn, cmd)) {
14322 send_resp(dut, conn, SIGMA_ERROR,
14323 "ErrorCode,sta_transmit_omi failed");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014324 return STATUS_SENT_ERROR;
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -070014325 }
14326
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080014327 val = get_param(cmd, "Powersave");
14328 if (val) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053014329 int ps;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080014330
14331 if (strcasecmp(val, "off") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053014332 ps = 2;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080014333 } else if (strcasecmp(val, "on") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053014334 ps = 1;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080014335 } else {
14336 sigma_dut_print(dut, DUT_MSG_ERROR,
14337 "Unsupported Powersave value '%s'",
14338 val);
Jouni Malinen1702fe32021-06-08 19:08:01 +030014339 return INVALID_SEND_STATUS;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080014340 }
Vinita S. Malooa8b62722020-04-23 01:45:41 +053014341 if (set_power_save_wcn(dut, intf, ps) < 0)
Jouni Malinen1702fe32021-06-08 19:08:01 +030014342 return ERROR_SEND_STATUS;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080014343 }
14344
Kiran Kumar Lokere2c4b7ce2019-01-30 12:02:28 -080014345 val = get_param(cmd, "MU_EDCA");
14346 if (val) {
14347 if (strcasecmp(val, "Override") == 0) {
14348 if (sta_set_mu_edca_override(dut, intf, 1)) {
14349 send_resp(dut, conn, SIGMA_ERROR,
14350 "errorCode,MU EDCA override set failed");
14351 return STATUS_SENT;
14352 }
14353 } else if (strcasecmp(val, "Disable") == 0) {
14354 if (sta_set_mu_edca_override(dut, intf, 0)) {
14355 send_resp(dut, conn, SIGMA_ERROR,
14356 "errorCode,MU EDCA override disable failed");
14357 return STATUS_SENT;
14358 }
14359 }
14360 }
14361
Kiran Kumar Lokerefa7c7b92021-08-09 00:50:55 -070014362 val = get_param(cmd, "RUAllocTone");
14363 if (val && strcasecmp(val, "242") == 0) {
14364 if (sta_set_ru_242_tone_tx(dut, intf, 1)) {
14365 send_resp(dut, conn, SIGMA_ERROR,
14366 "ErrorCode,Failed to set RU 242 tone Tx");
14367 return STATUS_SENT_ERROR;
14368 }
14369 }
14370
14371 val = get_param(cmd, "PPDUTxType");
14372 if (val && strcasecmp(val, "ER-SU") == 0) {
14373 if (sta_set_er_su_ppdu_type_tx(dut, intf, 1)) {
14374 send_resp(dut, conn, SIGMA_ERROR,
14375 "ErrorCode,Failed to set ER-SU PPDU type Tx");
14376 return STATUS_SENT_ERROR;
14377 }
14378 }
14379
Kiran Kumar Lokeredd086642020-06-04 00:29:26 -070014380 val = get_param(cmd, "Ch_Pref");
14381 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
14382 return STATUS_SENT;
14383
14384 val = get_param(cmd, "Cellular_Data_Cap");
14385 if (val && mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
14386 return STATUS_SENT;
14387
Jouni Malinen1702fe32021-06-08 19:08:01 +030014388 return SUCCESS_SEND_STATUS;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014389
14390failed:
14391 free(token);
Jouni Malinen1702fe32021-06-08 19:08:01 +030014392 return ERROR_SEND_STATUS;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014393}
14394
14395
Jouni Malinen1702fe32021-06-08 19:08:01 +030014396static enum sigma_cmd_result
14397cmd_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
14398 struct sigma_conn *conn, struct sigma_cmd *cmd)
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014399{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020014400 switch (get_driver_type(dut)) {
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014401 case DRIVER_WCN:
14402 return wcn_sta_set_rfeature_he(intf, dut, conn, cmd);
14403 default:
14404 send_resp(dut, conn, SIGMA_ERROR,
14405 "errorCode,Unsupported sta_set_rfeature(HE) with the current driver");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014406 return STATUS_SENT_ERROR;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014407 }
14408}
14409
14410
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080014411static int cmd_sta_set_power_save_he(const char *intf, struct sigma_dut *dut,
14412 struct sigma_conn *conn,
14413 struct sigma_cmd *cmd)
14414{
14415 const char *val;
14416
14417 val = get_param(cmd, "powersave");
14418 if (val) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053014419 int ps;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080014420
14421 if (strcasecmp(val, "off") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053014422 ps = 2;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080014423 } else if (strcasecmp(val, "on") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053014424 ps = 1;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080014425 } else {
14426 sigma_dut_print(dut, DUT_MSG_ERROR,
14427 "Unsupported power save config");
14428 return -1;
14429 }
Vinita S. Malooa8b62722020-04-23 01:45:41 +053014430 if (set_power_save_wcn(dut, intf, ps) < 0)
14431 return 0;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080014432 return 1;
14433 }
14434
14435 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported command");
14436
14437 return 0;
14438}
14439
14440
Ashwini Patil5acd7382017-04-13 15:55:04 +053014441static int btm_query_candidate_list(struct sigma_dut *dut,
14442 struct sigma_conn *conn,
14443 struct sigma_cmd *cmd)
14444{
14445 const char *bssid, *info, *op_class, *ch, *phy_type, *pref;
14446 int len, ret;
14447 char buf[10];
14448
14449 /*
14450 * Neighbor Report elements format:
14451 * neighbor=<BSSID>,<BSSID Information>,<Operating Class>,
14452 * <Channel Number>,<PHY Type>[,<hexdump of Optional Subelements>]
14453 * eg: neighbor=aa:bb:cc:dd:ee:ff,17,81,6,1,030101
14454 */
14455
14456 bssid = get_param(cmd, "Nebor_BSSID");
14457 if (!bssid) {
14458 send_resp(dut, conn, SIGMA_INVALID,
14459 "errorCode,Nebor_BSSID is missing");
14460 return 0;
14461 }
14462
14463 info = get_param(cmd, "Nebor_Bssid_Info");
14464 if (!info) {
14465 sigma_dut_print(dut, DUT_MSG_INFO,
14466 "Using default value for Nebor_Bssid_Info: %s",
14467 DEFAULT_NEIGHBOR_BSSID_INFO);
14468 info = DEFAULT_NEIGHBOR_BSSID_INFO;
14469 }
14470
14471 op_class = get_param(cmd, "Nebor_Op_Class");
14472 if (!op_class) {
14473 send_resp(dut, conn, SIGMA_INVALID,
14474 "errorCode,Nebor_Op_Class is missing");
14475 return 0;
14476 }
14477
14478 ch = get_param(cmd, "Nebor_Op_Ch");
14479 if (!ch) {
14480 send_resp(dut, conn, SIGMA_INVALID,
14481 "errorCode,Nebor_Op_Ch is missing");
14482 return 0;
14483 }
14484
14485 phy_type = get_param(cmd, "Nebor_Phy_Type");
14486 if (!phy_type) {
14487 sigma_dut_print(dut, DUT_MSG_INFO,
14488 "Using default value for Nebor_Phy_Type: %s",
14489 DEFAULT_NEIGHBOR_PHY_TYPE);
14490 phy_type = DEFAULT_NEIGHBOR_PHY_TYPE;
14491 }
14492
14493 /* Parse optional subelements */
14494 buf[0] = '\0';
14495 pref = get_param(cmd, "Nebor_Pref");
14496 if (pref) {
14497 /* hexdump for preferrence subelement */
14498 ret = snprintf(buf, sizeof(buf), ",0301%02x", atoi(pref));
14499 if (ret < 0 || ret >= (int) sizeof(buf)) {
14500 sigma_dut_print(dut, DUT_MSG_ERROR,
14501 "snprintf failed for optional subelement ret: %d",
14502 ret);
14503 send_resp(dut, conn, SIGMA_ERROR,
14504 "errorCode,snprintf failed for subelement");
14505 return 0;
14506 }
14507 }
14508
14509 if (!dut->btm_query_cand_list) {
14510 dut->btm_query_cand_list = calloc(1, NEIGHBOR_REPORT_SIZE);
14511 if (!dut->btm_query_cand_list) {
14512 send_resp(dut, conn, SIGMA_ERROR,
14513 "errorCode,Failed to allocate memory for btm_query_cand_list");
14514 return 0;
14515 }
14516 }
14517
14518 len = strlen(dut->btm_query_cand_list);
14519 ret = snprintf(dut->btm_query_cand_list + len,
14520 NEIGHBOR_REPORT_SIZE - len, " neighbor=%s,%s,%s,%s,%s%s",
14521 bssid, info, op_class, ch, phy_type, buf);
14522 if (ret < 0 || ret >= NEIGHBOR_REPORT_SIZE - len) {
14523 sigma_dut_print(dut, DUT_MSG_ERROR,
14524 "snprintf failed for neighbor report list ret: %d",
14525 ret);
14526 send_resp(dut, conn, SIGMA_ERROR,
14527 "errorCode,snprintf failed for neighbor report");
14528 free(dut->btm_query_cand_list);
14529 dut->btm_query_cand_list = NULL;
14530 return 0;
14531 }
14532
14533 return 1;
14534}
14535
14536
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020014537int sta_extract_60g_ese(struct sigma_dut *dut, struct sigma_cmd *cmd,
14538 struct sigma_ese_alloc *allocs, int *allocs_size)
14539{
14540 int max_count = *allocs_size;
14541 int count = 0, i;
14542 const char *val;
14543
14544 do {
14545 val = get_param_indexed(cmd, "AllocID", count);
14546 if (val)
14547 count++;
14548 } while (val);
14549
14550 if (count == 0 || count > max_count) {
14551 sigma_dut_print(dut, DUT_MSG_ERROR,
14552 "Invalid number of allocations(%d)", count);
14553 return -1;
14554 }
14555
14556 for (i = 0; i < count; i++) {
14557 val = get_param_indexed(cmd, "PercentBI", i);
14558 if (!val) {
14559 sigma_dut_print(dut, DUT_MSG_ERROR,
14560 "Missing PercentBI parameter at index %d",
14561 i);
14562 return -1;
14563 }
14564 allocs[i].percent_bi = atoi(val);
14565
14566 val = get_param_indexed(cmd, "SrcAID", i);
14567 if (val)
14568 allocs[i].src_aid = strtol(val, NULL, 0);
14569 else
14570 allocs[i].src_aid = ESE_BCAST_AID;
14571
14572 val = get_param_indexed(cmd, "DestAID", i);
14573 if (val)
14574 allocs[i].dst_aid = strtol(val, NULL, 0);
14575 else
14576 allocs[i].dst_aid = ESE_BCAST_AID;
14577
14578 allocs[i].type = ESE_CBAP;
14579 sigma_dut_print(dut, DUT_MSG_INFO,
14580 "Alloc %d PercentBI %d SrcAID %d DstAID %d",
14581 i, allocs[i].percent_bi, allocs[i].src_aid,
14582 allocs[i].dst_aid);
14583 }
14584
14585 *allocs_size = count;
14586 return 0;
14587}
14588
14589
14590static int sta_set_60g_ese(struct sigma_dut *dut, int count,
14591 struct sigma_ese_alloc *allocs)
14592{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020014593 switch (get_driver_type(dut)) {
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020014594#ifdef __linux__
14595 case DRIVER_WIL6210:
14596 if (wil6210_set_ese(dut, count, allocs))
14597 return -1;
14598 return 1;
14599#endif /* __linux__ */
14600 default:
14601 sigma_dut_print(dut, DUT_MSG_ERROR,
14602 "Unsupported sta_set_60g_ese with the current driver");
14603 return -1;
14604 }
14605}
14606
14607
14608static int cmd_sta_set_rfeature_60g(const char *intf, struct sigma_dut *dut,
14609 struct sigma_conn *conn,
14610 struct sigma_cmd *cmd)
14611{
14612 const char *val;
14613
14614 val = get_param(cmd, "ExtSchIE");
14615 if (val && !strcasecmp(val, "Enable")) {
14616 struct sigma_ese_alloc allocs[MAX_ESE_ALLOCS];
14617 int count = MAX_ESE_ALLOCS;
14618
14619 if (sta_extract_60g_ese(dut, cmd, allocs, &count))
14620 return -1;
14621 return sta_set_60g_ese(dut, count, allocs);
14622 }
14623
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020014624 val = get_param(cmd, "MCS_FixedRate");
14625 if (val) {
14626 int sta_mcs = atoi(val);
14627
14628 sigma_dut_print(dut, DUT_MSG_INFO, "Force STA MCS to %d",
14629 sta_mcs);
14630 wil6210_set_force_mcs(dut, 1, sta_mcs);
14631
Jouni Malinen0e29cf22019-02-19 01:13:21 +020014632 return SUCCESS_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020014633 }
14634
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020014635 send_resp(dut, conn, SIGMA_ERROR,
14636 "errorCode,Invalid sta_set_rfeature(60G)");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020014637 return STATUS_SENT;
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020014638}
14639
14640
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053014641static int wcn_sta_override_oci(struct sigma_dut *dut, const char *intf,
14642 const char *oci_frametype, uint32_t oci_freq)
14643{
14644#ifdef NL80211_SUPPORT
14645 struct nl_msg *msg;
14646 int ret = 0;
14647 struct nlattr *params;
14648 struct nlattr *attr;
14649 int ifindex;
14650 u8 frame_type;
14651
14652 ifindex = if_nametoindex(intf);
14653 if (ifindex == 0) {
14654 sigma_dut_print(dut, DUT_MSG_ERROR,
14655 "%s: Index for interface %s failed",
14656 __func__, intf);
14657 return -1;
14658 }
14659
14660 if (strcasecmp(oci_frametype, "SAQueryReq") == 0) {
14661 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_SA_QUERY_REQ;
14662 } else if (strcasecmp(oci_frametype, "SAQueryResp") == 0) {
14663 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_SA_QUERY_RESP;
14664 } else if (strcasecmp(oci_frametype, "Reassocreq") == 0) {
14665 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_FT_REASSOC_REQ;
14666 } else {
14667 sigma_dut_print(dut, DUT_MSG_ERROR, "%s: Unknown frametype %s",
14668 __func__, oci_frametype);
14669 return -1;
14670 }
14671
14672
14673 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
14674 NL80211_CMD_VENDOR)) ||
14675 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
14676 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
14677 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
14678 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
14679 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
14680 !(params = nla_nest_start(
14681 msg,
14682 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_OCI_OVERRIDE)) ||
14683 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_OCI_OVERRIDE_FRAME_TYPE,
14684 frame_type) ||
14685 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_OCI_OVERRIDE_FREQUENCY,
14686 oci_freq)) {
14687 sigma_dut_print(dut, DUT_MSG_ERROR,
14688 "%s: err in adding vendor_cmd and vendor_data",
14689 __func__);
14690 nlmsg_free(msg);
14691 return -1;
14692 }
14693 nla_nest_end(msg, params);
14694 nla_nest_end(msg, attr);
14695
14696 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
14697 if (ret) {
14698 sigma_dut_print(dut, DUT_MSG_ERROR,
14699 "%s: err in send_and_recv_msgs, ret=%d",
14700 __func__, ret);
14701 }
14702 return ret;
14703#else /* NL80211_SUPPORT */
14704 sigma_dut_print(dut, DUT_MSG_ERROR,
14705 "OCI override not possible without NL80211_SUPPORT defined");
14706 return -1;
14707#endif /* NL80211_SUPPORT */
14708}
14709
14710
Veerendranath Jakkam50d5c782020-07-22 01:59:01 +053014711static int wcn_sta_ignore_csa(struct sigma_dut *dut, const char *intf,
14712 uint8_t ignore_csa)
14713{
14714#ifdef NL80211_SUPPORT
14715 return wcn_wifi_test_config_set_u8(
14716 dut, intf,
14717 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_IGNORE_CSA, ignore_csa);
14718#else /* NL80211_SUPPORT */
14719 sigma_dut_print(dut, DUT_MSG_ERROR,
14720 "IgnoreCSA can't be set without NL80211_SUPPORT defined");
14721 return -1;
14722#endif /* NL80211_SUPPORT */
14723}
14724
14725
Veerendranath Jakkamc771fac2020-07-22 01:32:56 +053014726static int wcn_sta_set_rsnxe_used(struct sigma_dut *dut, const char *intf,
14727 uint8_t rsnxe_used)
14728{
14729#ifdef NL80211_SUPPORT
14730 return wcn_wifi_test_config_set_u8(
14731 dut, intf,
14732 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_FT_REASSOCREQ_RSNXE_USED,
14733 rsnxe_used);
14734#else /* NL80211_SUPPORT */
14735 sigma_dut_print(dut, DUT_MSG_ERROR,
14736 "RSNXE_Used can't be set without NL80211_SUPPORT defined");
14737 return -1;
14738#endif /* NL80211_SUPPORT */
14739}
14740
14741
Veerendranath Jakkam1e1e5fd2020-09-10 07:12:37 +053014742static int wcn_sta_ignore_sa_query_timeout(struct sigma_dut *dut,
14743 const char *intf,
14744 uint8_t ignore_sa_query_timeout)
14745{
14746#ifdef NL80211_SUPPORT
14747 return wcn_wifi_test_config_set_u8(
14748 dut, intf,
14749 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_IGNORE_SA_QUERY_TIMEOUT,
14750 ignore_sa_query_timeout);
14751#else /* NL80211_SUPPORT */
14752 sigma_dut_print(dut, DUT_MSG_ERROR,
14753 "Ignore SA Query timeout can't be set without NL80211_SUPPORT defined");
14754 return -1;
14755#endif /* NL80211_SUPPORT */
14756}
14757
14758
Jouni Malinen6250cb02020-04-15 13:54:45 +030014759static enum sigma_cmd_result
14760cmd_sta_set_rfeature_wpa3(const char *intf, struct sigma_dut *dut,
14761 struct sigma_conn *conn,
14762 struct sigma_cmd *cmd)
14763{
Vamsi Krishnad29bc762020-05-08 23:23:30 +053014764 const char *val, *oci_chan, *oci_frametype;
Jouni Malinen6250cb02020-04-15 13:54:45 +030014765
Veerendranath Jakkam30bf9072020-04-16 14:37:57 +053014766 val = get_param(cmd, "ReassocReq_RSNXE_Used");
Jouni Malinen6250cb02020-04-15 13:54:45 +030014767 if (val && atoi(val) == 1) {
Veerendranath Jakkamc771fac2020-07-22 01:32:56 +053014768 if (wifi_chip_type == DRIVER_WCN) {
14769 if (wcn_sta_set_rsnxe_used(dut, intf, 1)) {
14770 send_resp(dut, conn, SIGMA_ERROR,
14771 "errorCode,Failed to set ft_rsnxe_used");
14772 return STATUS_SENT_ERROR;
14773 }
14774 return SUCCESS_SEND_STATUS;
14775 } else if (wpa_command(intf, "SET ft_rsnxe_used 1") < 0) {
Jouni Malinen6250cb02020-04-15 13:54:45 +030014776 send_resp(dut, conn, SIGMA_ERROR,
14777 "errorCode,Failed to set ft_rsnxe_used");
14778 return STATUS_SENT_ERROR;
14779 }
14780 return SUCCESS_SEND_STATUS;
14781 }
Vamsi Krishnad29bc762020-05-08 23:23:30 +053014782
14783 oci_chan = get_param(cmd, "OCIChannel");
14784 oci_frametype = get_param(cmd, "OCIFrameType");
14785 if (oci_chan && oci_frametype) {
14786 unsigned int oci_freq = channel_to_freq(dut, atoi(oci_chan));
14787 char buf[100];
14788
14789 if (!oci_freq) {
14790 send_resp(dut, conn, SIGMA_ERROR,
14791 "errorCode,Invalid OCIChannel number");
14792 return STATUS_SENT_ERROR;
14793 }
14794
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053014795 if (wifi_chip_type == DRIVER_WCN &&
14796 (strcasecmp(oci_frametype, "SAQueryReq") == 0 ||
14797 strcasecmp(oci_frametype, "SAQueryResp") == 0 ||
14798 strcasecmp(oci_frametype, "Reassocreq") == 0)) {
14799 if (wcn_sta_override_oci(dut, intf, oci_frametype,
14800 oci_freq)) {
14801 send_resp(dut, conn, SIGMA_ERROR,
14802 "errorCode,Failed to override OCI");
14803 return STATUS_SENT_ERROR;
14804 }
14805 return SUCCESS_SEND_STATUS;
14806 }
14807
Vamsi Krishnad29bc762020-05-08 23:23:30 +053014808 if (strcasecmp(oci_frametype, "eapolM2") == 0) {
14809 snprintf(buf, sizeof(buf),
14810 "SET oci_freq_override_eapol %d", oci_freq);
14811 } else if (strcasecmp(oci_frametype, "SAQueryReq") == 0) {
14812 snprintf(buf, sizeof(buf),
14813 "SET oci_freq_override_saquery_req %d",
14814 oci_freq);
14815 } else if (strcasecmp(oci_frametype, "SAQueryResp") == 0) {
14816 snprintf(buf, sizeof(buf),
14817 "SET oci_freq_override_saquery_resp %d",
14818 oci_freq);
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053014819 } else if (strcasecmp(oci_frametype, "GrpKeyM2") == 0) {
14820 snprintf(buf, sizeof(buf),
14821 "SET oci_freq_override_eapol_g2 %d",
14822 oci_freq);
14823 } else if (strcasecmp(oci_frametype, "Reassocreq") == 0) {
14824 snprintf(buf, sizeof(buf),
14825 "SET oci_freq_override_ft_assoc %d",
14826 oci_freq);
Vamsi Krishnad29bc762020-05-08 23:23:30 +053014827 } else {
14828 send_resp(dut, conn, SIGMA_ERROR,
14829 "errorCode,Unsupported OCIFrameType");
14830 return STATUS_SENT_ERROR;
14831 }
14832 if (wpa_command(intf, buf) < 0) {
14833 send_resp(dut, conn, SIGMA_ERROR,
14834 "errorCode,Failed to set oci_freq_override");
14835 return STATUS_SENT_ERROR;
14836 }
14837 return SUCCESS_SEND_STATUS;
14838 }
14839
Veerendranath Jakkam50d5c782020-07-22 01:59:01 +053014840 val = get_param(cmd, "IgnoreCSA");
14841 if (val && atoi(val) == 1) {
14842 if (wifi_chip_type == DRIVER_WCN) {
14843 if (wcn_sta_ignore_csa(dut, intf, 1)) {
14844 send_resp(dut, conn, SIGMA_ERROR,
14845 "errorCode,Failed to set ignore CSA");
14846 return STATUS_SENT_ERROR;
14847 }
14848 return SUCCESS_SEND_STATUS;
14849 }
14850 }
14851
Veerendranath Jakkam1e1e5fd2020-09-10 07:12:37 +053014852 val = get_param(cmd, "Deauth_Per_SAQueryResp");
14853 if (val && atoi(val) == 0) {
14854 if (wifi_chip_type == DRIVER_WCN) {
14855 if (wcn_sta_ignore_sa_query_timeout(dut, intf, 1)) {
14856 send_resp(dut, conn, SIGMA_ERROR,
14857 "errorCode,Failed to set ignore SA Query timeout");
14858 return STATUS_SENT_ERROR;
14859 }
14860 return SUCCESS_SEND_STATUS;
14861 }
14862 }
14863
Jouni Malinen6250cb02020-04-15 13:54:45 +030014864 send_resp(dut, conn, SIGMA_ERROR,
14865 "errorCode,Unsupported WPA3 rfeature");
14866 return STATUS_SENT_ERROR;
14867}
14868
14869
Veerendranath Jakkam329a3cd2021-09-11 18:10:13 +053014870static enum sigma_cmd_result
14871cmd_sta_set_rfeature_qm(const char *intf, struct sigma_dut *dut,
14872 struct sigma_conn *conn, struct sigma_cmd *cmd)
14873{
14874 const char *val;
14875
14876 val = get_param(cmd, "DomainName_Domain");
14877 if (val) {
14878 if (strlen(val) >= sizeof(dut->qm_domain_name))
14879 return ERROR_SEND_STATUS;
14880
14881 strlcpy(dut->qm_domain_name, val, sizeof(dut->qm_domain_name));
14882 return SUCCESS_SEND_STATUS;
14883 }
14884
Veerendranath Jakkam1bf1bd62021-09-12 16:35:55 +053014885 val = get_param(cmd, "DSCPPolicy_PolicyID");
14886 if (val) {
14887 unsigned int i;
14888 int policy_id = atoi(val);
14889
14890 val = get_param(cmd, "DSCPPolicy_RequestType");
14891
14892 if (!policy_id || !val)
14893 return INVALID_SEND_STATUS;
14894
14895 if (dut->num_dscp_status >= ARRAY_SIZE(dut->dscp_status)) {
14896 send_resp(dut, conn, SIGMA_ERROR,
14897 "errorCode,DSCP status list full");
14898 return STATUS_SENT_ERROR;
14899 }
14900
14901 for (i = 0; i < dut->num_dscp_status; i++)
14902 if (dut->dscp_status[i].id == policy_id)
14903 break;
14904
14905 /* New policy configured */
14906 if (i == dut->num_dscp_status) {
14907 dut->dscp_status[i].id = policy_id;
14908 dut->num_dscp_status++;
14909 }
14910
14911 dut->dscp_status[i].status = strcasecmp(val, "Remove") ?
14912 DSCP_POLICY_SUCCESS : DSCP_POLICY_REJECT;
14913
14914 return SUCCESS_SEND_STATUS;
14915 }
14916
Veerendranath Jakkam329a3cd2021-09-11 18:10:13 +053014917 send_resp(dut, conn, SIGMA_ERROR,
14918 "errorCode,Unsupported QM rfeature");
14919 return STATUS_SENT_ERROR;
14920}
14921
14922
Jouni Malinenf7222712019-06-13 01:50:21 +030014923static enum sigma_cmd_result cmd_sta_set_rfeature(struct sigma_dut *dut,
14924 struct sigma_conn *conn,
14925 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014926{
14927 const char *intf = get_param(cmd, "Interface");
14928 const char *prog = get_param(cmd, "Prog");
Ashwini Patil68d02cd2017-01-10 15:39:16 +053014929 const char *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014930
Veerendranath Jakkam329a3cd2021-09-11 18:10:13 +053014931 if (!prog)
14932 prog = get_param(cmd, "Program");
14933
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014934 if (intf == NULL || prog == NULL)
14935 return -1;
14936
Ashwini Patil5acd7382017-04-13 15:55:04 +053014937 /* BSS Transition candidate list for BTM query */
14938 val = get_param(cmd, "Nebor_BSSID");
14939 if (val && btm_query_candidate_list(dut, conn, cmd) == 0)
14940 return 0;
14941
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014942 if (strcasecmp(prog, "TDLS") == 0)
14943 return cmd_sta_set_rfeature_tdls(intf, dut, conn, cmd);
14944
14945 if (strcasecmp(prog, "VHT") == 0)
14946 return cmd_sta_set_rfeature_vht(intf, dut, conn, cmd);
14947
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014948 if (strcasecmp(prog, "HE") == 0)
14949 return cmd_sta_set_rfeature_he(intf, dut, conn, cmd);
14950
Ashwini Patil68d02cd2017-01-10 15:39:16 +053014951 if (strcasecmp(prog, "MBO") == 0) {
14952 val = get_param(cmd, "Cellular_Data_Cap");
14953 if (val &&
14954 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
14955 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +053014956
14957 val = get_param(cmd, "Ch_Pref");
14958 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
14959 return 0;
14960
Ashwini Patil68d02cd2017-01-10 15:39:16 +053014961 return 1;
14962 }
14963
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020014964 if (strcasecmp(prog, "60GHz") == 0)
14965 return cmd_sta_set_rfeature_60g(intf, dut, conn, cmd);
14966
Jouni Malinen6250cb02020-04-15 13:54:45 +030014967 if (strcasecmp(prog, "WPA3") == 0)
14968 return cmd_sta_set_rfeature_wpa3(intf, dut, conn, cmd);
Veerendranath Jakkam329a3cd2021-09-11 18:10:13 +053014969 if (strcasecmp(prog, "QM") == 0)
14970 return cmd_sta_set_rfeature_qm(intf, dut, conn, cmd);
Jouni Malinen6250cb02020-04-15 13:54:45 +030014971
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014972 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported Prog");
14973 return 0;
14974}
14975
14976
Jouni Malinenf7222712019-06-13 01:50:21 +030014977static enum sigma_cmd_result cmd_sta_set_radio(struct sigma_dut *dut,
14978 struct sigma_conn *conn,
14979 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014980{
14981 const char *intf = get_param(cmd, "Interface");
14982 const char *mode = get_param(cmd, "Mode");
14983 int res;
14984
14985 if (intf == NULL || mode == NULL)
14986 return -1;
14987
14988 if (strcasecmp(mode, "On") == 0)
14989 res = wpa_command(intf, "SET radio_disabled 0");
14990 else if (strcasecmp(mode, "Off") == 0)
14991 res = wpa_command(intf, "SET radio_disabled 1");
14992 else
14993 return -1;
14994
14995 if (res) {
14996 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
14997 "radio mode");
14998 return 0;
14999 }
15000
15001 return 1;
15002}
15003
15004
Jouni Malinenf7222712019-06-13 01:50:21 +030015005static enum sigma_cmd_result cmd_sta_set_pwrsave(struct sigma_dut *dut,
15006 struct sigma_conn *conn,
15007 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015008{
15009 const char *intf = get_param(cmd, "Interface");
15010 const char *mode = get_param(cmd, "Mode");
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020015011 const char *prog = get_param(cmd, "program");
15012 const char *powersave = get_param(cmd, "powersave");
15013 int res = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015014
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020015015 if (intf == NULL)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015016 return -1;
15017
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020015018 if (prog && strcasecmp(prog, "60GHz") == 0) {
15019 /*
15020 * The CAPI mode parameter does not exist in 60G
15021 * unscheduled PS.
15022 */
Hu Wang5dc3ff12019-06-14 15:14:26 +080015023 if (powersave && strcasecmp(powersave, "unscheduled") == 0)
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020015024 res = set_ps(intf, dut, 1);
Jouni Malinen016ae6c2019-11-04 17:00:01 +020015025 } else if (prog && get_driver_type(dut) == DRIVER_WCN &&
Alexei Avshalom Lazar2f6fdb42019-02-04 14:16:08 +020015026 strcasecmp(prog, "HE") == 0) {
15027 return cmd_sta_set_power_save_he(intf, dut, conn, cmd);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020015028 } else {
15029 if (mode == NULL)
15030 return -1;
15031
15032 if (strcasecmp(mode, "On") == 0)
15033 res = set_ps(intf, dut, 1);
15034 else if (strcasecmp(mode, "Off") == 0)
15035 res = set_ps(intf, dut, 0);
15036 else
15037 return -1;
15038 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015039
15040 if (res) {
15041 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
15042 "power save mode");
15043 return 0;
15044 }
15045
15046 return 1;
15047}
15048
15049
Jouni Malinenf7222712019-06-13 01:50:21 +030015050static enum sigma_cmd_result cmd_sta_bssid_pool(struct sigma_dut *dut,
15051 struct sigma_conn *conn,
15052 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015053{
15054 const char *intf = get_param(cmd, "Interface");
15055 const char *val, *bssid;
15056 int res;
15057 char *buf;
15058 size_t buf_len;
15059
15060 val = get_param(cmd, "BSSID_FILTER");
15061 if (val == NULL)
15062 return -1;
15063
15064 bssid = get_param(cmd, "BSSID_List");
15065 if (atoi(val) == 0 || bssid == NULL) {
15066 /* Disable BSSID filter */
15067 if (wpa_command(intf, "SET bssid_filter ")) {
15068 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed "
15069 "to disable BSSID filter");
15070 return 0;
15071 }
15072
15073 return 1;
15074 }
15075
15076 buf_len = 100 + strlen(bssid);
15077 buf = malloc(buf_len);
15078 if (buf == NULL)
15079 return -1;
15080
15081 snprintf(buf, buf_len, "SET bssid_filter %s", bssid);
15082 res = wpa_command(intf, buf);
15083 free(buf);
15084 if (res) {
15085 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to enable "
15086 "BSSID filter");
15087 return 0;
15088 }
15089
15090 return 1;
15091}
15092
15093
Jouni Malinenf7222712019-06-13 01:50:21 +030015094static enum sigma_cmd_result cmd_sta_reset_parm(struct sigma_dut *dut,
15095 struct sigma_conn *conn,
15096 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015097{
15098 const char *intf = get_param(cmd, "Interface");
15099 const char *val;
15100
15101 /* TODO: ARP */
15102
15103 val = get_param(cmd, "HS2_CACHE_PROFILE");
15104 if (val && strcasecmp(val, "All") == 0)
15105 hs2_clear_credentials(intf);
15106
15107 return 1;
15108}
15109
15110
Jouni Malinenf7222712019-06-13 01:50:21 +030015111static enum sigma_cmd_result cmd_sta_get_key(struct sigma_dut *dut,
15112 struct sigma_conn *conn,
15113 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015114{
15115 const char *intf = get_param(cmd, "Interface");
15116 const char *key_type = get_param(cmd, "KeyType");
15117 char buf[100], resp[200];
15118
15119 if (key_type == NULL)
15120 return -1;
15121
15122 if (strcasecmp(key_type, "GTK") == 0) {
15123 if (wpa_command_resp(intf, "GET gtk", buf, sizeof(buf)) < 0 ||
15124 strncmp(buf, "FAIL", 4) == 0) {
15125 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
15126 "not fetch current GTK");
15127 return 0;
15128 }
15129 snprintf(resp, sizeof(resp), "KeyValue,%s", buf);
15130 send_resp(dut, conn, SIGMA_COMPLETE, resp);
15131 return 0;
15132 } else {
15133 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
15134 "KeyType");
15135 return 0;
15136 }
15137
15138 return 1;
15139}
15140
15141
15142static int hs2_set_policy(struct sigma_dut *dut)
15143{
15144#ifdef ANDROID
15145 system("ip rule del prio 23000");
15146 if (system("ip rule add from all lookup main prio 23000") != 0) {
15147 sigma_dut_print(dut, DUT_MSG_ERROR,
15148 "Failed to run:ip rule add from all lookup main prio");
15149 return -1;
15150 }
15151 if (system("ip route flush cache") != 0) {
15152 sigma_dut_print(dut, DUT_MSG_ERROR,
15153 "Failed to run ip route flush cache");
15154 return -1;
15155 }
15156 return 1;
15157#else /* ANDROID */
15158 return 0;
15159#endif /* ANDROID */
15160}
15161
15162
Jouni Malinenf7222712019-06-13 01:50:21 +030015163static enum sigma_cmd_result cmd_sta_hs2_associate(struct sigma_dut *dut,
15164 struct sigma_conn *conn,
15165 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015166{
15167 const char *intf = get_param(cmd, "Interface");
15168 const char *val = get_param(cmd, "Ignore_blacklist");
Jouni Malinen439352d2018-09-13 03:42:23 +030015169 const char *band = get_param(cmd, "Band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015170 struct wpa_ctrl *ctrl;
Jouni Malinen3aa72862019-05-29 23:14:51 +030015171 int res, r;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015172 char bssid[20], ssid[40], resp[100], buf[100], blacklisted[100];
15173 int tries = 0;
15174 int ignore_blacklist = 0;
15175 const char *events[] = {
15176 "CTRL-EVENT-CONNECTED",
15177 "INTERWORKING-BLACKLISTED",
15178 "INTERWORKING-NO-MATCH",
15179 NULL
15180 };
15181
15182 start_sta_mode(dut);
15183
Jouni Malinen439352d2018-09-13 03:42:23 +030015184 if (band) {
15185 if (strcmp(band, "2.4") == 0) {
15186 wpa_command(intf, "SET setband 2G");
15187 } else if (strcmp(band, "5") == 0) {
15188 wpa_command(intf, "SET setband 5G");
15189 } else {
15190 send_resp(dut, conn, SIGMA_ERROR,
15191 "errorCode,Unsupported band");
15192 return 0;
15193 }
15194 }
15195
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015196 blacklisted[0] = '\0';
15197 if (val && atoi(val))
15198 ignore_blacklist = 1;
15199
15200try_again:
15201 ctrl = open_wpa_mon(intf);
15202 if (ctrl == NULL) {
15203 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
15204 "wpa_supplicant monitor connection");
15205 return -2;
15206 }
15207
15208 tries++;
15209 if (wpa_command(intf, "INTERWORKING_SELECT auto")) {
15210 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start "
15211 "Interworking connection");
15212 wpa_ctrl_detach(ctrl);
15213 wpa_ctrl_close(ctrl);
15214 return 0;
15215 }
15216
15217 buf[0] = '\0';
15218 while (1) {
15219 char *pos;
15220 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
15221 pos = strstr(buf, "INTERWORKING-BLACKLISTED");
15222 if (!pos)
15223 break;
15224 pos += 25;
15225 sigma_dut_print(dut, DUT_MSG_DEBUG, "Found blacklisted AP: %s",
15226 pos);
15227 if (!blacklisted[0])
15228 memcpy(blacklisted, pos, strlen(pos) + 1);
15229 }
15230
15231 if (ignore_blacklist && blacklisted[0]) {
15232 char *end;
15233 end = strchr(blacklisted, ' ');
15234 if (end)
15235 *end = '\0';
15236 sigma_dut_print(dut, DUT_MSG_DEBUG, "Try to connect to a blacklisted network: %s",
15237 blacklisted);
Jouni Malinen3aa72862019-05-29 23:14:51 +030015238 r = snprintf(buf, sizeof(buf), "INTERWORKING_CONNECT %s",
15239 blacklisted);
15240 if (r < 0 || r >= sizeof(buf) || wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015241 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start Interworking connection to blacklisted network");
15242 wpa_ctrl_detach(ctrl);
15243 wpa_ctrl_close(ctrl);
15244 return 0;
15245 }
15246 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
15247 buf, sizeof(buf));
15248 }
15249
15250 wpa_ctrl_detach(ctrl);
15251 wpa_ctrl_close(ctrl);
15252
15253 if (res < 0) {
15254 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
15255 "connect");
15256 return 0;
15257 }
15258
15259 if (strstr(buf, "INTERWORKING-NO-MATCH") ||
15260 strstr(buf, "INTERWORKING-BLACKLISTED")) {
15261 if (tries < 2) {
15262 sigma_dut_print(dut, DUT_MSG_INFO, "No match found - try again to verify no APs were missed in the scan");
15263 goto try_again;
15264 }
15265 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,No network with "
15266 "matching credentials found");
15267 return 0;
15268 }
15269
15270 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
15271 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
15272 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
15273 "get current BSSID/SSID");
15274 return 0;
15275 }
15276
15277 snprintf(resp, sizeof(resp), "SSID,%s,BSSID,%s", ssid, bssid);
15278 send_resp(dut, conn, SIGMA_COMPLETE, resp);
15279 hs2_set_policy(dut);
15280 return 0;
15281}
15282
15283
Jouni Malinenf7222712019-06-13 01:50:21 +030015284static enum sigma_cmd_result cmd_sta_hs2_venue_info(struct sigma_dut *dut,
15285 struct sigma_conn *conn,
15286 struct sigma_cmd *cmd)
Jouni Malinenb639f1c2018-09-13 02:39:46 +030015287{
15288 const char *intf = get_param(cmd, "Interface");
15289 const char *display = get_param(cmd, "Display");
15290 struct wpa_ctrl *ctrl;
15291 char buf[300], params[400], *pos;
15292 char bssid[20];
15293 int info_avail = 0;
15294 unsigned int old_timeout;
15295 int res;
15296
15297 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
15298 send_resp(dut, conn, SIGMA_ERROR,
15299 "ErrorCode,Could not get current BSSID");
15300 return 0;
15301 }
15302 ctrl = open_wpa_mon(intf);
15303 if (!ctrl) {
15304 sigma_dut_print(dut, DUT_MSG_ERROR,
15305 "Failed to open wpa_supplicant monitor connection");
15306 return -2;
15307 }
15308
15309 snprintf(buf, sizeof(buf), "ANQP_GET %s 277", bssid);
15310 wpa_command(intf, buf);
15311
15312 res = get_wpa_cli_event(dut, ctrl, "GAS-QUERY-DONE", buf, sizeof(buf));
15313 if (res < 0) {
15314 send_resp(dut, conn, SIGMA_ERROR,
15315 "ErrorCode,Could not complete GAS query");
15316 goto fail;
15317 }
15318
15319 old_timeout = dut->default_timeout;
15320 dut->default_timeout = 2;
15321 res = get_wpa_cli_event(dut, ctrl, "RX-VENUE-URL", buf, sizeof(buf));
15322 dut->default_timeout = old_timeout;
15323 if (res < 0)
15324 goto done;
15325 pos = strchr(buf, ' ');
15326 if (!pos)
15327 goto done;
15328 pos++;
15329 pos = strchr(pos, ' ');
15330 if (!pos)
15331 goto done;
15332 pos++;
15333 info_avail = 1;
15334 snprintf(params, sizeof(params), "browser %s", pos);
15335
15336 if (display && strcasecmp(display, "Yes") == 0) {
15337 pid_t pid;
15338
15339 pid = fork();
15340 if (pid < 0) {
15341 perror("fork");
15342 return -1;
15343 }
15344
15345 if (pid == 0) {
15346 run_hs20_osu(dut, params);
15347 exit(0);
15348 }
15349 }
15350
15351done:
15352 snprintf(buf, sizeof(buf), "Info_available,%s",
15353 info_avail ? "Yes" : "No");
15354 send_resp(dut, conn, SIGMA_COMPLETE, buf);
15355fail:
15356 wpa_ctrl_detach(ctrl);
15357 wpa_ctrl_close(ctrl);
15358 return 0;
15359}
15360
15361
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015362static int sta_add_credential_uname_pwd(struct sigma_dut *dut,
15363 struct sigma_conn *conn,
15364 const char *ifname,
15365 struct sigma_cmd *cmd)
15366{
15367 const char *val;
15368 int id;
15369
15370 id = add_cred(ifname);
15371 if (id < 0)
15372 return -2;
15373 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
15374
15375 val = get_param(cmd, "prefer");
15376 if (val && atoi(val) > 0)
15377 set_cred(ifname, id, "priority", "1");
15378
15379 val = get_param(cmd, "REALM");
15380 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
15381 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
15382 "realm");
15383 return 0;
15384 }
15385
15386 val = get_param(cmd, "HOME_FQDN");
15387 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
15388 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
15389 "home_fqdn");
15390 return 0;
15391 }
15392
15393 val = get_param(cmd, "Username");
15394 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
15395 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
15396 "username");
15397 return 0;
15398 }
15399
15400 val = get_param(cmd, "Password");
15401 if (val && set_cred_quoted(ifname, id, "password", val) < 0) {
15402 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
15403 "password");
15404 return 0;
15405 }
15406
15407 val = get_param(cmd, "ROOT_CA");
15408 if (val) {
15409 char fname[200];
15410 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
15411#ifdef __linux__
15412 if (!file_exists(fname)) {
15413 char msg[300];
15414 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
15415 "file (%s) not found", fname);
15416 send_resp(dut, conn, SIGMA_ERROR, msg);
15417 return 0;
15418 }
15419#endif /* __linux__ */
15420 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
15421 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
15422 "not set root CA");
15423 return 0;
15424 }
15425 }
15426
15427 return 1;
15428}
15429
15430
15431static int update_devdetail_imsi(struct sigma_dut *dut, const char *imsi)
15432{
15433 FILE *in, *out;
15434 char buf[500];
15435 int found = 0;
15436
15437 in = fopen("devdetail.xml", "r");
15438 if (in == NULL)
15439 return -1;
15440 out = fopen("devdetail.xml.tmp", "w");
15441 if (out == NULL) {
15442 fclose(in);
15443 return -1;
15444 }
15445
15446 while (fgets(buf, sizeof(buf), in)) {
15447 char *pos = strstr(buf, "<IMSI>");
15448 if (pos) {
15449 sigma_dut_print(dut, DUT_MSG_INFO, "Updated DevDetail IMSI to %s",
15450 imsi);
15451 pos += 6;
15452 *pos = '\0';
15453 fprintf(out, "%s%s</IMSI>\n", buf, imsi);
15454 found++;
15455 } else {
15456 fprintf(out, "%s", buf);
15457 }
15458 }
15459
15460 fclose(out);
15461 fclose(in);
15462 if (found)
15463 rename("devdetail.xml.tmp", "devdetail.xml");
15464 else
15465 unlink("devdetail.xml.tmp");
15466
15467 return 0;
15468}
15469
15470
15471static int sta_add_credential_sim(struct sigma_dut *dut,
15472 struct sigma_conn *conn,
15473 const char *ifname, struct sigma_cmd *cmd)
15474{
15475 const char *val, *imsi = NULL;
15476 int id;
15477 char buf[200];
15478 int res;
15479 const char *pos;
15480 size_t mnc_len;
15481 char plmn_mcc[4];
15482 char plmn_mnc[4];
15483
15484 id = add_cred(ifname);
15485 if (id < 0)
15486 return -2;
15487 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
15488
15489 val = get_param(cmd, "prefer");
15490 if (val && atoi(val) > 0)
15491 set_cred(ifname, id, "priority", "1");
15492
15493 val = get_param(cmd, "PLMN_MCC");
15494 if (val == NULL) {
15495 send_resp(dut, conn, SIGMA_ERROR,
15496 "errorCode,Missing PLMN_MCC");
15497 return 0;
15498 }
15499 if (strlen(val) != 3) {
15500 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MCC");
15501 return 0;
15502 }
15503 snprintf(plmn_mcc, sizeof(plmn_mcc), "%s", val);
15504
15505 val = get_param(cmd, "PLMN_MNC");
15506 if (val == NULL) {
15507 send_resp(dut, conn, SIGMA_ERROR,
15508 "errorCode,Missing PLMN_MNC");
15509 return 0;
15510 }
15511 if (strlen(val) != 2 && strlen(val) != 3) {
15512 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MNC");
15513 return 0;
15514 }
15515 snprintf(plmn_mnc, sizeof(plmn_mnc), "%s", val);
15516
15517 val = get_param(cmd, "IMSI");
15518 if (val == NULL) {
15519 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing SIM "
15520 "IMSI");
15521 return 0;
15522 }
15523
15524 imsi = pos = val;
15525
15526 if (strncmp(plmn_mcc, pos, 3) != 0) {
15527 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MCC mismatch");
15528 return 0;
15529 }
15530 pos += 3;
15531
15532 mnc_len = strlen(plmn_mnc);
15533 if (mnc_len < 2) {
15534 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC not set");
15535 return 0;
15536 }
15537
15538 if (strncmp(plmn_mnc, pos, mnc_len) != 0) {
15539 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC mismatch");
15540 return 0;
15541 }
15542 pos += mnc_len;
15543
15544 res = snprintf(buf, sizeof(buf), "%s%s-%s",plmn_mcc, plmn_mnc, pos);
15545 if (res < 0 || res >= (int) sizeof(buf))
15546 return -1;
15547 if (set_cred_quoted(ifname, id, "imsi", buf) < 0) {
15548 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
15549 "not set IMSI");
15550 return 0;
15551 }
15552
15553 val = get_param(cmd, "Password");
15554 if (val && set_cred_quoted(ifname, id, "milenage", val) < 0) {
15555 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
15556 "not set password");
15557 return 0;
15558 }
15559
Jouni Malinenba630452018-06-22 11:49:59 +030015560 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015561 /*
15562 * Set provisioning_sp for the test cases where SIM/USIM
15563 * provisioning is used.
15564 */
15565 if (val && set_cred_quoted(ifname, id, "provisioning_sp",
15566 "wi-fi.org") < 0) {
15567 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
15568 "not set provisioning_sp");
15569 return 0;
15570 }
15571
15572 update_devdetail_imsi(dut, imsi);
15573 }
15574
15575 return 1;
15576}
15577
15578
15579static int sta_add_credential_cert(struct sigma_dut *dut,
15580 struct sigma_conn *conn,
15581 const char *ifname,
15582 struct sigma_cmd *cmd)
15583{
15584 const char *val;
15585 int id;
15586
15587 id = add_cred(ifname);
15588 if (id < 0)
15589 return -2;
15590 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
15591
15592 val = get_param(cmd, "prefer");
15593 if (val && atoi(val) > 0)
15594 set_cred(ifname, id, "priority", "1");
15595
15596 val = get_param(cmd, "REALM");
15597 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
15598 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
15599 "realm");
15600 return 0;
15601 }
15602
15603 val = get_param(cmd, "HOME_FQDN");
15604 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
15605 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
15606 "home_fqdn");
15607 return 0;
15608 }
15609
15610 val = get_param(cmd, "Username");
15611 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
15612 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
15613 "username");
15614 return 0;
15615 }
15616
15617 val = get_param(cmd, "clientCertificate");
15618 if (val) {
15619 char fname[200];
15620 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
15621#ifdef __linux__
15622 if (!file_exists(fname)) {
15623 char msg[300];
15624 snprintf(msg, sizeof(msg),
15625 "ErrorCode,clientCertificate "
15626 "file (%s) not found", fname);
15627 send_resp(dut, conn, SIGMA_ERROR, msg);
15628 return 0;
15629 }
15630#endif /* __linux__ */
15631 if (set_cred_quoted(ifname, id, "client_cert", fname) < 0) {
15632 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
15633 "not set client_cert");
15634 return 0;
15635 }
15636 if (set_cred_quoted(ifname, id, "private_key", fname) < 0) {
15637 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
15638 "not set private_key");
15639 return 0;
15640 }
15641 }
15642
15643 val = get_param(cmd, "ROOT_CA");
15644 if (val) {
15645 char fname[200];
15646 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
15647#ifdef __linux__
15648 if (!file_exists(fname)) {
15649 char msg[300];
15650 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
15651 "file (%s) not found", fname);
15652 send_resp(dut, conn, SIGMA_ERROR, msg);
15653 return 0;
15654 }
15655#endif /* __linux__ */
15656 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
15657 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
15658 "not set root CA");
15659 return 0;
15660 }
15661 }
15662
15663 return 1;
15664}
15665
15666
Jouni Malinenf7222712019-06-13 01:50:21 +030015667static enum sigma_cmd_result cmd_sta_add_credential(struct sigma_dut *dut,
15668 struct sigma_conn *conn,
15669 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015670{
15671 const char *intf = get_param(cmd, "Interface");
15672 const char *type;
15673
15674 start_sta_mode(dut);
15675
15676 type = get_param(cmd, "Type");
15677 if (!type)
15678 return -1;
15679
15680 if (strcasecmp(type, "uname_pwd") == 0)
15681 return sta_add_credential_uname_pwd(dut, conn, intf, cmd);
15682
15683 if (strcasecmp(type, "sim") == 0)
15684 return sta_add_credential_sim(dut, conn, intf, cmd);
15685
15686 if (strcasecmp(type, "cert") == 0)
15687 return sta_add_credential_cert(dut, conn, intf, cmd);
15688
15689 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported credential "
15690 "type");
15691 return 0;
15692}
15693
15694
Jouni Malinenf7222712019-06-13 01:50:21 +030015695static enum sigma_cmd_result cmd_sta_scan(struct sigma_dut *dut,
15696 struct sigma_conn *conn,
15697 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015698{
15699 const char *intf = get_param(cmd, "Interface");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080015700 const char *val, *bssid, *ssid, *scan_freq, *short_ssid;
Veerendranathdc581b52020-08-10 03:29:08 -070015701 char buf[4096], scan_res[20];
vamsi krishna89ad8c62017-09-19 12:51:18 +053015702 char ssid_hex[65];
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080015703 int wildcard_ssid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015704 int res;
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080015705 enum sigma_cmd_result status;
Jouni Malinen228a2fc2020-06-22 23:37:45 +030015706 struct wpa_ctrl *ctrl = NULL;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015707
Jouni Malinen8c1abeb2019-11-06 18:48:34 +020015708 start_sta_mode(dut);
15709
Arif Hussain66a4af02019-02-07 15:04:51 -080015710 val = get_param(cmd, "GetParameter");
15711 if (val && strcmp(val, "SSID_BSSID") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020015712 if (get_wpa_ssid_bssid(dut, get_station_ifname(dut),
Arif Hussain66a4af02019-02-07 15:04:51 -080015713 buf, sizeof(buf)) < 0) {
15714 sigma_dut_print(dut, DUT_MSG_ERROR,
15715 "Could not get ssid bssid");
15716 return ERROR_SEND_STATUS;
15717 }
15718
15719 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
15720 send_resp(dut, conn, SIGMA_COMPLETE, buf);
15721 return STATUS_SENT;
15722 }
15723
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015724 val = get_param(cmd, "HESSID");
15725 if (val) {
15726 res = snprintf(buf, sizeof(buf), "SET hessid %s", val);
15727 if (res < 0 || res >= (int) sizeof(buf))
15728 return -1;
15729 wpa_command(intf, buf);
15730 }
15731
15732 val = get_param(cmd, "ACCS_NET_TYPE");
15733 if (val) {
15734 res = snprintf(buf, sizeof(buf), "SET access_network_type %s",
15735 val);
15736 if (res < 0 || res >= (int) sizeof(buf))
15737 return -1;
15738 wpa_command(intf, buf);
15739 }
15740
Kiran Kumar Lokere69d89952021-08-08 23:41:46 -070015741 if (get_param(cmd, "RxMac"))
15742 sta_set_scan_unicast_probe(dut, intf, 1);
15743
vamsi krishna89ad8c62017-09-19 12:51:18 +053015744 bssid = get_param(cmd, "Bssid");
15745 ssid = get_param(cmd, "Ssid");
Kiran Kumar Lokere69d89952021-08-08 23:41:46 -070015746 if (!bssid)
15747 bssid = get_param(cmd, "RxMac");
vamsi krishna89ad8c62017-09-19 12:51:18 +053015748
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080015749 if (ssid && strcasecmp(ssid, "ZeroLength") == 0 &&
15750 dut->device_type == STA_testbed) {
15751 ssid = NULL;
15752 wildcard_ssid = 1;
15753 }
15754
vamsi krishna89ad8c62017-09-19 12:51:18 +053015755 if (ssid) {
15756 if (2 * strlen(ssid) >= sizeof(ssid_hex)) {
15757 send_resp(dut, conn, SIGMA_ERROR,
15758 "ErrorCode,Too long SSID");
15759 return 0;
15760 }
15761 ascii2hexstr(ssid, ssid_hex);
15762 }
15763
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080015764 short_ssid = get_param(cmd, "ShortSSID");
15765 if (short_ssid) {
15766 uint32_t short_ssid_hex;
15767
15768 short_ssid_hex = strtoul(short_ssid, NULL, 16);
15769 short_ssid_hex = ((short_ssid_hex & 0xFF) << 24) |
15770 (((short_ssid_hex >> 8) & 0xFF) << 16) |
15771 (((short_ssid_hex >> 16) & 0xFF) << 8) |
15772 ((short_ssid_hex >> 24) & 0xFF);
15773
15774 res = snprintf(buf, sizeof(buf),
15775 "VENDOR_ELEM_ADD 14 ff053a%08x",
15776 short_ssid_hex);
15777 if (res < 0 || res >= (int) sizeof(buf) ||
15778 wpa_command(intf, buf)) {
15779 send_resp(dut, conn, SIGMA_ERROR,
15780 "errorCode,Failed to add short SSID");
15781 return STATUS_SENT_ERROR;
15782 }
15783 }
15784
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080015785 scan_freq = get_param(cmd, "ChnlFreq");
Veerendranath Jakkam132c4b42020-08-10 00:29:03 +053015786 if (scan_freq) {
15787 if (strcasecmp(scan_freq, "2G") == 0)
15788 scan_freq = "2412-2462";
15789 else if (strcasecmp(scan_freq, "5G") == 0)
15790 scan_freq = "5180-5925";
15791 }
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080015792
Jouni Malinen228a2fc2020-06-22 23:37:45 +030015793 val = get_param(cmd, "WaitCompletion");
15794 if (val && atoi(val) == 1) {
15795 ctrl = open_wpa_mon(intf);
15796 if (!ctrl) {
15797 send_resp(dut, conn, SIGMA_ERROR,
15798 "errorCode,Failed to open monitor socket");
15799 return STATUS_SENT_ERROR;
15800 }
15801 }
15802
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080015803 res = snprintf(buf, sizeof(buf), "SCAN%s%s%s%s%s%s%s",
vamsi krishna89ad8c62017-09-19 12:51:18 +053015804 bssid ? " bssid=": "",
15805 bssid ? bssid : "",
15806 ssid ? " ssid " : "",
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080015807 ssid ? ssid_hex : "",
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080015808 wildcard_ssid ? " wildcard_ssid=1" : "",
15809 scan_freq ? " freq=" : "",
15810 scan_freq ? scan_freq : "");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080015811 if (res < 0 || res >= (int) sizeof(buf)) {
15812 send_resp(dut, conn, SIGMA_ERROR,
15813 "errorCode,Could not build scan command");
15814 status = STATUS_SENT_ERROR;
15815 goto remove_s_ssid;
15816 }
vamsi krishna89ad8c62017-09-19 12:51:18 +053015817
Veerendranathdc581b52020-08-10 03:29:08 -070015818 res = wpa_command_resp(intf, buf, scan_res, sizeof(scan_res));
15819 if (strncmp(scan_res, "FAIL-BUSY", 9) == 0) {
15820 sigma_dut_print(dut, DUT_MSG_DEBUG,
15821 "Scan request rejected with busy status, abort ongoing scan and try again");
15822 wpa_command(intf, "ABORT_SCAN");
15823 res = wpa_command(intf, buf);
15824 }
15825
15826 if (res < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015827 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not start "
15828 "scan");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080015829 status = STATUS_SENT_ERROR;
15830 } else {
15831 status = SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015832 }
15833
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080015834remove_s_ssid:
15835 if (short_ssid && wpa_command(intf, "VENDOR_ELEM_REMOVE 14 *"))
15836 sigma_dut_print(dut, DUT_MSG_ERROR,
15837 "Failed to delete vendor element");
15838
Jouni Malinen228a2fc2020-06-22 23:37:45 +030015839 if (ctrl) {
15840 if (status == SUCCESS_SEND_STATUS) {
15841 res = get_wpa_cli_event(dut, ctrl,
15842 "CTRL-EVENT-SCAN-RESULTS",
15843 buf, sizeof(buf));
15844 if (res < 0) {
15845 send_resp(dut, conn, SIGMA_ERROR,
15846 "ErrorCode,scan did not complete");
15847 status = STATUS_SENT_ERROR;
15848 }
15849 }
15850
15851 wpa_ctrl_detach(ctrl);
15852 wpa_ctrl_close(ctrl);
15853 }
15854
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080015855 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015856}
15857
15858
Jouni Malinenf7222712019-06-13 01:50:21 +030015859static enum sigma_cmd_result cmd_sta_scan_bss(struct sigma_dut *dut,
15860 struct sigma_conn *conn,
15861 struct sigma_cmd *cmd)
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020015862{
15863 const char *intf = get_param(cmd, "Interface");
15864 const char *bssid;
15865 char buf[4096], *pos;
15866 int freq, chan;
15867 char *ssid;
15868 char resp[100];
15869 int res;
15870 struct wpa_ctrl *ctrl;
15871
15872 bssid = get_param(cmd, "BSSID");
15873 if (!bssid) {
15874 send_resp(dut, conn, SIGMA_INVALID,
15875 "errorCode,BSSID argument is missing");
15876 return 0;
15877 }
15878
15879 ctrl = open_wpa_mon(intf);
15880 if (!ctrl) {
15881 sigma_dut_print(dut, DUT_MSG_ERROR,
15882 "Failed to open wpa_supplicant monitor connection");
15883 return -1;
15884 }
15885
15886 if (wpa_command(intf, "SCAN TYPE=ONLY")) {
15887 send_resp(dut, conn, SIGMA_ERROR,
15888 "errorCode,Could not start scan");
15889 wpa_ctrl_detach(ctrl);
15890 wpa_ctrl_close(ctrl);
15891 return 0;
15892 }
15893
15894 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
15895 buf, sizeof(buf));
15896
15897 wpa_ctrl_detach(ctrl);
15898 wpa_ctrl_close(ctrl);
15899
15900 if (res < 0) {
15901 send_resp(dut, conn, SIGMA_ERROR,
15902 "errorCode,Scan did not complete");
15903 return 0;
15904 }
15905
15906 snprintf(buf, sizeof(buf), "BSS %s", bssid);
15907 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
15908 strncmp(buf, "id=", 3) != 0) {
15909 send_resp(dut, conn, SIGMA_ERROR,
15910 "errorCode,Specified BSSID not found");
15911 return 0;
15912 }
15913
15914 pos = strstr(buf, "\nfreq=");
15915 if (!pos) {
15916 send_resp(dut, conn, SIGMA_ERROR,
15917 "errorCode,Channel not found");
15918 return 0;
15919 }
15920 freq = atoi(pos + 6);
15921 chan = freq_to_channel(freq);
15922
15923 pos = strstr(buf, "\nssid=");
15924 if (!pos) {
15925 send_resp(dut, conn, SIGMA_ERROR,
15926 "errorCode,SSID not found");
15927 return 0;
15928 }
15929 ssid = pos + 6;
15930 pos = strchr(ssid, '\n');
15931 if (pos)
15932 *pos = '\0';
15933 snprintf(resp, sizeof(resp), "ssid,%s,bsschannel,%d", ssid, chan);
15934 send_resp(dut, conn, SIGMA_COMPLETE, resp);
15935 return 0;
15936}
15937
15938
Jouni Malinenf7222712019-06-13 01:50:21 +030015939static enum sigma_cmd_result cmd_sta_set_systime(struct sigma_dut *dut,
15940 struct sigma_conn *conn,
15941 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015942{
15943#ifdef __linux__
15944 struct timeval tv;
15945 struct tm tm;
15946 time_t t;
15947 const char *val;
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053015948 int v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015949
Jouni Malinen016ae6c2019-11-04 17:00:01 +020015950 wpa_command(get_station_ifname(dut), "PMKSA_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015951
15952 memset(&tm, 0, sizeof(tm));
15953 val = get_param(cmd, "seconds");
15954 if (val)
15955 tm.tm_sec = atoi(val);
15956 val = get_param(cmd, "minutes");
15957 if (val)
15958 tm.tm_min = atoi(val);
15959 val = get_param(cmd, "hours");
15960 if (val)
15961 tm.tm_hour = atoi(val);
15962 val = get_param(cmd, "date");
15963 if (val)
15964 tm.tm_mday = atoi(val);
15965 val = get_param(cmd, "month");
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053015966 if (val) {
15967 v = atoi(val);
15968 if (v < 1 || v > 12) {
15969 send_resp(dut, conn, SIGMA_INVALID,
15970 "errorCode,Invalid month");
15971 return 0;
15972 }
15973 tm.tm_mon = v - 1;
15974 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015975 val = get_param(cmd, "year");
15976 if (val) {
15977 int year = atoi(val);
15978#ifdef ANDROID
15979 if (year > 2035)
15980 year = 2035; /* years beyond 2035 not supported */
15981#endif /* ANDROID */
15982 tm.tm_year = year - 1900;
15983 }
15984 t = mktime(&tm);
15985 if (t == (time_t) -1) {
15986 send_resp(dut, conn, SIGMA_ERROR,
15987 "errorCode,Invalid date or time");
15988 return 0;
15989 }
15990
15991 memset(&tv, 0, sizeof(tv));
15992 tv.tv_sec = t;
15993
15994 if (settimeofday(&tv, NULL) < 0) {
15995 sigma_dut_print(dut, DUT_MSG_INFO, "settimeofday failed: %s",
15996 strerror(errno));
15997 send_resp(dut, conn, SIGMA_ERROR,
15998 "errorCode,Failed to set time");
15999 return 0;
16000 }
16001
16002 return 1;
16003#endif /* __linux__ */
16004
16005 return -1;
16006}
16007
16008
Jouni Malinenf7222712019-06-13 01:50:21 +030016009static enum sigma_cmd_result cmd_sta_osu(struct sigma_dut *dut,
16010 struct sigma_conn *conn,
16011 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016012{
16013 const char *intf = get_param(cmd, "Interface");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030016014 const char *name, *osu_ssid, *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016015 int prod_ess_assoc = 1;
Jouni Malinen4c8681c2018-09-12 23:28:11 +030016016 char buf[300], bssid[100], ssid[100];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016017 int res;
16018 struct wpa_ctrl *ctrl;
16019
16020 name = get_param(cmd, "osuFriendlyName");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030016021 osu_ssid = get_param(cmd, "osu_ssid");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016022
16023 val = get_param(cmd, "ProdESSAssoc");
16024 if (val)
16025 prod_ess_assoc = atoi(val);
16026
16027 kill_dhcp_client(dut, intf);
16028 if (start_dhcp_client(dut, intf) < 0)
16029 return -2;
16030
16031 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger OSU");
16032 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
16033 res = snprintf(buf, sizeof(buf),
Jouni Malinen4c8681c2018-09-12 23:28:11 +030016034 "%s %s%s%s %s%s%s signup osu-ca.pem",
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016035 prod_ess_assoc ? "" : "-N",
16036 name ? "-O'" : "", name ? name : "",
Jouni Malinen4c8681c2018-09-12 23:28:11 +030016037 name ? "'" : "",
16038 osu_ssid ? "-o'" : "", osu_ssid ? osu_ssid : "",
16039 osu_ssid ? "'" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016040
Kanchanapally, Vidyullatha12b66762015-12-31 16:46:42 +053016041 hs2_set_policy(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016042 if (run_hs20_osu(dut, buf) < 0) {
16043 FILE *f;
16044
16045 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to complete OSU");
16046
16047 f = fopen("hs20-osu-client.res", "r");
16048 if (f) {
16049 char resp[400], res[300], *pos;
16050 if (!fgets(res, sizeof(res), f))
16051 res[0] = '\0';
16052 pos = strchr(res, '\n');
16053 if (pos)
16054 *pos = '\0';
16055 fclose(f);
16056 sigma_dut_summary(dut, "hs20-osu-client provisioning failed: %s",
16057 res);
16058 snprintf(resp, sizeof(resp), "notify-send '%s'", res);
16059 if (system(resp) != 0) {
16060 }
16061 snprintf(resp, sizeof(resp),
16062 "SSID,,BSSID,,failureReason,%s", res);
16063 send_resp(dut, conn, SIGMA_COMPLETE, resp);
16064 return 0;
16065 }
16066
16067 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
16068 return 0;
16069 }
16070
16071 if (!prod_ess_assoc)
16072 goto report;
16073
16074 ctrl = open_wpa_mon(intf);
16075 if (ctrl == NULL) {
16076 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
16077 "wpa_supplicant monitor connection");
16078 return -1;
16079 }
16080
16081 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
16082 buf, sizeof(buf));
16083
16084 wpa_ctrl_detach(ctrl);
16085 wpa_ctrl_close(ctrl);
16086
16087 if (res < 0) {
16088 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to connect to "
16089 "network after OSU");
16090 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
16091 return 0;
16092 }
16093
16094report:
16095 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
16096 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
16097 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get BSSID/SSID");
16098 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
16099 return 0;
16100 }
16101
16102 snprintf(buf, sizeof(buf), "SSID,%s,BSSID,%s", ssid, bssid);
16103 send_resp(dut, conn, SIGMA_COMPLETE, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016104 return 0;
16105}
16106
16107
Jouni Malinenf7222712019-06-13 01:50:21 +030016108static enum sigma_cmd_result cmd_sta_policy_update(struct sigma_dut *dut,
16109 struct sigma_conn *conn,
16110 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016111{
16112 const char *val;
16113 int timeout = 120;
16114
16115 val = get_param(cmd, "PolicyUpdate");
16116 if (val == NULL || atoi(val) == 0)
16117 return 1; /* No operation requested */
16118
16119 val = get_param(cmd, "Timeout");
16120 if (val)
16121 timeout = atoi(val);
16122
16123 if (timeout) {
16124 /* TODO: time out the command and return
16125 * PolicyUpdateStatus,TIMEOUT if needed. */
16126 }
16127
16128 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger policy update");
16129 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
16130 if (run_hs20_osu(dut, "pol_upd fqdn=wi-fi.org") < 0) {
16131 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,FAIL");
16132 return 0;
16133 }
16134
16135 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,SUCCESS");
16136 return 0;
16137}
16138
16139
Jouni Malinenf7222712019-06-13 01:50:21 +030016140static enum sigma_cmd_result cmd_sta_er_config(struct sigma_dut *dut,
16141 struct sigma_conn *conn,
16142 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016143{
16144 struct wpa_ctrl *ctrl;
16145 const char *intf = get_param(cmd, "Interface");
16146 const char *bssid = get_param(cmd, "Bssid");
16147 const char *ssid = get_param(cmd, "SSID");
16148 const char *security = get_param(cmd, "Security");
16149 const char *passphrase = get_param(cmd, "Passphrase");
16150 const char *pin = get_param(cmd, "PIN");
16151 char buf[1000];
16152 char ssid_hex[200], passphrase_hex[200];
16153 const char *keymgmt, *cipher;
16154
16155 if (intf == NULL)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020016156 intf = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016157
16158 if (!bssid) {
16159 send_resp(dut, conn, SIGMA_ERROR,
16160 "ErrorCode,Missing Bssid argument");
16161 return 0;
16162 }
16163
16164 if (!ssid) {
16165 send_resp(dut, conn, SIGMA_ERROR,
16166 "ErrorCode,Missing SSID argument");
16167 return 0;
16168 }
16169
16170 if (!security) {
16171 send_resp(dut, conn, SIGMA_ERROR,
16172 "ErrorCode,Missing Security argument");
16173 return 0;
16174 }
16175
16176 if (!passphrase) {
16177 send_resp(dut, conn, SIGMA_ERROR,
16178 "ErrorCode,Missing Passphrase argument");
16179 return 0;
16180 }
16181
16182 if (!pin) {
16183 send_resp(dut, conn, SIGMA_ERROR,
16184 "ErrorCode,Missing PIN argument");
16185 return 0;
16186 }
16187
vamsi krishna8c9c1562017-05-12 15:51:46 +053016188 if (2 * strlen(ssid) >= sizeof(ssid_hex) ||
16189 2 * strlen(passphrase) >= sizeof(passphrase_hex)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016190 send_resp(dut, conn, SIGMA_ERROR,
16191 "ErrorCode,Too long SSID/passphrase");
16192 return 0;
16193 }
16194
16195 ctrl = open_wpa_mon(intf);
16196 if (ctrl == NULL) {
16197 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
16198 "wpa_supplicant monitor connection");
16199 return -2;
16200 }
16201
16202 if (strcasecmp(security, "wpa2-psk") == 0) {
16203 keymgmt = "WPA2PSK";
16204 cipher = "CCMP";
16205 } else {
16206 wpa_ctrl_detach(ctrl);
16207 wpa_ctrl_close(ctrl);
16208 send_resp(dut, conn, SIGMA_ERROR,
16209 "ErrorCode,Unsupported Security value");
16210 return 0;
16211 }
16212
16213 ascii2hexstr(ssid, ssid_hex);
16214 ascii2hexstr(passphrase, passphrase_hex);
16215 snprintf(buf, sizeof(buf), "WPS_REG %s %s %s %s %s %s",
16216 bssid, pin, ssid_hex, keymgmt, cipher, passphrase_hex);
16217
16218 if (wpa_command(intf, buf) < 0) {
16219 wpa_ctrl_detach(ctrl);
16220 wpa_ctrl_close(ctrl);
16221 send_resp(dut, conn, SIGMA_ERROR,
16222 "ErrorCode,Failed to start registrar");
16223 return 0;
16224 }
16225
16226 snprintf(dut->er_oper_bssid, sizeof(dut->er_oper_bssid), "%s", bssid);
16227 dut->er_oper_performed = 1;
16228
16229 return wps_connection_event(dut, conn, ctrl, intf, 0);
16230}
16231
16232
Jouni Malinenf7222712019-06-13 01:50:21 +030016233static enum sigma_cmd_result
16234cmd_sta_wps_connect_pw_token(struct sigma_dut *dut, struct sigma_conn *conn,
16235 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016236{
16237 struct wpa_ctrl *ctrl;
16238 const char *intf = get_param(cmd, "Interface");
16239 const char *bssid = get_param(cmd, "Bssid");
16240 char buf[100];
16241
16242 if (!bssid) {
16243 send_resp(dut, conn, SIGMA_ERROR,
16244 "ErrorCode,Missing Bssid argument");
16245 return 0;
16246 }
16247
16248 ctrl = open_wpa_mon(intf);
16249 if (ctrl == NULL) {
16250 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
16251 "wpa_supplicant monitor connection");
16252 return -2;
16253 }
16254
16255 snprintf(buf, sizeof(buf), "WPS_NFC %s", bssid);
16256
16257 if (wpa_command(intf, buf) < 0) {
16258 wpa_ctrl_detach(ctrl);
16259 wpa_ctrl_close(ctrl);
16260 send_resp(dut, conn, SIGMA_ERROR,
16261 "ErrorCode,Failed to start registrar");
16262 return 0;
16263 }
16264
16265 return wps_connection_event(dut, conn, ctrl, intf, 0);
16266}
16267
16268
Jouni Malinenf7222712019-06-13 01:50:21 +030016269static enum sigma_cmd_result cmd_start_wps_registration(struct sigma_dut *dut,
16270 struct sigma_conn *conn,
16271 struct sigma_cmd *cmd)
vamsi krishna9b144002017-09-20 13:28:13 +053016272{
16273 struct wpa_ctrl *ctrl;
16274 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020016275 const char *network_mode = get_param(cmd, "network_mode");
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020016276 const char *config_method = get_param(cmd, "WPSConfigMethod");
16277 const char *role;
vamsi krishna9b144002017-09-20 13:28:13 +053016278 int res;
16279 char buf[256];
16280 const char *events[] = {
16281 "CTRL-EVENT-CONNECTED",
16282 "WPS-OVERLAP-DETECTED",
16283 "WPS-TIMEOUT",
16284 "WPS-FAIL",
16285 NULL
16286 };
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020016287 int id = 0;
vamsi krishna9b144002017-09-20 13:28:13 +053016288
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020016289 /* 60G WPS tests do not pass Interface parameter */
16290 if (!intf)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020016291 intf = get_main_ifname(dut);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020016292
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020016293 if (dut->mode == SIGMA_MODE_AP)
16294 return ap_wps_registration(dut, conn, cmd);
16295
16296 if (config_method) {
16297 /* WFA_CS_WPS_PIN_KEYPAD mode is set when using the
16298 * sta_wps_enter_pin before calling start_wps_registration. */
16299 if (strcasecmp(config_method, "PBC") == 0)
16300 dut->wps_method = WFA_CS_WPS_PBC;
16301 }
16302 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
16303 send_resp(dut, conn, SIGMA_ERROR,
16304 "ErrorCode,WPS parameters not yet set");
16305 return STATUS_SENT;
16306 }
16307
16308 /* Make sure WPS is enabled (also for STA mode) */
16309 dut->wps_disable = 0;
16310
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020016311 if (dut->band == WPS_BAND_60G && network_mode &&
16312 strcasecmp(network_mode, "PBSS") == 0) {
16313 sigma_dut_print(dut, DUT_MSG_DEBUG,
16314 "Set PBSS network mode, network id %d", id);
Jouni Malinen016ae6c2019-11-04 17:00:01 +020016315 if (set_network(get_station_ifname(dut), id, "pbss", "1") < 0)
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020016316 return -2;
16317 }
16318
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020016319 if (dut->force_rsn_ie) {
16320 sigma_dut_print(dut, DUT_MSG_DEBUG, "Force RSN_IE: %d",
16321 dut->force_rsn_ie);
16322 if (sta_60g_force_rsn_ie(dut, dut->force_rsn_ie) < 0) {
16323 sigma_dut_print(dut, DUT_MSG_INFO,
16324 "Failed to force RSN_IE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020016325 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020016326 }
16327 }
16328
vamsi krishna9b144002017-09-20 13:28:13 +053016329 ctrl = open_wpa_mon(intf);
16330 if (!ctrl) {
16331 sigma_dut_print(dut, DUT_MSG_ERROR,
16332 "Failed to open wpa_supplicant monitor connection");
16333 return -2;
16334 }
16335
16336 role = get_param(cmd, "WpsRole");
16337 if (!role) {
16338 send_resp(dut, conn, SIGMA_INVALID,
16339 "ErrorCode,WpsRole not provided");
16340 goto fail;
16341 }
16342
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020016343 if (strcasecmp(role, "Enrollee") != 0) {
16344 /* Registrar role for STA not supported */
16345 send_resp(dut, conn, SIGMA_ERROR,
16346 "ErrorCode,Unsupported WpsRole value");
16347 goto fail;
16348 }
16349
16350 if (is_60g_sigma_dut(dut)) {
16351 if (dut->wps_method == WFA_CS_WPS_PBC)
16352 snprintf(buf, sizeof(buf), "WPS_PBC");
16353 else /* WFA_CS_WPS_PIN_KEYPAD */
16354 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
16355 dut->wps_pin);
16356 if (wpa_command(intf, buf) < 0) {
16357 send_resp(dut, conn, SIGMA_ERROR,
16358 "ErrorCode,Failed to start WPS");
vamsi krishna9b144002017-09-20 13:28:13 +053016359 goto fail;
16360 }
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020016361 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
16362 if (res < 0) {
16363 send_resp(dut, conn, SIGMA_ERROR,
16364 "ErrorCode,WPS connection did not complete");
16365 goto fail;
16366 }
16367 if (strstr(buf, "WPS-TIMEOUT")) {
16368 send_resp(dut, conn, SIGMA_COMPLETE, "WpsState,NoPeer");
16369 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
16370 send_resp(dut, conn, SIGMA_COMPLETE,
16371 "WpsState,OverlapSession");
16372 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
16373 send_resp(dut, conn, SIGMA_COMPLETE,
16374 "WpsState,Successful");
16375 } else {
16376 send_resp(dut, conn, SIGMA_COMPLETE,
16377 "WpsState,Failure");
16378 }
16379 } else {
16380 if (dut->wps_method == WFA_CS_WPS_PBC) {
vamsi krishna9b144002017-09-20 13:28:13 +053016381 if (wpa_command(intf, "WPS_PBC") < 0) {
16382 send_resp(dut, conn, SIGMA_ERROR,
16383 "ErrorCode,Failed to enable PBC");
16384 goto fail;
16385 }
16386 } else {
16387 /* TODO: PIN method */
16388 send_resp(dut, conn, SIGMA_ERROR,
16389 "ErrorCode,Unsupported WpsConfigMethod value");
16390 goto fail;
16391 }
16392 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
16393 if (res < 0) {
16394 send_resp(dut, conn, SIGMA_ERROR,
16395 "ErrorCode,WPS connection did not complete");
16396 goto fail;
16397 }
16398 if (strstr(buf, "WPS-TIMEOUT")) {
16399 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,NoPeer");
16400 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
16401 send_resp(dut, conn, SIGMA_ERROR,
16402 "ErrorCode,OverlapSession");
16403 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
16404 send_resp(dut, conn, SIGMA_COMPLETE, "Successful");
16405 } else {
16406 send_resp(dut, conn, SIGMA_ERROR,
16407 "ErrorCode,WPS operation failed");
16408 }
vamsi krishna9b144002017-09-20 13:28:13 +053016409 }
16410
16411fail:
16412 wpa_ctrl_detach(ctrl);
16413 wpa_ctrl_close(ctrl);
16414 return 0;
16415}
16416
16417
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016418static int req_intf(struct sigma_cmd *cmd)
16419{
16420 return get_param(cmd, "interface") == NULL ? -1 : 0;
16421}
16422
16423
16424void sta_register_cmds(void)
16425{
16426 sigma_dut_reg_cmd("sta_get_ip_config", req_intf,
16427 cmd_sta_get_ip_config);
16428 sigma_dut_reg_cmd("sta_set_ip_config", req_intf,
16429 cmd_sta_set_ip_config);
16430 sigma_dut_reg_cmd("sta_get_info", req_intf, cmd_sta_get_info);
16431 sigma_dut_reg_cmd("sta_get_mac_address", req_intf,
16432 cmd_sta_get_mac_address);
16433 sigma_dut_reg_cmd("sta_is_connected", req_intf, cmd_sta_is_connected);
16434 sigma_dut_reg_cmd("sta_verify_ip_connection", req_intf,
16435 cmd_sta_verify_ip_connection);
16436 sigma_dut_reg_cmd("sta_get_bssid", req_intf, cmd_sta_get_bssid);
16437 sigma_dut_reg_cmd("sta_set_encryption", req_intf,
16438 cmd_sta_set_encryption);
16439 sigma_dut_reg_cmd("sta_set_psk", req_intf, cmd_sta_set_psk);
16440 sigma_dut_reg_cmd("sta_set_eaptls", req_intf, cmd_sta_set_eaptls);
16441 sigma_dut_reg_cmd("sta_set_eapttls", req_intf, cmd_sta_set_eapttls);
16442 sigma_dut_reg_cmd("sta_set_eapsim", req_intf, cmd_sta_set_eapsim);
16443 sigma_dut_reg_cmd("sta_set_peap", req_intf, cmd_sta_set_peap);
16444 sigma_dut_reg_cmd("sta_set_eapfast", req_intf, cmd_sta_set_eapfast);
16445 sigma_dut_reg_cmd("sta_set_eapaka", req_intf, cmd_sta_set_eapaka);
16446 sigma_dut_reg_cmd("sta_set_eapakaprime", req_intf,
16447 cmd_sta_set_eapakaprime);
16448 sigma_dut_reg_cmd("sta_set_security", req_intf, cmd_sta_set_security);
16449 sigma_dut_reg_cmd("sta_set_uapsd", req_intf, cmd_sta_set_uapsd);
16450 /* TODO: sta_set_ibss */
16451 /* TODO: sta_set_mode */
16452 sigma_dut_reg_cmd("sta_set_wmm", req_intf, cmd_sta_set_wmm);
16453 sigma_dut_reg_cmd("sta_associate", req_intf, cmd_sta_associate);
16454 /* TODO: sta_up_load */
16455 sigma_dut_reg_cmd("sta_preset_testparameters", req_intf,
16456 cmd_sta_preset_testparameters);
16457 /* TODO: sta_set_system */
16458 sigma_dut_reg_cmd("sta_set_11n", req_intf, cmd_sta_set_11n);
16459 /* TODO: sta_set_rifs_test */
16460 sigma_dut_reg_cmd("sta_set_wireless", req_intf, cmd_sta_set_wireless);
16461 sigma_dut_reg_cmd("sta_send_addba", req_intf, cmd_sta_send_addba);
16462 /* TODO: sta_send_coexist_mgmt */
16463 sigma_dut_reg_cmd("sta_disconnect", req_intf, cmd_sta_disconnect);
16464 sigma_dut_reg_cmd("sta_reassoc", req_intf, cmd_sta_reassoc);
16465 sigma_dut_reg_cmd("sta_reassociate", req_intf, cmd_sta_reassoc);
16466 sigma_dut_reg_cmd("sta_reset_default", req_intf,
16467 cmd_sta_reset_default);
16468 sigma_dut_reg_cmd("sta_send_frame", req_intf, cmd_sta_send_frame);
16469 sigma_dut_reg_cmd("sta_set_macaddr", req_intf, cmd_sta_set_macaddr);
16470 sigma_dut_reg_cmd("sta_set_rfeature", req_intf, cmd_sta_set_rfeature);
16471 sigma_dut_reg_cmd("sta_set_radio", req_intf, cmd_sta_set_radio);
16472 sigma_dut_reg_cmd("sta_set_pwrsave", req_intf, cmd_sta_set_pwrsave);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020016473 sigma_dut_reg_cmd("sta_set_power_save", req_intf, cmd_sta_set_pwrsave);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016474 sigma_dut_reg_cmd("sta_bssid_pool", req_intf, cmd_sta_bssid_pool);
16475 sigma_dut_reg_cmd("sta_reset_parm", req_intf, cmd_sta_reset_parm);
16476 sigma_dut_reg_cmd("sta_get_key", req_intf, cmd_sta_get_key);
16477 sigma_dut_reg_cmd("sta_hs2_associate", req_intf,
16478 cmd_sta_hs2_associate);
Jouni Malinenb639f1c2018-09-13 02:39:46 +030016479 sigma_dut_reg_cmd("sta_hs2_venue_info", req_intf,
16480 cmd_sta_hs2_venue_info);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016481 sigma_dut_reg_cmd("sta_add_credential", req_intf,
16482 cmd_sta_add_credential);
16483 sigma_dut_reg_cmd("sta_scan", req_intf, cmd_sta_scan);
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020016484 sigma_dut_reg_cmd("sta_scan_bss", req_intf, cmd_sta_scan_bss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016485 sigma_dut_reg_cmd("sta_set_systime", NULL, cmd_sta_set_systime);
16486 sigma_dut_reg_cmd("sta_osu", req_intf, cmd_sta_osu);
16487 sigma_dut_reg_cmd("sta_policy_update", req_intf, cmd_sta_policy_update);
16488 sigma_dut_reg_cmd("sta_er_config", NULL, cmd_sta_er_config);
16489 sigma_dut_reg_cmd("sta_wps_connect_pw_token", req_intf,
16490 cmd_sta_wps_connect_pw_token);
Jouni Malinen82905202018-04-29 17:20:10 +030016491 sigma_dut_reg_cmd("sta_exec_action", NULL, cmd_sta_exec_action);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016492 sigma_dut_reg_cmd("sta_get_events", req_intf, cmd_sta_get_events);
16493 sigma_dut_reg_cmd("sta_get_parameter", req_intf, cmd_sta_get_parameter);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020016494 sigma_dut_reg_cmd("start_wps_registration", NULL,
vamsi krishna9b144002017-09-20 13:28:13 +053016495 cmd_start_wps_registration);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016496}