blob: 121679a77b01e38ba3930159b9e58aca22cd8131 [file] [log] [blame]
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001/*
2 * Sigma Control API DUT (station/AP)
3 * Copyright (c) 2010-2011, Atheros Communications, Inc.
Jouni Malinen9d7e31d2017-12-22 18:55:04 +02004 * Copyright (c) 2011-2017, Qualcomm Atheros, Inc.
Jouni Malinenc12ea4a2018-01-05 21:07:10 +02005 * Copyright (c) 2018, The Linux Foundation
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006 * All Rights Reserved.
7 * Licensed under the Clear BSD license. See README for more details.
8 */
9
10#include "sigma_dut.h"
11#include <sys/ioctl.h>
12#include <sys/stat.h>
Jouni Malinen82905202018-04-29 17:20:10 +030013#include <sys/wait.h>
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030014#include <ctype.h>
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015#ifdef __linux__
Lior Davidcc88b562017-01-03 18:52:09 +020016#include <regex.h>
17#include <dirent.h>
Jouni Malinencd4e3c32015-10-29 12:39:56 +020018#include <sys/time.h>
19#include <netpacket/packet.h>
20#include <linux/if_ether.h>
21#ifdef ANDROID
22#include <cutils/properties.h>
23#include <android/log.h>
24#include "keystore_get.h"
25#else /* ANDROID */
26#include <ifaddrs.h>
27#endif /* ANDROID */
28#include <netdb.h>
29#endif /* __linux__ */
30#ifdef __QNXNTO__
31#include <net/if_dl.h>
32#endif /* __QNXNTO__ */
33#include "wpa_ctrl.h"
34#include "wpa_helpers.h"
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -070035#include "miracast.h"
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -070036#include "qca-vendor_copy.h"
Jouni Malinencd4e3c32015-10-29 12:39:56 +020037
38/* Temporary files for sta_send_addba */
39#define VI_QOS_TMP_FILE "/tmp/vi-qos.tmp"
40#define VI_QOS_FILE "/tmp/vi-qos.txt"
41#define VI_QOS_REFFILE "/etc/vi-qos.txt"
42
43/*
44 * MTU for Ethernet need to take into account 8-byte SNAP header
45 * to be added when encapsulating Ethernet frame into 802.11
46 */
47#ifndef IEEE80211_MAX_DATA_LEN_DMG
48#define IEEE80211_MAX_DATA_LEN_DMG 7920
49#endif
50#ifndef IEEE80211_SNAP_LEN_DMG
51#define IEEE80211_SNAP_LEN_DMG 8
52#endif
53
Ashwini Patil00402582017-04-13 12:29:39 +053054#define NON_PREF_CH_LIST_SIZE 100
Ashwini Patil5acd7382017-04-13 15:55:04 +053055#define NEIGHBOR_REPORT_SIZE 1000
56#define DEFAULT_NEIGHBOR_BSSID_INFO "17"
57#define DEFAULT_NEIGHBOR_PHY_TYPE "1"
Ashwini Patil00402582017-04-13 12:29:39 +053058
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030059#define WIL_DEFAULT_BI 100
60
61/* default remain on channel time for transmitting frames (milliseconds) */
62#define WIL_TRANSMIT_FRAME_DEFAULT_ROC 500
63#define IEEE80211_P2P_ATTR_DEVICE_ID 3
64#define IEEE80211_P2P_ATTR_GROUP_ID 15
65
66/* describes tagged bytes in template frame file */
67struct template_frame_tag {
68 int num;
69 int offset;
70 size_t len;
71};
72
Jouni Malinencd4e3c32015-10-29 12:39:56 +020073extern char *sigma_wpas_ctrl;
74extern char *sigma_cert_path;
75extern enum driver_type wifi_chip_type;
76extern char *sigma_radio_ifname[];
77
Lior David0fe101e2017-03-09 16:09:50 +020078#ifdef __linux__
79#define WIL_WMI_MAX_PAYLOAD 248
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020080#define WIL_WMI_ESE_CFG_CMDID 0xa01
Lior David0fe101e2017-03-09 16:09:50 +020081#define WIL_WMI_BF_TRIG_CMDID 0x83a
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020082#define WIL_WMI_UNIT_TEST_CMDID 0x900
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030083#define WIL_WMI_P2P_CFG_CMDID 0x910
84#define WIL_WMI_START_LISTEN_CMDID 0x914
85#define WIL_WMI_DISCOVERY_STOP_CMDID 0x917
Lior David0fe101e2017-03-09 16:09:50 +020086
87struct wil_wmi_header {
88 uint8_t mid;
89 uint8_t reserved;
90 uint16_t cmd;
91 uint32_t ts;
92} __attribute__((packed));
93
94enum wil_wmi_bf_trig_type {
95 WIL_WMI_SLS,
96 WIL_WMI_BRP_RX,
97 WIL_WMI_BRP_TX,
98};
99
100struct wil_wmi_bf_trig_cmd {
101 /* enum wil_wmi_bf_trig_type */
102 uint32_t bf_type;
103 /* cid when type == WMI_BRP_RX */
104 uint32_t sta_id;
105 uint32_t reserved;
106 /* mac address when type = WIL_WMI_SLS */
107 uint8_t dest_mac[6];
108} __attribute__((packed));
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +0200109
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +0200110enum wil_wmi_sched_scheme_advertisment {
111 WIL_WMI_ADVERTISE_ESE_DISABLED,
112 WIL_WMI_ADVERTISE_ESE_IN_BEACON,
113 WIL_WMI_ADVERTISE_ESE_IN_ANNOUNCE_FRAME,
114};
115
116enum wil_wmi_ese_slot_type {
117 WIL_WMI_ESE_SP,
118 WIL_WMI_ESE_CBAP,
119 WIL_WMI_ESE_ANNOUNCE_NO_ACK,
120};
121
122struct wil_wmi_ese_slot {
123 /* offset from start of BI in microseconds */
124 uint32_t tbtt_offset;
125 uint8_t flags;
126 /* enum wil_wmi_ese_slot_type */
127 uint8_t slot_type;
128 /* duration in microseconds */
129 uint16_t duration;
130 /* frame exchange sequence duration, microseconds */
131 uint16_t tx_op;
132 /* time between 2 blocks for periodic allocation(microseconds) */
133 uint16_t period;
134 /* number of blocks in periodic allocation */
135 uint8_t num_blocks;
136 /* for semi-active allocations */
137 uint8_t idle_period;
138 uint8_t src_aid;
139 uint8_t dst_aid;
140 uint32_t reserved;
141} __attribute__((packed));
142
143#define WIL_WMI_MAX_ESE_SLOTS 4
144struct wil_wmi_ese_cfg {
145 uint8_t serial_num;
146 /* wil_wmi_sched_scheme_advertisment */
147 uint8_t ese_advertisment;
148 uint16_t flags;
149 uint8_t num_allocs;
150 uint8_t reserved[3];
151 uint64_t start_tbtt;
152 /* allocations list */
153 struct wil_wmi_ese_slot slots[WIL_WMI_MAX_ESE_SLOTS];
154} __attribute__((packed));
155
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +0200156#define WIL_WMI_UT_FORCE_MCS 6
157struct wil_wmi_force_mcs {
158 /* WIL_WMI_UT_HW_SYSAPI */
159 uint16_t module_id;
160 /* WIL_WMI_UT_FORCE_MCS */
161 uint16_t subtype_id;
162 /* cid (ignored in oob_mode, affects all stations) */
163 uint32_t cid;
164 /* 1 to force MCS, 0 to restore default behavior */
165 uint32_t force_enable;
166 /* MCS index, 0-12 */
167 uint32_t mcs;
168} __attribute__((packed));
169
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +0200170#define WIL_WMI_UT_HW_SYSAPI 10
171#define WIL_WMI_UT_FORCE_RSN_IE 0x29
172struct wil_wmi_force_rsn_ie {
173 /* WIL_WMI_UT_HW_SYSAPI */
174 uint16_t module_id;
175 /* WIL_WMI_UT_FORCE_RSN_IE */
176 uint16_t subtype_id;
177 /* 0 = no change, 1 = remove if exists, 2 = add if does not exist */
178 uint32_t state;
179} __attribute__((packed));
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +0300180
181enum wil_wmi_discovery_mode {
182 WMI_DISCOVERY_MODE_NON_OFFLOAD,
183 WMI_DISCOVERY_MODE_OFFLOAD,
184 WMI_DISCOVERY_MODE_PEER2PEER,
185};
186
187struct wil_wmi_p2p_cfg_cmd {
188 /* enum wil_wmi_discovery_mode */
189 uint8_t discovery_mode;
190 /* 0-based (wireless channel - 1) */
191 uint8_t channel;
192 /* set to WIL_DEFAULT_BI */
193 uint16_t bcon_interval;
194} __attribute__((packed));
Lior David0fe101e2017-03-09 16:09:50 +0200195#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200196
197#ifdef ANDROID
198
199static int add_ipv6_rule(struct sigma_dut *dut, const char *ifname);
200
201#define ANDROID_KEYSTORE_GET 'g'
202#define ANDROID_KEYSTORE_GET_PUBKEY 'b'
203
204static int android_keystore_get(char cmd, const char *key, unsigned char *val)
205{
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200206 /* Android 4.3 changed keystore design, so need to use keystore_get() */
207#ifndef KEYSTORE_MESSAGE_SIZE
208#define KEYSTORE_MESSAGE_SIZE 65535
209#endif /* KEYSTORE_MESSAGE_SIZE */
210
211 ssize_t len;
212 uint8_t *value = NULL;
213
214 __android_log_print(ANDROID_LOG_DEBUG, "sigma_dut",
215 "keystore command '%c' key '%s' --> keystore_get",
216 cmd, key);
217
218 len = keystore_get(key, strlen(key), &value);
219 if (len < 0) {
220 __android_log_print(ANDROID_LOG_DEBUG, "sigma_dut",
221 "keystore_get() failed");
222 return -1;
223 }
224
225 if (len > KEYSTORE_MESSAGE_SIZE)
226 len = KEYSTORE_MESSAGE_SIZE;
227 memcpy(val, value, len);
228 free(value);
229 return len;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200230}
231#endif /* ANDROID */
232
233
Vinita S. Maloo0fcb57d2020-04-24 14:03:56 +0530234#ifdef NL80211_SUPPORT
235static int nl80211_sta_set_power_save(struct sigma_dut *dut,
236 const char *intf,
237 enum nl80211_ps_state ps_state)
238{
239 struct nl_msg *msg;
240 int ifindex, ret;
241
242 ifindex = if_nametoindex(intf);
243 if (ifindex == 0) {
244 sigma_dut_print(dut, DUT_MSG_ERROR,
245 "%s: Index for interface %s not found",
246 __func__, intf);
247 return -1;
248 }
249
250 msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
251 NL80211_CMD_SET_POWER_SAVE);
252 if (!msg) {
253 sigma_dut_print(dut, DUT_MSG_ERROR,
254 "%s: err in creating nl80211 msg", __func__);
255 return -1;
256 }
257
258 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) {
259 sigma_dut_print(dut, DUT_MSG_ERROR,
260 "%s: err in populating nl80211 msg", __func__);
261 nlmsg_free(msg);
262 return -1;
263 }
264
265 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
266 if (ret) {
267 sigma_dut_print(dut, DUT_MSG_ERROR,
268 "%s: err in send_and_recv_msgs, ret=%d (%s)",
269 __func__, ret, strerror(-ret));
270 return -1;
271 }
272
273 return 0;
274}
275#endif /* NL80211_SUPPORT */
276
277
Vinita S. Malooa8b62722020-04-23 01:45:41 +0530278static int set_power_save_wcn(struct sigma_dut *dut, const char *intf, int ps)
279{
280 char buf[100];
Vinita S. Maloo0fcb57d2020-04-24 14:03:56 +0530281#ifdef NL80211_SUPPORT
282 enum nl80211_ps_state ps_state;
283
284 ps_state = ps == 1 ? NL80211_PS_ENABLED : NL80211_PS_DISABLED;
285 if (nl80211_sta_set_power_save(dut, intf, ps_state) == 0)
286 return 0;
287#endif /* NL80211_SUPPORT */
Vinita S. Malooa8b62722020-04-23 01:45:41 +0530288
289 snprintf(buf, sizeof(buf), "iwpriv %s setPower %d", intf, ps);
290 if (system(buf) != 0) {
291 sigma_dut_print(dut, DUT_MSG_ERROR,
292 "iwpriv setPower %d failed", ps);
293 return -1;
294 }
295 return 0;
296}
297
298
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200299int set_ps(const char *intf, struct sigma_dut *dut, int enabled)
300{
301#ifdef __linux__
302 char buf[100];
303
304 if (wifi_chip_type == DRIVER_WCN) {
305 if (enabled) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +0530306 if (set_power_save_wcn(dut, intf, 1) < 0) {
Purushottam Kushwaha304561d2019-12-23 16:57:18 +0530307 snprintf(buf, sizeof(buf),
308 "iwpriv wlan0 dump 906");
309 if (system(buf) != 0)
310 goto set_power_save;
311 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200312 } else {
Vinita S. Malooa8b62722020-04-23 01:45:41 +0530313 if (set_power_save_wcn(dut, intf, 2) < 0) {
Purushottam Kushwaha304561d2019-12-23 16:57:18 +0530314 snprintf(buf, sizeof(buf),
315 "iwpriv wlan0 dump 905");
316 if (system(buf) != 0)
317 goto set_power_save;
318 snprintf(buf, sizeof(buf),
319 "iwpriv wlan0 dump 912");
320 if (system(buf) != 0)
321 goto set_power_save;
322 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200323 }
324
325 return 0;
326 }
327
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530328set_power_save:
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200329 snprintf(buf, sizeof(buf), "./iw dev %s set power_save %s",
330 intf, enabled ? "on" : "off");
331 if (system(buf) != 0) {
332 snprintf(buf, sizeof(buf), "iw dev %s set power_save %s",
333 intf, enabled ? "on" : "off");
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530334 if (system(buf) != 0) {
335 sigma_dut_print(dut, DUT_MSG_ERROR,
336 "Failed to set power save %s",
337 enabled ? "on" : "off");
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200338 return -1;
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530339 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200340 }
341
342 return 0;
343#else /* __linux__ */
344 return -1;
345#endif /* __linux__ */
346}
347
348
Lior Davidcc88b562017-01-03 18:52:09 +0200349#ifdef __linux__
Lior David0fe101e2017-03-09 16:09:50 +0200350
Lior Davidcc88b562017-01-03 18:52:09 +0200351static int wil6210_get_debugfs_dir(struct sigma_dut *dut, char *path,
352 size_t len)
353{
354 DIR *dir, *wil_dir;
355 struct dirent *entry;
356 int ret = -1;
357 const char *root_path = "/sys/kernel/debug/ieee80211";
358
359 dir = opendir(root_path);
360 if (!dir)
361 return -2;
362
363 while ((entry = readdir(dir))) {
364 if (strcmp(entry->d_name, ".") == 0 ||
365 strcmp(entry->d_name, "..") == 0)
366 continue;
367
368 if (snprintf(path, len, "%s/%s/wil6210",
369 root_path, entry->d_name) >= (int) len) {
370 ret = -3;
371 break;
372 }
373
374 wil_dir = opendir(path);
375 if (wil_dir) {
376 closedir(wil_dir);
377 ret = 0;
378 break;
379 }
380 }
381
382 closedir(dir);
383 return ret;
384}
Lior David0fe101e2017-03-09 16:09:50 +0200385
386
387static int wil6210_wmi_send(struct sigma_dut *dut, uint16_t command,
388 void *payload, uint16_t length)
389{
390 struct {
391 struct wil_wmi_header hdr;
392 char payload[WIL_WMI_MAX_PAYLOAD];
393 } __attribute__((packed)) cmd;
394 char buf[128], fname[128];
395 size_t towrite, written;
396 FILE *f;
Jouni Malinen3aa72862019-05-29 23:14:51 +0300397 int res;
Lior David0fe101e2017-03-09 16:09:50 +0200398
399 if (length > WIL_WMI_MAX_PAYLOAD) {
400 sigma_dut_print(dut, DUT_MSG_ERROR,
401 "payload too large(%u, max %u)",
402 length, WIL_WMI_MAX_PAYLOAD);
403 return -1;
404 }
405
406 memset(&cmd.hdr, 0, sizeof(cmd.hdr));
407 cmd.hdr.cmd = command;
408 memcpy(cmd.payload, payload, length);
409
410 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
411 sigma_dut_print(dut, DUT_MSG_ERROR,
412 "failed to get wil6210 debugfs dir");
413 return -1;
414 }
415
Jouni Malinen3aa72862019-05-29 23:14:51 +0300416 res = snprintf(fname, sizeof(fname), "%s/wmi_send", buf);
417 if (res < 0 || res >= sizeof(fname))
418 return -1;
Lior David0fe101e2017-03-09 16:09:50 +0200419 f = fopen(fname, "wb");
420 if (!f) {
421 sigma_dut_print(dut, DUT_MSG_ERROR,
422 "failed to open: %s", fname);
423 return -1;
424 }
425
426 towrite = sizeof(cmd.hdr) + length;
427 written = fwrite(&cmd, 1, towrite, f);
428 fclose(f);
429 if (written != towrite) {
430 sigma_dut_print(dut, DUT_MSG_ERROR,
431 "failed to send wmi %u", command);
432 return -1;
433 }
434
435 return 0;
436}
437
438
439static int wil6210_get_sta_info_field(struct sigma_dut *dut, const char *bssid,
440 const char *pattern, unsigned int *field)
441{
442 char buf[128], fname[128];
443 FILE *f;
444 regex_t re;
445 regmatch_t m[2];
Jouni Malinen3aa72862019-05-29 23:14:51 +0300446 int rc, ret = -1, res;
Lior David0fe101e2017-03-09 16:09:50 +0200447
448 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
449 sigma_dut_print(dut, DUT_MSG_ERROR,
450 "failed to get wil6210 debugfs dir");
451 return -1;
452 }
453
Jouni Malinen3aa72862019-05-29 23:14:51 +0300454 res = snprintf(fname, sizeof(fname), "%s/stations", buf);
455 if (res < 0 || res >= sizeof(fname))
456 return -1;
Lior David0fe101e2017-03-09 16:09:50 +0200457 f = fopen(fname, "r");
458 if (!f) {
459 sigma_dut_print(dut, DUT_MSG_ERROR,
460 "failed to open: %s", fname);
461 return -1;
462 }
463
464 if (regcomp(&re, pattern, REG_EXTENDED)) {
465 sigma_dut_print(dut, DUT_MSG_ERROR,
466 "regcomp failed: %s", pattern);
467 goto out;
468 }
469
470 /*
471 * find the entry for the mac address
472 * line is of the form: [n] 11:22:33:44:55:66 state AID aid
473 */
474 while (fgets(buf, sizeof(buf), f)) {
475 if (strcasestr(buf, bssid)) {
476 /* extract the field (CID/AID/state) */
477 rc = regexec(&re, buf, 2, m, 0);
478 if (!rc && (m[1].rm_so >= 0)) {
479 buf[m[1].rm_eo] = 0;
480 *field = atoi(&buf[m[1].rm_so]);
481 ret = 0;
482 break;
483 }
484 }
485 }
486
487 regfree(&re);
488 if (ret)
489 sigma_dut_print(dut, DUT_MSG_ERROR,
490 "could not extract field");
491
492out:
493 fclose(f);
494
495 return ret;
496}
497
498
499static int wil6210_get_cid(struct sigma_dut *dut, const char *bssid,
500 unsigned int *cid)
501{
502 const char *pattern = "\\[([0-9]+)\\]";
503
504 return wil6210_get_sta_info_field(dut, bssid, pattern, cid);
505}
506
507
508static int wil6210_send_brp_rx(struct sigma_dut *dut, const char *mac,
509 int l_rx)
510{
Rakesh Sunki556237d2017-03-30 14:49:31 -0700511 struct wil_wmi_bf_trig_cmd cmd;
Lior David0fe101e2017-03-09 16:09:50 +0200512 unsigned int cid;
513
Rakesh Sunki556237d2017-03-30 14:49:31 -0700514 memset(&cmd, 0, sizeof(cmd));
515
Lior David0fe101e2017-03-09 16:09:50 +0200516 if (wil6210_get_cid(dut, mac, &cid))
517 return -1;
518
519 cmd.bf_type = WIL_WMI_BRP_RX;
520 cmd.sta_id = cid;
521 /* training length (l_rx) is ignored, FW always uses length 16 */
522 return wil6210_wmi_send(dut, WIL_WMI_BF_TRIG_CMDID,
523 &cmd, sizeof(cmd));
524}
525
526
527static int wil6210_send_sls(struct sigma_dut *dut, const char *mac)
528{
Rakesh Sunki556237d2017-03-30 14:49:31 -0700529 struct wil_wmi_bf_trig_cmd cmd;
530
531 memset(&cmd, 0, sizeof(cmd));
Lior David0fe101e2017-03-09 16:09:50 +0200532
533 if (parse_mac_address(dut, mac, (unsigned char *)&cmd.dest_mac))
534 return -1;
535
536 cmd.bf_type = WIL_WMI_SLS;
537 return wil6210_wmi_send(dut, WIL_WMI_BF_TRIG_CMDID,
538 &cmd, sizeof(cmd));
539}
540
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +0200541
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +0200542int wil6210_set_ese(struct sigma_dut *dut, int count,
543 struct sigma_ese_alloc *allocs)
544{
545 struct wil_wmi_ese_cfg cmd = { };
546 int i;
547
548 if (count == 0 || count > WIL_WMI_MAX_ESE_SLOTS)
549 return -1;
550
551 if (dut->ap_bcnint <= 0) {
552 sigma_dut_print(dut, DUT_MSG_ERROR,
553 "invalid beacon interval(%d), check test",
554 dut->ap_bcnint);
555 return -1;
556 }
557
558 cmd.ese_advertisment = WIL_WMI_ADVERTISE_ESE_IN_BEACON;
559 cmd.flags = 0x1d;
560 cmd.num_allocs = count;
561 for (i = 0; i < count; i++) {
562 /*
563 * Convert percent from BI (BI specified in milliseconds)
564 * to absolute duration in microseconds.
565 */
566 cmd.slots[i].duration =
567 (allocs[i].percent_bi * dut->ap_bcnint * 1000) / 100;
568 switch (allocs[i].type) {
569 case ESE_CBAP:
570 cmd.slots[i].slot_type = WIL_WMI_ESE_CBAP;
571 break;
572 case ESE_SP:
573 cmd.slots[i].slot_type = WIL_WMI_ESE_SP;
574 break;
575 default:
576 sigma_dut_print(dut, DUT_MSG_ERROR,
577 "invalid slot type(%d) at index %d",
578 allocs[i].type, i);
579 return -1;
580 }
581 cmd.slots[i].src_aid = allocs[i].src_aid;
582 cmd.slots[i].dst_aid = allocs[i].dst_aid;
583 sigma_dut_print(dut, DUT_MSG_INFO,
584 "slot %d, duration %u, type %d, srcAID %u dstAID %u",
585 i, cmd.slots[i].duration,
586 cmd.slots[i].slot_type, cmd.slots[i].src_aid,
587 cmd.slots[i].dst_aid);
588 }
589
590 return wil6210_wmi_send(dut, WIL_WMI_ESE_CFG_CMDID, &cmd, sizeof(cmd));
591}
592
593
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +0200594int wil6210_set_force_mcs(struct sigma_dut *dut, int force, int mcs)
595{
596 struct wil_wmi_force_mcs cmd = { };
597
598 cmd.module_id = WIL_WMI_UT_HW_SYSAPI;
599 cmd.subtype_id = WIL_WMI_UT_FORCE_MCS;
600 cmd.force_enable = (uint32_t) force;
601 cmd.mcs = (uint32_t) mcs;
602
603 return wil6210_wmi_send(dut, WIL_WMI_UNIT_TEST_CMDID,
604 &cmd, sizeof(cmd));
605}
606
607
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +0200608static int wil6210_force_rsn_ie(struct sigma_dut *dut, int state)
609{
610 struct wil_wmi_force_rsn_ie cmd = { };
611
612 cmd.module_id = WIL_WMI_UT_HW_SYSAPI;
613 cmd.subtype_id = WIL_WMI_UT_FORCE_RSN_IE;
614 cmd.state = (uint32_t) state;
615
616 return wil6210_wmi_send(dut, WIL_WMI_UNIT_TEST_CMDID,
617 &cmd, sizeof(cmd));
618}
619
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +0300620
621/*
622 * this function is also used to configure generic remain-on-channel
623 */
624static int wil6210_p2p_cfg(struct sigma_dut *dut, int freq)
625{
626 struct wil_wmi_p2p_cfg_cmd cmd = { };
627 int channel = freq_to_channel(freq);
628
629 if (channel < 0)
630 return -1;
631 cmd.discovery_mode = WMI_DISCOVERY_MODE_NON_OFFLOAD;
632 cmd.channel = channel - 1;
633 cmd.bcon_interval = WIL_DEFAULT_BI;
634 cmd.discovery_mode = WMI_DISCOVERY_MODE_PEER2PEER;
635
636 return wil6210_wmi_send(dut, WIL_WMI_P2P_CFG_CMDID,
637 &cmd, sizeof(cmd));
638}
639
640
641static int wil6210_remain_on_channel(struct sigma_dut *dut, int freq)
642{
643 int ret = wil6210_p2p_cfg(dut, freq);
644
645 if (ret)
646 return ret;
647
648 ret = wil6210_wmi_send(dut, WIL_WMI_START_LISTEN_CMDID, NULL, 0);
649 if (!ret) {
650 /*
651 * wait a bit to allow FW to setup the radio
652 * especially important if we switch channels
653 */
654 usleep(500000);
655 }
656
657 return ret;
658}
659
660
661static int wil6210_stop_discovery(struct sigma_dut *dut)
662{
663 return wil6210_wmi_send(dut, WIL_WMI_DISCOVERY_STOP_CMDID, NULL, 0);
664}
665
666
667static int wil6210_transmit_frame(struct sigma_dut *dut, int freq,
668 int wait_duration,
669 const char *frame, size_t frame_len)
670{
671 char buf[128], fname[128];
672 FILE *f;
Jouni Malinen3aa72862019-05-29 23:14:51 +0300673 int res = 0, r;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +0300674 size_t written;
675
676 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
677 sigma_dut_print(dut, DUT_MSG_ERROR,
678 "failed to get wil6210 debugfs dir");
679 return -1;
680 }
Jouni Malinen3aa72862019-05-29 23:14:51 +0300681 r = snprintf(fname, sizeof(fname), "%s/tx_mgmt", buf);
682 if (r < 0 || r >= sizeof(fname))
683 return -1;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +0300684
685 if (wil6210_remain_on_channel(dut, freq)) {
686 sigma_dut_print(dut, DUT_MSG_ERROR,
687 "failed to listen on channel");
688 return -1;
689 }
690
691 f = fopen(fname, "wb");
692 if (!f) {
693 sigma_dut_print(dut, DUT_MSG_ERROR,
694 "failed to open: %s", fname);
695 res = -1;
696 goto out_stop;
697 }
698 written = fwrite(frame, 1, frame_len, f);
699 fclose(f);
700
701 if (written != frame_len) {
702 sigma_dut_print(dut, DUT_MSG_ERROR,
703 "failed to transmit frame (got %zd, expected %zd)",
704 written, frame_len);
705 res = -1;
706 goto out_stop;
707 }
708
709 usleep(wait_duration * 1000);
710
711out_stop:
712 wil6210_stop_discovery(dut);
713 return res;
714}
715
716
717static int find_template_frame_tag(struct template_frame_tag *tags,
718 int total_tags, int tag_num)
719{
720 int i;
721
722 for (i = 0; i < total_tags; i++) {
723 if (tag_num == tags[i].num)
724 return i;
725 }
726
727 return -1;
728}
729
730
731static int replace_p2p_attribute(struct sigma_dut *dut, char *buf, size_t len,
732 int id, const char *value, size_t val_len)
733{
734 struct wfa_p2p_attribute *attr = (struct wfa_p2p_attribute *) buf;
735
736 if (len < 3 + val_len) {
737 sigma_dut_print(dut, DUT_MSG_ERROR,
738 "not enough space to replace P2P attribute");
739 return -1;
740 }
741
742 if (attr->len != val_len) {
743 sigma_dut_print(dut, DUT_MSG_ERROR,
744 "attribute length mismatch (need %zu have %hu)",
745 val_len, attr->len);
746 return -1;
747 }
748
749 if (attr->id != id) {
750 sigma_dut_print(dut, DUT_MSG_ERROR,
751 "incorrect attribute id (expected %d actual %d)",
752 id, attr->id);
753 return -1;
754 }
755
756 memcpy(attr->variable, value, val_len);
757
758 return 0;
759}
760
761
762static int parse_template_frame_file(struct sigma_dut *dut, const char *fname,
763 char *buf, size_t *length,
764 struct template_frame_tag *tags,
765 size_t *num_tags)
766{
767 char line[512];
768 FILE *f;
769 size_t offset = 0, tag_index = 0;
770 int num, index;
771 int in_tag = 0, tag_num = 0, tag_offset = 0;
772
773 if (*length < sizeof(struct ieee80211_hdr_3addr)) {
774 sigma_dut_print(dut, DUT_MSG_ERROR,
775 "supplied buffer is too small");
776 return -1;
777 }
778
779 f = fopen(fname, "r");
780 if (!f) {
781 sigma_dut_print(dut, DUT_MSG_ERROR,
782 "failed to open template file %s", fname);
783 return -1;
784 }
785
786 /*
787 * template file format: lines beginning with # are comments and
788 * ignored.
789 * It is possible to tag bytes in the frame to make it easy
790 * to replace fields in the template, espcially if they appear
791 * in variable-sized sections (such as IEs)
792 * This is done by a line beginning with $NUM where NUM is an integer
793 * tag number. It can be followed by space(s) and comment.
794 * The next line is considered the tagged bytes. The parser will fill
795 * the tag number, offset and length of the tagged bytes.
796 * rest of the lines contain frame bytes as sequence of hex digits,
797 * 2 digits for each byte. Spaces are allowed between bytes.
798 * On bytes lines only hex digits and spaces are allowed
799 */
800 while (!feof(f)) {
801 if (!fgets(line, sizeof(line), f))
802 break;
803 index = 0;
804 while (isspace((unsigned char) line[index]))
805 index++;
806 if (!line[index] || line[index] == '#')
807 continue;
808 if (line[index] == '$') {
809 if (tags) {
810 index++;
811 tag_num = strtol(&line[index], NULL, 0);
812 tag_offset = offset;
813 in_tag = 1;
814 }
815 continue;
816 }
817 while (line[index]) {
818 if (isspace((unsigned char) line[index])) {
819 index++;
820 continue;
821 }
822 num = hex_byte(&line[index]);
823 if (num < 0)
824 break;
825 buf[offset++] = num;
826 if (offset == *length)
827 goto out;
828 index += 2;
829 }
830
831 if (in_tag) {
832 if (tag_index < *num_tags) {
833 tags[tag_index].num = tag_num;
834 tags[tag_index].offset = tag_offset;
835 tags[tag_index].len = offset - tag_offset;
836 tag_index++;
837 } else {
838 sigma_dut_print(dut, DUT_MSG_INFO,
839 "too many tags, tag ignored");
840 }
841 in_tag = 0;
842 }
843 }
844
845 if (num_tags)
846 *num_tags = tag_index;
847out:
848 fclose(f);
849 if (offset < sizeof(struct ieee80211_hdr_3addr)) {
850 sigma_dut_print(dut, DUT_MSG_ERROR,
851 "template frame is too small");
852 return -1;
853 }
854
855 *length = offset;
856 return 0;
857}
858
Lior Davidcc88b562017-01-03 18:52:09 +0200859#endif /* __linux__ */
860
861
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200862static void static_ip_file(int proto, const char *addr, const char *mask,
863 const char *gw)
864{
865 if (proto) {
866 FILE *f = fopen("static-ip", "w");
867 if (f) {
868 fprintf(f, "%d %s %s %s\n", proto, addr,
869 mask ? mask : "N/A",
870 gw ? gw : "N/A");
871 fclose(f);
872 }
873 } else {
874 unlink("static-ip");
875 }
876}
877
878
879static int send_neighbor_request(struct sigma_dut *dut, const char *intf,
880 const char *ssid)
881{
882#ifdef __linux__
883 char buf[100];
884
885 snprintf(buf, sizeof(buf), "iwpriv %s neighbor %s",
886 intf, ssid);
887 sigma_dut_print(dut, DUT_MSG_INFO, "Request: %s", buf);
888
889 if (system(buf) != 0) {
890 sigma_dut_print(dut, DUT_MSG_ERROR,
891 "iwpriv neighbor request failed");
892 return -1;
893 }
894
895 sigma_dut_print(dut, DUT_MSG_INFO, "iwpriv neighbor request send");
896
897 return 0;
898#else /* __linux__ */
899 return -1;
900#endif /* __linux__ */
901}
902
903
904static int send_trans_mgmt_query(struct sigma_dut *dut, const char *intf,
Ashwini Patil5acd7382017-04-13 15:55:04 +0530905 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200906{
Ashwini Patil5acd7382017-04-13 15:55:04 +0530907 const char *val;
908 int reason_code = 0;
909 char buf[1024];
910
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200911 /*
912 * In the earlier builds we used WNM_QUERY and in later
913 * builds used WNM_BSS_QUERY.
914 */
915
Ashwini Patil5acd7382017-04-13 15:55:04 +0530916 val = get_param(cmd, "BTMQuery_Reason_Code");
917 if (val)
918 reason_code = atoi(val);
919
920 val = get_param(cmd, "Cand_List");
921 if (val && atoi(val) == 1 && dut->btm_query_cand_list) {
922 snprintf(buf, sizeof(buf), "WNM_BSS_QUERY %d%s", reason_code,
923 dut->btm_query_cand_list);
924 free(dut->btm_query_cand_list);
925 dut->btm_query_cand_list = NULL;
926 } else {
927 snprintf(buf, sizeof(buf), "WNM_BSS_QUERY %d", reason_code);
928 }
929
930 if (wpa_command(intf, buf) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200931 sigma_dut_print(dut, DUT_MSG_ERROR,
932 "transition management query failed");
933 return -1;
934 }
935
936 sigma_dut_print(dut, DUT_MSG_DEBUG,
937 "transition management query sent");
938
939 return 0;
940}
941
942
943int is_ip_addr(const char *str)
944{
945 const char *pos = str;
946 struct in_addr addr;
947
948 while (*pos) {
949 if (*pos != '.' && (*pos < '0' || *pos > '9'))
950 return 0;
951 pos++;
952 }
953
954 return inet_aton(str, &addr);
955}
956
957
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200958int get_ip_config(struct sigma_dut *dut, const char *ifname, char *buf,
959 size_t buf_len)
960{
vamsi krishnaa11d0732018-05-16 12:19:48 +0530961 char tmp[256];
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200962 char ip[16], mask[15], dns[16], sec_dns[16];
963 int is_dhcp = 0;
964 int s;
965#ifdef ANDROID
966 char prop[PROPERTY_VALUE_MAX];
vamsi krishnaa11d0732018-05-16 12:19:48 +0530967#else /* ANDROID */
968 FILE *f;
969#ifdef __linux__
970 const char *str_ps;
971#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200972#endif /* ANDROID */
973
974 ip[0] = '\0';
975 mask[0] = '\0';
976 dns[0] = '\0';
977 sec_dns[0] = '\0';
978
979 s = socket(PF_INET, SOCK_DGRAM, 0);
980 if (s >= 0) {
981 struct ifreq ifr;
982 struct sockaddr_in saddr;
983
984 memset(&ifr, 0, sizeof(ifr));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700985 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200986 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
987 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get "
988 "%s IP address: %s",
989 ifname, strerror(errno));
990 } else {
991 memcpy(&saddr, &ifr.ifr_addr,
992 sizeof(struct sockaddr_in));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700993 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200994 }
995
996 if (ioctl(s, SIOCGIFNETMASK, &ifr) == 0) {
997 memcpy(&saddr, &ifr.ifr_addr,
998 sizeof(struct sockaddr_in));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700999 strlcpy(mask, inet_ntoa(saddr.sin_addr), sizeof(mask));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001000 }
1001 close(s);
1002 }
1003
1004#ifdef ANDROID
1005 snprintf(tmp, sizeof(tmp), "dhcp.%s.pid", ifname);
1006 if (property_get(tmp, prop, NULL) != 0 && atoi(prop) > 0) {
1007 snprintf(tmp, sizeof(tmp), "dhcp.%s.result", ifname);
1008 if (property_get(tmp, prop, NULL) != 0 &&
1009 strcmp(prop, "ok") == 0) {
1010 snprintf(tmp, sizeof(tmp), "dhcp.%s.ipaddress",
1011 ifname);
1012 if (property_get(tmp, prop, NULL) != 0 &&
1013 strcmp(ip, prop) == 0)
1014 is_dhcp = 1;
1015 }
1016 }
1017
1018 snprintf(tmp, sizeof(tmp), "dhcp.%s.dns1", ifname);
Peng Xub8fc5cc2017-05-10 17:27:28 -07001019 if (property_get(tmp, prop, NULL) != 0)
1020 strlcpy(dns, prop, sizeof(dns));
1021 else if (property_get("net.dns1", prop, NULL) != 0)
1022 strlcpy(dns, prop, sizeof(dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001023
1024 snprintf(tmp, sizeof(tmp), "dhcp.%s.dns2", ifname);
Peng Xub8fc5cc2017-05-10 17:27:28 -07001025 if (property_get(tmp, prop, NULL) != 0)
1026 strlcpy(sec_dns, prop, sizeof(sec_dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001027#else /* ANDROID */
1028#ifdef __linux__
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001029 if (get_driver_type(dut) == DRIVER_OPENWRT)
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +05301030 str_ps = "ps -w";
1031 else
1032 str_ps = "ps ax";
1033 snprintf(tmp, sizeof(tmp),
1034 "%s | grep dhclient | grep -v grep | grep -q %s",
1035 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001036 if (system(tmp) == 0)
1037 is_dhcp = 1;
1038 else {
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +05301039 snprintf(tmp, sizeof(tmp),
1040 "%s | grep udhcpc | grep -v grep | grep -q %s",
1041 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001042 if (system(tmp) == 0)
1043 is_dhcp = 1;
1044 else {
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +05301045 snprintf(tmp, sizeof(tmp),
1046 "%s | grep dhcpcd | grep -v grep | grep -q %s",
1047 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001048 if (system(tmp) == 0)
1049 is_dhcp = 1;
1050 }
1051 }
1052#endif /* __linux__ */
1053
1054 f = fopen("/etc/resolv.conf", "r");
1055 if (f) {
vamsi krishnaa11d0732018-05-16 12:19:48 +05301056 char *pos, *pos2;
1057
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001058 while (fgets(tmp, sizeof(tmp), f)) {
1059 if (strncmp(tmp, "nameserver", 10) != 0)
1060 continue;
1061 pos = tmp + 10;
1062 while (*pos == ' ' || *pos == '\t')
1063 pos++;
1064 pos2 = pos;
1065 while (*pos2) {
1066 if (*pos2 == '\n' || *pos2 == '\r') {
1067 *pos2 = '\0';
1068 break;
1069 }
1070 pos2++;
1071 }
Peng Xub8fc5cc2017-05-10 17:27:28 -07001072 if (!dns[0])
1073 strlcpy(dns, pos, sizeof(dns));
1074 else if (!sec_dns[0])
1075 strlcpy(sec_dns, pos, sizeof(sec_dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001076 }
1077 fclose(f);
1078 }
1079#endif /* ANDROID */
1080
1081 snprintf(buf, buf_len, "dhcp,%d,ip,%s,mask,%s,primary-dns,%s",
1082 is_dhcp, ip, mask, dns);
1083 buf[buf_len - 1] = '\0';
1084
1085 return 0;
1086}
1087
1088
1089
1090
1091int get_ipv6_config(struct sigma_dut *dut, const char *ifname, char *buf,
1092 size_t buf_len)
1093{
1094#ifdef __linux__
1095#ifdef ANDROID
1096 char cmd[200], result[1000], *pos, *end;
1097 FILE *f;
1098 size_t len;
1099
1100 snprintf(cmd, sizeof(cmd), "ip addr show dev %s scope global", ifname);
1101 f = popen(cmd, "r");
1102 if (f == NULL)
1103 return -1;
1104 len = fread(result, 1, sizeof(result) - 1, f);
1105 pclose(f);
1106 if (len == 0)
1107 return -1;
1108 result[len] = '\0';
1109 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s result: %s\n", cmd, result);
1110
1111 pos = strstr(result, "inet6 ");
1112 if (pos == NULL)
1113 return -1;
1114 pos += 6;
1115 end = strchr(pos, ' ');
1116 if (end)
1117 *end = '\0';
1118 end = strchr(pos, '/');
1119 if (end)
1120 *end = '\0';
1121 snprintf(buf, buf_len, "ip,%s", pos);
1122 buf[buf_len - 1] = '\0';
1123 return 0;
1124#else /* ANDROID */
1125 struct ifaddrs *ifaddr, *ifa;
1126 int res, found = 0;
1127 char host[NI_MAXHOST];
1128
1129 if (getifaddrs(&ifaddr) < 0) {
1130 perror("getifaddrs");
1131 return -1;
1132 }
1133
1134 for (ifa = ifaddr; ifa; ifa = ifa->ifa_next) {
1135 if (strcasecmp(ifname, ifa->ifa_name) != 0)
1136 continue;
1137 if (ifa->ifa_addr == NULL ||
1138 ifa->ifa_addr->sa_family != AF_INET6)
1139 continue;
1140
1141 res = getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in6),
1142 host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
1143 if (res != 0) {
1144 sigma_dut_print(dut, DUT_MSG_DEBUG, "getnameinfo: %s",
1145 gai_strerror(res));
1146 continue;
1147 }
1148 if (strncmp(host, "fe80::", 6) == 0)
1149 continue; /* skip link-local */
1150
1151 sigma_dut_print(dut, DUT_MSG_DEBUG, "ifaddr: %s", host);
1152 found = 1;
1153 break;
1154 }
1155
1156 freeifaddrs(ifaddr);
1157
1158 if (found) {
1159 char *pos;
1160 pos = strchr(host, '%');
1161 if (pos)
1162 *pos = '\0';
1163 snprintf(buf, buf_len, "ip,%s", host);
1164 buf[buf_len - 1] = '\0';
1165 return 0;
1166 }
1167
1168#endif /* ANDROID */
1169#endif /* __linux__ */
1170 return -1;
1171}
1172
1173
Jouni Malinenf7222712019-06-13 01:50:21 +03001174static enum sigma_cmd_result cmd_sta_get_ip_config(struct sigma_dut *dut,
1175 struct sigma_conn *conn,
1176 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001177{
1178 const char *intf = get_param(cmd, "Interface");
1179 const char *ifname;
1180 char buf[200];
1181 const char *val;
1182 int type = 1;
1183
1184 if (intf == NULL)
1185 return -1;
1186
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001187 if (strcmp(intf, get_main_ifname(dut)) == 0)
1188 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001189 else
1190 ifname = intf;
1191
1192 /*
1193 * UCC may assume the IP address to be available immediately after
1194 * association without trying to run sta_get_ip_config multiple times.
1195 * Sigma CAPI does not specify this command as a block command that
1196 * would wait for the address to become available, but to pass tests
1197 * more reliably, it looks like such a wait may be needed here.
1198 */
1199 if (wait_ip_addr(dut, ifname, 15) < 0) {
1200 sigma_dut_print(dut, DUT_MSG_INFO, "Could not get IP address "
1201 "for sta_get_ip_config");
1202 /*
1203 * Try to continue anyway since many UCC tests do not really
1204 * care about the return value from here..
1205 */
1206 }
1207
1208 val = get_param(cmd, "Type");
1209 if (val)
1210 type = atoi(val);
1211 if (type == 2 || dut->last_set_ip_config_ipv6) {
1212 int i;
1213
1214 /*
1215 * Since we do not have proper wait for IPv6 addresses, use a
1216 * fixed two second delay here as a workaround for UCC script
1217 * assuming IPv6 address is available when this command returns.
1218 * Some scripts did not use Type,2 properly for IPv6, so include
1219 * also the cases where the previous sta_set_ip_config indicated
1220 * use of IPv6.
1221 */
1222 sigma_dut_print(dut, DUT_MSG_INFO, "Wait up to extra ten seconds in sta_get_ip_config for IPv6 address");
1223 for (i = 0; i < 10; i++) {
1224 sleep(1);
1225 if (get_ipv6_config(dut, ifname, buf, sizeof(buf)) == 0)
1226 {
1227 sigma_dut_print(dut, DUT_MSG_INFO, "Found IPv6 address");
1228 send_resp(dut, conn, SIGMA_COMPLETE, buf);
1229#ifdef ANDROID
1230 sigma_dut_print(dut, DUT_MSG_INFO,
1231 "Adding IPv6 rule on Android");
1232 add_ipv6_rule(dut, intf);
1233#endif /* ANDROID */
1234
1235 return 0;
1236 }
1237 }
1238 }
1239 if (type == 1) {
1240 if (get_ip_config(dut, ifname, buf, sizeof(buf)) < 0)
1241 return -2;
1242 } else if (type == 2) {
1243 if (get_ipv6_config(dut, ifname, buf, sizeof(buf)) < 0)
1244 return -2;
1245 } else {
1246 send_resp(dut, conn, SIGMA_ERROR,
1247 "errorCode,Unsupported address type");
1248 return 0;
1249 }
1250
1251 send_resp(dut, conn, SIGMA_COMPLETE, buf);
1252 return 0;
1253}
1254
1255
1256static void kill_dhcp_client(struct sigma_dut *dut, const char *ifname)
1257{
1258#ifdef __linux__
1259 char buf[200];
1260 char path[128];
1261 struct stat s;
1262
1263#ifdef ANDROID
1264 snprintf(path, sizeof(path), "/data/misc/dhcp/dhcpcd-%s.pid", ifname);
1265#else /* ANDROID */
1266 snprintf(path, sizeof(path), "/var/run/dhclient-%s.pid", ifname);
1267#endif /* ANDROID */
1268 if (stat(path, &s) == 0) {
1269 snprintf(buf, sizeof(buf), "kill `cat %s`", path);
1270 sigma_dut_print(dut, DUT_MSG_INFO,
1271 "Kill previous DHCP client: %s", buf);
1272 if (system(buf) != 0)
1273 sigma_dut_print(dut, DUT_MSG_INFO,
1274 "Failed to kill DHCP client");
1275 unlink(path);
1276 sleep(1);
1277 } else {
1278 snprintf(path, sizeof(path), "/var/run/dhcpcd-%s.pid", ifname);
1279
1280 if (stat(path, &s) == 0) {
1281 snprintf(buf, sizeof(buf), "kill `cat %s`", path);
1282 sigma_dut_print(dut, DUT_MSG_INFO,
1283 "Kill previous DHCP client: %s", buf);
1284 if (system(buf) != 0)
1285 sigma_dut_print(dut, DUT_MSG_INFO,
1286 "Failed to kill DHCP client");
1287 unlink(path);
1288 sleep(1);
1289 }
1290 }
1291#endif /* __linux__ */
1292}
1293
1294
1295static int start_dhcp_client(struct sigma_dut *dut, const char *ifname)
1296{
1297#ifdef __linux__
1298 char buf[200];
1299
1300#ifdef ANDROID
Purushottam Kushwaha46d64262016-08-23 17:57:53 +05301301 if (access("/system/bin/dhcpcd", F_OK) != -1) {
1302 snprintf(buf, sizeof(buf),
1303 "/system/bin/dhcpcd -b %s", ifname);
1304 } else if (access("/system/bin/dhcptool", F_OK) != -1) {
1305 snprintf(buf, sizeof(buf), "/system/bin/dhcptool %s &", ifname);
Ankita Bajaj8454e5d2019-04-05 16:04:55 +05301306 } else if (access("/vendor/bin/dhcpcd", F_OK) != -1) {
1307 snprintf(buf, sizeof(buf), "/vendor/bin/dhcpcd -b %s", ifname);
1308 } else if (access("/vendor/bin/dhcptool", F_OK) != -1) {
1309 snprintf(buf, sizeof(buf), "/vendor/bin/dhcptool %s", ifname);
Purushottam Kushwaha46d64262016-08-23 17:57:53 +05301310 } else {
1311 sigma_dut_print(dut, DUT_MSG_ERROR,
1312 "DHCP client program missing");
1313 return 0;
1314 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001315#else /* ANDROID */
1316 snprintf(buf, sizeof(buf),
1317 "dhclient -nw -pf /var/run/dhclient-%s.pid %s",
1318 ifname, ifname);
1319#endif /* ANDROID */
1320 sigma_dut_print(dut, DUT_MSG_INFO, "Start DHCP client: %s", buf);
1321 if (system(buf) != 0) {
1322 snprintf(buf, sizeof(buf), "dhcpcd -t 0 %s &", ifname);
1323 if (system(buf) != 0) {
1324 sigma_dut_print(dut, DUT_MSG_INFO,
1325 "Failed to start DHCP client");
1326#ifndef ANDROID
1327 return -1;
1328#endif /* ANDROID */
1329 }
1330 }
1331#endif /* __linux__ */
1332
1333 return 0;
1334}
1335
1336
1337static int clear_ip_addr(struct sigma_dut *dut, const char *ifname)
1338{
1339#ifdef __linux__
1340 char buf[200];
1341
1342 snprintf(buf, sizeof(buf), "ip addr flush dev %s", ifname);
1343 if (system(buf) != 0) {
1344 sigma_dut_print(dut, DUT_MSG_INFO,
1345 "Failed to clear IP addresses");
1346 return -1;
1347 }
1348#endif /* __linux__ */
1349
1350 return 0;
1351}
1352
1353
1354#ifdef ANDROID
1355static int add_ipv6_rule(struct sigma_dut *dut, const char *ifname)
1356{
1357 char cmd[200], *result, *pos;
1358 FILE *fp;
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +05301359 int tableid;
1360 size_t len, result_len = 1000;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001361
1362 snprintf(cmd, sizeof(cmd), "ip -6 route list table all | grep %s",
1363 ifname);
1364 fp = popen(cmd, "r");
1365 if (fp == NULL)
1366 return -1;
1367
1368 result = malloc(result_len);
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05301369 if (result == NULL) {
1370 fclose(fp);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001371 return -1;
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05301372 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001373
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +05301374 len = fread(result, 1, result_len - 1, fp);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001375 fclose(fp);
1376
1377 if (len == 0) {
1378 free(result);
1379 return -1;
1380 }
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +05301381 result[len] = '\0';
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001382
1383 pos = strstr(result, "table ");
1384 if (pos == NULL) {
1385 free(result);
1386 return -1;
1387 }
1388
1389 pos += strlen("table ");
1390 tableid = atoi(pos);
1391 if (tableid != 0) {
1392 if (system("ip -6 rule del prio 22000") != 0) {
1393 /* ignore any error */
1394 }
1395 snprintf(cmd, sizeof(cmd),
1396 "ip -6 rule add from all lookup %d prio 22000",
1397 tableid);
1398 if (system(cmd) != 0) {
1399 sigma_dut_print(dut, DUT_MSG_INFO,
1400 "Failed to run %s", cmd);
1401 free(result);
1402 return -1;
1403 }
1404 } else {
1405 sigma_dut_print(dut, DUT_MSG_INFO,
1406 "No Valid Table Id found %s", pos);
1407 free(result);
1408 return -1;
1409 }
1410 free(result);
1411
1412 return 0;
1413}
1414#endif /* ANDROID */
1415
1416
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301417int set_ipv4_addr(struct sigma_dut *dut, const char *ifname,
1418 const char *ip, const char *mask)
1419{
1420 char buf[200];
1421
1422 snprintf(buf, sizeof(buf), "ifconfig %s %s netmask %s",
1423 ifname, ip, mask);
1424 return system(buf) == 0;
1425}
1426
1427
1428int set_ipv4_gw(struct sigma_dut *dut, const char *gw)
1429{
1430 char buf[200];
1431
1432 if (!is_ip_addr(gw)) {
1433 sigma_dut_print(dut, DUT_MSG_DEBUG, "Invalid gw addr - %s", gw);
1434 return -1;
1435 }
1436
1437 snprintf(buf, sizeof(buf), "route add default gw %s", gw);
1438 if (!dut->no_ip_addr_set && system(buf) != 0) {
1439 snprintf(buf, sizeof(buf), "ip ro re default via %s",
1440 gw);
1441 if (system(buf) != 0)
1442 return 0;
1443 }
1444
1445 return 1;
1446}
1447
1448
Jouni Malinenf7222712019-06-13 01:50:21 +03001449static enum sigma_cmd_result cmd_sta_set_ip_config(struct sigma_dut *dut,
1450 struct sigma_conn *conn,
1451 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001452{
1453 const char *intf = get_param(cmd, "Interface");
1454 const char *ifname;
1455 char buf[200];
1456 const char *val, *ip, *mask, *gw;
1457 int type = 1;
1458
1459 if (intf == NULL)
1460 return -1;
1461
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001462 if (strcmp(intf, get_main_ifname(dut)) == 0)
1463 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001464 else
1465 ifname = intf;
1466
1467 if (if_nametoindex(ifname) == 0) {
1468 send_resp(dut, conn, SIGMA_ERROR,
1469 "ErrorCode,Unknown interface");
1470 return 0;
1471 }
1472
1473 val = get_param(cmd, "Type");
1474 if (val) {
1475 type = atoi(val);
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301476 if (type < 1 || type > 3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001477 send_resp(dut, conn, SIGMA_ERROR,
1478 "ErrorCode,Unsupported address type");
1479 return 0;
1480 }
1481 }
1482
1483 dut->last_set_ip_config_ipv6 = 0;
1484
1485 val = get_param(cmd, "dhcp");
1486 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "true") == 0)) {
1487 static_ip_file(0, NULL, NULL, NULL);
1488#ifdef __linux__
1489 if (type == 2) {
1490 dut->last_set_ip_config_ipv6 = 1;
1491 sigma_dut_print(dut, DUT_MSG_INFO, "Using IPv6 "
1492 "stateless address autoconfiguration");
1493#ifdef ANDROID
1494 /*
1495 * This sleep is required as the assignment in case of
1496 * Android is taking time and is done by the kernel.
1497 * The subsequent ping for IPv6 is impacting HS20 test
1498 * case.
1499 */
1500 sleep(2);
1501 add_ipv6_rule(dut, intf);
1502#endif /* ANDROID */
1503 /* Assume this happens by default */
1504 return 1;
1505 }
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301506 if (type != 3) {
1507 kill_dhcp_client(dut, ifname);
1508 if (start_dhcp_client(dut, ifname) < 0)
1509 return -2;
1510 } else {
1511 sigma_dut_print(dut, DUT_MSG_DEBUG,
1512 "Using FILS HLP DHCPv4 Rapid Commit");
1513 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001514
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001515 return 1;
1516#endif /* __linux__ */
1517 return -2;
1518 }
1519
1520 ip = get_param(cmd, "ip");
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301521 if (!ip) {
1522 send_resp(dut, conn, SIGMA_INVALID,
1523 "ErrorCode,Missing IP address");
1524 return 0;
1525 }
1526
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001527 mask = get_param(cmd, "mask");
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301528 if (!mask) {
1529 send_resp(dut, conn, SIGMA_INVALID,
1530 "ErrorCode,Missing subnet mask");
1531 return 0;
1532 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001533
1534 if (type == 2) {
1535 int net = atoi(mask);
1536
1537 if ((net < 0 && net > 64) || !is_ipv6_addr(ip))
1538 return -1;
1539
1540 if (dut->no_ip_addr_set) {
1541 snprintf(buf, sizeof(buf),
1542 "sysctl net.ipv6.conf.%s.disable_ipv6=1",
1543 ifname);
1544 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
1545 if (system(buf) != 0) {
1546 sigma_dut_print(dut, DUT_MSG_DEBUG,
1547 "Failed to disable IPv6 address before association");
1548 }
1549 } else {
Veerendranath Jakkam176181c2020-05-16 00:19:21 +05301550 if (set_ipv6_addr(dut, ip, mask, ifname) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001551 send_resp(dut, conn, SIGMA_ERROR,
1552 "ErrorCode,Failed to set IPv6 address");
1553 return 0;
1554 }
1555 }
1556
1557 dut->last_set_ip_config_ipv6 = 1;
1558 static_ip_file(6, ip, mask, NULL);
1559 return 1;
1560 } else if (type == 1) {
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301561 if (!is_ip_addr(ip) || !is_ip_addr(mask))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001562 return -1;
1563 }
1564
1565 kill_dhcp_client(dut, ifname);
1566
1567 if (!dut->no_ip_addr_set) {
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301568 if (!set_ipv4_addr(dut, ifname, ip, mask)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001569 send_resp(dut, conn, SIGMA_ERROR,
1570 "ErrorCode,Failed to set IP address");
1571 return 0;
1572 }
1573 }
1574
1575 gw = get_param(cmd, "defaultGateway");
1576 if (gw) {
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301577 if (set_ipv4_gw(dut, gw) < 1) {
1578 send_resp(dut, conn, SIGMA_ERROR,
1579 "ErrorCode,Failed to set default gateway");
1580 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001581 }
1582 }
1583
1584 val = get_param(cmd, "primary-dns");
1585 if (val) {
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
Jouni Malinenf7222712019-06-13 01:50:21 +03002134static enum sigma_cmd_result cmd_sta_set_psk(struct sigma_dut *dut,
2135 struct sigma_conn *conn,
2136 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002137{
2138 const char *intf = get_param(cmd, "Interface");
Jouni Malinen992a81e2017-08-22 13:57:47 +03002139 const char *type = get_param(cmd, "Type");
Jouni Malinen1287cd72018-01-04 17:08:01 +02002140 const char *pmf = get_param(cmd, "PMF");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002141 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinene4fde732019-03-25 22:29:37 +02002142 const char *akm = get_param(cmd, "AKMSuiteType");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002143 const char *ifname, *val, *alg;
2144 int id;
Jouni Malinen4b3769d2019-10-10 16:20:29 +03002145 char buf[50];
Jouni Malinen11e55212019-11-22 21:46:59 +02002146 int sae_pwe = -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002147
2148 if (intf == NULL)
2149 return -1;
2150
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002151 if (strcmp(intf, get_main_ifname(dut)) == 0)
2152 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002153 else
2154 ifname = intf;
2155
2156 id = set_wpa_common(dut, conn, ifname, cmd);
2157 if (id < 0)
2158 return id;
2159
2160 val = get_param(cmd, "keyMgmtType");
2161 alg = get_param(cmd, "micAlg");
2162
Jouni Malinen992a81e2017-08-22 13:57:47 +03002163 if (type && strcasecmp(type, "SAE") == 0) {
Jouni Malinene4fde732019-03-25 22:29:37 +02002164 if (!akm && val && strcasecmp(val, "wpa2-ft") == 0) {
Jouni Malinen992a81e2017-08-22 13:57:47 +03002165 if (set_network(ifname, id, "key_mgmt", "FT-SAE") < 0)
2166 return -2;
Jouni Malinene4fde732019-03-25 22:29:37 +02002167 } else if (!akm) {
Jouni Malinen992a81e2017-08-22 13:57:47 +03002168 if (set_network(ifname, id, "key_mgmt", "SAE") < 0)
2169 return -2;
2170 }
2171 if (wpa_command(ifname, "SET sae_groups ") != 0) {
2172 sigma_dut_print(dut, DUT_MSG_ERROR,
2173 "Failed to clear sae_groups to default");
2174 return -2;
2175 }
Jouni Malinen1287cd72018-01-04 17:08:01 +02002176 if (!pmf) {
2177 dut->sta_pmf = STA_PMF_REQUIRED;
2178 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2179 return -2;
2180 }
Jouni Malinen0ab50f42017-08-31 01:34:59 +03002181 } else if (type && strcasecmp(type, "PSK-SAE") == 0) {
2182 if (val && strcasecmp(val, "wpa2-ft") == 0) {
2183 if (set_network(ifname, id, "key_mgmt",
2184 "FT-SAE FT-PSK") < 0)
2185 return -2;
Jouni Malinen3b73d872019-06-12 03:13:25 +03002186 } else if (!akm) {
Jouni Malinen0ab50f42017-08-31 01:34:59 +03002187 if (set_network(ifname, id, "key_mgmt",
2188 "SAE WPA-PSK") < 0)
2189 return -2;
2190 }
2191 if (wpa_command(ifname, "SET sae_groups ") != 0) {
2192 sigma_dut_print(dut, DUT_MSG_ERROR,
2193 "Failed to clear sae_groups to default");
2194 return -2;
2195 }
Jouni Malinen1287cd72018-01-04 17:08:01 +02002196 if (!pmf) {
2197 dut->sta_pmf = STA_PMF_OPTIONAL;
2198 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2199 return -2;
2200 }
Jouni Malinen992a81e2017-08-22 13:57:47 +03002201 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002202 if (set_network(ifname, id, "key_mgmt", "WPA-PSK-SHA256") < 0)
2203 return -2;
2204 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
2205 if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0)
2206 return -2;
Ashwini Patil6dbf7b02017-03-20 13:42:11 +05302207 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
2208 if (set_network(ifname, id, "key_mgmt", "FT-PSK") < 0)
2209 return -2;
Jouni Malinen3b73d872019-06-12 03:13:25 +03002210 } else if (!akm &&
2211 ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
2212 dut->sta_pmf == STA_PMF_REQUIRED)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002213 if (set_network(ifname, id, "key_mgmt",
2214 "WPA-PSK WPA-PSK-SHA256") < 0)
2215 return -2;
Jouni Malinen77ff3f02019-03-28 03:45:40 +02002216 } else if (!akm && dut->sta_pmf == STA_PMF_OPTIONAL) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002217 if (set_network(ifname, id, "key_mgmt",
2218 "WPA-PSK WPA-PSK-SHA256") < 0)
2219 return -2;
Jouni Malinen77ff3f02019-03-28 03:45:40 +02002220 } else if (!akm) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002221 if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0)
2222 return -2;
2223 }
2224
2225 val = get_param(cmd, "passPhrase");
2226 if (val == NULL)
2227 return -1;
Jouni Malinen2126f422017-10-11 23:24:33 +03002228 if (type && strcasecmp(type, "SAE") == 0) {
2229 if (set_network_quoted(ifname, id, "sae_password", val) < 0)
2230 return -2;
2231 } else {
2232 if (set_network_quoted(ifname, id, "psk", val) < 0)
2233 return -2;
2234 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002235
Jouni Malinen78d10c42019-03-25 22:34:32 +02002236 val = get_param(cmd, "PasswordId");
2237 if (val && set_network_quoted(ifname, id, "sae_password_id", val) < 0)
2238 return ERROR_SEND_STATUS;
2239
Jouni Malinen992a81e2017-08-22 13:57:47 +03002240 val = get_param(cmd, "ECGroupID");
2241 if (val) {
Jouni Malinenb54f0df2019-12-12 01:57:29 +02002242 snprintf(buf, sizeof(buf), "SET sae_groups %s", val);
Jouni Malinen992a81e2017-08-22 13:57:47 +03002243 if (wpa_command(ifname, buf) != 0) {
2244 sigma_dut_print(dut, DUT_MSG_ERROR,
2245 "Failed to clear sae_groups");
2246 return -2;
2247 }
2248 }
2249
Jouni Malinen68143132017-09-02 02:34:08 +03002250 val = get_param(cmd, "InvalidSAEElement");
2251 if (val) {
2252 free(dut->sae_commit_override);
2253 dut->sae_commit_override = strdup(val);
2254 }
2255
Jouni Malinen4b3769d2019-10-10 16:20:29 +03002256 val = get_param(cmd, "PMKID_Include");
2257 if (val) {
2258 snprintf(buf, sizeof(buf), "SET sae_pmkid_in_assoc %d",
2259 get_enable_disable(val));
2260 wpa_command(intf, buf);
2261 }
2262
Jouni Malineneeb43d32019-12-06 17:40:07 +02002263 val = get_param(cmd, "IgnoreH2E_RSNXE_BSSMemSel");
2264 if (val) {
2265 snprintf(buf, sizeof(buf), "SET ignore_sae_h2e_only %d",
2266 get_enable_disable(val));
2267 wpa_command(intf, buf);
2268 }
2269
Jouni Malinenf2348d22019-12-07 11:52:55 +02002270 val = get_param(cmd, "ECGroupID_RGE");
2271 if (val) {
2272 snprintf(buf, sizeof(buf), "SET extra_sae_rejected_groups %s",
2273 val);
2274 wpa_command(intf, buf);
2275 }
2276
Jouni Malinen99e55022019-12-07 13:59:41 +02002277 val = get_param(cmd, "RSNXE_Content");
2278 if (val) {
2279 const char *param;
2280
2281 if (strncasecmp(val, "AssocReq:", 9) == 0) {
2282 val += 9;
2283 param = "rsnxe_override_assoc";
2284 } else if (strncasecmp(val, "EapolM2:", 8) == 0) {
2285 val += 8;
2286 param = "rsnxe_override_eapol";
2287 } else {
2288 send_resp(dut, conn, SIGMA_ERROR,
2289 "errorCode,Unsupported RSNXE_Content value");
2290 return STATUS_SENT_ERROR;
2291 }
2292 snprintf(buf, sizeof(buf), "SET %s %s", param, val);
2293 wpa_command(intf, buf);
2294 }
2295
Jouni Malinen11e55212019-11-22 21:46:59 +02002296 val = get_param(cmd, "sae_pwe");
2297 if (val) {
2298 if (strcasecmp(val, "h2e") == 0) {
2299 dut->sae_pwe = SAE_PWE_H2E;
Jouni Malinen7244a412019-12-07 11:54:10 +02002300 } else if (strcasecmp(val, "loop") == 0 ||
2301 strcasecmp(val, "looping") == 0) {
Jouni Malinen11e55212019-11-22 21:46:59 +02002302 dut->sae_pwe = SAE_PWE_LOOP;
2303 } else {
2304 send_resp(dut, conn, SIGMA_ERROR,
2305 "errorCode,Unsupported sae_pwe value");
2306 return STATUS_SENT_ERROR;
2307 }
2308 }
Vinita S. Maloo6d7454f2020-04-02 15:03:26 +05302309
2310 val = get_param(cmd, "Clear_RSNXE");
2311 if (val && strcmp(val, "1") == 0 &&
2312 (wpa_command(intf, "SET rsnxe_override_assoc ") ||
2313 wpa_command(intf, "SET rsnxe_override_eapol "))) {
2314 send_resp(dut, conn, SIGMA_ERROR,
2315 "errorCode,Failed to clear RSNXE");
Jouni Malinenb11498c2020-08-03 11:05:53 +03002316 return STATUS_SENT_ERROR;
Vinita S. Maloo6d7454f2020-04-02 15:03:26 +05302317 }
2318
Jouni Malinenc0078772020-03-04 21:23:16 +02002319 if (dut->sae_pwe == SAE_PWE_LOOP && get_param(cmd, "PasswordId"))
2320 sae_pwe = 3;
2321 else if (dut->sae_pwe == SAE_PWE_LOOP)
Jouni Malinen11e55212019-11-22 21:46:59 +02002322 sae_pwe = 0;
2323 else if (dut->sae_pwe == SAE_PWE_H2E)
2324 sae_pwe = 1;
2325 else if (dut->sae_h2e_default)
2326 sae_pwe = 2;
2327 snprintf(buf, sizeof(buf), "SET sae_pwe %d", sae_pwe);
2328 if (sae_pwe >= 0 && wpa_command(ifname, buf) != 0)
2329 return ERROR_SEND_STATUS;
2330
Veerendranath Jakkam0316be12020-06-23 20:11:41 +05302331 val = get_param(cmd, "sae_pk");
2332 if (val && strcmp(val, "0") == 0 &&
2333 set_network(ifname, id, "sae_pk", "2") < 0)
2334 return ERROR_SEND_STATUS;
2335
Veerendranath Jakkama9177042020-08-10 00:14:03 +05302336 val = get_param(cmd, "sae_pk_only");
2337 if (val && strcmp(val, "1") == 0 &&
2338 set_network(ifname, id, "sae_pk", "1") < 0)
2339 return ERROR_SEND_STATUS;
2340
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002341 if (dut->program == PROGRAM_60GHZ && network_mode &&
2342 strcasecmp(network_mode, "PBSS") == 0 &&
2343 set_network(ifname, id, "pbss", "1") < 0)
2344 return -2;
2345
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002346 return 1;
2347}
2348
2349
Jouni Malinen8ac93452019-08-14 15:19:13 +03002350static enum sigma_cmd_result set_trust_root_system(struct sigma_dut *dut,
2351 struct sigma_conn *conn,
2352 const char *ifname, int id)
2353{
2354 char buf[200];
2355
2356 snprintf(buf, sizeof(buf), "%s/certs", sigma_cert_path);
2357 if (!file_exists(buf))
2358 strlcpy(buf, "/system/etc/security/cacerts", sizeof(buf));
2359 if (!file_exists(buf))
2360 strlcpy(buf, "/etc/ssl/certs", sizeof(buf));
2361 if (!file_exists(buf)) {
2362 char msg[300];
2363
2364 snprintf(msg, sizeof(msg),
2365 "ErrorCode,trustedRootCA system store (%s) not found",
2366 buf);
2367 send_resp(dut, conn, SIGMA_ERROR, msg);
2368 return STATUS_SENT_ERROR;
2369 }
2370
2371 if (set_network_quoted(ifname, id, "ca_path", buf) < 0)
2372 return ERROR_SEND_STATUS;
2373
2374 return SUCCESS_SEND_STATUS;
2375}
2376
2377
2378static enum sigma_cmd_result set_trust_root(struct sigma_dut *dut,
2379 struct sigma_conn *conn,
2380 const char *ifname, int id,
2381 const char *val)
2382{
2383 char buf[200];
2384#ifdef ANDROID
2385 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
2386 int length;
2387#endif /* ANDROID */
2388
2389 if (strcmp(val, "DEFAULT") == 0)
2390 return set_trust_root_system(dut, conn, ifname, id);
2391
2392#ifdef ANDROID
2393 snprintf(buf, sizeof(buf), "CACERT_%s", val);
2394 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
2395 if (length > 0) {
2396 sigma_dut_print(dut, DUT_MSG_INFO, "Use Android keystore [%s]",
2397 buf);
2398 snprintf(buf, sizeof(buf), "keystore://CACERT_%s", val);
2399 goto ca_cert_selected;
2400 }
2401#endif /* ANDROID */
2402
2403 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
2404#ifdef __linux__
2405 if (!file_exists(buf)) {
2406 char msg[300];
2407
2408 snprintf(msg, sizeof(msg),
2409 "ErrorCode,trustedRootCA file (%s) not found", buf);
2410 send_resp(dut, conn, SIGMA_ERROR, msg);
2411 return STATUS_SENT_ERROR;
2412 }
2413#endif /* __linux__ */
2414#ifdef ANDROID
2415ca_cert_selected:
2416#endif /* ANDROID */
2417 if (set_network_quoted(ifname, id, "ca_cert", buf) < 0)
2418 return ERROR_SEND_STATUS;
2419
2420 return SUCCESS_SEND_STATUS;
2421}
2422
2423
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002424static int set_eap_common(struct sigma_dut *dut, struct sigma_conn *conn,
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302425 const char *ifname, int username_identity,
2426 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002427{
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002428 const char *val, *alg, *akm, *trust_root, *domain, *domain_suffix;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002429 int id;
Jouni Malinen53264f62019-05-03 13:04:40 +03002430 char buf[200], buf2[300];
Jouni Malinen8179fee2019-03-28 03:19:47 +02002431 int erp = 0;
Jouni Malinen8ac93452019-08-14 15:19:13 +03002432 enum sigma_cmd_result res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002433
2434 id = set_wpa_common(dut, conn, ifname, cmd);
2435 if (id < 0)
2436 return id;
2437
2438 val = get_param(cmd, "keyMgmtType");
2439 alg = get_param(cmd, "micAlg");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302440 akm = get_param(cmd, "AKMSuiteType");
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002441 trust_root = get_param(cmd, "trustedRootCA");
2442 domain = get_param(cmd, "Domain");
2443 domain_suffix = get_param(cmd, "DomainSuffix");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002444
Jouni Malinenad395a22017-09-01 21:13:46 +03002445 if (val && strcasecmp(val, "SuiteB") == 0) {
2446 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SUITE-B-192") <
2447 0)
2448 return -2;
2449 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002450 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SHA256") < 0)
2451 return -2;
2452 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
2453 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
2454 return -2;
2455 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
2456 if (set_network(ifname, id, "key_mgmt", "FT-EAP") < 0)
2457 return -2;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002458 } else if (!akm &&
2459 ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
2460 dut->sta_pmf == STA_PMF_REQUIRED)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002461 if (set_network(ifname, id, "key_mgmt",
2462 "WPA-EAP WPA-EAP-SHA256") < 0)
2463 return -2;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302464 } else if (akm && atoi(akm) == 14) {
2465 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
2466 dut->sta_pmf == STA_PMF_REQUIRED) {
2467 if (set_network(ifname, id, "key_mgmt",
2468 "WPA-EAP-SHA256 FILS-SHA256") < 0)
2469 return -2;
2470 } else {
2471 if (set_network(ifname, id, "key_mgmt",
2472 "WPA-EAP FILS-SHA256") < 0)
2473 return -2;
2474 }
2475
Jouni Malinen8179fee2019-03-28 03:19:47 +02002476 erp = 1;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302477 } else if (akm && atoi(akm) == 15) {
2478 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
2479 dut->sta_pmf == STA_PMF_REQUIRED) {
2480 if (set_network(ifname, id, "key_mgmt",
2481 "WPA-EAP-SHA256 FILS-SHA384") < 0)
2482 return -2;
2483 } else {
2484 if (set_network(ifname, id, "key_mgmt",
2485 "WPA-EAP FILS-SHA384") < 0)
2486 return -2;
2487 }
2488
Jouni Malinen8179fee2019-03-28 03:19:47 +02002489 erp = 1;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002490 } else if (!akm && dut->sta_pmf == STA_PMF_OPTIONAL) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002491 if (set_network(ifname, id, "key_mgmt",
2492 "WPA-EAP WPA-EAP-SHA256") < 0)
2493 return -2;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002494 } else if (!akm) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002495 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
2496 return -2;
2497 }
2498
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002499 if (trust_root) {
2500 if (strcmp(trust_root, "DEFAULT") == 0 && !domain &&
2501 !domain_suffix) {
2502 send_resp(dut, conn, SIGMA_ERROR,
2503 "errorCode,trustRootCA DEFAULT used without specifying Domain or DomainSuffix");
2504 return STATUS_SENT_ERROR;
2505 }
2506 res = set_trust_root(dut, conn, ifname, id, trust_root);
Jouni Malinen8ac93452019-08-14 15:19:13 +03002507 if (res != SUCCESS_SEND_STATUS)
2508 return res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002509 }
2510
Jouni Malinen53264f62019-05-03 13:04:40 +03002511 val = get_param(cmd, "ServerCert");
2512 if (val) {
2513 FILE *f;
2514 char *result = NULL, *pos;
2515
2516 snprintf(buf, sizeof(buf), "%s/%s.sha256", sigma_cert_path,
2517 val);
2518 f = fopen(buf, "r");
2519 if (f) {
2520 result = fgets(buf, sizeof(buf), f);
2521 fclose(f);
2522 }
2523 if (!result) {
2524 snprintf(buf2, sizeof(buf2),
2525 "ErrorCode,ServerCert hash could not be read from %s",
2526 buf);
2527 send_resp(dut, conn, SIGMA_ERROR, buf2);
2528 return STATUS_SENT_ERROR;
2529 }
2530 pos = strchr(buf, '\n');
2531 if (pos)
2532 *pos = '\0';
Jouni Malinen0572a742020-10-08 13:53:25 +03002533 pos = strchr(buf, '\r');
2534 if (pos)
2535 *pos = '\0';
Jouni Malinen53264f62019-05-03 13:04:40 +03002536 snprintf(buf2, sizeof(buf2), "hash://server/sha256/%s", buf);
2537 if (set_network_quoted(ifname, id, "ca_cert", buf2) < 0)
2538 return ERROR_SEND_STATUS;
Jouni Malinen29108dc2019-06-13 23:42:11 +03002539
2540 snprintf(buf, sizeof(buf), "%s/%s.tod", sigma_cert_path, val);
2541 if (file_exists(buf)) {
2542 sigma_dut_print(dut, DUT_MSG_DEBUG,
2543 "TOD policy enabled for the configured ServerCert hash");
2544 dut->sta_tod_policy = 1;
2545 }
Jouni Malinen53264f62019-05-03 13:04:40 +03002546 }
2547
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002548 if (domain &&
2549 set_network_quoted(ifname, id, "domain_match", domain) < 0)
Jouni Malinen96f84b02019-05-03 12:32:56 +03002550 return ERROR_SEND_STATUS;
2551
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002552 if (domain_suffix &&
2553 set_network_quoted(ifname, id, "domain_suffix_match",
2554 domain_suffix) < 0)
Jouni Malinen96f84b02019-05-03 12:32:56 +03002555 return ERROR_SEND_STATUS;
2556
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302557 if (username_identity) {
2558 val = get_param(cmd, "username");
2559 if (val) {
2560 if (set_network_quoted(ifname, id, "identity", val) < 0)
2561 return -2;
2562 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002563
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302564 val = get_param(cmd, "password");
2565 if (val) {
2566 if (set_network_quoted(ifname, id, "password", val) < 0)
2567 return -2;
2568 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002569 }
2570
Jouni Malinen8179fee2019-03-28 03:19:47 +02002571 if (dut->akm_values &
2572 ((1 << AKM_FILS_SHA256) |
2573 (1 << AKM_FILS_SHA384) |
2574 (1 << AKM_FT_FILS_SHA256) |
2575 (1 << AKM_FT_FILS_SHA384)))
2576 erp = 1;
2577 if (erp && set_network(ifname, id, "erp", "1") < 0)
2578 return ERROR_SEND_STATUS;
2579
Jouni Malinen134fe3c2019-06-12 04:16:49 +03002580 dut->sta_associate_wait_connect = 1;
2581
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002582 return id;
2583}
2584
2585
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002586static int set_tls_cipher(const char *ifname, int id, const char *cipher)
2587{
2588 const char *val;
2589
2590 if (!cipher)
2591 return 0;
2592
2593 if (strcasecmp(cipher, "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384") == 0)
2594 val = "ECDHE-ECDSA-AES256-GCM-SHA384";
2595 else if (strcasecmp(cipher,
2596 "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
2597 val = "ECDHE-RSA-AES256-GCM-SHA384";
2598 else if (strcasecmp(cipher, "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
2599 val = "DHE-RSA-AES256-GCM-SHA384";
2600 else if (strcasecmp(cipher,
2601 "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256") == 0)
2602 val = "ECDHE-ECDSA-AES128-GCM-SHA256";
2603 else
2604 return -1;
2605
2606 /* Need to clear phase1="tls_suiteb=1" to allow cipher enforcement */
2607 set_network_quoted(ifname, id, "phase1", "");
2608
2609 return set_network_quoted(ifname, id, "openssl_ciphers", val);
2610}
2611
2612
Jouni Malinenf7222712019-06-13 01:50:21 +03002613static enum sigma_cmd_result cmd_sta_set_eaptls(struct sigma_dut *dut,
2614 struct sigma_conn *conn,
2615 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002616{
2617 const char *intf = get_param(cmd, "Interface");
2618 const char *ifname, *val;
2619 int id;
2620 char buf[200];
2621#ifdef ANDROID
2622 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
2623 int length;
2624 int jb_or_newer = 0;
2625 char prop[PROPERTY_VALUE_MAX];
2626#endif /* ANDROID */
2627
2628 if (intf == NULL)
2629 return -1;
2630
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002631 if (strcmp(intf, get_main_ifname(dut)) == 0)
2632 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002633 else
2634 ifname = intf;
2635
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302636 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002637 if (id < 0)
2638 return id;
2639
2640 if (set_network(ifname, id, "eap", "TLS") < 0)
2641 return -2;
2642
Pradeep Reddy POTTETI9f6c2132016-05-05 16:28:19 +05302643 if (!get_param(cmd, "username") &&
2644 set_network_quoted(ifname, id, "identity",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002645 "wifi-user@wifilabs.local") < 0)
2646 return -2;
2647
2648 val = get_param(cmd, "clientCertificate");
2649 if (val == NULL)
2650 return -1;
2651#ifdef ANDROID
2652 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2653 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
2654 if (length < 0) {
2655 /*
2656 * JB started reporting keystore type mismatches, so retry with
2657 * the GET_PUBKEY command if the generic GET fails.
2658 */
2659 length = android_keystore_get(ANDROID_KEYSTORE_GET_PUBKEY,
2660 buf, kvalue);
2661 }
2662
2663 if (property_get("ro.build.version.release", prop, NULL) != 0) {
2664 sigma_dut_print(dut, DUT_MSG_DEBUG, "Android release %s", prop);
2665 if (strncmp(prop, "4.0", 3) != 0)
2666 jb_or_newer = 1;
2667 } else
2668 jb_or_newer = 1; /* assume newer */
2669
2670 if (jb_or_newer && length > 0) {
2671 sigma_dut_print(dut, DUT_MSG_INFO,
2672 "Use Android keystore [%s]", buf);
2673 if (set_network(ifname, id, "engine", "1") < 0)
2674 return -2;
2675 if (set_network_quoted(ifname, id, "engine_id", "keystore") < 0)
2676 return -2;
2677 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2678 if (set_network_quoted(ifname, id, "key_id", buf) < 0)
2679 return -2;
2680 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2681 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2682 return -2;
2683 return 1;
2684 } else if (length > 0) {
2685 sigma_dut_print(dut, DUT_MSG_INFO,
2686 "Use Android keystore [%s]", buf);
2687 snprintf(buf, sizeof(buf), "keystore://USRPKEY_%s", val);
2688 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2689 return -2;
2690 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2691 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2692 return -2;
2693 return 1;
2694 }
2695#endif /* ANDROID */
2696
2697 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
2698#ifdef __linux__
2699 if (!file_exists(buf)) {
2700 char msg[300];
2701 snprintf(msg, sizeof(msg), "ErrorCode,clientCertificate file "
2702 "(%s) not found", buf);
2703 send_resp(dut, conn, SIGMA_ERROR, msg);
2704 return -3;
2705 }
2706#endif /* __linux__ */
2707 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2708 return -2;
2709 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2710 return -2;
2711
2712 if (set_network_quoted(ifname, id, "private_key_passwd", "wifi") < 0)
2713 return -2;
2714
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002715 val = get_param(cmd, "keyMgmtType");
2716 if (val && strcasecmp(val, "SuiteB") == 0) {
2717 val = get_param(cmd, "CertType");
2718 if (val && strcasecmp(val, "RSA") == 0) {
2719 if (set_network_quoted(ifname, id, "phase1",
2720 "tls_suiteb=1") < 0)
2721 return -2;
2722 } else {
2723 if (set_network_quoted(ifname, id, "openssl_ciphers",
2724 "SUITEB192") < 0)
2725 return -2;
2726 }
2727
2728 val = get_param(cmd, "TLSCipher");
2729 if (set_tls_cipher(ifname, id, val) < 0) {
2730 send_resp(dut, conn, SIGMA_ERROR,
2731 "ErrorCode,Unsupported TLSCipher value");
2732 return -3;
2733 }
2734 }
2735
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002736 return 1;
2737}
2738
2739
Jouni Malinenf7222712019-06-13 01:50:21 +03002740static enum sigma_cmd_result cmd_sta_set_eapttls(struct sigma_dut *dut,
2741 struct sigma_conn *conn,
2742 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002743{
2744 const char *intf = get_param(cmd, "Interface");
2745 const char *ifname;
2746 int id;
2747
2748 if (intf == NULL)
2749 return -1;
2750
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002751 if (strcmp(intf, get_main_ifname(dut)) == 0)
2752 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002753 else
2754 ifname = intf;
2755
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302756 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002757 if (id < 0)
2758 return id;
2759
2760 if (set_network(ifname, id, "eap", "TTLS") < 0) {
2761 send_resp(dut, conn, SIGMA_ERROR,
2762 "errorCode,Failed to set TTLS method");
2763 return 0;
2764 }
2765
2766 if (set_network_quoted(ifname, id, "phase2", "auth=MSCHAPV2") < 0) {
2767 send_resp(dut, conn, SIGMA_ERROR,
2768 "errorCode,Failed to set MSCHAPv2 for TTLS Phase 2");
2769 return 0;
2770 }
2771
2772 return 1;
2773}
2774
2775
Jouni Malinenf7222712019-06-13 01:50:21 +03002776static enum sigma_cmd_result cmd_sta_set_eapsim(struct sigma_dut *dut,
2777 struct sigma_conn *conn,
2778 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002779{
2780 const char *intf = get_param(cmd, "Interface");
2781 const char *ifname;
2782 int id;
2783
2784 if (intf == NULL)
2785 return -1;
2786
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002787 if (strcmp(intf, get_main_ifname(dut)) == 0)
2788 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002789 else
2790 ifname = intf;
2791
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302792 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002793 if (id < 0)
2794 return id;
2795
2796 if (set_network(ifname, id, "eap", "SIM") < 0)
2797 return -2;
2798
2799 return 1;
2800}
2801
2802
Jouni Malinenf7222712019-06-13 01:50:21 +03002803static enum sigma_cmd_result cmd_sta_set_peap(struct sigma_dut *dut,
2804 struct sigma_conn *conn,
2805 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002806{
2807 const char *intf = get_param(cmd, "Interface");
2808 const char *ifname, *val;
2809 int id;
2810 char buf[100];
2811
2812 if (intf == NULL)
2813 return -1;
2814
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002815 if (strcmp(intf, get_main_ifname(dut)) == 0)
2816 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002817 else
2818 ifname = intf;
2819
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302820 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002821 if (id < 0)
2822 return id;
2823
2824 if (set_network(ifname, id, "eap", "PEAP") < 0)
2825 return -2;
2826
2827 val = get_param(cmd, "innerEAP");
2828 if (val) {
2829 if (strcasecmp(val, "MSCHAPv2") == 0) {
2830 if (set_network_quoted(ifname, id, "phase2",
2831 "auth=MSCHAPV2") < 0)
2832 return -2;
2833 } else if (strcasecmp(val, "GTC") == 0) {
2834 if (set_network_quoted(ifname, id, "phase2",
2835 "auth=GTC") < 0)
2836 return -2;
2837 } else
2838 return -1;
2839 }
2840
2841 val = get_param(cmd, "peapVersion");
2842 if (val) {
2843 int ver = atoi(val);
2844 if (ver < 0 || ver > 1)
2845 return -1;
2846 snprintf(buf, sizeof(buf), "peapver=%d", ver);
2847 if (set_network_quoted(ifname, id, "phase1", buf) < 0)
2848 return -2;
2849 }
2850
2851 return 1;
2852}
2853
2854
Jouni Malinenf7222712019-06-13 01:50:21 +03002855static enum sigma_cmd_result cmd_sta_set_eapfast(struct sigma_dut *dut,
2856 struct sigma_conn *conn,
2857 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002858{
2859 const char *intf = get_param(cmd, "Interface");
2860 const char *ifname, *val;
2861 int id;
2862 char buf[100];
2863
2864 if (intf == NULL)
2865 return -1;
2866
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002867 if (strcmp(intf, get_main_ifname(dut)) == 0)
2868 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002869 else
2870 ifname = intf;
2871
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302872 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002873 if (id < 0)
2874 return id;
2875
2876 if (set_network(ifname, id, "eap", "FAST") < 0)
2877 return -2;
2878
2879 val = get_param(cmd, "innerEAP");
2880 if (val) {
2881 if (strcasecmp(val, "MSCHAPV2") == 0) {
2882 if (set_network_quoted(ifname, id, "phase2",
2883 "auth=MSCHAPV2") < 0)
2884 return -2;
2885 } else if (strcasecmp(val, "GTC") == 0) {
2886 if (set_network_quoted(ifname, id, "phase2",
2887 "auth=GTC") < 0)
2888 return -2;
2889 } else
2890 return -1;
2891 }
2892
2893 val = get_param(cmd, "validateServer");
2894 if (val) {
2895 /* TODO */
2896 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored EAP-FAST "
2897 "validateServer=%s", val);
2898 }
2899
2900 val = get_param(cmd, "pacFile");
2901 if (val) {
2902 snprintf(buf, sizeof(buf), "blob://%s", val);
2903 if (set_network_quoted(ifname, id, "pac_file", buf) < 0)
2904 return -2;
2905 }
2906
2907 if (set_network_quoted(ifname, id, "phase1", "fast_provisioning=2") <
2908 0)
2909 return -2;
2910
2911 return 1;
2912}
2913
2914
Jouni Malinenf7222712019-06-13 01:50:21 +03002915static enum sigma_cmd_result cmd_sta_set_eapaka(struct sigma_dut *dut,
2916 struct sigma_conn *conn,
2917 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002918{
2919 const char *intf = get_param(cmd, "Interface");
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302920 const char *username = get_param(cmd, "Username");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002921 const char *ifname;
2922 int id;
2923
2924 if (intf == NULL)
2925 return -1;
2926
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002927 if (strcmp(intf, get_main_ifname(dut)) == 0)
2928 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002929 else
2930 ifname = intf;
2931
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302932 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002933 if (id < 0)
2934 return id;
2935
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302936 /* RFC 5448: EAP-AKA' MUST use the leading character "6" (ASCII 36
2937 * hexadecimal).
2938 */
2939 if (username && username[0] == '6') {
2940 if (set_network(ifname, id, "eap", "AKA'") < 0)
2941 return -2;
2942 } else if (set_network(ifname, id, "eap", "AKA") < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002943 return -2;
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302944 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002945
2946 return 1;
2947}
2948
2949
Jouni Malinenf7222712019-06-13 01:50:21 +03002950static enum sigma_cmd_result cmd_sta_set_eapakaprime(struct sigma_dut *dut,
2951 struct sigma_conn *conn,
2952 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002953{
2954 const char *intf = get_param(cmd, "Interface");
2955 const char *ifname;
2956 int id;
2957
2958 if (intf == NULL)
2959 return -1;
2960
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002961 if (strcmp(intf, get_main_ifname(dut)) == 0)
2962 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002963 else
2964 ifname = intf;
2965
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302966 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002967 if (id < 0)
2968 return id;
2969
2970 if (set_network(ifname, id, "eap", "AKA'") < 0)
2971 return -2;
2972
2973 return 1;
2974}
2975
2976
2977static int sta_set_open(struct sigma_dut *dut, struct sigma_conn *conn,
2978 struct sigma_cmd *cmd)
2979{
2980 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002981 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002982 const char *ifname;
2983 int id;
2984
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002985 if (strcmp(intf, get_main_ifname(dut)) == 0)
2986 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002987 else
2988 ifname = intf;
2989
2990 id = add_network_common(dut, conn, ifname, cmd);
2991 if (id < 0)
2992 return id;
2993
2994 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
2995 return -2;
2996
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002997 if (dut->program == PROGRAM_60GHZ && network_mode &&
2998 strcasecmp(network_mode, "PBSS") == 0 &&
2999 set_network(ifname, id, "pbss", "1") < 0)
3000 return -2;
3001
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003002 return 1;
3003}
3004
3005
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003006static enum sigma_cmd_result sta_set_owe(struct sigma_dut *dut,
3007 struct sigma_conn *conn,
3008 struct sigma_cmd *cmd)
Jouni Malinen47dcc952017-10-09 16:43:24 +03003009{
3010 const char *intf = get_param(cmd, "Interface");
3011 const char *ifname, *val;
3012 int id;
3013
3014 if (intf == NULL)
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003015 return INVALID_SEND_STATUS;
Jouni Malinen47dcc952017-10-09 16:43:24 +03003016
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003017 if (strcmp(intf, get_main_ifname(dut)) == 0)
3018 ifname = get_station_ifname(dut);
Jouni Malinen47dcc952017-10-09 16:43:24 +03003019 else
3020 ifname = intf;
3021
3022 id = set_wpa_common(dut, conn, ifname, cmd);
3023 if (id < 0)
3024 return id;
3025
3026 if (set_network(ifname, id, "key_mgmt", "OWE") < 0)
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003027 return ERROR_SEND_STATUS;
Jouni Malinen47dcc952017-10-09 16:43:24 +03003028
Hu Wangdd5eed22020-07-16 12:18:03 +08003029 if (dut->owe_ptk_workaround &&
3030 set_network(ifname, id, "owe_ptk_workaround", "1") < 0) {
3031 sigma_dut_print(dut, DUT_MSG_ERROR,
3032 "Failed to set owe_ptk_workaround to 1");
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003033 return ERROR_SEND_STATUS;
Hu Wangdd5eed22020-07-16 12:18:03 +08003034 }
3035
Jouni Malinen47dcc952017-10-09 16:43:24 +03003036 val = get_param(cmd, "ECGroupID");
Jouni Malinenfac9cad2017-10-10 18:35:55 +03003037 if (val && strcmp(val, "0") == 0) {
3038 if (wpa_command(ifname,
3039 "VENDOR_ELEM_ADD 13 ff23200000783590fb7440e03d5b3b33911f86affdcc6b4411b707846ac4ff08ddc8831ccd") != 0) {
3040 sigma_dut_print(dut, DUT_MSG_ERROR,
3041 "Failed to set OWE DH Param element override");
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003042 return ERROR_SEND_STATUS;
Jouni Malinenfac9cad2017-10-10 18:35:55 +03003043 }
Hu Wangdd5eed22020-07-16 12:18:03 +08003044 } else if (val && set_network(ifname, id, "owe_group", val) < 0) {
Jouni Malinen47dcc952017-10-09 16:43:24 +03003045 sigma_dut_print(dut, DUT_MSG_ERROR,
Hu Wang6010ce72020-03-05 19:33:53 +08003046 "Failed to set owe_group");
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003047 return ERROR_SEND_STATUS;
Jouni Malinen47dcc952017-10-09 16:43:24 +03003048 }
3049
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003050 return SUCCESS_SEND_STATUS;
Jouni Malinen47dcc952017-10-09 16:43:24 +03003051}
3052
3053
Jouni Malinenf7222712019-06-13 01:50:21 +03003054static enum sigma_cmd_result cmd_sta_set_security(struct sigma_dut *dut,
3055 struct sigma_conn *conn,
3056 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003057{
3058 const char *type = get_param(cmd, "Type");
3059
3060 if (type == NULL) {
3061 send_resp(dut, conn, SIGMA_ERROR,
3062 "ErrorCode,Missing Type argument");
3063 return 0;
3064 }
3065
3066 if (strcasecmp(type, "OPEN") == 0)
3067 return sta_set_open(dut, conn, cmd);
Jouni Malinen47dcc952017-10-09 16:43:24 +03003068 if (strcasecmp(type, "OWE") == 0)
3069 return sta_set_owe(dut, conn, cmd);
Jouni Malinen992a81e2017-08-22 13:57:47 +03003070 if (strcasecmp(type, "PSK") == 0 ||
Jouni Malinen0ab50f42017-08-31 01:34:59 +03003071 strcasecmp(type, "PSK-SAE") == 0 ||
Jouni Malinen992a81e2017-08-22 13:57:47 +03003072 strcasecmp(type, "SAE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003073 return cmd_sta_set_psk(dut, conn, cmd);
3074 if (strcasecmp(type, "EAPTLS") == 0)
3075 return cmd_sta_set_eaptls(dut, conn, cmd);
3076 if (strcasecmp(type, "EAPTTLS") == 0)
3077 return cmd_sta_set_eapttls(dut, conn, cmd);
3078 if (strcasecmp(type, "EAPPEAP") == 0)
3079 return cmd_sta_set_peap(dut, conn, cmd);
3080 if (strcasecmp(type, "EAPSIM") == 0)
3081 return cmd_sta_set_eapsim(dut, conn, cmd);
3082 if (strcasecmp(type, "EAPFAST") == 0)
3083 return cmd_sta_set_eapfast(dut, conn, cmd);
3084 if (strcasecmp(type, "EAPAKA") == 0)
3085 return cmd_sta_set_eapaka(dut, conn, cmd);
3086 if (strcasecmp(type, "EAPAKAPRIME") == 0)
3087 return cmd_sta_set_eapakaprime(dut, conn, cmd);
Amarnath Hullur Subramanyam81b11cd2018-01-30 19:07:17 -08003088 if (strcasecmp(type, "wep") == 0)
3089 return cmd_sta_set_encryption(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003090
3091 send_resp(dut, conn, SIGMA_ERROR,
3092 "ErrorCode,Unsupported Type value");
3093 return 0;
3094}
3095
3096
3097int ath6kl_client_uapsd(struct sigma_dut *dut, const char *intf, int uapsd)
3098{
3099#ifdef __linux__
3100 /* special handling for ath6kl */
3101 char path[128], fname[128], *pos;
3102 ssize_t res;
3103 FILE *f;
3104
Jouni Malinene39cd562019-05-29 23:39:56 +03003105 res = snprintf(fname, sizeof(fname), "/sys/class/net/%s/phy80211",
3106 intf);
3107 if (res < 0 || res >= sizeof(fname))
3108 return 0;
3109 res = readlink(fname, path, sizeof(path));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003110 if (res < 0)
3111 return 0; /* not ath6kl */
3112
3113 if (res >= (int) sizeof(path))
3114 res = sizeof(path) - 1;
3115 path[res] = '\0';
3116 pos = strrchr(path, '/');
3117 if (pos == NULL)
3118 pos = path;
3119 else
3120 pos++;
Jouni Malinen77dda642020-01-07 11:21:55 +02003121 res = snprintf(fname, sizeof(fname),
3122 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
3123 "create_qos", pos);
3124 if (res < 0 || res >= sizeof(fname) || !file_exists(fname))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003125 return 0; /* not ath6kl */
3126
3127 if (uapsd) {
3128 f = fopen(fname, "w");
3129 if (f == NULL)
3130 return -1;
3131
3132 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl create_qos");
3133 fprintf(f, "4 2 2 1 2 9999999 9999999 9999999 7777777 0 4 "
3134 "45000 200 56789000 56789000 5678900 0 0 9999999 "
3135 "20000 0\n");
3136 fclose(f);
3137 } else {
Jouni Malinen77dda642020-01-07 11:21:55 +02003138 res = snprintf(fname, sizeof(fname),
3139 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
3140 "delete_qos", pos);
3141 if (res < 0 || res >= sizeof(fname))
3142 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003143
3144 f = fopen(fname, "w");
3145 if (f == NULL)
3146 return -1;
3147
3148 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl delete_qos");
3149 fprintf(f, "2 4\n");
3150 fclose(f);
3151 }
3152#endif /* __linux__ */
3153
3154 return 0;
3155}
3156
3157
Jouni Malinenf7222712019-06-13 01:50:21 +03003158static enum sigma_cmd_result cmd_sta_set_uapsd(struct sigma_dut *dut,
3159 struct sigma_conn *conn,
3160 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003161{
3162 const char *intf = get_param(cmd, "Interface");
3163 /* const char *ssid = get_param(cmd, "ssid"); */
3164 const char *val;
3165 int max_sp_len = 4;
3166 int ac_be = 1, ac_bk = 1, ac_vi = 1, ac_vo = 1;
3167 char buf[100];
3168 int ret1, ret2;
3169
3170 val = get_param(cmd, "maxSPLength");
3171 if (val) {
3172 max_sp_len = atoi(val);
3173 if (max_sp_len != 0 && max_sp_len != 1 && max_sp_len != 2 &&
3174 max_sp_len != 4)
3175 return -1;
3176 }
3177
3178 val = get_param(cmd, "acBE");
3179 if (val)
3180 ac_be = atoi(val);
3181
3182 val = get_param(cmd, "acBK");
3183 if (val)
3184 ac_bk = atoi(val);
3185
3186 val = get_param(cmd, "acVI");
3187 if (val)
3188 ac_vi = atoi(val);
3189
3190 val = get_param(cmd, "acVO");
3191 if (val)
3192 ac_vo = atoi(val);
3193
3194 dut->client_uapsd = ac_be || ac_bk || ac_vi || ac_vo;
3195
3196 snprintf(buf, sizeof(buf), "P2P_SET client_apsd %d,%d,%d,%d;%d",
3197 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
3198 ret1 = wpa_command(intf, buf);
3199
3200 snprintf(buf, sizeof(buf), "SET uapsd %d,%d,%d,%d;%d",
3201 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
3202 ret2 = wpa_command(intf, buf);
3203
3204 if (ret1 && ret2) {
3205 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to set client mode "
3206 "UAPSD parameters.");
3207 return -2;
3208 }
3209
3210 if (ath6kl_client_uapsd(dut, intf, dut->client_uapsd) < 0) {
3211 send_resp(dut, conn, SIGMA_ERROR,
3212 "ErrorCode,Failed to set ath6kl QoS parameters");
3213 return 0;
3214 }
3215
3216 return 1;
3217}
3218
3219
Jouni Malinenf7222712019-06-13 01:50:21 +03003220static enum sigma_cmd_result cmd_sta_set_wmm(struct sigma_dut *dut,
3221 struct sigma_conn *conn,
3222 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003223{
3224 char buf[1000];
3225 const char *intf = get_param(cmd, "Interface");
3226 const char *grp = get_param(cmd, "Group");
3227 const char *act = get_param(cmd, "Action");
3228 const char *tid = get_param(cmd, "Tid");
3229 const char *dir = get_param(cmd, "Direction");
3230 const char *psb = get_param(cmd, "Psb");
3231 const char *up = get_param(cmd, "Up");
3232 const char *fixed = get_param(cmd, "Fixed");
3233 const char *size = get_param(cmd, "Size");
3234 const char *msize = get_param(cmd, "Maxsize");
3235 const char *minsi = get_param(cmd, "Min_srvc_intrvl");
3236 const char *maxsi = get_param(cmd, "Max_srvc_intrvl");
3237 const char *inact = get_param(cmd, "Inactivity");
3238 const char *sus = get_param(cmd, "Suspension");
3239 const char *mindr = get_param(cmd, "Mindatarate");
3240 const char *meandr = get_param(cmd, "Meandatarate");
3241 const char *peakdr = get_param(cmd, "Peakdatarate");
3242 const char *phyrate = get_param(cmd, "Phyrate");
3243 const char *burstsize = get_param(cmd, "Burstsize");
3244 const char *sba = get_param(cmd, "Sba");
3245 int direction;
3246 int handle;
Peng Xu93319622017-10-04 17:58:16 -07003247 float sba_fv = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003248 int fixed_int;
3249 int psb_ts;
3250
3251 if (intf == NULL || grp == NULL || act == NULL )
3252 return -1;
3253
3254 if (strcasecmp(act, "addts") == 0) {
3255 if (tid == NULL || dir == NULL || psb == NULL ||
3256 up == NULL || fixed == NULL || size == NULL)
3257 return -1;
3258
3259 /*
3260 * Note: Sigma CAPI spec lists uplink, downlink, and bidi as the
3261 * possible values, but WMM-AC and V-E test scripts use "UP,
3262 * "DOWN", and "BIDI".
3263 */
3264 if (strcasecmp(dir, "uplink") == 0 ||
3265 strcasecmp(dir, "up") == 0) {
3266 direction = 0;
3267 } else if (strcasecmp(dir, "downlink") == 0 ||
3268 strcasecmp(dir, "down") == 0) {
3269 direction = 1;
3270 } else if (strcasecmp(dir, "bidi") == 0) {
3271 direction = 2;
3272 } else {
3273 sigma_dut_print(dut, DUT_MSG_ERROR,
3274 "Direction %s not supported", dir);
3275 return -1;
3276 }
3277
3278 if (strcasecmp(psb, "legacy") == 0) {
3279 psb_ts = 0;
3280 } else if (strcasecmp(psb, "uapsd") == 0) {
3281 psb_ts = 1;
3282 } else {
3283 sigma_dut_print(dut, DUT_MSG_ERROR,
3284 "PSB %s not supported", psb);
3285 return -1;
3286 }
3287
3288 if (atoi(tid) < 0 || atoi(tid) > 7) {
3289 sigma_dut_print(dut, DUT_MSG_ERROR,
3290 "TID %s not supported", tid);
3291 return -1;
3292 }
3293
3294 if (strcasecmp(fixed, "true") == 0) {
3295 fixed_int = 1;
3296 } else {
3297 fixed_int = 0;
3298 }
3299
Peng Xu93319622017-10-04 17:58:16 -07003300 if (sba)
3301 sba_fv = atof(sba);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003302
3303 dut->dialog_token++;
3304 handle = 7000 + dut->dialog_token;
3305
3306 /*
3307 * size: convert to hex
3308 * maxsi: convert to hex
3309 * mindr: convert to hex
3310 * meandr: convert to hex
3311 * peakdr: convert to hex
3312 * burstsize: convert to hex
3313 * phyrate: convert to hex
3314 * sba: convert to hex with modification
3315 * minsi: convert to integer
3316 * sus: convert to integer
3317 * inact: convert to integer
3318 * maxsi: convert to integer
3319 */
3320
3321 /*
3322 * The Nominal MSDU Size field is 2 octets long and contains an
3323 * unsigned integer that specifies the nominal size, in octets,
3324 * of MSDUs belonging to the traffic under this traffic
3325 * specification and is defined in Figure 16. If the Fixed
3326 * subfield is set to 1, then the size of the MSDU is fixed and
3327 * is indicated by the Size Subfield. If the Fixed subfield is
3328 * set to 0, then the size of the MSDU might not be fixed and
3329 * the Size indicates the nominal MSDU size.
3330 *
3331 * The Surplus Bandwidth Allowance Factor field is 2 octets long
3332 * and specifies the excess allocation of time (and bandwidth)
3333 * over and above the stated rates required to transport an MSDU
3334 * belonging to the traffic in this TSPEC. This field is
3335 * represented as an unsigned binary number with an implicit
3336 * binary point after the leftmost 3 bits. For example, an SBA
3337 * of 1.75 is represented as 0x3800. This field is included to
3338 * account for retransmissions. As such, the value of this field
3339 * must be greater than unity.
3340 */
3341
3342 snprintf(buf, sizeof(buf),
3343 "iwpriv %s addTspec %d %s %d %d %s 0x%X"
3344 " 0x%X 0x%X 0x%X"
3345 " 0x%X 0x%X 0x%X"
3346 " 0x%X %d %d %d %d"
3347 " %d %d",
3348 intf, handle, tid, direction, psb_ts, up,
3349 (unsigned int) ((fixed_int << 15) | atoi(size)),
3350 msize ? atoi(msize) : 0,
3351 mindr ? atoi(mindr) : 0,
3352 meandr ? atoi(meandr) : 0,
3353 peakdr ? atoi(peakdr) : 0,
3354 burstsize ? atoi(burstsize) : 0,
3355 phyrate ? atoi(phyrate) : 0,
3356 sba ? ((unsigned int) (((int) sba_fv << 13) |
3357 (int)((sba_fv - (int) sba_fv) *
3358 8192))) : 0,
3359 minsi ? atoi(minsi) : 0,
3360 sus ? atoi(sus) : 0,
3361 0, 0,
3362 inact ? atoi(inact) : 0,
3363 maxsi ? atoi(maxsi) : 0);
3364
3365 if (system(buf) != 0) {
3366 sigma_dut_print(dut, DUT_MSG_ERROR,
3367 "iwpriv addtspec request failed");
3368 send_resp(dut, conn, SIGMA_ERROR,
3369 "errorCode,Failed to execute addTspec command");
3370 return 0;
3371 }
3372
3373 sigma_dut_print(dut, DUT_MSG_INFO,
3374 "iwpriv addtspec request send");
3375
3376 /* Mapping handle to a TID */
3377 dut->tid_to_handle[atoi(tid)] = handle;
3378 } else if (strcasecmp(act, "delts") == 0) {
3379 if (tid == NULL)
3380 return -1;
3381
3382 if (atoi(tid) < 0 || atoi(tid) > 7) {
3383 sigma_dut_print(dut, DUT_MSG_ERROR,
3384 "TID %s not supported", tid);
3385 send_resp(dut, conn, SIGMA_ERROR,
3386 "errorCode,Unsupported TID");
3387 return 0;
3388 }
3389
3390 handle = dut->tid_to_handle[atoi(tid)];
3391
3392 if (handle < 7000 || handle > 7255) {
3393 /* Invalid handle ie no mapping for that TID */
3394 sigma_dut_print(dut, DUT_MSG_ERROR,
3395 "handle-> %d not found", handle);
3396 }
3397
3398 snprintf(buf, sizeof(buf), "iwpriv %s delTspec %d",
3399 intf, handle);
3400
3401 if (system(buf) != 0) {
3402 sigma_dut_print(dut, DUT_MSG_ERROR,
3403 "iwpriv deltspec request failed");
3404 send_resp(dut, conn, SIGMA_ERROR,
3405 "errorCode,Failed to execute delTspec command");
3406 return 0;
3407 }
3408
3409 sigma_dut_print(dut, DUT_MSG_INFO,
3410 "iwpriv deltspec request send");
3411
3412 dut->tid_to_handle[atoi(tid)] = 0;
3413 } else {
3414 sigma_dut_print(dut, DUT_MSG_ERROR,
3415 "Action type %s not supported", act);
3416 send_resp(dut, conn, SIGMA_ERROR,
3417 "errorCode,Unsupported Action");
3418 return 0;
3419 }
3420
3421 return 1;
3422}
3423
3424
vamsi krishna52e16f92017-08-29 12:37:34 +05303425static int find_network(struct sigma_dut *dut, const char *ssid)
3426{
3427 char list[4096];
3428 char *pos;
3429
3430 sigma_dut_print(dut, DUT_MSG_DEBUG,
3431 "Search for profile based on SSID: '%s'", ssid);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003432 if (wpa_command_resp(get_station_ifname(dut), "LIST_NETWORKS",
vamsi krishna52e16f92017-08-29 12:37:34 +05303433 list, sizeof(list)) < 0)
3434 return -1;
3435 pos = strstr(list, ssid);
3436 if (!pos || pos == list || pos[-1] != '\t' || pos[strlen(ssid)] != '\t')
3437 return -1;
3438
3439 while (pos > list && pos[-1] != '\n')
3440 pos--;
3441 dut->infra_network_id = atoi(pos);
3442 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
3443 return 0;
3444}
3445
3446
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303447/**
3448 * enum qca_sta_helper_config_params - This helper enum defines the config
3449 * parameters which can be delivered to sta.
3450 */
3451enum qca_sta_helper_config_params {
3452 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE */
3453 STA_SET_RSNIE,
3454
3455 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_LDPC */
3456 STA_SET_LDPC,
3457
3458 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_TX_STBC */
3459 STA_SET_TX_STBC,
3460
3461 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_RX_STBC */
3462 STA_SET_RX_STBC,
3463
3464 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_TX_MSDU_AGGREGATION */
3465 STA_SET_TX_MSDU,
3466
3467 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_RX_MSDU_AGGREGATION */
3468 STA_SET_RX_MSDU,
Shivani Baranwal2a572842021-09-16 12:27:15 +05303469
3470 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_CHANNEL_WIDTH */
3471 STA_SET_CHAN_WIDTH,
Shivani Baranwal7aa48602021-09-29 10:53:38 +05303472
3473 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_FT_OVER_DS */
3474 STA_SET_FT_DS,
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303475};
3476
3477
3478static int sta_config_params(struct sigma_dut *dut, const char *intf,
3479 enum qca_sta_helper_config_params config_cmd,
3480 int value)
Sunil Dutt44595082018-02-12 19:41:45 +05303481{
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303482#ifdef NL80211_SUPPORT
Sunil Dutt44595082018-02-12 19:41:45 +05303483 struct nl_msg *msg;
3484 int ret;
3485 struct nlattr *params;
3486 int ifindex;
3487
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303488 ifindex = if_nametoindex(intf);
3489 if (ifindex == 0) {
3490 sigma_dut_print(dut, DUT_MSG_ERROR,
3491 "%s: Interface %s does not exist",
3492 __func__, intf);
3493 return -1;
3494 }
3495
Sunil Dutt44595082018-02-12 19:41:45 +05303496 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
3497 NL80211_CMD_VENDOR)) ||
3498 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
3499 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
3500 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
3501 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) ||
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303502 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)))
3503 goto fail;
3504
3505 switch (config_cmd) {
3506 case STA_SET_RSNIE:
3507 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE, value))
3508 goto fail;
3509 break;
3510 case STA_SET_LDPC:
3511 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_LDPC, value))
3512 goto fail;
3513 break;
3514 case STA_SET_TX_STBC:
3515 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TX_STBC, value))
3516 goto fail;
3517 break;
3518 case STA_SET_RX_STBC:
3519 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_RX_STBC, value))
3520 goto fail;
3521 break;
3522 case STA_SET_TX_MSDU:
3523 if (nla_put_u8(msg,
3524 QCA_WLAN_VENDOR_ATTR_CONFIG_TX_MSDU_AGGREGATION,
3525 value))
3526 goto fail;
3527 break;
3528 case STA_SET_RX_MSDU:
3529 if (nla_put_u8(msg,
3530 QCA_WLAN_VENDOR_ATTR_CONFIG_RX_MSDU_AGGREGATION,
3531 value))
3532 goto fail;
3533 break;
Shivani Baranwal2a572842021-09-16 12:27:15 +05303534 case STA_SET_CHAN_WIDTH:
3535 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_CHANNEL_WIDTH,
3536 value))
3537 goto fail;
3538 break;
Shivani Baranwal7aa48602021-09-29 10:53:38 +05303539 case STA_SET_FT_DS:
3540 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_FT_OVER_DS,
3541 value))
3542 goto fail;
3543 break;
Sunil Dutt44595082018-02-12 19:41:45 +05303544 }
3545 nla_nest_end(msg, params);
3546
3547 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
3548 if (ret) {
3549 sigma_dut_print(dut, DUT_MSG_ERROR,
3550 "%s: err in send_and_recv_msgs, ret=%d",
3551 __func__, ret);
3552 return ret;
3553 }
3554
3555 return 0;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303556
3557fail:
3558 sigma_dut_print(dut, DUT_MSG_ERROR,
3559 "%s: err in adding vendor_cmd and vendor_data",
3560 __func__);
3561 nlmsg_free(msg);
Sunil Dutt44595082018-02-12 19:41:45 +05303562#endif /* NL80211_SUPPORT */
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303563 return -1;
3564}
Sunil Dutt44595082018-02-12 19:41:45 +05303565
3566
Veerendranath Jakkam9ceb3b12021-09-10 03:18:17 +05303567void free_dscp_policy_table(struct sigma_dut *dut)
3568{
3569 struct dscp_policy_data *dscp_policy;
3570
3571 while (dut->dscp_policy_table) {
3572 dscp_policy = dut->dscp_policy_table;
3573 dut->dscp_policy_table = dscp_policy->next;
3574 free(dscp_policy);
3575 }
3576}
3577
3578
3579static int delete_nft_table(struct sigma_dut *dut, const char *table,
3580 const char *ip_type)
3581{
3582 int res;
3583 char cmd[200];
3584
3585 res = snprintf(cmd, sizeof(cmd), "nft delete table %s %s_%s", ip_type,
3586 table, ip_type);
3587 if (snprintf_error(sizeof(cmd), res)) {
3588 sigma_dut_print(dut, DUT_MSG_ERROR,
3589 "Failed to create delete table command");
3590 return -1;
3591 }
3592
3593 if (system(cmd) != 0) {
3594 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run %s", cmd);
3595 return -1;
3596 }
3597
3598 return 0;
3599}
3600
3601
3602static int remove_nft_rule(struct sigma_dut *dut, int policy_id,
3603 enum ip_version ip_ver)
3604{
3605 int res;
3606 char table[50];
3607
3608 res = snprintf(table, sizeof(table), "wifi_%s_dscp_policy_%d",
3609 dut->station_ifname, policy_id);
3610 if (snprintf_error(sizeof(table), res)) {
3611 sigma_dut_print(dut, DUT_MSG_INFO,
3612 "Failed to create table name for policy %d",
3613 policy_id);
3614 return -1;
3615 }
3616
3617
3618 if (ip_ver == IPV6)
3619 return delete_nft_table(dut, table, "ip6");
3620 else
3621 return delete_nft_table(dut, table, "ip");
3622}
3623
3624
3625static int create_nft_table(struct sigma_dut *dut, int policy_id,
3626 const char *table_name, enum ip_version ip_ver)
3627{
3628 char cmd[200];
3629 int res;
3630
3631 res = snprintf(cmd, sizeof(cmd), "nft add table %s %s",
3632 ip_ver == IPV6 ? "ip6" : "ip", table_name);
3633 if (snprintf_error(sizeof(cmd), res)) {
3634 sigma_dut_print(dut, DUT_MSG_INFO,
3635 "Failed to add rule to create table for policy id %d",
3636 policy_id);
3637 return -1;
3638 }
3639
3640 if (system(cmd) != 0) {
3641 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run %s", cmd);
3642 return -1;
3643 }
3644
3645 res = snprintf(cmd, sizeof(cmd),
3646 "nft add chain %s %s OUTPUT { type filter hook output priority 0 \\; }",
3647 ip_ver == IPV6 ? "ip6" : "ip", table_name);
3648 if (snprintf_error(sizeof(cmd), res)) {
3649 sigma_dut_print(dut, DUT_MSG_INFO,
3650 "Failed to add rule to create chain for table = %s",
3651 table_name);
3652 return -1;
3653 }
3654
3655 if (system(cmd) != 0) {
3656 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run %s", cmd);
3657 return -1;
3658 }
3659
3660 return 0;
3661}
3662
3663
3664static char * protocol_to_str(int proto)
3665{
3666 switch (proto) {
3667 case 6:
3668 return "tcp";
3669 case 17:
3670 return "udp";
3671 case 50:
3672 return "esp";
3673 default:
3674 return "unknown";
3675 }
3676}
3677
3678
3679static int remove_dscp_policy(struct sigma_dut *dut, u8 policy_id)
3680{
3681 struct dscp_policy_data *dscp_policy = dut->dscp_policy_table;
3682 struct dscp_policy_data *prev = NULL;
3683
3684 while (dscp_policy) {
3685 if (dscp_policy->policy_id == policy_id)
3686 break;
3687
3688 prev = dscp_policy;
3689 dscp_policy = dscp_policy->next;
3690 }
3691
3692 /*
3693 * Consider remove request for a policy id which does not exist as
3694 * success.
3695 */
3696 if (!dscp_policy)
3697 return 0;
3698
3699 if (strlen(dscp_policy->domain_name) == 0 &&
3700 remove_nft_rule(dut, policy_id, dscp_policy->ip_version))
3701 return -1;
3702
3703 if (prev)
3704 prev->next = dscp_policy->next;
3705 else
3706 dut->dscp_policy_table = dscp_policy->next;
3707
3708 free(dscp_policy);
3709 return 0;
3710}
3711
3712
3713static int add_nft_rule(struct sigma_dut *dut,
3714 struct dscp_policy_data *dscp_policy)
3715{
3716 char nft_cmd[1000], ip[4], table_name[100];
3717 char *pos;
3718 int ret, len, policy_id = dscp_policy->policy_id;
3719 enum ip_version ip_ver = dscp_policy->ip_version;
3720
3721 if (ip_ver == IPV6)
3722 strlcpy(ip, "ip6", sizeof(ip));
3723 else
3724 strlcpy(ip, "ip", sizeof(ip));
3725
3726 ret = snprintf(table_name, sizeof(table_name),
3727 "wifi_%s_dscp_policy_%d_%s",
3728 dut->station_ifname, policy_id, ip);
3729 if (snprintf_error(sizeof(table_name), ret))
3730 return -1;
3731
3732 if (create_nft_table(dut, policy_id, table_name, ip_ver)) {
3733 sigma_dut_print(dut, DUT_MSG_INFO,
3734 "Failed to create nft table");
3735 return -1;
3736 }
3737
3738 pos = nft_cmd;
3739 len = sizeof(nft_cmd);
3740
3741 ret = snprintf(pos, len,
3742 "nft add rule %s %s OUTPUT oifname \"%s\"",
3743 ip, table_name, dut->station_ifname);
3744 if (snprintf_error(len, ret)) {
3745 sigma_dut_print(dut, DUT_MSG_INFO,
3746 "Failed to create nft cmd %s", nft_cmd);
3747 return -1;
3748 }
3749
3750 pos += ret;
3751 len -= ret;
3752
3753 if (strlen(dscp_policy->src_ip)) {
3754 ret = snprintf(pos, len, " %s saddr %s", ip,
3755 dscp_policy->src_ip);
3756 if (snprintf_error(len, ret))
3757 return -1;
3758
3759 pos += ret;
3760 len -= ret;
3761 }
3762
3763 if (strlen(dscp_policy->dst_ip)) {
3764 ret = snprintf(pos, len, " %s daddr %s", ip,
3765 dscp_policy->dst_ip);
3766 if (snprintf_error(len, ret))
3767 return -1;
3768
3769 pos += ret;
3770 len -= ret;
3771 }
3772
3773 if (dscp_policy->src_port) {
3774 ret = snprintf(pos, len, " %s sport %d",
3775 protocol_to_str(dscp_policy->protocol),
3776 dscp_policy->src_port);
3777 if (snprintf_error(len, ret))
3778 return -1;
3779
3780 pos += ret;
3781 len -= ret;
3782 }
3783
3784 if (dscp_policy->dst_port) {
3785 ret = snprintf(pos, len, " %s dport %d",
3786 protocol_to_str(dscp_policy->protocol),
3787 dscp_policy->dst_port);
3788 if (snprintf_error(len, ret))
3789 return -1;
3790
3791 pos += ret;
3792 len -= ret;
3793 }
3794
3795 if (dscp_policy->start_port && dscp_policy->end_port) {
3796 ret = snprintf(pos, len, " %s dport %d-%d",
3797 protocol_to_str(dscp_policy->protocol),
3798 dscp_policy->start_port,
3799 dscp_policy->end_port);
3800 if (snprintf_error(len, ret))
3801 return -1;
3802
3803 pos += ret;
3804 len -= ret;
3805 }
3806
3807 ret = snprintf(pos, len, " counter %s dscp set 0x%0x", ip,
3808 dscp_policy->dscp);
3809 if (snprintf_error(len, ret))
3810 return -1;
3811
3812 ret = system(nft_cmd);
3813 sigma_dut_print(dut, DUT_MSG_INFO, "nft rule: %s err: %d",
3814 nft_cmd, ret);
3815
3816 return ret;
3817}
3818
3819
3820static void clear_all_dscp_policies(struct sigma_dut *dut)
3821{
3822 free_dscp_policy_table(dut);
3823
3824 if (system("nft flush ruleset") != 0)
3825 sigma_dut_print(dut, DUT_MSG_ERROR,
3826 "Failed to flush DSCP policy");
3827}
3828
3829
3830static int send_dscp_response(struct sigma_dut *dut,
3831 struct dscp_policy_status *status_list,
3832 int num_status)
3833{
3834 int rem_len, ret;
3835 char buf[200] = "", *pos, cmd[256];
3836
3837 pos = buf;
3838 rem_len = sizeof(buf);
3839
3840 ret = snprintf(pos, rem_len, " solicited");
3841 if (snprintf_error(rem_len, ret)) {
3842 sigma_dut_print(dut, DUT_MSG_ERROR,
3843 "Failed to write DSCP policy response command");
3844 return -1;
3845 }
3846 pos += ret;
3847 rem_len -= ret;
3848
3849 for (int i = 0; i < num_status; i++) {
3850 ret = snprintf(pos, rem_len, " policy_id=%d status=%d",
3851 status_list[i].id, status_list[i].status);
3852 if (snprintf_error(rem_len, ret)) {
3853 sigma_dut_print(dut, DUT_MSG_ERROR,
3854 "Failed to wite DSCP policy response");
3855 return -1;
3856 }
3857
3858 pos += ret;
3859 rem_len -= ret;
3860 }
3861
3862 ret = snprintf(cmd, sizeof(cmd), "DSCP_RESP%s", buf);
3863 if (snprintf_error(sizeof(cmd), ret)) {
3864 sigma_dut_print(dut, DUT_MSG_ERROR,
3865 "Failed to create DSCP Policy Response frame");
3866 return -1;
3867 }
3868
3869 if (wpa_command(dut->station_ifname, cmd) != 0) {
3870 sigma_dut_print(dut, DUT_MSG_ERROR,
3871 "Failed to send DSCP Policy Response frame");
3872 return -1;
3873 }
3874
3875 sigma_dut_print(dut, DUT_MSG_DEBUG,
3876 "DSCP Policy Response frame sent: %s", cmd);
3877 return 0;
3878}
3879
3880
3881#ifdef ANDROID
3882static void thread_cancel_handler(int sig)
3883{
3884 if (sig == SIGUSR1)
3885 pthread_exit(0);
3886}
3887#endif /* ANDROID */
3888
3889
3890static void * mon_dscp_policies(void *ptr)
3891{
3892 struct sigma_dut *dut = ptr;
3893 int ret, policy_id;
3894 struct wpa_ctrl *ctrl;
3895 char buf[4096], *pos, *end;
3896 struct dscp_policy_data *policy = NULL, *policy_table;
3897 struct dscp_policy_status status_list[10];
3898 int num_status = 0;
3899 const char *events[] = {
3900 "CTRL-EVENT-DISCONNECTED",
3901 "CTRL-EVENT-DSCP-POLICY",
3902 NULL
3903 };
3904#ifdef ANDROID
3905 struct sigaction actions;
3906#endif /* ANDROID */
3907
3908 ctrl = open_wpa_mon(get_station_ifname(dut));
3909 if (!ctrl) {
3910 sigma_dut_print(dut, DUT_MSG_ERROR,
3911 "Failed to open wpa_supplicant monitor connection");
3912 return NULL;
3913 }
3914
3915#ifdef ANDROID
3916 memset(&actions, 0, sizeof(actions));
3917 sigemptyset(&actions.sa_mask);
3918 actions.sa_flags = 0;
3919 actions.sa_handler = thread_cancel_handler;
3920 if (sigaction(SIGUSR1, &actions, NULL) == -1) {
3921 sigma_dut_print(dut, DUT_MSG_ERROR,
3922 "Failed to register exit handler for %s",
3923 __func__);
3924 wpa_ctrl_detach(ctrl);
3925 wpa_ctrl_close(ctrl);
3926 return NULL;
3927 }
3928#endif /* ANDROID */
3929
3930 while (1) {
3931 ret = get_wpa_cli_events_timeout(dut, ctrl, events,
3932 buf, sizeof(buf), 0);
3933
3934 if (ret || strlen(buf) == 0) {
3935 sigma_dut_print(dut, DUT_MSG_INFO,
3936 "Did not receive any event");
3937 continue;
3938 }
3939
3940 if (strstr(buf, "CTRL-EVENT-DISCONNECTED")) {
3941 clear_all_dscp_policies(dut);
3942 break;
3943 }
3944
3945 if (strstr(buf, "request_start")) {
3946 num_status = 0;
3947 if (strstr(buf, "clear_all"))
3948 clear_all_dscp_policies(dut);
3949 continue;
3950 }
3951
3952 if (strstr(buf, "request_end")) {
3953 send_dscp_response(dut, status_list, num_status);
3954 continue;
3955 }
3956
3957 if (!strstr(buf, "add") && !strstr(buf, "remove") &&
3958 !strstr(buf, "reject")) {
3959 sigma_dut_print(dut, DUT_MSG_DEBUG, "Ignore event: %s",
3960 buf);
3961 continue;
3962 }
3963
3964 pos = strstr(buf, "policy_id=");
3965 if (!pos) {
3966 sigma_dut_print(dut, DUT_MSG_INFO,
3967 "Policy id not present");
3968 continue;
3969 }
3970 policy_id = atoi(pos + 10);
3971
3972 if (num_status >= ARRAY_SIZE(status_list)) {
3973 sigma_dut_print(dut, DUT_MSG_INFO,
3974 "Max policies allowed per DSCP request reached. Drop policy id %d request",
3975 policy_id);
3976 continue;
3977 }
3978 status_list[num_status].id = policy_id;
3979
Veerendranath Jakkama16cdc82021-09-12 16:44:22 +05303980 if (dut->reject_dscp_policies) {
3981 status_list[num_status].status =
3982 dut->dscp_reject_resp_code;
3983 num_status++;
3984 continue;
3985 }
3986
Veerendranath Jakkam9ceb3b12021-09-10 03:18:17 +05303987 if (strstr(buf, "reject"))
3988 goto reject;
3989
3990 /*
3991 * In case of "add" also if policy with same policy id exist it
3992 * shall be removed. So always call remove_dscp_policy().
3993 */
3994 if (remove_dscp_policy(dut, policy_id))
3995 goto reject;
3996
3997 if (strstr(buf, "remove"))
3998 goto success;
3999
4000 policy = malloc(sizeof(*policy));
4001 if (!policy)
4002 goto reject;
4003
4004 memset(policy, 0, sizeof(*policy));
4005
4006 policy->policy_id = policy_id;
4007
4008 pos = strstr(buf, "dscp=");
4009 if (!pos) {
4010 sigma_dut_print(dut, DUT_MSG_ERROR,
4011 "DSCP info not present");
4012 goto reject;
4013 }
4014 policy->dscp = atoi(pos + 5);
4015
4016 pos = strstr(buf, "ip_version=");
4017 if (!pos) {
4018 sigma_dut_print(dut, DUT_MSG_ERROR,
4019 "IP version info not present");
4020 goto reject;
4021 }
4022 policy->ip_version = atoi(pos + 11);
4023
4024 pos = strstr(buf, "domain_name=");
4025 if (pos) {
4026 pos += 12;
4027 end = strchr(pos, ' ');
4028 if (!end)
4029 end = pos + strlen(pos);
4030
4031 if (end - pos >= (int) sizeof(policy->domain_name))
4032 goto reject;
4033
4034 memcpy(policy->domain_name, pos, end - pos);
4035 policy->domain_name[end - pos] = '\0';
4036 }
4037
4038 pos = strstr(buf, "start_port=");
4039 if (pos) {
4040 pos += 11;
4041 policy->start_port = atoi(pos);
4042 }
4043
4044 pos = strstr(buf, "end_port=");
4045 if (pos) {
4046 pos += 9;
4047 policy->end_port = atoi(pos);
4048 }
4049
4050 pos = strstr(buf, "src_ip=");
4051 if (pos) {
4052 pos += 7;
4053 end = strchr(pos, ' ');
4054 if (!end)
4055 end = pos + strlen(pos);
4056
4057 if (end - pos >= (int) sizeof(policy->src_ip))
4058 goto reject;
4059
4060 memcpy(policy->src_ip, pos, end - pos);
4061 policy->src_ip[end - pos] = '\0';
4062 }
4063
4064 pos = strstr(buf, "dst_ip=");
4065 if (pos) {
4066 pos += 7;
4067 end = strchr(pos, ' ');
4068 if (!end)
4069 end = pos + strlen(pos);
4070
4071 if (end - pos >= (int) sizeof(policy->dst_ip))
4072 goto reject;
4073
4074 memcpy(policy->dst_ip, pos, end - pos);
4075 policy->dst_ip[end - pos] = '\0';
4076 }
4077
4078 pos = strstr(buf, "src_port=");
4079 if (pos) {
4080 pos += 9;
4081 policy->src_port = atoi(pos);
4082 }
4083
4084 pos = strstr(buf, "dst_port=");
4085 if (pos) {
4086 pos += 9;
4087 policy->dst_port = atoi(pos);
4088 }
4089
4090 pos = strstr(buf, "protocol=");
4091 if (pos) {
4092 pos += 9;
4093 policy->protocol = atoi(pos);
4094 }
4095
4096 /*
4097 * Skip adding nft rules for doman name policies.
4098 * Domain name rules are applied in sigma_dut itself.
4099 */
4100 if (!strlen(policy->domain_name) && add_nft_rule(dut, policy))
4101 goto reject;
4102
4103 if (dut->dscp_policy_table) {
4104 policy_table = dut->dscp_policy_table;
4105 while (policy_table->next != NULL)
4106 policy_table = policy_table->next;
4107
4108 policy_table->next = policy;
4109 } else
4110 dut->dscp_policy_table = policy;
4111
4112success:
4113 status_list[num_status].status = DSCP_POLICY_SUCCESS;
4114 num_status++;
4115 policy = NULL;
4116 continue;
4117reject:
4118 status_list[num_status].status = DSCP_POLICY_REJECT;
4119 num_status++;
4120 free(policy);
4121 policy = NULL;
4122 }
4123
4124 free_dscp_policy_table(dut);
4125 wpa_ctrl_detach(ctrl);
4126 wpa_ctrl_close(ctrl);
4127
4128 pthread_exit(0);
4129 return NULL;
4130}
4131
4132
4133static void start_dscp_policy_mon_thread(struct sigma_dut *dut)
4134{
4135 /* Create event thread */
4136 pthread_create(&dut->dscp_policy_mon_thread, NULL, &mon_dscp_policies,
4137 (void *) dut);
4138}
4139
4140
4141void stop_dscp_policy_mon_thread(struct sigma_dut *dut)
4142{
4143 if (dut->dscp_policy_mon_thread) {
4144#ifdef ANDROID
4145 /* pthread_cancel not supported in Android */
4146 pthread_kill(dut->dscp_policy_mon_thread, SIGUSR1);
4147#else /* ANDROID */
4148 pthread_cancel(dut->dscp_policy_mon_thread);
4149#endif /* ANDROID */
4150 dut->dscp_policy_mon_thread = 0;
4151 }
4152}
4153
4154
Jouni Malinenf7222712019-06-13 01:50:21 +03004155static enum sigma_cmd_result cmd_sta_associate(struct sigma_dut *dut,
4156 struct sigma_conn *conn,
4157 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004158{
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304159#ifdef NL80211_SUPPORT
4160 const char *intf = get_param(cmd, "Interface");
4161#endif /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004162 const char *ssid = get_param(cmd, "ssid");
4163 const char *wps_param = get_param(cmd, "WPS");
4164 const char *bssid = get_param(cmd, "bssid");
Jouni Malinen46a19b62017-06-23 14:31:27 +03004165 const char *chan = get_param(cmd, "channel");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02004166 const char *network_mode = get_param(cmd, "network_mode");
Veerendranath Jakkama082e342020-05-16 00:19:21 +05304167 const char *ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004168 int wps = 0;
Jouni Malinen3c367e82017-06-23 17:01:47 +03004169 char buf[1000], extra[50];
Jouni Malinen134fe3c2019-06-12 04:16:49 +03004170 int e;
4171 enum sigma_cmd_result ret = SUCCESS_SEND_STATUS;
4172 struct wpa_ctrl *ctrl = NULL;
4173 int num_network_not_found = 0;
4174 int num_disconnected = 0;
4175 int tod = -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004176
4177 if (ssid == NULL)
4178 return -1;
4179
Jouni Malinen37d5c692019-08-19 16:56:55 +03004180 dut->server_cert_tod = 0;
4181
Jouni Malinen3c367e82017-06-23 17:01:47 +03004182 if (dut->rsne_override) {
Sunil Dutt44595082018-02-12 19:41:45 +05304183#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004184 if (get_driver_type(dut) == DRIVER_WCN) {
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304185 sta_config_params(dut, intf, STA_SET_RSNIE, 1);
Sunil Dutt44595082018-02-12 19:41:45 +05304186 dut->config_rsnie = 1;
4187 }
4188#endif /* NL80211_SUPPORT */
Jouni Malinen3c367e82017-06-23 17:01:47 +03004189 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
4190 dut->rsne_override);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004191 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinen3c367e82017-06-23 17:01:47 +03004192 send_resp(dut, conn, SIGMA_ERROR,
4193 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
4194 return 0;
4195 }
4196 }
4197
Jouni Malinen68143132017-09-02 02:34:08 +03004198 if (dut->sae_commit_override) {
4199 snprintf(buf, sizeof(buf), "SET sae_commit_override %s",
4200 dut->sae_commit_override);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004201 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinen68143132017-09-02 02:34:08 +03004202 send_resp(dut, conn, SIGMA_ERROR,
4203 "ErrorCode,Failed to set SAE commit override");
4204 return 0;
4205 }
4206 }
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304207#ifdef ANDROID
4208 if (dut->fils_hlp)
4209 process_fils_hlp(dut);
4210#endif /* ANDROID */
Jouni Malinen68143132017-09-02 02:34:08 +03004211
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004212 if (wps_param &&
4213 (strcmp(wps_param, "1") == 0 || strcasecmp(wps_param, "On") == 0))
4214 wps = 1;
4215
4216 if (wps) {
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02004217 if (dut->program == PROGRAM_60GHZ && network_mode &&
4218 strcasecmp(network_mode, "PBSS") == 0 &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004219 set_network(get_station_ifname(dut), dut->infra_network_id,
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02004220 "pbss", "1") < 0)
4221 return -2;
4222
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004223 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
4224 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,WPS "
4225 "parameters not yet set");
4226 return 0;
4227 }
4228 if (dut->wps_method == WFA_CS_WPS_PBC) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004229 if (wpa_command(get_station_ifname(dut), "WPS_PBC") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004230 return -2;
4231 } else {
4232 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
4233 dut->wps_pin);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004234 if (wpa_command(get_station_ifname(dut), buf) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004235 return -2;
4236 }
4237 } else {
vamsi krishna52e16f92017-08-29 12:37:34 +05304238 if (strcmp(ssid, dut->infra_ssid) == 0) {
4239 sigma_dut_print(dut, DUT_MSG_DEBUG,
4240 "sta_associate for the most recently added network");
4241 } else if (find_network(dut, ssid) < 0) {
4242 sigma_dut_print(dut, DUT_MSG_DEBUG,
4243 "sta_associate for a previously stored network profile");
4244 send_resp(dut, conn, SIGMA_ERROR,
4245 "ErrorCode,Profile not found");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004246 return 0;
4247 }
4248
4249 if (bssid &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004250 set_network(get_station_ifname(dut), dut->infra_network_id,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004251 "bssid", bssid) < 0) {
4252 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
4253 "Invalid bssid argument");
4254 return 0;
4255 }
4256
Veerendranath Jakkama082e342020-05-16 00:19:21 +05304257 if ((dut->program == PROGRAM_WPA3 &&
4258 dut->sta_associate_wait_connect) ||
4259 dut->program == PROGRAM_QM) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004260 ctrl = open_wpa_mon(get_station_ifname(dut));
Jouni Malinen134fe3c2019-06-12 04:16:49 +03004261 if (!ctrl)
4262 return ERROR_SEND_STATUS;
4263 }
4264
Jouni Malinen46a19b62017-06-23 14:31:27 +03004265 extra[0] = '\0';
4266 if (chan)
4267 snprintf(extra, sizeof(extra), " freq=%u",
Alexei Avshalom Lazar093569f2018-11-13 14:08:17 +02004268 channel_to_freq(dut, atoi(chan)));
Jouni Malinen46a19b62017-06-23 14:31:27 +03004269 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d%s",
4270 dut->infra_network_id, extra);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004271 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004272 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to select "
4273 "network id %d on %s",
4274 dut->infra_network_id,
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004275 get_station_ifname(dut));
Jouni Malinen134fe3c2019-06-12 04:16:49 +03004276 ret = ERROR_SEND_STATUS;
4277 goto done;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004278 }
4279 }
4280
Jouni Malinen134fe3c2019-06-12 04:16:49 +03004281 if (!ctrl)
4282 return SUCCESS_SEND_STATUS;
4283
4284 /* Wait for connection result to be able to store server certificate
4285 * hash for trust root override testing
4286 * (dev_exec_action,ServerCertTrust). */
4287
4288 for (e = 0; e < 20; e++) {
4289 const char *events[] = {
4290 "CTRL-EVENT-EAP-PEER-CERT",
4291 "CTRL-EVENT-EAP-TLS-CERT-ERROR",
4292 "CTRL-EVENT-DISCONNECTED",
4293 "CTRL-EVENT-CONNECTED",
4294 "CTRL-EVENT-NETWORK-NOT-FOUND",
4295 NULL
4296 };
4297 char buf[1024];
4298 int res;
4299
4300 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
4301 if (res < 0) {
Jouni Malinenf1f16642019-11-15 21:19:04 +02004302 send_resp(dut, conn, SIGMA_COMPLETE,
4303 "Result,Association did not complete");
Jouni Malinen134fe3c2019-06-12 04:16:49 +03004304 ret = STATUS_SENT_ERROR;
4305 break;
4306 }
4307 sigma_dut_print(dut, DUT_MSG_DEBUG, "Connection event: %s",
4308 buf);
4309
4310 if (strstr(buf, "CTRL-EVENT-EAP-PEER-CERT") &&
4311 strstr(buf, " depth=0")) {
4312 char *pos = strstr(buf, " hash=");
4313
4314 if (pos) {
4315 char *end;
4316
Jouni Malinen34b19cb2019-08-16 16:37:17 +03004317 if (strstr(buf, " tod=1"))
4318 tod = 1;
4319 else if (strstr(buf, " tod=2"))
4320 tod = 2;
4321 else
4322 tod = 0;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03004323 sigma_dut_print(dut, DUT_MSG_DEBUG,
4324 "Server certificate TOD policy: %d",
4325 tod);
Jouni Malinen37d5c692019-08-19 16:56:55 +03004326 dut->server_cert_tod = tod;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03004327
4328 pos += 6;
4329 end = strchr(pos, ' ');
4330 if (end)
4331 *end = '\0';
4332 strlcpy(dut->server_cert_hash, pos,
4333 sizeof(dut->server_cert_hash));
4334 sigma_dut_print(dut, DUT_MSG_DEBUG,
4335 "Server certificate hash: %s",
4336 dut->server_cert_hash);
4337 }
4338 }
4339
4340 if (strstr(buf, "CTRL-EVENT-EAP-TLS-CERT-ERROR")) {
4341 send_resp(dut, conn, SIGMA_COMPLETE,
4342 "Result,TLS server certificate validation failed");
4343 ret = STATUS_SENT_ERROR;
4344 break;
4345 }
4346
4347 if (strstr(buf, "CTRL-EVENT-NETWORK-NOT-FOUND")) {
4348 num_network_not_found++;
4349
4350 if (num_network_not_found > 2) {
4351 send_resp(dut, conn, SIGMA_COMPLETE,
4352 "Result,Network not found");
4353 ret = STATUS_SENT_ERROR;
4354 break;
4355 }
4356 }
4357
4358 if (strstr(buf, "CTRL-EVENT-DISCONNECTED")) {
4359 num_disconnected++;
4360
4361 if (num_disconnected > 2) {
4362 send_resp(dut, conn, SIGMA_COMPLETE,
4363 "Result,Connection failed");
4364 ret = STATUS_SENT_ERROR;
4365 break;
4366 }
4367 }
4368
4369 if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
4370 if (tod >= 0) {
4371 sigma_dut_print(dut, DUT_MSG_DEBUG,
4372 "Network profile TOD policy update: %d -> %d",
4373 dut->sta_tod_policy, tod);
4374 dut->sta_tod_policy = tod;
4375 }
Veerendranath Jakkama082e342020-05-16 00:19:21 +05304376 if (dut->program == PROGRAM_QM) {
4377 unsigned char iface_mac_addr[ETH_ALEN];
4378 char ipv6[100];
4379
4380 if (get_hwaddr(ifname, iface_mac_addr) < 0) {
4381 sigma_dut_print(dut, DUT_MSG_ERROR,
4382 "%s: get_hwaddr %s failed",
4383 __func__, ifname);
4384 ret = ERROR_SEND_STATUS;
4385 break;
4386 }
4387
4388 convert_mac_addr_to_ipv6_lladdr(iface_mac_addr,
4389 ipv6,
4390 sizeof(ipv6));
4391
4392 if (set_ipv6_addr(dut, ipv6, "64", ifname) !=
4393 0) {
4394 ret = ERROR_SEND_STATUS;
4395 break;
4396 }
Veerendranath Jakkam9ceb3b12021-09-10 03:18:17 +05304397 start_dscp_policy_mon_thread(dut);
Veerendranath Jakkama082e342020-05-16 00:19:21 +05304398 }
Jouni Malinen134fe3c2019-06-12 04:16:49 +03004399 break;
4400 }
4401 }
4402done:
4403 if (ctrl) {
4404 wpa_ctrl_detach(ctrl);
4405 wpa_ctrl_close(ctrl);
4406 }
4407 return ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004408}
4409
4410
4411static int run_hs20_osu(struct sigma_dut *dut, const char *params)
4412{
4413 char buf[500], cmd[200];
4414 int res;
4415
4416 /* Use hs20-osu-client file at the current dir, if found; otherwise use
4417 * default path */
4418 res = snprintf(cmd, sizeof(cmd),
4419 "%s -w \"%s\" -r hs20-osu-client.res %s%s -dddKt -f Logs/hs20-osu-client.txt",
4420 file_exists("./hs20-osu-client") ?
4421 "./hs20-osu-client" : "hs20-osu-client",
4422 sigma_wpas_ctrl,
4423 dut->summary_log ? "-s " : "",
4424 dut->summary_log ? dut->summary_log : "");
4425 if (res < 0 || res >= (int) sizeof(cmd))
4426 return -1;
4427
4428 res = snprintf(buf, sizeof(buf), "%s %s", cmd, params);
4429 if (res < 0 || res >= (int) sizeof(buf))
4430 return -1;
4431 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
4432
4433 if (system(buf) != 0) {
4434 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run: %s", buf);
4435 return -1;
4436 }
4437 sigma_dut_print(dut, DUT_MSG_DEBUG,
4438 "Completed hs20-osu-client operation");
4439
4440 return 0;
4441}
4442
4443
4444static int download_ppsmo(struct sigma_dut *dut,
4445 struct sigma_conn *conn,
4446 const char *intf,
4447 struct sigma_cmd *cmd)
4448{
4449 const char *name, *path, *val;
4450 char url[500], buf[600], fbuf[100];
4451 char *fqdn = NULL;
4452
4453 name = get_param(cmd, "FileName");
4454 path = get_param(cmd, "FilePath");
4455 if (name == NULL || path == NULL)
4456 return -1;
4457
4458 if (strcasecmp(path, "VendorSpecific") == 0) {
4459 snprintf(url, sizeof(url), "PPS/%s", name);
4460 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured PPS MO "
4461 "from the device (%s)", url);
4462 if (!file_exists(url)) {
4463 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
4464 "PPS MO file does not exist");
4465 return 0;
4466 }
4467 snprintf(buf, sizeof(buf), "cp %s pps-tnds.xml", url);
4468 if (system(buf) != 0) {
4469 send_resp(dut, conn, SIGMA_ERROR,
4470 "errorCode,Failed to copy PPS MO");
4471 return 0;
4472 }
4473 } else if (strncasecmp(path, "http:", 5) != 0 &&
4474 strncasecmp(path, "https:", 6) != 0) {
4475 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
4476 "Unsupported FilePath value");
4477 return 0;
4478 } else {
4479 snprintf(url, sizeof(url), "%s/%s", path, name);
4480 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading PPS MO from %s",
4481 url);
4482 snprintf(buf, sizeof(buf), "wget -T 10 -t 3 -O pps-tnds.xml '%s'", url);
4483 remove("pps-tnds.xml");
4484 if (system(buf) != 0) {
4485 send_resp(dut, conn, SIGMA_ERROR,
4486 "errorCode,Failed to download PPS MO");
4487 return 0;
4488 }
4489 }
4490
4491 if (run_hs20_osu(dut, "from_tnds pps-tnds.xml pps.xml") < 0) {
4492 send_resp(dut, conn, SIGMA_ERROR,
4493 "errorCode,Failed to parse downloaded PPSMO");
4494 return 0;
4495 }
4496 unlink("pps-tnds.xml");
4497
4498 val = get_param(cmd, "managementTreeURI");
4499 if (val) {
4500 const char *pos, *end;
4501 sigma_dut_print(dut, DUT_MSG_DEBUG, "managementTreeURI: %s",
4502 val);
4503 if (strncmp(val, "./Wi-Fi/", 8) != 0) {
4504 send_resp(dut, conn, SIGMA_ERROR,
4505 "errorCode,Invalid managementTreeURI prefix");
4506 return 0;
4507 }
4508 pos = val + 8;
4509 end = strchr(pos, '/');
4510 if (end == NULL ||
4511 strcmp(end, "/PerProviderSubscription") != 0) {
4512 send_resp(dut, conn, SIGMA_ERROR,
4513 "errorCode,Invalid managementTreeURI postfix");
4514 return 0;
4515 }
4516 if (end - pos >= (int) sizeof(fbuf)) {
4517 send_resp(dut, conn, SIGMA_ERROR,
4518 "errorCode,Too long FQDN in managementTreeURI");
4519 return 0;
4520 }
4521 memcpy(fbuf, pos, end - pos);
4522 fbuf[end - pos] = '\0';
4523 fqdn = fbuf;
4524 sigma_dut_print(dut, DUT_MSG_INFO,
4525 "FQDN from managementTreeURI: %s", fqdn);
4526 } else if (run_hs20_osu(dut, "get_fqdn pps.xml") == 0) {
4527 FILE *f = fopen("pps-fqdn", "r");
4528 if (f) {
4529 if (fgets(fbuf, sizeof(fbuf), f)) {
4530 fbuf[sizeof(fbuf) - 1] = '\0';
4531 fqdn = fbuf;
4532 sigma_dut_print(dut, DUT_MSG_DEBUG,
4533 "Use FQDN %s", fqdn);
4534 }
4535 fclose(f);
4536 }
4537 }
4538
4539 if (fqdn == NULL) {
4540 send_resp(dut, conn, SIGMA_ERROR,
4541 "errorCode,No FQDN specified");
4542 return 0;
4543 }
4544
4545 mkdir("SP", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
4546 snprintf(buf, sizeof(buf), "SP/%s", fqdn);
4547 mkdir(buf, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
4548
4549 snprintf(buf, sizeof(buf), "SP/%s/pps.xml", fqdn);
4550 if (rename("pps.xml", buf) < 0) {
4551 send_resp(dut, conn, SIGMA_ERROR,
4552 "errorCode,Could not move PPS MO");
4553 return 0;
4554 }
4555
4556 if (strcasecmp(path, "VendorSpecific") == 0) {
4557 snprintf(buf, sizeof(buf), "cp Certs/ca.pem SP/%s/ca.pem",
4558 fqdn);
4559 if (system(buf)) {
4560 send_resp(dut, conn, SIGMA_ERROR,
4561 "errorCode,Failed to copy OSU CA cert");
4562 return 0;
4563 }
4564
4565 snprintf(buf, sizeof(buf),
4566 "cp Certs/aaa-ca.pem SP/%s/aaa-ca.pem",
4567 fqdn);
4568 if (system(buf)) {
4569 send_resp(dut, conn, SIGMA_ERROR,
4570 "errorCode,Failed to copy AAA CA cert");
4571 return 0;
4572 }
4573 } else {
4574 snprintf(buf, sizeof(buf),
4575 "dl_osu_ca SP/%s/pps.xml SP/%s/ca.pem",
4576 fqdn, fqdn);
4577 if (run_hs20_osu(dut, buf) < 0) {
4578 send_resp(dut, conn, SIGMA_ERROR,
4579 "errorCode,Failed to download OSU CA cert");
4580 return 0;
4581 }
4582
4583 snprintf(buf, sizeof(buf),
4584 "dl_aaa_ca SP/%s/pps.xml SP/%s/aaa-ca.pem",
4585 fqdn, fqdn);
4586 if (run_hs20_osu(dut, buf) < 0) {
4587 sigma_dut_print(dut, DUT_MSG_INFO,
4588 "Failed to download AAA CA cert");
4589 }
4590 }
4591
4592 if (file_exists("next-client-cert.pem")) {
4593 snprintf(buf, sizeof(buf), "SP/%s/client-cert.pem", fqdn);
4594 if (rename("next-client-cert.pem", buf) < 0) {
4595 send_resp(dut, conn, SIGMA_ERROR,
4596 "errorCode,Could not move client certificate");
4597 return 0;
4598 }
4599 }
4600
4601 if (file_exists("next-client-key.pem")) {
4602 snprintf(buf, sizeof(buf), "SP/%s/client-key.pem", fqdn);
4603 if (rename("next-client-key.pem", buf) < 0) {
4604 send_resp(dut, conn, SIGMA_ERROR,
4605 "errorCode,Could not move client key");
4606 return 0;
4607 }
4608 }
4609
4610 snprintf(buf, sizeof(buf), "set_pps SP/%s/pps.xml", fqdn);
4611 if (run_hs20_osu(dut, buf) < 0) {
4612 send_resp(dut, conn, SIGMA_ERROR,
4613 "errorCode,Failed to configure credential from "
4614 "PPSMO");
4615 return 0;
4616 }
4617
4618 return 1;
4619}
4620
4621
4622static int download_cert(struct sigma_dut *dut,
4623 struct sigma_conn *conn,
4624 const char *intf,
4625 struct sigma_cmd *cmd)
4626{
4627 const char *name, *path;
4628 char url[500], buf[600];
4629
4630 name = get_param(cmd, "FileName");
4631 path = get_param(cmd, "FilePath");
4632 if (name == NULL || path == NULL)
4633 return -1;
4634
4635 if (strcasecmp(path, "VendorSpecific") == 0) {
4636 snprintf(url, sizeof(url), "Certs/%s-cert.pem", name);
4637 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
4638 "certificate from the device (%s)", url);
4639 if (!file_exists(url)) {
4640 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
4641 "certificate file does not exist");
4642 return 0;
4643 }
4644 snprintf(buf, sizeof(buf), "cp %s next-client-cert.pem", url);
4645 if (system(buf) != 0) {
4646 send_resp(dut, conn, SIGMA_ERROR,
4647 "errorCode,Failed to copy client "
4648 "certificate");
4649 return 0;
4650 }
4651
4652 snprintf(url, sizeof(url), "Certs/%s-key.pem", name);
4653 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
4654 "private key from the device (%s)", url);
4655 if (!file_exists(url)) {
4656 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
4657 "private key file does not exist");
4658 return 0;
4659 }
4660 snprintf(buf, sizeof(buf), "cp %s next-client-key.pem", url);
4661 if (system(buf) != 0) {
4662 send_resp(dut, conn, SIGMA_ERROR,
4663 "errorCode,Failed to copy client key");
4664 return 0;
4665 }
4666 } else if (strncasecmp(path, "http:", 5) != 0 &&
4667 strncasecmp(path, "https:", 6) != 0) {
4668 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
4669 "Unsupported FilePath value");
4670 return 0;
4671 } else {
4672 snprintf(url, sizeof(url), "%s/%s.pem", path, name);
4673 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading client "
4674 "certificate/key from %s", url);
4675 snprintf(buf, sizeof(buf),
4676 "wget -T 10 -t 3 -O next-client-cert.pem '%s'", url);
4677 if (system(buf) != 0) {
4678 send_resp(dut, conn, SIGMA_ERROR,
4679 "errorCode,Failed to download client "
4680 "certificate");
4681 return 0;
4682 }
4683
4684 if (system("cp next-client-cert.pem next-client-key.pem") != 0)
4685 {
4686 send_resp(dut, conn, SIGMA_ERROR,
4687 "errorCode,Failed to copy client key");
4688 return 0;
4689 }
4690 }
4691
4692 return 1;
4693}
4694
4695
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02004696static int cmd_sta_preset_testparameters_60ghz(struct sigma_dut *dut,
4697 struct sigma_conn *conn,
4698 struct sigma_cmd *cmd)
4699{
4700 const char *val;
4701 const char *intf = get_param(cmd, "interface");
4702
4703 if (!intf)
4704 return -1;
4705
4706 val = get_param(cmd, "WscIEFragment");
4707 if (val && strcasecmp(val, "enable") == 0) {
4708 sigma_dut_print(dut, DUT_MSG_DEBUG,
4709 "Enable WSC IE fragmentation");
4710
4711 dut->wsc_fragment = 1;
4712 /* set long attributes to force fragmentation */
4713 if (wpa_command(intf, "SET device_name "
4714 WPS_LONG_DEVICE_NAME) < 0)
4715 return -2;
4716 if (wpa_command(intf, "SET manufacturer "
4717 WPS_LONG_MANUFACTURER) < 0)
4718 return -2;
4719 if (wpa_command(intf, "SET model_name "
4720 WPS_LONG_MODEL_NAME) < 0)
4721 return -2;
4722 if (wpa_command(intf, "SET model_number "
4723 WPS_LONG_MODEL_NUMBER) < 0)
4724 return -2;
4725 if (wpa_command(intf, "SET serial_number "
4726 WPS_LONG_SERIAL_NUMBER) < 0)
4727 return -2;
4728 }
4729
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02004730 val = get_param(cmd, "RSN_IE");
4731 if (val) {
4732 if (strcasecmp(val, "disable") == 0)
4733 dut->force_rsn_ie = FORCE_RSN_IE_REMOVE;
4734 else if (strcasecmp(val, "enable") == 0)
4735 dut->force_rsn_ie = FORCE_RSN_IE_ADD;
4736 }
4737
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02004738 val = get_param(cmd, "WpsVersion");
4739 if (val)
4740 dut->wps_forced_version = get_wps_forced_version(dut, val);
4741
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02004742 val = get_param(cmd, "WscEAPFragment");
4743 if (val && strcasecmp(val, "enable") == 0)
4744 dut->eap_fragment = 1;
4745
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02004746 return 1;
4747}
4748
4749
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004750static int cmd_sta_preset_testparameters_hs2_r2(struct sigma_dut *dut,
4751 struct sigma_conn *conn,
4752 const char *intf,
4753 struct sigma_cmd *cmd)
4754{
4755 const char *val;
4756
4757 val = get_param(cmd, "FileType");
4758 if (val && strcasecmp(val, "PPSMO") == 0)
4759 return download_ppsmo(dut, conn, intf, cmd);
4760 if (val && strcasecmp(val, "CERT") == 0)
4761 return download_cert(dut, conn, intf, cmd);
4762 if (val) {
4763 send_resp(dut, conn, SIGMA_ERROR,
4764 "ErrorCode,Unsupported FileType");
4765 return 0;
4766 }
4767
4768 return 1;
4769}
4770
4771
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304772static int cmd_sta_preset_testparameters_oce(struct sigma_dut *dut,
4773 struct sigma_conn *conn,
4774 const char *intf,
4775 struct sigma_cmd *cmd)
4776{
4777 const char *val;
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304778 char buf[1000];
4779 char text[20];
4780 unsigned char addr[ETH_ALEN];
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304781
4782 val = get_param(cmd, "OCESupport");
4783 if (val && strcasecmp(val, "Disable") == 0) {
4784 if (wpa_command(intf, "SET oce 0") < 0) {
4785 send_resp(dut, conn, SIGMA_ERROR,
4786 "ErrorCode,Failed to disable OCE");
4787 return 0;
4788 }
4789 } else if (val && strcasecmp(val, "Enable") == 0) {
4790 if (wpa_command(intf, "SET oce 1") < 0) {
4791 send_resp(dut, conn, SIGMA_ERROR,
4792 "ErrorCode,Failed to enable OCE");
4793 return 0;
4794 }
4795 }
4796
vamsi krishnaa2799492017-12-05 14:28:01 +05304797 val = get_param(cmd, "FILScap");
4798 if (val && (atoi(val) == 1)) {
4799 if (wpa_command(intf, "SET disable_fils 0") < 0) {
4800 send_resp(dut, conn, SIGMA_ERROR,
4801 "ErrorCode,Failed to enable FILS");
4802 return 0;
4803 }
4804 } else if (val && (atoi(val) == 0)) {
4805 if (wpa_command(intf, "SET disable_fils 1") < 0) {
4806 send_resp(dut, conn, SIGMA_ERROR,
4807 "ErrorCode,Failed to disable FILS");
4808 return 0;
4809 }
4810 }
4811
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304812 val = get_param(cmd, "FILSHLP");
4813 if (val && strcasecmp(val, "Enable") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004814 if (get_wpa_status(get_station_ifname(dut), "address", text,
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304815 sizeof(text)) < 0)
4816 return -2;
4817 hwaddr_aton(text, addr);
4818 snprintf(buf, sizeof(buf),
4819 "FILS_HLP_REQ_ADD ff:ff:ff:ff:ff:ff "
4820 "080045100140000040004011399e00000000ffffffff00440043"
4821 "012cb30001010600fd4f46410000000000000000000000000000"
4822 "000000000000"
4823 "%02x%02x%02x%02x%02x%02x"
4824 "0000000000000000000000000000000000000000000000000000"
4825 "0000000000000000000000000000000000000000000000000000"
4826 "0000000000000000000000000000000000000000000000000000"
4827 "0000000000000000000000000000000000000000000000000000"
4828 "0000000000000000000000000000000000000000000000000000"
4829 "0000000000000000000000000000000000000000000000000000"
4830 "0000000000000000000000000000000000000000000000000000"
4831 "0000000000000000000000000000000000000000638253633501"
4832 "013d0701000af549d29b390205dc3c12616e64726f69642d6468"
4833 "63702d382e302e30370a0103060f1a1c333a3b2b5000ff00",
4834 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
4835 if (wpa_command(intf, buf)) {
4836 send_resp(dut, conn, SIGMA_ERROR,
4837 "ErrorCode,Failed to add HLP");
4838 return 0;
4839 }
4840 dut->fils_hlp = 1;
4841 }
4842
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304843 return 1;
4844}
4845
4846
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004847static void ath_sta_set_noack(struct sigma_dut *dut, const char *intf,
4848 const char *val)
4849{
4850 int counter = 0;
4851 char token[50];
4852 char *result;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304853 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004854
Peng Xub8fc5cc2017-05-10 17:27:28 -07004855 strlcpy(token, val, sizeof(token));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004856 token[sizeof(token) - 1] = '\0';
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304857 result = strtok_r(token, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004858 while (result) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004859 if (strcmp(result, "disable") == 0)
4860 run_iwpriv(dut, intf, "noackpolicy %d 1 0", counter);
4861 else
4862 run_iwpriv(dut, intf, "noackpolicy %d 1 1", counter);
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304863 result = strtok_r(NULL, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004864 counter++;
4865 }
4866}
4867
4868
4869static void ath_sta_set_rts(struct sigma_dut *dut, const char *intf,
4870 const char *val)
4871{
4872 char buf[100];
4873
4874 snprintf(buf, sizeof(buf), "iwconfig %s rts %s", intf, val);
4875 if (system(buf) != 0) {
4876 sigma_dut_print(dut, DUT_MSG_ERROR, "iwconfig RTS failed");
4877 }
4878}
4879
4880
4881static void ath_sta_set_wmm(struct sigma_dut *dut, const char *intf,
4882 const char *val)
4883{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004884 if (strcasecmp(val, "off") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004885 run_iwpriv(dut, intf, "wmm 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004886 }
4887}
4888
4889
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08004890static int wcn_sta_set_wmm(struct sigma_dut *dut, const char *intf,
4891 const char *val)
4892{
4893#ifdef NL80211_SUPPORT
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08004894 int wmmenable = 1;
4895
4896 if (val &&
4897 (strcasecmp(val, "off") == 0 || strcmp(val, "0") == 0))
4898 wmmenable = 0;
4899
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05304900 return wcn_wifi_test_config_set_u8(
4901 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WMM_ENABLE,
4902 wmmenable);
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08004903#else /* NL80211_SUPPORT */
4904 sigma_dut_print(dut, DUT_MSG_ERROR,
4905 "WMM cannot be changed without NL80211_SUPPORT defined");
4906 return -1;
4907#endif /* NL80211_SUPPORT */
4908}
4909
4910
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004911static void ath_sta_set_sgi(struct sigma_dut *dut, const char *intf,
4912 const char *val)
4913{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004914 int sgi20;
4915
4916 sgi20 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
4917
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004918 run_iwpriv(dut, intf, "shortgi %d", sgi20);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004919}
4920
4921
4922static void ath_sta_set_11nrates(struct sigma_dut *dut, const char *intf,
4923 const char *val)
4924{
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05304925 int rate_code, v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004926
4927 /* Disable Tx Beam forming when using a fixed rate */
4928 ath_disable_txbf(dut, intf);
4929
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05304930 v = atoi(val);
4931 if (v < 0 || v > 32) {
4932 sigma_dut_print(dut, DUT_MSG_ERROR,
4933 "Invalid Fixed MCS rate: %d", v);
4934 return;
4935 }
4936 rate_code = 0x80 + v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004937
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004938 run_iwpriv(dut, intf, "set11NRates 0x%x", rate_code);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004939
4940 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004941 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004942}
4943
4944
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08004945static void iwpriv_sta_set_amsdu(struct sigma_dut *dut, const char *intf,
4946 const char *val)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004947{
4948 char buf[60];
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304949 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004950
4951 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)
4952 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 2", intf);
4953 else
4954 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf);
4955
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304956 ret = system(buf);
4957#ifdef NL80211_SUPPORT
4958 if (ret) {
4959 int value = (strcasecmp(val, "Enable") == 0) ? 2 : 1;
4960
4961 ret = sta_config_params(dut, intf, STA_SET_TX_MSDU, value);
4962 ret |= sta_config_params(dut, intf, STA_SET_RX_MSDU, value);
4963 }
4964#endif /* NL80211_SUPPORT */
4965 if (ret)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004966 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv amsdu failed");
4967}
4968
4969
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004970static int iwpriv_sta_set_ampdu(struct sigma_dut *dut, const char *intf,
4971 int ampdu)
4972{
4973 char buf[60];
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08004974 int maxaggregation = 63;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004975
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08004976 if (ampdu)
4977 ampdu = maxaggregation;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004978 snprintf(buf, sizeof(buf), "iwpriv %s ampdu %d", intf, ampdu);
4979 if (system(buf) != 0) {
4980 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv ampdu failed");
4981 return -1;
4982 }
4983
4984 return 0;
4985}
4986
4987
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004988static void ath_sta_set_stbc(struct sigma_dut *dut, const char *intf,
4989 const char *val)
4990{
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004991 run_iwpriv(dut, intf, "tx_stbc %s", val);
4992 run_iwpriv(dut, intf, "rx_stbc %s", val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004993}
4994
4995
4996static int wcn_sta_set_cts_width(struct sigma_dut *dut, const char *intf,
4997 const char *val)
4998{
4999 char buf[60];
5000
Peng Xucc317ed2017-05-18 16:44:37 -07005001 if (strcmp(val, "160") == 0) {
5002 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 5", intf);
5003 } else if (strcmp(val, "80") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005004 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
5005 } else if (strcmp(val, "40") == 0) {
5006 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 2", intf);
5007 } else if (strcmp(val, "20") == 0) {
5008 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 1", intf);
5009 } else if (strcasecmp(val, "Auto") == 0) {
5010 buf[0] = '\0';
5011 } else {
5012 sigma_dut_print(dut, DUT_MSG_ERROR,
5013 "WIDTH/CTS_WIDTH value not supported");
5014 return -1;
5015 }
5016
5017 if (buf[0] != '\0' && system(buf) != 0) {
5018 sigma_dut_print(dut, DUT_MSG_ERROR,
5019 "Failed to set WIDTH/CTS_WIDTH");
5020 return -1;
5021 }
5022
5023 return 0;
5024}
5025
5026
5027int ath_set_width(struct sigma_dut *dut, struct sigma_conn *conn,
5028 const char *intf, const char *val)
5029{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005030 if (strcasecmp(val, "Auto") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005031 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005032 dut->chwidth = 0;
5033 } else if (strcasecmp(val, "20") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005034 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005035 dut->chwidth = 0;
5036 } else if (strcasecmp(val, "40") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005037 run_iwpriv(dut, intf, "chwidth 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005038 dut->chwidth = 1;
5039 } else if (strcasecmp(val, "80") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005040 run_iwpriv(dut, intf, "chwidth 2");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005041 dut->chwidth = 2;
5042 } else if (strcasecmp(val, "160") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005043 run_iwpriv(dut, intf, "chwidth 3");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005044 dut->chwidth = 3;
5045 } else {
5046 send_resp(dut, conn, SIGMA_ERROR,
5047 "ErrorCode,WIDTH not supported");
5048 return -1;
5049 }
5050
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005051 return 0;
5052}
5053
5054
5055static int wcn_sta_set_sp_stream(struct sigma_dut *dut, const char *intf,
5056 const char *val)
5057{
5058 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07005059 int sta_nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005060
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08005061 if (strcmp(val, "1SS") == 0 || strcmp(val, "1") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005062 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07005063 sta_nss = 1;
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08005064 } else if (strcmp(val, "2SS") == 0 || strcmp(val, "2") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005065 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07005066 sta_nss = 2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005067 } else {
5068 sigma_dut_print(dut, DUT_MSG_ERROR,
5069 "SP_STREAM value not supported");
5070 return -1;
5071 }
5072
5073 if (system(buf) != 0) {
5074 sigma_dut_print(dut, DUT_MSG_ERROR,
5075 "Failed to set SP_STREAM");
5076 return -1;
5077 }
5078
Arif Hussainac6c5112018-05-25 17:34:00 -07005079 dut->sta_nss = sta_nss;
5080
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005081 return 0;
5082}
5083
5084
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05305085static void wcn_sta_set_stbc(struct sigma_dut *dut, const char *intf,
5086 const char *val)
5087{
5088 char buf[60];
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05305089 int ret;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05305090
5091 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc %s", intf, val);
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05305092 ret = system(buf);
5093#ifdef NL80211_SUPPORT
5094 if (ret)
5095 ret = sta_config_params(dut, intf, STA_SET_TX_STBC,
5096 strcmp(val, "0") == 0 ? 0 : 1);
5097#endif /* NL80211_SUPPORT */
5098 if (ret)
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05305099 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv tx_stbc failed");
5100
5101 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc %s", intf, val);
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05305102 ret = system(buf);
5103#ifdef NL80211_SUPPORT
5104 if (ret)
5105 ret = sta_config_params(dut, intf, STA_SET_RX_STBC,
5106 strcmp(val, "0") == 0 ? 0 : 1);
5107#endif /* NL80211_SUPPORT */
5108 if (ret)
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05305109 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv rx_stbc failed");
5110}
5111
5112
Ashwini Patil68d02cd2017-01-10 15:39:16 +05305113static int mbo_set_cellular_data_capa(struct sigma_dut *dut,
5114 struct sigma_conn *conn,
5115 const char *intf, int capa)
5116{
5117 char buf[32];
5118
5119 if (capa > 0 && capa < 4) {
5120 snprintf(buf, sizeof(buf), "SET mbo_cell_capa %d", capa);
5121 if (wpa_command(intf, buf) < 0) {
5122 send_resp(dut, conn, SIGMA_ERROR,
5123 "ErrorCode, Failed to set cellular data capability");
5124 return 0;
5125 }
5126 return 1;
5127 }
5128
5129 sigma_dut_print(dut, DUT_MSG_ERROR,
5130 "Invalid Cellular data capability: %d", capa);
5131 send_resp(dut, conn, SIGMA_INVALID,
5132 "ErrorCode,Invalid cellular data capability");
5133 return 0;
5134}
5135
5136
Ashwini Patil9183fdb2017-04-13 16:58:25 +05305137static int mbo_set_roaming(struct sigma_dut *dut, struct sigma_conn *conn,
5138 const char *intf, const char *val)
5139{
5140 if (strcasecmp(val, "Disable") == 0) {
5141 if (wpa_command(intf, "SET roaming 0") < 0) {
5142 send_resp(dut, conn, SIGMA_ERROR,
5143 "ErrorCode,Failed to disable roaming");
5144 return 0;
5145 }
5146 return 1;
5147 }
5148
5149 if (strcasecmp(val, "Enable") == 0) {
5150 if (wpa_command(intf, "SET roaming 1") < 0) {
5151 send_resp(dut, conn, SIGMA_ERROR,
5152 "ErrorCode,Failed to enable roaming");
5153 return 0;
5154 }
5155 return 1;
5156 }
5157
5158 sigma_dut_print(dut, DUT_MSG_ERROR,
5159 "Invalid value provided for roaming: %s", val);
5160 send_resp(dut, conn, SIGMA_INVALID,
5161 "ErrorCode,Unknown value provided for Roaming");
5162 return 0;
5163}
5164
5165
Ashwini Patila75de5a2017-04-13 16:35:05 +05305166static int mbo_set_assoc_disallow(struct sigma_dut *dut,
5167 struct sigma_conn *conn,
5168 const char *intf, const char *val)
5169{
5170 if (strcasecmp(val, "Disable") == 0) {
5171 if (wpa_command(intf, "SET ignore_assoc_disallow 1") < 0) {
5172 send_resp(dut, conn, SIGMA_ERROR,
5173 "ErrorCode,Failed to disable Assoc_disallow");
5174 return 0;
5175 }
5176 return 1;
5177 }
5178
5179 if (strcasecmp(val, "Enable") == 0) {
5180 if (wpa_command(intf, "SET ignore_assoc_disallow 0") < 0) {
5181 send_resp(dut, conn, SIGMA_ERROR,
5182 "ErrorCode,Failed to enable Assoc_disallow");
5183 return 0;
5184 }
5185 return 1;
5186 }
5187
5188 sigma_dut_print(dut, DUT_MSG_ERROR,
5189 "Invalid value provided for Assoc_disallow: %s", val);
5190 send_resp(dut, conn, SIGMA_INVALID,
5191 "ErrorCode,Unknown value provided for Assoc_disallow");
5192 return 0;
5193}
5194
5195
Ashwini Patilc63161e2017-04-13 16:30:23 +05305196static int mbo_set_bss_trans_req(struct sigma_dut *dut, struct sigma_conn *conn,
5197 const char *intf, const char *val)
5198{
5199 if (strcasecmp(val, "Reject") == 0) {
5200 if (wpa_command(intf, "SET reject_btm_req_reason 1") < 0) {
5201 send_resp(dut, conn, SIGMA_ERROR,
5202 "ErrorCode,Failed to Reject BTM Request");
5203 return 0;
5204 }
5205 return 1;
5206 }
5207
5208 if (strcasecmp(val, "Accept") == 0) {
5209 if (wpa_command(intf, "SET reject_btm_req_reason 0") < 0) {
5210 send_resp(dut, conn, SIGMA_ERROR,
5211 "ErrorCode,Failed to Accept BTM Request");
5212 return 0;
5213 }
5214 return 1;
5215 }
5216
5217 sigma_dut_print(dut, DUT_MSG_ERROR,
5218 "Invalid value provided for BSS_Transition: %s", val);
5219 send_resp(dut, conn, SIGMA_INVALID,
5220 "ErrorCode,Unknown value provided for BSS_Transition");
5221 return 0;
5222}
5223
5224
Ashwini Patil00402582017-04-13 12:29:39 +05305225static int mbo_set_non_pref_ch_list(struct sigma_dut *dut,
5226 struct sigma_conn *conn,
5227 const char *intf,
5228 struct sigma_cmd *cmd)
5229{
5230 const char *ch, *pref, *op_class, *reason;
5231 char buf[120];
5232 int len, ret;
5233
5234 pref = get_param(cmd, "Ch_Pref");
5235 if (!pref)
5236 return 1;
5237
5238 if (strcasecmp(pref, "clear") == 0) {
5239 free(dut->non_pref_ch_list);
5240 dut->non_pref_ch_list = NULL;
5241 } else {
5242 op_class = get_param(cmd, "Ch_Op_Class");
5243 if (!op_class) {
5244 send_resp(dut, conn, SIGMA_INVALID,
5245 "ErrorCode,Ch_Op_Class not provided");
5246 return 0;
5247 }
5248
5249 ch = get_param(cmd, "Ch_Pref_Num");
5250 if (!ch) {
5251 send_resp(dut, conn, SIGMA_INVALID,
5252 "ErrorCode,Ch_Pref_Num not provided");
5253 return 0;
5254 }
5255
5256 reason = get_param(cmd, "Ch_Reason_Code");
5257 if (!reason) {
5258 send_resp(dut, conn, SIGMA_INVALID,
5259 "ErrorCode,Ch_Reason_Code not provided");
5260 return 0;
5261 }
5262
5263 if (!dut->non_pref_ch_list) {
5264 dut->non_pref_ch_list =
5265 calloc(1, NON_PREF_CH_LIST_SIZE);
5266 if (!dut->non_pref_ch_list) {
5267 send_resp(dut, conn, SIGMA_ERROR,
5268 "ErrorCode,Failed to allocate memory for non_pref_ch_list");
5269 return 0;
5270 }
5271 }
5272 len = strlen(dut->non_pref_ch_list);
5273 ret = snprintf(dut->non_pref_ch_list + len,
5274 NON_PREF_CH_LIST_SIZE - len,
5275 " %s:%s:%s:%s", op_class, ch, pref, reason);
5276 if (ret > 0 && ret < NON_PREF_CH_LIST_SIZE - len) {
5277 sigma_dut_print(dut, DUT_MSG_DEBUG, "non_pref_list: %s",
5278 dut->non_pref_ch_list);
5279 } else {
5280 sigma_dut_print(dut, DUT_MSG_ERROR,
5281 "snprintf failed for non_pref_list, ret = %d",
5282 ret);
5283 send_resp(dut, conn, SIGMA_ERROR,
5284 "ErrorCode,snprintf failed");
5285 free(dut->non_pref_ch_list);
5286 dut->non_pref_ch_list = NULL;
5287 return 0;
5288 }
5289 }
5290
5291 ret = snprintf(buf, sizeof(buf), "SET non_pref_chan%s",
5292 dut->non_pref_ch_list ? dut->non_pref_ch_list : " ");
5293 if (ret < 0 || ret >= (int) sizeof(buf)) {
5294 sigma_dut_print(dut, DUT_MSG_DEBUG,
5295 "snprintf failed for set non_pref_chan, ret: %d",
5296 ret);
5297 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,snprint failed");
5298 return 0;
5299 }
5300
5301 if (wpa_command(intf, buf) < 0) {
5302 send_resp(dut, conn, SIGMA_ERROR,
5303 "ErrorCode,Failed to set non-preferred channel list");
5304 return 0;
5305 }
5306
5307 return 1;
5308}
5309
5310
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08005311#ifdef NL80211_SUPPORT
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08005312
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08005313static int sta_set_he_htc_supp(struct sigma_dut *dut, const char *intf,
5314 uint8_t cfg)
5315{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05305316 return wcn_wifi_test_config_set_u8(
5317 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_HTC_HE_SUPP,
5318 cfg);
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08005319}
5320
5321
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08005322static int sta_set_he_fragmentation(struct sigma_dut *dut, const char *intf,
5323 enum he_fragmentation_val frag)
5324{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05305325 return wcn_wifi_test_config_set_u8(
5326 dut, intf,
5327 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_FRAGMENTATION, frag);
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08005328}
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08005329
5330
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -08005331int wcn_set_he_ltf(struct sigma_dut *dut, const char *intf,
5332 enum qca_wlan_he_ltf_cfg ltf)
Subhani Shaik8e7a3052018-04-24 14:03:00 -07005333{
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_LTF, ltf);
Subhani Shaik8e7a3052018-04-24 14:03:00 -07005336}
5337
5338
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08005339static int nlvendor_sta_set_noack(struct sigma_dut *dut, const char *intf,
5340 int noack, enum qca_wlan_ac_type ac)
5341{
5342 struct nl_msg *msg;
5343 int ret = 0;
5344 struct nlattr *params;
5345 int ifindex;
5346
5347 ifindex = if_nametoindex(intf);
5348 if (ifindex == 0) {
5349 sigma_dut_print(dut, DUT_MSG_ERROR,
5350 "%s: Index for interface %s failed",
5351 __func__, intf);
5352 return -1;
5353 }
5354
5355 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5356 NL80211_CMD_VENDOR)) ||
5357 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5358 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5359 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5360 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5361 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5362 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_NO_ACK,
5363 noack) ||
5364 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_NO_ACK_AC,
5365 ac)) {
5366 sigma_dut_print(dut, DUT_MSG_ERROR,
5367 "%s: err in adding vendor_cmd and vendor_data",
5368 __func__);
5369 nlmsg_free(msg);
5370 return -1;
5371 }
5372 nla_nest_end(msg, params);
5373
5374 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5375 if (ret) {
5376 sigma_dut_print(dut, DUT_MSG_ERROR,
5377 "%s: err in send_and_recv_msgs, ret=%d",
5378 __func__, ret);
5379 }
5380 return ret;
5381}
5382
5383
5384static void wcn_sta_set_noack(struct sigma_dut *dut, const char *intf,
5385 const char *val)
5386{
5387 int noack, ret;
5388 char token[100];
5389 char *result;
5390 char *saveptr;
5391 enum qca_wlan_ac_type ac = QCA_WLAN_AC_BE;
5392
5393 strlcpy(token, val, sizeof(token));
5394 token[sizeof(token) - 1] = '\0';
5395 result = strtok_r(token, ":", &saveptr);
5396 while (result) {
5397 noack = strcasecmp(result, "Disable") != 0;
5398 ret = nlvendor_sta_set_noack(dut, intf, noack, ac);
5399 if (ret) {
5400 sigma_dut_print(dut, DUT_MSG_ERROR,
5401 "nlvendor_sta_set_noack failed for ac:%d, ret:%d",
5402 ac, ret);
5403 }
5404 result = strtok_r(NULL, ":", &saveptr);
5405 ac++;
5406 }
5407}
5408
Vinita S. Maloo7462e812020-05-22 15:16:04 +05305409
5410static int nlvendor_sta_set_phymode(struct sigma_dut *dut, const char *intf,
5411 enum qca_wlan_vendor_phy_mode val)
5412{
5413 struct nl_msg *msg;
5414 struct nlattr *params;
5415 int ifindex, ret;
5416
5417 ifindex = if_nametoindex(intf);
5418 if (ifindex == 0) {
5419 sigma_dut_print(dut, DUT_MSG_ERROR,
5420 "%s: Index for interface %s not found",
5421 __func__, intf);
5422 return -1;
5423 }
5424
5425 msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5426 NL80211_CMD_VENDOR);
5427 if (!msg) {
5428 sigma_dut_print(dut, DUT_MSG_ERROR,
5429 "%s: err in adding vendor_cmd", __func__);
5430 return -1;
5431 }
5432
5433 if (nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5434 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5435 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION)) {
5436 sigma_dut_print(dut, DUT_MSG_ERROR,
5437 "%s: err in adding vendor_attr", __func__);
5438 nlmsg_free(msg);
5439 return -1;
5440 }
5441
5442 params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
5443 if (!params || nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_PHY_MODE,
5444 val)) {
5445 sigma_dut_print(dut, DUT_MSG_ERROR,
5446 "%s: err in adding vendor_data", __func__);
5447 nlmsg_free(msg);
5448 return -1;
5449 }
5450
5451 nla_nest_end(msg, params);
5452 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5453 if (ret) {
5454 sigma_dut_print(dut, DUT_MSG_ERROR,
5455 "%s: err in send_and_recv_msgs, ret=%d (%s)",
5456 __func__, ret, strerror(-ret));
5457 return ret;
5458 }
5459
5460 return 0;
5461}
5462
5463
5464static enum qca_wlan_vendor_phy_mode get_qca_vendor_phymode(const char *val)
5465{
5466 if (strcmp(val, "11a") == 0) {
5467 /* IEEE80211_MODE_11A */
5468 return QCA_WLAN_VENDOR_PHY_MODE_11A;
5469 }
5470
5471 if (strcmp(val, "11g") == 0) {
5472 /* IEEE80211_MODE_11G */
5473 return QCA_WLAN_VENDOR_PHY_MODE_11G;
5474 }
5475
5476 if (strcmp(val, "11b") == 0) {
5477 /* IEEE80211_MODE_11B */
5478 return QCA_WLAN_VENDOR_PHY_MODE_11B;
5479 }
5480
5481 if (strcmp(val, "11n") == 0 ||
5482 strcmp(val, "11nl") == 0 ||
5483 strcmp(val, "11nl(nabg)") == 0) {
5484 /* IEEE80211_MODE_11AGN */
5485 return QCA_WLAN_VENDOR_PHY_MODE_11AGN;
5486 }
5487
5488 if (strcmp(val, "11ng") == 0) {
5489 /* IEEE80211_MODE_11NG_HT40 */
5490 return QCA_WLAN_VENDOR_PHY_MODE_11NG_HT40;
5491 }
5492
5493 if (strcmp(val, "AC") == 0 ||
5494 strcasecmp(val, "11AC") == 0) {
5495 /* IEEE80211_MODE_11AC_VHT80 */
5496 return QCA_WLAN_VENDOR_PHY_MODE_11AC_VHT80;
5497 }
5498
5499 if (strcmp(val, "11na") == 0 ||
5500 strcasecmp(val, "11an") == 0) {
5501 /* IEEE80211_MODE_11NA_HT40 */
5502 return QCA_WLAN_VENDOR_PHY_MODE_11NA_HT40;
5503 }
5504
5505 if (strcmp(val, "11ax") == 0 ||
5506 strcmp(val, "auto") == 0) {
5507 /* IEEE80211_MODE_AUTO */
5508 return QCA_WLAN_VENDOR_PHY_MODE_AUTO;
5509 }
5510
5511 return -1;
5512}
5513
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08005514#endif /* NL80211_SUPPORT */
5515
5516
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05305517static int get_phymode(const char *val)
5518{
5519 if (strcmp(val, "11a") == 0)
5520 return 1; /* IEEE80211_MODE_11A */
5521 if (strcmp(val, "11g") == 0)
5522 return 3; /* IEEE80211_MODE_11G */
5523 if (strcmp(val, "11b") == 0)
5524 return 2; /* IEEE80211_MODE_11B */
5525 if (strcmp(val, "11n") == 0 ||
5526 strcmp(val, "11nl") == 0 ||
5527 strcmp(val, "11nl(nabg)") == 0)
5528 return 22; /* IEEE80211_MODE_11AGN */
5529 if (strcmp(val, "11ng") == 0)
5530 return 13; /* IEEE80211_MODE_11NG_HT40 */
5531 if (strcmp(val, "AC") == 0 ||
5532 strcasecmp(val, "11AC") == 0)
5533 return 19; /* IEEE80211_MODE_11AC_VHT80 */
5534 if (strcmp(val, "11na") == 0 ||
5535 strcasecmp(val, "11an") == 0)
5536 return 14; /* IEEE80211_MODE_11NA_HT40 */
5537 if (strcmp(val, "11ax") == 0 ||
5538 strcmp(val, "auto") == 0)
5539 return 0; /* IEEE80211_MODE_AUTO */
5540 return -1;
5541}
5542
5543
5544static void sta_set_phymode(struct sigma_dut *dut, const char *intf,
5545 const char *val)
5546{
5547 char buf[100];
5548 int len, phymode;
Vinita S. Maloo7462e812020-05-22 15:16:04 +05305549#ifdef NL80211_SUPPORT
5550 enum qca_wlan_vendor_phy_mode qca_phymode;
5551
5552 qca_phymode = get_qca_vendor_phymode(val);
5553 if (qca_phymode == -1) {
5554 sigma_dut_print(dut, DUT_MSG_DEBUG,
5555 "Ignoring mode change for mode: %s",
5556 val);
5557 return;
5558 }
5559
5560 if (nlvendor_sta_set_phymode(dut, intf, qca_phymode) == 0)
5561 return;
5562#endif /* NL80211_SUPPORT */
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05305563
5564 phymode = get_phymode(val);
5565 if (phymode == -1) {
5566 sigma_dut_print(dut, DUT_MSG_DEBUG,
5567 "Ignoring mode change for mode: %s",
5568 val);
5569 return;
5570 }
5571
5572 len = snprintf(buf, sizeof(buf), "iwpriv %s setphymode %d", intf,
5573 phymode);
5574 if (len < 0 || len >= sizeof(buf)) {
5575 sigma_dut_print(dut, DUT_MSG_ERROR,
5576 "Failed to set phymode");
5577 return;
5578 }
5579
5580 if (system(buf) != 0)
5581 sigma_dut_print(dut, DUT_MSG_ERROR,
5582 "iwpriv setting of phymode failed");
5583}
5584
5585
Jouni Malinenf7222712019-06-13 01:50:21 +03005586static enum sigma_cmd_result
5587cmd_sta_preset_testparameters(struct sigma_dut *dut, struct sigma_conn *conn,
5588 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005589{
5590 const char *intf = get_param(cmd, "Interface");
5591 const char *val;
5592
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03005593 val = get_param(cmd, "FT_DS");
5594 if (val) {
5595 if (strcasecmp(val, "Enable") == 0) {
5596 dut->sta_ft_ds = 1;
5597 } else if (strcasecmp(val, "Disable") == 0) {
5598 dut->sta_ft_ds = 0;
5599 } else {
5600 send_resp(dut, conn, SIGMA_ERROR,
5601 "errorCode,Unsupported value for FT_DS");
5602 return STATUS_SENT_ERROR;
5603 }
Shivani Baranwal7aa48602021-09-29 10:53:38 +05305604 if (get_driver_type(dut) == DRIVER_WCN &&
5605 sta_config_params(dut, intf, STA_SET_FT_DS,
5606 dut->sta_ft_ds) != 0) {
5607 send_resp(dut, conn, SIGMA_ERROR,
5608 "errorCode,Failed to enable/disable FT_DS");
5609 return STATUS_SENT_ERROR;
5610 }
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03005611 }
5612
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005613 val = get_param(cmd, "Program");
Jouni Malinen1f6ae642018-06-07 23:56:13 +03005614 if (val && (strcasecmp(val, "HS2-R2") == 0 ||
5615 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005616 return cmd_sta_preset_testparameters_hs2_r2(dut, conn, intf,
5617 cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005618
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07005619 if (val && strcasecmp(val, "LOC") == 0)
5620 return loc_cmd_sta_preset_testparameters(dut, conn, cmd);
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02005621 if (val && strcasecmp(val, "60GHZ") == 0) {
5622 val = get_param(cmd, "WPS");
5623 if (val && strcasecmp(val, "disable") == 0) {
5624 dut->wps_disable = 1;
5625 sigma_dut_print(dut, DUT_MSG_INFO, "WPS disabled");
5626 } else {
5627 /* wps_disable can have other value from the previous
5628 * test, so make sure it has the correct value.
5629 */
5630 dut->wps_disable = 0;
5631 }
5632
5633 val = get_param(cmd, "P2P");
5634 if (val && strcasecmp(val, "disable") == 0)
5635 sigma_dut_print(dut, DUT_MSG_INFO, "P2P disabled");
5636 }
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07005637
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02005638 if (dut->program == PROGRAM_WPS && dut->band == WPS_BAND_60G)
5639 return cmd_sta_preset_testparameters_60ghz(dut, conn, cmd);
5640
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005641#ifdef ANDROID_NAN
5642 if (val && strcasecmp(val, "NAN") == 0)
5643 return nan_cmd_sta_preset_testparameters(dut, conn, cmd);
5644#endif /* ANDROID_NAN */
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07005645#ifdef MIRACAST
5646 if (val && (strcasecmp(val, "WFD") == 0 ||
5647 strcasecmp(val, "DisplayR2") == 0))
5648 return miracast_preset_testparameters(dut, conn, cmd);
5649#endif /* MIRACAST */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005650
Kiran Kumar Lokeredd086642020-06-04 00:29:26 -07005651 if (val &&
5652 (strcasecmp(val, "MBO") == 0 || strcasecmp(val, "HE") == 0)) {
Ashwini Patil68d02cd2017-01-10 15:39:16 +05305653 val = get_param(cmd, "Cellular_Data_Cap");
5654 if (val &&
5655 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
5656 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +05305657
5658 val = get_param(cmd, "Ch_Pref");
5659 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
5660 return 0;
5661
Ashwini Patilc63161e2017-04-13 16:30:23 +05305662 val = get_param(cmd, "BSS_Transition");
5663 if (val && mbo_set_bss_trans_req(dut, conn, intf, val) == 0)
5664 return 0;
5665
Ashwini Patila75de5a2017-04-13 16:35:05 +05305666 val = get_param(cmd, "Assoc_Disallow");
5667 if (val && mbo_set_assoc_disallow(dut, conn, intf, val) == 0)
5668 return 0;
5669
Ashwini Patil9183fdb2017-04-13 16:58:25 +05305670 val = get_param(cmd, "Roaming");
5671 if (val && mbo_set_roaming(dut, conn, intf, val) == 0)
5672 return 0;
5673
Ashwini Patil68d02cd2017-01-10 15:39:16 +05305674 return 1;
5675 }
5676
Ankita Bajaja2cb5672017-10-25 16:08:28 +05305677 if (val && strcasecmp(val, "OCE") == 0)
5678 return cmd_sta_preset_testparameters_oce(dut, conn, intf, cmd);
5679
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005680#if 0
5681 val = get_param(cmd, "Supplicant");
5682 if (val && strcasecmp(val, "Default") != 0) {
5683 send_resp(dut, conn, SIGMA_ERROR,
5684 "ErrorCode,Only default(Vendor) supplicant "
5685 "supported");
5686 return 0;
5687 }
5688#endif
5689
5690 val = get_param(cmd, "RTS");
5691 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005692 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005693 case DRIVER_ATHEROS:
5694 ath_sta_set_rts(dut, intf, val);
5695 break;
5696 default:
5697#if 0
5698 send_resp(dut, conn, SIGMA_ERROR,
5699 "ErrorCode,Setting RTS not supported");
5700 return 0;
5701#else
5702 sigma_dut_print(dut, DUT_MSG_DEBUG,
5703 "Setting RTS not supported");
5704 break;
5705#endif
5706 }
5707 }
5708
5709#if 0
5710 val = get_param(cmd, "FRGMNT");
5711 if (val) {
5712 /* TODO */
5713 send_resp(dut, conn, SIGMA_ERROR,
5714 "ErrorCode,Setting FRGMNT not supported");
5715 return 0;
5716 }
5717#endif
5718
5719#if 0
5720 val = get_param(cmd, "Preamble");
5721 if (val) {
5722 /* TODO: Long/Short */
5723 send_resp(dut, conn, SIGMA_ERROR,
5724 "ErrorCode,Setting Preamble not supported");
5725 return 0;
5726 }
5727#endif
5728
5729 val = get_param(cmd, "Mode");
5730 if (val) {
5731 if (strcmp(val, "11b") == 0 ||
5732 strcmp(val, "11g") == 0 ||
5733 strcmp(val, "11a") == 0 ||
5734 strcmp(val, "11n") == 0 ||
5735 strcmp(val, "11ng") == 0 ||
5736 strcmp(val, "11nl") == 0 ||
5737 strcmp(val, "11nl(nabg)") == 0 ||
5738 strcmp(val, "AC") == 0 ||
5739 strcmp(val, "11AC") == 0 ||
5740 strcmp(val, "11ac") == 0 ||
5741 strcmp(val, "11na") == 0 ||
Amarnath Hullur Subramanyamb0db2712018-01-30 19:40:35 -08005742 strcmp(val, "11an") == 0 ||
5743 strcmp(val, "11ax") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005744 /* STA supports all modes by default */
5745 } else {
5746 send_resp(dut, conn, SIGMA_ERROR,
5747 "ErrorCode,Setting Mode not supported");
5748 return 0;
5749 }
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08005750
5751 /* Change the mode only in case of testbed for HE program
5752 * and for 11a and 11g modes only. */
5753 if (dut->program == PROGRAM_HE &&
5754 dut->device_type == STA_testbed) {
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05305755 sta_set_phymode(dut, intf, val);
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08005756 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005757 }
5758
5759 val = get_param(cmd, "wmm");
5760 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005761 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005762 case DRIVER_ATHEROS:
5763 ath_sta_set_wmm(dut, intf, val);
5764 break;
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08005765 case DRIVER_WCN:
5766 wcn_sta_set_wmm(dut, intf, val);
5767 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005768 default:
5769 sigma_dut_print(dut, DUT_MSG_DEBUG,
5770 "Setting wmm not supported");
5771 break;
5772 }
5773 }
5774
5775 val = get_param(cmd, "Powersave");
5776 if (val) {
5777 if (strcmp(val, "0") == 0 || strcasecmp(val, "off") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005778 if (get_driver_type(dut) == DRIVER_WCN) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +05305779 if (set_power_save_wcn(dut, intf, 2) < 0)
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005780 return 0;
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005781 }
5782
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005783 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005784 "P2P_SET ps 0") < 0)
5785 return -2;
5786 /* Make sure test modes are disabled */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005787 wpa_command(get_station_ifname(dut), "P2P_SET ps 98");
5788 wpa_command(get_station_ifname(dut), "P2P_SET ps 96");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005789 } else if (strcmp(val, "1") == 0 ||
5790 strcasecmp(val, "PSPoll") == 0 ||
5791 strcasecmp(val, "on") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005792 if (get_driver_type(dut) == DRIVER_WCN) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +05305793 if (set_power_save_wcn(dut, intf, 1) < 0)
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005794 return 0;
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005795 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005796 /* Disable default power save mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005797 wpa_command(get_station_ifname(dut), "P2P_SET ps 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005798 /* Enable PS-Poll test mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005799 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005800 "P2P_SET ps 97") < 0 ||
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005801 wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005802 "P2P_SET ps 99") < 0)
5803 return -2;
5804 } else if (strcmp(val, "2") == 0 ||
5805 strcasecmp(val, "Fast") == 0) {
5806 /* TODO */
5807 send_resp(dut, conn, SIGMA_ERROR,
5808 "ErrorCode,Powersave=Fast not supported");
5809 return 0;
5810 } else if (strcmp(val, "3") == 0 ||
5811 strcasecmp(val, "PSNonPoll") == 0) {
5812 /* Make sure test modes are disabled */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005813 wpa_command(get_station_ifname(dut), "P2P_SET ps 98");
5814 wpa_command(get_station_ifname(dut), "P2P_SET ps 96");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005815
5816 /* Enable default power save 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 1") < 0)
5819 return -2;
5820 } else
5821 return -1;
5822 }
5823
5824 val = get_param(cmd, "NoAck");
5825 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005826 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005827 case DRIVER_ATHEROS:
5828 ath_sta_set_noack(dut, intf, val);
5829 break;
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08005830#ifdef NL80211_SUPPORT
5831 case DRIVER_WCN:
5832 wcn_sta_set_noack(dut, intf, val);
5833 break;
5834#endif /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005835 default:
5836 send_resp(dut, conn, SIGMA_ERROR,
5837 "ErrorCode,Setting NoAck not supported");
5838 return 0;
5839 }
5840 }
5841
5842 val = get_param(cmd, "IgnoreChswitchProhibit");
5843 if (val) {
5844 /* TODO: Enabled/disabled */
5845 if (strcasecmp(val, "Enabled") == 0) {
5846 send_resp(dut, conn, SIGMA_ERROR,
5847 "ErrorCode,Enabling IgnoreChswitchProhibit "
5848 "not supported");
5849 return 0;
5850 }
5851 }
5852
5853 val = get_param(cmd, "TDLS");
5854 if (val) {
5855 if (strcasecmp(val, "Disabled") == 0) {
5856 if (wpa_command(intf, "SET tdls_disabled 1")) {
5857 send_resp(dut, conn, SIGMA_ERROR,
5858 "ErrorCode,Failed to disable TDLS");
5859 return 0;
5860 }
5861 } else if (strcasecmp(val, "Enabled") == 0) {
5862 if (wpa_command(intf, "SET tdls_disabled 0")) {
5863 send_resp(dut, conn, SIGMA_ERROR,
5864 "ErrorCode,Failed to enable TDLS");
5865 return 0;
5866 }
5867 } else {
5868 send_resp(dut, conn, SIGMA_ERROR,
5869 "ErrorCode,Unsupported TDLS value");
5870 return 0;
5871 }
5872 }
5873
5874 val = get_param(cmd, "TDLSmode");
5875 if (val) {
5876 if (strcasecmp(val, "Default") == 0) {
5877 wpa_command(intf, "SET tdls_testing 0");
5878 } else if (strcasecmp(val, "APProhibit") == 0) {
5879 if (wpa_command(intf, "SET tdls_testing 0x400")) {
5880 send_resp(dut, conn, SIGMA_ERROR,
5881 "ErrorCode,Failed to enable ignore "
5882 "APProhibit TDLS mode");
5883 return 0;
5884 }
5885 } else if (strcasecmp(val, "HiLoMac") == 0) {
5886 /* STA should respond with TDLS setup req for a TDLS
5887 * setup req */
5888 if (wpa_command(intf, "SET tdls_testing 0x80")) {
5889 send_resp(dut, conn, SIGMA_ERROR,
5890 "ErrorCode,Failed to enable HiLoMac "
5891 "TDLS mode");
5892 return 0;
5893 }
5894 } else if (strcasecmp(val, "WeakSecurity") == 0) {
5895 /*
5896 * Since all security modes are enabled by default when
5897 * Sigma control is used, there is no need to do
5898 * anything here.
5899 */
5900 } else if (strcasecmp(val, "ExistLink") == 0) {
5901 /*
5902 * Since we allow new TDLS Setup Request even if there
5903 * is an existing link, nothing needs to be done for
5904 * this.
5905 */
5906 } else {
5907 /* TODO:
5908 * ExistLink: STA should send TDLS setup req even if
5909 * direct link already exists
5910 */
5911 send_resp(dut, conn, SIGMA_ERROR,
5912 "ErrorCode,Unsupported TDLSmode value");
5913 return 0;
5914 }
5915 }
5916
5917 val = get_param(cmd, "FakePubKey");
5918 if (val && atoi(val) && wpa_command(intf, "SET wps_corrupt_pkhash 1")) {
5919 send_resp(dut, conn, SIGMA_ERROR,
5920 "ErrorCode,Failed to enable FakePubKey");
5921 return 0;
5922 }
5923
Amarnath Hullur Subramanyamae1042b2018-02-22 21:52:52 -08005924#ifdef NL80211_SUPPORT
5925 val = get_param(cmd, "FrgmntSupport");
5926 if (val) {
5927 if (strcasecmp(val, "Enable") == 0) {
5928 if (sta_set_he_fragmentation(dut, intf,
5929 HE_FRAG_LEVEL1)) {
5930 send_resp(dut, conn, SIGMA_ERROR,
5931 "ErrorCode,Failed to enable HE Fragmentation");
5932 return 0;
5933 }
5934 } else if (strcasecmp(val, "Disable") == 0) {
5935 if (sta_set_he_fragmentation(dut, intf,
5936 HE_FRAG_DISABLE)) {
5937 send_resp(dut, conn, SIGMA_ERROR,
5938 "ErrorCode,Failed to disable HE Fragmentation");
5939 return 0;
5940 }
5941 }
5942 }
5943#endif /* NL80211_SUPPORT */
5944
Vinita S. Maloo8a4779c2020-06-22 19:32:37 +05305945 val = get_param(cmd, "IncludeMSCSDescriptor");
5946 if (val && strcasecmp(val, "1") == 0) {
5947 char buf[128];
5948 int len;
5949
5950 len = snprintf(buf, sizeof(buf),
Veerendranath Jakkam62cde372020-08-19 18:03:06 +05305951 "MSCS add up_bitmap=F0 up_limit=7 stream_timeout=60000 frame_classifier=045F%032x",
Vinita S. Maloo8a4779c2020-06-22 19:32:37 +05305952 0);
5953
5954 if (len < 0 || len >= sizeof(buf)) {
5955 sigma_dut_print(dut, DUT_MSG_ERROR,
5956 "Failed to build MSCS Descriptor IE");
5957 return ERROR_SEND_STATUS;
5958 }
5959
5960 if (wpa_command(intf, buf) != 0) {
5961 send_resp(dut, conn, SIGMA_ERROR,
5962 "ErrorCode,Failed to include MSCS descriptor");
5963 return STATUS_SENT_ERROR;
5964 }
5965 }
5966
Vinita S. Maloo2287f142021-02-01 16:17:09 +05305967 val = get_param(cmd, "SCSSupport");
5968 if (val) {
5969 char buf[30];
5970 int disable_scs, len;
5971
5972 if (strcasecmp(val, "Enable") == 0) {
5973 disable_scs = 0;
5974 } else if (strcasecmp(val, "Disable") == 0) {
5975 disable_scs = 1;
5976 } else {
5977 sigma_dut_print(dut, DUT_MSG_ERROR,
5978 "Invalid SCSsupport parameter");
5979 return INVALID_SEND_STATUS;
5980 }
5981
Shivani Baranwalebde8f62021-10-19 12:26:02 +05305982 if (disable_scs || dut->prev_disable_scs_support) {
5983 len = snprintf(buf, sizeof(buf),
5984 "SET disable_scs_support %d",
5985 disable_scs);
5986 if (len < 0 || len >= sizeof(buf) ||
5987 wpa_command(intf, buf) != 0) {
5988 send_resp(dut, conn, SIGMA_ERROR,
5989 "ErrorCode,Failed to update SCS support");
5990 return STATUS_SENT_ERROR;
5991 }
5992 dut->prev_disable_scs_support = disable_scs;
Vinita S. Maloo2287f142021-02-01 16:17:09 +05305993 }
5994 }
5995
Vinita S. Maloo83dee552021-04-12 16:47:47 +05305996 val = get_param(cmd, "MSCSSupport");
5997 if (val) {
5998 char buf[30];
5999 int disable_mscs, len;
6000
6001 if (strcasecmp(val, "Enable") == 0) {
6002 disable_mscs = 0;
6003 } else if (strcasecmp(val, "Disable") == 0) {
6004 disable_mscs = 1;
6005 } else {
6006 sigma_dut_print(dut, DUT_MSG_ERROR,
6007 "Invalid MSCSsupport parameter");
6008 return INVALID_SEND_STATUS;
6009 }
6010
Shivani Baranwalebde8f62021-10-19 12:26:02 +05306011 if (disable_mscs || dut->prev_disable_mscs_support) {
6012 len = snprintf(buf, sizeof(buf),
6013 "SET disable_mscs_support %d",
6014 disable_mscs);
6015 if (len < 0 || len >= sizeof(buf) ||
6016 wpa_command(intf, buf) != 0) {
6017 send_resp(dut, conn, SIGMA_ERROR,
6018 "ErrorCode,Failed to update MSCS support");
6019 return STATUS_SENT_ERROR;
6020 }
6021 dut->prev_disable_mscs_support = disable_mscs;
Vinita S. Maloo83dee552021-04-12 16:47:47 +05306022 }
6023 }
6024
Veerendranath Jakkama16cdc82021-09-12 16:44:22 +05306025 val = get_param(cmd, "DSCPPolicyCapability");
6026 if (val) {
6027 char buf[35];
6028 int len;
6029
6030 if (strcasecmp(val, "Enable") == 0) {
6031 len = snprintf(buf, sizeof(buf),
6032 "SET enable_dscp_policy_capa 1");
6033 } else if (strcasecmp(val, "Disable") == 0) {
6034 len = snprintf(buf, sizeof(buf),
6035 "SET enable_dscp_policy_capa 0");
6036 } else {
6037 sigma_dut_print(dut, DUT_MSG_ERROR,
6038 "Invalid DSCP policy parameter");
6039 return INVALID_SEND_STATUS;
6040 }
6041
6042 if (len < 0 || len >= sizeof(buf) ||
6043 wpa_command(intf, buf) != 0) {
6044 send_resp(dut, conn, SIGMA_ERROR,
6045 "ErrorCode,Failed to update DSCP policy capability");
6046 return STATUS_SENT_ERROR;
6047 }
6048 }
6049
6050 val = get_param(cmd, "DSCPPolicyRespParams");
6051 if (val) {
6052 if (strcasecmp(val, "RejectAll") == 0) {
6053 dut->reject_dscp_policies = 1;
6054 dut->dscp_reject_resp_code = DSCP_POLICY_REJECT;
6055 } else if (strcasecmp(val, "AcceptAll") == 0) {
6056 dut->reject_dscp_policies = 0;
6057 }
6058 }
6059
6060 val = get_param(cmd, "DSCPPolicyResp_StatusCode");
6061 if (val)
6062 dut->dscp_reject_resp_code = atoi(val);
6063
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006064 return 1;
6065}
6066
6067
6068static const char * ath_get_radio_name(const char *radio_name)
6069{
6070 if (radio_name == NULL)
6071 return "wifi0";
6072 if (strcmp(radio_name, "wifi1") == 0)
6073 return "wifi1";
6074 if (strcmp(radio_name, "wifi2") == 0)
6075 return "wifi2";
6076 return "wifi0";
6077}
6078
6079
6080static void ath_sta_set_txsp_stream(struct sigma_dut *dut, const char *intf,
6081 const char *val)
6082{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006083 unsigned int vht_mcsmap = 0;
6084 int txchainmask = 0;
6085 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
6086
6087 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
6088 if (dut->testbed_flag_txsp == 1) {
6089 vht_mcsmap = 0xfffc;
6090 dut->testbed_flag_txsp = 0;
6091 } else {
6092 vht_mcsmap = 0xfffe;
6093 }
6094 txchainmask = 1;
6095 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
6096 if (dut->testbed_flag_txsp == 1) {
6097 vht_mcsmap = 0xfff0;
6098 dut->testbed_flag_txsp = 0;
6099 } else {
6100 vht_mcsmap = 0xfffa;
6101 }
6102 txchainmask = 3;
6103 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
6104 if (dut->testbed_flag_txsp == 1) {
6105 vht_mcsmap = 0xffc0;
6106 dut->testbed_flag_txsp = 0;
6107 } else {
6108 vht_mcsmap = 0xffea;
6109 }
6110 txchainmask = 7;
6111 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
6112 if (dut->testbed_flag_txsp == 1) {
6113 vht_mcsmap = 0xff00;
6114 dut->testbed_flag_txsp = 0;
6115 } else {
6116 vht_mcsmap = 0xffaa;
6117 }
6118 txchainmask = 15;
6119 } else {
6120 if (dut->testbed_flag_txsp == 1) {
6121 vht_mcsmap = 0xffc0;
6122 dut->testbed_flag_txsp = 0;
6123 } else {
6124 vht_mcsmap = 0xffea;
6125 }
6126 }
6127
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006128 if (txchainmask)
6129 run_iwpriv(dut, basedev, "txchainmask %d", txchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006130
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006131 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006132}
6133
6134
6135static void ath_sta_set_rxsp_stream(struct sigma_dut *dut, const char *intf,
6136 const char *val)
6137{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006138 unsigned int vht_mcsmap = 0;
6139 int rxchainmask = 0;
6140 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
6141
6142 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
6143 if (dut->testbed_flag_rxsp == 1) {
6144 vht_mcsmap = 0xfffc;
6145 dut->testbed_flag_rxsp = 0;
6146 } else {
6147 vht_mcsmap = 0xfffe;
6148 }
6149 rxchainmask = 1;
6150 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
6151 if (dut->testbed_flag_rxsp == 1) {
6152 vht_mcsmap = 0xfff0;
6153 dut->testbed_flag_rxsp = 0;
6154 } else {
6155 vht_mcsmap = 0xfffa;
6156 }
6157 rxchainmask = 3;
6158 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
6159 if (dut->testbed_flag_rxsp == 1) {
6160 vht_mcsmap = 0xffc0;
6161 dut->testbed_flag_rxsp = 0;
6162 } else {
6163 vht_mcsmap = 0xffea;
6164 }
6165 rxchainmask = 7;
6166 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
6167 if (dut->testbed_flag_rxsp == 1) {
6168 vht_mcsmap = 0xff00;
6169 dut->testbed_flag_rxsp = 0;
6170 } else {
6171 vht_mcsmap = 0xffaa;
6172 }
6173 rxchainmask = 15;
6174 } else {
6175 if (dut->testbed_flag_rxsp == 1) {
6176 vht_mcsmap = 0xffc0;
6177 dut->testbed_flag_rxsp = 0;
6178 } else {
6179 vht_mcsmap = 0xffea;
6180 }
6181 }
6182
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006183 if (rxchainmask)
6184 run_iwpriv(dut, basedev, "rxchainmask %d", rxchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006185
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006186 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006187}
6188
6189
6190void ath_set_zero_crc(struct sigma_dut *dut, const char *val)
6191{
6192 if (strcasecmp(val, "enable") == 0) {
6193 if (system("athdiag --set --address=0x2a204 --and=0xbfffffff")
6194 != 0) {
6195 sigma_dut_print(dut, DUT_MSG_ERROR,
6196 "Disable BB_VHTSIGB_CRC_CALC failed");
6197 }
6198
6199 if (system("athdiag --set --address=0x2a204 --or=0x80000000")
6200 != 0) {
6201 sigma_dut_print(dut, DUT_MSG_ERROR,
6202 "Enable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
6203 }
6204 } else {
6205 if (system("athdiag --set --address=0x2a204 --and=0x7fffffff")
6206 != 0) {
6207 sigma_dut_print(dut, DUT_MSG_ERROR,
6208 "Disable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
6209 }
6210
6211 if (system("athdiag --set --address=0x2a204 --or=0x40000000")
6212 != 0) {
6213 sigma_dut_print(dut, DUT_MSG_ERROR,
6214 "Enable BB_VHTSIGB_CRC_CALC failed");
6215 }
6216 }
6217}
6218
6219
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08006220static int wcn_sta_set_width(struct sigma_dut *dut, const char *intf,
6221 const char *val)
6222{
6223 char buf[60];
6224
Shivani Baranwal2a572842021-09-16 12:27:15 +05306225#ifdef NL80211_SUPPORT
6226 enum nl80211_chan_width qca_channel_width;
6227
6228 if (strcmp(val, "20") == 0) {
6229 qca_channel_width = NL80211_CHAN_WIDTH_20;
6230 dut->chwidth = 0;
6231 } else if (strcmp(val, "40") == 0) {
6232 qca_channel_width = NL80211_CHAN_WIDTH_40;
6233 dut->chwidth = 1;
6234 } else if (strcmp(val, "80") == 0) {
6235 qca_channel_width = NL80211_CHAN_WIDTH_80;
6236 dut->chwidth = 2;
6237 } else if (strcmp(val, "160") == 0) {
6238 qca_channel_width = NL80211_CHAN_WIDTH_160;
6239 dut->chwidth = 3;
6240 } else if (strcasecmp(val, "Auto") == 0) {
6241 return 0;
6242 } else {
6243 sigma_dut_print(dut, DUT_MSG_ERROR, "WIDTH %s not supported",
6244 val);
6245 return -1;
6246 }
6247 if (sta_config_params(dut, intf, STA_SET_CHAN_WIDTH,
6248 qca_channel_width) == 0)
6249 return 0;
6250#endif /* NL80211_SUPPORT */
6251
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08006252 if (strcmp(val, "20") == 0) {
6253 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
6254 dut->chwidth = 0;
6255 } else if (strcmp(val, "40") == 0) {
6256 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 1", intf);
6257 dut->chwidth = 1;
6258 } else if (strcmp(val, "80") == 0) {
6259 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
6260 dut->chwidth = 2;
Sunil Duttb1cccac2018-05-22 21:03:12 +05306261 } else if (strcasecmp(val, "Auto") == 0) {
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08006262 buf[0] = '\0';
6263 } else {
6264 sigma_dut_print(dut, DUT_MSG_ERROR, "WIDTH %s not supported",
6265 val);
6266 return -1;
6267 }
6268
6269 if (buf[0] != '\0' && system(buf) != 0) {
6270 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv chwidth failed");
6271 return -1;
6272 }
6273
6274 return 0;
6275}
6276
6277
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08006278static int nlvendor_sta_set_addba_reject(struct sigma_dut *dut,
6279 const char *intf, int addbareject)
6280{
6281#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05306282 return wcn_wifi_test_config_set_u8(
6283 dut, intf,
6284 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ACCEPT_ADDBA_REQ,
6285 !addbareject);
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08006286#else /* NL80211_SUPPORT */
6287 sigma_dut_print(dut, DUT_MSG_ERROR,
6288 "ADDBA_REJECT cannot be set without NL80211_SUPPORT defined");
6289 return -1;
6290#endif /* NL80211_SUPPORT */
6291}
6292
6293
6294static int sta_set_addba_reject(struct sigma_dut *dut, const char *intf,
6295 int addbareject)
6296{
6297 int ret;
6298
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006299 switch (get_driver_type(dut)) {
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08006300 case DRIVER_WCN:
6301 ret = nlvendor_sta_set_addba_reject(dut, intf, addbareject);
6302 if (ret) {
6303 sigma_dut_print(dut, DUT_MSG_ERROR,
6304 "nlvendor_sta_set_addba_reject failed, ret:%d",
6305 ret);
6306 return ret;
6307 }
6308 break;
6309 default:
6310 sigma_dut_print(dut, DUT_MSG_ERROR,
6311 "errorCode,Unsupported ADDBA_REJECT with the current driver");
6312 ret = -1;
6313 break;
6314 }
6315
6316 return ret;
6317}
6318
6319
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08006320static int nlvendor_config_send_addba(struct sigma_dut *dut, const char *intf,
6321 int enable)
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08006322{
6323#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05306324 return wcn_wifi_test_config_set_u8(
6325 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SEND_ADDBA_REQ,
6326 enable);
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08006327#else /* NL80211_SUPPORT */
6328 sigma_dut_print(dut, DUT_MSG_ERROR,
6329 "Disable addba not possible without NL80211_SUPPORT defined");
6330 return -1;
6331#endif /* NL80211_SUPPORT */
6332}
6333
6334
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05306335#ifdef NL80211_SUPPORT
6336static int nl80211_sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
6337{
6338 struct nl_msg *msg;
6339 int ret = 0;
6340 int ifindex;
6341
6342 ifindex = if_nametoindex(intf);
6343 if (ifindex == 0) {
6344 sigma_dut_print(dut, DUT_MSG_ERROR,
6345 "%s: Index for interface %s failed",
6346 __func__, intf);
6347 return -1;
6348 }
6349
6350 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6351 NL80211_CMD_SET_WIPHY)) ||
6352 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) {
6353 sigma_dut_print(dut, DUT_MSG_ERROR,
6354 "%s: err in adding RTS threshold",
6355 __func__);
6356 nlmsg_free(msg);
6357 return -1;
6358 }
6359
6360 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6361 if (ret) {
6362 sigma_dut_print(dut, DUT_MSG_ERROR,
6363 "%s: err in send_and_recv_msgs, ret=%d",
6364 __func__, ret);
6365 }
6366 return ret;
6367}
6368#endif /* NL80211_SUPPORT */
6369
6370
6371static int sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
6372{
6373 char buf[100];
6374
6375#ifdef NL80211_SUPPORT
6376 if (nl80211_sta_set_rts(dut, intf, val) == 0)
6377 return 0;
6378 sigma_dut_print(dut, DUT_MSG_DEBUG,
6379 "Fall back to using iwconfig for setting RTS threshold");
6380#endif /* NL80211_SUPPORT */
6381
6382 snprintf(buf, sizeof(buf), "iwconfig %s rts %d", intf, val);
6383 if (system(buf) != 0) {
6384 sigma_dut_print(dut, DUT_MSG_ERROR,
6385 "Failed to set RTS threshold %d", val);
6386 return -1;
6387 }
6388 return 0;
6389}
6390
6391
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006392static enum sigma_cmd_result
6393cmd_sta_set_wireless_common(const char *intf, struct sigma_dut *dut,
6394 struct sigma_conn *conn, struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006395{
6396 const char *val;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08006397 int ampdu = -1, addbareject = -1;
Jouni Malinen3aa72862019-05-29 23:14:51 +03006398 char buf[128];
6399 int res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006400
6401 val = get_param(cmd, "40_INTOLERANT");
6402 if (val) {
6403 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
6404 /* TODO: iwpriv ht40intol through wpa_supplicant */
6405 send_resp(dut, conn, SIGMA_ERROR,
6406 "ErrorCode,40_INTOLERANT not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006407 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006408 }
6409 }
6410
6411 val = get_param(cmd, "ADDBA_REJECT");
6412 if (val) {
6413 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
6414 /* reject any ADDBA with status "decline" */
6415 ampdu = 0;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08006416 addbareject = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006417 } else {
6418 /* accept ADDBA */
6419 ampdu = 1;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08006420 addbareject = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006421 }
6422 }
6423
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08006424 if (addbareject >= 0 &&
6425 sta_set_addba_reject(dut, intf, addbareject) < 0) {
6426 send_resp(dut, conn, SIGMA_ERROR,
6427 "ErrorCode,set addba_reject failed");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006428 return STATUS_SENT_ERROR;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08006429 }
6430
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006431 val = get_param(cmd, "AMPDU");
6432 if (val) {
6433 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
6434 /* enable AMPDU Aggregation */
6435 if (ampdu == 0) {
6436 send_resp(dut, conn, SIGMA_ERROR,
6437 "ErrorCode,Mismatch in "
6438 "addba_reject/ampdu - "
6439 "not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006440 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006441 }
6442 ampdu = 1;
6443 } else {
6444 /* disable AMPDU Aggregation */
6445 if (ampdu == 1) {
6446 send_resp(dut, conn, SIGMA_ERROR,
6447 "ErrorCode,Mismatch in "
6448 "addba_reject/ampdu - "
6449 "not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006450 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006451 }
6452 ampdu = 0;
6453 }
6454 }
6455
6456 if (ampdu >= 0) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08006457 int ret;
6458
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006459 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s A-MPDU aggregation",
6460 ampdu ? "Enabling" : "Disabling");
6461 snprintf(buf, sizeof(buf), "SET ampdu %d", ampdu);
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07006462 if (wpa_command(intf, buf) < 0 &&
6463 iwpriv_sta_set_ampdu(dut, intf, ampdu) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006464 send_resp(dut, conn, SIGMA_ERROR,
6465 "ErrorCode,set aggr failed");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006466 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006467 }
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08006468
6469 if (ampdu == 0) {
6470 /* Disable sending of addba using nl vendor command */
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08006471 ret = nlvendor_config_send_addba(dut, intf, 0);
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08006472 if (ret) {
6473 sigma_dut_print(dut, DUT_MSG_ERROR,
6474 "Failed to disable addba, ret:%d",
6475 ret);
6476 }
6477 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006478 }
6479
6480 val = get_param(cmd, "AMSDU");
6481 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006482 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006483 case DRIVER_ATHEROS:
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08006484 case DRIVER_WCN:
6485 iwpriv_sta_set_amsdu(dut, intf, val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006486 break;
6487 default:
6488 if (strcmp(val, "1") == 0 ||
6489 strcasecmp(val, "Enable") == 0) {
6490 /* Enable AMSDU Aggregation */
6491 send_resp(dut, conn, SIGMA_ERROR,
6492 "ErrorCode,AMSDU aggregation not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006493 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006494 }
6495 break;
6496 }
6497 }
6498
6499 val = get_param(cmd, "STBC_RX");
6500 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006501 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006502 case DRIVER_ATHEROS:
6503 ath_sta_set_stbc(dut, intf, val);
6504 break;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05306505 case DRIVER_WCN:
6506 wcn_sta_set_stbc(dut, intf, val);
6507 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006508 default:
6509 send_resp(dut, conn, SIGMA_ERROR,
6510 "ErrorCode,STBC_RX not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006511 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006512 }
6513 }
6514
6515 val = get_param(cmd, "WIDTH");
6516 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006517 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006518 case DRIVER_WCN:
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08006519 if (wcn_sta_set_width(dut, intf, val) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006520 send_resp(dut, conn, SIGMA_ERROR,
6521 "ErrorCode,Failed to set WIDTH");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006522 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006523 }
6524 break;
6525 case DRIVER_ATHEROS:
6526 if (ath_set_width(dut, conn, intf, val) < 0)
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006527 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006528 break;
6529 default:
6530 sigma_dut_print(dut, DUT_MSG_ERROR,
6531 "Setting WIDTH not supported");
6532 break;
6533 }
6534 }
6535
6536 val = get_param(cmd, "SMPS");
6537 if (val) {
6538 /* TODO: Dynamic/0, Static/1, No Limit/2 */
6539 send_resp(dut, conn, SIGMA_ERROR,
6540 "ErrorCode,SMPS not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006541 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006542 }
6543
6544 val = get_param(cmd, "TXSP_STREAM");
6545 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006546 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006547 case DRIVER_WCN:
6548 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
6549 send_resp(dut, conn, SIGMA_ERROR,
6550 "ErrorCode,Failed to set TXSP_STREAM");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006551 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006552 }
6553 break;
6554 case DRIVER_ATHEROS:
6555 ath_sta_set_txsp_stream(dut, intf, val);
6556 break;
6557 default:
6558 sigma_dut_print(dut, DUT_MSG_ERROR,
6559 "Setting TXSP_STREAM not supported");
6560 break;
6561 }
6562 }
6563
6564 val = get_param(cmd, "RXSP_STREAM");
6565 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006566 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006567 case DRIVER_WCN:
6568 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
6569 send_resp(dut, conn, SIGMA_ERROR,
6570 "ErrorCode,Failed to set RXSP_STREAM");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006571 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006572 }
6573 break;
6574 case DRIVER_ATHEROS:
6575 ath_sta_set_rxsp_stream(dut, intf, val);
6576 break;
6577 default:
6578 sigma_dut_print(dut, DUT_MSG_ERROR,
6579 "Setting RXSP_STREAM not supported");
6580 break;
6581 }
6582 }
6583
6584 val = get_param(cmd, "DYN_BW_SGNL");
6585 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006586 switch (get_driver_type(dut)) {
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08006587 case DRIVER_WCN:
Peng Xuc59afd32016-11-21 15:01:11 -08006588 if (strcasecmp(val, "enable") == 0) {
6589 snprintf(buf, sizeof(buf),
6590 "iwpriv %s cwmenable 1", intf);
6591 if (system(buf) != 0) {
6592 sigma_dut_print(dut, DUT_MSG_ERROR,
6593 "iwpriv cwmenable 1 failed");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006594 return ERROR_SEND_STATUS;
Peng Xuc59afd32016-11-21 15:01:11 -08006595 }
6596 } else if (strcasecmp(val, "disable") == 0) {
6597 snprintf(buf, sizeof(buf),
6598 "iwpriv %s cwmenable 0", intf);
6599 if (system(buf) != 0) {
6600 sigma_dut_print(dut, DUT_MSG_ERROR,
6601 "iwpriv cwmenable 0 failed");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006602 return ERROR_SEND_STATUS;
Peng Xuc59afd32016-11-21 15:01:11 -08006603 }
6604 } else {
6605 sigma_dut_print(dut, DUT_MSG_ERROR,
6606 "Unsupported DYN_BW_SGL");
6607 }
6608
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006609 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
6610 if (system(buf) != 0) {
6611 sigma_dut_print(dut, DUT_MSG_ERROR,
6612 "Failed to set cts_cbw in DYN_BW_SGNL");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006613 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006614 }
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08006615 break;
6616 case DRIVER_ATHEROS:
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07006617 novap_reset(dut, intf, 1);
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08006618 ath_config_dyn_bw_sig(dut, intf, val);
6619 break;
6620 default:
6621 sigma_dut_print(dut, DUT_MSG_ERROR,
6622 "Failed to set DYN_BW_SGNL");
6623 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006624 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006625 }
6626
6627 val = get_param(cmd, "RTS_FORCE");
6628 if (val) {
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07006629 novap_reset(dut, intf, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006630 if (strcasecmp(val, "Enable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05306631 if (sta_set_rts(dut, intf, 64) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02006632 sigma_dut_print(dut, DUT_MSG_ERROR,
6633 "Failed to set RTS_FORCE 64");
6634 }
Jouni Malinen3aa72862019-05-29 23:14:51 +03006635 res = snprintf(buf, sizeof(buf),
6636 "wifitool %s beeliner_fw_test 100 1",
6637 intf);
6638 if (res < 0 || res >= sizeof(buf) || system(buf) != 0) {
priyadharshini gowthaman270870e2015-12-09 10:10:23 -08006639 sigma_dut_print(dut, DUT_MSG_ERROR,
6640 "wifitool beeliner_fw_test 100 1 failed");
6641 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006642 } else if (strcasecmp(val, "Disable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05306643 if (sta_set_rts(dut, intf, 2347) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02006644 sigma_dut_print(dut, DUT_MSG_ERROR,
6645 "Failed to set RTS_FORCE 2347");
6646 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006647 } else {
6648 send_resp(dut, conn, SIGMA_ERROR,
6649 "ErrorCode,RTS_FORCE value not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006650 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006651 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006652 }
6653
6654 val = get_param(cmd, "CTS_WIDTH");
6655 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006656 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006657 case DRIVER_WCN:
6658 if (wcn_sta_set_cts_width(dut, intf, val) < 0) {
6659 send_resp(dut, conn, SIGMA_ERROR,
6660 "ErrorCode,Failed to set CTS_WIDTH");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006661 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006662 }
6663 break;
6664 case DRIVER_ATHEROS:
6665 ath_set_cts_width(dut, intf, val);
6666 break;
6667 default:
6668 sigma_dut_print(dut, DUT_MSG_ERROR,
6669 "Setting CTS_WIDTH not supported");
6670 break;
6671 }
6672 }
6673
6674 val = get_param(cmd, "BW_SGNL");
6675 if (val) {
6676 if (strcasecmp(val, "Enable") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006677 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006678 } else if (strcasecmp(val, "Disable") == 0) {
6679 /* TODO: Disable */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006680 } else {
6681 send_resp(dut, conn, SIGMA_ERROR,
6682 "ErrorCode,BW_SGNL value not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006683 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006684 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006685 }
6686
6687 val = get_param(cmd, "Band");
6688 if (val) {
6689 if (strcmp(val, "2.4") == 0 || strcmp(val, "5") == 0) {
6690 /* STA supports all bands by default */
6691 } else {
6692 send_resp(dut, conn, SIGMA_ERROR,
6693 "ErrorCode,Unsupported Band");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006694 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006695 }
6696 }
6697
6698 val = get_param(cmd, "zero_crc");
6699 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006700 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006701 case DRIVER_ATHEROS:
6702 ath_set_zero_crc(dut, val);
6703 break;
6704 default:
6705 break;
6706 }
6707 }
6708
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006709 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006710}
6711
6712
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006713static int sta_set_force_mcs(struct sigma_dut *dut, int force, int mcs)
6714{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006715 switch (get_driver_type(dut)) {
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006716#ifdef __linux__
6717 case DRIVER_WIL6210:
6718 return wil6210_set_force_mcs(dut, force, mcs);
6719#endif /* __linux__ */
6720 default:
6721 sigma_dut_print(dut, DUT_MSG_ERROR,
6722 "Unsupported sta_set_force_mcs with the current driver");
6723 return -1;
6724 }
6725}
6726
6727
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02006728static int sta_60g_force_rsn_ie(struct sigma_dut *dut, int state)
6729{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006730 switch (get_driver_type(dut)) {
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02006731#ifdef __linux__
6732 case DRIVER_WIL6210:
6733 return wil6210_force_rsn_ie(dut, state);
6734#endif /* __linux__ */
6735 default:
6736 sigma_dut_print(dut, DUT_MSG_ERROR,
6737 "Unsupported sta_60g_force_rsn_ie with the current driver");
6738 return -1;
6739 }
6740}
6741
6742
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006743static int sta_set_60g_common(struct sigma_dut *dut, struct sigma_conn *conn,
6744 struct sigma_cmd *cmd)
6745{
6746 const char *val;
6747 char buf[100];
6748
6749 val = get_param(cmd, "MSDUSize");
6750 if (val) {
6751 int mtu;
6752
6753 dut->amsdu_size = atoi(val);
6754 if (dut->amsdu_size > IEEE80211_MAX_DATA_LEN_DMG ||
6755 dut->amsdu_size < IEEE80211_SNAP_LEN_DMG) {
6756 sigma_dut_print(dut, DUT_MSG_ERROR,
6757 "MSDUSize %d is above max %d or below min %d",
6758 dut->amsdu_size,
6759 IEEE80211_MAX_DATA_LEN_DMG,
6760 IEEE80211_SNAP_LEN_DMG);
6761 dut->amsdu_size = 0;
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006762 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006763 }
6764
6765 mtu = dut->amsdu_size - IEEE80211_SNAP_LEN_DMG;
6766 sigma_dut_print(dut, DUT_MSG_DEBUG,
6767 "Setting amsdu_size to %d", mtu);
6768 snprintf(buf, sizeof(buf), "ifconfig %s mtu %d",
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006769 get_station_ifname(dut), mtu);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006770
6771 if (system(buf) != 0) {
6772 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
6773 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006774 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006775 }
6776 }
6777
6778 val = get_param(cmd, "BAckRcvBuf");
6779 if (val) {
6780 dut->back_rcv_buf = atoi(val);
6781 if (dut->back_rcv_buf == 0) {
6782 sigma_dut_print(dut, DUT_MSG_ERROR,
6783 "Failed to convert %s or value is 0",
6784 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006785 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006786 }
6787
6788 sigma_dut_print(dut, DUT_MSG_DEBUG,
6789 "Setting BAckRcvBuf to %s", val);
6790 }
6791
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006792 val = get_param(cmd, "MCS_FixedRate");
6793 if (val) {
6794 if (sta_set_force_mcs(dut, 1, atoi(val))) {
6795 sigma_dut_print(dut, DUT_MSG_ERROR,
6796 "Failed to force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006797 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006798 }
6799 }
6800
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006801 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006802}
6803
6804
6805static int sta_pcp_start(struct sigma_dut *dut, struct sigma_conn *conn,
6806 struct sigma_cmd *cmd)
6807{
6808 int net_id;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006809 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006810 const char *val;
6811 char buf[100];
6812
6813 dut->mode = SIGMA_MODE_STATION;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006814 ifname = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006815 if (wpa_command(ifname, "PING") != 0) {
6816 sigma_dut_print(dut, DUT_MSG_ERROR, "Supplicant not running");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006817 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006818 }
6819
6820 wpa_command(ifname, "FLUSH");
6821 net_id = add_network_common(dut, conn, ifname, cmd);
6822 if (net_id < 0) {
6823 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add network");
6824 return net_id;
6825 }
6826
6827 /* TODO: mode=2 for the AP; in the future, replace for mode PCP */
6828 if (set_network(ifname, net_id, "mode", "2") < 0) {
6829 sigma_dut_print(dut, DUT_MSG_ERROR,
6830 "Failed to set supplicant network mode");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006831 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006832 }
6833
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02006834 if (set_network(ifname, net_id, "pbss", "1") < 0)
6835 return -2;
6836
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006837 sigma_dut_print(dut, DUT_MSG_DEBUG,
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02006838 "Supplicant set network with mode 2. network_id %d",
6839 net_id);
6840
6841 if (set_network(ifname, net_id, "wps_disabled", "0") < 0) {
6842 sigma_dut_print(dut, DUT_MSG_INFO,
6843 "Failed to set supplicant to WPS ENABLE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006844 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02006845 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006846
6847 val = get_param(cmd, "Security");
6848 if (val && strcasecmp(val, "OPEN") == 0) {
6849 dut->ap_key_mgmt = AP_OPEN;
6850 if (set_network(ifname, net_id, "key_mgmt", "NONE") < 0) {
6851 sigma_dut_print(dut, DUT_MSG_ERROR,
6852 "Failed to set supplicant to %s security",
6853 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006854 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006855 }
6856 } else if (val && strcasecmp(val, "WPA2-PSK") == 0) {
6857 dut->ap_key_mgmt = AP_WPA2_PSK;
6858 if (set_network(ifname, net_id, "key_mgmt", "WPA-PSK") < 0) {
6859 sigma_dut_print(dut, DUT_MSG_ERROR,
6860 "Failed to set supplicant to %s security",
6861 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006862 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006863 }
6864
6865 if (set_network(ifname, net_id, "proto", "RSN") < 0) {
6866 sigma_dut_print(dut, DUT_MSG_ERROR,
6867 "Failed to set supplicant to proto RSN");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006868 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006869 }
6870 } else if (val) {
6871 sigma_dut_print(dut, DUT_MSG_ERROR,
6872 "Requested Security %s is not supported on 60GHz",
6873 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006874 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006875 }
6876
6877 val = get_param(cmd, "Encrypt");
6878 if (val && strcasecmp(val, "AES-GCMP") == 0) {
6879 if (set_network(ifname, net_id, "pairwise", "GCMP") < 0) {
6880 sigma_dut_print(dut, DUT_MSG_ERROR,
6881 "Failed to set supplicant to pairwise GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006882 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006883 }
6884 if (set_network(ifname, net_id, "group", "GCMP") < 0) {
6885 sigma_dut_print(dut, DUT_MSG_ERROR,
6886 "Failed to set supplicant to group GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006887 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006888 }
6889 } else if (val) {
6890 sigma_dut_print(dut, DUT_MSG_ERROR,
6891 "Requested Encrypt %s is not supported on 60 GHz",
6892 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006893 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006894 }
6895
6896 val = get_param(cmd, "PSK");
6897 if (val && set_network_quoted(ifname, net_id, "psk", val) < 0) {
6898 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set psk %s",
6899 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006900 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006901 }
6902
6903 /* Convert 60G channel to freq */
6904 switch (dut->ap_channel) {
6905 case 1:
6906 val = "58320";
6907 break;
6908 case 2:
6909 val = "60480";
6910 break;
6911 case 3:
6912 val = "62640";
6913 break;
6914 default:
6915 sigma_dut_print(dut, DUT_MSG_ERROR,
6916 "Failed to configure channel %d. Not supported",
6917 dut->ap_channel);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006918 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006919 }
6920
6921 if (set_network(ifname, net_id, "frequency", val) < 0) {
6922 sigma_dut_print(dut, DUT_MSG_ERROR,
6923 "Failed to set supplicant network frequency");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006924 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006925 }
6926
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02006927 if (dut->eap_fragment) {
6928 sigma_dut_print(dut, DUT_MSG_DEBUG,
6929 "Set EAP fragment size to 128 bytes.");
6930 if (set_network(ifname, net_id, "fragment_size", "128") < 0)
6931 return ERROR_SEND_STATUS;
6932 }
6933
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006934 sigma_dut_print(dut, DUT_MSG_DEBUG,
6935 "Supplicant set network with frequency");
6936
6937 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d", net_id);
6938 if (wpa_command(ifname, buf) < 0) {
6939 sigma_dut_print(dut, DUT_MSG_INFO,
6940 "Failed to select network id %d on %s",
6941 net_id, ifname);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006942 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006943 }
6944
6945 sigma_dut_print(dut, DUT_MSG_DEBUG, "Selected network");
6946
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006947 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006948}
6949
6950
Lior David67543f52017-01-03 19:04:22 +02006951static int wil6210_set_abft_len(struct sigma_dut *dut, int abft_len)
6952{
6953 char buf[128], fname[128];
6954 FILE *f;
Jouni Malinen3aa72862019-05-29 23:14:51 +03006955 int res;
Lior David67543f52017-01-03 19:04:22 +02006956
6957 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
6958 sigma_dut_print(dut, DUT_MSG_ERROR,
6959 "failed to get wil6210 debugfs dir");
6960 return -1;
6961 }
6962
Jouni Malinen3aa72862019-05-29 23:14:51 +03006963 res = snprintf(fname, sizeof(fname), "%s/abft_len", buf);
6964 if (res < 0 || res >= sizeof(fname))
6965 return -1;
Lior David67543f52017-01-03 19:04:22 +02006966 f = fopen(fname, "w");
6967 if (!f) {
6968 sigma_dut_print(dut, DUT_MSG_ERROR,
6969 "failed to open: %s", fname);
6970 return -1;
6971 }
6972
6973 fprintf(f, "%d\n", abft_len);
6974 fclose(f);
6975
6976 return 0;
6977}
6978
6979
Alexei Avshalom Lazar49498b82019-01-31 15:16:32 +02006980int sta_set_60g_abft_len(struct sigma_dut *dut, struct sigma_conn *conn,
6981 int abft_len)
Lior David67543f52017-01-03 19:04:22 +02006982{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006983 switch (get_driver_type(dut)) {
Lior David67543f52017-01-03 19:04:22 +02006984 case DRIVER_WIL6210:
6985 return wil6210_set_abft_len(dut, abft_len);
6986 default:
6987 sigma_dut_print(dut, DUT_MSG_ERROR,
6988 "set abft_len not supported");
6989 return -1;
6990 }
6991}
6992
6993
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006994static int sta_set_60g_pcp(struct sigma_dut *dut, struct sigma_conn *conn,
6995 struct sigma_cmd *cmd)
6996{
6997 const char *val;
Lior David67543f52017-01-03 19:04:22 +02006998 unsigned int abft_len = 1; /* default is one slot */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006999
7000 if (dut->dev_role != DEVROLE_PCP) {
7001 send_resp(dut, conn, SIGMA_INVALID,
7002 "ErrorCode,Invalid DevRole");
7003 return 0;
7004 }
7005
7006 val = get_param(cmd, "SSID");
7007 if (val) {
7008 if (strlen(val) > sizeof(dut->ap_ssid) - 1) {
7009 send_resp(dut, conn, SIGMA_INVALID,
7010 "ErrorCode,Invalid SSID");
7011 return -1;
7012 }
7013
Peng Xub8fc5cc2017-05-10 17:27:28 -07007014 strlcpy(dut->ap_ssid, val, sizeof(dut->ap_ssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007015 }
7016
7017 val = get_param(cmd, "CHANNEL");
7018 if (val) {
7019 const char *pos;
7020
7021 dut->ap_channel = atoi(val);
7022 pos = strchr(val, ';');
7023 if (pos) {
7024 pos++;
7025 dut->ap_channel_1 = atoi(pos);
7026 }
7027 }
7028
7029 switch (dut->ap_channel) {
7030 case 1:
7031 case 2:
7032 case 3:
7033 break;
7034 default:
7035 sigma_dut_print(dut, DUT_MSG_ERROR,
7036 "Channel %d is not supported", dut->ap_channel);
7037 send_resp(dut, conn, SIGMA_ERROR,
7038 "Requested channel is not supported");
7039 return -1;
7040 }
7041
7042 val = get_param(cmd, "BCNINT");
7043 if (val)
7044 dut->ap_bcnint = atoi(val);
7045
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007046 val = get_param(cmd, "AllocType");
7047 if (val) {
7048 send_resp(dut, conn, SIGMA_ERROR,
7049 "ErrorCode,AllocType is not supported yet");
7050 return -1;
7051 }
7052
7053 val = get_param(cmd, "PercentBI");
7054 if (val) {
7055 send_resp(dut, conn, SIGMA_ERROR,
7056 "ErrorCode,PercentBI is not supported yet");
7057 return -1;
7058 }
7059
7060 val = get_param(cmd, "CBAPOnly");
7061 if (val) {
7062 send_resp(dut, conn, SIGMA_ERROR,
7063 "ErrorCode,CBAPOnly is not supported yet");
7064 return -1;
7065 }
7066
7067 val = get_param(cmd, "AMPDU");
7068 if (val) {
7069 if (strcasecmp(val, "Enable") == 0)
7070 dut->ap_ampdu = 1;
7071 else if (strcasecmp(val, "Disable") == 0)
7072 dut->ap_ampdu = 2;
7073 else {
7074 send_resp(dut, conn, SIGMA_ERROR,
7075 "ErrorCode,AMPDU value is not Enable nor Disabled");
7076 return -1;
7077 }
7078 }
7079
7080 val = get_param(cmd, "AMSDU");
7081 if (val) {
7082 if (strcasecmp(val, "Enable") == 0)
7083 dut->ap_amsdu = 1;
7084 else if (strcasecmp(val, "Disable") == 0)
7085 dut->ap_amsdu = 2;
7086 }
7087
7088 val = get_param(cmd, "NumMSDU");
7089 if (val) {
7090 send_resp(dut, conn, SIGMA_ERROR,
7091 "ErrorCode, NumMSDU is not supported yet");
7092 return -1;
7093 }
7094
7095 val = get_param(cmd, "ABFTLRang");
7096 if (val) {
7097 sigma_dut_print(dut, DUT_MSG_DEBUG,
Lior David67543f52017-01-03 19:04:22 +02007098 "ABFTLRang parameter %s", val);
7099 if (strcmp(val, "Gt1") == 0)
7100 abft_len = 2; /* 2 slots in this case */
7101 }
7102
7103 if (sta_set_60g_abft_len(dut, conn, abft_len)) {
7104 send_resp(dut, conn, SIGMA_ERROR,
7105 "ErrorCode, Can't set ABFT length");
7106 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007107 }
7108
7109 if (sta_pcp_start(dut, conn, cmd) < 0) {
7110 send_resp(dut, conn, SIGMA_ERROR,
7111 "ErrorCode, Can't start PCP role");
7112 return -1;
7113 }
7114
7115 return sta_set_60g_common(dut, conn, cmd);
7116}
7117
7118
7119static int sta_set_60g_sta(struct sigma_dut *dut, struct sigma_conn *conn,
7120 struct sigma_cmd *cmd)
7121{
7122 const char *val = get_param(cmd, "DiscoveryMode");
7123
7124 if (dut->dev_role != DEVROLE_STA) {
7125 send_resp(dut, conn, SIGMA_INVALID,
7126 "ErrorCode,Invalid DevRole");
7127 return 0;
7128 }
7129
7130 if (val) {
7131 sigma_dut_print(dut, DUT_MSG_DEBUG, "Discovery: %s", val);
7132 /* Ignore Discovery mode till Driver expose API. */
7133#if 0
7134 if (strcasecmp(val, "1") == 0) {
7135 send_resp(dut, conn, SIGMA_INVALID,
7136 "ErrorCode,DiscoveryMode 1 not supported");
7137 return 0;
7138 }
7139
7140 if (strcasecmp(val, "0") == 0) {
7141 /* OK */
7142 } else {
7143 send_resp(dut, conn, SIGMA_INVALID,
7144 "ErrorCode,DiscoveryMode not supported");
7145 return 0;
7146 }
7147#endif
7148 }
7149
7150 if (start_sta_mode(dut) != 0)
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007151 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007152 return sta_set_60g_common(dut, conn, cmd);
7153}
7154
7155
Jouni Malinenf7222712019-06-13 01:50:21 +03007156static enum sigma_cmd_result cmd_sta_disconnect(struct sigma_dut *dut,
7157 struct sigma_conn *conn,
7158 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007159{
7160 const char *intf = get_param(cmd, "Interface");
Jouni Malinened77e672018-01-10 16:45:13 +02007161 const char *val = get_param(cmd, "maintain_profile");
vamsi krishnad605c422017-09-20 14:56:31 +05307162
Jouni Malinened77e672018-01-10 16:45:13 +02007163 if (dut->program == PROGRAM_OCE ||
Amarnath Hullur Subramanyamebeda9e2018-01-31 03:21:48 -08007164 dut->program == PROGRAM_HE ||
Jouni Malinened77e672018-01-10 16:45:13 +02007165 (val && atoi(val) == 1)) {
vamsi krishnad605c422017-09-20 14:56:31 +05307166 wpa_command(intf, "DISCONNECT");
7167 return 1;
7168 }
7169
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007170 disconnect_station(dut);
7171 /* Try to ignore old scan results to avoid HS 2.0R2 test case failures
7172 * due to cached results. */
7173 wpa_command(intf, "SET ignore_old_scan_res 1");
7174 wpa_command(intf, "BSS_FLUSH");
7175 return 1;
7176}
7177
7178
Jouni Malinenf7222712019-06-13 01:50:21 +03007179static enum sigma_cmd_result cmd_sta_reassoc(struct sigma_dut *dut,
7180 struct sigma_conn *conn,
7181 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007182{
7183 const char *intf = get_param(cmd, "Interface");
7184 const char *bssid = get_param(cmd, "bssid");
7185 const char *val = get_param(cmd, "CHANNEL");
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07007186 const char *freq_val = get_param(cmd, "ChnlFreq");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007187 struct wpa_ctrl *ctrl;
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05307188 char buf[1000];
Sunil Duttd30ce092018-01-11 23:56:29 +05307189 char result[32];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007190 int res;
7191 int chan = 0;
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07007192 int freq = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007193 enum sigma_cmd_result status = STATUS_SENT;
Sunil Duttd30ce092018-01-11 23:56:29 +05307194 int fastreassoc = 1;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007195 int ft_ds = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007196
7197 if (bssid == NULL) {
7198 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing bssid "
7199 "argument");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007200 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007201 }
7202
7203 if (val)
7204 chan = atoi(val);
7205
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07007206 if (freq_val)
7207 freq = atoi(freq_val);
7208
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007209 if (wifi_chip_type != DRIVER_WCN && wifi_chip_type != DRIVER_AR6003) {
7210 /* The current network may be from sta_associate or
7211 * sta_hs2_associate
7212 */
7213 if (set_network(intf, dut->infra_network_id, "bssid", bssid) <
7214 0 ||
7215 set_network(intf, 0, "bssid", bssid) < 0)
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007216 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007217 }
7218
7219 ctrl = open_wpa_mon(intf);
7220 if (ctrl == NULL) {
7221 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
7222 "wpa_supplicant monitor connection");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007223 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007224 }
7225
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007226 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Sunil Duttd30ce092018-01-11 23:56:29 +05307227 sizeof(result)) < 0 ||
7228 strncmp(result, "COMPLETED", 9) != 0) {
7229 sigma_dut_print(dut, DUT_MSG_DEBUG,
7230 "sta_reassoc: Not connected");
7231 fastreassoc = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007232 } else if (dut->sta_ft_ds) {
7233 sigma_dut_print(dut, DUT_MSG_DEBUG,
7234 "sta_reassoc: Use FT-over-DS");
7235 ft_ds = 1;
Sunil Duttd30ce092018-01-11 23:56:29 +05307236 }
7237
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05307238 if (dut->rsne_override) {
7239#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007240 if (get_driver_type(dut) == DRIVER_WCN &&
7241 dut->config_rsnie == 0) {
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05307242 sta_config_params(dut, intf, STA_SET_RSNIE, 1);
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05307243 dut->config_rsnie = 1;
7244 }
7245#endif /* NL80211_SUPPORT */
7246 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
7247 dut->rsne_override);
7248 if (wpa_command(intf, buf) < 0) {
7249 send_resp(dut, conn, SIGMA_ERROR,
7250 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
7251 return 0;
7252 }
7253 }
7254
Shivani Baranwal7aa48602021-09-29 10:53:38 +05307255 if (ft_ds && get_driver_type(dut) != DRIVER_WCN) {
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07007256 if (chan || freq) {
7257 if (!freq)
7258 freq = channel_to_freq(dut, chan);
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007259 if (!freq) {
7260 sigma_dut_print(dut, DUT_MSG_ERROR,
7261 "Invalid channel number provided: %d",
7262 chan);
7263 send_resp(dut, conn, SIGMA_INVALID,
7264 "ErrorCode,Invalid channel number");
7265 goto close_mon_conn;
7266 }
7267 res = snprintf(buf, sizeof(buf),
7268 "SCAN TYPE=ONLY freq=%d", freq);
7269 } else {
7270 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
7271 }
7272 if (res < 0 || res >= (int) sizeof(buf)) {
7273 send_resp(dut, conn, SIGMA_ERROR,
7274 "ErrorCode,snprintf failed");
7275 goto close_mon_conn;
7276 }
7277 if (wpa_command(intf, buf) < 0) {
7278 sigma_dut_print(dut, DUT_MSG_INFO,
7279 "Failed to start scan");
7280 send_resp(dut, conn, SIGMA_ERROR,
7281 "ErrorCode,scan failed");
7282 goto close_mon_conn;
7283 }
7284
7285 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
7286 buf, sizeof(buf));
7287 if (res < 0) {
7288 sigma_dut_print(dut, DUT_MSG_INFO,
7289 "Scan did not complete");
7290 send_resp(dut, conn, SIGMA_ERROR,
7291 "ErrorCode,scan did not complete");
7292 goto close_mon_conn;
7293 }
7294
7295 res = snprintf(buf, sizeof(buf), "FT_DS %s", bssid);
7296 if (res > 0 && res < (int) sizeof(buf))
7297 res = wpa_command(intf, buf);
7298
7299 if (res < 0 || res >= (int) sizeof(buf)) {
7300 send_resp(dut, conn, SIGMA_ERROR,
7301 "errorCode,FT_DS command failed");
7302 status = STATUS_SENT_ERROR;
7303 goto close_mon_conn;
7304 }
7305 } else if (wifi_chip_type == DRIVER_WCN && fastreassoc) {
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07007306 if (chan || freq) {
7307 if (!freq)
7308 freq = channel_to_freq(dut, chan);
Ashwini Patil4c8158f2017-05-25 12:49:21 +05307309 if (!freq) {
7310 sigma_dut_print(dut, DUT_MSG_ERROR,
7311 "Invalid channel number provided: %d",
7312 chan);
7313 send_resp(dut, conn, SIGMA_INVALID,
7314 "ErrorCode,Invalid channel number");
7315 goto close_mon_conn;
7316 }
7317 res = snprintf(buf, sizeof(buf),
7318 "SCAN TYPE=ONLY freq=%d", freq);
7319 } else {
7320 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
7321 }
7322 if (res < 0 || res >= (int) sizeof(buf)) {
7323 send_resp(dut, conn, SIGMA_ERROR,
7324 "ErrorCode,snprintf failed");
7325 goto close_mon_conn;
7326 }
7327 if (wpa_command(intf, buf) < 0) {
7328 sigma_dut_print(dut, DUT_MSG_INFO,
7329 "Failed to start scan");
7330 send_resp(dut, conn, SIGMA_ERROR,
7331 "ErrorCode,scan failed");
7332 goto close_mon_conn;
7333 }
7334
7335 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
7336 buf, sizeof(buf));
7337 if (res < 0) {
7338 sigma_dut_print(dut, DUT_MSG_INFO,
7339 "Scan did not complete");
7340 send_resp(dut, conn, SIGMA_ERROR,
7341 "ErrorCode,scan did not complete");
7342 goto close_mon_conn;
7343 }
7344
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007345 if (set_network(intf, dut->infra_network_id, "bssid", "any")
7346 < 0) {
7347 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
7348 "bssid to any during FASTREASSOC");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007349 status = ERROR_SEND_STATUS;
Ashwini Patil467efef2017-05-25 12:18:27 +05307350 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007351 }
Vinita Maloo54b78cf2020-03-30 12:18:19 +05307352 res = snprintf(buf, sizeof(buf), "FASTREASSOC %s %d",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007353 bssid, chan);
Vinita Maloo54b78cf2020-03-30 12:18:19 +05307354 if (res < 0 || res >= (int) sizeof(buf) ||
7355 wcn_driver_cmd(intf, buf) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007356 send_resp(dut, conn, SIGMA_ERROR,
Vinita Maloo54b78cf2020-03-30 12:18:19 +05307357 "errorCode,Failed to run FASTREASSOC");
Ashwini Patil467efef2017-05-25 12:18:27 +05307358 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007359 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007360 sigma_dut_print(dut, DUT_MSG_INFO,
7361 "sta_reassoc: Run %s successful", buf);
7362 } else if (wpa_command(intf, "REASSOCIATE")) {
7363 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
7364 "request reassociation");
Ashwini Patil467efef2017-05-25 12:18:27 +05307365 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007366 }
7367
7368 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
7369 buf, sizeof(buf));
Ashwini Patil467efef2017-05-25 12:18:27 +05307370 if (res < 0) {
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007371 send_resp(dut, conn, SIGMA_ERROR,
7372 "errorCode,Connection did not complete");
7373 status = STATUS_SENT_ERROR;
Ashwini Patil467efef2017-05-25 12:18:27 +05307374 goto close_mon_conn;
7375 }
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007376 status = SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007377
Ashwini Patil467efef2017-05-25 12:18:27 +05307378close_mon_conn:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007379 wpa_ctrl_detach(ctrl);
7380 wpa_ctrl_close(ctrl);
Ashwini Patil467efef2017-05-25 12:18:27 +05307381 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007382}
7383
7384
7385static void hs2_clear_credentials(const char *intf)
7386{
7387 wpa_command(intf, "REMOVE_CRED all");
7388}
7389
7390
Lior Davidcc88b562017-01-03 18:52:09 +02007391#ifdef __linux__
7392static int wil6210_get_aid(struct sigma_dut *dut, const char *bssid,
7393 unsigned int *aid)
7394{
Lior David0fe101e2017-03-09 16:09:50 +02007395 const char *pattern = "AID[ \t]+([0-9]+)";
Lior Davidcc88b562017-01-03 18:52:09 +02007396
Lior David0fe101e2017-03-09 16:09:50 +02007397 return wil6210_get_sta_info_field(dut, bssid, pattern, aid);
Lior Davidcc88b562017-01-03 18:52:09 +02007398}
7399#endif /* __linux__ */
7400
7401
7402static int sta_get_aid_60g(struct sigma_dut *dut, const char *bssid,
7403 unsigned int *aid)
7404{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007405 switch (get_driver_type(dut)) {
Lior Davidcc88b562017-01-03 18:52:09 +02007406#ifdef __linux__
7407 case DRIVER_WIL6210:
7408 return wil6210_get_aid(dut, bssid, aid);
7409#endif /* __linux__ */
7410 default:
7411 sigma_dut_print(dut, DUT_MSG_ERROR, "get AID not supported");
7412 return -1;
7413 }
7414}
7415
7416
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007417static int sta_get_parameter_60g(struct sigma_dut *dut, struct sigma_conn *conn,
7418 struct sigma_cmd *cmd)
7419{
7420 char buf[MAX_CMD_LEN];
7421 char bss_list[MAX_CMD_LEN];
7422 const char *parameter = get_param(cmd, "Parameter");
7423
7424 if (parameter == NULL)
7425 return -1;
7426
Lior Davidcc88b562017-01-03 18:52:09 +02007427 if (strcasecmp(parameter, "AID") == 0) {
7428 unsigned int aid = 0;
7429 char bssid[20];
7430
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007431 if (get_wpa_status(get_station_ifname(dut), "bssid",
Lior Davidcc88b562017-01-03 18:52:09 +02007432 bssid, sizeof(bssid)) < 0) {
7433 sigma_dut_print(dut, DUT_MSG_ERROR,
7434 "could not get bssid");
7435 return -2;
7436 }
7437
7438 if (sta_get_aid_60g(dut, bssid, &aid))
7439 return -2;
7440
7441 snprintf(buf, sizeof(buf), "aid,%d", aid);
7442 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
7443 send_resp(dut, conn, SIGMA_COMPLETE, buf);
7444 return 0;
7445 }
7446
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007447 if (strcasecmp(parameter, "DiscoveredDevList") == 0) {
7448 char *bss_line;
7449 char *bss_id = NULL;
7450 const char *ifname = get_param(cmd, "Interface");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05307451 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007452
7453 if (ifname == NULL) {
7454 sigma_dut_print(dut, DUT_MSG_INFO,
7455 "For get DiscoveredDevList need Interface name.");
7456 return -1;
7457 }
7458
7459 /*
7460 * Use "BSS RANGE=ALL MASK=0x2" which provides a list
7461 * of BSSIDs in "bssid=<BSSID>\n"
7462 */
7463 if (wpa_command_resp(ifname, "BSS RANGE=ALL MASK=0x2",
7464 bss_list,
7465 sizeof(bss_list)) < 0) {
7466 sigma_dut_print(dut, DUT_MSG_ERROR,
7467 "Failed to get bss list");
7468 return -1;
7469 }
7470
7471 sigma_dut_print(dut, DUT_MSG_DEBUG,
7472 "bss list for ifname:%s is:%s",
7473 ifname, bss_list);
7474
7475 snprintf(buf, sizeof(buf), "DeviceList");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05307476 bss_line = strtok_r(bss_list, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007477 while (bss_line) {
7478 if (sscanf(bss_line, "bssid=%ms", &bss_id) > 0 &&
7479 bss_id) {
7480 int len;
7481
7482 len = snprintf(buf + strlen(buf),
7483 sizeof(buf) - strlen(buf),
7484 ",%s", bss_id);
7485 free(bss_id);
7486 bss_id = NULL;
7487 if (len < 0) {
7488 sigma_dut_print(dut,
7489 DUT_MSG_ERROR,
7490 "Failed to read BSSID");
7491 send_resp(dut, conn, SIGMA_ERROR,
7492 "ErrorCode,Failed to read BSS ID");
7493 return 0;
7494 }
7495
7496 if ((size_t) len >= sizeof(buf) - strlen(buf)) {
7497 sigma_dut_print(dut,
7498 DUT_MSG_ERROR,
7499 "Response buf too small for list");
7500 send_resp(dut, conn,
7501 SIGMA_ERROR,
7502 "ErrorCode,Response buf too small for list");
7503 return 0;
7504 }
7505 }
7506
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05307507 bss_line = strtok_r(NULL, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007508 }
7509
7510 sigma_dut_print(dut, DUT_MSG_INFO, "DiscoveredDevList is %s",
7511 buf);
7512 send_resp(dut, conn, SIGMA_COMPLETE, buf);
7513 return 0;
7514 }
7515
7516 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7517 return 0;
7518}
7519
7520
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07007521static int sta_get_parameter_he(struct sigma_dut *dut, struct sigma_conn *conn,
7522 struct sigma_cmd *cmd)
7523{
7524 char buf[MAX_CMD_LEN];
7525 const char *parameter = get_param(cmd, "Parameter");
7526
7527 if (!parameter)
7528 return -1;
7529
7530 if (strcasecmp(parameter, "RSSI") == 0) {
7531 char rssi[10];
7532
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007533 if (get_wpa_signal_poll(dut, get_station_ifname(dut), "RSSI",
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07007534 rssi, sizeof(rssi)) < 0) {
7535 sigma_dut_print(dut, DUT_MSG_ERROR,
7536 "Could not get RSSI");
7537 return -2;
7538 }
7539
7540 snprintf(buf, sizeof(buf), "rssi,%s", rssi);
7541 sigma_dut_print(dut, DUT_MSG_INFO, "RSSI %s", buf);
7542 send_resp(dut, conn, SIGMA_COMPLETE, buf);
7543 return 0;
7544 }
7545
7546 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7547 return 0;
7548}
7549
7550
Veerendranath Jakkamd0ad6ef2020-05-21 17:09:26 +05307551#ifdef NL80211_SUPPORT
7552
7553struct station_info {
7554 uint64_t filled;
7555 uint32_t beacon_mic_error_count;
7556 uint32_t beacon_replay_count;
7557};
7558
7559
7560static int qca_get_sta_info_handler(struct nl_msg *msg, void *arg)
7561{
7562 struct nlattr *tb[NL80211_ATTR_MAX + 1];
7563 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
7564 struct station_info *data = arg;
7565 struct nlattr *info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_MAX + 1];
7566 static struct nla_policy info_policy[
7567 QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_MAX + 1] = {
7568 [QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT] = {
7569 .type = NLA_U32
7570 },
7571 [QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT] = {
7572 .type = NLA_U32
7573 },
7574 };
7575
7576 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
7577 genlmsg_attrlen(gnlh, 0), NULL);
7578
7579 if (!tb[NL80211_ATTR_VENDOR_DATA])
7580 return NL_SKIP;
7581
7582 if (nla_parse_nested(info, QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_MAX,
7583 tb[NL80211_ATTR_VENDOR_DATA], info_policy)) {
7584 return NL_SKIP;
7585 }
7586
7587 if (info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT]) {
7588 data->filled |=
7589 BIT_ULL(QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT);
7590 data->beacon_mic_error_count =
7591 nla_get_u32(info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT]);
7592 }
7593
7594 if (info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT]) {
7595 data->filled |=
7596 BIT_ULL(QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT);
7597 data->beacon_replay_count =
7598 nla_get_u32(info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT]);
7599 }
7600
7601 return NL_SKIP;
7602}
7603
7604
7605static int qca_nl80211_get_sta_info(struct sigma_dut *dut, const char *intf,
7606 struct station_info *sta_data)
7607{
7608 struct nl_msg *msg;
7609 int ifindex, ret;
7610
7611 ifindex = if_nametoindex(intf);
7612 if (ifindex == 0) {
7613 sigma_dut_print(dut, DUT_MSG_ERROR,
7614 "%s: Index for interface %s not found",
7615 __func__, intf);
7616 return -1;
7617 }
7618
7619 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7620 NL80211_CMD_VENDOR)) ||
7621 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7622 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7623 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7624 QCA_NL80211_VENDOR_SUBCMD_GET_STA_INFO)) {
7625 sigma_dut_print(dut, DUT_MSG_ERROR,
7626 "%s: err in adding vendor_cmd", __func__);
7627 nlmsg_free(msg);
7628 return -1;
7629 }
7630
7631 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg,
7632 qca_get_sta_info_handler, sta_data);
7633 if (ret) {
7634 sigma_dut_print(dut, DUT_MSG_ERROR,
7635 "%s: err in send_and_recv_msgs, ret=%d",
7636 __func__, ret);
7637 }
7638 return ret;
7639}
7640#endif /* NL80211_SUPPORT */
7641
7642
7643static int get_bip_mic_error_count(struct sigma_dut *dut,
7644 const char *ifname,
7645 unsigned int *count)
7646{
7647#ifdef NL80211_SUPPORT
7648 struct station_info sta_data;
7649#endif /* NL80211_SUPPORT */
7650
7651 if (get_driver_type(dut) != DRIVER_WCN) {
7652 sigma_dut_print(dut, DUT_MSG_ERROR,
7653 "BIP MIC error count not supported");
7654 return -1;
7655 }
7656
7657#ifdef NL80211_SUPPORT
7658 if (qca_nl80211_get_sta_info(dut, ifname, &sta_data) != 0 ||
7659 !(sta_data.filled &
7660 BIT_ULL(QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT))) {
7661 sigma_dut_print(dut, DUT_MSG_ERROR,
7662 "BIP MIC error count fetching failed");
7663 return -1;
7664 }
7665
7666 *count = sta_data.beacon_mic_error_count;
7667 return 0;
7668#else /* NL80211_SUPPORT */
7669 sigma_dut_print(dut, DUT_MSG_ERROR,
7670 "BIP MIC error count cannot be fetched without NL80211_SUPPORT defined");
7671 return -1;
7672#endif /* NL80211_SUPPORT */
7673}
7674
7675
7676static int get_cmac_replay_count(struct sigma_dut *dut, const char *ifname,
7677 unsigned int *count)
7678{
7679#ifdef NL80211_SUPPORT
7680 struct station_info sta_data;
7681#endif /* NL80211_SUPPORT */
7682
7683 if (get_driver_type(dut) != DRIVER_WCN) {
7684 sigma_dut_print(dut, DUT_MSG_ERROR,
7685 "CMAC reply count not supported");
7686 return -1;
7687 }
7688
7689#ifdef NL80211_SUPPORT
7690 if (qca_nl80211_get_sta_info(dut, ifname, &sta_data) != 0 ||
7691 !(sta_data.filled &
7692 BIT_ULL(QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT))) {
7693 sigma_dut_print(dut, DUT_MSG_ERROR,
7694 "CMAC replay count fetching failed");
7695 return -1;
7696 }
7697
7698 *count = sta_data.beacon_replay_count;
7699 return 0;
7700#else /* NL80211_SUPPORT */
7701 sigma_dut_print(dut, DUT_MSG_ERROR,
7702 "CMAC replay count cannot be fetched without NL80211_SUPPORT defined");
7703 return -1;
7704#endif /* NL80211_SUPPORT */
7705}
7706
7707
7708static enum sigma_cmd_result sta_get_parameter_wpa3(struct sigma_dut *dut,
7709 struct sigma_conn *conn,
7710 struct sigma_cmd *cmd)
7711{
7712 char buf[MAX_CMD_LEN];
7713 const char *ifname = get_param(cmd, "interface");
7714 const char *parameter = get_param(cmd, "Parameter");
7715 unsigned int val;
7716
7717 if (!ifname || !parameter)
7718 return INVALID_SEND_STATUS;
7719
7720 if (strcasecmp(parameter, "BIPMICErrors") == 0) {
7721 if (get_bip_mic_error_count(dut, ifname, &val)) {
7722 send_resp(dut, conn, SIGMA_ERROR,
7723 "ErrorCode,Failed to get BIPMICErrors");
7724 return STATUS_SENT_ERROR;
7725 }
7726 snprintf(buf, sizeof(buf), "BIPMICErrors,%d", val);
7727 sigma_dut_print(dut, DUT_MSG_INFO, "BIPMICErrors %s", buf);
7728 send_resp(dut, conn, SIGMA_COMPLETE, buf);
7729 return STATUS_SENT;
7730 }
7731
7732 if (strcasecmp(parameter, "CMACReplays") == 0) {
7733 if (get_cmac_replay_count(dut, ifname, &val)) {
7734 send_resp(dut, conn, SIGMA_ERROR,
7735 "ErrorCode,Failed to get CMACReplays");
7736 return STATUS_SENT_ERROR;
7737 }
7738 snprintf(buf, sizeof(buf), "CMACReplays,%d", val);
7739 sigma_dut_print(dut, DUT_MSG_INFO, "CMACReplays %s", buf);
7740 send_resp(dut, conn, SIGMA_COMPLETE, buf);
7741 return STATUS_SENT;
7742 }
7743
7744 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7745 return STATUS_SENT_ERROR;
7746}
7747
7748
Jouni Malinenca0abd32020-02-09 20:18:10 +02007749static enum sigma_cmd_result sta_get_pmk(struct sigma_dut *dut,
7750 struct sigma_conn *conn,
7751 struct sigma_cmd *cmd)
7752{
7753 const char *intf = get_param(cmd, "Interface");
7754 char buf[4096], bssid[20], resp[200], *pos, *tmp;
7755
7756 snprintf(buf, sizeof(buf), "PMKSA_GET %d", dut->infra_network_id);
7757 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
7758 strncmp(buf, "UNKNOWN COMMAND", 15) == 0) {
7759 send_resp(dut, conn, SIGMA_ERROR,
7760 "ErrorCode,PMKSA_GET not supported");
7761 return STATUS_SENT_ERROR;
7762 }
7763
7764 if (strncmp(buf, "FAIL", 4) == 0 ||
7765 get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
7766 send_resp(dut, conn, SIGMA_ERROR,
7767 "ErrorCode,Could not find current network");
7768 return STATUS_SENT_ERROR;
7769 }
7770
7771 pos = buf;
7772 while (pos) {
7773 if (strncmp(pos, bssid, 17) == 0) {
7774 pos = strchr(pos, ' ');
7775 if (!pos)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05307776 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02007777 pos++;
7778 pos = strchr(pos, ' ');
7779 if (!pos)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05307780 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02007781 pos++;
7782 tmp = strchr(pos, ' ');
7783 if (!tmp)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05307784 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02007785 *tmp = '\0';
7786 break;
7787 }
Jouni Malinenca0abd32020-02-09 20:18:10 +02007788 pos = strchr(pos, '\n');
7789 if (pos)
7790 pos++;
7791 }
7792
7793 if (!pos) {
7794 send_resp(dut, conn, SIGMA_ERROR,
7795 "ErrorCode,PMK not available");
7796 return STATUS_SENT_ERROR;
7797 }
7798
7799 snprintf(resp, sizeof(resp), "PMK,%s", pos);
7800 send_resp(dut, conn, SIGMA_COMPLETE, resp);
7801 return STATUS_SENT;
7802}
7803
7804
Jouni Malinenf7222712019-06-13 01:50:21 +03007805static enum sigma_cmd_result cmd_sta_get_parameter(struct sigma_dut *dut,
7806 struct sigma_conn *conn,
7807 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007808{
7809 const char *program = get_param(cmd, "Program");
Jouni Malinenca0abd32020-02-09 20:18:10 +02007810 const char *parameter = get_param(cmd, "Parameter");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007811
Jouni Malinenca0abd32020-02-09 20:18:10 +02007812 if (!parameter)
7813 return INVALID_SEND_STATUS;
7814
7815 if (strcasecmp(parameter, "PMK") == 0)
7816 return sta_get_pmk(dut, conn, cmd);
7817
7818 if (!program)
7819 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007820
7821 if (strcasecmp(program, "P2PNFC") == 0)
7822 return p2p_cmd_sta_get_parameter(dut, conn, cmd);
7823
7824 if (strcasecmp(program, "60ghz") == 0)
7825 return sta_get_parameter_60g(dut, conn, cmd);
7826
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07007827 if (strcasecmp(program, "he") == 0)
7828 return sta_get_parameter_he(dut, conn, cmd);
7829
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007830#ifdef ANDROID_NAN
7831 if (strcasecmp(program, "NAN") == 0)
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07007832 return nan_cmd_sta_get_parameter(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007833#endif /* ANDROID_NAN */
7834
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007835#ifdef MIRACAST
7836 if (strcasecmp(program, "WFD") == 0 ||
7837 strcasecmp(program, "DisplayR2") == 0)
7838 return miracast_cmd_sta_get_parameter(dut, conn, cmd);
7839#endif /* MIRACAST */
Veerendranath Jakkamd0ad6ef2020-05-21 17:09:26 +05307840 if (strcasecmp(program, "WPA3") == 0)
7841 return sta_get_parameter_wpa3(dut, conn, cmd);
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007842
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007843 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7844 return 0;
7845}
7846
7847
7848static void sta_reset_default_ath(struct sigma_dut *dut, const char *intf,
7849 const char *type)
7850{
7851 char buf[100];
7852
7853 if (dut->program == PROGRAM_VHT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007854 run_iwpriv(dut, intf, "chwidth 2");
7855 run_iwpriv(dut, intf, "mode 11ACVHT80");
7856 run_iwpriv(dut, intf, "vhtmcs -1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007857 }
7858
7859 if (dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007860 run_iwpriv(dut, intf, "chwidth 0");
7861 run_iwpriv(dut, intf, "mode 11naht40");
7862 run_iwpriv(dut, intf, "set11NRates 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007863 }
7864
7865 if (dut->program == PROGRAM_VHT || dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007866 run_iwpriv(dut, intf, "powersave 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007867
7868 /* Reset CTS width */
7869 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 54 0",
7870 intf);
7871 if (system(buf) != 0) {
7872 sigma_dut_print(dut, DUT_MSG_ERROR,
7873 "wifitool %s beeliner_fw_test 54 0 failed",
7874 intf);
7875 }
7876
7877 /* Enable Dynamic Bandwidth signalling by default */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007878 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007879
7880 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", intf);
7881 if (system(buf) != 0) {
7882 sigma_dut_print(dut, DUT_MSG_ERROR,
7883 "iwpriv rts failed");
7884 }
7885 }
7886
7887 if (type && strcasecmp(type, "Testbed") == 0) {
7888 dut->testbed_flag_txsp = 1;
7889 dut->testbed_flag_rxsp = 1;
7890 /* STA has to set spatial stream to 2 per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007891 run_iwpriv(dut, intf, "vht_mcsmap 0xfff0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007892
7893 /* Disable LDPC per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007894 run_iwpriv(dut, intf, "ldpc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007895
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007896 run_iwpriv(dut, intf, "amsdu 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007897
7898 /* TODO: Disable STBC 2x1 transmit and receive */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007899 run_iwpriv(dut, intf, "tx_stbc 0");
7900 run_iwpriv(dut, intf, "rx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007901
7902 /* STA has to disable Short GI per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007903 run_iwpriv(dut, intf, "shortgi 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007904 }
7905
7906 if (type && strcasecmp(type, "DUT") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007907 run_iwpriv(dut, intf, "nss 3");
Arif Hussainac6c5112018-05-25 17:34:00 -07007908 dut->sta_nss = 3;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007909
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007910 run_iwpriv(dut, intf, "shortgi 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007911 }
7912}
7913
7914
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007915#ifdef NL80211_SUPPORT
7916static int sta_set_he_mcs(struct sigma_dut *dut, const char *intf,
7917 enum he_mcs_config mcs)
7918{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307919 return wcn_wifi_test_config_set_u8(
7920 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MCS, mcs);
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007921}
7922#endif /* NL80211_SUPPORT */
7923
7924
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07007925static int sta_set_action_tx_in_he_tb_ppdu(struct sigma_dut *dut,
7926 const char *intf, int enable)
7927{
7928#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307929 return wcn_wifi_test_config_set_u8(
7930 dut, intf,
7931 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_ACTION_TX_TB_PPDU,
7932 enable);
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07007933#else /* NL80211_SUPPORT */
7934 sigma_dut_print(dut, DUT_MSG_ERROR,
7935 "HE action Tx TB PPDU cannot be set without NL80211_SUPPORT defined");
7936 return -1;
7937#endif /* NL80211_SUPPORT */
7938}
7939
7940
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08007941static int sta_set_heconfig_and_wep_tkip(struct sigma_dut *dut,
7942 const char *intf, int enable)
7943{
7944#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307945 return wcn_wifi_test_config_set_u8(
7946 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WEP_TKIP_IN_HE,
7947 enable);
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08007948#else /* NL80211_SUPPORT */
7949 sigma_dut_print(dut, DUT_MSG_ERROR,
7950 "HE config enablement cannot be changed without NL80211_SUPPORT defined");
7951 return -1;
7952#endif /* NL80211_SUPPORT */
7953}
7954
7955
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007956#ifdef NL80211_SUPPORT
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007957
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007958static int sta_set_he_testbed_def(struct sigma_dut *dut,
7959 const char *intf, int cfg)
7960{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307961 return wcn_wifi_test_config_set_u8(
7962 dut, intf,
7963 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SET_HE_TESTBED_DEFAULTS,
7964 cfg);
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007965}
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007966
7967
7968static int sta_set_2g_vht_supp(struct sigma_dut *dut, const char *intf, int cfg)
7969{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307970 return wcn_wifi_test_config_set_u8(
7971 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_2G_VHT,
7972 cfg);
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007973}
7974
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007975#endif /* NL80211_SUPPORT */
7976
7977
Qiwei Caib6806972020-01-15 13:52:11 +08007978int sta_set_addba_buf_size(struct sigma_dut *dut,
7979 const char *intf, int bufsize)
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007980{
7981#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307982 return wcn_wifi_test_config_set_u16(
7983 dut, intf,
7984 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE, bufsize);
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007985#else /* NL80211_SUPPORT */
7986 sigma_dut_print(dut, DUT_MSG_ERROR,
7987 "AddBA bufsize cannot be changed without NL80211_SUPPORT defined");
7988 return -1;
7989#endif /* NL80211_SUPPORT */
7990}
7991
7992
Kiran Kumar Lokere69d89952021-08-08 23:41:46 -07007993static int sta_set_scan_unicast_probe(struct sigma_dut *dut,
7994 const char *intf, int val)
7995{
7996#ifdef NL80211_SUPPORT
7997 return wcn_wifi_test_config_set_u8(
7998 dut, intf,
7999 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_USE_BSSID_IN_PROBE_REQ_RA,
8000 val);
8001#else /* NL80211_SUPPORT */
8002 sigma_dut_print(dut, DUT_MSG_ERROR,
8003 "Unicast RA in Probe Request frame cannot be set without NL80211_SUPPORT defined");
8004 return -1;
8005#endif /* NL80211_SUPPORT */
8006}
8007
8008
Kiran Kumar Lokere09dbcef2021-08-09 00:01:41 -07008009static int sta_set_rx_ctrl_multi_bss(struct sigma_dut *dut, const char *intf,
8010 int enable)
8011{
8012#ifdef NL80211_SUPPORT
8013 return wcn_wifi_test_config_set_u8(
8014 dut, intf,
8015 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_RX_CTRL_FRAME_TO_MBSS,
8016 enable);
8017#else /* NL80211_SUPPORT */
8018 sigma_dut_print(dut, DUT_MSG_ERROR,
8019 "Rx ctrl frame to Multi-BSS cannot be changed without NL80211_SUPPORT defined");
8020 return -1;
8021#endif /* NL80211_SUPPORT */
8022}
8023
8024
8025static int sta_set_bcast_twt_support(struct sigma_dut *dut, const char *intf,
8026 int enable)
8027{
8028#ifdef NL80211_SUPPORT
8029 return wcn_wifi_test_config_set_u8(
8030 dut, intf,
8031 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BCAST_TWT_SUPPORT,
8032 enable);
8033#else /* NL80211_SUPPORT */
8034 sigma_dut_print(dut, DUT_MSG_ERROR,
8035 "BCAST TWT cannot be changed without NL80211_SUPPORT defined");
8036 return -1;
8037#endif /* NL80211_SUPPORT */
8038}
8039
8040
Arif Hussain8d5b27b2018-05-14 14:31:03 -07008041static int sta_set_tx_beamformee(struct sigma_dut *dut, const char *intf,
8042 int enable)
8043{
8044#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05308045 return wcn_wifi_test_config_set_u8(
8046 dut, intf,
8047 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_TX_BEAMFORMEE,
8048 enable);
Arif Hussain8d5b27b2018-05-14 14:31:03 -07008049#else /* NL80211_SUPPORT */
8050 sigma_dut_print(dut, DUT_MSG_ERROR,
8051 "tx beamformee cannot be changed without NL80211_SUPPORT defined");
8052 return -1;
8053#endif /* NL80211_SUPPORT */
8054}
8055
8056
Arif Hussain9765f7d2018-07-03 08:28:26 -07008057static int sta_set_beamformee_sts(struct sigma_dut *dut, const char *intf,
8058 int val)
8059{
8060#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05308061 return wcn_wifi_test_config_set_u8(
8062 dut, intf,
8063 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_BEAMFORMEE_NSTS,
8064 val);
Arif Hussain9765f7d2018-07-03 08:28:26 -07008065#else /* NL80211_SUPPORT */
8066 sigma_dut_print(dut, DUT_MSG_ERROR,
8067 "beamformee sts cannot be changed without NL80211_SUPPORT defined");
8068 return -1;
8069#endif /* NL80211_SUPPORT */
8070}
8071
8072
Arif Hussain68d23f52018-07-11 13:39:08 -07008073#ifdef NL80211_SUPPORT
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07008074static int sta_set_mac_padding_duration(struct sigma_dut *dut, const char *intf,
8075 enum qca_wlan_he_mac_padding_dur val)
8076{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05308077 return wcn_wifi_test_config_set_u8(
8078 dut, intf,
8079 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MAC_PADDING_DUR, val);
Arif Hussain68d23f52018-07-11 13:39:08 -07008080}
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07008081#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07008082
8083
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07008084static int sta_set_tx_su_ppdu_cfg(struct sigma_dut *dut, const char *intf,
8085 int val)
8086{
8087#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05308088 return wcn_wifi_test_config_set_u8(
8089 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_SUPPDU,
8090 val);
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07008091#else /* NL80211_SUPPORT */
8092 sigma_dut_print(dut, DUT_MSG_ERROR,
8093 "Tx SU PPDU cannot be set without NL80211_SUPPORT defined");
8094 return -1;
8095#endif /* NL80211_SUPPORT */
8096}
8097
8098
Kiran Kumar Lokere54b72522021-04-01 00:22:44 -07008099static int sta_set_mgmt_data_tx_disable_cfg(struct sigma_dut *dut,
8100 const char *intf, int val)
8101{
8102#ifdef NL80211_SUPPORT
8103 return wcn_wifi_test_config_set_u8(
8104 dut, intf,
8105 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_DISABLE_DATA_MGMT_RSP_TX,
8106 val);
8107#else /* NL80211_SUPPORT */
8108 sigma_dut_print(dut, DUT_MSG_ERROR,
8109 "Tx disable config cannot be set without NL80211_SUPPORT defined");
8110 return -1;
8111#endif /* NL80211_SUPPORT */
8112}
8113
8114
Kiran Kumar Lokere1809da12021-06-24 00:45:38 -07008115static int sta_set_keep_alive_data_cfg(struct sigma_dut *dut, const char *intf,
8116 int val)
8117{
8118#ifdef NL80211_SUPPORT
8119 return wcn_wifi_test_config_set_u8(
8120 dut, intf,
8121 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_KEEP_ALIVE_FRAME_TYPE,
8122 val);
8123#else /* NL80211_SUPPORT */
8124 sigma_dut_print(dut, DUT_MSG_ERROR,
8125 "Keep alive data type cannot be set without NL80211_SUPPORT defined");
8126 return -1;
8127#endif /* NL80211_SUPPORT */
8128}
8129
8130
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07008131#ifdef NL80211_SUPPORT
8132static int sta_set_he_om_ctrl_reset(struct sigma_dut *dut, const char *intf)
8133{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05308134 return wcn_wifi_test_config_set_flag(
8135 dut, intf,
8136 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_CLEAR_HE_OM_CTRL_CONFIG);
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07008137}
8138#endif /* NL80211_SUPPORT */
8139
8140
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07008141static int sta_set_mu_edca_override(struct sigma_dut *dut, const char *intf,
8142 int val)
8143{
8144#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05308145 return wcn_wifi_test_config_set_u8(
8146 dut, intf,
8147 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_OVERRIDE_MU_EDCA, val);
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07008148#else /* NL80211_SUPPORT */
8149 sigma_dut_print(dut, DUT_MSG_ERROR,
8150 "MU EDCA override cannot be changed without NL80211_SUPPORT defined");
8151 return -1;
8152#endif /* NL80211_SUPPORT */
8153}
8154
8155
Kiran Kumar Lokerefa7c7b92021-08-09 00:50:55 -07008156static int sta_set_er_su_ppdu_type_tx(struct sigma_dut *dut, const char *intf,
8157 int val)
8158{
8159#ifdef NL80211_SUPPORT
8160 return wcn_wifi_test_config_set_u8(
8161 dut, intf,
8162 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ER_SU_PPDU_TYPE, val);
8163#else /* NL80211_SUPPORT */
8164 sigma_dut_print(dut, DUT_MSG_ERROR,
8165 "ER-SU PPDU type cannot be set without NL80211_SUPPORT defined");
8166 return -1;
8167#endif /* NL80211_SUPPORT */
8168}
8169
8170
8171static int sta_set_ru_242_tone_tx(struct sigma_dut *dut, const char *intf,
8172 int val)
8173{
8174#ifdef NL80211_SUPPORT
8175 return wcn_wifi_test_config_set_u8(
8176 dut, intf,
8177 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_RU_242_TONE_TX, val);
8178#else /* NL80211_SUPPORT */
8179 sigma_dut_print(dut, DUT_MSG_ERROR,
8180 "RU 242 tone cannot be set without NL80211_SUPPORT defined");
8181 return -1;
8182#endif /* NL80211_SUPPORT */
8183}
8184
8185
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07008186static int sta_set_om_ctrl_supp(struct sigma_dut *dut, const char *intf,
8187 int val)
8188{
8189#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05308190 return wcn_wifi_test_config_set_u8(
8191 dut, intf,
8192 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OM_CTRL_SUPP, val);
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07008193#else /* NL80211_SUPPORT */
8194 sigma_dut_print(dut, DUT_MSG_ERROR,
8195 "HE OM ctrl cannot be changed without NL80211_SUPPORT defined");
8196 return -1;
8197#endif /* NL80211_SUPPORT */
8198}
8199
8200
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07008201#ifdef NL80211_SUPPORT
8202
8203struct features_info {
8204 unsigned char flags[8];
8205 size_t flags_len;
8206};
8207
8208static int features_info_handler(struct nl_msg *msg, void *arg)
8209{
8210 struct nlattr *tb[NL80211_ATTR_MAX + 1];
8211 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
8212 struct features_info *info = arg;
8213 struct nlattr *nl_vend, *attr;
8214
8215 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
8216 genlmsg_attrlen(gnlh, 0), NULL);
8217
8218 nl_vend = tb[NL80211_ATTR_VENDOR_DATA];
8219 if (nl_vend) {
8220 struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1];
8221
8222 nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX,
8223 nla_data(nl_vend), nla_len(nl_vend), NULL);
8224
8225 attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_FEATURE_FLAGS];
8226 if (attr) {
8227 int len = nla_len(attr);
8228
Vamsi Krishna79a91132021-08-16 21:40:22 +05308229 if (info && len <= sizeof(info->flags)) {
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07008230 memcpy(info->flags, nla_data(attr), len);
8231 info->flags_len = len;
8232 }
8233 }
8234 }
8235
8236 return NL_SKIP;
8237}
8238
8239
8240static int check_feature(enum qca_wlan_vendor_features feature,
8241 struct features_info *info)
8242{
8243 size_t idx = feature / 8;
8244
Vamsi Krishna79a91132021-08-16 21:40:22 +05308245 if (!info)
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07008246 return 0;
8247
8248 return (idx < info->flags_len) &&
8249 (info->flags[idx] & BIT(feature % 8));
8250}
8251
8252#endif /* NL80211_SUPPORT */
8253
8254
8255static void sta_get_twt_feature_async_supp(struct sigma_dut *dut,
8256 const char *intf)
8257{
8258#ifdef NL80211_SUPPORT
8259 struct nl_msg *msg;
8260 struct features_info info = { 0 };
8261 int ifindex, ret;
8262
8263 ifindex = if_nametoindex(intf);
8264 if (ifindex == 0) {
8265 sigma_dut_print(dut, DUT_MSG_ERROR,
8266 "%s: Index for interface %s failed",
8267 __func__, intf);
8268 return;
8269 }
8270
8271 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8272 NL80211_CMD_VENDOR)) ||
8273 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8274 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8275 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8276 QCA_NL80211_VENDOR_SUBCMD_GET_FEATURES)) {
8277 sigma_dut_print(dut, DUT_MSG_ERROR,
8278 "%s: err in adding vendor_cmd and vendor_data",
8279 __func__);
8280 nlmsg_free(msg);
8281 return;
8282 }
8283
8284 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, features_info_handler,
8285 &info);
8286 if (ret) {
8287 sigma_dut_print(dut, DUT_MSG_ERROR,
8288 "%s: err in send_and_recv_msgs, ret=%d",
8289 __func__, ret);
8290 return;
8291 }
8292
8293 if (check_feature(QCA_WLAN_VENDOR_FEATURE_TWT_ASYNC_SUPPORT, &info))
8294 dut->sta_async_twt_supp = 1;
8295 else
8296 dut->sta_async_twt_supp = 0;
8297
8298 sigma_dut_print(dut, DUT_MSG_DEBUG,
8299 "%s: sta_async_twt_supp %d",
8300 __func__, dut->sta_async_twt_supp);
8301#else /* NL80211_SUPPORT */
8302 sigma_dut_print(dut, DUT_MSG_INFO,
8303 "TWT async supp get cannot be done without NL80211_SUPPORT defined");
8304 dut->sta_async_twt_supp = 0;
8305#endif /* NL80211_SUPPORT */
8306}
8307
8308
Arif Hussain480d5f42019-03-12 14:40:42 -07008309static int sta_set_twt_req_support(struct sigma_dut *dut, const char *intf,
8310 int val)
8311{
8312#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05308313 return wcn_wifi_test_config_set_u8(
8314 dut, intf,
8315 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TWT_REQ_SUPPORT, val);
Arif Hussain480d5f42019-03-12 14:40:42 -07008316#else /* NL80211_SUPPORT */
8317 sigma_dut_print(dut, DUT_MSG_ERROR,
8318 "TWT Request cannot be changed without NL80211_SUPPORT defined");
8319 return -1;
8320#endif /* NL80211_SUPPORT */
8321}
8322
8323
Kiran Kumar Lokere4f2d4b02021-04-01 00:07:39 -07008324static int sta_set_bss_max_idle_period(struct sigma_dut *dut, const char *intf,
8325 int val)
8326{
8327#ifdef NL80211_SUPPORT
8328 return wcn_wifi_test_config_set_u16(
8329 dut, intf,
8330 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BSS_MAX_IDLE_PERIOD, val);
8331#else /* NL80211_SUPPORT */
8332 sigma_dut_print(dut, DUT_MSG_ERROR,
8333 "BSS max idle period cannot be set without NL80211_SUPPORT defined");
8334 return -1;
8335#endif /* NL80211_SUPPORT */
8336}
8337
8338
Kiran Kumar Lokere07ad92b2021-08-09 00:27:14 -07008339static int sta_set_bss_max_idle_support(struct sigma_dut *dut, const char *intf,
8340 int val)
8341{
8342#ifdef NL80211_SUPPORT
8343 return wcn_wifi_test_config_set_u8(
8344 dut, intf,
8345 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BSS_MAX_IDLE_PERIOD_ENABLE,
8346 val);
8347#else /* NL80211_SUPPORT */
8348 sigma_dut_print(dut, DUT_MSG_ERROR,
8349 "BSS max idle support cannot be set without NL80211_SUPPORT defined");
8350 return -1;
8351#endif /* NL80211_SUPPORT */
8352}
8353
8354
Srinivas Girigowda0525e292020-11-12 13:28:21 -08008355static int sta_set_fullbw_ulmumimo(struct sigma_dut *dut, const char *intf,
8356 int val)
8357{
8358#ifdef NL80211_SUPPORT
8359 return wcn_wifi_test_config_set_u8(
8360 dut, intf,
8361 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_FULL_BW_UL_MU_MIMO, val);
8362#else /* NL80211_SUPPORT */
8363 sigma_dut_print(dut, DUT_MSG_ERROR,
8364 "Full BW UL MU MIMO cannot be changed without NL80211_SUPPORT defined");
8365 return -1;
8366#endif /* NL80211_SUPPORT */
8367}
8368
8369
Kiran Kumar Lokered0ec5ed2021-04-01 00:15:04 -07008370static int sta_set_punctured_preamble_rx(struct sigma_dut *dut,
8371 const char *intf, int val)
8372{
8373#ifdef NL80211_SUPPORT
8374 return wcn_wifi_test_config_set_u8(
8375 dut, intf,
8376 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_PUNCTURED_PREAMBLE_RX,
8377 val);
8378#else /* NL80211_SUPPORT */
8379 sigma_dut_print(dut, DUT_MSG_ERROR,
8380 "Punctured preamble Rx cannot be set without NL80211_SUPPORT defined");
8381 return -1;
8382#endif /* NL80211_SUPPORT */
8383}
8384
8385
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08008386static void sta_reset_default_wcn(struct sigma_dut *dut, const char *intf,
8387 const char *type)
8388{
8389 char buf[60];
8390
8391 if (dut->program == PROGRAM_HE) {
8392 /* resetting phymode to auto in case of HE program */
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05308393 sta_set_phymode(dut, intf, "auto");
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08008394
Amarnath Hullur Subramanyam9cecb502018-04-25 13:26:30 -07008395 /* reset the rate to Auto rate */
8396 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0xff",
8397 intf);
8398 if (system(buf) != 0) {
8399 sigma_dut_print(dut, DUT_MSG_ERROR,
8400 "iwpriv %s set_11ax_rate 0xff failed",
8401 intf);
8402 }
8403
Kiran Kumar Lokere86cfe3a2018-06-01 11:55:15 -07008404 /* reset the LDPC setting */
8405 snprintf(buf, sizeof(buf), "iwpriv %s ldpc 1", intf);
8406 if (system(buf) != 0) {
8407 sigma_dut_print(dut, DUT_MSG_ERROR,
8408 "iwpriv %s ldpc 1 failed", intf);
8409 }
8410
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08008411 /* reset the power save setting */
Vinita S. Malooa8b62722020-04-23 01:45:41 +05308412 set_power_save_wcn(dut, intf, 2);
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08008413
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08008414 /* remove all network profiles */
8415 remove_wpa_networks(intf);
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08008416
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08008417 /* Configure ADDBA Req/Rsp buffer size to be 64 */
8418 sta_set_addba_buf_size(dut, intf, 64);
8419
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07008420 if (dut->sta_async_twt_supp == -1)
8421 sta_get_twt_feature_async_supp(dut, intf);
8422
Kiran Kumar Lokere69d89952021-08-08 23:41:46 -07008423 sta_set_scan_unicast_probe(dut, intf, 0);
8424
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08008425#ifdef NL80211_SUPPORT
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08008426 /* Reset the device HE capabilities to its default supported
8427 * configuration. */
8428 sta_set_he_testbed_def(dut, intf, 0);
8429
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08008430 /* Disable noackpolicy for all AC */
8431 if (nlvendor_sta_set_noack(dut, intf, 0, QCA_WLAN_AC_ALL)) {
8432 sigma_dut_print(dut, DUT_MSG_ERROR,
8433 "Disable of noackpolicy for all AC failed");
8434 }
8435#endif /* NL80211_SUPPORT */
8436
Amarnath Hullur Subramanyamb1724a52018-03-07 14:31:46 -08008437 /* Enable WMM by default */
8438 if (wcn_sta_set_wmm(dut, intf, "on")) {
8439 sigma_dut_print(dut, DUT_MSG_ERROR,
8440 "Enable of WMM in sta_reset_default_wcn failed");
8441 }
8442
8443 /* Disable ADDBA_REJECT by default */
8444 if (nlvendor_sta_set_addba_reject(dut, intf, 0)) {
8445 sigma_dut_print(dut, DUT_MSG_ERROR,
8446 "Disable of addba_reject in sta_reset_default_wcn failed");
8447 }
8448
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08008449 /* Enable sending of ADDBA by default */
8450 if (nlvendor_config_send_addba(dut, intf, 1)) {
8451 sigma_dut_print(dut, DUT_MSG_ERROR,
8452 "Enable sending of ADDBA in sta_reset_default_wcn failed");
8453 }
8454
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08008455 /* Enable AMPDU by default */
8456 iwpriv_sta_set_ampdu(dut, intf, 1);
8457
Subhani Shaik8e7a3052018-04-24 14:03:00 -07008458#ifdef NL80211_SUPPORT
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -08008459 if (wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_AUTO)) {
Subhani Shaik8e7a3052018-04-24 14:03:00 -07008460 sigma_dut_print(dut, DUT_MSG_ERROR,
8461 "Set LTF config to default in sta_reset_default_wcn failed");
8462 }
Arif Hussain9765f7d2018-07-03 08:28:26 -07008463
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08008464 /* set the beamformee NSTS(maximum number of
8465 * space-time streams) to default DUT config
8466 */
8467 if (sta_set_beamformee_sts(dut, intf, 7)) {
Arif Hussain9765f7d2018-07-03 08:28:26 -07008468 sigma_dut_print(dut, DUT_MSG_ERROR,
8469 "Failed to set BeamformeeSTS");
8470 }
Arif Hussain68d23f52018-07-11 13:39:08 -07008471
Kiran Kumar Lokere54b72522021-04-01 00:22:44 -07008472 if (sta_set_mgmt_data_tx_disable_cfg(dut, intf, 0)) {
8473 sigma_dut_print(dut, DUT_MSG_ERROR,
8474 "Failed to reset mgmt/data Tx disable config");
8475 }
8476
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07008477 if (sta_set_mac_padding_duration(
8478 dut, intf,
8479 QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07008480 sigma_dut_print(dut, DUT_MSG_ERROR,
8481 "Failed to set MAC padding duration");
8482 }
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07008483
8484 if (sta_set_mu_edca_override(dut, intf, 0)) {
8485 sigma_dut_print(dut, DUT_MSG_ERROR,
8486 "ErrorCode,Failed to set MU EDCA override disable");
8487 }
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07008488
Kiran Kumar Lokerefa7c7b92021-08-09 00:50:55 -07008489 if (sta_set_ru_242_tone_tx(dut, intf, 0)) {
8490 sigma_dut_print(dut, DUT_MSG_ERROR,
8491 "Failed to set RU 242 tone Tx");
8492 }
8493
8494 if (sta_set_er_su_ppdu_type_tx(dut, intf, 0)) {
8495 sigma_dut_print(dut, DUT_MSG_ERROR,
8496 "Failed to set ER-SU PPDU type Tx");
8497 }
8498
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07008499 if (sta_set_om_ctrl_supp(dut, intf, 1)) {
8500 sigma_dut_print(dut, DUT_MSG_ERROR,
8501 "Failed to set OM ctrl supp");
8502 }
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07008503
8504 if (sta_set_tx_su_ppdu_cfg(dut, intf, 1)) {
8505 sigma_dut_print(dut, DUT_MSG_ERROR,
8506 "Failed to set Tx SU PPDU enable");
8507 }
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07008508
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07008509 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 0)) {
8510 sigma_dut_print(dut, DUT_MSG_ERROR,
8511 "failed to send TB PPDU Tx cfg");
8512 }
8513
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07008514 if (sta_set_he_om_ctrl_reset(dut, intf)) {
8515 sigma_dut_print(dut, DUT_MSG_ERROR,
8516 "Failed to set OM ctrl reset");
8517 }
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08008518
8519 /* +HTC-HE support default on */
8520 if (sta_set_he_htc_supp(dut, intf, 1)) {
8521 sigma_dut_print(dut, DUT_MSG_ERROR,
8522 "Setting of +HTC-HE support failed");
8523 }
Subhani Shaik8e7a3052018-04-24 14:03:00 -07008524#endif /* NL80211_SUPPORT */
8525
Arif Hussain8d5b27b2018-05-14 14:31:03 -07008526 if (sta_set_tx_beamformee(dut, intf, 1)) {
8527 sigma_dut_print(dut, DUT_MSG_ERROR,
8528 "Set tx beamformee enable by default in sta_reset_default_wcn failed");
8529 }
8530
Kiran Kumar Lokereb55ff442020-07-15 00:20:40 -07008531 wpa_command(intf, "SET oce 1");
8532
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08008533 /* Set nss to 1 and MCS 0-7 in case of testbed */
8534 if (type && strcasecmp(type, "Testbed") == 0) {
8535#ifdef NL80211_SUPPORT
8536 int ret;
8537#endif /* NL80211_SUPPORT */
8538
Kiran Kumar Lokereb55ff442020-07-15 00:20:40 -07008539 wpa_command(intf, "SET oce 0");
8540
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08008541 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
8542 if (system(buf) != 0) {
8543 sigma_dut_print(dut, DUT_MSG_ERROR,
8544 "iwpriv %s nss failed", intf);
8545 }
8546
8547#ifdef NL80211_SUPPORT
8548 ret = sta_set_he_mcs(dut, intf, HE_80_MCS0_7);
8549 if (ret) {
8550 sigma_dut_print(dut, DUT_MSG_ERROR,
8551 "Setting of MCS failed, ret:%d",
8552 ret);
8553 }
8554#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyamc67621d2018-02-04 23:18:01 -08008555
8556 /* Disable STBC as default */
8557 wcn_sta_set_stbc(dut, intf, "0");
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08008558
8559 /* Disable AMSDU as default */
8560 iwpriv_sta_set_amsdu(dut, intf, "0");
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08008561
8562#ifdef NL80211_SUPPORT
8563 /* HE fragmentation default off */
8564 if (sta_set_he_fragmentation(dut, intf,
8565 HE_FRAG_DISABLE)) {
8566 sigma_dut_print(dut, DUT_MSG_ERROR,
8567 "Setting of HE fragmentation failed");
8568 }
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08008569
8570 /* set the beamformee NSTS(maximum number of
8571 * space-time streams) to default testbed config
8572 */
8573 if (sta_set_beamformee_sts(dut, intf, 3)) {
8574 sigma_dut_print(dut, DUT_MSG_ERROR,
8575 "Failed to set BeamformeeSTS");
8576 }
8577
Kiran Kumar Lokered0ec5ed2021-04-01 00:15:04 -07008578 if (sta_set_punctured_preamble_rx(dut, intf, 0)) {
8579 sigma_dut_print(dut, DUT_MSG_ERROR,
8580 "Failed to reset PreamblePunctRx support");
8581 }
8582
Kiran Kumar Lokere727687f2021-06-24 00:35:49 -07008583 if (sta_set_bss_max_idle_period(dut, intf, 0)) {
8584 sigma_dut_print(dut, DUT_MSG_ERROR,
8585 "Failed to reset BSS max idle period");
8586 }
8587
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08008588 /* +HTC-HE support default off */
8589 if (sta_set_he_htc_supp(dut, intf, 0)) {
8590 sigma_dut_print(dut, DUT_MSG_ERROR,
8591 "Setting of +HTC-HE support failed");
8592 }
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08008593
8594 /* Set device HE capabilities to testbed default
8595 * configuration. */
8596 if (sta_set_he_testbed_def(dut, intf, 1)) {
8597 sigma_dut_print(dut, DUT_MSG_DEBUG,
8598 "Failed to set HE defaults");
8599 }
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08008600
8601 /* Disable VHT support in 2.4 GHz for testbed */
8602 sta_set_2g_vht_supp(dut, intf, 0);
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08008603#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08008604
8605 /* Enable WEP/TKIP with HE capability in testbed */
8606 if (sta_set_heconfig_and_wep_tkip(dut, intf, 1)) {
8607 sigma_dut_print(dut, DUT_MSG_ERROR,
8608 "Enabling HE config with WEP/TKIP failed");
8609 }
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08008610 }
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08008611
8612 /* Defaults in case of DUT */
8613 if (type && strcasecmp(type, "DUT") == 0) {
Arif Hussaind48fcc72018-05-01 18:34:18 -07008614 /* Enable STBC by default */
8615 wcn_sta_set_stbc(dut, intf, "1");
8616
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08008617 /* set nss to 2 */
8618 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
8619 if (system(buf) != 0) {
8620 sigma_dut_print(dut, DUT_MSG_ERROR,
8621 "iwpriv %s nss 2 failed", intf);
8622 }
Arif Hussainac6c5112018-05-25 17:34:00 -07008623 dut->sta_nss = 2;
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08008624
8625#ifdef NL80211_SUPPORT
Arif Hussainae239842018-05-01 18:20:05 -07008626 /* Set HE_MCS to 0-11 */
8627 if (sta_set_he_mcs(dut, intf, HE_80_MCS0_11)) {
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08008628 sigma_dut_print(dut, DUT_MSG_ERROR,
8629 "Setting of MCS failed");
8630 }
8631#endif /* NL80211_SUPPORT */
8632
8633 /* Disable WEP/TKIP with HE capability in DUT */
8634 if (sta_set_heconfig_and_wep_tkip(dut, intf, 0)) {
8635 sigma_dut_print(dut, DUT_MSG_ERROR,
8636 "Enabling HE config with WEP/TKIP failed");
8637 }
8638 }
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08008639 }
8640}
8641
8642
Veerendranath Jakkam47867202020-12-21 01:53:52 +05308643static int sta_set_client_privacy(struct sigma_dut *dut,
8644 struct sigma_conn *conn, const char *intf,
8645 int enable)
8646{
8647 if (enable &&
8648 (wpa_command(intf, "SET mac_addr 1") < 0 ||
8649 wpa_command(intf, "SET rand_addr_lifetime 1") < 0 ||
Veerendranath Jakkam39fd5c42020-12-21 02:02:21 +05308650 (wpa_command(intf, "MAC_RAND_SCAN enable=1 all") < 0 &&
8651 wpa_command(intf, "SET preassoc_mac_addr 1") < 0) ||
Veerendranath Jakkam47867202020-12-21 01:53:52 +05308652 wpa_command(intf, "SET gas_rand_mac_addr 1") < 0 ||
8653 wpa_command(intf, "SET gas_rand_addr_lifetime 1") < 0))
8654 return -1;
8655
8656 if (!enable &&
8657 (wpa_command(intf, "SET mac_addr 0") < 0 ||
Veerendranath Jakkam39fd5c42020-12-21 02:02:21 +05308658 (wpa_command(intf, "MAC_RAND_SCAN enable=0 all") < 0 &&
8659 wpa_command(intf, "SET preassoc_mac_addr 0") < 0) ||
Veerendranath Jakkam47867202020-12-21 01:53:52 +05308660 wpa_command(intf, "SET gas_rand_mac_addr 0") < 0))
8661 return -1;
8662
8663 dut->client_privacy = enable;
8664 return 0;
8665}
8666
8667
Jouni Malinenf7222712019-06-13 01:50:21 +03008668static enum sigma_cmd_result cmd_sta_reset_default(struct sigma_dut *dut,
8669 struct sigma_conn *conn,
8670 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008671{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008672 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008673 const char *band = get_param(cmd, "band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008674 const char *type;
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07008675 const char *program = get_param(cmd, "program");
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05308676 const char *dev_role = get_param(cmd, "DevRole");
Veerendranath Jakkamc1f71b62021-01-23 03:09:51 +05308677 char resp[20];
Veerendranath Jakkamea7f0692021-08-11 19:13:12 +05308678 char buf[100];
Veerendranath Jakkamc1f71b62021-01-23 03:09:51 +05308679 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008680
Jouni Malinenb21f0542019-11-04 17:53:38 +02008681 if (dut->station_ifname_2g &&
8682 strcmp(dut->station_ifname_2g, intf) == 0)
8683 dut->use_5g = 0;
8684 else if (dut->station_ifname_5g &&
8685 strcmp(dut->station_ifname_5g, intf) == 0)
8686 dut->use_5g = 1;
8687
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07008688 if (!program)
8689 program = get_param(cmd, "prog");
8690 dut->program = sigma_program_to_enum(program);
Vinita S. Maloof7a2cbf2020-11-18 19:29:44 +05308691
8692 if (dut->program == PROGRAM_WFD && dut->user_config_timeout)
8693 dut->default_timeout = dut->user_config_timeout;
8694
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008695 dut->device_type = STA_unknown;
8696 type = get_param(cmd, "type");
8697 if (type && strcasecmp(type, "Testbed") == 0)
8698 dut->device_type = STA_testbed;
8699 if (type && strcasecmp(type, "DUT") == 0)
8700 dut->device_type = STA_dut;
8701
8702 if (dut->program == PROGRAM_TDLS) {
8703 /* Clear TDLS testing mode */
8704 wpa_command(intf, "SET tdls_disabled 0");
8705 wpa_command(intf, "SET tdls_testing 0");
8706 dut->no_tpk_expiration = 0;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008707 if (get_driver_type(dut) == DRIVER_WCN) {
Pradeep Reddy POTTETI8ce2a232016-10-28 12:17:32 +05308708 /* Enable the WCN driver in TDLS Explicit trigger mode
8709 */
8710 wpa_command(intf, "SET tdls_external_control 0");
8711 wpa_command(intf, "SET tdls_trigger_control 0");
8712 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008713 }
8714
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07008715#ifdef MIRACAST
8716 if (dut->program == PROGRAM_WFD ||
8717 dut->program == PROGRAM_DISPLAYR2)
8718 miracast_sta_reset_default(dut, conn, cmd);
8719#endif /* MIRACAST */
8720
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008721 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008722 case DRIVER_ATHEROS:
8723 sta_reset_default_ath(dut, intf, type);
8724 break;
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08008725 case DRIVER_WCN:
8726 sta_reset_default_wcn(dut, intf, type);
8727 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008728 default:
8729 break;
8730 }
8731
8732#ifdef ANDROID_NAN
8733 if (dut->program == PROGRAM_NAN)
8734 nan_cmd_sta_reset_default(dut, conn, cmd);
8735#endif /* ANDROID_NAN */
8736
Vinay Gannevaram3b9fdd32019-06-14 17:55:44 +05308737 if (dut->program == PROGRAM_LOC &&
8738 lowi_cmd_sta_reset_default(dut, conn, cmd) < 0)
8739 return ERROR_SEND_STATUS;
8740
Jouni Malinenba630452018-06-22 11:49:59 +03008741 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008742 unlink("SP/wi-fi.org/pps.xml");
8743 if (system("rm -r SP/*") != 0) {
8744 }
8745 unlink("next-client-cert.pem");
8746 unlink("next-client-key.pem");
8747 }
8748
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008749 /* For WPS program of the 60 GHz band the band type needs to be saved */
8750 if (dut->program == PROGRAM_WPS) {
8751 if (band && strcasecmp(band, "60GHz") == 0) {
8752 dut->band = WPS_BAND_60G;
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02008753 /* For 60 GHz enable WPS for WPS TCs */
8754 dut->wps_disable = 0;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008755 } else {
8756 dut->band = WPS_BAND_NON_60G;
8757 }
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02008758 } else if (dut->program == PROGRAM_60GHZ) {
8759 /* For 60 GHz MAC/PHY TCs WPS must be disabled */
8760 dut->wps_disable = 1;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008761 }
8762
Alexei Avshalom Lazar157ba062018-12-23 16:15:26 +02008763 if (is_60g_sigma_dut(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008764 const char *dev_role = get_param(cmd, "DevRole");
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02008765 char buf[256];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008766
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02008767 sigma_dut_print(dut, DUT_MSG_INFO,
8768 "WPS 60 GHz program, wps_disable = %d",
8769 dut->wps_disable);
8770
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008771 if (!dev_role) {
8772 send_resp(dut, conn, SIGMA_ERROR,
8773 "errorCode,Missing DevRole argument");
8774 return 0;
8775 }
8776
8777 if (strcasecmp(dev_role, "STA") == 0)
8778 dut->dev_role = DEVROLE_STA;
8779 else if (strcasecmp(dev_role, "PCP") == 0)
8780 dut->dev_role = DEVROLE_PCP;
8781 else {
8782 send_resp(dut, conn, SIGMA_ERROR,
8783 "errorCode,Unknown DevRole");
8784 return 0;
8785 }
8786
8787 if (dut->device_type == STA_unknown) {
8788 sigma_dut_print(dut, DUT_MSG_ERROR,
8789 "Device type is not STA testbed or DUT");
8790 send_resp(dut, conn, SIGMA_ERROR,
8791 "errorCode,Unknown device type");
8792 return 0;
8793 }
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02008794
8795 sigma_dut_print(dut, DUT_MSG_DEBUG,
8796 "Setting msdu_size to MAX: 7912");
8797 snprintf(buf, sizeof(buf), "ifconfig %s mtu 7912",
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008798 get_station_ifname(dut));
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02008799
8800 if (system(buf) != 0) {
8801 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
8802 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02008803 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02008804 }
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02008805
8806 if (sta_set_force_mcs(dut, 0, 1)) {
8807 sigma_dut_print(dut, DUT_MSG_ERROR,
8808 "Failed to reset force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02008809 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02008810 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008811 }
8812
8813 wpa_command(intf, "WPS_ER_STOP");
8814 wpa_command(intf, "FLUSH");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05308815 wpa_command(intf, "ERP_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008816 wpa_command(intf, "SET radio_disabled 0");
8817
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02008818 dut->wps_forced_version = 0;
8819
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008820 if (dut->wsc_fragment) {
8821 dut->wsc_fragment = 0;
8822 wpa_command(intf, "SET device_name Test client");
8823 wpa_command(intf, "SET manufacturer ");
8824 wpa_command(intf, "SET model_name ");
8825 wpa_command(intf, "SET model_number ");
8826 wpa_command(intf, "SET serial_number ");
8827 }
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02008828 if (is_60g_sigma_dut(dut) && dut->force_rsn_ie) {
8829 dut->force_rsn_ie = FORCE_RSN_IE_NONE;
8830 sta_60g_force_rsn_ie(dut, FORCE_RSN_IE_NONE);
8831 }
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008832
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008833 if (dut->tmp_mac_addr && dut->set_macaddr) {
8834 dut->tmp_mac_addr = 0;
8835 if (system(dut->set_macaddr) != 0) {
8836 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to clear "
8837 "temporary MAC address");
8838 }
8839 }
8840
8841 set_ps(intf, dut, 0);
8842
Jouni Malinenba630452018-06-22 11:49:59 +03008843 if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2 ||
8844 dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008845 wpa_command(intf, "SET interworking 1");
8846 wpa_command(intf, "SET hs20 1");
8847 }
8848
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08008849 if (dut->program == PROGRAM_HS2_R2 ||
Jouni Malinenba630452018-06-22 11:49:59 +03008850 dut->program == PROGRAM_HS2_R3 ||
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08008851 dut->program == PROGRAM_OCE) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008852 wpa_command(intf, "SET pmf 1");
8853 } else {
8854 wpa_command(intf, "SET pmf 0");
8855 }
8856
8857 hs2_clear_credentials(intf);
8858 wpa_command(intf, "SET hessid 00:00:00:00:00:00");
8859 wpa_command(intf, "SET access_network_type 15");
8860
8861 static_ip_file(0, NULL, NULL, NULL);
8862 kill_dhcp_client(dut, intf);
8863 clear_ip_addr(dut, intf);
8864
8865 dut->er_oper_performed = 0;
8866 dut->er_oper_bssid[0] = '\0';
8867
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07008868 if (dut->program == PROGRAM_LOC) {
8869 /* Disable Interworking by default */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008870 wpa_command(get_station_ifname(dut), "SET interworking 0");
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07008871 }
8872
Kiran Kumar Lokeredd086642020-06-04 00:29:26 -07008873 if (dut->program == PROGRAM_MBO || dut->program == PROGRAM_HE) {
Ashwini Patil00402582017-04-13 12:29:39 +05308874 free(dut->non_pref_ch_list);
8875 dut->non_pref_ch_list = NULL;
Ashwini Patil5acd7382017-04-13 15:55:04 +05308876 free(dut->btm_query_cand_list);
8877 dut->btm_query_cand_list = NULL;
Ashwini Patilc63161e2017-04-13 16:30:23 +05308878 wpa_command(intf, "SET reject_btm_req_reason 0");
Ashwini Patila75de5a2017-04-13 16:35:05 +05308879 wpa_command(intf, "SET ignore_assoc_disallow 0");
Ashwini Patild174f2c2017-04-13 16:49:46 +05308880 wpa_command(intf, "SET gas_address3 0");
Ashwini Patil9183fdb2017-04-13 16:58:25 +05308881 wpa_command(intf, "SET roaming 1");
Ankita Bajaj1d974552018-09-18 16:56:44 +05308882 wpa_command(intf, "SET interworking 1");
Ashwini Patil00402582017-04-13 12:29:39 +05308883 }
8884
Jouni Malinen3c367e82017-06-23 17:01:47 +03008885 free(dut->rsne_override);
8886 dut->rsne_override = NULL;
8887
Jouni Malinen68143132017-09-02 02:34:08 +03008888 free(dut->sae_commit_override);
8889 dut->sae_commit_override = NULL;
Jouni Malinen4b3769d2019-10-10 16:20:29 +03008890 wpa_command(intf, "SET sae_pmkid_in_assoc 0");
Jouni Malinen11e55212019-11-22 21:46:59 +02008891 dut->sae_pwe = SAE_PWE_DEFAULT;
Jouni Malinen68143132017-09-02 02:34:08 +03008892
Jouni Malinen134fe3c2019-06-12 04:16:49 +03008893 dut->sta_associate_wait_connect = 0;
8894 dut->server_cert_hash[0] = '\0';
Jouni Malinen37d5c692019-08-19 16:56:55 +03008895 dut->server_cert_tod = 0;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03008896 dut->sta_tod_policy = 0;
8897
Jouni Malinend86e5822017-08-29 03:55:32 +03008898 dut->dpp_conf_id = -1;
Jouni Malinenb1dd21f2017-11-13 19:14:29 +02008899 free(dut->dpp_peer_uri);
8900 dut->dpp_peer_uri = NULL;
Jouni Malinen63d50412017-11-24 11:55:38 +02008901 dut->dpp_local_bootstrap = -1;
Jouni Malinen5011fb52017-12-05 21:00:15 +02008902 wpa_command(intf, "SET dpp_config_processing 2");
Jouni Malinen90776b12020-05-04 15:34:46 +03008903 wpa_command(intf, "SET dpp_mud_url ");
Jouni Malinend86e5822017-08-29 03:55:32 +03008904
Jouni Malinenfac9cad2017-10-10 18:35:55 +03008905 wpa_command(intf, "VENDOR_ELEM_REMOVE 13 *");
8906
vamsi krishnaa2799492017-12-05 14:28:01 +05308907 if (dut->program == PROGRAM_OCE) {
Ankita Bajaja2cb5672017-10-25 16:08:28 +05308908 wpa_command(intf, "SET oce 1");
vamsi krishnaa2799492017-12-05 14:28:01 +05308909 wpa_command(intf, "SET disable_fils 0");
Ankita Bajaj1bde7942018-01-09 19:15:01 +05308910 wpa_command(intf, "FILS_HLP_REQ_FLUSH");
8911 dut->fils_hlp = 0;
8912#ifdef ANDROID
8913 hlp_thread_cleanup(dut);
8914#endif /* ANDROID */
vamsi krishnaa2799492017-12-05 14:28:01 +05308915 }
Ankita Bajaja2cb5672017-10-25 16:08:28 +05308916
Veerendranath Jakkamea7f0692021-08-11 19:13:12 +05308917 if (dut->program == PROGRAM_QM) {
Vamsi Krishnaf642d6a2020-03-27 12:33:14 +05308918 wpa_command(intf, "SET interworking 1");
Veerendranath Jakkama16cdc82021-09-12 16:44:22 +05308919 wpa_command(intf, "SET enable_dscp_policy_capa 1");
Veerendranath Jakkam329a3cd2021-09-11 18:10:13 +05308920 dut->qm_domain_name[0] = '\0';
Veerendranath Jakkama16cdc82021-09-12 16:44:22 +05308921 dut->reject_dscp_policies = 0;
Veerendranath Jakkam1bf1bd62021-09-12 16:35:55 +05308922 dut->num_dscp_status = 0;
Veerendranath Jakkamea7f0692021-08-11 19:13:12 +05308923 snprintf(buf, sizeof(buf),
8924 "ip -6 route replace fe80::/64 dev %s table local",
8925 intf);
8926 if (system(buf) != 0)
8927 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run: %s",
8928 buf);
Veerendranath Jakkam9ceb3b12021-09-10 03:18:17 +05308929
8930 stop_dscp_policy_mon_thread(dut);
8931 clear_all_dscp_policies(dut);
Veerendranath Jakkamea7f0692021-08-11 19:13:12 +05308932 }
Vamsi Krishnaf642d6a2020-03-27 12:33:14 +05308933
Jouni Malinen8179fee2019-03-28 03:19:47 +02008934 dut->akm_values = 0;
Shivani Baranwal7aa48602021-09-29 10:53:38 +05308935
8936#ifdef NL80211_SUPPORT
8937 if (get_driver_type(dut) == DRIVER_WCN)
8938 sta_config_params(dut, intf, STA_SET_FT_DS, 0);
8939#endif /* NL80211_SUPPORT */
8940
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03008941 dut->sta_ft_ds = 0;
Jouni Malinen8179fee2019-03-28 03:19:47 +02008942
Sunil Dutt076081f2018-02-05 19:45:50 +05308943#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008944 if (get_driver_type(dut) == DRIVER_WCN &&
Sunil Dutt44595082018-02-12 19:41:45 +05308945 dut->config_rsnie == 1) {
8946 dut->config_rsnie = 0;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05308947 sta_config_params(dut, intf, STA_SET_RSNIE, 0);
Sunil Dutt076081f2018-02-05 19:45:50 +05308948 }
8949#endif /* NL80211_SUPPORT */
8950
Sunil Duttfebf8a82018-02-09 18:50:13 +05308951 if (dev_role && strcasecmp(dev_role, "STA-CFON") == 0) {
8952 dut->dev_role = DEVROLE_STA_CFON;
8953 return sta_cfon_reset_default(dut, conn, cmd);
8954 }
8955
Jouni Malinen439352d2018-09-13 03:42:23 +03008956 wpa_command(intf, "SET setband AUTO");
8957
Veerendranath Jakkamc1f71b62021-01-23 03:09:51 +05308958 ret = wpa_command_resp(intf, "GET_CAPABILITY ocv", resp, sizeof(resp));
8959 dut->ocvc = ret == 0 && strncmp(resp, "supported", 9) == 0;
8960
8961 ret = wpa_command_resp(intf, "GET_CAPABILITY beacon_prot", resp,
8962 sizeof(resp));
8963 dut->beacon_prot = ret == 0 && strncmp(resp, "supported", 9) == 0;
8964
Veerendranath Jakkam47867202020-12-21 01:53:52 +05308965 if (sta_set_client_privacy(dut, conn, intf,
8966 dut->program == PROGRAM_WPA3 &&
8967 dut->device_type == STA_dut &&
8968 dut->client_privacy_default)) {
8969 sigma_dut_print(dut, DUT_MSG_ERROR,
8970 "Failed to set client privacy functionality");
8971 /* sta_reset_default command is not really supposed to fail,
8972 * so allow this to continue. */
8973 }
8974
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +05308975 dut->saquery_oci_freq = 0;
Shivani Baranwalebde8f62021-10-19 12:26:02 +05308976 dut->prev_disable_scs_support = 0;
8977 dut->prev_disable_mscs_support = 0;
Vamsi Krishnac1633d22020-05-06 18:31:21 +05308978
Sunil Duttfebf8a82018-02-09 18:50:13 +05308979 if (dut->program != PROGRAM_VHT)
8980 return cmd_sta_p2p_reset(dut, conn, cmd);
8981
Priyadharshini Gowthamana7dfd492015-11-09 14:34:08 -08008982 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008983}
8984
8985
Jouni Malinenf7222712019-06-13 01:50:21 +03008986static enum sigma_cmd_result cmd_sta_get_events(struct sigma_dut *dut,
8987 struct sigma_conn *conn,
8988 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008989{
8990 const char *program = get_param(cmd, "Program");
8991
8992 if (program == NULL)
8993 return -1;
8994#ifdef ANDROID_NAN
8995 if (strcasecmp(program, "NAN") == 0)
8996 return nan_cmd_sta_get_events(dut, conn, cmd);
8997#endif /* ANDROID_NAN */
8998 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
8999 return 0;
9000}
9001
9002
Jouni Malinen82905202018-04-29 17:20:10 +03009003static int sta_exec_action_url(struct sigma_dut *dut, struct sigma_conn *conn,
9004 struct sigma_cmd *cmd)
9005{
9006 const char *url = get_param(cmd, "url");
9007 const char *method = get_param(cmd, "method");
9008 pid_t pid;
9009 int status;
9010
9011 if (!url || !method)
9012 return -1;
9013
9014 /* TODO: Add support for method,post */
9015 if (strcasecmp(method, "get") != 0) {
9016 send_resp(dut, conn, SIGMA_ERROR,
9017 "ErrorCode,Unsupported method");
9018 return 0;
9019 }
9020
9021 pid = fork();
9022 if (pid < 0) {
9023 perror("fork");
9024 return -1;
9025 }
9026
9027 if (pid == 0) {
9028 char * argv[5] = { "wget", "-O", "/dev/null",
9029 (char *) url, NULL };
9030
9031 execv("/usr/bin/wget", argv);
9032 perror("execv");
9033 exit(0);
9034 return -1;
9035 }
9036
9037 if (waitpid(pid, &status, 0) < 0) {
9038 perror("waitpid");
9039 return -1;
9040 }
9041
9042 if (WIFEXITED(status)) {
9043 const char *errmsg;
9044
9045 if (WEXITSTATUS(status) == 0)
9046 return 1;
9047 sigma_dut_print(dut, DUT_MSG_INFO, "wget exit status %d",
9048 WEXITSTATUS(status));
9049 switch (WEXITSTATUS(status)) {
9050 case 4:
9051 errmsg = "errmsg,Network failure";
9052 break;
9053 case 8:
9054 errmsg = "errmsg,Server issued an error response";
9055 break;
9056 default:
9057 errmsg = "errmsg,Unknown failure from wget";
9058 break;
9059 }
9060 send_resp(dut, conn, SIGMA_ERROR, errmsg);
9061 return 0;
9062 }
9063
9064 send_resp(dut, conn, SIGMA_ERROR, "errmsg,Unknown failure");
9065 return 0;
9066}
9067
9068
Jouni Malinenf7222712019-06-13 01:50:21 +03009069static enum sigma_cmd_result cmd_sta_exec_action(struct sigma_dut *dut,
9070 struct sigma_conn *conn,
9071 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009072{
9073 const char *program = get_param(cmd, "Prog");
9074
Jouni Malinen82905202018-04-29 17:20:10 +03009075 if (program && !get_param(cmd, "interface"))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009076 return -1;
9077#ifdef ANDROID_NAN
Jouni Malinen82905202018-04-29 17:20:10 +03009078 if (program && strcasecmp(program, "NAN") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009079 return nan_cmd_sta_exec_action(dut, conn, cmd);
9080#endif /* ANDROID_NAN */
Jouni Malinen82905202018-04-29 17:20:10 +03009081
9082 if (program && strcasecmp(program, "Loc") == 0)
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07009083 return loc_cmd_sta_exec_action(dut, conn, cmd);
Jouni Malinen82905202018-04-29 17:20:10 +03009084
9085 if (get_param(cmd, "url"))
9086 return sta_exec_action_url(dut, conn, cmd);
9087
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009088 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
9089 return 0;
9090}
9091
9092
Jouni Malinenf7222712019-06-13 01:50:21 +03009093static enum sigma_cmd_result cmd_sta_set_11n(struct sigma_dut *dut,
9094 struct sigma_conn *conn,
9095 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009096{
9097 const char *intf = get_param(cmd, "Interface");
9098 const char *val, *mcs32, *rate;
9099
9100 val = get_param(cmd, "GREENFIELD");
9101 if (val) {
9102 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
9103 /* Enable GD */
9104 send_resp(dut, conn, SIGMA_ERROR,
9105 "ErrorCode,GF not supported");
9106 return 0;
9107 }
9108 }
9109
9110 val = get_param(cmd, "SGI20");
9111 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009112 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009113 case DRIVER_ATHEROS:
9114 ath_sta_set_sgi(dut, intf, val);
9115 break;
9116 default:
9117 send_resp(dut, conn, SIGMA_ERROR,
9118 "ErrorCode,SGI20 not supported");
9119 return 0;
9120 }
9121 }
9122
9123 mcs32 = get_param(cmd, "MCS32"); /* HT Duplicate Mode Enable/Disable */
9124 rate = get_param(cmd, "MCS_FIXEDRATE"); /* Fixed MCS rate (0..31) */
9125 if (mcs32 && rate) {
9126 /* TODO */
9127 send_resp(dut, conn, SIGMA_ERROR,
9128 "ErrorCode,MCS32,MCS_FIXEDRATE not supported");
9129 return 0;
9130 } else if (mcs32 && !rate) {
9131 /* TODO */
9132 send_resp(dut, conn, SIGMA_ERROR,
9133 "ErrorCode,MCS32 not supported");
9134 return 0;
9135 } else if (!mcs32 && rate) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009136 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009137 case DRIVER_ATHEROS:
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07009138 novap_reset(dut, intf, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009139 ath_sta_set_11nrates(dut, intf, rate);
9140 break;
9141 default:
9142 send_resp(dut, conn, SIGMA_ERROR,
9143 "ErrorCode,MCS32_FIXEDRATE not supported");
9144 return 0;
9145 }
9146 }
9147
9148 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
9149}
9150
9151
Arif Hussain7b47d2d2018-05-09 10:44:02 -07009152static void cmd_set_max_he_mcs(struct sigma_dut *dut, const char *intf,
9153 int mcs_config)
9154{
9155#ifdef NL80211_SUPPORT
9156 int ret;
9157
9158 switch (mcs_config) {
9159 case HE_80_MCS0_7:
9160 case HE_80_MCS0_9:
9161 case HE_80_MCS0_11:
9162 ret = sta_set_he_mcs(dut, intf, mcs_config);
9163 if (ret) {
9164 sigma_dut_print(dut, DUT_MSG_ERROR,
9165 "cmd_set_max_he_mcs: Setting of MCS:%d failed, ret:%d",
9166 mcs_config, ret);
9167 }
9168 break;
9169 default:
9170 sigma_dut_print(dut, DUT_MSG_ERROR,
9171 "cmd_set_max_he_mcs: Invalid mcs %d",
9172 mcs_config);
9173 break;
9174 }
9175#else /* NL80211_SUPPORT */
9176 sigma_dut_print(dut, DUT_MSG_ERROR,
9177 "max HE MCS cannot be changed without NL80211_SUPPORT defined");
9178#endif /* NL80211_SUPPORT */
9179}
9180
9181
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07009182struct wait_event {
9183 struct sigma_dut *dut;
9184 int cmd;
9185 unsigned int twt_op;
9186};
9187
9188#ifdef NL80211_SUPPORT
9189
9190static int twt_event_handler(struct nl_msg *msg, void *arg)
9191{
9192 struct wait_event *wait = arg;
9193 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
9194 struct nlattr *tb[NL80211_ATTR_MAX + 1];
9195 uint32_t subcmd;
9196 uint8_t *data = NULL;
9197 size_t len = 0;
9198 struct nlattr *twt_rsp[QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_MAX + 1];
9199 struct nlattr *twt_status[QCA_WLAN_VENDOR_ATTR_TWT_SETUP_MAX + 1];
9200 int cmd_id;
9201 unsigned char val;
9202
9203 if (!wait)
9204 return NL_SKIP;
9205
9206 if (gnlh->cmd != NL80211_CMD_VENDOR) {
9207 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9208 "%s: NL cmd is not vendor %d", __func__,
9209 gnlh->cmd);
9210 return NL_SKIP;
9211 }
9212
9213 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
9214 genlmsg_attrlen(gnlh, 0), NULL);
9215
9216 if (!tb[NL80211_ATTR_VENDOR_ID] || !tb[NL80211_ATTR_VENDOR_SUBCMD]) {
9217 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9218 "%s: vendor ID not found", __func__);
9219 return NL_SKIP;
9220 }
9221 subcmd = nla_get_u32(tb[NL80211_ATTR_VENDOR_SUBCMD]);
9222
9223 if (subcmd != QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) {
9224 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9225 "%s: Not a TWT_cmd %d", __func__, subcmd);
9226 return NL_SKIP;
9227 }
9228 if (tb[NL80211_ATTR_VENDOR_DATA]) {
9229 data = nla_data(tb[NL80211_ATTR_VENDOR_DATA]);
9230 len = nla_len(tb[NL80211_ATTR_VENDOR_DATA]);
9231 } else {
9232 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9233 "%s: vendor data not present", __func__);
9234 return NL_SKIP;
9235 }
9236 if (!data || !len) {
9237 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9238 "Invalid vendor data or len");
9239 return NL_SKIP;
9240 }
9241 sigma_dut_print(wait->dut, DUT_MSG_DEBUG,
9242 "event data len %ld", len);
9243 hex_dump(wait->dut, data, len);
9244 if (nla_parse(twt_rsp, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_MAX,
9245 (struct nlattr *) data, len, NULL)) {
9246 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9247 "vendor data parse error");
9248 return NL_SKIP;
9249 }
9250
9251 val = nla_get_u8(twt_rsp[QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION]);
9252 if (val != wait->twt_op) {
9253 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9254 "Invalid TWT operation, expected %d, rcvd %d",
9255 wait->twt_op, val);
9256 return NL_SKIP;
9257 }
9258 if (nla_parse_nested(twt_status, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_MAX,
9259 twt_rsp[QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS],
9260 NULL)) {
9261 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9262 "nla_parse failed for TWT event");
9263 return NL_SKIP;
9264 }
9265
9266 cmd_id = QCA_WLAN_VENDOR_ATTR_TWT_SETUP_STATUS;
9267 if (!twt_status[cmd_id]) {
9268 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9269 "%s TWT resp status missing", __func__);
9270 wait->cmd = -1;
9271 } else {
9272 val = nla_get_u8(twt_status[cmd_id]);
9273 if (val != QCA_WLAN_VENDOR_TWT_STATUS_OK) {
9274 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9275 "%s TWT resp status %d", __func__, val);
9276 wait->cmd = -1;
9277 } else {
9278 wait->cmd = 1;
9279 }
9280 }
9281
9282 return NL_SKIP;
9283}
9284
9285
9286static int wait_on_nl_socket(struct nl_sock *sock, struct sigma_dut *dut,
9287 unsigned int timeout)
9288{
9289 fd_set read_fd_set;
9290 int retval;
9291 int sock_fd;
9292 struct timeval time_out;
9293
9294 time_out.tv_sec = timeout;
9295 time_out.tv_usec = 0;
9296
9297 FD_ZERO(&read_fd_set);
9298
9299 if (!sock)
9300 return -1;
9301
9302 sock_fd = nl_socket_get_fd(sock);
9303 FD_SET(sock_fd, &read_fd_set);
9304
9305 retval = select(sock_fd + 1, &read_fd_set, NULL, NULL, &time_out);
9306
9307 if (retval == 0)
9308 sigma_dut_print(dut, DUT_MSG_ERROR,
9309 "%s: TWT event response timedout", __func__);
9310
9311 if (retval < 0)
9312 sigma_dut_print(dut, DUT_MSG_ERROR, "%s:no NL msgs, ret=%d",
9313 __func__, retval);
9314
9315 return retval;
9316}
9317
9318
9319#define TWT_ASYNC_EVENT_WAIT_TIME_SEC 6
9320
9321static int twt_async_event_wait(struct sigma_dut *dut, unsigned int twt_op)
9322{
9323 struct nl_cb *cb;
9324 int err_code = 0, select_retval = 0;
9325 struct wait_event wait_info;
9326
9327 cb = nl_socket_get_cb(dut->nl_ctx->event_sock);
9328 if (!cb) {
9329 sigma_dut_print(dut, DUT_MSG_ERROR,
9330 "event callback not found");
9331 return ERROR_SEND_STATUS;
9332 }
9333
9334 wait_info.cmd = 0;
9335 wait_info.dut = dut;
9336 wait_info.twt_op = twt_op;
9337
9338 nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, twt_event_handler, &wait_info);
9339
9340 while (!wait_info.cmd) {
9341 select_retval = wait_on_nl_socket(
9342 dut->nl_ctx->event_sock, dut,
9343 TWT_ASYNC_EVENT_WAIT_TIME_SEC);
9344
9345 if (select_retval > 0) {
9346 err_code = nl_recvmsgs(dut->nl_ctx->event_sock, cb);
9347 if (err_code < 0) {
9348 sigma_dut_print(dut, DUT_MSG_ERROR,
9349 "%s: nl rcv failed, err_code %d",
9350 __func__, err_code);
9351 break;
9352 }
9353 } else {
9354 sigma_dut_print(dut, DUT_MSG_ERROR,
9355 "%s: wait on socket failed %d",
9356 __func__, select_retval);
9357 err_code = 1;
9358 break;
9359 }
9360
9361 }
9362 nl_cb_put(cb);
9363
9364 if (wait_info.cmd < 0)
9365 err_code = 1;
9366
9367 sigma_dut_print(dut, DUT_MSG_DEBUG,
9368 "%s: rcvd cmd %d, err_code %d, s_ret %d",
9369 __func__, wait_info.cmd, err_code, select_retval);
9370
9371 return err_code;
9372}
9373
9374#endif /* NL80211_SUPPORT */
9375
9376
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009377static int sta_twt_send_suspend(struct sigma_dut *dut, struct sigma_conn *conn,
9378 struct sigma_cmd *cmd)
9379{
9380#ifdef NL80211_SUPPORT
9381 struct nlattr *attr, *attr1;
9382 struct nl_msg *msg;
9383 int ifindex, ret;
9384 const char *intf = get_param(cmd, "Interface");
9385
9386 ifindex = if_nametoindex(intf);
9387 if (ifindex == 0) {
9388 sigma_dut_print(dut, DUT_MSG_ERROR,
9389 "%s: Index for interface %s failed",
9390 __func__, intf);
9391 return ERROR_SEND_STATUS;
9392 }
9393
9394 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9395 NL80211_CMD_VENDOR)) ||
9396 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9397 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9398 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9399 QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) ||
9400 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9401 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION,
9402 QCA_WLAN_TWT_SUSPEND) ||
9403 !(attr1 = nla_nest_start(msg,
Kiran Kumar Lokere7ede00c2021-08-09 00:59:52 -07009404 QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS))) {
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009405 sigma_dut_print(dut, DUT_MSG_ERROR,
9406 "%s: err in adding vendor_cmd and vendor_data",
9407 __func__);
9408 nlmsg_free(msg);
9409 return ERROR_SEND_STATUS;
9410 }
9411 nla_nest_end(msg, attr1);
9412 nla_nest_end(msg, attr);
9413
9414 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9415 if (ret) {
9416 sigma_dut_print(dut, DUT_MSG_ERROR,
9417 "%s: err in send_and_recv_msgs, ret=%d",
9418 __func__, ret);
9419 }
9420
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07009421 if (!dut->sta_async_twt_supp)
9422 return ret;
9423
9424 return twt_async_event_wait(dut, QCA_WLAN_TWT_SUSPEND);
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009425#else /* NL80211_SUPPORT */
9426 sigma_dut_print(dut, DUT_MSG_ERROR,
9427 "TWT suspend cannot be done without NL80211_SUPPORT defined");
9428 return ERROR_SEND_STATUS;
9429#endif /* NL80211_SUPPORT */
9430}
9431
9432
9433static int sta_twt_send_nudge(struct sigma_dut *dut, struct sigma_conn *conn,
9434 struct sigma_cmd *cmd,
9435 unsigned int suspend_duration)
9436{
9437#ifdef NL80211_SUPPORT
9438 struct nlattr *attr, *attr1;
9439 struct nl_msg *msg;
9440 int ifindex, ret;
9441 const char *intf = get_param(cmd, "Interface");
9442 int next_twt_size = 1;
9443
9444 ifindex = if_nametoindex(intf);
9445 if (ifindex == 0) {
9446 sigma_dut_print(dut, DUT_MSG_ERROR,
9447 "%s: Index for interface %s failed",
9448 __func__, intf);
9449 return ERROR_SEND_STATUS;
9450 }
9451
9452 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9453 NL80211_CMD_VENDOR)) ||
9454 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9455 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9456 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9457 QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) ||
9458 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9459 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION,
9460 QCA_WLAN_TWT_NUDGE) ||
9461 !(attr1 = nla_nest_start(msg,
9462 QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS)) ||
9463 (suspend_duration &&
9464 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_NUDGE_WAKE_TIME,
9465 suspend_duration)) ||
9466 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_NUDGE_NEXT_TWT_SIZE,
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -07009467 next_twt_size) ||
9468 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_NUDGE_FLOW_ID, 0)) {
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009469 sigma_dut_print(dut, DUT_MSG_ERROR,
9470 "%s: err in adding vendor_cmd and vendor_data",
9471 __func__);
9472 nlmsg_free(msg);
9473 return ERROR_SEND_STATUS;
9474 }
9475 nla_nest_end(msg, attr1);
9476 nla_nest_end(msg, attr);
9477
9478 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9479 if (ret) {
9480 sigma_dut_print(dut, DUT_MSG_ERROR,
9481 "%s: err in send_and_recv_msgs, ret=%d",
9482 __func__, ret);
9483 }
9484
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07009485 if (!dut->sta_async_twt_supp)
9486 return ret;
9487
9488 return twt_async_event_wait(dut, QCA_WLAN_TWT_NUDGE);
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009489#else /* NL80211_SUPPORT */
9490 sigma_dut_print(dut, DUT_MSG_ERROR,
9491 "TWT suspend cannot be done without NL80211_SUPPORT defined");
9492 return ERROR_SEND_STATUS;
9493#endif /* NL80211_SUPPORT */
9494}
9495
9496
9497static int sta_twt_suspend_or_nudge(struct sigma_dut *dut,
9498 struct sigma_conn *conn,
9499 struct sigma_cmd *cmd)
9500{
9501 const char *val;
9502
9503 val = get_param(cmd, "TWT_SuspendDuration");
9504 if (val) {
9505 unsigned int suspend_duration;
9506
9507 suspend_duration = atoi(val);
9508 suspend_duration = suspend_duration * 1000 * 1000;
9509 return sta_twt_send_nudge(dut, conn, cmd, suspend_duration);
9510 }
9511
9512 return sta_twt_send_suspend(dut, conn, cmd);
9513}
9514
9515
9516static int sta_twt_resume(struct sigma_dut *dut, struct sigma_conn *conn,
9517 struct sigma_cmd *cmd)
9518{
9519#ifdef NL80211_SUPPORT
9520 struct nlattr *attr, *attr1;
9521 struct nl_msg *msg;
9522 int ifindex, ret;
9523 const char *intf = get_param(cmd, "Interface");
9524 int next2_twt_size = 1;
9525 unsigned int resume_duration = 0;
9526 const char *val;
9527
9528 ifindex = if_nametoindex(intf);
9529 if (ifindex == 0) {
9530 sigma_dut_print(dut, DUT_MSG_ERROR,
9531 "%s: Index for interface %s failed",
9532 __func__, intf);
9533 return ERROR_SEND_STATUS;
9534 }
9535
9536 val = get_param(cmd, "TWT_ResumeDuration");
9537 if (val) {
9538 resume_duration = atoi(val);
9539 resume_duration = resume_duration * 1000 * 1000;
9540 }
9541
9542 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9543 NL80211_CMD_VENDOR)) ||
9544 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9545 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9546 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9547 QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) ||
9548 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9549 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION,
9550 QCA_WLAN_TWT_RESUME) ||
9551 !(attr1 = nla_nest_start(msg,
9552 QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS)) ||
9553 (resume_duration &&
9554 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_RESUME_NEXT2_TWT,
9555 resume_duration)) ||
9556 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_RESUME_NEXT_TWT_SIZE,
9557 next2_twt_size)) {
9558 sigma_dut_print(dut, DUT_MSG_ERROR,
9559 "%s: err in adding vendor_cmd and vendor_data",
9560 __func__);
9561 nlmsg_free(msg);
9562 return ERROR_SEND_STATUS;
9563 }
9564 nla_nest_end(msg, attr1);
9565 nla_nest_end(msg, attr);
9566
9567 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9568 if (ret) {
9569 sigma_dut_print(dut, DUT_MSG_ERROR,
9570 "%s: err in send_and_recv_msgs, ret=%d",
9571 __func__, ret);
9572 }
9573
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07009574 if (!dut->sta_async_twt_supp)
9575 return ret;
9576
9577 return twt_async_event_wait(dut, QCA_WLAN_TWT_RESUME);
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009578#else /* NL80211_SUPPORT */
9579 sigma_dut_print(dut, DUT_MSG_ERROR,
9580 "TWT resume cannot be done without NL80211_SUPPORT defined");
9581 return ERROR_SEND_STATUS;
9582#endif /* NL80211_SUPPORT */
9583}
9584
9585
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07009586#define TWT_REQUEST_CMD 0
9587#define TWT_SUGGEST_CMD 1
9588#define TWT_DEMAND_CMD 2
9589
Arif Hussain480d5f42019-03-12 14:40:42 -07009590static int sta_twt_request(struct sigma_dut *dut, struct sigma_conn *conn,
9591 struct sigma_cmd *cmd)
9592{
9593#ifdef NL80211_SUPPORT
9594 struct nlattr *params;
9595 struct nlattr *attr;
Arif Hussain480d5f42019-03-12 14:40:42 -07009596 struct nl_msg *msg;
9597 int ifindex, ret;
9598 const char *val;
9599 const char *intf = get_param(cmd, "Interface");
9600 int wake_interval_exp = 10, nominal_min_wake_dur = 255,
9601 wake_interval_mantissa = 512;
9602 int flow_type = 0, twt_trigger = 0, target_wake_time = 0,
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07009603 protection = 0, cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_SUGGEST;
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -07009604 int bcast_twt = 0;
9605 int bcast_twt_id = 0, bcast_twt_recommdn = 0, bcast_twt_persis = 0;
Arif Hussain480d5f42019-03-12 14:40:42 -07009606
9607 ifindex = if_nametoindex(intf);
9608 if (ifindex == 0) {
9609 sigma_dut_print(dut, DUT_MSG_ERROR,
9610 "%s: Index for interface %s failed",
9611 __func__, intf);
9612 return -1;
9613 }
9614
9615 val = get_param(cmd, "FlowType");
9616 if (val) {
9617 flow_type = atoi(val);
9618 if (flow_type != 0 && flow_type != 1) {
9619 sigma_dut_print(dut, DUT_MSG_ERROR,
9620 "TWT: Invalid FlowType %d", flow_type);
9621 return -1;
9622 }
9623 }
9624
9625 val = get_param(cmd, "TWT_Trigger");
9626 if (val) {
9627 twt_trigger = atoi(val);
9628 if (twt_trigger != 0 && twt_trigger != 1) {
9629 sigma_dut_print(dut, DUT_MSG_ERROR,
9630 "TWT: Invalid TWT_Trigger %d",
9631 twt_trigger);
9632 return -1;
9633 }
9634 }
9635
9636 val = get_param(cmd, "Protection");
9637 if (val) {
9638 protection = atoi(val);
9639 if (protection != 0 && protection != 1) {
9640 sigma_dut_print(dut, DUT_MSG_ERROR,
9641 "TWT: Invalid Protection %d",
9642 protection);
9643 return -1;
9644 }
9645 }
9646
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07009647 val = get_param(cmd, "SetupCommand");
9648 if (val) {
9649 cmd_type = atoi(val);
9650 if (cmd_type == TWT_REQUEST_CMD)
9651 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_REQUEST;
9652 else if (cmd_type == TWT_SUGGEST_CMD)
9653 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_SUGGEST;
9654 else if (cmd_type == TWT_DEMAND_CMD)
9655 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_DEMAND;
9656 else
9657 sigma_dut_print(dut, DUT_MSG_ERROR,
9658 "Default suggest is used for cmd %d",
9659 cmd_type);
9660 }
9661
Arif Hussain480d5f42019-03-12 14:40:42 -07009662 val = get_param(cmd, "TargetWakeTime");
9663 if (val)
9664 target_wake_time = atoi(val);
9665
9666 val = get_param(cmd, "WakeIntervalMantissa");
9667 if (val)
9668 wake_interval_mantissa = atoi(val);
9669
9670 val = get_param(cmd, "WakeIntervalExp");
9671 if (val)
9672 wake_interval_exp = atoi(val);
9673
9674 val = get_param(cmd, "NominalMinWakeDur");
9675 if (val)
9676 nominal_min_wake_dur = atoi(val);
9677
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -07009678 val = get_param(cmd, "BTWT_ID");
9679 if (val) {
9680 bcast_twt_id = atoi(val);
9681 bcast_twt = 1;
9682 }
9683
9684 val = get_param(cmd, "BTWT_Persistence");
9685 if (val) {
9686 bcast_twt_persis = atoi(val);
9687 bcast_twt = 1;
9688 }
9689
9690 val = get_param(cmd, "BTWT_Recommendation");
9691 if (val) {
9692 bcast_twt_recommdn = atoi(val);
9693 bcast_twt = 1;
9694 }
9695
9696 if (bcast_twt)
9697 sigma_dut_print(dut, DUT_MSG_DEBUG,
9698 "BCAST_TWT: ID %d, RECOMM %d, PERSIS %d",
9699 bcast_twt_id, bcast_twt_recommdn,
9700 bcast_twt_persis);
9701
Arif Hussain480d5f42019-03-12 14:40:42 -07009702 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9703 NL80211_CMD_VENDOR)) ||
9704 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9705 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9706 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009707 QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07009708 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009709 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION,
9710 QCA_WLAN_TWT_SET) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07009711 !(params = nla_nest_start(
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009712 msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07009713 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_EXP,
9714 wake_interval_exp) ||
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07009715 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_REQ_TYPE, cmd_type) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -07009716 (twt_trigger &&
9717 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_TRIGGER)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07009718 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE,
9719 flow_type) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -07009720 (protection &&
9721 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_PROTECTION)) ||
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -07009722 (bcast_twt &&
9723 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_BCAST)) ||
9724 (bcast_twt &&
9725 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_BCAST_ID,
9726 bcast_twt_id)) ||
9727 (bcast_twt &&
9728 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_BCAST_PERSISTENCE,
9729 bcast_twt_persis)) ||
9730 (bcast_twt &&
9731 nla_put_u8(msg,
9732 QCA_WLAN_VENDOR_ATTR_TWT_SETUP_BCAST_RECOMMENDATION,
9733 bcast_twt_recommdn)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07009734 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_TIME,
9735 target_wake_time) ||
9736 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_DURATION,
9737 nominal_min_wake_dur) ||
9738 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_MANTISSA,
9739 wake_interval_mantissa)) {
9740 sigma_dut_print(dut, DUT_MSG_ERROR,
9741 "%s: err in adding vendor_cmd and vendor_data",
9742 __func__);
9743 nlmsg_free(msg);
9744 return -1;
9745 }
Arif Hussain480d5f42019-03-12 14:40:42 -07009746 nla_nest_end(msg, params);
9747 nla_nest_end(msg, attr);
9748
9749 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9750 if (ret) {
9751 sigma_dut_print(dut, DUT_MSG_ERROR,
9752 "%s: err in send_and_recv_msgs, ret=%d",
9753 __func__, ret);
9754 }
9755
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07009756 if (!dut->sta_async_twt_supp)
9757 return ret;
9758
9759 return twt_async_event_wait(dut, QCA_WLAN_TWT_SET);
Arif Hussain480d5f42019-03-12 14:40:42 -07009760#else /* NL80211_SUPPORT */
9761 sigma_dut_print(dut, DUT_MSG_ERROR,
9762 "TWT request cannot be done without NL80211_SUPPORT defined");
9763 return -1;
9764#endif /* NL80211_SUPPORT */
9765}
9766
9767
9768static int sta_twt_teardown(struct sigma_dut *dut, struct sigma_conn *conn,
9769 struct sigma_cmd *cmd)
9770{
9771 #ifdef NL80211_SUPPORT
9772 struct nlattr *params;
9773 struct nlattr *attr;
Arif Hussain480d5f42019-03-12 14:40:42 -07009774 int ifindex, ret;
9775 struct nl_msg *msg;
9776 const char *intf = get_param(cmd, "Interface");
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -07009777 int bcast_twt = 0;
9778 int bcast_twt_id = 0;
9779 const char *val;
Arif Hussain480d5f42019-03-12 14:40:42 -07009780
9781 ifindex = if_nametoindex(intf);
9782 if (ifindex == 0) {
9783 sigma_dut_print(dut, DUT_MSG_ERROR,
9784 "%s: Index for interface %s failed",
9785 __func__, intf);
9786 return -1;
9787 }
9788
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -07009789 val = get_param(cmd, "BTWT_ID");
9790 if (val) {
9791 bcast_twt_id = atoi(val);
9792 bcast_twt = 1;
9793 }
9794
Arif Hussain480d5f42019-03-12 14:40:42 -07009795 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9796 NL80211_CMD_VENDOR)) ||
9797 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9798 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9799 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009800 QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07009801 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009802 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION,
9803 QCA_WLAN_TWT_TERMINATE) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07009804 !(params = nla_nest_start(
9805 msg,
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009806 QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS)) ||
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -07009807 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE, 0) ||
9808 (bcast_twt &&
9809 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_BCAST)) ||
9810 (bcast_twt &&
9811 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_BCAST_ID,
9812 bcast_twt_id))) {
Arif Hussain480d5f42019-03-12 14:40:42 -07009813 sigma_dut_print(dut, DUT_MSG_ERROR,
9814 "%s: err in adding vendor_cmd and vendor_data",
9815 __func__);
9816 nlmsg_free(msg);
9817 return -1;
9818 }
Arif Hussain480d5f42019-03-12 14:40:42 -07009819 nla_nest_end(msg, params);
9820 nla_nest_end(msg, attr);
9821
9822 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9823 if (ret) {
9824 sigma_dut_print(dut, DUT_MSG_ERROR,
9825 "%s: err in send_and_recv_msgs, ret=%d",
9826 __func__, ret);
9827 }
9828
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07009829 if (!dut->sta_async_twt_supp)
9830 return ret;
9831
9832 return twt_async_event_wait(dut, QCA_WLAN_TWT_TERMINATE);
Arif Hussain480d5f42019-03-12 14:40:42 -07009833#else /* NL80211_SUPPORT */
9834 sigma_dut_print(dut, DUT_MSG_ERROR,
9835 "TWT teardown cannot be done without NL80211_SUPPORT defined");
9836 return -1;
9837#endif /* NL80211_SUPPORT */
9838}
9839
9840
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -08009841static int sta_transmit_omi(struct sigma_dut *dut, struct sigma_conn *conn,
9842 struct sigma_cmd *cmd)
9843{
9844#ifdef NL80211_SUPPORT
9845 struct nlattr *params;
9846 struct nlattr *attr;
9847 struct nlattr *attr1;
9848 struct nl_msg *msg;
9849 int ifindex, ret;
9850 const char *val;
9851 const char *intf = get_param(cmd, "Interface");
9852 uint8_t rx_nss = 0xFF, ch_bw = 0xFF, tx_nsts = 0xFF, ulmu_dis = 0,
9853 ulmu_data_dis = 0;
9854
9855 ifindex = if_nametoindex(intf);
9856 if (ifindex == 0) {
9857 sigma_dut_print(dut, DUT_MSG_ERROR,
9858 "%s: Index for interface %s failed",
9859 __func__, intf);
9860 return -1;
9861 }
9862 val = get_param(cmd, "OMCtrl_RxNSS");
9863 if (val)
9864 rx_nss = atoi(val);
9865
9866 val = get_param(cmd, "OMCtrl_ChnlWidth");
9867 if (val)
9868 ch_bw = atoi(val);
9869
9870 val = get_param(cmd, "OMCtrl_ULMUDisable");
9871 if (val)
9872 ulmu_dis = atoi(val);
9873
9874 val = get_param(cmd, "OMCtrl_TxNSTS");
9875 if (val)
9876 tx_nsts = atoi(val);
9877
9878 val = get_param(cmd, "OMCtrl_ULMUDataDisable");
9879 if (val)
9880 ulmu_data_dis = atoi(val);
9881
9882 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9883 NL80211_CMD_VENDOR)) ||
9884 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9885 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9886 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9887 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
9888 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9889 !(params = nla_nest_start(
9890 msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OMI_TX)) ||
9891 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9892 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_RX_NSS, rx_nss) ||
9893 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_CH_BW, ch_bw) ||
9894 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_TX_NSTS, tx_nsts) ||
9895 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DATA_DISABLE,
9896 ulmu_data_dis) ||
9897 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DISABLE,
9898 ulmu_dis)) {
9899 sigma_dut_print(dut, DUT_MSG_ERROR,
9900 "%s: err in adding vendor_cmd and vendor_data",
9901 __func__);
9902 nlmsg_free(msg);
9903 return -1;
9904 }
9905 nla_nest_end(msg, attr1);
9906 nla_nest_end(msg, params);
9907 nla_nest_end(msg, attr);
9908
9909 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9910 if (ret) {
9911 sigma_dut_print(dut, DUT_MSG_ERROR,
9912 "%s: err in send_and_recv_msgs, ret=%d",
9913 __func__, ret);
9914 }
9915
9916 return ret;
9917#else /* NL80211_SUPPORT */
9918 sigma_dut_print(dut, DUT_MSG_ERROR,
9919 "OMI TX cannot be processed without NL80211_SUPPORT defined");
9920 return -1;
9921#endif /* NL80211_SUPPORT */
9922}
9923
9924
Jouni Malinen224e3902021-06-09 16:41:27 +03009925static enum sigma_cmd_result
9926cmd_sta_set_wireless_vht(struct sigma_dut *dut, struct sigma_conn *conn,
9927 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009928{
9929 const char *intf = get_param(cmd, "Interface");
9930 const char *val;
Arif Hussaina37e9552018-06-20 17:05:59 -07009931 const char *program;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009932 int tkip = -1;
9933 int wep = -1;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05309934 int iwpriv_status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009935
Arif Hussaina37e9552018-06-20 17:05:59 -07009936 program = get_param(cmd, "Program");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009937 val = get_param(cmd, "SGI80");
9938 if (val) {
9939 int sgi80;
9940
9941 sgi80 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009942 run_iwpriv(dut, intf, "shortgi %d", sgi80);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009943 }
9944
9945 val = get_param(cmd, "TxBF");
9946 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009947 switch (get_driver_type(dut)) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009948 case DRIVER_WCN:
9949 if (sta_set_tx_beamformee(dut, intf, 1)) {
9950 send_resp(dut, conn, SIGMA_ERROR,
9951 "ErrorCode,Failed to set TX beamformee enable");
Jouni Malinen224e3902021-06-09 16:41:27 +03009952 return STATUS_SENT_ERROR;
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009953 }
9954 break;
9955 case DRIVER_ATHEROS:
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009956 if (run_iwpriv(dut, intf, "vhtsubfee 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009957 send_resp(dut, conn, SIGMA_ERROR,
9958 "ErrorCode,Setting vhtsubfee failed");
Jouni Malinen224e3902021-06-09 16:41:27 +03009959 return STATUS_SENT_ERROR;
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009960 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009961 if (run_iwpriv(dut, intf, "vhtsubfer 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009962 send_resp(dut, conn, SIGMA_ERROR,
9963 "ErrorCode,Setting vhtsubfer failed");
Jouni Malinen224e3902021-06-09 16:41:27 +03009964 return STATUS_SENT_ERROR;
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009965 }
9966 break;
9967 default:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009968 sigma_dut_print(dut, DUT_MSG_ERROR,
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009969 "Unsupported driver type");
9970 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009971 }
9972 }
9973
9974 val = get_param(cmd, "MU_TxBF");
9975 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009976 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009977 case DRIVER_ATHEROS:
9978 ath_sta_set_txsp_stream(dut, intf, "1SS");
9979 ath_sta_set_rxsp_stream(dut, intf, "1SS");
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009980 run_iwpriv(dut, intf, "vhtmubfee 1");
9981 run_iwpriv(dut, intf, "vhtmubfer 1");
Sunil Duttae9e5d12018-06-29 11:50:47 +05309982 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009983 case DRIVER_WCN:
9984 if (wcn_sta_set_sp_stream(dut, intf, "1SS") < 0) {
9985 send_resp(dut, conn, SIGMA_ERROR,
9986 "ErrorCode,Failed to set RX/TXSP_STREAM");
Jouni Malinen224e3902021-06-09 16:41:27 +03009987 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009988 }
Sunil Duttae9e5d12018-06-29 11:50:47 +05309989 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009990 default:
9991 sigma_dut_print(dut, DUT_MSG_ERROR,
9992 "Setting SP_STREAM not supported");
9993 break;
9994 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009995 }
9996
9997 val = get_param(cmd, "LDPC");
9998 if (val) {
9999 int ldpc;
10000
10001 ldpc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +053010002 iwpriv_status = run_iwpriv(dut, intf, "ldpc %d", ldpc);
10003 if (iwpriv_status)
10004 sta_config_params(dut, intf, STA_SET_LDPC, ldpc);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010005 }
10006
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -080010007 val = get_param(cmd, "BCC");
10008 if (val) {
10009 int bcc;
10010
10011 bcc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
10012 /* use LDPC iwpriv itself to set bcc coding, bcc coding
10013 * is mutually exclusive to bcc */
Mohammad Asaad Akram50848402020-05-28 14:10:24 +053010014 iwpriv_status = run_iwpriv(dut, intf, "ldpc %d", !bcc);
10015 if (iwpriv_status)
10016 sta_config_params(dut, intf, STA_SET_LDPC, !bcc);
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -080010017 }
10018
Arif Hussain7b47d2d2018-05-09 10:44:02 -070010019 val = get_param(cmd, "MaxHE-MCS_1SS_RxMapLTE80");
10020 if (val && dut->sta_nss == 1)
10021 cmd_set_max_he_mcs(dut, intf, atoi(val));
10022
10023 val = get_param(cmd, "MaxHE-MCS_2SS_RxMapLTE80");
10024 if (val && dut->sta_nss == 2)
10025 cmd_set_max_he_mcs(dut, intf, atoi(val));
10026
Arif Hussainac6c5112018-05-25 17:34:00 -070010027 val = get_param(cmd, "MCS_FixedRate");
10028 if (val) {
10029#ifdef NL80211_SUPPORT
10030 int mcs, ratecode = 0;
10031 enum he_mcs_config mcs_config;
10032 int ret;
Jouni Malinenb9b671d2019-04-26 13:23:17 +030010033 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -070010034
10035 ratecode = (0x07 & dut->sta_nss) << 5;
10036 mcs = atoi(val);
10037 /* Add the MCS to the ratecode */
10038 if (mcs >= 0 && mcs <= 11) {
10039 ratecode += mcs;
10040 if (dut->device_type == STA_testbed &&
10041 mcs > 7 && mcs <= 11) {
10042 if (mcs <= 9)
10043 mcs_config = HE_80_MCS0_9;
10044 else
10045 mcs_config = HE_80_MCS0_11;
10046 ret = sta_set_he_mcs(dut, intf, mcs_config);
10047 if (ret) {
10048 sigma_dut_print(dut, DUT_MSG_ERROR,
10049 "MCS_FixedRate: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
10050 mcs, mcs_config, ret);
10051 }
10052 }
10053 snprintf(buf, sizeof(buf),
10054 "iwpriv %s set_11ax_rate 0x%03x",
10055 intf, ratecode);
10056 if (system(buf) != 0) {
10057 sigma_dut_print(dut, DUT_MSG_ERROR,
10058 "MCS_FixedRate: iwpriv setting of 11ax rates 0x%03x failed",
10059 ratecode);
10060 }
10061 } else {
10062 sigma_dut_print(dut, DUT_MSG_ERROR,
10063 "MCS_FixedRate: HE MCS %d not supported",
10064 mcs);
10065 }
10066#else /* NL80211_SUPPORT */
10067 sigma_dut_print(dut, DUT_MSG_ERROR,
10068 "MCS_FixedRate cannot be changed without NL80211_SUPPORT defined");
10069#endif /* NL80211_SUPPORT */
10070 }
10071
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010072 val = get_param(cmd, "opt_md_notif_ie");
10073 if (val) {
10074 char *result = NULL;
10075 char delim[] = ";";
10076 char token[30];
10077 int value, config_val = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010078 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010079
Peng Xub8fc5cc2017-05-10 17:27:28 -070010080 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010081 result = strtok_r(token, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010082
10083 /* Extract the NSS information */
10084 if (result) {
10085 value = atoi(result);
10086 switch (value) {
10087 case 1:
10088 config_val = 1;
10089 break;
10090 case 2:
10091 config_val = 3;
10092 break;
10093 case 3:
10094 config_val = 7;
10095 break;
10096 case 4:
10097 config_val = 15;
10098 break;
10099 default:
10100 config_val = 3;
10101 break;
10102 }
10103
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010104 run_iwpriv(dut, intf, "rxchainmask %d", config_val);
10105 run_iwpriv(dut, intf, "txchainmask %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010106
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010107 }
10108
10109 /* Extract the channel width information */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010110 result = strtok_r(NULL, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010111 if (result) {
10112 value = atoi(result);
10113 switch (value) {
10114 case 20:
10115 config_val = 0;
10116 break;
10117 case 40:
10118 config_val = 1;
10119 break;
10120 case 80:
10121 config_val = 2;
10122 break;
10123 case 160:
10124 config_val = 3;
10125 break;
10126 default:
10127 config_val = 2;
10128 break;
10129 }
10130
10131 dut->chwidth = config_val;
10132
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010133 run_iwpriv(dut, intf, "chwidth %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010134 }
10135
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010136 run_iwpriv(dut, intf, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010137 }
10138
10139 val = get_param(cmd, "nss_mcs_cap");
10140 if (val) {
10141 int nss, mcs;
10142 char token[20];
10143 char *result = NULL;
10144 unsigned int vht_mcsmap = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010145 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010146
Peng Xub8fc5cc2017-05-10 17:27:28 -070010147 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010148 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +053010149 if (!result) {
10150 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -070010151 "NSS not specified");
10152 send_resp(dut, conn, SIGMA_ERROR,
10153 "errorCode,NSS not specified");
Jouni Malinen224e3902021-06-09 16:41:27 +030010154 return STATUS_SENT_ERROR;
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +053010155 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010156 nss = atoi(result);
10157
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010158 run_iwpriv(dut, intf, "nss %d", nss);
Arif Hussainac6c5112018-05-25 17:34:00 -070010159 dut->sta_nss = nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010160
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010161 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010162 if (result == NULL) {
10163 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -070010164 "MCS not specified");
10165 send_resp(dut, conn, SIGMA_ERROR,
10166 "errorCode,MCS not specified");
Jouni Malinen224e3902021-06-09 16:41:27 +030010167 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010168 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010169 result = strtok_r(result, "-", &saveptr);
10170 result = strtok_r(NULL, "-", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +053010171 if (!result) {
10172 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -070010173 "MCS not specified");
10174 send_resp(dut, conn, SIGMA_ERROR,
10175 "errorCode,MCS not specified");
Jouni Malinen224e3902021-06-09 16:41:27 +030010176 return STATUS_SENT_ERROR;
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +053010177 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010178 mcs = atoi(result);
10179
Arif Hussaina37e9552018-06-20 17:05:59 -070010180 if (program && strcasecmp(program, "HE") == 0) {
10181#ifdef NL80211_SUPPORT
10182 enum he_mcs_config mcs_config;
10183 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010184
Arif Hussaina37e9552018-06-20 17:05:59 -070010185 if (mcs >= 0 && mcs <= 7) {
10186 mcs_config = HE_80_MCS0_7;
10187 } else if (mcs > 7 && mcs <= 9) {
10188 mcs_config = HE_80_MCS0_9;
10189 } else if (mcs > 9 && mcs <= 11) {
10190 mcs_config = HE_80_MCS0_11;
10191 } else {
10192 sigma_dut_print(dut, DUT_MSG_ERROR,
10193 "nss_mcs_cap: HE: Invalid mcs: %d",
10194 mcs);
10195 send_resp(dut, conn, SIGMA_ERROR,
10196 "errorCode,Invalid MCS");
Jouni Malinen224e3902021-06-09 16:41:27 +030010197 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010198 }
Arif Hussaina37e9552018-06-20 17:05:59 -070010199
10200 ret = sta_set_he_mcs(dut, intf, mcs_config);
10201 if (ret) {
10202 sigma_dut_print(dut, DUT_MSG_ERROR,
10203 "nss_mcs_cap: HE: Setting of MCS failed, mcs_config: %d, ret: %d",
10204 mcs_config, ret);
10205 send_resp(dut, conn, SIGMA_ERROR,
10206 "errorCode,Failed to set MCS");
Jouni Malinen224e3902021-06-09 16:41:27 +030010207 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010208 }
Arif Hussaina37e9552018-06-20 17:05:59 -070010209#else /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010210 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -070010211 "nss_mcs_cap: HE: MCS cannot be changed without NL80211_SUPPORT defined");
10212#endif /* NL80211_SUPPORT */
10213 } else {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010214 run_iwpriv(dut, intf, "vhtmcs %d", mcs);
Arif Hussaina37e9552018-06-20 17:05:59 -070010215
10216 switch (nss) {
10217 case 1:
10218 switch (mcs) {
10219 case 7:
10220 vht_mcsmap = 0xfffc;
10221 break;
10222 case 8:
10223 vht_mcsmap = 0xfffd;
10224 break;
10225 case 9:
10226 vht_mcsmap = 0xfffe;
10227 break;
10228 default:
10229 vht_mcsmap = 0xfffe;
10230 break;
10231 }
10232 break;
10233 case 2:
10234 switch (mcs) {
10235 case 7:
10236 vht_mcsmap = 0xfff0;
10237 break;
10238 case 8:
10239 vht_mcsmap = 0xfff5;
10240 break;
10241 case 9:
10242 vht_mcsmap = 0xfffa;
10243 break;
10244 default:
10245 vht_mcsmap = 0xfffa;
10246 break;
10247 }
10248 break;
10249 case 3:
10250 switch (mcs) {
10251 case 7:
10252 vht_mcsmap = 0xffc0;
10253 break;
10254 case 8:
10255 vht_mcsmap = 0xffd5;
10256 break;
10257 case 9:
10258 vht_mcsmap = 0xffea;
10259 break;
10260 default:
10261 vht_mcsmap = 0xffea;
10262 break;
10263 }
10264 break;
10265 default:
10266 vht_mcsmap = 0xffea;
10267 break;
10268 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010269 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010270 }
10271 }
10272
10273 /* UNSUPPORTED: val = get_param(cmd, "Tx_lgi_rate"); */
10274
10275 val = get_param(cmd, "Vht_tkip");
10276 if (val)
10277 tkip = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
10278
10279 val = get_param(cmd, "Vht_wep");
10280 if (val)
10281 wep = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
10282
10283 if (tkip != -1 || wep != -1) {
10284 if ((tkip == 1 && wep != 0) || (wep == 1 && tkip != 0)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010285 run_iwpriv(dut, intf, "htweptkip 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010286 } else if ((tkip == 0 && wep != 1) || (wep == 0 && tkip != 1)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010287 run_iwpriv(dut, intf, "htweptkip 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010288 } else {
Jouni Malinen224e3902021-06-09 16:41:27 +030010289 send_resp(dut, conn, SIGMA_ERROR,
10290 "ErrorCode,mixed mode of VHT TKIP/WEP not supported");
10291 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010292 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010293 }
10294
Kiran Kumar Lokere09dbcef2021-08-09 00:01:41 -070010295 val = get_param(cmd, "TWTSchedSTASupport");
10296 if (val) {
10297 int set_val;
10298
10299 switch (get_driver_type(dut)) {
10300 case DRIVER_WCN:
10301 if (strcasecmp(val, "Enable") == 0) {
10302 set_val = 1;
10303 } else if (strcasecmp(val, "Disable") == 0) {
10304 set_val = 0;
10305 } else {
10306 send_resp(dut, conn, SIGMA_ERROR,
10307 "ErrorCode,Invalid TWTSchedSTASupport");
10308 return STATUS_SENT_ERROR;
10309 }
10310
10311 if (sta_set_bcast_twt_support(dut, intf, set_val)) {
10312 send_resp(dut, conn, SIGMA_ERROR,
10313 "ErrorCode,Failed to set TWTSchedSTASupport");
10314 return STATUS_SENT_ERROR;
10315 }
10316 break;
10317 default:
10318 sigma_dut_print(dut, DUT_MSG_ERROR,
10319 "Setting TWTSchedSTASupport not supported");
10320 break;
10321 }
10322 }
10323
10324 val = get_param(cmd, "MBSSID_RxCtrl");
10325 if (val) {
10326 int set_val;
10327
10328 switch (get_driver_type(dut)) {
10329 case DRIVER_WCN:
10330 if (strcasecmp(val, "Enable") == 0) {
10331 set_val = 1;
10332 } else if (strcasecmp(val, "Disable") == 0) {
10333 set_val = 0;
10334 } else {
10335 send_resp(dut, conn, SIGMA_ERROR,
10336 "ErrorCode,Invalid MBSSID_RxCtrl");
10337 return STATUS_SENT_ERROR;
10338 }
10339
10340 if (sta_set_rx_ctrl_multi_bss(dut, intf, set_val)) {
10341 send_resp(dut, conn, SIGMA_ERROR,
10342 "ErrorCode,Failed to set MBSSID_RxCtrl");
10343 return STATUS_SENT_ERROR;
10344 }
10345 break;
10346 default:
10347 sigma_dut_print(dut, DUT_MSG_ERROR,
10348 "Setting MBSSID_RxCtrl not supported");
10349 break;
10350 }
10351 }
10352
Arif Hussain55f00da2018-07-03 08:28:26 -070010353 val = get_param(cmd, "txBandwidth");
10354 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010355 switch (get_driver_type(dut)) {
Arif Hussain55f00da2018-07-03 08:28:26 -070010356 case DRIVER_WCN:
10357 if (wcn_sta_set_width(dut, intf, val) < 0) {
10358 send_resp(dut, conn, SIGMA_ERROR,
10359 "ErrorCode,Failed to set txBandwidth");
Jouni Malinen224e3902021-06-09 16:41:27 +030010360 return STATUS_SENT_ERROR;
Arif Hussain55f00da2018-07-03 08:28:26 -070010361 }
10362 break;
10363 case DRIVER_ATHEROS:
10364 if (ath_set_width(dut, conn, intf, val) < 0) {
10365 send_resp(dut, conn, SIGMA_ERROR,
10366 "ErrorCode,Failed to set txBandwidth");
Jouni Malinen224e3902021-06-09 16:41:27 +030010367 return STATUS_SENT_ERROR;
Arif Hussain55f00da2018-07-03 08:28:26 -070010368 }
10369 break;
10370 default:
10371 sigma_dut_print(dut, DUT_MSG_ERROR,
10372 "Setting txBandwidth not supported");
10373 break;
10374 }
10375 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010376
Arif Hussain9765f7d2018-07-03 08:28:26 -070010377 val = get_param(cmd, "BeamformeeSTS");
10378 if (val) {
Kiran Kumar Lokerebc89d432018-07-10 12:20:13 -070010379 if (sta_set_tx_beamformee(dut, intf, 1)) {
10380 send_resp(dut, conn, SIGMA_ERROR,
10381 "ErrorCode,Failed to set TX beamformee enable");
Jouni Malinen224e3902021-06-09 16:41:27 +030010382 return STATUS_SENT_ERROR;
Kiran Kumar Lokerebc89d432018-07-10 12:20:13 -070010383 }
10384
Arif Hussain9765f7d2018-07-03 08:28:26 -070010385 if (sta_set_beamformee_sts(dut, intf, atoi(val))) {
10386 send_resp(dut, conn, SIGMA_ERROR,
10387 "ErrorCode,Failed to set BeamformeeSTS");
Jouni Malinen224e3902021-06-09 16:41:27 +030010388 return STATUS_SENT_ERROR;
Arif Hussain9765f7d2018-07-03 08:28:26 -070010389 }
10390 }
10391
Arif Hussain68d23f52018-07-11 13:39:08 -070010392 val = get_param(cmd, "Trig_MAC_Padding_Dur");
10393 if (val) {
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -070010394#ifdef NL80211_SUPPORT
10395 enum qca_wlan_he_mac_padding_dur set_val;
10396
10397 switch (atoi(val)) {
10398 case 16:
10399 set_val = QCA_WLAN_HE_16US_OF_PROCESS_TIME;
10400 break;
10401 case 8:
10402 set_val = QCA_WLAN_HE_8US_OF_PROCESS_TIME;
10403 break;
10404 default:
10405 set_val = QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME;
10406 break;
10407 }
10408 if (sta_set_mac_padding_duration(dut, intf, set_val)) {
Arif Hussain68d23f52018-07-11 13:39:08 -070010409 send_resp(dut, conn, SIGMA_ERROR,
10410 "ErrorCode,Failed to set MAC padding duration");
Jouni Malinen224e3902021-06-09 16:41:27 +030010411 return STATUS_SENT_ERROR;
Arif Hussain68d23f52018-07-11 13:39:08 -070010412 }
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -070010413#else /* NL80211_SUPPORT */
10414 sigma_dut_print(dut, DUT_MSG_ERROR,
10415 "MAC padding duration cannot be changed without NL80211_SUPPORT defined");
10416#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -070010417 }
10418
Arif Hussain480d5f42019-03-12 14:40:42 -070010419 val = get_param(cmd, "TWT_ReqSupport");
10420 if (val) {
10421 int set_val;
10422
10423 if (strcasecmp(val, "Enable") == 0) {
10424 set_val = 1;
10425 } else if (strcasecmp(val, "Disable") == 0) {
10426 set_val = 0;
10427 } else {
10428 send_resp(dut, conn, SIGMA_ERROR,
10429 "ErrorCode,Invalid TWT_ReqSupport");
Jouni Malinen224e3902021-06-09 16:41:27 +030010430 return STATUS_SENT_ERROR;
Arif Hussain480d5f42019-03-12 14:40:42 -070010431 }
10432
10433 if (sta_set_twt_req_support(dut, intf, set_val)) {
10434 sigma_dut_print(dut, DUT_MSG_ERROR,
10435 "Failed to set TWT req support %d",
10436 set_val);
10437 send_resp(dut, conn, SIGMA_ERROR,
10438 "ErrorCode,Failed to set TWT_ReqSupport");
Jouni Malinen224e3902021-06-09 16:41:27 +030010439 return STATUS_SENT_ERROR;
Arif Hussain480d5f42019-03-12 14:40:42 -070010440 }
10441 }
10442
Kiran Kumar Lokered0ec5ed2021-04-01 00:15:04 -070010443 val = get_param(cmd, "PreamblePunctRx");
10444 if (val && get_driver_type(dut) == DRIVER_WCN) {
10445 int set_val;
10446
10447 if (strcasecmp(val, "Enable") == 0) {
10448 set_val = 1;
10449 } else if (strcasecmp(val, "Disable") == 0) {
10450 set_val = 0;
10451 } else {
10452 send_resp(dut, conn, SIGMA_ERROR,
10453 "ErrorCode,Invalid PreamblePunctRx");
10454 return STATUS_SENT_ERROR;
10455 }
10456
10457 if (sta_set_punctured_preamble_rx(dut, intf, set_val)) {
10458 sigma_dut_print(dut, DUT_MSG_ERROR,
10459 "Failed to set PreamblePunctRx support %d",
10460 set_val);
10461 send_resp(dut, conn, SIGMA_ERROR,
10462 "ErrorCode,Failed to set PreamblePunctRx");
10463 return STATUS_SENT_ERROR;
10464 }
10465 }
10466
Srinivas Girigowda0525e292020-11-12 13:28:21 -080010467 val = get_param(cmd, "FullBW_ULMUMIMO");
10468 if (val) {
10469 int set_val;
10470
10471 if (strcasecmp(val, "Enable") == 0) {
10472 set_val = 1;
10473 } else if (strcasecmp(val, "Disable") == 0) {
10474 set_val = 0;
10475 } else {
10476 send_resp(dut, conn, SIGMA_ERROR,
10477 "ErrorCode,Invalid FullBW_ULMUMIMO");
10478 return STATUS_SENT_ERROR;
10479 }
10480
10481 if (sta_set_fullbw_ulmumimo(dut, intf, set_val)) {
10482 sigma_dut_print(dut, DUT_MSG_ERROR,
10483 "Failed to set FullBW_ULMUMIMO %d",
10484 set_val);
10485 send_resp(dut, conn, SIGMA_ERROR,
10486 "ErrorCode,Failed to set FullBW_ULMUMIMO");
10487 return STATUS_SENT_ERROR;
10488 }
10489 }
10490
Srinivas Girigowda6707f032020-10-26 15:24:46 -070010491 val = get_param(cmd, "TWTInfoFrameTx");
10492 if (val) {
10493 if (strcasecmp(val, "Enable") == 0) {
10494 /* No-op */
10495 } else if (strcasecmp(val, "Disable") == 0) {
10496 /* No-op */
10497 } else {
10498 send_resp(dut, conn, SIGMA_ERROR,
10499 "ErrorCode,Invalid TWTInfoFrameTx");
10500 return STATUS_SENT_ERROR;
10501 }
10502 }
10503
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -070010504 val = get_param(cmd, "MU_EDCA");
10505 if (val && (strcasecmp(val, "Override") == 0)) {
10506 if (sta_set_mu_edca_override(dut, intf, 1)) {
10507 send_resp(dut, conn, SIGMA_ERROR,
10508 "ErrorCode,Failed to set MU EDCA override");
Jouni Malinen224e3902021-06-09 16:41:27 +030010509 return STATUS_SENT_ERROR;
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -070010510 }
10511 }
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -070010512
Kiran Kumar Lokerefa7c7b92021-08-09 00:50:55 -070010513 val = get_param(cmd, "PPDUTxType");
10514 if (val && strcasecmp(val, "ER-SU") == 0) {
10515 if (sta_set_er_su_ppdu_type_tx(dut, intf, 1)) {
10516 send_resp(dut, conn, SIGMA_ERROR,
10517 "ErrorCode,Failed to set ER-SU PPDU type Tx");
10518 return STATUS_SENT_ERROR;
10519 }
10520 }
10521
10522 val = get_param(cmd, "RUAllocTone");
10523 if (val && strcasecmp(val, "242") == 0) {
10524 if (sta_set_ru_242_tone_tx(dut, intf, 1)) {
10525 send_resp(dut, conn, SIGMA_ERROR,
10526 "ErrorCode,Failed to set RU 242 tone Tx");
10527 return STATUS_SENT_ERROR;
10528 }
10529 }
10530
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -070010531 val = get_param(cmd, "OMControl");
10532 if (val) {
10533 int set_val = 1;
10534
10535 if (strcasecmp(val, "Enable") == 0)
10536 set_val = 1;
10537 else if (strcasecmp(val, "Disable") == 0)
10538 set_val = 0;
10539
10540 if (sta_set_om_ctrl_supp(dut, intf, set_val)) {
10541 send_resp(dut, conn, SIGMA_ERROR,
10542 "ErrorCode,Failed to set OM ctrl supp");
Jouni Malinen224e3902021-06-09 16:41:27 +030010543 return STATUS_SENT_ERROR;
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -070010544 }
10545 }
10546
Kiran Kumar Lokere4f2d4b02021-04-01 00:07:39 -070010547 val = get_param(cmd, "BSSMaxIdlePeriod");
10548 if (val && sta_set_bss_max_idle_period(dut, intf, atoi(val))) {
10549 send_resp(dut, conn, SIGMA_ERROR,
10550 "ErrorCode,Failed to set BSS max idle period");
10551 return STATUS_SENT_ERROR;
10552 }
10553
Kiran Kumar Lokere07ad92b2021-08-09 00:27:14 -070010554 val = get_param(cmd, "BSS_max_idle");
10555 if (val) {
10556 int set_val = 0;
10557
10558 if (strcasecmp(val, "Enable") == 0)
10559 set_val = 1;
10560 else if (strcasecmp(val, "Disable") == 0)
10561 set_val = 0;
10562 if (sta_set_bss_max_idle_support(dut, intf, set_val)) {
10563 send_resp(dut, conn, SIGMA_ERROR,
10564 "ErrorCode,Failed to set BSS max idle support");
10565 return STATUS_SENT_ERROR;
10566 }
10567 }
10568
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -070010569 val = get_param(cmd, "ADDBAResp_BufSize");
10570 if (val) {
10571 int buf_size;
10572
10573 if (strcasecmp(val, "gt64") == 0)
10574 buf_size = 256;
10575 else
10576 buf_size = 64;
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010577 if (get_driver_type(dut) == DRIVER_WCN &&
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -070010578 sta_set_addba_buf_size(dut, intf, buf_size)) {
10579 send_resp(dut, conn, SIGMA_ERROR,
10580 "ErrorCode,set addbaresp_buff_size failed");
Jouni Malinen224e3902021-06-09 16:41:27 +030010581 return STATUS_SENT_ERROR;
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -070010582 }
10583 }
10584
10585 val = get_param(cmd, "ADDBAReq_BufSize");
10586 if (val) {
10587 int buf_size;
10588
10589 if (strcasecmp(val, "gt64") == 0)
10590 buf_size = 256;
10591 else
10592 buf_size = 64;
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010593 if (get_driver_type(dut) == DRIVER_WCN &&
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -070010594 sta_set_addba_buf_size(dut, intf, buf_size)) {
10595 send_resp(dut, conn, SIGMA_ERROR,
10596 "ErrorCode,set addbareq_buff_size failed");
Jouni Malinen224e3902021-06-09 16:41:27 +030010597 return STATUS_SENT_ERROR;
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -070010598 }
10599 }
10600
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010601 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
10602}
10603
10604
10605static int sta_set_wireless_60g(struct sigma_dut *dut,
10606 struct sigma_conn *conn,
10607 struct sigma_cmd *cmd)
10608{
10609 const char *dev_role = get_param(cmd, "DevRole");
10610
10611 if (!dev_role) {
10612 send_resp(dut, conn, SIGMA_INVALID,
10613 "ErrorCode,DevRole not specified");
10614 return 0;
10615 }
10616
10617 if (strcasecmp(dev_role, "PCP") == 0)
10618 return sta_set_60g_pcp(dut, conn, cmd);
10619 if (strcasecmp(dev_role, "STA") == 0)
10620 return sta_set_60g_sta(dut, conn, cmd);
10621 send_resp(dut, conn, SIGMA_INVALID,
10622 "ErrorCode,DevRole not supported");
10623 return 0;
10624}
10625
10626
Ankita Bajaj0d5825b2017-10-25 16:20:17 +053010627static int sta_set_wireless_oce(struct sigma_dut *dut, struct sigma_conn *conn,
10628 struct sigma_cmd *cmd)
10629{
10630 int status;
10631 const char *intf = get_param(cmd, "Interface");
10632 const char *val = get_param(cmd, "DevRole");
10633
10634 if (val && strcasecmp(val, "STA-CFON") == 0) {
10635 status = sta_cfon_set_wireless(dut, conn, cmd);
10636 if (status)
10637 return status;
10638 }
10639 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
10640}
10641
10642
Jouni Malinen67433fc2020-06-26 22:50:33 +030010643static enum sigma_cmd_result
10644sta_set_wireless_wpa3(struct sigma_dut *dut, struct sigma_conn *conn,
10645 struct sigma_cmd *cmd)
Vamsi Krishnac1633d22020-05-06 18:31:21 +053010646{
10647 const char *intf = get_param(cmd, "Interface");
10648 const char *val;
10649
10650 val = get_param(cmd, "ocvc");
10651 if (val)
10652 dut->ocvc = atoi(val);
10653
Jouni Malinen67433fc2020-06-26 22:50:33 +030010654 val = get_param(cmd, "ClientPrivacy");
Veerendranath Jakkam47867202020-12-21 01:53:52 +053010655 if (val && dut->client_privacy != atoi(val) &&
10656 sta_set_client_privacy(dut, conn, intf, atoi(val))) {
10657 send_resp(dut, conn, SIGMA_ERROR,
10658 "errorCode,Failed to configure random MAC address use");
10659 return STATUS_SENT_ERROR;
Jouni Malinen67433fc2020-06-26 22:50:33 +030010660 }
10661
Vamsi Krishnac1633d22020-05-06 18:31:21 +053010662 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
10663}
10664
10665
Jouni Malinenf7222712019-06-13 01:50:21 +030010666static enum sigma_cmd_result cmd_sta_set_wireless(struct sigma_dut *dut,
10667 struct sigma_conn *conn,
10668 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010669{
10670 const char *val;
10671
10672 val = get_param(cmd, "Program");
10673 if (val) {
10674 if (strcasecmp(val, "11n") == 0)
10675 return cmd_sta_set_11n(dut, conn, cmd);
Amarnath Hullur Subramanyam4f860292018-01-31 03:49:35 -080010676 if (strcasecmp(val, "VHT") == 0 || strcasecmp(val, "HE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010677 return cmd_sta_set_wireless_vht(dut, conn, cmd);
10678 if (strcasecmp(val, "60ghz") == 0)
10679 return sta_set_wireless_60g(dut, conn, cmd);
Ankita Bajaj0d5825b2017-10-25 16:20:17 +053010680 if (strcasecmp(val, "OCE") == 0)
10681 return sta_set_wireless_oce(dut, conn, cmd);
Alexei Avshalom Lazar66bb9972018-12-18 16:01:43 +020010682 /* sta_set_wireless in WPS program is only used for 60G */
10683 if (is_60g_sigma_dut(dut))
10684 return sta_set_wireless_60g(dut, conn, cmd);
Vamsi Krishnac1633d22020-05-06 18:31:21 +053010685 if (strcasecmp(val, "WPA3") == 0)
10686 return sta_set_wireless_wpa3(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010687 send_resp(dut, conn, SIGMA_ERROR,
10688 "ErrorCode,Program value not supported");
10689 } else {
10690 send_resp(dut, conn, SIGMA_ERROR,
10691 "ErrorCode,Program argument not available");
10692 }
10693
10694 return 0;
10695}
10696
10697
10698static void ath_sta_inject_frame(struct sigma_dut *dut, const char *intf,
10699 int tid)
10700{
10701 char buf[100];
10702 int tid_to_dscp [] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 };
10703
Pradeep Reddy POTTETId31d1322016-10-13 17:22:03 +053010704 if (tid < 0 ||
10705 tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) {
10706 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid);
10707 return;
10708 }
10709
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010710 /*
10711 * Two ways to ensure that addba request with a
10712 * non zero TID could be sent out. EV 117296
10713 */
10714 snprintf(buf, sizeof(buf),
10715 "ping -c 8 -Q %d `arp -a | grep wlan0 | awk '{print $2}' | tr -d '()'`",
10716 tid);
10717 if (system(buf) != 0) {
10718 sigma_dut_print(dut, DUT_MSG_ERROR,
10719 "Ping did not send out");
10720 }
10721
10722 snprintf(buf, sizeof(buf),
10723 "iwconfig %s | grep Access | awk '{print $6}' > %s",
10724 intf, VI_QOS_TMP_FILE);
10725 if (system(buf) != 0)
10726 return;
10727
10728 snprintf(buf, sizeof(buf),
10729 "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s",
10730 intf, VI_QOS_TMP_FILE);
10731 if (system(buf) != 0)
10732 sigma_dut_print(dut, DUT_MSG_ERROR, "HWaddr matching failed");
10733
10734 snprintf(buf,sizeof(buf), "sed -n '3,$p' %s >> %s",
10735 VI_QOS_REFFILE, VI_QOS_TMP_FILE);
10736 if (system(buf) != 0) {
10737 sigma_dut_print(dut, DUT_MSG_ERROR,
10738 "VI_QOS_TEMP_FILE generation error failed");
10739 }
10740 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
10741 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
10742 if (system(buf) != 0) {
10743 sigma_dut_print(dut, DUT_MSG_ERROR,
10744 "VI_QOS_FILE generation failed");
10745 }
10746
10747 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
10748 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
10749 if (system(buf) != 0) {
10750 sigma_dut_print(dut, DUT_MSG_ERROR,
10751 "VI_QOS_FILE generation failed");
10752 }
10753
10754 snprintf(buf, sizeof(buf), "ethinject %s %s", intf, VI_QOS_FILE);
10755 if (system(buf) != 0) {
10756 }
10757}
10758
10759
10760static int ath_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
10761 struct sigma_cmd *cmd)
10762{
10763 const char *intf = get_param(cmd, "Interface");
10764 const char *val;
10765 int tid = 0;
10766 char buf[100];
10767
10768 val = get_param(cmd, "TID");
10769 if (val) {
10770 tid = atoi(val);
10771 if (tid)
10772 ath_sta_inject_frame(dut, intf, tid);
10773 }
10774
10775 /* Command sequence for ADDBA request on Peregrine based devices */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010776 run_iwpriv(dut, intf, "setaddbaoper 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010777
10778 snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4", intf, tid);
10779 if (system(buf) != 0) {
10780 sigma_dut_print(dut, DUT_MSG_ERROR,
10781 "wifitool senddelba failed");
10782 }
10783
10784 snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64", intf, tid);
10785 if (system(buf) != 0) {
10786 sigma_dut_print(dut, DUT_MSG_ERROR,
10787 "wifitool sendaddba failed");
10788 }
10789
10790 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
10791
10792 return 1;
10793}
10794
10795
Lior David9981b512017-01-20 13:16:40 +020010796#ifdef __linux__
10797
10798static int wil6210_send_addba(struct sigma_dut *dut, const char *dest_mac,
10799 int agg_size)
10800{
10801 char dir[128], buf[128];
10802 FILE *f;
10803 regex_t re;
10804 regmatch_t m[2];
Jouni Malinen3aa72862019-05-29 23:14:51 +030010805 int rc, ret = -1, vring_id, found, res;
Lior David9981b512017-01-20 13:16:40 +020010806
10807 if (wil6210_get_debugfs_dir(dut, dir, sizeof(dir))) {
10808 sigma_dut_print(dut, DUT_MSG_ERROR,
10809 "failed to get wil6210 debugfs dir");
10810 return -1;
10811 }
10812
Jouni Malinen3aa72862019-05-29 23:14:51 +030010813 res = snprintf(buf, sizeof(buf), "%s/vrings", dir);
10814 if (res < 0 || res >= sizeof(buf))
10815 return -1;
Lior David9981b512017-01-20 13:16:40 +020010816 f = fopen(buf, "r");
10817 if (!f) {
10818 sigma_dut_print(dut, DUT_MSG_ERROR, "failed to open: %s", buf);
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +020010819 /* newer wil6210 driver renamed file to "rings" */
Jouni Malinen3aa72862019-05-29 23:14:51 +030010820 res = snprintf(buf, sizeof(buf), "%s/rings", dir);
10821 if (res < 0 || res >= sizeof(buf))
10822 return -1;
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +020010823 f = fopen(buf, "r");
10824 if (!f) {
10825 sigma_dut_print(dut, DUT_MSG_ERROR,
10826 "failed to open: %s", buf);
10827 return -1;
10828 }
Lior David9981b512017-01-20 13:16:40 +020010829 }
10830
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +020010831 /* can be either VRING tx... or RING... */
10832 if (regcomp(&re, "RING tx_[ \t]*([0-9]+)", REG_EXTENDED)) {
Lior David9981b512017-01-20 13:16:40 +020010833 sigma_dut_print(dut, DUT_MSG_ERROR, "regcomp failed");
10834 goto out;
10835 }
10836
10837 /* find TX VRING for the mac address */
10838 found = 0;
10839 while (fgets(buf, sizeof(buf), f)) {
10840 if (strcasestr(buf, dest_mac)) {
10841 found = 1;
10842 break;
10843 }
10844 }
10845
10846 if (!found) {
10847 sigma_dut_print(dut, DUT_MSG_ERROR,
10848 "no TX VRING for %s", dest_mac);
10849 goto out;
10850 }
10851
10852 /* extract VRING ID, "VRING tx_<id> = {" */
10853 if (!fgets(buf, sizeof(buf), f)) {
10854 sigma_dut_print(dut, DUT_MSG_ERROR,
10855 "no VRING start line for %s", dest_mac);
10856 goto out;
10857 }
10858
10859 rc = regexec(&re, buf, 2, m, 0);
10860 regfree(&re);
10861 if (rc || m[1].rm_so < 0) {
10862 sigma_dut_print(dut, DUT_MSG_ERROR,
10863 "no VRING TX ID for %s", dest_mac);
10864 goto out;
10865 }
10866 buf[m[1].rm_eo] = 0;
10867 vring_id = atoi(&buf[m[1].rm_so]);
10868
10869 /* send the addba command */
10870 fclose(f);
Jouni Malinen3aa72862019-05-29 23:14:51 +030010871 res = snprintf(buf, sizeof(buf), "%s/back", dir);
10872 if (res < 0 || res >= sizeof(buf))
10873 return -1;
Lior David9981b512017-01-20 13:16:40 +020010874 f = fopen(buf, "w");
10875 if (!f) {
10876 sigma_dut_print(dut, DUT_MSG_ERROR,
10877 "failed to open: %s", buf);
10878 return -1;
10879 }
10880
10881 fprintf(f, "add %d %d\n", vring_id, agg_size);
10882
10883 ret = 0;
10884
10885out:
10886 fclose(f);
10887
10888 return ret;
10889}
10890
10891
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +020010892int send_addba_60g(struct sigma_dut *dut, struct sigma_conn *conn,
10893 struct sigma_cmd *cmd, const char *mac_param)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010894{
10895 const char *val;
10896 int tid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010897
10898 val = get_param(cmd, "TID");
10899 if (val) {
10900 tid = atoi(val);
10901 if (tid != 0) {
10902 sigma_dut_print(dut, DUT_MSG_ERROR,
10903 "Ignore TID %d for send_addba use TID 0 for 60g since only 0 required on TX",
10904 tid);
10905 }
10906 }
10907
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +020010908 val = get_param(cmd, mac_param);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010909 if (!val) {
10910 sigma_dut_print(dut, DUT_MSG_ERROR,
10911 "Currently not supporting addba for 60G without Dest_mac");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020010912 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010913 }
10914
Lior David9981b512017-01-20 13:16:40 +020010915 if (wil6210_send_addba(dut, val, dut->back_rcv_buf))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010916 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010917
10918 return 1;
10919}
10920
Lior David9981b512017-01-20 13:16:40 +020010921#endif /* __linux__ */
10922
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010923
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080010924static int wcn_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
10925 struct sigma_cmd *cmd)
10926{
10927#ifdef NL80211_SUPPORT
10928 const char *intf = get_param(cmd, "Interface");
10929 const char *val;
10930 int tid = -1;
10931 int bufsize = 64;
10932 struct nl_msg *msg;
10933 int ret = 0;
10934 struct nlattr *params;
10935 int ifindex;
10936
10937 val = get_param(cmd, "TID");
10938 if (val)
10939 tid = atoi(val);
10940
10941 if (tid == -1) {
10942 send_resp(dut, conn, SIGMA_ERROR,
10943 "ErrorCode,sta_send_addba tid invalid");
10944 return 0;
10945 }
10946
10947 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
10948
10949 ifindex = if_nametoindex(intf);
10950 if (ifindex == 0) {
10951 sigma_dut_print(dut, DUT_MSG_ERROR,
10952 "%s: Index for interface %s failed",
10953 __func__, intf);
10954 send_resp(dut, conn, SIGMA_ERROR,
10955 "ErrorCode,sta_send_addba interface invalid");
10956 return 0;
10957 }
10958
10959 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
10960 NL80211_CMD_VENDOR)) ||
10961 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
10962 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
10963 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
10964 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
10965 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
10966 nla_put_u8(msg,
10967 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADD_DEL_BA_SESSION,
10968 QCA_WLAN_ADD_BA) ||
10969 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BA_TID,
10970 tid) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -070010971 nla_put_u16(msg,
10972 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
10973 bufsize)) {
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080010974 sigma_dut_print(dut, DUT_MSG_ERROR,
10975 "%s: err in adding vendor_cmd and vendor_data",
10976 __func__);
10977 nlmsg_free(msg);
10978 send_resp(dut, conn, SIGMA_ERROR,
10979 "ErrorCode,sta_send_addba err in adding vendor_cmd and vendor_data");
10980 return 0;
10981 }
10982 nla_nest_end(msg, params);
10983
10984 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
10985 if (ret) {
10986 sigma_dut_print(dut, DUT_MSG_ERROR,
10987 "%s: err in send_and_recv_msgs, ret=%d",
10988 __func__, ret);
Sunil Dutt30605592018-05-04 20:35:50 +053010989 if (ret == -EOPNOTSUPP)
10990 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080010991 send_resp(dut, conn, SIGMA_ERROR,
10992 "ErrorCode,sta_send_addba err in send_and_recv_msgs");
10993 return 0;
10994 }
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080010995#else /* NL80211_SUPPORT */
10996 sigma_dut_print(dut, DUT_MSG_ERROR,
10997 "sta_send_addba not supported without NL80211_SUPPORT defined");
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080010998#endif /* NL80211_SUPPORT */
Sunil Dutt30605592018-05-04 20:35:50 +053010999
11000 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080011001}
11002
11003
Jouni Malinenf7222712019-06-13 01:50:21 +030011004static enum sigma_cmd_result cmd_sta_send_addba(struct sigma_dut *dut,
11005 struct sigma_conn *conn,
11006 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011007{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011008 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011009 case DRIVER_ATHEROS:
11010 return ath_sta_send_addba(dut, conn, cmd);
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080011011 case DRIVER_WCN:
11012 return wcn_sta_send_addba(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +020011013#ifdef __linux__
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011014 case DRIVER_WIL6210:
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +020011015 return send_addba_60g(dut, conn, cmd, "Dest_mac");
Lior David9981b512017-01-20 13:16:40 +020011016#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011017 default:
11018 /*
11019 * There is no driver specific implementation for other drivers.
11020 * Ignore the command and report COMPLETE since the following
11021 * throughput test operation will end up sending ADDBA anyway.
11022 */
11023 return 1;
11024 }
11025}
11026
11027
11028int inject_eth_frame(int s, const void *data, size_t len,
11029 unsigned short ethtype, char *dst, char *src)
11030{
11031 struct iovec iov[4] = {
11032 {
11033 .iov_base = dst,
11034 .iov_len = ETH_ALEN,
11035 },
11036 {
11037 .iov_base = src,
11038 .iov_len = ETH_ALEN,
11039 },
11040 {
11041 .iov_base = &ethtype,
11042 .iov_len = sizeof(unsigned short),
11043 },
11044 {
11045 .iov_base = (void *) data,
11046 .iov_len = len,
11047 }
11048 };
11049 struct msghdr msg = {
11050 .msg_name = NULL,
11051 .msg_namelen = 0,
11052 .msg_iov = iov,
11053 .msg_iovlen = 4,
11054 .msg_control = NULL,
11055 .msg_controllen = 0,
11056 .msg_flags = 0,
11057 };
11058
11059 return sendmsg(s, &msg, 0);
11060}
11061
11062#if defined(__linux__) || defined(__QNXNTO__)
11063
11064int inject_frame(int s, const void *data, size_t len, int encrypt)
11065{
11066#define IEEE80211_RADIOTAP_F_WEP 0x04
11067#define IEEE80211_RADIOTAP_F_FRAG 0x08
11068 unsigned char rtap_hdr[] = {
11069 0x00, 0x00, /* radiotap version */
11070 0x0e, 0x00, /* radiotap length */
11071 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
11072 IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */
11073 0x00, /* padding */
11074 0x00, 0x00, /* RX and TX flags to indicate that */
11075 0x00, 0x00, /* this is the injected frame directly */
11076 };
11077 struct iovec iov[2] = {
11078 {
11079 .iov_base = &rtap_hdr,
11080 .iov_len = sizeof(rtap_hdr),
11081 },
11082 {
11083 .iov_base = (void *) data,
11084 .iov_len = len,
11085 }
11086 };
11087 struct msghdr msg = {
11088 .msg_name = NULL,
11089 .msg_namelen = 0,
11090 .msg_iov = iov,
11091 .msg_iovlen = 2,
11092 .msg_control = NULL,
11093 .msg_controllen = 0,
11094 .msg_flags = 0,
11095 };
11096
11097 if (encrypt)
11098 rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP;
11099
11100 return sendmsg(s, &msg, 0);
11101}
11102
11103
11104int open_monitor(const char *ifname)
11105{
11106#ifdef __QNXNTO__
11107 struct sockaddr_dl ll;
11108 int s;
11109
11110 memset(&ll, 0, sizeof(ll));
11111 ll.sdl_family = AF_LINK;
11112 ll.sdl_index = if_nametoindex(ifname);
11113 if (ll.sdl_index == 0) {
11114 perror("if_nametoindex");
11115 return -1;
11116 }
11117 s = socket(PF_INET, SOCK_RAW, 0);
11118#else /* __QNXNTO__ */
11119 struct sockaddr_ll ll;
11120 int s;
11121
11122 memset(&ll, 0, sizeof(ll));
11123 ll.sll_family = AF_PACKET;
11124 ll.sll_ifindex = if_nametoindex(ifname);
11125 if (ll.sll_ifindex == 0) {
11126 perror("if_nametoindex");
11127 return -1;
11128 }
11129 s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
11130#endif /* __QNXNTO__ */
11131 if (s < 0) {
11132 perror("socket[PF_PACKET,SOCK_RAW]");
11133 return -1;
11134 }
11135
11136 if (bind(s, (struct sockaddr *) &ll, sizeof(ll)) < 0) {
11137 perror("monitor socket bind");
11138 close(s);
11139 return -1;
11140 }
11141
11142 return s;
11143}
11144
11145
11146static int hex2num(char c)
11147{
11148 if (c >= '0' && c <= '9')
11149 return c - '0';
11150 if (c >= 'a' && c <= 'f')
11151 return c - 'a' + 10;
11152 if (c >= 'A' && c <= 'F')
11153 return c - 'A' + 10;
11154 return -1;
11155}
11156
11157
11158int hwaddr_aton(const char *txt, unsigned char *addr)
11159{
11160 int i;
11161
11162 for (i = 0; i < 6; i++) {
11163 int a, b;
11164
11165 a = hex2num(*txt++);
11166 if (a < 0)
11167 return -1;
11168 b = hex2num(*txt++);
11169 if (b < 0)
11170 return -1;
11171 *addr++ = (a << 4) | b;
11172 if (i < 5 && *txt++ != ':')
11173 return -1;
11174 }
11175
11176 return 0;
11177}
11178
11179#endif /* defined(__linux__) || defined(__QNXNTO__) */
11180
Veerendranath Jakkam49774122020-07-05 09:52:18 +053011181
11182#ifdef NL80211_SUPPORT
11183static int nl80211_send_frame_cmd(struct sigma_dut *dut, const char *intf,
11184 const u8 *data, size_t data_len, int freq)
11185{
11186 struct nl_msg *msg;
11187 int ret = 0;
11188 int ifindex;
11189
11190 ifindex = if_nametoindex(intf);
11191 if (ifindex == 0) {
11192 sigma_dut_print(dut, DUT_MSG_ERROR,
11193 "%s: Index for interface %s failed",
11194 __func__, intf);
11195 return -1;
11196 }
11197
11198 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
11199 NL80211_CMD_FRAME)) ||
11200 (freq && nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
11201 nla_put(msg, NL80211_ATTR_FRAME, data_len, data)) {
11202 sigma_dut_print(dut, DUT_MSG_ERROR,
11203 "%s: Error in adding NL80211_CMD_FRAME",
11204 __func__);
11205 nlmsg_free(msg);
11206 return -1;
11207 }
11208
11209 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
11210 if (ret) {
11211 sigma_dut_print(dut, DUT_MSG_ERROR,
11212 "nl80211: Frame command failed: ret=%d (%s) req=%u",
11213 ret, strerror(-ret), freq);
11214 return -1;
11215 }
11216
11217 return 0;
11218}
11219#endif /* NL80211_SUPPORT */
11220
11221
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011222enum send_frame_type {
11223 DISASSOC, DEAUTH, SAQUERY, AUTH, ASSOCREQ, REASSOCREQ, DLS_REQ
11224};
11225enum send_frame_protection {
11226 CORRECT_KEY, INCORRECT_KEY, UNPROTECTED
11227};
11228
11229
11230static int sta_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn,
Veerendranath Jakkam49774122020-07-05 09:52:18 +053011231 const char *intf, enum send_frame_type frame,
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011232 enum send_frame_protection protected,
Veerendranath Jakkam49774122020-07-05 09:52:18 +053011233 const char *dest, int use_monitor)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011234{
11235#ifdef __linux__
11236 unsigned char buf[1000], *pos;
11237 int s, res;
11238 char bssid[20], addr[20];
11239 char result[32], ssid[100];
11240 size_t ssid_len;
11241
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011242 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011243 sizeof(result)) < 0 ||
11244 strncmp(result, "COMPLETED", 9) != 0) {
11245 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Not connected");
11246 return 0;
11247 }
11248
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011249 if (get_wpa_status(get_station_ifname(dut), "bssid",
11250 bssid, sizeof(bssid)) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011251 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
11252 "current BSSID");
11253 return 0;
11254 }
11255
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011256 if (get_wpa_status(get_station_ifname(dut), "address",
11257 addr, sizeof(addr)) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011258 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
11259 "own MAC address");
11260 return 0;
11261 }
11262
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011263 if (get_wpa_status(get_station_ifname(dut), "ssid", ssid, sizeof(ssid))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011264 < 0) {
11265 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
11266 "current SSID");
11267 return 0;
11268 }
11269 ssid_len = strlen(ssid);
11270
11271 pos = buf;
11272
11273 /* Frame Control */
11274 switch (frame) {
11275 case DISASSOC:
11276 *pos++ = 0xa0;
11277 break;
11278 case DEAUTH:
11279 *pos++ = 0xc0;
11280 break;
11281 case SAQUERY:
11282 *pos++ = 0xd0;
11283 break;
11284 case AUTH:
11285 *pos++ = 0xb0;
11286 break;
11287 case ASSOCREQ:
11288 *pos++ = 0x00;
11289 break;
11290 case REASSOCREQ:
11291 *pos++ = 0x20;
11292 break;
11293 case DLS_REQ:
11294 *pos++ = 0xd0;
11295 break;
11296 }
11297
11298 if (protected == INCORRECT_KEY)
11299 *pos++ = 0x40; /* Set Protected field to 1 */
11300 else
11301 *pos++ = 0x00;
11302
11303 /* Duration */
11304 *pos++ = 0x00;
11305 *pos++ = 0x00;
11306
11307 /* addr1 = DA (current AP) */
11308 hwaddr_aton(bssid, pos);
11309 pos += 6;
11310 /* addr2 = SA (own address) */
11311 hwaddr_aton(addr, pos);
11312 pos += 6;
11313 /* addr3 = BSSID (current AP) */
11314 hwaddr_aton(bssid, pos);
11315 pos += 6;
11316
11317 /* Seq# (to be filled by driver/mac80211) */
11318 *pos++ = 0x00;
11319 *pos++ = 0x00;
11320
11321 if (protected == INCORRECT_KEY) {
11322 /* CCMP parameters */
11323 memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8);
11324 pos += 8;
11325 }
11326
11327 if (protected == INCORRECT_KEY) {
11328 switch (frame) {
11329 case DEAUTH:
11330 /* Reason code (encrypted) */
11331 memcpy(pos, "\xa7\x39", 2);
11332 pos += 2;
11333 break;
11334 case DISASSOC:
11335 /* Reason code (encrypted) */
11336 memcpy(pos, "\xa7\x39", 2);
11337 pos += 2;
11338 break;
11339 case SAQUERY:
11340 /* Category|Action|TransID (encrypted) */
11341 memcpy(pos, "\x6f\xbd\xe9\x4d", 4);
11342 pos += 4;
11343 break;
11344 default:
11345 return -1;
11346 }
11347
11348 /* CCMP MIC */
11349 memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8);
11350 pos += 8;
11351 } else {
11352 switch (frame) {
11353 case DEAUTH:
11354 /* reason code = 8 */
11355 *pos++ = 0x08;
11356 *pos++ = 0x00;
11357 break;
11358 case DISASSOC:
11359 /* reason code = 8 */
11360 *pos++ = 0x08;
11361 *pos++ = 0x00;
11362 break;
11363 case SAQUERY:
11364 /* Category - SA Query */
11365 *pos++ = 0x08;
11366 /* SA query Action - Request */
11367 *pos++ = 0x00;
11368 /* Transaction ID */
11369 *pos++ = 0x12;
11370 *pos++ = 0x34;
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053011371 if (dut->saquery_oci_freq) {
11372 /* OCI IE - Extended ID */
11373 *pos++ = 0xFF;
11374 *pos++ = 0x04;
11375 *pos++ = 0x36;
11376 /* Operating Class */
11377 *pos++ = 0x74;
11378 /* Primary Channel */
11379 *pos++ = freq_to_channel(dut->saquery_oci_freq);
11380 /* Frequency Segment 1 Channel Number */
11381 *pos++ = 0x00;
11382 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011383 break;
11384 case AUTH:
11385 /* Auth Alg (Open) */
11386 *pos++ = 0x00;
11387 *pos++ = 0x00;
11388 /* Seq# */
11389 *pos++ = 0x01;
11390 *pos++ = 0x00;
11391 /* Status code */
11392 *pos++ = 0x00;
11393 *pos++ = 0x00;
11394 break;
11395 case ASSOCREQ:
11396 /* Capability Information */
11397 *pos++ = 0x31;
11398 *pos++ = 0x04;
11399 /* Listen Interval */
11400 *pos++ = 0x0a;
11401 *pos++ = 0x00;
11402 /* SSID */
11403 *pos++ = 0x00;
11404 *pos++ = ssid_len;
11405 memcpy(pos, ssid, ssid_len);
11406 pos += ssid_len;
11407 /* Supported Rates */
11408 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
11409 10);
11410 pos += 10;
11411 /* Extended Supported Rates */
11412 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
11413 pos += 6;
11414 /* RSN */
11415 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
11416 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
11417 "\x00\x00\x00\x00\x0f\xac\x06", 28);
11418 pos += 28;
11419 break;
11420 case REASSOCREQ:
11421 /* Capability Information */
11422 *pos++ = 0x31;
11423 *pos++ = 0x04;
11424 /* Listen Interval */
11425 *pos++ = 0x0a;
11426 *pos++ = 0x00;
11427 /* Current AP */
11428 hwaddr_aton(bssid, pos);
11429 pos += 6;
11430 /* SSID */
11431 *pos++ = 0x00;
11432 *pos++ = ssid_len;
11433 memcpy(pos, ssid, ssid_len);
11434 pos += ssid_len;
11435 /* Supported Rates */
11436 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
11437 10);
11438 pos += 10;
11439 /* Extended Supported Rates */
11440 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
11441 pos += 6;
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053011442 /* RSNE - Group and Pairwise ciphers */
11443 memcpy(pos,
11444 "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x04",
11445 14);
11446 pos += 14;
11447 /* RSNE - AKM Suite count */
11448 *pos++ = 0x01;
11449 *pos++ = 0x00;
11450 /* RSNE - AKM Suites */
11451 if (dut->program == PROGRAM_WPA3)
11452 memcpy(pos, "\x00\x0f\xac\x08", 4);
11453 else
11454 memcpy(pos, "\x00\x0f\xac\x02", 4);
11455 pos += 4;
11456 /* RSNE - Capabilities */
11457 *pos++ = 0xc0;
11458 if (dut->ocvc)
11459 *pos++ = 0x40;
11460 else
11461 *pos++ = 0x00;
11462 /* RSNE - PMKID list and Group Management Ciphers */
11463 memcpy(pos, "\x00\x00\x00\x0f\xac\x06", 6);
11464 pos += 6;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011465 break;
11466 case DLS_REQ:
11467 /* Category - DLS */
11468 *pos++ = 0x02;
11469 /* DLS Action - Request */
11470 *pos++ = 0x00;
11471 /* Destination MACAddress */
11472 if (dest)
11473 hwaddr_aton(dest, pos);
11474 else
11475 memset(pos, 0, 6);
11476 pos += 6;
11477 /* Source MACAddress */
11478 hwaddr_aton(addr, pos);
11479 pos += 6;
11480 /* Capability Information */
11481 *pos++ = 0x10; /* Privacy */
11482 *pos++ = 0x06; /* QoS */
11483 /* DLS Timeout Value */
11484 *pos++ = 0x00;
11485 *pos++ = 0x01;
11486 /* Supported rates */
11487 *pos++ = 0x01;
11488 *pos++ = 0x08;
11489 *pos++ = 0x0c; /* 6 Mbps */
11490 *pos++ = 0x12; /* 9 Mbps */
11491 *pos++ = 0x18; /* 12 Mbps */
11492 *pos++ = 0x24; /* 18 Mbps */
11493 *pos++ = 0x30; /* 24 Mbps */
11494 *pos++ = 0x48; /* 36 Mbps */
11495 *pos++ = 0x60; /* 48 Mbps */
11496 *pos++ = 0x6c; /* 54 Mbps */
11497 /* TODO: Extended Supported Rates */
11498 /* TODO: HT Capabilities */
11499 break;
11500 }
11501 }
11502
Veerendranath Jakkam49774122020-07-05 09:52:18 +053011503 if (use_monitor) {
11504 s = open_monitor("sigmadut");
11505 if (s < 0) {
11506 send_resp(dut, conn, SIGMA_ERROR,
11507 "errorCode,Failed to open monitor socket");
11508 return 0;
11509 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011510
Veerendranath Jakkam49774122020-07-05 09:52:18 +053011511 res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY);
11512 if (res < 0) {
11513 send_resp(dut, conn, SIGMA_ERROR,
11514 "errorCode,Failed to inject frame");
11515 close(s);
11516 return 0;
11517 }
11518 if (res < pos - buf) {
11519 send_resp(dut, conn, SIGMA_ERROR,
11520 "errorCode,Only partial frame sent");
11521 close(s);
11522 return 0;
11523 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011524
Veerendranath Jakkam49774122020-07-05 09:52:18 +053011525 close(s);
11526 } else {
11527#ifdef NL80211_SUPPORT
11528 int freq;
11529 char freq_str[10];
11530
11531 if (get_wpa_status(get_station_ifname(dut), "freq",
11532 freq_str, sizeof(freq_str)) < 0) {
11533 send_resp(dut, conn, SIGMA_ERROR,
11534 "errorCode,Could not get current operating frequency");
11535 return 0;
11536 }
11537 freq = atoi(freq_str);
11538
11539 if (nl80211_send_frame_cmd(dut, intf, buf, pos - buf, freq)) {
11540 send_resp(dut, conn, SIGMA_ERROR,
11541 "errorCode,Failed to inject frame");
11542 return 0;
11543 }
11544#else /* NL80211_SUPPORT */
11545 send_resp(dut, conn, SIGMA_ERROR,
11546 "errorCode,Failed to inject frame (no NL80211_SUPPORT)");
11547 return 0;
11548#endif /* NL80211_SUPPORT */
11549 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011550
11551 return 1;
11552#else /* __linux__ */
11553 send_resp(dut, conn, SIGMA_ERROR, "errorCode,sta_send_frame not "
11554 "yet supported");
11555 return 0;
11556#endif /* __linux__ */
11557}
11558
11559
11560static int cmd_sta_send_frame_tdls(struct sigma_dut *dut,
11561 struct sigma_conn *conn,
11562 struct sigma_cmd *cmd)
11563{
11564 const char *intf = get_param(cmd, "Interface");
11565 const char *sta, *val;
11566 unsigned char addr[ETH_ALEN];
11567 char buf[100];
11568
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030011569 if (!intf)
11570 return -1;
11571
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011572 sta = get_param(cmd, "peer");
11573 if (sta == NULL)
11574 sta = get_param(cmd, "station");
11575 if (sta == NULL) {
11576 send_resp(dut, conn, SIGMA_ERROR,
11577 "ErrorCode,Missing peer address");
11578 return 0;
11579 }
11580 if (hwaddr_aton(sta, addr) < 0) {
11581 send_resp(dut, conn, SIGMA_ERROR,
11582 "ErrorCode,Invalid peer address");
11583 return 0;
11584 }
11585
11586 val = get_param(cmd, "type");
11587 if (val == NULL)
11588 return -1;
11589
11590 if (strcasecmp(val, "DISCOVERY") == 0) {
11591 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", sta);
11592 if (wpa_command(intf, buf) < 0) {
11593 send_resp(dut, conn, SIGMA_ERROR,
11594 "ErrorCode,Failed to send TDLS discovery");
11595 return 0;
11596 }
11597 return 1;
11598 }
11599
11600 if (strcasecmp(val, "SETUP") == 0) {
11601 int status = 0, timeout = 0;
11602
11603 val = get_param(cmd, "Status");
11604 if (val)
11605 status = atoi(val);
11606
11607 val = get_param(cmd, "Timeout");
11608 if (val)
11609 timeout = atoi(val);
11610
11611 if (status != 0 && status != 37) {
11612 send_resp(dut, conn, SIGMA_ERROR,
11613 "ErrorCode,Unsupported status value");
11614 return 0;
11615 }
11616
11617 if (timeout != 0 && timeout != 301) {
11618 send_resp(dut, conn, SIGMA_ERROR,
11619 "ErrorCode,Unsupported timeout value");
11620 return 0;
11621 }
11622
11623 if (status && timeout) {
11624 send_resp(dut, conn, SIGMA_ERROR,
11625 "ErrorCode,Unsupported timeout+status "
11626 "combination");
11627 return 0;
11628 }
11629
11630 if (status == 37 &&
11631 wpa_command(intf, "SET tdls_testing 0x200")) {
11632 send_resp(dut, conn, SIGMA_ERROR,
11633 "ErrorCode,Failed to enable "
11634 "decline setup response test mode");
11635 return 0;
11636 }
11637
11638 if (timeout == 301) {
11639 int res;
11640 if (dut->no_tpk_expiration)
11641 res = wpa_command(intf,
11642 "SET tdls_testing 0x108");
11643 else
11644 res = wpa_command(intf,
11645 "SET tdls_testing 0x8");
11646 if (res) {
11647 send_resp(dut, conn, SIGMA_ERROR,
11648 "ErrorCode,Failed to set short TPK "
11649 "lifetime");
11650 return 0;
11651 }
11652 }
11653
11654 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", sta);
11655 if (wpa_command(intf, buf) < 0) {
11656 send_resp(dut, conn, SIGMA_ERROR,
11657 "ErrorCode,Failed to send TDLS setup");
11658 return 0;
11659 }
11660 return 1;
11661 }
11662
11663 if (strcasecmp(val, "TEARDOWN") == 0) {
11664 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", sta);
11665 if (wpa_command(intf, buf) < 0) {
11666 send_resp(dut, conn, SIGMA_ERROR,
11667 "ErrorCode,Failed to send TDLS teardown");
11668 return 0;
11669 }
11670 return 1;
11671 }
11672
11673 send_resp(dut, conn, SIGMA_ERROR,
11674 "ErrorCode,Unsupported TDLS frame");
11675 return 0;
11676}
11677
11678
11679static int sta_ap_known(const char *ifname, const char *bssid)
11680{
11681 char buf[4096];
11682
Jouni Malinendd32f192018-09-15 02:55:19 +030011683 snprintf(buf, sizeof(buf), "BSS MASK=1 %s", bssid);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011684 if (wpa_command_resp(ifname, buf, buf, sizeof(buf)) < 0)
11685 return 0;
11686 if (strncmp(buf, "id=", 3) != 0)
11687 return 0;
11688 return 1;
11689}
11690
11691
11692static int sta_scan_ap(struct sigma_dut *dut, const char *ifname,
11693 const char *bssid)
11694{
11695 int res;
11696 struct wpa_ctrl *ctrl;
11697 char buf[256];
11698
11699 if (sta_ap_known(ifname, bssid))
11700 return 0;
11701 sigma_dut_print(dut, DUT_MSG_DEBUG,
11702 "AP not in BSS table - start scan");
11703
11704 ctrl = open_wpa_mon(ifname);
11705 if (ctrl == NULL) {
11706 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
11707 "wpa_supplicant monitor connection");
11708 return -1;
11709 }
11710
11711 if (wpa_command(ifname, "SCAN") < 0) {
11712 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to start scan");
11713 wpa_ctrl_detach(ctrl);
11714 wpa_ctrl_close(ctrl);
11715 return -1;
11716 }
11717
11718 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
11719 buf, sizeof(buf));
11720
11721 wpa_ctrl_detach(ctrl);
11722 wpa_ctrl_close(ctrl);
11723
11724 if (res < 0) {
11725 sigma_dut_print(dut, DUT_MSG_INFO, "Scan did not complete");
11726 return -1;
11727 }
11728
11729 if (sta_ap_known(ifname, bssid))
11730 return 0;
11731 sigma_dut_print(dut, DUT_MSG_INFO, "AP not in BSS table");
11732 return -1;
11733}
11734
11735
11736static int cmd_sta_send_frame_hs2_neighadv(struct sigma_dut *dut,
11737 struct sigma_conn *conn,
11738 struct sigma_cmd *cmd,
11739 const char *intf)
11740{
11741 char buf[200];
11742
11743 snprintf(buf, sizeof(buf), "ndsend 2001:DB8::1 %s", intf);
11744 if (system(buf) != 0) {
11745 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Failed to run "
11746 "ndsend");
11747 return 0;
11748 }
11749
11750 return 1;
11751}
11752
11753
11754static int cmd_sta_send_frame_hs2_neighsolreq(struct sigma_dut *dut,
11755 struct sigma_conn *conn,
11756 struct sigma_cmd *cmd,
11757 const char *intf)
11758{
11759 char buf[200];
11760 const char *ip = get_param(cmd, "SenderIP");
11761
Peng Xu26b356d2017-10-04 17:58:16 -070011762 if (!ip)
11763 return 0;
11764
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011765 snprintf(buf, sizeof(buf), "ndisc6 -nm %s %s -r 4", ip, intf);
11766 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11767 if (system(buf) == 0) {
11768 sigma_dut_print(dut, DUT_MSG_INFO,
11769 "Neighbor Solicitation got a response "
11770 "for %s@%s", ip, intf);
11771 }
11772
11773 return 1;
11774}
11775
11776
11777static int cmd_sta_send_frame_hs2_arpprobe(struct sigma_dut *dut,
11778 struct sigma_conn *conn,
11779 struct sigma_cmd *cmd,
11780 const char *ifname)
11781{
11782 char buf[200];
11783 const char *ip = get_param(cmd, "SenderIP");
11784
11785 if (ip == NULL) {
11786 send_resp(dut, conn, SIGMA_ERROR,
11787 "ErrorCode,Missing SenderIP parameter");
11788 return 0;
11789 }
11790 snprintf(buf, sizeof(buf), "arping -I %s -D %s -c 4", ifname, ip);
11791 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11792 if (system(buf) != 0) {
11793 sigma_dut_print(dut, DUT_MSG_INFO, "arping DAD got a response "
11794 "for %s@%s", ip, ifname);
11795 }
11796
11797 return 1;
11798}
11799
11800
11801static int cmd_sta_send_frame_hs2_arpannounce(struct sigma_dut *dut,
11802 struct sigma_conn *conn,
11803 struct sigma_cmd *cmd,
11804 const char *ifname)
11805{
11806 char buf[200];
11807 char ip[16];
11808 int s;
Peng Xub3756882017-10-04 14:39:09 -070011809 struct ifreq ifr;
11810 struct sockaddr_in saddr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011811
11812 s = socket(PF_INET, SOCK_DGRAM, 0);
Peng Xub3756882017-10-04 14:39:09 -070011813 if (s < 0) {
11814 perror("socket");
11815 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011816 }
11817
Peng Xub3756882017-10-04 14:39:09 -070011818 memset(&ifr, 0, sizeof(ifr));
11819 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
11820 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
11821 sigma_dut_print(dut, DUT_MSG_INFO,
11822 "Failed to get %s IP address: %s",
11823 ifname, strerror(errno));
11824 close(s);
11825 return -1;
11826 }
11827 close(s);
11828
11829 memcpy(&saddr, &ifr.ifr_addr, sizeof(struct sockaddr_in));
11830 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
11831
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011832 snprintf(buf, sizeof(buf), "arping -I %s -s %s %s -c 4", ifname, ip,
11833 ip);
11834 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11835 if (system(buf) != 0) {
11836 }
11837
11838 return 1;
11839}
11840
11841
11842static int cmd_sta_send_frame_hs2_arpreply(struct sigma_dut *dut,
11843 struct sigma_conn *conn,
11844 struct sigma_cmd *cmd,
11845 const char *ifname)
11846{
11847 char buf[200], addr[20];
11848 char dst[ETH_ALEN], src[ETH_ALEN];
11849 short ethtype = htons(ETH_P_ARP);
11850 char *pos;
11851 int s, res;
11852 const char *val;
11853 struct sockaddr_in taddr;
11854
11855 val = get_param(cmd, "dest");
11856 if (val)
11857 hwaddr_aton(val, (unsigned char *) dst);
11858
11859 val = get_param(cmd, "DestIP");
11860 if (val)
11861 inet_aton(val, &taddr.sin_addr);
Peng Xu151c9e12017-10-04 14:39:09 -070011862 else
11863 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011864
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011865 if (get_wpa_status(get_station_ifname(dut), "address", addr,
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011866 sizeof(addr)) < 0)
11867 return -2;
11868 hwaddr_aton(addr, (unsigned char *) src);
11869
11870 pos = buf;
11871 *pos++ = 0x00;
11872 *pos++ = 0x01;
11873 *pos++ = 0x08;
11874 *pos++ = 0x00;
11875 *pos++ = 0x06;
11876 *pos++ = 0x04;
11877 *pos++ = 0x00;
11878 *pos++ = 0x02;
11879 memcpy(pos, src, ETH_ALEN);
11880 pos += ETH_ALEN;
11881 memcpy(pos, &taddr.sin_addr, 4);
11882 pos += 4;
11883 memcpy(pos, dst, ETH_ALEN);
11884 pos += ETH_ALEN;
11885 memcpy(pos, &taddr.sin_addr, 4);
11886 pos += 4;
11887
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011888 s = open_monitor(get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011889 if (s < 0) {
11890 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
11891 "monitor socket");
11892 return 0;
11893 }
11894
11895 res = inject_eth_frame(s, buf, pos - buf, ethtype, dst, src);
11896 if (res < 0) {
11897 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
11898 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +053011899 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011900 return 0;
11901 }
11902
11903 close(s);
11904
11905 return 1;
11906}
11907
11908
11909static int cmd_sta_send_frame_hs2_dls_req(struct sigma_dut *dut,
11910 struct sigma_conn *conn,
11911 struct sigma_cmd *cmd,
11912 const char *intf, const char *dest)
11913{
11914 char buf[100];
11915
11916 if (if_nametoindex("sigmadut") == 0) {
11917 snprintf(buf, sizeof(buf),
11918 "iw dev %s interface add sigmadut type monitor",
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011919 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011920 if (system(buf) != 0 ||
11921 if_nametoindex("sigmadut") == 0) {
11922 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
11923 "monitor interface with '%s'", buf);
11924 return -2;
11925 }
11926 }
11927
11928 if (system("ifconfig sigmadut up") != 0) {
11929 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
11930 "monitor interface up");
11931 return -2;
11932 }
11933
Veerendranath Jakkam49774122020-07-05 09:52:18 +053011934 return sta_inject_frame(dut, conn, intf, DLS_REQ, UNPROTECTED, dest, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011935}
11936
11937
11938static int cmd_sta_send_frame_hs2(struct sigma_dut *dut,
11939 struct sigma_conn *conn,
11940 struct sigma_cmd *cmd)
11941{
11942 const char *intf = get_param(cmd, "Interface");
11943 const char *dest = get_param(cmd, "Dest");
11944 const char *type = get_param(cmd, "FrameName");
11945 const char *val;
11946 char buf[200], *pos, *end;
11947 int count, count2;
11948
11949 if (type == NULL)
11950 type = get_param(cmd, "Type");
11951
11952 if (intf == NULL || dest == NULL || type == NULL)
11953 return -1;
11954
11955 if (strcasecmp(type, "NeighAdv") == 0)
11956 return cmd_sta_send_frame_hs2_neighadv(dut, conn, cmd, intf);
11957
11958 if (strcasecmp(type, "NeighSolicitReq") == 0)
11959 return cmd_sta_send_frame_hs2_neighsolreq(dut, conn, cmd, intf);
11960
11961 if (strcasecmp(type, "ARPProbe") == 0)
11962 return cmd_sta_send_frame_hs2_arpprobe(dut, conn, cmd, intf);
11963
11964 if (strcasecmp(type, "ARPAnnounce") == 0)
11965 return cmd_sta_send_frame_hs2_arpannounce(dut, conn, cmd, intf);
11966
11967 if (strcasecmp(type, "ARPReply") == 0)
11968 return cmd_sta_send_frame_hs2_arpreply(dut, conn, cmd, intf);
11969
11970 if (strcasecmp(type, "DLS-request") == 0 ||
11971 strcasecmp(type, "DLSrequest") == 0)
11972 return cmd_sta_send_frame_hs2_dls_req(dut, conn, cmd, intf,
11973 dest);
11974
11975 if (strcasecmp(type, "ANQPQuery") != 0 &&
11976 strcasecmp(type, "Query") != 0) {
11977 send_resp(dut, conn, SIGMA_ERROR,
11978 "ErrorCode,Unsupported HS 2.0 send frame type");
11979 return 0;
11980 }
11981
11982 if (sta_scan_ap(dut, intf, dest) < 0) {
11983 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not find "
11984 "the requested AP");
11985 return 0;
11986 }
11987
11988 pos = buf;
11989 end = buf + sizeof(buf);
11990 count = 0;
11991 pos += snprintf(pos, end - pos, "ANQP_GET %s ", dest);
11992
11993 val = get_param(cmd, "ANQP_CAP_LIST");
11994 if (val && atoi(val)) {
11995 pos += snprintf(pos, end - pos, "%s257", count > 0 ? "," : "");
11996 count++;
11997 }
11998
11999 val = get_param(cmd, "VENUE_NAME");
12000 if (val && atoi(val)) {
12001 pos += snprintf(pos, end - pos, "%s258", count > 0 ? "," : "");
12002 count++;
12003 }
12004
12005 val = get_param(cmd, "NETWORK_AUTH_TYPE");
12006 if (val && atoi(val)) {
12007 pos += snprintf(pos, end - pos, "%s260", count > 0 ? "," : "");
12008 count++;
12009 }
12010
12011 val = get_param(cmd, "ROAMING_CONS");
12012 if (val && atoi(val)) {
12013 pos += snprintf(pos, end - pos, "%s261", count > 0 ? "," : "");
12014 count++;
12015 }
12016
12017 val = get_param(cmd, "IP_ADDR_TYPE_AVAILABILITY");
12018 if (val && atoi(val)) {
12019 pos += snprintf(pos, end - pos, "%s262", count > 0 ? "," : "");
12020 count++;
12021 }
12022
12023 val = get_param(cmd, "NAI_REALM_LIST");
12024 if (val && atoi(val)) {
12025 pos += snprintf(pos, end - pos, "%s263", count > 0 ? "," : "");
12026 count++;
12027 }
12028
12029 val = get_param(cmd, "3GPP_INFO");
12030 if (val && atoi(val)) {
12031 pos += snprintf(pos, end - pos, "%s264", count > 0 ? "," : "");
12032 count++;
12033 }
12034
12035 val = get_param(cmd, "DOMAIN_LIST");
12036 if (val && atoi(val)) {
12037 pos += snprintf(pos, end - pos, "%s268", count > 0 ? "," : "");
12038 count++;
12039 }
12040
Jouni Malinen34cf9532018-04-29 19:26:33 +030012041 val = get_param(cmd, "Venue_URL");
12042 if (val && atoi(val)) {
12043 pos += snprintf(pos, end - pos, "%s277", count > 0 ? "," : "");
12044 count++;
12045 }
12046
Jouni Malinend3bca5d2018-04-29 17:25:23 +030012047 val = get_param(cmd, "Advice_Of_Charge");
12048 if (val && atoi(val)) {
12049 pos += snprintf(pos, end - pos, "%s278", count > 0 ? "," : "");
12050 count++;
12051 }
12052
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012053 if (count && wpa_command(intf, buf)) {
12054 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,ANQP_GET failed");
12055 return 0;
12056 }
12057
12058 pos = buf;
12059 end = buf + sizeof(buf);
12060 count2 = 0;
12061 pos += snprintf(pos, end - pos, "HS20_ANQP_GET %s ", dest);
12062
12063 val = get_param(cmd, "HS_CAP_LIST");
12064 if (val && atoi(val)) {
12065 pos += snprintf(pos, end - pos, "%s2", count2 > 0 ? "," : "");
12066 count2++;
12067 }
12068
12069 val = get_param(cmd, "OPER_NAME");
12070 if (val && atoi(val)) {
12071 pos += snprintf(pos, end - pos, "%s3", count2 > 0 ? "," : "");
12072 count2++;
12073 }
12074
12075 val = get_param(cmd, "WAN_METRICS");
12076 if (!val)
12077 val = get_param(cmd, "WAN_MAT");
12078 if (!val)
12079 val = get_param(cmd, "WAN_MET");
12080 if (val && atoi(val)) {
12081 pos += snprintf(pos, end - pos, "%s4", count2 > 0 ? "," : "");
12082 count2++;
12083 }
12084
12085 val = get_param(cmd, "CONNECTION_CAPABILITY");
12086 if (val && atoi(val)) {
12087 pos += snprintf(pos, end - pos, "%s5", count2 > 0 ? "," : "");
12088 count2++;
12089 }
12090
12091 val = get_param(cmd, "OP_CLASS");
12092 if (val && atoi(val)) {
12093 pos += snprintf(pos, end - pos, "%s7", count2 > 0 ? "," : "");
12094 count2++;
12095 }
12096
12097 val = get_param(cmd, "OSU_PROVIDER_LIST");
12098 if (val && atoi(val)) {
12099 pos += snprintf(pos, end - pos, "%s8", count2 > 0 ? "," : "");
12100 count2++;
12101 }
12102
Jouni Malinenf67afec2018-04-29 19:24:58 +030012103 val = get_param(cmd, "OPER_ICON_METADATA");
12104 if (!val)
12105 val = get_param(cmd, "OPERATOR_ICON_METADATA");
12106 if (val && atoi(val)) {
12107 pos += snprintf(pos, end - pos, "%s12", count2 > 0 ? "," : "");
12108 count2++;
12109 }
12110
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012111 if (count && count2) {
12112 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before sending out "
12113 "second query");
12114 sleep(1);
12115 }
12116
12117 if (count2 && wpa_command(intf, buf)) {
12118 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,HS20_ANQP_GET "
12119 "failed");
12120 return 0;
12121 }
12122
12123 val = get_param(cmd, "NAI_HOME_REALM_LIST");
12124 if (val) {
12125 if (count || count2) {
12126 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
12127 "sending out second query");
12128 sleep(1);
12129 }
12130
12131 if (strcmp(val, "1") == 0)
12132 val = "mail.example.com";
12133 snprintf(buf, end - pos,
12134 "HS20_GET_NAI_HOME_REALM_LIST %s realm=%s",
12135 dest, val);
12136 if (wpa_command(intf, buf)) {
12137 send_resp(dut, conn, SIGMA_ERROR,
12138 "ErrorCode,HS20_GET_NAI_HOME_REALM_LIST "
12139 "failed");
12140 return 0;
12141 }
12142 }
12143
12144 val = get_param(cmd, "ICON_REQUEST");
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 snprintf(buf, end - pos,
12153 "HS20_ICON_REQUEST %s %s", dest, val);
12154 if (wpa_command(intf, buf)) {
12155 send_resp(dut, conn, SIGMA_ERROR,
12156 "ErrorCode,HS20_ICON_REQUEST failed");
12157 return 0;
12158 }
12159 }
12160
12161 return 1;
12162}
12163
12164
12165static int ath_sta_send_frame_vht(struct sigma_dut *dut,
12166 struct sigma_conn *conn,
12167 struct sigma_cmd *cmd)
12168{
12169 const char *val;
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012170 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012171 int chwidth, nss;
12172
12173 val = get_param(cmd, "framename");
12174 if (!val)
12175 return -1;
12176 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
12177
12178 /* Command sequence to generate Op mode notification */
12179 if (val && strcasecmp(val, "Op_md_notif_frm") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012180 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012181
12182 /* Disable STBC */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012183 run_iwpriv(dut, ifname, "tx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012184
12185 /* Extract Channel width */
12186 val = get_param(cmd, "Channel_width");
12187 if (val) {
12188 switch (atoi(val)) {
12189 case 20:
12190 chwidth = 0;
12191 break;
12192 case 40:
12193 chwidth = 1;
12194 break;
12195 case 80:
12196 chwidth = 2;
12197 break;
12198 case 160:
12199 chwidth = 3;
12200 break;
12201 default:
12202 chwidth = 2;
12203 break;
12204 }
12205
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012206 run_iwpriv(dut, ifname, "chwidth %d", chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012207 }
12208
12209 /* Extract NSS */
12210 val = get_param(cmd, "NSS");
12211 if (val) {
12212 switch (atoi(val)) {
12213 case 1:
12214 nss = 1;
12215 break;
12216 case 2:
12217 nss = 3;
12218 break;
12219 case 3:
12220 nss = 7;
12221 break;
12222 default:
12223 /* We do not support NSS > 3 */
12224 nss = 3;
12225 break;
12226 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012227 run_iwpriv(dut, ifname, "rxchainmask %d", nss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012228 }
12229
12230 /* Opmode notify */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012231 run_iwpriv(dut, ifname, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012232 }
12233
12234 return 1;
12235}
12236
12237
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070012238static int wcn_sta_set_pmf_config(struct sigma_dut *dut, const char *intf,
12239 enum send_frame_protection protected)
12240{
12241#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +053012242 return wcn_wifi_test_config_set_u8(
12243 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_PMF_PROTECTION,
12244 protected);
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070012245#else /* NL80211_SUPPORT */
12246 sigma_dut_print(dut, DUT_MSG_ERROR,
12247 "PMF config cannot be set without NL80211_SUPPORT defined");
12248 return -1;
12249#endif /* NL80211_SUPPORT */
12250}
12251
12252
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012253static int cmd_sta_send_frame_vht(struct sigma_dut *dut,
12254 struct sigma_conn *conn,
12255 struct sigma_cmd *cmd)
12256{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012257 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012258 case DRIVER_ATHEROS:
12259 return ath_sta_send_frame_vht(dut, conn, cmd);
12260 default:
12261 send_resp(dut, conn, SIGMA_ERROR,
12262 "errorCode,Unsupported sta_set_frame(VHT) with the current driver");
12263 return 0;
12264 }
12265}
12266
12267
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070012268static int wcn_sta_send_disassoc(struct sigma_dut *dut, const char *intf)
12269{
12270#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +053012271 return wcn_wifi_test_config_set_flag(
12272 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_DISASSOC_TX);
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070012273#else /* NL80211_SUPPORT */
12274 sigma_dut_print(dut, DUT_MSG_ERROR,
12275 "Disassoc Tx cannot be done without NL80211_SUPPORT defined");
12276 return -1;
12277#endif /* NL80211_SUPPORT */
12278}
12279
12280
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070012281static int wcn_sta_send_frame_he(struct sigma_dut *dut, struct sigma_conn *conn,
12282 struct sigma_cmd *cmd)
12283{
12284 const char *val;
12285 const char *intf = get_param(cmd, "Interface");
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070012286 enum send_frame_protection protected;
12287 const char *pmf;
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070012288
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030012289 if (!intf)
12290 return -1;
12291
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070012292 val = get_param(cmd, "framename");
12293 if (!val)
12294 return -1;
12295 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
12296
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070012297 pmf = get_param(cmd, "PMFProtected");
12298 if (!pmf)
12299 pmf = get_param(cmd, "Protected");
12300 if (pmf) {
12301 if (strcasecmp(pmf, "Correct-key") == 0 ||
12302 strcasecmp(pmf, "CorrectKey") == 0) {
12303 protected = CORRECT_KEY;
12304 } else if (strcasecmp(pmf, "IncorrectKey") == 0) {
12305 protected = INCORRECT_KEY;
12306 } else if (strcasecmp(pmf, "Unprotected") == 0) {
12307 protected = UNPROTECTED;
12308 } else {
12309 send_resp(dut, conn, SIGMA_ERROR,
12310 "errorCode,Unsupported PMFProtected");
12311 return STATUS_SENT_ERROR;
12312 }
12313 sigma_dut_print(dut, DUT_MSG_DEBUG, "Config PMF protection %d",
12314 protected);
12315 wcn_sta_set_pmf_config(dut, intf, protected);
12316 }
12317
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070012318 /* Command sequence to generate Op mode notification */
12319 if (val && strcasecmp(val, "action") == 0) {
12320 val = get_param(cmd, "PPDUTxType");
12321 if (val && strcasecmp(val, "TB") == 0) {
12322 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 1)) {
12323 sigma_dut_print(dut, DUT_MSG_ERROR,
12324 "failed to send TB PPDU Tx cfg");
12325 send_resp(dut, conn, SIGMA_ERROR,
12326 "ErrorCode,set TB PPDU Tx cfg failed");
12327 return 0;
12328 }
12329 return 1;
12330 }
12331
12332 sigma_dut_print(dut, DUT_MSG_ERROR,
12333 "Action Tx type is not defined");
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070012334
12335 return SUCCESS_SEND_STATUS;
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070012336 }
12337
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070012338 if (strcasecmp(val, "disassoc") == 0)
12339 wcn_sta_send_disassoc(dut, intf);
12340
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070012341 return 1;
12342}
12343
12344
12345static int cmd_sta_send_frame_he(struct sigma_dut *dut,
12346 struct sigma_conn *conn,
12347 struct sigma_cmd *cmd)
12348{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012349 switch (get_driver_type(dut)) {
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070012350 case DRIVER_WCN:
12351 return wcn_sta_send_frame_he(dut, conn, cmd);
12352 default:
12353 send_resp(dut, conn, SIGMA_ERROR,
12354 "errorCode,Unsupported sta_set_frame(HE) with the current driver");
12355 return 0;
12356 }
12357}
12358
12359
Lior David0fe101e2017-03-09 16:09:50 +020012360#ifdef __linux__
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030012361
12362static int
12363wil6210_send_p2p_frame_60g(struct sigma_dut *dut, struct sigma_cmd *cmd,
12364 const char *frame_name, const char *dest_mac)
12365{
12366 int isprobereq = strcasecmp(frame_name, "probereq") == 0;
12367 const char *ssid = get_param(cmd, "ssid");
12368 const char *countstr = get_param(cmd, "count");
12369 const char *channelstr = get_param(cmd, "channel");
12370 const char *group_id = get_param(cmd, "groupid");
12371 const char *client_id = get_param(cmd, "clientmac");
12372 int count, channel, freq, i;
12373 const char *fname;
12374 char frame[1024], src_mac[20], group_id_attr[25],
12375 device_macstr[3 * ETH_ALEN], client_mac[ETH_ALEN];
12376 const char *group_ssid;
12377 const int group_ssid_prefix_len = 9;
12378 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *) frame;
12379 size_t framelen = sizeof(frame);
12380 struct template_frame_tag tags[2];
12381 size_t tags_total = ARRAY_SIZE(tags);
12382 int tag_index, len, dst_len;
12383
12384 if (!countstr || !channelstr) {
12385 sigma_dut_print(dut, DUT_MSG_ERROR,
12386 "Missing argument: count, channel");
12387 return -1;
12388 }
12389 if (isprobereq && !ssid) {
12390 sigma_dut_print(dut, DUT_MSG_ERROR,
12391 "Missing argument: ssid");
12392 return -1;
12393 }
12394 if (!isprobereq && (!group_id || !client_id)) {
12395 sigma_dut_print(dut, DUT_MSG_ERROR,
12396 "Missing argument: group_id, client_id");
12397 return -1;
12398 }
12399
12400 count = atoi(countstr);
12401 channel = atoi(channelstr);
12402 freq = channel_to_freq(dut, channel);
12403
12404 if (!freq) {
12405 sigma_dut_print(dut, DUT_MSG_ERROR,
12406 "invalid channel: %s", channelstr);
12407 return -1;
12408 }
12409
12410 if (isprobereq) {
12411 if (strcasecmp(ssid, "wildcard") == 0) {
12412 fname = "probe_req_wildcard.txt";
12413 } else if (strcasecmp(ssid, "P2P_Wildcard") == 0) {
12414 fname = "probe_req_P2P_Wildcard.txt";
12415 } else {
12416 sigma_dut_print(dut, DUT_MSG_ERROR,
12417 "invalid probe request type");
12418 return -1;
12419 }
12420 } else {
12421 fname = "P2P_device_discovery_req.txt";
12422 }
12423
12424 if (parse_template_frame_file(dut, fname, frame, &framelen,
12425 tags, &tags_total)) {
12426 sigma_dut_print(dut, DUT_MSG_ERROR,
12427 "invalid frame template: %s", fname);
12428 return -1;
12429 }
12430
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012431 if (get_wpa_status(get_station_ifname(dut), "address",
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030012432 src_mac, sizeof(src_mac)) < 0 ||
12433 parse_mac_address(dut, src_mac, &hdr->addr2[0]) ||
12434 parse_mac_address(dut, dest_mac, &hdr->addr1[0]))
12435 return -1;
12436 /* Use wildcard BSSID, since we are in PBSS */
12437 memset(&hdr->addr3, 0xFF, ETH_ALEN);
12438
12439 if (!isprobereq) {
12440 tag_index = find_template_frame_tag(tags, tags_total, 1);
12441 if (tag_index < 0) {
12442 sigma_dut_print(dut, DUT_MSG_ERROR,
12443 "can't find device id attribute");
12444 return -1;
12445 }
12446 if (parse_mac_address(dut, client_id,
12447 (unsigned char *) client_mac)) {
12448 sigma_dut_print(dut, DUT_MSG_ERROR,
12449 "invalid client_id: %s", client_id);
12450 return -1;
12451 }
12452 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
12453 framelen - tags[tag_index].offset,
12454 IEEE80211_P2P_ATTR_DEVICE_ID,
12455 client_mac, ETH_ALEN)) {
12456 sigma_dut_print(dut, DUT_MSG_ERROR,
12457 "fail to replace device id attribute");
12458 return -1;
12459 }
12460
12461 /*
12462 * group_id arg contains device MAC address followed by
12463 * space and SSID (DIRECT-somessid).
12464 * group id attribute contains device address (6 bytes)
12465 * followed by SSID prefix DIRECT-XX (9 bytes)
12466 */
12467 if (strlen(group_id) < sizeof(device_macstr)) {
12468 sigma_dut_print(dut, DUT_MSG_ERROR,
12469 "group_id arg too short");
12470 return -1;
12471 }
12472 memcpy(device_macstr, group_id, sizeof(device_macstr));
12473 device_macstr[sizeof(device_macstr) - 1] = '\0';
12474 if (parse_mac_address(dut, device_macstr,
12475 (unsigned char *) group_id_attr)) {
12476 sigma_dut_print(dut, DUT_MSG_ERROR,
12477 "fail to parse device address from group_id");
12478 return -1;
12479 }
12480 group_ssid = strchr(group_id, ' ');
12481 if (!group_ssid) {
12482 sigma_dut_print(dut, DUT_MSG_ERROR,
12483 "invalid group_id arg, no ssid");
12484 return -1;
12485 }
12486 group_ssid++;
12487 len = strlen(group_ssid);
12488 if (len < group_ssid_prefix_len) {
12489 sigma_dut_print(dut, DUT_MSG_ERROR,
12490 "group_id SSID too short");
12491 return -1;
12492 }
12493 dst_len = sizeof(group_id_attr) - ETH_ALEN;
12494 if (len > dst_len) {
12495 sigma_dut_print(dut, DUT_MSG_ERROR,
12496 "group_id SSID (%s) too long",
12497 group_ssid);
12498 return -1;
12499 }
12500
12501 memcpy(group_id_attr + ETH_ALEN, group_ssid, len);
12502 tag_index = find_template_frame_tag(tags, tags_total, 2);
12503 if (tag_index < 0) {
12504 sigma_dut_print(dut, DUT_MSG_ERROR,
12505 "can't find group id attribute");
12506 return -1;
12507 }
12508 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
12509 framelen - tags[tag_index].offset,
12510 IEEE80211_P2P_ATTR_GROUP_ID,
12511 group_id_attr,
12512 sizeof(group_id_attr))) {
12513 sigma_dut_print(dut, DUT_MSG_ERROR,
12514 "fail to replace group id attribute");
12515 return -1;
12516 }
12517 }
12518
12519 for (i = 0; i < count; i++) {
12520 if (wil6210_transmit_frame(dut, freq,
12521 WIL_TRANSMIT_FRAME_DEFAULT_ROC,
12522 frame, framelen)) {
12523 sigma_dut_print(dut, DUT_MSG_ERROR,
12524 "fail to transmit probe request frame");
12525 return -1;
12526 }
12527 }
12528
12529 return 0;
12530}
12531
12532
Lior David0fe101e2017-03-09 16:09:50 +020012533int wil6210_send_frame_60g(struct sigma_dut *dut, struct sigma_conn *conn,
12534 struct sigma_cmd *cmd)
12535{
12536 const char *frame_name = get_param(cmd, "framename");
12537 const char *mac = get_param(cmd, "dest_mac");
12538
12539 if (!frame_name || !mac) {
12540 sigma_dut_print(dut, DUT_MSG_ERROR,
12541 "framename and dest_mac must be provided");
12542 return -1;
12543 }
12544
12545 if (strcasecmp(frame_name, "brp") == 0) {
12546 const char *l_rx = get_param(cmd, "L-RX");
12547 int l_rx_i;
12548
12549 if (!l_rx) {
12550 sigma_dut_print(dut, DUT_MSG_ERROR,
12551 "L-RX must be provided");
12552 return -1;
12553 }
12554 l_rx_i = atoi(l_rx);
12555
12556 sigma_dut_print(dut, DUT_MSG_INFO,
12557 "dev_send_frame: BRP-RX, dest_mac %s, L-RX %s",
12558 mac, l_rx);
12559 if (l_rx_i != 16) {
12560 sigma_dut_print(dut, DUT_MSG_ERROR,
12561 "unsupported L-RX: %s", l_rx);
12562 return -1;
12563 }
12564
12565 if (wil6210_send_brp_rx(dut, mac, l_rx_i))
12566 return -1;
12567 } else if (strcasecmp(frame_name, "ssw") == 0) {
12568 sigma_dut_print(dut, DUT_MSG_INFO,
12569 "dev_send_frame: SLS, dest_mac %s", mac);
12570 if (wil6210_send_sls(dut, mac))
12571 return -1;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030012572 } else if ((strcasecmp(frame_name, "probereq") == 0) ||
12573 (strcasecmp(frame_name, "devdiscreq") == 0)) {
12574 sigma_dut_print(dut, DUT_MSG_INFO,
12575 "dev_send_frame: %s, dest_mac %s", frame_name,
12576 mac);
12577 if (wil6210_send_p2p_frame_60g(dut, cmd, frame_name, mac))
12578 return -1;
Lior David0fe101e2017-03-09 16:09:50 +020012579 } else {
12580 sigma_dut_print(dut, DUT_MSG_ERROR,
12581 "unsupported frame type: %s", frame_name);
12582 return -1;
12583 }
12584
12585 return 1;
12586}
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030012587
Lior David0fe101e2017-03-09 16:09:50 +020012588#endif /* __linux__ */
12589
12590
12591static int cmd_sta_send_frame_60g(struct sigma_dut *dut,
12592 struct sigma_conn *conn,
12593 struct sigma_cmd *cmd)
12594{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012595 switch (get_driver_type(dut)) {
Lior David0fe101e2017-03-09 16:09:50 +020012596#ifdef __linux__
12597 case DRIVER_WIL6210:
12598 return wil6210_send_frame_60g(dut, conn, cmd);
12599#endif /* __linux__ */
12600 default:
12601 send_resp(dut, conn, SIGMA_ERROR,
12602 "errorCode,Unsupported sta_set_frame(60G) with the current driver");
12603 return 0;
12604 }
12605}
12606
12607
Ashwini Patildb59b3c2017-04-13 15:19:23 +053012608static int mbo_send_anqp_query(struct sigma_dut *dut, struct sigma_conn *conn,
12609 const char *intf, struct sigma_cmd *cmd)
12610{
12611 const char *val, *addr;
12612 char buf[100];
12613
12614 addr = get_param(cmd, "DestMac");
12615 if (!addr) {
12616 send_resp(dut, conn, SIGMA_INVALID,
12617 "ErrorCode,AP MAC address is missing");
12618 return 0;
12619 }
12620
12621 val = get_param(cmd, "ANQPQuery_ID");
12622 if (!val) {
12623 send_resp(dut, conn, SIGMA_INVALID,
12624 "ErrorCode,Missing ANQPQuery_ID");
12625 return 0;
12626 }
12627
12628 if (strcasecmp(val, "NeighborReportReq") == 0) {
12629 snprintf(buf, sizeof(buf), "ANQP_GET %s 272", addr);
12630 } else if (strcasecmp(val, "QueryListWithCellPref") == 0) {
12631 snprintf(buf, sizeof(buf), "ANQP_GET %s 272,mbo:2", addr);
12632 } else {
12633 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid ANQPQuery_ID: %s",
12634 val);
12635 send_resp(dut, conn, SIGMA_INVALID,
12636 "ErrorCode,Invalid ANQPQuery_ID");
12637 return 0;
12638 }
12639
Ashwini Patild174f2c2017-04-13 16:49:46 +053012640 /* Set gas_address3 field to IEEE 802.11-2012 standard compliant form
12641 * (Address3 = Wildcard BSSID when sent to not-associated AP;
12642 * if associated, AP BSSID).
12643 */
12644 if (wpa_command(intf, "SET gas_address3 1") < 0) {
12645 send_resp(dut, conn, SIGMA_ERROR,
12646 "ErrorCode,Failed to set gas_address3");
12647 return 0;
12648 }
12649
Ashwini Patildb59b3c2017-04-13 15:19:23 +053012650 if (wpa_command(intf, buf) < 0) {
12651 send_resp(dut, conn, SIGMA_ERROR,
12652 "ErrorCode,Failed to send ANQP query");
12653 return 0;
12654 }
12655
12656 return 1;
12657}
12658
12659
12660static int mbo_cmd_sta_send_frame(struct sigma_dut *dut,
12661 struct sigma_conn *conn,
12662 const char *intf,
12663 struct sigma_cmd *cmd)
12664{
12665 const char *val = get_param(cmd, "FrameName");
12666
12667 if (val && strcasecmp(val, "ANQPQuery") == 0)
12668 return mbo_send_anqp_query(dut, conn, intf, cmd);
12669
12670 return 2;
12671}
12672
12673
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053012674static enum sigma_cmd_result cmd_sta_send_frame_wpa3(struct sigma_dut *dut,
12675 struct sigma_conn *conn,
12676 const char *intf,
12677 struct sigma_cmd *cmd)
12678{
12679 const char *val = get_param(cmd, "framename");
12680
12681 if (!val)
12682 return INVALID_SEND_STATUS;
12683
12684 if (strcasecmp(val, "SAQueryReq") == 0) {
12685 val = get_param(cmd, "OCIChannel");
12686
12687 if (!val) {
12688 send_resp(dut, conn, SIGMA_ERROR,
12689 "errorCode,OCIChannel not present");
12690 return STATUS_SENT_ERROR;
12691 }
12692
12693 dut->saquery_oci_freq = channel_to_freq(dut, atoi(val));
12694 if (!dut->saquery_oci_freq) {
12695 send_resp(dut, conn, SIGMA_ERROR,
12696 "errorCode,Invalid OCIChannel number");
12697 return STATUS_SENT_ERROR;
12698 }
12699
12700 return sta_inject_frame(dut, conn, intf, SAQUERY, CORRECT_KEY,
12701 NULL, 0);
12702 }
12703
12704 if (strcasecmp(val, "reassocreq") == 0)
12705 return sta_inject_frame(dut, conn, intf, REASSOCREQ,
12706 CORRECT_KEY, NULL, 0);
12707
Veerendranath9f81dfb2020-08-10 01:21:29 -070012708 if (strcasecmp(val, "ANQPQuery") == 0) {
12709 char buf[50];
12710 const char *dest = get_param(cmd, "DestMac");
12711 const char *chan = get_param(cmd, "channel");
Veerendranath Jakkam78862fc2020-11-19 21:23:27 +053012712 const char *freq_str = get_param(cmd, "ChnlFreq");
Veerendranath9f81dfb2020-08-10 01:21:29 -070012713 int len, freq;
12714
Veerendranath Jakkam78862fc2020-11-19 21:23:27 +053012715 if (freq_str)
12716 freq = atoi(freq_str);
12717 else
12718 freq = chan ? channel_to_freq(dut, atoi(chan)) : 0;
12719
Veerendranath9f81dfb2020-08-10 01:21:29 -070012720 if (!dest || !freq)
12721 return INVALID_SEND_STATUS;
12722
12723 len = snprintf(buf, sizeof(buf), "ANQP_GET %s freq=%d 257",
12724 dest, freq);
12725 if (len < 0 || len >= sizeof(buf)) {
12726 sigma_dut_print(dut, DUT_MSG_ERROR,
12727 "Failed to allocate buf");
12728 return ERROR_SEND_STATUS;
12729 }
12730
12731 if (wpa_command(intf, buf) != 0) {
12732 send_resp(dut, conn, SIGMA_ERROR,
12733 "ErrorCode,Failed to send ANQP Query frame");
12734 return STATUS_SENT_ERROR;
12735 }
12736
12737 sigma_dut_print(dut, DUT_MSG_DEBUG,
12738 "ANQP Query sent: %s", buf);
12739
12740 return SUCCESS_SEND_STATUS;
12741 }
12742
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053012743 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported framename");
12744 return STATUS_SENT_ERROR;
12745}
12746
12747
Vinita S. Malooca85fd22021-01-15 02:54:34 +053012748static int
12749get_type4_frame_classifier(struct sigma_dut *dut, struct sigma_cmd *cmd,
12750 char *pos, int rem_len, int num_of_scs_desc,
12751 int num_of_tclas_elem)
12752{
12753 const char *val;
12754 int ipv6;
12755 int len, total_len = 0;
12756
12757 val = get_param_fmt(cmd, "TCLASElem_Version_%d_%d", num_of_scs_desc,
12758 num_of_tclas_elem);
12759 if (!val) {
12760 sigma_dut_print(dut, DUT_MSG_ERROR, "%s: ip_version empty",
12761 __func__);
12762 return -1;
12763 }
12764
12765 if (strcmp(val, "6") == 0) {
12766 ipv6 = 1;
12767 } else if (strcmp(val, "4") == 0) {
12768 ipv6 = 0;
12769 } else {
12770 sigma_dut_print(dut, DUT_MSG_ERROR, "%s: ip_version invalid",
12771 __func__);
12772 return -1;
12773 }
12774
12775 len = snprintf(pos, rem_len, " ip_version=%s", ipv6 ? "ipv6" : "ipv4");
12776 if (len < 0 || len >= rem_len)
12777 return -1;
12778
12779 pos += len;
12780 rem_len -= len;
12781 total_len += len;
12782
12783 val = get_param_fmt(cmd, "TCLASElem_SourceIPAddr_%d_%d",
12784 num_of_scs_desc, num_of_tclas_elem);
12785 if (val) {
12786 len = snprintf(pos, rem_len, " src_ip=%s", val);
12787 if (len < 0 || len >= rem_len)
12788 return -1;
12789
12790 pos += len;
12791 rem_len -= len;
12792 total_len += len;
12793 }
12794
12795 val = get_param_fmt(cmd, "TCLASElem_DestinationIPAddr_%d_%d",
12796 num_of_scs_desc, num_of_tclas_elem);
12797 if (val) {
12798 len = snprintf(pos, rem_len, " dst_ip=%s", val);
12799 if (len < 0 || len >= rem_len)
12800 return -1;
12801
12802 pos += len;
12803 rem_len -= len;
12804 total_len += len;
12805 }
12806
12807 val = get_param_fmt(cmd, "TCLASElem_SourcePort_%d_%d", num_of_scs_desc,
12808 num_of_tclas_elem);
12809 if (val) {
12810 len = snprintf(pos, rem_len, " src_port=%s", val);
12811 if (len < 0 || len >= rem_len)
12812 return -1;
12813
12814 pos += len;
12815 rem_len -= len;
12816 total_len += len;
12817 }
12818
12819 val = get_param_fmt(cmd, "TCLASElem_DestinationPort_%d_%d",
12820 num_of_scs_desc, num_of_tclas_elem);
12821 if (val) {
12822 len = snprintf(pos, rem_len, " dst_port=%s", val);
12823 if (len < 0 || len >= rem_len)
12824 return -1;
12825
12826 pos += len;
12827 rem_len -= len;
12828 total_len += len;
12829 }
12830
12831 val = get_param_fmt(cmd, "TCLASElem_DSCP_%d_%d", num_of_scs_desc,
12832 num_of_tclas_elem);
12833 if (val) {
12834 len = snprintf(pos, rem_len, " dscp=%s", val);
12835 if (len < 0 || len >= rem_len)
12836 return -1;
12837
12838 pos += len;
12839 rem_len -= len;
12840 total_len += len;
12841 }
12842
12843 val = get_param_fmt(cmd, "TCLASElem_ProtocolNxtHeader_%d_%d",
12844 num_of_scs_desc, num_of_tclas_elem);
12845 if (val) {
12846 char *prot;
12847
12848 switch (atoi(val)) {
12849 case 17:
12850 prot = "udp";
12851 break;
12852 case 6:
12853 prot = "tcp";
12854 break;
12855 case 50:
12856 prot = "esp";
12857 break;
12858 default:
12859 sigma_dut_print(dut, DUT_MSG_ERROR,
12860 "Invalid protocol %d", atoi(val));
12861 return -1;
12862 }
12863
12864 if (ipv6)
12865 len = snprintf(pos, rem_len, " next_header=%s", prot);
12866 else
12867 len = snprintf(pos, rem_len, " protocol=%s", prot);
12868 if (len < 0 || len >= rem_len)
12869 return -1;
12870
12871 pos += len;
12872 rem_len -= len;
12873 total_len += len;
12874 }
12875
12876 return total_len;
12877}
12878
12879
12880static int
12881get_type10_frame_classifier(struct sigma_dut *dut, struct sigma_cmd *cmd,
12882 char *pos, int rem_len, int num_of_scs_desc,
12883 int num_of_tclas_elem)
12884{
12885 const char *val;
12886 int len, total_len = 0;
12887
12888 val = get_param_fmt(cmd, "TCLASElem_ProtoInstance_%d_%d",
12889 num_of_scs_desc, num_of_tclas_elem);
12890 if (val) {
12891 len = snprintf(pos, rem_len, " prot_instance=%s",
12892 val);
12893 if (len < 0 || len >= rem_len)
12894 return -1;
12895
12896 pos += len;
12897 rem_len -= len;
12898 total_len += len;
12899 }
12900
12901 val = get_param_fmt(cmd, "TCLASElem_ProtoNumNextHeader_%d_%d",
12902 num_of_scs_desc, num_of_tclas_elem);
12903 if (val) {
12904 char *prot;
12905
12906 switch (atoi(val)) {
12907 case 17:
12908 prot = "udp";
12909 break;
12910 case 6:
12911 prot = "tcp";
12912 break;
12913 case 50:
12914 prot = "esp";
12915 break;
12916 default:
12917 sigma_dut_print(dut, DUT_MSG_ERROR,
12918 "Invalid protocol %d",
12919 atoi(val));
12920 return -1;
12921 }
12922
12923 len = snprintf(pos, rem_len, " prot_number=%s", prot);
12924 if (len < 0 || len >= rem_len)
12925 return -1;
12926
12927 pos += len;
12928 rem_len -= len;
12929 total_len += len;
12930 }
12931
12932 val = get_param_fmt(cmd, "TCLASElem_FilterValue_%d_%d",
12933 num_of_scs_desc, num_of_tclas_elem);
12934 if (val) {
12935 len = snprintf(pos, rem_len, " filter_value=%s", (val + 2));
12936 if (len < 0 || len >= rem_len)
12937 return -1;
12938
12939 pos += len;
12940 rem_len -= len;
12941 total_len += len;
12942 }
12943
12944 val = get_param_fmt(cmd, "TCLASElem_FilterMask_%d_%d", num_of_scs_desc,
12945 num_of_tclas_elem);
12946 if (val && strlen(val) >= 2) {
12947 len = snprintf(pos, rem_len, " filter_mask=%s", val + 2);
12948 if (len < 0 || len >= rem_len)
12949 return -1;
12950
12951 pos += len;
12952 rem_len -= len;
12953 total_len += len;
12954 }
12955
12956 return total_len;
12957}
12958
12959
12960static enum sigma_cmd_result
12961cmd_sta_send_frame_scs(struct sigma_dut *dut, struct sigma_conn *conn,
12962 const char *intf, struct sigma_cmd *cmd)
12963{
12964 char buf[4096], *pos;
12965 const char *val, *scs_id, *classifier_type;
12966 int len, rem_len, total_bytes;
12967 int num_of_scs_desc = 0, num_of_tclas_elem = 0;
12968
12969 scs_id = get_param(cmd, "SCSDescrElem_SCSID_1");
12970 if (!scs_id) {
12971 sigma_dut_print(dut, DUT_MSG_ERROR, "SCS ID empty");
12972 return INVALID_SEND_STATUS;
12973 }
12974
12975 rem_len = sizeof(buf);
12976 pos = buf;
12977
12978 len = snprintf(buf, sizeof(buf), "SCS");
12979 if (len < 0 || len > rem_len)
12980 goto fail;
12981
12982 pos += len;
12983 rem_len -= len;
12984
12985 while (scs_id) {
12986 num_of_scs_desc++;
12987
12988 val = get_param_fmt(cmd, "SCSDescrElem_RequestType_%d",
12989 num_of_scs_desc);
12990 if (!val)
12991 return INVALID_SEND_STATUS;
12992
12993 if (strcasecmp(val, "Add") == 0) {
12994 len = snprintf(pos, rem_len, " scs_id=%s add",
12995 scs_id);
12996 } else if (strcasecmp(val, "Change") == 0) {
12997 len = snprintf(pos, rem_len, " scs_id=%s change",
12998 scs_id);
12999 } else if (strcasecmp(val, "Remove") == 0) {
13000 len = snprintf(pos, rem_len, " scs_id=%s remove",
13001 scs_id);
13002 if (len < 0 || len >= rem_len)
13003 goto fail;
13004
13005 pos += len;
13006 rem_len -= len;
13007 goto scs_desc_end;
13008 } else {
13009 sigma_dut_print(dut, DUT_MSG_ERROR,
13010 "%s: request type - %s is invalid",
13011 __func__, val);
13012 return INVALID_SEND_STATUS;
13013 }
13014
13015 if (len < 0 || len >= rem_len)
13016 goto fail;
13017
13018 pos += len;
13019 rem_len -= len;
13020
13021 val = get_param_fmt(cmd, "IntraAccessCatElem_UP_%d",
13022 num_of_scs_desc);
13023 if (!val) {
13024 sigma_dut_print(dut, DUT_MSG_ERROR,
13025 "IntraAccess Priority empty");
13026 return INVALID_SEND_STATUS;
13027 }
13028
13029 len = snprintf(pos, rem_len, " scs_up=%s", val);
13030 if (len < 0 || len >= rem_len)
13031 goto fail;
13032
13033 pos += len;
13034 rem_len -= len;
13035
13036 classifier_type = get_param_fmt(cmd,
13037 "TCLASElem_ClassifierType_%d_1",
13038 num_of_scs_desc);
13039 if (!classifier_type) {
13040 sigma_dut_print(dut, DUT_MSG_ERROR,
13041 "classifier type missing");
13042 return INVALID_SEND_STATUS;
13043 }
13044
13045 while (classifier_type) {
13046 num_of_tclas_elem++;
13047
13048 len = snprintf(pos, rem_len, " classifier_type=%s",
13049 classifier_type);
13050 if (len < 0 || len >= rem_len)
13051 goto fail;
13052
13053 pos += len;
13054 rem_len -= len;
13055
13056 if (strcmp(classifier_type, "10") == 0) {
13057 total_bytes = get_type10_frame_classifier(
13058 dut, cmd, pos, rem_len,
13059 num_of_scs_desc,
13060 num_of_tclas_elem);
13061 } else if (strcmp(classifier_type, "4") == 0) {
13062 total_bytes = get_type4_frame_classifier(
13063 dut, cmd, pos, rem_len,
13064 num_of_scs_desc,
13065 num_of_tclas_elem);
13066 } else {
13067 sigma_dut_print(dut, DUT_MSG_ERROR,
13068 "classifier_type invalid");
13069 goto fail;
13070 }
13071
13072 if (total_bytes < 0)
13073 goto fail;
13074
13075 pos += total_bytes;
13076 rem_len -= total_bytes;
13077
13078 classifier_type = get_param_fmt(
13079 cmd, "TCLASElem_ClassifierType_%d_%d",
13080 num_of_scs_desc, num_of_tclas_elem + 1);
13081 }
13082
13083 if (num_of_tclas_elem > 1) {
13084 val = get_param_fmt(cmd,
13085 "TCLASProcessingElem_Processing_%d",
13086 num_of_scs_desc);
13087 if (!val) {
13088 sigma_dut_print(dut, DUT_MSG_ERROR,
13089 "Tclas_processing element %d empty",
13090 num_of_scs_desc);
13091 goto fail;
13092 }
13093
13094 len = snprintf(pos, rem_len,
13095 " tclas_processing=%s", val);
13096 if (len < 0 || len >= rem_len)
13097 goto fail;
13098
13099 pos += len;
13100 rem_len -= len;
13101 }
13102scs_desc_end:
13103 num_of_tclas_elem = 0;
13104 scs_id = get_param_fmt(cmd, "SCSDescrElem_SCSID_%d",
13105 num_of_scs_desc + 1);
13106 }
13107
13108 if (wpa_command(intf, buf) != 0) {
13109 send_resp(dut, conn, SIGMA_ERROR,
13110 "ErrorCode,Failed to send SCS frame request");
13111 return STATUS_SENT_ERROR;
13112 }
13113
13114 sigma_dut_print(dut, DUT_MSG_DEBUG,
13115 "SCS frame request sent: %s", buf);
13116
13117 return SUCCESS_SEND_STATUS;
13118fail:
13119 sigma_dut_print(dut, DUT_MSG_ERROR,
13120 "Failed to create SCS frame request");
13121 return ERROR_SEND_STATUS;
13122}
13123
13124
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053013125static enum sigma_cmd_result
13126cmd_sta_send_frame_mscs(struct sigma_dut *dut, struct sigma_conn *conn,
13127 const char *intf, struct sigma_cmd *cmd)
13128{
13129 char buf[128], *pos;
13130 const char *val, *classifier_type = "04", *type;
13131 int len, rem_len;
13132 u8 up_bitmap;
13133
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053013134 type = get_param(cmd, "Request_Type");
Vinita S. Malooca85fd22021-01-15 02:54:34 +053013135 if (!type) {
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053013136 sigma_dut_print(dut, DUT_MSG_ERROR,
Vinita S. Malooca85fd22021-01-15 02:54:34 +053013137 "%s: type not valid", __func__);
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053013138 return INVALID_SEND_STATUS;
13139 }
13140
13141 rem_len = sizeof(buf);
13142 pos = buf;
13143 if (strcasecmp(type, "add") == 0) {
13144 len = snprintf(pos, rem_len, "MSCS add");
13145 } else if (strcasecmp(type, "update") == 0) {
13146 len = snprintf(pos, rem_len, "MSCS change");
13147 } else if (strcasecmp(type, "remove") == 0) {
13148 if (wpa_command(intf, "MSCS remove") != 0) {
13149 send_resp(dut, conn, SIGMA_ERROR,
13150 "ErrorCode,Failed to send MSCS frame req");
13151 return STATUS_SENT_ERROR;
13152 }
13153 return SUCCESS_SEND_STATUS;
13154 } else {
13155 sigma_dut_print(dut, DUT_MSG_ERROR,
13156 "%s: request type invalid", __func__);
13157 return INVALID_SEND_STATUS;
13158 }
13159
13160 if (len < 0 || len >= rem_len)
13161 goto fail;
13162
13163 pos += len;
13164 rem_len -= len;
13165
13166 val = get_param(cmd, "User_Priority_Bitmap");
13167 if (!val) {
13168 sigma_dut_print(dut, DUT_MSG_ERROR,
13169 "%s: user priority bitmap empty", __func__);
13170 return INVALID_SEND_STATUS;
13171 }
13172
13173 switch (atoi(val)) {
13174 case 0:
13175 up_bitmap = 0x00;
13176 break;
13177 case 1:
13178 up_bitmap = 0xF0;
13179 break;
13180 case 2:
13181 up_bitmap = 0xF6;
13182 break;
13183 default:
13184 sigma_dut_print(dut, DUT_MSG_ERROR,
13185 "%s: Unknown User_Priority_Bitmap value %d",
13186 __func__, atoi(val));
13187 return INVALID_SEND_STATUS;
13188 }
13189
13190 len = snprintf(pos, rem_len, " up_bitmap=%02x", up_bitmap);
13191 if (len < 0 || len >= rem_len)
13192 goto fail;
13193
13194 pos += len;
13195 rem_len -= len;
13196
13197 val = get_param(cmd, "User_Priority_Limit");
13198 if (!val) {
13199 sigma_dut_print(dut, DUT_MSG_ERROR,
13200 "%s: invalid user priority limit", __func__);
13201 return INVALID_SEND_STATUS;
13202 }
13203
13204 len = snprintf(pos, rem_len, " up_limit=%s", val);
13205 if (len < 0 || len >= rem_len)
13206 goto fail;
13207
13208 pos += len;
13209 rem_len -= len;
13210
13211 val = get_param(cmd, "Stream_Timeout");
13212 if (!val)
13213 val = get_param(cmd, "Stream_Timtout");
13214 if (!val) {
13215 sigma_dut_print(dut, DUT_MSG_ERROR,
13216 "%s: invalid stream timeout", __func__);
13217 return INVALID_SEND_STATUS;
13218 }
13219
13220 len = snprintf(pos, rem_len, " stream_timeout=%s", val);
13221 if (len < 0 || len >= rem_len)
13222 goto fail;
13223
13224 pos += len;
13225 rem_len -= len;
13226
13227 val = get_param(cmd, "TCLAS_Mask");
13228 if (!val) {
13229 sigma_dut_print(dut, DUT_MSG_ERROR,
13230 "%s: invalid tclas mask", __func__);
13231 return INVALID_SEND_STATUS;
13232 }
13233
13234 len = snprintf(pos, rem_len, " frame_classifier=%s%lx%032x",
13235 classifier_type, strtol(val, NULL, 2), 0);
13236 if (len < 0 || len >= rem_len)
13237 goto fail;
13238
13239 if (wpa_command(intf, buf) != 0) {
13240 send_resp(dut, conn, SIGMA_ERROR,
13241 "ErrorCode,Failed to send MSCS frame req");
13242 return STATUS_SENT_ERROR;
13243 }
13244
13245 sigma_dut_print(dut, DUT_MSG_DEBUG,
13246 "MSCS frame request sent: %s", buf);
13247
13248 return SUCCESS_SEND_STATUS;
13249fail:
13250 sigma_dut_print(dut, DUT_MSG_ERROR,
13251 "Failed to create MSCS frame req");
13252 return ERROR_SEND_STATUS;
13253}
13254
13255
Vinita S. Malooca85fd22021-01-15 02:54:34 +053013256static enum sigma_cmd_result
Veerendranath Jakkam329a3cd2021-09-11 18:10:13 +053013257cmd_sta_send_frame_dscp_query(struct sigma_dut *dut, struct sigma_conn *conn,
13258 const char *intf, struct sigma_cmd *cmd)
13259{
13260 char buf[150], *pos;
13261 const char *val;
13262 int len, rem_len;
13263
13264 rem_len = sizeof(buf);
13265 pos = buf;
13266
13267 len = snprintf(pos, rem_len, "DSCP_QUERY");
13268 if (len < 0 || len >= rem_len)
13269 goto fail;
13270
13271 pos += len;
13272 rem_len -= len;
13273
13274 val = get_param(cmd, "Wildcard");
13275 if (val && strcasecmp(val, "Yes") == 0) {
13276 len = snprintf(pos, rem_len, " wildcard");
13277 if (len < 0 || len >= rem_len)
13278 goto fail;
13279 } else if (strlen(dut->qm_domain_name)) {
13280 len = snprintf(pos, rem_len, " domain_name=%s",
13281 dut->qm_domain_name);
13282 if (len < 0 || len >= rem_len)
13283 goto fail;
13284 } else {
13285 sigma_dut_print(dut, DUT_MSG_ERROR,
13286 "Invalid DSCP Query configuration");
13287 return INVALID_SEND_STATUS;
13288 }
13289
13290 if (wpa_command(intf, buf) != 0) {
13291 send_resp(dut, conn, SIGMA_ERROR,
13292 "ErrorCode,Failed to send DSCP policy query frame");
13293 return STATUS_SENT_ERROR;
13294 }
13295
13296 sigma_dut_print(dut, DUT_MSG_DEBUG,
13297 "DSCP policy query frame sent: %s", buf);
13298 return SUCCESS_SEND_STATUS;
13299fail:
13300 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to send DSCP query");
13301 return ERROR_SEND_STATUS;
13302}
13303
13304
13305static enum sigma_cmd_result
Veerendranath Jakkam1bf1bd62021-09-12 16:35:55 +053013306cmd_sta_send_frame_dscp_response(struct sigma_dut *dut, struct sigma_conn *conn,
13307 const char *intf, struct sigma_cmd *cmd)
13308{
13309 char buf[256], *pos, *item, *list, *saveptr;
13310 const char *val;
13311 int len, rem_len;
13312
13313 pos = buf;
13314 rem_len = sizeof(buf);
13315
13316 len = snprintf(pos, rem_len, "DSCP_RESP");
13317 if (snprintf_error(rem_len, len)) {
13318 sigma_dut_print(dut, DUT_MSG_ERROR,
13319 "Failed to create DSCP Policy Response command");
13320 return ERROR_SEND_STATUS;
13321 }
13322
13323 pos += len;
13324 rem_len -= len;
13325
13326 val = get_param(cmd, "PolicyID_List");
13327 if (!val) {
13328 sigma_dut_print(dut, DUT_MSG_ERROR,
13329 "DSCP policy ID list missing");
13330 return INVALID_SEND_STATUS;
13331 }
13332
13333 list = strdup(val);
13334 if (!list)
13335 return ERROR_SEND_STATUS;
13336
13337 item = strtok_r(list, "_", &saveptr);
13338 while (item) {
13339 unsigned int i;
13340 int policy_id = atoi(item);
13341
13342 for (i = 0; i < dut->num_dscp_status; i++)
13343 if (dut->dscp_status[i].id == policy_id)
13344 break;
13345
13346 if (i == dut->num_dscp_status) {
13347 free(list);
13348 send_resp(dut, conn, SIGMA_ERROR,
13349 "ErrorCode,DSCP policy id not found in status list");
13350 return STATUS_SENT_ERROR;
13351 }
13352
13353 len = snprintf(pos, rem_len, " policy_id=%d status=%d",
13354 policy_id, dut->dscp_status[i].status);
13355 if (snprintf_error(rem_len, len)) {
13356 free(list);
13357 sigma_dut_print(dut, DUT_MSG_ERROR,
13358 "Failed to write DSCP policy list");
13359 return ERROR_SEND_STATUS;
13360 }
13361
13362 pos += len;
13363 rem_len -= len;
13364
13365 if (dut->dscp_status[i].status)
13366 remove_dscp_policy(dut, policy_id);
13367
13368 item = strtok_r(NULL, "_", &saveptr);
13369 }
13370
13371 free(list);
13372
13373 if (wpa_command(intf, buf) != 0) {
13374 send_resp(dut, conn, SIGMA_ERROR,
13375 "ErrorCode,Failed to send DSCP Policy Response frame");
13376 return STATUS_SENT_ERROR;
13377 }
13378
13379 sigma_dut_print(dut, DUT_MSG_DEBUG,
13380 "DSCP Policy Response frame sent: %s", buf);
13381 return SUCCESS_SEND_STATUS;
13382}
13383
13384
13385static enum sigma_cmd_result
Vinita S. Malooca85fd22021-01-15 02:54:34 +053013386cmd_sta_send_frame_qm(struct sigma_dut *dut, struct sigma_conn *conn,
13387 const char *intf, struct sigma_cmd *cmd)
13388{
13389 const char *val;
13390
13391 val = get_param(cmd, "FrameName");
13392 if (val) {
13393 if (strcasecmp(val, "MSCSReq") == 0)
13394 return cmd_sta_send_frame_mscs(dut, conn, intf, cmd);
13395 if (strcasecmp(val, "SCSReq") == 0)
13396 return cmd_sta_send_frame_scs(dut, conn, intf, cmd);
Veerendranath Jakkam329a3cd2021-09-11 18:10:13 +053013397 if (strcasecmp(val, "DSCPPolicyQuery") == 0)
13398 return cmd_sta_send_frame_dscp_query(dut, conn, intf,
13399 cmd);
Veerendranath Jakkam1bf1bd62021-09-12 16:35:55 +053013400 if (strcasecmp(val, "DSCPPolicyResponse") == 0)
13401 return cmd_sta_send_frame_dscp_response(dut, conn, intf,
13402 cmd);
Vinita S. Malooca85fd22021-01-15 02:54:34 +053013403
13404 sigma_dut_print(dut, DUT_MSG_ERROR,
13405 "%s: frame name - %s is invalid",
13406 __func__, val);
13407 }
13408
13409 return INVALID_SEND_STATUS;
13410}
13411
13412
Jouni Malinenf7222712019-06-13 01:50:21 +030013413enum sigma_cmd_result cmd_sta_send_frame(struct sigma_dut *dut,
13414 struct sigma_conn *conn,
13415 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013416{
13417 const char *intf = get_param(cmd, "Interface");
13418 const char *val;
13419 enum send_frame_type frame;
13420 enum send_frame_protection protected;
13421 char buf[100];
13422 unsigned char addr[ETH_ALEN];
13423 int res;
13424
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030013425 if (!intf)
13426 return -1;
13427
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013428 val = get_param(cmd, "program");
13429 if (val == NULL)
13430 val = get_param(cmd, "frame");
13431 if (val && strcasecmp(val, "TDLS") == 0)
13432 return cmd_sta_send_frame_tdls(dut, conn, cmd);
13433 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030013434 strcasecmp(val, "HS2-R2") == 0 ||
13435 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013436 return cmd_sta_send_frame_hs2(dut, conn, cmd);
13437 if (val && strcasecmp(val, "VHT") == 0)
13438 return cmd_sta_send_frame_vht(dut, conn, cmd);
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070013439 if (val && strcasecmp(val, "HE") == 0)
13440 return cmd_sta_send_frame_he(dut, conn, cmd);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -070013441 if (val && strcasecmp(val, "LOC") == 0)
13442 return loc_cmd_sta_send_frame(dut, conn, cmd);
Lior David0fe101e2017-03-09 16:09:50 +020013443 if (val && strcasecmp(val, "60GHz") == 0)
13444 return cmd_sta_send_frame_60g(dut, conn, cmd);
Ashwini Patildb59b3c2017-04-13 15:19:23 +053013445 if (val && strcasecmp(val, "MBO") == 0) {
13446 res = mbo_cmd_sta_send_frame(dut, conn, intf, cmd);
13447 if (res != 2)
13448 return res;
13449 }
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053013450 if (val && strcasecmp(val, "WPA3") == 0)
13451 return cmd_sta_send_frame_wpa3(dut, conn, intf, cmd);
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053013452 if (val && strcasecmp(val, "QM") == 0)
Vinita S. Malooca85fd22021-01-15 02:54:34 +053013453 return cmd_sta_send_frame_qm(dut, conn, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013454
13455 val = get_param(cmd, "TD_DISC");
13456 if (val) {
13457 if (hwaddr_aton(val, addr) < 0)
13458 return -1;
13459 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", val);
13460 if (wpa_command(intf, buf) < 0) {
13461 send_resp(dut, conn, SIGMA_ERROR,
13462 "ErrorCode,Failed to send TDLS discovery");
13463 return 0;
13464 }
13465 return 1;
13466 }
13467
13468 val = get_param(cmd, "TD_Setup");
13469 if (val) {
13470 if (hwaddr_aton(val, addr) < 0)
13471 return -1;
13472 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", val);
13473 if (wpa_command(intf, buf) < 0) {
13474 send_resp(dut, conn, SIGMA_ERROR,
13475 "ErrorCode,Failed to start TDLS setup");
13476 return 0;
13477 }
13478 return 1;
13479 }
13480
13481 val = get_param(cmd, "TD_TearDown");
13482 if (val) {
13483 if (hwaddr_aton(val, addr) < 0)
13484 return -1;
13485 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", val);
13486 if (wpa_command(intf, buf) < 0) {
13487 send_resp(dut, conn, SIGMA_ERROR,
13488 "ErrorCode,Failed to tear down TDLS link");
13489 return 0;
13490 }
13491 return 1;
13492 }
13493
13494 val = get_param(cmd, "TD_ChannelSwitch");
13495 if (val) {
13496 /* TODO */
13497 send_resp(dut, conn, SIGMA_ERROR,
13498 "ErrorCode,TD_ChannelSwitch not yet supported");
13499 return 0;
13500 }
13501
13502 val = get_param(cmd, "TD_NF");
13503 if (val) {
13504 /* TODO */
13505 send_resp(dut, conn, SIGMA_ERROR,
13506 "ErrorCode,TD_NF not yet supported");
13507 return 0;
13508 }
13509
13510 val = get_param(cmd, "PMFFrameType");
13511 if (val == NULL)
13512 val = get_param(cmd, "FrameName");
13513 if (val == NULL)
13514 val = get_param(cmd, "Type");
13515 if (val == NULL)
13516 return -1;
13517 if (strcasecmp(val, "disassoc") == 0)
13518 frame = DISASSOC;
13519 else if (strcasecmp(val, "deauth") == 0)
13520 frame = DEAUTH;
13521 else if (strcasecmp(val, "saquery") == 0)
13522 frame = SAQUERY;
13523 else if (strcasecmp(val, "auth") == 0)
13524 frame = AUTH;
13525 else if (strcasecmp(val, "assocreq") == 0)
13526 frame = ASSOCREQ;
13527 else if (strcasecmp(val, "reassocreq") == 0)
13528 frame = REASSOCREQ;
13529 else if (strcasecmp(val, "neigreq") == 0) {
13530 sigma_dut_print(dut, DUT_MSG_INFO, "Got neighbor request");
13531
13532 val = get_param(cmd, "ssid");
13533 if (val == NULL)
13534 return -1;
13535
13536 res = send_neighbor_request(dut, intf, val);
13537 if (res) {
13538 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
13539 "Failed to send neighbor report request");
13540 return 0;
13541 }
13542
13543 return 1;
Ashwini Patil5acd7382017-04-13 15:55:04 +053013544 } else if (strcasecmp(val, "transmgmtquery") == 0 ||
13545 strcasecmp(val, "BTMQuery") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013546 sigma_dut_print(dut, DUT_MSG_DEBUG,
13547 "Got Transition Management Query");
13548
Ashwini Patil5acd7382017-04-13 15:55:04 +053013549 res = send_trans_mgmt_query(dut, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013550 if (res) {
13551 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
13552 "Failed to send Transition Management Query");
13553 return 0;
13554 }
13555
13556 return 1;
13557 } else {
13558 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
13559 "PMFFrameType");
13560 return 0;
13561 }
13562
13563 val = get_param(cmd, "PMFProtected");
13564 if (val == NULL)
13565 val = get_param(cmd, "Protected");
13566 if (val == NULL)
13567 return -1;
13568 if (strcasecmp(val, "Correct-key") == 0 ||
13569 strcasecmp(val, "CorrectKey") == 0)
13570 protected = CORRECT_KEY;
13571 else if (strcasecmp(val, "IncorrectKey") == 0)
13572 protected = INCORRECT_KEY;
13573 else if (strcasecmp(val, "Unprotected") == 0)
13574 protected = UNPROTECTED;
13575 else {
13576 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
13577 "PMFProtected");
13578 return 0;
13579 }
13580
13581 if (protected != UNPROTECTED &&
13582 (frame == AUTH || frame == ASSOCREQ || frame == REASSOCREQ)) {
13583 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Impossible "
13584 "PMFProtected for auth/assocreq/reassocreq");
13585 return 0;
13586 }
13587
13588 if (if_nametoindex("sigmadut") == 0) {
13589 snprintf(buf, sizeof(buf),
13590 "iw dev %s interface add sigmadut type monitor",
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013591 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013592 if (system(buf) != 0 ||
13593 if_nametoindex("sigmadut") == 0) {
13594 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
13595 "monitor interface with '%s'", buf);
13596 return -2;
13597 }
13598 }
13599
13600 if (system("ifconfig sigmadut up") != 0) {
13601 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
13602 "monitor interface up");
13603 return -2;
13604 }
13605
Veerendranath Jakkam49774122020-07-05 09:52:18 +053013606 return sta_inject_frame(dut, conn, intf, frame, protected, NULL, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013607}
13608
13609
13610static int cmd_sta_set_parameter_hs2(struct sigma_dut *dut,
13611 struct sigma_conn *conn,
13612 struct sigma_cmd *cmd,
13613 const char *ifname)
13614{
13615 char buf[200];
13616 const char *val;
13617
13618 val = get_param(cmd, "ClearARP");
13619 if (val && atoi(val) == 1) {
13620 snprintf(buf, sizeof(buf), "ip neigh flush dev %s", ifname);
13621 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
13622 if (system(buf) != 0) {
13623 send_resp(dut, conn, SIGMA_ERROR,
13624 "errorCode,Failed to clear ARP cache");
13625 return 0;
13626 }
13627 }
13628
13629 return 1;
13630}
13631
13632
13633int cmd_sta_set_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
13634 struct sigma_cmd *cmd)
13635{
13636 const char *intf = get_param(cmd, "Interface");
13637 const char *val;
13638
13639 if (intf == NULL)
13640 return -1;
13641
13642 val = get_param(cmd, "program");
13643 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030013644 strcasecmp(val, "HS2-R2") == 0 ||
13645 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013646 return cmd_sta_set_parameter_hs2(dut, conn, cmd, intf);
13647
13648 return -1;
13649}
13650
13651
Jouni Malinenf7222712019-06-13 01:50:21 +030013652static enum sigma_cmd_result cmd_sta_set_macaddr(struct sigma_dut *dut,
13653 struct sigma_conn *conn,
13654 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013655{
13656 const char *intf = get_param(cmd, "Interface");
13657 const char *mac = get_param(cmd, "MAC");
13658
13659 if (intf == NULL || mac == NULL)
13660 return -1;
13661
13662 sigma_dut_print(dut, DUT_MSG_INFO, "Change local MAC address for "
13663 "interface %s to %s", intf, mac);
13664
13665 if (dut->set_macaddr) {
13666 char buf[128];
13667 int res;
13668 if (strcasecmp(mac, "default") == 0) {
13669 res = snprintf(buf, sizeof(buf), "%s",
13670 dut->set_macaddr);
13671 dut->tmp_mac_addr = 0;
13672 } else {
13673 res = snprintf(buf, sizeof(buf), "%s %s",
13674 dut->set_macaddr, mac);
13675 dut->tmp_mac_addr = 1;
13676 }
13677 if (res < 0 || res >= (int) sizeof(buf))
13678 return -1;
13679 if (system(buf) != 0) {
13680 send_resp(dut, conn, SIGMA_ERROR,
13681 "errorCode,Failed to set MAC "
13682 "address");
13683 return 0;
13684 }
13685 return 1;
13686 }
13687
13688 if (strcasecmp(mac, "default") == 0)
13689 return 1;
13690
13691 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
13692 "command");
13693 return 0;
13694}
13695
13696
13697static int iwpriv_tdlsoffchnmode(struct sigma_dut *dut,
13698 struct sigma_conn *conn, const char *intf,
13699 int val)
13700{
13701 char buf[200];
13702 int res;
13703
13704 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchnmode %d",
13705 intf, val);
13706 if (res < 0 || res >= (int) sizeof(buf))
13707 return -1;
13708 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
13709 if (system(buf) != 0) {
13710 send_resp(dut, conn, SIGMA_ERROR,
13711 "errorCode,Failed to configure offchannel mode");
13712 return 0;
13713 }
13714
13715 return 1;
13716}
13717
13718
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013719static int off_chan_val(enum sec_ch_offset off)
13720{
13721 switch (off) {
13722 case SEC_CH_NO:
13723 return 0;
13724 case SEC_CH_40ABOVE:
13725 return 40;
13726 case SEC_CH_40BELOW:
13727 return -40;
13728 }
13729
13730 return 0;
13731}
13732
13733
13734static int iwpriv_set_offchan(struct sigma_dut *dut, struct sigma_conn *conn,
13735 const char *intf, int off_ch_num,
13736 enum sec_ch_offset sec)
13737{
13738 char buf[200];
13739 int res;
13740
13741 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchan %d",
13742 intf, off_ch_num);
13743 if (res < 0 || res >= (int) sizeof(buf))
13744 return -1;
13745 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
13746 if (system(buf) != 0) {
13747 send_resp(dut, conn, SIGMA_ERROR,
13748 "errorCode,Failed to set offchan");
13749 return 0;
13750 }
13751
13752 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsecchnoffst %d",
13753 intf, off_chan_val(sec));
13754 if (res < 0 || res >= (int) sizeof(buf))
13755 return -1;
13756 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
13757 if (system(buf) != 0) {
13758 send_resp(dut, conn, SIGMA_ERROR,
13759 "errorCode,Failed to set sec chan offset");
13760 return 0;
13761 }
13762
13763 return 1;
13764}
13765
13766
13767static int tdls_set_offchannel_offset(struct sigma_dut *dut,
13768 struct sigma_conn *conn,
13769 const char *intf, int off_ch_num,
13770 enum sec_ch_offset sec)
13771{
13772 char buf[200];
13773 int res;
13774
13775 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNEL %d",
13776 off_ch_num);
13777 if (res < 0 || res >= (int) sizeof(buf))
13778 return -1;
13779 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
13780
13781 if (wpa_command(intf, buf) < 0) {
13782 send_resp(dut, conn, SIGMA_ERROR,
13783 "ErrorCode,Failed to set offchan");
13784 return 0;
13785 }
13786 res = snprintf(buf, sizeof(buf), "DRIVER TDLSSECONDARYCHANNELOFFSET %d",
13787 off_chan_val(sec));
13788 if (res < 0 || res >= (int) sizeof(buf))
13789 return -1;
13790
13791 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
13792
13793 if (wpa_command(intf, buf) < 0) {
13794 send_resp(dut, conn, SIGMA_ERROR,
13795 "ErrorCode,Failed to set sec chan offset");
13796 return 0;
13797 }
13798
13799 return 1;
13800}
13801
13802
13803static int tdls_set_offchannel_mode(struct sigma_dut *dut,
13804 struct sigma_conn *conn,
13805 const char *intf, int val)
13806{
13807 char buf[200];
13808 int res;
13809
13810 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNELMODE %d",
13811 val);
13812 if (res < 0 || res >= (int) sizeof(buf))
13813 return -1;
13814 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
13815
13816 if (wpa_command(intf, buf) < 0) {
13817 send_resp(dut, conn, SIGMA_ERROR,
13818 "ErrorCode,Failed to configure offchannel mode");
13819 return 0;
13820 }
13821
13822 return 1;
13823}
13824
13825
13826static int cmd_sta_set_rfeature_tdls(const char *intf, struct sigma_dut *dut,
13827 struct sigma_conn *conn,
13828 struct sigma_cmd *cmd)
13829{
13830 const char *val;
13831 enum {
13832 CHSM_NOT_SET,
13833 CHSM_ENABLE,
13834 CHSM_DISABLE,
13835 CHSM_REJREQ,
13836 CHSM_UNSOLRESP
13837 } chsm = CHSM_NOT_SET;
13838 int off_ch_num = -1;
13839 enum sec_ch_offset sec_ch = SEC_CH_NO;
13840 int res;
13841
13842 val = get_param(cmd, "Uapsd");
13843 if (val) {
13844 char buf[100];
13845 if (strcasecmp(val, "Enable") == 0)
13846 snprintf(buf, sizeof(buf), "SET ps 99");
13847 else if (strcasecmp(val, "Disable") == 0)
13848 snprintf(buf, sizeof(buf), "SET ps 98");
13849 else {
13850 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
13851 "Unsupported uapsd parameter value");
13852 return 0;
13853 }
13854 if (wpa_command(intf, buf)) {
13855 send_resp(dut, conn, SIGMA_ERROR,
13856 "ErrorCode,Failed to change U-APSD "
13857 "powersave mode");
13858 return 0;
13859 }
13860 }
13861
13862 val = get_param(cmd, "TPKTIMER");
13863 if (val && strcasecmp(val, "DISABLE") == 0) {
13864 if (wpa_command(intf, "SET tdls_testing 0x100")) {
13865 send_resp(dut, conn, SIGMA_ERROR,
13866 "ErrorCode,Failed to enable no TPK "
13867 "expiration test mode");
13868 return 0;
13869 }
13870 dut->no_tpk_expiration = 1;
13871 }
13872
13873 val = get_param(cmd, "ChSwitchMode");
13874 if (val) {
13875 if (strcasecmp(val, "Enable") == 0 ||
13876 strcasecmp(val, "Initiate") == 0)
13877 chsm = CHSM_ENABLE;
13878 else if (strcasecmp(val, "Disable") == 0 ||
13879 strcasecmp(val, "passive") == 0)
13880 chsm = CHSM_DISABLE;
13881 else if (strcasecmp(val, "RejReq") == 0)
13882 chsm = CHSM_REJREQ;
13883 else if (strcasecmp(val, "UnSolResp") == 0)
13884 chsm = CHSM_UNSOLRESP;
13885 else {
13886 send_resp(dut, conn, SIGMA_ERROR,
13887 "ErrorCode,Unknown ChSwitchMode value");
13888 return 0;
13889 }
13890 }
13891
13892 val = get_param(cmd, "OffChNum");
13893 if (val) {
13894 off_ch_num = atoi(val);
13895 if (off_ch_num == 0) {
13896 send_resp(dut, conn, SIGMA_ERROR,
13897 "ErrorCode,Invalid OffChNum");
13898 return 0;
13899 }
13900 }
13901
13902 val = get_param(cmd, "SecChOffset");
13903 if (val) {
13904 if (strcmp(val, "20") == 0)
13905 sec_ch = SEC_CH_NO;
13906 else if (strcasecmp(val, "40above") == 0)
13907 sec_ch = SEC_CH_40ABOVE;
13908 else if (strcasecmp(val, "40below") == 0)
13909 sec_ch = SEC_CH_40BELOW;
13910 else {
13911 send_resp(dut, conn, SIGMA_ERROR,
13912 "ErrorCode,Unknown SecChOffset value");
13913 return 0;
13914 }
13915 }
13916
13917 if (chsm == CHSM_NOT_SET) {
13918 /* no offchannel changes requested */
13919 return 1;
13920 }
13921
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013922 if (strcmp(intf, get_main_ifname(dut)) != 0 &&
13923 strcmp(intf, get_station_ifname(dut)) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013924 send_resp(dut, conn, SIGMA_ERROR,
13925 "ErrorCode,Unknown interface");
13926 return 0;
13927 }
13928
13929 switch (chsm) {
13930 case CHSM_NOT_SET:
Jouni Malinen280f5ba2016-08-29 21:33:10 +030013931 res = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013932 break;
13933 case CHSM_ENABLE:
13934 if (off_ch_num < 0) {
13935 send_resp(dut, conn, SIGMA_ERROR,
13936 "ErrorCode,Missing OffChNum argument");
13937 return 0;
13938 }
13939 if (wifi_chip_type == DRIVER_WCN) {
13940 res = tdls_set_offchannel_offset(dut, conn, intf,
13941 off_ch_num, sec_ch);
13942 } else {
13943 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
13944 sec_ch);
13945 }
13946 if (res != 1)
13947 return res;
13948 if (wifi_chip_type == DRIVER_WCN)
13949 res = tdls_set_offchannel_mode(dut, conn, intf, 1);
13950 else
13951 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 1);
13952 break;
13953 case CHSM_DISABLE:
13954 if (wifi_chip_type == DRIVER_WCN)
13955 res = tdls_set_offchannel_mode(dut, conn, intf, 2);
13956 else
13957 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 2);
13958 break;
13959 case CHSM_REJREQ:
13960 if (wifi_chip_type == DRIVER_WCN)
13961 res = tdls_set_offchannel_mode(dut, conn, intf, 3);
13962 else
13963 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 3);
13964 break;
13965 case CHSM_UNSOLRESP:
13966 if (off_ch_num < 0) {
13967 send_resp(dut, conn, SIGMA_ERROR,
13968 "ErrorCode,Missing OffChNum argument");
13969 return 0;
13970 }
13971 if (wifi_chip_type == DRIVER_WCN) {
13972 res = tdls_set_offchannel_offset(dut, conn, intf,
13973 off_ch_num, sec_ch);
13974 } else {
13975 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
13976 sec_ch);
13977 }
13978 if (res != 1)
13979 return res;
13980 if (wifi_chip_type == DRIVER_WCN)
13981 res = tdls_set_offchannel_mode(dut, conn, intf, 4);
13982 else
13983 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 4);
13984 break;
13985 }
13986
13987 return res;
13988}
13989
13990
13991static int ath_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
13992 struct sigma_conn *conn,
13993 struct sigma_cmd *cmd)
13994{
13995 const char *val;
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053013996 char *token = NULL, *result;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013997
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -070013998 novap_reset(dut, intf, 1);
priyadharshini gowthamane5e25172015-12-08 14:53:48 -080013999
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014000 val = get_param(cmd, "nss_mcs_opt");
14001 if (val) {
14002 /* String (nss_operating_mode; mcs_operating_mode) */
14003 int nss, mcs;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053014004 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014005
14006 token = strdup(val);
14007 if (!token)
14008 return 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053014009 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053014010 if (!result) {
14011 sigma_dut_print(dut, DUT_MSG_ERROR,
14012 "VHT NSS not specified");
14013 goto failed;
14014 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014015 if (strcasecmp(result, "def") != 0) {
14016 nss = atoi(result);
14017 if (nss == 4)
14018 ath_disable_txbf(dut, intf);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070014019 if (run_iwpriv(dut, intf, "nss %d", nss) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014020 goto failed;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070014021
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014022 }
14023
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053014024 result = strtok_r(NULL, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053014025 if (!result) {
14026 sigma_dut_print(dut, DUT_MSG_ERROR,
14027 "VHT MCS not specified");
14028 goto failed;
14029 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014030 if (strcasecmp(result, "def") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070014031 if (run_iwpriv(dut, intf, "set11NRates 0") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014032 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014033 } else {
14034 mcs = atoi(result);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070014035 if (run_iwpriv(dut, intf, "vhtmcs %d", mcs) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014036 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014037 }
14038 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070014039 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014040 }
14041
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053014042 free(token);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014043 return 1;
14044failed:
14045 free(token);
14046 return 0;
14047}
14048
14049
14050static int cmd_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
14051 struct sigma_conn *conn,
14052 struct sigma_cmd *cmd)
14053{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020014054 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014055 case DRIVER_ATHEROS:
14056 return ath_sta_set_rfeature_vht(intf, dut, conn, cmd);
14057 default:
14058 send_resp(dut, conn, SIGMA_ERROR,
14059 "errorCode,Unsupported sta_set_rfeature(VHT) with the current driver");
14060 return 0;
14061 }
14062}
14063
14064
Jouni Malinen1702fe32021-06-08 19:08:01 +030014065static enum sigma_cmd_result
14066wcn_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
14067 struct sigma_conn *conn, struct sigma_cmd *cmd)
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014068{
14069 const char *val;
14070 char *token = NULL, *result;
14071 char buf[60];
14072
14073 val = get_param(cmd, "nss_mcs_opt");
14074 if (val) {
14075 /* String (nss_operating_mode; mcs_operating_mode) */
14076 int nss, mcs, ratecode;
14077 char *saveptr;
14078
14079 token = strdup(val);
14080 if (!token)
Jouni Malinen1702fe32021-06-08 19:08:01 +030014081 return ERROR_SEND_STATUS;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014082
14083 result = strtok_r(token, ";", &saveptr);
14084 if (!result) {
14085 sigma_dut_print(dut, DUT_MSG_ERROR,
14086 "HE NSS not specified");
14087 goto failed;
14088 }
14089 nss = 1;
14090 if (strcasecmp(result, "def") != 0)
14091 nss = atoi(result);
14092
14093 result = strtok_r(NULL, ";", &saveptr);
14094 if (!result) {
14095 sigma_dut_print(dut, DUT_MSG_ERROR,
14096 "HE MCS not specified");
14097 goto failed;
14098 }
14099 mcs = 7;
14100 if (strcasecmp(result, "def") != 0)
14101 mcs = atoi(result);
14102
Arif Hussain557bf412018-05-25 17:29:36 -070014103 ratecode = 0x20; /* for nss:1 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014104 if (nss == 2) {
Arif Hussain557bf412018-05-25 17:29:36 -070014105 ratecode = 0x40; /* for nss:2 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014106 } else if (nss > 2) {
14107 sigma_dut_print(dut, DUT_MSG_ERROR,
14108 "HE NSS %d not supported", nss);
14109 goto failed;
14110 }
14111
Arif Hussain557bf412018-05-25 17:29:36 -070014112 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss);
14113 if (system(buf) != 0) {
14114 sigma_dut_print(dut, DUT_MSG_ERROR,
14115 "nss_mcs_opt: iwpriv %s nss %d failed",
14116 intf, nss);
14117 goto failed;
14118 }
Arif Hussainac6c5112018-05-25 17:34:00 -070014119 dut->sta_nss = nss;
Arif Hussain557bf412018-05-25 17:29:36 -070014120
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014121 /* Add the MCS to the ratecode */
14122 if (mcs >= 0 && mcs <= 11) {
14123 ratecode += mcs;
Arif Hussain557bf412018-05-25 17:29:36 -070014124#ifdef NL80211_SUPPORT
14125 if (dut->device_type == STA_testbed) {
14126 enum he_mcs_config mcs_config;
14127 int ret;
14128
14129 if (mcs <= 7)
14130 mcs_config = HE_80_MCS0_7;
14131 else if (mcs <= 9)
14132 mcs_config = HE_80_MCS0_9;
14133 else
14134 mcs_config = HE_80_MCS0_11;
14135 ret = sta_set_he_mcs(dut, intf, mcs_config);
14136 if (ret) {
14137 sigma_dut_print(dut, DUT_MSG_ERROR,
14138 "nss_mcs_opt: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
14139 mcs, mcs_config, ret);
14140 goto failed;
14141 }
14142 }
14143#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014144 } else {
14145 sigma_dut_print(dut, DUT_MSG_ERROR,
14146 "HE MCS %d not supported", mcs);
14147 goto failed;
14148 }
14149 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0x%03x",
14150 intf, ratecode);
14151 if (system(buf) != 0) {
14152 sigma_dut_print(dut, DUT_MSG_ERROR,
14153 "iwpriv setting of 11ax rates failed");
14154 goto failed;
14155 }
14156 free(token);
14157 }
14158
14159 val = get_param(cmd, "GI");
14160 if (val) {
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080014161 int fix_rate_sgi;
14162
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014163 if (strcmp(val, "0.8") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070014164 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 9", intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080014165 fix_rate_sgi = 1;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014166 } else if (strcmp(val, "1.6") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070014167 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 10",
14168 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080014169 fix_rate_sgi = 2;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014170 } else if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070014171 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 11",
14172 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080014173 fix_rate_sgi = 3;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014174 } else {
14175 send_resp(dut, conn, SIGMA_ERROR,
14176 "errorCode,GI value not supported");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014177 return STATUS_SENT_ERROR;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014178 }
14179 if (system(buf) != 0) {
14180 send_resp(dut, conn, SIGMA_ERROR,
14181 "errorCode,Failed to set shortgi");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014182 return STATUS_SENT_ERROR;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014183 }
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080014184 snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d",
14185 intf, fix_rate_sgi);
14186 if (system(buf) != 0) {
14187 send_resp(dut, conn, SIGMA_ERROR,
14188 "errorCode,Failed to set fix rate shortgi");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014189 return STATUS_SENT_ERROR;
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080014190 }
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014191 }
14192
Subhani Shaik8e7a3052018-04-24 14:03:00 -070014193 val = get_param(cmd, "LTF");
14194 if (val) {
14195#ifdef NL80211_SUPPORT
14196 if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080014197 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_1X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070014198 } if (strcmp(val, "6.4") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080014199 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_2X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070014200 } else if (strcmp(val, "12.8") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080014201 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_4X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070014202 } else {
14203 send_resp(dut, conn, SIGMA_ERROR,
14204 "errorCode, LTF value not supported");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014205 return STATUS_SENT_ERROR;
Subhani Shaik8e7a3052018-04-24 14:03:00 -070014206 }
14207#else /* NL80211_SUPPORT */
14208 sigma_dut_print(dut, DUT_MSG_ERROR,
14209 "LTF cannot be set without NL80211_SUPPORT defined");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014210 return ERROR_SEND_STATUS;
Subhani Shaik8e7a3052018-04-24 14:03:00 -070014211#endif /* NL80211_SUPPORT */
14212 }
14213
Kiran Kumar Lokere1809da12021-06-24 00:45:38 -070014214 val = get_param(cmd, "KeepAlive");
14215 if (val) {
14216 int set_val = QCA_WLAN_KEEP_ALIVE_DEFAULT;
14217
14218 if (strcasecmp(val, "Data") == 0)
14219 set_val = QCA_WLAN_KEEP_ALIVE_DATA;
14220 else if (strcasecmp(val, "Mgmt") == 0)
14221 set_val = QCA_WLAN_KEEP_ALIVE_MGMT;
14222
14223 if (sta_set_keep_alive_data_cfg(dut, intf, set_val)) {
14224 send_resp(dut, conn, SIGMA_ERROR,
14225 "ErrorCode,Failed to set keep alive type config");
14226 return STATUS_SENT_ERROR;
14227 }
14228 }
14229
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -070014230 val = get_param(cmd, "TxSUPPDU");
14231 if (val) {
14232 int set_val = 1;
14233
14234 if (strcasecmp(val, "Enable") == 0)
14235 set_val = 1;
14236 else if (strcasecmp(val, "Disable") == 0)
14237 set_val = 0;
14238
14239 if (sta_set_tx_su_ppdu_cfg(dut, intf, set_val)) {
14240 send_resp(dut, conn, SIGMA_ERROR,
14241 "ErrorCode,Failed to set Tx SU PPDU config");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014242 return STATUS_SENT_ERROR;
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -070014243 }
14244 }
14245
Kiran Kumar Lokere54b72522021-04-01 00:22:44 -070014246 val = get_param(cmd, "Mgmt_Data_TX_Resp_Frame");
14247 if (val) {
14248 int set_val = 0;
14249
14250 if (strcasecmp(val, "Enable") == 0)
14251 set_val = 0;
14252 else if (strcasecmp(val, "Disable") == 0)
14253 set_val = 1;
14254
14255 if (sta_set_mgmt_data_tx_disable_cfg(dut, intf, set_val)) {
14256 send_resp(dut, conn, SIGMA_ERROR,
14257 "ErrorCode,Failed to set mgmt/data Tx disable config");
14258 return STATUS_SENT_ERROR;
14259 }
14260 }
14261
Arif Hussain480d5f42019-03-12 14:40:42 -070014262 val = get_param(cmd, "TWT_Setup");
14263 if (val) {
14264 if (strcasecmp(val, "Request") == 0) {
14265 if (sta_twt_request(dut, conn, cmd)) {
14266 send_resp(dut, conn, SIGMA_ERROR,
Srinivas Girigowda6707f032020-10-26 15:24:46 -070014267 "ErrorCode,TWT setup failed");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014268 return STATUS_SENT_ERROR;
Arif Hussain480d5f42019-03-12 14:40:42 -070014269 }
14270 } else if (strcasecmp(val, "Teardown") == 0) {
14271 if (sta_twt_teardown(dut, conn, cmd)) {
14272 send_resp(dut, conn, SIGMA_ERROR,
Srinivas Girigowda6707f032020-10-26 15:24:46 -070014273 "ErrorCode,TWT teardown failed");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014274 return STATUS_SENT_ERROR;
Arif Hussain480d5f42019-03-12 14:40:42 -070014275 }
14276 }
14277 }
14278
Srinivas Girigowda6707f032020-10-26 15:24:46 -070014279 val = get_param(cmd, "TWT_Operation");
14280 if (val) {
14281 if (strcasecmp(val, "Suspend") == 0) {
14282 if (sta_twt_suspend_or_nudge(dut, conn, cmd)) {
14283 send_resp(dut, conn, SIGMA_ERROR,
14284 "ErrorCode,TWT suspend failed");
14285 return STATUS_SENT_ERROR;
14286 }
14287 } else if (strcasecmp(val, "Resume") == 0) {
14288 if (sta_twt_resume(dut, conn, cmd)) {
14289 send_resp(dut, conn, SIGMA_ERROR,
14290 "ErrorCode,TWT resume failed");
14291 return STATUS_SENT_ERROR;
14292 }
14293 }
14294 }
14295
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -080014296 val = get_param(cmd, "transmitOMI");
14297 if (val && sta_transmit_omi(dut, conn, cmd)) {
14298 send_resp(dut, conn, SIGMA_ERROR,
14299 "ErrorCode,sta_transmit_omi failed");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014300 return STATUS_SENT_ERROR;
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -070014301 }
14302
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080014303 val = get_param(cmd, "Powersave");
14304 if (val) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053014305 int ps;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080014306
14307 if (strcasecmp(val, "off") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053014308 ps = 2;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080014309 } else if (strcasecmp(val, "on") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053014310 ps = 1;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080014311 } else {
14312 sigma_dut_print(dut, DUT_MSG_ERROR,
14313 "Unsupported Powersave value '%s'",
14314 val);
Jouni Malinen1702fe32021-06-08 19:08:01 +030014315 return INVALID_SEND_STATUS;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080014316 }
Vinita S. Malooa8b62722020-04-23 01:45:41 +053014317 if (set_power_save_wcn(dut, intf, ps) < 0)
Jouni Malinen1702fe32021-06-08 19:08:01 +030014318 return ERROR_SEND_STATUS;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080014319 }
14320
Kiran Kumar Lokere2c4b7ce2019-01-30 12:02:28 -080014321 val = get_param(cmd, "MU_EDCA");
14322 if (val) {
14323 if (strcasecmp(val, "Override") == 0) {
14324 if (sta_set_mu_edca_override(dut, intf, 1)) {
14325 send_resp(dut, conn, SIGMA_ERROR,
14326 "errorCode,MU EDCA override set failed");
14327 return STATUS_SENT;
14328 }
14329 } else if (strcasecmp(val, "Disable") == 0) {
14330 if (sta_set_mu_edca_override(dut, intf, 0)) {
14331 send_resp(dut, conn, SIGMA_ERROR,
14332 "errorCode,MU EDCA override disable failed");
14333 return STATUS_SENT;
14334 }
14335 }
14336 }
14337
Kiran Kumar Lokerefa7c7b92021-08-09 00:50:55 -070014338 val = get_param(cmd, "RUAllocTone");
14339 if (val && strcasecmp(val, "242") == 0) {
14340 if (sta_set_ru_242_tone_tx(dut, intf, 1)) {
14341 send_resp(dut, conn, SIGMA_ERROR,
14342 "ErrorCode,Failed to set RU 242 tone Tx");
14343 return STATUS_SENT_ERROR;
14344 }
14345 }
14346
14347 val = get_param(cmd, "PPDUTxType");
14348 if (val && strcasecmp(val, "ER-SU") == 0) {
14349 if (sta_set_er_su_ppdu_type_tx(dut, intf, 1)) {
14350 send_resp(dut, conn, SIGMA_ERROR,
14351 "ErrorCode,Failed to set ER-SU PPDU type Tx");
14352 return STATUS_SENT_ERROR;
14353 }
14354 }
14355
Kiran Kumar Lokeredd086642020-06-04 00:29:26 -070014356 val = get_param(cmd, "Ch_Pref");
14357 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
14358 return STATUS_SENT;
14359
14360 val = get_param(cmd, "Cellular_Data_Cap");
14361 if (val && mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
14362 return STATUS_SENT;
14363
Jouni Malinen1702fe32021-06-08 19:08:01 +030014364 return SUCCESS_SEND_STATUS;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014365
14366failed:
14367 free(token);
Jouni Malinen1702fe32021-06-08 19:08:01 +030014368 return ERROR_SEND_STATUS;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014369}
14370
14371
Jouni Malinen1702fe32021-06-08 19:08:01 +030014372static enum sigma_cmd_result
14373cmd_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
14374 struct sigma_conn *conn, struct sigma_cmd *cmd)
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014375{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020014376 switch (get_driver_type(dut)) {
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014377 case DRIVER_WCN:
14378 return wcn_sta_set_rfeature_he(intf, dut, conn, cmd);
14379 default:
14380 send_resp(dut, conn, SIGMA_ERROR,
14381 "errorCode,Unsupported sta_set_rfeature(HE) with the current driver");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014382 return STATUS_SENT_ERROR;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014383 }
14384}
14385
14386
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080014387static int cmd_sta_set_power_save_he(const char *intf, struct sigma_dut *dut,
14388 struct sigma_conn *conn,
14389 struct sigma_cmd *cmd)
14390{
14391 const char *val;
14392
14393 val = get_param(cmd, "powersave");
14394 if (val) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053014395 int ps;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080014396
14397 if (strcasecmp(val, "off") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053014398 ps = 2;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080014399 } else if (strcasecmp(val, "on") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053014400 ps = 1;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080014401 } else {
14402 sigma_dut_print(dut, DUT_MSG_ERROR,
14403 "Unsupported power save config");
14404 return -1;
14405 }
Vinita S. Malooa8b62722020-04-23 01:45:41 +053014406 if (set_power_save_wcn(dut, intf, ps) < 0)
14407 return 0;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080014408 return 1;
14409 }
14410
14411 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported command");
14412
14413 return 0;
14414}
14415
14416
Ashwini Patil5acd7382017-04-13 15:55:04 +053014417static int btm_query_candidate_list(struct sigma_dut *dut,
14418 struct sigma_conn *conn,
14419 struct sigma_cmd *cmd)
14420{
14421 const char *bssid, *info, *op_class, *ch, *phy_type, *pref;
14422 int len, ret;
14423 char buf[10];
14424
14425 /*
14426 * Neighbor Report elements format:
14427 * neighbor=<BSSID>,<BSSID Information>,<Operating Class>,
14428 * <Channel Number>,<PHY Type>[,<hexdump of Optional Subelements>]
14429 * eg: neighbor=aa:bb:cc:dd:ee:ff,17,81,6,1,030101
14430 */
14431
14432 bssid = get_param(cmd, "Nebor_BSSID");
14433 if (!bssid) {
14434 send_resp(dut, conn, SIGMA_INVALID,
14435 "errorCode,Nebor_BSSID is missing");
14436 return 0;
14437 }
14438
14439 info = get_param(cmd, "Nebor_Bssid_Info");
14440 if (!info) {
14441 sigma_dut_print(dut, DUT_MSG_INFO,
14442 "Using default value for Nebor_Bssid_Info: %s",
14443 DEFAULT_NEIGHBOR_BSSID_INFO);
14444 info = DEFAULT_NEIGHBOR_BSSID_INFO;
14445 }
14446
14447 op_class = get_param(cmd, "Nebor_Op_Class");
14448 if (!op_class) {
14449 send_resp(dut, conn, SIGMA_INVALID,
14450 "errorCode,Nebor_Op_Class is missing");
14451 return 0;
14452 }
14453
14454 ch = get_param(cmd, "Nebor_Op_Ch");
14455 if (!ch) {
14456 send_resp(dut, conn, SIGMA_INVALID,
14457 "errorCode,Nebor_Op_Ch is missing");
14458 return 0;
14459 }
14460
14461 phy_type = get_param(cmd, "Nebor_Phy_Type");
14462 if (!phy_type) {
14463 sigma_dut_print(dut, DUT_MSG_INFO,
14464 "Using default value for Nebor_Phy_Type: %s",
14465 DEFAULT_NEIGHBOR_PHY_TYPE);
14466 phy_type = DEFAULT_NEIGHBOR_PHY_TYPE;
14467 }
14468
14469 /* Parse optional subelements */
14470 buf[0] = '\0';
14471 pref = get_param(cmd, "Nebor_Pref");
14472 if (pref) {
14473 /* hexdump for preferrence subelement */
14474 ret = snprintf(buf, sizeof(buf), ",0301%02x", atoi(pref));
14475 if (ret < 0 || ret >= (int) sizeof(buf)) {
14476 sigma_dut_print(dut, DUT_MSG_ERROR,
14477 "snprintf failed for optional subelement ret: %d",
14478 ret);
14479 send_resp(dut, conn, SIGMA_ERROR,
14480 "errorCode,snprintf failed for subelement");
14481 return 0;
14482 }
14483 }
14484
14485 if (!dut->btm_query_cand_list) {
14486 dut->btm_query_cand_list = calloc(1, NEIGHBOR_REPORT_SIZE);
14487 if (!dut->btm_query_cand_list) {
14488 send_resp(dut, conn, SIGMA_ERROR,
14489 "errorCode,Failed to allocate memory for btm_query_cand_list");
14490 return 0;
14491 }
14492 }
14493
14494 len = strlen(dut->btm_query_cand_list);
14495 ret = snprintf(dut->btm_query_cand_list + len,
14496 NEIGHBOR_REPORT_SIZE - len, " neighbor=%s,%s,%s,%s,%s%s",
14497 bssid, info, op_class, ch, phy_type, buf);
14498 if (ret < 0 || ret >= NEIGHBOR_REPORT_SIZE - len) {
14499 sigma_dut_print(dut, DUT_MSG_ERROR,
14500 "snprintf failed for neighbor report list ret: %d",
14501 ret);
14502 send_resp(dut, conn, SIGMA_ERROR,
14503 "errorCode,snprintf failed for neighbor report");
14504 free(dut->btm_query_cand_list);
14505 dut->btm_query_cand_list = NULL;
14506 return 0;
14507 }
14508
14509 return 1;
14510}
14511
14512
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020014513int sta_extract_60g_ese(struct sigma_dut *dut, struct sigma_cmd *cmd,
14514 struct sigma_ese_alloc *allocs, int *allocs_size)
14515{
14516 int max_count = *allocs_size;
14517 int count = 0, i;
14518 const char *val;
14519
14520 do {
14521 val = get_param_indexed(cmd, "AllocID", count);
14522 if (val)
14523 count++;
14524 } while (val);
14525
14526 if (count == 0 || count > max_count) {
14527 sigma_dut_print(dut, DUT_MSG_ERROR,
14528 "Invalid number of allocations(%d)", count);
14529 return -1;
14530 }
14531
14532 for (i = 0; i < count; i++) {
14533 val = get_param_indexed(cmd, "PercentBI", i);
14534 if (!val) {
14535 sigma_dut_print(dut, DUT_MSG_ERROR,
14536 "Missing PercentBI parameter at index %d",
14537 i);
14538 return -1;
14539 }
14540 allocs[i].percent_bi = atoi(val);
14541
14542 val = get_param_indexed(cmd, "SrcAID", i);
14543 if (val)
14544 allocs[i].src_aid = strtol(val, NULL, 0);
14545 else
14546 allocs[i].src_aid = ESE_BCAST_AID;
14547
14548 val = get_param_indexed(cmd, "DestAID", i);
14549 if (val)
14550 allocs[i].dst_aid = strtol(val, NULL, 0);
14551 else
14552 allocs[i].dst_aid = ESE_BCAST_AID;
14553
14554 allocs[i].type = ESE_CBAP;
14555 sigma_dut_print(dut, DUT_MSG_INFO,
14556 "Alloc %d PercentBI %d SrcAID %d DstAID %d",
14557 i, allocs[i].percent_bi, allocs[i].src_aid,
14558 allocs[i].dst_aid);
14559 }
14560
14561 *allocs_size = count;
14562 return 0;
14563}
14564
14565
14566static int sta_set_60g_ese(struct sigma_dut *dut, int count,
14567 struct sigma_ese_alloc *allocs)
14568{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020014569 switch (get_driver_type(dut)) {
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020014570#ifdef __linux__
14571 case DRIVER_WIL6210:
14572 if (wil6210_set_ese(dut, count, allocs))
14573 return -1;
14574 return 1;
14575#endif /* __linux__ */
14576 default:
14577 sigma_dut_print(dut, DUT_MSG_ERROR,
14578 "Unsupported sta_set_60g_ese with the current driver");
14579 return -1;
14580 }
14581}
14582
14583
14584static int cmd_sta_set_rfeature_60g(const char *intf, struct sigma_dut *dut,
14585 struct sigma_conn *conn,
14586 struct sigma_cmd *cmd)
14587{
14588 const char *val;
14589
14590 val = get_param(cmd, "ExtSchIE");
14591 if (val && !strcasecmp(val, "Enable")) {
14592 struct sigma_ese_alloc allocs[MAX_ESE_ALLOCS];
14593 int count = MAX_ESE_ALLOCS;
14594
14595 if (sta_extract_60g_ese(dut, cmd, allocs, &count))
14596 return -1;
14597 return sta_set_60g_ese(dut, count, allocs);
14598 }
14599
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020014600 val = get_param(cmd, "MCS_FixedRate");
14601 if (val) {
14602 int sta_mcs = atoi(val);
14603
14604 sigma_dut_print(dut, DUT_MSG_INFO, "Force STA MCS to %d",
14605 sta_mcs);
14606 wil6210_set_force_mcs(dut, 1, sta_mcs);
14607
Jouni Malinen0e29cf22019-02-19 01:13:21 +020014608 return SUCCESS_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020014609 }
14610
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020014611 send_resp(dut, conn, SIGMA_ERROR,
14612 "errorCode,Invalid sta_set_rfeature(60G)");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020014613 return STATUS_SENT;
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020014614}
14615
14616
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053014617static int wcn_sta_override_oci(struct sigma_dut *dut, const char *intf,
14618 const char *oci_frametype, uint32_t oci_freq)
14619{
14620#ifdef NL80211_SUPPORT
14621 struct nl_msg *msg;
14622 int ret = 0;
14623 struct nlattr *params;
14624 struct nlattr *attr;
14625 int ifindex;
14626 u8 frame_type;
14627
14628 ifindex = if_nametoindex(intf);
14629 if (ifindex == 0) {
14630 sigma_dut_print(dut, DUT_MSG_ERROR,
14631 "%s: Index for interface %s failed",
14632 __func__, intf);
14633 return -1;
14634 }
14635
14636 if (strcasecmp(oci_frametype, "SAQueryReq") == 0) {
14637 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_SA_QUERY_REQ;
14638 } else if (strcasecmp(oci_frametype, "SAQueryResp") == 0) {
14639 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_SA_QUERY_RESP;
14640 } else if (strcasecmp(oci_frametype, "Reassocreq") == 0) {
14641 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_FT_REASSOC_REQ;
14642 } else {
14643 sigma_dut_print(dut, DUT_MSG_ERROR, "%s: Unknown frametype %s",
14644 __func__, oci_frametype);
14645 return -1;
14646 }
14647
14648
14649 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
14650 NL80211_CMD_VENDOR)) ||
14651 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
14652 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
14653 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
14654 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
14655 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
14656 !(params = nla_nest_start(
14657 msg,
14658 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_OCI_OVERRIDE)) ||
14659 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_OCI_OVERRIDE_FRAME_TYPE,
14660 frame_type) ||
14661 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_OCI_OVERRIDE_FREQUENCY,
14662 oci_freq)) {
14663 sigma_dut_print(dut, DUT_MSG_ERROR,
14664 "%s: err in adding vendor_cmd and vendor_data",
14665 __func__);
14666 nlmsg_free(msg);
14667 return -1;
14668 }
14669 nla_nest_end(msg, params);
14670 nla_nest_end(msg, attr);
14671
14672 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
14673 if (ret) {
14674 sigma_dut_print(dut, DUT_MSG_ERROR,
14675 "%s: err in send_and_recv_msgs, ret=%d",
14676 __func__, ret);
14677 }
14678 return ret;
14679#else /* NL80211_SUPPORT */
14680 sigma_dut_print(dut, DUT_MSG_ERROR,
14681 "OCI override not possible without NL80211_SUPPORT defined");
14682 return -1;
14683#endif /* NL80211_SUPPORT */
14684}
14685
14686
Veerendranath Jakkam50d5c782020-07-22 01:59:01 +053014687static int wcn_sta_ignore_csa(struct sigma_dut *dut, const char *intf,
14688 uint8_t ignore_csa)
14689{
14690#ifdef NL80211_SUPPORT
14691 return wcn_wifi_test_config_set_u8(
14692 dut, intf,
14693 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_IGNORE_CSA, ignore_csa);
14694#else /* NL80211_SUPPORT */
14695 sigma_dut_print(dut, DUT_MSG_ERROR,
14696 "IgnoreCSA can't be set without NL80211_SUPPORT defined");
14697 return -1;
14698#endif /* NL80211_SUPPORT */
14699}
14700
14701
Veerendranath Jakkamc771fac2020-07-22 01:32:56 +053014702static int wcn_sta_set_rsnxe_used(struct sigma_dut *dut, const char *intf,
14703 uint8_t rsnxe_used)
14704{
14705#ifdef NL80211_SUPPORT
14706 return wcn_wifi_test_config_set_u8(
14707 dut, intf,
14708 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_FT_REASSOCREQ_RSNXE_USED,
14709 rsnxe_used);
14710#else /* NL80211_SUPPORT */
14711 sigma_dut_print(dut, DUT_MSG_ERROR,
14712 "RSNXE_Used can't be set without NL80211_SUPPORT defined");
14713 return -1;
14714#endif /* NL80211_SUPPORT */
14715}
14716
14717
Veerendranath Jakkam1e1e5fd2020-09-10 07:12:37 +053014718static int wcn_sta_ignore_sa_query_timeout(struct sigma_dut *dut,
14719 const char *intf,
14720 uint8_t ignore_sa_query_timeout)
14721{
14722#ifdef NL80211_SUPPORT
14723 return wcn_wifi_test_config_set_u8(
14724 dut, intf,
14725 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_IGNORE_SA_QUERY_TIMEOUT,
14726 ignore_sa_query_timeout);
14727#else /* NL80211_SUPPORT */
14728 sigma_dut_print(dut, DUT_MSG_ERROR,
14729 "Ignore SA Query timeout can't be set without NL80211_SUPPORT defined");
14730 return -1;
14731#endif /* NL80211_SUPPORT */
14732}
14733
14734
Jouni Malinen6250cb02020-04-15 13:54:45 +030014735static enum sigma_cmd_result
14736cmd_sta_set_rfeature_wpa3(const char *intf, struct sigma_dut *dut,
14737 struct sigma_conn *conn,
14738 struct sigma_cmd *cmd)
14739{
Vamsi Krishnad29bc762020-05-08 23:23:30 +053014740 const char *val, *oci_chan, *oci_frametype;
Jouni Malinen6250cb02020-04-15 13:54:45 +030014741
Veerendranath Jakkam30bf9072020-04-16 14:37:57 +053014742 val = get_param(cmd, "ReassocReq_RSNXE_Used");
Jouni Malinen6250cb02020-04-15 13:54:45 +030014743 if (val && atoi(val) == 1) {
Veerendranath Jakkamc771fac2020-07-22 01:32:56 +053014744 if (wifi_chip_type == DRIVER_WCN) {
14745 if (wcn_sta_set_rsnxe_used(dut, intf, 1)) {
14746 send_resp(dut, conn, SIGMA_ERROR,
14747 "errorCode,Failed to set ft_rsnxe_used");
14748 return STATUS_SENT_ERROR;
14749 }
14750 return SUCCESS_SEND_STATUS;
14751 } else if (wpa_command(intf, "SET ft_rsnxe_used 1") < 0) {
Jouni Malinen6250cb02020-04-15 13:54:45 +030014752 send_resp(dut, conn, SIGMA_ERROR,
14753 "errorCode,Failed to set ft_rsnxe_used");
14754 return STATUS_SENT_ERROR;
14755 }
14756 return SUCCESS_SEND_STATUS;
14757 }
Vamsi Krishnad29bc762020-05-08 23:23:30 +053014758
14759 oci_chan = get_param(cmd, "OCIChannel");
14760 oci_frametype = get_param(cmd, "OCIFrameType");
14761 if (oci_chan && oci_frametype) {
14762 unsigned int oci_freq = channel_to_freq(dut, atoi(oci_chan));
14763 char buf[100];
14764
14765 if (!oci_freq) {
14766 send_resp(dut, conn, SIGMA_ERROR,
14767 "errorCode,Invalid OCIChannel number");
14768 return STATUS_SENT_ERROR;
14769 }
14770
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053014771 if (wifi_chip_type == DRIVER_WCN &&
14772 (strcasecmp(oci_frametype, "SAQueryReq") == 0 ||
14773 strcasecmp(oci_frametype, "SAQueryResp") == 0 ||
14774 strcasecmp(oci_frametype, "Reassocreq") == 0)) {
14775 if (wcn_sta_override_oci(dut, intf, oci_frametype,
14776 oci_freq)) {
14777 send_resp(dut, conn, SIGMA_ERROR,
14778 "errorCode,Failed to override OCI");
14779 return STATUS_SENT_ERROR;
14780 }
14781 return SUCCESS_SEND_STATUS;
14782 }
14783
Vamsi Krishnad29bc762020-05-08 23:23:30 +053014784 if (strcasecmp(oci_frametype, "eapolM2") == 0) {
14785 snprintf(buf, sizeof(buf),
14786 "SET oci_freq_override_eapol %d", oci_freq);
14787 } else if (strcasecmp(oci_frametype, "SAQueryReq") == 0) {
14788 snprintf(buf, sizeof(buf),
14789 "SET oci_freq_override_saquery_req %d",
14790 oci_freq);
14791 } else if (strcasecmp(oci_frametype, "SAQueryResp") == 0) {
14792 snprintf(buf, sizeof(buf),
14793 "SET oci_freq_override_saquery_resp %d",
14794 oci_freq);
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053014795 } else if (strcasecmp(oci_frametype, "GrpKeyM2") == 0) {
14796 snprintf(buf, sizeof(buf),
14797 "SET oci_freq_override_eapol_g2 %d",
14798 oci_freq);
14799 } else if (strcasecmp(oci_frametype, "Reassocreq") == 0) {
14800 snprintf(buf, sizeof(buf),
14801 "SET oci_freq_override_ft_assoc %d",
14802 oci_freq);
Vamsi Krishnad29bc762020-05-08 23:23:30 +053014803 } else {
14804 send_resp(dut, conn, SIGMA_ERROR,
14805 "errorCode,Unsupported OCIFrameType");
14806 return STATUS_SENT_ERROR;
14807 }
14808 if (wpa_command(intf, buf) < 0) {
14809 send_resp(dut, conn, SIGMA_ERROR,
14810 "errorCode,Failed to set oci_freq_override");
14811 return STATUS_SENT_ERROR;
14812 }
14813 return SUCCESS_SEND_STATUS;
14814 }
14815
Veerendranath Jakkam50d5c782020-07-22 01:59:01 +053014816 val = get_param(cmd, "IgnoreCSA");
14817 if (val && atoi(val) == 1) {
14818 if (wifi_chip_type == DRIVER_WCN) {
14819 if (wcn_sta_ignore_csa(dut, intf, 1)) {
14820 send_resp(dut, conn, SIGMA_ERROR,
14821 "errorCode,Failed to set ignore CSA");
14822 return STATUS_SENT_ERROR;
14823 }
14824 return SUCCESS_SEND_STATUS;
14825 }
14826 }
14827
Veerendranath Jakkam1e1e5fd2020-09-10 07:12:37 +053014828 val = get_param(cmd, "Deauth_Per_SAQueryResp");
14829 if (val && atoi(val) == 0) {
14830 if (wifi_chip_type == DRIVER_WCN) {
14831 if (wcn_sta_ignore_sa_query_timeout(dut, intf, 1)) {
14832 send_resp(dut, conn, SIGMA_ERROR,
14833 "errorCode,Failed to set ignore SA Query timeout");
14834 return STATUS_SENT_ERROR;
14835 }
14836 return SUCCESS_SEND_STATUS;
14837 }
14838 }
14839
Jouni Malinen6250cb02020-04-15 13:54:45 +030014840 send_resp(dut, conn, SIGMA_ERROR,
14841 "errorCode,Unsupported WPA3 rfeature");
14842 return STATUS_SENT_ERROR;
14843}
14844
14845
Veerendranath Jakkam329a3cd2021-09-11 18:10:13 +053014846static enum sigma_cmd_result
14847cmd_sta_set_rfeature_qm(const char *intf, struct sigma_dut *dut,
14848 struct sigma_conn *conn, struct sigma_cmd *cmd)
14849{
14850 const char *val;
14851
14852 val = get_param(cmd, "DomainName_Domain");
14853 if (val) {
14854 if (strlen(val) >= sizeof(dut->qm_domain_name))
14855 return ERROR_SEND_STATUS;
14856
14857 strlcpy(dut->qm_domain_name, val, sizeof(dut->qm_domain_name));
14858 return SUCCESS_SEND_STATUS;
14859 }
14860
Veerendranath Jakkam1bf1bd62021-09-12 16:35:55 +053014861 val = get_param(cmd, "DSCPPolicy_PolicyID");
14862 if (val) {
14863 unsigned int i;
14864 int policy_id = atoi(val);
14865
14866 val = get_param(cmd, "DSCPPolicy_RequestType");
14867
14868 if (!policy_id || !val)
14869 return INVALID_SEND_STATUS;
14870
14871 if (dut->num_dscp_status >= ARRAY_SIZE(dut->dscp_status)) {
14872 send_resp(dut, conn, SIGMA_ERROR,
14873 "errorCode,DSCP status list full");
14874 return STATUS_SENT_ERROR;
14875 }
14876
14877 for (i = 0; i < dut->num_dscp_status; i++)
14878 if (dut->dscp_status[i].id == policy_id)
14879 break;
14880
14881 /* New policy configured */
14882 if (i == dut->num_dscp_status) {
14883 dut->dscp_status[i].id = policy_id;
14884 dut->num_dscp_status++;
14885 }
14886
14887 dut->dscp_status[i].status = strcasecmp(val, "Remove") ?
14888 DSCP_POLICY_SUCCESS : DSCP_POLICY_REJECT;
14889
14890 return SUCCESS_SEND_STATUS;
14891 }
14892
Veerendranath Jakkam329a3cd2021-09-11 18:10:13 +053014893 send_resp(dut, conn, SIGMA_ERROR,
14894 "errorCode,Unsupported QM rfeature");
14895 return STATUS_SENT_ERROR;
14896}
14897
14898
Jouni Malinenf7222712019-06-13 01:50:21 +030014899static enum sigma_cmd_result cmd_sta_set_rfeature(struct sigma_dut *dut,
14900 struct sigma_conn *conn,
14901 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014902{
14903 const char *intf = get_param(cmd, "Interface");
14904 const char *prog = get_param(cmd, "Prog");
Ashwini Patil68d02cd2017-01-10 15:39:16 +053014905 const char *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014906
Veerendranath Jakkam329a3cd2021-09-11 18:10:13 +053014907 if (!prog)
14908 prog = get_param(cmd, "Program");
14909
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014910 if (intf == NULL || prog == NULL)
14911 return -1;
14912
Ashwini Patil5acd7382017-04-13 15:55:04 +053014913 /* BSS Transition candidate list for BTM query */
14914 val = get_param(cmd, "Nebor_BSSID");
14915 if (val && btm_query_candidate_list(dut, conn, cmd) == 0)
14916 return 0;
14917
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014918 if (strcasecmp(prog, "TDLS") == 0)
14919 return cmd_sta_set_rfeature_tdls(intf, dut, conn, cmd);
14920
14921 if (strcasecmp(prog, "VHT") == 0)
14922 return cmd_sta_set_rfeature_vht(intf, dut, conn, cmd);
14923
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014924 if (strcasecmp(prog, "HE") == 0)
14925 return cmd_sta_set_rfeature_he(intf, dut, conn, cmd);
14926
Ashwini Patil68d02cd2017-01-10 15:39:16 +053014927 if (strcasecmp(prog, "MBO") == 0) {
14928 val = get_param(cmd, "Cellular_Data_Cap");
14929 if (val &&
14930 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
14931 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +053014932
14933 val = get_param(cmd, "Ch_Pref");
14934 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
14935 return 0;
14936
Ashwini Patil68d02cd2017-01-10 15:39:16 +053014937 return 1;
14938 }
14939
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020014940 if (strcasecmp(prog, "60GHz") == 0)
14941 return cmd_sta_set_rfeature_60g(intf, dut, conn, cmd);
14942
Jouni Malinen6250cb02020-04-15 13:54:45 +030014943 if (strcasecmp(prog, "WPA3") == 0)
14944 return cmd_sta_set_rfeature_wpa3(intf, dut, conn, cmd);
Veerendranath Jakkam329a3cd2021-09-11 18:10:13 +053014945 if (strcasecmp(prog, "QM") == 0)
14946 return cmd_sta_set_rfeature_qm(intf, dut, conn, cmd);
Jouni Malinen6250cb02020-04-15 13:54:45 +030014947
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014948 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported Prog");
14949 return 0;
14950}
14951
14952
Jouni Malinenf7222712019-06-13 01:50:21 +030014953static enum sigma_cmd_result cmd_sta_set_radio(struct sigma_dut *dut,
14954 struct sigma_conn *conn,
14955 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014956{
14957 const char *intf = get_param(cmd, "Interface");
14958 const char *mode = get_param(cmd, "Mode");
14959 int res;
14960
14961 if (intf == NULL || mode == NULL)
14962 return -1;
14963
14964 if (strcasecmp(mode, "On") == 0)
14965 res = wpa_command(intf, "SET radio_disabled 0");
14966 else if (strcasecmp(mode, "Off") == 0)
14967 res = wpa_command(intf, "SET radio_disabled 1");
14968 else
14969 return -1;
14970
14971 if (res) {
14972 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
14973 "radio mode");
14974 return 0;
14975 }
14976
14977 return 1;
14978}
14979
14980
Jouni Malinenf7222712019-06-13 01:50:21 +030014981static enum sigma_cmd_result cmd_sta_set_pwrsave(struct sigma_dut *dut,
14982 struct sigma_conn *conn,
14983 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014984{
14985 const char *intf = get_param(cmd, "Interface");
14986 const char *mode = get_param(cmd, "Mode");
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020014987 const char *prog = get_param(cmd, "program");
14988 const char *powersave = get_param(cmd, "powersave");
14989 int res = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014990
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020014991 if (intf == NULL)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014992 return -1;
14993
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020014994 if (prog && strcasecmp(prog, "60GHz") == 0) {
14995 /*
14996 * The CAPI mode parameter does not exist in 60G
14997 * unscheduled PS.
14998 */
Hu Wang5dc3ff12019-06-14 15:14:26 +080014999 if (powersave && strcasecmp(powersave, "unscheduled") == 0)
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020015000 res = set_ps(intf, dut, 1);
Jouni Malinen016ae6c2019-11-04 17:00:01 +020015001 } else if (prog && get_driver_type(dut) == DRIVER_WCN &&
Alexei Avshalom Lazar2f6fdb42019-02-04 14:16:08 +020015002 strcasecmp(prog, "HE") == 0) {
15003 return cmd_sta_set_power_save_he(intf, dut, conn, cmd);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020015004 } else {
15005 if (mode == NULL)
15006 return -1;
15007
15008 if (strcasecmp(mode, "On") == 0)
15009 res = set_ps(intf, dut, 1);
15010 else if (strcasecmp(mode, "Off") == 0)
15011 res = set_ps(intf, dut, 0);
15012 else
15013 return -1;
15014 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015015
15016 if (res) {
15017 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
15018 "power save mode");
15019 return 0;
15020 }
15021
15022 return 1;
15023}
15024
15025
Jouni Malinenf7222712019-06-13 01:50:21 +030015026static enum sigma_cmd_result cmd_sta_bssid_pool(struct sigma_dut *dut,
15027 struct sigma_conn *conn,
15028 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015029{
15030 const char *intf = get_param(cmd, "Interface");
15031 const char *val, *bssid;
15032 int res;
15033 char *buf;
15034 size_t buf_len;
15035
15036 val = get_param(cmd, "BSSID_FILTER");
15037 if (val == NULL)
15038 return -1;
15039
15040 bssid = get_param(cmd, "BSSID_List");
15041 if (atoi(val) == 0 || bssid == NULL) {
15042 /* Disable BSSID filter */
15043 if (wpa_command(intf, "SET bssid_filter ")) {
15044 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed "
15045 "to disable BSSID filter");
15046 return 0;
15047 }
15048
15049 return 1;
15050 }
15051
15052 buf_len = 100 + strlen(bssid);
15053 buf = malloc(buf_len);
15054 if (buf == NULL)
15055 return -1;
15056
15057 snprintf(buf, buf_len, "SET bssid_filter %s", bssid);
15058 res = wpa_command(intf, buf);
15059 free(buf);
15060 if (res) {
15061 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to enable "
15062 "BSSID filter");
15063 return 0;
15064 }
15065
15066 return 1;
15067}
15068
15069
Jouni Malinenf7222712019-06-13 01:50:21 +030015070static enum sigma_cmd_result cmd_sta_reset_parm(struct sigma_dut *dut,
15071 struct sigma_conn *conn,
15072 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015073{
15074 const char *intf = get_param(cmd, "Interface");
15075 const char *val;
15076
15077 /* TODO: ARP */
15078
15079 val = get_param(cmd, "HS2_CACHE_PROFILE");
15080 if (val && strcasecmp(val, "All") == 0)
15081 hs2_clear_credentials(intf);
15082
15083 return 1;
15084}
15085
15086
Jouni Malinenf7222712019-06-13 01:50:21 +030015087static enum sigma_cmd_result cmd_sta_get_key(struct sigma_dut *dut,
15088 struct sigma_conn *conn,
15089 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015090{
15091 const char *intf = get_param(cmd, "Interface");
15092 const char *key_type = get_param(cmd, "KeyType");
15093 char buf[100], resp[200];
15094
15095 if (key_type == NULL)
15096 return -1;
15097
15098 if (strcasecmp(key_type, "GTK") == 0) {
15099 if (wpa_command_resp(intf, "GET gtk", buf, sizeof(buf)) < 0 ||
15100 strncmp(buf, "FAIL", 4) == 0) {
15101 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
15102 "not fetch current GTK");
15103 return 0;
15104 }
15105 snprintf(resp, sizeof(resp), "KeyValue,%s", buf);
15106 send_resp(dut, conn, SIGMA_COMPLETE, resp);
15107 return 0;
15108 } else {
15109 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
15110 "KeyType");
15111 return 0;
15112 }
15113
15114 return 1;
15115}
15116
15117
15118static int hs2_set_policy(struct sigma_dut *dut)
15119{
15120#ifdef ANDROID
15121 system("ip rule del prio 23000");
15122 if (system("ip rule add from all lookup main prio 23000") != 0) {
15123 sigma_dut_print(dut, DUT_MSG_ERROR,
15124 "Failed to run:ip rule add from all lookup main prio");
15125 return -1;
15126 }
15127 if (system("ip route flush cache") != 0) {
15128 sigma_dut_print(dut, DUT_MSG_ERROR,
15129 "Failed to run ip route flush cache");
15130 return -1;
15131 }
15132 return 1;
15133#else /* ANDROID */
15134 return 0;
15135#endif /* ANDROID */
15136}
15137
15138
Jouni Malinenf7222712019-06-13 01:50:21 +030015139static enum sigma_cmd_result cmd_sta_hs2_associate(struct sigma_dut *dut,
15140 struct sigma_conn *conn,
15141 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015142{
15143 const char *intf = get_param(cmd, "Interface");
15144 const char *val = get_param(cmd, "Ignore_blacklist");
Jouni Malinen439352d2018-09-13 03:42:23 +030015145 const char *band = get_param(cmd, "Band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015146 struct wpa_ctrl *ctrl;
Jouni Malinen3aa72862019-05-29 23:14:51 +030015147 int res, r;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015148 char bssid[20], ssid[40], resp[100], buf[100], blacklisted[100];
15149 int tries = 0;
15150 int ignore_blacklist = 0;
15151 const char *events[] = {
15152 "CTRL-EVENT-CONNECTED",
15153 "INTERWORKING-BLACKLISTED",
15154 "INTERWORKING-NO-MATCH",
15155 NULL
15156 };
15157
15158 start_sta_mode(dut);
15159
Jouni Malinen439352d2018-09-13 03:42:23 +030015160 if (band) {
15161 if (strcmp(band, "2.4") == 0) {
15162 wpa_command(intf, "SET setband 2G");
15163 } else if (strcmp(band, "5") == 0) {
15164 wpa_command(intf, "SET setband 5G");
15165 } else {
15166 send_resp(dut, conn, SIGMA_ERROR,
15167 "errorCode,Unsupported band");
15168 return 0;
15169 }
15170 }
15171
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015172 blacklisted[0] = '\0';
15173 if (val && atoi(val))
15174 ignore_blacklist = 1;
15175
15176try_again:
15177 ctrl = open_wpa_mon(intf);
15178 if (ctrl == NULL) {
15179 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
15180 "wpa_supplicant monitor connection");
15181 return -2;
15182 }
15183
15184 tries++;
15185 if (wpa_command(intf, "INTERWORKING_SELECT auto")) {
15186 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start "
15187 "Interworking connection");
15188 wpa_ctrl_detach(ctrl);
15189 wpa_ctrl_close(ctrl);
15190 return 0;
15191 }
15192
15193 buf[0] = '\0';
15194 while (1) {
15195 char *pos;
15196 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
15197 pos = strstr(buf, "INTERWORKING-BLACKLISTED");
15198 if (!pos)
15199 break;
15200 pos += 25;
15201 sigma_dut_print(dut, DUT_MSG_DEBUG, "Found blacklisted AP: %s",
15202 pos);
15203 if (!blacklisted[0])
15204 memcpy(blacklisted, pos, strlen(pos) + 1);
15205 }
15206
15207 if (ignore_blacklist && blacklisted[0]) {
15208 char *end;
15209 end = strchr(blacklisted, ' ');
15210 if (end)
15211 *end = '\0';
15212 sigma_dut_print(dut, DUT_MSG_DEBUG, "Try to connect to a blacklisted network: %s",
15213 blacklisted);
Jouni Malinen3aa72862019-05-29 23:14:51 +030015214 r = snprintf(buf, sizeof(buf), "INTERWORKING_CONNECT %s",
15215 blacklisted);
15216 if (r < 0 || r >= sizeof(buf) || wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015217 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start Interworking connection to blacklisted network");
15218 wpa_ctrl_detach(ctrl);
15219 wpa_ctrl_close(ctrl);
15220 return 0;
15221 }
15222 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
15223 buf, sizeof(buf));
15224 }
15225
15226 wpa_ctrl_detach(ctrl);
15227 wpa_ctrl_close(ctrl);
15228
15229 if (res < 0) {
15230 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
15231 "connect");
15232 return 0;
15233 }
15234
15235 if (strstr(buf, "INTERWORKING-NO-MATCH") ||
15236 strstr(buf, "INTERWORKING-BLACKLISTED")) {
15237 if (tries < 2) {
15238 sigma_dut_print(dut, DUT_MSG_INFO, "No match found - try again to verify no APs were missed in the scan");
15239 goto try_again;
15240 }
15241 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,No network with "
15242 "matching credentials found");
15243 return 0;
15244 }
15245
15246 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
15247 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
15248 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
15249 "get current BSSID/SSID");
15250 return 0;
15251 }
15252
15253 snprintf(resp, sizeof(resp), "SSID,%s,BSSID,%s", ssid, bssid);
15254 send_resp(dut, conn, SIGMA_COMPLETE, resp);
15255 hs2_set_policy(dut);
15256 return 0;
15257}
15258
15259
Jouni Malinenf7222712019-06-13 01:50:21 +030015260static enum sigma_cmd_result cmd_sta_hs2_venue_info(struct sigma_dut *dut,
15261 struct sigma_conn *conn,
15262 struct sigma_cmd *cmd)
Jouni Malinenb639f1c2018-09-13 02:39:46 +030015263{
15264 const char *intf = get_param(cmd, "Interface");
15265 const char *display = get_param(cmd, "Display");
15266 struct wpa_ctrl *ctrl;
15267 char buf[300], params[400], *pos;
15268 char bssid[20];
15269 int info_avail = 0;
15270 unsigned int old_timeout;
15271 int res;
15272
15273 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
15274 send_resp(dut, conn, SIGMA_ERROR,
15275 "ErrorCode,Could not get current BSSID");
15276 return 0;
15277 }
15278 ctrl = open_wpa_mon(intf);
15279 if (!ctrl) {
15280 sigma_dut_print(dut, DUT_MSG_ERROR,
15281 "Failed to open wpa_supplicant monitor connection");
15282 return -2;
15283 }
15284
15285 snprintf(buf, sizeof(buf), "ANQP_GET %s 277", bssid);
15286 wpa_command(intf, buf);
15287
15288 res = get_wpa_cli_event(dut, ctrl, "GAS-QUERY-DONE", buf, sizeof(buf));
15289 if (res < 0) {
15290 send_resp(dut, conn, SIGMA_ERROR,
15291 "ErrorCode,Could not complete GAS query");
15292 goto fail;
15293 }
15294
15295 old_timeout = dut->default_timeout;
15296 dut->default_timeout = 2;
15297 res = get_wpa_cli_event(dut, ctrl, "RX-VENUE-URL", buf, sizeof(buf));
15298 dut->default_timeout = old_timeout;
15299 if (res < 0)
15300 goto done;
15301 pos = strchr(buf, ' ');
15302 if (!pos)
15303 goto done;
15304 pos++;
15305 pos = strchr(pos, ' ');
15306 if (!pos)
15307 goto done;
15308 pos++;
15309 info_avail = 1;
15310 snprintf(params, sizeof(params), "browser %s", pos);
15311
15312 if (display && strcasecmp(display, "Yes") == 0) {
15313 pid_t pid;
15314
15315 pid = fork();
15316 if (pid < 0) {
15317 perror("fork");
15318 return -1;
15319 }
15320
15321 if (pid == 0) {
15322 run_hs20_osu(dut, params);
15323 exit(0);
15324 }
15325 }
15326
15327done:
15328 snprintf(buf, sizeof(buf), "Info_available,%s",
15329 info_avail ? "Yes" : "No");
15330 send_resp(dut, conn, SIGMA_COMPLETE, buf);
15331fail:
15332 wpa_ctrl_detach(ctrl);
15333 wpa_ctrl_close(ctrl);
15334 return 0;
15335}
15336
15337
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015338static int sta_add_credential_uname_pwd(struct sigma_dut *dut,
15339 struct sigma_conn *conn,
15340 const char *ifname,
15341 struct sigma_cmd *cmd)
15342{
15343 const char *val;
15344 int id;
15345
15346 id = add_cred(ifname);
15347 if (id < 0)
15348 return -2;
15349 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
15350
15351 val = get_param(cmd, "prefer");
15352 if (val && atoi(val) > 0)
15353 set_cred(ifname, id, "priority", "1");
15354
15355 val = get_param(cmd, "REALM");
15356 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
15357 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
15358 "realm");
15359 return 0;
15360 }
15361
15362 val = get_param(cmd, "HOME_FQDN");
15363 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
15364 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
15365 "home_fqdn");
15366 return 0;
15367 }
15368
15369 val = get_param(cmd, "Username");
15370 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
15371 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
15372 "username");
15373 return 0;
15374 }
15375
15376 val = get_param(cmd, "Password");
15377 if (val && set_cred_quoted(ifname, id, "password", val) < 0) {
15378 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
15379 "password");
15380 return 0;
15381 }
15382
15383 val = get_param(cmd, "ROOT_CA");
15384 if (val) {
15385 char fname[200];
15386 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
15387#ifdef __linux__
15388 if (!file_exists(fname)) {
15389 char msg[300];
15390 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
15391 "file (%s) not found", fname);
15392 send_resp(dut, conn, SIGMA_ERROR, msg);
15393 return 0;
15394 }
15395#endif /* __linux__ */
15396 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
15397 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
15398 "not set root CA");
15399 return 0;
15400 }
15401 }
15402
15403 return 1;
15404}
15405
15406
15407static int update_devdetail_imsi(struct sigma_dut *dut, const char *imsi)
15408{
15409 FILE *in, *out;
15410 char buf[500];
15411 int found = 0;
15412
15413 in = fopen("devdetail.xml", "r");
15414 if (in == NULL)
15415 return -1;
15416 out = fopen("devdetail.xml.tmp", "w");
15417 if (out == NULL) {
15418 fclose(in);
15419 return -1;
15420 }
15421
15422 while (fgets(buf, sizeof(buf), in)) {
15423 char *pos = strstr(buf, "<IMSI>");
15424 if (pos) {
15425 sigma_dut_print(dut, DUT_MSG_INFO, "Updated DevDetail IMSI to %s",
15426 imsi);
15427 pos += 6;
15428 *pos = '\0';
15429 fprintf(out, "%s%s</IMSI>\n", buf, imsi);
15430 found++;
15431 } else {
15432 fprintf(out, "%s", buf);
15433 }
15434 }
15435
15436 fclose(out);
15437 fclose(in);
15438 if (found)
15439 rename("devdetail.xml.tmp", "devdetail.xml");
15440 else
15441 unlink("devdetail.xml.tmp");
15442
15443 return 0;
15444}
15445
15446
15447static int sta_add_credential_sim(struct sigma_dut *dut,
15448 struct sigma_conn *conn,
15449 const char *ifname, struct sigma_cmd *cmd)
15450{
15451 const char *val, *imsi = NULL;
15452 int id;
15453 char buf[200];
15454 int res;
15455 const char *pos;
15456 size_t mnc_len;
15457 char plmn_mcc[4];
15458 char plmn_mnc[4];
15459
15460 id = add_cred(ifname);
15461 if (id < 0)
15462 return -2;
15463 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
15464
15465 val = get_param(cmd, "prefer");
15466 if (val && atoi(val) > 0)
15467 set_cred(ifname, id, "priority", "1");
15468
15469 val = get_param(cmd, "PLMN_MCC");
15470 if (val == NULL) {
15471 send_resp(dut, conn, SIGMA_ERROR,
15472 "errorCode,Missing PLMN_MCC");
15473 return 0;
15474 }
15475 if (strlen(val) != 3) {
15476 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MCC");
15477 return 0;
15478 }
15479 snprintf(plmn_mcc, sizeof(plmn_mcc), "%s", val);
15480
15481 val = get_param(cmd, "PLMN_MNC");
15482 if (val == NULL) {
15483 send_resp(dut, conn, SIGMA_ERROR,
15484 "errorCode,Missing PLMN_MNC");
15485 return 0;
15486 }
15487 if (strlen(val) != 2 && strlen(val) != 3) {
15488 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MNC");
15489 return 0;
15490 }
15491 snprintf(plmn_mnc, sizeof(plmn_mnc), "%s", val);
15492
15493 val = get_param(cmd, "IMSI");
15494 if (val == NULL) {
15495 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing SIM "
15496 "IMSI");
15497 return 0;
15498 }
15499
15500 imsi = pos = val;
15501
15502 if (strncmp(plmn_mcc, pos, 3) != 0) {
15503 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MCC mismatch");
15504 return 0;
15505 }
15506 pos += 3;
15507
15508 mnc_len = strlen(plmn_mnc);
15509 if (mnc_len < 2) {
15510 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC not set");
15511 return 0;
15512 }
15513
15514 if (strncmp(plmn_mnc, pos, mnc_len) != 0) {
15515 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC mismatch");
15516 return 0;
15517 }
15518 pos += mnc_len;
15519
15520 res = snprintf(buf, sizeof(buf), "%s%s-%s",plmn_mcc, plmn_mnc, pos);
15521 if (res < 0 || res >= (int) sizeof(buf))
15522 return -1;
15523 if (set_cred_quoted(ifname, id, "imsi", buf) < 0) {
15524 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
15525 "not set IMSI");
15526 return 0;
15527 }
15528
15529 val = get_param(cmd, "Password");
15530 if (val && set_cred_quoted(ifname, id, "milenage", val) < 0) {
15531 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
15532 "not set password");
15533 return 0;
15534 }
15535
Jouni Malinenba630452018-06-22 11:49:59 +030015536 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015537 /*
15538 * Set provisioning_sp for the test cases where SIM/USIM
15539 * provisioning is used.
15540 */
15541 if (val && set_cred_quoted(ifname, id, "provisioning_sp",
15542 "wi-fi.org") < 0) {
15543 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
15544 "not set provisioning_sp");
15545 return 0;
15546 }
15547
15548 update_devdetail_imsi(dut, imsi);
15549 }
15550
15551 return 1;
15552}
15553
15554
15555static int sta_add_credential_cert(struct sigma_dut *dut,
15556 struct sigma_conn *conn,
15557 const char *ifname,
15558 struct sigma_cmd *cmd)
15559{
15560 const char *val;
15561 int id;
15562
15563 id = add_cred(ifname);
15564 if (id < 0)
15565 return -2;
15566 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
15567
15568 val = get_param(cmd, "prefer");
15569 if (val && atoi(val) > 0)
15570 set_cred(ifname, id, "priority", "1");
15571
15572 val = get_param(cmd, "REALM");
15573 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
15574 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
15575 "realm");
15576 return 0;
15577 }
15578
15579 val = get_param(cmd, "HOME_FQDN");
15580 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
15581 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
15582 "home_fqdn");
15583 return 0;
15584 }
15585
15586 val = get_param(cmd, "Username");
15587 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
15588 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
15589 "username");
15590 return 0;
15591 }
15592
15593 val = get_param(cmd, "clientCertificate");
15594 if (val) {
15595 char fname[200];
15596 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
15597#ifdef __linux__
15598 if (!file_exists(fname)) {
15599 char msg[300];
15600 snprintf(msg, sizeof(msg),
15601 "ErrorCode,clientCertificate "
15602 "file (%s) not found", fname);
15603 send_resp(dut, conn, SIGMA_ERROR, msg);
15604 return 0;
15605 }
15606#endif /* __linux__ */
15607 if (set_cred_quoted(ifname, id, "client_cert", fname) < 0) {
15608 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
15609 "not set client_cert");
15610 return 0;
15611 }
15612 if (set_cred_quoted(ifname, id, "private_key", fname) < 0) {
15613 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
15614 "not set private_key");
15615 return 0;
15616 }
15617 }
15618
15619 val = get_param(cmd, "ROOT_CA");
15620 if (val) {
15621 char fname[200];
15622 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
15623#ifdef __linux__
15624 if (!file_exists(fname)) {
15625 char msg[300];
15626 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
15627 "file (%s) not found", fname);
15628 send_resp(dut, conn, SIGMA_ERROR, msg);
15629 return 0;
15630 }
15631#endif /* __linux__ */
15632 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
15633 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
15634 "not set root CA");
15635 return 0;
15636 }
15637 }
15638
15639 return 1;
15640}
15641
15642
Jouni Malinenf7222712019-06-13 01:50:21 +030015643static enum sigma_cmd_result cmd_sta_add_credential(struct sigma_dut *dut,
15644 struct sigma_conn *conn,
15645 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015646{
15647 const char *intf = get_param(cmd, "Interface");
15648 const char *type;
15649
15650 start_sta_mode(dut);
15651
15652 type = get_param(cmd, "Type");
15653 if (!type)
15654 return -1;
15655
15656 if (strcasecmp(type, "uname_pwd") == 0)
15657 return sta_add_credential_uname_pwd(dut, conn, intf, cmd);
15658
15659 if (strcasecmp(type, "sim") == 0)
15660 return sta_add_credential_sim(dut, conn, intf, cmd);
15661
15662 if (strcasecmp(type, "cert") == 0)
15663 return sta_add_credential_cert(dut, conn, intf, cmd);
15664
15665 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported credential "
15666 "type");
15667 return 0;
15668}
15669
15670
Jouni Malinenf7222712019-06-13 01:50:21 +030015671static enum sigma_cmd_result cmd_sta_scan(struct sigma_dut *dut,
15672 struct sigma_conn *conn,
15673 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015674{
15675 const char *intf = get_param(cmd, "Interface");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080015676 const char *val, *bssid, *ssid, *scan_freq, *short_ssid;
Veerendranathdc581b52020-08-10 03:29:08 -070015677 char buf[4096], scan_res[20];
vamsi krishna89ad8c62017-09-19 12:51:18 +053015678 char ssid_hex[65];
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080015679 int wildcard_ssid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015680 int res;
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080015681 enum sigma_cmd_result status;
Jouni Malinen228a2fc2020-06-22 23:37:45 +030015682 struct wpa_ctrl *ctrl = NULL;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015683
Jouni Malinen8c1abeb2019-11-06 18:48:34 +020015684 start_sta_mode(dut);
15685
Arif Hussain66a4af02019-02-07 15:04:51 -080015686 val = get_param(cmd, "GetParameter");
15687 if (val && strcmp(val, "SSID_BSSID") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020015688 if (get_wpa_ssid_bssid(dut, get_station_ifname(dut),
Arif Hussain66a4af02019-02-07 15:04:51 -080015689 buf, sizeof(buf)) < 0) {
15690 sigma_dut_print(dut, DUT_MSG_ERROR,
15691 "Could not get ssid bssid");
15692 return ERROR_SEND_STATUS;
15693 }
15694
15695 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
15696 send_resp(dut, conn, SIGMA_COMPLETE, buf);
15697 return STATUS_SENT;
15698 }
15699
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015700 val = get_param(cmd, "HESSID");
15701 if (val) {
15702 res = snprintf(buf, sizeof(buf), "SET hessid %s", val);
15703 if (res < 0 || res >= (int) sizeof(buf))
15704 return -1;
15705 wpa_command(intf, buf);
15706 }
15707
15708 val = get_param(cmd, "ACCS_NET_TYPE");
15709 if (val) {
15710 res = snprintf(buf, sizeof(buf), "SET access_network_type %s",
15711 val);
15712 if (res < 0 || res >= (int) sizeof(buf))
15713 return -1;
15714 wpa_command(intf, buf);
15715 }
15716
Kiran Kumar Lokere69d89952021-08-08 23:41:46 -070015717 if (get_param(cmd, "RxMac"))
15718 sta_set_scan_unicast_probe(dut, intf, 1);
15719
vamsi krishna89ad8c62017-09-19 12:51:18 +053015720 bssid = get_param(cmd, "Bssid");
15721 ssid = get_param(cmd, "Ssid");
Kiran Kumar Lokere69d89952021-08-08 23:41:46 -070015722 if (!bssid)
15723 bssid = get_param(cmd, "RxMac");
vamsi krishna89ad8c62017-09-19 12:51:18 +053015724
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080015725 if (ssid && strcasecmp(ssid, "ZeroLength") == 0 &&
15726 dut->device_type == STA_testbed) {
15727 ssid = NULL;
15728 wildcard_ssid = 1;
15729 }
15730
vamsi krishna89ad8c62017-09-19 12:51:18 +053015731 if (ssid) {
15732 if (2 * strlen(ssid) >= sizeof(ssid_hex)) {
15733 send_resp(dut, conn, SIGMA_ERROR,
15734 "ErrorCode,Too long SSID");
15735 return 0;
15736 }
15737 ascii2hexstr(ssid, ssid_hex);
15738 }
15739
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080015740 short_ssid = get_param(cmd, "ShortSSID");
15741 if (short_ssid) {
15742 uint32_t short_ssid_hex;
15743
15744 short_ssid_hex = strtoul(short_ssid, NULL, 16);
15745 short_ssid_hex = ((short_ssid_hex & 0xFF) << 24) |
15746 (((short_ssid_hex >> 8) & 0xFF) << 16) |
15747 (((short_ssid_hex >> 16) & 0xFF) << 8) |
15748 ((short_ssid_hex >> 24) & 0xFF);
15749
15750 res = snprintf(buf, sizeof(buf),
15751 "VENDOR_ELEM_ADD 14 ff053a%08x",
15752 short_ssid_hex);
15753 if (res < 0 || res >= (int) sizeof(buf) ||
15754 wpa_command(intf, buf)) {
15755 send_resp(dut, conn, SIGMA_ERROR,
15756 "errorCode,Failed to add short SSID");
15757 return STATUS_SENT_ERROR;
15758 }
15759 }
15760
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080015761 scan_freq = get_param(cmd, "ChnlFreq");
Veerendranath Jakkam132c4b42020-08-10 00:29:03 +053015762 if (scan_freq) {
15763 if (strcasecmp(scan_freq, "2G") == 0)
15764 scan_freq = "2412-2462";
15765 else if (strcasecmp(scan_freq, "5G") == 0)
15766 scan_freq = "5180-5925";
15767 }
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080015768
Jouni Malinen228a2fc2020-06-22 23:37:45 +030015769 val = get_param(cmd, "WaitCompletion");
15770 if (val && atoi(val) == 1) {
15771 ctrl = open_wpa_mon(intf);
15772 if (!ctrl) {
15773 send_resp(dut, conn, SIGMA_ERROR,
15774 "errorCode,Failed to open monitor socket");
15775 return STATUS_SENT_ERROR;
15776 }
15777 }
15778
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080015779 res = snprintf(buf, sizeof(buf), "SCAN%s%s%s%s%s%s%s",
vamsi krishna89ad8c62017-09-19 12:51:18 +053015780 bssid ? " bssid=": "",
15781 bssid ? bssid : "",
15782 ssid ? " ssid " : "",
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080015783 ssid ? ssid_hex : "",
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080015784 wildcard_ssid ? " wildcard_ssid=1" : "",
15785 scan_freq ? " freq=" : "",
15786 scan_freq ? scan_freq : "");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080015787 if (res < 0 || res >= (int) sizeof(buf)) {
15788 send_resp(dut, conn, SIGMA_ERROR,
15789 "errorCode,Could not build scan command");
15790 status = STATUS_SENT_ERROR;
15791 goto remove_s_ssid;
15792 }
vamsi krishna89ad8c62017-09-19 12:51:18 +053015793
Veerendranathdc581b52020-08-10 03:29:08 -070015794 res = wpa_command_resp(intf, buf, scan_res, sizeof(scan_res));
15795 if (strncmp(scan_res, "FAIL-BUSY", 9) == 0) {
15796 sigma_dut_print(dut, DUT_MSG_DEBUG,
15797 "Scan request rejected with busy status, abort ongoing scan and try again");
15798 wpa_command(intf, "ABORT_SCAN");
15799 res = wpa_command(intf, buf);
15800 }
15801
15802 if (res < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015803 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not start "
15804 "scan");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080015805 status = STATUS_SENT_ERROR;
15806 } else {
15807 status = SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015808 }
15809
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080015810remove_s_ssid:
15811 if (short_ssid && wpa_command(intf, "VENDOR_ELEM_REMOVE 14 *"))
15812 sigma_dut_print(dut, DUT_MSG_ERROR,
15813 "Failed to delete vendor element");
15814
Jouni Malinen228a2fc2020-06-22 23:37:45 +030015815 if (ctrl) {
15816 if (status == SUCCESS_SEND_STATUS) {
15817 res = get_wpa_cli_event(dut, ctrl,
15818 "CTRL-EVENT-SCAN-RESULTS",
15819 buf, sizeof(buf));
15820 if (res < 0) {
15821 send_resp(dut, conn, SIGMA_ERROR,
15822 "ErrorCode,scan did not complete");
15823 status = STATUS_SENT_ERROR;
15824 }
15825 }
15826
15827 wpa_ctrl_detach(ctrl);
15828 wpa_ctrl_close(ctrl);
15829 }
15830
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080015831 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015832}
15833
15834
Jouni Malinenf7222712019-06-13 01:50:21 +030015835static enum sigma_cmd_result cmd_sta_scan_bss(struct sigma_dut *dut,
15836 struct sigma_conn *conn,
15837 struct sigma_cmd *cmd)
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020015838{
15839 const char *intf = get_param(cmd, "Interface");
15840 const char *bssid;
15841 char buf[4096], *pos;
15842 int freq, chan;
15843 char *ssid;
15844 char resp[100];
15845 int res;
15846 struct wpa_ctrl *ctrl;
15847
15848 bssid = get_param(cmd, "BSSID");
15849 if (!bssid) {
15850 send_resp(dut, conn, SIGMA_INVALID,
15851 "errorCode,BSSID argument is missing");
15852 return 0;
15853 }
15854
15855 ctrl = open_wpa_mon(intf);
15856 if (!ctrl) {
15857 sigma_dut_print(dut, DUT_MSG_ERROR,
15858 "Failed to open wpa_supplicant monitor connection");
15859 return -1;
15860 }
15861
15862 if (wpa_command(intf, "SCAN TYPE=ONLY")) {
15863 send_resp(dut, conn, SIGMA_ERROR,
15864 "errorCode,Could not start scan");
15865 wpa_ctrl_detach(ctrl);
15866 wpa_ctrl_close(ctrl);
15867 return 0;
15868 }
15869
15870 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
15871 buf, sizeof(buf));
15872
15873 wpa_ctrl_detach(ctrl);
15874 wpa_ctrl_close(ctrl);
15875
15876 if (res < 0) {
15877 send_resp(dut, conn, SIGMA_ERROR,
15878 "errorCode,Scan did not complete");
15879 return 0;
15880 }
15881
15882 snprintf(buf, sizeof(buf), "BSS %s", bssid);
15883 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
15884 strncmp(buf, "id=", 3) != 0) {
15885 send_resp(dut, conn, SIGMA_ERROR,
15886 "errorCode,Specified BSSID not found");
15887 return 0;
15888 }
15889
15890 pos = strstr(buf, "\nfreq=");
15891 if (!pos) {
15892 send_resp(dut, conn, SIGMA_ERROR,
15893 "errorCode,Channel not found");
15894 return 0;
15895 }
15896 freq = atoi(pos + 6);
15897 chan = freq_to_channel(freq);
15898
15899 pos = strstr(buf, "\nssid=");
15900 if (!pos) {
15901 send_resp(dut, conn, SIGMA_ERROR,
15902 "errorCode,SSID not found");
15903 return 0;
15904 }
15905 ssid = pos + 6;
15906 pos = strchr(ssid, '\n');
15907 if (pos)
15908 *pos = '\0';
15909 snprintf(resp, sizeof(resp), "ssid,%s,bsschannel,%d", ssid, chan);
15910 send_resp(dut, conn, SIGMA_COMPLETE, resp);
15911 return 0;
15912}
15913
15914
Jouni Malinenf7222712019-06-13 01:50:21 +030015915static enum sigma_cmd_result cmd_sta_set_systime(struct sigma_dut *dut,
15916 struct sigma_conn *conn,
15917 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015918{
15919#ifdef __linux__
15920 struct timeval tv;
15921 struct tm tm;
15922 time_t t;
15923 const char *val;
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053015924 int v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015925
Jouni Malinen016ae6c2019-11-04 17:00:01 +020015926 wpa_command(get_station_ifname(dut), "PMKSA_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015927
15928 memset(&tm, 0, sizeof(tm));
15929 val = get_param(cmd, "seconds");
15930 if (val)
15931 tm.tm_sec = atoi(val);
15932 val = get_param(cmd, "minutes");
15933 if (val)
15934 tm.tm_min = atoi(val);
15935 val = get_param(cmd, "hours");
15936 if (val)
15937 tm.tm_hour = atoi(val);
15938 val = get_param(cmd, "date");
15939 if (val)
15940 tm.tm_mday = atoi(val);
15941 val = get_param(cmd, "month");
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053015942 if (val) {
15943 v = atoi(val);
15944 if (v < 1 || v > 12) {
15945 send_resp(dut, conn, SIGMA_INVALID,
15946 "errorCode,Invalid month");
15947 return 0;
15948 }
15949 tm.tm_mon = v - 1;
15950 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015951 val = get_param(cmd, "year");
15952 if (val) {
15953 int year = atoi(val);
15954#ifdef ANDROID
15955 if (year > 2035)
15956 year = 2035; /* years beyond 2035 not supported */
15957#endif /* ANDROID */
15958 tm.tm_year = year - 1900;
15959 }
15960 t = mktime(&tm);
15961 if (t == (time_t) -1) {
15962 send_resp(dut, conn, SIGMA_ERROR,
15963 "errorCode,Invalid date or time");
15964 return 0;
15965 }
15966
15967 memset(&tv, 0, sizeof(tv));
15968 tv.tv_sec = t;
15969
15970 if (settimeofday(&tv, NULL) < 0) {
15971 sigma_dut_print(dut, DUT_MSG_INFO, "settimeofday failed: %s",
15972 strerror(errno));
15973 send_resp(dut, conn, SIGMA_ERROR,
15974 "errorCode,Failed to set time");
15975 return 0;
15976 }
15977
15978 return 1;
15979#endif /* __linux__ */
15980
15981 return -1;
15982}
15983
15984
Jouni Malinenf7222712019-06-13 01:50:21 +030015985static enum sigma_cmd_result cmd_sta_osu(struct sigma_dut *dut,
15986 struct sigma_conn *conn,
15987 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015988{
15989 const char *intf = get_param(cmd, "Interface");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030015990 const char *name, *osu_ssid, *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015991 int prod_ess_assoc = 1;
Jouni Malinen4c8681c2018-09-12 23:28:11 +030015992 char buf[300], bssid[100], ssid[100];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015993 int res;
15994 struct wpa_ctrl *ctrl;
15995
15996 name = get_param(cmd, "osuFriendlyName");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030015997 osu_ssid = get_param(cmd, "osu_ssid");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015998
15999 val = get_param(cmd, "ProdESSAssoc");
16000 if (val)
16001 prod_ess_assoc = atoi(val);
16002
16003 kill_dhcp_client(dut, intf);
16004 if (start_dhcp_client(dut, intf) < 0)
16005 return -2;
16006
16007 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger OSU");
16008 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
16009 res = snprintf(buf, sizeof(buf),
Jouni Malinen4c8681c2018-09-12 23:28:11 +030016010 "%s %s%s%s %s%s%s signup osu-ca.pem",
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016011 prod_ess_assoc ? "" : "-N",
16012 name ? "-O'" : "", name ? name : "",
Jouni Malinen4c8681c2018-09-12 23:28:11 +030016013 name ? "'" : "",
16014 osu_ssid ? "-o'" : "", osu_ssid ? osu_ssid : "",
16015 osu_ssid ? "'" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016016
Kanchanapally, Vidyullatha12b66762015-12-31 16:46:42 +053016017 hs2_set_policy(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016018 if (run_hs20_osu(dut, buf) < 0) {
16019 FILE *f;
16020
16021 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to complete OSU");
16022
16023 f = fopen("hs20-osu-client.res", "r");
16024 if (f) {
16025 char resp[400], res[300], *pos;
16026 if (!fgets(res, sizeof(res), f))
16027 res[0] = '\0';
16028 pos = strchr(res, '\n');
16029 if (pos)
16030 *pos = '\0';
16031 fclose(f);
16032 sigma_dut_summary(dut, "hs20-osu-client provisioning failed: %s",
16033 res);
16034 snprintf(resp, sizeof(resp), "notify-send '%s'", res);
16035 if (system(resp) != 0) {
16036 }
16037 snprintf(resp, sizeof(resp),
16038 "SSID,,BSSID,,failureReason,%s", res);
16039 send_resp(dut, conn, SIGMA_COMPLETE, resp);
16040 return 0;
16041 }
16042
16043 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
16044 return 0;
16045 }
16046
16047 if (!prod_ess_assoc)
16048 goto report;
16049
16050 ctrl = open_wpa_mon(intf);
16051 if (ctrl == NULL) {
16052 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
16053 "wpa_supplicant monitor connection");
16054 return -1;
16055 }
16056
16057 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
16058 buf, sizeof(buf));
16059
16060 wpa_ctrl_detach(ctrl);
16061 wpa_ctrl_close(ctrl);
16062
16063 if (res < 0) {
16064 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to connect to "
16065 "network after OSU");
16066 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
16067 return 0;
16068 }
16069
16070report:
16071 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
16072 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
16073 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get BSSID/SSID");
16074 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
16075 return 0;
16076 }
16077
16078 snprintf(buf, sizeof(buf), "SSID,%s,BSSID,%s", ssid, bssid);
16079 send_resp(dut, conn, SIGMA_COMPLETE, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016080 return 0;
16081}
16082
16083
Jouni Malinenf7222712019-06-13 01:50:21 +030016084static enum sigma_cmd_result cmd_sta_policy_update(struct sigma_dut *dut,
16085 struct sigma_conn *conn,
16086 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016087{
16088 const char *val;
16089 int timeout = 120;
16090
16091 val = get_param(cmd, "PolicyUpdate");
16092 if (val == NULL || atoi(val) == 0)
16093 return 1; /* No operation requested */
16094
16095 val = get_param(cmd, "Timeout");
16096 if (val)
16097 timeout = atoi(val);
16098
16099 if (timeout) {
16100 /* TODO: time out the command and return
16101 * PolicyUpdateStatus,TIMEOUT if needed. */
16102 }
16103
16104 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger policy update");
16105 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
16106 if (run_hs20_osu(dut, "pol_upd fqdn=wi-fi.org") < 0) {
16107 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,FAIL");
16108 return 0;
16109 }
16110
16111 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,SUCCESS");
16112 return 0;
16113}
16114
16115
Jouni Malinenf7222712019-06-13 01:50:21 +030016116static enum sigma_cmd_result cmd_sta_er_config(struct sigma_dut *dut,
16117 struct sigma_conn *conn,
16118 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016119{
16120 struct wpa_ctrl *ctrl;
16121 const char *intf = get_param(cmd, "Interface");
16122 const char *bssid = get_param(cmd, "Bssid");
16123 const char *ssid = get_param(cmd, "SSID");
16124 const char *security = get_param(cmd, "Security");
16125 const char *passphrase = get_param(cmd, "Passphrase");
16126 const char *pin = get_param(cmd, "PIN");
16127 char buf[1000];
16128 char ssid_hex[200], passphrase_hex[200];
16129 const char *keymgmt, *cipher;
16130
16131 if (intf == NULL)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020016132 intf = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016133
16134 if (!bssid) {
16135 send_resp(dut, conn, SIGMA_ERROR,
16136 "ErrorCode,Missing Bssid argument");
16137 return 0;
16138 }
16139
16140 if (!ssid) {
16141 send_resp(dut, conn, SIGMA_ERROR,
16142 "ErrorCode,Missing SSID argument");
16143 return 0;
16144 }
16145
16146 if (!security) {
16147 send_resp(dut, conn, SIGMA_ERROR,
16148 "ErrorCode,Missing Security argument");
16149 return 0;
16150 }
16151
16152 if (!passphrase) {
16153 send_resp(dut, conn, SIGMA_ERROR,
16154 "ErrorCode,Missing Passphrase argument");
16155 return 0;
16156 }
16157
16158 if (!pin) {
16159 send_resp(dut, conn, SIGMA_ERROR,
16160 "ErrorCode,Missing PIN argument");
16161 return 0;
16162 }
16163
vamsi krishna8c9c1562017-05-12 15:51:46 +053016164 if (2 * strlen(ssid) >= sizeof(ssid_hex) ||
16165 2 * strlen(passphrase) >= sizeof(passphrase_hex)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016166 send_resp(dut, conn, SIGMA_ERROR,
16167 "ErrorCode,Too long SSID/passphrase");
16168 return 0;
16169 }
16170
16171 ctrl = open_wpa_mon(intf);
16172 if (ctrl == NULL) {
16173 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
16174 "wpa_supplicant monitor connection");
16175 return -2;
16176 }
16177
16178 if (strcasecmp(security, "wpa2-psk") == 0) {
16179 keymgmt = "WPA2PSK";
16180 cipher = "CCMP";
16181 } else {
16182 wpa_ctrl_detach(ctrl);
16183 wpa_ctrl_close(ctrl);
16184 send_resp(dut, conn, SIGMA_ERROR,
16185 "ErrorCode,Unsupported Security value");
16186 return 0;
16187 }
16188
16189 ascii2hexstr(ssid, ssid_hex);
16190 ascii2hexstr(passphrase, passphrase_hex);
16191 snprintf(buf, sizeof(buf), "WPS_REG %s %s %s %s %s %s",
16192 bssid, pin, ssid_hex, keymgmt, cipher, passphrase_hex);
16193
16194 if (wpa_command(intf, buf) < 0) {
16195 wpa_ctrl_detach(ctrl);
16196 wpa_ctrl_close(ctrl);
16197 send_resp(dut, conn, SIGMA_ERROR,
16198 "ErrorCode,Failed to start registrar");
16199 return 0;
16200 }
16201
16202 snprintf(dut->er_oper_bssid, sizeof(dut->er_oper_bssid), "%s", bssid);
16203 dut->er_oper_performed = 1;
16204
16205 return wps_connection_event(dut, conn, ctrl, intf, 0);
16206}
16207
16208
Jouni Malinenf7222712019-06-13 01:50:21 +030016209static enum sigma_cmd_result
16210cmd_sta_wps_connect_pw_token(struct sigma_dut *dut, struct sigma_conn *conn,
16211 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016212{
16213 struct wpa_ctrl *ctrl;
16214 const char *intf = get_param(cmd, "Interface");
16215 const char *bssid = get_param(cmd, "Bssid");
16216 char buf[100];
16217
16218 if (!bssid) {
16219 send_resp(dut, conn, SIGMA_ERROR,
16220 "ErrorCode,Missing Bssid argument");
16221 return 0;
16222 }
16223
16224 ctrl = open_wpa_mon(intf);
16225 if (ctrl == NULL) {
16226 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
16227 "wpa_supplicant monitor connection");
16228 return -2;
16229 }
16230
16231 snprintf(buf, sizeof(buf), "WPS_NFC %s", bssid);
16232
16233 if (wpa_command(intf, buf) < 0) {
16234 wpa_ctrl_detach(ctrl);
16235 wpa_ctrl_close(ctrl);
16236 send_resp(dut, conn, SIGMA_ERROR,
16237 "ErrorCode,Failed to start registrar");
16238 return 0;
16239 }
16240
16241 return wps_connection_event(dut, conn, ctrl, intf, 0);
16242}
16243
16244
Jouni Malinenf7222712019-06-13 01:50:21 +030016245static enum sigma_cmd_result cmd_start_wps_registration(struct sigma_dut *dut,
16246 struct sigma_conn *conn,
16247 struct sigma_cmd *cmd)
vamsi krishna9b144002017-09-20 13:28:13 +053016248{
16249 struct wpa_ctrl *ctrl;
16250 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020016251 const char *network_mode = get_param(cmd, "network_mode");
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020016252 const char *config_method = get_param(cmd, "WPSConfigMethod");
16253 const char *role;
vamsi krishna9b144002017-09-20 13:28:13 +053016254 int res;
16255 char buf[256];
16256 const char *events[] = {
16257 "CTRL-EVENT-CONNECTED",
16258 "WPS-OVERLAP-DETECTED",
16259 "WPS-TIMEOUT",
16260 "WPS-FAIL",
16261 NULL
16262 };
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020016263 int id = 0;
vamsi krishna9b144002017-09-20 13:28:13 +053016264
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020016265 /* 60G WPS tests do not pass Interface parameter */
16266 if (!intf)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020016267 intf = get_main_ifname(dut);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020016268
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020016269 if (dut->mode == SIGMA_MODE_AP)
16270 return ap_wps_registration(dut, conn, cmd);
16271
16272 if (config_method) {
16273 /* WFA_CS_WPS_PIN_KEYPAD mode is set when using the
16274 * sta_wps_enter_pin before calling start_wps_registration. */
16275 if (strcasecmp(config_method, "PBC") == 0)
16276 dut->wps_method = WFA_CS_WPS_PBC;
16277 }
16278 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
16279 send_resp(dut, conn, SIGMA_ERROR,
16280 "ErrorCode,WPS parameters not yet set");
16281 return STATUS_SENT;
16282 }
16283
16284 /* Make sure WPS is enabled (also for STA mode) */
16285 dut->wps_disable = 0;
16286
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020016287 if (dut->band == WPS_BAND_60G && network_mode &&
16288 strcasecmp(network_mode, "PBSS") == 0) {
16289 sigma_dut_print(dut, DUT_MSG_DEBUG,
16290 "Set PBSS network mode, network id %d", id);
Jouni Malinen016ae6c2019-11-04 17:00:01 +020016291 if (set_network(get_station_ifname(dut), id, "pbss", "1") < 0)
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020016292 return -2;
16293 }
16294
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020016295 if (dut->force_rsn_ie) {
16296 sigma_dut_print(dut, DUT_MSG_DEBUG, "Force RSN_IE: %d",
16297 dut->force_rsn_ie);
16298 if (sta_60g_force_rsn_ie(dut, dut->force_rsn_ie) < 0) {
16299 sigma_dut_print(dut, DUT_MSG_INFO,
16300 "Failed to force RSN_IE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020016301 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020016302 }
16303 }
16304
vamsi krishna9b144002017-09-20 13:28:13 +053016305 ctrl = open_wpa_mon(intf);
16306 if (!ctrl) {
16307 sigma_dut_print(dut, DUT_MSG_ERROR,
16308 "Failed to open wpa_supplicant monitor connection");
16309 return -2;
16310 }
16311
16312 role = get_param(cmd, "WpsRole");
16313 if (!role) {
16314 send_resp(dut, conn, SIGMA_INVALID,
16315 "ErrorCode,WpsRole not provided");
16316 goto fail;
16317 }
16318
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020016319 if (strcasecmp(role, "Enrollee") != 0) {
16320 /* Registrar role for STA not supported */
16321 send_resp(dut, conn, SIGMA_ERROR,
16322 "ErrorCode,Unsupported WpsRole value");
16323 goto fail;
16324 }
16325
16326 if (is_60g_sigma_dut(dut)) {
16327 if (dut->wps_method == WFA_CS_WPS_PBC)
16328 snprintf(buf, sizeof(buf), "WPS_PBC");
16329 else /* WFA_CS_WPS_PIN_KEYPAD */
16330 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
16331 dut->wps_pin);
16332 if (wpa_command(intf, buf) < 0) {
16333 send_resp(dut, conn, SIGMA_ERROR,
16334 "ErrorCode,Failed to start WPS");
vamsi krishna9b144002017-09-20 13:28:13 +053016335 goto fail;
16336 }
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020016337 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
16338 if (res < 0) {
16339 send_resp(dut, conn, SIGMA_ERROR,
16340 "ErrorCode,WPS connection did not complete");
16341 goto fail;
16342 }
16343 if (strstr(buf, "WPS-TIMEOUT")) {
16344 send_resp(dut, conn, SIGMA_COMPLETE, "WpsState,NoPeer");
16345 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
16346 send_resp(dut, conn, SIGMA_COMPLETE,
16347 "WpsState,OverlapSession");
16348 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
16349 send_resp(dut, conn, SIGMA_COMPLETE,
16350 "WpsState,Successful");
16351 } else {
16352 send_resp(dut, conn, SIGMA_COMPLETE,
16353 "WpsState,Failure");
16354 }
16355 } else {
16356 if (dut->wps_method == WFA_CS_WPS_PBC) {
vamsi krishna9b144002017-09-20 13:28:13 +053016357 if (wpa_command(intf, "WPS_PBC") < 0) {
16358 send_resp(dut, conn, SIGMA_ERROR,
16359 "ErrorCode,Failed to enable PBC");
16360 goto fail;
16361 }
16362 } else {
16363 /* TODO: PIN method */
16364 send_resp(dut, conn, SIGMA_ERROR,
16365 "ErrorCode,Unsupported WpsConfigMethod value");
16366 goto fail;
16367 }
16368 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
16369 if (res < 0) {
16370 send_resp(dut, conn, SIGMA_ERROR,
16371 "ErrorCode,WPS connection did not complete");
16372 goto fail;
16373 }
16374 if (strstr(buf, "WPS-TIMEOUT")) {
16375 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,NoPeer");
16376 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
16377 send_resp(dut, conn, SIGMA_ERROR,
16378 "ErrorCode,OverlapSession");
16379 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
16380 send_resp(dut, conn, SIGMA_COMPLETE, "Successful");
16381 } else {
16382 send_resp(dut, conn, SIGMA_ERROR,
16383 "ErrorCode,WPS operation failed");
16384 }
vamsi krishna9b144002017-09-20 13:28:13 +053016385 }
16386
16387fail:
16388 wpa_ctrl_detach(ctrl);
16389 wpa_ctrl_close(ctrl);
16390 return 0;
16391}
16392
16393
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016394static int req_intf(struct sigma_cmd *cmd)
16395{
16396 return get_param(cmd, "interface") == NULL ? -1 : 0;
16397}
16398
16399
16400void sta_register_cmds(void)
16401{
16402 sigma_dut_reg_cmd("sta_get_ip_config", req_intf,
16403 cmd_sta_get_ip_config);
16404 sigma_dut_reg_cmd("sta_set_ip_config", req_intf,
16405 cmd_sta_set_ip_config);
16406 sigma_dut_reg_cmd("sta_get_info", req_intf, cmd_sta_get_info);
16407 sigma_dut_reg_cmd("sta_get_mac_address", req_intf,
16408 cmd_sta_get_mac_address);
16409 sigma_dut_reg_cmd("sta_is_connected", req_intf, cmd_sta_is_connected);
16410 sigma_dut_reg_cmd("sta_verify_ip_connection", req_intf,
16411 cmd_sta_verify_ip_connection);
16412 sigma_dut_reg_cmd("sta_get_bssid", req_intf, cmd_sta_get_bssid);
16413 sigma_dut_reg_cmd("sta_set_encryption", req_intf,
16414 cmd_sta_set_encryption);
16415 sigma_dut_reg_cmd("sta_set_psk", req_intf, cmd_sta_set_psk);
16416 sigma_dut_reg_cmd("sta_set_eaptls", req_intf, cmd_sta_set_eaptls);
16417 sigma_dut_reg_cmd("sta_set_eapttls", req_intf, cmd_sta_set_eapttls);
16418 sigma_dut_reg_cmd("sta_set_eapsim", req_intf, cmd_sta_set_eapsim);
16419 sigma_dut_reg_cmd("sta_set_peap", req_intf, cmd_sta_set_peap);
16420 sigma_dut_reg_cmd("sta_set_eapfast", req_intf, cmd_sta_set_eapfast);
16421 sigma_dut_reg_cmd("sta_set_eapaka", req_intf, cmd_sta_set_eapaka);
16422 sigma_dut_reg_cmd("sta_set_eapakaprime", req_intf,
16423 cmd_sta_set_eapakaprime);
16424 sigma_dut_reg_cmd("sta_set_security", req_intf, cmd_sta_set_security);
16425 sigma_dut_reg_cmd("sta_set_uapsd", req_intf, cmd_sta_set_uapsd);
16426 /* TODO: sta_set_ibss */
16427 /* TODO: sta_set_mode */
16428 sigma_dut_reg_cmd("sta_set_wmm", req_intf, cmd_sta_set_wmm);
16429 sigma_dut_reg_cmd("sta_associate", req_intf, cmd_sta_associate);
16430 /* TODO: sta_up_load */
16431 sigma_dut_reg_cmd("sta_preset_testparameters", req_intf,
16432 cmd_sta_preset_testparameters);
16433 /* TODO: sta_set_system */
16434 sigma_dut_reg_cmd("sta_set_11n", req_intf, cmd_sta_set_11n);
16435 /* TODO: sta_set_rifs_test */
16436 sigma_dut_reg_cmd("sta_set_wireless", req_intf, cmd_sta_set_wireless);
16437 sigma_dut_reg_cmd("sta_send_addba", req_intf, cmd_sta_send_addba);
16438 /* TODO: sta_send_coexist_mgmt */
16439 sigma_dut_reg_cmd("sta_disconnect", req_intf, cmd_sta_disconnect);
16440 sigma_dut_reg_cmd("sta_reassoc", req_intf, cmd_sta_reassoc);
16441 sigma_dut_reg_cmd("sta_reassociate", req_intf, cmd_sta_reassoc);
16442 sigma_dut_reg_cmd("sta_reset_default", req_intf,
16443 cmd_sta_reset_default);
16444 sigma_dut_reg_cmd("sta_send_frame", req_intf, cmd_sta_send_frame);
16445 sigma_dut_reg_cmd("sta_set_macaddr", req_intf, cmd_sta_set_macaddr);
16446 sigma_dut_reg_cmd("sta_set_rfeature", req_intf, cmd_sta_set_rfeature);
16447 sigma_dut_reg_cmd("sta_set_radio", req_intf, cmd_sta_set_radio);
16448 sigma_dut_reg_cmd("sta_set_pwrsave", req_intf, cmd_sta_set_pwrsave);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020016449 sigma_dut_reg_cmd("sta_set_power_save", req_intf, cmd_sta_set_pwrsave);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016450 sigma_dut_reg_cmd("sta_bssid_pool", req_intf, cmd_sta_bssid_pool);
16451 sigma_dut_reg_cmd("sta_reset_parm", req_intf, cmd_sta_reset_parm);
16452 sigma_dut_reg_cmd("sta_get_key", req_intf, cmd_sta_get_key);
16453 sigma_dut_reg_cmd("sta_hs2_associate", req_intf,
16454 cmd_sta_hs2_associate);
Jouni Malinenb639f1c2018-09-13 02:39:46 +030016455 sigma_dut_reg_cmd("sta_hs2_venue_info", req_intf,
16456 cmd_sta_hs2_venue_info);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016457 sigma_dut_reg_cmd("sta_add_credential", req_intf,
16458 cmd_sta_add_credential);
16459 sigma_dut_reg_cmd("sta_scan", req_intf, cmd_sta_scan);
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020016460 sigma_dut_reg_cmd("sta_scan_bss", req_intf, cmd_sta_scan_bss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016461 sigma_dut_reg_cmd("sta_set_systime", NULL, cmd_sta_set_systime);
16462 sigma_dut_reg_cmd("sta_osu", req_intf, cmd_sta_osu);
16463 sigma_dut_reg_cmd("sta_policy_update", req_intf, cmd_sta_policy_update);
16464 sigma_dut_reg_cmd("sta_er_config", NULL, cmd_sta_er_config);
16465 sigma_dut_reg_cmd("sta_wps_connect_pw_token", req_intf,
16466 cmd_sta_wps_connect_pw_token);
Jouni Malinen82905202018-04-29 17:20:10 +030016467 sigma_dut_reg_cmd("sta_exec_action", NULL, cmd_sta_exec_action);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016468 sigma_dut_reg_cmd("sta_get_events", req_intf, cmd_sta_get_events);
16469 sigma_dut_reg_cmd("sta_get_parameter", req_intf, cmd_sta_get_parameter);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020016470 sigma_dut_reg_cmd("start_wps_registration", NULL,
vamsi krishna9b144002017-09-20 13:28:13 +053016471 cmd_start_wps_registration);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016472}