blob: 29407571d8db920f27cff1b87b92e260632fc725 [file] [log] [blame]
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001/*
2 * Sigma Control API DUT (station/AP)
3 * Copyright (c) 2010-2011, Atheros Communications, Inc.
Jouni Malinen9d7e31d2017-12-22 18:55:04 +02004 * Copyright (c) 2011-2017, Qualcomm Atheros, Inc.
Jouni Malinen2feb9132021-11-16 00:53:06 +02005 * Copyright (c) 2018-2021, The Linux Foundation
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006 * All Rights Reserved.
7 * Licensed under the Clear BSD license. See README for more details.
8 */
9
10#include "sigma_dut.h"
11#include <sys/ioctl.h>
12#include <sys/stat.h>
Jouni Malinen82905202018-04-29 17:20:10 +030013#include <sys/wait.h>
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030014#include <ctype.h>
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015#ifdef __linux__
Lior Davidcc88b562017-01-03 18:52:09 +020016#include <regex.h>
17#include <dirent.h>
Jouni Malinencd4e3c32015-10-29 12:39:56 +020018#include <sys/time.h>
19#include <netpacket/packet.h>
20#include <linux/if_ether.h>
21#ifdef ANDROID
22#include <cutils/properties.h>
23#include <android/log.h>
24#include "keystore_get.h"
25#else /* ANDROID */
26#include <ifaddrs.h>
27#endif /* ANDROID */
28#include <netdb.h>
29#endif /* __linux__ */
30#ifdef __QNXNTO__
31#include <net/if_dl.h>
32#endif /* __QNXNTO__ */
33#include "wpa_ctrl.h"
34#include "wpa_helpers.h"
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -070035#include "miracast.h"
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -070036#include "qca-vendor_copy.h"
Jouni Malinencd4e3c32015-10-29 12:39:56 +020037
38/* Temporary files for sta_send_addba */
39#define VI_QOS_TMP_FILE "/tmp/vi-qos.tmp"
40#define VI_QOS_FILE "/tmp/vi-qos.txt"
41#define VI_QOS_REFFILE "/etc/vi-qos.txt"
42
43/*
44 * MTU for Ethernet need to take into account 8-byte SNAP header
45 * to be added when encapsulating Ethernet frame into 802.11
46 */
47#ifndef IEEE80211_MAX_DATA_LEN_DMG
48#define IEEE80211_MAX_DATA_LEN_DMG 7920
49#endif
50#ifndef IEEE80211_SNAP_LEN_DMG
51#define IEEE80211_SNAP_LEN_DMG 8
52#endif
53
Ashwini Patil00402582017-04-13 12:29:39 +053054#define NON_PREF_CH_LIST_SIZE 100
Ashwini Patil5acd7382017-04-13 15:55:04 +053055#define NEIGHBOR_REPORT_SIZE 1000
56#define DEFAULT_NEIGHBOR_BSSID_INFO "17"
57#define DEFAULT_NEIGHBOR_PHY_TYPE "1"
Ashwini Patil00402582017-04-13 12:29:39 +053058
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030059#define WIL_DEFAULT_BI 100
60
61/* default remain on channel time for transmitting frames (milliseconds) */
62#define WIL_TRANSMIT_FRAME_DEFAULT_ROC 500
63#define IEEE80211_P2P_ATTR_DEVICE_ID 3
64#define IEEE80211_P2P_ATTR_GROUP_ID 15
65
66/* describes tagged bytes in template frame file */
67struct template_frame_tag {
68 int num;
69 int offset;
70 size_t len;
71};
72
Jouni Malinencd4e3c32015-10-29 12:39:56 +020073extern char *sigma_wpas_ctrl;
74extern char *sigma_cert_path;
75extern enum driver_type wifi_chip_type;
76extern char *sigma_radio_ifname[];
77
Lior David0fe101e2017-03-09 16:09:50 +020078#ifdef __linux__
79#define WIL_WMI_MAX_PAYLOAD 248
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020080#define WIL_WMI_ESE_CFG_CMDID 0xa01
Lior David0fe101e2017-03-09 16:09:50 +020081#define WIL_WMI_BF_TRIG_CMDID 0x83a
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020082#define WIL_WMI_UNIT_TEST_CMDID 0x900
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030083#define WIL_WMI_P2P_CFG_CMDID 0x910
84#define WIL_WMI_START_LISTEN_CMDID 0x914
85#define WIL_WMI_DISCOVERY_STOP_CMDID 0x917
Lior David0fe101e2017-03-09 16:09:50 +020086
87struct wil_wmi_header {
88 uint8_t mid;
89 uint8_t reserved;
90 uint16_t cmd;
91 uint32_t ts;
92} __attribute__((packed));
93
94enum wil_wmi_bf_trig_type {
95 WIL_WMI_SLS,
96 WIL_WMI_BRP_RX,
97 WIL_WMI_BRP_TX,
98};
99
100struct wil_wmi_bf_trig_cmd {
101 /* enum wil_wmi_bf_trig_type */
102 uint32_t bf_type;
103 /* cid when type == WMI_BRP_RX */
104 uint32_t sta_id;
105 uint32_t reserved;
106 /* mac address when type = WIL_WMI_SLS */
107 uint8_t dest_mac[6];
108} __attribute__((packed));
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +0200109
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +0200110enum wil_wmi_sched_scheme_advertisment {
111 WIL_WMI_ADVERTISE_ESE_DISABLED,
112 WIL_WMI_ADVERTISE_ESE_IN_BEACON,
113 WIL_WMI_ADVERTISE_ESE_IN_ANNOUNCE_FRAME,
114};
115
116enum wil_wmi_ese_slot_type {
117 WIL_WMI_ESE_SP,
118 WIL_WMI_ESE_CBAP,
119 WIL_WMI_ESE_ANNOUNCE_NO_ACK,
120};
121
122struct wil_wmi_ese_slot {
123 /* offset from start of BI in microseconds */
124 uint32_t tbtt_offset;
125 uint8_t flags;
126 /* enum wil_wmi_ese_slot_type */
127 uint8_t slot_type;
128 /* duration in microseconds */
129 uint16_t duration;
130 /* frame exchange sequence duration, microseconds */
131 uint16_t tx_op;
132 /* time between 2 blocks for periodic allocation(microseconds) */
133 uint16_t period;
134 /* number of blocks in periodic allocation */
135 uint8_t num_blocks;
136 /* for semi-active allocations */
137 uint8_t idle_period;
138 uint8_t src_aid;
139 uint8_t dst_aid;
140 uint32_t reserved;
141} __attribute__((packed));
142
143#define WIL_WMI_MAX_ESE_SLOTS 4
144struct wil_wmi_ese_cfg {
145 uint8_t serial_num;
146 /* wil_wmi_sched_scheme_advertisment */
147 uint8_t ese_advertisment;
148 uint16_t flags;
149 uint8_t num_allocs;
150 uint8_t reserved[3];
151 uint64_t start_tbtt;
152 /* allocations list */
153 struct wil_wmi_ese_slot slots[WIL_WMI_MAX_ESE_SLOTS];
154} __attribute__((packed));
155
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +0200156#define WIL_WMI_UT_FORCE_MCS 6
157struct wil_wmi_force_mcs {
158 /* WIL_WMI_UT_HW_SYSAPI */
159 uint16_t module_id;
160 /* WIL_WMI_UT_FORCE_MCS */
161 uint16_t subtype_id;
162 /* cid (ignored in oob_mode, affects all stations) */
163 uint32_t cid;
164 /* 1 to force MCS, 0 to restore default behavior */
165 uint32_t force_enable;
166 /* MCS index, 0-12 */
167 uint32_t mcs;
168} __attribute__((packed));
169
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +0200170#define WIL_WMI_UT_HW_SYSAPI 10
171#define WIL_WMI_UT_FORCE_RSN_IE 0x29
172struct wil_wmi_force_rsn_ie {
173 /* WIL_WMI_UT_HW_SYSAPI */
174 uint16_t module_id;
175 /* WIL_WMI_UT_FORCE_RSN_IE */
176 uint16_t subtype_id;
177 /* 0 = no change, 1 = remove if exists, 2 = add if does not exist */
178 uint32_t state;
179} __attribute__((packed));
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +0300180
181enum wil_wmi_discovery_mode {
182 WMI_DISCOVERY_MODE_NON_OFFLOAD,
183 WMI_DISCOVERY_MODE_OFFLOAD,
184 WMI_DISCOVERY_MODE_PEER2PEER,
185};
186
187struct wil_wmi_p2p_cfg_cmd {
188 /* enum wil_wmi_discovery_mode */
189 uint8_t discovery_mode;
190 /* 0-based (wireless channel - 1) */
191 uint8_t channel;
192 /* set to WIL_DEFAULT_BI */
193 uint16_t bcon_interval;
194} __attribute__((packed));
Lior David0fe101e2017-03-09 16:09:50 +0200195#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200196
197#ifdef ANDROID
198
199static int add_ipv6_rule(struct sigma_dut *dut, const char *ifname);
200
201#define ANDROID_KEYSTORE_GET 'g'
202#define ANDROID_KEYSTORE_GET_PUBKEY 'b'
203
204static int android_keystore_get(char cmd, const char *key, unsigned char *val)
205{
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200206 /* Android 4.3 changed keystore design, so need to use keystore_get() */
207#ifndef KEYSTORE_MESSAGE_SIZE
208#define KEYSTORE_MESSAGE_SIZE 65535
209#endif /* KEYSTORE_MESSAGE_SIZE */
210
211 ssize_t len;
212 uint8_t *value = NULL;
213
214 __android_log_print(ANDROID_LOG_DEBUG, "sigma_dut",
215 "keystore command '%c' key '%s' --> keystore_get",
216 cmd, key);
217
218 len = keystore_get(key, strlen(key), &value);
219 if (len < 0) {
220 __android_log_print(ANDROID_LOG_DEBUG, "sigma_dut",
221 "keystore_get() failed");
222 return -1;
223 }
224
225 if (len > KEYSTORE_MESSAGE_SIZE)
226 len = KEYSTORE_MESSAGE_SIZE;
227 memcpy(val, value, len);
228 free(value);
229 return len;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200230}
231#endif /* ANDROID */
232
233
Vinita S. Maloo0fcb57d2020-04-24 14:03:56 +0530234#ifdef NL80211_SUPPORT
235static int nl80211_sta_set_power_save(struct sigma_dut *dut,
236 const char *intf,
237 enum nl80211_ps_state ps_state)
238{
239 struct nl_msg *msg;
240 int ifindex, ret;
241
242 ifindex = if_nametoindex(intf);
243 if (ifindex == 0) {
244 sigma_dut_print(dut, DUT_MSG_ERROR,
245 "%s: Index for interface %s not found",
246 __func__, intf);
247 return -1;
248 }
249
250 msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
251 NL80211_CMD_SET_POWER_SAVE);
252 if (!msg) {
253 sigma_dut_print(dut, DUT_MSG_ERROR,
254 "%s: err in creating nl80211 msg", __func__);
255 return -1;
256 }
257
258 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) {
259 sigma_dut_print(dut, DUT_MSG_ERROR,
260 "%s: err in populating nl80211 msg", __func__);
261 nlmsg_free(msg);
262 return -1;
263 }
264
265 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
266 if (ret) {
267 sigma_dut_print(dut, DUT_MSG_ERROR,
268 "%s: err in send_and_recv_msgs, ret=%d (%s)",
269 __func__, ret, strerror(-ret));
270 return -1;
271 }
272
273 return 0;
274}
275#endif /* NL80211_SUPPORT */
276
277
Vinita S. Malooa8b62722020-04-23 01:45:41 +0530278static int set_power_save_wcn(struct sigma_dut *dut, const char *intf, int ps)
279{
280 char buf[100];
Vinita S. Maloo0fcb57d2020-04-24 14:03:56 +0530281#ifdef NL80211_SUPPORT
282 enum nl80211_ps_state ps_state;
283
284 ps_state = ps == 1 ? NL80211_PS_ENABLED : NL80211_PS_DISABLED;
285 if (nl80211_sta_set_power_save(dut, intf, ps_state) == 0)
286 return 0;
287#endif /* NL80211_SUPPORT */
Vinita S. Malooa8b62722020-04-23 01:45:41 +0530288
289 snprintf(buf, sizeof(buf), "iwpriv %s setPower %d", intf, ps);
290 if (system(buf) != 0) {
291 sigma_dut_print(dut, DUT_MSG_ERROR,
292 "iwpriv setPower %d failed", ps);
293 return -1;
294 }
295 return 0;
296}
297
298
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200299int set_ps(const char *intf, struct sigma_dut *dut, int enabled)
300{
301#ifdef __linux__
302 char buf[100];
303
304 if (wifi_chip_type == DRIVER_WCN) {
305 if (enabled) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +0530306 if (set_power_save_wcn(dut, intf, 1) < 0) {
Purushottam Kushwaha304561d2019-12-23 16:57:18 +0530307 snprintf(buf, sizeof(buf),
308 "iwpriv wlan0 dump 906");
309 if (system(buf) != 0)
310 goto set_power_save;
311 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200312 } else {
Vinita S. Malooa8b62722020-04-23 01:45:41 +0530313 if (set_power_save_wcn(dut, intf, 2) < 0) {
Purushottam Kushwaha304561d2019-12-23 16:57:18 +0530314 snprintf(buf, sizeof(buf),
315 "iwpriv wlan0 dump 905");
316 if (system(buf) != 0)
317 goto set_power_save;
318 snprintf(buf, sizeof(buf),
319 "iwpriv wlan0 dump 912");
320 if (system(buf) != 0)
321 goto set_power_save;
322 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200323 }
324
325 return 0;
326 }
327
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530328set_power_save:
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200329 snprintf(buf, sizeof(buf), "./iw dev %s set power_save %s",
330 intf, enabled ? "on" : "off");
331 if (system(buf) != 0) {
332 snprintf(buf, sizeof(buf), "iw dev %s set power_save %s",
333 intf, enabled ? "on" : "off");
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530334 if (system(buf) != 0) {
335 sigma_dut_print(dut, DUT_MSG_ERROR,
336 "Failed to set power save %s",
337 enabled ? "on" : "off");
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200338 return -1;
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530339 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200340 }
341
342 return 0;
343#else /* __linux__ */
344 return -1;
345#endif /* __linux__ */
346}
347
348
Lior Davidcc88b562017-01-03 18:52:09 +0200349#ifdef __linux__
Lior David0fe101e2017-03-09 16:09:50 +0200350
Lior Davidcc88b562017-01-03 18:52:09 +0200351static int wil6210_get_debugfs_dir(struct sigma_dut *dut, char *path,
352 size_t len)
353{
354 DIR *dir, *wil_dir;
355 struct dirent *entry;
356 int ret = -1;
357 const char *root_path = "/sys/kernel/debug/ieee80211";
358
359 dir = opendir(root_path);
360 if (!dir)
361 return -2;
362
363 while ((entry = readdir(dir))) {
364 if (strcmp(entry->d_name, ".") == 0 ||
365 strcmp(entry->d_name, "..") == 0)
366 continue;
367
368 if (snprintf(path, len, "%s/%s/wil6210",
369 root_path, entry->d_name) >= (int) len) {
370 ret = -3;
371 break;
372 }
373
374 wil_dir = opendir(path);
375 if (wil_dir) {
376 closedir(wil_dir);
377 ret = 0;
378 break;
379 }
380 }
381
382 closedir(dir);
383 return ret;
384}
Lior David0fe101e2017-03-09 16:09:50 +0200385
386
387static int wil6210_wmi_send(struct sigma_dut *dut, uint16_t command,
388 void *payload, uint16_t length)
389{
390 struct {
391 struct wil_wmi_header hdr;
392 char payload[WIL_WMI_MAX_PAYLOAD];
393 } __attribute__((packed)) cmd;
394 char buf[128], fname[128];
395 size_t towrite, written;
396 FILE *f;
Jouni Malinen3aa72862019-05-29 23:14:51 +0300397 int res;
Lior David0fe101e2017-03-09 16:09:50 +0200398
399 if (length > WIL_WMI_MAX_PAYLOAD) {
400 sigma_dut_print(dut, DUT_MSG_ERROR,
401 "payload too large(%u, max %u)",
402 length, WIL_WMI_MAX_PAYLOAD);
403 return -1;
404 }
405
406 memset(&cmd.hdr, 0, sizeof(cmd.hdr));
407 cmd.hdr.cmd = command;
408 memcpy(cmd.payload, payload, length);
409
410 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
411 sigma_dut_print(dut, DUT_MSG_ERROR,
412 "failed to get wil6210 debugfs dir");
413 return -1;
414 }
415
Jouni Malinen3aa72862019-05-29 23:14:51 +0300416 res = snprintf(fname, sizeof(fname), "%s/wmi_send", buf);
417 if (res < 0 || res >= sizeof(fname))
418 return -1;
Lior David0fe101e2017-03-09 16:09:50 +0200419 f = fopen(fname, "wb");
420 if (!f) {
421 sigma_dut_print(dut, DUT_MSG_ERROR,
422 "failed to open: %s", fname);
423 return -1;
424 }
425
426 towrite = sizeof(cmd.hdr) + length;
427 written = fwrite(&cmd, 1, towrite, f);
428 fclose(f);
429 if (written != towrite) {
430 sigma_dut_print(dut, DUT_MSG_ERROR,
431 "failed to send wmi %u", command);
432 return -1;
433 }
434
435 return 0;
436}
437
438
439static int wil6210_get_sta_info_field(struct sigma_dut *dut, const char *bssid,
440 const char *pattern, unsigned int *field)
441{
442 char buf[128], fname[128];
443 FILE *f;
444 regex_t re;
445 regmatch_t m[2];
Jouni Malinen3aa72862019-05-29 23:14:51 +0300446 int rc, ret = -1, res;
Lior David0fe101e2017-03-09 16:09:50 +0200447
448 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
449 sigma_dut_print(dut, DUT_MSG_ERROR,
450 "failed to get wil6210 debugfs dir");
451 return -1;
452 }
453
Jouni Malinen3aa72862019-05-29 23:14:51 +0300454 res = snprintf(fname, sizeof(fname), "%s/stations", buf);
455 if (res < 0 || res >= sizeof(fname))
456 return -1;
Lior David0fe101e2017-03-09 16:09:50 +0200457 f = fopen(fname, "r");
458 if (!f) {
459 sigma_dut_print(dut, DUT_MSG_ERROR,
460 "failed to open: %s", fname);
461 return -1;
462 }
463
464 if (regcomp(&re, pattern, REG_EXTENDED)) {
465 sigma_dut_print(dut, DUT_MSG_ERROR,
466 "regcomp failed: %s", pattern);
467 goto out;
468 }
469
470 /*
471 * find the entry for the mac address
472 * line is of the form: [n] 11:22:33:44:55:66 state AID aid
473 */
474 while (fgets(buf, sizeof(buf), f)) {
475 if (strcasestr(buf, bssid)) {
476 /* extract the field (CID/AID/state) */
477 rc = regexec(&re, buf, 2, m, 0);
478 if (!rc && (m[1].rm_so >= 0)) {
479 buf[m[1].rm_eo] = 0;
480 *field = atoi(&buf[m[1].rm_so]);
481 ret = 0;
482 break;
483 }
484 }
485 }
486
487 regfree(&re);
488 if (ret)
489 sigma_dut_print(dut, DUT_MSG_ERROR,
490 "could not extract field");
491
492out:
493 fclose(f);
494
495 return ret;
496}
497
498
499static int wil6210_get_cid(struct sigma_dut *dut, const char *bssid,
500 unsigned int *cid)
501{
502 const char *pattern = "\\[([0-9]+)\\]";
503
504 return wil6210_get_sta_info_field(dut, bssid, pattern, cid);
505}
506
507
508static int wil6210_send_brp_rx(struct sigma_dut *dut, const char *mac,
509 int l_rx)
510{
Rakesh Sunki556237d2017-03-30 14:49:31 -0700511 struct wil_wmi_bf_trig_cmd cmd;
Lior David0fe101e2017-03-09 16:09:50 +0200512 unsigned int cid;
513
Rakesh Sunki556237d2017-03-30 14:49:31 -0700514 memset(&cmd, 0, sizeof(cmd));
515
Lior David0fe101e2017-03-09 16:09:50 +0200516 if (wil6210_get_cid(dut, mac, &cid))
517 return -1;
518
519 cmd.bf_type = WIL_WMI_BRP_RX;
520 cmd.sta_id = cid;
521 /* training length (l_rx) is ignored, FW always uses length 16 */
522 return wil6210_wmi_send(dut, WIL_WMI_BF_TRIG_CMDID,
523 &cmd, sizeof(cmd));
524}
525
526
527static int wil6210_send_sls(struct sigma_dut *dut, const char *mac)
528{
Rakesh Sunki556237d2017-03-30 14:49:31 -0700529 struct wil_wmi_bf_trig_cmd cmd;
530
531 memset(&cmd, 0, sizeof(cmd));
Lior David0fe101e2017-03-09 16:09:50 +0200532
533 if (parse_mac_address(dut, mac, (unsigned char *)&cmd.dest_mac))
534 return -1;
535
536 cmd.bf_type = WIL_WMI_SLS;
537 return wil6210_wmi_send(dut, WIL_WMI_BF_TRIG_CMDID,
538 &cmd, sizeof(cmd));
539}
540
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +0200541
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +0200542int wil6210_set_ese(struct sigma_dut *dut, int count,
543 struct sigma_ese_alloc *allocs)
544{
545 struct wil_wmi_ese_cfg cmd = { };
546 int i;
547
548 if (count == 0 || count > WIL_WMI_MAX_ESE_SLOTS)
549 return -1;
550
551 if (dut->ap_bcnint <= 0) {
552 sigma_dut_print(dut, DUT_MSG_ERROR,
553 "invalid beacon interval(%d), check test",
554 dut->ap_bcnint);
555 return -1;
556 }
557
558 cmd.ese_advertisment = WIL_WMI_ADVERTISE_ESE_IN_BEACON;
559 cmd.flags = 0x1d;
560 cmd.num_allocs = count;
561 for (i = 0; i < count; i++) {
562 /*
563 * Convert percent from BI (BI specified in milliseconds)
564 * to absolute duration in microseconds.
565 */
566 cmd.slots[i].duration =
567 (allocs[i].percent_bi * dut->ap_bcnint * 1000) / 100;
568 switch (allocs[i].type) {
569 case ESE_CBAP:
570 cmd.slots[i].slot_type = WIL_WMI_ESE_CBAP;
571 break;
572 case ESE_SP:
573 cmd.slots[i].slot_type = WIL_WMI_ESE_SP;
574 break;
575 default:
576 sigma_dut_print(dut, DUT_MSG_ERROR,
577 "invalid slot type(%d) at index %d",
578 allocs[i].type, i);
579 return -1;
580 }
581 cmd.slots[i].src_aid = allocs[i].src_aid;
582 cmd.slots[i].dst_aid = allocs[i].dst_aid;
583 sigma_dut_print(dut, DUT_MSG_INFO,
584 "slot %d, duration %u, type %d, srcAID %u dstAID %u",
585 i, cmd.slots[i].duration,
586 cmd.slots[i].slot_type, cmd.slots[i].src_aid,
587 cmd.slots[i].dst_aid);
588 }
589
590 return wil6210_wmi_send(dut, WIL_WMI_ESE_CFG_CMDID, &cmd, sizeof(cmd));
591}
592
593
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +0200594int wil6210_set_force_mcs(struct sigma_dut *dut, int force, int mcs)
595{
596 struct wil_wmi_force_mcs cmd = { };
597
598 cmd.module_id = WIL_WMI_UT_HW_SYSAPI;
599 cmd.subtype_id = WIL_WMI_UT_FORCE_MCS;
600 cmd.force_enable = (uint32_t) force;
601 cmd.mcs = (uint32_t) mcs;
602
603 return wil6210_wmi_send(dut, WIL_WMI_UNIT_TEST_CMDID,
604 &cmd, sizeof(cmd));
605}
606
607
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +0200608static int wil6210_force_rsn_ie(struct sigma_dut *dut, int state)
609{
610 struct wil_wmi_force_rsn_ie cmd = { };
611
612 cmd.module_id = WIL_WMI_UT_HW_SYSAPI;
613 cmd.subtype_id = WIL_WMI_UT_FORCE_RSN_IE;
614 cmd.state = (uint32_t) state;
615
616 return wil6210_wmi_send(dut, WIL_WMI_UNIT_TEST_CMDID,
617 &cmd, sizeof(cmd));
618}
619
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +0300620
621/*
622 * this function is also used to configure generic remain-on-channel
623 */
624static int wil6210_p2p_cfg(struct sigma_dut *dut, int freq)
625{
626 struct wil_wmi_p2p_cfg_cmd cmd = { };
627 int channel = freq_to_channel(freq);
628
629 if (channel < 0)
630 return -1;
631 cmd.discovery_mode = WMI_DISCOVERY_MODE_NON_OFFLOAD;
632 cmd.channel = channel - 1;
633 cmd.bcon_interval = WIL_DEFAULT_BI;
634 cmd.discovery_mode = WMI_DISCOVERY_MODE_PEER2PEER;
635
636 return wil6210_wmi_send(dut, WIL_WMI_P2P_CFG_CMDID,
637 &cmd, sizeof(cmd));
638}
639
640
641static int wil6210_remain_on_channel(struct sigma_dut *dut, int freq)
642{
643 int ret = wil6210_p2p_cfg(dut, freq);
644
645 if (ret)
646 return ret;
647
648 ret = wil6210_wmi_send(dut, WIL_WMI_START_LISTEN_CMDID, NULL, 0);
649 if (!ret) {
650 /*
651 * wait a bit to allow FW to setup the radio
652 * especially important if we switch channels
653 */
654 usleep(500000);
655 }
656
657 return ret;
658}
659
660
661static int wil6210_stop_discovery(struct sigma_dut *dut)
662{
663 return wil6210_wmi_send(dut, WIL_WMI_DISCOVERY_STOP_CMDID, NULL, 0);
664}
665
666
667static int wil6210_transmit_frame(struct sigma_dut *dut, int freq,
668 int wait_duration,
669 const char *frame, size_t frame_len)
670{
671 char buf[128], fname[128];
672 FILE *f;
Jouni Malinen3aa72862019-05-29 23:14:51 +0300673 int res = 0, r;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +0300674 size_t written;
675
676 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
677 sigma_dut_print(dut, DUT_MSG_ERROR,
678 "failed to get wil6210 debugfs dir");
679 return -1;
680 }
Jouni Malinen3aa72862019-05-29 23:14:51 +0300681 r = snprintf(fname, sizeof(fname), "%s/tx_mgmt", buf);
682 if (r < 0 || r >= sizeof(fname))
683 return -1;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +0300684
685 if (wil6210_remain_on_channel(dut, freq)) {
686 sigma_dut_print(dut, DUT_MSG_ERROR,
687 "failed to listen on channel");
688 return -1;
689 }
690
691 f = fopen(fname, "wb");
692 if (!f) {
693 sigma_dut_print(dut, DUT_MSG_ERROR,
694 "failed to open: %s", fname);
695 res = -1;
696 goto out_stop;
697 }
698 written = fwrite(frame, 1, frame_len, f);
699 fclose(f);
700
701 if (written != frame_len) {
702 sigma_dut_print(dut, DUT_MSG_ERROR,
703 "failed to transmit frame (got %zd, expected %zd)",
704 written, frame_len);
705 res = -1;
706 goto out_stop;
707 }
708
709 usleep(wait_duration * 1000);
710
711out_stop:
712 wil6210_stop_discovery(dut);
713 return res;
714}
715
716
717static int find_template_frame_tag(struct template_frame_tag *tags,
718 int total_tags, int tag_num)
719{
720 int i;
721
722 for (i = 0; i < total_tags; i++) {
723 if (tag_num == tags[i].num)
724 return i;
725 }
726
727 return -1;
728}
729
730
731static int replace_p2p_attribute(struct sigma_dut *dut, char *buf, size_t len,
732 int id, const char *value, size_t val_len)
733{
734 struct wfa_p2p_attribute *attr = (struct wfa_p2p_attribute *) buf;
735
736 if (len < 3 + val_len) {
737 sigma_dut_print(dut, DUT_MSG_ERROR,
738 "not enough space to replace P2P attribute");
739 return -1;
740 }
741
742 if (attr->len != val_len) {
743 sigma_dut_print(dut, DUT_MSG_ERROR,
744 "attribute length mismatch (need %zu have %hu)",
745 val_len, attr->len);
746 return -1;
747 }
748
749 if (attr->id != id) {
750 sigma_dut_print(dut, DUT_MSG_ERROR,
751 "incorrect attribute id (expected %d actual %d)",
752 id, attr->id);
753 return -1;
754 }
755
756 memcpy(attr->variable, value, val_len);
757
758 return 0;
759}
760
761
762static int parse_template_frame_file(struct sigma_dut *dut, const char *fname,
763 char *buf, size_t *length,
764 struct template_frame_tag *tags,
765 size_t *num_tags)
766{
767 char line[512];
768 FILE *f;
769 size_t offset = 0, tag_index = 0;
770 int num, index;
771 int in_tag = 0, tag_num = 0, tag_offset = 0;
772
773 if (*length < sizeof(struct ieee80211_hdr_3addr)) {
774 sigma_dut_print(dut, DUT_MSG_ERROR,
775 "supplied buffer is too small");
776 return -1;
777 }
778
779 f = fopen(fname, "r");
780 if (!f) {
781 sigma_dut_print(dut, DUT_MSG_ERROR,
782 "failed to open template file %s", fname);
783 return -1;
784 }
785
786 /*
787 * template file format: lines beginning with # are comments and
788 * ignored.
789 * It is possible to tag bytes in the frame to make it easy
790 * to replace fields in the template, espcially if they appear
791 * in variable-sized sections (such as IEs)
792 * This is done by a line beginning with $NUM where NUM is an integer
793 * tag number. It can be followed by space(s) and comment.
794 * The next line is considered the tagged bytes. The parser will fill
795 * the tag number, offset and length of the tagged bytes.
796 * rest of the lines contain frame bytes as sequence of hex digits,
797 * 2 digits for each byte. Spaces are allowed between bytes.
798 * On bytes lines only hex digits and spaces are allowed
799 */
800 while (!feof(f)) {
801 if (!fgets(line, sizeof(line), f))
802 break;
803 index = 0;
804 while (isspace((unsigned char) line[index]))
805 index++;
806 if (!line[index] || line[index] == '#')
807 continue;
808 if (line[index] == '$') {
809 if (tags) {
810 index++;
811 tag_num = strtol(&line[index], NULL, 0);
812 tag_offset = offset;
813 in_tag = 1;
814 }
815 continue;
816 }
817 while (line[index]) {
818 if (isspace((unsigned char) line[index])) {
819 index++;
820 continue;
821 }
822 num = hex_byte(&line[index]);
823 if (num < 0)
824 break;
825 buf[offset++] = num;
826 if (offset == *length)
827 goto out;
828 index += 2;
829 }
830
831 if (in_tag) {
832 if (tag_index < *num_tags) {
833 tags[tag_index].num = tag_num;
834 tags[tag_index].offset = tag_offset;
835 tags[tag_index].len = offset - tag_offset;
836 tag_index++;
837 } else {
838 sigma_dut_print(dut, DUT_MSG_INFO,
839 "too many tags, tag ignored");
840 }
841 in_tag = 0;
842 }
843 }
844
845 if (num_tags)
846 *num_tags = tag_index;
847out:
848 fclose(f);
849 if (offset < sizeof(struct ieee80211_hdr_3addr)) {
850 sigma_dut_print(dut, DUT_MSG_ERROR,
851 "template frame is too small");
852 return -1;
853 }
854
855 *length = offset;
856 return 0;
857}
858
Lior Davidcc88b562017-01-03 18:52:09 +0200859#endif /* __linux__ */
860
861
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200862static void static_ip_file(int proto, const char *addr, const char *mask,
863 const char *gw)
864{
865 if (proto) {
866 FILE *f = fopen("static-ip", "w");
867 if (f) {
868 fprintf(f, "%d %s %s %s\n", proto, addr,
869 mask ? mask : "N/A",
870 gw ? gw : "N/A");
871 fclose(f);
872 }
873 } else {
874 unlink("static-ip");
875 }
876}
877
878
879static int send_neighbor_request(struct sigma_dut *dut, const char *intf,
880 const char *ssid)
881{
882#ifdef __linux__
883 char buf[100];
884
885 snprintf(buf, sizeof(buf), "iwpriv %s neighbor %s",
886 intf, ssid);
887 sigma_dut_print(dut, DUT_MSG_INFO, "Request: %s", buf);
888
889 if (system(buf) != 0) {
890 sigma_dut_print(dut, DUT_MSG_ERROR,
891 "iwpriv neighbor request failed");
892 return -1;
893 }
894
895 sigma_dut_print(dut, DUT_MSG_INFO, "iwpriv neighbor request send");
896
897 return 0;
898#else /* __linux__ */
899 return -1;
900#endif /* __linux__ */
901}
902
903
904static int send_trans_mgmt_query(struct sigma_dut *dut, const char *intf,
Ashwini Patil5acd7382017-04-13 15:55:04 +0530905 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200906{
Ashwini Patil5acd7382017-04-13 15:55:04 +0530907 const char *val;
908 int reason_code = 0;
909 char buf[1024];
910
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200911 /*
912 * In the earlier builds we used WNM_QUERY and in later
913 * builds used WNM_BSS_QUERY.
914 */
915
Ashwini Patil5acd7382017-04-13 15:55:04 +0530916 val = get_param(cmd, "BTMQuery_Reason_Code");
917 if (val)
918 reason_code = atoi(val);
919
920 val = get_param(cmd, "Cand_List");
921 if (val && atoi(val) == 1 && dut->btm_query_cand_list) {
922 snprintf(buf, sizeof(buf), "WNM_BSS_QUERY %d%s", reason_code,
923 dut->btm_query_cand_list);
924 free(dut->btm_query_cand_list);
925 dut->btm_query_cand_list = NULL;
926 } else {
927 snprintf(buf, sizeof(buf), "WNM_BSS_QUERY %d", reason_code);
928 }
929
930 if (wpa_command(intf, buf) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200931 sigma_dut_print(dut, DUT_MSG_ERROR,
932 "transition management query failed");
933 return -1;
934 }
935
936 sigma_dut_print(dut, DUT_MSG_DEBUG,
937 "transition management query sent");
938
939 return 0;
940}
941
942
943int is_ip_addr(const char *str)
944{
945 const char *pos = str;
946 struct in_addr addr;
947
948 while (*pos) {
949 if (*pos != '.' && (*pos < '0' || *pos > '9'))
950 return 0;
951 pos++;
952 }
953
954 return inet_aton(str, &addr);
955}
956
957
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200958int get_ip_config(struct sigma_dut *dut, const char *ifname, char *buf,
959 size_t buf_len)
960{
vamsi krishnaa11d0732018-05-16 12:19:48 +0530961 char tmp[256];
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200962 char ip[16], mask[15], dns[16], sec_dns[16];
963 int is_dhcp = 0;
964 int s;
965#ifdef ANDROID
966 char prop[PROPERTY_VALUE_MAX];
vamsi krishnaa11d0732018-05-16 12:19:48 +0530967#else /* ANDROID */
968 FILE *f;
969#ifdef __linux__
970 const char *str_ps;
971#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200972#endif /* ANDROID */
973
974 ip[0] = '\0';
975 mask[0] = '\0';
976 dns[0] = '\0';
977 sec_dns[0] = '\0';
978
979 s = socket(PF_INET, SOCK_DGRAM, 0);
980 if (s >= 0) {
981 struct ifreq ifr;
982 struct sockaddr_in saddr;
983
984 memset(&ifr, 0, sizeof(ifr));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700985 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200986 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
987 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get "
988 "%s IP address: %s",
989 ifname, strerror(errno));
990 } else {
991 memcpy(&saddr, &ifr.ifr_addr,
992 sizeof(struct sockaddr_in));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700993 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200994 }
995
996 if (ioctl(s, SIOCGIFNETMASK, &ifr) == 0) {
997 memcpy(&saddr, &ifr.ifr_addr,
998 sizeof(struct sockaddr_in));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700999 strlcpy(mask, inet_ntoa(saddr.sin_addr), sizeof(mask));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001000 }
1001 close(s);
1002 }
1003
1004#ifdef ANDROID
1005 snprintf(tmp, sizeof(tmp), "dhcp.%s.pid", ifname);
1006 if (property_get(tmp, prop, NULL) != 0 && atoi(prop) > 0) {
1007 snprintf(tmp, sizeof(tmp), "dhcp.%s.result", ifname);
1008 if (property_get(tmp, prop, NULL) != 0 &&
1009 strcmp(prop, "ok") == 0) {
1010 snprintf(tmp, sizeof(tmp), "dhcp.%s.ipaddress",
1011 ifname);
1012 if (property_get(tmp, prop, NULL) != 0 &&
1013 strcmp(ip, prop) == 0)
1014 is_dhcp = 1;
1015 }
1016 }
1017
1018 snprintf(tmp, sizeof(tmp), "dhcp.%s.dns1", ifname);
Peng Xub8fc5cc2017-05-10 17:27:28 -07001019 if (property_get(tmp, prop, NULL) != 0)
1020 strlcpy(dns, prop, sizeof(dns));
1021 else if (property_get("net.dns1", prop, NULL) != 0)
1022 strlcpy(dns, prop, sizeof(dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001023
1024 snprintf(tmp, sizeof(tmp), "dhcp.%s.dns2", ifname);
Peng Xub8fc5cc2017-05-10 17:27:28 -07001025 if (property_get(tmp, prop, NULL) != 0)
1026 strlcpy(sec_dns, prop, sizeof(sec_dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001027#else /* ANDROID */
1028#ifdef __linux__
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001029 if (get_driver_type(dut) == DRIVER_OPENWRT)
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +05301030 str_ps = "ps -w";
1031 else
1032 str_ps = "ps ax";
1033 snprintf(tmp, sizeof(tmp),
1034 "%s | grep dhclient | grep -v grep | grep -q %s",
1035 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001036 if (system(tmp) == 0)
1037 is_dhcp = 1;
1038 else {
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +05301039 snprintf(tmp, sizeof(tmp),
1040 "%s | grep udhcpc | grep -v grep | grep -q %s",
1041 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001042 if (system(tmp) == 0)
1043 is_dhcp = 1;
1044 else {
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +05301045 snprintf(tmp, sizeof(tmp),
1046 "%s | grep dhcpcd | grep -v grep | grep -q %s",
1047 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001048 if (system(tmp) == 0)
1049 is_dhcp = 1;
1050 }
1051 }
1052#endif /* __linux__ */
1053
1054 f = fopen("/etc/resolv.conf", "r");
1055 if (f) {
vamsi krishnaa11d0732018-05-16 12:19:48 +05301056 char *pos, *pos2;
1057
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001058 while (fgets(tmp, sizeof(tmp), f)) {
1059 if (strncmp(tmp, "nameserver", 10) != 0)
1060 continue;
1061 pos = tmp + 10;
1062 while (*pos == ' ' || *pos == '\t')
1063 pos++;
1064 pos2 = pos;
1065 while (*pos2) {
1066 if (*pos2 == '\n' || *pos2 == '\r') {
1067 *pos2 = '\0';
1068 break;
1069 }
1070 pos2++;
1071 }
Peng Xub8fc5cc2017-05-10 17:27:28 -07001072 if (!dns[0])
1073 strlcpy(dns, pos, sizeof(dns));
1074 else if (!sec_dns[0])
1075 strlcpy(sec_dns, pos, sizeof(sec_dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001076 }
1077 fclose(f);
1078 }
1079#endif /* ANDROID */
1080
1081 snprintf(buf, buf_len, "dhcp,%d,ip,%s,mask,%s,primary-dns,%s",
1082 is_dhcp, ip, mask, dns);
1083 buf[buf_len - 1] = '\0';
1084
1085 return 0;
1086}
1087
1088
1089
1090
1091int get_ipv6_config(struct sigma_dut *dut, const char *ifname, char *buf,
1092 size_t buf_len)
1093{
1094#ifdef __linux__
1095#ifdef ANDROID
1096 char cmd[200], result[1000], *pos, *end;
1097 FILE *f;
1098 size_t len;
1099
1100 snprintf(cmd, sizeof(cmd), "ip addr show dev %s scope global", ifname);
1101 f = popen(cmd, "r");
1102 if (f == NULL)
1103 return -1;
1104 len = fread(result, 1, sizeof(result) - 1, f);
1105 pclose(f);
1106 if (len == 0)
1107 return -1;
1108 result[len] = '\0';
1109 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s result: %s\n", cmd, result);
1110
1111 pos = strstr(result, "inet6 ");
1112 if (pos == NULL)
1113 return -1;
1114 pos += 6;
1115 end = strchr(pos, ' ');
1116 if (end)
1117 *end = '\0';
1118 end = strchr(pos, '/');
1119 if (end)
1120 *end = '\0';
1121 snprintf(buf, buf_len, "ip,%s", pos);
1122 buf[buf_len - 1] = '\0';
1123 return 0;
1124#else /* ANDROID */
1125 struct ifaddrs *ifaddr, *ifa;
1126 int res, found = 0;
1127 char host[NI_MAXHOST];
1128
1129 if (getifaddrs(&ifaddr) < 0) {
1130 perror("getifaddrs");
1131 return -1;
1132 }
1133
1134 for (ifa = ifaddr; ifa; ifa = ifa->ifa_next) {
1135 if (strcasecmp(ifname, ifa->ifa_name) != 0)
1136 continue;
1137 if (ifa->ifa_addr == NULL ||
1138 ifa->ifa_addr->sa_family != AF_INET6)
1139 continue;
1140
1141 res = getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in6),
1142 host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
1143 if (res != 0) {
1144 sigma_dut_print(dut, DUT_MSG_DEBUG, "getnameinfo: %s",
1145 gai_strerror(res));
1146 continue;
1147 }
1148 if (strncmp(host, "fe80::", 6) == 0)
1149 continue; /* skip link-local */
1150
1151 sigma_dut_print(dut, DUT_MSG_DEBUG, "ifaddr: %s", host);
1152 found = 1;
1153 break;
1154 }
1155
1156 freeifaddrs(ifaddr);
1157
1158 if (found) {
1159 char *pos;
1160 pos = strchr(host, '%');
1161 if (pos)
1162 *pos = '\0';
1163 snprintf(buf, buf_len, "ip,%s", host);
1164 buf[buf_len - 1] = '\0';
1165 return 0;
1166 }
1167
1168#endif /* ANDROID */
1169#endif /* __linux__ */
1170 return -1;
1171}
1172
1173
Jouni Malinenf7222712019-06-13 01:50:21 +03001174static enum sigma_cmd_result cmd_sta_get_ip_config(struct sigma_dut *dut,
1175 struct sigma_conn *conn,
1176 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001177{
1178 const char *intf = get_param(cmd, "Interface");
1179 const char *ifname;
1180 char buf[200];
1181 const char *val;
1182 int type = 1;
1183
1184 if (intf == NULL)
1185 return -1;
1186
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001187 if (strcmp(intf, get_main_ifname(dut)) == 0)
1188 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001189 else
1190 ifname = intf;
1191
1192 /*
1193 * UCC may assume the IP address to be available immediately after
1194 * association without trying to run sta_get_ip_config multiple times.
1195 * Sigma CAPI does not specify this command as a block command that
1196 * would wait for the address to become available, but to pass tests
1197 * more reliably, it looks like such a wait may be needed here.
1198 */
1199 if (wait_ip_addr(dut, ifname, 15) < 0) {
1200 sigma_dut_print(dut, DUT_MSG_INFO, "Could not get IP address "
1201 "for sta_get_ip_config");
1202 /*
1203 * Try to continue anyway since many UCC tests do not really
1204 * care about the return value from here..
1205 */
1206 }
1207
1208 val = get_param(cmd, "Type");
1209 if (val)
1210 type = atoi(val);
1211 if (type == 2 || dut->last_set_ip_config_ipv6) {
1212 int i;
1213
1214 /*
1215 * Since we do not have proper wait for IPv6 addresses, use a
1216 * fixed two second delay here as a workaround for UCC script
1217 * assuming IPv6 address is available when this command returns.
1218 * Some scripts did not use Type,2 properly for IPv6, so include
1219 * also the cases where the previous sta_set_ip_config indicated
1220 * use of IPv6.
1221 */
1222 sigma_dut_print(dut, DUT_MSG_INFO, "Wait up to extra ten seconds in sta_get_ip_config for IPv6 address");
1223 for (i = 0; i < 10; i++) {
1224 sleep(1);
1225 if (get_ipv6_config(dut, ifname, buf, sizeof(buf)) == 0)
1226 {
1227 sigma_dut_print(dut, DUT_MSG_INFO, "Found IPv6 address");
1228 send_resp(dut, conn, SIGMA_COMPLETE, buf);
1229#ifdef ANDROID
1230 sigma_dut_print(dut, DUT_MSG_INFO,
1231 "Adding IPv6 rule on Android");
1232 add_ipv6_rule(dut, intf);
1233#endif /* ANDROID */
1234
1235 return 0;
1236 }
1237 }
1238 }
1239 if (type == 1) {
1240 if (get_ip_config(dut, ifname, buf, sizeof(buf)) < 0)
1241 return -2;
1242 } else if (type == 2) {
1243 if (get_ipv6_config(dut, ifname, buf, sizeof(buf)) < 0)
1244 return -2;
1245 } else {
1246 send_resp(dut, conn, SIGMA_ERROR,
1247 "errorCode,Unsupported address type");
1248 return 0;
1249 }
1250
1251 send_resp(dut, conn, SIGMA_COMPLETE, buf);
1252 return 0;
1253}
1254
1255
1256static void kill_dhcp_client(struct sigma_dut *dut, const char *ifname)
1257{
1258#ifdef __linux__
1259 char buf[200];
1260 char path[128];
1261 struct stat s;
1262
1263#ifdef ANDROID
1264 snprintf(path, sizeof(path), "/data/misc/dhcp/dhcpcd-%s.pid", ifname);
1265#else /* ANDROID */
1266 snprintf(path, sizeof(path), "/var/run/dhclient-%s.pid", ifname);
1267#endif /* ANDROID */
1268 if (stat(path, &s) == 0) {
1269 snprintf(buf, sizeof(buf), "kill `cat %s`", path);
1270 sigma_dut_print(dut, DUT_MSG_INFO,
1271 "Kill previous DHCP client: %s", buf);
1272 if (system(buf) != 0)
1273 sigma_dut_print(dut, DUT_MSG_INFO,
1274 "Failed to kill DHCP client");
1275 unlink(path);
1276 sleep(1);
1277 } else {
1278 snprintf(path, sizeof(path), "/var/run/dhcpcd-%s.pid", ifname);
1279
1280 if (stat(path, &s) == 0) {
1281 snprintf(buf, sizeof(buf), "kill `cat %s`", path);
1282 sigma_dut_print(dut, DUT_MSG_INFO,
1283 "Kill previous DHCP client: %s", buf);
1284 if (system(buf) != 0)
1285 sigma_dut_print(dut, DUT_MSG_INFO,
1286 "Failed to kill DHCP client");
1287 unlink(path);
1288 sleep(1);
1289 }
1290 }
1291#endif /* __linux__ */
1292}
1293
1294
1295static int start_dhcp_client(struct sigma_dut *dut, const char *ifname)
1296{
1297#ifdef __linux__
1298 char buf[200];
1299
1300#ifdef ANDROID
Purushottam Kushwaha46d64262016-08-23 17:57:53 +05301301 if (access("/system/bin/dhcpcd", F_OK) != -1) {
1302 snprintf(buf, sizeof(buf),
1303 "/system/bin/dhcpcd -b %s", ifname);
1304 } else if (access("/system/bin/dhcptool", F_OK) != -1) {
1305 snprintf(buf, sizeof(buf), "/system/bin/dhcptool %s &", ifname);
Ankita Bajaj8454e5d2019-04-05 16:04:55 +05301306 } else if (access("/vendor/bin/dhcpcd", F_OK) != -1) {
1307 snprintf(buf, sizeof(buf), "/vendor/bin/dhcpcd -b %s", ifname);
1308 } else if (access("/vendor/bin/dhcptool", F_OK) != -1) {
1309 snprintf(buf, sizeof(buf), "/vendor/bin/dhcptool %s", ifname);
Purushottam Kushwaha46d64262016-08-23 17:57:53 +05301310 } else {
1311 sigma_dut_print(dut, DUT_MSG_ERROR,
1312 "DHCP client program missing");
1313 return 0;
1314 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001315#else /* ANDROID */
1316 snprintf(buf, sizeof(buf),
1317 "dhclient -nw -pf /var/run/dhclient-%s.pid %s",
1318 ifname, ifname);
1319#endif /* ANDROID */
1320 sigma_dut_print(dut, DUT_MSG_INFO, "Start DHCP client: %s", buf);
1321 if (system(buf) != 0) {
1322 snprintf(buf, sizeof(buf), "dhcpcd -t 0 %s &", ifname);
1323 if (system(buf) != 0) {
1324 sigma_dut_print(dut, DUT_MSG_INFO,
1325 "Failed to start DHCP client");
1326#ifndef ANDROID
1327 return -1;
1328#endif /* ANDROID */
1329 }
1330 }
1331#endif /* __linux__ */
1332
1333 return 0;
1334}
1335
1336
1337static int clear_ip_addr(struct sigma_dut *dut, const char *ifname)
1338{
1339#ifdef __linux__
1340 char buf[200];
1341
1342 snprintf(buf, sizeof(buf), "ip addr flush dev %s", ifname);
1343 if (system(buf) != 0) {
1344 sigma_dut_print(dut, DUT_MSG_INFO,
1345 "Failed to clear IP addresses");
1346 return -1;
1347 }
1348#endif /* __linux__ */
1349
1350 return 0;
1351}
1352
1353
1354#ifdef ANDROID
1355static int add_ipv6_rule(struct sigma_dut *dut, const char *ifname)
1356{
1357 char cmd[200], *result, *pos;
1358 FILE *fp;
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +05301359 int tableid;
1360 size_t len, result_len = 1000;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001361
1362 snprintf(cmd, sizeof(cmd), "ip -6 route list table all | grep %s",
1363 ifname);
1364 fp = popen(cmd, "r");
1365 if (fp == NULL)
1366 return -1;
1367
1368 result = malloc(result_len);
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05301369 if (result == NULL) {
1370 fclose(fp);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001371 return -1;
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05301372 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001373
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +05301374 len = fread(result, 1, result_len - 1, fp);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001375 fclose(fp);
1376
1377 if (len == 0) {
1378 free(result);
1379 return -1;
1380 }
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +05301381 result[len] = '\0';
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001382
1383 pos = strstr(result, "table ");
1384 if (pos == NULL) {
1385 free(result);
1386 return -1;
1387 }
1388
1389 pos += strlen("table ");
1390 tableid = atoi(pos);
1391 if (tableid != 0) {
1392 if (system("ip -6 rule del prio 22000") != 0) {
1393 /* ignore any error */
1394 }
1395 snprintf(cmd, sizeof(cmd),
1396 "ip -6 rule add from all lookup %d prio 22000",
1397 tableid);
1398 if (system(cmd) != 0) {
1399 sigma_dut_print(dut, DUT_MSG_INFO,
1400 "Failed to run %s", cmd);
1401 free(result);
1402 return -1;
1403 }
1404 } else {
1405 sigma_dut_print(dut, DUT_MSG_INFO,
1406 "No Valid Table Id found %s", pos);
1407 free(result);
1408 return -1;
1409 }
1410 free(result);
1411
1412 return 0;
1413}
1414#endif /* ANDROID */
1415
1416
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301417int set_ipv4_addr(struct sigma_dut *dut, const char *ifname,
1418 const char *ip, const char *mask)
1419{
1420 char buf[200];
1421
1422 snprintf(buf, sizeof(buf), "ifconfig %s %s netmask %s",
1423 ifname, ip, mask);
1424 return system(buf) == 0;
1425}
1426
1427
1428int set_ipv4_gw(struct sigma_dut *dut, const char *gw)
1429{
1430 char buf[200];
1431
1432 if (!is_ip_addr(gw)) {
1433 sigma_dut_print(dut, DUT_MSG_DEBUG, "Invalid gw addr - %s", gw);
1434 return -1;
1435 }
1436
1437 snprintf(buf, sizeof(buf), "route add default gw %s", gw);
1438 if (!dut->no_ip_addr_set && system(buf) != 0) {
1439 snprintf(buf, sizeof(buf), "ip ro re default via %s",
1440 gw);
1441 if (system(buf) != 0)
1442 return 0;
1443 }
1444
1445 return 1;
1446}
1447
1448
Jouni Malinenf7222712019-06-13 01:50:21 +03001449static enum sigma_cmd_result cmd_sta_set_ip_config(struct sigma_dut *dut,
1450 struct sigma_conn *conn,
1451 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001452{
1453 const char *intf = get_param(cmd, "Interface");
1454 const char *ifname;
1455 char buf[200];
1456 const char *val, *ip, *mask, *gw;
1457 int type = 1;
1458
1459 if (intf == NULL)
1460 return -1;
1461
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001462 if (strcmp(intf, get_main_ifname(dut)) == 0)
1463 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001464 else
1465 ifname = intf;
1466
1467 if (if_nametoindex(ifname) == 0) {
1468 send_resp(dut, conn, SIGMA_ERROR,
1469 "ErrorCode,Unknown interface");
1470 return 0;
1471 }
1472
1473 val = get_param(cmd, "Type");
1474 if (val) {
1475 type = atoi(val);
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301476 if (type < 1 || type > 3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001477 send_resp(dut, conn, SIGMA_ERROR,
1478 "ErrorCode,Unsupported address type");
1479 return 0;
1480 }
1481 }
1482
1483 dut->last_set_ip_config_ipv6 = 0;
1484
1485 val = get_param(cmd, "dhcp");
1486 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "true") == 0)) {
1487 static_ip_file(0, NULL, NULL, NULL);
1488#ifdef __linux__
1489 if (type == 2) {
1490 dut->last_set_ip_config_ipv6 = 1;
1491 sigma_dut_print(dut, DUT_MSG_INFO, "Using IPv6 "
1492 "stateless address autoconfiguration");
1493#ifdef ANDROID
1494 /*
1495 * This sleep is required as the assignment in case of
1496 * Android is taking time and is done by the kernel.
1497 * The subsequent ping for IPv6 is impacting HS20 test
1498 * case.
1499 */
1500 sleep(2);
1501 add_ipv6_rule(dut, intf);
1502#endif /* ANDROID */
1503 /* Assume this happens by default */
1504 return 1;
1505 }
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301506 if (type != 3) {
1507 kill_dhcp_client(dut, ifname);
1508 if (start_dhcp_client(dut, ifname) < 0)
1509 return -2;
1510 } else {
1511 sigma_dut_print(dut, DUT_MSG_DEBUG,
1512 "Using FILS HLP DHCPv4 Rapid Commit");
1513 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001514
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001515 return 1;
1516#endif /* __linux__ */
1517 return -2;
1518 }
1519
1520 ip = get_param(cmd, "ip");
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301521 if (!ip) {
1522 send_resp(dut, conn, SIGMA_INVALID,
1523 "ErrorCode,Missing IP address");
1524 return 0;
1525 }
1526
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001527 mask = get_param(cmd, "mask");
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301528 if (!mask) {
1529 send_resp(dut, conn, SIGMA_INVALID,
1530 "ErrorCode,Missing subnet mask");
1531 return 0;
1532 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001533
1534 if (type == 2) {
1535 int net = atoi(mask);
1536
1537 if ((net < 0 && net > 64) || !is_ipv6_addr(ip))
1538 return -1;
1539
1540 if (dut->no_ip_addr_set) {
1541 snprintf(buf, sizeof(buf),
1542 "sysctl net.ipv6.conf.%s.disable_ipv6=1",
1543 ifname);
1544 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
1545 if (system(buf) != 0) {
1546 sigma_dut_print(dut, DUT_MSG_DEBUG,
1547 "Failed to disable IPv6 address before association");
1548 }
1549 } else {
Veerendranath Jakkam176181c2020-05-16 00:19:21 +05301550 if (set_ipv6_addr(dut, ip, mask, ifname) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001551 send_resp(dut, conn, SIGMA_ERROR,
1552 "ErrorCode,Failed to set IPv6 address");
1553 return 0;
1554 }
1555 }
1556
1557 dut->last_set_ip_config_ipv6 = 1;
1558 static_ip_file(6, ip, mask, NULL);
1559 return 1;
1560 } else if (type == 1) {
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301561 if (!is_ip_addr(ip) || !is_ip_addr(mask))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001562 return -1;
1563 }
1564
1565 kill_dhcp_client(dut, ifname);
1566
1567 if (!dut->no_ip_addr_set) {
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301568 if (!set_ipv4_addr(dut, ifname, ip, mask)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001569 send_resp(dut, conn, SIGMA_ERROR,
1570 "ErrorCode,Failed to set IP address");
1571 return 0;
1572 }
1573 }
1574
1575 gw = get_param(cmd, "defaultGateway");
1576 if (gw) {
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301577 if (set_ipv4_gw(dut, gw) < 1) {
1578 send_resp(dut, conn, SIGMA_ERROR,
1579 "ErrorCode,Failed to set default gateway");
1580 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001581 }
1582 }
1583
1584 val = get_param(cmd, "primary-dns");
1585 if (val) {
Vinita S. Maloo069e8d42021-04-29 13:15:08 +05301586#ifdef ANDROID
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001587 /* TODO */
1588 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored primary-dns %s "
1589 "setting", val);
Vinita S. Maloo069e8d42021-04-29 13:15:08 +05301590#else /* ANDROID */
1591 char dns_cmd[200];
1592 int len;
1593
1594 if (system("sed -i '/nameserver/d' /etc/resolv.conf") != 0) {
1595 sigma_dut_print(dut, DUT_MSG_ERROR,
1596 "Failed to clear nameserver entries in /etc/resolv.conf");
1597 return ERROR_SEND_STATUS;
1598 }
1599
1600 len = snprintf(dns_cmd, sizeof(dns_cmd),
1601 "sed -i '1 i nameserver %s' /etc/resolv.conf", val);
1602 if (len < 0 || len >= sizeof(dns_cmd))
1603 return ERROR_SEND_STATUS;
1604
1605 sigma_dut_print(dut, DUT_MSG_DEBUG, "Running %s", dns_cmd);
1606 if (system(dns_cmd) != 0) {
1607 send_resp(dut, conn, SIGMA_ERROR,
1608 "ErrorCode,Failed to set primary-dns");
1609 return STATUS_SENT_ERROR;
1610 }
1611#endif /* ANDROID */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001612 }
1613
1614 val = get_param(cmd, "secondary-dns");
1615 if (val) {
1616 /* TODO */
1617 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored secondary-dns %s "
1618 "setting", val);
1619 }
1620
1621 static_ip_file(4, ip, mask, gw);
1622
1623 return 1;
1624}
1625
1626
Jouni Malinenf7222712019-06-13 01:50:21 +03001627static enum sigma_cmd_result cmd_sta_get_info(struct sigma_dut *dut,
1628 struct sigma_conn *conn,
1629 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001630{
1631 /* const char *intf = get_param(cmd, "Interface"); */
1632 /* TODO: could report more details here */
1633 send_resp(dut, conn, SIGMA_COMPLETE, "vendor,Atheros");
1634 return 0;
1635}
1636
1637
Jouni Malinenf7222712019-06-13 01:50:21 +03001638static enum sigma_cmd_result cmd_sta_get_mac_address(struct sigma_dut *dut,
1639 struct sigma_conn *conn,
1640 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001641{
1642 /* const char *intf = get_param(cmd, "Interface"); */
1643 char addr[20], resp[50];
1644
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05301645 if (dut->dev_role == DEVROLE_STA_CFON)
1646 return sta_cfon_get_mac_address(dut, conn, cmd);
1647
Jouni Malinen9540e012019-11-05 17:08:42 +02001648 start_sta_mode(dut);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001649 if (get_wpa_status(get_station_ifname(dut), "address",
1650 addr, sizeof(addr)) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001651 return -2;
1652
1653 snprintf(resp, sizeof(resp), "mac,%s", addr);
1654 send_resp(dut, conn, SIGMA_COMPLETE, resp);
1655 return 0;
1656}
1657
1658
Jouni Malinenf7222712019-06-13 01:50:21 +03001659static enum sigma_cmd_result cmd_sta_is_connected(struct sigma_dut *dut,
1660 struct sigma_conn *conn,
1661 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001662{
1663 /* const char *intf = get_param(cmd, "Interface"); */
1664 int connected = 0;
1665 char result[32];
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001666 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001667 sizeof(result)) < 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001668 sigma_dut_print(dut, DUT_MSG_INFO,
1669 "Could not get interface %s status",
1670 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001671 return -2;
1672 }
1673
1674 sigma_dut_print(dut, DUT_MSG_DEBUG, "wpa_state=%s", result);
1675 if (strncmp(result, "COMPLETED", 9) == 0)
1676 connected = 1;
1677
1678 if (connected)
1679 send_resp(dut, conn, SIGMA_COMPLETE, "connected,1");
1680 else
1681 send_resp(dut, conn, SIGMA_COMPLETE, "connected,0");
1682
1683 return 0;
1684}
1685
1686
Jouni Malinenf7222712019-06-13 01:50:21 +03001687static enum sigma_cmd_result
1688cmd_sta_verify_ip_connection(struct sigma_dut *dut, struct sigma_conn *conn,
1689 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001690{
1691 /* const char *intf = get_param(cmd, "Interface"); */
1692 const char *dst, *timeout;
1693 int wait_time = 90;
1694 char buf[100];
1695 int res;
1696
1697 dst = get_param(cmd, "destination");
1698 if (dst == NULL || !is_ip_addr(dst))
1699 return -1;
1700
1701 timeout = get_param(cmd, "timeout");
1702 if (timeout) {
1703 wait_time = atoi(timeout);
1704 if (wait_time < 1)
1705 wait_time = 1;
1706 }
1707
1708 /* TODO: force renewal of IP lease if DHCP is enabled */
1709
1710 snprintf(buf, sizeof(buf), "ping %s -c 3 -W %d", dst, wait_time);
1711 res = system(buf);
1712 sigma_dut_print(dut, DUT_MSG_DEBUG, "ping returned: %d", res);
1713 if (res == 0)
1714 send_resp(dut, conn, SIGMA_COMPLETE, "connected,1");
1715 else if (res == 256)
1716 send_resp(dut, conn, SIGMA_COMPLETE, "connected,0");
1717 else
1718 return -2;
1719
1720 return 0;
1721}
1722
1723
Jouni Malinenf7222712019-06-13 01:50:21 +03001724static enum sigma_cmd_result cmd_sta_get_bssid(struct sigma_dut *dut,
1725 struct sigma_conn *conn,
1726 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001727{
1728 /* const char *intf = get_param(cmd, "Interface"); */
1729 char bssid[20], resp[50];
1730
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001731 if (get_wpa_status(get_station_ifname(dut), "bssid",
1732 bssid, sizeof(bssid)) < 0)
Peng Xub8fc5cc2017-05-10 17:27:28 -07001733 strlcpy(bssid, "00:00:00:00:00:00", sizeof(bssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001734
1735 snprintf(resp, sizeof(resp), "bssid,%s", bssid);
1736 send_resp(dut, conn, SIGMA_COMPLETE, resp);
1737 return 0;
1738}
1739
1740
1741#ifdef __SAMSUNG__
1742static int add_use_network(const char *ifname)
1743{
1744 char buf[100];
1745
1746 snprintf(buf, sizeof(buf), "USE_NETWORK ON");
1747 wpa_command(ifname, buf);
1748 return 0;
1749}
1750#endif /* __SAMSUNG__ */
1751
1752
1753static int add_network_common(struct sigma_dut *dut, struct sigma_conn *conn,
1754 const char *ifname, struct sigma_cmd *cmd)
1755{
1756 const char *ssid = get_param(cmd, "ssid");
1757 int id;
1758 const char *val;
1759
1760 if (ssid == NULL)
1761 return -1;
1762
1763 start_sta_mode(dut);
1764
1765#ifdef __SAMSUNG__
1766 add_use_network(ifname);
1767#endif /* __SAMSUNG__ */
1768
1769 id = add_network(ifname);
1770 if (id < 0)
1771 return -2;
1772 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding network %d", id);
1773
1774 if (set_network_quoted(ifname, id, "ssid", ssid) < 0)
1775 return -2;
1776
1777 dut->infra_network_id = id;
1778 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
1779
1780 val = get_param(cmd, "program");
1781 if (!val)
1782 val = get_param(cmd, "prog");
1783 if (val && strcasecmp(val, "hs2") == 0) {
1784 char buf[100];
1785 snprintf(buf, sizeof(buf), "ENABLE_NETWORK %d no-connect", id);
1786 wpa_command(ifname, buf);
1787
1788 val = get_param(cmd, "prefer");
1789 if (val && atoi(val) > 0)
1790 set_network(ifname, id, "priority", "1");
1791 }
1792
1793 return id;
1794}
1795
1796
Jouni Malinenf7222712019-06-13 01:50:21 +03001797static enum sigma_cmd_result cmd_sta_set_encryption(struct sigma_dut *dut,
1798 struct sigma_conn *conn,
1799 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001800{
1801 const char *intf = get_param(cmd, "Interface");
1802 const char *ssid = get_param(cmd, "ssid");
1803 const char *type = get_param(cmd, "encpType");
1804 const char *ifname;
1805 char buf[200];
1806 int id;
1807
1808 if (intf == NULL || ssid == NULL)
1809 return -1;
1810
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001811 if (strcmp(intf, get_main_ifname(dut)) == 0)
1812 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001813 else
1814 ifname = intf;
1815
1816 id = add_network_common(dut, conn, ifname, cmd);
1817 if (id < 0)
1818 return id;
1819
1820 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
1821 return -2;
1822
1823 if (type && strcasecmp(type, "wep") == 0) {
1824 const char *val;
1825 int i;
1826
1827 val = get_param(cmd, "activeKey");
1828 if (val) {
1829 int keyid;
1830 keyid = atoi(val);
1831 if (keyid < 1 || keyid > 4)
1832 return -1;
1833 snprintf(buf, sizeof(buf), "%d", keyid - 1);
1834 if (set_network(ifname, id, "wep_tx_keyidx", buf) < 0)
1835 return -2;
1836 }
1837
1838 for (i = 0; i < 4; i++) {
1839 snprintf(buf, sizeof(buf), "key%d", i + 1);
1840 val = get_param(cmd, buf);
1841 if (val == NULL)
1842 continue;
1843 snprintf(buf, sizeof(buf), "wep_key%d", i);
1844 if (set_network(ifname, id, buf, val) < 0)
1845 return -2;
1846 }
1847 }
1848
1849 return 1;
1850}
1851
1852
Jouni Malinene4fde732019-03-25 22:29:37 +02001853static int set_akm_suites(struct sigma_dut *dut, const char *ifname,
1854 int id, const char *val)
1855{
1856 char key_mgmt[200], *end, *pos;
1857 const char *in_pos = val;
1858
Jouni Malinen8179fee2019-03-28 03:19:47 +02001859 dut->akm_values = 0;
Jouni Malinene4fde732019-03-25 22:29:37 +02001860 pos = key_mgmt;
1861 end = pos + sizeof(key_mgmt);
1862 while (*in_pos) {
1863 int res, akm = atoi(in_pos);
1864 const char *str;
1865
Jouni Malinen8179fee2019-03-28 03:19:47 +02001866 if (akm >= 0 && akm < 32)
1867 dut->akm_values |= 1 << akm;
1868
Jouni Malinene4fde732019-03-25 22:29:37 +02001869 switch (akm) {
1870 case AKM_WPA_EAP:
1871 str = "WPA-EAP";
1872 break;
1873 case AKM_WPA_PSK:
1874 str = "WPA-PSK";
1875 break;
1876 case AKM_FT_EAP:
1877 str = "FT-EAP";
1878 break;
1879 case AKM_FT_PSK:
1880 str = "FT-PSK";
1881 break;
1882 case AKM_EAP_SHA256:
1883 str = "WPA-EAP-SHA256";
1884 break;
1885 case AKM_PSK_SHA256:
1886 str = "WPA-PSK-SHA256";
1887 break;
1888 case AKM_SAE:
1889 str = "SAE";
1890 break;
1891 case AKM_FT_SAE:
1892 str = "FT-SAE";
1893 break;
1894 case AKM_SUITE_B:
1895 str = "WPA-EAP-SUITE-B-192";
1896 break;
1897 case AKM_FT_SUITE_B:
1898 str = "FT-EAP-SHA384";
1899 break;
1900 case AKM_FILS_SHA256:
1901 str = "FILS-SHA256";
1902 break;
1903 case AKM_FILS_SHA384:
1904 str = "FILS-SHA384";
1905 break;
1906 case AKM_FT_FILS_SHA256:
1907 str = "FT-FILS-SHA256";
1908 break;
1909 case AKM_FT_FILS_SHA384:
1910 str = "FT-FILS-SHA384";
1911 break;
1912 default:
1913 sigma_dut_print(dut, DUT_MSG_ERROR,
1914 "Unsupported AKMSuitetype %d", akm);
1915 return -1;
1916 }
1917
1918 res = snprintf(pos, end - pos, "%s%s",
1919 pos == key_mgmt ? "" : " ", str);
1920 if (res < 0 || res >= end - pos)
1921 return -1;
1922 pos += res;
1923
1924 in_pos = strchr(in_pos, ';');
1925 if (!in_pos)
1926 break;
1927 while (*in_pos == ';')
1928 in_pos++;
1929 }
1930 sigma_dut_print(dut, DUT_MSG_DEBUG, "AKMSuiteType %s --> %s",
1931 val, key_mgmt);
1932 return set_network(ifname, id, "key_mgmt", key_mgmt);
1933}
1934
1935
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001936static int set_wpa_common(struct sigma_dut *dut, struct sigma_conn *conn,
1937 const char *ifname, struct sigma_cmd *cmd)
1938{
1939 const char *val;
1940 int id;
Jouni Malinenad395a22017-09-01 21:13:46 +03001941 int cipher_set = 0;
Jouni Malinen47dcc952017-10-09 16:43:24 +03001942 int owe;
Sunil Duttc75a1e62018-01-11 20:47:50 +05301943 int suite_b = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001944
1945 id = add_network_common(dut, conn, ifname, cmd);
1946 if (id < 0)
1947 return id;
1948
Jouni Malinen47dcc952017-10-09 16:43:24 +03001949 val = get_param(cmd, "Type");
1950 owe = val && strcasecmp(val, "OWE") == 0;
1951
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001952 val = get_param(cmd, "keyMgmtType");
Jouni Malinen47dcc952017-10-09 16:43:24 +03001953 if (!val && owe)
1954 val = "OWE";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001955 if (val == NULL) {
Jouni Malinene4fde732019-03-25 22:29:37 +02001956 /* keyMgmtType is being replaced with AKMSuiteType, so ignore
1957 * this missing parameter and assume proto=WPA2. */
1958 if (set_network(ifname, id, "proto", "WPA2") < 0)
1959 return ERROR_SEND_STATUS;
1960 } else if (strcasecmp(val, "wpa") == 0 ||
1961 strcasecmp(val, "wpa-psk") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001962 if (set_network(ifname, id, "proto", "WPA") < 0)
1963 return -2;
1964 } else if (strcasecmp(val, "wpa2") == 0 ||
1965 strcasecmp(val, "wpa2-psk") == 0 ||
1966 strcasecmp(val, "wpa2-ft") == 0 ||
1967 strcasecmp(val, "wpa2-sha256") == 0) {
1968 if (set_network(ifname, id, "proto", "WPA2") < 0)
1969 return -2;
Pradeep Reddy POTTETI6d04b3b2016-11-15 14:51:26 +05301970 } else if (strcasecmp(val, "wpa2-wpa-psk") == 0 ||
1971 strcasecmp(val, "wpa2-wpa-ent") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001972 if (set_network(ifname, id, "proto", "WPA WPA2") < 0)
1973 return -2;
Jouni Malinenad395a22017-09-01 21:13:46 +03001974 } else if (strcasecmp(val, "SuiteB") == 0) {
Sunil Duttc75a1e62018-01-11 20:47:50 +05301975 suite_b = 1;
Jouni Malinenad395a22017-09-01 21:13:46 +03001976 if (set_network(ifname, id, "proto", "WPA2") < 0)
1977 return -2;
Jouni Malinen47dcc952017-10-09 16:43:24 +03001978 } else if (strcasecmp(val, "OWE") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001979 } else {
1980 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized keyMgmtType value");
1981 return 0;
1982 }
1983
1984 val = get_param(cmd, "encpType");
Jouni Malinenad395a22017-09-01 21:13:46 +03001985 if (val) {
1986 cipher_set = 1;
1987 if (strcasecmp(val, "tkip") == 0) {
1988 if (set_network(ifname, id, "pairwise", "TKIP") < 0)
1989 return -2;
1990 } else if (strcasecmp(val, "aes-ccmp") == 0) {
1991 if (set_network(ifname, id, "pairwise", "CCMP") < 0)
1992 return -2;
1993 } else if (strcasecmp(val, "aes-ccmp-tkip") == 0) {
1994 if (set_network(ifname, id, "pairwise",
1995 "CCMP TKIP") < 0)
1996 return -2;
1997 } else if (strcasecmp(val, "aes-gcmp") == 0) {
1998 if (set_network(ifname, id, "pairwise", "GCMP") < 0)
1999 return -2;
2000 if (set_network(ifname, id, "group", "GCMP") < 0)
2001 return -2;
2002 } else {
2003 send_resp(dut, conn, SIGMA_ERROR,
2004 "errorCode,Unrecognized encpType value");
2005 return 0;
2006 }
2007 }
2008
2009 val = get_param(cmd, "PairwiseCipher");
2010 if (val) {
2011 cipher_set = 1;
2012 /* TODO: Support space separated list */
2013 if (strcasecmp(val, "AES-GCMP-256") == 0) {
2014 if (set_network(ifname, id, "pairwise", "GCMP-256") < 0)
2015 return -2;
2016 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
2017 if (set_network(ifname, id, "pairwise",
2018 "CCMP-256") < 0)
2019 return -2;
2020 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
2021 if (set_network(ifname, id, "pairwise", "GCMP") < 0)
2022 return -2;
2023 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
2024 if (set_network(ifname, id, "pairwise", "CCMP") < 0)
2025 return -2;
2026 } else {
2027 send_resp(dut, conn, SIGMA_ERROR,
2028 "errorCode,Unrecognized PairwiseCipher value");
2029 return 0;
2030 }
2031 }
2032
Jouni Malinen47dcc952017-10-09 16:43:24 +03002033 if (!cipher_set && !owe) {
Jouni Malinenad395a22017-09-01 21:13:46 +03002034 send_resp(dut, conn, SIGMA_ERROR,
2035 "errorCode,Missing encpType and PairwiseCipher");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002036 return 0;
2037 }
Jouni Malinenad395a22017-09-01 21:13:46 +03002038
2039 val = get_param(cmd, "GroupCipher");
2040 if (val) {
2041 if (strcasecmp(val, "AES-GCMP-256") == 0) {
2042 if (set_network(ifname, id, "group", "GCMP-256") < 0)
2043 return -2;
2044 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
2045 if (set_network(ifname, id, "group", "CCMP-256") < 0)
2046 return -2;
2047 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
2048 if (set_network(ifname, id, "group", "GCMP") < 0)
2049 return -2;
2050 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
2051 if (set_network(ifname, id, "group", "CCMP") < 0)
2052 return -2;
2053 } else {
2054 send_resp(dut, conn, SIGMA_ERROR,
2055 "errorCode,Unrecognized GroupCipher value");
2056 return 0;
2057 }
2058 }
2059
Jouni Malinen7b239522017-09-14 21:37:18 +03002060 val = get_param(cmd, "GroupMgntCipher");
Jouni Malinenad395a22017-09-01 21:13:46 +03002061 if (val) {
Jouni Malinene8898cb2017-09-26 17:55:26 +03002062 const char *cipher;
2063
2064 if (strcasecmp(val, "BIP-GMAC-256") == 0) {
2065 cipher = "BIP-GMAC-256";
2066 } else if (strcasecmp(val, "BIP-CMAC-256") == 0) {
2067 cipher = "BIP-CMAC-256";
2068 } else if (strcasecmp(val, "BIP-GMAC-128") == 0) {
2069 cipher = "BIP-GMAC-128";
2070 } else if (strcasecmp(val, "BIP-CMAC-128") == 0) {
2071 cipher = "AES-128-CMAC";
2072 } else {
2073 send_resp(dut, conn, SIGMA_INVALID,
2074 "errorCode,Unsupported GroupMgntCipher");
2075 return 0;
2076 }
2077 if (set_network(ifname, id, "group_mgmt", cipher) < 0) {
2078 send_resp(dut, conn, SIGMA_INVALID,
2079 "errorCode,Failed to set GroupMgntCipher");
2080 return 0;
2081 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002082 }
2083
Jouni Malinene4fde732019-03-25 22:29:37 +02002084 val = get_param(cmd, "AKMSuiteType");
2085 if (val && set_akm_suites(dut, ifname, id, val) < 0)
2086 return ERROR_SEND_STATUS;
2087
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002088 dut->sta_pmf = STA_PMF_DISABLED;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302089
2090 if (dut->program == PROGRAM_OCE) {
2091 dut->sta_pmf = STA_PMF_OPTIONAL;
2092 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2093 return -2;
2094 }
2095
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002096 val = get_param(cmd, "PMF");
2097 if (val) {
2098 if (strcasecmp(val, "Required") == 0 ||
2099 strcasecmp(val, "Forced_Required") == 0) {
2100 dut->sta_pmf = STA_PMF_REQUIRED;
2101 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2102 return -2;
2103 } else if (strcasecmp(val, "Optional") == 0) {
2104 dut->sta_pmf = STA_PMF_OPTIONAL;
2105 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2106 return -2;
2107 } else if (strcasecmp(val, "Disabled") == 0 ||
Kiran Kumar Lokere07da3b22018-12-16 22:42:49 -08002108 strcasecmp(val, "Disable") == 0 ||
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002109 strcasecmp(val, "Forced_Disabled") == 0) {
2110 dut->sta_pmf = STA_PMF_DISABLED;
2111 } else {
2112 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized PMF value");
2113 return 0;
2114 }
Sunil Duttc75a1e62018-01-11 20:47:50 +05302115 } else if (owe || suite_b) {
Jouni Malinen1287cd72018-01-04 17:08:01 +02002116 dut->sta_pmf = STA_PMF_REQUIRED;
2117 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2118 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002119 }
2120
Jouni Malinen0165c7f2020-03-26 11:51:58 +02002121 val = get_param(cmd, "BeaconProtection");
Veerendranath Jakkamc1f71b62021-01-23 03:09:51 +05302122 if (val)
2123 dut->beacon_prot = atoi(val);
2124 if (dut->beacon_prot && set_network(ifname, id, "beacon_prot", "1") < 0)
Jouni Malinen0165c7f2020-03-26 11:51:58 +02002125 return ERROR_SEND_STATUS;
2126
Veerendranath Jakkam54fd51c2020-12-21 01:36:04 +05302127 if (dut->ocvc && set_network(ifname, id, "ocv", "1") < 0)
2128 return ERROR_SEND_STATUS;
2129
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002130 return id;
2131}
2132
2133
Veerendranath Jakkamca239592021-10-11 20:48:00 +05302134static int wcn_set_ignore_h2e_rsnxe(struct sigma_dut *dut, const char *intf,
2135 uint8_t cfg)
2136{
2137#ifdef NL80211_SUPPORT
2138 return wcn_wifi_test_config_set_u8(
2139 dut, intf,
2140 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_IGNORE_H2E_RSNXE, cfg);
2141#else /* NL80211_SUPPORT */
2142 sigma_dut_print(dut, DUT_MSG_ERROR,
2143 "Ignore SAE H2E requirement mismatch can't be set without NL80211_SUPPORT defined");
2144 return -1;
2145#endif /* NL80211_SUPPORT */
2146}
2147
2148
Jouni Malinenf7222712019-06-13 01:50:21 +03002149static enum sigma_cmd_result cmd_sta_set_psk(struct sigma_dut *dut,
2150 struct sigma_conn *conn,
2151 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002152{
2153 const char *intf = get_param(cmd, "Interface");
Jouni Malinen992a81e2017-08-22 13:57:47 +03002154 const char *type = get_param(cmd, "Type");
Jouni Malinen1287cd72018-01-04 17:08:01 +02002155 const char *pmf = get_param(cmd, "PMF");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002156 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinene4fde732019-03-25 22:29:37 +02002157 const char *akm = get_param(cmd, "AKMSuiteType");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002158 const char *ifname, *val, *alg;
2159 int id;
Jouni Malinen4b3769d2019-10-10 16:20:29 +03002160 char buf[50];
Jouni Malinen11e55212019-11-22 21:46:59 +02002161 int sae_pwe = -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002162
2163 if (intf == NULL)
2164 return -1;
2165
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002166 if (strcmp(intf, get_main_ifname(dut)) == 0)
2167 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002168 else
2169 ifname = intf;
2170
2171 id = set_wpa_common(dut, conn, ifname, cmd);
2172 if (id < 0)
2173 return id;
2174
2175 val = get_param(cmd, "keyMgmtType");
2176 alg = get_param(cmd, "micAlg");
2177
Jouni Malinen992a81e2017-08-22 13:57:47 +03002178 if (type && strcasecmp(type, "SAE") == 0) {
Jouni Malinene4fde732019-03-25 22:29:37 +02002179 if (!akm && val && strcasecmp(val, "wpa2-ft") == 0) {
Jouni Malinen992a81e2017-08-22 13:57:47 +03002180 if (set_network(ifname, id, "key_mgmt", "FT-SAE") < 0)
2181 return -2;
Jouni Malinene4fde732019-03-25 22:29:37 +02002182 } else if (!akm) {
Jouni Malinen992a81e2017-08-22 13:57:47 +03002183 if (set_network(ifname, id, "key_mgmt", "SAE") < 0)
2184 return -2;
2185 }
2186 if (wpa_command(ifname, "SET sae_groups ") != 0) {
2187 sigma_dut_print(dut, DUT_MSG_ERROR,
2188 "Failed to clear sae_groups to default");
2189 return -2;
2190 }
Jouni Malinen1287cd72018-01-04 17:08:01 +02002191 if (!pmf) {
2192 dut->sta_pmf = STA_PMF_REQUIRED;
2193 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2194 return -2;
2195 }
Jouni Malinen0ab50f42017-08-31 01:34:59 +03002196 } else if (type && strcasecmp(type, "PSK-SAE") == 0) {
2197 if (val && strcasecmp(val, "wpa2-ft") == 0) {
2198 if (set_network(ifname, id, "key_mgmt",
2199 "FT-SAE FT-PSK") < 0)
2200 return -2;
Jouni Malinen3b73d872019-06-12 03:13:25 +03002201 } else if (!akm) {
Jouni Malinen0ab50f42017-08-31 01:34:59 +03002202 if (set_network(ifname, id, "key_mgmt",
2203 "SAE WPA-PSK") < 0)
2204 return -2;
2205 }
2206 if (wpa_command(ifname, "SET sae_groups ") != 0) {
2207 sigma_dut_print(dut, DUT_MSG_ERROR,
2208 "Failed to clear sae_groups to default");
2209 return -2;
2210 }
Jouni Malinen1287cd72018-01-04 17:08:01 +02002211 if (!pmf) {
2212 dut->sta_pmf = STA_PMF_OPTIONAL;
2213 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2214 return -2;
2215 }
Jouni Malinen992a81e2017-08-22 13:57:47 +03002216 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002217 if (set_network(ifname, id, "key_mgmt", "WPA-PSK-SHA256") < 0)
2218 return -2;
2219 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
2220 if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0)
2221 return -2;
Ashwini Patil6dbf7b02017-03-20 13:42:11 +05302222 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
2223 if (set_network(ifname, id, "key_mgmt", "FT-PSK") < 0)
2224 return -2;
Jouni Malinen3b73d872019-06-12 03:13:25 +03002225 } else if (!akm &&
2226 ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
2227 dut->sta_pmf == STA_PMF_REQUIRED)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002228 if (set_network(ifname, id, "key_mgmt",
2229 "WPA-PSK WPA-PSK-SHA256") < 0)
2230 return -2;
Jouni Malinen77ff3f02019-03-28 03:45:40 +02002231 } else if (!akm && dut->sta_pmf == STA_PMF_OPTIONAL) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002232 if (set_network(ifname, id, "key_mgmt",
2233 "WPA-PSK WPA-PSK-SHA256") < 0)
2234 return -2;
Jouni Malinen77ff3f02019-03-28 03:45:40 +02002235 } else if (!akm) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002236 if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0)
2237 return -2;
2238 }
2239
2240 val = get_param(cmd, "passPhrase");
2241 if (val == NULL)
2242 return -1;
Jouni Malinen2126f422017-10-11 23:24:33 +03002243 if (type && strcasecmp(type, "SAE") == 0) {
2244 if (set_network_quoted(ifname, id, "sae_password", val) < 0)
2245 return -2;
2246 } else {
2247 if (set_network_quoted(ifname, id, "psk", val) < 0)
2248 return -2;
2249 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002250
Jouni Malinen78d10c42019-03-25 22:34:32 +02002251 val = get_param(cmd, "PasswordId");
2252 if (val && set_network_quoted(ifname, id, "sae_password_id", val) < 0)
2253 return ERROR_SEND_STATUS;
2254
Jouni Malinen992a81e2017-08-22 13:57:47 +03002255 val = get_param(cmd, "ECGroupID");
2256 if (val) {
Jouni Malinenb54f0df2019-12-12 01:57:29 +02002257 snprintf(buf, sizeof(buf), "SET sae_groups %s", val);
Jouni Malinen992a81e2017-08-22 13:57:47 +03002258 if (wpa_command(ifname, buf) != 0) {
2259 sigma_dut_print(dut, DUT_MSG_ERROR,
2260 "Failed to clear sae_groups");
2261 return -2;
2262 }
2263 }
2264
Jouni Malinen68143132017-09-02 02:34:08 +03002265 val = get_param(cmd, "InvalidSAEElement");
2266 if (val) {
2267 free(dut->sae_commit_override);
2268 dut->sae_commit_override = strdup(val);
2269 }
2270
Jouni Malinen4b3769d2019-10-10 16:20:29 +03002271 val = get_param(cmd, "PMKID_Include");
2272 if (val) {
2273 snprintf(buf, sizeof(buf), "SET sae_pmkid_in_assoc %d",
2274 get_enable_disable(val));
2275 wpa_command(intf, buf);
2276 }
2277
Jouni Malineneeb43d32019-12-06 17:40:07 +02002278 val = get_param(cmd, "IgnoreH2E_RSNXE_BSSMemSel");
2279 if (val) {
2280 snprintf(buf, sizeof(buf), "SET ignore_sae_h2e_only %d",
2281 get_enable_disable(val));
2282 wpa_command(intf, buf);
Veerendranath Jakkamca239592021-10-11 20:48:00 +05302283 if (get_driver_type(dut) == DRIVER_WCN)
2284 wcn_set_ignore_h2e_rsnxe(dut, intf,
2285 get_enable_disable(val));
Jouni Malineneeb43d32019-12-06 17:40:07 +02002286 }
2287
Jouni Malinenf2348d22019-12-07 11:52:55 +02002288 val = get_param(cmd, "ECGroupID_RGE");
2289 if (val) {
2290 snprintf(buf, sizeof(buf), "SET extra_sae_rejected_groups %s",
2291 val);
2292 wpa_command(intf, buf);
2293 }
2294
Jouni Malinen99e55022019-12-07 13:59:41 +02002295 val = get_param(cmd, "RSNXE_Content");
2296 if (val) {
2297 const char *param;
2298
2299 if (strncasecmp(val, "AssocReq:", 9) == 0) {
2300 val += 9;
2301 param = "rsnxe_override_assoc";
2302 } else if (strncasecmp(val, "EapolM2:", 8) == 0) {
2303 val += 8;
2304 param = "rsnxe_override_eapol";
2305 } else {
2306 send_resp(dut, conn, SIGMA_ERROR,
2307 "errorCode,Unsupported RSNXE_Content value");
2308 return STATUS_SENT_ERROR;
2309 }
2310 snprintf(buf, sizeof(buf), "SET %s %s", param, val);
2311 wpa_command(intf, buf);
2312 }
2313
Jouni Malinen11e55212019-11-22 21:46:59 +02002314 val = get_param(cmd, "sae_pwe");
2315 if (val) {
2316 if (strcasecmp(val, "h2e") == 0) {
2317 dut->sae_pwe = SAE_PWE_H2E;
Jouni Malinen7244a412019-12-07 11:54:10 +02002318 } else if (strcasecmp(val, "loop") == 0 ||
2319 strcasecmp(val, "looping") == 0) {
Jouni Malinen11e55212019-11-22 21:46:59 +02002320 dut->sae_pwe = SAE_PWE_LOOP;
2321 } else {
2322 send_resp(dut, conn, SIGMA_ERROR,
2323 "errorCode,Unsupported sae_pwe value");
2324 return STATUS_SENT_ERROR;
2325 }
2326 }
Vinita S. Maloo6d7454f2020-04-02 15:03:26 +05302327
2328 val = get_param(cmd, "Clear_RSNXE");
2329 if (val && strcmp(val, "1") == 0 &&
2330 (wpa_command(intf, "SET rsnxe_override_assoc ") ||
2331 wpa_command(intf, "SET rsnxe_override_eapol "))) {
2332 send_resp(dut, conn, SIGMA_ERROR,
2333 "errorCode,Failed to clear RSNXE");
Jouni Malinenb11498c2020-08-03 11:05:53 +03002334 return STATUS_SENT_ERROR;
Vinita S. Maloo6d7454f2020-04-02 15:03:26 +05302335 }
2336
Jouni Malinenc0078772020-03-04 21:23:16 +02002337 if (dut->sae_pwe == SAE_PWE_LOOP && get_param(cmd, "PasswordId"))
2338 sae_pwe = 3;
2339 else if (dut->sae_pwe == SAE_PWE_LOOP)
Jouni Malinen11e55212019-11-22 21:46:59 +02002340 sae_pwe = 0;
2341 else if (dut->sae_pwe == SAE_PWE_H2E)
2342 sae_pwe = 1;
2343 else if (dut->sae_h2e_default)
2344 sae_pwe = 2;
2345 snprintf(buf, sizeof(buf), "SET sae_pwe %d", sae_pwe);
2346 if (sae_pwe >= 0 && wpa_command(ifname, buf) != 0)
2347 return ERROR_SEND_STATUS;
2348
Veerendranath Jakkam0316be12020-06-23 20:11:41 +05302349 val = get_param(cmd, "sae_pk");
2350 if (val && strcmp(val, "0") == 0 &&
2351 set_network(ifname, id, "sae_pk", "2") < 0)
2352 return ERROR_SEND_STATUS;
2353
Veerendranath Jakkama9177042020-08-10 00:14:03 +05302354 val = get_param(cmd, "sae_pk_only");
2355 if (val && strcmp(val, "1") == 0 &&
2356 set_network(ifname, id, "sae_pk", "1") < 0)
2357 return ERROR_SEND_STATUS;
2358
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002359 if (dut->program == PROGRAM_60GHZ && network_mode &&
2360 strcasecmp(network_mode, "PBSS") == 0 &&
2361 set_network(ifname, id, "pbss", "1") < 0)
2362 return -2;
2363
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002364 return 1;
2365}
2366
2367
Jouni Malinen8ac93452019-08-14 15:19:13 +03002368static enum sigma_cmd_result set_trust_root_system(struct sigma_dut *dut,
2369 struct sigma_conn *conn,
2370 const char *ifname, int id)
2371{
2372 char buf[200];
2373
2374 snprintf(buf, sizeof(buf), "%s/certs", sigma_cert_path);
2375 if (!file_exists(buf))
2376 strlcpy(buf, "/system/etc/security/cacerts", sizeof(buf));
2377 if (!file_exists(buf))
2378 strlcpy(buf, "/etc/ssl/certs", sizeof(buf));
2379 if (!file_exists(buf)) {
2380 char msg[300];
2381
2382 snprintf(msg, sizeof(msg),
2383 "ErrorCode,trustedRootCA system store (%s) not found",
2384 buf);
2385 send_resp(dut, conn, SIGMA_ERROR, msg);
2386 return STATUS_SENT_ERROR;
2387 }
2388
2389 if (set_network_quoted(ifname, id, "ca_path", buf) < 0)
2390 return ERROR_SEND_STATUS;
2391
2392 return SUCCESS_SEND_STATUS;
2393}
2394
2395
2396static enum sigma_cmd_result set_trust_root(struct sigma_dut *dut,
2397 struct sigma_conn *conn,
2398 const char *ifname, int id,
2399 const char *val)
2400{
2401 char buf[200];
2402#ifdef ANDROID
2403 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
2404 int length;
2405#endif /* ANDROID */
2406
2407 if (strcmp(val, "DEFAULT") == 0)
2408 return set_trust_root_system(dut, conn, ifname, id);
2409
2410#ifdef ANDROID
2411 snprintf(buf, sizeof(buf), "CACERT_%s", val);
2412 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
2413 if (length > 0) {
2414 sigma_dut_print(dut, DUT_MSG_INFO, "Use Android keystore [%s]",
2415 buf);
2416 snprintf(buf, sizeof(buf), "keystore://CACERT_%s", val);
2417 goto ca_cert_selected;
2418 }
2419#endif /* ANDROID */
2420
2421 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
2422#ifdef __linux__
2423 if (!file_exists(buf)) {
2424 char msg[300];
2425
2426 snprintf(msg, sizeof(msg),
2427 "ErrorCode,trustedRootCA file (%s) not found", buf);
2428 send_resp(dut, conn, SIGMA_ERROR, msg);
2429 return STATUS_SENT_ERROR;
2430 }
2431#endif /* __linux__ */
2432#ifdef ANDROID
2433ca_cert_selected:
2434#endif /* ANDROID */
2435 if (set_network_quoted(ifname, id, "ca_cert", buf) < 0)
2436 return ERROR_SEND_STATUS;
2437
2438 return SUCCESS_SEND_STATUS;
2439}
2440
2441
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002442static int set_eap_common(struct sigma_dut *dut, struct sigma_conn *conn,
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302443 const char *ifname, int username_identity,
2444 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002445{
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002446 const char *val, *alg, *akm, *trust_root, *domain, *domain_suffix;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002447 int id;
Jouni Malinen53264f62019-05-03 13:04:40 +03002448 char buf[200], buf2[300];
Jouni Malinen8179fee2019-03-28 03:19:47 +02002449 int erp = 0;
Jouni Malinen8ac93452019-08-14 15:19:13 +03002450 enum sigma_cmd_result res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002451
2452 id = set_wpa_common(dut, conn, ifname, cmd);
2453 if (id < 0)
2454 return id;
2455
2456 val = get_param(cmd, "keyMgmtType");
2457 alg = get_param(cmd, "micAlg");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302458 akm = get_param(cmd, "AKMSuiteType");
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002459 trust_root = get_param(cmd, "trustedRootCA");
2460 domain = get_param(cmd, "Domain");
2461 domain_suffix = get_param(cmd, "DomainSuffix");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002462
Jouni Malinenad395a22017-09-01 21:13:46 +03002463 if (val && strcasecmp(val, "SuiteB") == 0) {
2464 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SUITE-B-192") <
2465 0)
2466 return -2;
2467 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002468 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SHA256") < 0)
2469 return -2;
2470 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
2471 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
2472 return -2;
2473 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
2474 if (set_network(ifname, id, "key_mgmt", "FT-EAP") < 0)
2475 return -2;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002476 } else if (!akm &&
2477 ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
2478 dut->sta_pmf == STA_PMF_REQUIRED)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002479 if (set_network(ifname, id, "key_mgmt",
2480 "WPA-EAP WPA-EAP-SHA256") < 0)
2481 return -2;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302482 } else if (akm && atoi(akm) == 14) {
2483 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
2484 dut->sta_pmf == STA_PMF_REQUIRED) {
2485 if (set_network(ifname, id, "key_mgmt",
2486 "WPA-EAP-SHA256 FILS-SHA256") < 0)
2487 return -2;
2488 } else {
2489 if (set_network(ifname, id, "key_mgmt",
2490 "WPA-EAP FILS-SHA256") < 0)
2491 return -2;
2492 }
2493
Jouni Malinen8179fee2019-03-28 03:19:47 +02002494 erp = 1;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302495 } else if (akm && atoi(akm) == 15) {
2496 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
2497 dut->sta_pmf == STA_PMF_REQUIRED) {
2498 if (set_network(ifname, id, "key_mgmt",
2499 "WPA-EAP-SHA256 FILS-SHA384") < 0)
2500 return -2;
2501 } else {
2502 if (set_network(ifname, id, "key_mgmt",
2503 "WPA-EAP FILS-SHA384") < 0)
2504 return -2;
2505 }
2506
Jouni Malinen8179fee2019-03-28 03:19:47 +02002507 erp = 1;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002508 } else if (!akm && dut->sta_pmf == STA_PMF_OPTIONAL) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002509 if (set_network(ifname, id, "key_mgmt",
2510 "WPA-EAP WPA-EAP-SHA256") < 0)
2511 return -2;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002512 } else if (!akm) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002513 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
2514 return -2;
2515 }
2516
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002517 if (trust_root) {
2518 if (strcmp(trust_root, "DEFAULT") == 0 && !domain &&
2519 !domain_suffix) {
2520 send_resp(dut, conn, SIGMA_ERROR,
2521 "errorCode,trustRootCA DEFAULT used without specifying Domain or DomainSuffix");
2522 return STATUS_SENT_ERROR;
2523 }
2524 res = set_trust_root(dut, conn, ifname, id, trust_root);
Jouni Malinen8ac93452019-08-14 15:19:13 +03002525 if (res != SUCCESS_SEND_STATUS)
2526 return res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002527 }
2528
Jouni Malinen53264f62019-05-03 13:04:40 +03002529 val = get_param(cmd, "ServerCert");
2530 if (val) {
2531 FILE *f;
2532 char *result = NULL, *pos;
2533
2534 snprintf(buf, sizeof(buf), "%s/%s.sha256", sigma_cert_path,
2535 val);
2536 f = fopen(buf, "r");
2537 if (f) {
2538 result = fgets(buf, sizeof(buf), f);
2539 fclose(f);
2540 }
2541 if (!result) {
2542 snprintf(buf2, sizeof(buf2),
2543 "ErrorCode,ServerCert hash could not be read from %s",
2544 buf);
2545 send_resp(dut, conn, SIGMA_ERROR, buf2);
2546 return STATUS_SENT_ERROR;
2547 }
2548 pos = strchr(buf, '\n');
2549 if (pos)
2550 *pos = '\0';
Jouni Malinen0572a742020-10-08 13:53:25 +03002551 pos = strchr(buf, '\r');
2552 if (pos)
2553 *pos = '\0';
Jouni Malinen53264f62019-05-03 13:04:40 +03002554 snprintf(buf2, sizeof(buf2), "hash://server/sha256/%s", buf);
2555 if (set_network_quoted(ifname, id, "ca_cert", buf2) < 0)
2556 return ERROR_SEND_STATUS;
Jouni Malinen29108dc2019-06-13 23:42:11 +03002557
2558 snprintf(buf, sizeof(buf), "%s/%s.tod", sigma_cert_path, val);
2559 if (file_exists(buf)) {
2560 sigma_dut_print(dut, DUT_MSG_DEBUG,
2561 "TOD policy enabled for the configured ServerCert hash");
2562 dut->sta_tod_policy = 1;
2563 }
Jouni Malinen53264f62019-05-03 13:04:40 +03002564 }
2565
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002566 if (domain &&
2567 set_network_quoted(ifname, id, "domain_match", domain) < 0)
Jouni Malinen96f84b02019-05-03 12:32:56 +03002568 return ERROR_SEND_STATUS;
2569
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002570 if (domain_suffix &&
2571 set_network_quoted(ifname, id, "domain_suffix_match",
2572 domain_suffix) < 0)
Jouni Malinen96f84b02019-05-03 12:32:56 +03002573 return ERROR_SEND_STATUS;
2574
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302575 if (username_identity) {
2576 val = get_param(cmd, "username");
2577 if (val) {
2578 if (set_network_quoted(ifname, id, "identity", val) < 0)
2579 return -2;
2580 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002581
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302582 val = get_param(cmd, "password");
2583 if (val) {
2584 if (set_network_quoted(ifname, id, "password", val) < 0)
2585 return -2;
2586 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002587 }
2588
Jouni Malinen8179fee2019-03-28 03:19:47 +02002589 if (dut->akm_values &
2590 ((1 << AKM_FILS_SHA256) |
2591 (1 << AKM_FILS_SHA384) |
2592 (1 << AKM_FT_FILS_SHA256) |
2593 (1 << AKM_FT_FILS_SHA384)))
2594 erp = 1;
2595 if (erp && set_network(ifname, id, "erp", "1") < 0)
2596 return ERROR_SEND_STATUS;
2597
Jouni Malinen134fe3c2019-06-12 04:16:49 +03002598 dut->sta_associate_wait_connect = 1;
2599
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002600 return id;
2601}
2602
2603
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002604static int set_tls_cipher(const char *ifname, int id, const char *cipher)
2605{
2606 const char *val;
2607
2608 if (!cipher)
2609 return 0;
2610
2611 if (strcasecmp(cipher, "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384") == 0)
2612 val = "ECDHE-ECDSA-AES256-GCM-SHA384";
2613 else if (strcasecmp(cipher,
2614 "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
2615 val = "ECDHE-RSA-AES256-GCM-SHA384";
2616 else if (strcasecmp(cipher, "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
2617 val = "DHE-RSA-AES256-GCM-SHA384";
2618 else if (strcasecmp(cipher,
2619 "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256") == 0)
2620 val = "ECDHE-ECDSA-AES128-GCM-SHA256";
2621 else
2622 return -1;
2623
2624 /* Need to clear phase1="tls_suiteb=1" to allow cipher enforcement */
2625 set_network_quoted(ifname, id, "phase1", "");
2626
2627 return set_network_quoted(ifname, id, "openssl_ciphers", val);
2628}
2629
2630
Jouni Malinenf7222712019-06-13 01:50:21 +03002631static enum sigma_cmd_result cmd_sta_set_eaptls(struct sigma_dut *dut,
2632 struct sigma_conn *conn,
2633 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002634{
2635 const char *intf = get_param(cmd, "Interface");
2636 const char *ifname, *val;
2637 int id;
2638 char buf[200];
2639#ifdef ANDROID
2640 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
2641 int length;
2642 int jb_or_newer = 0;
2643 char prop[PROPERTY_VALUE_MAX];
2644#endif /* ANDROID */
2645
2646 if (intf == NULL)
2647 return -1;
2648
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002649 if (strcmp(intf, get_main_ifname(dut)) == 0)
2650 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002651 else
2652 ifname = intf;
2653
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302654 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002655 if (id < 0)
2656 return id;
2657
2658 if (set_network(ifname, id, "eap", "TLS") < 0)
2659 return -2;
2660
Pradeep Reddy POTTETI9f6c2132016-05-05 16:28:19 +05302661 if (!get_param(cmd, "username") &&
2662 set_network_quoted(ifname, id, "identity",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002663 "wifi-user@wifilabs.local") < 0)
2664 return -2;
2665
2666 val = get_param(cmd, "clientCertificate");
2667 if (val == NULL)
2668 return -1;
2669#ifdef ANDROID
2670 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2671 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
2672 if (length < 0) {
2673 /*
2674 * JB started reporting keystore type mismatches, so retry with
2675 * the GET_PUBKEY command if the generic GET fails.
2676 */
2677 length = android_keystore_get(ANDROID_KEYSTORE_GET_PUBKEY,
2678 buf, kvalue);
2679 }
2680
2681 if (property_get("ro.build.version.release", prop, NULL) != 0) {
2682 sigma_dut_print(dut, DUT_MSG_DEBUG, "Android release %s", prop);
2683 if (strncmp(prop, "4.0", 3) != 0)
2684 jb_or_newer = 1;
2685 } else
2686 jb_or_newer = 1; /* assume newer */
2687
2688 if (jb_or_newer && length > 0) {
2689 sigma_dut_print(dut, DUT_MSG_INFO,
2690 "Use Android keystore [%s]", buf);
2691 if (set_network(ifname, id, "engine", "1") < 0)
2692 return -2;
2693 if (set_network_quoted(ifname, id, "engine_id", "keystore") < 0)
2694 return -2;
2695 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2696 if (set_network_quoted(ifname, id, "key_id", buf) < 0)
2697 return -2;
2698 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2699 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2700 return -2;
2701 return 1;
2702 } else if (length > 0) {
2703 sigma_dut_print(dut, DUT_MSG_INFO,
2704 "Use Android keystore [%s]", buf);
2705 snprintf(buf, sizeof(buf), "keystore://USRPKEY_%s", val);
2706 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2707 return -2;
2708 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2709 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2710 return -2;
2711 return 1;
2712 }
2713#endif /* ANDROID */
2714
2715 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
2716#ifdef __linux__
2717 if (!file_exists(buf)) {
2718 char msg[300];
2719 snprintf(msg, sizeof(msg), "ErrorCode,clientCertificate file "
2720 "(%s) not found", buf);
2721 send_resp(dut, conn, SIGMA_ERROR, msg);
2722 return -3;
2723 }
2724#endif /* __linux__ */
2725 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2726 return -2;
2727 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2728 return -2;
2729
2730 if (set_network_quoted(ifname, id, "private_key_passwd", "wifi") < 0)
2731 return -2;
2732
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002733 val = get_param(cmd, "keyMgmtType");
2734 if (val && strcasecmp(val, "SuiteB") == 0) {
2735 val = get_param(cmd, "CertType");
2736 if (val && strcasecmp(val, "RSA") == 0) {
2737 if (set_network_quoted(ifname, id, "phase1",
2738 "tls_suiteb=1") < 0)
2739 return -2;
2740 } else {
2741 if (set_network_quoted(ifname, id, "openssl_ciphers",
2742 "SUITEB192") < 0)
2743 return -2;
2744 }
2745
2746 val = get_param(cmd, "TLSCipher");
2747 if (set_tls_cipher(ifname, id, val) < 0) {
2748 send_resp(dut, conn, SIGMA_ERROR,
2749 "ErrorCode,Unsupported TLSCipher value");
2750 return -3;
2751 }
2752 }
2753
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002754 return 1;
2755}
2756
2757
Jouni Malinenf7222712019-06-13 01:50:21 +03002758static enum sigma_cmd_result cmd_sta_set_eapttls(struct sigma_dut *dut,
2759 struct sigma_conn *conn,
2760 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002761{
2762 const char *intf = get_param(cmd, "Interface");
2763 const char *ifname;
2764 int id;
2765
2766 if (intf == NULL)
2767 return -1;
2768
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002769 if (strcmp(intf, get_main_ifname(dut)) == 0)
2770 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002771 else
2772 ifname = intf;
2773
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302774 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002775 if (id < 0)
2776 return id;
2777
2778 if (set_network(ifname, id, "eap", "TTLS") < 0) {
2779 send_resp(dut, conn, SIGMA_ERROR,
2780 "errorCode,Failed to set TTLS method");
2781 return 0;
2782 }
2783
2784 if (set_network_quoted(ifname, id, "phase2", "auth=MSCHAPV2") < 0) {
2785 send_resp(dut, conn, SIGMA_ERROR,
2786 "errorCode,Failed to set MSCHAPv2 for TTLS Phase 2");
2787 return 0;
2788 }
2789
2790 return 1;
2791}
2792
2793
Jouni Malinenf7222712019-06-13 01:50:21 +03002794static enum sigma_cmd_result cmd_sta_set_eapsim(struct sigma_dut *dut,
2795 struct sigma_conn *conn,
2796 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002797{
2798 const char *intf = get_param(cmd, "Interface");
2799 const char *ifname;
2800 int id;
2801
2802 if (intf == NULL)
2803 return -1;
2804
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002805 if (strcmp(intf, get_main_ifname(dut)) == 0)
2806 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002807 else
2808 ifname = intf;
2809
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302810 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002811 if (id < 0)
2812 return id;
2813
2814 if (set_network(ifname, id, "eap", "SIM") < 0)
2815 return -2;
2816
2817 return 1;
2818}
2819
2820
Jouni Malinenf7222712019-06-13 01:50:21 +03002821static enum sigma_cmd_result cmd_sta_set_peap(struct sigma_dut *dut,
2822 struct sigma_conn *conn,
2823 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002824{
2825 const char *intf = get_param(cmd, "Interface");
2826 const char *ifname, *val;
2827 int id;
2828 char buf[100];
2829
2830 if (intf == NULL)
2831 return -1;
2832
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002833 if (strcmp(intf, get_main_ifname(dut)) == 0)
2834 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002835 else
2836 ifname = intf;
2837
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302838 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002839 if (id < 0)
2840 return id;
2841
2842 if (set_network(ifname, id, "eap", "PEAP") < 0)
2843 return -2;
2844
2845 val = get_param(cmd, "innerEAP");
2846 if (val) {
2847 if (strcasecmp(val, "MSCHAPv2") == 0) {
2848 if (set_network_quoted(ifname, id, "phase2",
2849 "auth=MSCHAPV2") < 0)
2850 return -2;
2851 } else if (strcasecmp(val, "GTC") == 0) {
2852 if (set_network_quoted(ifname, id, "phase2",
2853 "auth=GTC") < 0)
2854 return -2;
2855 } else
2856 return -1;
2857 }
2858
2859 val = get_param(cmd, "peapVersion");
2860 if (val) {
2861 int ver = atoi(val);
2862 if (ver < 0 || ver > 1)
2863 return -1;
2864 snprintf(buf, sizeof(buf), "peapver=%d", ver);
2865 if (set_network_quoted(ifname, id, "phase1", buf) < 0)
2866 return -2;
2867 }
2868
2869 return 1;
2870}
2871
2872
Jouni Malinenf7222712019-06-13 01:50:21 +03002873static enum sigma_cmd_result cmd_sta_set_eapfast(struct sigma_dut *dut,
2874 struct sigma_conn *conn,
2875 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002876{
2877 const char *intf = get_param(cmd, "Interface");
2878 const char *ifname, *val;
2879 int id;
2880 char buf[100];
2881
2882 if (intf == NULL)
2883 return -1;
2884
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002885 if (strcmp(intf, get_main_ifname(dut)) == 0)
2886 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002887 else
2888 ifname = intf;
2889
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302890 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002891 if (id < 0)
2892 return id;
2893
2894 if (set_network(ifname, id, "eap", "FAST") < 0)
2895 return -2;
2896
2897 val = get_param(cmd, "innerEAP");
2898 if (val) {
2899 if (strcasecmp(val, "MSCHAPV2") == 0) {
2900 if (set_network_quoted(ifname, id, "phase2",
2901 "auth=MSCHAPV2") < 0)
2902 return -2;
2903 } else if (strcasecmp(val, "GTC") == 0) {
2904 if (set_network_quoted(ifname, id, "phase2",
2905 "auth=GTC") < 0)
2906 return -2;
2907 } else
2908 return -1;
2909 }
2910
2911 val = get_param(cmd, "validateServer");
2912 if (val) {
2913 /* TODO */
2914 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored EAP-FAST "
2915 "validateServer=%s", val);
2916 }
2917
2918 val = get_param(cmd, "pacFile");
2919 if (val) {
2920 snprintf(buf, sizeof(buf), "blob://%s", val);
2921 if (set_network_quoted(ifname, id, "pac_file", buf) < 0)
2922 return -2;
2923 }
2924
2925 if (set_network_quoted(ifname, id, "phase1", "fast_provisioning=2") <
2926 0)
2927 return -2;
2928
2929 return 1;
2930}
2931
2932
Jouni Malinenf7222712019-06-13 01:50:21 +03002933static enum sigma_cmd_result cmd_sta_set_eapaka(struct sigma_dut *dut,
2934 struct sigma_conn *conn,
2935 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002936{
2937 const char *intf = get_param(cmd, "Interface");
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302938 const char *username = get_param(cmd, "Username");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002939 const char *ifname;
2940 int id;
2941
2942 if (intf == NULL)
2943 return -1;
2944
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002945 if (strcmp(intf, get_main_ifname(dut)) == 0)
2946 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002947 else
2948 ifname = intf;
2949
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302950 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002951 if (id < 0)
2952 return id;
2953
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302954 /* RFC 5448: EAP-AKA' MUST use the leading character "6" (ASCII 36
2955 * hexadecimal).
2956 */
2957 if (username && username[0] == '6') {
2958 if (set_network(ifname, id, "eap", "AKA'") < 0)
2959 return -2;
2960 } else if (set_network(ifname, id, "eap", "AKA") < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002961 return -2;
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302962 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002963
2964 return 1;
2965}
2966
2967
Jouni Malinenf7222712019-06-13 01:50:21 +03002968static enum sigma_cmd_result cmd_sta_set_eapakaprime(struct sigma_dut *dut,
2969 struct sigma_conn *conn,
2970 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002971{
2972 const char *intf = get_param(cmd, "Interface");
2973 const char *ifname;
2974 int id;
2975
2976 if (intf == NULL)
2977 return -1;
2978
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002979 if (strcmp(intf, get_main_ifname(dut)) == 0)
2980 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002981 else
2982 ifname = intf;
2983
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302984 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002985 if (id < 0)
2986 return id;
2987
2988 if (set_network(ifname, id, "eap", "AKA'") < 0)
2989 return -2;
2990
2991 return 1;
2992}
2993
2994
2995static int sta_set_open(struct sigma_dut *dut, struct sigma_conn *conn,
2996 struct sigma_cmd *cmd)
2997{
2998 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002999 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003000 const char *ifname;
3001 int id;
3002
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003003 if (strcmp(intf, get_main_ifname(dut)) == 0)
3004 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003005 else
3006 ifname = intf;
3007
3008 id = add_network_common(dut, conn, ifname, cmd);
3009 if (id < 0)
3010 return id;
3011
3012 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
3013 return -2;
3014
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003015 if (dut->program == PROGRAM_60GHZ && network_mode &&
3016 strcasecmp(network_mode, "PBSS") == 0 &&
3017 set_network(ifname, id, "pbss", "1") < 0)
3018 return -2;
3019
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003020 return 1;
3021}
3022
3023
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003024static enum sigma_cmd_result sta_set_owe(struct sigma_dut *dut,
3025 struct sigma_conn *conn,
3026 struct sigma_cmd *cmd)
Jouni Malinen47dcc952017-10-09 16:43:24 +03003027{
3028 const char *intf = get_param(cmd, "Interface");
3029 const char *ifname, *val;
3030 int id;
3031
3032 if (intf == NULL)
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003033 return INVALID_SEND_STATUS;
Jouni Malinen47dcc952017-10-09 16:43:24 +03003034
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003035 if (strcmp(intf, get_main_ifname(dut)) == 0)
3036 ifname = get_station_ifname(dut);
Jouni Malinen47dcc952017-10-09 16:43:24 +03003037 else
3038 ifname = intf;
3039
3040 id = set_wpa_common(dut, conn, ifname, cmd);
3041 if (id < 0)
3042 return id;
3043
3044 if (set_network(ifname, id, "key_mgmt", "OWE") < 0)
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003045 return ERROR_SEND_STATUS;
Jouni Malinen47dcc952017-10-09 16:43:24 +03003046
Hu Wangdd5eed22020-07-16 12:18:03 +08003047 if (dut->owe_ptk_workaround &&
3048 set_network(ifname, id, "owe_ptk_workaround", "1") < 0) {
3049 sigma_dut_print(dut, DUT_MSG_ERROR,
3050 "Failed to set owe_ptk_workaround to 1");
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003051 return ERROR_SEND_STATUS;
Hu Wangdd5eed22020-07-16 12:18:03 +08003052 }
3053
Jouni Malinen47dcc952017-10-09 16:43:24 +03003054 val = get_param(cmd, "ECGroupID");
Jouni Malinenfac9cad2017-10-10 18:35:55 +03003055 if (val && strcmp(val, "0") == 0) {
3056 if (wpa_command(ifname,
3057 "VENDOR_ELEM_ADD 13 ff23200000783590fb7440e03d5b3b33911f86affdcc6b4411b707846ac4ff08ddc8831ccd") != 0) {
3058 sigma_dut_print(dut, DUT_MSG_ERROR,
3059 "Failed to set OWE DH Param element override");
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003060 return ERROR_SEND_STATUS;
Jouni Malinenfac9cad2017-10-10 18:35:55 +03003061 }
Hu Wangdd5eed22020-07-16 12:18:03 +08003062 } else if (val && set_network(ifname, id, "owe_group", val) < 0) {
Jouni Malinen47dcc952017-10-09 16:43:24 +03003063 sigma_dut_print(dut, DUT_MSG_ERROR,
Hu Wang6010ce72020-03-05 19:33:53 +08003064 "Failed to set owe_group");
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003065 return ERROR_SEND_STATUS;
Jouni Malinen47dcc952017-10-09 16:43:24 +03003066 }
3067
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003068 return SUCCESS_SEND_STATUS;
Jouni Malinen47dcc952017-10-09 16:43:24 +03003069}
3070
3071
Jouni Malinenf7222712019-06-13 01:50:21 +03003072static enum sigma_cmd_result cmd_sta_set_security(struct sigma_dut *dut,
3073 struct sigma_conn *conn,
3074 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003075{
3076 const char *type = get_param(cmd, "Type");
3077
3078 if (type == NULL) {
3079 send_resp(dut, conn, SIGMA_ERROR,
3080 "ErrorCode,Missing Type argument");
3081 return 0;
3082 }
3083
3084 if (strcasecmp(type, "OPEN") == 0)
3085 return sta_set_open(dut, conn, cmd);
Jouni Malinen47dcc952017-10-09 16:43:24 +03003086 if (strcasecmp(type, "OWE") == 0)
3087 return sta_set_owe(dut, conn, cmd);
Jouni Malinen992a81e2017-08-22 13:57:47 +03003088 if (strcasecmp(type, "PSK") == 0 ||
Jouni Malinen0ab50f42017-08-31 01:34:59 +03003089 strcasecmp(type, "PSK-SAE") == 0 ||
Jouni Malinen992a81e2017-08-22 13:57:47 +03003090 strcasecmp(type, "SAE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003091 return cmd_sta_set_psk(dut, conn, cmd);
3092 if (strcasecmp(type, "EAPTLS") == 0)
3093 return cmd_sta_set_eaptls(dut, conn, cmd);
3094 if (strcasecmp(type, "EAPTTLS") == 0)
3095 return cmd_sta_set_eapttls(dut, conn, cmd);
3096 if (strcasecmp(type, "EAPPEAP") == 0)
3097 return cmd_sta_set_peap(dut, conn, cmd);
3098 if (strcasecmp(type, "EAPSIM") == 0)
3099 return cmd_sta_set_eapsim(dut, conn, cmd);
3100 if (strcasecmp(type, "EAPFAST") == 0)
3101 return cmd_sta_set_eapfast(dut, conn, cmd);
3102 if (strcasecmp(type, "EAPAKA") == 0)
3103 return cmd_sta_set_eapaka(dut, conn, cmd);
3104 if (strcasecmp(type, "EAPAKAPRIME") == 0)
3105 return cmd_sta_set_eapakaprime(dut, conn, cmd);
Amarnath Hullur Subramanyam81b11cd2018-01-30 19:07:17 -08003106 if (strcasecmp(type, "wep") == 0)
3107 return cmd_sta_set_encryption(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003108
3109 send_resp(dut, conn, SIGMA_ERROR,
3110 "ErrorCode,Unsupported Type value");
3111 return 0;
3112}
3113
3114
3115int ath6kl_client_uapsd(struct sigma_dut *dut, const char *intf, int uapsd)
3116{
3117#ifdef __linux__
3118 /* special handling for ath6kl */
3119 char path[128], fname[128], *pos;
3120 ssize_t res;
3121 FILE *f;
3122
Jouni Malinene39cd562019-05-29 23:39:56 +03003123 res = snprintf(fname, sizeof(fname), "/sys/class/net/%s/phy80211",
3124 intf);
3125 if (res < 0 || res >= sizeof(fname))
3126 return 0;
3127 res = readlink(fname, path, sizeof(path));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003128 if (res < 0)
3129 return 0; /* not ath6kl */
3130
3131 if (res >= (int) sizeof(path))
3132 res = sizeof(path) - 1;
3133 path[res] = '\0';
3134 pos = strrchr(path, '/');
3135 if (pos == NULL)
3136 pos = path;
3137 else
3138 pos++;
Jouni Malinen77dda642020-01-07 11:21:55 +02003139 res = snprintf(fname, sizeof(fname),
3140 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
3141 "create_qos", pos);
3142 if (res < 0 || res >= sizeof(fname) || !file_exists(fname))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003143 return 0; /* not ath6kl */
3144
3145 if (uapsd) {
3146 f = fopen(fname, "w");
3147 if (f == NULL)
3148 return -1;
3149
3150 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl create_qos");
3151 fprintf(f, "4 2 2 1 2 9999999 9999999 9999999 7777777 0 4 "
3152 "45000 200 56789000 56789000 5678900 0 0 9999999 "
3153 "20000 0\n");
3154 fclose(f);
3155 } else {
Jouni Malinen77dda642020-01-07 11:21:55 +02003156 res = snprintf(fname, sizeof(fname),
3157 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
3158 "delete_qos", pos);
3159 if (res < 0 || res >= sizeof(fname))
3160 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003161
3162 f = fopen(fname, "w");
3163 if (f == NULL)
3164 return -1;
3165
3166 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl delete_qos");
3167 fprintf(f, "2 4\n");
3168 fclose(f);
3169 }
3170#endif /* __linux__ */
3171
3172 return 0;
3173}
3174
3175
Jouni Malinenf7222712019-06-13 01:50:21 +03003176static enum sigma_cmd_result cmd_sta_set_uapsd(struct sigma_dut *dut,
3177 struct sigma_conn *conn,
3178 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003179{
3180 const char *intf = get_param(cmd, "Interface");
3181 /* const char *ssid = get_param(cmd, "ssid"); */
3182 const char *val;
3183 int max_sp_len = 4;
3184 int ac_be = 1, ac_bk = 1, ac_vi = 1, ac_vo = 1;
3185 char buf[100];
3186 int ret1, ret2;
3187
3188 val = get_param(cmd, "maxSPLength");
3189 if (val) {
3190 max_sp_len = atoi(val);
3191 if (max_sp_len != 0 && max_sp_len != 1 && max_sp_len != 2 &&
3192 max_sp_len != 4)
3193 return -1;
3194 }
3195
3196 val = get_param(cmd, "acBE");
3197 if (val)
3198 ac_be = atoi(val);
3199
3200 val = get_param(cmd, "acBK");
3201 if (val)
3202 ac_bk = atoi(val);
3203
3204 val = get_param(cmd, "acVI");
3205 if (val)
3206 ac_vi = atoi(val);
3207
3208 val = get_param(cmd, "acVO");
3209 if (val)
3210 ac_vo = atoi(val);
3211
3212 dut->client_uapsd = ac_be || ac_bk || ac_vi || ac_vo;
3213
3214 snprintf(buf, sizeof(buf), "P2P_SET client_apsd %d,%d,%d,%d;%d",
3215 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
3216 ret1 = wpa_command(intf, buf);
3217
3218 snprintf(buf, sizeof(buf), "SET uapsd %d,%d,%d,%d;%d",
3219 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
3220 ret2 = wpa_command(intf, buf);
3221
3222 if (ret1 && ret2) {
3223 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to set client mode "
3224 "UAPSD parameters.");
3225 return -2;
3226 }
3227
3228 if (ath6kl_client_uapsd(dut, intf, dut->client_uapsd) < 0) {
3229 send_resp(dut, conn, SIGMA_ERROR,
3230 "ErrorCode,Failed to set ath6kl QoS parameters");
3231 return 0;
3232 }
3233
3234 return 1;
3235}
3236
3237
Jouni Malinenf7222712019-06-13 01:50:21 +03003238static enum sigma_cmd_result cmd_sta_set_wmm(struct sigma_dut *dut,
3239 struct sigma_conn *conn,
3240 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003241{
3242 char buf[1000];
3243 const char *intf = get_param(cmd, "Interface");
3244 const char *grp = get_param(cmd, "Group");
3245 const char *act = get_param(cmd, "Action");
3246 const char *tid = get_param(cmd, "Tid");
3247 const char *dir = get_param(cmd, "Direction");
3248 const char *psb = get_param(cmd, "Psb");
3249 const char *up = get_param(cmd, "Up");
3250 const char *fixed = get_param(cmd, "Fixed");
3251 const char *size = get_param(cmd, "Size");
3252 const char *msize = get_param(cmd, "Maxsize");
3253 const char *minsi = get_param(cmd, "Min_srvc_intrvl");
3254 const char *maxsi = get_param(cmd, "Max_srvc_intrvl");
3255 const char *inact = get_param(cmd, "Inactivity");
3256 const char *sus = get_param(cmd, "Suspension");
3257 const char *mindr = get_param(cmd, "Mindatarate");
3258 const char *meandr = get_param(cmd, "Meandatarate");
3259 const char *peakdr = get_param(cmd, "Peakdatarate");
3260 const char *phyrate = get_param(cmd, "Phyrate");
3261 const char *burstsize = get_param(cmd, "Burstsize");
3262 const char *sba = get_param(cmd, "Sba");
3263 int direction;
3264 int handle;
Peng Xu93319622017-10-04 17:58:16 -07003265 float sba_fv = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003266 int fixed_int;
3267 int psb_ts;
3268
3269 if (intf == NULL || grp == NULL || act == NULL )
3270 return -1;
3271
3272 if (strcasecmp(act, "addts") == 0) {
3273 if (tid == NULL || dir == NULL || psb == NULL ||
3274 up == NULL || fixed == NULL || size == NULL)
3275 return -1;
3276
3277 /*
3278 * Note: Sigma CAPI spec lists uplink, downlink, and bidi as the
3279 * possible values, but WMM-AC and V-E test scripts use "UP,
3280 * "DOWN", and "BIDI".
3281 */
3282 if (strcasecmp(dir, "uplink") == 0 ||
3283 strcasecmp(dir, "up") == 0) {
3284 direction = 0;
3285 } else if (strcasecmp(dir, "downlink") == 0 ||
3286 strcasecmp(dir, "down") == 0) {
3287 direction = 1;
3288 } else if (strcasecmp(dir, "bidi") == 0) {
3289 direction = 2;
3290 } else {
3291 sigma_dut_print(dut, DUT_MSG_ERROR,
3292 "Direction %s not supported", dir);
3293 return -1;
3294 }
3295
3296 if (strcasecmp(psb, "legacy") == 0) {
3297 psb_ts = 0;
3298 } else if (strcasecmp(psb, "uapsd") == 0) {
3299 psb_ts = 1;
3300 } else {
3301 sigma_dut_print(dut, DUT_MSG_ERROR,
3302 "PSB %s not supported", psb);
3303 return -1;
3304 }
3305
3306 if (atoi(tid) < 0 || atoi(tid) > 7) {
3307 sigma_dut_print(dut, DUT_MSG_ERROR,
3308 "TID %s not supported", tid);
3309 return -1;
3310 }
3311
3312 if (strcasecmp(fixed, "true") == 0) {
3313 fixed_int = 1;
3314 } else {
3315 fixed_int = 0;
3316 }
3317
Peng Xu93319622017-10-04 17:58:16 -07003318 if (sba)
3319 sba_fv = atof(sba);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003320
3321 dut->dialog_token++;
3322 handle = 7000 + dut->dialog_token;
3323
3324 /*
3325 * size: convert to hex
3326 * maxsi: convert to hex
3327 * mindr: convert to hex
3328 * meandr: convert to hex
3329 * peakdr: convert to hex
3330 * burstsize: convert to hex
3331 * phyrate: convert to hex
3332 * sba: convert to hex with modification
3333 * minsi: convert to integer
3334 * sus: convert to integer
3335 * inact: convert to integer
3336 * maxsi: convert to integer
3337 */
3338
3339 /*
3340 * The Nominal MSDU Size field is 2 octets long and contains an
3341 * unsigned integer that specifies the nominal size, in octets,
3342 * of MSDUs belonging to the traffic under this traffic
3343 * specification and is defined in Figure 16. If the Fixed
3344 * subfield is set to 1, then the size of the MSDU is fixed and
3345 * is indicated by the Size Subfield. If the Fixed subfield is
3346 * set to 0, then the size of the MSDU might not be fixed and
3347 * the Size indicates the nominal MSDU size.
3348 *
3349 * The Surplus Bandwidth Allowance Factor field is 2 octets long
3350 * and specifies the excess allocation of time (and bandwidth)
3351 * over and above the stated rates required to transport an MSDU
3352 * belonging to the traffic in this TSPEC. This field is
3353 * represented as an unsigned binary number with an implicit
3354 * binary point after the leftmost 3 bits. For example, an SBA
3355 * of 1.75 is represented as 0x3800. This field is included to
3356 * account for retransmissions. As such, the value of this field
3357 * must be greater than unity.
3358 */
3359
3360 snprintf(buf, sizeof(buf),
3361 "iwpriv %s addTspec %d %s %d %d %s 0x%X"
3362 " 0x%X 0x%X 0x%X"
3363 " 0x%X 0x%X 0x%X"
3364 " 0x%X %d %d %d %d"
3365 " %d %d",
3366 intf, handle, tid, direction, psb_ts, up,
3367 (unsigned int) ((fixed_int << 15) | atoi(size)),
3368 msize ? atoi(msize) : 0,
3369 mindr ? atoi(mindr) : 0,
3370 meandr ? atoi(meandr) : 0,
3371 peakdr ? atoi(peakdr) : 0,
3372 burstsize ? atoi(burstsize) : 0,
3373 phyrate ? atoi(phyrate) : 0,
3374 sba ? ((unsigned int) (((int) sba_fv << 13) |
3375 (int)((sba_fv - (int) sba_fv) *
3376 8192))) : 0,
3377 minsi ? atoi(minsi) : 0,
3378 sus ? atoi(sus) : 0,
3379 0, 0,
3380 inact ? atoi(inact) : 0,
3381 maxsi ? atoi(maxsi) : 0);
3382
3383 if (system(buf) != 0) {
3384 sigma_dut_print(dut, DUT_MSG_ERROR,
3385 "iwpriv addtspec request failed");
3386 send_resp(dut, conn, SIGMA_ERROR,
3387 "errorCode,Failed to execute addTspec command");
3388 return 0;
3389 }
3390
3391 sigma_dut_print(dut, DUT_MSG_INFO,
3392 "iwpriv addtspec request send");
3393
3394 /* Mapping handle to a TID */
3395 dut->tid_to_handle[atoi(tid)] = handle;
3396 } else if (strcasecmp(act, "delts") == 0) {
3397 if (tid == NULL)
3398 return -1;
3399
3400 if (atoi(tid) < 0 || atoi(tid) > 7) {
3401 sigma_dut_print(dut, DUT_MSG_ERROR,
3402 "TID %s not supported", tid);
3403 send_resp(dut, conn, SIGMA_ERROR,
3404 "errorCode,Unsupported TID");
3405 return 0;
3406 }
3407
3408 handle = dut->tid_to_handle[atoi(tid)];
3409
3410 if (handle < 7000 || handle > 7255) {
3411 /* Invalid handle ie no mapping for that TID */
3412 sigma_dut_print(dut, DUT_MSG_ERROR,
3413 "handle-> %d not found", handle);
3414 }
3415
3416 snprintf(buf, sizeof(buf), "iwpriv %s delTspec %d",
3417 intf, handle);
3418
3419 if (system(buf) != 0) {
3420 sigma_dut_print(dut, DUT_MSG_ERROR,
3421 "iwpriv deltspec request failed");
3422 send_resp(dut, conn, SIGMA_ERROR,
3423 "errorCode,Failed to execute delTspec command");
3424 return 0;
3425 }
3426
3427 sigma_dut_print(dut, DUT_MSG_INFO,
3428 "iwpriv deltspec request send");
3429
3430 dut->tid_to_handle[atoi(tid)] = 0;
3431 } else {
3432 sigma_dut_print(dut, DUT_MSG_ERROR,
3433 "Action type %s not supported", act);
3434 send_resp(dut, conn, SIGMA_ERROR,
3435 "errorCode,Unsupported Action");
3436 return 0;
3437 }
3438
3439 return 1;
3440}
3441
3442
vamsi krishna52e16f92017-08-29 12:37:34 +05303443static int find_network(struct sigma_dut *dut, const char *ssid)
3444{
3445 char list[4096];
3446 char *pos;
3447
3448 sigma_dut_print(dut, DUT_MSG_DEBUG,
3449 "Search for profile based on SSID: '%s'", ssid);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003450 if (wpa_command_resp(get_station_ifname(dut), "LIST_NETWORKS",
vamsi krishna52e16f92017-08-29 12:37:34 +05303451 list, sizeof(list)) < 0)
3452 return -1;
3453 pos = strstr(list, ssid);
3454 if (!pos || pos == list || pos[-1] != '\t' || pos[strlen(ssid)] != '\t')
3455 return -1;
3456
3457 while (pos > list && pos[-1] != '\n')
3458 pos--;
3459 dut->infra_network_id = atoi(pos);
3460 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
3461 return 0;
3462}
3463
3464
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303465/**
3466 * enum qca_sta_helper_config_params - This helper enum defines the config
3467 * parameters which can be delivered to sta.
3468 */
3469enum qca_sta_helper_config_params {
3470 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE */
3471 STA_SET_RSNIE,
3472
3473 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_LDPC */
3474 STA_SET_LDPC,
3475
3476 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_TX_STBC */
3477 STA_SET_TX_STBC,
3478
3479 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_RX_STBC */
3480 STA_SET_RX_STBC,
3481
3482 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_TX_MSDU_AGGREGATION */
3483 STA_SET_TX_MSDU,
3484
3485 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_RX_MSDU_AGGREGATION */
3486 STA_SET_RX_MSDU,
Shivani Baranwal2a572842021-09-16 12:27:15 +05303487
3488 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_CHANNEL_WIDTH */
3489 STA_SET_CHAN_WIDTH,
Shivani Baranwal7aa48602021-09-29 10:53:38 +05303490
3491 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_FT_OVER_DS */
3492 STA_SET_FT_DS,
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303493};
3494
3495
3496static int sta_config_params(struct sigma_dut *dut, const char *intf,
3497 enum qca_sta_helper_config_params config_cmd,
3498 int value)
Sunil Dutt44595082018-02-12 19:41:45 +05303499{
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303500#ifdef NL80211_SUPPORT
Sunil Dutt44595082018-02-12 19:41:45 +05303501 struct nl_msg *msg;
3502 int ret;
3503 struct nlattr *params;
3504 int ifindex;
3505
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303506 ifindex = if_nametoindex(intf);
3507 if (ifindex == 0) {
3508 sigma_dut_print(dut, DUT_MSG_ERROR,
3509 "%s: Interface %s does not exist",
3510 __func__, intf);
3511 return -1;
3512 }
3513
Sunil Dutt44595082018-02-12 19:41:45 +05303514 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
3515 NL80211_CMD_VENDOR)) ||
3516 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
3517 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
3518 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
3519 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) ||
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303520 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)))
3521 goto fail;
3522
3523 switch (config_cmd) {
3524 case STA_SET_RSNIE:
3525 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE, value))
3526 goto fail;
3527 break;
3528 case STA_SET_LDPC:
3529 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_LDPC, value))
3530 goto fail;
3531 break;
3532 case STA_SET_TX_STBC:
3533 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TX_STBC, value))
3534 goto fail;
3535 break;
3536 case STA_SET_RX_STBC:
3537 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_RX_STBC, value))
3538 goto fail;
3539 break;
3540 case STA_SET_TX_MSDU:
3541 if (nla_put_u8(msg,
3542 QCA_WLAN_VENDOR_ATTR_CONFIG_TX_MSDU_AGGREGATION,
3543 value))
3544 goto fail;
3545 break;
3546 case STA_SET_RX_MSDU:
3547 if (nla_put_u8(msg,
3548 QCA_WLAN_VENDOR_ATTR_CONFIG_RX_MSDU_AGGREGATION,
3549 value))
3550 goto fail;
3551 break;
Shivani Baranwal2a572842021-09-16 12:27:15 +05303552 case STA_SET_CHAN_WIDTH:
3553 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_CHANNEL_WIDTH,
3554 value))
3555 goto fail;
3556 break;
Shivani Baranwal7aa48602021-09-29 10:53:38 +05303557 case STA_SET_FT_DS:
3558 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_FT_OVER_DS,
3559 value))
3560 goto fail;
3561 break;
Sunil Dutt44595082018-02-12 19:41:45 +05303562 }
3563 nla_nest_end(msg, params);
3564
3565 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
3566 if (ret) {
3567 sigma_dut_print(dut, DUT_MSG_ERROR,
3568 "%s: err in send_and_recv_msgs, ret=%d",
3569 __func__, ret);
3570 return ret;
3571 }
3572
3573 return 0;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303574
3575fail:
3576 sigma_dut_print(dut, DUT_MSG_ERROR,
3577 "%s: err in adding vendor_cmd and vendor_data",
3578 __func__);
3579 nlmsg_free(msg);
Sunil Dutt44595082018-02-12 19:41:45 +05303580#endif /* NL80211_SUPPORT */
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303581 return -1;
3582}
Sunil Dutt44595082018-02-12 19:41:45 +05303583
3584
Veerendranath Jakkam9ceb3b12021-09-10 03:18:17 +05303585void free_dscp_policy_table(struct sigma_dut *dut)
3586{
3587 struct dscp_policy_data *dscp_policy;
3588
3589 while (dut->dscp_policy_table) {
3590 dscp_policy = dut->dscp_policy_table;
3591 dut->dscp_policy_table = dscp_policy->next;
3592 free(dscp_policy);
3593 }
3594}
3595
3596
Shivani Baranwal9cfc8d72021-11-22 11:53:19 +05303597static char * protocol_to_str(int proto)
3598{
3599 switch (proto) {
3600 case 6:
3601 return "tcp";
3602 case 17:
3603 return "udp";
3604 case 50:
3605 return "esp";
3606 default:
3607 return "unknown";
3608 }
3609}
3610
3611
Veerendranath Jakkam9ceb3b12021-09-10 03:18:17 +05303612static int delete_nft_table(struct sigma_dut *dut, const char *table,
3613 const char *ip_type)
3614{
3615 int res;
3616 char cmd[200];
3617
3618 res = snprintf(cmd, sizeof(cmd), "nft delete table %s %s_%s", ip_type,
3619 table, ip_type);
3620 if (snprintf_error(sizeof(cmd), res)) {
3621 sigma_dut_print(dut, DUT_MSG_ERROR,
3622 "Failed to create delete table command");
3623 return -1;
3624 }
3625
3626 if (system(cmd) != 0) {
3627 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run %s", cmd);
3628 return -1;
3629 }
3630
3631 return 0;
3632}
3633
3634
3635static int remove_nft_rule(struct sigma_dut *dut, int policy_id,
3636 enum ip_version ip_ver)
3637{
3638 int res;
3639 char table[50];
3640
3641 res = snprintf(table, sizeof(table), "wifi_%s_dscp_policy_%d",
3642 dut->station_ifname, policy_id);
3643 if (snprintf_error(sizeof(table), res)) {
3644 sigma_dut_print(dut, DUT_MSG_INFO,
3645 "Failed to create table name for policy %d",
3646 policy_id);
3647 return -1;
3648 }
3649
3650
3651 if (ip_ver == IPV6)
3652 return delete_nft_table(dut, table, "ip6");
3653 else
3654 return delete_nft_table(dut, table, "ip");
3655}
3656
3657
Shivani Baranwal9cfc8d72021-11-22 11:53:19 +05303658static int remove_iptable_rule(struct sigma_dut *dut,
3659 struct dscp_policy_data *dscp_policy)
3660{
3661 char ip_cmd[1000];
3662 char *pos;
3663 int ret, len;
3664 enum ip_version ip_ver = dscp_policy->ip_version;
3665
3666 pos = ip_cmd;
3667 len = sizeof(ip_cmd);
3668
3669 ret = snprintf(pos, len,
Shivani Baranwalbf2b5212021-12-08 16:38:23 +05303670 "%s -t mangle -D OUTPUT -o %s",
3671#ifdef ANDROID
3672 ip_ver == IPV6 ? "/system/bin/ip6tables" : "/system/bin/iptables",
3673#else /* ANDROID */
Shivani Baranwal9cfc8d72021-11-22 11:53:19 +05303674 ip_ver == IPV6 ? "ip6tables" : "iptables",
Shivani Baranwalbf2b5212021-12-08 16:38:23 +05303675#endif /* ANDROID */
Shivani Baranwal9cfc8d72021-11-22 11:53:19 +05303676 dut->station_ifname);
3677 if (snprintf_error(len, ret)) {
3678 sigma_dut_print(dut, DUT_MSG_INFO,
3679 "Failed to create delete iptables command %s",
3680 ip_cmd);
3681 return -1;
3682 }
3683
3684 pos += ret;
3685 len -= ret;
3686
3687 if (strlen(dscp_policy->src_ip)) {
3688 ret = snprintf(pos, len, " -s %s", dscp_policy->src_ip);
3689 if (snprintf_error(len, ret)) {
3690 sigma_dut_print(dut, DUT_MSG_INFO,
3691 "Error in adding src_ip %s in delete command",
3692 dscp_policy->src_ip);
3693 return -1;
3694 }
3695 pos += ret;
3696 len -= ret;
3697 }
3698
3699 if (strlen(dscp_policy->dst_ip)) {
3700 ret = snprintf(pos, len, " -d %s",
3701 dscp_policy->dst_ip);
3702 if (snprintf_error(len, ret)) {
3703 sigma_dut_print(dut, DUT_MSG_INFO,
3704 "Error in adding dst_ip %s in delete cmd",
3705 dscp_policy->dst_ip);
3706 return -1;
3707 }
3708 pos += ret;
3709 len -= ret;
3710 }
3711
3712 if (dscp_policy->src_port || dscp_policy->dst_port ||
3713 (dscp_policy->start_port && dscp_policy->end_port)) {
3714 ret = snprintf(pos, len, " -p %s",
3715 protocol_to_str(dscp_policy->protocol));
3716 if (snprintf_error(len, ret)) {
3717 sigma_dut_print(dut, DUT_MSG_INFO,
3718 "Error in adding protocol %d in delete command",
3719 dscp_policy->protocol);
3720 return -1;
3721 }
3722 pos += ret;
3723 len -= ret;
3724 }
3725
3726 if (dscp_policy->src_port) {
3727 ret = snprintf(pos, len, " --sport %d",
3728 dscp_policy->src_port);
3729 if (snprintf_error(len, ret)) {
3730 sigma_dut_print(dut, DUT_MSG_INFO,
3731 "Error in adding src_port %d in delete command",
3732 dscp_policy->src_port);
3733 return -1;
3734 }
3735 pos += ret;
3736 len -= ret;
3737 }
3738
3739 if (dscp_policy->dst_port) {
3740 ret = snprintf(pos, len, " --dport %d",
3741 dscp_policy->dst_port);
3742 if (snprintf_error(len, ret)) {
3743 sigma_dut_print(dut, DUT_MSG_INFO,
3744 "Error in adding dst_port %d in delete command",
3745 dscp_policy->dst_port);
3746 return -1;
3747 }
3748 pos += ret;
3749 len -= ret;
3750 }
3751
3752 if (dscp_policy->start_port && dscp_policy->end_port) {
3753 ret = snprintf(pos, len, " --match multiport --dports %d:%d",
3754 dscp_policy->start_port,
3755 dscp_policy->end_port);
3756 if (snprintf_error(len, ret)) {
3757 sigma_dut_print(dut, DUT_MSG_INFO,
3758 "Error in adding start:end port %d:%d in delete command",
3759 dscp_policy->start_port,
3760 dscp_policy->end_port);
3761 return -1;
3762 }
3763 pos += ret;
3764 len -= ret;
3765 }
3766
3767 ret = snprintf(pos, len, " -j DSCP --set-dscp 0x%0x",
3768 dscp_policy->dscp);
3769 if (snprintf_error(len, ret)) {
3770 sigma_dut_print(dut, DUT_MSG_INFO,
3771 "Error in adding dscp %0x in delete command",
3772 dscp_policy->dscp);
3773 return -1;
3774 }
3775 ret = system(ip_cmd);
3776 sigma_dut_print(dut, DUT_MSG_DEBUG, "iptables rule: %s err: %d",
3777 ip_cmd, ret);
3778
3779 return ret;
3780}
3781
3782
3783static int remove_dscp_policy_rule(struct sigma_dut *dut,
3784 struct dscp_policy_data *dscp_policy)
3785{
3786 return dut->dscp_use_iptables ? remove_iptable_rule(dut, dscp_policy) :
3787 remove_nft_rule(dut, dscp_policy->policy_id,
3788 dscp_policy->ip_version);
3789}
3790
3791
Veerendranath Jakkam9ceb3b12021-09-10 03:18:17 +05303792static int create_nft_table(struct sigma_dut *dut, int policy_id,
3793 const char *table_name, enum ip_version ip_ver)
3794{
3795 char cmd[200];
3796 int res;
3797
3798 res = snprintf(cmd, sizeof(cmd), "nft add table %s %s",
3799 ip_ver == IPV6 ? "ip6" : "ip", table_name);
3800 if (snprintf_error(sizeof(cmd), res)) {
3801 sigma_dut_print(dut, DUT_MSG_INFO,
3802 "Failed to add rule to create table for policy id %d",
3803 policy_id);
3804 return -1;
3805 }
3806
3807 if (system(cmd) != 0) {
3808 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run %s", cmd);
3809 return -1;
3810 }
3811
3812 res = snprintf(cmd, sizeof(cmd),
3813 "nft add chain %s %s OUTPUT { type filter hook output priority 0 \\; }",
3814 ip_ver == IPV6 ? "ip6" : "ip", table_name);
3815 if (snprintf_error(sizeof(cmd), res)) {
3816 sigma_dut_print(dut, DUT_MSG_INFO,
3817 "Failed to add rule to create chain for table = %s",
3818 table_name);
3819 return -1;
3820 }
3821
3822 if (system(cmd) != 0) {
3823 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run %s", cmd);
3824 return -1;
3825 }
3826
3827 return 0;
3828}
3829
3830
Veerendranath Jakkam9ceb3b12021-09-10 03:18:17 +05303831static int remove_dscp_policy(struct sigma_dut *dut, u8 policy_id)
3832{
3833 struct dscp_policy_data *dscp_policy = dut->dscp_policy_table;
3834 struct dscp_policy_data *prev = NULL;
3835
3836 while (dscp_policy) {
3837 if (dscp_policy->policy_id == policy_id)
3838 break;
3839
3840 prev = dscp_policy;
3841 dscp_policy = dscp_policy->next;
3842 }
3843
3844 /*
3845 * Consider remove request for a policy id which does not exist as
3846 * success.
3847 */
3848 if (!dscp_policy)
3849 return 0;
3850
3851 if (strlen(dscp_policy->domain_name) == 0 &&
Shivani Baranwal9cfc8d72021-11-22 11:53:19 +05303852 remove_dscp_policy_rule(dut, dscp_policy))
Veerendranath Jakkam9ceb3b12021-09-10 03:18:17 +05303853 return -1;
3854
3855 if (prev)
3856 prev->next = dscp_policy->next;
3857 else
3858 dut->dscp_policy_table = dscp_policy->next;
3859
3860 free(dscp_policy);
3861 return 0;
3862}
3863
3864
3865static int add_nft_rule(struct sigma_dut *dut,
3866 struct dscp_policy_data *dscp_policy)
3867{
3868 char nft_cmd[1000], ip[4], table_name[100];
3869 char *pos;
3870 int ret, len, policy_id = dscp_policy->policy_id;
3871 enum ip_version ip_ver = dscp_policy->ip_version;
3872
3873 if (ip_ver == IPV6)
3874 strlcpy(ip, "ip6", sizeof(ip));
3875 else
3876 strlcpy(ip, "ip", sizeof(ip));
3877
3878 ret = snprintf(table_name, sizeof(table_name),
3879 "wifi_%s_dscp_policy_%d_%s",
3880 dut->station_ifname, policy_id, ip);
3881 if (snprintf_error(sizeof(table_name), ret))
3882 return -1;
3883
3884 if (create_nft_table(dut, policy_id, table_name, ip_ver)) {
3885 sigma_dut_print(dut, DUT_MSG_INFO,
3886 "Failed to create nft table");
3887 return -1;
3888 }
3889
3890 pos = nft_cmd;
3891 len = sizeof(nft_cmd);
3892
3893 ret = snprintf(pos, len,
3894 "nft add rule %s %s OUTPUT oifname \"%s\"",
3895 ip, table_name, dut->station_ifname);
3896 if (snprintf_error(len, ret)) {
3897 sigma_dut_print(dut, DUT_MSG_INFO,
3898 "Failed to create nft cmd %s", nft_cmd);
3899 return -1;
3900 }
3901
3902 pos += ret;
3903 len -= ret;
3904
3905 if (strlen(dscp_policy->src_ip)) {
3906 ret = snprintf(pos, len, " %s saddr %s", ip,
3907 dscp_policy->src_ip);
3908 if (snprintf_error(len, ret))
3909 return -1;
3910
3911 pos += ret;
3912 len -= ret;
3913 }
3914
3915 if (strlen(dscp_policy->dst_ip)) {
3916 ret = snprintf(pos, len, " %s daddr %s", ip,
3917 dscp_policy->dst_ip);
3918 if (snprintf_error(len, ret))
3919 return -1;
3920
3921 pos += ret;
3922 len -= ret;
3923 }
3924
3925 if (dscp_policy->src_port) {
3926 ret = snprintf(pos, len, " %s sport %d",
3927 protocol_to_str(dscp_policy->protocol),
3928 dscp_policy->src_port);
3929 if (snprintf_error(len, ret))
3930 return -1;
3931
3932 pos += ret;
3933 len -= ret;
3934 }
3935
3936 if (dscp_policy->dst_port) {
3937 ret = snprintf(pos, len, " %s dport %d",
3938 protocol_to_str(dscp_policy->protocol),
3939 dscp_policy->dst_port);
3940 if (snprintf_error(len, ret))
3941 return -1;
3942
3943 pos += ret;
3944 len -= ret;
3945 }
3946
3947 if (dscp_policy->start_port && dscp_policy->end_port) {
3948 ret = snprintf(pos, len, " %s dport %d-%d",
3949 protocol_to_str(dscp_policy->protocol),
3950 dscp_policy->start_port,
3951 dscp_policy->end_port);
3952 if (snprintf_error(len, ret))
3953 return -1;
3954
3955 pos += ret;
3956 len -= ret;
3957 }
3958
3959 ret = snprintf(pos, len, " counter %s dscp set 0x%0x", ip,
3960 dscp_policy->dscp);
3961 if (snprintf_error(len, ret))
3962 return -1;
3963
3964 ret = system(nft_cmd);
3965 sigma_dut_print(dut, DUT_MSG_INFO, "nft rule: %s err: %d",
3966 nft_cmd, ret);
3967
3968 return ret;
3969}
3970
3971
Shivani Baranwal9cfc8d72021-11-22 11:53:19 +05303972static int add_iptable_rule(struct sigma_dut *dut,
3973 struct dscp_policy_data *dscp_policy)
3974{
3975 char ip_cmd[1000];
3976 char *pos;
3977 int ret, len;
3978 enum ip_version ip_ver = dscp_policy->ip_version;
3979 struct dscp_policy_data *active_policy = dut->dscp_policy_table;
3980 int ipv4_rule_num = 1, ipv6_rule_num = 1;
3981
3982 pos = ip_cmd;
3983 len = sizeof(ip_cmd);
3984
3985 /*
3986 * DSCP target in the mangle table doesn't stop processing of rules
3987 * so to make sure the most granular rule is applied last, add the new
3988 * rules in granularity increasing order.
3989 */
3990 while (active_policy) {
3991 /*
3992 * Domain name rules are managed in sigma_dut thus don't count
3993 * them while counting the number of active rules.
3994 */
3995 if (strlen(active_policy->domain_name)) {
3996 active_policy = active_policy->next;
3997 continue;
3998 }
3999
4000 if (active_policy->granularity_score >
4001 dscp_policy->granularity_score)
4002 break;
4003
4004 if (active_policy->ip_version == IPV6)
4005 ipv6_rule_num++;
4006 else
4007 ipv4_rule_num++;
4008
4009 active_policy = active_policy->next;
4010 }
4011
4012 ret = snprintf(pos, len,
Shivani Baranwalbf2b5212021-12-08 16:38:23 +05304013 "%s -t mangle -I OUTPUT %d -o %s",
4014#ifdef ANDROID
4015 ip_ver == IPV6 ? "/system/bin/ip6tables" : "/system/bin/iptables",
4016#else /* ANDROID */
Shivani Baranwal9cfc8d72021-11-22 11:53:19 +05304017 ip_ver == IPV6 ? "ip6tables" : "iptables",
Shivani Baranwalbf2b5212021-12-08 16:38:23 +05304018#endif /* ANDROID */
Shivani Baranwal9cfc8d72021-11-22 11:53:19 +05304019 ip_ver == IPV6 ? ipv6_rule_num : ipv4_rule_num,
4020 dut->station_ifname);
4021 if (snprintf_error(len, ret)) {
4022 sigma_dut_print(dut, DUT_MSG_INFO,
4023 "Failed to create iptables command %s", ip_cmd);
4024 return -1;
4025 }
4026
4027 pos += ret;
4028 len -= ret;
4029
4030 if (strlen(dscp_policy->src_ip)) {
4031 ret = snprintf(pos, len, " -s %s", dscp_policy->src_ip);
4032 if (snprintf_error(len, ret)) {
4033 sigma_dut_print(dut, DUT_MSG_INFO,
4034 "Error in adding src_ip %s",
4035 dscp_policy->src_ip);
4036 return -1;
4037 }
4038 pos += ret;
4039 len -= ret;
4040 }
4041
4042 if (strlen(dscp_policy->dst_ip)) {
4043 ret = snprintf(pos, len, " -d %s", dscp_policy->dst_ip);
4044 if (snprintf_error(len, ret)) {
4045 sigma_dut_print(dut, DUT_MSG_INFO,
4046 "Error in adding dst_ip %s",
4047 dscp_policy->dst_ip);
4048 return -1;
4049 }
4050 pos += ret;
4051 len -= ret;
4052 }
4053
4054 if (dscp_policy->src_port || dscp_policy->dst_port ||
4055 (dscp_policy->start_port && dscp_policy->end_port)) {
4056 ret = snprintf(pos, len, " -p %s",
4057 protocol_to_str(dscp_policy->protocol));
4058 if (snprintf_error(len, ret)) {
4059 sigma_dut_print(dut, DUT_MSG_INFO,
4060 "Error in adding protocol %d in add command",
4061 dscp_policy->protocol);
4062 return -1;
4063 }
4064 pos += ret;
4065 len -= ret;
4066 }
4067
4068 if (dscp_policy->src_port) {
4069 ret = snprintf(pos, len, " --sport %d", dscp_policy->src_port);
4070 if (snprintf_error(len, ret)) {
4071 sigma_dut_print(dut, DUT_MSG_INFO,
4072 "Error in adding src_port %d",
4073 dscp_policy->src_port);
4074 return -1;
4075 }
4076 pos += ret;
4077 len -= ret;
4078 }
4079
4080 if (dscp_policy->dst_port) {
4081 ret = snprintf(pos, len, " --dport %d", dscp_policy->dst_port);
4082 if (snprintf_error(len, ret)) {
4083 sigma_dut_print(dut, DUT_MSG_INFO,
4084 "Error in adding dst_port %d",
4085 dscp_policy->dst_port);
4086 return -1;
4087 }
4088 pos += ret;
4089 len -= ret;
4090 }
4091
4092 if (dscp_policy->start_port && dscp_policy->end_port) {
4093 ret = snprintf(pos, len, " --match multiport --dports %d:%d",
4094 dscp_policy->start_port, dscp_policy->end_port);
4095 if (snprintf_error(len, ret)) {
4096 sigma_dut_print(dut, DUT_MSG_INFO,
4097 "Error in adding start:end port %d:%d",
4098 dscp_policy->start_port,
4099 dscp_policy->end_port);
4100 return -1;
4101 }
4102 pos += ret;
4103 len -= ret;
4104 }
4105
4106 ret = snprintf(pos, len, " -j DSCP --set-dscp 0x%0x",
4107 dscp_policy->dscp);
4108 if (snprintf_error(len, ret)) {
4109 sigma_dut_print(dut, DUT_MSG_INFO,
4110 "Error in adding dscp %0x", dscp_policy->dscp);
4111 return -1;
4112 }
4113 ret = system(ip_cmd);
4114 sigma_dut_print(dut, DUT_MSG_DEBUG, "iptables rule: %s err: %d",
4115 ip_cmd, ret);
4116
4117 return ret;
4118}
4119
4120
4121static int add_dscp_policy_rule(struct sigma_dut *dut,
4122 struct dscp_policy_data *dscp_policy)
4123{
4124 return dut->dscp_use_iptables ? add_iptable_rule(dut, dscp_policy) :
4125 add_nft_rule(dut, dscp_policy);
4126}
4127
4128
Veerendranath Jakkam9ceb3b12021-09-10 03:18:17 +05304129static void clear_all_dscp_policies(struct sigma_dut *dut)
4130{
4131 free_dscp_policy_table(dut);
4132
Shivani Baranwal9cfc8d72021-11-22 11:53:19 +05304133 if (dut->dscp_use_iptables) {
Shivani Baranwalbf2b5212021-12-08 16:38:23 +05304134#ifdef ANDROID
Shivani Baranwal9cfc8d72021-11-22 11:53:19 +05304135 if (system("/system/bin/iptables -t mangle -F && /system/bin/iptables -t mangle -X") != 0 ||
Shivani Baranwalbf2b5212021-12-08 16:38:23 +05304136 system("/system/bin/ip6tables -t mangle -F && /system/bin/ip6tables -t mangle -X") != 0)
Shivani Baranwal9cfc8d72021-11-22 11:53:19 +05304137 sigma_dut_print(dut, DUT_MSG_ERROR,
4138 "iptables: Failed to flush DSCP policy");
Shivani Baranwalbf2b5212021-12-08 16:38:23 +05304139#else /* ANDROID */
4140 if (system("iptables -t mangle -F && iptables -t mangle -X") != 0 ||
4141 system("ip6tables -t mangle -F && ip6tables -t mangle -X") != 0)
4142 sigma_dut_print(dut, DUT_MSG_ERROR,
4143 "iptables: Failed to flush DSCP policy");
4144#endif /* ANDROID */
Shivani Baranwal9cfc8d72021-11-22 11:53:19 +05304145 } else {
4146 if (system("nft flush ruleset") != 0)
4147 sigma_dut_print(dut, DUT_MSG_ERROR,
4148 "nftables: Failed to flush DSCP policy");
4149 }
Veerendranath Jakkam9ceb3b12021-09-10 03:18:17 +05304150}
4151
4152
4153static int send_dscp_response(struct sigma_dut *dut,
4154 struct dscp_policy_status *status_list,
4155 int num_status)
4156{
4157 int rem_len, ret;
4158 char buf[200] = "", *pos, cmd[256];
4159
4160 pos = buf;
4161 rem_len = sizeof(buf);
4162
4163 ret = snprintf(pos, rem_len, " solicited");
4164 if (snprintf_error(rem_len, ret)) {
4165 sigma_dut_print(dut, DUT_MSG_ERROR,
4166 "Failed to write DSCP policy response command");
4167 return -1;
4168 }
4169 pos += ret;
4170 rem_len -= ret;
4171
4172 for (int i = 0; i < num_status; i++) {
4173 ret = snprintf(pos, rem_len, " policy_id=%d status=%d",
4174 status_list[i].id, status_list[i].status);
4175 if (snprintf_error(rem_len, ret)) {
4176 sigma_dut_print(dut, DUT_MSG_ERROR,
4177 "Failed to wite DSCP policy response");
4178 return -1;
4179 }
4180
4181 pos += ret;
4182 rem_len -= ret;
4183 }
4184
4185 ret = snprintf(cmd, sizeof(cmd), "DSCP_RESP%s", buf);
4186 if (snprintf_error(sizeof(cmd), ret)) {
4187 sigma_dut_print(dut, DUT_MSG_ERROR,
4188 "Failed to create DSCP Policy Response frame");
4189 return -1;
4190 }
4191
4192 if (wpa_command(dut->station_ifname, cmd) != 0) {
4193 sigma_dut_print(dut, DUT_MSG_ERROR,
4194 "Failed to send DSCP Policy Response frame");
4195 return -1;
4196 }
4197
4198 sigma_dut_print(dut, DUT_MSG_DEBUG,
4199 "DSCP Policy Response frame sent: %s", cmd);
4200 return 0;
4201}
4202
4203
4204#ifdef ANDROID
4205static void thread_cancel_handler(int sig)
4206{
4207 if (sig == SIGUSR1)
4208 pthread_exit(0);
4209}
4210#endif /* ANDROID */
4211
4212
4213static void * mon_dscp_policies(void *ptr)
4214{
4215 struct sigma_dut *dut = ptr;
4216 int ret, policy_id;
4217 struct wpa_ctrl *ctrl;
4218 char buf[4096], *pos, *end;
Shivani Baranwal9cfc8d72021-11-22 11:53:19 +05304219 struct dscp_policy_data *policy = NULL, *current_policy, *prev_policy;
Veerendranath Jakkam9ceb3b12021-09-10 03:18:17 +05304220 struct dscp_policy_status status_list[10];
4221 int num_status = 0;
4222 const char *events[] = {
4223 "CTRL-EVENT-DISCONNECTED",
4224 "CTRL-EVENT-DSCP-POLICY",
4225 NULL
4226 };
4227#ifdef ANDROID
4228 struct sigaction actions;
4229#endif /* ANDROID */
4230
4231 ctrl = open_wpa_mon(get_station_ifname(dut));
4232 if (!ctrl) {
4233 sigma_dut_print(dut, DUT_MSG_ERROR,
4234 "Failed to open wpa_supplicant monitor connection");
4235 return NULL;
4236 }
4237
4238#ifdef ANDROID
4239 memset(&actions, 0, sizeof(actions));
4240 sigemptyset(&actions.sa_mask);
4241 actions.sa_flags = 0;
4242 actions.sa_handler = thread_cancel_handler;
4243 if (sigaction(SIGUSR1, &actions, NULL) == -1) {
4244 sigma_dut_print(dut, DUT_MSG_ERROR,
4245 "Failed to register exit handler for %s",
4246 __func__);
4247 wpa_ctrl_detach(ctrl);
4248 wpa_ctrl_close(ctrl);
4249 return NULL;
4250 }
4251#endif /* ANDROID */
4252
4253 while (1) {
4254 ret = get_wpa_cli_events_timeout(dut, ctrl, events,
4255 buf, sizeof(buf), 0);
4256
4257 if (ret || strlen(buf) == 0) {
4258 sigma_dut_print(dut, DUT_MSG_INFO,
4259 "Did not receive any event");
4260 continue;
4261 }
4262
4263 if (strstr(buf, "CTRL-EVENT-DISCONNECTED")) {
4264 clear_all_dscp_policies(dut);
4265 break;
4266 }
4267
4268 if (strstr(buf, "request_start")) {
4269 num_status = 0;
4270 if (strstr(buf, "clear_all"))
4271 clear_all_dscp_policies(dut);
4272 continue;
4273 }
4274
4275 if (strstr(buf, "request_end")) {
4276 send_dscp_response(dut, status_list, num_status);
4277 continue;
4278 }
4279
4280 if (!strstr(buf, "add") && !strstr(buf, "remove") &&
4281 !strstr(buf, "reject")) {
4282 sigma_dut_print(dut, DUT_MSG_DEBUG, "Ignore event: %s",
4283 buf);
4284 continue;
4285 }
4286
4287 pos = strstr(buf, "policy_id=");
4288 if (!pos) {
4289 sigma_dut_print(dut, DUT_MSG_INFO,
4290 "Policy id not present");
4291 continue;
4292 }
4293 policy_id = atoi(pos + 10);
4294
4295 if (num_status >= ARRAY_SIZE(status_list)) {
4296 sigma_dut_print(dut, DUT_MSG_INFO,
4297 "Max policies allowed per DSCP request reached. Drop policy id %d request",
4298 policy_id);
4299 continue;
4300 }
4301 status_list[num_status].id = policy_id;
4302
Veerendranath Jakkama16cdc82021-09-12 16:44:22 +05304303 if (dut->reject_dscp_policies) {
4304 status_list[num_status].status =
4305 dut->dscp_reject_resp_code;
4306 num_status++;
4307 continue;
4308 }
4309
Veerendranath Jakkam9ceb3b12021-09-10 03:18:17 +05304310 if (strstr(buf, "reject"))
4311 goto reject;
4312
4313 /*
4314 * In case of "add" also if policy with same policy id exist it
4315 * shall be removed. So always call remove_dscp_policy().
4316 */
4317 if (remove_dscp_policy(dut, policy_id))
4318 goto reject;
4319
4320 if (strstr(buf, "remove"))
4321 goto success;
4322
4323 policy = malloc(sizeof(*policy));
4324 if (!policy)
4325 goto reject;
4326
4327 memset(policy, 0, sizeof(*policy));
4328
4329 policy->policy_id = policy_id;
4330
4331 pos = strstr(buf, "dscp=");
4332 if (!pos) {
4333 sigma_dut_print(dut, DUT_MSG_ERROR,
4334 "DSCP info not present");
4335 goto reject;
4336 }
4337 policy->dscp = atoi(pos + 5);
4338
4339 pos = strstr(buf, "ip_version=");
4340 if (!pos) {
4341 sigma_dut_print(dut, DUT_MSG_ERROR,
4342 "IP version info not present");
4343 goto reject;
4344 }
4345 policy->ip_version = atoi(pos + 11);
Shivani Baranwal9cfc8d72021-11-22 11:53:19 +05304346 if (policy->ip_version)
4347 policy->granularity_score++;
Veerendranath Jakkam9ceb3b12021-09-10 03:18:17 +05304348
4349 pos = strstr(buf, "domain_name=");
4350 if (pos) {
4351 pos += 12;
4352 end = strchr(pos, ' ');
4353 if (!end)
4354 end = pos + strlen(pos);
4355
4356 if (end - pos >= (int) sizeof(policy->domain_name))
4357 goto reject;
4358
4359 memcpy(policy->domain_name, pos, end - pos);
4360 policy->domain_name[end - pos] = '\0';
Shivani Baranwal9cfc8d72021-11-22 11:53:19 +05304361 policy->granularity_score++;
Veerendranath Jakkam9ceb3b12021-09-10 03:18:17 +05304362 }
4363
4364 pos = strstr(buf, "start_port=");
4365 if (pos) {
4366 pos += 11;
4367 policy->start_port = atoi(pos);
4368 }
4369
4370 pos = strstr(buf, "end_port=");
4371 if (pos) {
4372 pos += 9;
4373 policy->end_port = atoi(pos);
4374 }
4375
Shivani Baranwal9cfc8d72021-11-22 11:53:19 +05304376 if (policy->start_port && policy->end_port)
4377 policy->granularity_score++;
4378
Veerendranath Jakkam9ceb3b12021-09-10 03:18:17 +05304379 pos = strstr(buf, "src_ip=");
4380 if (pos) {
4381 pos += 7;
4382 end = strchr(pos, ' ');
4383 if (!end)
4384 end = pos + strlen(pos);
4385
4386 if (end - pos >= (int) sizeof(policy->src_ip))
4387 goto reject;
4388
4389 memcpy(policy->src_ip, pos, end - pos);
4390 policy->src_ip[end - pos] = '\0';
Shivani Baranwal9cfc8d72021-11-22 11:53:19 +05304391 policy->granularity_score++;
Veerendranath Jakkam9ceb3b12021-09-10 03:18:17 +05304392 }
4393
4394 pos = strstr(buf, "dst_ip=");
4395 if (pos) {
4396 pos += 7;
4397 end = strchr(pos, ' ');
4398 if (!end)
4399 end = pos + strlen(pos);
4400
4401 if (end - pos >= (int) sizeof(policy->dst_ip))
4402 goto reject;
4403
4404 memcpy(policy->dst_ip, pos, end - pos);
4405 policy->dst_ip[end - pos] = '\0';
Shivani Baranwal9cfc8d72021-11-22 11:53:19 +05304406 policy->granularity_score++;
Veerendranath Jakkam9ceb3b12021-09-10 03:18:17 +05304407 }
4408
4409 pos = strstr(buf, "src_port=");
4410 if (pos) {
4411 pos += 9;
4412 policy->src_port = atoi(pos);
Shivani Baranwal9cfc8d72021-11-22 11:53:19 +05304413 policy->granularity_score++;
Veerendranath Jakkam9ceb3b12021-09-10 03:18:17 +05304414 }
4415
4416 pos = strstr(buf, "dst_port=");
4417 if (pos) {
4418 pos += 9;
4419 policy->dst_port = atoi(pos);
Shivani Baranwal9cfc8d72021-11-22 11:53:19 +05304420 policy->granularity_score++;
Veerendranath Jakkam9ceb3b12021-09-10 03:18:17 +05304421 }
4422
4423 pos = strstr(buf, "protocol=");
4424 if (pos) {
4425 pos += 9;
4426 policy->protocol = atoi(pos);
Shivani Baranwal9cfc8d72021-11-22 11:53:19 +05304427 policy->granularity_score++;
Veerendranath Jakkam9ceb3b12021-09-10 03:18:17 +05304428 }
4429
4430 /*
4431 * Skip adding nft rules for doman name policies.
4432 * Domain name rules are applied in sigma_dut itself.
4433 */
Shivani Baranwal9cfc8d72021-11-22 11:53:19 +05304434 if (!strlen(policy->domain_name) &&
4435 add_dscp_policy_rule(dut, policy))
Veerendranath Jakkam9ceb3b12021-09-10 03:18:17 +05304436 goto reject;
4437
Shivani Baranwal9cfc8d72021-11-22 11:53:19 +05304438 /*
4439 * Add the new policy in policy table in granularity increasing
4440 * order.
4441 */
4442 current_policy = dut->dscp_policy_table;
4443 prev_policy = NULL;
Veerendranath Jakkam9ceb3b12021-09-10 03:18:17 +05304444
Shivani Baranwal9cfc8d72021-11-22 11:53:19 +05304445 while (current_policy) {
4446 if (current_policy->granularity_score >
4447 policy->granularity_score)
4448 break;
4449
4450 prev_policy = current_policy;
4451 current_policy = current_policy->next;
4452 }
4453
4454 if (prev_policy)
4455 prev_policy->next = policy;
4456 else
Veerendranath Jakkam9ceb3b12021-09-10 03:18:17 +05304457 dut->dscp_policy_table = policy;
4458
Shivani Baranwal9cfc8d72021-11-22 11:53:19 +05304459 policy->next = current_policy;
4460
Veerendranath Jakkam9ceb3b12021-09-10 03:18:17 +05304461success:
4462 status_list[num_status].status = DSCP_POLICY_SUCCESS;
4463 num_status++;
4464 policy = NULL;
4465 continue;
4466reject:
4467 status_list[num_status].status = DSCP_POLICY_REJECT;
4468 num_status++;
4469 free(policy);
4470 policy = NULL;
4471 }
4472
4473 free_dscp_policy_table(dut);
4474 wpa_ctrl_detach(ctrl);
4475 wpa_ctrl_close(ctrl);
4476
4477 pthread_exit(0);
4478 return NULL;
4479}
4480
4481
4482static void start_dscp_policy_mon_thread(struct sigma_dut *dut)
4483{
4484 /* Create event thread */
4485 pthread_create(&dut->dscp_policy_mon_thread, NULL, &mon_dscp_policies,
4486 (void *) dut);
4487}
4488
4489
4490void stop_dscp_policy_mon_thread(struct sigma_dut *dut)
4491{
4492 if (dut->dscp_policy_mon_thread) {
4493#ifdef ANDROID
4494 /* pthread_cancel not supported in Android */
4495 pthread_kill(dut->dscp_policy_mon_thread, SIGUSR1);
4496#else /* ANDROID */
4497 pthread_cancel(dut->dscp_policy_mon_thread);
4498#endif /* ANDROID */
4499 dut->dscp_policy_mon_thread = 0;
4500 }
4501}
4502
4503
Jouni Malinenf7222712019-06-13 01:50:21 +03004504static enum sigma_cmd_result cmd_sta_associate(struct sigma_dut *dut,
4505 struct sigma_conn *conn,
4506 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004507{
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304508#ifdef NL80211_SUPPORT
4509 const char *intf = get_param(cmd, "Interface");
4510#endif /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004511 const char *ssid = get_param(cmd, "ssid");
4512 const char *wps_param = get_param(cmd, "WPS");
4513 const char *bssid = get_param(cmd, "bssid");
Jouni Malinen46a19b62017-06-23 14:31:27 +03004514 const char *chan = get_param(cmd, "channel");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02004515 const char *network_mode = get_param(cmd, "network_mode");
Veerendranath Jakkama082e342020-05-16 00:19:21 +05304516 const char *ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004517 int wps = 0;
Jouni Malinen3c367e82017-06-23 17:01:47 +03004518 char buf[1000], extra[50];
Jouni Malinen134fe3c2019-06-12 04:16:49 +03004519 int e;
4520 enum sigma_cmd_result ret = SUCCESS_SEND_STATUS;
4521 struct wpa_ctrl *ctrl = NULL;
4522 int num_network_not_found = 0;
4523 int num_disconnected = 0;
4524 int tod = -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004525
4526 if (ssid == NULL)
4527 return -1;
4528
Jouni Malinen37d5c692019-08-19 16:56:55 +03004529 dut->server_cert_tod = 0;
4530
Jouni Malinen3c367e82017-06-23 17:01:47 +03004531 if (dut->rsne_override) {
Sunil Dutt44595082018-02-12 19:41:45 +05304532#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004533 if (get_driver_type(dut) == DRIVER_WCN) {
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304534 sta_config_params(dut, intf, STA_SET_RSNIE, 1);
Sunil Dutt44595082018-02-12 19:41:45 +05304535 dut->config_rsnie = 1;
4536 }
4537#endif /* NL80211_SUPPORT */
Jouni Malinen3c367e82017-06-23 17:01:47 +03004538 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
4539 dut->rsne_override);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004540 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinen3c367e82017-06-23 17:01:47 +03004541 send_resp(dut, conn, SIGMA_ERROR,
4542 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
4543 return 0;
4544 }
4545 }
4546
Jouni Malinen68143132017-09-02 02:34:08 +03004547 if (dut->sae_commit_override) {
4548 snprintf(buf, sizeof(buf), "SET sae_commit_override %s",
4549 dut->sae_commit_override);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004550 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinen68143132017-09-02 02:34:08 +03004551 send_resp(dut, conn, SIGMA_ERROR,
4552 "ErrorCode,Failed to set SAE commit override");
4553 return 0;
4554 }
4555 }
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304556#ifdef ANDROID
4557 if (dut->fils_hlp)
4558 process_fils_hlp(dut);
4559#endif /* ANDROID */
Jouni Malinen68143132017-09-02 02:34:08 +03004560
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004561 if (wps_param &&
4562 (strcmp(wps_param, "1") == 0 || strcasecmp(wps_param, "On") == 0))
4563 wps = 1;
4564
4565 if (wps) {
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02004566 if (dut->program == PROGRAM_60GHZ && network_mode &&
4567 strcasecmp(network_mode, "PBSS") == 0 &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004568 set_network(get_station_ifname(dut), dut->infra_network_id,
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02004569 "pbss", "1") < 0)
4570 return -2;
4571
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004572 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
4573 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,WPS "
4574 "parameters not yet set");
4575 return 0;
4576 }
4577 if (dut->wps_method == WFA_CS_WPS_PBC) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004578 if (wpa_command(get_station_ifname(dut), "WPS_PBC") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004579 return -2;
4580 } else {
4581 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
4582 dut->wps_pin);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004583 if (wpa_command(get_station_ifname(dut), buf) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004584 return -2;
4585 }
4586 } else {
vamsi krishna52e16f92017-08-29 12:37:34 +05304587 if (strcmp(ssid, dut->infra_ssid) == 0) {
4588 sigma_dut_print(dut, DUT_MSG_DEBUG,
4589 "sta_associate for the most recently added network");
4590 } else if (find_network(dut, ssid) < 0) {
4591 sigma_dut_print(dut, DUT_MSG_DEBUG,
4592 "sta_associate for a previously stored network profile");
4593 send_resp(dut, conn, SIGMA_ERROR,
4594 "ErrorCode,Profile not found");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004595 return 0;
4596 }
4597
4598 if (bssid &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004599 set_network(get_station_ifname(dut), dut->infra_network_id,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004600 "bssid", bssid) < 0) {
4601 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
4602 "Invalid bssid argument");
4603 return 0;
4604 }
4605
Veerendranath Jakkama082e342020-05-16 00:19:21 +05304606 if ((dut->program == PROGRAM_WPA3 &&
4607 dut->sta_associate_wait_connect) ||
4608 dut->program == PROGRAM_QM) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004609 ctrl = open_wpa_mon(get_station_ifname(dut));
Jouni Malinen134fe3c2019-06-12 04:16:49 +03004610 if (!ctrl)
4611 return ERROR_SEND_STATUS;
4612 }
4613
Jouni Malinen46a19b62017-06-23 14:31:27 +03004614 extra[0] = '\0';
4615 if (chan)
4616 snprintf(extra, sizeof(extra), " freq=%u",
Alexei Avshalom Lazar093569f2018-11-13 14:08:17 +02004617 channel_to_freq(dut, atoi(chan)));
Jouni Malinen46a19b62017-06-23 14:31:27 +03004618 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d%s",
4619 dut->infra_network_id, extra);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004620 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004621 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to select "
4622 "network id %d on %s",
4623 dut->infra_network_id,
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004624 get_station_ifname(dut));
Jouni Malinen134fe3c2019-06-12 04:16:49 +03004625 ret = ERROR_SEND_STATUS;
4626 goto done;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004627 }
4628 }
4629
Jouni Malinen134fe3c2019-06-12 04:16:49 +03004630 if (!ctrl)
4631 return SUCCESS_SEND_STATUS;
4632
4633 /* Wait for connection result to be able to store server certificate
4634 * hash for trust root override testing
4635 * (dev_exec_action,ServerCertTrust). */
4636
4637 for (e = 0; e < 20; e++) {
4638 const char *events[] = {
4639 "CTRL-EVENT-EAP-PEER-CERT",
4640 "CTRL-EVENT-EAP-TLS-CERT-ERROR",
4641 "CTRL-EVENT-DISCONNECTED",
4642 "CTRL-EVENT-CONNECTED",
4643 "CTRL-EVENT-NETWORK-NOT-FOUND",
4644 NULL
4645 };
4646 char buf[1024];
4647 int res;
4648
4649 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
4650 if (res < 0) {
Jouni Malinenf1f16642019-11-15 21:19:04 +02004651 send_resp(dut, conn, SIGMA_COMPLETE,
4652 "Result,Association did not complete");
Jouni Malinen134fe3c2019-06-12 04:16:49 +03004653 ret = STATUS_SENT_ERROR;
4654 break;
4655 }
4656 sigma_dut_print(dut, DUT_MSG_DEBUG, "Connection event: %s",
4657 buf);
4658
4659 if (strstr(buf, "CTRL-EVENT-EAP-PEER-CERT") &&
4660 strstr(buf, " depth=0")) {
4661 char *pos = strstr(buf, " hash=");
4662
4663 if (pos) {
4664 char *end;
4665
Jouni Malinen34b19cb2019-08-16 16:37:17 +03004666 if (strstr(buf, " tod=1"))
4667 tod = 1;
4668 else if (strstr(buf, " tod=2"))
4669 tod = 2;
4670 else
4671 tod = 0;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03004672 sigma_dut_print(dut, DUT_MSG_DEBUG,
4673 "Server certificate TOD policy: %d",
4674 tod);
Jouni Malinen37d5c692019-08-19 16:56:55 +03004675 dut->server_cert_tod = tod;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03004676
4677 pos += 6;
4678 end = strchr(pos, ' ');
4679 if (end)
4680 *end = '\0';
4681 strlcpy(dut->server_cert_hash, pos,
4682 sizeof(dut->server_cert_hash));
4683 sigma_dut_print(dut, DUT_MSG_DEBUG,
4684 "Server certificate hash: %s",
4685 dut->server_cert_hash);
4686 }
4687 }
4688
4689 if (strstr(buf, "CTRL-EVENT-EAP-TLS-CERT-ERROR")) {
4690 send_resp(dut, conn, SIGMA_COMPLETE,
4691 "Result,TLS server certificate validation failed");
4692 ret = STATUS_SENT_ERROR;
4693 break;
4694 }
4695
4696 if (strstr(buf, "CTRL-EVENT-NETWORK-NOT-FOUND")) {
4697 num_network_not_found++;
4698
4699 if (num_network_not_found > 2) {
4700 send_resp(dut, conn, SIGMA_COMPLETE,
4701 "Result,Network not found");
4702 ret = STATUS_SENT_ERROR;
4703 break;
4704 }
4705 }
4706
4707 if (strstr(buf, "CTRL-EVENT-DISCONNECTED")) {
4708 num_disconnected++;
4709
4710 if (num_disconnected > 2) {
4711 send_resp(dut, conn, SIGMA_COMPLETE,
4712 "Result,Connection failed");
4713 ret = STATUS_SENT_ERROR;
4714 break;
4715 }
4716 }
4717
4718 if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
4719 if (tod >= 0) {
4720 sigma_dut_print(dut, DUT_MSG_DEBUG,
4721 "Network profile TOD policy update: %d -> %d",
4722 dut->sta_tod_policy, tod);
4723 dut->sta_tod_policy = tod;
4724 }
Veerendranath Jakkama082e342020-05-16 00:19:21 +05304725 if (dut->program == PROGRAM_QM) {
4726 unsigned char iface_mac_addr[ETH_ALEN];
4727 char ipv6[100];
4728
4729 if (get_hwaddr(ifname, iface_mac_addr) < 0) {
4730 sigma_dut_print(dut, DUT_MSG_ERROR,
4731 "%s: get_hwaddr %s failed",
4732 __func__, ifname);
4733 ret = ERROR_SEND_STATUS;
4734 break;
4735 }
4736
4737 convert_mac_addr_to_ipv6_lladdr(iface_mac_addr,
4738 ipv6,
4739 sizeof(ipv6));
4740
4741 if (set_ipv6_addr(dut, ipv6, "64", ifname) !=
4742 0) {
4743 ret = ERROR_SEND_STATUS;
4744 break;
4745 }
Veerendranath Jakkam9ceb3b12021-09-10 03:18:17 +05304746 start_dscp_policy_mon_thread(dut);
Veerendranath Jakkama082e342020-05-16 00:19:21 +05304747 }
Jouni Malinen134fe3c2019-06-12 04:16:49 +03004748 break;
4749 }
4750 }
4751done:
4752 if (ctrl) {
4753 wpa_ctrl_detach(ctrl);
4754 wpa_ctrl_close(ctrl);
4755 }
4756 return ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004757}
4758
4759
4760static int run_hs20_osu(struct sigma_dut *dut, const char *params)
4761{
4762 char buf[500], cmd[200];
4763 int res;
4764
4765 /* Use hs20-osu-client file at the current dir, if found; otherwise use
4766 * default path */
4767 res = snprintf(cmd, sizeof(cmd),
4768 "%s -w \"%s\" -r hs20-osu-client.res %s%s -dddKt -f Logs/hs20-osu-client.txt",
4769 file_exists("./hs20-osu-client") ?
4770 "./hs20-osu-client" : "hs20-osu-client",
4771 sigma_wpas_ctrl,
4772 dut->summary_log ? "-s " : "",
4773 dut->summary_log ? dut->summary_log : "");
4774 if (res < 0 || res >= (int) sizeof(cmd))
4775 return -1;
4776
4777 res = snprintf(buf, sizeof(buf), "%s %s", cmd, params);
4778 if (res < 0 || res >= (int) sizeof(buf))
4779 return -1;
4780 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
4781
4782 if (system(buf) != 0) {
4783 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run: %s", buf);
4784 return -1;
4785 }
4786 sigma_dut_print(dut, DUT_MSG_DEBUG,
4787 "Completed hs20-osu-client operation");
4788
4789 return 0;
4790}
4791
4792
4793static int download_ppsmo(struct sigma_dut *dut,
4794 struct sigma_conn *conn,
4795 const char *intf,
4796 struct sigma_cmd *cmd)
4797{
4798 const char *name, *path, *val;
4799 char url[500], buf[600], fbuf[100];
4800 char *fqdn = NULL;
4801
4802 name = get_param(cmd, "FileName");
4803 path = get_param(cmd, "FilePath");
4804 if (name == NULL || path == NULL)
4805 return -1;
4806
4807 if (strcasecmp(path, "VendorSpecific") == 0) {
4808 snprintf(url, sizeof(url), "PPS/%s", name);
4809 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured PPS MO "
4810 "from the device (%s)", url);
4811 if (!file_exists(url)) {
4812 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
4813 "PPS MO file does not exist");
4814 return 0;
4815 }
4816 snprintf(buf, sizeof(buf), "cp %s pps-tnds.xml", url);
4817 if (system(buf) != 0) {
4818 send_resp(dut, conn, SIGMA_ERROR,
4819 "errorCode,Failed to copy PPS MO");
4820 return 0;
4821 }
4822 } else if (strncasecmp(path, "http:", 5) != 0 &&
4823 strncasecmp(path, "https:", 6) != 0) {
4824 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
4825 "Unsupported FilePath value");
4826 return 0;
4827 } else {
4828 snprintf(url, sizeof(url), "%s/%s", path, name);
4829 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading PPS MO from %s",
4830 url);
4831 snprintf(buf, sizeof(buf), "wget -T 10 -t 3 -O pps-tnds.xml '%s'", url);
4832 remove("pps-tnds.xml");
4833 if (system(buf) != 0) {
4834 send_resp(dut, conn, SIGMA_ERROR,
4835 "errorCode,Failed to download PPS MO");
4836 return 0;
4837 }
4838 }
4839
4840 if (run_hs20_osu(dut, "from_tnds pps-tnds.xml pps.xml") < 0) {
4841 send_resp(dut, conn, SIGMA_ERROR,
4842 "errorCode,Failed to parse downloaded PPSMO");
4843 return 0;
4844 }
4845 unlink("pps-tnds.xml");
4846
4847 val = get_param(cmd, "managementTreeURI");
4848 if (val) {
4849 const char *pos, *end;
4850 sigma_dut_print(dut, DUT_MSG_DEBUG, "managementTreeURI: %s",
4851 val);
4852 if (strncmp(val, "./Wi-Fi/", 8) != 0) {
4853 send_resp(dut, conn, SIGMA_ERROR,
4854 "errorCode,Invalid managementTreeURI prefix");
4855 return 0;
4856 }
4857 pos = val + 8;
4858 end = strchr(pos, '/');
4859 if (end == NULL ||
4860 strcmp(end, "/PerProviderSubscription") != 0) {
4861 send_resp(dut, conn, SIGMA_ERROR,
4862 "errorCode,Invalid managementTreeURI postfix");
4863 return 0;
4864 }
4865 if (end - pos >= (int) sizeof(fbuf)) {
4866 send_resp(dut, conn, SIGMA_ERROR,
4867 "errorCode,Too long FQDN in managementTreeURI");
4868 return 0;
4869 }
4870 memcpy(fbuf, pos, end - pos);
4871 fbuf[end - pos] = '\0';
4872 fqdn = fbuf;
4873 sigma_dut_print(dut, DUT_MSG_INFO,
4874 "FQDN from managementTreeURI: %s", fqdn);
4875 } else if (run_hs20_osu(dut, "get_fqdn pps.xml") == 0) {
4876 FILE *f = fopen("pps-fqdn", "r");
4877 if (f) {
4878 if (fgets(fbuf, sizeof(fbuf), f)) {
4879 fbuf[sizeof(fbuf) - 1] = '\0';
4880 fqdn = fbuf;
4881 sigma_dut_print(dut, DUT_MSG_DEBUG,
4882 "Use FQDN %s", fqdn);
4883 }
4884 fclose(f);
4885 }
4886 }
4887
4888 if (fqdn == NULL) {
4889 send_resp(dut, conn, SIGMA_ERROR,
4890 "errorCode,No FQDN specified");
4891 return 0;
4892 }
4893
4894 mkdir("SP", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
4895 snprintf(buf, sizeof(buf), "SP/%s", fqdn);
4896 mkdir(buf, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
4897
4898 snprintf(buf, sizeof(buf), "SP/%s/pps.xml", fqdn);
4899 if (rename("pps.xml", buf) < 0) {
4900 send_resp(dut, conn, SIGMA_ERROR,
4901 "errorCode,Could not move PPS MO");
4902 return 0;
4903 }
4904
4905 if (strcasecmp(path, "VendorSpecific") == 0) {
4906 snprintf(buf, sizeof(buf), "cp Certs/ca.pem SP/%s/ca.pem",
4907 fqdn);
4908 if (system(buf)) {
4909 send_resp(dut, conn, SIGMA_ERROR,
4910 "errorCode,Failed to copy OSU CA cert");
4911 return 0;
4912 }
4913
4914 snprintf(buf, sizeof(buf),
4915 "cp Certs/aaa-ca.pem SP/%s/aaa-ca.pem",
4916 fqdn);
4917 if (system(buf)) {
4918 send_resp(dut, conn, SIGMA_ERROR,
4919 "errorCode,Failed to copy AAA CA cert");
4920 return 0;
4921 }
4922 } else {
4923 snprintf(buf, sizeof(buf),
4924 "dl_osu_ca SP/%s/pps.xml SP/%s/ca.pem",
4925 fqdn, fqdn);
4926 if (run_hs20_osu(dut, buf) < 0) {
4927 send_resp(dut, conn, SIGMA_ERROR,
4928 "errorCode,Failed to download OSU CA cert");
4929 return 0;
4930 }
4931
4932 snprintf(buf, sizeof(buf),
4933 "dl_aaa_ca SP/%s/pps.xml SP/%s/aaa-ca.pem",
4934 fqdn, fqdn);
4935 if (run_hs20_osu(dut, buf) < 0) {
4936 sigma_dut_print(dut, DUT_MSG_INFO,
4937 "Failed to download AAA CA cert");
4938 }
4939 }
4940
4941 if (file_exists("next-client-cert.pem")) {
4942 snprintf(buf, sizeof(buf), "SP/%s/client-cert.pem", fqdn);
4943 if (rename("next-client-cert.pem", buf) < 0) {
4944 send_resp(dut, conn, SIGMA_ERROR,
4945 "errorCode,Could not move client certificate");
4946 return 0;
4947 }
4948 }
4949
4950 if (file_exists("next-client-key.pem")) {
4951 snprintf(buf, sizeof(buf), "SP/%s/client-key.pem", fqdn);
4952 if (rename("next-client-key.pem", buf) < 0) {
4953 send_resp(dut, conn, SIGMA_ERROR,
4954 "errorCode,Could not move client key");
4955 return 0;
4956 }
4957 }
4958
4959 snprintf(buf, sizeof(buf), "set_pps SP/%s/pps.xml", fqdn);
4960 if (run_hs20_osu(dut, buf) < 0) {
4961 send_resp(dut, conn, SIGMA_ERROR,
4962 "errorCode,Failed to configure credential from "
4963 "PPSMO");
4964 return 0;
4965 }
4966
4967 return 1;
4968}
4969
4970
4971static int download_cert(struct sigma_dut *dut,
4972 struct sigma_conn *conn,
4973 const char *intf,
4974 struct sigma_cmd *cmd)
4975{
4976 const char *name, *path;
4977 char url[500], buf[600];
4978
4979 name = get_param(cmd, "FileName");
4980 path = get_param(cmd, "FilePath");
4981 if (name == NULL || path == NULL)
4982 return -1;
4983
4984 if (strcasecmp(path, "VendorSpecific") == 0) {
4985 snprintf(url, sizeof(url), "Certs/%s-cert.pem", name);
4986 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
4987 "certificate from the device (%s)", url);
4988 if (!file_exists(url)) {
4989 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
4990 "certificate file does not exist");
4991 return 0;
4992 }
4993 snprintf(buf, sizeof(buf), "cp %s next-client-cert.pem", url);
4994 if (system(buf) != 0) {
4995 send_resp(dut, conn, SIGMA_ERROR,
4996 "errorCode,Failed to copy client "
4997 "certificate");
4998 return 0;
4999 }
5000
5001 snprintf(url, sizeof(url), "Certs/%s-key.pem", name);
5002 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
5003 "private key from the device (%s)", url);
5004 if (!file_exists(url)) {
5005 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
5006 "private key file does not exist");
5007 return 0;
5008 }
5009 snprintf(buf, sizeof(buf), "cp %s next-client-key.pem", url);
5010 if (system(buf) != 0) {
5011 send_resp(dut, conn, SIGMA_ERROR,
5012 "errorCode,Failed to copy client key");
5013 return 0;
5014 }
5015 } else if (strncasecmp(path, "http:", 5) != 0 &&
5016 strncasecmp(path, "https:", 6) != 0) {
5017 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
5018 "Unsupported FilePath value");
5019 return 0;
5020 } else {
5021 snprintf(url, sizeof(url), "%s/%s.pem", path, name);
5022 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading client "
5023 "certificate/key from %s", url);
5024 snprintf(buf, sizeof(buf),
5025 "wget -T 10 -t 3 -O next-client-cert.pem '%s'", url);
5026 if (system(buf) != 0) {
5027 send_resp(dut, conn, SIGMA_ERROR,
5028 "errorCode,Failed to download client "
5029 "certificate");
5030 return 0;
5031 }
5032
5033 if (system("cp next-client-cert.pem next-client-key.pem") != 0)
5034 {
5035 send_resp(dut, conn, SIGMA_ERROR,
5036 "errorCode,Failed to copy client key");
5037 return 0;
5038 }
5039 }
5040
5041 return 1;
5042}
5043
5044
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02005045static int cmd_sta_preset_testparameters_60ghz(struct sigma_dut *dut,
5046 struct sigma_conn *conn,
5047 struct sigma_cmd *cmd)
5048{
5049 const char *val;
5050 const char *intf = get_param(cmd, "interface");
5051
5052 if (!intf)
5053 return -1;
5054
5055 val = get_param(cmd, "WscIEFragment");
5056 if (val && strcasecmp(val, "enable") == 0) {
5057 sigma_dut_print(dut, DUT_MSG_DEBUG,
5058 "Enable WSC IE fragmentation");
5059
5060 dut->wsc_fragment = 1;
5061 /* set long attributes to force fragmentation */
5062 if (wpa_command(intf, "SET device_name "
5063 WPS_LONG_DEVICE_NAME) < 0)
5064 return -2;
5065 if (wpa_command(intf, "SET manufacturer "
5066 WPS_LONG_MANUFACTURER) < 0)
5067 return -2;
5068 if (wpa_command(intf, "SET model_name "
5069 WPS_LONG_MODEL_NAME) < 0)
5070 return -2;
5071 if (wpa_command(intf, "SET model_number "
5072 WPS_LONG_MODEL_NUMBER) < 0)
5073 return -2;
5074 if (wpa_command(intf, "SET serial_number "
5075 WPS_LONG_SERIAL_NUMBER) < 0)
5076 return -2;
5077 }
5078
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02005079 val = get_param(cmd, "RSN_IE");
5080 if (val) {
5081 if (strcasecmp(val, "disable") == 0)
5082 dut->force_rsn_ie = FORCE_RSN_IE_REMOVE;
5083 else if (strcasecmp(val, "enable") == 0)
5084 dut->force_rsn_ie = FORCE_RSN_IE_ADD;
5085 }
5086
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02005087 val = get_param(cmd, "WpsVersion");
5088 if (val)
5089 dut->wps_forced_version = get_wps_forced_version(dut, val);
5090
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02005091 val = get_param(cmd, "WscEAPFragment");
5092 if (val && strcasecmp(val, "enable") == 0)
5093 dut->eap_fragment = 1;
5094
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02005095 return 1;
5096}
5097
5098
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005099static int cmd_sta_preset_testparameters_hs2_r2(struct sigma_dut *dut,
5100 struct sigma_conn *conn,
5101 const char *intf,
5102 struct sigma_cmd *cmd)
5103{
5104 const char *val;
5105
5106 val = get_param(cmd, "FileType");
5107 if (val && strcasecmp(val, "PPSMO") == 0)
5108 return download_ppsmo(dut, conn, intf, cmd);
5109 if (val && strcasecmp(val, "CERT") == 0)
5110 return download_cert(dut, conn, intf, cmd);
5111 if (val) {
5112 send_resp(dut, conn, SIGMA_ERROR,
5113 "ErrorCode,Unsupported FileType");
5114 return 0;
5115 }
5116
5117 return 1;
5118}
5119
5120
Ankita Bajaja2cb5672017-10-25 16:08:28 +05305121static int cmd_sta_preset_testparameters_oce(struct sigma_dut *dut,
5122 struct sigma_conn *conn,
5123 const char *intf,
5124 struct sigma_cmd *cmd)
5125{
5126 const char *val;
Ankita Bajaj1bde7942018-01-09 19:15:01 +05305127 char buf[1000];
5128 char text[20];
5129 unsigned char addr[ETH_ALEN];
Ankita Bajaja2cb5672017-10-25 16:08:28 +05305130
5131 val = get_param(cmd, "OCESupport");
5132 if (val && strcasecmp(val, "Disable") == 0) {
5133 if (wpa_command(intf, "SET oce 0") < 0) {
5134 send_resp(dut, conn, SIGMA_ERROR,
5135 "ErrorCode,Failed to disable OCE");
5136 return 0;
5137 }
5138 } else if (val && strcasecmp(val, "Enable") == 0) {
5139 if (wpa_command(intf, "SET oce 1") < 0) {
5140 send_resp(dut, conn, SIGMA_ERROR,
5141 "ErrorCode,Failed to enable OCE");
5142 return 0;
5143 }
5144 }
5145
vamsi krishnaa2799492017-12-05 14:28:01 +05305146 val = get_param(cmd, "FILScap");
5147 if (val && (atoi(val) == 1)) {
5148 if (wpa_command(intf, "SET disable_fils 0") < 0) {
5149 send_resp(dut, conn, SIGMA_ERROR,
5150 "ErrorCode,Failed to enable FILS");
5151 return 0;
5152 }
5153 } else if (val && (atoi(val) == 0)) {
5154 if (wpa_command(intf, "SET disable_fils 1") < 0) {
5155 send_resp(dut, conn, SIGMA_ERROR,
5156 "ErrorCode,Failed to disable FILS");
5157 return 0;
5158 }
5159 }
5160
Ankita Bajaj1bde7942018-01-09 19:15:01 +05305161 val = get_param(cmd, "FILSHLP");
5162 if (val && strcasecmp(val, "Enable") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005163 if (get_wpa_status(get_station_ifname(dut), "address", text,
Ankita Bajaj1bde7942018-01-09 19:15:01 +05305164 sizeof(text)) < 0)
5165 return -2;
5166 hwaddr_aton(text, addr);
5167 snprintf(buf, sizeof(buf),
5168 "FILS_HLP_REQ_ADD ff:ff:ff:ff:ff:ff "
5169 "080045100140000040004011399e00000000ffffffff00440043"
5170 "012cb30001010600fd4f46410000000000000000000000000000"
5171 "000000000000"
5172 "%02x%02x%02x%02x%02x%02x"
5173 "0000000000000000000000000000000000000000000000000000"
5174 "0000000000000000000000000000000000000000000000000000"
5175 "0000000000000000000000000000000000000000000000000000"
5176 "0000000000000000000000000000000000000000000000000000"
5177 "0000000000000000000000000000000000000000000000000000"
5178 "0000000000000000000000000000000000000000000000000000"
5179 "0000000000000000000000000000000000000000000000000000"
5180 "0000000000000000000000000000000000000000638253633501"
5181 "013d0701000af549d29b390205dc3c12616e64726f69642d6468"
5182 "63702d382e302e30370a0103060f1a1c333a3b2b5000ff00",
5183 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
5184 if (wpa_command(intf, buf)) {
5185 send_resp(dut, conn, SIGMA_ERROR,
5186 "ErrorCode,Failed to add HLP");
5187 return 0;
5188 }
5189 dut->fils_hlp = 1;
5190 }
5191
Ankita Bajaja2cb5672017-10-25 16:08:28 +05305192 return 1;
5193}
5194
5195
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005196static void ath_sta_set_noack(struct sigma_dut *dut, const char *intf,
5197 const char *val)
5198{
5199 int counter = 0;
5200 char token[50];
5201 char *result;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05305202 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005203
Peng Xub8fc5cc2017-05-10 17:27:28 -07005204 strlcpy(token, val, sizeof(token));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005205 token[sizeof(token) - 1] = '\0';
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05305206 result = strtok_r(token, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005207 while (result) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005208 if (strcmp(result, "disable") == 0)
5209 run_iwpriv(dut, intf, "noackpolicy %d 1 0", counter);
5210 else
5211 run_iwpriv(dut, intf, "noackpolicy %d 1 1", counter);
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05305212 result = strtok_r(NULL, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005213 counter++;
5214 }
5215}
5216
5217
5218static void ath_sta_set_rts(struct sigma_dut *dut, const char *intf,
5219 const char *val)
5220{
5221 char buf[100];
5222
5223 snprintf(buf, sizeof(buf), "iwconfig %s rts %s", intf, val);
5224 if (system(buf) != 0) {
5225 sigma_dut_print(dut, DUT_MSG_ERROR, "iwconfig RTS failed");
5226 }
5227}
5228
5229
5230static void ath_sta_set_wmm(struct sigma_dut *dut, const char *intf,
5231 const char *val)
5232{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005233 if (strcasecmp(val, "off") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005234 run_iwpriv(dut, intf, "wmm 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005235 }
5236}
5237
5238
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08005239static int wcn_sta_set_wmm(struct sigma_dut *dut, const char *intf,
5240 const char *val)
5241{
5242#ifdef NL80211_SUPPORT
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08005243 int wmmenable = 1;
5244
5245 if (val &&
5246 (strcasecmp(val, "off") == 0 || strcmp(val, "0") == 0))
5247 wmmenable = 0;
5248
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05305249 return wcn_wifi_test_config_set_u8(
5250 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WMM_ENABLE,
5251 wmmenable);
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08005252#else /* NL80211_SUPPORT */
5253 sigma_dut_print(dut, DUT_MSG_ERROR,
5254 "WMM cannot be changed without NL80211_SUPPORT defined");
5255 return -1;
5256#endif /* NL80211_SUPPORT */
5257}
5258
5259
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005260static void ath_sta_set_sgi(struct sigma_dut *dut, const char *intf,
5261 const char *val)
5262{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005263 int sgi20;
5264
5265 sgi20 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
5266
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005267 run_iwpriv(dut, intf, "shortgi %d", sgi20);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005268}
5269
5270
5271static void ath_sta_set_11nrates(struct sigma_dut *dut, const char *intf,
5272 const char *val)
5273{
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05305274 int rate_code, v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005275
5276 /* Disable Tx Beam forming when using a fixed rate */
5277 ath_disable_txbf(dut, intf);
5278
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05305279 v = atoi(val);
5280 if (v < 0 || v > 32) {
5281 sigma_dut_print(dut, DUT_MSG_ERROR,
5282 "Invalid Fixed MCS rate: %d", v);
5283 return;
5284 }
5285 rate_code = 0x80 + v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005286
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005287 run_iwpriv(dut, intf, "set11NRates 0x%x", rate_code);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005288
5289 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005290 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005291}
5292
5293
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08005294static void iwpriv_sta_set_amsdu(struct sigma_dut *dut, const char *intf,
5295 const char *val)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005296{
5297 char buf[60];
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05305298 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005299
5300 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)
5301 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 2", intf);
5302 else
5303 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf);
5304
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05305305 ret = system(buf);
5306#ifdef NL80211_SUPPORT
5307 if (ret) {
5308 int value = (strcasecmp(val, "Enable") == 0) ? 2 : 1;
5309
5310 ret = sta_config_params(dut, intf, STA_SET_TX_MSDU, value);
5311 ret |= sta_config_params(dut, intf, STA_SET_RX_MSDU, value);
5312 }
5313#endif /* NL80211_SUPPORT */
5314 if (ret)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005315 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv amsdu failed");
5316}
5317
5318
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07005319static int iwpriv_sta_set_ampdu(struct sigma_dut *dut, const char *intf,
5320 int ampdu)
5321{
5322 char buf[60];
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08005323 int maxaggregation = 63;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07005324
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08005325 if (ampdu)
5326 ampdu = maxaggregation;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07005327 snprintf(buf, sizeof(buf), "iwpriv %s ampdu %d", intf, ampdu);
5328 if (system(buf) != 0) {
5329 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv ampdu failed");
5330 return -1;
5331 }
5332
5333 return 0;
5334}
5335
5336
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005337static void ath_sta_set_stbc(struct sigma_dut *dut, const char *intf,
5338 const char *val)
5339{
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005340 run_iwpriv(dut, intf, "tx_stbc %s", val);
5341 run_iwpriv(dut, intf, "rx_stbc %s", val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005342}
5343
5344
5345static int wcn_sta_set_cts_width(struct sigma_dut *dut, const char *intf,
5346 const char *val)
5347{
5348 char buf[60];
5349
Peng Xucc317ed2017-05-18 16:44:37 -07005350 if (strcmp(val, "160") == 0) {
5351 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 5", intf);
5352 } else if (strcmp(val, "80") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005353 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
5354 } else if (strcmp(val, "40") == 0) {
5355 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 2", intf);
5356 } else if (strcmp(val, "20") == 0) {
5357 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 1", intf);
5358 } else if (strcasecmp(val, "Auto") == 0) {
5359 buf[0] = '\0';
5360 } else {
5361 sigma_dut_print(dut, DUT_MSG_ERROR,
5362 "WIDTH/CTS_WIDTH value not supported");
5363 return -1;
5364 }
5365
5366 if (buf[0] != '\0' && system(buf) != 0) {
5367 sigma_dut_print(dut, DUT_MSG_ERROR,
5368 "Failed to set WIDTH/CTS_WIDTH");
5369 return -1;
5370 }
5371
5372 return 0;
5373}
5374
5375
5376int ath_set_width(struct sigma_dut *dut, struct sigma_conn *conn,
5377 const char *intf, const char *val)
5378{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005379 if (strcasecmp(val, "Auto") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005380 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005381 dut->chwidth = 0;
5382 } else if (strcasecmp(val, "20") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005383 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005384 dut->chwidth = 0;
5385 } else if (strcasecmp(val, "40") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005386 run_iwpriv(dut, intf, "chwidth 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005387 dut->chwidth = 1;
5388 } else if (strcasecmp(val, "80") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005389 run_iwpriv(dut, intf, "chwidth 2");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005390 dut->chwidth = 2;
5391 } else if (strcasecmp(val, "160") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005392 run_iwpriv(dut, intf, "chwidth 3");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005393 dut->chwidth = 3;
5394 } else {
5395 send_resp(dut, conn, SIGMA_ERROR,
5396 "ErrorCode,WIDTH not supported");
5397 return -1;
5398 }
5399
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005400 return 0;
5401}
5402
5403
5404static int wcn_sta_set_sp_stream(struct sigma_dut *dut, const char *intf,
5405 const char *val)
5406{
5407 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07005408 int sta_nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005409
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08005410 if (strcmp(val, "1SS") == 0 || strcmp(val, "1") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005411 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07005412 sta_nss = 1;
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08005413 } else if (strcmp(val, "2SS") == 0 || strcmp(val, "2") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005414 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07005415 sta_nss = 2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005416 } else {
5417 sigma_dut_print(dut, DUT_MSG_ERROR,
5418 "SP_STREAM value not supported");
5419 return -1;
5420 }
5421
5422 if (system(buf) != 0) {
5423 sigma_dut_print(dut, DUT_MSG_ERROR,
5424 "Failed to set SP_STREAM");
5425 return -1;
5426 }
5427
Arif Hussainac6c5112018-05-25 17:34:00 -07005428 dut->sta_nss = sta_nss;
5429
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005430 return 0;
5431}
5432
5433
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05305434static void wcn_sta_set_stbc(struct sigma_dut *dut, const char *intf,
5435 const char *val)
5436{
5437 char buf[60];
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05305438 int ret;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05305439
5440 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc %s", intf, val);
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05305441 ret = system(buf);
5442#ifdef NL80211_SUPPORT
5443 if (ret)
5444 ret = sta_config_params(dut, intf, STA_SET_TX_STBC,
5445 strcmp(val, "0") == 0 ? 0 : 1);
5446#endif /* NL80211_SUPPORT */
5447 if (ret)
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05305448 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv tx_stbc failed");
5449
5450 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc %s", intf, val);
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05305451 ret = system(buf);
5452#ifdef NL80211_SUPPORT
5453 if (ret)
5454 ret = sta_config_params(dut, intf, STA_SET_RX_STBC,
5455 strcmp(val, "0") == 0 ? 0 : 1);
5456#endif /* NL80211_SUPPORT */
5457 if (ret)
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05305458 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv rx_stbc failed");
5459}
5460
5461
Ashwini Patil68d02cd2017-01-10 15:39:16 +05305462static int mbo_set_cellular_data_capa(struct sigma_dut *dut,
5463 struct sigma_conn *conn,
5464 const char *intf, int capa)
5465{
5466 char buf[32];
5467
5468 if (capa > 0 && capa < 4) {
5469 snprintf(buf, sizeof(buf), "SET mbo_cell_capa %d", capa);
5470 if (wpa_command(intf, buf) < 0) {
5471 send_resp(dut, conn, SIGMA_ERROR,
5472 "ErrorCode, Failed to set cellular data capability");
5473 return 0;
5474 }
5475 return 1;
5476 }
5477
5478 sigma_dut_print(dut, DUT_MSG_ERROR,
5479 "Invalid Cellular data capability: %d", capa);
5480 send_resp(dut, conn, SIGMA_INVALID,
5481 "ErrorCode,Invalid cellular data capability");
5482 return 0;
5483}
5484
5485
Ashwini Patil9183fdb2017-04-13 16:58:25 +05305486static int mbo_set_roaming(struct sigma_dut *dut, struct sigma_conn *conn,
5487 const char *intf, const char *val)
5488{
5489 if (strcasecmp(val, "Disable") == 0) {
5490 if (wpa_command(intf, "SET roaming 0") < 0) {
5491 send_resp(dut, conn, SIGMA_ERROR,
5492 "ErrorCode,Failed to disable roaming");
5493 return 0;
5494 }
5495 return 1;
5496 }
5497
5498 if (strcasecmp(val, "Enable") == 0) {
5499 if (wpa_command(intf, "SET roaming 1") < 0) {
5500 send_resp(dut, conn, SIGMA_ERROR,
5501 "ErrorCode,Failed to enable roaming");
5502 return 0;
5503 }
5504 return 1;
5505 }
5506
5507 sigma_dut_print(dut, DUT_MSG_ERROR,
5508 "Invalid value provided for roaming: %s", val);
5509 send_resp(dut, conn, SIGMA_INVALID,
5510 "ErrorCode,Unknown value provided for Roaming");
5511 return 0;
5512}
5513
5514
Ashwini Patila75de5a2017-04-13 16:35:05 +05305515static int mbo_set_assoc_disallow(struct sigma_dut *dut,
5516 struct sigma_conn *conn,
5517 const char *intf, const char *val)
5518{
5519 if (strcasecmp(val, "Disable") == 0) {
5520 if (wpa_command(intf, "SET ignore_assoc_disallow 1") < 0) {
5521 send_resp(dut, conn, SIGMA_ERROR,
5522 "ErrorCode,Failed to disable Assoc_disallow");
5523 return 0;
5524 }
5525 return 1;
5526 }
5527
5528 if (strcasecmp(val, "Enable") == 0) {
5529 if (wpa_command(intf, "SET ignore_assoc_disallow 0") < 0) {
5530 send_resp(dut, conn, SIGMA_ERROR,
5531 "ErrorCode,Failed to enable Assoc_disallow");
5532 return 0;
5533 }
5534 return 1;
5535 }
5536
5537 sigma_dut_print(dut, DUT_MSG_ERROR,
5538 "Invalid value provided for Assoc_disallow: %s", val);
5539 send_resp(dut, conn, SIGMA_INVALID,
5540 "ErrorCode,Unknown value provided for Assoc_disallow");
5541 return 0;
5542}
5543
5544
Ashwini Patilc63161e2017-04-13 16:30:23 +05305545static int mbo_set_bss_trans_req(struct sigma_dut *dut, struct sigma_conn *conn,
5546 const char *intf, const char *val)
5547{
5548 if (strcasecmp(val, "Reject") == 0) {
5549 if (wpa_command(intf, "SET reject_btm_req_reason 1") < 0) {
5550 send_resp(dut, conn, SIGMA_ERROR,
5551 "ErrorCode,Failed to Reject BTM Request");
5552 return 0;
5553 }
5554 return 1;
5555 }
5556
5557 if (strcasecmp(val, "Accept") == 0) {
5558 if (wpa_command(intf, "SET reject_btm_req_reason 0") < 0) {
5559 send_resp(dut, conn, SIGMA_ERROR,
5560 "ErrorCode,Failed to Accept BTM Request");
5561 return 0;
5562 }
5563 return 1;
5564 }
5565
5566 sigma_dut_print(dut, DUT_MSG_ERROR,
5567 "Invalid value provided for BSS_Transition: %s", val);
5568 send_resp(dut, conn, SIGMA_INVALID,
5569 "ErrorCode,Unknown value provided for BSS_Transition");
5570 return 0;
5571}
5572
5573
Ashwini Patil00402582017-04-13 12:29:39 +05305574static int mbo_set_non_pref_ch_list(struct sigma_dut *dut,
5575 struct sigma_conn *conn,
5576 const char *intf,
5577 struct sigma_cmd *cmd)
5578{
5579 const char *ch, *pref, *op_class, *reason;
5580 char buf[120];
5581 int len, ret;
5582
5583 pref = get_param(cmd, "Ch_Pref");
5584 if (!pref)
5585 return 1;
5586
5587 if (strcasecmp(pref, "clear") == 0) {
5588 free(dut->non_pref_ch_list);
5589 dut->non_pref_ch_list = NULL;
5590 } else {
5591 op_class = get_param(cmd, "Ch_Op_Class");
5592 if (!op_class) {
5593 send_resp(dut, conn, SIGMA_INVALID,
5594 "ErrorCode,Ch_Op_Class not provided");
5595 return 0;
5596 }
5597
5598 ch = get_param(cmd, "Ch_Pref_Num");
5599 if (!ch) {
5600 send_resp(dut, conn, SIGMA_INVALID,
5601 "ErrorCode,Ch_Pref_Num not provided");
5602 return 0;
5603 }
5604
5605 reason = get_param(cmd, "Ch_Reason_Code");
5606 if (!reason) {
5607 send_resp(dut, conn, SIGMA_INVALID,
5608 "ErrorCode,Ch_Reason_Code not provided");
5609 return 0;
5610 }
5611
5612 if (!dut->non_pref_ch_list) {
5613 dut->non_pref_ch_list =
5614 calloc(1, NON_PREF_CH_LIST_SIZE);
5615 if (!dut->non_pref_ch_list) {
5616 send_resp(dut, conn, SIGMA_ERROR,
5617 "ErrorCode,Failed to allocate memory for non_pref_ch_list");
5618 return 0;
5619 }
5620 }
5621 len = strlen(dut->non_pref_ch_list);
5622 ret = snprintf(dut->non_pref_ch_list + len,
5623 NON_PREF_CH_LIST_SIZE - len,
5624 " %s:%s:%s:%s", op_class, ch, pref, reason);
5625 if (ret > 0 && ret < NON_PREF_CH_LIST_SIZE - len) {
5626 sigma_dut_print(dut, DUT_MSG_DEBUG, "non_pref_list: %s",
5627 dut->non_pref_ch_list);
5628 } else {
5629 sigma_dut_print(dut, DUT_MSG_ERROR,
5630 "snprintf failed for non_pref_list, ret = %d",
5631 ret);
5632 send_resp(dut, conn, SIGMA_ERROR,
5633 "ErrorCode,snprintf failed");
5634 free(dut->non_pref_ch_list);
5635 dut->non_pref_ch_list = NULL;
5636 return 0;
5637 }
5638 }
5639
5640 ret = snprintf(buf, sizeof(buf), "SET non_pref_chan%s",
5641 dut->non_pref_ch_list ? dut->non_pref_ch_list : " ");
5642 if (ret < 0 || ret >= (int) sizeof(buf)) {
5643 sigma_dut_print(dut, DUT_MSG_DEBUG,
5644 "snprintf failed for set non_pref_chan, ret: %d",
5645 ret);
5646 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,snprint failed");
5647 return 0;
5648 }
5649
5650 if (wpa_command(intf, buf) < 0) {
5651 send_resp(dut, conn, SIGMA_ERROR,
5652 "ErrorCode,Failed to set non-preferred channel list");
5653 return 0;
5654 }
5655
5656 return 1;
5657}
5658
5659
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08005660#ifdef NL80211_SUPPORT
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08005661
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08005662static int sta_set_he_htc_supp(struct sigma_dut *dut, const char *intf,
5663 uint8_t cfg)
5664{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05305665 return wcn_wifi_test_config_set_u8(
5666 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_HTC_HE_SUPP,
5667 cfg);
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08005668}
5669
5670
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08005671static int sta_set_he_fragmentation(struct sigma_dut *dut, const char *intf,
5672 enum he_fragmentation_val frag)
5673{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05305674 return wcn_wifi_test_config_set_u8(
5675 dut, intf,
5676 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_FRAGMENTATION, frag);
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08005677}
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08005678
5679
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -08005680int wcn_set_he_ltf(struct sigma_dut *dut, const char *intf,
5681 enum qca_wlan_he_ltf_cfg ltf)
Subhani Shaik8e7a3052018-04-24 14:03:00 -07005682{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05305683 return wcn_wifi_test_config_set_u8(
5684 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_LTF, ltf);
Subhani Shaik8e7a3052018-04-24 14:03:00 -07005685}
5686
5687
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08005688static int nlvendor_sta_set_noack(struct sigma_dut *dut, const char *intf,
5689 int noack, enum qca_wlan_ac_type ac)
5690{
5691 struct nl_msg *msg;
5692 int ret = 0;
5693 struct nlattr *params;
5694 int ifindex;
5695
5696 ifindex = if_nametoindex(intf);
5697 if (ifindex == 0) {
5698 sigma_dut_print(dut, DUT_MSG_ERROR,
5699 "%s: Index for interface %s failed",
5700 __func__, intf);
5701 return -1;
5702 }
5703
5704 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5705 NL80211_CMD_VENDOR)) ||
5706 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5707 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5708 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5709 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5710 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5711 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_NO_ACK,
5712 noack) ||
5713 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_NO_ACK_AC,
5714 ac)) {
5715 sigma_dut_print(dut, DUT_MSG_ERROR,
5716 "%s: err in adding vendor_cmd and vendor_data",
5717 __func__);
5718 nlmsg_free(msg);
5719 return -1;
5720 }
5721 nla_nest_end(msg, params);
5722
5723 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5724 if (ret) {
5725 sigma_dut_print(dut, DUT_MSG_ERROR,
5726 "%s: err in send_and_recv_msgs, ret=%d",
5727 __func__, ret);
5728 }
5729 return ret;
5730}
5731
5732
5733static void wcn_sta_set_noack(struct sigma_dut *dut, const char *intf,
5734 const char *val)
5735{
5736 int noack, ret;
5737 char token[100];
5738 char *result;
5739 char *saveptr;
5740 enum qca_wlan_ac_type ac = QCA_WLAN_AC_BE;
5741
5742 strlcpy(token, val, sizeof(token));
5743 token[sizeof(token) - 1] = '\0';
5744 result = strtok_r(token, ":", &saveptr);
5745 while (result) {
5746 noack = strcasecmp(result, "Disable") != 0;
5747 ret = nlvendor_sta_set_noack(dut, intf, noack, ac);
5748 if (ret) {
5749 sigma_dut_print(dut, DUT_MSG_ERROR,
5750 "nlvendor_sta_set_noack failed for ac:%d, ret:%d",
5751 ac, ret);
5752 }
5753 result = strtok_r(NULL, ":", &saveptr);
5754 ac++;
5755 }
5756}
5757
Vinita S. Maloo7462e812020-05-22 15:16:04 +05305758
5759static int nlvendor_sta_set_phymode(struct sigma_dut *dut, const char *intf,
5760 enum qca_wlan_vendor_phy_mode val)
5761{
5762 struct nl_msg *msg;
5763 struct nlattr *params;
5764 int ifindex, ret;
5765
5766 ifindex = if_nametoindex(intf);
5767 if (ifindex == 0) {
5768 sigma_dut_print(dut, DUT_MSG_ERROR,
5769 "%s: Index for interface %s not found",
5770 __func__, intf);
5771 return -1;
5772 }
5773
5774 msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5775 NL80211_CMD_VENDOR);
5776 if (!msg) {
5777 sigma_dut_print(dut, DUT_MSG_ERROR,
5778 "%s: err in adding vendor_cmd", __func__);
5779 return -1;
5780 }
5781
5782 if (nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5783 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5784 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION)) {
5785 sigma_dut_print(dut, DUT_MSG_ERROR,
5786 "%s: err in adding vendor_attr", __func__);
5787 nlmsg_free(msg);
5788 return -1;
5789 }
5790
5791 params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
5792 if (!params || nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_PHY_MODE,
5793 val)) {
5794 sigma_dut_print(dut, DUT_MSG_ERROR,
5795 "%s: err in adding vendor_data", __func__);
5796 nlmsg_free(msg);
5797 return -1;
5798 }
5799
5800 nla_nest_end(msg, params);
5801 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5802 if (ret) {
5803 sigma_dut_print(dut, DUT_MSG_ERROR,
5804 "%s: err in send_and_recv_msgs, ret=%d (%s)",
5805 __func__, ret, strerror(-ret));
5806 return ret;
5807 }
5808
5809 return 0;
5810}
5811
5812
5813static enum qca_wlan_vendor_phy_mode get_qca_vendor_phymode(const char *val)
5814{
5815 if (strcmp(val, "11a") == 0) {
5816 /* IEEE80211_MODE_11A */
5817 return QCA_WLAN_VENDOR_PHY_MODE_11A;
5818 }
5819
5820 if (strcmp(val, "11g") == 0) {
5821 /* IEEE80211_MODE_11G */
5822 return QCA_WLAN_VENDOR_PHY_MODE_11G;
5823 }
5824
5825 if (strcmp(val, "11b") == 0) {
5826 /* IEEE80211_MODE_11B */
5827 return QCA_WLAN_VENDOR_PHY_MODE_11B;
5828 }
5829
5830 if (strcmp(val, "11n") == 0 ||
5831 strcmp(val, "11nl") == 0 ||
5832 strcmp(val, "11nl(nabg)") == 0) {
5833 /* IEEE80211_MODE_11AGN */
5834 return QCA_WLAN_VENDOR_PHY_MODE_11AGN;
5835 }
5836
5837 if (strcmp(val, "11ng") == 0) {
5838 /* IEEE80211_MODE_11NG_HT40 */
5839 return QCA_WLAN_VENDOR_PHY_MODE_11NG_HT40;
5840 }
5841
5842 if (strcmp(val, "AC") == 0 ||
5843 strcasecmp(val, "11AC") == 0) {
5844 /* IEEE80211_MODE_11AC_VHT80 */
5845 return QCA_WLAN_VENDOR_PHY_MODE_11AC_VHT80;
5846 }
5847
5848 if (strcmp(val, "11na") == 0 ||
5849 strcasecmp(val, "11an") == 0) {
5850 /* IEEE80211_MODE_11NA_HT40 */
5851 return QCA_WLAN_VENDOR_PHY_MODE_11NA_HT40;
5852 }
5853
5854 if (strcmp(val, "11ax") == 0 ||
5855 strcmp(val, "auto") == 0) {
5856 /* IEEE80211_MODE_AUTO */
5857 return QCA_WLAN_VENDOR_PHY_MODE_AUTO;
5858 }
5859
5860 return -1;
5861}
5862
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08005863#endif /* NL80211_SUPPORT */
5864
5865
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05305866static int get_phymode(const char *val)
5867{
5868 if (strcmp(val, "11a") == 0)
5869 return 1; /* IEEE80211_MODE_11A */
5870 if (strcmp(val, "11g") == 0)
5871 return 3; /* IEEE80211_MODE_11G */
5872 if (strcmp(val, "11b") == 0)
5873 return 2; /* IEEE80211_MODE_11B */
5874 if (strcmp(val, "11n") == 0 ||
5875 strcmp(val, "11nl") == 0 ||
5876 strcmp(val, "11nl(nabg)") == 0)
5877 return 22; /* IEEE80211_MODE_11AGN */
5878 if (strcmp(val, "11ng") == 0)
5879 return 13; /* IEEE80211_MODE_11NG_HT40 */
5880 if (strcmp(val, "AC") == 0 ||
5881 strcasecmp(val, "11AC") == 0)
5882 return 19; /* IEEE80211_MODE_11AC_VHT80 */
5883 if (strcmp(val, "11na") == 0 ||
5884 strcasecmp(val, "11an") == 0)
5885 return 14; /* IEEE80211_MODE_11NA_HT40 */
5886 if (strcmp(val, "11ax") == 0 ||
5887 strcmp(val, "auto") == 0)
5888 return 0; /* IEEE80211_MODE_AUTO */
5889 return -1;
5890}
5891
5892
5893static void sta_set_phymode(struct sigma_dut *dut, const char *intf,
5894 const char *val)
5895{
5896 char buf[100];
5897 int len, phymode;
Vinita S. Maloo7462e812020-05-22 15:16:04 +05305898#ifdef NL80211_SUPPORT
5899 enum qca_wlan_vendor_phy_mode qca_phymode;
5900
5901 qca_phymode = get_qca_vendor_phymode(val);
5902 if (qca_phymode == -1) {
5903 sigma_dut_print(dut, DUT_MSG_DEBUG,
5904 "Ignoring mode change for mode: %s",
5905 val);
5906 return;
5907 }
5908
5909 if (nlvendor_sta_set_phymode(dut, intf, qca_phymode) == 0)
5910 return;
5911#endif /* NL80211_SUPPORT */
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05305912
5913 phymode = get_phymode(val);
5914 if (phymode == -1) {
5915 sigma_dut_print(dut, DUT_MSG_DEBUG,
5916 "Ignoring mode change for mode: %s",
5917 val);
5918 return;
5919 }
5920
5921 len = snprintf(buf, sizeof(buf), "iwpriv %s setphymode %d", intf,
5922 phymode);
5923 if (len < 0 || len >= sizeof(buf)) {
5924 sigma_dut_print(dut, DUT_MSG_ERROR,
5925 "Failed to set phymode");
5926 return;
5927 }
5928
5929 if (system(buf) != 0)
5930 sigma_dut_print(dut, DUT_MSG_ERROR,
5931 "iwpriv setting of phymode failed");
5932}
5933
5934
Jouni Malinenf7222712019-06-13 01:50:21 +03005935static enum sigma_cmd_result
5936cmd_sta_preset_testparameters(struct sigma_dut *dut, struct sigma_conn *conn,
5937 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005938{
5939 const char *intf = get_param(cmd, "Interface");
5940 const char *val;
5941
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03005942 val = get_param(cmd, "FT_DS");
5943 if (val) {
5944 if (strcasecmp(val, "Enable") == 0) {
5945 dut->sta_ft_ds = 1;
5946 } else if (strcasecmp(val, "Disable") == 0) {
5947 dut->sta_ft_ds = 0;
5948 } else {
5949 send_resp(dut, conn, SIGMA_ERROR,
5950 "errorCode,Unsupported value for FT_DS");
5951 return STATUS_SENT_ERROR;
5952 }
Shivani Baranwal7aa48602021-09-29 10:53:38 +05305953 if (get_driver_type(dut) == DRIVER_WCN &&
5954 sta_config_params(dut, intf, STA_SET_FT_DS,
5955 dut->sta_ft_ds) != 0) {
5956 send_resp(dut, conn, SIGMA_ERROR,
5957 "errorCode,Failed to enable/disable FT_DS");
5958 return STATUS_SENT_ERROR;
5959 }
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03005960 }
5961
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005962 val = get_param(cmd, "Program");
Jouni Malinen1f6ae642018-06-07 23:56:13 +03005963 if (val && (strcasecmp(val, "HS2-R2") == 0 ||
5964 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005965 return cmd_sta_preset_testparameters_hs2_r2(dut, conn, intf,
5966 cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005967
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07005968 if (val && strcasecmp(val, "LOC") == 0)
5969 return loc_cmd_sta_preset_testparameters(dut, conn, cmd);
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02005970 if (val && strcasecmp(val, "60GHZ") == 0) {
5971 val = get_param(cmd, "WPS");
5972 if (val && strcasecmp(val, "disable") == 0) {
5973 dut->wps_disable = 1;
5974 sigma_dut_print(dut, DUT_MSG_INFO, "WPS disabled");
5975 } else {
5976 /* wps_disable can have other value from the previous
5977 * test, so make sure it has the correct value.
5978 */
5979 dut->wps_disable = 0;
5980 }
5981
5982 val = get_param(cmd, "P2P");
5983 if (val && strcasecmp(val, "disable") == 0)
5984 sigma_dut_print(dut, DUT_MSG_INFO, "P2P disabled");
5985 }
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07005986
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02005987 if (dut->program == PROGRAM_WPS && dut->band == WPS_BAND_60G)
5988 return cmd_sta_preset_testparameters_60ghz(dut, conn, cmd);
5989
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005990#ifdef ANDROID_NAN
5991 if (val && strcasecmp(val, "NAN") == 0)
5992 return nan_cmd_sta_preset_testparameters(dut, conn, cmd);
5993#endif /* ANDROID_NAN */
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07005994#ifdef MIRACAST
5995 if (val && (strcasecmp(val, "WFD") == 0 ||
5996 strcasecmp(val, "DisplayR2") == 0))
5997 return miracast_preset_testparameters(dut, conn, cmd);
5998#endif /* MIRACAST */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005999
Kiran Kumar Lokeredd086642020-06-04 00:29:26 -07006000 if (val &&
6001 (strcasecmp(val, "MBO") == 0 || strcasecmp(val, "HE") == 0)) {
Ashwini Patil68d02cd2017-01-10 15:39:16 +05306002 val = get_param(cmd, "Cellular_Data_Cap");
6003 if (val &&
6004 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
6005 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +05306006
6007 val = get_param(cmd, "Ch_Pref");
6008 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
6009 return 0;
6010
Ashwini Patilc63161e2017-04-13 16:30:23 +05306011 val = get_param(cmd, "BSS_Transition");
6012 if (val && mbo_set_bss_trans_req(dut, conn, intf, val) == 0)
6013 return 0;
6014
Ashwini Patila75de5a2017-04-13 16:35:05 +05306015 val = get_param(cmd, "Assoc_Disallow");
6016 if (val && mbo_set_assoc_disallow(dut, conn, intf, val) == 0)
6017 return 0;
6018
Ashwini Patil9183fdb2017-04-13 16:58:25 +05306019 val = get_param(cmd, "Roaming");
6020 if (val && mbo_set_roaming(dut, conn, intf, val) == 0)
6021 return 0;
6022
Ashwini Patil68d02cd2017-01-10 15:39:16 +05306023 return 1;
6024 }
6025
Ankita Bajaja2cb5672017-10-25 16:08:28 +05306026 if (val && strcasecmp(val, "OCE") == 0)
6027 return cmd_sta_preset_testparameters_oce(dut, conn, intf, cmd);
6028
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006029#if 0
6030 val = get_param(cmd, "Supplicant");
6031 if (val && strcasecmp(val, "Default") != 0) {
6032 send_resp(dut, conn, SIGMA_ERROR,
6033 "ErrorCode,Only default(Vendor) supplicant "
6034 "supported");
6035 return 0;
6036 }
6037#endif
6038
6039 val = get_param(cmd, "RTS");
6040 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006041 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006042 case DRIVER_ATHEROS:
6043 ath_sta_set_rts(dut, intf, val);
6044 break;
6045 default:
6046#if 0
6047 send_resp(dut, conn, SIGMA_ERROR,
6048 "ErrorCode,Setting RTS not supported");
6049 return 0;
6050#else
6051 sigma_dut_print(dut, DUT_MSG_DEBUG,
6052 "Setting RTS not supported");
6053 break;
6054#endif
6055 }
6056 }
6057
6058#if 0
6059 val = get_param(cmd, "FRGMNT");
6060 if (val) {
6061 /* TODO */
6062 send_resp(dut, conn, SIGMA_ERROR,
6063 "ErrorCode,Setting FRGMNT not supported");
6064 return 0;
6065 }
6066#endif
6067
6068#if 0
6069 val = get_param(cmd, "Preamble");
6070 if (val) {
6071 /* TODO: Long/Short */
6072 send_resp(dut, conn, SIGMA_ERROR,
6073 "ErrorCode,Setting Preamble not supported");
6074 return 0;
6075 }
6076#endif
6077
6078 val = get_param(cmd, "Mode");
6079 if (val) {
6080 if (strcmp(val, "11b") == 0 ||
6081 strcmp(val, "11g") == 0 ||
6082 strcmp(val, "11a") == 0 ||
6083 strcmp(val, "11n") == 0 ||
6084 strcmp(val, "11ng") == 0 ||
6085 strcmp(val, "11nl") == 0 ||
6086 strcmp(val, "11nl(nabg)") == 0 ||
6087 strcmp(val, "AC") == 0 ||
6088 strcmp(val, "11AC") == 0 ||
6089 strcmp(val, "11ac") == 0 ||
6090 strcmp(val, "11na") == 0 ||
Amarnath Hullur Subramanyamb0db2712018-01-30 19:40:35 -08006091 strcmp(val, "11an") == 0 ||
6092 strcmp(val, "11ax") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006093 /* STA supports all modes by default */
6094 } else {
6095 send_resp(dut, conn, SIGMA_ERROR,
6096 "ErrorCode,Setting Mode not supported");
6097 return 0;
6098 }
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08006099
6100 /* Change the mode only in case of testbed for HE program
6101 * and for 11a and 11g modes only. */
6102 if (dut->program == PROGRAM_HE &&
6103 dut->device_type == STA_testbed) {
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05306104 sta_set_phymode(dut, intf, val);
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08006105 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006106 }
6107
6108 val = get_param(cmd, "wmm");
6109 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006110 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006111 case DRIVER_ATHEROS:
6112 ath_sta_set_wmm(dut, intf, val);
6113 break;
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08006114 case DRIVER_WCN:
6115 wcn_sta_set_wmm(dut, intf, val);
6116 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006117 default:
6118 sigma_dut_print(dut, DUT_MSG_DEBUG,
6119 "Setting wmm not supported");
6120 break;
6121 }
6122 }
6123
6124 val = get_param(cmd, "Powersave");
6125 if (val) {
6126 if (strcmp(val, "0") == 0 || strcasecmp(val, "off") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006127 if (get_driver_type(dut) == DRIVER_WCN) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +05306128 if (set_power_save_wcn(dut, intf, 2) < 0)
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08006129 return 0;
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08006130 }
6131
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006132 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006133 "P2P_SET ps 0") < 0)
6134 return -2;
6135 /* Make sure test modes are disabled */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006136 wpa_command(get_station_ifname(dut), "P2P_SET ps 98");
6137 wpa_command(get_station_ifname(dut), "P2P_SET ps 96");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006138 } else if (strcmp(val, "1") == 0 ||
6139 strcasecmp(val, "PSPoll") == 0 ||
6140 strcasecmp(val, "on") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006141 if (get_driver_type(dut) == DRIVER_WCN) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +05306142 if (set_power_save_wcn(dut, intf, 1) < 0)
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08006143 return 0;
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08006144 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006145 /* Disable default power save mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006146 wpa_command(get_station_ifname(dut), "P2P_SET ps 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006147 /* Enable PS-Poll test mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006148 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006149 "P2P_SET ps 97") < 0 ||
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006150 wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006151 "P2P_SET ps 99") < 0)
6152 return -2;
6153 } else if (strcmp(val, "2") == 0 ||
6154 strcasecmp(val, "Fast") == 0) {
6155 /* TODO */
6156 send_resp(dut, conn, SIGMA_ERROR,
6157 "ErrorCode,Powersave=Fast not supported");
6158 return 0;
6159 } else if (strcmp(val, "3") == 0 ||
6160 strcasecmp(val, "PSNonPoll") == 0) {
6161 /* Make sure test modes are disabled */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006162 wpa_command(get_station_ifname(dut), "P2P_SET ps 98");
6163 wpa_command(get_station_ifname(dut), "P2P_SET ps 96");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006164
6165 /* Enable default power save mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006166 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006167 "P2P_SET ps 1") < 0)
6168 return -2;
6169 } else
6170 return -1;
6171 }
6172
6173 val = get_param(cmd, "NoAck");
6174 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006175 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006176 case DRIVER_ATHEROS:
6177 ath_sta_set_noack(dut, intf, val);
6178 break;
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08006179#ifdef NL80211_SUPPORT
6180 case DRIVER_WCN:
6181 wcn_sta_set_noack(dut, intf, val);
6182 break;
6183#endif /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006184 default:
6185 send_resp(dut, conn, SIGMA_ERROR,
6186 "ErrorCode,Setting NoAck not supported");
6187 return 0;
6188 }
6189 }
6190
6191 val = get_param(cmd, "IgnoreChswitchProhibit");
6192 if (val) {
6193 /* TODO: Enabled/disabled */
6194 if (strcasecmp(val, "Enabled") == 0) {
6195 send_resp(dut, conn, SIGMA_ERROR,
6196 "ErrorCode,Enabling IgnoreChswitchProhibit "
6197 "not supported");
6198 return 0;
6199 }
6200 }
6201
6202 val = get_param(cmd, "TDLS");
6203 if (val) {
6204 if (strcasecmp(val, "Disabled") == 0) {
6205 if (wpa_command(intf, "SET tdls_disabled 1")) {
6206 send_resp(dut, conn, SIGMA_ERROR,
6207 "ErrorCode,Failed to disable TDLS");
6208 return 0;
6209 }
6210 } else if (strcasecmp(val, "Enabled") == 0) {
6211 if (wpa_command(intf, "SET tdls_disabled 0")) {
6212 send_resp(dut, conn, SIGMA_ERROR,
6213 "ErrorCode,Failed to enable TDLS");
6214 return 0;
6215 }
6216 } else {
6217 send_resp(dut, conn, SIGMA_ERROR,
6218 "ErrorCode,Unsupported TDLS value");
6219 return 0;
6220 }
6221 }
6222
6223 val = get_param(cmd, "TDLSmode");
6224 if (val) {
6225 if (strcasecmp(val, "Default") == 0) {
6226 wpa_command(intf, "SET tdls_testing 0");
6227 } else if (strcasecmp(val, "APProhibit") == 0) {
6228 if (wpa_command(intf, "SET tdls_testing 0x400")) {
6229 send_resp(dut, conn, SIGMA_ERROR,
6230 "ErrorCode,Failed to enable ignore "
6231 "APProhibit TDLS mode");
6232 return 0;
6233 }
6234 } else if (strcasecmp(val, "HiLoMac") == 0) {
6235 /* STA should respond with TDLS setup req for a TDLS
6236 * setup req */
6237 if (wpa_command(intf, "SET tdls_testing 0x80")) {
6238 send_resp(dut, conn, SIGMA_ERROR,
6239 "ErrorCode,Failed to enable HiLoMac "
6240 "TDLS mode");
6241 return 0;
6242 }
6243 } else if (strcasecmp(val, "WeakSecurity") == 0) {
6244 /*
6245 * Since all security modes are enabled by default when
6246 * Sigma control is used, there is no need to do
6247 * anything here.
6248 */
6249 } else if (strcasecmp(val, "ExistLink") == 0) {
6250 /*
6251 * Since we allow new TDLS Setup Request even if there
6252 * is an existing link, nothing needs to be done for
6253 * this.
6254 */
6255 } else {
6256 /* TODO:
6257 * ExistLink: STA should send TDLS setup req even if
6258 * direct link already exists
6259 */
6260 send_resp(dut, conn, SIGMA_ERROR,
6261 "ErrorCode,Unsupported TDLSmode value");
6262 return 0;
6263 }
6264 }
6265
6266 val = get_param(cmd, "FakePubKey");
6267 if (val && atoi(val) && wpa_command(intf, "SET wps_corrupt_pkhash 1")) {
6268 send_resp(dut, conn, SIGMA_ERROR,
6269 "ErrorCode,Failed to enable FakePubKey");
6270 return 0;
6271 }
6272
Amarnath Hullur Subramanyamae1042b2018-02-22 21:52:52 -08006273#ifdef NL80211_SUPPORT
6274 val = get_param(cmd, "FrgmntSupport");
6275 if (val) {
6276 if (strcasecmp(val, "Enable") == 0) {
6277 if (sta_set_he_fragmentation(dut, intf,
6278 HE_FRAG_LEVEL1)) {
6279 send_resp(dut, conn, SIGMA_ERROR,
6280 "ErrorCode,Failed to enable HE Fragmentation");
6281 return 0;
6282 }
6283 } else if (strcasecmp(val, "Disable") == 0) {
6284 if (sta_set_he_fragmentation(dut, intf,
6285 HE_FRAG_DISABLE)) {
6286 send_resp(dut, conn, SIGMA_ERROR,
6287 "ErrorCode,Failed to disable HE Fragmentation");
6288 return 0;
6289 }
6290 }
6291 }
6292#endif /* NL80211_SUPPORT */
6293
Vinita S. Maloo8a4779c2020-06-22 19:32:37 +05306294 val = get_param(cmd, "IncludeMSCSDescriptor");
6295 if (val && strcasecmp(val, "1") == 0) {
6296 char buf[128];
6297 int len;
6298
6299 len = snprintf(buf, sizeof(buf),
Veerendranath Jakkam62cde372020-08-19 18:03:06 +05306300 "MSCS add up_bitmap=F0 up_limit=7 stream_timeout=60000 frame_classifier=045F%032x",
Vinita S. Maloo8a4779c2020-06-22 19:32:37 +05306301 0);
6302
6303 if (len < 0 || len >= sizeof(buf)) {
6304 sigma_dut_print(dut, DUT_MSG_ERROR,
6305 "Failed to build MSCS Descriptor IE");
6306 return ERROR_SEND_STATUS;
6307 }
6308
6309 if (wpa_command(intf, buf) != 0) {
6310 send_resp(dut, conn, SIGMA_ERROR,
6311 "ErrorCode,Failed to include MSCS descriptor");
6312 return STATUS_SENT_ERROR;
6313 }
6314 }
6315
Vinita S. Maloo2287f142021-02-01 16:17:09 +05306316 val = get_param(cmd, "SCSSupport");
6317 if (val) {
6318 char buf[30];
6319 int disable_scs, len;
6320
6321 if (strcasecmp(val, "Enable") == 0) {
6322 disable_scs = 0;
6323 } else if (strcasecmp(val, "Disable") == 0) {
6324 disable_scs = 1;
6325 } else {
6326 sigma_dut_print(dut, DUT_MSG_ERROR,
6327 "Invalid SCSsupport parameter");
6328 return INVALID_SEND_STATUS;
6329 }
6330
Shivani Baranwalebde8f62021-10-19 12:26:02 +05306331 if (disable_scs || dut->prev_disable_scs_support) {
6332 len = snprintf(buf, sizeof(buf),
6333 "SET disable_scs_support %d",
6334 disable_scs);
6335 if (len < 0 || len >= sizeof(buf) ||
6336 wpa_command(intf, buf) != 0) {
6337 send_resp(dut, conn, SIGMA_ERROR,
6338 "ErrorCode,Failed to update SCS support");
6339 return STATUS_SENT_ERROR;
6340 }
6341 dut->prev_disable_scs_support = disable_scs;
Vinita S. Maloo2287f142021-02-01 16:17:09 +05306342 }
6343 }
6344
Vinita S. Maloo83dee552021-04-12 16:47:47 +05306345 val = get_param(cmd, "MSCSSupport");
6346 if (val) {
6347 char buf[30];
6348 int disable_mscs, len;
6349
6350 if (strcasecmp(val, "Enable") == 0) {
6351 disable_mscs = 0;
6352 } else if (strcasecmp(val, "Disable") == 0) {
6353 disable_mscs = 1;
6354 } else {
6355 sigma_dut_print(dut, DUT_MSG_ERROR,
6356 "Invalid MSCSsupport parameter");
6357 return INVALID_SEND_STATUS;
6358 }
6359
Shivani Baranwalebde8f62021-10-19 12:26:02 +05306360 if (disable_mscs || dut->prev_disable_mscs_support) {
6361 len = snprintf(buf, sizeof(buf),
6362 "SET disable_mscs_support %d",
6363 disable_mscs);
6364 if (len < 0 || len >= sizeof(buf) ||
6365 wpa_command(intf, buf) != 0) {
6366 send_resp(dut, conn, SIGMA_ERROR,
6367 "ErrorCode,Failed to update MSCS support");
6368 return STATUS_SENT_ERROR;
6369 }
6370 dut->prev_disable_mscs_support = disable_mscs;
Vinita S. Maloo83dee552021-04-12 16:47:47 +05306371 }
6372 }
6373
Veerendranath Jakkama16cdc82021-09-12 16:44:22 +05306374 val = get_param(cmd, "DSCPPolicyCapability");
6375 if (val) {
6376 char buf[35];
6377 int len;
6378
6379 if (strcasecmp(val, "Enable") == 0) {
6380 len = snprintf(buf, sizeof(buf),
6381 "SET enable_dscp_policy_capa 1");
6382 } else if (strcasecmp(val, "Disable") == 0) {
6383 len = snprintf(buf, sizeof(buf),
6384 "SET enable_dscp_policy_capa 0");
6385 } else {
6386 sigma_dut_print(dut, DUT_MSG_ERROR,
6387 "Invalid DSCP policy parameter");
6388 return INVALID_SEND_STATUS;
6389 }
6390
6391 if (len < 0 || len >= sizeof(buf) ||
6392 wpa_command(intf, buf) != 0) {
6393 send_resp(dut, conn, SIGMA_ERROR,
6394 "ErrorCode,Failed to update DSCP policy capability");
6395 return STATUS_SENT_ERROR;
6396 }
6397 }
6398
6399 val = get_param(cmd, "DSCPPolicyRespParams");
6400 if (val) {
6401 if (strcasecmp(val, "RejectAll") == 0) {
6402 dut->reject_dscp_policies = 1;
6403 dut->dscp_reject_resp_code = DSCP_POLICY_REJECT;
6404 } else if (strcasecmp(val, "AcceptAll") == 0) {
6405 dut->reject_dscp_policies = 0;
6406 }
6407 }
6408
6409 val = get_param(cmd, "DSCPPolicyResp_StatusCode");
6410 if (val)
6411 dut->dscp_reject_resp_code = atoi(val);
6412
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006413 return 1;
6414}
6415
6416
6417static const char * ath_get_radio_name(const char *radio_name)
6418{
6419 if (radio_name == NULL)
6420 return "wifi0";
6421 if (strcmp(radio_name, "wifi1") == 0)
6422 return "wifi1";
6423 if (strcmp(radio_name, "wifi2") == 0)
6424 return "wifi2";
6425 return "wifi0";
6426}
6427
6428
6429static void ath_sta_set_txsp_stream(struct sigma_dut *dut, const char *intf,
6430 const char *val)
6431{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006432 unsigned int vht_mcsmap = 0;
6433 int txchainmask = 0;
6434 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
6435
6436 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
6437 if (dut->testbed_flag_txsp == 1) {
6438 vht_mcsmap = 0xfffc;
6439 dut->testbed_flag_txsp = 0;
6440 } else {
6441 vht_mcsmap = 0xfffe;
6442 }
6443 txchainmask = 1;
6444 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
6445 if (dut->testbed_flag_txsp == 1) {
6446 vht_mcsmap = 0xfff0;
6447 dut->testbed_flag_txsp = 0;
6448 } else {
6449 vht_mcsmap = 0xfffa;
6450 }
6451 txchainmask = 3;
6452 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
6453 if (dut->testbed_flag_txsp == 1) {
6454 vht_mcsmap = 0xffc0;
6455 dut->testbed_flag_txsp = 0;
6456 } else {
6457 vht_mcsmap = 0xffea;
6458 }
6459 txchainmask = 7;
6460 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
6461 if (dut->testbed_flag_txsp == 1) {
6462 vht_mcsmap = 0xff00;
6463 dut->testbed_flag_txsp = 0;
6464 } else {
6465 vht_mcsmap = 0xffaa;
6466 }
6467 txchainmask = 15;
6468 } else {
6469 if (dut->testbed_flag_txsp == 1) {
6470 vht_mcsmap = 0xffc0;
6471 dut->testbed_flag_txsp = 0;
6472 } else {
6473 vht_mcsmap = 0xffea;
6474 }
6475 }
6476
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006477 if (txchainmask)
6478 run_iwpriv(dut, basedev, "txchainmask %d", txchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006479
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006480 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006481}
6482
6483
6484static void ath_sta_set_rxsp_stream(struct sigma_dut *dut, const char *intf,
6485 const char *val)
6486{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006487 unsigned int vht_mcsmap = 0;
6488 int rxchainmask = 0;
6489 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
6490
6491 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
6492 if (dut->testbed_flag_rxsp == 1) {
6493 vht_mcsmap = 0xfffc;
6494 dut->testbed_flag_rxsp = 0;
6495 } else {
6496 vht_mcsmap = 0xfffe;
6497 }
6498 rxchainmask = 1;
6499 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
6500 if (dut->testbed_flag_rxsp == 1) {
6501 vht_mcsmap = 0xfff0;
6502 dut->testbed_flag_rxsp = 0;
6503 } else {
6504 vht_mcsmap = 0xfffa;
6505 }
6506 rxchainmask = 3;
6507 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
6508 if (dut->testbed_flag_rxsp == 1) {
6509 vht_mcsmap = 0xffc0;
6510 dut->testbed_flag_rxsp = 0;
6511 } else {
6512 vht_mcsmap = 0xffea;
6513 }
6514 rxchainmask = 7;
6515 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
6516 if (dut->testbed_flag_rxsp == 1) {
6517 vht_mcsmap = 0xff00;
6518 dut->testbed_flag_rxsp = 0;
6519 } else {
6520 vht_mcsmap = 0xffaa;
6521 }
6522 rxchainmask = 15;
6523 } else {
6524 if (dut->testbed_flag_rxsp == 1) {
6525 vht_mcsmap = 0xffc0;
6526 dut->testbed_flag_rxsp = 0;
6527 } else {
6528 vht_mcsmap = 0xffea;
6529 }
6530 }
6531
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006532 if (rxchainmask)
6533 run_iwpriv(dut, basedev, "rxchainmask %d", rxchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006534
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006535 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006536}
6537
6538
6539void ath_set_zero_crc(struct sigma_dut *dut, const char *val)
6540{
6541 if (strcasecmp(val, "enable") == 0) {
6542 if (system("athdiag --set --address=0x2a204 --and=0xbfffffff")
6543 != 0) {
6544 sigma_dut_print(dut, DUT_MSG_ERROR,
6545 "Disable BB_VHTSIGB_CRC_CALC failed");
6546 }
6547
6548 if (system("athdiag --set --address=0x2a204 --or=0x80000000")
6549 != 0) {
6550 sigma_dut_print(dut, DUT_MSG_ERROR,
6551 "Enable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
6552 }
6553 } else {
6554 if (system("athdiag --set --address=0x2a204 --and=0x7fffffff")
6555 != 0) {
6556 sigma_dut_print(dut, DUT_MSG_ERROR,
6557 "Disable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
6558 }
6559
6560 if (system("athdiag --set --address=0x2a204 --or=0x40000000")
6561 != 0) {
6562 sigma_dut_print(dut, DUT_MSG_ERROR,
6563 "Enable BB_VHTSIGB_CRC_CALC failed");
6564 }
6565 }
6566}
6567
6568
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08006569static int wcn_sta_set_width(struct sigma_dut *dut, const char *intf,
6570 const char *val)
6571{
6572 char buf[60];
6573
Shivani Baranwal2a572842021-09-16 12:27:15 +05306574#ifdef NL80211_SUPPORT
6575 enum nl80211_chan_width qca_channel_width;
6576
6577 if (strcmp(val, "20") == 0) {
6578 qca_channel_width = NL80211_CHAN_WIDTH_20;
6579 dut->chwidth = 0;
6580 } else if (strcmp(val, "40") == 0) {
6581 qca_channel_width = NL80211_CHAN_WIDTH_40;
6582 dut->chwidth = 1;
6583 } else if (strcmp(val, "80") == 0) {
6584 qca_channel_width = NL80211_CHAN_WIDTH_80;
6585 dut->chwidth = 2;
6586 } else if (strcmp(val, "160") == 0) {
6587 qca_channel_width = NL80211_CHAN_WIDTH_160;
6588 dut->chwidth = 3;
6589 } else if (strcasecmp(val, "Auto") == 0) {
6590 return 0;
6591 } else {
6592 sigma_dut_print(dut, DUT_MSG_ERROR, "WIDTH %s not supported",
6593 val);
6594 return -1;
6595 }
6596 if (sta_config_params(dut, intf, STA_SET_CHAN_WIDTH,
6597 qca_channel_width) == 0)
6598 return 0;
6599#endif /* NL80211_SUPPORT */
6600
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08006601 if (strcmp(val, "20") == 0) {
6602 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
6603 dut->chwidth = 0;
6604 } else if (strcmp(val, "40") == 0) {
6605 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 1", intf);
6606 dut->chwidth = 1;
6607 } else if (strcmp(val, "80") == 0) {
6608 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
6609 dut->chwidth = 2;
Sunil Duttb1cccac2018-05-22 21:03:12 +05306610 } else if (strcasecmp(val, "Auto") == 0) {
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08006611 buf[0] = '\0';
6612 } else {
6613 sigma_dut_print(dut, DUT_MSG_ERROR, "WIDTH %s not supported",
6614 val);
6615 return -1;
6616 }
6617
6618 if (buf[0] != '\0' && system(buf) != 0) {
6619 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv chwidth failed");
6620 return -1;
6621 }
6622
6623 return 0;
6624}
6625
6626
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08006627static int nlvendor_sta_set_addba_reject(struct sigma_dut *dut,
6628 const char *intf, int addbareject)
6629{
6630#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05306631 return wcn_wifi_test_config_set_u8(
6632 dut, intf,
6633 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ACCEPT_ADDBA_REQ,
6634 !addbareject);
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08006635#else /* NL80211_SUPPORT */
6636 sigma_dut_print(dut, DUT_MSG_ERROR,
6637 "ADDBA_REJECT cannot be set without NL80211_SUPPORT defined");
6638 return -1;
6639#endif /* NL80211_SUPPORT */
6640}
6641
6642
6643static int sta_set_addba_reject(struct sigma_dut *dut, const char *intf,
6644 int addbareject)
6645{
6646 int ret;
6647
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006648 switch (get_driver_type(dut)) {
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08006649 case DRIVER_WCN:
6650 ret = nlvendor_sta_set_addba_reject(dut, intf, addbareject);
6651 if (ret) {
6652 sigma_dut_print(dut, DUT_MSG_ERROR,
6653 "nlvendor_sta_set_addba_reject failed, ret:%d",
6654 ret);
6655 return ret;
6656 }
6657 break;
6658 default:
6659 sigma_dut_print(dut, DUT_MSG_ERROR,
6660 "errorCode,Unsupported ADDBA_REJECT with the current driver");
6661 ret = -1;
6662 break;
6663 }
6664
6665 return ret;
6666}
6667
6668
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08006669static int nlvendor_config_send_addba(struct sigma_dut *dut, const char *intf,
6670 int enable)
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08006671{
6672#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05306673 return wcn_wifi_test_config_set_u8(
6674 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SEND_ADDBA_REQ,
6675 enable);
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08006676#else /* NL80211_SUPPORT */
6677 sigma_dut_print(dut, DUT_MSG_ERROR,
6678 "Disable addba not possible without NL80211_SUPPORT defined");
6679 return -1;
6680#endif /* NL80211_SUPPORT */
6681}
6682
6683
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05306684#ifdef NL80211_SUPPORT
6685static int nl80211_sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
6686{
6687 struct nl_msg *msg;
6688 int ret = 0;
6689 int ifindex;
6690
6691 ifindex = if_nametoindex(intf);
6692 if (ifindex == 0) {
6693 sigma_dut_print(dut, DUT_MSG_ERROR,
6694 "%s: Index for interface %s failed",
6695 __func__, intf);
6696 return -1;
6697 }
6698
6699 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6700 NL80211_CMD_SET_WIPHY)) ||
6701 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) {
6702 sigma_dut_print(dut, DUT_MSG_ERROR,
6703 "%s: err in adding RTS threshold",
6704 __func__);
6705 nlmsg_free(msg);
6706 return -1;
6707 }
6708
6709 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6710 if (ret) {
6711 sigma_dut_print(dut, DUT_MSG_ERROR,
6712 "%s: err in send_and_recv_msgs, ret=%d",
6713 __func__, ret);
6714 }
6715 return ret;
6716}
6717#endif /* NL80211_SUPPORT */
6718
6719
6720static int sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
6721{
6722 char buf[100];
6723
6724#ifdef NL80211_SUPPORT
6725 if (nl80211_sta_set_rts(dut, intf, val) == 0)
6726 return 0;
6727 sigma_dut_print(dut, DUT_MSG_DEBUG,
6728 "Fall back to using iwconfig for setting RTS threshold");
6729#endif /* NL80211_SUPPORT */
6730
6731 snprintf(buf, sizeof(buf), "iwconfig %s rts %d", intf, val);
6732 if (system(buf) != 0) {
6733 sigma_dut_print(dut, DUT_MSG_ERROR,
6734 "Failed to set RTS threshold %d", val);
6735 return -1;
6736 }
6737 return 0;
6738}
6739
6740
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006741static enum sigma_cmd_result
6742cmd_sta_set_wireless_common(const char *intf, struct sigma_dut *dut,
6743 struct sigma_conn *conn, struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006744{
6745 const char *val;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08006746 int ampdu = -1, addbareject = -1;
Jouni Malinen3aa72862019-05-29 23:14:51 +03006747 char buf[128];
6748 int res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006749
6750 val = get_param(cmd, "40_INTOLERANT");
6751 if (val) {
6752 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
6753 /* TODO: iwpriv ht40intol through wpa_supplicant */
6754 send_resp(dut, conn, SIGMA_ERROR,
6755 "ErrorCode,40_INTOLERANT not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006756 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006757 }
6758 }
6759
6760 val = get_param(cmd, "ADDBA_REJECT");
6761 if (val) {
6762 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
6763 /* reject any ADDBA with status "decline" */
6764 ampdu = 0;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08006765 addbareject = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006766 } else {
6767 /* accept ADDBA */
6768 ampdu = 1;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08006769 addbareject = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006770 }
6771 }
6772
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08006773 if (addbareject >= 0 &&
6774 sta_set_addba_reject(dut, intf, addbareject) < 0) {
6775 send_resp(dut, conn, SIGMA_ERROR,
6776 "ErrorCode,set addba_reject failed");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006777 return STATUS_SENT_ERROR;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08006778 }
6779
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006780 val = get_param(cmd, "AMPDU");
6781 if (val) {
6782 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
6783 /* enable AMPDU Aggregation */
6784 if (ampdu == 0) {
6785 send_resp(dut, conn, SIGMA_ERROR,
6786 "ErrorCode,Mismatch in "
6787 "addba_reject/ampdu - "
6788 "not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006789 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006790 }
6791 ampdu = 1;
6792 } else {
6793 /* disable AMPDU Aggregation */
6794 if (ampdu == 1) {
6795 send_resp(dut, conn, SIGMA_ERROR,
6796 "ErrorCode,Mismatch in "
6797 "addba_reject/ampdu - "
6798 "not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006799 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006800 }
6801 ampdu = 0;
6802 }
6803 }
6804
6805 if (ampdu >= 0) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08006806 int ret;
6807
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006808 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s A-MPDU aggregation",
6809 ampdu ? "Enabling" : "Disabling");
6810 snprintf(buf, sizeof(buf), "SET ampdu %d", ampdu);
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07006811 if (wpa_command(intf, buf) < 0 &&
6812 iwpriv_sta_set_ampdu(dut, intf, ampdu) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006813 send_resp(dut, conn, SIGMA_ERROR,
6814 "ErrorCode,set aggr failed");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006815 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006816 }
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08006817
6818 if (ampdu == 0) {
6819 /* Disable sending of addba using nl vendor command */
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08006820 ret = nlvendor_config_send_addba(dut, intf, 0);
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08006821 if (ret) {
6822 sigma_dut_print(dut, DUT_MSG_ERROR,
6823 "Failed to disable addba, ret:%d",
6824 ret);
6825 }
6826 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006827 }
6828
6829 val = get_param(cmd, "AMSDU");
6830 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006831 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006832 case DRIVER_ATHEROS:
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08006833 case DRIVER_WCN:
6834 iwpriv_sta_set_amsdu(dut, intf, val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006835 break;
6836 default:
6837 if (strcmp(val, "1") == 0 ||
6838 strcasecmp(val, "Enable") == 0) {
6839 /* Enable AMSDU Aggregation */
6840 send_resp(dut, conn, SIGMA_ERROR,
6841 "ErrorCode,AMSDU aggregation not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006842 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006843 }
6844 break;
6845 }
6846 }
6847
6848 val = get_param(cmd, "STBC_RX");
6849 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006850 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006851 case DRIVER_ATHEROS:
6852 ath_sta_set_stbc(dut, intf, val);
6853 break;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05306854 case DRIVER_WCN:
6855 wcn_sta_set_stbc(dut, intf, val);
6856 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006857 default:
6858 send_resp(dut, conn, SIGMA_ERROR,
6859 "ErrorCode,STBC_RX not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006860 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006861 }
6862 }
6863
6864 val = get_param(cmd, "WIDTH");
6865 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006866 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006867 case DRIVER_WCN:
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08006868 if (wcn_sta_set_width(dut, intf, val) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006869 send_resp(dut, conn, SIGMA_ERROR,
6870 "ErrorCode,Failed to set WIDTH");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006871 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006872 }
6873 break;
6874 case DRIVER_ATHEROS:
6875 if (ath_set_width(dut, conn, intf, val) < 0)
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006876 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006877 break;
6878 default:
6879 sigma_dut_print(dut, DUT_MSG_ERROR,
6880 "Setting WIDTH not supported");
6881 break;
6882 }
6883 }
6884
6885 val = get_param(cmd, "SMPS");
6886 if (val) {
6887 /* TODO: Dynamic/0, Static/1, No Limit/2 */
6888 send_resp(dut, conn, SIGMA_ERROR,
6889 "ErrorCode,SMPS not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006890 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006891 }
6892
6893 val = get_param(cmd, "TXSP_STREAM");
6894 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006895 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006896 case DRIVER_WCN:
6897 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
6898 send_resp(dut, conn, SIGMA_ERROR,
6899 "ErrorCode,Failed to set TXSP_STREAM");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006900 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006901 }
6902 break;
6903 case DRIVER_ATHEROS:
6904 ath_sta_set_txsp_stream(dut, intf, val);
6905 break;
6906 default:
6907 sigma_dut_print(dut, DUT_MSG_ERROR,
6908 "Setting TXSP_STREAM not supported");
6909 break;
6910 }
6911 }
6912
6913 val = get_param(cmd, "RXSP_STREAM");
6914 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006915 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006916 case DRIVER_WCN:
6917 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
6918 send_resp(dut, conn, SIGMA_ERROR,
6919 "ErrorCode,Failed to set RXSP_STREAM");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006920 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006921 }
6922 break;
6923 case DRIVER_ATHEROS:
6924 ath_sta_set_rxsp_stream(dut, intf, val);
6925 break;
6926 default:
6927 sigma_dut_print(dut, DUT_MSG_ERROR,
6928 "Setting RXSP_STREAM not supported");
6929 break;
6930 }
6931 }
6932
6933 val = get_param(cmd, "DYN_BW_SGNL");
6934 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006935 switch (get_driver_type(dut)) {
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08006936 case DRIVER_WCN:
Peng Xuc59afd32016-11-21 15:01:11 -08006937 if (strcasecmp(val, "enable") == 0) {
6938 snprintf(buf, sizeof(buf),
6939 "iwpriv %s cwmenable 1", intf);
6940 if (system(buf) != 0) {
6941 sigma_dut_print(dut, DUT_MSG_ERROR,
6942 "iwpriv cwmenable 1 failed");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006943 return ERROR_SEND_STATUS;
Peng Xuc59afd32016-11-21 15:01:11 -08006944 }
6945 } else if (strcasecmp(val, "disable") == 0) {
6946 snprintf(buf, sizeof(buf),
6947 "iwpriv %s cwmenable 0", intf);
6948 if (system(buf) != 0) {
6949 sigma_dut_print(dut, DUT_MSG_ERROR,
6950 "iwpriv cwmenable 0 failed");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006951 return ERROR_SEND_STATUS;
Peng Xuc59afd32016-11-21 15:01:11 -08006952 }
6953 } else {
6954 sigma_dut_print(dut, DUT_MSG_ERROR,
6955 "Unsupported DYN_BW_SGL");
6956 }
6957
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006958 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
6959 if (system(buf) != 0) {
6960 sigma_dut_print(dut, DUT_MSG_ERROR,
6961 "Failed to set cts_cbw in DYN_BW_SGNL");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006962 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006963 }
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08006964 break;
6965 case DRIVER_ATHEROS:
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07006966 novap_reset(dut, intf, 1);
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08006967 ath_config_dyn_bw_sig(dut, intf, val);
6968 break;
6969 default:
6970 sigma_dut_print(dut, DUT_MSG_ERROR,
6971 "Failed to set DYN_BW_SGNL");
6972 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006973 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006974 }
6975
6976 val = get_param(cmd, "RTS_FORCE");
6977 if (val) {
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07006978 novap_reset(dut, intf, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006979 if (strcasecmp(val, "Enable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05306980 if (sta_set_rts(dut, intf, 64) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02006981 sigma_dut_print(dut, DUT_MSG_ERROR,
6982 "Failed to set RTS_FORCE 64");
6983 }
Jouni Malinen3aa72862019-05-29 23:14:51 +03006984 res = snprintf(buf, sizeof(buf),
6985 "wifitool %s beeliner_fw_test 100 1",
6986 intf);
6987 if (res < 0 || res >= sizeof(buf) || system(buf) != 0) {
priyadharshini gowthaman270870e2015-12-09 10:10:23 -08006988 sigma_dut_print(dut, DUT_MSG_ERROR,
6989 "wifitool beeliner_fw_test 100 1 failed");
6990 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006991 } else if (strcasecmp(val, "Disable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05306992 if (sta_set_rts(dut, intf, 2347) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02006993 sigma_dut_print(dut, DUT_MSG_ERROR,
6994 "Failed to set RTS_FORCE 2347");
6995 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006996 } else {
6997 send_resp(dut, conn, SIGMA_ERROR,
6998 "ErrorCode,RTS_FORCE value not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006999 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007000 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007001 }
7002
7003 val = get_param(cmd, "CTS_WIDTH");
7004 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007005 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007006 case DRIVER_WCN:
7007 if (wcn_sta_set_cts_width(dut, intf, val) < 0) {
7008 send_resp(dut, conn, SIGMA_ERROR,
7009 "ErrorCode,Failed to set CTS_WIDTH");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03007010 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007011 }
7012 break;
7013 case DRIVER_ATHEROS:
7014 ath_set_cts_width(dut, intf, val);
7015 break;
7016 default:
7017 sigma_dut_print(dut, DUT_MSG_ERROR,
7018 "Setting CTS_WIDTH not supported");
7019 break;
7020 }
7021 }
7022
7023 val = get_param(cmd, "BW_SGNL");
7024 if (val) {
7025 if (strcasecmp(val, "Enable") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007026 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007027 } else if (strcasecmp(val, "Disable") == 0) {
7028 /* TODO: Disable */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007029 } else {
7030 send_resp(dut, conn, SIGMA_ERROR,
7031 "ErrorCode,BW_SGNL value not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03007032 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007033 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007034 }
7035
7036 val = get_param(cmd, "Band");
7037 if (val) {
7038 if (strcmp(val, "2.4") == 0 || strcmp(val, "5") == 0) {
7039 /* STA supports all bands by default */
7040 } else {
7041 send_resp(dut, conn, SIGMA_ERROR,
7042 "ErrorCode,Unsupported Band");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03007043 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007044 }
7045 }
7046
7047 val = get_param(cmd, "zero_crc");
7048 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007049 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007050 case DRIVER_ATHEROS:
7051 ath_set_zero_crc(dut, val);
7052 break;
7053 default:
7054 break;
7055 }
7056 }
7057
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03007058 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007059}
7060
7061
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02007062static int sta_set_force_mcs(struct sigma_dut *dut, int force, int mcs)
7063{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007064 switch (get_driver_type(dut)) {
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02007065#ifdef __linux__
7066 case DRIVER_WIL6210:
7067 return wil6210_set_force_mcs(dut, force, mcs);
7068#endif /* __linux__ */
7069 default:
7070 sigma_dut_print(dut, DUT_MSG_ERROR,
7071 "Unsupported sta_set_force_mcs with the current driver");
7072 return -1;
7073 }
7074}
7075
7076
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02007077static int sta_60g_force_rsn_ie(struct sigma_dut *dut, int state)
7078{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007079 switch (get_driver_type(dut)) {
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02007080#ifdef __linux__
7081 case DRIVER_WIL6210:
7082 return wil6210_force_rsn_ie(dut, state);
7083#endif /* __linux__ */
7084 default:
7085 sigma_dut_print(dut, DUT_MSG_ERROR,
7086 "Unsupported sta_60g_force_rsn_ie with the current driver");
7087 return -1;
7088 }
7089}
7090
7091
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007092static int sta_set_60g_common(struct sigma_dut *dut, struct sigma_conn *conn,
7093 struct sigma_cmd *cmd)
7094{
7095 const char *val;
7096 char buf[100];
7097
7098 val = get_param(cmd, "MSDUSize");
7099 if (val) {
7100 int mtu;
7101
7102 dut->amsdu_size = atoi(val);
7103 if (dut->amsdu_size > IEEE80211_MAX_DATA_LEN_DMG ||
7104 dut->amsdu_size < IEEE80211_SNAP_LEN_DMG) {
7105 sigma_dut_print(dut, DUT_MSG_ERROR,
7106 "MSDUSize %d is above max %d or below min %d",
7107 dut->amsdu_size,
7108 IEEE80211_MAX_DATA_LEN_DMG,
7109 IEEE80211_SNAP_LEN_DMG);
7110 dut->amsdu_size = 0;
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007111 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007112 }
7113
7114 mtu = dut->amsdu_size - IEEE80211_SNAP_LEN_DMG;
7115 sigma_dut_print(dut, DUT_MSG_DEBUG,
7116 "Setting amsdu_size to %d", mtu);
7117 snprintf(buf, sizeof(buf), "ifconfig %s mtu %d",
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007118 get_station_ifname(dut), mtu);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007119
7120 if (system(buf) != 0) {
7121 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
7122 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007123 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007124 }
7125 }
7126
7127 val = get_param(cmd, "BAckRcvBuf");
7128 if (val) {
7129 dut->back_rcv_buf = atoi(val);
7130 if (dut->back_rcv_buf == 0) {
7131 sigma_dut_print(dut, DUT_MSG_ERROR,
7132 "Failed to convert %s or value is 0",
7133 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007134 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007135 }
7136
7137 sigma_dut_print(dut, DUT_MSG_DEBUG,
7138 "Setting BAckRcvBuf to %s", val);
7139 }
7140
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02007141 val = get_param(cmd, "MCS_FixedRate");
7142 if (val) {
7143 if (sta_set_force_mcs(dut, 1, atoi(val))) {
7144 sigma_dut_print(dut, DUT_MSG_ERROR,
7145 "Failed to force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007146 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02007147 }
7148 }
7149
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007150 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007151}
7152
7153
7154static int sta_pcp_start(struct sigma_dut *dut, struct sigma_conn *conn,
7155 struct sigma_cmd *cmd)
7156{
7157 int net_id;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007158 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007159 const char *val;
7160 char buf[100];
7161
7162 dut->mode = SIGMA_MODE_STATION;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007163 ifname = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007164 if (wpa_command(ifname, "PING") != 0) {
7165 sigma_dut_print(dut, DUT_MSG_ERROR, "Supplicant not running");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007166 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007167 }
7168
7169 wpa_command(ifname, "FLUSH");
7170 net_id = add_network_common(dut, conn, ifname, cmd);
7171 if (net_id < 0) {
7172 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add network");
7173 return net_id;
7174 }
7175
7176 /* TODO: mode=2 for the AP; in the future, replace for mode PCP */
7177 if (set_network(ifname, net_id, "mode", "2") < 0) {
7178 sigma_dut_print(dut, DUT_MSG_ERROR,
7179 "Failed to set supplicant network mode");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007180 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007181 }
7182
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02007183 if (set_network(ifname, net_id, "pbss", "1") < 0)
7184 return -2;
7185
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007186 sigma_dut_print(dut, DUT_MSG_DEBUG,
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02007187 "Supplicant set network with mode 2. network_id %d",
7188 net_id);
7189
7190 if (set_network(ifname, net_id, "wps_disabled", "0") < 0) {
7191 sigma_dut_print(dut, DUT_MSG_INFO,
7192 "Failed to set supplicant to WPS ENABLE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007193 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02007194 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007195
7196 val = get_param(cmd, "Security");
7197 if (val && strcasecmp(val, "OPEN") == 0) {
7198 dut->ap_key_mgmt = AP_OPEN;
7199 if (set_network(ifname, net_id, "key_mgmt", "NONE") < 0) {
7200 sigma_dut_print(dut, DUT_MSG_ERROR,
7201 "Failed to set supplicant to %s security",
7202 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007203 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007204 }
7205 } else if (val && strcasecmp(val, "WPA2-PSK") == 0) {
7206 dut->ap_key_mgmt = AP_WPA2_PSK;
7207 if (set_network(ifname, net_id, "key_mgmt", "WPA-PSK") < 0) {
7208 sigma_dut_print(dut, DUT_MSG_ERROR,
7209 "Failed to set supplicant to %s security",
7210 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007211 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007212 }
7213
7214 if (set_network(ifname, net_id, "proto", "RSN") < 0) {
7215 sigma_dut_print(dut, DUT_MSG_ERROR,
7216 "Failed to set supplicant to proto RSN");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007217 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007218 }
7219 } else if (val) {
7220 sigma_dut_print(dut, DUT_MSG_ERROR,
7221 "Requested Security %s is not supported on 60GHz",
7222 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007223 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007224 }
7225
7226 val = get_param(cmd, "Encrypt");
7227 if (val && strcasecmp(val, "AES-GCMP") == 0) {
7228 if (set_network(ifname, net_id, "pairwise", "GCMP") < 0) {
7229 sigma_dut_print(dut, DUT_MSG_ERROR,
7230 "Failed to set supplicant to pairwise GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007231 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007232 }
7233 if (set_network(ifname, net_id, "group", "GCMP") < 0) {
7234 sigma_dut_print(dut, DUT_MSG_ERROR,
7235 "Failed to set supplicant to group GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007236 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007237 }
7238 } else if (val) {
7239 sigma_dut_print(dut, DUT_MSG_ERROR,
7240 "Requested Encrypt %s is not supported on 60 GHz",
7241 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007242 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007243 }
7244
7245 val = get_param(cmd, "PSK");
7246 if (val && set_network_quoted(ifname, net_id, "psk", val) < 0) {
7247 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set psk %s",
7248 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007249 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007250 }
7251
7252 /* Convert 60G channel to freq */
7253 switch (dut->ap_channel) {
7254 case 1:
7255 val = "58320";
7256 break;
7257 case 2:
7258 val = "60480";
7259 break;
7260 case 3:
7261 val = "62640";
7262 break;
7263 default:
7264 sigma_dut_print(dut, DUT_MSG_ERROR,
7265 "Failed to configure channel %d. Not supported",
7266 dut->ap_channel);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007267 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007268 }
7269
7270 if (set_network(ifname, net_id, "frequency", val) < 0) {
7271 sigma_dut_print(dut, DUT_MSG_ERROR,
7272 "Failed to set supplicant network frequency");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007273 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007274 }
7275
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02007276 if (dut->eap_fragment) {
7277 sigma_dut_print(dut, DUT_MSG_DEBUG,
7278 "Set EAP fragment size to 128 bytes.");
7279 if (set_network(ifname, net_id, "fragment_size", "128") < 0)
7280 return ERROR_SEND_STATUS;
7281 }
7282
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007283 sigma_dut_print(dut, DUT_MSG_DEBUG,
7284 "Supplicant set network with frequency");
7285
7286 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d", net_id);
7287 if (wpa_command(ifname, buf) < 0) {
7288 sigma_dut_print(dut, DUT_MSG_INFO,
7289 "Failed to select network id %d on %s",
7290 net_id, ifname);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007291 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007292 }
7293
7294 sigma_dut_print(dut, DUT_MSG_DEBUG, "Selected network");
7295
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007296 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007297}
7298
7299
Lior David67543f52017-01-03 19:04:22 +02007300static int wil6210_set_abft_len(struct sigma_dut *dut, int abft_len)
7301{
7302 char buf[128], fname[128];
7303 FILE *f;
Jouni Malinen3aa72862019-05-29 23:14:51 +03007304 int res;
Lior David67543f52017-01-03 19:04:22 +02007305
7306 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
7307 sigma_dut_print(dut, DUT_MSG_ERROR,
7308 "failed to get wil6210 debugfs dir");
7309 return -1;
7310 }
7311
Jouni Malinen3aa72862019-05-29 23:14:51 +03007312 res = snprintf(fname, sizeof(fname), "%s/abft_len", buf);
7313 if (res < 0 || res >= sizeof(fname))
7314 return -1;
Lior David67543f52017-01-03 19:04:22 +02007315 f = fopen(fname, "w");
7316 if (!f) {
7317 sigma_dut_print(dut, DUT_MSG_ERROR,
7318 "failed to open: %s", fname);
7319 return -1;
7320 }
7321
7322 fprintf(f, "%d\n", abft_len);
7323 fclose(f);
7324
7325 return 0;
7326}
7327
7328
Alexei Avshalom Lazar49498b82019-01-31 15:16:32 +02007329int sta_set_60g_abft_len(struct sigma_dut *dut, struct sigma_conn *conn,
7330 int abft_len)
Lior David67543f52017-01-03 19:04:22 +02007331{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007332 switch (get_driver_type(dut)) {
Lior David67543f52017-01-03 19:04:22 +02007333 case DRIVER_WIL6210:
7334 return wil6210_set_abft_len(dut, abft_len);
7335 default:
7336 sigma_dut_print(dut, DUT_MSG_ERROR,
7337 "set abft_len not supported");
7338 return -1;
7339 }
7340}
7341
7342
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007343static int sta_set_60g_pcp(struct sigma_dut *dut, struct sigma_conn *conn,
7344 struct sigma_cmd *cmd)
7345{
7346 const char *val;
Lior David67543f52017-01-03 19:04:22 +02007347 unsigned int abft_len = 1; /* default is one slot */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007348
7349 if (dut->dev_role != DEVROLE_PCP) {
7350 send_resp(dut, conn, SIGMA_INVALID,
7351 "ErrorCode,Invalid DevRole");
7352 return 0;
7353 }
7354
7355 val = get_param(cmd, "SSID");
7356 if (val) {
7357 if (strlen(val) > sizeof(dut->ap_ssid) - 1) {
7358 send_resp(dut, conn, SIGMA_INVALID,
7359 "ErrorCode,Invalid SSID");
7360 return -1;
7361 }
7362
Peng Xub8fc5cc2017-05-10 17:27:28 -07007363 strlcpy(dut->ap_ssid, val, sizeof(dut->ap_ssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007364 }
7365
7366 val = get_param(cmd, "CHANNEL");
7367 if (val) {
7368 const char *pos;
7369
7370 dut->ap_channel = atoi(val);
7371 pos = strchr(val, ';');
7372 if (pos) {
7373 pos++;
7374 dut->ap_channel_1 = atoi(pos);
7375 }
7376 }
7377
7378 switch (dut->ap_channel) {
7379 case 1:
7380 case 2:
7381 case 3:
7382 break;
7383 default:
7384 sigma_dut_print(dut, DUT_MSG_ERROR,
7385 "Channel %d is not supported", dut->ap_channel);
7386 send_resp(dut, conn, SIGMA_ERROR,
7387 "Requested channel is not supported");
7388 return -1;
7389 }
7390
7391 val = get_param(cmd, "BCNINT");
7392 if (val)
7393 dut->ap_bcnint = atoi(val);
7394
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007395 val = get_param(cmd, "AllocType");
7396 if (val) {
7397 send_resp(dut, conn, SIGMA_ERROR,
7398 "ErrorCode,AllocType is not supported yet");
7399 return -1;
7400 }
7401
7402 val = get_param(cmd, "PercentBI");
7403 if (val) {
7404 send_resp(dut, conn, SIGMA_ERROR,
7405 "ErrorCode,PercentBI is not supported yet");
7406 return -1;
7407 }
7408
7409 val = get_param(cmd, "CBAPOnly");
7410 if (val) {
7411 send_resp(dut, conn, SIGMA_ERROR,
7412 "ErrorCode,CBAPOnly is not supported yet");
7413 return -1;
7414 }
7415
7416 val = get_param(cmd, "AMPDU");
7417 if (val) {
7418 if (strcasecmp(val, "Enable") == 0)
7419 dut->ap_ampdu = 1;
7420 else if (strcasecmp(val, "Disable") == 0)
7421 dut->ap_ampdu = 2;
7422 else {
7423 send_resp(dut, conn, SIGMA_ERROR,
7424 "ErrorCode,AMPDU value is not Enable nor Disabled");
7425 return -1;
7426 }
7427 }
7428
7429 val = get_param(cmd, "AMSDU");
7430 if (val) {
7431 if (strcasecmp(val, "Enable") == 0)
7432 dut->ap_amsdu = 1;
7433 else if (strcasecmp(val, "Disable") == 0)
7434 dut->ap_amsdu = 2;
7435 }
7436
7437 val = get_param(cmd, "NumMSDU");
7438 if (val) {
7439 send_resp(dut, conn, SIGMA_ERROR,
7440 "ErrorCode, NumMSDU is not supported yet");
7441 return -1;
7442 }
7443
7444 val = get_param(cmd, "ABFTLRang");
7445 if (val) {
7446 sigma_dut_print(dut, DUT_MSG_DEBUG,
Lior David67543f52017-01-03 19:04:22 +02007447 "ABFTLRang parameter %s", val);
7448 if (strcmp(val, "Gt1") == 0)
7449 abft_len = 2; /* 2 slots in this case */
7450 }
7451
7452 if (sta_set_60g_abft_len(dut, conn, abft_len)) {
7453 send_resp(dut, conn, SIGMA_ERROR,
7454 "ErrorCode, Can't set ABFT length");
7455 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007456 }
7457
7458 if (sta_pcp_start(dut, conn, cmd) < 0) {
7459 send_resp(dut, conn, SIGMA_ERROR,
7460 "ErrorCode, Can't start PCP role");
7461 return -1;
7462 }
7463
7464 return sta_set_60g_common(dut, conn, cmd);
7465}
7466
7467
7468static int sta_set_60g_sta(struct sigma_dut *dut, struct sigma_conn *conn,
7469 struct sigma_cmd *cmd)
7470{
7471 const char *val = get_param(cmd, "DiscoveryMode");
7472
7473 if (dut->dev_role != DEVROLE_STA) {
7474 send_resp(dut, conn, SIGMA_INVALID,
7475 "ErrorCode,Invalid DevRole");
7476 return 0;
7477 }
7478
7479 if (val) {
7480 sigma_dut_print(dut, DUT_MSG_DEBUG, "Discovery: %s", val);
7481 /* Ignore Discovery mode till Driver expose API. */
7482#if 0
7483 if (strcasecmp(val, "1") == 0) {
7484 send_resp(dut, conn, SIGMA_INVALID,
7485 "ErrorCode,DiscoveryMode 1 not supported");
7486 return 0;
7487 }
7488
7489 if (strcasecmp(val, "0") == 0) {
7490 /* OK */
7491 } else {
7492 send_resp(dut, conn, SIGMA_INVALID,
7493 "ErrorCode,DiscoveryMode not supported");
7494 return 0;
7495 }
7496#endif
7497 }
7498
7499 if (start_sta_mode(dut) != 0)
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007500 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007501 return sta_set_60g_common(dut, conn, cmd);
7502}
7503
7504
Jouni Malinenf7222712019-06-13 01:50:21 +03007505static enum sigma_cmd_result cmd_sta_disconnect(struct sigma_dut *dut,
7506 struct sigma_conn *conn,
7507 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007508{
7509 const char *intf = get_param(cmd, "Interface");
Jouni Malinened77e672018-01-10 16:45:13 +02007510 const char *val = get_param(cmd, "maintain_profile");
vamsi krishnad605c422017-09-20 14:56:31 +05307511
Jouni Malinened77e672018-01-10 16:45:13 +02007512 if (dut->program == PROGRAM_OCE ||
Amarnath Hullur Subramanyamebeda9e2018-01-31 03:21:48 -08007513 dut->program == PROGRAM_HE ||
Jouni Malinened77e672018-01-10 16:45:13 +02007514 (val && atoi(val) == 1)) {
vamsi krishnad605c422017-09-20 14:56:31 +05307515 wpa_command(intf, "DISCONNECT");
7516 return 1;
7517 }
7518
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007519 disconnect_station(dut);
7520 /* Try to ignore old scan results to avoid HS 2.0R2 test case failures
7521 * due to cached results. */
7522 wpa_command(intf, "SET ignore_old_scan_res 1");
7523 wpa_command(intf, "BSS_FLUSH");
7524 return 1;
7525}
7526
7527
Jouni Malinenf7222712019-06-13 01:50:21 +03007528static enum sigma_cmd_result cmd_sta_reassoc(struct sigma_dut *dut,
7529 struct sigma_conn *conn,
7530 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007531{
7532 const char *intf = get_param(cmd, "Interface");
7533 const char *bssid = get_param(cmd, "bssid");
7534 const char *val = get_param(cmd, "CHANNEL");
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07007535 const char *freq_val = get_param(cmd, "ChnlFreq");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007536 struct wpa_ctrl *ctrl;
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05307537 char buf[1000];
Sunil Duttd30ce092018-01-11 23:56:29 +05307538 char result[32];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007539 int res;
7540 int chan = 0;
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07007541 int freq = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007542 enum sigma_cmd_result status = STATUS_SENT;
Sunil Duttd30ce092018-01-11 23:56:29 +05307543 int fastreassoc = 1;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007544 int ft_ds = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007545
7546 if (bssid == NULL) {
7547 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing bssid "
7548 "argument");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007549 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007550 }
7551
7552 if (val)
7553 chan = atoi(val);
7554
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07007555 if (freq_val)
7556 freq = atoi(freq_val);
7557
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007558 if (wifi_chip_type != DRIVER_WCN && wifi_chip_type != DRIVER_AR6003) {
7559 /* The current network may be from sta_associate or
7560 * sta_hs2_associate
7561 */
7562 if (set_network(intf, dut->infra_network_id, "bssid", bssid) <
7563 0 ||
7564 set_network(intf, 0, "bssid", bssid) < 0)
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007565 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007566 }
7567
7568 ctrl = open_wpa_mon(intf);
7569 if (ctrl == NULL) {
7570 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
7571 "wpa_supplicant monitor connection");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007572 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007573 }
7574
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007575 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Sunil Duttd30ce092018-01-11 23:56:29 +05307576 sizeof(result)) < 0 ||
7577 strncmp(result, "COMPLETED", 9) != 0) {
7578 sigma_dut_print(dut, DUT_MSG_DEBUG,
7579 "sta_reassoc: Not connected");
7580 fastreassoc = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007581 } else if (dut->sta_ft_ds) {
7582 sigma_dut_print(dut, DUT_MSG_DEBUG,
7583 "sta_reassoc: Use FT-over-DS");
7584 ft_ds = 1;
Sunil Duttd30ce092018-01-11 23:56:29 +05307585 }
7586
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05307587 if (dut->rsne_override) {
7588#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007589 if (get_driver_type(dut) == DRIVER_WCN &&
7590 dut->config_rsnie == 0) {
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05307591 sta_config_params(dut, intf, STA_SET_RSNIE, 1);
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05307592 dut->config_rsnie = 1;
7593 }
7594#endif /* NL80211_SUPPORT */
7595 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
7596 dut->rsne_override);
7597 if (wpa_command(intf, buf) < 0) {
7598 send_resp(dut, conn, SIGMA_ERROR,
7599 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
7600 return 0;
7601 }
7602 }
7603
Shivani Baranwal7aa48602021-09-29 10:53:38 +05307604 if (ft_ds && get_driver_type(dut) != DRIVER_WCN) {
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07007605 if (chan || freq) {
7606 if (!freq)
7607 freq = channel_to_freq(dut, chan);
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007608 if (!freq) {
7609 sigma_dut_print(dut, DUT_MSG_ERROR,
7610 "Invalid channel number provided: %d",
7611 chan);
7612 send_resp(dut, conn, SIGMA_INVALID,
7613 "ErrorCode,Invalid channel number");
7614 goto close_mon_conn;
7615 }
7616 res = snprintf(buf, sizeof(buf),
7617 "SCAN TYPE=ONLY freq=%d", freq);
7618 } else {
7619 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
7620 }
7621 if (res < 0 || res >= (int) sizeof(buf)) {
7622 send_resp(dut, conn, SIGMA_ERROR,
7623 "ErrorCode,snprintf failed");
7624 goto close_mon_conn;
7625 }
7626 if (wpa_command(intf, buf) < 0) {
7627 sigma_dut_print(dut, DUT_MSG_INFO,
7628 "Failed to start scan");
7629 send_resp(dut, conn, SIGMA_ERROR,
7630 "ErrorCode,scan failed");
7631 goto close_mon_conn;
7632 }
7633
7634 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
7635 buf, sizeof(buf));
7636 if (res < 0) {
7637 sigma_dut_print(dut, DUT_MSG_INFO,
7638 "Scan did not complete");
7639 send_resp(dut, conn, SIGMA_ERROR,
7640 "ErrorCode,scan did not complete");
7641 goto close_mon_conn;
7642 }
7643
7644 res = snprintf(buf, sizeof(buf), "FT_DS %s", bssid);
7645 if (res > 0 && res < (int) sizeof(buf))
7646 res = wpa_command(intf, buf);
7647
7648 if (res < 0 || res >= (int) sizeof(buf)) {
7649 send_resp(dut, conn, SIGMA_ERROR,
7650 "errorCode,FT_DS command failed");
7651 status = STATUS_SENT_ERROR;
7652 goto close_mon_conn;
7653 }
7654 } else if (wifi_chip_type == DRIVER_WCN && fastreassoc) {
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07007655 if (chan || freq) {
7656 if (!freq)
7657 freq = channel_to_freq(dut, chan);
Ashwini Patil4c8158f2017-05-25 12:49:21 +05307658 if (!freq) {
7659 sigma_dut_print(dut, DUT_MSG_ERROR,
7660 "Invalid channel number provided: %d",
7661 chan);
7662 send_resp(dut, conn, SIGMA_INVALID,
7663 "ErrorCode,Invalid channel number");
7664 goto close_mon_conn;
7665 }
7666 res = snprintf(buf, sizeof(buf),
7667 "SCAN TYPE=ONLY freq=%d", freq);
7668 } else {
7669 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
7670 }
7671 if (res < 0 || res >= (int) sizeof(buf)) {
7672 send_resp(dut, conn, SIGMA_ERROR,
7673 "ErrorCode,snprintf failed");
7674 goto close_mon_conn;
7675 }
7676 if (wpa_command(intf, buf) < 0) {
7677 sigma_dut_print(dut, DUT_MSG_INFO,
7678 "Failed to start scan");
7679 send_resp(dut, conn, SIGMA_ERROR,
7680 "ErrorCode,scan failed");
7681 goto close_mon_conn;
7682 }
7683
7684 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
7685 buf, sizeof(buf));
7686 if (res < 0) {
7687 sigma_dut_print(dut, DUT_MSG_INFO,
7688 "Scan did not complete");
7689 send_resp(dut, conn, SIGMA_ERROR,
7690 "ErrorCode,scan did not complete");
7691 goto close_mon_conn;
7692 }
7693
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007694 if (set_network(intf, dut->infra_network_id, "bssid", "any")
7695 < 0) {
7696 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
7697 "bssid to any during FASTREASSOC");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007698 status = ERROR_SEND_STATUS;
Ashwini Patil467efef2017-05-25 12:18:27 +05307699 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007700 }
Vinita Maloo54b78cf2020-03-30 12:18:19 +05307701 res = snprintf(buf, sizeof(buf), "FASTREASSOC %s %d",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007702 bssid, chan);
Vinita Maloo54b78cf2020-03-30 12:18:19 +05307703 if (res < 0 || res >= (int) sizeof(buf) ||
7704 wcn_driver_cmd(intf, buf) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007705 send_resp(dut, conn, SIGMA_ERROR,
Vinita Maloo54b78cf2020-03-30 12:18:19 +05307706 "errorCode,Failed to run FASTREASSOC");
Ashwini Patil467efef2017-05-25 12:18:27 +05307707 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007708 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007709 sigma_dut_print(dut, DUT_MSG_INFO,
7710 "sta_reassoc: Run %s successful", buf);
7711 } else if (wpa_command(intf, "REASSOCIATE")) {
7712 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
7713 "request reassociation");
Ashwini Patil467efef2017-05-25 12:18:27 +05307714 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007715 }
7716
7717 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
7718 buf, sizeof(buf));
Ashwini Patil467efef2017-05-25 12:18:27 +05307719 if (res < 0) {
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007720 send_resp(dut, conn, SIGMA_ERROR,
7721 "errorCode,Connection did not complete");
7722 status = STATUS_SENT_ERROR;
Ashwini Patil467efef2017-05-25 12:18:27 +05307723 goto close_mon_conn;
7724 }
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007725 status = SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007726
Ashwini Patil467efef2017-05-25 12:18:27 +05307727close_mon_conn:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007728 wpa_ctrl_detach(ctrl);
7729 wpa_ctrl_close(ctrl);
Ashwini Patil467efef2017-05-25 12:18:27 +05307730 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007731}
7732
7733
7734static void hs2_clear_credentials(const char *intf)
7735{
7736 wpa_command(intf, "REMOVE_CRED all");
7737}
7738
7739
Lior Davidcc88b562017-01-03 18:52:09 +02007740#ifdef __linux__
7741static int wil6210_get_aid(struct sigma_dut *dut, const char *bssid,
7742 unsigned int *aid)
7743{
Lior David0fe101e2017-03-09 16:09:50 +02007744 const char *pattern = "AID[ \t]+([0-9]+)";
Lior Davidcc88b562017-01-03 18:52:09 +02007745
Lior David0fe101e2017-03-09 16:09:50 +02007746 return wil6210_get_sta_info_field(dut, bssid, pattern, aid);
Lior Davidcc88b562017-01-03 18:52:09 +02007747}
7748#endif /* __linux__ */
7749
7750
7751static int sta_get_aid_60g(struct sigma_dut *dut, const char *bssid,
7752 unsigned int *aid)
7753{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007754 switch (get_driver_type(dut)) {
Lior Davidcc88b562017-01-03 18:52:09 +02007755#ifdef __linux__
7756 case DRIVER_WIL6210:
7757 return wil6210_get_aid(dut, bssid, aid);
7758#endif /* __linux__ */
7759 default:
7760 sigma_dut_print(dut, DUT_MSG_ERROR, "get AID not supported");
7761 return -1;
7762 }
7763}
7764
7765
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007766static int sta_get_parameter_60g(struct sigma_dut *dut, struct sigma_conn *conn,
7767 struct sigma_cmd *cmd)
7768{
7769 char buf[MAX_CMD_LEN];
7770 char bss_list[MAX_CMD_LEN];
7771 const char *parameter = get_param(cmd, "Parameter");
7772
7773 if (parameter == NULL)
7774 return -1;
7775
Lior Davidcc88b562017-01-03 18:52:09 +02007776 if (strcasecmp(parameter, "AID") == 0) {
7777 unsigned int aid = 0;
7778 char bssid[20];
7779
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007780 if (get_wpa_status(get_station_ifname(dut), "bssid",
Lior Davidcc88b562017-01-03 18:52:09 +02007781 bssid, sizeof(bssid)) < 0) {
7782 sigma_dut_print(dut, DUT_MSG_ERROR,
7783 "could not get bssid");
7784 return -2;
7785 }
7786
7787 if (sta_get_aid_60g(dut, bssid, &aid))
7788 return -2;
7789
7790 snprintf(buf, sizeof(buf), "aid,%d", aid);
7791 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
7792 send_resp(dut, conn, SIGMA_COMPLETE, buf);
7793 return 0;
7794 }
7795
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007796 if (strcasecmp(parameter, "DiscoveredDevList") == 0) {
7797 char *bss_line;
7798 char *bss_id = NULL;
7799 const char *ifname = get_param(cmd, "Interface");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05307800 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007801
7802 if (ifname == NULL) {
7803 sigma_dut_print(dut, DUT_MSG_INFO,
7804 "For get DiscoveredDevList need Interface name.");
7805 return -1;
7806 }
7807
7808 /*
7809 * Use "BSS RANGE=ALL MASK=0x2" which provides a list
7810 * of BSSIDs in "bssid=<BSSID>\n"
7811 */
7812 if (wpa_command_resp(ifname, "BSS RANGE=ALL MASK=0x2",
7813 bss_list,
7814 sizeof(bss_list)) < 0) {
7815 sigma_dut_print(dut, DUT_MSG_ERROR,
7816 "Failed to get bss list");
7817 return -1;
7818 }
7819
7820 sigma_dut_print(dut, DUT_MSG_DEBUG,
7821 "bss list for ifname:%s is:%s",
7822 ifname, bss_list);
7823
7824 snprintf(buf, sizeof(buf), "DeviceList");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05307825 bss_line = strtok_r(bss_list, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007826 while (bss_line) {
7827 if (sscanf(bss_line, "bssid=%ms", &bss_id) > 0 &&
7828 bss_id) {
7829 int len;
7830
7831 len = snprintf(buf + strlen(buf),
7832 sizeof(buf) - strlen(buf),
7833 ",%s", bss_id);
7834 free(bss_id);
7835 bss_id = NULL;
7836 if (len < 0) {
7837 sigma_dut_print(dut,
7838 DUT_MSG_ERROR,
7839 "Failed to read BSSID");
7840 send_resp(dut, conn, SIGMA_ERROR,
7841 "ErrorCode,Failed to read BSS ID");
7842 return 0;
7843 }
7844
7845 if ((size_t) len >= sizeof(buf) - strlen(buf)) {
7846 sigma_dut_print(dut,
7847 DUT_MSG_ERROR,
7848 "Response buf too small for list");
7849 send_resp(dut, conn,
7850 SIGMA_ERROR,
7851 "ErrorCode,Response buf too small for list");
7852 return 0;
7853 }
7854 }
7855
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05307856 bss_line = strtok_r(NULL, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007857 }
7858
7859 sigma_dut_print(dut, DUT_MSG_INFO, "DiscoveredDevList is %s",
7860 buf);
7861 send_resp(dut, conn, SIGMA_COMPLETE, buf);
7862 return 0;
7863 }
7864
7865 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7866 return 0;
7867}
7868
7869
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07007870static int sta_get_parameter_he(struct sigma_dut *dut, struct sigma_conn *conn,
7871 struct sigma_cmd *cmd)
7872{
7873 char buf[MAX_CMD_LEN];
7874 const char *parameter = get_param(cmd, "Parameter");
7875
7876 if (!parameter)
7877 return -1;
7878
7879 if (strcasecmp(parameter, "RSSI") == 0) {
7880 char rssi[10];
7881
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007882 if (get_wpa_signal_poll(dut, get_station_ifname(dut), "RSSI",
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07007883 rssi, sizeof(rssi)) < 0) {
7884 sigma_dut_print(dut, DUT_MSG_ERROR,
7885 "Could not get RSSI");
7886 return -2;
7887 }
7888
7889 snprintf(buf, sizeof(buf), "rssi,%s", rssi);
7890 sigma_dut_print(dut, DUT_MSG_INFO, "RSSI %s", buf);
7891 send_resp(dut, conn, SIGMA_COMPLETE, buf);
7892 return 0;
7893 }
7894
7895 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7896 return 0;
7897}
7898
7899
Veerendranath Jakkamd0ad6ef2020-05-21 17:09:26 +05307900#ifdef NL80211_SUPPORT
7901
7902struct station_info {
7903 uint64_t filled;
7904 uint32_t beacon_mic_error_count;
7905 uint32_t beacon_replay_count;
7906};
7907
7908
7909static int qca_get_sta_info_handler(struct nl_msg *msg, void *arg)
7910{
7911 struct nlattr *tb[NL80211_ATTR_MAX + 1];
7912 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
7913 struct station_info *data = arg;
7914 struct nlattr *info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_MAX + 1];
7915 static struct nla_policy info_policy[
7916 QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_MAX + 1] = {
7917 [QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT] = {
7918 .type = NLA_U32
7919 },
7920 [QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT] = {
7921 .type = NLA_U32
7922 },
7923 };
7924
7925 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
7926 genlmsg_attrlen(gnlh, 0), NULL);
7927
7928 if (!tb[NL80211_ATTR_VENDOR_DATA])
7929 return NL_SKIP;
7930
7931 if (nla_parse_nested(info, QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_MAX,
7932 tb[NL80211_ATTR_VENDOR_DATA], info_policy)) {
7933 return NL_SKIP;
7934 }
7935
7936 if (info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT]) {
7937 data->filled |=
7938 BIT_ULL(QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT);
7939 data->beacon_mic_error_count =
7940 nla_get_u32(info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT]);
7941 }
7942
7943 if (info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT]) {
7944 data->filled |=
7945 BIT_ULL(QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT);
7946 data->beacon_replay_count =
7947 nla_get_u32(info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT]);
7948 }
7949
7950 return NL_SKIP;
7951}
7952
7953
7954static int qca_nl80211_get_sta_info(struct sigma_dut *dut, const char *intf,
7955 struct station_info *sta_data)
7956{
7957 struct nl_msg *msg;
7958 int ifindex, ret;
7959
7960 ifindex = if_nametoindex(intf);
7961 if (ifindex == 0) {
7962 sigma_dut_print(dut, DUT_MSG_ERROR,
7963 "%s: Index for interface %s not found",
7964 __func__, intf);
7965 return -1;
7966 }
7967
7968 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7969 NL80211_CMD_VENDOR)) ||
7970 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7971 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7972 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7973 QCA_NL80211_VENDOR_SUBCMD_GET_STA_INFO)) {
7974 sigma_dut_print(dut, DUT_MSG_ERROR,
7975 "%s: err in adding vendor_cmd", __func__);
7976 nlmsg_free(msg);
7977 return -1;
7978 }
7979
7980 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg,
7981 qca_get_sta_info_handler, sta_data);
7982 if (ret) {
7983 sigma_dut_print(dut, DUT_MSG_ERROR,
7984 "%s: err in send_and_recv_msgs, ret=%d",
7985 __func__, ret);
7986 }
7987 return ret;
7988}
7989#endif /* NL80211_SUPPORT */
7990
7991
7992static int get_bip_mic_error_count(struct sigma_dut *dut,
7993 const char *ifname,
7994 unsigned int *count)
7995{
7996#ifdef NL80211_SUPPORT
7997 struct station_info sta_data;
7998#endif /* NL80211_SUPPORT */
7999
8000 if (get_driver_type(dut) != DRIVER_WCN) {
8001 sigma_dut_print(dut, DUT_MSG_ERROR,
8002 "BIP MIC error count not supported");
8003 return -1;
8004 }
8005
8006#ifdef NL80211_SUPPORT
8007 if (qca_nl80211_get_sta_info(dut, ifname, &sta_data) != 0 ||
8008 !(sta_data.filled &
8009 BIT_ULL(QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT))) {
8010 sigma_dut_print(dut, DUT_MSG_ERROR,
8011 "BIP MIC error count fetching failed");
8012 return -1;
8013 }
8014
8015 *count = sta_data.beacon_mic_error_count;
8016 return 0;
8017#else /* NL80211_SUPPORT */
8018 sigma_dut_print(dut, DUT_MSG_ERROR,
8019 "BIP MIC error count cannot be fetched without NL80211_SUPPORT defined");
8020 return -1;
8021#endif /* NL80211_SUPPORT */
8022}
8023
8024
8025static int get_cmac_replay_count(struct sigma_dut *dut, const char *ifname,
8026 unsigned int *count)
8027{
8028#ifdef NL80211_SUPPORT
8029 struct station_info sta_data;
8030#endif /* NL80211_SUPPORT */
8031
8032 if (get_driver_type(dut) != DRIVER_WCN) {
8033 sigma_dut_print(dut, DUT_MSG_ERROR,
8034 "CMAC reply count not supported");
8035 return -1;
8036 }
8037
8038#ifdef NL80211_SUPPORT
8039 if (qca_nl80211_get_sta_info(dut, ifname, &sta_data) != 0 ||
8040 !(sta_data.filled &
8041 BIT_ULL(QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT))) {
8042 sigma_dut_print(dut, DUT_MSG_ERROR,
8043 "CMAC replay count fetching failed");
8044 return -1;
8045 }
8046
8047 *count = sta_data.beacon_replay_count;
8048 return 0;
8049#else /* NL80211_SUPPORT */
8050 sigma_dut_print(dut, DUT_MSG_ERROR,
8051 "CMAC replay count cannot be fetched without NL80211_SUPPORT defined");
8052 return -1;
8053#endif /* NL80211_SUPPORT */
8054}
8055
8056
8057static enum sigma_cmd_result sta_get_parameter_wpa3(struct sigma_dut *dut,
8058 struct sigma_conn *conn,
8059 struct sigma_cmd *cmd)
8060{
8061 char buf[MAX_CMD_LEN];
8062 const char *ifname = get_param(cmd, "interface");
8063 const char *parameter = get_param(cmd, "Parameter");
8064 unsigned int val;
8065
8066 if (!ifname || !parameter)
8067 return INVALID_SEND_STATUS;
8068
8069 if (strcasecmp(parameter, "BIPMICErrors") == 0) {
8070 if (get_bip_mic_error_count(dut, ifname, &val)) {
8071 send_resp(dut, conn, SIGMA_ERROR,
8072 "ErrorCode,Failed to get BIPMICErrors");
8073 return STATUS_SENT_ERROR;
8074 }
8075 snprintf(buf, sizeof(buf), "BIPMICErrors,%d", val);
8076 sigma_dut_print(dut, DUT_MSG_INFO, "BIPMICErrors %s", buf);
8077 send_resp(dut, conn, SIGMA_COMPLETE, buf);
8078 return STATUS_SENT;
8079 }
8080
8081 if (strcasecmp(parameter, "CMACReplays") == 0) {
8082 if (get_cmac_replay_count(dut, ifname, &val)) {
8083 send_resp(dut, conn, SIGMA_ERROR,
8084 "ErrorCode,Failed to get CMACReplays");
8085 return STATUS_SENT_ERROR;
8086 }
8087 snprintf(buf, sizeof(buf), "CMACReplays,%d", val);
8088 sigma_dut_print(dut, DUT_MSG_INFO, "CMACReplays %s", buf);
8089 send_resp(dut, conn, SIGMA_COMPLETE, buf);
8090 return STATUS_SENT;
8091 }
8092
8093 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
8094 return STATUS_SENT_ERROR;
8095}
8096
8097
Jouni Malinenca0abd32020-02-09 20:18:10 +02008098static enum sigma_cmd_result sta_get_pmk(struct sigma_dut *dut,
8099 struct sigma_conn *conn,
8100 struct sigma_cmd *cmd)
8101{
8102 const char *intf = get_param(cmd, "Interface");
8103 char buf[4096], bssid[20], resp[200], *pos, *tmp;
8104
8105 snprintf(buf, sizeof(buf), "PMKSA_GET %d", dut->infra_network_id);
8106 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
8107 strncmp(buf, "UNKNOWN COMMAND", 15) == 0) {
8108 send_resp(dut, conn, SIGMA_ERROR,
8109 "ErrorCode,PMKSA_GET not supported");
8110 return STATUS_SENT_ERROR;
8111 }
8112
8113 if (strncmp(buf, "FAIL", 4) == 0 ||
8114 get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
8115 send_resp(dut, conn, SIGMA_ERROR,
8116 "ErrorCode,Could not find current network");
8117 return STATUS_SENT_ERROR;
8118 }
8119
8120 pos = buf;
8121 while (pos) {
8122 if (strncmp(pos, bssid, 17) == 0) {
8123 pos = strchr(pos, ' ');
8124 if (!pos)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05308125 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02008126 pos++;
8127 pos = strchr(pos, ' ');
8128 if (!pos)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05308129 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02008130 pos++;
8131 tmp = strchr(pos, ' ');
8132 if (!tmp)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05308133 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02008134 *tmp = '\0';
8135 break;
8136 }
Jouni Malinenca0abd32020-02-09 20:18:10 +02008137 pos = strchr(pos, '\n');
8138 if (pos)
8139 pos++;
8140 }
8141
8142 if (!pos) {
8143 send_resp(dut, conn, SIGMA_ERROR,
8144 "ErrorCode,PMK not available");
8145 return STATUS_SENT_ERROR;
8146 }
8147
8148 snprintf(resp, sizeof(resp), "PMK,%s", pos);
8149 send_resp(dut, conn, SIGMA_COMPLETE, resp);
8150 return STATUS_SENT;
8151}
8152
8153
Jouni Malinenf7222712019-06-13 01:50:21 +03008154static enum sigma_cmd_result cmd_sta_get_parameter(struct sigma_dut *dut,
8155 struct sigma_conn *conn,
8156 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008157{
8158 const char *program = get_param(cmd, "Program");
Jouni Malinenca0abd32020-02-09 20:18:10 +02008159 const char *parameter = get_param(cmd, "Parameter");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008160
Jouni Malinenca0abd32020-02-09 20:18:10 +02008161 if (!parameter)
8162 return INVALID_SEND_STATUS;
8163
8164 if (strcasecmp(parameter, "PMK") == 0)
8165 return sta_get_pmk(dut, conn, cmd);
8166
8167 if (!program)
8168 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008169
8170 if (strcasecmp(program, "P2PNFC") == 0)
8171 return p2p_cmd_sta_get_parameter(dut, conn, cmd);
8172
8173 if (strcasecmp(program, "60ghz") == 0)
8174 return sta_get_parameter_60g(dut, conn, cmd);
8175
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07008176 if (strcasecmp(program, "he") == 0)
8177 return sta_get_parameter_he(dut, conn, cmd);
8178
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008179#ifdef ANDROID_NAN
8180 if (strcasecmp(program, "NAN") == 0)
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07008181 return nan_cmd_sta_get_parameter(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008182#endif /* ANDROID_NAN */
8183
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07008184#ifdef MIRACAST
8185 if (strcasecmp(program, "WFD") == 0 ||
8186 strcasecmp(program, "DisplayR2") == 0)
8187 return miracast_cmd_sta_get_parameter(dut, conn, cmd);
8188#endif /* MIRACAST */
Veerendranath Jakkamd0ad6ef2020-05-21 17:09:26 +05308189 if (strcasecmp(program, "WPA3") == 0)
8190 return sta_get_parameter_wpa3(dut, conn, cmd);
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07008191
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008192 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
8193 return 0;
8194}
8195
8196
8197static void sta_reset_default_ath(struct sigma_dut *dut, const char *intf,
8198 const char *type)
8199{
8200 char buf[100];
8201
8202 if (dut->program == PROGRAM_VHT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008203 run_iwpriv(dut, intf, "chwidth 2");
8204 run_iwpriv(dut, intf, "mode 11ACVHT80");
8205 run_iwpriv(dut, intf, "vhtmcs -1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008206 }
8207
8208 if (dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008209 run_iwpriv(dut, intf, "chwidth 0");
8210 run_iwpriv(dut, intf, "mode 11naht40");
8211 run_iwpriv(dut, intf, "set11NRates 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008212 }
8213
8214 if (dut->program == PROGRAM_VHT || dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008215 run_iwpriv(dut, intf, "powersave 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008216
8217 /* Reset CTS width */
8218 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 54 0",
8219 intf);
8220 if (system(buf) != 0) {
8221 sigma_dut_print(dut, DUT_MSG_ERROR,
8222 "wifitool %s beeliner_fw_test 54 0 failed",
8223 intf);
8224 }
8225
8226 /* Enable Dynamic Bandwidth signalling by default */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008227 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008228
8229 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", intf);
8230 if (system(buf) != 0) {
8231 sigma_dut_print(dut, DUT_MSG_ERROR,
8232 "iwpriv rts failed");
8233 }
8234 }
8235
8236 if (type && strcasecmp(type, "Testbed") == 0) {
8237 dut->testbed_flag_txsp = 1;
8238 dut->testbed_flag_rxsp = 1;
8239 /* STA has to set spatial stream to 2 per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008240 run_iwpriv(dut, intf, "vht_mcsmap 0xfff0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008241
8242 /* Disable LDPC per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008243 run_iwpriv(dut, intf, "ldpc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008244
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008245 run_iwpriv(dut, intf, "amsdu 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008246
8247 /* TODO: Disable STBC 2x1 transmit and receive */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008248 run_iwpriv(dut, intf, "tx_stbc 0");
8249 run_iwpriv(dut, intf, "rx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008250
8251 /* STA has to disable Short GI per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008252 run_iwpriv(dut, intf, "shortgi 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008253 }
8254
8255 if (type && strcasecmp(type, "DUT") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008256 run_iwpriv(dut, intf, "nss 3");
Arif Hussainac6c5112018-05-25 17:34:00 -07008257 dut->sta_nss = 3;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008258
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008259 run_iwpriv(dut, intf, "shortgi 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008260 }
8261}
8262
8263
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08008264#ifdef NL80211_SUPPORT
8265static int sta_set_he_mcs(struct sigma_dut *dut, const char *intf,
8266 enum he_mcs_config mcs)
8267{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05308268 return wcn_wifi_test_config_set_u8(
8269 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MCS, mcs);
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08008270}
8271#endif /* NL80211_SUPPORT */
8272
8273
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07008274static int sta_set_action_tx_in_he_tb_ppdu(struct sigma_dut *dut,
8275 const char *intf, int enable)
8276{
8277#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05308278 return wcn_wifi_test_config_set_u8(
8279 dut, intf,
8280 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_ACTION_TX_TB_PPDU,
8281 enable);
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07008282#else /* NL80211_SUPPORT */
8283 sigma_dut_print(dut, DUT_MSG_ERROR,
8284 "HE action Tx TB PPDU cannot be set without NL80211_SUPPORT defined");
8285 return -1;
8286#endif /* NL80211_SUPPORT */
8287}
8288
8289
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08008290static int sta_set_heconfig_and_wep_tkip(struct sigma_dut *dut,
8291 const char *intf, int enable)
8292{
8293#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05308294 return wcn_wifi_test_config_set_u8(
8295 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WEP_TKIP_IN_HE,
8296 enable);
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08008297#else /* NL80211_SUPPORT */
8298 sigma_dut_print(dut, DUT_MSG_ERROR,
8299 "HE config enablement cannot be changed without NL80211_SUPPORT defined");
8300 return -1;
8301#endif /* NL80211_SUPPORT */
8302}
8303
8304
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08008305#ifdef NL80211_SUPPORT
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08008306
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08008307static int sta_set_he_testbed_def(struct sigma_dut *dut,
8308 const char *intf, int cfg)
8309{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05308310 return wcn_wifi_test_config_set_u8(
8311 dut, intf,
8312 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SET_HE_TESTBED_DEFAULTS,
8313 cfg);
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08008314}
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08008315
8316
8317static int sta_set_2g_vht_supp(struct sigma_dut *dut, const char *intf, int cfg)
8318{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05308319 return wcn_wifi_test_config_set_u8(
8320 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_2G_VHT,
8321 cfg);
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08008322}
8323
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08008324#endif /* NL80211_SUPPORT */
8325
8326
Qiwei Caib6806972020-01-15 13:52:11 +08008327int sta_set_addba_buf_size(struct sigma_dut *dut,
8328 const char *intf, int bufsize)
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08008329{
8330#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05308331 return wcn_wifi_test_config_set_u16(
8332 dut, intf,
8333 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE, bufsize);
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08008334#else /* NL80211_SUPPORT */
8335 sigma_dut_print(dut, DUT_MSG_ERROR,
8336 "AddBA bufsize cannot be changed without NL80211_SUPPORT defined");
8337 return -1;
8338#endif /* NL80211_SUPPORT */
8339}
8340
8341
Kiran Kumar Lokere69d89952021-08-08 23:41:46 -07008342static int sta_set_scan_unicast_probe(struct sigma_dut *dut,
8343 const char *intf, int val)
8344{
8345#ifdef NL80211_SUPPORT
8346 return wcn_wifi_test_config_set_u8(
8347 dut, intf,
8348 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_USE_BSSID_IN_PROBE_REQ_RA,
8349 val);
8350#else /* NL80211_SUPPORT */
8351 sigma_dut_print(dut, DUT_MSG_ERROR,
8352 "Unicast RA in Probe Request frame cannot be set without NL80211_SUPPORT defined");
8353 return -1;
8354#endif /* NL80211_SUPPORT */
8355}
8356
8357
Kiran Kumar Lokere09dbcef2021-08-09 00:01:41 -07008358static int sta_set_rx_ctrl_multi_bss(struct sigma_dut *dut, const char *intf,
8359 int enable)
8360{
8361#ifdef NL80211_SUPPORT
8362 return wcn_wifi_test_config_set_u8(
8363 dut, intf,
8364 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_RX_CTRL_FRAME_TO_MBSS,
8365 enable);
8366#else /* NL80211_SUPPORT */
8367 sigma_dut_print(dut, DUT_MSG_ERROR,
8368 "Rx ctrl frame to Multi-BSS cannot be changed without NL80211_SUPPORT defined");
8369 return -1;
8370#endif /* NL80211_SUPPORT */
8371}
8372
8373
8374static int sta_set_bcast_twt_support(struct sigma_dut *dut, const char *intf,
8375 int enable)
8376{
8377#ifdef NL80211_SUPPORT
8378 return wcn_wifi_test_config_set_u8(
8379 dut, intf,
8380 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BCAST_TWT_SUPPORT,
8381 enable);
8382#else /* NL80211_SUPPORT */
8383 sigma_dut_print(dut, DUT_MSG_ERROR,
8384 "BCAST TWT cannot be changed without NL80211_SUPPORT defined");
8385 return -1;
8386#endif /* NL80211_SUPPORT */
8387}
8388
8389
Arif Hussain8d5b27b2018-05-14 14:31:03 -07008390static int sta_set_tx_beamformee(struct sigma_dut *dut, const char *intf,
8391 int enable)
8392{
8393#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05308394 return wcn_wifi_test_config_set_u8(
8395 dut, intf,
8396 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_TX_BEAMFORMEE,
8397 enable);
Arif Hussain8d5b27b2018-05-14 14:31:03 -07008398#else /* NL80211_SUPPORT */
8399 sigma_dut_print(dut, DUT_MSG_ERROR,
8400 "tx beamformee cannot be changed without NL80211_SUPPORT defined");
8401 return -1;
8402#endif /* NL80211_SUPPORT */
8403}
8404
8405
Arif Hussain9765f7d2018-07-03 08:28:26 -07008406static int sta_set_beamformee_sts(struct sigma_dut *dut, const char *intf,
8407 int val)
8408{
8409#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05308410 return wcn_wifi_test_config_set_u8(
8411 dut, intf,
8412 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_BEAMFORMEE_NSTS,
8413 val);
Arif Hussain9765f7d2018-07-03 08:28:26 -07008414#else /* NL80211_SUPPORT */
8415 sigma_dut_print(dut, DUT_MSG_ERROR,
8416 "beamformee sts cannot be changed without NL80211_SUPPORT defined");
8417 return -1;
8418#endif /* NL80211_SUPPORT */
8419}
8420
8421
Arif Hussain68d23f52018-07-11 13:39:08 -07008422#ifdef NL80211_SUPPORT
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07008423static int sta_set_mac_padding_duration(struct sigma_dut *dut, const char *intf,
8424 enum qca_wlan_he_mac_padding_dur val)
8425{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05308426 return wcn_wifi_test_config_set_u8(
8427 dut, intf,
8428 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MAC_PADDING_DUR, val);
Arif Hussain68d23f52018-07-11 13:39:08 -07008429}
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07008430#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07008431
8432
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07008433static int sta_set_tx_su_ppdu_cfg(struct sigma_dut *dut, const char *intf,
8434 int val)
8435{
8436#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05308437 return wcn_wifi_test_config_set_u8(
8438 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_SUPPDU,
8439 val);
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07008440#else /* NL80211_SUPPORT */
8441 sigma_dut_print(dut, DUT_MSG_ERROR,
8442 "Tx SU PPDU cannot be set without NL80211_SUPPORT defined");
8443 return -1;
8444#endif /* NL80211_SUPPORT */
8445}
8446
8447
Kiran Kumar Lokere54b72522021-04-01 00:22:44 -07008448static int sta_set_mgmt_data_tx_disable_cfg(struct sigma_dut *dut,
8449 const char *intf, int val)
8450{
8451#ifdef NL80211_SUPPORT
8452 return wcn_wifi_test_config_set_u8(
8453 dut, intf,
8454 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_DISABLE_DATA_MGMT_RSP_TX,
8455 val);
8456#else /* NL80211_SUPPORT */
8457 sigma_dut_print(dut, DUT_MSG_ERROR,
8458 "Tx disable config cannot be set without NL80211_SUPPORT defined");
8459 return -1;
8460#endif /* NL80211_SUPPORT */
8461}
8462
8463
Kiran Kumar Lokere1809da12021-06-24 00:45:38 -07008464static int sta_set_keep_alive_data_cfg(struct sigma_dut *dut, const char *intf,
8465 int val)
8466{
8467#ifdef NL80211_SUPPORT
8468 return wcn_wifi_test_config_set_u8(
8469 dut, intf,
8470 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_KEEP_ALIVE_FRAME_TYPE,
8471 val);
8472#else /* NL80211_SUPPORT */
8473 sigma_dut_print(dut, DUT_MSG_ERROR,
8474 "Keep alive data type cannot be set without NL80211_SUPPORT defined");
8475 return -1;
8476#endif /* NL80211_SUPPORT */
8477}
8478
8479
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07008480#ifdef NL80211_SUPPORT
8481static int sta_set_he_om_ctrl_reset(struct sigma_dut *dut, const char *intf)
8482{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05308483 return wcn_wifi_test_config_set_flag(
8484 dut, intf,
8485 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_CLEAR_HE_OM_CTRL_CONFIG);
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07008486}
8487#endif /* NL80211_SUPPORT */
8488
8489
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07008490static int sta_set_mu_edca_override(struct sigma_dut *dut, const char *intf,
8491 int val)
8492{
8493#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05308494 return wcn_wifi_test_config_set_u8(
8495 dut, intf,
8496 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_OVERRIDE_MU_EDCA, val);
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07008497#else /* NL80211_SUPPORT */
8498 sigma_dut_print(dut, DUT_MSG_ERROR,
8499 "MU EDCA override cannot be changed without NL80211_SUPPORT defined");
8500 return -1;
8501#endif /* NL80211_SUPPORT */
8502}
8503
8504
Kiran Kumar Lokerefa7c7b92021-08-09 00:50:55 -07008505static int sta_set_er_su_ppdu_type_tx(struct sigma_dut *dut, const char *intf,
8506 int val)
8507{
8508#ifdef NL80211_SUPPORT
8509 return wcn_wifi_test_config_set_u8(
8510 dut, intf,
8511 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ER_SU_PPDU_TYPE, val);
8512#else /* NL80211_SUPPORT */
8513 sigma_dut_print(dut, DUT_MSG_ERROR,
8514 "ER-SU PPDU type cannot be set without NL80211_SUPPORT defined");
8515 return -1;
8516#endif /* NL80211_SUPPORT */
8517}
8518
8519
8520static int sta_set_ru_242_tone_tx(struct sigma_dut *dut, const char *intf,
8521 int val)
8522{
8523#ifdef NL80211_SUPPORT
8524 return wcn_wifi_test_config_set_u8(
8525 dut, intf,
8526 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_RU_242_TONE_TX, val);
8527#else /* NL80211_SUPPORT */
8528 sigma_dut_print(dut, DUT_MSG_ERROR,
8529 "RU 242 tone cannot be set without NL80211_SUPPORT defined");
8530 return -1;
8531#endif /* NL80211_SUPPORT */
8532}
8533
8534
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07008535static int sta_set_om_ctrl_supp(struct sigma_dut *dut, const char *intf,
8536 int val)
8537{
8538#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05308539 return wcn_wifi_test_config_set_u8(
8540 dut, intf,
8541 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OM_CTRL_SUPP, val);
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07008542#else /* NL80211_SUPPORT */
8543 sigma_dut_print(dut, DUT_MSG_ERROR,
8544 "HE OM ctrl cannot be changed without NL80211_SUPPORT defined");
8545 return -1;
8546#endif /* NL80211_SUPPORT */
8547}
8548
8549
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07008550#ifdef NL80211_SUPPORT
8551
8552struct features_info {
8553 unsigned char flags[8];
8554 size_t flags_len;
8555};
8556
8557static int features_info_handler(struct nl_msg *msg, void *arg)
8558{
8559 struct nlattr *tb[NL80211_ATTR_MAX + 1];
8560 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
8561 struct features_info *info = arg;
8562 struct nlattr *nl_vend, *attr;
8563
8564 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
8565 genlmsg_attrlen(gnlh, 0), NULL);
8566
8567 nl_vend = tb[NL80211_ATTR_VENDOR_DATA];
8568 if (nl_vend) {
8569 struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1];
8570
8571 nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX,
8572 nla_data(nl_vend), nla_len(nl_vend), NULL);
8573
8574 attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_FEATURE_FLAGS];
8575 if (attr) {
8576 int len = nla_len(attr);
8577
Vamsi Krishna79a91132021-08-16 21:40:22 +05308578 if (info && len <= sizeof(info->flags)) {
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07008579 memcpy(info->flags, nla_data(attr), len);
8580 info->flags_len = len;
8581 }
8582 }
8583 }
8584
8585 return NL_SKIP;
8586}
8587
8588
8589static int check_feature(enum qca_wlan_vendor_features feature,
8590 struct features_info *info)
8591{
8592 size_t idx = feature / 8;
8593
Vamsi Krishna79a91132021-08-16 21:40:22 +05308594 if (!info)
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07008595 return 0;
8596
8597 return (idx < info->flags_len) &&
8598 (info->flags[idx] & BIT(feature % 8));
8599}
8600
8601#endif /* NL80211_SUPPORT */
8602
8603
8604static void sta_get_twt_feature_async_supp(struct sigma_dut *dut,
8605 const char *intf)
8606{
8607#ifdef NL80211_SUPPORT
8608 struct nl_msg *msg;
8609 struct features_info info = { 0 };
8610 int ifindex, ret;
8611
8612 ifindex = if_nametoindex(intf);
8613 if (ifindex == 0) {
8614 sigma_dut_print(dut, DUT_MSG_ERROR,
8615 "%s: Index for interface %s failed",
8616 __func__, intf);
8617 return;
8618 }
8619
8620 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8621 NL80211_CMD_VENDOR)) ||
8622 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8623 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8624 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8625 QCA_NL80211_VENDOR_SUBCMD_GET_FEATURES)) {
8626 sigma_dut_print(dut, DUT_MSG_ERROR,
8627 "%s: err in adding vendor_cmd and vendor_data",
8628 __func__);
8629 nlmsg_free(msg);
8630 return;
8631 }
8632
8633 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, features_info_handler,
8634 &info);
8635 if (ret) {
8636 sigma_dut_print(dut, DUT_MSG_ERROR,
8637 "%s: err in send_and_recv_msgs, ret=%d",
8638 __func__, ret);
8639 return;
8640 }
8641
8642 if (check_feature(QCA_WLAN_VENDOR_FEATURE_TWT_ASYNC_SUPPORT, &info))
8643 dut->sta_async_twt_supp = 1;
8644 else
8645 dut->sta_async_twt_supp = 0;
8646
8647 sigma_dut_print(dut, DUT_MSG_DEBUG,
8648 "%s: sta_async_twt_supp %d",
8649 __func__, dut->sta_async_twt_supp);
8650#else /* NL80211_SUPPORT */
8651 sigma_dut_print(dut, DUT_MSG_INFO,
8652 "TWT async supp get cannot be done without NL80211_SUPPORT defined");
8653 dut->sta_async_twt_supp = 0;
8654#endif /* NL80211_SUPPORT */
8655}
8656
8657
Arif Hussain480d5f42019-03-12 14:40:42 -07008658static int sta_set_twt_req_support(struct sigma_dut *dut, const char *intf,
8659 int val)
8660{
8661#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05308662 return wcn_wifi_test_config_set_u8(
8663 dut, intf,
8664 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TWT_REQ_SUPPORT, val);
Arif Hussain480d5f42019-03-12 14:40:42 -07008665#else /* NL80211_SUPPORT */
8666 sigma_dut_print(dut, DUT_MSG_ERROR,
8667 "TWT Request cannot be changed without NL80211_SUPPORT defined");
8668 return -1;
8669#endif /* NL80211_SUPPORT */
8670}
8671
8672
Kiran Kumar Lokere4f2d4b02021-04-01 00:07:39 -07008673static int sta_set_bss_max_idle_period(struct sigma_dut *dut, const char *intf,
8674 int val)
8675{
8676#ifdef NL80211_SUPPORT
8677 return wcn_wifi_test_config_set_u16(
8678 dut, intf,
8679 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BSS_MAX_IDLE_PERIOD, val);
8680#else /* NL80211_SUPPORT */
8681 sigma_dut_print(dut, DUT_MSG_ERROR,
8682 "BSS max idle period cannot be set without NL80211_SUPPORT defined");
8683 return -1;
8684#endif /* NL80211_SUPPORT */
8685}
8686
8687
Kiran Kumar Lokere07ad92b2021-08-09 00:27:14 -07008688static int sta_set_bss_max_idle_support(struct sigma_dut *dut, const char *intf,
8689 int val)
8690{
8691#ifdef NL80211_SUPPORT
8692 return wcn_wifi_test_config_set_u8(
8693 dut, intf,
8694 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BSS_MAX_IDLE_PERIOD_ENABLE,
8695 val);
8696#else /* NL80211_SUPPORT */
8697 sigma_dut_print(dut, DUT_MSG_ERROR,
8698 "BSS max idle support cannot be set without NL80211_SUPPORT defined");
8699 return -1;
8700#endif /* NL80211_SUPPORT */
8701}
8702
8703
Srinivas Girigowda0525e292020-11-12 13:28:21 -08008704static int sta_set_fullbw_ulmumimo(struct sigma_dut *dut, const char *intf,
8705 int val)
8706{
8707#ifdef NL80211_SUPPORT
8708 return wcn_wifi_test_config_set_u8(
8709 dut, intf,
8710 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_FULL_BW_UL_MU_MIMO, val);
8711#else /* NL80211_SUPPORT */
8712 sigma_dut_print(dut, DUT_MSG_ERROR,
8713 "Full BW UL MU MIMO cannot be changed without NL80211_SUPPORT defined");
8714 return -1;
8715#endif /* NL80211_SUPPORT */
8716}
8717
8718
Kiran Kumar Lokered0ec5ed2021-04-01 00:15:04 -07008719static int sta_set_punctured_preamble_rx(struct sigma_dut *dut,
8720 const char *intf, int val)
8721{
8722#ifdef NL80211_SUPPORT
8723 return wcn_wifi_test_config_set_u8(
8724 dut, intf,
8725 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_PUNCTURED_PREAMBLE_RX,
8726 val);
8727#else /* NL80211_SUPPORT */
8728 sigma_dut_print(dut, DUT_MSG_ERROR,
8729 "Punctured preamble Rx cannot be set without NL80211_SUPPORT defined");
8730 return -1;
8731#endif /* NL80211_SUPPORT */
8732}
8733
8734
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08008735static void sta_reset_default_wcn(struct sigma_dut *dut, const char *intf,
8736 const char *type)
8737{
8738 char buf[60];
8739
8740 if (dut->program == PROGRAM_HE) {
8741 /* resetting phymode to auto in case of HE program */
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05308742 sta_set_phymode(dut, intf, "auto");
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08008743
Amarnath Hullur Subramanyam9cecb502018-04-25 13:26:30 -07008744 /* reset the rate to Auto rate */
8745 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0xff",
8746 intf);
8747 if (system(buf) != 0) {
8748 sigma_dut_print(dut, DUT_MSG_ERROR,
8749 "iwpriv %s set_11ax_rate 0xff failed",
8750 intf);
8751 }
8752
Kiran Kumar Lokere86cfe3a2018-06-01 11:55:15 -07008753 /* reset the LDPC setting */
8754 snprintf(buf, sizeof(buf), "iwpriv %s ldpc 1", intf);
8755 if (system(buf) != 0) {
8756 sigma_dut_print(dut, DUT_MSG_ERROR,
8757 "iwpriv %s ldpc 1 failed", intf);
8758 }
8759
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08008760 /* reset the power save setting */
Vinita S. Malooa8b62722020-04-23 01:45:41 +05308761 set_power_save_wcn(dut, intf, 2);
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08008762
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08008763 /* remove all network profiles */
8764 remove_wpa_networks(intf);
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08008765
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08008766 /* Configure ADDBA Req/Rsp buffer size to be 64 */
8767 sta_set_addba_buf_size(dut, intf, 64);
8768
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07008769 if (dut->sta_async_twt_supp == -1)
8770 sta_get_twt_feature_async_supp(dut, intf);
8771
Kiran Kumar Lokere69d89952021-08-08 23:41:46 -07008772 sta_set_scan_unicast_probe(dut, intf, 0);
8773
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08008774#ifdef NL80211_SUPPORT
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08008775 /* Reset the device HE capabilities to its default supported
8776 * configuration. */
8777 sta_set_he_testbed_def(dut, intf, 0);
8778
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08008779 /* Disable noackpolicy for all AC */
8780 if (nlvendor_sta_set_noack(dut, intf, 0, QCA_WLAN_AC_ALL)) {
8781 sigma_dut_print(dut, DUT_MSG_ERROR,
8782 "Disable of noackpolicy for all AC failed");
8783 }
8784#endif /* NL80211_SUPPORT */
8785
Amarnath Hullur Subramanyamb1724a52018-03-07 14:31:46 -08008786 /* Enable WMM by default */
8787 if (wcn_sta_set_wmm(dut, intf, "on")) {
8788 sigma_dut_print(dut, DUT_MSG_ERROR,
8789 "Enable of WMM in sta_reset_default_wcn failed");
8790 }
8791
8792 /* Disable ADDBA_REJECT by default */
8793 if (nlvendor_sta_set_addba_reject(dut, intf, 0)) {
8794 sigma_dut_print(dut, DUT_MSG_ERROR,
8795 "Disable of addba_reject in sta_reset_default_wcn failed");
8796 }
8797
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08008798 /* Enable sending of ADDBA by default */
8799 if (nlvendor_config_send_addba(dut, intf, 1)) {
8800 sigma_dut_print(dut, DUT_MSG_ERROR,
8801 "Enable sending of ADDBA in sta_reset_default_wcn failed");
8802 }
8803
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08008804 /* Enable AMPDU by default */
8805 iwpriv_sta_set_ampdu(dut, intf, 1);
8806
Subhani Shaik8e7a3052018-04-24 14:03:00 -07008807#ifdef NL80211_SUPPORT
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -08008808 if (wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_AUTO)) {
Subhani Shaik8e7a3052018-04-24 14:03:00 -07008809 sigma_dut_print(dut, DUT_MSG_ERROR,
8810 "Set LTF config to default in sta_reset_default_wcn failed");
8811 }
Arif Hussain9765f7d2018-07-03 08:28:26 -07008812
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08008813 /* set the beamformee NSTS(maximum number of
8814 * space-time streams) to default DUT config
8815 */
8816 if (sta_set_beamformee_sts(dut, intf, 7)) {
Arif Hussain9765f7d2018-07-03 08:28:26 -07008817 sigma_dut_print(dut, DUT_MSG_ERROR,
8818 "Failed to set BeamformeeSTS");
8819 }
Arif Hussain68d23f52018-07-11 13:39:08 -07008820
Kiran Kumar Lokere54b72522021-04-01 00:22:44 -07008821 if (sta_set_mgmt_data_tx_disable_cfg(dut, intf, 0)) {
8822 sigma_dut_print(dut, DUT_MSG_ERROR,
8823 "Failed to reset mgmt/data Tx disable config");
8824 }
8825
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07008826 if (sta_set_mac_padding_duration(
8827 dut, intf,
8828 QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07008829 sigma_dut_print(dut, DUT_MSG_ERROR,
8830 "Failed to set MAC padding duration");
8831 }
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07008832
8833 if (sta_set_mu_edca_override(dut, intf, 0)) {
8834 sigma_dut_print(dut, DUT_MSG_ERROR,
8835 "ErrorCode,Failed to set MU EDCA override disable");
8836 }
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07008837
Kiran Kumar Lokerefa7c7b92021-08-09 00:50:55 -07008838 if (sta_set_ru_242_tone_tx(dut, intf, 0)) {
8839 sigma_dut_print(dut, DUT_MSG_ERROR,
8840 "Failed to set RU 242 tone Tx");
8841 }
8842
8843 if (sta_set_er_su_ppdu_type_tx(dut, intf, 0)) {
8844 sigma_dut_print(dut, DUT_MSG_ERROR,
8845 "Failed to set ER-SU PPDU type Tx");
8846 }
8847
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07008848 if (sta_set_om_ctrl_supp(dut, intf, 1)) {
8849 sigma_dut_print(dut, DUT_MSG_ERROR,
8850 "Failed to set OM ctrl supp");
8851 }
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07008852
8853 if (sta_set_tx_su_ppdu_cfg(dut, intf, 1)) {
8854 sigma_dut_print(dut, DUT_MSG_ERROR,
8855 "Failed to set Tx SU PPDU enable");
8856 }
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07008857
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07008858 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 0)) {
8859 sigma_dut_print(dut, DUT_MSG_ERROR,
8860 "failed to send TB PPDU Tx cfg");
8861 }
8862
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07008863 if (sta_set_he_om_ctrl_reset(dut, intf)) {
8864 sigma_dut_print(dut, DUT_MSG_ERROR,
8865 "Failed to set OM ctrl reset");
8866 }
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08008867
8868 /* +HTC-HE support default on */
8869 if (sta_set_he_htc_supp(dut, intf, 1)) {
8870 sigma_dut_print(dut, DUT_MSG_ERROR,
8871 "Setting of +HTC-HE support failed");
8872 }
Subhani Shaik8e7a3052018-04-24 14:03:00 -07008873#endif /* NL80211_SUPPORT */
8874
Arif Hussain8d5b27b2018-05-14 14:31:03 -07008875 if (sta_set_tx_beamformee(dut, intf, 1)) {
8876 sigma_dut_print(dut, DUT_MSG_ERROR,
8877 "Set tx beamformee enable by default in sta_reset_default_wcn failed");
8878 }
8879
Kiran Kumar Lokereb55ff442020-07-15 00:20:40 -07008880 wpa_command(intf, "SET oce 1");
8881
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08008882 /* Set nss to 1 and MCS 0-7 in case of testbed */
8883 if (type && strcasecmp(type, "Testbed") == 0) {
8884#ifdef NL80211_SUPPORT
8885 int ret;
8886#endif /* NL80211_SUPPORT */
8887
Kiran Kumar Lokereb55ff442020-07-15 00:20:40 -07008888 wpa_command(intf, "SET oce 0");
8889
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08008890 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
8891 if (system(buf) != 0) {
8892 sigma_dut_print(dut, DUT_MSG_ERROR,
8893 "iwpriv %s nss failed", intf);
8894 }
8895
8896#ifdef NL80211_SUPPORT
8897 ret = sta_set_he_mcs(dut, intf, HE_80_MCS0_7);
8898 if (ret) {
8899 sigma_dut_print(dut, DUT_MSG_ERROR,
8900 "Setting of MCS failed, ret:%d",
8901 ret);
8902 }
8903#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyamc67621d2018-02-04 23:18:01 -08008904
8905 /* Disable STBC as default */
8906 wcn_sta_set_stbc(dut, intf, "0");
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08008907
8908 /* Disable AMSDU as default */
8909 iwpriv_sta_set_amsdu(dut, intf, "0");
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08008910
8911#ifdef NL80211_SUPPORT
8912 /* HE fragmentation default off */
8913 if (sta_set_he_fragmentation(dut, intf,
8914 HE_FRAG_DISABLE)) {
8915 sigma_dut_print(dut, DUT_MSG_ERROR,
8916 "Setting of HE fragmentation failed");
8917 }
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08008918
8919 /* set the beamformee NSTS(maximum number of
8920 * space-time streams) to default testbed config
8921 */
8922 if (sta_set_beamformee_sts(dut, intf, 3)) {
8923 sigma_dut_print(dut, DUT_MSG_ERROR,
8924 "Failed to set BeamformeeSTS");
8925 }
8926
Kiran Kumar Lokered0ec5ed2021-04-01 00:15:04 -07008927 if (sta_set_punctured_preamble_rx(dut, intf, 0)) {
8928 sigma_dut_print(dut, DUT_MSG_ERROR,
8929 "Failed to reset PreamblePunctRx support");
8930 }
8931
Kiran Kumar Lokere727687f2021-06-24 00:35:49 -07008932 if (sta_set_bss_max_idle_period(dut, intf, 0)) {
8933 sigma_dut_print(dut, DUT_MSG_ERROR,
8934 "Failed to reset BSS max idle period");
8935 }
8936
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08008937 /* +HTC-HE support default off */
8938 if (sta_set_he_htc_supp(dut, intf, 0)) {
8939 sigma_dut_print(dut, DUT_MSG_ERROR,
8940 "Setting of +HTC-HE support failed");
8941 }
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08008942
8943 /* Set device HE capabilities to testbed default
8944 * configuration. */
8945 if (sta_set_he_testbed_def(dut, intf, 1)) {
8946 sigma_dut_print(dut, DUT_MSG_DEBUG,
8947 "Failed to set HE defaults");
8948 }
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08008949
8950 /* Disable VHT support in 2.4 GHz for testbed */
8951 sta_set_2g_vht_supp(dut, intf, 0);
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08008952#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08008953
8954 /* Enable WEP/TKIP with HE capability in testbed */
8955 if (sta_set_heconfig_and_wep_tkip(dut, intf, 1)) {
8956 sigma_dut_print(dut, DUT_MSG_ERROR,
8957 "Enabling HE config with WEP/TKIP failed");
8958 }
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08008959 }
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08008960
8961 /* Defaults in case of DUT */
8962 if (type && strcasecmp(type, "DUT") == 0) {
Arif Hussaind48fcc72018-05-01 18:34:18 -07008963 /* Enable STBC by default */
8964 wcn_sta_set_stbc(dut, intf, "1");
8965
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08008966 /* set nss to 2 */
8967 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
8968 if (system(buf) != 0) {
8969 sigma_dut_print(dut, DUT_MSG_ERROR,
8970 "iwpriv %s nss 2 failed", intf);
8971 }
Arif Hussainac6c5112018-05-25 17:34:00 -07008972 dut->sta_nss = 2;
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08008973
8974#ifdef NL80211_SUPPORT
Arif Hussainae239842018-05-01 18:20:05 -07008975 /* Set HE_MCS to 0-11 */
8976 if (sta_set_he_mcs(dut, intf, HE_80_MCS0_11)) {
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08008977 sigma_dut_print(dut, DUT_MSG_ERROR,
8978 "Setting of MCS failed");
8979 }
8980#endif /* NL80211_SUPPORT */
8981
8982 /* Disable WEP/TKIP with HE capability in DUT */
8983 if (sta_set_heconfig_and_wep_tkip(dut, intf, 0)) {
8984 sigma_dut_print(dut, DUT_MSG_ERROR,
8985 "Enabling HE config with WEP/TKIP failed");
8986 }
8987 }
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08008988 }
8989}
8990
8991
Veerendranath Jakkam47867202020-12-21 01:53:52 +05308992static int sta_set_client_privacy(struct sigma_dut *dut,
8993 struct sigma_conn *conn, const char *intf,
8994 int enable)
8995{
8996 if (enable &&
8997 (wpa_command(intf, "SET mac_addr 1") < 0 ||
8998 wpa_command(intf, "SET rand_addr_lifetime 1") < 0 ||
Veerendranath Jakkam39fd5c42020-12-21 02:02:21 +05308999 (wpa_command(intf, "MAC_RAND_SCAN enable=1 all") < 0 &&
9000 wpa_command(intf, "SET preassoc_mac_addr 1") < 0) ||
Veerendranath Jakkam47867202020-12-21 01:53:52 +05309001 wpa_command(intf, "SET gas_rand_mac_addr 1") < 0 ||
9002 wpa_command(intf, "SET gas_rand_addr_lifetime 1") < 0))
9003 return -1;
9004
9005 if (!enable &&
9006 (wpa_command(intf, "SET mac_addr 0") < 0 ||
Veerendranath Jakkam39fd5c42020-12-21 02:02:21 +05309007 (wpa_command(intf, "MAC_RAND_SCAN enable=0 all") < 0 &&
9008 wpa_command(intf, "SET preassoc_mac_addr 0") < 0) ||
Veerendranath Jakkam47867202020-12-21 01:53:52 +05309009 wpa_command(intf, "SET gas_rand_mac_addr 0") < 0))
9010 return -1;
9011
9012 dut->client_privacy = enable;
9013 return 0;
9014}
9015
9016
Jouni Malinenf7222712019-06-13 01:50:21 +03009017static enum sigma_cmd_result cmd_sta_reset_default(struct sigma_dut *dut,
9018 struct sigma_conn *conn,
9019 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009020{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009021 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02009022 const char *band = get_param(cmd, "band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009023 const char *type;
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07009024 const char *program = get_param(cmd, "program");
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05309025 const char *dev_role = get_param(cmd, "DevRole");
Veerendranath Jakkamc1f71b62021-01-23 03:09:51 +05309026 char resp[20];
Veerendranath Jakkamea7f0692021-08-11 19:13:12 +05309027 char buf[100];
Veerendranath Jakkamc1f71b62021-01-23 03:09:51 +05309028 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009029
Jouni Malinenb21f0542019-11-04 17:53:38 +02009030 if (dut->station_ifname_2g &&
9031 strcmp(dut->station_ifname_2g, intf) == 0)
9032 dut->use_5g = 0;
9033 else if (dut->station_ifname_5g &&
9034 strcmp(dut->station_ifname_5g, intf) == 0)
9035 dut->use_5g = 1;
9036
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07009037 if (!program)
9038 program = get_param(cmd, "prog");
9039 dut->program = sigma_program_to_enum(program);
Vinita S. Maloof7a2cbf2020-11-18 19:29:44 +05309040
9041 if (dut->program == PROGRAM_WFD && dut->user_config_timeout)
9042 dut->default_timeout = dut->user_config_timeout;
9043
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009044 dut->device_type = STA_unknown;
9045 type = get_param(cmd, "type");
9046 if (type && strcasecmp(type, "Testbed") == 0)
9047 dut->device_type = STA_testbed;
9048 if (type && strcasecmp(type, "DUT") == 0)
9049 dut->device_type = STA_dut;
9050
9051 if (dut->program == PROGRAM_TDLS) {
9052 /* Clear TDLS testing mode */
9053 wpa_command(intf, "SET tdls_disabled 0");
9054 wpa_command(intf, "SET tdls_testing 0");
9055 dut->no_tpk_expiration = 0;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009056 if (get_driver_type(dut) == DRIVER_WCN) {
Pradeep Reddy POTTETI8ce2a232016-10-28 12:17:32 +05309057 /* Enable the WCN driver in TDLS Explicit trigger mode
9058 */
9059 wpa_command(intf, "SET tdls_external_control 0");
9060 wpa_command(intf, "SET tdls_trigger_control 0");
9061 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009062 }
9063
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07009064#ifdef MIRACAST
9065 if (dut->program == PROGRAM_WFD ||
9066 dut->program == PROGRAM_DISPLAYR2)
9067 miracast_sta_reset_default(dut, conn, cmd);
9068#endif /* MIRACAST */
9069
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009070 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009071 case DRIVER_ATHEROS:
9072 sta_reset_default_ath(dut, intf, type);
9073 break;
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08009074 case DRIVER_WCN:
9075 sta_reset_default_wcn(dut, intf, type);
9076 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009077 default:
9078 break;
9079 }
9080
9081#ifdef ANDROID_NAN
9082 if (dut->program == PROGRAM_NAN)
9083 nan_cmd_sta_reset_default(dut, conn, cmd);
9084#endif /* ANDROID_NAN */
9085
Vinay Gannevaram3b9fdd32019-06-14 17:55:44 +05309086 if (dut->program == PROGRAM_LOC &&
9087 lowi_cmd_sta_reset_default(dut, conn, cmd) < 0)
9088 return ERROR_SEND_STATUS;
9089
Jouni Malinenba630452018-06-22 11:49:59 +03009090 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009091 unlink("SP/wi-fi.org/pps.xml");
9092 if (system("rm -r SP/*") != 0) {
9093 }
9094 unlink("next-client-cert.pem");
9095 unlink("next-client-key.pem");
9096 }
9097
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02009098 /* For WPS program of the 60 GHz band the band type needs to be saved */
9099 if (dut->program == PROGRAM_WPS) {
9100 if (band && strcasecmp(band, "60GHz") == 0) {
9101 dut->band = WPS_BAND_60G;
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02009102 /* For 60 GHz enable WPS for WPS TCs */
9103 dut->wps_disable = 0;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02009104 } else {
9105 dut->band = WPS_BAND_NON_60G;
9106 }
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02009107 } else if (dut->program == PROGRAM_60GHZ) {
9108 /* For 60 GHz MAC/PHY TCs WPS must be disabled */
9109 dut->wps_disable = 1;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02009110 }
9111
Alexei Avshalom Lazar157ba062018-12-23 16:15:26 +02009112 if (is_60g_sigma_dut(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009113 const char *dev_role = get_param(cmd, "DevRole");
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02009114 char buf[256];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009115
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02009116 sigma_dut_print(dut, DUT_MSG_INFO,
9117 "WPS 60 GHz program, wps_disable = %d",
9118 dut->wps_disable);
9119
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009120 if (!dev_role) {
9121 send_resp(dut, conn, SIGMA_ERROR,
9122 "errorCode,Missing DevRole argument");
9123 return 0;
9124 }
9125
9126 if (strcasecmp(dev_role, "STA") == 0)
9127 dut->dev_role = DEVROLE_STA;
9128 else if (strcasecmp(dev_role, "PCP") == 0)
9129 dut->dev_role = DEVROLE_PCP;
9130 else {
9131 send_resp(dut, conn, SIGMA_ERROR,
9132 "errorCode,Unknown DevRole");
9133 return 0;
9134 }
9135
9136 if (dut->device_type == STA_unknown) {
9137 sigma_dut_print(dut, DUT_MSG_ERROR,
9138 "Device type is not STA testbed or DUT");
9139 send_resp(dut, conn, SIGMA_ERROR,
9140 "errorCode,Unknown device type");
9141 return 0;
9142 }
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02009143
9144 sigma_dut_print(dut, DUT_MSG_DEBUG,
9145 "Setting msdu_size to MAX: 7912");
9146 snprintf(buf, sizeof(buf), "ifconfig %s mtu 7912",
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009147 get_station_ifname(dut));
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02009148
9149 if (system(buf) != 0) {
9150 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
9151 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02009152 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02009153 }
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02009154
9155 if (sta_set_force_mcs(dut, 0, 1)) {
9156 sigma_dut_print(dut, DUT_MSG_ERROR,
9157 "Failed to reset force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02009158 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02009159 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009160 }
9161
9162 wpa_command(intf, "WPS_ER_STOP");
9163 wpa_command(intf, "FLUSH");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05309164 wpa_command(intf, "ERP_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009165 wpa_command(intf, "SET radio_disabled 0");
9166
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02009167 dut->wps_forced_version = 0;
9168
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02009169 if (dut->wsc_fragment) {
9170 dut->wsc_fragment = 0;
9171 wpa_command(intf, "SET device_name Test client");
9172 wpa_command(intf, "SET manufacturer ");
9173 wpa_command(intf, "SET model_name ");
9174 wpa_command(intf, "SET model_number ");
9175 wpa_command(intf, "SET serial_number ");
9176 }
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02009177 if (is_60g_sigma_dut(dut) && dut->force_rsn_ie) {
9178 dut->force_rsn_ie = FORCE_RSN_IE_NONE;
9179 sta_60g_force_rsn_ie(dut, FORCE_RSN_IE_NONE);
9180 }
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02009181
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009182 if (dut->tmp_mac_addr && dut->set_macaddr) {
9183 dut->tmp_mac_addr = 0;
9184 if (system(dut->set_macaddr) != 0) {
9185 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to clear "
9186 "temporary MAC address");
9187 }
9188 }
9189
9190 set_ps(intf, dut, 0);
9191
Jouni Malinenba630452018-06-22 11:49:59 +03009192 if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2 ||
9193 dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009194 wpa_command(intf, "SET interworking 1");
9195 wpa_command(intf, "SET hs20 1");
9196 }
9197
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08009198 if (dut->program == PROGRAM_HS2_R2 ||
Jouni Malinenba630452018-06-22 11:49:59 +03009199 dut->program == PROGRAM_HS2_R3 ||
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08009200 dut->program == PROGRAM_OCE) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009201 wpa_command(intf, "SET pmf 1");
9202 } else {
9203 wpa_command(intf, "SET pmf 0");
9204 }
9205
9206 hs2_clear_credentials(intf);
9207 wpa_command(intf, "SET hessid 00:00:00:00:00:00");
9208 wpa_command(intf, "SET access_network_type 15");
9209
9210 static_ip_file(0, NULL, NULL, NULL);
9211 kill_dhcp_client(dut, intf);
9212 clear_ip_addr(dut, intf);
9213
9214 dut->er_oper_performed = 0;
9215 dut->er_oper_bssid[0] = '\0';
9216
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07009217 if (dut->program == PROGRAM_LOC) {
9218 /* Disable Interworking by default */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009219 wpa_command(get_station_ifname(dut), "SET interworking 0");
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07009220 }
9221
Kiran Kumar Lokeredd086642020-06-04 00:29:26 -07009222 if (dut->program == PROGRAM_MBO || dut->program == PROGRAM_HE) {
Ashwini Patil00402582017-04-13 12:29:39 +05309223 free(dut->non_pref_ch_list);
9224 dut->non_pref_ch_list = NULL;
Ashwini Patil5acd7382017-04-13 15:55:04 +05309225 free(dut->btm_query_cand_list);
9226 dut->btm_query_cand_list = NULL;
Ashwini Patilc63161e2017-04-13 16:30:23 +05309227 wpa_command(intf, "SET reject_btm_req_reason 0");
Ashwini Patila75de5a2017-04-13 16:35:05 +05309228 wpa_command(intf, "SET ignore_assoc_disallow 0");
Ashwini Patild174f2c2017-04-13 16:49:46 +05309229 wpa_command(intf, "SET gas_address3 0");
Ashwini Patil9183fdb2017-04-13 16:58:25 +05309230 wpa_command(intf, "SET roaming 1");
Ankita Bajaj1d974552018-09-18 16:56:44 +05309231 wpa_command(intf, "SET interworking 1");
Ashwini Patil00402582017-04-13 12:29:39 +05309232 }
9233
Jouni Malinen3c367e82017-06-23 17:01:47 +03009234 free(dut->rsne_override);
9235 dut->rsne_override = NULL;
9236
Jouni Malinen68143132017-09-02 02:34:08 +03009237 free(dut->sae_commit_override);
9238 dut->sae_commit_override = NULL;
Jouni Malinen4b3769d2019-10-10 16:20:29 +03009239 wpa_command(intf, "SET sae_pmkid_in_assoc 0");
Jouni Malinen11e55212019-11-22 21:46:59 +02009240 dut->sae_pwe = SAE_PWE_DEFAULT;
Jouni Malinen68143132017-09-02 02:34:08 +03009241
Jouni Malinen134fe3c2019-06-12 04:16:49 +03009242 dut->sta_associate_wait_connect = 0;
9243 dut->server_cert_hash[0] = '\0';
Jouni Malinen37d5c692019-08-19 16:56:55 +03009244 dut->server_cert_tod = 0;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03009245 dut->sta_tod_policy = 0;
9246
Jouni Malinend86e5822017-08-29 03:55:32 +03009247 dut->dpp_conf_id = -1;
Jouni Malinenb1dd21f2017-11-13 19:14:29 +02009248 free(dut->dpp_peer_uri);
9249 dut->dpp_peer_uri = NULL;
Jouni Malinen63d50412017-11-24 11:55:38 +02009250 dut->dpp_local_bootstrap = -1;
Jouni Malinen5011fb52017-12-05 21:00:15 +02009251 wpa_command(intf, "SET dpp_config_processing 2");
Jouni Malinen90776b12020-05-04 15:34:46 +03009252 wpa_command(intf, "SET dpp_mud_url ");
Jouni Malinend86e5822017-08-29 03:55:32 +03009253
Jouni Malinenfac9cad2017-10-10 18:35:55 +03009254 wpa_command(intf, "VENDOR_ELEM_REMOVE 13 *");
9255
vamsi krishnaa2799492017-12-05 14:28:01 +05309256 if (dut->program == PROGRAM_OCE) {
Ankita Bajaja2cb5672017-10-25 16:08:28 +05309257 wpa_command(intf, "SET oce 1");
vamsi krishnaa2799492017-12-05 14:28:01 +05309258 wpa_command(intf, "SET disable_fils 0");
Ankita Bajaj1bde7942018-01-09 19:15:01 +05309259 wpa_command(intf, "FILS_HLP_REQ_FLUSH");
9260 dut->fils_hlp = 0;
9261#ifdef ANDROID
9262 hlp_thread_cleanup(dut);
9263#endif /* ANDROID */
vamsi krishnaa2799492017-12-05 14:28:01 +05309264 }
Ankita Bajaja2cb5672017-10-25 16:08:28 +05309265
Veerendranath Jakkamea7f0692021-08-11 19:13:12 +05309266 if (dut->program == PROGRAM_QM) {
Vamsi Krishnaf642d6a2020-03-27 12:33:14 +05309267 wpa_command(intf, "SET interworking 1");
Veerendranath Jakkama16cdc82021-09-12 16:44:22 +05309268 wpa_command(intf, "SET enable_dscp_policy_capa 1");
Veerendranath Jakkam329a3cd2021-09-11 18:10:13 +05309269 dut->qm_domain_name[0] = '\0';
Veerendranath Jakkama16cdc82021-09-12 16:44:22 +05309270 dut->reject_dscp_policies = 0;
Veerendranath Jakkam1bf1bd62021-09-12 16:35:55 +05309271 dut->num_dscp_status = 0;
Veerendranath Jakkamea7f0692021-08-11 19:13:12 +05309272 snprintf(buf, sizeof(buf),
9273 "ip -6 route replace fe80::/64 dev %s table local",
9274 intf);
9275 if (system(buf) != 0)
9276 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run: %s",
9277 buf);
Veerendranath Jakkam9ceb3b12021-09-10 03:18:17 +05309278
9279 stop_dscp_policy_mon_thread(dut);
9280 clear_all_dscp_policies(dut);
Veerendranath Jakkamea7f0692021-08-11 19:13:12 +05309281 }
Vamsi Krishnaf642d6a2020-03-27 12:33:14 +05309282
Jouni Malinen8179fee2019-03-28 03:19:47 +02009283 dut->akm_values = 0;
Shivani Baranwal7aa48602021-09-29 10:53:38 +05309284
9285#ifdef NL80211_SUPPORT
9286 if (get_driver_type(dut) == DRIVER_WCN)
9287 sta_config_params(dut, intf, STA_SET_FT_DS, 0);
9288#endif /* NL80211_SUPPORT */
9289
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03009290 dut->sta_ft_ds = 0;
Jouni Malinen8179fee2019-03-28 03:19:47 +02009291
Sunil Dutt076081f2018-02-05 19:45:50 +05309292#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009293 if (get_driver_type(dut) == DRIVER_WCN &&
Sunil Dutt44595082018-02-12 19:41:45 +05309294 dut->config_rsnie == 1) {
9295 dut->config_rsnie = 0;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05309296 sta_config_params(dut, intf, STA_SET_RSNIE, 0);
Sunil Dutt076081f2018-02-05 19:45:50 +05309297 }
9298#endif /* NL80211_SUPPORT */
9299
Sunil Duttfebf8a82018-02-09 18:50:13 +05309300 if (dev_role && strcasecmp(dev_role, "STA-CFON") == 0) {
9301 dut->dev_role = DEVROLE_STA_CFON;
9302 return sta_cfon_reset_default(dut, conn, cmd);
9303 }
9304
Jouni Malinen439352d2018-09-13 03:42:23 +03009305 wpa_command(intf, "SET setband AUTO");
9306
Veerendranath Jakkamc1f71b62021-01-23 03:09:51 +05309307 ret = wpa_command_resp(intf, "GET_CAPABILITY ocv", resp, sizeof(resp));
9308 dut->ocvc = ret == 0 && strncmp(resp, "supported", 9) == 0;
9309
9310 ret = wpa_command_resp(intf, "GET_CAPABILITY beacon_prot", resp,
9311 sizeof(resp));
9312 dut->beacon_prot = ret == 0 && strncmp(resp, "supported", 9) == 0;
9313
Veerendranath Jakkam47867202020-12-21 01:53:52 +05309314 if (sta_set_client_privacy(dut, conn, intf,
9315 dut->program == PROGRAM_WPA3 &&
9316 dut->device_type == STA_dut &&
9317 dut->client_privacy_default)) {
9318 sigma_dut_print(dut, DUT_MSG_ERROR,
9319 "Failed to set client privacy functionality");
9320 /* sta_reset_default command is not really supposed to fail,
9321 * so allow this to continue. */
9322 }
9323
Veerendranath Jakkamca239592021-10-11 20:48:00 +05309324 if (get_driver_type(dut) == DRIVER_WCN)
9325 wcn_set_ignore_h2e_rsnxe(dut, intf, 0);
9326
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +05309327 dut->saquery_oci_freq = 0;
Shivani Baranwalebde8f62021-10-19 12:26:02 +05309328 dut->prev_disable_scs_support = 0;
9329 dut->prev_disable_mscs_support = 0;
Vamsi Krishnac1633d22020-05-06 18:31:21 +05309330
Sunil Duttfebf8a82018-02-09 18:50:13 +05309331 if (dut->program != PROGRAM_VHT)
9332 return cmd_sta_p2p_reset(dut, conn, cmd);
9333
Priyadharshini Gowthamana7dfd492015-11-09 14:34:08 -08009334 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009335}
9336
9337
Jouni Malinenf7222712019-06-13 01:50:21 +03009338static enum sigma_cmd_result cmd_sta_get_events(struct sigma_dut *dut,
9339 struct sigma_conn *conn,
9340 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009341{
9342 const char *program = get_param(cmd, "Program");
9343
9344 if (program == NULL)
9345 return -1;
9346#ifdef ANDROID_NAN
9347 if (strcasecmp(program, "NAN") == 0)
9348 return nan_cmd_sta_get_events(dut, conn, cmd);
9349#endif /* ANDROID_NAN */
9350 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
9351 return 0;
9352}
9353
9354
Jouni Malinen82905202018-04-29 17:20:10 +03009355static int sta_exec_action_url(struct sigma_dut *dut, struct sigma_conn *conn,
9356 struct sigma_cmd *cmd)
9357{
9358 const char *url = get_param(cmd, "url");
9359 const char *method = get_param(cmd, "method");
9360 pid_t pid;
9361 int status;
9362
9363 if (!url || !method)
9364 return -1;
9365
9366 /* TODO: Add support for method,post */
9367 if (strcasecmp(method, "get") != 0) {
9368 send_resp(dut, conn, SIGMA_ERROR,
9369 "ErrorCode,Unsupported method");
9370 return 0;
9371 }
9372
9373 pid = fork();
9374 if (pid < 0) {
9375 perror("fork");
9376 return -1;
9377 }
9378
9379 if (pid == 0) {
9380 char * argv[5] = { "wget", "-O", "/dev/null",
9381 (char *) url, NULL };
9382
9383 execv("/usr/bin/wget", argv);
9384 perror("execv");
9385 exit(0);
9386 return -1;
9387 }
9388
9389 if (waitpid(pid, &status, 0) < 0) {
9390 perror("waitpid");
9391 return -1;
9392 }
9393
9394 if (WIFEXITED(status)) {
9395 const char *errmsg;
9396
9397 if (WEXITSTATUS(status) == 0)
9398 return 1;
9399 sigma_dut_print(dut, DUT_MSG_INFO, "wget exit status %d",
9400 WEXITSTATUS(status));
9401 switch (WEXITSTATUS(status)) {
9402 case 4:
9403 errmsg = "errmsg,Network failure";
9404 break;
9405 case 8:
9406 errmsg = "errmsg,Server issued an error response";
9407 break;
9408 default:
9409 errmsg = "errmsg,Unknown failure from wget";
9410 break;
9411 }
9412 send_resp(dut, conn, SIGMA_ERROR, errmsg);
9413 return 0;
9414 }
9415
9416 send_resp(dut, conn, SIGMA_ERROR, "errmsg,Unknown failure");
9417 return 0;
9418}
9419
9420
Jouni Malinenf7222712019-06-13 01:50:21 +03009421static enum sigma_cmd_result cmd_sta_exec_action(struct sigma_dut *dut,
9422 struct sigma_conn *conn,
9423 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009424{
9425 const char *program = get_param(cmd, "Prog");
9426
Jouni Malinen82905202018-04-29 17:20:10 +03009427 if (program && !get_param(cmd, "interface"))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009428 return -1;
9429#ifdef ANDROID_NAN
Jouni Malinen82905202018-04-29 17:20:10 +03009430 if (program && strcasecmp(program, "NAN") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009431 return nan_cmd_sta_exec_action(dut, conn, cmd);
9432#endif /* ANDROID_NAN */
Jouni Malinen82905202018-04-29 17:20:10 +03009433
9434 if (program && strcasecmp(program, "Loc") == 0)
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07009435 return loc_cmd_sta_exec_action(dut, conn, cmd);
Jouni Malinen82905202018-04-29 17:20:10 +03009436
9437 if (get_param(cmd, "url"))
9438 return sta_exec_action_url(dut, conn, cmd);
9439
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009440 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
9441 return 0;
9442}
9443
9444
Jouni Malinenf7222712019-06-13 01:50:21 +03009445static enum sigma_cmd_result cmd_sta_set_11n(struct sigma_dut *dut,
9446 struct sigma_conn *conn,
9447 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009448{
9449 const char *intf = get_param(cmd, "Interface");
9450 const char *val, *mcs32, *rate;
9451
9452 val = get_param(cmd, "GREENFIELD");
9453 if (val) {
9454 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
9455 /* Enable GD */
9456 send_resp(dut, conn, SIGMA_ERROR,
9457 "ErrorCode,GF not supported");
9458 return 0;
9459 }
9460 }
9461
9462 val = get_param(cmd, "SGI20");
9463 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009464 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009465 case DRIVER_ATHEROS:
9466 ath_sta_set_sgi(dut, intf, val);
9467 break;
9468 default:
9469 send_resp(dut, conn, SIGMA_ERROR,
9470 "ErrorCode,SGI20 not supported");
9471 return 0;
9472 }
9473 }
9474
9475 mcs32 = get_param(cmd, "MCS32"); /* HT Duplicate Mode Enable/Disable */
9476 rate = get_param(cmd, "MCS_FIXEDRATE"); /* Fixed MCS rate (0..31) */
9477 if (mcs32 && rate) {
9478 /* TODO */
9479 send_resp(dut, conn, SIGMA_ERROR,
9480 "ErrorCode,MCS32,MCS_FIXEDRATE not supported");
9481 return 0;
9482 } else if (mcs32 && !rate) {
9483 /* TODO */
9484 send_resp(dut, conn, SIGMA_ERROR,
9485 "ErrorCode,MCS32 not supported");
9486 return 0;
9487 } else if (!mcs32 && rate) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009488 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009489 case DRIVER_ATHEROS:
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07009490 novap_reset(dut, intf, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009491 ath_sta_set_11nrates(dut, intf, rate);
9492 break;
9493 default:
9494 send_resp(dut, conn, SIGMA_ERROR,
9495 "ErrorCode,MCS32_FIXEDRATE not supported");
9496 return 0;
9497 }
9498 }
9499
9500 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
9501}
9502
9503
Arif Hussain7b47d2d2018-05-09 10:44:02 -07009504static void cmd_set_max_he_mcs(struct sigma_dut *dut, const char *intf,
9505 int mcs_config)
9506{
9507#ifdef NL80211_SUPPORT
9508 int ret;
9509
9510 switch (mcs_config) {
9511 case HE_80_MCS0_7:
9512 case HE_80_MCS0_9:
9513 case HE_80_MCS0_11:
9514 ret = sta_set_he_mcs(dut, intf, mcs_config);
9515 if (ret) {
9516 sigma_dut_print(dut, DUT_MSG_ERROR,
9517 "cmd_set_max_he_mcs: Setting of MCS:%d failed, ret:%d",
9518 mcs_config, ret);
9519 }
9520 break;
9521 default:
9522 sigma_dut_print(dut, DUT_MSG_ERROR,
9523 "cmd_set_max_he_mcs: Invalid mcs %d",
9524 mcs_config);
9525 break;
9526 }
9527#else /* NL80211_SUPPORT */
9528 sigma_dut_print(dut, DUT_MSG_ERROR,
9529 "max HE MCS cannot be changed without NL80211_SUPPORT defined");
9530#endif /* NL80211_SUPPORT */
9531}
9532
9533
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07009534struct wait_event {
9535 struct sigma_dut *dut;
9536 int cmd;
9537 unsigned int twt_op;
9538};
9539
9540#ifdef NL80211_SUPPORT
9541
9542static int twt_event_handler(struct nl_msg *msg, void *arg)
9543{
9544 struct wait_event *wait = arg;
9545 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
9546 struct nlattr *tb[NL80211_ATTR_MAX + 1];
9547 uint32_t subcmd;
9548 uint8_t *data = NULL;
9549 size_t len = 0;
9550 struct nlattr *twt_rsp[QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_MAX + 1];
9551 struct nlattr *twt_status[QCA_WLAN_VENDOR_ATTR_TWT_SETUP_MAX + 1];
9552 int cmd_id;
9553 unsigned char val;
9554
9555 if (!wait)
9556 return NL_SKIP;
9557
9558 if (gnlh->cmd != NL80211_CMD_VENDOR) {
9559 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9560 "%s: NL cmd is not vendor %d", __func__,
9561 gnlh->cmd);
9562 return NL_SKIP;
9563 }
9564
9565 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
9566 genlmsg_attrlen(gnlh, 0), NULL);
9567
9568 if (!tb[NL80211_ATTR_VENDOR_ID] || !tb[NL80211_ATTR_VENDOR_SUBCMD]) {
9569 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9570 "%s: vendor ID not found", __func__);
9571 return NL_SKIP;
9572 }
9573 subcmd = nla_get_u32(tb[NL80211_ATTR_VENDOR_SUBCMD]);
9574
9575 if (subcmd != QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) {
9576 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9577 "%s: Not a TWT_cmd %d", __func__, subcmd);
9578 return NL_SKIP;
9579 }
9580 if (tb[NL80211_ATTR_VENDOR_DATA]) {
9581 data = nla_data(tb[NL80211_ATTR_VENDOR_DATA]);
9582 len = nla_len(tb[NL80211_ATTR_VENDOR_DATA]);
9583 } else {
9584 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9585 "%s: vendor data not present", __func__);
9586 return NL_SKIP;
9587 }
9588 if (!data || !len) {
9589 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9590 "Invalid vendor data or len");
9591 return NL_SKIP;
9592 }
9593 sigma_dut_print(wait->dut, DUT_MSG_DEBUG,
9594 "event data len %ld", len);
9595 hex_dump(wait->dut, data, len);
9596 if (nla_parse(twt_rsp, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_MAX,
9597 (struct nlattr *) data, len, NULL)) {
9598 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9599 "vendor data parse error");
9600 return NL_SKIP;
9601 }
9602
9603 val = nla_get_u8(twt_rsp[QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION]);
9604 if (val != wait->twt_op) {
9605 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9606 "Invalid TWT operation, expected %d, rcvd %d",
9607 wait->twt_op, val);
9608 return NL_SKIP;
9609 }
9610 if (nla_parse_nested(twt_status, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_MAX,
9611 twt_rsp[QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS],
9612 NULL)) {
9613 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9614 "nla_parse failed for TWT event");
9615 return NL_SKIP;
9616 }
9617
9618 cmd_id = QCA_WLAN_VENDOR_ATTR_TWT_SETUP_STATUS;
9619 if (!twt_status[cmd_id]) {
9620 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9621 "%s TWT resp status missing", __func__);
9622 wait->cmd = -1;
9623 } else {
9624 val = nla_get_u8(twt_status[cmd_id]);
9625 if (val != QCA_WLAN_VENDOR_TWT_STATUS_OK) {
9626 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9627 "%s TWT resp status %d", __func__, val);
9628 wait->cmd = -1;
9629 } else {
9630 wait->cmd = 1;
9631 }
9632 }
9633
9634 return NL_SKIP;
9635}
9636
9637
9638static int wait_on_nl_socket(struct nl_sock *sock, struct sigma_dut *dut,
9639 unsigned int timeout)
9640{
9641 fd_set read_fd_set;
9642 int retval;
9643 int sock_fd;
9644 struct timeval time_out;
9645
9646 time_out.tv_sec = timeout;
9647 time_out.tv_usec = 0;
9648
9649 FD_ZERO(&read_fd_set);
9650
9651 if (!sock)
9652 return -1;
9653
9654 sock_fd = nl_socket_get_fd(sock);
9655 FD_SET(sock_fd, &read_fd_set);
9656
9657 retval = select(sock_fd + 1, &read_fd_set, NULL, NULL, &time_out);
9658
9659 if (retval == 0)
9660 sigma_dut_print(dut, DUT_MSG_ERROR,
9661 "%s: TWT event response timedout", __func__);
9662
9663 if (retval < 0)
9664 sigma_dut_print(dut, DUT_MSG_ERROR, "%s:no NL msgs, ret=%d",
9665 __func__, retval);
9666
9667 return retval;
9668}
9669
9670
9671#define TWT_ASYNC_EVENT_WAIT_TIME_SEC 6
9672
9673static int twt_async_event_wait(struct sigma_dut *dut, unsigned int twt_op)
9674{
9675 struct nl_cb *cb;
9676 int err_code = 0, select_retval = 0;
9677 struct wait_event wait_info;
9678
9679 cb = nl_socket_get_cb(dut->nl_ctx->event_sock);
9680 if (!cb) {
9681 sigma_dut_print(dut, DUT_MSG_ERROR,
9682 "event callback not found");
9683 return ERROR_SEND_STATUS;
9684 }
9685
9686 wait_info.cmd = 0;
9687 wait_info.dut = dut;
9688 wait_info.twt_op = twt_op;
9689
9690 nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, twt_event_handler, &wait_info);
9691
9692 while (!wait_info.cmd) {
9693 select_retval = wait_on_nl_socket(
9694 dut->nl_ctx->event_sock, dut,
9695 TWT_ASYNC_EVENT_WAIT_TIME_SEC);
9696
9697 if (select_retval > 0) {
9698 err_code = nl_recvmsgs(dut->nl_ctx->event_sock, cb);
9699 if (err_code < 0) {
9700 sigma_dut_print(dut, DUT_MSG_ERROR,
9701 "%s: nl rcv failed, err_code %d",
9702 __func__, err_code);
9703 break;
9704 }
9705 } else {
9706 sigma_dut_print(dut, DUT_MSG_ERROR,
9707 "%s: wait on socket failed %d",
9708 __func__, select_retval);
9709 err_code = 1;
9710 break;
9711 }
9712
9713 }
9714 nl_cb_put(cb);
9715
9716 if (wait_info.cmd < 0)
9717 err_code = 1;
9718
9719 sigma_dut_print(dut, DUT_MSG_DEBUG,
9720 "%s: rcvd cmd %d, err_code %d, s_ret %d",
9721 __func__, wait_info.cmd, err_code, select_retval);
9722
9723 return err_code;
9724}
9725
9726#endif /* NL80211_SUPPORT */
9727
9728
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009729static int sta_twt_send_suspend(struct sigma_dut *dut, struct sigma_conn *conn,
9730 struct sigma_cmd *cmd)
9731{
9732#ifdef NL80211_SUPPORT
9733 struct nlattr *attr, *attr1;
9734 struct nl_msg *msg;
9735 int ifindex, ret;
9736 const char *intf = get_param(cmd, "Interface");
9737
9738 ifindex = if_nametoindex(intf);
9739 if (ifindex == 0) {
9740 sigma_dut_print(dut, DUT_MSG_ERROR,
9741 "%s: Index for interface %s failed",
9742 __func__, intf);
9743 return ERROR_SEND_STATUS;
9744 }
9745
9746 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9747 NL80211_CMD_VENDOR)) ||
9748 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9749 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9750 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9751 QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) ||
9752 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9753 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION,
9754 QCA_WLAN_TWT_SUSPEND) ||
9755 !(attr1 = nla_nest_start(msg,
Kiran Kumar Lokere7ede00c2021-08-09 00:59:52 -07009756 QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS))) {
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009757 sigma_dut_print(dut, DUT_MSG_ERROR,
9758 "%s: err in adding vendor_cmd and vendor_data",
9759 __func__);
9760 nlmsg_free(msg);
9761 return ERROR_SEND_STATUS;
9762 }
9763 nla_nest_end(msg, attr1);
9764 nla_nest_end(msg, attr);
9765
9766 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9767 if (ret) {
9768 sigma_dut_print(dut, DUT_MSG_ERROR,
9769 "%s: err in send_and_recv_msgs, ret=%d",
9770 __func__, ret);
9771 }
9772
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07009773 if (!dut->sta_async_twt_supp)
9774 return ret;
9775
9776 return twt_async_event_wait(dut, QCA_WLAN_TWT_SUSPEND);
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009777#else /* NL80211_SUPPORT */
9778 sigma_dut_print(dut, DUT_MSG_ERROR,
9779 "TWT suspend cannot be done without NL80211_SUPPORT defined");
9780 return ERROR_SEND_STATUS;
9781#endif /* NL80211_SUPPORT */
9782}
9783
9784
9785static int sta_twt_send_nudge(struct sigma_dut *dut, struct sigma_conn *conn,
9786 struct sigma_cmd *cmd,
9787 unsigned int suspend_duration)
9788{
9789#ifdef NL80211_SUPPORT
9790 struct nlattr *attr, *attr1;
9791 struct nl_msg *msg;
9792 int ifindex, ret;
9793 const char *intf = get_param(cmd, "Interface");
9794 int next_twt_size = 1;
9795
9796 ifindex = if_nametoindex(intf);
9797 if (ifindex == 0) {
9798 sigma_dut_print(dut, DUT_MSG_ERROR,
9799 "%s: Index for interface %s failed",
9800 __func__, intf);
9801 return ERROR_SEND_STATUS;
9802 }
9803
9804 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9805 NL80211_CMD_VENDOR)) ||
9806 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9807 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9808 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9809 QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) ||
9810 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9811 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION,
9812 QCA_WLAN_TWT_NUDGE) ||
9813 !(attr1 = nla_nest_start(msg,
9814 QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS)) ||
9815 (suspend_duration &&
9816 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_NUDGE_WAKE_TIME,
9817 suspend_duration)) ||
9818 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_NUDGE_NEXT_TWT_SIZE,
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -07009819 next_twt_size) ||
9820 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_NUDGE_FLOW_ID, 0)) {
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009821 sigma_dut_print(dut, DUT_MSG_ERROR,
9822 "%s: err in adding vendor_cmd and vendor_data",
9823 __func__);
9824 nlmsg_free(msg);
9825 return ERROR_SEND_STATUS;
9826 }
9827 nla_nest_end(msg, attr1);
9828 nla_nest_end(msg, attr);
9829
9830 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9831 if (ret) {
9832 sigma_dut_print(dut, DUT_MSG_ERROR,
9833 "%s: err in send_and_recv_msgs, ret=%d",
9834 __func__, ret);
9835 }
9836
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07009837 if (!dut->sta_async_twt_supp)
9838 return ret;
9839
9840 return twt_async_event_wait(dut, QCA_WLAN_TWT_NUDGE);
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009841#else /* NL80211_SUPPORT */
9842 sigma_dut_print(dut, DUT_MSG_ERROR,
9843 "TWT suspend cannot be done without NL80211_SUPPORT defined");
9844 return ERROR_SEND_STATUS;
9845#endif /* NL80211_SUPPORT */
9846}
9847
9848
9849static int sta_twt_suspend_or_nudge(struct sigma_dut *dut,
9850 struct sigma_conn *conn,
9851 struct sigma_cmd *cmd)
9852{
9853 const char *val;
9854
9855 val = get_param(cmd, "TWT_SuspendDuration");
9856 if (val) {
9857 unsigned int suspend_duration;
9858
9859 suspend_duration = atoi(val);
9860 suspend_duration = suspend_duration * 1000 * 1000;
9861 return sta_twt_send_nudge(dut, conn, cmd, suspend_duration);
9862 }
9863
9864 return sta_twt_send_suspend(dut, conn, cmd);
9865}
9866
9867
9868static int sta_twt_resume(struct sigma_dut *dut, struct sigma_conn *conn,
9869 struct sigma_cmd *cmd)
9870{
9871#ifdef NL80211_SUPPORT
9872 struct nlattr *attr, *attr1;
9873 struct nl_msg *msg;
9874 int ifindex, ret;
9875 const char *intf = get_param(cmd, "Interface");
9876 int next2_twt_size = 1;
9877 unsigned int resume_duration = 0;
9878 const char *val;
9879
9880 ifindex = if_nametoindex(intf);
9881 if (ifindex == 0) {
9882 sigma_dut_print(dut, DUT_MSG_ERROR,
9883 "%s: Index for interface %s failed",
9884 __func__, intf);
9885 return ERROR_SEND_STATUS;
9886 }
9887
9888 val = get_param(cmd, "TWT_ResumeDuration");
9889 if (val) {
9890 resume_duration = atoi(val);
9891 resume_duration = resume_duration * 1000 * 1000;
9892 }
9893
9894 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9895 NL80211_CMD_VENDOR)) ||
9896 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9897 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9898 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9899 QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) ||
9900 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9901 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION,
9902 QCA_WLAN_TWT_RESUME) ||
9903 !(attr1 = nla_nest_start(msg,
9904 QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS)) ||
9905 (resume_duration &&
9906 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_RESUME_NEXT2_TWT,
9907 resume_duration)) ||
9908 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_RESUME_NEXT_TWT_SIZE,
9909 next2_twt_size)) {
9910 sigma_dut_print(dut, DUT_MSG_ERROR,
9911 "%s: err in adding vendor_cmd and vendor_data",
9912 __func__);
9913 nlmsg_free(msg);
9914 return ERROR_SEND_STATUS;
9915 }
9916 nla_nest_end(msg, attr1);
9917 nla_nest_end(msg, attr);
9918
9919 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9920 if (ret) {
9921 sigma_dut_print(dut, DUT_MSG_ERROR,
9922 "%s: err in send_and_recv_msgs, ret=%d",
9923 __func__, ret);
9924 }
9925
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07009926 if (!dut->sta_async_twt_supp)
9927 return ret;
9928
9929 return twt_async_event_wait(dut, QCA_WLAN_TWT_RESUME);
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009930#else /* NL80211_SUPPORT */
9931 sigma_dut_print(dut, DUT_MSG_ERROR,
9932 "TWT resume cannot be done without NL80211_SUPPORT defined");
9933 return ERROR_SEND_STATUS;
9934#endif /* NL80211_SUPPORT */
9935}
9936
9937
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07009938#define TWT_REQUEST_CMD 0
9939#define TWT_SUGGEST_CMD 1
9940#define TWT_DEMAND_CMD 2
9941
Arif Hussain480d5f42019-03-12 14:40:42 -07009942static int sta_twt_request(struct sigma_dut *dut, struct sigma_conn *conn,
9943 struct sigma_cmd *cmd)
9944{
9945#ifdef NL80211_SUPPORT
9946 struct nlattr *params;
9947 struct nlattr *attr;
Arif Hussain480d5f42019-03-12 14:40:42 -07009948 struct nl_msg *msg;
9949 int ifindex, ret;
9950 const char *val;
9951 const char *intf = get_param(cmd, "Interface");
9952 int wake_interval_exp = 10, nominal_min_wake_dur = 255,
9953 wake_interval_mantissa = 512;
9954 int flow_type = 0, twt_trigger = 0, target_wake_time = 0,
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07009955 protection = 0, cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_SUGGEST;
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -07009956 int bcast_twt = 0;
9957 int bcast_twt_id = 0, bcast_twt_recommdn = 0, bcast_twt_persis = 0;
Arif Hussain480d5f42019-03-12 14:40:42 -07009958
9959 ifindex = if_nametoindex(intf);
9960 if (ifindex == 0) {
9961 sigma_dut_print(dut, DUT_MSG_ERROR,
9962 "%s: Index for interface %s failed",
9963 __func__, intf);
9964 return -1;
9965 }
9966
9967 val = get_param(cmd, "FlowType");
9968 if (val) {
9969 flow_type = atoi(val);
9970 if (flow_type != 0 && flow_type != 1) {
9971 sigma_dut_print(dut, DUT_MSG_ERROR,
9972 "TWT: Invalid FlowType %d", flow_type);
9973 return -1;
9974 }
9975 }
9976
9977 val = get_param(cmd, "TWT_Trigger");
9978 if (val) {
9979 twt_trigger = atoi(val);
9980 if (twt_trigger != 0 && twt_trigger != 1) {
9981 sigma_dut_print(dut, DUT_MSG_ERROR,
9982 "TWT: Invalid TWT_Trigger %d",
9983 twt_trigger);
9984 return -1;
9985 }
9986 }
9987
9988 val = get_param(cmd, "Protection");
9989 if (val) {
9990 protection = atoi(val);
9991 if (protection != 0 && protection != 1) {
9992 sigma_dut_print(dut, DUT_MSG_ERROR,
9993 "TWT: Invalid Protection %d",
9994 protection);
9995 return -1;
9996 }
9997 }
9998
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07009999 val = get_param(cmd, "SetupCommand");
10000 if (val) {
10001 cmd_type = atoi(val);
10002 if (cmd_type == TWT_REQUEST_CMD)
10003 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_REQUEST;
10004 else if (cmd_type == TWT_SUGGEST_CMD)
10005 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_SUGGEST;
10006 else if (cmd_type == TWT_DEMAND_CMD)
10007 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_DEMAND;
10008 else
10009 sigma_dut_print(dut, DUT_MSG_ERROR,
10010 "Default suggest is used for cmd %d",
10011 cmd_type);
10012 }
10013
Arif Hussain480d5f42019-03-12 14:40:42 -070010014 val = get_param(cmd, "TargetWakeTime");
10015 if (val)
10016 target_wake_time = atoi(val);
10017
10018 val = get_param(cmd, "WakeIntervalMantissa");
10019 if (val)
10020 wake_interval_mantissa = atoi(val);
10021
10022 val = get_param(cmd, "WakeIntervalExp");
10023 if (val)
10024 wake_interval_exp = atoi(val);
10025
10026 val = get_param(cmd, "NominalMinWakeDur");
10027 if (val)
10028 nominal_min_wake_dur = atoi(val);
10029
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -070010030 val = get_param(cmd, "BTWT_ID");
10031 if (val) {
10032 bcast_twt_id = atoi(val);
10033 bcast_twt = 1;
10034 }
10035
10036 val = get_param(cmd, "BTWT_Persistence");
10037 if (val) {
10038 bcast_twt_persis = atoi(val);
10039 bcast_twt = 1;
10040 }
10041
10042 val = get_param(cmd, "BTWT_Recommendation");
10043 if (val) {
10044 bcast_twt_recommdn = atoi(val);
10045 bcast_twt = 1;
10046 }
10047
10048 if (bcast_twt)
10049 sigma_dut_print(dut, DUT_MSG_DEBUG,
10050 "BCAST_TWT: ID %d, RECOMM %d, PERSIS %d",
10051 bcast_twt_id, bcast_twt_recommdn,
10052 bcast_twt_persis);
10053
Arif Hussain480d5f42019-03-12 14:40:42 -070010054 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
10055 NL80211_CMD_VENDOR)) ||
10056 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
10057 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
10058 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
Srinivas Girigowda6707f032020-10-26 15:24:46 -070010059 QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) ||
Arif Hussain480d5f42019-03-12 14:40:42 -070010060 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
Srinivas Girigowda6707f032020-10-26 15:24:46 -070010061 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION,
10062 QCA_WLAN_TWT_SET) ||
Arif Hussain480d5f42019-03-12 14:40:42 -070010063 !(params = nla_nest_start(
Srinivas Girigowda6707f032020-10-26 15:24:46 -070010064 msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -070010065 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_EXP,
10066 wake_interval_exp) ||
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -070010067 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_REQ_TYPE, cmd_type) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -070010068 (twt_trigger &&
10069 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_TRIGGER)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -070010070 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE,
10071 flow_type) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -070010072 (protection &&
10073 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_PROTECTION)) ||
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -070010074 (bcast_twt &&
10075 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_BCAST)) ||
10076 (bcast_twt &&
10077 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_BCAST_ID,
10078 bcast_twt_id)) ||
10079 (bcast_twt &&
10080 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_BCAST_PERSISTENCE,
10081 bcast_twt_persis)) ||
10082 (bcast_twt &&
10083 nla_put_u8(msg,
10084 QCA_WLAN_VENDOR_ATTR_TWT_SETUP_BCAST_RECOMMENDATION,
10085 bcast_twt_recommdn)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -070010086 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_TIME,
10087 target_wake_time) ||
10088 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_DURATION,
10089 nominal_min_wake_dur) ||
10090 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_MANTISSA,
10091 wake_interval_mantissa)) {
10092 sigma_dut_print(dut, DUT_MSG_ERROR,
10093 "%s: err in adding vendor_cmd and vendor_data",
10094 __func__);
10095 nlmsg_free(msg);
10096 return -1;
10097 }
Arif Hussain480d5f42019-03-12 14:40:42 -070010098 nla_nest_end(msg, params);
10099 nla_nest_end(msg, attr);
10100
10101 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
10102 if (ret) {
10103 sigma_dut_print(dut, DUT_MSG_ERROR,
10104 "%s: err in send_and_recv_msgs, ret=%d",
10105 __func__, ret);
10106 }
10107
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -070010108 if (!dut->sta_async_twt_supp)
10109 return ret;
10110
10111 return twt_async_event_wait(dut, QCA_WLAN_TWT_SET);
Arif Hussain480d5f42019-03-12 14:40:42 -070010112#else /* NL80211_SUPPORT */
10113 sigma_dut_print(dut, DUT_MSG_ERROR,
10114 "TWT request cannot be done without NL80211_SUPPORT defined");
10115 return -1;
10116#endif /* NL80211_SUPPORT */
10117}
10118
10119
10120static int sta_twt_teardown(struct sigma_dut *dut, struct sigma_conn *conn,
10121 struct sigma_cmd *cmd)
10122{
10123 #ifdef NL80211_SUPPORT
10124 struct nlattr *params;
10125 struct nlattr *attr;
Arif Hussain480d5f42019-03-12 14:40:42 -070010126 int ifindex, ret;
10127 struct nl_msg *msg;
10128 const char *intf = get_param(cmd, "Interface");
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -070010129 int bcast_twt = 0;
10130 int bcast_twt_id = 0;
10131 const char *val;
Arif Hussain480d5f42019-03-12 14:40:42 -070010132
10133 ifindex = if_nametoindex(intf);
10134 if (ifindex == 0) {
10135 sigma_dut_print(dut, DUT_MSG_ERROR,
10136 "%s: Index for interface %s failed",
10137 __func__, intf);
10138 return -1;
10139 }
10140
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -070010141 val = get_param(cmd, "BTWT_ID");
10142 if (val) {
10143 bcast_twt_id = atoi(val);
10144 bcast_twt = 1;
10145 }
10146
Arif Hussain480d5f42019-03-12 14:40:42 -070010147 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
10148 NL80211_CMD_VENDOR)) ||
10149 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
10150 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
10151 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
Srinivas Girigowda6707f032020-10-26 15:24:46 -070010152 QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) ||
Arif Hussain480d5f42019-03-12 14:40:42 -070010153 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
Srinivas Girigowda6707f032020-10-26 15:24:46 -070010154 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION,
10155 QCA_WLAN_TWT_TERMINATE) ||
Arif Hussain480d5f42019-03-12 14:40:42 -070010156 !(params = nla_nest_start(
10157 msg,
Srinivas Girigowda6707f032020-10-26 15:24:46 -070010158 QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS)) ||
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -070010159 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE, 0) ||
10160 (bcast_twt &&
10161 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_BCAST)) ||
10162 (bcast_twt &&
10163 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_BCAST_ID,
10164 bcast_twt_id))) {
Arif Hussain480d5f42019-03-12 14:40:42 -070010165 sigma_dut_print(dut, DUT_MSG_ERROR,
10166 "%s: err in adding vendor_cmd and vendor_data",
10167 __func__);
10168 nlmsg_free(msg);
10169 return -1;
10170 }
Arif Hussain480d5f42019-03-12 14:40:42 -070010171 nla_nest_end(msg, params);
10172 nla_nest_end(msg, attr);
10173
10174 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
10175 if (ret) {
10176 sigma_dut_print(dut, DUT_MSG_ERROR,
10177 "%s: err in send_and_recv_msgs, ret=%d",
10178 __func__, ret);
10179 }
10180
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -070010181 if (!dut->sta_async_twt_supp)
10182 return ret;
10183
10184 return twt_async_event_wait(dut, QCA_WLAN_TWT_TERMINATE);
Arif Hussain480d5f42019-03-12 14:40:42 -070010185#else /* NL80211_SUPPORT */
10186 sigma_dut_print(dut, DUT_MSG_ERROR,
10187 "TWT teardown cannot be done without NL80211_SUPPORT defined");
10188 return -1;
10189#endif /* NL80211_SUPPORT */
10190}
10191
10192
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -080010193static int sta_transmit_omi(struct sigma_dut *dut, struct sigma_conn *conn,
10194 struct sigma_cmd *cmd)
10195{
10196#ifdef NL80211_SUPPORT
10197 struct nlattr *params;
10198 struct nlattr *attr;
10199 struct nlattr *attr1;
10200 struct nl_msg *msg;
10201 int ifindex, ret;
10202 const char *val;
10203 const char *intf = get_param(cmd, "Interface");
10204 uint8_t rx_nss = 0xFF, ch_bw = 0xFF, tx_nsts = 0xFF, ulmu_dis = 0,
10205 ulmu_data_dis = 0;
10206
10207 ifindex = if_nametoindex(intf);
10208 if (ifindex == 0) {
10209 sigma_dut_print(dut, DUT_MSG_ERROR,
10210 "%s: Index for interface %s failed",
10211 __func__, intf);
10212 return -1;
10213 }
10214 val = get_param(cmd, "OMCtrl_RxNSS");
10215 if (val)
10216 rx_nss = atoi(val);
10217
10218 val = get_param(cmd, "OMCtrl_ChnlWidth");
10219 if (val)
10220 ch_bw = atoi(val);
10221
10222 val = get_param(cmd, "OMCtrl_ULMUDisable");
10223 if (val)
10224 ulmu_dis = atoi(val);
10225
10226 val = get_param(cmd, "OMCtrl_TxNSTS");
10227 if (val)
10228 tx_nsts = atoi(val);
10229
10230 val = get_param(cmd, "OMCtrl_ULMUDataDisable");
10231 if (val)
10232 ulmu_data_dis = atoi(val);
10233
10234 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
10235 NL80211_CMD_VENDOR)) ||
10236 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
10237 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
10238 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
10239 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
10240 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
10241 !(params = nla_nest_start(
10242 msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OMI_TX)) ||
10243 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
10244 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_RX_NSS, rx_nss) ||
10245 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_CH_BW, ch_bw) ||
10246 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_TX_NSTS, tx_nsts) ||
10247 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DATA_DISABLE,
10248 ulmu_data_dis) ||
10249 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DISABLE,
10250 ulmu_dis)) {
10251 sigma_dut_print(dut, DUT_MSG_ERROR,
10252 "%s: err in adding vendor_cmd and vendor_data",
10253 __func__);
10254 nlmsg_free(msg);
10255 return -1;
10256 }
10257 nla_nest_end(msg, attr1);
10258 nla_nest_end(msg, params);
10259 nla_nest_end(msg, attr);
10260
10261 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
10262 if (ret) {
10263 sigma_dut_print(dut, DUT_MSG_ERROR,
10264 "%s: err in send_and_recv_msgs, ret=%d",
10265 __func__, ret);
10266 }
10267
10268 return ret;
10269#else /* NL80211_SUPPORT */
10270 sigma_dut_print(dut, DUT_MSG_ERROR,
10271 "OMI TX cannot be processed without NL80211_SUPPORT defined");
10272 return -1;
10273#endif /* NL80211_SUPPORT */
10274}
10275
10276
Jouni Malinen224e3902021-06-09 16:41:27 +030010277static enum sigma_cmd_result
10278cmd_sta_set_wireless_vht(struct sigma_dut *dut, struct sigma_conn *conn,
10279 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010280{
10281 const char *intf = get_param(cmd, "Interface");
10282 const char *val;
Arif Hussaina37e9552018-06-20 17:05:59 -070010283 const char *program;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010284 int tkip = -1;
10285 int wep = -1;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +053010286 int iwpriv_status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010287
Arif Hussaina37e9552018-06-20 17:05:59 -070010288 program = get_param(cmd, "Program");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010289 val = get_param(cmd, "SGI80");
10290 if (val) {
10291 int sgi80;
10292
10293 sgi80 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010294 run_iwpriv(dut, intf, "shortgi %d", sgi80);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010295 }
10296
10297 val = get_param(cmd, "TxBF");
10298 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010299 switch (get_driver_type(dut)) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -070010300 case DRIVER_WCN:
10301 if (sta_set_tx_beamformee(dut, intf, 1)) {
10302 send_resp(dut, conn, SIGMA_ERROR,
10303 "ErrorCode,Failed to set TX beamformee enable");
Jouni Malinen224e3902021-06-09 16:41:27 +030010304 return STATUS_SENT_ERROR;
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -070010305 }
10306 break;
10307 case DRIVER_ATHEROS:
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010308 if (run_iwpriv(dut, intf, "vhtsubfee 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -070010309 send_resp(dut, conn, SIGMA_ERROR,
10310 "ErrorCode,Setting vhtsubfee failed");
Jouni Malinen224e3902021-06-09 16:41:27 +030010311 return STATUS_SENT_ERROR;
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -070010312 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010313 if (run_iwpriv(dut, intf, "vhtsubfer 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -070010314 send_resp(dut, conn, SIGMA_ERROR,
10315 "ErrorCode,Setting vhtsubfer failed");
Jouni Malinen224e3902021-06-09 16:41:27 +030010316 return STATUS_SENT_ERROR;
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -070010317 }
10318 break;
10319 default:
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010320 sigma_dut_print(dut, DUT_MSG_ERROR,
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -070010321 "Unsupported driver type");
10322 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010323 }
10324 }
10325
10326 val = get_param(cmd, "MU_TxBF");
10327 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010328 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010329 case DRIVER_ATHEROS:
10330 ath_sta_set_txsp_stream(dut, intf, "1SS");
10331 ath_sta_set_rxsp_stream(dut, intf, "1SS");
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010332 run_iwpriv(dut, intf, "vhtmubfee 1");
10333 run_iwpriv(dut, intf, "vhtmubfer 1");
Sunil Duttae9e5d12018-06-29 11:50:47 +053010334 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010335 case DRIVER_WCN:
10336 if (wcn_sta_set_sp_stream(dut, intf, "1SS") < 0) {
10337 send_resp(dut, conn, SIGMA_ERROR,
10338 "ErrorCode,Failed to set RX/TXSP_STREAM");
Jouni Malinen224e3902021-06-09 16:41:27 +030010339 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010340 }
Sunil Duttae9e5d12018-06-29 11:50:47 +053010341 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010342 default:
10343 sigma_dut_print(dut, DUT_MSG_ERROR,
10344 "Setting SP_STREAM not supported");
10345 break;
10346 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010347 }
10348
10349 val = get_param(cmd, "LDPC");
10350 if (val) {
10351 int ldpc;
10352
10353 ldpc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +053010354 iwpriv_status = run_iwpriv(dut, intf, "ldpc %d", ldpc);
10355 if (iwpriv_status)
10356 sta_config_params(dut, intf, STA_SET_LDPC, ldpc);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010357 }
10358
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -080010359 val = get_param(cmd, "BCC");
10360 if (val) {
10361 int bcc;
10362
10363 bcc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
10364 /* use LDPC iwpriv itself to set bcc coding, bcc coding
10365 * is mutually exclusive to bcc */
Mohammad Asaad Akram50848402020-05-28 14:10:24 +053010366 iwpriv_status = run_iwpriv(dut, intf, "ldpc %d", !bcc);
10367 if (iwpriv_status)
10368 sta_config_params(dut, intf, STA_SET_LDPC, !bcc);
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -080010369 }
10370
Arif Hussain7b47d2d2018-05-09 10:44:02 -070010371 val = get_param(cmd, "MaxHE-MCS_1SS_RxMapLTE80");
10372 if (val && dut->sta_nss == 1)
10373 cmd_set_max_he_mcs(dut, intf, atoi(val));
10374
10375 val = get_param(cmd, "MaxHE-MCS_2SS_RxMapLTE80");
10376 if (val && dut->sta_nss == 2)
10377 cmd_set_max_he_mcs(dut, intf, atoi(val));
10378
Arif Hussainac6c5112018-05-25 17:34:00 -070010379 val = get_param(cmd, "MCS_FixedRate");
10380 if (val) {
10381#ifdef NL80211_SUPPORT
10382 int mcs, ratecode = 0;
10383 enum he_mcs_config mcs_config;
10384 int ret;
Jouni Malinenb9b671d2019-04-26 13:23:17 +030010385 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -070010386
10387 ratecode = (0x07 & dut->sta_nss) << 5;
10388 mcs = atoi(val);
10389 /* Add the MCS to the ratecode */
10390 if (mcs >= 0 && mcs <= 11) {
10391 ratecode += mcs;
10392 if (dut->device_type == STA_testbed &&
10393 mcs > 7 && mcs <= 11) {
10394 if (mcs <= 9)
10395 mcs_config = HE_80_MCS0_9;
10396 else
10397 mcs_config = HE_80_MCS0_11;
10398 ret = sta_set_he_mcs(dut, intf, mcs_config);
10399 if (ret) {
10400 sigma_dut_print(dut, DUT_MSG_ERROR,
10401 "MCS_FixedRate: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
10402 mcs, mcs_config, ret);
10403 }
10404 }
10405 snprintf(buf, sizeof(buf),
10406 "iwpriv %s set_11ax_rate 0x%03x",
10407 intf, ratecode);
10408 if (system(buf) != 0) {
10409 sigma_dut_print(dut, DUT_MSG_ERROR,
10410 "MCS_FixedRate: iwpriv setting of 11ax rates 0x%03x failed",
10411 ratecode);
10412 }
10413 } else {
10414 sigma_dut_print(dut, DUT_MSG_ERROR,
10415 "MCS_FixedRate: HE MCS %d not supported",
10416 mcs);
10417 }
10418#else /* NL80211_SUPPORT */
10419 sigma_dut_print(dut, DUT_MSG_ERROR,
10420 "MCS_FixedRate cannot be changed without NL80211_SUPPORT defined");
10421#endif /* NL80211_SUPPORT */
10422 }
10423
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010424 val = get_param(cmd, "opt_md_notif_ie");
10425 if (val) {
10426 char *result = NULL;
10427 char delim[] = ";";
10428 char token[30];
10429 int value, config_val = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010430 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010431
Peng Xub8fc5cc2017-05-10 17:27:28 -070010432 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010433 result = strtok_r(token, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010434
10435 /* Extract the NSS information */
10436 if (result) {
10437 value = atoi(result);
10438 switch (value) {
10439 case 1:
10440 config_val = 1;
10441 break;
10442 case 2:
10443 config_val = 3;
10444 break;
10445 case 3:
10446 config_val = 7;
10447 break;
10448 case 4:
10449 config_val = 15;
10450 break;
10451 default:
10452 config_val = 3;
10453 break;
10454 }
10455
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010456 run_iwpriv(dut, intf, "rxchainmask %d", config_val);
10457 run_iwpriv(dut, intf, "txchainmask %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010458
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010459 }
10460
10461 /* Extract the channel width information */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010462 result = strtok_r(NULL, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010463 if (result) {
10464 value = atoi(result);
10465 switch (value) {
10466 case 20:
10467 config_val = 0;
10468 break;
10469 case 40:
10470 config_val = 1;
10471 break;
10472 case 80:
10473 config_val = 2;
10474 break;
10475 case 160:
10476 config_val = 3;
10477 break;
10478 default:
10479 config_val = 2;
10480 break;
10481 }
10482
10483 dut->chwidth = config_val;
10484
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010485 run_iwpriv(dut, intf, "chwidth %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010486 }
10487
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010488 run_iwpriv(dut, intf, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010489 }
10490
10491 val = get_param(cmd, "nss_mcs_cap");
10492 if (val) {
10493 int nss, mcs;
10494 char token[20];
10495 char *result = NULL;
10496 unsigned int vht_mcsmap = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010497 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010498
Peng Xub8fc5cc2017-05-10 17:27:28 -070010499 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010500 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +053010501 if (!result) {
10502 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -070010503 "NSS not specified");
10504 send_resp(dut, conn, SIGMA_ERROR,
10505 "errorCode,NSS not specified");
Jouni Malinen224e3902021-06-09 16:41:27 +030010506 return STATUS_SENT_ERROR;
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +053010507 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010508 nss = atoi(result);
10509
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010510 run_iwpriv(dut, intf, "nss %d", nss);
Arif Hussainac6c5112018-05-25 17:34:00 -070010511 dut->sta_nss = nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010512
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010513 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010514 if (result == NULL) {
10515 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -070010516 "MCS not specified");
10517 send_resp(dut, conn, SIGMA_ERROR,
10518 "errorCode,MCS not specified");
Jouni Malinen224e3902021-06-09 16:41:27 +030010519 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010520 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010521 result = strtok_r(result, "-", &saveptr);
10522 result = strtok_r(NULL, "-", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +053010523 if (!result) {
10524 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -070010525 "MCS not specified");
10526 send_resp(dut, conn, SIGMA_ERROR,
10527 "errorCode,MCS not specified");
Jouni Malinen224e3902021-06-09 16:41:27 +030010528 return STATUS_SENT_ERROR;
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +053010529 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010530 mcs = atoi(result);
10531
Arif Hussaina37e9552018-06-20 17:05:59 -070010532 if (program && strcasecmp(program, "HE") == 0) {
10533#ifdef NL80211_SUPPORT
10534 enum he_mcs_config mcs_config;
10535 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010536
Arif Hussaina37e9552018-06-20 17:05:59 -070010537 if (mcs >= 0 && mcs <= 7) {
10538 mcs_config = HE_80_MCS0_7;
10539 } else if (mcs > 7 && mcs <= 9) {
10540 mcs_config = HE_80_MCS0_9;
10541 } else if (mcs > 9 && mcs <= 11) {
10542 mcs_config = HE_80_MCS0_11;
10543 } else {
10544 sigma_dut_print(dut, DUT_MSG_ERROR,
10545 "nss_mcs_cap: HE: Invalid mcs: %d",
10546 mcs);
10547 send_resp(dut, conn, SIGMA_ERROR,
10548 "errorCode,Invalid MCS");
Jouni Malinen224e3902021-06-09 16:41:27 +030010549 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010550 }
Arif Hussaina37e9552018-06-20 17:05:59 -070010551
10552 ret = sta_set_he_mcs(dut, intf, mcs_config);
10553 if (ret) {
10554 sigma_dut_print(dut, DUT_MSG_ERROR,
10555 "nss_mcs_cap: HE: Setting of MCS failed, mcs_config: %d, ret: %d",
10556 mcs_config, ret);
10557 send_resp(dut, conn, SIGMA_ERROR,
10558 "errorCode,Failed to set MCS");
Jouni Malinen224e3902021-06-09 16:41:27 +030010559 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010560 }
Arif Hussaina37e9552018-06-20 17:05:59 -070010561#else /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010562 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -070010563 "nss_mcs_cap: HE: MCS cannot be changed without NL80211_SUPPORT defined");
10564#endif /* NL80211_SUPPORT */
10565 } else {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010566 run_iwpriv(dut, intf, "vhtmcs %d", mcs);
Arif Hussaina37e9552018-06-20 17:05:59 -070010567
10568 switch (nss) {
10569 case 1:
10570 switch (mcs) {
10571 case 7:
10572 vht_mcsmap = 0xfffc;
10573 break;
10574 case 8:
10575 vht_mcsmap = 0xfffd;
10576 break;
10577 case 9:
10578 vht_mcsmap = 0xfffe;
10579 break;
10580 default:
10581 vht_mcsmap = 0xfffe;
10582 break;
10583 }
10584 break;
10585 case 2:
10586 switch (mcs) {
10587 case 7:
10588 vht_mcsmap = 0xfff0;
10589 break;
10590 case 8:
10591 vht_mcsmap = 0xfff5;
10592 break;
10593 case 9:
10594 vht_mcsmap = 0xfffa;
10595 break;
10596 default:
10597 vht_mcsmap = 0xfffa;
10598 break;
10599 }
10600 break;
10601 case 3:
10602 switch (mcs) {
10603 case 7:
10604 vht_mcsmap = 0xffc0;
10605 break;
10606 case 8:
10607 vht_mcsmap = 0xffd5;
10608 break;
10609 case 9:
10610 vht_mcsmap = 0xffea;
10611 break;
10612 default:
10613 vht_mcsmap = 0xffea;
10614 break;
10615 }
10616 break;
10617 default:
10618 vht_mcsmap = 0xffea;
10619 break;
10620 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010621 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010622 }
10623 }
10624
10625 /* UNSUPPORTED: val = get_param(cmd, "Tx_lgi_rate"); */
10626
10627 val = get_param(cmd, "Vht_tkip");
10628 if (val)
10629 tkip = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
10630
10631 val = get_param(cmd, "Vht_wep");
10632 if (val)
10633 wep = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
10634
10635 if (tkip != -1 || wep != -1) {
10636 if ((tkip == 1 && wep != 0) || (wep == 1 && tkip != 0)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010637 run_iwpriv(dut, intf, "htweptkip 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010638 } else if ((tkip == 0 && wep != 1) || (wep == 0 && tkip != 1)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010639 run_iwpriv(dut, intf, "htweptkip 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010640 } else {
Jouni Malinen224e3902021-06-09 16:41:27 +030010641 send_resp(dut, conn, SIGMA_ERROR,
10642 "ErrorCode,mixed mode of VHT TKIP/WEP not supported");
10643 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010644 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010645 }
10646
Kiran Kumar Lokere09dbcef2021-08-09 00:01:41 -070010647 val = get_param(cmd, "TWTSchedSTASupport");
10648 if (val) {
10649 int set_val;
10650
10651 switch (get_driver_type(dut)) {
10652 case DRIVER_WCN:
10653 if (strcasecmp(val, "Enable") == 0) {
10654 set_val = 1;
10655 } else if (strcasecmp(val, "Disable") == 0) {
10656 set_val = 0;
10657 } else {
10658 send_resp(dut, conn, SIGMA_ERROR,
10659 "ErrorCode,Invalid TWTSchedSTASupport");
10660 return STATUS_SENT_ERROR;
10661 }
10662
10663 if (sta_set_bcast_twt_support(dut, intf, set_val)) {
10664 send_resp(dut, conn, SIGMA_ERROR,
10665 "ErrorCode,Failed to set TWTSchedSTASupport");
10666 return STATUS_SENT_ERROR;
10667 }
10668 break;
10669 default:
10670 sigma_dut_print(dut, DUT_MSG_ERROR,
10671 "Setting TWTSchedSTASupport not supported");
10672 break;
10673 }
10674 }
10675
10676 val = get_param(cmd, "MBSSID_RxCtrl");
10677 if (val) {
10678 int set_val;
10679
10680 switch (get_driver_type(dut)) {
10681 case DRIVER_WCN:
10682 if (strcasecmp(val, "Enable") == 0) {
10683 set_val = 1;
10684 } else if (strcasecmp(val, "Disable") == 0) {
10685 set_val = 0;
10686 } else {
10687 send_resp(dut, conn, SIGMA_ERROR,
10688 "ErrorCode,Invalid MBSSID_RxCtrl");
10689 return STATUS_SENT_ERROR;
10690 }
10691
10692 if (sta_set_rx_ctrl_multi_bss(dut, intf, set_val)) {
10693 send_resp(dut, conn, SIGMA_ERROR,
10694 "ErrorCode,Failed to set MBSSID_RxCtrl");
10695 return STATUS_SENT_ERROR;
10696 }
10697 break;
10698 default:
10699 sigma_dut_print(dut, DUT_MSG_ERROR,
10700 "Setting MBSSID_RxCtrl not supported");
10701 break;
10702 }
10703 }
10704
Arif Hussain55f00da2018-07-03 08:28:26 -070010705 val = get_param(cmd, "txBandwidth");
10706 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010707 switch (get_driver_type(dut)) {
Arif Hussain55f00da2018-07-03 08:28:26 -070010708 case DRIVER_WCN:
10709 if (wcn_sta_set_width(dut, intf, val) < 0) {
10710 send_resp(dut, conn, SIGMA_ERROR,
10711 "ErrorCode,Failed to set txBandwidth");
Jouni Malinen224e3902021-06-09 16:41:27 +030010712 return STATUS_SENT_ERROR;
Arif Hussain55f00da2018-07-03 08:28:26 -070010713 }
10714 break;
10715 case DRIVER_ATHEROS:
10716 if (ath_set_width(dut, conn, intf, val) < 0) {
10717 send_resp(dut, conn, SIGMA_ERROR,
10718 "ErrorCode,Failed to set txBandwidth");
Jouni Malinen224e3902021-06-09 16:41:27 +030010719 return STATUS_SENT_ERROR;
Arif Hussain55f00da2018-07-03 08:28:26 -070010720 }
10721 break;
10722 default:
10723 sigma_dut_print(dut, DUT_MSG_ERROR,
10724 "Setting txBandwidth not supported");
10725 break;
10726 }
10727 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010728
Arif Hussain9765f7d2018-07-03 08:28:26 -070010729 val = get_param(cmd, "BeamformeeSTS");
10730 if (val) {
Kiran Kumar Lokerebc89d432018-07-10 12:20:13 -070010731 if (sta_set_tx_beamformee(dut, intf, 1)) {
10732 send_resp(dut, conn, SIGMA_ERROR,
10733 "ErrorCode,Failed to set TX beamformee enable");
Jouni Malinen224e3902021-06-09 16:41:27 +030010734 return STATUS_SENT_ERROR;
Kiran Kumar Lokerebc89d432018-07-10 12:20:13 -070010735 }
10736
Arif Hussain9765f7d2018-07-03 08:28:26 -070010737 if (sta_set_beamformee_sts(dut, intf, atoi(val))) {
10738 send_resp(dut, conn, SIGMA_ERROR,
10739 "ErrorCode,Failed to set BeamformeeSTS");
Jouni Malinen224e3902021-06-09 16:41:27 +030010740 return STATUS_SENT_ERROR;
Arif Hussain9765f7d2018-07-03 08:28:26 -070010741 }
10742 }
10743
Arif Hussain68d23f52018-07-11 13:39:08 -070010744 val = get_param(cmd, "Trig_MAC_Padding_Dur");
10745 if (val) {
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -070010746#ifdef NL80211_SUPPORT
10747 enum qca_wlan_he_mac_padding_dur set_val;
10748
10749 switch (atoi(val)) {
10750 case 16:
10751 set_val = QCA_WLAN_HE_16US_OF_PROCESS_TIME;
10752 break;
10753 case 8:
10754 set_val = QCA_WLAN_HE_8US_OF_PROCESS_TIME;
10755 break;
10756 default:
10757 set_val = QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME;
10758 break;
10759 }
10760 if (sta_set_mac_padding_duration(dut, intf, set_val)) {
Arif Hussain68d23f52018-07-11 13:39:08 -070010761 send_resp(dut, conn, SIGMA_ERROR,
10762 "ErrorCode,Failed to set MAC padding duration");
Jouni Malinen224e3902021-06-09 16:41:27 +030010763 return STATUS_SENT_ERROR;
Arif Hussain68d23f52018-07-11 13:39:08 -070010764 }
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -070010765#else /* NL80211_SUPPORT */
10766 sigma_dut_print(dut, DUT_MSG_ERROR,
10767 "MAC padding duration cannot be changed without NL80211_SUPPORT defined");
10768#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -070010769 }
10770
Arif Hussain480d5f42019-03-12 14:40:42 -070010771 val = get_param(cmd, "TWT_ReqSupport");
10772 if (val) {
10773 int set_val;
10774
10775 if (strcasecmp(val, "Enable") == 0) {
10776 set_val = 1;
10777 } else if (strcasecmp(val, "Disable") == 0) {
10778 set_val = 0;
10779 } else {
10780 send_resp(dut, conn, SIGMA_ERROR,
10781 "ErrorCode,Invalid TWT_ReqSupport");
Jouni Malinen224e3902021-06-09 16:41:27 +030010782 return STATUS_SENT_ERROR;
Arif Hussain480d5f42019-03-12 14:40:42 -070010783 }
10784
10785 if (sta_set_twt_req_support(dut, intf, set_val)) {
10786 sigma_dut_print(dut, DUT_MSG_ERROR,
10787 "Failed to set TWT req support %d",
10788 set_val);
10789 send_resp(dut, conn, SIGMA_ERROR,
10790 "ErrorCode,Failed to set TWT_ReqSupport");
Jouni Malinen224e3902021-06-09 16:41:27 +030010791 return STATUS_SENT_ERROR;
Arif Hussain480d5f42019-03-12 14:40:42 -070010792 }
10793 }
10794
Kiran Kumar Lokered0ec5ed2021-04-01 00:15:04 -070010795 val = get_param(cmd, "PreamblePunctRx");
10796 if (val && get_driver_type(dut) == DRIVER_WCN) {
10797 int set_val;
10798
10799 if (strcasecmp(val, "Enable") == 0) {
10800 set_val = 1;
10801 } else if (strcasecmp(val, "Disable") == 0) {
10802 set_val = 0;
10803 } else {
10804 send_resp(dut, conn, SIGMA_ERROR,
10805 "ErrorCode,Invalid PreamblePunctRx");
10806 return STATUS_SENT_ERROR;
10807 }
10808
10809 if (sta_set_punctured_preamble_rx(dut, intf, set_val)) {
10810 sigma_dut_print(dut, DUT_MSG_ERROR,
10811 "Failed to set PreamblePunctRx support %d",
10812 set_val);
10813 send_resp(dut, conn, SIGMA_ERROR,
10814 "ErrorCode,Failed to set PreamblePunctRx");
10815 return STATUS_SENT_ERROR;
10816 }
10817 }
10818
Srinivas Girigowda0525e292020-11-12 13:28:21 -080010819 val = get_param(cmd, "FullBW_ULMUMIMO");
10820 if (val) {
10821 int set_val;
10822
10823 if (strcasecmp(val, "Enable") == 0) {
10824 set_val = 1;
10825 } else if (strcasecmp(val, "Disable") == 0) {
10826 set_val = 0;
10827 } else {
10828 send_resp(dut, conn, SIGMA_ERROR,
10829 "ErrorCode,Invalid FullBW_ULMUMIMO");
10830 return STATUS_SENT_ERROR;
10831 }
10832
10833 if (sta_set_fullbw_ulmumimo(dut, intf, set_val)) {
10834 sigma_dut_print(dut, DUT_MSG_ERROR,
10835 "Failed to set FullBW_ULMUMIMO %d",
10836 set_val);
10837 send_resp(dut, conn, SIGMA_ERROR,
10838 "ErrorCode,Failed to set FullBW_ULMUMIMO");
10839 return STATUS_SENT_ERROR;
10840 }
10841 }
10842
Srinivas Girigowda6707f032020-10-26 15:24:46 -070010843 val = get_param(cmd, "TWTInfoFrameTx");
10844 if (val) {
10845 if (strcasecmp(val, "Enable") == 0) {
10846 /* No-op */
10847 } else if (strcasecmp(val, "Disable") == 0) {
10848 /* No-op */
10849 } else {
10850 send_resp(dut, conn, SIGMA_ERROR,
10851 "ErrorCode,Invalid TWTInfoFrameTx");
10852 return STATUS_SENT_ERROR;
10853 }
10854 }
10855
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -070010856 val = get_param(cmd, "MU_EDCA");
10857 if (val && (strcasecmp(val, "Override") == 0)) {
10858 if (sta_set_mu_edca_override(dut, intf, 1)) {
10859 send_resp(dut, conn, SIGMA_ERROR,
10860 "ErrorCode,Failed to set MU EDCA override");
Jouni Malinen224e3902021-06-09 16:41:27 +030010861 return STATUS_SENT_ERROR;
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -070010862 }
10863 }
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -070010864
Kiran Kumar Lokerefa7c7b92021-08-09 00:50:55 -070010865 val = get_param(cmd, "PPDUTxType");
10866 if (val && strcasecmp(val, "ER-SU") == 0) {
10867 if (sta_set_er_su_ppdu_type_tx(dut, intf, 1)) {
10868 send_resp(dut, conn, SIGMA_ERROR,
10869 "ErrorCode,Failed to set ER-SU PPDU type Tx");
10870 return STATUS_SENT_ERROR;
10871 }
10872 }
10873
10874 val = get_param(cmd, "RUAllocTone");
10875 if (val && strcasecmp(val, "242") == 0) {
10876 if (sta_set_ru_242_tone_tx(dut, intf, 1)) {
10877 send_resp(dut, conn, SIGMA_ERROR,
10878 "ErrorCode,Failed to set RU 242 tone Tx");
10879 return STATUS_SENT_ERROR;
10880 }
10881 }
10882
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -070010883 val = get_param(cmd, "OMControl");
10884 if (val) {
10885 int set_val = 1;
10886
10887 if (strcasecmp(val, "Enable") == 0)
10888 set_val = 1;
10889 else if (strcasecmp(val, "Disable") == 0)
10890 set_val = 0;
10891
10892 if (sta_set_om_ctrl_supp(dut, intf, set_val)) {
10893 send_resp(dut, conn, SIGMA_ERROR,
10894 "ErrorCode,Failed to set OM ctrl supp");
Jouni Malinen224e3902021-06-09 16:41:27 +030010895 return STATUS_SENT_ERROR;
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -070010896 }
10897 }
10898
Kiran Kumar Lokere4f2d4b02021-04-01 00:07:39 -070010899 val = get_param(cmd, "BSSMaxIdlePeriod");
10900 if (val && sta_set_bss_max_idle_period(dut, intf, atoi(val))) {
10901 send_resp(dut, conn, SIGMA_ERROR,
10902 "ErrorCode,Failed to set BSS max idle period");
10903 return STATUS_SENT_ERROR;
10904 }
10905
Kiran Kumar Lokere07ad92b2021-08-09 00:27:14 -070010906 val = get_param(cmd, "BSS_max_idle");
10907 if (val) {
10908 int set_val = 0;
10909
10910 if (strcasecmp(val, "Enable") == 0)
10911 set_val = 1;
10912 else if (strcasecmp(val, "Disable") == 0)
10913 set_val = 0;
10914 if (sta_set_bss_max_idle_support(dut, intf, set_val)) {
10915 send_resp(dut, conn, SIGMA_ERROR,
10916 "ErrorCode,Failed to set BSS max idle support");
10917 return STATUS_SENT_ERROR;
10918 }
10919 }
10920
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -070010921 val = get_param(cmd, "ADDBAResp_BufSize");
10922 if (val) {
10923 int buf_size;
10924
10925 if (strcasecmp(val, "gt64") == 0)
10926 buf_size = 256;
10927 else
10928 buf_size = 64;
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010929 if (get_driver_type(dut) == DRIVER_WCN &&
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -070010930 sta_set_addba_buf_size(dut, intf, buf_size)) {
10931 send_resp(dut, conn, SIGMA_ERROR,
10932 "ErrorCode,set addbaresp_buff_size failed");
Jouni Malinen224e3902021-06-09 16:41:27 +030010933 return STATUS_SENT_ERROR;
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -070010934 }
10935 }
10936
10937 val = get_param(cmd, "ADDBAReq_BufSize");
10938 if (val) {
10939 int buf_size;
10940
10941 if (strcasecmp(val, "gt64") == 0)
10942 buf_size = 256;
10943 else
10944 buf_size = 64;
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010945 if (get_driver_type(dut) == DRIVER_WCN &&
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -070010946 sta_set_addba_buf_size(dut, intf, buf_size)) {
10947 send_resp(dut, conn, SIGMA_ERROR,
10948 "ErrorCode,set addbareq_buff_size failed");
Jouni Malinen224e3902021-06-09 16:41:27 +030010949 return STATUS_SENT_ERROR;
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -070010950 }
10951 }
10952
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010953 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
10954}
10955
10956
10957static int sta_set_wireless_60g(struct sigma_dut *dut,
10958 struct sigma_conn *conn,
10959 struct sigma_cmd *cmd)
10960{
10961 const char *dev_role = get_param(cmd, "DevRole");
10962
10963 if (!dev_role) {
10964 send_resp(dut, conn, SIGMA_INVALID,
10965 "ErrorCode,DevRole not specified");
10966 return 0;
10967 }
10968
10969 if (strcasecmp(dev_role, "PCP") == 0)
10970 return sta_set_60g_pcp(dut, conn, cmd);
10971 if (strcasecmp(dev_role, "STA") == 0)
10972 return sta_set_60g_sta(dut, conn, cmd);
10973 send_resp(dut, conn, SIGMA_INVALID,
10974 "ErrorCode,DevRole not supported");
10975 return 0;
10976}
10977
10978
Ankita Bajaj0d5825b2017-10-25 16:20:17 +053010979static int sta_set_wireless_oce(struct sigma_dut *dut, struct sigma_conn *conn,
10980 struct sigma_cmd *cmd)
10981{
10982 int status;
10983 const char *intf = get_param(cmd, "Interface");
10984 const char *val = get_param(cmd, "DevRole");
10985
10986 if (val && strcasecmp(val, "STA-CFON") == 0) {
10987 status = sta_cfon_set_wireless(dut, conn, cmd);
10988 if (status)
10989 return status;
10990 }
10991 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
10992}
10993
10994
Jouni Malinen67433fc2020-06-26 22:50:33 +030010995static enum sigma_cmd_result
10996sta_set_wireless_wpa3(struct sigma_dut *dut, struct sigma_conn *conn,
10997 struct sigma_cmd *cmd)
Vamsi Krishnac1633d22020-05-06 18:31:21 +053010998{
10999 const char *intf = get_param(cmd, "Interface");
11000 const char *val;
11001
11002 val = get_param(cmd, "ocvc");
11003 if (val)
11004 dut->ocvc = atoi(val);
11005
Jouni Malinen67433fc2020-06-26 22:50:33 +030011006 val = get_param(cmd, "ClientPrivacy");
Veerendranath Jakkam47867202020-12-21 01:53:52 +053011007 if (val && dut->client_privacy != atoi(val) &&
11008 sta_set_client_privacy(dut, conn, intf, atoi(val))) {
11009 send_resp(dut, conn, SIGMA_ERROR,
11010 "errorCode,Failed to configure random MAC address use");
11011 return STATUS_SENT_ERROR;
Jouni Malinen67433fc2020-06-26 22:50:33 +030011012 }
11013
Vamsi Krishnac1633d22020-05-06 18:31:21 +053011014 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
11015}
11016
11017
Jouni Malinenf7222712019-06-13 01:50:21 +030011018static enum sigma_cmd_result cmd_sta_set_wireless(struct sigma_dut *dut,
11019 struct sigma_conn *conn,
11020 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011021{
11022 const char *val;
11023
11024 val = get_param(cmd, "Program");
11025 if (val) {
11026 if (strcasecmp(val, "11n") == 0)
11027 return cmd_sta_set_11n(dut, conn, cmd);
Amarnath Hullur Subramanyam4f860292018-01-31 03:49:35 -080011028 if (strcasecmp(val, "VHT") == 0 || strcasecmp(val, "HE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011029 return cmd_sta_set_wireless_vht(dut, conn, cmd);
11030 if (strcasecmp(val, "60ghz") == 0)
11031 return sta_set_wireless_60g(dut, conn, cmd);
Ankita Bajaj0d5825b2017-10-25 16:20:17 +053011032 if (strcasecmp(val, "OCE") == 0)
11033 return sta_set_wireless_oce(dut, conn, cmd);
Alexei Avshalom Lazar66bb9972018-12-18 16:01:43 +020011034 /* sta_set_wireless in WPS program is only used for 60G */
11035 if (is_60g_sigma_dut(dut))
11036 return sta_set_wireless_60g(dut, conn, cmd);
Vamsi Krishnac1633d22020-05-06 18:31:21 +053011037 if (strcasecmp(val, "WPA3") == 0)
11038 return sta_set_wireless_wpa3(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011039 send_resp(dut, conn, SIGMA_ERROR,
11040 "ErrorCode,Program value not supported");
11041 } else {
11042 send_resp(dut, conn, SIGMA_ERROR,
11043 "ErrorCode,Program argument not available");
11044 }
11045
11046 return 0;
11047}
11048
11049
11050static void ath_sta_inject_frame(struct sigma_dut *dut, const char *intf,
11051 int tid)
11052{
11053 char buf[100];
11054 int tid_to_dscp [] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 };
11055
Pradeep Reddy POTTETId31d1322016-10-13 17:22:03 +053011056 if (tid < 0 ||
11057 tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) {
11058 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid);
11059 return;
11060 }
11061
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011062 /*
11063 * Two ways to ensure that addba request with a
11064 * non zero TID could be sent out. EV 117296
11065 */
11066 snprintf(buf, sizeof(buf),
11067 "ping -c 8 -Q %d `arp -a | grep wlan0 | awk '{print $2}' | tr -d '()'`",
11068 tid);
11069 if (system(buf) != 0) {
11070 sigma_dut_print(dut, DUT_MSG_ERROR,
11071 "Ping did not send out");
11072 }
11073
11074 snprintf(buf, sizeof(buf),
11075 "iwconfig %s | grep Access | awk '{print $6}' > %s",
11076 intf, VI_QOS_TMP_FILE);
11077 if (system(buf) != 0)
11078 return;
11079
11080 snprintf(buf, sizeof(buf),
11081 "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s",
11082 intf, VI_QOS_TMP_FILE);
11083 if (system(buf) != 0)
11084 sigma_dut_print(dut, DUT_MSG_ERROR, "HWaddr matching failed");
11085
11086 snprintf(buf,sizeof(buf), "sed -n '3,$p' %s >> %s",
11087 VI_QOS_REFFILE, VI_QOS_TMP_FILE);
11088 if (system(buf) != 0) {
11089 sigma_dut_print(dut, DUT_MSG_ERROR,
11090 "VI_QOS_TEMP_FILE generation error failed");
11091 }
11092 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
11093 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
11094 if (system(buf) != 0) {
11095 sigma_dut_print(dut, DUT_MSG_ERROR,
11096 "VI_QOS_FILE generation failed");
11097 }
11098
11099 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
11100 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
11101 if (system(buf) != 0) {
11102 sigma_dut_print(dut, DUT_MSG_ERROR,
11103 "VI_QOS_FILE generation failed");
11104 }
11105
11106 snprintf(buf, sizeof(buf), "ethinject %s %s", intf, VI_QOS_FILE);
11107 if (system(buf) != 0) {
11108 }
11109}
11110
11111
11112static int ath_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
11113 struct sigma_cmd *cmd)
11114{
11115 const char *intf = get_param(cmd, "Interface");
11116 const char *val;
11117 int tid = 0;
11118 char buf[100];
11119
11120 val = get_param(cmd, "TID");
11121 if (val) {
11122 tid = atoi(val);
11123 if (tid)
11124 ath_sta_inject_frame(dut, intf, tid);
11125 }
11126
11127 /* Command sequence for ADDBA request on Peregrine based devices */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011128 run_iwpriv(dut, intf, "setaddbaoper 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011129
11130 snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4", intf, tid);
11131 if (system(buf) != 0) {
11132 sigma_dut_print(dut, DUT_MSG_ERROR,
11133 "wifitool senddelba failed");
11134 }
11135
11136 snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64", intf, tid);
11137 if (system(buf) != 0) {
11138 sigma_dut_print(dut, DUT_MSG_ERROR,
11139 "wifitool sendaddba failed");
11140 }
11141
11142 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
11143
11144 return 1;
11145}
11146
11147
Lior David9981b512017-01-20 13:16:40 +020011148#ifdef __linux__
11149
11150static int wil6210_send_addba(struct sigma_dut *dut, const char *dest_mac,
11151 int agg_size)
11152{
11153 char dir[128], buf[128];
11154 FILE *f;
11155 regex_t re;
11156 regmatch_t m[2];
Jouni Malinen3aa72862019-05-29 23:14:51 +030011157 int rc, ret = -1, vring_id, found, res;
Lior David9981b512017-01-20 13:16:40 +020011158
11159 if (wil6210_get_debugfs_dir(dut, dir, sizeof(dir))) {
11160 sigma_dut_print(dut, DUT_MSG_ERROR,
11161 "failed to get wil6210 debugfs dir");
11162 return -1;
11163 }
11164
Jouni Malinen3aa72862019-05-29 23:14:51 +030011165 res = snprintf(buf, sizeof(buf), "%s/vrings", dir);
11166 if (res < 0 || res >= sizeof(buf))
11167 return -1;
Lior David9981b512017-01-20 13:16:40 +020011168 f = fopen(buf, "r");
11169 if (!f) {
11170 sigma_dut_print(dut, DUT_MSG_ERROR, "failed to open: %s", buf);
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +020011171 /* newer wil6210 driver renamed file to "rings" */
Jouni Malinen3aa72862019-05-29 23:14:51 +030011172 res = snprintf(buf, sizeof(buf), "%s/rings", dir);
11173 if (res < 0 || res >= sizeof(buf))
11174 return -1;
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +020011175 f = fopen(buf, "r");
11176 if (!f) {
11177 sigma_dut_print(dut, DUT_MSG_ERROR,
11178 "failed to open: %s", buf);
11179 return -1;
11180 }
Lior David9981b512017-01-20 13:16:40 +020011181 }
11182
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +020011183 /* can be either VRING tx... or RING... */
11184 if (regcomp(&re, "RING tx_[ \t]*([0-9]+)", REG_EXTENDED)) {
Lior David9981b512017-01-20 13:16:40 +020011185 sigma_dut_print(dut, DUT_MSG_ERROR, "regcomp failed");
11186 goto out;
11187 }
11188
11189 /* find TX VRING for the mac address */
11190 found = 0;
11191 while (fgets(buf, sizeof(buf), f)) {
11192 if (strcasestr(buf, dest_mac)) {
11193 found = 1;
11194 break;
11195 }
11196 }
11197
11198 if (!found) {
11199 sigma_dut_print(dut, DUT_MSG_ERROR,
11200 "no TX VRING for %s", dest_mac);
11201 goto out;
11202 }
11203
11204 /* extract VRING ID, "VRING tx_<id> = {" */
11205 if (!fgets(buf, sizeof(buf), f)) {
11206 sigma_dut_print(dut, DUT_MSG_ERROR,
11207 "no VRING start line for %s", dest_mac);
11208 goto out;
11209 }
11210
11211 rc = regexec(&re, buf, 2, m, 0);
11212 regfree(&re);
11213 if (rc || m[1].rm_so < 0) {
11214 sigma_dut_print(dut, DUT_MSG_ERROR,
11215 "no VRING TX ID for %s", dest_mac);
11216 goto out;
11217 }
11218 buf[m[1].rm_eo] = 0;
11219 vring_id = atoi(&buf[m[1].rm_so]);
11220
11221 /* send the addba command */
11222 fclose(f);
Jouni Malinen3aa72862019-05-29 23:14:51 +030011223 res = snprintf(buf, sizeof(buf), "%s/back", dir);
11224 if (res < 0 || res >= sizeof(buf))
11225 return -1;
Lior David9981b512017-01-20 13:16:40 +020011226 f = fopen(buf, "w");
11227 if (!f) {
11228 sigma_dut_print(dut, DUT_MSG_ERROR,
11229 "failed to open: %s", buf);
11230 return -1;
11231 }
11232
11233 fprintf(f, "add %d %d\n", vring_id, agg_size);
11234
11235 ret = 0;
11236
11237out:
11238 fclose(f);
11239
11240 return ret;
11241}
11242
11243
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +020011244int send_addba_60g(struct sigma_dut *dut, struct sigma_conn *conn,
11245 struct sigma_cmd *cmd, const char *mac_param)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011246{
11247 const char *val;
11248 int tid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011249
11250 val = get_param(cmd, "TID");
11251 if (val) {
11252 tid = atoi(val);
11253 if (tid != 0) {
11254 sigma_dut_print(dut, DUT_MSG_ERROR,
11255 "Ignore TID %d for send_addba use TID 0 for 60g since only 0 required on TX",
11256 tid);
11257 }
11258 }
11259
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +020011260 val = get_param(cmd, mac_param);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011261 if (!val) {
11262 sigma_dut_print(dut, DUT_MSG_ERROR,
11263 "Currently not supporting addba for 60G without Dest_mac");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020011264 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011265 }
11266
Lior David9981b512017-01-20 13:16:40 +020011267 if (wil6210_send_addba(dut, val, dut->back_rcv_buf))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011268 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011269
11270 return 1;
11271}
11272
Lior David9981b512017-01-20 13:16:40 +020011273#endif /* __linux__ */
11274
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011275
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080011276static int wcn_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
11277 struct sigma_cmd *cmd)
11278{
11279#ifdef NL80211_SUPPORT
11280 const char *intf = get_param(cmd, "Interface");
11281 const char *val;
11282 int tid = -1;
11283 int bufsize = 64;
11284 struct nl_msg *msg;
11285 int ret = 0;
11286 struct nlattr *params;
11287 int ifindex;
11288
11289 val = get_param(cmd, "TID");
11290 if (val)
11291 tid = atoi(val);
11292
11293 if (tid == -1) {
11294 send_resp(dut, conn, SIGMA_ERROR,
11295 "ErrorCode,sta_send_addba tid invalid");
11296 return 0;
11297 }
11298
11299 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
11300
11301 ifindex = if_nametoindex(intf);
11302 if (ifindex == 0) {
11303 sigma_dut_print(dut, DUT_MSG_ERROR,
11304 "%s: Index for interface %s failed",
11305 __func__, intf);
11306 send_resp(dut, conn, SIGMA_ERROR,
11307 "ErrorCode,sta_send_addba interface invalid");
11308 return 0;
11309 }
11310
11311 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
11312 NL80211_CMD_VENDOR)) ||
11313 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
11314 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
11315 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
11316 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
11317 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
11318 nla_put_u8(msg,
11319 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADD_DEL_BA_SESSION,
11320 QCA_WLAN_ADD_BA) ||
11321 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BA_TID,
11322 tid) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -070011323 nla_put_u16(msg,
11324 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
11325 bufsize)) {
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080011326 sigma_dut_print(dut, DUT_MSG_ERROR,
11327 "%s: err in adding vendor_cmd and vendor_data",
11328 __func__);
11329 nlmsg_free(msg);
11330 send_resp(dut, conn, SIGMA_ERROR,
11331 "ErrorCode,sta_send_addba err in adding vendor_cmd and vendor_data");
11332 return 0;
11333 }
11334 nla_nest_end(msg, params);
11335
11336 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
11337 if (ret) {
11338 sigma_dut_print(dut, DUT_MSG_ERROR,
11339 "%s: err in send_and_recv_msgs, ret=%d",
11340 __func__, ret);
Sunil Dutt30605592018-05-04 20:35:50 +053011341 if (ret == -EOPNOTSUPP)
11342 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080011343 send_resp(dut, conn, SIGMA_ERROR,
11344 "ErrorCode,sta_send_addba err in send_and_recv_msgs");
11345 return 0;
11346 }
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080011347#else /* NL80211_SUPPORT */
11348 sigma_dut_print(dut, DUT_MSG_ERROR,
11349 "sta_send_addba not supported without NL80211_SUPPORT defined");
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080011350#endif /* NL80211_SUPPORT */
Sunil Dutt30605592018-05-04 20:35:50 +053011351
11352 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080011353}
11354
11355
Jouni Malinenf7222712019-06-13 01:50:21 +030011356static enum sigma_cmd_result cmd_sta_send_addba(struct sigma_dut *dut,
11357 struct sigma_conn *conn,
11358 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011359{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011360 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011361 case DRIVER_ATHEROS:
11362 return ath_sta_send_addba(dut, conn, cmd);
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080011363 case DRIVER_WCN:
11364 return wcn_sta_send_addba(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +020011365#ifdef __linux__
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011366 case DRIVER_WIL6210:
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +020011367 return send_addba_60g(dut, conn, cmd, "Dest_mac");
Lior David9981b512017-01-20 13:16:40 +020011368#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011369 default:
11370 /*
11371 * There is no driver specific implementation for other drivers.
11372 * Ignore the command and report COMPLETE since the following
11373 * throughput test operation will end up sending ADDBA anyway.
11374 */
11375 return 1;
11376 }
11377}
11378
11379
11380int inject_eth_frame(int s, const void *data, size_t len,
11381 unsigned short ethtype, char *dst, char *src)
11382{
11383 struct iovec iov[4] = {
11384 {
11385 .iov_base = dst,
11386 .iov_len = ETH_ALEN,
11387 },
11388 {
11389 .iov_base = src,
11390 .iov_len = ETH_ALEN,
11391 },
11392 {
11393 .iov_base = &ethtype,
11394 .iov_len = sizeof(unsigned short),
11395 },
11396 {
11397 .iov_base = (void *) data,
11398 .iov_len = len,
11399 }
11400 };
11401 struct msghdr msg = {
11402 .msg_name = NULL,
11403 .msg_namelen = 0,
11404 .msg_iov = iov,
11405 .msg_iovlen = 4,
11406 .msg_control = NULL,
11407 .msg_controllen = 0,
11408 .msg_flags = 0,
11409 };
11410
11411 return sendmsg(s, &msg, 0);
11412}
11413
11414#if defined(__linux__) || defined(__QNXNTO__)
11415
11416int inject_frame(int s, const void *data, size_t len, int encrypt)
11417{
11418#define IEEE80211_RADIOTAP_F_WEP 0x04
11419#define IEEE80211_RADIOTAP_F_FRAG 0x08
11420 unsigned char rtap_hdr[] = {
11421 0x00, 0x00, /* radiotap version */
11422 0x0e, 0x00, /* radiotap length */
11423 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
11424 IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */
11425 0x00, /* padding */
11426 0x00, 0x00, /* RX and TX flags to indicate that */
11427 0x00, 0x00, /* this is the injected frame directly */
11428 };
11429 struct iovec iov[2] = {
11430 {
11431 .iov_base = &rtap_hdr,
11432 .iov_len = sizeof(rtap_hdr),
11433 },
11434 {
11435 .iov_base = (void *) data,
11436 .iov_len = len,
11437 }
11438 };
11439 struct msghdr msg = {
11440 .msg_name = NULL,
11441 .msg_namelen = 0,
11442 .msg_iov = iov,
11443 .msg_iovlen = 2,
11444 .msg_control = NULL,
11445 .msg_controllen = 0,
11446 .msg_flags = 0,
11447 };
11448
11449 if (encrypt)
11450 rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP;
11451
11452 return sendmsg(s, &msg, 0);
11453}
11454
11455
11456int open_monitor(const char *ifname)
11457{
11458#ifdef __QNXNTO__
11459 struct sockaddr_dl ll;
11460 int s;
11461
11462 memset(&ll, 0, sizeof(ll));
11463 ll.sdl_family = AF_LINK;
11464 ll.sdl_index = if_nametoindex(ifname);
11465 if (ll.sdl_index == 0) {
11466 perror("if_nametoindex");
11467 return -1;
11468 }
11469 s = socket(PF_INET, SOCK_RAW, 0);
11470#else /* __QNXNTO__ */
11471 struct sockaddr_ll ll;
11472 int s;
11473
11474 memset(&ll, 0, sizeof(ll));
11475 ll.sll_family = AF_PACKET;
11476 ll.sll_ifindex = if_nametoindex(ifname);
11477 if (ll.sll_ifindex == 0) {
11478 perror("if_nametoindex");
11479 return -1;
11480 }
11481 s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
11482#endif /* __QNXNTO__ */
11483 if (s < 0) {
11484 perror("socket[PF_PACKET,SOCK_RAW]");
11485 return -1;
11486 }
11487
11488 if (bind(s, (struct sockaddr *) &ll, sizeof(ll)) < 0) {
11489 perror("monitor socket bind");
11490 close(s);
11491 return -1;
11492 }
11493
11494 return s;
11495}
11496
11497
11498static int hex2num(char c)
11499{
11500 if (c >= '0' && c <= '9')
11501 return c - '0';
11502 if (c >= 'a' && c <= 'f')
11503 return c - 'a' + 10;
11504 if (c >= 'A' && c <= 'F')
11505 return c - 'A' + 10;
11506 return -1;
11507}
11508
11509
11510int hwaddr_aton(const char *txt, unsigned char *addr)
11511{
11512 int i;
11513
11514 for (i = 0; i < 6; i++) {
11515 int a, b;
11516
11517 a = hex2num(*txt++);
11518 if (a < 0)
11519 return -1;
11520 b = hex2num(*txt++);
11521 if (b < 0)
11522 return -1;
11523 *addr++ = (a << 4) | b;
11524 if (i < 5 && *txt++ != ':')
11525 return -1;
11526 }
11527
11528 return 0;
11529}
11530
11531#endif /* defined(__linux__) || defined(__QNXNTO__) */
11532
Veerendranath Jakkam49774122020-07-05 09:52:18 +053011533
11534#ifdef NL80211_SUPPORT
11535static int nl80211_send_frame_cmd(struct sigma_dut *dut, const char *intf,
11536 const u8 *data, size_t data_len, int freq)
11537{
11538 struct nl_msg *msg;
11539 int ret = 0;
11540 int ifindex;
11541
11542 ifindex = if_nametoindex(intf);
11543 if (ifindex == 0) {
11544 sigma_dut_print(dut, DUT_MSG_ERROR,
11545 "%s: Index for interface %s failed",
11546 __func__, intf);
11547 return -1;
11548 }
11549
11550 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
11551 NL80211_CMD_FRAME)) ||
11552 (freq && nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
11553 nla_put(msg, NL80211_ATTR_FRAME, data_len, data)) {
11554 sigma_dut_print(dut, DUT_MSG_ERROR,
11555 "%s: Error in adding NL80211_CMD_FRAME",
11556 __func__);
11557 nlmsg_free(msg);
11558 return -1;
11559 }
11560
11561 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
11562 if (ret) {
11563 sigma_dut_print(dut, DUT_MSG_ERROR,
11564 "nl80211: Frame command failed: ret=%d (%s) req=%u",
11565 ret, strerror(-ret), freq);
11566 return -1;
11567 }
11568
11569 return 0;
11570}
11571#endif /* NL80211_SUPPORT */
11572
11573
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011574enum send_frame_type {
11575 DISASSOC, DEAUTH, SAQUERY, AUTH, ASSOCREQ, REASSOCREQ, DLS_REQ
11576};
11577enum send_frame_protection {
11578 CORRECT_KEY, INCORRECT_KEY, UNPROTECTED
11579};
11580
11581
11582static int sta_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn,
Veerendranath Jakkam49774122020-07-05 09:52:18 +053011583 const char *intf, enum send_frame_type frame,
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011584 enum send_frame_protection protected,
Veerendranath Jakkam49774122020-07-05 09:52:18 +053011585 const char *dest, int use_monitor)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011586{
11587#ifdef __linux__
11588 unsigned char buf[1000], *pos;
11589 int s, res;
11590 char bssid[20], addr[20];
11591 char result[32], ssid[100];
11592 size_t ssid_len;
11593
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011594 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011595 sizeof(result)) < 0 ||
11596 strncmp(result, "COMPLETED", 9) != 0) {
11597 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Not connected");
11598 return 0;
11599 }
11600
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011601 if (get_wpa_status(get_station_ifname(dut), "bssid",
11602 bssid, sizeof(bssid)) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011603 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
11604 "current BSSID");
11605 return 0;
11606 }
11607
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011608 if (get_wpa_status(get_station_ifname(dut), "address",
11609 addr, sizeof(addr)) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011610 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
11611 "own MAC address");
11612 return 0;
11613 }
11614
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011615 if (get_wpa_status(get_station_ifname(dut), "ssid", ssid, sizeof(ssid))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011616 < 0) {
11617 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
11618 "current SSID");
11619 return 0;
11620 }
11621 ssid_len = strlen(ssid);
11622
11623 pos = buf;
11624
11625 /* Frame Control */
11626 switch (frame) {
11627 case DISASSOC:
11628 *pos++ = 0xa0;
11629 break;
11630 case DEAUTH:
11631 *pos++ = 0xc0;
11632 break;
11633 case SAQUERY:
11634 *pos++ = 0xd0;
11635 break;
11636 case AUTH:
11637 *pos++ = 0xb0;
11638 break;
11639 case ASSOCREQ:
11640 *pos++ = 0x00;
11641 break;
11642 case REASSOCREQ:
11643 *pos++ = 0x20;
11644 break;
11645 case DLS_REQ:
11646 *pos++ = 0xd0;
11647 break;
11648 }
11649
11650 if (protected == INCORRECT_KEY)
11651 *pos++ = 0x40; /* Set Protected field to 1 */
11652 else
11653 *pos++ = 0x00;
11654
11655 /* Duration */
11656 *pos++ = 0x00;
11657 *pos++ = 0x00;
11658
11659 /* addr1 = DA (current AP) */
11660 hwaddr_aton(bssid, pos);
11661 pos += 6;
11662 /* addr2 = SA (own address) */
11663 hwaddr_aton(addr, pos);
11664 pos += 6;
11665 /* addr3 = BSSID (current AP) */
11666 hwaddr_aton(bssid, pos);
11667 pos += 6;
11668
11669 /* Seq# (to be filled by driver/mac80211) */
11670 *pos++ = 0x00;
11671 *pos++ = 0x00;
11672
11673 if (protected == INCORRECT_KEY) {
11674 /* CCMP parameters */
11675 memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8);
11676 pos += 8;
11677 }
11678
11679 if (protected == INCORRECT_KEY) {
11680 switch (frame) {
11681 case DEAUTH:
11682 /* Reason code (encrypted) */
11683 memcpy(pos, "\xa7\x39", 2);
11684 pos += 2;
11685 break;
11686 case DISASSOC:
11687 /* Reason code (encrypted) */
11688 memcpy(pos, "\xa7\x39", 2);
11689 pos += 2;
11690 break;
11691 case SAQUERY:
11692 /* Category|Action|TransID (encrypted) */
11693 memcpy(pos, "\x6f\xbd\xe9\x4d", 4);
11694 pos += 4;
11695 break;
11696 default:
11697 return -1;
11698 }
11699
11700 /* CCMP MIC */
11701 memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8);
11702 pos += 8;
11703 } else {
11704 switch (frame) {
11705 case DEAUTH:
11706 /* reason code = 8 */
11707 *pos++ = 0x08;
11708 *pos++ = 0x00;
11709 break;
11710 case DISASSOC:
11711 /* reason code = 8 */
11712 *pos++ = 0x08;
11713 *pos++ = 0x00;
11714 break;
11715 case SAQUERY:
11716 /* Category - SA Query */
11717 *pos++ = 0x08;
11718 /* SA query Action - Request */
11719 *pos++ = 0x00;
11720 /* Transaction ID */
11721 *pos++ = 0x12;
11722 *pos++ = 0x34;
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053011723 if (dut->saquery_oci_freq) {
11724 /* OCI IE - Extended ID */
11725 *pos++ = 0xFF;
11726 *pos++ = 0x04;
11727 *pos++ = 0x36;
11728 /* Operating Class */
11729 *pos++ = 0x74;
11730 /* Primary Channel */
11731 *pos++ = freq_to_channel(dut->saquery_oci_freq);
11732 /* Frequency Segment 1 Channel Number */
11733 *pos++ = 0x00;
11734 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011735 break;
11736 case AUTH:
11737 /* Auth Alg (Open) */
11738 *pos++ = 0x00;
11739 *pos++ = 0x00;
11740 /* Seq# */
11741 *pos++ = 0x01;
11742 *pos++ = 0x00;
11743 /* Status code */
11744 *pos++ = 0x00;
11745 *pos++ = 0x00;
11746 break;
11747 case ASSOCREQ:
11748 /* Capability Information */
11749 *pos++ = 0x31;
11750 *pos++ = 0x04;
11751 /* Listen Interval */
11752 *pos++ = 0x0a;
11753 *pos++ = 0x00;
11754 /* SSID */
11755 *pos++ = 0x00;
11756 *pos++ = ssid_len;
11757 memcpy(pos, ssid, ssid_len);
11758 pos += ssid_len;
11759 /* Supported Rates */
11760 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
11761 10);
11762 pos += 10;
11763 /* Extended Supported Rates */
11764 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
11765 pos += 6;
11766 /* RSN */
11767 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
11768 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
11769 "\x00\x00\x00\x00\x0f\xac\x06", 28);
11770 pos += 28;
11771 break;
11772 case REASSOCREQ:
11773 /* Capability Information */
11774 *pos++ = 0x31;
11775 *pos++ = 0x04;
11776 /* Listen Interval */
11777 *pos++ = 0x0a;
11778 *pos++ = 0x00;
11779 /* Current AP */
11780 hwaddr_aton(bssid, pos);
11781 pos += 6;
11782 /* SSID */
11783 *pos++ = 0x00;
11784 *pos++ = ssid_len;
11785 memcpy(pos, ssid, ssid_len);
11786 pos += ssid_len;
11787 /* Supported Rates */
11788 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
11789 10);
11790 pos += 10;
11791 /* Extended Supported Rates */
11792 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
11793 pos += 6;
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053011794 /* RSNE - Group and Pairwise ciphers */
11795 memcpy(pos,
11796 "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x04",
11797 14);
11798 pos += 14;
11799 /* RSNE - AKM Suite count */
11800 *pos++ = 0x01;
11801 *pos++ = 0x00;
11802 /* RSNE - AKM Suites */
11803 if (dut->program == PROGRAM_WPA3)
11804 memcpy(pos, "\x00\x0f\xac\x08", 4);
11805 else
11806 memcpy(pos, "\x00\x0f\xac\x02", 4);
11807 pos += 4;
11808 /* RSNE - Capabilities */
11809 *pos++ = 0xc0;
11810 if (dut->ocvc)
11811 *pos++ = 0x40;
11812 else
11813 *pos++ = 0x00;
11814 /* RSNE - PMKID list and Group Management Ciphers */
11815 memcpy(pos, "\x00\x00\x00\x0f\xac\x06", 6);
11816 pos += 6;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011817 break;
11818 case DLS_REQ:
11819 /* Category - DLS */
11820 *pos++ = 0x02;
11821 /* DLS Action - Request */
11822 *pos++ = 0x00;
11823 /* Destination MACAddress */
11824 if (dest)
11825 hwaddr_aton(dest, pos);
11826 else
11827 memset(pos, 0, 6);
11828 pos += 6;
11829 /* Source MACAddress */
11830 hwaddr_aton(addr, pos);
11831 pos += 6;
11832 /* Capability Information */
11833 *pos++ = 0x10; /* Privacy */
11834 *pos++ = 0x06; /* QoS */
11835 /* DLS Timeout Value */
11836 *pos++ = 0x00;
11837 *pos++ = 0x01;
11838 /* Supported rates */
11839 *pos++ = 0x01;
11840 *pos++ = 0x08;
11841 *pos++ = 0x0c; /* 6 Mbps */
11842 *pos++ = 0x12; /* 9 Mbps */
11843 *pos++ = 0x18; /* 12 Mbps */
11844 *pos++ = 0x24; /* 18 Mbps */
11845 *pos++ = 0x30; /* 24 Mbps */
11846 *pos++ = 0x48; /* 36 Mbps */
11847 *pos++ = 0x60; /* 48 Mbps */
11848 *pos++ = 0x6c; /* 54 Mbps */
11849 /* TODO: Extended Supported Rates */
11850 /* TODO: HT Capabilities */
11851 break;
11852 }
11853 }
11854
Veerendranath Jakkam49774122020-07-05 09:52:18 +053011855 if (use_monitor) {
11856 s = open_monitor("sigmadut");
11857 if (s < 0) {
11858 send_resp(dut, conn, SIGMA_ERROR,
11859 "errorCode,Failed to open monitor socket");
11860 return 0;
11861 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011862
Veerendranath Jakkam49774122020-07-05 09:52:18 +053011863 res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY);
11864 if (res < 0) {
11865 send_resp(dut, conn, SIGMA_ERROR,
11866 "errorCode,Failed to inject frame");
11867 close(s);
11868 return 0;
11869 }
11870 if (res < pos - buf) {
11871 send_resp(dut, conn, SIGMA_ERROR,
11872 "errorCode,Only partial frame sent");
11873 close(s);
11874 return 0;
11875 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011876
Veerendranath Jakkam49774122020-07-05 09:52:18 +053011877 close(s);
11878 } else {
11879#ifdef NL80211_SUPPORT
11880 int freq;
11881 char freq_str[10];
11882
11883 if (get_wpa_status(get_station_ifname(dut), "freq",
11884 freq_str, sizeof(freq_str)) < 0) {
11885 send_resp(dut, conn, SIGMA_ERROR,
11886 "errorCode,Could not get current operating frequency");
11887 return 0;
11888 }
11889 freq = atoi(freq_str);
11890
11891 if (nl80211_send_frame_cmd(dut, intf, buf, pos - buf, freq)) {
11892 send_resp(dut, conn, SIGMA_ERROR,
11893 "errorCode,Failed to inject frame");
11894 return 0;
11895 }
11896#else /* NL80211_SUPPORT */
11897 send_resp(dut, conn, SIGMA_ERROR,
11898 "errorCode,Failed to inject frame (no NL80211_SUPPORT)");
11899 return 0;
11900#endif /* NL80211_SUPPORT */
11901 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011902
11903 return 1;
11904#else /* __linux__ */
11905 send_resp(dut, conn, SIGMA_ERROR, "errorCode,sta_send_frame not "
11906 "yet supported");
11907 return 0;
11908#endif /* __linux__ */
11909}
11910
11911
11912static int cmd_sta_send_frame_tdls(struct sigma_dut *dut,
11913 struct sigma_conn *conn,
11914 struct sigma_cmd *cmd)
11915{
11916 const char *intf = get_param(cmd, "Interface");
11917 const char *sta, *val;
11918 unsigned char addr[ETH_ALEN];
11919 char buf[100];
11920
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030011921 if (!intf)
11922 return -1;
11923
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011924 sta = get_param(cmd, "peer");
11925 if (sta == NULL)
11926 sta = get_param(cmd, "station");
11927 if (sta == NULL) {
11928 send_resp(dut, conn, SIGMA_ERROR,
11929 "ErrorCode,Missing peer address");
11930 return 0;
11931 }
11932 if (hwaddr_aton(sta, addr) < 0) {
11933 send_resp(dut, conn, SIGMA_ERROR,
11934 "ErrorCode,Invalid peer address");
11935 return 0;
11936 }
11937
11938 val = get_param(cmd, "type");
11939 if (val == NULL)
11940 return -1;
11941
11942 if (strcasecmp(val, "DISCOVERY") == 0) {
11943 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", sta);
11944 if (wpa_command(intf, buf) < 0) {
11945 send_resp(dut, conn, SIGMA_ERROR,
11946 "ErrorCode,Failed to send TDLS discovery");
11947 return 0;
11948 }
11949 return 1;
11950 }
11951
11952 if (strcasecmp(val, "SETUP") == 0) {
11953 int status = 0, timeout = 0;
11954
11955 val = get_param(cmd, "Status");
11956 if (val)
11957 status = atoi(val);
11958
11959 val = get_param(cmd, "Timeout");
11960 if (val)
11961 timeout = atoi(val);
11962
11963 if (status != 0 && status != 37) {
11964 send_resp(dut, conn, SIGMA_ERROR,
11965 "ErrorCode,Unsupported status value");
11966 return 0;
11967 }
11968
11969 if (timeout != 0 && timeout != 301) {
11970 send_resp(dut, conn, SIGMA_ERROR,
11971 "ErrorCode,Unsupported timeout value");
11972 return 0;
11973 }
11974
11975 if (status && timeout) {
11976 send_resp(dut, conn, SIGMA_ERROR,
11977 "ErrorCode,Unsupported timeout+status "
11978 "combination");
11979 return 0;
11980 }
11981
11982 if (status == 37 &&
11983 wpa_command(intf, "SET tdls_testing 0x200")) {
11984 send_resp(dut, conn, SIGMA_ERROR,
11985 "ErrorCode,Failed to enable "
11986 "decline setup response test mode");
11987 return 0;
11988 }
11989
11990 if (timeout == 301) {
11991 int res;
11992 if (dut->no_tpk_expiration)
11993 res = wpa_command(intf,
11994 "SET tdls_testing 0x108");
11995 else
11996 res = wpa_command(intf,
11997 "SET tdls_testing 0x8");
11998 if (res) {
11999 send_resp(dut, conn, SIGMA_ERROR,
12000 "ErrorCode,Failed to set short TPK "
12001 "lifetime");
12002 return 0;
12003 }
12004 }
12005
12006 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", sta);
12007 if (wpa_command(intf, buf) < 0) {
12008 send_resp(dut, conn, SIGMA_ERROR,
12009 "ErrorCode,Failed to send TDLS setup");
12010 return 0;
12011 }
12012 return 1;
12013 }
12014
12015 if (strcasecmp(val, "TEARDOWN") == 0) {
12016 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", sta);
12017 if (wpa_command(intf, buf) < 0) {
12018 send_resp(dut, conn, SIGMA_ERROR,
12019 "ErrorCode,Failed to send TDLS teardown");
12020 return 0;
12021 }
12022 return 1;
12023 }
12024
12025 send_resp(dut, conn, SIGMA_ERROR,
12026 "ErrorCode,Unsupported TDLS frame");
12027 return 0;
12028}
12029
12030
12031static int sta_ap_known(const char *ifname, const char *bssid)
12032{
12033 char buf[4096];
12034
Jouni Malinendd32f192018-09-15 02:55:19 +030012035 snprintf(buf, sizeof(buf), "BSS MASK=1 %s", bssid);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012036 if (wpa_command_resp(ifname, buf, buf, sizeof(buf)) < 0)
12037 return 0;
12038 if (strncmp(buf, "id=", 3) != 0)
12039 return 0;
12040 return 1;
12041}
12042
12043
12044static int sta_scan_ap(struct sigma_dut *dut, const char *ifname,
12045 const char *bssid)
12046{
12047 int res;
12048 struct wpa_ctrl *ctrl;
12049 char buf[256];
12050
12051 if (sta_ap_known(ifname, bssid))
12052 return 0;
12053 sigma_dut_print(dut, DUT_MSG_DEBUG,
12054 "AP not in BSS table - start scan");
12055
12056 ctrl = open_wpa_mon(ifname);
12057 if (ctrl == NULL) {
12058 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
12059 "wpa_supplicant monitor connection");
12060 return -1;
12061 }
12062
12063 if (wpa_command(ifname, "SCAN") < 0) {
12064 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to start scan");
12065 wpa_ctrl_detach(ctrl);
12066 wpa_ctrl_close(ctrl);
12067 return -1;
12068 }
12069
12070 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
12071 buf, sizeof(buf));
12072
12073 wpa_ctrl_detach(ctrl);
12074 wpa_ctrl_close(ctrl);
12075
12076 if (res < 0) {
12077 sigma_dut_print(dut, DUT_MSG_INFO, "Scan did not complete");
12078 return -1;
12079 }
12080
12081 if (sta_ap_known(ifname, bssid))
12082 return 0;
12083 sigma_dut_print(dut, DUT_MSG_INFO, "AP not in BSS table");
12084 return -1;
12085}
12086
12087
12088static int cmd_sta_send_frame_hs2_neighadv(struct sigma_dut *dut,
12089 struct sigma_conn *conn,
12090 struct sigma_cmd *cmd,
12091 const char *intf)
12092{
12093 char buf[200];
12094
12095 snprintf(buf, sizeof(buf), "ndsend 2001:DB8::1 %s", intf);
12096 if (system(buf) != 0) {
12097 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Failed to run "
12098 "ndsend");
12099 return 0;
12100 }
12101
12102 return 1;
12103}
12104
12105
12106static int cmd_sta_send_frame_hs2_neighsolreq(struct sigma_dut *dut,
12107 struct sigma_conn *conn,
12108 struct sigma_cmd *cmd,
12109 const char *intf)
12110{
12111 char buf[200];
12112 const char *ip = get_param(cmd, "SenderIP");
12113
Peng Xu26b356d2017-10-04 17:58:16 -070012114 if (!ip)
12115 return 0;
12116
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012117 snprintf(buf, sizeof(buf), "ndisc6 -nm %s %s -r 4", ip, intf);
12118 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
12119 if (system(buf) == 0) {
12120 sigma_dut_print(dut, DUT_MSG_INFO,
12121 "Neighbor Solicitation got a response "
12122 "for %s@%s", ip, intf);
12123 }
12124
12125 return 1;
12126}
12127
12128
12129static int cmd_sta_send_frame_hs2_arpprobe(struct sigma_dut *dut,
12130 struct sigma_conn *conn,
12131 struct sigma_cmd *cmd,
12132 const char *ifname)
12133{
12134 char buf[200];
12135 const char *ip = get_param(cmd, "SenderIP");
12136
12137 if (ip == NULL) {
12138 send_resp(dut, conn, SIGMA_ERROR,
12139 "ErrorCode,Missing SenderIP parameter");
12140 return 0;
12141 }
12142 snprintf(buf, sizeof(buf), "arping -I %s -D %s -c 4", ifname, ip);
12143 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
12144 if (system(buf) != 0) {
12145 sigma_dut_print(dut, DUT_MSG_INFO, "arping DAD got a response "
12146 "for %s@%s", ip, ifname);
12147 }
12148
12149 return 1;
12150}
12151
12152
12153static int cmd_sta_send_frame_hs2_arpannounce(struct sigma_dut *dut,
12154 struct sigma_conn *conn,
12155 struct sigma_cmd *cmd,
12156 const char *ifname)
12157{
12158 char buf[200];
12159 char ip[16];
12160 int s;
Peng Xub3756882017-10-04 14:39:09 -070012161 struct ifreq ifr;
12162 struct sockaddr_in saddr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012163
12164 s = socket(PF_INET, SOCK_DGRAM, 0);
Peng Xub3756882017-10-04 14:39:09 -070012165 if (s < 0) {
12166 perror("socket");
12167 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012168 }
12169
Peng Xub3756882017-10-04 14:39:09 -070012170 memset(&ifr, 0, sizeof(ifr));
12171 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
12172 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
12173 sigma_dut_print(dut, DUT_MSG_INFO,
12174 "Failed to get %s IP address: %s",
12175 ifname, strerror(errno));
12176 close(s);
12177 return -1;
12178 }
12179 close(s);
12180
12181 memcpy(&saddr, &ifr.ifr_addr, sizeof(struct sockaddr_in));
12182 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
12183
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012184 snprintf(buf, sizeof(buf), "arping -I %s -s %s %s -c 4", ifname, ip,
12185 ip);
12186 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
12187 if (system(buf) != 0) {
12188 }
12189
12190 return 1;
12191}
12192
12193
12194static int cmd_sta_send_frame_hs2_arpreply(struct sigma_dut *dut,
12195 struct sigma_conn *conn,
12196 struct sigma_cmd *cmd,
12197 const char *ifname)
12198{
12199 char buf[200], addr[20];
12200 char dst[ETH_ALEN], src[ETH_ALEN];
12201 short ethtype = htons(ETH_P_ARP);
12202 char *pos;
12203 int s, res;
12204 const char *val;
12205 struct sockaddr_in taddr;
12206
12207 val = get_param(cmd, "dest");
12208 if (val)
12209 hwaddr_aton(val, (unsigned char *) dst);
12210
12211 val = get_param(cmd, "DestIP");
12212 if (val)
12213 inet_aton(val, &taddr.sin_addr);
Peng Xu151c9e12017-10-04 14:39:09 -070012214 else
12215 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012216
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012217 if (get_wpa_status(get_station_ifname(dut), "address", addr,
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012218 sizeof(addr)) < 0)
12219 return -2;
12220 hwaddr_aton(addr, (unsigned char *) src);
12221
12222 pos = buf;
12223 *pos++ = 0x00;
12224 *pos++ = 0x01;
12225 *pos++ = 0x08;
12226 *pos++ = 0x00;
12227 *pos++ = 0x06;
12228 *pos++ = 0x04;
12229 *pos++ = 0x00;
12230 *pos++ = 0x02;
12231 memcpy(pos, src, ETH_ALEN);
12232 pos += ETH_ALEN;
12233 memcpy(pos, &taddr.sin_addr, 4);
12234 pos += 4;
12235 memcpy(pos, dst, ETH_ALEN);
12236 pos += ETH_ALEN;
12237 memcpy(pos, &taddr.sin_addr, 4);
12238 pos += 4;
12239
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012240 s = open_monitor(get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012241 if (s < 0) {
12242 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
12243 "monitor socket");
12244 return 0;
12245 }
12246
12247 res = inject_eth_frame(s, buf, pos - buf, ethtype, dst, src);
12248 if (res < 0) {
12249 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
12250 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +053012251 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012252 return 0;
12253 }
12254
12255 close(s);
12256
12257 return 1;
12258}
12259
12260
12261static int cmd_sta_send_frame_hs2_dls_req(struct sigma_dut *dut,
12262 struct sigma_conn *conn,
12263 struct sigma_cmd *cmd,
12264 const char *intf, const char *dest)
12265{
12266 char buf[100];
12267
12268 if (if_nametoindex("sigmadut") == 0) {
12269 snprintf(buf, sizeof(buf),
12270 "iw dev %s interface add sigmadut type monitor",
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012271 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012272 if (system(buf) != 0 ||
12273 if_nametoindex("sigmadut") == 0) {
12274 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
12275 "monitor interface with '%s'", buf);
12276 return -2;
12277 }
12278 }
12279
12280 if (system("ifconfig sigmadut up") != 0) {
12281 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
12282 "monitor interface up");
12283 return -2;
12284 }
12285
Veerendranath Jakkam49774122020-07-05 09:52:18 +053012286 return sta_inject_frame(dut, conn, intf, DLS_REQ, UNPROTECTED, dest, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012287}
12288
12289
12290static int cmd_sta_send_frame_hs2(struct sigma_dut *dut,
12291 struct sigma_conn *conn,
12292 struct sigma_cmd *cmd)
12293{
12294 const char *intf = get_param(cmd, "Interface");
12295 const char *dest = get_param(cmd, "Dest");
12296 const char *type = get_param(cmd, "FrameName");
12297 const char *val;
12298 char buf[200], *pos, *end;
12299 int count, count2;
12300
12301 if (type == NULL)
12302 type = get_param(cmd, "Type");
12303
12304 if (intf == NULL || dest == NULL || type == NULL)
12305 return -1;
12306
12307 if (strcasecmp(type, "NeighAdv") == 0)
12308 return cmd_sta_send_frame_hs2_neighadv(dut, conn, cmd, intf);
12309
12310 if (strcasecmp(type, "NeighSolicitReq") == 0)
12311 return cmd_sta_send_frame_hs2_neighsolreq(dut, conn, cmd, intf);
12312
12313 if (strcasecmp(type, "ARPProbe") == 0)
12314 return cmd_sta_send_frame_hs2_arpprobe(dut, conn, cmd, intf);
12315
12316 if (strcasecmp(type, "ARPAnnounce") == 0)
12317 return cmd_sta_send_frame_hs2_arpannounce(dut, conn, cmd, intf);
12318
12319 if (strcasecmp(type, "ARPReply") == 0)
12320 return cmd_sta_send_frame_hs2_arpreply(dut, conn, cmd, intf);
12321
12322 if (strcasecmp(type, "DLS-request") == 0 ||
12323 strcasecmp(type, "DLSrequest") == 0)
12324 return cmd_sta_send_frame_hs2_dls_req(dut, conn, cmd, intf,
12325 dest);
12326
12327 if (strcasecmp(type, "ANQPQuery") != 0 &&
12328 strcasecmp(type, "Query") != 0) {
12329 send_resp(dut, conn, SIGMA_ERROR,
12330 "ErrorCode,Unsupported HS 2.0 send frame type");
12331 return 0;
12332 }
12333
12334 if (sta_scan_ap(dut, intf, dest) < 0) {
12335 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not find "
12336 "the requested AP");
12337 return 0;
12338 }
12339
12340 pos = buf;
12341 end = buf + sizeof(buf);
12342 count = 0;
12343 pos += snprintf(pos, end - pos, "ANQP_GET %s ", dest);
12344
12345 val = get_param(cmd, "ANQP_CAP_LIST");
12346 if (val && atoi(val)) {
12347 pos += snprintf(pos, end - pos, "%s257", count > 0 ? "," : "");
12348 count++;
12349 }
12350
12351 val = get_param(cmd, "VENUE_NAME");
12352 if (val && atoi(val)) {
12353 pos += snprintf(pos, end - pos, "%s258", count > 0 ? "," : "");
12354 count++;
12355 }
12356
12357 val = get_param(cmd, "NETWORK_AUTH_TYPE");
12358 if (val && atoi(val)) {
12359 pos += snprintf(pos, end - pos, "%s260", count > 0 ? "," : "");
12360 count++;
12361 }
12362
12363 val = get_param(cmd, "ROAMING_CONS");
12364 if (val && atoi(val)) {
12365 pos += snprintf(pos, end - pos, "%s261", count > 0 ? "," : "");
12366 count++;
12367 }
12368
12369 val = get_param(cmd, "IP_ADDR_TYPE_AVAILABILITY");
12370 if (val && atoi(val)) {
12371 pos += snprintf(pos, end - pos, "%s262", count > 0 ? "," : "");
12372 count++;
12373 }
12374
12375 val = get_param(cmd, "NAI_REALM_LIST");
12376 if (val && atoi(val)) {
12377 pos += snprintf(pos, end - pos, "%s263", count > 0 ? "," : "");
12378 count++;
12379 }
12380
12381 val = get_param(cmd, "3GPP_INFO");
12382 if (val && atoi(val)) {
12383 pos += snprintf(pos, end - pos, "%s264", count > 0 ? "," : "");
12384 count++;
12385 }
12386
12387 val = get_param(cmd, "DOMAIN_LIST");
12388 if (val && atoi(val)) {
12389 pos += snprintf(pos, end - pos, "%s268", count > 0 ? "," : "");
12390 count++;
12391 }
12392
Jouni Malinen34cf9532018-04-29 19:26:33 +030012393 val = get_param(cmd, "Venue_URL");
12394 if (val && atoi(val)) {
12395 pos += snprintf(pos, end - pos, "%s277", count > 0 ? "," : "");
12396 count++;
12397 }
12398
Jouni Malinend3bca5d2018-04-29 17:25:23 +030012399 val = get_param(cmd, "Advice_Of_Charge");
12400 if (val && atoi(val)) {
12401 pos += snprintf(pos, end - pos, "%s278", count > 0 ? "," : "");
12402 count++;
12403 }
12404
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012405 if (count && wpa_command(intf, buf)) {
12406 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,ANQP_GET failed");
12407 return 0;
12408 }
12409
12410 pos = buf;
12411 end = buf + sizeof(buf);
12412 count2 = 0;
12413 pos += snprintf(pos, end - pos, "HS20_ANQP_GET %s ", dest);
12414
12415 val = get_param(cmd, "HS_CAP_LIST");
12416 if (val && atoi(val)) {
12417 pos += snprintf(pos, end - pos, "%s2", count2 > 0 ? "," : "");
12418 count2++;
12419 }
12420
12421 val = get_param(cmd, "OPER_NAME");
12422 if (val && atoi(val)) {
12423 pos += snprintf(pos, end - pos, "%s3", count2 > 0 ? "," : "");
12424 count2++;
12425 }
12426
12427 val = get_param(cmd, "WAN_METRICS");
12428 if (!val)
12429 val = get_param(cmd, "WAN_MAT");
12430 if (!val)
12431 val = get_param(cmd, "WAN_MET");
12432 if (val && atoi(val)) {
12433 pos += snprintf(pos, end - pos, "%s4", count2 > 0 ? "," : "");
12434 count2++;
12435 }
12436
12437 val = get_param(cmd, "CONNECTION_CAPABILITY");
12438 if (val && atoi(val)) {
12439 pos += snprintf(pos, end - pos, "%s5", count2 > 0 ? "," : "");
12440 count2++;
12441 }
12442
12443 val = get_param(cmd, "OP_CLASS");
12444 if (val && atoi(val)) {
12445 pos += snprintf(pos, end - pos, "%s7", count2 > 0 ? "," : "");
12446 count2++;
12447 }
12448
12449 val = get_param(cmd, "OSU_PROVIDER_LIST");
12450 if (val && atoi(val)) {
12451 pos += snprintf(pos, end - pos, "%s8", count2 > 0 ? "," : "");
12452 count2++;
12453 }
12454
Jouni Malinenf67afec2018-04-29 19:24:58 +030012455 val = get_param(cmd, "OPER_ICON_METADATA");
12456 if (!val)
12457 val = get_param(cmd, "OPERATOR_ICON_METADATA");
12458 if (val && atoi(val)) {
12459 pos += snprintf(pos, end - pos, "%s12", count2 > 0 ? "," : "");
12460 count2++;
12461 }
12462
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012463 if (count && count2) {
12464 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before sending out "
12465 "second query");
12466 sleep(1);
12467 }
12468
12469 if (count2 && wpa_command(intf, buf)) {
12470 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,HS20_ANQP_GET "
12471 "failed");
12472 return 0;
12473 }
12474
12475 val = get_param(cmd, "NAI_HOME_REALM_LIST");
12476 if (val) {
12477 if (count || count2) {
12478 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
12479 "sending out second query");
12480 sleep(1);
12481 }
12482
12483 if (strcmp(val, "1") == 0)
12484 val = "mail.example.com";
12485 snprintf(buf, end - pos,
12486 "HS20_GET_NAI_HOME_REALM_LIST %s realm=%s",
12487 dest, val);
12488 if (wpa_command(intf, buf)) {
12489 send_resp(dut, conn, SIGMA_ERROR,
12490 "ErrorCode,HS20_GET_NAI_HOME_REALM_LIST "
12491 "failed");
12492 return 0;
12493 }
12494 }
12495
12496 val = get_param(cmd, "ICON_REQUEST");
12497 if (val) {
12498 if (count || count2) {
12499 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
12500 "sending out second query");
12501 sleep(1);
12502 }
12503
12504 snprintf(buf, end - pos,
12505 "HS20_ICON_REQUEST %s %s", dest, val);
12506 if (wpa_command(intf, buf)) {
12507 send_resp(dut, conn, SIGMA_ERROR,
12508 "ErrorCode,HS20_ICON_REQUEST failed");
12509 return 0;
12510 }
12511 }
12512
12513 return 1;
12514}
12515
12516
12517static int ath_sta_send_frame_vht(struct sigma_dut *dut,
12518 struct sigma_conn *conn,
12519 struct sigma_cmd *cmd)
12520{
12521 const char *val;
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012522 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012523 int chwidth, nss;
12524
12525 val = get_param(cmd, "framename");
12526 if (!val)
12527 return -1;
12528 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
12529
12530 /* Command sequence to generate Op mode notification */
12531 if (val && strcasecmp(val, "Op_md_notif_frm") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012532 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012533
12534 /* Disable STBC */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012535 run_iwpriv(dut, ifname, "tx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012536
12537 /* Extract Channel width */
12538 val = get_param(cmd, "Channel_width");
12539 if (val) {
12540 switch (atoi(val)) {
12541 case 20:
12542 chwidth = 0;
12543 break;
12544 case 40:
12545 chwidth = 1;
12546 break;
12547 case 80:
12548 chwidth = 2;
12549 break;
12550 case 160:
12551 chwidth = 3;
12552 break;
12553 default:
12554 chwidth = 2;
12555 break;
12556 }
12557
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012558 run_iwpriv(dut, ifname, "chwidth %d", chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012559 }
12560
12561 /* Extract NSS */
12562 val = get_param(cmd, "NSS");
12563 if (val) {
12564 switch (atoi(val)) {
12565 case 1:
12566 nss = 1;
12567 break;
12568 case 2:
12569 nss = 3;
12570 break;
12571 case 3:
12572 nss = 7;
12573 break;
12574 default:
12575 /* We do not support NSS > 3 */
12576 nss = 3;
12577 break;
12578 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012579 run_iwpriv(dut, ifname, "rxchainmask %d", nss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012580 }
12581
12582 /* Opmode notify */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012583 run_iwpriv(dut, ifname, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012584 }
12585
12586 return 1;
12587}
12588
12589
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070012590static int wcn_sta_set_pmf_config(struct sigma_dut *dut, const char *intf,
12591 enum send_frame_protection protected)
12592{
12593#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +053012594 return wcn_wifi_test_config_set_u8(
12595 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_PMF_PROTECTION,
12596 protected);
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070012597#else /* NL80211_SUPPORT */
12598 sigma_dut_print(dut, DUT_MSG_ERROR,
12599 "PMF config cannot be set without NL80211_SUPPORT defined");
12600 return -1;
12601#endif /* NL80211_SUPPORT */
12602}
12603
12604
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012605static int cmd_sta_send_frame_vht(struct sigma_dut *dut,
12606 struct sigma_conn *conn,
12607 struct sigma_cmd *cmd)
12608{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012609 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012610 case DRIVER_ATHEROS:
12611 return ath_sta_send_frame_vht(dut, conn, cmd);
12612 default:
12613 send_resp(dut, conn, SIGMA_ERROR,
12614 "errorCode,Unsupported sta_set_frame(VHT) with the current driver");
12615 return 0;
12616 }
12617}
12618
12619
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070012620static int wcn_sta_send_disassoc(struct sigma_dut *dut, const char *intf)
12621{
12622#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +053012623 return wcn_wifi_test_config_set_flag(
12624 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_DISASSOC_TX);
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070012625#else /* NL80211_SUPPORT */
12626 sigma_dut_print(dut, DUT_MSG_ERROR,
12627 "Disassoc Tx cannot be done without NL80211_SUPPORT defined");
12628 return -1;
12629#endif /* NL80211_SUPPORT */
12630}
12631
12632
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070012633static int wcn_sta_send_frame_he(struct sigma_dut *dut, struct sigma_conn *conn,
12634 struct sigma_cmd *cmd)
12635{
12636 const char *val;
12637 const char *intf = get_param(cmd, "Interface");
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070012638 enum send_frame_protection protected;
12639 const char *pmf;
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070012640
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030012641 if (!intf)
12642 return -1;
12643
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070012644 val = get_param(cmd, "framename");
12645 if (!val)
12646 return -1;
12647 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
12648
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070012649 pmf = get_param(cmd, "PMFProtected");
12650 if (!pmf)
12651 pmf = get_param(cmd, "Protected");
12652 if (pmf) {
12653 if (strcasecmp(pmf, "Correct-key") == 0 ||
12654 strcasecmp(pmf, "CorrectKey") == 0) {
12655 protected = CORRECT_KEY;
12656 } else if (strcasecmp(pmf, "IncorrectKey") == 0) {
12657 protected = INCORRECT_KEY;
12658 } else if (strcasecmp(pmf, "Unprotected") == 0) {
12659 protected = UNPROTECTED;
12660 } else {
12661 send_resp(dut, conn, SIGMA_ERROR,
12662 "errorCode,Unsupported PMFProtected");
12663 return STATUS_SENT_ERROR;
12664 }
12665 sigma_dut_print(dut, DUT_MSG_DEBUG, "Config PMF protection %d",
12666 protected);
12667 wcn_sta_set_pmf_config(dut, intf, protected);
12668 }
12669
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070012670 /* Command sequence to generate Op mode notification */
12671 if (val && strcasecmp(val, "action") == 0) {
12672 val = get_param(cmd, "PPDUTxType");
12673 if (val && strcasecmp(val, "TB") == 0) {
12674 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 1)) {
12675 sigma_dut_print(dut, DUT_MSG_ERROR,
12676 "failed to send TB PPDU Tx cfg");
12677 send_resp(dut, conn, SIGMA_ERROR,
12678 "ErrorCode,set TB PPDU Tx cfg failed");
12679 return 0;
12680 }
12681 return 1;
12682 }
12683
12684 sigma_dut_print(dut, DUT_MSG_ERROR,
12685 "Action Tx type is not defined");
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070012686
12687 return SUCCESS_SEND_STATUS;
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070012688 }
12689
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070012690 if (strcasecmp(val, "disassoc") == 0)
12691 wcn_sta_send_disassoc(dut, intf);
12692
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070012693 return 1;
12694}
12695
12696
12697static int cmd_sta_send_frame_he(struct sigma_dut *dut,
12698 struct sigma_conn *conn,
12699 struct sigma_cmd *cmd)
12700{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012701 switch (get_driver_type(dut)) {
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070012702 case DRIVER_WCN:
12703 return wcn_sta_send_frame_he(dut, conn, cmd);
12704 default:
12705 send_resp(dut, conn, SIGMA_ERROR,
12706 "errorCode,Unsupported sta_set_frame(HE) with the current driver");
12707 return 0;
12708 }
12709}
12710
12711
Lior David0fe101e2017-03-09 16:09:50 +020012712#ifdef __linux__
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030012713
12714static int
12715wil6210_send_p2p_frame_60g(struct sigma_dut *dut, struct sigma_cmd *cmd,
12716 const char *frame_name, const char *dest_mac)
12717{
12718 int isprobereq = strcasecmp(frame_name, "probereq") == 0;
12719 const char *ssid = get_param(cmd, "ssid");
12720 const char *countstr = get_param(cmd, "count");
12721 const char *channelstr = get_param(cmd, "channel");
12722 const char *group_id = get_param(cmd, "groupid");
12723 const char *client_id = get_param(cmd, "clientmac");
12724 int count, channel, freq, i;
12725 const char *fname;
12726 char frame[1024], src_mac[20], group_id_attr[25],
12727 device_macstr[3 * ETH_ALEN], client_mac[ETH_ALEN];
12728 const char *group_ssid;
12729 const int group_ssid_prefix_len = 9;
12730 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *) frame;
12731 size_t framelen = sizeof(frame);
12732 struct template_frame_tag tags[2];
12733 size_t tags_total = ARRAY_SIZE(tags);
12734 int tag_index, len, dst_len;
12735
12736 if (!countstr || !channelstr) {
12737 sigma_dut_print(dut, DUT_MSG_ERROR,
12738 "Missing argument: count, channel");
12739 return -1;
12740 }
12741 if (isprobereq && !ssid) {
12742 sigma_dut_print(dut, DUT_MSG_ERROR,
12743 "Missing argument: ssid");
12744 return -1;
12745 }
12746 if (!isprobereq && (!group_id || !client_id)) {
12747 sigma_dut_print(dut, DUT_MSG_ERROR,
12748 "Missing argument: group_id, client_id");
12749 return -1;
12750 }
12751
12752 count = atoi(countstr);
12753 channel = atoi(channelstr);
12754 freq = channel_to_freq(dut, channel);
12755
12756 if (!freq) {
12757 sigma_dut_print(dut, DUT_MSG_ERROR,
12758 "invalid channel: %s", channelstr);
12759 return -1;
12760 }
12761
12762 if (isprobereq) {
12763 if (strcasecmp(ssid, "wildcard") == 0) {
12764 fname = "probe_req_wildcard.txt";
12765 } else if (strcasecmp(ssid, "P2P_Wildcard") == 0) {
12766 fname = "probe_req_P2P_Wildcard.txt";
12767 } else {
12768 sigma_dut_print(dut, DUT_MSG_ERROR,
12769 "invalid probe request type");
12770 return -1;
12771 }
12772 } else {
12773 fname = "P2P_device_discovery_req.txt";
12774 }
12775
12776 if (parse_template_frame_file(dut, fname, frame, &framelen,
12777 tags, &tags_total)) {
12778 sigma_dut_print(dut, DUT_MSG_ERROR,
12779 "invalid frame template: %s", fname);
12780 return -1;
12781 }
12782
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012783 if (get_wpa_status(get_station_ifname(dut), "address",
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030012784 src_mac, sizeof(src_mac)) < 0 ||
12785 parse_mac_address(dut, src_mac, &hdr->addr2[0]) ||
12786 parse_mac_address(dut, dest_mac, &hdr->addr1[0]))
12787 return -1;
12788 /* Use wildcard BSSID, since we are in PBSS */
12789 memset(&hdr->addr3, 0xFF, ETH_ALEN);
12790
12791 if (!isprobereq) {
12792 tag_index = find_template_frame_tag(tags, tags_total, 1);
12793 if (tag_index < 0) {
12794 sigma_dut_print(dut, DUT_MSG_ERROR,
12795 "can't find device id attribute");
12796 return -1;
12797 }
12798 if (parse_mac_address(dut, client_id,
12799 (unsigned char *) client_mac)) {
12800 sigma_dut_print(dut, DUT_MSG_ERROR,
12801 "invalid client_id: %s", client_id);
12802 return -1;
12803 }
12804 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
12805 framelen - tags[tag_index].offset,
12806 IEEE80211_P2P_ATTR_DEVICE_ID,
12807 client_mac, ETH_ALEN)) {
12808 sigma_dut_print(dut, DUT_MSG_ERROR,
12809 "fail to replace device id attribute");
12810 return -1;
12811 }
12812
12813 /*
12814 * group_id arg contains device MAC address followed by
12815 * space and SSID (DIRECT-somessid).
12816 * group id attribute contains device address (6 bytes)
12817 * followed by SSID prefix DIRECT-XX (9 bytes)
12818 */
12819 if (strlen(group_id) < sizeof(device_macstr)) {
12820 sigma_dut_print(dut, DUT_MSG_ERROR,
12821 "group_id arg too short");
12822 return -1;
12823 }
12824 memcpy(device_macstr, group_id, sizeof(device_macstr));
12825 device_macstr[sizeof(device_macstr) - 1] = '\0';
12826 if (parse_mac_address(dut, device_macstr,
12827 (unsigned char *) group_id_attr)) {
12828 sigma_dut_print(dut, DUT_MSG_ERROR,
12829 "fail to parse device address from group_id");
12830 return -1;
12831 }
12832 group_ssid = strchr(group_id, ' ');
12833 if (!group_ssid) {
12834 sigma_dut_print(dut, DUT_MSG_ERROR,
12835 "invalid group_id arg, no ssid");
12836 return -1;
12837 }
12838 group_ssid++;
12839 len = strlen(group_ssid);
12840 if (len < group_ssid_prefix_len) {
12841 sigma_dut_print(dut, DUT_MSG_ERROR,
12842 "group_id SSID too short");
12843 return -1;
12844 }
12845 dst_len = sizeof(group_id_attr) - ETH_ALEN;
12846 if (len > dst_len) {
12847 sigma_dut_print(dut, DUT_MSG_ERROR,
12848 "group_id SSID (%s) too long",
12849 group_ssid);
12850 return -1;
12851 }
12852
12853 memcpy(group_id_attr + ETH_ALEN, group_ssid, len);
12854 tag_index = find_template_frame_tag(tags, tags_total, 2);
12855 if (tag_index < 0) {
12856 sigma_dut_print(dut, DUT_MSG_ERROR,
12857 "can't find group id attribute");
12858 return -1;
12859 }
12860 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
12861 framelen - tags[tag_index].offset,
12862 IEEE80211_P2P_ATTR_GROUP_ID,
12863 group_id_attr,
12864 sizeof(group_id_attr))) {
12865 sigma_dut_print(dut, DUT_MSG_ERROR,
12866 "fail to replace group id attribute");
12867 return -1;
12868 }
12869 }
12870
12871 for (i = 0; i < count; i++) {
12872 if (wil6210_transmit_frame(dut, freq,
12873 WIL_TRANSMIT_FRAME_DEFAULT_ROC,
12874 frame, framelen)) {
12875 sigma_dut_print(dut, DUT_MSG_ERROR,
12876 "fail to transmit probe request frame");
12877 return -1;
12878 }
12879 }
12880
12881 return 0;
12882}
12883
12884
Lior David0fe101e2017-03-09 16:09:50 +020012885int wil6210_send_frame_60g(struct sigma_dut *dut, struct sigma_conn *conn,
12886 struct sigma_cmd *cmd)
12887{
12888 const char *frame_name = get_param(cmd, "framename");
12889 const char *mac = get_param(cmd, "dest_mac");
12890
12891 if (!frame_name || !mac) {
12892 sigma_dut_print(dut, DUT_MSG_ERROR,
12893 "framename and dest_mac must be provided");
12894 return -1;
12895 }
12896
12897 if (strcasecmp(frame_name, "brp") == 0) {
12898 const char *l_rx = get_param(cmd, "L-RX");
12899 int l_rx_i;
12900
12901 if (!l_rx) {
12902 sigma_dut_print(dut, DUT_MSG_ERROR,
12903 "L-RX must be provided");
12904 return -1;
12905 }
12906 l_rx_i = atoi(l_rx);
12907
12908 sigma_dut_print(dut, DUT_MSG_INFO,
12909 "dev_send_frame: BRP-RX, dest_mac %s, L-RX %s",
12910 mac, l_rx);
12911 if (l_rx_i != 16) {
12912 sigma_dut_print(dut, DUT_MSG_ERROR,
12913 "unsupported L-RX: %s", l_rx);
12914 return -1;
12915 }
12916
12917 if (wil6210_send_brp_rx(dut, mac, l_rx_i))
12918 return -1;
12919 } else if (strcasecmp(frame_name, "ssw") == 0) {
12920 sigma_dut_print(dut, DUT_MSG_INFO,
12921 "dev_send_frame: SLS, dest_mac %s", mac);
12922 if (wil6210_send_sls(dut, mac))
12923 return -1;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030012924 } else if ((strcasecmp(frame_name, "probereq") == 0) ||
12925 (strcasecmp(frame_name, "devdiscreq") == 0)) {
12926 sigma_dut_print(dut, DUT_MSG_INFO,
12927 "dev_send_frame: %s, dest_mac %s", frame_name,
12928 mac);
12929 if (wil6210_send_p2p_frame_60g(dut, cmd, frame_name, mac))
12930 return -1;
Lior David0fe101e2017-03-09 16:09:50 +020012931 } else {
12932 sigma_dut_print(dut, DUT_MSG_ERROR,
12933 "unsupported frame type: %s", frame_name);
12934 return -1;
12935 }
12936
12937 return 1;
12938}
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030012939
Lior David0fe101e2017-03-09 16:09:50 +020012940#endif /* __linux__ */
12941
12942
12943static int cmd_sta_send_frame_60g(struct sigma_dut *dut,
12944 struct sigma_conn *conn,
12945 struct sigma_cmd *cmd)
12946{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012947 switch (get_driver_type(dut)) {
Lior David0fe101e2017-03-09 16:09:50 +020012948#ifdef __linux__
12949 case DRIVER_WIL6210:
12950 return wil6210_send_frame_60g(dut, conn, cmd);
12951#endif /* __linux__ */
12952 default:
12953 send_resp(dut, conn, SIGMA_ERROR,
12954 "errorCode,Unsupported sta_set_frame(60G) with the current driver");
12955 return 0;
12956 }
12957}
12958
12959
Ashwini Patildb59b3c2017-04-13 15:19:23 +053012960static int mbo_send_anqp_query(struct sigma_dut *dut, struct sigma_conn *conn,
12961 const char *intf, struct sigma_cmd *cmd)
12962{
12963 const char *val, *addr;
12964 char buf[100];
12965
12966 addr = get_param(cmd, "DestMac");
12967 if (!addr) {
12968 send_resp(dut, conn, SIGMA_INVALID,
12969 "ErrorCode,AP MAC address is missing");
12970 return 0;
12971 }
12972
12973 val = get_param(cmd, "ANQPQuery_ID");
12974 if (!val) {
12975 send_resp(dut, conn, SIGMA_INVALID,
12976 "ErrorCode,Missing ANQPQuery_ID");
12977 return 0;
12978 }
12979
12980 if (strcasecmp(val, "NeighborReportReq") == 0) {
12981 snprintf(buf, sizeof(buf), "ANQP_GET %s 272", addr);
12982 } else if (strcasecmp(val, "QueryListWithCellPref") == 0) {
12983 snprintf(buf, sizeof(buf), "ANQP_GET %s 272,mbo:2", addr);
12984 } else {
12985 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid ANQPQuery_ID: %s",
12986 val);
12987 send_resp(dut, conn, SIGMA_INVALID,
12988 "ErrorCode,Invalid ANQPQuery_ID");
12989 return 0;
12990 }
12991
Ashwini Patild174f2c2017-04-13 16:49:46 +053012992 /* Set gas_address3 field to IEEE 802.11-2012 standard compliant form
12993 * (Address3 = Wildcard BSSID when sent to not-associated AP;
12994 * if associated, AP BSSID).
12995 */
12996 if (wpa_command(intf, "SET gas_address3 1") < 0) {
12997 send_resp(dut, conn, SIGMA_ERROR,
12998 "ErrorCode,Failed to set gas_address3");
12999 return 0;
13000 }
13001
Ashwini Patildb59b3c2017-04-13 15:19:23 +053013002 if (wpa_command(intf, buf) < 0) {
13003 send_resp(dut, conn, SIGMA_ERROR,
13004 "ErrorCode,Failed to send ANQP query");
13005 return 0;
13006 }
13007
13008 return 1;
13009}
13010
13011
13012static int mbo_cmd_sta_send_frame(struct sigma_dut *dut,
13013 struct sigma_conn *conn,
13014 const char *intf,
13015 struct sigma_cmd *cmd)
13016{
13017 const char *val = get_param(cmd, "FrameName");
13018
13019 if (val && strcasecmp(val, "ANQPQuery") == 0)
13020 return mbo_send_anqp_query(dut, conn, intf, cmd);
13021
13022 return 2;
13023}
13024
13025
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053013026static enum sigma_cmd_result cmd_sta_send_frame_wpa3(struct sigma_dut *dut,
13027 struct sigma_conn *conn,
13028 const char *intf,
13029 struct sigma_cmd *cmd)
13030{
13031 const char *val = get_param(cmd, "framename");
13032
13033 if (!val)
13034 return INVALID_SEND_STATUS;
13035
13036 if (strcasecmp(val, "SAQueryReq") == 0) {
13037 val = get_param(cmd, "OCIChannel");
13038
13039 if (!val) {
13040 send_resp(dut, conn, SIGMA_ERROR,
13041 "errorCode,OCIChannel not present");
13042 return STATUS_SENT_ERROR;
13043 }
13044
13045 dut->saquery_oci_freq = channel_to_freq(dut, atoi(val));
13046 if (!dut->saquery_oci_freq) {
13047 send_resp(dut, conn, SIGMA_ERROR,
13048 "errorCode,Invalid OCIChannel number");
13049 return STATUS_SENT_ERROR;
13050 }
13051
13052 return sta_inject_frame(dut, conn, intf, SAQUERY, CORRECT_KEY,
13053 NULL, 0);
13054 }
13055
13056 if (strcasecmp(val, "reassocreq") == 0)
13057 return sta_inject_frame(dut, conn, intf, REASSOCREQ,
13058 CORRECT_KEY, NULL, 0);
13059
Veerendranath9f81dfb2020-08-10 01:21:29 -070013060 if (strcasecmp(val, "ANQPQuery") == 0) {
13061 char buf[50];
13062 const char *dest = get_param(cmd, "DestMac");
13063 const char *chan = get_param(cmd, "channel");
Veerendranath Jakkam78862fc2020-11-19 21:23:27 +053013064 const char *freq_str = get_param(cmd, "ChnlFreq");
Veerendranath9f81dfb2020-08-10 01:21:29 -070013065 int len, freq;
13066
Veerendranath Jakkam78862fc2020-11-19 21:23:27 +053013067 if (freq_str)
13068 freq = atoi(freq_str);
13069 else
13070 freq = chan ? channel_to_freq(dut, atoi(chan)) : 0;
13071
Veerendranath9f81dfb2020-08-10 01:21:29 -070013072 if (!dest || !freq)
13073 return INVALID_SEND_STATUS;
13074
13075 len = snprintf(buf, sizeof(buf), "ANQP_GET %s freq=%d 257",
13076 dest, freq);
13077 if (len < 0 || len >= sizeof(buf)) {
13078 sigma_dut_print(dut, DUT_MSG_ERROR,
13079 "Failed to allocate buf");
13080 return ERROR_SEND_STATUS;
13081 }
13082
13083 if (wpa_command(intf, buf) != 0) {
13084 send_resp(dut, conn, SIGMA_ERROR,
13085 "ErrorCode,Failed to send ANQP Query frame");
13086 return STATUS_SENT_ERROR;
13087 }
13088
13089 sigma_dut_print(dut, DUT_MSG_DEBUG,
13090 "ANQP Query sent: %s", buf);
13091
13092 return SUCCESS_SEND_STATUS;
13093 }
13094
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053013095 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported framename");
13096 return STATUS_SENT_ERROR;
13097}
13098
13099
Vinita S. Malooca85fd22021-01-15 02:54:34 +053013100static int
13101get_type4_frame_classifier(struct sigma_dut *dut, struct sigma_cmd *cmd,
13102 char *pos, int rem_len, int num_of_scs_desc,
13103 int num_of_tclas_elem)
13104{
13105 const char *val;
13106 int ipv6;
13107 int len, total_len = 0;
13108
13109 val = get_param_fmt(cmd, "TCLASElem_Version_%d_%d", num_of_scs_desc,
13110 num_of_tclas_elem);
13111 if (!val) {
13112 sigma_dut_print(dut, DUT_MSG_ERROR, "%s: ip_version empty",
13113 __func__);
13114 return -1;
13115 }
13116
13117 if (strcmp(val, "6") == 0) {
13118 ipv6 = 1;
13119 } else if (strcmp(val, "4") == 0) {
13120 ipv6 = 0;
13121 } else {
13122 sigma_dut_print(dut, DUT_MSG_ERROR, "%s: ip_version invalid",
13123 __func__);
13124 return -1;
13125 }
13126
13127 len = snprintf(pos, rem_len, " ip_version=%s", ipv6 ? "ipv6" : "ipv4");
13128 if (len < 0 || len >= rem_len)
13129 return -1;
13130
13131 pos += len;
13132 rem_len -= len;
13133 total_len += len;
13134
13135 val = get_param_fmt(cmd, "TCLASElem_SourceIPAddr_%d_%d",
13136 num_of_scs_desc, num_of_tclas_elem);
13137 if (val) {
13138 len = snprintf(pos, rem_len, " src_ip=%s", val);
13139 if (len < 0 || len >= rem_len)
13140 return -1;
13141
13142 pos += len;
13143 rem_len -= len;
13144 total_len += len;
13145 }
13146
13147 val = get_param_fmt(cmd, "TCLASElem_DestinationIPAddr_%d_%d",
13148 num_of_scs_desc, num_of_tclas_elem);
13149 if (val) {
13150 len = snprintf(pos, rem_len, " dst_ip=%s", val);
13151 if (len < 0 || len >= rem_len)
13152 return -1;
13153
13154 pos += len;
13155 rem_len -= len;
13156 total_len += len;
13157 }
13158
13159 val = get_param_fmt(cmd, "TCLASElem_SourcePort_%d_%d", num_of_scs_desc,
13160 num_of_tclas_elem);
13161 if (val) {
13162 len = snprintf(pos, rem_len, " src_port=%s", val);
13163 if (len < 0 || len >= rem_len)
13164 return -1;
13165
13166 pos += len;
13167 rem_len -= len;
13168 total_len += len;
13169 }
13170
13171 val = get_param_fmt(cmd, "TCLASElem_DestinationPort_%d_%d",
13172 num_of_scs_desc, num_of_tclas_elem);
13173 if (val) {
13174 len = snprintf(pos, rem_len, " dst_port=%s", val);
13175 if (len < 0 || len >= rem_len)
13176 return -1;
13177
13178 pos += len;
13179 rem_len -= len;
13180 total_len += len;
13181 }
13182
13183 val = get_param_fmt(cmd, "TCLASElem_DSCP_%d_%d", num_of_scs_desc,
13184 num_of_tclas_elem);
13185 if (val) {
13186 len = snprintf(pos, rem_len, " dscp=%s", val);
13187 if (len < 0 || len >= rem_len)
13188 return -1;
13189
13190 pos += len;
13191 rem_len -= len;
13192 total_len += len;
13193 }
13194
13195 val = get_param_fmt(cmd, "TCLASElem_ProtocolNxtHeader_%d_%d",
13196 num_of_scs_desc, num_of_tclas_elem);
13197 if (val) {
13198 char *prot;
13199
13200 switch (atoi(val)) {
13201 case 17:
13202 prot = "udp";
13203 break;
13204 case 6:
13205 prot = "tcp";
13206 break;
13207 case 50:
13208 prot = "esp";
13209 break;
13210 default:
13211 sigma_dut_print(dut, DUT_MSG_ERROR,
13212 "Invalid protocol %d", atoi(val));
13213 return -1;
13214 }
13215
13216 if (ipv6)
13217 len = snprintf(pos, rem_len, " next_header=%s", prot);
13218 else
13219 len = snprintf(pos, rem_len, " protocol=%s", prot);
13220 if (len < 0 || len >= rem_len)
13221 return -1;
13222
13223 pos += len;
13224 rem_len -= len;
13225 total_len += len;
13226 }
13227
13228 return total_len;
13229}
13230
13231
13232static int
13233get_type10_frame_classifier(struct sigma_dut *dut, struct sigma_cmd *cmd,
13234 char *pos, int rem_len, int num_of_scs_desc,
13235 int num_of_tclas_elem)
13236{
13237 const char *val;
13238 int len, total_len = 0;
13239
13240 val = get_param_fmt(cmd, "TCLASElem_ProtoInstance_%d_%d",
13241 num_of_scs_desc, num_of_tclas_elem);
13242 if (val) {
13243 len = snprintf(pos, rem_len, " prot_instance=%s",
13244 val);
13245 if (len < 0 || len >= rem_len)
13246 return -1;
13247
13248 pos += len;
13249 rem_len -= len;
13250 total_len += len;
13251 }
13252
13253 val = get_param_fmt(cmd, "TCLASElem_ProtoNumNextHeader_%d_%d",
13254 num_of_scs_desc, num_of_tclas_elem);
13255 if (val) {
13256 char *prot;
13257
13258 switch (atoi(val)) {
13259 case 17:
13260 prot = "udp";
13261 break;
13262 case 6:
13263 prot = "tcp";
13264 break;
13265 case 50:
13266 prot = "esp";
13267 break;
13268 default:
13269 sigma_dut_print(dut, DUT_MSG_ERROR,
13270 "Invalid protocol %d",
13271 atoi(val));
13272 return -1;
13273 }
13274
13275 len = snprintf(pos, rem_len, " prot_number=%s", prot);
13276 if (len < 0 || len >= rem_len)
13277 return -1;
13278
13279 pos += len;
13280 rem_len -= len;
13281 total_len += len;
13282 }
13283
13284 val = get_param_fmt(cmd, "TCLASElem_FilterValue_%d_%d",
13285 num_of_scs_desc, num_of_tclas_elem);
13286 if (val) {
13287 len = snprintf(pos, rem_len, " filter_value=%s", (val + 2));
13288 if (len < 0 || len >= rem_len)
13289 return -1;
13290
13291 pos += len;
13292 rem_len -= len;
13293 total_len += len;
13294 }
13295
13296 val = get_param_fmt(cmd, "TCLASElem_FilterMask_%d_%d", num_of_scs_desc,
13297 num_of_tclas_elem);
13298 if (val && strlen(val) >= 2) {
13299 len = snprintf(pos, rem_len, " filter_mask=%s", val + 2);
13300 if (len < 0 || len >= rem_len)
13301 return -1;
13302
13303 pos += len;
13304 rem_len -= len;
13305 total_len += len;
13306 }
13307
13308 return total_len;
13309}
13310
13311
13312static enum sigma_cmd_result
13313cmd_sta_send_frame_scs(struct sigma_dut *dut, struct sigma_conn *conn,
13314 const char *intf, struct sigma_cmd *cmd)
13315{
13316 char buf[4096], *pos;
13317 const char *val, *scs_id, *classifier_type;
13318 int len, rem_len, total_bytes;
13319 int num_of_scs_desc = 0, num_of_tclas_elem = 0;
13320
13321 scs_id = get_param(cmd, "SCSDescrElem_SCSID_1");
13322 if (!scs_id) {
13323 sigma_dut_print(dut, DUT_MSG_ERROR, "SCS ID empty");
13324 return INVALID_SEND_STATUS;
13325 }
13326
13327 rem_len = sizeof(buf);
13328 pos = buf;
13329
13330 len = snprintf(buf, sizeof(buf), "SCS");
13331 if (len < 0 || len > rem_len)
13332 goto fail;
13333
13334 pos += len;
13335 rem_len -= len;
13336
13337 while (scs_id) {
13338 num_of_scs_desc++;
13339
13340 val = get_param_fmt(cmd, "SCSDescrElem_RequestType_%d",
13341 num_of_scs_desc);
13342 if (!val)
13343 return INVALID_SEND_STATUS;
13344
13345 if (strcasecmp(val, "Add") == 0) {
13346 len = snprintf(pos, rem_len, " scs_id=%s add",
13347 scs_id);
13348 } else if (strcasecmp(val, "Change") == 0) {
13349 len = snprintf(pos, rem_len, " scs_id=%s change",
13350 scs_id);
13351 } else if (strcasecmp(val, "Remove") == 0) {
13352 len = snprintf(pos, rem_len, " scs_id=%s remove",
13353 scs_id);
13354 if (len < 0 || len >= rem_len)
13355 goto fail;
13356
13357 pos += len;
13358 rem_len -= len;
13359 goto scs_desc_end;
13360 } else {
13361 sigma_dut_print(dut, DUT_MSG_ERROR,
13362 "%s: request type - %s is invalid",
13363 __func__, val);
13364 return INVALID_SEND_STATUS;
13365 }
13366
13367 if (len < 0 || len >= rem_len)
13368 goto fail;
13369
13370 pos += len;
13371 rem_len -= len;
13372
13373 val = get_param_fmt(cmd, "IntraAccessCatElem_UP_%d",
13374 num_of_scs_desc);
13375 if (!val) {
13376 sigma_dut_print(dut, DUT_MSG_ERROR,
13377 "IntraAccess Priority empty");
13378 return INVALID_SEND_STATUS;
13379 }
13380
13381 len = snprintf(pos, rem_len, " scs_up=%s", val);
13382 if (len < 0 || len >= rem_len)
13383 goto fail;
13384
13385 pos += len;
13386 rem_len -= len;
13387
13388 classifier_type = get_param_fmt(cmd,
13389 "TCLASElem_ClassifierType_%d_1",
13390 num_of_scs_desc);
13391 if (!classifier_type) {
13392 sigma_dut_print(dut, DUT_MSG_ERROR,
13393 "classifier type missing");
13394 return INVALID_SEND_STATUS;
13395 }
13396
13397 while (classifier_type) {
13398 num_of_tclas_elem++;
13399
13400 len = snprintf(pos, rem_len, " classifier_type=%s",
13401 classifier_type);
13402 if (len < 0 || len >= rem_len)
13403 goto fail;
13404
13405 pos += len;
13406 rem_len -= len;
13407
13408 if (strcmp(classifier_type, "10") == 0) {
13409 total_bytes = get_type10_frame_classifier(
13410 dut, cmd, pos, rem_len,
13411 num_of_scs_desc,
13412 num_of_tclas_elem);
13413 } else if (strcmp(classifier_type, "4") == 0) {
13414 total_bytes = get_type4_frame_classifier(
13415 dut, cmd, pos, rem_len,
13416 num_of_scs_desc,
13417 num_of_tclas_elem);
13418 } else {
13419 sigma_dut_print(dut, DUT_MSG_ERROR,
13420 "classifier_type invalid");
13421 goto fail;
13422 }
13423
13424 if (total_bytes < 0)
13425 goto fail;
13426
13427 pos += total_bytes;
13428 rem_len -= total_bytes;
13429
13430 classifier_type = get_param_fmt(
13431 cmd, "TCLASElem_ClassifierType_%d_%d",
13432 num_of_scs_desc, num_of_tclas_elem + 1);
13433 }
13434
13435 if (num_of_tclas_elem > 1) {
13436 val = get_param_fmt(cmd,
13437 "TCLASProcessingElem_Processing_%d",
13438 num_of_scs_desc);
13439 if (!val) {
13440 sigma_dut_print(dut, DUT_MSG_ERROR,
13441 "Tclas_processing element %d empty",
13442 num_of_scs_desc);
13443 goto fail;
13444 }
13445
13446 len = snprintf(pos, rem_len,
13447 " tclas_processing=%s", val);
13448 if (len < 0 || len >= rem_len)
13449 goto fail;
13450
13451 pos += len;
13452 rem_len -= len;
13453 }
13454scs_desc_end:
13455 num_of_tclas_elem = 0;
13456 scs_id = get_param_fmt(cmd, "SCSDescrElem_SCSID_%d",
13457 num_of_scs_desc + 1);
13458 }
13459
13460 if (wpa_command(intf, buf) != 0) {
13461 send_resp(dut, conn, SIGMA_ERROR,
13462 "ErrorCode,Failed to send SCS frame request");
13463 return STATUS_SENT_ERROR;
13464 }
13465
13466 sigma_dut_print(dut, DUT_MSG_DEBUG,
13467 "SCS frame request sent: %s", buf);
13468
13469 return SUCCESS_SEND_STATUS;
13470fail:
13471 sigma_dut_print(dut, DUT_MSG_ERROR,
13472 "Failed to create SCS frame request");
13473 return ERROR_SEND_STATUS;
13474}
13475
13476
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053013477static enum sigma_cmd_result
13478cmd_sta_send_frame_mscs(struct sigma_dut *dut, struct sigma_conn *conn,
13479 const char *intf, struct sigma_cmd *cmd)
13480{
13481 char buf[128], *pos;
13482 const char *val, *classifier_type = "04", *type;
13483 int len, rem_len;
13484 u8 up_bitmap;
13485
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053013486 type = get_param(cmd, "Request_Type");
Vinita S. Malooca85fd22021-01-15 02:54:34 +053013487 if (!type) {
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053013488 sigma_dut_print(dut, DUT_MSG_ERROR,
Vinita S. Malooca85fd22021-01-15 02:54:34 +053013489 "%s: type not valid", __func__);
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053013490 return INVALID_SEND_STATUS;
13491 }
13492
13493 rem_len = sizeof(buf);
13494 pos = buf;
13495 if (strcasecmp(type, "add") == 0) {
13496 len = snprintf(pos, rem_len, "MSCS add");
13497 } else if (strcasecmp(type, "update") == 0) {
13498 len = snprintf(pos, rem_len, "MSCS change");
13499 } else if (strcasecmp(type, "remove") == 0) {
13500 if (wpa_command(intf, "MSCS remove") != 0) {
13501 send_resp(dut, conn, SIGMA_ERROR,
13502 "ErrorCode,Failed to send MSCS frame req");
13503 return STATUS_SENT_ERROR;
13504 }
13505 return SUCCESS_SEND_STATUS;
13506 } else {
13507 sigma_dut_print(dut, DUT_MSG_ERROR,
13508 "%s: request type invalid", __func__);
13509 return INVALID_SEND_STATUS;
13510 }
13511
13512 if (len < 0 || len >= rem_len)
13513 goto fail;
13514
13515 pos += len;
13516 rem_len -= len;
13517
13518 val = get_param(cmd, "User_Priority_Bitmap");
13519 if (!val) {
13520 sigma_dut_print(dut, DUT_MSG_ERROR,
13521 "%s: user priority bitmap empty", __func__);
13522 return INVALID_SEND_STATUS;
13523 }
13524
13525 switch (atoi(val)) {
13526 case 0:
13527 up_bitmap = 0x00;
13528 break;
13529 case 1:
13530 up_bitmap = 0xF0;
13531 break;
13532 case 2:
13533 up_bitmap = 0xF6;
13534 break;
13535 default:
13536 sigma_dut_print(dut, DUT_MSG_ERROR,
13537 "%s: Unknown User_Priority_Bitmap value %d",
13538 __func__, atoi(val));
13539 return INVALID_SEND_STATUS;
13540 }
13541
13542 len = snprintf(pos, rem_len, " up_bitmap=%02x", up_bitmap);
13543 if (len < 0 || len >= rem_len)
13544 goto fail;
13545
13546 pos += len;
13547 rem_len -= len;
13548
13549 val = get_param(cmd, "User_Priority_Limit");
13550 if (!val) {
13551 sigma_dut_print(dut, DUT_MSG_ERROR,
13552 "%s: invalid user priority limit", __func__);
13553 return INVALID_SEND_STATUS;
13554 }
13555
13556 len = snprintf(pos, rem_len, " up_limit=%s", val);
13557 if (len < 0 || len >= rem_len)
13558 goto fail;
13559
13560 pos += len;
13561 rem_len -= len;
13562
13563 val = get_param(cmd, "Stream_Timeout");
13564 if (!val)
13565 val = get_param(cmd, "Stream_Timtout");
13566 if (!val) {
13567 sigma_dut_print(dut, DUT_MSG_ERROR,
13568 "%s: invalid stream timeout", __func__);
13569 return INVALID_SEND_STATUS;
13570 }
13571
13572 len = snprintf(pos, rem_len, " stream_timeout=%s", val);
13573 if (len < 0 || len >= rem_len)
13574 goto fail;
13575
13576 pos += len;
13577 rem_len -= len;
13578
13579 val = get_param(cmd, "TCLAS_Mask");
13580 if (!val) {
13581 sigma_dut_print(dut, DUT_MSG_ERROR,
13582 "%s: invalid tclas mask", __func__);
13583 return INVALID_SEND_STATUS;
13584 }
13585
13586 len = snprintf(pos, rem_len, " frame_classifier=%s%lx%032x",
13587 classifier_type, strtol(val, NULL, 2), 0);
13588 if (len < 0 || len >= rem_len)
13589 goto fail;
13590
13591 if (wpa_command(intf, buf) != 0) {
13592 send_resp(dut, conn, SIGMA_ERROR,
13593 "ErrorCode,Failed to send MSCS frame req");
13594 return STATUS_SENT_ERROR;
13595 }
13596
13597 sigma_dut_print(dut, DUT_MSG_DEBUG,
13598 "MSCS frame request sent: %s", buf);
13599
13600 return SUCCESS_SEND_STATUS;
13601fail:
13602 sigma_dut_print(dut, DUT_MSG_ERROR,
13603 "Failed to create MSCS frame req");
13604 return ERROR_SEND_STATUS;
13605}
13606
13607
Vinita S. Malooca85fd22021-01-15 02:54:34 +053013608static enum sigma_cmd_result
Veerendranath Jakkam329a3cd2021-09-11 18:10:13 +053013609cmd_sta_send_frame_dscp_query(struct sigma_dut *dut, struct sigma_conn *conn,
13610 const char *intf, struct sigma_cmd *cmd)
13611{
13612 char buf[150], *pos;
13613 const char *val;
13614 int len, rem_len;
13615
13616 rem_len = sizeof(buf);
13617 pos = buf;
13618
13619 len = snprintf(pos, rem_len, "DSCP_QUERY");
13620 if (len < 0 || len >= rem_len)
13621 goto fail;
13622
13623 pos += len;
13624 rem_len -= len;
13625
13626 val = get_param(cmd, "Wildcard");
13627 if (val && strcasecmp(val, "Yes") == 0) {
13628 len = snprintf(pos, rem_len, " wildcard");
13629 if (len < 0 || len >= rem_len)
13630 goto fail;
13631 } else if (strlen(dut->qm_domain_name)) {
13632 len = snprintf(pos, rem_len, " domain_name=%s",
13633 dut->qm_domain_name);
13634 if (len < 0 || len >= rem_len)
13635 goto fail;
13636 } else {
13637 sigma_dut_print(dut, DUT_MSG_ERROR,
13638 "Invalid DSCP Query configuration");
13639 return INVALID_SEND_STATUS;
13640 }
13641
13642 if (wpa_command(intf, buf) != 0) {
13643 send_resp(dut, conn, SIGMA_ERROR,
13644 "ErrorCode,Failed to send DSCP policy query frame");
13645 return STATUS_SENT_ERROR;
13646 }
13647
13648 sigma_dut_print(dut, DUT_MSG_DEBUG,
13649 "DSCP policy query frame sent: %s", buf);
13650 return SUCCESS_SEND_STATUS;
13651fail:
13652 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to send DSCP query");
13653 return ERROR_SEND_STATUS;
13654}
13655
13656
13657static enum sigma_cmd_result
Veerendranath Jakkam1bf1bd62021-09-12 16:35:55 +053013658cmd_sta_send_frame_dscp_response(struct sigma_dut *dut, struct sigma_conn *conn,
13659 const char *intf, struct sigma_cmd *cmd)
13660{
13661 char buf[256], *pos, *item, *list, *saveptr;
13662 const char *val;
13663 int len, rem_len;
13664
13665 pos = buf;
13666 rem_len = sizeof(buf);
13667
13668 len = snprintf(pos, rem_len, "DSCP_RESP");
13669 if (snprintf_error(rem_len, len)) {
13670 sigma_dut_print(dut, DUT_MSG_ERROR,
13671 "Failed to create DSCP Policy Response command");
13672 return ERROR_SEND_STATUS;
13673 }
13674
13675 pos += len;
13676 rem_len -= len;
13677
13678 val = get_param(cmd, "PolicyID_List");
13679 if (!val) {
13680 sigma_dut_print(dut, DUT_MSG_ERROR,
13681 "DSCP policy ID list missing");
13682 return INVALID_SEND_STATUS;
13683 }
13684
13685 list = strdup(val);
13686 if (!list)
13687 return ERROR_SEND_STATUS;
13688
13689 item = strtok_r(list, "_", &saveptr);
13690 while (item) {
13691 unsigned int i;
13692 int policy_id = atoi(item);
13693
13694 for (i = 0; i < dut->num_dscp_status; i++)
13695 if (dut->dscp_status[i].id == policy_id)
13696 break;
13697
13698 if (i == dut->num_dscp_status) {
13699 free(list);
13700 send_resp(dut, conn, SIGMA_ERROR,
13701 "ErrorCode,DSCP policy id not found in status list");
13702 return STATUS_SENT_ERROR;
13703 }
13704
13705 len = snprintf(pos, rem_len, " policy_id=%d status=%d",
13706 policy_id, dut->dscp_status[i].status);
13707 if (snprintf_error(rem_len, len)) {
13708 free(list);
13709 sigma_dut_print(dut, DUT_MSG_ERROR,
13710 "Failed to write DSCP policy list");
13711 return ERROR_SEND_STATUS;
13712 }
13713
13714 pos += len;
13715 rem_len -= len;
13716
13717 if (dut->dscp_status[i].status)
13718 remove_dscp_policy(dut, policy_id);
13719
13720 item = strtok_r(NULL, "_", &saveptr);
13721 }
13722
13723 free(list);
13724
13725 if (wpa_command(intf, buf) != 0) {
13726 send_resp(dut, conn, SIGMA_ERROR,
13727 "ErrorCode,Failed to send DSCP Policy Response frame");
13728 return STATUS_SENT_ERROR;
13729 }
13730
13731 sigma_dut_print(dut, DUT_MSG_DEBUG,
13732 "DSCP Policy Response frame sent: %s", buf);
13733 return SUCCESS_SEND_STATUS;
13734}
13735
13736
13737static enum sigma_cmd_result
Vinita S. Malooca85fd22021-01-15 02:54:34 +053013738cmd_sta_send_frame_qm(struct sigma_dut *dut, struct sigma_conn *conn,
13739 const char *intf, struct sigma_cmd *cmd)
13740{
13741 const char *val;
13742
13743 val = get_param(cmd, "FrameName");
13744 if (val) {
13745 if (strcasecmp(val, "MSCSReq") == 0)
13746 return cmd_sta_send_frame_mscs(dut, conn, intf, cmd);
13747 if (strcasecmp(val, "SCSReq") == 0)
13748 return cmd_sta_send_frame_scs(dut, conn, intf, cmd);
Veerendranath Jakkam329a3cd2021-09-11 18:10:13 +053013749 if (strcasecmp(val, "DSCPPolicyQuery") == 0)
13750 return cmd_sta_send_frame_dscp_query(dut, conn, intf,
13751 cmd);
Veerendranath Jakkam1bf1bd62021-09-12 16:35:55 +053013752 if (strcasecmp(val, "DSCPPolicyResponse") == 0)
13753 return cmd_sta_send_frame_dscp_response(dut, conn, intf,
13754 cmd);
Vinita S. Malooca85fd22021-01-15 02:54:34 +053013755
13756 sigma_dut_print(dut, DUT_MSG_ERROR,
13757 "%s: frame name - %s is invalid",
13758 __func__, val);
13759 }
13760
13761 return INVALID_SEND_STATUS;
13762}
13763
13764
Jouni Malinenf7222712019-06-13 01:50:21 +030013765enum sigma_cmd_result cmd_sta_send_frame(struct sigma_dut *dut,
13766 struct sigma_conn *conn,
13767 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013768{
13769 const char *intf = get_param(cmd, "Interface");
13770 const char *val;
13771 enum send_frame_type frame;
13772 enum send_frame_protection protected;
13773 char buf[100];
13774 unsigned char addr[ETH_ALEN];
13775 int res;
13776
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030013777 if (!intf)
13778 return -1;
13779
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013780 val = get_param(cmd, "program");
13781 if (val == NULL)
13782 val = get_param(cmd, "frame");
13783 if (val && strcasecmp(val, "TDLS") == 0)
13784 return cmd_sta_send_frame_tdls(dut, conn, cmd);
13785 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030013786 strcasecmp(val, "HS2-R2") == 0 ||
13787 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013788 return cmd_sta_send_frame_hs2(dut, conn, cmd);
13789 if (val && strcasecmp(val, "VHT") == 0)
13790 return cmd_sta_send_frame_vht(dut, conn, cmd);
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070013791 if (val && strcasecmp(val, "HE") == 0)
13792 return cmd_sta_send_frame_he(dut, conn, cmd);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -070013793 if (val && strcasecmp(val, "LOC") == 0)
13794 return loc_cmd_sta_send_frame(dut, conn, cmd);
Lior David0fe101e2017-03-09 16:09:50 +020013795 if (val && strcasecmp(val, "60GHz") == 0)
13796 return cmd_sta_send_frame_60g(dut, conn, cmd);
Ashwini Patildb59b3c2017-04-13 15:19:23 +053013797 if (val && strcasecmp(val, "MBO") == 0) {
13798 res = mbo_cmd_sta_send_frame(dut, conn, intf, cmd);
13799 if (res != 2)
13800 return res;
13801 }
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053013802 if (val && strcasecmp(val, "WPA3") == 0)
13803 return cmd_sta_send_frame_wpa3(dut, conn, intf, cmd);
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053013804 if (val && strcasecmp(val, "QM") == 0)
Vinita S. Malooca85fd22021-01-15 02:54:34 +053013805 return cmd_sta_send_frame_qm(dut, conn, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013806
13807 val = get_param(cmd, "TD_DISC");
13808 if (val) {
13809 if (hwaddr_aton(val, addr) < 0)
13810 return -1;
13811 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", val);
13812 if (wpa_command(intf, buf) < 0) {
13813 send_resp(dut, conn, SIGMA_ERROR,
13814 "ErrorCode,Failed to send TDLS discovery");
13815 return 0;
13816 }
13817 return 1;
13818 }
13819
13820 val = get_param(cmd, "TD_Setup");
13821 if (val) {
13822 if (hwaddr_aton(val, addr) < 0)
13823 return -1;
13824 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", val);
13825 if (wpa_command(intf, buf) < 0) {
13826 send_resp(dut, conn, SIGMA_ERROR,
13827 "ErrorCode,Failed to start TDLS setup");
13828 return 0;
13829 }
13830 return 1;
13831 }
13832
13833 val = get_param(cmd, "TD_TearDown");
13834 if (val) {
13835 if (hwaddr_aton(val, addr) < 0)
13836 return -1;
13837 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", val);
13838 if (wpa_command(intf, buf) < 0) {
13839 send_resp(dut, conn, SIGMA_ERROR,
13840 "ErrorCode,Failed to tear down TDLS link");
13841 return 0;
13842 }
13843 return 1;
13844 }
13845
13846 val = get_param(cmd, "TD_ChannelSwitch");
13847 if (val) {
13848 /* TODO */
13849 send_resp(dut, conn, SIGMA_ERROR,
13850 "ErrorCode,TD_ChannelSwitch not yet supported");
13851 return 0;
13852 }
13853
13854 val = get_param(cmd, "TD_NF");
13855 if (val) {
13856 /* TODO */
13857 send_resp(dut, conn, SIGMA_ERROR,
13858 "ErrorCode,TD_NF not yet supported");
13859 return 0;
13860 }
13861
13862 val = get_param(cmd, "PMFFrameType");
13863 if (val == NULL)
13864 val = get_param(cmd, "FrameName");
13865 if (val == NULL)
13866 val = get_param(cmd, "Type");
13867 if (val == NULL)
13868 return -1;
13869 if (strcasecmp(val, "disassoc") == 0)
13870 frame = DISASSOC;
13871 else if (strcasecmp(val, "deauth") == 0)
13872 frame = DEAUTH;
13873 else if (strcasecmp(val, "saquery") == 0)
13874 frame = SAQUERY;
13875 else if (strcasecmp(val, "auth") == 0)
13876 frame = AUTH;
13877 else if (strcasecmp(val, "assocreq") == 0)
13878 frame = ASSOCREQ;
13879 else if (strcasecmp(val, "reassocreq") == 0)
13880 frame = REASSOCREQ;
13881 else if (strcasecmp(val, "neigreq") == 0) {
13882 sigma_dut_print(dut, DUT_MSG_INFO, "Got neighbor request");
13883
13884 val = get_param(cmd, "ssid");
13885 if (val == NULL)
13886 return -1;
13887
13888 res = send_neighbor_request(dut, intf, val);
13889 if (res) {
13890 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
13891 "Failed to send neighbor report request");
13892 return 0;
13893 }
13894
13895 return 1;
Ashwini Patil5acd7382017-04-13 15:55:04 +053013896 } else if (strcasecmp(val, "transmgmtquery") == 0 ||
13897 strcasecmp(val, "BTMQuery") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013898 sigma_dut_print(dut, DUT_MSG_DEBUG,
13899 "Got Transition Management Query");
13900
Ashwini Patil5acd7382017-04-13 15:55:04 +053013901 res = send_trans_mgmt_query(dut, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013902 if (res) {
13903 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
13904 "Failed to send Transition Management Query");
13905 return 0;
13906 }
13907
13908 return 1;
13909 } else {
13910 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
13911 "PMFFrameType");
13912 return 0;
13913 }
13914
13915 val = get_param(cmd, "PMFProtected");
13916 if (val == NULL)
13917 val = get_param(cmd, "Protected");
13918 if (val == NULL)
13919 return -1;
13920 if (strcasecmp(val, "Correct-key") == 0 ||
13921 strcasecmp(val, "CorrectKey") == 0)
13922 protected = CORRECT_KEY;
13923 else if (strcasecmp(val, "IncorrectKey") == 0)
13924 protected = INCORRECT_KEY;
13925 else if (strcasecmp(val, "Unprotected") == 0)
13926 protected = UNPROTECTED;
13927 else {
13928 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
13929 "PMFProtected");
13930 return 0;
13931 }
13932
13933 if (protected != UNPROTECTED &&
13934 (frame == AUTH || frame == ASSOCREQ || frame == REASSOCREQ)) {
13935 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Impossible "
13936 "PMFProtected for auth/assocreq/reassocreq");
13937 return 0;
13938 }
13939
13940 if (if_nametoindex("sigmadut") == 0) {
13941 snprintf(buf, sizeof(buf),
13942 "iw dev %s interface add sigmadut type monitor",
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013943 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013944 if (system(buf) != 0 ||
13945 if_nametoindex("sigmadut") == 0) {
13946 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
13947 "monitor interface with '%s'", buf);
13948 return -2;
13949 }
13950 }
13951
13952 if (system("ifconfig sigmadut up") != 0) {
13953 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
13954 "monitor interface up");
13955 return -2;
13956 }
13957
Veerendranath Jakkam49774122020-07-05 09:52:18 +053013958 return sta_inject_frame(dut, conn, intf, frame, protected, NULL, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013959}
13960
13961
13962static int cmd_sta_set_parameter_hs2(struct sigma_dut *dut,
13963 struct sigma_conn *conn,
13964 struct sigma_cmd *cmd,
13965 const char *ifname)
13966{
13967 char buf[200];
13968 const char *val;
13969
13970 val = get_param(cmd, "ClearARP");
13971 if (val && atoi(val) == 1) {
13972 snprintf(buf, sizeof(buf), "ip neigh flush dev %s", ifname);
13973 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
13974 if (system(buf) != 0) {
13975 send_resp(dut, conn, SIGMA_ERROR,
13976 "errorCode,Failed to clear ARP cache");
13977 return 0;
13978 }
13979 }
13980
13981 return 1;
13982}
13983
13984
13985int cmd_sta_set_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
13986 struct sigma_cmd *cmd)
13987{
13988 const char *intf = get_param(cmd, "Interface");
13989 const char *val;
13990
13991 if (intf == NULL)
13992 return -1;
13993
13994 val = get_param(cmd, "program");
13995 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030013996 strcasecmp(val, "HS2-R2") == 0 ||
13997 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013998 return cmd_sta_set_parameter_hs2(dut, conn, cmd, intf);
13999
14000 return -1;
14001}
14002
14003
Jouni Malinenf7222712019-06-13 01:50:21 +030014004static enum sigma_cmd_result cmd_sta_set_macaddr(struct sigma_dut *dut,
14005 struct sigma_conn *conn,
14006 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014007{
14008 const char *intf = get_param(cmd, "Interface");
14009 const char *mac = get_param(cmd, "MAC");
14010
14011 if (intf == NULL || mac == NULL)
14012 return -1;
14013
14014 sigma_dut_print(dut, DUT_MSG_INFO, "Change local MAC address for "
14015 "interface %s to %s", intf, mac);
14016
14017 if (dut->set_macaddr) {
14018 char buf[128];
14019 int res;
14020 if (strcasecmp(mac, "default") == 0) {
14021 res = snprintf(buf, sizeof(buf), "%s",
14022 dut->set_macaddr);
14023 dut->tmp_mac_addr = 0;
14024 } else {
14025 res = snprintf(buf, sizeof(buf), "%s %s",
14026 dut->set_macaddr, mac);
14027 dut->tmp_mac_addr = 1;
14028 }
14029 if (res < 0 || res >= (int) sizeof(buf))
14030 return -1;
14031 if (system(buf) != 0) {
14032 send_resp(dut, conn, SIGMA_ERROR,
14033 "errorCode,Failed to set MAC "
14034 "address");
14035 return 0;
14036 }
14037 return 1;
14038 }
14039
14040 if (strcasecmp(mac, "default") == 0)
14041 return 1;
14042
14043 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
14044 "command");
14045 return 0;
14046}
14047
14048
14049static int iwpriv_tdlsoffchnmode(struct sigma_dut *dut,
14050 struct sigma_conn *conn, const char *intf,
14051 int val)
14052{
14053 char buf[200];
14054 int res;
14055
14056 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchnmode %d",
14057 intf, val);
14058 if (res < 0 || res >= (int) sizeof(buf))
14059 return -1;
14060 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
14061 if (system(buf) != 0) {
14062 send_resp(dut, conn, SIGMA_ERROR,
14063 "errorCode,Failed to configure offchannel mode");
14064 return 0;
14065 }
14066
14067 return 1;
14068}
14069
14070
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014071static int off_chan_val(enum sec_ch_offset off)
14072{
14073 switch (off) {
14074 case SEC_CH_NO:
14075 return 0;
14076 case SEC_CH_40ABOVE:
14077 return 40;
14078 case SEC_CH_40BELOW:
14079 return -40;
14080 }
14081
14082 return 0;
14083}
14084
14085
14086static int iwpriv_set_offchan(struct sigma_dut *dut, struct sigma_conn *conn,
14087 const char *intf, int off_ch_num,
14088 enum sec_ch_offset sec)
14089{
14090 char buf[200];
14091 int res;
14092
14093 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchan %d",
14094 intf, off_ch_num);
14095 if (res < 0 || res >= (int) sizeof(buf))
14096 return -1;
14097 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
14098 if (system(buf) != 0) {
14099 send_resp(dut, conn, SIGMA_ERROR,
14100 "errorCode,Failed to set offchan");
14101 return 0;
14102 }
14103
14104 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsecchnoffst %d",
14105 intf, off_chan_val(sec));
14106 if (res < 0 || res >= (int) sizeof(buf))
14107 return -1;
14108 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
14109 if (system(buf) != 0) {
14110 send_resp(dut, conn, SIGMA_ERROR,
14111 "errorCode,Failed to set sec chan offset");
14112 return 0;
14113 }
14114
14115 return 1;
14116}
14117
14118
14119static int tdls_set_offchannel_offset(struct sigma_dut *dut,
14120 struct sigma_conn *conn,
14121 const char *intf, int off_ch_num,
14122 enum sec_ch_offset sec)
14123{
14124 char buf[200];
14125 int res;
14126
14127 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNEL %d",
14128 off_ch_num);
14129 if (res < 0 || res >= (int) sizeof(buf))
14130 return -1;
14131 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
14132
14133 if (wpa_command(intf, buf) < 0) {
14134 send_resp(dut, conn, SIGMA_ERROR,
14135 "ErrorCode,Failed to set offchan");
14136 return 0;
14137 }
14138 res = snprintf(buf, sizeof(buf), "DRIVER TDLSSECONDARYCHANNELOFFSET %d",
14139 off_chan_val(sec));
14140 if (res < 0 || res >= (int) sizeof(buf))
14141 return -1;
14142
14143 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
14144
14145 if (wpa_command(intf, buf) < 0) {
14146 send_resp(dut, conn, SIGMA_ERROR,
14147 "ErrorCode,Failed to set sec chan offset");
14148 return 0;
14149 }
14150
14151 return 1;
14152}
14153
14154
14155static int tdls_set_offchannel_mode(struct sigma_dut *dut,
14156 struct sigma_conn *conn,
14157 const char *intf, int val)
14158{
14159 char buf[200];
14160 int res;
14161
14162 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNELMODE %d",
14163 val);
14164 if (res < 0 || res >= (int) sizeof(buf))
14165 return -1;
14166 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
14167
14168 if (wpa_command(intf, buf) < 0) {
14169 send_resp(dut, conn, SIGMA_ERROR,
14170 "ErrorCode,Failed to configure offchannel mode");
14171 return 0;
14172 }
14173
14174 return 1;
14175}
14176
14177
14178static int cmd_sta_set_rfeature_tdls(const char *intf, struct sigma_dut *dut,
14179 struct sigma_conn *conn,
14180 struct sigma_cmd *cmd)
14181{
14182 const char *val;
14183 enum {
14184 CHSM_NOT_SET,
14185 CHSM_ENABLE,
14186 CHSM_DISABLE,
14187 CHSM_REJREQ,
14188 CHSM_UNSOLRESP
14189 } chsm = CHSM_NOT_SET;
14190 int off_ch_num = -1;
14191 enum sec_ch_offset sec_ch = SEC_CH_NO;
14192 int res;
14193
14194 val = get_param(cmd, "Uapsd");
14195 if (val) {
14196 char buf[100];
14197 if (strcasecmp(val, "Enable") == 0)
14198 snprintf(buf, sizeof(buf), "SET ps 99");
14199 else if (strcasecmp(val, "Disable") == 0)
14200 snprintf(buf, sizeof(buf), "SET ps 98");
14201 else {
14202 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
14203 "Unsupported uapsd parameter value");
14204 return 0;
14205 }
14206 if (wpa_command(intf, buf)) {
14207 send_resp(dut, conn, SIGMA_ERROR,
14208 "ErrorCode,Failed to change U-APSD "
14209 "powersave mode");
14210 return 0;
14211 }
14212 }
14213
14214 val = get_param(cmd, "TPKTIMER");
14215 if (val && strcasecmp(val, "DISABLE") == 0) {
14216 if (wpa_command(intf, "SET tdls_testing 0x100")) {
14217 send_resp(dut, conn, SIGMA_ERROR,
14218 "ErrorCode,Failed to enable no TPK "
14219 "expiration test mode");
14220 return 0;
14221 }
14222 dut->no_tpk_expiration = 1;
14223 }
14224
14225 val = get_param(cmd, "ChSwitchMode");
14226 if (val) {
14227 if (strcasecmp(val, "Enable") == 0 ||
14228 strcasecmp(val, "Initiate") == 0)
14229 chsm = CHSM_ENABLE;
14230 else if (strcasecmp(val, "Disable") == 0 ||
14231 strcasecmp(val, "passive") == 0)
14232 chsm = CHSM_DISABLE;
14233 else if (strcasecmp(val, "RejReq") == 0)
14234 chsm = CHSM_REJREQ;
14235 else if (strcasecmp(val, "UnSolResp") == 0)
14236 chsm = CHSM_UNSOLRESP;
14237 else {
14238 send_resp(dut, conn, SIGMA_ERROR,
14239 "ErrorCode,Unknown ChSwitchMode value");
14240 return 0;
14241 }
14242 }
14243
14244 val = get_param(cmd, "OffChNum");
14245 if (val) {
14246 off_ch_num = atoi(val);
14247 if (off_ch_num == 0) {
14248 send_resp(dut, conn, SIGMA_ERROR,
14249 "ErrorCode,Invalid OffChNum");
14250 return 0;
14251 }
14252 }
14253
14254 val = get_param(cmd, "SecChOffset");
14255 if (val) {
14256 if (strcmp(val, "20") == 0)
14257 sec_ch = SEC_CH_NO;
14258 else if (strcasecmp(val, "40above") == 0)
14259 sec_ch = SEC_CH_40ABOVE;
14260 else if (strcasecmp(val, "40below") == 0)
14261 sec_ch = SEC_CH_40BELOW;
14262 else {
14263 send_resp(dut, conn, SIGMA_ERROR,
14264 "ErrorCode,Unknown SecChOffset value");
14265 return 0;
14266 }
14267 }
14268
14269 if (chsm == CHSM_NOT_SET) {
14270 /* no offchannel changes requested */
14271 return 1;
14272 }
14273
Jouni Malinen016ae6c2019-11-04 17:00:01 +020014274 if (strcmp(intf, get_main_ifname(dut)) != 0 &&
14275 strcmp(intf, get_station_ifname(dut)) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014276 send_resp(dut, conn, SIGMA_ERROR,
14277 "ErrorCode,Unknown interface");
14278 return 0;
14279 }
14280
14281 switch (chsm) {
14282 case CHSM_NOT_SET:
Jouni Malinen280f5ba2016-08-29 21:33:10 +030014283 res = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014284 break;
14285 case CHSM_ENABLE:
14286 if (off_ch_num < 0) {
14287 send_resp(dut, conn, SIGMA_ERROR,
14288 "ErrorCode,Missing OffChNum argument");
14289 return 0;
14290 }
14291 if (wifi_chip_type == DRIVER_WCN) {
14292 res = tdls_set_offchannel_offset(dut, conn, intf,
14293 off_ch_num, sec_ch);
14294 } else {
14295 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
14296 sec_ch);
14297 }
14298 if (res != 1)
14299 return res;
14300 if (wifi_chip_type == DRIVER_WCN)
14301 res = tdls_set_offchannel_mode(dut, conn, intf, 1);
14302 else
14303 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 1);
14304 break;
14305 case CHSM_DISABLE:
14306 if (wifi_chip_type == DRIVER_WCN)
14307 res = tdls_set_offchannel_mode(dut, conn, intf, 2);
14308 else
14309 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 2);
14310 break;
14311 case CHSM_REJREQ:
14312 if (wifi_chip_type == DRIVER_WCN)
14313 res = tdls_set_offchannel_mode(dut, conn, intf, 3);
14314 else
14315 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 3);
14316 break;
14317 case CHSM_UNSOLRESP:
14318 if (off_ch_num < 0) {
14319 send_resp(dut, conn, SIGMA_ERROR,
14320 "ErrorCode,Missing OffChNum argument");
14321 return 0;
14322 }
14323 if (wifi_chip_type == DRIVER_WCN) {
14324 res = tdls_set_offchannel_offset(dut, conn, intf,
14325 off_ch_num, sec_ch);
14326 } else {
14327 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
14328 sec_ch);
14329 }
14330 if (res != 1)
14331 return res;
14332 if (wifi_chip_type == DRIVER_WCN)
14333 res = tdls_set_offchannel_mode(dut, conn, intf, 4);
14334 else
14335 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 4);
14336 break;
14337 }
14338
14339 return res;
14340}
14341
14342
14343static int ath_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
14344 struct sigma_conn *conn,
14345 struct sigma_cmd *cmd)
14346{
14347 const char *val;
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053014348 char *token = NULL, *result;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014349
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -070014350 novap_reset(dut, intf, 1);
priyadharshini gowthamane5e25172015-12-08 14:53:48 -080014351
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014352 val = get_param(cmd, "nss_mcs_opt");
14353 if (val) {
14354 /* String (nss_operating_mode; mcs_operating_mode) */
14355 int nss, mcs;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053014356 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014357
14358 token = strdup(val);
14359 if (!token)
14360 return 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053014361 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053014362 if (!result) {
14363 sigma_dut_print(dut, DUT_MSG_ERROR,
14364 "VHT NSS not specified");
14365 goto failed;
14366 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014367 if (strcasecmp(result, "def") != 0) {
14368 nss = atoi(result);
14369 if (nss == 4)
14370 ath_disable_txbf(dut, intf);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070014371 if (run_iwpriv(dut, intf, "nss %d", nss) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014372 goto failed;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070014373
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014374 }
14375
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053014376 result = strtok_r(NULL, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053014377 if (!result) {
14378 sigma_dut_print(dut, DUT_MSG_ERROR,
14379 "VHT MCS not specified");
14380 goto failed;
14381 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014382 if (strcasecmp(result, "def") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070014383 if (run_iwpriv(dut, intf, "set11NRates 0") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014384 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014385 } else {
14386 mcs = atoi(result);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070014387 if (run_iwpriv(dut, intf, "vhtmcs %d", mcs) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014388 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014389 }
14390 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070014391 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014392 }
14393
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053014394 free(token);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014395 return 1;
14396failed:
14397 free(token);
14398 return 0;
14399}
14400
14401
14402static int cmd_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
14403 struct sigma_conn *conn,
14404 struct sigma_cmd *cmd)
14405{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020014406 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014407 case DRIVER_ATHEROS:
14408 return ath_sta_set_rfeature_vht(intf, dut, conn, cmd);
14409 default:
14410 send_resp(dut, conn, SIGMA_ERROR,
14411 "errorCode,Unsupported sta_set_rfeature(VHT) with the current driver");
14412 return 0;
14413 }
14414}
14415
14416
Jouni Malinen1702fe32021-06-08 19:08:01 +030014417static enum sigma_cmd_result
14418wcn_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
14419 struct sigma_conn *conn, struct sigma_cmd *cmd)
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014420{
14421 const char *val;
14422 char *token = NULL, *result;
14423 char buf[60];
14424
14425 val = get_param(cmd, "nss_mcs_opt");
14426 if (val) {
14427 /* String (nss_operating_mode; mcs_operating_mode) */
14428 int nss, mcs, ratecode;
14429 char *saveptr;
14430
14431 token = strdup(val);
14432 if (!token)
Jouni Malinen1702fe32021-06-08 19:08:01 +030014433 return ERROR_SEND_STATUS;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014434
14435 result = strtok_r(token, ";", &saveptr);
14436 if (!result) {
14437 sigma_dut_print(dut, DUT_MSG_ERROR,
14438 "HE NSS not specified");
14439 goto failed;
14440 }
14441 nss = 1;
14442 if (strcasecmp(result, "def") != 0)
14443 nss = atoi(result);
14444
14445 result = strtok_r(NULL, ";", &saveptr);
14446 if (!result) {
14447 sigma_dut_print(dut, DUT_MSG_ERROR,
14448 "HE MCS not specified");
14449 goto failed;
14450 }
14451 mcs = 7;
14452 if (strcasecmp(result, "def") != 0)
14453 mcs = atoi(result);
14454
Arif Hussain557bf412018-05-25 17:29:36 -070014455 ratecode = 0x20; /* for nss:1 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014456 if (nss == 2) {
Arif Hussain557bf412018-05-25 17:29:36 -070014457 ratecode = 0x40; /* for nss:2 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014458 } else if (nss > 2) {
14459 sigma_dut_print(dut, DUT_MSG_ERROR,
14460 "HE NSS %d not supported", nss);
14461 goto failed;
14462 }
14463
Arif Hussain557bf412018-05-25 17:29:36 -070014464 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss);
14465 if (system(buf) != 0) {
14466 sigma_dut_print(dut, DUT_MSG_ERROR,
14467 "nss_mcs_opt: iwpriv %s nss %d failed",
14468 intf, nss);
14469 goto failed;
14470 }
Arif Hussainac6c5112018-05-25 17:34:00 -070014471 dut->sta_nss = nss;
Arif Hussain557bf412018-05-25 17:29:36 -070014472
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014473 /* Add the MCS to the ratecode */
14474 if (mcs >= 0 && mcs <= 11) {
14475 ratecode += mcs;
Arif Hussain557bf412018-05-25 17:29:36 -070014476#ifdef NL80211_SUPPORT
14477 if (dut->device_type == STA_testbed) {
14478 enum he_mcs_config mcs_config;
14479 int ret;
14480
14481 if (mcs <= 7)
14482 mcs_config = HE_80_MCS0_7;
14483 else if (mcs <= 9)
14484 mcs_config = HE_80_MCS0_9;
14485 else
14486 mcs_config = HE_80_MCS0_11;
14487 ret = sta_set_he_mcs(dut, intf, mcs_config);
14488 if (ret) {
14489 sigma_dut_print(dut, DUT_MSG_ERROR,
14490 "nss_mcs_opt: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
14491 mcs, mcs_config, ret);
14492 goto failed;
14493 }
14494 }
14495#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014496 } else {
14497 sigma_dut_print(dut, DUT_MSG_ERROR,
14498 "HE MCS %d not supported", mcs);
14499 goto failed;
14500 }
14501 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0x%03x",
14502 intf, ratecode);
14503 if (system(buf) != 0) {
14504 sigma_dut_print(dut, DUT_MSG_ERROR,
14505 "iwpriv setting of 11ax rates failed");
14506 goto failed;
14507 }
14508 free(token);
14509 }
14510
14511 val = get_param(cmd, "GI");
14512 if (val) {
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080014513 int fix_rate_sgi;
14514
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014515 if (strcmp(val, "0.8") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070014516 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 9", intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080014517 fix_rate_sgi = 1;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014518 } else if (strcmp(val, "1.6") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070014519 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 10",
14520 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080014521 fix_rate_sgi = 2;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014522 } else if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070014523 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 11",
14524 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080014525 fix_rate_sgi = 3;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014526 } else {
14527 send_resp(dut, conn, SIGMA_ERROR,
14528 "errorCode,GI value not supported");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014529 return STATUS_SENT_ERROR;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014530 }
14531 if (system(buf) != 0) {
14532 send_resp(dut, conn, SIGMA_ERROR,
14533 "errorCode,Failed to set shortgi");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014534 return STATUS_SENT_ERROR;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014535 }
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080014536 snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d",
14537 intf, fix_rate_sgi);
14538 if (system(buf) != 0) {
14539 send_resp(dut, conn, SIGMA_ERROR,
14540 "errorCode,Failed to set fix rate shortgi");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014541 return STATUS_SENT_ERROR;
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080014542 }
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014543 }
14544
Subhani Shaik8e7a3052018-04-24 14:03:00 -070014545 val = get_param(cmd, "LTF");
14546 if (val) {
14547#ifdef NL80211_SUPPORT
14548 if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080014549 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_1X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070014550 } if (strcmp(val, "6.4") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080014551 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_2X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070014552 } else if (strcmp(val, "12.8") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080014553 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_4X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070014554 } else {
14555 send_resp(dut, conn, SIGMA_ERROR,
14556 "errorCode, LTF value not supported");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014557 return STATUS_SENT_ERROR;
Subhani Shaik8e7a3052018-04-24 14:03:00 -070014558 }
14559#else /* NL80211_SUPPORT */
14560 sigma_dut_print(dut, DUT_MSG_ERROR,
14561 "LTF cannot be set without NL80211_SUPPORT defined");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014562 return ERROR_SEND_STATUS;
Subhani Shaik8e7a3052018-04-24 14:03:00 -070014563#endif /* NL80211_SUPPORT */
14564 }
14565
Kiran Kumar Lokere1809da12021-06-24 00:45:38 -070014566 val = get_param(cmd, "KeepAlive");
14567 if (val) {
14568 int set_val = QCA_WLAN_KEEP_ALIVE_DEFAULT;
14569
14570 if (strcasecmp(val, "Data") == 0)
14571 set_val = QCA_WLAN_KEEP_ALIVE_DATA;
14572 else if (strcasecmp(val, "Mgmt") == 0)
14573 set_val = QCA_WLAN_KEEP_ALIVE_MGMT;
14574
14575 if (sta_set_keep_alive_data_cfg(dut, intf, set_val)) {
14576 send_resp(dut, conn, SIGMA_ERROR,
14577 "ErrorCode,Failed to set keep alive type config");
14578 return STATUS_SENT_ERROR;
14579 }
14580 }
14581
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -070014582 val = get_param(cmd, "TxSUPPDU");
14583 if (val) {
14584 int set_val = 1;
14585
14586 if (strcasecmp(val, "Enable") == 0)
14587 set_val = 1;
14588 else if (strcasecmp(val, "Disable") == 0)
14589 set_val = 0;
14590
14591 if (sta_set_tx_su_ppdu_cfg(dut, intf, set_val)) {
14592 send_resp(dut, conn, SIGMA_ERROR,
14593 "ErrorCode,Failed to set Tx SU PPDU config");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014594 return STATUS_SENT_ERROR;
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -070014595 }
14596 }
14597
Kiran Kumar Lokere54b72522021-04-01 00:22:44 -070014598 val = get_param(cmd, "Mgmt_Data_TX_Resp_Frame");
14599 if (val) {
14600 int set_val = 0;
14601
14602 if (strcasecmp(val, "Enable") == 0)
14603 set_val = 0;
14604 else if (strcasecmp(val, "Disable") == 0)
14605 set_val = 1;
14606
14607 if (sta_set_mgmt_data_tx_disable_cfg(dut, intf, set_val)) {
14608 send_resp(dut, conn, SIGMA_ERROR,
14609 "ErrorCode,Failed to set mgmt/data Tx disable config");
14610 return STATUS_SENT_ERROR;
14611 }
14612 }
14613
Arif Hussain480d5f42019-03-12 14:40:42 -070014614 val = get_param(cmd, "TWT_Setup");
14615 if (val) {
14616 if (strcasecmp(val, "Request") == 0) {
Kiran Kumar Lokereafac46a2021-11-29 14:03:20 -080014617 if (set_power_save_wcn(dut, intf, 1) < 0)
14618 sigma_dut_print(dut, DUT_MSG_ERROR,
14619 "Failed to enable power save");
Arif Hussain480d5f42019-03-12 14:40:42 -070014620 if (sta_twt_request(dut, conn, cmd)) {
14621 send_resp(dut, conn, SIGMA_ERROR,
Srinivas Girigowda6707f032020-10-26 15:24:46 -070014622 "ErrorCode,TWT setup failed");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014623 return STATUS_SENT_ERROR;
Arif Hussain480d5f42019-03-12 14:40:42 -070014624 }
14625 } else if (strcasecmp(val, "Teardown") == 0) {
14626 if (sta_twt_teardown(dut, conn, cmd)) {
14627 send_resp(dut, conn, SIGMA_ERROR,
Srinivas Girigowda6707f032020-10-26 15:24:46 -070014628 "ErrorCode,TWT teardown failed");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014629 return STATUS_SENT_ERROR;
Arif Hussain480d5f42019-03-12 14:40:42 -070014630 }
14631 }
14632 }
14633
Srinivas Girigowda6707f032020-10-26 15:24:46 -070014634 val = get_param(cmd, "TWT_Operation");
14635 if (val) {
14636 if (strcasecmp(val, "Suspend") == 0) {
14637 if (sta_twt_suspend_or_nudge(dut, conn, cmd)) {
14638 send_resp(dut, conn, SIGMA_ERROR,
14639 "ErrorCode,TWT suspend failed");
14640 return STATUS_SENT_ERROR;
14641 }
14642 } else if (strcasecmp(val, "Resume") == 0) {
14643 if (sta_twt_resume(dut, conn, cmd)) {
14644 send_resp(dut, conn, SIGMA_ERROR,
14645 "ErrorCode,TWT resume failed");
14646 return STATUS_SENT_ERROR;
14647 }
14648 }
14649 }
14650
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -080014651 val = get_param(cmd, "transmitOMI");
14652 if (val && sta_transmit_omi(dut, conn, cmd)) {
14653 send_resp(dut, conn, SIGMA_ERROR,
14654 "ErrorCode,sta_transmit_omi failed");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014655 return STATUS_SENT_ERROR;
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -070014656 }
14657
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080014658 val = get_param(cmd, "Powersave");
14659 if (val) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053014660 int ps;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080014661
14662 if (strcasecmp(val, "off") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053014663 ps = 2;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080014664 } else if (strcasecmp(val, "on") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053014665 ps = 1;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080014666 } else {
14667 sigma_dut_print(dut, DUT_MSG_ERROR,
14668 "Unsupported Powersave value '%s'",
14669 val);
Jouni Malinen1702fe32021-06-08 19:08:01 +030014670 return INVALID_SEND_STATUS;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080014671 }
Vinita S. Malooa8b62722020-04-23 01:45:41 +053014672 if (set_power_save_wcn(dut, intf, ps) < 0)
Jouni Malinen1702fe32021-06-08 19:08:01 +030014673 return ERROR_SEND_STATUS;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080014674 }
14675
Kiran Kumar Lokere2c4b7ce2019-01-30 12:02:28 -080014676 val = get_param(cmd, "MU_EDCA");
14677 if (val) {
14678 if (strcasecmp(val, "Override") == 0) {
14679 if (sta_set_mu_edca_override(dut, intf, 1)) {
14680 send_resp(dut, conn, SIGMA_ERROR,
14681 "errorCode,MU EDCA override set failed");
14682 return STATUS_SENT;
14683 }
14684 } else if (strcasecmp(val, "Disable") == 0) {
14685 if (sta_set_mu_edca_override(dut, intf, 0)) {
14686 send_resp(dut, conn, SIGMA_ERROR,
14687 "errorCode,MU EDCA override disable failed");
14688 return STATUS_SENT;
14689 }
14690 }
14691 }
14692
Kiran Kumar Lokerefa7c7b92021-08-09 00:50:55 -070014693 val = get_param(cmd, "RUAllocTone");
14694 if (val && strcasecmp(val, "242") == 0) {
14695 if (sta_set_ru_242_tone_tx(dut, intf, 1)) {
14696 send_resp(dut, conn, SIGMA_ERROR,
14697 "ErrorCode,Failed to set RU 242 tone Tx");
14698 return STATUS_SENT_ERROR;
14699 }
14700 }
14701
14702 val = get_param(cmd, "PPDUTxType");
14703 if (val && strcasecmp(val, "ER-SU") == 0) {
14704 if (sta_set_er_su_ppdu_type_tx(dut, intf, 1)) {
14705 send_resp(dut, conn, SIGMA_ERROR,
14706 "ErrorCode,Failed to set ER-SU PPDU type Tx");
14707 return STATUS_SENT_ERROR;
14708 }
14709 }
14710
Kiran Kumar Lokeredd086642020-06-04 00:29:26 -070014711 val = get_param(cmd, "Ch_Pref");
14712 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
14713 return STATUS_SENT;
14714
14715 val = get_param(cmd, "Cellular_Data_Cap");
14716 if (val && mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
14717 return STATUS_SENT;
14718
Jouni Malinen1702fe32021-06-08 19:08:01 +030014719 return SUCCESS_SEND_STATUS;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014720
14721failed:
14722 free(token);
Jouni Malinen1702fe32021-06-08 19:08:01 +030014723 return ERROR_SEND_STATUS;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014724}
14725
14726
Jouni Malinen1702fe32021-06-08 19:08:01 +030014727static enum sigma_cmd_result
14728cmd_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
14729 struct sigma_conn *conn, struct sigma_cmd *cmd)
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014730{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020014731 switch (get_driver_type(dut)) {
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014732 case DRIVER_WCN:
14733 return wcn_sta_set_rfeature_he(intf, dut, conn, cmd);
14734 default:
14735 send_resp(dut, conn, SIGMA_ERROR,
14736 "errorCode,Unsupported sta_set_rfeature(HE) with the current driver");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014737 return STATUS_SENT_ERROR;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014738 }
14739}
14740
14741
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080014742static int cmd_sta_set_power_save_he(const char *intf, struct sigma_dut *dut,
14743 struct sigma_conn *conn,
14744 struct sigma_cmd *cmd)
14745{
14746 const char *val;
14747
14748 val = get_param(cmd, "powersave");
14749 if (val) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053014750 int ps;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080014751
14752 if (strcasecmp(val, "off") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053014753 ps = 2;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080014754 } else if (strcasecmp(val, "on") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053014755 ps = 1;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080014756 } else {
14757 sigma_dut_print(dut, DUT_MSG_ERROR,
14758 "Unsupported power save config");
14759 return -1;
14760 }
Vinita S. Malooa8b62722020-04-23 01:45:41 +053014761 if (set_power_save_wcn(dut, intf, ps) < 0)
14762 return 0;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080014763 return 1;
14764 }
14765
14766 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported command");
14767
14768 return 0;
14769}
14770
14771
Ashwini Patil5acd7382017-04-13 15:55:04 +053014772static int btm_query_candidate_list(struct sigma_dut *dut,
14773 struct sigma_conn *conn,
14774 struct sigma_cmd *cmd)
14775{
14776 const char *bssid, *info, *op_class, *ch, *phy_type, *pref;
14777 int len, ret;
14778 char buf[10];
14779
14780 /*
14781 * Neighbor Report elements format:
14782 * neighbor=<BSSID>,<BSSID Information>,<Operating Class>,
14783 * <Channel Number>,<PHY Type>[,<hexdump of Optional Subelements>]
14784 * eg: neighbor=aa:bb:cc:dd:ee:ff,17,81,6,1,030101
14785 */
14786
14787 bssid = get_param(cmd, "Nebor_BSSID");
14788 if (!bssid) {
14789 send_resp(dut, conn, SIGMA_INVALID,
14790 "errorCode,Nebor_BSSID is missing");
14791 return 0;
14792 }
14793
14794 info = get_param(cmd, "Nebor_Bssid_Info");
14795 if (!info) {
14796 sigma_dut_print(dut, DUT_MSG_INFO,
14797 "Using default value for Nebor_Bssid_Info: %s",
14798 DEFAULT_NEIGHBOR_BSSID_INFO);
14799 info = DEFAULT_NEIGHBOR_BSSID_INFO;
14800 }
14801
14802 op_class = get_param(cmd, "Nebor_Op_Class");
14803 if (!op_class) {
14804 send_resp(dut, conn, SIGMA_INVALID,
14805 "errorCode,Nebor_Op_Class is missing");
14806 return 0;
14807 }
14808
14809 ch = get_param(cmd, "Nebor_Op_Ch");
14810 if (!ch) {
14811 send_resp(dut, conn, SIGMA_INVALID,
14812 "errorCode,Nebor_Op_Ch is missing");
14813 return 0;
14814 }
14815
14816 phy_type = get_param(cmd, "Nebor_Phy_Type");
14817 if (!phy_type) {
14818 sigma_dut_print(dut, DUT_MSG_INFO,
14819 "Using default value for Nebor_Phy_Type: %s",
14820 DEFAULT_NEIGHBOR_PHY_TYPE);
14821 phy_type = DEFAULT_NEIGHBOR_PHY_TYPE;
14822 }
14823
14824 /* Parse optional subelements */
14825 buf[0] = '\0';
14826 pref = get_param(cmd, "Nebor_Pref");
14827 if (pref) {
14828 /* hexdump for preferrence subelement */
14829 ret = snprintf(buf, sizeof(buf), ",0301%02x", atoi(pref));
14830 if (ret < 0 || ret >= (int) sizeof(buf)) {
14831 sigma_dut_print(dut, DUT_MSG_ERROR,
14832 "snprintf failed for optional subelement ret: %d",
14833 ret);
14834 send_resp(dut, conn, SIGMA_ERROR,
14835 "errorCode,snprintf failed for subelement");
14836 return 0;
14837 }
14838 }
14839
14840 if (!dut->btm_query_cand_list) {
14841 dut->btm_query_cand_list = calloc(1, NEIGHBOR_REPORT_SIZE);
14842 if (!dut->btm_query_cand_list) {
14843 send_resp(dut, conn, SIGMA_ERROR,
14844 "errorCode,Failed to allocate memory for btm_query_cand_list");
14845 return 0;
14846 }
14847 }
14848
14849 len = strlen(dut->btm_query_cand_list);
14850 ret = snprintf(dut->btm_query_cand_list + len,
14851 NEIGHBOR_REPORT_SIZE - len, " neighbor=%s,%s,%s,%s,%s%s",
14852 bssid, info, op_class, ch, phy_type, buf);
14853 if (ret < 0 || ret >= NEIGHBOR_REPORT_SIZE - len) {
14854 sigma_dut_print(dut, DUT_MSG_ERROR,
14855 "snprintf failed for neighbor report list ret: %d",
14856 ret);
14857 send_resp(dut, conn, SIGMA_ERROR,
14858 "errorCode,snprintf failed for neighbor report");
14859 free(dut->btm_query_cand_list);
14860 dut->btm_query_cand_list = NULL;
14861 return 0;
14862 }
14863
14864 return 1;
14865}
14866
14867
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020014868int sta_extract_60g_ese(struct sigma_dut *dut, struct sigma_cmd *cmd,
14869 struct sigma_ese_alloc *allocs, int *allocs_size)
14870{
14871 int max_count = *allocs_size;
14872 int count = 0, i;
14873 const char *val;
14874
14875 do {
14876 val = get_param_indexed(cmd, "AllocID", count);
14877 if (val)
14878 count++;
14879 } while (val);
14880
14881 if (count == 0 || count > max_count) {
14882 sigma_dut_print(dut, DUT_MSG_ERROR,
14883 "Invalid number of allocations(%d)", count);
14884 return -1;
14885 }
14886
14887 for (i = 0; i < count; i++) {
14888 val = get_param_indexed(cmd, "PercentBI", i);
14889 if (!val) {
14890 sigma_dut_print(dut, DUT_MSG_ERROR,
14891 "Missing PercentBI parameter at index %d",
14892 i);
14893 return -1;
14894 }
14895 allocs[i].percent_bi = atoi(val);
14896
14897 val = get_param_indexed(cmd, "SrcAID", i);
14898 if (val)
14899 allocs[i].src_aid = strtol(val, NULL, 0);
14900 else
14901 allocs[i].src_aid = ESE_BCAST_AID;
14902
14903 val = get_param_indexed(cmd, "DestAID", i);
14904 if (val)
14905 allocs[i].dst_aid = strtol(val, NULL, 0);
14906 else
14907 allocs[i].dst_aid = ESE_BCAST_AID;
14908
14909 allocs[i].type = ESE_CBAP;
14910 sigma_dut_print(dut, DUT_MSG_INFO,
14911 "Alloc %d PercentBI %d SrcAID %d DstAID %d",
14912 i, allocs[i].percent_bi, allocs[i].src_aid,
14913 allocs[i].dst_aid);
14914 }
14915
14916 *allocs_size = count;
14917 return 0;
14918}
14919
14920
14921static int sta_set_60g_ese(struct sigma_dut *dut, int count,
14922 struct sigma_ese_alloc *allocs)
14923{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020014924 switch (get_driver_type(dut)) {
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020014925#ifdef __linux__
14926 case DRIVER_WIL6210:
14927 if (wil6210_set_ese(dut, count, allocs))
14928 return -1;
14929 return 1;
14930#endif /* __linux__ */
14931 default:
14932 sigma_dut_print(dut, DUT_MSG_ERROR,
14933 "Unsupported sta_set_60g_ese with the current driver");
14934 return -1;
14935 }
14936}
14937
14938
14939static int cmd_sta_set_rfeature_60g(const char *intf, struct sigma_dut *dut,
14940 struct sigma_conn *conn,
14941 struct sigma_cmd *cmd)
14942{
14943 const char *val;
14944
14945 val = get_param(cmd, "ExtSchIE");
14946 if (val && !strcasecmp(val, "Enable")) {
14947 struct sigma_ese_alloc allocs[MAX_ESE_ALLOCS];
14948 int count = MAX_ESE_ALLOCS;
14949
14950 if (sta_extract_60g_ese(dut, cmd, allocs, &count))
14951 return -1;
14952 return sta_set_60g_ese(dut, count, allocs);
14953 }
14954
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020014955 val = get_param(cmd, "MCS_FixedRate");
14956 if (val) {
14957 int sta_mcs = atoi(val);
14958
14959 sigma_dut_print(dut, DUT_MSG_INFO, "Force STA MCS to %d",
14960 sta_mcs);
14961 wil6210_set_force_mcs(dut, 1, sta_mcs);
14962
Jouni Malinen0e29cf22019-02-19 01:13:21 +020014963 return SUCCESS_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020014964 }
14965
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020014966 send_resp(dut, conn, SIGMA_ERROR,
14967 "errorCode,Invalid sta_set_rfeature(60G)");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020014968 return STATUS_SENT;
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020014969}
14970
14971
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053014972static int wcn_sta_override_oci(struct sigma_dut *dut, const char *intf,
14973 const char *oci_frametype, uint32_t oci_freq)
14974{
14975#ifdef NL80211_SUPPORT
14976 struct nl_msg *msg;
14977 int ret = 0;
14978 struct nlattr *params;
14979 struct nlattr *attr;
14980 int ifindex;
14981 u8 frame_type;
14982
14983 ifindex = if_nametoindex(intf);
14984 if (ifindex == 0) {
14985 sigma_dut_print(dut, DUT_MSG_ERROR,
14986 "%s: Index for interface %s failed",
14987 __func__, intf);
14988 return -1;
14989 }
14990
14991 if (strcasecmp(oci_frametype, "SAQueryReq") == 0) {
14992 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_SA_QUERY_REQ;
14993 } else if (strcasecmp(oci_frametype, "SAQueryResp") == 0) {
14994 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_SA_QUERY_RESP;
14995 } else if (strcasecmp(oci_frametype, "Reassocreq") == 0) {
14996 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_FT_REASSOC_REQ;
14997 } else {
14998 sigma_dut_print(dut, DUT_MSG_ERROR, "%s: Unknown frametype %s",
14999 __func__, oci_frametype);
15000 return -1;
15001 }
15002
15003
15004 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
15005 NL80211_CMD_VENDOR)) ||
15006 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
15007 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
15008 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
15009 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
15010 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
15011 !(params = nla_nest_start(
15012 msg,
15013 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_OCI_OVERRIDE)) ||
15014 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_OCI_OVERRIDE_FRAME_TYPE,
15015 frame_type) ||
15016 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_OCI_OVERRIDE_FREQUENCY,
15017 oci_freq)) {
15018 sigma_dut_print(dut, DUT_MSG_ERROR,
15019 "%s: err in adding vendor_cmd and vendor_data",
15020 __func__);
15021 nlmsg_free(msg);
15022 return -1;
15023 }
15024 nla_nest_end(msg, params);
15025 nla_nest_end(msg, attr);
15026
15027 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
15028 if (ret) {
15029 sigma_dut_print(dut, DUT_MSG_ERROR,
15030 "%s: err in send_and_recv_msgs, ret=%d",
15031 __func__, ret);
15032 }
15033 return ret;
15034#else /* NL80211_SUPPORT */
15035 sigma_dut_print(dut, DUT_MSG_ERROR,
15036 "OCI override not possible without NL80211_SUPPORT defined");
15037 return -1;
15038#endif /* NL80211_SUPPORT */
15039}
15040
15041
Veerendranath Jakkam50d5c782020-07-22 01:59:01 +053015042static int wcn_sta_ignore_csa(struct sigma_dut *dut, const char *intf,
15043 uint8_t ignore_csa)
15044{
15045#ifdef NL80211_SUPPORT
15046 return wcn_wifi_test_config_set_u8(
15047 dut, intf,
15048 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_IGNORE_CSA, ignore_csa);
15049#else /* NL80211_SUPPORT */
15050 sigma_dut_print(dut, DUT_MSG_ERROR,
15051 "IgnoreCSA can't be set without NL80211_SUPPORT defined");
15052 return -1;
15053#endif /* NL80211_SUPPORT */
15054}
15055
15056
Veerendranath Jakkamc771fac2020-07-22 01:32:56 +053015057static int wcn_sta_set_rsnxe_used(struct sigma_dut *dut, const char *intf,
15058 uint8_t rsnxe_used)
15059{
15060#ifdef NL80211_SUPPORT
15061 return wcn_wifi_test_config_set_u8(
15062 dut, intf,
15063 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_FT_REASSOCREQ_RSNXE_USED,
15064 rsnxe_used);
15065#else /* NL80211_SUPPORT */
15066 sigma_dut_print(dut, DUT_MSG_ERROR,
15067 "RSNXE_Used can't be set without NL80211_SUPPORT defined");
15068 return -1;
15069#endif /* NL80211_SUPPORT */
15070}
15071
15072
Veerendranath Jakkam1e1e5fd2020-09-10 07:12:37 +053015073static int wcn_sta_ignore_sa_query_timeout(struct sigma_dut *dut,
15074 const char *intf,
15075 uint8_t ignore_sa_query_timeout)
15076{
15077#ifdef NL80211_SUPPORT
15078 return wcn_wifi_test_config_set_u8(
15079 dut, intf,
15080 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_IGNORE_SA_QUERY_TIMEOUT,
15081 ignore_sa_query_timeout);
15082#else /* NL80211_SUPPORT */
15083 sigma_dut_print(dut, DUT_MSG_ERROR,
15084 "Ignore SA Query timeout can't be set without NL80211_SUPPORT defined");
15085 return -1;
15086#endif /* NL80211_SUPPORT */
15087}
15088
15089
Jouni Malinen6250cb02020-04-15 13:54:45 +030015090static enum sigma_cmd_result
15091cmd_sta_set_rfeature_wpa3(const char *intf, struct sigma_dut *dut,
15092 struct sigma_conn *conn,
15093 struct sigma_cmd *cmd)
15094{
Vamsi Krishnad29bc762020-05-08 23:23:30 +053015095 const char *val, *oci_chan, *oci_frametype;
Jouni Malinen6250cb02020-04-15 13:54:45 +030015096
Veerendranath Jakkam30bf9072020-04-16 14:37:57 +053015097 val = get_param(cmd, "ReassocReq_RSNXE_Used");
Jouni Malinen6250cb02020-04-15 13:54:45 +030015098 if (val && atoi(val) == 1) {
Veerendranath Jakkamc771fac2020-07-22 01:32:56 +053015099 if (wifi_chip_type == DRIVER_WCN) {
15100 if (wcn_sta_set_rsnxe_used(dut, intf, 1)) {
15101 send_resp(dut, conn, SIGMA_ERROR,
15102 "errorCode,Failed to set ft_rsnxe_used");
15103 return STATUS_SENT_ERROR;
15104 }
15105 return SUCCESS_SEND_STATUS;
15106 } else if (wpa_command(intf, "SET ft_rsnxe_used 1") < 0) {
Jouni Malinen6250cb02020-04-15 13:54:45 +030015107 send_resp(dut, conn, SIGMA_ERROR,
15108 "errorCode,Failed to set ft_rsnxe_used");
15109 return STATUS_SENT_ERROR;
15110 }
15111 return SUCCESS_SEND_STATUS;
15112 }
Vamsi Krishnad29bc762020-05-08 23:23:30 +053015113
15114 oci_chan = get_param(cmd, "OCIChannel");
15115 oci_frametype = get_param(cmd, "OCIFrameType");
15116 if (oci_chan && oci_frametype) {
15117 unsigned int oci_freq = channel_to_freq(dut, atoi(oci_chan));
15118 char buf[100];
15119
15120 if (!oci_freq) {
15121 send_resp(dut, conn, SIGMA_ERROR,
15122 "errorCode,Invalid OCIChannel number");
15123 return STATUS_SENT_ERROR;
15124 }
15125
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053015126 if (wifi_chip_type == DRIVER_WCN &&
15127 (strcasecmp(oci_frametype, "SAQueryReq") == 0 ||
15128 strcasecmp(oci_frametype, "SAQueryResp") == 0 ||
15129 strcasecmp(oci_frametype, "Reassocreq") == 0)) {
15130 if (wcn_sta_override_oci(dut, intf, oci_frametype,
15131 oci_freq)) {
15132 send_resp(dut, conn, SIGMA_ERROR,
15133 "errorCode,Failed to override OCI");
15134 return STATUS_SENT_ERROR;
15135 }
15136 return SUCCESS_SEND_STATUS;
15137 }
15138
Vamsi Krishnad29bc762020-05-08 23:23:30 +053015139 if (strcasecmp(oci_frametype, "eapolM2") == 0) {
15140 snprintf(buf, sizeof(buf),
15141 "SET oci_freq_override_eapol %d", oci_freq);
15142 } else if (strcasecmp(oci_frametype, "SAQueryReq") == 0) {
15143 snprintf(buf, sizeof(buf),
15144 "SET oci_freq_override_saquery_req %d",
15145 oci_freq);
15146 } else if (strcasecmp(oci_frametype, "SAQueryResp") == 0) {
15147 snprintf(buf, sizeof(buf),
15148 "SET oci_freq_override_saquery_resp %d",
15149 oci_freq);
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053015150 } else if (strcasecmp(oci_frametype, "GrpKeyM2") == 0) {
15151 snprintf(buf, sizeof(buf),
15152 "SET oci_freq_override_eapol_g2 %d",
15153 oci_freq);
15154 } else if (strcasecmp(oci_frametype, "Reassocreq") == 0) {
15155 snprintf(buf, sizeof(buf),
15156 "SET oci_freq_override_ft_assoc %d",
15157 oci_freq);
Vamsi Krishnad29bc762020-05-08 23:23:30 +053015158 } else {
15159 send_resp(dut, conn, SIGMA_ERROR,
15160 "errorCode,Unsupported OCIFrameType");
15161 return STATUS_SENT_ERROR;
15162 }
15163 if (wpa_command(intf, buf) < 0) {
15164 send_resp(dut, conn, SIGMA_ERROR,
15165 "errorCode,Failed to set oci_freq_override");
15166 return STATUS_SENT_ERROR;
15167 }
15168 return SUCCESS_SEND_STATUS;
15169 }
15170
Veerendranath Jakkam50d5c782020-07-22 01:59:01 +053015171 val = get_param(cmd, "IgnoreCSA");
15172 if (val && atoi(val) == 1) {
15173 if (wifi_chip_type == DRIVER_WCN) {
15174 if (wcn_sta_ignore_csa(dut, intf, 1)) {
15175 send_resp(dut, conn, SIGMA_ERROR,
15176 "errorCode,Failed to set ignore CSA");
15177 return STATUS_SENT_ERROR;
15178 }
15179 return SUCCESS_SEND_STATUS;
15180 }
15181 }
15182
Veerendranath Jakkam1e1e5fd2020-09-10 07:12:37 +053015183 val = get_param(cmd, "Deauth_Per_SAQueryResp");
15184 if (val && atoi(val) == 0) {
15185 if (wifi_chip_type == DRIVER_WCN) {
15186 if (wcn_sta_ignore_sa_query_timeout(dut, intf, 1)) {
15187 send_resp(dut, conn, SIGMA_ERROR,
15188 "errorCode,Failed to set ignore SA Query timeout");
15189 return STATUS_SENT_ERROR;
15190 }
15191 return SUCCESS_SEND_STATUS;
15192 }
15193 }
15194
Jouni Malinen6250cb02020-04-15 13:54:45 +030015195 send_resp(dut, conn, SIGMA_ERROR,
15196 "errorCode,Unsupported WPA3 rfeature");
15197 return STATUS_SENT_ERROR;
15198}
15199
15200
Veerendranath Jakkam329a3cd2021-09-11 18:10:13 +053015201static enum sigma_cmd_result
15202cmd_sta_set_rfeature_qm(const char *intf, struct sigma_dut *dut,
15203 struct sigma_conn *conn, struct sigma_cmd *cmd)
15204{
15205 const char *val;
15206
15207 val = get_param(cmd, "DomainName_Domain");
15208 if (val) {
15209 if (strlen(val) >= sizeof(dut->qm_domain_name))
15210 return ERROR_SEND_STATUS;
15211
15212 strlcpy(dut->qm_domain_name, val, sizeof(dut->qm_domain_name));
15213 return SUCCESS_SEND_STATUS;
15214 }
15215
Veerendranath Jakkam1bf1bd62021-09-12 16:35:55 +053015216 val = get_param(cmd, "DSCPPolicy_PolicyID");
15217 if (val) {
15218 unsigned int i;
15219 int policy_id = atoi(val);
15220
15221 val = get_param(cmd, "DSCPPolicy_RequestType");
15222
15223 if (!policy_id || !val)
15224 return INVALID_SEND_STATUS;
15225
15226 if (dut->num_dscp_status >= ARRAY_SIZE(dut->dscp_status)) {
15227 send_resp(dut, conn, SIGMA_ERROR,
15228 "errorCode,DSCP status list full");
15229 return STATUS_SENT_ERROR;
15230 }
15231
15232 for (i = 0; i < dut->num_dscp_status; i++)
15233 if (dut->dscp_status[i].id == policy_id)
15234 break;
15235
15236 /* New policy configured */
15237 if (i == dut->num_dscp_status) {
15238 dut->dscp_status[i].id = policy_id;
15239 dut->num_dscp_status++;
15240 }
15241
15242 dut->dscp_status[i].status = strcasecmp(val, "Remove") ?
15243 DSCP_POLICY_SUCCESS : DSCP_POLICY_REJECT;
15244
15245 return SUCCESS_SEND_STATUS;
15246 }
15247
Veerendranath Jakkam329a3cd2021-09-11 18:10:13 +053015248 send_resp(dut, conn, SIGMA_ERROR,
15249 "errorCode,Unsupported QM rfeature");
15250 return STATUS_SENT_ERROR;
15251}
15252
15253
Jouni Malinenf7222712019-06-13 01:50:21 +030015254static enum sigma_cmd_result cmd_sta_set_rfeature(struct sigma_dut *dut,
15255 struct sigma_conn *conn,
15256 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015257{
15258 const char *intf = get_param(cmd, "Interface");
15259 const char *prog = get_param(cmd, "Prog");
Ashwini Patil68d02cd2017-01-10 15:39:16 +053015260 const char *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015261
Veerendranath Jakkam329a3cd2021-09-11 18:10:13 +053015262 if (!prog)
15263 prog = get_param(cmd, "Program");
15264
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015265 if (intf == NULL || prog == NULL)
15266 return -1;
15267
Ashwini Patil5acd7382017-04-13 15:55:04 +053015268 /* BSS Transition candidate list for BTM query */
15269 val = get_param(cmd, "Nebor_BSSID");
15270 if (val && btm_query_candidate_list(dut, conn, cmd) == 0)
15271 return 0;
15272
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015273 if (strcasecmp(prog, "TDLS") == 0)
15274 return cmd_sta_set_rfeature_tdls(intf, dut, conn, cmd);
15275
15276 if (strcasecmp(prog, "VHT") == 0)
15277 return cmd_sta_set_rfeature_vht(intf, dut, conn, cmd);
15278
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080015279 if (strcasecmp(prog, "HE") == 0)
15280 return cmd_sta_set_rfeature_he(intf, dut, conn, cmd);
15281
Ashwini Patil68d02cd2017-01-10 15:39:16 +053015282 if (strcasecmp(prog, "MBO") == 0) {
15283 val = get_param(cmd, "Cellular_Data_Cap");
15284 if (val &&
15285 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
15286 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +053015287
15288 val = get_param(cmd, "Ch_Pref");
15289 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
15290 return 0;
15291
Ashwini Patil68d02cd2017-01-10 15:39:16 +053015292 return 1;
15293 }
15294
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020015295 if (strcasecmp(prog, "60GHz") == 0)
15296 return cmd_sta_set_rfeature_60g(intf, dut, conn, cmd);
15297
Jouni Malinen6250cb02020-04-15 13:54:45 +030015298 if (strcasecmp(prog, "WPA3") == 0)
15299 return cmd_sta_set_rfeature_wpa3(intf, dut, conn, cmd);
Veerendranath Jakkam329a3cd2021-09-11 18:10:13 +053015300 if (strcasecmp(prog, "QM") == 0)
15301 return cmd_sta_set_rfeature_qm(intf, dut, conn, cmd);
Jouni Malinen6250cb02020-04-15 13:54:45 +030015302
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015303 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported Prog");
15304 return 0;
15305}
15306
15307
Jouni Malinenf7222712019-06-13 01:50:21 +030015308static enum sigma_cmd_result cmd_sta_set_radio(struct sigma_dut *dut,
15309 struct sigma_conn *conn,
15310 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015311{
15312 const char *intf = get_param(cmd, "Interface");
15313 const char *mode = get_param(cmd, "Mode");
15314 int res;
15315
15316 if (intf == NULL || mode == NULL)
15317 return -1;
15318
15319 if (strcasecmp(mode, "On") == 0)
15320 res = wpa_command(intf, "SET radio_disabled 0");
15321 else if (strcasecmp(mode, "Off") == 0)
15322 res = wpa_command(intf, "SET radio_disabled 1");
15323 else
15324 return -1;
15325
15326 if (res) {
15327 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
15328 "radio mode");
15329 return 0;
15330 }
15331
15332 return 1;
15333}
15334
15335
Jouni Malinenf7222712019-06-13 01:50:21 +030015336static enum sigma_cmd_result cmd_sta_set_pwrsave(struct sigma_dut *dut,
15337 struct sigma_conn *conn,
15338 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015339{
15340 const char *intf = get_param(cmd, "Interface");
15341 const char *mode = get_param(cmd, "Mode");
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020015342 const char *prog = get_param(cmd, "program");
15343 const char *powersave = get_param(cmd, "powersave");
15344 int res = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015345
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020015346 if (intf == NULL)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015347 return -1;
15348
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020015349 if (prog && strcasecmp(prog, "60GHz") == 0) {
15350 /*
15351 * The CAPI mode parameter does not exist in 60G
15352 * unscheduled PS.
15353 */
Hu Wang5dc3ff12019-06-14 15:14:26 +080015354 if (powersave && strcasecmp(powersave, "unscheduled") == 0)
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020015355 res = set_ps(intf, dut, 1);
Jouni Malinen016ae6c2019-11-04 17:00:01 +020015356 } else if (prog && get_driver_type(dut) == DRIVER_WCN &&
Alexei Avshalom Lazar2f6fdb42019-02-04 14:16:08 +020015357 strcasecmp(prog, "HE") == 0) {
15358 return cmd_sta_set_power_save_he(intf, dut, conn, cmd);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020015359 } else {
15360 if (mode == NULL)
15361 return -1;
15362
15363 if (strcasecmp(mode, "On") == 0)
15364 res = set_ps(intf, dut, 1);
15365 else if (strcasecmp(mode, "Off") == 0)
15366 res = set_ps(intf, dut, 0);
15367 else
15368 return -1;
15369 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015370
15371 if (res) {
15372 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
15373 "power save mode");
15374 return 0;
15375 }
15376
15377 return 1;
15378}
15379
15380
Jouni Malinenf7222712019-06-13 01:50:21 +030015381static enum sigma_cmd_result cmd_sta_bssid_pool(struct sigma_dut *dut,
15382 struct sigma_conn *conn,
15383 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015384{
15385 const char *intf = get_param(cmd, "Interface");
15386 const char *val, *bssid;
15387 int res;
15388 char *buf;
15389 size_t buf_len;
15390
15391 val = get_param(cmd, "BSSID_FILTER");
15392 if (val == NULL)
15393 return -1;
15394
15395 bssid = get_param(cmd, "BSSID_List");
15396 if (atoi(val) == 0 || bssid == NULL) {
15397 /* Disable BSSID filter */
15398 if (wpa_command(intf, "SET bssid_filter ")) {
15399 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed "
15400 "to disable BSSID filter");
15401 return 0;
15402 }
15403
15404 return 1;
15405 }
15406
15407 buf_len = 100 + strlen(bssid);
15408 buf = malloc(buf_len);
15409 if (buf == NULL)
15410 return -1;
15411
15412 snprintf(buf, buf_len, "SET bssid_filter %s", bssid);
15413 res = wpa_command(intf, buf);
15414 free(buf);
15415 if (res) {
15416 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to enable "
15417 "BSSID filter");
15418 return 0;
15419 }
15420
15421 return 1;
15422}
15423
15424
Jouni Malinenf7222712019-06-13 01:50:21 +030015425static enum sigma_cmd_result cmd_sta_reset_parm(struct sigma_dut *dut,
15426 struct sigma_conn *conn,
15427 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015428{
15429 const char *intf = get_param(cmd, "Interface");
15430 const char *val;
15431
15432 /* TODO: ARP */
15433
15434 val = get_param(cmd, "HS2_CACHE_PROFILE");
15435 if (val && strcasecmp(val, "All") == 0)
15436 hs2_clear_credentials(intf);
15437
15438 return 1;
15439}
15440
15441
Jouni Malinenf7222712019-06-13 01:50:21 +030015442static enum sigma_cmd_result cmd_sta_get_key(struct sigma_dut *dut,
15443 struct sigma_conn *conn,
15444 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015445{
15446 const char *intf = get_param(cmd, "Interface");
15447 const char *key_type = get_param(cmd, "KeyType");
15448 char buf[100], resp[200];
15449
15450 if (key_type == NULL)
15451 return -1;
15452
15453 if (strcasecmp(key_type, "GTK") == 0) {
15454 if (wpa_command_resp(intf, "GET gtk", buf, sizeof(buf)) < 0 ||
15455 strncmp(buf, "FAIL", 4) == 0) {
15456 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
15457 "not fetch current GTK");
15458 return 0;
15459 }
15460 snprintf(resp, sizeof(resp), "KeyValue,%s", buf);
15461 send_resp(dut, conn, SIGMA_COMPLETE, resp);
15462 return 0;
15463 } else {
15464 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
15465 "KeyType");
15466 return 0;
15467 }
15468
15469 return 1;
15470}
15471
15472
15473static int hs2_set_policy(struct sigma_dut *dut)
15474{
15475#ifdef ANDROID
15476 system("ip rule del prio 23000");
15477 if (system("ip rule add from all lookup main prio 23000") != 0) {
15478 sigma_dut_print(dut, DUT_MSG_ERROR,
15479 "Failed to run:ip rule add from all lookup main prio");
15480 return -1;
15481 }
15482 if (system("ip route flush cache") != 0) {
15483 sigma_dut_print(dut, DUT_MSG_ERROR,
15484 "Failed to run ip route flush cache");
15485 return -1;
15486 }
15487 return 1;
15488#else /* ANDROID */
15489 return 0;
15490#endif /* ANDROID */
15491}
15492
15493
Jouni Malinenf7222712019-06-13 01:50:21 +030015494static enum sigma_cmd_result cmd_sta_hs2_associate(struct sigma_dut *dut,
15495 struct sigma_conn *conn,
15496 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015497{
15498 const char *intf = get_param(cmd, "Interface");
15499 const char *val = get_param(cmd, "Ignore_blacklist");
Jouni Malinen439352d2018-09-13 03:42:23 +030015500 const char *band = get_param(cmd, "Band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015501 struct wpa_ctrl *ctrl;
Jouni Malinen3aa72862019-05-29 23:14:51 +030015502 int res, r;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015503 char bssid[20], ssid[40], resp[100], buf[100], blacklisted[100];
15504 int tries = 0;
15505 int ignore_blacklist = 0;
15506 const char *events[] = {
15507 "CTRL-EVENT-CONNECTED",
15508 "INTERWORKING-BLACKLISTED",
15509 "INTERWORKING-NO-MATCH",
15510 NULL
15511 };
15512
15513 start_sta_mode(dut);
15514
Jouni Malinen439352d2018-09-13 03:42:23 +030015515 if (band) {
15516 if (strcmp(band, "2.4") == 0) {
15517 wpa_command(intf, "SET setband 2G");
15518 } else if (strcmp(band, "5") == 0) {
15519 wpa_command(intf, "SET setband 5G");
15520 } else {
15521 send_resp(dut, conn, SIGMA_ERROR,
15522 "errorCode,Unsupported band");
15523 return 0;
15524 }
15525 }
15526
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015527 blacklisted[0] = '\0';
15528 if (val && atoi(val))
15529 ignore_blacklist = 1;
15530
15531try_again:
15532 ctrl = open_wpa_mon(intf);
15533 if (ctrl == NULL) {
15534 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
15535 "wpa_supplicant monitor connection");
15536 return -2;
15537 }
15538
15539 tries++;
15540 if (wpa_command(intf, "INTERWORKING_SELECT auto")) {
15541 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start "
15542 "Interworking connection");
15543 wpa_ctrl_detach(ctrl);
15544 wpa_ctrl_close(ctrl);
15545 return 0;
15546 }
15547
15548 buf[0] = '\0';
15549 while (1) {
15550 char *pos;
15551 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
15552 pos = strstr(buf, "INTERWORKING-BLACKLISTED");
15553 if (!pos)
15554 break;
15555 pos += 25;
15556 sigma_dut_print(dut, DUT_MSG_DEBUG, "Found blacklisted AP: %s",
15557 pos);
15558 if (!blacklisted[0])
15559 memcpy(blacklisted, pos, strlen(pos) + 1);
15560 }
15561
15562 if (ignore_blacklist && blacklisted[0]) {
15563 char *end;
15564 end = strchr(blacklisted, ' ');
15565 if (end)
15566 *end = '\0';
15567 sigma_dut_print(dut, DUT_MSG_DEBUG, "Try to connect to a blacklisted network: %s",
15568 blacklisted);
Jouni Malinen3aa72862019-05-29 23:14:51 +030015569 r = snprintf(buf, sizeof(buf), "INTERWORKING_CONNECT %s",
15570 blacklisted);
15571 if (r < 0 || r >= sizeof(buf) || wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015572 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start Interworking connection to blacklisted network");
15573 wpa_ctrl_detach(ctrl);
15574 wpa_ctrl_close(ctrl);
15575 return 0;
15576 }
15577 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
15578 buf, sizeof(buf));
15579 }
15580
15581 wpa_ctrl_detach(ctrl);
15582 wpa_ctrl_close(ctrl);
15583
15584 if (res < 0) {
15585 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
15586 "connect");
15587 return 0;
15588 }
15589
15590 if (strstr(buf, "INTERWORKING-NO-MATCH") ||
15591 strstr(buf, "INTERWORKING-BLACKLISTED")) {
15592 if (tries < 2) {
15593 sigma_dut_print(dut, DUT_MSG_INFO, "No match found - try again to verify no APs were missed in the scan");
15594 goto try_again;
15595 }
15596 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,No network with "
15597 "matching credentials found");
15598 return 0;
15599 }
15600
15601 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
15602 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
15603 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
15604 "get current BSSID/SSID");
15605 return 0;
15606 }
15607
15608 snprintf(resp, sizeof(resp), "SSID,%s,BSSID,%s", ssid, bssid);
15609 send_resp(dut, conn, SIGMA_COMPLETE, resp);
15610 hs2_set_policy(dut);
15611 return 0;
15612}
15613
15614
Jouni Malinenf7222712019-06-13 01:50:21 +030015615static enum sigma_cmd_result cmd_sta_hs2_venue_info(struct sigma_dut *dut,
15616 struct sigma_conn *conn,
15617 struct sigma_cmd *cmd)
Jouni Malinenb639f1c2018-09-13 02:39:46 +030015618{
15619 const char *intf = get_param(cmd, "Interface");
15620 const char *display = get_param(cmd, "Display");
15621 struct wpa_ctrl *ctrl;
15622 char buf[300], params[400], *pos;
15623 char bssid[20];
15624 int info_avail = 0;
15625 unsigned int old_timeout;
15626 int res;
15627
15628 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
15629 send_resp(dut, conn, SIGMA_ERROR,
15630 "ErrorCode,Could not get current BSSID");
15631 return 0;
15632 }
15633 ctrl = open_wpa_mon(intf);
15634 if (!ctrl) {
15635 sigma_dut_print(dut, DUT_MSG_ERROR,
15636 "Failed to open wpa_supplicant monitor connection");
15637 return -2;
15638 }
15639
15640 snprintf(buf, sizeof(buf), "ANQP_GET %s 277", bssid);
15641 wpa_command(intf, buf);
15642
15643 res = get_wpa_cli_event(dut, ctrl, "GAS-QUERY-DONE", buf, sizeof(buf));
15644 if (res < 0) {
15645 send_resp(dut, conn, SIGMA_ERROR,
15646 "ErrorCode,Could not complete GAS query");
15647 goto fail;
15648 }
15649
15650 old_timeout = dut->default_timeout;
15651 dut->default_timeout = 2;
15652 res = get_wpa_cli_event(dut, ctrl, "RX-VENUE-URL", buf, sizeof(buf));
15653 dut->default_timeout = old_timeout;
15654 if (res < 0)
15655 goto done;
15656 pos = strchr(buf, ' ');
15657 if (!pos)
15658 goto done;
15659 pos++;
15660 pos = strchr(pos, ' ');
15661 if (!pos)
15662 goto done;
15663 pos++;
15664 info_avail = 1;
15665 snprintf(params, sizeof(params), "browser %s", pos);
15666
15667 if (display && strcasecmp(display, "Yes") == 0) {
15668 pid_t pid;
15669
15670 pid = fork();
15671 if (pid < 0) {
15672 perror("fork");
15673 return -1;
15674 }
15675
15676 if (pid == 0) {
15677 run_hs20_osu(dut, params);
15678 exit(0);
15679 }
15680 }
15681
15682done:
15683 snprintf(buf, sizeof(buf), "Info_available,%s",
15684 info_avail ? "Yes" : "No");
15685 send_resp(dut, conn, SIGMA_COMPLETE, buf);
15686fail:
15687 wpa_ctrl_detach(ctrl);
15688 wpa_ctrl_close(ctrl);
15689 return 0;
15690}
15691
15692
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015693static int sta_add_credential_uname_pwd(struct sigma_dut *dut,
15694 struct sigma_conn *conn,
15695 const char *ifname,
15696 struct sigma_cmd *cmd)
15697{
15698 const char *val;
15699 int id;
15700
15701 id = add_cred(ifname);
15702 if (id < 0)
15703 return -2;
15704 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
15705
15706 val = get_param(cmd, "prefer");
15707 if (val && atoi(val) > 0)
15708 set_cred(ifname, id, "priority", "1");
15709
15710 val = get_param(cmd, "REALM");
15711 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
15712 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
15713 "realm");
15714 return 0;
15715 }
15716
15717 val = get_param(cmd, "HOME_FQDN");
15718 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
15719 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
15720 "home_fqdn");
15721 return 0;
15722 }
15723
15724 val = get_param(cmd, "Username");
15725 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
15726 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
15727 "username");
15728 return 0;
15729 }
15730
15731 val = get_param(cmd, "Password");
15732 if (val && set_cred_quoted(ifname, id, "password", val) < 0) {
15733 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
15734 "password");
15735 return 0;
15736 }
15737
15738 val = get_param(cmd, "ROOT_CA");
15739 if (val) {
15740 char fname[200];
15741 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
15742#ifdef __linux__
15743 if (!file_exists(fname)) {
15744 char msg[300];
15745 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
15746 "file (%s) not found", fname);
15747 send_resp(dut, conn, SIGMA_ERROR, msg);
15748 return 0;
15749 }
15750#endif /* __linux__ */
15751 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
15752 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
15753 "not set root CA");
15754 return 0;
15755 }
15756 }
15757
15758 return 1;
15759}
15760
15761
15762static int update_devdetail_imsi(struct sigma_dut *dut, const char *imsi)
15763{
15764 FILE *in, *out;
15765 char buf[500];
15766 int found = 0;
15767
15768 in = fopen("devdetail.xml", "r");
15769 if (in == NULL)
15770 return -1;
15771 out = fopen("devdetail.xml.tmp", "w");
15772 if (out == NULL) {
15773 fclose(in);
15774 return -1;
15775 }
15776
15777 while (fgets(buf, sizeof(buf), in)) {
15778 char *pos = strstr(buf, "<IMSI>");
15779 if (pos) {
15780 sigma_dut_print(dut, DUT_MSG_INFO, "Updated DevDetail IMSI to %s",
15781 imsi);
15782 pos += 6;
15783 *pos = '\0';
15784 fprintf(out, "%s%s</IMSI>\n", buf, imsi);
15785 found++;
15786 } else {
15787 fprintf(out, "%s", buf);
15788 }
15789 }
15790
15791 fclose(out);
15792 fclose(in);
15793 if (found)
15794 rename("devdetail.xml.tmp", "devdetail.xml");
15795 else
15796 unlink("devdetail.xml.tmp");
15797
15798 return 0;
15799}
15800
15801
15802static int sta_add_credential_sim(struct sigma_dut *dut,
15803 struct sigma_conn *conn,
15804 const char *ifname, struct sigma_cmd *cmd)
15805{
15806 const char *val, *imsi = NULL;
15807 int id;
15808 char buf[200];
15809 int res;
15810 const char *pos;
15811 size_t mnc_len;
15812 char plmn_mcc[4];
15813 char plmn_mnc[4];
15814
15815 id = add_cred(ifname);
15816 if (id < 0)
15817 return -2;
15818 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
15819
15820 val = get_param(cmd, "prefer");
15821 if (val && atoi(val) > 0)
15822 set_cred(ifname, id, "priority", "1");
15823
15824 val = get_param(cmd, "PLMN_MCC");
15825 if (val == NULL) {
15826 send_resp(dut, conn, SIGMA_ERROR,
15827 "errorCode,Missing PLMN_MCC");
15828 return 0;
15829 }
15830 if (strlen(val) != 3) {
15831 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MCC");
15832 return 0;
15833 }
15834 snprintf(plmn_mcc, sizeof(plmn_mcc), "%s", val);
15835
15836 val = get_param(cmd, "PLMN_MNC");
15837 if (val == NULL) {
15838 send_resp(dut, conn, SIGMA_ERROR,
15839 "errorCode,Missing PLMN_MNC");
15840 return 0;
15841 }
15842 if (strlen(val) != 2 && strlen(val) != 3) {
15843 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MNC");
15844 return 0;
15845 }
15846 snprintf(plmn_mnc, sizeof(plmn_mnc), "%s", val);
15847
15848 val = get_param(cmd, "IMSI");
15849 if (val == NULL) {
15850 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing SIM "
15851 "IMSI");
15852 return 0;
15853 }
15854
15855 imsi = pos = val;
15856
15857 if (strncmp(plmn_mcc, pos, 3) != 0) {
15858 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MCC mismatch");
15859 return 0;
15860 }
15861 pos += 3;
15862
15863 mnc_len = strlen(plmn_mnc);
15864 if (mnc_len < 2) {
15865 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC not set");
15866 return 0;
15867 }
15868
15869 if (strncmp(plmn_mnc, pos, mnc_len) != 0) {
15870 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC mismatch");
15871 return 0;
15872 }
15873 pos += mnc_len;
15874
15875 res = snprintf(buf, sizeof(buf), "%s%s-%s",plmn_mcc, plmn_mnc, pos);
15876 if (res < 0 || res >= (int) sizeof(buf))
15877 return -1;
15878 if (set_cred_quoted(ifname, id, "imsi", buf) < 0) {
15879 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
15880 "not set IMSI");
15881 return 0;
15882 }
15883
15884 val = get_param(cmd, "Password");
15885 if (val && set_cred_quoted(ifname, id, "milenage", val) < 0) {
15886 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
15887 "not set password");
15888 return 0;
15889 }
15890
Jouni Malinenba630452018-06-22 11:49:59 +030015891 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015892 /*
15893 * Set provisioning_sp for the test cases where SIM/USIM
15894 * provisioning is used.
15895 */
15896 if (val && set_cred_quoted(ifname, id, "provisioning_sp",
15897 "wi-fi.org") < 0) {
15898 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
15899 "not set provisioning_sp");
15900 return 0;
15901 }
15902
15903 update_devdetail_imsi(dut, imsi);
15904 }
15905
15906 return 1;
15907}
15908
15909
15910static int sta_add_credential_cert(struct sigma_dut *dut,
15911 struct sigma_conn *conn,
15912 const char *ifname,
15913 struct sigma_cmd *cmd)
15914{
15915 const char *val;
15916 int id;
15917
15918 id = add_cred(ifname);
15919 if (id < 0)
15920 return -2;
15921 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
15922
15923 val = get_param(cmd, "prefer");
15924 if (val && atoi(val) > 0)
15925 set_cred(ifname, id, "priority", "1");
15926
15927 val = get_param(cmd, "REALM");
15928 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
15929 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
15930 "realm");
15931 return 0;
15932 }
15933
15934 val = get_param(cmd, "HOME_FQDN");
15935 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
15936 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
15937 "home_fqdn");
15938 return 0;
15939 }
15940
15941 val = get_param(cmd, "Username");
15942 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
15943 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
15944 "username");
15945 return 0;
15946 }
15947
15948 val = get_param(cmd, "clientCertificate");
15949 if (val) {
15950 char fname[200];
15951 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
15952#ifdef __linux__
15953 if (!file_exists(fname)) {
15954 char msg[300];
15955 snprintf(msg, sizeof(msg),
15956 "ErrorCode,clientCertificate "
15957 "file (%s) not found", fname);
15958 send_resp(dut, conn, SIGMA_ERROR, msg);
15959 return 0;
15960 }
15961#endif /* __linux__ */
15962 if (set_cred_quoted(ifname, id, "client_cert", fname) < 0) {
15963 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
15964 "not set client_cert");
15965 return 0;
15966 }
15967 if (set_cred_quoted(ifname, id, "private_key", fname) < 0) {
15968 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
15969 "not set private_key");
15970 return 0;
15971 }
15972 }
15973
15974 val = get_param(cmd, "ROOT_CA");
15975 if (val) {
15976 char fname[200];
15977 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
15978#ifdef __linux__
15979 if (!file_exists(fname)) {
15980 char msg[300];
15981 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
15982 "file (%s) not found", fname);
15983 send_resp(dut, conn, SIGMA_ERROR, msg);
15984 return 0;
15985 }
15986#endif /* __linux__ */
15987 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
15988 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
15989 "not set root CA");
15990 return 0;
15991 }
15992 }
15993
15994 return 1;
15995}
15996
15997
Jouni Malinenf7222712019-06-13 01:50:21 +030015998static enum sigma_cmd_result cmd_sta_add_credential(struct sigma_dut *dut,
15999 struct sigma_conn *conn,
16000 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016001{
16002 const char *intf = get_param(cmd, "Interface");
16003 const char *type;
16004
16005 start_sta_mode(dut);
16006
16007 type = get_param(cmd, "Type");
16008 if (!type)
16009 return -1;
16010
16011 if (strcasecmp(type, "uname_pwd") == 0)
16012 return sta_add_credential_uname_pwd(dut, conn, intf, cmd);
16013
16014 if (strcasecmp(type, "sim") == 0)
16015 return sta_add_credential_sim(dut, conn, intf, cmd);
16016
16017 if (strcasecmp(type, "cert") == 0)
16018 return sta_add_credential_cert(dut, conn, intf, cmd);
16019
16020 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported credential "
16021 "type");
16022 return 0;
16023}
16024
16025
Jouni Malinenf7222712019-06-13 01:50:21 +030016026static enum sigma_cmd_result cmd_sta_scan(struct sigma_dut *dut,
16027 struct sigma_conn *conn,
16028 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016029{
16030 const char *intf = get_param(cmd, "Interface");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080016031 const char *val, *bssid, *ssid, *scan_freq, *short_ssid;
Veerendranathdc581b52020-08-10 03:29:08 -070016032 char buf[4096], scan_res[20];
vamsi krishna89ad8c62017-09-19 12:51:18 +053016033 char ssid_hex[65];
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080016034 int wildcard_ssid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016035 int res;
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080016036 enum sigma_cmd_result status;
Jouni Malinen228a2fc2020-06-22 23:37:45 +030016037 struct wpa_ctrl *ctrl = NULL;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016038
Jouni Malinen8c1abeb2019-11-06 18:48:34 +020016039 start_sta_mode(dut);
16040
Arif Hussain66a4af02019-02-07 15:04:51 -080016041 val = get_param(cmd, "GetParameter");
16042 if (val && strcmp(val, "SSID_BSSID") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020016043 if (get_wpa_ssid_bssid(dut, get_station_ifname(dut),
Arif Hussain66a4af02019-02-07 15:04:51 -080016044 buf, sizeof(buf)) < 0) {
16045 sigma_dut_print(dut, DUT_MSG_ERROR,
16046 "Could not get ssid bssid");
16047 return ERROR_SEND_STATUS;
16048 }
16049
16050 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
16051 send_resp(dut, conn, SIGMA_COMPLETE, buf);
16052 return STATUS_SENT;
16053 }
16054
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016055 val = get_param(cmd, "HESSID");
16056 if (val) {
16057 res = snprintf(buf, sizeof(buf), "SET hessid %s", val);
16058 if (res < 0 || res >= (int) sizeof(buf))
16059 return -1;
16060 wpa_command(intf, buf);
16061 }
16062
16063 val = get_param(cmd, "ACCS_NET_TYPE");
16064 if (val) {
16065 res = snprintf(buf, sizeof(buf), "SET access_network_type %s",
16066 val);
16067 if (res < 0 || res >= (int) sizeof(buf))
16068 return -1;
16069 wpa_command(intf, buf);
16070 }
16071
Kiran Kumar Lokere69d89952021-08-08 23:41:46 -070016072 if (get_param(cmd, "RxMac"))
16073 sta_set_scan_unicast_probe(dut, intf, 1);
16074
vamsi krishna89ad8c62017-09-19 12:51:18 +053016075 bssid = get_param(cmd, "Bssid");
16076 ssid = get_param(cmd, "Ssid");
Kiran Kumar Lokere69d89952021-08-08 23:41:46 -070016077 if (!bssid)
16078 bssid = get_param(cmd, "RxMac");
vamsi krishna89ad8c62017-09-19 12:51:18 +053016079
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080016080 if (ssid && strcasecmp(ssid, "ZeroLength") == 0 &&
16081 dut->device_type == STA_testbed) {
16082 ssid = NULL;
16083 wildcard_ssid = 1;
16084 }
16085
vamsi krishna89ad8c62017-09-19 12:51:18 +053016086 if (ssid) {
16087 if (2 * strlen(ssid) >= sizeof(ssid_hex)) {
16088 send_resp(dut, conn, SIGMA_ERROR,
16089 "ErrorCode,Too long SSID");
16090 return 0;
16091 }
16092 ascii2hexstr(ssid, ssid_hex);
16093 }
16094
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080016095 short_ssid = get_param(cmd, "ShortSSID");
16096 if (short_ssid) {
16097 uint32_t short_ssid_hex;
16098
16099 short_ssid_hex = strtoul(short_ssid, NULL, 16);
16100 short_ssid_hex = ((short_ssid_hex & 0xFF) << 24) |
16101 (((short_ssid_hex >> 8) & 0xFF) << 16) |
16102 (((short_ssid_hex >> 16) & 0xFF) << 8) |
16103 ((short_ssid_hex >> 24) & 0xFF);
16104
16105 res = snprintf(buf, sizeof(buf),
16106 "VENDOR_ELEM_ADD 14 ff053a%08x",
16107 short_ssid_hex);
16108 if (res < 0 || res >= (int) sizeof(buf) ||
16109 wpa_command(intf, buf)) {
16110 send_resp(dut, conn, SIGMA_ERROR,
16111 "errorCode,Failed to add short SSID");
16112 return STATUS_SENT_ERROR;
16113 }
16114 }
16115
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080016116 scan_freq = get_param(cmd, "ChnlFreq");
Veerendranath Jakkam132c4b42020-08-10 00:29:03 +053016117 if (scan_freq) {
16118 if (strcasecmp(scan_freq, "2G") == 0)
16119 scan_freq = "2412-2462";
16120 else if (strcasecmp(scan_freq, "5G") == 0)
16121 scan_freq = "5180-5925";
16122 }
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080016123
Jouni Malinen228a2fc2020-06-22 23:37:45 +030016124 val = get_param(cmd, "WaitCompletion");
16125 if (val && atoi(val) == 1) {
16126 ctrl = open_wpa_mon(intf);
16127 if (!ctrl) {
16128 send_resp(dut, conn, SIGMA_ERROR,
16129 "errorCode,Failed to open monitor socket");
16130 return STATUS_SENT_ERROR;
16131 }
16132 }
16133
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080016134 res = snprintf(buf, sizeof(buf), "SCAN%s%s%s%s%s%s%s",
vamsi krishna89ad8c62017-09-19 12:51:18 +053016135 bssid ? " bssid=": "",
16136 bssid ? bssid : "",
16137 ssid ? " ssid " : "",
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080016138 ssid ? ssid_hex : "",
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080016139 wildcard_ssid ? " wildcard_ssid=1" : "",
16140 scan_freq ? " freq=" : "",
16141 scan_freq ? scan_freq : "");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080016142 if (res < 0 || res >= (int) sizeof(buf)) {
16143 send_resp(dut, conn, SIGMA_ERROR,
16144 "errorCode,Could not build scan command");
16145 status = STATUS_SENT_ERROR;
16146 goto remove_s_ssid;
16147 }
vamsi krishna89ad8c62017-09-19 12:51:18 +053016148
Veerendranathdc581b52020-08-10 03:29:08 -070016149 res = wpa_command_resp(intf, buf, scan_res, sizeof(scan_res));
16150 if (strncmp(scan_res, "FAIL-BUSY", 9) == 0) {
16151 sigma_dut_print(dut, DUT_MSG_DEBUG,
16152 "Scan request rejected with busy status, abort ongoing scan and try again");
16153 wpa_command(intf, "ABORT_SCAN");
16154 res = wpa_command(intf, buf);
16155 }
16156
16157 if (res < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016158 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not start "
16159 "scan");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080016160 status = STATUS_SENT_ERROR;
16161 } else {
16162 status = SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016163 }
16164
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080016165remove_s_ssid:
16166 if (short_ssid && wpa_command(intf, "VENDOR_ELEM_REMOVE 14 *"))
16167 sigma_dut_print(dut, DUT_MSG_ERROR,
16168 "Failed to delete vendor element");
16169
Jouni Malinen228a2fc2020-06-22 23:37:45 +030016170 if (ctrl) {
16171 if (status == SUCCESS_SEND_STATUS) {
16172 res = get_wpa_cli_event(dut, ctrl,
16173 "CTRL-EVENT-SCAN-RESULTS",
16174 buf, sizeof(buf));
16175 if (res < 0) {
16176 send_resp(dut, conn, SIGMA_ERROR,
16177 "ErrorCode,scan did not complete");
16178 status = STATUS_SENT_ERROR;
16179 }
16180 }
16181
16182 wpa_ctrl_detach(ctrl);
16183 wpa_ctrl_close(ctrl);
16184 }
16185
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080016186 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016187}
16188
16189
Jouni Malinenf7222712019-06-13 01:50:21 +030016190static enum sigma_cmd_result cmd_sta_scan_bss(struct sigma_dut *dut,
16191 struct sigma_conn *conn,
16192 struct sigma_cmd *cmd)
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020016193{
16194 const char *intf = get_param(cmd, "Interface");
16195 const char *bssid;
16196 char buf[4096], *pos;
16197 int freq, chan;
16198 char *ssid;
16199 char resp[100];
16200 int res;
16201 struct wpa_ctrl *ctrl;
16202
16203 bssid = get_param(cmd, "BSSID");
16204 if (!bssid) {
16205 send_resp(dut, conn, SIGMA_INVALID,
16206 "errorCode,BSSID argument is missing");
16207 return 0;
16208 }
16209
16210 ctrl = open_wpa_mon(intf);
16211 if (!ctrl) {
16212 sigma_dut_print(dut, DUT_MSG_ERROR,
16213 "Failed to open wpa_supplicant monitor connection");
16214 return -1;
16215 }
16216
16217 if (wpa_command(intf, "SCAN TYPE=ONLY")) {
16218 send_resp(dut, conn, SIGMA_ERROR,
16219 "errorCode,Could not start scan");
16220 wpa_ctrl_detach(ctrl);
16221 wpa_ctrl_close(ctrl);
16222 return 0;
16223 }
16224
16225 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
16226 buf, sizeof(buf));
16227
16228 wpa_ctrl_detach(ctrl);
16229 wpa_ctrl_close(ctrl);
16230
16231 if (res < 0) {
16232 send_resp(dut, conn, SIGMA_ERROR,
16233 "errorCode,Scan did not complete");
16234 return 0;
16235 }
16236
16237 snprintf(buf, sizeof(buf), "BSS %s", bssid);
16238 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
16239 strncmp(buf, "id=", 3) != 0) {
16240 send_resp(dut, conn, SIGMA_ERROR,
16241 "errorCode,Specified BSSID not found");
16242 return 0;
16243 }
16244
16245 pos = strstr(buf, "\nfreq=");
16246 if (!pos) {
16247 send_resp(dut, conn, SIGMA_ERROR,
16248 "errorCode,Channel not found");
16249 return 0;
16250 }
16251 freq = atoi(pos + 6);
16252 chan = freq_to_channel(freq);
16253
16254 pos = strstr(buf, "\nssid=");
16255 if (!pos) {
16256 send_resp(dut, conn, SIGMA_ERROR,
16257 "errorCode,SSID not found");
16258 return 0;
16259 }
16260 ssid = pos + 6;
16261 pos = strchr(ssid, '\n');
16262 if (pos)
16263 *pos = '\0';
16264 snprintf(resp, sizeof(resp), "ssid,%s,bsschannel,%d", ssid, chan);
16265 send_resp(dut, conn, SIGMA_COMPLETE, resp);
16266 return 0;
16267}
16268
16269
Jouni Malinenf7222712019-06-13 01:50:21 +030016270static enum sigma_cmd_result cmd_sta_set_systime(struct sigma_dut *dut,
16271 struct sigma_conn *conn,
16272 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016273{
16274#ifdef __linux__
16275 struct timeval tv;
16276 struct tm tm;
16277 time_t t;
16278 const char *val;
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053016279 int v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016280
Jouni Malinen016ae6c2019-11-04 17:00:01 +020016281 wpa_command(get_station_ifname(dut), "PMKSA_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016282
16283 memset(&tm, 0, sizeof(tm));
16284 val = get_param(cmd, "seconds");
16285 if (val)
16286 tm.tm_sec = atoi(val);
16287 val = get_param(cmd, "minutes");
16288 if (val)
16289 tm.tm_min = atoi(val);
16290 val = get_param(cmd, "hours");
16291 if (val)
16292 tm.tm_hour = atoi(val);
16293 val = get_param(cmd, "date");
16294 if (val)
16295 tm.tm_mday = atoi(val);
16296 val = get_param(cmd, "month");
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053016297 if (val) {
16298 v = atoi(val);
16299 if (v < 1 || v > 12) {
16300 send_resp(dut, conn, SIGMA_INVALID,
16301 "errorCode,Invalid month");
16302 return 0;
16303 }
16304 tm.tm_mon = v - 1;
16305 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016306 val = get_param(cmd, "year");
16307 if (val) {
16308 int year = atoi(val);
16309#ifdef ANDROID
16310 if (year > 2035)
16311 year = 2035; /* years beyond 2035 not supported */
16312#endif /* ANDROID */
16313 tm.tm_year = year - 1900;
16314 }
16315 t = mktime(&tm);
16316 if (t == (time_t) -1) {
16317 send_resp(dut, conn, SIGMA_ERROR,
16318 "errorCode,Invalid date or time");
16319 return 0;
16320 }
16321
16322 memset(&tv, 0, sizeof(tv));
16323 tv.tv_sec = t;
16324
16325 if (settimeofday(&tv, NULL) < 0) {
16326 sigma_dut_print(dut, DUT_MSG_INFO, "settimeofday failed: %s",
16327 strerror(errno));
16328 send_resp(dut, conn, SIGMA_ERROR,
16329 "errorCode,Failed to set time");
16330 return 0;
16331 }
16332
16333 return 1;
16334#endif /* __linux__ */
16335
16336 return -1;
16337}
16338
16339
Jouni Malinenf7222712019-06-13 01:50:21 +030016340static enum sigma_cmd_result cmd_sta_osu(struct sigma_dut *dut,
16341 struct sigma_conn *conn,
16342 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016343{
16344 const char *intf = get_param(cmd, "Interface");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030016345 const char *name, *osu_ssid, *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016346 int prod_ess_assoc = 1;
Jouni Malinen4c8681c2018-09-12 23:28:11 +030016347 char buf[300], bssid[100], ssid[100];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016348 int res;
16349 struct wpa_ctrl *ctrl;
16350
16351 name = get_param(cmd, "osuFriendlyName");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030016352 osu_ssid = get_param(cmd, "osu_ssid");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016353
16354 val = get_param(cmd, "ProdESSAssoc");
16355 if (val)
16356 prod_ess_assoc = atoi(val);
16357
16358 kill_dhcp_client(dut, intf);
16359 if (start_dhcp_client(dut, intf) < 0)
16360 return -2;
16361
16362 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger OSU");
16363 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
16364 res = snprintf(buf, sizeof(buf),
Jouni Malinen4c8681c2018-09-12 23:28:11 +030016365 "%s %s%s%s %s%s%s signup osu-ca.pem",
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016366 prod_ess_assoc ? "" : "-N",
16367 name ? "-O'" : "", name ? name : "",
Jouni Malinen4c8681c2018-09-12 23:28:11 +030016368 name ? "'" : "",
16369 osu_ssid ? "-o'" : "", osu_ssid ? osu_ssid : "",
16370 osu_ssid ? "'" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016371
Kanchanapally, Vidyullatha12b66762015-12-31 16:46:42 +053016372 hs2_set_policy(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016373 if (run_hs20_osu(dut, buf) < 0) {
16374 FILE *f;
16375
16376 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to complete OSU");
16377
16378 f = fopen("hs20-osu-client.res", "r");
16379 if (f) {
16380 char resp[400], res[300], *pos;
16381 if (!fgets(res, sizeof(res), f))
16382 res[0] = '\0';
16383 pos = strchr(res, '\n');
16384 if (pos)
16385 *pos = '\0';
16386 fclose(f);
16387 sigma_dut_summary(dut, "hs20-osu-client provisioning failed: %s",
16388 res);
16389 snprintf(resp, sizeof(resp), "notify-send '%s'", res);
16390 if (system(resp) != 0) {
16391 }
16392 snprintf(resp, sizeof(resp),
16393 "SSID,,BSSID,,failureReason,%s", res);
16394 send_resp(dut, conn, SIGMA_COMPLETE, resp);
16395 return 0;
16396 }
16397
16398 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
16399 return 0;
16400 }
16401
16402 if (!prod_ess_assoc)
16403 goto report;
16404
16405 ctrl = open_wpa_mon(intf);
16406 if (ctrl == NULL) {
16407 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
16408 "wpa_supplicant monitor connection");
16409 return -1;
16410 }
16411
16412 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
16413 buf, sizeof(buf));
16414
16415 wpa_ctrl_detach(ctrl);
16416 wpa_ctrl_close(ctrl);
16417
16418 if (res < 0) {
16419 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to connect to "
16420 "network after OSU");
16421 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
16422 return 0;
16423 }
16424
16425report:
16426 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
16427 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
16428 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get BSSID/SSID");
16429 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
16430 return 0;
16431 }
16432
16433 snprintf(buf, sizeof(buf), "SSID,%s,BSSID,%s", ssid, bssid);
16434 send_resp(dut, conn, SIGMA_COMPLETE, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016435 return 0;
16436}
16437
16438
Jouni Malinenf7222712019-06-13 01:50:21 +030016439static enum sigma_cmd_result cmd_sta_policy_update(struct sigma_dut *dut,
16440 struct sigma_conn *conn,
16441 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016442{
16443 const char *val;
16444 int timeout = 120;
16445
16446 val = get_param(cmd, "PolicyUpdate");
16447 if (val == NULL || atoi(val) == 0)
16448 return 1; /* No operation requested */
16449
16450 val = get_param(cmd, "Timeout");
16451 if (val)
16452 timeout = atoi(val);
16453
16454 if (timeout) {
16455 /* TODO: time out the command and return
16456 * PolicyUpdateStatus,TIMEOUT if needed. */
16457 }
16458
16459 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger policy update");
16460 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
16461 if (run_hs20_osu(dut, "pol_upd fqdn=wi-fi.org") < 0) {
16462 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,FAIL");
16463 return 0;
16464 }
16465
16466 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,SUCCESS");
16467 return 0;
16468}
16469
16470
Jouni Malinenf7222712019-06-13 01:50:21 +030016471static enum sigma_cmd_result cmd_sta_er_config(struct sigma_dut *dut,
16472 struct sigma_conn *conn,
16473 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016474{
16475 struct wpa_ctrl *ctrl;
16476 const char *intf = get_param(cmd, "Interface");
16477 const char *bssid = get_param(cmd, "Bssid");
16478 const char *ssid = get_param(cmd, "SSID");
16479 const char *security = get_param(cmd, "Security");
16480 const char *passphrase = get_param(cmd, "Passphrase");
16481 const char *pin = get_param(cmd, "PIN");
16482 char buf[1000];
16483 char ssid_hex[200], passphrase_hex[200];
16484 const char *keymgmt, *cipher;
16485
16486 if (intf == NULL)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020016487 intf = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016488
16489 if (!bssid) {
16490 send_resp(dut, conn, SIGMA_ERROR,
16491 "ErrorCode,Missing Bssid argument");
16492 return 0;
16493 }
16494
16495 if (!ssid) {
16496 send_resp(dut, conn, SIGMA_ERROR,
16497 "ErrorCode,Missing SSID argument");
16498 return 0;
16499 }
16500
16501 if (!security) {
16502 send_resp(dut, conn, SIGMA_ERROR,
16503 "ErrorCode,Missing Security argument");
16504 return 0;
16505 }
16506
16507 if (!passphrase) {
16508 send_resp(dut, conn, SIGMA_ERROR,
16509 "ErrorCode,Missing Passphrase argument");
16510 return 0;
16511 }
16512
16513 if (!pin) {
16514 send_resp(dut, conn, SIGMA_ERROR,
16515 "ErrorCode,Missing PIN argument");
16516 return 0;
16517 }
16518
vamsi krishna8c9c1562017-05-12 15:51:46 +053016519 if (2 * strlen(ssid) >= sizeof(ssid_hex) ||
16520 2 * strlen(passphrase) >= sizeof(passphrase_hex)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016521 send_resp(dut, conn, SIGMA_ERROR,
16522 "ErrorCode,Too long SSID/passphrase");
16523 return 0;
16524 }
16525
16526 ctrl = open_wpa_mon(intf);
16527 if (ctrl == NULL) {
16528 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
16529 "wpa_supplicant monitor connection");
16530 return -2;
16531 }
16532
16533 if (strcasecmp(security, "wpa2-psk") == 0) {
16534 keymgmt = "WPA2PSK";
16535 cipher = "CCMP";
16536 } else {
16537 wpa_ctrl_detach(ctrl);
16538 wpa_ctrl_close(ctrl);
16539 send_resp(dut, conn, SIGMA_ERROR,
16540 "ErrorCode,Unsupported Security value");
16541 return 0;
16542 }
16543
16544 ascii2hexstr(ssid, ssid_hex);
16545 ascii2hexstr(passphrase, passphrase_hex);
16546 snprintf(buf, sizeof(buf), "WPS_REG %s %s %s %s %s %s",
16547 bssid, pin, ssid_hex, keymgmt, cipher, passphrase_hex);
16548
16549 if (wpa_command(intf, buf) < 0) {
16550 wpa_ctrl_detach(ctrl);
16551 wpa_ctrl_close(ctrl);
16552 send_resp(dut, conn, SIGMA_ERROR,
16553 "ErrorCode,Failed to start registrar");
16554 return 0;
16555 }
16556
16557 snprintf(dut->er_oper_bssid, sizeof(dut->er_oper_bssid), "%s", bssid);
16558 dut->er_oper_performed = 1;
16559
16560 return wps_connection_event(dut, conn, ctrl, intf, 0);
16561}
16562
16563
Jouni Malinenf7222712019-06-13 01:50:21 +030016564static enum sigma_cmd_result
16565cmd_sta_wps_connect_pw_token(struct sigma_dut *dut, struct sigma_conn *conn,
16566 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016567{
16568 struct wpa_ctrl *ctrl;
16569 const char *intf = get_param(cmd, "Interface");
16570 const char *bssid = get_param(cmd, "Bssid");
16571 char buf[100];
16572
16573 if (!bssid) {
16574 send_resp(dut, conn, SIGMA_ERROR,
16575 "ErrorCode,Missing Bssid argument");
16576 return 0;
16577 }
16578
16579 ctrl = open_wpa_mon(intf);
16580 if (ctrl == NULL) {
16581 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
16582 "wpa_supplicant monitor connection");
16583 return -2;
16584 }
16585
16586 snprintf(buf, sizeof(buf), "WPS_NFC %s", bssid);
16587
16588 if (wpa_command(intf, buf) < 0) {
16589 wpa_ctrl_detach(ctrl);
16590 wpa_ctrl_close(ctrl);
16591 send_resp(dut, conn, SIGMA_ERROR,
16592 "ErrorCode,Failed to start registrar");
16593 return 0;
16594 }
16595
16596 return wps_connection_event(dut, conn, ctrl, intf, 0);
16597}
16598
16599
Jouni Malinenf7222712019-06-13 01:50:21 +030016600static enum sigma_cmd_result cmd_start_wps_registration(struct sigma_dut *dut,
16601 struct sigma_conn *conn,
16602 struct sigma_cmd *cmd)
vamsi krishna9b144002017-09-20 13:28:13 +053016603{
16604 struct wpa_ctrl *ctrl;
16605 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020016606 const char *network_mode = get_param(cmd, "network_mode");
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020016607 const char *config_method = get_param(cmd, "WPSConfigMethod");
16608 const char *role;
vamsi krishna9b144002017-09-20 13:28:13 +053016609 int res;
16610 char buf[256];
16611 const char *events[] = {
16612 "CTRL-EVENT-CONNECTED",
16613 "WPS-OVERLAP-DETECTED",
16614 "WPS-TIMEOUT",
16615 "WPS-FAIL",
16616 NULL
16617 };
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020016618 int id = 0;
vamsi krishna9b144002017-09-20 13:28:13 +053016619
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020016620 /* 60G WPS tests do not pass Interface parameter */
16621 if (!intf)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020016622 intf = get_main_ifname(dut);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020016623
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020016624 if (dut->mode == SIGMA_MODE_AP)
16625 return ap_wps_registration(dut, conn, cmd);
16626
16627 if (config_method) {
16628 /* WFA_CS_WPS_PIN_KEYPAD mode is set when using the
16629 * sta_wps_enter_pin before calling start_wps_registration. */
16630 if (strcasecmp(config_method, "PBC") == 0)
16631 dut->wps_method = WFA_CS_WPS_PBC;
16632 }
16633 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
16634 send_resp(dut, conn, SIGMA_ERROR,
16635 "ErrorCode,WPS parameters not yet set");
16636 return STATUS_SENT;
16637 }
16638
16639 /* Make sure WPS is enabled (also for STA mode) */
16640 dut->wps_disable = 0;
16641
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020016642 if (dut->band == WPS_BAND_60G && network_mode &&
16643 strcasecmp(network_mode, "PBSS") == 0) {
16644 sigma_dut_print(dut, DUT_MSG_DEBUG,
16645 "Set PBSS network mode, network id %d", id);
Jouni Malinen016ae6c2019-11-04 17:00:01 +020016646 if (set_network(get_station_ifname(dut), id, "pbss", "1") < 0)
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020016647 return -2;
16648 }
16649
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020016650 if (dut->force_rsn_ie) {
16651 sigma_dut_print(dut, DUT_MSG_DEBUG, "Force RSN_IE: %d",
16652 dut->force_rsn_ie);
16653 if (sta_60g_force_rsn_ie(dut, dut->force_rsn_ie) < 0) {
16654 sigma_dut_print(dut, DUT_MSG_INFO,
16655 "Failed to force RSN_IE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020016656 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020016657 }
16658 }
16659
vamsi krishna9b144002017-09-20 13:28:13 +053016660 ctrl = open_wpa_mon(intf);
16661 if (!ctrl) {
16662 sigma_dut_print(dut, DUT_MSG_ERROR,
16663 "Failed to open wpa_supplicant monitor connection");
16664 return -2;
16665 }
16666
16667 role = get_param(cmd, "WpsRole");
16668 if (!role) {
16669 send_resp(dut, conn, SIGMA_INVALID,
16670 "ErrorCode,WpsRole not provided");
16671 goto fail;
16672 }
16673
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020016674 if (strcasecmp(role, "Enrollee") != 0) {
16675 /* Registrar role for STA not supported */
16676 send_resp(dut, conn, SIGMA_ERROR,
16677 "ErrorCode,Unsupported WpsRole value");
16678 goto fail;
16679 }
16680
16681 if (is_60g_sigma_dut(dut)) {
16682 if (dut->wps_method == WFA_CS_WPS_PBC)
16683 snprintf(buf, sizeof(buf), "WPS_PBC");
16684 else /* WFA_CS_WPS_PIN_KEYPAD */
16685 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
16686 dut->wps_pin);
16687 if (wpa_command(intf, buf) < 0) {
16688 send_resp(dut, conn, SIGMA_ERROR,
16689 "ErrorCode,Failed to start WPS");
vamsi krishna9b144002017-09-20 13:28:13 +053016690 goto fail;
16691 }
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020016692 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
16693 if (res < 0) {
16694 send_resp(dut, conn, SIGMA_ERROR,
16695 "ErrorCode,WPS connection did not complete");
16696 goto fail;
16697 }
16698 if (strstr(buf, "WPS-TIMEOUT")) {
16699 send_resp(dut, conn, SIGMA_COMPLETE, "WpsState,NoPeer");
16700 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
16701 send_resp(dut, conn, SIGMA_COMPLETE,
16702 "WpsState,OverlapSession");
16703 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
16704 send_resp(dut, conn, SIGMA_COMPLETE,
16705 "WpsState,Successful");
16706 } else {
16707 send_resp(dut, conn, SIGMA_COMPLETE,
16708 "WpsState,Failure");
16709 }
16710 } else {
16711 if (dut->wps_method == WFA_CS_WPS_PBC) {
vamsi krishna9b144002017-09-20 13:28:13 +053016712 if (wpa_command(intf, "WPS_PBC") < 0) {
16713 send_resp(dut, conn, SIGMA_ERROR,
16714 "ErrorCode,Failed to enable PBC");
16715 goto fail;
16716 }
16717 } else {
16718 /* TODO: PIN method */
16719 send_resp(dut, conn, SIGMA_ERROR,
16720 "ErrorCode,Unsupported WpsConfigMethod value");
16721 goto fail;
16722 }
16723 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
16724 if (res < 0) {
16725 send_resp(dut, conn, SIGMA_ERROR,
16726 "ErrorCode,WPS connection did not complete");
16727 goto fail;
16728 }
16729 if (strstr(buf, "WPS-TIMEOUT")) {
16730 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,NoPeer");
16731 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
16732 send_resp(dut, conn, SIGMA_ERROR,
16733 "ErrorCode,OverlapSession");
16734 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
16735 send_resp(dut, conn, SIGMA_COMPLETE, "Successful");
16736 } else {
16737 send_resp(dut, conn, SIGMA_ERROR,
16738 "ErrorCode,WPS operation failed");
16739 }
vamsi krishna9b144002017-09-20 13:28:13 +053016740 }
16741
16742fail:
16743 wpa_ctrl_detach(ctrl);
16744 wpa_ctrl_close(ctrl);
16745 return 0;
16746}
16747
16748
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016749static int req_intf(struct sigma_cmd *cmd)
16750{
16751 return get_param(cmd, "interface") == NULL ? -1 : 0;
16752}
16753
16754
16755void sta_register_cmds(void)
16756{
16757 sigma_dut_reg_cmd("sta_get_ip_config", req_intf,
16758 cmd_sta_get_ip_config);
16759 sigma_dut_reg_cmd("sta_set_ip_config", req_intf,
16760 cmd_sta_set_ip_config);
16761 sigma_dut_reg_cmd("sta_get_info", req_intf, cmd_sta_get_info);
16762 sigma_dut_reg_cmd("sta_get_mac_address", req_intf,
16763 cmd_sta_get_mac_address);
16764 sigma_dut_reg_cmd("sta_is_connected", req_intf, cmd_sta_is_connected);
16765 sigma_dut_reg_cmd("sta_verify_ip_connection", req_intf,
16766 cmd_sta_verify_ip_connection);
16767 sigma_dut_reg_cmd("sta_get_bssid", req_intf, cmd_sta_get_bssid);
16768 sigma_dut_reg_cmd("sta_set_encryption", req_intf,
16769 cmd_sta_set_encryption);
16770 sigma_dut_reg_cmd("sta_set_psk", req_intf, cmd_sta_set_psk);
16771 sigma_dut_reg_cmd("sta_set_eaptls", req_intf, cmd_sta_set_eaptls);
16772 sigma_dut_reg_cmd("sta_set_eapttls", req_intf, cmd_sta_set_eapttls);
16773 sigma_dut_reg_cmd("sta_set_eapsim", req_intf, cmd_sta_set_eapsim);
16774 sigma_dut_reg_cmd("sta_set_peap", req_intf, cmd_sta_set_peap);
16775 sigma_dut_reg_cmd("sta_set_eapfast", req_intf, cmd_sta_set_eapfast);
16776 sigma_dut_reg_cmd("sta_set_eapaka", req_intf, cmd_sta_set_eapaka);
16777 sigma_dut_reg_cmd("sta_set_eapakaprime", req_intf,
16778 cmd_sta_set_eapakaprime);
16779 sigma_dut_reg_cmd("sta_set_security", req_intf, cmd_sta_set_security);
16780 sigma_dut_reg_cmd("sta_set_uapsd", req_intf, cmd_sta_set_uapsd);
16781 /* TODO: sta_set_ibss */
16782 /* TODO: sta_set_mode */
16783 sigma_dut_reg_cmd("sta_set_wmm", req_intf, cmd_sta_set_wmm);
16784 sigma_dut_reg_cmd("sta_associate", req_intf, cmd_sta_associate);
16785 /* TODO: sta_up_load */
16786 sigma_dut_reg_cmd("sta_preset_testparameters", req_intf,
16787 cmd_sta_preset_testparameters);
16788 /* TODO: sta_set_system */
16789 sigma_dut_reg_cmd("sta_set_11n", req_intf, cmd_sta_set_11n);
16790 /* TODO: sta_set_rifs_test */
16791 sigma_dut_reg_cmd("sta_set_wireless", req_intf, cmd_sta_set_wireless);
16792 sigma_dut_reg_cmd("sta_send_addba", req_intf, cmd_sta_send_addba);
16793 /* TODO: sta_send_coexist_mgmt */
16794 sigma_dut_reg_cmd("sta_disconnect", req_intf, cmd_sta_disconnect);
16795 sigma_dut_reg_cmd("sta_reassoc", req_intf, cmd_sta_reassoc);
16796 sigma_dut_reg_cmd("sta_reassociate", req_intf, cmd_sta_reassoc);
16797 sigma_dut_reg_cmd("sta_reset_default", req_intf,
16798 cmd_sta_reset_default);
16799 sigma_dut_reg_cmd("sta_send_frame", req_intf, cmd_sta_send_frame);
16800 sigma_dut_reg_cmd("sta_set_macaddr", req_intf, cmd_sta_set_macaddr);
16801 sigma_dut_reg_cmd("sta_set_rfeature", req_intf, cmd_sta_set_rfeature);
16802 sigma_dut_reg_cmd("sta_set_radio", req_intf, cmd_sta_set_radio);
16803 sigma_dut_reg_cmd("sta_set_pwrsave", req_intf, cmd_sta_set_pwrsave);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020016804 sigma_dut_reg_cmd("sta_set_power_save", req_intf, cmd_sta_set_pwrsave);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016805 sigma_dut_reg_cmd("sta_bssid_pool", req_intf, cmd_sta_bssid_pool);
16806 sigma_dut_reg_cmd("sta_reset_parm", req_intf, cmd_sta_reset_parm);
16807 sigma_dut_reg_cmd("sta_get_key", req_intf, cmd_sta_get_key);
16808 sigma_dut_reg_cmd("sta_hs2_associate", req_intf,
16809 cmd_sta_hs2_associate);
Jouni Malinenb639f1c2018-09-13 02:39:46 +030016810 sigma_dut_reg_cmd("sta_hs2_venue_info", req_intf,
16811 cmd_sta_hs2_venue_info);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016812 sigma_dut_reg_cmd("sta_add_credential", req_intf,
16813 cmd_sta_add_credential);
16814 sigma_dut_reg_cmd("sta_scan", req_intf, cmd_sta_scan);
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020016815 sigma_dut_reg_cmd("sta_scan_bss", req_intf, cmd_sta_scan_bss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016816 sigma_dut_reg_cmd("sta_set_systime", NULL, cmd_sta_set_systime);
16817 sigma_dut_reg_cmd("sta_osu", req_intf, cmd_sta_osu);
16818 sigma_dut_reg_cmd("sta_policy_update", req_intf, cmd_sta_policy_update);
16819 sigma_dut_reg_cmd("sta_er_config", NULL, cmd_sta_er_config);
16820 sigma_dut_reg_cmd("sta_wps_connect_pw_token", req_intf,
16821 cmd_sta_wps_connect_pw_token);
Jouni Malinen82905202018-04-29 17:20:10 +030016822 sigma_dut_reg_cmd("sta_exec_action", NULL, cmd_sta_exec_action);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016823 sigma_dut_reg_cmd("sta_get_events", req_intf, cmd_sta_get_events);
16824 sigma_dut_reg_cmd("sta_get_parameter", req_intf, cmd_sta_get_parameter);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020016825 sigma_dut_reg_cmd("start_wps_registration", NULL,
vamsi krishna9b144002017-09-20 13:28:13 +053016826 cmd_start_wps_registration);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016827}