blob: 75e580dd0f624cc9b8d856ae505943f31818df44 [file] [log] [blame]
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001/*
2 * Sigma Control API DUT (station/AP)
3 * Copyright (c) 2010-2011, Atheros Communications, Inc.
Jouni Malinen9d7e31d2017-12-22 18:55:04 +02004 * Copyright (c) 2011-2017, Qualcomm Atheros, Inc.
Jouni Malinenc12ea4a2018-01-05 21:07:10 +02005 * Copyright (c) 2018, The Linux Foundation
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006 * All Rights Reserved.
7 * Licensed under the Clear BSD license. See README for more details.
8 */
9
10#include "sigma_dut.h"
11#include <sys/ioctl.h>
12#include <sys/stat.h>
Jouni Malinen82905202018-04-29 17:20:10 +030013#include <sys/wait.h>
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030014#include <ctype.h>
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015#ifdef __linux__
Lior Davidcc88b562017-01-03 18:52:09 +020016#include <regex.h>
17#include <dirent.h>
Jouni Malinencd4e3c32015-10-29 12:39:56 +020018#include <sys/time.h>
19#include <netpacket/packet.h>
20#include <linux/if_ether.h>
21#ifdef ANDROID
22#include <cutils/properties.h>
23#include <android/log.h>
24#include "keystore_get.h"
25#else /* ANDROID */
26#include <ifaddrs.h>
27#endif /* ANDROID */
28#include <netdb.h>
29#endif /* __linux__ */
30#ifdef __QNXNTO__
31#include <net/if_dl.h>
32#endif /* __QNXNTO__ */
33#include "wpa_ctrl.h"
34#include "wpa_helpers.h"
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -070035#include "miracast.h"
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -070036#include "qca-vendor_copy.h"
Jouni Malinencd4e3c32015-10-29 12:39:56 +020037
38/* Temporary files for sta_send_addba */
39#define VI_QOS_TMP_FILE "/tmp/vi-qos.tmp"
40#define VI_QOS_FILE "/tmp/vi-qos.txt"
41#define VI_QOS_REFFILE "/etc/vi-qos.txt"
42
43/*
44 * MTU for Ethernet need to take into account 8-byte SNAP header
45 * to be added when encapsulating Ethernet frame into 802.11
46 */
47#ifndef IEEE80211_MAX_DATA_LEN_DMG
48#define IEEE80211_MAX_DATA_LEN_DMG 7920
49#endif
50#ifndef IEEE80211_SNAP_LEN_DMG
51#define IEEE80211_SNAP_LEN_DMG 8
52#endif
53
Ashwini Patil00402582017-04-13 12:29:39 +053054#define NON_PREF_CH_LIST_SIZE 100
Ashwini Patil5acd7382017-04-13 15:55:04 +053055#define NEIGHBOR_REPORT_SIZE 1000
56#define DEFAULT_NEIGHBOR_BSSID_INFO "17"
57#define DEFAULT_NEIGHBOR_PHY_TYPE "1"
Ashwini Patil00402582017-04-13 12:29:39 +053058
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030059#define WIL_DEFAULT_BI 100
60
61/* default remain on channel time for transmitting frames (milliseconds) */
62#define WIL_TRANSMIT_FRAME_DEFAULT_ROC 500
63#define IEEE80211_P2P_ATTR_DEVICE_ID 3
64#define IEEE80211_P2P_ATTR_GROUP_ID 15
65
66/* describes tagged bytes in template frame file */
67struct template_frame_tag {
68 int num;
69 int offset;
70 size_t len;
71};
72
Jouni Malinencd4e3c32015-10-29 12:39:56 +020073extern char *sigma_wpas_ctrl;
74extern char *sigma_cert_path;
75extern enum driver_type wifi_chip_type;
76extern char *sigma_radio_ifname[];
77
Lior David0fe101e2017-03-09 16:09:50 +020078#ifdef __linux__
79#define WIL_WMI_MAX_PAYLOAD 248
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020080#define WIL_WMI_ESE_CFG_CMDID 0xa01
Lior David0fe101e2017-03-09 16:09:50 +020081#define WIL_WMI_BF_TRIG_CMDID 0x83a
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020082#define WIL_WMI_UNIT_TEST_CMDID 0x900
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030083#define WIL_WMI_P2P_CFG_CMDID 0x910
84#define WIL_WMI_START_LISTEN_CMDID 0x914
85#define WIL_WMI_DISCOVERY_STOP_CMDID 0x917
Lior David0fe101e2017-03-09 16:09:50 +020086
87struct wil_wmi_header {
88 uint8_t mid;
89 uint8_t reserved;
90 uint16_t cmd;
91 uint32_t ts;
92} __attribute__((packed));
93
94enum wil_wmi_bf_trig_type {
95 WIL_WMI_SLS,
96 WIL_WMI_BRP_RX,
97 WIL_WMI_BRP_TX,
98};
99
100struct wil_wmi_bf_trig_cmd {
101 /* enum wil_wmi_bf_trig_type */
102 uint32_t bf_type;
103 /* cid when type == WMI_BRP_RX */
104 uint32_t sta_id;
105 uint32_t reserved;
106 /* mac address when type = WIL_WMI_SLS */
107 uint8_t dest_mac[6];
108} __attribute__((packed));
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +0200109
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +0200110enum wil_wmi_sched_scheme_advertisment {
111 WIL_WMI_ADVERTISE_ESE_DISABLED,
112 WIL_WMI_ADVERTISE_ESE_IN_BEACON,
113 WIL_WMI_ADVERTISE_ESE_IN_ANNOUNCE_FRAME,
114};
115
116enum wil_wmi_ese_slot_type {
117 WIL_WMI_ESE_SP,
118 WIL_WMI_ESE_CBAP,
119 WIL_WMI_ESE_ANNOUNCE_NO_ACK,
120};
121
122struct wil_wmi_ese_slot {
123 /* offset from start of BI in microseconds */
124 uint32_t tbtt_offset;
125 uint8_t flags;
126 /* enum wil_wmi_ese_slot_type */
127 uint8_t slot_type;
128 /* duration in microseconds */
129 uint16_t duration;
130 /* frame exchange sequence duration, microseconds */
131 uint16_t tx_op;
132 /* time between 2 blocks for periodic allocation(microseconds) */
133 uint16_t period;
134 /* number of blocks in periodic allocation */
135 uint8_t num_blocks;
136 /* for semi-active allocations */
137 uint8_t idle_period;
138 uint8_t src_aid;
139 uint8_t dst_aid;
140 uint32_t reserved;
141} __attribute__((packed));
142
143#define WIL_WMI_MAX_ESE_SLOTS 4
144struct wil_wmi_ese_cfg {
145 uint8_t serial_num;
146 /* wil_wmi_sched_scheme_advertisment */
147 uint8_t ese_advertisment;
148 uint16_t flags;
149 uint8_t num_allocs;
150 uint8_t reserved[3];
151 uint64_t start_tbtt;
152 /* allocations list */
153 struct wil_wmi_ese_slot slots[WIL_WMI_MAX_ESE_SLOTS];
154} __attribute__((packed));
155
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +0200156#define WIL_WMI_UT_FORCE_MCS 6
157struct wil_wmi_force_mcs {
158 /* WIL_WMI_UT_HW_SYSAPI */
159 uint16_t module_id;
160 /* WIL_WMI_UT_FORCE_MCS */
161 uint16_t subtype_id;
162 /* cid (ignored in oob_mode, affects all stations) */
163 uint32_t cid;
164 /* 1 to force MCS, 0 to restore default behavior */
165 uint32_t force_enable;
166 /* MCS index, 0-12 */
167 uint32_t mcs;
168} __attribute__((packed));
169
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +0200170#define WIL_WMI_UT_HW_SYSAPI 10
171#define WIL_WMI_UT_FORCE_RSN_IE 0x29
172struct wil_wmi_force_rsn_ie {
173 /* WIL_WMI_UT_HW_SYSAPI */
174 uint16_t module_id;
175 /* WIL_WMI_UT_FORCE_RSN_IE */
176 uint16_t subtype_id;
177 /* 0 = no change, 1 = remove if exists, 2 = add if does not exist */
178 uint32_t state;
179} __attribute__((packed));
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +0300180
181enum wil_wmi_discovery_mode {
182 WMI_DISCOVERY_MODE_NON_OFFLOAD,
183 WMI_DISCOVERY_MODE_OFFLOAD,
184 WMI_DISCOVERY_MODE_PEER2PEER,
185};
186
187struct wil_wmi_p2p_cfg_cmd {
188 /* enum wil_wmi_discovery_mode */
189 uint8_t discovery_mode;
190 /* 0-based (wireless channel - 1) */
191 uint8_t channel;
192 /* set to WIL_DEFAULT_BI */
193 uint16_t bcon_interval;
194} __attribute__((packed));
Lior David0fe101e2017-03-09 16:09:50 +0200195#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200196
197#ifdef ANDROID
198
199static int add_ipv6_rule(struct sigma_dut *dut, const char *ifname);
200
201#define ANDROID_KEYSTORE_GET 'g'
202#define ANDROID_KEYSTORE_GET_PUBKEY 'b'
203
204static int android_keystore_get(char cmd, const char *key, unsigned char *val)
205{
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200206 /* Android 4.3 changed keystore design, so need to use keystore_get() */
207#ifndef KEYSTORE_MESSAGE_SIZE
208#define KEYSTORE_MESSAGE_SIZE 65535
209#endif /* KEYSTORE_MESSAGE_SIZE */
210
211 ssize_t len;
212 uint8_t *value = NULL;
213
214 __android_log_print(ANDROID_LOG_DEBUG, "sigma_dut",
215 "keystore command '%c' key '%s' --> keystore_get",
216 cmd, key);
217
218 len = keystore_get(key, strlen(key), &value);
219 if (len < 0) {
220 __android_log_print(ANDROID_LOG_DEBUG, "sigma_dut",
221 "keystore_get() failed");
222 return -1;
223 }
224
225 if (len > KEYSTORE_MESSAGE_SIZE)
226 len = KEYSTORE_MESSAGE_SIZE;
227 memcpy(val, value, len);
228 free(value);
229 return len;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200230}
231#endif /* ANDROID */
232
233
Vinita S. Maloo0fcb57d2020-04-24 14:03:56 +0530234#ifdef NL80211_SUPPORT
235static int nl80211_sta_set_power_save(struct sigma_dut *dut,
236 const char *intf,
237 enum nl80211_ps_state ps_state)
238{
239 struct nl_msg *msg;
240 int ifindex, ret;
241
242 ifindex = if_nametoindex(intf);
243 if (ifindex == 0) {
244 sigma_dut_print(dut, DUT_MSG_ERROR,
245 "%s: Index for interface %s not found",
246 __func__, intf);
247 return -1;
248 }
249
250 msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
251 NL80211_CMD_SET_POWER_SAVE);
252 if (!msg) {
253 sigma_dut_print(dut, DUT_MSG_ERROR,
254 "%s: err in creating nl80211 msg", __func__);
255 return -1;
256 }
257
258 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) {
259 sigma_dut_print(dut, DUT_MSG_ERROR,
260 "%s: err in populating nl80211 msg", __func__);
261 nlmsg_free(msg);
262 return -1;
263 }
264
265 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
266 if (ret) {
267 sigma_dut_print(dut, DUT_MSG_ERROR,
268 "%s: err in send_and_recv_msgs, ret=%d (%s)",
269 __func__, ret, strerror(-ret));
270 return -1;
271 }
272
273 return 0;
274}
275#endif /* NL80211_SUPPORT */
276
277
Vinita S. Malooa8b62722020-04-23 01:45:41 +0530278static int set_power_save_wcn(struct sigma_dut *dut, const char *intf, int ps)
279{
280 char buf[100];
Vinita S. Maloo0fcb57d2020-04-24 14:03:56 +0530281#ifdef NL80211_SUPPORT
282 enum nl80211_ps_state ps_state;
283
284 ps_state = ps == 1 ? NL80211_PS_ENABLED : NL80211_PS_DISABLED;
285 if (nl80211_sta_set_power_save(dut, intf, ps_state) == 0)
286 return 0;
287#endif /* NL80211_SUPPORT */
Vinita S. Malooa8b62722020-04-23 01:45:41 +0530288
289 snprintf(buf, sizeof(buf), "iwpriv %s setPower %d", intf, ps);
290 if (system(buf) != 0) {
291 sigma_dut_print(dut, DUT_MSG_ERROR,
292 "iwpriv setPower %d failed", ps);
293 return -1;
294 }
295 return 0;
296}
297
298
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200299int set_ps(const char *intf, struct sigma_dut *dut, int enabled)
300{
301#ifdef __linux__
302 char buf[100];
303
304 if (wifi_chip_type == DRIVER_WCN) {
305 if (enabled) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +0530306 if (set_power_save_wcn(dut, intf, 1) < 0) {
Purushottam Kushwaha304561d2019-12-23 16:57:18 +0530307 snprintf(buf, sizeof(buf),
308 "iwpriv wlan0 dump 906");
309 if (system(buf) != 0)
310 goto set_power_save;
311 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200312 } else {
Vinita S. Malooa8b62722020-04-23 01:45:41 +0530313 if (set_power_save_wcn(dut, intf, 2) < 0) {
Purushottam Kushwaha304561d2019-12-23 16:57:18 +0530314 snprintf(buf, sizeof(buf),
315 "iwpriv wlan0 dump 905");
316 if (system(buf) != 0)
317 goto set_power_save;
318 snprintf(buf, sizeof(buf),
319 "iwpriv wlan0 dump 912");
320 if (system(buf) != 0)
321 goto set_power_save;
322 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200323 }
324
325 return 0;
326 }
327
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530328set_power_save:
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200329 snprintf(buf, sizeof(buf), "./iw dev %s set power_save %s",
330 intf, enabled ? "on" : "off");
331 if (system(buf) != 0) {
332 snprintf(buf, sizeof(buf), "iw dev %s set power_save %s",
333 intf, enabled ? "on" : "off");
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530334 if (system(buf) != 0) {
335 sigma_dut_print(dut, DUT_MSG_ERROR,
336 "Failed to set power save %s",
337 enabled ? "on" : "off");
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200338 return -1;
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530339 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200340 }
341
342 return 0;
343#else /* __linux__ */
344 return -1;
345#endif /* __linux__ */
346}
347
348
Lior Davidcc88b562017-01-03 18:52:09 +0200349#ifdef __linux__
Lior David0fe101e2017-03-09 16:09:50 +0200350
Lior Davidcc88b562017-01-03 18:52:09 +0200351static int wil6210_get_debugfs_dir(struct sigma_dut *dut, char *path,
352 size_t len)
353{
354 DIR *dir, *wil_dir;
355 struct dirent *entry;
356 int ret = -1;
357 const char *root_path = "/sys/kernel/debug/ieee80211";
358
359 dir = opendir(root_path);
360 if (!dir)
361 return -2;
362
363 while ((entry = readdir(dir))) {
364 if (strcmp(entry->d_name, ".") == 0 ||
365 strcmp(entry->d_name, "..") == 0)
366 continue;
367
368 if (snprintf(path, len, "%s/%s/wil6210",
369 root_path, entry->d_name) >= (int) len) {
370 ret = -3;
371 break;
372 }
373
374 wil_dir = opendir(path);
375 if (wil_dir) {
376 closedir(wil_dir);
377 ret = 0;
378 break;
379 }
380 }
381
382 closedir(dir);
383 return ret;
384}
Lior David0fe101e2017-03-09 16:09:50 +0200385
386
387static int wil6210_wmi_send(struct sigma_dut *dut, uint16_t command,
388 void *payload, uint16_t length)
389{
390 struct {
391 struct wil_wmi_header hdr;
392 char payload[WIL_WMI_MAX_PAYLOAD];
393 } __attribute__((packed)) cmd;
394 char buf[128], fname[128];
395 size_t towrite, written;
396 FILE *f;
Jouni Malinen3aa72862019-05-29 23:14:51 +0300397 int res;
Lior David0fe101e2017-03-09 16:09:50 +0200398
399 if (length > WIL_WMI_MAX_PAYLOAD) {
400 sigma_dut_print(dut, DUT_MSG_ERROR,
401 "payload too large(%u, max %u)",
402 length, WIL_WMI_MAX_PAYLOAD);
403 return -1;
404 }
405
406 memset(&cmd.hdr, 0, sizeof(cmd.hdr));
407 cmd.hdr.cmd = command;
408 memcpy(cmd.payload, payload, length);
409
410 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
411 sigma_dut_print(dut, DUT_MSG_ERROR,
412 "failed to get wil6210 debugfs dir");
413 return -1;
414 }
415
Jouni Malinen3aa72862019-05-29 23:14:51 +0300416 res = snprintf(fname, sizeof(fname), "%s/wmi_send", buf);
417 if (res < 0 || res >= sizeof(fname))
418 return -1;
Lior David0fe101e2017-03-09 16:09:50 +0200419 f = fopen(fname, "wb");
420 if (!f) {
421 sigma_dut_print(dut, DUT_MSG_ERROR,
422 "failed to open: %s", fname);
423 return -1;
424 }
425
426 towrite = sizeof(cmd.hdr) + length;
427 written = fwrite(&cmd, 1, towrite, f);
428 fclose(f);
429 if (written != towrite) {
430 sigma_dut_print(dut, DUT_MSG_ERROR,
431 "failed to send wmi %u", command);
432 return -1;
433 }
434
435 return 0;
436}
437
438
439static int wil6210_get_sta_info_field(struct sigma_dut *dut, const char *bssid,
440 const char *pattern, unsigned int *field)
441{
442 char buf[128], fname[128];
443 FILE *f;
444 regex_t re;
445 regmatch_t m[2];
Jouni Malinen3aa72862019-05-29 23:14:51 +0300446 int rc, ret = -1, res;
Lior David0fe101e2017-03-09 16:09:50 +0200447
448 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
449 sigma_dut_print(dut, DUT_MSG_ERROR,
450 "failed to get wil6210 debugfs dir");
451 return -1;
452 }
453
Jouni Malinen3aa72862019-05-29 23:14:51 +0300454 res = snprintf(fname, sizeof(fname), "%s/stations", buf);
455 if (res < 0 || res >= sizeof(fname))
456 return -1;
Lior David0fe101e2017-03-09 16:09:50 +0200457 f = fopen(fname, "r");
458 if (!f) {
459 sigma_dut_print(dut, DUT_MSG_ERROR,
460 "failed to open: %s", fname);
461 return -1;
462 }
463
464 if (regcomp(&re, pattern, REG_EXTENDED)) {
465 sigma_dut_print(dut, DUT_MSG_ERROR,
466 "regcomp failed: %s", pattern);
467 goto out;
468 }
469
470 /*
471 * find the entry for the mac address
472 * line is of the form: [n] 11:22:33:44:55:66 state AID aid
473 */
474 while (fgets(buf, sizeof(buf), f)) {
475 if (strcasestr(buf, bssid)) {
476 /* extract the field (CID/AID/state) */
477 rc = regexec(&re, buf, 2, m, 0);
478 if (!rc && (m[1].rm_so >= 0)) {
479 buf[m[1].rm_eo] = 0;
480 *field = atoi(&buf[m[1].rm_so]);
481 ret = 0;
482 break;
483 }
484 }
485 }
486
487 regfree(&re);
488 if (ret)
489 sigma_dut_print(dut, DUT_MSG_ERROR,
490 "could not extract field");
491
492out:
493 fclose(f);
494
495 return ret;
496}
497
498
499static int wil6210_get_cid(struct sigma_dut *dut, const char *bssid,
500 unsigned int *cid)
501{
502 const char *pattern = "\\[([0-9]+)\\]";
503
504 return wil6210_get_sta_info_field(dut, bssid, pattern, cid);
505}
506
507
508static int wil6210_send_brp_rx(struct sigma_dut *dut, const char *mac,
509 int l_rx)
510{
Rakesh Sunki556237d2017-03-30 14:49:31 -0700511 struct wil_wmi_bf_trig_cmd cmd;
Lior David0fe101e2017-03-09 16:09:50 +0200512 unsigned int cid;
513
Rakesh Sunki556237d2017-03-30 14:49:31 -0700514 memset(&cmd, 0, sizeof(cmd));
515
Lior David0fe101e2017-03-09 16:09:50 +0200516 if (wil6210_get_cid(dut, mac, &cid))
517 return -1;
518
519 cmd.bf_type = WIL_WMI_BRP_RX;
520 cmd.sta_id = cid;
521 /* training length (l_rx) is ignored, FW always uses length 16 */
522 return wil6210_wmi_send(dut, WIL_WMI_BF_TRIG_CMDID,
523 &cmd, sizeof(cmd));
524}
525
526
527static int wil6210_send_sls(struct sigma_dut *dut, const char *mac)
528{
Rakesh Sunki556237d2017-03-30 14:49:31 -0700529 struct wil_wmi_bf_trig_cmd cmd;
530
531 memset(&cmd, 0, sizeof(cmd));
Lior David0fe101e2017-03-09 16:09:50 +0200532
533 if (parse_mac_address(dut, mac, (unsigned char *)&cmd.dest_mac))
534 return -1;
535
536 cmd.bf_type = WIL_WMI_SLS;
537 return wil6210_wmi_send(dut, WIL_WMI_BF_TRIG_CMDID,
538 &cmd, sizeof(cmd));
539}
540
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +0200541
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +0200542int wil6210_set_ese(struct sigma_dut *dut, int count,
543 struct sigma_ese_alloc *allocs)
544{
545 struct wil_wmi_ese_cfg cmd = { };
546 int i;
547
548 if (count == 0 || count > WIL_WMI_MAX_ESE_SLOTS)
549 return -1;
550
551 if (dut->ap_bcnint <= 0) {
552 sigma_dut_print(dut, DUT_MSG_ERROR,
553 "invalid beacon interval(%d), check test",
554 dut->ap_bcnint);
555 return -1;
556 }
557
558 cmd.ese_advertisment = WIL_WMI_ADVERTISE_ESE_IN_BEACON;
559 cmd.flags = 0x1d;
560 cmd.num_allocs = count;
561 for (i = 0; i < count; i++) {
562 /*
563 * Convert percent from BI (BI specified in milliseconds)
564 * to absolute duration in microseconds.
565 */
566 cmd.slots[i].duration =
567 (allocs[i].percent_bi * dut->ap_bcnint * 1000) / 100;
568 switch (allocs[i].type) {
569 case ESE_CBAP:
570 cmd.slots[i].slot_type = WIL_WMI_ESE_CBAP;
571 break;
572 case ESE_SP:
573 cmd.slots[i].slot_type = WIL_WMI_ESE_SP;
574 break;
575 default:
576 sigma_dut_print(dut, DUT_MSG_ERROR,
577 "invalid slot type(%d) at index %d",
578 allocs[i].type, i);
579 return -1;
580 }
581 cmd.slots[i].src_aid = allocs[i].src_aid;
582 cmd.slots[i].dst_aid = allocs[i].dst_aid;
583 sigma_dut_print(dut, DUT_MSG_INFO,
584 "slot %d, duration %u, type %d, srcAID %u dstAID %u",
585 i, cmd.slots[i].duration,
586 cmd.slots[i].slot_type, cmd.slots[i].src_aid,
587 cmd.slots[i].dst_aid);
588 }
589
590 return wil6210_wmi_send(dut, WIL_WMI_ESE_CFG_CMDID, &cmd, sizeof(cmd));
591}
592
593
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +0200594int wil6210_set_force_mcs(struct sigma_dut *dut, int force, int mcs)
595{
596 struct wil_wmi_force_mcs cmd = { };
597
598 cmd.module_id = WIL_WMI_UT_HW_SYSAPI;
599 cmd.subtype_id = WIL_WMI_UT_FORCE_MCS;
600 cmd.force_enable = (uint32_t) force;
601 cmd.mcs = (uint32_t) mcs;
602
603 return wil6210_wmi_send(dut, WIL_WMI_UNIT_TEST_CMDID,
604 &cmd, sizeof(cmd));
605}
606
607
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +0200608static int wil6210_force_rsn_ie(struct sigma_dut *dut, int state)
609{
610 struct wil_wmi_force_rsn_ie cmd = { };
611
612 cmd.module_id = WIL_WMI_UT_HW_SYSAPI;
613 cmd.subtype_id = WIL_WMI_UT_FORCE_RSN_IE;
614 cmd.state = (uint32_t) state;
615
616 return wil6210_wmi_send(dut, WIL_WMI_UNIT_TEST_CMDID,
617 &cmd, sizeof(cmd));
618}
619
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +0300620
621/*
622 * this function is also used to configure generic remain-on-channel
623 */
624static int wil6210_p2p_cfg(struct sigma_dut *dut, int freq)
625{
626 struct wil_wmi_p2p_cfg_cmd cmd = { };
627 int channel = freq_to_channel(freq);
628
629 if (channel < 0)
630 return -1;
631 cmd.discovery_mode = WMI_DISCOVERY_MODE_NON_OFFLOAD;
632 cmd.channel = channel - 1;
633 cmd.bcon_interval = WIL_DEFAULT_BI;
634 cmd.discovery_mode = WMI_DISCOVERY_MODE_PEER2PEER;
635
636 return wil6210_wmi_send(dut, WIL_WMI_P2P_CFG_CMDID,
637 &cmd, sizeof(cmd));
638}
639
640
641static int wil6210_remain_on_channel(struct sigma_dut *dut, int freq)
642{
643 int ret = wil6210_p2p_cfg(dut, freq);
644
645 if (ret)
646 return ret;
647
648 ret = wil6210_wmi_send(dut, WIL_WMI_START_LISTEN_CMDID, NULL, 0);
649 if (!ret) {
650 /*
651 * wait a bit to allow FW to setup the radio
652 * especially important if we switch channels
653 */
654 usleep(500000);
655 }
656
657 return ret;
658}
659
660
661static int wil6210_stop_discovery(struct sigma_dut *dut)
662{
663 return wil6210_wmi_send(dut, WIL_WMI_DISCOVERY_STOP_CMDID, NULL, 0);
664}
665
666
667static int wil6210_transmit_frame(struct sigma_dut *dut, int freq,
668 int wait_duration,
669 const char *frame, size_t frame_len)
670{
671 char buf[128], fname[128];
672 FILE *f;
Jouni Malinen3aa72862019-05-29 23:14:51 +0300673 int res = 0, r;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +0300674 size_t written;
675
676 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
677 sigma_dut_print(dut, DUT_MSG_ERROR,
678 "failed to get wil6210 debugfs dir");
679 return -1;
680 }
Jouni Malinen3aa72862019-05-29 23:14:51 +0300681 r = snprintf(fname, sizeof(fname), "%s/tx_mgmt", buf);
682 if (r < 0 || r >= sizeof(fname))
683 return -1;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +0300684
685 if (wil6210_remain_on_channel(dut, freq)) {
686 sigma_dut_print(dut, DUT_MSG_ERROR,
687 "failed to listen on channel");
688 return -1;
689 }
690
691 f = fopen(fname, "wb");
692 if (!f) {
693 sigma_dut_print(dut, DUT_MSG_ERROR,
694 "failed to open: %s", fname);
695 res = -1;
696 goto out_stop;
697 }
698 written = fwrite(frame, 1, frame_len, f);
699 fclose(f);
700
701 if (written != frame_len) {
702 sigma_dut_print(dut, DUT_MSG_ERROR,
703 "failed to transmit frame (got %zd, expected %zd)",
704 written, frame_len);
705 res = -1;
706 goto out_stop;
707 }
708
709 usleep(wait_duration * 1000);
710
711out_stop:
712 wil6210_stop_discovery(dut);
713 return res;
714}
715
716
717static int find_template_frame_tag(struct template_frame_tag *tags,
718 int total_tags, int tag_num)
719{
720 int i;
721
722 for (i = 0; i < total_tags; i++) {
723 if (tag_num == tags[i].num)
724 return i;
725 }
726
727 return -1;
728}
729
730
731static int replace_p2p_attribute(struct sigma_dut *dut, char *buf, size_t len,
732 int id, const char *value, size_t val_len)
733{
734 struct wfa_p2p_attribute *attr = (struct wfa_p2p_attribute *) buf;
735
736 if (len < 3 + val_len) {
737 sigma_dut_print(dut, DUT_MSG_ERROR,
738 "not enough space to replace P2P attribute");
739 return -1;
740 }
741
742 if (attr->len != val_len) {
743 sigma_dut_print(dut, DUT_MSG_ERROR,
744 "attribute length mismatch (need %zu have %hu)",
745 val_len, attr->len);
746 return -1;
747 }
748
749 if (attr->id != id) {
750 sigma_dut_print(dut, DUT_MSG_ERROR,
751 "incorrect attribute id (expected %d actual %d)",
752 id, attr->id);
753 return -1;
754 }
755
756 memcpy(attr->variable, value, val_len);
757
758 return 0;
759}
760
761
762static int parse_template_frame_file(struct sigma_dut *dut, const char *fname,
763 char *buf, size_t *length,
764 struct template_frame_tag *tags,
765 size_t *num_tags)
766{
767 char line[512];
768 FILE *f;
769 size_t offset = 0, tag_index = 0;
770 int num, index;
771 int in_tag = 0, tag_num = 0, tag_offset = 0;
772
773 if (*length < sizeof(struct ieee80211_hdr_3addr)) {
774 sigma_dut_print(dut, DUT_MSG_ERROR,
775 "supplied buffer is too small");
776 return -1;
777 }
778
779 f = fopen(fname, "r");
780 if (!f) {
781 sigma_dut_print(dut, DUT_MSG_ERROR,
782 "failed to open template file %s", fname);
783 return -1;
784 }
785
786 /*
787 * template file format: lines beginning with # are comments and
788 * ignored.
789 * It is possible to tag bytes in the frame to make it easy
790 * to replace fields in the template, espcially if they appear
791 * in variable-sized sections (such as IEs)
792 * This is done by a line beginning with $NUM where NUM is an integer
793 * tag number. It can be followed by space(s) and comment.
794 * The next line is considered the tagged bytes. The parser will fill
795 * the tag number, offset and length of the tagged bytes.
796 * rest of the lines contain frame bytes as sequence of hex digits,
797 * 2 digits for each byte. Spaces are allowed between bytes.
798 * On bytes lines only hex digits and spaces are allowed
799 */
800 while (!feof(f)) {
801 if (!fgets(line, sizeof(line), f))
802 break;
803 index = 0;
804 while (isspace((unsigned char) line[index]))
805 index++;
806 if (!line[index] || line[index] == '#')
807 continue;
808 if (line[index] == '$') {
809 if (tags) {
810 index++;
811 tag_num = strtol(&line[index], NULL, 0);
812 tag_offset = offset;
813 in_tag = 1;
814 }
815 continue;
816 }
817 while (line[index]) {
818 if (isspace((unsigned char) line[index])) {
819 index++;
820 continue;
821 }
822 num = hex_byte(&line[index]);
823 if (num < 0)
824 break;
825 buf[offset++] = num;
826 if (offset == *length)
827 goto out;
828 index += 2;
829 }
830
831 if (in_tag) {
832 if (tag_index < *num_tags) {
833 tags[tag_index].num = tag_num;
834 tags[tag_index].offset = tag_offset;
835 tags[tag_index].len = offset - tag_offset;
836 tag_index++;
837 } else {
838 sigma_dut_print(dut, DUT_MSG_INFO,
839 "too many tags, tag ignored");
840 }
841 in_tag = 0;
842 }
843 }
844
845 if (num_tags)
846 *num_tags = tag_index;
847out:
848 fclose(f);
849 if (offset < sizeof(struct ieee80211_hdr_3addr)) {
850 sigma_dut_print(dut, DUT_MSG_ERROR,
851 "template frame is too small");
852 return -1;
853 }
854
855 *length = offset;
856 return 0;
857}
858
Lior Davidcc88b562017-01-03 18:52:09 +0200859#endif /* __linux__ */
860
861
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200862static void static_ip_file(int proto, const char *addr, const char *mask,
863 const char *gw)
864{
865 if (proto) {
866 FILE *f = fopen("static-ip", "w");
867 if (f) {
868 fprintf(f, "%d %s %s %s\n", proto, addr,
869 mask ? mask : "N/A",
870 gw ? gw : "N/A");
871 fclose(f);
872 }
873 } else {
874 unlink("static-ip");
875 }
876}
877
878
879static int send_neighbor_request(struct sigma_dut *dut, const char *intf,
880 const char *ssid)
881{
882#ifdef __linux__
883 char buf[100];
884
885 snprintf(buf, sizeof(buf), "iwpriv %s neighbor %s",
886 intf, ssid);
887 sigma_dut_print(dut, DUT_MSG_INFO, "Request: %s", buf);
888
889 if (system(buf) != 0) {
890 sigma_dut_print(dut, DUT_MSG_ERROR,
891 "iwpriv neighbor request failed");
892 return -1;
893 }
894
895 sigma_dut_print(dut, DUT_MSG_INFO, "iwpriv neighbor request send");
896
897 return 0;
898#else /* __linux__ */
899 return -1;
900#endif /* __linux__ */
901}
902
903
904static int send_trans_mgmt_query(struct sigma_dut *dut, const char *intf,
Ashwini Patil5acd7382017-04-13 15:55:04 +0530905 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200906{
Ashwini Patil5acd7382017-04-13 15:55:04 +0530907 const char *val;
908 int reason_code = 0;
909 char buf[1024];
910
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200911 /*
912 * In the earlier builds we used WNM_QUERY and in later
913 * builds used WNM_BSS_QUERY.
914 */
915
Ashwini Patil5acd7382017-04-13 15:55:04 +0530916 val = get_param(cmd, "BTMQuery_Reason_Code");
917 if (val)
918 reason_code = atoi(val);
919
920 val = get_param(cmd, "Cand_List");
921 if (val && atoi(val) == 1 && dut->btm_query_cand_list) {
922 snprintf(buf, sizeof(buf), "WNM_BSS_QUERY %d%s", reason_code,
923 dut->btm_query_cand_list);
924 free(dut->btm_query_cand_list);
925 dut->btm_query_cand_list = NULL;
926 } else {
927 snprintf(buf, sizeof(buf), "WNM_BSS_QUERY %d", reason_code);
928 }
929
930 if (wpa_command(intf, buf) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200931 sigma_dut_print(dut, DUT_MSG_ERROR,
932 "transition management query failed");
933 return -1;
934 }
935
936 sigma_dut_print(dut, DUT_MSG_DEBUG,
937 "transition management query sent");
938
939 return 0;
940}
941
942
943int is_ip_addr(const char *str)
944{
945 const char *pos = str;
946 struct in_addr addr;
947
948 while (*pos) {
949 if (*pos != '.' && (*pos < '0' || *pos > '9'))
950 return 0;
951 pos++;
952 }
953
954 return inet_aton(str, &addr);
955}
956
957
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200958int get_ip_config(struct sigma_dut *dut, const char *ifname, char *buf,
959 size_t buf_len)
960{
vamsi krishnaa11d0732018-05-16 12:19:48 +0530961 char tmp[256];
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200962 char ip[16], mask[15], dns[16], sec_dns[16];
963 int is_dhcp = 0;
964 int s;
965#ifdef ANDROID
966 char prop[PROPERTY_VALUE_MAX];
vamsi krishnaa11d0732018-05-16 12:19:48 +0530967#else /* ANDROID */
968 FILE *f;
969#ifdef __linux__
970 const char *str_ps;
971#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200972#endif /* ANDROID */
973
974 ip[0] = '\0';
975 mask[0] = '\0';
976 dns[0] = '\0';
977 sec_dns[0] = '\0';
978
979 s = socket(PF_INET, SOCK_DGRAM, 0);
980 if (s >= 0) {
981 struct ifreq ifr;
982 struct sockaddr_in saddr;
983
984 memset(&ifr, 0, sizeof(ifr));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700985 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200986 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
987 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get "
988 "%s IP address: %s",
989 ifname, strerror(errno));
990 } else {
991 memcpy(&saddr, &ifr.ifr_addr,
992 sizeof(struct sockaddr_in));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700993 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200994 }
995
996 if (ioctl(s, SIOCGIFNETMASK, &ifr) == 0) {
997 memcpy(&saddr, &ifr.ifr_addr,
998 sizeof(struct sockaddr_in));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700999 strlcpy(mask, inet_ntoa(saddr.sin_addr), sizeof(mask));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001000 }
1001 close(s);
1002 }
1003
1004#ifdef ANDROID
1005 snprintf(tmp, sizeof(tmp), "dhcp.%s.pid", ifname);
1006 if (property_get(tmp, prop, NULL) != 0 && atoi(prop) > 0) {
1007 snprintf(tmp, sizeof(tmp), "dhcp.%s.result", ifname);
1008 if (property_get(tmp, prop, NULL) != 0 &&
1009 strcmp(prop, "ok") == 0) {
1010 snprintf(tmp, sizeof(tmp), "dhcp.%s.ipaddress",
1011 ifname);
1012 if (property_get(tmp, prop, NULL) != 0 &&
1013 strcmp(ip, prop) == 0)
1014 is_dhcp = 1;
1015 }
1016 }
1017
1018 snprintf(tmp, sizeof(tmp), "dhcp.%s.dns1", ifname);
Peng Xub8fc5cc2017-05-10 17:27:28 -07001019 if (property_get(tmp, prop, NULL) != 0)
1020 strlcpy(dns, prop, sizeof(dns));
1021 else if (property_get("net.dns1", prop, NULL) != 0)
1022 strlcpy(dns, prop, sizeof(dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001023
1024 snprintf(tmp, sizeof(tmp), "dhcp.%s.dns2", ifname);
Peng Xub8fc5cc2017-05-10 17:27:28 -07001025 if (property_get(tmp, prop, NULL) != 0)
1026 strlcpy(sec_dns, prop, sizeof(sec_dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001027#else /* ANDROID */
1028#ifdef __linux__
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001029 if (get_driver_type(dut) == DRIVER_OPENWRT)
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +05301030 str_ps = "ps -w";
1031 else
1032 str_ps = "ps ax";
1033 snprintf(tmp, sizeof(tmp),
1034 "%s | grep dhclient | grep -v grep | grep -q %s",
1035 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001036 if (system(tmp) == 0)
1037 is_dhcp = 1;
1038 else {
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +05301039 snprintf(tmp, sizeof(tmp),
1040 "%s | grep udhcpc | grep -v grep | grep -q %s",
1041 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001042 if (system(tmp) == 0)
1043 is_dhcp = 1;
1044 else {
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +05301045 snprintf(tmp, sizeof(tmp),
1046 "%s | grep dhcpcd | grep -v grep | grep -q %s",
1047 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001048 if (system(tmp) == 0)
1049 is_dhcp = 1;
1050 }
1051 }
1052#endif /* __linux__ */
1053
1054 f = fopen("/etc/resolv.conf", "r");
1055 if (f) {
vamsi krishnaa11d0732018-05-16 12:19:48 +05301056 char *pos, *pos2;
1057
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001058 while (fgets(tmp, sizeof(tmp), f)) {
1059 if (strncmp(tmp, "nameserver", 10) != 0)
1060 continue;
1061 pos = tmp + 10;
1062 while (*pos == ' ' || *pos == '\t')
1063 pos++;
1064 pos2 = pos;
1065 while (*pos2) {
1066 if (*pos2 == '\n' || *pos2 == '\r') {
1067 *pos2 = '\0';
1068 break;
1069 }
1070 pos2++;
1071 }
Peng Xub8fc5cc2017-05-10 17:27:28 -07001072 if (!dns[0])
1073 strlcpy(dns, pos, sizeof(dns));
1074 else if (!sec_dns[0])
1075 strlcpy(sec_dns, pos, sizeof(sec_dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001076 }
1077 fclose(f);
1078 }
1079#endif /* ANDROID */
1080
1081 snprintf(buf, buf_len, "dhcp,%d,ip,%s,mask,%s,primary-dns,%s",
1082 is_dhcp, ip, mask, dns);
1083 buf[buf_len - 1] = '\0';
1084
1085 return 0;
1086}
1087
1088
1089
1090
1091int get_ipv6_config(struct sigma_dut *dut, const char *ifname, char *buf,
1092 size_t buf_len)
1093{
1094#ifdef __linux__
1095#ifdef ANDROID
1096 char cmd[200], result[1000], *pos, *end;
1097 FILE *f;
1098 size_t len;
1099
1100 snprintf(cmd, sizeof(cmd), "ip addr show dev %s scope global", ifname);
1101 f = popen(cmd, "r");
1102 if (f == NULL)
1103 return -1;
1104 len = fread(result, 1, sizeof(result) - 1, f);
1105 pclose(f);
1106 if (len == 0)
1107 return -1;
1108 result[len] = '\0';
1109 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s result: %s\n", cmd, result);
1110
1111 pos = strstr(result, "inet6 ");
1112 if (pos == NULL)
1113 return -1;
1114 pos += 6;
1115 end = strchr(pos, ' ');
1116 if (end)
1117 *end = '\0';
1118 end = strchr(pos, '/');
1119 if (end)
1120 *end = '\0';
1121 snprintf(buf, buf_len, "ip,%s", pos);
1122 buf[buf_len - 1] = '\0';
1123 return 0;
1124#else /* ANDROID */
1125 struct ifaddrs *ifaddr, *ifa;
1126 int res, found = 0;
1127 char host[NI_MAXHOST];
1128
1129 if (getifaddrs(&ifaddr) < 0) {
1130 perror("getifaddrs");
1131 return -1;
1132 }
1133
1134 for (ifa = ifaddr; ifa; ifa = ifa->ifa_next) {
1135 if (strcasecmp(ifname, ifa->ifa_name) != 0)
1136 continue;
1137 if (ifa->ifa_addr == NULL ||
1138 ifa->ifa_addr->sa_family != AF_INET6)
1139 continue;
1140
1141 res = getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in6),
1142 host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
1143 if (res != 0) {
1144 sigma_dut_print(dut, DUT_MSG_DEBUG, "getnameinfo: %s",
1145 gai_strerror(res));
1146 continue;
1147 }
1148 if (strncmp(host, "fe80::", 6) == 0)
1149 continue; /* skip link-local */
1150
1151 sigma_dut_print(dut, DUT_MSG_DEBUG, "ifaddr: %s", host);
1152 found = 1;
1153 break;
1154 }
1155
1156 freeifaddrs(ifaddr);
1157
1158 if (found) {
1159 char *pos;
1160 pos = strchr(host, '%');
1161 if (pos)
1162 *pos = '\0';
1163 snprintf(buf, buf_len, "ip,%s", host);
1164 buf[buf_len - 1] = '\0';
1165 return 0;
1166 }
1167
1168#endif /* ANDROID */
1169#endif /* __linux__ */
1170 return -1;
1171}
1172
1173
Jouni Malinenf7222712019-06-13 01:50:21 +03001174static enum sigma_cmd_result cmd_sta_get_ip_config(struct sigma_dut *dut,
1175 struct sigma_conn *conn,
1176 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001177{
1178 const char *intf = get_param(cmd, "Interface");
1179 const char *ifname;
1180 char buf[200];
1181 const char *val;
1182 int type = 1;
1183
1184 if (intf == NULL)
1185 return -1;
1186
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001187 if (strcmp(intf, get_main_ifname(dut)) == 0)
1188 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001189 else
1190 ifname = intf;
1191
1192 /*
1193 * UCC may assume the IP address to be available immediately after
1194 * association without trying to run sta_get_ip_config multiple times.
1195 * Sigma CAPI does not specify this command as a block command that
1196 * would wait for the address to become available, but to pass tests
1197 * more reliably, it looks like such a wait may be needed here.
1198 */
1199 if (wait_ip_addr(dut, ifname, 15) < 0) {
1200 sigma_dut_print(dut, DUT_MSG_INFO, "Could not get IP address "
1201 "for sta_get_ip_config");
1202 /*
1203 * Try to continue anyway since many UCC tests do not really
1204 * care about the return value from here..
1205 */
1206 }
1207
1208 val = get_param(cmd, "Type");
1209 if (val)
1210 type = atoi(val);
1211 if (type == 2 || dut->last_set_ip_config_ipv6) {
1212 int i;
1213
1214 /*
1215 * Since we do not have proper wait for IPv6 addresses, use a
1216 * fixed two second delay here as a workaround for UCC script
1217 * assuming IPv6 address is available when this command returns.
1218 * Some scripts did not use Type,2 properly for IPv6, so include
1219 * also the cases where the previous sta_set_ip_config indicated
1220 * use of IPv6.
1221 */
1222 sigma_dut_print(dut, DUT_MSG_INFO, "Wait up to extra ten seconds in sta_get_ip_config for IPv6 address");
1223 for (i = 0; i < 10; i++) {
1224 sleep(1);
1225 if (get_ipv6_config(dut, ifname, buf, sizeof(buf)) == 0)
1226 {
1227 sigma_dut_print(dut, DUT_MSG_INFO, "Found IPv6 address");
1228 send_resp(dut, conn, SIGMA_COMPLETE, buf);
1229#ifdef ANDROID
1230 sigma_dut_print(dut, DUT_MSG_INFO,
1231 "Adding IPv6 rule on Android");
1232 add_ipv6_rule(dut, intf);
1233#endif /* ANDROID */
1234
1235 return 0;
1236 }
1237 }
1238 }
1239 if (type == 1) {
1240 if (get_ip_config(dut, ifname, buf, sizeof(buf)) < 0)
1241 return -2;
1242 } else if (type == 2) {
1243 if (get_ipv6_config(dut, ifname, buf, sizeof(buf)) < 0)
1244 return -2;
1245 } else {
1246 send_resp(dut, conn, SIGMA_ERROR,
1247 "errorCode,Unsupported address type");
1248 return 0;
1249 }
1250
1251 send_resp(dut, conn, SIGMA_COMPLETE, buf);
1252 return 0;
1253}
1254
1255
1256static void kill_dhcp_client(struct sigma_dut *dut, const char *ifname)
1257{
1258#ifdef __linux__
1259 char buf[200];
1260 char path[128];
1261 struct stat s;
1262
1263#ifdef ANDROID
1264 snprintf(path, sizeof(path), "/data/misc/dhcp/dhcpcd-%s.pid", ifname);
1265#else /* ANDROID */
1266 snprintf(path, sizeof(path), "/var/run/dhclient-%s.pid", ifname);
1267#endif /* ANDROID */
1268 if (stat(path, &s) == 0) {
1269 snprintf(buf, sizeof(buf), "kill `cat %s`", path);
1270 sigma_dut_print(dut, DUT_MSG_INFO,
1271 "Kill previous DHCP client: %s", buf);
1272 if (system(buf) != 0)
1273 sigma_dut_print(dut, DUT_MSG_INFO,
1274 "Failed to kill DHCP client");
1275 unlink(path);
1276 sleep(1);
1277 } else {
1278 snprintf(path, sizeof(path), "/var/run/dhcpcd-%s.pid", ifname);
1279
1280 if (stat(path, &s) == 0) {
1281 snprintf(buf, sizeof(buf), "kill `cat %s`", path);
1282 sigma_dut_print(dut, DUT_MSG_INFO,
1283 "Kill previous DHCP client: %s", buf);
1284 if (system(buf) != 0)
1285 sigma_dut_print(dut, DUT_MSG_INFO,
1286 "Failed to kill DHCP client");
1287 unlink(path);
1288 sleep(1);
1289 }
1290 }
1291#endif /* __linux__ */
1292}
1293
1294
1295static int start_dhcp_client(struct sigma_dut *dut, const char *ifname)
1296{
1297#ifdef __linux__
1298 char buf[200];
1299
1300#ifdef ANDROID
Purushottam Kushwaha46d64262016-08-23 17:57:53 +05301301 if (access("/system/bin/dhcpcd", F_OK) != -1) {
1302 snprintf(buf, sizeof(buf),
1303 "/system/bin/dhcpcd -b %s", ifname);
1304 } else if (access("/system/bin/dhcptool", F_OK) != -1) {
1305 snprintf(buf, sizeof(buf), "/system/bin/dhcptool %s &", ifname);
Ankita Bajaj8454e5d2019-04-05 16:04:55 +05301306 } else if (access("/vendor/bin/dhcpcd", F_OK) != -1) {
1307 snprintf(buf, sizeof(buf), "/vendor/bin/dhcpcd -b %s", ifname);
1308 } else if (access("/vendor/bin/dhcptool", F_OK) != -1) {
1309 snprintf(buf, sizeof(buf), "/vendor/bin/dhcptool %s", ifname);
Purushottam Kushwaha46d64262016-08-23 17:57:53 +05301310 } else {
1311 sigma_dut_print(dut, DUT_MSG_ERROR,
1312 "DHCP client program missing");
1313 return 0;
1314 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001315#else /* ANDROID */
1316 snprintf(buf, sizeof(buf),
1317 "dhclient -nw -pf /var/run/dhclient-%s.pid %s",
1318 ifname, ifname);
1319#endif /* ANDROID */
1320 sigma_dut_print(dut, DUT_MSG_INFO, "Start DHCP client: %s", buf);
1321 if (system(buf) != 0) {
1322 snprintf(buf, sizeof(buf), "dhcpcd -t 0 %s &", ifname);
1323 if (system(buf) != 0) {
1324 sigma_dut_print(dut, DUT_MSG_INFO,
1325 "Failed to start DHCP client");
1326#ifndef ANDROID
1327 return -1;
1328#endif /* ANDROID */
1329 }
1330 }
1331#endif /* __linux__ */
1332
1333 return 0;
1334}
1335
1336
1337static int clear_ip_addr(struct sigma_dut *dut, const char *ifname)
1338{
1339#ifdef __linux__
1340 char buf[200];
1341
1342 snprintf(buf, sizeof(buf), "ip addr flush dev %s", ifname);
1343 if (system(buf) != 0) {
1344 sigma_dut_print(dut, DUT_MSG_INFO,
1345 "Failed to clear IP addresses");
1346 return -1;
1347 }
1348#endif /* __linux__ */
1349
1350 return 0;
1351}
1352
1353
1354#ifdef ANDROID
1355static int add_ipv6_rule(struct sigma_dut *dut, const char *ifname)
1356{
1357 char cmd[200], *result, *pos;
1358 FILE *fp;
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +05301359 int tableid;
1360 size_t len, result_len = 1000;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001361
1362 snprintf(cmd, sizeof(cmd), "ip -6 route list table all | grep %s",
1363 ifname);
1364 fp = popen(cmd, "r");
1365 if (fp == NULL)
1366 return -1;
1367
1368 result = malloc(result_len);
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05301369 if (result == NULL) {
1370 fclose(fp);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001371 return -1;
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05301372 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001373
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +05301374 len = fread(result, 1, result_len - 1, fp);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001375 fclose(fp);
1376
1377 if (len == 0) {
1378 free(result);
1379 return -1;
1380 }
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +05301381 result[len] = '\0';
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001382
1383 pos = strstr(result, "table ");
1384 if (pos == NULL) {
1385 free(result);
1386 return -1;
1387 }
1388
1389 pos += strlen("table ");
1390 tableid = atoi(pos);
1391 if (tableid != 0) {
1392 if (system("ip -6 rule del prio 22000") != 0) {
1393 /* ignore any error */
1394 }
1395 snprintf(cmd, sizeof(cmd),
1396 "ip -6 rule add from all lookup %d prio 22000",
1397 tableid);
1398 if (system(cmd) != 0) {
1399 sigma_dut_print(dut, DUT_MSG_INFO,
1400 "Failed to run %s", cmd);
1401 free(result);
1402 return -1;
1403 }
1404 } else {
1405 sigma_dut_print(dut, DUT_MSG_INFO,
1406 "No Valid Table Id found %s", pos);
1407 free(result);
1408 return -1;
1409 }
1410 free(result);
1411
1412 return 0;
1413}
1414#endif /* ANDROID */
1415
1416
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301417int set_ipv4_addr(struct sigma_dut *dut, const char *ifname,
1418 const char *ip, const char *mask)
1419{
1420 char buf[200];
1421
1422 snprintf(buf, sizeof(buf), "ifconfig %s %s netmask %s",
1423 ifname, ip, mask);
1424 return system(buf) == 0;
1425}
1426
1427
1428int set_ipv4_gw(struct sigma_dut *dut, const char *gw)
1429{
1430 char buf[200];
1431
1432 if (!is_ip_addr(gw)) {
1433 sigma_dut_print(dut, DUT_MSG_DEBUG, "Invalid gw addr - %s", gw);
1434 return -1;
1435 }
1436
1437 snprintf(buf, sizeof(buf), "route add default gw %s", gw);
1438 if (!dut->no_ip_addr_set && system(buf) != 0) {
1439 snprintf(buf, sizeof(buf), "ip ro re default via %s",
1440 gw);
1441 if (system(buf) != 0)
1442 return 0;
1443 }
1444
1445 return 1;
1446}
1447
1448
Jouni Malinenf7222712019-06-13 01:50:21 +03001449static enum sigma_cmd_result cmd_sta_set_ip_config(struct sigma_dut *dut,
1450 struct sigma_conn *conn,
1451 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001452{
1453 const char *intf = get_param(cmd, "Interface");
1454 const char *ifname;
1455 char buf[200];
1456 const char *val, *ip, *mask, *gw;
1457 int type = 1;
1458
1459 if (intf == NULL)
1460 return -1;
1461
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001462 if (strcmp(intf, get_main_ifname(dut)) == 0)
1463 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001464 else
1465 ifname = intf;
1466
1467 if (if_nametoindex(ifname) == 0) {
1468 send_resp(dut, conn, SIGMA_ERROR,
1469 "ErrorCode,Unknown interface");
1470 return 0;
1471 }
1472
1473 val = get_param(cmd, "Type");
1474 if (val) {
1475 type = atoi(val);
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301476 if (type < 1 || type > 3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001477 send_resp(dut, conn, SIGMA_ERROR,
1478 "ErrorCode,Unsupported address type");
1479 return 0;
1480 }
1481 }
1482
1483 dut->last_set_ip_config_ipv6 = 0;
1484
1485 val = get_param(cmd, "dhcp");
1486 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "true") == 0)) {
1487 static_ip_file(0, NULL, NULL, NULL);
1488#ifdef __linux__
1489 if (type == 2) {
1490 dut->last_set_ip_config_ipv6 = 1;
1491 sigma_dut_print(dut, DUT_MSG_INFO, "Using IPv6 "
1492 "stateless address autoconfiguration");
1493#ifdef ANDROID
1494 /*
1495 * This sleep is required as the assignment in case of
1496 * Android is taking time and is done by the kernel.
1497 * The subsequent ping for IPv6 is impacting HS20 test
1498 * case.
1499 */
1500 sleep(2);
1501 add_ipv6_rule(dut, intf);
1502#endif /* ANDROID */
1503 /* Assume this happens by default */
1504 return 1;
1505 }
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301506 if (type != 3) {
1507 kill_dhcp_client(dut, ifname);
1508 if (start_dhcp_client(dut, ifname) < 0)
1509 return -2;
1510 } else {
1511 sigma_dut_print(dut, DUT_MSG_DEBUG,
1512 "Using FILS HLP DHCPv4 Rapid Commit");
1513 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001514
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001515 return 1;
1516#endif /* __linux__ */
1517 return -2;
1518 }
1519
1520 ip = get_param(cmd, "ip");
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301521 if (!ip) {
1522 send_resp(dut, conn, SIGMA_INVALID,
1523 "ErrorCode,Missing IP address");
1524 return 0;
1525 }
1526
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001527 mask = get_param(cmd, "mask");
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301528 if (!mask) {
1529 send_resp(dut, conn, SIGMA_INVALID,
1530 "ErrorCode,Missing subnet mask");
1531 return 0;
1532 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001533
1534 if (type == 2) {
1535 int net = atoi(mask);
1536
1537 if ((net < 0 && net > 64) || !is_ipv6_addr(ip))
1538 return -1;
1539
1540 if (dut->no_ip_addr_set) {
1541 snprintf(buf, sizeof(buf),
1542 "sysctl net.ipv6.conf.%s.disable_ipv6=1",
1543 ifname);
1544 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
1545 if (system(buf) != 0) {
1546 sigma_dut_print(dut, DUT_MSG_DEBUG,
1547 "Failed to disable IPv6 address before association");
1548 }
1549 } else {
Veerendranath Jakkam176181c2020-05-16 00:19:21 +05301550 if (set_ipv6_addr(dut, ip, mask, ifname) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001551 send_resp(dut, conn, SIGMA_ERROR,
1552 "ErrorCode,Failed to set IPv6 address");
1553 return 0;
1554 }
1555 }
1556
1557 dut->last_set_ip_config_ipv6 = 1;
1558 static_ip_file(6, ip, mask, NULL);
1559 return 1;
1560 } else if (type == 1) {
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301561 if (!is_ip_addr(ip) || !is_ip_addr(mask))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001562 return -1;
1563 }
1564
1565 kill_dhcp_client(dut, ifname);
1566
1567 if (!dut->no_ip_addr_set) {
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301568 if (!set_ipv4_addr(dut, ifname, ip, mask)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001569 send_resp(dut, conn, SIGMA_ERROR,
1570 "ErrorCode,Failed to set IP address");
1571 return 0;
1572 }
1573 }
1574
1575 gw = get_param(cmd, "defaultGateway");
1576 if (gw) {
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301577 if (set_ipv4_gw(dut, gw) < 1) {
1578 send_resp(dut, conn, SIGMA_ERROR,
1579 "ErrorCode,Failed to set default gateway");
1580 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001581 }
1582 }
1583
1584 val = get_param(cmd, "primary-dns");
1585 if (val) {
1586 /* TODO */
1587 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored primary-dns %s "
1588 "setting", val);
1589 }
1590
1591 val = get_param(cmd, "secondary-dns");
1592 if (val) {
1593 /* TODO */
1594 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored secondary-dns %s "
1595 "setting", val);
1596 }
1597
1598 static_ip_file(4, ip, mask, gw);
1599
1600 return 1;
1601}
1602
1603
Jouni Malinenf7222712019-06-13 01:50:21 +03001604static enum sigma_cmd_result cmd_sta_get_info(struct sigma_dut *dut,
1605 struct sigma_conn *conn,
1606 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001607{
1608 /* const char *intf = get_param(cmd, "Interface"); */
1609 /* TODO: could report more details here */
1610 send_resp(dut, conn, SIGMA_COMPLETE, "vendor,Atheros");
1611 return 0;
1612}
1613
1614
Jouni Malinenf7222712019-06-13 01:50:21 +03001615static enum sigma_cmd_result cmd_sta_get_mac_address(struct sigma_dut *dut,
1616 struct sigma_conn *conn,
1617 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001618{
1619 /* const char *intf = get_param(cmd, "Interface"); */
1620 char addr[20], resp[50];
1621
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05301622 if (dut->dev_role == DEVROLE_STA_CFON)
1623 return sta_cfon_get_mac_address(dut, conn, cmd);
1624
Jouni Malinen9540e012019-11-05 17:08:42 +02001625 start_sta_mode(dut);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001626 if (get_wpa_status(get_station_ifname(dut), "address",
1627 addr, sizeof(addr)) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001628 return -2;
1629
1630 snprintf(resp, sizeof(resp), "mac,%s", addr);
1631 send_resp(dut, conn, SIGMA_COMPLETE, resp);
1632 return 0;
1633}
1634
1635
Jouni Malinenf7222712019-06-13 01:50:21 +03001636static enum sigma_cmd_result cmd_sta_is_connected(struct sigma_dut *dut,
1637 struct sigma_conn *conn,
1638 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001639{
1640 /* const char *intf = get_param(cmd, "Interface"); */
1641 int connected = 0;
1642 char result[32];
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001643 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001644 sizeof(result)) < 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001645 sigma_dut_print(dut, DUT_MSG_INFO,
1646 "Could not get interface %s status",
1647 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001648 return -2;
1649 }
1650
1651 sigma_dut_print(dut, DUT_MSG_DEBUG, "wpa_state=%s", result);
1652 if (strncmp(result, "COMPLETED", 9) == 0)
1653 connected = 1;
1654
1655 if (connected)
1656 send_resp(dut, conn, SIGMA_COMPLETE, "connected,1");
1657 else
1658 send_resp(dut, conn, SIGMA_COMPLETE, "connected,0");
1659
1660 return 0;
1661}
1662
1663
Jouni Malinenf7222712019-06-13 01:50:21 +03001664static enum sigma_cmd_result
1665cmd_sta_verify_ip_connection(struct sigma_dut *dut, struct sigma_conn *conn,
1666 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001667{
1668 /* const char *intf = get_param(cmd, "Interface"); */
1669 const char *dst, *timeout;
1670 int wait_time = 90;
1671 char buf[100];
1672 int res;
1673
1674 dst = get_param(cmd, "destination");
1675 if (dst == NULL || !is_ip_addr(dst))
1676 return -1;
1677
1678 timeout = get_param(cmd, "timeout");
1679 if (timeout) {
1680 wait_time = atoi(timeout);
1681 if (wait_time < 1)
1682 wait_time = 1;
1683 }
1684
1685 /* TODO: force renewal of IP lease if DHCP is enabled */
1686
1687 snprintf(buf, sizeof(buf), "ping %s -c 3 -W %d", dst, wait_time);
1688 res = system(buf);
1689 sigma_dut_print(dut, DUT_MSG_DEBUG, "ping returned: %d", res);
1690 if (res == 0)
1691 send_resp(dut, conn, SIGMA_COMPLETE, "connected,1");
1692 else if (res == 256)
1693 send_resp(dut, conn, SIGMA_COMPLETE, "connected,0");
1694 else
1695 return -2;
1696
1697 return 0;
1698}
1699
1700
Jouni Malinenf7222712019-06-13 01:50:21 +03001701static enum sigma_cmd_result cmd_sta_get_bssid(struct sigma_dut *dut,
1702 struct sigma_conn *conn,
1703 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001704{
1705 /* const char *intf = get_param(cmd, "Interface"); */
1706 char bssid[20], resp[50];
1707
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001708 if (get_wpa_status(get_station_ifname(dut), "bssid",
1709 bssid, sizeof(bssid)) < 0)
Peng Xub8fc5cc2017-05-10 17:27:28 -07001710 strlcpy(bssid, "00:00:00:00:00:00", sizeof(bssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001711
1712 snprintf(resp, sizeof(resp), "bssid,%s", bssid);
1713 send_resp(dut, conn, SIGMA_COMPLETE, resp);
1714 return 0;
1715}
1716
1717
1718#ifdef __SAMSUNG__
1719static int add_use_network(const char *ifname)
1720{
1721 char buf[100];
1722
1723 snprintf(buf, sizeof(buf), "USE_NETWORK ON");
1724 wpa_command(ifname, buf);
1725 return 0;
1726}
1727#endif /* __SAMSUNG__ */
1728
1729
1730static int add_network_common(struct sigma_dut *dut, struct sigma_conn *conn,
1731 const char *ifname, struct sigma_cmd *cmd)
1732{
1733 const char *ssid = get_param(cmd, "ssid");
1734 int id;
1735 const char *val;
1736
1737 if (ssid == NULL)
1738 return -1;
1739
1740 start_sta_mode(dut);
1741
1742#ifdef __SAMSUNG__
1743 add_use_network(ifname);
1744#endif /* __SAMSUNG__ */
1745
1746 id = add_network(ifname);
1747 if (id < 0)
1748 return -2;
1749 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding network %d", id);
1750
1751 if (set_network_quoted(ifname, id, "ssid", ssid) < 0)
1752 return -2;
1753
1754 dut->infra_network_id = id;
1755 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
1756
1757 val = get_param(cmd, "program");
1758 if (!val)
1759 val = get_param(cmd, "prog");
1760 if (val && strcasecmp(val, "hs2") == 0) {
1761 char buf[100];
1762 snprintf(buf, sizeof(buf), "ENABLE_NETWORK %d no-connect", id);
1763 wpa_command(ifname, buf);
1764
1765 val = get_param(cmd, "prefer");
1766 if (val && atoi(val) > 0)
1767 set_network(ifname, id, "priority", "1");
1768 }
1769
1770 return id;
1771}
1772
1773
Jouni Malinenf7222712019-06-13 01:50:21 +03001774static enum sigma_cmd_result cmd_sta_set_encryption(struct sigma_dut *dut,
1775 struct sigma_conn *conn,
1776 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001777{
1778 const char *intf = get_param(cmd, "Interface");
1779 const char *ssid = get_param(cmd, "ssid");
1780 const char *type = get_param(cmd, "encpType");
1781 const char *ifname;
1782 char buf[200];
1783 int id;
1784
1785 if (intf == NULL || ssid == NULL)
1786 return -1;
1787
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001788 if (strcmp(intf, get_main_ifname(dut)) == 0)
1789 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001790 else
1791 ifname = intf;
1792
1793 id = add_network_common(dut, conn, ifname, cmd);
1794 if (id < 0)
1795 return id;
1796
1797 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
1798 return -2;
1799
1800 if (type && strcasecmp(type, "wep") == 0) {
1801 const char *val;
1802 int i;
1803
1804 val = get_param(cmd, "activeKey");
1805 if (val) {
1806 int keyid;
1807 keyid = atoi(val);
1808 if (keyid < 1 || keyid > 4)
1809 return -1;
1810 snprintf(buf, sizeof(buf), "%d", keyid - 1);
1811 if (set_network(ifname, id, "wep_tx_keyidx", buf) < 0)
1812 return -2;
1813 }
1814
1815 for (i = 0; i < 4; i++) {
1816 snprintf(buf, sizeof(buf), "key%d", i + 1);
1817 val = get_param(cmd, buf);
1818 if (val == NULL)
1819 continue;
1820 snprintf(buf, sizeof(buf), "wep_key%d", i);
1821 if (set_network(ifname, id, buf, val) < 0)
1822 return -2;
1823 }
1824 }
1825
1826 return 1;
1827}
1828
1829
Jouni Malinene4fde732019-03-25 22:29:37 +02001830static int set_akm_suites(struct sigma_dut *dut, const char *ifname,
1831 int id, const char *val)
1832{
1833 char key_mgmt[200], *end, *pos;
1834 const char *in_pos = val;
1835
Jouni Malinen8179fee2019-03-28 03:19:47 +02001836 dut->akm_values = 0;
Jouni Malinene4fde732019-03-25 22:29:37 +02001837 pos = key_mgmt;
1838 end = pos + sizeof(key_mgmt);
1839 while (*in_pos) {
1840 int res, akm = atoi(in_pos);
1841 const char *str;
1842
Jouni Malinen8179fee2019-03-28 03:19:47 +02001843 if (akm >= 0 && akm < 32)
1844 dut->akm_values |= 1 << akm;
1845
Jouni Malinene4fde732019-03-25 22:29:37 +02001846 switch (akm) {
1847 case AKM_WPA_EAP:
1848 str = "WPA-EAP";
1849 break;
1850 case AKM_WPA_PSK:
1851 str = "WPA-PSK";
1852 break;
1853 case AKM_FT_EAP:
1854 str = "FT-EAP";
1855 break;
1856 case AKM_FT_PSK:
1857 str = "FT-PSK";
1858 break;
1859 case AKM_EAP_SHA256:
1860 str = "WPA-EAP-SHA256";
1861 break;
1862 case AKM_PSK_SHA256:
1863 str = "WPA-PSK-SHA256";
1864 break;
1865 case AKM_SAE:
1866 str = "SAE";
1867 break;
1868 case AKM_FT_SAE:
1869 str = "FT-SAE";
1870 break;
1871 case AKM_SUITE_B:
1872 str = "WPA-EAP-SUITE-B-192";
1873 break;
1874 case AKM_FT_SUITE_B:
1875 str = "FT-EAP-SHA384";
1876 break;
1877 case AKM_FILS_SHA256:
1878 str = "FILS-SHA256";
1879 break;
1880 case AKM_FILS_SHA384:
1881 str = "FILS-SHA384";
1882 break;
1883 case AKM_FT_FILS_SHA256:
1884 str = "FT-FILS-SHA256";
1885 break;
1886 case AKM_FT_FILS_SHA384:
1887 str = "FT-FILS-SHA384";
1888 break;
1889 default:
1890 sigma_dut_print(dut, DUT_MSG_ERROR,
1891 "Unsupported AKMSuitetype %d", akm);
1892 return -1;
1893 }
1894
1895 res = snprintf(pos, end - pos, "%s%s",
1896 pos == key_mgmt ? "" : " ", str);
1897 if (res < 0 || res >= end - pos)
1898 return -1;
1899 pos += res;
1900
1901 in_pos = strchr(in_pos, ';');
1902 if (!in_pos)
1903 break;
1904 while (*in_pos == ';')
1905 in_pos++;
1906 }
1907 sigma_dut_print(dut, DUT_MSG_DEBUG, "AKMSuiteType %s --> %s",
1908 val, key_mgmt);
1909 return set_network(ifname, id, "key_mgmt", key_mgmt);
1910}
1911
1912
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001913static int set_wpa_common(struct sigma_dut *dut, struct sigma_conn *conn,
1914 const char *ifname, struct sigma_cmd *cmd)
1915{
1916 const char *val;
1917 int id;
Jouni Malinenad395a22017-09-01 21:13:46 +03001918 int cipher_set = 0;
Jouni Malinen47dcc952017-10-09 16:43:24 +03001919 int owe;
Sunil Duttc75a1e62018-01-11 20:47:50 +05301920 int suite_b = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001921
1922 id = add_network_common(dut, conn, ifname, cmd);
1923 if (id < 0)
1924 return id;
1925
Jouni Malinen47dcc952017-10-09 16:43:24 +03001926 val = get_param(cmd, "Type");
1927 owe = val && strcasecmp(val, "OWE") == 0;
1928
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001929 val = get_param(cmd, "keyMgmtType");
Jouni Malinen47dcc952017-10-09 16:43:24 +03001930 if (!val && owe)
1931 val = "OWE";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001932 if (val == NULL) {
Jouni Malinene4fde732019-03-25 22:29:37 +02001933 /* keyMgmtType is being replaced with AKMSuiteType, so ignore
1934 * this missing parameter and assume proto=WPA2. */
1935 if (set_network(ifname, id, "proto", "WPA2") < 0)
1936 return ERROR_SEND_STATUS;
1937 } else if (strcasecmp(val, "wpa") == 0 ||
1938 strcasecmp(val, "wpa-psk") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001939 if (set_network(ifname, id, "proto", "WPA") < 0)
1940 return -2;
1941 } else if (strcasecmp(val, "wpa2") == 0 ||
1942 strcasecmp(val, "wpa2-psk") == 0 ||
1943 strcasecmp(val, "wpa2-ft") == 0 ||
1944 strcasecmp(val, "wpa2-sha256") == 0) {
1945 if (set_network(ifname, id, "proto", "WPA2") < 0)
1946 return -2;
Pradeep Reddy POTTETI6d04b3b2016-11-15 14:51:26 +05301947 } else if (strcasecmp(val, "wpa2-wpa-psk") == 0 ||
1948 strcasecmp(val, "wpa2-wpa-ent") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001949 if (set_network(ifname, id, "proto", "WPA WPA2") < 0)
1950 return -2;
Jouni Malinenad395a22017-09-01 21:13:46 +03001951 } else if (strcasecmp(val, "SuiteB") == 0) {
Sunil Duttc75a1e62018-01-11 20:47:50 +05301952 suite_b = 1;
Jouni Malinenad395a22017-09-01 21:13:46 +03001953 if (set_network(ifname, id, "proto", "WPA2") < 0)
1954 return -2;
Jouni Malinen47dcc952017-10-09 16:43:24 +03001955 } else if (strcasecmp(val, "OWE") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001956 } else {
1957 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized keyMgmtType value");
1958 return 0;
1959 }
1960
1961 val = get_param(cmd, "encpType");
Jouni Malinenad395a22017-09-01 21:13:46 +03001962 if (val) {
1963 cipher_set = 1;
1964 if (strcasecmp(val, "tkip") == 0) {
1965 if (set_network(ifname, id, "pairwise", "TKIP") < 0)
1966 return -2;
1967 } else if (strcasecmp(val, "aes-ccmp") == 0) {
1968 if (set_network(ifname, id, "pairwise", "CCMP") < 0)
1969 return -2;
1970 } else if (strcasecmp(val, "aes-ccmp-tkip") == 0) {
1971 if (set_network(ifname, id, "pairwise",
1972 "CCMP TKIP") < 0)
1973 return -2;
1974 } else if (strcasecmp(val, "aes-gcmp") == 0) {
1975 if (set_network(ifname, id, "pairwise", "GCMP") < 0)
1976 return -2;
1977 if (set_network(ifname, id, "group", "GCMP") < 0)
1978 return -2;
1979 } else {
1980 send_resp(dut, conn, SIGMA_ERROR,
1981 "errorCode,Unrecognized encpType value");
1982 return 0;
1983 }
1984 }
1985
1986 val = get_param(cmd, "PairwiseCipher");
1987 if (val) {
1988 cipher_set = 1;
1989 /* TODO: Support space separated list */
1990 if (strcasecmp(val, "AES-GCMP-256") == 0) {
1991 if (set_network(ifname, id, "pairwise", "GCMP-256") < 0)
1992 return -2;
1993 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
1994 if (set_network(ifname, id, "pairwise",
1995 "CCMP-256") < 0)
1996 return -2;
1997 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
1998 if (set_network(ifname, id, "pairwise", "GCMP") < 0)
1999 return -2;
2000 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
2001 if (set_network(ifname, id, "pairwise", "CCMP") < 0)
2002 return -2;
2003 } else {
2004 send_resp(dut, conn, SIGMA_ERROR,
2005 "errorCode,Unrecognized PairwiseCipher value");
2006 return 0;
2007 }
2008 }
2009
Jouni Malinen47dcc952017-10-09 16:43:24 +03002010 if (!cipher_set && !owe) {
Jouni Malinenad395a22017-09-01 21:13:46 +03002011 send_resp(dut, conn, SIGMA_ERROR,
2012 "errorCode,Missing encpType and PairwiseCipher");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002013 return 0;
2014 }
Jouni Malinenad395a22017-09-01 21:13:46 +03002015
2016 val = get_param(cmd, "GroupCipher");
2017 if (val) {
2018 if (strcasecmp(val, "AES-GCMP-256") == 0) {
2019 if (set_network(ifname, id, "group", "GCMP-256") < 0)
2020 return -2;
2021 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
2022 if (set_network(ifname, id, "group", "CCMP-256") < 0)
2023 return -2;
2024 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
2025 if (set_network(ifname, id, "group", "GCMP") < 0)
2026 return -2;
2027 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
2028 if (set_network(ifname, id, "group", "CCMP") < 0)
2029 return -2;
2030 } else {
2031 send_resp(dut, conn, SIGMA_ERROR,
2032 "errorCode,Unrecognized GroupCipher value");
2033 return 0;
2034 }
2035 }
2036
Jouni Malinen7b239522017-09-14 21:37:18 +03002037 val = get_param(cmd, "GroupMgntCipher");
Jouni Malinenad395a22017-09-01 21:13:46 +03002038 if (val) {
Jouni Malinene8898cb2017-09-26 17:55:26 +03002039 const char *cipher;
2040
2041 if (strcasecmp(val, "BIP-GMAC-256") == 0) {
2042 cipher = "BIP-GMAC-256";
2043 } else if (strcasecmp(val, "BIP-CMAC-256") == 0) {
2044 cipher = "BIP-CMAC-256";
2045 } else if (strcasecmp(val, "BIP-GMAC-128") == 0) {
2046 cipher = "BIP-GMAC-128";
2047 } else if (strcasecmp(val, "BIP-CMAC-128") == 0) {
2048 cipher = "AES-128-CMAC";
2049 } else {
2050 send_resp(dut, conn, SIGMA_INVALID,
2051 "errorCode,Unsupported GroupMgntCipher");
2052 return 0;
2053 }
2054 if (set_network(ifname, id, "group_mgmt", cipher) < 0) {
2055 send_resp(dut, conn, SIGMA_INVALID,
2056 "errorCode,Failed to set GroupMgntCipher");
2057 return 0;
2058 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002059 }
2060
Jouni Malinene4fde732019-03-25 22:29:37 +02002061 val = get_param(cmd, "AKMSuiteType");
2062 if (val && set_akm_suites(dut, ifname, id, val) < 0)
2063 return ERROR_SEND_STATUS;
2064
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002065 dut->sta_pmf = STA_PMF_DISABLED;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302066
2067 if (dut->program == PROGRAM_OCE) {
2068 dut->sta_pmf = STA_PMF_OPTIONAL;
2069 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2070 return -2;
2071 }
2072
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002073 val = get_param(cmd, "PMF");
2074 if (val) {
2075 if (strcasecmp(val, "Required") == 0 ||
2076 strcasecmp(val, "Forced_Required") == 0) {
2077 dut->sta_pmf = STA_PMF_REQUIRED;
2078 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2079 return -2;
2080 } else if (strcasecmp(val, "Optional") == 0) {
2081 dut->sta_pmf = STA_PMF_OPTIONAL;
2082 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2083 return -2;
2084 } else if (strcasecmp(val, "Disabled") == 0 ||
Kiran Kumar Lokere07da3b22018-12-16 22:42:49 -08002085 strcasecmp(val, "Disable") == 0 ||
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002086 strcasecmp(val, "Forced_Disabled") == 0) {
2087 dut->sta_pmf = STA_PMF_DISABLED;
2088 } else {
2089 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized PMF value");
2090 return 0;
2091 }
Sunil Duttc75a1e62018-01-11 20:47:50 +05302092 } else if (owe || suite_b) {
Jouni Malinen1287cd72018-01-04 17:08:01 +02002093 dut->sta_pmf = STA_PMF_REQUIRED;
2094 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2095 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002096 }
2097
Jouni Malinen0165c7f2020-03-26 11:51:58 +02002098 val = get_param(cmd, "BeaconProtection");
Veerendranath Jakkamc1f71b62021-01-23 03:09:51 +05302099 if (val)
2100 dut->beacon_prot = atoi(val);
2101 if (dut->beacon_prot && set_network(ifname, id, "beacon_prot", "1") < 0)
Jouni Malinen0165c7f2020-03-26 11:51:58 +02002102 return ERROR_SEND_STATUS;
2103
Veerendranath Jakkam54fd51c2020-12-21 01:36:04 +05302104 if (dut->ocvc && set_network(ifname, id, "ocv", "1") < 0)
2105 return ERROR_SEND_STATUS;
2106
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002107 return id;
2108}
2109
2110
Jouni Malinenf7222712019-06-13 01:50:21 +03002111static enum sigma_cmd_result cmd_sta_set_psk(struct sigma_dut *dut,
2112 struct sigma_conn *conn,
2113 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002114{
2115 const char *intf = get_param(cmd, "Interface");
Jouni Malinen992a81e2017-08-22 13:57:47 +03002116 const char *type = get_param(cmd, "Type");
Jouni Malinen1287cd72018-01-04 17:08:01 +02002117 const char *pmf = get_param(cmd, "PMF");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002118 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinene4fde732019-03-25 22:29:37 +02002119 const char *akm = get_param(cmd, "AKMSuiteType");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002120 const char *ifname, *val, *alg;
2121 int id;
Jouni Malinen4b3769d2019-10-10 16:20:29 +03002122 char buf[50];
Jouni Malinen11e55212019-11-22 21:46:59 +02002123 int sae_pwe = -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002124
2125 if (intf == NULL)
2126 return -1;
2127
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002128 if (strcmp(intf, get_main_ifname(dut)) == 0)
2129 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002130 else
2131 ifname = intf;
2132
2133 id = set_wpa_common(dut, conn, ifname, cmd);
2134 if (id < 0)
2135 return id;
2136
2137 val = get_param(cmd, "keyMgmtType");
2138 alg = get_param(cmd, "micAlg");
2139
Jouni Malinen992a81e2017-08-22 13:57:47 +03002140 if (type && strcasecmp(type, "SAE") == 0) {
Jouni Malinene4fde732019-03-25 22:29:37 +02002141 if (!akm && val && strcasecmp(val, "wpa2-ft") == 0) {
Jouni Malinen992a81e2017-08-22 13:57:47 +03002142 if (set_network(ifname, id, "key_mgmt", "FT-SAE") < 0)
2143 return -2;
Jouni Malinene4fde732019-03-25 22:29:37 +02002144 } else if (!akm) {
Jouni Malinen992a81e2017-08-22 13:57:47 +03002145 if (set_network(ifname, id, "key_mgmt", "SAE") < 0)
2146 return -2;
2147 }
2148 if (wpa_command(ifname, "SET sae_groups ") != 0) {
2149 sigma_dut_print(dut, DUT_MSG_ERROR,
2150 "Failed to clear sae_groups to default");
2151 return -2;
2152 }
Jouni Malinen1287cd72018-01-04 17:08:01 +02002153 if (!pmf) {
2154 dut->sta_pmf = STA_PMF_REQUIRED;
2155 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2156 return -2;
2157 }
Jouni Malinen0ab50f42017-08-31 01:34:59 +03002158 } else if (type && strcasecmp(type, "PSK-SAE") == 0) {
2159 if (val && strcasecmp(val, "wpa2-ft") == 0) {
2160 if (set_network(ifname, id, "key_mgmt",
2161 "FT-SAE FT-PSK") < 0)
2162 return -2;
Jouni Malinen3b73d872019-06-12 03:13:25 +03002163 } else if (!akm) {
Jouni Malinen0ab50f42017-08-31 01:34:59 +03002164 if (set_network(ifname, id, "key_mgmt",
2165 "SAE WPA-PSK") < 0)
2166 return -2;
2167 }
2168 if (wpa_command(ifname, "SET sae_groups ") != 0) {
2169 sigma_dut_print(dut, DUT_MSG_ERROR,
2170 "Failed to clear sae_groups to default");
2171 return -2;
2172 }
Jouni Malinen1287cd72018-01-04 17:08:01 +02002173 if (!pmf) {
2174 dut->sta_pmf = STA_PMF_OPTIONAL;
2175 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2176 return -2;
2177 }
Jouni Malinen992a81e2017-08-22 13:57:47 +03002178 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002179 if (set_network(ifname, id, "key_mgmt", "WPA-PSK-SHA256") < 0)
2180 return -2;
2181 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
2182 if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0)
2183 return -2;
Ashwini Patil6dbf7b02017-03-20 13:42:11 +05302184 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
2185 if (set_network(ifname, id, "key_mgmt", "FT-PSK") < 0)
2186 return -2;
Jouni Malinen3b73d872019-06-12 03:13:25 +03002187 } else if (!akm &&
2188 ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
2189 dut->sta_pmf == STA_PMF_REQUIRED)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002190 if (set_network(ifname, id, "key_mgmt",
2191 "WPA-PSK WPA-PSK-SHA256") < 0)
2192 return -2;
Jouni Malinen77ff3f02019-03-28 03:45:40 +02002193 } else if (!akm && dut->sta_pmf == STA_PMF_OPTIONAL) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002194 if (set_network(ifname, id, "key_mgmt",
2195 "WPA-PSK WPA-PSK-SHA256") < 0)
2196 return -2;
Jouni Malinen77ff3f02019-03-28 03:45:40 +02002197 } else if (!akm) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002198 if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0)
2199 return -2;
2200 }
2201
2202 val = get_param(cmd, "passPhrase");
2203 if (val == NULL)
2204 return -1;
Jouni Malinen2126f422017-10-11 23:24:33 +03002205 if (type && strcasecmp(type, "SAE") == 0) {
2206 if (set_network_quoted(ifname, id, "sae_password", val) < 0)
2207 return -2;
2208 } else {
2209 if (set_network_quoted(ifname, id, "psk", val) < 0)
2210 return -2;
2211 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002212
Jouni Malinen78d10c42019-03-25 22:34:32 +02002213 val = get_param(cmd, "PasswordId");
2214 if (val && set_network_quoted(ifname, id, "sae_password_id", val) < 0)
2215 return ERROR_SEND_STATUS;
2216
Jouni Malinen992a81e2017-08-22 13:57:47 +03002217 val = get_param(cmd, "ECGroupID");
2218 if (val) {
Jouni Malinenb54f0df2019-12-12 01:57:29 +02002219 snprintf(buf, sizeof(buf), "SET sae_groups %s", val);
Jouni Malinen992a81e2017-08-22 13:57:47 +03002220 if (wpa_command(ifname, buf) != 0) {
2221 sigma_dut_print(dut, DUT_MSG_ERROR,
2222 "Failed to clear sae_groups");
2223 return -2;
2224 }
2225 }
2226
Jouni Malinen68143132017-09-02 02:34:08 +03002227 val = get_param(cmd, "InvalidSAEElement");
2228 if (val) {
2229 free(dut->sae_commit_override);
2230 dut->sae_commit_override = strdup(val);
2231 }
2232
Jouni Malinen4b3769d2019-10-10 16:20:29 +03002233 val = get_param(cmd, "PMKID_Include");
2234 if (val) {
2235 snprintf(buf, sizeof(buf), "SET sae_pmkid_in_assoc %d",
2236 get_enable_disable(val));
2237 wpa_command(intf, buf);
2238 }
2239
Jouni Malineneeb43d32019-12-06 17:40:07 +02002240 val = get_param(cmd, "IgnoreH2E_RSNXE_BSSMemSel");
2241 if (val) {
2242 snprintf(buf, sizeof(buf), "SET ignore_sae_h2e_only %d",
2243 get_enable_disable(val));
2244 wpa_command(intf, buf);
2245 }
2246
Jouni Malinenf2348d22019-12-07 11:52:55 +02002247 val = get_param(cmd, "ECGroupID_RGE");
2248 if (val) {
2249 snprintf(buf, sizeof(buf), "SET extra_sae_rejected_groups %s",
2250 val);
2251 wpa_command(intf, buf);
2252 }
2253
Jouni Malinen99e55022019-12-07 13:59:41 +02002254 val = get_param(cmd, "RSNXE_Content");
2255 if (val) {
2256 const char *param;
2257
2258 if (strncasecmp(val, "AssocReq:", 9) == 0) {
2259 val += 9;
2260 param = "rsnxe_override_assoc";
2261 } else if (strncasecmp(val, "EapolM2:", 8) == 0) {
2262 val += 8;
2263 param = "rsnxe_override_eapol";
2264 } else {
2265 send_resp(dut, conn, SIGMA_ERROR,
2266 "errorCode,Unsupported RSNXE_Content value");
2267 return STATUS_SENT_ERROR;
2268 }
2269 snprintf(buf, sizeof(buf), "SET %s %s", param, val);
2270 wpa_command(intf, buf);
2271 }
2272
Jouni Malinen11e55212019-11-22 21:46:59 +02002273 val = get_param(cmd, "sae_pwe");
2274 if (val) {
2275 if (strcasecmp(val, "h2e") == 0) {
2276 dut->sae_pwe = SAE_PWE_H2E;
Jouni Malinen7244a412019-12-07 11:54:10 +02002277 } else if (strcasecmp(val, "loop") == 0 ||
2278 strcasecmp(val, "looping") == 0) {
Jouni Malinen11e55212019-11-22 21:46:59 +02002279 dut->sae_pwe = SAE_PWE_LOOP;
2280 } else {
2281 send_resp(dut, conn, SIGMA_ERROR,
2282 "errorCode,Unsupported sae_pwe value");
2283 return STATUS_SENT_ERROR;
2284 }
2285 }
Vinita S. Maloo6d7454f2020-04-02 15:03:26 +05302286
2287 val = get_param(cmd, "Clear_RSNXE");
2288 if (val && strcmp(val, "1") == 0 &&
2289 (wpa_command(intf, "SET rsnxe_override_assoc ") ||
2290 wpa_command(intf, "SET rsnxe_override_eapol "))) {
2291 send_resp(dut, conn, SIGMA_ERROR,
2292 "errorCode,Failed to clear RSNXE");
Jouni Malinenb11498c2020-08-03 11:05:53 +03002293 return STATUS_SENT_ERROR;
Vinita S. Maloo6d7454f2020-04-02 15:03:26 +05302294 }
2295
Jouni Malinenc0078772020-03-04 21:23:16 +02002296 if (dut->sae_pwe == SAE_PWE_LOOP && get_param(cmd, "PasswordId"))
2297 sae_pwe = 3;
2298 else if (dut->sae_pwe == SAE_PWE_LOOP)
Jouni Malinen11e55212019-11-22 21:46:59 +02002299 sae_pwe = 0;
2300 else if (dut->sae_pwe == SAE_PWE_H2E)
2301 sae_pwe = 1;
2302 else if (dut->sae_h2e_default)
2303 sae_pwe = 2;
2304 snprintf(buf, sizeof(buf), "SET sae_pwe %d", sae_pwe);
2305 if (sae_pwe >= 0 && wpa_command(ifname, buf) != 0)
2306 return ERROR_SEND_STATUS;
2307
Veerendranath Jakkam0316be12020-06-23 20:11:41 +05302308 val = get_param(cmd, "sae_pk");
2309 if (val && strcmp(val, "0") == 0 &&
2310 set_network(ifname, id, "sae_pk", "2") < 0)
2311 return ERROR_SEND_STATUS;
2312
Veerendranath Jakkama9177042020-08-10 00:14:03 +05302313 val = get_param(cmd, "sae_pk_only");
2314 if (val && strcmp(val, "1") == 0 &&
2315 set_network(ifname, id, "sae_pk", "1") < 0)
2316 return ERROR_SEND_STATUS;
2317
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002318 if (dut->program == PROGRAM_60GHZ && network_mode &&
2319 strcasecmp(network_mode, "PBSS") == 0 &&
2320 set_network(ifname, id, "pbss", "1") < 0)
2321 return -2;
2322
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002323 return 1;
2324}
2325
2326
Jouni Malinen8ac93452019-08-14 15:19:13 +03002327static enum sigma_cmd_result set_trust_root_system(struct sigma_dut *dut,
2328 struct sigma_conn *conn,
2329 const char *ifname, int id)
2330{
2331 char buf[200];
2332
2333 snprintf(buf, sizeof(buf), "%s/certs", sigma_cert_path);
2334 if (!file_exists(buf))
2335 strlcpy(buf, "/system/etc/security/cacerts", sizeof(buf));
2336 if (!file_exists(buf))
2337 strlcpy(buf, "/etc/ssl/certs", sizeof(buf));
2338 if (!file_exists(buf)) {
2339 char msg[300];
2340
2341 snprintf(msg, sizeof(msg),
2342 "ErrorCode,trustedRootCA system store (%s) not found",
2343 buf);
2344 send_resp(dut, conn, SIGMA_ERROR, msg);
2345 return STATUS_SENT_ERROR;
2346 }
2347
2348 if (set_network_quoted(ifname, id, "ca_path", buf) < 0)
2349 return ERROR_SEND_STATUS;
2350
2351 return SUCCESS_SEND_STATUS;
2352}
2353
2354
2355static enum sigma_cmd_result set_trust_root(struct sigma_dut *dut,
2356 struct sigma_conn *conn,
2357 const char *ifname, int id,
2358 const char *val)
2359{
2360 char buf[200];
2361#ifdef ANDROID
2362 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
2363 int length;
2364#endif /* ANDROID */
2365
2366 if (strcmp(val, "DEFAULT") == 0)
2367 return set_trust_root_system(dut, conn, ifname, id);
2368
2369#ifdef ANDROID
2370 snprintf(buf, sizeof(buf), "CACERT_%s", val);
2371 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
2372 if (length > 0) {
2373 sigma_dut_print(dut, DUT_MSG_INFO, "Use Android keystore [%s]",
2374 buf);
2375 snprintf(buf, sizeof(buf), "keystore://CACERT_%s", val);
2376 goto ca_cert_selected;
2377 }
2378#endif /* ANDROID */
2379
2380 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
2381#ifdef __linux__
2382 if (!file_exists(buf)) {
2383 char msg[300];
2384
2385 snprintf(msg, sizeof(msg),
2386 "ErrorCode,trustedRootCA file (%s) not found", buf);
2387 send_resp(dut, conn, SIGMA_ERROR, msg);
2388 return STATUS_SENT_ERROR;
2389 }
2390#endif /* __linux__ */
2391#ifdef ANDROID
2392ca_cert_selected:
2393#endif /* ANDROID */
2394 if (set_network_quoted(ifname, id, "ca_cert", buf) < 0)
2395 return ERROR_SEND_STATUS;
2396
2397 return SUCCESS_SEND_STATUS;
2398}
2399
2400
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002401static int set_eap_common(struct sigma_dut *dut, struct sigma_conn *conn,
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302402 const char *ifname, int username_identity,
2403 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002404{
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002405 const char *val, *alg, *akm, *trust_root, *domain, *domain_suffix;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002406 int id;
Jouni Malinen53264f62019-05-03 13:04:40 +03002407 char buf[200], buf2[300];
Jouni Malinen8179fee2019-03-28 03:19:47 +02002408 int erp = 0;
Jouni Malinen8ac93452019-08-14 15:19:13 +03002409 enum sigma_cmd_result res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002410
2411 id = set_wpa_common(dut, conn, ifname, cmd);
2412 if (id < 0)
2413 return id;
2414
2415 val = get_param(cmd, "keyMgmtType");
2416 alg = get_param(cmd, "micAlg");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302417 akm = get_param(cmd, "AKMSuiteType");
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002418 trust_root = get_param(cmd, "trustedRootCA");
2419 domain = get_param(cmd, "Domain");
2420 domain_suffix = get_param(cmd, "DomainSuffix");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002421
Jouni Malinenad395a22017-09-01 21:13:46 +03002422 if (val && strcasecmp(val, "SuiteB") == 0) {
2423 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SUITE-B-192") <
2424 0)
2425 return -2;
2426 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002427 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SHA256") < 0)
2428 return -2;
2429 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
2430 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
2431 return -2;
2432 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
2433 if (set_network(ifname, id, "key_mgmt", "FT-EAP") < 0)
2434 return -2;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002435 } else if (!akm &&
2436 ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
2437 dut->sta_pmf == STA_PMF_REQUIRED)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002438 if (set_network(ifname, id, "key_mgmt",
2439 "WPA-EAP WPA-EAP-SHA256") < 0)
2440 return -2;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302441 } else if (akm && atoi(akm) == 14) {
2442 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
2443 dut->sta_pmf == STA_PMF_REQUIRED) {
2444 if (set_network(ifname, id, "key_mgmt",
2445 "WPA-EAP-SHA256 FILS-SHA256") < 0)
2446 return -2;
2447 } else {
2448 if (set_network(ifname, id, "key_mgmt",
2449 "WPA-EAP FILS-SHA256") < 0)
2450 return -2;
2451 }
2452
Jouni Malinen8179fee2019-03-28 03:19:47 +02002453 erp = 1;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302454 } else if (akm && atoi(akm) == 15) {
2455 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
2456 dut->sta_pmf == STA_PMF_REQUIRED) {
2457 if (set_network(ifname, id, "key_mgmt",
2458 "WPA-EAP-SHA256 FILS-SHA384") < 0)
2459 return -2;
2460 } else {
2461 if (set_network(ifname, id, "key_mgmt",
2462 "WPA-EAP FILS-SHA384") < 0)
2463 return -2;
2464 }
2465
Jouni Malinen8179fee2019-03-28 03:19:47 +02002466 erp = 1;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002467 } else if (!akm && dut->sta_pmf == STA_PMF_OPTIONAL) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002468 if (set_network(ifname, id, "key_mgmt",
2469 "WPA-EAP WPA-EAP-SHA256") < 0)
2470 return -2;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002471 } else if (!akm) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002472 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
2473 return -2;
2474 }
2475
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002476 if (trust_root) {
2477 if (strcmp(trust_root, "DEFAULT") == 0 && !domain &&
2478 !domain_suffix) {
2479 send_resp(dut, conn, SIGMA_ERROR,
2480 "errorCode,trustRootCA DEFAULT used without specifying Domain or DomainSuffix");
2481 return STATUS_SENT_ERROR;
2482 }
2483 res = set_trust_root(dut, conn, ifname, id, trust_root);
Jouni Malinen8ac93452019-08-14 15:19:13 +03002484 if (res != SUCCESS_SEND_STATUS)
2485 return res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002486 }
2487
Jouni Malinen53264f62019-05-03 13:04:40 +03002488 val = get_param(cmd, "ServerCert");
2489 if (val) {
2490 FILE *f;
2491 char *result = NULL, *pos;
2492
2493 snprintf(buf, sizeof(buf), "%s/%s.sha256", sigma_cert_path,
2494 val);
2495 f = fopen(buf, "r");
2496 if (f) {
2497 result = fgets(buf, sizeof(buf), f);
2498 fclose(f);
2499 }
2500 if (!result) {
2501 snprintf(buf2, sizeof(buf2),
2502 "ErrorCode,ServerCert hash could not be read from %s",
2503 buf);
2504 send_resp(dut, conn, SIGMA_ERROR, buf2);
2505 return STATUS_SENT_ERROR;
2506 }
2507 pos = strchr(buf, '\n');
2508 if (pos)
2509 *pos = '\0';
Jouni Malinen0572a742020-10-08 13:53:25 +03002510 pos = strchr(buf, '\r');
2511 if (pos)
2512 *pos = '\0';
Jouni Malinen53264f62019-05-03 13:04:40 +03002513 snprintf(buf2, sizeof(buf2), "hash://server/sha256/%s", buf);
2514 if (set_network_quoted(ifname, id, "ca_cert", buf2) < 0)
2515 return ERROR_SEND_STATUS;
Jouni Malinen29108dc2019-06-13 23:42:11 +03002516
2517 snprintf(buf, sizeof(buf), "%s/%s.tod", sigma_cert_path, val);
2518 if (file_exists(buf)) {
2519 sigma_dut_print(dut, DUT_MSG_DEBUG,
2520 "TOD policy enabled for the configured ServerCert hash");
2521 dut->sta_tod_policy = 1;
2522 }
Jouni Malinen53264f62019-05-03 13:04:40 +03002523 }
2524
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002525 if (domain &&
2526 set_network_quoted(ifname, id, "domain_match", domain) < 0)
Jouni Malinen96f84b02019-05-03 12:32:56 +03002527 return ERROR_SEND_STATUS;
2528
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002529 if (domain_suffix &&
2530 set_network_quoted(ifname, id, "domain_suffix_match",
2531 domain_suffix) < 0)
Jouni Malinen96f84b02019-05-03 12:32:56 +03002532 return ERROR_SEND_STATUS;
2533
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302534 if (username_identity) {
2535 val = get_param(cmd, "username");
2536 if (val) {
2537 if (set_network_quoted(ifname, id, "identity", val) < 0)
2538 return -2;
2539 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002540
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302541 val = get_param(cmd, "password");
2542 if (val) {
2543 if (set_network_quoted(ifname, id, "password", val) < 0)
2544 return -2;
2545 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002546 }
2547
Jouni Malinen8179fee2019-03-28 03:19:47 +02002548 if (dut->akm_values &
2549 ((1 << AKM_FILS_SHA256) |
2550 (1 << AKM_FILS_SHA384) |
2551 (1 << AKM_FT_FILS_SHA256) |
2552 (1 << AKM_FT_FILS_SHA384)))
2553 erp = 1;
2554 if (erp && set_network(ifname, id, "erp", "1") < 0)
2555 return ERROR_SEND_STATUS;
2556
Jouni Malinen134fe3c2019-06-12 04:16:49 +03002557 dut->sta_associate_wait_connect = 1;
2558
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002559 return id;
2560}
2561
2562
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002563static int set_tls_cipher(const char *ifname, int id, const char *cipher)
2564{
2565 const char *val;
2566
2567 if (!cipher)
2568 return 0;
2569
2570 if (strcasecmp(cipher, "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384") == 0)
2571 val = "ECDHE-ECDSA-AES256-GCM-SHA384";
2572 else if (strcasecmp(cipher,
2573 "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
2574 val = "ECDHE-RSA-AES256-GCM-SHA384";
2575 else if (strcasecmp(cipher, "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
2576 val = "DHE-RSA-AES256-GCM-SHA384";
2577 else if (strcasecmp(cipher,
2578 "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256") == 0)
2579 val = "ECDHE-ECDSA-AES128-GCM-SHA256";
2580 else
2581 return -1;
2582
2583 /* Need to clear phase1="tls_suiteb=1" to allow cipher enforcement */
2584 set_network_quoted(ifname, id, "phase1", "");
2585
2586 return set_network_quoted(ifname, id, "openssl_ciphers", val);
2587}
2588
2589
Jouni Malinenf7222712019-06-13 01:50:21 +03002590static enum sigma_cmd_result cmd_sta_set_eaptls(struct sigma_dut *dut,
2591 struct sigma_conn *conn,
2592 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002593{
2594 const char *intf = get_param(cmd, "Interface");
2595 const char *ifname, *val;
2596 int id;
2597 char buf[200];
2598#ifdef ANDROID
2599 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
2600 int length;
2601 int jb_or_newer = 0;
2602 char prop[PROPERTY_VALUE_MAX];
2603#endif /* ANDROID */
2604
2605 if (intf == NULL)
2606 return -1;
2607
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002608 if (strcmp(intf, get_main_ifname(dut)) == 0)
2609 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002610 else
2611 ifname = intf;
2612
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302613 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002614 if (id < 0)
2615 return id;
2616
2617 if (set_network(ifname, id, "eap", "TLS") < 0)
2618 return -2;
2619
Pradeep Reddy POTTETI9f6c2132016-05-05 16:28:19 +05302620 if (!get_param(cmd, "username") &&
2621 set_network_quoted(ifname, id, "identity",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002622 "wifi-user@wifilabs.local") < 0)
2623 return -2;
2624
2625 val = get_param(cmd, "clientCertificate");
2626 if (val == NULL)
2627 return -1;
2628#ifdef ANDROID
2629 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2630 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
2631 if (length < 0) {
2632 /*
2633 * JB started reporting keystore type mismatches, so retry with
2634 * the GET_PUBKEY command if the generic GET fails.
2635 */
2636 length = android_keystore_get(ANDROID_KEYSTORE_GET_PUBKEY,
2637 buf, kvalue);
2638 }
2639
2640 if (property_get("ro.build.version.release", prop, NULL) != 0) {
2641 sigma_dut_print(dut, DUT_MSG_DEBUG, "Android release %s", prop);
2642 if (strncmp(prop, "4.0", 3) != 0)
2643 jb_or_newer = 1;
2644 } else
2645 jb_or_newer = 1; /* assume newer */
2646
2647 if (jb_or_newer && length > 0) {
2648 sigma_dut_print(dut, DUT_MSG_INFO,
2649 "Use Android keystore [%s]", buf);
2650 if (set_network(ifname, id, "engine", "1") < 0)
2651 return -2;
2652 if (set_network_quoted(ifname, id, "engine_id", "keystore") < 0)
2653 return -2;
2654 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2655 if (set_network_quoted(ifname, id, "key_id", buf) < 0)
2656 return -2;
2657 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2658 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2659 return -2;
2660 return 1;
2661 } else if (length > 0) {
2662 sigma_dut_print(dut, DUT_MSG_INFO,
2663 "Use Android keystore [%s]", buf);
2664 snprintf(buf, sizeof(buf), "keystore://USRPKEY_%s", val);
2665 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2666 return -2;
2667 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2668 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2669 return -2;
2670 return 1;
2671 }
2672#endif /* ANDROID */
2673
2674 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
2675#ifdef __linux__
2676 if (!file_exists(buf)) {
2677 char msg[300];
2678 snprintf(msg, sizeof(msg), "ErrorCode,clientCertificate file "
2679 "(%s) not found", buf);
2680 send_resp(dut, conn, SIGMA_ERROR, msg);
2681 return -3;
2682 }
2683#endif /* __linux__ */
2684 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2685 return -2;
2686 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2687 return -2;
2688
2689 if (set_network_quoted(ifname, id, "private_key_passwd", "wifi") < 0)
2690 return -2;
2691
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002692 val = get_param(cmd, "keyMgmtType");
2693 if (val && strcasecmp(val, "SuiteB") == 0) {
2694 val = get_param(cmd, "CertType");
2695 if (val && strcasecmp(val, "RSA") == 0) {
2696 if (set_network_quoted(ifname, id, "phase1",
2697 "tls_suiteb=1") < 0)
2698 return -2;
2699 } else {
2700 if (set_network_quoted(ifname, id, "openssl_ciphers",
2701 "SUITEB192") < 0)
2702 return -2;
2703 }
2704
2705 val = get_param(cmd, "TLSCipher");
2706 if (set_tls_cipher(ifname, id, val) < 0) {
2707 send_resp(dut, conn, SIGMA_ERROR,
2708 "ErrorCode,Unsupported TLSCipher value");
2709 return -3;
2710 }
2711 }
2712
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002713 return 1;
2714}
2715
2716
Jouni Malinenf7222712019-06-13 01:50:21 +03002717static enum sigma_cmd_result cmd_sta_set_eapttls(struct sigma_dut *dut,
2718 struct sigma_conn *conn,
2719 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002720{
2721 const char *intf = get_param(cmd, "Interface");
2722 const char *ifname;
2723 int id;
2724
2725 if (intf == NULL)
2726 return -1;
2727
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002728 if (strcmp(intf, get_main_ifname(dut)) == 0)
2729 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002730 else
2731 ifname = intf;
2732
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302733 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002734 if (id < 0)
2735 return id;
2736
2737 if (set_network(ifname, id, "eap", "TTLS") < 0) {
2738 send_resp(dut, conn, SIGMA_ERROR,
2739 "errorCode,Failed to set TTLS method");
2740 return 0;
2741 }
2742
2743 if (set_network_quoted(ifname, id, "phase2", "auth=MSCHAPV2") < 0) {
2744 send_resp(dut, conn, SIGMA_ERROR,
2745 "errorCode,Failed to set MSCHAPv2 for TTLS Phase 2");
2746 return 0;
2747 }
2748
2749 return 1;
2750}
2751
2752
Jouni Malinenf7222712019-06-13 01:50:21 +03002753static enum sigma_cmd_result cmd_sta_set_eapsim(struct sigma_dut *dut,
2754 struct sigma_conn *conn,
2755 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002756{
2757 const char *intf = get_param(cmd, "Interface");
2758 const char *ifname;
2759 int id;
2760
2761 if (intf == NULL)
2762 return -1;
2763
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002764 if (strcmp(intf, get_main_ifname(dut)) == 0)
2765 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002766 else
2767 ifname = intf;
2768
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302769 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002770 if (id < 0)
2771 return id;
2772
2773 if (set_network(ifname, id, "eap", "SIM") < 0)
2774 return -2;
2775
2776 return 1;
2777}
2778
2779
Jouni Malinenf7222712019-06-13 01:50:21 +03002780static enum sigma_cmd_result cmd_sta_set_peap(struct sigma_dut *dut,
2781 struct sigma_conn *conn,
2782 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002783{
2784 const char *intf = get_param(cmd, "Interface");
2785 const char *ifname, *val;
2786 int id;
2787 char buf[100];
2788
2789 if (intf == NULL)
2790 return -1;
2791
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002792 if (strcmp(intf, get_main_ifname(dut)) == 0)
2793 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002794 else
2795 ifname = intf;
2796
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302797 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002798 if (id < 0)
2799 return id;
2800
2801 if (set_network(ifname, id, "eap", "PEAP") < 0)
2802 return -2;
2803
2804 val = get_param(cmd, "innerEAP");
2805 if (val) {
2806 if (strcasecmp(val, "MSCHAPv2") == 0) {
2807 if (set_network_quoted(ifname, id, "phase2",
2808 "auth=MSCHAPV2") < 0)
2809 return -2;
2810 } else if (strcasecmp(val, "GTC") == 0) {
2811 if (set_network_quoted(ifname, id, "phase2",
2812 "auth=GTC") < 0)
2813 return -2;
2814 } else
2815 return -1;
2816 }
2817
2818 val = get_param(cmd, "peapVersion");
2819 if (val) {
2820 int ver = atoi(val);
2821 if (ver < 0 || ver > 1)
2822 return -1;
2823 snprintf(buf, sizeof(buf), "peapver=%d", ver);
2824 if (set_network_quoted(ifname, id, "phase1", buf) < 0)
2825 return -2;
2826 }
2827
2828 return 1;
2829}
2830
2831
Jouni Malinenf7222712019-06-13 01:50:21 +03002832static enum sigma_cmd_result cmd_sta_set_eapfast(struct sigma_dut *dut,
2833 struct sigma_conn *conn,
2834 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002835{
2836 const char *intf = get_param(cmd, "Interface");
2837 const char *ifname, *val;
2838 int id;
2839 char buf[100];
2840
2841 if (intf == NULL)
2842 return -1;
2843
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002844 if (strcmp(intf, get_main_ifname(dut)) == 0)
2845 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002846 else
2847 ifname = intf;
2848
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302849 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002850 if (id < 0)
2851 return id;
2852
2853 if (set_network(ifname, id, "eap", "FAST") < 0)
2854 return -2;
2855
2856 val = get_param(cmd, "innerEAP");
2857 if (val) {
2858 if (strcasecmp(val, "MSCHAPV2") == 0) {
2859 if (set_network_quoted(ifname, id, "phase2",
2860 "auth=MSCHAPV2") < 0)
2861 return -2;
2862 } else if (strcasecmp(val, "GTC") == 0) {
2863 if (set_network_quoted(ifname, id, "phase2",
2864 "auth=GTC") < 0)
2865 return -2;
2866 } else
2867 return -1;
2868 }
2869
2870 val = get_param(cmd, "validateServer");
2871 if (val) {
2872 /* TODO */
2873 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored EAP-FAST "
2874 "validateServer=%s", val);
2875 }
2876
2877 val = get_param(cmd, "pacFile");
2878 if (val) {
2879 snprintf(buf, sizeof(buf), "blob://%s", val);
2880 if (set_network_quoted(ifname, id, "pac_file", buf) < 0)
2881 return -2;
2882 }
2883
2884 if (set_network_quoted(ifname, id, "phase1", "fast_provisioning=2") <
2885 0)
2886 return -2;
2887
2888 return 1;
2889}
2890
2891
Jouni Malinenf7222712019-06-13 01:50:21 +03002892static enum sigma_cmd_result cmd_sta_set_eapaka(struct sigma_dut *dut,
2893 struct sigma_conn *conn,
2894 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002895{
2896 const char *intf = get_param(cmd, "Interface");
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302897 const char *username = get_param(cmd, "Username");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002898 const char *ifname;
2899 int id;
2900
2901 if (intf == NULL)
2902 return -1;
2903
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002904 if (strcmp(intf, get_main_ifname(dut)) == 0)
2905 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002906 else
2907 ifname = intf;
2908
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302909 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002910 if (id < 0)
2911 return id;
2912
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302913 /* RFC 5448: EAP-AKA' MUST use the leading character "6" (ASCII 36
2914 * hexadecimal).
2915 */
2916 if (username && username[0] == '6') {
2917 if (set_network(ifname, id, "eap", "AKA'") < 0)
2918 return -2;
2919 } else if (set_network(ifname, id, "eap", "AKA") < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002920 return -2;
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302921 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002922
2923 return 1;
2924}
2925
2926
Jouni Malinenf7222712019-06-13 01:50:21 +03002927static enum sigma_cmd_result cmd_sta_set_eapakaprime(struct sigma_dut *dut,
2928 struct sigma_conn *conn,
2929 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002930{
2931 const char *intf = get_param(cmd, "Interface");
2932 const char *ifname;
2933 int id;
2934
2935 if (intf == NULL)
2936 return -1;
2937
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002938 if (strcmp(intf, get_main_ifname(dut)) == 0)
2939 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002940 else
2941 ifname = intf;
2942
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302943 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002944 if (id < 0)
2945 return id;
2946
2947 if (set_network(ifname, id, "eap", "AKA'") < 0)
2948 return -2;
2949
2950 return 1;
2951}
2952
2953
2954static int sta_set_open(struct sigma_dut *dut, struct sigma_conn *conn,
2955 struct sigma_cmd *cmd)
2956{
2957 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002958 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002959 const char *ifname;
2960 int id;
2961
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002962 if (strcmp(intf, get_main_ifname(dut)) == 0)
2963 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002964 else
2965 ifname = intf;
2966
2967 id = add_network_common(dut, conn, ifname, cmd);
2968 if (id < 0)
2969 return id;
2970
2971 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
2972 return -2;
2973
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002974 if (dut->program == PROGRAM_60GHZ && network_mode &&
2975 strcasecmp(network_mode, "PBSS") == 0 &&
2976 set_network(ifname, id, "pbss", "1") < 0)
2977 return -2;
2978
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002979 return 1;
2980}
2981
2982
Jouni Malinen8e3f8812020-10-05 10:02:03 +03002983static enum sigma_cmd_result sta_set_owe(struct sigma_dut *dut,
2984 struct sigma_conn *conn,
2985 struct sigma_cmd *cmd)
Jouni Malinen47dcc952017-10-09 16:43:24 +03002986{
2987 const char *intf = get_param(cmd, "Interface");
2988 const char *ifname, *val;
2989 int id;
2990
2991 if (intf == NULL)
Jouni Malinen8e3f8812020-10-05 10:02:03 +03002992 return INVALID_SEND_STATUS;
Jouni Malinen47dcc952017-10-09 16:43:24 +03002993
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002994 if (strcmp(intf, get_main_ifname(dut)) == 0)
2995 ifname = get_station_ifname(dut);
Jouni Malinen47dcc952017-10-09 16:43:24 +03002996 else
2997 ifname = intf;
2998
2999 id = set_wpa_common(dut, conn, ifname, cmd);
3000 if (id < 0)
3001 return id;
3002
3003 if (set_network(ifname, id, "key_mgmt", "OWE") < 0)
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003004 return ERROR_SEND_STATUS;
Jouni Malinen47dcc952017-10-09 16:43:24 +03003005
Hu Wangdd5eed22020-07-16 12:18:03 +08003006 if (dut->owe_ptk_workaround &&
3007 set_network(ifname, id, "owe_ptk_workaround", "1") < 0) {
3008 sigma_dut_print(dut, DUT_MSG_ERROR,
3009 "Failed to set owe_ptk_workaround to 1");
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003010 return ERROR_SEND_STATUS;
Hu Wangdd5eed22020-07-16 12:18:03 +08003011 }
3012
Jouni Malinen47dcc952017-10-09 16:43:24 +03003013 val = get_param(cmd, "ECGroupID");
Jouni Malinenfac9cad2017-10-10 18:35:55 +03003014 if (val && strcmp(val, "0") == 0) {
3015 if (wpa_command(ifname,
3016 "VENDOR_ELEM_ADD 13 ff23200000783590fb7440e03d5b3b33911f86affdcc6b4411b707846ac4ff08ddc8831ccd") != 0) {
3017 sigma_dut_print(dut, DUT_MSG_ERROR,
3018 "Failed to set OWE DH Param element override");
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003019 return ERROR_SEND_STATUS;
Jouni Malinenfac9cad2017-10-10 18:35:55 +03003020 }
Hu Wangdd5eed22020-07-16 12:18:03 +08003021 } else if (val && set_network(ifname, id, "owe_group", val) < 0) {
Jouni Malinen47dcc952017-10-09 16:43:24 +03003022 sigma_dut_print(dut, DUT_MSG_ERROR,
Hu Wang6010ce72020-03-05 19:33:53 +08003023 "Failed to set owe_group");
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003024 return ERROR_SEND_STATUS;
Jouni Malinen47dcc952017-10-09 16:43:24 +03003025 }
3026
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003027 return SUCCESS_SEND_STATUS;
Jouni Malinen47dcc952017-10-09 16:43:24 +03003028}
3029
3030
Jouni Malinenf7222712019-06-13 01:50:21 +03003031static enum sigma_cmd_result cmd_sta_set_security(struct sigma_dut *dut,
3032 struct sigma_conn *conn,
3033 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003034{
3035 const char *type = get_param(cmd, "Type");
3036
3037 if (type == NULL) {
3038 send_resp(dut, conn, SIGMA_ERROR,
3039 "ErrorCode,Missing Type argument");
3040 return 0;
3041 }
3042
3043 if (strcasecmp(type, "OPEN") == 0)
3044 return sta_set_open(dut, conn, cmd);
Jouni Malinen47dcc952017-10-09 16:43:24 +03003045 if (strcasecmp(type, "OWE") == 0)
3046 return sta_set_owe(dut, conn, cmd);
Jouni Malinen992a81e2017-08-22 13:57:47 +03003047 if (strcasecmp(type, "PSK") == 0 ||
Jouni Malinen0ab50f42017-08-31 01:34:59 +03003048 strcasecmp(type, "PSK-SAE") == 0 ||
Jouni Malinen992a81e2017-08-22 13:57:47 +03003049 strcasecmp(type, "SAE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003050 return cmd_sta_set_psk(dut, conn, cmd);
3051 if (strcasecmp(type, "EAPTLS") == 0)
3052 return cmd_sta_set_eaptls(dut, conn, cmd);
3053 if (strcasecmp(type, "EAPTTLS") == 0)
3054 return cmd_sta_set_eapttls(dut, conn, cmd);
3055 if (strcasecmp(type, "EAPPEAP") == 0)
3056 return cmd_sta_set_peap(dut, conn, cmd);
3057 if (strcasecmp(type, "EAPSIM") == 0)
3058 return cmd_sta_set_eapsim(dut, conn, cmd);
3059 if (strcasecmp(type, "EAPFAST") == 0)
3060 return cmd_sta_set_eapfast(dut, conn, cmd);
3061 if (strcasecmp(type, "EAPAKA") == 0)
3062 return cmd_sta_set_eapaka(dut, conn, cmd);
3063 if (strcasecmp(type, "EAPAKAPRIME") == 0)
3064 return cmd_sta_set_eapakaprime(dut, conn, cmd);
Amarnath Hullur Subramanyam81b11cd2018-01-30 19:07:17 -08003065 if (strcasecmp(type, "wep") == 0)
3066 return cmd_sta_set_encryption(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003067
3068 send_resp(dut, conn, SIGMA_ERROR,
3069 "ErrorCode,Unsupported Type value");
3070 return 0;
3071}
3072
3073
3074int ath6kl_client_uapsd(struct sigma_dut *dut, const char *intf, int uapsd)
3075{
3076#ifdef __linux__
3077 /* special handling for ath6kl */
3078 char path[128], fname[128], *pos;
3079 ssize_t res;
3080 FILE *f;
3081
Jouni Malinene39cd562019-05-29 23:39:56 +03003082 res = snprintf(fname, sizeof(fname), "/sys/class/net/%s/phy80211",
3083 intf);
3084 if (res < 0 || res >= sizeof(fname))
3085 return 0;
3086 res = readlink(fname, path, sizeof(path));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003087 if (res < 0)
3088 return 0; /* not ath6kl */
3089
3090 if (res >= (int) sizeof(path))
3091 res = sizeof(path) - 1;
3092 path[res] = '\0';
3093 pos = strrchr(path, '/');
3094 if (pos == NULL)
3095 pos = path;
3096 else
3097 pos++;
Jouni Malinen77dda642020-01-07 11:21:55 +02003098 res = snprintf(fname, sizeof(fname),
3099 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
3100 "create_qos", pos);
3101 if (res < 0 || res >= sizeof(fname) || !file_exists(fname))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003102 return 0; /* not ath6kl */
3103
3104 if (uapsd) {
3105 f = fopen(fname, "w");
3106 if (f == NULL)
3107 return -1;
3108
3109 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl create_qos");
3110 fprintf(f, "4 2 2 1 2 9999999 9999999 9999999 7777777 0 4 "
3111 "45000 200 56789000 56789000 5678900 0 0 9999999 "
3112 "20000 0\n");
3113 fclose(f);
3114 } else {
Jouni Malinen77dda642020-01-07 11:21:55 +02003115 res = snprintf(fname, sizeof(fname),
3116 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
3117 "delete_qos", pos);
3118 if (res < 0 || res >= sizeof(fname))
3119 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003120
3121 f = fopen(fname, "w");
3122 if (f == NULL)
3123 return -1;
3124
3125 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl delete_qos");
3126 fprintf(f, "2 4\n");
3127 fclose(f);
3128 }
3129#endif /* __linux__ */
3130
3131 return 0;
3132}
3133
3134
Jouni Malinenf7222712019-06-13 01:50:21 +03003135static enum sigma_cmd_result cmd_sta_set_uapsd(struct sigma_dut *dut,
3136 struct sigma_conn *conn,
3137 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003138{
3139 const char *intf = get_param(cmd, "Interface");
3140 /* const char *ssid = get_param(cmd, "ssid"); */
3141 const char *val;
3142 int max_sp_len = 4;
3143 int ac_be = 1, ac_bk = 1, ac_vi = 1, ac_vo = 1;
3144 char buf[100];
3145 int ret1, ret2;
3146
3147 val = get_param(cmd, "maxSPLength");
3148 if (val) {
3149 max_sp_len = atoi(val);
3150 if (max_sp_len != 0 && max_sp_len != 1 && max_sp_len != 2 &&
3151 max_sp_len != 4)
3152 return -1;
3153 }
3154
3155 val = get_param(cmd, "acBE");
3156 if (val)
3157 ac_be = atoi(val);
3158
3159 val = get_param(cmd, "acBK");
3160 if (val)
3161 ac_bk = atoi(val);
3162
3163 val = get_param(cmd, "acVI");
3164 if (val)
3165 ac_vi = atoi(val);
3166
3167 val = get_param(cmd, "acVO");
3168 if (val)
3169 ac_vo = atoi(val);
3170
3171 dut->client_uapsd = ac_be || ac_bk || ac_vi || ac_vo;
3172
3173 snprintf(buf, sizeof(buf), "P2P_SET client_apsd %d,%d,%d,%d;%d",
3174 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
3175 ret1 = wpa_command(intf, buf);
3176
3177 snprintf(buf, sizeof(buf), "SET uapsd %d,%d,%d,%d;%d",
3178 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
3179 ret2 = wpa_command(intf, buf);
3180
3181 if (ret1 && ret2) {
3182 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to set client mode "
3183 "UAPSD parameters.");
3184 return -2;
3185 }
3186
3187 if (ath6kl_client_uapsd(dut, intf, dut->client_uapsd) < 0) {
3188 send_resp(dut, conn, SIGMA_ERROR,
3189 "ErrorCode,Failed to set ath6kl QoS parameters");
3190 return 0;
3191 }
3192
3193 return 1;
3194}
3195
3196
Jouni Malinenf7222712019-06-13 01:50:21 +03003197static enum sigma_cmd_result cmd_sta_set_wmm(struct sigma_dut *dut,
3198 struct sigma_conn *conn,
3199 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003200{
3201 char buf[1000];
3202 const char *intf = get_param(cmd, "Interface");
3203 const char *grp = get_param(cmd, "Group");
3204 const char *act = get_param(cmd, "Action");
3205 const char *tid = get_param(cmd, "Tid");
3206 const char *dir = get_param(cmd, "Direction");
3207 const char *psb = get_param(cmd, "Psb");
3208 const char *up = get_param(cmd, "Up");
3209 const char *fixed = get_param(cmd, "Fixed");
3210 const char *size = get_param(cmd, "Size");
3211 const char *msize = get_param(cmd, "Maxsize");
3212 const char *minsi = get_param(cmd, "Min_srvc_intrvl");
3213 const char *maxsi = get_param(cmd, "Max_srvc_intrvl");
3214 const char *inact = get_param(cmd, "Inactivity");
3215 const char *sus = get_param(cmd, "Suspension");
3216 const char *mindr = get_param(cmd, "Mindatarate");
3217 const char *meandr = get_param(cmd, "Meandatarate");
3218 const char *peakdr = get_param(cmd, "Peakdatarate");
3219 const char *phyrate = get_param(cmd, "Phyrate");
3220 const char *burstsize = get_param(cmd, "Burstsize");
3221 const char *sba = get_param(cmd, "Sba");
3222 int direction;
3223 int handle;
Peng Xu93319622017-10-04 17:58:16 -07003224 float sba_fv = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003225 int fixed_int;
3226 int psb_ts;
3227
3228 if (intf == NULL || grp == NULL || act == NULL )
3229 return -1;
3230
3231 if (strcasecmp(act, "addts") == 0) {
3232 if (tid == NULL || dir == NULL || psb == NULL ||
3233 up == NULL || fixed == NULL || size == NULL)
3234 return -1;
3235
3236 /*
3237 * Note: Sigma CAPI spec lists uplink, downlink, and bidi as the
3238 * possible values, but WMM-AC and V-E test scripts use "UP,
3239 * "DOWN", and "BIDI".
3240 */
3241 if (strcasecmp(dir, "uplink") == 0 ||
3242 strcasecmp(dir, "up") == 0) {
3243 direction = 0;
3244 } else if (strcasecmp(dir, "downlink") == 0 ||
3245 strcasecmp(dir, "down") == 0) {
3246 direction = 1;
3247 } else if (strcasecmp(dir, "bidi") == 0) {
3248 direction = 2;
3249 } else {
3250 sigma_dut_print(dut, DUT_MSG_ERROR,
3251 "Direction %s not supported", dir);
3252 return -1;
3253 }
3254
3255 if (strcasecmp(psb, "legacy") == 0) {
3256 psb_ts = 0;
3257 } else if (strcasecmp(psb, "uapsd") == 0) {
3258 psb_ts = 1;
3259 } else {
3260 sigma_dut_print(dut, DUT_MSG_ERROR,
3261 "PSB %s not supported", psb);
3262 return -1;
3263 }
3264
3265 if (atoi(tid) < 0 || atoi(tid) > 7) {
3266 sigma_dut_print(dut, DUT_MSG_ERROR,
3267 "TID %s not supported", tid);
3268 return -1;
3269 }
3270
3271 if (strcasecmp(fixed, "true") == 0) {
3272 fixed_int = 1;
3273 } else {
3274 fixed_int = 0;
3275 }
3276
Peng Xu93319622017-10-04 17:58:16 -07003277 if (sba)
3278 sba_fv = atof(sba);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003279
3280 dut->dialog_token++;
3281 handle = 7000 + dut->dialog_token;
3282
3283 /*
3284 * size: convert to hex
3285 * maxsi: convert to hex
3286 * mindr: convert to hex
3287 * meandr: convert to hex
3288 * peakdr: convert to hex
3289 * burstsize: convert to hex
3290 * phyrate: convert to hex
3291 * sba: convert to hex with modification
3292 * minsi: convert to integer
3293 * sus: convert to integer
3294 * inact: convert to integer
3295 * maxsi: convert to integer
3296 */
3297
3298 /*
3299 * The Nominal MSDU Size field is 2 octets long and contains an
3300 * unsigned integer that specifies the nominal size, in octets,
3301 * of MSDUs belonging to the traffic under this traffic
3302 * specification and is defined in Figure 16. If the Fixed
3303 * subfield is set to 1, then the size of the MSDU is fixed and
3304 * is indicated by the Size Subfield. If the Fixed subfield is
3305 * set to 0, then the size of the MSDU might not be fixed and
3306 * the Size indicates the nominal MSDU size.
3307 *
3308 * The Surplus Bandwidth Allowance Factor field is 2 octets long
3309 * and specifies the excess allocation of time (and bandwidth)
3310 * over and above the stated rates required to transport an MSDU
3311 * belonging to the traffic in this TSPEC. This field is
3312 * represented as an unsigned binary number with an implicit
3313 * binary point after the leftmost 3 bits. For example, an SBA
3314 * of 1.75 is represented as 0x3800. This field is included to
3315 * account for retransmissions. As such, the value of this field
3316 * must be greater than unity.
3317 */
3318
3319 snprintf(buf, sizeof(buf),
3320 "iwpriv %s addTspec %d %s %d %d %s 0x%X"
3321 " 0x%X 0x%X 0x%X"
3322 " 0x%X 0x%X 0x%X"
3323 " 0x%X %d %d %d %d"
3324 " %d %d",
3325 intf, handle, tid, direction, psb_ts, up,
3326 (unsigned int) ((fixed_int << 15) | atoi(size)),
3327 msize ? atoi(msize) : 0,
3328 mindr ? atoi(mindr) : 0,
3329 meandr ? atoi(meandr) : 0,
3330 peakdr ? atoi(peakdr) : 0,
3331 burstsize ? atoi(burstsize) : 0,
3332 phyrate ? atoi(phyrate) : 0,
3333 sba ? ((unsigned int) (((int) sba_fv << 13) |
3334 (int)((sba_fv - (int) sba_fv) *
3335 8192))) : 0,
3336 minsi ? atoi(minsi) : 0,
3337 sus ? atoi(sus) : 0,
3338 0, 0,
3339 inact ? atoi(inact) : 0,
3340 maxsi ? atoi(maxsi) : 0);
3341
3342 if (system(buf) != 0) {
3343 sigma_dut_print(dut, DUT_MSG_ERROR,
3344 "iwpriv addtspec request failed");
3345 send_resp(dut, conn, SIGMA_ERROR,
3346 "errorCode,Failed to execute addTspec command");
3347 return 0;
3348 }
3349
3350 sigma_dut_print(dut, DUT_MSG_INFO,
3351 "iwpriv addtspec request send");
3352
3353 /* Mapping handle to a TID */
3354 dut->tid_to_handle[atoi(tid)] = handle;
3355 } else if (strcasecmp(act, "delts") == 0) {
3356 if (tid == NULL)
3357 return -1;
3358
3359 if (atoi(tid) < 0 || atoi(tid) > 7) {
3360 sigma_dut_print(dut, DUT_MSG_ERROR,
3361 "TID %s not supported", tid);
3362 send_resp(dut, conn, SIGMA_ERROR,
3363 "errorCode,Unsupported TID");
3364 return 0;
3365 }
3366
3367 handle = dut->tid_to_handle[atoi(tid)];
3368
3369 if (handle < 7000 || handle > 7255) {
3370 /* Invalid handle ie no mapping for that TID */
3371 sigma_dut_print(dut, DUT_MSG_ERROR,
3372 "handle-> %d not found", handle);
3373 }
3374
3375 snprintf(buf, sizeof(buf), "iwpriv %s delTspec %d",
3376 intf, handle);
3377
3378 if (system(buf) != 0) {
3379 sigma_dut_print(dut, DUT_MSG_ERROR,
3380 "iwpriv deltspec request failed");
3381 send_resp(dut, conn, SIGMA_ERROR,
3382 "errorCode,Failed to execute delTspec command");
3383 return 0;
3384 }
3385
3386 sigma_dut_print(dut, DUT_MSG_INFO,
3387 "iwpriv deltspec request send");
3388
3389 dut->tid_to_handle[atoi(tid)] = 0;
3390 } else {
3391 sigma_dut_print(dut, DUT_MSG_ERROR,
3392 "Action type %s not supported", act);
3393 send_resp(dut, conn, SIGMA_ERROR,
3394 "errorCode,Unsupported Action");
3395 return 0;
3396 }
3397
3398 return 1;
3399}
3400
3401
vamsi krishna52e16f92017-08-29 12:37:34 +05303402static int find_network(struct sigma_dut *dut, const char *ssid)
3403{
3404 char list[4096];
3405 char *pos;
3406
3407 sigma_dut_print(dut, DUT_MSG_DEBUG,
3408 "Search for profile based on SSID: '%s'", ssid);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003409 if (wpa_command_resp(get_station_ifname(dut), "LIST_NETWORKS",
vamsi krishna52e16f92017-08-29 12:37:34 +05303410 list, sizeof(list)) < 0)
3411 return -1;
3412 pos = strstr(list, ssid);
3413 if (!pos || pos == list || pos[-1] != '\t' || pos[strlen(ssid)] != '\t')
3414 return -1;
3415
3416 while (pos > list && pos[-1] != '\n')
3417 pos--;
3418 dut->infra_network_id = atoi(pos);
3419 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
3420 return 0;
3421}
3422
3423
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303424/**
3425 * enum qca_sta_helper_config_params - This helper enum defines the config
3426 * parameters which can be delivered to sta.
3427 */
3428enum qca_sta_helper_config_params {
3429 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE */
3430 STA_SET_RSNIE,
3431
3432 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_LDPC */
3433 STA_SET_LDPC,
3434
3435 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_TX_STBC */
3436 STA_SET_TX_STBC,
3437
3438 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_RX_STBC */
3439 STA_SET_RX_STBC,
3440
3441 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_TX_MSDU_AGGREGATION */
3442 STA_SET_TX_MSDU,
3443
3444 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_RX_MSDU_AGGREGATION */
3445 STA_SET_RX_MSDU,
3446};
3447
3448
3449static int sta_config_params(struct sigma_dut *dut, const char *intf,
3450 enum qca_sta_helper_config_params config_cmd,
3451 int value)
Sunil Dutt44595082018-02-12 19:41:45 +05303452{
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303453#ifdef NL80211_SUPPORT
Sunil Dutt44595082018-02-12 19:41:45 +05303454 struct nl_msg *msg;
3455 int ret;
3456 struct nlattr *params;
3457 int ifindex;
3458
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303459 ifindex = if_nametoindex(intf);
3460 if (ifindex == 0) {
3461 sigma_dut_print(dut, DUT_MSG_ERROR,
3462 "%s: Interface %s does not exist",
3463 __func__, intf);
3464 return -1;
3465 }
3466
Sunil Dutt44595082018-02-12 19:41:45 +05303467 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
3468 NL80211_CMD_VENDOR)) ||
3469 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
3470 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
3471 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
3472 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) ||
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303473 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)))
3474 goto fail;
3475
3476 switch (config_cmd) {
3477 case STA_SET_RSNIE:
3478 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE, value))
3479 goto fail;
3480 break;
3481 case STA_SET_LDPC:
3482 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_LDPC, value))
3483 goto fail;
3484 break;
3485 case STA_SET_TX_STBC:
3486 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TX_STBC, value))
3487 goto fail;
3488 break;
3489 case STA_SET_RX_STBC:
3490 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_RX_STBC, value))
3491 goto fail;
3492 break;
3493 case STA_SET_TX_MSDU:
3494 if (nla_put_u8(msg,
3495 QCA_WLAN_VENDOR_ATTR_CONFIG_TX_MSDU_AGGREGATION,
3496 value))
3497 goto fail;
3498 break;
3499 case STA_SET_RX_MSDU:
3500 if (nla_put_u8(msg,
3501 QCA_WLAN_VENDOR_ATTR_CONFIG_RX_MSDU_AGGREGATION,
3502 value))
3503 goto fail;
3504 break;
Sunil Dutt44595082018-02-12 19:41:45 +05303505 }
3506 nla_nest_end(msg, params);
3507
3508 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
3509 if (ret) {
3510 sigma_dut_print(dut, DUT_MSG_ERROR,
3511 "%s: err in send_and_recv_msgs, ret=%d",
3512 __func__, ret);
3513 return ret;
3514 }
3515
3516 return 0;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303517
3518fail:
3519 sigma_dut_print(dut, DUT_MSG_ERROR,
3520 "%s: err in adding vendor_cmd and vendor_data",
3521 __func__);
3522 nlmsg_free(msg);
Sunil Dutt44595082018-02-12 19:41:45 +05303523#endif /* NL80211_SUPPORT */
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303524 return -1;
3525}
Sunil Dutt44595082018-02-12 19:41:45 +05303526
3527
Jouni Malinenf7222712019-06-13 01:50:21 +03003528static enum sigma_cmd_result cmd_sta_associate(struct sigma_dut *dut,
3529 struct sigma_conn *conn,
3530 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003531{
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303532#ifdef NL80211_SUPPORT
3533 const char *intf = get_param(cmd, "Interface");
3534#endif /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003535 const char *ssid = get_param(cmd, "ssid");
3536 const char *wps_param = get_param(cmd, "WPS");
3537 const char *bssid = get_param(cmd, "bssid");
Jouni Malinen46a19b62017-06-23 14:31:27 +03003538 const char *chan = get_param(cmd, "channel");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003539 const char *network_mode = get_param(cmd, "network_mode");
Veerendranath Jakkama082e342020-05-16 00:19:21 +05303540 const char *ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003541 int wps = 0;
Jouni Malinen3c367e82017-06-23 17:01:47 +03003542 char buf[1000], extra[50];
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003543 int e;
3544 enum sigma_cmd_result ret = SUCCESS_SEND_STATUS;
3545 struct wpa_ctrl *ctrl = NULL;
3546 int num_network_not_found = 0;
3547 int num_disconnected = 0;
3548 int tod = -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003549
3550 if (ssid == NULL)
3551 return -1;
3552
Jouni Malinen37d5c692019-08-19 16:56:55 +03003553 dut->server_cert_tod = 0;
3554
Jouni Malinen3c367e82017-06-23 17:01:47 +03003555 if (dut->rsne_override) {
Sunil Dutt44595082018-02-12 19:41:45 +05303556#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003557 if (get_driver_type(dut) == DRIVER_WCN) {
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303558 sta_config_params(dut, intf, STA_SET_RSNIE, 1);
Sunil Dutt44595082018-02-12 19:41:45 +05303559 dut->config_rsnie = 1;
3560 }
3561#endif /* NL80211_SUPPORT */
Jouni Malinen3c367e82017-06-23 17:01:47 +03003562 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
3563 dut->rsne_override);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003564 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinen3c367e82017-06-23 17:01:47 +03003565 send_resp(dut, conn, SIGMA_ERROR,
3566 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
3567 return 0;
3568 }
3569 }
3570
Jouni Malinen68143132017-09-02 02:34:08 +03003571 if (dut->sae_commit_override) {
3572 snprintf(buf, sizeof(buf), "SET sae_commit_override %s",
3573 dut->sae_commit_override);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003574 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinen68143132017-09-02 02:34:08 +03003575 send_resp(dut, conn, SIGMA_ERROR,
3576 "ErrorCode,Failed to set SAE commit override");
3577 return 0;
3578 }
3579 }
Ankita Bajaj1bde7942018-01-09 19:15:01 +05303580#ifdef ANDROID
3581 if (dut->fils_hlp)
3582 process_fils_hlp(dut);
3583#endif /* ANDROID */
Jouni Malinen68143132017-09-02 02:34:08 +03003584
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003585 if (wps_param &&
3586 (strcmp(wps_param, "1") == 0 || strcasecmp(wps_param, "On") == 0))
3587 wps = 1;
3588
3589 if (wps) {
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003590 if (dut->program == PROGRAM_60GHZ && network_mode &&
3591 strcasecmp(network_mode, "PBSS") == 0 &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003592 set_network(get_station_ifname(dut), dut->infra_network_id,
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003593 "pbss", "1") < 0)
3594 return -2;
3595
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003596 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
3597 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,WPS "
3598 "parameters not yet set");
3599 return 0;
3600 }
3601 if (dut->wps_method == WFA_CS_WPS_PBC) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003602 if (wpa_command(get_station_ifname(dut), "WPS_PBC") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003603 return -2;
3604 } else {
3605 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
3606 dut->wps_pin);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003607 if (wpa_command(get_station_ifname(dut), buf) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003608 return -2;
3609 }
3610 } else {
vamsi krishna52e16f92017-08-29 12:37:34 +05303611 if (strcmp(ssid, dut->infra_ssid) == 0) {
3612 sigma_dut_print(dut, DUT_MSG_DEBUG,
3613 "sta_associate for the most recently added network");
3614 } else if (find_network(dut, ssid) < 0) {
3615 sigma_dut_print(dut, DUT_MSG_DEBUG,
3616 "sta_associate for a previously stored network profile");
3617 send_resp(dut, conn, SIGMA_ERROR,
3618 "ErrorCode,Profile not found");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003619 return 0;
3620 }
3621
3622 if (bssid &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003623 set_network(get_station_ifname(dut), dut->infra_network_id,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003624 "bssid", bssid) < 0) {
3625 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3626 "Invalid bssid argument");
3627 return 0;
3628 }
3629
Veerendranath Jakkama082e342020-05-16 00:19:21 +05303630 if ((dut->program == PROGRAM_WPA3 &&
3631 dut->sta_associate_wait_connect) ||
3632 dut->program == PROGRAM_QM) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003633 ctrl = open_wpa_mon(get_station_ifname(dut));
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003634 if (!ctrl)
3635 return ERROR_SEND_STATUS;
3636 }
3637
Jouni Malinen46a19b62017-06-23 14:31:27 +03003638 extra[0] = '\0';
3639 if (chan)
3640 snprintf(extra, sizeof(extra), " freq=%u",
Alexei Avshalom Lazar093569f2018-11-13 14:08:17 +02003641 channel_to_freq(dut, atoi(chan)));
Jouni Malinen46a19b62017-06-23 14:31:27 +03003642 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d%s",
3643 dut->infra_network_id, extra);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003644 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003645 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to select "
3646 "network id %d on %s",
3647 dut->infra_network_id,
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003648 get_station_ifname(dut));
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003649 ret = ERROR_SEND_STATUS;
3650 goto done;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003651 }
3652 }
3653
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003654 if (!ctrl)
3655 return SUCCESS_SEND_STATUS;
3656
3657 /* Wait for connection result to be able to store server certificate
3658 * hash for trust root override testing
3659 * (dev_exec_action,ServerCertTrust). */
3660
3661 for (e = 0; e < 20; e++) {
3662 const char *events[] = {
3663 "CTRL-EVENT-EAP-PEER-CERT",
3664 "CTRL-EVENT-EAP-TLS-CERT-ERROR",
3665 "CTRL-EVENT-DISCONNECTED",
3666 "CTRL-EVENT-CONNECTED",
3667 "CTRL-EVENT-NETWORK-NOT-FOUND",
3668 NULL
3669 };
3670 char buf[1024];
3671 int res;
3672
3673 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
3674 if (res < 0) {
Jouni Malinenf1f16642019-11-15 21:19:04 +02003675 send_resp(dut, conn, SIGMA_COMPLETE,
3676 "Result,Association did not complete");
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003677 ret = STATUS_SENT_ERROR;
3678 break;
3679 }
3680 sigma_dut_print(dut, DUT_MSG_DEBUG, "Connection event: %s",
3681 buf);
3682
3683 if (strstr(buf, "CTRL-EVENT-EAP-PEER-CERT") &&
3684 strstr(buf, " depth=0")) {
3685 char *pos = strstr(buf, " hash=");
3686
3687 if (pos) {
3688 char *end;
3689
Jouni Malinen34b19cb2019-08-16 16:37:17 +03003690 if (strstr(buf, " tod=1"))
3691 tod = 1;
3692 else if (strstr(buf, " tod=2"))
3693 tod = 2;
3694 else
3695 tod = 0;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003696 sigma_dut_print(dut, DUT_MSG_DEBUG,
3697 "Server certificate TOD policy: %d",
3698 tod);
Jouni Malinen37d5c692019-08-19 16:56:55 +03003699 dut->server_cert_tod = tod;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003700
3701 pos += 6;
3702 end = strchr(pos, ' ');
3703 if (end)
3704 *end = '\0';
3705 strlcpy(dut->server_cert_hash, pos,
3706 sizeof(dut->server_cert_hash));
3707 sigma_dut_print(dut, DUT_MSG_DEBUG,
3708 "Server certificate hash: %s",
3709 dut->server_cert_hash);
3710 }
3711 }
3712
3713 if (strstr(buf, "CTRL-EVENT-EAP-TLS-CERT-ERROR")) {
3714 send_resp(dut, conn, SIGMA_COMPLETE,
3715 "Result,TLS server certificate validation failed");
3716 ret = STATUS_SENT_ERROR;
3717 break;
3718 }
3719
3720 if (strstr(buf, "CTRL-EVENT-NETWORK-NOT-FOUND")) {
3721 num_network_not_found++;
3722
3723 if (num_network_not_found > 2) {
3724 send_resp(dut, conn, SIGMA_COMPLETE,
3725 "Result,Network not found");
3726 ret = STATUS_SENT_ERROR;
3727 break;
3728 }
3729 }
3730
3731 if (strstr(buf, "CTRL-EVENT-DISCONNECTED")) {
3732 num_disconnected++;
3733
3734 if (num_disconnected > 2) {
3735 send_resp(dut, conn, SIGMA_COMPLETE,
3736 "Result,Connection failed");
3737 ret = STATUS_SENT_ERROR;
3738 break;
3739 }
3740 }
3741
3742 if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
3743 if (tod >= 0) {
3744 sigma_dut_print(dut, DUT_MSG_DEBUG,
3745 "Network profile TOD policy update: %d -> %d",
3746 dut->sta_tod_policy, tod);
3747 dut->sta_tod_policy = tod;
3748 }
Veerendranath Jakkama082e342020-05-16 00:19:21 +05303749 if (dut->program == PROGRAM_QM) {
3750 unsigned char iface_mac_addr[ETH_ALEN];
3751 char ipv6[100];
3752
3753 if (get_hwaddr(ifname, iface_mac_addr) < 0) {
3754 sigma_dut_print(dut, DUT_MSG_ERROR,
3755 "%s: get_hwaddr %s failed",
3756 __func__, ifname);
3757 ret = ERROR_SEND_STATUS;
3758 break;
3759 }
3760
3761 convert_mac_addr_to_ipv6_lladdr(iface_mac_addr,
3762 ipv6,
3763 sizeof(ipv6));
3764
3765 if (set_ipv6_addr(dut, ipv6, "64", ifname) !=
3766 0) {
3767 ret = ERROR_SEND_STATUS;
3768 break;
3769 }
3770 }
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003771 break;
3772 }
3773 }
3774done:
3775 if (ctrl) {
3776 wpa_ctrl_detach(ctrl);
3777 wpa_ctrl_close(ctrl);
3778 }
3779 return ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003780}
3781
3782
3783static int run_hs20_osu(struct sigma_dut *dut, const char *params)
3784{
3785 char buf[500], cmd[200];
3786 int res;
3787
3788 /* Use hs20-osu-client file at the current dir, if found; otherwise use
3789 * default path */
3790 res = snprintf(cmd, sizeof(cmd),
3791 "%s -w \"%s\" -r hs20-osu-client.res %s%s -dddKt -f Logs/hs20-osu-client.txt",
3792 file_exists("./hs20-osu-client") ?
3793 "./hs20-osu-client" : "hs20-osu-client",
3794 sigma_wpas_ctrl,
3795 dut->summary_log ? "-s " : "",
3796 dut->summary_log ? dut->summary_log : "");
3797 if (res < 0 || res >= (int) sizeof(cmd))
3798 return -1;
3799
3800 res = snprintf(buf, sizeof(buf), "%s %s", cmd, params);
3801 if (res < 0 || res >= (int) sizeof(buf))
3802 return -1;
3803 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
3804
3805 if (system(buf) != 0) {
3806 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run: %s", buf);
3807 return -1;
3808 }
3809 sigma_dut_print(dut, DUT_MSG_DEBUG,
3810 "Completed hs20-osu-client operation");
3811
3812 return 0;
3813}
3814
3815
3816static int download_ppsmo(struct sigma_dut *dut,
3817 struct sigma_conn *conn,
3818 const char *intf,
3819 struct sigma_cmd *cmd)
3820{
3821 const char *name, *path, *val;
3822 char url[500], buf[600], fbuf[100];
3823 char *fqdn = NULL;
3824
3825 name = get_param(cmd, "FileName");
3826 path = get_param(cmd, "FilePath");
3827 if (name == NULL || path == NULL)
3828 return -1;
3829
3830 if (strcasecmp(path, "VendorSpecific") == 0) {
3831 snprintf(url, sizeof(url), "PPS/%s", name);
3832 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured PPS MO "
3833 "from the device (%s)", url);
3834 if (!file_exists(url)) {
3835 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
3836 "PPS MO file does not exist");
3837 return 0;
3838 }
3839 snprintf(buf, sizeof(buf), "cp %s pps-tnds.xml", url);
3840 if (system(buf) != 0) {
3841 send_resp(dut, conn, SIGMA_ERROR,
3842 "errorCode,Failed to copy PPS MO");
3843 return 0;
3844 }
3845 } else if (strncasecmp(path, "http:", 5) != 0 &&
3846 strncasecmp(path, "https:", 6) != 0) {
3847 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3848 "Unsupported FilePath value");
3849 return 0;
3850 } else {
3851 snprintf(url, sizeof(url), "%s/%s", path, name);
3852 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading PPS MO from %s",
3853 url);
3854 snprintf(buf, sizeof(buf), "wget -T 10 -t 3 -O pps-tnds.xml '%s'", url);
3855 remove("pps-tnds.xml");
3856 if (system(buf) != 0) {
3857 send_resp(dut, conn, SIGMA_ERROR,
3858 "errorCode,Failed to download PPS MO");
3859 return 0;
3860 }
3861 }
3862
3863 if (run_hs20_osu(dut, "from_tnds pps-tnds.xml pps.xml") < 0) {
3864 send_resp(dut, conn, SIGMA_ERROR,
3865 "errorCode,Failed to parse downloaded PPSMO");
3866 return 0;
3867 }
3868 unlink("pps-tnds.xml");
3869
3870 val = get_param(cmd, "managementTreeURI");
3871 if (val) {
3872 const char *pos, *end;
3873 sigma_dut_print(dut, DUT_MSG_DEBUG, "managementTreeURI: %s",
3874 val);
3875 if (strncmp(val, "./Wi-Fi/", 8) != 0) {
3876 send_resp(dut, conn, SIGMA_ERROR,
3877 "errorCode,Invalid managementTreeURI prefix");
3878 return 0;
3879 }
3880 pos = val + 8;
3881 end = strchr(pos, '/');
3882 if (end == NULL ||
3883 strcmp(end, "/PerProviderSubscription") != 0) {
3884 send_resp(dut, conn, SIGMA_ERROR,
3885 "errorCode,Invalid managementTreeURI postfix");
3886 return 0;
3887 }
3888 if (end - pos >= (int) sizeof(fbuf)) {
3889 send_resp(dut, conn, SIGMA_ERROR,
3890 "errorCode,Too long FQDN in managementTreeURI");
3891 return 0;
3892 }
3893 memcpy(fbuf, pos, end - pos);
3894 fbuf[end - pos] = '\0';
3895 fqdn = fbuf;
3896 sigma_dut_print(dut, DUT_MSG_INFO,
3897 "FQDN from managementTreeURI: %s", fqdn);
3898 } else if (run_hs20_osu(dut, "get_fqdn pps.xml") == 0) {
3899 FILE *f = fopen("pps-fqdn", "r");
3900 if (f) {
3901 if (fgets(fbuf, sizeof(fbuf), f)) {
3902 fbuf[sizeof(fbuf) - 1] = '\0';
3903 fqdn = fbuf;
3904 sigma_dut_print(dut, DUT_MSG_DEBUG,
3905 "Use FQDN %s", fqdn);
3906 }
3907 fclose(f);
3908 }
3909 }
3910
3911 if (fqdn == NULL) {
3912 send_resp(dut, conn, SIGMA_ERROR,
3913 "errorCode,No FQDN specified");
3914 return 0;
3915 }
3916
3917 mkdir("SP", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
3918 snprintf(buf, sizeof(buf), "SP/%s", fqdn);
3919 mkdir(buf, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
3920
3921 snprintf(buf, sizeof(buf), "SP/%s/pps.xml", fqdn);
3922 if (rename("pps.xml", buf) < 0) {
3923 send_resp(dut, conn, SIGMA_ERROR,
3924 "errorCode,Could not move PPS MO");
3925 return 0;
3926 }
3927
3928 if (strcasecmp(path, "VendorSpecific") == 0) {
3929 snprintf(buf, sizeof(buf), "cp Certs/ca.pem SP/%s/ca.pem",
3930 fqdn);
3931 if (system(buf)) {
3932 send_resp(dut, conn, SIGMA_ERROR,
3933 "errorCode,Failed to copy OSU CA cert");
3934 return 0;
3935 }
3936
3937 snprintf(buf, sizeof(buf),
3938 "cp Certs/aaa-ca.pem SP/%s/aaa-ca.pem",
3939 fqdn);
3940 if (system(buf)) {
3941 send_resp(dut, conn, SIGMA_ERROR,
3942 "errorCode,Failed to copy AAA CA cert");
3943 return 0;
3944 }
3945 } else {
3946 snprintf(buf, sizeof(buf),
3947 "dl_osu_ca SP/%s/pps.xml SP/%s/ca.pem",
3948 fqdn, fqdn);
3949 if (run_hs20_osu(dut, buf) < 0) {
3950 send_resp(dut, conn, SIGMA_ERROR,
3951 "errorCode,Failed to download OSU CA cert");
3952 return 0;
3953 }
3954
3955 snprintf(buf, sizeof(buf),
3956 "dl_aaa_ca SP/%s/pps.xml SP/%s/aaa-ca.pem",
3957 fqdn, fqdn);
3958 if (run_hs20_osu(dut, buf) < 0) {
3959 sigma_dut_print(dut, DUT_MSG_INFO,
3960 "Failed to download AAA CA cert");
3961 }
3962 }
3963
3964 if (file_exists("next-client-cert.pem")) {
3965 snprintf(buf, sizeof(buf), "SP/%s/client-cert.pem", fqdn);
3966 if (rename("next-client-cert.pem", buf) < 0) {
3967 send_resp(dut, conn, SIGMA_ERROR,
3968 "errorCode,Could not move client certificate");
3969 return 0;
3970 }
3971 }
3972
3973 if (file_exists("next-client-key.pem")) {
3974 snprintf(buf, sizeof(buf), "SP/%s/client-key.pem", fqdn);
3975 if (rename("next-client-key.pem", buf) < 0) {
3976 send_resp(dut, conn, SIGMA_ERROR,
3977 "errorCode,Could not move client key");
3978 return 0;
3979 }
3980 }
3981
3982 snprintf(buf, sizeof(buf), "set_pps SP/%s/pps.xml", fqdn);
3983 if (run_hs20_osu(dut, buf) < 0) {
3984 send_resp(dut, conn, SIGMA_ERROR,
3985 "errorCode,Failed to configure credential from "
3986 "PPSMO");
3987 return 0;
3988 }
3989
3990 return 1;
3991}
3992
3993
3994static int download_cert(struct sigma_dut *dut,
3995 struct sigma_conn *conn,
3996 const char *intf,
3997 struct sigma_cmd *cmd)
3998{
3999 const char *name, *path;
4000 char url[500], buf[600];
4001
4002 name = get_param(cmd, "FileName");
4003 path = get_param(cmd, "FilePath");
4004 if (name == NULL || path == NULL)
4005 return -1;
4006
4007 if (strcasecmp(path, "VendorSpecific") == 0) {
4008 snprintf(url, sizeof(url), "Certs/%s-cert.pem", name);
4009 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
4010 "certificate from the device (%s)", url);
4011 if (!file_exists(url)) {
4012 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
4013 "certificate file does not exist");
4014 return 0;
4015 }
4016 snprintf(buf, sizeof(buf), "cp %s next-client-cert.pem", url);
4017 if (system(buf) != 0) {
4018 send_resp(dut, conn, SIGMA_ERROR,
4019 "errorCode,Failed to copy client "
4020 "certificate");
4021 return 0;
4022 }
4023
4024 snprintf(url, sizeof(url), "Certs/%s-key.pem", name);
4025 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
4026 "private key from the device (%s)", url);
4027 if (!file_exists(url)) {
4028 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
4029 "private key file does not exist");
4030 return 0;
4031 }
4032 snprintf(buf, sizeof(buf), "cp %s next-client-key.pem", url);
4033 if (system(buf) != 0) {
4034 send_resp(dut, conn, SIGMA_ERROR,
4035 "errorCode,Failed to copy client key");
4036 return 0;
4037 }
4038 } else if (strncasecmp(path, "http:", 5) != 0 &&
4039 strncasecmp(path, "https:", 6) != 0) {
4040 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
4041 "Unsupported FilePath value");
4042 return 0;
4043 } else {
4044 snprintf(url, sizeof(url), "%s/%s.pem", path, name);
4045 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading client "
4046 "certificate/key from %s", url);
4047 snprintf(buf, sizeof(buf),
4048 "wget -T 10 -t 3 -O next-client-cert.pem '%s'", url);
4049 if (system(buf) != 0) {
4050 send_resp(dut, conn, SIGMA_ERROR,
4051 "errorCode,Failed to download client "
4052 "certificate");
4053 return 0;
4054 }
4055
4056 if (system("cp next-client-cert.pem next-client-key.pem") != 0)
4057 {
4058 send_resp(dut, conn, SIGMA_ERROR,
4059 "errorCode,Failed to copy client key");
4060 return 0;
4061 }
4062 }
4063
4064 return 1;
4065}
4066
4067
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02004068static int cmd_sta_preset_testparameters_60ghz(struct sigma_dut *dut,
4069 struct sigma_conn *conn,
4070 struct sigma_cmd *cmd)
4071{
4072 const char *val;
4073 const char *intf = get_param(cmd, "interface");
4074
4075 if (!intf)
4076 return -1;
4077
4078 val = get_param(cmd, "WscIEFragment");
4079 if (val && strcasecmp(val, "enable") == 0) {
4080 sigma_dut_print(dut, DUT_MSG_DEBUG,
4081 "Enable WSC IE fragmentation");
4082
4083 dut->wsc_fragment = 1;
4084 /* set long attributes to force fragmentation */
4085 if (wpa_command(intf, "SET device_name "
4086 WPS_LONG_DEVICE_NAME) < 0)
4087 return -2;
4088 if (wpa_command(intf, "SET manufacturer "
4089 WPS_LONG_MANUFACTURER) < 0)
4090 return -2;
4091 if (wpa_command(intf, "SET model_name "
4092 WPS_LONG_MODEL_NAME) < 0)
4093 return -2;
4094 if (wpa_command(intf, "SET model_number "
4095 WPS_LONG_MODEL_NUMBER) < 0)
4096 return -2;
4097 if (wpa_command(intf, "SET serial_number "
4098 WPS_LONG_SERIAL_NUMBER) < 0)
4099 return -2;
4100 }
4101
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02004102 val = get_param(cmd, "RSN_IE");
4103 if (val) {
4104 if (strcasecmp(val, "disable") == 0)
4105 dut->force_rsn_ie = FORCE_RSN_IE_REMOVE;
4106 else if (strcasecmp(val, "enable") == 0)
4107 dut->force_rsn_ie = FORCE_RSN_IE_ADD;
4108 }
4109
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02004110 val = get_param(cmd, "WpsVersion");
4111 if (val)
4112 dut->wps_forced_version = get_wps_forced_version(dut, val);
4113
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02004114 val = get_param(cmd, "WscEAPFragment");
4115 if (val && strcasecmp(val, "enable") == 0)
4116 dut->eap_fragment = 1;
4117
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02004118 return 1;
4119}
4120
4121
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004122static int cmd_sta_preset_testparameters_hs2_r2(struct sigma_dut *dut,
4123 struct sigma_conn *conn,
4124 const char *intf,
4125 struct sigma_cmd *cmd)
4126{
4127 const char *val;
4128
4129 val = get_param(cmd, "FileType");
4130 if (val && strcasecmp(val, "PPSMO") == 0)
4131 return download_ppsmo(dut, conn, intf, cmd);
4132 if (val && strcasecmp(val, "CERT") == 0)
4133 return download_cert(dut, conn, intf, cmd);
4134 if (val) {
4135 send_resp(dut, conn, SIGMA_ERROR,
4136 "ErrorCode,Unsupported FileType");
4137 return 0;
4138 }
4139
4140 return 1;
4141}
4142
4143
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304144static int cmd_sta_preset_testparameters_oce(struct sigma_dut *dut,
4145 struct sigma_conn *conn,
4146 const char *intf,
4147 struct sigma_cmd *cmd)
4148{
4149 const char *val;
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304150 char buf[1000];
4151 char text[20];
4152 unsigned char addr[ETH_ALEN];
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304153
4154 val = get_param(cmd, "OCESupport");
4155 if (val && strcasecmp(val, "Disable") == 0) {
4156 if (wpa_command(intf, "SET oce 0") < 0) {
4157 send_resp(dut, conn, SIGMA_ERROR,
4158 "ErrorCode,Failed to disable OCE");
4159 return 0;
4160 }
4161 } else if (val && strcasecmp(val, "Enable") == 0) {
4162 if (wpa_command(intf, "SET oce 1") < 0) {
4163 send_resp(dut, conn, SIGMA_ERROR,
4164 "ErrorCode,Failed to enable OCE");
4165 return 0;
4166 }
4167 }
4168
vamsi krishnaa2799492017-12-05 14:28:01 +05304169 val = get_param(cmd, "FILScap");
4170 if (val && (atoi(val) == 1)) {
4171 if (wpa_command(intf, "SET disable_fils 0") < 0) {
4172 send_resp(dut, conn, SIGMA_ERROR,
4173 "ErrorCode,Failed to enable FILS");
4174 return 0;
4175 }
4176 } else if (val && (atoi(val) == 0)) {
4177 if (wpa_command(intf, "SET disable_fils 1") < 0) {
4178 send_resp(dut, conn, SIGMA_ERROR,
4179 "ErrorCode,Failed to disable FILS");
4180 return 0;
4181 }
4182 }
4183
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304184 val = get_param(cmd, "FILSHLP");
4185 if (val && strcasecmp(val, "Enable") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004186 if (get_wpa_status(get_station_ifname(dut), "address", text,
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304187 sizeof(text)) < 0)
4188 return -2;
4189 hwaddr_aton(text, addr);
4190 snprintf(buf, sizeof(buf),
4191 "FILS_HLP_REQ_ADD ff:ff:ff:ff:ff:ff "
4192 "080045100140000040004011399e00000000ffffffff00440043"
4193 "012cb30001010600fd4f46410000000000000000000000000000"
4194 "000000000000"
4195 "%02x%02x%02x%02x%02x%02x"
4196 "0000000000000000000000000000000000000000000000000000"
4197 "0000000000000000000000000000000000000000000000000000"
4198 "0000000000000000000000000000000000000000000000000000"
4199 "0000000000000000000000000000000000000000000000000000"
4200 "0000000000000000000000000000000000000000000000000000"
4201 "0000000000000000000000000000000000000000000000000000"
4202 "0000000000000000000000000000000000000000000000000000"
4203 "0000000000000000000000000000000000000000638253633501"
4204 "013d0701000af549d29b390205dc3c12616e64726f69642d6468"
4205 "63702d382e302e30370a0103060f1a1c333a3b2b5000ff00",
4206 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
4207 if (wpa_command(intf, buf)) {
4208 send_resp(dut, conn, SIGMA_ERROR,
4209 "ErrorCode,Failed to add HLP");
4210 return 0;
4211 }
4212 dut->fils_hlp = 1;
4213 }
4214
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304215 return 1;
4216}
4217
4218
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004219static void ath_sta_set_noack(struct sigma_dut *dut, const char *intf,
4220 const char *val)
4221{
4222 int counter = 0;
4223 char token[50];
4224 char *result;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304225 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004226
Peng Xub8fc5cc2017-05-10 17:27:28 -07004227 strlcpy(token, val, sizeof(token));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004228 token[sizeof(token) - 1] = '\0';
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304229 result = strtok_r(token, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004230 while (result) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004231 if (strcmp(result, "disable") == 0)
4232 run_iwpriv(dut, intf, "noackpolicy %d 1 0", counter);
4233 else
4234 run_iwpriv(dut, intf, "noackpolicy %d 1 1", counter);
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304235 result = strtok_r(NULL, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004236 counter++;
4237 }
4238}
4239
4240
4241static void ath_sta_set_rts(struct sigma_dut *dut, const char *intf,
4242 const char *val)
4243{
4244 char buf[100];
4245
4246 snprintf(buf, sizeof(buf), "iwconfig %s rts %s", intf, val);
4247 if (system(buf) != 0) {
4248 sigma_dut_print(dut, DUT_MSG_ERROR, "iwconfig RTS failed");
4249 }
4250}
4251
4252
4253static void ath_sta_set_wmm(struct sigma_dut *dut, const char *intf,
4254 const char *val)
4255{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004256 if (strcasecmp(val, "off") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004257 run_iwpriv(dut, intf, "wmm 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004258 }
4259}
4260
4261
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08004262static int wcn_sta_set_wmm(struct sigma_dut *dut, const char *intf,
4263 const char *val)
4264{
4265#ifdef NL80211_SUPPORT
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08004266 int wmmenable = 1;
4267
4268 if (val &&
4269 (strcasecmp(val, "off") == 0 || strcmp(val, "0") == 0))
4270 wmmenable = 0;
4271
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05304272 return wcn_wifi_test_config_set_u8(
4273 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WMM_ENABLE,
4274 wmmenable);
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08004275#else /* NL80211_SUPPORT */
4276 sigma_dut_print(dut, DUT_MSG_ERROR,
4277 "WMM cannot be changed without NL80211_SUPPORT defined");
4278 return -1;
4279#endif /* NL80211_SUPPORT */
4280}
4281
4282
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004283static void ath_sta_set_sgi(struct sigma_dut *dut, const char *intf,
4284 const char *val)
4285{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004286 int sgi20;
4287
4288 sgi20 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
4289
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004290 run_iwpriv(dut, intf, "shortgi %d", sgi20);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004291}
4292
4293
4294static void ath_sta_set_11nrates(struct sigma_dut *dut, const char *intf,
4295 const char *val)
4296{
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05304297 int rate_code, v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004298
4299 /* Disable Tx Beam forming when using a fixed rate */
4300 ath_disable_txbf(dut, intf);
4301
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05304302 v = atoi(val);
4303 if (v < 0 || v > 32) {
4304 sigma_dut_print(dut, DUT_MSG_ERROR,
4305 "Invalid Fixed MCS rate: %d", v);
4306 return;
4307 }
4308 rate_code = 0x80 + v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004309
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004310 run_iwpriv(dut, intf, "set11NRates 0x%x", rate_code);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004311
4312 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004313 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004314}
4315
4316
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08004317static void iwpriv_sta_set_amsdu(struct sigma_dut *dut, const char *intf,
4318 const char *val)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004319{
4320 char buf[60];
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304321 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004322
4323 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)
4324 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 2", intf);
4325 else
4326 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf);
4327
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304328 ret = system(buf);
4329#ifdef NL80211_SUPPORT
4330 if (ret) {
4331 int value = (strcasecmp(val, "Enable") == 0) ? 2 : 1;
4332
4333 ret = sta_config_params(dut, intf, STA_SET_TX_MSDU, value);
4334 ret |= sta_config_params(dut, intf, STA_SET_RX_MSDU, value);
4335 }
4336#endif /* NL80211_SUPPORT */
4337 if (ret)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004338 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv amsdu failed");
4339}
4340
4341
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004342static int iwpriv_sta_set_ampdu(struct sigma_dut *dut, const char *intf,
4343 int ampdu)
4344{
4345 char buf[60];
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08004346 int maxaggregation = 63;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004347
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08004348 if (ampdu)
4349 ampdu = maxaggregation;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004350 snprintf(buf, sizeof(buf), "iwpriv %s ampdu %d", intf, ampdu);
4351 if (system(buf) != 0) {
4352 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv ampdu failed");
4353 return -1;
4354 }
4355
4356 return 0;
4357}
4358
4359
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004360static void ath_sta_set_stbc(struct sigma_dut *dut, const char *intf,
4361 const char *val)
4362{
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004363 run_iwpriv(dut, intf, "tx_stbc %s", val);
4364 run_iwpriv(dut, intf, "rx_stbc %s", val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004365}
4366
4367
4368static int wcn_sta_set_cts_width(struct sigma_dut *dut, const char *intf,
4369 const char *val)
4370{
4371 char buf[60];
4372
Peng Xucc317ed2017-05-18 16:44:37 -07004373 if (strcmp(val, "160") == 0) {
4374 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 5", intf);
4375 } else if (strcmp(val, "80") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004376 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
4377 } else if (strcmp(val, "40") == 0) {
4378 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 2", intf);
4379 } else if (strcmp(val, "20") == 0) {
4380 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 1", intf);
4381 } else if (strcasecmp(val, "Auto") == 0) {
4382 buf[0] = '\0';
4383 } else {
4384 sigma_dut_print(dut, DUT_MSG_ERROR,
4385 "WIDTH/CTS_WIDTH value not supported");
4386 return -1;
4387 }
4388
4389 if (buf[0] != '\0' && system(buf) != 0) {
4390 sigma_dut_print(dut, DUT_MSG_ERROR,
4391 "Failed to set WIDTH/CTS_WIDTH");
4392 return -1;
4393 }
4394
4395 return 0;
4396}
4397
4398
4399int ath_set_width(struct sigma_dut *dut, struct sigma_conn *conn,
4400 const char *intf, const char *val)
4401{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004402 if (strcasecmp(val, "Auto") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004403 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004404 dut->chwidth = 0;
4405 } else if (strcasecmp(val, "20") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004406 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004407 dut->chwidth = 0;
4408 } else if (strcasecmp(val, "40") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004409 run_iwpriv(dut, intf, "chwidth 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004410 dut->chwidth = 1;
4411 } else if (strcasecmp(val, "80") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004412 run_iwpriv(dut, intf, "chwidth 2");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004413 dut->chwidth = 2;
4414 } else if (strcasecmp(val, "160") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004415 run_iwpriv(dut, intf, "chwidth 3");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004416 dut->chwidth = 3;
4417 } else {
4418 send_resp(dut, conn, SIGMA_ERROR,
4419 "ErrorCode,WIDTH not supported");
4420 return -1;
4421 }
4422
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004423 return 0;
4424}
4425
4426
4427static int wcn_sta_set_sp_stream(struct sigma_dut *dut, const char *intf,
4428 const char *val)
4429{
4430 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07004431 int sta_nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004432
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08004433 if (strcmp(val, "1SS") == 0 || strcmp(val, "1") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004434 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07004435 sta_nss = 1;
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08004436 } else if (strcmp(val, "2SS") == 0 || strcmp(val, "2") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004437 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07004438 sta_nss = 2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004439 } else {
4440 sigma_dut_print(dut, DUT_MSG_ERROR,
4441 "SP_STREAM value not supported");
4442 return -1;
4443 }
4444
4445 if (system(buf) != 0) {
4446 sigma_dut_print(dut, DUT_MSG_ERROR,
4447 "Failed to set SP_STREAM");
4448 return -1;
4449 }
4450
Arif Hussainac6c5112018-05-25 17:34:00 -07004451 dut->sta_nss = sta_nss;
4452
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004453 return 0;
4454}
4455
4456
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304457static void wcn_sta_set_stbc(struct sigma_dut *dut, const char *intf,
4458 const char *val)
4459{
4460 char buf[60];
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304461 int ret;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304462
4463 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc %s", intf, val);
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304464 ret = system(buf);
4465#ifdef NL80211_SUPPORT
4466 if (ret)
4467 ret = sta_config_params(dut, intf, STA_SET_TX_STBC,
4468 strcmp(val, "0") == 0 ? 0 : 1);
4469#endif /* NL80211_SUPPORT */
4470 if (ret)
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304471 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv tx_stbc failed");
4472
4473 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc %s", intf, val);
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304474 ret = system(buf);
4475#ifdef NL80211_SUPPORT
4476 if (ret)
4477 ret = sta_config_params(dut, intf, STA_SET_RX_STBC,
4478 strcmp(val, "0") == 0 ? 0 : 1);
4479#endif /* NL80211_SUPPORT */
4480 if (ret)
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304481 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv rx_stbc failed");
4482}
4483
4484
Ashwini Patil68d02cd2017-01-10 15:39:16 +05304485static int mbo_set_cellular_data_capa(struct sigma_dut *dut,
4486 struct sigma_conn *conn,
4487 const char *intf, int capa)
4488{
4489 char buf[32];
4490
4491 if (capa > 0 && capa < 4) {
4492 snprintf(buf, sizeof(buf), "SET mbo_cell_capa %d", capa);
4493 if (wpa_command(intf, buf) < 0) {
4494 send_resp(dut, conn, SIGMA_ERROR,
4495 "ErrorCode, Failed to set cellular data capability");
4496 return 0;
4497 }
4498 return 1;
4499 }
4500
4501 sigma_dut_print(dut, DUT_MSG_ERROR,
4502 "Invalid Cellular data capability: %d", capa);
4503 send_resp(dut, conn, SIGMA_INVALID,
4504 "ErrorCode,Invalid cellular data capability");
4505 return 0;
4506}
4507
4508
Ashwini Patil9183fdb2017-04-13 16:58:25 +05304509static int mbo_set_roaming(struct sigma_dut *dut, struct sigma_conn *conn,
4510 const char *intf, const char *val)
4511{
4512 if (strcasecmp(val, "Disable") == 0) {
4513 if (wpa_command(intf, "SET roaming 0") < 0) {
4514 send_resp(dut, conn, SIGMA_ERROR,
4515 "ErrorCode,Failed to disable roaming");
4516 return 0;
4517 }
4518 return 1;
4519 }
4520
4521 if (strcasecmp(val, "Enable") == 0) {
4522 if (wpa_command(intf, "SET roaming 1") < 0) {
4523 send_resp(dut, conn, SIGMA_ERROR,
4524 "ErrorCode,Failed to enable roaming");
4525 return 0;
4526 }
4527 return 1;
4528 }
4529
4530 sigma_dut_print(dut, DUT_MSG_ERROR,
4531 "Invalid value provided for roaming: %s", val);
4532 send_resp(dut, conn, SIGMA_INVALID,
4533 "ErrorCode,Unknown value provided for Roaming");
4534 return 0;
4535}
4536
4537
Ashwini Patila75de5a2017-04-13 16:35:05 +05304538static int mbo_set_assoc_disallow(struct sigma_dut *dut,
4539 struct sigma_conn *conn,
4540 const char *intf, const char *val)
4541{
4542 if (strcasecmp(val, "Disable") == 0) {
4543 if (wpa_command(intf, "SET ignore_assoc_disallow 1") < 0) {
4544 send_resp(dut, conn, SIGMA_ERROR,
4545 "ErrorCode,Failed to disable Assoc_disallow");
4546 return 0;
4547 }
4548 return 1;
4549 }
4550
4551 if (strcasecmp(val, "Enable") == 0) {
4552 if (wpa_command(intf, "SET ignore_assoc_disallow 0") < 0) {
4553 send_resp(dut, conn, SIGMA_ERROR,
4554 "ErrorCode,Failed to enable Assoc_disallow");
4555 return 0;
4556 }
4557 return 1;
4558 }
4559
4560 sigma_dut_print(dut, DUT_MSG_ERROR,
4561 "Invalid value provided for Assoc_disallow: %s", val);
4562 send_resp(dut, conn, SIGMA_INVALID,
4563 "ErrorCode,Unknown value provided for Assoc_disallow");
4564 return 0;
4565}
4566
4567
Ashwini Patilc63161e2017-04-13 16:30:23 +05304568static int mbo_set_bss_trans_req(struct sigma_dut *dut, struct sigma_conn *conn,
4569 const char *intf, const char *val)
4570{
4571 if (strcasecmp(val, "Reject") == 0) {
4572 if (wpa_command(intf, "SET reject_btm_req_reason 1") < 0) {
4573 send_resp(dut, conn, SIGMA_ERROR,
4574 "ErrorCode,Failed to Reject BTM Request");
4575 return 0;
4576 }
4577 return 1;
4578 }
4579
4580 if (strcasecmp(val, "Accept") == 0) {
4581 if (wpa_command(intf, "SET reject_btm_req_reason 0") < 0) {
4582 send_resp(dut, conn, SIGMA_ERROR,
4583 "ErrorCode,Failed to Accept BTM Request");
4584 return 0;
4585 }
4586 return 1;
4587 }
4588
4589 sigma_dut_print(dut, DUT_MSG_ERROR,
4590 "Invalid value provided for BSS_Transition: %s", val);
4591 send_resp(dut, conn, SIGMA_INVALID,
4592 "ErrorCode,Unknown value provided for BSS_Transition");
4593 return 0;
4594}
4595
4596
Ashwini Patil00402582017-04-13 12:29:39 +05304597static int mbo_set_non_pref_ch_list(struct sigma_dut *dut,
4598 struct sigma_conn *conn,
4599 const char *intf,
4600 struct sigma_cmd *cmd)
4601{
4602 const char *ch, *pref, *op_class, *reason;
4603 char buf[120];
4604 int len, ret;
4605
4606 pref = get_param(cmd, "Ch_Pref");
4607 if (!pref)
4608 return 1;
4609
4610 if (strcasecmp(pref, "clear") == 0) {
4611 free(dut->non_pref_ch_list);
4612 dut->non_pref_ch_list = NULL;
4613 } else {
4614 op_class = get_param(cmd, "Ch_Op_Class");
4615 if (!op_class) {
4616 send_resp(dut, conn, SIGMA_INVALID,
4617 "ErrorCode,Ch_Op_Class not provided");
4618 return 0;
4619 }
4620
4621 ch = get_param(cmd, "Ch_Pref_Num");
4622 if (!ch) {
4623 send_resp(dut, conn, SIGMA_INVALID,
4624 "ErrorCode,Ch_Pref_Num not provided");
4625 return 0;
4626 }
4627
4628 reason = get_param(cmd, "Ch_Reason_Code");
4629 if (!reason) {
4630 send_resp(dut, conn, SIGMA_INVALID,
4631 "ErrorCode,Ch_Reason_Code not provided");
4632 return 0;
4633 }
4634
4635 if (!dut->non_pref_ch_list) {
4636 dut->non_pref_ch_list =
4637 calloc(1, NON_PREF_CH_LIST_SIZE);
4638 if (!dut->non_pref_ch_list) {
4639 send_resp(dut, conn, SIGMA_ERROR,
4640 "ErrorCode,Failed to allocate memory for non_pref_ch_list");
4641 return 0;
4642 }
4643 }
4644 len = strlen(dut->non_pref_ch_list);
4645 ret = snprintf(dut->non_pref_ch_list + len,
4646 NON_PREF_CH_LIST_SIZE - len,
4647 " %s:%s:%s:%s", op_class, ch, pref, reason);
4648 if (ret > 0 && ret < NON_PREF_CH_LIST_SIZE - len) {
4649 sigma_dut_print(dut, DUT_MSG_DEBUG, "non_pref_list: %s",
4650 dut->non_pref_ch_list);
4651 } else {
4652 sigma_dut_print(dut, DUT_MSG_ERROR,
4653 "snprintf failed for non_pref_list, ret = %d",
4654 ret);
4655 send_resp(dut, conn, SIGMA_ERROR,
4656 "ErrorCode,snprintf failed");
4657 free(dut->non_pref_ch_list);
4658 dut->non_pref_ch_list = NULL;
4659 return 0;
4660 }
4661 }
4662
4663 ret = snprintf(buf, sizeof(buf), "SET non_pref_chan%s",
4664 dut->non_pref_ch_list ? dut->non_pref_ch_list : " ");
4665 if (ret < 0 || ret >= (int) sizeof(buf)) {
4666 sigma_dut_print(dut, DUT_MSG_DEBUG,
4667 "snprintf failed for set non_pref_chan, ret: %d",
4668 ret);
4669 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,snprint failed");
4670 return 0;
4671 }
4672
4673 if (wpa_command(intf, buf) < 0) {
4674 send_resp(dut, conn, SIGMA_ERROR,
4675 "ErrorCode,Failed to set non-preferred channel list");
4676 return 0;
4677 }
4678
4679 return 1;
4680}
4681
4682
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004683#ifdef NL80211_SUPPORT
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004684
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08004685static int sta_set_he_htc_supp(struct sigma_dut *dut, const char *intf,
4686 uint8_t cfg)
4687{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05304688 return wcn_wifi_test_config_set_u8(
4689 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_HTC_HE_SUPP,
4690 cfg);
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08004691}
4692
4693
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004694static int sta_set_he_fragmentation(struct sigma_dut *dut, const char *intf,
4695 enum he_fragmentation_val frag)
4696{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05304697 return wcn_wifi_test_config_set_u8(
4698 dut, intf,
4699 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_FRAGMENTATION, frag);
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004700}
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004701
4702
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -08004703int wcn_set_he_ltf(struct sigma_dut *dut, const char *intf,
4704 enum qca_wlan_he_ltf_cfg ltf)
Subhani Shaik8e7a3052018-04-24 14:03:00 -07004705{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05304706 return wcn_wifi_test_config_set_u8(
4707 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_LTF, ltf);
Subhani Shaik8e7a3052018-04-24 14:03:00 -07004708}
4709
4710
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004711static int nlvendor_sta_set_noack(struct sigma_dut *dut, const char *intf,
4712 int noack, enum qca_wlan_ac_type ac)
4713{
4714 struct nl_msg *msg;
4715 int ret = 0;
4716 struct nlattr *params;
4717 int ifindex;
4718
4719 ifindex = if_nametoindex(intf);
4720 if (ifindex == 0) {
4721 sigma_dut_print(dut, DUT_MSG_ERROR,
4722 "%s: Index for interface %s failed",
4723 __func__, intf);
4724 return -1;
4725 }
4726
4727 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4728 NL80211_CMD_VENDOR)) ||
4729 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4730 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4731 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4732 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4733 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4734 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_NO_ACK,
4735 noack) ||
4736 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_NO_ACK_AC,
4737 ac)) {
4738 sigma_dut_print(dut, DUT_MSG_ERROR,
4739 "%s: err in adding vendor_cmd and vendor_data",
4740 __func__);
4741 nlmsg_free(msg);
4742 return -1;
4743 }
4744 nla_nest_end(msg, params);
4745
4746 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4747 if (ret) {
4748 sigma_dut_print(dut, DUT_MSG_ERROR,
4749 "%s: err in send_and_recv_msgs, ret=%d",
4750 __func__, ret);
4751 }
4752 return ret;
4753}
4754
4755
4756static void wcn_sta_set_noack(struct sigma_dut *dut, const char *intf,
4757 const char *val)
4758{
4759 int noack, ret;
4760 char token[100];
4761 char *result;
4762 char *saveptr;
4763 enum qca_wlan_ac_type ac = QCA_WLAN_AC_BE;
4764
4765 strlcpy(token, val, sizeof(token));
4766 token[sizeof(token) - 1] = '\0';
4767 result = strtok_r(token, ":", &saveptr);
4768 while (result) {
4769 noack = strcasecmp(result, "Disable") != 0;
4770 ret = nlvendor_sta_set_noack(dut, intf, noack, ac);
4771 if (ret) {
4772 sigma_dut_print(dut, DUT_MSG_ERROR,
4773 "nlvendor_sta_set_noack failed for ac:%d, ret:%d",
4774 ac, ret);
4775 }
4776 result = strtok_r(NULL, ":", &saveptr);
4777 ac++;
4778 }
4779}
4780
Vinita S. Maloo7462e812020-05-22 15:16:04 +05304781
4782static int nlvendor_sta_set_phymode(struct sigma_dut *dut, const char *intf,
4783 enum qca_wlan_vendor_phy_mode val)
4784{
4785 struct nl_msg *msg;
4786 struct nlattr *params;
4787 int ifindex, ret;
4788
4789 ifindex = if_nametoindex(intf);
4790 if (ifindex == 0) {
4791 sigma_dut_print(dut, DUT_MSG_ERROR,
4792 "%s: Index for interface %s not found",
4793 __func__, intf);
4794 return -1;
4795 }
4796
4797 msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4798 NL80211_CMD_VENDOR);
4799 if (!msg) {
4800 sigma_dut_print(dut, DUT_MSG_ERROR,
4801 "%s: err in adding vendor_cmd", __func__);
4802 return -1;
4803 }
4804
4805 if (nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4806 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4807 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION)) {
4808 sigma_dut_print(dut, DUT_MSG_ERROR,
4809 "%s: err in adding vendor_attr", __func__);
4810 nlmsg_free(msg);
4811 return -1;
4812 }
4813
4814 params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
4815 if (!params || nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_PHY_MODE,
4816 val)) {
4817 sigma_dut_print(dut, DUT_MSG_ERROR,
4818 "%s: err in adding vendor_data", __func__);
4819 nlmsg_free(msg);
4820 return -1;
4821 }
4822
4823 nla_nest_end(msg, params);
4824 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4825 if (ret) {
4826 sigma_dut_print(dut, DUT_MSG_ERROR,
4827 "%s: err in send_and_recv_msgs, ret=%d (%s)",
4828 __func__, ret, strerror(-ret));
4829 return ret;
4830 }
4831
4832 return 0;
4833}
4834
4835
4836static enum qca_wlan_vendor_phy_mode get_qca_vendor_phymode(const char *val)
4837{
4838 if (strcmp(val, "11a") == 0) {
4839 /* IEEE80211_MODE_11A */
4840 return QCA_WLAN_VENDOR_PHY_MODE_11A;
4841 }
4842
4843 if (strcmp(val, "11g") == 0) {
4844 /* IEEE80211_MODE_11G */
4845 return QCA_WLAN_VENDOR_PHY_MODE_11G;
4846 }
4847
4848 if (strcmp(val, "11b") == 0) {
4849 /* IEEE80211_MODE_11B */
4850 return QCA_WLAN_VENDOR_PHY_MODE_11B;
4851 }
4852
4853 if (strcmp(val, "11n") == 0 ||
4854 strcmp(val, "11nl") == 0 ||
4855 strcmp(val, "11nl(nabg)") == 0) {
4856 /* IEEE80211_MODE_11AGN */
4857 return QCA_WLAN_VENDOR_PHY_MODE_11AGN;
4858 }
4859
4860 if (strcmp(val, "11ng") == 0) {
4861 /* IEEE80211_MODE_11NG_HT40 */
4862 return QCA_WLAN_VENDOR_PHY_MODE_11NG_HT40;
4863 }
4864
4865 if (strcmp(val, "AC") == 0 ||
4866 strcasecmp(val, "11AC") == 0) {
4867 /* IEEE80211_MODE_11AC_VHT80 */
4868 return QCA_WLAN_VENDOR_PHY_MODE_11AC_VHT80;
4869 }
4870
4871 if (strcmp(val, "11na") == 0 ||
4872 strcasecmp(val, "11an") == 0) {
4873 /* IEEE80211_MODE_11NA_HT40 */
4874 return QCA_WLAN_VENDOR_PHY_MODE_11NA_HT40;
4875 }
4876
4877 if (strcmp(val, "11ax") == 0 ||
4878 strcmp(val, "auto") == 0) {
4879 /* IEEE80211_MODE_AUTO */
4880 return QCA_WLAN_VENDOR_PHY_MODE_AUTO;
4881 }
4882
4883 return -1;
4884}
4885
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004886#endif /* NL80211_SUPPORT */
4887
4888
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05304889static int get_phymode(const char *val)
4890{
4891 if (strcmp(val, "11a") == 0)
4892 return 1; /* IEEE80211_MODE_11A */
4893 if (strcmp(val, "11g") == 0)
4894 return 3; /* IEEE80211_MODE_11G */
4895 if (strcmp(val, "11b") == 0)
4896 return 2; /* IEEE80211_MODE_11B */
4897 if (strcmp(val, "11n") == 0 ||
4898 strcmp(val, "11nl") == 0 ||
4899 strcmp(val, "11nl(nabg)") == 0)
4900 return 22; /* IEEE80211_MODE_11AGN */
4901 if (strcmp(val, "11ng") == 0)
4902 return 13; /* IEEE80211_MODE_11NG_HT40 */
4903 if (strcmp(val, "AC") == 0 ||
4904 strcasecmp(val, "11AC") == 0)
4905 return 19; /* IEEE80211_MODE_11AC_VHT80 */
4906 if (strcmp(val, "11na") == 0 ||
4907 strcasecmp(val, "11an") == 0)
4908 return 14; /* IEEE80211_MODE_11NA_HT40 */
4909 if (strcmp(val, "11ax") == 0 ||
4910 strcmp(val, "auto") == 0)
4911 return 0; /* IEEE80211_MODE_AUTO */
4912 return -1;
4913}
4914
4915
4916static void sta_set_phymode(struct sigma_dut *dut, const char *intf,
4917 const char *val)
4918{
4919 char buf[100];
4920 int len, phymode;
Vinita S. Maloo7462e812020-05-22 15:16:04 +05304921#ifdef NL80211_SUPPORT
4922 enum qca_wlan_vendor_phy_mode qca_phymode;
4923
4924 qca_phymode = get_qca_vendor_phymode(val);
4925 if (qca_phymode == -1) {
4926 sigma_dut_print(dut, DUT_MSG_DEBUG,
4927 "Ignoring mode change for mode: %s",
4928 val);
4929 return;
4930 }
4931
4932 if (nlvendor_sta_set_phymode(dut, intf, qca_phymode) == 0)
4933 return;
4934#endif /* NL80211_SUPPORT */
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05304935
4936 phymode = get_phymode(val);
4937 if (phymode == -1) {
4938 sigma_dut_print(dut, DUT_MSG_DEBUG,
4939 "Ignoring mode change for mode: %s",
4940 val);
4941 return;
4942 }
4943
4944 len = snprintf(buf, sizeof(buf), "iwpriv %s setphymode %d", intf,
4945 phymode);
4946 if (len < 0 || len >= sizeof(buf)) {
4947 sigma_dut_print(dut, DUT_MSG_ERROR,
4948 "Failed to set phymode");
4949 return;
4950 }
4951
4952 if (system(buf) != 0)
4953 sigma_dut_print(dut, DUT_MSG_ERROR,
4954 "iwpriv setting of phymode failed");
4955}
4956
4957
Jouni Malinenf7222712019-06-13 01:50:21 +03004958static enum sigma_cmd_result
4959cmd_sta_preset_testparameters(struct sigma_dut *dut, struct sigma_conn *conn,
4960 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004961{
4962 const char *intf = get_param(cmd, "Interface");
4963 const char *val;
4964
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03004965 val = get_param(cmd, "FT_DS");
4966 if (val) {
4967 if (strcasecmp(val, "Enable") == 0) {
4968 dut->sta_ft_ds = 1;
4969 } else if (strcasecmp(val, "Disable") == 0) {
4970 dut->sta_ft_ds = 0;
4971 } else {
4972 send_resp(dut, conn, SIGMA_ERROR,
4973 "errorCode,Unsupported value for FT_DS");
4974 return STATUS_SENT_ERROR;
4975 }
4976 }
4977
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004978 val = get_param(cmd, "Program");
Jouni Malinen1f6ae642018-06-07 23:56:13 +03004979 if (val && (strcasecmp(val, "HS2-R2") == 0 ||
4980 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004981 return cmd_sta_preset_testparameters_hs2_r2(dut, conn, intf,
4982 cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004983
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07004984 if (val && strcasecmp(val, "LOC") == 0)
4985 return loc_cmd_sta_preset_testparameters(dut, conn, cmd);
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02004986 if (val && strcasecmp(val, "60GHZ") == 0) {
4987 val = get_param(cmd, "WPS");
4988 if (val && strcasecmp(val, "disable") == 0) {
4989 dut->wps_disable = 1;
4990 sigma_dut_print(dut, DUT_MSG_INFO, "WPS disabled");
4991 } else {
4992 /* wps_disable can have other value from the previous
4993 * test, so make sure it has the correct value.
4994 */
4995 dut->wps_disable = 0;
4996 }
4997
4998 val = get_param(cmd, "P2P");
4999 if (val && strcasecmp(val, "disable") == 0)
5000 sigma_dut_print(dut, DUT_MSG_INFO, "P2P disabled");
5001 }
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07005002
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02005003 if (dut->program == PROGRAM_WPS && dut->band == WPS_BAND_60G)
5004 return cmd_sta_preset_testparameters_60ghz(dut, conn, cmd);
5005
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005006#ifdef ANDROID_NAN
5007 if (val && strcasecmp(val, "NAN") == 0)
5008 return nan_cmd_sta_preset_testparameters(dut, conn, cmd);
5009#endif /* ANDROID_NAN */
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07005010#ifdef MIRACAST
5011 if (val && (strcasecmp(val, "WFD") == 0 ||
5012 strcasecmp(val, "DisplayR2") == 0))
5013 return miracast_preset_testparameters(dut, conn, cmd);
5014#endif /* MIRACAST */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005015
Kiran Kumar Lokeredd086642020-06-04 00:29:26 -07005016 if (val &&
5017 (strcasecmp(val, "MBO") == 0 || strcasecmp(val, "HE") == 0)) {
Ashwini Patil68d02cd2017-01-10 15:39:16 +05305018 val = get_param(cmd, "Cellular_Data_Cap");
5019 if (val &&
5020 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
5021 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +05305022
5023 val = get_param(cmd, "Ch_Pref");
5024 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
5025 return 0;
5026
Ashwini Patilc63161e2017-04-13 16:30:23 +05305027 val = get_param(cmd, "BSS_Transition");
5028 if (val && mbo_set_bss_trans_req(dut, conn, intf, val) == 0)
5029 return 0;
5030
Ashwini Patila75de5a2017-04-13 16:35:05 +05305031 val = get_param(cmd, "Assoc_Disallow");
5032 if (val && mbo_set_assoc_disallow(dut, conn, intf, val) == 0)
5033 return 0;
5034
Ashwini Patil9183fdb2017-04-13 16:58:25 +05305035 val = get_param(cmd, "Roaming");
5036 if (val && mbo_set_roaming(dut, conn, intf, val) == 0)
5037 return 0;
5038
Ashwini Patil68d02cd2017-01-10 15:39:16 +05305039 return 1;
5040 }
5041
Ankita Bajaja2cb5672017-10-25 16:08:28 +05305042 if (val && strcasecmp(val, "OCE") == 0)
5043 return cmd_sta_preset_testparameters_oce(dut, conn, intf, cmd);
5044
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005045#if 0
5046 val = get_param(cmd, "Supplicant");
5047 if (val && strcasecmp(val, "Default") != 0) {
5048 send_resp(dut, conn, SIGMA_ERROR,
5049 "ErrorCode,Only default(Vendor) supplicant "
5050 "supported");
5051 return 0;
5052 }
5053#endif
5054
5055 val = get_param(cmd, "RTS");
5056 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005057 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005058 case DRIVER_ATHEROS:
5059 ath_sta_set_rts(dut, intf, val);
5060 break;
5061 default:
5062#if 0
5063 send_resp(dut, conn, SIGMA_ERROR,
5064 "ErrorCode,Setting RTS not supported");
5065 return 0;
5066#else
5067 sigma_dut_print(dut, DUT_MSG_DEBUG,
5068 "Setting RTS not supported");
5069 break;
5070#endif
5071 }
5072 }
5073
5074#if 0
5075 val = get_param(cmd, "FRGMNT");
5076 if (val) {
5077 /* TODO */
5078 send_resp(dut, conn, SIGMA_ERROR,
5079 "ErrorCode,Setting FRGMNT not supported");
5080 return 0;
5081 }
5082#endif
5083
5084#if 0
5085 val = get_param(cmd, "Preamble");
5086 if (val) {
5087 /* TODO: Long/Short */
5088 send_resp(dut, conn, SIGMA_ERROR,
5089 "ErrorCode,Setting Preamble not supported");
5090 return 0;
5091 }
5092#endif
5093
5094 val = get_param(cmd, "Mode");
5095 if (val) {
5096 if (strcmp(val, "11b") == 0 ||
5097 strcmp(val, "11g") == 0 ||
5098 strcmp(val, "11a") == 0 ||
5099 strcmp(val, "11n") == 0 ||
5100 strcmp(val, "11ng") == 0 ||
5101 strcmp(val, "11nl") == 0 ||
5102 strcmp(val, "11nl(nabg)") == 0 ||
5103 strcmp(val, "AC") == 0 ||
5104 strcmp(val, "11AC") == 0 ||
5105 strcmp(val, "11ac") == 0 ||
5106 strcmp(val, "11na") == 0 ||
Amarnath Hullur Subramanyamb0db2712018-01-30 19:40:35 -08005107 strcmp(val, "11an") == 0 ||
5108 strcmp(val, "11ax") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005109 /* STA supports all modes by default */
5110 } else {
5111 send_resp(dut, conn, SIGMA_ERROR,
5112 "ErrorCode,Setting Mode not supported");
5113 return 0;
5114 }
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08005115
5116 /* Change the mode only in case of testbed for HE program
5117 * and for 11a and 11g modes only. */
5118 if (dut->program == PROGRAM_HE &&
5119 dut->device_type == STA_testbed) {
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05305120 sta_set_phymode(dut, intf, val);
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08005121 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005122 }
5123
5124 val = get_param(cmd, "wmm");
5125 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005126 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005127 case DRIVER_ATHEROS:
5128 ath_sta_set_wmm(dut, intf, val);
5129 break;
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08005130 case DRIVER_WCN:
5131 wcn_sta_set_wmm(dut, intf, val);
5132 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005133 default:
5134 sigma_dut_print(dut, DUT_MSG_DEBUG,
5135 "Setting wmm not supported");
5136 break;
5137 }
5138 }
5139
5140 val = get_param(cmd, "Powersave");
5141 if (val) {
5142 if (strcmp(val, "0") == 0 || strcasecmp(val, "off") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005143 if (get_driver_type(dut) == DRIVER_WCN) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +05305144 if (set_power_save_wcn(dut, intf, 2) < 0)
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005145 return 0;
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005146 }
5147
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005148 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005149 "P2P_SET ps 0") < 0)
5150 return -2;
5151 /* Make sure test modes are disabled */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005152 wpa_command(get_station_ifname(dut), "P2P_SET ps 98");
5153 wpa_command(get_station_ifname(dut), "P2P_SET ps 96");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005154 } else if (strcmp(val, "1") == 0 ||
5155 strcasecmp(val, "PSPoll") == 0 ||
5156 strcasecmp(val, "on") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005157 if (get_driver_type(dut) == DRIVER_WCN) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +05305158 if (set_power_save_wcn(dut, intf, 1) < 0)
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005159 return 0;
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005160 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005161 /* Disable default power save mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005162 wpa_command(get_station_ifname(dut), "P2P_SET ps 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005163 /* Enable PS-Poll test mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005164 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005165 "P2P_SET ps 97") < 0 ||
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005166 wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005167 "P2P_SET ps 99") < 0)
5168 return -2;
5169 } else if (strcmp(val, "2") == 0 ||
5170 strcasecmp(val, "Fast") == 0) {
5171 /* TODO */
5172 send_resp(dut, conn, SIGMA_ERROR,
5173 "ErrorCode,Powersave=Fast not supported");
5174 return 0;
5175 } else if (strcmp(val, "3") == 0 ||
5176 strcasecmp(val, "PSNonPoll") == 0) {
5177 /* Make sure test modes are disabled */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005178 wpa_command(get_station_ifname(dut), "P2P_SET ps 98");
5179 wpa_command(get_station_ifname(dut), "P2P_SET ps 96");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005180
5181 /* Enable default power save mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005182 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005183 "P2P_SET ps 1") < 0)
5184 return -2;
5185 } else
5186 return -1;
5187 }
5188
5189 val = get_param(cmd, "NoAck");
5190 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005191 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005192 case DRIVER_ATHEROS:
5193 ath_sta_set_noack(dut, intf, val);
5194 break;
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08005195#ifdef NL80211_SUPPORT
5196 case DRIVER_WCN:
5197 wcn_sta_set_noack(dut, intf, val);
5198 break;
5199#endif /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005200 default:
5201 send_resp(dut, conn, SIGMA_ERROR,
5202 "ErrorCode,Setting NoAck not supported");
5203 return 0;
5204 }
5205 }
5206
5207 val = get_param(cmd, "IgnoreChswitchProhibit");
5208 if (val) {
5209 /* TODO: Enabled/disabled */
5210 if (strcasecmp(val, "Enabled") == 0) {
5211 send_resp(dut, conn, SIGMA_ERROR,
5212 "ErrorCode,Enabling IgnoreChswitchProhibit "
5213 "not supported");
5214 return 0;
5215 }
5216 }
5217
5218 val = get_param(cmd, "TDLS");
5219 if (val) {
5220 if (strcasecmp(val, "Disabled") == 0) {
5221 if (wpa_command(intf, "SET tdls_disabled 1")) {
5222 send_resp(dut, conn, SIGMA_ERROR,
5223 "ErrorCode,Failed to disable TDLS");
5224 return 0;
5225 }
5226 } else if (strcasecmp(val, "Enabled") == 0) {
5227 if (wpa_command(intf, "SET tdls_disabled 0")) {
5228 send_resp(dut, conn, SIGMA_ERROR,
5229 "ErrorCode,Failed to enable TDLS");
5230 return 0;
5231 }
5232 } else {
5233 send_resp(dut, conn, SIGMA_ERROR,
5234 "ErrorCode,Unsupported TDLS value");
5235 return 0;
5236 }
5237 }
5238
5239 val = get_param(cmd, "TDLSmode");
5240 if (val) {
5241 if (strcasecmp(val, "Default") == 0) {
5242 wpa_command(intf, "SET tdls_testing 0");
5243 } else if (strcasecmp(val, "APProhibit") == 0) {
5244 if (wpa_command(intf, "SET tdls_testing 0x400")) {
5245 send_resp(dut, conn, SIGMA_ERROR,
5246 "ErrorCode,Failed to enable ignore "
5247 "APProhibit TDLS mode");
5248 return 0;
5249 }
5250 } else if (strcasecmp(val, "HiLoMac") == 0) {
5251 /* STA should respond with TDLS setup req for a TDLS
5252 * setup req */
5253 if (wpa_command(intf, "SET tdls_testing 0x80")) {
5254 send_resp(dut, conn, SIGMA_ERROR,
5255 "ErrorCode,Failed to enable HiLoMac "
5256 "TDLS mode");
5257 return 0;
5258 }
5259 } else if (strcasecmp(val, "WeakSecurity") == 0) {
5260 /*
5261 * Since all security modes are enabled by default when
5262 * Sigma control is used, there is no need to do
5263 * anything here.
5264 */
5265 } else if (strcasecmp(val, "ExistLink") == 0) {
5266 /*
5267 * Since we allow new TDLS Setup Request even if there
5268 * is an existing link, nothing needs to be done for
5269 * this.
5270 */
5271 } else {
5272 /* TODO:
5273 * ExistLink: STA should send TDLS setup req even if
5274 * direct link already exists
5275 */
5276 send_resp(dut, conn, SIGMA_ERROR,
5277 "ErrorCode,Unsupported TDLSmode value");
5278 return 0;
5279 }
5280 }
5281
5282 val = get_param(cmd, "FakePubKey");
5283 if (val && atoi(val) && wpa_command(intf, "SET wps_corrupt_pkhash 1")) {
5284 send_resp(dut, conn, SIGMA_ERROR,
5285 "ErrorCode,Failed to enable FakePubKey");
5286 return 0;
5287 }
5288
Amarnath Hullur Subramanyamae1042b2018-02-22 21:52:52 -08005289#ifdef NL80211_SUPPORT
5290 val = get_param(cmd, "FrgmntSupport");
5291 if (val) {
5292 if (strcasecmp(val, "Enable") == 0) {
5293 if (sta_set_he_fragmentation(dut, intf,
5294 HE_FRAG_LEVEL1)) {
5295 send_resp(dut, conn, SIGMA_ERROR,
5296 "ErrorCode,Failed to enable HE Fragmentation");
5297 return 0;
5298 }
5299 } else if (strcasecmp(val, "Disable") == 0) {
5300 if (sta_set_he_fragmentation(dut, intf,
5301 HE_FRAG_DISABLE)) {
5302 send_resp(dut, conn, SIGMA_ERROR,
5303 "ErrorCode,Failed to disable HE Fragmentation");
5304 return 0;
5305 }
5306 }
5307 }
5308#endif /* NL80211_SUPPORT */
5309
Vinita S. Maloo8a4779c2020-06-22 19:32:37 +05305310 val = get_param(cmd, "IncludeMSCSDescriptor");
5311 if (val && strcasecmp(val, "1") == 0) {
5312 char buf[128];
5313 int len;
5314
5315 len = snprintf(buf, sizeof(buf),
Veerendranath Jakkam62cde372020-08-19 18:03:06 +05305316 "MSCS add up_bitmap=F0 up_limit=7 stream_timeout=60000 frame_classifier=045F%032x",
Vinita S. Maloo8a4779c2020-06-22 19:32:37 +05305317 0);
5318
5319 if (len < 0 || len >= sizeof(buf)) {
5320 sigma_dut_print(dut, DUT_MSG_ERROR,
5321 "Failed to build MSCS Descriptor IE");
5322 return ERROR_SEND_STATUS;
5323 }
5324
5325 if (wpa_command(intf, buf) != 0) {
5326 send_resp(dut, conn, SIGMA_ERROR,
5327 "ErrorCode,Failed to include MSCS descriptor");
5328 return STATUS_SENT_ERROR;
5329 }
5330 }
5331
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005332 return 1;
5333}
5334
5335
5336static const char * ath_get_radio_name(const char *radio_name)
5337{
5338 if (radio_name == NULL)
5339 return "wifi0";
5340 if (strcmp(radio_name, "wifi1") == 0)
5341 return "wifi1";
5342 if (strcmp(radio_name, "wifi2") == 0)
5343 return "wifi2";
5344 return "wifi0";
5345}
5346
5347
5348static void ath_sta_set_txsp_stream(struct sigma_dut *dut, const char *intf,
5349 const char *val)
5350{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005351 unsigned int vht_mcsmap = 0;
5352 int txchainmask = 0;
5353 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
5354
5355 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
5356 if (dut->testbed_flag_txsp == 1) {
5357 vht_mcsmap = 0xfffc;
5358 dut->testbed_flag_txsp = 0;
5359 } else {
5360 vht_mcsmap = 0xfffe;
5361 }
5362 txchainmask = 1;
5363 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
5364 if (dut->testbed_flag_txsp == 1) {
5365 vht_mcsmap = 0xfff0;
5366 dut->testbed_flag_txsp = 0;
5367 } else {
5368 vht_mcsmap = 0xfffa;
5369 }
5370 txchainmask = 3;
5371 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
5372 if (dut->testbed_flag_txsp == 1) {
5373 vht_mcsmap = 0xffc0;
5374 dut->testbed_flag_txsp = 0;
5375 } else {
5376 vht_mcsmap = 0xffea;
5377 }
5378 txchainmask = 7;
5379 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
5380 if (dut->testbed_flag_txsp == 1) {
5381 vht_mcsmap = 0xff00;
5382 dut->testbed_flag_txsp = 0;
5383 } else {
5384 vht_mcsmap = 0xffaa;
5385 }
5386 txchainmask = 15;
5387 } else {
5388 if (dut->testbed_flag_txsp == 1) {
5389 vht_mcsmap = 0xffc0;
5390 dut->testbed_flag_txsp = 0;
5391 } else {
5392 vht_mcsmap = 0xffea;
5393 }
5394 }
5395
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005396 if (txchainmask)
5397 run_iwpriv(dut, basedev, "txchainmask %d", txchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005398
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005399 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005400}
5401
5402
5403static void ath_sta_set_rxsp_stream(struct sigma_dut *dut, const char *intf,
5404 const char *val)
5405{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005406 unsigned int vht_mcsmap = 0;
5407 int rxchainmask = 0;
5408 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
5409
5410 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
5411 if (dut->testbed_flag_rxsp == 1) {
5412 vht_mcsmap = 0xfffc;
5413 dut->testbed_flag_rxsp = 0;
5414 } else {
5415 vht_mcsmap = 0xfffe;
5416 }
5417 rxchainmask = 1;
5418 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
5419 if (dut->testbed_flag_rxsp == 1) {
5420 vht_mcsmap = 0xfff0;
5421 dut->testbed_flag_rxsp = 0;
5422 } else {
5423 vht_mcsmap = 0xfffa;
5424 }
5425 rxchainmask = 3;
5426 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
5427 if (dut->testbed_flag_rxsp == 1) {
5428 vht_mcsmap = 0xffc0;
5429 dut->testbed_flag_rxsp = 0;
5430 } else {
5431 vht_mcsmap = 0xffea;
5432 }
5433 rxchainmask = 7;
5434 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
5435 if (dut->testbed_flag_rxsp == 1) {
5436 vht_mcsmap = 0xff00;
5437 dut->testbed_flag_rxsp = 0;
5438 } else {
5439 vht_mcsmap = 0xffaa;
5440 }
5441 rxchainmask = 15;
5442 } else {
5443 if (dut->testbed_flag_rxsp == 1) {
5444 vht_mcsmap = 0xffc0;
5445 dut->testbed_flag_rxsp = 0;
5446 } else {
5447 vht_mcsmap = 0xffea;
5448 }
5449 }
5450
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005451 if (rxchainmask)
5452 run_iwpriv(dut, basedev, "rxchainmask %d", rxchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005453
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005454 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005455}
5456
5457
5458void ath_set_zero_crc(struct sigma_dut *dut, const char *val)
5459{
5460 if (strcasecmp(val, "enable") == 0) {
5461 if (system("athdiag --set --address=0x2a204 --and=0xbfffffff")
5462 != 0) {
5463 sigma_dut_print(dut, DUT_MSG_ERROR,
5464 "Disable BB_VHTSIGB_CRC_CALC failed");
5465 }
5466
5467 if (system("athdiag --set --address=0x2a204 --or=0x80000000")
5468 != 0) {
5469 sigma_dut_print(dut, DUT_MSG_ERROR,
5470 "Enable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
5471 }
5472 } else {
5473 if (system("athdiag --set --address=0x2a204 --and=0x7fffffff")
5474 != 0) {
5475 sigma_dut_print(dut, DUT_MSG_ERROR,
5476 "Disable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
5477 }
5478
5479 if (system("athdiag --set --address=0x2a204 --or=0x40000000")
5480 != 0) {
5481 sigma_dut_print(dut, DUT_MSG_ERROR,
5482 "Enable BB_VHTSIGB_CRC_CALC failed");
5483 }
5484 }
5485}
5486
5487
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005488static int wcn_sta_set_width(struct sigma_dut *dut, const char *intf,
5489 const char *val)
5490{
5491 char buf[60];
5492
5493 if (strcmp(val, "20") == 0) {
5494 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
5495 dut->chwidth = 0;
5496 } else if (strcmp(val, "40") == 0) {
5497 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 1", intf);
5498 dut->chwidth = 1;
5499 } else if (strcmp(val, "80") == 0) {
5500 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
5501 dut->chwidth = 2;
Sunil Duttb1cccac2018-05-22 21:03:12 +05305502 } else if (strcasecmp(val, "Auto") == 0) {
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005503 buf[0] = '\0';
5504 } else {
5505 sigma_dut_print(dut, DUT_MSG_ERROR, "WIDTH %s not supported",
5506 val);
5507 return -1;
5508 }
5509
5510 if (buf[0] != '\0' && system(buf) != 0) {
5511 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv chwidth failed");
5512 return -1;
5513 }
5514
5515 return 0;
5516}
5517
5518
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005519static int nlvendor_sta_set_addba_reject(struct sigma_dut *dut,
5520 const char *intf, int addbareject)
5521{
5522#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05305523 return wcn_wifi_test_config_set_u8(
5524 dut, intf,
5525 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ACCEPT_ADDBA_REQ,
5526 !addbareject);
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005527#else /* NL80211_SUPPORT */
5528 sigma_dut_print(dut, DUT_MSG_ERROR,
5529 "ADDBA_REJECT cannot be set without NL80211_SUPPORT defined");
5530 return -1;
5531#endif /* NL80211_SUPPORT */
5532}
5533
5534
5535static int sta_set_addba_reject(struct sigma_dut *dut, const char *intf,
5536 int addbareject)
5537{
5538 int ret;
5539
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005540 switch (get_driver_type(dut)) {
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005541 case DRIVER_WCN:
5542 ret = nlvendor_sta_set_addba_reject(dut, intf, addbareject);
5543 if (ret) {
5544 sigma_dut_print(dut, DUT_MSG_ERROR,
5545 "nlvendor_sta_set_addba_reject failed, ret:%d",
5546 ret);
5547 return ret;
5548 }
5549 break;
5550 default:
5551 sigma_dut_print(dut, DUT_MSG_ERROR,
5552 "errorCode,Unsupported ADDBA_REJECT with the current driver");
5553 ret = -1;
5554 break;
5555 }
5556
5557 return ret;
5558}
5559
5560
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005561static int nlvendor_config_send_addba(struct sigma_dut *dut, const char *intf,
5562 int enable)
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005563{
5564#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05305565 return wcn_wifi_test_config_set_u8(
5566 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SEND_ADDBA_REQ,
5567 enable);
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005568#else /* NL80211_SUPPORT */
5569 sigma_dut_print(dut, DUT_MSG_ERROR,
5570 "Disable addba not possible without NL80211_SUPPORT defined");
5571 return -1;
5572#endif /* NL80211_SUPPORT */
5573}
5574
5575
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305576#ifdef NL80211_SUPPORT
5577static int nl80211_sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
5578{
5579 struct nl_msg *msg;
5580 int ret = 0;
5581 int ifindex;
5582
5583 ifindex = if_nametoindex(intf);
5584 if (ifindex == 0) {
5585 sigma_dut_print(dut, DUT_MSG_ERROR,
5586 "%s: Index for interface %s failed",
5587 __func__, intf);
5588 return -1;
5589 }
5590
5591 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5592 NL80211_CMD_SET_WIPHY)) ||
5593 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) {
5594 sigma_dut_print(dut, DUT_MSG_ERROR,
5595 "%s: err in adding RTS threshold",
5596 __func__);
5597 nlmsg_free(msg);
5598 return -1;
5599 }
5600
5601 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5602 if (ret) {
5603 sigma_dut_print(dut, DUT_MSG_ERROR,
5604 "%s: err in send_and_recv_msgs, ret=%d",
5605 __func__, ret);
5606 }
5607 return ret;
5608}
5609#endif /* NL80211_SUPPORT */
5610
5611
5612static int sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
5613{
5614 char buf[100];
5615
5616#ifdef NL80211_SUPPORT
5617 if (nl80211_sta_set_rts(dut, intf, val) == 0)
5618 return 0;
5619 sigma_dut_print(dut, DUT_MSG_DEBUG,
5620 "Fall back to using iwconfig for setting RTS threshold");
5621#endif /* NL80211_SUPPORT */
5622
5623 snprintf(buf, sizeof(buf), "iwconfig %s rts %d", intf, val);
5624 if (system(buf) != 0) {
5625 sigma_dut_print(dut, DUT_MSG_ERROR,
5626 "Failed to set RTS threshold %d", val);
5627 return -1;
5628 }
5629 return 0;
5630}
5631
5632
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03005633static enum sigma_cmd_result
5634cmd_sta_set_wireless_common(const char *intf, struct sigma_dut *dut,
5635 struct sigma_conn *conn, struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005636{
5637 const char *val;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005638 int ampdu = -1, addbareject = -1;
Jouni Malinen3aa72862019-05-29 23:14:51 +03005639 char buf[128];
5640 int res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005641
5642 val = get_param(cmd, "40_INTOLERANT");
5643 if (val) {
5644 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5645 /* TODO: iwpriv ht40intol through wpa_supplicant */
5646 send_resp(dut, conn, SIGMA_ERROR,
5647 "ErrorCode,40_INTOLERANT not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03005648 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005649 }
5650 }
5651
5652 val = get_param(cmd, "ADDBA_REJECT");
5653 if (val) {
5654 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5655 /* reject any ADDBA with status "decline" */
5656 ampdu = 0;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005657 addbareject = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005658 } else {
5659 /* accept ADDBA */
5660 ampdu = 1;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005661 addbareject = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005662 }
5663 }
5664
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005665 if (addbareject >= 0 &&
5666 sta_set_addba_reject(dut, intf, addbareject) < 0) {
5667 send_resp(dut, conn, SIGMA_ERROR,
5668 "ErrorCode,set addba_reject failed");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03005669 return STATUS_SENT_ERROR;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005670 }
5671
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005672 val = get_param(cmd, "AMPDU");
5673 if (val) {
5674 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5675 /* enable AMPDU Aggregation */
5676 if (ampdu == 0) {
5677 send_resp(dut, conn, SIGMA_ERROR,
5678 "ErrorCode,Mismatch in "
5679 "addba_reject/ampdu - "
5680 "not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03005681 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005682 }
5683 ampdu = 1;
5684 } else {
5685 /* disable AMPDU Aggregation */
5686 if (ampdu == 1) {
5687 send_resp(dut, conn, SIGMA_ERROR,
5688 "ErrorCode,Mismatch in "
5689 "addba_reject/ampdu - "
5690 "not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03005691 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005692 }
5693 ampdu = 0;
5694 }
5695 }
5696
5697 if (ampdu >= 0) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005698 int ret;
5699
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005700 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s A-MPDU aggregation",
5701 ampdu ? "Enabling" : "Disabling");
5702 snprintf(buf, sizeof(buf), "SET ampdu %d", ampdu);
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07005703 if (wpa_command(intf, buf) < 0 &&
5704 iwpriv_sta_set_ampdu(dut, intf, ampdu) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005705 send_resp(dut, conn, SIGMA_ERROR,
5706 "ErrorCode,set aggr failed");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03005707 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005708 }
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005709
5710 if (ampdu == 0) {
5711 /* Disable sending of addba using nl vendor command */
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005712 ret = nlvendor_config_send_addba(dut, intf, 0);
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005713 if (ret) {
5714 sigma_dut_print(dut, DUT_MSG_ERROR,
5715 "Failed to disable addba, ret:%d",
5716 ret);
5717 }
5718 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005719 }
5720
5721 val = get_param(cmd, "AMSDU");
5722 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005723 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005724 case DRIVER_ATHEROS:
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08005725 case DRIVER_WCN:
5726 iwpriv_sta_set_amsdu(dut, intf, val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005727 break;
5728 default:
5729 if (strcmp(val, "1") == 0 ||
5730 strcasecmp(val, "Enable") == 0) {
5731 /* Enable AMSDU Aggregation */
5732 send_resp(dut, conn, SIGMA_ERROR,
5733 "ErrorCode,AMSDU aggregation not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03005734 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005735 }
5736 break;
5737 }
5738 }
5739
5740 val = get_param(cmd, "STBC_RX");
5741 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005742 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005743 case DRIVER_ATHEROS:
5744 ath_sta_set_stbc(dut, intf, val);
5745 break;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05305746 case DRIVER_WCN:
5747 wcn_sta_set_stbc(dut, intf, val);
5748 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005749 default:
5750 send_resp(dut, conn, SIGMA_ERROR,
5751 "ErrorCode,STBC_RX not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03005752 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005753 }
5754 }
5755
5756 val = get_param(cmd, "WIDTH");
5757 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005758 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005759 case DRIVER_WCN:
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005760 if (wcn_sta_set_width(dut, intf, val) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005761 send_resp(dut, conn, SIGMA_ERROR,
5762 "ErrorCode,Failed to set WIDTH");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03005763 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005764 }
5765 break;
5766 case DRIVER_ATHEROS:
5767 if (ath_set_width(dut, conn, intf, val) < 0)
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03005768 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005769 break;
5770 default:
5771 sigma_dut_print(dut, DUT_MSG_ERROR,
5772 "Setting WIDTH not supported");
5773 break;
5774 }
5775 }
5776
5777 val = get_param(cmd, "SMPS");
5778 if (val) {
5779 /* TODO: Dynamic/0, Static/1, No Limit/2 */
5780 send_resp(dut, conn, SIGMA_ERROR,
5781 "ErrorCode,SMPS not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03005782 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005783 }
5784
5785 val = get_param(cmd, "TXSP_STREAM");
5786 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005787 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005788 case DRIVER_WCN:
5789 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
5790 send_resp(dut, conn, SIGMA_ERROR,
5791 "ErrorCode,Failed to set TXSP_STREAM");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03005792 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005793 }
5794 break;
5795 case DRIVER_ATHEROS:
5796 ath_sta_set_txsp_stream(dut, intf, val);
5797 break;
5798 default:
5799 sigma_dut_print(dut, DUT_MSG_ERROR,
5800 "Setting TXSP_STREAM not supported");
5801 break;
5802 }
5803 }
5804
5805 val = get_param(cmd, "RXSP_STREAM");
5806 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005807 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005808 case DRIVER_WCN:
5809 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
5810 send_resp(dut, conn, SIGMA_ERROR,
5811 "ErrorCode,Failed to set RXSP_STREAM");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03005812 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005813 }
5814 break;
5815 case DRIVER_ATHEROS:
5816 ath_sta_set_rxsp_stream(dut, intf, val);
5817 break;
5818 default:
5819 sigma_dut_print(dut, DUT_MSG_ERROR,
5820 "Setting RXSP_STREAM not supported");
5821 break;
5822 }
5823 }
5824
5825 val = get_param(cmd, "DYN_BW_SGNL");
5826 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005827 switch (get_driver_type(dut)) {
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005828 case DRIVER_WCN:
Peng Xuc59afd32016-11-21 15:01:11 -08005829 if (strcasecmp(val, "enable") == 0) {
5830 snprintf(buf, sizeof(buf),
5831 "iwpriv %s cwmenable 1", intf);
5832 if (system(buf) != 0) {
5833 sigma_dut_print(dut, DUT_MSG_ERROR,
5834 "iwpriv cwmenable 1 failed");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03005835 return ERROR_SEND_STATUS;
Peng Xuc59afd32016-11-21 15:01:11 -08005836 }
5837 } else if (strcasecmp(val, "disable") == 0) {
5838 snprintf(buf, sizeof(buf),
5839 "iwpriv %s cwmenable 0", intf);
5840 if (system(buf) != 0) {
5841 sigma_dut_print(dut, DUT_MSG_ERROR,
5842 "iwpriv cwmenable 0 failed");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03005843 return ERROR_SEND_STATUS;
Peng Xuc59afd32016-11-21 15:01:11 -08005844 }
5845 } else {
5846 sigma_dut_print(dut, DUT_MSG_ERROR,
5847 "Unsupported DYN_BW_SGL");
5848 }
5849
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005850 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
5851 if (system(buf) != 0) {
5852 sigma_dut_print(dut, DUT_MSG_ERROR,
5853 "Failed to set cts_cbw in DYN_BW_SGNL");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03005854 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005855 }
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005856 break;
5857 case DRIVER_ATHEROS:
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07005858 novap_reset(dut, intf, 1);
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005859 ath_config_dyn_bw_sig(dut, intf, val);
5860 break;
5861 default:
5862 sigma_dut_print(dut, DUT_MSG_ERROR,
5863 "Failed to set DYN_BW_SGNL");
5864 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005865 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005866 }
5867
5868 val = get_param(cmd, "RTS_FORCE");
5869 if (val) {
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07005870 novap_reset(dut, intf, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005871 if (strcasecmp(val, "Enable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305872 if (sta_set_rts(dut, intf, 64) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02005873 sigma_dut_print(dut, DUT_MSG_ERROR,
5874 "Failed to set RTS_FORCE 64");
5875 }
Jouni Malinen3aa72862019-05-29 23:14:51 +03005876 res = snprintf(buf, sizeof(buf),
5877 "wifitool %s beeliner_fw_test 100 1",
5878 intf);
5879 if (res < 0 || res >= sizeof(buf) || system(buf) != 0) {
priyadharshini gowthaman270870e2015-12-09 10:10:23 -08005880 sigma_dut_print(dut, DUT_MSG_ERROR,
5881 "wifitool beeliner_fw_test 100 1 failed");
5882 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005883 } else if (strcasecmp(val, "Disable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305884 if (sta_set_rts(dut, intf, 2347) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02005885 sigma_dut_print(dut, DUT_MSG_ERROR,
5886 "Failed to set RTS_FORCE 2347");
5887 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005888 } else {
5889 send_resp(dut, conn, SIGMA_ERROR,
5890 "ErrorCode,RTS_FORCE value not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03005891 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005892 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005893 }
5894
5895 val = get_param(cmd, "CTS_WIDTH");
5896 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005897 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005898 case DRIVER_WCN:
5899 if (wcn_sta_set_cts_width(dut, intf, val) < 0) {
5900 send_resp(dut, conn, SIGMA_ERROR,
5901 "ErrorCode,Failed to set CTS_WIDTH");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03005902 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005903 }
5904 break;
5905 case DRIVER_ATHEROS:
5906 ath_set_cts_width(dut, intf, val);
5907 break;
5908 default:
5909 sigma_dut_print(dut, DUT_MSG_ERROR,
5910 "Setting CTS_WIDTH not supported");
5911 break;
5912 }
5913 }
5914
5915 val = get_param(cmd, "BW_SGNL");
5916 if (val) {
5917 if (strcasecmp(val, "Enable") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005918 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005919 } else if (strcasecmp(val, "Disable") == 0) {
5920 /* TODO: Disable */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005921 } else {
5922 send_resp(dut, conn, SIGMA_ERROR,
5923 "ErrorCode,BW_SGNL value not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03005924 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005925 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005926 }
5927
5928 val = get_param(cmd, "Band");
5929 if (val) {
5930 if (strcmp(val, "2.4") == 0 || strcmp(val, "5") == 0) {
5931 /* STA supports all bands by default */
5932 } else {
5933 send_resp(dut, conn, SIGMA_ERROR,
5934 "ErrorCode,Unsupported Band");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03005935 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005936 }
5937 }
5938
5939 val = get_param(cmd, "zero_crc");
5940 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005941 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005942 case DRIVER_ATHEROS:
5943 ath_set_zero_crc(dut, val);
5944 break;
5945 default:
5946 break;
5947 }
5948 }
5949
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03005950 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005951}
5952
5953
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005954static int sta_set_force_mcs(struct sigma_dut *dut, int force, int mcs)
5955{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005956 switch (get_driver_type(dut)) {
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005957#ifdef __linux__
5958 case DRIVER_WIL6210:
5959 return wil6210_set_force_mcs(dut, force, mcs);
5960#endif /* __linux__ */
5961 default:
5962 sigma_dut_print(dut, DUT_MSG_ERROR,
5963 "Unsupported sta_set_force_mcs with the current driver");
5964 return -1;
5965 }
5966}
5967
5968
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02005969static int sta_60g_force_rsn_ie(struct sigma_dut *dut, int state)
5970{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005971 switch (get_driver_type(dut)) {
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02005972#ifdef __linux__
5973 case DRIVER_WIL6210:
5974 return wil6210_force_rsn_ie(dut, state);
5975#endif /* __linux__ */
5976 default:
5977 sigma_dut_print(dut, DUT_MSG_ERROR,
5978 "Unsupported sta_60g_force_rsn_ie with the current driver");
5979 return -1;
5980 }
5981}
5982
5983
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005984static int sta_set_60g_common(struct sigma_dut *dut, struct sigma_conn *conn,
5985 struct sigma_cmd *cmd)
5986{
5987 const char *val;
5988 char buf[100];
5989
5990 val = get_param(cmd, "MSDUSize");
5991 if (val) {
5992 int mtu;
5993
5994 dut->amsdu_size = atoi(val);
5995 if (dut->amsdu_size > IEEE80211_MAX_DATA_LEN_DMG ||
5996 dut->amsdu_size < IEEE80211_SNAP_LEN_DMG) {
5997 sigma_dut_print(dut, DUT_MSG_ERROR,
5998 "MSDUSize %d is above max %d or below min %d",
5999 dut->amsdu_size,
6000 IEEE80211_MAX_DATA_LEN_DMG,
6001 IEEE80211_SNAP_LEN_DMG);
6002 dut->amsdu_size = 0;
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006003 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006004 }
6005
6006 mtu = dut->amsdu_size - IEEE80211_SNAP_LEN_DMG;
6007 sigma_dut_print(dut, DUT_MSG_DEBUG,
6008 "Setting amsdu_size to %d", mtu);
6009 snprintf(buf, sizeof(buf), "ifconfig %s mtu %d",
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006010 get_station_ifname(dut), mtu);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006011
6012 if (system(buf) != 0) {
6013 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
6014 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006015 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006016 }
6017 }
6018
6019 val = get_param(cmd, "BAckRcvBuf");
6020 if (val) {
6021 dut->back_rcv_buf = atoi(val);
6022 if (dut->back_rcv_buf == 0) {
6023 sigma_dut_print(dut, DUT_MSG_ERROR,
6024 "Failed to convert %s or value is 0",
6025 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006026 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006027 }
6028
6029 sigma_dut_print(dut, DUT_MSG_DEBUG,
6030 "Setting BAckRcvBuf to %s", val);
6031 }
6032
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006033 val = get_param(cmd, "MCS_FixedRate");
6034 if (val) {
6035 if (sta_set_force_mcs(dut, 1, atoi(val))) {
6036 sigma_dut_print(dut, DUT_MSG_ERROR,
6037 "Failed to force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006038 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006039 }
6040 }
6041
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006042 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006043}
6044
6045
6046static int sta_pcp_start(struct sigma_dut *dut, struct sigma_conn *conn,
6047 struct sigma_cmd *cmd)
6048{
6049 int net_id;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006050 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006051 const char *val;
6052 char buf[100];
6053
6054 dut->mode = SIGMA_MODE_STATION;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006055 ifname = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006056 if (wpa_command(ifname, "PING") != 0) {
6057 sigma_dut_print(dut, DUT_MSG_ERROR, "Supplicant not running");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006058 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006059 }
6060
6061 wpa_command(ifname, "FLUSH");
6062 net_id = add_network_common(dut, conn, ifname, cmd);
6063 if (net_id < 0) {
6064 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add network");
6065 return net_id;
6066 }
6067
6068 /* TODO: mode=2 for the AP; in the future, replace for mode PCP */
6069 if (set_network(ifname, net_id, "mode", "2") < 0) {
6070 sigma_dut_print(dut, DUT_MSG_ERROR,
6071 "Failed to set supplicant network mode");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006072 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006073 }
6074
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02006075 if (set_network(ifname, net_id, "pbss", "1") < 0)
6076 return -2;
6077
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006078 sigma_dut_print(dut, DUT_MSG_DEBUG,
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02006079 "Supplicant set network with mode 2. network_id %d",
6080 net_id);
6081
6082 if (set_network(ifname, net_id, "wps_disabled", "0") < 0) {
6083 sigma_dut_print(dut, DUT_MSG_INFO,
6084 "Failed to set supplicant to WPS ENABLE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006085 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02006086 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006087
6088 val = get_param(cmd, "Security");
6089 if (val && strcasecmp(val, "OPEN") == 0) {
6090 dut->ap_key_mgmt = AP_OPEN;
6091 if (set_network(ifname, net_id, "key_mgmt", "NONE") < 0) {
6092 sigma_dut_print(dut, DUT_MSG_ERROR,
6093 "Failed to set supplicant to %s security",
6094 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006095 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006096 }
6097 } else if (val && strcasecmp(val, "WPA2-PSK") == 0) {
6098 dut->ap_key_mgmt = AP_WPA2_PSK;
6099 if (set_network(ifname, net_id, "key_mgmt", "WPA-PSK") < 0) {
6100 sigma_dut_print(dut, DUT_MSG_ERROR,
6101 "Failed to set supplicant to %s security",
6102 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006103 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006104 }
6105
6106 if (set_network(ifname, net_id, "proto", "RSN") < 0) {
6107 sigma_dut_print(dut, DUT_MSG_ERROR,
6108 "Failed to set supplicant to proto RSN");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006109 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006110 }
6111 } else if (val) {
6112 sigma_dut_print(dut, DUT_MSG_ERROR,
6113 "Requested Security %s is not supported on 60GHz",
6114 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006115 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006116 }
6117
6118 val = get_param(cmd, "Encrypt");
6119 if (val && strcasecmp(val, "AES-GCMP") == 0) {
6120 if (set_network(ifname, net_id, "pairwise", "GCMP") < 0) {
6121 sigma_dut_print(dut, DUT_MSG_ERROR,
6122 "Failed to set supplicant to pairwise GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006123 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006124 }
6125 if (set_network(ifname, net_id, "group", "GCMP") < 0) {
6126 sigma_dut_print(dut, DUT_MSG_ERROR,
6127 "Failed to set supplicant to group GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006128 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006129 }
6130 } else if (val) {
6131 sigma_dut_print(dut, DUT_MSG_ERROR,
6132 "Requested Encrypt %s is not supported on 60 GHz",
6133 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006134 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006135 }
6136
6137 val = get_param(cmd, "PSK");
6138 if (val && set_network_quoted(ifname, net_id, "psk", val) < 0) {
6139 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set psk %s",
6140 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006141 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006142 }
6143
6144 /* Convert 60G channel to freq */
6145 switch (dut->ap_channel) {
6146 case 1:
6147 val = "58320";
6148 break;
6149 case 2:
6150 val = "60480";
6151 break;
6152 case 3:
6153 val = "62640";
6154 break;
6155 default:
6156 sigma_dut_print(dut, DUT_MSG_ERROR,
6157 "Failed to configure channel %d. Not supported",
6158 dut->ap_channel);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006159 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006160 }
6161
6162 if (set_network(ifname, net_id, "frequency", val) < 0) {
6163 sigma_dut_print(dut, DUT_MSG_ERROR,
6164 "Failed to set supplicant network frequency");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006165 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006166 }
6167
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02006168 if (dut->eap_fragment) {
6169 sigma_dut_print(dut, DUT_MSG_DEBUG,
6170 "Set EAP fragment size to 128 bytes.");
6171 if (set_network(ifname, net_id, "fragment_size", "128") < 0)
6172 return ERROR_SEND_STATUS;
6173 }
6174
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006175 sigma_dut_print(dut, DUT_MSG_DEBUG,
6176 "Supplicant set network with frequency");
6177
6178 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d", net_id);
6179 if (wpa_command(ifname, buf) < 0) {
6180 sigma_dut_print(dut, DUT_MSG_INFO,
6181 "Failed to select network id %d on %s",
6182 net_id, ifname);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006183 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006184 }
6185
6186 sigma_dut_print(dut, DUT_MSG_DEBUG, "Selected network");
6187
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006188 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006189}
6190
6191
Lior David67543f52017-01-03 19:04:22 +02006192static int wil6210_set_abft_len(struct sigma_dut *dut, int abft_len)
6193{
6194 char buf[128], fname[128];
6195 FILE *f;
Jouni Malinen3aa72862019-05-29 23:14:51 +03006196 int res;
Lior David67543f52017-01-03 19:04:22 +02006197
6198 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
6199 sigma_dut_print(dut, DUT_MSG_ERROR,
6200 "failed to get wil6210 debugfs dir");
6201 return -1;
6202 }
6203
Jouni Malinen3aa72862019-05-29 23:14:51 +03006204 res = snprintf(fname, sizeof(fname), "%s/abft_len", buf);
6205 if (res < 0 || res >= sizeof(fname))
6206 return -1;
Lior David67543f52017-01-03 19:04:22 +02006207 f = fopen(fname, "w");
6208 if (!f) {
6209 sigma_dut_print(dut, DUT_MSG_ERROR,
6210 "failed to open: %s", fname);
6211 return -1;
6212 }
6213
6214 fprintf(f, "%d\n", abft_len);
6215 fclose(f);
6216
6217 return 0;
6218}
6219
6220
Alexei Avshalom Lazar49498b82019-01-31 15:16:32 +02006221int sta_set_60g_abft_len(struct sigma_dut *dut, struct sigma_conn *conn,
6222 int abft_len)
Lior David67543f52017-01-03 19:04:22 +02006223{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006224 switch (get_driver_type(dut)) {
Lior David67543f52017-01-03 19:04:22 +02006225 case DRIVER_WIL6210:
6226 return wil6210_set_abft_len(dut, abft_len);
6227 default:
6228 sigma_dut_print(dut, DUT_MSG_ERROR,
6229 "set abft_len not supported");
6230 return -1;
6231 }
6232}
6233
6234
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006235static int sta_set_60g_pcp(struct sigma_dut *dut, struct sigma_conn *conn,
6236 struct sigma_cmd *cmd)
6237{
6238 const char *val;
Lior David67543f52017-01-03 19:04:22 +02006239 unsigned int abft_len = 1; /* default is one slot */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006240
6241 if (dut->dev_role != DEVROLE_PCP) {
6242 send_resp(dut, conn, SIGMA_INVALID,
6243 "ErrorCode,Invalid DevRole");
6244 return 0;
6245 }
6246
6247 val = get_param(cmd, "SSID");
6248 if (val) {
6249 if (strlen(val) > sizeof(dut->ap_ssid) - 1) {
6250 send_resp(dut, conn, SIGMA_INVALID,
6251 "ErrorCode,Invalid SSID");
6252 return -1;
6253 }
6254
Peng Xub8fc5cc2017-05-10 17:27:28 -07006255 strlcpy(dut->ap_ssid, val, sizeof(dut->ap_ssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006256 }
6257
6258 val = get_param(cmd, "CHANNEL");
6259 if (val) {
6260 const char *pos;
6261
6262 dut->ap_channel = atoi(val);
6263 pos = strchr(val, ';');
6264 if (pos) {
6265 pos++;
6266 dut->ap_channel_1 = atoi(pos);
6267 }
6268 }
6269
6270 switch (dut->ap_channel) {
6271 case 1:
6272 case 2:
6273 case 3:
6274 break;
6275 default:
6276 sigma_dut_print(dut, DUT_MSG_ERROR,
6277 "Channel %d is not supported", dut->ap_channel);
6278 send_resp(dut, conn, SIGMA_ERROR,
6279 "Requested channel is not supported");
6280 return -1;
6281 }
6282
6283 val = get_param(cmd, "BCNINT");
6284 if (val)
6285 dut->ap_bcnint = atoi(val);
6286
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006287 val = get_param(cmd, "AllocType");
6288 if (val) {
6289 send_resp(dut, conn, SIGMA_ERROR,
6290 "ErrorCode,AllocType is not supported yet");
6291 return -1;
6292 }
6293
6294 val = get_param(cmd, "PercentBI");
6295 if (val) {
6296 send_resp(dut, conn, SIGMA_ERROR,
6297 "ErrorCode,PercentBI is not supported yet");
6298 return -1;
6299 }
6300
6301 val = get_param(cmd, "CBAPOnly");
6302 if (val) {
6303 send_resp(dut, conn, SIGMA_ERROR,
6304 "ErrorCode,CBAPOnly is not supported yet");
6305 return -1;
6306 }
6307
6308 val = get_param(cmd, "AMPDU");
6309 if (val) {
6310 if (strcasecmp(val, "Enable") == 0)
6311 dut->ap_ampdu = 1;
6312 else if (strcasecmp(val, "Disable") == 0)
6313 dut->ap_ampdu = 2;
6314 else {
6315 send_resp(dut, conn, SIGMA_ERROR,
6316 "ErrorCode,AMPDU value is not Enable nor Disabled");
6317 return -1;
6318 }
6319 }
6320
6321 val = get_param(cmd, "AMSDU");
6322 if (val) {
6323 if (strcasecmp(val, "Enable") == 0)
6324 dut->ap_amsdu = 1;
6325 else if (strcasecmp(val, "Disable") == 0)
6326 dut->ap_amsdu = 2;
6327 }
6328
6329 val = get_param(cmd, "NumMSDU");
6330 if (val) {
6331 send_resp(dut, conn, SIGMA_ERROR,
6332 "ErrorCode, NumMSDU is not supported yet");
6333 return -1;
6334 }
6335
6336 val = get_param(cmd, "ABFTLRang");
6337 if (val) {
6338 sigma_dut_print(dut, DUT_MSG_DEBUG,
Lior David67543f52017-01-03 19:04:22 +02006339 "ABFTLRang parameter %s", val);
6340 if (strcmp(val, "Gt1") == 0)
6341 abft_len = 2; /* 2 slots in this case */
6342 }
6343
6344 if (sta_set_60g_abft_len(dut, conn, abft_len)) {
6345 send_resp(dut, conn, SIGMA_ERROR,
6346 "ErrorCode, Can't set ABFT length");
6347 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006348 }
6349
6350 if (sta_pcp_start(dut, conn, cmd) < 0) {
6351 send_resp(dut, conn, SIGMA_ERROR,
6352 "ErrorCode, Can't start PCP role");
6353 return -1;
6354 }
6355
6356 return sta_set_60g_common(dut, conn, cmd);
6357}
6358
6359
6360static int sta_set_60g_sta(struct sigma_dut *dut, struct sigma_conn *conn,
6361 struct sigma_cmd *cmd)
6362{
6363 const char *val = get_param(cmd, "DiscoveryMode");
6364
6365 if (dut->dev_role != DEVROLE_STA) {
6366 send_resp(dut, conn, SIGMA_INVALID,
6367 "ErrorCode,Invalid DevRole");
6368 return 0;
6369 }
6370
6371 if (val) {
6372 sigma_dut_print(dut, DUT_MSG_DEBUG, "Discovery: %s", val);
6373 /* Ignore Discovery mode till Driver expose API. */
6374#if 0
6375 if (strcasecmp(val, "1") == 0) {
6376 send_resp(dut, conn, SIGMA_INVALID,
6377 "ErrorCode,DiscoveryMode 1 not supported");
6378 return 0;
6379 }
6380
6381 if (strcasecmp(val, "0") == 0) {
6382 /* OK */
6383 } else {
6384 send_resp(dut, conn, SIGMA_INVALID,
6385 "ErrorCode,DiscoveryMode not supported");
6386 return 0;
6387 }
6388#endif
6389 }
6390
6391 if (start_sta_mode(dut) != 0)
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006392 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006393 return sta_set_60g_common(dut, conn, cmd);
6394}
6395
6396
Jouni Malinenf7222712019-06-13 01:50:21 +03006397static enum sigma_cmd_result cmd_sta_disconnect(struct sigma_dut *dut,
6398 struct sigma_conn *conn,
6399 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006400{
6401 const char *intf = get_param(cmd, "Interface");
Jouni Malinened77e672018-01-10 16:45:13 +02006402 const char *val = get_param(cmd, "maintain_profile");
vamsi krishnad605c422017-09-20 14:56:31 +05306403
Jouni Malinened77e672018-01-10 16:45:13 +02006404 if (dut->program == PROGRAM_OCE ||
Amarnath Hullur Subramanyamebeda9e2018-01-31 03:21:48 -08006405 dut->program == PROGRAM_HE ||
Jouni Malinened77e672018-01-10 16:45:13 +02006406 (val && atoi(val) == 1)) {
vamsi krishnad605c422017-09-20 14:56:31 +05306407 wpa_command(intf, "DISCONNECT");
6408 return 1;
6409 }
6410
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006411 disconnect_station(dut);
6412 /* Try to ignore old scan results to avoid HS 2.0R2 test case failures
6413 * due to cached results. */
6414 wpa_command(intf, "SET ignore_old_scan_res 1");
6415 wpa_command(intf, "BSS_FLUSH");
6416 return 1;
6417}
6418
6419
Jouni Malinenf7222712019-06-13 01:50:21 +03006420static enum sigma_cmd_result cmd_sta_reassoc(struct sigma_dut *dut,
6421 struct sigma_conn *conn,
6422 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006423{
6424 const char *intf = get_param(cmd, "Interface");
6425 const char *bssid = get_param(cmd, "bssid");
6426 const char *val = get_param(cmd, "CHANNEL");
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006427 const char *freq_val = get_param(cmd, "ChnlFreq");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006428 struct wpa_ctrl *ctrl;
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306429 char buf[1000];
Sunil Duttd30ce092018-01-11 23:56:29 +05306430 char result[32];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006431 int res;
6432 int chan = 0;
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006433 int freq = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006434 enum sigma_cmd_result status = STATUS_SENT;
Sunil Duttd30ce092018-01-11 23:56:29 +05306435 int fastreassoc = 1;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006436 int ft_ds = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006437
6438 if (bssid == NULL) {
6439 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing bssid "
6440 "argument");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006441 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006442 }
6443
6444 if (val)
6445 chan = atoi(val);
6446
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006447 if (freq_val)
6448 freq = atoi(freq_val);
6449
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006450 if (wifi_chip_type != DRIVER_WCN && wifi_chip_type != DRIVER_AR6003) {
6451 /* The current network may be from sta_associate or
6452 * sta_hs2_associate
6453 */
6454 if (set_network(intf, dut->infra_network_id, "bssid", bssid) <
6455 0 ||
6456 set_network(intf, 0, "bssid", bssid) < 0)
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006457 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006458 }
6459
6460 ctrl = open_wpa_mon(intf);
6461 if (ctrl == NULL) {
6462 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
6463 "wpa_supplicant monitor connection");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006464 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006465 }
6466
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006467 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Sunil Duttd30ce092018-01-11 23:56:29 +05306468 sizeof(result)) < 0 ||
6469 strncmp(result, "COMPLETED", 9) != 0) {
6470 sigma_dut_print(dut, DUT_MSG_DEBUG,
6471 "sta_reassoc: Not connected");
6472 fastreassoc = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006473 } else if (dut->sta_ft_ds) {
6474 sigma_dut_print(dut, DUT_MSG_DEBUG,
6475 "sta_reassoc: Use FT-over-DS");
6476 ft_ds = 1;
Sunil Duttd30ce092018-01-11 23:56:29 +05306477 }
6478
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306479 if (dut->rsne_override) {
6480#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006481 if (get_driver_type(dut) == DRIVER_WCN &&
6482 dut->config_rsnie == 0) {
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05306483 sta_config_params(dut, intf, STA_SET_RSNIE, 1);
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306484 dut->config_rsnie = 1;
6485 }
6486#endif /* NL80211_SUPPORT */
6487 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
6488 dut->rsne_override);
6489 if (wpa_command(intf, buf) < 0) {
6490 send_resp(dut, conn, SIGMA_ERROR,
6491 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
6492 return 0;
6493 }
6494 }
6495
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006496 if (ft_ds) {
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006497 if (chan || freq) {
6498 if (!freq)
6499 freq = channel_to_freq(dut, chan);
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006500 if (!freq) {
6501 sigma_dut_print(dut, DUT_MSG_ERROR,
6502 "Invalid channel number provided: %d",
6503 chan);
6504 send_resp(dut, conn, SIGMA_INVALID,
6505 "ErrorCode,Invalid channel number");
6506 goto close_mon_conn;
6507 }
6508 res = snprintf(buf, sizeof(buf),
6509 "SCAN TYPE=ONLY freq=%d", freq);
6510 } else {
6511 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
6512 }
6513 if (res < 0 || res >= (int) sizeof(buf)) {
6514 send_resp(dut, conn, SIGMA_ERROR,
6515 "ErrorCode,snprintf failed");
6516 goto close_mon_conn;
6517 }
6518 if (wpa_command(intf, buf) < 0) {
6519 sigma_dut_print(dut, DUT_MSG_INFO,
6520 "Failed to start scan");
6521 send_resp(dut, conn, SIGMA_ERROR,
6522 "ErrorCode,scan failed");
6523 goto close_mon_conn;
6524 }
6525
6526 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
6527 buf, sizeof(buf));
6528 if (res < 0) {
6529 sigma_dut_print(dut, DUT_MSG_INFO,
6530 "Scan did not complete");
6531 send_resp(dut, conn, SIGMA_ERROR,
6532 "ErrorCode,scan did not complete");
6533 goto close_mon_conn;
6534 }
6535
6536 res = snprintf(buf, sizeof(buf), "FT_DS %s", bssid);
6537 if (res > 0 && res < (int) sizeof(buf))
6538 res = wpa_command(intf, buf);
6539
6540 if (res < 0 || res >= (int) sizeof(buf)) {
6541 send_resp(dut, conn, SIGMA_ERROR,
6542 "errorCode,FT_DS command failed");
6543 status = STATUS_SENT_ERROR;
6544 goto close_mon_conn;
6545 }
6546 } else if (wifi_chip_type == DRIVER_WCN && fastreassoc) {
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006547 if (chan || freq) {
6548 if (!freq)
6549 freq = channel_to_freq(dut, chan);
Ashwini Patil4c8158f2017-05-25 12:49:21 +05306550 if (!freq) {
6551 sigma_dut_print(dut, DUT_MSG_ERROR,
6552 "Invalid channel number provided: %d",
6553 chan);
6554 send_resp(dut, conn, SIGMA_INVALID,
6555 "ErrorCode,Invalid channel number");
6556 goto close_mon_conn;
6557 }
6558 res = snprintf(buf, sizeof(buf),
6559 "SCAN TYPE=ONLY freq=%d", freq);
6560 } else {
6561 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
6562 }
6563 if (res < 0 || res >= (int) sizeof(buf)) {
6564 send_resp(dut, conn, SIGMA_ERROR,
6565 "ErrorCode,snprintf failed");
6566 goto close_mon_conn;
6567 }
6568 if (wpa_command(intf, buf) < 0) {
6569 sigma_dut_print(dut, DUT_MSG_INFO,
6570 "Failed to start scan");
6571 send_resp(dut, conn, SIGMA_ERROR,
6572 "ErrorCode,scan failed");
6573 goto close_mon_conn;
6574 }
6575
6576 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
6577 buf, sizeof(buf));
6578 if (res < 0) {
6579 sigma_dut_print(dut, DUT_MSG_INFO,
6580 "Scan did not complete");
6581 send_resp(dut, conn, SIGMA_ERROR,
6582 "ErrorCode,scan did not complete");
6583 goto close_mon_conn;
6584 }
6585
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006586 if (set_network(intf, dut->infra_network_id, "bssid", "any")
6587 < 0) {
6588 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
6589 "bssid to any during FASTREASSOC");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006590 status = ERROR_SEND_STATUS;
Ashwini Patil467efef2017-05-25 12:18:27 +05306591 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006592 }
Vinita Maloo54b78cf2020-03-30 12:18:19 +05306593 res = snprintf(buf, sizeof(buf), "FASTREASSOC %s %d",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006594 bssid, chan);
Vinita Maloo54b78cf2020-03-30 12:18:19 +05306595 if (res < 0 || res >= (int) sizeof(buf) ||
6596 wcn_driver_cmd(intf, buf) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006597 send_resp(dut, conn, SIGMA_ERROR,
Vinita Maloo54b78cf2020-03-30 12:18:19 +05306598 "errorCode,Failed to run FASTREASSOC");
Ashwini Patil467efef2017-05-25 12:18:27 +05306599 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006600 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006601 sigma_dut_print(dut, DUT_MSG_INFO,
6602 "sta_reassoc: Run %s successful", buf);
6603 } else if (wpa_command(intf, "REASSOCIATE")) {
6604 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
6605 "request reassociation");
Ashwini Patil467efef2017-05-25 12:18:27 +05306606 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006607 }
6608
6609 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
6610 buf, sizeof(buf));
Ashwini Patil467efef2017-05-25 12:18:27 +05306611 if (res < 0) {
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006612 send_resp(dut, conn, SIGMA_ERROR,
6613 "errorCode,Connection did not complete");
6614 status = STATUS_SENT_ERROR;
Ashwini Patil467efef2017-05-25 12:18:27 +05306615 goto close_mon_conn;
6616 }
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006617 status = SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006618
Ashwini Patil467efef2017-05-25 12:18:27 +05306619close_mon_conn:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006620 wpa_ctrl_detach(ctrl);
6621 wpa_ctrl_close(ctrl);
Ashwini Patil467efef2017-05-25 12:18:27 +05306622 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006623}
6624
6625
6626static void hs2_clear_credentials(const char *intf)
6627{
6628 wpa_command(intf, "REMOVE_CRED all");
6629}
6630
6631
Lior Davidcc88b562017-01-03 18:52:09 +02006632#ifdef __linux__
6633static int wil6210_get_aid(struct sigma_dut *dut, const char *bssid,
6634 unsigned int *aid)
6635{
Lior David0fe101e2017-03-09 16:09:50 +02006636 const char *pattern = "AID[ \t]+([0-9]+)";
Lior Davidcc88b562017-01-03 18:52:09 +02006637
Lior David0fe101e2017-03-09 16:09:50 +02006638 return wil6210_get_sta_info_field(dut, bssid, pattern, aid);
Lior Davidcc88b562017-01-03 18:52:09 +02006639}
6640#endif /* __linux__ */
6641
6642
6643static int sta_get_aid_60g(struct sigma_dut *dut, const char *bssid,
6644 unsigned int *aid)
6645{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006646 switch (get_driver_type(dut)) {
Lior Davidcc88b562017-01-03 18:52:09 +02006647#ifdef __linux__
6648 case DRIVER_WIL6210:
6649 return wil6210_get_aid(dut, bssid, aid);
6650#endif /* __linux__ */
6651 default:
6652 sigma_dut_print(dut, DUT_MSG_ERROR, "get AID not supported");
6653 return -1;
6654 }
6655}
6656
6657
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006658static int sta_get_parameter_60g(struct sigma_dut *dut, struct sigma_conn *conn,
6659 struct sigma_cmd *cmd)
6660{
6661 char buf[MAX_CMD_LEN];
6662 char bss_list[MAX_CMD_LEN];
6663 const char *parameter = get_param(cmd, "Parameter");
6664
6665 if (parameter == NULL)
6666 return -1;
6667
Lior Davidcc88b562017-01-03 18:52:09 +02006668 if (strcasecmp(parameter, "AID") == 0) {
6669 unsigned int aid = 0;
6670 char bssid[20];
6671
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006672 if (get_wpa_status(get_station_ifname(dut), "bssid",
Lior Davidcc88b562017-01-03 18:52:09 +02006673 bssid, sizeof(bssid)) < 0) {
6674 sigma_dut_print(dut, DUT_MSG_ERROR,
6675 "could not get bssid");
6676 return -2;
6677 }
6678
6679 if (sta_get_aid_60g(dut, bssid, &aid))
6680 return -2;
6681
6682 snprintf(buf, sizeof(buf), "aid,%d", aid);
6683 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
6684 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6685 return 0;
6686 }
6687
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006688 if (strcasecmp(parameter, "DiscoveredDevList") == 0) {
6689 char *bss_line;
6690 char *bss_id = NULL;
6691 const char *ifname = get_param(cmd, "Interface");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306692 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006693
6694 if (ifname == NULL) {
6695 sigma_dut_print(dut, DUT_MSG_INFO,
6696 "For get DiscoveredDevList need Interface name.");
6697 return -1;
6698 }
6699
6700 /*
6701 * Use "BSS RANGE=ALL MASK=0x2" which provides a list
6702 * of BSSIDs in "bssid=<BSSID>\n"
6703 */
6704 if (wpa_command_resp(ifname, "BSS RANGE=ALL MASK=0x2",
6705 bss_list,
6706 sizeof(bss_list)) < 0) {
6707 sigma_dut_print(dut, DUT_MSG_ERROR,
6708 "Failed to get bss list");
6709 return -1;
6710 }
6711
6712 sigma_dut_print(dut, DUT_MSG_DEBUG,
6713 "bss list for ifname:%s is:%s",
6714 ifname, bss_list);
6715
6716 snprintf(buf, sizeof(buf), "DeviceList");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306717 bss_line = strtok_r(bss_list, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006718 while (bss_line) {
6719 if (sscanf(bss_line, "bssid=%ms", &bss_id) > 0 &&
6720 bss_id) {
6721 int len;
6722
6723 len = snprintf(buf + strlen(buf),
6724 sizeof(buf) - strlen(buf),
6725 ",%s", bss_id);
6726 free(bss_id);
6727 bss_id = NULL;
6728 if (len < 0) {
6729 sigma_dut_print(dut,
6730 DUT_MSG_ERROR,
6731 "Failed to read BSSID");
6732 send_resp(dut, conn, SIGMA_ERROR,
6733 "ErrorCode,Failed to read BSS ID");
6734 return 0;
6735 }
6736
6737 if ((size_t) len >= sizeof(buf) - strlen(buf)) {
6738 sigma_dut_print(dut,
6739 DUT_MSG_ERROR,
6740 "Response buf too small for list");
6741 send_resp(dut, conn,
6742 SIGMA_ERROR,
6743 "ErrorCode,Response buf too small for list");
6744 return 0;
6745 }
6746 }
6747
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306748 bss_line = strtok_r(NULL, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006749 }
6750
6751 sigma_dut_print(dut, DUT_MSG_INFO, "DiscoveredDevList is %s",
6752 buf);
6753 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6754 return 0;
6755 }
6756
6757 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6758 return 0;
6759}
6760
6761
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006762static int sta_get_parameter_he(struct sigma_dut *dut, struct sigma_conn *conn,
6763 struct sigma_cmd *cmd)
6764{
6765 char buf[MAX_CMD_LEN];
6766 const char *parameter = get_param(cmd, "Parameter");
6767
6768 if (!parameter)
6769 return -1;
6770
6771 if (strcasecmp(parameter, "RSSI") == 0) {
6772 char rssi[10];
6773
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006774 if (get_wpa_signal_poll(dut, get_station_ifname(dut), "RSSI",
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006775 rssi, sizeof(rssi)) < 0) {
6776 sigma_dut_print(dut, DUT_MSG_ERROR,
6777 "Could not get RSSI");
6778 return -2;
6779 }
6780
6781 snprintf(buf, sizeof(buf), "rssi,%s", rssi);
6782 sigma_dut_print(dut, DUT_MSG_INFO, "RSSI %s", buf);
6783 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6784 return 0;
6785 }
6786
6787 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6788 return 0;
6789}
6790
6791
Veerendranath Jakkamd0ad6ef2020-05-21 17:09:26 +05306792#ifdef NL80211_SUPPORT
6793
6794struct station_info {
6795 uint64_t filled;
6796 uint32_t beacon_mic_error_count;
6797 uint32_t beacon_replay_count;
6798};
6799
6800
6801static int qca_get_sta_info_handler(struct nl_msg *msg, void *arg)
6802{
6803 struct nlattr *tb[NL80211_ATTR_MAX + 1];
6804 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
6805 struct station_info *data = arg;
6806 struct nlattr *info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_MAX + 1];
6807 static struct nla_policy info_policy[
6808 QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_MAX + 1] = {
6809 [QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT] = {
6810 .type = NLA_U32
6811 },
6812 [QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT] = {
6813 .type = NLA_U32
6814 },
6815 };
6816
6817 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
6818 genlmsg_attrlen(gnlh, 0), NULL);
6819
6820 if (!tb[NL80211_ATTR_VENDOR_DATA])
6821 return NL_SKIP;
6822
6823 if (nla_parse_nested(info, QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_MAX,
6824 tb[NL80211_ATTR_VENDOR_DATA], info_policy)) {
6825 return NL_SKIP;
6826 }
6827
6828 if (info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT]) {
6829 data->filled |=
6830 BIT_ULL(QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT);
6831 data->beacon_mic_error_count =
6832 nla_get_u32(info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT]);
6833 }
6834
6835 if (info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT]) {
6836 data->filled |=
6837 BIT_ULL(QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT);
6838 data->beacon_replay_count =
6839 nla_get_u32(info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT]);
6840 }
6841
6842 return NL_SKIP;
6843}
6844
6845
6846static int qca_nl80211_get_sta_info(struct sigma_dut *dut, const char *intf,
6847 struct station_info *sta_data)
6848{
6849 struct nl_msg *msg;
6850 int ifindex, ret;
6851
6852 ifindex = if_nametoindex(intf);
6853 if (ifindex == 0) {
6854 sigma_dut_print(dut, DUT_MSG_ERROR,
6855 "%s: Index for interface %s not found",
6856 __func__, intf);
6857 return -1;
6858 }
6859
6860 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6861 NL80211_CMD_VENDOR)) ||
6862 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6863 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6864 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6865 QCA_NL80211_VENDOR_SUBCMD_GET_STA_INFO)) {
6866 sigma_dut_print(dut, DUT_MSG_ERROR,
6867 "%s: err in adding vendor_cmd", __func__);
6868 nlmsg_free(msg);
6869 return -1;
6870 }
6871
6872 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg,
6873 qca_get_sta_info_handler, sta_data);
6874 if (ret) {
6875 sigma_dut_print(dut, DUT_MSG_ERROR,
6876 "%s: err in send_and_recv_msgs, ret=%d",
6877 __func__, ret);
6878 }
6879 return ret;
6880}
6881#endif /* NL80211_SUPPORT */
6882
6883
6884static int get_bip_mic_error_count(struct sigma_dut *dut,
6885 const char *ifname,
6886 unsigned int *count)
6887{
6888#ifdef NL80211_SUPPORT
6889 struct station_info sta_data;
6890#endif /* NL80211_SUPPORT */
6891
6892 if (get_driver_type(dut) != DRIVER_WCN) {
6893 sigma_dut_print(dut, DUT_MSG_ERROR,
6894 "BIP MIC error count not supported");
6895 return -1;
6896 }
6897
6898#ifdef NL80211_SUPPORT
6899 if (qca_nl80211_get_sta_info(dut, ifname, &sta_data) != 0 ||
6900 !(sta_data.filled &
6901 BIT_ULL(QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT))) {
6902 sigma_dut_print(dut, DUT_MSG_ERROR,
6903 "BIP MIC error count fetching failed");
6904 return -1;
6905 }
6906
6907 *count = sta_data.beacon_mic_error_count;
6908 return 0;
6909#else /* NL80211_SUPPORT */
6910 sigma_dut_print(dut, DUT_MSG_ERROR,
6911 "BIP MIC error count cannot be fetched without NL80211_SUPPORT defined");
6912 return -1;
6913#endif /* NL80211_SUPPORT */
6914}
6915
6916
6917static int get_cmac_replay_count(struct sigma_dut *dut, const char *ifname,
6918 unsigned int *count)
6919{
6920#ifdef NL80211_SUPPORT
6921 struct station_info sta_data;
6922#endif /* NL80211_SUPPORT */
6923
6924 if (get_driver_type(dut) != DRIVER_WCN) {
6925 sigma_dut_print(dut, DUT_MSG_ERROR,
6926 "CMAC reply count not supported");
6927 return -1;
6928 }
6929
6930#ifdef NL80211_SUPPORT
6931 if (qca_nl80211_get_sta_info(dut, ifname, &sta_data) != 0 ||
6932 !(sta_data.filled &
6933 BIT_ULL(QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT))) {
6934 sigma_dut_print(dut, DUT_MSG_ERROR,
6935 "CMAC replay count fetching failed");
6936 return -1;
6937 }
6938
6939 *count = sta_data.beacon_replay_count;
6940 return 0;
6941#else /* NL80211_SUPPORT */
6942 sigma_dut_print(dut, DUT_MSG_ERROR,
6943 "CMAC replay count cannot be fetched without NL80211_SUPPORT defined");
6944 return -1;
6945#endif /* NL80211_SUPPORT */
6946}
6947
6948
6949static enum sigma_cmd_result sta_get_parameter_wpa3(struct sigma_dut *dut,
6950 struct sigma_conn *conn,
6951 struct sigma_cmd *cmd)
6952{
6953 char buf[MAX_CMD_LEN];
6954 const char *ifname = get_param(cmd, "interface");
6955 const char *parameter = get_param(cmd, "Parameter");
6956 unsigned int val;
6957
6958 if (!ifname || !parameter)
6959 return INVALID_SEND_STATUS;
6960
6961 if (strcasecmp(parameter, "BIPMICErrors") == 0) {
6962 if (get_bip_mic_error_count(dut, ifname, &val)) {
6963 send_resp(dut, conn, SIGMA_ERROR,
6964 "ErrorCode,Failed to get BIPMICErrors");
6965 return STATUS_SENT_ERROR;
6966 }
6967 snprintf(buf, sizeof(buf), "BIPMICErrors,%d", val);
6968 sigma_dut_print(dut, DUT_MSG_INFO, "BIPMICErrors %s", buf);
6969 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6970 return STATUS_SENT;
6971 }
6972
6973 if (strcasecmp(parameter, "CMACReplays") == 0) {
6974 if (get_cmac_replay_count(dut, ifname, &val)) {
6975 send_resp(dut, conn, SIGMA_ERROR,
6976 "ErrorCode,Failed to get CMACReplays");
6977 return STATUS_SENT_ERROR;
6978 }
6979 snprintf(buf, sizeof(buf), "CMACReplays,%d", val);
6980 sigma_dut_print(dut, DUT_MSG_INFO, "CMACReplays %s", buf);
6981 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6982 return STATUS_SENT;
6983 }
6984
6985 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6986 return STATUS_SENT_ERROR;
6987}
6988
6989
Jouni Malinenca0abd32020-02-09 20:18:10 +02006990static enum sigma_cmd_result sta_get_pmk(struct sigma_dut *dut,
6991 struct sigma_conn *conn,
6992 struct sigma_cmd *cmd)
6993{
6994 const char *intf = get_param(cmd, "Interface");
6995 char buf[4096], bssid[20], resp[200], *pos, *tmp;
6996
6997 snprintf(buf, sizeof(buf), "PMKSA_GET %d", dut->infra_network_id);
6998 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
6999 strncmp(buf, "UNKNOWN COMMAND", 15) == 0) {
7000 send_resp(dut, conn, SIGMA_ERROR,
7001 "ErrorCode,PMKSA_GET not supported");
7002 return STATUS_SENT_ERROR;
7003 }
7004
7005 if (strncmp(buf, "FAIL", 4) == 0 ||
7006 get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
7007 send_resp(dut, conn, SIGMA_ERROR,
7008 "ErrorCode,Could not find current network");
7009 return STATUS_SENT_ERROR;
7010 }
7011
7012 pos = buf;
7013 while (pos) {
7014 if (strncmp(pos, bssid, 17) == 0) {
7015 pos = strchr(pos, ' ');
7016 if (!pos)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05307017 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02007018 pos++;
7019 pos = strchr(pos, ' ');
7020 if (!pos)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05307021 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02007022 pos++;
7023 tmp = strchr(pos, ' ');
7024 if (!tmp)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05307025 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02007026 *tmp = '\0';
7027 break;
7028 }
Jouni Malinenca0abd32020-02-09 20:18:10 +02007029 pos = strchr(pos, '\n');
7030 if (pos)
7031 pos++;
7032 }
7033
7034 if (!pos) {
7035 send_resp(dut, conn, SIGMA_ERROR,
7036 "ErrorCode,PMK not available");
7037 return STATUS_SENT_ERROR;
7038 }
7039
7040 snprintf(resp, sizeof(resp), "PMK,%s", pos);
7041 send_resp(dut, conn, SIGMA_COMPLETE, resp);
7042 return STATUS_SENT;
7043}
7044
7045
Jouni Malinenf7222712019-06-13 01:50:21 +03007046static enum sigma_cmd_result cmd_sta_get_parameter(struct sigma_dut *dut,
7047 struct sigma_conn *conn,
7048 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007049{
7050 const char *program = get_param(cmd, "Program");
Jouni Malinenca0abd32020-02-09 20:18:10 +02007051 const char *parameter = get_param(cmd, "Parameter");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007052
Jouni Malinenca0abd32020-02-09 20:18:10 +02007053 if (!parameter)
7054 return INVALID_SEND_STATUS;
7055
7056 if (strcasecmp(parameter, "PMK") == 0)
7057 return sta_get_pmk(dut, conn, cmd);
7058
7059 if (!program)
7060 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007061
7062 if (strcasecmp(program, "P2PNFC") == 0)
7063 return p2p_cmd_sta_get_parameter(dut, conn, cmd);
7064
7065 if (strcasecmp(program, "60ghz") == 0)
7066 return sta_get_parameter_60g(dut, conn, cmd);
7067
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07007068 if (strcasecmp(program, "he") == 0)
7069 return sta_get_parameter_he(dut, conn, cmd);
7070
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007071#ifdef ANDROID_NAN
7072 if (strcasecmp(program, "NAN") == 0)
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07007073 return nan_cmd_sta_get_parameter(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007074#endif /* ANDROID_NAN */
7075
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007076#ifdef MIRACAST
7077 if (strcasecmp(program, "WFD") == 0 ||
7078 strcasecmp(program, "DisplayR2") == 0)
7079 return miracast_cmd_sta_get_parameter(dut, conn, cmd);
7080#endif /* MIRACAST */
Veerendranath Jakkamd0ad6ef2020-05-21 17:09:26 +05307081 if (strcasecmp(program, "WPA3") == 0)
7082 return sta_get_parameter_wpa3(dut, conn, cmd);
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007083
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007084 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7085 return 0;
7086}
7087
7088
7089static void sta_reset_default_ath(struct sigma_dut *dut, const char *intf,
7090 const char *type)
7091{
7092 char buf[100];
7093
7094 if (dut->program == PROGRAM_VHT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007095 run_iwpriv(dut, intf, "chwidth 2");
7096 run_iwpriv(dut, intf, "mode 11ACVHT80");
7097 run_iwpriv(dut, intf, "vhtmcs -1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007098 }
7099
7100 if (dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007101 run_iwpriv(dut, intf, "chwidth 0");
7102 run_iwpriv(dut, intf, "mode 11naht40");
7103 run_iwpriv(dut, intf, "set11NRates 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007104 }
7105
7106 if (dut->program == PROGRAM_VHT || dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007107 run_iwpriv(dut, intf, "powersave 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007108
7109 /* Reset CTS width */
7110 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 54 0",
7111 intf);
7112 if (system(buf) != 0) {
7113 sigma_dut_print(dut, DUT_MSG_ERROR,
7114 "wifitool %s beeliner_fw_test 54 0 failed",
7115 intf);
7116 }
7117
7118 /* Enable Dynamic Bandwidth signalling by default */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007119 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007120
7121 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", intf);
7122 if (system(buf) != 0) {
7123 sigma_dut_print(dut, DUT_MSG_ERROR,
7124 "iwpriv rts failed");
7125 }
7126 }
7127
7128 if (type && strcasecmp(type, "Testbed") == 0) {
7129 dut->testbed_flag_txsp = 1;
7130 dut->testbed_flag_rxsp = 1;
7131 /* STA has to set spatial stream to 2 per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007132 run_iwpriv(dut, intf, "vht_mcsmap 0xfff0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007133
7134 /* Disable LDPC per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007135 run_iwpriv(dut, intf, "ldpc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007136
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007137 run_iwpriv(dut, intf, "amsdu 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007138
7139 /* TODO: Disable STBC 2x1 transmit and receive */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007140 run_iwpriv(dut, intf, "tx_stbc 0");
7141 run_iwpriv(dut, intf, "rx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007142
7143 /* STA has to disable Short GI per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007144 run_iwpriv(dut, intf, "shortgi 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007145 }
7146
7147 if (type && strcasecmp(type, "DUT") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007148 run_iwpriv(dut, intf, "nss 3");
Arif Hussainac6c5112018-05-25 17:34:00 -07007149 dut->sta_nss = 3;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007150
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007151 run_iwpriv(dut, intf, "shortgi 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007152 }
7153}
7154
7155
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007156#ifdef NL80211_SUPPORT
7157static int sta_set_he_mcs(struct sigma_dut *dut, const char *intf,
7158 enum he_mcs_config mcs)
7159{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307160 return wcn_wifi_test_config_set_u8(
7161 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MCS, mcs);
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007162}
7163#endif /* NL80211_SUPPORT */
7164
7165
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07007166static int sta_set_action_tx_in_he_tb_ppdu(struct sigma_dut *dut,
7167 const char *intf, int enable)
7168{
7169#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307170 return wcn_wifi_test_config_set_u8(
7171 dut, intf,
7172 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_ACTION_TX_TB_PPDU,
7173 enable);
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07007174#else /* NL80211_SUPPORT */
7175 sigma_dut_print(dut, DUT_MSG_ERROR,
7176 "HE action Tx TB PPDU cannot be set without NL80211_SUPPORT defined");
7177 return -1;
7178#endif /* NL80211_SUPPORT */
7179}
7180
7181
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08007182static int sta_set_heconfig_and_wep_tkip(struct sigma_dut *dut,
7183 const char *intf, int enable)
7184{
7185#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307186 return wcn_wifi_test_config_set_u8(
7187 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WEP_TKIP_IN_HE,
7188 enable);
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08007189#else /* NL80211_SUPPORT */
7190 sigma_dut_print(dut, DUT_MSG_ERROR,
7191 "HE config enablement cannot be changed without NL80211_SUPPORT defined");
7192 return -1;
7193#endif /* NL80211_SUPPORT */
7194}
7195
7196
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007197#ifdef NL80211_SUPPORT
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007198
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007199static int sta_set_he_testbed_def(struct sigma_dut *dut,
7200 const char *intf, int cfg)
7201{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307202 return wcn_wifi_test_config_set_u8(
7203 dut, intf,
7204 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SET_HE_TESTBED_DEFAULTS,
7205 cfg);
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007206}
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007207
7208
7209static int sta_set_2g_vht_supp(struct sigma_dut *dut, const char *intf, int cfg)
7210{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307211 return wcn_wifi_test_config_set_u8(
7212 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_2G_VHT,
7213 cfg);
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007214}
7215
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007216#endif /* NL80211_SUPPORT */
7217
7218
Qiwei Caib6806972020-01-15 13:52:11 +08007219int sta_set_addba_buf_size(struct sigma_dut *dut,
7220 const char *intf, int bufsize)
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007221{
7222#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307223 return wcn_wifi_test_config_set_u16(
7224 dut, intf,
7225 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE, bufsize);
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007226#else /* NL80211_SUPPORT */
7227 sigma_dut_print(dut, DUT_MSG_ERROR,
7228 "AddBA bufsize cannot be changed without NL80211_SUPPORT defined");
7229 return -1;
7230#endif /* NL80211_SUPPORT */
7231}
7232
7233
Kiran Kumar Lokere69d89952021-08-08 23:41:46 -07007234static int sta_set_scan_unicast_probe(struct sigma_dut *dut,
7235 const char *intf, int val)
7236{
7237#ifdef NL80211_SUPPORT
7238 return wcn_wifi_test_config_set_u8(
7239 dut, intf,
7240 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_USE_BSSID_IN_PROBE_REQ_RA,
7241 val);
7242#else /* NL80211_SUPPORT */
7243 sigma_dut_print(dut, DUT_MSG_ERROR,
7244 "Unicast RA in Probe Request frame cannot be set without NL80211_SUPPORT defined");
7245 return -1;
7246#endif /* NL80211_SUPPORT */
7247}
7248
7249
Kiran Kumar Lokere09dbcef2021-08-09 00:01:41 -07007250static int sta_set_rx_ctrl_multi_bss(struct sigma_dut *dut, const char *intf,
7251 int enable)
7252{
7253#ifdef NL80211_SUPPORT
7254 return wcn_wifi_test_config_set_u8(
7255 dut, intf,
7256 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_RX_CTRL_FRAME_TO_MBSS,
7257 enable);
7258#else /* NL80211_SUPPORT */
7259 sigma_dut_print(dut, DUT_MSG_ERROR,
7260 "Rx ctrl frame to Multi-BSS cannot be changed without NL80211_SUPPORT defined");
7261 return -1;
7262#endif /* NL80211_SUPPORT */
7263}
7264
7265
7266static int sta_set_bcast_twt_support(struct sigma_dut *dut, const char *intf,
7267 int enable)
7268{
7269#ifdef NL80211_SUPPORT
7270 return wcn_wifi_test_config_set_u8(
7271 dut, intf,
7272 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BCAST_TWT_SUPPORT,
7273 enable);
7274#else /* NL80211_SUPPORT */
7275 sigma_dut_print(dut, DUT_MSG_ERROR,
7276 "BCAST TWT cannot be changed without NL80211_SUPPORT defined");
7277 return -1;
7278#endif /* NL80211_SUPPORT */
7279}
7280
7281
Arif Hussain8d5b27b2018-05-14 14:31:03 -07007282static int sta_set_tx_beamformee(struct sigma_dut *dut, const char *intf,
7283 int enable)
7284{
7285#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307286 return wcn_wifi_test_config_set_u8(
7287 dut, intf,
7288 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_TX_BEAMFORMEE,
7289 enable);
Arif Hussain8d5b27b2018-05-14 14:31:03 -07007290#else /* NL80211_SUPPORT */
7291 sigma_dut_print(dut, DUT_MSG_ERROR,
7292 "tx beamformee cannot be changed without NL80211_SUPPORT defined");
7293 return -1;
7294#endif /* NL80211_SUPPORT */
7295}
7296
7297
Arif Hussain9765f7d2018-07-03 08:28:26 -07007298static int sta_set_beamformee_sts(struct sigma_dut *dut, const char *intf,
7299 int val)
7300{
7301#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307302 return wcn_wifi_test_config_set_u8(
7303 dut, intf,
7304 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_BEAMFORMEE_NSTS,
7305 val);
Arif Hussain9765f7d2018-07-03 08:28:26 -07007306#else /* NL80211_SUPPORT */
7307 sigma_dut_print(dut, DUT_MSG_ERROR,
7308 "beamformee sts cannot be changed without NL80211_SUPPORT defined");
7309 return -1;
7310#endif /* NL80211_SUPPORT */
7311}
7312
7313
Arif Hussain68d23f52018-07-11 13:39:08 -07007314#ifdef NL80211_SUPPORT
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007315static int sta_set_mac_padding_duration(struct sigma_dut *dut, const char *intf,
7316 enum qca_wlan_he_mac_padding_dur val)
7317{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307318 return wcn_wifi_test_config_set_u8(
7319 dut, intf,
7320 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MAC_PADDING_DUR, val);
Arif Hussain68d23f52018-07-11 13:39:08 -07007321}
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007322#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07007323
7324
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07007325static int sta_set_tx_su_ppdu_cfg(struct sigma_dut *dut, const char *intf,
7326 int val)
7327{
7328#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307329 return wcn_wifi_test_config_set_u8(
7330 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_SUPPDU,
7331 val);
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07007332#else /* NL80211_SUPPORT */
7333 sigma_dut_print(dut, DUT_MSG_ERROR,
7334 "Tx SU PPDU cannot be set without NL80211_SUPPORT defined");
7335 return -1;
7336#endif /* NL80211_SUPPORT */
7337}
7338
7339
Kiran Kumar Lokere54b72522021-04-01 00:22:44 -07007340static int sta_set_mgmt_data_tx_disable_cfg(struct sigma_dut *dut,
7341 const char *intf, int val)
7342{
7343#ifdef NL80211_SUPPORT
7344 return wcn_wifi_test_config_set_u8(
7345 dut, intf,
7346 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_DISABLE_DATA_MGMT_RSP_TX,
7347 val);
7348#else /* NL80211_SUPPORT */
7349 sigma_dut_print(dut, DUT_MSG_ERROR,
7350 "Tx disable config cannot be set without NL80211_SUPPORT defined");
7351 return -1;
7352#endif /* NL80211_SUPPORT */
7353}
7354
7355
Kiran Kumar Lokere1809da12021-06-24 00:45:38 -07007356static int sta_set_keep_alive_data_cfg(struct sigma_dut *dut, const char *intf,
7357 int val)
7358{
7359#ifdef NL80211_SUPPORT
7360 return wcn_wifi_test_config_set_u8(
7361 dut, intf,
7362 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_KEEP_ALIVE_FRAME_TYPE,
7363 val);
7364#else /* NL80211_SUPPORT */
7365 sigma_dut_print(dut, DUT_MSG_ERROR,
7366 "Keep alive data type cannot be set without NL80211_SUPPORT defined");
7367 return -1;
7368#endif /* NL80211_SUPPORT */
7369}
7370
7371
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007372#ifdef NL80211_SUPPORT
7373static int sta_set_he_om_ctrl_reset(struct sigma_dut *dut, const char *intf)
7374{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307375 return wcn_wifi_test_config_set_flag(
7376 dut, intf,
7377 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_CLEAR_HE_OM_CTRL_CONFIG);
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007378}
7379#endif /* NL80211_SUPPORT */
7380
7381
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07007382static int sta_set_mu_edca_override(struct sigma_dut *dut, const char *intf,
7383 int val)
7384{
7385#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307386 return wcn_wifi_test_config_set_u8(
7387 dut, intf,
7388 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_OVERRIDE_MU_EDCA, val);
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07007389#else /* NL80211_SUPPORT */
7390 sigma_dut_print(dut, DUT_MSG_ERROR,
7391 "MU EDCA override cannot be changed without NL80211_SUPPORT defined");
7392 return -1;
7393#endif /* NL80211_SUPPORT */
7394}
7395
7396
Kiran Kumar Lokerefa7c7b92021-08-09 00:50:55 -07007397static int sta_set_er_su_ppdu_type_tx(struct sigma_dut *dut, const char *intf,
7398 int val)
7399{
7400#ifdef NL80211_SUPPORT
7401 return wcn_wifi_test_config_set_u8(
7402 dut, intf,
7403 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ER_SU_PPDU_TYPE, val);
7404#else /* NL80211_SUPPORT */
7405 sigma_dut_print(dut, DUT_MSG_ERROR,
7406 "ER-SU PPDU type cannot be set without NL80211_SUPPORT defined");
7407 return -1;
7408#endif /* NL80211_SUPPORT */
7409}
7410
7411
7412static int sta_set_ru_242_tone_tx(struct sigma_dut *dut, const char *intf,
7413 int val)
7414{
7415#ifdef NL80211_SUPPORT
7416 return wcn_wifi_test_config_set_u8(
7417 dut, intf,
7418 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_RU_242_TONE_TX, val);
7419#else /* NL80211_SUPPORT */
7420 sigma_dut_print(dut, DUT_MSG_ERROR,
7421 "RU 242 tone cannot be set without NL80211_SUPPORT defined");
7422 return -1;
7423#endif /* NL80211_SUPPORT */
7424}
7425
7426
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007427static int sta_set_om_ctrl_supp(struct sigma_dut *dut, const char *intf,
7428 int val)
7429{
7430#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307431 return wcn_wifi_test_config_set_u8(
7432 dut, intf,
7433 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OM_CTRL_SUPP, val);
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007434#else /* NL80211_SUPPORT */
7435 sigma_dut_print(dut, DUT_MSG_ERROR,
7436 "HE OM ctrl cannot be changed without NL80211_SUPPORT defined");
7437 return -1;
7438#endif /* NL80211_SUPPORT */
7439}
7440
7441
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07007442#ifdef NL80211_SUPPORT
7443
7444struct features_info {
7445 unsigned char flags[8];
7446 size_t flags_len;
7447};
7448
7449static int features_info_handler(struct nl_msg *msg, void *arg)
7450{
7451 struct nlattr *tb[NL80211_ATTR_MAX + 1];
7452 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
7453 struct features_info *info = arg;
7454 struct nlattr *nl_vend, *attr;
7455
7456 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
7457 genlmsg_attrlen(gnlh, 0), NULL);
7458
7459 nl_vend = tb[NL80211_ATTR_VENDOR_DATA];
7460 if (nl_vend) {
7461 struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1];
7462
7463 nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX,
7464 nla_data(nl_vend), nla_len(nl_vend), NULL);
7465
7466 attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_FEATURE_FLAGS];
7467 if (attr) {
7468 int len = nla_len(attr);
7469
Vamsi Krishna79a91132021-08-16 21:40:22 +05307470 if (info && len <= sizeof(info->flags)) {
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07007471 memcpy(info->flags, nla_data(attr), len);
7472 info->flags_len = len;
7473 }
7474 }
7475 }
7476
7477 return NL_SKIP;
7478}
7479
7480
7481static int check_feature(enum qca_wlan_vendor_features feature,
7482 struct features_info *info)
7483{
7484 size_t idx = feature / 8;
7485
Vamsi Krishna79a91132021-08-16 21:40:22 +05307486 if (!info)
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07007487 return 0;
7488
7489 return (idx < info->flags_len) &&
7490 (info->flags[idx] & BIT(feature % 8));
7491}
7492
7493#endif /* NL80211_SUPPORT */
7494
7495
7496static void sta_get_twt_feature_async_supp(struct sigma_dut *dut,
7497 const char *intf)
7498{
7499#ifdef NL80211_SUPPORT
7500 struct nl_msg *msg;
7501 struct features_info info = { 0 };
7502 int ifindex, ret;
7503
7504 ifindex = if_nametoindex(intf);
7505 if (ifindex == 0) {
7506 sigma_dut_print(dut, DUT_MSG_ERROR,
7507 "%s: Index for interface %s failed",
7508 __func__, intf);
7509 return;
7510 }
7511
7512 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7513 NL80211_CMD_VENDOR)) ||
7514 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7515 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7516 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7517 QCA_NL80211_VENDOR_SUBCMD_GET_FEATURES)) {
7518 sigma_dut_print(dut, DUT_MSG_ERROR,
7519 "%s: err in adding vendor_cmd and vendor_data",
7520 __func__);
7521 nlmsg_free(msg);
7522 return;
7523 }
7524
7525 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, features_info_handler,
7526 &info);
7527 if (ret) {
7528 sigma_dut_print(dut, DUT_MSG_ERROR,
7529 "%s: err in send_and_recv_msgs, ret=%d",
7530 __func__, ret);
7531 return;
7532 }
7533
7534 if (check_feature(QCA_WLAN_VENDOR_FEATURE_TWT_ASYNC_SUPPORT, &info))
7535 dut->sta_async_twt_supp = 1;
7536 else
7537 dut->sta_async_twt_supp = 0;
7538
7539 sigma_dut_print(dut, DUT_MSG_DEBUG,
7540 "%s: sta_async_twt_supp %d",
7541 __func__, dut->sta_async_twt_supp);
7542#else /* NL80211_SUPPORT */
7543 sigma_dut_print(dut, DUT_MSG_INFO,
7544 "TWT async supp get cannot be done without NL80211_SUPPORT defined");
7545 dut->sta_async_twt_supp = 0;
7546#endif /* NL80211_SUPPORT */
7547}
7548
7549
Arif Hussain480d5f42019-03-12 14:40:42 -07007550static int sta_set_twt_req_support(struct sigma_dut *dut, const char *intf,
7551 int val)
7552{
7553#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307554 return wcn_wifi_test_config_set_u8(
7555 dut, intf,
7556 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TWT_REQ_SUPPORT, val);
Arif Hussain480d5f42019-03-12 14:40:42 -07007557#else /* NL80211_SUPPORT */
7558 sigma_dut_print(dut, DUT_MSG_ERROR,
7559 "TWT Request cannot be changed without NL80211_SUPPORT defined");
7560 return -1;
7561#endif /* NL80211_SUPPORT */
7562}
7563
7564
Kiran Kumar Lokere4f2d4b02021-04-01 00:07:39 -07007565static int sta_set_bss_max_idle_period(struct sigma_dut *dut, const char *intf,
7566 int val)
7567{
7568#ifdef NL80211_SUPPORT
7569 return wcn_wifi_test_config_set_u16(
7570 dut, intf,
7571 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BSS_MAX_IDLE_PERIOD, val);
7572#else /* NL80211_SUPPORT */
7573 sigma_dut_print(dut, DUT_MSG_ERROR,
7574 "BSS max idle period cannot be set without NL80211_SUPPORT defined");
7575 return -1;
7576#endif /* NL80211_SUPPORT */
7577}
7578
7579
Kiran Kumar Lokere07ad92b2021-08-09 00:27:14 -07007580static int sta_set_bss_max_idle_support(struct sigma_dut *dut, const char *intf,
7581 int val)
7582{
7583#ifdef NL80211_SUPPORT
7584 return wcn_wifi_test_config_set_u8(
7585 dut, intf,
7586 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BSS_MAX_IDLE_PERIOD_ENABLE,
7587 val);
7588#else /* NL80211_SUPPORT */
7589 sigma_dut_print(dut, DUT_MSG_ERROR,
7590 "BSS max idle support cannot be set without NL80211_SUPPORT defined");
7591 return -1;
7592#endif /* NL80211_SUPPORT */
7593}
7594
7595
Srinivas Girigowda0525e292020-11-12 13:28:21 -08007596static int sta_set_fullbw_ulmumimo(struct sigma_dut *dut, const char *intf,
7597 int val)
7598{
7599#ifdef NL80211_SUPPORT
7600 return wcn_wifi_test_config_set_u8(
7601 dut, intf,
7602 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_FULL_BW_UL_MU_MIMO, val);
7603#else /* NL80211_SUPPORT */
7604 sigma_dut_print(dut, DUT_MSG_ERROR,
7605 "Full BW UL MU MIMO cannot be changed without NL80211_SUPPORT defined");
7606 return -1;
7607#endif /* NL80211_SUPPORT */
7608}
7609
7610
Kiran Kumar Lokered0ec5ed2021-04-01 00:15:04 -07007611static int sta_set_punctured_preamble_rx(struct sigma_dut *dut,
7612 const char *intf, int val)
7613{
7614#ifdef NL80211_SUPPORT
7615 return wcn_wifi_test_config_set_u8(
7616 dut, intf,
7617 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_PUNCTURED_PREAMBLE_RX,
7618 val);
7619#else /* NL80211_SUPPORT */
7620 sigma_dut_print(dut, DUT_MSG_ERROR,
7621 "Punctured preamble Rx cannot be set without NL80211_SUPPORT defined");
7622 return -1;
7623#endif /* NL80211_SUPPORT */
7624}
7625
7626
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007627static void sta_reset_default_wcn(struct sigma_dut *dut, const char *intf,
7628 const char *type)
7629{
7630 char buf[60];
7631
7632 if (dut->program == PROGRAM_HE) {
7633 /* resetting phymode to auto in case of HE program */
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05307634 sta_set_phymode(dut, intf, "auto");
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007635
Amarnath Hullur Subramanyam9cecb502018-04-25 13:26:30 -07007636 /* reset the rate to Auto rate */
7637 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0xff",
7638 intf);
7639 if (system(buf) != 0) {
7640 sigma_dut_print(dut, DUT_MSG_ERROR,
7641 "iwpriv %s set_11ax_rate 0xff failed",
7642 intf);
7643 }
7644
Kiran Kumar Lokere86cfe3a2018-06-01 11:55:15 -07007645 /* reset the LDPC setting */
7646 snprintf(buf, sizeof(buf), "iwpriv %s ldpc 1", intf);
7647 if (system(buf) != 0) {
7648 sigma_dut_print(dut, DUT_MSG_ERROR,
7649 "iwpriv %s ldpc 1 failed", intf);
7650 }
7651
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08007652 /* reset the power save setting */
Vinita S. Malooa8b62722020-04-23 01:45:41 +05307653 set_power_save_wcn(dut, intf, 2);
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08007654
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007655 /* remove all network profiles */
7656 remove_wpa_networks(intf);
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007657
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007658 /* Configure ADDBA Req/Rsp buffer size to be 64 */
7659 sta_set_addba_buf_size(dut, intf, 64);
7660
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07007661 if (dut->sta_async_twt_supp == -1)
7662 sta_get_twt_feature_async_supp(dut, intf);
7663
Kiran Kumar Lokere69d89952021-08-08 23:41:46 -07007664 sta_set_scan_unicast_probe(dut, intf, 0);
7665
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08007666#ifdef NL80211_SUPPORT
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007667 /* Reset the device HE capabilities to its default supported
7668 * configuration. */
7669 sta_set_he_testbed_def(dut, intf, 0);
7670
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08007671 /* Disable noackpolicy for all AC */
7672 if (nlvendor_sta_set_noack(dut, intf, 0, QCA_WLAN_AC_ALL)) {
7673 sigma_dut_print(dut, DUT_MSG_ERROR,
7674 "Disable of noackpolicy for all AC failed");
7675 }
7676#endif /* NL80211_SUPPORT */
7677
Amarnath Hullur Subramanyamb1724a52018-03-07 14:31:46 -08007678 /* Enable WMM by default */
7679 if (wcn_sta_set_wmm(dut, intf, "on")) {
7680 sigma_dut_print(dut, DUT_MSG_ERROR,
7681 "Enable of WMM in sta_reset_default_wcn failed");
7682 }
7683
7684 /* Disable ADDBA_REJECT by default */
7685 if (nlvendor_sta_set_addba_reject(dut, intf, 0)) {
7686 sigma_dut_print(dut, DUT_MSG_ERROR,
7687 "Disable of addba_reject in sta_reset_default_wcn failed");
7688 }
7689
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08007690 /* Enable sending of ADDBA by default */
7691 if (nlvendor_config_send_addba(dut, intf, 1)) {
7692 sigma_dut_print(dut, DUT_MSG_ERROR,
7693 "Enable sending of ADDBA in sta_reset_default_wcn failed");
7694 }
7695
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08007696 /* Enable AMPDU by default */
7697 iwpriv_sta_set_ampdu(dut, intf, 1);
7698
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007699#ifdef NL80211_SUPPORT
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -08007700 if (wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_AUTO)) {
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007701 sigma_dut_print(dut, DUT_MSG_ERROR,
7702 "Set LTF config to default in sta_reset_default_wcn failed");
7703 }
Arif Hussain9765f7d2018-07-03 08:28:26 -07007704
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08007705 /* set the beamformee NSTS(maximum number of
7706 * space-time streams) to default DUT config
7707 */
7708 if (sta_set_beamformee_sts(dut, intf, 7)) {
Arif Hussain9765f7d2018-07-03 08:28:26 -07007709 sigma_dut_print(dut, DUT_MSG_ERROR,
7710 "Failed to set BeamformeeSTS");
7711 }
Arif Hussain68d23f52018-07-11 13:39:08 -07007712
Kiran Kumar Lokere54b72522021-04-01 00:22:44 -07007713 if (sta_set_mgmt_data_tx_disable_cfg(dut, intf, 0)) {
7714 sigma_dut_print(dut, DUT_MSG_ERROR,
7715 "Failed to reset mgmt/data Tx disable config");
7716 }
7717
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007718 if (sta_set_mac_padding_duration(
7719 dut, intf,
7720 QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07007721 sigma_dut_print(dut, DUT_MSG_ERROR,
7722 "Failed to set MAC padding duration");
7723 }
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07007724
7725 if (sta_set_mu_edca_override(dut, intf, 0)) {
7726 sigma_dut_print(dut, DUT_MSG_ERROR,
7727 "ErrorCode,Failed to set MU EDCA override disable");
7728 }
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007729
Kiran Kumar Lokerefa7c7b92021-08-09 00:50:55 -07007730 if (sta_set_ru_242_tone_tx(dut, intf, 0)) {
7731 sigma_dut_print(dut, DUT_MSG_ERROR,
7732 "Failed to set RU 242 tone Tx");
7733 }
7734
7735 if (sta_set_er_su_ppdu_type_tx(dut, intf, 0)) {
7736 sigma_dut_print(dut, DUT_MSG_ERROR,
7737 "Failed to set ER-SU PPDU type Tx");
7738 }
7739
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007740 if (sta_set_om_ctrl_supp(dut, intf, 1)) {
7741 sigma_dut_print(dut, DUT_MSG_ERROR,
7742 "Failed to set OM ctrl supp");
7743 }
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07007744
7745 if (sta_set_tx_su_ppdu_cfg(dut, intf, 1)) {
7746 sigma_dut_print(dut, DUT_MSG_ERROR,
7747 "Failed to set Tx SU PPDU enable");
7748 }
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007749
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07007750 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 0)) {
7751 sigma_dut_print(dut, DUT_MSG_ERROR,
7752 "failed to send TB PPDU Tx cfg");
7753 }
7754
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007755 if (sta_set_he_om_ctrl_reset(dut, intf)) {
7756 sigma_dut_print(dut, DUT_MSG_ERROR,
7757 "Failed to set OM ctrl reset");
7758 }
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08007759
7760 /* +HTC-HE support default on */
7761 if (sta_set_he_htc_supp(dut, intf, 1)) {
7762 sigma_dut_print(dut, DUT_MSG_ERROR,
7763 "Setting of +HTC-HE support failed");
7764 }
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007765#endif /* NL80211_SUPPORT */
7766
Arif Hussain8d5b27b2018-05-14 14:31:03 -07007767 if (sta_set_tx_beamformee(dut, intf, 1)) {
7768 sigma_dut_print(dut, DUT_MSG_ERROR,
7769 "Set tx beamformee enable by default in sta_reset_default_wcn failed");
7770 }
7771
Kiran Kumar Lokereb55ff442020-07-15 00:20:40 -07007772 wpa_command(intf, "SET oce 1");
7773
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007774 /* Set nss to 1 and MCS 0-7 in case of testbed */
7775 if (type && strcasecmp(type, "Testbed") == 0) {
7776#ifdef NL80211_SUPPORT
7777 int ret;
7778#endif /* NL80211_SUPPORT */
7779
Kiran Kumar Lokereb55ff442020-07-15 00:20:40 -07007780 wpa_command(intf, "SET oce 0");
7781
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007782 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
7783 if (system(buf) != 0) {
7784 sigma_dut_print(dut, DUT_MSG_ERROR,
7785 "iwpriv %s nss failed", intf);
7786 }
7787
7788#ifdef NL80211_SUPPORT
7789 ret = sta_set_he_mcs(dut, intf, HE_80_MCS0_7);
7790 if (ret) {
7791 sigma_dut_print(dut, DUT_MSG_ERROR,
7792 "Setting of MCS failed, ret:%d",
7793 ret);
7794 }
7795#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyamc67621d2018-02-04 23:18:01 -08007796
7797 /* Disable STBC as default */
7798 wcn_sta_set_stbc(dut, intf, "0");
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08007799
7800 /* Disable AMSDU as default */
7801 iwpriv_sta_set_amsdu(dut, intf, "0");
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08007802
7803#ifdef NL80211_SUPPORT
7804 /* HE fragmentation default off */
7805 if (sta_set_he_fragmentation(dut, intf,
7806 HE_FRAG_DISABLE)) {
7807 sigma_dut_print(dut, DUT_MSG_ERROR,
7808 "Setting of HE fragmentation failed");
7809 }
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08007810
7811 /* set the beamformee NSTS(maximum number of
7812 * space-time streams) to default testbed config
7813 */
7814 if (sta_set_beamformee_sts(dut, intf, 3)) {
7815 sigma_dut_print(dut, DUT_MSG_ERROR,
7816 "Failed to set BeamformeeSTS");
7817 }
7818
Kiran Kumar Lokered0ec5ed2021-04-01 00:15:04 -07007819 if (sta_set_punctured_preamble_rx(dut, intf, 0)) {
7820 sigma_dut_print(dut, DUT_MSG_ERROR,
7821 "Failed to reset PreamblePunctRx support");
7822 }
7823
Kiran Kumar Lokere727687f2021-06-24 00:35:49 -07007824 if (sta_set_bss_max_idle_period(dut, intf, 0)) {
7825 sigma_dut_print(dut, DUT_MSG_ERROR,
7826 "Failed to reset BSS max idle period");
7827 }
7828
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08007829 /* +HTC-HE support default off */
7830 if (sta_set_he_htc_supp(dut, intf, 0)) {
7831 sigma_dut_print(dut, DUT_MSG_ERROR,
7832 "Setting of +HTC-HE support failed");
7833 }
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007834
7835 /* Set device HE capabilities to testbed default
7836 * configuration. */
7837 if (sta_set_he_testbed_def(dut, intf, 1)) {
7838 sigma_dut_print(dut, DUT_MSG_DEBUG,
7839 "Failed to set HE defaults");
7840 }
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007841
7842 /* Disable VHT support in 2.4 GHz for testbed */
7843 sta_set_2g_vht_supp(dut, intf, 0);
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08007844#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08007845
7846 /* Enable WEP/TKIP with HE capability in testbed */
7847 if (sta_set_heconfig_and_wep_tkip(dut, intf, 1)) {
7848 sigma_dut_print(dut, DUT_MSG_ERROR,
7849 "Enabling HE config with WEP/TKIP failed");
7850 }
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007851 }
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007852
7853 /* Defaults in case of DUT */
7854 if (type && strcasecmp(type, "DUT") == 0) {
Arif Hussaind48fcc72018-05-01 18:34:18 -07007855 /* Enable STBC by default */
7856 wcn_sta_set_stbc(dut, intf, "1");
7857
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007858 /* set nss to 2 */
7859 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
7860 if (system(buf) != 0) {
7861 sigma_dut_print(dut, DUT_MSG_ERROR,
7862 "iwpriv %s nss 2 failed", intf);
7863 }
Arif Hussainac6c5112018-05-25 17:34:00 -07007864 dut->sta_nss = 2;
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007865
7866#ifdef NL80211_SUPPORT
Arif Hussainae239842018-05-01 18:20:05 -07007867 /* Set HE_MCS to 0-11 */
7868 if (sta_set_he_mcs(dut, intf, HE_80_MCS0_11)) {
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007869 sigma_dut_print(dut, DUT_MSG_ERROR,
7870 "Setting of MCS failed");
7871 }
7872#endif /* NL80211_SUPPORT */
7873
7874 /* Disable WEP/TKIP with HE capability in DUT */
7875 if (sta_set_heconfig_and_wep_tkip(dut, intf, 0)) {
7876 sigma_dut_print(dut, DUT_MSG_ERROR,
7877 "Enabling HE config with WEP/TKIP failed");
7878 }
7879 }
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007880 }
7881}
7882
7883
Veerendranath Jakkam47867202020-12-21 01:53:52 +05307884static int sta_set_client_privacy(struct sigma_dut *dut,
7885 struct sigma_conn *conn, const char *intf,
7886 int enable)
7887{
7888 if (enable &&
7889 (wpa_command(intf, "SET mac_addr 1") < 0 ||
7890 wpa_command(intf, "SET rand_addr_lifetime 1") < 0 ||
Veerendranath Jakkam39fd5c42020-12-21 02:02:21 +05307891 (wpa_command(intf, "MAC_RAND_SCAN enable=1 all") < 0 &&
7892 wpa_command(intf, "SET preassoc_mac_addr 1") < 0) ||
Veerendranath Jakkam47867202020-12-21 01:53:52 +05307893 wpa_command(intf, "SET gas_rand_mac_addr 1") < 0 ||
7894 wpa_command(intf, "SET gas_rand_addr_lifetime 1") < 0))
7895 return -1;
7896
7897 if (!enable &&
7898 (wpa_command(intf, "SET mac_addr 0") < 0 ||
Veerendranath Jakkam39fd5c42020-12-21 02:02:21 +05307899 (wpa_command(intf, "MAC_RAND_SCAN enable=0 all") < 0 &&
7900 wpa_command(intf, "SET preassoc_mac_addr 0") < 0) ||
Veerendranath Jakkam47867202020-12-21 01:53:52 +05307901 wpa_command(intf, "SET gas_rand_mac_addr 0") < 0))
7902 return -1;
7903
7904 dut->client_privacy = enable;
7905 return 0;
7906}
7907
7908
Jouni Malinenf7222712019-06-13 01:50:21 +03007909static enum sigma_cmd_result cmd_sta_reset_default(struct sigma_dut *dut,
7910 struct sigma_conn *conn,
7911 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007912{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007913 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007914 const char *band = get_param(cmd, "band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007915 const char *type;
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007916 const char *program = get_param(cmd, "program");
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05307917 const char *dev_role = get_param(cmd, "DevRole");
Veerendranath Jakkamc1f71b62021-01-23 03:09:51 +05307918 char resp[20];
Veerendranath Jakkamea7f0692021-08-11 19:13:12 +05307919 char buf[100];
Veerendranath Jakkamc1f71b62021-01-23 03:09:51 +05307920 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007921
Jouni Malinenb21f0542019-11-04 17:53:38 +02007922 if (dut->station_ifname_2g &&
7923 strcmp(dut->station_ifname_2g, intf) == 0)
7924 dut->use_5g = 0;
7925 else if (dut->station_ifname_5g &&
7926 strcmp(dut->station_ifname_5g, intf) == 0)
7927 dut->use_5g = 1;
7928
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007929 if (!program)
7930 program = get_param(cmd, "prog");
7931 dut->program = sigma_program_to_enum(program);
Vinita S. Maloof7a2cbf2020-11-18 19:29:44 +05307932
7933 if (dut->program == PROGRAM_WFD && dut->user_config_timeout)
7934 dut->default_timeout = dut->user_config_timeout;
7935
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007936 dut->device_type = STA_unknown;
7937 type = get_param(cmd, "type");
7938 if (type && strcasecmp(type, "Testbed") == 0)
7939 dut->device_type = STA_testbed;
7940 if (type && strcasecmp(type, "DUT") == 0)
7941 dut->device_type = STA_dut;
7942
7943 if (dut->program == PROGRAM_TDLS) {
7944 /* Clear TDLS testing mode */
7945 wpa_command(intf, "SET tdls_disabled 0");
7946 wpa_command(intf, "SET tdls_testing 0");
7947 dut->no_tpk_expiration = 0;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007948 if (get_driver_type(dut) == DRIVER_WCN) {
Pradeep Reddy POTTETI8ce2a232016-10-28 12:17:32 +05307949 /* Enable the WCN driver in TDLS Explicit trigger mode
7950 */
7951 wpa_command(intf, "SET tdls_external_control 0");
7952 wpa_command(intf, "SET tdls_trigger_control 0");
7953 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007954 }
7955
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007956#ifdef MIRACAST
7957 if (dut->program == PROGRAM_WFD ||
7958 dut->program == PROGRAM_DISPLAYR2)
7959 miracast_sta_reset_default(dut, conn, cmd);
7960#endif /* MIRACAST */
7961
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007962 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007963 case DRIVER_ATHEROS:
7964 sta_reset_default_ath(dut, intf, type);
7965 break;
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007966 case DRIVER_WCN:
7967 sta_reset_default_wcn(dut, intf, type);
7968 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007969 default:
7970 break;
7971 }
7972
7973#ifdef ANDROID_NAN
7974 if (dut->program == PROGRAM_NAN)
7975 nan_cmd_sta_reset_default(dut, conn, cmd);
7976#endif /* ANDROID_NAN */
7977
Vinay Gannevaram3b9fdd32019-06-14 17:55:44 +05307978 if (dut->program == PROGRAM_LOC &&
7979 lowi_cmd_sta_reset_default(dut, conn, cmd) < 0)
7980 return ERROR_SEND_STATUS;
7981
Jouni Malinenba630452018-06-22 11:49:59 +03007982 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007983 unlink("SP/wi-fi.org/pps.xml");
7984 if (system("rm -r SP/*") != 0) {
7985 }
7986 unlink("next-client-cert.pem");
7987 unlink("next-client-key.pem");
7988 }
7989
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007990 /* For WPS program of the 60 GHz band the band type needs to be saved */
7991 if (dut->program == PROGRAM_WPS) {
7992 if (band && strcasecmp(band, "60GHz") == 0) {
7993 dut->band = WPS_BAND_60G;
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02007994 /* For 60 GHz enable WPS for WPS TCs */
7995 dut->wps_disable = 0;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007996 } else {
7997 dut->band = WPS_BAND_NON_60G;
7998 }
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02007999 } else if (dut->program == PROGRAM_60GHZ) {
8000 /* For 60 GHz MAC/PHY TCs WPS must be disabled */
8001 dut->wps_disable = 1;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008002 }
8003
Alexei Avshalom Lazar157ba062018-12-23 16:15:26 +02008004 if (is_60g_sigma_dut(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008005 const char *dev_role = get_param(cmd, "DevRole");
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02008006 char buf[256];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008007
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02008008 sigma_dut_print(dut, DUT_MSG_INFO,
8009 "WPS 60 GHz program, wps_disable = %d",
8010 dut->wps_disable);
8011
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008012 if (!dev_role) {
8013 send_resp(dut, conn, SIGMA_ERROR,
8014 "errorCode,Missing DevRole argument");
8015 return 0;
8016 }
8017
8018 if (strcasecmp(dev_role, "STA") == 0)
8019 dut->dev_role = DEVROLE_STA;
8020 else if (strcasecmp(dev_role, "PCP") == 0)
8021 dut->dev_role = DEVROLE_PCP;
8022 else {
8023 send_resp(dut, conn, SIGMA_ERROR,
8024 "errorCode,Unknown DevRole");
8025 return 0;
8026 }
8027
8028 if (dut->device_type == STA_unknown) {
8029 sigma_dut_print(dut, DUT_MSG_ERROR,
8030 "Device type is not STA testbed or DUT");
8031 send_resp(dut, conn, SIGMA_ERROR,
8032 "errorCode,Unknown device type");
8033 return 0;
8034 }
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02008035
8036 sigma_dut_print(dut, DUT_MSG_DEBUG,
8037 "Setting msdu_size to MAX: 7912");
8038 snprintf(buf, sizeof(buf), "ifconfig %s mtu 7912",
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008039 get_station_ifname(dut));
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02008040
8041 if (system(buf) != 0) {
8042 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
8043 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02008044 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02008045 }
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02008046
8047 if (sta_set_force_mcs(dut, 0, 1)) {
8048 sigma_dut_print(dut, DUT_MSG_ERROR,
8049 "Failed to reset force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02008050 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02008051 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008052 }
8053
8054 wpa_command(intf, "WPS_ER_STOP");
8055 wpa_command(intf, "FLUSH");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05308056 wpa_command(intf, "ERP_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008057 wpa_command(intf, "SET radio_disabled 0");
8058
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02008059 dut->wps_forced_version = 0;
8060
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008061 if (dut->wsc_fragment) {
8062 dut->wsc_fragment = 0;
8063 wpa_command(intf, "SET device_name Test client");
8064 wpa_command(intf, "SET manufacturer ");
8065 wpa_command(intf, "SET model_name ");
8066 wpa_command(intf, "SET model_number ");
8067 wpa_command(intf, "SET serial_number ");
8068 }
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02008069 if (is_60g_sigma_dut(dut) && dut->force_rsn_ie) {
8070 dut->force_rsn_ie = FORCE_RSN_IE_NONE;
8071 sta_60g_force_rsn_ie(dut, FORCE_RSN_IE_NONE);
8072 }
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008073
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008074 if (dut->tmp_mac_addr && dut->set_macaddr) {
8075 dut->tmp_mac_addr = 0;
8076 if (system(dut->set_macaddr) != 0) {
8077 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to clear "
8078 "temporary MAC address");
8079 }
8080 }
8081
8082 set_ps(intf, dut, 0);
8083
Jouni Malinenba630452018-06-22 11:49:59 +03008084 if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2 ||
8085 dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008086 wpa_command(intf, "SET interworking 1");
8087 wpa_command(intf, "SET hs20 1");
8088 }
8089
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08008090 if (dut->program == PROGRAM_HS2_R2 ||
Jouni Malinenba630452018-06-22 11:49:59 +03008091 dut->program == PROGRAM_HS2_R3 ||
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08008092 dut->program == PROGRAM_OCE) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008093 wpa_command(intf, "SET pmf 1");
8094 } else {
8095 wpa_command(intf, "SET pmf 0");
8096 }
8097
8098 hs2_clear_credentials(intf);
8099 wpa_command(intf, "SET hessid 00:00:00:00:00:00");
8100 wpa_command(intf, "SET access_network_type 15");
8101
8102 static_ip_file(0, NULL, NULL, NULL);
8103 kill_dhcp_client(dut, intf);
8104 clear_ip_addr(dut, intf);
8105
8106 dut->er_oper_performed = 0;
8107 dut->er_oper_bssid[0] = '\0';
8108
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07008109 if (dut->program == PROGRAM_LOC) {
8110 /* Disable Interworking by default */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008111 wpa_command(get_station_ifname(dut), "SET interworking 0");
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07008112 }
8113
Kiran Kumar Lokeredd086642020-06-04 00:29:26 -07008114 if (dut->program == PROGRAM_MBO || dut->program == PROGRAM_HE) {
Ashwini Patil00402582017-04-13 12:29:39 +05308115 free(dut->non_pref_ch_list);
8116 dut->non_pref_ch_list = NULL;
Ashwini Patil5acd7382017-04-13 15:55:04 +05308117 free(dut->btm_query_cand_list);
8118 dut->btm_query_cand_list = NULL;
Ashwini Patilc63161e2017-04-13 16:30:23 +05308119 wpa_command(intf, "SET reject_btm_req_reason 0");
Ashwini Patila75de5a2017-04-13 16:35:05 +05308120 wpa_command(intf, "SET ignore_assoc_disallow 0");
Ashwini Patild174f2c2017-04-13 16:49:46 +05308121 wpa_command(intf, "SET gas_address3 0");
Ashwini Patil9183fdb2017-04-13 16:58:25 +05308122 wpa_command(intf, "SET roaming 1");
Ankita Bajaj1d974552018-09-18 16:56:44 +05308123 wpa_command(intf, "SET interworking 1");
Ashwini Patil00402582017-04-13 12:29:39 +05308124 }
8125
Jouni Malinen3c367e82017-06-23 17:01:47 +03008126 free(dut->rsne_override);
8127 dut->rsne_override = NULL;
8128
Jouni Malinen68143132017-09-02 02:34:08 +03008129 free(dut->sae_commit_override);
8130 dut->sae_commit_override = NULL;
Jouni Malinen4b3769d2019-10-10 16:20:29 +03008131 wpa_command(intf, "SET sae_pmkid_in_assoc 0");
Jouni Malinen11e55212019-11-22 21:46:59 +02008132 dut->sae_pwe = SAE_PWE_DEFAULT;
Jouni Malinen68143132017-09-02 02:34:08 +03008133
Jouni Malinen134fe3c2019-06-12 04:16:49 +03008134 dut->sta_associate_wait_connect = 0;
8135 dut->server_cert_hash[0] = '\0';
Jouni Malinen37d5c692019-08-19 16:56:55 +03008136 dut->server_cert_tod = 0;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03008137 dut->sta_tod_policy = 0;
8138
Jouni Malinend86e5822017-08-29 03:55:32 +03008139 dut->dpp_conf_id = -1;
Jouni Malinenb1dd21f2017-11-13 19:14:29 +02008140 free(dut->dpp_peer_uri);
8141 dut->dpp_peer_uri = NULL;
Jouni Malinen63d50412017-11-24 11:55:38 +02008142 dut->dpp_local_bootstrap = -1;
Jouni Malinen5011fb52017-12-05 21:00:15 +02008143 wpa_command(intf, "SET dpp_config_processing 2");
Jouni Malinen90776b12020-05-04 15:34:46 +03008144 wpa_command(intf, "SET dpp_mud_url ");
Jouni Malinend86e5822017-08-29 03:55:32 +03008145
Jouni Malinenfac9cad2017-10-10 18:35:55 +03008146 wpa_command(intf, "VENDOR_ELEM_REMOVE 13 *");
8147
vamsi krishnaa2799492017-12-05 14:28:01 +05308148 if (dut->program == PROGRAM_OCE) {
Ankita Bajaja2cb5672017-10-25 16:08:28 +05308149 wpa_command(intf, "SET oce 1");
vamsi krishnaa2799492017-12-05 14:28:01 +05308150 wpa_command(intf, "SET disable_fils 0");
Ankita Bajaj1bde7942018-01-09 19:15:01 +05308151 wpa_command(intf, "FILS_HLP_REQ_FLUSH");
8152 dut->fils_hlp = 0;
8153#ifdef ANDROID
8154 hlp_thread_cleanup(dut);
8155#endif /* ANDROID */
vamsi krishnaa2799492017-12-05 14:28:01 +05308156 }
Ankita Bajaja2cb5672017-10-25 16:08:28 +05308157
Veerendranath Jakkamea7f0692021-08-11 19:13:12 +05308158 if (dut->program == PROGRAM_QM) {
Vamsi Krishnaf642d6a2020-03-27 12:33:14 +05308159 wpa_command(intf, "SET interworking 1");
Veerendranath Jakkamea7f0692021-08-11 19:13:12 +05308160 snprintf(buf, sizeof(buf),
8161 "ip -6 route replace fe80::/64 dev %s table local",
8162 intf);
8163 if (system(buf) != 0)
8164 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run: %s",
8165 buf);
8166 }
Vamsi Krishnaf642d6a2020-03-27 12:33:14 +05308167
Jouni Malinen8179fee2019-03-28 03:19:47 +02008168 dut->akm_values = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03008169 dut->sta_ft_ds = 0;
Jouni Malinen8179fee2019-03-28 03:19:47 +02008170
Sunil Dutt076081f2018-02-05 19:45:50 +05308171#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008172 if (get_driver_type(dut) == DRIVER_WCN &&
Sunil Dutt44595082018-02-12 19:41:45 +05308173 dut->config_rsnie == 1) {
8174 dut->config_rsnie = 0;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05308175 sta_config_params(dut, intf, STA_SET_RSNIE, 0);
Sunil Dutt076081f2018-02-05 19:45:50 +05308176 }
8177#endif /* NL80211_SUPPORT */
8178
Sunil Duttfebf8a82018-02-09 18:50:13 +05308179 if (dev_role && strcasecmp(dev_role, "STA-CFON") == 0) {
8180 dut->dev_role = DEVROLE_STA_CFON;
8181 return sta_cfon_reset_default(dut, conn, cmd);
8182 }
8183
Jouni Malinen439352d2018-09-13 03:42:23 +03008184 wpa_command(intf, "SET setband AUTO");
8185
Veerendranath Jakkamc1f71b62021-01-23 03:09:51 +05308186 ret = wpa_command_resp(intf, "GET_CAPABILITY ocv", resp, sizeof(resp));
8187 dut->ocvc = ret == 0 && strncmp(resp, "supported", 9) == 0;
8188
8189 ret = wpa_command_resp(intf, "GET_CAPABILITY beacon_prot", resp,
8190 sizeof(resp));
8191 dut->beacon_prot = ret == 0 && strncmp(resp, "supported", 9) == 0;
8192
Veerendranath Jakkam47867202020-12-21 01:53:52 +05308193 if (sta_set_client_privacy(dut, conn, intf,
8194 dut->program == PROGRAM_WPA3 &&
8195 dut->device_type == STA_dut &&
8196 dut->client_privacy_default)) {
8197 sigma_dut_print(dut, DUT_MSG_ERROR,
8198 "Failed to set client privacy functionality");
8199 /* sta_reset_default command is not really supposed to fail,
8200 * so allow this to continue. */
8201 }
8202
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +05308203 dut->saquery_oci_freq = 0;
Vamsi Krishnac1633d22020-05-06 18:31:21 +05308204
Sunil Duttfebf8a82018-02-09 18:50:13 +05308205 if (dut->program != PROGRAM_VHT)
8206 return cmd_sta_p2p_reset(dut, conn, cmd);
8207
Priyadharshini Gowthamana7dfd492015-11-09 14:34:08 -08008208 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008209}
8210
8211
Jouni Malinenf7222712019-06-13 01:50:21 +03008212static enum sigma_cmd_result cmd_sta_get_events(struct sigma_dut *dut,
8213 struct sigma_conn *conn,
8214 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008215{
8216 const char *program = get_param(cmd, "Program");
8217
8218 if (program == NULL)
8219 return -1;
8220#ifdef ANDROID_NAN
8221 if (strcasecmp(program, "NAN") == 0)
8222 return nan_cmd_sta_get_events(dut, conn, cmd);
8223#endif /* ANDROID_NAN */
8224 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
8225 return 0;
8226}
8227
8228
Jouni Malinen82905202018-04-29 17:20:10 +03008229static int sta_exec_action_url(struct sigma_dut *dut, struct sigma_conn *conn,
8230 struct sigma_cmd *cmd)
8231{
8232 const char *url = get_param(cmd, "url");
8233 const char *method = get_param(cmd, "method");
8234 pid_t pid;
8235 int status;
8236
8237 if (!url || !method)
8238 return -1;
8239
8240 /* TODO: Add support for method,post */
8241 if (strcasecmp(method, "get") != 0) {
8242 send_resp(dut, conn, SIGMA_ERROR,
8243 "ErrorCode,Unsupported method");
8244 return 0;
8245 }
8246
8247 pid = fork();
8248 if (pid < 0) {
8249 perror("fork");
8250 return -1;
8251 }
8252
8253 if (pid == 0) {
8254 char * argv[5] = { "wget", "-O", "/dev/null",
8255 (char *) url, NULL };
8256
8257 execv("/usr/bin/wget", argv);
8258 perror("execv");
8259 exit(0);
8260 return -1;
8261 }
8262
8263 if (waitpid(pid, &status, 0) < 0) {
8264 perror("waitpid");
8265 return -1;
8266 }
8267
8268 if (WIFEXITED(status)) {
8269 const char *errmsg;
8270
8271 if (WEXITSTATUS(status) == 0)
8272 return 1;
8273 sigma_dut_print(dut, DUT_MSG_INFO, "wget exit status %d",
8274 WEXITSTATUS(status));
8275 switch (WEXITSTATUS(status)) {
8276 case 4:
8277 errmsg = "errmsg,Network failure";
8278 break;
8279 case 8:
8280 errmsg = "errmsg,Server issued an error response";
8281 break;
8282 default:
8283 errmsg = "errmsg,Unknown failure from wget";
8284 break;
8285 }
8286 send_resp(dut, conn, SIGMA_ERROR, errmsg);
8287 return 0;
8288 }
8289
8290 send_resp(dut, conn, SIGMA_ERROR, "errmsg,Unknown failure");
8291 return 0;
8292}
8293
8294
Jouni Malinenf7222712019-06-13 01:50:21 +03008295static enum sigma_cmd_result cmd_sta_exec_action(struct sigma_dut *dut,
8296 struct sigma_conn *conn,
8297 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008298{
8299 const char *program = get_param(cmd, "Prog");
8300
Jouni Malinen82905202018-04-29 17:20:10 +03008301 if (program && !get_param(cmd, "interface"))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008302 return -1;
8303#ifdef ANDROID_NAN
Jouni Malinen82905202018-04-29 17:20:10 +03008304 if (program && strcasecmp(program, "NAN") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008305 return nan_cmd_sta_exec_action(dut, conn, cmd);
8306#endif /* ANDROID_NAN */
Jouni Malinen82905202018-04-29 17:20:10 +03008307
8308 if (program && strcasecmp(program, "Loc") == 0)
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07008309 return loc_cmd_sta_exec_action(dut, conn, cmd);
Jouni Malinen82905202018-04-29 17:20:10 +03008310
8311 if (get_param(cmd, "url"))
8312 return sta_exec_action_url(dut, conn, cmd);
8313
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008314 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
8315 return 0;
8316}
8317
8318
Jouni Malinenf7222712019-06-13 01:50:21 +03008319static enum sigma_cmd_result cmd_sta_set_11n(struct sigma_dut *dut,
8320 struct sigma_conn *conn,
8321 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008322{
8323 const char *intf = get_param(cmd, "Interface");
8324 const char *val, *mcs32, *rate;
8325
8326 val = get_param(cmd, "GREENFIELD");
8327 if (val) {
8328 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
8329 /* Enable GD */
8330 send_resp(dut, conn, SIGMA_ERROR,
8331 "ErrorCode,GF not supported");
8332 return 0;
8333 }
8334 }
8335
8336 val = get_param(cmd, "SGI20");
8337 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008338 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008339 case DRIVER_ATHEROS:
8340 ath_sta_set_sgi(dut, intf, val);
8341 break;
8342 default:
8343 send_resp(dut, conn, SIGMA_ERROR,
8344 "ErrorCode,SGI20 not supported");
8345 return 0;
8346 }
8347 }
8348
8349 mcs32 = get_param(cmd, "MCS32"); /* HT Duplicate Mode Enable/Disable */
8350 rate = get_param(cmd, "MCS_FIXEDRATE"); /* Fixed MCS rate (0..31) */
8351 if (mcs32 && rate) {
8352 /* TODO */
8353 send_resp(dut, conn, SIGMA_ERROR,
8354 "ErrorCode,MCS32,MCS_FIXEDRATE not supported");
8355 return 0;
8356 } else if (mcs32 && !rate) {
8357 /* TODO */
8358 send_resp(dut, conn, SIGMA_ERROR,
8359 "ErrorCode,MCS32 not supported");
8360 return 0;
8361 } else if (!mcs32 && rate) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008362 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008363 case DRIVER_ATHEROS:
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07008364 novap_reset(dut, intf, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008365 ath_sta_set_11nrates(dut, intf, rate);
8366 break;
8367 default:
8368 send_resp(dut, conn, SIGMA_ERROR,
8369 "ErrorCode,MCS32_FIXEDRATE not supported");
8370 return 0;
8371 }
8372 }
8373
8374 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
8375}
8376
8377
Arif Hussain7b47d2d2018-05-09 10:44:02 -07008378static void cmd_set_max_he_mcs(struct sigma_dut *dut, const char *intf,
8379 int mcs_config)
8380{
8381#ifdef NL80211_SUPPORT
8382 int ret;
8383
8384 switch (mcs_config) {
8385 case HE_80_MCS0_7:
8386 case HE_80_MCS0_9:
8387 case HE_80_MCS0_11:
8388 ret = sta_set_he_mcs(dut, intf, mcs_config);
8389 if (ret) {
8390 sigma_dut_print(dut, DUT_MSG_ERROR,
8391 "cmd_set_max_he_mcs: Setting of MCS:%d failed, ret:%d",
8392 mcs_config, ret);
8393 }
8394 break;
8395 default:
8396 sigma_dut_print(dut, DUT_MSG_ERROR,
8397 "cmd_set_max_he_mcs: Invalid mcs %d",
8398 mcs_config);
8399 break;
8400 }
8401#else /* NL80211_SUPPORT */
8402 sigma_dut_print(dut, DUT_MSG_ERROR,
8403 "max HE MCS cannot be changed without NL80211_SUPPORT defined");
8404#endif /* NL80211_SUPPORT */
8405}
8406
8407
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07008408struct wait_event {
8409 struct sigma_dut *dut;
8410 int cmd;
8411 unsigned int twt_op;
8412};
8413
8414#ifdef NL80211_SUPPORT
8415
8416static int twt_event_handler(struct nl_msg *msg, void *arg)
8417{
8418 struct wait_event *wait = arg;
8419 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
8420 struct nlattr *tb[NL80211_ATTR_MAX + 1];
8421 uint32_t subcmd;
8422 uint8_t *data = NULL;
8423 size_t len = 0;
8424 struct nlattr *twt_rsp[QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_MAX + 1];
8425 struct nlattr *twt_status[QCA_WLAN_VENDOR_ATTR_TWT_SETUP_MAX + 1];
8426 int cmd_id;
8427 unsigned char val;
8428
8429 if (!wait)
8430 return NL_SKIP;
8431
8432 if (gnlh->cmd != NL80211_CMD_VENDOR) {
8433 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
8434 "%s: NL cmd is not vendor %d", __func__,
8435 gnlh->cmd);
8436 return NL_SKIP;
8437 }
8438
8439 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
8440 genlmsg_attrlen(gnlh, 0), NULL);
8441
8442 if (!tb[NL80211_ATTR_VENDOR_ID] || !tb[NL80211_ATTR_VENDOR_SUBCMD]) {
8443 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
8444 "%s: vendor ID not found", __func__);
8445 return NL_SKIP;
8446 }
8447 subcmd = nla_get_u32(tb[NL80211_ATTR_VENDOR_SUBCMD]);
8448
8449 if (subcmd != QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) {
8450 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
8451 "%s: Not a TWT_cmd %d", __func__, subcmd);
8452 return NL_SKIP;
8453 }
8454 if (tb[NL80211_ATTR_VENDOR_DATA]) {
8455 data = nla_data(tb[NL80211_ATTR_VENDOR_DATA]);
8456 len = nla_len(tb[NL80211_ATTR_VENDOR_DATA]);
8457 } else {
8458 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
8459 "%s: vendor data not present", __func__);
8460 return NL_SKIP;
8461 }
8462 if (!data || !len) {
8463 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
8464 "Invalid vendor data or len");
8465 return NL_SKIP;
8466 }
8467 sigma_dut_print(wait->dut, DUT_MSG_DEBUG,
8468 "event data len %ld", len);
8469 hex_dump(wait->dut, data, len);
8470 if (nla_parse(twt_rsp, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_MAX,
8471 (struct nlattr *) data, len, NULL)) {
8472 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
8473 "vendor data parse error");
8474 return NL_SKIP;
8475 }
8476
8477 val = nla_get_u8(twt_rsp[QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION]);
8478 if (val != wait->twt_op) {
8479 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
8480 "Invalid TWT operation, expected %d, rcvd %d",
8481 wait->twt_op, val);
8482 return NL_SKIP;
8483 }
8484 if (nla_parse_nested(twt_status, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_MAX,
8485 twt_rsp[QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS],
8486 NULL)) {
8487 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
8488 "nla_parse failed for TWT event");
8489 return NL_SKIP;
8490 }
8491
8492 cmd_id = QCA_WLAN_VENDOR_ATTR_TWT_SETUP_STATUS;
8493 if (!twt_status[cmd_id]) {
8494 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
8495 "%s TWT resp status missing", __func__);
8496 wait->cmd = -1;
8497 } else {
8498 val = nla_get_u8(twt_status[cmd_id]);
8499 if (val != QCA_WLAN_VENDOR_TWT_STATUS_OK) {
8500 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
8501 "%s TWT resp status %d", __func__, val);
8502 wait->cmd = -1;
8503 } else {
8504 wait->cmd = 1;
8505 }
8506 }
8507
8508 return NL_SKIP;
8509}
8510
8511
8512static int wait_on_nl_socket(struct nl_sock *sock, struct sigma_dut *dut,
8513 unsigned int timeout)
8514{
8515 fd_set read_fd_set;
8516 int retval;
8517 int sock_fd;
8518 struct timeval time_out;
8519
8520 time_out.tv_sec = timeout;
8521 time_out.tv_usec = 0;
8522
8523 FD_ZERO(&read_fd_set);
8524
8525 if (!sock)
8526 return -1;
8527
8528 sock_fd = nl_socket_get_fd(sock);
8529 FD_SET(sock_fd, &read_fd_set);
8530
8531 retval = select(sock_fd + 1, &read_fd_set, NULL, NULL, &time_out);
8532
8533 if (retval == 0)
8534 sigma_dut_print(dut, DUT_MSG_ERROR,
8535 "%s: TWT event response timedout", __func__);
8536
8537 if (retval < 0)
8538 sigma_dut_print(dut, DUT_MSG_ERROR, "%s:no NL msgs, ret=%d",
8539 __func__, retval);
8540
8541 return retval;
8542}
8543
8544
8545#define TWT_ASYNC_EVENT_WAIT_TIME_SEC 6
8546
8547static int twt_async_event_wait(struct sigma_dut *dut, unsigned int twt_op)
8548{
8549 struct nl_cb *cb;
8550 int err_code = 0, select_retval = 0;
8551 struct wait_event wait_info;
8552
8553 cb = nl_socket_get_cb(dut->nl_ctx->event_sock);
8554 if (!cb) {
8555 sigma_dut_print(dut, DUT_MSG_ERROR,
8556 "event callback not found");
8557 return ERROR_SEND_STATUS;
8558 }
8559
8560 wait_info.cmd = 0;
8561 wait_info.dut = dut;
8562 wait_info.twt_op = twt_op;
8563
8564 nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, twt_event_handler, &wait_info);
8565
8566 while (!wait_info.cmd) {
8567 select_retval = wait_on_nl_socket(
8568 dut->nl_ctx->event_sock, dut,
8569 TWT_ASYNC_EVENT_WAIT_TIME_SEC);
8570
8571 if (select_retval > 0) {
8572 err_code = nl_recvmsgs(dut->nl_ctx->event_sock, cb);
8573 if (err_code < 0) {
8574 sigma_dut_print(dut, DUT_MSG_ERROR,
8575 "%s: nl rcv failed, err_code %d",
8576 __func__, err_code);
8577 break;
8578 }
8579 } else {
8580 sigma_dut_print(dut, DUT_MSG_ERROR,
8581 "%s: wait on socket failed %d",
8582 __func__, select_retval);
8583 err_code = 1;
8584 break;
8585 }
8586
8587 }
8588 nl_cb_put(cb);
8589
8590 if (wait_info.cmd < 0)
8591 err_code = 1;
8592
8593 sigma_dut_print(dut, DUT_MSG_DEBUG,
8594 "%s: rcvd cmd %d, err_code %d, s_ret %d",
8595 __func__, wait_info.cmd, err_code, select_retval);
8596
8597 return err_code;
8598}
8599
8600#endif /* NL80211_SUPPORT */
8601
8602
Srinivas Girigowda6707f032020-10-26 15:24:46 -07008603static int sta_twt_send_suspend(struct sigma_dut *dut, struct sigma_conn *conn,
8604 struct sigma_cmd *cmd)
8605{
8606#ifdef NL80211_SUPPORT
8607 struct nlattr *attr, *attr1;
8608 struct nl_msg *msg;
8609 int ifindex, ret;
8610 const char *intf = get_param(cmd, "Interface");
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 ERROR_SEND_STATUS;
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_CONFIG_TWT) ||
8626 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8627 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION,
8628 QCA_WLAN_TWT_SUSPEND) ||
8629 !(attr1 = nla_nest_start(msg,
Kiran Kumar Lokere7ede00c2021-08-09 00:59:52 -07008630 QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS))) {
Srinivas Girigowda6707f032020-10-26 15:24:46 -07008631 sigma_dut_print(dut, DUT_MSG_ERROR,
8632 "%s: err in adding vendor_cmd and vendor_data",
8633 __func__);
8634 nlmsg_free(msg);
8635 return ERROR_SEND_STATUS;
8636 }
8637 nla_nest_end(msg, attr1);
8638 nla_nest_end(msg, attr);
8639
8640 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8641 if (ret) {
8642 sigma_dut_print(dut, DUT_MSG_ERROR,
8643 "%s: err in send_and_recv_msgs, ret=%d",
8644 __func__, ret);
8645 }
8646
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07008647 if (!dut->sta_async_twt_supp)
8648 return ret;
8649
8650 return twt_async_event_wait(dut, QCA_WLAN_TWT_SUSPEND);
Srinivas Girigowda6707f032020-10-26 15:24:46 -07008651#else /* NL80211_SUPPORT */
8652 sigma_dut_print(dut, DUT_MSG_ERROR,
8653 "TWT suspend cannot be done without NL80211_SUPPORT defined");
8654 return ERROR_SEND_STATUS;
8655#endif /* NL80211_SUPPORT */
8656}
8657
8658
8659static int sta_twt_send_nudge(struct sigma_dut *dut, struct sigma_conn *conn,
8660 struct sigma_cmd *cmd,
8661 unsigned int suspend_duration)
8662{
8663#ifdef NL80211_SUPPORT
8664 struct nlattr *attr, *attr1;
8665 struct nl_msg *msg;
8666 int ifindex, ret;
8667 const char *intf = get_param(cmd, "Interface");
8668 int next_twt_size = 1;
8669
8670 ifindex = if_nametoindex(intf);
8671 if (ifindex == 0) {
8672 sigma_dut_print(dut, DUT_MSG_ERROR,
8673 "%s: Index for interface %s failed",
8674 __func__, intf);
8675 return ERROR_SEND_STATUS;
8676 }
8677
8678 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8679 NL80211_CMD_VENDOR)) ||
8680 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8681 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8682 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8683 QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) ||
8684 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8685 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION,
8686 QCA_WLAN_TWT_NUDGE) ||
8687 !(attr1 = nla_nest_start(msg,
8688 QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS)) ||
8689 (suspend_duration &&
8690 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_NUDGE_WAKE_TIME,
8691 suspend_duration)) ||
8692 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_NUDGE_NEXT_TWT_SIZE,
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -07008693 next_twt_size) ||
8694 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_NUDGE_FLOW_ID, 0)) {
Srinivas Girigowda6707f032020-10-26 15:24:46 -07008695 sigma_dut_print(dut, DUT_MSG_ERROR,
8696 "%s: err in adding vendor_cmd and vendor_data",
8697 __func__);
8698 nlmsg_free(msg);
8699 return ERROR_SEND_STATUS;
8700 }
8701 nla_nest_end(msg, attr1);
8702 nla_nest_end(msg, attr);
8703
8704 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8705 if (ret) {
8706 sigma_dut_print(dut, DUT_MSG_ERROR,
8707 "%s: err in send_and_recv_msgs, ret=%d",
8708 __func__, ret);
8709 }
8710
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07008711 if (!dut->sta_async_twt_supp)
8712 return ret;
8713
8714 return twt_async_event_wait(dut, QCA_WLAN_TWT_NUDGE);
Srinivas Girigowda6707f032020-10-26 15:24:46 -07008715#else /* NL80211_SUPPORT */
8716 sigma_dut_print(dut, DUT_MSG_ERROR,
8717 "TWT suspend cannot be done without NL80211_SUPPORT defined");
8718 return ERROR_SEND_STATUS;
8719#endif /* NL80211_SUPPORT */
8720}
8721
8722
8723static int sta_twt_suspend_or_nudge(struct sigma_dut *dut,
8724 struct sigma_conn *conn,
8725 struct sigma_cmd *cmd)
8726{
8727 const char *val;
8728
8729 val = get_param(cmd, "TWT_SuspendDuration");
8730 if (val) {
8731 unsigned int suspend_duration;
8732
8733 suspend_duration = atoi(val);
8734 suspend_duration = suspend_duration * 1000 * 1000;
8735 return sta_twt_send_nudge(dut, conn, cmd, suspend_duration);
8736 }
8737
8738 return sta_twt_send_suspend(dut, conn, cmd);
8739}
8740
8741
8742static int sta_twt_resume(struct sigma_dut *dut, struct sigma_conn *conn,
8743 struct sigma_cmd *cmd)
8744{
8745#ifdef NL80211_SUPPORT
8746 struct nlattr *attr, *attr1;
8747 struct nl_msg *msg;
8748 int ifindex, ret;
8749 const char *intf = get_param(cmd, "Interface");
8750 int next2_twt_size = 1;
8751 unsigned int resume_duration = 0;
8752 const char *val;
8753
8754 ifindex = if_nametoindex(intf);
8755 if (ifindex == 0) {
8756 sigma_dut_print(dut, DUT_MSG_ERROR,
8757 "%s: Index for interface %s failed",
8758 __func__, intf);
8759 return ERROR_SEND_STATUS;
8760 }
8761
8762 val = get_param(cmd, "TWT_ResumeDuration");
8763 if (val) {
8764 resume_duration = atoi(val);
8765 resume_duration = resume_duration * 1000 * 1000;
8766 }
8767
8768 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8769 NL80211_CMD_VENDOR)) ||
8770 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8771 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8772 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8773 QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) ||
8774 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8775 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION,
8776 QCA_WLAN_TWT_RESUME) ||
8777 !(attr1 = nla_nest_start(msg,
8778 QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS)) ||
8779 (resume_duration &&
8780 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_RESUME_NEXT2_TWT,
8781 resume_duration)) ||
8782 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_RESUME_NEXT_TWT_SIZE,
8783 next2_twt_size)) {
8784 sigma_dut_print(dut, DUT_MSG_ERROR,
8785 "%s: err in adding vendor_cmd and vendor_data",
8786 __func__);
8787 nlmsg_free(msg);
8788 return ERROR_SEND_STATUS;
8789 }
8790 nla_nest_end(msg, attr1);
8791 nla_nest_end(msg, attr);
8792
8793 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8794 if (ret) {
8795 sigma_dut_print(dut, DUT_MSG_ERROR,
8796 "%s: err in send_and_recv_msgs, ret=%d",
8797 __func__, ret);
8798 }
8799
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07008800 if (!dut->sta_async_twt_supp)
8801 return ret;
8802
8803 return twt_async_event_wait(dut, QCA_WLAN_TWT_RESUME);
Srinivas Girigowda6707f032020-10-26 15:24:46 -07008804#else /* NL80211_SUPPORT */
8805 sigma_dut_print(dut, DUT_MSG_ERROR,
8806 "TWT resume cannot be done without NL80211_SUPPORT defined");
8807 return ERROR_SEND_STATUS;
8808#endif /* NL80211_SUPPORT */
8809}
8810
8811
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07008812#define TWT_REQUEST_CMD 0
8813#define TWT_SUGGEST_CMD 1
8814#define TWT_DEMAND_CMD 2
8815
Arif Hussain480d5f42019-03-12 14:40:42 -07008816static int sta_twt_request(struct sigma_dut *dut, struct sigma_conn *conn,
8817 struct sigma_cmd *cmd)
8818{
8819#ifdef NL80211_SUPPORT
8820 struct nlattr *params;
8821 struct nlattr *attr;
Arif Hussain480d5f42019-03-12 14:40:42 -07008822 struct nl_msg *msg;
8823 int ifindex, ret;
8824 const char *val;
8825 const char *intf = get_param(cmd, "Interface");
8826 int wake_interval_exp = 10, nominal_min_wake_dur = 255,
8827 wake_interval_mantissa = 512;
8828 int flow_type = 0, twt_trigger = 0, target_wake_time = 0,
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07008829 protection = 0, cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_SUGGEST;
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -07008830 int bcast_twt = 0;
8831 int bcast_twt_id = 0, bcast_twt_recommdn = 0, bcast_twt_persis = 0;
Arif Hussain480d5f42019-03-12 14:40:42 -07008832
8833 ifindex = if_nametoindex(intf);
8834 if (ifindex == 0) {
8835 sigma_dut_print(dut, DUT_MSG_ERROR,
8836 "%s: Index for interface %s failed",
8837 __func__, intf);
8838 return -1;
8839 }
8840
8841 val = get_param(cmd, "FlowType");
8842 if (val) {
8843 flow_type = atoi(val);
8844 if (flow_type != 0 && flow_type != 1) {
8845 sigma_dut_print(dut, DUT_MSG_ERROR,
8846 "TWT: Invalid FlowType %d", flow_type);
8847 return -1;
8848 }
8849 }
8850
8851 val = get_param(cmd, "TWT_Trigger");
8852 if (val) {
8853 twt_trigger = atoi(val);
8854 if (twt_trigger != 0 && twt_trigger != 1) {
8855 sigma_dut_print(dut, DUT_MSG_ERROR,
8856 "TWT: Invalid TWT_Trigger %d",
8857 twt_trigger);
8858 return -1;
8859 }
8860 }
8861
8862 val = get_param(cmd, "Protection");
8863 if (val) {
8864 protection = atoi(val);
8865 if (protection != 0 && protection != 1) {
8866 sigma_dut_print(dut, DUT_MSG_ERROR,
8867 "TWT: Invalid Protection %d",
8868 protection);
8869 return -1;
8870 }
8871 }
8872
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07008873 val = get_param(cmd, "SetupCommand");
8874 if (val) {
8875 cmd_type = atoi(val);
8876 if (cmd_type == TWT_REQUEST_CMD)
8877 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_REQUEST;
8878 else if (cmd_type == TWT_SUGGEST_CMD)
8879 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_SUGGEST;
8880 else if (cmd_type == TWT_DEMAND_CMD)
8881 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_DEMAND;
8882 else
8883 sigma_dut_print(dut, DUT_MSG_ERROR,
8884 "Default suggest is used for cmd %d",
8885 cmd_type);
8886 }
8887
Arif Hussain480d5f42019-03-12 14:40:42 -07008888 val = get_param(cmd, "TargetWakeTime");
8889 if (val)
8890 target_wake_time = atoi(val);
8891
8892 val = get_param(cmd, "WakeIntervalMantissa");
8893 if (val)
8894 wake_interval_mantissa = atoi(val);
8895
8896 val = get_param(cmd, "WakeIntervalExp");
8897 if (val)
8898 wake_interval_exp = atoi(val);
8899
8900 val = get_param(cmd, "NominalMinWakeDur");
8901 if (val)
8902 nominal_min_wake_dur = atoi(val);
8903
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -07008904 val = get_param(cmd, "BTWT_ID");
8905 if (val) {
8906 bcast_twt_id = atoi(val);
8907 bcast_twt = 1;
8908 }
8909
8910 val = get_param(cmd, "BTWT_Persistence");
8911 if (val) {
8912 bcast_twt_persis = atoi(val);
8913 bcast_twt = 1;
8914 }
8915
8916 val = get_param(cmd, "BTWT_Recommendation");
8917 if (val) {
8918 bcast_twt_recommdn = atoi(val);
8919 bcast_twt = 1;
8920 }
8921
8922 if (bcast_twt)
8923 sigma_dut_print(dut, DUT_MSG_DEBUG,
8924 "BCAST_TWT: ID %d, RECOMM %d, PERSIS %d",
8925 bcast_twt_id, bcast_twt_recommdn,
8926 bcast_twt_persis);
8927
Arif Hussain480d5f42019-03-12 14:40:42 -07008928 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8929 NL80211_CMD_VENDOR)) ||
8930 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8931 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8932 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
Srinivas Girigowda6707f032020-10-26 15:24:46 -07008933 QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008934 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
Srinivas Girigowda6707f032020-10-26 15:24:46 -07008935 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION,
8936 QCA_WLAN_TWT_SET) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008937 !(params = nla_nest_start(
Srinivas Girigowda6707f032020-10-26 15:24:46 -07008938 msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008939 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_EXP,
8940 wake_interval_exp) ||
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07008941 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_REQ_TYPE, cmd_type) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -07008942 (twt_trigger &&
8943 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_TRIGGER)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008944 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE,
8945 flow_type) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -07008946 (protection &&
8947 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_PROTECTION)) ||
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -07008948 (bcast_twt &&
8949 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_BCAST)) ||
8950 (bcast_twt &&
8951 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_BCAST_ID,
8952 bcast_twt_id)) ||
8953 (bcast_twt &&
8954 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_BCAST_PERSISTENCE,
8955 bcast_twt_persis)) ||
8956 (bcast_twt &&
8957 nla_put_u8(msg,
8958 QCA_WLAN_VENDOR_ATTR_TWT_SETUP_BCAST_RECOMMENDATION,
8959 bcast_twt_recommdn)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008960 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_TIME,
8961 target_wake_time) ||
8962 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_DURATION,
8963 nominal_min_wake_dur) ||
8964 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_MANTISSA,
8965 wake_interval_mantissa)) {
8966 sigma_dut_print(dut, DUT_MSG_ERROR,
8967 "%s: err in adding vendor_cmd and vendor_data",
8968 __func__);
8969 nlmsg_free(msg);
8970 return -1;
8971 }
Arif Hussain480d5f42019-03-12 14:40:42 -07008972 nla_nest_end(msg, params);
8973 nla_nest_end(msg, attr);
8974
8975 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8976 if (ret) {
8977 sigma_dut_print(dut, DUT_MSG_ERROR,
8978 "%s: err in send_and_recv_msgs, ret=%d",
8979 __func__, ret);
8980 }
8981
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07008982 if (!dut->sta_async_twt_supp)
8983 return ret;
8984
8985 return twt_async_event_wait(dut, QCA_WLAN_TWT_SET);
Arif Hussain480d5f42019-03-12 14:40:42 -07008986#else /* NL80211_SUPPORT */
8987 sigma_dut_print(dut, DUT_MSG_ERROR,
8988 "TWT request cannot be done without NL80211_SUPPORT defined");
8989 return -1;
8990#endif /* NL80211_SUPPORT */
8991}
8992
8993
8994static int sta_twt_teardown(struct sigma_dut *dut, struct sigma_conn *conn,
8995 struct sigma_cmd *cmd)
8996{
8997 #ifdef NL80211_SUPPORT
8998 struct nlattr *params;
8999 struct nlattr *attr;
Arif Hussain480d5f42019-03-12 14:40:42 -07009000 int ifindex, ret;
9001 struct nl_msg *msg;
9002 const char *intf = get_param(cmd, "Interface");
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -07009003 int bcast_twt = 0;
9004 int bcast_twt_id = 0;
9005 const char *val;
Arif Hussain480d5f42019-03-12 14:40:42 -07009006
9007 ifindex = if_nametoindex(intf);
9008 if (ifindex == 0) {
9009 sigma_dut_print(dut, DUT_MSG_ERROR,
9010 "%s: Index for interface %s failed",
9011 __func__, intf);
9012 return -1;
9013 }
9014
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -07009015 val = get_param(cmd, "BTWT_ID");
9016 if (val) {
9017 bcast_twt_id = atoi(val);
9018 bcast_twt = 1;
9019 }
9020
Arif Hussain480d5f42019-03-12 14:40:42 -07009021 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9022 NL80211_CMD_VENDOR)) ||
9023 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9024 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9025 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009026 QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07009027 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009028 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION,
9029 QCA_WLAN_TWT_TERMINATE) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07009030 !(params = nla_nest_start(
9031 msg,
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009032 QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS)) ||
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -07009033 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE, 0) ||
9034 (bcast_twt &&
9035 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_BCAST)) ||
9036 (bcast_twt &&
9037 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_BCAST_ID,
9038 bcast_twt_id))) {
Arif Hussain480d5f42019-03-12 14:40:42 -07009039 sigma_dut_print(dut, DUT_MSG_ERROR,
9040 "%s: err in adding vendor_cmd and vendor_data",
9041 __func__);
9042 nlmsg_free(msg);
9043 return -1;
9044 }
Arif Hussain480d5f42019-03-12 14:40:42 -07009045 nla_nest_end(msg, params);
9046 nla_nest_end(msg, attr);
9047
9048 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9049 if (ret) {
9050 sigma_dut_print(dut, DUT_MSG_ERROR,
9051 "%s: err in send_and_recv_msgs, ret=%d",
9052 __func__, ret);
9053 }
9054
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07009055 if (!dut->sta_async_twt_supp)
9056 return ret;
9057
9058 return twt_async_event_wait(dut, QCA_WLAN_TWT_TERMINATE);
Arif Hussain480d5f42019-03-12 14:40:42 -07009059#else /* NL80211_SUPPORT */
9060 sigma_dut_print(dut, DUT_MSG_ERROR,
9061 "TWT teardown cannot be done without NL80211_SUPPORT defined");
9062 return -1;
9063#endif /* NL80211_SUPPORT */
9064}
9065
9066
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -08009067static int sta_transmit_omi(struct sigma_dut *dut, struct sigma_conn *conn,
9068 struct sigma_cmd *cmd)
9069{
9070#ifdef NL80211_SUPPORT
9071 struct nlattr *params;
9072 struct nlattr *attr;
9073 struct nlattr *attr1;
9074 struct nl_msg *msg;
9075 int ifindex, ret;
9076 const char *val;
9077 const char *intf = get_param(cmd, "Interface");
9078 uint8_t rx_nss = 0xFF, ch_bw = 0xFF, tx_nsts = 0xFF, ulmu_dis = 0,
9079 ulmu_data_dis = 0;
9080
9081 ifindex = if_nametoindex(intf);
9082 if (ifindex == 0) {
9083 sigma_dut_print(dut, DUT_MSG_ERROR,
9084 "%s: Index for interface %s failed",
9085 __func__, intf);
9086 return -1;
9087 }
9088 val = get_param(cmd, "OMCtrl_RxNSS");
9089 if (val)
9090 rx_nss = atoi(val);
9091
9092 val = get_param(cmd, "OMCtrl_ChnlWidth");
9093 if (val)
9094 ch_bw = atoi(val);
9095
9096 val = get_param(cmd, "OMCtrl_ULMUDisable");
9097 if (val)
9098 ulmu_dis = atoi(val);
9099
9100 val = get_param(cmd, "OMCtrl_TxNSTS");
9101 if (val)
9102 tx_nsts = atoi(val);
9103
9104 val = get_param(cmd, "OMCtrl_ULMUDataDisable");
9105 if (val)
9106 ulmu_data_dis = atoi(val);
9107
9108 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9109 NL80211_CMD_VENDOR)) ||
9110 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9111 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9112 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9113 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
9114 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9115 !(params = nla_nest_start(
9116 msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OMI_TX)) ||
9117 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9118 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_RX_NSS, rx_nss) ||
9119 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_CH_BW, ch_bw) ||
9120 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_TX_NSTS, tx_nsts) ||
9121 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DATA_DISABLE,
9122 ulmu_data_dis) ||
9123 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DISABLE,
9124 ulmu_dis)) {
9125 sigma_dut_print(dut, DUT_MSG_ERROR,
9126 "%s: err in adding vendor_cmd and vendor_data",
9127 __func__);
9128 nlmsg_free(msg);
9129 return -1;
9130 }
9131 nla_nest_end(msg, attr1);
9132 nla_nest_end(msg, params);
9133 nla_nest_end(msg, attr);
9134
9135 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9136 if (ret) {
9137 sigma_dut_print(dut, DUT_MSG_ERROR,
9138 "%s: err in send_and_recv_msgs, ret=%d",
9139 __func__, ret);
9140 }
9141
9142 return ret;
9143#else /* NL80211_SUPPORT */
9144 sigma_dut_print(dut, DUT_MSG_ERROR,
9145 "OMI TX cannot be processed without NL80211_SUPPORT defined");
9146 return -1;
9147#endif /* NL80211_SUPPORT */
9148}
9149
9150
Jouni Malinen224e3902021-06-09 16:41:27 +03009151static enum sigma_cmd_result
9152cmd_sta_set_wireless_vht(struct sigma_dut *dut, struct sigma_conn *conn,
9153 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009154{
9155 const char *intf = get_param(cmd, "Interface");
9156 const char *val;
Arif Hussaina37e9552018-06-20 17:05:59 -07009157 const char *program;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009158 int tkip = -1;
9159 int wep = -1;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05309160 int iwpriv_status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009161
Arif Hussaina37e9552018-06-20 17:05:59 -07009162 program = get_param(cmd, "Program");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009163 val = get_param(cmd, "SGI80");
9164 if (val) {
9165 int sgi80;
9166
9167 sgi80 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009168 run_iwpriv(dut, intf, "shortgi %d", sgi80);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009169 }
9170
9171 val = get_param(cmd, "TxBF");
9172 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009173 switch (get_driver_type(dut)) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009174 case DRIVER_WCN:
9175 if (sta_set_tx_beamformee(dut, intf, 1)) {
9176 send_resp(dut, conn, SIGMA_ERROR,
9177 "ErrorCode,Failed to set TX beamformee enable");
Jouni Malinen224e3902021-06-09 16:41:27 +03009178 return STATUS_SENT_ERROR;
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009179 }
9180 break;
9181 case DRIVER_ATHEROS:
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009182 if (run_iwpriv(dut, intf, "vhtsubfee 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009183 send_resp(dut, conn, SIGMA_ERROR,
9184 "ErrorCode,Setting vhtsubfee failed");
Jouni Malinen224e3902021-06-09 16:41:27 +03009185 return STATUS_SENT_ERROR;
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009186 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009187 if (run_iwpriv(dut, intf, "vhtsubfer 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009188 send_resp(dut, conn, SIGMA_ERROR,
9189 "ErrorCode,Setting vhtsubfer failed");
Jouni Malinen224e3902021-06-09 16:41:27 +03009190 return STATUS_SENT_ERROR;
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009191 }
9192 break;
9193 default:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009194 sigma_dut_print(dut, DUT_MSG_ERROR,
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009195 "Unsupported driver type");
9196 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009197 }
9198 }
9199
9200 val = get_param(cmd, "MU_TxBF");
9201 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009202 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009203 case DRIVER_ATHEROS:
9204 ath_sta_set_txsp_stream(dut, intf, "1SS");
9205 ath_sta_set_rxsp_stream(dut, intf, "1SS");
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009206 run_iwpriv(dut, intf, "vhtmubfee 1");
9207 run_iwpriv(dut, intf, "vhtmubfer 1");
Sunil Duttae9e5d12018-06-29 11:50:47 +05309208 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009209 case DRIVER_WCN:
9210 if (wcn_sta_set_sp_stream(dut, intf, "1SS") < 0) {
9211 send_resp(dut, conn, SIGMA_ERROR,
9212 "ErrorCode,Failed to set RX/TXSP_STREAM");
Jouni Malinen224e3902021-06-09 16:41:27 +03009213 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009214 }
Sunil Duttae9e5d12018-06-29 11:50:47 +05309215 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009216 default:
9217 sigma_dut_print(dut, DUT_MSG_ERROR,
9218 "Setting SP_STREAM not supported");
9219 break;
9220 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009221 }
9222
9223 val = get_param(cmd, "LDPC");
9224 if (val) {
9225 int ldpc;
9226
9227 ldpc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05309228 iwpriv_status = run_iwpriv(dut, intf, "ldpc %d", ldpc);
9229 if (iwpriv_status)
9230 sta_config_params(dut, intf, STA_SET_LDPC, ldpc);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009231 }
9232
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08009233 val = get_param(cmd, "BCC");
9234 if (val) {
9235 int bcc;
9236
9237 bcc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
9238 /* use LDPC iwpriv itself to set bcc coding, bcc coding
9239 * is mutually exclusive to bcc */
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05309240 iwpriv_status = run_iwpriv(dut, intf, "ldpc %d", !bcc);
9241 if (iwpriv_status)
9242 sta_config_params(dut, intf, STA_SET_LDPC, !bcc);
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08009243 }
9244
Arif Hussain7b47d2d2018-05-09 10:44:02 -07009245 val = get_param(cmd, "MaxHE-MCS_1SS_RxMapLTE80");
9246 if (val && dut->sta_nss == 1)
9247 cmd_set_max_he_mcs(dut, intf, atoi(val));
9248
9249 val = get_param(cmd, "MaxHE-MCS_2SS_RxMapLTE80");
9250 if (val && dut->sta_nss == 2)
9251 cmd_set_max_he_mcs(dut, intf, atoi(val));
9252
Arif Hussainac6c5112018-05-25 17:34:00 -07009253 val = get_param(cmd, "MCS_FixedRate");
9254 if (val) {
9255#ifdef NL80211_SUPPORT
9256 int mcs, ratecode = 0;
9257 enum he_mcs_config mcs_config;
9258 int ret;
Jouni Malinenb9b671d2019-04-26 13:23:17 +03009259 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07009260
9261 ratecode = (0x07 & dut->sta_nss) << 5;
9262 mcs = atoi(val);
9263 /* Add the MCS to the ratecode */
9264 if (mcs >= 0 && mcs <= 11) {
9265 ratecode += mcs;
9266 if (dut->device_type == STA_testbed &&
9267 mcs > 7 && mcs <= 11) {
9268 if (mcs <= 9)
9269 mcs_config = HE_80_MCS0_9;
9270 else
9271 mcs_config = HE_80_MCS0_11;
9272 ret = sta_set_he_mcs(dut, intf, mcs_config);
9273 if (ret) {
9274 sigma_dut_print(dut, DUT_MSG_ERROR,
9275 "MCS_FixedRate: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
9276 mcs, mcs_config, ret);
9277 }
9278 }
9279 snprintf(buf, sizeof(buf),
9280 "iwpriv %s set_11ax_rate 0x%03x",
9281 intf, ratecode);
9282 if (system(buf) != 0) {
9283 sigma_dut_print(dut, DUT_MSG_ERROR,
9284 "MCS_FixedRate: iwpriv setting of 11ax rates 0x%03x failed",
9285 ratecode);
9286 }
9287 } else {
9288 sigma_dut_print(dut, DUT_MSG_ERROR,
9289 "MCS_FixedRate: HE MCS %d not supported",
9290 mcs);
9291 }
9292#else /* NL80211_SUPPORT */
9293 sigma_dut_print(dut, DUT_MSG_ERROR,
9294 "MCS_FixedRate cannot be changed without NL80211_SUPPORT defined");
9295#endif /* NL80211_SUPPORT */
9296 }
9297
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009298 val = get_param(cmd, "opt_md_notif_ie");
9299 if (val) {
9300 char *result = NULL;
9301 char delim[] = ";";
9302 char token[30];
9303 int value, config_val = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309304 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009305
Peng Xub8fc5cc2017-05-10 17:27:28 -07009306 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309307 result = strtok_r(token, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009308
9309 /* Extract the NSS information */
9310 if (result) {
9311 value = atoi(result);
9312 switch (value) {
9313 case 1:
9314 config_val = 1;
9315 break;
9316 case 2:
9317 config_val = 3;
9318 break;
9319 case 3:
9320 config_val = 7;
9321 break;
9322 case 4:
9323 config_val = 15;
9324 break;
9325 default:
9326 config_val = 3;
9327 break;
9328 }
9329
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009330 run_iwpriv(dut, intf, "rxchainmask %d", config_val);
9331 run_iwpriv(dut, intf, "txchainmask %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009332
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009333 }
9334
9335 /* Extract the channel width information */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309336 result = strtok_r(NULL, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009337 if (result) {
9338 value = atoi(result);
9339 switch (value) {
9340 case 20:
9341 config_val = 0;
9342 break;
9343 case 40:
9344 config_val = 1;
9345 break;
9346 case 80:
9347 config_val = 2;
9348 break;
9349 case 160:
9350 config_val = 3;
9351 break;
9352 default:
9353 config_val = 2;
9354 break;
9355 }
9356
9357 dut->chwidth = config_val;
9358
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009359 run_iwpriv(dut, intf, "chwidth %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009360 }
9361
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009362 run_iwpriv(dut, intf, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009363 }
9364
9365 val = get_param(cmd, "nss_mcs_cap");
9366 if (val) {
9367 int nss, mcs;
9368 char token[20];
9369 char *result = NULL;
9370 unsigned int vht_mcsmap = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309371 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009372
Peng Xub8fc5cc2017-05-10 17:27:28 -07009373 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309374 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05309375 if (!result) {
9376 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07009377 "NSS not specified");
9378 send_resp(dut, conn, SIGMA_ERROR,
9379 "errorCode,NSS not specified");
Jouni Malinen224e3902021-06-09 16:41:27 +03009380 return STATUS_SENT_ERROR;
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05309381 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009382 nss = atoi(result);
9383
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009384 run_iwpriv(dut, intf, "nss %d", nss);
Arif Hussainac6c5112018-05-25 17:34:00 -07009385 dut->sta_nss = nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009386
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309387 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009388 if (result == NULL) {
9389 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07009390 "MCS not specified");
9391 send_resp(dut, conn, SIGMA_ERROR,
9392 "errorCode,MCS not specified");
Jouni Malinen224e3902021-06-09 16:41:27 +03009393 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009394 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309395 result = strtok_r(result, "-", &saveptr);
9396 result = strtok_r(NULL, "-", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05309397 if (!result) {
9398 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07009399 "MCS not specified");
9400 send_resp(dut, conn, SIGMA_ERROR,
9401 "errorCode,MCS not specified");
Jouni Malinen224e3902021-06-09 16:41:27 +03009402 return STATUS_SENT_ERROR;
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05309403 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009404 mcs = atoi(result);
9405
Arif Hussaina37e9552018-06-20 17:05:59 -07009406 if (program && strcasecmp(program, "HE") == 0) {
9407#ifdef NL80211_SUPPORT
9408 enum he_mcs_config mcs_config;
9409 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009410
Arif Hussaina37e9552018-06-20 17:05:59 -07009411 if (mcs >= 0 && mcs <= 7) {
9412 mcs_config = HE_80_MCS0_7;
9413 } else if (mcs > 7 && mcs <= 9) {
9414 mcs_config = HE_80_MCS0_9;
9415 } else if (mcs > 9 && mcs <= 11) {
9416 mcs_config = HE_80_MCS0_11;
9417 } else {
9418 sigma_dut_print(dut, DUT_MSG_ERROR,
9419 "nss_mcs_cap: HE: Invalid mcs: %d",
9420 mcs);
9421 send_resp(dut, conn, SIGMA_ERROR,
9422 "errorCode,Invalid MCS");
Jouni Malinen224e3902021-06-09 16:41:27 +03009423 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009424 }
Arif Hussaina37e9552018-06-20 17:05:59 -07009425
9426 ret = sta_set_he_mcs(dut, intf, mcs_config);
9427 if (ret) {
9428 sigma_dut_print(dut, DUT_MSG_ERROR,
9429 "nss_mcs_cap: HE: Setting of MCS failed, mcs_config: %d, ret: %d",
9430 mcs_config, ret);
9431 send_resp(dut, conn, SIGMA_ERROR,
9432 "errorCode,Failed to set MCS");
Jouni Malinen224e3902021-06-09 16:41:27 +03009433 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009434 }
Arif Hussaina37e9552018-06-20 17:05:59 -07009435#else /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009436 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07009437 "nss_mcs_cap: HE: MCS cannot be changed without NL80211_SUPPORT defined");
9438#endif /* NL80211_SUPPORT */
9439 } else {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009440 run_iwpriv(dut, intf, "vhtmcs %d", mcs);
Arif Hussaina37e9552018-06-20 17:05:59 -07009441
9442 switch (nss) {
9443 case 1:
9444 switch (mcs) {
9445 case 7:
9446 vht_mcsmap = 0xfffc;
9447 break;
9448 case 8:
9449 vht_mcsmap = 0xfffd;
9450 break;
9451 case 9:
9452 vht_mcsmap = 0xfffe;
9453 break;
9454 default:
9455 vht_mcsmap = 0xfffe;
9456 break;
9457 }
9458 break;
9459 case 2:
9460 switch (mcs) {
9461 case 7:
9462 vht_mcsmap = 0xfff0;
9463 break;
9464 case 8:
9465 vht_mcsmap = 0xfff5;
9466 break;
9467 case 9:
9468 vht_mcsmap = 0xfffa;
9469 break;
9470 default:
9471 vht_mcsmap = 0xfffa;
9472 break;
9473 }
9474 break;
9475 case 3:
9476 switch (mcs) {
9477 case 7:
9478 vht_mcsmap = 0xffc0;
9479 break;
9480 case 8:
9481 vht_mcsmap = 0xffd5;
9482 break;
9483 case 9:
9484 vht_mcsmap = 0xffea;
9485 break;
9486 default:
9487 vht_mcsmap = 0xffea;
9488 break;
9489 }
9490 break;
9491 default:
9492 vht_mcsmap = 0xffea;
9493 break;
9494 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009495 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009496 }
9497 }
9498
9499 /* UNSUPPORTED: val = get_param(cmd, "Tx_lgi_rate"); */
9500
9501 val = get_param(cmd, "Vht_tkip");
9502 if (val)
9503 tkip = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
9504
9505 val = get_param(cmd, "Vht_wep");
9506 if (val)
9507 wep = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
9508
9509 if (tkip != -1 || wep != -1) {
9510 if ((tkip == 1 && wep != 0) || (wep == 1 && tkip != 0)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009511 run_iwpriv(dut, intf, "htweptkip 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009512 } else if ((tkip == 0 && wep != 1) || (wep == 0 && tkip != 1)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009513 run_iwpriv(dut, intf, "htweptkip 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009514 } else {
Jouni Malinen224e3902021-06-09 16:41:27 +03009515 send_resp(dut, conn, SIGMA_ERROR,
9516 "ErrorCode,mixed mode of VHT TKIP/WEP not supported");
9517 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009518 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009519 }
9520
Kiran Kumar Lokere09dbcef2021-08-09 00:01:41 -07009521 val = get_param(cmd, "TWTSchedSTASupport");
9522 if (val) {
9523 int set_val;
9524
9525 switch (get_driver_type(dut)) {
9526 case DRIVER_WCN:
9527 if (strcasecmp(val, "Enable") == 0) {
9528 set_val = 1;
9529 } else if (strcasecmp(val, "Disable") == 0) {
9530 set_val = 0;
9531 } else {
9532 send_resp(dut, conn, SIGMA_ERROR,
9533 "ErrorCode,Invalid TWTSchedSTASupport");
9534 return STATUS_SENT_ERROR;
9535 }
9536
9537 if (sta_set_bcast_twt_support(dut, intf, set_val)) {
9538 send_resp(dut, conn, SIGMA_ERROR,
9539 "ErrorCode,Failed to set TWTSchedSTASupport");
9540 return STATUS_SENT_ERROR;
9541 }
9542 break;
9543 default:
9544 sigma_dut_print(dut, DUT_MSG_ERROR,
9545 "Setting TWTSchedSTASupport not supported");
9546 break;
9547 }
9548 }
9549
9550 val = get_param(cmd, "MBSSID_RxCtrl");
9551 if (val) {
9552 int set_val;
9553
9554 switch (get_driver_type(dut)) {
9555 case DRIVER_WCN:
9556 if (strcasecmp(val, "Enable") == 0) {
9557 set_val = 1;
9558 } else if (strcasecmp(val, "Disable") == 0) {
9559 set_val = 0;
9560 } else {
9561 send_resp(dut, conn, SIGMA_ERROR,
9562 "ErrorCode,Invalid MBSSID_RxCtrl");
9563 return STATUS_SENT_ERROR;
9564 }
9565
9566 if (sta_set_rx_ctrl_multi_bss(dut, intf, set_val)) {
9567 send_resp(dut, conn, SIGMA_ERROR,
9568 "ErrorCode,Failed to set MBSSID_RxCtrl");
9569 return STATUS_SENT_ERROR;
9570 }
9571 break;
9572 default:
9573 sigma_dut_print(dut, DUT_MSG_ERROR,
9574 "Setting MBSSID_RxCtrl not supported");
9575 break;
9576 }
9577 }
9578
Arif Hussain55f00da2018-07-03 08:28:26 -07009579 val = get_param(cmd, "txBandwidth");
9580 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009581 switch (get_driver_type(dut)) {
Arif Hussain55f00da2018-07-03 08:28:26 -07009582 case DRIVER_WCN:
9583 if (wcn_sta_set_width(dut, intf, val) < 0) {
9584 send_resp(dut, conn, SIGMA_ERROR,
9585 "ErrorCode,Failed to set txBandwidth");
Jouni Malinen224e3902021-06-09 16:41:27 +03009586 return STATUS_SENT_ERROR;
Arif Hussain55f00da2018-07-03 08:28:26 -07009587 }
9588 break;
9589 case DRIVER_ATHEROS:
9590 if (ath_set_width(dut, conn, intf, val) < 0) {
9591 send_resp(dut, conn, SIGMA_ERROR,
9592 "ErrorCode,Failed to set txBandwidth");
Jouni Malinen224e3902021-06-09 16:41:27 +03009593 return STATUS_SENT_ERROR;
Arif Hussain55f00da2018-07-03 08:28:26 -07009594 }
9595 break;
9596 default:
9597 sigma_dut_print(dut, DUT_MSG_ERROR,
9598 "Setting txBandwidth not supported");
9599 break;
9600 }
9601 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009602
Arif Hussain9765f7d2018-07-03 08:28:26 -07009603 val = get_param(cmd, "BeamformeeSTS");
9604 if (val) {
Kiran Kumar Lokerebc89d432018-07-10 12:20:13 -07009605 if (sta_set_tx_beamformee(dut, intf, 1)) {
9606 send_resp(dut, conn, SIGMA_ERROR,
9607 "ErrorCode,Failed to set TX beamformee enable");
Jouni Malinen224e3902021-06-09 16:41:27 +03009608 return STATUS_SENT_ERROR;
Kiran Kumar Lokerebc89d432018-07-10 12:20:13 -07009609 }
9610
Arif Hussain9765f7d2018-07-03 08:28:26 -07009611 if (sta_set_beamformee_sts(dut, intf, atoi(val))) {
9612 send_resp(dut, conn, SIGMA_ERROR,
9613 "ErrorCode,Failed to set BeamformeeSTS");
Jouni Malinen224e3902021-06-09 16:41:27 +03009614 return STATUS_SENT_ERROR;
Arif Hussain9765f7d2018-07-03 08:28:26 -07009615 }
9616 }
9617
Arif Hussain68d23f52018-07-11 13:39:08 -07009618 val = get_param(cmd, "Trig_MAC_Padding_Dur");
9619 if (val) {
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07009620#ifdef NL80211_SUPPORT
9621 enum qca_wlan_he_mac_padding_dur set_val;
9622
9623 switch (atoi(val)) {
9624 case 16:
9625 set_val = QCA_WLAN_HE_16US_OF_PROCESS_TIME;
9626 break;
9627 case 8:
9628 set_val = QCA_WLAN_HE_8US_OF_PROCESS_TIME;
9629 break;
9630 default:
9631 set_val = QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME;
9632 break;
9633 }
9634 if (sta_set_mac_padding_duration(dut, intf, set_val)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07009635 send_resp(dut, conn, SIGMA_ERROR,
9636 "ErrorCode,Failed to set MAC padding duration");
Jouni Malinen224e3902021-06-09 16:41:27 +03009637 return STATUS_SENT_ERROR;
Arif Hussain68d23f52018-07-11 13:39:08 -07009638 }
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07009639#else /* NL80211_SUPPORT */
9640 sigma_dut_print(dut, DUT_MSG_ERROR,
9641 "MAC padding duration cannot be changed without NL80211_SUPPORT defined");
9642#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07009643 }
9644
Arif Hussain480d5f42019-03-12 14:40:42 -07009645 val = get_param(cmd, "TWT_ReqSupport");
9646 if (val) {
9647 int set_val;
9648
9649 if (strcasecmp(val, "Enable") == 0) {
9650 set_val = 1;
9651 } else if (strcasecmp(val, "Disable") == 0) {
9652 set_val = 0;
9653 } else {
9654 send_resp(dut, conn, SIGMA_ERROR,
9655 "ErrorCode,Invalid TWT_ReqSupport");
Jouni Malinen224e3902021-06-09 16:41:27 +03009656 return STATUS_SENT_ERROR;
Arif Hussain480d5f42019-03-12 14:40:42 -07009657 }
9658
9659 if (sta_set_twt_req_support(dut, intf, set_val)) {
9660 sigma_dut_print(dut, DUT_MSG_ERROR,
9661 "Failed to set TWT req support %d",
9662 set_val);
9663 send_resp(dut, conn, SIGMA_ERROR,
9664 "ErrorCode,Failed to set TWT_ReqSupport");
Jouni Malinen224e3902021-06-09 16:41:27 +03009665 return STATUS_SENT_ERROR;
Arif Hussain480d5f42019-03-12 14:40:42 -07009666 }
9667 }
9668
Kiran Kumar Lokered0ec5ed2021-04-01 00:15:04 -07009669 val = get_param(cmd, "PreamblePunctRx");
9670 if (val && get_driver_type(dut) == DRIVER_WCN) {
9671 int set_val;
9672
9673 if (strcasecmp(val, "Enable") == 0) {
9674 set_val = 1;
9675 } else if (strcasecmp(val, "Disable") == 0) {
9676 set_val = 0;
9677 } else {
9678 send_resp(dut, conn, SIGMA_ERROR,
9679 "ErrorCode,Invalid PreamblePunctRx");
9680 return STATUS_SENT_ERROR;
9681 }
9682
9683 if (sta_set_punctured_preamble_rx(dut, intf, set_val)) {
9684 sigma_dut_print(dut, DUT_MSG_ERROR,
9685 "Failed to set PreamblePunctRx support %d",
9686 set_val);
9687 send_resp(dut, conn, SIGMA_ERROR,
9688 "ErrorCode,Failed to set PreamblePunctRx");
9689 return STATUS_SENT_ERROR;
9690 }
9691 }
9692
Srinivas Girigowda0525e292020-11-12 13:28:21 -08009693 val = get_param(cmd, "FullBW_ULMUMIMO");
9694 if (val) {
9695 int set_val;
9696
9697 if (strcasecmp(val, "Enable") == 0) {
9698 set_val = 1;
9699 } else if (strcasecmp(val, "Disable") == 0) {
9700 set_val = 0;
9701 } else {
9702 send_resp(dut, conn, SIGMA_ERROR,
9703 "ErrorCode,Invalid FullBW_ULMUMIMO");
9704 return STATUS_SENT_ERROR;
9705 }
9706
9707 if (sta_set_fullbw_ulmumimo(dut, intf, set_val)) {
9708 sigma_dut_print(dut, DUT_MSG_ERROR,
9709 "Failed to set FullBW_ULMUMIMO %d",
9710 set_val);
9711 send_resp(dut, conn, SIGMA_ERROR,
9712 "ErrorCode,Failed to set FullBW_ULMUMIMO");
9713 return STATUS_SENT_ERROR;
9714 }
9715 }
9716
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009717 val = get_param(cmd, "TWTInfoFrameTx");
9718 if (val) {
9719 if (strcasecmp(val, "Enable") == 0) {
9720 /* No-op */
9721 } else if (strcasecmp(val, "Disable") == 0) {
9722 /* No-op */
9723 } else {
9724 send_resp(dut, conn, SIGMA_ERROR,
9725 "ErrorCode,Invalid TWTInfoFrameTx");
9726 return STATUS_SENT_ERROR;
9727 }
9728 }
9729
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07009730 val = get_param(cmd, "MU_EDCA");
9731 if (val && (strcasecmp(val, "Override") == 0)) {
9732 if (sta_set_mu_edca_override(dut, intf, 1)) {
9733 send_resp(dut, conn, SIGMA_ERROR,
9734 "ErrorCode,Failed to set MU EDCA override");
Jouni Malinen224e3902021-06-09 16:41:27 +03009735 return STATUS_SENT_ERROR;
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07009736 }
9737 }
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009738
Kiran Kumar Lokerefa7c7b92021-08-09 00:50:55 -07009739 val = get_param(cmd, "PPDUTxType");
9740 if (val && strcasecmp(val, "ER-SU") == 0) {
9741 if (sta_set_er_su_ppdu_type_tx(dut, intf, 1)) {
9742 send_resp(dut, conn, SIGMA_ERROR,
9743 "ErrorCode,Failed to set ER-SU PPDU type Tx");
9744 return STATUS_SENT_ERROR;
9745 }
9746 }
9747
9748 val = get_param(cmd, "RUAllocTone");
9749 if (val && strcasecmp(val, "242") == 0) {
9750 if (sta_set_ru_242_tone_tx(dut, intf, 1)) {
9751 send_resp(dut, conn, SIGMA_ERROR,
9752 "ErrorCode,Failed to set RU 242 tone Tx");
9753 return STATUS_SENT_ERROR;
9754 }
9755 }
9756
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07009757 val = get_param(cmd, "OMControl");
9758 if (val) {
9759 int set_val = 1;
9760
9761 if (strcasecmp(val, "Enable") == 0)
9762 set_val = 1;
9763 else if (strcasecmp(val, "Disable") == 0)
9764 set_val = 0;
9765
9766 if (sta_set_om_ctrl_supp(dut, intf, set_val)) {
9767 send_resp(dut, conn, SIGMA_ERROR,
9768 "ErrorCode,Failed to set OM ctrl supp");
Jouni Malinen224e3902021-06-09 16:41:27 +03009769 return STATUS_SENT_ERROR;
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07009770 }
9771 }
9772
Kiran Kumar Lokere4f2d4b02021-04-01 00:07:39 -07009773 val = get_param(cmd, "BSSMaxIdlePeriod");
9774 if (val && sta_set_bss_max_idle_period(dut, intf, atoi(val))) {
9775 send_resp(dut, conn, SIGMA_ERROR,
9776 "ErrorCode,Failed to set BSS max idle period");
9777 return STATUS_SENT_ERROR;
9778 }
9779
Kiran Kumar Lokere07ad92b2021-08-09 00:27:14 -07009780 val = get_param(cmd, "BSS_max_idle");
9781 if (val) {
9782 int set_val = 0;
9783
9784 if (strcasecmp(val, "Enable") == 0)
9785 set_val = 1;
9786 else if (strcasecmp(val, "Disable") == 0)
9787 set_val = 0;
9788 if (sta_set_bss_max_idle_support(dut, intf, set_val)) {
9789 send_resp(dut, conn, SIGMA_ERROR,
9790 "ErrorCode,Failed to set BSS max idle support");
9791 return STATUS_SENT_ERROR;
9792 }
9793 }
9794
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009795 val = get_param(cmd, "ADDBAResp_BufSize");
9796 if (val) {
9797 int buf_size;
9798
9799 if (strcasecmp(val, "gt64") == 0)
9800 buf_size = 256;
9801 else
9802 buf_size = 64;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009803 if (get_driver_type(dut) == DRIVER_WCN &&
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009804 sta_set_addba_buf_size(dut, intf, buf_size)) {
9805 send_resp(dut, conn, SIGMA_ERROR,
9806 "ErrorCode,set addbaresp_buff_size failed");
Jouni Malinen224e3902021-06-09 16:41:27 +03009807 return STATUS_SENT_ERROR;
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009808 }
9809 }
9810
9811 val = get_param(cmd, "ADDBAReq_BufSize");
9812 if (val) {
9813 int buf_size;
9814
9815 if (strcasecmp(val, "gt64") == 0)
9816 buf_size = 256;
9817 else
9818 buf_size = 64;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009819 if (get_driver_type(dut) == DRIVER_WCN &&
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009820 sta_set_addba_buf_size(dut, intf, buf_size)) {
9821 send_resp(dut, conn, SIGMA_ERROR,
9822 "ErrorCode,set addbareq_buff_size failed");
Jouni Malinen224e3902021-06-09 16:41:27 +03009823 return STATUS_SENT_ERROR;
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009824 }
9825 }
9826
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009827 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
9828}
9829
9830
9831static int sta_set_wireless_60g(struct sigma_dut *dut,
9832 struct sigma_conn *conn,
9833 struct sigma_cmd *cmd)
9834{
9835 const char *dev_role = get_param(cmd, "DevRole");
9836
9837 if (!dev_role) {
9838 send_resp(dut, conn, SIGMA_INVALID,
9839 "ErrorCode,DevRole not specified");
9840 return 0;
9841 }
9842
9843 if (strcasecmp(dev_role, "PCP") == 0)
9844 return sta_set_60g_pcp(dut, conn, cmd);
9845 if (strcasecmp(dev_role, "STA") == 0)
9846 return sta_set_60g_sta(dut, conn, cmd);
9847 send_resp(dut, conn, SIGMA_INVALID,
9848 "ErrorCode,DevRole not supported");
9849 return 0;
9850}
9851
9852
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05309853static int sta_set_wireless_oce(struct sigma_dut *dut, struct sigma_conn *conn,
9854 struct sigma_cmd *cmd)
9855{
9856 int status;
9857 const char *intf = get_param(cmd, "Interface");
9858 const char *val = get_param(cmd, "DevRole");
9859
9860 if (val && strcasecmp(val, "STA-CFON") == 0) {
9861 status = sta_cfon_set_wireless(dut, conn, cmd);
9862 if (status)
9863 return status;
9864 }
9865 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
9866}
9867
9868
Jouni Malinen67433fc2020-06-26 22:50:33 +03009869static enum sigma_cmd_result
9870sta_set_wireless_wpa3(struct sigma_dut *dut, struct sigma_conn *conn,
9871 struct sigma_cmd *cmd)
Vamsi Krishnac1633d22020-05-06 18:31:21 +05309872{
9873 const char *intf = get_param(cmd, "Interface");
9874 const char *val;
9875
9876 val = get_param(cmd, "ocvc");
9877 if (val)
9878 dut->ocvc = atoi(val);
9879
Jouni Malinen67433fc2020-06-26 22:50:33 +03009880 val = get_param(cmd, "ClientPrivacy");
Veerendranath Jakkam47867202020-12-21 01:53:52 +05309881 if (val && dut->client_privacy != atoi(val) &&
9882 sta_set_client_privacy(dut, conn, intf, atoi(val))) {
9883 send_resp(dut, conn, SIGMA_ERROR,
9884 "errorCode,Failed to configure random MAC address use");
9885 return STATUS_SENT_ERROR;
Jouni Malinen67433fc2020-06-26 22:50:33 +03009886 }
9887
Vamsi Krishnac1633d22020-05-06 18:31:21 +05309888 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
9889}
9890
9891
Jouni Malinenf7222712019-06-13 01:50:21 +03009892static enum sigma_cmd_result cmd_sta_set_wireless(struct sigma_dut *dut,
9893 struct sigma_conn *conn,
9894 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009895{
9896 const char *val;
9897
9898 val = get_param(cmd, "Program");
9899 if (val) {
9900 if (strcasecmp(val, "11n") == 0)
9901 return cmd_sta_set_11n(dut, conn, cmd);
Amarnath Hullur Subramanyam4f860292018-01-31 03:49:35 -08009902 if (strcasecmp(val, "VHT") == 0 || strcasecmp(val, "HE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009903 return cmd_sta_set_wireless_vht(dut, conn, cmd);
9904 if (strcasecmp(val, "60ghz") == 0)
9905 return sta_set_wireless_60g(dut, conn, cmd);
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05309906 if (strcasecmp(val, "OCE") == 0)
9907 return sta_set_wireless_oce(dut, conn, cmd);
Alexei Avshalom Lazar66bb9972018-12-18 16:01:43 +02009908 /* sta_set_wireless in WPS program is only used for 60G */
9909 if (is_60g_sigma_dut(dut))
9910 return sta_set_wireless_60g(dut, conn, cmd);
Vamsi Krishnac1633d22020-05-06 18:31:21 +05309911 if (strcasecmp(val, "WPA3") == 0)
9912 return sta_set_wireless_wpa3(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009913 send_resp(dut, conn, SIGMA_ERROR,
9914 "ErrorCode,Program value not supported");
9915 } else {
9916 send_resp(dut, conn, SIGMA_ERROR,
9917 "ErrorCode,Program argument not available");
9918 }
9919
9920 return 0;
9921}
9922
9923
9924static void ath_sta_inject_frame(struct sigma_dut *dut, const char *intf,
9925 int tid)
9926{
9927 char buf[100];
9928 int tid_to_dscp [] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 };
9929
Pradeep Reddy POTTETId31d1322016-10-13 17:22:03 +05309930 if (tid < 0 ||
9931 tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) {
9932 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid);
9933 return;
9934 }
9935
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009936 /*
9937 * Two ways to ensure that addba request with a
9938 * non zero TID could be sent out. EV 117296
9939 */
9940 snprintf(buf, sizeof(buf),
9941 "ping -c 8 -Q %d `arp -a | grep wlan0 | awk '{print $2}' | tr -d '()'`",
9942 tid);
9943 if (system(buf) != 0) {
9944 sigma_dut_print(dut, DUT_MSG_ERROR,
9945 "Ping did not send out");
9946 }
9947
9948 snprintf(buf, sizeof(buf),
9949 "iwconfig %s | grep Access | awk '{print $6}' > %s",
9950 intf, VI_QOS_TMP_FILE);
9951 if (system(buf) != 0)
9952 return;
9953
9954 snprintf(buf, sizeof(buf),
9955 "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s",
9956 intf, VI_QOS_TMP_FILE);
9957 if (system(buf) != 0)
9958 sigma_dut_print(dut, DUT_MSG_ERROR, "HWaddr matching failed");
9959
9960 snprintf(buf,sizeof(buf), "sed -n '3,$p' %s >> %s",
9961 VI_QOS_REFFILE, VI_QOS_TMP_FILE);
9962 if (system(buf) != 0) {
9963 sigma_dut_print(dut, DUT_MSG_ERROR,
9964 "VI_QOS_TEMP_FILE generation error failed");
9965 }
9966 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
9967 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
9968 if (system(buf) != 0) {
9969 sigma_dut_print(dut, DUT_MSG_ERROR,
9970 "VI_QOS_FILE generation failed");
9971 }
9972
9973 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
9974 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
9975 if (system(buf) != 0) {
9976 sigma_dut_print(dut, DUT_MSG_ERROR,
9977 "VI_QOS_FILE generation failed");
9978 }
9979
9980 snprintf(buf, sizeof(buf), "ethinject %s %s", intf, VI_QOS_FILE);
9981 if (system(buf) != 0) {
9982 }
9983}
9984
9985
9986static int ath_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
9987 struct sigma_cmd *cmd)
9988{
9989 const char *intf = get_param(cmd, "Interface");
9990 const char *val;
9991 int tid = 0;
9992 char buf[100];
9993
9994 val = get_param(cmd, "TID");
9995 if (val) {
9996 tid = atoi(val);
9997 if (tid)
9998 ath_sta_inject_frame(dut, intf, tid);
9999 }
10000
10001 /* Command sequence for ADDBA request on Peregrine based devices */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010002 run_iwpriv(dut, intf, "setaddbaoper 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010003
10004 snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4", intf, tid);
10005 if (system(buf) != 0) {
10006 sigma_dut_print(dut, DUT_MSG_ERROR,
10007 "wifitool senddelba failed");
10008 }
10009
10010 snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64", intf, tid);
10011 if (system(buf) != 0) {
10012 sigma_dut_print(dut, DUT_MSG_ERROR,
10013 "wifitool sendaddba failed");
10014 }
10015
10016 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
10017
10018 return 1;
10019}
10020
10021
Lior David9981b512017-01-20 13:16:40 +020010022#ifdef __linux__
10023
10024static int wil6210_send_addba(struct sigma_dut *dut, const char *dest_mac,
10025 int agg_size)
10026{
10027 char dir[128], buf[128];
10028 FILE *f;
10029 regex_t re;
10030 regmatch_t m[2];
Jouni Malinen3aa72862019-05-29 23:14:51 +030010031 int rc, ret = -1, vring_id, found, res;
Lior David9981b512017-01-20 13:16:40 +020010032
10033 if (wil6210_get_debugfs_dir(dut, dir, sizeof(dir))) {
10034 sigma_dut_print(dut, DUT_MSG_ERROR,
10035 "failed to get wil6210 debugfs dir");
10036 return -1;
10037 }
10038
Jouni Malinen3aa72862019-05-29 23:14:51 +030010039 res = snprintf(buf, sizeof(buf), "%s/vrings", dir);
10040 if (res < 0 || res >= sizeof(buf))
10041 return -1;
Lior David9981b512017-01-20 13:16:40 +020010042 f = fopen(buf, "r");
10043 if (!f) {
10044 sigma_dut_print(dut, DUT_MSG_ERROR, "failed to open: %s", buf);
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +020010045 /* newer wil6210 driver renamed file to "rings" */
Jouni Malinen3aa72862019-05-29 23:14:51 +030010046 res = snprintf(buf, sizeof(buf), "%s/rings", dir);
10047 if (res < 0 || res >= sizeof(buf))
10048 return -1;
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +020010049 f = fopen(buf, "r");
10050 if (!f) {
10051 sigma_dut_print(dut, DUT_MSG_ERROR,
10052 "failed to open: %s", buf);
10053 return -1;
10054 }
Lior David9981b512017-01-20 13:16:40 +020010055 }
10056
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +020010057 /* can be either VRING tx... or RING... */
10058 if (regcomp(&re, "RING tx_[ \t]*([0-9]+)", REG_EXTENDED)) {
Lior David9981b512017-01-20 13:16:40 +020010059 sigma_dut_print(dut, DUT_MSG_ERROR, "regcomp failed");
10060 goto out;
10061 }
10062
10063 /* find TX VRING for the mac address */
10064 found = 0;
10065 while (fgets(buf, sizeof(buf), f)) {
10066 if (strcasestr(buf, dest_mac)) {
10067 found = 1;
10068 break;
10069 }
10070 }
10071
10072 if (!found) {
10073 sigma_dut_print(dut, DUT_MSG_ERROR,
10074 "no TX VRING for %s", dest_mac);
10075 goto out;
10076 }
10077
10078 /* extract VRING ID, "VRING tx_<id> = {" */
10079 if (!fgets(buf, sizeof(buf), f)) {
10080 sigma_dut_print(dut, DUT_MSG_ERROR,
10081 "no VRING start line for %s", dest_mac);
10082 goto out;
10083 }
10084
10085 rc = regexec(&re, buf, 2, m, 0);
10086 regfree(&re);
10087 if (rc || m[1].rm_so < 0) {
10088 sigma_dut_print(dut, DUT_MSG_ERROR,
10089 "no VRING TX ID for %s", dest_mac);
10090 goto out;
10091 }
10092 buf[m[1].rm_eo] = 0;
10093 vring_id = atoi(&buf[m[1].rm_so]);
10094
10095 /* send the addba command */
10096 fclose(f);
Jouni Malinen3aa72862019-05-29 23:14:51 +030010097 res = snprintf(buf, sizeof(buf), "%s/back", dir);
10098 if (res < 0 || res >= sizeof(buf))
10099 return -1;
Lior David9981b512017-01-20 13:16:40 +020010100 f = fopen(buf, "w");
10101 if (!f) {
10102 sigma_dut_print(dut, DUT_MSG_ERROR,
10103 "failed to open: %s", buf);
10104 return -1;
10105 }
10106
10107 fprintf(f, "add %d %d\n", vring_id, agg_size);
10108
10109 ret = 0;
10110
10111out:
10112 fclose(f);
10113
10114 return ret;
10115}
10116
10117
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +020010118int send_addba_60g(struct sigma_dut *dut, struct sigma_conn *conn,
10119 struct sigma_cmd *cmd, const char *mac_param)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010120{
10121 const char *val;
10122 int tid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010123
10124 val = get_param(cmd, "TID");
10125 if (val) {
10126 tid = atoi(val);
10127 if (tid != 0) {
10128 sigma_dut_print(dut, DUT_MSG_ERROR,
10129 "Ignore TID %d for send_addba use TID 0 for 60g since only 0 required on TX",
10130 tid);
10131 }
10132 }
10133
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +020010134 val = get_param(cmd, mac_param);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010135 if (!val) {
10136 sigma_dut_print(dut, DUT_MSG_ERROR,
10137 "Currently not supporting addba for 60G without Dest_mac");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020010138 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010139 }
10140
Lior David9981b512017-01-20 13:16:40 +020010141 if (wil6210_send_addba(dut, val, dut->back_rcv_buf))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010142 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010143
10144 return 1;
10145}
10146
Lior David9981b512017-01-20 13:16:40 +020010147#endif /* __linux__ */
10148
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010149
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080010150static int wcn_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
10151 struct sigma_cmd *cmd)
10152{
10153#ifdef NL80211_SUPPORT
10154 const char *intf = get_param(cmd, "Interface");
10155 const char *val;
10156 int tid = -1;
10157 int bufsize = 64;
10158 struct nl_msg *msg;
10159 int ret = 0;
10160 struct nlattr *params;
10161 int ifindex;
10162
10163 val = get_param(cmd, "TID");
10164 if (val)
10165 tid = atoi(val);
10166
10167 if (tid == -1) {
10168 send_resp(dut, conn, SIGMA_ERROR,
10169 "ErrorCode,sta_send_addba tid invalid");
10170 return 0;
10171 }
10172
10173 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
10174
10175 ifindex = if_nametoindex(intf);
10176 if (ifindex == 0) {
10177 sigma_dut_print(dut, DUT_MSG_ERROR,
10178 "%s: Index for interface %s failed",
10179 __func__, intf);
10180 send_resp(dut, conn, SIGMA_ERROR,
10181 "ErrorCode,sta_send_addba interface invalid");
10182 return 0;
10183 }
10184
10185 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
10186 NL80211_CMD_VENDOR)) ||
10187 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
10188 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
10189 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
10190 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
10191 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
10192 nla_put_u8(msg,
10193 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADD_DEL_BA_SESSION,
10194 QCA_WLAN_ADD_BA) ||
10195 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BA_TID,
10196 tid) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -070010197 nla_put_u16(msg,
10198 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
10199 bufsize)) {
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080010200 sigma_dut_print(dut, DUT_MSG_ERROR,
10201 "%s: err in adding vendor_cmd and vendor_data",
10202 __func__);
10203 nlmsg_free(msg);
10204 send_resp(dut, conn, SIGMA_ERROR,
10205 "ErrorCode,sta_send_addba err in adding vendor_cmd and vendor_data");
10206 return 0;
10207 }
10208 nla_nest_end(msg, params);
10209
10210 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
10211 if (ret) {
10212 sigma_dut_print(dut, DUT_MSG_ERROR,
10213 "%s: err in send_and_recv_msgs, ret=%d",
10214 __func__, ret);
Sunil Dutt30605592018-05-04 20:35:50 +053010215 if (ret == -EOPNOTSUPP)
10216 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080010217 send_resp(dut, conn, SIGMA_ERROR,
10218 "ErrorCode,sta_send_addba err in send_and_recv_msgs");
10219 return 0;
10220 }
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080010221#else /* NL80211_SUPPORT */
10222 sigma_dut_print(dut, DUT_MSG_ERROR,
10223 "sta_send_addba not supported without NL80211_SUPPORT defined");
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080010224#endif /* NL80211_SUPPORT */
Sunil Dutt30605592018-05-04 20:35:50 +053010225
10226 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080010227}
10228
10229
Jouni Malinenf7222712019-06-13 01:50:21 +030010230static enum sigma_cmd_result cmd_sta_send_addba(struct sigma_dut *dut,
10231 struct sigma_conn *conn,
10232 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010233{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010234 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010235 case DRIVER_ATHEROS:
10236 return ath_sta_send_addba(dut, conn, cmd);
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080010237 case DRIVER_WCN:
10238 return wcn_sta_send_addba(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +020010239#ifdef __linux__
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010240 case DRIVER_WIL6210:
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +020010241 return send_addba_60g(dut, conn, cmd, "Dest_mac");
Lior David9981b512017-01-20 13:16:40 +020010242#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010243 default:
10244 /*
10245 * There is no driver specific implementation for other drivers.
10246 * Ignore the command and report COMPLETE since the following
10247 * throughput test operation will end up sending ADDBA anyway.
10248 */
10249 return 1;
10250 }
10251}
10252
10253
10254int inject_eth_frame(int s, const void *data, size_t len,
10255 unsigned short ethtype, char *dst, char *src)
10256{
10257 struct iovec iov[4] = {
10258 {
10259 .iov_base = dst,
10260 .iov_len = ETH_ALEN,
10261 },
10262 {
10263 .iov_base = src,
10264 .iov_len = ETH_ALEN,
10265 },
10266 {
10267 .iov_base = &ethtype,
10268 .iov_len = sizeof(unsigned short),
10269 },
10270 {
10271 .iov_base = (void *) data,
10272 .iov_len = len,
10273 }
10274 };
10275 struct msghdr msg = {
10276 .msg_name = NULL,
10277 .msg_namelen = 0,
10278 .msg_iov = iov,
10279 .msg_iovlen = 4,
10280 .msg_control = NULL,
10281 .msg_controllen = 0,
10282 .msg_flags = 0,
10283 };
10284
10285 return sendmsg(s, &msg, 0);
10286}
10287
10288#if defined(__linux__) || defined(__QNXNTO__)
10289
10290int inject_frame(int s, const void *data, size_t len, int encrypt)
10291{
10292#define IEEE80211_RADIOTAP_F_WEP 0x04
10293#define IEEE80211_RADIOTAP_F_FRAG 0x08
10294 unsigned char rtap_hdr[] = {
10295 0x00, 0x00, /* radiotap version */
10296 0x0e, 0x00, /* radiotap length */
10297 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
10298 IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */
10299 0x00, /* padding */
10300 0x00, 0x00, /* RX and TX flags to indicate that */
10301 0x00, 0x00, /* this is the injected frame directly */
10302 };
10303 struct iovec iov[2] = {
10304 {
10305 .iov_base = &rtap_hdr,
10306 .iov_len = sizeof(rtap_hdr),
10307 },
10308 {
10309 .iov_base = (void *) data,
10310 .iov_len = len,
10311 }
10312 };
10313 struct msghdr msg = {
10314 .msg_name = NULL,
10315 .msg_namelen = 0,
10316 .msg_iov = iov,
10317 .msg_iovlen = 2,
10318 .msg_control = NULL,
10319 .msg_controllen = 0,
10320 .msg_flags = 0,
10321 };
10322
10323 if (encrypt)
10324 rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP;
10325
10326 return sendmsg(s, &msg, 0);
10327}
10328
10329
10330int open_monitor(const char *ifname)
10331{
10332#ifdef __QNXNTO__
10333 struct sockaddr_dl ll;
10334 int s;
10335
10336 memset(&ll, 0, sizeof(ll));
10337 ll.sdl_family = AF_LINK;
10338 ll.sdl_index = if_nametoindex(ifname);
10339 if (ll.sdl_index == 0) {
10340 perror("if_nametoindex");
10341 return -1;
10342 }
10343 s = socket(PF_INET, SOCK_RAW, 0);
10344#else /* __QNXNTO__ */
10345 struct sockaddr_ll ll;
10346 int s;
10347
10348 memset(&ll, 0, sizeof(ll));
10349 ll.sll_family = AF_PACKET;
10350 ll.sll_ifindex = if_nametoindex(ifname);
10351 if (ll.sll_ifindex == 0) {
10352 perror("if_nametoindex");
10353 return -1;
10354 }
10355 s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
10356#endif /* __QNXNTO__ */
10357 if (s < 0) {
10358 perror("socket[PF_PACKET,SOCK_RAW]");
10359 return -1;
10360 }
10361
10362 if (bind(s, (struct sockaddr *) &ll, sizeof(ll)) < 0) {
10363 perror("monitor socket bind");
10364 close(s);
10365 return -1;
10366 }
10367
10368 return s;
10369}
10370
10371
10372static int hex2num(char c)
10373{
10374 if (c >= '0' && c <= '9')
10375 return c - '0';
10376 if (c >= 'a' && c <= 'f')
10377 return c - 'a' + 10;
10378 if (c >= 'A' && c <= 'F')
10379 return c - 'A' + 10;
10380 return -1;
10381}
10382
10383
10384int hwaddr_aton(const char *txt, unsigned char *addr)
10385{
10386 int i;
10387
10388 for (i = 0; i < 6; i++) {
10389 int a, b;
10390
10391 a = hex2num(*txt++);
10392 if (a < 0)
10393 return -1;
10394 b = hex2num(*txt++);
10395 if (b < 0)
10396 return -1;
10397 *addr++ = (a << 4) | b;
10398 if (i < 5 && *txt++ != ':')
10399 return -1;
10400 }
10401
10402 return 0;
10403}
10404
10405#endif /* defined(__linux__) || defined(__QNXNTO__) */
10406
Veerendranath Jakkam49774122020-07-05 09:52:18 +053010407
10408#ifdef NL80211_SUPPORT
10409static int nl80211_send_frame_cmd(struct sigma_dut *dut, const char *intf,
10410 const u8 *data, size_t data_len, int freq)
10411{
10412 struct nl_msg *msg;
10413 int ret = 0;
10414 int ifindex;
10415
10416 ifindex = if_nametoindex(intf);
10417 if (ifindex == 0) {
10418 sigma_dut_print(dut, DUT_MSG_ERROR,
10419 "%s: Index for interface %s failed",
10420 __func__, intf);
10421 return -1;
10422 }
10423
10424 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
10425 NL80211_CMD_FRAME)) ||
10426 (freq && nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
10427 nla_put(msg, NL80211_ATTR_FRAME, data_len, data)) {
10428 sigma_dut_print(dut, DUT_MSG_ERROR,
10429 "%s: Error in adding NL80211_CMD_FRAME",
10430 __func__);
10431 nlmsg_free(msg);
10432 return -1;
10433 }
10434
10435 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
10436 if (ret) {
10437 sigma_dut_print(dut, DUT_MSG_ERROR,
10438 "nl80211: Frame command failed: ret=%d (%s) req=%u",
10439 ret, strerror(-ret), freq);
10440 return -1;
10441 }
10442
10443 return 0;
10444}
10445#endif /* NL80211_SUPPORT */
10446
10447
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010448enum send_frame_type {
10449 DISASSOC, DEAUTH, SAQUERY, AUTH, ASSOCREQ, REASSOCREQ, DLS_REQ
10450};
10451enum send_frame_protection {
10452 CORRECT_KEY, INCORRECT_KEY, UNPROTECTED
10453};
10454
10455
10456static int sta_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn,
Veerendranath Jakkam49774122020-07-05 09:52:18 +053010457 const char *intf, enum send_frame_type frame,
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010458 enum send_frame_protection protected,
Veerendranath Jakkam49774122020-07-05 09:52:18 +053010459 const char *dest, int use_monitor)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010460{
10461#ifdef __linux__
10462 unsigned char buf[1000], *pos;
10463 int s, res;
10464 char bssid[20], addr[20];
10465 char result[32], ssid[100];
10466 size_t ssid_len;
10467
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010468 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010469 sizeof(result)) < 0 ||
10470 strncmp(result, "COMPLETED", 9) != 0) {
10471 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Not connected");
10472 return 0;
10473 }
10474
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010475 if (get_wpa_status(get_station_ifname(dut), "bssid",
10476 bssid, sizeof(bssid)) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010477 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
10478 "current BSSID");
10479 return 0;
10480 }
10481
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010482 if (get_wpa_status(get_station_ifname(dut), "address",
10483 addr, sizeof(addr)) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010484 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
10485 "own MAC address");
10486 return 0;
10487 }
10488
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010489 if (get_wpa_status(get_station_ifname(dut), "ssid", ssid, sizeof(ssid))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010490 < 0) {
10491 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
10492 "current SSID");
10493 return 0;
10494 }
10495 ssid_len = strlen(ssid);
10496
10497 pos = buf;
10498
10499 /* Frame Control */
10500 switch (frame) {
10501 case DISASSOC:
10502 *pos++ = 0xa0;
10503 break;
10504 case DEAUTH:
10505 *pos++ = 0xc0;
10506 break;
10507 case SAQUERY:
10508 *pos++ = 0xd0;
10509 break;
10510 case AUTH:
10511 *pos++ = 0xb0;
10512 break;
10513 case ASSOCREQ:
10514 *pos++ = 0x00;
10515 break;
10516 case REASSOCREQ:
10517 *pos++ = 0x20;
10518 break;
10519 case DLS_REQ:
10520 *pos++ = 0xd0;
10521 break;
10522 }
10523
10524 if (protected == INCORRECT_KEY)
10525 *pos++ = 0x40; /* Set Protected field to 1 */
10526 else
10527 *pos++ = 0x00;
10528
10529 /* Duration */
10530 *pos++ = 0x00;
10531 *pos++ = 0x00;
10532
10533 /* addr1 = DA (current AP) */
10534 hwaddr_aton(bssid, pos);
10535 pos += 6;
10536 /* addr2 = SA (own address) */
10537 hwaddr_aton(addr, pos);
10538 pos += 6;
10539 /* addr3 = BSSID (current AP) */
10540 hwaddr_aton(bssid, pos);
10541 pos += 6;
10542
10543 /* Seq# (to be filled by driver/mac80211) */
10544 *pos++ = 0x00;
10545 *pos++ = 0x00;
10546
10547 if (protected == INCORRECT_KEY) {
10548 /* CCMP parameters */
10549 memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8);
10550 pos += 8;
10551 }
10552
10553 if (protected == INCORRECT_KEY) {
10554 switch (frame) {
10555 case DEAUTH:
10556 /* Reason code (encrypted) */
10557 memcpy(pos, "\xa7\x39", 2);
10558 pos += 2;
10559 break;
10560 case DISASSOC:
10561 /* Reason code (encrypted) */
10562 memcpy(pos, "\xa7\x39", 2);
10563 pos += 2;
10564 break;
10565 case SAQUERY:
10566 /* Category|Action|TransID (encrypted) */
10567 memcpy(pos, "\x6f\xbd\xe9\x4d", 4);
10568 pos += 4;
10569 break;
10570 default:
10571 return -1;
10572 }
10573
10574 /* CCMP MIC */
10575 memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8);
10576 pos += 8;
10577 } else {
10578 switch (frame) {
10579 case DEAUTH:
10580 /* reason code = 8 */
10581 *pos++ = 0x08;
10582 *pos++ = 0x00;
10583 break;
10584 case DISASSOC:
10585 /* reason code = 8 */
10586 *pos++ = 0x08;
10587 *pos++ = 0x00;
10588 break;
10589 case SAQUERY:
10590 /* Category - SA Query */
10591 *pos++ = 0x08;
10592 /* SA query Action - Request */
10593 *pos++ = 0x00;
10594 /* Transaction ID */
10595 *pos++ = 0x12;
10596 *pos++ = 0x34;
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053010597 if (dut->saquery_oci_freq) {
10598 /* OCI IE - Extended ID */
10599 *pos++ = 0xFF;
10600 *pos++ = 0x04;
10601 *pos++ = 0x36;
10602 /* Operating Class */
10603 *pos++ = 0x74;
10604 /* Primary Channel */
10605 *pos++ = freq_to_channel(dut->saquery_oci_freq);
10606 /* Frequency Segment 1 Channel Number */
10607 *pos++ = 0x00;
10608 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010609 break;
10610 case AUTH:
10611 /* Auth Alg (Open) */
10612 *pos++ = 0x00;
10613 *pos++ = 0x00;
10614 /* Seq# */
10615 *pos++ = 0x01;
10616 *pos++ = 0x00;
10617 /* Status code */
10618 *pos++ = 0x00;
10619 *pos++ = 0x00;
10620 break;
10621 case ASSOCREQ:
10622 /* Capability Information */
10623 *pos++ = 0x31;
10624 *pos++ = 0x04;
10625 /* Listen Interval */
10626 *pos++ = 0x0a;
10627 *pos++ = 0x00;
10628 /* SSID */
10629 *pos++ = 0x00;
10630 *pos++ = ssid_len;
10631 memcpy(pos, ssid, ssid_len);
10632 pos += ssid_len;
10633 /* Supported Rates */
10634 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
10635 10);
10636 pos += 10;
10637 /* Extended Supported Rates */
10638 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
10639 pos += 6;
10640 /* RSN */
10641 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
10642 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
10643 "\x00\x00\x00\x00\x0f\xac\x06", 28);
10644 pos += 28;
10645 break;
10646 case REASSOCREQ:
10647 /* Capability Information */
10648 *pos++ = 0x31;
10649 *pos++ = 0x04;
10650 /* Listen Interval */
10651 *pos++ = 0x0a;
10652 *pos++ = 0x00;
10653 /* Current AP */
10654 hwaddr_aton(bssid, pos);
10655 pos += 6;
10656 /* SSID */
10657 *pos++ = 0x00;
10658 *pos++ = ssid_len;
10659 memcpy(pos, ssid, ssid_len);
10660 pos += ssid_len;
10661 /* Supported Rates */
10662 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
10663 10);
10664 pos += 10;
10665 /* Extended Supported Rates */
10666 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
10667 pos += 6;
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053010668 /* RSNE - Group and Pairwise ciphers */
10669 memcpy(pos,
10670 "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x04",
10671 14);
10672 pos += 14;
10673 /* RSNE - AKM Suite count */
10674 *pos++ = 0x01;
10675 *pos++ = 0x00;
10676 /* RSNE - AKM Suites */
10677 if (dut->program == PROGRAM_WPA3)
10678 memcpy(pos, "\x00\x0f\xac\x08", 4);
10679 else
10680 memcpy(pos, "\x00\x0f\xac\x02", 4);
10681 pos += 4;
10682 /* RSNE - Capabilities */
10683 *pos++ = 0xc0;
10684 if (dut->ocvc)
10685 *pos++ = 0x40;
10686 else
10687 *pos++ = 0x00;
10688 /* RSNE - PMKID list and Group Management Ciphers */
10689 memcpy(pos, "\x00\x00\x00\x0f\xac\x06", 6);
10690 pos += 6;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010691 break;
10692 case DLS_REQ:
10693 /* Category - DLS */
10694 *pos++ = 0x02;
10695 /* DLS Action - Request */
10696 *pos++ = 0x00;
10697 /* Destination MACAddress */
10698 if (dest)
10699 hwaddr_aton(dest, pos);
10700 else
10701 memset(pos, 0, 6);
10702 pos += 6;
10703 /* Source MACAddress */
10704 hwaddr_aton(addr, pos);
10705 pos += 6;
10706 /* Capability Information */
10707 *pos++ = 0x10; /* Privacy */
10708 *pos++ = 0x06; /* QoS */
10709 /* DLS Timeout Value */
10710 *pos++ = 0x00;
10711 *pos++ = 0x01;
10712 /* Supported rates */
10713 *pos++ = 0x01;
10714 *pos++ = 0x08;
10715 *pos++ = 0x0c; /* 6 Mbps */
10716 *pos++ = 0x12; /* 9 Mbps */
10717 *pos++ = 0x18; /* 12 Mbps */
10718 *pos++ = 0x24; /* 18 Mbps */
10719 *pos++ = 0x30; /* 24 Mbps */
10720 *pos++ = 0x48; /* 36 Mbps */
10721 *pos++ = 0x60; /* 48 Mbps */
10722 *pos++ = 0x6c; /* 54 Mbps */
10723 /* TODO: Extended Supported Rates */
10724 /* TODO: HT Capabilities */
10725 break;
10726 }
10727 }
10728
Veerendranath Jakkam49774122020-07-05 09:52:18 +053010729 if (use_monitor) {
10730 s = open_monitor("sigmadut");
10731 if (s < 0) {
10732 send_resp(dut, conn, SIGMA_ERROR,
10733 "errorCode,Failed to open monitor socket");
10734 return 0;
10735 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010736
Veerendranath Jakkam49774122020-07-05 09:52:18 +053010737 res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY);
10738 if (res < 0) {
10739 send_resp(dut, conn, SIGMA_ERROR,
10740 "errorCode,Failed to inject frame");
10741 close(s);
10742 return 0;
10743 }
10744 if (res < pos - buf) {
10745 send_resp(dut, conn, SIGMA_ERROR,
10746 "errorCode,Only partial frame sent");
10747 close(s);
10748 return 0;
10749 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010750
Veerendranath Jakkam49774122020-07-05 09:52:18 +053010751 close(s);
10752 } else {
10753#ifdef NL80211_SUPPORT
10754 int freq;
10755 char freq_str[10];
10756
10757 if (get_wpa_status(get_station_ifname(dut), "freq",
10758 freq_str, sizeof(freq_str)) < 0) {
10759 send_resp(dut, conn, SIGMA_ERROR,
10760 "errorCode,Could not get current operating frequency");
10761 return 0;
10762 }
10763 freq = atoi(freq_str);
10764
10765 if (nl80211_send_frame_cmd(dut, intf, buf, pos - buf, freq)) {
10766 send_resp(dut, conn, SIGMA_ERROR,
10767 "errorCode,Failed to inject frame");
10768 return 0;
10769 }
10770#else /* NL80211_SUPPORT */
10771 send_resp(dut, conn, SIGMA_ERROR,
10772 "errorCode,Failed to inject frame (no NL80211_SUPPORT)");
10773 return 0;
10774#endif /* NL80211_SUPPORT */
10775 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010776
10777 return 1;
10778#else /* __linux__ */
10779 send_resp(dut, conn, SIGMA_ERROR, "errorCode,sta_send_frame not "
10780 "yet supported");
10781 return 0;
10782#endif /* __linux__ */
10783}
10784
10785
10786static int cmd_sta_send_frame_tdls(struct sigma_dut *dut,
10787 struct sigma_conn *conn,
10788 struct sigma_cmd *cmd)
10789{
10790 const char *intf = get_param(cmd, "Interface");
10791 const char *sta, *val;
10792 unsigned char addr[ETH_ALEN];
10793 char buf[100];
10794
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030010795 if (!intf)
10796 return -1;
10797
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010798 sta = get_param(cmd, "peer");
10799 if (sta == NULL)
10800 sta = get_param(cmd, "station");
10801 if (sta == NULL) {
10802 send_resp(dut, conn, SIGMA_ERROR,
10803 "ErrorCode,Missing peer address");
10804 return 0;
10805 }
10806 if (hwaddr_aton(sta, addr) < 0) {
10807 send_resp(dut, conn, SIGMA_ERROR,
10808 "ErrorCode,Invalid peer address");
10809 return 0;
10810 }
10811
10812 val = get_param(cmd, "type");
10813 if (val == NULL)
10814 return -1;
10815
10816 if (strcasecmp(val, "DISCOVERY") == 0) {
10817 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", sta);
10818 if (wpa_command(intf, buf) < 0) {
10819 send_resp(dut, conn, SIGMA_ERROR,
10820 "ErrorCode,Failed to send TDLS discovery");
10821 return 0;
10822 }
10823 return 1;
10824 }
10825
10826 if (strcasecmp(val, "SETUP") == 0) {
10827 int status = 0, timeout = 0;
10828
10829 val = get_param(cmd, "Status");
10830 if (val)
10831 status = atoi(val);
10832
10833 val = get_param(cmd, "Timeout");
10834 if (val)
10835 timeout = atoi(val);
10836
10837 if (status != 0 && status != 37) {
10838 send_resp(dut, conn, SIGMA_ERROR,
10839 "ErrorCode,Unsupported status value");
10840 return 0;
10841 }
10842
10843 if (timeout != 0 && timeout != 301) {
10844 send_resp(dut, conn, SIGMA_ERROR,
10845 "ErrorCode,Unsupported timeout value");
10846 return 0;
10847 }
10848
10849 if (status && timeout) {
10850 send_resp(dut, conn, SIGMA_ERROR,
10851 "ErrorCode,Unsupported timeout+status "
10852 "combination");
10853 return 0;
10854 }
10855
10856 if (status == 37 &&
10857 wpa_command(intf, "SET tdls_testing 0x200")) {
10858 send_resp(dut, conn, SIGMA_ERROR,
10859 "ErrorCode,Failed to enable "
10860 "decline setup response test mode");
10861 return 0;
10862 }
10863
10864 if (timeout == 301) {
10865 int res;
10866 if (dut->no_tpk_expiration)
10867 res = wpa_command(intf,
10868 "SET tdls_testing 0x108");
10869 else
10870 res = wpa_command(intf,
10871 "SET tdls_testing 0x8");
10872 if (res) {
10873 send_resp(dut, conn, SIGMA_ERROR,
10874 "ErrorCode,Failed to set short TPK "
10875 "lifetime");
10876 return 0;
10877 }
10878 }
10879
10880 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", sta);
10881 if (wpa_command(intf, buf) < 0) {
10882 send_resp(dut, conn, SIGMA_ERROR,
10883 "ErrorCode,Failed to send TDLS setup");
10884 return 0;
10885 }
10886 return 1;
10887 }
10888
10889 if (strcasecmp(val, "TEARDOWN") == 0) {
10890 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", sta);
10891 if (wpa_command(intf, buf) < 0) {
10892 send_resp(dut, conn, SIGMA_ERROR,
10893 "ErrorCode,Failed to send TDLS teardown");
10894 return 0;
10895 }
10896 return 1;
10897 }
10898
10899 send_resp(dut, conn, SIGMA_ERROR,
10900 "ErrorCode,Unsupported TDLS frame");
10901 return 0;
10902}
10903
10904
10905static int sta_ap_known(const char *ifname, const char *bssid)
10906{
10907 char buf[4096];
10908
Jouni Malinendd32f192018-09-15 02:55:19 +030010909 snprintf(buf, sizeof(buf), "BSS MASK=1 %s", bssid);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010910 if (wpa_command_resp(ifname, buf, buf, sizeof(buf)) < 0)
10911 return 0;
10912 if (strncmp(buf, "id=", 3) != 0)
10913 return 0;
10914 return 1;
10915}
10916
10917
10918static int sta_scan_ap(struct sigma_dut *dut, const char *ifname,
10919 const char *bssid)
10920{
10921 int res;
10922 struct wpa_ctrl *ctrl;
10923 char buf[256];
10924
10925 if (sta_ap_known(ifname, bssid))
10926 return 0;
10927 sigma_dut_print(dut, DUT_MSG_DEBUG,
10928 "AP not in BSS table - start scan");
10929
10930 ctrl = open_wpa_mon(ifname);
10931 if (ctrl == NULL) {
10932 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
10933 "wpa_supplicant monitor connection");
10934 return -1;
10935 }
10936
10937 if (wpa_command(ifname, "SCAN") < 0) {
10938 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to start scan");
10939 wpa_ctrl_detach(ctrl);
10940 wpa_ctrl_close(ctrl);
10941 return -1;
10942 }
10943
10944 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
10945 buf, sizeof(buf));
10946
10947 wpa_ctrl_detach(ctrl);
10948 wpa_ctrl_close(ctrl);
10949
10950 if (res < 0) {
10951 sigma_dut_print(dut, DUT_MSG_INFO, "Scan did not complete");
10952 return -1;
10953 }
10954
10955 if (sta_ap_known(ifname, bssid))
10956 return 0;
10957 sigma_dut_print(dut, DUT_MSG_INFO, "AP not in BSS table");
10958 return -1;
10959}
10960
10961
10962static int cmd_sta_send_frame_hs2_neighadv(struct sigma_dut *dut,
10963 struct sigma_conn *conn,
10964 struct sigma_cmd *cmd,
10965 const char *intf)
10966{
10967 char buf[200];
10968
10969 snprintf(buf, sizeof(buf), "ndsend 2001:DB8::1 %s", intf);
10970 if (system(buf) != 0) {
10971 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Failed to run "
10972 "ndsend");
10973 return 0;
10974 }
10975
10976 return 1;
10977}
10978
10979
10980static int cmd_sta_send_frame_hs2_neighsolreq(struct sigma_dut *dut,
10981 struct sigma_conn *conn,
10982 struct sigma_cmd *cmd,
10983 const char *intf)
10984{
10985 char buf[200];
10986 const char *ip = get_param(cmd, "SenderIP");
10987
Peng Xu26b356d2017-10-04 17:58:16 -070010988 if (!ip)
10989 return 0;
10990
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010991 snprintf(buf, sizeof(buf), "ndisc6 -nm %s %s -r 4", ip, intf);
10992 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10993 if (system(buf) == 0) {
10994 sigma_dut_print(dut, DUT_MSG_INFO,
10995 "Neighbor Solicitation got a response "
10996 "for %s@%s", ip, intf);
10997 }
10998
10999 return 1;
11000}
11001
11002
11003static int cmd_sta_send_frame_hs2_arpprobe(struct sigma_dut *dut,
11004 struct sigma_conn *conn,
11005 struct sigma_cmd *cmd,
11006 const char *ifname)
11007{
11008 char buf[200];
11009 const char *ip = get_param(cmd, "SenderIP");
11010
11011 if (ip == NULL) {
11012 send_resp(dut, conn, SIGMA_ERROR,
11013 "ErrorCode,Missing SenderIP parameter");
11014 return 0;
11015 }
11016 snprintf(buf, sizeof(buf), "arping -I %s -D %s -c 4", ifname, ip);
11017 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11018 if (system(buf) != 0) {
11019 sigma_dut_print(dut, DUT_MSG_INFO, "arping DAD got a response "
11020 "for %s@%s", ip, ifname);
11021 }
11022
11023 return 1;
11024}
11025
11026
11027static int cmd_sta_send_frame_hs2_arpannounce(struct sigma_dut *dut,
11028 struct sigma_conn *conn,
11029 struct sigma_cmd *cmd,
11030 const char *ifname)
11031{
11032 char buf[200];
11033 char ip[16];
11034 int s;
Peng Xub3756882017-10-04 14:39:09 -070011035 struct ifreq ifr;
11036 struct sockaddr_in saddr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011037
11038 s = socket(PF_INET, SOCK_DGRAM, 0);
Peng Xub3756882017-10-04 14:39:09 -070011039 if (s < 0) {
11040 perror("socket");
11041 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011042 }
11043
Peng Xub3756882017-10-04 14:39:09 -070011044 memset(&ifr, 0, sizeof(ifr));
11045 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
11046 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
11047 sigma_dut_print(dut, DUT_MSG_INFO,
11048 "Failed to get %s IP address: %s",
11049 ifname, strerror(errno));
11050 close(s);
11051 return -1;
11052 }
11053 close(s);
11054
11055 memcpy(&saddr, &ifr.ifr_addr, sizeof(struct sockaddr_in));
11056 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
11057
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011058 snprintf(buf, sizeof(buf), "arping -I %s -s %s %s -c 4", ifname, ip,
11059 ip);
11060 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11061 if (system(buf) != 0) {
11062 }
11063
11064 return 1;
11065}
11066
11067
11068static int cmd_sta_send_frame_hs2_arpreply(struct sigma_dut *dut,
11069 struct sigma_conn *conn,
11070 struct sigma_cmd *cmd,
11071 const char *ifname)
11072{
11073 char buf[200], addr[20];
11074 char dst[ETH_ALEN], src[ETH_ALEN];
11075 short ethtype = htons(ETH_P_ARP);
11076 char *pos;
11077 int s, res;
11078 const char *val;
11079 struct sockaddr_in taddr;
11080
11081 val = get_param(cmd, "dest");
11082 if (val)
11083 hwaddr_aton(val, (unsigned char *) dst);
11084
11085 val = get_param(cmd, "DestIP");
11086 if (val)
11087 inet_aton(val, &taddr.sin_addr);
Peng Xu151c9e12017-10-04 14:39:09 -070011088 else
11089 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011090
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011091 if (get_wpa_status(get_station_ifname(dut), "address", addr,
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011092 sizeof(addr)) < 0)
11093 return -2;
11094 hwaddr_aton(addr, (unsigned char *) src);
11095
11096 pos = buf;
11097 *pos++ = 0x00;
11098 *pos++ = 0x01;
11099 *pos++ = 0x08;
11100 *pos++ = 0x00;
11101 *pos++ = 0x06;
11102 *pos++ = 0x04;
11103 *pos++ = 0x00;
11104 *pos++ = 0x02;
11105 memcpy(pos, src, ETH_ALEN);
11106 pos += ETH_ALEN;
11107 memcpy(pos, &taddr.sin_addr, 4);
11108 pos += 4;
11109 memcpy(pos, dst, ETH_ALEN);
11110 pos += ETH_ALEN;
11111 memcpy(pos, &taddr.sin_addr, 4);
11112 pos += 4;
11113
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011114 s = open_monitor(get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011115 if (s < 0) {
11116 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
11117 "monitor socket");
11118 return 0;
11119 }
11120
11121 res = inject_eth_frame(s, buf, pos - buf, ethtype, dst, src);
11122 if (res < 0) {
11123 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
11124 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +053011125 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011126 return 0;
11127 }
11128
11129 close(s);
11130
11131 return 1;
11132}
11133
11134
11135static int cmd_sta_send_frame_hs2_dls_req(struct sigma_dut *dut,
11136 struct sigma_conn *conn,
11137 struct sigma_cmd *cmd,
11138 const char *intf, const char *dest)
11139{
11140 char buf[100];
11141
11142 if (if_nametoindex("sigmadut") == 0) {
11143 snprintf(buf, sizeof(buf),
11144 "iw dev %s interface add sigmadut type monitor",
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011145 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011146 if (system(buf) != 0 ||
11147 if_nametoindex("sigmadut") == 0) {
11148 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
11149 "monitor interface with '%s'", buf);
11150 return -2;
11151 }
11152 }
11153
11154 if (system("ifconfig sigmadut up") != 0) {
11155 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
11156 "monitor interface up");
11157 return -2;
11158 }
11159
Veerendranath Jakkam49774122020-07-05 09:52:18 +053011160 return sta_inject_frame(dut, conn, intf, DLS_REQ, UNPROTECTED, dest, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011161}
11162
11163
11164static int cmd_sta_send_frame_hs2(struct sigma_dut *dut,
11165 struct sigma_conn *conn,
11166 struct sigma_cmd *cmd)
11167{
11168 const char *intf = get_param(cmd, "Interface");
11169 const char *dest = get_param(cmd, "Dest");
11170 const char *type = get_param(cmd, "FrameName");
11171 const char *val;
11172 char buf[200], *pos, *end;
11173 int count, count2;
11174
11175 if (type == NULL)
11176 type = get_param(cmd, "Type");
11177
11178 if (intf == NULL || dest == NULL || type == NULL)
11179 return -1;
11180
11181 if (strcasecmp(type, "NeighAdv") == 0)
11182 return cmd_sta_send_frame_hs2_neighadv(dut, conn, cmd, intf);
11183
11184 if (strcasecmp(type, "NeighSolicitReq") == 0)
11185 return cmd_sta_send_frame_hs2_neighsolreq(dut, conn, cmd, intf);
11186
11187 if (strcasecmp(type, "ARPProbe") == 0)
11188 return cmd_sta_send_frame_hs2_arpprobe(dut, conn, cmd, intf);
11189
11190 if (strcasecmp(type, "ARPAnnounce") == 0)
11191 return cmd_sta_send_frame_hs2_arpannounce(dut, conn, cmd, intf);
11192
11193 if (strcasecmp(type, "ARPReply") == 0)
11194 return cmd_sta_send_frame_hs2_arpreply(dut, conn, cmd, intf);
11195
11196 if (strcasecmp(type, "DLS-request") == 0 ||
11197 strcasecmp(type, "DLSrequest") == 0)
11198 return cmd_sta_send_frame_hs2_dls_req(dut, conn, cmd, intf,
11199 dest);
11200
11201 if (strcasecmp(type, "ANQPQuery") != 0 &&
11202 strcasecmp(type, "Query") != 0) {
11203 send_resp(dut, conn, SIGMA_ERROR,
11204 "ErrorCode,Unsupported HS 2.0 send frame type");
11205 return 0;
11206 }
11207
11208 if (sta_scan_ap(dut, intf, dest) < 0) {
11209 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not find "
11210 "the requested AP");
11211 return 0;
11212 }
11213
11214 pos = buf;
11215 end = buf + sizeof(buf);
11216 count = 0;
11217 pos += snprintf(pos, end - pos, "ANQP_GET %s ", dest);
11218
11219 val = get_param(cmd, "ANQP_CAP_LIST");
11220 if (val && atoi(val)) {
11221 pos += snprintf(pos, end - pos, "%s257", count > 0 ? "," : "");
11222 count++;
11223 }
11224
11225 val = get_param(cmd, "VENUE_NAME");
11226 if (val && atoi(val)) {
11227 pos += snprintf(pos, end - pos, "%s258", count > 0 ? "," : "");
11228 count++;
11229 }
11230
11231 val = get_param(cmd, "NETWORK_AUTH_TYPE");
11232 if (val && atoi(val)) {
11233 pos += snprintf(pos, end - pos, "%s260", count > 0 ? "," : "");
11234 count++;
11235 }
11236
11237 val = get_param(cmd, "ROAMING_CONS");
11238 if (val && atoi(val)) {
11239 pos += snprintf(pos, end - pos, "%s261", count > 0 ? "," : "");
11240 count++;
11241 }
11242
11243 val = get_param(cmd, "IP_ADDR_TYPE_AVAILABILITY");
11244 if (val && atoi(val)) {
11245 pos += snprintf(pos, end - pos, "%s262", count > 0 ? "," : "");
11246 count++;
11247 }
11248
11249 val = get_param(cmd, "NAI_REALM_LIST");
11250 if (val && atoi(val)) {
11251 pos += snprintf(pos, end - pos, "%s263", count > 0 ? "," : "");
11252 count++;
11253 }
11254
11255 val = get_param(cmd, "3GPP_INFO");
11256 if (val && atoi(val)) {
11257 pos += snprintf(pos, end - pos, "%s264", count > 0 ? "," : "");
11258 count++;
11259 }
11260
11261 val = get_param(cmd, "DOMAIN_LIST");
11262 if (val && atoi(val)) {
11263 pos += snprintf(pos, end - pos, "%s268", count > 0 ? "," : "");
11264 count++;
11265 }
11266
Jouni Malinen34cf9532018-04-29 19:26:33 +030011267 val = get_param(cmd, "Venue_URL");
11268 if (val && atoi(val)) {
11269 pos += snprintf(pos, end - pos, "%s277", count > 0 ? "," : "");
11270 count++;
11271 }
11272
Jouni Malinend3bca5d2018-04-29 17:25:23 +030011273 val = get_param(cmd, "Advice_Of_Charge");
11274 if (val && atoi(val)) {
11275 pos += snprintf(pos, end - pos, "%s278", count > 0 ? "," : "");
11276 count++;
11277 }
11278
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011279 if (count && wpa_command(intf, buf)) {
11280 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,ANQP_GET failed");
11281 return 0;
11282 }
11283
11284 pos = buf;
11285 end = buf + sizeof(buf);
11286 count2 = 0;
11287 pos += snprintf(pos, end - pos, "HS20_ANQP_GET %s ", dest);
11288
11289 val = get_param(cmd, "HS_CAP_LIST");
11290 if (val && atoi(val)) {
11291 pos += snprintf(pos, end - pos, "%s2", count2 > 0 ? "," : "");
11292 count2++;
11293 }
11294
11295 val = get_param(cmd, "OPER_NAME");
11296 if (val && atoi(val)) {
11297 pos += snprintf(pos, end - pos, "%s3", count2 > 0 ? "," : "");
11298 count2++;
11299 }
11300
11301 val = get_param(cmd, "WAN_METRICS");
11302 if (!val)
11303 val = get_param(cmd, "WAN_MAT");
11304 if (!val)
11305 val = get_param(cmd, "WAN_MET");
11306 if (val && atoi(val)) {
11307 pos += snprintf(pos, end - pos, "%s4", count2 > 0 ? "," : "");
11308 count2++;
11309 }
11310
11311 val = get_param(cmd, "CONNECTION_CAPABILITY");
11312 if (val && atoi(val)) {
11313 pos += snprintf(pos, end - pos, "%s5", count2 > 0 ? "," : "");
11314 count2++;
11315 }
11316
11317 val = get_param(cmd, "OP_CLASS");
11318 if (val && atoi(val)) {
11319 pos += snprintf(pos, end - pos, "%s7", count2 > 0 ? "," : "");
11320 count2++;
11321 }
11322
11323 val = get_param(cmd, "OSU_PROVIDER_LIST");
11324 if (val && atoi(val)) {
11325 pos += snprintf(pos, end - pos, "%s8", count2 > 0 ? "," : "");
11326 count2++;
11327 }
11328
Jouni Malinenf67afec2018-04-29 19:24:58 +030011329 val = get_param(cmd, "OPER_ICON_METADATA");
11330 if (!val)
11331 val = get_param(cmd, "OPERATOR_ICON_METADATA");
11332 if (val && atoi(val)) {
11333 pos += snprintf(pos, end - pos, "%s12", count2 > 0 ? "," : "");
11334 count2++;
11335 }
11336
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011337 if (count && count2) {
11338 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before sending out "
11339 "second query");
11340 sleep(1);
11341 }
11342
11343 if (count2 && wpa_command(intf, buf)) {
11344 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,HS20_ANQP_GET "
11345 "failed");
11346 return 0;
11347 }
11348
11349 val = get_param(cmd, "NAI_HOME_REALM_LIST");
11350 if (val) {
11351 if (count || count2) {
11352 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
11353 "sending out second query");
11354 sleep(1);
11355 }
11356
11357 if (strcmp(val, "1") == 0)
11358 val = "mail.example.com";
11359 snprintf(buf, end - pos,
11360 "HS20_GET_NAI_HOME_REALM_LIST %s realm=%s",
11361 dest, val);
11362 if (wpa_command(intf, buf)) {
11363 send_resp(dut, conn, SIGMA_ERROR,
11364 "ErrorCode,HS20_GET_NAI_HOME_REALM_LIST "
11365 "failed");
11366 return 0;
11367 }
11368 }
11369
11370 val = get_param(cmd, "ICON_REQUEST");
11371 if (val) {
11372 if (count || count2) {
11373 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
11374 "sending out second query");
11375 sleep(1);
11376 }
11377
11378 snprintf(buf, end - pos,
11379 "HS20_ICON_REQUEST %s %s", dest, val);
11380 if (wpa_command(intf, buf)) {
11381 send_resp(dut, conn, SIGMA_ERROR,
11382 "ErrorCode,HS20_ICON_REQUEST failed");
11383 return 0;
11384 }
11385 }
11386
11387 return 1;
11388}
11389
11390
11391static int ath_sta_send_frame_vht(struct sigma_dut *dut,
11392 struct sigma_conn *conn,
11393 struct sigma_cmd *cmd)
11394{
11395 const char *val;
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011396 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011397 int chwidth, nss;
11398
11399 val = get_param(cmd, "framename");
11400 if (!val)
11401 return -1;
11402 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
11403
11404 /* Command sequence to generate Op mode notification */
11405 if (val && strcasecmp(val, "Op_md_notif_frm") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011406 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011407
11408 /* Disable STBC */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011409 run_iwpriv(dut, ifname, "tx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011410
11411 /* Extract Channel width */
11412 val = get_param(cmd, "Channel_width");
11413 if (val) {
11414 switch (atoi(val)) {
11415 case 20:
11416 chwidth = 0;
11417 break;
11418 case 40:
11419 chwidth = 1;
11420 break;
11421 case 80:
11422 chwidth = 2;
11423 break;
11424 case 160:
11425 chwidth = 3;
11426 break;
11427 default:
11428 chwidth = 2;
11429 break;
11430 }
11431
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011432 run_iwpriv(dut, ifname, "chwidth %d", chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011433 }
11434
11435 /* Extract NSS */
11436 val = get_param(cmd, "NSS");
11437 if (val) {
11438 switch (atoi(val)) {
11439 case 1:
11440 nss = 1;
11441 break;
11442 case 2:
11443 nss = 3;
11444 break;
11445 case 3:
11446 nss = 7;
11447 break;
11448 default:
11449 /* We do not support NSS > 3 */
11450 nss = 3;
11451 break;
11452 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011453 run_iwpriv(dut, ifname, "rxchainmask %d", nss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011454 }
11455
11456 /* Opmode notify */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011457 run_iwpriv(dut, ifname, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011458 }
11459
11460 return 1;
11461}
11462
11463
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070011464static int wcn_sta_set_pmf_config(struct sigma_dut *dut, const char *intf,
11465 enum send_frame_protection protected)
11466{
11467#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +053011468 return wcn_wifi_test_config_set_u8(
11469 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_PMF_PROTECTION,
11470 protected);
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070011471#else /* NL80211_SUPPORT */
11472 sigma_dut_print(dut, DUT_MSG_ERROR,
11473 "PMF config cannot be set without NL80211_SUPPORT defined");
11474 return -1;
11475#endif /* NL80211_SUPPORT */
11476}
11477
11478
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011479static int cmd_sta_send_frame_vht(struct sigma_dut *dut,
11480 struct sigma_conn *conn,
11481 struct sigma_cmd *cmd)
11482{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011483 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011484 case DRIVER_ATHEROS:
11485 return ath_sta_send_frame_vht(dut, conn, cmd);
11486 default:
11487 send_resp(dut, conn, SIGMA_ERROR,
11488 "errorCode,Unsupported sta_set_frame(VHT) with the current driver");
11489 return 0;
11490 }
11491}
11492
11493
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070011494static int wcn_sta_send_disassoc(struct sigma_dut *dut, const char *intf)
11495{
11496#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +053011497 return wcn_wifi_test_config_set_flag(
11498 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_DISASSOC_TX);
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070011499#else /* NL80211_SUPPORT */
11500 sigma_dut_print(dut, DUT_MSG_ERROR,
11501 "Disassoc Tx cannot be done without NL80211_SUPPORT defined");
11502 return -1;
11503#endif /* NL80211_SUPPORT */
11504}
11505
11506
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011507static int wcn_sta_send_frame_he(struct sigma_dut *dut, struct sigma_conn *conn,
11508 struct sigma_cmd *cmd)
11509{
11510 const char *val;
11511 const char *intf = get_param(cmd, "Interface");
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070011512 enum send_frame_protection protected;
11513 const char *pmf;
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011514
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030011515 if (!intf)
11516 return -1;
11517
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011518 val = get_param(cmd, "framename");
11519 if (!val)
11520 return -1;
11521 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
11522
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070011523 pmf = get_param(cmd, "PMFProtected");
11524 if (!pmf)
11525 pmf = get_param(cmd, "Protected");
11526 if (pmf) {
11527 if (strcasecmp(pmf, "Correct-key") == 0 ||
11528 strcasecmp(pmf, "CorrectKey") == 0) {
11529 protected = CORRECT_KEY;
11530 } else if (strcasecmp(pmf, "IncorrectKey") == 0) {
11531 protected = INCORRECT_KEY;
11532 } else if (strcasecmp(pmf, "Unprotected") == 0) {
11533 protected = UNPROTECTED;
11534 } else {
11535 send_resp(dut, conn, SIGMA_ERROR,
11536 "errorCode,Unsupported PMFProtected");
11537 return STATUS_SENT_ERROR;
11538 }
11539 sigma_dut_print(dut, DUT_MSG_DEBUG, "Config PMF protection %d",
11540 protected);
11541 wcn_sta_set_pmf_config(dut, intf, protected);
11542 }
11543
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011544 /* Command sequence to generate Op mode notification */
11545 if (val && strcasecmp(val, "action") == 0) {
11546 val = get_param(cmd, "PPDUTxType");
11547 if (val && strcasecmp(val, "TB") == 0) {
11548 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 1)) {
11549 sigma_dut_print(dut, DUT_MSG_ERROR,
11550 "failed to send TB PPDU Tx cfg");
11551 send_resp(dut, conn, SIGMA_ERROR,
11552 "ErrorCode,set TB PPDU Tx cfg failed");
11553 return 0;
11554 }
11555 return 1;
11556 }
11557
11558 sigma_dut_print(dut, DUT_MSG_ERROR,
11559 "Action Tx type is not defined");
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070011560
11561 return SUCCESS_SEND_STATUS;
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011562 }
11563
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070011564 if (strcasecmp(val, "disassoc") == 0)
11565 wcn_sta_send_disassoc(dut, intf);
11566
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011567 return 1;
11568}
11569
11570
11571static int cmd_sta_send_frame_he(struct sigma_dut *dut,
11572 struct sigma_conn *conn,
11573 struct sigma_cmd *cmd)
11574{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011575 switch (get_driver_type(dut)) {
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011576 case DRIVER_WCN:
11577 return wcn_sta_send_frame_he(dut, conn, cmd);
11578 default:
11579 send_resp(dut, conn, SIGMA_ERROR,
11580 "errorCode,Unsupported sta_set_frame(HE) with the current driver");
11581 return 0;
11582 }
11583}
11584
11585
Lior David0fe101e2017-03-09 16:09:50 +020011586#ifdef __linux__
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030011587
11588static int
11589wil6210_send_p2p_frame_60g(struct sigma_dut *dut, struct sigma_cmd *cmd,
11590 const char *frame_name, const char *dest_mac)
11591{
11592 int isprobereq = strcasecmp(frame_name, "probereq") == 0;
11593 const char *ssid = get_param(cmd, "ssid");
11594 const char *countstr = get_param(cmd, "count");
11595 const char *channelstr = get_param(cmd, "channel");
11596 const char *group_id = get_param(cmd, "groupid");
11597 const char *client_id = get_param(cmd, "clientmac");
11598 int count, channel, freq, i;
11599 const char *fname;
11600 char frame[1024], src_mac[20], group_id_attr[25],
11601 device_macstr[3 * ETH_ALEN], client_mac[ETH_ALEN];
11602 const char *group_ssid;
11603 const int group_ssid_prefix_len = 9;
11604 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *) frame;
11605 size_t framelen = sizeof(frame);
11606 struct template_frame_tag tags[2];
11607 size_t tags_total = ARRAY_SIZE(tags);
11608 int tag_index, len, dst_len;
11609
11610 if (!countstr || !channelstr) {
11611 sigma_dut_print(dut, DUT_MSG_ERROR,
11612 "Missing argument: count, channel");
11613 return -1;
11614 }
11615 if (isprobereq && !ssid) {
11616 sigma_dut_print(dut, DUT_MSG_ERROR,
11617 "Missing argument: ssid");
11618 return -1;
11619 }
11620 if (!isprobereq && (!group_id || !client_id)) {
11621 sigma_dut_print(dut, DUT_MSG_ERROR,
11622 "Missing argument: group_id, client_id");
11623 return -1;
11624 }
11625
11626 count = atoi(countstr);
11627 channel = atoi(channelstr);
11628 freq = channel_to_freq(dut, channel);
11629
11630 if (!freq) {
11631 sigma_dut_print(dut, DUT_MSG_ERROR,
11632 "invalid channel: %s", channelstr);
11633 return -1;
11634 }
11635
11636 if (isprobereq) {
11637 if (strcasecmp(ssid, "wildcard") == 0) {
11638 fname = "probe_req_wildcard.txt";
11639 } else if (strcasecmp(ssid, "P2P_Wildcard") == 0) {
11640 fname = "probe_req_P2P_Wildcard.txt";
11641 } else {
11642 sigma_dut_print(dut, DUT_MSG_ERROR,
11643 "invalid probe request type");
11644 return -1;
11645 }
11646 } else {
11647 fname = "P2P_device_discovery_req.txt";
11648 }
11649
11650 if (parse_template_frame_file(dut, fname, frame, &framelen,
11651 tags, &tags_total)) {
11652 sigma_dut_print(dut, DUT_MSG_ERROR,
11653 "invalid frame template: %s", fname);
11654 return -1;
11655 }
11656
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011657 if (get_wpa_status(get_station_ifname(dut), "address",
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030011658 src_mac, sizeof(src_mac)) < 0 ||
11659 parse_mac_address(dut, src_mac, &hdr->addr2[0]) ||
11660 parse_mac_address(dut, dest_mac, &hdr->addr1[0]))
11661 return -1;
11662 /* Use wildcard BSSID, since we are in PBSS */
11663 memset(&hdr->addr3, 0xFF, ETH_ALEN);
11664
11665 if (!isprobereq) {
11666 tag_index = find_template_frame_tag(tags, tags_total, 1);
11667 if (tag_index < 0) {
11668 sigma_dut_print(dut, DUT_MSG_ERROR,
11669 "can't find device id attribute");
11670 return -1;
11671 }
11672 if (parse_mac_address(dut, client_id,
11673 (unsigned char *) client_mac)) {
11674 sigma_dut_print(dut, DUT_MSG_ERROR,
11675 "invalid client_id: %s", client_id);
11676 return -1;
11677 }
11678 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
11679 framelen - tags[tag_index].offset,
11680 IEEE80211_P2P_ATTR_DEVICE_ID,
11681 client_mac, ETH_ALEN)) {
11682 sigma_dut_print(dut, DUT_MSG_ERROR,
11683 "fail to replace device id attribute");
11684 return -1;
11685 }
11686
11687 /*
11688 * group_id arg contains device MAC address followed by
11689 * space and SSID (DIRECT-somessid).
11690 * group id attribute contains device address (6 bytes)
11691 * followed by SSID prefix DIRECT-XX (9 bytes)
11692 */
11693 if (strlen(group_id) < sizeof(device_macstr)) {
11694 sigma_dut_print(dut, DUT_MSG_ERROR,
11695 "group_id arg too short");
11696 return -1;
11697 }
11698 memcpy(device_macstr, group_id, sizeof(device_macstr));
11699 device_macstr[sizeof(device_macstr) - 1] = '\0';
11700 if (parse_mac_address(dut, device_macstr,
11701 (unsigned char *) group_id_attr)) {
11702 sigma_dut_print(dut, DUT_MSG_ERROR,
11703 "fail to parse device address from group_id");
11704 return -1;
11705 }
11706 group_ssid = strchr(group_id, ' ');
11707 if (!group_ssid) {
11708 sigma_dut_print(dut, DUT_MSG_ERROR,
11709 "invalid group_id arg, no ssid");
11710 return -1;
11711 }
11712 group_ssid++;
11713 len = strlen(group_ssid);
11714 if (len < group_ssid_prefix_len) {
11715 sigma_dut_print(dut, DUT_MSG_ERROR,
11716 "group_id SSID too short");
11717 return -1;
11718 }
11719 dst_len = sizeof(group_id_attr) - ETH_ALEN;
11720 if (len > dst_len) {
11721 sigma_dut_print(dut, DUT_MSG_ERROR,
11722 "group_id SSID (%s) too long",
11723 group_ssid);
11724 return -1;
11725 }
11726
11727 memcpy(group_id_attr + ETH_ALEN, group_ssid, len);
11728 tag_index = find_template_frame_tag(tags, tags_total, 2);
11729 if (tag_index < 0) {
11730 sigma_dut_print(dut, DUT_MSG_ERROR,
11731 "can't find group id attribute");
11732 return -1;
11733 }
11734 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
11735 framelen - tags[tag_index].offset,
11736 IEEE80211_P2P_ATTR_GROUP_ID,
11737 group_id_attr,
11738 sizeof(group_id_attr))) {
11739 sigma_dut_print(dut, DUT_MSG_ERROR,
11740 "fail to replace group id attribute");
11741 return -1;
11742 }
11743 }
11744
11745 for (i = 0; i < count; i++) {
11746 if (wil6210_transmit_frame(dut, freq,
11747 WIL_TRANSMIT_FRAME_DEFAULT_ROC,
11748 frame, framelen)) {
11749 sigma_dut_print(dut, DUT_MSG_ERROR,
11750 "fail to transmit probe request frame");
11751 return -1;
11752 }
11753 }
11754
11755 return 0;
11756}
11757
11758
Lior David0fe101e2017-03-09 16:09:50 +020011759int wil6210_send_frame_60g(struct sigma_dut *dut, struct sigma_conn *conn,
11760 struct sigma_cmd *cmd)
11761{
11762 const char *frame_name = get_param(cmd, "framename");
11763 const char *mac = get_param(cmd, "dest_mac");
11764
11765 if (!frame_name || !mac) {
11766 sigma_dut_print(dut, DUT_MSG_ERROR,
11767 "framename and dest_mac must be provided");
11768 return -1;
11769 }
11770
11771 if (strcasecmp(frame_name, "brp") == 0) {
11772 const char *l_rx = get_param(cmd, "L-RX");
11773 int l_rx_i;
11774
11775 if (!l_rx) {
11776 sigma_dut_print(dut, DUT_MSG_ERROR,
11777 "L-RX must be provided");
11778 return -1;
11779 }
11780 l_rx_i = atoi(l_rx);
11781
11782 sigma_dut_print(dut, DUT_MSG_INFO,
11783 "dev_send_frame: BRP-RX, dest_mac %s, L-RX %s",
11784 mac, l_rx);
11785 if (l_rx_i != 16) {
11786 sigma_dut_print(dut, DUT_MSG_ERROR,
11787 "unsupported L-RX: %s", l_rx);
11788 return -1;
11789 }
11790
11791 if (wil6210_send_brp_rx(dut, mac, l_rx_i))
11792 return -1;
11793 } else if (strcasecmp(frame_name, "ssw") == 0) {
11794 sigma_dut_print(dut, DUT_MSG_INFO,
11795 "dev_send_frame: SLS, dest_mac %s", mac);
11796 if (wil6210_send_sls(dut, mac))
11797 return -1;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030011798 } else if ((strcasecmp(frame_name, "probereq") == 0) ||
11799 (strcasecmp(frame_name, "devdiscreq") == 0)) {
11800 sigma_dut_print(dut, DUT_MSG_INFO,
11801 "dev_send_frame: %s, dest_mac %s", frame_name,
11802 mac);
11803 if (wil6210_send_p2p_frame_60g(dut, cmd, frame_name, mac))
11804 return -1;
Lior David0fe101e2017-03-09 16:09:50 +020011805 } else {
11806 sigma_dut_print(dut, DUT_MSG_ERROR,
11807 "unsupported frame type: %s", frame_name);
11808 return -1;
11809 }
11810
11811 return 1;
11812}
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030011813
Lior David0fe101e2017-03-09 16:09:50 +020011814#endif /* __linux__ */
11815
11816
11817static int cmd_sta_send_frame_60g(struct sigma_dut *dut,
11818 struct sigma_conn *conn,
11819 struct sigma_cmd *cmd)
11820{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011821 switch (get_driver_type(dut)) {
Lior David0fe101e2017-03-09 16:09:50 +020011822#ifdef __linux__
11823 case DRIVER_WIL6210:
11824 return wil6210_send_frame_60g(dut, conn, cmd);
11825#endif /* __linux__ */
11826 default:
11827 send_resp(dut, conn, SIGMA_ERROR,
11828 "errorCode,Unsupported sta_set_frame(60G) with the current driver");
11829 return 0;
11830 }
11831}
11832
11833
Ashwini Patildb59b3c2017-04-13 15:19:23 +053011834static int mbo_send_anqp_query(struct sigma_dut *dut, struct sigma_conn *conn,
11835 const char *intf, struct sigma_cmd *cmd)
11836{
11837 const char *val, *addr;
11838 char buf[100];
11839
11840 addr = get_param(cmd, "DestMac");
11841 if (!addr) {
11842 send_resp(dut, conn, SIGMA_INVALID,
11843 "ErrorCode,AP MAC address is missing");
11844 return 0;
11845 }
11846
11847 val = get_param(cmd, "ANQPQuery_ID");
11848 if (!val) {
11849 send_resp(dut, conn, SIGMA_INVALID,
11850 "ErrorCode,Missing ANQPQuery_ID");
11851 return 0;
11852 }
11853
11854 if (strcasecmp(val, "NeighborReportReq") == 0) {
11855 snprintf(buf, sizeof(buf), "ANQP_GET %s 272", addr);
11856 } else if (strcasecmp(val, "QueryListWithCellPref") == 0) {
11857 snprintf(buf, sizeof(buf), "ANQP_GET %s 272,mbo:2", addr);
11858 } else {
11859 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid ANQPQuery_ID: %s",
11860 val);
11861 send_resp(dut, conn, SIGMA_INVALID,
11862 "ErrorCode,Invalid ANQPQuery_ID");
11863 return 0;
11864 }
11865
Ashwini Patild174f2c2017-04-13 16:49:46 +053011866 /* Set gas_address3 field to IEEE 802.11-2012 standard compliant form
11867 * (Address3 = Wildcard BSSID when sent to not-associated AP;
11868 * if associated, AP BSSID).
11869 */
11870 if (wpa_command(intf, "SET gas_address3 1") < 0) {
11871 send_resp(dut, conn, SIGMA_ERROR,
11872 "ErrorCode,Failed to set gas_address3");
11873 return 0;
11874 }
11875
Ashwini Patildb59b3c2017-04-13 15:19:23 +053011876 if (wpa_command(intf, buf) < 0) {
11877 send_resp(dut, conn, SIGMA_ERROR,
11878 "ErrorCode,Failed to send ANQP query");
11879 return 0;
11880 }
11881
11882 return 1;
11883}
11884
11885
11886static int mbo_cmd_sta_send_frame(struct sigma_dut *dut,
11887 struct sigma_conn *conn,
11888 const char *intf,
11889 struct sigma_cmd *cmd)
11890{
11891 const char *val = get_param(cmd, "FrameName");
11892
11893 if (val && strcasecmp(val, "ANQPQuery") == 0)
11894 return mbo_send_anqp_query(dut, conn, intf, cmd);
11895
11896 return 2;
11897}
11898
11899
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053011900static enum sigma_cmd_result cmd_sta_send_frame_wpa3(struct sigma_dut *dut,
11901 struct sigma_conn *conn,
11902 const char *intf,
11903 struct sigma_cmd *cmd)
11904{
11905 const char *val = get_param(cmd, "framename");
11906
11907 if (!val)
11908 return INVALID_SEND_STATUS;
11909
11910 if (strcasecmp(val, "SAQueryReq") == 0) {
11911 val = get_param(cmd, "OCIChannel");
11912
11913 if (!val) {
11914 send_resp(dut, conn, SIGMA_ERROR,
11915 "errorCode,OCIChannel not present");
11916 return STATUS_SENT_ERROR;
11917 }
11918
11919 dut->saquery_oci_freq = channel_to_freq(dut, atoi(val));
11920 if (!dut->saquery_oci_freq) {
11921 send_resp(dut, conn, SIGMA_ERROR,
11922 "errorCode,Invalid OCIChannel number");
11923 return STATUS_SENT_ERROR;
11924 }
11925
11926 return sta_inject_frame(dut, conn, intf, SAQUERY, CORRECT_KEY,
11927 NULL, 0);
11928 }
11929
11930 if (strcasecmp(val, "reassocreq") == 0)
11931 return sta_inject_frame(dut, conn, intf, REASSOCREQ,
11932 CORRECT_KEY, NULL, 0);
11933
Veerendranath9f81dfb2020-08-10 01:21:29 -070011934 if (strcasecmp(val, "ANQPQuery") == 0) {
11935 char buf[50];
11936 const char *dest = get_param(cmd, "DestMac");
11937 const char *chan = get_param(cmd, "channel");
Veerendranath Jakkam78862fc2020-11-19 21:23:27 +053011938 const char *freq_str = get_param(cmd, "ChnlFreq");
Veerendranath9f81dfb2020-08-10 01:21:29 -070011939 int len, freq;
11940
Veerendranath Jakkam78862fc2020-11-19 21:23:27 +053011941 if (freq_str)
11942 freq = atoi(freq_str);
11943 else
11944 freq = chan ? channel_to_freq(dut, atoi(chan)) : 0;
11945
Veerendranath9f81dfb2020-08-10 01:21:29 -070011946 if (!dest || !freq)
11947 return INVALID_SEND_STATUS;
11948
11949 len = snprintf(buf, sizeof(buf), "ANQP_GET %s freq=%d 257",
11950 dest, freq);
11951 if (len < 0 || len >= sizeof(buf)) {
11952 sigma_dut_print(dut, DUT_MSG_ERROR,
11953 "Failed to allocate buf");
11954 return ERROR_SEND_STATUS;
11955 }
11956
11957 if (wpa_command(intf, buf) != 0) {
11958 send_resp(dut, conn, SIGMA_ERROR,
11959 "ErrorCode,Failed to send ANQP Query frame");
11960 return STATUS_SENT_ERROR;
11961 }
11962
11963 sigma_dut_print(dut, DUT_MSG_DEBUG,
11964 "ANQP Query sent: %s", buf);
11965
11966 return SUCCESS_SEND_STATUS;
11967 }
11968
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053011969 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported framename");
11970 return STATUS_SENT_ERROR;
11971}
11972
11973
Vinita S. Malooca85fd22021-01-15 02:54:34 +053011974static int
11975get_type4_frame_classifier(struct sigma_dut *dut, struct sigma_cmd *cmd,
11976 char *pos, int rem_len, int num_of_scs_desc,
11977 int num_of_tclas_elem)
11978{
11979 const char *val;
11980 int ipv6;
11981 int len, total_len = 0;
11982
11983 val = get_param_fmt(cmd, "TCLASElem_Version_%d_%d", num_of_scs_desc,
11984 num_of_tclas_elem);
11985 if (!val) {
11986 sigma_dut_print(dut, DUT_MSG_ERROR, "%s: ip_version empty",
11987 __func__);
11988 return -1;
11989 }
11990
11991 if (strcmp(val, "6") == 0) {
11992 ipv6 = 1;
11993 } else if (strcmp(val, "4") == 0) {
11994 ipv6 = 0;
11995 } else {
11996 sigma_dut_print(dut, DUT_MSG_ERROR, "%s: ip_version invalid",
11997 __func__);
11998 return -1;
11999 }
12000
12001 len = snprintf(pos, rem_len, " ip_version=%s", ipv6 ? "ipv6" : "ipv4");
12002 if (len < 0 || len >= rem_len)
12003 return -1;
12004
12005 pos += len;
12006 rem_len -= len;
12007 total_len += len;
12008
12009 val = get_param_fmt(cmd, "TCLASElem_SourceIPAddr_%d_%d",
12010 num_of_scs_desc, num_of_tclas_elem);
12011 if (val) {
12012 len = snprintf(pos, rem_len, " src_ip=%s", val);
12013 if (len < 0 || len >= rem_len)
12014 return -1;
12015
12016 pos += len;
12017 rem_len -= len;
12018 total_len += len;
12019 }
12020
12021 val = get_param_fmt(cmd, "TCLASElem_DestinationIPAddr_%d_%d",
12022 num_of_scs_desc, num_of_tclas_elem);
12023 if (val) {
12024 len = snprintf(pos, rem_len, " dst_ip=%s", val);
12025 if (len < 0 || len >= rem_len)
12026 return -1;
12027
12028 pos += len;
12029 rem_len -= len;
12030 total_len += len;
12031 }
12032
12033 val = get_param_fmt(cmd, "TCLASElem_SourcePort_%d_%d", num_of_scs_desc,
12034 num_of_tclas_elem);
12035 if (val) {
12036 len = snprintf(pos, rem_len, " src_port=%s", val);
12037 if (len < 0 || len >= rem_len)
12038 return -1;
12039
12040 pos += len;
12041 rem_len -= len;
12042 total_len += len;
12043 }
12044
12045 val = get_param_fmt(cmd, "TCLASElem_DestinationPort_%d_%d",
12046 num_of_scs_desc, num_of_tclas_elem);
12047 if (val) {
12048 len = snprintf(pos, rem_len, " dst_port=%s", val);
12049 if (len < 0 || len >= rem_len)
12050 return -1;
12051
12052 pos += len;
12053 rem_len -= len;
12054 total_len += len;
12055 }
12056
12057 val = get_param_fmt(cmd, "TCLASElem_DSCP_%d_%d", num_of_scs_desc,
12058 num_of_tclas_elem);
12059 if (val) {
12060 len = snprintf(pos, rem_len, " dscp=%s", val);
12061 if (len < 0 || len >= rem_len)
12062 return -1;
12063
12064 pos += len;
12065 rem_len -= len;
12066 total_len += len;
12067 }
12068
12069 val = get_param_fmt(cmd, "TCLASElem_ProtocolNxtHeader_%d_%d",
12070 num_of_scs_desc, num_of_tclas_elem);
12071 if (val) {
12072 char *prot;
12073
12074 switch (atoi(val)) {
12075 case 17:
12076 prot = "udp";
12077 break;
12078 case 6:
12079 prot = "tcp";
12080 break;
12081 case 50:
12082 prot = "esp";
12083 break;
12084 default:
12085 sigma_dut_print(dut, DUT_MSG_ERROR,
12086 "Invalid protocol %d", atoi(val));
12087 return -1;
12088 }
12089
12090 if (ipv6)
12091 len = snprintf(pos, rem_len, " next_header=%s", prot);
12092 else
12093 len = snprintf(pos, rem_len, " protocol=%s", prot);
12094 if (len < 0 || len >= rem_len)
12095 return -1;
12096
12097 pos += len;
12098 rem_len -= len;
12099 total_len += len;
12100 }
12101
12102 return total_len;
12103}
12104
12105
12106static int
12107get_type10_frame_classifier(struct sigma_dut *dut, struct sigma_cmd *cmd,
12108 char *pos, int rem_len, int num_of_scs_desc,
12109 int num_of_tclas_elem)
12110{
12111 const char *val;
12112 int len, total_len = 0;
12113
12114 val = get_param_fmt(cmd, "TCLASElem_ProtoInstance_%d_%d",
12115 num_of_scs_desc, num_of_tclas_elem);
12116 if (val) {
12117 len = snprintf(pos, rem_len, " prot_instance=%s",
12118 val);
12119 if (len < 0 || len >= rem_len)
12120 return -1;
12121
12122 pos += len;
12123 rem_len -= len;
12124 total_len += len;
12125 }
12126
12127 val = get_param_fmt(cmd, "TCLASElem_ProtoNumNextHeader_%d_%d",
12128 num_of_scs_desc, num_of_tclas_elem);
12129 if (val) {
12130 char *prot;
12131
12132 switch (atoi(val)) {
12133 case 17:
12134 prot = "udp";
12135 break;
12136 case 6:
12137 prot = "tcp";
12138 break;
12139 case 50:
12140 prot = "esp";
12141 break;
12142 default:
12143 sigma_dut_print(dut, DUT_MSG_ERROR,
12144 "Invalid protocol %d",
12145 atoi(val));
12146 return -1;
12147 }
12148
12149 len = snprintf(pos, rem_len, " prot_number=%s", prot);
12150 if (len < 0 || len >= rem_len)
12151 return -1;
12152
12153 pos += len;
12154 rem_len -= len;
12155 total_len += len;
12156 }
12157
12158 val = get_param_fmt(cmd, "TCLASElem_FilterValue_%d_%d",
12159 num_of_scs_desc, num_of_tclas_elem);
12160 if (val) {
12161 len = snprintf(pos, rem_len, " filter_value=%s", (val + 2));
12162 if (len < 0 || len >= rem_len)
12163 return -1;
12164
12165 pos += len;
12166 rem_len -= len;
12167 total_len += len;
12168 }
12169
12170 val = get_param_fmt(cmd, "TCLASElem_FilterMask_%d_%d", num_of_scs_desc,
12171 num_of_tclas_elem);
12172 if (val && strlen(val) >= 2) {
12173 len = snprintf(pos, rem_len, " filter_mask=%s", val + 2);
12174 if (len < 0 || len >= rem_len)
12175 return -1;
12176
12177 pos += len;
12178 rem_len -= len;
12179 total_len += len;
12180 }
12181
12182 return total_len;
12183}
12184
12185
12186static enum sigma_cmd_result
12187cmd_sta_send_frame_scs(struct sigma_dut *dut, struct sigma_conn *conn,
12188 const char *intf, struct sigma_cmd *cmd)
12189{
12190 char buf[4096], *pos;
12191 const char *val, *scs_id, *classifier_type;
12192 int len, rem_len, total_bytes;
12193 int num_of_scs_desc = 0, num_of_tclas_elem = 0;
12194
12195 scs_id = get_param(cmd, "SCSDescrElem_SCSID_1");
12196 if (!scs_id) {
12197 sigma_dut_print(dut, DUT_MSG_ERROR, "SCS ID empty");
12198 return INVALID_SEND_STATUS;
12199 }
12200
12201 rem_len = sizeof(buf);
12202 pos = buf;
12203
12204 len = snprintf(buf, sizeof(buf), "SCS");
12205 if (len < 0 || len > rem_len)
12206 goto fail;
12207
12208 pos += len;
12209 rem_len -= len;
12210
12211 while (scs_id) {
12212 num_of_scs_desc++;
12213
12214 val = get_param_fmt(cmd, "SCSDescrElem_RequestType_%d",
12215 num_of_scs_desc);
12216 if (!val)
12217 return INVALID_SEND_STATUS;
12218
12219 if (strcasecmp(val, "Add") == 0) {
12220 len = snprintf(pos, rem_len, " scs_id=%s add",
12221 scs_id);
12222 } else if (strcasecmp(val, "Change") == 0) {
12223 len = snprintf(pos, rem_len, " scs_id=%s change",
12224 scs_id);
12225 } else if (strcasecmp(val, "Remove") == 0) {
12226 len = snprintf(pos, rem_len, " scs_id=%s remove",
12227 scs_id);
12228 if (len < 0 || len >= rem_len)
12229 goto fail;
12230
12231 pos += len;
12232 rem_len -= len;
12233 goto scs_desc_end;
12234 } else {
12235 sigma_dut_print(dut, DUT_MSG_ERROR,
12236 "%s: request type - %s is invalid",
12237 __func__, val);
12238 return INVALID_SEND_STATUS;
12239 }
12240
12241 if (len < 0 || len >= rem_len)
12242 goto fail;
12243
12244 pos += len;
12245 rem_len -= len;
12246
12247 val = get_param_fmt(cmd, "IntraAccessCatElem_UP_%d",
12248 num_of_scs_desc);
12249 if (!val) {
12250 sigma_dut_print(dut, DUT_MSG_ERROR,
12251 "IntraAccess Priority empty");
12252 return INVALID_SEND_STATUS;
12253 }
12254
12255 len = snprintf(pos, rem_len, " scs_up=%s", val);
12256 if (len < 0 || len >= rem_len)
12257 goto fail;
12258
12259 pos += len;
12260 rem_len -= len;
12261
12262 classifier_type = get_param_fmt(cmd,
12263 "TCLASElem_ClassifierType_%d_1",
12264 num_of_scs_desc);
12265 if (!classifier_type) {
12266 sigma_dut_print(dut, DUT_MSG_ERROR,
12267 "classifier type missing");
12268 return INVALID_SEND_STATUS;
12269 }
12270
12271 while (classifier_type) {
12272 num_of_tclas_elem++;
12273
12274 len = snprintf(pos, rem_len, " classifier_type=%s",
12275 classifier_type);
12276 if (len < 0 || len >= rem_len)
12277 goto fail;
12278
12279 pos += len;
12280 rem_len -= len;
12281
12282 if (strcmp(classifier_type, "10") == 0) {
12283 total_bytes = get_type10_frame_classifier(
12284 dut, cmd, pos, rem_len,
12285 num_of_scs_desc,
12286 num_of_tclas_elem);
12287 } else if (strcmp(classifier_type, "4") == 0) {
12288 total_bytes = get_type4_frame_classifier(
12289 dut, cmd, pos, rem_len,
12290 num_of_scs_desc,
12291 num_of_tclas_elem);
12292 } else {
12293 sigma_dut_print(dut, DUT_MSG_ERROR,
12294 "classifier_type invalid");
12295 goto fail;
12296 }
12297
12298 if (total_bytes < 0)
12299 goto fail;
12300
12301 pos += total_bytes;
12302 rem_len -= total_bytes;
12303
12304 classifier_type = get_param_fmt(
12305 cmd, "TCLASElem_ClassifierType_%d_%d",
12306 num_of_scs_desc, num_of_tclas_elem + 1);
12307 }
12308
12309 if (num_of_tclas_elem > 1) {
12310 val = get_param_fmt(cmd,
12311 "TCLASProcessingElem_Processing_%d",
12312 num_of_scs_desc);
12313 if (!val) {
12314 sigma_dut_print(dut, DUT_MSG_ERROR,
12315 "Tclas_processing element %d empty",
12316 num_of_scs_desc);
12317 goto fail;
12318 }
12319
12320 len = snprintf(pos, rem_len,
12321 " tclas_processing=%s", val);
12322 if (len < 0 || len >= rem_len)
12323 goto fail;
12324
12325 pos += len;
12326 rem_len -= len;
12327 }
12328scs_desc_end:
12329 num_of_tclas_elem = 0;
12330 scs_id = get_param_fmt(cmd, "SCSDescrElem_SCSID_%d",
12331 num_of_scs_desc + 1);
12332 }
12333
12334 if (wpa_command(intf, buf) != 0) {
12335 send_resp(dut, conn, SIGMA_ERROR,
12336 "ErrorCode,Failed to send SCS frame request");
12337 return STATUS_SENT_ERROR;
12338 }
12339
12340 sigma_dut_print(dut, DUT_MSG_DEBUG,
12341 "SCS frame request sent: %s", buf);
12342
12343 return SUCCESS_SEND_STATUS;
12344fail:
12345 sigma_dut_print(dut, DUT_MSG_ERROR,
12346 "Failed to create SCS frame request");
12347 return ERROR_SEND_STATUS;
12348}
12349
12350
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053012351static enum sigma_cmd_result
12352cmd_sta_send_frame_mscs(struct sigma_dut *dut, struct sigma_conn *conn,
12353 const char *intf, struct sigma_cmd *cmd)
12354{
12355 char buf[128], *pos;
12356 const char *val, *classifier_type = "04", *type;
12357 int len, rem_len;
12358 u8 up_bitmap;
12359
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053012360 type = get_param(cmd, "Request_Type");
Vinita S. Malooca85fd22021-01-15 02:54:34 +053012361 if (!type) {
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053012362 sigma_dut_print(dut, DUT_MSG_ERROR,
Vinita S. Malooca85fd22021-01-15 02:54:34 +053012363 "%s: type not valid", __func__);
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053012364 return INVALID_SEND_STATUS;
12365 }
12366
12367 rem_len = sizeof(buf);
12368 pos = buf;
12369 if (strcasecmp(type, "add") == 0) {
12370 len = snprintf(pos, rem_len, "MSCS add");
12371 } else if (strcasecmp(type, "update") == 0) {
12372 len = snprintf(pos, rem_len, "MSCS change");
12373 } else if (strcasecmp(type, "remove") == 0) {
12374 if (wpa_command(intf, "MSCS remove") != 0) {
12375 send_resp(dut, conn, SIGMA_ERROR,
12376 "ErrorCode,Failed to send MSCS frame req");
12377 return STATUS_SENT_ERROR;
12378 }
12379 return SUCCESS_SEND_STATUS;
12380 } else {
12381 sigma_dut_print(dut, DUT_MSG_ERROR,
12382 "%s: request type invalid", __func__);
12383 return INVALID_SEND_STATUS;
12384 }
12385
12386 if (len < 0 || len >= rem_len)
12387 goto fail;
12388
12389 pos += len;
12390 rem_len -= len;
12391
12392 val = get_param(cmd, "User_Priority_Bitmap");
12393 if (!val) {
12394 sigma_dut_print(dut, DUT_MSG_ERROR,
12395 "%s: user priority bitmap empty", __func__);
12396 return INVALID_SEND_STATUS;
12397 }
12398
12399 switch (atoi(val)) {
12400 case 0:
12401 up_bitmap = 0x00;
12402 break;
12403 case 1:
12404 up_bitmap = 0xF0;
12405 break;
12406 case 2:
12407 up_bitmap = 0xF6;
12408 break;
12409 default:
12410 sigma_dut_print(dut, DUT_MSG_ERROR,
12411 "%s: Unknown User_Priority_Bitmap value %d",
12412 __func__, atoi(val));
12413 return INVALID_SEND_STATUS;
12414 }
12415
12416 len = snprintf(pos, rem_len, " up_bitmap=%02x", up_bitmap);
12417 if (len < 0 || len >= rem_len)
12418 goto fail;
12419
12420 pos += len;
12421 rem_len -= len;
12422
12423 val = get_param(cmd, "User_Priority_Limit");
12424 if (!val) {
12425 sigma_dut_print(dut, DUT_MSG_ERROR,
12426 "%s: invalid user priority limit", __func__);
12427 return INVALID_SEND_STATUS;
12428 }
12429
12430 len = snprintf(pos, rem_len, " up_limit=%s", val);
12431 if (len < 0 || len >= rem_len)
12432 goto fail;
12433
12434 pos += len;
12435 rem_len -= len;
12436
12437 val = get_param(cmd, "Stream_Timeout");
12438 if (!val)
12439 val = get_param(cmd, "Stream_Timtout");
12440 if (!val) {
12441 sigma_dut_print(dut, DUT_MSG_ERROR,
12442 "%s: invalid stream timeout", __func__);
12443 return INVALID_SEND_STATUS;
12444 }
12445
12446 len = snprintf(pos, rem_len, " stream_timeout=%s", val);
12447 if (len < 0 || len >= rem_len)
12448 goto fail;
12449
12450 pos += len;
12451 rem_len -= len;
12452
12453 val = get_param(cmd, "TCLAS_Mask");
12454 if (!val) {
12455 sigma_dut_print(dut, DUT_MSG_ERROR,
12456 "%s: invalid tclas mask", __func__);
12457 return INVALID_SEND_STATUS;
12458 }
12459
12460 len = snprintf(pos, rem_len, " frame_classifier=%s%lx%032x",
12461 classifier_type, strtol(val, NULL, 2), 0);
12462 if (len < 0 || len >= rem_len)
12463 goto fail;
12464
12465 if (wpa_command(intf, buf) != 0) {
12466 send_resp(dut, conn, SIGMA_ERROR,
12467 "ErrorCode,Failed to send MSCS frame req");
12468 return STATUS_SENT_ERROR;
12469 }
12470
12471 sigma_dut_print(dut, DUT_MSG_DEBUG,
12472 "MSCS frame request sent: %s", buf);
12473
12474 return SUCCESS_SEND_STATUS;
12475fail:
12476 sigma_dut_print(dut, DUT_MSG_ERROR,
12477 "Failed to create MSCS frame req");
12478 return ERROR_SEND_STATUS;
12479}
12480
12481
Vinita S. Malooca85fd22021-01-15 02:54:34 +053012482static enum sigma_cmd_result
12483cmd_sta_send_frame_qm(struct sigma_dut *dut, struct sigma_conn *conn,
12484 const char *intf, struct sigma_cmd *cmd)
12485{
12486 const char *val;
12487
12488 val = get_param(cmd, "FrameName");
12489 if (val) {
12490 if (strcasecmp(val, "MSCSReq") == 0)
12491 return cmd_sta_send_frame_mscs(dut, conn, intf, cmd);
12492 if (strcasecmp(val, "SCSReq") == 0)
12493 return cmd_sta_send_frame_scs(dut, conn, intf, cmd);
12494
12495 sigma_dut_print(dut, DUT_MSG_ERROR,
12496 "%s: frame name - %s is invalid",
12497 __func__, val);
12498 }
12499
12500 return INVALID_SEND_STATUS;
12501}
12502
12503
Jouni Malinenf7222712019-06-13 01:50:21 +030012504enum sigma_cmd_result cmd_sta_send_frame(struct sigma_dut *dut,
12505 struct sigma_conn *conn,
12506 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012507{
12508 const char *intf = get_param(cmd, "Interface");
12509 const char *val;
12510 enum send_frame_type frame;
12511 enum send_frame_protection protected;
12512 char buf[100];
12513 unsigned char addr[ETH_ALEN];
12514 int res;
12515
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030012516 if (!intf)
12517 return -1;
12518
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012519 val = get_param(cmd, "program");
12520 if (val == NULL)
12521 val = get_param(cmd, "frame");
12522 if (val && strcasecmp(val, "TDLS") == 0)
12523 return cmd_sta_send_frame_tdls(dut, conn, cmd);
12524 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030012525 strcasecmp(val, "HS2-R2") == 0 ||
12526 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012527 return cmd_sta_send_frame_hs2(dut, conn, cmd);
12528 if (val && strcasecmp(val, "VHT") == 0)
12529 return cmd_sta_send_frame_vht(dut, conn, cmd);
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070012530 if (val && strcasecmp(val, "HE") == 0)
12531 return cmd_sta_send_frame_he(dut, conn, cmd);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -070012532 if (val && strcasecmp(val, "LOC") == 0)
12533 return loc_cmd_sta_send_frame(dut, conn, cmd);
Lior David0fe101e2017-03-09 16:09:50 +020012534 if (val && strcasecmp(val, "60GHz") == 0)
12535 return cmd_sta_send_frame_60g(dut, conn, cmd);
Ashwini Patildb59b3c2017-04-13 15:19:23 +053012536 if (val && strcasecmp(val, "MBO") == 0) {
12537 res = mbo_cmd_sta_send_frame(dut, conn, intf, cmd);
12538 if (res != 2)
12539 return res;
12540 }
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053012541 if (val && strcasecmp(val, "WPA3") == 0)
12542 return cmd_sta_send_frame_wpa3(dut, conn, intf, cmd);
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053012543 if (val && strcasecmp(val, "QM") == 0)
Vinita S. Malooca85fd22021-01-15 02:54:34 +053012544 return cmd_sta_send_frame_qm(dut, conn, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012545
12546 val = get_param(cmd, "TD_DISC");
12547 if (val) {
12548 if (hwaddr_aton(val, addr) < 0)
12549 return -1;
12550 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", val);
12551 if (wpa_command(intf, buf) < 0) {
12552 send_resp(dut, conn, SIGMA_ERROR,
12553 "ErrorCode,Failed to send TDLS discovery");
12554 return 0;
12555 }
12556 return 1;
12557 }
12558
12559 val = get_param(cmd, "TD_Setup");
12560 if (val) {
12561 if (hwaddr_aton(val, addr) < 0)
12562 return -1;
12563 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", val);
12564 if (wpa_command(intf, buf) < 0) {
12565 send_resp(dut, conn, SIGMA_ERROR,
12566 "ErrorCode,Failed to start TDLS setup");
12567 return 0;
12568 }
12569 return 1;
12570 }
12571
12572 val = get_param(cmd, "TD_TearDown");
12573 if (val) {
12574 if (hwaddr_aton(val, addr) < 0)
12575 return -1;
12576 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", val);
12577 if (wpa_command(intf, buf) < 0) {
12578 send_resp(dut, conn, SIGMA_ERROR,
12579 "ErrorCode,Failed to tear down TDLS link");
12580 return 0;
12581 }
12582 return 1;
12583 }
12584
12585 val = get_param(cmd, "TD_ChannelSwitch");
12586 if (val) {
12587 /* TODO */
12588 send_resp(dut, conn, SIGMA_ERROR,
12589 "ErrorCode,TD_ChannelSwitch not yet supported");
12590 return 0;
12591 }
12592
12593 val = get_param(cmd, "TD_NF");
12594 if (val) {
12595 /* TODO */
12596 send_resp(dut, conn, SIGMA_ERROR,
12597 "ErrorCode,TD_NF not yet supported");
12598 return 0;
12599 }
12600
12601 val = get_param(cmd, "PMFFrameType");
12602 if (val == NULL)
12603 val = get_param(cmd, "FrameName");
12604 if (val == NULL)
12605 val = get_param(cmd, "Type");
12606 if (val == NULL)
12607 return -1;
12608 if (strcasecmp(val, "disassoc") == 0)
12609 frame = DISASSOC;
12610 else if (strcasecmp(val, "deauth") == 0)
12611 frame = DEAUTH;
12612 else if (strcasecmp(val, "saquery") == 0)
12613 frame = SAQUERY;
12614 else if (strcasecmp(val, "auth") == 0)
12615 frame = AUTH;
12616 else if (strcasecmp(val, "assocreq") == 0)
12617 frame = ASSOCREQ;
12618 else if (strcasecmp(val, "reassocreq") == 0)
12619 frame = REASSOCREQ;
12620 else if (strcasecmp(val, "neigreq") == 0) {
12621 sigma_dut_print(dut, DUT_MSG_INFO, "Got neighbor request");
12622
12623 val = get_param(cmd, "ssid");
12624 if (val == NULL)
12625 return -1;
12626
12627 res = send_neighbor_request(dut, intf, val);
12628 if (res) {
12629 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
12630 "Failed to send neighbor report request");
12631 return 0;
12632 }
12633
12634 return 1;
Ashwini Patil5acd7382017-04-13 15:55:04 +053012635 } else if (strcasecmp(val, "transmgmtquery") == 0 ||
12636 strcasecmp(val, "BTMQuery") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012637 sigma_dut_print(dut, DUT_MSG_DEBUG,
12638 "Got Transition Management Query");
12639
Ashwini Patil5acd7382017-04-13 15:55:04 +053012640 res = send_trans_mgmt_query(dut, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012641 if (res) {
12642 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
12643 "Failed to send Transition Management Query");
12644 return 0;
12645 }
12646
12647 return 1;
12648 } else {
12649 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
12650 "PMFFrameType");
12651 return 0;
12652 }
12653
12654 val = get_param(cmd, "PMFProtected");
12655 if (val == NULL)
12656 val = get_param(cmd, "Protected");
12657 if (val == NULL)
12658 return -1;
12659 if (strcasecmp(val, "Correct-key") == 0 ||
12660 strcasecmp(val, "CorrectKey") == 0)
12661 protected = CORRECT_KEY;
12662 else if (strcasecmp(val, "IncorrectKey") == 0)
12663 protected = INCORRECT_KEY;
12664 else if (strcasecmp(val, "Unprotected") == 0)
12665 protected = UNPROTECTED;
12666 else {
12667 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
12668 "PMFProtected");
12669 return 0;
12670 }
12671
12672 if (protected != UNPROTECTED &&
12673 (frame == AUTH || frame == ASSOCREQ || frame == REASSOCREQ)) {
12674 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Impossible "
12675 "PMFProtected for auth/assocreq/reassocreq");
12676 return 0;
12677 }
12678
12679 if (if_nametoindex("sigmadut") == 0) {
12680 snprintf(buf, sizeof(buf),
12681 "iw dev %s interface add sigmadut type monitor",
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012682 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012683 if (system(buf) != 0 ||
12684 if_nametoindex("sigmadut") == 0) {
12685 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
12686 "monitor interface with '%s'", buf);
12687 return -2;
12688 }
12689 }
12690
12691 if (system("ifconfig sigmadut up") != 0) {
12692 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
12693 "monitor interface up");
12694 return -2;
12695 }
12696
Veerendranath Jakkam49774122020-07-05 09:52:18 +053012697 return sta_inject_frame(dut, conn, intf, frame, protected, NULL, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012698}
12699
12700
12701static int cmd_sta_set_parameter_hs2(struct sigma_dut *dut,
12702 struct sigma_conn *conn,
12703 struct sigma_cmd *cmd,
12704 const char *ifname)
12705{
12706 char buf[200];
12707 const char *val;
12708
12709 val = get_param(cmd, "ClearARP");
12710 if (val && atoi(val) == 1) {
12711 snprintf(buf, sizeof(buf), "ip neigh flush dev %s", ifname);
12712 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
12713 if (system(buf) != 0) {
12714 send_resp(dut, conn, SIGMA_ERROR,
12715 "errorCode,Failed to clear ARP cache");
12716 return 0;
12717 }
12718 }
12719
12720 return 1;
12721}
12722
12723
12724int cmd_sta_set_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
12725 struct sigma_cmd *cmd)
12726{
12727 const char *intf = get_param(cmd, "Interface");
12728 const char *val;
12729
12730 if (intf == NULL)
12731 return -1;
12732
12733 val = get_param(cmd, "program");
12734 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030012735 strcasecmp(val, "HS2-R2") == 0 ||
12736 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012737 return cmd_sta_set_parameter_hs2(dut, conn, cmd, intf);
12738
12739 return -1;
12740}
12741
12742
Jouni Malinenf7222712019-06-13 01:50:21 +030012743static enum sigma_cmd_result cmd_sta_set_macaddr(struct sigma_dut *dut,
12744 struct sigma_conn *conn,
12745 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012746{
12747 const char *intf = get_param(cmd, "Interface");
12748 const char *mac = get_param(cmd, "MAC");
12749
12750 if (intf == NULL || mac == NULL)
12751 return -1;
12752
12753 sigma_dut_print(dut, DUT_MSG_INFO, "Change local MAC address for "
12754 "interface %s to %s", intf, mac);
12755
12756 if (dut->set_macaddr) {
12757 char buf[128];
12758 int res;
12759 if (strcasecmp(mac, "default") == 0) {
12760 res = snprintf(buf, sizeof(buf), "%s",
12761 dut->set_macaddr);
12762 dut->tmp_mac_addr = 0;
12763 } else {
12764 res = snprintf(buf, sizeof(buf), "%s %s",
12765 dut->set_macaddr, mac);
12766 dut->tmp_mac_addr = 1;
12767 }
12768 if (res < 0 || res >= (int) sizeof(buf))
12769 return -1;
12770 if (system(buf) != 0) {
12771 send_resp(dut, conn, SIGMA_ERROR,
12772 "errorCode,Failed to set MAC "
12773 "address");
12774 return 0;
12775 }
12776 return 1;
12777 }
12778
12779 if (strcasecmp(mac, "default") == 0)
12780 return 1;
12781
12782 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
12783 "command");
12784 return 0;
12785}
12786
12787
12788static int iwpriv_tdlsoffchnmode(struct sigma_dut *dut,
12789 struct sigma_conn *conn, const char *intf,
12790 int val)
12791{
12792 char buf[200];
12793 int res;
12794
12795 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchnmode %d",
12796 intf, val);
12797 if (res < 0 || res >= (int) sizeof(buf))
12798 return -1;
12799 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
12800 if (system(buf) != 0) {
12801 send_resp(dut, conn, SIGMA_ERROR,
12802 "errorCode,Failed to configure offchannel mode");
12803 return 0;
12804 }
12805
12806 return 1;
12807}
12808
12809
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012810static int off_chan_val(enum sec_ch_offset off)
12811{
12812 switch (off) {
12813 case SEC_CH_NO:
12814 return 0;
12815 case SEC_CH_40ABOVE:
12816 return 40;
12817 case SEC_CH_40BELOW:
12818 return -40;
12819 }
12820
12821 return 0;
12822}
12823
12824
12825static int iwpriv_set_offchan(struct sigma_dut *dut, struct sigma_conn *conn,
12826 const char *intf, int off_ch_num,
12827 enum sec_ch_offset sec)
12828{
12829 char buf[200];
12830 int res;
12831
12832 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchan %d",
12833 intf, off_ch_num);
12834 if (res < 0 || res >= (int) sizeof(buf))
12835 return -1;
12836 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
12837 if (system(buf) != 0) {
12838 send_resp(dut, conn, SIGMA_ERROR,
12839 "errorCode,Failed to set offchan");
12840 return 0;
12841 }
12842
12843 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsecchnoffst %d",
12844 intf, off_chan_val(sec));
12845 if (res < 0 || res >= (int) sizeof(buf))
12846 return -1;
12847 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
12848 if (system(buf) != 0) {
12849 send_resp(dut, conn, SIGMA_ERROR,
12850 "errorCode,Failed to set sec chan offset");
12851 return 0;
12852 }
12853
12854 return 1;
12855}
12856
12857
12858static int tdls_set_offchannel_offset(struct sigma_dut *dut,
12859 struct sigma_conn *conn,
12860 const char *intf, int off_ch_num,
12861 enum sec_ch_offset sec)
12862{
12863 char buf[200];
12864 int res;
12865
12866 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNEL %d",
12867 off_ch_num);
12868 if (res < 0 || res >= (int) sizeof(buf))
12869 return -1;
12870 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
12871
12872 if (wpa_command(intf, buf) < 0) {
12873 send_resp(dut, conn, SIGMA_ERROR,
12874 "ErrorCode,Failed to set offchan");
12875 return 0;
12876 }
12877 res = snprintf(buf, sizeof(buf), "DRIVER TDLSSECONDARYCHANNELOFFSET %d",
12878 off_chan_val(sec));
12879 if (res < 0 || res >= (int) sizeof(buf))
12880 return -1;
12881
12882 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
12883
12884 if (wpa_command(intf, buf) < 0) {
12885 send_resp(dut, conn, SIGMA_ERROR,
12886 "ErrorCode,Failed to set sec chan offset");
12887 return 0;
12888 }
12889
12890 return 1;
12891}
12892
12893
12894static int tdls_set_offchannel_mode(struct sigma_dut *dut,
12895 struct sigma_conn *conn,
12896 const char *intf, int val)
12897{
12898 char buf[200];
12899 int res;
12900
12901 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNELMODE %d",
12902 val);
12903 if (res < 0 || res >= (int) sizeof(buf))
12904 return -1;
12905 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
12906
12907 if (wpa_command(intf, buf) < 0) {
12908 send_resp(dut, conn, SIGMA_ERROR,
12909 "ErrorCode,Failed to configure offchannel mode");
12910 return 0;
12911 }
12912
12913 return 1;
12914}
12915
12916
12917static int cmd_sta_set_rfeature_tdls(const char *intf, struct sigma_dut *dut,
12918 struct sigma_conn *conn,
12919 struct sigma_cmd *cmd)
12920{
12921 const char *val;
12922 enum {
12923 CHSM_NOT_SET,
12924 CHSM_ENABLE,
12925 CHSM_DISABLE,
12926 CHSM_REJREQ,
12927 CHSM_UNSOLRESP
12928 } chsm = CHSM_NOT_SET;
12929 int off_ch_num = -1;
12930 enum sec_ch_offset sec_ch = SEC_CH_NO;
12931 int res;
12932
12933 val = get_param(cmd, "Uapsd");
12934 if (val) {
12935 char buf[100];
12936 if (strcasecmp(val, "Enable") == 0)
12937 snprintf(buf, sizeof(buf), "SET ps 99");
12938 else if (strcasecmp(val, "Disable") == 0)
12939 snprintf(buf, sizeof(buf), "SET ps 98");
12940 else {
12941 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
12942 "Unsupported uapsd parameter value");
12943 return 0;
12944 }
12945 if (wpa_command(intf, buf)) {
12946 send_resp(dut, conn, SIGMA_ERROR,
12947 "ErrorCode,Failed to change U-APSD "
12948 "powersave mode");
12949 return 0;
12950 }
12951 }
12952
12953 val = get_param(cmd, "TPKTIMER");
12954 if (val && strcasecmp(val, "DISABLE") == 0) {
12955 if (wpa_command(intf, "SET tdls_testing 0x100")) {
12956 send_resp(dut, conn, SIGMA_ERROR,
12957 "ErrorCode,Failed to enable no TPK "
12958 "expiration test mode");
12959 return 0;
12960 }
12961 dut->no_tpk_expiration = 1;
12962 }
12963
12964 val = get_param(cmd, "ChSwitchMode");
12965 if (val) {
12966 if (strcasecmp(val, "Enable") == 0 ||
12967 strcasecmp(val, "Initiate") == 0)
12968 chsm = CHSM_ENABLE;
12969 else if (strcasecmp(val, "Disable") == 0 ||
12970 strcasecmp(val, "passive") == 0)
12971 chsm = CHSM_DISABLE;
12972 else if (strcasecmp(val, "RejReq") == 0)
12973 chsm = CHSM_REJREQ;
12974 else if (strcasecmp(val, "UnSolResp") == 0)
12975 chsm = CHSM_UNSOLRESP;
12976 else {
12977 send_resp(dut, conn, SIGMA_ERROR,
12978 "ErrorCode,Unknown ChSwitchMode value");
12979 return 0;
12980 }
12981 }
12982
12983 val = get_param(cmd, "OffChNum");
12984 if (val) {
12985 off_ch_num = atoi(val);
12986 if (off_ch_num == 0) {
12987 send_resp(dut, conn, SIGMA_ERROR,
12988 "ErrorCode,Invalid OffChNum");
12989 return 0;
12990 }
12991 }
12992
12993 val = get_param(cmd, "SecChOffset");
12994 if (val) {
12995 if (strcmp(val, "20") == 0)
12996 sec_ch = SEC_CH_NO;
12997 else if (strcasecmp(val, "40above") == 0)
12998 sec_ch = SEC_CH_40ABOVE;
12999 else if (strcasecmp(val, "40below") == 0)
13000 sec_ch = SEC_CH_40BELOW;
13001 else {
13002 send_resp(dut, conn, SIGMA_ERROR,
13003 "ErrorCode,Unknown SecChOffset value");
13004 return 0;
13005 }
13006 }
13007
13008 if (chsm == CHSM_NOT_SET) {
13009 /* no offchannel changes requested */
13010 return 1;
13011 }
13012
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013013 if (strcmp(intf, get_main_ifname(dut)) != 0 &&
13014 strcmp(intf, get_station_ifname(dut)) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013015 send_resp(dut, conn, SIGMA_ERROR,
13016 "ErrorCode,Unknown interface");
13017 return 0;
13018 }
13019
13020 switch (chsm) {
13021 case CHSM_NOT_SET:
Jouni Malinen280f5ba2016-08-29 21:33:10 +030013022 res = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013023 break;
13024 case CHSM_ENABLE:
13025 if (off_ch_num < 0) {
13026 send_resp(dut, conn, SIGMA_ERROR,
13027 "ErrorCode,Missing OffChNum argument");
13028 return 0;
13029 }
13030 if (wifi_chip_type == DRIVER_WCN) {
13031 res = tdls_set_offchannel_offset(dut, conn, intf,
13032 off_ch_num, sec_ch);
13033 } else {
13034 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
13035 sec_ch);
13036 }
13037 if (res != 1)
13038 return res;
13039 if (wifi_chip_type == DRIVER_WCN)
13040 res = tdls_set_offchannel_mode(dut, conn, intf, 1);
13041 else
13042 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 1);
13043 break;
13044 case CHSM_DISABLE:
13045 if (wifi_chip_type == DRIVER_WCN)
13046 res = tdls_set_offchannel_mode(dut, conn, intf, 2);
13047 else
13048 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 2);
13049 break;
13050 case CHSM_REJREQ:
13051 if (wifi_chip_type == DRIVER_WCN)
13052 res = tdls_set_offchannel_mode(dut, conn, intf, 3);
13053 else
13054 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 3);
13055 break;
13056 case CHSM_UNSOLRESP:
13057 if (off_ch_num < 0) {
13058 send_resp(dut, conn, SIGMA_ERROR,
13059 "ErrorCode,Missing OffChNum argument");
13060 return 0;
13061 }
13062 if (wifi_chip_type == DRIVER_WCN) {
13063 res = tdls_set_offchannel_offset(dut, conn, intf,
13064 off_ch_num, sec_ch);
13065 } else {
13066 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
13067 sec_ch);
13068 }
13069 if (res != 1)
13070 return res;
13071 if (wifi_chip_type == DRIVER_WCN)
13072 res = tdls_set_offchannel_mode(dut, conn, intf, 4);
13073 else
13074 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 4);
13075 break;
13076 }
13077
13078 return res;
13079}
13080
13081
13082static int ath_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
13083 struct sigma_conn *conn,
13084 struct sigma_cmd *cmd)
13085{
13086 const char *val;
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053013087 char *token = NULL, *result;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013088
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -070013089 novap_reset(dut, intf, 1);
priyadharshini gowthamane5e25172015-12-08 14:53:48 -080013090
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013091 val = get_param(cmd, "nss_mcs_opt");
13092 if (val) {
13093 /* String (nss_operating_mode; mcs_operating_mode) */
13094 int nss, mcs;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053013095 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013096
13097 token = strdup(val);
13098 if (!token)
13099 return 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053013100 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053013101 if (!result) {
13102 sigma_dut_print(dut, DUT_MSG_ERROR,
13103 "VHT NSS not specified");
13104 goto failed;
13105 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013106 if (strcasecmp(result, "def") != 0) {
13107 nss = atoi(result);
13108 if (nss == 4)
13109 ath_disable_txbf(dut, intf);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070013110 if (run_iwpriv(dut, intf, "nss %d", nss) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013111 goto failed;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070013112
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013113 }
13114
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053013115 result = strtok_r(NULL, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053013116 if (!result) {
13117 sigma_dut_print(dut, DUT_MSG_ERROR,
13118 "VHT MCS not specified");
13119 goto failed;
13120 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013121 if (strcasecmp(result, "def") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070013122 if (run_iwpriv(dut, intf, "set11NRates 0") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013123 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013124 } else {
13125 mcs = atoi(result);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070013126 if (run_iwpriv(dut, intf, "vhtmcs %d", mcs) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013127 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013128 }
13129 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070013130 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013131 }
13132
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053013133 free(token);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013134 return 1;
13135failed:
13136 free(token);
13137 return 0;
13138}
13139
13140
13141static int cmd_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
13142 struct sigma_conn *conn,
13143 struct sigma_cmd *cmd)
13144{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013145 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013146 case DRIVER_ATHEROS:
13147 return ath_sta_set_rfeature_vht(intf, dut, conn, cmd);
13148 default:
13149 send_resp(dut, conn, SIGMA_ERROR,
13150 "errorCode,Unsupported sta_set_rfeature(VHT) with the current driver");
13151 return 0;
13152 }
13153}
13154
13155
Jouni Malinen1702fe32021-06-08 19:08:01 +030013156static enum sigma_cmd_result
13157wcn_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
13158 struct sigma_conn *conn, struct sigma_cmd *cmd)
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080013159{
13160 const char *val;
13161 char *token = NULL, *result;
13162 char buf[60];
13163
13164 val = get_param(cmd, "nss_mcs_opt");
13165 if (val) {
13166 /* String (nss_operating_mode; mcs_operating_mode) */
13167 int nss, mcs, ratecode;
13168 char *saveptr;
13169
13170 token = strdup(val);
13171 if (!token)
Jouni Malinen1702fe32021-06-08 19:08:01 +030013172 return ERROR_SEND_STATUS;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080013173
13174 result = strtok_r(token, ";", &saveptr);
13175 if (!result) {
13176 sigma_dut_print(dut, DUT_MSG_ERROR,
13177 "HE NSS not specified");
13178 goto failed;
13179 }
13180 nss = 1;
13181 if (strcasecmp(result, "def") != 0)
13182 nss = atoi(result);
13183
13184 result = strtok_r(NULL, ";", &saveptr);
13185 if (!result) {
13186 sigma_dut_print(dut, DUT_MSG_ERROR,
13187 "HE MCS not specified");
13188 goto failed;
13189 }
13190 mcs = 7;
13191 if (strcasecmp(result, "def") != 0)
13192 mcs = atoi(result);
13193
Arif Hussain557bf412018-05-25 17:29:36 -070013194 ratecode = 0x20; /* for nss:1 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080013195 if (nss == 2) {
Arif Hussain557bf412018-05-25 17:29:36 -070013196 ratecode = 0x40; /* for nss:2 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080013197 } else if (nss > 2) {
13198 sigma_dut_print(dut, DUT_MSG_ERROR,
13199 "HE NSS %d not supported", nss);
13200 goto failed;
13201 }
13202
Arif Hussain557bf412018-05-25 17:29:36 -070013203 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss);
13204 if (system(buf) != 0) {
13205 sigma_dut_print(dut, DUT_MSG_ERROR,
13206 "nss_mcs_opt: iwpriv %s nss %d failed",
13207 intf, nss);
13208 goto failed;
13209 }
Arif Hussainac6c5112018-05-25 17:34:00 -070013210 dut->sta_nss = nss;
Arif Hussain557bf412018-05-25 17:29:36 -070013211
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080013212 /* Add the MCS to the ratecode */
13213 if (mcs >= 0 && mcs <= 11) {
13214 ratecode += mcs;
Arif Hussain557bf412018-05-25 17:29:36 -070013215#ifdef NL80211_SUPPORT
13216 if (dut->device_type == STA_testbed) {
13217 enum he_mcs_config mcs_config;
13218 int ret;
13219
13220 if (mcs <= 7)
13221 mcs_config = HE_80_MCS0_7;
13222 else if (mcs <= 9)
13223 mcs_config = HE_80_MCS0_9;
13224 else
13225 mcs_config = HE_80_MCS0_11;
13226 ret = sta_set_he_mcs(dut, intf, mcs_config);
13227 if (ret) {
13228 sigma_dut_print(dut, DUT_MSG_ERROR,
13229 "nss_mcs_opt: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
13230 mcs, mcs_config, ret);
13231 goto failed;
13232 }
13233 }
13234#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080013235 } else {
13236 sigma_dut_print(dut, DUT_MSG_ERROR,
13237 "HE MCS %d not supported", mcs);
13238 goto failed;
13239 }
13240 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0x%03x",
13241 intf, ratecode);
13242 if (system(buf) != 0) {
13243 sigma_dut_print(dut, DUT_MSG_ERROR,
13244 "iwpriv setting of 11ax rates failed");
13245 goto failed;
13246 }
13247 free(token);
13248 }
13249
13250 val = get_param(cmd, "GI");
13251 if (val) {
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080013252 int fix_rate_sgi;
13253
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080013254 if (strcmp(val, "0.8") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070013255 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 9", intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080013256 fix_rate_sgi = 1;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080013257 } else if (strcmp(val, "1.6") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070013258 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 10",
13259 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080013260 fix_rate_sgi = 2;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080013261 } else if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070013262 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 11",
13263 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080013264 fix_rate_sgi = 3;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080013265 } else {
13266 send_resp(dut, conn, SIGMA_ERROR,
13267 "errorCode,GI value not supported");
Jouni Malinen1702fe32021-06-08 19:08:01 +030013268 return STATUS_SENT_ERROR;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080013269 }
13270 if (system(buf) != 0) {
13271 send_resp(dut, conn, SIGMA_ERROR,
13272 "errorCode,Failed to set shortgi");
Jouni Malinen1702fe32021-06-08 19:08:01 +030013273 return STATUS_SENT_ERROR;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080013274 }
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080013275 snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d",
13276 intf, fix_rate_sgi);
13277 if (system(buf) != 0) {
13278 send_resp(dut, conn, SIGMA_ERROR,
13279 "errorCode,Failed to set fix rate shortgi");
Jouni Malinen1702fe32021-06-08 19:08:01 +030013280 return STATUS_SENT_ERROR;
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080013281 }
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080013282 }
13283
Subhani Shaik8e7a3052018-04-24 14:03:00 -070013284 val = get_param(cmd, "LTF");
13285 if (val) {
13286#ifdef NL80211_SUPPORT
13287 if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080013288 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_1X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070013289 } if (strcmp(val, "6.4") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080013290 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_2X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070013291 } else if (strcmp(val, "12.8") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080013292 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_4X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070013293 } else {
13294 send_resp(dut, conn, SIGMA_ERROR,
13295 "errorCode, LTF value not supported");
Jouni Malinen1702fe32021-06-08 19:08:01 +030013296 return STATUS_SENT_ERROR;
Subhani Shaik8e7a3052018-04-24 14:03:00 -070013297 }
13298#else /* NL80211_SUPPORT */
13299 sigma_dut_print(dut, DUT_MSG_ERROR,
13300 "LTF cannot be set without NL80211_SUPPORT defined");
Jouni Malinen1702fe32021-06-08 19:08:01 +030013301 return ERROR_SEND_STATUS;
Subhani Shaik8e7a3052018-04-24 14:03:00 -070013302#endif /* NL80211_SUPPORT */
13303 }
13304
Kiran Kumar Lokere1809da12021-06-24 00:45:38 -070013305 val = get_param(cmd, "KeepAlive");
13306 if (val) {
13307 int set_val = QCA_WLAN_KEEP_ALIVE_DEFAULT;
13308
13309 if (strcasecmp(val, "Data") == 0)
13310 set_val = QCA_WLAN_KEEP_ALIVE_DATA;
13311 else if (strcasecmp(val, "Mgmt") == 0)
13312 set_val = QCA_WLAN_KEEP_ALIVE_MGMT;
13313
13314 if (sta_set_keep_alive_data_cfg(dut, intf, set_val)) {
13315 send_resp(dut, conn, SIGMA_ERROR,
13316 "ErrorCode,Failed to set keep alive type config");
13317 return STATUS_SENT_ERROR;
13318 }
13319 }
13320
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -070013321 val = get_param(cmd, "TxSUPPDU");
13322 if (val) {
13323 int set_val = 1;
13324
13325 if (strcasecmp(val, "Enable") == 0)
13326 set_val = 1;
13327 else if (strcasecmp(val, "Disable") == 0)
13328 set_val = 0;
13329
13330 if (sta_set_tx_su_ppdu_cfg(dut, intf, set_val)) {
13331 send_resp(dut, conn, SIGMA_ERROR,
13332 "ErrorCode,Failed to set Tx SU PPDU config");
Jouni Malinen1702fe32021-06-08 19:08:01 +030013333 return STATUS_SENT_ERROR;
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -070013334 }
13335 }
13336
Kiran Kumar Lokere54b72522021-04-01 00:22:44 -070013337 val = get_param(cmd, "Mgmt_Data_TX_Resp_Frame");
13338 if (val) {
13339 int set_val = 0;
13340
13341 if (strcasecmp(val, "Enable") == 0)
13342 set_val = 0;
13343 else if (strcasecmp(val, "Disable") == 0)
13344 set_val = 1;
13345
13346 if (sta_set_mgmt_data_tx_disable_cfg(dut, intf, set_val)) {
13347 send_resp(dut, conn, SIGMA_ERROR,
13348 "ErrorCode,Failed to set mgmt/data Tx disable config");
13349 return STATUS_SENT_ERROR;
13350 }
13351 }
13352
Arif Hussain480d5f42019-03-12 14:40:42 -070013353 val = get_param(cmd, "TWT_Setup");
13354 if (val) {
13355 if (strcasecmp(val, "Request") == 0) {
13356 if (sta_twt_request(dut, conn, cmd)) {
13357 send_resp(dut, conn, SIGMA_ERROR,
Srinivas Girigowda6707f032020-10-26 15:24:46 -070013358 "ErrorCode,TWT setup failed");
Jouni Malinen1702fe32021-06-08 19:08:01 +030013359 return STATUS_SENT_ERROR;
Arif Hussain480d5f42019-03-12 14:40:42 -070013360 }
13361 } else if (strcasecmp(val, "Teardown") == 0) {
13362 if (sta_twt_teardown(dut, conn, cmd)) {
13363 send_resp(dut, conn, SIGMA_ERROR,
Srinivas Girigowda6707f032020-10-26 15:24:46 -070013364 "ErrorCode,TWT teardown failed");
Jouni Malinen1702fe32021-06-08 19:08:01 +030013365 return STATUS_SENT_ERROR;
Arif Hussain480d5f42019-03-12 14:40:42 -070013366 }
13367 }
13368 }
13369
Srinivas Girigowda6707f032020-10-26 15:24:46 -070013370 val = get_param(cmd, "TWT_Operation");
13371 if (val) {
13372 if (strcasecmp(val, "Suspend") == 0) {
13373 if (sta_twt_suspend_or_nudge(dut, conn, cmd)) {
13374 send_resp(dut, conn, SIGMA_ERROR,
13375 "ErrorCode,TWT suspend failed");
13376 return STATUS_SENT_ERROR;
13377 }
13378 } else if (strcasecmp(val, "Resume") == 0) {
13379 if (sta_twt_resume(dut, conn, cmd)) {
13380 send_resp(dut, conn, SIGMA_ERROR,
13381 "ErrorCode,TWT resume failed");
13382 return STATUS_SENT_ERROR;
13383 }
13384 }
13385 }
13386
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -080013387 val = get_param(cmd, "transmitOMI");
13388 if (val && sta_transmit_omi(dut, conn, cmd)) {
13389 send_resp(dut, conn, SIGMA_ERROR,
13390 "ErrorCode,sta_transmit_omi failed");
Jouni Malinen1702fe32021-06-08 19:08:01 +030013391 return STATUS_SENT_ERROR;
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -070013392 }
13393
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080013394 val = get_param(cmd, "Powersave");
13395 if (val) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053013396 int ps;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080013397
13398 if (strcasecmp(val, "off") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053013399 ps = 2;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080013400 } else if (strcasecmp(val, "on") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053013401 ps = 1;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080013402 } else {
13403 sigma_dut_print(dut, DUT_MSG_ERROR,
13404 "Unsupported Powersave value '%s'",
13405 val);
Jouni Malinen1702fe32021-06-08 19:08:01 +030013406 return INVALID_SEND_STATUS;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080013407 }
Vinita S. Malooa8b62722020-04-23 01:45:41 +053013408 if (set_power_save_wcn(dut, intf, ps) < 0)
Jouni Malinen1702fe32021-06-08 19:08:01 +030013409 return ERROR_SEND_STATUS;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080013410 }
13411
Kiran Kumar Lokere2c4b7ce2019-01-30 12:02:28 -080013412 val = get_param(cmd, "MU_EDCA");
13413 if (val) {
13414 if (strcasecmp(val, "Override") == 0) {
13415 if (sta_set_mu_edca_override(dut, intf, 1)) {
13416 send_resp(dut, conn, SIGMA_ERROR,
13417 "errorCode,MU EDCA override set failed");
13418 return STATUS_SENT;
13419 }
13420 } else if (strcasecmp(val, "Disable") == 0) {
13421 if (sta_set_mu_edca_override(dut, intf, 0)) {
13422 send_resp(dut, conn, SIGMA_ERROR,
13423 "errorCode,MU EDCA override disable failed");
13424 return STATUS_SENT;
13425 }
13426 }
13427 }
13428
Kiran Kumar Lokerefa7c7b92021-08-09 00:50:55 -070013429 val = get_param(cmd, "RUAllocTone");
13430 if (val && strcasecmp(val, "242") == 0) {
13431 if (sta_set_ru_242_tone_tx(dut, intf, 1)) {
13432 send_resp(dut, conn, SIGMA_ERROR,
13433 "ErrorCode,Failed to set RU 242 tone Tx");
13434 return STATUS_SENT_ERROR;
13435 }
13436 }
13437
13438 val = get_param(cmd, "PPDUTxType");
13439 if (val && strcasecmp(val, "ER-SU") == 0) {
13440 if (sta_set_er_su_ppdu_type_tx(dut, intf, 1)) {
13441 send_resp(dut, conn, SIGMA_ERROR,
13442 "ErrorCode,Failed to set ER-SU PPDU type Tx");
13443 return STATUS_SENT_ERROR;
13444 }
13445 }
13446
Kiran Kumar Lokeredd086642020-06-04 00:29:26 -070013447 val = get_param(cmd, "Ch_Pref");
13448 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
13449 return STATUS_SENT;
13450
13451 val = get_param(cmd, "Cellular_Data_Cap");
13452 if (val && mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
13453 return STATUS_SENT;
13454
Jouni Malinen1702fe32021-06-08 19:08:01 +030013455 return SUCCESS_SEND_STATUS;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080013456
13457failed:
13458 free(token);
Jouni Malinen1702fe32021-06-08 19:08:01 +030013459 return ERROR_SEND_STATUS;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080013460}
13461
13462
Jouni Malinen1702fe32021-06-08 19:08:01 +030013463static enum sigma_cmd_result
13464cmd_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
13465 struct sigma_conn *conn, struct sigma_cmd *cmd)
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080013466{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013467 switch (get_driver_type(dut)) {
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080013468 case DRIVER_WCN:
13469 return wcn_sta_set_rfeature_he(intf, dut, conn, cmd);
13470 default:
13471 send_resp(dut, conn, SIGMA_ERROR,
13472 "errorCode,Unsupported sta_set_rfeature(HE) with the current driver");
Jouni Malinen1702fe32021-06-08 19:08:01 +030013473 return STATUS_SENT_ERROR;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080013474 }
13475}
13476
13477
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080013478static int cmd_sta_set_power_save_he(const char *intf, struct sigma_dut *dut,
13479 struct sigma_conn *conn,
13480 struct sigma_cmd *cmd)
13481{
13482 const char *val;
13483
13484 val = get_param(cmd, "powersave");
13485 if (val) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053013486 int ps;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080013487
13488 if (strcasecmp(val, "off") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053013489 ps = 2;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080013490 } else if (strcasecmp(val, "on") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053013491 ps = 1;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080013492 } else {
13493 sigma_dut_print(dut, DUT_MSG_ERROR,
13494 "Unsupported power save config");
13495 return -1;
13496 }
Vinita S. Malooa8b62722020-04-23 01:45:41 +053013497 if (set_power_save_wcn(dut, intf, ps) < 0)
13498 return 0;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080013499 return 1;
13500 }
13501
13502 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported command");
13503
13504 return 0;
13505}
13506
13507
Ashwini Patil5acd7382017-04-13 15:55:04 +053013508static int btm_query_candidate_list(struct sigma_dut *dut,
13509 struct sigma_conn *conn,
13510 struct sigma_cmd *cmd)
13511{
13512 const char *bssid, *info, *op_class, *ch, *phy_type, *pref;
13513 int len, ret;
13514 char buf[10];
13515
13516 /*
13517 * Neighbor Report elements format:
13518 * neighbor=<BSSID>,<BSSID Information>,<Operating Class>,
13519 * <Channel Number>,<PHY Type>[,<hexdump of Optional Subelements>]
13520 * eg: neighbor=aa:bb:cc:dd:ee:ff,17,81,6,1,030101
13521 */
13522
13523 bssid = get_param(cmd, "Nebor_BSSID");
13524 if (!bssid) {
13525 send_resp(dut, conn, SIGMA_INVALID,
13526 "errorCode,Nebor_BSSID is missing");
13527 return 0;
13528 }
13529
13530 info = get_param(cmd, "Nebor_Bssid_Info");
13531 if (!info) {
13532 sigma_dut_print(dut, DUT_MSG_INFO,
13533 "Using default value for Nebor_Bssid_Info: %s",
13534 DEFAULT_NEIGHBOR_BSSID_INFO);
13535 info = DEFAULT_NEIGHBOR_BSSID_INFO;
13536 }
13537
13538 op_class = get_param(cmd, "Nebor_Op_Class");
13539 if (!op_class) {
13540 send_resp(dut, conn, SIGMA_INVALID,
13541 "errorCode,Nebor_Op_Class is missing");
13542 return 0;
13543 }
13544
13545 ch = get_param(cmd, "Nebor_Op_Ch");
13546 if (!ch) {
13547 send_resp(dut, conn, SIGMA_INVALID,
13548 "errorCode,Nebor_Op_Ch is missing");
13549 return 0;
13550 }
13551
13552 phy_type = get_param(cmd, "Nebor_Phy_Type");
13553 if (!phy_type) {
13554 sigma_dut_print(dut, DUT_MSG_INFO,
13555 "Using default value for Nebor_Phy_Type: %s",
13556 DEFAULT_NEIGHBOR_PHY_TYPE);
13557 phy_type = DEFAULT_NEIGHBOR_PHY_TYPE;
13558 }
13559
13560 /* Parse optional subelements */
13561 buf[0] = '\0';
13562 pref = get_param(cmd, "Nebor_Pref");
13563 if (pref) {
13564 /* hexdump for preferrence subelement */
13565 ret = snprintf(buf, sizeof(buf), ",0301%02x", atoi(pref));
13566 if (ret < 0 || ret >= (int) sizeof(buf)) {
13567 sigma_dut_print(dut, DUT_MSG_ERROR,
13568 "snprintf failed for optional subelement ret: %d",
13569 ret);
13570 send_resp(dut, conn, SIGMA_ERROR,
13571 "errorCode,snprintf failed for subelement");
13572 return 0;
13573 }
13574 }
13575
13576 if (!dut->btm_query_cand_list) {
13577 dut->btm_query_cand_list = calloc(1, NEIGHBOR_REPORT_SIZE);
13578 if (!dut->btm_query_cand_list) {
13579 send_resp(dut, conn, SIGMA_ERROR,
13580 "errorCode,Failed to allocate memory for btm_query_cand_list");
13581 return 0;
13582 }
13583 }
13584
13585 len = strlen(dut->btm_query_cand_list);
13586 ret = snprintf(dut->btm_query_cand_list + len,
13587 NEIGHBOR_REPORT_SIZE - len, " neighbor=%s,%s,%s,%s,%s%s",
13588 bssid, info, op_class, ch, phy_type, buf);
13589 if (ret < 0 || ret >= NEIGHBOR_REPORT_SIZE - len) {
13590 sigma_dut_print(dut, DUT_MSG_ERROR,
13591 "snprintf failed for neighbor report list ret: %d",
13592 ret);
13593 send_resp(dut, conn, SIGMA_ERROR,
13594 "errorCode,snprintf failed for neighbor report");
13595 free(dut->btm_query_cand_list);
13596 dut->btm_query_cand_list = NULL;
13597 return 0;
13598 }
13599
13600 return 1;
13601}
13602
13603
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020013604int sta_extract_60g_ese(struct sigma_dut *dut, struct sigma_cmd *cmd,
13605 struct sigma_ese_alloc *allocs, int *allocs_size)
13606{
13607 int max_count = *allocs_size;
13608 int count = 0, i;
13609 const char *val;
13610
13611 do {
13612 val = get_param_indexed(cmd, "AllocID", count);
13613 if (val)
13614 count++;
13615 } while (val);
13616
13617 if (count == 0 || count > max_count) {
13618 sigma_dut_print(dut, DUT_MSG_ERROR,
13619 "Invalid number of allocations(%d)", count);
13620 return -1;
13621 }
13622
13623 for (i = 0; i < count; i++) {
13624 val = get_param_indexed(cmd, "PercentBI", i);
13625 if (!val) {
13626 sigma_dut_print(dut, DUT_MSG_ERROR,
13627 "Missing PercentBI parameter at index %d",
13628 i);
13629 return -1;
13630 }
13631 allocs[i].percent_bi = atoi(val);
13632
13633 val = get_param_indexed(cmd, "SrcAID", i);
13634 if (val)
13635 allocs[i].src_aid = strtol(val, NULL, 0);
13636 else
13637 allocs[i].src_aid = ESE_BCAST_AID;
13638
13639 val = get_param_indexed(cmd, "DestAID", i);
13640 if (val)
13641 allocs[i].dst_aid = strtol(val, NULL, 0);
13642 else
13643 allocs[i].dst_aid = ESE_BCAST_AID;
13644
13645 allocs[i].type = ESE_CBAP;
13646 sigma_dut_print(dut, DUT_MSG_INFO,
13647 "Alloc %d PercentBI %d SrcAID %d DstAID %d",
13648 i, allocs[i].percent_bi, allocs[i].src_aid,
13649 allocs[i].dst_aid);
13650 }
13651
13652 *allocs_size = count;
13653 return 0;
13654}
13655
13656
13657static int sta_set_60g_ese(struct sigma_dut *dut, int count,
13658 struct sigma_ese_alloc *allocs)
13659{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013660 switch (get_driver_type(dut)) {
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020013661#ifdef __linux__
13662 case DRIVER_WIL6210:
13663 if (wil6210_set_ese(dut, count, allocs))
13664 return -1;
13665 return 1;
13666#endif /* __linux__ */
13667 default:
13668 sigma_dut_print(dut, DUT_MSG_ERROR,
13669 "Unsupported sta_set_60g_ese with the current driver");
13670 return -1;
13671 }
13672}
13673
13674
13675static int cmd_sta_set_rfeature_60g(const char *intf, struct sigma_dut *dut,
13676 struct sigma_conn *conn,
13677 struct sigma_cmd *cmd)
13678{
13679 const char *val;
13680
13681 val = get_param(cmd, "ExtSchIE");
13682 if (val && !strcasecmp(val, "Enable")) {
13683 struct sigma_ese_alloc allocs[MAX_ESE_ALLOCS];
13684 int count = MAX_ESE_ALLOCS;
13685
13686 if (sta_extract_60g_ese(dut, cmd, allocs, &count))
13687 return -1;
13688 return sta_set_60g_ese(dut, count, allocs);
13689 }
13690
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020013691 val = get_param(cmd, "MCS_FixedRate");
13692 if (val) {
13693 int sta_mcs = atoi(val);
13694
13695 sigma_dut_print(dut, DUT_MSG_INFO, "Force STA MCS to %d",
13696 sta_mcs);
13697 wil6210_set_force_mcs(dut, 1, sta_mcs);
13698
Jouni Malinen0e29cf22019-02-19 01:13:21 +020013699 return SUCCESS_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020013700 }
13701
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020013702 send_resp(dut, conn, SIGMA_ERROR,
13703 "errorCode,Invalid sta_set_rfeature(60G)");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020013704 return STATUS_SENT;
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020013705}
13706
13707
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053013708static int wcn_sta_override_oci(struct sigma_dut *dut, const char *intf,
13709 const char *oci_frametype, uint32_t oci_freq)
13710{
13711#ifdef NL80211_SUPPORT
13712 struct nl_msg *msg;
13713 int ret = 0;
13714 struct nlattr *params;
13715 struct nlattr *attr;
13716 int ifindex;
13717 u8 frame_type;
13718
13719 ifindex = if_nametoindex(intf);
13720 if (ifindex == 0) {
13721 sigma_dut_print(dut, DUT_MSG_ERROR,
13722 "%s: Index for interface %s failed",
13723 __func__, intf);
13724 return -1;
13725 }
13726
13727 if (strcasecmp(oci_frametype, "SAQueryReq") == 0) {
13728 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_SA_QUERY_REQ;
13729 } else if (strcasecmp(oci_frametype, "SAQueryResp") == 0) {
13730 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_SA_QUERY_RESP;
13731 } else if (strcasecmp(oci_frametype, "Reassocreq") == 0) {
13732 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_FT_REASSOC_REQ;
13733 } else {
13734 sigma_dut_print(dut, DUT_MSG_ERROR, "%s: Unknown frametype %s",
13735 __func__, oci_frametype);
13736 return -1;
13737 }
13738
13739
13740 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
13741 NL80211_CMD_VENDOR)) ||
13742 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
13743 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
13744 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
13745 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
13746 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
13747 !(params = nla_nest_start(
13748 msg,
13749 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_OCI_OVERRIDE)) ||
13750 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_OCI_OVERRIDE_FRAME_TYPE,
13751 frame_type) ||
13752 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_OCI_OVERRIDE_FREQUENCY,
13753 oci_freq)) {
13754 sigma_dut_print(dut, DUT_MSG_ERROR,
13755 "%s: err in adding vendor_cmd and vendor_data",
13756 __func__);
13757 nlmsg_free(msg);
13758 return -1;
13759 }
13760 nla_nest_end(msg, params);
13761 nla_nest_end(msg, attr);
13762
13763 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
13764 if (ret) {
13765 sigma_dut_print(dut, DUT_MSG_ERROR,
13766 "%s: err in send_and_recv_msgs, ret=%d",
13767 __func__, ret);
13768 }
13769 return ret;
13770#else /* NL80211_SUPPORT */
13771 sigma_dut_print(dut, DUT_MSG_ERROR,
13772 "OCI override not possible without NL80211_SUPPORT defined");
13773 return -1;
13774#endif /* NL80211_SUPPORT */
13775}
13776
13777
Veerendranath Jakkam50d5c782020-07-22 01:59:01 +053013778static int wcn_sta_ignore_csa(struct sigma_dut *dut, const char *intf,
13779 uint8_t ignore_csa)
13780{
13781#ifdef NL80211_SUPPORT
13782 return wcn_wifi_test_config_set_u8(
13783 dut, intf,
13784 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_IGNORE_CSA, ignore_csa);
13785#else /* NL80211_SUPPORT */
13786 sigma_dut_print(dut, DUT_MSG_ERROR,
13787 "IgnoreCSA can't be set without NL80211_SUPPORT defined");
13788 return -1;
13789#endif /* NL80211_SUPPORT */
13790}
13791
13792
Veerendranath Jakkamc771fac2020-07-22 01:32:56 +053013793static int wcn_sta_set_rsnxe_used(struct sigma_dut *dut, const char *intf,
13794 uint8_t rsnxe_used)
13795{
13796#ifdef NL80211_SUPPORT
13797 return wcn_wifi_test_config_set_u8(
13798 dut, intf,
13799 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_FT_REASSOCREQ_RSNXE_USED,
13800 rsnxe_used);
13801#else /* NL80211_SUPPORT */
13802 sigma_dut_print(dut, DUT_MSG_ERROR,
13803 "RSNXE_Used can't be set without NL80211_SUPPORT defined");
13804 return -1;
13805#endif /* NL80211_SUPPORT */
13806}
13807
13808
Veerendranath Jakkam1e1e5fd2020-09-10 07:12:37 +053013809static int wcn_sta_ignore_sa_query_timeout(struct sigma_dut *dut,
13810 const char *intf,
13811 uint8_t ignore_sa_query_timeout)
13812{
13813#ifdef NL80211_SUPPORT
13814 return wcn_wifi_test_config_set_u8(
13815 dut, intf,
13816 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_IGNORE_SA_QUERY_TIMEOUT,
13817 ignore_sa_query_timeout);
13818#else /* NL80211_SUPPORT */
13819 sigma_dut_print(dut, DUT_MSG_ERROR,
13820 "Ignore SA Query timeout can't be set without NL80211_SUPPORT defined");
13821 return -1;
13822#endif /* NL80211_SUPPORT */
13823}
13824
13825
Jouni Malinen6250cb02020-04-15 13:54:45 +030013826static enum sigma_cmd_result
13827cmd_sta_set_rfeature_wpa3(const char *intf, struct sigma_dut *dut,
13828 struct sigma_conn *conn,
13829 struct sigma_cmd *cmd)
13830{
Vamsi Krishnad29bc762020-05-08 23:23:30 +053013831 const char *val, *oci_chan, *oci_frametype;
Jouni Malinen6250cb02020-04-15 13:54:45 +030013832
Veerendranath Jakkam30bf9072020-04-16 14:37:57 +053013833 val = get_param(cmd, "ReassocReq_RSNXE_Used");
Jouni Malinen6250cb02020-04-15 13:54:45 +030013834 if (val && atoi(val) == 1) {
Veerendranath Jakkamc771fac2020-07-22 01:32:56 +053013835 if (wifi_chip_type == DRIVER_WCN) {
13836 if (wcn_sta_set_rsnxe_used(dut, intf, 1)) {
13837 send_resp(dut, conn, SIGMA_ERROR,
13838 "errorCode,Failed to set ft_rsnxe_used");
13839 return STATUS_SENT_ERROR;
13840 }
13841 return SUCCESS_SEND_STATUS;
13842 } else if (wpa_command(intf, "SET ft_rsnxe_used 1") < 0) {
Jouni Malinen6250cb02020-04-15 13:54:45 +030013843 send_resp(dut, conn, SIGMA_ERROR,
13844 "errorCode,Failed to set ft_rsnxe_used");
13845 return STATUS_SENT_ERROR;
13846 }
13847 return SUCCESS_SEND_STATUS;
13848 }
Vamsi Krishnad29bc762020-05-08 23:23:30 +053013849
13850 oci_chan = get_param(cmd, "OCIChannel");
13851 oci_frametype = get_param(cmd, "OCIFrameType");
13852 if (oci_chan && oci_frametype) {
13853 unsigned int oci_freq = channel_to_freq(dut, atoi(oci_chan));
13854 char buf[100];
13855
13856 if (!oci_freq) {
13857 send_resp(dut, conn, SIGMA_ERROR,
13858 "errorCode,Invalid OCIChannel number");
13859 return STATUS_SENT_ERROR;
13860 }
13861
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053013862 if (wifi_chip_type == DRIVER_WCN &&
13863 (strcasecmp(oci_frametype, "SAQueryReq") == 0 ||
13864 strcasecmp(oci_frametype, "SAQueryResp") == 0 ||
13865 strcasecmp(oci_frametype, "Reassocreq") == 0)) {
13866 if (wcn_sta_override_oci(dut, intf, oci_frametype,
13867 oci_freq)) {
13868 send_resp(dut, conn, SIGMA_ERROR,
13869 "errorCode,Failed to override OCI");
13870 return STATUS_SENT_ERROR;
13871 }
13872 return SUCCESS_SEND_STATUS;
13873 }
13874
Vamsi Krishnad29bc762020-05-08 23:23:30 +053013875 if (strcasecmp(oci_frametype, "eapolM2") == 0) {
13876 snprintf(buf, sizeof(buf),
13877 "SET oci_freq_override_eapol %d", oci_freq);
13878 } else if (strcasecmp(oci_frametype, "SAQueryReq") == 0) {
13879 snprintf(buf, sizeof(buf),
13880 "SET oci_freq_override_saquery_req %d",
13881 oci_freq);
13882 } else if (strcasecmp(oci_frametype, "SAQueryResp") == 0) {
13883 snprintf(buf, sizeof(buf),
13884 "SET oci_freq_override_saquery_resp %d",
13885 oci_freq);
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053013886 } else if (strcasecmp(oci_frametype, "GrpKeyM2") == 0) {
13887 snprintf(buf, sizeof(buf),
13888 "SET oci_freq_override_eapol_g2 %d",
13889 oci_freq);
13890 } else if (strcasecmp(oci_frametype, "Reassocreq") == 0) {
13891 snprintf(buf, sizeof(buf),
13892 "SET oci_freq_override_ft_assoc %d",
13893 oci_freq);
Vamsi Krishnad29bc762020-05-08 23:23:30 +053013894 } else {
13895 send_resp(dut, conn, SIGMA_ERROR,
13896 "errorCode,Unsupported OCIFrameType");
13897 return STATUS_SENT_ERROR;
13898 }
13899 if (wpa_command(intf, buf) < 0) {
13900 send_resp(dut, conn, SIGMA_ERROR,
13901 "errorCode,Failed to set oci_freq_override");
13902 return STATUS_SENT_ERROR;
13903 }
13904 return SUCCESS_SEND_STATUS;
13905 }
13906
Veerendranath Jakkam50d5c782020-07-22 01:59:01 +053013907 val = get_param(cmd, "IgnoreCSA");
13908 if (val && atoi(val) == 1) {
13909 if (wifi_chip_type == DRIVER_WCN) {
13910 if (wcn_sta_ignore_csa(dut, intf, 1)) {
13911 send_resp(dut, conn, SIGMA_ERROR,
13912 "errorCode,Failed to set ignore CSA");
13913 return STATUS_SENT_ERROR;
13914 }
13915 return SUCCESS_SEND_STATUS;
13916 }
13917 }
13918
Veerendranath Jakkam1e1e5fd2020-09-10 07:12:37 +053013919 val = get_param(cmd, "Deauth_Per_SAQueryResp");
13920 if (val && atoi(val) == 0) {
13921 if (wifi_chip_type == DRIVER_WCN) {
13922 if (wcn_sta_ignore_sa_query_timeout(dut, intf, 1)) {
13923 send_resp(dut, conn, SIGMA_ERROR,
13924 "errorCode,Failed to set ignore SA Query timeout");
13925 return STATUS_SENT_ERROR;
13926 }
13927 return SUCCESS_SEND_STATUS;
13928 }
13929 }
13930
Jouni Malinen6250cb02020-04-15 13:54:45 +030013931 send_resp(dut, conn, SIGMA_ERROR,
13932 "errorCode,Unsupported WPA3 rfeature");
13933 return STATUS_SENT_ERROR;
13934}
13935
13936
Jouni Malinenf7222712019-06-13 01:50:21 +030013937static enum sigma_cmd_result cmd_sta_set_rfeature(struct sigma_dut *dut,
13938 struct sigma_conn *conn,
13939 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013940{
13941 const char *intf = get_param(cmd, "Interface");
13942 const char *prog = get_param(cmd, "Prog");
Ashwini Patil68d02cd2017-01-10 15:39:16 +053013943 const char *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013944
13945 if (intf == NULL || prog == NULL)
13946 return -1;
13947
Ashwini Patil5acd7382017-04-13 15:55:04 +053013948 /* BSS Transition candidate list for BTM query */
13949 val = get_param(cmd, "Nebor_BSSID");
13950 if (val && btm_query_candidate_list(dut, conn, cmd) == 0)
13951 return 0;
13952
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013953 if (strcasecmp(prog, "TDLS") == 0)
13954 return cmd_sta_set_rfeature_tdls(intf, dut, conn, cmd);
13955
13956 if (strcasecmp(prog, "VHT") == 0)
13957 return cmd_sta_set_rfeature_vht(intf, dut, conn, cmd);
13958
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080013959 if (strcasecmp(prog, "HE") == 0)
13960 return cmd_sta_set_rfeature_he(intf, dut, conn, cmd);
13961
Ashwini Patil68d02cd2017-01-10 15:39:16 +053013962 if (strcasecmp(prog, "MBO") == 0) {
13963 val = get_param(cmd, "Cellular_Data_Cap");
13964 if (val &&
13965 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
13966 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +053013967
13968 val = get_param(cmd, "Ch_Pref");
13969 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
13970 return 0;
13971
Ashwini Patil68d02cd2017-01-10 15:39:16 +053013972 return 1;
13973 }
13974
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020013975 if (strcasecmp(prog, "60GHz") == 0)
13976 return cmd_sta_set_rfeature_60g(intf, dut, conn, cmd);
13977
Jouni Malinen6250cb02020-04-15 13:54:45 +030013978 if (strcasecmp(prog, "WPA3") == 0)
13979 return cmd_sta_set_rfeature_wpa3(intf, dut, conn, cmd);
13980
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013981 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported Prog");
13982 return 0;
13983}
13984
13985
Jouni Malinenf7222712019-06-13 01:50:21 +030013986static enum sigma_cmd_result cmd_sta_set_radio(struct sigma_dut *dut,
13987 struct sigma_conn *conn,
13988 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013989{
13990 const char *intf = get_param(cmd, "Interface");
13991 const char *mode = get_param(cmd, "Mode");
13992 int res;
13993
13994 if (intf == NULL || mode == NULL)
13995 return -1;
13996
13997 if (strcasecmp(mode, "On") == 0)
13998 res = wpa_command(intf, "SET radio_disabled 0");
13999 else if (strcasecmp(mode, "Off") == 0)
14000 res = wpa_command(intf, "SET radio_disabled 1");
14001 else
14002 return -1;
14003
14004 if (res) {
14005 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
14006 "radio mode");
14007 return 0;
14008 }
14009
14010 return 1;
14011}
14012
14013
Jouni Malinenf7222712019-06-13 01:50:21 +030014014static enum sigma_cmd_result cmd_sta_set_pwrsave(struct sigma_dut *dut,
14015 struct sigma_conn *conn,
14016 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014017{
14018 const char *intf = get_param(cmd, "Interface");
14019 const char *mode = get_param(cmd, "Mode");
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020014020 const char *prog = get_param(cmd, "program");
14021 const char *powersave = get_param(cmd, "powersave");
14022 int res = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014023
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020014024 if (intf == NULL)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014025 return -1;
14026
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020014027 if (prog && strcasecmp(prog, "60GHz") == 0) {
14028 /*
14029 * The CAPI mode parameter does not exist in 60G
14030 * unscheduled PS.
14031 */
Hu Wang5dc3ff12019-06-14 15:14:26 +080014032 if (powersave && strcasecmp(powersave, "unscheduled") == 0)
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020014033 res = set_ps(intf, dut, 1);
Jouni Malinen016ae6c2019-11-04 17:00:01 +020014034 } else if (prog && get_driver_type(dut) == DRIVER_WCN &&
Alexei Avshalom Lazar2f6fdb42019-02-04 14:16:08 +020014035 strcasecmp(prog, "HE") == 0) {
14036 return cmd_sta_set_power_save_he(intf, dut, conn, cmd);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020014037 } else {
14038 if (mode == NULL)
14039 return -1;
14040
14041 if (strcasecmp(mode, "On") == 0)
14042 res = set_ps(intf, dut, 1);
14043 else if (strcasecmp(mode, "Off") == 0)
14044 res = set_ps(intf, dut, 0);
14045 else
14046 return -1;
14047 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014048
14049 if (res) {
14050 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
14051 "power save mode");
14052 return 0;
14053 }
14054
14055 return 1;
14056}
14057
14058
Jouni Malinenf7222712019-06-13 01:50:21 +030014059static enum sigma_cmd_result cmd_sta_bssid_pool(struct sigma_dut *dut,
14060 struct sigma_conn *conn,
14061 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014062{
14063 const char *intf = get_param(cmd, "Interface");
14064 const char *val, *bssid;
14065 int res;
14066 char *buf;
14067 size_t buf_len;
14068
14069 val = get_param(cmd, "BSSID_FILTER");
14070 if (val == NULL)
14071 return -1;
14072
14073 bssid = get_param(cmd, "BSSID_List");
14074 if (atoi(val) == 0 || bssid == NULL) {
14075 /* Disable BSSID filter */
14076 if (wpa_command(intf, "SET bssid_filter ")) {
14077 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed "
14078 "to disable BSSID filter");
14079 return 0;
14080 }
14081
14082 return 1;
14083 }
14084
14085 buf_len = 100 + strlen(bssid);
14086 buf = malloc(buf_len);
14087 if (buf == NULL)
14088 return -1;
14089
14090 snprintf(buf, buf_len, "SET bssid_filter %s", bssid);
14091 res = wpa_command(intf, buf);
14092 free(buf);
14093 if (res) {
14094 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to enable "
14095 "BSSID filter");
14096 return 0;
14097 }
14098
14099 return 1;
14100}
14101
14102
Jouni Malinenf7222712019-06-13 01:50:21 +030014103static enum sigma_cmd_result cmd_sta_reset_parm(struct sigma_dut *dut,
14104 struct sigma_conn *conn,
14105 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014106{
14107 const char *intf = get_param(cmd, "Interface");
14108 const char *val;
14109
14110 /* TODO: ARP */
14111
14112 val = get_param(cmd, "HS2_CACHE_PROFILE");
14113 if (val && strcasecmp(val, "All") == 0)
14114 hs2_clear_credentials(intf);
14115
14116 return 1;
14117}
14118
14119
Jouni Malinenf7222712019-06-13 01:50:21 +030014120static enum sigma_cmd_result cmd_sta_get_key(struct sigma_dut *dut,
14121 struct sigma_conn *conn,
14122 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014123{
14124 const char *intf = get_param(cmd, "Interface");
14125 const char *key_type = get_param(cmd, "KeyType");
14126 char buf[100], resp[200];
14127
14128 if (key_type == NULL)
14129 return -1;
14130
14131 if (strcasecmp(key_type, "GTK") == 0) {
14132 if (wpa_command_resp(intf, "GET gtk", buf, sizeof(buf)) < 0 ||
14133 strncmp(buf, "FAIL", 4) == 0) {
14134 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
14135 "not fetch current GTK");
14136 return 0;
14137 }
14138 snprintf(resp, sizeof(resp), "KeyValue,%s", buf);
14139 send_resp(dut, conn, SIGMA_COMPLETE, resp);
14140 return 0;
14141 } else {
14142 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
14143 "KeyType");
14144 return 0;
14145 }
14146
14147 return 1;
14148}
14149
14150
14151static int hs2_set_policy(struct sigma_dut *dut)
14152{
14153#ifdef ANDROID
14154 system("ip rule del prio 23000");
14155 if (system("ip rule add from all lookup main prio 23000") != 0) {
14156 sigma_dut_print(dut, DUT_MSG_ERROR,
14157 "Failed to run:ip rule add from all lookup main prio");
14158 return -1;
14159 }
14160 if (system("ip route flush cache") != 0) {
14161 sigma_dut_print(dut, DUT_MSG_ERROR,
14162 "Failed to run ip route flush cache");
14163 return -1;
14164 }
14165 return 1;
14166#else /* ANDROID */
14167 return 0;
14168#endif /* ANDROID */
14169}
14170
14171
Jouni Malinenf7222712019-06-13 01:50:21 +030014172static enum sigma_cmd_result cmd_sta_hs2_associate(struct sigma_dut *dut,
14173 struct sigma_conn *conn,
14174 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014175{
14176 const char *intf = get_param(cmd, "Interface");
14177 const char *val = get_param(cmd, "Ignore_blacklist");
Jouni Malinen439352d2018-09-13 03:42:23 +030014178 const char *band = get_param(cmd, "Band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014179 struct wpa_ctrl *ctrl;
Jouni Malinen3aa72862019-05-29 23:14:51 +030014180 int res, r;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014181 char bssid[20], ssid[40], resp[100], buf[100], blacklisted[100];
14182 int tries = 0;
14183 int ignore_blacklist = 0;
14184 const char *events[] = {
14185 "CTRL-EVENT-CONNECTED",
14186 "INTERWORKING-BLACKLISTED",
14187 "INTERWORKING-NO-MATCH",
14188 NULL
14189 };
14190
14191 start_sta_mode(dut);
14192
Jouni Malinen439352d2018-09-13 03:42:23 +030014193 if (band) {
14194 if (strcmp(band, "2.4") == 0) {
14195 wpa_command(intf, "SET setband 2G");
14196 } else if (strcmp(band, "5") == 0) {
14197 wpa_command(intf, "SET setband 5G");
14198 } else {
14199 send_resp(dut, conn, SIGMA_ERROR,
14200 "errorCode,Unsupported band");
14201 return 0;
14202 }
14203 }
14204
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014205 blacklisted[0] = '\0';
14206 if (val && atoi(val))
14207 ignore_blacklist = 1;
14208
14209try_again:
14210 ctrl = open_wpa_mon(intf);
14211 if (ctrl == NULL) {
14212 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
14213 "wpa_supplicant monitor connection");
14214 return -2;
14215 }
14216
14217 tries++;
14218 if (wpa_command(intf, "INTERWORKING_SELECT auto")) {
14219 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start "
14220 "Interworking connection");
14221 wpa_ctrl_detach(ctrl);
14222 wpa_ctrl_close(ctrl);
14223 return 0;
14224 }
14225
14226 buf[0] = '\0';
14227 while (1) {
14228 char *pos;
14229 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
14230 pos = strstr(buf, "INTERWORKING-BLACKLISTED");
14231 if (!pos)
14232 break;
14233 pos += 25;
14234 sigma_dut_print(dut, DUT_MSG_DEBUG, "Found blacklisted AP: %s",
14235 pos);
14236 if (!blacklisted[0])
14237 memcpy(blacklisted, pos, strlen(pos) + 1);
14238 }
14239
14240 if (ignore_blacklist && blacklisted[0]) {
14241 char *end;
14242 end = strchr(blacklisted, ' ');
14243 if (end)
14244 *end = '\0';
14245 sigma_dut_print(dut, DUT_MSG_DEBUG, "Try to connect to a blacklisted network: %s",
14246 blacklisted);
Jouni Malinen3aa72862019-05-29 23:14:51 +030014247 r = snprintf(buf, sizeof(buf), "INTERWORKING_CONNECT %s",
14248 blacklisted);
14249 if (r < 0 || r >= sizeof(buf) || wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014250 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start Interworking connection to blacklisted network");
14251 wpa_ctrl_detach(ctrl);
14252 wpa_ctrl_close(ctrl);
14253 return 0;
14254 }
14255 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
14256 buf, sizeof(buf));
14257 }
14258
14259 wpa_ctrl_detach(ctrl);
14260 wpa_ctrl_close(ctrl);
14261
14262 if (res < 0) {
14263 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
14264 "connect");
14265 return 0;
14266 }
14267
14268 if (strstr(buf, "INTERWORKING-NO-MATCH") ||
14269 strstr(buf, "INTERWORKING-BLACKLISTED")) {
14270 if (tries < 2) {
14271 sigma_dut_print(dut, DUT_MSG_INFO, "No match found - try again to verify no APs were missed in the scan");
14272 goto try_again;
14273 }
14274 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,No network with "
14275 "matching credentials found");
14276 return 0;
14277 }
14278
14279 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
14280 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
14281 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
14282 "get current BSSID/SSID");
14283 return 0;
14284 }
14285
14286 snprintf(resp, sizeof(resp), "SSID,%s,BSSID,%s", ssid, bssid);
14287 send_resp(dut, conn, SIGMA_COMPLETE, resp);
14288 hs2_set_policy(dut);
14289 return 0;
14290}
14291
14292
Jouni Malinenf7222712019-06-13 01:50:21 +030014293static enum sigma_cmd_result cmd_sta_hs2_venue_info(struct sigma_dut *dut,
14294 struct sigma_conn *conn,
14295 struct sigma_cmd *cmd)
Jouni Malinenb639f1c2018-09-13 02:39:46 +030014296{
14297 const char *intf = get_param(cmd, "Interface");
14298 const char *display = get_param(cmd, "Display");
14299 struct wpa_ctrl *ctrl;
14300 char buf[300], params[400], *pos;
14301 char bssid[20];
14302 int info_avail = 0;
14303 unsigned int old_timeout;
14304 int res;
14305
14306 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
14307 send_resp(dut, conn, SIGMA_ERROR,
14308 "ErrorCode,Could not get current BSSID");
14309 return 0;
14310 }
14311 ctrl = open_wpa_mon(intf);
14312 if (!ctrl) {
14313 sigma_dut_print(dut, DUT_MSG_ERROR,
14314 "Failed to open wpa_supplicant monitor connection");
14315 return -2;
14316 }
14317
14318 snprintf(buf, sizeof(buf), "ANQP_GET %s 277", bssid);
14319 wpa_command(intf, buf);
14320
14321 res = get_wpa_cli_event(dut, ctrl, "GAS-QUERY-DONE", buf, sizeof(buf));
14322 if (res < 0) {
14323 send_resp(dut, conn, SIGMA_ERROR,
14324 "ErrorCode,Could not complete GAS query");
14325 goto fail;
14326 }
14327
14328 old_timeout = dut->default_timeout;
14329 dut->default_timeout = 2;
14330 res = get_wpa_cli_event(dut, ctrl, "RX-VENUE-URL", buf, sizeof(buf));
14331 dut->default_timeout = old_timeout;
14332 if (res < 0)
14333 goto done;
14334 pos = strchr(buf, ' ');
14335 if (!pos)
14336 goto done;
14337 pos++;
14338 pos = strchr(pos, ' ');
14339 if (!pos)
14340 goto done;
14341 pos++;
14342 info_avail = 1;
14343 snprintf(params, sizeof(params), "browser %s", pos);
14344
14345 if (display && strcasecmp(display, "Yes") == 0) {
14346 pid_t pid;
14347
14348 pid = fork();
14349 if (pid < 0) {
14350 perror("fork");
14351 return -1;
14352 }
14353
14354 if (pid == 0) {
14355 run_hs20_osu(dut, params);
14356 exit(0);
14357 }
14358 }
14359
14360done:
14361 snprintf(buf, sizeof(buf), "Info_available,%s",
14362 info_avail ? "Yes" : "No");
14363 send_resp(dut, conn, SIGMA_COMPLETE, buf);
14364fail:
14365 wpa_ctrl_detach(ctrl);
14366 wpa_ctrl_close(ctrl);
14367 return 0;
14368}
14369
14370
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014371static int sta_add_credential_uname_pwd(struct sigma_dut *dut,
14372 struct sigma_conn *conn,
14373 const char *ifname,
14374 struct sigma_cmd *cmd)
14375{
14376 const char *val;
14377 int id;
14378
14379 id = add_cred(ifname);
14380 if (id < 0)
14381 return -2;
14382 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
14383
14384 val = get_param(cmd, "prefer");
14385 if (val && atoi(val) > 0)
14386 set_cred(ifname, id, "priority", "1");
14387
14388 val = get_param(cmd, "REALM");
14389 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
14390 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
14391 "realm");
14392 return 0;
14393 }
14394
14395 val = get_param(cmd, "HOME_FQDN");
14396 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
14397 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
14398 "home_fqdn");
14399 return 0;
14400 }
14401
14402 val = get_param(cmd, "Username");
14403 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
14404 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
14405 "username");
14406 return 0;
14407 }
14408
14409 val = get_param(cmd, "Password");
14410 if (val && set_cred_quoted(ifname, id, "password", val) < 0) {
14411 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
14412 "password");
14413 return 0;
14414 }
14415
14416 val = get_param(cmd, "ROOT_CA");
14417 if (val) {
14418 char fname[200];
14419 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
14420#ifdef __linux__
14421 if (!file_exists(fname)) {
14422 char msg[300];
14423 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
14424 "file (%s) not found", fname);
14425 send_resp(dut, conn, SIGMA_ERROR, msg);
14426 return 0;
14427 }
14428#endif /* __linux__ */
14429 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
14430 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
14431 "not set root CA");
14432 return 0;
14433 }
14434 }
14435
14436 return 1;
14437}
14438
14439
14440static int update_devdetail_imsi(struct sigma_dut *dut, const char *imsi)
14441{
14442 FILE *in, *out;
14443 char buf[500];
14444 int found = 0;
14445
14446 in = fopen("devdetail.xml", "r");
14447 if (in == NULL)
14448 return -1;
14449 out = fopen("devdetail.xml.tmp", "w");
14450 if (out == NULL) {
14451 fclose(in);
14452 return -1;
14453 }
14454
14455 while (fgets(buf, sizeof(buf), in)) {
14456 char *pos = strstr(buf, "<IMSI>");
14457 if (pos) {
14458 sigma_dut_print(dut, DUT_MSG_INFO, "Updated DevDetail IMSI to %s",
14459 imsi);
14460 pos += 6;
14461 *pos = '\0';
14462 fprintf(out, "%s%s</IMSI>\n", buf, imsi);
14463 found++;
14464 } else {
14465 fprintf(out, "%s", buf);
14466 }
14467 }
14468
14469 fclose(out);
14470 fclose(in);
14471 if (found)
14472 rename("devdetail.xml.tmp", "devdetail.xml");
14473 else
14474 unlink("devdetail.xml.tmp");
14475
14476 return 0;
14477}
14478
14479
14480static int sta_add_credential_sim(struct sigma_dut *dut,
14481 struct sigma_conn *conn,
14482 const char *ifname, struct sigma_cmd *cmd)
14483{
14484 const char *val, *imsi = NULL;
14485 int id;
14486 char buf[200];
14487 int res;
14488 const char *pos;
14489 size_t mnc_len;
14490 char plmn_mcc[4];
14491 char plmn_mnc[4];
14492
14493 id = add_cred(ifname);
14494 if (id < 0)
14495 return -2;
14496 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
14497
14498 val = get_param(cmd, "prefer");
14499 if (val && atoi(val) > 0)
14500 set_cred(ifname, id, "priority", "1");
14501
14502 val = get_param(cmd, "PLMN_MCC");
14503 if (val == NULL) {
14504 send_resp(dut, conn, SIGMA_ERROR,
14505 "errorCode,Missing PLMN_MCC");
14506 return 0;
14507 }
14508 if (strlen(val) != 3) {
14509 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MCC");
14510 return 0;
14511 }
14512 snprintf(plmn_mcc, sizeof(plmn_mcc), "%s", val);
14513
14514 val = get_param(cmd, "PLMN_MNC");
14515 if (val == NULL) {
14516 send_resp(dut, conn, SIGMA_ERROR,
14517 "errorCode,Missing PLMN_MNC");
14518 return 0;
14519 }
14520 if (strlen(val) != 2 && strlen(val) != 3) {
14521 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MNC");
14522 return 0;
14523 }
14524 snprintf(plmn_mnc, sizeof(plmn_mnc), "%s", val);
14525
14526 val = get_param(cmd, "IMSI");
14527 if (val == NULL) {
14528 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing SIM "
14529 "IMSI");
14530 return 0;
14531 }
14532
14533 imsi = pos = val;
14534
14535 if (strncmp(plmn_mcc, pos, 3) != 0) {
14536 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MCC mismatch");
14537 return 0;
14538 }
14539 pos += 3;
14540
14541 mnc_len = strlen(plmn_mnc);
14542 if (mnc_len < 2) {
14543 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC not set");
14544 return 0;
14545 }
14546
14547 if (strncmp(plmn_mnc, pos, mnc_len) != 0) {
14548 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC mismatch");
14549 return 0;
14550 }
14551 pos += mnc_len;
14552
14553 res = snprintf(buf, sizeof(buf), "%s%s-%s",plmn_mcc, plmn_mnc, pos);
14554 if (res < 0 || res >= (int) sizeof(buf))
14555 return -1;
14556 if (set_cred_quoted(ifname, id, "imsi", buf) < 0) {
14557 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
14558 "not set IMSI");
14559 return 0;
14560 }
14561
14562 val = get_param(cmd, "Password");
14563 if (val && set_cred_quoted(ifname, id, "milenage", val) < 0) {
14564 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
14565 "not set password");
14566 return 0;
14567 }
14568
Jouni Malinenba630452018-06-22 11:49:59 +030014569 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014570 /*
14571 * Set provisioning_sp for the test cases where SIM/USIM
14572 * provisioning is used.
14573 */
14574 if (val && set_cred_quoted(ifname, id, "provisioning_sp",
14575 "wi-fi.org") < 0) {
14576 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
14577 "not set provisioning_sp");
14578 return 0;
14579 }
14580
14581 update_devdetail_imsi(dut, imsi);
14582 }
14583
14584 return 1;
14585}
14586
14587
14588static int sta_add_credential_cert(struct sigma_dut *dut,
14589 struct sigma_conn *conn,
14590 const char *ifname,
14591 struct sigma_cmd *cmd)
14592{
14593 const char *val;
14594 int id;
14595
14596 id = add_cred(ifname);
14597 if (id < 0)
14598 return -2;
14599 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
14600
14601 val = get_param(cmd, "prefer");
14602 if (val && atoi(val) > 0)
14603 set_cred(ifname, id, "priority", "1");
14604
14605 val = get_param(cmd, "REALM");
14606 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
14607 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
14608 "realm");
14609 return 0;
14610 }
14611
14612 val = get_param(cmd, "HOME_FQDN");
14613 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
14614 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
14615 "home_fqdn");
14616 return 0;
14617 }
14618
14619 val = get_param(cmd, "Username");
14620 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
14621 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
14622 "username");
14623 return 0;
14624 }
14625
14626 val = get_param(cmd, "clientCertificate");
14627 if (val) {
14628 char fname[200];
14629 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
14630#ifdef __linux__
14631 if (!file_exists(fname)) {
14632 char msg[300];
14633 snprintf(msg, sizeof(msg),
14634 "ErrorCode,clientCertificate "
14635 "file (%s) not found", fname);
14636 send_resp(dut, conn, SIGMA_ERROR, msg);
14637 return 0;
14638 }
14639#endif /* __linux__ */
14640 if (set_cred_quoted(ifname, id, "client_cert", fname) < 0) {
14641 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
14642 "not set client_cert");
14643 return 0;
14644 }
14645 if (set_cred_quoted(ifname, id, "private_key", fname) < 0) {
14646 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
14647 "not set private_key");
14648 return 0;
14649 }
14650 }
14651
14652 val = get_param(cmd, "ROOT_CA");
14653 if (val) {
14654 char fname[200];
14655 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
14656#ifdef __linux__
14657 if (!file_exists(fname)) {
14658 char msg[300];
14659 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
14660 "file (%s) not found", fname);
14661 send_resp(dut, conn, SIGMA_ERROR, msg);
14662 return 0;
14663 }
14664#endif /* __linux__ */
14665 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
14666 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
14667 "not set root CA");
14668 return 0;
14669 }
14670 }
14671
14672 return 1;
14673}
14674
14675
Jouni Malinenf7222712019-06-13 01:50:21 +030014676static enum sigma_cmd_result cmd_sta_add_credential(struct sigma_dut *dut,
14677 struct sigma_conn *conn,
14678 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014679{
14680 const char *intf = get_param(cmd, "Interface");
14681 const char *type;
14682
14683 start_sta_mode(dut);
14684
14685 type = get_param(cmd, "Type");
14686 if (!type)
14687 return -1;
14688
14689 if (strcasecmp(type, "uname_pwd") == 0)
14690 return sta_add_credential_uname_pwd(dut, conn, intf, cmd);
14691
14692 if (strcasecmp(type, "sim") == 0)
14693 return sta_add_credential_sim(dut, conn, intf, cmd);
14694
14695 if (strcasecmp(type, "cert") == 0)
14696 return sta_add_credential_cert(dut, conn, intf, cmd);
14697
14698 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported credential "
14699 "type");
14700 return 0;
14701}
14702
14703
Jouni Malinenf7222712019-06-13 01:50:21 +030014704static enum sigma_cmd_result cmd_sta_scan(struct sigma_dut *dut,
14705 struct sigma_conn *conn,
14706 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014707{
14708 const char *intf = get_param(cmd, "Interface");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080014709 const char *val, *bssid, *ssid, *scan_freq, *short_ssid;
Veerendranathdc581b52020-08-10 03:29:08 -070014710 char buf[4096], scan_res[20];
vamsi krishna89ad8c62017-09-19 12:51:18 +053014711 char ssid_hex[65];
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080014712 int wildcard_ssid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014713 int res;
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080014714 enum sigma_cmd_result status;
Jouni Malinen228a2fc2020-06-22 23:37:45 +030014715 struct wpa_ctrl *ctrl = NULL;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014716
Jouni Malinen8c1abeb2019-11-06 18:48:34 +020014717 start_sta_mode(dut);
14718
Arif Hussain66a4af02019-02-07 15:04:51 -080014719 val = get_param(cmd, "GetParameter");
14720 if (val && strcmp(val, "SSID_BSSID") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020014721 if (get_wpa_ssid_bssid(dut, get_station_ifname(dut),
Arif Hussain66a4af02019-02-07 15:04:51 -080014722 buf, sizeof(buf)) < 0) {
14723 sigma_dut_print(dut, DUT_MSG_ERROR,
14724 "Could not get ssid bssid");
14725 return ERROR_SEND_STATUS;
14726 }
14727
14728 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
14729 send_resp(dut, conn, SIGMA_COMPLETE, buf);
14730 return STATUS_SENT;
14731 }
14732
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014733 val = get_param(cmd, "HESSID");
14734 if (val) {
14735 res = snprintf(buf, sizeof(buf), "SET hessid %s", val);
14736 if (res < 0 || res >= (int) sizeof(buf))
14737 return -1;
14738 wpa_command(intf, buf);
14739 }
14740
14741 val = get_param(cmd, "ACCS_NET_TYPE");
14742 if (val) {
14743 res = snprintf(buf, sizeof(buf), "SET access_network_type %s",
14744 val);
14745 if (res < 0 || res >= (int) sizeof(buf))
14746 return -1;
14747 wpa_command(intf, buf);
14748 }
14749
Kiran Kumar Lokere69d89952021-08-08 23:41:46 -070014750 if (get_param(cmd, "RxMac"))
14751 sta_set_scan_unicast_probe(dut, intf, 1);
14752
vamsi krishna89ad8c62017-09-19 12:51:18 +053014753 bssid = get_param(cmd, "Bssid");
14754 ssid = get_param(cmd, "Ssid");
Kiran Kumar Lokere69d89952021-08-08 23:41:46 -070014755 if (!bssid)
14756 bssid = get_param(cmd, "RxMac");
vamsi krishna89ad8c62017-09-19 12:51:18 +053014757
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080014758 if (ssid && strcasecmp(ssid, "ZeroLength") == 0 &&
14759 dut->device_type == STA_testbed) {
14760 ssid = NULL;
14761 wildcard_ssid = 1;
14762 }
14763
vamsi krishna89ad8c62017-09-19 12:51:18 +053014764 if (ssid) {
14765 if (2 * strlen(ssid) >= sizeof(ssid_hex)) {
14766 send_resp(dut, conn, SIGMA_ERROR,
14767 "ErrorCode,Too long SSID");
14768 return 0;
14769 }
14770 ascii2hexstr(ssid, ssid_hex);
14771 }
14772
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080014773 short_ssid = get_param(cmd, "ShortSSID");
14774 if (short_ssid) {
14775 uint32_t short_ssid_hex;
14776
14777 short_ssid_hex = strtoul(short_ssid, NULL, 16);
14778 short_ssid_hex = ((short_ssid_hex & 0xFF) << 24) |
14779 (((short_ssid_hex >> 8) & 0xFF) << 16) |
14780 (((short_ssid_hex >> 16) & 0xFF) << 8) |
14781 ((short_ssid_hex >> 24) & 0xFF);
14782
14783 res = snprintf(buf, sizeof(buf),
14784 "VENDOR_ELEM_ADD 14 ff053a%08x",
14785 short_ssid_hex);
14786 if (res < 0 || res >= (int) sizeof(buf) ||
14787 wpa_command(intf, buf)) {
14788 send_resp(dut, conn, SIGMA_ERROR,
14789 "errorCode,Failed to add short SSID");
14790 return STATUS_SENT_ERROR;
14791 }
14792 }
14793
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080014794 scan_freq = get_param(cmd, "ChnlFreq");
Veerendranath Jakkam132c4b42020-08-10 00:29:03 +053014795 if (scan_freq) {
14796 if (strcasecmp(scan_freq, "2G") == 0)
14797 scan_freq = "2412-2462";
14798 else if (strcasecmp(scan_freq, "5G") == 0)
14799 scan_freq = "5180-5925";
14800 }
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080014801
Jouni Malinen228a2fc2020-06-22 23:37:45 +030014802 val = get_param(cmd, "WaitCompletion");
14803 if (val && atoi(val) == 1) {
14804 ctrl = open_wpa_mon(intf);
14805 if (!ctrl) {
14806 send_resp(dut, conn, SIGMA_ERROR,
14807 "errorCode,Failed to open monitor socket");
14808 return STATUS_SENT_ERROR;
14809 }
14810 }
14811
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080014812 res = snprintf(buf, sizeof(buf), "SCAN%s%s%s%s%s%s%s",
vamsi krishna89ad8c62017-09-19 12:51:18 +053014813 bssid ? " bssid=": "",
14814 bssid ? bssid : "",
14815 ssid ? " ssid " : "",
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080014816 ssid ? ssid_hex : "",
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080014817 wildcard_ssid ? " wildcard_ssid=1" : "",
14818 scan_freq ? " freq=" : "",
14819 scan_freq ? scan_freq : "");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080014820 if (res < 0 || res >= (int) sizeof(buf)) {
14821 send_resp(dut, conn, SIGMA_ERROR,
14822 "errorCode,Could not build scan command");
14823 status = STATUS_SENT_ERROR;
14824 goto remove_s_ssid;
14825 }
vamsi krishna89ad8c62017-09-19 12:51:18 +053014826
Veerendranathdc581b52020-08-10 03:29:08 -070014827 res = wpa_command_resp(intf, buf, scan_res, sizeof(scan_res));
14828 if (strncmp(scan_res, "FAIL-BUSY", 9) == 0) {
14829 sigma_dut_print(dut, DUT_MSG_DEBUG,
14830 "Scan request rejected with busy status, abort ongoing scan and try again");
14831 wpa_command(intf, "ABORT_SCAN");
14832 res = wpa_command(intf, buf);
14833 }
14834
14835 if (res < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014836 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not start "
14837 "scan");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080014838 status = STATUS_SENT_ERROR;
14839 } else {
14840 status = SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014841 }
14842
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080014843remove_s_ssid:
14844 if (short_ssid && wpa_command(intf, "VENDOR_ELEM_REMOVE 14 *"))
14845 sigma_dut_print(dut, DUT_MSG_ERROR,
14846 "Failed to delete vendor element");
14847
Jouni Malinen228a2fc2020-06-22 23:37:45 +030014848 if (ctrl) {
14849 if (status == SUCCESS_SEND_STATUS) {
14850 res = get_wpa_cli_event(dut, ctrl,
14851 "CTRL-EVENT-SCAN-RESULTS",
14852 buf, sizeof(buf));
14853 if (res < 0) {
14854 send_resp(dut, conn, SIGMA_ERROR,
14855 "ErrorCode,scan did not complete");
14856 status = STATUS_SENT_ERROR;
14857 }
14858 }
14859
14860 wpa_ctrl_detach(ctrl);
14861 wpa_ctrl_close(ctrl);
14862 }
14863
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080014864 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014865}
14866
14867
Jouni Malinenf7222712019-06-13 01:50:21 +030014868static enum sigma_cmd_result cmd_sta_scan_bss(struct sigma_dut *dut,
14869 struct sigma_conn *conn,
14870 struct sigma_cmd *cmd)
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020014871{
14872 const char *intf = get_param(cmd, "Interface");
14873 const char *bssid;
14874 char buf[4096], *pos;
14875 int freq, chan;
14876 char *ssid;
14877 char resp[100];
14878 int res;
14879 struct wpa_ctrl *ctrl;
14880
14881 bssid = get_param(cmd, "BSSID");
14882 if (!bssid) {
14883 send_resp(dut, conn, SIGMA_INVALID,
14884 "errorCode,BSSID argument is missing");
14885 return 0;
14886 }
14887
14888 ctrl = open_wpa_mon(intf);
14889 if (!ctrl) {
14890 sigma_dut_print(dut, DUT_MSG_ERROR,
14891 "Failed to open wpa_supplicant monitor connection");
14892 return -1;
14893 }
14894
14895 if (wpa_command(intf, "SCAN TYPE=ONLY")) {
14896 send_resp(dut, conn, SIGMA_ERROR,
14897 "errorCode,Could not start scan");
14898 wpa_ctrl_detach(ctrl);
14899 wpa_ctrl_close(ctrl);
14900 return 0;
14901 }
14902
14903 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
14904 buf, sizeof(buf));
14905
14906 wpa_ctrl_detach(ctrl);
14907 wpa_ctrl_close(ctrl);
14908
14909 if (res < 0) {
14910 send_resp(dut, conn, SIGMA_ERROR,
14911 "errorCode,Scan did not complete");
14912 return 0;
14913 }
14914
14915 snprintf(buf, sizeof(buf), "BSS %s", bssid);
14916 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
14917 strncmp(buf, "id=", 3) != 0) {
14918 send_resp(dut, conn, SIGMA_ERROR,
14919 "errorCode,Specified BSSID not found");
14920 return 0;
14921 }
14922
14923 pos = strstr(buf, "\nfreq=");
14924 if (!pos) {
14925 send_resp(dut, conn, SIGMA_ERROR,
14926 "errorCode,Channel not found");
14927 return 0;
14928 }
14929 freq = atoi(pos + 6);
14930 chan = freq_to_channel(freq);
14931
14932 pos = strstr(buf, "\nssid=");
14933 if (!pos) {
14934 send_resp(dut, conn, SIGMA_ERROR,
14935 "errorCode,SSID not found");
14936 return 0;
14937 }
14938 ssid = pos + 6;
14939 pos = strchr(ssid, '\n');
14940 if (pos)
14941 *pos = '\0';
14942 snprintf(resp, sizeof(resp), "ssid,%s,bsschannel,%d", ssid, chan);
14943 send_resp(dut, conn, SIGMA_COMPLETE, resp);
14944 return 0;
14945}
14946
14947
Jouni Malinenf7222712019-06-13 01:50:21 +030014948static enum sigma_cmd_result cmd_sta_set_systime(struct sigma_dut *dut,
14949 struct sigma_conn *conn,
14950 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014951{
14952#ifdef __linux__
14953 struct timeval tv;
14954 struct tm tm;
14955 time_t t;
14956 const char *val;
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053014957 int v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014958
Jouni Malinen016ae6c2019-11-04 17:00:01 +020014959 wpa_command(get_station_ifname(dut), "PMKSA_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014960
14961 memset(&tm, 0, sizeof(tm));
14962 val = get_param(cmd, "seconds");
14963 if (val)
14964 tm.tm_sec = atoi(val);
14965 val = get_param(cmd, "minutes");
14966 if (val)
14967 tm.tm_min = atoi(val);
14968 val = get_param(cmd, "hours");
14969 if (val)
14970 tm.tm_hour = atoi(val);
14971 val = get_param(cmd, "date");
14972 if (val)
14973 tm.tm_mday = atoi(val);
14974 val = get_param(cmd, "month");
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053014975 if (val) {
14976 v = atoi(val);
14977 if (v < 1 || v > 12) {
14978 send_resp(dut, conn, SIGMA_INVALID,
14979 "errorCode,Invalid month");
14980 return 0;
14981 }
14982 tm.tm_mon = v - 1;
14983 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014984 val = get_param(cmd, "year");
14985 if (val) {
14986 int year = atoi(val);
14987#ifdef ANDROID
14988 if (year > 2035)
14989 year = 2035; /* years beyond 2035 not supported */
14990#endif /* ANDROID */
14991 tm.tm_year = year - 1900;
14992 }
14993 t = mktime(&tm);
14994 if (t == (time_t) -1) {
14995 send_resp(dut, conn, SIGMA_ERROR,
14996 "errorCode,Invalid date or time");
14997 return 0;
14998 }
14999
15000 memset(&tv, 0, sizeof(tv));
15001 tv.tv_sec = t;
15002
15003 if (settimeofday(&tv, NULL) < 0) {
15004 sigma_dut_print(dut, DUT_MSG_INFO, "settimeofday failed: %s",
15005 strerror(errno));
15006 send_resp(dut, conn, SIGMA_ERROR,
15007 "errorCode,Failed to set time");
15008 return 0;
15009 }
15010
15011 return 1;
15012#endif /* __linux__ */
15013
15014 return -1;
15015}
15016
15017
Jouni Malinenf7222712019-06-13 01:50:21 +030015018static enum sigma_cmd_result cmd_sta_osu(struct sigma_dut *dut,
15019 struct sigma_conn *conn,
15020 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015021{
15022 const char *intf = get_param(cmd, "Interface");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030015023 const char *name, *osu_ssid, *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015024 int prod_ess_assoc = 1;
Jouni Malinen4c8681c2018-09-12 23:28:11 +030015025 char buf[300], bssid[100], ssid[100];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015026 int res;
15027 struct wpa_ctrl *ctrl;
15028
15029 name = get_param(cmd, "osuFriendlyName");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030015030 osu_ssid = get_param(cmd, "osu_ssid");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015031
15032 val = get_param(cmd, "ProdESSAssoc");
15033 if (val)
15034 prod_ess_assoc = atoi(val);
15035
15036 kill_dhcp_client(dut, intf);
15037 if (start_dhcp_client(dut, intf) < 0)
15038 return -2;
15039
15040 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger OSU");
15041 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
15042 res = snprintf(buf, sizeof(buf),
Jouni Malinen4c8681c2018-09-12 23:28:11 +030015043 "%s %s%s%s %s%s%s signup osu-ca.pem",
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015044 prod_ess_assoc ? "" : "-N",
15045 name ? "-O'" : "", name ? name : "",
Jouni Malinen4c8681c2018-09-12 23:28:11 +030015046 name ? "'" : "",
15047 osu_ssid ? "-o'" : "", osu_ssid ? osu_ssid : "",
15048 osu_ssid ? "'" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015049
Kanchanapally, Vidyullatha12b66762015-12-31 16:46:42 +053015050 hs2_set_policy(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015051 if (run_hs20_osu(dut, buf) < 0) {
15052 FILE *f;
15053
15054 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to complete OSU");
15055
15056 f = fopen("hs20-osu-client.res", "r");
15057 if (f) {
15058 char resp[400], res[300], *pos;
15059 if (!fgets(res, sizeof(res), f))
15060 res[0] = '\0';
15061 pos = strchr(res, '\n');
15062 if (pos)
15063 *pos = '\0';
15064 fclose(f);
15065 sigma_dut_summary(dut, "hs20-osu-client provisioning failed: %s",
15066 res);
15067 snprintf(resp, sizeof(resp), "notify-send '%s'", res);
15068 if (system(resp) != 0) {
15069 }
15070 snprintf(resp, sizeof(resp),
15071 "SSID,,BSSID,,failureReason,%s", res);
15072 send_resp(dut, conn, SIGMA_COMPLETE, resp);
15073 return 0;
15074 }
15075
15076 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
15077 return 0;
15078 }
15079
15080 if (!prod_ess_assoc)
15081 goto report;
15082
15083 ctrl = open_wpa_mon(intf);
15084 if (ctrl == NULL) {
15085 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
15086 "wpa_supplicant monitor connection");
15087 return -1;
15088 }
15089
15090 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
15091 buf, sizeof(buf));
15092
15093 wpa_ctrl_detach(ctrl);
15094 wpa_ctrl_close(ctrl);
15095
15096 if (res < 0) {
15097 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to connect to "
15098 "network after OSU");
15099 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
15100 return 0;
15101 }
15102
15103report:
15104 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
15105 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
15106 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get BSSID/SSID");
15107 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
15108 return 0;
15109 }
15110
15111 snprintf(buf, sizeof(buf), "SSID,%s,BSSID,%s", ssid, bssid);
15112 send_resp(dut, conn, SIGMA_COMPLETE, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015113 return 0;
15114}
15115
15116
Jouni Malinenf7222712019-06-13 01:50:21 +030015117static enum sigma_cmd_result cmd_sta_policy_update(struct sigma_dut *dut,
15118 struct sigma_conn *conn,
15119 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015120{
15121 const char *val;
15122 int timeout = 120;
15123
15124 val = get_param(cmd, "PolicyUpdate");
15125 if (val == NULL || atoi(val) == 0)
15126 return 1; /* No operation requested */
15127
15128 val = get_param(cmd, "Timeout");
15129 if (val)
15130 timeout = atoi(val);
15131
15132 if (timeout) {
15133 /* TODO: time out the command and return
15134 * PolicyUpdateStatus,TIMEOUT if needed. */
15135 }
15136
15137 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger policy update");
15138 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
15139 if (run_hs20_osu(dut, "pol_upd fqdn=wi-fi.org") < 0) {
15140 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,FAIL");
15141 return 0;
15142 }
15143
15144 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,SUCCESS");
15145 return 0;
15146}
15147
15148
Jouni Malinenf7222712019-06-13 01:50:21 +030015149static enum sigma_cmd_result cmd_sta_er_config(struct sigma_dut *dut,
15150 struct sigma_conn *conn,
15151 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015152{
15153 struct wpa_ctrl *ctrl;
15154 const char *intf = get_param(cmd, "Interface");
15155 const char *bssid = get_param(cmd, "Bssid");
15156 const char *ssid = get_param(cmd, "SSID");
15157 const char *security = get_param(cmd, "Security");
15158 const char *passphrase = get_param(cmd, "Passphrase");
15159 const char *pin = get_param(cmd, "PIN");
15160 char buf[1000];
15161 char ssid_hex[200], passphrase_hex[200];
15162 const char *keymgmt, *cipher;
15163
15164 if (intf == NULL)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020015165 intf = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015166
15167 if (!bssid) {
15168 send_resp(dut, conn, SIGMA_ERROR,
15169 "ErrorCode,Missing Bssid argument");
15170 return 0;
15171 }
15172
15173 if (!ssid) {
15174 send_resp(dut, conn, SIGMA_ERROR,
15175 "ErrorCode,Missing SSID argument");
15176 return 0;
15177 }
15178
15179 if (!security) {
15180 send_resp(dut, conn, SIGMA_ERROR,
15181 "ErrorCode,Missing Security argument");
15182 return 0;
15183 }
15184
15185 if (!passphrase) {
15186 send_resp(dut, conn, SIGMA_ERROR,
15187 "ErrorCode,Missing Passphrase argument");
15188 return 0;
15189 }
15190
15191 if (!pin) {
15192 send_resp(dut, conn, SIGMA_ERROR,
15193 "ErrorCode,Missing PIN argument");
15194 return 0;
15195 }
15196
vamsi krishna8c9c1562017-05-12 15:51:46 +053015197 if (2 * strlen(ssid) >= sizeof(ssid_hex) ||
15198 2 * strlen(passphrase) >= sizeof(passphrase_hex)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015199 send_resp(dut, conn, SIGMA_ERROR,
15200 "ErrorCode,Too long SSID/passphrase");
15201 return 0;
15202 }
15203
15204 ctrl = open_wpa_mon(intf);
15205 if (ctrl == NULL) {
15206 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
15207 "wpa_supplicant monitor connection");
15208 return -2;
15209 }
15210
15211 if (strcasecmp(security, "wpa2-psk") == 0) {
15212 keymgmt = "WPA2PSK";
15213 cipher = "CCMP";
15214 } else {
15215 wpa_ctrl_detach(ctrl);
15216 wpa_ctrl_close(ctrl);
15217 send_resp(dut, conn, SIGMA_ERROR,
15218 "ErrorCode,Unsupported Security value");
15219 return 0;
15220 }
15221
15222 ascii2hexstr(ssid, ssid_hex);
15223 ascii2hexstr(passphrase, passphrase_hex);
15224 snprintf(buf, sizeof(buf), "WPS_REG %s %s %s %s %s %s",
15225 bssid, pin, ssid_hex, keymgmt, cipher, passphrase_hex);
15226
15227 if (wpa_command(intf, buf) < 0) {
15228 wpa_ctrl_detach(ctrl);
15229 wpa_ctrl_close(ctrl);
15230 send_resp(dut, conn, SIGMA_ERROR,
15231 "ErrorCode,Failed to start registrar");
15232 return 0;
15233 }
15234
15235 snprintf(dut->er_oper_bssid, sizeof(dut->er_oper_bssid), "%s", bssid);
15236 dut->er_oper_performed = 1;
15237
15238 return wps_connection_event(dut, conn, ctrl, intf, 0);
15239}
15240
15241
Jouni Malinenf7222712019-06-13 01:50:21 +030015242static enum sigma_cmd_result
15243cmd_sta_wps_connect_pw_token(struct sigma_dut *dut, struct sigma_conn *conn,
15244 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015245{
15246 struct wpa_ctrl *ctrl;
15247 const char *intf = get_param(cmd, "Interface");
15248 const char *bssid = get_param(cmd, "Bssid");
15249 char buf[100];
15250
15251 if (!bssid) {
15252 send_resp(dut, conn, SIGMA_ERROR,
15253 "ErrorCode,Missing Bssid argument");
15254 return 0;
15255 }
15256
15257 ctrl = open_wpa_mon(intf);
15258 if (ctrl == NULL) {
15259 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
15260 "wpa_supplicant monitor connection");
15261 return -2;
15262 }
15263
15264 snprintf(buf, sizeof(buf), "WPS_NFC %s", bssid);
15265
15266 if (wpa_command(intf, buf) < 0) {
15267 wpa_ctrl_detach(ctrl);
15268 wpa_ctrl_close(ctrl);
15269 send_resp(dut, conn, SIGMA_ERROR,
15270 "ErrorCode,Failed to start registrar");
15271 return 0;
15272 }
15273
15274 return wps_connection_event(dut, conn, ctrl, intf, 0);
15275}
15276
15277
Jouni Malinenf7222712019-06-13 01:50:21 +030015278static enum sigma_cmd_result cmd_start_wps_registration(struct sigma_dut *dut,
15279 struct sigma_conn *conn,
15280 struct sigma_cmd *cmd)
vamsi krishna9b144002017-09-20 13:28:13 +053015281{
15282 struct wpa_ctrl *ctrl;
15283 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020015284 const char *network_mode = get_param(cmd, "network_mode");
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020015285 const char *config_method = get_param(cmd, "WPSConfigMethod");
15286 const char *role;
vamsi krishna9b144002017-09-20 13:28:13 +053015287 int res;
15288 char buf[256];
15289 const char *events[] = {
15290 "CTRL-EVENT-CONNECTED",
15291 "WPS-OVERLAP-DETECTED",
15292 "WPS-TIMEOUT",
15293 "WPS-FAIL",
15294 NULL
15295 };
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020015296 int id = 0;
vamsi krishna9b144002017-09-20 13:28:13 +053015297
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020015298 /* 60G WPS tests do not pass Interface parameter */
15299 if (!intf)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020015300 intf = get_main_ifname(dut);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020015301
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020015302 if (dut->mode == SIGMA_MODE_AP)
15303 return ap_wps_registration(dut, conn, cmd);
15304
15305 if (config_method) {
15306 /* WFA_CS_WPS_PIN_KEYPAD mode is set when using the
15307 * sta_wps_enter_pin before calling start_wps_registration. */
15308 if (strcasecmp(config_method, "PBC") == 0)
15309 dut->wps_method = WFA_CS_WPS_PBC;
15310 }
15311 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
15312 send_resp(dut, conn, SIGMA_ERROR,
15313 "ErrorCode,WPS parameters not yet set");
15314 return STATUS_SENT;
15315 }
15316
15317 /* Make sure WPS is enabled (also for STA mode) */
15318 dut->wps_disable = 0;
15319
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020015320 if (dut->band == WPS_BAND_60G && network_mode &&
15321 strcasecmp(network_mode, "PBSS") == 0) {
15322 sigma_dut_print(dut, DUT_MSG_DEBUG,
15323 "Set PBSS network mode, network id %d", id);
Jouni Malinen016ae6c2019-11-04 17:00:01 +020015324 if (set_network(get_station_ifname(dut), id, "pbss", "1") < 0)
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020015325 return -2;
15326 }
15327
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020015328 if (dut->force_rsn_ie) {
15329 sigma_dut_print(dut, DUT_MSG_DEBUG, "Force RSN_IE: %d",
15330 dut->force_rsn_ie);
15331 if (sta_60g_force_rsn_ie(dut, dut->force_rsn_ie) < 0) {
15332 sigma_dut_print(dut, DUT_MSG_INFO,
15333 "Failed to force RSN_IE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020015334 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020015335 }
15336 }
15337
vamsi krishna9b144002017-09-20 13:28:13 +053015338 ctrl = open_wpa_mon(intf);
15339 if (!ctrl) {
15340 sigma_dut_print(dut, DUT_MSG_ERROR,
15341 "Failed to open wpa_supplicant monitor connection");
15342 return -2;
15343 }
15344
15345 role = get_param(cmd, "WpsRole");
15346 if (!role) {
15347 send_resp(dut, conn, SIGMA_INVALID,
15348 "ErrorCode,WpsRole not provided");
15349 goto fail;
15350 }
15351
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020015352 if (strcasecmp(role, "Enrollee") != 0) {
15353 /* Registrar role for STA not supported */
15354 send_resp(dut, conn, SIGMA_ERROR,
15355 "ErrorCode,Unsupported WpsRole value");
15356 goto fail;
15357 }
15358
15359 if (is_60g_sigma_dut(dut)) {
15360 if (dut->wps_method == WFA_CS_WPS_PBC)
15361 snprintf(buf, sizeof(buf), "WPS_PBC");
15362 else /* WFA_CS_WPS_PIN_KEYPAD */
15363 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
15364 dut->wps_pin);
15365 if (wpa_command(intf, buf) < 0) {
15366 send_resp(dut, conn, SIGMA_ERROR,
15367 "ErrorCode,Failed to start WPS");
vamsi krishna9b144002017-09-20 13:28:13 +053015368 goto fail;
15369 }
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020015370 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
15371 if (res < 0) {
15372 send_resp(dut, conn, SIGMA_ERROR,
15373 "ErrorCode,WPS connection did not complete");
15374 goto fail;
15375 }
15376 if (strstr(buf, "WPS-TIMEOUT")) {
15377 send_resp(dut, conn, SIGMA_COMPLETE, "WpsState,NoPeer");
15378 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
15379 send_resp(dut, conn, SIGMA_COMPLETE,
15380 "WpsState,OverlapSession");
15381 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
15382 send_resp(dut, conn, SIGMA_COMPLETE,
15383 "WpsState,Successful");
15384 } else {
15385 send_resp(dut, conn, SIGMA_COMPLETE,
15386 "WpsState,Failure");
15387 }
15388 } else {
15389 if (dut->wps_method == WFA_CS_WPS_PBC) {
vamsi krishna9b144002017-09-20 13:28:13 +053015390 if (wpa_command(intf, "WPS_PBC") < 0) {
15391 send_resp(dut, conn, SIGMA_ERROR,
15392 "ErrorCode,Failed to enable PBC");
15393 goto fail;
15394 }
15395 } else {
15396 /* TODO: PIN method */
15397 send_resp(dut, conn, SIGMA_ERROR,
15398 "ErrorCode,Unsupported WpsConfigMethod value");
15399 goto fail;
15400 }
15401 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
15402 if (res < 0) {
15403 send_resp(dut, conn, SIGMA_ERROR,
15404 "ErrorCode,WPS connection did not complete");
15405 goto fail;
15406 }
15407 if (strstr(buf, "WPS-TIMEOUT")) {
15408 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,NoPeer");
15409 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
15410 send_resp(dut, conn, SIGMA_ERROR,
15411 "ErrorCode,OverlapSession");
15412 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
15413 send_resp(dut, conn, SIGMA_COMPLETE, "Successful");
15414 } else {
15415 send_resp(dut, conn, SIGMA_ERROR,
15416 "ErrorCode,WPS operation failed");
15417 }
vamsi krishna9b144002017-09-20 13:28:13 +053015418 }
15419
15420fail:
15421 wpa_ctrl_detach(ctrl);
15422 wpa_ctrl_close(ctrl);
15423 return 0;
15424}
15425
15426
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015427static int req_intf(struct sigma_cmd *cmd)
15428{
15429 return get_param(cmd, "interface") == NULL ? -1 : 0;
15430}
15431
15432
15433void sta_register_cmds(void)
15434{
15435 sigma_dut_reg_cmd("sta_get_ip_config", req_intf,
15436 cmd_sta_get_ip_config);
15437 sigma_dut_reg_cmd("sta_set_ip_config", req_intf,
15438 cmd_sta_set_ip_config);
15439 sigma_dut_reg_cmd("sta_get_info", req_intf, cmd_sta_get_info);
15440 sigma_dut_reg_cmd("sta_get_mac_address", req_intf,
15441 cmd_sta_get_mac_address);
15442 sigma_dut_reg_cmd("sta_is_connected", req_intf, cmd_sta_is_connected);
15443 sigma_dut_reg_cmd("sta_verify_ip_connection", req_intf,
15444 cmd_sta_verify_ip_connection);
15445 sigma_dut_reg_cmd("sta_get_bssid", req_intf, cmd_sta_get_bssid);
15446 sigma_dut_reg_cmd("sta_set_encryption", req_intf,
15447 cmd_sta_set_encryption);
15448 sigma_dut_reg_cmd("sta_set_psk", req_intf, cmd_sta_set_psk);
15449 sigma_dut_reg_cmd("sta_set_eaptls", req_intf, cmd_sta_set_eaptls);
15450 sigma_dut_reg_cmd("sta_set_eapttls", req_intf, cmd_sta_set_eapttls);
15451 sigma_dut_reg_cmd("sta_set_eapsim", req_intf, cmd_sta_set_eapsim);
15452 sigma_dut_reg_cmd("sta_set_peap", req_intf, cmd_sta_set_peap);
15453 sigma_dut_reg_cmd("sta_set_eapfast", req_intf, cmd_sta_set_eapfast);
15454 sigma_dut_reg_cmd("sta_set_eapaka", req_intf, cmd_sta_set_eapaka);
15455 sigma_dut_reg_cmd("sta_set_eapakaprime", req_intf,
15456 cmd_sta_set_eapakaprime);
15457 sigma_dut_reg_cmd("sta_set_security", req_intf, cmd_sta_set_security);
15458 sigma_dut_reg_cmd("sta_set_uapsd", req_intf, cmd_sta_set_uapsd);
15459 /* TODO: sta_set_ibss */
15460 /* TODO: sta_set_mode */
15461 sigma_dut_reg_cmd("sta_set_wmm", req_intf, cmd_sta_set_wmm);
15462 sigma_dut_reg_cmd("sta_associate", req_intf, cmd_sta_associate);
15463 /* TODO: sta_up_load */
15464 sigma_dut_reg_cmd("sta_preset_testparameters", req_intf,
15465 cmd_sta_preset_testparameters);
15466 /* TODO: sta_set_system */
15467 sigma_dut_reg_cmd("sta_set_11n", req_intf, cmd_sta_set_11n);
15468 /* TODO: sta_set_rifs_test */
15469 sigma_dut_reg_cmd("sta_set_wireless", req_intf, cmd_sta_set_wireless);
15470 sigma_dut_reg_cmd("sta_send_addba", req_intf, cmd_sta_send_addba);
15471 /* TODO: sta_send_coexist_mgmt */
15472 sigma_dut_reg_cmd("sta_disconnect", req_intf, cmd_sta_disconnect);
15473 sigma_dut_reg_cmd("sta_reassoc", req_intf, cmd_sta_reassoc);
15474 sigma_dut_reg_cmd("sta_reassociate", req_intf, cmd_sta_reassoc);
15475 sigma_dut_reg_cmd("sta_reset_default", req_intf,
15476 cmd_sta_reset_default);
15477 sigma_dut_reg_cmd("sta_send_frame", req_intf, cmd_sta_send_frame);
15478 sigma_dut_reg_cmd("sta_set_macaddr", req_intf, cmd_sta_set_macaddr);
15479 sigma_dut_reg_cmd("sta_set_rfeature", req_intf, cmd_sta_set_rfeature);
15480 sigma_dut_reg_cmd("sta_set_radio", req_intf, cmd_sta_set_radio);
15481 sigma_dut_reg_cmd("sta_set_pwrsave", req_intf, cmd_sta_set_pwrsave);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020015482 sigma_dut_reg_cmd("sta_set_power_save", req_intf, cmd_sta_set_pwrsave);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015483 sigma_dut_reg_cmd("sta_bssid_pool", req_intf, cmd_sta_bssid_pool);
15484 sigma_dut_reg_cmd("sta_reset_parm", req_intf, cmd_sta_reset_parm);
15485 sigma_dut_reg_cmd("sta_get_key", req_intf, cmd_sta_get_key);
15486 sigma_dut_reg_cmd("sta_hs2_associate", req_intf,
15487 cmd_sta_hs2_associate);
Jouni Malinenb639f1c2018-09-13 02:39:46 +030015488 sigma_dut_reg_cmd("sta_hs2_venue_info", req_intf,
15489 cmd_sta_hs2_venue_info);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015490 sigma_dut_reg_cmd("sta_add_credential", req_intf,
15491 cmd_sta_add_credential);
15492 sigma_dut_reg_cmd("sta_scan", req_intf, cmd_sta_scan);
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020015493 sigma_dut_reg_cmd("sta_scan_bss", req_intf, cmd_sta_scan_bss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015494 sigma_dut_reg_cmd("sta_set_systime", NULL, cmd_sta_set_systime);
15495 sigma_dut_reg_cmd("sta_osu", req_intf, cmd_sta_osu);
15496 sigma_dut_reg_cmd("sta_policy_update", req_intf, cmd_sta_policy_update);
15497 sigma_dut_reg_cmd("sta_er_config", NULL, cmd_sta_er_config);
15498 sigma_dut_reg_cmd("sta_wps_connect_pw_token", req_intf,
15499 cmd_sta_wps_connect_pw_token);
Jouni Malinen82905202018-04-29 17:20:10 +030015500 sigma_dut_reg_cmd("sta_exec_action", NULL, cmd_sta_exec_action);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015501 sigma_dut_reg_cmd("sta_get_events", req_intf, cmd_sta_get_events);
15502 sigma_dut_reg_cmd("sta_get_parameter", req_intf, cmd_sta_get_parameter);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020015503 sigma_dut_reg_cmd("start_wps_registration", NULL,
vamsi krishna9b144002017-09-20 13:28:13 +053015504 cmd_start_wps_registration);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015505}