blob: 3fac22f9b1b8babe48d86dddff042ec0f2f5e6a0 [file] [log] [blame]
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001/*
2 * Sigma Control API DUT (station/AP)
3 * Copyright (c) 2010-2011, Atheros Communications, Inc.
Jouni Malinen9d7e31d2017-12-22 18:55:04 +02004 * Copyright (c) 2011-2017, Qualcomm Atheros, Inc.
Jouni Malinenc12ea4a2018-01-05 21:07:10 +02005 * Copyright (c) 2018, The Linux Foundation
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006 * All Rights Reserved.
7 * Licensed under the Clear BSD license. See README for more details.
8 */
9
10#include "sigma_dut.h"
11#include <sys/ioctl.h>
12#include <sys/stat.h>
Jouni Malinen82905202018-04-29 17:20:10 +030013#include <sys/wait.h>
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030014#include <ctype.h>
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015#ifdef __linux__
Lior Davidcc88b562017-01-03 18:52:09 +020016#include <regex.h>
17#include <dirent.h>
Jouni Malinencd4e3c32015-10-29 12:39:56 +020018#include <sys/time.h>
19#include <netpacket/packet.h>
20#include <linux/if_ether.h>
21#ifdef ANDROID
22#include <cutils/properties.h>
23#include <android/log.h>
24#include "keystore_get.h"
25#else /* ANDROID */
26#include <ifaddrs.h>
27#endif /* ANDROID */
28#include <netdb.h>
29#endif /* __linux__ */
30#ifdef __QNXNTO__
31#include <net/if_dl.h>
32#endif /* __QNXNTO__ */
33#include "wpa_ctrl.h"
34#include "wpa_helpers.h"
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -070035#include "miracast.h"
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -070036#include "qca-vendor_copy.h"
Jouni Malinencd4e3c32015-10-29 12:39:56 +020037
38/* Temporary files for sta_send_addba */
39#define VI_QOS_TMP_FILE "/tmp/vi-qos.tmp"
40#define VI_QOS_FILE "/tmp/vi-qos.txt"
41#define VI_QOS_REFFILE "/etc/vi-qos.txt"
42
43/*
44 * MTU for Ethernet need to take into account 8-byte SNAP header
45 * to be added when encapsulating Ethernet frame into 802.11
46 */
47#ifndef IEEE80211_MAX_DATA_LEN_DMG
48#define IEEE80211_MAX_DATA_LEN_DMG 7920
49#endif
50#ifndef IEEE80211_SNAP_LEN_DMG
51#define IEEE80211_SNAP_LEN_DMG 8
52#endif
53
Ashwini Patil00402582017-04-13 12:29:39 +053054#define NON_PREF_CH_LIST_SIZE 100
Ashwini Patil5acd7382017-04-13 15:55:04 +053055#define NEIGHBOR_REPORT_SIZE 1000
56#define DEFAULT_NEIGHBOR_BSSID_INFO "17"
57#define DEFAULT_NEIGHBOR_PHY_TYPE "1"
Ashwini Patil00402582017-04-13 12:29:39 +053058
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030059#define WIL_DEFAULT_BI 100
60
61/* default remain on channel time for transmitting frames (milliseconds) */
62#define WIL_TRANSMIT_FRAME_DEFAULT_ROC 500
63#define IEEE80211_P2P_ATTR_DEVICE_ID 3
64#define IEEE80211_P2P_ATTR_GROUP_ID 15
65
66/* describes tagged bytes in template frame file */
67struct template_frame_tag {
68 int num;
69 int offset;
70 size_t len;
71};
72
Jouni Malinencd4e3c32015-10-29 12:39:56 +020073extern char *sigma_wpas_ctrl;
74extern char *sigma_cert_path;
75extern enum driver_type wifi_chip_type;
76extern char *sigma_radio_ifname[];
77
Lior David0fe101e2017-03-09 16:09:50 +020078#ifdef __linux__
79#define WIL_WMI_MAX_PAYLOAD 248
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020080#define WIL_WMI_ESE_CFG_CMDID 0xa01
Lior David0fe101e2017-03-09 16:09:50 +020081#define WIL_WMI_BF_TRIG_CMDID 0x83a
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020082#define WIL_WMI_UNIT_TEST_CMDID 0x900
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030083#define WIL_WMI_P2P_CFG_CMDID 0x910
84#define WIL_WMI_START_LISTEN_CMDID 0x914
85#define WIL_WMI_DISCOVERY_STOP_CMDID 0x917
Lior David0fe101e2017-03-09 16:09:50 +020086
87struct wil_wmi_header {
88 uint8_t mid;
89 uint8_t reserved;
90 uint16_t cmd;
91 uint32_t ts;
92} __attribute__((packed));
93
94enum wil_wmi_bf_trig_type {
95 WIL_WMI_SLS,
96 WIL_WMI_BRP_RX,
97 WIL_WMI_BRP_TX,
98};
99
100struct wil_wmi_bf_trig_cmd {
101 /* enum wil_wmi_bf_trig_type */
102 uint32_t bf_type;
103 /* cid when type == WMI_BRP_RX */
104 uint32_t sta_id;
105 uint32_t reserved;
106 /* mac address when type = WIL_WMI_SLS */
107 uint8_t dest_mac[6];
108} __attribute__((packed));
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +0200109
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +0200110enum wil_wmi_sched_scheme_advertisment {
111 WIL_WMI_ADVERTISE_ESE_DISABLED,
112 WIL_WMI_ADVERTISE_ESE_IN_BEACON,
113 WIL_WMI_ADVERTISE_ESE_IN_ANNOUNCE_FRAME,
114};
115
116enum wil_wmi_ese_slot_type {
117 WIL_WMI_ESE_SP,
118 WIL_WMI_ESE_CBAP,
119 WIL_WMI_ESE_ANNOUNCE_NO_ACK,
120};
121
122struct wil_wmi_ese_slot {
123 /* offset from start of BI in microseconds */
124 uint32_t tbtt_offset;
125 uint8_t flags;
126 /* enum wil_wmi_ese_slot_type */
127 uint8_t slot_type;
128 /* duration in microseconds */
129 uint16_t duration;
130 /* frame exchange sequence duration, microseconds */
131 uint16_t tx_op;
132 /* time between 2 blocks for periodic allocation(microseconds) */
133 uint16_t period;
134 /* number of blocks in periodic allocation */
135 uint8_t num_blocks;
136 /* for semi-active allocations */
137 uint8_t idle_period;
138 uint8_t src_aid;
139 uint8_t dst_aid;
140 uint32_t reserved;
141} __attribute__((packed));
142
143#define WIL_WMI_MAX_ESE_SLOTS 4
144struct wil_wmi_ese_cfg {
145 uint8_t serial_num;
146 /* wil_wmi_sched_scheme_advertisment */
147 uint8_t ese_advertisment;
148 uint16_t flags;
149 uint8_t num_allocs;
150 uint8_t reserved[3];
151 uint64_t start_tbtt;
152 /* allocations list */
153 struct wil_wmi_ese_slot slots[WIL_WMI_MAX_ESE_SLOTS];
154} __attribute__((packed));
155
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +0200156#define WIL_WMI_UT_FORCE_MCS 6
157struct wil_wmi_force_mcs {
158 /* WIL_WMI_UT_HW_SYSAPI */
159 uint16_t module_id;
160 /* WIL_WMI_UT_FORCE_MCS */
161 uint16_t subtype_id;
162 /* cid (ignored in oob_mode, affects all stations) */
163 uint32_t cid;
164 /* 1 to force MCS, 0 to restore default behavior */
165 uint32_t force_enable;
166 /* MCS index, 0-12 */
167 uint32_t mcs;
168} __attribute__((packed));
169
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +0200170#define WIL_WMI_UT_HW_SYSAPI 10
171#define WIL_WMI_UT_FORCE_RSN_IE 0x29
172struct wil_wmi_force_rsn_ie {
173 /* WIL_WMI_UT_HW_SYSAPI */
174 uint16_t module_id;
175 /* WIL_WMI_UT_FORCE_RSN_IE */
176 uint16_t subtype_id;
177 /* 0 = no change, 1 = remove if exists, 2 = add if does not exist */
178 uint32_t state;
179} __attribute__((packed));
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +0300180
181enum wil_wmi_discovery_mode {
182 WMI_DISCOVERY_MODE_NON_OFFLOAD,
183 WMI_DISCOVERY_MODE_OFFLOAD,
184 WMI_DISCOVERY_MODE_PEER2PEER,
185};
186
187struct wil_wmi_p2p_cfg_cmd {
188 /* enum wil_wmi_discovery_mode */
189 uint8_t discovery_mode;
190 /* 0-based (wireless channel - 1) */
191 uint8_t channel;
192 /* set to WIL_DEFAULT_BI */
193 uint16_t bcon_interval;
194} __attribute__((packed));
Lior David0fe101e2017-03-09 16:09:50 +0200195#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200196
197#ifdef ANDROID
198
199static int add_ipv6_rule(struct sigma_dut *dut, const char *ifname);
200
201#define ANDROID_KEYSTORE_GET 'g'
202#define ANDROID_KEYSTORE_GET_PUBKEY 'b'
203
204static int android_keystore_get(char cmd, const char *key, unsigned char *val)
205{
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200206 /* Android 4.3 changed keystore design, so need to use keystore_get() */
207#ifndef KEYSTORE_MESSAGE_SIZE
208#define KEYSTORE_MESSAGE_SIZE 65535
209#endif /* KEYSTORE_MESSAGE_SIZE */
210
211 ssize_t len;
212 uint8_t *value = NULL;
213
214 __android_log_print(ANDROID_LOG_DEBUG, "sigma_dut",
215 "keystore command '%c' key '%s' --> keystore_get",
216 cmd, key);
217
218 len = keystore_get(key, strlen(key), &value);
219 if (len < 0) {
220 __android_log_print(ANDROID_LOG_DEBUG, "sigma_dut",
221 "keystore_get() failed");
222 return -1;
223 }
224
225 if (len > KEYSTORE_MESSAGE_SIZE)
226 len = KEYSTORE_MESSAGE_SIZE;
227 memcpy(val, value, len);
228 free(value);
229 return len;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200230}
231#endif /* ANDROID */
232
233
Vinita S. Maloo0fcb57d2020-04-24 14:03:56 +0530234#ifdef NL80211_SUPPORT
235static int nl80211_sta_set_power_save(struct sigma_dut *dut,
236 const char *intf,
237 enum nl80211_ps_state ps_state)
238{
239 struct nl_msg *msg;
240 int ifindex, ret;
241
242 ifindex = if_nametoindex(intf);
243 if (ifindex == 0) {
244 sigma_dut_print(dut, DUT_MSG_ERROR,
245 "%s: Index for interface %s not found",
246 __func__, intf);
247 return -1;
248 }
249
250 msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
251 NL80211_CMD_SET_POWER_SAVE);
252 if (!msg) {
253 sigma_dut_print(dut, DUT_MSG_ERROR,
254 "%s: err in creating nl80211 msg", __func__);
255 return -1;
256 }
257
258 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) {
259 sigma_dut_print(dut, DUT_MSG_ERROR,
260 "%s: err in populating nl80211 msg", __func__);
261 nlmsg_free(msg);
262 return -1;
263 }
264
265 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
266 if (ret) {
267 sigma_dut_print(dut, DUT_MSG_ERROR,
268 "%s: err in send_and_recv_msgs, ret=%d (%s)",
269 __func__, ret, strerror(-ret));
270 return -1;
271 }
272
273 return 0;
274}
275#endif /* NL80211_SUPPORT */
276
277
Vinita S. Malooa8b62722020-04-23 01:45:41 +0530278static int set_power_save_wcn(struct sigma_dut *dut, const char *intf, int ps)
279{
280 char buf[100];
Vinita S. Maloo0fcb57d2020-04-24 14:03:56 +0530281#ifdef NL80211_SUPPORT
282 enum nl80211_ps_state ps_state;
283
284 ps_state = ps == 1 ? NL80211_PS_ENABLED : NL80211_PS_DISABLED;
285 if (nl80211_sta_set_power_save(dut, intf, ps_state) == 0)
286 return 0;
287#endif /* NL80211_SUPPORT */
Vinita S. Malooa8b62722020-04-23 01:45:41 +0530288
289 snprintf(buf, sizeof(buf), "iwpriv %s setPower %d", intf, ps);
290 if (system(buf) != 0) {
291 sigma_dut_print(dut, DUT_MSG_ERROR,
292 "iwpriv setPower %d failed", ps);
293 return -1;
294 }
295 return 0;
296}
297
298
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200299int set_ps(const char *intf, struct sigma_dut *dut, int enabled)
300{
301#ifdef __linux__
302 char buf[100];
303
304 if (wifi_chip_type == DRIVER_WCN) {
305 if (enabled) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +0530306 if (set_power_save_wcn(dut, intf, 1) < 0) {
Purushottam Kushwaha304561d2019-12-23 16:57:18 +0530307 snprintf(buf, sizeof(buf),
308 "iwpriv wlan0 dump 906");
309 if (system(buf) != 0)
310 goto set_power_save;
311 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200312 } else {
Vinita S. Malooa8b62722020-04-23 01:45:41 +0530313 if (set_power_save_wcn(dut, intf, 2) < 0) {
Purushottam Kushwaha304561d2019-12-23 16:57:18 +0530314 snprintf(buf, sizeof(buf),
315 "iwpriv wlan0 dump 905");
316 if (system(buf) != 0)
317 goto set_power_save;
318 snprintf(buf, sizeof(buf),
319 "iwpriv wlan0 dump 912");
320 if (system(buf) != 0)
321 goto set_power_save;
322 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200323 }
324
325 return 0;
326 }
327
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530328set_power_save:
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200329 snprintf(buf, sizeof(buf), "./iw dev %s set power_save %s",
330 intf, enabled ? "on" : "off");
331 if (system(buf) != 0) {
332 snprintf(buf, sizeof(buf), "iw dev %s set power_save %s",
333 intf, enabled ? "on" : "off");
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530334 if (system(buf) != 0) {
335 sigma_dut_print(dut, DUT_MSG_ERROR,
336 "Failed to set power save %s",
337 enabled ? "on" : "off");
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200338 return -1;
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530339 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200340 }
341
342 return 0;
343#else /* __linux__ */
344 return -1;
345#endif /* __linux__ */
346}
347
348
Lior Davidcc88b562017-01-03 18:52:09 +0200349#ifdef __linux__
Lior David0fe101e2017-03-09 16:09:50 +0200350
Lior Davidcc88b562017-01-03 18:52:09 +0200351static int wil6210_get_debugfs_dir(struct sigma_dut *dut, char *path,
352 size_t len)
353{
354 DIR *dir, *wil_dir;
355 struct dirent *entry;
356 int ret = -1;
357 const char *root_path = "/sys/kernel/debug/ieee80211";
358
359 dir = opendir(root_path);
360 if (!dir)
361 return -2;
362
363 while ((entry = readdir(dir))) {
364 if (strcmp(entry->d_name, ".") == 0 ||
365 strcmp(entry->d_name, "..") == 0)
366 continue;
367
368 if (snprintf(path, len, "%s/%s/wil6210",
369 root_path, entry->d_name) >= (int) len) {
370 ret = -3;
371 break;
372 }
373
374 wil_dir = opendir(path);
375 if (wil_dir) {
376 closedir(wil_dir);
377 ret = 0;
378 break;
379 }
380 }
381
382 closedir(dir);
383 return ret;
384}
Lior David0fe101e2017-03-09 16:09:50 +0200385
386
387static int wil6210_wmi_send(struct sigma_dut *dut, uint16_t command,
388 void *payload, uint16_t length)
389{
390 struct {
391 struct wil_wmi_header hdr;
392 char payload[WIL_WMI_MAX_PAYLOAD];
393 } __attribute__((packed)) cmd;
394 char buf[128], fname[128];
395 size_t towrite, written;
396 FILE *f;
Jouni Malinen3aa72862019-05-29 23:14:51 +0300397 int res;
Lior David0fe101e2017-03-09 16:09:50 +0200398
399 if (length > WIL_WMI_MAX_PAYLOAD) {
400 sigma_dut_print(dut, DUT_MSG_ERROR,
401 "payload too large(%u, max %u)",
402 length, WIL_WMI_MAX_PAYLOAD);
403 return -1;
404 }
405
406 memset(&cmd.hdr, 0, sizeof(cmd.hdr));
407 cmd.hdr.cmd = command;
408 memcpy(cmd.payload, payload, length);
409
410 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
411 sigma_dut_print(dut, DUT_MSG_ERROR,
412 "failed to get wil6210 debugfs dir");
413 return -1;
414 }
415
Jouni Malinen3aa72862019-05-29 23:14:51 +0300416 res = snprintf(fname, sizeof(fname), "%s/wmi_send", buf);
417 if (res < 0 || res >= sizeof(fname))
418 return -1;
Lior David0fe101e2017-03-09 16:09:50 +0200419 f = fopen(fname, "wb");
420 if (!f) {
421 sigma_dut_print(dut, DUT_MSG_ERROR,
422 "failed to open: %s", fname);
423 return -1;
424 }
425
426 towrite = sizeof(cmd.hdr) + length;
427 written = fwrite(&cmd, 1, towrite, f);
428 fclose(f);
429 if (written != towrite) {
430 sigma_dut_print(dut, DUT_MSG_ERROR,
431 "failed to send wmi %u", command);
432 return -1;
433 }
434
435 return 0;
436}
437
438
439static int wil6210_get_sta_info_field(struct sigma_dut *dut, const char *bssid,
440 const char *pattern, unsigned int *field)
441{
442 char buf[128], fname[128];
443 FILE *f;
444 regex_t re;
445 regmatch_t m[2];
Jouni Malinen3aa72862019-05-29 23:14:51 +0300446 int rc, ret = -1, res;
Lior David0fe101e2017-03-09 16:09:50 +0200447
448 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
449 sigma_dut_print(dut, DUT_MSG_ERROR,
450 "failed to get wil6210 debugfs dir");
451 return -1;
452 }
453
Jouni Malinen3aa72862019-05-29 23:14:51 +0300454 res = snprintf(fname, sizeof(fname), "%s/stations", buf);
455 if (res < 0 || res >= sizeof(fname))
456 return -1;
Lior David0fe101e2017-03-09 16:09:50 +0200457 f = fopen(fname, "r");
458 if (!f) {
459 sigma_dut_print(dut, DUT_MSG_ERROR,
460 "failed to open: %s", fname);
461 return -1;
462 }
463
464 if (regcomp(&re, pattern, REG_EXTENDED)) {
465 sigma_dut_print(dut, DUT_MSG_ERROR,
466 "regcomp failed: %s", pattern);
467 goto out;
468 }
469
470 /*
471 * find the entry for the mac address
472 * line is of the form: [n] 11:22:33:44:55:66 state AID aid
473 */
474 while (fgets(buf, sizeof(buf), f)) {
475 if (strcasestr(buf, bssid)) {
476 /* extract the field (CID/AID/state) */
477 rc = regexec(&re, buf, 2, m, 0);
478 if (!rc && (m[1].rm_so >= 0)) {
479 buf[m[1].rm_eo] = 0;
480 *field = atoi(&buf[m[1].rm_so]);
481 ret = 0;
482 break;
483 }
484 }
485 }
486
487 regfree(&re);
488 if (ret)
489 sigma_dut_print(dut, DUT_MSG_ERROR,
490 "could not extract field");
491
492out:
493 fclose(f);
494
495 return ret;
496}
497
498
499static int wil6210_get_cid(struct sigma_dut *dut, const char *bssid,
500 unsigned int *cid)
501{
502 const char *pattern = "\\[([0-9]+)\\]";
503
504 return wil6210_get_sta_info_field(dut, bssid, pattern, cid);
505}
506
507
508static int wil6210_send_brp_rx(struct sigma_dut *dut, const char *mac,
509 int l_rx)
510{
Rakesh Sunki556237d2017-03-30 14:49:31 -0700511 struct wil_wmi_bf_trig_cmd cmd;
Lior David0fe101e2017-03-09 16:09:50 +0200512 unsigned int cid;
513
Rakesh Sunki556237d2017-03-30 14:49:31 -0700514 memset(&cmd, 0, sizeof(cmd));
515
Lior David0fe101e2017-03-09 16:09:50 +0200516 if (wil6210_get_cid(dut, mac, &cid))
517 return -1;
518
519 cmd.bf_type = WIL_WMI_BRP_RX;
520 cmd.sta_id = cid;
521 /* training length (l_rx) is ignored, FW always uses length 16 */
522 return wil6210_wmi_send(dut, WIL_WMI_BF_TRIG_CMDID,
523 &cmd, sizeof(cmd));
524}
525
526
527static int wil6210_send_sls(struct sigma_dut *dut, const char *mac)
528{
Rakesh Sunki556237d2017-03-30 14:49:31 -0700529 struct wil_wmi_bf_trig_cmd cmd;
530
531 memset(&cmd, 0, sizeof(cmd));
Lior David0fe101e2017-03-09 16:09:50 +0200532
533 if (parse_mac_address(dut, mac, (unsigned char *)&cmd.dest_mac))
534 return -1;
535
536 cmd.bf_type = WIL_WMI_SLS;
537 return wil6210_wmi_send(dut, WIL_WMI_BF_TRIG_CMDID,
538 &cmd, sizeof(cmd));
539}
540
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +0200541
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +0200542int wil6210_set_ese(struct sigma_dut *dut, int count,
543 struct sigma_ese_alloc *allocs)
544{
545 struct wil_wmi_ese_cfg cmd = { };
546 int i;
547
548 if (count == 0 || count > WIL_WMI_MAX_ESE_SLOTS)
549 return -1;
550
551 if (dut->ap_bcnint <= 0) {
552 sigma_dut_print(dut, DUT_MSG_ERROR,
553 "invalid beacon interval(%d), check test",
554 dut->ap_bcnint);
555 return -1;
556 }
557
558 cmd.ese_advertisment = WIL_WMI_ADVERTISE_ESE_IN_BEACON;
559 cmd.flags = 0x1d;
560 cmd.num_allocs = count;
561 for (i = 0; i < count; i++) {
562 /*
563 * Convert percent from BI (BI specified in milliseconds)
564 * to absolute duration in microseconds.
565 */
566 cmd.slots[i].duration =
567 (allocs[i].percent_bi * dut->ap_bcnint * 1000) / 100;
568 switch (allocs[i].type) {
569 case ESE_CBAP:
570 cmd.slots[i].slot_type = WIL_WMI_ESE_CBAP;
571 break;
572 case ESE_SP:
573 cmd.slots[i].slot_type = WIL_WMI_ESE_SP;
574 break;
575 default:
576 sigma_dut_print(dut, DUT_MSG_ERROR,
577 "invalid slot type(%d) at index %d",
578 allocs[i].type, i);
579 return -1;
580 }
581 cmd.slots[i].src_aid = allocs[i].src_aid;
582 cmd.slots[i].dst_aid = allocs[i].dst_aid;
583 sigma_dut_print(dut, DUT_MSG_INFO,
584 "slot %d, duration %u, type %d, srcAID %u dstAID %u",
585 i, cmd.slots[i].duration,
586 cmd.slots[i].slot_type, cmd.slots[i].src_aid,
587 cmd.slots[i].dst_aid);
588 }
589
590 return wil6210_wmi_send(dut, WIL_WMI_ESE_CFG_CMDID, &cmd, sizeof(cmd));
591}
592
593
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +0200594int wil6210_set_force_mcs(struct sigma_dut *dut, int force, int mcs)
595{
596 struct wil_wmi_force_mcs cmd = { };
597
598 cmd.module_id = WIL_WMI_UT_HW_SYSAPI;
599 cmd.subtype_id = WIL_WMI_UT_FORCE_MCS;
600 cmd.force_enable = (uint32_t) force;
601 cmd.mcs = (uint32_t) mcs;
602
603 return wil6210_wmi_send(dut, WIL_WMI_UNIT_TEST_CMDID,
604 &cmd, sizeof(cmd));
605}
606
607
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +0200608static int wil6210_force_rsn_ie(struct sigma_dut *dut, int state)
609{
610 struct wil_wmi_force_rsn_ie cmd = { };
611
612 cmd.module_id = WIL_WMI_UT_HW_SYSAPI;
613 cmd.subtype_id = WIL_WMI_UT_FORCE_RSN_IE;
614 cmd.state = (uint32_t) state;
615
616 return wil6210_wmi_send(dut, WIL_WMI_UNIT_TEST_CMDID,
617 &cmd, sizeof(cmd));
618}
619
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +0300620
621/*
622 * this function is also used to configure generic remain-on-channel
623 */
624static int wil6210_p2p_cfg(struct sigma_dut *dut, int freq)
625{
626 struct wil_wmi_p2p_cfg_cmd cmd = { };
627 int channel = freq_to_channel(freq);
628
629 if (channel < 0)
630 return -1;
631 cmd.discovery_mode = WMI_DISCOVERY_MODE_NON_OFFLOAD;
632 cmd.channel = channel - 1;
633 cmd.bcon_interval = WIL_DEFAULT_BI;
634 cmd.discovery_mode = WMI_DISCOVERY_MODE_PEER2PEER;
635
636 return wil6210_wmi_send(dut, WIL_WMI_P2P_CFG_CMDID,
637 &cmd, sizeof(cmd));
638}
639
640
641static int wil6210_remain_on_channel(struct sigma_dut *dut, int freq)
642{
643 int ret = wil6210_p2p_cfg(dut, freq);
644
645 if (ret)
646 return ret;
647
648 ret = wil6210_wmi_send(dut, WIL_WMI_START_LISTEN_CMDID, NULL, 0);
649 if (!ret) {
650 /*
651 * wait a bit to allow FW to setup the radio
652 * especially important if we switch channels
653 */
654 usleep(500000);
655 }
656
657 return ret;
658}
659
660
661static int wil6210_stop_discovery(struct sigma_dut *dut)
662{
663 return wil6210_wmi_send(dut, WIL_WMI_DISCOVERY_STOP_CMDID, NULL, 0);
664}
665
666
667static int wil6210_transmit_frame(struct sigma_dut *dut, int freq,
668 int wait_duration,
669 const char *frame, size_t frame_len)
670{
671 char buf[128], fname[128];
672 FILE *f;
Jouni Malinen3aa72862019-05-29 23:14:51 +0300673 int res = 0, r;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +0300674 size_t written;
675
676 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
677 sigma_dut_print(dut, DUT_MSG_ERROR,
678 "failed to get wil6210 debugfs dir");
679 return -1;
680 }
Jouni Malinen3aa72862019-05-29 23:14:51 +0300681 r = snprintf(fname, sizeof(fname), "%s/tx_mgmt", buf);
682 if (r < 0 || r >= sizeof(fname))
683 return -1;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +0300684
685 if (wil6210_remain_on_channel(dut, freq)) {
686 sigma_dut_print(dut, DUT_MSG_ERROR,
687 "failed to listen on channel");
688 return -1;
689 }
690
691 f = fopen(fname, "wb");
692 if (!f) {
693 sigma_dut_print(dut, DUT_MSG_ERROR,
694 "failed to open: %s", fname);
695 res = -1;
696 goto out_stop;
697 }
698 written = fwrite(frame, 1, frame_len, f);
699 fclose(f);
700
701 if (written != frame_len) {
702 sigma_dut_print(dut, DUT_MSG_ERROR,
703 "failed to transmit frame (got %zd, expected %zd)",
704 written, frame_len);
705 res = -1;
706 goto out_stop;
707 }
708
709 usleep(wait_duration * 1000);
710
711out_stop:
712 wil6210_stop_discovery(dut);
713 return res;
714}
715
716
717static int find_template_frame_tag(struct template_frame_tag *tags,
718 int total_tags, int tag_num)
719{
720 int i;
721
722 for (i = 0; i < total_tags; i++) {
723 if (tag_num == tags[i].num)
724 return i;
725 }
726
727 return -1;
728}
729
730
731static int replace_p2p_attribute(struct sigma_dut *dut, char *buf, size_t len,
732 int id, const char *value, size_t val_len)
733{
734 struct wfa_p2p_attribute *attr = (struct wfa_p2p_attribute *) buf;
735
736 if (len < 3 + val_len) {
737 sigma_dut_print(dut, DUT_MSG_ERROR,
738 "not enough space to replace P2P attribute");
739 return -1;
740 }
741
742 if (attr->len != val_len) {
743 sigma_dut_print(dut, DUT_MSG_ERROR,
744 "attribute length mismatch (need %zu have %hu)",
745 val_len, attr->len);
746 return -1;
747 }
748
749 if (attr->id != id) {
750 sigma_dut_print(dut, DUT_MSG_ERROR,
751 "incorrect attribute id (expected %d actual %d)",
752 id, attr->id);
753 return -1;
754 }
755
756 memcpy(attr->variable, value, val_len);
757
758 return 0;
759}
760
761
762static int parse_template_frame_file(struct sigma_dut *dut, const char *fname,
763 char *buf, size_t *length,
764 struct template_frame_tag *tags,
765 size_t *num_tags)
766{
767 char line[512];
768 FILE *f;
769 size_t offset = 0, tag_index = 0;
770 int num, index;
771 int in_tag = 0, tag_num = 0, tag_offset = 0;
772
773 if (*length < sizeof(struct ieee80211_hdr_3addr)) {
774 sigma_dut_print(dut, DUT_MSG_ERROR,
775 "supplied buffer is too small");
776 return -1;
777 }
778
779 f = fopen(fname, "r");
780 if (!f) {
781 sigma_dut_print(dut, DUT_MSG_ERROR,
782 "failed to open template file %s", fname);
783 return -1;
784 }
785
786 /*
787 * template file format: lines beginning with # are comments and
788 * ignored.
789 * It is possible to tag bytes in the frame to make it easy
790 * to replace fields in the template, espcially if they appear
791 * in variable-sized sections (such as IEs)
792 * This is done by a line beginning with $NUM where NUM is an integer
793 * tag number. It can be followed by space(s) and comment.
794 * The next line is considered the tagged bytes. The parser will fill
795 * the tag number, offset and length of the tagged bytes.
796 * rest of the lines contain frame bytes as sequence of hex digits,
797 * 2 digits for each byte. Spaces are allowed between bytes.
798 * On bytes lines only hex digits and spaces are allowed
799 */
800 while (!feof(f)) {
801 if (!fgets(line, sizeof(line), f))
802 break;
803 index = 0;
804 while (isspace((unsigned char) line[index]))
805 index++;
806 if (!line[index] || line[index] == '#')
807 continue;
808 if (line[index] == '$') {
809 if (tags) {
810 index++;
811 tag_num = strtol(&line[index], NULL, 0);
812 tag_offset = offset;
813 in_tag = 1;
814 }
815 continue;
816 }
817 while (line[index]) {
818 if (isspace((unsigned char) line[index])) {
819 index++;
820 continue;
821 }
822 num = hex_byte(&line[index]);
823 if (num < 0)
824 break;
825 buf[offset++] = num;
826 if (offset == *length)
827 goto out;
828 index += 2;
829 }
830
831 if (in_tag) {
832 if (tag_index < *num_tags) {
833 tags[tag_index].num = tag_num;
834 tags[tag_index].offset = tag_offset;
835 tags[tag_index].len = offset - tag_offset;
836 tag_index++;
837 } else {
838 sigma_dut_print(dut, DUT_MSG_INFO,
839 "too many tags, tag ignored");
840 }
841 in_tag = 0;
842 }
843 }
844
845 if (num_tags)
846 *num_tags = tag_index;
847out:
848 fclose(f);
849 if (offset < sizeof(struct ieee80211_hdr_3addr)) {
850 sigma_dut_print(dut, DUT_MSG_ERROR,
851 "template frame is too small");
852 return -1;
853 }
854
855 *length = offset;
856 return 0;
857}
858
Lior Davidcc88b562017-01-03 18:52:09 +0200859#endif /* __linux__ */
860
861
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200862static void static_ip_file(int proto, const char *addr, const char *mask,
863 const char *gw)
864{
865 if (proto) {
866 FILE *f = fopen("static-ip", "w");
867 if (f) {
868 fprintf(f, "%d %s %s %s\n", proto, addr,
869 mask ? mask : "N/A",
870 gw ? gw : "N/A");
871 fclose(f);
872 }
873 } else {
874 unlink("static-ip");
875 }
876}
877
878
879static int send_neighbor_request(struct sigma_dut *dut, const char *intf,
880 const char *ssid)
881{
882#ifdef __linux__
883 char buf[100];
884
885 snprintf(buf, sizeof(buf), "iwpriv %s neighbor %s",
886 intf, ssid);
887 sigma_dut_print(dut, DUT_MSG_INFO, "Request: %s", buf);
888
889 if (system(buf) != 0) {
890 sigma_dut_print(dut, DUT_MSG_ERROR,
891 "iwpriv neighbor request failed");
892 return -1;
893 }
894
895 sigma_dut_print(dut, DUT_MSG_INFO, "iwpriv neighbor request send");
896
897 return 0;
898#else /* __linux__ */
899 return -1;
900#endif /* __linux__ */
901}
902
903
904static int send_trans_mgmt_query(struct sigma_dut *dut, const char *intf,
Ashwini Patil5acd7382017-04-13 15:55:04 +0530905 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200906{
Ashwini Patil5acd7382017-04-13 15:55:04 +0530907 const char *val;
908 int reason_code = 0;
909 char buf[1024];
910
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200911 /*
912 * In the earlier builds we used WNM_QUERY and in later
913 * builds used WNM_BSS_QUERY.
914 */
915
Ashwini Patil5acd7382017-04-13 15:55:04 +0530916 val = get_param(cmd, "BTMQuery_Reason_Code");
917 if (val)
918 reason_code = atoi(val);
919
920 val = get_param(cmd, "Cand_List");
921 if (val && atoi(val) == 1 && dut->btm_query_cand_list) {
922 snprintf(buf, sizeof(buf), "WNM_BSS_QUERY %d%s", reason_code,
923 dut->btm_query_cand_list);
924 free(dut->btm_query_cand_list);
925 dut->btm_query_cand_list = NULL;
926 } else {
927 snprintf(buf, sizeof(buf), "WNM_BSS_QUERY %d", reason_code);
928 }
929
930 if (wpa_command(intf, buf) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200931 sigma_dut_print(dut, DUT_MSG_ERROR,
932 "transition management query failed");
933 return -1;
934 }
935
936 sigma_dut_print(dut, DUT_MSG_DEBUG,
937 "transition management query sent");
938
939 return 0;
940}
941
942
943int is_ip_addr(const char *str)
944{
945 const char *pos = str;
946 struct in_addr addr;
947
948 while (*pos) {
949 if (*pos != '.' && (*pos < '0' || *pos > '9'))
950 return 0;
951 pos++;
952 }
953
954 return inet_aton(str, &addr);
955}
956
957
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200958int get_ip_config(struct sigma_dut *dut, const char *ifname, char *buf,
959 size_t buf_len)
960{
vamsi krishnaa11d0732018-05-16 12:19:48 +0530961 char tmp[256];
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200962 char ip[16], mask[15], dns[16], sec_dns[16];
963 int is_dhcp = 0;
964 int s;
965#ifdef ANDROID
966 char prop[PROPERTY_VALUE_MAX];
vamsi krishnaa11d0732018-05-16 12:19:48 +0530967#else /* ANDROID */
968 FILE *f;
969#ifdef __linux__
970 const char *str_ps;
971#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200972#endif /* ANDROID */
973
974 ip[0] = '\0';
975 mask[0] = '\0';
976 dns[0] = '\0';
977 sec_dns[0] = '\0';
978
979 s = socket(PF_INET, SOCK_DGRAM, 0);
980 if (s >= 0) {
981 struct ifreq ifr;
982 struct sockaddr_in saddr;
983
984 memset(&ifr, 0, sizeof(ifr));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700985 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200986 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
987 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get "
988 "%s IP address: %s",
989 ifname, strerror(errno));
990 } else {
991 memcpy(&saddr, &ifr.ifr_addr,
992 sizeof(struct sockaddr_in));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700993 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200994 }
995
996 if (ioctl(s, SIOCGIFNETMASK, &ifr) == 0) {
997 memcpy(&saddr, &ifr.ifr_addr,
998 sizeof(struct sockaddr_in));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700999 strlcpy(mask, inet_ntoa(saddr.sin_addr), sizeof(mask));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001000 }
1001 close(s);
1002 }
1003
1004#ifdef ANDROID
1005 snprintf(tmp, sizeof(tmp), "dhcp.%s.pid", ifname);
1006 if (property_get(tmp, prop, NULL) != 0 && atoi(prop) > 0) {
1007 snprintf(tmp, sizeof(tmp), "dhcp.%s.result", ifname);
1008 if (property_get(tmp, prop, NULL) != 0 &&
1009 strcmp(prop, "ok") == 0) {
1010 snprintf(tmp, sizeof(tmp), "dhcp.%s.ipaddress",
1011 ifname);
1012 if (property_get(tmp, prop, NULL) != 0 &&
1013 strcmp(ip, prop) == 0)
1014 is_dhcp = 1;
1015 }
1016 }
1017
1018 snprintf(tmp, sizeof(tmp), "dhcp.%s.dns1", ifname);
Peng Xub8fc5cc2017-05-10 17:27:28 -07001019 if (property_get(tmp, prop, NULL) != 0)
1020 strlcpy(dns, prop, sizeof(dns));
1021 else if (property_get("net.dns1", prop, NULL) != 0)
1022 strlcpy(dns, prop, sizeof(dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001023
1024 snprintf(tmp, sizeof(tmp), "dhcp.%s.dns2", ifname);
Peng Xub8fc5cc2017-05-10 17:27:28 -07001025 if (property_get(tmp, prop, NULL) != 0)
1026 strlcpy(sec_dns, prop, sizeof(sec_dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001027#else /* ANDROID */
1028#ifdef __linux__
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001029 if (get_driver_type(dut) == DRIVER_OPENWRT)
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +05301030 str_ps = "ps -w";
1031 else
1032 str_ps = "ps ax";
1033 snprintf(tmp, sizeof(tmp),
1034 "%s | grep dhclient | grep -v grep | grep -q %s",
1035 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001036 if (system(tmp) == 0)
1037 is_dhcp = 1;
1038 else {
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +05301039 snprintf(tmp, sizeof(tmp),
1040 "%s | grep udhcpc | grep -v grep | grep -q %s",
1041 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001042 if (system(tmp) == 0)
1043 is_dhcp = 1;
1044 else {
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +05301045 snprintf(tmp, sizeof(tmp),
1046 "%s | grep dhcpcd | grep -v grep | grep -q %s",
1047 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001048 if (system(tmp) == 0)
1049 is_dhcp = 1;
1050 }
1051 }
1052#endif /* __linux__ */
1053
1054 f = fopen("/etc/resolv.conf", "r");
1055 if (f) {
vamsi krishnaa11d0732018-05-16 12:19:48 +05301056 char *pos, *pos2;
1057
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001058 while (fgets(tmp, sizeof(tmp), f)) {
1059 if (strncmp(tmp, "nameserver", 10) != 0)
1060 continue;
1061 pos = tmp + 10;
1062 while (*pos == ' ' || *pos == '\t')
1063 pos++;
1064 pos2 = pos;
1065 while (*pos2) {
1066 if (*pos2 == '\n' || *pos2 == '\r') {
1067 *pos2 = '\0';
1068 break;
1069 }
1070 pos2++;
1071 }
Peng Xub8fc5cc2017-05-10 17:27:28 -07001072 if (!dns[0])
1073 strlcpy(dns, pos, sizeof(dns));
1074 else if (!sec_dns[0])
1075 strlcpy(sec_dns, pos, sizeof(sec_dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001076 }
1077 fclose(f);
1078 }
1079#endif /* ANDROID */
1080
1081 snprintf(buf, buf_len, "dhcp,%d,ip,%s,mask,%s,primary-dns,%s",
1082 is_dhcp, ip, mask, dns);
1083 buf[buf_len - 1] = '\0';
1084
1085 return 0;
1086}
1087
1088
1089
1090
1091int get_ipv6_config(struct sigma_dut *dut, const char *ifname, char *buf,
1092 size_t buf_len)
1093{
1094#ifdef __linux__
1095#ifdef ANDROID
1096 char cmd[200], result[1000], *pos, *end;
1097 FILE *f;
1098 size_t len;
1099
1100 snprintf(cmd, sizeof(cmd), "ip addr show dev %s scope global", ifname);
1101 f = popen(cmd, "r");
1102 if (f == NULL)
1103 return -1;
1104 len = fread(result, 1, sizeof(result) - 1, f);
1105 pclose(f);
1106 if (len == 0)
1107 return -1;
1108 result[len] = '\0';
1109 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s result: %s\n", cmd, result);
1110
1111 pos = strstr(result, "inet6 ");
1112 if (pos == NULL)
1113 return -1;
1114 pos += 6;
1115 end = strchr(pos, ' ');
1116 if (end)
1117 *end = '\0';
1118 end = strchr(pos, '/');
1119 if (end)
1120 *end = '\0';
1121 snprintf(buf, buf_len, "ip,%s", pos);
1122 buf[buf_len - 1] = '\0';
1123 return 0;
1124#else /* ANDROID */
1125 struct ifaddrs *ifaddr, *ifa;
1126 int res, found = 0;
1127 char host[NI_MAXHOST];
1128
1129 if (getifaddrs(&ifaddr) < 0) {
1130 perror("getifaddrs");
1131 return -1;
1132 }
1133
1134 for (ifa = ifaddr; ifa; ifa = ifa->ifa_next) {
1135 if (strcasecmp(ifname, ifa->ifa_name) != 0)
1136 continue;
1137 if (ifa->ifa_addr == NULL ||
1138 ifa->ifa_addr->sa_family != AF_INET6)
1139 continue;
1140
1141 res = getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in6),
1142 host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
1143 if (res != 0) {
1144 sigma_dut_print(dut, DUT_MSG_DEBUG, "getnameinfo: %s",
1145 gai_strerror(res));
1146 continue;
1147 }
1148 if (strncmp(host, "fe80::", 6) == 0)
1149 continue; /* skip link-local */
1150
1151 sigma_dut_print(dut, DUT_MSG_DEBUG, "ifaddr: %s", host);
1152 found = 1;
1153 break;
1154 }
1155
1156 freeifaddrs(ifaddr);
1157
1158 if (found) {
1159 char *pos;
1160 pos = strchr(host, '%');
1161 if (pos)
1162 *pos = '\0';
1163 snprintf(buf, buf_len, "ip,%s", host);
1164 buf[buf_len - 1] = '\0';
1165 return 0;
1166 }
1167
1168#endif /* ANDROID */
1169#endif /* __linux__ */
1170 return -1;
1171}
1172
1173
Jouni Malinenf7222712019-06-13 01:50:21 +03001174static enum sigma_cmd_result cmd_sta_get_ip_config(struct sigma_dut *dut,
1175 struct sigma_conn *conn,
1176 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001177{
1178 const char *intf = get_param(cmd, "Interface");
1179 const char *ifname;
1180 char buf[200];
1181 const char *val;
1182 int type = 1;
1183
1184 if (intf == NULL)
1185 return -1;
1186
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001187 if (strcmp(intf, get_main_ifname(dut)) == 0)
1188 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001189 else
1190 ifname = intf;
1191
1192 /*
1193 * UCC may assume the IP address to be available immediately after
1194 * association without trying to run sta_get_ip_config multiple times.
1195 * Sigma CAPI does not specify this command as a block command that
1196 * would wait for the address to become available, but to pass tests
1197 * more reliably, it looks like such a wait may be needed here.
1198 */
1199 if (wait_ip_addr(dut, ifname, 15) < 0) {
1200 sigma_dut_print(dut, DUT_MSG_INFO, "Could not get IP address "
1201 "for sta_get_ip_config");
1202 /*
1203 * Try to continue anyway since many UCC tests do not really
1204 * care about the return value from here..
1205 */
1206 }
1207
1208 val = get_param(cmd, "Type");
1209 if (val)
1210 type = atoi(val);
1211 if (type == 2 || dut->last_set_ip_config_ipv6) {
1212 int i;
1213
1214 /*
1215 * Since we do not have proper wait for IPv6 addresses, use a
1216 * fixed two second delay here as a workaround for UCC script
1217 * assuming IPv6 address is available when this command returns.
1218 * Some scripts did not use Type,2 properly for IPv6, so include
1219 * also the cases where the previous sta_set_ip_config indicated
1220 * use of IPv6.
1221 */
1222 sigma_dut_print(dut, DUT_MSG_INFO, "Wait up to extra ten seconds in sta_get_ip_config for IPv6 address");
1223 for (i = 0; i < 10; i++) {
1224 sleep(1);
1225 if (get_ipv6_config(dut, ifname, buf, sizeof(buf)) == 0)
1226 {
1227 sigma_dut_print(dut, DUT_MSG_INFO, "Found IPv6 address");
1228 send_resp(dut, conn, SIGMA_COMPLETE, buf);
1229#ifdef ANDROID
1230 sigma_dut_print(dut, DUT_MSG_INFO,
1231 "Adding IPv6 rule on Android");
1232 add_ipv6_rule(dut, intf);
1233#endif /* ANDROID */
1234
1235 return 0;
1236 }
1237 }
1238 }
1239 if (type == 1) {
1240 if (get_ip_config(dut, ifname, buf, sizeof(buf)) < 0)
1241 return -2;
1242 } else if (type == 2) {
1243 if (get_ipv6_config(dut, ifname, buf, sizeof(buf)) < 0)
1244 return -2;
1245 } else {
1246 send_resp(dut, conn, SIGMA_ERROR,
1247 "errorCode,Unsupported address type");
1248 return 0;
1249 }
1250
1251 send_resp(dut, conn, SIGMA_COMPLETE, buf);
1252 return 0;
1253}
1254
1255
1256static void kill_dhcp_client(struct sigma_dut *dut, const char *ifname)
1257{
1258#ifdef __linux__
1259 char buf[200];
1260 char path[128];
1261 struct stat s;
1262
1263#ifdef ANDROID
1264 snprintf(path, sizeof(path), "/data/misc/dhcp/dhcpcd-%s.pid", ifname);
1265#else /* ANDROID */
1266 snprintf(path, sizeof(path), "/var/run/dhclient-%s.pid", ifname);
1267#endif /* ANDROID */
1268 if (stat(path, &s) == 0) {
1269 snprintf(buf, sizeof(buf), "kill `cat %s`", path);
1270 sigma_dut_print(dut, DUT_MSG_INFO,
1271 "Kill previous DHCP client: %s", buf);
1272 if (system(buf) != 0)
1273 sigma_dut_print(dut, DUT_MSG_INFO,
1274 "Failed to kill DHCP client");
1275 unlink(path);
1276 sleep(1);
1277 } else {
1278 snprintf(path, sizeof(path), "/var/run/dhcpcd-%s.pid", ifname);
1279
1280 if (stat(path, &s) == 0) {
1281 snprintf(buf, sizeof(buf), "kill `cat %s`", path);
1282 sigma_dut_print(dut, DUT_MSG_INFO,
1283 "Kill previous DHCP client: %s", buf);
1284 if (system(buf) != 0)
1285 sigma_dut_print(dut, DUT_MSG_INFO,
1286 "Failed to kill DHCP client");
1287 unlink(path);
1288 sleep(1);
1289 }
1290 }
1291#endif /* __linux__ */
1292}
1293
1294
1295static int start_dhcp_client(struct sigma_dut *dut, const char *ifname)
1296{
1297#ifdef __linux__
1298 char buf[200];
1299
1300#ifdef ANDROID
Purushottam Kushwaha46d64262016-08-23 17:57:53 +05301301 if (access("/system/bin/dhcpcd", F_OK) != -1) {
1302 snprintf(buf, sizeof(buf),
1303 "/system/bin/dhcpcd -b %s", ifname);
1304 } else if (access("/system/bin/dhcptool", F_OK) != -1) {
1305 snprintf(buf, sizeof(buf), "/system/bin/dhcptool %s &", ifname);
Ankita Bajaj8454e5d2019-04-05 16:04:55 +05301306 } else if (access("/vendor/bin/dhcpcd", F_OK) != -1) {
1307 snprintf(buf, sizeof(buf), "/vendor/bin/dhcpcd -b %s", ifname);
1308 } else if (access("/vendor/bin/dhcptool", F_OK) != -1) {
1309 snprintf(buf, sizeof(buf), "/vendor/bin/dhcptool %s", ifname);
Purushottam Kushwaha46d64262016-08-23 17:57:53 +05301310 } else {
1311 sigma_dut_print(dut, DUT_MSG_ERROR,
1312 "DHCP client program missing");
1313 return 0;
1314 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001315#else /* ANDROID */
1316 snprintf(buf, sizeof(buf),
1317 "dhclient -nw -pf /var/run/dhclient-%s.pid %s",
1318 ifname, ifname);
1319#endif /* ANDROID */
1320 sigma_dut_print(dut, DUT_MSG_INFO, "Start DHCP client: %s", buf);
1321 if (system(buf) != 0) {
1322 snprintf(buf, sizeof(buf), "dhcpcd -t 0 %s &", ifname);
1323 if (system(buf) != 0) {
1324 sigma_dut_print(dut, DUT_MSG_INFO,
1325 "Failed to start DHCP client");
1326#ifndef ANDROID
1327 return -1;
1328#endif /* ANDROID */
1329 }
1330 }
1331#endif /* __linux__ */
1332
1333 return 0;
1334}
1335
1336
1337static int clear_ip_addr(struct sigma_dut *dut, const char *ifname)
1338{
1339#ifdef __linux__
1340 char buf[200];
1341
1342 snprintf(buf, sizeof(buf), "ip addr flush dev %s", ifname);
1343 if (system(buf) != 0) {
1344 sigma_dut_print(dut, DUT_MSG_INFO,
1345 "Failed to clear IP addresses");
1346 return -1;
1347 }
1348#endif /* __linux__ */
1349
1350 return 0;
1351}
1352
1353
1354#ifdef ANDROID
1355static int add_ipv6_rule(struct sigma_dut *dut, const char *ifname)
1356{
1357 char cmd[200], *result, *pos;
1358 FILE *fp;
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +05301359 int tableid;
1360 size_t len, result_len = 1000;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001361
1362 snprintf(cmd, sizeof(cmd), "ip -6 route list table all | grep %s",
1363 ifname);
1364 fp = popen(cmd, "r");
1365 if (fp == NULL)
1366 return -1;
1367
1368 result = malloc(result_len);
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05301369 if (result == NULL) {
1370 fclose(fp);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001371 return -1;
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05301372 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001373
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +05301374 len = fread(result, 1, result_len - 1, fp);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001375 fclose(fp);
1376
1377 if (len == 0) {
1378 free(result);
1379 return -1;
1380 }
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +05301381 result[len] = '\0';
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001382
1383 pos = strstr(result, "table ");
1384 if (pos == NULL) {
1385 free(result);
1386 return -1;
1387 }
1388
1389 pos += strlen("table ");
1390 tableid = atoi(pos);
1391 if (tableid != 0) {
1392 if (system("ip -6 rule del prio 22000") != 0) {
1393 /* ignore any error */
1394 }
1395 snprintf(cmd, sizeof(cmd),
1396 "ip -6 rule add from all lookup %d prio 22000",
1397 tableid);
1398 if (system(cmd) != 0) {
1399 sigma_dut_print(dut, DUT_MSG_INFO,
1400 "Failed to run %s", cmd);
1401 free(result);
1402 return -1;
1403 }
1404 } else {
1405 sigma_dut_print(dut, DUT_MSG_INFO,
1406 "No Valid Table Id found %s", pos);
1407 free(result);
1408 return -1;
1409 }
1410 free(result);
1411
1412 return 0;
1413}
1414#endif /* ANDROID */
1415
1416
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301417int set_ipv4_addr(struct sigma_dut *dut, const char *ifname,
1418 const char *ip, const char *mask)
1419{
1420 char buf[200];
1421
1422 snprintf(buf, sizeof(buf), "ifconfig %s %s netmask %s",
1423 ifname, ip, mask);
1424 return system(buf) == 0;
1425}
1426
1427
1428int set_ipv4_gw(struct sigma_dut *dut, const char *gw)
1429{
1430 char buf[200];
1431
1432 if (!is_ip_addr(gw)) {
1433 sigma_dut_print(dut, DUT_MSG_DEBUG, "Invalid gw addr - %s", gw);
1434 return -1;
1435 }
1436
1437 snprintf(buf, sizeof(buf), "route add default gw %s", gw);
1438 if (!dut->no_ip_addr_set && system(buf) != 0) {
1439 snprintf(buf, sizeof(buf), "ip ro re default via %s",
1440 gw);
1441 if (system(buf) != 0)
1442 return 0;
1443 }
1444
1445 return 1;
1446}
1447
1448
Jouni Malinenf7222712019-06-13 01:50:21 +03001449static enum sigma_cmd_result cmd_sta_set_ip_config(struct sigma_dut *dut,
1450 struct sigma_conn *conn,
1451 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001452{
1453 const char *intf = get_param(cmd, "Interface");
1454 const char *ifname;
1455 char buf[200];
1456 const char *val, *ip, *mask, *gw;
1457 int type = 1;
1458
1459 if (intf == NULL)
1460 return -1;
1461
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001462 if (strcmp(intf, get_main_ifname(dut)) == 0)
1463 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001464 else
1465 ifname = intf;
1466
1467 if (if_nametoindex(ifname) == 0) {
1468 send_resp(dut, conn, SIGMA_ERROR,
1469 "ErrorCode,Unknown interface");
1470 return 0;
1471 }
1472
1473 val = get_param(cmd, "Type");
1474 if (val) {
1475 type = atoi(val);
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301476 if (type < 1 || type > 3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001477 send_resp(dut, conn, SIGMA_ERROR,
1478 "ErrorCode,Unsupported address type");
1479 return 0;
1480 }
1481 }
1482
1483 dut->last_set_ip_config_ipv6 = 0;
1484
1485 val = get_param(cmd, "dhcp");
1486 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "true") == 0)) {
1487 static_ip_file(0, NULL, NULL, NULL);
1488#ifdef __linux__
1489 if (type == 2) {
1490 dut->last_set_ip_config_ipv6 = 1;
1491 sigma_dut_print(dut, DUT_MSG_INFO, "Using IPv6 "
1492 "stateless address autoconfiguration");
1493#ifdef ANDROID
1494 /*
1495 * This sleep is required as the assignment in case of
1496 * Android is taking time and is done by the kernel.
1497 * The subsequent ping for IPv6 is impacting HS20 test
1498 * case.
1499 */
1500 sleep(2);
1501 add_ipv6_rule(dut, intf);
1502#endif /* ANDROID */
1503 /* Assume this happens by default */
1504 return 1;
1505 }
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301506 if (type != 3) {
1507 kill_dhcp_client(dut, ifname);
1508 if (start_dhcp_client(dut, ifname) < 0)
1509 return -2;
1510 } else {
1511 sigma_dut_print(dut, DUT_MSG_DEBUG,
1512 "Using FILS HLP DHCPv4 Rapid Commit");
1513 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001514
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001515 return 1;
1516#endif /* __linux__ */
1517 return -2;
1518 }
1519
1520 ip = get_param(cmd, "ip");
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301521 if (!ip) {
1522 send_resp(dut, conn, SIGMA_INVALID,
1523 "ErrorCode,Missing IP address");
1524 return 0;
1525 }
1526
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001527 mask = get_param(cmd, "mask");
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301528 if (!mask) {
1529 send_resp(dut, conn, SIGMA_INVALID,
1530 "ErrorCode,Missing subnet mask");
1531 return 0;
1532 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001533
1534 if (type == 2) {
1535 int net = atoi(mask);
1536
1537 if ((net < 0 && net > 64) || !is_ipv6_addr(ip))
1538 return -1;
1539
1540 if (dut->no_ip_addr_set) {
1541 snprintf(buf, sizeof(buf),
1542 "sysctl net.ipv6.conf.%s.disable_ipv6=1",
1543 ifname);
1544 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
1545 if (system(buf) != 0) {
1546 sigma_dut_print(dut, DUT_MSG_DEBUG,
1547 "Failed to disable IPv6 address before association");
1548 }
1549 } else {
Veerendranath Jakkam176181c2020-05-16 00:19:21 +05301550 if (set_ipv6_addr(dut, ip, mask, ifname) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001551 send_resp(dut, conn, SIGMA_ERROR,
1552 "ErrorCode,Failed to set IPv6 address");
1553 return 0;
1554 }
1555 }
1556
1557 dut->last_set_ip_config_ipv6 = 1;
1558 static_ip_file(6, ip, mask, NULL);
1559 return 1;
1560 } else if (type == 1) {
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301561 if (!is_ip_addr(ip) || !is_ip_addr(mask))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001562 return -1;
1563 }
1564
1565 kill_dhcp_client(dut, ifname);
1566
1567 if (!dut->no_ip_addr_set) {
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301568 if (!set_ipv4_addr(dut, ifname, ip, mask)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001569 send_resp(dut, conn, SIGMA_ERROR,
1570 "ErrorCode,Failed to set IP address");
1571 return 0;
1572 }
1573 }
1574
1575 gw = get_param(cmd, "defaultGateway");
1576 if (gw) {
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301577 if (set_ipv4_gw(dut, gw) < 1) {
1578 send_resp(dut, conn, SIGMA_ERROR,
1579 "ErrorCode,Failed to set default gateway");
1580 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001581 }
1582 }
1583
1584 val = get_param(cmd, "primary-dns");
1585 if (val) {
Vinita S. Maloo069e8d42021-04-29 13:15:08 +05301586#ifdef ANDROID
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001587 /* TODO */
1588 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored primary-dns %s "
1589 "setting", val);
Vinita S. Maloo069e8d42021-04-29 13:15:08 +05301590#else /* ANDROID */
1591 char dns_cmd[200];
1592 int len;
1593
1594 if (system("sed -i '/nameserver/d' /etc/resolv.conf") != 0) {
1595 sigma_dut_print(dut, DUT_MSG_ERROR,
1596 "Failed to clear nameserver entries in /etc/resolv.conf");
1597 return ERROR_SEND_STATUS;
1598 }
1599
1600 len = snprintf(dns_cmd, sizeof(dns_cmd),
1601 "sed -i '1 i nameserver %s' /etc/resolv.conf", val);
1602 if (len < 0 || len >= sizeof(dns_cmd))
1603 return ERROR_SEND_STATUS;
1604
1605 sigma_dut_print(dut, DUT_MSG_DEBUG, "Running %s", dns_cmd);
1606 if (system(dns_cmd) != 0) {
1607 send_resp(dut, conn, SIGMA_ERROR,
1608 "ErrorCode,Failed to set primary-dns");
1609 return STATUS_SENT_ERROR;
1610 }
1611#endif /* ANDROID */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001612 }
1613
1614 val = get_param(cmd, "secondary-dns");
1615 if (val) {
1616 /* TODO */
1617 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored secondary-dns %s "
1618 "setting", val);
1619 }
1620
1621 static_ip_file(4, ip, mask, gw);
1622
1623 return 1;
1624}
1625
1626
Jouni Malinenf7222712019-06-13 01:50:21 +03001627static enum sigma_cmd_result cmd_sta_get_info(struct sigma_dut *dut,
1628 struct sigma_conn *conn,
1629 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001630{
1631 /* const char *intf = get_param(cmd, "Interface"); */
1632 /* TODO: could report more details here */
1633 send_resp(dut, conn, SIGMA_COMPLETE, "vendor,Atheros");
1634 return 0;
1635}
1636
1637
Jouni Malinenf7222712019-06-13 01:50:21 +03001638static enum sigma_cmd_result cmd_sta_get_mac_address(struct sigma_dut *dut,
1639 struct sigma_conn *conn,
1640 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001641{
1642 /* const char *intf = get_param(cmd, "Interface"); */
1643 char addr[20], resp[50];
1644
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05301645 if (dut->dev_role == DEVROLE_STA_CFON)
1646 return sta_cfon_get_mac_address(dut, conn, cmd);
1647
Jouni Malinen9540e012019-11-05 17:08:42 +02001648 start_sta_mode(dut);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001649 if (get_wpa_status(get_station_ifname(dut), "address",
1650 addr, sizeof(addr)) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001651 return -2;
1652
1653 snprintf(resp, sizeof(resp), "mac,%s", addr);
1654 send_resp(dut, conn, SIGMA_COMPLETE, resp);
1655 return 0;
1656}
1657
1658
Jouni Malinenf7222712019-06-13 01:50:21 +03001659static enum sigma_cmd_result cmd_sta_is_connected(struct sigma_dut *dut,
1660 struct sigma_conn *conn,
1661 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001662{
1663 /* const char *intf = get_param(cmd, "Interface"); */
1664 int connected = 0;
1665 char result[32];
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001666 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001667 sizeof(result)) < 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001668 sigma_dut_print(dut, DUT_MSG_INFO,
1669 "Could not get interface %s status",
1670 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001671 return -2;
1672 }
1673
1674 sigma_dut_print(dut, DUT_MSG_DEBUG, "wpa_state=%s", result);
1675 if (strncmp(result, "COMPLETED", 9) == 0)
1676 connected = 1;
1677
1678 if (connected)
1679 send_resp(dut, conn, SIGMA_COMPLETE, "connected,1");
1680 else
1681 send_resp(dut, conn, SIGMA_COMPLETE, "connected,0");
1682
1683 return 0;
1684}
1685
1686
Jouni Malinenf7222712019-06-13 01:50:21 +03001687static enum sigma_cmd_result
1688cmd_sta_verify_ip_connection(struct sigma_dut *dut, struct sigma_conn *conn,
1689 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001690{
1691 /* const char *intf = get_param(cmd, "Interface"); */
1692 const char *dst, *timeout;
1693 int wait_time = 90;
1694 char buf[100];
1695 int res;
1696
1697 dst = get_param(cmd, "destination");
1698 if (dst == NULL || !is_ip_addr(dst))
1699 return -1;
1700
1701 timeout = get_param(cmd, "timeout");
1702 if (timeout) {
1703 wait_time = atoi(timeout);
1704 if (wait_time < 1)
1705 wait_time = 1;
1706 }
1707
1708 /* TODO: force renewal of IP lease if DHCP is enabled */
1709
1710 snprintf(buf, sizeof(buf), "ping %s -c 3 -W %d", dst, wait_time);
1711 res = system(buf);
1712 sigma_dut_print(dut, DUT_MSG_DEBUG, "ping returned: %d", res);
1713 if (res == 0)
1714 send_resp(dut, conn, SIGMA_COMPLETE, "connected,1");
1715 else if (res == 256)
1716 send_resp(dut, conn, SIGMA_COMPLETE, "connected,0");
1717 else
1718 return -2;
1719
1720 return 0;
1721}
1722
1723
Jouni Malinenf7222712019-06-13 01:50:21 +03001724static enum sigma_cmd_result cmd_sta_get_bssid(struct sigma_dut *dut,
1725 struct sigma_conn *conn,
1726 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001727{
1728 /* const char *intf = get_param(cmd, "Interface"); */
1729 char bssid[20], resp[50];
1730
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001731 if (get_wpa_status(get_station_ifname(dut), "bssid",
1732 bssid, sizeof(bssid)) < 0)
Peng Xub8fc5cc2017-05-10 17:27:28 -07001733 strlcpy(bssid, "00:00:00:00:00:00", sizeof(bssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001734
1735 snprintf(resp, sizeof(resp), "bssid,%s", bssid);
1736 send_resp(dut, conn, SIGMA_COMPLETE, resp);
1737 return 0;
1738}
1739
1740
1741#ifdef __SAMSUNG__
1742static int add_use_network(const char *ifname)
1743{
1744 char buf[100];
1745
1746 snprintf(buf, sizeof(buf), "USE_NETWORK ON");
1747 wpa_command(ifname, buf);
1748 return 0;
1749}
1750#endif /* __SAMSUNG__ */
1751
1752
1753static int add_network_common(struct sigma_dut *dut, struct sigma_conn *conn,
1754 const char *ifname, struct sigma_cmd *cmd)
1755{
1756 const char *ssid = get_param(cmd, "ssid");
1757 int id;
1758 const char *val;
1759
1760 if (ssid == NULL)
1761 return -1;
1762
1763 start_sta_mode(dut);
1764
1765#ifdef __SAMSUNG__
1766 add_use_network(ifname);
1767#endif /* __SAMSUNG__ */
1768
1769 id = add_network(ifname);
1770 if (id < 0)
1771 return -2;
1772 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding network %d", id);
1773
1774 if (set_network_quoted(ifname, id, "ssid", ssid) < 0)
1775 return -2;
1776
1777 dut->infra_network_id = id;
1778 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
1779
1780 val = get_param(cmd, "program");
1781 if (!val)
1782 val = get_param(cmd, "prog");
1783 if (val && strcasecmp(val, "hs2") == 0) {
1784 char buf[100];
1785 snprintf(buf, sizeof(buf), "ENABLE_NETWORK %d no-connect", id);
1786 wpa_command(ifname, buf);
1787
1788 val = get_param(cmd, "prefer");
1789 if (val && atoi(val) > 0)
1790 set_network(ifname, id, "priority", "1");
1791 }
1792
1793 return id;
1794}
1795
1796
Jouni Malinenf7222712019-06-13 01:50:21 +03001797static enum sigma_cmd_result cmd_sta_set_encryption(struct sigma_dut *dut,
1798 struct sigma_conn *conn,
1799 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001800{
1801 const char *intf = get_param(cmd, "Interface");
1802 const char *ssid = get_param(cmd, "ssid");
1803 const char *type = get_param(cmd, "encpType");
1804 const char *ifname;
1805 char buf[200];
1806 int id;
1807
1808 if (intf == NULL || ssid == NULL)
1809 return -1;
1810
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001811 if (strcmp(intf, get_main_ifname(dut)) == 0)
1812 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001813 else
1814 ifname = intf;
1815
1816 id = add_network_common(dut, conn, ifname, cmd);
1817 if (id < 0)
1818 return id;
1819
1820 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
1821 return -2;
1822
1823 if (type && strcasecmp(type, "wep") == 0) {
1824 const char *val;
1825 int i;
1826
1827 val = get_param(cmd, "activeKey");
1828 if (val) {
1829 int keyid;
1830 keyid = atoi(val);
1831 if (keyid < 1 || keyid > 4)
1832 return -1;
1833 snprintf(buf, sizeof(buf), "%d", keyid - 1);
1834 if (set_network(ifname, id, "wep_tx_keyidx", buf) < 0)
1835 return -2;
1836 }
1837
1838 for (i = 0; i < 4; i++) {
1839 snprintf(buf, sizeof(buf), "key%d", i + 1);
1840 val = get_param(cmd, buf);
1841 if (val == NULL)
1842 continue;
1843 snprintf(buf, sizeof(buf), "wep_key%d", i);
1844 if (set_network(ifname, id, buf, val) < 0)
1845 return -2;
1846 }
1847 }
1848
1849 return 1;
1850}
1851
1852
Jouni Malinene4fde732019-03-25 22:29:37 +02001853static int set_akm_suites(struct sigma_dut *dut, const char *ifname,
1854 int id, const char *val)
1855{
1856 char key_mgmt[200], *end, *pos;
1857 const char *in_pos = val;
1858
Jouni Malinen8179fee2019-03-28 03:19:47 +02001859 dut->akm_values = 0;
Jouni Malinene4fde732019-03-25 22:29:37 +02001860 pos = key_mgmt;
1861 end = pos + sizeof(key_mgmt);
1862 while (*in_pos) {
1863 int res, akm = atoi(in_pos);
1864 const char *str;
1865
Jouni Malinen8179fee2019-03-28 03:19:47 +02001866 if (akm >= 0 && akm < 32)
1867 dut->akm_values |= 1 << akm;
1868
Jouni Malinene4fde732019-03-25 22:29:37 +02001869 switch (akm) {
1870 case AKM_WPA_EAP:
1871 str = "WPA-EAP";
1872 break;
1873 case AKM_WPA_PSK:
1874 str = "WPA-PSK";
1875 break;
1876 case AKM_FT_EAP:
1877 str = "FT-EAP";
1878 break;
1879 case AKM_FT_PSK:
1880 str = "FT-PSK";
1881 break;
1882 case AKM_EAP_SHA256:
1883 str = "WPA-EAP-SHA256";
1884 break;
1885 case AKM_PSK_SHA256:
1886 str = "WPA-PSK-SHA256";
1887 break;
1888 case AKM_SAE:
1889 str = "SAE";
1890 break;
1891 case AKM_FT_SAE:
1892 str = "FT-SAE";
1893 break;
1894 case AKM_SUITE_B:
1895 str = "WPA-EAP-SUITE-B-192";
1896 break;
1897 case AKM_FT_SUITE_B:
1898 str = "FT-EAP-SHA384";
1899 break;
1900 case AKM_FILS_SHA256:
1901 str = "FILS-SHA256";
1902 break;
1903 case AKM_FILS_SHA384:
1904 str = "FILS-SHA384";
1905 break;
1906 case AKM_FT_FILS_SHA256:
1907 str = "FT-FILS-SHA256";
1908 break;
1909 case AKM_FT_FILS_SHA384:
1910 str = "FT-FILS-SHA384";
1911 break;
1912 default:
1913 sigma_dut_print(dut, DUT_MSG_ERROR,
1914 "Unsupported AKMSuitetype %d", akm);
1915 return -1;
1916 }
1917
1918 res = snprintf(pos, end - pos, "%s%s",
1919 pos == key_mgmt ? "" : " ", str);
1920 if (res < 0 || res >= end - pos)
1921 return -1;
1922 pos += res;
1923
1924 in_pos = strchr(in_pos, ';');
1925 if (!in_pos)
1926 break;
1927 while (*in_pos == ';')
1928 in_pos++;
1929 }
1930 sigma_dut_print(dut, DUT_MSG_DEBUG, "AKMSuiteType %s --> %s",
1931 val, key_mgmt);
1932 return set_network(ifname, id, "key_mgmt", key_mgmt);
1933}
1934
1935
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001936static int set_wpa_common(struct sigma_dut *dut, struct sigma_conn *conn,
1937 const char *ifname, struct sigma_cmd *cmd)
1938{
1939 const char *val;
1940 int id;
Jouni Malinenad395a22017-09-01 21:13:46 +03001941 int cipher_set = 0;
Jouni Malinen47dcc952017-10-09 16:43:24 +03001942 int owe;
Sunil Duttc75a1e62018-01-11 20:47:50 +05301943 int suite_b = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001944
1945 id = add_network_common(dut, conn, ifname, cmd);
1946 if (id < 0)
1947 return id;
1948
Jouni Malinen47dcc952017-10-09 16:43:24 +03001949 val = get_param(cmd, "Type");
1950 owe = val && strcasecmp(val, "OWE") == 0;
1951
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001952 val = get_param(cmd, "keyMgmtType");
Jouni Malinen47dcc952017-10-09 16:43:24 +03001953 if (!val && owe)
1954 val = "OWE";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001955 if (val == NULL) {
Jouni Malinene4fde732019-03-25 22:29:37 +02001956 /* keyMgmtType is being replaced with AKMSuiteType, so ignore
1957 * this missing parameter and assume proto=WPA2. */
1958 if (set_network(ifname, id, "proto", "WPA2") < 0)
1959 return ERROR_SEND_STATUS;
1960 } else if (strcasecmp(val, "wpa") == 0 ||
1961 strcasecmp(val, "wpa-psk") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001962 if (set_network(ifname, id, "proto", "WPA") < 0)
1963 return -2;
1964 } else if (strcasecmp(val, "wpa2") == 0 ||
1965 strcasecmp(val, "wpa2-psk") == 0 ||
1966 strcasecmp(val, "wpa2-ft") == 0 ||
1967 strcasecmp(val, "wpa2-sha256") == 0) {
1968 if (set_network(ifname, id, "proto", "WPA2") < 0)
1969 return -2;
Pradeep Reddy POTTETI6d04b3b2016-11-15 14:51:26 +05301970 } else if (strcasecmp(val, "wpa2-wpa-psk") == 0 ||
1971 strcasecmp(val, "wpa2-wpa-ent") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001972 if (set_network(ifname, id, "proto", "WPA WPA2") < 0)
1973 return -2;
Jouni Malinenad395a22017-09-01 21:13:46 +03001974 } else if (strcasecmp(val, "SuiteB") == 0) {
Sunil Duttc75a1e62018-01-11 20:47:50 +05301975 suite_b = 1;
Jouni Malinenad395a22017-09-01 21:13:46 +03001976 if (set_network(ifname, id, "proto", "WPA2") < 0)
1977 return -2;
Jouni Malinen47dcc952017-10-09 16:43:24 +03001978 } else if (strcasecmp(val, "OWE") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001979 } else {
1980 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized keyMgmtType value");
1981 return 0;
1982 }
1983
1984 val = get_param(cmd, "encpType");
Jouni Malinenad395a22017-09-01 21:13:46 +03001985 if (val) {
1986 cipher_set = 1;
1987 if (strcasecmp(val, "tkip") == 0) {
1988 if (set_network(ifname, id, "pairwise", "TKIP") < 0)
1989 return -2;
1990 } else if (strcasecmp(val, "aes-ccmp") == 0) {
1991 if (set_network(ifname, id, "pairwise", "CCMP") < 0)
1992 return -2;
1993 } else if (strcasecmp(val, "aes-ccmp-tkip") == 0) {
1994 if (set_network(ifname, id, "pairwise",
1995 "CCMP TKIP") < 0)
1996 return -2;
1997 } else if (strcasecmp(val, "aes-gcmp") == 0) {
1998 if (set_network(ifname, id, "pairwise", "GCMP") < 0)
1999 return -2;
2000 if (set_network(ifname, id, "group", "GCMP") < 0)
2001 return -2;
2002 } else {
2003 send_resp(dut, conn, SIGMA_ERROR,
2004 "errorCode,Unrecognized encpType value");
2005 return 0;
2006 }
2007 }
2008
2009 val = get_param(cmd, "PairwiseCipher");
2010 if (val) {
2011 cipher_set = 1;
2012 /* TODO: Support space separated list */
2013 if (strcasecmp(val, "AES-GCMP-256") == 0) {
2014 if (set_network(ifname, id, "pairwise", "GCMP-256") < 0)
2015 return -2;
2016 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
2017 if (set_network(ifname, id, "pairwise",
2018 "CCMP-256") < 0)
2019 return -2;
2020 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
2021 if (set_network(ifname, id, "pairwise", "GCMP") < 0)
2022 return -2;
2023 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
2024 if (set_network(ifname, id, "pairwise", "CCMP") < 0)
2025 return -2;
2026 } else {
2027 send_resp(dut, conn, SIGMA_ERROR,
2028 "errorCode,Unrecognized PairwiseCipher value");
2029 return 0;
2030 }
2031 }
2032
Jouni Malinen47dcc952017-10-09 16:43:24 +03002033 if (!cipher_set && !owe) {
Jouni Malinenad395a22017-09-01 21:13:46 +03002034 send_resp(dut, conn, SIGMA_ERROR,
2035 "errorCode,Missing encpType and PairwiseCipher");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002036 return 0;
2037 }
Jouni Malinenad395a22017-09-01 21:13:46 +03002038
2039 val = get_param(cmd, "GroupCipher");
2040 if (val) {
2041 if (strcasecmp(val, "AES-GCMP-256") == 0) {
2042 if (set_network(ifname, id, "group", "GCMP-256") < 0)
2043 return -2;
2044 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
2045 if (set_network(ifname, id, "group", "CCMP-256") < 0)
2046 return -2;
2047 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
2048 if (set_network(ifname, id, "group", "GCMP") < 0)
2049 return -2;
2050 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
2051 if (set_network(ifname, id, "group", "CCMP") < 0)
2052 return -2;
2053 } else {
2054 send_resp(dut, conn, SIGMA_ERROR,
2055 "errorCode,Unrecognized GroupCipher value");
2056 return 0;
2057 }
2058 }
2059
Jouni Malinen7b239522017-09-14 21:37:18 +03002060 val = get_param(cmd, "GroupMgntCipher");
Jouni Malinenad395a22017-09-01 21:13:46 +03002061 if (val) {
Jouni Malinene8898cb2017-09-26 17:55:26 +03002062 const char *cipher;
2063
2064 if (strcasecmp(val, "BIP-GMAC-256") == 0) {
2065 cipher = "BIP-GMAC-256";
2066 } else if (strcasecmp(val, "BIP-CMAC-256") == 0) {
2067 cipher = "BIP-CMAC-256";
2068 } else if (strcasecmp(val, "BIP-GMAC-128") == 0) {
2069 cipher = "BIP-GMAC-128";
2070 } else if (strcasecmp(val, "BIP-CMAC-128") == 0) {
2071 cipher = "AES-128-CMAC";
2072 } else {
2073 send_resp(dut, conn, SIGMA_INVALID,
2074 "errorCode,Unsupported GroupMgntCipher");
2075 return 0;
2076 }
2077 if (set_network(ifname, id, "group_mgmt", cipher) < 0) {
2078 send_resp(dut, conn, SIGMA_INVALID,
2079 "errorCode,Failed to set GroupMgntCipher");
2080 return 0;
2081 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002082 }
2083
Jouni Malinene4fde732019-03-25 22:29:37 +02002084 val = get_param(cmd, "AKMSuiteType");
2085 if (val && set_akm_suites(dut, ifname, id, val) < 0)
2086 return ERROR_SEND_STATUS;
2087
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002088 dut->sta_pmf = STA_PMF_DISABLED;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302089
2090 if (dut->program == PROGRAM_OCE) {
2091 dut->sta_pmf = STA_PMF_OPTIONAL;
2092 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2093 return -2;
2094 }
2095
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002096 val = get_param(cmd, "PMF");
2097 if (val) {
2098 if (strcasecmp(val, "Required") == 0 ||
2099 strcasecmp(val, "Forced_Required") == 0) {
2100 dut->sta_pmf = STA_PMF_REQUIRED;
2101 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2102 return -2;
2103 } else if (strcasecmp(val, "Optional") == 0) {
2104 dut->sta_pmf = STA_PMF_OPTIONAL;
2105 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2106 return -2;
2107 } else if (strcasecmp(val, "Disabled") == 0 ||
Kiran Kumar Lokere07da3b22018-12-16 22:42:49 -08002108 strcasecmp(val, "Disable") == 0 ||
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002109 strcasecmp(val, "Forced_Disabled") == 0) {
2110 dut->sta_pmf = STA_PMF_DISABLED;
2111 } else {
2112 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized PMF value");
2113 return 0;
2114 }
Sunil Duttc75a1e62018-01-11 20:47:50 +05302115 } else if (owe || suite_b) {
Jouni Malinen1287cd72018-01-04 17:08:01 +02002116 dut->sta_pmf = STA_PMF_REQUIRED;
2117 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2118 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002119 }
2120
Jouni Malinen0165c7f2020-03-26 11:51:58 +02002121 val = get_param(cmd, "BeaconProtection");
Veerendranath Jakkamc1f71b62021-01-23 03:09:51 +05302122 if (val)
2123 dut->beacon_prot = atoi(val);
2124 if (dut->beacon_prot && set_network(ifname, id, "beacon_prot", "1") < 0)
Jouni Malinen0165c7f2020-03-26 11:51:58 +02002125 return ERROR_SEND_STATUS;
2126
Veerendranath Jakkam54fd51c2020-12-21 01:36:04 +05302127 if (dut->ocvc && set_network(ifname, id, "ocv", "1") < 0)
2128 return ERROR_SEND_STATUS;
2129
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002130 return id;
2131}
2132
2133
Jouni Malinenf7222712019-06-13 01:50:21 +03002134static enum sigma_cmd_result cmd_sta_set_psk(struct sigma_dut *dut,
2135 struct sigma_conn *conn,
2136 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002137{
2138 const char *intf = get_param(cmd, "Interface");
Jouni Malinen992a81e2017-08-22 13:57:47 +03002139 const char *type = get_param(cmd, "Type");
Jouni Malinen1287cd72018-01-04 17:08:01 +02002140 const char *pmf = get_param(cmd, "PMF");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002141 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinene4fde732019-03-25 22:29:37 +02002142 const char *akm = get_param(cmd, "AKMSuiteType");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002143 const char *ifname, *val, *alg;
2144 int id;
Jouni Malinen4b3769d2019-10-10 16:20:29 +03002145 char buf[50];
Jouni Malinen11e55212019-11-22 21:46:59 +02002146 int sae_pwe = -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002147
2148 if (intf == NULL)
2149 return -1;
2150
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002151 if (strcmp(intf, get_main_ifname(dut)) == 0)
2152 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002153 else
2154 ifname = intf;
2155
2156 id = set_wpa_common(dut, conn, ifname, cmd);
2157 if (id < 0)
2158 return id;
2159
2160 val = get_param(cmd, "keyMgmtType");
2161 alg = get_param(cmd, "micAlg");
2162
Jouni Malinen992a81e2017-08-22 13:57:47 +03002163 if (type && strcasecmp(type, "SAE") == 0) {
Jouni Malinene4fde732019-03-25 22:29:37 +02002164 if (!akm && val && strcasecmp(val, "wpa2-ft") == 0) {
Jouni Malinen992a81e2017-08-22 13:57:47 +03002165 if (set_network(ifname, id, "key_mgmt", "FT-SAE") < 0)
2166 return -2;
Jouni Malinene4fde732019-03-25 22:29:37 +02002167 } else if (!akm) {
Jouni Malinen992a81e2017-08-22 13:57:47 +03002168 if (set_network(ifname, id, "key_mgmt", "SAE") < 0)
2169 return -2;
2170 }
2171 if (wpa_command(ifname, "SET sae_groups ") != 0) {
2172 sigma_dut_print(dut, DUT_MSG_ERROR,
2173 "Failed to clear sae_groups to default");
2174 return -2;
2175 }
Jouni Malinen1287cd72018-01-04 17:08:01 +02002176 if (!pmf) {
2177 dut->sta_pmf = STA_PMF_REQUIRED;
2178 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2179 return -2;
2180 }
Jouni Malinen0ab50f42017-08-31 01:34:59 +03002181 } else if (type && strcasecmp(type, "PSK-SAE") == 0) {
2182 if (val && strcasecmp(val, "wpa2-ft") == 0) {
2183 if (set_network(ifname, id, "key_mgmt",
2184 "FT-SAE FT-PSK") < 0)
2185 return -2;
Jouni Malinen3b73d872019-06-12 03:13:25 +03002186 } else if (!akm) {
Jouni Malinen0ab50f42017-08-31 01:34:59 +03002187 if (set_network(ifname, id, "key_mgmt",
2188 "SAE WPA-PSK") < 0)
2189 return -2;
2190 }
2191 if (wpa_command(ifname, "SET sae_groups ") != 0) {
2192 sigma_dut_print(dut, DUT_MSG_ERROR,
2193 "Failed to clear sae_groups to default");
2194 return -2;
2195 }
Jouni Malinen1287cd72018-01-04 17:08:01 +02002196 if (!pmf) {
2197 dut->sta_pmf = STA_PMF_OPTIONAL;
2198 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2199 return -2;
2200 }
Jouni Malinen992a81e2017-08-22 13:57:47 +03002201 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002202 if (set_network(ifname, id, "key_mgmt", "WPA-PSK-SHA256") < 0)
2203 return -2;
2204 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
2205 if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0)
2206 return -2;
Ashwini Patil6dbf7b02017-03-20 13:42:11 +05302207 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
2208 if (set_network(ifname, id, "key_mgmt", "FT-PSK") < 0)
2209 return -2;
Jouni Malinen3b73d872019-06-12 03:13:25 +03002210 } else if (!akm &&
2211 ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
2212 dut->sta_pmf == STA_PMF_REQUIRED)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002213 if (set_network(ifname, id, "key_mgmt",
2214 "WPA-PSK WPA-PSK-SHA256") < 0)
2215 return -2;
Jouni Malinen77ff3f02019-03-28 03:45:40 +02002216 } else if (!akm && dut->sta_pmf == STA_PMF_OPTIONAL) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002217 if (set_network(ifname, id, "key_mgmt",
2218 "WPA-PSK WPA-PSK-SHA256") < 0)
2219 return -2;
Jouni Malinen77ff3f02019-03-28 03:45:40 +02002220 } else if (!akm) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002221 if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0)
2222 return -2;
2223 }
2224
2225 val = get_param(cmd, "passPhrase");
2226 if (val == NULL)
2227 return -1;
Jouni Malinen2126f422017-10-11 23:24:33 +03002228 if (type && strcasecmp(type, "SAE") == 0) {
2229 if (set_network_quoted(ifname, id, "sae_password", val) < 0)
2230 return -2;
2231 } else {
2232 if (set_network_quoted(ifname, id, "psk", val) < 0)
2233 return -2;
2234 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002235
Jouni Malinen78d10c42019-03-25 22:34:32 +02002236 val = get_param(cmd, "PasswordId");
2237 if (val && set_network_quoted(ifname, id, "sae_password_id", val) < 0)
2238 return ERROR_SEND_STATUS;
2239
Jouni Malinen992a81e2017-08-22 13:57:47 +03002240 val = get_param(cmd, "ECGroupID");
2241 if (val) {
Jouni Malinenb54f0df2019-12-12 01:57:29 +02002242 snprintf(buf, sizeof(buf), "SET sae_groups %s", val);
Jouni Malinen992a81e2017-08-22 13:57:47 +03002243 if (wpa_command(ifname, buf) != 0) {
2244 sigma_dut_print(dut, DUT_MSG_ERROR,
2245 "Failed to clear sae_groups");
2246 return -2;
2247 }
2248 }
2249
Jouni Malinen68143132017-09-02 02:34:08 +03002250 val = get_param(cmd, "InvalidSAEElement");
2251 if (val) {
2252 free(dut->sae_commit_override);
2253 dut->sae_commit_override = strdup(val);
2254 }
2255
Jouni Malinen4b3769d2019-10-10 16:20:29 +03002256 val = get_param(cmd, "PMKID_Include");
2257 if (val) {
2258 snprintf(buf, sizeof(buf), "SET sae_pmkid_in_assoc %d",
2259 get_enable_disable(val));
2260 wpa_command(intf, buf);
2261 }
2262
Jouni Malineneeb43d32019-12-06 17:40:07 +02002263 val = get_param(cmd, "IgnoreH2E_RSNXE_BSSMemSel");
2264 if (val) {
2265 snprintf(buf, sizeof(buf), "SET ignore_sae_h2e_only %d",
2266 get_enable_disable(val));
2267 wpa_command(intf, buf);
2268 }
2269
Jouni Malinenf2348d22019-12-07 11:52:55 +02002270 val = get_param(cmd, "ECGroupID_RGE");
2271 if (val) {
2272 snprintf(buf, sizeof(buf), "SET extra_sae_rejected_groups %s",
2273 val);
2274 wpa_command(intf, buf);
2275 }
2276
Jouni Malinen99e55022019-12-07 13:59:41 +02002277 val = get_param(cmd, "RSNXE_Content");
2278 if (val) {
2279 const char *param;
2280
2281 if (strncasecmp(val, "AssocReq:", 9) == 0) {
2282 val += 9;
2283 param = "rsnxe_override_assoc";
2284 } else if (strncasecmp(val, "EapolM2:", 8) == 0) {
2285 val += 8;
2286 param = "rsnxe_override_eapol";
2287 } else {
2288 send_resp(dut, conn, SIGMA_ERROR,
2289 "errorCode,Unsupported RSNXE_Content value");
2290 return STATUS_SENT_ERROR;
2291 }
2292 snprintf(buf, sizeof(buf), "SET %s %s", param, val);
2293 wpa_command(intf, buf);
2294 }
2295
Jouni Malinen11e55212019-11-22 21:46:59 +02002296 val = get_param(cmd, "sae_pwe");
2297 if (val) {
2298 if (strcasecmp(val, "h2e") == 0) {
2299 dut->sae_pwe = SAE_PWE_H2E;
Jouni Malinen7244a412019-12-07 11:54:10 +02002300 } else if (strcasecmp(val, "loop") == 0 ||
2301 strcasecmp(val, "looping") == 0) {
Jouni Malinen11e55212019-11-22 21:46:59 +02002302 dut->sae_pwe = SAE_PWE_LOOP;
2303 } else {
2304 send_resp(dut, conn, SIGMA_ERROR,
2305 "errorCode,Unsupported sae_pwe value");
2306 return STATUS_SENT_ERROR;
2307 }
2308 }
Vinita S. Maloo6d7454f2020-04-02 15:03:26 +05302309
2310 val = get_param(cmd, "Clear_RSNXE");
2311 if (val && strcmp(val, "1") == 0 &&
2312 (wpa_command(intf, "SET rsnxe_override_assoc ") ||
2313 wpa_command(intf, "SET rsnxe_override_eapol "))) {
2314 send_resp(dut, conn, SIGMA_ERROR,
2315 "errorCode,Failed to clear RSNXE");
Jouni Malinenb11498c2020-08-03 11:05:53 +03002316 return STATUS_SENT_ERROR;
Vinita S. Maloo6d7454f2020-04-02 15:03:26 +05302317 }
2318
Jouni Malinenc0078772020-03-04 21:23:16 +02002319 if (dut->sae_pwe == SAE_PWE_LOOP && get_param(cmd, "PasswordId"))
2320 sae_pwe = 3;
2321 else if (dut->sae_pwe == SAE_PWE_LOOP)
Jouni Malinen11e55212019-11-22 21:46:59 +02002322 sae_pwe = 0;
2323 else if (dut->sae_pwe == SAE_PWE_H2E)
2324 sae_pwe = 1;
2325 else if (dut->sae_h2e_default)
2326 sae_pwe = 2;
2327 snprintf(buf, sizeof(buf), "SET sae_pwe %d", sae_pwe);
2328 if (sae_pwe >= 0 && wpa_command(ifname, buf) != 0)
2329 return ERROR_SEND_STATUS;
2330
Veerendranath Jakkam0316be12020-06-23 20:11:41 +05302331 val = get_param(cmd, "sae_pk");
2332 if (val && strcmp(val, "0") == 0 &&
2333 set_network(ifname, id, "sae_pk", "2") < 0)
2334 return ERROR_SEND_STATUS;
2335
Veerendranath Jakkama9177042020-08-10 00:14:03 +05302336 val = get_param(cmd, "sae_pk_only");
2337 if (val && strcmp(val, "1") == 0 &&
2338 set_network(ifname, id, "sae_pk", "1") < 0)
2339 return ERROR_SEND_STATUS;
2340
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002341 if (dut->program == PROGRAM_60GHZ && network_mode &&
2342 strcasecmp(network_mode, "PBSS") == 0 &&
2343 set_network(ifname, id, "pbss", "1") < 0)
2344 return -2;
2345
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002346 return 1;
2347}
2348
2349
Jouni Malinen8ac93452019-08-14 15:19:13 +03002350static enum sigma_cmd_result set_trust_root_system(struct sigma_dut *dut,
2351 struct sigma_conn *conn,
2352 const char *ifname, int id)
2353{
2354 char buf[200];
2355
2356 snprintf(buf, sizeof(buf), "%s/certs", sigma_cert_path);
2357 if (!file_exists(buf))
2358 strlcpy(buf, "/system/etc/security/cacerts", sizeof(buf));
2359 if (!file_exists(buf))
2360 strlcpy(buf, "/etc/ssl/certs", sizeof(buf));
2361 if (!file_exists(buf)) {
2362 char msg[300];
2363
2364 snprintf(msg, sizeof(msg),
2365 "ErrorCode,trustedRootCA system store (%s) not found",
2366 buf);
2367 send_resp(dut, conn, SIGMA_ERROR, msg);
2368 return STATUS_SENT_ERROR;
2369 }
2370
2371 if (set_network_quoted(ifname, id, "ca_path", buf) < 0)
2372 return ERROR_SEND_STATUS;
2373
2374 return SUCCESS_SEND_STATUS;
2375}
2376
2377
2378static enum sigma_cmd_result set_trust_root(struct sigma_dut *dut,
2379 struct sigma_conn *conn,
2380 const char *ifname, int id,
2381 const char *val)
2382{
2383 char buf[200];
2384#ifdef ANDROID
2385 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
2386 int length;
2387#endif /* ANDROID */
2388
2389 if (strcmp(val, "DEFAULT") == 0)
2390 return set_trust_root_system(dut, conn, ifname, id);
2391
2392#ifdef ANDROID
2393 snprintf(buf, sizeof(buf), "CACERT_%s", val);
2394 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
2395 if (length > 0) {
2396 sigma_dut_print(dut, DUT_MSG_INFO, "Use Android keystore [%s]",
2397 buf);
2398 snprintf(buf, sizeof(buf), "keystore://CACERT_%s", val);
2399 goto ca_cert_selected;
2400 }
2401#endif /* ANDROID */
2402
2403 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
2404#ifdef __linux__
2405 if (!file_exists(buf)) {
2406 char msg[300];
2407
2408 snprintf(msg, sizeof(msg),
2409 "ErrorCode,trustedRootCA file (%s) not found", buf);
2410 send_resp(dut, conn, SIGMA_ERROR, msg);
2411 return STATUS_SENT_ERROR;
2412 }
2413#endif /* __linux__ */
2414#ifdef ANDROID
2415ca_cert_selected:
2416#endif /* ANDROID */
2417 if (set_network_quoted(ifname, id, "ca_cert", buf) < 0)
2418 return ERROR_SEND_STATUS;
2419
2420 return SUCCESS_SEND_STATUS;
2421}
2422
2423
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002424static int set_eap_common(struct sigma_dut *dut, struct sigma_conn *conn,
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302425 const char *ifname, int username_identity,
2426 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002427{
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002428 const char *val, *alg, *akm, *trust_root, *domain, *domain_suffix;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002429 int id;
Jouni Malinen53264f62019-05-03 13:04:40 +03002430 char buf[200], buf2[300];
Jouni Malinen8179fee2019-03-28 03:19:47 +02002431 int erp = 0;
Jouni Malinen8ac93452019-08-14 15:19:13 +03002432 enum sigma_cmd_result res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002433
2434 id = set_wpa_common(dut, conn, ifname, cmd);
2435 if (id < 0)
2436 return id;
2437
2438 val = get_param(cmd, "keyMgmtType");
2439 alg = get_param(cmd, "micAlg");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302440 akm = get_param(cmd, "AKMSuiteType");
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002441 trust_root = get_param(cmd, "trustedRootCA");
2442 domain = get_param(cmd, "Domain");
2443 domain_suffix = get_param(cmd, "DomainSuffix");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002444
Jouni Malinenad395a22017-09-01 21:13:46 +03002445 if (val && strcasecmp(val, "SuiteB") == 0) {
2446 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SUITE-B-192") <
2447 0)
2448 return -2;
2449 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002450 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SHA256") < 0)
2451 return -2;
2452 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
2453 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
2454 return -2;
2455 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
2456 if (set_network(ifname, id, "key_mgmt", "FT-EAP") < 0)
2457 return -2;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002458 } else if (!akm &&
2459 ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
2460 dut->sta_pmf == STA_PMF_REQUIRED)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002461 if (set_network(ifname, id, "key_mgmt",
2462 "WPA-EAP WPA-EAP-SHA256") < 0)
2463 return -2;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302464 } else if (akm && atoi(akm) == 14) {
2465 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
2466 dut->sta_pmf == STA_PMF_REQUIRED) {
2467 if (set_network(ifname, id, "key_mgmt",
2468 "WPA-EAP-SHA256 FILS-SHA256") < 0)
2469 return -2;
2470 } else {
2471 if (set_network(ifname, id, "key_mgmt",
2472 "WPA-EAP FILS-SHA256") < 0)
2473 return -2;
2474 }
2475
Jouni Malinen8179fee2019-03-28 03:19:47 +02002476 erp = 1;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302477 } else if (akm && atoi(akm) == 15) {
2478 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
2479 dut->sta_pmf == STA_PMF_REQUIRED) {
2480 if (set_network(ifname, id, "key_mgmt",
2481 "WPA-EAP-SHA256 FILS-SHA384") < 0)
2482 return -2;
2483 } else {
2484 if (set_network(ifname, id, "key_mgmt",
2485 "WPA-EAP FILS-SHA384") < 0)
2486 return -2;
2487 }
2488
Jouni Malinen8179fee2019-03-28 03:19:47 +02002489 erp = 1;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002490 } else if (!akm && dut->sta_pmf == STA_PMF_OPTIONAL) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002491 if (set_network(ifname, id, "key_mgmt",
2492 "WPA-EAP WPA-EAP-SHA256") < 0)
2493 return -2;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002494 } else if (!akm) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002495 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
2496 return -2;
2497 }
2498
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002499 if (trust_root) {
2500 if (strcmp(trust_root, "DEFAULT") == 0 && !domain &&
2501 !domain_suffix) {
2502 send_resp(dut, conn, SIGMA_ERROR,
2503 "errorCode,trustRootCA DEFAULT used without specifying Domain or DomainSuffix");
2504 return STATUS_SENT_ERROR;
2505 }
2506 res = set_trust_root(dut, conn, ifname, id, trust_root);
Jouni Malinen8ac93452019-08-14 15:19:13 +03002507 if (res != SUCCESS_SEND_STATUS)
2508 return res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002509 }
2510
Jouni Malinen53264f62019-05-03 13:04:40 +03002511 val = get_param(cmd, "ServerCert");
2512 if (val) {
2513 FILE *f;
2514 char *result = NULL, *pos;
2515
2516 snprintf(buf, sizeof(buf), "%s/%s.sha256", sigma_cert_path,
2517 val);
2518 f = fopen(buf, "r");
2519 if (f) {
2520 result = fgets(buf, sizeof(buf), f);
2521 fclose(f);
2522 }
2523 if (!result) {
2524 snprintf(buf2, sizeof(buf2),
2525 "ErrorCode,ServerCert hash could not be read from %s",
2526 buf);
2527 send_resp(dut, conn, SIGMA_ERROR, buf2);
2528 return STATUS_SENT_ERROR;
2529 }
2530 pos = strchr(buf, '\n');
2531 if (pos)
2532 *pos = '\0';
Jouni Malinen0572a742020-10-08 13:53:25 +03002533 pos = strchr(buf, '\r');
2534 if (pos)
2535 *pos = '\0';
Jouni Malinen53264f62019-05-03 13:04:40 +03002536 snprintf(buf2, sizeof(buf2), "hash://server/sha256/%s", buf);
2537 if (set_network_quoted(ifname, id, "ca_cert", buf2) < 0)
2538 return ERROR_SEND_STATUS;
Jouni Malinen29108dc2019-06-13 23:42:11 +03002539
2540 snprintf(buf, sizeof(buf), "%s/%s.tod", sigma_cert_path, val);
2541 if (file_exists(buf)) {
2542 sigma_dut_print(dut, DUT_MSG_DEBUG,
2543 "TOD policy enabled for the configured ServerCert hash");
2544 dut->sta_tod_policy = 1;
2545 }
Jouni Malinen53264f62019-05-03 13:04:40 +03002546 }
2547
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002548 if (domain &&
2549 set_network_quoted(ifname, id, "domain_match", domain) < 0)
Jouni Malinen96f84b02019-05-03 12:32:56 +03002550 return ERROR_SEND_STATUS;
2551
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002552 if (domain_suffix &&
2553 set_network_quoted(ifname, id, "domain_suffix_match",
2554 domain_suffix) < 0)
Jouni Malinen96f84b02019-05-03 12:32:56 +03002555 return ERROR_SEND_STATUS;
2556
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302557 if (username_identity) {
2558 val = get_param(cmd, "username");
2559 if (val) {
2560 if (set_network_quoted(ifname, id, "identity", val) < 0)
2561 return -2;
2562 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002563
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302564 val = get_param(cmd, "password");
2565 if (val) {
2566 if (set_network_quoted(ifname, id, "password", val) < 0)
2567 return -2;
2568 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002569 }
2570
Jouni Malinen8179fee2019-03-28 03:19:47 +02002571 if (dut->akm_values &
2572 ((1 << AKM_FILS_SHA256) |
2573 (1 << AKM_FILS_SHA384) |
2574 (1 << AKM_FT_FILS_SHA256) |
2575 (1 << AKM_FT_FILS_SHA384)))
2576 erp = 1;
2577 if (erp && set_network(ifname, id, "erp", "1") < 0)
2578 return ERROR_SEND_STATUS;
2579
Jouni Malinen134fe3c2019-06-12 04:16:49 +03002580 dut->sta_associate_wait_connect = 1;
2581
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002582 return id;
2583}
2584
2585
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002586static int set_tls_cipher(const char *ifname, int id, const char *cipher)
2587{
2588 const char *val;
2589
2590 if (!cipher)
2591 return 0;
2592
2593 if (strcasecmp(cipher, "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384") == 0)
2594 val = "ECDHE-ECDSA-AES256-GCM-SHA384";
2595 else if (strcasecmp(cipher,
2596 "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
2597 val = "ECDHE-RSA-AES256-GCM-SHA384";
2598 else if (strcasecmp(cipher, "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
2599 val = "DHE-RSA-AES256-GCM-SHA384";
2600 else if (strcasecmp(cipher,
2601 "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256") == 0)
2602 val = "ECDHE-ECDSA-AES128-GCM-SHA256";
2603 else
2604 return -1;
2605
2606 /* Need to clear phase1="tls_suiteb=1" to allow cipher enforcement */
2607 set_network_quoted(ifname, id, "phase1", "");
2608
2609 return set_network_quoted(ifname, id, "openssl_ciphers", val);
2610}
2611
2612
Jouni Malinenf7222712019-06-13 01:50:21 +03002613static enum sigma_cmd_result cmd_sta_set_eaptls(struct sigma_dut *dut,
2614 struct sigma_conn *conn,
2615 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002616{
2617 const char *intf = get_param(cmd, "Interface");
2618 const char *ifname, *val;
2619 int id;
2620 char buf[200];
2621#ifdef ANDROID
2622 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
2623 int length;
2624 int jb_or_newer = 0;
2625 char prop[PROPERTY_VALUE_MAX];
2626#endif /* ANDROID */
2627
2628 if (intf == NULL)
2629 return -1;
2630
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002631 if (strcmp(intf, get_main_ifname(dut)) == 0)
2632 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002633 else
2634 ifname = intf;
2635
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302636 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002637 if (id < 0)
2638 return id;
2639
2640 if (set_network(ifname, id, "eap", "TLS") < 0)
2641 return -2;
2642
Pradeep Reddy POTTETI9f6c2132016-05-05 16:28:19 +05302643 if (!get_param(cmd, "username") &&
2644 set_network_quoted(ifname, id, "identity",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002645 "wifi-user@wifilabs.local") < 0)
2646 return -2;
2647
2648 val = get_param(cmd, "clientCertificate");
2649 if (val == NULL)
2650 return -1;
2651#ifdef ANDROID
2652 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2653 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
2654 if (length < 0) {
2655 /*
2656 * JB started reporting keystore type mismatches, so retry with
2657 * the GET_PUBKEY command if the generic GET fails.
2658 */
2659 length = android_keystore_get(ANDROID_KEYSTORE_GET_PUBKEY,
2660 buf, kvalue);
2661 }
2662
2663 if (property_get("ro.build.version.release", prop, NULL) != 0) {
2664 sigma_dut_print(dut, DUT_MSG_DEBUG, "Android release %s", prop);
2665 if (strncmp(prop, "4.0", 3) != 0)
2666 jb_or_newer = 1;
2667 } else
2668 jb_or_newer = 1; /* assume newer */
2669
2670 if (jb_or_newer && length > 0) {
2671 sigma_dut_print(dut, DUT_MSG_INFO,
2672 "Use Android keystore [%s]", buf);
2673 if (set_network(ifname, id, "engine", "1") < 0)
2674 return -2;
2675 if (set_network_quoted(ifname, id, "engine_id", "keystore") < 0)
2676 return -2;
2677 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2678 if (set_network_quoted(ifname, id, "key_id", buf) < 0)
2679 return -2;
2680 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2681 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2682 return -2;
2683 return 1;
2684 } else if (length > 0) {
2685 sigma_dut_print(dut, DUT_MSG_INFO,
2686 "Use Android keystore [%s]", buf);
2687 snprintf(buf, sizeof(buf), "keystore://USRPKEY_%s", val);
2688 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2689 return -2;
2690 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2691 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2692 return -2;
2693 return 1;
2694 }
2695#endif /* ANDROID */
2696
2697 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
2698#ifdef __linux__
2699 if (!file_exists(buf)) {
2700 char msg[300];
2701 snprintf(msg, sizeof(msg), "ErrorCode,clientCertificate file "
2702 "(%s) not found", buf);
2703 send_resp(dut, conn, SIGMA_ERROR, msg);
2704 return -3;
2705 }
2706#endif /* __linux__ */
2707 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2708 return -2;
2709 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2710 return -2;
2711
2712 if (set_network_quoted(ifname, id, "private_key_passwd", "wifi") < 0)
2713 return -2;
2714
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002715 val = get_param(cmd, "keyMgmtType");
2716 if (val && strcasecmp(val, "SuiteB") == 0) {
2717 val = get_param(cmd, "CertType");
2718 if (val && strcasecmp(val, "RSA") == 0) {
2719 if (set_network_quoted(ifname, id, "phase1",
2720 "tls_suiteb=1") < 0)
2721 return -2;
2722 } else {
2723 if (set_network_quoted(ifname, id, "openssl_ciphers",
2724 "SUITEB192") < 0)
2725 return -2;
2726 }
2727
2728 val = get_param(cmd, "TLSCipher");
2729 if (set_tls_cipher(ifname, id, val) < 0) {
2730 send_resp(dut, conn, SIGMA_ERROR,
2731 "ErrorCode,Unsupported TLSCipher value");
2732 return -3;
2733 }
2734 }
2735
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002736 return 1;
2737}
2738
2739
Jouni Malinenf7222712019-06-13 01:50:21 +03002740static enum sigma_cmd_result cmd_sta_set_eapttls(struct sigma_dut *dut,
2741 struct sigma_conn *conn,
2742 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002743{
2744 const char *intf = get_param(cmd, "Interface");
2745 const char *ifname;
2746 int id;
2747
2748 if (intf == NULL)
2749 return -1;
2750
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002751 if (strcmp(intf, get_main_ifname(dut)) == 0)
2752 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002753 else
2754 ifname = intf;
2755
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302756 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002757 if (id < 0)
2758 return id;
2759
2760 if (set_network(ifname, id, "eap", "TTLS") < 0) {
2761 send_resp(dut, conn, SIGMA_ERROR,
2762 "errorCode,Failed to set TTLS method");
2763 return 0;
2764 }
2765
2766 if (set_network_quoted(ifname, id, "phase2", "auth=MSCHAPV2") < 0) {
2767 send_resp(dut, conn, SIGMA_ERROR,
2768 "errorCode,Failed to set MSCHAPv2 for TTLS Phase 2");
2769 return 0;
2770 }
2771
2772 return 1;
2773}
2774
2775
Jouni Malinenf7222712019-06-13 01:50:21 +03002776static enum sigma_cmd_result cmd_sta_set_eapsim(struct sigma_dut *dut,
2777 struct sigma_conn *conn,
2778 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002779{
2780 const char *intf = get_param(cmd, "Interface");
2781 const char *ifname;
2782 int id;
2783
2784 if (intf == NULL)
2785 return -1;
2786
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002787 if (strcmp(intf, get_main_ifname(dut)) == 0)
2788 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002789 else
2790 ifname = intf;
2791
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302792 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002793 if (id < 0)
2794 return id;
2795
2796 if (set_network(ifname, id, "eap", "SIM") < 0)
2797 return -2;
2798
2799 return 1;
2800}
2801
2802
Jouni Malinenf7222712019-06-13 01:50:21 +03002803static enum sigma_cmd_result cmd_sta_set_peap(struct sigma_dut *dut,
2804 struct sigma_conn *conn,
2805 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002806{
2807 const char *intf = get_param(cmd, "Interface");
2808 const char *ifname, *val;
2809 int id;
2810 char buf[100];
2811
2812 if (intf == NULL)
2813 return -1;
2814
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002815 if (strcmp(intf, get_main_ifname(dut)) == 0)
2816 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002817 else
2818 ifname = intf;
2819
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302820 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002821 if (id < 0)
2822 return id;
2823
2824 if (set_network(ifname, id, "eap", "PEAP") < 0)
2825 return -2;
2826
2827 val = get_param(cmd, "innerEAP");
2828 if (val) {
2829 if (strcasecmp(val, "MSCHAPv2") == 0) {
2830 if (set_network_quoted(ifname, id, "phase2",
2831 "auth=MSCHAPV2") < 0)
2832 return -2;
2833 } else if (strcasecmp(val, "GTC") == 0) {
2834 if (set_network_quoted(ifname, id, "phase2",
2835 "auth=GTC") < 0)
2836 return -2;
2837 } else
2838 return -1;
2839 }
2840
2841 val = get_param(cmd, "peapVersion");
2842 if (val) {
2843 int ver = atoi(val);
2844 if (ver < 0 || ver > 1)
2845 return -1;
2846 snprintf(buf, sizeof(buf), "peapver=%d", ver);
2847 if (set_network_quoted(ifname, id, "phase1", buf) < 0)
2848 return -2;
2849 }
2850
2851 return 1;
2852}
2853
2854
Jouni Malinenf7222712019-06-13 01:50:21 +03002855static enum sigma_cmd_result cmd_sta_set_eapfast(struct sigma_dut *dut,
2856 struct sigma_conn *conn,
2857 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002858{
2859 const char *intf = get_param(cmd, "Interface");
2860 const char *ifname, *val;
2861 int id;
2862 char buf[100];
2863
2864 if (intf == NULL)
2865 return -1;
2866
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002867 if (strcmp(intf, get_main_ifname(dut)) == 0)
2868 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002869 else
2870 ifname = intf;
2871
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302872 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002873 if (id < 0)
2874 return id;
2875
2876 if (set_network(ifname, id, "eap", "FAST") < 0)
2877 return -2;
2878
2879 val = get_param(cmd, "innerEAP");
2880 if (val) {
2881 if (strcasecmp(val, "MSCHAPV2") == 0) {
2882 if (set_network_quoted(ifname, id, "phase2",
2883 "auth=MSCHAPV2") < 0)
2884 return -2;
2885 } else if (strcasecmp(val, "GTC") == 0) {
2886 if (set_network_quoted(ifname, id, "phase2",
2887 "auth=GTC") < 0)
2888 return -2;
2889 } else
2890 return -1;
2891 }
2892
2893 val = get_param(cmd, "validateServer");
2894 if (val) {
2895 /* TODO */
2896 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored EAP-FAST "
2897 "validateServer=%s", val);
2898 }
2899
2900 val = get_param(cmd, "pacFile");
2901 if (val) {
2902 snprintf(buf, sizeof(buf), "blob://%s", val);
2903 if (set_network_quoted(ifname, id, "pac_file", buf) < 0)
2904 return -2;
2905 }
2906
2907 if (set_network_quoted(ifname, id, "phase1", "fast_provisioning=2") <
2908 0)
2909 return -2;
2910
2911 return 1;
2912}
2913
2914
Jouni Malinenf7222712019-06-13 01:50:21 +03002915static enum sigma_cmd_result cmd_sta_set_eapaka(struct sigma_dut *dut,
2916 struct sigma_conn *conn,
2917 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002918{
2919 const char *intf = get_param(cmd, "Interface");
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302920 const char *username = get_param(cmd, "Username");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002921 const char *ifname;
2922 int id;
2923
2924 if (intf == NULL)
2925 return -1;
2926
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002927 if (strcmp(intf, get_main_ifname(dut)) == 0)
2928 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002929 else
2930 ifname = intf;
2931
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302932 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002933 if (id < 0)
2934 return id;
2935
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302936 /* RFC 5448: EAP-AKA' MUST use the leading character "6" (ASCII 36
2937 * hexadecimal).
2938 */
2939 if (username && username[0] == '6') {
2940 if (set_network(ifname, id, "eap", "AKA'") < 0)
2941 return -2;
2942 } else if (set_network(ifname, id, "eap", "AKA") < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002943 return -2;
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302944 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002945
2946 return 1;
2947}
2948
2949
Jouni Malinenf7222712019-06-13 01:50:21 +03002950static enum sigma_cmd_result cmd_sta_set_eapakaprime(struct sigma_dut *dut,
2951 struct sigma_conn *conn,
2952 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002953{
2954 const char *intf = get_param(cmd, "Interface");
2955 const char *ifname;
2956 int id;
2957
2958 if (intf == NULL)
2959 return -1;
2960
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002961 if (strcmp(intf, get_main_ifname(dut)) == 0)
2962 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002963 else
2964 ifname = intf;
2965
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302966 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002967 if (id < 0)
2968 return id;
2969
2970 if (set_network(ifname, id, "eap", "AKA'") < 0)
2971 return -2;
2972
2973 return 1;
2974}
2975
2976
2977static int sta_set_open(struct sigma_dut *dut, struct sigma_conn *conn,
2978 struct sigma_cmd *cmd)
2979{
2980 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002981 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002982 const char *ifname;
2983 int id;
2984
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002985 if (strcmp(intf, get_main_ifname(dut)) == 0)
2986 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002987 else
2988 ifname = intf;
2989
2990 id = add_network_common(dut, conn, ifname, cmd);
2991 if (id < 0)
2992 return id;
2993
2994 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
2995 return -2;
2996
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002997 if (dut->program == PROGRAM_60GHZ && network_mode &&
2998 strcasecmp(network_mode, "PBSS") == 0 &&
2999 set_network(ifname, id, "pbss", "1") < 0)
3000 return -2;
3001
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003002 return 1;
3003}
3004
3005
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003006static enum sigma_cmd_result sta_set_owe(struct sigma_dut *dut,
3007 struct sigma_conn *conn,
3008 struct sigma_cmd *cmd)
Jouni Malinen47dcc952017-10-09 16:43:24 +03003009{
3010 const char *intf = get_param(cmd, "Interface");
3011 const char *ifname, *val;
3012 int id;
3013
3014 if (intf == NULL)
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003015 return INVALID_SEND_STATUS;
Jouni Malinen47dcc952017-10-09 16:43:24 +03003016
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003017 if (strcmp(intf, get_main_ifname(dut)) == 0)
3018 ifname = get_station_ifname(dut);
Jouni Malinen47dcc952017-10-09 16:43:24 +03003019 else
3020 ifname = intf;
3021
3022 id = set_wpa_common(dut, conn, ifname, cmd);
3023 if (id < 0)
3024 return id;
3025
3026 if (set_network(ifname, id, "key_mgmt", "OWE") < 0)
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003027 return ERROR_SEND_STATUS;
Jouni Malinen47dcc952017-10-09 16:43:24 +03003028
Hu Wangdd5eed22020-07-16 12:18:03 +08003029 if (dut->owe_ptk_workaround &&
3030 set_network(ifname, id, "owe_ptk_workaround", "1") < 0) {
3031 sigma_dut_print(dut, DUT_MSG_ERROR,
3032 "Failed to set owe_ptk_workaround to 1");
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003033 return ERROR_SEND_STATUS;
Hu Wangdd5eed22020-07-16 12:18:03 +08003034 }
3035
Jouni Malinen47dcc952017-10-09 16:43:24 +03003036 val = get_param(cmd, "ECGroupID");
Jouni Malinenfac9cad2017-10-10 18:35:55 +03003037 if (val && strcmp(val, "0") == 0) {
3038 if (wpa_command(ifname,
3039 "VENDOR_ELEM_ADD 13 ff23200000783590fb7440e03d5b3b33911f86affdcc6b4411b707846ac4ff08ddc8831ccd") != 0) {
3040 sigma_dut_print(dut, DUT_MSG_ERROR,
3041 "Failed to set OWE DH Param element override");
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003042 return ERROR_SEND_STATUS;
Jouni Malinenfac9cad2017-10-10 18:35:55 +03003043 }
Hu Wangdd5eed22020-07-16 12:18:03 +08003044 } else if (val && set_network(ifname, id, "owe_group", val) < 0) {
Jouni Malinen47dcc952017-10-09 16:43:24 +03003045 sigma_dut_print(dut, DUT_MSG_ERROR,
Hu Wang6010ce72020-03-05 19:33:53 +08003046 "Failed to set owe_group");
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003047 return ERROR_SEND_STATUS;
Jouni Malinen47dcc952017-10-09 16:43:24 +03003048 }
3049
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003050 return SUCCESS_SEND_STATUS;
Jouni Malinen47dcc952017-10-09 16:43:24 +03003051}
3052
3053
Jouni Malinenf7222712019-06-13 01:50:21 +03003054static enum sigma_cmd_result cmd_sta_set_security(struct sigma_dut *dut,
3055 struct sigma_conn *conn,
3056 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003057{
3058 const char *type = get_param(cmd, "Type");
3059
3060 if (type == NULL) {
3061 send_resp(dut, conn, SIGMA_ERROR,
3062 "ErrorCode,Missing Type argument");
3063 return 0;
3064 }
3065
3066 if (strcasecmp(type, "OPEN") == 0)
3067 return sta_set_open(dut, conn, cmd);
Jouni Malinen47dcc952017-10-09 16:43:24 +03003068 if (strcasecmp(type, "OWE") == 0)
3069 return sta_set_owe(dut, conn, cmd);
Jouni Malinen992a81e2017-08-22 13:57:47 +03003070 if (strcasecmp(type, "PSK") == 0 ||
Jouni Malinen0ab50f42017-08-31 01:34:59 +03003071 strcasecmp(type, "PSK-SAE") == 0 ||
Jouni Malinen992a81e2017-08-22 13:57:47 +03003072 strcasecmp(type, "SAE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003073 return cmd_sta_set_psk(dut, conn, cmd);
3074 if (strcasecmp(type, "EAPTLS") == 0)
3075 return cmd_sta_set_eaptls(dut, conn, cmd);
3076 if (strcasecmp(type, "EAPTTLS") == 0)
3077 return cmd_sta_set_eapttls(dut, conn, cmd);
3078 if (strcasecmp(type, "EAPPEAP") == 0)
3079 return cmd_sta_set_peap(dut, conn, cmd);
3080 if (strcasecmp(type, "EAPSIM") == 0)
3081 return cmd_sta_set_eapsim(dut, conn, cmd);
3082 if (strcasecmp(type, "EAPFAST") == 0)
3083 return cmd_sta_set_eapfast(dut, conn, cmd);
3084 if (strcasecmp(type, "EAPAKA") == 0)
3085 return cmd_sta_set_eapaka(dut, conn, cmd);
3086 if (strcasecmp(type, "EAPAKAPRIME") == 0)
3087 return cmd_sta_set_eapakaprime(dut, conn, cmd);
Amarnath Hullur Subramanyam81b11cd2018-01-30 19:07:17 -08003088 if (strcasecmp(type, "wep") == 0)
3089 return cmd_sta_set_encryption(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003090
3091 send_resp(dut, conn, SIGMA_ERROR,
3092 "ErrorCode,Unsupported Type value");
3093 return 0;
3094}
3095
3096
3097int ath6kl_client_uapsd(struct sigma_dut *dut, const char *intf, int uapsd)
3098{
3099#ifdef __linux__
3100 /* special handling for ath6kl */
3101 char path[128], fname[128], *pos;
3102 ssize_t res;
3103 FILE *f;
3104
Jouni Malinene39cd562019-05-29 23:39:56 +03003105 res = snprintf(fname, sizeof(fname), "/sys/class/net/%s/phy80211",
3106 intf);
3107 if (res < 0 || res >= sizeof(fname))
3108 return 0;
3109 res = readlink(fname, path, sizeof(path));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003110 if (res < 0)
3111 return 0; /* not ath6kl */
3112
3113 if (res >= (int) sizeof(path))
3114 res = sizeof(path) - 1;
3115 path[res] = '\0';
3116 pos = strrchr(path, '/');
3117 if (pos == NULL)
3118 pos = path;
3119 else
3120 pos++;
Jouni Malinen77dda642020-01-07 11:21:55 +02003121 res = snprintf(fname, sizeof(fname),
3122 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
3123 "create_qos", pos);
3124 if (res < 0 || res >= sizeof(fname) || !file_exists(fname))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003125 return 0; /* not ath6kl */
3126
3127 if (uapsd) {
3128 f = fopen(fname, "w");
3129 if (f == NULL)
3130 return -1;
3131
3132 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl create_qos");
3133 fprintf(f, "4 2 2 1 2 9999999 9999999 9999999 7777777 0 4 "
3134 "45000 200 56789000 56789000 5678900 0 0 9999999 "
3135 "20000 0\n");
3136 fclose(f);
3137 } else {
Jouni Malinen77dda642020-01-07 11:21:55 +02003138 res = snprintf(fname, sizeof(fname),
3139 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
3140 "delete_qos", pos);
3141 if (res < 0 || res >= sizeof(fname))
3142 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003143
3144 f = fopen(fname, "w");
3145 if (f == NULL)
3146 return -1;
3147
3148 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl delete_qos");
3149 fprintf(f, "2 4\n");
3150 fclose(f);
3151 }
3152#endif /* __linux__ */
3153
3154 return 0;
3155}
3156
3157
Jouni Malinenf7222712019-06-13 01:50:21 +03003158static enum sigma_cmd_result cmd_sta_set_uapsd(struct sigma_dut *dut,
3159 struct sigma_conn *conn,
3160 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003161{
3162 const char *intf = get_param(cmd, "Interface");
3163 /* const char *ssid = get_param(cmd, "ssid"); */
3164 const char *val;
3165 int max_sp_len = 4;
3166 int ac_be = 1, ac_bk = 1, ac_vi = 1, ac_vo = 1;
3167 char buf[100];
3168 int ret1, ret2;
3169
3170 val = get_param(cmd, "maxSPLength");
3171 if (val) {
3172 max_sp_len = atoi(val);
3173 if (max_sp_len != 0 && max_sp_len != 1 && max_sp_len != 2 &&
3174 max_sp_len != 4)
3175 return -1;
3176 }
3177
3178 val = get_param(cmd, "acBE");
3179 if (val)
3180 ac_be = atoi(val);
3181
3182 val = get_param(cmd, "acBK");
3183 if (val)
3184 ac_bk = atoi(val);
3185
3186 val = get_param(cmd, "acVI");
3187 if (val)
3188 ac_vi = atoi(val);
3189
3190 val = get_param(cmd, "acVO");
3191 if (val)
3192 ac_vo = atoi(val);
3193
3194 dut->client_uapsd = ac_be || ac_bk || ac_vi || ac_vo;
3195
3196 snprintf(buf, sizeof(buf), "P2P_SET client_apsd %d,%d,%d,%d;%d",
3197 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
3198 ret1 = wpa_command(intf, buf);
3199
3200 snprintf(buf, sizeof(buf), "SET uapsd %d,%d,%d,%d;%d",
3201 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
3202 ret2 = wpa_command(intf, buf);
3203
3204 if (ret1 && ret2) {
3205 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to set client mode "
3206 "UAPSD parameters.");
3207 return -2;
3208 }
3209
3210 if (ath6kl_client_uapsd(dut, intf, dut->client_uapsd) < 0) {
3211 send_resp(dut, conn, SIGMA_ERROR,
3212 "ErrorCode,Failed to set ath6kl QoS parameters");
3213 return 0;
3214 }
3215
3216 return 1;
3217}
3218
3219
Jouni Malinenf7222712019-06-13 01:50:21 +03003220static enum sigma_cmd_result cmd_sta_set_wmm(struct sigma_dut *dut,
3221 struct sigma_conn *conn,
3222 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003223{
3224 char buf[1000];
3225 const char *intf = get_param(cmd, "Interface");
3226 const char *grp = get_param(cmd, "Group");
3227 const char *act = get_param(cmd, "Action");
3228 const char *tid = get_param(cmd, "Tid");
3229 const char *dir = get_param(cmd, "Direction");
3230 const char *psb = get_param(cmd, "Psb");
3231 const char *up = get_param(cmd, "Up");
3232 const char *fixed = get_param(cmd, "Fixed");
3233 const char *size = get_param(cmd, "Size");
3234 const char *msize = get_param(cmd, "Maxsize");
3235 const char *minsi = get_param(cmd, "Min_srvc_intrvl");
3236 const char *maxsi = get_param(cmd, "Max_srvc_intrvl");
3237 const char *inact = get_param(cmd, "Inactivity");
3238 const char *sus = get_param(cmd, "Suspension");
3239 const char *mindr = get_param(cmd, "Mindatarate");
3240 const char *meandr = get_param(cmd, "Meandatarate");
3241 const char *peakdr = get_param(cmd, "Peakdatarate");
3242 const char *phyrate = get_param(cmd, "Phyrate");
3243 const char *burstsize = get_param(cmd, "Burstsize");
3244 const char *sba = get_param(cmd, "Sba");
3245 int direction;
3246 int handle;
Peng Xu93319622017-10-04 17:58:16 -07003247 float sba_fv = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003248 int fixed_int;
3249 int psb_ts;
3250
3251 if (intf == NULL || grp == NULL || act == NULL )
3252 return -1;
3253
3254 if (strcasecmp(act, "addts") == 0) {
3255 if (tid == NULL || dir == NULL || psb == NULL ||
3256 up == NULL || fixed == NULL || size == NULL)
3257 return -1;
3258
3259 /*
3260 * Note: Sigma CAPI spec lists uplink, downlink, and bidi as the
3261 * possible values, but WMM-AC and V-E test scripts use "UP,
3262 * "DOWN", and "BIDI".
3263 */
3264 if (strcasecmp(dir, "uplink") == 0 ||
3265 strcasecmp(dir, "up") == 0) {
3266 direction = 0;
3267 } else if (strcasecmp(dir, "downlink") == 0 ||
3268 strcasecmp(dir, "down") == 0) {
3269 direction = 1;
3270 } else if (strcasecmp(dir, "bidi") == 0) {
3271 direction = 2;
3272 } else {
3273 sigma_dut_print(dut, DUT_MSG_ERROR,
3274 "Direction %s not supported", dir);
3275 return -1;
3276 }
3277
3278 if (strcasecmp(psb, "legacy") == 0) {
3279 psb_ts = 0;
3280 } else if (strcasecmp(psb, "uapsd") == 0) {
3281 psb_ts = 1;
3282 } else {
3283 sigma_dut_print(dut, DUT_MSG_ERROR,
3284 "PSB %s not supported", psb);
3285 return -1;
3286 }
3287
3288 if (atoi(tid) < 0 || atoi(tid) > 7) {
3289 sigma_dut_print(dut, DUT_MSG_ERROR,
3290 "TID %s not supported", tid);
3291 return -1;
3292 }
3293
3294 if (strcasecmp(fixed, "true") == 0) {
3295 fixed_int = 1;
3296 } else {
3297 fixed_int = 0;
3298 }
3299
Peng Xu93319622017-10-04 17:58:16 -07003300 if (sba)
3301 sba_fv = atof(sba);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003302
3303 dut->dialog_token++;
3304 handle = 7000 + dut->dialog_token;
3305
3306 /*
3307 * size: convert to hex
3308 * maxsi: convert to hex
3309 * mindr: convert to hex
3310 * meandr: convert to hex
3311 * peakdr: convert to hex
3312 * burstsize: convert to hex
3313 * phyrate: convert to hex
3314 * sba: convert to hex with modification
3315 * minsi: convert to integer
3316 * sus: convert to integer
3317 * inact: convert to integer
3318 * maxsi: convert to integer
3319 */
3320
3321 /*
3322 * The Nominal MSDU Size field is 2 octets long and contains an
3323 * unsigned integer that specifies the nominal size, in octets,
3324 * of MSDUs belonging to the traffic under this traffic
3325 * specification and is defined in Figure 16. If the Fixed
3326 * subfield is set to 1, then the size of the MSDU is fixed and
3327 * is indicated by the Size Subfield. If the Fixed subfield is
3328 * set to 0, then the size of the MSDU might not be fixed and
3329 * the Size indicates the nominal MSDU size.
3330 *
3331 * The Surplus Bandwidth Allowance Factor field is 2 octets long
3332 * and specifies the excess allocation of time (and bandwidth)
3333 * over and above the stated rates required to transport an MSDU
3334 * belonging to the traffic in this TSPEC. This field is
3335 * represented as an unsigned binary number with an implicit
3336 * binary point after the leftmost 3 bits. For example, an SBA
3337 * of 1.75 is represented as 0x3800. This field is included to
3338 * account for retransmissions. As such, the value of this field
3339 * must be greater than unity.
3340 */
3341
3342 snprintf(buf, sizeof(buf),
3343 "iwpriv %s addTspec %d %s %d %d %s 0x%X"
3344 " 0x%X 0x%X 0x%X"
3345 " 0x%X 0x%X 0x%X"
3346 " 0x%X %d %d %d %d"
3347 " %d %d",
3348 intf, handle, tid, direction, psb_ts, up,
3349 (unsigned int) ((fixed_int << 15) | atoi(size)),
3350 msize ? atoi(msize) : 0,
3351 mindr ? atoi(mindr) : 0,
3352 meandr ? atoi(meandr) : 0,
3353 peakdr ? atoi(peakdr) : 0,
3354 burstsize ? atoi(burstsize) : 0,
3355 phyrate ? atoi(phyrate) : 0,
3356 sba ? ((unsigned int) (((int) sba_fv << 13) |
3357 (int)((sba_fv - (int) sba_fv) *
3358 8192))) : 0,
3359 minsi ? atoi(minsi) : 0,
3360 sus ? atoi(sus) : 0,
3361 0, 0,
3362 inact ? atoi(inact) : 0,
3363 maxsi ? atoi(maxsi) : 0);
3364
3365 if (system(buf) != 0) {
3366 sigma_dut_print(dut, DUT_MSG_ERROR,
3367 "iwpriv addtspec request failed");
3368 send_resp(dut, conn, SIGMA_ERROR,
3369 "errorCode,Failed to execute addTspec command");
3370 return 0;
3371 }
3372
3373 sigma_dut_print(dut, DUT_MSG_INFO,
3374 "iwpriv addtspec request send");
3375
3376 /* Mapping handle to a TID */
3377 dut->tid_to_handle[atoi(tid)] = handle;
3378 } else if (strcasecmp(act, "delts") == 0) {
3379 if (tid == NULL)
3380 return -1;
3381
3382 if (atoi(tid) < 0 || atoi(tid) > 7) {
3383 sigma_dut_print(dut, DUT_MSG_ERROR,
3384 "TID %s not supported", tid);
3385 send_resp(dut, conn, SIGMA_ERROR,
3386 "errorCode,Unsupported TID");
3387 return 0;
3388 }
3389
3390 handle = dut->tid_to_handle[atoi(tid)];
3391
3392 if (handle < 7000 || handle > 7255) {
3393 /* Invalid handle ie no mapping for that TID */
3394 sigma_dut_print(dut, DUT_MSG_ERROR,
3395 "handle-> %d not found", handle);
3396 }
3397
3398 snprintf(buf, sizeof(buf), "iwpriv %s delTspec %d",
3399 intf, handle);
3400
3401 if (system(buf) != 0) {
3402 sigma_dut_print(dut, DUT_MSG_ERROR,
3403 "iwpriv deltspec request failed");
3404 send_resp(dut, conn, SIGMA_ERROR,
3405 "errorCode,Failed to execute delTspec command");
3406 return 0;
3407 }
3408
3409 sigma_dut_print(dut, DUT_MSG_INFO,
3410 "iwpriv deltspec request send");
3411
3412 dut->tid_to_handle[atoi(tid)] = 0;
3413 } else {
3414 sigma_dut_print(dut, DUT_MSG_ERROR,
3415 "Action type %s not supported", act);
3416 send_resp(dut, conn, SIGMA_ERROR,
3417 "errorCode,Unsupported Action");
3418 return 0;
3419 }
3420
3421 return 1;
3422}
3423
3424
vamsi krishna52e16f92017-08-29 12:37:34 +05303425static int find_network(struct sigma_dut *dut, const char *ssid)
3426{
3427 char list[4096];
3428 char *pos;
3429
3430 sigma_dut_print(dut, DUT_MSG_DEBUG,
3431 "Search for profile based on SSID: '%s'", ssid);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003432 if (wpa_command_resp(get_station_ifname(dut), "LIST_NETWORKS",
vamsi krishna52e16f92017-08-29 12:37:34 +05303433 list, sizeof(list)) < 0)
3434 return -1;
3435 pos = strstr(list, ssid);
3436 if (!pos || pos == list || pos[-1] != '\t' || pos[strlen(ssid)] != '\t')
3437 return -1;
3438
3439 while (pos > list && pos[-1] != '\n')
3440 pos--;
3441 dut->infra_network_id = atoi(pos);
3442 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
3443 return 0;
3444}
3445
3446
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303447/**
3448 * enum qca_sta_helper_config_params - This helper enum defines the config
3449 * parameters which can be delivered to sta.
3450 */
3451enum qca_sta_helper_config_params {
3452 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE */
3453 STA_SET_RSNIE,
3454
3455 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_LDPC */
3456 STA_SET_LDPC,
3457
3458 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_TX_STBC */
3459 STA_SET_TX_STBC,
3460
3461 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_RX_STBC */
3462 STA_SET_RX_STBC,
3463
3464 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_TX_MSDU_AGGREGATION */
3465 STA_SET_TX_MSDU,
3466
3467 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_RX_MSDU_AGGREGATION */
3468 STA_SET_RX_MSDU,
Shivani Baranwal2a572842021-09-16 12:27:15 +05303469
3470 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_CHANNEL_WIDTH */
3471 STA_SET_CHAN_WIDTH,
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303472};
3473
3474
3475static int sta_config_params(struct sigma_dut *dut, const char *intf,
3476 enum qca_sta_helper_config_params config_cmd,
3477 int value)
Sunil Dutt44595082018-02-12 19:41:45 +05303478{
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303479#ifdef NL80211_SUPPORT
Sunil Dutt44595082018-02-12 19:41:45 +05303480 struct nl_msg *msg;
3481 int ret;
3482 struct nlattr *params;
3483 int ifindex;
3484
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303485 ifindex = if_nametoindex(intf);
3486 if (ifindex == 0) {
3487 sigma_dut_print(dut, DUT_MSG_ERROR,
3488 "%s: Interface %s does not exist",
3489 __func__, intf);
3490 return -1;
3491 }
3492
Sunil Dutt44595082018-02-12 19:41:45 +05303493 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
3494 NL80211_CMD_VENDOR)) ||
3495 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
3496 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
3497 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
3498 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) ||
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303499 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)))
3500 goto fail;
3501
3502 switch (config_cmd) {
3503 case STA_SET_RSNIE:
3504 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE, value))
3505 goto fail;
3506 break;
3507 case STA_SET_LDPC:
3508 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_LDPC, value))
3509 goto fail;
3510 break;
3511 case STA_SET_TX_STBC:
3512 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TX_STBC, value))
3513 goto fail;
3514 break;
3515 case STA_SET_RX_STBC:
3516 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_RX_STBC, value))
3517 goto fail;
3518 break;
3519 case STA_SET_TX_MSDU:
3520 if (nla_put_u8(msg,
3521 QCA_WLAN_VENDOR_ATTR_CONFIG_TX_MSDU_AGGREGATION,
3522 value))
3523 goto fail;
3524 break;
3525 case STA_SET_RX_MSDU:
3526 if (nla_put_u8(msg,
3527 QCA_WLAN_VENDOR_ATTR_CONFIG_RX_MSDU_AGGREGATION,
3528 value))
3529 goto fail;
3530 break;
Shivani Baranwal2a572842021-09-16 12:27:15 +05303531 case STA_SET_CHAN_WIDTH:
3532 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_CHANNEL_WIDTH,
3533 value))
3534 goto fail;
3535 break;
Sunil Dutt44595082018-02-12 19:41:45 +05303536 }
3537 nla_nest_end(msg, params);
3538
3539 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
3540 if (ret) {
3541 sigma_dut_print(dut, DUT_MSG_ERROR,
3542 "%s: err in send_and_recv_msgs, ret=%d",
3543 __func__, ret);
3544 return ret;
3545 }
3546
3547 return 0;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303548
3549fail:
3550 sigma_dut_print(dut, DUT_MSG_ERROR,
3551 "%s: err in adding vendor_cmd and vendor_data",
3552 __func__);
3553 nlmsg_free(msg);
Sunil Dutt44595082018-02-12 19:41:45 +05303554#endif /* NL80211_SUPPORT */
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303555 return -1;
3556}
Sunil Dutt44595082018-02-12 19:41:45 +05303557
3558
Veerendranath Jakkam9ceb3b12021-09-10 03:18:17 +05303559void free_dscp_policy_table(struct sigma_dut *dut)
3560{
3561 struct dscp_policy_data *dscp_policy;
3562
3563 while (dut->dscp_policy_table) {
3564 dscp_policy = dut->dscp_policy_table;
3565 dut->dscp_policy_table = dscp_policy->next;
3566 free(dscp_policy);
3567 }
3568}
3569
3570
3571static int delete_nft_table(struct sigma_dut *dut, const char *table,
3572 const char *ip_type)
3573{
3574 int res;
3575 char cmd[200];
3576
3577 res = snprintf(cmd, sizeof(cmd), "nft delete table %s %s_%s", ip_type,
3578 table, ip_type);
3579 if (snprintf_error(sizeof(cmd), res)) {
3580 sigma_dut_print(dut, DUT_MSG_ERROR,
3581 "Failed to create delete table command");
3582 return -1;
3583 }
3584
3585 if (system(cmd) != 0) {
3586 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run %s", cmd);
3587 return -1;
3588 }
3589
3590 return 0;
3591}
3592
3593
3594static int remove_nft_rule(struct sigma_dut *dut, int policy_id,
3595 enum ip_version ip_ver)
3596{
3597 int res;
3598 char table[50];
3599
3600 res = snprintf(table, sizeof(table), "wifi_%s_dscp_policy_%d",
3601 dut->station_ifname, policy_id);
3602 if (snprintf_error(sizeof(table), res)) {
3603 sigma_dut_print(dut, DUT_MSG_INFO,
3604 "Failed to create table name for policy %d",
3605 policy_id);
3606 return -1;
3607 }
3608
3609
3610 if (ip_ver == IPV6)
3611 return delete_nft_table(dut, table, "ip6");
3612 else
3613 return delete_nft_table(dut, table, "ip");
3614}
3615
3616
3617static int create_nft_table(struct sigma_dut *dut, int policy_id,
3618 const char *table_name, enum ip_version ip_ver)
3619{
3620 char cmd[200];
3621 int res;
3622
3623 res = snprintf(cmd, sizeof(cmd), "nft add table %s %s",
3624 ip_ver == IPV6 ? "ip6" : "ip", table_name);
3625 if (snprintf_error(sizeof(cmd), res)) {
3626 sigma_dut_print(dut, DUT_MSG_INFO,
3627 "Failed to add rule to create table for policy id %d",
3628 policy_id);
3629 return -1;
3630 }
3631
3632 if (system(cmd) != 0) {
3633 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run %s", cmd);
3634 return -1;
3635 }
3636
3637 res = snprintf(cmd, sizeof(cmd),
3638 "nft add chain %s %s OUTPUT { type filter hook output priority 0 \\; }",
3639 ip_ver == IPV6 ? "ip6" : "ip", table_name);
3640 if (snprintf_error(sizeof(cmd), res)) {
3641 sigma_dut_print(dut, DUT_MSG_INFO,
3642 "Failed to add rule to create chain for table = %s",
3643 table_name);
3644 return -1;
3645 }
3646
3647 if (system(cmd) != 0) {
3648 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run %s", cmd);
3649 return -1;
3650 }
3651
3652 return 0;
3653}
3654
3655
3656static char * protocol_to_str(int proto)
3657{
3658 switch (proto) {
3659 case 6:
3660 return "tcp";
3661 case 17:
3662 return "udp";
3663 case 50:
3664 return "esp";
3665 default:
3666 return "unknown";
3667 }
3668}
3669
3670
3671static int remove_dscp_policy(struct sigma_dut *dut, u8 policy_id)
3672{
3673 struct dscp_policy_data *dscp_policy = dut->dscp_policy_table;
3674 struct dscp_policy_data *prev = NULL;
3675
3676 while (dscp_policy) {
3677 if (dscp_policy->policy_id == policy_id)
3678 break;
3679
3680 prev = dscp_policy;
3681 dscp_policy = dscp_policy->next;
3682 }
3683
3684 /*
3685 * Consider remove request for a policy id which does not exist as
3686 * success.
3687 */
3688 if (!dscp_policy)
3689 return 0;
3690
3691 if (strlen(dscp_policy->domain_name) == 0 &&
3692 remove_nft_rule(dut, policy_id, dscp_policy->ip_version))
3693 return -1;
3694
3695 if (prev)
3696 prev->next = dscp_policy->next;
3697 else
3698 dut->dscp_policy_table = dscp_policy->next;
3699
3700 free(dscp_policy);
3701 return 0;
3702}
3703
3704
3705static int add_nft_rule(struct sigma_dut *dut,
3706 struct dscp_policy_data *dscp_policy)
3707{
3708 char nft_cmd[1000], ip[4], table_name[100];
3709 char *pos;
3710 int ret, len, policy_id = dscp_policy->policy_id;
3711 enum ip_version ip_ver = dscp_policy->ip_version;
3712
3713 if (ip_ver == IPV6)
3714 strlcpy(ip, "ip6", sizeof(ip));
3715 else
3716 strlcpy(ip, "ip", sizeof(ip));
3717
3718 ret = snprintf(table_name, sizeof(table_name),
3719 "wifi_%s_dscp_policy_%d_%s",
3720 dut->station_ifname, policy_id, ip);
3721 if (snprintf_error(sizeof(table_name), ret))
3722 return -1;
3723
3724 if (create_nft_table(dut, policy_id, table_name, ip_ver)) {
3725 sigma_dut_print(dut, DUT_MSG_INFO,
3726 "Failed to create nft table");
3727 return -1;
3728 }
3729
3730 pos = nft_cmd;
3731 len = sizeof(nft_cmd);
3732
3733 ret = snprintf(pos, len,
3734 "nft add rule %s %s OUTPUT oifname \"%s\"",
3735 ip, table_name, dut->station_ifname);
3736 if (snprintf_error(len, ret)) {
3737 sigma_dut_print(dut, DUT_MSG_INFO,
3738 "Failed to create nft cmd %s", nft_cmd);
3739 return -1;
3740 }
3741
3742 pos += ret;
3743 len -= ret;
3744
3745 if (strlen(dscp_policy->src_ip)) {
3746 ret = snprintf(pos, len, " %s saddr %s", ip,
3747 dscp_policy->src_ip);
3748 if (snprintf_error(len, ret))
3749 return -1;
3750
3751 pos += ret;
3752 len -= ret;
3753 }
3754
3755 if (strlen(dscp_policy->dst_ip)) {
3756 ret = snprintf(pos, len, " %s daddr %s", ip,
3757 dscp_policy->dst_ip);
3758 if (snprintf_error(len, ret))
3759 return -1;
3760
3761 pos += ret;
3762 len -= ret;
3763 }
3764
3765 if (dscp_policy->src_port) {
3766 ret = snprintf(pos, len, " %s sport %d",
3767 protocol_to_str(dscp_policy->protocol),
3768 dscp_policy->src_port);
3769 if (snprintf_error(len, ret))
3770 return -1;
3771
3772 pos += ret;
3773 len -= ret;
3774 }
3775
3776 if (dscp_policy->dst_port) {
3777 ret = snprintf(pos, len, " %s dport %d",
3778 protocol_to_str(dscp_policy->protocol),
3779 dscp_policy->dst_port);
3780 if (snprintf_error(len, ret))
3781 return -1;
3782
3783 pos += ret;
3784 len -= ret;
3785 }
3786
3787 if (dscp_policy->start_port && dscp_policy->end_port) {
3788 ret = snprintf(pos, len, " %s dport %d-%d",
3789 protocol_to_str(dscp_policy->protocol),
3790 dscp_policy->start_port,
3791 dscp_policy->end_port);
3792 if (snprintf_error(len, ret))
3793 return -1;
3794
3795 pos += ret;
3796 len -= ret;
3797 }
3798
3799 ret = snprintf(pos, len, " counter %s dscp set 0x%0x", ip,
3800 dscp_policy->dscp);
3801 if (snprintf_error(len, ret))
3802 return -1;
3803
3804 ret = system(nft_cmd);
3805 sigma_dut_print(dut, DUT_MSG_INFO, "nft rule: %s err: %d",
3806 nft_cmd, ret);
3807
3808 return ret;
3809}
3810
3811
3812static void clear_all_dscp_policies(struct sigma_dut *dut)
3813{
3814 free_dscp_policy_table(dut);
3815
3816 if (system("nft flush ruleset") != 0)
3817 sigma_dut_print(dut, DUT_MSG_ERROR,
3818 "Failed to flush DSCP policy");
3819}
3820
3821
3822static int send_dscp_response(struct sigma_dut *dut,
3823 struct dscp_policy_status *status_list,
3824 int num_status)
3825{
3826 int rem_len, ret;
3827 char buf[200] = "", *pos, cmd[256];
3828
3829 pos = buf;
3830 rem_len = sizeof(buf);
3831
3832 ret = snprintf(pos, rem_len, " solicited");
3833 if (snprintf_error(rem_len, ret)) {
3834 sigma_dut_print(dut, DUT_MSG_ERROR,
3835 "Failed to write DSCP policy response command");
3836 return -1;
3837 }
3838 pos += ret;
3839 rem_len -= ret;
3840
3841 for (int i = 0; i < num_status; i++) {
3842 ret = snprintf(pos, rem_len, " policy_id=%d status=%d",
3843 status_list[i].id, status_list[i].status);
3844 if (snprintf_error(rem_len, ret)) {
3845 sigma_dut_print(dut, DUT_MSG_ERROR,
3846 "Failed to wite DSCP policy response");
3847 return -1;
3848 }
3849
3850 pos += ret;
3851 rem_len -= ret;
3852 }
3853
3854 ret = snprintf(cmd, sizeof(cmd), "DSCP_RESP%s", buf);
3855 if (snprintf_error(sizeof(cmd), ret)) {
3856 sigma_dut_print(dut, DUT_MSG_ERROR,
3857 "Failed to create DSCP Policy Response frame");
3858 return -1;
3859 }
3860
3861 if (wpa_command(dut->station_ifname, cmd) != 0) {
3862 sigma_dut_print(dut, DUT_MSG_ERROR,
3863 "Failed to send DSCP Policy Response frame");
3864 return -1;
3865 }
3866
3867 sigma_dut_print(dut, DUT_MSG_DEBUG,
3868 "DSCP Policy Response frame sent: %s", cmd);
3869 return 0;
3870}
3871
3872
3873#ifdef ANDROID
3874static void thread_cancel_handler(int sig)
3875{
3876 if (sig == SIGUSR1)
3877 pthread_exit(0);
3878}
3879#endif /* ANDROID */
3880
3881
3882static void * mon_dscp_policies(void *ptr)
3883{
3884 struct sigma_dut *dut = ptr;
3885 int ret, policy_id;
3886 struct wpa_ctrl *ctrl;
3887 char buf[4096], *pos, *end;
3888 struct dscp_policy_data *policy = NULL, *policy_table;
3889 struct dscp_policy_status status_list[10];
3890 int num_status = 0;
3891 const char *events[] = {
3892 "CTRL-EVENT-DISCONNECTED",
3893 "CTRL-EVENT-DSCP-POLICY",
3894 NULL
3895 };
3896#ifdef ANDROID
3897 struct sigaction actions;
3898#endif /* ANDROID */
3899
3900 ctrl = open_wpa_mon(get_station_ifname(dut));
3901 if (!ctrl) {
3902 sigma_dut_print(dut, DUT_MSG_ERROR,
3903 "Failed to open wpa_supplicant monitor connection");
3904 return NULL;
3905 }
3906
3907#ifdef ANDROID
3908 memset(&actions, 0, sizeof(actions));
3909 sigemptyset(&actions.sa_mask);
3910 actions.sa_flags = 0;
3911 actions.sa_handler = thread_cancel_handler;
3912 if (sigaction(SIGUSR1, &actions, NULL) == -1) {
3913 sigma_dut_print(dut, DUT_MSG_ERROR,
3914 "Failed to register exit handler for %s",
3915 __func__);
3916 wpa_ctrl_detach(ctrl);
3917 wpa_ctrl_close(ctrl);
3918 return NULL;
3919 }
3920#endif /* ANDROID */
3921
3922 while (1) {
3923 ret = get_wpa_cli_events_timeout(dut, ctrl, events,
3924 buf, sizeof(buf), 0);
3925
3926 if (ret || strlen(buf) == 0) {
3927 sigma_dut_print(dut, DUT_MSG_INFO,
3928 "Did not receive any event");
3929 continue;
3930 }
3931
3932 if (strstr(buf, "CTRL-EVENT-DISCONNECTED")) {
3933 clear_all_dscp_policies(dut);
3934 break;
3935 }
3936
3937 if (strstr(buf, "request_start")) {
3938 num_status = 0;
3939 if (strstr(buf, "clear_all"))
3940 clear_all_dscp_policies(dut);
3941 continue;
3942 }
3943
3944 if (strstr(buf, "request_end")) {
3945 send_dscp_response(dut, status_list, num_status);
3946 continue;
3947 }
3948
3949 if (!strstr(buf, "add") && !strstr(buf, "remove") &&
3950 !strstr(buf, "reject")) {
3951 sigma_dut_print(dut, DUT_MSG_DEBUG, "Ignore event: %s",
3952 buf);
3953 continue;
3954 }
3955
3956 pos = strstr(buf, "policy_id=");
3957 if (!pos) {
3958 sigma_dut_print(dut, DUT_MSG_INFO,
3959 "Policy id not present");
3960 continue;
3961 }
3962 policy_id = atoi(pos + 10);
3963
3964 if (num_status >= ARRAY_SIZE(status_list)) {
3965 sigma_dut_print(dut, DUT_MSG_INFO,
3966 "Max policies allowed per DSCP request reached. Drop policy id %d request",
3967 policy_id);
3968 continue;
3969 }
3970 status_list[num_status].id = policy_id;
3971
Veerendranath Jakkama16cdc82021-09-12 16:44:22 +05303972 if (dut->reject_dscp_policies) {
3973 status_list[num_status].status =
3974 dut->dscp_reject_resp_code;
3975 num_status++;
3976 continue;
3977 }
3978
Veerendranath Jakkam9ceb3b12021-09-10 03:18:17 +05303979 if (strstr(buf, "reject"))
3980 goto reject;
3981
3982 /*
3983 * In case of "add" also if policy with same policy id exist it
3984 * shall be removed. So always call remove_dscp_policy().
3985 */
3986 if (remove_dscp_policy(dut, policy_id))
3987 goto reject;
3988
3989 if (strstr(buf, "remove"))
3990 goto success;
3991
3992 policy = malloc(sizeof(*policy));
3993 if (!policy)
3994 goto reject;
3995
3996 memset(policy, 0, sizeof(*policy));
3997
3998 policy->policy_id = policy_id;
3999
4000 pos = strstr(buf, "dscp=");
4001 if (!pos) {
4002 sigma_dut_print(dut, DUT_MSG_ERROR,
4003 "DSCP info not present");
4004 goto reject;
4005 }
4006 policy->dscp = atoi(pos + 5);
4007
4008 pos = strstr(buf, "ip_version=");
4009 if (!pos) {
4010 sigma_dut_print(dut, DUT_MSG_ERROR,
4011 "IP version info not present");
4012 goto reject;
4013 }
4014 policy->ip_version = atoi(pos + 11);
4015
4016 pos = strstr(buf, "domain_name=");
4017 if (pos) {
4018 pos += 12;
4019 end = strchr(pos, ' ');
4020 if (!end)
4021 end = pos + strlen(pos);
4022
4023 if (end - pos >= (int) sizeof(policy->domain_name))
4024 goto reject;
4025
4026 memcpy(policy->domain_name, pos, end - pos);
4027 policy->domain_name[end - pos] = '\0';
4028 }
4029
4030 pos = strstr(buf, "start_port=");
4031 if (pos) {
4032 pos += 11;
4033 policy->start_port = atoi(pos);
4034 }
4035
4036 pos = strstr(buf, "end_port=");
4037 if (pos) {
4038 pos += 9;
4039 policy->end_port = atoi(pos);
4040 }
4041
4042 pos = strstr(buf, "src_ip=");
4043 if (pos) {
4044 pos += 7;
4045 end = strchr(pos, ' ');
4046 if (!end)
4047 end = pos + strlen(pos);
4048
4049 if (end - pos >= (int) sizeof(policy->src_ip))
4050 goto reject;
4051
4052 memcpy(policy->src_ip, pos, end - pos);
4053 policy->src_ip[end - pos] = '\0';
4054 }
4055
4056 pos = strstr(buf, "dst_ip=");
4057 if (pos) {
4058 pos += 7;
4059 end = strchr(pos, ' ');
4060 if (!end)
4061 end = pos + strlen(pos);
4062
4063 if (end - pos >= (int) sizeof(policy->dst_ip))
4064 goto reject;
4065
4066 memcpy(policy->dst_ip, pos, end - pos);
4067 policy->dst_ip[end - pos] = '\0';
4068 }
4069
4070 pos = strstr(buf, "src_port=");
4071 if (pos) {
4072 pos += 9;
4073 policy->src_port = atoi(pos);
4074 }
4075
4076 pos = strstr(buf, "dst_port=");
4077 if (pos) {
4078 pos += 9;
4079 policy->dst_port = atoi(pos);
4080 }
4081
4082 pos = strstr(buf, "protocol=");
4083 if (pos) {
4084 pos += 9;
4085 policy->protocol = atoi(pos);
4086 }
4087
4088 /*
4089 * Skip adding nft rules for doman name policies.
4090 * Domain name rules are applied in sigma_dut itself.
4091 */
4092 if (!strlen(policy->domain_name) && add_nft_rule(dut, policy))
4093 goto reject;
4094
4095 if (dut->dscp_policy_table) {
4096 policy_table = dut->dscp_policy_table;
4097 while (policy_table->next != NULL)
4098 policy_table = policy_table->next;
4099
4100 policy_table->next = policy;
4101 } else
4102 dut->dscp_policy_table = policy;
4103
4104success:
4105 status_list[num_status].status = DSCP_POLICY_SUCCESS;
4106 num_status++;
4107 policy = NULL;
4108 continue;
4109reject:
4110 status_list[num_status].status = DSCP_POLICY_REJECT;
4111 num_status++;
4112 free(policy);
4113 policy = NULL;
4114 }
4115
4116 free_dscp_policy_table(dut);
4117 wpa_ctrl_detach(ctrl);
4118 wpa_ctrl_close(ctrl);
4119
4120 pthread_exit(0);
4121 return NULL;
4122}
4123
4124
4125static void start_dscp_policy_mon_thread(struct sigma_dut *dut)
4126{
4127 /* Create event thread */
4128 pthread_create(&dut->dscp_policy_mon_thread, NULL, &mon_dscp_policies,
4129 (void *) dut);
4130}
4131
4132
4133void stop_dscp_policy_mon_thread(struct sigma_dut *dut)
4134{
4135 if (dut->dscp_policy_mon_thread) {
4136#ifdef ANDROID
4137 /* pthread_cancel not supported in Android */
4138 pthread_kill(dut->dscp_policy_mon_thread, SIGUSR1);
4139#else /* ANDROID */
4140 pthread_cancel(dut->dscp_policy_mon_thread);
4141#endif /* ANDROID */
4142 dut->dscp_policy_mon_thread = 0;
4143 }
4144}
4145
4146
Jouni Malinenf7222712019-06-13 01:50:21 +03004147static enum sigma_cmd_result cmd_sta_associate(struct sigma_dut *dut,
4148 struct sigma_conn *conn,
4149 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004150{
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304151#ifdef NL80211_SUPPORT
4152 const char *intf = get_param(cmd, "Interface");
4153#endif /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004154 const char *ssid = get_param(cmd, "ssid");
4155 const char *wps_param = get_param(cmd, "WPS");
4156 const char *bssid = get_param(cmd, "bssid");
Jouni Malinen46a19b62017-06-23 14:31:27 +03004157 const char *chan = get_param(cmd, "channel");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02004158 const char *network_mode = get_param(cmd, "network_mode");
Veerendranath Jakkama082e342020-05-16 00:19:21 +05304159 const char *ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004160 int wps = 0;
Jouni Malinen3c367e82017-06-23 17:01:47 +03004161 char buf[1000], extra[50];
Jouni Malinen134fe3c2019-06-12 04:16:49 +03004162 int e;
4163 enum sigma_cmd_result ret = SUCCESS_SEND_STATUS;
4164 struct wpa_ctrl *ctrl = NULL;
4165 int num_network_not_found = 0;
4166 int num_disconnected = 0;
4167 int tod = -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004168
4169 if (ssid == NULL)
4170 return -1;
4171
Jouni Malinen37d5c692019-08-19 16:56:55 +03004172 dut->server_cert_tod = 0;
4173
Jouni Malinen3c367e82017-06-23 17:01:47 +03004174 if (dut->rsne_override) {
Sunil Dutt44595082018-02-12 19:41:45 +05304175#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004176 if (get_driver_type(dut) == DRIVER_WCN) {
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304177 sta_config_params(dut, intf, STA_SET_RSNIE, 1);
Sunil Dutt44595082018-02-12 19:41:45 +05304178 dut->config_rsnie = 1;
4179 }
4180#endif /* NL80211_SUPPORT */
Jouni Malinen3c367e82017-06-23 17:01:47 +03004181 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
4182 dut->rsne_override);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004183 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinen3c367e82017-06-23 17:01:47 +03004184 send_resp(dut, conn, SIGMA_ERROR,
4185 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
4186 return 0;
4187 }
4188 }
4189
Jouni Malinen68143132017-09-02 02:34:08 +03004190 if (dut->sae_commit_override) {
4191 snprintf(buf, sizeof(buf), "SET sae_commit_override %s",
4192 dut->sae_commit_override);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004193 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinen68143132017-09-02 02:34:08 +03004194 send_resp(dut, conn, SIGMA_ERROR,
4195 "ErrorCode,Failed to set SAE commit override");
4196 return 0;
4197 }
4198 }
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304199#ifdef ANDROID
4200 if (dut->fils_hlp)
4201 process_fils_hlp(dut);
4202#endif /* ANDROID */
Jouni Malinen68143132017-09-02 02:34:08 +03004203
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004204 if (wps_param &&
4205 (strcmp(wps_param, "1") == 0 || strcasecmp(wps_param, "On") == 0))
4206 wps = 1;
4207
4208 if (wps) {
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02004209 if (dut->program == PROGRAM_60GHZ && network_mode &&
4210 strcasecmp(network_mode, "PBSS") == 0 &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004211 set_network(get_station_ifname(dut), dut->infra_network_id,
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02004212 "pbss", "1") < 0)
4213 return -2;
4214
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004215 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
4216 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,WPS "
4217 "parameters not yet set");
4218 return 0;
4219 }
4220 if (dut->wps_method == WFA_CS_WPS_PBC) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004221 if (wpa_command(get_station_ifname(dut), "WPS_PBC") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004222 return -2;
4223 } else {
4224 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
4225 dut->wps_pin);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004226 if (wpa_command(get_station_ifname(dut), buf) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004227 return -2;
4228 }
4229 } else {
vamsi krishna52e16f92017-08-29 12:37:34 +05304230 if (strcmp(ssid, dut->infra_ssid) == 0) {
4231 sigma_dut_print(dut, DUT_MSG_DEBUG,
4232 "sta_associate for the most recently added network");
4233 } else if (find_network(dut, ssid) < 0) {
4234 sigma_dut_print(dut, DUT_MSG_DEBUG,
4235 "sta_associate for a previously stored network profile");
4236 send_resp(dut, conn, SIGMA_ERROR,
4237 "ErrorCode,Profile not found");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004238 return 0;
4239 }
4240
4241 if (bssid &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004242 set_network(get_station_ifname(dut), dut->infra_network_id,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004243 "bssid", bssid) < 0) {
4244 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
4245 "Invalid bssid argument");
4246 return 0;
4247 }
4248
Veerendranath Jakkama082e342020-05-16 00:19:21 +05304249 if ((dut->program == PROGRAM_WPA3 &&
4250 dut->sta_associate_wait_connect) ||
4251 dut->program == PROGRAM_QM) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004252 ctrl = open_wpa_mon(get_station_ifname(dut));
Jouni Malinen134fe3c2019-06-12 04:16:49 +03004253 if (!ctrl)
4254 return ERROR_SEND_STATUS;
4255 }
4256
Jouni Malinen46a19b62017-06-23 14:31:27 +03004257 extra[0] = '\0';
4258 if (chan)
4259 snprintf(extra, sizeof(extra), " freq=%u",
Alexei Avshalom Lazar093569f2018-11-13 14:08:17 +02004260 channel_to_freq(dut, atoi(chan)));
Jouni Malinen46a19b62017-06-23 14:31:27 +03004261 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d%s",
4262 dut->infra_network_id, extra);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004263 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004264 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to select "
4265 "network id %d on %s",
4266 dut->infra_network_id,
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004267 get_station_ifname(dut));
Jouni Malinen134fe3c2019-06-12 04:16:49 +03004268 ret = ERROR_SEND_STATUS;
4269 goto done;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004270 }
4271 }
4272
Jouni Malinen134fe3c2019-06-12 04:16:49 +03004273 if (!ctrl)
4274 return SUCCESS_SEND_STATUS;
4275
4276 /* Wait for connection result to be able to store server certificate
4277 * hash for trust root override testing
4278 * (dev_exec_action,ServerCertTrust). */
4279
4280 for (e = 0; e < 20; e++) {
4281 const char *events[] = {
4282 "CTRL-EVENT-EAP-PEER-CERT",
4283 "CTRL-EVENT-EAP-TLS-CERT-ERROR",
4284 "CTRL-EVENT-DISCONNECTED",
4285 "CTRL-EVENT-CONNECTED",
4286 "CTRL-EVENT-NETWORK-NOT-FOUND",
4287 NULL
4288 };
4289 char buf[1024];
4290 int res;
4291
4292 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
4293 if (res < 0) {
Jouni Malinenf1f16642019-11-15 21:19:04 +02004294 send_resp(dut, conn, SIGMA_COMPLETE,
4295 "Result,Association did not complete");
Jouni Malinen134fe3c2019-06-12 04:16:49 +03004296 ret = STATUS_SENT_ERROR;
4297 break;
4298 }
4299 sigma_dut_print(dut, DUT_MSG_DEBUG, "Connection event: %s",
4300 buf);
4301
4302 if (strstr(buf, "CTRL-EVENT-EAP-PEER-CERT") &&
4303 strstr(buf, " depth=0")) {
4304 char *pos = strstr(buf, " hash=");
4305
4306 if (pos) {
4307 char *end;
4308
Jouni Malinen34b19cb2019-08-16 16:37:17 +03004309 if (strstr(buf, " tod=1"))
4310 tod = 1;
4311 else if (strstr(buf, " tod=2"))
4312 tod = 2;
4313 else
4314 tod = 0;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03004315 sigma_dut_print(dut, DUT_MSG_DEBUG,
4316 "Server certificate TOD policy: %d",
4317 tod);
Jouni Malinen37d5c692019-08-19 16:56:55 +03004318 dut->server_cert_tod = tod;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03004319
4320 pos += 6;
4321 end = strchr(pos, ' ');
4322 if (end)
4323 *end = '\0';
4324 strlcpy(dut->server_cert_hash, pos,
4325 sizeof(dut->server_cert_hash));
4326 sigma_dut_print(dut, DUT_MSG_DEBUG,
4327 "Server certificate hash: %s",
4328 dut->server_cert_hash);
4329 }
4330 }
4331
4332 if (strstr(buf, "CTRL-EVENT-EAP-TLS-CERT-ERROR")) {
4333 send_resp(dut, conn, SIGMA_COMPLETE,
4334 "Result,TLS server certificate validation failed");
4335 ret = STATUS_SENT_ERROR;
4336 break;
4337 }
4338
4339 if (strstr(buf, "CTRL-EVENT-NETWORK-NOT-FOUND")) {
4340 num_network_not_found++;
4341
4342 if (num_network_not_found > 2) {
4343 send_resp(dut, conn, SIGMA_COMPLETE,
4344 "Result,Network not found");
4345 ret = STATUS_SENT_ERROR;
4346 break;
4347 }
4348 }
4349
4350 if (strstr(buf, "CTRL-EVENT-DISCONNECTED")) {
4351 num_disconnected++;
4352
4353 if (num_disconnected > 2) {
4354 send_resp(dut, conn, SIGMA_COMPLETE,
4355 "Result,Connection failed");
4356 ret = STATUS_SENT_ERROR;
4357 break;
4358 }
4359 }
4360
4361 if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
4362 if (tod >= 0) {
4363 sigma_dut_print(dut, DUT_MSG_DEBUG,
4364 "Network profile TOD policy update: %d -> %d",
4365 dut->sta_tod_policy, tod);
4366 dut->sta_tod_policy = tod;
4367 }
Veerendranath Jakkama082e342020-05-16 00:19:21 +05304368 if (dut->program == PROGRAM_QM) {
4369 unsigned char iface_mac_addr[ETH_ALEN];
4370 char ipv6[100];
4371
4372 if (get_hwaddr(ifname, iface_mac_addr) < 0) {
4373 sigma_dut_print(dut, DUT_MSG_ERROR,
4374 "%s: get_hwaddr %s failed",
4375 __func__, ifname);
4376 ret = ERROR_SEND_STATUS;
4377 break;
4378 }
4379
4380 convert_mac_addr_to_ipv6_lladdr(iface_mac_addr,
4381 ipv6,
4382 sizeof(ipv6));
4383
4384 if (set_ipv6_addr(dut, ipv6, "64", ifname) !=
4385 0) {
4386 ret = ERROR_SEND_STATUS;
4387 break;
4388 }
Veerendranath Jakkam9ceb3b12021-09-10 03:18:17 +05304389 start_dscp_policy_mon_thread(dut);
Veerendranath Jakkama082e342020-05-16 00:19:21 +05304390 }
Jouni Malinen134fe3c2019-06-12 04:16:49 +03004391 break;
4392 }
4393 }
4394done:
4395 if (ctrl) {
4396 wpa_ctrl_detach(ctrl);
4397 wpa_ctrl_close(ctrl);
4398 }
4399 return ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004400}
4401
4402
4403static int run_hs20_osu(struct sigma_dut *dut, const char *params)
4404{
4405 char buf[500], cmd[200];
4406 int res;
4407
4408 /* Use hs20-osu-client file at the current dir, if found; otherwise use
4409 * default path */
4410 res = snprintf(cmd, sizeof(cmd),
4411 "%s -w \"%s\" -r hs20-osu-client.res %s%s -dddKt -f Logs/hs20-osu-client.txt",
4412 file_exists("./hs20-osu-client") ?
4413 "./hs20-osu-client" : "hs20-osu-client",
4414 sigma_wpas_ctrl,
4415 dut->summary_log ? "-s " : "",
4416 dut->summary_log ? dut->summary_log : "");
4417 if (res < 0 || res >= (int) sizeof(cmd))
4418 return -1;
4419
4420 res = snprintf(buf, sizeof(buf), "%s %s", cmd, params);
4421 if (res < 0 || res >= (int) sizeof(buf))
4422 return -1;
4423 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
4424
4425 if (system(buf) != 0) {
4426 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run: %s", buf);
4427 return -1;
4428 }
4429 sigma_dut_print(dut, DUT_MSG_DEBUG,
4430 "Completed hs20-osu-client operation");
4431
4432 return 0;
4433}
4434
4435
4436static int download_ppsmo(struct sigma_dut *dut,
4437 struct sigma_conn *conn,
4438 const char *intf,
4439 struct sigma_cmd *cmd)
4440{
4441 const char *name, *path, *val;
4442 char url[500], buf[600], fbuf[100];
4443 char *fqdn = NULL;
4444
4445 name = get_param(cmd, "FileName");
4446 path = get_param(cmd, "FilePath");
4447 if (name == NULL || path == NULL)
4448 return -1;
4449
4450 if (strcasecmp(path, "VendorSpecific") == 0) {
4451 snprintf(url, sizeof(url), "PPS/%s", name);
4452 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured PPS MO "
4453 "from the device (%s)", url);
4454 if (!file_exists(url)) {
4455 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
4456 "PPS MO file does not exist");
4457 return 0;
4458 }
4459 snprintf(buf, sizeof(buf), "cp %s pps-tnds.xml", url);
4460 if (system(buf) != 0) {
4461 send_resp(dut, conn, SIGMA_ERROR,
4462 "errorCode,Failed to copy PPS MO");
4463 return 0;
4464 }
4465 } else if (strncasecmp(path, "http:", 5) != 0 &&
4466 strncasecmp(path, "https:", 6) != 0) {
4467 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
4468 "Unsupported FilePath value");
4469 return 0;
4470 } else {
4471 snprintf(url, sizeof(url), "%s/%s", path, name);
4472 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading PPS MO from %s",
4473 url);
4474 snprintf(buf, sizeof(buf), "wget -T 10 -t 3 -O pps-tnds.xml '%s'", url);
4475 remove("pps-tnds.xml");
4476 if (system(buf) != 0) {
4477 send_resp(dut, conn, SIGMA_ERROR,
4478 "errorCode,Failed to download PPS MO");
4479 return 0;
4480 }
4481 }
4482
4483 if (run_hs20_osu(dut, "from_tnds pps-tnds.xml pps.xml") < 0) {
4484 send_resp(dut, conn, SIGMA_ERROR,
4485 "errorCode,Failed to parse downloaded PPSMO");
4486 return 0;
4487 }
4488 unlink("pps-tnds.xml");
4489
4490 val = get_param(cmd, "managementTreeURI");
4491 if (val) {
4492 const char *pos, *end;
4493 sigma_dut_print(dut, DUT_MSG_DEBUG, "managementTreeURI: %s",
4494 val);
4495 if (strncmp(val, "./Wi-Fi/", 8) != 0) {
4496 send_resp(dut, conn, SIGMA_ERROR,
4497 "errorCode,Invalid managementTreeURI prefix");
4498 return 0;
4499 }
4500 pos = val + 8;
4501 end = strchr(pos, '/');
4502 if (end == NULL ||
4503 strcmp(end, "/PerProviderSubscription") != 0) {
4504 send_resp(dut, conn, SIGMA_ERROR,
4505 "errorCode,Invalid managementTreeURI postfix");
4506 return 0;
4507 }
4508 if (end - pos >= (int) sizeof(fbuf)) {
4509 send_resp(dut, conn, SIGMA_ERROR,
4510 "errorCode,Too long FQDN in managementTreeURI");
4511 return 0;
4512 }
4513 memcpy(fbuf, pos, end - pos);
4514 fbuf[end - pos] = '\0';
4515 fqdn = fbuf;
4516 sigma_dut_print(dut, DUT_MSG_INFO,
4517 "FQDN from managementTreeURI: %s", fqdn);
4518 } else if (run_hs20_osu(dut, "get_fqdn pps.xml") == 0) {
4519 FILE *f = fopen("pps-fqdn", "r");
4520 if (f) {
4521 if (fgets(fbuf, sizeof(fbuf), f)) {
4522 fbuf[sizeof(fbuf) - 1] = '\0';
4523 fqdn = fbuf;
4524 sigma_dut_print(dut, DUT_MSG_DEBUG,
4525 "Use FQDN %s", fqdn);
4526 }
4527 fclose(f);
4528 }
4529 }
4530
4531 if (fqdn == NULL) {
4532 send_resp(dut, conn, SIGMA_ERROR,
4533 "errorCode,No FQDN specified");
4534 return 0;
4535 }
4536
4537 mkdir("SP", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
4538 snprintf(buf, sizeof(buf), "SP/%s", fqdn);
4539 mkdir(buf, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
4540
4541 snprintf(buf, sizeof(buf), "SP/%s/pps.xml", fqdn);
4542 if (rename("pps.xml", buf) < 0) {
4543 send_resp(dut, conn, SIGMA_ERROR,
4544 "errorCode,Could not move PPS MO");
4545 return 0;
4546 }
4547
4548 if (strcasecmp(path, "VendorSpecific") == 0) {
4549 snprintf(buf, sizeof(buf), "cp Certs/ca.pem SP/%s/ca.pem",
4550 fqdn);
4551 if (system(buf)) {
4552 send_resp(dut, conn, SIGMA_ERROR,
4553 "errorCode,Failed to copy OSU CA cert");
4554 return 0;
4555 }
4556
4557 snprintf(buf, sizeof(buf),
4558 "cp Certs/aaa-ca.pem SP/%s/aaa-ca.pem",
4559 fqdn);
4560 if (system(buf)) {
4561 send_resp(dut, conn, SIGMA_ERROR,
4562 "errorCode,Failed to copy AAA CA cert");
4563 return 0;
4564 }
4565 } else {
4566 snprintf(buf, sizeof(buf),
4567 "dl_osu_ca SP/%s/pps.xml SP/%s/ca.pem",
4568 fqdn, fqdn);
4569 if (run_hs20_osu(dut, buf) < 0) {
4570 send_resp(dut, conn, SIGMA_ERROR,
4571 "errorCode,Failed to download OSU CA cert");
4572 return 0;
4573 }
4574
4575 snprintf(buf, sizeof(buf),
4576 "dl_aaa_ca SP/%s/pps.xml SP/%s/aaa-ca.pem",
4577 fqdn, fqdn);
4578 if (run_hs20_osu(dut, buf) < 0) {
4579 sigma_dut_print(dut, DUT_MSG_INFO,
4580 "Failed to download AAA CA cert");
4581 }
4582 }
4583
4584 if (file_exists("next-client-cert.pem")) {
4585 snprintf(buf, sizeof(buf), "SP/%s/client-cert.pem", fqdn);
4586 if (rename("next-client-cert.pem", buf) < 0) {
4587 send_resp(dut, conn, SIGMA_ERROR,
4588 "errorCode,Could not move client certificate");
4589 return 0;
4590 }
4591 }
4592
4593 if (file_exists("next-client-key.pem")) {
4594 snprintf(buf, sizeof(buf), "SP/%s/client-key.pem", fqdn);
4595 if (rename("next-client-key.pem", buf) < 0) {
4596 send_resp(dut, conn, SIGMA_ERROR,
4597 "errorCode,Could not move client key");
4598 return 0;
4599 }
4600 }
4601
4602 snprintf(buf, sizeof(buf), "set_pps SP/%s/pps.xml", fqdn);
4603 if (run_hs20_osu(dut, buf) < 0) {
4604 send_resp(dut, conn, SIGMA_ERROR,
4605 "errorCode,Failed to configure credential from "
4606 "PPSMO");
4607 return 0;
4608 }
4609
4610 return 1;
4611}
4612
4613
4614static int download_cert(struct sigma_dut *dut,
4615 struct sigma_conn *conn,
4616 const char *intf,
4617 struct sigma_cmd *cmd)
4618{
4619 const char *name, *path;
4620 char url[500], buf[600];
4621
4622 name = get_param(cmd, "FileName");
4623 path = get_param(cmd, "FilePath");
4624 if (name == NULL || path == NULL)
4625 return -1;
4626
4627 if (strcasecmp(path, "VendorSpecific") == 0) {
4628 snprintf(url, sizeof(url), "Certs/%s-cert.pem", name);
4629 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
4630 "certificate from the device (%s)", url);
4631 if (!file_exists(url)) {
4632 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
4633 "certificate file does not exist");
4634 return 0;
4635 }
4636 snprintf(buf, sizeof(buf), "cp %s next-client-cert.pem", url);
4637 if (system(buf) != 0) {
4638 send_resp(dut, conn, SIGMA_ERROR,
4639 "errorCode,Failed to copy client "
4640 "certificate");
4641 return 0;
4642 }
4643
4644 snprintf(url, sizeof(url), "Certs/%s-key.pem", name);
4645 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
4646 "private key from the device (%s)", url);
4647 if (!file_exists(url)) {
4648 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
4649 "private key file does not exist");
4650 return 0;
4651 }
4652 snprintf(buf, sizeof(buf), "cp %s next-client-key.pem", url);
4653 if (system(buf) != 0) {
4654 send_resp(dut, conn, SIGMA_ERROR,
4655 "errorCode,Failed to copy client key");
4656 return 0;
4657 }
4658 } else if (strncasecmp(path, "http:", 5) != 0 &&
4659 strncasecmp(path, "https:", 6) != 0) {
4660 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
4661 "Unsupported FilePath value");
4662 return 0;
4663 } else {
4664 snprintf(url, sizeof(url), "%s/%s.pem", path, name);
4665 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading client "
4666 "certificate/key from %s", url);
4667 snprintf(buf, sizeof(buf),
4668 "wget -T 10 -t 3 -O next-client-cert.pem '%s'", url);
4669 if (system(buf) != 0) {
4670 send_resp(dut, conn, SIGMA_ERROR,
4671 "errorCode,Failed to download client "
4672 "certificate");
4673 return 0;
4674 }
4675
4676 if (system("cp next-client-cert.pem next-client-key.pem") != 0)
4677 {
4678 send_resp(dut, conn, SIGMA_ERROR,
4679 "errorCode,Failed to copy client key");
4680 return 0;
4681 }
4682 }
4683
4684 return 1;
4685}
4686
4687
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02004688static int cmd_sta_preset_testparameters_60ghz(struct sigma_dut *dut,
4689 struct sigma_conn *conn,
4690 struct sigma_cmd *cmd)
4691{
4692 const char *val;
4693 const char *intf = get_param(cmd, "interface");
4694
4695 if (!intf)
4696 return -1;
4697
4698 val = get_param(cmd, "WscIEFragment");
4699 if (val && strcasecmp(val, "enable") == 0) {
4700 sigma_dut_print(dut, DUT_MSG_DEBUG,
4701 "Enable WSC IE fragmentation");
4702
4703 dut->wsc_fragment = 1;
4704 /* set long attributes to force fragmentation */
4705 if (wpa_command(intf, "SET device_name "
4706 WPS_LONG_DEVICE_NAME) < 0)
4707 return -2;
4708 if (wpa_command(intf, "SET manufacturer "
4709 WPS_LONG_MANUFACTURER) < 0)
4710 return -2;
4711 if (wpa_command(intf, "SET model_name "
4712 WPS_LONG_MODEL_NAME) < 0)
4713 return -2;
4714 if (wpa_command(intf, "SET model_number "
4715 WPS_LONG_MODEL_NUMBER) < 0)
4716 return -2;
4717 if (wpa_command(intf, "SET serial_number "
4718 WPS_LONG_SERIAL_NUMBER) < 0)
4719 return -2;
4720 }
4721
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02004722 val = get_param(cmd, "RSN_IE");
4723 if (val) {
4724 if (strcasecmp(val, "disable") == 0)
4725 dut->force_rsn_ie = FORCE_RSN_IE_REMOVE;
4726 else if (strcasecmp(val, "enable") == 0)
4727 dut->force_rsn_ie = FORCE_RSN_IE_ADD;
4728 }
4729
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02004730 val = get_param(cmd, "WpsVersion");
4731 if (val)
4732 dut->wps_forced_version = get_wps_forced_version(dut, val);
4733
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02004734 val = get_param(cmd, "WscEAPFragment");
4735 if (val && strcasecmp(val, "enable") == 0)
4736 dut->eap_fragment = 1;
4737
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02004738 return 1;
4739}
4740
4741
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004742static int cmd_sta_preset_testparameters_hs2_r2(struct sigma_dut *dut,
4743 struct sigma_conn *conn,
4744 const char *intf,
4745 struct sigma_cmd *cmd)
4746{
4747 const char *val;
4748
4749 val = get_param(cmd, "FileType");
4750 if (val && strcasecmp(val, "PPSMO") == 0)
4751 return download_ppsmo(dut, conn, intf, cmd);
4752 if (val && strcasecmp(val, "CERT") == 0)
4753 return download_cert(dut, conn, intf, cmd);
4754 if (val) {
4755 send_resp(dut, conn, SIGMA_ERROR,
4756 "ErrorCode,Unsupported FileType");
4757 return 0;
4758 }
4759
4760 return 1;
4761}
4762
4763
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304764static int cmd_sta_preset_testparameters_oce(struct sigma_dut *dut,
4765 struct sigma_conn *conn,
4766 const char *intf,
4767 struct sigma_cmd *cmd)
4768{
4769 const char *val;
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304770 char buf[1000];
4771 char text[20];
4772 unsigned char addr[ETH_ALEN];
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304773
4774 val = get_param(cmd, "OCESupport");
4775 if (val && strcasecmp(val, "Disable") == 0) {
4776 if (wpa_command(intf, "SET oce 0") < 0) {
4777 send_resp(dut, conn, SIGMA_ERROR,
4778 "ErrorCode,Failed to disable OCE");
4779 return 0;
4780 }
4781 } else if (val && strcasecmp(val, "Enable") == 0) {
4782 if (wpa_command(intf, "SET oce 1") < 0) {
4783 send_resp(dut, conn, SIGMA_ERROR,
4784 "ErrorCode,Failed to enable OCE");
4785 return 0;
4786 }
4787 }
4788
vamsi krishnaa2799492017-12-05 14:28:01 +05304789 val = get_param(cmd, "FILScap");
4790 if (val && (atoi(val) == 1)) {
4791 if (wpa_command(intf, "SET disable_fils 0") < 0) {
4792 send_resp(dut, conn, SIGMA_ERROR,
4793 "ErrorCode,Failed to enable FILS");
4794 return 0;
4795 }
4796 } else if (val && (atoi(val) == 0)) {
4797 if (wpa_command(intf, "SET disable_fils 1") < 0) {
4798 send_resp(dut, conn, SIGMA_ERROR,
4799 "ErrorCode,Failed to disable FILS");
4800 return 0;
4801 }
4802 }
4803
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304804 val = get_param(cmd, "FILSHLP");
4805 if (val && strcasecmp(val, "Enable") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004806 if (get_wpa_status(get_station_ifname(dut), "address", text,
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304807 sizeof(text)) < 0)
4808 return -2;
4809 hwaddr_aton(text, addr);
4810 snprintf(buf, sizeof(buf),
4811 "FILS_HLP_REQ_ADD ff:ff:ff:ff:ff:ff "
4812 "080045100140000040004011399e00000000ffffffff00440043"
4813 "012cb30001010600fd4f46410000000000000000000000000000"
4814 "000000000000"
4815 "%02x%02x%02x%02x%02x%02x"
4816 "0000000000000000000000000000000000000000000000000000"
4817 "0000000000000000000000000000000000000000000000000000"
4818 "0000000000000000000000000000000000000000000000000000"
4819 "0000000000000000000000000000000000000000000000000000"
4820 "0000000000000000000000000000000000000000000000000000"
4821 "0000000000000000000000000000000000000000000000000000"
4822 "0000000000000000000000000000000000000000000000000000"
4823 "0000000000000000000000000000000000000000638253633501"
4824 "013d0701000af549d29b390205dc3c12616e64726f69642d6468"
4825 "63702d382e302e30370a0103060f1a1c333a3b2b5000ff00",
4826 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
4827 if (wpa_command(intf, buf)) {
4828 send_resp(dut, conn, SIGMA_ERROR,
4829 "ErrorCode,Failed to add HLP");
4830 return 0;
4831 }
4832 dut->fils_hlp = 1;
4833 }
4834
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304835 return 1;
4836}
4837
4838
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004839static void ath_sta_set_noack(struct sigma_dut *dut, const char *intf,
4840 const char *val)
4841{
4842 int counter = 0;
4843 char token[50];
4844 char *result;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304845 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004846
Peng Xub8fc5cc2017-05-10 17:27:28 -07004847 strlcpy(token, val, sizeof(token));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004848 token[sizeof(token) - 1] = '\0';
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304849 result = strtok_r(token, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004850 while (result) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004851 if (strcmp(result, "disable") == 0)
4852 run_iwpriv(dut, intf, "noackpolicy %d 1 0", counter);
4853 else
4854 run_iwpriv(dut, intf, "noackpolicy %d 1 1", counter);
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304855 result = strtok_r(NULL, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004856 counter++;
4857 }
4858}
4859
4860
4861static void ath_sta_set_rts(struct sigma_dut *dut, const char *intf,
4862 const char *val)
4863{
4864 char buf[100];
4865
4866 snprintf(buf, sizeof(buf), "iwconfig %s rts %s", intf, val);
4867 if (system(buf) != 0) {
4868 sigma_dut_print(dut, DUT_MSG_ERROR, "iwconfig RTS failed");
4869 }
4870}
4871
4872
4873static void ath_sta_set_wmm(struct sigma_dut *dut, const char *intf,
4874 const char *val)
4875{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004876 if (strcasecmp(val, "off") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004877 run_iwpriv(dut, intf, "wmm 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004878 }
4879}
4880
4881
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08004882static int wcn_sta_set_wmm(struct sigma_dut *dut, const char *intf,
4883 const char *val)
4884{
4885#ifdef NL80211_SUPPORT
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08004886 int wmmenable = 1;
4887
4888 if (val &&
4889 (strcasecmp(val, "off") == 0 || strcmp(val, "0") == 0))
4890 wmmenable = 0;
4891
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05304892 return wcn_wifi_test_config_set_u8(
4893 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WMM_ENABLE,
4894 wmmenable);
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08004895#else /* NL80211_SUPPORT */
4896 sigma_dut_print(dut, DUT_MSG_ERROR,
4897 "WMM cannot be changed without NL80211_SUPPORT defined");
4898 return -1;
4899#endif /* NL80211_SUPPORT */
4900}
4901
4902
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004903static void ath_sta_set_sgi(struct sigma_dut *dut, const char *intf,
4904 const char *val)
4905{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004906 int sgi20;
4907
4908 sgi20 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
4909
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004910 run_iwpriv(dut, intf, "shortgi %d", sgi20);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004911}
4912
4913
4914static void ath_sta_set_11nrates(struct sigma_dut *dut, const char *intf,
4915 const char *val)
4916{
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05304917 int rate_code, v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004918
4919 /* Disable Tx Beam forming when using a fixed rate */
4920 ath_disable_txbf(dut, intf);
4921
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05304922 v = atoi(val);
4923 if (v < 0 || v > 32) {
4924 sigma_dut_print(dut, DUT_MSG_ERROR,
4925 "Invalid Fixed MCS rate: %d", v);
4926 return;
4927 }
4928 rate_code = 0x80 + v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004929
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004930 run_iwpriv(dut, intf, "set11NRates 0x%x", rate_code);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004931
4932 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004933 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004934}
4935
4936
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08004937static void iwpriv_sta_set_amsdu(struct sigma_dut *dut, const char *intf,
4938 const char *val)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004939{
4940 char buf[60];
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304941 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004942
4943 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)
4944 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 2", intf);
4945 else
4946 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf);
4947
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304948 ret = system(buf);
4949#ifdef NL80211_SUPPORT
4950 if (ret) {
4951 int value = (strcasecmp(val, "Enable") == 0) ? 2 : 1;
4952
4953 ret = sta_config_params(dut, intf, STA_SET_TX_MSDU, value);
4954 ret |= sta_config_params(dut, intf, STA_SET_RX_MSDU, value);
4955 }
4956#endif /* NL80211_SUPPORT */
4957 if (ret)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004958 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv amsdu failed");
4959}
4960
4961
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004962static int iwpriv_sta_set_ampdu(struct sigma_dut *dut, const char *intf,
4963 int ampdu)
4964{
4965 char buf[60];
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08004966 int maxaggregation = 63;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004967
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08004968 if (ampdu)
4969 ampdu = maxaggregation;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004970 snprintf(buf, sizeof(buf), "iwpriv %s ampdu %d", intf, ampdu);
4971 if (system(buf) != 0) {
4972 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv ampdu failed");
4973 return -1;
4974 }
4975
4976 return 0;
4977}
4978
4979
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004980static void ath_sta_set_stbc(struct sigma_dut *dut, const char *intf,
4981 const char *val)
4982{
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004983 run_iwpriv(dut, intf, "tx_stbc %s", val);
4984 run_iwpriv(dut, intf, "rx_stbc %s", val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004985}
4986
4987
4988static int wcn_sta_set_cts_width(struct sigma_dut *dut, const char *intf,
4989 const char *val)
4990{
4991 char buf[60];
4992
Peng Xucc317ed2017-05-18 16:44:37 -07004993 if (strcmp(val, "160") == 0) {
4994 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 5", intf);
4995 } else if (strcmp(val, "80") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004996 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
4997 } else if (strcmp(val, "40") == 0) {
4998 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 2", intf);
4999 } else if (strcmp(val, "20") == 0) {
5000 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 1", intf);
5001 } else if (strcasecmp(val, "Auto") == 0) {
5002 buf[0] = '\0';
5003 } else {
5004 sigma_dut_print(dut, DUT_MSG_ERROR,
5005 "WIDTH/CTS_WIDTH value not supported");
5006 return -1;
5007 }
5008
5009 if (buf[0] != '\0' && system(buf) != 0) {
5010 sigma_dut_print(dut, DUT_MSG_ERROR,
5011 "Failed to set WIDTH/CTS_WIDTH");
5012 return -1;
5013 }
5014
5015 return 0;
5016}
5017
5018
5019int ath_set_width(struct sigma_dut *dut, struct sigma_conn *conn,
5020 const char *intf, const char *val)
5021{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005022 if (strcasecmp(val, "Auto") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005023 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005024 dut->chwidth = 0;
5025 } else if (strcasecmp(val, "20") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005026 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005027 dut->chwidth = 0;
5028 } else if (strcasecmp(val, "40") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005029 run_iwpriv(dut, intf, "chwidth 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005030 dut->chwidth = 1;
5031 } else if (strcasecmp(val, "80") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005032 run_iwpriv(dut, intf, "chwidth 2");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005033 dut->chwidth = 2;
5034 } else if (strcasecmp(val, "160") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005035 run_iwpriv(dut, intf, "chwidth 3");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005036 dut->chwidth = 3;
5037 } else {
5038 send_resp(dut, conn, SIGMA_ERROR,
5039 "ErrorCode,WIDTH not supported");
5040 return -1;
5041 }
5042
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005043 return 0;
5044}
5045
5046
5047static int wcn_sta_set_sp_stream(struct sigma_dut *dut, const char *intf,
5048 const char *val)
5049{
5050 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07005051 int sta_nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005052
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08005053 if (strcmp(val, "1SS") == 0 || strcmp(val, "1") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005054 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07005055 sta_nss = 1;
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08005056 } else if (strcmp(val, "2SS") == 0 || strcmp(val, "2") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005057 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07005058 sta_nss = 2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005059 } else {
5060 sigma_dut_print(dut, DUT_MSG_ERROR,
5061 "SP_STREAM value not supported");
5062 return -1;
5063 }
5064
5065 if (system(buf) != 0) {
5066 sigma_dut_print(dut, DUT_MSG_ERROR,
5067 "Failed to set SP_STREAM");
5068 return -1;
5069 }
5070
Arif Hussainac6c5112018-05-25 17:34:00 -07005071 dut->sta_nss = sta_nss;
5072
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005073 return 0;
5074}
5075
5076
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05305077static void wcn_sta_set_stbc(struct sigma_dut *dut, const char *intf,
5078 const char *val)
5079{
5080 char buf[60];
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05305081 int ret;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05305082
5083 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc %s", intf, val);
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05305084 ret = system(buf);
5085#ifdef NL80211_SUPPORT
5086 if (ret)
5087 ret = sta_config_params(dut, intf, STA_SET_TX_STBC,
5088 strcmp(val, "0") == 0 ? 0 : 1);
5089#endif /* NL80211_SUPPORT */
5090 if (ret)
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05305091 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv tx_stbc failed");
5092
5093 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc %s", intf, val);
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05305094 ret = system(buf);
5095#ifdef NL80211_SUPPORT
5096 if (ret)
5097 ret = sta_config_params(dut, intf, STA_SET_RX_STBC,
5098 strcmp(val, "0") == 0 ? 0 : 1);
5099#endif /* NL80211_SUPPORT */
5100 if (ret)
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05305101 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv rx_stbc failed");
5102}
5103
5104
Ashwini Patil68d02cd2017-01-10 15:39:16 +05305105static int mbo_set_cellular_data_capa(struct sigma_dut *dut,
5106 struct sigma_conn *conn,
5107 const char *intf, int capa)
5108{
5109 char buf[32];
5110
5111 if (capa > 0 && capa < 4) {
5112 snprintf(buf, sizeof(buf), "SET mbo_cell_capa %d", capa);
5113 if (wpa_command(intf, buf) < 0) {
5114 send_resp(dut, conn, SIGMA_ERROR,
5115 "ErrorCode, Failed to set cellular data capability");
5116 return 0;
5117 }
5118 return 1;
5119 }
5120
5121 sigma_dut_print(dut, DUT_MSG_ERROR,
5122 "Invalid Cellular data capability: %d", capa);
5123 send_resp(dut, conn, SIGMA_INVALID,
5124 "ErrorCode,Invalid cellular data capability");
5125 return 0;
5126}
5127
5128
Ashwini Patil9183fdb2017-04-13 16:58:25 +05305129static int mbo_set_roaming(struct sigma_dut *dut, struct sigma_conn *conn,
5130 const char *intf, const char *val)
5131{
5132 if (strcasecmp(val, "Disable") == 0) {
5133 if (wpa_command(intf, "SET roaming 0") < 0) {
5134 send_resp(dut, conn, SIGMA_ERROR,
5135 "ErrorCode,Failed to disable roaming");
5136 return 0;
5137 }
5138 return 1;
5139 }
5140
5141 if (strcasecmp(val, "Enable") == 0) {
5142 if (wpa_command(intf, "SET roaming 1") < 0) {
5143 send_resp(dut, conn, SIGMA_ERROR,
5144 "ErrorCode,Failed to enable roaming");
5145 return 0;
5146 }
5147 return 1;
5148 }
5149
5150 sigma_dut_print(dut, DUT_MSG_ERROR,
5151 "Invalid value provided for roaming: %s", val);
5152 send_resp(dut, conn, SIGMA_INVALID,
5153 "ErrorCode,Unknown value provided for Roaming");
5154 return 0;
5155}
5156
5157
Ashwini Patila75de5a2017-04-13 16:35:05 +05305158static int mbo_set_assoc_disallow(struct sigma_dut *dut,
5159 struct sigma_conn *conn,
5160 const char *intf, const char *val)
5161{
5162 if (strcasecmp(val, "Disable") == 0) {
5163 if (wpa_command(intf, "SET ignore_assoc_disallow 1") < 0) {
5164 send_resp(dut, conn, SIGMA_ERROR,
5165 "ErrorCode,Failed to disable Assoc_disallow");
5166 return 0;
5167 }
5168 return 1;
5169 }
5170
5171 if (strcasecmp(val, "Enable") == 0) {
5172 if (wpa_command(intf, "SET ignore_assoc_disallow 0") < 0) {
5173 send_resp(dut, conn, SIGMA_ERROR,
5174 "ErrorCode,Failed to enable Assoc_disallow");
5175 return 0;
5176 }
5177 return 1;
5178 }
5179
5180 sigma_dut_print(dut, DUT_MSG_ERROR,
5181 "Invalid value provided for Assoc_disallow: %s", val);
5182 send_resp(dut, conn, SIGMA_INVALID,
5183 "ErrorCode,Unknown value provided for Assoc_disallow");
5184 return 0;
5185}
5186
5187
Ashwini Patilc63161e2017-04-13 16:30:23 +05305188static int mbo_set_bss_trans_req(struct sigma_dut *dut, struct sigma_conn *conn,
5189 const char *intf, const char *val)
5190{
5191 if (strcasecmp(val, "Reject") == 0) {
5192 if (wpa_command(intf, "SET reject_btm_req_reason 1") < 0) {
5193 send_resp(dut, conn, SIGMA_ERROR,
5194 "ErrorCode,Failed to Reject BTM Request");
5195 return 0;
5196 }
5197 return 1;
5198 }
5199
5200 if (strcasecmp(val, "Accept") == 0) {
5201 if (wpa_command(intf, "SET reject_btm_req_reason 0") < 0) {
5202 send_resp(dut, conn, SIGMA_ERROR,
5203 "ErrorCode,Failed to Accept BTM Request");
5204 return 0;
5205 }
5206 return 1;
5207 }
5208
5209 sigma_dut_print(dut, DUT_MSG_ERROR,
5210 "Invalid value provided for BSS_Transition: %s", val);
5211 send_resp(dut, conn, SIGMA_INVALID,
5212 "ErrorCode,Unknown value provided for BSS_Transition");
5213 return 0;
5214}
5215
5216
Ashwini Patil00402582017-04-13 12:29:39 +05305217static int mbo_set_non_pref_ch_list(struct sigma_dut *dut,
5218 struct sigma_conn *conn,
5219 const char *intf,
5220 struct sigma_cmd *cmd)
5221{
5222 const char *ch, *pref, *op_class, *reason;
5223 char buf[120];
5224 int len, ret;
5225
5226 pref = get_param(cmd, "Ch_Pref");
5227 if (!pref)
5228 return 1;
5229
5230 if (strcasecmp(pref, "clear") == 0) {
5231 free(dut->non_pref_ch_list);
5232 dut->non_pref_ch_list = NULL;
5233 } else {
5234 op_class = get_param(cmd, "Ch_Op_Class");
5235 if (!op_class) {
5236 send_resp(dut, conn, SIGMA_INVALID,
5237 "ErrorCode,Ch_Op_Class not provided");
5238 return 0;
5239 }
5240
5241 ch = get_param(cmd, "Ch_Pref_Num");
5242 if (!ch) {
5243 send_resp(dut, conn, SIGMA_INVALID,
5244 "ErrorCode,Ch_Pref_Num not provided");
5245 return 0;
5246 }
5247
5248 reason = get_param(cmd, "Ch_Reason_Code");
5249 if (!reason) {
5250 send_resp(dut, conn, SIGMA_INVALID,
5251 "ErrorCode,Ch_Reason_Code not provided");
5252 return 0;
5253 }
5254
5255 if (!dut->non_pref_ch_list) {
5256 dut->non_pref_ch_list =
5257 calloc(1, NON_PREF_CH_LIST_SIZE);
5258 if (!dut->non_pref_ch_list) {
5259 send_resp(dut, conn, SIGMA_ERROR,
5260 "ErrorCode,Failed to allocate memory for non_pref_ch_list");
5261 return 0;
5262 }
5263 }
5264 len = strlen(dut->non_pref_ch_list);
5265 ret = snprintf(dut->non_pref_ch_list + len,
5266 NON_PREF_CH_LIST_SIZE - len,
5267 " %s:%s:%s:%s", op_class, ch, pref, reason);
5268 if (ret > 0 && ret < NON_PREF_CH_LIST_SIZE - len) {
5269 sigma_dut_print(dut, DUT_MSG_DEBUG, "non_pref_list: %s",
5270 dut->non_pref_ch_list);
5271 } else {
5272 sigma_dut_print(dut, DUT_MSG_ERROR,
5273 "snprintf failed for non_pref_list, ret = %d",
5274 ret);
5275 send_resp(dut, conn, SIGMA_ERROR,
5276 "ErrorCode,snprintf failed");
5277 free(dut->non_pref_ch_list);
5278 dut->non_pref_ch_list = NULL;
5279 return 0;
5280 }
5281 }
5282
5283 ret = snprintf(buf, sizeof(buf), "SET non_pref_chan%s",
5284 dut->non_pref_ch_list ? dut->non_pref_ch_list : " ");
5285 if (ret < 0 || ret >= (int) sizeof(buf)) {
5286 sigma_dut_print(dut, DUT_MSG_DEBUG,
5287 "snprintf failed for set non_pref_chan, ret: %d",
5288 ret);
5289 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,snprint failed");
5290 return 0;
5291 }
5292
5293 if (wpa_command(intf, buf) < 0) {
5294 send_resp(dut, conn, SIGMA_ERROR,
5295 "ErrorCode,Failed to set non-preferred channel list");
5296 return 0;
5297 }
5298
5299 return 1;
5300}
5301
5302
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08005303#ifdef NL80211_SUPPORT
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08005304
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08005305static int sta_set_he_htc_supp(struct sigma_dut *dut, const char *intf,
5306 uint8_t cfg)
5307{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05305308 return wcn_wifi_test_config_set_u8(
5309 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_HTC_HE_SUPP,
5310 cfg);
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08005311}
5312
5313
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08005314static int sta_set_he_fragmentation(struct sigma_dut *dut, const char *intf,
5315 enum he_fragmentation_val frag)
5316{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05305317 return wcn_wifi_test_config_set_u8(
5318 dut, intf,
5319 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_FRAGMENTATION, frag);
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08005320}
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08005321
5322
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -08005323int wcn_set_he_ltf(struct sigma_dut *dut, const char *intf,
5324 enum qca_wlan_he_ltf_cfg ltf)
Subhani Shaik8e7a3052018-04-24 14:03:00 -07005325{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05305326 return wcn_wifi_test_config_set_u8(
5327 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_LTF, ltf);
Subhani Shaik8e7a3052018-04-24 14:03:00 -07005328}
5329
5330
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08005331static int nlvendor_sta_set_noack(struct sigma_dut *dut, const char *intf,
5332 int noack, enum qca_wlan_ac_type ac)
5333{
5334 struct nl_msg *msg;
5335 int ret = 0;
5336 struct nlattr *params;
5337 int ifindex;
5338
5339 ifindex = if_nametoindex(intf);
5340 if (ifindex == 0) {
5341 sigma_dut_print(dut, DUT_MSG_ERROR,
5342 "%s: Index for interface %s failed",
5343 __func__, intf);
5344 return -1;
5345 }
5346
5347 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5348 NL80211_CMD_VENDOR)) ||
5349 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5350 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5351 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5352 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5353 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5354 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_NO_ACK,
5355 noack) ||
5356 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_NO_ACK_AC,
5357 ac)) {
5358 sigma_dut_print(dut, DUT_MSG_ERROR,
5359 "%s: err in adding vendor_cmd and vendor_data",
5360 __func__);
5361 nlmsg_free(msg);
5362 return -1;
5363 }
5364 nla_nest_end(msg, params);
5365
5366 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5367 if (ret) {
5368 sigma_dut_print(dut, DUT_MSG_ERROR,
5369 "%s: err in send_and_recv_msgs, ret=%d",
5370 __func__, ret);
5371 }
5372 return ret;
5373}
5374
5375
5376static void wcn_sta_set_noack(struct sigma_dut *dut, const char *intf,
5377 const char *val)
5378{
5379 int noack, ret;
5380 char token[100];
5381 char *result;
5382 char *saveptr;
5383 enum qca_wlan_ac_type ac = QCA_WLAN_AC_BE;
5384
5385 strlcpy(token, val, sizeof(token));
5386 token[sizeof(token) - 1] = '\0';
5387 result = strtok_r(token, ":", &saveptr);
5388 while (result) {
5389 noack = strcasecmp(result, "Disable") != 0;
5390 ret = nlvendor_sta_set_noack(dut, intf, noack, ac);
5391 if (ret) {
5392 sigma_dut_print(dut, DUT_MSG_ERROR,
5393 "nlvendor_sta_set_noack failed for ac:%d, ret:%d",
5394 ac, ret);
5395 }
5396 result = strtok_r(NULL, ":", &saveptr);
5397 ac++;
5398 }
5399}
5400
Vinita S. Maloo7462e812020-05-22 15:16:04 +05305401
5402static int nlvendor_sta_set_phymode(struct sigma_dut *dut, const char *intf,
5403 enum qca_wlan_vendor_phy_mode val)
5404{
5405 struct nl_msg *msg;
5406 struct nlattr *params;
5407 int ifindex, ret;
5408
5409 ifindex = if_nametoindex(intf);
5410 if (ifindex == 0) {
5411 sigma_dut_print(dut, DUT_MSG_ERROR,
5412 "%s: Index for interface %s not found",
5413 __func__, intf);
5414 return -1;
5415 }
5416
5417 msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5418 NL80211_CMD_VENDOR);
5419 if (!msg) {
5420 sigma_dut_print(dut, DUT_MSG_ERROR,
5421 "%s: err in adding vendor_cmd", __func__);
5422 return -1;
5423 }
5424
5425 if (nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5426 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5427 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION)) {
5428 sigma_dut_print(dut, DUT_MSG_ERROR,
5429 "%s: err in adding vendor_attr", __func__);
5430 nlmsg_free(msg);
5431 return -1;
5432 }
5433
5434 params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
5435 if (!params || nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_PHY_MODE,
5436 val)) {
5437 sigma_dut_print(dut, DUT_MSG_ERROR,
5438 "%s: err in adding vendor_data", __func__);
5439 nlmsg_free(msg);
5440 return -1;
5441 }
5442
5443 nla_nest_end(msg, params);
5444 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5445 if (ret) {
5446 sigma_dut_print(dut, DUT_MSG_ERROR,
5447 "%s: err in send_and_recv_msgs, ret=%d (%s)",
5448 __func__, ret, strerror(-ret));
5449 return ret;
5450 }
5451
5452 return 0;
5453}
5454
5455
5456static enum qca_wlan_vendor_phy_mode get_qca_vendor_phymode(const char *val)
5457{
5458 if (strcmp(val, "11a") == 0) {
5459 /* IEEE80211_MODE_11A */
5460 return QCA_WLAN_VENDOR_PHY_MODE_11A;
5461 }
5462
5463 if (strcmp(val, "11g") == 0) {
5464 /* IEEE80211_MODE_11G */
5465 return QCA_WLAN_VENDOR_PHY_MODE_11G;
5466 }
5467
5468 if (strcmp(val, "11b") == 0) {
5469 /* IEEE80211_MODE_11B */
5470 return QCA_WLAN_VENDOR_PHY_MODE_11B;
5471 }
5472
5473 if (strcmp(val, "11n") == 0 ||
5474 strcmp(val, "11nl") == 0 ||
5475 strcmp(val, "11nl(nabg)") == 0) {
5476 /* IEEE80211_MODE_11AGN */
5477 return QCA_WLAN_VENDOR_PHY_MODE_11AGN;
5478 }
5479
5480 if (strcmp(val, "11ng") == 0) {
5481 /* IEEE80211_MODE_11NG_HT40 */
5482 return QCA_WLAN_VENDOR_PHY_MODE_11NG_HT40;
5483 }
5484
5485 if (strcmp(val, "AC") == 0 ||
5486 strcasecmp(val, "11AC") == 0) {
5487 /* IEEE80211_MODE_11AC_VHT80 */
5488 return QCA_WLAN_VENDOR_PHY_MODE_11AC_VHT80;
5489 }
5490
5491 if (strcmp(val, "11na") == 0 ||
5492 strcasecmp(val, "11an") == 0) {
5493 /* IEEE80211_MODE_11NA_HT40 */
5494 return QCA_WLAN_VENDOR_PHY_MODE_11NA_HT40;
5495 }
5496
5497 if (strcmp(val, "11ax") == 0 ||
5498 strcmp(val, "auto") == 0) {
5499 /* IEEE80211_MODE_AUTO */
5500 return QCA_WLAN_VENDOR_PHY_MODE_AUTO;
5501 }
5502
5503 return -1;
5504}
5505
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08005506#endif /* NL80211_SUPPORT */
5507
5508
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05305509static int get_phymode(const char *val)
5510{
5511 if (strcmp(val, "11a") == 0)
5512 return 1; /* IEEE80211_MODE_11A */
5513 if (strcmp(val, "11g") == 0)
5514 return 3; /* IEEE80211_MODE_11G */
5515 if (strcmp(val, "11b") == 0)
5516 return 2; /* IEEE80211_MODE_11B */
5517 if (strcmp(val, "11n") == 0 ||
5518 strcmp(val, "11nl") == 0 ||
5519 strcmp(val, "11nl(nabg)") == 0)
5520 return 22; /* IEEE80211_MODE_11AGN */
5521 if (strcmp(val, "11ng") == 0)
5522 return 13; /* IEEE80211_MODE_11NG_HT40 */
5523 if (strcmp(val, "AC") == 0 ||
5524 strcasecmp(val, "11AC") == 0)
5525 return 19; /* IEEE80211_MODE_11AC_VHT80 */
5526 if (strcmp(val, "11na") == 0 ||
5527 strcasecmp(val, "11an") == 0)
5528 return 14; /* IEEE80211_MODE_11NA_HT40 */
5529 if (strcmp(val, "11ax") == 0 ||
5530 strcmp(val, "auto") == 0)
5531 return 0; /* IEEE80211_MODE_AUTO */
5532 return -1;
5533}
5534
5535
5536static void sta_set_phymode(struct sigma_dut *dut, const char *intf,
5537 const char *val)
5538{
5539 char buf[100];
5540 int len, phymode;
Vinita S. Maloo7462e812020-05-22 15:16:04 +05305541#ifdef NL80211_SUPPORT
5542 enum qca_wlan_vendor_phy_mode qca_phymode;
5543
5544 qca_phymode = get_qca_vendor_phymode(val);
5545 if (qca_phymode == -1) {
5546 sigma_dut_print(dut, DUT_MSG_DEBUG,
5547 "Ignoring mode change for mode: %s",
5548 val);
5549 return;
5550 }
5551
5552 if (nlvendor_sta_set_phymode(dut, intf, qca_phymode) == 0)
5553 return;
5554#endif /* NL80211_SUPPORT */
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05305555
5556 phymode = get_phymode(val);
5557 if (phymode == -1) {
5558 sigma_dut_print(dut, DUT_MSG_DEBUG,
5559 "Ignoring mode change for mode: %s",
5560 val);
5561 return;
5562 }
5563
5564 len = snprintf(buf, sizeof(buf), "iwpriv %s setphymode %d", intf,
5565 phymode);
5566 if (len < 0 || len >= sizeof(buf)) {
5567 sigma_dut_print(dut, DUT_MSG_ERROR,
5568 "Failed to set phymode");
5569 return;
5570 }
5571
5572 if (system(buf) != 0)
5573 sigma_dut_print(dut, DUT_MSG_ERROR,
5574 "iwpriv setting of phymode failed");
5575}
5576
5577
Jouni Malinenf7222712019-06-13 01:50:21 +03005578static enum sigma_cmd_result
5579cmd_sta_preset_testparameters(struct sigma_dut *dut, struct sigma_conn *conn,
5580 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005581{
5582 const char *intf = get_param(cmd, "Interface");
5583 const char *val;
5584
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03005585 val = get_param(cmd, "FT_DS");
5586 if (val) {
5587 if (strcasecmp(val, "Enable") == 0) {
5588 dut->sta_ft_ds = 1;
5589 } else if (strcasecmp(val, "Disable") == 0) {
5590 dut->sta_ft_ds = 0;
5591 } else {
5592 send_resp(dut, conn, SIGMA_ERROR,
5593 "errorCode,Unsupported value for FT_DS");
5594 return STATUS_SENT_ERROR;
5595 }
5596 }
5597
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005598 val = get_param(cmd, "Program");
Jouni Malinen1f6ae642018-06-07 23:56:13 +03005599 if (val && (strcasecmp(val, "HS2-R2") == 0 ||
5600 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005601 return cmd_sta_preset_testparameters_hs2_r2(dut, conn, intf,
5602 cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005603
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07005604 if (val && strcasecmp(val, "LOC") == 0)
5605 return loc_cmd_sta_preset_testparameters(dut, conn, cmd);
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02005606 if (val && strcasecmp(val, "60GHZ") == 0) {
5607 val = get_param(cmd, "WPS");
5608 if (val && strcasecmp(val, "disable") == 0) {
5609 dut->wps_disable = 1;
5610 sigma_dut_print(dut, DUT_MSG_INFO, "WPS disabled");
5611 } else {
5612 /* wps_disable can have other value from the previous
5613 * test, so make sure it has the correct value.
5614 */
5615 dut->wps_disable = 0;
5616 }
5617
5618 val = get_param(cmd, "P2P");
5619 if (val && strcasecmp(val, "disable") == 0)
5620 sigma_dut_print(dut, DUT_MSG_INFO, "P2P disabled");
5621 }
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07005622
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02005623 if (dut->program == PROGRAM_WPS && dut->band == WPS_BAND_60G)
5624 return cmd_sta_preset_testparameters_60ghz(dut, conn, cmd);
5625
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005626#ifdef ANDROID_NAN
5627 if (val && strcasecmp(val, "NAN") == 0)
5628 return nan_cmd_sta_preset_testparameters(dut, conn, cmd);
5629#endif /* ANDROID_NAN */
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07005630#ifdef MIRACAST
5631 if (val && (strcasecmp(val, "WFD") == 0 ||
5632 strcasecmp(val, "DisplayR2") == 0))
5633 return miracast_preset_testparameters(dut, conn, cmd);
5634#endif /* MIRACAST */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005635
Kiran Kumar Lokeredd086642020-06-04 00:29:26 -07005636 if (val &&
5637 (strcasecmp(val, "MBO") == 0 || strcasecmp(val, "HE") == 0)) {
Ashwini Patil68d02cd2017-01-10 15:39:16 +05305638 val = get_param(cmd, "Cellular_Data_Cap");
5639 if (val &&
5640 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
5641 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +05305642
5643 val = get_param(cmd, "Ch_Pref");
5644 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
5645 return 0;
5646
Ashwini Patilc63161e2017-04-13 16:30:23 +05305647 val = get_param(cmd, "BSS_Transition");
5648 if (val && mbo_set_bss_trans_req(dut, conn, intf, val) == 0)
5649 return 0;
5650
Ashwini Patila75de5a2017-04-13 16:35:05 +05305651 val = get_param(cmd, "Assoc_Disallow");
5652 if (val && mbo_set_assoc_disallow(dut, conn, intf, val) == 0)
5653 return 0;
5654
Ashwini Patil9183fdb2017-04-13 16:58:25 +05305655 val = get_param(cmd, "Roaming");
5656 if (val && mbo_set_roaming(dut, conn, intf, val) == 0)
5657 return 0;
5658
Ashwini Patil68d02cd2017-01-10 15:39:16 +05305659 return 1;
5660 }
5661
Ankita Bajaja2cb5672017-10-25 16:08:28 +05305662 if (val && strcasecmp(val, "OCE") == 0)
5663 return cmd_sta_preset_testparameters_oce(dut, conn, intf, cmd);
5664
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005665#if 0
5666 val = get_param(cmd, "Supplicant");
5667 if (val && strcasecmp(val, "Default") != 0) {
5668 send_resp(dut, conn, SIGMA_ERROR,
5669 "ErrorCode,Only default(Vendor) supplicant "
5670 "supported");
5671 return 0;
5672 }
5673#endif
5674
5675 val = get_param(cmd, "RTS");
5676 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005677 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005678 case DRIVER_ATHEROS:
5679 ath_sta_set_rts(dut, intf, val);
5680 break;
5681 default:
5682#if 0
5683 send_resp(dut, conn, SIGMA_ERROR,
5684 "ErrorCode,Setting RTS not supported");
5685 return 0;
5686#else
5687 sigma_dut_print(dut, DUT_MSG_DEBUG,
5688 "Setting RTS not supported");
5689 break;
5690#endif
5691 }
5692 }
5693
5694#if 0
5695 val = get_param(cmd, "FRGMNT");
5696 if (val) {
5697 /* TODO */
5698 send_resp(dut, conn, SIGMA_ERROR,
5699 "ErrorCode,Setting FRGMNT not supported");
5700 return 0;
5701 }
5702#endif
5703
5704#if 0
5705 val = get_param(cmd, "Preamble");
5706 if (val) {
5707 /* TODO: Long/Short */
5708 send_resp(dut, conn, SIGMA_ERROR,
5709 "ErrorCode,Setting Preamble not supported");
5710 return 0;
5711 }
5712#endif
5713
5714 val = get_param(cmd, "Mode");
5715 if (val) {
5716 if (strcmp(val, "11b") == 0 ||
5717 strcmp(val, "11g") == 0 ||
5718 strcmp(val, "11a") == 0 ||
5719 strcmp(val, "11n") == 0 ||
5720 strcmp(val, "11ng") == 0 ||
5721 strcmp(val, "11nl") == 0 ||
5722 strcmp(val, "11nl(nabg)") == 0 ||
5723 strcmp(val, "AC") == 0 ||
5724 strcmp(val, "11AC") == 0 ||
5725 strcmp(val, "11ac") == 0 ||
5726 strcmp(val, "11na") == 0 ||
Amarnath Hullur Subramanyamb0db2712018-01-30 19:40:35 -08005727 strcmp(val, "11an") == 0 ||
5728 strcmp(val, "11ax") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005729 /* STA supports all modes by default */
5730 } else {
5731 send_resp(dut, conn, SIGMA_ERROR,
5732 "ErrorCode,Setting Mode not supported");
5733 return 0;
5734 }
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08005735
5736 /* Change the mode only in case of testbed for HE program
5737 * and for 11a and 11g modes only. */
5738 if (dut->program == PROGRAM_HE &&
5739 dut->device_type == STA_testbed) {
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05305740 sta_set_phymode(dut, intf, val);
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08005741 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005742 }
5743
5744 val = get_param(cmd, "wmm");
5745 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005746 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005747 case DRIVER_ATHEROS:
5748 ath_sta_set_wmm(dut, intf, val);
5749 break;
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08005750 case DRIVER_WCN:
5751 wcn_sta_set_wmm(dut, intf, val);
5752 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005753 default:
5754 sigma_dut_print(dut, DUT_MSG_DEBUG,
5755 "Setting wmm not supported");
5756 break;
5757 }
5758 }
5759
5760 val = get_param(cmd, "Powersave");
5761 if (val) {
5762 if (strcmp(val, "0") == 0 || strcasecmp(val, "off") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005763 if (get_driver_type(dut) == DRIVER_WCN) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +05305764 if (set_power_save_wcn(dut, intf, 2) < 0)
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005765 return 0;
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005766 }
5767
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005768 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005769 "P2P_SET ps 0") < 0)
5770 return -2;
5771 /* Make sure test modes are disabled */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005772 wpa_command(get_station_ifname(dut), "P2P_SET ps 98");
5773 wpa_command(get_station_ifname(dut), "P2P_SET ps 96");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005774 } else if (strcmp(val, "1") == 0 ||
5775 strcasecmp(val, "PSPoll") == 0 ||
5776 strcasecmp(val, "on") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005777 if (get_driver_type(dut) == DRIVER_WCN) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +05305778 if (set_power_save_wcn(dut, intf, 1) < 0)
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005779 return 0;
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005780 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005781 /* Disable default power save mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005782 wpa_command(get_station_ifname(dut), "P2P_SET ps 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005783 /* Enable PS-Poll test mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005784 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005785 "P2P_SET ps 97") < 0 ||
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005786 wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005787 "P2P_SET ps 99") < 0)
5788 return -2;
5789 } else if (strcmp(val, "2") == 0 ||
5790 strcasecmp(val, "Fast") == 0) {
5791 /* TODO */
5792 send_resp(dut, conn, SIGMA_ERROR,
5793 "ErrorCode,Powersave=Fast not supported");
5794 return 0;
5795 } else if (strcmp(val, "3") == 0 ||
5796 strcasecmp(val, "PSNonPoll") == 0) {
5797 /* Make sure test modes are disabled */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005798 wpa_command(get_station_ifname(dut), "P2P_SET ps 98");
5799 wpa_command(get_station_ifname(dut), "P2P_SET ps 96");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005800
5801 /* Enable default power save mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005802 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005803 "P2P_SET ps 1") < 0)
5804 return -2;
5805 } else
5806 return -1;
5807 }
5808
5809 val = get_param(cmd, "NoAck");
5810 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005811 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005812 case DRIVER_ATHEROS:
5813 ath_sta_set_noack(dut, intf, val);
5814 break;
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08005815#ifdef NL80211_SUPPORT
5816 case DRIVER_WCN:
5817 wcn_sta_set_noack(dut, intf, val);
5818 break;
5819#endif /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005820 default:
5821 send_resp(dut, conn, SIGMA_ERROR,
5822 "ErrorCode,Setting NoAck not supported");
5823 return 0;
5824 }
5825 }
5826
5827 val = get_param(cmd, "IgnoreChswitchProhibit");
5828 if (val) {
5829 /* TODO: Enabled/disabled */
5830 if (strcasecmp(val, "Enabled") == 0) {
5831 send_resp(dut, conn, SIGMA_ERROR,
5832 "ErrorCode,Enabling IgnoreChswitchProhibit "
5833 "not supported");
5834 return 0;
5835 }
5836 }
5837
5838 val = get_param(cmd, "TDLS");
5839 if (val) {
5840 if (strcasecmp(val, "Disabled") == 0) {
5841 if (wpa_command(intf, "SET tdls_disabled 1")) {
5842 send_resp(dut, conn, SIGMA_ERROR,
5843 "ErrorCode,Failed to disable TDLS");
5844 return 0;
5845 }
5846 } else if (strcasecmp(val, "Enabled") == 0) {
5847 if (wpa_command(intf, "SET tdls_disabled 0")) {
5848 send_resp(dut, conn, SIGMA_ERROR,
5849 "ErrorCode,Failed to enable TDLS");
5850 return 0;
5851 }
5852 } else {
5853 send_resp(dut, conn, SIGMA_ERROR,
5854 "ErrorCode,Unsupported TDLS value");
5855 return 0;
5856 }
5857 }
5858
5859 val = get_param(cmd, "TDLSmode");
5860 if (val) {
5861 if (strcasecmp(val, "Default") == 0) {
5862 wpa_command(intf, "SET tdls_testing 0");
5863 } else if (strcasecmp(val, "APProhibit") == 0) {
5864 if (wpa_command(intf, "SET tdls_testing 0x400")) {
5865 send_resp(dut, conn, SIGMA_ERROR,
5866 "ErrorCode,Failed to enable ignore "
5867 "APProhibit TDLS mode");
5868 return 0;
5869 }
5870 } else if (strcasecmp(val, "HiLoMac") == 0) {
5871 /* STA should respond with TDLS setup req for a TDLS
5872 * setup req */
5873 if (wpa_command(intf, "SET tdls_testing 0x80")) {
5874 send_resp(dut, conn, SIGMA_ERROR,
5875 "ErrorCode,Failed to enable HiLoMac "
5876 "TDLS mode");
5877 return 0;
5878 }
5879 } else if (strcasecmp(val, "WeakSecurity") == 0) {
5880 /*
5881 * Since all security modes are enabled by default when
5882 * Sigma control is used, there is no need to do
5883 * anything here.
5884 */
5885 } else if (strcasecmp(val, "ExistLink") == 0) {
5886 /*
5887 * Since we allow new TDLS Setup Request even if there
5888 * is an existing link, nothing needs to be done for
5889 * this.
5890 */
5891 } else {
5892 /* TODO:
5893 * ExistLink: STA should send TDLS setup req even if
5894 * direct link already exists
5895 */
5896 send_resp(dut, conn, SIGMA_ERROR,
5897 "ErrorCode,Unsupported TDLSmode value");
5898 return 0;
5899 }
5900 }
5901
5902 val = get_param(cmd, "FakePubKey");
5903 if (val && atoi(val) && wpa_command(intf, "SET wps_corrupt_pkhash 1")) {
5904 send_resp(dut, conn, SIGMA_ERROR,
5905 "ErrorCode,Failed to enable FakePubKey");
5906 return 0;
5907 }
5908
Amarnath Hullur Subramanyamae1042b2018-02-22 21:52:52 -08005909#ifdef NL80211_SUPPORT
5910 val = get_param(cmd, "FrgmntSupport");
5911 if (val) {
5912 if (strcasecmp(val, "Enable") == 0) {
5913 if (sta_set_he_fragmentation(dut, intf,
5914 HE_FRAG_LEVEL1)) {
5915 send_resp(dut, conn, SIGMA_ERROR,
5916 "ErrorCode,Failed to enable HE Fragmentation");
5917 return 0;
5918 }
5919 } else if (strcasecmp(val, "Disable") == 0) {
5920 if (sta_set_he_fragmentation(dut, intf,
5921 HE_FRAG_DISABLE)) {
5922 send_resp(dut, conn, SIGMA_ERROR,
5923 "ErrorCode,Failed to disable HE Fragmentation");
5924 return 0;
5925 }
5926 }
5927 }
5928#endif /* NL80211_SUPPORT */
5929
Vinita S. Maloo8a4779c2020-06-22 19:32:37 +05305930 val = get_param(cmd, "IncludeMSCSDescriptor");
5931 if (val && strcasecmp(val, "1") == 0) {
5932 char buf[128];
5933 int len;
5934
5935 len = snprintf(buf, sizeof(buf),
Veerendranath Jakkam62cde372020-08-19 18:03:06 +05305936 "MSCS add up_bitmap=F0 up_limit=7 stream_timeout=60000 frame_classifier=045F%032x",
Vinita S. Maloo8a4779c2020-06-22 19:32:37 +05305937 0);
5938
5939 if (len < 0 || len >= sizeof(buf)) {
5940 sigma_dut_print(dut, DUT_MSG_ERROR,
5941 "Failed to build MSCS Descriptor IE");
5942 return ERROR_SEND_STATUS;
5943 }
5944
5945 if (wpa_command(intf, buf) != 0) {
5946 send_resp(dut, conn, SIGMA_ERROR,
5947 "ErrorCode,Failed to include MSCS descriptor");
5948 return STATUS_SENT_ERROR;
5949 }
5950 }
5951
Vinita S. Maloo2287f142021-02-01 16:17:09 +05305952 val = get_param(cmd, "SCSSupport");
5953 if (val) {
5954 char buf[30];
5955 int disable_scs, len;
5956
5957 if (strcasecmp(val, "Enable") == 0) {
5958 disable_scs = 0;
5959 } else if (strcasecmp(val, "Disable") == 0) {
5960 disable_scs = 1;
5961 } else {
5962 sigma_dut_print(dut, DUT_MSG_ERROR,
5963 "Invalid SCSsupport parameter");
5964 return INVALID_SEND_STATUS;
5965 }
5966
5967 len = snprintf(buf, sizeof(buf), "SET disable_scs_support %d",
5968 disable_scs);
5969 if (len < 0 || len >= sizeof(buf) ||
5970 wpa_command(intf, buf) != 0) {
5971 send_resp(dut, conn, SIGMA_ERROR,
5972 "ErrorCode,Failed to update SCS support");
5973 return STATUS_SENT_ERROR;
5974 }
5975 }
5976
Vinita S. Maloo83dee552021-04-12 16:47:47 +05305977 val = get_param(cmd, "MSCSSupport");
5978 if (val) {
5979 char buf[30];
5980 int disable_mscs, len;
5981
5982 if (strcasecmp(val, "Enable") == 0) {
5983 disable_mscs = 0;
5984 } else if (strcasecmp(val, "Disable") == 0) {
5985 disable_mscs = 1;
5986 } else {
5987 sigma_dut_print(dut, DUT_MSG_ERROR,
5988 "Invalid MSCSsupport parameter");
5989 return INVALID_SEND_STATUS;
5990 }
5991
5992 len = snprintf(buf, sizeof(buf), "SET disable_mscs_support %d",
5993 disable_mscs);
5994 if (len < 0 || len >= sizeof(buf) ||
5995 wpa_command(intf, buf) != 0) {
5996 send_resp(dut, conn, SIGMA_ERROR,
5997 "ErrorCode,Failed to update MSCS support");
5998 return STATUS_SENT_ERROR;
5999 }
6000 }
6001
Veerendranath Jakkama16cdc82021-09-12 16:44:22 +05306002 val = get_param(cmd, "DSCPPolicyCapability");
6003 if (val) {
6004 char buf[35];
6005 int len;
6006
6007 if (strcasecmp(val, "Enable") == 0) {
6008 len = snprintf(buf, sizeof(buf),
6009 "SET enable_dscp_policy_capa 1");
6010 } else if (strcasecmp(val, "Disable") == 0) {
6011 len = snprintf(buf, sizeof(buf),
6012 "SET enable_dscp_policy_capa 0");
6013 } else {
6014 sigma_dut_print(dut, DUT_MSG_ERROR,
6015 "Invalid DSCP policy parameter");
6016 return INVALID_SEND_STATUS;
6017 }
6018
6019 if (len < 0 || len >= sizeof(buf) ||
6020 wpa_command(intf, buf) != 0) {
6021 send_resp(dut, conn, SIGMA_ERROR,
6022 "ErrorCode,Failed to update DSCP policy capability");
6023 return STATUS_SENT_ERROR;
6024 }
6025 }
6026
6027 val = get_param(cmd, "DSCPPolicyRespParams");
6028 if (val) {
6029 if (strcasecmp(val, "RejectAll") == 0) {
6030 dut->reject_dscp_policies = 1;
6031 dut->dscp_reject_resp_code = DSCP_POLICY_REJECT;
6032 } else if (strcasecmp(val, "AcceptAll") == 0) {
6033 dut->reject_dscp_policies = 0;
6034 }
6035 }
6036
6037 val = get_param(cmd, "DSCPPolicyResp_StatusCode");
6038 if (val)
6039 dut->dscp_reject_resp_code = atoi(val);
6040
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006041 return 1;
6042}
6043
6044
6045static const char * ath_get_radio_name(const char *radio_name)
6046{
6047 if (radio_name == NULL)
6048 return "wifi0";
6049 if (strcmp(radio_name, "wifi1") == 0)
6050 return "wifi1";
6051 if (strcmp(radio_name, "wifi2") == 0)
6052 return "wifi2";
6053 return "wifi0";
6054}
6055
6056
6057static void ath_sta_set_txsp_stream(struct sigma_dut *dut, const char *intf,
6058 const char *val)
6059{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006060 unsigned int vht_mcsmap = 0;
6061 int txchainmask = 0;
6062 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
6063
6064 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
6065 if (dut->testbed_flag_txsp == 1) {
6066 vht_mcsmap = 0xfffc;
6067 dut->testbed_flag_txsp = 0;
6068 } else {
6069 vht_mcsmap = 0xfffe;
6070 }
6071 txchainmask = 1;
6072 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
6073 if (dut->testbed_flag_txsp == 1) {
6074 vht_mcsmap = 0xfff0;
6075 dut->testbed_flag_txsp = 0;
6076 } else {
6077 vht_mcsmap = 0xfffa;
6078 }
6079 txchainmask = 3;
6080 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
6081 if (dut->testbed_flag_txsp == 1) {
6082 vht_mcsmap = 0xffc0;
6083 dut->testbed_flag_txsp = 0;
6084 } else {
6085 vht_mcsmap = 0xffea;
6086 }
6087 txchainmask = 7;
6088 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
6089 if (dut->testbed_flag_txsp == 1) {
6090 vht_mcsmap = 0xff00;
6091 dut->testbed_flag_txsp = 0;
6092 } else {
6093 vht_mcsmap = 0xffaa;
6094 }
6095 txchainmask = 15;
6096 } else {
6097 if (dut->testbed_flag_txsp == 1) {
6098 vht_mcsmap = 0xffc0;
6099 dut->testbed_flag_txsp = 0;
6100 } else {
6101 vht_mcsmap = 0xffea;
6102 }
6103 }
6104
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006105 if (txchainmask)
6106 run_iwpriv(dut, basedev, "txchainmask %d", txchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006107
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006108 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006109}
6110
6111
6112static void ath_sta_set_rxsp_stream(struct sigma_dut *dut, const char *intf,
6113 const char *val)
6114{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006115 unsigned int vht_mcsmap = 0;
6116 int rxchainmask = 0;
6117 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
6118
6119 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
6120 if (dut->testbed_flag_rxsp == 1) {
6121 vht_mcsmap = 0xfffc;
6122 dut->testbed_flag_rxsp = 0;
6123 } else {
6124 vht_mcsmap = 0xfffe;
6125 }
6126 rxchainmask = 1;
6127 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
6128 if (dut->testbed_flag_rxsp == 1) {
6129 vht_mcsmap = 0xfff0;
6130 dut->testbed_flag_rxsp = 0;
6131 } else {
6132 vht_mcsmap = 0xfffa;
6133 }
6134 rxchainmask = 3;
6135 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
6136 if (dut->testbed_flag_rxsp == 1) {
6137 vht_mcsmap = 0xffc0;
6138 dut->testbed_flag_rxsp = 0;
6139 } else {
6140 vht_mcsmap = 0xffea;
6141 }
6142 rxchainmask = 7;
6143 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
6144 if (dut->testbed_flag_rxsp == 1) {
6145 vht_mcsmap = 0xff00;
6146 dut->testbed_flag_rxsp = 0;
6147 } else {
6148 vht_mcsmap = 0xffaa;
6149 }
6150 rxchainmask = 15;
6151 } else {
6152 if (dut->testbed_flag_rxsp == 1) {
6153 vht_mcsmap = 0xffc0;
6154 dut->testbed_flag_rxsp = 0;
6155 } else {
6156 vht_mcsmap = 0xffea;
6157 }
6158 }
6159
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006160 if (rxchainmask)
6161 run_iwpriv(dut, basedev, "rxchainmask %d", rxchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006162
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006163 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006164}
6165
6166
6167void ath_set_zero_crc(struct sigma_dut *dut, const char *val)
6168{
6169 if (strcasecmp(val, "enable") == 0) {
6170 if (system("athdiag --set --address=0x2a204 --and=0xbfffffff")
6171 != 0) {
6172 sigma_dut_print(dut, DUT_MSG_ERROR,
6173 "Disable BB_VHTSIGB_CRC_CALC failed");
6174 }
6175
6176 if (system("athdiag --set --address=0x2a204 --or=0x80000000")
6177 != 0) {
6178 sigma_dut_print(dut, DUT_MSG_ERROR,
6179 "Enable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
6180 }
6181 } else {
6182 if (system("athdiag --set --address=0x2a204 --and=0x7fffffff")
6183 != 0) {
6184 sigma_dut_print(dut, DUT_MSG_ERROR,
6185 "Disable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
6186 }
6187
6188 if (system("athdiag --set --address=0x2a204 --or=0x40000000")
6189 != 0) {
6190 sigma_dut_print(dut, DUT_MSG_ERROR,
6191 "Enable BB_VHTSIGB_CRC_CALC failed");
6192 }
6193 }
6194}
6195
6196
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08006197static int wcn_sta_set_width(struct sigma_dut *dut, const char *intf,
6198 const char *val)
6199{
6200 char buf[60];
6201
Shivani Baranwal2a572842021-09-16 12:27:15 +05306202#ifdef NL80211_SUPPORT
6203 enum nl80211_chan_width qca_channel_width;
6204
6205 if (strcmp(val, "20") == 0) {
6206 qca_channel_width = NL80211_CHAN_WIDTH_20;
6207 dut->chwidth = 0;
6208 } else if (strcmp(val, "40") == 0) {
6209 qca_channel_width = NL80211_CHAN_WIDTH_40;
6210 dut->chwidth = 1;
6211 } else if (strcmp(val, "80") == 0) {
6212 qca_channel_width = NL80211_CHAN_WIDTH_80;
6213 dut->chwidth = 2;
6214 } else if (strcmp(val, "160") == 0) {
6215 qca_channel_width = NL80211_CHAN_WIDTH_160;
6216 dut->chwidth = 3;
6217 } else if (strcasecmp(val, "Auto") == 0) {
6218 return 0;
6219 } else {
6220 sigma_dut_print(dut, DUT_MSG_ERROR, "WIDTH %s not supported",
6221 val);
6222 return -1;
6223 }
6224 if (sta_config_params(dut, intf, STA_SET_CHAN_WIDTH,
6225 qca_channel_width) == 0)
6226 return 0;
6227#endif /* NL80211_SUPPORT */
6228
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08006229 if (strcmp(val, "20") == 0) {
6230 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
6231 dut->chwidth = 0;
6232 } else if (strcmp(val, "40") == 0) {
6233 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 1", intf);
6234 dut->chwidth = 1;
6235 } else if (strcmp(val, "80") == 0) {
6236 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
6237 dut->chwidth = 2;
Sunil Duttb1cccac2018-05-22 21:03:12 +05306238 } else if (strcasecmp(val, "Auto") == 0) {
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08006239 buf[0] = '\0';
6240 } else {
6241 sigma_dut_print(dut, DUT_MSG_ERROR, "WIDTH %s not supported",
6242 val);
6243 return -1;
6244 }
6245
6246 if (buf[0] != '\0' && system(buf) != 0) {
6247 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv chwidth failed");
6248 return -1;
6249 }
6250
6251 return 0;
6252}
6253
6254
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08006255static int nlvendor_sta_set_addba_reject(struct sigma_dut *dut,
6256 const char *intf, int addbareject)
6257{
6258#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05306259 return wcn_wifi_test_config_set_u8(
6260 dut, intf,
6261 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ACCEPT_ADDBA_REQ,
6262 !addbareject);
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08006263#else /* NL80211_SUPPORT */
6264 sigma_dut_print(dut, DUT_MSG_ERROR,
6265 "ADDBA_REJECT cannot be set without NL80211_SUPPORT defined");
6266 return -1;
6267#endif /* NL80211_SUPPORT */
6268}
6269
6270
6271static int sta_set_addba_reject(struct sigma_dut *dut, const char *intf,
6272 int addbareject)
6273{
6274 int ret;
6275
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006276 switch (get_driver_type(dut)) {
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08006277 case DRIVER_WCN:
6278 ret = nlvendor_sta_set_addba_reject(dut, intf, addbareject);
6279 if (ret) {
6280 sigma_dut_print(dut, DUT_MSG_ERROR,
6281 "nlvendor_sta_set_addba_reject failed, ret:%d",
6282 ret);
6283 return ret;
6284 }
6285 break;
6286 default:
6287 sigma_dut_print(dut, DUT_MSG_ERROR,
6288 "errorCode,Unsupported ADDBA_REJECT with the current driver");
6289 ret = -1;
6290 break;
6291 }
6292
6293 return ret;
6294}
6295
6296
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08006297static int nlvendor_config_send_addba(struct sigma_dut *dut, const char *intf,
6298 int enable)
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08006299{
6300#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05306301 return wcn_wifi_test_config_set_u8(
6302 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SEND_ADDBA_REQ,
6303 enable);
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08006304#else /* NL80211_SUPPORT */
6305 sigma_dut_print(dut, DUT_MSG_ERROR,
6306 "Disable addba not possible without NL80211_SUPPORT defined");
6307 return -1;
6308#endif /* NL80211_SUPPORT */
6309}
6310
6311
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05306312#ifdef NL80211_SUPPORT
6313static int nl80211_sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
6314{
6315 struct nl_msg *msg;
6316 int ret = 0;
6317 int ifindex;
6318
6319 ifindex = if_nametoindex(intf);
6320 if (ifindex == 0) {
6321 sigma_dut_print(dut, DUT_MSG_ERROR,
6322 "%s: Index for interface %s failed",
6323 __func__, intf);
6324 return -1;
6325 }
6326
6327 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6328 NL80211_CMD_SET_WIPHY)) ||
6329 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) {
6330 sigma_dut_print(dut, DUT_MSG_ERROR,
6331 "%s: err in adding RTS threshold",
6332 __func__);
6333 nlmsg_free(msg);
6334 return -1;
6335 }
6336
6337 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6338 if (ret) {
6339 sigma_dut_print(dut, DUT_MSG_ERROR,
6340 "%s: err in send_and_recv_msgs, ret=%d",
6341 __func__, ret);
6342 }
6343 return ret;
6344}
6345#endif /* NL80211_SUPPORT */
6346
6347
6348static int sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
6349{
6350 char buf[100];
6351
6352#ifdef NL80211_SUPPORT
6353 if (nl80211_sta_set_rts(dut, intf, val) == 0)
6354 return 0;
6355 sigma_dut_print(dut, DUT_MSG_DEBUG,
6356 "Fall back to using iwconfig for setting RTS threshold");
6357#endif /* NL80211_SUPPORT */
6358
6359 snprintf(buf, sizeof(buf), "iwconfig %s rts %d", intf, val);
6360 if (system(buf) != 0) {
6361 sigma_dut_print(dut, DUT_MSG_ERROR,
6362 "Failed to set RTS threshold %d", val);
6363 return -1;
6364 }
6365 return 0;
6366}
6367
6368
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006369static enum sigma_cmd_result
6370cmd_sta_set_wireless_common(const char *intf, struct sigma_dut *dut,
6371 struct sigma_conn *conn, struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006372{
6373 const char *val;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08006374 int ampdu = -1, addbareject = -1;
Jouni Malinen3aa72862019-05-29 23:14:51 +03006375 char buf[128];
6376 int res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006377
6378 val = get_param(cmd, "40_INTOLERANT");
6379 if (val) {
6380 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
6381 /* TODO: iwpriv ht40intol through wpa_supplicant */
6382 send_resp(dut, conn, SIGMA_ERROR,
6383 "ErrorCode,40_INTOLERANT not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006384 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006385 }
6386 }
6387
6388 val = get_param(cmd, "ADDBA_REJECT");
6389 if (val) {
6390 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
6391 /* reject any ADDBA with status "decline" */
6392 ampdu = 0;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08006393 addbareject = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006394 } else {
6395 /* accept ADDBA */
6396 ampdu = 1;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08006397 addbareject = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006398 }
6399 }
6400
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08006401 if (addbareject >= 0 &&
6402 sta_set_addba_reject(dut, intf, addbareject) < 0) {
6403 send_resp(dut, conn, SIGMA_ERROR,
6404 "ErrorCode,set addba_reject failed");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006405 return STATUS_SENT_ERROR;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08006406 }
6407
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006408 val = get_param(cmd, "AMPDU");
6409 if (val) {
6410 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
6411 /* enable AMPDU Aggregation */
6412 if (ampdu == 0) {
6413 send_resp(dut, conn, SIGMA_ERROR,
6414 "ErrorCode,Mismatch in "
6415 "addba_reject/ampdu - "
6416 "not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006417 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006418 }
6419 ampdu = 1;
6420 } else {
6421 /* disable AMPDU Aggregation */
6422 if (ampdu == 1) {
6423 send_resp(dut, conn, SIGMA_ERROR,
6424 "ErrorCode,Mismatch in "
6425 "addba_reject/ampdu - "
6426 "not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006427 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006428 }
6429 ampdu = 0;
6430 }
6431 }
6432
6433 if (ampdu >= 0) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08006434 int ret;
6435
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006436 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s A-MPDU aggregation",
6437 ampdu ? "Enabling" : "Disabling");
6438 snprintf(buf, sizeof(buf), "SET ampdu %d", ampdu);
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07006439 if (wpa_command(intf, buf) < 0 &&
6440 iwpriv_sta_set_ampdu(dut, intf, ampdu) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006441 send_resp(dut, conn, SIGMA_ERROR,
6442 "ErrorCode,set aggr failed");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006443 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006444 }
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08006445
6446 if (ampdu == 0) {
6447 /* Disable sending of addba using nl vendor command */
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08006448 ret = nlvendor_config_send_addba(dut, intf, 0);
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08006449 if (ret) {
6450 sigma_dut_print(dut, DUT_MSG_ERROR,
6451 "Failed to disable addba, ret:%d",
6452 ret);
6453 }
6454 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006455 }
6456
6457 val = get_param(cmd, "AMSDU");
6458 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006459 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006460 case DRIVER_ATHEROS:
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08006461 case DRIVER_WCN:
6462 iwpriv_sta_set_amsdu(dut, intf, val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006463 break;
6464 default:
6465 if (strcmp(val, "1") == 0 ||
6466 strcasecmp(val, "Enable") == 0) {
6467 /* Enable AMSDU Aggregation */
6468 send_resp(dut, conn, SIGMA_ERROR,
6469 "ErrorCode,AMSDU aggregation not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006470 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006471 }
6472 break;
6473 }
6474 }
6475
6476 val = get_param(cmd, "STBC_RX");
6477 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006478 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006479 case DRIVER_ATHEROS:
6480 ath_sta_set_stbc(dut, intf, val);
6481 break;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05306482 case DRIVER_WCN:
6483 wcn_sta_set_stbc(dut, intf, val);
6484 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006485 default:
6486 send_resp(dut, conn, SIGMA_ERROR,
6487 "ErrorCode,STBC_RX not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006488 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006489 }
6490 }
6491
6492 val = get_param(cmd, "WIDTH");
6493 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006494 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006495 case DRIVER_WCN:
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08006496 if (wcn_sta_set_width(dut, intf, val) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006497 send_resp(dut, conn, SIGMA_ERROR,
6498 "ErrorCode,Failed to set WIDTH");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006499 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006500 }
6501 break;
6502 case DRIVER_ATHEROS:
6503 if (ath_set_width(dut, conn, intf, val) < 0)
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006504 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006505 break;
6506 default:
6507 sigma_dut_print(dut, DUT_MSG_ERROR,
6508 "Setting WIDTH not supported");
6509 break;
6510 }
6511 }
6512
6513 val = get_param(cmd, "SMPS");
6514 if (val) {
6515 /* TODO: Dynamic/0, Static/1, No Limit/2 */
6516 send_resp(dut, conn, SIGMA_ERROR,
6517 "ErrorCode,SMPS not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006518 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006519 }
6520
6521 val = get_param(cmd, "TXSP_STREAM");
6522 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006523 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006524 case DRIVER_WCN:
6525 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
6526 send_resp(dut, conn, SIGMA_ERROR,
6527 "ErrorCode,Failed to set TXSP_STREAM");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006528 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006529 }
6530 break;
6531 case DRIVER_ATHEROS:
6532 ath_sta_set_txsp_stream(dut, intf, val);
6533 break;
6534 default:
6535 sigma_dut_print(dut, DUT_MSG_ERROR,
6536 "Setting TXSP_STREAM not supported");
6537 break;
6538 }
6539 }
6540
6541 val = get_param(cmd, "RXSP_STREAM");
6542 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006543 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006544 case DRIVER_WCN:
6545 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
6546 send_resp(dut, conn, SIGMA_ERROR,
6547 "ErrorCode,Failed to set RXSP_STREAM");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006548 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006549 }
6550 break;
6551 case DRIVER_ATHEROS:
6552 ath_sta_set_rxsp_stream(dut, intf, val);
6553 break;
6554 default:
6555 sigma_dut_print(dut, DUT_MSG_ERROR,
6556 "Setting RXSP_STREAM not supported");
6557 break;
6558 }
6559 }
6560
6561 val = get_param(cmd, "DYN_BW_SGNL");
6562 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006563 switch (get_driver_type(dut)) {
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08006564 case DRIVER_WCN:
Peng Xuc59afd32016-11-21 15:01:11 -08006565 if (strcasecmp(val, "enable") == 0) {
6566 snprintf(buf, sizeof(buf),
6567 "iwpriv %s cwmenable 1", intf);
6568 if (system(buf) != 0) {
6569 sigma_dut_print(dut, DUT_MSG_ERROR,
6570 "iwpriv cwmenable 1 failed");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006571 return ERROR_SEND_STATUS;
Peng Xuc59afd32016-11-21 15:01:11 -08006572 }
6573 } else if (strcasecmp(val, "disable") == 0) {
6574 snprintf(buf, sizeof(buf),
6575 "iwpriv %s cwmenable 0", intf);
6576 if (system(buf) != 0) {
6577 sigma_dut_print(dut, DUT_MSG_ERROR,
6578 "iwpriv cwmenable 0 failed");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006579 return ERROR_SEND_STATUS;
Peng Xuc59afd32016-11-21 15:01:11 -08006580 }
6581 } else {
6582 sigma_dut_print(dut, DUT_MSG_ERROR,
6583 "Unsupported DYN_BW_SGL");
6584 }
6585
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006586 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
6587 if (system(buf) != 0) {
6588 sigma_dut_print(dut, DUT_MSG_ERROR,
6589 "Failed to set cts_cbw in DYN_BW_SGNL");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006590 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006591 }
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08006592 break;
6593 case DRIVER_ATHEROS:
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07006594 novap_reset(dut, intf, 1);
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08006595 ath_config_dyn_bw_sig(dut, intf, val);
6596 break;
6597 default:
6598 sigma_dut_print(dut, DUT_MSG_ERROR,
6599 "Failed to set DYN_BW_SGNL");
6600 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006601 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006602 }
6603
6604 val = get_param(cmd, "RTS_FORCE");
6605 if (val) {
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07006606 novap_reset(dut, intf, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006607 if (strcasecmp(val, "Enable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05306608 if (sta_set_rts(dut, intf, 64) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02006609 sigma_dut_print(dut, DUT_MSG_ERROR,
6610 "Failed to set RTS_FORCE 64");
6611 }
Jouni Malinen3aa72862019-05-29 23:14:51 +03006612 res = snprintf(buf, sizeof(buf),
6613 "wifitool %s beeliner_fw_test 100 1",
6614 intf);
6615 if (res < 0 || res >= sizeof(buf) || system(buf) != 0) {
priyadharshini gowthaman270870e2015-12-09 10:10:23 -08006616 sigma_dut_print(dut, DUT_MSG_ERROR,
6617 "wifitool beeliner_fw_test 100 1 failed");
6618 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006619 } else if (strcasecmp(val, "Disable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05306620 if (sta_set_rts(dut, intf, 2347) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02006621 sigma_dut_print(dut, DUT_MSG_ERROR,
6622 "Failed to set RTS_FORCE 2347");
6623 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006624 } else {
6625 send_resp(dut, conn, SIGMA_ERROR,
6626 "ErrorCode,RTS_FORCE value not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006627 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006628 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006629 }
6630
6631 val = get_param(cmd, "CTS_WIDTH");
6632 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006633 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006634 case DRIVER_WCN:
6635 if (wcn_sta_set_cts_width(dut, intf, val) < 0) {
6636 send_resp(dut, conn, SIGMA_ERROR,
6637 "ErrorCode,Failed to set CTS_WIDTH");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006638 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006639 }
6640 break;
6641 case DRIVER_ATHEROS:
6642 ath_set_cts_width(dut, intf, val);
6643 break;
6644 default:
6645 sigma_dut_print(dut, DUT_MSG_ERROR,
6646 "Setting CTS_WIDTH not supported");
6647 break;
6648 }
6649 }
6650
6651 val = get_param(cmd, "BW_SGNL");
6652 if (val) {
6653 if (strcasecmp(val, "Enable") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006654 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006655 } else if (strcasecmp(val, "Disable") == 0) {
6656 /* TODO: Disable */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006657 } else {
6658 send_resp(dut, conn, SIGMA_ERROR,
6659 "ErrorCode,BW_SGNL value not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006660 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006661 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006662 }
6663
6664 val = get_param(cmd, "Band");
6665 if (val) {
6666 if (strcmp(val, "2.4") == 0 || strcmp(val, "5") == 0) {
6667 /* STA supports all bands by default */
6668 } else {
6669 send_resp(dut, conn, SIGMA_ERROR,
6670 "ErrorCode,Unsupported Band");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006671 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006672 }
6673 }
6674
6675 val = get_param(cmd, "zero_crc");
6676 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006677 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006678 case DRIVER_ATHEROS:
6679 ath_set_zero_crc(dut, val);
6680 break;
6681 default:
6682 break;
6683 }
6684 }
6685
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006686 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006687}
6688
6689
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006690static int sta_set_force_mcs(struct sigma_dut *dut, int force, int mcs)
6691{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006692 switch (get_driver_type(dut)) {
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006693#ifdef __linux__
6694 case DRIVER_WIL6210:
6695 return wil6210_set_force_mcs(dut, force, mcs);
6696#endif /* __linux__ */
6697 default:
6698 sigma_dut_print(dut, DUT_MSG_ERROR,
6699 "Unsupported sta_set_force_mcs with the current driver");
6700 return -1;
6701 }
6702}
6703
6704
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02006705static int sta_60g_force_rsn_ie(struct sigma_dut *dut, int state)
6706{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006707 switch (get_driver_type(dut)) {
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02006708#ifdef __linux__
6709 case DRIVER_WIL6210:
6710 return wil6210_force_rsn_ie(dut, state);
6711#endif /* __linux__ */
6712 default:
6713 sigma_dut_print(dut, DUT_MSG_ERROR,
6714 "Unsupported sta_60g_force_rsn_ie with the current driver");
6715 return -1;
6716 }
6717}
6718
6719
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006720static int sta_set_60g_common(struct sigma_dut *dut, struct sigma_conn *conn,
6721 struct sigma_cmd *cmd)
6722{
6723 const char *val;
6724 char buf[100];
6725
6726 val = get_param(cmd, "MSDUSize");
6727 if (val) {
6728 int mtu;
6729
6730 dut->amsdu_size = atoi(val);
6731 if (dut->amsdu_size > IEEE80211_MAX_DATA_LEN_DMG ||
6732 dut->amsdu_size < IEEE80211_SNAP_LEN_DMG) {
6733 sigma_dut_print(dut, DUT_MSG_ERROR,
6734 "MSDUSize %d is above max %d or below min %d",
6735 dut->amsdu_size,
6736 IEEE80211_MAX_DATA_LEN_DMG,
6737 IEEE80211_SNAP_LEN_DMG);
6738 dut->amsdu_size = 0;
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006739 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006740 }
6741
6742 mtu = dut->amsdu_size - IEEE80211_SNAP_LEN_DMG;
6743 sigma_dut_print(dut, DUT_MSG_DEBUG,
6744 "Setting amsdu_size to %d", mtu);
6745 snprintf(buf, sizeof(buf), "ifconfig %s mtu %d",
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006746 get_station_ifname(dut), mtu);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006747
6748 if (system(buf) != 0) {
6749 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
6750 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006751 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006752 }
6753 }
6754
6755 val = get_param(cmd, "BAckRcvBuf");
6756 if (val) {
6757 dut->back_rcv_buf = atoi(val);
6758 if (dut->back_rcv_buf == 0) {
6759 sigma_dut_print(dut, DUT_MSG_ERROR,
6760 "Failed to convert %s or value is 0",
6761 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006762 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006763 }
6764
6765 sigma_dut_print(dut, DUT_MSG_DEBUG,
6766 "Setting BAckRcvBuf to %s", val);
6767 }
6768
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006769 val = get_param(cmd, "MCS_FixedRate");
6770 if (val) {
6771 if (sta_set_force_mcs(dut, 1, atoi(val))) {
6772 sigma_dut_print(dut, DUT_MSG_ERROR,
6773 "Failed to force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006774 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006775 }
6776 }
6777
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006778 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006779}
6780
6781
6782static int sta_pcp_start(struct sigma_dut *dut, struct sigma_conn *conn,
6783 struct sigma_cmd *cmd)
6784{
6785 int net_id;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006786 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006787 const char *val;
6788 char buf[100];
6789
6790 dut->mode = SIGMA_MODE_STATION;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006791 ifname = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006792 if (wpa_command(ifname, "PING") != 0) {
6793 sigma_dut_print(dut, DUT_MSG_ERROR, "Supplicant not running");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006794 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006795 }
6796
6797 wpa_command(ifname, "FLUSH");
6798 net_id = add_network_common(dut, conn, ifname, cmd);
6799 if (net_id < 0) {
6800 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add network");
6801 return net_id;
6802 }
6803
6804 /* TODO: mode=2 for the AP; in the future, replace for mode PCP */
6805 if (set_network(ifname, net_id, "mode", "2") < 0) {
6806 sigma_dut_print(dut, DUT_MSG_ERROR,
6807 "Failed to set supplicant network mode");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006808 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006809 }
6810
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02006811 if (set_network(ifname, net_id, "pbss", "1") < 0)
6812 return -2;
6813
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006814 sigma_dut_print(dut, DUT_MSG_DEBUG,
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02006815 "Supplicant set network with mode 2. network_id %d",
6816 net_id);
6817
6818 if (set_network(ifname, net_id, "wps_disabled", "0") < 0) {
6819 sigma_dut_print(dut, DUT_MSG_INFO,
6820 "Failed to set supplicant to WPS ENABLE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006821 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02006822 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006823
6824 val = get_param(cmd, "Security");
6825 if (val && strcasecmp(val, "OPEN") == 0) {
6826 dut->ap_key_mgmt = AP_OPEN;
6827 if (set_network(ifname, net_id, "key_mgmt", "NONE") < 0) {
6828 sigma_dut_print(dut, DUT_MSG_ERROR,
6829 "Failed to set supplicant to %s security",
6830 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006831 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006832 }
6833 } else if (val && strcasecmp(val, "WPA2-PSK") == 0) {
6834 dut->ap_key_mgmt = AP_WPA2_PSK;
6835 if (set_network(ifname, net_id, "key_mgmt", "WPA-PSK") < 0) {
6836 sigma_dut_print(dut, DUT_MSG_ERROR,
6837 "Failed to set supplicant to %s security",
6838 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006839 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006840 }
6841
6842 if (set_network(ifname, net_id, "proto", "RSN") < 0) {
6843 sigma_dut_print(dut, DUT_MSG_ERROR,
6844 "Failed to set supplicant to proto RSN");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006845 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006846 }
6847 } else if (val) {
6848 sigma_dut_print(dut, DUT_MSG_ERROR,
6849 "Requested Security %s is not supported on 60GHz",
6850 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006851 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006852 }
6853
6854 val = get_param(cmd, "Encrypt");
6855 if (val && strcasecmp(val, "AES-GCMP") == 0) {
6856 if (set_network(ifname, net_id, "pairwise", "GCMP") < 0) {
6857 sigma_dut_print(dut, DUT_MSG_ERROR,
6858 "Failed to set supplicant to pairwise GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006859 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006860 }
6861 if (set_network(ifname, net_id, "group", "GCMP") < 0) {
6862 sigma_dut_print(dut, DUT_MSG_ERROR,
6863 "Failed to set supplicant to group GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006864 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006865 }
6866 } else if (val) {
6867 sigma_dut_print(dut, DUT_MSG_ERROR,
6868 "Requested Encrypt %s is not supported on 60 GHz",
6869 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006870 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006871 }
6872
6873 val = get_param(cmd, "PSK");
6874 if (val && set_network_quoted(ifname, net_id, "psk", val) < 0) {
6875 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set psk %s",
6876 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006877 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006878 }
6879
6880 /* Convert 60G channel to freq */
6881 switch (dut->ap_channel) {
6882 case 1:
6883 val = "58320";
6884 break;
6885 case 2:
6886 val = "60480";
6887 break;
6888 case 3:
6889 val = "62640";
6890 break;
6891 default:
6892 sigma_dut_print(dut, DUT_MSG_ERROR,
6893 "Failed to configure channel %d. Not supported",
6894 dut->ap_channel);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006895 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006896 }
6897
6898 if (set_network(ifname, net_id, "frequency", val) < 0) {
6899 sigma_dut_print(dut, DUT_MSG_ERROR,
6900 "Failed to set supplicant network frequency");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006901 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006902 }
6903
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02006904 if (dut->eap_fragment) {
6905 sigma_dut_print(dut, DUT_MSG_DEBUG,
6906 "Set EAP fragment size to 128 bytes.");
6907 if (set_network(ifname, net_id, "fragment_size", "128") < 0)
6908 return ERROR_SEND_STATUS;
6909 }
6910
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006911 sigma_dut_print(dut, DUT_MSG_DEBUG,
6912 "Supplicant set network with frequency");
6913
6914 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d", net_id);
6915 if (wpa_command(ifname, buf) < 0) {
6916 sigma_dut_print(dut, DUT_MSG_INFO,
6917 "Failed to select network id %d on %s",
6918 net_id, ifname);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006919 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006920 }
6921
6922 sigma_dut_print(dut, DUT_MSG_DEBUG, "Selected network");
6923
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006924 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006925}
6926
6927
Lior David67543f52017-01-03 19:04:22 +02006928static int wil6210_set_abft_len(struct sigma_dut *dut, int abft_len)
6929{
6930 char buf[128], fname[128];
6931 FILE *f;
Jouni Malinen3aa72862019-05-29 23:14:51 +03006932 int res;
Lior David67543f52017-01-03 19:04:22 +02006933
6934 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
6935 sigma_dut_print(dut, DUT_MSG_ERROR,
6936 "failed to get wil6210 debugfs dir");
6937 return -1;
6938 }
6939
Jouni Malinen3aa72862019-05-29 23:14:51 +03006940 res = snprintf(fname, sizeof(fname), "%s/abft_len", buf);
6941 if (res < 0 || res >= sizeof(fname))
6942 return -1;
Lior David67543f52017-01-03 19:04:22 +02006943 f = fopen(fname, "w");
6944 if (!f) {
6945 sigma_dut_print(dut, DUT_MSG_ERROR,
6946 "failed to open: %s", fname);
6947 return -1;
6948 }
6949
6950 fprintf(f, "%d\n", abft_len);
6951 fclose(f);
6952
6953 return 0;
6954}
6955
6956
Alexei Avshalom Lazar49498b82019-01-31 15:16:32 +02006957int sta_set_60g_abft_len(struct sigma_dut *dut, struct sigma_conn *conn,
6958 int abft_len)
Lior David67543f52017-01-03 19:04:22 +02006959{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006960 switch (get_driver_type(dut)) {
Lior David67543f52017-01-03 19:04:22 +02006961 case DRIVER_WIL6210:
6962 return wil6210_set_abft_len(dut, abft_len);
6963 default:
6964 sigma_dut_print(dut, DUT_MSG_ERROR,
6965 "set abft_len not supported");
6966 return -1;
6967 }
6968}
6969
6970
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006971static int sta_set_60g_pcp(struct sigma_dut *dut, struct sigma_conn *conn,
6972 struct sigma_cmd *cmd)
6973{
6974 const char *val;
Lior David67543f52017-01-03 19:04:22 +02006975 unsigned int abft_len = 1; /* default is one slot */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006976
6977 if (dut->dev_role != DEVROLE_PCP) {
6978 send_resp(dut, conn, SIGMA_INVALID,
6979 "ErrorCode,Invalid DevRole");
6980 return 0;
6981 }
6982
6983 val = get_param(cmd, "SSID");
6984 if (val) {
6985 if (strlen(val) > sizeof(dut->ap_ssid) - 1) {
6986 send_resp(dut, conn, SIGMA_INVALID,
6987 "ErrorCode,Invalid SSID");
6988 return -1;
6989 }
6990
Peng Xub8fc5cc2017-05-10 17:27:28 -07006991 strlcpy(dut->ap_ssid, val, sizeof(dut->ap_ssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006992 }
6993
6994 val = get_param(cmd, "CHANNEL");
6995 if (val) {
6996 const char *pos;
6997
6998 dut->ap_channel = atoi(val);
6999 pos = strchr(val, ';');
7000 if (pos) {
7001 pos++;
7002 dut->ap_channel_1 = atoi(pos);
7003 }
7004 }
7005
7006 switch (dut->ap_channel) {
7007 case 1:
7008 case 2:
7009 case 3:
7010 break;
7011 default:
7012 sigma_dut_print(dut, DUT_MSG_ERROR,
7013 "Channel %d is not supported", dut->ap_channel);
7014 send_resp(dut, conn, SIGMA_ERROR,
7015 "Requested channel is not supported");
7016 return -1;
7017 }
7018
7019 val = get_param(cmd, "BCNINT");
7020 if (val)
7021 dut->ap_bcnint = atoi(val);
7022
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007023 val = get_param(cmd, "AllocType");
7024 if (val) {
7025 send_resp(dut, conn, SIGMA_ERROR,
7026 "ErrorCode,AllocType is not supported yet");
7027 return -1;
7028 }
7029
7030 val = get_param(cmd, "PercentBI");
7031 if (val) {
7032 send_resp(dut, conn, SIGMA_ERROR,
7033 "ErrorCode,PercentBI is not supported yet");
7034 return -1;
7035 }
7036
7037 val = get_param(cmd, "CBAPOnly");
7038 if (val) {
7039 send_resp(dut, conn, SIGMA_ERROR,
7040 "ErrorCode,CBAPOnly is not supported yet");
7041 return -1;
7042 }
7043
7044 val = get_param(cmd, "AMPDU");
7045 if (val) {
7046 if (strcasecmp(val, "Enable") == 0)
7047 dut->ap_ampdu = 1;
7048 else if (strcasecmp(val, "Disable") == 0)
7049 dut->ap_ampdu = 2;
7050 else {
7051 send_resp(dut, conn, SIGMA_ERROR,
7052 "ErrorCode,AMPDU value is not Enable nor Disabled");
7053 return -1;
7054 }
7055 }
7056
7057 val = get_param(cmd, "AMSDU");
7058 if (val) {
7059 if (strcasecmp(val, "Enable") == 0)
7060 dut->ap_amsdu = 1;
7061 else if (strcasecmp(val, "Disable") == 0)
7062 dut->ap_amsdu = 2;
7063 }
7064
7065 val = get_param(cmd, "NumMSDU");
7066 if (val) {
7067 send_resp(dut, conn, SIGMA_ERROR,
7068 "ErrorCode, NumMSDU is not supported yet");
7069 return -1;
7070 }
7071
7072 val = get_param(cmd, "ABFTLRang");
7073 if (val) {
7074 sigma_dut_print(dut, DUT_MSG_DEBUG,
Lior David67543f52017-01-03 19:04:22 +02007075 "ABFTLRang parameter %s", val);
7076 if (strcmp(val, "Gt1") == 0)
7077 abft_len = 2; /* 2 slots in this case */
7078 }
7079
7080 if (sta_set_60g_abft_len(dut, conn, abft_len)) {
7081 send_resp(dut, conn, SIGMA_ERROR,
7082 "ErrorCode, Can't set ABFT length");
7083 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007084 }
7085
7086 if (sta_pcp_start(dut, conn, cmd) < 0) {
7087 send_resp(dut, conn, SIGMA_ERROR,
7088 "ErrorCode, Can't start PCP role");
7089 return -1;
7090 }
7091
7092 return sta_set_60g_common(dut, conn, cmd);
7093}
7094
7095
7096static int sta_set_60g_sta(struct sigma_dut *dut, struct sigma_conn *conn,
7097 struct sigma_cmd *cmd)
7098{
7099 const char *val = get_param(cmd, "DiscoveryMode");
7100
7101 if (dut->dev_role != DEVROLE_STA) {
7102 send_resp(dut, conn, SIGMA_INVALID,
7103 "ErrorCode,Invalid DevRole");
7104 return 0;
7105 }
7106
7107 if (val) {
7108 sigma_dut_print(dut, DUT_MSG_DEBUG, "Discovery: %s", val);
7109 /* Ignore Discovery mode till Driver expose API. */
7110#if 0
7111 if (strcasecmp(val, "1") == 0) {
7112 send_resp(dut, conn, SIGMA_INVALID,
7113 "ErrorCode,DiscoveryMode 1 not supported");
7114 return 0;
7115 }
7116
7117 if (strcasecmp(val, "0") == 0) {
7118 /* OK */
7119 } else {
7120 send_resp(dut, conn, SIGMA_INVALID,
7121 "ErrorCode,DiscoveryMode not supported");
7122 return 0;
7123 }
7124#endif
7125 }
7126
7127 if (start_sta_mode(dut) != 0)
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007128 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007129 return sta_set_60g_common(dut, conn, cmd);
7130}
7131
7132
Jouni Malinenf7222712019-06-13 01:50:21 +03007133static enum sigma_cmd_result cmd_sta_disconnect(struct sigma_dut *dut,
7134 struct sigma_conn *conn,
7135 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007136{
7137 const char *intf = get_param(cmd, "Interface");
Jouni Malinened77e672018-01-10 16:45:13 +02007138 const char *val = get_param(cmd, "maintain_profile");
vamsi krishnad605c422017-09-20 14:56:31 +05307139
Jouni Malinened77e672018-01-10 16:45:13 +02007140 if (dut->program == PROGRAM_OCE ||
Amarnath Hullur Subramanyamebeda9e2018-01-31 03:21:48 -08007141 dut->program == PROGRAM_HE ||
Jouni Malinened77e672018-01-10 16:45:13 +02007142 (val && atoi(val) == 1)) {
vamsi krishnad605c422017-09-20 14:56:31 +05307143 wpa_command(intf, "DISCONNECT");
7144 return 1;
7145 }
7146
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007147 disconnect_station(dut);
7148 /* Try to ignore old scan results to avoid HS 2.0R2 test case failures
7149 * due to cached results. */
7150 wpa_command(intf, "SET ignore_old_scan_res 1");
7151 wpa_command(intf, "BSS_FLUSH");
7152 return 1;
7153}
7154
7155
Jouni Malinenf7222712019-06-13 01:50:21 +03007156static enum sigma_cmd_result cmd_sta_reassoc(struct sigma_dut *dut,
7157 struct sigma_conn *conn,
7158 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007159{
7160 const char *intf = get_param(cmd, "Interface");
7161 const char *bssid = get_param(cmd, "bssid");
7162 const char *val = get_param(cmd, "CHANNEL");
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07007163 const char *freq_val = get_param(cmd, "ChnlFreq");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007164 struct wpa_ctrl *ctrl;
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05307165 char buf[1000];
Sunil Duttd30ce092018-01-11 23:56:29 +05307166 char result[32];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007167 int res;
7168 int chan = 0;
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07007169 int freq = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007170 enum sigma_cmd_result status = STATUS_SENT;
Sunil Duttd30ce092018-01-11 23:56:29 +05307171 int fastreassoc = 1;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007172 int ft_ds = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007173
7174 if (bssid == NULL) {
7175 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing bssid "
7176 "argument");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007177 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007178 }
7179
7180 if (val)
7181 chan = atoi(val);
7182
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07007183 if (freq_val)
7184 freq = atoi(freq_val);
7185
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007186 if (wifi_chip_type != DRIVER_WCN && wifi_chip_type != DRIVER_AR6003) {
7187 /* The current network may be from sta_associate or
7188 * sta_hs2_associate
7189 */
7190 if (set_network(intf, dut->infra_network_id, "bssid", bssid) <
7191 0 ||
7192 set_network(intf, 0, "bssid", bssid) < 0)
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007193 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007194 }
7195
7196 ctrl = open_wpa_mon(intf);
7197 if (ctrl == NULL) {
7198 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
7199 "wpa_supplicant monitor connection");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007200 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007201 }
7202
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007203 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Sunil Duttd30ce092018-01-11 23:56:29 +05307204 sizeof(result)) < 0 ||
7205 strncmp(result, "COMPLETED", 9) != 0) {
7206 sigma_dut_print(dut, DUT_MSG_DEBUG,
7207 "sta_reassoc: Not connected");
7208 fastreassoc = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007209 } else if (dut->sta_ft_ds) {
7210 sigma_dut_print(dut, DUT_MSG_DEBUG,
7211 "sta_reassoc: Use FT-over-DS");
7212 ft_ds = 1;
Sunil Duttd30ce092018-01-11 23:56:29 +05307213 }
7214
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05307215 if (dut->rsne_override) {
7216#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007217 if (get_driver_type(dut) == DRIVER_WCN &&
7218 dut->config_rsnie == 0) {
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05307219 sta_config_params(dut, intf, STA_SET_RSNIE, 1);
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05307220 dut->config_rsnie = 1;
7221 }
7222#endif /* NL80211_SUPPORT */
7223 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
7224 dut->rsne_override);
7225 if (wpa_command(intf, buf) < 0) {
7226 send_resp(dut, conn, SIGMA_ERROR,
7227 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
7228 return 0;
7229 }
7230 }
7231
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007232 if (ft_ds) {
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07007233 if (chan || freq) {
7234 if (!freq)
7235 freq = channel_to_freq(dut, chan);
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007236 if (!freq) {
7237 sigma_dut_print(dut, DUT_MSG_ERROR,
7238 "Invalid channel number provided: %d",
7239 chan);
7240 send_resp(dut, conn, SIGMA_INVALID,
7241 "ErrorCode,Invalid channel number");
7242 goto close_mon_conn;
7243 }
7244 res = snprintf(buf, sizeof(buf),
7245 "SCAN TYPE=ONLY freq=%d", freq);
7246 } else {
7247 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
7248 }
7249 if (res < 0 || res >= (int) sizeof(buf)) {
7250 send_resp(dut, conn, SIGMA_ERROR,
7251 "ErrorCode,snprintf failed");
7252 goto close_mon_conn;
7253 }
7254 if (wpa_command(intf, buf) < 0) {
7255 sigma_dut_print(dut, DUT_MSG_INFO,
7256 "Failed to start scan");
7257 send_resp(dut, conn, SIGMA_ERROR,
7258 "ErrorCode,scan failed");
7259 goto close_mon_conn;
7260 }
7261
7262 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
7263 buf, sizeof(buf));
7264 if (res < 0) {
7265 sigma_dut_print(dut, DUT_MSG_INFO,
7266 "Scan did not complete");
7267 send_resp(dut, conn, SIGMA_ERROR,
7268 "ErrorCode,scan did not complete");
7269 goto close_mon_conn;
7270 }
7271
7272 res = snprintf(buf, sizeof(buf), "FT_DS %s", bssid);
7273 if (res > 0 && res < (int) sizeof(buf))
7274 res = wpa_command(intf, buf);
7275
7276 if (res < 0 || res >= (int) sizeof(buf)) {
7277 send_resp(dut, conn, SIGMA_ERROR,
7278 "errorCode,FT_DS command failed");
7279 status = STATUS_SENT_ERROR;
7280 goto close_mon_conn;
7281 }
7282 } else if (wifi_chip_type == DRIVER_WCN && fastreassoc) {
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07007283 if (chan || freq) {
7284 if (!freq)
7285 freq = channel_to_freq(dut, chan);
Ashwini Patil4c8158f2017-05-25 12:49:21 +05307286 if (!freq) {
7287 sigma_dut_print(dut, DUT_MSG_ERROR,
7288 "Invalid channel number provided: %d",
7289 chan);
7290 send_resp(dut, conn, SIGMA_INVALID,
7291 "ErrorCode,Invalid channel number");
7292 goto close_mon_conn;
7293 }
7294 res = snprintf(buf, sizeof(buf),
7295 "SCAN TYPE=ONLY freq=%d", freq);
7296 } else {
7297 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
7298 }
7299 if (res < 0 || res >= (int) sizeof(buf)) {
7300 send_resp(dut, conn, SIGMA_ERROR,
7301 "ErrorCode,snprintf failed");
7302 goto close_mon_conn;
7303 }
7304 if (wpa_command(intf, buf) < 0) {
7305 sigma_dut_print(dut, DUT_MSG_INFO,
7306 "Failed to start scan");
7307 send_resp(dut, conn, SIGMA_ERROR,
7308 "ErrorCode,scan failed");
7309 goto close_mon_conn;
7310 }
7311
7312 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
7313 buf, sizeof(buf));
7314 if (res < 0) {
7315 sigma_dut_print(dut, DUT_MSG_INFO,
7316 "Scan did not complete");
7317 send_resp(dut, conn, SIGMA_ERROR,
7318 "ErrorCode,scan did not complete");
7319 goto close_mon_conn;
7320 }
7321
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007322 if (set_network(intf, dut->infra_network_id, "bssid", "any")
7323 < 0) {
7324 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
7325 "bssid to any during FASTREASSOC");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007326 status = ERROR_SEND_STATUS;
Ashwini Patil467efef2017-05-25 12:18:27 +05307327 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007328 }
Vinita Maloo54b78cf2020-03-30 12:18:19 +05307329 res = snprintf(buf, sizeof(buf), "FASTREASSOC %s %d",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007330 bssid, chan);
Vinita Maloo54b78cf2020-03-30 12:18:19 +05307331 if (res < 0 || res >= (int) sizeof(buf) ||
7332 wcn_driver_cmd(intf, buf) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007333 send_resp(dut, conn, SIGMA_ERROR,
Vinita Maloo54b78cf2020-03-30 12:18:19 +05307334 "errorCode,Failed to run FASTREASSOC");
Ashwini Patil467efef2017-05-25 12:18:27 +05307335 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007336 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007337 sigma_dut_print(dut, DUT_MSG_INFO,
7338 "sta_reassoc: Run %s successful", buf);
7339 } else if (wpa_command(intf, "REASSOCIATE")) {
7340 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
7341 "request reassociation");
Ashwini Patil467efef2017-05-25 12:18:27 +05307342 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007343 }
7344
7345 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
7346 buf, sizeof(buf));
Ashwini Patil467efef2017-05-25 12:18:27 +05307347 if (res < 0) {
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007348 send_resp(dut, conn, SIGMA_ERROR,
7349 "errorCode,Connection did not complete");
7350 status = STATUS_SENT_ERROR;
Ashwini Patil467efef2017-05-25 12:18:27 +05307351 goto close_mon_conn;
7352 }
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007353 status = SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007354
Ashwini Patil467efef2017-05-25 12:18:27 +05307355close_mon_conn:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007356 wpa_ctrl_detach(ctrl);
7357 wpa_ctrl_close(ctrl);
Ashwini Patil467efef2017-05-25 12:18:27 +05307358 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007359}
7360
7361
7362static void hs2_clear_credentials(const char *intf)
7363{
7364 wpa_command(intf, "REMOVE_CRED all");
7365}
7366
7367
Lior Davidcc88b562017-01-03 18:52:09 +02007368#ifdef __linux__
7369static int wil6210_get_aid(struct sigma_dut *dut, const char *bssid,
7370 unsigned int *aid)
7371{
Lior David0fe101e2017-03-09 16:09:50 +02007372 const char *pattern = "AID[ \t]+([0-9]+)";
Lior Davidcc88b562017-01-03 18:52:09 +02007373
Lior David0fe101e2017-03-09 16:09:50 +02007374 return wil6210_get_sta_info_field(dut, bssid, pattern, aid);
Lior Davidcc88b562017-01-03 18:52:09 +02007375}
7376#endif /* __linux__ */
7377
7378
7379static int sta_get_aid_60g(struct sigma_dut *dut, const char *bssid,
7380 unsigned int *aid)
7381{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007382 switch (get_driver_type(dut)) {
Lior Davidcc88b562017-01-03 18:52:09 +02007383#ifdef __linux__
7384 case DRIVER_WIL6210:
7385 return wil6210_get_aid(dut, bssid, aid);
7386#endif /* __linux__ */
7387 default:
7388 sigma_dut_print(dut, DUT_MSG_ERROR, "get AID not supported");
7389 return -1;
7390 }
7391}
7392
7393
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007394static int sta_get_parameter_60g(struct sigma_dut *dut, struct sigma_conn *conn,
7395 struct sigma_cmd *cmd)
7396{
7397 char buf[MAX_CMD_LEN];
7398 char bss_list[MAX_CMD_LEN];
7399 const char *parameter = get_param(cmd, "Parameter");
7400
7401 if (parameter == NULL)
7402 return -1;
7403
Lior Davidcc88b562017-01-03 18:52:09 +02007404 if (strcasecmp(parameter, "AID") == 0) {
7405 unsigned int aid = 0;
7406 char bssid[20];
7407
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007408 if (get_wpa_status(get_station_ifname(dut), "bssid",
Lior Davidcc88b562017-01-03 18:52:09 +02007409 bssid, sizeof(bssid)) < 0) {
7410 sigma_dut_print(dut, DUT_MSG_ERROR,
7411 "could not get bssid");
7412 return -2;
7413 }
7414
7415 if (sta_get_aid_60g(dut, bssid, &aid))
7416 return -2;
7417
7418 snprintf(buf, sizeof(buf), "aid,%d", aid);
7419 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
7420 send_resp(dut, conn, SIGMA_COMPLETE, buf);
7421 return 0;
7422 }
7423
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007424 if (strcasecmp(parameter, "DiscoveredDevList") == 0) {
7425 char *bss_line;
7426 char *bss_id = NULL;
7427 const char *ifname = get_param(cmd, "Interface");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05307428 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007429
7430 if (ifname == NULL) {
7431 sigma_dut_print(dut, DUT_MSG_INFO,
7432 "For get DiscoveredDevList need Interface name.");
7433 return -1;
7434 }
7435
7436 /*
7437 * Use "BSS RANGE=ALL MASK=0x2" which provides a list
7438 * of BSSIDs in "bssid=<BSSID>\n"
7439 */
7440 if (wpa_command_resp(ifname, "BSS RANGE=ALL MASK=0x2",
7441 bss_list,
7442 sizeof(bss_list)) < 0) {
7443 sigma_dut_print(dut, DUT_MSG_ERROR,
7444 "Failed to get bss list");
7445 return -1;
7446 }
7447
7448 sigma_dut_print(dut, DUT_MSG_DEBUG,
7449 "bss list for ifname:%s is:%s",
7450 ifname, bss_list);
7451
7452 snprintf(buf, sizeof(buf), "DeviceList");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05307453 bss_line = strtok_r(bss_list, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007454 while (bss_line) {
7455 if (sscanf(bss_line, "bssid=%ms", &bss_id) > 0 &&
7456 bss_id) {
7457 int len;
7458
7459 len = snprintf(buf + strlen(buf),
7460 sizeof(buf) - strlen(buf),
7461 ",%s", bss_id);
7462 free(bss_id);
7463 bss_id = NULL;
7464 if (len < 0) {
7465 sigma_dut_print(dut,
7466 DUT_MSG_ERROR,
7467 "Failed to read BSSID");
7468 send_resp(dut, conn, SIGMA_ERROR,
7469 "ErrorCode,Failed to read BSS ID");
7470 return 0;
7471 }
7472
7473 if ((size_t) len >= sizeof(buf) - strlen(buf)) {
7474 sigma_dut_print(dut,
7475 DUT_MSG_ERROR,
7476 "Response buf too small for list");
7477 send_resp(dut, conn,
7478 SIGMA_ERROR,
7479 "ErrorCode,Response buf too small for list");
7480 return 0;
7481 }
7482 }
7483
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05307484 bss_line = strtok_r(NULL, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007485 }
7486
7487 sigma_dut_print(dut, DUT_MSG_INFO, "DiscoveredDevList is %s",
7488 buf);
7489 send_resp(dut, conn, SIGMA_COMPLETE, buf);
7490 return 0;
7491 }
7492
7493 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7494 return 0;
7495}
7496
7497
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07007498static int sta_get_parameter_he(struct sigma_dut *dut, struct sigma_conn *conn,
7499 struct sigma_cmd *cmd)
7500{
7501 char buf[MAX_CMD_LEN];
7502 const char *parameter = get_param(cmd, "Parameter");
7503
7504 if (!parameter)
7505 return -1;
7506
7507 if (strcasecmp(parameter, "RSSI") == 0) {
7508 char rssi[10];
7509
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007510 if (get_wpa_signal_poll(dut, get_station_ifname(dut), "RSSI",
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07007511 rssi, sizeof(rssi)) < 0) {
7512 sigma_dut_print(dut, DUT_MSG_ERROR,
7513 "Could not get RSSI");
7514 return -2;
7515 }
7516
7517 snprintf(buf, sizeof(buf), "rssi,%s", rssi);
7518 sigma_dut_print(dut, DUT_MSG_INFO, "RSSI %s", buf);
7519 send_resp(dut, conn, SIGMA_COMPLETE, buf);
7520 return 0;
7521 }
7522
7523 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7524 return 0;
7525}
7526
7527
Veerendranath Jakkamd0ad6ef2020-05-21 17:09:26 +05307528#ifdef NL80211_SUPPORT
7529
7530struct station_info {
7531 uint64_t filled;
7532 uint32_t beacon_mic_error_count;
7533 uint32_t beacon_replay_count;
7534};
7535
7536
7537static int qca_get_sta_info_handler(struct nl_msg *msg, void *arg)
7538{
7539 struct nlattr *tb[NL80211_ATTR_MAX + 1];
7540 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
7541 struct station_info *data = arg;
7542 struct nlattr *info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_MAX + 1];
7543 static struct nla_policy info_policy[
7544 QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_MAX + 1] = {
7545 [QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT] = {
7546 .type = NLA_U32
7547 },
7548 [QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT] = {
7549 .type = NLA_U32
7550 },
7551 };
7552
7553 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
7554 genlmsg_attrlen(gnlh, 0), NULL);
7555
7556 if (!tb[NL80211_ATTR_VENDOR_DATA])
7557 return NL_SKIP;
7558
7559 if (nla_parse_nested(info, QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_MAX,
7560 tb[NL80211_ATTR_VENDOR_DATA], info_policy)) {
7561 return NL_SKIP;
7562 }
7563
7564 if (info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT]) {
7565 data->filled |=
7566 BIT_ULL(QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT);
7567 data->beacon_mic_error_count =
7568 nla_get_u32(info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT]);
7569 }
7570
7571 if (info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT]) {
7572 data->filled |=
7573 BIT_ULL(QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT);
7574 data->beacon_replay_count =
7575 nla_get_u32(info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT]);
7576 }
7577
7578 return NL_SKIP;
7579}
7580
7581
7582static int qca_nl80211_get_sta_info(struct sigma_dut *dut, const char *intf,
7583 struct station_info *sta_data)
7584{
7585 struct nl_msg *msg;
7586 int ifindex, ret;
7587
7588 ifindex = if_nametoindex(intf);
7589 if (ifindex == 0) {
7590 sigma_dut_print(dut, DUT_MSG_ERROR,
7591 "%s: Index for interface %s not found",
7592 __func__, intf);
7593 return -1;
7594 }
7595
7596 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7597 NL80211_CMD_VENDOR)) ||
7598 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7599 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7600 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7601 QCA_NL80211_VENDOR_SUBCMD_GET_STA_INFO)) {
7602 sigma_dut_print(dut, DUT_MSG_ERROR,
7603 "%s: err in adding vendor_cmd", __func__);
7604 nlmsg_free(msg);
7605 return -1;
7606 }
7607
7608 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg,
7609 qca_get_sta_info_handler, sta_data);
7610 if (ret) {
7611 sigma_dut_print(dut, DUT_MSG_ERROR,
7612 "%s: err in send_and_recv_msgs, ret=%d",
7613 __func__, ret);
7614 }
7615 return ret;
7616}
7617#endif /* NL80211_SUPPORT */
7618
7619
7620static int get_bip_mic_error_count(struct sigma_dut *dut,
7621 const char *ifname,
7622 unsigned int *count)
7623{
7624#ifdef NL80211_SUPPORT
7625 struct station_info sta_data;
7626#endif /* NL80211_SUPPORT */
7627
7628 if (get_driver_type(dut) != DRIVER_WCN) {
7629 sigma_dut_print(dut, DUT_MSG_ERROR,
7630 "BIP MIC error count not supported");
7631 return -1;
7632 }
7633
7634#ifdef NL80211_SUPPORT
7635 if (qca_nl80211_get_sta_info(dut, ifname, &sta_data) != 0 ||
7636 !(sta_data.filled &
7637 BIT_ULL(QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT))) {
7638 sigma_dut_print(dut, DUT_MSG_ERROR,
7639 "BIP MIC error count fetching failed");
7640 return -1;
7641 }
7642
7643 *count = sta_data.beacon_mic_error_count;
7644 return 0;
7645#else /* NL80211_SUPPORT */
7646 sigma_dut_print(dut, DUT_MSG_ERROR,
7647 "BIP MIC error count cannot be fetched without NL80211_SUPPORT defined");
7648 return -1;
7649#endif /* NL80211_SUPPORT */
7650}
7651
7652
7653static int get_cmac_replay_count(struct sigma_dut *dut, const char *ifname,
7654 unsigned int *count)
7655{
7656#ifdef NL80211_SUPPORT
7657 struct station_info sta_data;
7658#endif /* NL80211_SUPPORT */
7659
7660 if (get_driver_type(dut) != DRIVER_WCN) {
7661 sigma_dut_print(dut, DUT_MSG_ERROR,
7662 "CMAC reply count not supported");
7663 return -1;
7664 }
7665
7666#ifdef NL80211_SUPPORT
7667 if (qca_nl80211_get_sta_info(dut, ifname, &sta_data) != 0 ||
7668 !(sta_data.filled &
7669 BIT_ULL(QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT))) {
7670 sigma_dut_print(dut, DUT_MSG_ERROR,
7671 "CMAC replay count fetching failed");
7672 return -1;
7673 }
7674
7675 *count = sta_data.beacon_replay_count;
7676 return 0;
7677#else /* NL80211_SUPPORT */
7678 sigma_dut_print(dut, DUT_MSG_ERROR,
7679 "CMAC replay count cannot be fetched without NL80211_SUPPORT defined");
7680 return -1;
7681#endif /* NL80211_SUPPORT */
7682}
7683
7684
7685static enum sigma_cmd_result sta_get_parameter_wpa3(struct sigma_dut *dut,
7686 struct sigma_conn *conn,
7687 struct sigma_cmd *cmd)
7688{
7689 char buf[MAX_CMD_LEN];
7690 const char *ifname = get_param(cmd, "interface");
7691 const char *parameter = get_param(cmd, "Parameter");
7692 unsigned int val;
7693
7694 if (!ifname || !parameter)
7695 return INVALID_SEND_STATUS;
7696
7697 if (strcasecmp(parameter, "BIPMICErrors") == 0) {
7698 if (get_bip_mic_error_count(dut, ifname, &val)) {
7699 send_resp(dut, conn, SIGMA_ERROR,
7700 "ErrorCode,Failed to get BIPMICErrors");
7701 return STATUS_SENT_ERROR;
7702 }
7703 snprintf(buf, sizeof(buf), "BIPMICErrors,%d", val);
7704 sigma_dut_print(dut, DUT_MSG_INFO, "BIPMICErrors %s", buf);
7705 send_resp(dut, conn, SIGMA_COMPLETE, buf);
7706 return STATUS_SENT;
7707 }
7708
7709 if (strcasecmp(parameter, "CMACReplays") == 0) {
7710 if (get_cmac_replay_count(dut, ifname, &val)) {
7711 send_resp(dut, conn, SIGMA_ERROR,
7712 "ErrorCode,Failed to get CMACReplays");
7713 return STATUS_SENT_ERROR;
7714 }
7715 snprintf(buf, sizeof(buf), "CMACReplays,%d", val);
7716 sigma_dut_print(dut, DUT_MSG_INFO, "CMACReplays %s", buf);
7717 send_resp(dut, conn, SIGMA_COMPLETE, buf);
7718 return STATUS_SENT;
7719 }
7720
7721 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7722 return STATUS_SENT_ERROR;
7723}
7724
7725
Jouni Malinenca0abd32020-02-09 20:18:10 +02007726static enum sigma_cmd_result sta_get_pmk(struct sigma_dut *dut,
7727 struct sigma_conn *conn,
7728 struct sigma_cmd *cmd)
7729{
7730 const char *intf = get_param(cmd, "Interface");
7731 char buf[4096], bssid[20], resp[200], *pos, *tmp;
7732
7733 snprintf(buf, sizeof(buf), "PMKSA_GET %d", dut->infra_network_id);
7734 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
7735 strncmp(buf, "UNKNOWN COMMAND", 15) == 0) {
7736 send_resp(dut, conn, SIGMA_ERROR,
7737 "ErrorCode,PMKSA_GET not supported");
7738 return STATUS_SENT_ERROR;
7739 }
7740
7741 if (strncmp(buf, "FAIL", 4) == 0 ||
7742 get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
7743 send_resp(dut, conn, SIGMA_ERROR,
7744 "ErrorCode,Could not find current network");
7745 return STATUS_SENT_ERROR;
7746 }
7747
7748 pos = buf;
7749 while (pos) {
7750 if (strncmp(pos, bssid, 17) == 0) {
7751 pos = strchr(pos, ' ');
7752 if (!pos)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05307753 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02007754 pos++;
7755 pos = strchr(pos, ' ');
7756 if (!pos)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05307757 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02007758 pos++;
7759 tmp = strchr(pos, ' ');
7760 if (!tmp)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05307761 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02007762 *tmp = '\0';
7763 break;
7764 }
Jouni Malinenca0abd32020-02-09 20:18:10 +02007765 pos = strchr(pos, '\n');
7766 if (pos)
7767 pos++;
7768 }
7769
7770 if (!pos) {
7771 send_resp(dut, conn, SIGMA_ERROR,
7772 "ErrorCode,PMK not available");
7773 return STATUS_SENT_ERROR;
7774 }
7775
7776 snprintf(resp, sizeof(resp), "PMK,%s", pos);
7777 send_resp(dut, conn, SIGMA_COMPLETE, resp);
7778 return STATUS_SENT;
7779}
7780
7781
Jouni Malinenf7222712019-06-13 01:50:21 +03007782static enum sigma_cmd_result cmd_sta_get_parameter(struct sigma_dut *dut,
7783 struct sigma_conn *conn,
7784 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007785{
7786 const char *program = get_param(cmd, "Program");
Jouni Malinenca0abd32020-02-09 20:18:10 +02007787 const char *parameter = get_param(cmd, "Parameter");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007788
Jouni Malinenca0abd32020-02-09 20:18:10 +02007789 if (!parameter)
7790 return INVALID_SEND_STATUS;
7791
7792 if (strcasecmp(parameter, "PMK") == 0)
7793 return sta_get_pmk(dut, conn, cmd);
7794
7795 if (!program)
7796 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007797
7798 if (strcasecmp(program, "P2PNFC") == 0)
7799 return p2p_cmd_sta_get_parameter(dut, conn, cmd);
7800
7801 if (strcasecmp(program, "60ghz") == 0)
7802 return sta_get_parameter_60g(dut, conn, cmd);
7803
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07007804 if (strcasecmp(program, "he") == 0)
7805 return sta_get_parameter_he(dut, conn, cmd);
7806
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007807#ifdef ANDROID_NAN
7808 if (strcasecmp(program, "NAN") == 0)
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07007809 return nan_cmd_sta_get_parameter(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007810#endif /* ANDROID_NAN */
7811
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007812#ifdef MIRACAST
7813 if (strcasecmp(program, "WFD") == 0 ||
7814 strcasecmp(program, "DisplayR2") == 0)
7815 return miracast_cmd_sta_get_parameter(dut, conn, cmd);
7816#endif /* MIRACAST */
Veerendranath Jakkamd0ad6ef2020-05-21 17:09:26 +05307817 if (strcasecmp(program, "WPA3") == 0)
7818 return sta_get_parameter_wpa3(dut, conn, cmd);
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007819
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007820 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7821 return 0;
7822}
7823
7824
7825static void sta_reset_default_ath(struct sigma_dut *dut, const char *intf,
7826 const char *type)
7827{
7828 char buf[100];
7829
7830 if (dut->program == PROGRAM_VHT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007831 run_iwpriv(dut, intf, "chwidth 2");
7832 run_iwpriv(dut, intf, "mode 11ACVHT80");
7833 run_iwpriv(dut, intf, "vhtmcs -1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007834 }
7835
7836 if (dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007837 run_iwpriv(dut, intf, "chwidth 0");
7838 run_iwpriv(dut, intf, "mode 11naht40");
7839 run_iwpriv(dut, intf, "set11NRates 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007840 }
7841
7842 if (dut->program == PROGRAM_VHT || dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007843 run_iwpriv(dut, intf, "powersave 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007844
7845 /* Reset CTS width */
7846 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 54 0",
7847 intf);
7848 if (system(buf) != 0) {
7849 sigma_dut_print(dut, DUT_MSG_ERROR,
7850 "wifitool %s beeliner_fw_test 54 0 failed",
7851 intf);
7852 }
7853
7854 /* Enable Dynamic Bandwidth signalling by default */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007855 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007856
7857 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", intf);
7858 if (system(buf) != 0) {
7859 sigma_dut_print(dut, DUT_MSG_ERROR,
7860 "iwpriv rts failed");
7861 }
7862 }
7863
7864 if (type && strcasecmp(type, "Testbed") == 0) {
7865 dut->testbed_flag_txsp = 1;
7866 dut->testbed_flag_rxsp = 1;
7867 /* STA has to set spatial stream to 2 per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007868 run_iwpriv(dut, intf, "vht_mcsmap 0xfff0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007869
7870 /* Disable LDPC per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007871 run_iwpriv(dut, intf, "ldpc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007872
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007873 run_iwpriv(dut, intf, "amsdu 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007874
7875 /* TODO: Disable STBC 2x1 transmit and receive */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007876 run_iwpriv(dut, intf, "tx_stbc 0");
7877 run_iwpriv(dut, intf, "rx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007878
7879 /* STA has to disable Short GI per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007880 run_iwpriv(dut, intf, "shortgi 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007881 }
7882
7883 if (type && strcasecmp(type, "DUT") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007884 run_iwpriv(dut, intf, "nss 3");
Arif Hussainac6c5112018-05-25 17:34:00 -07007885 dut->sta_nss = 3;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007886
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007887 run_iwpriv(dut, intf, "shortgi 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007888 }
7889}
7890
7891
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007892#ifdef NL80211_SUPPORT
7893static int sta_set_he_mcs(struct sigma_dut *dut, const char *intf,
7894 enum he_mcs_config mcs)
7895{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307896 return wcn_wifi_test_config_set_u8(
7897 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MCS, mcs);
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007898}
7899#endif /* NL80211_SUPPORT */
7900
7901
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07007902static int sta_set_action_tx_in_he_tb_ppdu(struct sigma_dut *dut,
7903 const char *intf, int enable)
7904{
7905#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307906 return wcn_wifi_test_config_set_u8(
7907 dut, intf,
7908 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_ACTION_TX_TB_PPDU,
7909 enable);
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07007910#else /* NL80211_SUPPORT */
7911 sigma_dut_print(dut, DUT_MSG_ERROR,
7912 "HE action Tx TB PPDU cannot be set without NL80211_SUPPORT defined");
7913 return -1;
7914#endif /* NL80211_SUPPORT */
7915}
7916
7917
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08007918static int sta_set_heconfig_and_wep_tkip(struct sigma_dut *dut,
7919 const char *intf, int enable)
7920{
7921#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307922 return wcn_wifi_test_config_set_u8(
7923 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WEP_TKIP_IN_HE,
7924 enable);
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08007925#else /* NL80211_SUPPORT */
7926 sigma_dut_print(dut, DUT_MSG_ERROR,
7927 "HE config enablement cannot be changed without NL80211_SUPPORT defined");
7928 return -1;
7929#endif /* NL80211_SUPPORT */
7930}
7931
7932
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007933#ifdef NL80211_SUPPORT
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007934
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007935static int sta_set_he_testbed_def(struct sigma_dut *dut,
7936 const char *intf, int cfg)
7937{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307938 return wcn_wifi_test_config_set_u8(
7939 dut, intf,
7940 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SET_HE_TESTBED_DEFAULTS,
7941 cfg);
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007942}
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007943
7944
7945static int sta_set_2g_vht_supp(struct sigma_dut *dut, const char *intf, int cfg)
7946{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307947 return wcn_wifi_test_config_set_u8(
7948 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_2G_VHT,
7949 cfg);
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007950}
7951
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007952#endif /* NL80211_SUPPORT */
7953
7954
Qiwei Caib6806972020-01-15 13:52:11 +08007955int sta_set_addba_buf_size(struct sigma_dut *dut,
7956 const char *intf, int bufsize)
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007957{
7958#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307959 return wcn_wifi_test_config_set_u16(
7960 dut, intf,
7961 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE, bufsize);
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007962#else /* NL80211_SUPPORT */
7963 sigma_dut_print(dut, DUT_MSG_ERROR,
7964 "AddBA bufsize cannot be changed without NL80211_SUPPORT defined");
7965 return -1;
7966#endif /* NL80211_SUPPORT */
7967}
7968
7969
Kiran Kumar Lokere69d89952021-08-08 23:41:46 -07007970static int sta_set_scan_unicast_probe(struct sigma_dut *dut,
7971 const char *intf, int val)
7972{
7973#ifdef NL80211_SUPPORT
7974 return wcn_wifi_test_config_set_u8(
7975 dut, intf,
7976 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_USE_BSSID_IN_PROBE_REQ_RA,
7977 val);
7978#else /* NL80211_SUPPORT */
7979 sigma_dut_print(dut, DUT_MSG_ERROR,
7980 "Unicast RA in Probe Request frame cannot be set without NL80211_SUPPORT defined");
7981 return -1;
7982#endif /* NL80211_SUPPORT */
7983}
7984
7985
Kiran Kumar Lokere09dbcef2021-08-09 00:01:41 -07007986static int sta_set_rx_ctrl_multi_bss(struct sigma_dut *dut, const char *intf,
7987 int enable)
7988{
7989#ifdef NL80211_SUPPORT
7990 return wcn_wifi_test_config_set_u8(
7991 dut, intf,
7992 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_RX_CTRL_FRAME_TO_MBSS,
7993 enable);
7994#else /* NL80211_SUPPORT */
7995 sigma_dut_print(dut, DUT_MSG_ERROR,
7996 "Rx ctrl frame to Multi-BSS cannot be changed without NL80211_SUPPORT defined");
7997 return -1;
7998#endif /* NL80211_SUPPORT */
7999}
8000
8001
8002static int sta_set_bcast_twt_support(struct sigma_dut *dut, const char *intf,
8003 int enable)
8004{
8005#ifdef NL80211_SUPPORT
8006 return wcn_wifi_test_config_set_u8(
8007 dut, intf,
8008 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BCAST_TWT_SUPPORT,
8009 enable);
8010#else /* NL80211_SUPPORT */
8011 sigma_dut_print(dut, DUT_MSG_ERROR,
8012 "BCAST TWT cannot be changed without NL80211_SUPPORT defined");
8013 return -1;
8014#endif /* NL80211_SUPPORT */
8015}
8016
8017
Arif Hussain8d5b27b2018-05-14 14:31:03 -07008018static int sta_set_tx_beamformee(struct sigma_dut *dut, const char *intf,
8019 int enable)
8020{
8021#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05308022 return wcn_wifi_test_config_set_u8(
8023 dut, intf,
8024 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_TX_BEAMFORMEE,
8025 enable);
Arif Hussain8d5b27b2018-05-14 14:31:03 -07008026#else /* NL80211_SUPPORT */
8027 sigma_dut_print(dut, DUT_MSG_ERROR,
8028 "tx beamformee cannot be changed without NL80211_SUPPORT defined");
8029 return -1;
8030#endif /* NL80211_SUPPORT */
8031}
8032
8033
Arif Hussain9765f7d2018-07-03 08:28:26 -07008034static int sta_set_beamformee_sts(struct sigma_dut *dut, const char *intf,
8035 int val)
8036{
8037#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05308038 return wcn_wifi_test_config_set_u8(
8039 dut, intf,
8040 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_BEAMFORMEE_NSTS,
8041 val);
Arif Hussain9765f7d2018-07-03 08:28:26 -07008042#else /* NL80211_SUPPORT */
8043 sigma_dut_print(dut, DUT_MSG_ERROR,
8044 "beamformee sts cannot be changed without NL80211_SUPPORT defined");
8045 return -1;
8046#endif /* NL80211_SUPPORT */
8047}
8048
8049
Arif Hussain68d23f52018-07-11 13:39:08 -07008050#ifdef NL80211_SUPPORT
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07008051static int sta_set_mac_padding_duration(struct sigma_dut *dut, const char *intf,
8052 enum qca_wlan_he_mac_padding_dur val)
8053{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05308054 return wcn_wifi_test_config_set_u8(
8055 dut, intf,
8056 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MAC_PADDING_DUR, val);
Arif Hussain68d23f52018-07-11 13:39:08 -07008057}
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07008058#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07008059
8060
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07008061static int sta_set_tx_su_ppdu_cfg(struct sigma_dut *dut, const char *intf,
8062 int val)
8063{
8064#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05308065 return wcn_wifi_test_config_set_u8(
8066 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_SUPPDU,
8067 val);
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07008068#else /* NL80211_SUPPORT */
8069 sigma_dut_print(dut, DUT_MSG_ERROR,
8070 "Tx SU PPDU cannot be set without NL80211_SUPPORT defined");
8071 return -1;
8072#endif /* NL80211_SUPPORT */
8073}
8074
8075
Kiran Kumar Lokere54b72522021-04-01 00:22:44 -07008076static int sta_set_mgmt_data_tx_disable_cfg(struct sigma_dut *dut,
8077 const char *intf, int val)
8078{
8079#ifdef NL80211_SUPPORT
8080 return wcn_wifi_test_config_set_u8(
8081 dut, intf,
8082 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_DISABLE_DATA_MGMT_RSP_TX,
8083 val);
8084#else /* NL80211_SUPPORT */
8085 sigma_dut_print(dut, DUT_MSG_ERROR,
8086 "Tx disable config cannot be set without NL80211_SUPPORT defined");
8087 return -1;
8088#endif /* NL80211_SUPPORT */
8089}
8090
8091
Kiran Kumar Lokere1809da12021-06-24 00:45:38 -07008092static int sta_set_keep_alive_data_cfg(struct sigma_dut *dut, const char *intf,
8093 int val)
8094{
8095#ifdef NL80211_SUPPORT
8096 return wcn_wifi_test_config_set_u8(
8097 dut, intf,
8098 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_KEEP_ALIVE_FRAME_TYPE,
8099 val);
8100#else /* NL80211_SUPPORT */
8101 sigma_dut_print(dut, DUT_MSG_ERROR,
8102 "Keep alive data type cannot be set without NL80211_SUPPORT defined");
8103 return -1;
8104#endif /* NL80211_SUPPORT */
8105}
8106
8107
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07008108#ifdef NL80211_SUPPORT
8109static int sta_set_he_om_ctrl_reset(struct sigma_dut *dut, const char *intf)
8110{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05308111 return wcn_wifi_test_config_set_flag(
8112 dut, intf,
8113 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_CLEAR_HE_OM_CTRL_CONFIG);
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07008114}
8115#endif /* NL80211_SUPPORT */
8116
8117
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07008118static int sta_set_mu_edca_override(struct sigma_dut *dut, const char *intf,
8119 int val)
8120{
8121#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05308122 return wcn_wifi_test_config_set_u8(
8123 dut, intf,
8124 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_OVERRIDE_MU_EDCA, val);
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07008125#else /* NL80211_SUPPORT */
8126 sigma_dut_print(dut, DUT_MSG_ERROR,
8127 "MU EDCA override cannot be changed without NL80211_SUPPORT defined");
8128 return -1;
8129#endif /* NL80211_SUPPORT */
8130}
8131
8132
Kiran Kumar Lokerefa7c7b92021-08-09 00:50:55 -07008133static int sta_set_er_su_ppdu_type_tx(struct sigma_dut *dut, const char *intf,
8134 int val)
8135{
8136#ifdef NL80211_SUPPORT
8137 return wcn_wifi_test_config_set_u8(
8138 dut, intf,
8139 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ER_SU_PPDU_TYPE, val);
8140#else /* NL80211_SUPPORT */
8141 sigma_dut_print(dut, DUT_MSG_ERROR,
8142 "ER-SU PPDU type cannot be set without NL80211_SUPPORT defined");
8143 return -1;
8144#endif /* NL80211_SUPPORT */
8145}
8146
8147
8148static int sta_set_ru_242_tone_tx(struct sigma_dut *dut, const char *intf,
8149 int val)
8150{
8151#ifdef NL80211_SUPPORT
8152 return wcn_wifi_test_config_set_u8(
8153 dut, intf,
8154 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_RU_242_TONE_TX, val);
8155#else /* NL80211_SUPPORT */
8156 sigma_dut_print(dut, DUT_MSG_ERROR,
8157 "RU 242 tone cannot be set without NL80211_SUPPORT defined");
8158 return -1;
8159#endif /* NL80211_SUPPORT */
8160}
8161
8162
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07008163static int sta_set_om_ctrl_supp(struct sigma_dut *dut, const char *intf,
8164 int val)
8165{
8166#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05308167 return wcn_wifi_test_config_set_u8(
8168 dut, intf,
8169 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OM_CTRL_SUPP, val);
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07008170#else /* NL80211_SUPPORT */
8171 sigma_dut_print(dut, DUT_MSG_ERROR,
8172 "HE OM ctrl cannot be changed without NL80211_SUPPORT defined");
8173 return -1;
8174#endif /* NL80211_SUPPORT */
8175}
8176
8177
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07008178#ifdef NL80211_SUPPORT
8179
8180struct features_info {
8181 unsigned char flags[8];
8182 size_t flags_len;
8183};
8184
8185static int features_info_handler(struct nl_msg *msg, void *arg)
8186{
8187 struct nlattr *tb[NL80211_ATTR_MAX + 1];
8188 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
8189 struct features_info *info = arg;
8190 struct nlattr *nl_vend, *attr;
8191
8192 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
8193 genlmsg_attrlen(gnlh, 0), NULL);
8194
8195 nl_vend = tb[NL80211_ATTR_VENDOR_DATA];
8196 if (nl_vend) {
8197 struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1];
8198
8199 nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX,
8200 nla_data(nl_vend), nla_len(nl_vend), NULL);
8201
8202 attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_FEATURE_FLAGS];
8203 if (attr) {
8204 int len = nla_len(attr);
8205
Vamsi Krishna79a91132021-08-16 21:40:22 +05308206 if (info && len <= sizeof(info->flags)) {
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07008207 memcpy(info->flags, nla_data(attr), len);
8208 info->flags_len = len;
8209 }
8210 }
8211 }
8212
8213 return NL_SKIP;
8214}
8215
8216
8217static int check_feature(enum qca_wlan_vendor_features feature,
8218 struct features_info *info)
8219{
8220 size_t idx = feature / 8;
8221
Vamsi Krishna79a91132021-08-16 21:40:22 +05308222 if (!info)
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07008223 return 0;
8224
8225 return (idx < info->flags_len) &&
8226 (info->flags[idx] & BIT(feature % 8));
8227}
8228
8229#endif /* NL80211_SUPPORT */
8230
8231
8232static void sta_get_twt_feature_async_supp(struct sigma_dut *dut,
8233 const char *intf)
8234{
8235#ifdef NL80211_SUPPORT
8236 struct nl_msg *msg;
8237 struct features_info info = { 0 };
8238 int ifindex, ret;
8239
8240 ifindex = if_nametoindex(intf);
8241 if (ifindex == 0) {
8242 sigma_dut_print(dut, DUT_MSG_ERROR,
8243 "%s: Index for interface %s failed",
8244 __func__, intf);
8245 return;
8246 }
8247
8248 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8249 NL80211_CMD_VENDOR)) ||
8250 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8251 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8252 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8253 QCA_NL80211_VENDOR_SUBCMD_GET_FEATURES)) {
8254 sigma_dut_print(dut, DUT_MSG_ERROR,
8255 "%s: err in adding vendor_cmd and vendor_data",
8256 __func__);
8257 nlmsg_free(msg);
8258 return;
8259 }
8260
8261 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, features_info_handler,
8262 &info);
8263 if (ret) {
8264 sigma_dut_print(dut, DUT_MSG_ERROR,
8265 "%s: err in send_and_recv_msgs, ret=%d",
8266 __func__, ret);
8267 return;
8268 }
8269
8270 if (check_feature(QCA_WLAN_VENDOR_FEATURE_TWT_ASYNC_SUPPORT, &info))
8271 dut->sta_async_twt_supp = 1;
8272 else
8273 dut->sta_async_twt_supp = 0;
8274
8275 sigma_dut_print(dut, DUT_MSG_DEBUG,
8276 "%s: sta_async_twt_supp %d",
8277 __func__, dut->sta_async_twt_supp);
8278#else /* NL80211_SUPPORT */
8279 sigma_dut_print(dut, DUT_MSG_INFO,
8280 "TWT async supp get cannot be done without NL80211_SUPPORT defined");
8281 dut->sta_async_twt_supp = 0;
8282#endif /* NL80211_SUPPORT */
8283}
8284
8285
Arif Hussain480d5f42019-03-12 14:40:42 -07008286static int sta_set_twt_req_support(struct sigma_dut *dut, const char *intf,
8287 int val)
8288{
8289#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05308290 return wcn_wifi_test_config_set_u8(
8291 dut, intf,
8292 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TWT_REQ_SUPPORT, val);
Arif Hussain480d5f42019-03-12 14:40:42 -07008293#else /* NL80211_SUPPORT */
8294 sigma_dut_print(dut, DUT_MSG_ERROR,
8295 "TWT Request cannot be changed without NL80211_SUPPORT defined");
8296 return -1;
8297#endif /* NL80211_SUPPORT */
8298}
8299
8300
Kiran Kumar Lokere4f2d4b02021-04-01 00:07:39 -07008301static int sta_set_bss_max_idle_period(struct sigma_dut *dut, const char *intf,
8302 int val)
8303{
8304#ifdef NL80211_SUPPORT
8305 return wcn_wifi_test_config_set_u16(
8306 dut, intf,
8307 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BSS_MAX_IDLE_PERIOD, val);
8308#else /* NL80211_SUPPORT */
8309 sigma_dut_print(dut, DUT_MSG_ERROR,
8310 "BSS max idle period cannot be set without NL80211_SUPPORT defined");
8311 return -1;
8312#endif /* NL80211_SUPPORT */
8313}
8314
8315
Kiran Kumar Lokere07ad92b2021-08-09 00:27:14 -07008316static int sta_set_bss_max_idle_support(struct sigma_dut *dut, const char *intf,
8317 int val)
8318{
8319#ifdef NL80211_SUPPORT
8320 return wcn_wifi_test_config_set_u8(
8321 dut, intf,
8322 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BSS_MAX_IDLE_PERIOD_ENABLE,
8323 val);
8324#else /* NL80211_SUPPORT */
8325 sigma_dut_print(dut, DUT_MSG_ERROR,
8326 "BSS max idle support cannot be set without NL80211_SUPPORT defined");
8327 return -1;
8328#endif /* NL80211_SUPPORT */
8329}
8330
8331
Srinivas Girigowda0525e292020-11-12 13:28:21 -08008332static int sta_set_fullbw_ulmumimo(struct sigma_dut *dut, const char *intf,
8333 int val)
8334{
8335#ifdef NL80211_SUPPORT
8336 return wcn_wifi_test_config_set_u8(
8337 dut, intf,
8338 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_FULL_BW_UL_MU_MIMO, val);
8339#else /* NL80211_SUPPORT */
8340 sigma_dut_print(dut, DUT_MSG_ERROR,
8341 "Full BW UL MU MIMO cannot be changed without NL80211_SUPPORT defined");
8342 return -1;
8343#endif /* NL80211_SUPPORT */
8344}
8345
8346
Kiran Kumar Lokered0ec5ed2021-04-01 00:15:04 -07008347static int sta_set_punctured_preamble_rx(struct sigma_dut *dut,
8348 const char *intf, int val)
8349{
8350#ifdef NL80211_SUPPORT
8351 return wcn_wifi_test_config_set_u8(
8352 dut, intf,
8353 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_PUNCTURED_PREAMBLE_RX,
8354 val);
8355#else /* NL80211_SUPPORT */
8356 sigma_dut_print(dut, DUT_MSG_ERROR,
8357 "Punctured preamble Rx cannot be set without NL80211_SUPPORT defined");
8358 return -1;
8359#endif /* NL80211_SUPPORT */
8360}
8361
8362
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08008363static void sta_reset_default_wcn(struct sigma_dut *dut, const char *intf,
8364 const char *type)
8365{
8366 char buf[60];
8367
8368 if (dut->program == PROGRAM_HE) {
8369 /* resetting phymode to auto in case of HE program */
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05308370 sta_set_phymode(dut, intf, "auto");
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08008371
Amarnath Hullur Subramanyam9cecb502018-04-25 13:26:30 -07008372 /* reset the rate to Auto rate */
8373 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0xff",
8374 intf);
8375 if (system(buf) != 0) {
8376 sigma_dut_print(dut, DUT_MSG_ERROR,
8377 "iwpriv %s set_11ax_rate 0xff failed",
8378 intf);
8379 }
8380
Kiran Kumar Lokere86cfe3a2018-06-01 11:55:15 -07008381 /* reset the LDPC setting */
8382 snprintf(buf, sizeof(buf), "iwpriv %s ldpc 1", intf);
8383 if (system(buf) != 0) {
8384 sigma_dut_print(dut, DUT_MSG_ERROR,
8385 "iwpriv %s ldpc 1 failed", intf);
8386 }
8387
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08008388 /* reset the power save setting */
Vinita S. Malooa8b62722020-04-23 01:45:41 +05308389 set_power_save_wcn(dut, intf, 2);
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08008390
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08008391 /* remove all network profiles */
8392 remove_wpa_networks(intf);
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08008393
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08008394 /* Configure ADDBA Req/Rsp buffer size to be 64 */
8395 sta_set_addba_buf_size(dut, intf, 64);
8396
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07008397 if (dut->sta_async_twt_supp == -1)
8398 sta_get_twt_feature_async_supp(dut, intf);
8399
Kiran Kumar Lokere69d89952021-08-08 23:41:46 -07008400 sta_set_scan_unicast_probe(dut, intf, 0);
8401
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08008402#ifdef NL80211_SUPPORT
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08008403 /* Reset the device HE capabilities to its default supported
8404 * configuration. */
8405 sta_set_he_testbed_def(dut, intf, 0);
8406
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08008407 /* Disable noackpolicy for all AC */
8408 if (nlvendor_sta_set_noack(dut, intf, 0, QCA_WLAN_AC_ALL)) {
8409 sigma_dut_print(dut, DUT_MSG_ERROR,
8410 "Disable of noackpolicy for all AC failed");
8411 }
8412#endif /* NL80211_SUPPORT */
8413
Amarnath Hullur Subramanyamb1724a52018-03-07 14:31:46 -08008414 /* Enable WMM by default */
8415 if (wcn_sta_set_wmm(dut, intf, "on")) {
8416 sigma_dut_print(dut, DUT_MSG_ERROR,
8417 "Enable of WMM in sta_reset_default_wcn failed");
8418 }
8419
8420 /* Disable ADDBA_REJECT by default */
8421 if (nlvendor_sta_set_addba_reject(dut, intf, 0)) {
8422 sigma_dut_print(dut, DUT_MSG_ERROR,
8423 "Disable of addba_reject in sta_reset_default_wcn failed");
8424 }
8425
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08008426 /* Enable sending of ADDBA by default */
8427 if (nlvendor_config_send_addba(dut, intf, 1)) {
8428 sigma_dut_print(dut, DUT_MSG_ERROR,
8429 "Enable sending of ADDBA in sta_reset_default_wcn failed");
8430 }
8431
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08008432 /* Enable AMPDU by default */
8433 iwpriv_sta_set_ampdu(dut, intf, 1);
8434
Subhani Shaik8e7a3052018-04-24 14:03:00 -07008435#ifdef NL80211_SUPPORT
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -08008436 if (wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_AUTO)) {
Subhani Shaik8e7a3052018-04-24 14:03:00 -07008437 sigma_dut_print(dut, DUT_MSG_ERROR,
8438 "Set LTF config to default in sta_reset_default_wcn failed");
8439 }
Arif Hussain9765f7d2018-07-03 08:28:26 -07008440
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08008441 /* set the beamformee NSTS(maximum number of
8442 * space-time streams) to default DUT config
8443 */
8444 if (sta_set_beamformee_sts(dut, intf, 7)) {
Arif Hussain9765f7d2018-07-03 08:28:26 -07008445 sigma_dut_print(dut, DUT_MSG_ERROR,
8446 "Failed to set BeamformeeSTS");
8447 }
Arif Hussain68d23f52018-07-11 13:39:08 -07008448
Kiran Kumar Lokere54b72522021-04-01 00:22:44 -07008449 if (sta_set_mgmt_data_tx_disable_cfg(dut, intf, 0)) {
8450 sigma_dut_print(dut, DUT_MSG_ERROR,
8451 "Failed to reset mgmt/data Tx disable config");
8452 }
8453
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07008454 if (sta_set_mac_padding_duration(
8455 dut, intf,
8456 QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07008457 sigma_dut_print(dut, DUT_MSG_ERROR,
8458 "Failed to set MAC padding duration");
8459 }
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07008460
8461 if (sta_set_mu_edca_override(dut, intf, 0)) {
8462 sigma_dut_print(dut, DUT_MSG_ERROR,
8463 "ErrorCode,Failed to set MU EDCA override disable");
8464 }
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07008465
Kiran Kumar Lokerefa7c7b92021-08-09 00:50:55 -07008466 if (sta_set_ru_242_tone_tx(dut, intf, 0)) {
8467 sigma_dut_print(dut, DUT_MSG_ERROR,
8468 "Failed to set RU 242 tone Tx");
8469 }
8470
8471 if (sta_set_er_su_ppdu_type_tx(dut, intf, 0)) {
8472 sigma_dut_print(dut, DUT_MSG_ERROR,
8473 "Failed to set ER-SU PPDU type Tx");
8474 }
8475
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07008476 if (sta_set_om_ctrl_supp(dut, intf, 1)) {
8477 sigma_dut_print(dut, DUT_MSG_ERROR,
8478 "Failed to set OM ctrl supp");
8479 }
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07008480
8481 if (sta_set_tx_su_ppdu_cfg(dut, intf, 1)) {
8482 sigma_dut_print(dut, DUT_MSG_ERROR,
8483 "Failed to set Tx SU PPDU enable");
8484 }
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07008485
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07008486 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 0)) {
8487 sigma_dut_print(dut, DUT_MSG_ERROR,
8488 "failed to send TB PPDU Tx cfg");
8489 }
8490
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07008491 if (sta_set_he_om_ctrl_reset(dut, intf)) {
8492 sigma_dut_print(dut, DUT_MSG_ERROR,
8493 "Failed to set OM ctrl reset");
8494 }
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08008495
8496 /* +HTC-HE support default on */
8497 if (sta_set_he_htc_supp(dut, intf, 1)) {
8498 sigma_dut_print(dut, DUT_MSG_ERROR,
8499 "Setting of +HTC-HE support failed");
8500 }
Subhani Shaik8e7a3052018-04-24 14:03:00 -07008501#endif /* NL80211_SUPPORT */
8502
Arif Hussain8d5b27b2018-05-14 14:31:03 -07008503 if (sta_set_tx_beamformee(dut, intf, 1)) {
8504 sigma_dut_print(dut, DUT_MSG_ERROR,
8505 "Set tx beamformee enable by default in sta_reset_default_wcn failed");
8506 }
8507
Kiran Kumar Lokereb55ff442020-07-15 00:20:40 -07008508 wpa_command(intf, "SET oce 1");
8509
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08008510 /* Set nss to 1 and MCS 0-7 in case of testbed */
8511 if (type && strcasecmp(type, "Testbed") == 0) {
8512#ifdef NL80211_SUPPORT
8513 int ret;
8514#endif /* NL80211_SUPPORT */
8515
Kiran Kumar Lokereb55ff442020-07-15 00:20:40 -07008516 wpa_command(intf, "SET oce 0");
8517
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08008518 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
8519 if (system(buf) != 0) {
8520 sigma_dut_print(dut, DUT_MSG_ERROR,
8521 "iwpriv %s nss failed", intf);
8522 }
8523
8524#ifdef NL80211_SUPPORT
8525 ret = sta_set_he_mcs(dut, intf, HE_80_MCS0_7);
8526 if (ret) {
8527 sigma_dut_print(dut, DUT_MSG_ERROR,
8528 "Setting of MCS failed, ret:%d",
8529 ret);
8530 }
8531#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyamc67621d2018-02-04 23:18:01 -08008532
8533 /* Disable STBC as default */
8534 wcn_sta_set_stbc(dut, intf, "0");
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08008535
8536 /* Disable AMSDU as default */
8537 iwpriv_sta_set_amsdu(dut, intf, "0");
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08008538
8539#ifdef NL80211_SUPPORT
8540 /* HE fragmentation default off */
8541 if (sta_set_he_fragmentation(dut, intf,
8542 HE_FRAG_DISABLE)) {
8543 sigma_dut_print(dut, DUT_MSG_ERROR,
8544 "Setting of HE fragmentation failed");
8545 }
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08008546
8547 /* set the beamformee NSTS(maximum number of
8548 * space-time streams) to default testbed config
8549 */
8550 if (sta_set_beamformee_sts(dut, intf, 3)) {
8551 sigma_dut_print(dut, DUT_MSG_ERROR,
8552 "Failed to set BeamformeeSTS");
8553 }
8554
Kiran Kumar Lokered0ec5ed2021-04-01 00:15:04 -07008555 if (sta_set_punctured_preamble_rx(dut, intf, 0)) {
8556 sigma_dut_print(dut, DUT_MSG_ERROR,
8557 "Failed to reset PreamblePunctRx support");
8558 }
8559
Kiran Kumar Lokere727687f2021-06-24 00:35:49 -07008560 if (sta_set_bss_max_idle_period(dut, intf, 0)) {
8561 sigma_dut_print(dut, DUT_MSG_ERROR,
8562 "Failed to reset BSS max idle period");
8563 }
8564
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08008565 /* +HTC-HE support default off */
8566 if (sta_set_he_htc_supp(dut, intf, 0)) {
8567 sigma_dut_print(dut, DUT_MSG_ERROR,
8568 "Setting of +HTC-HE support failed");
8569 }
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08008570
8571 /* Set device HE capabilities to testbed default
8572 * configuration. */
8573 if (sta_set_he_testbed_def(dut, intf, 1)) {
8574 sigma_dut_print(dut, DUT_MSG_DEBUG,
8575 "Failed to set HE defaults");
8576 }
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08008577
8578 /* Disable VHT support in 2.4 GHz for testbed */
8579 sta_set_2g_vht_supp(dut, intf, 0);
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08008580#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08008581
8582 /* Enable WEP/TKIP with HE capability in testbed */
8583 if (sta_set_heconfig_and_wep_tkip(dut, intf, 1)) {
8584 sigma_dut_print(dut, DUT_MSG_ERROR,
8585 "Enabling HE config with WEP/TKIP failed");
8586 }
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08008587 }
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08008588
8589 /* Defaults in case of DUT */
8590 if (type && strcasecmp(type, "DUT") == 0) {
Arif Hussaind48fcc72018-05-01 18:34:18 -07008591 /* Enable STBC by default */
8592 wcn_sta_set_stbc(dut, intf, "1");
8593
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08008594 /* set nss to 2 */
8595 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
8596 if (system(buf) != 0) {
8597 sigma_dut_print(dut, DUT_MSG_ERROR,
8598 "iwpriv %s nss 2 failed", intf);
8599 }
Arif Hussainac6c5112018-05-25 17:34:00 -07008600 dut->sta_nss = 2;
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08008601
8602#ifdef NL80211_SUPPORT
Arif Hussainae239842018-05-01 18:20:05 -07008603 /* Set HE_MCS to 0-11 */
8604 if (sta_set_he_mcs(dut, intf, HE_80_MCS0_11)) {
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08008605 sigma_dut_print(dut, DUT_MSG_ERROR,
8606 "Setting of MCS failed");
8607 }
8608#endif /* NL80211_SUPPORT */
8609
8610 /* Disable WEP/TKIP with HE capability in DUT */
8611 if (sta_set_heconfig_and_wep_tkip(dut, intf, 0)) {
8612 sigma_dut_print(dut, DUT_MSG_ERROR,
8613 "Enabling HE config with WEP/TKIP failed");
8614 }
8615 }
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08008616 }
8617}
8618
8619
Veerendranath Jakkam47867202020-12-21 01:53:52 +05308620static int sta_set_client_privacy(struct sigma_dut *dut,
8621 struct sigma_conn *conn, const char *intf,
8622 int enable)
8623{
8624 if (enable &&
8625 (wpa_command(intf, "SET mac_addr 1") < 0 ||
8626 wpa_command(intf, "SET rand_addr_lifetime 1") < 0 ||
Veerendranath Jakkam39fd5c42020-12-21 02:02:21 +05308627 (wpa_command(intf, "MAC_RAND_SCAN enable=1 all") < 0 &&
8628 wpa_command(intf, "SET preassoc_mac_addr 1") < 0) ||
Veerendranath Jakkam47867202020-12-21 01:53:52 +05308629 wpa_command(intf, "SET gas_rand_mac_addr 1") < 0 ||
8630 wpa_command(intf, "SET gas_rand_addr_lifetime 1") < 0))
8631 return -1;
8632
8633 if (!enable &&
8634 (wpa_command(intf, "SET mac_addr 0") < 0 ||
Veerendranath Jakkam39fd5c42020-12-21 02:02:21 +05308635 (wpa_command(intf, "MAC_RAND_SCAN enable=0 all") < 0 &&
8636 wpa_command(intf, "SET preassoc_mac_addr 0") < 0) ||
Veerendranath Jakkam47867202020-12-21 01:53:52 +05308637 wpa_command(intf, "SET gas_rand_mac_addr 0") < 0))
8638 return -1;
8639
8640 dut->client_privacy = enable;
8641 return 0;
8642}
8643
8644
Jouni Malinenf7222712019-06-13 01:50:21 +03008645static enum sigma_cmd_result cmd_sta_reset_default(struct sigma_dut *dut,
8646 struct sigma_conn *conn,
8647 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008648{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008649 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008650 const char *band = get_param(cmd, "band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008651 const char *type;
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07008652 const char *program = get_param(cmd, "program");
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05308653 const char *dev_role = get_param(cmd, "DevRole");
Veerendranath Jakkamc1f71b62021-01-23 03:09:51 +05308654 char resp[20];
Veerendranath Jakkamea7f0692021-08-11 19:13:12 +05308655 char buf[100];
Veerendranath Jakkamc1f71b62021-01-23 03:09:51 +05308656 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008657
Jouni Malinenb21f0542019-11-04 17:53:38 +02008658 if (dut->station_ifname_2g &&
8659 strcmp(dut->station_ifname_2g, intf) == 0)
8660 dut->use_5g = 0;
8661 else if (dut->station_ifname_5g &&
8662 strcmp(dut->station_ifname_5g, intf) == 0)
8663 dut->use_5g = 1;
8664
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07008665 if (!program)
8666 program = get_param(cmd, "prog");
8667 dut->program = sigma_program_to_enum(program);
Vinita S. Maloof7a2cbf2020-11-18 19:29:44 +05308668
8669 if (dut->program == PROGRAM_WFD && dut->user_config_timeout)
8670 dut->default_timeout = dut->user_config_timeout;
8671
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008672 dut->device_type = STA_unknown;
8673 type = get_param(cmd, "type");
8674 if (type && strcasecmp(type, "Testbed") == 0)
8675 dut->device_type = STA_testbed;
8676 if (type && strcasecmp(type, "DUT") == 0)
8677 dut->device_type = STA_dut;
8678
8679 if (dut->program == PROGRAM_TDLS) {
8680 /* Clear TDLS testing mode */
8681 wpa_command(intf, "SET tdls_disabled 0");
8682 wpa_command(intf, "SET tdls_testing 0");
8683 dut->no_tpk_expiration = 0;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008684 if (get_driver_type(dut) == DRIVER_WCN) {
Pradeep Reddy POTTETI8ce2a232016-10-28 12:17:32 +05308685 /* Enable the WCN driver in TDLS Explicit trigger mode
8686 */
8687 wpa_command(intf, "SET tdls_external_control 0");
8688 wpa_command(intf, "SET tdls_trigger_control 0");
8689 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008690 }
8691
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07008692#ifdef MIRACAST
8693 if (dut->program == PROGRAM_WFD ||
8694 dut->program == PROGRAM_DISPLAYR2)
8695 miracast_sta_reset_default(dut, conn, cmd);
8696#endif /* MIRACAST */
8697
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008698 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008699 case DRIVER_ATHEROS:
8700 sta_reset_default_ath(dut, intf, type);
8701 break;
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08008702 case DRIVER_WCN:
8703 sta_reset_default_wcn(dut, intf, type);
8704 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008705 default:
8706 break;
8707 }
8708
8709#ifdef ANDROID_NAN
8710 if (dut->program == PROGRAM_NAN)
8711 nan_cmd_sta_reset_default(dut, conn, cmd);
8712#endif /* ANDROID_NAN */
8713
Vinay Gannevaram3b9fdd32019-06-14 17:55:44 +05308714 if (dut->program == PROGRAM_LOC &&
8715 lowi_cmd_sta_reset_default(dut, conn, cmd) < 0)
8716 return ERROR_SEND_STATUS;
8717
Jouni Malinenba630452018-06-22 11:49:59 +03008718 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008719 unlink("SP/wi-fi.org/pps.xml");
8720 if (system("rm -r SP/*") != 0) {
8721 }
8722 unlink("next-client-cert.pem");
8723 unlink("next-client-key.pem");
8724 }
8725
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008726 /* For WPS program of the 60 GHz band the band type needs to be saved */
8727 if (dut->program == PROGRAM_WPS) {
8728 if (band && strcasecmp(band, "60GHz") == 0) {
8729 dut->band = WPS_BAND_60G;
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02008730 /* For 60 GHz enable WPS for WPS TCs */
8731 dut->wps_disable = 0;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008732 } else {
8733 dut->band = WPS_BAND_NON_60G;
8734 }
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02008735 } else if (dut->program == PROGRAM_60GHZ) {
8736 /* For 60 GHz MAC/PHY TCs WPS must be disabled */
8737 dut->wps_disable = 1;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008738 }
8739
Alexei Avshalom Lazar157ba062018-12-23 16:15:26 +02008740 if (is_60g_sigma_dut(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008741 const char *dev_role = get_param(cmd, "DevRole");
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02008742 char buf[256];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008743
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02008744 sigma_dut_print(dut, DUT_MSG_INFO,
8745 "WPS 60 GHz program, wps_disable = %d",
8746 dut->wps_disable);
8747
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008748 if (!dev_role) {
8749 send_resp(dut, conn, SIGMA_ERROR,
8750 "errorCode,Missing DevRole argument");
8751 return 0;
8752 }
8753
8754 if (strcasecmp(dev_role, "STA") == 0)
8755 dut->dev_role = DEVROLE_STA;
8756 else if (strcasecmp(dev_role, "PCP") == 0)
8757 dut->dev_role = DEVROLE_PCP;
8758 else {
8759 send_resp(dut, conn, SIGMA_ERROR,
8760 "errorCode,Unknown DevRole");
8761 return 0;
8762 }
8763
8764 if (dut->device_type == STA_unknown) {
8765 sigma_dut_print(dut, DUT_MSG_ERROR,
8766 "Device type is not STA testbed or DUT");
8767 send_resp(dut, conn, SIGMA_ERROR,
8768 "errorCode,Unknown device type");
8769 return 0;
8770 }
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02008771
8772 sigma_dut_print(dut, DUT_MSG_DEBUG,
8773 "Setting msdu_size to MAX: 7912");
8774 snprintf(buf, sizeof(buf), "ifconfig %s mtu 7912",
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008775 get_station_ifname(dut));
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02008776
8777 if (system(buf) != 0) {
8778 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
8779 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02008780 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02008781 }
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02008782
8783 if (sta_set_force_mcs(dut, 0, 1)) {
8784 sigma_dut_print(dut, DUT_MSG_ERROR,
8785 "Failed to reset force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02008786 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02008787 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008788 }
8789
8790 wpa_command(intf, "WPS_ER_STOP");
8791 wpa_command(intf, "FLUSH");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05308792 wpa_command(intf, "ERP_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008793 wpa_command(intf, "SET radio_disabled 0");
8794
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02008795 dut->wps_forced_version = 0;
8796
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008797 if (dut->wsc_fragment) {
8798 dut->wsc_fragment = 0;
8799 wpa_command(intf, "SET device_name Test client");
8800 wpa_command(intf, "SET manufacturer ");
8801 wpa_command(intf, "SET model_name ");
8802 wpa_command(intf, "SET model_number ");
8803 wpa_command(intf, "SET serial_number ");
8804 }
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02008805 if (is_60g_sigma_dut(dut) && dut->force_rsn_ie) {
8806 dut->force_rsn_ie = FORCE_RSN_IE_NONE;
8807 sta_60g_force_rsn_ie(dut, FORCE_RSN_IE_NONE);
8808 }
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008809
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008810 if (dut->tmp_mac_addr && dut->set_macaddr) {
8811 dut->tmp_mac_addr = 0;
8812 if (system(dut->set_macaddr) != 0) {
8813 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to clear "
8814 "temporary MAC address");
8815 }
8816 }
8817
8818 set_ps(intf, dut, 0);
8819
Jouni Malinenba630452018-06-22 11:49:59 +03008820 if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2 ||
8821 dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008822 wpa_command(intf, "SET interworking 1");
8823 wpa_command(intf, "SET hs20 1");
8824 }
8825
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08008826 if (dut->program == PROGRAM_HS2_R2 ||
Jouni Malinenba630452018-06-22 11:49:59 +03008827 dut->program == PROGRAM_HS2_R3 ||
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08008828 dut->program == PROGRAM_OCE) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008829 wpa_command(intf, "SET pmf 1");
8830 } else {
8831 wpa_command(intf, "SET pmf 0");
8832 }
8833
8834 hs2_clear_credentials(intf);
8835 wpa_command(intf, "SET hessid 00:00:00:00:00:00");
8836 wpa_command(intf, "SET access_network_type 15");
8837
8838 static_ip_file(0, NULL, NULL, NULL);
8839 kill_dhcp_client(dut, intf);
8840 clear_ip_addr(dut, intf);
8841
8842 dut->er_oper_performed = 0;
8843 dut->er_oper_bssid[0] = '\0';
8844
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07008845 if (dut->program == PROGRAM_LOC) {
8846 /* Disable Interworking by default */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008847 wpa_command(get_station_ifname(dut), "SET interworking 0");
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07008848 }
8849
Kiran Kumar Lokeredd086642020-06-04 00:29:26 -07008850 if (dut->program == PROGRAM_MBO || dut->program == PROGRAM_HE) {
Ashwini Patil00402582017-04-13 12:29:39 +05308851 free(dut->non_pref_ch_list);
8852 dut->non_pref_ch_list = NULL;
Ashwini Patil5acd7382017-04-13 15:55:04 +05308853 free(dut->btm_query_cand_list);
8854 dut->btm_query_cand_list = NULL;
Ashwini Patilc63161e2017-04-13 16:30:23 +05308855 wpa_command(intf, "SET reject_btm_req_reason 0");
Ashwini Patila75de5a2017-04-13 16:35:05 +05308856 wpa_command(intf, "SET ignore_assoc_disallow 0");
Ashwini Patild174f2c2017-04-13 16:49:46 +05308857 wpa_command(intf, "SET gas_address3 0");
Ashwini Patil9183fdb2017-04-13 16:58:25 +05308858 wpa_command(intf, "SET roaming 1");
Ankita Bajaj1d974552018-09-18 16:56:44 +05308859 wpa_command(intf, "SET interworking 1");
Ashwini Patil00402582017-04-13 12:29:39 +05308860 }
8861
Jouni Malinen3c367e82017-06-23 17:01:47 +03008862 free(dut->rsne_override);
8863 dut->rsne_override = NULL;
8864
Jouni Malinen68143132017-09-02 02:34:08 +03008865 free(dut->sae_commit_override);
8866 dut->sae_commit_override = NULL;
Jouni Malinen4b3769d2019-10-10 16:20:29 +03008867 wpa_command(intf, "SET sae_pmkid_in_assoc 0");
Jouni Malinen11e55212019-11-22 21:46:59 +02008868 dut->sae_pwe = SAE_PWE_DEFAULT;
Jouni Malinen68143132017-09-02 02:34:08 +03008869
Jouni Malinen134fe3c2019-06-12 04:16:49 +03008870 dut->sta_associate_wait_connect = 0;
8871 dut->server_cert_hash[0] = '\0';
Jouni Malinen37d5c692019-08-19 16:56:55 +03008872 dut->server_cert_tod = 0;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03008873 dut->sta_tod_policy = 0;
8874
Jouni Malinend86e5822017-08-29 03:55:32 +03008875 dut->dpp_conf_id = -1;
Jouni Malinenb1dd21f2017-11-13 19:14:29 +02008876 free(dut->dpp_peer_uri);
8877 dut->dpp_peer_uri = NULL;
Jouni Malinen63d50412017-11-24 11:55:38 +02008878 dut->dpp_local_bootstrap = -1;
Jouni Malinen5011fb52017-12-05 21:00:15 +02008879 wpa_command(intf, "SET dpp_config_processing 2");
Jouni Malinen90776b12020-05-04 15:34:46 +03008880 wpa_command(intf, "SET dpp_mud_url ");
Jouni Malinend86e5822017-08-29 03:55:32 +03008881
Jouni Malinenfac9cad2017-10-10 18:35:55 +03008882 wpa_command(intf, "VENDOR_ELEM_REMOVE 13 *");
8883
vamsi krishnaa2799492017-12-05 14:28:01 +05308884 if (dut->program == PROGRAM_OCE) {
Ankita Bajaja2cb5672017-10-25 16:08:28 +05308885 wpa_command(intf, "SET oce 1");
vamsi krishnaa2799492017-12-05 14:28:01 +05308886 wpa_command(intf, "SET disable_fils 0");
Ankita Bajaj1bde7942018-01-09 19:15:01 +05308887 wpa_command(intf, "FILS_HLP_REQ_FLUSH");
8888 dut->fils_hlp = 0;
8889#ifdef ANDROID
8890 hlp_thread_cleanup(dut);
8891#endif /* ANDROID */
vamsi krishnaa2799492017-12-05 14:28:01 +05308892 }
Ankita Bajaja2cb5672017-10-25 16:08:28 +05308893
Veerendranath Jakkamea7f0692021-08-11 19:13:12 +05308894 if (dut->program == PROGRAM_QM) {
Vamsi Krishnaf642d6a2020-03-27 12:33:14 +05308895 wpa_command(intf, "SET interworking 1");
Vinita S. Maloo2287f142021-02-01 16:17:09 +05308896 wpa_command(intf, "SET disable_scs_support 0");
Vinita S. Maloo83dee552021-04-12 16:47:47 +05308897 wpa_command(intf, "SET disable_mscs_support 0");
Veerendranath Jakkama16cdc82021-09-12 16:44:22 +05308898 wpa_command(intf, "SET enable_dscp_policy_capa 1");
Veerendranath Jakkam329a3cd2021-09-11 18:10:13 +05308899 dut->qm_domain_name[0] = '\0';
Veerendranath Jakkama16cdc82021-09-12 16:44:22 +05308900 dut->reject_dscp_policies = 0;
Veerendranath Jakkamea7f0692021-08-11 19:13:12 +05308901 snprintf(buf, sizeof(buf),
8902 "ip -6 route replace fe80::/64 dev %s table local",
8903 intf);
8904 if (system(buf) != 0)
8905 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run: %s",
8906 buf);
Veerendranath Jakkam9ceb3b12021-09-10 03:18:17 +05308907
8908 stop_dscp_policy_mon_thread(dut);
8909 clear_all_dscp_policies(dut);
Veerendranath Jakkamea7f0692021-08-11 19:13:12 +05308910 }
Vamsi Krishnaf642d6a2020-03-27 12:33:14 +05308911
Jouni Malinen8179fee2019-03-28 03:19:47 +02008912 dut->akm_values = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03008913 dut->sta_ft_ds = 0;
Jouni Malinen8179fee2019-03-28 03:19:47 +02008914
Sunil Dutt076081f2018-02-05 19:45:50 +05308915#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008916 if (get_driver_type(dut) == DRIVER_WCN &&
Sunil Dutt44595082018-02-12 19:41:45 +05308917 dut->config_rsnie == 1) {
8918 dut->config_rsnie = 0;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05308919 sta_config_params(dut, intf, STA_SET_RSNIE, 0);
Sunil Dutt076081f2018-02-05 19:45:50 +05308920 }
8921#endif /* NL80211_SUPPORT */
8922
Sunil Duttfebf8a82018-02-09 18:50:13 +05308923 if (dev_role && strcasecmp(dev_role, "STA-CFON") == 0) {
8924 dut->dev_role = DEVROLE_STA_CFON;
8925 return sta_cfon_reset_default(dut, conn, cmd);
8926 }
8927
Jouni Malinen439352d2018-09-13 03:42:23 +03008928 wpa_command(intf, "SET setband AUTO");
8929
Veerendranath Jakkamc1f71b62021-01-23 03:09:51 +05308930 ret = wpa_command_resp(intf, "GET_CAPABILITY ocv", resp, sizeof(resp));
8931 dut->ocvc = ret == 0 && strncmp(resp, "supported", 9) == 0;
8932
8933 ret = wpa_command_resp(intf, "GET_CAPABILITY beacon_prot", resp,
8934 sizeof(resp));
8935 dut->beacon_prot = ret == 0 && strncmp(resp, "supported", 9) == 0;
8936
Veerendranath Jakkam47867202020-12-21 01:53:52 +05308937 if (sta_set_client_privacy(dut, conn, intf,
8938 dut->program == PROGRAM_WPA3 &&
8939 dut->device_type == STA_dut &&
8940 dut->client_privacy_default)) {
8941 sigma_dut_print(dut, DUT_MSG_ERROR,
8942 "Failed to set client privacy functionality");
8943 /* sta_reset_default command is not really supposed to fail,
8944 * so allow this to continue. */
8945 }
8946
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +05308947 dut->saquery_oci_freq = 0;
Vamsi Krishnac1633d22020-05-06 18:31:21 +05308948
Sunil Duttfebf8a82018-02-09 18:50:13 +05308949 if (dut->program != PROGRAM_VHT)
8950 return cmd_sta_p2p_reset(dut, conn, cmd);
8951
Priyadharshini Gowthamana7dfd492015-11-09 14:34:08 -08008952 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008953}
8954
8955
Jouni Malinenf7222712019-06-13 01:50:21 +03008956static enum sigma_cmd_result cmd_sta_get_events(struct sigma_dut *dut,
8957 struct sigma_conn *conn,
8958 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008959{
8960 const char *program = get_param(cmd, "Program");
8961
8962 if (program == NULL)
8963 return -1;
8964#ifdef ANDROID_NAN
8965 if (strcasecmp(program, "NAN") == 0)
8966 return nan_cmd_sta_get_events(dut, conn, cmd);
8967#endif /* ANDROID_NAN */
8968 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
8969 return 0;
8970}
8971
8972
Jouni Malinen82905202018-04-29 17:20:10 +03008973static int sta_exec_action_url(struct sigma_dut *dut, struct sigma_conn *conn,
8974 struct sigma_cmd *cmd)
8975{
8976 const char *url = get_param(cmd, "url");
8977 const char *method = get_param(cmd, "method");
8978 pid_t pid;
8979 int status;
8980
8981 if (!url || !method)
8982 return -1;
8983
8984 /* TODO: Add support for method,post */
8985 if (strcasecmp(method, "get") != 0) {
8986 send_resp(dut, conn, SIGMA_ERROR,
8987 "ErrorCode,Unsupported method");
8988 return 0;
8989 }
8990
8991 pid = fork();
8992 if (pid < 0) {
8993 perror("fork");
8994 return -1;
8995 }
8996
8997 if (pid == 0) {
8998 char * argv[5] = { "wget", "-O", "/dev/null",
8999 (char *) url, NULL };
9000
9001 execv("/usr/bin/wget", argv);
9002 perror("execv");
9003 exit(0);
9004 return -1;
9005 }
9006
9007 if (waitpid(pid, &status, 0) < 0) {
9008 perror("waitpid");
9009 return -1;
9010 }
9011
9012 if (WIFEXITED(status)) {
9013 const char *errmsg;
9014
9015 if (WEXITSTATUS(status) == 0)
9016 return 1;
9017 sigma_dut_print(dut, DUT_MSG_INFO, "wget exit status %d",
9018 WEXITSTATUS(status));
9019 switch (WEXITSTATUS(status)) {
9020 case 4:
9021 errmsg = "errmsg,Network failure";
9022 break;
9023 case 8:
9024 errmsg = "errmsg,Server issued an error response";
9025 break;
9026 default:
9027 errmsg = "errmsg,Unknown failure from wget";
9028 break;
9029 }
9030 send_resp(dut, conn, SIGMA_ERROR, errmsg);
9031 return 0;
9032 }
9033
9034 send_resp(dut, conn, SIGMA_ERROR, "errmsg,Unknown failure");
9035 return 0;
9036}
9037
9038
Jouni Malinenf7222712019-06-13 01:50:21 +03009039static enum sigma_cmd_result cmd_sta_exec_action(struct sigma_dut *dut,
9040 struct sigma_conn *conn,
9041 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009042{
9043 const char *program = get_param(cmd, "Prog");
9044
Jouni Malinen82905202018-04-29 17:20:10 +03009045 if (program && !get_param(cmd, "interface"))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009046 return -1;
9047#ifdef ANDROID_NAN
Jouni Malinen82905202018-04-29 17:20:10 +03009048 if (program && strcasecmp(program, "NAN") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009049 return nan_cmd_sta_exec_action(dut, conn, cmd);
9050#endif /* ANDROID_NAN */
Jouni Malinen82905202018-04-29 17:20:10 +03009051
9052 if (program && strcasecmp(program, "Loc") == 0)
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07009053 return loc_cmd_sta_exec_action(dut, conn, cmd);
Jouni Malinen82905202018-04-29 17:20:10 +03009054
9055 if (get_param(cmd, "url"))
9056 return sta_exec_action_url(dut, conn, cmd);
9057
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009058 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
9059 return 0;
9060}
9061
9062
Jouni Malinenf7222712019-06-13 01:50:21 +03009063static enum sigma_cmd_result cmd_sta_set_11n(struct sigma_dut *dut,
9064 struct sigma_conn *conn,
9065 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009066{
9067 const char *intf = get_param(cmd, "Interface");
9068 const char *val, *mcs32, *rate;
9069
9070 val = get_param(cmd, "GREENFIELD");
9071 if (val) {
9072 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
9073 /* Enable GD */
9074 send_resp(dut, conn, SIGMA_ERROR,
9075 "ErrorCode,GF not supported");
9076 return 0;
9077 }
9078 }
9079
9080 val = get_param(cmd, "SGI20");
9081 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009082 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009083 case DRIVER_ATHEROS:
9084 ath_sta_set_sgi(dut, intf, val);
9085 break;
9086 default:
9087 send_resp(dut, conn, SIGMA_ERROR,
9088 "ErrorCode,SGI20 not supported");
9089 return 0;
9090 }
9091 }
9092
9093 mcs32 = get_param(cmd, "MCS32"); /* HT Duplicate Mode Enable/Disable */
9094 rate = get_param(cmd, "MCS_FIXEDRATE"); /* Fixed MCS rate (0..31) */
9095 if (mcs32 && rate) {
9096 /* TODO */
9097 send_resp(dut, conn, SIGMA_ERROR,
9098 "ErrorCode,MCS32,MCS_FIXEDRATE not supported");
9099 return 0;
9100 } else if (mcs32 && !rate) {
9101 /* TODO */
9102 send_resp(dut, conn, SIGMA_ERROR,
9103 "ErrorCode,MCS32 not supported");
9104 return 0;
9105 } else if (!mcs32 && rate) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009106 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009107 case DRIVER_ATHEROS:
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07009108 novap_reset(dut, intf, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009109 ath_sta_set_11nrates(dut, intf, rate);
9110 break;
9111 default:
9112 send_resp(dut, conn, SIGMA_ERROR,
9113 "ErrorCode,MCS32_FIXEDRATE not supported");
9114 return 0;
9115 }
9116 }
9117
9118 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
9119}
9120
9121
Arif Hussain7b47d2d2018-05-09 10:44:02 -07009122static void cmd_set_max_he_mcs(struct sigma_dut *dut, const char *intf,
9123 int mcs_config)
9124{
9125#ifdef NL80211_SUPPORT
9126 int ret;
9127
9128 switch (mcs_config) {
9129 case HE_80_MCS0_7:
9130 case HE_80_MCS0_9:
9131 case HE_80_MCS0_11:
9132 ret = sta_set_he_mcs(dut, intf, mcs_config);
9133 if (ret) {
9134 sigma_dut_print(dut, DUT_MSG_ERROR,
9135 "cmd_set_max_he_mcs: Setting of MCS:%d failed, ret:%d",
9136 mcs_config, ret);
9137 }
9138 break;
9139 default:
9140 sigma_dut_print(dut, DUT_MSG_ERROR,
9141 "cmd_set_max_he_mcs: Invalid mcs %d",
9142 mcs_config);
9143 break;
9144 }
9145#else /* NL80211_SUPPORT */
9146 sigma_dut_print(dut, DUT_MSG_ERROR,
9147 "max HE MCS cannot be changed without NL80211_SUPPORT defined");
9148#endif /* NL80211_SUPPORT */
9149}
9150
9151
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07009152struct wait_event {
9153 struct sigma_dut *dut;
9154 int cmd;
9155 unsigned int twt_op;
9156};
9157
9158#ifdef NL80211_SUPPORT
9159
9160static int twt_event_handler(struct nl_msg *msg, void *arg)
9161{
9162 struct wait_event *wait = arg;
9163 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
9164 struct nlattr *tb[NL80211_ATTR_MAX + 1];
9165 uint32_t subcmd;
9166 uint8_t *data = NULL;
9167 size_t len = 0;
9168 struct nlattr *twt_rsp[QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_MAX + 1];
9169 struct nlattr *twt_status[QCA_WLAN_VENDOR_ATTR_TWT_SETUP_MAX + 1];
9170 int cmd_id;
9171 unsigned char val;
9172
9173 if (!wait)
9174 return NL_SKIP;
9175
9176 if (gnlh->cmd != NL80211_CMD_VENDOR) {
9177 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9178 "%s: NL cmd is not vendor %d", __func__,
9179 gnlh->cmd);
9180 return NL_SKIP;
9181 }
9182
9183 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
9184 genlmsg_attrlen(gnlh, 0), NULL);
9185
9186 if (!tb[NL80211_ATTR_VENDOR_ID] || !tb[NL80211_ATTR_VENDOR_SUBCMD]) {
9187 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9188 "%s: vendor ID not found", __func__);
9189 return NL_SKIP;
9190 }
9191 subcmd = nla_get_u32(tb[NL80211_ATTR_VENDOR_SUBCMD]);
9192
9193 if (subcmd != QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) {
9194 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9195 "%s: Not a TWT_cmd %d", __func__, subcmd);
9196 return NL_SKIP;
9197 }
9198 if (tb[NL80211_ATTR_VENDOR_DATA]) {
9199 data = nla_data(tb[NL80211_ATTR_VENDOR_DATA]);
9200 len = nla_len(tb[NL80211_ATTR_VENDOR_DATA]);
9201 } else {
9202 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9203 "%s: vendor data not present", __func__);
9204 return NL_SKIP;
9205 }
9206 if (!data || !len) {
9207 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9208 "Invalid vendor data or len");
9209 return NL_SKIP;
9210 }
9211 sigma_dut_print(wait->dut, DUT_MSG_DEBUG,
9212 "event data len %ld", len);
9213 hex_dump(wait->dut, data, len);
9214 if (nla_parse(twt_rsp, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_MAX,
9215 (struct nlattr *) data, len, NULL)) {
9216 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9217 "vendor data parse error");
9218 return NL_SKIP;
9219 }
9220
9221 val = nla_get_u8(twt_rsp[QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION]);
9222 if (val != wait->twt_op) {
9223 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9224 "Invalid TWT operation, expected %d, rcvd %d",
9225 wait->twt_op, val);
9226 return NL_SKIP;
9227 }
9228 if (nla_parse_nested(twt_status, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_MAX,
9229 twt_rsp[QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS],
9230 NULL)) {
9231 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9232 "nla_parse failed for TWT event");
9233 return NL_SKIP;
9234 }
9235
9236 cmd_id = QCA_WLAN_VENDOR_ATTR_TWT_SETUP_STATUS;
9237 if (!twt_status[cmd_id]) {
9238 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9239 "%s TWT resp status missing", __func__);
9240 wait->cmd = -1;
9241 } else {
9242 val = nla_get_u8(twt_status[cmd_id]);
9243 if (val != QCA_WLAN_VENDOR_TWT_STATUS_OK) {
9244 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9245 "%s TWT resp status %d", __func__, val);
9246 wait->cmd = -1;
9247 } else {
9248 wait->cmd = 1;
9249 }
9250 }
9251
9252 return NL_SKIP;
9253}
9254
9255
9256static int wait_on_nl_socket(struct nl_sock *sock, struct sigma_dut *dut,
9257 unsigned int timeout)
9258{
9259 fd_set read_fd_set;
9260 int retval;
9261 int sock_fd;
9262 struct timeval time_out;
9263
9264 time_out.tv_sec = timeout;
9265 time_out.tv_usec = 0;
9266
9267 FD_ZERO(&read_fd_set);
9268
9269 if (!sock)
9270 return -1;
9271
9272 sock_fd = nl_socket_get_fd(sock);
9273 FD_SET(sock_fd, &read_fd_set);
9274
9275 retval = select(sock_fd + 1, &read_fd_set, NULL, NULL, &time_out);
9276
9277 if (retval == 0)
9278 sigma_dut_print(dut, DUT_MSG_ERROR,
9279 "%s: TWT event response timedout", __func__);
9280
9281 if (retval < 0)
9282 sigma_dut_print(dut, DUT_MSG_ERROR, "%s:no NL msgs, ret=%d",
9283 __func__, retval);
9284
9285 return retval;
9286}
9287
9288
9289#define TWT_ASYNC_EVENT_WAIT_TIME_SEC 6
9290
9291static int twt_async_event_wait(struct sigma_dut *dut, unsigned int twt_op)
9292{
9293 struct nl_cb *cb;
9294 int err_code = 0, select_retval = 0;
9295 struct wait_event wait_info;
9296
9297 cb = nl_socket_get_cb(dut->nl_ctx->event_sock);
9298 if (!cb) {
9299 sigma_dut_print(dut, DUT_MSG_ERROR,
9300 "event callback not found");
9301 return ERROR_SEND_STATUS;
9302 }
9303
9304 wait_info.cmd = 0;
9305 wait_info.dut = dut;
9306 wait_info.twt_op = twt_op;
9307
9308 nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, twt_event_handler, &wait_info);
9309
9310 while (!wait_info.cmd) {
9311 select_retval = wait_on_nl_socket(
9312 dut->nl_ctx->event_sock, dut,
9313 TWT_ASYNC_EVENT_WAIT_TIME_SEC);
9314
9315 if (select_retval > 0) {
9316 err_code = nl_recvmsgs(dut->nl_ctx->event_sock, cb);
9317 if (err_code < 0) {
9318 sigma_dut_print(dut, DUT_MSG_ERROR,
9319 "%s: nl rcv failed, err_code %d",
9320 __func__, err_code);
9321 break;
9322 }
9323 } else {
9324 sigma_dut_print(dut, DUT_MSG_ERROR,
9325 "%s: wait on socket failed %d",
9326 __func__, select_retval);
9327 err_code = 1;
9328 break;
9329 }
9330
9331 }
9332 nl_cb_put(cb);
9333
9334 if (wait_info.cmd < 0)
9335 err_code = 1;
9336
9337 sigma_dut_print(dut, DUT_MSG_DEBUG,
9338 "%s: rcvd cmd %d, err_code %d, s_ret %d",
9339 __func__, wait_info.cmd, err_code, select_retval);
9340
9341 return err_code;
9342}
9343
9344#endif /* NL80211_SUPPORT */
9345
9346
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009347static int sta_twt_send_suspend(struct sigma_dut *dut, struct sigma_conn *conn,
9348 struct sigma_cmd *cmd)
9349{
9350#ifdef NL80211_SUPPORT
9351 struct nlattr *attr, *attr1;
9352 struct nl_msg *msg;
9353 int ifindex, ret;
9354 const char *intf = get_param(cmd, "Interface");
9355
9356 ifindex = if_nametoindex(intf);
9357 if (ifindex == 0) {
9358 sigma_dut_print(dut, DUT_MSG_ERROR,
9359 "%s: Index for interface %s failed",
9360 __func__, intf);
9361 return ERROR_SEND_STATUS;
9362 }
9363
9364 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9365 NL80211_CMD_VENDOR)) ||
9366 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9367 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9368 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9369 QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) ||
9370 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9371 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION,
9372 QCA_WLAN_TWT_SUSPEND) ||
9373 !(attr1 = nla_nest_start(msg,
Kiran Kumar Lokere7ede00c2021-08-09 00:59:52 -07009374 QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS))) {
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009375 sigma_dut_print(dut, DUT_MSG_ERROR,
9376 "%s: err in adding vendor_cmd and vendor_data",
9377 __func__);
9378 nlmsg_free(msg);
9379 return ERROR_SEND_STATUS;
9380 }
9381 nla_nest_end(msg, attr1);
9382 nla_nest_end(msg, attr);
9383
9384 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9385 if (ret) {
9386 sigma_dut_print(dut, DUT_MSG_ERROR,
9387 "%s: err in send_and_recv_msgs, ret=%d",
9388 __func__, ret);
9389 }
9390
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07009391 if (!dut->sta_async_twt_supp)
9392 return ret;
9393
9394 return twt_async_event_wait(dut, QCA_WLAN_TWT_SUSPEND);
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009395#else /* NL80211_SUPPORT */
9396 sigma_dut_print(dut, DUT_MSG_ERROR,
9397 "TWT suspend cannot be done without NL80211_SUPPORT defined");
9398 return ERROR_SEND_STATUS;
9399#endif /* NL80211_SUPPORT */
9400}
9401
9402
9403static int sta_twt_send_nudge(struct sigma_dut *dut, struct sigma_conn *conn,
9404 struct sigma_cmd *cmd,
9405 unsigned int suspend_duration)
9406{
9407#ifdef NL80211_SUPPORT
9408 struct nlattr *attr, *attr1;
9409 struct nl_msg *msg;
9410 int ifindex, ret;
9411 const char *intf = get_param(cmd, "Interface");
9412 int next_twt_size = 1;
9413
9414 ifindex = if_nametoindex(intf);
9415 if (ifindex == 0) {
9416 sigma_dut_print(dut, DUT_MSG_ERROR,
9417 "%s: Index for interface %s failed",
9418 __func__, intf);
9419 return ERROR_SEND_STATUS;
9420 }
9421
9422 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9423 NL80211_CMD_VENDOR)) ||
9424 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9425 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9426 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9427 QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) ||
9428 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9429 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION,
9430 QCA_WLAN_TWT_NUDGE) ||
9431 !(attr1 = nla_nest_start(msg,
9432 QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS)) ||
9433 (suspend_duration &&
9434 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_NUDGE_WAKE_TIME,
9435 suspend_duration)) ||
9436 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_NUDGE_NEXT_TWT_SIZE,
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -07009437 next_twt_size) ||
9438 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_NUDGE_FLOW_ID, 0)) {
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009439 sigma_dut_print(dut, DUT_MSG_ERROR,
9440 "%s: err in adding vendor_cmd and vendor_data",
9441 __func__);
9442 nlmsg_free(msg);
9443 return ERROR_SEND_STATUS;
9444 }
9445 nla_nest_end(msg, attr1);
9446 nla_nest_end(msg, attr);
9447
9448 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9449 if (ret) {
9450 sigma_dut_print(dut, DUT_MSG_ERROR,
9451 "%s: err in send_and_recv_msgs, ret=%d",
9452 __func__, ret);
9453 }
9454
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07009455 if (!dut->sta_async_twt_supp)
9456 return ret;
9457
9458 return twt_async_event_wait(dut, QCA_WLAN_TWT_NUDGE);
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009459#else /* NL80211_SUPPORT */
9460 sigma_dut_print(dut, DUT_MSG_ERROR,
9461 "TWT suspend cannot be done without NL80211_SUPPORT defined");
9462 return ERROR_SEND_STATUS;
9463#endif /* NL80211_SUPPORT */
9464}
9465
9466
9467static int sta_twt_suspend_or_nudge(struct sigma_dut *dut,
9468 struct sigma_conn *conn,
9469 struct sigma_cmd *cmd)
9470{
9471 const char *val;
9472
9473 val = get_param(cmd, "TWT_SuspendDuration");
9474 if (val) {
9475 unsigned int suspend_duration;
9476
9477 suspend_duration = atoi(val);
9478 suspend_duration = suspend_duration * 1000 * 1000;
9479 return sta_twt_send_nudge(dut, conn, cmd, suspend_duration);
9480 }
9481
9482 return sta_twt_send_suspend(dut, conn, cmd);
9483}
9484
9485
9486static int sta_twt_resume(struct sigma_dut *dut, struct sigma_conn *conn,
9487 struct sigma_cmd *cmd)
9488{
9489#ifdef NL80211_SUPPORT
9490 struct nlattr *attr, *attr1;
9491 struct nl_msg *msg;
9492 int ifindex, ret;
9493 const char *intf = get_param(cmd, "Interface");
9494 int next2_twt_size = 1;
9495 unsigned int resume_duration = 0;
9496 const char *val;
9497
9498 ifindex = if_nametoindex(intf);
9499 if (ifindex == 0) {
9500 sigma_dut_print(dut, DUT_MSG_ERROR,
9501 "%s: Index for interface %s failed",
9502 __func__, intf);
9503 return ERROR_SEND_STATUS;
9504 }
9505
9506 val = get_param(cmd, "TWT_ResumeDuration");
9507 if (val) {
9508 resume_duration = atoi(val);
9509 resume_duration = resume_duration * 1000 * 1000;
9510 }
9511
9512 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9513 NL80211_CMD_VENDOR)) ||
9514 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9515 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9516 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9517 QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) ||
9518 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9519 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION,
9520 QCA_WLAN_TWT_RESUME) ||
9521 !(attr1 = nla_nest_start(msg,
9522 QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS)) ||
9523 (resume_duration &&
9524 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_RESUME_NEXT2_TWT,
9525 resume_duration)) ||
9526 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_RESUME_NEXT_TWT_SIZE,
9527 next2_twt_size)) {
9528 sigma_dut_print(dut, DUT_MSG_ERROR,
9529 "%s: err in adding vendor_cmd and vendor_data",
9530 __func__);
9531 nlmsg_free(msg);
9532 return ERROR_SEND_STATUS;
9533 }
9534 nla_nest_end(msg, attr1);
9535 nla_nest_end(msg, attr);
9536
9537 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9538 if (ret) {
9539 sigma_dut_print(dut, DUT_MSG_ERROR,
9540 "%s: err in send_and_recv_msgs, ret=%d",
9541 __func__, ret);
9542 }
9543
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07009544 if (!dut->sta_async_twt_supp)
9545 return ret;
9546
9547 return twt_async_event_wait(dut, QCA_WLAN_TWT_RESUME);
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009548#else /* NL80211_SUPPORT */
9549 sigma_dut_print(dut, DUT_MSG_ERROR,
9550 "TWT resume cannot be done without NL80211_SUPPORT defined");
9551 return ERROR_SEND_STATUS;
9552#endif /* NL80211_SUPPORT */
9553}
9554
9555
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07009556#define TWT_REQUEST_CMD 0
9557#define TWT_SUGGEST_CMD 1
9558#define TWT_DEMAND_CMD 2
9559
Arif Hussain480d5f42019-03-12 14:40:42 -07009560static int sta_twt_request(struct sigma_dut *dut, struct sigma_conn *conn,
9561 struct sigma_cmd *cmd)
9562{
9563#ifdef NL80211_SUPPORT
9564 struct nlattr *params;
9565 struct nlattr *attr;
Arif Hussain480d5f42019-03-12 14:40:42 -07009566 struct nl_msg *msg;
9567 int ifindex, ret;
9568 const char *val;
9569 const char *intf = get_param(cmd, "Interface");
9570 int wake_interval_exp = 10, nominal_min_wake_dur = 255,
9571 wake_interval_mantissa = 512;
9572 int flow_type = 0, twt_trigger = 0, target_wake_time = 0,
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07009573 protection = 0, cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_SUGGEST;
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -07009574 int bcast_twt = 0;
9575 int bcast_twt_id = 0, bcast_twt_recommdn = 0, bcast_twt_persis = 0;
Arif Hussain480d5f42019-03-12 14:40:42 -07009576
9577 ifindex = if_nametoindex(intf);
9578 if (ifindex == 0) {
9579 sigma_dut_print(dut, DUT_MSG_ERROR,
9580 "%s: Index for interface %s failed",
9581 __func__, intf);
9582 return -1;
9583 }
9584
9585 val = get_param(cmd, "FlowType");
9586 if (val) {
9587 flow_type = atoi(val);
9588 if (flow_type != 0 && flow_type != 1) {
9589 sigma_dut_print(dut, DUT_MSG_ERROR,
9590 "TWT: Invalid FlowType %d", flow_type);
9591 return -1;
9592 }
9593 }
9594
9595 val = get_param(cmd, "TWT_Trigger");
9596 if (val) {
9597 twt_trigger = atoi(val);
9598 if (twt_trigger != 0 && twt_trigger != 1) {
9599 sigma_dut_print(dut, DUT_MSG_ERROR,
9600 "TWT: Invalid TWT_Trigger %d",
9601 twt_trigger);
9602 return -1;
9603 }
9604 }
9605
9606 val = get_param(cmd, "Protection");
9607 if (val) {
9608 protection = atoi(val);
9609 if (protection != 0 && protection != 1) {
9610 sigma_dut_print(dut, DUT_MSG_ERROR,
9611 "TWT: Invalid Protection %d",
9612 protection);
9613 return -1;
9614 }
9615 }
9616
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07009617 val = get_param(cmd, "SetupCommand");
9618 if (val) {
9619 cmd_type = atoi(val);
9620 if (cmd_type == TWT_REQUEST_CMD)
9621 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_REQUEST;
9622 else if (cmd_type == TWT_SUGGEST_CMD)
9623 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_SUGGEST;
9624 else if (cmd_type == TWT_DEMAND_CMD)
9625 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_DEMAND;
9626 else
9627 sigma_dut_print(dut, DUT_MSG_ERROR,
9628 "Default suggest is used for cmd %d",
9629 cmd_type);
9630 }
9631
Arif Hussain480d5f42019-03-12 14:40:42 -07009632 val = get_param(cmd, "TargetWakeTime");
9633 if (val)
9634 target_wake_time = atoi(val);
9635
9636 val = get_param(cmd, "WakeIntervalMantissa");
9637 if (val)
9638 wake_interval_mantissa = atoi(val);
9639
9640 val = get_param(cmd, "WakeIntervalExp");
9641 if (val)
9642 wake_interval_exp = atoi(val);
9643
9644 val = get_param(cmd, "NominalMinWakeDur");
9645 if (val)
9646 nominal_min_wake_dur = atoi(val);
9647
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -07009648 val = get_param(cmd, "BTWT_ID");
9649 if (val) {
9650 bcast_twt_id = atoi(val);
9651 bcast_twt = 1;
9652 }
9653
9654 val = get_param(cmd, "BTWT_Persistence");
9655 if (val) {
9656 bcast_twt_persis = atoi(val);
9657 bcast_twt = 1;
9658 }
9659
9660 val = get_param(cmd, "BTWT_Recommendation");
9661 if (val) {
9662 bcast_twt_recommdn = atoi(val);
9663 bcast_twt = 1;
9664 }
9665
9666 if (bcast_twt)
9667 sigma_dut_print(dut, DUT_MSG_DEBUG,
9668 "BCAST_TWT: ID %d, RECOMM %d, PERSIS %d",
9669 bcast_twt_id, bcast_twt_recommdn,
9670 bcast_twt_persis);
9671
Arif Hussain480d5f42019-03-12 14:40:42 -07009672 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9673 NL80211_CMD_VENDOR)) ||
9674 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9675 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9676 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009677 QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07009678 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009679 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION,
9680 QCA_WLAN_TWT_SET) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07009681 !(params = nla_nest_start(
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009682 msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07009683 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_EXP,
9684 wake_interval_exp) ||
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07009685 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_REQ_TYPE, cmd_type) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -07009686 (twt_trigger &&
9687 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_TRIGGER)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07009688 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE,
9689 flow_type) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -07009690 (protection &&
9691 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_PROTECTION)) ||
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -07009692 (bcast_twt &&
9693 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_BCAST)) ||
9694 (bcast_twt &&
9695 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_BCAST_ID,
9696 bcast_twt_id)) ||
9697 (bcast_twt &&
9698 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_BCAST_PERSISTENCE,
9699 bcast_twt_persis)) ||
9700 (bcast_twt &&
9701 nla_put_u8(msg,
9702 QCA_WLAN_VENDOR_ATTR_TWT_SETUP_BCAST_RECOMMENDATION,
9703 bcast_twt_recommdn)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07009704 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_TIME,
9705 target_wake_time) ||
9706 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_DURATION,
9707 nominal_min_wake_dur) ||
9708 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_MANTISSA,
9709 wake_interval_mantissa)) {
9710 sigma_dut_print(dut, DUT_MSG_ERROR,
9711 "%s: err in adding vendor_cmd and vendor_data",
9712 __func__);
9713 nlmsg_free(msg);
9714 return -1;
9715 }
Arif Hussain480d5f42019-03-12 14:40:42 -07009716 nla_nest_end(msg, params);
9717 nla_nest_end(msg, attr);
9718
9719 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9720 if (ret) {
9721 sigma_dut_print(dut, DUT_MSG_ERROR,
9722 "%s: err in send_and_recv_msgs, ret=%d",
9723 __func__, ret);
9724 }
9725
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07009726 if (!dut->sta_async_twt_supp)
9727 return ret;
9728
9729 return twt_async_event_wait(dut, QCA_WLAN_TWT_SET);
Arif Hussain480d5f42019-03-12 14:40:42 -07009730#else /* NL80211_SUPPORT */
9731 sigma_dut_print(dut, DUT_MSG_ERROR,
9732 "TWT request cannot be done without NL80211_SUPPORT defined");
9733 return -1;
9734#endif /* NL80211_SUPPORT */
9735}
9736
9737
9738static int sta_twt_teardown(struct sigma_dut *dut, struct sigma_conn *conn,
9739 struct sigma_cmd *cmd)
9740{
9741 #ifdef NL80211_SUPPORT
9742 struct nlattr *params;
9743 struct nlattr *attr;
Arif Hussain480d5f42019-03-12 14:40:42 -07009744 int ifindex, ret;
9745 struct nl_msg *msg;
9746 const char *intf = get_param(cmd, "Interface");
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -07009747 int bcast_twt = 0;
9748 int bcast_twt_id = 0;
9749 const char *val;
Arif Hussain480d5f42019-03-12 14:40:42 -07009750
9751 ifindex = if_nametoindex(intf);
9752 if (ifindex == 0) {
9753 sigma_dut_print(dut, DUT_MSG_ERROR,
9754 "%s: Index for interface %s failed",
9755 __func__, intf);
9756 return -1;
9757 }
9758
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -07009759 val = get_param(cmd, "BTWT_ID");
9760 if (val) {
9761 bcast_twt_id = atoi(val);
9762 bcast_twt = 1;
9763 }
9764
Arif Hussain480d5f42019-03-12 14:40:42 -07009765 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9766 NL80211_CMD_VENDOR)) ||
9767 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9768 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9769 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009770 QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07009771 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009772 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION,
9773 QCA_WLAN_TWT_TERMINATE) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07009774 !(params = nla_nest_start(
9775 msg,
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009776 QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS)) ||
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -07009777 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE, 0) ||
9778 (bcast_twt &&
9779 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_BCAST)) ||
9780 (bcast_twt &&
9781 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_BCAST_ID,
9782 bcast_twt_id))) {
Arif Hussain480d5f42019-03-12 14:40:42 -07009783 sigma_dut_print(dut, DUT_MSG_ERROR,
9784 "%s: err in adding vendor_cmd and vendor_data",
9785 __func__);
9786 nlmsg_free(msg);
9787 return -1;
9788 }
Arif Hussain480d5f42019-03-12 14:40:42 -07009789 nla_nest_end(msg, params);
9790 nla_nest_end(msg, attr);
9791
9792 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9793 if (ret) {
9794 sigma_dut_print(dut, DUT_MSG_ERROR,
9795 "%s: err in send_and_recv_msgs, ret=%d",
9796 __func__, ret);
9797 }
9798
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07009799 if (!dut->sta_async_twt_supp)
9800 return ret;
9801
9802 return twt_async_event_wait(dut, QCA_WLAN_TWT_TERMINATE);
Arif Hussain480d5f42019-03-12 14:40:42 -07009803#else /* NL80211_SUPPORT */
9804 sigma_dut_print(dut, DUT_MSG_ERROR,
9805 "TWT teardown cannot be done without NL80211_SUPPORT defined");
9806 return -1;
9807#endif /* NL80211_SUPPORT */
9808}
9809
9810
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -08009811static int sta_transmit_omi(struct sigma_dut *dut, struct sigma_conn *conn,
9812 struct sigma_cmd *cmd)
9813{
9814#ifdef NL80211_SUPPORT
9815 struct nlattr *params;
9816 struct nlattr *attr;
9817 struct nlattr *attr1;
9818 struct nl_msg *msg;
9819 int ifindex, ret;
9820 const char *val;
9821 const char *intf = get_param(cmd, "Interface");
9822 uint8_t rx_nss = 0xFF, ch_bw = 0xFF, tx_nsts = 0xFF, ulmu_dis = 0,
9823 ulmu_data_dis = 0;
9824
9825 ifindex = if_nametoindex(intf);
9826 if (ifindex == 0) {
9827 sigma_dut_print(dut, DUT_MSG_ERROR,
9828 "%s: Index for interface %s failed",
9829 __func__, intf);
9830 return -1;
9831 }
9832 val = get_param(cmd, "OMCtrl_RxNSS");
9833 if (val)
9834 rx_nss = atoi(val);
9835
9836 val = get_param(cmd, "OMCtrl_ChnlWidth");
9837 if (val)
9838 ch_bw = atoi(val);
9839
9840 val = get_param(cmd, "OMCtrl_ULMUDisable");
9841 if (val)
9842 ulmu_dis = atoi(val);
9843
9844 val = get_param(cmd, "OMCtrl_TxNSTS");
9845 if (val)
9846 tx_nsts = atoi(val);
9847
9848 val = get_param(cmd, "OMCtrl_ULMUDataDisable");
9849 if (val)
9850 ulmu_data_dis = atoi(val);
9851
9852 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9853 NL80211_CMD_VENDOR)) ||
9854 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9855 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9856 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9857 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
9858 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9859 !(params = nla_nest_start(
9860 msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OMI_TX)) ||
9861 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9862 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_RX_NSS, rx_nss) ||
9863 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_CH_BW, ch_bw) ||
9864 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_TX_NSTS, tx_nsts) ||
9865 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DATA_DISABLE,
9866 ulmu_data_dis) ||
9867 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DISABLE,
9868 ulmu_dis)) {
9869 sigma_dut_print(dut, DUT_MSG_ERROR,
9870 "%s: err in adding vendor_cmd and vendor_data",
9871 __func__);
9872 nlmsg_free(msg);
9873 return -1;
9874 }
9875 nla_nest_end(msg, attr1);
9876 nla_nest_end(msg, params);
9877 nla_nest_end(msg, attr);
9878
9879 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9880 if (ret) {
9881 sigma_dut_print(dut, DUT_MSG_ERROR,
9882 "%s: err in send_and_recv_msgs, ret=%d",
9883 __func__, ret);
9884 }
9885
9886 return ret;
9887#else /* NL80211_SUPPORT */
9888 sigma_dut_print(dut, DUT_MSG_ERROR,
9889 "OMI TX cannot be processed without NL80211_SUPPORT defined");
9890 return -1;
9891#endif /* NL80211_SUPPORT */
9892}
9893
9894
Jouni Malinen224e3902021-06-09 16:41:27 +03009895static enum sigma_cmd_result
9896cmd_sta_set_wireless_vht(struct sigma_dut *dut, struct sigma_conn *conn,
9897 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009898{
9899 const char *intf = get_param(cmd, "Interface");
9900 const char *val;
Arif Hussaina37e9552018-06-20 17:05:59 -07009901 const char *program;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009902 int tkip = -1;
9903 int wep = -1;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05309904 int iwpriv_status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009905
Arif Hussaina37e9552018-06-20 17:05:59 -07009906 program = get_param(cmd, "Program");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009907 val = get_param(cmd, "SGI80");
9908 if (val) {
9909 int sgi80;
9910
9911 sgi80 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009912 run_iwpriv(dut, intf, "shortgi %d", sgi80);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009913 }
9914
9915 val = get_param(cmd, "TxBF");
9916 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009917 switch (get_driver_type(dut)) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009918 case DRIVER_WCN:
9919 if (sta_set_tx_beamformee(dut, intf, 1)) {
9920 send_resp(dut, conn, SIGMA_ERROR,
9921 "ErrorCode,Failed to set TX beamformee enable");
Jouni Malinen224e3902021-06-09 16:41:27 +03009922 return STATUS_SENT_ERROR;
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009923 }
9924 break;
9925 case DRIVER_ATHEROS:
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009926 if (run_iwpriv(dut, intf, "vhtsubfee 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009927 send_resp(dut, conn, SIGMA_ERROR,
9928 "ErrorCode,Setting vhtsubfee failed");
Jouni Malinen224e3902021-06-09 16:41:27 +03009929 return STATUS_SENT_ERROR;
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009930 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009931 if (run_iwpriv(dut, intf, "vhtsubfer 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009932 send_resp(dut, conn, SIGMA_ERROR,
9933 "ErrorCode,Setting vhtsubfer failed");
Jouni Malinen224e3902021-06-09 16:41:27 +03009934 return STATUS_SENT_ERROR;
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009935 }
9936 break;
9937 default:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009938 sigma_dut_print(dut, DUT_MSG_ERROR,
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009939 "Unsupported driver type");
9940 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009941 }
9942 }
9943
9944 val = get_param(cmd, "MU_TxBF");
9945 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009946 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009947 case DRIVER_ATHEROS:
9948 ath_sta_set_txsp_stream(dut, intf, "1SS");
9949 ath_sta_set_rxsp_stream(dut, intf, "1SS");
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009950 run_iwpriv(dut, intf, "vhtmubfee 1");
9951 run_iwpriv(dut, intf, "vhtmubfer 1");
Sunil Duttae9e5d12018-06-29 11:50:47 +05309952 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009953 case DRIVER_WCN:
9954 if (wcn_sta_set_sp_stream(dut, intf, "1SS") < 0) {
9955 send_resp(dut, conn, SIGMA_ERROR,
9956 "ErrorCode,Failed to set RX/TXSP_STREAM");
Jouni Malinen224e3902021-06-09 16:41:27 +03009957 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009958 }
Sunil Duttae9e5d12018-06-29 11:50:47 +05309959 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009960 default:
9961 sigma_dut_print(dut, DUT_MSG_ERROR,
9962 "Setting SP_STREAM not supported");
9963 break;
9964 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009965 }
9966
9967 val = get_param(cmd, "LDPC");
9968 if (val) {
9969 int ldpc;
9970
9971 ldpc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05309972 iwpriv_status = run_iwpriv(dut, intf, "ldpc %d", ldpc);
9973 if (iwpriv_status)
9974 sta_config_params(dut, intf, STA_SET_LDPC, ldpc);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009975 }
9976
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08009977 val = get_param(cmd, "BCC");
9978 if (val) {
9979 int bcc;
9980
9981 bcc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
9982 /* use LDPC iwpriv itself to set bcc coding, bcc coding
9983 * is mutually exclusive to bcc */
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05309984 iwpriv_status = run_iwpriv(dut, intf, "ldpc %d", !bcc);
9985 if (iwpriv_status)
9986 sta_config_params(dut, intf, STA_SET_LDPC, !bcc);
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08009987 }
9988
Arif Hussain7b47d2d2018-05-09 10:44:02 -07009989 val = get_param(cmd, "MaxHE-MCS_1SS_RxMapLTE80");
9990 if (val && dut->sta_nss == 1)
9991 cmd_set_max_he_mcs(dut, intf, atoi(val));
9992
9993 val = get_param(cmd, "MaxHE-MCS_2SS_RxMapLTE80");
9994 if (val && dut->sta_nss == 2)
9995 cmd_set_max_he_mcs(dut, intf, atoi(val));
9996
Arif Hussainac6c5112018-05-25 17:34:00 -07009997 val = get_param(cmd, "MCS_FixedRate");
9998 if (val) {
9999#ifdef NL80211_SUPPORT
10000 int mcs, ratecode = 0;
10001 enum he_mcs_config mcs_config;
10002 int ret;
Jouni Malinenb9b671d2019-04-26 13:23:17 +030010003 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -070010004
10005 ratecode = (0x07 & dut->sta_nss) << 5;
10006 mcs = atoi(val);
10007 /* Add the MCS to the ratecode */
10008 if (mcs >= 0 && mcs <= 11) {
10009 ratecode += mcs;
10010 if (dut->device_type == STA_testbed &&
10011 mcs > 7 && mcs <= 11) {
10012 if (mcs <= 9)
10013 mcs_config = HE_80_MCS0_9;
10014 else
10015 mcs_config = HE_80_MCS0_11;
10016 ret = sta_set_he_mcs(dut, intf, mcs_config);
10017 if (ret) {
10018 sigma_dut_print(dut, DUT_MSG_ERROR,
10019 "MCS_FixedRate: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
10020 mcs, mcs_config, ret);
10021 }
10022 }
10023 snprintf(buf, sizeof(buf),
10024 "iwpriv %s set_11ax_rate 0x%03x",
10025 intf, ratecode);
10026 if (system(buf) != 0) {
10027 sigma_dut_print(dut, DUT_MSG_ERROR,
10028 "MCS_FixedRate: iwpriv setting of 11ax rates 0x%03x failed",
10029 ratecode);
10030 }
10031 } else {
10032 sigma_dut_print(dut, DUT_MSG_ERROR,
10033 "MCS_FixedRate: HE MCS %d not supported",
10034 mcs);
10035 }
10036#else /* NL80211_SUPPORT */
10037 sigma_dut_print(dut, DUT_MSG_ERROR,
10038 "MCS_FixedRate cannot be changed without NL80211_SUPPORT defined");
10039#endif /* NL80211_SUPPORT */
10040 }
10041
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010042 val = get_param(cmd, "opt_md_notif_ie");
10043 if (val) {
10044 char *result = NULL;
10045 char delim[] = ";";
10046 char token[30];
10047 int value, config_val = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010048 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010049
Peng Xub8fc5cc2017-05-10 17:27:28 -070010050 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010051 result = strtok_r(token, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010052
10053 /* Extract the NSS information */
10054 if (result) {
10055 value = atoi(result);
10056 switch (value) {
10057 case 1:
10058 config_val = 1;
10059 break;
10060 case 2:
10061 config_val = 3;
10062 break;
10063 case 3:
10064 config_val = 7;
10065 break;
10066 case 4:
10067 config_val = 15;
10068 break;
10069 default:
10070 config_val = 3;
10071 break;
10072 }
10073
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010074 run_iwpriv(dut, intf, "rxchainmask %d", config_val);
10075 run_iwpriv(dut, intf, "txchainmask %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010076
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010077 }
10078
10079 /* Extract the channel width information */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010080 result = strtok_r(NULL, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010081 if (result) {
10082 value = atoi(result);
10083 switch (value) {
10084 case 20:
10085 config_val = 0;
10086 break;
10087 case 40:
10088 config_val = 1;
10089 break;
10090 case 80:
10091 config_val = 2;
10092 break;
10093 case 160:
10094 config_val = 3;
10095 break;
10096 default:
10097 config_val = 2;
10098 break;
10099 }
10100
10101 dut->chwidth = config_val;
10102
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010103 run_iwpriv(dut, intf, "chwidth %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010104 }
10105
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010106 run_iwpriv(dut, intf, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010107 }
10108
10109 val = get_param(cmd, "nss_mcs_cap");
10110 if (val) {
10111 int nss, mcs;
10112 char token[20];
10113 char *result = NULL;
10114 unsigned int vht_mcsmap = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010115 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010116
Peng Xub8fc5cc2017-05-10 17:27:28 -070010117 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010118 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +053010119 if (!result) {
10120 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -070010121 "NSS not specified");
10122 send_resp(dut, conn, SIGMA_ERROR,
10123 "errorCode,NSS not specified");
Jouni Malinen224e3902021-06-09 16:41:27 +030010124 return STATUS_SENT_ERROR;
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +053010125 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010126 nss = atoi(result);
10127
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010128 run_iwpriv(dut, intf, "nss %d", nss);
Arif Hussainac6c5112018-05-25 17:34:00 -070010129 dut->sta_nss = nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010130
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010131 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010132 if (result == NULL) {
10133 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -070010134 "MCS not specified");
10135 send_resp(dut, conn, SIGMA_ERROR,
10136 "errorCode,MCS not specified");
Jouni Malinen224e3902021-06-09 16:41:27 +030010137 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010138 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010139 result = strtok_r(result, "-", &saveptr);
10140 result = strtok_r(NULL, "-", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +053010141 if (!result) {
10142 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -070010143 "MCS not specified");
10144 send_resp(dut, conn, SIGMA_ERROR,
10145 "errorCode,MCS not specified");
Jouni Malinen224e3902021-06-09 16:41:27 +030010146 return STATUS_SENT_ERROR;
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +053010147 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010148 mcs = atoi(result);
10149
Arif Hussaina37e9552018-06-20 17:05:59 -070010150 if (program && strcasecmp(program, "HE") == 0) {
10151#ifdef NL80211_SUPPORT
10152 enum he_mcs_config mcs_config;
10153 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010154
Arif Hussaina37e9552018-06-20 17:05:59 -070010155 if (mcs >= 0 && mcs <= 7) {
10156 mcs_config = HE_80_MCS0_7;
10157 } else if (mcs > 7 && mcs <= 9) {
10158 mcs_config = HE_80_MCS0_9;
10159 } else if (mcs > 9 && mcs <= 11) {
10160 mcs_config = HE_80_MCS0_11;
10161 } else {
10162 sigma_dut_print(dut, DUT_MSG_ERROR,
10163 "nss_mcs_cap: HE: Invalid mcs: %d",
10164 mcs);
10165 send_resp(dut, conn, SIGMA_ERROR,
10166 "errorCode,Invalid MCS");
Jouni Malinen224e3902021-06-09 16:41:27 +030010167 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010168 }
Arif Hussaina37e9552018-06-20 17:05:59 -070010169
10170 ret = sta_set_he_mcs(dut, intf, mcs_config);
10171 if (ret) {
10172 sigma_dut_print(dut, DUT_MSG_ERROR,
10173 "nss_mcs_cap: HE: Setting of MCS failed, mcs_config: %d, ret: %d",
10174 mcs_config, ret);
10175 send_resp(dut, conn, SIGMA_ERROR,
10176 "errorCode,Failed to set MCS");
Jouni Malinen224e3902021-06-09 16:41:27 +030010177 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010178 }
Arif Hussaina37e9552018-06-20 17:05:59 -070010179#else /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010180 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -070010181 "nss_mcs_cap: HE: MCS cannot be changed without NL80211_SUPPORT defined");
10182#endif /* NL80211_SUPPORT */
10183 } else {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010184 run_iwpriv(dut, intf, "vhtmcs %d", mcs);
Arif Hussaina37e9552018-06-20 17:05:59 -070010185
10186 switch (nss) {
10187 case 1:
10188 switch (mcs) {
10189 case 7:
10190 vht_mcsmap = 0xfffc;
10191 break;
10192 case 8:
10193 vht_mcsmap = 0xfffd;
10194 break;
10195 case 9:
10196 vht_mcsmap = 0xfffe;
10197 break;
10198 default:
10199 vht_mcsmap = 0xfffe;
10200 break;
10201 }
10202 break;
10203 case 2:
10204 switch (mcs) {
10205 case 7:
10206 vht_mcsmap = 0xfff0;
10207 break;
10208 case 8:
10209 vht_mcsmap = 0xfff5;
10210 break;
10211 case 9:
10212 vht_mcsmap = 0xfffa;
10213 break;
10214 default:
10215 vht_mcsmap = 0xfffa;
10216 break;
10217 }
10218 break;
10219 case 3:
10220 switch (mcs) {
10221 case 7:
10222 vht_mcsmap = 0xffc0;
10223 break;
10224 case 8:
10225 vht_mcsmap = 0xffd5;
10226 break;
10227 case 9:
10228 vht_mcsmap = 0xffea;
10229 break;
10230 default:
10231 vht_mcsmap = 0xffea;
10232 break;
10233 }
10234 break;
10235 default:
10236 vht_mcsmap = 0xffea;
10237 break;
10238 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010239 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010240 }
10241 }
10242
10243 /* UNSUPPORTED: val = get_param(cmd, "Tx_lgi_rate"); */
10244
10245 val = get_param(cmd, "Vht_tkip");
10246 if (val)
10247 tkip = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
10248
10249 val = get_param(cmd, "Vht_wep");
10250 if (val)
10251 wep = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
10252
10253 if (tkip != -1 || wep != -1) {
10254 if ((tkip == 1 && wep != 0) || (wep == 1 && tkip != 0)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010255 run_iwpriv(dut, intf, "htweptkip 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010256 } else if ((tkip == 0 && wep != 1) || (wep == 0 && tkip != 1)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010257 run_iwpriv(dut, intf, "htweptkip 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010258 } else {
Jouni Malinen224e3902021-06-09 16:41:27 +030010259 send_resp(dut, conn, SIGMA_ERROR,
10260 "ErrorCode,mixed mode of VHT TKIP/WEP not supported");
10261 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010262 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010263 }
10264
Kiran Kumar Lokere09dbcef2021-08-09 00:01:41 -070010265 val = get_param(cmd, "TWTSchedSTASupport");
10266 if (val) {
10267 int set_val;
10268
10269 switch (get_driver_type(dut)) {
10270 case DRIVER_WCN:
10271 if (strcasecmp(val, "Enable") == 0) {
10272 set_val = 1;
10273 } else if (strcasecmp(val, "Disable") == 0) {
10274 set_val = 0;
10275 } else {
10276 send_resp(dut, conn, SIGMA_ERROR,
10277 "ErrorCode,Invalid TWTSchedSTASupport");
10278 return STATUS_SENT_ERROR;
10279 }
10280
10281 if (sta_set_bcast_twt_support(dut, intf, set_val)) {
10282 send_resp(dut, conn, SIGMA_ERROR,
10283 "ErrorCode,Failed to set TWTSchedSTASupport");
10284 return STATUS_SENT_ERROR;
10285 }
10286 break;
10287 default:
10288 sigma_dut_print(dut, DUT_MSG_ERROR,
10289 "Setting TWTSchedSTASupport not supported");
10290 break;
10291 }
10292 }
10293
10294 val = get_param(cmd, "MBSSID_RxCtrl");
10295 if (val) {
10296 int set_val;
10297
10298 switch (get_driver_type(dut)) {
10299 case DRIVER_WCN:
10300 if (strcasecmp(val, "Enable") == 0) {
10301 set_val = 1;
10302 } else if (strcasecmp(val, "Disable") == 0) {
10303 set_val = 0;
10304 } else {
10305 send_resp(dut, conn, SIGMA_ERROR,
10306 "ErrorCode,Invalid MBSSID_RxCtrl");
10307 return STATUS_SENT_ERROR;
10308 }
10309
10310 if (sta_set_rx_ctrl_multi_bss(dut, intf, set_val)) {
10311 send_resp(dut, conn, SIGMA_ERROR,
10312 "ErrorCode,Failed to set MBSSID_RxCtrl");
10313 return STATUS_SENT_ERROR;
10314 }
10315 break;
10316 default:
10317 sigma_dut_print(dut, DUT_MSG_ERROR,
10318 "Setting MBSSID_RxCtrl not supported");
10319 break;
10320 }
10321 }
10322
Arif Hussain55f00da2018-07-03 08:28:26 -070010323 val = get_param(cmd, "txBandwidth");
10324 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010325 switch (get_driver_type(dut)) {
Arif Hussain55f00da2018-07-03 08:28:26 -070010326 case DRIVER_WCN:
10327 if (wcn_sta_set_width(dut, intf, val) < 0) {
10328 send_resp(dut, conn, SIGMA_ERROR,
10329 "ErrorCode,Failed to set txBandwidth");
Jouni Malinen224e3902021-06-09 16:41:27 +030010330 return STATUS_SENT_ERROR;
Arif Hussain55f00da2018-07-03 08:28:26 -070010331 }
10332 break;
10333 case DRIVER_ATHEROS:
10334 if (ath_set_width(dut, conn, intf, val) < 0) {
10335 send_resp(dut, conn, SIGMA_ERROR,
10336 "ErrorCode,Failed to set txBandwidth");
Jouni Malinen224e3902021-06-09 16:41:27 +030010337 return STATUS_SENT_ERROR;
Arif Hussain55f00da2018-07-03 08:28:26 -070010338 }
10339 break;
10340 default:
10341 sigma_dut_print(dut, DUT_MSG_ERROR,
10342 "Setting txBandwidth not supported");
10343 break;
10344 }
10345 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010346
Arif Hussain9765f7d2018-07-03 08:28:26 -070010347 val = get_param(cmd, "BeamformeeSTS");
10348 if (val) {
Kiran Kumar Lokerebc89d432018-07-10 12:20:13 -070010349 if (sta_set_tx_beamformee(dut, intf, 1)) {
10350 send_resp(dut, conn, SIGMA_ERROR,
10351 "ErrorCode,Failed to set TX beamformee enable");
Jouni Malinen224e3902021-06-09 16:41:27 +030010352 return STATUS_SENT_ERROR;
Kiran Kumar Lokerebc89d432018-07-10 12:20:13 -070010353 }
10354
Arif Hussain9765f7d2018-07-03 08:28:26 -070010355 if (sta_set_beamformee_sts(dut, intf, atoi(val))) {
10356 send_resp(dut, conn, SIGMA_ERROR,
10357 "ErrorCode,Failed to set BeamformeeSTS");
Jouni Malinen224e3902021-06-09 16:41:27 +030010358 return STATUS_SENT_ERROR;
Arif Hussain9765f7d2018-07-03 08:28:26 -070010359 }
10360 }
10361
Arif Hussain68d23f52018-07-11 13:39:08 -070010362 val = get_param(cmd, "Trig_MAC_Padding_Dur");
10363 if (val) {
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -070010364#ifdef NL80211_SUPPORT
10365 enum qca_wlan_he_mac_padding_dur set_val;
10366
10367 switch (atoi(val)) {
10368 case 16:
10369 set_val = QCA_WLAN_HE_16US_OF_PROCESS_TIME;
10370 break;
10371 case 8:
10372 set_val = QCA_WLAN_HE_8US_OF_PROCESS_TIME;
10373 break;
10374 default:
10375 set_val = QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME;
10376 break;
10377 }
10378 if (sta_set_mac_padding_duration(dut, intf, set_val)) {
Arif Hussain68d23f52018-07-11 13:39:08 -070010379 send_resp(dut, conn, SIGMA_ERROR,
10380 "ErrorCode,Failed to set MAC padding duration");
Jouni Malinen224e3902021-06-09 16:41:27 +030010381 return STATUS_SENT_ERROR;
Arif Hussain68d23f52018-07-11 13:39:08 -070010382 }
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -070010383#else /* NL80211_SUPPORT */
10384 sigma_dut_print(dut, DUT_MSG_ERROR,
10385 "MAC padding duration cannot be changed without NL80211_SUPPORT defined");
10386#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -070010387 }
10388
Arif Hussain480d5f42019-03-12 14:40:42 -070010389 val = get_param(cmd, "TWT_ReqSupport");
10390 if (val) {
10391 int set_val;
10392
10393 if (strcasecmp(val, "Enable") == 0) {
10394 set_val = 1;
10395 } else if (strcasecmp(val, "Disable") == 0) {
10396 set_val = 0;
10397 } else {
10398 send_resp(dut, conn, SIGMA_ERROR,
10399 "ErrorCode,Invalid TWT_ReqSupport");
Jouni Malinen224e3902021-06-09 16:41:27 +030010400 return STATUS_SENT_ERROR;
Arif Hussain480d5f42019-03-12 14:40:42 -070010401 }
10402
10403 if (sta_set_twt_req_support(dut, intf, set_val)) {
10404 sigma_dut_print(dut, DUT_MSG_ERROR,
10405 "Failed to set TWT req support %d",
10406 set_val);
10407 send_resp(dut, conn, SIGMA_ERROR,
10408 "ErrorCode,Failed to set TWT_ReqSupport");
Jouni Malinen224e3902021-06-09 16:41:27 +030010409 return STATUS_SENT_ERROR;
Arif Hussain480d5f42019-03-12 14:40:42 -070010410 }
10411 }
10412
Kiran Kumar Lokered0ec5ed2021-04-01 00:15:04 -070010413 val = get_param(cmd, "PreamblePunctRx");
10414 if (val && get_driver_type(dut) == DRIVER_WCN) {
10415 int set_val;
10416
10417 if (strcasecmp(val, "Enable") == 0) {
10418 set_val = 1;
10419 } else if (strcasecmp(val, "Disable") == 0) {
10420 set_val = 0;
10421 } else {
10422 send_resp(dut, conn, SIGMA_ERROR,
10423 "ErrorCode,Invalid PreamblePunctRx");
10424 return STATUS_SENT_ERROR;
10425 }
10426
10427 if (sta_set_punctured_preamble_rx(dut, intf, set_val)) {
10428 sigma_dut_print(dut, DUT_MSG_ERROR,
10429 "Failed to set PreamblePunctRx support %d",
10430 set_val);
10431 send_resp(dut, conn, SIGMA_ERROR,
10432 "ErrorCode,Failed to set PreamblePunctRx");
10433 return STATUS_SENT_ERROR;
10434 }
10435 }
10436
Srinivas Girigowda0525e292020-11-12 13:28:21 -080010437 val = get_param(cmd, "FullBW_ULMUMIMO");
10438 if (val) {
10439 int set_val;
10440
10441 if (strcasecmp(val, "Enable") == 0) {
10442 set_val = 1;
10443 } else if (strcasecmp(val, "Disable") == 0) {
10444 set_val = 0;
10445 } else {
10446 send_resp(dut, conn, SIGMA_ERROR,
10447 "ErrorCode,Invalid FullBW_ULMUMIMO");
10448 return STATUS_SENT_ERROR;
10449 }
10450
10451 if (sta_set_fullbw_ulmumimo(dut, intf, set_val)) {
10452 sigma_dut_print(dut, DUT_MSG_ERROR,
10453 "Failed to set FullBW_ULMUMIMO %d",
10454 set_val);
10455 send_resp(dut, conn, SIGMA_ERROR,
10456 "ErrorCode,Failed to set FullBW_ULMUMIMO");
10457 return STATUS_SENT_ERROR;
10458 }
10459 }
10460
Srinivas Girigowda6707f032020-10-26 15:24:46 -070010461 val = get_param(cmd, "TWTInfoFrameTx");
10462 if (val) {
10463 if (strcasecmp(val, "Enable") == 0) {
10464 /* No-op */
10465 } else if (strcasecmp(val, "Disable") == 0) {
10466 /* No-op */
10467 } else {
10468 send_resp(dut, conn, SIGMA_ERROR,
10469 "ErrorCode,Invalid TWTInfoFrameTx");
10470 return STATUS_SENT_ERROR;
10471 }
10472 }
10473
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -070010474 val = get_param(cmd, "MU_EDCA");
10475 if (val && (strcasecmp(val, "Override") == 0)) {
10476 if (sta_set_mu_edca_override(dut, intf, 1)) {
10477 send_resp(dut, conn, SIGMA_ERROR,
10478 "ErrorCode,Failed to set MU EDCA override");
Jouni Malinen224e3902021-06-09 16:41:27 +030010479 return STATUS_SENT_ERROR;
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -070010480 }
10481 }
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -070010482
Kiran Kumar Lokerefa7c7b92021-08-09 00:50:55 -070010483 val = get_param(cmd, "PPDUTxType");
10484 if (val && strcasecmp(val, "ER-SU") == 0) {
10485 if (sta_set_er_su_ppdu_type_tx(dut, intf, 1)) {
10486 send_resp(dut, conn, SIGMA_ERROR,
10487 "ErrorCode,Failed to set ER-SU PPDU type Tx");
10488 return STATUS_SENT_ERROR;
10489 }
10490 }
10491
10492 val = get_param(cmd, "RUAllocTone");
10493 if (val && strcasecmp(val, "242") == 0) {
10494 if (sta_set_ru_242_tone_tx(dut, intf, 1)) {
10495 send_resp(dut, conn, SIGMA_ERROR,
10496 "ErrorCode,Failed to set RU 242 tone Tx");
10497 return STATUS_SENT_ERROR;
10498 }
10499 }
10500
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -070010501 val = get_param(cmd, "OMControl");
10502 if (val) {
10503 int set_val = 1;
10504
10505 if (strcasecmp(val, "Enable") == 0)
10506 set_val = 1;
10507 else if (strcasecmp(val, "Disable") == 0)
10508 set_val = 0;
10509
10510 if (sta_set_om_ctrl_supp(dut, intf, set_val)) {
10511 send_resp(dut, conn, SIGMA_ERROR,
10512 "ErrorCode,Failed to set OM ctrl supp");
Jouni Malinen224e3902021-06-09 16:41:27 +030010513 return STATUS_SENT_ERROR;
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -070010514 }
10515 }
10516
Kiran Kumar Lokere4f2d4b02021-04-01 00:07:39 -070010517 val = get_param(cmd, "BSSMaxIdlePeriod");
10518 if (val && sta_set_bss_max_idle_period(dut, intf, atoi(val))) {
10519 send_resp(dut, conn, SIGMA_ERROR,
10520 "ErrorCode,Failed to set BSS max idle period");
10521 return STATUS_SENT_ERROR;
10522 }
10523
Kiran Kumar Lokere07ad92b2021-08-09 00:27:14 -070010524 val = get_param(cmd, "BSS_max_idle");
10525 if (val) {
10526 int set_val = 0;
10527
10528 if (strcasecmp(val, "Enable") == 0)
10529 set_val = 1;
10530 else if (strcasecmp(val, "Disable") == 0)
10531 set_val = 0;
10532 if (sta_set_bss_max_idle_support(dut, intf, set_val)) {
10533 send_resp(dut, conn, SIGMA_ERROR,
10534 "ErrorCode,Failed to set BSS max idle support");
10535 return STATUS_SENT_ERROR;
10536 }
10537 }
10538
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -070010539 val = get_param(cmd, "ADDBAResp_BufSize");
10540 if (val) {
10541 int buf_size;
10542
10543 if (strcasecmp(val, "gt64") == 0)
10544 buf_size = 256;
10545 else
10546 buf_size = 64;
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010547 if (get_driver_type(dut) == DRIVER_WCN &&
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -070010548 sta_set_addba_buf_size(dut, intf, buf_size)) {
10549 send_resp(dut, conn, SIGMA_ERROR,
10550 "ErrorCode,set addbaresp_buff_size failed");
Jouni Malinen224e3902021-06-09 16:41:27 +030010551 return STATUS_SENT_ERROR;
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -070010552 }
10553 }
10554
10555 val = get_param(cmd, "ADDBAReq_BufSize");
10556 if (val) {
10557 int buf_size;
10558
10559 if (strcasecmp(val, "gt64") == 0)
10560 buf_size = 256;
10561 else
10562 buf_size = 64;
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010563 if (get_driver_type(dut) == DRIVER_WCN &&
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -070010564 sta_set_addba_buf_size(dut, intf, buf_size)) {
10565 send_resp(dut, conn, SIGMA_ERROR,
10566 "ErrorCode,set addbareq_buff_size failed");
Jouni Malinen224e3902021-06-09 16:41:27 +030010567 return STATUS_SENT_ERROR;
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -070010568 }
10569 }
10570
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010571 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
10572}
10573
10574
10575static int sta_set_wireless_60g(struct sigma_dut *dut,
10576 struct sigma_conn *conn,
10577 struct sigma_cmd *cmd)
10578{
10579 const char *dev_role = get_param(cmd, "DevRole");
10580
10581 if (!dev_role) {
10582 send_resp(dut, conn, SIGMA_INVALID,
10583 "ErrorCode,DevRole not specified");
10584 return 0;
10585 }
10586
10587 if (strcasecmp(dev_role, "PCP") == 0)
10588 return sta_set_60g_pcp(dut, conn, cmd);
10589 if (strcasecmp(dev_role, "STA") == 0)
10590 return sta_set_60g_sta(dut, conn, cmd);
10591 send_resp(dut, conn, SIGMA_INVALID,
10592 "ErrorCode,DevRole not supported");
10593 return 0;
10594}
10595
10596
Ankita Bajaj0d5825b2017-10-25 16:20:17 +053010597static int sta_set_wireless_oce(struct sigma_dut *dut, struct sigma_conn *conn,
10598 struct sigma_cmd *cmd)
10599{
10600 int status;
10601 const char *intf = get_param(cmd, "Interface");
10602 const char *val = get_param(cmd, "DevRole");
10603
10604 if (val && strcasecmp(val, "STA-CFON") == 0) {
10605 status = sta_cfon_set_wireless(dut, conn, cmd);
10606 if (status)
10607 return status;
10608 }
10609 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
10610}
10611
10612
Jouni Malinen67433fc2020-06-26 22:50:33 +030010613static enum sigma_cmd_result
10614sta_set_wireless_wpa3(struct sigma_dut *dut, struct sigma_conn *conn,
10615 struct sigma_cmd *cmd)
Vamsi Krishnac1633d22020-05-06 18:31:21 +053010616{
10617 const char *intf = get_param(cmd, "Interface");
10618 const char *val;
10619
10620 val = get_param(cmd, "ocvc");
10621 if (val)
10622 dut->ocvc = atoi(val);
10623
Jouni Malinen67433fc2020-06-26 22:50:33 +030010624 val = get_param(cmd, "ClientPrivacy");
Veerendranath Jakkam47867202020-12-21 01:53:52 +053010625 if (val && dut->client_privacy != atoi(val) &&
10626 sta_set_client_privacy(dut, conn, intf, atoi(val))) {
10627 send_resp(dut, conn, SIGMA_ERROR,
10628 "errorCode,Failed to configure random MAC address use");
10629 return STATUS_SENT_ERROR;
Jouni Malinen67433fc2020-06-26 22:50:33 +030010630 }
10631
Vamsi Krishnac1633d22020-05-06 18:31:21 +053010632 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
10633}
10634
10635
Jouni Malinenf7222712019-06-13 01:50:21 +030010636static enum sigma_cmd_result cmd_sta_set_wireless(struct sigma_dut *dut,
10637 struct sigma_conn *conn,
10638 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010639{
10640 const char *val;
10641
10642 val = get_param(cmd, "Program");
10643 if (val) {
10644 if (strcasecmp(val, "11n") == 0)
10645 return cmd_sta_set_11n(dut, conn, cmd);
Amarnath Hullur Subramanyam4f860292018-01-31 03:49:35 -080010646 if (strcasecmp(val, "VHT") == 0 || strcasecmp(val, "HE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010647 return cmd_sta_set_wireless_vht(dut, conn, cmd);
10648 if (strcasecmp(val, "60ghz") == 0)
10649 return sta_set_wireless_60g(dut, conn, cmd);
Ankita Bajaj0d5825b2017-10-25 16:20:17 +053010650 if (strcasecmp(val, "OCE") == 0)
10651 return sta_set_wireless_oce(dut, conn, cmd);
Alexei Avshalom Lazar66bb9972018-12-18 16:01:43 +020010652 /* sta_set_wireless in WPS program is only used for 60G */
10653 if (is_60g_sigma_dut(dut))
10654 return sta_set_wireless_60g(dut, conn, cmd);
Vamsi Krishnac1633d22020-05-06 18:31:21 +053010655 if (strcasecmp(val, "WPA3") == 0)
10656 return sta_set_wireless_wpa3(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010657 send_resp(dut, conn, SIGMA_ERROR,
10658 "ErrorCode,Program value not supported");
10659 } else {
10660 send_resp(dut, conn, SIGMA_ERROR,
10661 "ErrorCode,Program argument not available");
10662 }
10663
10664 return 0;
10665}
10666
10667
10668static void ath_sta_inject_frame(struct sigma_dut *dut, const char *intf,
10669 int tid)
10670{
10671 char buf[100];
10672 int tid_to_dscp [] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 };
10673
Pradeep Reddy POTTETId31d1322016-10-13 17:22:03 +053010674 if (tid < 0 ||
10675 tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) {
10676 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid);
10677 return;
10678 }
10679
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010680 /*
10681 * Two ways to ensure that addba request with a
10682 * non zero TID could be sent out. EV 117296
10683 */
10684 snprintf(buf, sizeof(buf),
10685 "ping -c 8 -Q %d `arp -a | grep wlan0 | awk '{print $2}' | tr -d '()'`",
10686 tid);
10687 if (system(buf) != 0) {
10688 sigma_dut_print(dut, DUT_MSG_ERROR,
10689 "Ping did not send out");
10690 }
10691
10692 snprintf(buf, sizeof(buf),
10693 "iwconfig %s | grep Access | awk '{print $6}' > %s",
10694 intf, VI_QOS_TMP_FILE);
10695 if (system(buf) != 0)
10696 return;
10697
10698 snprintf(buf, sizeof(buf),
10699 "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s",
10700 intf, VI_QOS_TMP_FILE);
10701 if (system(buf) != 0)
10702 sigma_dut_print(dut, DUT_MSG_ERROR, "HWaddr matching failed");
10703
10704 snprintf(buf,sizeof(buf), "sed -n '3,$p' %s >> %s",
10705 VI_QOS_REFFILE, VI_QOS_TMP_FILE);
10706 if (system(buf) != 0) {
10707 sigma_dut_print(dut, DUT_MSG_ERROR,
10708 "VI_QOS_TEMP_FILE generation error failed");
10709 }
10710 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
10711 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
10712 if (system(buf) != 0) {
10713 sigma_dut_print(dut, DUT_MSG_ERROR,
10714 "VI_QOS_FILE generation failed");
10715 }
10716
10717 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
10718 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
10719 if (system(buf) != 0) {
10720 sigma_dut_print(dut, DUT_MSG_ERROR,
10721 "VI_QOS_FILE generation failed");
10722 }
10723
10724 snprintf(buf, sizeof(buf), "ethinject %s %s", intf, VI_QOS_FILE);
10725 if (system(buf) != 0) {
10726 }
10727}
10728
10729
10730static int ath_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
10731 struct sigma_cmd *cmd)
10732{
10733 const char *intf = get_param(cmd, "Interface");
10734 const char *val;
10735 int tid = 0;
10736 char buf[100];
10737
10738 val = get_param(cmd, "TID");
10739 if (val) {
10740 tid = atoi(val);
10741 if (tid)
10742 ath_sta_inject_frame(dut, intf, tid);
10743 }
10744
10745 /* Command sequence for ADDBA request on Peregrine based devices */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010746 run_iwpriv(dut, intf, "setaddbaoper 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010747
10748 snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4", intf, tid);
10749 if (system(buf) != 0) {
10750 sigma_dut_print(dut, DUT_MSG_ERROR,
10751 "wifitool senddelba failed");
10752 }
10753
10754 snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64", intf, tid);
10755 if (system(buf) != 0) {
10756 sigma_dut_print(dut, DUT_MSG_ERROR,
10757 "wifitool sendaddba failed");
10758 }
10759
10760 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
10761
10762 return 1;
10763}
10764
10765
Lior David9981b512017-01-20 13:16:40 +020010766#ifdef __linux__
10767
10768static int wil6210_send_addba(struct sigma_dut *dut, const char *dest_mac,
10769 int agg_size)
10770{
10771 char dir[128], buf[128];
10772 FILE *f;
10773 regex_t re;
10774 regmatch_t m[2];
Jouni Malinen3aa72862019-05-29 23:14:51 +030010775 int rc, ret = -1, vring_id, found, res;
Lior David9981b512017-01-20 13:16:40 +020010776
10777 if (wil6210_get_debugfs_dir(dut, dir, sizeof(dir))) {
10778 sigma_dut_print(dut, DUT_MSG_ERROR,
10779 "failed to get wil6210 debugfs dir");
10780 return -1;
10781 }
10782
Jouni Malinen3aa72862019-05-29 23:14:51 +030010783 res = snprintf(buf, sizeof(buf), "%s/vrings", dir);
10784 if (res < 0 || res >= sizeof(buf))
10785 return -1;
Lior David9981b512017-01-20 13:16:40 +020010786 f = fopen(buf, "r");
10787 if (!f) {
10788 sigma_dut_print(dut, DUT_MSG_ERROR, "failed to open: %s", buf);
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +020010789 /* newer wil6210 driver renamed file to "rings" */
Jouni Malinen3aa72862019-05-29 23:14:51 +030010790 res = snprintf(buf, sizeof(buf), "%s/rings", dir);
10791 if (res < 0 || res >= sizeof(buf))
10792 return -1;
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +020010793 f = fopen(buf, "r");
10794 if (!f) {
10795 sigma_dut_print(dut, DUT_MSG_ERROR,
10796 "failed to open: %s", buf);
10797 return -1;
10798 }
Lior David9981b512017-01-20 13:16:40 +020010799 }
10800
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +020010801 /* can be either VRING tx... or RING... */
10802 if (regcomp(&re, "RING tx_[ \t]*([0-9]+)", REG_EXTENDED)) {
Lior David9981b512017-01-20 13:16:40 +020010803 sigma_dut_print(dut, DUT_MSG_ERROR, "regcomp failed");
10804 goto out;
10805 }
10806
10807 /* find TX VRING for the mac address */
10808 found = 0;
10809 while (fgets(buf, sizeof(buf), f)) {
10810 if (strcasestr(buf, dest_mac)) {
10811 found = 1;
10812 break;
10813 }
10814 }
10815
10816 if (!found) {
10817 sigma_dut_print(dut, DUT_MSG_ERROR,
10818 "no TX VRING for %s", dest_mac);
10819 goto out;
10820 }
10821
10822 /* extract VRING ID, "VRING tx_<id> = {" */
10823 if (!fgets(buf, sizeof(buf), f)) {
10824 sigma_dut_print(dut, DUT_MSG_ERROR,
10825 "no VRING start line for %s", dest_mac);
10826 goto out;
10827 }
10828
10829 rc = regexec(&re, buf, 2, m, 0);
10830 regfree(&re);
10831 if (rc || m[1].rm_so < 0) {
10832 sigma_dut_print(dut, DUT_MSG_ERROR,
10833 "no VRING TX ID for %s", dest_mac);
10834 goto out;
10835 }
10836 buf[m[1].rm_eo] = 0;
10837 vring_id = atoi(&buf[m[1].rm_so]);
10838
10839 /* send the addba command */
10840 fclose(f);
Jouni Malinen3aa72862019-05-29 23:14:51 +030010841 res = snprintf(buf, sizeof(buf), "%s/back", dir);
10842 if (res < 0 || res >= sizeof(buf))
10843 return -1;
Lior David9981b512017-01-20 13:16:40 +020010844 f = fopen(buf, "w");
10845 if (!f) {
10846 sigma_dut_print(dut, DUT_MSG_ERROR,
10847 "failed to open: %s", buf);
10848 return -1;
10849 }
10850
10851 fprintf(f, "add %d %d\n", vring_id, agg_size);
10852
10853 ret = 0;
10854
10855out:
10856 fclose(f);
10857
10858 return ret;
10859}
10860
10861
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +020010862int send_addba_60g(struct sigma_dut *dut, struct sigma_conn *conn,
10863 struct sigma_cmd *cmd, const char *mac_param)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010864{
10865 const char *val;
10866 int tid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010867
10868 val = get_param(cmd, "TID");
10869 if (val) {
10870 tid = atoi(val);
10871 if (tid != 0) {
10872 sigma_dut_print(dut, DUT_MSG_ERROR,
10873 "Ignore TID %d for send_addba use TID 0 for 60g since only 0 required on TX",
10874 tid);
10875 }
10876 }
10877
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +020010878 val = get_param(cmd, mac_param);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010879 if (!val) {
10880 sigma_dut_print(dut, DUT_MSG_ERROR,
10881 "Currently not supporting addba for 60G without Dest_mac");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020010882 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010883 }
10884
Lior David9981b512017-01-20 13:16:40 +020010885 if (wil6210_send_addba(dut, val, dut->back_rcv_buf))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010886 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010887
10888 return 1;
10889}
10890
Lior David9981b512017-01-20 13:16:40 +020010891#endif /* __linux__ */
10892
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010893
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080010894static int wcn_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
10895 struct sigma_cmd *cmd)
10896{
10897#ifdef NL80211_SUPPORT
10898 const char *intf = get_param(cmd, "Interface");
10899 const char *val;
10900 int tid = -1;
10901 int bufsize = 64;
10902 struct nl_msg *msg;
10903 int ret = 0;
10904 struct nlattr *params;
10905 int ifindex;
10906
10907 val = get_param(cmd, "TID");
10908 if (val)
10909 tid = atoi(val);
10910
10911 if (tid == -1) {
10912 send_resp(dut, conn, SIGMA_ERROR,
10913 "ErrorCode,sta_send_addba tid invalid");
10914 return 0;
10915 }
10916
10917 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
10918
10919 ifindex = if_nametoindex(intf);
10920 if (ifindex == 0) {
10921 sigma_dut_print(dut, DUT_MSG_ERROR,
10922 "%s: Index for interface %s failed",
10923 __func__, intf);
10924 send_resp(dut, conn, SIGMA_ERROR,
10925 "ErrorCode,sta_send_addba interface invalid");
10926 return 0;
10927 }
10928
10929 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
10930 NL80211_CMD_VENDOR)) ||
10931 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
10932 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
10933 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
10934 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
10935 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
10936 nla_put_u8(msg,
10937 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADD_DEL_BA_SESSION,
10938 QCA_WLAN_ADD_BA) ||
10939 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BA_TID,
10940 tid) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -070010941 nla_put_u16(msg,
10942 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
10943 bufsize)) {
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080010944 sigma_dut_print(dut, DUT_MSG_ERROR,
10945 "%s: err in adding vendor_cmd and vendor_data",
10946 __func__);
10947 nlmsg_free(msg);
10948 send_resp(dut, conn, SIGMA_ERROR,
10949 "ErrorCode,sta_send_addba err in adding vendor_cmd and vendor_data");
10950 return 0;
10951 }
10952 nla_nest_end(msg, params);
10953
10954 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
10955 if (ret) {
10956 sigma_dut_print(dut, DUT_MSG_ERROR,
10957 "%s: err in send_and_recv_msgs, ret=%d",
10958 __func__, ret);
Sunil Dutt30605592018-05-04 20:35:50 +053010959 if (ret == -EOPNOTSUPP)
10960 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080010961 send_resp(dut, conn, SIGMA_ERROR,
10962 "ErrorCode,sta_send_addba err in send_and_recv_msgs");
10963 return 0;
10964 }
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080010965#else /* NL80211_SUPPORT */
10966 sigma_dut_print(dut, DUT_MSG_ERROR,
10967 "sta_send_addba not supported without NL80211_SUPPORT defined");
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080010968#endif /* NL80211_SUPPORT */
Sunil Dutt30605592018-05-04 20:35:50 +053010969
10970 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080010971}
10972
10973
Jouni Malinenf7222712019-06-13 01:50:21 +030010974static enum sigma_cmd_result cmd_sta_send_addba(struct sigma_dut *dut,
10975 struct sigma_conn *conn,
10976 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010977{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010978 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010979 case DRIVER_ATHEROS:
10980 return ath_sta_send_addba(dut, conn, cmd);
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080010981 case DRIVER_WCN:
10982 return wcn_sta_send_addba(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +020010983#ifdef __linux__
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010984 case DRIVER_WIL6210:
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +020010985 return send_addba_60g(dut, conn, cmd, "Dest_mac");
Lior David9981b512017-01-20 13:16:40 +020010986#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010987 default:
10988 /*
10989 * There is no driver specific implementation for other drivers.
10990 * Ignore the command and report COMPLETE since the following
10991 * throughput test operation will end up sending ADDBA anyway.
10992 */
10993 return 1;
10994 }
10995}
10996
10997
10998int inject_eth_frame(int s, const void *data, size_t len,
10999 unsigned short ethtype, char *dst, char *src)
11000{
11001 struct iovec iov[4] = {
11002 {
11003 .iov_base = dst,
11004 .iov_len = ETH_ALEN,
11005 },
11006 {
11007 .iov_base = src,
11008 .iov_len = ETH_ALEN,
11009 },
11010 {
11011 .iov_base = &ethtype,
11012 .iov_len = sizeof(unsigned short),
11013 },
11014 {
11015 .iov_base = (void *) data,
11016 .iov_len = len,
11017 }
11018 };
11019 struct msghdr msg = {
11020 .msg_name = NULL,
11021 .msg_namelen = 0,
11022 .msg_iov = iov,
11023 .msg_iovlen = 4,
11024 .msg_control = NULL,
11025 .msg_controllen = 0,
11026 .msg_flags = 0,
11027 };
11028
11029 return sendmsg(s, &msg, 0);
11030}
11031
11032#if defined(__linux__) || defined(__QNXNTO__)
11033
11034int inject_frame(int s, const void *data, size_t len, int encrypt)
11035{
11036#define IEEE80211_RADIOTAP_F_WEP 0x04
11037#define IEEE80211_RADIOTAP_F_FRAG 0x08
11038 unsigned char rtap_hdr[] = {
11039 0x00, 0x00, /* radiotap version */
11040 0x0e, 0x00, /* radiotap length */
11041 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
11042 IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */
11043 0x00, /* padding */
11044 0x00, 0x00, /* RX and TX flags to indicate that */
11045 0x00, 0x00, /* this is the injected frame directly */
11046 };
11047 struct iovec iov[2] = {
11048 {
11049 .iov_base = &rtap_hdr,
11050 .iov_len = sizeof(rtap_hdr),
11051 },
11052 {
11053 .iov_base = (void *) data,
11054 .iov_len = len,
11055 }
11056 };
11057 struct msghdr msg = {
11058 .msg_name = NULL,
11059 .msg_namelen = 0,
11060 .msg_iov = iov,
11061 .msg_iovlen = 2,
11062 .msg_control = NULL,
11063 .msg_controllen = 0,
11064 .msg_flags = 0,
11065 };
11066
11067 if (encrypt)
11068 rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP;
11069
11070 return sendmsg(s, &msg, 0);
11071}
11072
11073
11074int open_monitor(const char *ifname)
11075{
11076#ifdef __QNXNTO__
11077 struct sockaddr_dl ll;
11078 int s;
11079
11080 memset(&ll, 0, sizeof(ll));
11081 ll.sdl_family = AF_LINK;
11082 ll.sdl_index = if_nametoindex(ifname);
11083 if (ll.sdl_index == 0) {
11084 perror("if_nametoindex");
11085 return -1;
11086 }
11087 s = socket(PF_INET, SOCK_RAW, 0);
11088#else /* __QNXNTO__ */
11089 struct sockaddr_ll ll;
11090 int s;
11091
11092 memset(&ll, 0, sizeof(ll));
11093 ll.sll_family = AF_PACKET;
11094 ll.sll_ifindex = if_nametoindex(ifname);
11095 if (ll.sll_ifindex == 0) {
11096 perror("if_nametoindex");
11097 return -1;
11098 }
11099 s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
11100#endif /* __QNXNTO__ */
11101 if (s < 0) {
11102 perror("socket[PF_PACKET,SOCK_RAW]");
11103 return -1;
11104 }
11105
11106 if (bind(s, (struct sockaddr *) &ll, sizeof(ll)) < 0) {
11107 perror("monitor socket bind");
11108 close(s);
11109 return -1;
11110 }
11111
11112 return s;
11113}
11114
11115
11116static int hex2num(char c)
11117{
11118 if (c >= '0' && c <= '9')
11119 return c - '0';
11120 if (c >= 'a' && c <= 'f')
11121 return c - 'a' + 10;
11122 if (c >= 'A' && c <= 'F')
11123 return c - 'A' + 10;
11124 return -1;
11125}
11126
11127
11128int hwaddr_aton(const char *txt, unsigned char *addr)
11129{
11130 int i;
11131
11132 for (i = 0; i < 6; i++) {
11133 int a, b;
11134
11135 a = hex2num(*txt++);
11136 if (a < 0)
11137 return -1;
11138 b = hex2num(*txt++);
11139 if (b < 0)
11140 return -1;
11141 *addr++ = (a << 4) | b;
11142 if (i < 5 && *txt++ != ':')
11143 return -1;
11144 }
11145
11146 return 0;
11147}
11148
11149#endif /* defined(__linux__) || defined(__QNXNTO__) */
11150
Veerendranath Jakkam49774122020-07-05 09:52:18 +053011151
11152#ifdef NL80211_SUPPORT
11153static int nl80211_send_frame_cmd(struct sigma_dut *dut, const char *intf,
11154 const u8 *data, size_t data_len, int freq)
11155{
11156 struct nl_msg *msg;
11157 int ret = 0;
11158 int ifindex;
11159
11160 ifindex = if_nametoindex(intf);
11161 if (ifindex == 0) {
11162 sigma_dut_print(dut, DUT_MSG_ERROR,
11163 "%s: Index for interface %s failed",
11164 __func__, intf);
11165 return -1;
11166 }
11167
11168 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
11169 NL80211_CMD_FRAME)) ||
11170 (freq && nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
11171 nla_put(msg, NL80211_ATTR_FRAME, data_len, data)) {
11172 sigma_dut_print(dut, DUT_MSG_ERROR,
11173 "%s: Error in adding NL80211_CMD_FRAME",
11174 __func__);
11175 nlmsg_free(msg);
11176 return -1;
11177 }
11178
11179 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
11180 if (ret) {
11181 sigma_dut_print(dut, DUT_MSG_ERROR,
11182 "nl80211: Frame command failed: ret=%d (%s) req=%u",
11183 ret, strerror(-ret), freq);
11184 return -1;
11185 }
11186
11187 return 0;
11188}
11189#endif /* NL80211_SUPPORT */
11190
11191
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011192enum send_frame_type {
11193 DISASSOC, DEAUTH, SAQUERY, AUTH, ASSOCREQ, REASSOCREQ, DLS_REQ
11194};
11195enum send_frame_protection {
11196 CORRECT_KEY, INCORRECT_KEY, UNPROTECTED
11197};
11198
11199
11200static int sta_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn,
Veerendranath Jakkam49774122020-07-05 09:52:18 +053011201 const char *intf, enum send_frame_type frame,
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011202 enum send_frame_protection protected,
Veerendranath Jakkam49774122020-07-05 09:52:18 +053011203 const char *dest, int use_monitor)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011204{
11205#ifdef __linux__
11206 unsigned char buf[1000], *pos;
11207 int s, res;
11208 char bssid[20], addr[20];
11209 char result[32], ssid[100];
11210 size_t ssid_len;
11211
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011212 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011213 sizeof(result)) < 0 ||
11214 strncmp(result, "COMPLETED", 9) != 0) {
11215 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Not connected");
11216 return 0;
11217 }
11218
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011219 if (get_wpa_status(get_station_ifname(dut), "bssid",
11220 bssid, sizeof(bssid)) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011221 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
11222 "current BSSID");
11223 return 0;
11224 }
11225
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011226 if (get_wpa_status(get_station_ifname(dut), "address",
11227 addr, sizeof(addr)) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011228 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
11229 "own MAC address");
11230 return 0;
11231 }
11232
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011233 if (get_wpa_status(get_station_ifname(dut), "ssid", ssid, sizeof(ssid))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011234 < 0) {
11235 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
11236 "current SSID");
11237 return 0;
11238 }
11239 ssid_len = strlen(ssid);
11240
11241 pos = buf;
11242
11243 /* Frame Control */
11244 switch (frame) {
11245 case DISASSOC:
11246 *pos++ = 0xa0;
11247 break;
11248 case DEAUTH:
11249 *pos++ = 0xc0;
11250 break;
11251 case SAQUERY:
11252 *pos++ = 0xd0;
11253 break;
11254 case AUTH:
11255 *pos++ = 0xb0;
11256 break;
11257 case ASSOCREQ:
11258 *pos++ = 0x00;
11259 break;
11260 case REASSOCREQ:
11261 *pos++ = 0x20;
11262 break;
11263 case DLS_REQ:
11264 *pos++ = 0xd0;
11265 break;
11266 }
11267
11268 if (protected == INCORRECT_KEY)
11269 *pos++ = 0x40; /* Set Protected field to 1 */
11270 else
11271 *pos++ = 0x00;
11272
11273 /* Duration */
11274 *pos++ = 0x00;
11275 *pos++ = 0x00;
11276
11277 /* addr1 = DA (current AP) */
11278 hwaddr_aton(bssid, pos);
11279 pos += 6;
11280 /* addr2 = SA (own address) */
11281 hwaddr_aton(addr, pos);
11282 pos += 6;
11283 /* addr3 = BSSID (current AP) */
11284 hwaddr_aton(bssid, pos);
11285 pos += 6;
11286
11287 /* Seq# (to be filled by driver/mac80211) */
11288 *pos++ = 0x00;
11289 *pos++ = 0x00;
11290
11291 if (protected == INCORRECT_KEY) {
11292 /* CCMP parameters */
11293 memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8);
11294 pos += 8;
11295 }
11296
11297 if (protected == INCORRECT_KEY) {
11298 switch (frame) {
11299 case DEAUTH:
11300 /* Reason code (encrypted) */
11301 memcpy(pos, "\xa7\x39", 2);
11302 pos += 2;
11303 break;
11304 case DISASSOC:
11305 /* Reason code (encrypted) */
11306 memcpy(pos, "\xa7\x39", 2);
11307 pos += 2;
11308 break;
11309 case SAQUERY:
11310 /* Category|Action|TransID (encrypted) */
11311 memcpy(pos, "\x6f\xbd\xe9\x4d", 4);
11312 pos += 4;
11313 break;
11314 default:
11315 return -1;
11316 }
11317
11318 /* CCMP MIC */
11319 memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8);
11320 pos += 8;
11321 } else {
11322 switch (frame) {
11323 case DEAUTH:
11324 /* reason code = 8 */
11325 *pos++ = 0x08;
11326 *pos++ = 0x00;
11327 break;
11328 case DISASSOC:
11329 /* reason code = 8 */
11330 *pos++ = 0x08;
11331 *pos++ = 0x00;
11332 break;
11333 case SAQUERY:
11334 /* Category - SA Query */
11335 *pos++ = 0x08;
11336 /* SA query Action - Request */
11337 *pos++ = 0x00;
11338 /* Transaction ID */
11339 *pos++ = 0x12;
11340 *pos++ = 0x34;
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053011341 if (dut->saquery_oci_freq) {
11342 /* OCI IE - Extended ID */
11343 *pos++ = 0xFF;
11344 *pos++ = 0x04;
11345 *pos++ = 0x36;
11346 /* Operating Class */
11347 *pos++ = 0x74;
11348 /* Primary Channel */
11349 *pos++ = freq_to_channel(dut->saquery_oci_freq);
11350 /* Frequency Segment 1 Channel Number */
11351 *pos++ = 0x00;
11352 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011353 break;
11354 case AUTH:
11355 /* Auth Alg (Open) */
11356 *pos++ = 0x00;
11357 *pos++ = 0x00;
11358 /* Seq# */
11359 *pos++ = 0x01;
11360 *pos++ = 0x00;
11361 /* Status code */
11362 *pos++ = 0x00;
11363 *pos++ = 0x00;
11364 break;
11365 case ASSOCREQ:
11366 /* Capability Information */
11367 *pos++ = 0x31;
11368 *pos++ = 0x04;
11369 /* Listen Interval */
11370 *pos++ = 0x0a;
11371 *pos++ = 0x00;
11372 /* SSID */
11373 *pos++ = 0x00;
11374 *pos++ = ssid_len;
11375 memcpy(pos, ssid, ssid_len);
11376 pos += ssid_len;
11377 /* Supported Rates */
11378 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
11379 10);
11380 pos += 10;
11381 /* Extended Supported Rates */
11382 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
11383 pos += 6;
11384 /* RSN */
11385 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
11386 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
11387 "\x00\x00\x00\x00\x0f\xac\x06", 28);
11388 pos += 28;
11389 break;
11390 case REASSOCREQ:
11391 /* Capability Information */
11392 *pos++ = 0x31;
11393 *pos++ = 0x04;
11394 /* Listen Interval */
11395 *pos++ = 0x0a;
11396 *pos++ = 0x00;
11397 /* Current AP */
11398 hwaddr_aton(bssid, pos);
11399 pos += 6;
11400 /* SSID */
11401 *pos++ = 0x00;
11402 *pos++ = ssid_len;
11403 memcpy(pos, ssid, ssid_len);
11404 pos += ssid_len;
11405 /* Supported Rates */
11406 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
11407 10);
11408 pos += 10;
11409 /* Extended Supported Rates */
11410 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
11411 pos += 6;
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053011412 /* RSNE - Group and Pairwise ciphers */
11413 memcpy(pos,
11414 "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x04",
11415 14);
11416 pos += 14;
11417 /* RSNE - AKM Suite count */
11418 *pos++ = 0x01;
11419 *pos++ = 0x00;
11420 /* RSNE - AKM Suites */
11421 if (dut->program == PROGRAM_WPA3)
11422 memcpy(pos, "\x00\x0f\xac\x08", 4);
11423 else
11424 memcpy(pos, "\x00\x0f\xac\x02", 4);
11425 pos += 4;
11426 /* RSNE - Capabilities */
11427 *pos++ = 0xc0;
11428 if (dut->ocvc)
11429 *pos++ = 0x40;
11430 else
11431 *pos++ = 0x00;
11432 /* RSNE - PMKID list and Group Management Ciphers */
11433 memcpy(pos, "\x00\x00\x00\x0f\xac\x06", 6);
11434 pos += 6;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011435 break;
11436 case DLS_REQ:
11437 /* Category - DLS */
11438 *pos++ = 0x02;
11439 /* DLS Action - Request */
11440 *pos++ = 0x00;
11441 /* Destination MACAddress */
11442 if (dest)
11443 hwaddr_aton(dest, pos);
11444 else
11445 memset(pos, 0, 6);
11446 pos += 6;
11447 /* Source MACAddress */
11448 hwaddr_aton(addr, pos);
11449 pos += 6;
11450 /* Capability Information */
11451 *pos++ = 0x10; /* Privacy */
11452 *pos++ = 0x06; /* QoS */
11453 /* DLS Timeout Value */
11454 *pos++ = 0x00;
11455 *pos++ = 0x01;
11456 /* Supported rates */
11457 *pos++ = 0x01;
11458 *pos++ = 0x08;
11459 *pos++ = 0x0c; /* 6 Mbps */
11460 *pos++ = 0x12; /* 9 Mbps */
11461 *pos++ = 0x18; /* 12 Mbps */
11462 *pos++ = 0x24; /* 18 Mbps */
11463 *pos++ = 0x30; /* 24 Mbps */
11464 *pos++ = 0x48; /* 36 Mbps */
11465 *pos++ = 0x60; /* 48 Mbps */
11466 *pos++ = 0x6c; /* 54 Mbps */
11467 /* TODO: Extended Supported Rates */
11468 /* TODO: HT Capabilities */
11469 break;
11470 }
11471 }
11472
Veerendranath Jakkam49774122020-07-05 09:52:18 +053011473 if (use_monitor) {
11474 s = open_monitor("sigmadut");
11475 if (s < 0) {
11476 send_resp(dut, conn, SIGMA_ERROR,
11477 "errorCode,Failed to open monitor socket");
11478 return 0;
11479 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011480
Veerendranath Jakkam49774122020-07-05 09:52:18 +053011481 res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY);
11482 if (res < 0) {
11483 send_resp(dut, conn, SIGMA_ERROR,
11484 "errorCode,Failed to inject frame");
11485 close(s);
11486 return 0;
11487 }
11488 if (res < pos - buf) {
11489 send_resp(dut, conn, SIGMA_ERROR,
11490 "errorCode,Only partial frame sent");
11491 close(s);
11492 return 0;
11493 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011494
Veerendranath Jakkam49774122020-07-05 09:52:18 +053011495 close(s);
11496 } else {
11497#ifdef NL80211_SUPPORT
11498 int freq;
11499 char freq_str[10];
11500
11501 if (get_wpa_status(get_station_ifname(dut), "freq",
11502 freq_str, sizeof(freq_str)) < 0) {
11503 send_resp(dut, conn, SIGMA_ERROR,
11504 "errorCode,Could not get current operating frequency");
11505 return 0;
11506 }
11507 freq = atoi(freq_str);
11508
11509 if (nl80211_send_frame_cmd(dut, intf, buf, pos - buf, freq)) {
11510 send_resp(dut, conn, SIGMA_ERROR,
11511 "errorCode,Failed to inject frame");
11512 return 0;
11513 }
11514#else /* NL80211_SUPPORT */
11515 send_resp(dut, conn, SIGMA_ERROR,
11516 "errorCode,Failed to inject frame (no NL80211_SUPPORT)");
11517 return 0;
11518#endif /* NL80211_SUPPORT */
11519 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011520
11521 return 1;
11522#else /* __linux__ */
11523 send_resp(dut, conn, SIGMA_ERROR, "errorCode,sta_send_frame not "
11524 "yet supported");
11525 return 0;
11526#endif /* __linux__ */
11527}
11528
11529
11530static int cmd_sta_send_frame_tdls(struct sigma_dut *dut,
11531 struct sigma_conn *conn,
11532 struct sigma_cmd *cmd)
11533{
11534 const char *intf = get_param(cmd, "Interface");
11535 const char *sta, *val;
11536 unsigned char addr[ETH_ALEN];
11537 char buf[100];
11538
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030011539 if (!intf)
11540 return -1;
11541
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011542 sta = get_param(cmd, "peer");
11543 if (sta == NULL)
11544 sta = get_param(cmd, "station");
11545 if (sta == NULL) {
11546 send_resp(dut, conn, SIGMA_ERROR,
11547 "ErrorCode,Missing peer address");
11548 return 0;
11549 }
11550 if (hwaddr_aton(sta, addr) < 0) {
11551 send_resp(dut, conn, SIGMA_ERROR,
11552 "ErrorCode,Invalid peer address");
11553 return 0;
11554 }
11555
11556 val = get_param(cmd, "type");
11557 if (val == NULL)
11558 return -1;
11559
11560 if (strcasecmp(val, "DISCOVERY") == 0) {
11561 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", sta);
11562 if (wpa_command(intf, buf) < 0) {
11563 send_resp(dut, conn, SIGMA_ERROR,
11564 "ErrorCode,Failed to send TDLS discovery");
11565 return 0;
11566 }
11567 return 1;
11568 }
11569
11570 if (strcasecmp(val, "SETUP") == 0) {
11571 int status = 0, timeout = 0;
11572
11573 val = get_param(cmd, "Status");
11574 if (val)
11575 status = atoi(val);
11576
11577 val = get_param(cmd, "Timeout");
11578 if (val)
11579 timeout = atoi(val);
11580
11581 if (status != 0 && status != 37) {
11582 send_resp(dut, conn, SIGMA_ERROR,
11583 "ErrorCode,Unsupported status value");
11584 return 0;
11585 }
11586
11587 if (timeout != 0 && timeout != 301) {
11588 send_resp(dut, conn, SIGMA_ERROR,
11589 "ErrorCode,Unsupported timeout value");
11590 return 0;
11591 }
11592
11593 if (status && timeout) {
11594 send_resp(dut, conn, SIGMA_ERROR,
11595 "ErrorCode,Unsupported timeout+status "
11596 "combination");
11597 return 0;
11598 }
11599
11600 if (status == 37 &&
11601 wpa_command(intf, "SET tdls_testing 0x200")) {
11602 send_resp(dut, conn, SIGMA_ERROR,
11603 "ErrorCode,Failed to enable "
11604 "decline setup response test mode");
11605 return 0;
11606 }
11607
11608 if (timeout == 301) {
11609 int res;
11610 if (dut->no_tpk_expiration)
11611 res = wpa_command(intf,
11612 "SET tdls_testing 0x108");
11613 else
11614 res = wpa_command(intf,
11615 "SET tdls_testing 0x8");
11616 if (res) {
11617 send_resp(dut, conn, SIGMA_ERROR,
11618 "ErrorCode,Failed to set short TPK "
11619 "lifetime");
11620 return 0;
11621 }
11622 }
11623
11624 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", sta);
11625 if (wpa_command(intf, buf) < 0) {
11626 send_resp(dut, conn, SIGMA_ERROR,
11627 "ErrorCode,Failed to send TDLS setup");
11628 return 0;
11629 }
11630 return 1;
11631 }
11632
11633 if (strcasecmp(val, "TEARDOWN") == 0) {
11634 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", sta);
11635 if (wpa_command(intf, buf) < 0) {
11636 send_resp(dut, conn, SIGMA_ERROR,
11637 "ErrorCode,Failed to send TDLS teardown");
11638 return 0;
11639 }
11640 return 1;
11641 }
11642
11643 send_resp(dut, conn, SIGMA_ERROR,
11644 "ErrorCode,Unsupported TDLS frame");
11645 return 0;
11646}
11647
11648
11649static int sta_ap_known(const char *ifname, const char *bssid)
11650{
11651 char buf[4096];
11652
Jouni Malinendd32f192018-09-15 02:55:19 +030011653 snprintf(buf, sizeof(buf), "BSS MASK=1 %s", bssid);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011654 if (wpa_command_resp(ifname, buf, buf, sizeof(buf)) < 0)
11655 return 0;
11656 if (strncmp(buf, "id=", 3) != 0)
11657 return 0;
11658 return 1;
11659}
11660
11661
11662static int sta_scan_ap(struct sigma_dut *dut, const char *ifname,
11663 const char *bssid)
11664{
11665 int res;
11666 struct wpa_ctrl *ctrl;
11667 char buf[256];
11668
11669 if (sta_ap_known(ifname, bssid))
11670 return 0;
11671 sigma_dut_print(dut, DUT_MSG_DEBUG,
11672 "AP not in BSS table - start scan");
11673
11674 ctrl = open_wpa_mon(ifname);
11675 if (ctrl == NULL) {
11676 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
11677 "wpa_supplicant monitor connection");
11678 return -1;
11679 }
11680
11681 if (wpa_command(ifname, "SCAN") < 0) {
11682 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to start scan");
11683 wpa_ctrl_detach(ctrl);
11684 wpa_ctrl_close(ctrl);
11685 return -1;
11686 }
11687
11688 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
11689 buf, sizeof(buf));
11690
11691 wpa_ctrl_detach(ctrl);
11692 wpa_ctrl_close(ctrl);
11693
11694 if (res < 0) {
11695 sigma_dut_print(dut, DUT_MSG_INFO, "Scan did not complete");
11696 return -1;
11697 }
11698
11699 if (sta_ap_known(ifname, bssid))
11700 return 0;
11701 sigma_dut_print(dut, DUT_MSG_INFO, "AP not in BSS table");
11702 return -1;
11703}
11704
11705
11706static int cmd_sta_send_frame_hs2_neighadv(struct sigma_dut *dut,
11707 struct sigma_conn *conn,
11708 struct sigma_cmd *cmd,
11709 const char *intf)
11710{
11711 char buf[200];
11712
11713 snprintf(buf, sizeof(buf), "ndsend 2001:DB8::1 %s", intf);
11714 if (system(buf) != 0) {
11715 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Failed to run "
11716 "ndsend");
11717 return 0;
11718 }
11719
11720 return 1;
11721}
11722
11723
11724static int cmd_sta_send_frame_hs2_neighsolreq(struct sigma_dut *dut,
11725 struct sigma_conn *conn,
11726 struct sigma_cmd *cmd,
11727 const char *intf)
11728{
11729 char buf[200];
11730 const char *ip = get_param(cmd, "SenderIP");
11731
Peng Xu26b356d2017-10-04 17:58:16 -070011732 if (!ip)
11733 return 0;
11734
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011735 snprintf(buf, sizeof(buf), "ndisc6 -nm %s %s -r 4", ip, intf);
11736 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11737 if (system(buf) == 0) {
11738 sigma_dut_print(dut, DUT_MSG_INFO,
11739 "Neighbor Solicitation got a response "
11740 "for %s@%s", ip, intf);
11741 }
11742
11743 return 1;
11744}
11745
11746
11747static int cmd_sta_send_frame_hs2_arpprobe(struct sigma_dut *dut,
11748 struct sigma_conn *conn,
11749 struct sigma_cmd *cmd,
11750 const char *ifname)
11751{
11752 char buf[200];
11753 const char *ip = get_param(cmd, "SenderIP");
11754
11755 if (ip == NULL) {
11756 send_resp(dut, conn, SIGMA_ERROR,
11757 "ErrorCode,Missing SenderIP parameter");
11758 return 0;
11759 }
11760 snprintf(buf, sizeof(buf), "arping -I %s -D %s -c 4", ifname, ip);
11761 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11762 if (system(buf) != 0) {
11763 sigma_dut_print(dut, DUT_MSG_INFO, "arping DAD got a response "
11764 "for %s@%s", ip, ifname);
11765 }
11766
11767 return 1;
11768}
11769
11770
11771static int cmd_sta_send_frame_hs2_arpannounce(struct sigma_dut *dut,
11772 struct sigma_conn *conn,
11773 struct sigma_cmd *cmd,
11774 const char *ifname)
11775{
11776 char buf[200];
11777 char ip[16];
11778 int s;
Peng Xub3756882017-10-04 14:39:09 -070011779 struct ifreq ifr;
11780 struct sockaddr_in saddr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011781
11782 s = socket(PF_INET, SOCK_DGRAM, 0);
Peng Xub3756882017-10-04 14:39:09 -070011783 if (s < 0) {
11784 perror("socket");
11785 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011786 }
11787
Peng Xub3756882017-10-04 14:39:09 -070011788 memset(&ifr, 0, sizeof(ifr));
11789 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
11790 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
11791 sigma_dut_print(dut, DUT_MSG_INFO,
11792 "Failed to get %s IP address: %s",
11793 ifname, strerror(errno));
11794 close(s);
11795 return -1;
11796 }
11797 close(s);
11798
11799 memcpy(&saddr, &ifr.ifr_addr, sizeof(struct sockaddr_in));
11800 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
11801
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011802 snprintf(buf, sizeof(buf), "arping -I %s -s %s %s -c 4", ifname, ip,
11803 ip);
11804 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11805 if (system(buf) != 0) {
11806 }
11807
11808 return 1;
11809}
11810
11811
11812static int cmd_sta_send_frame_hs2_arpreply(struct sigma_dut *dut,
11813 struct sigma_conn *conn,
11814 struct sigma_cmd *cmd,
11815 const char *ifname)
11816{
11817 char buf[200], addr[20];
11818 char dst[ETH_ALEN], src[ETH_ALEN];
11819 short ethtype = htons(ETH_P_ARP);
11820 char *pos;
11821 int s, res;
11822 const char *val;
11823 struct sockaddr_in taddr;
11824
11825 val = get_param(cmd, "dest");
11826 if (val)
11827 hwaddr_aton(val, (unsigned char *) dst);
11828
11829 val = get_param(cmd, "DestIP");
11830 if (val)
11831 inet_aton(val, &taddr.sin_addr);
Peng Xu151c9e12017-10-04 14:39:09 -070011832 else
11833 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011834
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011835 if (get_wpa_status(get_station_ifname(dut), "address", addr,
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011836 sizeof(addr)) < 0)
11837 return -2;
11838 hwaddr_aton(addr, (unsigned char *) src);
11839
11840 pos = buf;
11841 *pos++ = 0x00;
11842 *pos++ = 0x01;
11843 *pos++ = 0x08;
11844 *pos++ = 0x00;
11845 *pos++ = 0x06;
11846 *pos++ = 0x04;
11847 *pos++ = 0x00;
11848 *pos++ = 0x02;
11849 memcpy(pos, src, ETH_ALEN);
11850 pos += ETH_ALEN;
11851 memcpy(pos, &taddr.sin_addr, 4);
11852 pos += 4;
11853 memcpy(pos, dst, ETH_ALEN);
11854 pos += ETH_ALEN;
11855 memcpy(pos, &taddr.sin_addr, 4);
11856 pos += 4;
11857
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011858 s = open_monitor(get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011859 if (s < 0) {
11860 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
11861 "monitor socket");
11862 return 0;
11863 }
11864
11865 res = inject_eth_frame(s, buf, pos - buf, ethtype, dst, src);
11866 if (res < 0) {
11867 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
11868 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +053011869 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011870 return 0;
11871 }
11872
11873 close(s);
11874
11875 return 1;
11876}
11877
11878
11879static int cmd_sta_send_frame_hs2_dls_req(struct sigma_dut *dut,
11880 struct sigma_conn *conn,
11881 struct sigma_cmd *cmd,
11882 const char *intf, const char *dest)
11883{
11884 char buf[100];
11885
11886 if (if_nametoindex("sigmadut") == 0) {
11887 snprintf(buf, sizeof(buf),
11888 "iw dev %s interface add sigmadut type monitor",
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011889 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011890 if (system(buf) != 0 ||
11891 if_nametoindex("sigmadut") == 0) {
11892 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
11893 "monitor interface with '%s'", buf);
11894 return -2;
11895 }
11896 }
11897
11898 if (system("ifconfig sigmadut up") != 0) {
11899 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
11900 "monitor interface up");
11901 return -2;
11902 }
11903
Veerendranath Jakkam49774122020-07-05 09:52:18 +053011904 return sta_inject_frame(dut, conn, intf, DLS_REQ, UNPROTECTED, dest, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011905}
11906
11907
11908static int cmd_sta_send_frame_hs2(struct sigma_dut *dut,
11909 struct sigma_conn *conn,
11910 struct sigma_cmd *cmd)
11911{
11912 const char *intf = get_param(cmd, "Interface");
11913 const char *dest = get_param(cmd, "Dest");
11914 const char *type = get_param(cmd, "FrameName");
11915 const char *val;
11916 char buf[200], *pos, *end;
11917 int count, count2;
11918
11919 if (type == NULL)
11920 type = get_param(cmd, "Type");
11921
11922 if (intf == NULL || dest == NULL || type == NULL)
11923 return -1;
11924
11925 if (strcasecmp(type, "NeighAdv") == 0)
11926 return cmd_sta_send_frame_hs2_neighadv(dut, conn, cmd, intf);
11927
11928 if (strcasecmp(type, "NeighSolicitReq") == 0)
11929 return cmd_sta_send_frame_hs2_neighsolreq(dut, conn, cmd, intf);
11930
11931 if (strcasecmp(type, "ARPProbe") == 0)
11932 return cmd_sta_send_frame_hs2_arpprobe(dut, conn, cmd, intf);
11933
11934 if (strcasecmp(type, "ARPAnnounce") == 0)
11935 return cmd_sta_send_frame_hs2_arpannounce(dut, conn, cmd, intf);
11936
11937 if (strcasecmp(type, "ARPReply") == 0)
11938 return cmd_sta_send_frame_hs2_arpreply(dut, conn, cmd, intf);
11939
11940 if (strcasecmp(type, "DLS-request") == 0 ||
11941 strcasecmp(type, "DLSrequest") == 0)
11942 return cmd_sta_send_frame_hs2_dls_req(dut, conn, cmd, intf,
11943 dest);
11944
11945 if (strcasecmp(type, "ANQPQuery") != 0 &&
11946 strcasecmp(type, "Query") != 0) {
11947 send_resp(dut, conn, SIGMA_ERROR,
11948 "ErrorCode,Unsupported HS 2.0 send frame type");
11949 return 0;
11950 }
11951
11952 if (sta_scan_ap(dut, intf, dest) < 0) {
11953 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not find "
11954 "the requested AP");
11955 return 0;
11956 }
11957
11958 pos = buf;
11959 end = buf + sizeof(buf);
11960 count = 0;
11961 pos += snprintf(pos, end - pos, "ANQP_GET %s ", dest);
11962
11963 val = get_param(cmd, "ANQP_CAP_LIST");
11964 if (val && atoi(val)) {
11965 pos += snprintf(pos, end - pos, "%s257", count > 0 ? "," : "");
11966 count++;
11967 }
11968
11969 val = get_param(cmd, "VENUE_NAME");
11970 if (val && atoi(val)) {
11971 pos += snprintf(pos, end - pos, "%s258", count > 0 ? "," : "");
11972 count++;
11973 }
11974
11975 val = get_param(cmd, "NETWORK_AUTH_TYPE");
11976 if (val && atoi(val)) {
11977 pos += snprintf(pos, end - pos, "%s260", count > 0 ? "," : "");
11978 count++;
11979 }
11980
11981 val = get_param(cmd, "ROAMING_CONS");
11982 if (val && atoi(val)) {
11983 pos += snprintf(pos, end - pos, "%s261", count > 0 ? "," : "");
11984 count++;
11985 }
11986
11987 val = get_param(cmd, "IP_ADDR_TYPE_AVAILABILITY");
11988 if (val && atoi(val)) {
11989 pos += snprintf(pos, end - pos, "%s262", count > 0 ? "," : "");
11990 count++;
11991 }
11992
11993 val = get_param(cmd, "NAI_REALM_LIST");
11994 if (val && atoi(val)) {
11995 pos += snprintf(pos, end - pos, "%s263", count > 0 ? "," : "");
11996 count++;
11997 }
11998
11999 val = get_param(cmd, "3GPP_INFO");
12000 if (val && atoi(val)) {
12001 pos += snprintf(pos, end - pos, "%s264", count > 0 ? "," : "");
12002 count++;
12003 }
12004
12005 val = get_param(cmd, "DOMAIN_LIST");
12006 if (val && atoi(val)) {
12007 pos += snprintf(pos, end - pos, "%s268", count > 0 ? "," : "");
12008 count++;
12009 }
12010
Jouni Malinen34cf9532018-04-29 19:26:33 +030012011 val = get_param(cmd, "Venue_URL");
12012 if (val && atoi(val)) {
12013 pos += snprintf(pos, end - pos, "%s277", count > 0 ? "," : "");
12014 count++;
12015 }
12016
Jouni Malinend3bca5d2018-04-29 17:25:23 +030012017 val = get_param(cmd, "Advice_Of_Charge");
12018 if (val && atoi(val)) {
12019 pos += snprintf(pos, end - pos, "%s278", count > 0 ? "," : "");
12020 count++;
12021 }
12022
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012023 if (count && wpa_command(intf, buf)) {
12024 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,ANQP_GET failed");
12025 return 0;
12026 }
12027
12028 pos = buf;
12029 end = buf + sizeof(buf);
12030 count2 = 0;
12031 pos += snprintf(pos, end - pos, "HS20_ANQP_GET %s ", dest);
12032
12033 val = get_param(cmd, "HS_CAP_LIST");
12034 if (val && atoi(val)) {
12035 pos += snprintf(pos, end - pos, "%s2", count2 > 0 ? "," : "");
12036 count2++;
12037 }
12038
12039 val = get_param(cmd, "OPER_NAME");
12040 if (val && atoi(val)) {
12041 pos += snprintf(pos, end - pos, "%s3", count2 > 0 ? "," : "");
12042 count2++;
12043 }
12044
12045 val = get_param(cmd, "WAN_METRICS");
12046 if (!val)
12047 val = get_param(cmd, "WAN_MAT");
12048 if (!val)
12049 val = get_param(cmd, "WAN_MET");
12050 if (val && atoi(val)) {
12051 pos += snprintf(pos, end - pos, "%s4", count2 > 0 ? "," : "");
12052 count2++;
12053 }
12054
12055 val = get_param(cmd, "CONNECTION_CAPABILITY");
12056 if (val && atoi(val)) {
12057 pos += snprintf(pos, end - pos, "%s5", count2 > 0 ? "," : "");
12058 count2++;
12059 }
12060
12061 val = get_param(cmd, "OP_CLASS");
12062 if (val && atoi(val)) {
12063 pos += snprintf(pos, end - pos, "%s7", count2 > 0 ? "," : "");
12064 count2++;
12065 }
12066
12067 val = get_param(cmd, "OSU_PROVIDER_LIST");
12068 if (val && atoi(val)) {
12069 pos += snprintf(pos, end - pos, "%s8", count2 > 0 ? "," : "");
12070 count2++;
12071 }
12072
Jouni Malinenf67afec2018-04-29 19:24:58 +030012073 val = get_param(cmd, "OPER_ICON_METADATA");
12074 if (!val)
12075 val = get_param(cmd, "OPERATOR_ICON_METADATA");
12076 if (val && atoi(val)) {
12077 pos += snprintf(pos, end - pos, "%s12", count2 > 0 ? "," : "");
12078 count2++;
12079 }
12080
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012081 if (count && count2) {
12082 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before sending out "
12083 "second query");
12084 sleep(1);
12085 }
12086
12087 if (count2 && wpa_command(intf, buf)) {
12088 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,HS20_ANQP_GET "
12089 "failed");
12090 return 0;
12091 }
12092
12093 val = get_param(cmd, "NAI_HOME_REALM_LIST");
12094 if (val) {
12095 if (count || count2) {
12096 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
12097 "sending out second query");
12098 sleep(1);
12099 }
12100
12101 if (strcmp(val, "1") == 0)
12102 val = "mail.example.com";
12103 snprintf(buf, end - pos,
12104 "HS20_GET_NAI_HOME_REALM_LIST %s realm=%s",
12105 dest, val);
12106 if (wpa_command(intf, buf)) {
12107 send_resp(dut, conn, SIGMA_ERROR,
12108 "ErrorCode,HS20_GET_NAI_HOME_REALM_LIST "
12109 "failed");
12110 return 0;
12111 }
12112 }
12113
12114 val = get_param(cmd, "ICON_REQUEST");
12115 if (val) {
12116 if (count || count2) {
12117 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
12118 "sending out second query");
12119 sleep(1);
12120 }
12121
12122 snprintf(buf, end - pos,
12123 "HS20_ICON_REQUEST %s %s", dest, val);
12124 if (wpa_command(intf, buf)) {
12125 send_resp(dut, conn, SIGMA_ERROR,
12126 "ErrorCode,HS20_ICON_REQUEST failed");
12127 return 0;
12128 }
12129 }
12130
12131 return 1;
12132}
12133
12134
12135static int ath_sta_send_frame_vht(struct sigma_dut *dut,
12136 struct sigma_conn *conn,
12137 struct sigma_cmd *cmd)
12138{
12139 const char *val;
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012140 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012141 int chwidth, nss;
12142
12143 val = get_param(cmd, "framename");
12144 if (!val)
12145 return -1;
12146 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
12147
12148 /* Command sequence to generate Op mode notification */
12149 if (val && strcasecmp(val, "Op_md_notif_frm") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012150 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012151
12152 /* Disable STBC */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012153 run_iwpriv(dut, ifname, "tx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012154
12155 /* Extract Channel width */
12156 val = get_param(cmd, "Channel_width");
12157 if (val) {
12158 switch (atoi(val)) {
12159 case 20:
12160 chwidth = 0;
12161 break;
12162 case 40:
12163 chwidth = 1;
12164 break;
12165 case 80:
12166 chwidth = 2;
12167 break;
12168 case 160:
12169 chwidth = 3;
12170 break;
12171 default:
12172 chwidth = 2;
12173 break;
12174 }
12175
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012176 run_iwpriv(dut, ifname, "chwidth %d", chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012177 }
12178
12179 /* Extract NSS */
12180 val = get_param(cmd, "NSS");
12181 if (val) {
12182 switch (atoi(val)) {
12183 case 1:
12184 nss = 1;
12185 break;
12186 case 2:
12187 nss = 3;
12188 break;
12189 case 3:
12190 nss = 7;
12191 break;
12192 default:
12193 /* We do not support NSS > 3 */
12194 nss = 3;
12195 break;
12196 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012197 run_iwpriv(dut, ifname, "rxchainmask %d", nss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012198 }
12199
12200 /* Opmode notify */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012201 run_iwpriv(dut, ifname, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012202 }
12203
12204 return 1;
12205}
12206
12207
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070012208static int wcn_sta_set_pmf_config(struct sigma_dut *dut, const char *intf,
12209 enum send_frame_protection protected)
12210{
12211#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +053012212 return wcn_wifi_test_config_set_u8(
12213 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_PMF_PROTECTION,
12214 protected);
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070012215#else /* NL80211_SUPPORT */
12216 sigma_dut_print(dut, DUT_MSG_ERROR,
12217 "PMF config cannot be set without NL80211_SUPPORT defined");
12218 return -1;
12219#endif /* NL80211_SUPPORT */
12220}
12221
12222
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012223static int cmd_sta_send_frame_vht(struct sigma_dut *dut,
12224 struct sigma_conn *conn,
12225 struct sigma_cmd *cmd)
12226{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012227 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012228 case DRIVER_ATHEROS:
12229 return ath_sta_send_frame_vht(dut, conn, cmd);
12230 default:
12231 send_resp(dut, conn, SIGMA_ERROR,
12232 "errorCode,Unsupported sta_set_frame(VHT) with the current driver");
12233 return 0;
12234 }
12235}
12236
12237
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070012238static int wcn_sta_send_disassoc(struct sigma_dut *dut, const char *intf)
12239{
12240#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +053012241 return wcn_wifi_test_config_set_flag(
12242 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_DISASSOC_TX);
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070012243#else /* NL80211_SUPPORT */
12244 sigma_dut_print(dut, DUT_MSG_ERROR,
12245 "Disassoc Tx cannot be done without NL80211_SUPPORT defined");
12246 return -1;
12247#endif /* NL80211_SUPPORT */
12248}
12249
12250
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070012251static int wcn_sta_send_frame_he(struct sigma_dut *dut, struct sigma_conn *conn,
12252 struct sigma_cmd *cmd)
12253{
12254 const char *val;
12255 const char *intf = get_param(cmd, "Interface");
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070012256 enum send_frame_protection protected;
12257 const char *pmf;
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070012258
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030012259 if (!intf)
12260 return -1;
12261
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070012262 val = get_param(cmd, "framename");
12263 if (!val)
12264 return -1;
12265 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
12266
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070012267 pmf = get_param(cmd, "PMFProtected");
12268 if (!pmf)
12269 pmf = get_param(cmd, "Protected");
12270 if (pmf) {
12271 if (strcasecmp(pmf, "Correct-key") == 0 ||
12272 strcasecmp(pmf, "CorrectKey") == 0) {
12273 protected = CORRECT_KEY;
12274 } else if (strcasecmp(pmf, "IncorrectKey") == 0) {
12275 protected = INCORRECT_KEY;
12276 } else if (strcasecmp(pmf, "Unprotected") == 0) {
12277 protected = UNPROTECTED;
12278 } else {
12279 send_resp(dut, conn, SIGMA_ERROR,
12280 "errorCode,Unsupported PMFProtected");
12281 return STATUS_SENT_ERROR;
12282 }
12283 sigma_dut_print(dut, DUT_MSG_DEBUG, "Config PMF protection %d",
12284 protected);
12285 wcn_sta_set_pmf_config(dut, intf, protected);
12286 }
12287
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070012288 /* Command sequence to generate Op mode notification */
12289 if (val && strcasecmp(val, "action") == 0) {
12290 val = get_param(cmd, "PPDUTxType");
12291 if (val && strcasecmp(val, "TB") == 0) {
12292 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 1)) {
12293 sigma_dut_print(dut, DUT_MSG_ERROR,
12294 "failed to send TB PPDU Tx cfg");
12295 send_resp(dut, conn, SIGMA_ERROR,
12296 "ErrorCode,set TB PPDU Tx cfg failed");
12297 return 0;
12298 }
12299 return 1;
12300 }
12301
12302 sigma_dut_print(dut, DUT_MSG_ERROR,
12303 "Action Tx type is not defined");
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070012304
12305 return SUCCESS_SEND_STATUS;
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070012306 }
12307
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070012308 if (strcasecmp(val, "disassoc") == 0)
12309 wcn_sta_send_disassoc(dut, intf);
12310
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070012311 return 1;
12312}
12313
12314
12315static int cmd_sta_send_frame_he(struct sigma_dut *dut,
12316 struct sigma_conn *conn,
12317 struct sigma_cmd *cmd)
12318{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012319 switch (get_driver_type(dut)) {
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070012320 case DRIVER_WCN:
12321 return wcn_sta_send_frame_he(dut, conn, cmd);
12322 default:
12323 send_resp(dut, conn, SIGMA_ERROR,
12324 "errorCode,Unsupported sta_set_frame(HE) with the current driver");
12325 return 0;
12326 }
12327}
12328
12329
Lior David0fe101e2017-03-09 16:09:50 +020012330#ifdef __linux__
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030012331
12332static int
12333wil6210_send_p2p_frame_60g(struct sigma_dut *dut, struct sigma_cmd *cmd,
12334 const char *frame_name, const char *dest_mac)
12335{
12336 int isprobereq = strcasecmp(frame_name, "probereq") == 0;
12337 const char *ssid = get_param(cmd, "ssid");
12338 const char *countstr = get_param(cmd, "count");
12339 const char *channelstr = get_param(cmd, "channel");
12340 const char *group_id = get_param(cmd, "groupid");
12341 const char *client_id = get_param(cmd, "clientmac");
12342 int count, channel, freq, i;
12343 const char *fname;
12344 char frame[1024], src_mac[20], group_id_attr[25],
12345 device_macstr[3 * ETH_ALEN], client_mac[ETH_ALEN];
12346 const char *group_ssid;
12347 const int group_ssid_prefix_len = 9;
12348 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *) frame;
12349 size_t framelen = sizeof(frame);
12350 struct template_frame_tag tags[2];
12351 size_t tags_total = ARRAY_SIZE(tags);
12352 int tag_index, len, dst_len;
12353
12354 if (!countstr || !channelstr) {
12355 sigma_dut_print(dut, DUT_MSG_ERROR,
12356 "Missing argument: count, channel");
12357 return -1;
12358 }
12359 if (isprobereq && !ssid) {
12360 sigma_dut_print(dut, DUT_MSG_ERROR,
12361 "Missing argument: ssid");
12362 return -1;
12363 }
12364 if (!isprobereq && (!group_id || !client_id)) {
12365 sigma_dut_print(dut, DUT_MSG_ERROR,
12366 "Missing argument: group_id, client_id");
12367 return -1;
12368 }
12369
12370 count = atoi(countstr);
12371 channel = atoi(channelstr);
12372 freq = channel_to_freq(dut, channel);
12373
12374 if (!freq) {
12375 sigma_dut_print(dut, DUT_MSG_ERROR,
12376 "invalid channel: %s", channelstr);
12377 return -1;
12378 }
12379
12380 if (isprobereq) {
12381 if (strcasecmp(ssid, "wildcard") == 0) {
12382 fname = "probe_req_wildcard.txt";
12383 } else if (strcasecmp(ssid, "P2P_Wildcard") == 0) {
12384 fname = "probe_req_P2P_Wildcard.txt";
12385 } else {
12386 sigma_dut_print(dut, DUT_MSG_ERROR,
12387 "invalid probe request type");
12388 return -1;
12389 }
12390 } else {
12391 fname = "P2P_device_discovery_req.txt";
12392 }
12393
12394 if (parse_template_frame_file(dut, fname, frame, &framelen,
12395 tags, &tags_total)) {
12396 sigma_dut_print(dut, DUT_MSG_ERROR,
12397 "invalid frame template: %s", fname);
12398 return -1;
12399 }
12400
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012401 if (get_wpa_status(get_station_ifname(dut), "address",
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030012402 src_mac, sizeof(src_mac)) < 0 ||
12403 parse_mac_address(dut, src_mac, &hdr->addr2[0]) ||
12404 parse_mac_address(dut, dest_mac, &hdr->addr1[0]))
12405 return -1;
12406 /* Use wildcard BSSID, since we are in PBSS */
12407 memset(&hdr->addr3, 0xFF, ETH_ALEN);
12408
12409 if (!isprobereq) {
12410 tag_index = find_template_frame_tag(tags, tags_total, 1);
12411 if (tag_index < 0) {
12412 sigma_dut_print(dut, DUT_MSG_ERROR,
12413 "can't find device id attribute");
12414 return -1;
12415 }
12416 if (parse_mac_address(dut, client_id,
12417 (unsigned char *) client_mac)) {
12418 sigma_dut_print(dut, DUT_MSG_ERROR,
12419 "invalid client_id: %s", client_id);
12420 return -1;
12421 }
12422 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
12423 framelen - tags[tag_index].offset,
12424 IEEE80211_P2P_ATTR_DEVICE_ID,
12425 client_mac, ETH_ALEN)) {
12426 sigma_dut_print(dut, DUT_MSG_ERROR,
12427 "fail to replace device id attribute");
12428 return -1;
12429 }
12430
12431 /*
12432 * group_id arg contains device MAC address followed by
12433 * space and SSID (DIRECT-somessid).
12434 * group id attribute contains device address (6 bytes)
12435 * followed by SSID prefix DIRECT-XX (9 bytes)
12436 */
12437 if (strlen(group_id) < sizeof(device_macstr)) {
12438 sigma_dut_print(dut, DUT_MSG_ERROR,
12439 "group_id arg too short");
12440 return -1;
12441 }
12442 memcpy(device_macstr, group_id, sizeof(device_macstr));
12443 device_macstr[sizeof(device_macstr) - 1] = '\0';
12444 if (parse_mac_address(dut, device_macstr,
12445 (unsigned char *) group_id_attr)) {
12446 sigma_dut_print(dut, DUT_MSG_ERROR,
12447 "fail to parse device address from group_id");
12448 return -1;
12449 }
12450 group_ssid = strchr(group_id, ' ');
12451 if (!group_ssid) {
12452 sigma_dut_print(dut, DUT_MSG_ERROR,
12453 "invalid group_id arg, no ssid");
12454 return -1;
12455 }
12456 group_ssid++;
12457 len = strlen(group_ssid);
12458 if (len < group_ssid_prefix_len) {
12459 sigma_dut_print(dut, DUT_MSG_ERROR,
12460 "group_id SSID too short");
12461 return -1;
12462 }
12463 dst_len = sizeof(group_id_attr) - ETH_ALEN;
12464 if (len > dst_len) {
12465 sigma_dut_print(dut, DUT_MSG_ERROR,
12466 "group_id SSID (%s) too long",
12467 group_ssid);
12468 return -1;
12469 }
12470
12471 memcpy(group_id_attr + ETH_ALEN, group_ssid, len);
12472 tag_index = find_template_frame_tag(tags, tags_total, 2);
12473 if (tag_index < 0) {
12474 sigma_dut_print(dut, DUT_MSG_ERROR,
12475 "can't find group id attribute");
12476 return -1;
12477 }
12478 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
12479 framelen - tags[tag_index].offset,
12480 IEEE80211_P2P_ATTR_GROUP_ID,
12481 group_id_attr,
12482 sizeof(group_id_attr))) {
12483 sigma_dut_print(dut, DUT_MSG_ERROR,
12484 "fail to replace group id attribute");
12485 return -1;
12486 }
12487 }
12488
12489 for (i = 0; i < count; i++) {
12490 if (wil6210_transmit_frame(dut, freq,
12491 WIL_TRANSMIT_FRAME_DEFAULT_ROC,
12492 frame, framelen)) {
12493 sigma_dut_print(dut, DUT_MSG_ERROR,
12494 "fail to transmit probe request frame");
12495 return -1;
12496 }
12497 }
12498
12499 return 0;
12500}
12501
12502
Lior David0fe101e2017-03-09 16:09:50 +020012503int wil6210_send_frame_60g(struct sigma_dut *dut, struct sigma_conn *conn,
12504 struct sigma_cmd *cmd)
12505{
12506 const char *frame_name = get_param(cmd, "framename");
12507 const char *mac = get_param(cmd, "dest_mac");
12508
12509 if (!frame_name || !mac) {
12510 sigma_dut_print(dut, DUT_MSG_ERROR,
12511 "framename and dest_mac must be provided");
12512 return -1;
12513 }
12514
12515 if (strcasecmp(frame_name, "brp") == 0) {
12516 const char *l_rx = get_param(cmd, "L-RX");
12517 int l_rx_i;
12518
12519 if (!l_rx) {
12520 sigma_dut_print(dut, DUT_MSG_ERROR,
12521 "L-RX must be provided");
12522 return -1;
12523 }
12524 l_rx_i = atoi(l_rx);
12525
12526 sigma_dut_print(dut, DUT_MSG_INFO,
12527 "dev_send_frame: BRP-RX, dest_mac %s, L-RX %s",
12528 mac, l_rx);
12529 if (l_rx_i != 16) {
12530 sigma_dut_print(dut, DUT_MSG_ERROR,
12531 "unsupported L-RX: %s", l_rx);
12532 return -1;
12533 }
12534
12535 if (wil6210_send_brp_rx(dut, mac, l_rx_i))
12536 return -1;
12537 } else if (strcasecmp(frame_name, "ssw") == 0) {
12538 sigma_dut_print(dut, DUT_MSG_INFO,
12539 "dev_send_frame: SLS, dest_mac %s", mac);
12540 if (wil6210_send_sls(dut, mac))
12541 return -1;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030012542 } else if ((strcasecmp(frame_name, "probereq") == 0) ||
12543 (strcasecmp(frame_name, "devdiscreq") == 0)) {
12544 sigma_dut_print(dut, DUT_MSG_INFO,
12545 "dev_send_frame: %s, dest_mac %s", frame_name,
12546 mac);
12547 if (wil6210_send_p2p_frame_60g(dut, cmd, frame_name, mac))
12548 return -1;
Lior David0fe101e2017-03-09 16:09:50 +020012549 } else {
12550 sigma_dut_print(dut, DUT_MSG_ERROR,
12551 "unsupported frame type: %s", frame_name);
12552 return -1;
12553 }
12554
12555 return 1;
12556}
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030012557
Lior David0fe101e2017-03-09 16:09:50 +020012558#endif /* __linux__ */
12559
12560
12561static int cmd_sta_send_frame_60g(struct sigma_dut *dut,
12562 struct sigma_conn *conn,
12563 struct sigma_cmd *cmd)
12564{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012565 switch (get_driver_type(dut)) {
Lior David0fe101e2017-03-09 16:09:50 +020012566#ifdef __linux__
12567 case DRIVER_WIL6210:
12568 return wil6210_send_frame_60g(dut, conn, cmd);
12569#endif /* __linux__ */
12570 default:
12571 send_resp(dut, conn, SIGMA_ERROR,
12572 "errorCode,Unsupported sta_set_frame(60G) with the current driver");
12573 return 0;
12574 }
12575}
12576
12577
Ashwini Patildb59b3c2017-04-13 15:19:23 +053012578static int mbo_send_anqp_query(struct sigma_dut *dut, struct sigma_conn *conn,
12579 const char *intf, struct sigma_cmd *cmd)
12580{
12581 const char *val, *addr;
12582 char buf[100];
12583
12584 addr = get_param(cmd, "DestMac");
12585 if (!addr) {
12586 send_resp(dut, conn, SIGMA_INVALID,
12587 "ErrorCode,AP MAC address is missing");
12588 return 0;
12589 }
12590
12591 val = get_param(cmd, "ANQPQuery_ID");
12592 if (!val) {
12593 send_resp(dut, conn, SIGMA_INVALID,
12594 "ErrorCode,Missing ANQPQuery_ID");
12595 return 0;
12596 }
12597
12598 if (strcasecmp(val, "NeighborReportReq") == 0) {
12599 snprintf(buf, sizeof(buf), "ANQP_GET %s 272", addr);
12600 } else if (strcasecmp(val, "QueryListWithCellPref") == 0) {
12601 snprintf(buf, sizeof(buf), "ANQP_GET %s 272,mbo:2", addr);
12602 } else {
12603 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid ANQPQuery_ID: %s",
12604 val);
12605 send_resp(dut, conn, SIGMA_INVALID,
12606 "ErrorCode,Invalid ANQPQuery_ID");
12607 return 0;
12608 }
12609
Ashwini Patild174f2c2017-04-13 16:49:46 +053012610 /* Set gas_address3 field to IEEE 802.11-2012 standard compliant form
12611 * (Address3 = Wildcard BSSID when sent to not-associated AP;
12612 * if associated, AP BSSID).
12613 */
12614 if (wpa_command(intf, "SET gas_address3 1") < 0) {
12615 send_resp(dut, conn, SIGMA_ERROR,
12616 "ErrorCode,Failed to set gas_address3");
12617 return 0;
12618 }
12619
Ashwini Patildb59b3c2017-04-13 15:19:23 +053012620 if (wpa_command(intf, buf) < 0) {
12621 send_resp(dut, conn, SIGMA_ERROR,
12622 "ErrorCode,Failed to send ANQP query");
12623 return 0;
12624 }
12625
12626 return 1;
12627}
12628
12629
12630static int mbo_cmd_sta_send_frame(struct sigma_dut *dut,
12631 struct sigma_conn *conn,
12632 const char *intf,
12633 struct sigma_cmd *cmd)
12634{
12635 const char *val = get_param(cmd, "FrameName");
12636
12637 if (val && strcasecmp(val, "ANQPQuery") == 0)
12638 return mbo_send_anqp_query(dut, conn, intf, cmd);
12639
12640 return 2;
12641}
12642
12643
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053012644static enum sigma_cmd_result cmd_sta_send_frame_wpa3(struct sigma_dut *dut,
12645 struct sigma_conn *conn,
12646 const char *intf,
12647 struct sigma_cmd *cmd)
12648{
12649 const char *val = get_param(cmd, "framename");
12650
12651 if (!val)
12652 return INVALID_SEND_STATUS;
12653
12654 if (strcasecmp(val, "SAQueryReq") == 0) {
12655 val = get_param(cmd, "OCIChannel");
12656
12657 if (!val) {
12658 send_resp(dut, conn, SIGMA_ERROR,
12659 "errorCode,OCIChannel not present");
12660 return STATUS_SENT_ERROR;
12661 }
12662
12663 dut->saquery_oci_freq = channel_to_freq(dut, atoi(val));
12664 if (!dut->saquery_oci_freq) {
12665 send_resp(dut, conn, SIGMA_ERROR,
12666 "errorCode,Invalid OCIChannel number");
12667 return STATUS_SENT_ERROR;
12668 }
12669
12670 return sta_inject_frame(dut, conn, intf, SAQUERY, CORRECT_KEY,
12671 NULL, 0);
12672 }
12673
12674 if (strcasecmp(val, "reassocreq") == 0)
12675 return sta_inject_frame(dut, conn, intf, REASSOCREQ,
12676 CORRECT_KEY, NULL, 0);
12677
Veerendranath9f81dfb2020-08-10 01:21:29 -070012678 if (strcasecmp(val, "ANQPQuery") == 0) {
12679 char buf[50];
12680 const char *dest = get_param(cmd, "DestMac");
12681 const char *chan = get_param(cmd, "channel");
Veerendranath Jakkam78862fc2020-11-19 21:23:27 +053012682 const char *freq_str = get_param(cmd, "ChnlFreq");
Veerendranath9f81dfb2020-08-10 01:21:29 -070012683 int len, freq;
12684
Veerendranath Jakkam78862fc2020-11-19 21:23:27 +053012685 if (freq_str)
12686 freq = atoi(freq_str);
12687 else
12688 freq = chan ? channel_to_freq(dut, atoi(chan)) : 0;
12689
Veerendranath9f81dfb2020-08-10 01:21:29 -070012690 if (!dest || !freq)
12691 return INVALID_SEND_STATUS;
12692
12693 len = snprintf(buf, sizeof(buf), "ANQP_GET %s freq=%d 257",
12694 dest, freq);
12695 if (len < 0 || len >= sizeof(buf)) {
12696 sigma_dut_print(dut, DUT_MSG_ERROR,
12697 "Failed to allocate buf");
12698 return ERROR_SEND_STATUS;
12699 }
12700
12701 if (wpa_command(intf, buf) != 0) {
12702 send_resp(dut, conn, SIGMA_ERROR,
12703 "ErrorCode,Failed to send ANQP Query frame");
12704 return STATUS_SENT_ERROR;
12705 }
12706
12707 sigma_dut_print(dut, DUT_MSG_DEBUG,
12708 "ANQP Query sent: %s", buf);
12709
12710 return SUCCESS_SEND_STATUS;
12711 }
12712
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053012713 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported framename");
12714 return STATUS_SENT_ERROR;
12715}
12716
12717
Vinita S. Malooca85fd22021-01-15 02:54:34 +053012718static int
12719get_type4_frame_classifier(struct sigma_dut *dut, struct sigma_cmd *cmd,
12720 char *pos, int rem_len, int num_of_scs_desc,
12721 int num_of_tclas_elem)
12722{
12723 const char *val;
12724 int ipv6;
12725 int len, total_len = 0;
12726
12727 val = get_param_fmt(cmd, "TCLASElem_Version_%d_%d", num_of_scs_desc,
12728 num_of_tclas_elem);
12729 if (!val) {
12730 sigma_dut_print(dut, DUT_MSG_ERROR, "%s: ip_version empty",
12731 __func__);
12732 return -1;
12733 }
12734
12735 if (strcmp(val, "6") == 0) {
12736 ipv6 = 1;
12737 } else if (strcmp(val, "4") == 0) {
12738 ipv6 = 0;
12739 } else {
12740 sigma_dut_print(dut, DUT_MSG_ERROR, "%s: ip_version invalid",
12741 __func__);
12742 return -1;
12743 }
12744
12745 len = snprintf(pos, rem_len, " ip_version=%s", ipv6 ? "ipv6" : "ipv4");
12746 if (len < 0 || len >= rem_len)
12747 return -1;
12748
12749 pos += len;
12750 rem_len -= len;
12751 total_len += len;
12752
12753 val = get_param_fmt(cmd, "TCLASElem_SourceIPAddr_%d_%d",
12754 num_of_scs_desc, num_of_tclas_elem);
12755 if (val) {
12756 len = snprintf(pos, rem_len, " src_ip=%s", val);
12757 if (len < 0 || len >= rem_len)
12758 return -1;
12759
12760 pos += len;
12761 rem_len -= len;
12762 total_len += len;
12763 }
12764
12765 val = get_param_fmt(cmd, "TCLASElem_DestinationIPAddr_%d_%d",
12766 num_of_scs_desc, num_of_tclas_elem);
12767 if (val) {
12768 len = snprintf(pos, rem_len, " dst_ip=%s", val);
12769 if (len < 0 || len >= rem_len)
12770 return -1;
12771
12772 pos += len;
12773 rem_len -= len;
12774 total_len += len;
12775 }
12776
12777 val = get_param_fmt(cmd, "TCLASElem_SourcePort_%d_%d", num_of_scs_desc,
12778 num_of_tclas_elem);
12779 if (val) {
12780 len = snprintf(pos, rem_len, " src_port=%s", val);
12781 if (len < 0 || len >= rem_len)
12782 return -1;
12783
12784 pos += len;
12785 rem_len -= len;
12786 total_len += len;
12787 }
12788
12789 val = get_param_fmt(cmd, "TCLASElem_DestinationPort_%d_%d",
12790 num_of_scs_desc, num_of_tclas_elem);
12791 if (val) {
12792 len = snprintf(pos, rem_len, " dst_port=%s", val);
12793 if (len < 0 || len >= rem_len)
12794 return -1;
12795
12796 pos += len;
12797 rem_len -= len;
12798 total_len += len;
12799 }
12800
12801 val = get_param_fmt(cmd, "TCLASElem_DSCP_%d_%d", num_of_scs_desc,
12802 num_of_tclas_elem);
12803 if (val) {
12804 len = snprintf(pos, rem_len, " dscp=%s", val);
12805 if (len < 0 || len >= rem_len)
12806 return -1;
12807
12808 pos += len;
12809 rem_len -= len;
12810 total_len += len;
12811 }
12812
12813 val = get_param_fmt(cmd, "TCLASElem_ProtocolNxtHeader_%d_%d",
12814 num_of_scs_desc, num_of_tclas_elem);
12815 if (val) {
12816 char *prot;
12817
12818 switch (atoi(val)) {
12819 case 17:
12820 prot = "udp";
12821 break;
12822 case 6:
12823 prot = "tcp";
12824 break;
12825 case 50:
12826 prot = "esp";
12827 break;
12828 default:
12829 sigma_dut_print(dut, DUT_MSG_ERROR,
12830 "Invalid protocol %d", atoi(val));
12831 return -1;
12832 }
12833
12834 if (ipv6)
12835 len = snprintf(pos, rem_len, " next_header=%s", prot);
12836 else
12837 len = snprintf(pos, rem_len, " protocol=%s", prot);
12838 if (len < 0 || len >= rem_len)
12839 return -1;
12840
12841 pos += len;
12842 rem_len -= len;
12843 total_len += len;
12844 }
12845
12846 return total_len;
12847}
12848
12849
12850static int
12851get_type10_frame_classifier(struct sigma_dut *dut, struct sigma_cmd *cmd,
12852 char *pos, int rem_len, int num_of_scs_desc,
12853 int num_of_tclas_elem)
12854{
12855 const char *val;
12856 int len, total_len = 0;
12857
12858 val = get_param_fmt(cmd, "TCLASElem_ProtoInstance_%d_%d",
12859 num_of_scs_desc, num_of_tclas_elem);
12860 if (val) {
12861 len = snprintf(pos, rem_len, " prot_instance=%s",
12862 val);
12863 if (len < 0 || len >= rem_len)
12864 return -1;
12865
12866 pos += len;
12867 rem_len -= len;
12868 total_len += len;
12869 }
12870
12871 val = get_param_fmt(cmd, "TCLASElem_ProtoNumNextHeader_%d_%d",
12872 num_of_scs_desc, num_of_tclas_elem);
12873 if (val) {
12874 char *prot;
12875
12876 switch (atoi(val)) {
12877 case 17:
12878 prot = "udp";
12879 break;
12880 case 6:
12881 prot = "tcp";
12882 break;
12883 case 50:
12884 prot = "esp";
12885 break;
12886 default:
12887 sigma_dut_print(dut, DUT_MSG_ERROR,
12888 "Invalid protocol %d",
12889 atoi(val));
12890 return -1;
12891 }
12892
12893 len = snprintf(pos, rem_len, " prot_number=%s", prot);
12894 if (len < 0 || len >= rem_len)
12895 return -1;
12896
12897 pos += len;
12898 rem_len -= len;
12899 total_len += len;
12900 }
12901
12902 val = get_param_fmt(cmd, "TCLASElem_FilterValue_%d_%d",
12903 num_of_scs_desc, num_of_tclas_elem);
12904 if (val) {
12905 len = snprintf(pos, rem_len, " filter_value=%s", (val + 2));
12906 if (len < 0 || len >= rem_len)
12907 return -1;
12908
12909 pos += len;
12910 rem_len -= len;
12911 total_len += len;
12912 }
12913
12914 val = get_param_fmt(cmd, "TCLASElem_FilterMask_%d_%d", num_of_scs_desc,
12915 num_of_tclas_elem);
12916 if (val && strlen(val) >= 2) {
12917 len = snprintf(pos, rem_len, " filter_mask=%s", val + 2);
12918 if (len < 0 || len >= rem_len)
12919 return -1;
12920
12921 pos += len;
12922 rem_len -= len;
12923 total_len += len;
12924 }
12925
12926 return total_len;
12927}
12928
12929
12930static enum sigma_cmd_result
12931cmd_sta_send_frame_scs(struct sigma_dut *dut, struct sigma_conn *conn,
12932 const char *intf, struct sigma_cmd *cmd)
12933{
12934 char buf[4096], *pos;
12935 const char *val, *scs_id, *classifier_type;
12936 int len, rem_len, total_bytes;
12937 int num_of_scs_desc = 0, num_of_tclas_elem = 0;
12938
12939 scs_id = get_param(cmd, "SCSDescrElem_SCSID_1");
12940 if (!scs_id) {
12941 sigma_dut_print(dut, DUT_MSG_ERROR, "SCS ID empty");
12942 return INVALID_SEND_STATUS;
12943 }
12944
12945 rem_len = sizeof(buf);
12946 pos = buf;
12947
12948 len = snprintf(buf, sizeof(buf), "SCS");
12949 if (len < 0 || len > rem_len)
12950 goto fail;
12951
12952 pos += len;
12953 rem_len -= len;
12954
12955 while (scs_id) {
12956 num_of_scs_desc++;
12957
12958 val = get_param_fmt(cmd, "SCSDescrElem_RequestType_%d",
12959 num_of_scs_desc);
12960 if (!val)
12961 return INVALID_SEND_STATUS;
12962
12963 if (strcasecmp(val, "Add") == 0) {
12964 len = snprintf(pos, rem_len, " scs_id=%s add",
12965 scs_id);
12966 } else if (strcasecmp(val, "Change") == 0) {
12967 len = snprintf(pos, rem_len, " scs_id=%s change",
12968 scs_id);
12969 } else if (strcasecmp(val, "Remove") == 0) {
12970 len = snprintf(pos, rem_len, " scs_id=%s remove",
12971 scs_id);
12972 if (len < 0 || len >= rem_len)
12973 goto fail;
12974
12975 pos += len;
12976 rem_len -= len;
12977 goto scs_desc_end;
12978 } else {
12979 sigma_dut_print(dut, DUT_MSG_ERROR,
12980 "%s: request type - %s is invalid",
12981 __func__, val);
12982 return INVALID_SEND_STATUS;
12983 }
12984
12985 if (len < 0 || len >= rem_len)
12986 goto fail;
12987
12988 pos += len;
12989 rem_len -= len;
12990
12991 val = get_param_fmt(cmd, "IntraAccessCatElem_UP_%d",
12992 num_of_scs_desc);
12993 if (!val) {
12994 sigma_dut_print(dut, DUT_MSG_ERROR,
12995 "IntraAccess Priority empty");
12996 return INVALID_SEND_STATUS;
12997 }
12998
12999 len = snprintf(pos, rem_len, " scs_up=%s", val);
13000 if (len < 0 || len >= rem_len)
13001 goto fail;
13002
13003 pos += len;
13004 rem_len -= len;
13005
13006 classifier_type = get_param_fmt(cmd,
13007 "TCLASElem_ClassifierType_%d_1",
13008 num_of_scs_desc);
13009 if (!classifier_type) {
13010 sigma_dut_print(dut, DUT_MSG_ERROR,
13011 "classifier type missing");
13012 return INVALID_SEND_STATUS;
13013 }
13014
13015 while (classifier_type) {
13016 num_of_tclas_elem++;
13017
13018 len = snprintf(pos, rem_len, " classifier_type=%s",
13019 classifier_type);
13020 if (len < 0 || len >= rem_len)
13021 goto fail;
13022
13023 pos += len;
13024 rem_len -= len;
13025
13026 if (strcmp(classifier_type, "10") == 0) {
13027 total_bytes = get_type10_frame_classifier(
13028 dut, cmd, pos, rem_len,
13029 num_of_scs_desc,
13030 num_of_tclas_elem);
13031 } else if (strcmp(classifier_type, "4") == 0) {
13032 total_bytes = get_type4_frame_classifier(
13033 dut, cmd, pos, rem_len,
13034 num_of_scs_desc,
13035 num_of_tclas_elem);
13036 } else {
13037 sigma_dut_print(dut, DUT_MSG_ERROR,
13038 "classifier_type invalid");
13039 goto fail;
13040 }
13041
13042 if (total_bytes < 0)
13043 goto fail;
13044
13045 pos += total_bytes;
13046 rem_len -= total_bytes;
13047
13048 classifier_type = get_param_fmt(
13049 cmd, "TCLASElem_ClassifierType_%d_%d",
13050 num_of_scs_desc, num_of_tclas_elem + 1);
13051 }
13052
13053 if (num_of_tclas_elem > 1) {
13054 val = get_param_fmt(cmd,
13055 "TCLASProcessingElem_Processing_%d",
13056 num_of_scs_desc);
13057 if (!val) {
13058 sigma_dut_print(dut, DUT_MSG_ERROR,
13059 "Tclas_processing element %d empty",
13060 num_of_scs_desc);
13061 goto fail;
13062 }
13063
13064 len = snprintf(pos, rem_len,
13065 " tclas_processing=%s", val);
13066 if (len < 0 || len >= rem_len)
13067 goto fail;
13068
13069 pos += len;
13070 rem_len -= len;
13071 }
13072scs_desc_end:
13073 num_of_tclas_elem = 0;
13074 scs_id = get_param_fmt(cmd, "SCSDescrElem_SCSID_%d",
13075 num_of_scs_desc + 1);
13076 }
13077
13078 if (wpa_command(intf, buf) != 0) {
13079 send_resp(dut, conn, SIGMA_ERROR,
13080 "ErrorCode,Failed to send SCS frame request");
13081 return STATUS_SENT_ERROR;
13082 }
13083
13084 sigma_dut_print(dut, DUT_MSG_DEBUG,
13085 "SCS frame request sent: %s", buf);
13086
13087 return SUCCESS_SEND_STATUS;
13088fail:
13089 sigma_dut_print(dut, DUT_MSG_ERROR,
13090 "Failed to create SCS frame request");
13091 return ERROR_SEND_STATUS;
13092}
13093
13094
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053013095static enum sigma_cmd_result
13096cmd_sta_send_frame_mscs(struct sigma_dut *dut, struct sigma_conn *conn,
13097 const char *intf, struct sigma_cmd *cmd)
13098{
13099 char buf[128], *pos;
13100 const char *val, *classifier_type = "04", *type;
13101 int len, rem_len;
13102 u8 up_bitmap;
13103
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053013104 type = get_param(cmd, "Request_Type");
Vinita S. Malooca85fd22021-01-15 02:54:34 +053013105 if (!type) {
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053013106 sigma_dut_print(dut, DUT_MSG_ERROR,
Vinita S. Malooca85fd22021-01-15 02:54:34 +053013107 "%s: type not valid", __func__);
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053013108 return INVALID_SEND_STATUS;
13109 }
13110
13111 rem_len = sizeof(buf);
13112 pos = buf;
13113 if (strcasecmp(type, "add") == 0) {
13114 len = snprintf(pos, rem_len, "MSCS add");
13115 } else if (strcasecmp(type, "update") == 0) {
13116 len = snprintf(pos, rem_len, "MSCS change");
13117 } else if (strcasecmp(type, "remove") == 0) {
13118 if (wpa_command(intf, "MSCS remove") != 0) {
13119 send_resp(dut, conn, SIGMA_ERROR,
13120 "ErrorCode,Failed to send MSCS frame req");
13121 return STATUS_SENT_ERROR;
13122 }
13123 return SUCCESS_SEND_STATUS;
13124 } else {
13125 sigma_dut_print(dut, DUT_MSG_ERROR,
13126 "%s: request type invalid", __func__);
13127 return INVALID_SEND_STATUS;
13128 }
13129
13130 if (len < 0 || len >= rem_len)
13131 goto fail;
13132
13133 pos += len;
13134 rem_len -= len;
13135
13136 val = get_param(cmd, "User_Priority_Bitmap");
13137 if (!val) {
13138 sigma_dut_print(dut, DUT_MSG_ERROR,
13139 "%s: user priority bitmap empty", __func__);
13140 return INVALID_SEND_STATUS;
13141 }
13142
13143 switch (atoi(val)) {
13144 case 0:
13145 up_bitmap = 0x00;
13146 break;
13147 case 1:
13148 up_bitmap = 0xF0;
13149 break;
13150 case 2:
13151 up_bitmap = 0xF6;
13152 break;
13153 default:
13154 sigma_dut_print(dut, DUT_MSG_ERROR,
13155 "%s: Unknown User_Priority_Bitmap value %d",
13156 __func__, atoi(val));
13157 return INVALID_SEND_STATUS;
13158 }
13159
13160 len = snprintf(pos, rem_len, " up_bitmap=%02x", up_bitmap);
13161 if (len < 0 || len >= rem_len)
13162 goto fail;
13163
13164 pos += len;
13165 rem_len -= len;
13166
13167 val = get_param(cmd, "User_Priority_Limit");
13168 if (!val) {
13169 sigma_dut_print(dut, DUT_MSG_ERROR,
13170 "%s: invalid user priority limit", __func__);
13171 return INVALID_SEND_STATUS;
13172 }
13173
13174 len = snprintf(pos, rem_len, " up_limit=%s", val);
13175 if (len < 0 || len >= rem_len)
13176 goto fail;
13177
13178 pos += len;
13179 rem_len -= len;
13180
13181 val = get_param(cmd, "Stream_Timeout");
13182 if (!val)
13183 val = get_param(cmd, "Stream_Timtout");
13184 if (!val) {
13185 sigma_dut_print(dut, DUT_MSG_ERROR,
13186 "%s: invalid stream timeout", __func__);
13187 return INVALID_SEND_STATUS;
13188 }
13189
13190 len = snprintf(pos, rem_len, " stream_timeout=%s", val);
13191 if (len < 0 || len >= rem_len)
13192 goto fail;
13193
13194 pos += len;
13195 rem_len -= len;
13196
13197 val = get_param(cmd, "TCLAS_Mask");
13198 if (!val) {
13199 sigma_dut_print(dut, DUT_MSG_ERROR,
13200 "%s: invalid tclas mask", __func__);
13201 return INVALID_SEND_STATUS;
13202 }
13203
13204 len = snprintf(pos, rem_len, " frame_classifier=%s%lx%032x",
13205 classifier_type, strtol(val, NULL, 2), 0);
13206 if (len < 0 || len >= rem_len)
13207 goto fail;
13208
13209 if (wpa_command(intf, buf) != 0) {
13210 send_resp(dut, conn, SIGMA_ERROR,
13211 "ErrorCode,Failed to send MSCS frame req");
13212 return STATUS_SENT_ERROR;
13213 }
13214
13215 sigma_dut_print(dut, DUT_MSG_DEBUG,
13216 "MSCS frame request sent: %s", buf);
13217
13218 return SUCCESS_SEND_STATUS;
13219fail:
13220 sigma_dut_print(dut, DUT_MSG_ERROR,
13221 "Failed to create MSCS frame req");
13222 return ERROR_SEND_STATUS;
13223}
13224
13225
Vinita S. Malooca85fd22021-01-15 02:54:34 +053013226static enum sigma_cmd_result
Veerendranath Jakkam329a3cd2021-09-11 18:10:13 +053013227cmd_sta_send_frame_dscp_query(struct sigma_dut *dut, struct sigma_conn *conn,
13228 const char *intf, struct sigma_cmd *cmd)
13229{
13230 char buf[150], *pos;
13231 const char *val;
13232 int len, rem_len;
13233
13234 rem_len = sizeof(buf);
13235 pos = buf;
13236
13237 len = snprintf(pos, rem_len, "DSCP_QUERY");
13238 if (len < 0 || len >= rem_len)
13239 goto fail;
13240
13241 pos += len;
13242 rem_len -= len;
13243
13244 val = get_param(cmd, "Wildcard");
13245 if (val && strcasecmp(val, "Yes") == 0) {
13246 len = snprintf(pos, rem_len, " wildcard");
13247 if (len < 0 || len >= rem_len)
13248 goto fail;
13249 } else if (strlen(dut->qm_domain_name)) {
13250 len = snprintf(pos, rem_len, " domain_name=%s",
13251 dut->qm_domain_name);
13252 if (len < 0 || len >= rem_len)
13253 goto fail;
13254 } else {
13255 sigma_dut_print(dut, DUT_MSG_ERROR,
13256 "Invalid DSCP Query configuration");
13257 return INVALID_SEND_STATUS;
13258 }
13259
13260 if (wpa_command(intf, buf) != 0) {
13261 send_resp(dut, conn, SIGMA_ERROR,
13262 "ErrorCode,Failed to send DSCP policy query frame");
13263 return STATUS_SENT_ERROR;
13264 }
13265
13266 sigma_dut_print(dut, DUT_MSG_DEBUG,
13267 "DSCP policy query frame sent: %s", buf);
13268 return SUCCESS_SEND_STATUS;
13269fail:
13270 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to send DSCP query");
13271 return ERROR_SEND_STATUS;
13272}
13273
13274
13275static enum sigma_cmd_result
Vinita S. Malooca85fd22021-01-15 02:54:34 +053013276cmd_sta_send_frame_qm(struct sigma_dut *dut, struct sigma_conn *conn,
13277 const char *intf, struct sigma_cmd *cmd)
13278{
13279 const char *val;
13280
13281 val = get_param(cmd, "FrameName");
13282 if (val) {
13283 if (strcasecmp(val, "MSCSReq") == 0)
13284 return cmd_sta_send_frame_mscs(dut, conn, intf, cmd);
13285 if (strcasecmp(val, "SCSReq") == 0)
13286 return cmd_sta_send_frame_scs(dut, conn, intf, cmd);
Veerendranath Jakkam329a3cd2021-09-11 18:10:13 +053013287 if (strcasecmp(val, "DSCPPolicyQuery") == 0)
13288 return cmd_sta_send_frame_dscp_query(dut, conn, intf,
13289 cmd);
Vinita S. Malooca85fd22021-01-15 02:54:34 +053013290
13291 sigma_dut_print(dut, DUT_MSG_ERROR,
13292 "%s: frame name - %s is invalid",
13293 __func__, val);
13294 }
13295
13296 return INVALID_SEND_STATUS;
13297}
13298
13299
Jouni Malinenf7222712019-06-13 01:50:21 +030013300enum sigma_cmd_result cmd_sta_send_frame(struct sigma_dut *dut,
13301 struct sigma_conn *conn,
13302 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013303{
13304 const char *intf = get_param(cmd, "Interface");
13305 const char *val;
13306 enum send_frame_type frame;
13307 enum send_frame_protection protected;
13308 char buf[100];
13309 unsigned char addr[ETH_ALEN];
13310 int res;
13311
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030013312 if (!intf)
13313 return -1;
13314
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013315 val = get_param(cmd, "program");
13316 if (val == NULL)
13317 val = get_param(cmd, "frame");
13318 if (val && strcasecmp(val, "TDLS") == 0)
13319 return cmd_sta_send_frame_tdls(dut, conn, cmd);
13320 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030013321 strcasecmp(val, "HS2-R2") == 0 ||
13322 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013323 return cmd_sta_send_frame_hs2(dut, conn, cmd);
13324 if (val && strcasecmp(val, "VHT") == 0)
13325 return cmd_sta_send_frame_vht(dut, conn, cmd);
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070013326 if (val && strcasecmp(val, "HE") == 0)
13327 return cmd_sta_send_frame_he(dut, conn, cmd);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -070013328 if (val && strcasecmp(val, "LOC") == 0)
13329 return loc_cmd_sta_send_frame(dut, conn, cmd);
Lior David0fe101e2017-03-09 16:09:50 +020013330 if (val && strcasecmp(val, "60GHz") == 0)
13331 return cmd_sta_send_frame_60g(dut, conn, cmd);
Ashwini Patildb59b3c2017-04-13 15:19:23 +053013332 if (val && strcasecmp(val, "MBO") == 0) {
13333 res = mbo_cmd_sta_send_frame(dut, conn, intf, cmd);
13334 if (res != 2)
13335 return res;
13336 }
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053013337 if (val && strcasecmp(val, "WPA3") == 0)
13338 return cmd_sta_send_frame_wpa3(dut, conn, intf, cmd);
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053013339 if (val && strcasecmp(val, "QM") == 0)
Vinita S. Malooca85fd22021-01-15 02:54:34 +053013340 return cmd_sta_send_frame_qm(dut, conn, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013341
13342 val = get_param(cmd, "TD_DISC");
13343 if (val) {
13344 if (hwaddr_aton(val, addr) < 0)
13345 return -1;
13346 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", val);
13347 if (wpa_command(intf, buf) < 0) {
13348 send_resp(dut, conn, SIGMA_ERROR,
13349 "ErrorCode,Failed to send TDLS discovery");
13350 return 0;
13351 }
13352 return 1;
13353 }
13354
13355 val = get_param(cmd, "TD_Setup");
13356 if (val) {
13357 if (hwaddr_aton(val, addr) < 0)
13358 return -1;
13359 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", val);
13360 if (wpa_command(intf, buf) < 0) {
13361 send_resp(dut, conn, SIGMA_ERROR,
13362 "ErrorCode,Failed to start TDLS setup");
13363 return 0;
13364 }
13365 return 1;
13366 }
13367
13368 val = get_param(cmd, "TD_TearDown");
13369 if (val) {
13370 if (hwaddr_aton(val, addr) < 0)
13371 return -1;
13372 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", val);
13373 if (wpa_command(intf, buf) < 0) {
13374 send_resp(dut, conn, SIGMA_ERROR,
13375 "ErrorCode,Failed to tear down TDLS link");
13376 return 0;
13377 }
13378 return 1;
13379 }
13380
13381 val = get_param(cmd, "TD_ChannelSwitch");
13382 if (val) {
13383 /* TODO */
13384 send_resp(dut, conn, SIGMA_ERROR,
13385 "ErrorCode,TD_ChannelSwitch not yet supported");
13386 return 0;
13387 }
13388
13389 val = get_param(cmd, "TD_NF");
13390 if (val) {
13391 /* TODO */
13392 send_resp(dut, conn, SIGMA_ERROR,
13393 "ErrorCode,TD_NF not yet supported");
13394 return 0;
13395 }
13396
13397 val = get_param(cmd, "PMFFrameType");
13398 if (val == NULL)
13399 val = get_param(cmd, "FrameName");
13400 if (val == NULL)
13401 val = get_param(cmd, "Type");
13402 if (val == NULL)
13403 return -1;
13404 if (strcasecmp(val, "disassoc") == 0)
13405 frame = DISASSOC;
13406 else if (strcasecmp(val, "deauth") == 0)
13407 frame = DEAUTH;
13408 else if (strcasecmp(val, "saquery") == 0)
13409 frame = SAQUERY;
13410 else if (strcasecmp(val, "auth") == 0)
13411 frame = AUTH;
13412 else if (strcasecmp(val, "assocreq") == 0)
13413 frame = ASSOCREQ;
13414 else if (strcasecmp(val, "reassocreq") == 0)
13415 frame = REASSOCREQ;
13416 else if (strcasecmp(val, "neigreq") == 0) {
13417 sigma_dut_print(dut, DUT_MSG_INFO, "Got neighbor request");
13418
13419 val = get_param(cmd, "ssid");
13420 if (val == NULL)
13421 return -1;
13422
13423 res = send_neighbor_request(dut, intf, val);
13424 if (res) {
13425 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
13426 "Failed to send neighbor report request");
13427 return 0;
13428 }
13429
13430 return 1;
Ashwini Patil5acd7382017-04-13 15:55:04 +053013431 } else if (strcasecmp(val, "transmgmtquery") == 0 ||
13432 strcasecmp(val, "BTMQuery") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013433 sigma_dut_print(dut, DUT_MSG_DEBUG,
13434 "Got Transition Management Query");
13435
Ashwini Patil5acd7382017-04-13 15:55:04 +053013436 res = send_trans_mgmt_query(dut, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013437 if (res) {
13438 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
13439 "Failed to send Transition Management Query");
13440 return 0;
13441 }
13442
13443 return 1;
13444 } else {
13445 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
13446 "PMFFrameType");
13447 return 0;
13448 }
13449
13450 val = get_param(cmd, "PMFProtected");
13451 if (val == NULL)
13452 val = get_param(cmd, "Protected");
13453 if (val == NULL)
13454 return -1;
13455 if (strcasecmp(val, "Correct-key") == 0 ||
13456 strcasecmp(val, "CorrectKey") == 0)
13457 protected = CORRECT_KEY;
13458 else if (strcasecmp(val, "IncorrectKey") == 0)
13459 protected = INCORRECT_KEY;
13460 else if (strcasecmp(val, "Unprotected") == 0)
13461 protected = UNPROTECTED;
13462 else {
13463 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
13464 "PMFProtected");
13465 return 0;
13466 }
13467
13468 if (protected != UNPROTECTED &&
13469 (frame == AUTH || frame == ASSOCREQ || frame == REASSOCREQ)) {
13470 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Impossible "
13471 "PMFProtected for auth/assocreq/reassocreq");
13472 return 0;
13473 }
13474
13475 if (if_nametoindex("sigmadut") == 0) {
13476 snprintf(buf, sizeof(buf),
13477 "iw dev %s interface add sigmadut type monitor",
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013478 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013479 if (system(buf) != 0 ||
13480 if_nametoindex("sigmadut") == 0) {
13481 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
13482 "monitor interface with '%s'", buf);
13483 return -2;
13484 }
13485 }
13486
13487 if (system("ifconfig sigmadut up") != 0) {
13488 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
13489 "monitor interface up");
13490 return -2;
13491 }
13492
Veerendranath Jakkam49774122020-07-05 09:52:18 +053013493 return sta_inject_frame(dut, conn, intf, frame, protected, NULL, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013494}
13495
13496
13497static int cmd_sta_set_parameter_hs2(struct sigma_dut *dut,
13498 struct sigma_conn *conn,
13499 struct sigma_cmd *cmd,
13500 const char *ifname)
13501{
13502 char buf[200];
13503 const char *val;
13504
13505 val = get_param(cmd, "ClearARP");
13506 if (val && atoi(val) == 1) {
13507 snprintf(buf, sizeof(buf), "ip neigh flush dev %s", ifname);
13508 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
13509 if (system(buf) != 0) {
13510 send_resp(dut, conn, SIGMA_ERROR,
13511 "errorCode,Failed to clear ARP cache");
13512 return 0;
13513 }
13514 }
13515
13516 return 1;
13517}
13518
13519
13520int cmd_sta_set_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
13521 struct sigma_cmd *cmd)
13522{
13523 const char *intf = get_param(cmd, "Interface");
13524 const char *val;
13525
13526 if (intf == NULL)
13527 return -1;
13528
13529 val = get_param(cmd, "program");
13530 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030013531 strcasecmp(val, "HS2-R2") == 0 ||
13532 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013533 return cmd_sta_set_parameter_hs2(dut, conn, cmd, intf);
13534
13535 return -1;
13536}
13537
13538
Jouni Malinenf7222712019-06-13 01:50:21 +030013539static enum sigma_cmd_result cmd_sta_set_macaddr(struct sigma_dut *dut,
13540 struct sigma_conn *conn,
13541 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013542{
13543 const char *intf = get_param(cmd, "Interface");
13544 const char *mac = get_param(cmd, "MAC");
13545
13546 if (intf == NULL || mac == NULL)
13547 return -1;
13548
13549 sigma_dut_print(dut, DUT_MSG_INFO, "Change local MAC address for "
13550 "interface %s to %s", intf, mac);
13551
13552 if (dut->set_macaddr) {
13553 char buf[128];
13554 int res;
13555 if (strcasecmp(mac, "default") == 0) {
13556 res = snprintf(buf, sizeof(buf), "%s",
13557 dut->set_macaddr);
13558 dut->tmp_mac_addr = 0;
13559 } else {
13560 res = snprintf(buf, sizeof(buf), "%s %s",
13561 dut->set_macaddr, mac);
13562 dut->tmp_mac_addr = 1;
13563 }
13564 if (res < 0 || res >= (int) sizeof(buf))
13565 return -1;
13566 if (system(buf) != 0) {
13567 send_resp(dut, conn, SIGMA_ERROR,
13568 "errorCode,Failed to set MAC "
13569 "address");
13570 return 0;
13571 }
13572 return 1;
13573 }
13574
13575 if (strcasecmp(mac, "default") == 0)
13576 return 1;
13577
13578 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
13579 "command");
13580 return 0;
13581}
13582
13583
13584static int iwpriv_tdlsoffchnmode(struct sigma_dut *dut,
13585 struct sigma_conn *conn, const char *intf,
13586 int val)
13587{
13588 char buf[200];
13589 int res;
13590
13591 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchnmode %d",
13592 intf, val);
13593 if (res < 0 || res >= (int) sizeof(buf))
13594 return -1;
13595 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
13596 if (system(buf) != 0) {
13597 send_resp(dut, conn, SIGMA_ERROR,
13598 "errorCode,Failed to configure offchannel mode");
13599 return 0;
13600 }
13601
13602 return 1;
13603}
13604
13605
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013606static int off_chan_val(enum sec_ch_offset off)
13607{
13608 switch (off) {
13609 case SEC_CH_NO:
13610 return 0;
13611 case SEC_CH_40ABOVE:
13612 return 40;
13613 case SEC_CH_40BELOW:
13614 return -40;
13615 }
13616
13617 return 0;
13618}
13619
13620
13621static int iwpriv_set_offchan(struct sigma_dut *dut, struct sigma_conn *conn,
13622 const char *intf, int off_ch_num,
13623 enum sec_ch_offset sec)
13624{
13625 char buf[200];
13626 int res;
13627
13628 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchan %d",
13629 intf, off_ch_num);
13630 if (res < 0 || res >= (int) sizeof(buf))
13631 return -1;
13632 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
13633 if (system(buf) != 0) {
13634 send_resp(dut, conn, SIGMA_ERROR,
13635 "errorCode,Failed to set offchan");
13636 return 0;
13637 }
13638
13639 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsecchnoffst %d",
13640 intf, off_chan_val(sec));
13641 if (res < 0 || res >= (int) sizeof(buf))
13642 return -1;
13643 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
13644 if (system(buf) != 0) {
13645 send_resp(dut, conn, SIGMA_ERROR,
13646 "errorCode,Failed to set sec chan offset");
13647 return 0;
13648 }
13649
13650 return 1;
13651}
13652
13653
13654static int tdls_set_offchannel_offset(struct sigma_dut *dut,
13655 struct sigma_conn *conn,
13656 const char *intf, int off_ch_num,
13657 enum sec_ch_offset sec)
13658{
13659 char buf[200];
13660 int res;
13661
13662 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNEL %d",
13663 off_ch_num);
13664 if (res < 0 || res >= (int) sizeof(buf))
13665 return -1;
13666 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
13667
13668 if (wpa_command(intf, buf) < 0) {
13669 send_resp(dut, conn, SIGMA_ERROR,
13670 "ErrorCode,Failed to set offchan");
13671 return 0;
13672 }
13673 res = snprintf(buf, sizeof(buf), "DRIVER TDLSSECONDARYCHANNELOFFSET %d",
13674 off_chan_val(sec));
13675 if (res < 0 || res >= (int) sizeof(buf))
13676 return -1;
13677
13678 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
13679
13680 if (wpa_command(intf, buf) < 0) {
13681 send_resp(dut, conn, SIGMA_ERROR,
13682 "ErrorCode,Failed to set sec chan offset");
13683 return 0;
13684 }
13685
13686 return 1;
13687}
13688
13689
13690static int tdls_set_offchannel_mode(struct sigma_dut *dut,
13691 struct sigma_conn *conn,
13692 const char *intf, int val)
13693{
13694 char buf[200];
13695 int res;
13696
13697 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNELMODE %d",
13698 val);
13699 if (res < 0 || res >= (int) sizeof(buf))
13700 return -1;
13701 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
13702
13703 if (wpa_command(intf, buf) < 0) {
13704 send_resp(dut, conn, SIGMA_ERROR,
13705 "ErrorCode,Failed to configure offchannel mode");
13706 return 0;
13707 }
13708
13709 return 1;
13710}
13711
13712
13713static int cmd_sta_set_rfeature_tdls(const char *intf, struct sigma_dut *dut,
13714 struct sigma_conn *conn,
13715 struct sigma_cmd *cmd)
13716{
13717 const char *val;
13718 enum {
13719 CHSM_NOT_SET,
13720 CHSM_ENABLE,
13721 CHSM_DISABLE,
13722 CHSM_REJREQ,
13723 CHSM_UNSOLRESP
13724 } chsm = CHSM_NOT_SET;
13725 int off_ch_num = -1;
13726 enum sec_ch_offset sec_ch = SEC_CH_NO;
13727 int res;
13728
13729 val = get_param(cmd, "Uapsd");
13730 if (val) {
13731 char buf[100];
13732 if (strcasecmp(val, "Enable") == 0)
13733 snprintf(buf, sizeof(buf), "SET ps 99");
13734 else if (strcasecmp(val, "Disable") == 0)
13735 snprintf(buf, sizeof(buf), "SET ps 98");
13736 else {
13737 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
13738 "Unsupported uapsd parameter value");
13739 return 0;
13740 }
13741 if (wpa_command(intf, buf)) {
13742 send_resp(dut, conn, SIGMA_ERROR,
13743 "ErrorCode,Failed to change U-APSD "
13744 "powersave mode");
13745 return 0;
13746 }
13747 }
13748
13749 val = get_param(cmd, "TPKTIMER");
13750 if (val && strcasecmp(val, "DISABLE") == 0) {
13751 if (wpa_command(intf, "SET tdls_testing 0x100")) {
13752 send_resp(dut, conn, SIGMA_ERROR,
13753 "ErrorCode,Failed to enable no TPK "
13754 "expiration test mode");
13755 return 0;
13756 }
13757 dut->no_tpk_expiration = 1;
13758 }
13759
13760 val = get_param(cmd, "ChSwitchMode");
13761 if (val) {
13762 if (strcasecmp(val, "Enable") == 0 ||
13763 strcasecmp(val, "Initiate") == 0)
13764 chsm = CHSM_ENABLE;
13765 else if (strcasecmp(val, "Disable") == 0 ||
13766 strcasecmp(val, "passive") == 0)
13767 chsm = CHSM_DISABLE;
13768 else if (strcasecmp(val, "RejReq") == 0)
13769 chsm = CHSM_REJREQ;
13770 else if (strcasecmp(val, "UnSolResp") == 0)
13771 chsm = CHSM_UNSOLRESP;
13772 else {
13773 send_resp(dut, conn, SIGMA_ERROR,
13774 "ErrorCode,Unknown ChSwitchMode value");
13775 return 0;
13776 }
13777 }
13778
13779 val = get_param(cmd, "OffChNum");
13780 if (val) {
13781 off_ch_num = atoi(val);
13782 if (off_ch_num == 0) {
13783 send_resp(dut, conn, SIGMA_ERROR,
13784 "ErrorCode,Invalid OffChNum");
13785 return 0;
13786 }
13787 }
13788
13789 val = get_param(cmd, "SecChOffset");
13790 if (val) {
13791 if (strcmp(val, "20") == 0)
13792 sec_ch = SEC_CH_NO;
13793 else if (strcasecmp(val, "40above") == 0)
13794 sec_ch = SEC_CH_40ABOVE;
13795 else if (strcasecmp(val, "40below") == 0)
13796 sec_ch = SEC_CH_40BELOW;
13797 else {
13798 send_resp(dut, conn, SIGMA_ERROR,
13799 "ErrorCode,Unknown SecChOffset value");
13800 return 0;
13801 }
13802 }
13803
13804 if (chsm == CHSM_NOT_SET) {
13805 /* no offchannel changes requested */
13806 return 1;
13807 }
13808
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013809 if (strcmp(intf, get_main_ifname(dut)) != 0 &&
13810 strcmp(intf, get_station_ifname(dut)) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013811 send_resp(dut, conn, SIGMA_ERROR,
13812 "ErrorCode,Unknown interface");
13813 return 0;
13814 }
13815
13816 switch (chsm) {
13817 case CHSM_NOT_SET:
Jouni Malinen280f5ba2016-08-29 21:33:10 +030013818 res = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013819 break;
13820 case CHSM_ENABLE:
13821 if (off_ch_num < 0) {
13822 send_resp(dut, conn, SIGMA_ERROR,
13823 "ErrorCode,Missing OffChNum argument");
13824 return 0;
13825 }
13826 if (wifi_chip_type == DRIVER_WCN) {
13827 res = tdls_set_offchannel_offset(dut, conn, intf,
13828 off_ch_num, sec_ch);
13829 } else {
13830 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
13831 sec_ch);
13832 }
13833 if (res != 1)
13834 return res;
13835 if (wifi_chip_type == DRIVER_WCN)
13836 res = tdls_set_offchannel_mode(dut, conn, intf, 1);
13837 else
13838 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 1);
13839 break;
13840 case CHSM_DISABLE:
13841 if (wifi_chip_type == DRIVER_WCN)
13842 res = tdls_set_offchannel_mode(dut, conn, intf, 2);
13843 else
13844 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 2);
13845 break;
13846 case CHSM_REJREQ:
13847 if (wifi_chip_type == DRIVER_WCN)
13848 res = tdls_set_offchannel_mode(dut, conn, intf, 3);
13849 else
13850 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 3);
13851 break;
13852 case CHSM_UNSOLRESP:
13853 if (off_ch_num < 0) {
13854 send_resp(dut, conn, SIGMA_ERROR,
13855 "ErrorCode,Missing OffChNum argument");
13856 return 0;
13857 }
13858 if (wifi_chip_type == DRIVER_WCN) {
13859 res = tdls_set_offchannel_offset(dut, conn, intf,
13860 off_ch_num, sec_ch);
13861 } else {
13862 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
13863 sec_ch);
13864 }
13865 if (res != 1)
13866 return res;
13867 if (wifi_chip_type == DRIVER_WCN)
13868 res = tdls_set_offchannel_mode(dut, conn, intf, 4);
13869 else
13870 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 4);
13871 break;
13872 }
13873
13874 return res;
13875}
13876
13877
13878static int ath_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
13879 struct sigma_conn *conn,
13880 struct sigma_cmd *cmd)
13881{
13882 const char *val;
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053013883 char *token = NULL, *result;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013884
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -070013885 novap_reset(dut, intf, 1);
priyadharshini gowthamane5e25172015-12-08 14:53:48 -080013886
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013887 val = get_param(cmd, "nss_mcs_opt");
13888 if (val) {
13889 /* String (nss_operating_mode; mcs_operating_mode) */
13890 int nss, mcs;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053013891 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013892
13893 token = strdup(val);
13894 if (!token)
13895 return 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053013896 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053013897 if (!result) {
13898 sigma_dut_print(dut, DUT_MSG_ERROR,
13899 "VHT NSS not specified");
13900 goto failed;
13901 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013902 if (strcasecmp(result, "def") != 0) {
13903 nss = atoi(result);
13904 if (nss == 4)
13905 ath_disable_txbf(dut, intf);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070013906 if (run_iwpriv(dut, intf, "nss %d", nss) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013907 goto failed;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070013908
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013909 }
13910
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053013911 result = strtok_r(NULL, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053013912 if (!result) {
13913 sigma_dut_print(dut, DUT_MSG_ERROR,
13914 "VHT MCS not specified");
13915 goto failed;
13916 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013917 if (strcasecmp(result, "def") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070013918 if (run_iwpriv(dut, intf, "set11NRates 0") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013919 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013920 } else {
13921 mcs = atoi(result);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070013922 if (run_iwpriv(dut, intf, "vhtmcs %d", mcs) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013923 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013924 }
13925 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070013926 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013927 }
13928
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053013929 free(token);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013930 return 1;
13931failed:
13932 free(token);
13933 return 0;
13934}
13935
13936
13937static int cmd_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
13938 struct sigma_conn *conn,
13939 struct sigma_cmd *cmd)
13940{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013941 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013942 case DRIVER_ATHEROS:
13943 return ath_sta_set_rfeature_vht(intf, dut, conn, cmd);
13944 default:
13945 send_resp(dut, conn, SIGMA_ERROR,
13946 "errorCode,Unsupported sta_set_rfeature(VHT) with the current driver");
13947 return 0;
13948 }
13949}
13950
13951
Jouni Malinen1702fe32021-06-08 19:08:01 +030013952static enum sigma_cmd_result
13953wcn_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
13954 struct sigma_conn *conn, struct sigma_cmd *cmd)
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080013955{
13956 const char *val;
13957 char *token = NULL, *result;
13958 char buf[60];
13959
13960 val = get_param(cmd, "nss_mcs_opt");
13961 if (val) {
13962 /* String (nss_operating_mode; mcs_operating_mode) */
13963 int nss, mcs, ratecode;
13964 char *saveptr;
13965
13966 token = strdup(val);
13967 if (!token)
Jouni Malinen1702fe32021-06-08 19:08:01 +030013968 return ERROR_SEND_STATUS;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080013969
13970 result = strtok_r(token, ";", &saveptr);
13971 if (!result) {
13972 sigma_dut_print(dut, DUT_MSG_ERROR,
13973 "HE NSS not specified");
13974 goto failed;
13975 }
13976 nss = 1;
13977 if (strcasecmp(result, "def") != 0)
13978 nss = atoi(result);
13979
13980 result = strtok_r(NULL, ";", &saveptr);
13981 if (!result) {
13982 sigma_dut_print(dut, DUT_MSG_ERROR,
13983 "HE MCS not specified");
13984 goto failed;
13985 }
13986 mcs = 7;
13987 if (strcasecmp(result, "def") != 0)
13988 mcs = atoi(result);
13989
Arif Hussain557bf412018-05-25 17:29:36 -070013990 ratecode = 0x20; /* for nss:1 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080013991 if (nss == 2) {
Arif Hussain557bf412018-05-25 17:29:36 -070013992 ratecode = 0x40; /* for nss:2 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080013993 } else if (nss > 2) {
13994 sigma_dut_print(dut, DUT_MSG_ERROR,
13995 "HE NSS %d not supported", nss);
13996 goto failed;
13997 }
13998
Arif Hussain557bf412018-05-25 17:29:36 -070013999 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss);
14000 if (system(buf) != 0) {
14001 sigma_dut_print(dut, DUT_MSG_ERROR,
14002 "nss_mcs_opt: iwpriv %s nss %d failed",
14003 intf, nss);
14004 goto failed;
14005 }
Arif Hussainac6c5112018-05-25 17:34:00 -070014006 dut->sta_nss = nss;
Arif Hussain557bf412018-05-25 17:29:36 -070014007
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014008 /* Add the MCS to the ratecode */
14009 if (mcs >= 0 && mcs <= 11) {
14010 ratecode += mcs;
Arif Hussain557bf412018-05-25 17:29:36 -070014011#ifdef NL80211_SUPPORT
14012 if (dut->device_type == STA_testbed) {
14013 enum he_mcs_config mcs_config;
14014 int ret;
14015
14016 if (mcs <= 7)
14017 mcs_config = HE_80_MCS0_7;
14018 else if (mcs <= 9)
14019 mcs_config = HE_80_MCS0_9;
14020 else
14021 mcs_config = HE_80_MCS0_11;
14022 ret = sta_set_he_mcs(dut, intf, mcs_config);
14023 if (ret) {
14024 sigma_dut_print(dut, DUT_MSG_ERROR,
14025 "nss_mcs_opt: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
14026 mcs, mcs_config, ret);
14027 goto failed;
14028 }
14029 }
14030#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014031 } else {
14032 sigma_dut_print(dut, DUT_MSG_ERROR,
14033 "HE MCS %d not supported", mcs);
14034 goto failed;
14035 }
14036 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0x%03x",
14037 intf, ratecode);
14038 if (system(buf) != 0) {
14039 sigma_dut_print(dut, DUT_MSG_ERROR,
14040 "iwpriv setting of 11ax rates failed");
14041 goto failed;
14042 }
14043 free(token);
14044 }
14045
14046 val = get_param(cmd, "GI");
14047 if (val) {
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080014048 int fix_rate_sgi;
14049
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014050 if (strcmp(val, "0.8") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070014051 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 9", intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080014052 fix_rate_sgi = 1;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014053 } else if (strcmp(val, "1.6") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070014054 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 10",
14055 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080014056 fix_rate_sgi = 2;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014057 } else if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070014058 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 11",
14059 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080014060 fix_rate_sgi = 3;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014061 } else {
14062 send_resp(dut, conn, SIGMA_ERROR,
14063 "errorCode,GI value not supported");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014064 return STATUS_SENT_ERROR;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014065 }
14066 if (system(buf) != 0) {
14067 send_resp(dut, conn, SIGMA_ERROR,
14068 "errorCode,Failed to set shortgi");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014069 return STATUS_SENT_ERROR;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014070 }
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080014071 snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d",
14072 intf, fix_rate_sgi);
14073 if (system(buf) != 0) {
14074 send_resp(dut, conn, SIGMA_ERROR,
14075 "errorCode,Failed to set fix rate shortgi");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014076 return STATUS_SENT_ERROR;
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080014077 }
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014078 }
14079
Subhani Shaik8e7a3052018-04-24 14:03:00 -070014080 val = get_param(cmd, "LTF");
14081 if (val) {
14082#ifdef NL80211_SUPPORT
14083 if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080014084 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_1X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070014085 } if (strcmp(val, "6.4") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080014086 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_2X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070014087 } else if (strcmp(val, "12.8") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080014088 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_4X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070014089 } else {
14090 send_resp(dut, conn, SIGMA_ERROR,
14091 "errorCode, LTF value not supported");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014092 return STATUS_SENT_ERROR;
Subhani Shaik8e7a3052018-04-24 14:03:00 -070014093 }
14094#else /* NL80211_SUPPORT */
14095 sigma_dut_print(dut, DUT_MSG_ERROR,
14096 "LTF cannot be set without NL80211_SUPPORT defined");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014097 return ERROR_SEND_STATUS;
Subhani Shaik8e7a3052018-04-24 14:03:00 -070014098#endif /* NL80211_SUPPORT */
14099 }
14100
Kiran Kumar Lokere1809da12021-06-24 00:45:38 -070014101 val = get_param(cmd, "KeepAlive");
14102 if (val) {
14103 int set_val = QCA_WLAN_KEEP_ALIVE_DEFAULT;
14104
14105 if (strcasecmp(val, "Data") == 0)
14106 set_val = QCA_WLAN_KEEP_ALIVE_DATA;
14107 else if (strcasecmp(val, "Mgmt") == 0)
14108 set_val = QCA_WLAN_KEEP_ALIVE_MGMT;
14109
14110 if (sta_set_keep_alive_data_cfg(dut, intf, set_val)) {
14111 send_resp(dut, conn, SIGMA_ERROR,
14112 "ErrorCode,Failed to set keep alive type config");
14113 return STATUS_SENT_ERROR;
14114 }
14115 }
14116
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -070014117 val = get_param(cmd, "TxSUPPDU");
14118 if (val) {
14119 int set_val = 1;
14120
14121 if (strcasecmp(val, "Enable") == 0)
14122 set_val = 1;
14123 else if (strcasecmp(val, "Disable") == 0)
14124 set_val = 0;
14125
14126 if (sta_set_tx_su_ppdu_cfg(dut, intf, set_val)) {
14127 send_resp(dut, conn, SIGMA_ERROR,
14128 "ErrorCode,Failed to set Tx SU PPDU config");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014129 return STATUS_SENT_ERROR;
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -070014130 }
14131 }
14132
Kiran Kumar Lokere54b72522021-04-01 00:22:44 -070014133 val = get_param(cmd, "Mgmt_Data_TX_Resp_Frame");
14134 if (val) {
14135 int set_val = 0;
14136
14137 if (strcasecmp(val, "Enable") == 0)
14138 set_val = 0;
14139 else if (strcasecmp(val, "Disable") == 0)
14140 set_val = 1;
14141
14142 if (sta_set_mgmt_data_tx_disable_cfg(dut, intf, set_val)) {
14143 send_resp(dut, conn, SIGMA_ERROR,
14144 "ErrorCode,Failed to set mgmt/data Tx disable config");
14145 return STATUS_SENT_ERROR;
14146 }
14147 }
14148
Arif Hussain480d5f42019-03-12 14:40:42 -070014149 val = get_param(cmd, "TWT_Setup");
14150 if (val) {
14151 if (strcasecmp(val, "Request") == 0) {
14152 if (sta_twt_request(dut, conn, cmd)) {
14153 send_resp(dut, conn, SIGMA_ERROR,
Srinivas Girigowda6707f032020-10-26 15:24:46 -070014154 "ErrorCode,TWT setup failed");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014155 return STATUS_SENT_ERROR;
Arif Hussain480d5f42019-03-12 14:40:42 -070014156 }
14157 } else if (strcasecmp(val, "Teardown") == 0) {
14158 if (sta_twt_teardown(dut, conn, cmd)) {
14159 send_resp(dut, conn, SIGMA_ERROR,
Srinivas Girigowda6707f032020-10-26 15:24:46 -070014160 "ErrorCode,TWT teardown failed");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014161 return STATUS_SENT_ERROR;
Arif Hussain480d5f42019-03-12 14:40:42 -070014162 }
14163 }
14164 }
14165
Srinivas Girigowda6707f032020-10-26 15:24:46 -070014166 val = get_param(cmd, "TWT_Operation");
14167 if (val) {
14168 if (strcasecmp(val, "Suspend") == 0) {
14169 if (sta_twt_suspend_or_nudge(dut, conn, cmd)) {
14170 send_resp(dut, conn, SIGMA_ERROR,
14171 "ErrorCode,TWT suspend failed");
14172 return STATUS_SENT_ERROR;
14173 }
14174 } else if (strcasecmp(val, "Resume") == 0) {
14175 if (sta_twt_resume(dut, conn, cmd)) {
14176 send_resp(dut, conn, SIGMA_ERROR,
14177 "ErrorCode,TWT resume failed");
14178 return STATUS_SENT_ERROR;
14179 }
14180 }
14181 }
14182
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -080014183 val = get_param(cmd, "transmitOMI");
14184 if (val && sta_transmit_omi(dut, conn, cmd)) {
14185 send_resp(dut, conn, SIGMA_ERROR,
14186 "ErrorCode,sta_transmit_omi failed");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014187 return STATUS_SENT_ERROR;
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -070014188 }
14189
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080014190 val = get_param(cmd, "Powersave");
14191 if (val) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053014192 int ps;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080014193
14194 if (strcasecmp(val, "off") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053014195 ps = 2;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080014196 } else if (strcasecmp(val, "on") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053014197 ps = 1;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080014198 } else {
14199 sigma_dut_print(dut, DUT_MSG_ERROR,
14200 "Unsupported Powersave value '%s'",
14201 val);
Jouni Malinen1702fe32021-06-08 19:08:01 +030014202 return INVALID_SEND_STATUS;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080014203 }
Vinita S. Malooa8b62722020-04-23 01:45:41 +053014204 if (set_power_save_wcn(dut, intf, ps) < 0)
Jouni Malinen1702fe32021-06-08 19:08:01 +030014205 return ERROR_SEND_STATUS;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080014206 }
14207
Kiran Kumar Lokere2c4b7ce2019-01-30 12:02:28 -080014208 val = get_param(cmd, "MU_EDCA");
14209 if (val) {
14210 if (strcasecmp(val, "Override") == 0) {
14211 if (sta_set_mu_edca_override(dut, intf, 1)) {
14212 send_resp(dut, conn, SIGMA_ERROR,
14213 "errorCode,MU EDCA override set failed");
14214 return STATUS_SENT;
14215 }
14216 } else if (strcasecmp(val, "Disable") == 0) {
14217 if (sta_set_mu_edca_override(dut, intf, 0)) {
14218 send_resp(dut, conn, SIGMA_ERROR,
14219 "errorCode,MU EDCA override disable failed");
14220 return STATUS_SENT;
14221 }
14222 }
14223 }
14224
Kiran Kumar Lokerefa7c7b92021-08-09 00:50:55 -070014225 val = get_param(cmd, "RUAllocTone");
14226 if (val && strcasecmp(val, "242") == 0) {
14227 if (sta_set_ru_242_tone_tx(dut, intf, 1)) {
14228 send_resp(dut, conn, SIGMA_ERROR,
14229 "ErrorCode,Failed to set RU 242 tone Tx");
14230 return STATUS_SENT_ERROR;
14231 }
14232 }
14233
14234 val = get_param(cmd, "PPDUTxType");
14235 if (val && strcasecmp(val, "ER-SU") == 0) {
14236 if (sta_set_er_su_ppdu_type_tx(dut, intf, 1)) {
14237 send_resp(dut, conn, SIGMA_ERROR,
14238 "ErrorCode,Failed to set ER-SU PPDU type Tx");
14239 return STATUS_SENT_ERROR;
14240 }
14241 }
14242
Kiran Kumar Lokeredd086642020-06-04 00:29:26 -070014243 val = get_param(cmd, "Ch_Pref");
14244 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
14245 return STATUS_SENT;
14246
14247 val = get_param(cmd, "Cellular_Data_Cap");
14248 if (val && mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
14249 return STATUS_SENT;
14250
Jouni Malinen1702fe32021-06-08 19:08:01 +030014251 return SUCCESS_SEND_STATUS;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014252
14253failed:
14254 free(token);
Jouni Malinen1702fe32021-06-08 19:08:01 +030014255 return ERROR_SEND_STATUS;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014256}
14257
14258
Jouni Malinen1702fe32021-06-08 19:08:01 +030014259static enum sigma_cmd_result
14260cmd_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
14261 struct sigma_conn *conn, struct sigma_cmd *cmd)
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014262{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020014263 switch (get_driver_type(dut)) {
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014264 case DRIVER_WCN:
14265 return wcn_sta_set_rfeature_he(intf, dut, conn, cmd);
14266 default:
14267 send_resp(dut, conn, SIGMA_ERROR,
14268 "errorCode,Unsupported sta_set_rfeature(HE) with the current driver");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014269 return STATUS_SENT_ERROR;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014270 }
14271}
14272
14273
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080014274static int cmd_sta_set_power_save_he(const char *intf, struct sigma_dut *dut,
14275 struct sigma_conn *conn,
14276 struct sigma_cmd *cmd)
14277{
14278 const char *val;
14279
14280 val = get_param(cmd, "powersave");
14281 if (val) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053014282 int ps;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080014283
14284 if (strcasecmp(val, "off") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053014285 ps = 2;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080014286 } else if (strcasecmp(val, "on") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053014287 ps = 1;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080014288 } else {
14289 sigma_dut_print(dut, DUT_MSG_ERROR,
14290 "Unsupported power save config");
14291 return -1;
14292 }
Vinita S. Malooa8b62722020-04-23 01:45:41 +053014293 if (set_power_save_wcn(dut, intf, ps) < 0)
14294 return 0;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080014295 return 1;
14296 }
14297
14298 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported command");
14299
14300 return 0;
14301}
14302
14303
Ashwini Patil5acd7382017-04-13 15:55:04 +053014304static int btm_query_candidate_list(struct sigma_dut *dut,
14305 struct sigma_conn *conn,
14306 struct sigma_cmd *cmd)
14307{
14308 const char *bssid, *info, *op_class, *ch, *phy_type, *pref;
14309 int len, ret;
14310 char buf[10];
14311
14312 /*
14313 * Neighbor Report elements format:
14314 * neighbor=<BSSID>,<BSSID Information>,<Operating Class>,
14315 * <Channel Number>,<PHY Type>[,<hexdump of Optional Subelements>]
14316 * eg: neighbor=aa:bb:cc:dd:ee:ff,17,81,6,1,030101
14317 */
14318
14319 bssid = get_param(cmd, "Nebor_BSSID");
14320 if (!bssid) {
14321 send_resp(dut, conn, SIGMA_INVALID,
14322 "errorCode,Nebor_BSSID is missing");
14323 return 0;
14324 }
14325
14326 info = get_param(cmd, "Nebor_Bssid_Info");
14327 if (!info) {
14328 sigma_dut_print(dut, DUT_MSG_INFO,
14329 "Using default value for Nebor_Bssid_Info: %s",
14330 DEFAULT_NEIGHBOR_BSSID_INFO);
14331 info = DEFAULT_NEIGHBOR_BSSID_INFO;
14332 }
14333
14334 op_class = get_param(cmd, "Nebor_Op_Class");
14335 if (!op_class) {
14336 send_resp(dut, conn, SIGMA_INVALID,
14337 "errorCode,Nebor_Op_Class is missing");
14338 return 0;
14339 }
14340
14341 ch = get_param(cmd, "Nebor_Op_Ch");
14342 if (!ch) {
14343 send_resp(dut, conn, SIGMA_INVALID,
14344 "errorCode,Nebor_Op_Ch is missing");
14345 return 0;
14346 }
14347
14348 phy_type = get_param(cmd, "Nebor_Phy_Type");
14349 if (!phy_type) {
14350 sigma_dut_print(dut, DUT_MSG_INFO,
14351 "Using default value for Nebor_Phy_Type: %s",
14352 DEFAULT_NEIGHBOR_PHY_TYPE);
14353 phy_type = DEFAULT_NEIGHBOR_PHY_TYPE;
14354 }
14355
14356 /* Parse optional subelements */
14357 buf[0] = '\0';
14358 pref = get_param(cmd, "Nebor_Pref");
14359 if (pref) {
14360 /* hexdump for preferrence subelement */
14361 ret = snprintf(buf, sizeof(buf), ",0301%02x", atoi(pref));
14362 if (ret < 0 || ret >= (int) sizeof(buf)) {
14363 sigma_dut_print(dut, DUT_MSG_ERROR,
14364 "snprintf failed for optional subelement ret: %d",
14365 ret);
14366 send_resp(dut, conn, SIGMA_ERROR,
14367 "errorCode,snprintf failed for subelement");
14368 return 0;
14369 }
14370 }
14371
14372 if (!dut->btm_query_cand_list) {
14373 dut->btm_query_cand_list = calloc(1, NEIGHBOR_REPORT_SIZE);
14374 if (!dut->btm_query_cand_list) {
14375 send_resp(dut, conn, SIGMA_ERROR,
14376 "errorCode,Failed to allocate memory for btm_query_cand_list");
14377 return 0;
14378 }
14379 }
14380
14381 len = strlen(dut->btm_query_cand_list);
14382 ret = snprintf(dut->btm_query_cand_list + len,
14383 NEIGHBOR_REPORT_SIZE - len, " neighbor=%s,%s,%s,%s,%s%s",
14384 bssid, info, op_class, ch, phy_type, buf);
14385 if (ret < 0 || ret >= NEIGHBOR_REPORT_SIZE - len) {
14386 sigma_dut_print(dut, DUT_MSG_ERROR,
14387 "snprintf failed for neighbor report list ret: %d",
14388 ret);
14389 send_resp(dut, conn, SIGMA_ERROR,
14390 "errorCode,snprintf failed for neighbor report");
14391 free(dut->btm_query_cand_list);
14392 dut->btm_query_cand_list = NULL;
14393 return 0;
14394 }
14395
14396 return 1;
14397}
14398
14399
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020014400int sta_extract_60g_ese(struct sigma_dut *dut, struct sigma_cmd *cmd,
14401 struct sigma_ese_alloc *allocs, int *allocs_size)
14402{
14403 int max_count = *allocs_size;
14404 int count = 0, i;
14405 const char *val;
14406
14407 do {
14408 val = get_param_indexed(cmd, "AllocID", count);
14409 if (val)
14410 count++;
14411 } while (val);
14412
14413 if (count == 0 || count > max_count) {
14414 sigma_dut_print(dut, DUT_MSG_ERROR,
14415 "Invalid number of allocations(%d)", count);
14416 return -1;
14417 }
14418
14419 for (i = 0; i < count; i++) {
14420 val = get_param_indexed(cmd, "PercentBI", i);
14421 if (!val) {
14422 sigma_dut_print(dut, DUT_MSG_ERROR,
14423 "Missing PercentBI parameter at index %d",
14424 i);
14425 return -1;
14426 }
14427 allocs[i].percent_bi = atoi(val);
14428
14429 val = get_param_indexed(cmd, "SrcAID", i);
14430 if (val)
14431 allocs[i].src_aid = strtol(val, NULL, 0);
14432 else
14433 allocs[i].src_aid = ESE_BCAST_AID;
14434
14435 val = get_param_indexed(cmd, "DestAID", i);
14436 if (val)
14437 allocs[i].dst_aid = strtol(val, NULL, 0);
14438 else
14439 allocs[i].dst_aid = ESE_BCAST_AID;
14440
14441 allocs[i].type = ESE_CBAP;
14442 sigma_dut_print(dut, DUT_MSG_INFO,
14443 "Alloc %d PercentBI %d SrcAID %d DstAID %d",
14444 i, allocs[i].percent_bi, allocs[i].src_aid,
14445 allocs[i].dst_aid);
14446 }
14447
14448 *allocs_size = count;
14449 return 0;
14450}
14451
14452
14453static int sta_set_60g_ese(struct sigma_dut *dut, int count,
14454 struct sigma_ese_alloc *allocs)
14455{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020014456 switch (get_driver_type(dut)) {
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020014457#ifdef __linux__
14458 case DRIVER_WIL6210:
14459 if (wil6210_set_ese(dut, count, allocs))
14460 return -1;
14461 return 1;
14462#endif /* __linux__ */
14463 default:
14464 sigma_dut_print(dut, DUT_MSG_ERROR,
14465 "Unsupported sta_set_60g_ese with the current driver");
14466 return -1;
14467 }
14468}
14469
14470
14471static int cmd_sta_set_rfeature_60g(const char *intf, struct sigma_dut *dut,
14472 struct sigma_conn *conn,
14473 struct sigma_cmd *cmd)
14474{
14475 const char *val;
14476
14477 val = get_param(cmd, "ExtSchIE");
14478 if (val && !strcasecmp(val, "Enable")) {
14479 struct sigma_ese_alloc allocs[MAX_ESE_ALLOCS];
14480 int count = MAX_ESE_ALLOCS;
14481
14482 if (sta_extract_60g_ese(dut, cmd, allocs, &count))
14483 return -1;
14484 return sta_set_60g_ese(dut, count, allocs);
14485 }
14486
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020014487 val = get_param(cmd, "MCS_FixedRate");
14488 if (val) {
14489 int sta_mcs = atoi(val);
14490
14491 sigma_dut_print(dut, DUT_MSG_INFO, "Force STA MCS to %d",
14492 sta_mcs);
14493 wil6210_set_force_mcs(dut, 1, sta_mcs);
14494
Jouni Malinen0e29cf22019-02-19 01:13:21 +020014495 return SUCCESS_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020014496 }
14497
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020014498 send_resp(dut, conn, SIGMA_ERROR,
14499 "errorCode,Invalid sta_set_rfeature(60G)");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020014500 return STATUS_SENT;
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020014501}
14502
14503
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053014504static int wcn_sta_override_oci(struct sigma_dut *dut, const char *intf,
14505 const char *oci_frametype, uint32_t oci_freq)
14506{
14507#ifdef NL80211_SUPPORT
14508 struct nl_msg *msg;
14509 int ret = 0;
14510 struct nlattr *params;
14511 struct nlattr *attr;
14512 int ifindex;
14513 u8 frame_type;
14514
14515 ifindex = if_nametoindex(intf);
14516 if (ifindex == 0) {
14517 sigma_dut_print(dut, DUT_MSG_ERROR,
14518 "%s: Index for interface %s failed",
14519 __func__, intf);
14520 return -1;
14521 }
14522
14523 if (strcasecmp(oci_frametype, "SAQueryReq") == 0) {
14524 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_SA_QUERY_REQ;
14525 } else if (strcasecmp(oci_frametype, "SAQueryResp") == 0) {
14526 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_SA_QUERY_RESP;
14527 } else if (strcasecmp(oci_frametype, "Reassocreq") == 0) {
14528 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_FT_REASSOC_REQ;
14529 } else {
14530 sigma_dut_print(dut, DUT_MSG_ERROR, "%s: Unknown frametype %s",
14531 __func__, oci_frametype);
14532 return -1;
14533 }
14534
14535
14536 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
14537 NL80211_CMD_VENDOR)) ||
14538 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
14539 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
14540 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
14541 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
14542 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
14543 !(params = nla_nest_start(
14544 msg,
14545 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_OCI_OVERRIDE)) ||
14546 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_OCI_OVERRIDE_FRAME_TYPE,
14547 frame_type) ||
14548 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_OCI_OVERRIDE_FREQUENCY,
14549 oci_freq)) {
14550 sigma_dut_print(dut, DUT_MSG_ERROR,
14551 "%s: err in adding vendor_cmd and vendor_data",
14552 __func__);
14553 nlmsg_free(msg);
14554 return -1;
14555 }
14556 nla_nest_end(msg, params);
14557 nla_nest_end(msg, attr);
14558
14559 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
14560 if (ret) {
14561 sigma_dut_print(dut, DUT_MSG_ERROR,
14562 "%s: err in send_and_recv_msgs, ret=%d",
14563 __func__, ret);
14564 }
14565 return ret;
14566#else /* NL80211_SUPPORT */
14567 sigma_dut_print(dut, DUT_MSG_ERROR,
14568 "OCI override not possible without NL80211_SUPPORT defined");
14569 return -1;
14570#endif /* NL80211_SUPPORT */
14571}
14572
14573
Veerendranath Jakkam50d5c782020-07-22 01:59:01 +053014574static int wcn_sta_ignore_csa(struct sigma_dut *dut, const char *intf,
14575 uint8_t ignore_csa)
14576{
14577#ifdef NL80211_SUPPORT
14578 return wcn_wifi_test_config_set_u8(
14579 dut, intf,
14580 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_IGNORE_CSA, ignore_csa);
14581#else /* NL80211_SUPPORT */
14582 sigma_dut_print(dut, DUT_MSG_ERROR,
14583 "IgnoreCSA can't be set without NL80211_SUPPORT defined");
14584 return -1;
14585#endif /* NL80211_SUPPORT */
14586}
14587
14588
Veerendranath Jakkamc771fac2020-07-22 01:32:56 +053014589static int wcn_sta_set_rsnxe_used(struct sigma_dut *dut, const char *intf,
14590 uint8_t rsnxe_used)
14591{
14592#ifdef NL80211_SUPPORT
14593 return wcn_wifi_test_config_set_u8(
14594 dut, intf,
14595 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_FT_REASSOCREQ_RSNXE_USED,
14596 rsnxe_used);
14597#else /* NL80211_SUPPORT */
14598 sigma_dut_print(dut, DUT_MSG_ERROR,
14599 "RSNXE_Used can't be set without NL80211_SUPPORT defined");
14600 return -1;
14601#endif /* NL80211_SUPPORT */
14602}
14603
14604
Veerendranath Jakkam1e1e5fd2020-09-10 07:12:37 +053014605static int wcn_sta_ignore_sa_query_timeout(struct sigma_dut *dut,
14606 const char *intf,
14607 uint8_t ignore_sa_query_timeout)
14608{
14609#ifdef NL80211_SUPPORT
14610 return wcn_wifi_test_config_set_u8(
14611 dut, intf,
14612 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_IGNORE_SA_QUERY_TIMEOUT,
14613 ignore_sa_query_timeout);
14614#else /* NL80211_SUPPORT */
14615 sigma_dut_print(dut, DUT_MSG_ERROR,
14616 "Ignore SA Query timeout can't be set without NL80211_SUPPORT defined");
14617 return -1;
14618#endif /* NL80211_SUPPORT */
14619}
14620
14621
Jouni Malinen6250cb02020-04-15 13:54:45 +030014622static enum sigma_cmd_result
14623cmd_sta_set_rfeature_wpa3(const char *intf, struct sigma_dut *dut,
14624 struct sigma_conn *conn,
14625 struct sigma_cmd *cmd)
14626{
Vamsi Krishnad29bc762020-05-08 23:23:30 +053014627 const char *val, *oci_chan, *oci_frametype;
Jouni Malinen6250cb02020-04-15 13:54:45 +030014628
Veerendranath Jakkam30bf9072020-04-16 14:37:57 +053014629 val = get_param(cmd, "ReassocReq_RSNXE_Used");
Jouni Malinen6250cb02020-04-15 13:54:45 +030014630 if (val && atoi(val) == 1) {
Veerendranath Jakkamc771fac2020-07-22 01:32:56 +053014631 if (wifi_chip_type == DRIVER_WCN) {
14632 if (wcn_sta_set_rsnxe_used(dut, intf, 1)) {
14633 send_resp(dut, conn, SIGMA_ERROR,
14634 "errorCode,Failed to set ft_rsnxe_used");
14635 return STATUS_SENT_ERROR;
14636 }
14637 return SUCCESS_SEND_STATUS;
14638 } else if (wpa_command(intf, "SET ft_rsnxe_used 1") < 0) {
Jouni Malinen6250cb02020-04-15 13:54:45 +030014639 send_resp(dut, conn, SIGMA_ERROR,
14640 "errorCode,Failed to set ft_rsnxe_used");
14641 return STATUS_SENT_ERROR;
14642 }
14643 return SUCCESS_SEND_STATUS;
14644 }
Vamsi Krishnad29bc762020-05-08 23:23:30 +053014645
14646 oci_chan = get_param(cmd, "OCIChannel");
14647 oci_frametype = get_param(cmd, "OCIFrameType");
14648 if (oci_chan && oci_frametype) {
14649 unsigned int oci_freq = channel_to_freq(dut, atoi(oci_chan));
14650 char buf[100];
14651
14652 if (!oci_freq) {
14653 send_resp(dut, conn, SIGMA_ERROR,
14654 "errorCode,Invalid OCIChannel number");
14655 return STATUS_SENT_ERROR;
14656 }
14657
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053014658 if (wifi_chip_type == DRIVER_WCN &&
14659 (strcasecmp(oci_frametype, "SAQueryReq") == 0 ||
14660 strcasecmp(oci_frametype, "SAQueryResp") == 0 ||
14661 strcasecmp(oci_frametype, "Reassocreq") == 0)) {
14662 if (wcn_sta_override_oci(dut, intf, oci_frametype,
14663 oci_freq)) {
14664 send_resp(dut, conn, SIGMA_ERROR,
14665 "errorCode,Failed to override OCI");
14666 return STATUS_SENT_ERROR;
14667 }
14668 return SUCCESS_SEND_STATUS;
14669 }
14670
Vamsi Krishnad29bc762020-05-08 23:23:30 +053014671 if (strcasecmp(oci_frametype, "eapolM2") == 0) {
14672 snprintf(buf, sizeof(buf),
14673 "SET oci_freq_override_eapol %d", oci_freq);
14674 } else if (strcasecmp(oci_frametype, "SAQueryReq") == 0) {
14675 snprintf(buf, sizeof(buf),
14676 "SET oci_freq_override_saquery_req %d",
14677 oci_freq);
14678 } else if (strcasecmp(oci_frametype, "SAQueryResp") == 0) {
14679 snprintf(buf, sizeof(buf),
14680 "SET oci_freq_override_saquery_resp %d",
14681 oci_freq);
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053014682 } else if (strcasecmp(oci_frametype, "GrpKeyM2") == 0) {
14683 snprintf(buf, sizeof(buf),
14684 "SET oci_freq_override_eapol_g2 %d",
14685 oci_freq);
14686 } else if (strcasecmp(oci_frametype, "Reassocreq") == 0) {
14687 snprintf(buf, sizeof(buf),
14688 "SET oci_freq_override_ft_assoc %d",
14689 oci_freq);
Vamsi Krishnad29bc762020-05-08 23:23:30 +053014690 } else {
14691 send_resp(dut, conn, SIGMA_ERROR,
14692 "errorCode,Unsupported OCIFrameType");
14693 return STATUS_SENT_ERROR;
14694 }
14695 if (wpa_command(intf, buf) < 0) {
14696 send_resp(dut, conn, SIGMA_ERROR,
14697 "errorCode,Failed to set oci_freq_override");
14698 return STATUS_SENT_ERROR;
14699 }
14700 return SUCCESS_SEND_STATUS;
14701 }
14702
Veerendranath Jakkam50d5c782020-07-22 01:59:01 +053014703 val = get_param(cmd, "IgnoreCSA");
14704 if (val && atoi(val) == 1) {
14705 if (wifi_chip_type == DRIVER_WCN) {
14706 if (wcn_sta_ignore_csa(dut, intf, 1)) {
14707 send_resp(dut, conn, SIGMA_ERROR,
14708 "errorCode,Failed to set ignore CSA");
14709 return STATUS_SENT_ERROR;
14710 }
14711 return SUCCESS_SEND_STATUS;
14712 }
14713 }
14714
Veerendranath Jakkam1e1e5fd2020-09-10 07:12:37 +053014715 val = get_param(cmd, "Deauth_Per_SAQueryResp");
14716 if (val && atoi(val) == 0) {
14717 if (wifi_chip_type == DRIVER_WCN) {
14718 if (wcn_sta_ignore_sa_query_timeout(dut, intf, 1)) {
14719 send_resp(dut, conn, SIGMA_ERROR,
14720 "errorCode,Failed to set ignore SA Query timeout");
14721 return STATUS_SENT_ERROR;
14722 }
14723 return SUCCESS_SEND_STATUS;
14724 }
14725 }
14726
Jouni Malinen6250cb02020-04-15 13:54:45 +030014727 send_resp(dut, conn, SIGMA_ERROR,
14728 "errorCode,Unsupported WPA3 rfeature");
14729 return STATUS_SENT_ERROR;
14730}
14731
14732
Veerendranath Jakkam329a3cd2021-09-11 18:10:13 +053014733static enum sigma_cmd_result
14734cmd_sta_set_rfeature_qm(const char *intf, struct sigma_dut *dut,
14735 struct sigma_conn *conn, struct sigma_cmd *cmd)
14736{
14737 const char *val;
14738
14739 val = get_param(cmd, "DomainName_Domain");
14740 if (val) {
14741 if (strlen(val) >= sizeof(dut->qm_domain_name))
14742 return ERROR_SEND_STATUS;
14743
14744 strlcpy(dut->qm_domain_name, val, sizeof(dut->qm_domain_name));
14745 return SUCCESS_SEND_STATUS;
14746 }
14747
14748 send_resp(dut, conn, SIGMA_ERROR,
14749 "errorCode,Unsupported QM rfeature");
14750 return STATUS_SENT_ERROR;
14751}
14752
14753
Jouni Malinenf7222712019-06-13 01:50:21 +030014754static enum sigma_cmd_result cmd_sta_set_rfeature(struct sigma_dut *dut,
14755 struct sigma_conn *conn,
14756 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014757{
14758 const char *intf = get_param(cmd, "Interface");
14759 const char *prog = get_param(cmd, "Prog");
Ashwini Patil68d02cd2017-01-10 15:39:16 +053014760 const char *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014761
Veerendranath Jakkam329a3cd2021-09-11 18:10:13 +053014762 if (!prog)
14763 prog = get_param(cmd, "Program");
14764
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014765 if (intf == NULL || prog == NULL)
14766 return -1;
14767
Ashwini Patil5acd7382017-04-13 15:55:04 +053014768 /* BSS Transition candidate list for BTM query */
14769 val = get_param(cmd, "Nebor_BSSID");
14770 if (val && btm_query_candidate_list(dut, conn, cmd) == 0)
14771 return 0;
14772
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014773 if (strcasecmp(prog, "TDLS") == 0)
14774 return cmd_sta_set_rfeature_tdls(intf, dut, conn, cmd);
14775
14776 if (strcasecmp(prog, "VHT") == 0)
14777 return cmd_sta_set_rfeature_vht(intf, dut, conn, cmd);
14778
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014779 if (strcasecmp(prog, "HE") == 0)
14780 return cmd_sta_set_rfeature_he(intf, dut, conn, cmd);
14781
Ashwini Patil68d02cd2017-01-10 15:39:16 +053014782 if (strcasecmp(prog, "MBO") == 0) {
14783 val = get_param(cmd, "Cellular_Data_Cap");
14784 if (val &&
14785 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
14786 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +053014787
14788 val = get_param(cmd, "Ch_Pref");
14789 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
14790 return 0;
14791
Ashwini Patil68d02cd2017-01-10 15:39:16 +053014792 return 1;
14793 }
14794
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020014795 if (strcasecmp(prog, "60GHz") == 0)
14796 return cmd_sta_set_rfeature_60g(intf, dut, conn, cmd);
14797
Jouni Malinen6250cb02020-04-15 13:54:45 +030014798 if (strcasecmp(prog, "WPA3") == 0)
14799 return cmd_sta_set_rfeature_wpa3(intf, dut, conn, cmd);
Veerendranath Jakkam329a3cd2021-09-11 18:10:13 +053014800 if (strcasecmp(prog, "QM") == 0)
14801 return cmd_sta_set_rfeature_qm(intf, dut, conn, cmd);
Jouni Malinen6250cb02020-04-15 13:54:45 +030014802
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014803 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported Prog");
14804 return 0;
14805}
14806
14807
Jouni Malinenf7222712019-06-13 01:50:21 +030014808static enum sigma_cmd_result cmd_sta_set_radio(struct sigma_dut *dut,
14809 struct sigma_conn *conn,
14810 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014811{
14812 const char *intf = get_param(cmd, "Interface");
14813 const char *mode = get_param(cmd, "Mode");
14814 int res;
14815
14816 if (intf == NULL || mode == NULL)
14817 return -1;
14818
14819 if (strcasecmp(mode, "On") == 0)
14820 res = wpa_command(intf, "SET radio_disabled 0");
14821 else if (strcasecmp(mode, "Off") == 0)
14822 res = wpa_command(intf, "SET radio_disabled 1");
14823 else
14824 return -1;
14825
14826 if (res) {
14827 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
14828 "radio mode");
14829 return 0;
14830 }
14831
14832 return 1;
14833}
14834
14835
Jouni Malinenf7222712019-06-13 01:50:21 +030014836static enum sigma_cmd_result cmd_sta_set_pwrsave(struct sigma_dut *dut,
14837 struct sigma_conn *conn,
14838 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014839{
14840 const char *intf = get_param(cmd, "Interface");
14841 const char *mode = get_param(cmd, "Mode");
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020014842 const char *prog = get_param(cmd, "program");
14843 const char *powersave = get_param(cmd, "powersave");
14844 int res = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014845
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020014846 if (intf == NULL)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014847 return -1;
14848
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020014849 if (prog && strcasecmp(prog, "60GHz") == 0) {
14850 /*
14851 * The CAPI mode parameter does not exist in 60G
14852 * unscheduled PS.
14853 */
Hu Wang5dc3ff12019-06-14 15:14:26 +080014854 if (powersave && strcasecmp(powersave, "unscheduled") == 0)
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020014855 res = set_ps(intf, dut, 1);
Jouni Malinen016ae6c2019-11-04 17:00:01 +020014856 } else if (prog && get_driver_type(dut) == DRIVER_WCN &&
Alexei Avshalom Lazar2f6fdb42019-02-04 14:16:08 +020014857 strcasecmp(prog, "HE") == 0) {
14858 return cmd_sta_set_power_save_he(intf, dut, conn, cmd);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020014859 } else {
14860 if (mode == NULL)
14861 return -1;
14862
14863 if (strcasecmp(mode, "On") == 0)
14864 res = set_ps(intf, dut, 1);
14865 else if (strcasecmp(mode, "Off") == 0)
14866 res = set_ps(intf, dut, 0);
14867 else
14868 return -1;
14869 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014870
14871 if (res) {
14872 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
14873 "power save mode");
14874 return 0;
14875 }
14876
14877 return 1;
14878}
14879
14880
Jouni Malinenf7222712019-06-13 01:50:21 +030014881static enum sigma_cmd_result cmd_sta_bssid_pool(struct sigma_dut *dut,
14882 struct sigma_conn *conn,
14883 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014884{
14885 const char *intf = get_param(cmd, "Interface");
14886 const char *val, *bssid;
14887 int res;
14888 char *buf;
14889 size_t buf_len;
14890
14891 val = get_param(cmd, "BSSID_FILTER");
14892 if (val == NULL)
14893 return -1;
14894
14895 bssid = get_param(cmd, "BSSID_List");
14896 if (atoi(val) == 0 || bssid == NULL) {
14897 /* Disable BSSID filter */
14898 if (wpa_command(intf, "SET bssid_filter ")) {
14899 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed "
14900 "to disable BSSID filter");
14901 return 0;
14902 }
14903
14904 return 1;
14905 }
14906
14907 buf_len = 100 + strlen(bssid);
14908 buf = malloc(buf_len);
14909 if (buf == NULL)
14910 return -1;
14911
14912 snprintf(buf, buf_len, "SET bssid_filter %s", bssid);
14913 res = wpa_command(intf, buf);
14914 free(buf);
14915 if (res) {
14916 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to enable "
14917 "BSSID filter");
14918 return 0;
14919 }
14920
14921 return 1;
14922}
14923
14924
Jouni Malinenf7222712019-06-13 01:50:21 +030014925static enum sigma_cmd_result cmd_sta_reset_parm(struct sigma_dut *dut,
14926 struct sigma_conn *conn,
14927 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014928{
14929 const char *intf = get_param(cmd, "Interface");
14930 const char *val;
14931
14932 /* TODO: ARP */
14933
14934 val = get_param(cmd, "HS2_CACHE_PROFILE");
14935 if (val && strcasecmp(val, "All") == 0)
14936 hs2_clear_credentials(intf);
14937
14938 return 1;
14939}
14940
14941
Jouni Malinenf7222712019-06-13 01:50:21 +030014942static enum sigma_cmd_result cmd_sta_get_key(struct sigma_dut *dut,
14943 struct sigma_conn *conn,
14944 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014945{
14946 const char *intf = get_param(cmd, "Interface");
14947 const char *key_type = get_param(cmd, "KeyType");
14948 char buf[100], resp[200];
14949
14950 if (key_type == NULL)
14951 return -1;
14952
14953 if (strcasecmp(key_type, "GTK") == 0) {
14954 if (wpa_command_resp(intf, "GET gtk", buf, sizeof(buf)) < 0 ||
14955 strncmp(buf, "FAIL", 4) == 0) {
14956 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
14957 "not fetch current GTK");
14958 return 0;
14959 }
14960 snprintf(resp, sizeof(resp), "KeyValue,%s", buf);
14961 send_resp(dut, conn, SIGMA_COMPLETE, resp);
14962 return 0;
14963 } else {
14964 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
14965 "KeyType");
14966 return 0;
14967 }
14968
14969 return 1;
14970}
14971
14972
14973static int hs2_set_policy(struct sigma_dut *dut)
14974{
14975#ifdef ANDROID
14976 system("ip rule del prio 23000");
14977 if (system("ip rule add from all lookup main prio 23000") != 0) {
14978 sigma_dut_print(dut, DUT_MSG_ERROR,
14979 "Failed to run:ip rule add from all lookup main prio");
14980 return -1;
14981 }
14982 if (system("ip route flush cache") != 0) {
14983 sigma_dut_print(dut, DUT_MSG_ERROR,
14984 "Failed to run ip route flush cache");
14985 return -1;
14986 }
14987 return 1;
14988#else /* ANDROID */
14989 return 0;
14990#endif /* ANDROID */
14991}
14992
14993
Jouni Malinenf7222712019-06-13 01:50:21 +030014994static enum sigma_cmd_result cmd_sta_hs2_associate(struct sigma_dut *dut,
14995 struct sigma_conn *conn,
14996 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014997{
14998 const char *intf = get_param(cmd, "Interface");
14999 const char *val = get_param(cmd, "Ignore_blacklist");
Jouni Malinen439352d2018-09-13 03:42:23 +030015000 const char *band = get_param(cmd, "Band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015001 struct wpa_ctrl *ctrl;
Jouni Malinen3aa72862019-05-29 23:14:51 +030015002 int res, r;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015003 char bssid[20], ssid[40], resp[100], buf[100], blacklisted[100];
15004 int tries = 0;
15005 int ignore_blacklist = 0;
15006 const char *events[] = {
15007 "CTRL-EVENT-CONNECTED",
15008 "INTERWORKING-BLACKLISTED",
15009 "INTERWORKING-NO-MATCH",
15010 NULL
15011 };
15012
15013 start_sta_mode(dut);
15014
Jouni Malinen439352d2018-09-13 03:42:23 +030015015 if (band) {
15016 if (strcmp(band, "2.4") == 0) {
15017 wpa_command(intf, "SET setband 2G");
15018 } else if (strcmp(band, "5") == 0) {
15019 wpa_command(intf, "SET setband 5G");
15020 } else {
15021 send_resp(dut, conn, SIGMA_ERROR,
15022 "errorCode,Unsupported band");
15023 return 0;
15024 }
15025 }
15026
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015027 blacklisted[0] = '\0';
15028 if (val && atoi(val))
15029 ignore_blacklist = 1;
15030
15031try_again:
15032 ctrl = open_wpa_mon(intf);
15033 if (ctrl == NULL) {
15034 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
15035 "wpa_supplicant monitor connection");
15036 return -2;
15037 }
15038
15039 tries++;
15040 if (wpa_command(intf, "INTERWORKING_SELECT auto")) {
15041 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start "
15042 "Interworking connection");
15043 wpa_ctrl_detach(ctrl);
15044 wpa_ctrl_close(ctrl);
15045 return 0;
15046 }
15047
15048 buf[0] = '\0';
15049 while (1) {
15050 char *pos;
15051 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
15052 pos = strstr(buf, "INTERWORKING-BLACKLISTED");
15053 if (!pos)
15054 break;
15055 pos += 25;
15056 sigma_dut_print(dut, DUT_MSG_DEBUG, "Found blacklisted AP: %s",
15057 pos);
15058 if (!blacklisted[0])
15059 memcpy(blacklisted, pos, strlen(pos) + 1);
15060 }
15061
15062 if (ignore_blacklist && blacklisted[0]) {
15063 char *end;
15064 end = strchr(blacklisted, ' ');
15065 if (end)
15066 *end = '\0';
15067 sigma_dut_print(dut, DUT_MSG_DEBUG, "Try to connect to a blacklisted network: %s",
15068 blacklisted);
Jouni Malinen3aa72862019-05-29 23:14:51 +030015069 r = snprintf(buf, sizeof(buf), "INTERWORKING_CONNECT %s",
15070 blacklisted);
15071 if (r < 0 || r >= sizeof(buf) || wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015072 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start Interworking connection to blacklisted network");
15073 wpa_ctrl_detach(ctrl);
15074 wpa_ctrl_close(ctrl);
15075 return 0;
15076 }
15077 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
15078 buf, sizeof(buf));
15079 }
15080
15081 wpa_ctrl_detach(ctrl);
15082 wpa_ctrl_close(ctrl);
15083
15084 if (res < 0) {
15085 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
15086 "connect");
15087 return 0;
15088 }
15089
15090 if (strstr(buf, "INTERWORKING-NO-MATCH") ||
15091 strstr(buf, "INTERWORKING-BLACKLISTED")) {
15092 if (tries < 2) {
15093 sigma_dut_print(dut, DUT_MSG_INFO, "No match found - try again to verify no APs were missed in the scan");
15094 goto try_again;
15095 }
15096 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,No network with "
15097 "matching credentials found");
15098 return 0;
15099 }
15100
15101 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
15102 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
15103 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
15104 "get current BSSID/SSID");
15105 return 0;
15106 }
15107
15108 snprintf(resp, sizeof(resp), "SSID,%s,BSSID,%s", ssid, bssid);
15109 send_resp(dut, conn, SIGMA_COMPLETE, resp);
15110 hs2_set_policy(dut);
15111 return 0;
15112}
15113
15114
Jouni Malinenf7222712019-06-13 01:50:21 +030015115static enum sigma_cmd_result cmd_sta_hs2_venue_info(struct sigma_dut *dut,
15116 struct sigma_conn *conn,
15117 struct sigma_cmd *cmd)
Jouni Malinenb639f1c2018-09-13 02:39:46 +030015118{
15119 const char *intf = get_param(cmd, "Interface");
15120 const char *display = get_param(cmd, "Display");
15121 struct wpa_ctrl *ctrl;
15122 char buf[300], params[400], *pos;
15123 char bssid[20];
15124 int info_avail = 0;
15125 unsigned int old_timeout;
15126 int res;
15127
15128 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
15129 send_resp(dut, conn, SIGMA_ERROR,
15130 "ErrorCode,Could not get current BSSID");
15131 return 0;
15132 }
15133 ctrl = open_wpa_mon(intf);
15134 if (!ctrl) {
15135 sigma_dut_print(dut, DUT_MSG_ERROR,
15136 "Failed to open wpa_supplicant monitor connection");
15137 return -2;
15138 }
15139
15140 snprintf(buf, sizeof(buf), "ANQP_GET %s 277", bssid);
15141 wpa_command(intf, buf);
15142
15143 res = get_wpa_cli_event(dut, ctrl, "GAS-QUERY-DONE", buf, sizeof(buf));
15144 if (res < 0) {
15145 send_resp(dut, conn, SIGMA_ERROR,
15146 "ErrorCode,Could not complete GAS query");
15147 goto fail;
15148 }
15149
15150 old_timeout = dut->default_timeout;
15151 dut->default_timeout = 2;
15152 res = get_wpa_cli_event(dut, ctrl, "RX-VENUE-URL", buf, sizeof(buf));
15153 dut->default_timeout = old_timeout;
15154 if (res < 0)
15155 goto done;
15156 pos = strchr(buf, ' ');
15157 if (!pos)
15158 goto done;
15159 pos++;
15160 pos = strchr(pos, ' ');
15161 if (!pos)
15162 goto done;
15163 pos++;
15164 info_avail = 1;
15165 snprintf(params, sizeof(params), "browser %s", pos);
15166
15167 if (display && strcasecmp(display, "Yes") == 0) {
15168 pid_t pid;
15169
15170 pid = fork();
15171 if (pid < 0) {
15172 perror("fork");
15173 return -1;
15174 }
15175
15176 if (pid == 0) {
15177 run_hs20_osu(dut, params);
15178 exit(0);
15179 }
15180 }
15181
15182done:
15183 snprintf(buf, sizeof(buf), "Info_available,%s",
15184 info_avail ? "Yes" : "No");
15185 send_resp(dut, conn, SIGMA_COMPLETE, buf);
15186fail:
15187 wpa_ctrl_detach(ctrl);
15188 wpa_ctrl_close(ctrl);
15189 return 0;
15190}
15191
15192
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015193static int sta_add_credential_uname_pwd(struct sigma_dut *dut,
15194 struct sigma_conn *conn,
15195 const char *ifname,
15196 struct sigma_cmd *cmd)
15197{
15198 const char *val;
15199 int id;
15200
15201 id = add_cred(ifname);
15202 if (id < 0)
15203 return -2;
15204 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
15205
15206 val = get_param(cmd, "prefer");
15207 if (val && atoi(val) > 0)
15208 set_cred(ifname, id, "priority", "1");
15209
15210 val = get_param(cmd, "REALM");
15211 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
15212 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
15213 "realm");
15214 return 0;
15215 }
15216
15217 val = get_param(cmd, "HOME_FQDN");
15218 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
15219 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
15220 "home_fqdn");
15221 return 0;
15222 }
15223
15224 val = get_param(cmd, "Username");
15225 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
15226 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
15227 "username");
15228 return 0;
15229 }
15230
15231 val = get_param(cmd, "Password");
15232 if (val && set_cred_quoted(ifname, id, "password", val) < 0) {
15233 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
15234 "password");
15235 return 0;
15236 }
15237
15238 val = get_param(cmd, "ROOT_CA");
15239 if (val) {
15240 char fname[200];
15241 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
15242#ifdef __linux__
15243 if (!file_exists(fname)) {
15244 char msg[300];
15245 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
15246 "file (%s) not found", fname);
15247 send_resp(dut, conn, SIGMA_ERROR, msg);
15248 return 0;
15249 }
15250#endif /* __linux__ */
15251 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
15252 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
15253 "not set root CA");
15254 return 0;
15255 }
15256 }
15257
15258 return 1;
15259}
15260
15261
15262static int update_devdetail_imsi(struct sigma_dut *dut, const char *imsi)
15263{
15264 FILE *in, *out;
15265 char buf[500];
15266 int found = 0;
15267
15268 in = fopen("devdetail.xml", "r");
15269 if (in == NULL)
15270 return -1;
15271 out = fopen("devdetail.xml.tmp", "w");
15272 if (out == NULL) {
15273 fclose(in);
15274 return -1;
15275 }
15276
15277 while (fgets(buf, sizeof(buf), in)) {
15278 char *pos = strstr(buf, "<IMSI>");
15279 if (pos) {
15280 sigma_dut_print(dut, DUT_MSG_INFO, "Updated DevDetail IMSI to %s",
15281 imsi);
15282 pos += 6;
15283 *pos = '\0';
15284 fprintf(out, "%s%s</IMSI>\n", buf, imsi);
15285 found++;
15286 } else {
15287 fprintf(out, "%s", buf);
15288 }
15289 }
15290
15291 fclose(out);
15292 fclose(in);
15293 if (found)
15294 rename("devdetail.xml.tmp", "devdetail.xml");
15295 else
15296 unlink("devdetail.xml.tmp");
15297
15298 return 0;
15299}
15300
15301
15302static int sta_add_credential_sim(struct sigma_dut *dut,
15303 struct sigma_conn *conn,
15304 const char *ifname, struct sigma_cmd *cmd)
15305{
15306 const char *val, *imsi = NULL;
15307 int id;
15308 char buf[200];
15309 int res;
15310 const char *pos;
15311 size_t mnc_len;
15312 char plmn_mcc[4];
15313 char plmn_mnc[4];
15314
15315 id = add_cred(ifname);
15316 if (id < 0)
15317 return -2;
15318 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
15319
15320 val = get_param(cmd, "prefer");
15321 if (val && atoi(val) > 0)
15322 set_cred(ifname, id, "priority", "1");
15323
15324 val = get_param(cmd, "PLMN_MCC");
15325 if (val == NULL) {
15326 send_resp(dut, conn, SIGMA_ERROR,
15327 "errorCode,Missing PLMN_MCC");
15328 return 0;
15329 }
15330 if (strlen(val) != 3) {
15331 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MCC");
15332 return 0;
15333 }
15334 snprintf(plmn_mcc, sizeof(plmn_mcc), "%s", val);
15335
15336 val = get_param(cmd, "PLMN_MNC");
15337 if (val == NULL) {
15338 send_resp(dut, conn, SIGMA_ERROR,
15339 "errorCode,Missing PLMN_MNC");
15340 return 0;
15341 }
15342 if (strlen(val) != 2 && strlen(val) != 3) {
15343 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MNC");
15344 return 0;
15345 }
15346 snprintf(plmn_mnc, sizeof(plmn_mnc), "%s", val);
15347
15348 val = get_param(cmd, "IMSI");
15349 if (val == NULL) {
15350 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing SIM "
15351 "IMSI");
15352 return 0;
15353 }
15354
15355 imsi = pos = val;
15356
15357 if (strncmp(plmn_mcc, pos, 3) != 0) {
15358 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MCC mismatch");
15359 return 0;
15360 }
15361 pos += 3;
15362
15363 mnc_len = strlen(plmn_mnc);
15364 if (mnc_len < 2) {
15365 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC not set");
15366 return 0;
15367 }
15368
15369 if (strncmp(plmn_mnc, pos, mnc_len) != 0) {
15370 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC mismatch");
15371 return 0;
15372 }
15373 pos += mnc_len;
15374
15375 res = snprintf(buf, sizeof(buf), "%s%s-%s",plmn_mcc, plmn_mnc, pos);
15376 if (res < 0 || res >= (int) sizeof(buf))
15377 return -1;
15378 if (set_cred_quoted(ifname, id, "imsi", buf) < 0) {
15379 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
15380 "not set IMSI");
15381 return 0;
15382 }
15383
15384 val = get_param(cmd, "Password");
15385 if (val && set_cred_quoted(ifname, id, "milenage", val) < 0) {
15386 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
15387 "not set password");
15388 return 0;
15389 }
15390
Jouni Malinenba630452018-06-22 11:49:59 +030015391 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015392 /*
15393 * Set provisioning_sp for the test cases where SIM/USIM
15394 * provisioning is used.
15395 */
15396 if (val && set_cred_quoted(ifname, id, "provisioning_sp",
15397 "wi-fi.org") < 0) {
15398 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
15399 "not set provisioning_sp");
15400 return 0;
15401 }
15402
15403 update_devdetail_imsi(dut, imsi);
15404 }
15405
15406 return 1;
15407}
15408
15409
15410static int sta_add_credential_cert(struct sigma_dut *dut,
15411 struct sigma_conn *conn,
15412 const char *ifname,
15413 struct sigma_cmd *cmd)
15414{
15415 const char *val;
15416 int id;
15417
15418 id = add_cred(ifname);
15419 if (id < 0)
15420 return -2;
15421 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
15422
15423 val = get_param(cmd, "prefer");
15424 if (val && atoi(val) > 0)
15425 set_cred(ifname, id, "priority", "1");
15426
15427 val = get_param(cmd, "REALM");
15428 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
15429 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
15430 "realm");
15431 return 0;
15432 }
15433
15434 val = get_param(cmd, "HOME_FQDN");
15435 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
15436 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
15437 "home_fqdn");
15438 return 0;
15439 }
15440
15441 val = get_param(cmd, "Username");
15442 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
15443 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
15444 "username");
15445 return 0;
15446 }
15447
15448 val = get_param(cmd, "clientCertificate");
15449 if (val) {
15450 char fname[200];
15451 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
15452#ifdef __linux__
15453 if (!file_exists(fname)) {
15454 char msg[300];
15455 snprintf(msg, sizeof(msg),
15456 "ErrorCode,clientCertificate "
15457 "file (%s) not found", fname);
15458 send_resp(dut, conn, SIGMA_ERROR, msg);
15459 return 0;
15460 }
15461#endif /* __linux__ */
15462 if (set_cred_quoted(ifname, id, "client_cert", fname) < 0) {
15463 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
15464 "not set client_cert");
15465 return 0;
15466 }
15467 if (set_cred_quoted(ifname, id, "private_key", fname) < 0) {
15468 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
15469 "not set private_key");
15470 return 0;
15471 }
15472 }
15473
15474 val = get_param(cmd, "ROOT_CA");
15475 if (val) {
15476 char fname[200];
15477 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
15478#ifdef __linux__
15479 if (!file_exists(fname)) {
15480 char msg[300];
15481 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
15482 "file (%s) not found", fname);
15483 send_resp(dut, conn, SIGMA_ERROR, msg);
15484 return 0;
15485 }
15486#endif /* __linux__ */
15487 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
15488 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
15489 "not set root CA");
15490 return 0;
15491 }
15492 }
15493
15494 return 1;
15495}
15496
15497
Jouni Malinenf7222712019-06-13 01:50:21 +030015498static enum sigma_cmd_result cmd_sta_add_credential(struct sigma_dut *dut,
15499 struct sigma_conn *conn,
15500 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015501{
15502 const char *intf = get_param(cmd, "Interface");
15503 const char *type;
15504
15505 start_sta_mode(dut);
15506
15507 type = get_param(cmd, "Type");
15508 if (!type)
15509 return -1;
15510
15511 if (strcasecmp(type, "uname_pwd") == 0)
15512 return sta_add_credential_uname_pwd(dut, conn, intf, cmd);
15513
15514 if (strcasecmp(type, "sim") == 0)
15515 return sta_add_credential_sim(dut, conn, intf, cmd);
15516
15517 if (strcasecmp(type, "cert") == 0)
15518 return sta_add_credential_cert(dut, conn, intf, cmd);
15519
15520 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported credential "
15521 "type");
15522 return 0;
15523}
15524
15525
Jouni Malinenf7222712019-06-13 01:50:21 +030015526static enum sigma_cmd_result cmd_sta_scan(struct sigma_dut *dut,
15527 struct sigma_conn *conn,
15528 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015529{
15530 const char *intf = get_param(cmd, "Interface");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080015531 const char *val, *bssid, *ssid, *scan_freq, *short_ssid;
Veerendranathdc581b52020-08-10 03:29:08 -070015532 char buf[4096], scan_res[20];
vamsi krishna89ad8c62017-09-19 12:51:18 +053015533 char ssid_hex[65];
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080015534 int wildcard_ssid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015535 int res;
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080015536 enum sigma_cmd_result status;
Jouni Malinen228a2fc2020-06-22 23:37:45 +030015537 struct wpa_ctrl *ctrl = NULL;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015538
Jouni Malinen8c1abeb2019-11-06 18:48:34 +020015539 start_sta_mode(dut);
15540
Arif Hussain66a4af02019-02-07 15:04:51 -080015541 val = get_param(cmd, "GetParameter");
15542 if (val && strcmp(val, "SSID_BSSID") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020015543 if (get_wpa_ssid_bssid(dut, get_station_ifname(dut),
Arif Hussain66a4af02019-02-07 15:04:51 -080015544 buf, sizeof(buf)) < 0) {
15545 sigma_dut_print(dut, DUT_MSG_ERROR,
15546 "Could not get ssid bssid");
15547 return ERROR_SEND_STATUS;
15548 }
15549
15550 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
15551 send_resp(dut, conn, SIGMA_COMPLETE, buf);
15552 return STATUS_SENT;
15553 }
15554
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015555 val = get_param(cmd, "HESSID");
15556 if (val) {
15557 res = snprintf(buf, sizeof(buf), "SET hessid %s", val);
15558 if (res < 0 || res >= (int) sizeof(buf))
15559 return -1;
15560 wpa_command(intf, buf);
15561 }
15562
15563 val = get_param(cmd, "ACCS_NET_TYPE");
15564 if (val) {
15565 res = snprintf(buf, sizeof(buf), "SET access_network_type %s",
15566 val);
15567 if (res < 0 || res >= (int) sizeof(buf))
15568 return -1;
15569 wpa_command(intf, buf);
15570 }
15571
Kiran Kumar Lokere69d89952021-08-08 23:41:46 -070015572 if (get_param(cmd, "RxMac"))
15573 sta_set_scan_unicast_probe(dut, intf, 1);
15574
vamsi krishna89ad8c62017-09-19 12:51:18 +053015575 bssid = get_param(cmd, "Bssid");
15576 ssid = get_param(cmd, "Ssid");
Kiran Kumar Lokere69d89952021-08-08 23:41:46 -070015577 if (!bssid)
15578 bssid = get_param(cmd, "RxMac");
vamsi krishna89ad8c62017-09-19 12:51:18 +053015579
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080015580 if (ssid && strcasecmp(ssid, "ZeroLength") == 0 &&
15581 dut->device_type == STA_testbed) {
15582 ssid = NULL;
15583 wildcard_ssid = 1;
15584 }
15585
vamsi krishna89ad8c62017-09-19 12:51:18 +053015586 if (ssid) {
15587 if (2 * strlen(ssid) >= sizeof(ssid_hex)) {
15588 send_resp(dut, conn, SIGMA_ERROR,
15589 "ErrorCode,Too long SSID");
15590 return 0;
15591 }
15592 ascii2hexstr(ssid, ssid_hex);
15593 }
15594
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080015595 short_ssid = get_param(cmd, "ShortSSID");
15596 if (short_ssid) {
15597 uint32_t short_ssid_hex;
15598
15599 short_ssid_hex = strtoul(short_ssid, NULL, 16);
15600 short_ssid_hex = ((short_ssid_hex & 0xFF) << 24) |
15601 (((short_ssid_hex >> 8) & 0xFF) << 16) |
15602 (((short_ssid_hex >> 16) & 0xFF) << 8) |
15603 ((short_ssid_hex >> 24) & 0xFF);
15604
15605 res = snprintf(buf, sizeof(buf),
15606 "VENDOR_ELEM_ADD 14 ff053a%08x",
15607 short_ssid_hex);
15608 if (res < 0 || res >= (int) sizeof(buf) ||
15609 wpa_command(intf, buf)) {
15610 send_resp(dut, conn, SIGMA_ERROR,
15611 "errorCode,Failed to add short SSID");
15612 return STATUS_SENT_ERROR;
15613 }
15614 }
15615
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080015616 scan_freq = get_param(cmd, "ChnlFreq");
Veerendranath Jakkam132c4b42020-08-10 00:29:03 +053015617 if (scan_freq) {
15618 if (strcasecmp(scan_freq, "2G") == 0)
15619 scan_freq = "2412-2462";
15620 else if (strcasecmp(scan_freq, "5G") == 0)
15621 scan_freq = "5180-5925";
15622 }
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080015623
Jouni Malinen228a2fc2020-06-22 23:37:45 +030015624 val = get_param(cmd, "WaitCompletion");
15625 if (val && atoi(val) == 1) {
15626 ctrl = open_wpa_mon(intf);
15627 if (!ctrl) {
15628 send_resp(dut, conn, SIGMA_ERROR,
15629 "errorCode,Failed to open monitor socket");
15630 return STATUS_SENT_ERROR;
15631 }
15632 }
15633
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080015634 res = snprintf(buf, sizeof(buf), "SCAN%s%s%s%s%s%s%s",
vamsi krishna89ad8c62017-09-19 12:51:18 +053015635 bssid ? " bssid=": "",
15636 bssid ? bssid : "",
15637 ssid ? " ssid " : "",
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080015638 ssid ? ssid_hex : "",
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080015639 wildcard_ssid ? " wildcard_ssid=1" : "",
15640 scan_freq ? " freq=" : "",
15641 scan_freq ? scan_freq : "");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080015642 if (res < 0 || res >= (int) sizeof(buf)) {
15643 send_resp(dut, conn, SIGMA_ERROR,
15644 "errorCode,Could not build scan command");
15645 status = STATUS_SENT_ERROR;
15646 goto remove_s_ssid;
15647 }
vamsi krishna89ad8c62017-09-19 12:51:18 +053015648
Veerendranathdc581b52020-08-10 03:29:08 -070015649 res = wpa_command_resp(intf, buf, scan_res, sizeof(scan_res));
15650 if (strncmp(scan_res, "FAIL-BUSY", 9) == 0) {
15651 sigma_dut_print(dut, DUT_MSG_DEBUG,
15652 "Scan request rejected with busy status, abort ongoing scan and try again");
15653 wpa_command(intf, "ABORT_SCAN");
15654 res = wpa_command(intf, buf);
15655 }
15656
15657 if (res < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015658 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not start "
15659 "scan");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080015660 status = STATUS_SENT_ERROR;
15661 } else {
15662 status = SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015663 }
15664
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080015665remove_s_ssid:
15666 if (short_ssid && wpa_command(intf, "VENDOR_ELEM_REMOVE 14 *"))
15667 sigma_dut_print(dut, DUT_MSG_ERROR,
15668 "Failed to delete vendor element");
15669
Jouni Malinen228a2fc2020-06-22 23:37:45 +030015670 if (ctrl) {
15671 if (status == SUCCESS_SEND_STATUS) {
15672 res = get_wpa_cli_event(dut, ctrl,
15673 "CTRL-EVENT-SCAN-RESULTS",
15674 buf, sizeof(buf));
15675 if (res < 0) {
15676 send_resp(dut, conn, SIGMA_ERROR,
15677 "ErrorCode,scan did not complete");
15678 status = STATUS_SENT_ERROR;
15679 }
15680 }
15681
15682 wpa_ctrl_detach(ctrl);
15683 wpa_ctrl_close(ctrl);
15684 }
15685
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080015686 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015687}
15688
15689
Jouni Malinenf7222712019-06-13 01:50:21 +030015690static enum sigma_cmd_result cmd_sta_scan_bss(struct sigma_dut *dut,
15691 struct sigma_conn *conn,
15692 struct sigma_cmd *cmd)
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020015693{
15694 const char *intf = get_param(cmd, "Interface");
15695 const char *bssid;
15696 char buf[4096], *pos;
15697 int freq, chan;
15698 char *ssid;
15699 char resp[100];
15700 int res;
15701 struct wpa_ctrl *ctrl;
15702
15703 bssid = get_param(cmd, "BSSID");
15704 if (!bssid) {
15705 send_resp(dut, conn, SIGMA_INVALID,
15706 "errorCode,BSSID argument is missing");
15707 return 0;
15708 }
15709
15710 ctrl = open_wpa_mon(intf);
15711 if (!ctrl) {
15712 sigma_dut_print(dut, DUT_MSG_ERROR,
15713 "Failed to open wpa_supplicant monitor connection");
15714 return -1;
15715 }
15716
15717 if (wpa_command(intf, "SCAN TYPE=ONLY")) {
15718 send_resp(dut, conn, SIGMA_ERROR,
15719 "errorCode,Could not start scan");
15720 wpa_ctrl_detach(ctrl);
15721 wpa_ctrl_close(ctrl);
15722 return 0;
15723 }
15724
15725 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
15726 buf, sizeof(buf));
15727
15728 wpa_ctrl_detach(ctrl);
15729 wpa_ctrl_close(ctrl);
15730
15731 if (res < 0) {
15732 send_resp(dut, conn, SIGMA_ERROR,
15733 "errorCode,Scan did not complete");
15734 return 0;
15735 }
15736
15737 snprintf(buf, sizeof(buf), "BSS %s", bssid);
15738 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
15739 strncmp(buf, "id=", 3) != 0) {
15740 send_resp(dut, conn, SIGMA_ERROR,
15741 "errorCode,Specified BSSID not found");
15742 return 0;
15743 }
15744
15745 pos = strstr(buf, "\nfreq=");
15746 if (!pos) {
15747 send_resp(dut, conn, SIGMA_ERROR,
15748 "errorCode,Channel not found");
15749 return 0;
15750 }
15751 freq = atoi(pos + 6);
15752 chan = freq_to_channel(freq);
15753
15754 pos = strstr(buf, "\nssid=");
15755 if (!pos) {
15756 send_resp(dut, conn, SIGMA_ERROR,
15757 "errorCode,SSID not found");
15758 return 0;
15759 }
15760 ssid = pos + 6;
15761 pos = strchr(ssid, '\n');
15762 if (pos)
15763 *pos = '\0';
15764 snprintf(resp, sizeof(resp), "ssid,%s,bsschannel,%d", ssid, chan);
15765 send_resp(dut, conn, SIGMA_COMPLETE, resp);
15766 return 0;
15767}
15768
15769
Jouni Malinenf7222712019-06-13 01:50:21 +030015770static enum sigma_cmd_result cmd_sta_set_systime(struct sigma_dut *dut,
15771 struct sigma_conn *conn,
15772 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015773{
15774#ifdef __linux__
15775 struct timeval tv;
15776 struct tm tm;
15777 time_t t;
15778 const char *val;
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053015779 int v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015780
Jouni Malinen016ae6c2019-11-04 17:00:01 +020015781 wpa_command(get_station_ifname(dut), "PMKSA_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015782
15783 memset(&tm, 0, sizeof(tm));
15784 val = get_param(cmd, "seconds");
15785 if (val)
15786 tm.tm_sec = atoi(val);
15787 val = get_param(cmd, "minutes");
15788 if (val)
15789 tm.tm_min = atoi(val);
15790 val = get_param(cmd, "hours");
15791 if (val)
15792 tm.tm_hour = atoi(val);
15793 val = get_param(cmd, "date");
15794 if (val)
15795 tm.tm_mday = atoi(val);
15796 val = get_param(cmd, "month");
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053015797 if (val) {
15798 v = atoi(val);
15799 if (v < 1 || v > 12) {
15800 send_resp(dut, conn, SIGMA_INVALID,
15801 "errorCode,Invalid month");
15802 return 0;
15803 }
15804 tm.tm_mon = v - 1;
15805 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015806 val = get_param(cmd, "year");
15807 if (val) {
15808 int year = atoi(val);
15809#ifdef ANDROID
15810 if (year > 2035)
15811 year = 2035; /* years beyond 2035 not supported */
15812#endif /* ANDROID */
15813 tm.tm_year = year - 1900;
15814 }
15815 t = mktime(&tm);
15816 if (t == (time_t) -1) {
15817 send_resp(dut, conn, SIGMA_ERROR,
15818 "errorCode,Invalid date or time");
15819 return 0;
15820 }
15821
15822 memset(&tv, 0, sizeof(tv));
15823 tv.tv_sec = t;
15824
15825 if (settimeofday(&tv, NULL) < 0) {
15826 sigma_dut_print(dut, DUT_MSG_INFO, "settimeofday failed: %s",
15827 strerror(errno));
15828 send_resp(dut, conn, SIGMA_ERROR,
15829 "errorCode,Failed to set time");
15830 return 0;
15831 }
15832
15833 return 1;
15834#endif /* __linux__ */
15835
15836 return -1;
15837}
15838
15839
Jouni Malinenf7222712019-06-13 01:50:21 +030015840static enum sigma_cmd_result cmd_sta_osu(struct sigma_dut *dut,
15841 struct sigma_conn *conn,
15842 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015843{
15844 const char *intf = get_param(cmd, "Interface");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030015845 const char *name, *osu_ssid, *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015846 int prod_ess_assoc = 1;
Jouni Malinen4c8681c2018-09-12 23:28:11 +030015847 char buf[300], bssid[100], ssid[100];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015848 int res;
15849 struct wpa_ctrl *ctrl;
15850
15851 name = get_param(cmd, "osuFriendlyName");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030015852 osu_ssid = get_param(cmd, "osu_ssid");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015853
15854 val = get_param(cmd, "ProdESSAssoc");
15855 if (val)
15856 prod_ess_assoc = atoi(val);
15857
15858 kill_dhcp_client(dut, intf);
15859 if (start_dhcp_client(dut, intf) < 0)
15860 return -2;
15861
15862 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger OSU");
15863 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
15864 res = snprintf(buf, sizeof(buf),
Jouni Malinen4c8681c2018-09-12 23:28:11 +030015865 "%s %s%s%s %s%s%s signup osu-ca.pem",
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015866 prod_ess_assoc ? "" : "-N",
15867 name ? "-O'" : "", name ? name : "",
Jouni Malinen4c8681c2018-09-12 23:28:11 +030015868 name ? "'" : "",
15869 osu_ssid ? "-o'" : "", osu_ssid ? osu_ssid : "",
15870 osu_ssid ? "'" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015871
Kanchanapally, Vidyullatha12b66762015-12-31 16:46:42 +053015872 hs2_set_policy(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015873 if (run_hs20_osu(dut, buf) < 0) {
15874 FILE *f;
15875
15876 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to complete OSU");
15877
15878 f = fopen("hs20-osu-client.res", "r");
15879 if (f) {
15880 char resp[400], res[300], *pos;
15881 if (!fgets(res, sizeof(res), f))
15882 res[0] = '\0';
15883 pos = strchr(res, '\n');
15884 if (pos)
15885 *pos = '\0';
15886 fclose(f);
15887 sigma_dut_summary(dut, "hs20-osu-client provisioning failed: %s",
15888 res);
15889 snprintf(resp, sizeof(resp), "notify-send '%s'", res);
15890 if (system(resp) != 0) {
15891 }
15892 snprintf(resp, sizeof(resp),
15893 "SSID,,BSSID,,failureReason,%s", res);
15894 send_resp(dut, conn, SIGMA_COMPLETE, resp);
15895 return 0;
15896 }
15897
15898 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
15899 return 0;
15900 }
15901
15902 if (!prod_ess_assoc)
15903 goto report;
15904
15905 ctrl = open_wpa_mon(intf);
15906 if (ctrl == NULL) {
15907 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
15908 "wpa_supplicant monitor connection");
15909 return -1;
15910 }
15911
15912 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
15913 buf, sizeof(buf));
15914
15915 wpa_ctrl_detach(ctrl);
15916 wpa_ctrl_close(ctrl);
15917
15918 if (res < 0) {
15919 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to connect to "
15920 "network after OSU");
15921 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
15922 return 0;
15923 }
15924
15925report:
15926 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
15927 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
15928 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get BSSID/SSID");
15929 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
15930 return 0;
15931 }
15932
15933 snprintf(buf, sizeof(buf), "SSID,%s,BSSID,%s", ssid, bssid);
15934 send_resp(dut, conn, SIGMA_COMPLETE, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015935 return 0;
15936}
15937
15938
Jouni Malinenf7222712019-06-13 01:50:21 +030015939static enum sigma_cmd_result cmd_sta_policy_update(struct sigma_dut *dut,
15940 struct sigma_conn *conn,
15941 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015942{
15943 const char *val;
15944 int timeout = 120;
15945
15946 val = get_param(cmd, "PolicyUpdate");
15947 if (val == NULL || atoi(val) == 0)
15948 return 1; /* No operation requested */
15949
15950 val = get_param(cmd, "Timeout");
15951 if (val)
15952 timeout = atoi(val);
15953
15954 if (timeout) {
15955 /* TODO: time out the command and return
15956 * PolicyUpdateStatus,TIMEOUT if needed. */
15957 }
15958
15959 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger policy update");
15960 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
15961 if (run_hs20_osu(dut, "pol_upd fqdn=wi-fi.org") < 0) {
15962 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,FAIL");
15963 return 0;
15964 }
15965
15966 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,SUCCESS");
15967 return 0;
15968}
15969
15970
Jouni Malinenf7222712019-06-13 01:50:21 +030015971static enum sigma_cmd_result cmd_sta_er_config(struct sigma_dut *dut,
15972 struct sigma_conn *conn,
15973 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015974{
15975 struct wpa_ctrl *ctrl;
15976 const char *intf = get_param(cmd, "Interface");
15977 const char *bssid = get_param(cmd, "Bssid");
15978 const char *ssid = get_param(cmd, "SSID");
15979 const char *security = get_param(cmd, "Security");
15980 const char *passphrase = get_param(cmd, "Passphrase");
15981 const char *pin = get_param(cmd, "PIN");
15982 char buf[1000];
15983 char ssid_hex[200], passphrase_hex[200];
15984 const char *keymgmt, *cipher;
15985
15986 if (intf == NULL)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020015987 intf = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015988
15989 if (!bssid) {
15990 send_resp(dut, conn, SIGMA_ERROR,
15991 "ErrorCode,Missing Bssid argument");
15992 return 0;
15993 }
15994
15995 if (!ssid) {
15996 send_resp(dut, conn, SIGMA_ERROR,
15997 "ErrorCode,Missing SSID argument");
15998 return 0;
15999 }
16000
16001 if (!security) {
16002 send_resp(dut, conn, SIGMA_ERROR,
16003 "ErrorCode,Missing Security argument");
16004 return 0;
16005 }
16006
16007 if (!passphrase) {
16008 send_resp(dut, conn, SIGMA_ERROR,
16009 "ErrorCode,Missing Passphrase argument");
16010 return 0;
16011 }
16012
16013 if (!pin) {
16014 send_resp(dut, conn, SIGMA_ERROR,
16015 "ErrorCode,Missing PIN argument");
16016 return 0;
16017 }
16018
vamsi krishna8c9c1562017-05-12 15:51:46 +053016019 if (2 * strlen(ssid) >= sizeof(ssid_hex) ||
16020 2 * strlen(passphrase) >= sizeof(passphrase_hex)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016021 send_resp(dut, conn, SIGMA_ERROR,
16022 "ErrorCode,Too long SSID/passphrase");
16023 return 0;
16024 }
16025
16026 ctrl = open_wpa_mon(intf);
16027 if (ctrl == NULL) {
16028 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
16029 "wpa_supplicant monitor connection");
16030 return -2;
16031 }
16032
16033 if (strcasecmp(security, "wpa2-psk") == 0) {
16034 keymgmt = "WPA2PSK";
16035 cipher = "CCMP";
16036 } else {
16037 wpa_ctrl_detach(ctrl);
16038 wpa_ctrl_close(ctrl);
16039 send_resp(dut, conn, SIGMA_ERROR,
16040 "ErrorCode,Unsupported Security value");
16041 return 0;
16042 }
16043
16044 ascii2hexstr(ssid, ssid_hex);
16045 ascii2hexstr(passphrase, passphrase_hex);
16046 snprintf(buf, sizeof(buf), "WPS_REG %s %s %s %s %s %s",
16047 bssid, pin, ssid_hex, keymgmt, cipher, passphrase_hex);
16048
16049 if (wpa_command(intf, buf) < 0) {
16050 wpa_ctrl_detach(ctrl);
16051 wpa_ctrl_close(ctrl);
16052 send_resp(dut, conn, SIGMA_ERROR,
16053 "ErrorCode,Failed to start registrar");
16054 return 0;
16055 }
16056
16057 snprintf(dut->er_oper_bssid, sizeof(dut->er_oper_bssid), "%s", bssid);
16058 dut->er_oper_performed = 1;
16059
16060 return wps_connection_event(dut, conn, ctrl, intf, 0);
16061}
16062
16063
Jouni Malinenf7222712019-06-13 01:50:21 +030016064static enum sigma_cmd_result
16065cmd_sta_wps_connect_pw_token(struct sigma_dut *dut, struct sigma_conn *conn,
16066 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016067{
16068 struct wpa_ctrl *ctrl;
16069 const char *intf = get_param(cmd, "Interface");
16070 const char *bssid = get_param(cmd, "Bssid");
16071 char buf[100];
16072
16073 if (!bssid) {
16074 send_resp(dut, conn, SIGMA_ERROR,
16075 "ErrorCode,Missing Bssid argument");
16076 return 0;
16077 }
16078
16079 ctrl = open_wpa_mon(intf);
16080 if (ctrl == NULL) {
16081 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
16082 "wpa_supplicant monitor connection");
16083 return -2;
16084 }
16085
16086 snprintf(buf, sizeof(buf), "WPS_NFC %s", bssid);
16087
16088 if (wpa_command(intf, buf) < 0) {
16089 wpa_ctrl_detach(ctrl);
16090 wpa_ctrl_close(ctrl);
16091 send_resp(dut, conn, SIGMA_ERROR,
16092 "ErrorCode,Failed to start registrar");
16093 return 0;
16094 }
16095
16096 return wps_connection_event(dut, conn, ctrl, intf, 0);
16097}
16098
16099
Jouni Malinenf7222712019-06-13 01:50:21 +030016100static enum sigma_cmd_result cmd_start_wps_registration(struct sigma_dut *dut,
16101 struct sigma_conn *conn,
16102 struct sigma_cmd *cmd)
vamsi krishna9b144002017-09-20 13:28:13 +053016103{
16104 struct wpa_ctrl *ctrl;
16105 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020016106 const char *network_mode = get_param(cmd, "network_mode");
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020016107 const char *config_method = get_param(cmd, "WPSConfigMethod");
16108 const char *role;
vamsi krishna9b144002017-09-20 13:28:13 +053016109 int res;
16110 char buf[256];
16111 const char *events[] = {
16112 "CTRL-EVENT-CONNECTED",
16113 "WPS-OVERLAP-DETECTED",
16114 "WPS-TIMEOUT",
16115 "WPS-FAIL",
16116 NULL
16117 };
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020016118 int id = 0;
vamsi krishna9b144002017-09-20 13:28:13 +053016119
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020016120 /* 60G WPS tests do not pass Interface parameter */
16121 if (!intf)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020016122 intf = get_main_ifname(dut);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020016123
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020016124 if (dut->mode == SIGMA_MODE_AP)
16125 return ap_wps_registration(dut, conn, cmd);
16126
16127 if (config_method) {
16128 /* WFA_CS_WPS_PIN_KEYPAD mode is set when using the
16129 * sta_wps_enter_pin before calling start_wps_registration. */
16130 if (strcasecmp(config_method, "PBC") == 0)
16131 dut->wps_method = WFA_CS_WPS_PBC;
16132 }
16133 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
16134 send_resp(dut, conn, SIGMA_ERROR,
16135 "ErrorCode,WPS parameters not yet set");
16136 return STATUS_SENT;
16137 }
16138
16139 /* Make sure WPS is enabled (also for STA mode) */
16140 dut->wps_disable = 0;
16141
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020016142 if (dut->band == WPS_BAND_60G && network_mode &&
16143 strcasecmp(network_mode, "PBSS") == 0) {
16144 sigma_dut_print(dut, DUT_MSG_DEBUG,
16145 "Set PBSS network mode, network id %d", id);
Jouni Malinen016ae6c2019-11-04 17:00:01 +020016146 if (set_network(get_station_ifname(dut), id, "pbss", "1") < 0)
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020016147 return -2;
16148 }
16149
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020016150 if (dut->force_rsn_ie) {
16151 sigma_dut_print(dut, DUT_MSG_DEBUG, "Force RSN_IE: %d",
16152 dut->force_rsn_ie);
16153 if (sta_60g_force_rsn_ie(dut, dut->force_rsn_ie) < 0) {
16154 sigma_dut_print(dut, DUT_MSG_INFO,
16155 "Failed to force RSN_IE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020016156 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020016157 }
16158 }
16159
vamsi krishna9b144002017-09-20 13:28:13 +053016160 ctrl = open_wpa_mon(intf);
16161 if (!ctrl) {
16162 sigma_dut_print(dut, DUT_MSG_ERROR,
16163 "Failed to open wpa_supplicant monitor connection");
16164 return -2;
16165 }
16166
16167 role = get_param(cmd, "WpsRole");
16168 if (!role) {
16169 send_resp(dut, conn, SIGMA_INVALID,
16170 "ErrorCode,WpsRole not provided");
16171 goto fail;
16172 }
16173
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020016174 if (strcasecmp(role, "Enrollee") != 0) {
16175 /* Registrar role for STA not supported */
16176 send_resp(dut, conn, SIGMA_ERROR,
16177 "ErrorCode,Unsupported WpsRole value");
16178 goto fail;
16179 }
16180
16181 if (is_60g_sigma_dut(dut)) {
16182 if (dut->wps_method == WFA_CS_WPS_PBC)
16183 snprintf(buf, sizeof(buf), "WPS_PBC");
16184 else /* WFA_CS_WPS_PIN_KEYPAD */
16185 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
16186 dut->wps_pin);
16187 if (wpa_command(intf, buf) < 0) {
16188 send_resp(dut, conn, SIGMA_ERROR,
16189 "ErrorCode,Failed to start WPS");
vamsi krishna9b144002017-09-20 13:28:13 +053016190 goto fail;
16191 }
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020016192 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
16193 if (res < 0) {
16194 send_resp(dut, conn, SIGMA_ERROR,
16195 "ErrorCode,WPS connection did not complete");
16196 goto fail;
16197 }
16198 if (strstr(buf, "WPS-TIMEOUT")) {
16199 send_resp(dut, conn, SIGMA_COMPLETE, "WpsState,NoPeer");
16200 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
16201 send_resp(dut, conn, SIGMA_COMPLETE,
16202 "WpsState,OverlapSession");
16203 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
16204 send_resp(dut, conn, SIGMA_COMPLETE,
16205 "WpsState,Successful");
16206 } else {
16207 send_resp(dut, conn, SIGMA_COMPLETE,
16208 "WpsState,Failure");
16209 }
16210 } else {
16211 if (dut->wps_method == WFA_CS_WPS_PBC) {
vamsi krishna9b144002017-09-20 13:28:13 +053016212 if (wpa_command(intf, "WPS_PBC") < 0) {
16213 send_resp(dut, conn, SIGMA_ERROR,
16214 "ErrorCode,Failed to enable PBC");
16215 goto fail;
16216 }
16217 } else {
16218 /* TODO: PIN method */
16219 send_resp(dut, conn, SIGMA_ERROR,
16220 "ErrorCode,Unsupported WpsConfigMethod value");
16221 goto fail;
16222 }
16223 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
16224 if (res < 0) {
16225 send_resp(dut, conn, SIGMA_ERROR,
16226 "ErrorCode,WPS connection did not complete");
16227 goto fail;
16228 }
16229 if (strstr(buf, "WPS-TIMEOUT")) {
16230 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,NoPeer");
16231 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
16232 send_resp(dut, conn, SIGMA_ERROR,
16233 "ErrorCode,OverlapSession");
16234 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
16235 send_resp(dut, conn, SIGMA_COMPLETE, "Successful");
16236 } else {
16237 send_resp(dut, conn, SIGMA_ERROR,
16238 "ErrorCode,WPS operation failed");
16239 }
vamsi krishna9b144002017-09-20 13:28:13 +053016240 }
16241
16242fail:
16243 wpa_ctrl_detach(ctrl);
16244 wpa_ctrl_close(ctrl);
16245 return 0;
16246}
16247
16248
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016249static int req_intf(struct sigma_cmd *cmd)
16250{
16251 return get_param(cmd, "interface") == NULL ? -1 : 0;
16252}
16253
16254
16255void sta_register_cmds(void)
16256{
16257 sigma_dut_reg_cmd("sta_get_ip_config", req_intf,
16258 cmd_sta_get_ip_config);
16259 sigma_dut_reg_cmd("sta_set_ip_config", req_intf,
16260 cmd_sta_set_ip_config);
16261 sigma_dut_reg_cmd("sta_get_info", req_intf, cmd_sta_get_info);
16262 sigma_dut_reg_cmd("sta_get_mac_address", req_intf,
16263 cmd_sta_get_mac_address);
16264 sigma_dut_reg_cmd("sta_is_connected", req_intf, cmd_sta_is_connected);
16265 sigma_dut_reg_cmd("sta_verify_ip_connection", req_intf,
16266 cmd_sta_verify_ip_connection);
16267 sigma_dut_reg_cmd("sta_get_bssid", req_intf, cmd_sta_get_bssid);
16268 sigma_dut_reg_cmd("sta_set_encryption", req_intf,
16269 cmd_sta_set_encryption);
16270 sigma_dut_reg_cmd("sta_set_psk", req_intf, cmd_sta_set_psk);
16271 sigma_dut_reg_cmd("sta_set_eaptls", req_intf, cmd_sta_set_eaptls);
16272 sigma_dut_reg_cmd("sta_set_eapttls", req_intf, cmd_sta_set_eapttls);
16273 sigma_dut_reg_cmd("sta_set_eapsim", req_intf, cmd_sta_set_eapsim);
16274 sigma_dut_reg_cmd("sta_set_peap", req_intf, cmd_sta_set_peap);
16275 sigma_dut_reg_cmd("sta_set_eapfast", req_intf, cmd_sta_set_eapfast);
16276 sigma_dut_reg_cmd("sta_set_eapaka", req_intf, cmd_sta_set_eapaka);
16277 sigma_dut_reg_cmd("sta_set_eapakaprime", req_intf,
16278 cmd_sta_set_eapakaprime);
16279 sigma_dut_reg_cmd("sta_set_security", req_intf, cmd_sta_set_security);
16280 sigma_dut_reg_cmd("sta_set_uapsd", req_intf, cmd_sta_set_uapsd);
16281 /* TODO: sta_set_ibss */
16282 /* TODO: sta_set_mode */
16283 sigma_dut_reg_cmd("sta_set_wmm", req_intf, cmd_sta_set_wmm);
16284 sigma_dut_reg_cmd("sta_associate", req_intf, cmd_sta_associate);
16285 /* TODO: sta_up_load */
16286 sigma_dut_reg_cmd("sta_preset_testparameters", req_intf,
16287 cmd_sta_preset_testparameters);
16288 /* TODO: sta_set_system */
16289 sigma_dut_reg_cmd("sta_set_11n", req_intf, cmd_sta_set_11n);
16290 /* TODO: sta_set_rifs_test */
16291 sigma_dut_reg_cmd("sta_set_wireless", req_intf, cmd_sta_set_wireless);
16292 sigma_dut_reg_cmd("sta_send_addba", req_intf, cmd_sta_send_addba);
16293 /* TODO: sta_send_coexist_mgmt */
16294 sigma_dut_reg_cmd("sta_disconnect", req_intf, cmd_sta_disconnect);
16295 sigma_dut_reg_cmd("sta_reassoc", req_intf, cmd_sta_reassoc);
16296 sigma_dut_reg_cmd("sta_reassociate", req_intf, cmd_sta_reassoc);
16297 sigma_dut_reg_cmd("sta_reset_default", req_intf,
16298 cmd_sta_reset_default);
16299 sigma_dut_reg_cmd("sta_send_frame", req_intf, cmd_sta_send_frame);
16300 sigma_dut_reg_cmd("sta_set_macaddr", req_intf, cmd_sta_set_macaddr);
16301 sigma_dut_reg_cmd("sta_set_rfeature", req_intf, cmd_sta_set_rfeature);
16302 sigma_dut_reg_cmd("sta_set_radio", req_intf, cmd_sta_set_radio);
16303 sigma_dut_reg_cmd("sta_set_pwrsave", req_intf, cmd_sta_set_pwrsave);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020016304 sigma_dut_reg_cmd("sta_set_power_save", req_intf, cmd_sta_set_pwrsave);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016305 sigma_dut_reg_cmd("sta_bssid_pool", req_intf, cmd_sta_bssid_pool);
16306 sigma_dut_reg_cmd("sta_reset_parm", req_intf, cmd_sta_reset_parm);
16307 sigma_dut_reg_cmd("sta_get_key", req_intf, cmd_sta_get_key);
16308 sigma_dut_reg_cmd("sta_hs2_associate", req_intf,
16309 cmd_sta_hs2_associate);
Jouni Malinenb639f1c2018-09-13 02:39:46 +030016310 sigma_dut_reg_cmd("sta_hs2_venue_info", req_intf,
16311 cmd_sta_hs2_venue_info);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016312 sigma_dut_reg_cmd("sta_add_credential", req_intf,
16313 cmd_sta_add_credential);
16314 sigma_dut_reg_cmd("sta_scan", req_intf, cmd_sta_scan);
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020016315 sigma_dut_reg_cmd("sta_scan_bss", req_intf, cmd_sta_scan_bss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016316 sigma_dut_reg_cmd("sta_set_systime", NULL, cmd_sta_set_systime);
16317 sigma_dut_reg_cmd("sta_osu", req_intf, cmd_sta_osu);
16318 sigma_dut_reg_cmd("sta_policy_update", req_intf, cmd_sta_policy_update);
16319 sigma_dut_reg_cmd("sta_er_config", NULL, cmd_sta_er_config);
16320 sigma_dut_reg_cmd("sta_wps_connect_pw_token", req_intf,
16321 cmd_sta_wps_connect_pw_token);
Jouni Malinen82905202018-04-29 17:20:10 +030016322 sigma_dut_reg_cmd("sta_exec_action", NULL, cmd_sta_exec_action);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016323 sigma_dut_reg_cmd("sta_get_events", req_intf, cmd_sta_get_events);
16324 sigma_dut_reg_cmd("sta_get_parameter", req_intf, cmd_sta_get_parameter);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020016325 sigma_dut_reg_cmd("start_wps_registration", NULL,
vamsi krishna9b144002017-09-20 13:28:13 +053016326 cmd_start_wps_registration);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016327}