blob: 35f0b81653c7737aad49f1e63b47a3fbafd654dd [file] [log] [blame]
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001/*
2 * Sigma Control API DUT (station/AP)
3 * Copyright (c) 2010-2011, Atheros Communications, Inc.
Jouni Malinen9d7e31d2017-12-22 18:55:04 +02004 * Copyright (c) 2011-2017, Qualcomm Atheros, Inc.
Jouni Malinenc12ea4a2018-01-05 21:07:10 +02005 * Copyright (c) 2018, The Linux Foundation
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006 * All Rights Reserved.
7 * Licensed under the Clear BSD license. See README for more details.
8 */
9
10#include "sigma_dut.h"
11#include <sys/ioctl.h>
12#include <sys/stat.h>
Jouni Malinen82905202018-04-29 17:20:10 +030013#include <sys/wait.h>
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030014#include <ctype.h>
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015#ifdef __linux__
Lior Davidcc88b562017-01-03 18:52:09 +020016#include <regex.h>
17#include <dirent.h>
Jouni Malinencd4e3c32015-10-29 12:39:56 +020018#include <sys/time.h>
19#include <netpacket/packet.h>
20#include <linux/if_ether.h>
21#ifdef ANDROID
22#include <cutils/properties.h>
23#include <android/log.h>
24#include "keystore_get.h"
25#else /* ANDROID */
26#include <ifaddrs.h>
27#endif /* ANDROID */
28#include <netdb.h>
29#endif /* __linux__ */
30#ifdef __QNXNTO__
31#include <net/if_dl.h>
32#endif /* __QNXNTO__ */
33#include "wpa_ctrl.h"
34#include "wpa_helpers.h"
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -070035#include "miracast.h"
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -070036#include "qca-vendor_copy.h"
Jouni Malinencd4e3c32015-10-29 12:39:56 +020037
38/* Temporary files for sta_send_addba */
39#define VI_QOS_TMP_FILE "/tmp/vi-qos.tmp"
40#define VI_QOS_FILE "/tmp/vi-qos.txt"
41#define VI_QOS_REFFILE "/etc/vi-qos.txt"
42
43/*
44 * MTU for Ethernet need to take into account 8-byte SNAP header
45 * to be added when encapsulating Ethernet frame into 802.11
46 */
47#ifndef IEEE80211_MAX_DATA_LEN_DMG
48#define IEEE80211_MAX_DATA_LEN_DMG 7920
49#endif
50#ifndef IEEE80211_SNAP_LEN_DMG
51#define IEEE80211_SNAP_LEN_DMG 8
52#endif
53
Ashwini Patil00402582017-04-13 12:29:39 +053054#define NON_PREF_CH_LIST_SIZE 100
Ashwini Patil5acd7382017-04-13 15:55:04 +053055#define NEIGHBOR_REPORT_SIZE 1000
56#define DEFAULT_NEIGHBOR_BSSID_INFO "17"
57#define DEFAULT_NEIGHBOR_PHY_TYPE "1"
Ashwini Patil00402582017-04-13 12:29:39 +053058
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030059#define WIL_DEFAULT_BI 100
60
61/* default remain on channel time for transmitting frames (milliseconds) */
62#define WIL_TRANSMIT_FRAME_DEFAULT_ROC 500
63#define IEEE80211_P2P_ATTR_DEVICE_ID 3
64#define IEEE80211_P2P_ATTR_GROUP_ID 15
65
66/* describes tagged bytes in template frame file */
67struct template_frame_tag {
68 int num;
69 int offset;
70 size_t len;
71};
72
Jouni Malinencd4e3c32015-10-29 12:39:56 +020073extern char *sigma_wpas_ctrl;
74extern char *sigma_cert_path;
75extern enum driver_type wifi_chip_type;
76extern char *sigma_radio_ifname[];
77
Lior David0fe101e2017-03-09 16:09:50 +020078#ifdef __linux__
79#define WIL_WMI_MAX_PAYLOAD 248
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020080#define WIL_WMI_ESE_CFG_CMDID 0xa01
Lior David0fe101e2017-03-09 16:09:50 +020081#define WIL_WMI_BF_TRIG_CMDID 0x83a
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020082#define WIL_WMI_UNIT_TEST_CMDID 0x900
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030083#define WIL_WMI_P2P_CFG_CMDID 0x910
84#define WIL_WMI_START_LISTEN_CMDID 0x914
85#define WIL_WMI_DISCOVERY_STOP_CMDID 0x917
Lior David0fe101e2017-03-09 16:09:50 +020086
87struct wil_wmi_header {
88 uint8_t mid;
89 uint8_t reserved;
90 uint16_t cmd;
91 uint32_t ts;
92} __attribute__((packed));
93
94enum wil_wmi_bf_trig_type {
95 WIL_WMI_SLS,
96 WIL_WMI_BRP_RX,
97 WIL_WMI_BRP_TX,
98};
99
100struct wil_wmi_bf_trig_cmd {
101 /* enum wil_wmi_bf_trig_type */
102 uint32_t bf_type;
103 /* cid when type == WMI_BRP_RX */
104 uint32_t sta_id;
105 uint32_t reserved;
106 /* mac address when type = WIL_WMI_SLS */
107 uint8_t dest_mac[6];
108} __attribute__((packed));
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +0200109
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +0200110enum wil_wmi_sched_scheme_advertisment {
111 WIL_WMI_ADVERTISE_ESE_DISABLED,
112 WIL_WMI_ADVERTISE_ESE_IN_BEACON,
113 WIL_WMI_ADVERTISE_ESE_IN_ANNOUNCE_FRAME,
114};
115
116enum wil_wmi_ese_slot_type {
117 WIL_WMI_ESE_SP,
118 WIL_WMI_ESE_CBAP,
119 WIL_WMI_ESE_ANNOUNCE_NO_ACK,
120};
121
122struct wil_wmi_ese_slot {
123 /* offset from start of BI in microseconds */
124 uint32_t tbtt_offset;
125 uint8_t flags;
126 /* enum wil_wmi_ese_slot_type */
127 uint8_t slot_type;
128 /* duration in microseconds */
129 uint16_t duration;
130 /* frame exchange sequence duration, microseconds */
131 uint16_t tx_op;
132 /* time between 2 blocks for periodic allocation(microseconds) */
133 uint16_t period;
134 /* number of blocks in periodic allocation */
135 uint8_t num_blocks;
136 /* for semi-active allocations */
137 uint8_t idle_period;
138 uint8_t src_aid;
139 uint8_t dst_aid;
140 uint32_t reserved;
141} __attribute__((packed));
142
143#define WIL_WMI_MAX_ESE_SLOTS 4
144struct wil_wmi_ese_cfg {
145 uint8_t serial_num;
146 /* wil_wmi_sched_scheme_advertisment */
147 uint8_t ese_advertisment;
148 uint16_t flags;
149 uint8_t num_allocs;
150 uint8_t reserved[3];
151 uint64_t start_tbtt;
152 /* allocations list */
153 struct wil_wmi_ese_slot slots[WIL_WMI_MAX_ESE_SLOTS];
154} __attribute__((packed));
155
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +0200156#define WIL_WMI_UT_FORCE_MCS 6
157struct wil_wmi_force_mcs {
158 /* WIL_WMI_UT_HW_SYSAPI */
159 uint16_t module_id;
160 /* WIL_WMI_UT_FORCE_MCS */
161 uint16_t subtype_id;
162 /* cid (ignored in oob_mode, affects all stations) */
163 uint32_t cid;
164 /* 1 to force MCS, 0 to restore default behavior */
165 uint32_t force_enable;
166 /* MCS index, 0-12 */
167 uint32_t mcs;
168} __attribute__((packed));
169
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +0200170#define WIL_WMI_UT_HW_SYSAPI 10
171#define WIL_WMI_UT_FORCE_RSN_IE 0x29
172struct wil_wmi_force_rsn_ie {
173 /* WIL_WMI_UT_HW_SYSAPI */
174 uint16_t module_id;
175 /* WIL_WMI_UT_FORCE_RSN_IE */
176 uint16_t subtype_id;
177 /* 0 = no change, 1 = remove if exists, 2 = add if does not exist */
178 uint32_t state;
179} __attribute__((packed));
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +0300180
181enum wil_wmi_discovery_mode {
182 WMI_DISCOVERY_MODE_NON_OFFLOAD,
183 WMI_DISCOVERY_MODE_OFFLOAD,
184 WMI_DISCOVERY_MODE_PEER2PEER,
185};
186
187struct wil_wmi_p2p_cfg_cmd {
188 /* enum wil_wmi_discovery_mode */
189 uint8_t discovery_mode;
190 /* 0-based (wireless channel - 1) */
191 uint8_t channel;
192 /* set to WIL_DEFAULT_BI */
193 uint16_t bcon_interval;
194} __attribute__((packed));
Lior David0fe101e2017-03-09 16:09:50 +0200195#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200196
197#ifdef ANDROID
198
199static int add_ipv6_rule(struct sigma_dut *dut, const char *ifname);
200
201#define ANDROID_KEYSTORE_GET 'g'
202#define ANDROID_KEYSTORE_GET_PUBKEY 'b'
203
204static int android_keystore_get(char cmd, const char *key, unsigned char *val)
205{
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200206 /* Android 4.3 changed keystore design, so need to use keystore_get() */
207#ifndef KEYSTORE_MESSAGE_SIZE
208#define KEYSTORE_MESSAGE_SIZE 65535
209#endif /* KEYSTORE_MESSAGE_SIZE */
210
211 ssize_t len;
212 uint8_t *value = NULL;
213
214 __android_log_print(ANDROID_LOG_DEBUG, "sigma_dut",
215 "keystore command '%c' key '%s' --> keystore_get",
216 cmd, key);
217
218 len = keystore_get(key, strlen(key), &value);
219 if (len < 0) {
220 __android_log_print(ANDROID_LOG_DEBUG, "sigma_dut",
221 "keystore_get() failed");
222 return -1;
223 }
224
225 if (len > KEYSTORE_MESSAGE_SIZE)
226 len = KEYSTORE_MESSAGE_SIZE;
227 memcpy(val, value, len);
228 free(value);
229 return len;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200230}
231#endif /* ANDROID */
232
233
Vinita S. Maloo0fcb57d2020-04-24 14:03:56 +0530234#ifdef NL80211_SUPPORT
235static int nl80211_sta_set_power_save(struct sigma_dut *dut,
236 const char *intf,
237 enum nl80211_ps_state ps_state)
238{
239 struct nl_msg *msg;
240 int ifindex, ret;
241
242 ifindex = if_nametoindex(intf);
243 if (ifindex == 0) {
244 sigma_dut_print(dut, DUT_MSG_ERROR,
245 "%s: Index for interface %s not found",
246 __func__, intf);
247 return -1;
248 }
249
250 msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
251 NL80211_CMD_SET_POWER_SAVE);
252 if (!msg) {
253 sigma_dut_print(dut, DUT_MSG_ERROR,
254 "%s: err in creating nl80211 msg", __func__);
255 return -1;
256 }
257
258 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) {
259 sigma_dut_print(dut, DUT_MSG_ERROR,
260 "%s: err in populating nl80211 msg", __func__);
261 nlmsg_free(msg);
262 return -1;
263 }
264
265 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
266 if (ret) {
267 sigma_dut_print(dut, DUT_MSG_ERROR,
268 "%s: err in send_and_recv_msgs, ret=%d (%s)",
269 __func__, ret, strerror(-ret));
270 return -1;
271 }
272
273 return 0;
274}
275#endif /* NL80211_SUPPORT */
276
277
Vinita S. Malooa8b62722020-04-23 01:45:41 +0530278static int set_power_save_wcn(struct sigma_dut *dut, const char *intf, int ps)
279{
280 char buf[100];
Vinita S. Maloo0fcb57d2020-04-24 14:03:56 +0530281#ifdef NL80211_SUPPORT
282 enum nl80211_ps_state ps_state;
283
284 ps_state = ps == 1 ? NL80211_PS_ENABLED : NL80211_PS_DISABLED;
285 if (nl80211_sta_set_power_save(dut, intf, ps_state) == 0)
286 return 0;
287#endif /* NL80211_SUPPORT */
Vinita S. Malooa8b62722020-04-23 01:45:41 +0530288
289 snprintf(buf, sizeof(buf), "iwpriv %s setPower %d", intf, ps);
290 if (system(buf) != 0) {
291 sigma_dut_print(dut, DUT_MSG_ERROR,
292 "iwpriv setPower %d failed", ps);
293 return -1;
294 }
295 return 0;
296}
297
298
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200299int set_ps(const char *intf, struct sigma_dut *dut, int enabled)
300{
301#ifdef __linux__
302 char buf[100];
303
304 if (wifi_chip_type == DRIVER_WCN) {
305 if (enabled) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +0530306 if (set_power_save_wcn(dut, intf, 1) < 0) {
Purushottam Kushwaha304561d2019-12-23 16:57:18 +0530307 snprintf(buf, sizeof(buf),
308 "iwpriv wlan0 dump 906");
309 if (system(buf) != 0)
310 goto set_power_save;
311 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200312 } else {
Vinita S. Malooa8b62722020-04-23 01:45:41 +0530313 if (set_power_save_wcn(dut, intf, 2) < 0) {
Purushottam Kushwaha304561d2019-12-23 16:57:18 +0530314 snprintf(buf, sizeof(buf),
315 "iwpriv wlan0 dump 905");
316 if (system(buf) != 0)
317 goto set_power_save;
318 snprintf(buf, sizeof(buf),
319 "iwpriv wlan0 dump 912");
320 if (system(buf) != 0)
321 goto set_power_save;
322 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200323 }
324
325 return 0;
326 }
327
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530328set_power_save:
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200329 snprintf(buf, sizeof(buf), "./iw dev %s set power_save %s",
330 intf, enabled ? "on" : "off");
331 if (system(buf) != 0) {
332 snprintf(buf, sizeof(buf), "iw dev %s set power_save %s",
333 intf, enabled ? "on" : "off");
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530334 if (system(buf) != 0) {
335 sigma_dut_print(dut, DUT_MSG_ERROR,
336 "Failed to set power save %s",
337 enabled ? "on" : "off");
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200338 return -1;
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530339 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200340 }
341
342 return 0;
343#else /* __linux__ */
344 return -1;
345#endif /* __linux__ */
346}
347
348
Lior Davidcc88b562017-01-03 18:52:09 +0200349#ifdef __linux__
Lior David0fe101e2017-03-09 16:09:50 +0200350
Lior Davidcc88b562017-01-03 18:52:09 +0200351static int wil6210_get_debugfs_dir(struct sigma_dut *dut, char *path,
352 size_t len)
353{
354 DIR *dir, *wil_dir;
355 struct dirent *entry;
356 int ret = -1;
357 const char *root_path = "/sys/kernel/debug/ieee80211";
358
359 dir = opendir(root_path);
360 if (!dir)
361 return -2;
362
363 while ((entry = readdir(dir))) {
364 if (strcmp(entry->d_name, ".") == 0 ||
365 strcmp(entry->d_name, "..") == 0)
366 continue;
367
368 if (snprintf(path, len, "%s/%s/wil6210",
369 root_path, entry->d_name) >= (int) len) {
370 ret = -3;
371 break;
372 }
373
374 wil_dir = opendir(path);
375 if (wil_dir) {
376 closedir(wil_dir);
377 ret = 0;
378 break;
379 }
380 }
381
382 closedir(dir);
383 return ret;
384}
Lior David0fe101e2017-03-09 16:09:50 +0200385
386
387static int wil6210_wmi_send(struct sigma_dut *dut, uint16_t command,
388 void *payload, uint16_t length)
389{
390 struct {
391 struct wil_wmi_header hdr;
392 char payload[WIL_WMI_MAX_PAYLOAD];
393 } __attribute__((packed)) cmd;
394 char buf[128], fname[128];
395 size_t towrite, written;
396 FILE *f;
Jouni Malinen3aa72862019-05-29 23:14:51 +0300397 int res;
Lior David0fe101e2017-03-09 16:09:50 +0200398
399 if (length > WIL_WMI_MAX_PAYLOAD) {
400 sigma_dut_print(dut, DUT_MSG_ERROR,
401 "payload too large(%u, max %u)",
402 length, WIL_WMI_MAX_PAYLOAD);
403 return -1;
404 }
405
406 memset(&cmd.hdr, 0, sizeof(cmd.hdr));
407 cmd.hdr.cmd = command;
408 memcpy(cmd.payload, payload, length);
409
410 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
411 sigma_dut_print(dut, DUT_MSG_ERROR,
412 "failed to get wil6210 debugfs dir");
413 return -1;
414 }
415
Jouni Malinen3aa72862019-05-29 23:14:51 +0300416 res = snprintf(fname, sizeof(fname), "%s/wmi_send", buf);
417 if (res < 0 || res >= sizeof(fname))
418 return -1;
Lior David0fe101e2017-03-09 16:09:50 +0200419 f = fopen(fname, "wb");
420 if (!f) {
421 sigma_dut_print(dut, DUT_MSG_ERROR,
422 "failed to open: %s", fname);
423 return -1;
424 }
425
426 towrite = sizeof(cmd.hdr) + length;
427 written = fwrite(&cmd, 1, towrite, f);
428 fclose(f);
429 if (written != towrite) {
430 sigma_dut_print(dut, DUT_MSG_ERROR,
431 "failed to send wmi %u", command);
432 return -1;
433 }
434
435 return 0;
436}
437
438
439static int wil6210_get_sta_info_field(struct sigma_dut *dut, const char *bssid,
440 const char *pattern, unsigned int *field)
441{
442 char buf[128], fname[128];
443 FILE *f;
444 regex_t re;
445 regmatch_t m[2];
Jouni Malinen3aa72862019-05-29 23:14:51 +0300446 int rc, ret = -1, res;
Lior David0fe101e2017-03-09 16:09:50 +0200447
448 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
449 sigma_dut_print(dut, DUT_MSG_ERROR,
450 "failed to get wil6210 debugfs dir");
451 return -1;
452 }
453
Jouni Malinen3aa72862019-05-29 23:14:51 +0300454 res = snprintf(fname, sizeof(fname), "%s/stations", buf);
455 if (res < 0 || res >= sizeof(fname))
456 return -1;
Lior David0fe101e2017-03-09 16:09:50 +0200457 f = fopen(fname, "r");
458 if (!f) {
459 sigma_dut_print(dut, DUT_MSG_ERROR,
460 "failed to open: %s", fname);
461 return -1;
462 }
463
464 if (regcomp(&re, pattern, REG_EXTENDED)) {
465 sigma_dut_print(dut, DUT_MSG_ERROR,
466 "regcomp failed: %s", pattern);
467 goto out;
468 }
469
470 /*
471 * find the entry for the mac address
472 * line is of the form: [n] 11:22:33:44:55:66 state AID aid
473 */
474 while (fgets(buf, sizeof(buf), f)) {
475 if (strcasestr(buf, bssid)) {
476 /* extract the field (CID/AID/state) */
477 rc = regexec(&re, buf, 2, m, 0);
478 if (!rc && (m[1].rm_so >= 0)) {
479 buf[m[1].rm_eo] = 0;
480 *field = atoi(&buf[m[1].rm_so]);
481 ret = 0;
482 break;
483 }
484 }
485 }
486
487 regfree(&re);
488 if (ret)
489 sigma_dut_print(dut, DUT_MSG_ERROR,
490 "could not extract field");
491
492out:
493 fclose(f);
494
495 return ret;
496}
497
498
499static int wil6210_get_cid(struct sigma_dut *dut, const char *bssid,
500 unsigned int *cid)
501{
502 const char *pattern = "\\[([0-9]+)\\]";
503
504 return wil6210_get_sta_info_field(dut, bssid, pattern, cid);
505}
506
507
508static int wil6210_send_brp_rx(struct sigma_dut *dut, const char *mac,
509 int l_rx)
510{
Rakesh Sunki556237d2017-03-30 14:49:31 -0700511 struct wil_wmi_bf_trig_cmd cmd;
Lior David0fe101e2017-03-09 16:09:50 +0200512 unsigned int cid;
513
Rakesh Sunki556237d2017-03-30 14:49:31 -0700514 memset(&cmd, 0, sizeof(cmd));
515
Lior David0fe101e2017-03-09 16:09:50 +0200516 if (wil6210_get_cid(dut, mac, &cid))
517 return -1;
518
519 cmd.bf_type = WIL_WMI_BRP_RX;
520 cmd.sta_id = cid;
521 /* training length (l_rx) is ignored, FW always uses length 16 */
522 return wil6210_wmi_send(dut, WIL_WMI_BF_TRIG_CMDID,
523 &cmd, sizeof(cmd));
524}
525
526
527static int wil6210_send_sls(struct sigma_dut *dut, const char *mac)
528{
Rakesh Sunki556237d2017-03-30 14:49:31 -0700529 struct wil_wmi_bf_trig_cmd cmd;
530
531 memset(&cmd, 0, sizeof(cmd));
Lior David0fe101e2017-03-09 16:09:50 +0200532
533 if (parse_mac_address(dut, mac, (unsigned char *)&cmd.dest_mac))
534 return -1;
535
536 cmd.bf_type = WIL_WMI_SLS;
537 return wil6210_wmi_send(dut, WIL_WMI_BF_TRIG_CMDID,
538 &cmd, sizeof(cmd));
539}
540
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +0200541
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +0200542int wil6210_set_ese(struct sigma_dut *dut, int count,
543 struct sigma_ese_alloc *allocs)
544{
545 struct wil_wmi_ese_cfg cmd = { };
546 int i;
547
548 if (count == 0 || count > WIL_WMI_MAX_ESE_SLOTS)
549 return -1;
550
551 if (dut->ap_bcnint <= 0) {
552 sigma_dut_print(dut, DUT_MSG_ERROR,
553 "invalid beacon interval(%d), check test",
554 dut->ap_bcnint);
555 return -1;
556 }
557
558 cmd.ese_advertisment = WIL_WMI_ADVERTISE_ESE_IN_BEACON;
559 cmd.flags = 0x1d;
560 cmd.num_allocs = count;
561 for (i = 0; i < count; i++) {
562 /*
563 * Convert percent from BI (BI specified in milliseconds)
564 * to absolute duration in microseconds.
565 */
566 cmd.slots[i].duration =
567 (allocs[i].percent_bi * dut->ap_bcnint * 1000) / 100;
568 switch (allocs[i].type) {
569 case ESE_CBAP:
570 cmd.slots[i].slot_type = WIL_WMI_ESE_CBAP;
571 break;
572 case ESE_SP:
573 cmd.slots[i].slot_type = WIL_WMI_ESE_SP;
574 break;
575 default:
576 sigma_dut_print(dut, DUT_MSG_ERROR,
577 "invalid slot type(%d) at index %d",
578 allocs[i].type, i);
579 return -1;
580 }
581 cmd.slots[i].src_aid = allocs[i].src_aid;
582 cmd.slots[i].dst_aid = allocs[i].dst_aid;
583 sigma_dut_print(dut, DUT_MSG_INFO,
584 "slot %d, duration %u, type %d, srcAID %u dstAID %u",
585 i, cmd.slots[i].duration,
586 cmd.slots[i].slot_type, cmd.slots[i].src_aid,
587 cmd.slots[i].dst_aid);
588 }
589
590 return wil6210_wmi_send(dut, WIL_WMI_ESE_CFG_CMDID, &cmd, sizeof(cmd));
591}
592
593
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +0200594int wil6210_set_force_mcs(struct sigma_dut *dut, int force, int mcs)
595{
596 struct wil_wmi_force_mcs cmd = { };
597
598 cmd.module_id = WIL_WMI_UT_HW_SYSAPI;
599 cmd.subtype_id = WIL_WMI_UT_FORCE_MCS;
600 cmd.force_enable = (uint32_t) force;
601 cmd.mcs = (uint32_t) mcs;
602
603 return wil6210_wmi_send(dut, WIL_WMI_UNIT_TEST_CMDID,
604 &cmd, sizeof(cmd));
605}
606
607
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +0200608static int wil6210_force_rsn_ie(struct sigma_dut *dut, int state)
609{
610 struct wil_wmi_force_rsn_ie cmd = { };
611
612 cmd.module_id = WIL_WMI_UT_HW_SYSAPI;
613 cmd.subtype_id = WIL_WMI_UT_FORCE_RSN_IE;
614 cmd.state = (uint32_t) state;
615
616 return wil6210_wmi_send(dut, WIL_WMI_UNIT_TEST_CMDID,
617 &cmd, sizeof(cmd));
618}
619
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +0300620
621/*
622 * this function is also used to configure generic remain-on-channel
623 */
624static int wil6210_p2p_cfg(struct sigma_dut *dut, int freq)
625{
626 struct wil_wmi_p2p_cfg_cmd cmd = { };
627 int channel = freq_to_channel(freq);
628
629 if (channel < 0)
630 return -1;
631 cmd.discovery_mode = WMI_DISCOVERY_MODE_NON_OFFLOAD;
632 cmd.channel = channel - 1;
633 cmd.bcon_interval = WIL_DEFAULT_BI;
634 cmd.discovery_mode = WMI_DISCOVERY_MODE_PEER2PEER;
635
636 return wil6210_wmi_send(dut, WIL_WMI_P2P_CFG_CMDID,
637 &cmd, sizeof(cmd));
638}
639
640
641static int wil6210_remain_on_channel(struct sigma_dut *dut, int freq)
642{
643 int ret = wil6210_p2p_cfg(dut, freq);
644
645 if (ret)
646 return ret;
647
648 ret = wil6210_wmi_send(dut, WIL_WMI_START_LISTEN_CMDID, NULL, 0);
649 if (!ret) {
650 /*
651 * wait a bit to allow FW to setup the radio
652 * especially important if we switch channels
653 */
654 usleep(500000);
655 }
656
657 return ret;
658}
659
660
661static int wil6210_stop_discovery(struct sigma_dut *dut)
662{
663 return wil6210_wmi_send(dut, WIL_WMI_DISCOVERY_STOP_CMDID, NULL, 0);
664}
665
666
667static int wil6210_transmit_frame(struct sigma_dut *dut, int freq,
668 int wait_duration,
669 const char *frame, size_t frame_len)
670{
671 char buf[128], fname[128];
672 FILE *f;
Jouni Malinen3aa72862019-05-29 23:14:51 +0300673 int res = 0, r;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +0300674 size_t written;
675
676 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
677 sigma_dut_print(dut, DUT_MSG_ERROR,
678 "failed to get wil6210 debugfs dir");
679 return -1;
680 }
Jouni Malinen3aa72862019-05-29 23:14:51 +0300681 r = snprintf(fname, sizeof(fname), "%s/tx_mgmt", buf);
682 if (r < 0 || r >= sizeof(fname))
683 return -1;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +0300684
685 if (wil6210_remain_on_channel(dut, freq)) {
686 sigma_dut_print(dut, DUT_MSG_ERROR,
687 "failed to listen on channel");
688 return -1;
689 }
690
691 f = fopen(fname, "wb");
692 if (!f) {
693 sigma_dut_print(dut, DUT_MSG_ERROR,
694 "failed to open: %s", fname);
695 res = -1;
696 goto out_stop;
697 }
698 written = fwrite(frame, 1, frame_len, f);
699 fclose(f);
700
701 if (written != frame_len) {
702 sigma_dut_print(dut, DUT_MSG_ERROR,
703 "failed to transmit frame (got %zd, expected %zd)",
704 written, frame_len);
705 res = -1;
706 goto out_stop;
707 }
708
709 usleep(wait_duration * 1000);
710
711out_stop:
712 wil6210_stop_discovery(dut);
713 return res;
714}
715
716
717static int find_template_frame_tag(struct template_frame_tag *tags,
718 int total_tags, int tag_num)
719{
720 int i;
721
722 for (i = 0; i < total_tags; i++) {
723 if (tag_num == tags[i].num)
724 return i;
725 }
726
727 return -1;
728}
729
730
731static int replace_p2p_attribute(struct sigma_dut *dut, char *buf, size_t len,
732 int id, const char *value, size_t val_len)
733{
734 struct wfa_p2p_attribute *attr = (struct wfa_p2p_attribute *) buf;
735
736 if (len < 3 + val_len) {
737 sigma_dut_print(dut, DUT_MSG_ERROR,
738 "not enough space to replace P2P attribute");
739 return -1;
740 }
741
742 if (attr->len != val_len) {
743 sigma_dut_print(dut, DUT_MSG_ERROR,
744 "attribute length mismatch (need %zu have %hu)",
745 val_len, attr->len);
746 return -1;
747 }
748
749 if (attr->id != id) {
750 sigma_dut_print(dut, DUT_MSG_ERROR,
751 "incorrect attribute id (expected %d actual %d)",
752 id, attr->id);
753 return -1;
754 }
755
756 memcpy(attr->variable, value, val_len);
757
758 return 0;
759}
760
761
762static int parse_template_frame_file(struct sigma_dut *dut, const char *fname,
763 char *buf, size_t *length,
764 struct template_frame_tag *tags,
765 size_t *num_tags)
766{
767 char line[512];
768 FILE *f;
769 size_t offset = 0, tag_index = 0;
770 int num, index;
771 int in_tag = 0, tag_num = 0, tag_offset = 0;
772
773 if (*length < sizeof(struct ieee80211_hdr_3addr)) {
774 sigma_dut_print(dut, DUT_MSG_ERROR,
775 "supplied buffer is too small");
776 return -1;
777 }
778
779 f = fopen(fname, "r");
780 if (!f) {
781 sigma_dut_print(dut, DUT_MSG_ERROR,
782 "failed to open template file %s", fname);
783 return -1;
784 }
785
786 /*
787 * template file format: lines beginning with # are comments and
788 * ignored.
789 * It is possible to tag bytes in the frame to make it easy
790 * to replace fields in the template, espcially if they appear
791 * in variable-sized sections (such as IEs)
792 * This is done by a line beginning with $NUM where NUM is an integer
793 * tag number. It can be followed by space(s) and comment.
794 * The next line is considered the tagged bytes. The parser will fill
795 * the tag number, offset and length of the tagged bytes.
796 * rest of the lines contain frame bytes as sequence of hex digits,
797 * 2 digits for each byte. Spaces are allowed between bytes.
798 * On bytes lines only hex digits and spaces are allowed
799 */
800 while (!feof(f)) {
801 if (!fgets(line, sizeof(line), f))
802 break;
803 index = 0;
804 while (isspace((unsigned char) line[index]))
805 index++;
806 if (!line[index] || line[index] == '#')
807 continue;
808 if (line[index] == '$') {
809 if (tags) {
810 index++;
811 tag_num = strtol(&line[index], NULL, 0);
812 tag_offset = offset;
813 in_tag = 1;
814 }
815 continue;
816 }
817 while (line[index]) {
818 if (isspace((unsigned char) line[index])) {
819 index++;
820 continue;
821 }
822 num = hex_byte(&line[index]);
823 if (num < 0)
824 break;
825 buf[offset++] = num;
826 if (offset == *length)
827 goto out;
828 index += 2;
829 }
830
831 if (in_tag) {
832 if (tag_index < *num_tags) {
833 tags[tag_index].num = tag_num;
834 tags[tag_index].offset = tag_offset;
835 tags[tag_index].len = offset - tag_offset;
836 tag_index++;
837 } else {
838 sigma_dut_print(dut, DUT_MSG_INFO,
839 "too many tags, tag ignored");
840 }
841 in_tag = 0;
842 }
843 }
844
845 if (num_tags)
846 *num_tags = tag_index;
847out:
848 fclose(f);
849 if (offset < sizeof(struct ieee80211_hdr_3addr)) {
850 sigma_dut_print(dut, DUT_MSG_ERROR,
851 "template frame is too small");
852 return -1;
853 }
854
855 *length = offset;
856 return 0;
857}
858
Lior Davidcc88b562017-01-03 18:52:09 +0200859#endif /* __linux__ */
860
861
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200862static void static_ip_file(int proto, const char *addr, const char *mask,
863 const char *gw)
864{
865 if (proto) {
866 FILE *f = fopen("static-ip", "w");
867 if (f) {
868 fprintf(f, "%d %s %s %s\n", proto, addr,
869 mask ? mask : "N/A",
870 gw ? gw : "N/A");
871 fclose(f);
872 }
873 } else {
874 unlink("static-ip");
875 }
876}
877
878
879static int send_neighbor_request(struct sigma_dut *dut, const char *intf,
880 const char *ssid)
881{
882#ifdef __linux__
883 char buf[100];
884
885 snprintf(buf, sizeof(buf), "iwpriv %s neighbor %s",
886 intf, ssid);
887 sigma_dut_print(dut, DUT_MSG_INFO, "Request: %s", buf);
888
889 if (system(buf) != 0) {
890 sigma_dut_print(dut, DUT_MSG_ERROR,
891 "iwpriv neighbor request failed");
892 return -1;
893 }
894
895 sigma_dut_print(dut, DUT_MSG_INFO, "iwpriv neighbor request send");
896
897 return 0;
898#else /* __linux__ */
899 return -1;
900#endif /* __linux__ */
901}
902
903
904static int send_trans_mgmt_query(struct sigma_dut *dut, const char *intf,
Ashwini Patil5acd7382017-04-13 15:55:04 +0530905 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200906{
Ashwini Patil5acd7382017-04-13 15:55:04 +0530907 const char *val;
908 int reason_code = 0;
909 char buf[1024];
910
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200911 /*
912 * In the earlier builds we used WNM_QUERY and in later
913 * builds used WNM_BSS_QUERY.
914 */
915
Ashwini Patil5acd7382017-04-13 15:55:04 +0530916 val = get_param(cmd, "BTMQuery_Reason_Code");
917 if (val)
918 reason_code = atoi(val);
919
920 val = get_param(cmd, "Cand_List");
921 if (val && atoi(val) == 1 && dut->btm_query_cand_list) {
922 snprintf(buf, sizeof(buf), "WNM_BSS_QUERY %d%s", reason_code,
923 dut->btm_query_cand_list);
924 free(dut->btm_query_cand_list);
925 dut->btm_query_cand_list = NULL;
926 } else {
927 snprintf(buf, sizeof(buf), "WNM_BSS_QUERY %d", reason_code);
928 }
929
930 if (wpa_command(intf, buf) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200931 sigma_dut_print(dut, DUT_MSG_ERROR,
932 "transition management query failed");
933 return -1;
934 }
935
936 sigma_dut_print(dut, DUT_MSG_DEBUG,
937 "transition management query sent");
938
939 return 0;
940}
941
942
943int is_ip_addr(const char *str)
944{
945 const char *pos = str;
946 struct in_addr addr;
947
948 while (*pos) {
949 if (*pos != '.' && (*pos < '0' || *pos > '9'))
950 return 0;
951 pos++;
952 }
953
954 return inet_aton(str, &addr);
955}
956
957
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200958int get_ip_config(struct sigma_dut *dut, const char *ifname, char *buf,
959 size_t buf_len)
960{
vamsi krishnaa11d0732018-05-16 12:19:48 +0530961 char tmp[256];
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200962 char ip[16], mask[15], dns[16], sec_dns[16];
963 int is_dhcp = 0;
964 int s;
965#ifdef ANDROID
966 char prop[PROPERTY_VALUE_MAX];
vamsi krishnaa11d0732018-05-16 12:19:48 +0530967#else /* ANDROID */
968 FILE *f;
969#ifdef __linux__
970 const char *str_ps;
971#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200972#endif /* ANDROID */
973
974 ip[0] = '\0';
975 mask[0] = '\0';
976 dns[0] = '\0';
977 sec_dns[0] = '\0';
978
979 s = socket(PF_INET, SOCK_DGRAM, 0);
980 if (s >= 0) {
981 struct ifreq ifr;
982 struct sockaddr_in saddr;
983
984 memset(&ifr, 0, sizeof(ifr));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700985 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200986 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
987 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get "
988 "%s IP address: %s",
989 ifname, strerror(errno));
990 } else {
991 memcpy(&saddr, &ifr.ifr_addr,
992 sizeof(struct sockaddr_in));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700993 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200994 }
995
996 if (ioctl(s, SIOCGIFNETMASK, &ifr) == 0) {
997 memcpy(&saddr, &ifr.ifr_addr,
998 sizeof(struct sockaddr_in));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700999 strlcpy(mask, inet_ntoa(saddr.sin_addr), sizeof(mask));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001000 }
1001 close(s);
1002 }
1003
1004#ifdef ANDROID
1005 snprintf(tmp, sizeof(tmp), "dhcp.%s.pid", ifname);
1006 if (property_get(tmp, prop, NULL) != 0 && atoi(prop) > 0) {
1007 snprintf(tmp, sizeof(tmp), "dhcp.%s.result", ifname);
1008 if (property_get(tmp, prop, NULL) != 0 &&
1009 strcmp(prop, "ok") == 0) {
1010 snprintf(tmp, sizeof(tmp), "dhcp.%s.ipaddress",
1011 ifname);
1012 if (property_get(tmp, prop, NULL) != 0 &&
1013 strcmp(ip, prop) == 0)
1014 is_dhcp = 1;
1015 }
1016 }
1017
1018 snprintf(tmp, sizeof(tmp), "dhcp.%s.dns1", ifname);
Peng Xub8fc5cc2017-05-10 17:27:28 -07001019 if (property_get(tmp, prop, NULL) != 0)
1020 strlcpy(dns, prop, sizeof(dns));
1021 else if (property_get("net.dns1", prop, NULL) != 0)
1022 strlcpy(dns, prop, sizeof(dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001023
1024 snprintf(tmp, sizeof(tmp), "dhcp.%s.dns2", ifname);
Peng Xub8fc5cc2017-05-10 17:27:28 -07001025 if (property_get(tmp, prop, NULL) != 0)
1026 strlcpy(sec_dns, prop, sizeof(sec_dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001027#else /* ANDROID */
1028#ifdef __linux__
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001029 if (get_driver_type(dut) == DRIVER_OPENWRT)
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +05301030 str_ps = "ps -w";
1031 else
1032 str_ps = "ps ax";
1033 snprintf(tmp, sizeof(tmp),
1034 "%s | grep dhclient | grep -v grep | grep -q %s",
1035 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001036 if (system(tmp) == 0)
1037 is_dhcp = 1;
1038 else {
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +05301039 snprintf(tmp, sizeof(tmp),
1040 "%s | grep udhcpc | grep -v grep | grep -q %s",
1041 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001042 if (system(tmp) == 0)
1043 is_dhcp = 1;
1044 else {
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +05301045 snprintf(tmp, sizeof(tmp),
1046 "%s | grep dhcpcd | grep -v grep | grep -q %s",
1047 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001048 if (system(tmp) == 0)
1049 is_dhcp = 1;
1050 }
1051 }
1052#endif /* __linux__ */
1053
1054 f = fopen("/etc/resolv.conf", "r");
1055 if (f) {
vamsi krishnaa11d0732018-05-16 12:19:48 +05301056 char *pos, *pos2;
1057
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001058 while (fgets(tmp, sizeof(tmp), f)) {
1059 if (strncmp(tmp, "nameserver", 10) != 0)
1060 continue;
1061 pos = tmp + 10;
1062 while (*pos == ' ' || *pos == '\t')
1063 pos++;
1064 pos2 = pos;
1065 while (*pos2) {
1066 if (*pos2 == '\n' || *pos2 == '\r') {
1067 *pos2 = '\0';
1068 break;
1069 }
1070 pos2++;
1071 }
Peng Xub8fc5cc2017-05-10 17:27:28 -07001072 if (!dns[0])
1073 strlcpy(dns, pos, sizeof(dns));
1074 else if (!sec_dns[0])
1075 strlcpy(sec_dns, pos, sizeof(sec_dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001076 }
1077 fclose(f);
1078 }
1079#endif /* ANDROID */
1080
1081 snprintf(buf, buf_len, "dhcp,%d,ip,%s,mask,%s,primary-dns,%s",
1082 is_dhcp, ip, mask, dns);
1083 buf[buf_len - 1] = '\0';
1084
1085 return 0;
1086}
1087
1088
1089
1090
1091int get_ipv6_config(struct sigma_dut *dut, const char *ifname, char *buf,
1092 size_t buf_len)
1093{
1094#ifdef __linux__
1095#ifdef ANDROID
1096 char cmd[200], result[1000], *pos, *end;
1097 FILE *f;
1098 size_t len;
1099
1100 snprintf(cmd, sizeof(cmd), "ip addr show dev %s scope global", ifname);
1101 f = popen(cmd, "r");
1102 if (f == NULL)
1103 return -1;
1104 len = fread(result, 1, sizeof(result) - 1, f);
1105 pclose(f);
1106 if (len == 0)
1107 return -1;
1108 result[len] = '\0';
1109 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s result: %s\n", cmd, result);
1110
1111 pos = strstr(result, "inet6 ");
1112 if (pos == NULL)
1113 return -1;
1114 pos += 6;
1115 end = strchr(pos, ' ');
1116 if (end)
1117 *end = '\0';
1118 end = strchr(pos, '/');
1119 if (end)
1120 *end = '\0';
1121 snprintf(buf, buf_len, "ip,%s", pos);
1122 buf[buf_len - 1] = '\0';
1123 return 0;
1124#else /* ANDROID */
1125 struct ifaddrs *ifaddr, *ifa;
1126 int res, found = 0;
1127 char host[NI_MAXHOST];
1128
1129 if (getifaddrs(&ifaddr) < 0) {
1130 perror("getifaddrs");
1131 return -1;
1132 }
1133
1134 for (ifa = ifaddr; ifa; ifa = ifa->ifa_next) {
1135 if (strcasecmp(ifname, ifa->ifa_name) != 0)
1136 continue;
1137 if (ifa->ifa_addr == NULL ||
1138 ifa->ifa_addr->sa_family != AF_INET6)
1139 continue;
1140
1141 res = getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in6),
1142 host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
1143 if (res != 0) {
1144 sigma_dut_print(dut, DUT_MSG_DEBUG, "getnameinfo: %s",
1145 gai_strerror(res));
1146 continue;
1147 }
1148 if (strncmp(host, "fe80::", 6) == 0)
1149 continue; /* skip link-local */
1150
1151 sigma_dut_print(dut, DUT_MSG_DEBUG, "ifaddr: %s", host);
1152 found = 1;
1153 break;
1154 }
1155
1156 freeifaddrs(ifaddr);
1157
1158 if (found) {
1159 char *pos;
1160 pos = strchr(host, '%');
1161 if (pos)
1162 *pos = '\0';
1163 snprintf(buf, buf_len, "ip,%s", host);
1164 buf[buf_len - 1] = '\0';
1165 return 0;
1166 }
1167
1168#endif /* ANDROID */
1169#endif /* __linux__ */
1170 return -1;
1171}
1172
1173
Jouni Malinenf7222712019-06-13 01:50:21 +03001174static enum sigma_cmd_result cmd_sta_get_ip_config(struct sigma_dut *dut,
1175 struct sigma_conn *conn,
1176 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001177{
1178 const char *intf = get_param(cmd, "Interface");
1179 const char *ifname;
1180 char buf[200];
1181 const char *val;
1182 int type = 1;
1183
1184 if (intf == NULL)
1185 return -1;
1186
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001187 if (strcmp(intf, get_main_ifname(dut)) == 0)
1188 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001189 else
1190 ifname = intf;
1191
1192 /*
1193 * UCC may assume the IP address to be available immediately after
1194 * association without trying to run sta_get_ip_config multiple times.
1195 * Sigma CAPI does not specify this command as a block command that
1196 * would wait for the address to become available, but to pass tests
1197 * more reliably, it looks like such a wait may be needed here.
1198 */
1199 if (wait_ip_addr(dut, ifname, 15) < 0) {
1200 sigma_dut_print(dut, DUT_MSG_INFO, "Could not get IP address "
1201 "for sta_get_ip_config");
1202 /*
1203 * Try to continue anyway since many UCC tests do not really
1204 * care about the return value from here..
1205 */
1206 }
1207
1208 val = get_param(cmd, "Type");
1209 if (val)
1210 type = atoi(val);
1211 if (type == 2 || dut->last_set_ip_config_ipv6) {
1212 int i;
1213
1214 /*
1215 * Since we do not have proper wait for IPv6 addresses, use a
1216 * fixed two second delay here as a workaround for UCC script
1217 * assuming IPv6 address is available when this command returns.
1218 * Some scripts did not use Type,2 properly for IPv6, so include
1219 * also the cases where the previous sta_set_ip_config indicated
1220 * use of IPv6.
1221 */
1222 sigma_dut_print(dut, DUT_MSG_INFO, "Wait up to extra ten seconds in sta_get_ip_config for IPv6 address");
1223 for (i = 0; i < 10; i++) {
1224 sleep(1);
1225 if (get_ipv6_config(dut, ifname, buf, sizeof(buf)) == 0)
1226 {
1227 sigma_dut_print(dut, DUT_MSG_INFO, "Found IPv6 address");
1228 send_resp(dut, conn, SIGMA_COMPLETE, buf);
1229#ifdef ANDROID
1230 sigma_dut_print(dut, DUT_MSG_INFO,
1231 "Adding IPv6 rule on Android");
1232 add_ipv6_rule(dut, intf);
1233#endif /* ANDROID */
1234
1235 return 0;
1236 }
1237 }
1238 }
1239 if (type == 1) {
1240 if (get_ip_config(dut, ifname, buf, sizeof(buf)) < 0)
1241 return -2;
1242 } else if (type == 2) {
1243 if (get_ipv6_config(dut, ifname, buf, sizeof(buf)) < 0)
1244 return -2;
1245 } else {
1246 send_resp(dut, conn, SIGMA_ERROR,
1247 "errorCode,Unsupported address type");
1248 return 0;
1249 }
1250
1251 send_resp(dut, conn, SIGMA_COMPLETE, buf);
1252 return 0;
1253}
1254
1255
1256static void kill_dhcp_client(struct sigma_dut *dut, const char *ifname)
1257{
1258#ifdef __linux__
1259 char buf[200];
1260 char path[128];
1261 struct stat s;
1262
1263#ifdef ANDROID
1264 snprintf(path, sizeof(path), "/data/misc/dhcp/dhcpcd-%s.pid", ifname);
1265#else /* ANDROID */
1266 snprintf(path, sizeof(path), "/var/run/dhclient-%s.pid", ifname);
1267#endif /* ANDROID */
1268 if (stat(path, &s) == 0) {
1269 snprintf(buf, sizeof(buf), "kill `cat %s`", path);
1270 sigma_dut_print(dut, DUT_MSG_INFO,
1271 "Kill previous DHCP client: %s", buf);
1272 if (system(buf) != 0)
1273 sigma_dut_print(dut, DUT_MSG_INFO,
1274 "Failed to kill DHCP client");
1275 unlink(path);
1276 sleep(1);
1277 } else {
1278 snprintf(path, sizeof(path), "/var/run/dhcpcd-%s.pid", ifname);
1279
1280 if (stat(path, &s) == 0) {
1281 snprintf(buf, sizeof(buf), "kill `cat %s`", path);
1282 sigma_dut_print(dut, DUT_MSG_INFO,
1283 "Kill previous DHCP client: %s", buf);
1284 if (system(buf) != 0)
1285 sigma_dut_print(dut, DUT_MSG_INFO,
1286 "Failed to kill DHCP client");
1287 unlink(path);
1288 sleep(1);
1289 }
1290 }
1291#endif /* __linux__ */
1292}
1293
1294
1295static int start_dhcp_client(struct sigma_dut *dut, const char *ifname)
1296{
1297#ifdef __linux__
1298 char buf[200];
1299
1300#ifdef ANDROID
Purushottam Kushwaha46d64262016-08-23 17:57:53 +05301301 if (access("/system/bin/dhcpcd", F_OK) != -1) {
1302 snprintf(buf, sizeof(buf),
1303 "/system/bin/dhcpcd -b %s", ifname);
1304 } else if (access("/system/bin/dhcptool", F_OK) != -1) {
1305 snprintf(buf, sizeof(buf), "/system/bin/dhcptool %s &", ifname);
Ankita Bajaj8454e5d2019-04-05 16:04:55 +05301306 } else if (access("/vendor/bin/dhcpcd", F_OK) != -1) {
1307 snprintf(buf, sizeof(buf), "/vendor/bin/dhcpcd -b %s", ifname);
1308 } else if (access("/vendor/bin/dhcptool", F_OK) != -1) {
1309 snprintf(buf, sizeof(buf), "/vendor/bin/dhcptool %s", ifname);
Purushottam Kushwaha46d64262016-08-23 17:57:53 +05301310 } else {
1311 sigma_dut_print(dut, DUT_MSG_ERROR,
1312 "DHCP client program missing");
1313 return 0;
1314 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001315#else /* ANDROID */
1316 snprintf(buf, sizeof(buf),
1317 "dhclient -nw -pf /var/run/dhclient-%s.pid %s",
1318 ifname, ifname);
1319#endif /* ANDROID */
1320 sigma_dut_print(dut, DUT_MSG_INFO, "Start DHCP client: %s", buf);
1321 if (system(buf) != 0) {
1322 snprintf(buf, sizeof(buf), "dhcpcd -t 0 %s &", ifname);
1323 if (system(buf) != 0) {
1324 sigma_dut_print(dut, DUT_MSG_INFO,
1325 "Failed to start DHCP client");
1326#ifndef ANDROID
1327 return -1;
1328#endif /* ANDROID */
1329 }
1330 }
1331#endif /* __linux__ */
1332
1333 return 0;
1334}
1335
1336
1337static int clear_ip_addr(struct sigma_dut *dut, const char *ifname)
1338{
1339#ifdef __linux__
1340 char buf[200];
1341
1342 snprintf(buf, sizeof(buf), "ip addr flush dev %s", ifname);
1343 if (system(buf) != 0) {
1344 sigma_dut_print(dut, DUT_MSG_INFO,
1345 "Failed to clear IP addresses");
1346 return -1;
1347 }
1348#endif /* __linux__ */
1349
1350 return 0;
1351}
1352
1353
1354#ifdef ANDROID
1355static int add_ipv6_rule(struct sigma_dut *dut, const char *ifname)
1356{
1357 char cmd[200], *result, *pos;
1358 FILE *fp;
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +05301359 int tableid;
1360 size_t len, result_len = 1000;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001361
1362 snprintf(cmd, sizeof(cmd), "ip -6 route list table all | grep %s",
1363 ifname);
1364 fp = popen(cmd, "r");
1365 if (fp == NULL)
1366 return -1;
1367
1368 result = malloc(result_len);
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05301369 if (result == NULL) {
1370 fclose(fp);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001371 return -1;
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05301372 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001373
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +05301374 len = fread(result, 1, result_len - 1, fp);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001375 fclose(fp);
1376
1377 if (len == 0) {
1378 free(result);
1379 return -1;
1380 }
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +05301381 result[len] = '\0';
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001382
1383 pos = strstr(result, "table ");
1384 if (pos == NULL) {
1385 free(result);
1386 return -1;
1387 }
1388
1389 pos += strlen("table ");
1390 tableid = atoi(pos);
1391 if (tableid != 0) {
1392 if (system("ip -6 rule del prio 22000") != 0) {
1393 /* ignore any error */
1394 }
1395 snprintf(cmd, sizeof(cmd),
1396 "ip -6 rule add from all lookup %d prio 22000",
1397 tableid);
1398 if (system(cmd) != 0) {
1399 sigma_dut_print(dut, DUT_MSG_INFO,
1400 "Failed to run %s", cmd);
1401 free(result);
1402 return -1;
1403 }
1404 } else {
1405 sigma_dut_print(dut, DUT_MSG_INFO,
1406 "No Valid Table Id found %s", pos);
1407 free(result);
1408 return -1;
1409 }
1410 free(result);
1411
1412 return 0;
1413}
1414#endif /* ANDROID */
1415
1416
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301417int set_ipv4_addr(struct sigma_dut *dut, const char *ifname,
1418 const char *ip, const char *mask)
1419{
1420 char buf[200];
1421
1422 snprintf(buf, sizeof(buf), "ifconfig %s %s netmask %s",
1423 ifname, ip, mask);
1424 return system(buf) == 0;
1425}
1426
1427
1428int set_ipv4_gw(struct sigma_dut *dut, const char *gw)
1429{
1430 char buf[200];
1431
1432 if (!is_ip_addr(gw)) {
1433 sigma_dut_print(dut, DUT_MSG_DEBUG, "Invalid gw addr - %s", gw);
1434 return -1;
1435 }
1436
1437 snprintf(buf, sizeof(buf), "route add default gw %s", gw);
1438 if (!dut->no_ip_addr_set && system(buf) != 0) {
1439 snprintf(buf, sizeof(buf), "ip ro re default via %s",
1440 gw);
1441 if (system(buf) != 0)
1442 return 0;
1443 }
1444
1445 return 1;
1446}
1447
1448
Jouni Malinenf7222712019-06-13 01:50:21 +03001449static enum sigma_cmd_result cmd_sta_set_ip_config(struct sigma_dut *dut,
1450 struct sigma_conn *conn,
1451 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001452{
1453 const char *intf = get_param(cmd, "Interface");
1454 const char *ifname;
1455 char buf[200];
1456 const char *val, *ip, *mask, *gw;
1457 int type = 1;
1458
1459 if (intf == NULL)
1460 return -1;
1461
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001462 if (strcmp(intf, get_main_ifname(dut)) == 0)
1463 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001464 else
1465 ifname = intf;
1466
1467 if (if_nametoindex(ifname) == 0) {
1468 send_resp(dut, conn, SIGMA_ERROR,
1469 "ErrorCode,Unknown interface");
1470 return 0;
1471 }
1472
1473 val = get_param(cmd, "Type");
1474 if (val) {
1475 type = atoi(val);
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301476 if (type < 1 || type > 3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001477 send_resp(dut, conn, SIGMA_ERROR,
1478 "ErrorCode,Unsupported address type");
1479 return 0;
1480 }
1481 }
1482
1483 dut->last_set_ip_config_ipv6 = 0;
1484
1485 val = get_param(cmd, "dhcp");
1486 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "true") == 0)) {
1487 static_ip_file(0, NULL, NULL, NULL);
1488#ifdef __linux__
1489 if (type == 2) {
1490 dut->last_set_ip_config_ipv6 = 1;
1491 sigma_dut_print(dut, DUT_MSG_INFO, "Using IPv6 "
1492 "stateless address autoconfiguration");
1493#ifdef ANDROID
1494 /*
1495 * This sleep is required as the assignment in case of
1496 * Android is taking time and is done by the kernel.
1497 * The subsequent ping for IPv6 is impacting HS20 test
1498 * case.
1499 */
1500 sleep(2);
1501 add_ipv6_rule(dut, intf);
1502#endif /* ANDROID */
1503 /* Assume this happens by default */
1504 return 1;
1505 }
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301506 if (type != 3) {
1507 kill_dhcp_client(dut, ifname);
1508 if (start_dhcp_client(dut, ifname) < 0)
1509 return -2;
1510 } else {
1511 sigma_dut_print(dut, DUT_MSG_DEBUG,
1512 "Using FILS HLP DHCPv4 Rapid Commit");
1513 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001514
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001515 return 1;
1516#endif /* __linux__ */
1517 return -2;
1518 }
1519
1520 ip = get_param(cmd, "ip");
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301521 if (!ip) {
1522 send_resp(dut, conn, SIGMA_INVALID,
1523 "ErrorCode,Missing IP address");
1524 return 0;
1525 }
1526
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001527 mask = get_param(cmd, "mask");
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301528 if (!mask) {
1529 send_resp(dut, conn, SIGMA_INVALID,
1530 "ErrorCode,Missing subnet mask");
1531 return 0;
1532 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001533
1534 if (type == 2) {
1535 int net = atoi(mask);
1536
1537 if ((net < 0 && net > 64) || !is_ipv6_addr(ip))
1538 return -1;
1539
1540 if (dut->no_ip_addr_set) {
1541 snprintf(buf, sizeof(buf),
1542 "sysctl net.ipv6.conf.%s.disable_ipv6=1",
1543 ifname);
1544 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
1545 if (system(buf) != 0) {
1546 sigma_dut_print(dut, DUT_MSG_DEBUG,
1547 "Failed to disable IPv6 address before association");
1548 }
1549 } else {
Veerendranath Jakkam176181c2020-05-16 00:19:21 +05301550 if (set_ipv6_addr(dut, ip, mask, ifname) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001551 send_resp(dut, conn, SIGMA_ERROR,
1552 "ErrorCode,Failed to set IPv6 address");
1553 return 0;
1554 }
1555 }
1556
1557 dut->last_set_ip_config_ipv6 = 1;
1558 static_ip_file(6, ip, mask, NULL);
1559 return 1;
1560 } else if (type == 1) {
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301561 if (!is_ip_addr(ip) || !is_ip_addr(mask))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001562 return -1;
1563 }
1564
1565 kill_dhcp_client(dut, ifname);
1566
1567 if (!dut->no_ip_addr_set) {
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301568 if (!set_ipv4_addr(dut, ifname, ip, mask)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001569 send_resp(dut, conn, SIGMA_ERROR,
1570 "ErrorCode,Failed to set IP address");
1571 return 0;
1572 }
1573 }
1574
1575 gw = get_param(cmd, "defaultGateway");
1576 if (gw) {
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301577 if (set_ipv4_gw(dut, gw) < 1) {
1578 send_resp(dut, conn, SIGMA_ERROR,
1579 "ErrorCode,Failed to set default gateway");
1580 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001581 }
1582 }
1583
1584 val = get_param(cmd, "primary-dns");
1585 if (val) {
Vinita S. Maloo069e8d42021-04-29 13:15:08 +05301586#ifdef ANDROID
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001587 /* TODO */
1588 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored primary-dns %s "
1589 "setting", val);
Vinita S. Maloo069e8d42021-04-29 13:15:08 +05301590#else /* ANDROID */
1591 char dns_cmd[200];
1592 int len;
1593
1594 if (system("sed -i '/nameserver/d' /etc/resolv.conf") != 0) {
1595 sigma_dut_print(dut, DUT_MSG_ERROR,
1596 "Failed to clear nameserver entries in /etc/resolv.conf");
1597 return ERROR_SEND_STATUS;
1598 }
1599
1600 len = snprintf(dns_cmd, sizeof(dns_cmd),
1601 "sed -i '1 i nameserver %s' /etc/resolv.conf", val);
1602 if (len < 0 || len >= sizeof(dns_cmd))
1603 return ERROR_SEND_STATUS;
1604
1605 sigma_dut_print(dut, DUT_MSG_DEBUG, "Running %s", dns_cmd);
1606 if (system(dns_cmd) != 0) {
1607 send_resp(dut, conn, SIGMA_ERROR,
1608 "ErrorCode,Failed to set primary-dns");
1609 return STATUS_SENT_ERROR;
1610 }
1611#endif /* ANDROID */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001612 }
1613
1614 val = get_param(cmd, "secondary-dns");
1615 if (val) {
1616 /* TODO */
1617 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored secondary-dns %s "
1618 "setting", val);
1619 }
1620
1621 static_ip_file(4, ip, mask, gw);
1622
1623 return 1;
1624}
1625
1626
Jouni Malinenf7222712019-06-13 01:50:21 +03001627static enum sigma_cmd_result cmd_sta_get_info(struct sigma_dut *dut,
1628 struct sigma_conn *conn,
1629 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001630{
1631 /* const char *intf = get_param(cmd, "Interface"); */
1632 /* TODO: could report more details here */
1633 send_resp(dut, conn, SIGMA_COMPLETE, "vendor,Atheros");
1634 return 0;
1635}
1636
1637
Jouni Malinenf7222712019-06-13 01:50:21 +03001638static enum sigma_cmd_result cmd_sta_get_mac_address(struct sigma_dut *dut,
1639 struct sigma_conn *conn,
1640 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001641{
1642 /* const char *intf = get_param(cmd, "Interface"); */
1643 char addr[20], resp[50];
1644
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05301645 if (dut->dev_role == DEVROLE_STA_CFON)
1646 return sta_cfon_get_mac_address(dut, conn, cmd);
1647
Jouni Malinen9540e012019-11-05 17:08:42 +02001648 start_sta_mode(dut);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001649 if (get_wpa_status(get_station_ifname(dut), "address",
1650 addr, sizeof(addr)) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001651 return -2;
1652
1653 snprintf(resp, sizeof(resp), "mac,%s", addr);
1654 send_resp(dut, conn, SIGMA_COMPLETE, resp);
1655 return 0;
1656}
1657
1658
Jouni Malinenf7222712019-06-13 01:50:21 +03001659static enum sigma_cmd_result cmd_sta_is_connected(struct sigma_dut *dut,
1660 struct sigma_conn *conn,
1661 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001662{
1663 /* const char *intf = get_param(cmd, "Interface"); */
1664 int connected = 0;
1665 char result[32];
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001666 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001667 sizeof(result)) < 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001668 sigma_dut_print(dut, DUT_MSG_INFO,
1669 "Could not get interface %s status",
1670 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001671 return -2;
1672 }
1673
1674 sigma_dut_print(dut, DUT_MSG_DEBUG, "wpa_state=%s", result);
1675 if (strncmp(result, "COMPLETED", 9) == 0)
1676 connected = 1;
1677
1678 if (connected)
1679 send_resp(dut, conn, SIGMA_COMPLETE, "connected,1");
1680 else
1681 send_resp(dut, conn, SIGMA_COMPLETE, "connected,0");
1682
1683 return 0;
1684}
1685
1686
Jouni Malinenf7222712019-06-13 01:50:21 +03001687static enum sigma_cmd_result
1688cmd_sta_verify_ip_connection(struct sigma_dut *dut, struct sigma_conn *conn,
1689 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001690{
1691 /* const char *intf = get_param(cmd, "Interface"); */
1692 const char *dst, *timeout;
1693 int wait_time = 90;
1694 char buf[100];
1695 int res;
1696
1697 dst = get_param(cmd, "destination");
1698 if (dst == NULL || !is_ip_addr(dst))
1699 return -1;
1700
1701 timeout = get_param(cmd, "timeout");
1702 if (timeout) {
1703 wait_time = atoi(timeout);
1704 if (wait_time < 1)
1705 wait_time = 1;
1706 }
1707
1708 /* TODO: force renewal of IP lease if DHCP is enabled */
1709
1710 snprintf(buf, sizeof(buf), "ping %s -c 3 -W %d", dst, wait_time);
1711 res = system(buf);
1712 sigma_dut_print(dut, DUT_MSG_DEBUG, "ping returned: %d", res);
1713 if (res == 0)
1714 send_resp(dut, conn, SIGMA_COMPLETE, "connected,1");
1715 else if (res == 256)
1716 send_resp(dut, conn, SIGMA_COMPLETE, "connected,0");
1717 else
1718 return -2;
1719
1720 return 0;
1721}
1722
1723
Jouni Malinenf7222712019-06-13 01:50:21 +03001724static enum sigma_cmd_result cmd_sta_get_bssid(struct sigma_dut *dut,
1725 struct sigma_conn *conn,
1726 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001727{
1728 /* const char *intf = get_param(cmd, "Interface"); */
1729 char bssid[20], resp[50];
1730
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001731 if (get_wpa_status(get_station_ifname(dut), "bssid",
1732 bssid, sizeof(bssid)) < 0)
Peng Xub8fc5cc2017-05-10 17:27:28 -07001733 strlcpy(bssid, "00:00:00:00:00:00", sizeof(bssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001734
1735 snprintf(resp, sizeof(resp), "bssid,%s", bssid);
1736 send_resp(dut, conn, SIGMA_COMPLETE, resp);
1737 return 0;
1738}
1739
1740
1741#ifdef __SAMSUNG__
1742static int add_use_network(const char *ifname)
1743{
1744 char buf[100];
1745
1746 snprintf(buf, sizeof(buf), "USE_NETWORK ON");
1747 wpa_command(ifname, buf);
1748 return 0;
1749}
1750#endif /* __SAMSUNG__ */
1751
1752
1753static int add_network_common(struct sigma_dut *dut, struct sigma_conn *conn,
1754 const char *ifname, struct sigma_cmd *cmd)
1755{
1756 const char *ssid = get_param(cmd, "ssid");
1757 int id;
1758 const char *val;
1759
1760 if (ssid == NULL)
1761 return -1;
1762
1763 start_sta_mode(dut);
1764
1765#ifdef __SAMSUNG__
1766 add_use_network(ifname);
1767#endif /* __SAMSUNG__ */
1768
1769 id = add_network(ifname);
1770 if (id < 0)
1771 return -2;
1772 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding network %d", id);
1773
1774 if (set_network_quoted(ifname, id, "ssid", ssid) < 0)
1775 return -2;
1776
1777 dut->infra_network_id = id;
1778 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
1779
1780 val = get_param(cmd, "program");
1781 if (!val)
1782 val = get_param(cmd, "prog");
1783 if (val && strcasecmp(val, "hs2") == 0) {
1784 char buf[100];
1785 snprintf(buf, sizeof(buf), "ENABLE_NETWORK %d no-connect", id);
1786 wpa_command(ifname, buf);
1787
1788 val = get_param(cmd, "prefer");
1789 if (val && atoi(val) > 0)
1790 set_network(ifname, id, "priority", "1");
1791 }
1792
1793 return id;
1794}
1795
1796
Jouni Malinenf7222712019-06-13 01:50:21 +03001797static enum sigma_cmd_result cmd_sta_set_encryption(struct sigma_dut *dut,
1798 struct sigma_conn *conn,
1799 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001800{
1801 const char *intf = get_param(cmd, "Interface");
1802 const char *ssid = get_param(cmd, "ssid");
1803 const char *type = get_param(cmd, "encpType");
1804 const char *ifname;
1805 char buf[200];
1806 int id;
1807
1808 if (intf == NULL || ssid == NULL)
1809 return -1;
1810
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001811 if (strcmp(intf, get_main_ifname(dut)) == 0)
1812 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001813 else
1814 ifname = intf;
1815
1816 id = add_network_common(dut, conn, ifname, cmd);
1817 if (id < 0)
1818 return id;
1819
1820 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
1821 return -2;
1822
1823 if (type && strcasecmp(type, "wep") == 0) {
1824 const char *val;
1825 int i;
1826
1827 val = get_param(cmd, "activeKey");
1828 if (val) {
1829 int keyid;
1830 keyid = atoi(val);
1831 if (keyid < 1 || keyid > 4)
1832 return -1;
1833 snprintf(buf, sizeof(buf), "%d", keyid - 1);
1834 if (set_network(ifname, id, "wep_tx_keyidx", buf) < 0)
1835 return -2;
1836 }
1837
1838 for (i = 0; i < 4; i++) {
1839 snprintf(buf, sizeof(buf), "key%d", i + 1);
1840 val = get_param(cmd, buf);
1841 if (val == NULL)
1842 continue;
1843 snprintf(buf, sizeof(buf), "wep_key%d", i);
1844 if (set_network(ifname, id, buf, val) < 0)
1845 return -2;
1846 }
1847 }
1848
1849 return 1;
1850}
1851
1852
Jouni Malinene4fde732019-03-25 22:29:37 +02001853static int set_akm_suites(struct sigma_dut *dut, const char *ifname,
1854 int id, const char *val)
1855{
1856 char key_mgmt[200], *end, *pos;
1857 const char *in_pos = val;
1858
Jouni Malinen8179fee2019-03-28 03:19:47 +02001859 dut->akm_values = 0;
Jouni Malinene4fde732019-03-25 22:29:37 +02001860 pos = key_mgmt;
1861 end = pos + sizeof(key_mgmt);
1862 while (*in_pos) {
1863 int res, akm = atoi(in_pos);
1864 const char *str;
1865
Jouni Malinen8179fee2019-03-28 03:19:47 +02001866 if (akm >= 0 && akm < 32)
1867 dut->akm_values |= 1 << akm;
1868
Jouni Malinene4fde732019-03-25 22:29:37 +02001869 switch (akm) {
1870 case AKM_WPA_EAP:
1871 str = "WPA-EAP";
1872 break;
1873 case AKM_WPA_PSK:
1874 str = "WPA-PSK";
1875 break;
1876 case AKM_FT_EAP:
1877 str = "FT-EAP";
1878 break;
1879 case AKM_FT_PSK:
1880 str = "FT-PSK";
1881 break;
1882 case AKM_EAP_SHA256:
1883 str = "WPA-EAP-SHA256";
1884 break;
1885 case AKM_PSK_SHA256:
1886 str = "WPA-PSK-SHA256";
1887 break;
1888 case AKM_SAE:
1889 str = "SAE";
1890 break;
1891 case AKM_FT_SAE:
1892 str = "FT-SAE";
1893 break;
1894 case AKM_SUITE_B:
1895 str = "WPA-EAP-SUITE-B-192";
1896 break;
1897 case AKM_FT_SUITE_B:
1898 str = "FT-EAP-SHA384";
1899 break;
1900 case AKM_FILS_SHA256:
1901 str = "FILS-SHA256";
1902 break;
1903 case AKM_FILS_SHA384:
1904 str = "FILS-SHA384";
1905 break;
1906 case AKM_FT_FILS_SHA256:
1907 str = "FT-FILS-SHA256";
1908 break;
1909 case AKM_FT_FILS_SHA384:
1910 str = "FT-FILS-SHA384";
1911 break;
1912 default:
1913 sigma_dut_print(dut, DUT_MSG_ERROR,
1914 "Unsupported AKMSuitetype %d", akm);
1915 return -1;
1916 }
1917
1918 res = snprintf(pos, end - pos, "%s%s",
1919 pos == key_mgmt ? "" : " ", str);
1920 if (res < 0 || res >= end - pos)
1921 return -1;
1922 pos += res;
1923
1924 in_pos = strchr(in_pos, ';');
1925 if (!in_pos)
1926 break;
1927 while (*in_pos == ';')
1928 in_pos++;
1929 }
1930 sigma_dut_print(dut, DUT_MSG_DEBUG, "AKMSuiteType %s --> %s",
1931 val, key_mgmt);
1932 return set_network(ifname, id, "key_mgmt", key_mgmt);
1933}
1934
1935
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001936static int set_wpa_common(struct sigma_dut *dut, struct sigma_conn *conn,
1937 const char *ifname, struct sigma_cmd *cmd)
1938{
1939 const char *val;
1940 int id;
Jouni Malinenad395a22017-09-01 21:13:46 +03001941 int cipher_set = 0;
Jouni Malinen47dcc952017-10-09 16:43:24 +03001942 int owe;
Sunil Duttc75a1e62018-01-11 20:47:50 +05301943 int suite_b = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001944
1945 id = add_network_common(dut, conn, ifname, cmd);
1946 if (id < 0)
1947 return id;
1948
Jouni Malinen47dcc952017-10-09 16:43:24 +03001949 val = get_param(cmd, "Type");
1950 owe = val && strcasecmp(val, "OWE") == 0;
1951
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001952 val = get_param(cmd, "keyMgmtType");
Jouni Malinen47dcc952017-10-09 16:43:24 +03001953 if (!val && owe)
1954 val = "OWE";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001955 if (val == NULL) {
Jouni Malinene4fde732019-03-25 22:29:37 +02001956 /* keyMgmtType is being replaced with AKMSuiteType, so ignore
1957 * this missing parameter and assume proto=WPA2. */
1958 if (set_network(ifname, id, "proto", "WPA2") < 0)
1959 return ERROR_SEND_STATUS;
1960 } else if (strcasecmp(val, "wpa") == 0 ||
1961 strcasecmp(val, "wpa-psk") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001962 if (set_network(ifname, id, "proto", "WPA") < 0)
1963 return -2;
1964 } else if (strcasecmp(val, "wpa2") == 0 ||
1965 strcasecmp(val, "wpa2-psk") == 0 ||
1966 strcasecmp(val, "wpa2-ft") == 0 ||
1967 strcasecmp(val, "wpa2-sha256") == 0) {
1968 if (set_network(ifname, id, "proto", "WPA2") < 0)
1969 return -2;
Pradeep Reddy POTTETI6d04b3b2016-11-15 14:51:26 +05301970 } else if (strcasecmp(val, "wpa2-wpa-psk") == 0 ||
1971 strcasecmp(val, "wpa2-wpa-ent") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001972 if (set_network(ifname, id, "proto", "WPA WPA2") < 0)
1973 return -2;
Jouni Malinenad395a22017-09-01 21:13:46 +03001974 } else if (strcasecmp(val, "SuiteB") == 0) {
Sunil Duttc75a1e62018-01-11 20:47:50 +05301975 suite_b = 1;
Jouni Malinenad395a22017-09-01 21:13:46 +03001976 if (set_network(ifname, id, "proto", "WPA2") < 0)
1977 return -2;
Jouni Malinen47dcc952017-10-09 16:43:24 +03001978 } else if (strcasecmp(val, "OWE") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001979 } else {
1980 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized keyMgmtType value");
1981 return 0;
1982 }
1983
1984 val = get_param(cmd, "encpType");
Jouni Malinenad395a22017-09-01 21:13:46 +03001985 if (val) {
1986 cipher_set = 1;
1987 if (strcasecmp(val, "tkip") == 0) {
1988 if (set_network(ifname, id, "pairwise", "TKIP") < 0)
1989 return -2;
1990 } else if (strcasecmp(val, "aes-ccmp") == 0) {
1991 if (set_network(ifname, id, "pairwise", "CCMP") < 0)
1992 return -2;
1993 } else if (strcasecmp(val, "aes-ccmp-tkip") == 0) {
1994 if (set_network(ifname, id, "pairwise",
1995 "CCMP TKIP") < 0)
1996 return -2;
1997 } else if (strcasecmp(val, "aes-gcmp") == 0) {
1998 if (set_network(ifname, id, "pairwise", "GCMP") < 0)
1999 return -2;
2000 if (set_network(ifname, id, "group", "GCMP") < 0)
2001 return -2;
2002 } else {
2003 send_resp(dut, conn, SIGMA_ERROR,
2004 "errorCode,Unrecognized encpType value");
2005 return 0;
2006 }
2007 }
2008
2009 val = get_param(cmd, "PairwiseCipher");
2010 if (val) {
2011 cipher_set = 1;
2012 /* TODO: Support space separated list */
2013 if (strcasecmp(val, "AES-GCMP-256") == 0) {
2014 if (set_network(ifname, id, "pairwise", "GCMP-256") < 0)
2015 return -2;
2016 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
2017 if (set_network(ifname, id, "pairwise",
2018 "CCMP-256") < 0)
2019 return -2;
2020 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
2021 if (set_network(ifname, id, "pairwise", "GCMP") < 0)
2022 return -2;
2023 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
2024 if (set_network(ifname, id, "pairwise", "CCMP") < 0)
2025 return -2;
2026 } else {
2027 send_resp(dut, conn, SIGMA_ERROR,
2028 "errorCode,Unrecognized PairwiseCipher value");
2029 return 0;
2030 }
2031 }
2032
Jouni Malinen47dcc952017-10-09 16:43:24 +03002033 if (!cipher_set && !owe) {
Jouni Malinenad395a22017-09-01 21:13:46 +03002034 send_resp(dut, conn, SIGMA_ERROR,
2035 "errorCode,Missing encpType and PairwiseCipher");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002036 return 0;
2037 }
Jouni Malinenad395a22017-09-01 21:13:46 +03002038
2039 val = get_param(cmd, "GroupCipher");
2040 if (val) {
2041 if (strcasecmp(val, "AES-GCMP-256") == 0) {
2042 if (set_network(ifname, id, "group", "GCMP-256") < 0)
2043 return -2;
2044 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
2045 if (set_network(ifname, id, "group", "CCMP-256") < 0)
2046 return -2;
2047 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
2048 if (set_network(ifname, id, "group", "GCMP") < 0)
2049 return -2;
2050 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
2051 if (set_network(ifname, id, "group", "CCMP") < 0)
2052 return -2;
2053 } else {
2054 send_resp(dut, conn, SIGMA_ERROR,
2055 "errorCode,Unrecognized GroupCipher value");
2056 return 0;
2057 }
2058 }
2059
Jouni Malinen7b239522017-09-14 21:37:18 +03002060 val = get_param(cmd, "GroupMgntCipher");
Jouni Malinenad395a22017-09-01 21:13:46 +03002061 if (val) {
Jouni Malinene8898cb2017-09-26 17:55:26 +03002062 const char *cipher;
2063
2064 if (strcasecmp(val, "BIP-GMAC-256") == 0) {
2065 cipher = "BIP-GMAC-256";
2066 } else if (strcasecmp(val, "BIP-CMAC-256") == 0) {
2067 cipher = "BIP-CMAC-256";
2068 } else if (strcasecmp(val, "BIP-GMAC-128") == 0) {
2069 cipher = "BIP-GMAC-128";
2070 } else if (strcasecmp(val, "BIP-CMAC-128") == 0) {
2071 cipher = "AES-128-CMAC";
2072 } else {
2073 send_resp(dut, conn, SIGMA_INVALID,
2074 "errorCode,Unsupported GroupMgntCipher");
2075 return 0;
2076 }
2077 if (set_network(ifname, id, "group_mgmt", cipher) < 0) {
2078 send_resp(dut, conn, SIGMA_INVALID,
2079 "errorCode,Failed to set GroupMgntCipher");
2080 return 0;
2081 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002082 }
2083
Jouni Malinene4fde732019-03-25 22:29:37 +02002084 val = get_param(cmd, "AKMSuiteType");
2085 if (val && set_akm_suites(dut, ifname, id, val) < 0)
2086 return ERROR_SEND_STATUS;
2087
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002088 dut->sta_pmf = STA_PMF_DISABLED;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302089
2090 if (dut->program == PROGRAM_OCE) {
2091 dut->sta_pmf = STA_PMF_OPTIONAL;
2092 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2093 return -2;
2094 }
2095
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002096 val = get_param(cmd, "PMF");
2097 if (val) {
2098 if (strcasecmp(val, "Required") == 0 ||
2099 strcasecmp(val, "Forced_Required") == 0) {
2100 dut->sta_pmf = STA_PMF_REQUIRED;
2101 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2102 return -2;
2103 } else if (strcasecmp(val, "Optional") == 0) {
2104 dut->sta_pmf = STA_PMF_OPTIONAL;
2105 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2106 return -2;
2107 } else if (strcasecmp(val, "Disabled") == 0 ||
Kiran Kumar Lokere07da3b22018-12-16 22:42:49 -08002108 strcasecmp(val, "Disable") == 0 ||
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002109 strcasecmp(val, "Forced_Disabled") == 0) {
2110 dut->sta_pmf = STA_PMF_DISABLED;
2111 } else {
2112 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized PMF value");
2113 return 0;
2114 }
Sunil Duttc75a1e62018-01-11 20:47:50 +05302115 } else if (owe || suite_b) {
Jouni Malinen1287cd72018-01-04 17:08:01 +02002116 dut->sta_pmf = STA_PMF_REQUIRED;
2117 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2118 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002119 }
2120
Jouni Malinen0165c7f2020-03-26 11:51:58 +02002121 val = get_param(cmd, "BeaconProtection");
Veerendranath Jakkamc1f71b62021-01-23 03:09:51 +05302122 if (val)
2123 dut->beacon_prot = atoi(val);
2124 if (dut->beacon_prot && set_network(ifname, id, "beacon_prot", "1") < 0)
Jouni Malinen0165c7f2020-03-26 11:51:58 +02002125 return ERROR_SEND_STATUS;
2126
Veerendranath Jakkam54fd51c2020-12-21 01:36:04 +05302127 if (dut->ocvc && set_network(ifname, id, "ocv", "1") < 0)
2128 return ERROR_SEND_STATUS;
2129
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002130 return id;
2131}
2132
2133
Jouni Malinenf7222712019-06-13 01:50:21 +03002134static enum sigma_cmd_result cmd_sta_set_psk(struct sigma_dut *dut,
2135 struct sigma_conn *conn,
2136 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002137{
2138 const char *intf = get_param(cmd, "Interface");
Jouni Malinen992a81e2017-08-22 13:57:47 +03002139 const char *type = get_param(cmd, "Type");
Jouni Malinen1287cd72018-01-04 17:08:01 +02002140 const char *pmf = get_param(cmd, "PMF");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002141 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinene4fde732019-03-25 22:29:37 +02002142 const char *akm = get_param(cmd, "AKMSuiteType");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002143 const char *ifname, *val, *alg;
2144 int id;
Jouni Malinen4b3769d2019-10-10 16:20:29 +03002145 char buf[50];
Jouni Malinen11e55212019-11-22 21:46:59 +02002146 int sae_pwe = -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002147
2148 if (intf == NULL)
2149 return -1;
2150
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002151 if (strcmp(intf, get_main_ifname(dut)) == 0)
2152 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002153 else
2154 ifname = intf;
2155
2156 id = set_wpa_common(dut, conn, ifname, cmd);
2157 if (id < 0)
2158 return id;
2159
2160 val = get_param(cmd, "keyMgmtType");
2161 alg = get_param(cmd, "micAlg");
2162
Jouni Malinen992a81e2017-08-22 13:57:47 +03002163 if (type && strcasecmp(type, "SAE") == 0) {
Jouni Malinene4fde732019-03-25 22:29:37 +02002164 if (!akm && val && strcasecmp(val, "wpa2-ft") == 0) {
Jouni Malinen992a81e2017-08-22 13:57:47 +03002165 if (set_network(ifname, id, "key_mgmt", "FT-SAE") < 0)
2166 return -2;
Jouni Malinene4fde732019-03-25 22:29:37 +02002167 } else if (!akm) {
Jouni Malinen992a81e2017-08-22 13:57:47 +03002168 if (set_network(ifname, id, "key_mgmt", "SAE") < 0)
2169 return -2;
2170 }
2171 if (wpa_command(ifname, "SET sae_groups ") != 0) {
2172 sigma_dut_print(dut, DUT_MSG_ERROR,
2173 "Failed to clear sae_groups to default");
2174 return -2;
2175 }
Jouni Malinen1287cd72018-01-04 17:08:01 +02002176 if (!pmf) {
2177 dut->sta_pmf = STA_PMF_REQUIRED;
2178 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2179 return -2;
2180 }
Jouni Malinen0ab50f42017-08-31 01:34:59 +03002181 } else if (type && strcasecmp(type, "PSK-SAE") == 0) {
2182 if (val && strcasecmp(val, "wpa2-ft") == 0) {
2183 if (set_network(ifname, id, "key_mgmt",
2184 "FT-SAE FT-PSK") < 0)
2185 return -2;
Jouni Malinen3b73d872019-06-12 03:13:25 +03002186 } else if (!akm) {
Jouni Malinen0ab50f42017-08-31 01:34:59 +03002187 if (set_network(ifname, id, "key_mgmt",
2188 "SAE WPA-PSK") < 0)
2189 return -2;
2190 }
2191 if (wpa_command(ifname, "SET sae_groups ") != 0) {
2192 sigma_dut_print(dut, DUT_MSG_ERROR,
2193 "Failed to clear sae_groups to default");
2194 return -2;
2195 }
Jouni Malinen1287cd72018-01-04 17:08:01 +02002196 if (!pmf) {
2197 dut->sta_pmf = STA_PMF_OPTIONAL;
2198 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2199 return -2;
2200 }
Jouni Malinen992a81e2017-08-22 13:57:47 +03002201 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002202 if (set_network(ifname, id, "key_mgmt", "WPA-PSK-SHA256") < 0)
2203 return -2;
2204 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
2205 if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0)
2206 return -2;
Ashwini Patil6dbf7b02017-03-20 13:42:11 +05302207 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
2208 if (set_network(ifname, id, "key_mgmt", "FT-PSK") < 0)
2209 return -2;
Jouni Malinen3b73d872019-06-12 03:13:25 +03002210 } else if (!akm &&
2211 ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
2212 dut->sta_pmf == STA_PMF_REQUIRED)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002213 if (set_network(ifname, id, "key_mgmt",
2214 "WPA-PSK WPA-PSK-SHA256") < 0)
2215 return -2;
Jouni Malinen77ff3f02019-03-28 03:45:40 +02002216 } else if (!akm && dut->sta_pmf == STA_PMF_OPTIONAL) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002217 if (set_network(ifname, id, "key_mgmt",
2218 "WPA-PSK WPA-PSK-SHA256") < 0)
2219 return -2;
Jouni Malinen77ff3f02019-03-28 03:45:40 +02002220 } else if (!akm) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002221 if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0)
2222 return -2;
2223 }
2224
2225 val = get_param(cmd, "passPhrase");
2226 if (val == NULL)
2227 return -1;
Jouni Malinen2126f422017-10-11 23:24:33 +03002228 if (type && strcasecmp(type, "SAE") == 0) {
2229 if (set_network_quoted(ifname, id, "sae_password", val) < 0)
2230 return -2;
2231 } else {
2232 if (set_network_quoted(ifname, id, "psk", val) < 0)
2233 return -2;
2234 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002235
Jouni Malinen78d10c42019-03-25 22:34:32 +02002236 val = get_param(cmd, "PasswordId");
2237 if (val && set_network_quoted(ifname, id, "sae_password_id", val) < 0)
2238 return ERROR_SEND_STATUS;
2239
Jouni Malinen992a81e2017-08-22 13:57:47 +03002240 val = get_param(cmd, "ECGroupID");
2241 if (val) {
Jouni Malinenb54f0df2019-12-12 01:57:29 +02002242 snprintf(buf, sizeof(buf), "SET sae_groups %s", val);
Jouni Malinen992a81e2017-08-22 13:57:47 +03002243 if (wpa_command(ifname, buf) != 0) {
2244 sigma_dut_print(dut, DUT_MSG_ERROR,
2245 "Failed to clear sae_groups");
2246 return -2;
2247 }
2248 }
2249
Jouni Malinen68143132017-09-02 02:34:08 +03002250 val = get_param(cmd, "InvalidSAEElement");
2251 if (val) {
2252 free(dut->sae_commit_override);
2253 dut->sae_commit_override = strdup(val);
2254 }
2255
Jouni Malinen4b3769d2019-10-10 16:20:29 +03002256 val = get_param(cmd, "PMKID_Include");
2257 if (val) {
2258 snprintf(buf, sizeof(buf), "SET sae_pmkid_in_assoc %d",
2259 get_enable_disable(val));
2260 wpa_command(intf, buf);
2261 }
2262
Jouni Malineneeb43d32019-12-06 17:40:07 +02002263 val = get_param(cmd, "IgnoreH2E_RSNXE_BSSMemSel");
2264 if (val) {
2265 snprintf(buf, sizeof(buf), "SET ignore_sae_h2e_only %d",
2266 get_enable_disable(val));
2267 wpa_command(intf, buf);
2268 }
2269
Jouni Malinenf2348d22019-12-07 11:52:55 +02002270 val = get_param(cmd, "ECGroupID_RGE");
2271 if (val) {
2272 snprintf(buf, sizeof(buf), "SET extra_sae_rejected_groups %s",
2273 val);
2274 wpa_command(intf, buf);
2275 }
2276
Jouni Malinen99e55022019-12-07 13:59:41 +02002277 val = get_param(cmd, "RSNXE_Content");
2278 if (val) {
2279 const char *param;
2280
2281 if (strncasecmp(val, "AssocReq:", 9) == 0) {
2282 val += 9;
2283 param = "rsnxe_override_assoc";
2284 } else if (strncasecmp(val, "EapolM2:", 8) == 0) {
2285 val += 8;
2286 param = "rsnxe_override_eapol";
2287 } else {
2288 send_resp(dut, conn, SIGMA_ERROR,
2289 "errorCode,Unsupported RSNXE_Content value");
2290 return STATUS_SENT_ERROR;
2291 }
2292 snprintf(buf, sizeof(buf), "SET %s %s", param, val);
2293 wpa_command(intf, buf);
2294 }
2295
Jouni Malinen11e55212019-11-22 21:46:59 +02002296 val = get_param(cmd, "sae_pwe");
2297 if (val) {
2298 if (strcasecmp(val, "h2e") == 0) {
2299 dut->sae_pwe = SAE_PWE_H2E;
Jouni Malinen7244a412019-12-07 11:54:10 +02002300 } else if (strcasecmp(val, "loop") == 0 ||
2301 strcasecmp(val, "looping") == 0) {
Jouni Malinen11e55212019-11-22 21:46:59 +02002302 dut->sae_pwe = SAE_PWE_LOOP;
2303 } else {
2304 send_resp(dut, conn, SIGMA_ERROR,
2305 "errorCode,Unsupported sae_pwe value");
2306 return STATUS_SENT_ERROR;
2307 }
2308 }
Vinita S. Maloo6d7454f2020-04-02 15:03:26 +05302309
2310 val = get_param(cmd, "Clear_RSNXE");
2311 if (val && strcmp(val, "1") == 0 &&
2312 (wpa_command(intf, "SET rsnxe_override_assoc ") ||
2313 wpa_command(intf, "SET rsnxe_override_eapol "))) {
2314 send_resp(dut, conn, SIGMA_ERROR,
2315 "errorCode,Failed to clear RSNXE");
Jouni Malinenb11498c2020-08-03 11:05:53 +03002316 return STATUS_SENT_ERROR;
Vinita S. Maloo6d7454f2020-04-02 15:03:26 +05302317 }
2318
Jouni Malinenc0078772020-03-04 21:23:16 +02002319 if (dut->sae_pwe == SAE_PWE_LOOP && get_param(cmd, "PasswordId"))
2320 sae_pwe = 3;
2321 else if (dut->sae_pwe == SAE_PWE_LOOP)
Jouni Malinen11e55212019-11-22 21:46:59 +02002322 sae_pwe = 0;
2323 else if (dut->sae_pwe == SAE_PWE_H2E)
2324 sae_pwe = 1;
2325 else if (dut->sae_h2e_default)
2326 sae_pwe = 2;
2327 snprintf(buf, sizeof(buf), "SET sae_pwe %d", sae_pwe);
2328 if (sae_pwe >= 0 && wpa_command(ifname, buf) != 0)
2329 return ERROR_SEND_STATUS;
2330
Veerendranath Jakkam0316be12020-06-23 20:11:41 +05302331 val = get_param(cmd, "sae_pk");
2332 if (val && strcmp(val, "0") == 0 &&
2333 set_network(ifname, id, "sae_pk", "2") < 0)
2334 return ERROR_SEND_STATUS;
2335
Veerendranath Jakkama9177042020-08-10 00:14:03 +05302336 val = get_param(cmd, "sae_pk_only");
2337 if (val && strcmp(val, "1") == 0 &&
2338 set_network(ifname, id, "sae_pk", "1") < 0)
2339 return ERROR_SEND_STATUS;
2340
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002341 if (dut->program == PROGRAM_60GHZ && network_mode &&
2342 strcasecmp(network_mode, "PBSS") == 0 &&
2343 set_network(ifname, id, "pbss", "1") < 0)
2344 return -2;
2345
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002346 return 1;
2347}
2348
2349
Jouni Malinen8ac93452019-08-14 15:19:13 +03002350static enum sigma_cmd_result set_trust_root_system(struct sigma_dut *dut,
2351 struct sigma_conn *conn,
2352 const char *ifname, int id)
2353{
2354 char buf[200];
2355
2356 snprintf(buf, sizeof(buf), "%s/certs", sigma_cert_path);
2357 if (!file_exists(buf))
2358 strlcpy(buf, "/system/etc/security/cacerts", sizeof(buf));
2359 if (!file_exists(buf))
2360 strlcpy(buf, "/etc/ssl/certs", sizeof(buf));
2361 if (!file_exists(buf)) {
2362 char msg[300];
2363
2364 snprintf(msg, sizeof(msg),
2365 "ErrorCode,trustedRootCA system store (%s) not found",
2366 buf);
2367 send_resp(dut, conn, SIGMA_ERROR, msg);
2368 return STATUS_SENT_ERROR;
2369 }
2370
2371 if (set_network_quoted(ifname, id, "ca_path", buf) < 0)
2372 return ERROR_SEND_STATUS;
2373
2374 return SUCCESS_SEND_STATUS;
2375}
2376
2377
2378static enum sigma_cmd_result set_trust_root(struct sigma_dut *dut,
2379 struct sigma_conn *conn,
2380 const char *ifname, int id,
2381 const char *val)
2382{
2383 char buf[200];
2384#ifdef ANDROID
2385 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
2386 int length;
2387#endif /* ANDROID */
2388
2389 if (strcmp(val, "DEFAULT") == 0)
2390 return set_trust_root_system(dut, conn, ifname, id);
2391
2392#ifdef ANDROID
2393 snprintf(buf, sizeof(buf), "CACERT_%s", val);
2394 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
2395 if (length > 0) {
2396 sigma_dut_print(dut, DUT_MSG_INFO, "Use Android keystore [%s]",
2397 buf);
2398 snprintf(buf, sizeof(buf), "keystore://CACERT_%s", val);
2399 goto ca_cert_selected;
2400 }
2401#endif /* ANDROID */
2402
2403 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
2404#ifdef __linux__
2405 if (!file_exists(buf)) {
2406 char msg[300];
2407
2408 snprintf(msg, sizeof(msg),
2409 "ErrorCode,trustedRootCA file (%s) not found", buf);
2410 send_resp(dut, conn, SIGMA_ERROR, msg);
2411 return STATUS_SENT_ERROR;
2412 }
2413#endif /* __linux__ */
2414#ifdef ANDROID
2415ca_cert_selected:
2416#endif /* ANDROID */
2417 if (set_network_quoted(ifname, id, "ca_cert", buf) < 0)
2418 return ERROR_SEND_STATUS;
2419
2420 return SUCCESS_SEND_STATUS;
2421}
2422
2423
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002424static int set_eap_common(struct sigma_dut *dut, struct sigma_conn *conn,
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302425 const char *ifname, int username_identity,
2426 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002427{
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002428 const char *val, *alg, *akm, *trust_root, *domain, *domain_suffix;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002429 int id;
Jouni Malinen53264f62019-05-03 13:04:40 +03002430 char buf[200], buf2[300];
Jouni Malinen8179fee2019-03-28 03:19:47 +02002431 int erp = 0;
Jouni Malinen8ac93452019-08-14 15:19:13 +03002432 enum sigma_cmd_result res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002433
2434 id = set_wpa_common(dut, conn, ifname, cmd);
2435 if (id < 0)
2436 return id;
2437
2438 val = get_param(cmd, "keyMgmtType");
2439 alg = get_param(cmd, "micAlg");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302440 akm = get_param(cmd, "AKMSuiteType");
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002441 trust_root = get_param(cmd, "trustedRootCA");
2442 domain = get_param(cmd, "Domain");
2443 domain_suffix = get_param(cmd, "DomainSuffix");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002444
Jouni Malinenad395a22017-09-01 21:13:46 +03002445 if (val && strcasecmp(val, "SuiteB") == 0) {
2446 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SUITE-B-192") <
2447 0)
2448 return -2;
2449 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002450 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SHA256") < 0)
2451 return -2;
2452 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
2453 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
2454 return -2;
2455 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
2456 if (set_network(ifname, id, "key_mgmt", "FT-EAP") < 0)
2457 return -2;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002458 } else if (!akm &&
2459 ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
2460 dut->sta_pmf == STA_PMF_REQUIRED)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002461 if (set_network(ifname, id, "key_mgmt",
2462 "WPA-EAP WPA-EAP-SHA256") < 0)
2463 return -2;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302464 } else if (akm && atoi(akm) == 14) {
2465 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
2466 dut->sta_pmf == STA_PMF_REQUIRED) {
2467 if (set_network(ifname, id, "key_mgmt",
2468 "WPA-EAP-SHA256 FILS-SHA256") < 0)
2469 return -2;
2470 } else {
2471 if (set_network(ifname, id, "key_mgmt",
2472 "WPA-EAP FILS-SHA256") < 0)
2473 return -2;
2474 }
2475
Jouni Malinen8179fee2019-03-28 03:19:47 +02002476 erp = 1;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302477 } else if (akm && atoi(akm) == 15) {
2478 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
2479 dut->sta_pmf == STA_PMF_REQUIRED) {
2480 if (set_network(ifname, id, "key_mgmt",
2481 "WPA-EAP-SHA256 FILS-SHA384") < 0)
2482 return -2;
2483 } else {
2484 if (set_network(ifname, id, "key_mgmt",
2485 "WPA-EAP FILS-SHA384") < 0)
2486 return -2;
2487 }
2488
Jouni Malinen8179fee2019-03-28 03:19:47 +02002489 erp = 1;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002490 } else if (!akm && dut->sta_pmf == STA_PMF_OPTIONAL) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002491 if (set_network(ifname, id, "key_mgmt",
2492 "WPA-EAP WPA-EAP-SHA256") < 0)
2493 return -2;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002494 } else if (!akm) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002495 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
2496 return -2;
2497 }
2498
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002499 if (trust_root) {
2500 if (strcmp(trust_root, "DEFAULT") == 0 && !domain &&
2501 !domain_suffix) {
2502 send_resp(dut, conn, SIGMA_ERROR,
2503 "errorCode,trustRootCA DEFAULT used without specifying Domain or DomainSuffix");
2504 return STATUS_SENT_ERROR;
2505 }
2506 res = set_trust_root(dut, conn, ifname, id, trust_root);
Jouni Malinen8ac93452019-08-14 15:19:13 +03002507 if (res != SUCCESS_SEND_STATUS)
2508 return res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002509 }
2510
Jouni Malinen53264f62019-05-03 13:04:40 +03002511 val = get_param(cmd, "ServerCert");
2512 if (val) {
2513 FILE *f;
2514 char *result = NULL, *pos;
2515
2516 snprintf(buf, sizeof(buf), "%s/%s.sha256", sigma_cert_path,
2517 val);
2518 f = fopen(buf, "r");
2519 if (f) {
2520 result = fgets(buf, sizeof(buf), f);
2521 fclose(f);
2522 }
2523 if (!result) {
2524 snprintf(buf2, sizeof(buf2),
2525 "ErrorCode,ServerCert hash could not be read from %s",
2526 buf);
2527 send_resp(dut, conn, SIGMA_ERROR, buf2);
2528 return STATUS_SENT_ERROR;
2529 }
2530 pos = strchr(buf, '\n');
2531 if (pos)
2532 *pos = '\0';
Jouni Malinen0572a742020-10-08 13:53:25 +03002533 pos = strchr(buf, '\r');
2534 if (pos)
2535 *pos = '\0';
Jouni Malinen53264f62019-05-03 13:04:40 +03002536 snprintf(buf2, sizeof(buf2), "hash://server/sha256/%s", buf);
2537 if (set_network_quoted(ifname, id, "ca_cert", buf2) < 0)
2538 return ERROR_SEND_STATUS;
Jouni Malinen29108dc2019-06-13 23:42:11 +03002539
2540 snprintf(buf, sizeof(buf), "%s/%s.tod", sigma_cert_path, val);
2541 if (file_exists(buf)) {
2542 sigma_dut_print(dut, DUT_MSG_DEBUG,
2543 "TOD policy enabled for the configured ServerCert hash");
2544 dut->sta_tod_policy = 1;
2545 }
Jouni Malinen53264f62019-05-03 13:04:40 +03002546 }
2547
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002548 if (domain &&
2549 set_network_quoted(ifname, id, "domain_match", domain) < 0)
Jouni Malinen96f84b02019-05-03 12:32:56 +03002550 return ERROR_SEND_STATUS;
2551
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002552 if (domain_suffix &&
2553 set_network_quoted(ifname, id, "domain_suffix_match",
2554 domain_suffix) < 0)
Jouni Malinen96f84b02019-05-03 12:32:56 +03002555 return ERROR_SEND_STATUS;
2556
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302557 if (username_identity) {
2558 val = get_param(cmd, "username");
2559 if (val) {
2560 if (set_network_quoted(ifname, id, "identity", val) < 0)
2561 return -2;
2562 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002563
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302564 val = get_param(cmd, "password");
2565 if (val) {
2566 if (set_network_quoted(ifname, id, "password", val) < 0)
2567 return -2;
2568 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002569 }
2570
Jouni Malinen8179fee2019-03-28 03:19:47 +02002571 if (dut->akm_values &
2572 ((1 << AKM_FILS_SHA256) |
2573 (1 << AKM_FILS_SHA384) |
2574 (1 << AKM_FT_FILS_SHA256) |
2575 (1 << AKM_FT_FILS_SHA384)))
2576 erp = 1;
2577 if (erp && set_network(ifname, id, "erp", "1") < 0)
2578 return ERROR_SEND_STATUS;
2579
Jouni Malinen134fe3c2019-06-12 04:16:49 +03002580 dut->sta_associate_wait_connect = 1;
2581
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002582 return id;
2583}
2584
2585
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002586static int set_tls_cipher(const char *ifname, int id, const char *cipher)
2587{
2588 const char *val;
2589
2590 if (!cipher)
2591 return 0;
2592
2593 if (strcasecmp(cipher, "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384") == 0)
2594 val = "ECDHE-ECDSA-AES256-GCM-SHA384";
2595 else if (strcasecmp(cipher,
2596 "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
2597 val = "ECDHE-RSA-AES256-GCM-SHA384";
2598 else if (strcasecmp(cipher, "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
2599 val = "DHE-RSA-AES256-GCM-SHA384";
2600 else if (strcasecmp(cipher,
2601 "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256") == 0)
2602 val = "ECDHE-ECDSA-AES128-GCM-SHA256";
2603 else
2604 return -1;
2605
2606 /* Need to clear phase1="tls_suiteb=1" to allow cipher enforcement */
2607 set_network_quoted(ifname, id, "phase1", "");
2608
2609 return set_network_quoted(ifname, id, "openssl_ciphers", val);
2610}
2611
2612
Jouni Malinenf7222712019-06-13 01:50:21 +03002613static enum sigma_cmd_result cmd_sta_set_eaptls(struct sigma_dut *dut,
2614 struct sigma_conn *conn,
2615 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002616{
2617 const char *intf = get_param(cmd, "Interface");
2618 const char *ifname, *val;
2619 int id;
2620 char buf[200];
2621#ifdef ANDROID
2622 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
2623 int length;
2624 int jb_or_newer = 0;
2625 char prop[PROPERTY_VALUE_MAX];
2626#endif /* ANDROID */
2627
2628 if (intf == NULL)
2629 return -1;
2630
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002631 if (strcmp(intf, get_main_ifname(dut)) == 0)
2632 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002633 else
2634 ifname = intf;
2635
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302636 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002637 if (id < 0)
2638 return id;
2639
2640 if (set_network(ifname, id, "eap", "TLS") < 0)
2641 return -2;
2642
Pradeep Reddy POTTETI9f6c2132016-05-05 16:28:19 +05302643 if (!get_param(cmd, "username") &&
2644 set_network_quoted(ifname, id, "identity",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002645 "wifi-user@wifilabs.local") < 0)
2646 return -2;
2647
2648 val = get_param(cmd, "clientCertificate");
2649 if (val == NULL)
2650 return -1;
2651#ifdef ANDROID
2652 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2653 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
2654 if (length < 0) {
2655 /*
2656 * JB started reporting keystore type mismatches, so retry with
2657 * the GET_PUBKEY command if the generic GET fails.
2658 */
2659 length = android_keystore_get(ANDROID_KEYSTORE_GET_PUBKEY,
2660 buf, kvalue);
2661 }
2662
2663 if (property_get("ro.build.version.release", prop, NULL) != 0) {
2664 sigma_dut_print(dut, DUT_MSG_DEBUG, "Android release %s", prop);
2665 if (strncmp(prop, "4.0", 3) != 0)
2666 jb_or_newer = 1;
2667 } else
2668 jb_or_newer = 1; /* assume newer */
2669
2670 if (jb_or_newer && length > 0) {
2671 sigma_dut_print(dut, DUT_MSG_INFO,
2672 "Use Android keystore [%s]", buf);
2673 if (set_network(ifname, id, "engine", "1") < 0)
2674 return -2;
2675 if (set_network_quoted(ifname, id, "engine_id", "keystore") < 0)
2676 return -2;
2677 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2678 if (set_network_quoted(ifname, id, "key_id", buf) < 0)
2679 return -2;
2680 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2681 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2682 return -2;
2683 return 1;
2684 } else if (length > 0) {
2685 sigma_dut_print(dut, DUT_MSG_INFO,
2686 "Use Android keystore [%s]", buf);
2687 snprintf(buf, sizeof(buf), "keystore://USRPKEY_%s", val);
2688 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2689 return -2;
2690 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2691 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2692 return -2;
2693 return 1;
2694 }
2695#endif /* ANDROID */
2696
2697 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
2698#ifdef __linux__
2699 if (!file_exists(buf)) {
2700 char msg[300];
2701 snprintf(msg, sizeof(msg), "ErrorCode,clientCertificate file "
2702 "(%s) not found", buf);
2703 send_resp(dut, conn, SIGMA_ERROR, msg);
2704 return -3;
2705 }
2706#endif /* __linux__ */
2707 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2708 return -2;
2709 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2710 return -2;
2711
2712 if (set_network_quoted(ifname, id, "private_key_passwd", "wifi") < 0)
2713 return -2;
2714
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002715 val = get_param(cmd, "keyMgmtType");
2716 if (val && strcasecmp(val, "SuiteB") == 0) {
2717 val = get_param(cmd, "CertType");
2718 if (val && strcasecmp(val, "RSA") == 0) {
2719 if (set_network_quoted(ifname, id, "phase1",
2720 "tls_suiteb=1") < 0)
2721 return -2;
2722 } else {
2723 if (set_network_quoted(ifname, id, "openssl_ciphers",
2724 "SUITEB192") < 0)
2725 return -2;
2726 }
2727
2728 val = get_param(cmd, "TLSCipher");
2729 if (set_tls_cipher(ifname, id, val) < 0) {
2730 send_resp(dut, conn, SIGMA_ERROR,
2731 "ErrorCode,Unsupported TLSCipher value");
2732 return -3;
2733 }
2734 }
2735
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002736 return 1;
2737}
2738
2739
Jouni Malinenf7222712019-06-13 01:50:21 +03002740static enum sigma_cmd_result cmd_sta_set_eapttls(struct sigma_dut *dut,
2741 struct sigma_conn *conn,
2742 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002743{
2744 const char *intf = get_param(cmd, "Interface");
2745 const char *ifname;
2746 int id;
2747
2748 if (intf == NULL)
2749 return -1;
2750
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002751 if (strcmp(intf, get_main_ifname(dut)) == 0)
2752 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002753 else
2754 ifname = intf;
2755
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302756 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002757 if (id < 0)
2758 return id;
2759
2760 if (set_network(ifname, id, "eap", "TTLS") < 0) {
2761 send_resp(dut, conn, SIGMA_ERROR,
2762 "errorCode,Failed to set TTLS method");
2763 return 0;
2764 }
2765
2766 if (set_network_quoted(ifname, id, "phase2", "auth=MSCHAPV2") < 0) {
2767 send_resp(dut, conn, SIGMA_ERROR,
2768 "errorCode,Failed to set MSCHAPv2 for TTLS Phase 2");
2769 return 0;
2770 }
2771
2772 return 1;
2773}
2774
2775
Jouni Malinenf7222712019-06-13 01:50:21 +03002776static enum sigma_cmd_result cmd_sta_set_eapsim(struct sigma_dut *dut,
2777 struct sigma_conn *conn,
2778 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002779{
2780 const char *intf = get_param(cmd, "Interface");
2781 const char *ifname;
2782 int id;
2783
2784 if (intf == NULL)
2785 return -1;
2786
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002787 if (strcmp(intf, get_main_ifname(dut)) == 0)
2788 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002789 else
2790 ifname = intf;
2791
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302792 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002793 if (id < 0)
2794 return id;
2795
2796 if (set_network(ifname, id, "eap", "SIM") < 0)
2797 return -2;
2798
2799 return 1;
2800}
2801
2802
Jouni Malinenf7222712019-06-13 01:50:21 +03002803static enum sigma_cmd_result cmd_sta_set_peap(struct sigma_dut *dut,
2804 struct sigma_conn *conn,
2805 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002806{
2807 const char *intf = get_param(cmd, "Interface");
2808 const char *ifname, *val;
2809 int id;
2810 char buf[100];
2811
2812 if (intf == NULL)
2813 return -1;
2814
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002815 if (strcmp(intf, get_main_ifname(dut)) == 0)
2816 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002817 else
2818 ifname = intf;
2819
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302820 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002821 if (id < 0)
2822 return id;
2823
2824 if (set_network(ifname, id, "eap", "PEAP") < 0)
2825 return -2;
2826
2827 val = get_param(cmd, "innerEAP");
2828 if (val) {
2829 if (strcasecmp(val, "MSCHAPv2") == 0) {
2830 if (set_network_quoted(ifname, id, "phase2",
2831 "auth=MSCHAPV2") < 0)
2832 return -2;
2833 } else if (strcasecmp(val, "GTC") == 0) {
2834 if (set_network_quoted(ifname, id, "phase2",
2835 "auth=GTC") < 0)
2836 return -2;
2837 } else
2838 return -1;
2839 }
2840
2841 val = get_param(cmd, "peapVersion");
2842 if (val) {
2843 int ver = atoi(val);
2844 if (ver < 0 || ver > 1)
2845 return -1;
2846 snprintf(buf, sizeof(buf), "peapver=%d", ver);
2847 if (set_network_quoted(ifname, id, "phase1", buf) < 0)
2848 return -2;
2849 }
2850
2851 return 1;
2852}
2853
2854
Jouni Malinenf7222712019-06-13 01:50:21 +03002855static enum sigma_cmd_result cmd_sta_set_eapfast(struct sigma_dut *dut,
2856 struct sigma_conn *conn,
2857 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002858{
2859 const char *intf = get_param(cmd, "Interface");
2860 const char *ifname, *val;
2861 int id;
2862 char buf[100];
2863
2864 if (intf == NULL)
2865 return -1;
2866
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002867 if (strcmp(intf, get_main_ifname(dut)) == 0)
2868 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002869 else
2870 ifname = intf;
2871
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302872 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002873 if (id < 0)
2874 return id;
2875
2876 if (set_network(ifname, id, "eap", "FAST") < 0)
2877 return -2;
2878
2879 val = get_param(cmd, "innerEAP");
2880 if (val) {
2881 if (strcasecmp(val, "MSCHAPV2") == 0) {
2882 if (set_network_quoted(ifname, id, "phase2",
2883 "auth=MSCHAPV2") < 0)
2884 return -2;
2885 } else if (strcasecmp(val, "GTC") == 0) {
2886 if (set_network_quoted(ifname, id, "phase2",
2887 "auth=GTC") < 0)
2888 return -2;
2889 } else
2890 return -1;
2891 }
2892
2893 val = get_param(cmd, "validateServer");
2894 if (val) {
2895 /* TODO */
2896 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored EAP-FAST "
2897 "validateServer=%s", val);
2898 }
2899
2900 val = get_param(cmd, "pacFile");
2901 if (val) {
2902 snprintf(buf, sizeof(buf), "blob://%s", val);
2903 if (set_network_quoted(ifname, id, "pac_file", buf) < 0)
2904 return -2;
2905 }
2906
2907 if (set_network_quoted(ifname, id, "phase1", "fast_provisioning=2") <
2908 0)
2909 return -2;
2910
2911 return 1;
2912}
2913
2914
Jouni Malinenf7222712019-06-13 01:50:21 +03002915static enum sigma_cmd_result cmd_sta_set_eapaka(struct sigma_dut *dut,
2916 struct sigma_conn *conn,
2917 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002918{
2919 const char *intf = get_param(cmd, "Interface");
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302920 const char *username = get_param(cmd, "Username");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002921 const char *ifname;
2922 int id;
2923
2924 if (intf == NULL)
2925 return -1;
2926
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002927 if (strcmp(intf, get_main_ifname(dut)) == 0)
2928 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002929 else
2930 ifname = intf;
2931
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302932 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002933 if (id < 0)
2934 return id;
2935
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302936 /* RFC 5448: EAP-AKA' MUST use the leading character "6" (ASCII 36
2937 * hexadecimal).
2938 */
2939 if (username && username[0] == '6') {
2940 if (set_network(ifname, id, "eap", "AKA'") < 0)
2941 return -2;
2942 } else if (set_network(ifname, id, "eap", "AKA") < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002943 return -2;
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302944 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002945
2946 return 1;
2947}
2948
2949
Jouni Malinenf7222712019-06-13 01:50:21 +03002950static enum sigma_cmd_result cmd_sta_set_eapakaprime(struct sigma_dut *dut,
2951 struct sigma_conn *conn,
2952 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002953{
2954 const char *intf = get_param(cmd, "Interface");
2955 const char *ifname;
2956 int id;
2957
2958 if (intf == NULL)
2959 return -1;
2960
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002961 if (strcmp(intf, get_main_ifname(dut)) == 0)
2962 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002963 else
2964 ifname = intf;
2965
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302966 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002967 if (id < 0)
2968 return id;
2969
2970 if (set_network(ifname, id, "eap", "AKA'") < 0)
2971 return -2;
2972
2973 return 1;
2974}
2975
2976
2977static int sta_set_open(struct sigma_dut *dut, struct sigma_conn *conn,
2978 struct sigma_cmd *cmd)
2979{
2980 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002981 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002982 const char *ifname;
2983 int id;
2984
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002985 if (strcmp(intf, get_main_ifname(dut)) == 0)
2986 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002987 else
2988 ifname = intf;
2989
2990 id = add_network_common(dut, conn, ifname, cmd);
2991 if (id < 0)
2992 return id;
2993
2994 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
2995 return -2;
2996
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002997 if (dut->program == PROGRAM_60GHZ && network_mode &&
2998 strcasecmp(network_mode, "PBSS") == 0 &&
2999 set_network(ifname, id, "pbss", "1") < 0)
3000 return -2;
3001
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003002 return 1;
3003}
3004
3005
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003006static enum sigma_cmd_result sta_set_owe(struct sigma_dut *dut,
3007 struct sigma_conn *conn,
3008 struct sigma_cmd *cmd)
Jouni Malinen47dcc952017-10-09 16:43:24 +03003009{
3010 const char *intf = get_param(cmd, "Interface");
3011 const char *ifname, *val;
3012 int id;
3013
3014 if (intf == NULL)
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003015 return INVALID_SEND_STATUS;
Jouni Malinen47dcc952017-10-09 16:43:24 +03003016
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003017 if (strcmp(intf, get_main_ifname(dut)) == 0)
3018 ifname = get_station_ifname(dut);
Jouni Malinen47dcc952017-10-09 16:43:24 +03003019 else
3020 ifname = intf;
3021
3022 id = set_wpa_common(dut, conn, ifname, cmd);
3023 if (id < 0)
3024 return id;
3025
3026 if (set_network(ifname, id, "key_mgmt", "OWE") < 0)
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003027 return ERROR_SEND_STATUS;
Jouni Malinen47dcc952017-10-09 16:43:24 +03003028
Hu Wangdd5eed22020-07-16 12:18:03 +08003029 if (dut->owe_ptk_workaround &&
3030 set_network(ifname, id, "owe_ptk_workaround", "1") < 0) {
3031 sigma_dut_print(dut, DUT_MSG_ERROR,
3032 "Failed to set owe_ptk_workaround to 1");
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003033 return ERROR_SEND_STATUS;
Hu Wangdd5eed22020-07-16 12:18:03 +08003034 }
3035
Jouni Malinen47dcc952017-10-09 16:43:24 +03003036 val = get_param(cmd, "ECGroupID");
Jouni Malinenfac9cad2017-10-10 18:35:55 +03003037 if (val && strcmp(val, "0") == 0) {
3038 if (wpa_command(ifname,
3039 "VENDOR_ELEM_ADD 13 ff23200000783590fb7440e03d5b3b33911f86affdcc6b4411b707846ac4ff08ddc8831ccd") != 0) {
3040 sigma_dut_print(dut, DUT_MSG_ERROR,
3041 "Failed to set OWE DH Param element override");
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003042 return ERROR_SEND_STATUS;
Jouni Malinenfac9cad2017-10-10 18:35:55 +03003043 }
Hu Wangdd5eed22020-07-16 12:18:03 +08003044 } else if (val && set_network(ifname, id, "owe_group", val) < 0) {
Jouni Malinen47dcc952017-10-09 16:43:24 +03003045 sigma_dut_print(dut, DUT_MSG_ERROR,
Hu Wang6010ce72020-03-05 19:33:53 +08003046 "Failed to set owe_group");
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003047 return ERROR_SEND_STATUS;
Jouni Malinen47dcc952017-10-09 16:43:24 +03003048 }
3049
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003050 return SUCCESS_SEND_STATUS;
Jouni Malinen47dcc952017-10-09 16:43:24 +03003051}
3052
3053
Jouni Malinenf7222712019-06-13 01:50:21 +03003054static enum sigma_cmd_result cmd_sta_set_security(struct sigma_dut *dut,
3055 struct sigma_conn *conn,
3056 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003057{
3058 const char *type = get_param(cmd, "Type");
3059
3060 if (type == NULL) {
3061 send_resp(dut, conn, SIGMA_ERROR,
3062 "ErrorCode,Missing Type argument");
3063 return 0;
3064 }
3065
3066 if (strcasecmp(type, "OPEN") == 0)
3067 return sta_set_open(dut, conn, cmd);
Jouni Malinen47dcc952017-10-09 16:43:24 +03003068 if (strcasecmp(type, "OWE") == 0)
3069 return sta_set_owe(dut, conn, cmd);
Jouni Malinen992a81e2017-08-22 13:57:47 +03003070 if (strcasecmp(type, "PSK") == 0 ||
Jouni Malinen0ab50f42017-08-31 01:34:59 +03003071 strcasecmp(type, "PSK-SAE") == 0 ||
Jouni Malinen992a81e2017-08-22 13:57:47 +03003072 strcasecmp(type, "SAE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003073 return cmd_sta_set_psk(dut, conn, cmd);
3074 if (strcasecmp(type, "EAPTLS") == 0)
3075 return cmd_sta_set_eaptls(dut, conn, cmd);
3076 if (strcasecmp(type, "EAPTTLS") == 0)
3077 return cmd_sta_set_eapttls(dut, conn, cmd);
3078 if (strcasecmp(type, "EAPPEAP") == 0)
3079 return cmd_sta_set_peap(dut, conn, cmd);
3080 if (strcasecmp(type, "EAPSIM") == 0)
3081 return cmd_sta_set_eapsim(dut, conn, cmd);
3082 if (strcasecmp(type, "EAPFAST") == 0)
3083 return cmd_sta_set_eapfast(dut, conn, cmd);
3084 if (strcasecmp(type, "EAPAKA") == 0)
3085 return cmd_sta_set_eapaka(dut, conn, cmd);
3086 if (strcasecmp(type, "EAPAKAPRIME") == 0)
3087 return cmd_sta_set_eapakaprime(dut, conn, cmd);
Amarnath Hullur Subramanyam81b11cd2018-01-30 19:07:17 -08003088 if (strcasecmp(type, "wep") == 0)
3089 return cmd_sta_set_encryption(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003090
3091 send_resp(dut, conn, SIGMA_ERROR,
3092 "ErrorCode,Unsupported Type value");
3093 return 0;
3094}
3095
3096
3097int ath6kl_client_uapsd(struct sigma_dut *dut, const char *intf, int uapsd)
3098{
3099#ifdef __linux__
3100 /* special handling for ath6kl */
3101 char path[128], fname[128], *pos;
3102 ssize_t res;
3103 FILE *f;
3104
Jouni Malinene39cd562019-05-29 23:39:56 +03003105 res = snprintf(fname, sizeof(fname), "/sys/class/net/%s/phy80211",
3106 intf);
3107 if (res < 0 || res >= sizeof(fname))
3108 return 0;
3109 res = readlink(fname, path, sizeof(path));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003110 if (res < 0)
3111 return 0; /* not ath6kl */
3112
3113 if (res >= (int) sizeof(path))
3114 res = sizeof(path) - 1;
3115 path[res] = '\0';
3116 pos = strrchr(path, '/');
3117 if (pos == NULL)
3118 pos = path;
3119 else
3120 pos++;
Jouni Malinen77dda642020-01-07 11:21:55 +02003121 res = snprintf(fname, sizeof(fname),
3122 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
3123 "create_qos", pos);
3124 if (res < 0 || res >= sizeof(fname) || !file_exists(fname))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003125 return 0; /* not ath6kl */
3126
3127 if (uapsd) {
3128 f = fopen(fname, "w");
3129 if (f == NULL)
3130 return -1;
3131
3132 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl create_qos");
3133 fprintf(f, "4 2 2 1 2 9999999 9999999 9999999 7777777 0 4 "
3134 "45000 200 56789000 56789000 5678900 0 0 9999999 "
3135 "20000 0\n");
3136 fclose(f);
3137 } else {
Jouni Malinen77dda642020-01-07 11:21:55 +02003138 res = snprintf(fname, sizeof(fname),
3139 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
3140 "delete_qos", pos);
3141 if (res < 0 || res >= sizeof(fname))
3142 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003143
3144 f = fopen(fname, "w");
3145 if (f == NULL)
3146 return -1;
3147
3148 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl delete_qos");
3149 fprintf(f, "2 4\n");
3150 fclose(f);
3151 }
3152#endif /* __linux__ */
3153
3154 return 0;
3155}
3156
3157
Jouni Malinenf7222712019-06-13 01:50:21 +03003158static enum sigma_cmd_result cmd_sta_set_uapsd(struct sigma_dut *dut,
3159 struct sigma_conn *conn,
3160 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003161{
3162 const char *intf = get_param(cmd, "Interface");
3163 /* const char *ssid = get_param(cmd, "ssid"); */
3164 const char *val;
3165 int max_sp_len = 4;
3166 int ac_be = 1, ac_bk = 1, ac_vi = 1, ac_vo = 1;
3167 char buf[100];
3168 int ret1, ret2;
3169
3170 val = get_param(cmd, "maxSPLength");
3171 if (val) {
3172 max_sp_len = atoi(val);
3173 if (max_sp_len != 0 && max_sp_len != 1 && max_sp_len != 2 &&
3174 max_sp_len != 4)
3175 return -1;
3176 }
3177
3178 val = get_param(cmd, "acBE");
3179 if (val)
3180 ac_be = atoi(val);
3181
3182 val = get_param(cmd, "acBK");
3183 if (val)
3184 ac_bk = atoi(val);
3185
3186 val = get_param(cmd, "acVI");
3187 if (val)
3188 ac_vi = atoi(val);
3189
3190 val = get_param(cmd, "acVO");
3191 if (val)
3192 ac_vo = atoi(val);
3193
3194 dut->client_uapsd = ac_be || ac_bk || ac_vi || ac_vo;
3195
3196 snprintf(buf, sizeof(buf), "P2P_SET client_apsd %d,%d,%d,%d;%d",
3197 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
3198 ret1 = wpa_command(intf, buf);
3199
3200 snprintf(buf, sizeof(buf), "SET uapsd %d,%d,%d,%d;%d",
3201 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
3202 ret2 = wpa_command(intf, buf);
3203
3204 if (ret1 && ret2) {
3205 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to set client mode "
3206 "UAPSD parameters.");
3207 return -2;
3208 }
3209
3210 if (ath6kl_client_uapsd(dut, intf, dut->client_uapsd) < 0) {
3211 send_resp(dut, conn, SIGMA_ERROR,
3212 "ErrorCode,Failed to set ath6kl QoS parameters");
3213 return 0;
3214 }
3215
3216 return 1;
3217}
3218
3219
Jouni Malinenf7222712019-06-13 01:50:21 +03003220static enum sigma_cmd_result cmd_sta_set_wmm(struct sigma_dut *dut,
3221 struct sigma_conn *conn,
3222 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003223{
3224 char buf[1000];
3225 const char *intf = get_param(cmd, "Interface");
3226 const char *grp = get_param(cmd, "Group");
3227 const char *act = get_param(cmd, "Action");
3228 const char *tid = get_param(cmd, "Tid");
3229 const char *dir = get_param(cmd, "Direction");
3230 const char *psb = get_param(cmd, "Psb");
3231 const char *up = get_param(cmd, "Up");
3232 const char *fixed = get_param(cmd, "Fixed");
3233 const char *size = get_param(cmd, "Size");
3234 const char *msize = get_param(cmd, "Maxsize");
3235 const char *minsi = get_param(cmd, "Min_srvc_intrvl");
3236 const char *maxsi = get_param(cmd, "Max_srvc_intrvl");
3237 const char *inact = get_param(cmd, "Inactivity");
3238 const char *sus = get_param(cmd, "Suspension");
3239 const char *mindr = get_param(cmd, "Mindatarate");
3240 const char *meandr = get_param(cmd, "Meandatarate");
3241 const char *peakdr = get_param(cmd, "Peakdatarate");
3242 const char *phyrate = get_param(cmd, "Phyrate");
3243 const char *burstsize = get_param(cmd, "Burstsize");
3244 const char *sba = get_param(cmd, "Sba");
3245 int direction;
3246 int handle;
Peng Xu93319622017-10-04 17:58:16 -07003247 float sba_fv = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003248 int fixed_int;
3249 int psb_ts;
3250
3251 if (intf == NULL || grp == NULL || act == NULL )
3252 return -1;
3253
3254 if (strcasecmp(act, "addts") == 0) {
3255 if (tid == NULL || dir == NULL || psb == NULL ||
3256 up == NULL || fixed == NULL || size == NULL)
3257 return -1;
3258
3259 /*
3260 * Note: Sigma CAPI spec lists uplink, downlink, and bidi as the
3261 * possible values, but WMM-AC and V-E test scripts use "UP,
3262 * "DOWN", and "BIDI".
3263 */
3264 if (strcasecmp(dir, "uplink") == 0 ||
3265 strcasecmp(dir, "up") == 0) {
3266 direction = 0;
3267 } else if (strcasecmp(dir, "downlink") == 0 ||
3268 strcasecmp(dir, "down") == 0) {
3269 direction = 1;
3270 } else if (strcasecmp(dir, "bidi") == 0) {
3271 direction = 2;
3272 } else {
3273 sigma_dut_print(dut, DUT_MSG_ERROR,
3274 "Direction %s not supported", dir);
3275 return -1;
3276 }
3277
3278 if (strcasecmp(psb, "legacy") == 0) {
3279 psb_ts = 0;
3280 } else if (strcasecmp(psb, "uapsd") == 0) {
3281 psb_ts = 1;
3282 } else {
3283 sigma_dut_print(dut, DUT_MSG_ERROR,
3284 "PSB %s not supported", psb);
3285 return -1;
3286 }
3287
3288 if (atoi(tid) < 0 || atoi(tid) > 7) {
3289 sigma_dut_print(dut, DUT_MSG_ERROR,
3290 "TID %s not supported", tid);
3291 return -1;
3292 }
3293
3294 if (strcasecmp(fixed, "true") == 0) {
3295 fixed_int = 1;
3296 } else {
3297 fixed_int = 0;
3298 }
3299
Peng Xu93319622017-10-04 17:58:16 -07003300 if (sba)
3301 sba_fv = atof(sba);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003302
3303 dut->dialog_token++;
3304 handle = 7000 + dut->dialog_token;
3305
3306 /*
3307 * size: convert to hex
3308 * maxsi: convert to hex
3309 * mindr: convert to hex
3310 * meandr: convert to hex
3311 * peakdr: convert to hex
3312 * burstsize: convert to hex
3313 * phyrate: convert to hex
3314 * sba: convert to hex with modification
3315 * minsi: convert to integer
3316 * sus: convert to integer
3317 * inact: convert to integer
3318 * maxsi: convert to integer
3319 */
3320
3321 /*
3322 * The Nominal MSDU Size field is 2 octets long and contains an
3323 * unsigned integer that specifies the nominal size, in octets,
3324 * of MSDUs belonging to the traffic under this traffic
3325 * specification and is defined in Figure 16. If the Fixed
3326 * subfield is set to 1, then the size of the MSDU is fixed and
3327 * is indicated by the Size Subfield. If the Fixed subfield is
3328 * set to 0, then the size of the MSDU might not be fixed and
3329 * the Size indicates the nominal MSDU size.
3330 *
3331 * The Surplus Bandwidth Allowance Factor field is 2 octets long
3332 * and specifies the excess allocation of time (and bandwidth)
3333 * over and above the stated rates required to transport an MSDU
3334 * belonging to the traffic in this TSPEC. This field is
3335 * represented as an unsigned binary number with an implicit
3336 * binary point after the leftmost 3 bits. For example, an SBA
3337 * of 1.75 is represented as 0x3800. This field is included to
3338 * account for retransmissions. As such, the value of this field
3339 * must be greater than unity.
3340 */
3341
3342 snprintf(buf, sizeof(buf),
3343 "iwpriv %s addTspec %d %s %d %d %s 0x%X"
3344 " 0x%X 0x%X 0x%X"
3345 " 0x%X 0x%X 0x%X"
3346 " 0x%X %d %d %d %d"
3347 " %d %d",
3348 intf, handle, tid, direction, psb_ts, up,
3349 (unsigned int) ((fixed_int << 15) | atoi(size)),
3350 msize ? atoi(msize) : 0,
3351 mindr ? atoi(mindr) : 0,
3352 meandr ? atoi(meandr) : 0,
3353 peakdr ? atoi(peakdr) : 0,
3354 burstsize ? atoi(burstsize) : 0,
3355 phyrate ? atoi(phyrate) : 0,
3356 sba ? ((unsigned int) (((int) sba_fv << 13) |
3357 (int)((sba_fv - (int) sba_fv) *
3358 8192))) : 0,
3359 minsi ? atoi(minsi) : 0,
3360 sus ? atoi(sus) : 0,
3361 0, 0,
3362 inact ? atoi(inact) : 0,
3363 maxsi ? atoi(maxsi) : 0);
3364
3365 if (system(buf) != 0) {
3366 sigma_dut_print(dut, DUT_MSG_ERROR,
3367 "iwpriv addtspec request failed");
3368 send_resp(dut, conn, SIGMA_ERROR,
3369 "errorCode,Failed to execute addTspec command");
3370 return 0;
3371 }
3372
3373 sigma_dut_print(dut, DUT_MSG_INFO,
3374 "iwpriv addtspec request send");
3375
3376 /* Mapping handle to a TID */
3377 dut->tid_to_handle[atoi(tid)] = handle;
3378 } else if (strcasecmp(act, "delts") == 0) {
3379 if (tid == NULL)
3380 return -1;
3381
3382 if (atoi(tid) < 0 || atoi(tid) > 7) {
3383 sigma_dut_print(dut, DUT_MSG_ERROR,
3384 "TID %s not supported", tid);
3385 send_resp(dut, conn, SIGMA_ERROR,
3386 "errorCode,Unsupported TID");
3387 return 0;
3388 }
3389
3390 handle = dut->tid_to_handle[atoi(tid)];
3391
3392 if (handle < 7000 || handle > 7255) {
3393 /* Invalid handle ie no mapping for that TID */
3394 sigma_dut_print(dut, DUT_MSG_ERROR,
3395 "handle-> %d not found", handle);
3396 }
3397
3398 snprintf(buf, sizeof(buf), "iwpriv %s delTspec %d",
3399 intf, handle);
3400
3401 if (system(buf) != 0) {
3402 sigma_dut_print(dut, DUT_MSG_ERROR,
3403 "iwpriv deltspec request failed");
3404 send_resp(dut, conn, SIGMA_ERROR,
3405 "errorCode,Failed to execute delTspec command");
3406 return 0;
3407 }
3408
3409 sigma_dut_print(dut, DUT_MSG_INFO,
3410 "iwpriv deltspec request send");
3411
3412 dut->tid_to_handle[atoi(tid)] = 0;
3413 } else {
3414 sigma_dut_print(dut, DUT_MSG_ERROR,
3415 "Action type %s not supported", act);
3416 send_resp(dut, conn, SIGMA_ERROR,
3417 "errorCode,Unsupported Action");
3418 return 0;
3419 }
3420
3421 return 1;
3422}
3423
3424
vamsi krishna52e16f92017-08-29 12:37:34 +05303425static int find_network(struct sigma_dut *dut, const char *ssid)
3426{
3427 char list[4096];
3428 char *pos;
3429
3430 sigma_dut_print(dut, DUT_MSG_DEBUG,
3431 "Search for profile based on SSID: '%s'", ssid);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003432 if (wpa_command_resp(get_station_ifname(dut), "LIST_NETWORKS",
vamsi krishna52e16f92017-08-29 12:37:34 +05303433 list, sizeof(list)) < 0)
3434 return -1;
3435 pos = strstr(list, ssid);
3436 if (!pos || pos == list || pos[-1] != '\t' || pos[strlen(ssid)] != '\t')
3437 return -1;
3438
3439 while (pos > list && pos[-1] != '\n')
3440 pos--;
3441 dut->infra_network_id = atoi(pos);
3442 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
3443 return 0;
3444}
3445
3446
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303447/**
3448 * enum qca_sta_helper_config_params - This helper enum defines the config
3449 * parameters which can be delivered to sta.
3450 */
3451enum qca_sta_helper_config_params {
3452 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE */
3453 STA_SET_RSNIE,
3454
3455 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_LDPC */
3456 STA_SET_LDPC,
3457
3458 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_TX_STBC */
3459 STA_SET_TX_STBC,
3460
3461 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_RX_STBC */
3462 STA_SET_RX_STBC,
3463
3464 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_TX_MSDU_AGGREGATION */
3465 STA_SET_TX_MSDU,
3466
3467 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_RX_MSDU_AGGREGATION */
3468 STA_SET_RX_MSDU,
Shivani Baranwal2a572842021-09-16 12:27:15 +05303469
3470 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_CHANNEL_WIDTH */
3471 STA_SET_CHAN_WIDTH,
Shivani Baranwal7aa48602021-09-29 10:53:38 +05303472
3473 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_FT_OVER_DS */
3474 STA_SET_FT_DS,
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303475};
3476
3477
3478static int sta_config_params(struct sigma_dut *dut, const char *intf,
3479 enum qca_sta_helper_config_params config_cmd,
3480 int value)
Sunil Dutt44595082018-02-12 19:41:45 +05303481{
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303482#ifdef NL80211_SUPPORT
Sunil Dutt44595082018-02-12 19:41:45 +05303483 struct nl_msg *msg;
3484 int ret;
3485 struct nlattr *params;
3486 int ifindex;
3487
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303488 ifindex = if_nametoindex(intf);
3489 if (ifindex == 0) {
3490 sigma_dut_print(dut, DUT_MSG_ERROR,
3491 "%s: Interface %s does not exist",
3492 __func__, intf);
3493 return -1;
3494 }
3495
Sunil Dutt44595082018-02-12 19:41:45 +05303496 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
3497 NL80211_CMD_VENDOR)) ||
3498 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
3499 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
3500 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
3501 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) ||
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303502 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)))
3503 goto fail;
3504
3505 switch (config_cmd) {
3506 case STA_SET_RSNIE:
3507 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE, value))
3508 goto fail;
3509 break;
3510 case STA_SET_LDPC:
3511 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_LDPC, value))
3512 goto fail;
3513 break;
3514 case STA_SET_TX_STBC:
3515 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TX_STBC, value))
3516 goto fail;
3517 break;
3518 case STA_SET_RX_STBC:
3519 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_RX_STBC, value))
3520 goto fail;
3521 break;
3522 case STA_SET_TX_MSDU:
3523 if (nla_put_u8(msg,
3524 QCA_WLAN_VENDOR_ATTR_CONFIG_TX_MSDU_AGGREGATION,
3525 value))
3526 goto fail;
3527 break;
3528 case STA_SET_RX_MSDU:
3529 if (nla_put_u8(msg,
3530 QCA_WLAN_VENDOR_ATTR_CONFIG_RX_MSDU_AGGREGATION,
3531 value))
3532 goto fail;
3533 break;
Shivani Baranwal2a572842021-09-16 12:27:15 +05303534 case STA_SET_CHAN_WIDTH:
3535 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_CHANNEL_WIDTH,
3536 value))
3537 goto fail;
3538 break;
Shivani Baranwal7aa48602021-09-29 10:53:38 +05303539 case STA_SET_FT_DS:
3540 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_FT_OVER_DS,
3541 value))
3542 goto fail;
3543 break;
Sunil Dutt44595082018-02-12 19:41:45 +05303544 }
3545 nla_nest_end(msg, params);
3546
3547 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
3548 if (ret) {
3549 sigma_dut_print(dut, DUT_MSG_ERROR,
3550 "%s: err in send_and_recv_msgs, ret=%d",
3551 __func__, ret);
3552 return ret;
3553 }
3554
3555 return 0;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303556
3557fail:
3558 sigma_dut_print(dut, DUT_MSG_ERROR,
3559 "%s: err in adding vendor_cmd and vendor_data",
3560 __func__);
3561 nlmsg_free(msg);
Sunil Dutt44595082018-02-12 19:41:45 +05303562#endif /* NL80211_SUPPORT */
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303563 return -1;
3564}
Sunil Dutt44595082018-02-12 19:41:45 +05303565
3566
Veerendranath Jakkam9ceb3b12021-09-10 03:18:17 +05303567void free_dscp_policy_table(struct sigma_dut *dut)
3568{
3569 struct dscp_policy_data *dscp_policy;
3570
3571 while (dut->dscp_policy_table) {
3572 dscp_policy = dut->dscp_policy_table;
3573 dut->dscp_policy_table = dscp_policy->next;
3574 free(dscp_policy);
3575 }
3576}
3577
3578
3579static int delete_nft_table(struct sigma_dut *dut, const char *table,
3580 const char *ip_type)
3581{
3582 int res;
3583 char cmd[200];
3584
3585 res = snprintf(cmd, sizeof(cmd), "nft delete table %s %s_%s", ip_type,
3586 table, ip_type);
3587 if (snprintf_error(sizeof(cmd), res)) {
3588 sigma_dut_print(dut, DUT_MSG_ERROR,
3589 "Failed to create delete table command");
3590 return -1;
3591 }
3592
3593 if (system(cmd) != 0) {
3594 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run %s", cmd);
3595 return -1;
3596 }
3597
3598 return 0;
3599}
3600
3601
3602static int remove_nft_rule(struct sigma_dut *dut, int policy_id,
3603 enum ip_version ip_ver)
3604{
3605 int res;
3606 char table[50];
3607
3608 res = snprintf(table, sizeof(table), "wifi_%s_dscp_policy_%d",
3609 dut->station_ifname, policy_id);
3610 if (snprintf_error(sizeof(table), res)) {
3611 sigma_dut_print(dut, DUT_MSG_INFO,
3612 "Failed to create table name for policy %d",
3613 policy_id);
3614 return -1;
3615 }
3616
3617
3618 if (ip_ver == IPV6)
3619 return delete_nft_table(dut, table, "ip6");
3620 else
3621 return delete_nft_table(dut, table, "ip");
3622}
3623
3624
3625static int create_nft_table(struct sigma_dut *dut, int policy_id,
3626 const char *table_name, enum ip_version ip_ver)
3627{
3628 char cmd[200];
3629 int res;
3630
3631 res = snprintf(cmd, sizeof(cmd), "nft add table %s %s",
3632 ip_ver == IPV6 ? "ip6" : "ip", table_name);
3633 if (snprintf_error(sizeof(cmd), res)) {
3634 sigma_dut_print(dut, DUT_MSG_INFO,
3635 "Failed to add rule to create table for policy id %d",
3636 policy_id);
3637 return -1;
3638 }
3639
3640 if (system(cmd) != 0) {
3641 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run %s", cmd);
3642 return -1;
3643 }
3644
3645 res = snprintf(cmd, sizeof(cmd),
3646 "nft add chain %s %s OUTPUT { type filter hook output priority 0 \\; }",
3647 ip_ver == IPV6 ? "ip6" : "ip", table_name);
3648 if (snprintf_error(sizeof(cmd), res)) {
3649 sigma_dut_print(dut, DUT_MSG_INFO,
3650 "Failed to add rule to create chain for table = %s",
3651 table_name);
3652 return -1;
3653 }
3654
3655 if (system(cmd) != 0) {
3656 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run %s", cmd);
3657 return -1;
3658 }
3659
3660 return 0;
3661}
3662
3663
3664static char * protocol_to_str(int proto)
3665{
3666 switch (proto) {
3667 case 6:
3668 return "tcp";
3669 case 17:
3670 return "udp";
3671 case 50:
3672 return "esp";
3673 default:
3674 return "unknown";
3675 }
3676}
3677
3678
3679static int remove_dscp_policy(struct sigma_dut *dut, u8 policy_id)
3680{
3681 struct dscp_policy_data *dscp_policy = dut->dscp_policy_table;
3682 struct dscp_policy_data *prev = NULL;
3683
3684 while (dscp_policy) {
3685 if (dscp_policy->policy_id == policy_id)
3686 break;
3687
3688 prev = dscp_policy;
3689 dscp_policy = dscp_policy->next;
3690 }
3691
3692 /*
3693 * Consider remove request for a policy id which does not exist as
3694 * success.
3695 */
3696 if (!dscp_policy)
3697 return 0;
3698
3699 if (strlen(dscp_policy->domain_name) == 0 &&
3700 remove_nft_rule(dut, policy_id, dscp_policy->ip_version))
3701 return -1;
3702
3703 if (prev)
3704 prev->next = dscp_policy->next;
3705 else
3706 dut->dscp_policy_table = dscp_policy->next;
3707
3708 free(dscp_policy);
3709 return 0;
3710}
3711
3712
3713static int add_nft_rule(struct sigma_dut *dut,
3714 struct dscp_policy_data *dscp_policy)
3715{
3716 char nft_cmd[1000], ip[4], table_name[100];
3717 char *pos;
3718 int ret, len, policy_id = dscp_policy->policy_id;
3719 enum ip_version ip_ver = dscp_policy->ip_version;
3720
3721 if (ip_ver == IPV6)
3722 strlcpy(ip, "ip6", sizeof(ip));
3723 else
3724 strlcpy(ip, "ip", sizeof(ip));
3725
3726 ret = snprintf(table_name, sizeof(table_name),
3727 "wifi_%s_dscp_policy_%d_%s",
3728 dut->station_ifname, policy_id, ip);
3729 if (snprintf_error(sizeof(table_name), ret))
3730 return -1;
3731
3732 if (create_nft_table(dut, policy_id, table_name, ip_ver)) {
3733 sigma_dut_print(dut, DUT_MSG_INFO,
3734 "Failed to create nft table");
3735 return -1;
3736 }
3737
3738 pos = nft_cmd;
3739 len = sizeof(nft_cmd);
3740
3741 ret = snprintf(pos, len,
3742 "nft add rule %s %s OUTPUT oifname \"%s\"",
3743 ip, table_name, dut->station_ifname);
3744 if (snprintf_error(len, ret)) {
3745 sigma_dut_print(dut, DUT_MSG_INFO,
3746 "Failed to create nft cmd %s", nft_cmd);
3747 return -1;
3748 }
3749
3750 pos += ret;
3751 len -= ret;
3752
3753 if (strlen(dscp_policy->src_ip)) {
3754 ret = snprintf(pos, len, " %s saddr %s", ip,
3755 dscp_policy->src_ip);
3756 if (snprintf_error(len, ret))
3757 return -1;
3758
3759 pos += ret;
3760 len -= ret;
3761 }
3762
3763 if (strlen(dscp_policy->dst_ip)) {
3764 ret = snprintf(pos, len, " %s daddr %s", ip,
3765 dscp_policy->dst_ip);
3766 if (snprintf_error(len, ret))
3767 return -1;
3768
3769 pos += ret;
3770 len -= ret;
3771 }
3772
3773 if (dscp_policy->src_port) {
3774 ret = snprintf(pos, len, " %s sport %d",
3775 protocol_to_str(dscp_policy->protocol),
3776 dscp_policy->src_port);
3777 if (snprintf_error(len, ret))
3778 return -1;
3779
3780 pos += ret;
3781 len -= ret;
3782 }
3783
3784 if (dscp_policy->dst_port) {
3785 ret = snprintf(pos, len, " %s dport %d",
3786 protocol_to_str(dscp_policy->protocol),
3787 dscp_policy->dst_port);
3788 if (snprintf_error(len, ret))
3789 return -1;
3790
3791 pos += ret;
3792 len -= ret;
3793 }
3794
3795 if (dscp_policy->start_port && dscp_policy->end_port) {
3796 ret = snprintf(pos, len, " %s dport %d-%d",
3797 protocol_to_str(dscp_policy->protocol),
3798 dscp_policy->start_port,
3799 dscp_policy->end_port);
3800 if (snprintf_error(len, ret))
3801 return -1;
3802
3803 pos += ret;
3804 len -= ret;
3805 }
3806
3807 ret = snprintf(pos, len, " counter %s dscp set 0x%0x", ip,
3808 dscp_policy->dscp);
3809 if (snprintf_error(len, ret))
3810 return -1;
3811
3812 ret = system(nft_cmd);
3813 sigma_dut_print(dut, DUT_MSG_INFO, "nft rule: %s err: %d",
3814 nft_cmd, ret);
3815
3816 return ret;
3817}
3818
3819
3820static void clear_all_dscp_policies(struct sigma_dut *dut)
3821{
3822 free_dscp_policy_table(dut);
3823
3824 if (system("nft flush ruleset") != 0)
3825 sigma_dut_print(dut, DUT_MSG_ERROR,
3826 "Failed to flush DSCP policy");
3827}
3828
3829
3830static int send_dscp_response(struct sigma_dut *dut,
3831 struct dscp_policy_status *status_list,
3832 int num_status)
3833{
3834 int rem_len, ret;
3835 char buf[200] = "", *pos, cmd[256];
3836
3837 pos = buf;
3838 rem_len = sizeof(buf);
3839
3840 ret = snprintf(pos, rem_len, " solicited");
3841 if (snprintf_error(rem_len, ret)) {
3842 sigma_dut_print(dut, DUT_MSG_ERROR,
3843 "Failed to write DSCP policy response command");
3844 return -1;
3845 }
3846 pos += ret;
3847 rem_len -= ret;
3848
3849 for (int i = 0; i < num_status; i++) {
3850 ret = snprintf(pos, rem_len, " policy_id=%d status=%d",
3851 status_list[i].id, status_list[i].status);
3852 if (snprintf_error(rem_len, ret)) {
3853 sigma_dut_print(dut, DUT_MSG_ERROR,
3854 "Failed to wite DSCP policy response");
3855 return -1;
3856 }
3857
3858 pos += ret;
3859 rem_len -= ret;
3860 }
3861
3862 ret = snprintf(cmd, sizeof(cmd), "DSCP_RESP%s", buf);
3863 if (snprintf_error(sizeof(cmd), ret)) {
3864 sigma_dut_print(dut, DUT_MSG_ERROR,
3865 "Failed to create DSCP Policy Response frame");
3866 return -1;
3867 }
3868
3869 if (wpa_command(dut->station_ifname, cmd) != 0) {
3870 sigma_dut_print(dut, DUT_MSG_ERROR,
3871 "Failed to send DSCP Policy Response frame");
3872 return -1;
3873 }
3874
3875 sigma_dut_print(dut, DUT_MSG_DEBUG,
3876 "DSCP Policy Response frame sent: %s", cmd);
3877 return 0;
3878}
3879
3880
3881#ifdef ANDROID
3882static void thread_cancel_handler(int sig)
3883{
3884 if (sig == SIGUSR1)
3885 pthread_exit(0);
3886}
3887#endif /* ANDROID */
3888
3889
3890static void * mon_dscp_policies(void *ptr)
3891{
3892 struct sigma_dut *dut = ptr;
3893 int ret, policy_id;
3894 struct wpa_ctrl *ctrl;
3895 char buf[4096], *pos, *end;
3896 struct dscp_policy_data *policy = NULL, *policy_table;
3897 struct dscp_policy_status status_list[10];
3898 int num_status = 0;
3899 const char *events[] = {
3900 "CTRL-EVENT-DISCONNECTED",
3901 "CTRL-EVENT-DSCP-POLICY",
3902 NULL
3903 };
3904#ifdef ANDROID
3905 struct sigaction actions;
3906#endif /* ANDROID */
3907
3908 ctrl = open_wpa_mon(get_station_ifname(dut));
3909 if (!ctrl) {
3910 sigma_dut_print(dut, DUT_MSG_ERROR,
3911 "Failed to open wpa_supplicant monitor connection");
3912 return NULL;
3913 }
3914
3915#ifdef ANDROID
3916 memset(&actions, 0, sizeof(actions));
3917 sigemptyset(&actions.sa_mask);
3918 actions.sa_flags = 0;
3919 actions.sa_handler = thread_cancel_handler;
3920 if (sigaction(SIGUSR1, &actions, NULL) == -1) {
3921 sigma_dut_print(dut, DUT_MSG_ERROR,
3922 "Failed to register exit handler for %s",
3923 __func__);
3924 wpa_ctrl_detach(ctrl);
3925 wpa_ctrl_close(ctrl);
3926 return NULL;
3927 }
3928#endif /* ANDROID */
3929
3930 while (1) {
3931 ret = get_wpa_cli_events_timeout(dut, ctrl, events,
3932 buf, sizeof(buf), 0);
3933
3934 if (ret || strlen(buf) == 0) {
3935 sigma_dut_print(dut, DUT_MSG_INFO,
3936 "Did not receive any event");
3937 continue;
3938 }
3939
3940 if (strstr(buf, "CTRL-EVENT-DISCONNECTED")) {
3941 clear_all_dscp_policies(dut);
3942 break;
3943 }
3944
3945 if (strstr(buf, "request_start")) {
3946 num_status = 0;
3947 if (strstr(buf, "clear_all"))
3948 clear_all_dscp_policies(dut);
3949 continue;
3950 }
3951
3952 if (strstr(buf, "request_end")) {
3953 send_dscp_response(dut, status_list, num_status);
3954 continue;
3955 }
3956
3957 if (!strstr(buf, "add") && !strstr(buf, "remove") &&
3958 !strstr(buf, "reject")) {
3959 sigma_dut_print(dut, DUT_MSG_DEBUG, "Ignore event: %s",
3960 buf);
3961 continue;
3962 }
3963
3964 pos = strstr(buf, "policy_id=");
3965 if (!pos) {
3966 sigma_dut_print(dut, DUT_MSG_INFO,
3967 "Policy id not present");
3968 continue;
3969 }
3970 policy_id = atoi(pos + 10);
3971
3972 if (num_status >= ARRAY_SIZE(status_list)) {
3973 sigma_dut_print(dut, DUT_MSG_INFO,
3974 "Max policies allowed per DSCP request reached. Drop policy id %d request",
3975 policy_id);
3976 continue;
3977 }
3978 status_list[num_status].id = policy_id;
3979
Veerendranath Jakkama16cdc82021-09-12 16:44:22 +05303980 if (dut->reject_dscp_policies) {
3981 status_list[num_status].status =
3982 dut->dscp_reject_resp_code;
3983 num_status++;
3984 continue;
3985 }
3986
Veerendranath Jakkam9ceb3b12021-09-10 03:18:17 +05303987 if (strstr(buf, "reject"))
3988 goto reject;
3989
3990 /*
3991 * In case of "add" also if policy with same policy id exist it
3992 * shall be removed. So always call remove_dscp_policy().
3993 */
3994 if (remove_dscp_policy(dut, policy_id))
3995 goto reject;
3996
3997 if (strstr(buf, "remove"))
3998 goto success;
3999
4000 policy = malloc(sizeof(*policy));
4001 if (!policy)
4002 goto reject;
4003
4004 memset(policy, 0, sizeof(*policy));
4005
4006 policy->policy_id = policy_id;
4007
4008 pos = strstr(buf, "dscp=");
4009 if (!pos) {
4010 sigma_dut_print(dut, DUT_MSG_ERROR,
4011 "DSCP info not present");
4012 goto reject;
4013 }
4014 policy->dscp = atoi(pos + 5);
4015
4016 pos = strstr(buf, "ip_version=");
4017 if (!pos) {
4018 sigma_dut_print(dut, DUT_MSG_ERROR,
4019 "IP version info not present");
4020 goto reject;
4021 }
4022 policy->ip_version = atoi(pos + 11);
4023
4024 pos = strstr(buf, "domain_name=");
4025 if (pos) {
4026 pos += 12;
4027 end = strchr(pos, ' ');
4028 if (!end)
4029 end = pos + strlen(pos);
4030
4031 if (end - pos >= (int) sizeof(policy->domain_name))
4032 goto reject;
4033
4034 memcpy(policy->domain_name, pos, end - pos);
4035 policy->domain_name[end - pos] = '\0';
4036 }
4037
4038 pos = strstr(buf, "start_port=");
4039 if (pos) {
4040 pos += 11;
4041 policy->start_port = atoi(pos);
4042 }
4043
4044 pos = strstr(buf, "end_port=");
4045 if (pos) {
4046 pos += 9;
4047 policy->end_port = atoi(pos);
4048 }
4049
4050 pos = strstr(buf, "src_ip=");
4051 if (pos) {
4052 pos += 7;
4053 end = strchr(pos, ' ');
4054 if (!end)
4055 end = pos + strlen(pos);
4056
4057 if (end - pos >= (int) sizeof(policy->src_ip))
4058 goto reject;
4059
4060 memcpy(policy->src_ip, pos, end - pos);
4061 policy->src_ip[end - pos] = '\0';
4062 }
4063
4064 pos = strstr(buf, "dst_ip=");
4065 if (pos) {
4066 pos += 7;
4067 end = strchr(pos, ' ');
4068 if (!end)
4069 end = pos + strlen(pos);
4070
4071 if (end - pos >= (int) sizeof(policy->dst_ip))
4072 goto reject;
4073
4074 memcpy(policy->dst_ip, pos, end - pos);
4075 policy->dst_ip[end - pos] = '\0';
4076 }
4077
4078 pos = strstr(buf, "src_port=");
4079 if (pos) {
4080 pos += 9;
4081 policy->src_port = atoi(pos);
4082 }
4083
4084 pos = strstr(buf, "dst_port=");
4085 if (pos) {
4086 pos += 9;
4087 policy->dst_port = atoi(pos);
4088 }
4089
4090 pos = strstr(buf, "protocol=");
4091 if (pos) {
4092 pos += 9;
4093 policy->protocol = atoi(pos);
4094 }
4095
4096 /*
4097 * Skip adding nft rules for doman name policies.
4098 * Domain name rules are applied in sigma_dut itself.
4099 */
4100 if (!strlen(policy->domain_name) && add_nft_rule(dut, policy))
4101 goto reject;
4102
4103 if (dut->dscp_policy_table) {
4104 policy_table = dut->dscp_policy_table;
4105 while (policy_table->next != NULL)
4106 policy_table = policy_table->next;
4107
4108 policy_table->next = policy;
4109 } else
4110 dut->dscp_policy_table = policy;
4111
4112success:
4113 status_list[num_status].status = DSCP_POLICY_SUCCESS;
4114 num_status++;
4115 policy = NULL;
4116 continue;
4117reject:
4118 status_list[num_status].status = DSCP_POLICY_REJECT;
4119 num_status++;
4120 free(policy);
4121 policy = NULL;
4122 }
4123
4124 free_dscp_policy_table(dut);
4125 wpa_ctrl_detach(ctrl);
4126 wpa_ctrl_close(ctrl);
4127
4128 pthread_exit(0);
4129 return NULL;
4130}
4131
4132
4133static void start_dscp_policy_mon_thread(struct sigma_dut *dut)
4134{
4135 /* Create event thread */
4136 pthread_create(&dut->dscp_policy_mon_thread, NULL, &mon_dscp_policies,
4137 (void *) dut);
4138}
4139
4140
4141void stop_dscp_policy_mon_thread(struct sigma_dut *dut)
4142{
4143 if (dut->dscp_policy_mon_thread) {
4144#ifdef ANDROID
4145 /* pthread_cancel not supported in Android */
4146 pthread_kill(dut->dscp_policy_mon_thread, SIGUSR1);
4147#else /* ANDROID */
4148 pthread_cancel(dut->dscp_policy_mon_thread);
4149#endif /* ANDROID */
4150 dut->dscp_policy_mon_thread = 0;
4151 }
4152}
4153
4154
Jouni Malinenf7222712019-06-13 01:50:21 +03004155static enum sigma_cmd_result cmd_sta_associate(struct sigma_dut *dut,
4156 struct sigma_conn *conn,
4157 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004158{
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304159#ifdef NL80211_SUPPORT
4160 const char *intf = get_param(cmd, "Interface");
4161#endif /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004162 const char *ssid = get_param(cmd, "ssid");
4163 const char *wps_param = get_param(cmd, "WPS");
4164 const char *bssid = get_param(cmd, "bssid");
Jouni Malinen46a19b62017-06-23 14:31:27 +03004165 const char *chan = get_param(cmd, "channel");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02004166 const char *network_mode = get_param(cmd, "network_mode");
Veerendranath Jakkama082e342020-05-16 00:19:21 +05304167 const char *ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004168 int wps = 0;
Jouni Malinen3c367e82017-06-23 17:01:47 +03004169 char buf[1000], extra[50];
Jouni Malinen134fe3c2019-06-12 04:16:49 +03004170 int e;
4171 enum sigma_cmd_result ret = SUCCESS_SEND_STATUS;
4172 struct wpa_ctrl *ctrl = NULL;
4173 int num_network_not_found = 0;
4174 int num_disconnected = 0;
4175 int tod = -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004176
4177 if (ssid == NULL)
4178 return -1;
4179
Jouni Malinen37d5c692019-08-19 16:56:55 +03004180 dut->server_cert_tod = 0;
4181
Jouni Malinen3c367e82017-06-23 17:01:47 +03004182 if (dut->rsne_override) {
Sunil Dutt44595082018-02-12 19:41:45 +05304183#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004184 if (get_driver_type(dut) == DRIVER_WCN) {
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304185 sta_config_params(dut, intf, STA_SET_RSNIE, 1);
Sunil Dutt44595082018-02-12 19:41:45 +05304186 dut->config_rsnie = 1;
4187 }
4188#endif /* NL80211_SUPPORT */
Jouni Malinen3c367e82017-06-23 17:01:47 +03004189 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
4190 dut->rsne_override);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004191 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinen3c367e82017-06-23 17:01:47 +03004192 send_resp(dut, conn, SIGMA_ERROR,
4193 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
4194 return 0;
4195 }
4196 }
4197
Jouni Malinen68143132017-09-02 02:34:08 +03004198 if (dut->sae_commit_override) {
4199 snprintf(buf, sizeof(buf), "SET sae_commit_override %s",
4200 dut->sae_commit_override);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004201 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinen68143132017-09-02 02:34:08 +03004202 send_resp(dut, conn, SIGMA_ERROR,
4203 "ErrorCode,Failed to set SAE commit override");
4204 return 0;
4205 }
4206 }
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304207#ifdef ANDROID
4208 if (dut->fils_hlp)
4209 process_fils_hlp(dut);
4210#endif /* ANDROID */
Jouni Malinen68143132017-09-02 02:34:08 +03004211
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004212 if (wps_param &&
4213 (strcmp(wps_param, "1") == 0 || strcasecmp(wps_param, "On") == 0))
4214 wps = 1;
4215
4216 if (wps) {
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02004217 if (dut->program == PROGRAM_60GHZ && network_mode &&
4218 strcasecmp(network_mode, "PBSS") == 0 &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004219 set_network(get_station_ifname(dut), dut->infra_network_id,
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02004220 "pbss", "1") < 0)
4221 return -2;
4222
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004223 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
4224 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,WPS "
4225 "parameters not yet set");
4226 return 0;
4227 }
4228 if (dut->wps_method == WFA_CS_WPS_PBC) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004229 if (wpa_command(get_station_ifname(dut), "WPS_PBC") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004230 return -2;
4231 } else {
4232 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
4233 dut->wps_pin);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004234 if (wpa_command(get_station_ifname(dut), buf) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004235 return -2;
4236 }
4237 } else {
vamsi krishna52e16f92017-08-29 12:37:34 +05304238 if (strcmp(ssid, dut->infra_ssid) == 0) {
4239 sigma_dut_print(dut, DUT_MSG_DEBUG,
4240 "sta_associate for the most recently added network");
4241 } else if (find_network(dut, ssid) < 0) {
4242 sigma_dut_print(dut, DUT_MSG_DEBUG,
4243 "sta_associate for a previously stored network profile");
4244 send_resp(dut, conn, SIGMA_ERROR,
4245 "ErrorCode,Profile not found");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004246 return 0;
4247 }
4248
4249 if (bssid &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004250 set_network(get_station_ifname(dut), dut->infra_network_id,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004251 "bssid", bssid) < 0) {
4252 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
4253 "Invalid bssid argument");
4254 return 0;
4255 }
4256
Veerendranath Jakkama082e342020-05-16 00:19:21 +05304257 if ((dut->program == PROGRAM_WPA3 &&
4258 dut->sta_associate_wait_connect) ||
4259 dut->program == PROGRAM_QM) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004260 ctrl = open_wpa_mon(get_station_ifname(dut));
Jouni Malinen134fe3c2019-06-12 04:16:49 +03004261 if (!ctrl)
4262 return ERROR_SEND_STATUS;
4263 }
4264
Jouni Malinen46a19b62017-06-23 14:31:27 +03004265 extra[0] = '\0';
4266 if (chan)
4267 snprintf(extra, sizeof(extra), " freq=%u",
Alexei Avshalom Lazar093569f2018-11-13 14:08:17 +02004268 channel_to_freq(dut, atoi(chan)));
Jouni Malinen46a19b62017-06-23 14:31:27 +03004269 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d%s",
4270 dut->infra_network_id, extra);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004271 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004272 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to select "
4273 "network id %d on %s",
4274 dut->infra_network_id,
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004275 get_station_ifname(dut));
Jouni Malinen134fe3c2019-06-12 04:16:49 +03004276 ret = ERROR_SEND_STATUS;
4277 goto done;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004278 }
4279 }
4280
Jouni Malinen134fe3c2019-06-12 04:16:49 +03004281 if (!ctrl)
4282 return SUCCESS_SEND_STATUS;
4283
4284 /* Wait for connection result to be able to store server certificate
4285 * hash for trust root override testing
4286 * (dev_exec_action,ServerCertTrust). */
4287
4288 for (e = 0; e < 20; e++) {
4289 const char *events[] = {
4290 "CTRL-EVENT-EAP-PEER-CERT",
4291 "CTRL-EVENT-EAP-TLS-CERT-ERROR",
4292 "CTRL-EVENT-DISCONNECTED",
4293 "CTRL-EVENT-CONNECTED",
4294 "CTRL-EVENT-NETWORK-NOT-FOUND",
4295 NULL
4296 };
4297 char buf[1024];
4298 int res;
4299
4300 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
4301 if (res < 0) {
Jouni Malinenf1f16642019-11-15 21:19:04 +02004302 send_resp(dut, conn, SIGMA_COMPLETE,
4303 "Result,Association did not complete");
Jouni Malinen134fe3c2019-06-12 04:16:49 +03004304 ret = STATUS_SENT_ERROR;
4305 break;
4306 }
4307 sigma_dut_print(dut, DUT_MSG_DEBUG, "Connection event: %s",
4308 buf);
4309
4310 if (strstr(buf, "CTRL-EVENT-EAP-PEER-CERT") &&
4311 strstr(buf, " depth=0")) {
4312 char *pos = strstr(buf, " hash=");
4313
4314 if (pos) {
4315 char *end;
4316
Jouni Malinen34b19cb2019-08-16 16:37:17 +03004317 if (strstr(buf, " tod=1"))
4318 tod = 1;
4319 else if (strstr(buf, " tod=2"))
4320 tod = 2;
4321 else
4322 tod = 0;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03004323 sigma_dut_print(dut, DUT_MSG_DEBUG,
4324 "Server certificate TOD policy: %d",
4325 tod);
Jouni Malinen37d5c692019-08-19 16:56:55 +03004326 dut->server_cert_tod = tod;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03004327
4328 pos += 6;
4329 end = strchr(pos, ' ');
4330 if (end)
4331 *end = '\0';
4332 strlcpy(dut->server_cert_hash, pos,
4333 sizeof(dut->server_cert_hash));
4334 sigma_dut_print(dut, DUT_MSG_DEBUG,
4335 "Server certificate hash: %s",
4336 dut->server_cert_hash);
4337 }
4338 }
4339
4340 if (strstr(buf, "CTRL-EVENT-EAP-TLS-CERT-ERROR")) {
4341 send_resp(dut, conn, SIGMA_COMPLETE,
4342 "Result,TLS server certificate validation failed");
4343 ret = STATUS_SENT_ERROR;
4344 break;
4345 }
4346
4347 if (strstr(buf, "CTRL-EVENT-NETWORK-NOT-FOUND")) {
4348 num_network_not_found++;
4349
4350 if (num_network_not_found > 2) {
4351 send_resp(dut, conn, SIGMA_COMPLETE,
4352 "Result,Network not found");
4353 ret = STATUS_SENT_ERROR;
4354 break;
4355 }
4356 }
4357
4358 if (strstr(buf, "CTRL-EVENT-DISCONNECTED")) {
4359 num_disconnected++;
4360
4361 if (num_disconnected > 2) {
4362 send_resp(dut, conn, SIGMA_COMPLETE,
4363 "Result,Connection failed");
4364 ret = STATUS_SENT_ERROR;
4365 break;
4366 }
4367 }
4368
4369 if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
4370 if (tod >= 0) {
4371 sigma_dut_print(dut, DUT_MSG_DEBUG,
4372 "Network profile TOD policy update: %d -> %d",
4373 dut->sta_tod_policy, tod);
4374 dut->sta_tod_policy = tod;
4375 }
Veerendranath Jakkama082e342020-05-16 00:19:21 +05304376 if (dut->program == PROGRAM_QM) {
4377 unsigned char iface_mac_addr[ETH_ALEN];
4378 char ipv6[100];
4379
4380 if (get_hwaddr(ifname, iface_mac_addr) < 0) {
4381 sigma_dut_print(dut, DUT_MSG_ERROR,
4382 "%s: get_hwaddr %s failed",
4383 __func__, ifname);
4384 ret = ERROR_SEND_STATUS;
4385 break;
4386 }
4387
4388 convert_mac_addr_to_ipv6_lladdr(iface_mac_addr,
4389 ipv6,
4390 sizeof(ipv6));
4391
4392 if (set_ipv6_addr(dut, ipv6, "64", ifname) !=
4393 0) {
4394 ret = ERROR_SEND_STATUS;
4395 break;
4396 }
Veerendranath Jakkam9ceb3b12021-09-10 03:18:17 +05304397 start_dscp_policy_mon_thread(dut);
Veerendranath Jakkama082e342020-05-16 00:19:21 +05304398 }
Jouni Malinen134fe3c2019-06-12 04:16:49 +03004399 break;
4400 }
4401 }
4402done:
4403 if (ctrl) {
4404 wpa_ctrl_detach(ctrl);
4405 wpa_ctrl_close(ctrl);
4406 }
4407 return ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004408}
4409
4410
4411static int run_hs20_osu(struct sigma_dut *dut, const char *params)
4412{
4413 char buf[500], cmd[200];
4414 int res;
4415
4416 /* Use hs20-osu-client file at the current dir, if found; otherwise use
4417 * default path */
4418 res = snprintf(cmd, sizeof(cmd),
4419 "%s -w \"%s\" -r hs20-osu-client.res %s%s -dddKt -f Logs/hs20-osu-client.txt",
4420 file_exists("./hs20-osu-client") ?
4421 "./hs20-osu-client" : "hs20-osu-client",
4422 sigma_wpas_ctrl,
4423 dut->summary_log ? "-s " : "",
4424 dut->summary_log ? dut->summary_log : "");
4425 if (res < 0 || res >= (int) sizeof(cmd))
4426 return -1;
4427
4428 res = snprintf(buf, sizeof(buf), "%s %s", cmd, params);
4429 if (res < 0 || res >= (int) sizeof(buf))
4430 return -1;
4431 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
4432
4433 if (system(buf) != 0) {
4434 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run: %s", buf);
4435 return -1;
4436 }
4437 sigma_dut_print(dut, DUT_MSG_DEBUG,
4438 "Completed hs20-osu-client operation");
4439
4440 return 0;
4441}
4442
4443
4444static int download_ppsmo(struct sigma_dut *dut,
4445 struct sigma_conn *conn,
4446 const char *intf,
4447 struct sigma_cmd *cmd)
4448{
4449 const char *name, *path, *val;
4450 char url[500], buf[600], fbuf[100];
4451 char *fqdn = NULL;
4452
4453 name = get_param(cmd, "FileName");
4454 path = get_param(cmd, "FilePath");
4455 if (name == NULL || path == NULL)
4456 return -1;
4457
4458 if (strcasecmp(path, "VendorSpecific") == 0) {
4459 snprintf(url, sizeof(url), "PPS/%s", name);
4460 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured PPS MO "
4461 "from the device (%s)", url);
4462 if (!file_exists(url)) {
4463 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
4464 "PPS MO file does not exist");
4465 return 0;
4466 }
4467 snprintf(buf, sizeof(buf), "cp %s pps-tnds.xml", url);
4468 if (system(buf) != 0) {
4469 send_resp(dut, conn, SIGMA_ERROR,
4470 "errorCode,Failed to copy PPS MO");
4471 return 0;
4472 }
4473 } else if (strncasecmp(path, "http:", 5) != 0 &&
4474 strncasecmp(path, "https:", 6) != 0) {
4475 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
4476 "Unsupported FilePath value");
4477 return 0;
4478 } else {
4479 snprintf(url, sizeof(url), "%s/%s", path, name);
4480 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading PPS MO from %s",
4481 url);
4482 snprintf(buf, sizeof(buf), "wget -T 10 -t 3 -O pps-tnds.xml '%s'", url);
4483 remove("pps-tnds.xml");
4484 if (system(buf) != 0) {
4485 send_resp(dut, conn, SIGMA_ERROR,
4486 "errorCode,Failed to download PPS MO");
4487 return 0;
4488 }
4489 }
4490
4491 if (run_hs20_osu(dut, "from_tnds pps-tnds.xml pps.xml") < 0) {
4492 send_resp(dut, conn, SIGMA_ERROR,
4493 "errorCode,Failed to parse downloaded PPSMO");
4494 return 0;
4495 }
4496 unlink("pps-tnds.xml");
4497
4498 val = get_param(cmd, "managementTreeURI");
4499 if (val) {
4500 const char *pos, *end;
4501 sigma_dut_print(dut, DUT_MSG_DEBUG, "managementTreeURI: %s",
4502 val);
4503 if (strncmp(val, "./Wi-Fi/", 8) != 0) {
4504 send_resp(dut, conn, SIGMA_ERROR,
4505 "errorCode,Invalid managementTreeURI prefix");
4506 return 0;
4507 }
4508 pos = val + 8;
4509 end = strchr(pos, '/');
4510 if (end == NULL ||
4511 strcmp(end, "/PerProviderSubscription") != 0) {
4512 send_resp(dut, conn, SIGMA_ERROR,
4513 "errorCode,Invalid managementTreeURI postfix");
4514 return 0;
4515 }
4516 if (end - pos >= (int) sizeof(fbuf)) {
4517 send_resp(dut, conn, SIGMA_ERROR,
4518 "errorCode,Too long FQDN in managementTreeURI");
4519 return 0;
4520 }
4521 memcpy(fbuf, pos, end - pos);
4522 fbuf[end - pos] = '\0';
4523 fqdn = fbuf;
4524 sigma_dut_print(dut, DUT_MSG_INFO,
4525 "FQDN from managementTreeURI: %s", fqdn);
4526 } else if (run_hs20_osu(dut, "get_fqdn pps.xml") == 0) {
4527 FILE *f = fopen("pps-fqdn", "r");
4528 if (f) {
4529 if (fgets(fbuf, sizeof(fbuf), f)) {
4530 fbuf[sizeof(fbuf) - 1] = '\0';
4531 fqdn = fbuf;
4532 sigma_dut_print(dut, DUT_MSG_DEBUG,
4533 "Use FQDN %s", fqdn);
4534 }
4535 fclose(f);
4536 }
4537 }
4538
4539 if (fqdn == NULL) {
4540 send_resp(dut, conn, SIGMA_ERROR,
4541 "errorCode,No FQDN specified");
4542 return 0;
4543 }
4544
4545 mkdir("SP", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
4546 snprintf(buf, sizeof(buf), "SP/%s", fqdn);
4547 mkdir(buf, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
4548
4549 snprintf(buf, sizeof(buf), "SP/%s/pps.xml", fqdn);
4550 if (rename("pps.xml", buf) < 0) {
4551 send_resp(dut, conn, SIGMA_ERROR,
4552 "errorCode,Could not move PPS MO");
4553 return 0;
4554 }
4555
4556 if (strcasecmp(path, "VendorSpecific") == 0) {
4557 snprintf(buf, sizeof(buf), "cp Certs/ca.pem SP/%s/ca.pem",
4558 fqdn);
4559 if (system(buf)) {
4560 send_resp(dut, conn, SIGMA_ERROR,
4561 "errorCode,Failed to copy OSU CA cert");
4562 return 0;
4563 }
4564
4565 snprintf(buf, sizeof(buf),
4566 "cp Certs/aaa-ca.pem SP/%s/aaa-ca.pem",
4567 fqdn);
4568 if (system(buf)) {
4569 send_resp(dut, conn, SIGMA_ERROR,
4570 "errorCode,Failed to copy AAA CA cert");
4571 return 0;
4572 }
4573 } else {
4574 snprintf(buf, sizeof(buf),
4575 "dl_osu_ca SP/%s/pps.xml SP/%s/ca.pem",
4576 fqdn, fqdn);
4577 if (run_hs20_osu(dut, buf) < 0) {
4578 send_resp(dut, conn, SIGMA_ERROR,
4579 "errorCode,Failed to download OSU CA cert");
4580 return 0;
4581 }
4582
4583 snprintf(buf, sizeof(buf),
4584 "dl_aaa_ca SP/%s/pps.xml SP/%s/aaa-ca.pem",
4585 fqdn, fqdn);
4586 if (run_hs20_osu(dut, buf) < 0) {
4587 sigma_dut_print(dut, DUT_MSG_INFO,
4588 "Failed to download AAA CA cert");
4589 }
4590 }
4591
4592 if (file_exists("next-client-cert.pem")) {
4593 snprintf(buf, sizeof(buf), "SP/%s/client-cert.pem", fqdn);
4594 if (rename("next-client-cert.pem", buf) < 0) {
4595 send_resp(dut, conn, SIGMA_ERROR,
4596 "errorCode,Could not move client certificate");
4597 return 0;
4598 }
4599 }
4600
4601 if (file_exists("next-client-key.pem")) {
4602 snprintf(buf, sizeof(buf), "SP/%s/client-key.pem", fqdn);
4603 if (rename("next-client-key.pem", buf) < 0) {
4604 send_resp(dut, conn, SIGMA_ERROR,
4605 "errorCode,Could not move client key");
4606 return 0;
4607 }
4608 }
4609
4610 snprintf(buf, sizeof(buf), "set_pps SP/%s/pps.xml", fqdn);
4611 if (run_hs20_osu(dut, buf) < 0) {
4612 send_resp(dut, conn, SIGMA_ERROR,
4613 "errorCode,Failed to configure credential from "
4614 "PPSMO");
4615 return 0;
4616 }
4617
4618 return 1;
4619}
4620
4621
4622static int download_cert(struct sigma_dut *dut,
4623 struct sigma_conn *conn,
4624 const char *intf,
4625 struct sigma_cmd *cmd)
4626{
4627 const char *name, *path;
4628 char url[500], buf[600];
4629
4630 name = get_param(cmd, "FileName");
4631 path = get_param(cmd, "FilePath");
4632 if (name == NULL || path == NULL)
4633 return -1;
4634
4635 if (strcasecmp(path, "VendorSpecific") == 0) {
4636 snprintf(url, sizeof(url), "Certs/%s-cert.pem", name);
4637 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
4638 "certificate from the device (%s)", url);
4639 if (!file_exists(url)) {
4640 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
4641 "certificate file does not exist");
4642 return 0;
4643 }
4644 snprintf(buf, sizeof(buf), "cp %s next-client-cert.pem", url);
4645 if (system(buf) != 0) {
4646 send_resp(dut, conn, SIGMA_ERROR,
4647 "errorCode,Failed to copy client "
4648 "certificate");
4649 return 0;
4650 }
4651
4652 snprintf(url, sizeof(url), "Certs/%s-key.pem", name);
4653 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
4654 "private key from the device (%s)", url);
4655 if (!file_exists(url)) {
4656 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
4657 "private key file does not exist");
4658 return 0;
4659 }
4660 snprintf(buf, sizeof(buf), "cp %s next-client-key.pem", url);
4661 if (system(buf) != 0) {
4662 send_resp(dut, conn, SIGMA_ERROR,
4663 "errorCode,Failed to copy client key");
4664 return 0;
4665 }
4666 } else if (strncasecmp(path, "http:", 5) != 0 &&
4667 strncasecmp(path, "https:", 6) != 0) {
4668 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
4669 "Unsupported FilePath value");
4670 return 0;
4671 } else {
4672 snprintf(url, sizeof(url), "%s/%s.pem", path, name);
4673 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading client "
4674 "certificate/key from %s", url);
4675 snprintf(buf, sizeof(buf),
4676 "wget -T 10 -t 3 -O next-client-cert.pem '%s'", url);
4677 if (system(buf) != 0) {
4678 send_resp(dut, conn, SIGMA_ERROR,
4679 "errorCode,Failed to download client "
4680 "certificate");
4681 return 0;
4682 }
4683
4684 if (system("cp next-client-cert.pem next-client-key.pem") != 0)
4685 {
4686 send_resp(dut, conn, SIGMA_ERROR,
4687 "errorCode,Failed to copy client key");
4688 return 0;
4689 }
4690 }
4691
4692 return 1;
4693}
4694
4695
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02004696static int cmd_sta_preset_testparameters_60ghz(struct sigma_dut *dut,
4697 struct sigma_conn *conn,
4698 struct sigma_cmd *cmd)
4699{
4700 const char *val;
4701 const char *intf = get_param(cmd, "interface");
4702
4703 if (!intf)
4704 return -1;
4705
4706 val = get_param(cmd, "WscIEFragment");
4707 if (val && strcasecmp(val, "enable") == 0) {
4708 sigma_dut_print(dut, DUT_MSG_DEBUG,
4709 "Enable WSC IE fragmentation");
4710
4711 dut->wsc_fragment = 1;
4712 /* set long attributes to force fragmentation */
4713 if (wpa_command(intf, "SET device_name "
4714 WPS_LONG_DEVICE_NAME) < 0)
4715 return -2;
4716 if (wpa_command(intf, "SET manufacturer "
4717 WPS_LONG_MANUFACTURER) < 0)
4718 return -2;
4719 if (wpa_command(intf, "SET model_name "
4720 WPS_LONG_MODEL_NAME) < 0)
4721 return -2;
4722 if (wpa_command(intf, "SET model_number "
4723 WPS_LONG_MODEL_NUMBER) < 0)
4724 return -2;
4725 if (wpa_command(intf, "SET serial_number "
4726 WPS_LONG_SERIAL_NUMBER) < 0)
4727 return -2;
4728 }
4729
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02004730 val = get_param(cmd, "RSN_IE");
4731 if (val) {
4732 if (strcasecmp(val, "disable") == 0)
4733 dut->force_rsn_ie = FORCE_RSN_IE_REMOVE;
4734 else if (strcasecmp(val, "enable") == 0)
4735 dut->force_rsn_ie = FORCE_RSN_IE_ADD;
4736 }
4737
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02004738 val = get_param(cmd, "WpsVersion");
4739 if (val)
4740 dut->wps_forced_version = get_wps_forced_version(dut, val);
4741
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02004742 val = get_param(cmd, "WscEAPFragment");
4743 if (val && strcasecmp(val, "enable") == 0)
4744 dut->eap_fragment = 1;
4745
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02004746 return 1;
4747}
4748
4749
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004750static int cmd_sta_preset_testparameters_hs2_r2(struct sigma_dut *dut,
4751 struct sigma_conn *conn,
4752 const char *intf,
4753 struct sigma_cmd *cmd)
4754{
4755 const char *val;
4756
4757 val = get_param(cmd, "FileType");
4758 if (val && strcasecmp(val, "PPSMO") == 0)
4759 return download_ppsmo(dut, conn, intf, cmd);
4760 if (val && strcasecmp(val, "CERT") == 0)
4761 return download_cert(dut, conn, intf, cmd);
4762 if (val) {
4763 send_resp(dut, conn, SIGMA_ERROR,
4764 "ErrorCode,Unsupported FileType");
4765 return 0;
4766 }
4767
4768 return 1;
4769}
4770
4771
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304772static int cmd_sta_preset_testparameters_oce(struct sigma_dut *dut,
4773 struct sigma_conn *conn,
4774 const char *intf,
4775 struct sigma_cmd *cmd)
4776{
4777 const char *val;
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304778 char buf[1000];
4779 char text[20];
4780 unsigned char addr[ETH_ALEN];
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304781
4782 val = get_param(cmd, "OCESupport");
4783 if (val && strcasecmp(val, "Disable") == 0) {
4784 if (wpa_command(intf, "SET oce 0") < 0) {
4785 send_resp(dut, conn, SIGMA_ERROR,
4786 "ErrorCode,Failed to disable OCE");
4787 return 0;
4788 }
4789 } else if (val && strcasecmp(val, "Enable") == 0) {
4790 if (wpa_command(intf, "SET oce 1") < 0) {
4791 send_resp(dut, conn, SIGMA_ERROR,
4792 "ErrorCode,Failed to enable OCE");
4793 return 0;
4794 }
4795 }
4796
vamsi krishnaa2799492017-12-05 14:28:01 +05304797 val = get_param(cmd, "FILScap");
4798 if (val && (atoi(val) == 1)) {
4799 if (wpa_command(intf, "SET disable_fils 0") < 0) {
4800 send_resp(dut, conn, SIGMA_ERROR,
4801 "ErrorCode,Failed to enable FILS");
4802 return 0;
4803 }
4804 } else if (val && (atoi(val) == 0)) {
4805 if (wpa_command(intf, "SET disable_fils 1") < 0) {
4806 send_resp(dut, conn, SIGMA_ERROR,
4807 "ErrorCode,Failed to disable FILS");
4808 return 0;
4809 }
4810 }
4811
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304812 val = get_param(cmd, "FILSHLP");
4813 if (val && strcasecmp(val, "Enable") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004814 if (get_wpa_status(get_station_ifname(dut), "address", text,
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304815 sizeof(text)) < 0)
4816 return -2;
4817 hwaddr_aton(text, addr);
4818 snprintf(buf, sizeof(buf),
4819 "FILS_HLP_REQ_ADD ff:ff:ff:ff:ff:ff "
4820 "080045100140000040004011399e00000000ffffffff00440043"
4821 "012cb30001010600fd4f46410000000000000000000000000000"
4822 "000000000000"
4823 "%02x%02x%02x%02x%02x%02x"
4824 "0000000000000000000000000000000000000000000000000000"
4825 "0000000000000000000000000000000000000000000000000000"
4826 "0000000000000000000000000000000000000000000000000000"
4827 "0000000000000000000000000000000000000000000000000000"
4828 "0000000000000000000000000000000000000000000000000000"
4829 "0000000000000000000000000000000000000000000000000000"
4830 "0000000000000000000000000000000000000000000000000000"
4831 "0000000000000000000000000000000000000000638253633501"
4832 "013d0701000af549d29b390205dc3c12616e64726f69642d6468"
4833 "63702d382e302e30370a0103060f1a1c333a3b2b5000ff00",
4834 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
4835 if (wpa_command(intf, buf)) {
4836 send_resp(dut, conn, SIGMA_ERROR,
4837 "ErrorCode,Failed to add HLP");
4838 return 0;
4839 }
4840 dut->fils_hlp = 1;
4841 }
4842
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304843 return 1;
4844}
4845
4846
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004847static void ath_sta_set_noack(struct sigma_dut *dut, const char *intf,
4848 const char *val)
4849{
4850 int counter = 0;
4851 char token[50];
4852 char *result;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304853 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004854
Peng Xub8fc5cc2017-05-10 17:27:28 -07004855 strlcpy(token, val, sizeof(token));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004856 token[sizeof(token) - 1] = '\0';
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304857 result = strtok_r(token, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004858 while (result) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004859 if (strcmp(result, "disable") == 0)
4860 run_iwpriv(dut, intf, "noackpolicy %d 1 0", counter);
4861 else
4862 run_iwpriv(dut, intf, "noackpolicy %d 1 1", counter);
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304863 result = strtok_r(NULL, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004864 counter++;
4865 }
4866}
4867
4868
4869static void ath_sta_set_rts(struct sigma_dut *dut, const char *intf,
4870 const char *val)
4871{
4872 char buf[100];
4873
4874 snprintf(buf, sizeof(buf), "iwconfig %s rts %s", intf, val);
4875 if (system(buf) != 0) {
4876 sigma_dut_print(dut, DUT_MSG_ERROR, "iwconfig RTS failed");
4877 }
4878}
4879
4880
4881static void ath_sta_set_wmm(struct sigma_dut *dut, const char *intf,
4882 const char *val)
4883{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004884 if (strcasecmp(val, "off") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004885 run_iwpriv(dut, intf, "wmm 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004886 }
4887}
4888
4889
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08004890static int wcn_sta_set_wmm(struct sigma_dut *dut, const char *intf,
4891 const char *val)
4892{
4893#ifdef NL80211_SUPPORT
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08004894 int wmmenable = 1;
4895
4896 if (val &&
4897 (strcasecmp(val, "off") == 0 || strcmp(val, "0") == 0))
4898 wmmenable = 0;
4899
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05304900 return wcn_wifi_test_config_set_u8(
4901 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WMM_ENABLE,
4902 wmmenable);
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08004903#else /* NL80211_SUPPORT */
4904 sigma_dut_print(dut, DUT_MSG_ERROR,
4905 "WMM cannot be changed without NL80211_SUPPORT defined");
4906 return -1;
4907#endif /* NL80211_SUPPORT */
4908}
4909
4910
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004911static void ath_sta_set_sgi(struct sigma_dut *dut, const char *intf,
4912 const char *val)
4913{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004914 int sgi20;
4915
4916 sgi20 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
4917
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004918 run_iwpriv(dut, intf, "shortgi %d", sgi20);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004919}
4920
4921
4922static void ath_sta_set_11nrates(struct sigma_dut *dut, const char *intf,
4923 const char *val)
4924{
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05304925 int rate_code, v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004926
4927 /* Disable Tx Beam forming when using a fixed rate */
4928 ath_disable_txbf(dut, intf);
4929
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05304930 v = atoi(val);
4931 if (v < 0 || v > 32) {
4932 sigma_dut_print(dut, DUT_MSG_ERROR,
4933 "Invalid Fixed MCS rate: %d", v);
4934 return;
4935 }
4936 rate_code = 0x80 + v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004937
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004938 run_iwpriv(dut, intf, "set11NRates 0x%x", rate_code);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004939
4940 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004941 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004942}
4943
4944
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08004945static void iwpriv_sta_set_amsdu(struct sigma_dut *dut, const char *intf,
4946 const char *val)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004947{
4948 char buf[60];
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304949 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004950
4951 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)
4952 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 2", intf);
4953 else
4954 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf);
4955
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304956 ret = system(buf);
4957#ifdef NL80211_SUPPORT
4958 if (ret) {
4959 int value = (strcasecmp(val, "Enable") == 0) ? 2 : 1;
4960
4961 ret = sta_config_params(dut, intf, STA_SET_TX_MSDU, value);
4962 ret |= sta_config_params(dut, intf, STA_SET_RX_MSDU, value);
4963 }
4964#endif /* NL80211_SUPPORT */
4965 if (ret)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004966 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv amsdu failed");
4967}
4968
4969
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004970static int iwpriv_sta_set_ampdu(struct sigma_dut *dut, const char *intf,
4971 int ampdu)
4972{
4973 char buf[60];
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08004974 int maxaggregation = 63;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004975
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08004976 if (ampdu)
4977 ampdu = maxaggregation;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004978 snprintf(buf, sizeof(buf), "iwpriv %s ampdu %d", intf, ampdu);
4979 if (system(buf) != 0) {
4980 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv ampdu failed");
4981 return -1;
4982 }
4983
4984 return 0;
4985}
4986
4987
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004988static void ath_sta_set_stbc(struct sigma_dut *dut, const char *intf,
4989 const char *val)
4990{
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004991 run_iwpriv(dut, intf, "tx_stbc %s", val);
4992 run_iwpriv(dut, intf, "rx_stbc %s", val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004993}
4994
4995
4996static int wcn_sta_set_cts_width(struct sigma_dut *dut, const char *intf,
4997 const char *val)
4998{
4999 char buf[60];
5000
Peng Xucc317ed2017-05-18 16:44:37 -07005001 if (strcmp(val, "160") == 0) {
5002 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 5", intf);
5003 } else if (strcmp(val, "80") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005004 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
5005 } else if (strcmp(val, "40") == 0) {
5006 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 2", intf);
5007 } else if (strcmp(val, "20") == 0) {
5008 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 1", intf);
5009 } else if (strcasecmp(val, "Auto") == 0) {
5010 buf[0] = '\0';
5011 } else {
5012 sigma_dut_print(dut, DUT_MSG_ERROR,
5013 "WIDTH/CTS_WIDTH value not supported");
5014 return -1;
5015 }
5016
5017 if (buf[0] != '\0' && system(buf) != 0) {
5018 sigma_dut_print(dut, DUT_MSG_ERROR,
5019 "Failed to set WIDTH/CTS_WIDTH");
5020 return -1;
5021 }
5022
5023 return 0;
5024}
5025
5026
5027int ath_set_width(struct sigma_dut *dut, struct sigma_conn *conn,
5028 const char *intf, const char *val)
5029{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005030 if (strcasecmp(val, "Auto") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005031 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005032 dut->chwidth = 0;
5033 } else if (strcasecmp(val, "20") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005034 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005035 dut->chwidth = 0;
5036 } else if (strcasecmp(val, "40") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005037 run_iwpriv(dut, intf, "chwidth 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005038 dut->chwidth = 1;
5039 } else if (strcasecmp(val, "80") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005040 run_iwpriv(dut, intf, "chwidth 2");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005041 dut->chwidth = 2;
5042 } else if (strcasecmp(val, "160") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005043 run_iwpriv(dut, intf, "chwidth 3");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005044 dut->chwidth = 3;
5045 } else {
5046 send_resp(dut, conn, SIGMA_ERROR,
5047 "ErrorCode,WIDTH not supported");
5048 return -1;
5049 }
5050
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005051 return 0;
5052}
5053
5054
5055static int wcn_sta_set_sp_stream(struct sigma_dut *dut, const char *intf,
5056 const char *val)
5057{
5058 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07005059 int sta_nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005060
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08005061 if (strcmp(val, "1SS") == 0 || strcmp(val, "1") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005062 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07005063 sta_nss = 1;
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08005064 } else if (strcmp(val, "2SS") == 0 || strcmp(val, "2") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005065 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07005066 sta_nss = 2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005067 } else {
5068 sigma_dut_print(dut, DUT_MSG_ERROR,
5069 "SP_STREAM value not supported");
5070 return -1;
5071 }
5072
5073 if (system(buf) != 0) {
5074 sigma_dut_print(dut, DUT_MSG_ERROR,
5075 "Failed to set SP_STREAM");
5076 return -1;
5077 }
5078
Arif Hussainac6c5112018-05-25 17:34:00 -07005079 dut->sta_nss = sta_nss;
5080
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005081 return 0;
5082}
5083
5084
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05305085static void wcn_sta_set_stbc(struct sigma_dut *dut, const char *intf,
5086 const char *val)
5087{
5088 char buf[60];
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05305089 int ret;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05305090
5091 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc %s", intf, val);
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05305092 ret = system(buf);
5093#ifdef NL80211_SUPPORT
5094 if (ret)
5095 ret = sta_config_params(dut, intf, STA_SET_TX_STBC,
5096 strcmp(val, "0") == 0 ? 0 : 1);
5097#endif /* NL80211_SUPPORT */
5098 if (ret)
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05305099 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv tx_stbc failed");
5100
5101 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc %s", intf, val);
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05305102 ret = system(buf);
5103#ifdef NL80211_SUPPORT
5104 if (ret)
5105 ret = sta_config_params(dut, intf, STA_SET_RX_STBC,
5106 strcmp(val, "0") == 0 ? 0 : 1);
5107#endif /* NL80211_SUPPORT */
5108 if (ret)
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05305109 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv rx_stbc failed");
5110}
5111
5112
Ashwini Patil68d02cd2017-01-10 15:39:16 +05305113static int mbo_set_cellular_data_capa(struct sigma_dut *dut,
5114 struct sigma_conn *conn,
5115 const char *intf, int capa)
5116{
5117 char buf[32];
5118
5119 if (capa > 0 && capa < 4) {
5120 snprintf(buf, sizeof(buf), "SET mbo_cell_capa %d", capa);
5121 if (wpa_command(intf, buf) < 0) {
5122 send_resp(dut, conn, SIGMA_ERROR,
5123 "ErrorCode, Failed to set cellular data capability");
5124 return 0;
5125 }
5126 return 1;
5127 }
5128
5129 sigma_dut_print(dut, DUT_MSG_ERROR,
5130 "Invalid Cellular data capability: %d", capa);
5131 send_resp(dut, conn, SIGMA_INVALID,
5132 "ErrorCode,Invalid cellular data capability");
5133 return 0;
5134}
5135
5136
Ashwini Patil9183fdb2017-04-13 16:58:25 +05305137static int mbo_set_roaming(struct sigma_dut *dut, struct sigma_conn *conn,
5138 const char *intf, const char *val)
5139{
5140 if (strcasecmp(val, "Disable") == 0) {
5141 if (wpa_command(intf, "SET roaming 0") < 0) {
5142 send_resp(dut, conn, SIGMA_ERROR,
5143 "ErrorCode,Failed to disable roaming");
5144 return 0;
5145 }
5146 return 1;
5147 }
5148
5149 if (strcasecmp(val, "Enable") == 0) {
5150 if (wpa_command(intf, "SET roaming 1") < 0) {
5151 send_resp(dut, conn, SIGMA_ERROR,
5152 "ErrorCode,Failed to enable roaming");
5153 return 0;
5154 }
5155 return 1;
5156 }
5157
5158 sigma_dut_print(dut, DUT_MSG_ERROR,
5159 "Invalid value provided for roaming: %s", val);
5160 send_resp(dut, conn, SIGMA_INVALID,
5161 "ErrorCode,Unknown value provided for Roaming");
5162 return 0;
5163}
5164
5165
Ashwini Patila75de5a2017-04-13 16:35:05 +05305166static int mbo_set_assoc_disallow(struct sigma_dut *dut,
5167 struct sigma_conn *conn,
5168 const char *intf, const char *val)
5169{
5170 if (strcasecmp(val, "Disable") == 0) {
5171 if (wpa_command(intf, "SET ignore_assoc_disallow 1") < 0) {
5172 send_resp(dut, conn, SIGMA_ERROR,
5173 "ErrorCode,Failed to disable Assoc_disallow");
5174 return 0;
5175 }
5176 return 1;
5177 }
5178
5179 if (strcasecmp(val, "Enable") == 0) {
5180 if (wpa_command(intf, "SET ignore_assoc_disallow 0") < 0) {
5181 send_resp(dut, conn, SIGMA_ERROR,
5182 "ErrorCode,Failed to enable Assoc_disallow");
5183 return 0;
5184 }
5185 return 1;
5186 }
5187
5188 sigma_dut_print(dut, DUT_MSG_ERROR,
5189 "Invalid value provided for Assoc_disallow: %s", val);
5190 send_resp(dut, conn, SIGMA_INVALID,
5191 "ErrorCode,Unknown value provided for Assoc_disallow");
5192 return 0;
5193}
5194
5195
Ashwini Patilc63161e2017-04-13 16:30:23 +05305196static int mbo_set_bss_trans_req(struct sigma_dut *dut, struct sigma_conn *conn,
5197 const char *intf, const char *val)
5198{
5199 if (strcasecmp(val, "Reject") == 0) {
5200 if (wpa_command(intf, "SET reject_btm_req_reason 1") < 0) {
5201 send_resp(dut, conn, SIGMA_ERROR,
5202 "ErrorCode,Failed to Reject BTM Request");
5203 return 0;
5204 }
5205 return 1;
5206 }
5207
5208 if (strcasecmp(val, "Accept") == 0) {
5209 if (wpa_command(intf, "SET reject_btm_req_reason 0") < 0) {
5210 send_resp(dut, conn, SIGMA_ERROR,
5211 "ErrorCode,Failed to Accept BTM Request");
5212 return 0;
5213 }
5214 return 1;
5215 }
5216
5217 sigma_dut_print(dut, DUT_MSG_ERROR,
5218 "Invalid value provided for BSS_Transition: %s", val);
5219 send_resp(dut, conn, SIGMA_INVALID,
5220 "ErrorCode,Unknown value provided for BSS_Transition");
5221 return 0;
5222}
5223
5224
Ashwini Patil00402582017-04-13 12:29:39 +05305225static int mbo_set_non_pref_ch_list(struct sigma_dut *dut,
5226 struct sigma_conn *conn,
5227 const char *intf,
5228 struct sigma_cmd *cmd)
5229{
5230 const char *ch, *pref, *op_class, *reason;
5231 char buf[120];
5232 int len, ret;
5233
5234 pref = get_param(cmd, "Ch_Pref");
5235 if (!pref)
5236 return 1;
5237
5238 if (strcasecmp(pref, "clear") == 0) {
5239 free(dut->non_pref_ch_list);
5240 dut->non_pref_ch_list = NULL;
5241 } else {
5242 op_class = get_param(cmd, "Ch_Op_Class");
5243 if (!op_class) {
5244 send_resp(dut, conn, SIGMA_INVALID,
5245 "ErrorCode,Ch_Op_Class not provided");
5246 return 0;
5247 }
5248
5249 ch = get_param(cmd, "Ch_Pref_Num");
5250 if (!ch) {
5251 send_resp(dut, conn, SIGMA_INVALID,
5252 "ErrorCode,Ch_Pref_Num not provided");
5253 return 0;
5254 }
5255
5256 reason = get_param(cmd, "Ch_Reason_Code");
5257 if (!reason) {
5258 send_resp(dut, conn, SIGMA_INVALID,
5259 "ErrorCode,Ch_Reason_Code not provided");
5260 return 0;
5261 }
5262
5263 if (!dut->non_pref_ch_list) {
5264 dut->non_pref_ch_list =
5265 calloc(1, NON_PREF_CH_LIST_SIZE);
5266 if (!dut->non_pref_ch_list) {
5267 send_resp(dut, conn, SIGMA_ERROR,
5268 "ErrorCode,Failed to allocate memory for non_pref_ch_list");
5269 return 0;
5270 }
5271 }
5272 len = strlen(dut->non_pref_ch_list);
5273 ret = snprintf(dut->non_pref_ch_list + len,
5274 NON_PREF_CH_LIST_SIZE - len,
5275 " %s:%s:%s:%s", op_class, ch, pref, reason);
5276 if (ret > 0 && ret < NON_PREF_CH_LIST_SIZE - len) {
5277 sigma_dut_print(dut, DUT_MSG_DEBUG, "non_pref_list: %s",
5278 dut->non_pref_ch_list);
5279 } else {
5280 sigma_dut_print(dut, DUT_MSG_ERROR,
5281 "snprintf failed for non_pref_list, ret = %d",
5282 ret);
5283 send_resp(dut, conn, SIGMA_ERROR,
5284 "ErrorCode,snprintf failed");
5285 free(dut->non_pref_ch_list);
5286 dut->non_pref_ch_list = NULL;
5287 return 0;
5288 }
5289 }
5290
5291 ret = snprintf(buf, sizeof(buf), "SET non_pref_chan%s",
5292 dut->non_pref_ch_list ? dut->non_pref_ch_list : " ");
5293 if (ret < 0 || ret >= (int) sizeof(buf)) {
5294 sigma_dut_print(dut, DUT_MSG_DEBUG,
5295 "snprintf failed for set non_pref_chan, ret: %d",
5296 ret);
5297 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,snprint failed");
5298 return 0;
5299 }
5300
5301 if (wpa_command(intf, buf) < 0) {
5302 send_resp(dut, conn, SIGMA_ERROR,
5303 "ErrorCode,Failed to set non-preferred channel list");
5304 return 0;
5305 }
5306
5307 return 1;
5308}
5309
5310
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08005311#ifdef NL80211_SUPPORT
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08005312
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08005313static int sta_set_he_htc_supp(struct sigma_dut *dut, const char *intf,
5314 uint8_t cfg)
5315{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05305316 return wcn_wifi_test_config_set_u8(
5317 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_HTC_HE_SUPP,
5318 cfg);
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08005319}
5320
5321
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08005322static int sta_set_he_fragmentation(struct sigma_dut *dut, const char *intf,
5323 enum he_fragmentation_val frag)
5324{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05305325 return wcn_wifi_test_config_set_u8(
5326 dut, intf,
5327 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_FRAGMENTATION, frag);
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08005328}
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08005329
5330
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -08005331int wcn_set_he_ltf(struct sigma_dut *dut, const char *intf,
5332 enum qca_wlan_he_ltf_cfg ltf)
Subhani Shaik8e7a3052018-04-24 14:03:00 -07005333{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05305334 return wcn_wifi_test_config_set_u8(
5335 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_LTF, ltf);
Subhani Shaik8e7a3052018-04-24 14:03:00 -07005336}
5337
5338
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08005339static int nlvendor_sta_set_noack(struct sigma_dut *dut, const char *intf,
5340 int noack, enum qca_wlan_ac_type ac)
5341{
5342 struct nl_msg *msg;
5343 int ret = 0;
5344 struct nlattr *params;
5345 int ifindex;
5346
5347 ifindex = if_nametoindex(intf);
5348 if (ifindex == 0) {
5349 sigma_dut_print(dut, DUT_MSG_ERROR,
5350 "%s: Index for interface %s failed",
5351 __func__, intf);
5352 return -1;
5353 }
5354
5355 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5356 NL80211_CMD_VENDOR)) ||
5357 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5358 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5359 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5360 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5361 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5362 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_NO_ACK,
5363 noack) ||
5364 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_NO_ACK_AC,
5365 ac)) {
5366 sigma_dut_print(dut, DUT_MSG_ERROR,
5367 "%s: err in adding vendor_cmd and vendor_data",
5368 __func__);
5369 nlmsg_free(msg);
5370 return -1;
5371 }
5372 nla_nest_end(msg, params);
5373
5374 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5375 if (ret) {
5376 sigma_dut_print(dut, DUT_MSG_ERROR,
5377 "%s: err in send_and_recv_msgs, ret=%d",
5378 __func__, ret);
5379 }
5380 return ret;
5381}
5382
5383
5384static void wcn_sta_set_noack(struct sigma_dut *dut, const char *intf,
5385 const char *val)
5386{
5387 int noack, ret;
5388 char token[100];
5389 char *result;
5390 char *saveptr;
5391 enum qca_wlan_ac_type ac = QCA_WLAN_AC_BE;
5392
5393 strlcpy(token, val, sizeof(token));
5394 token[sizeof(token) - 1] = '\0';
5395 result = strtok_r(token, ":", &saveptr);
5396 while (result) {
5397 noack = strcasecmp(result, "Disable") != 0;
5398 ret = nlvendor_sta_set_noack(dut, intf, noack, ac);
5399 if (ret) {
5400 sigma_dut_print(dut, DUT_MSG_ERROR,
5401 "nlvendor_sta_set_noack failed for ac:%d, ret:%d",
5402 ac, ret);
5403 }
5404 result = strtok_r(NULL, ":", &saveptr);
5405 ac++;
5406 }
5407}
5408
Vinita S. Maloo7462e812020-05-22 15:16:04 +05305409
5410static int nlvendor_sta_set_phymode(struct sigma_dut *dut, const char *intf,
5411 enum qca_wlan_vendor_phy_mode val)
5412{
5413 struct nl_msg *msg;
5414 struct nlattr *params;
5415 int ifindex, ret;
5416
5417 ifindex = if_nametoindex(intf);
5418 if (ifindex == 0) {
5419 sigma_dut_print(dut, DUT_MSG_ERROR,
5420 "%s: Index for interface %s not found",
5421 __func__, intf);
5422 return -1;
5423 }
5424
5425 msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5426 NL80211_CMD_VENDOR);
5427 if (!msg) {
5428 sigma_dut_print(dut, DUT_MSG_ERROR,
5429 "%s: err in adding vendor_cmd", __func__);
5430 return -1;
5431 }
5432
5433 if (nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5434 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5435 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION)) {
5436 sigma_dut_print(dut, DUT_MSG_ERROR,
5437 "%s: err in adding vendor_attr", __func__);
5438 nlmsg_free(msg);
5439 return -1;
5440 }
5441
5442 params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
5443 if (!params || nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_PHY_MODE,
5444 val)) {
5445 sigma_dut_print(dut, DUT_MSG_ERROR,
5446 "%s: err in adding vendor_data", __func__);
5447 nlmsg_free(msg);
5448 return -1;
5449 }
5450
5451 nla_nest_end(msg, params);
5452 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5453 if (ret) {
5454 sigma_dut_print(dut, DUT_MSG_ERROR,
5455 "%s: err in send_and_recv_msgs, ret=%d (%s)",
5456 __func__, ret, strerror(-ret));
5457 return ret;
5458 }
5459
5460 return 0;
5461}
5462
5463
5464static enum qca_wlan_vendor_phy_mode get_qca_vendor_phymode(const char *val)
5465{
5466 if (strcmp(val, "11a") == 0) {
5467 /* IEEE80211_MODE_11A */
5468 return QCA_WLAN_VENDOR_PHY_MODE_11A;
5469 }
5470
5471 if (strcmp(val, "11g") == 0) {
5472 /* IEEE80211_MODE_11G */
5473 return QCA_WLAN_VENDOR_PHY_MODE_11G;
5474 }
5475
5476 if (strcmp(val, "11b") == 0) {
5477 /* IEEE80211_MODE_11B */
5478 return QCA_WLAN_VENDOR_PHY_MODE_11B;
5479 }
5480
5481 if (strcmp(val, "11n") == 0 ||
5482 strcmp(val, "11nl") == 0 ||
5483 strcmp(val, "11nl(nabg)") == 0) {
5484 /* IEEE80211_MODE_11AGN */
5485 return QCA_WLAN_VENDOR_PHY_MODE_11AGN;
5486 }
5487
5488 if (strcmp(val, "11ng") == 0) {
5489 /* IEEE80211_MODE_11NG_HT40 */
5490 return QCA_WLAN_VENDOR_PHY_MODE_11NG_HT40;
5491 }
5492
5493 if (strcmp(val, "AC") == 0 ||
5494 strcasecmp(val, "11AC") == 0) {
5495 /* IEEE80211_MODE_11AC_VHT80 */
5496 return QCA_WLAN_VENDOR_PHY_MODE_11AC_VHT80;
5497 }
5498
5499 if (strcmp(val, "11na") == 0 ||
5500 strcasecmp(val, "11an") == 0) {
5501 /* IEEE80211_MODE_11NA_HT40 */
5502 return QCA_WLAN_VENDOR_PHY_MODE_11NA_HT40;
5503 }
5504
5505 if (strcmp(val, "11ax") == 0 ||
5506 strcmp(val, "auto") == 0) {
5507 /* IEEE80211_MODE_AUTO */
5508 return QCA_WLAN_VENDOR_PHY_MODE_AUTO;
5509 }
5510
5511 return -1;
5512}
5513
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08005514#endif /* NL80211_SUPPORT */
5515
5516
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05305517static int get_phymode(const char *val)
5518{
5519 if (strcmp(val, "11a") == 0)
5520 return 1; /* IEEE80211_MODE_11A */
5521 if (strcmp(val, "11g") == 0)
5522 return 3; /* IEEE80211_MODE_11G */
5523 if (strcmp(val, "11b") == 0)
5524 return 2; /* IEEE80211_MODE_11B */
5525 if (strcmp(val, "11n") == 0 ||
5526 strcmp(val, "11nl") == 0 ||
5527 strcmp(val, "11nl(nabg)") == 0)
5528 return 22; /* IEEE80211_MODE_11AGN */
5529 if (strcmp(val, "11ng") == 0)
5530 return 13; /* IEEE80211_MODE_11NG_HT40 */
5531 if (strcmp(val, "AC") == 0 ||
5532 strcasecmp(val, "11AC") == 0)
5533 return 19; /* IEEE80211_MODE_11AC_VHT80 */
5534 if (strcmp(val, "11na") == 0 ||
5535 strcasecmp(val, "11an") == 0)
5536 return 14; /* IEEE80211_MODE_11NA_HT40 */
5537 if (strcmp(val, "11ax") == 0 ||
5538 strcmp(val, "auto") == 0)
5539 return 0; /* IEEE80211_MODE_AUTO */
5540 return -1;
5541}
5542
5543
5544static void sta_set_phymode(struct sigma_dut *dut, const char *intf,
5545 const char *val)
5546{
5547 char buf[100];
5548 int len, phymode;
Vinita S. Maloo7462e812020-05-22 15:16:04 +05305549#ifdef NL80211_SUPPORT
5550 enum qca_wlan_vendor_phy_mode qca_phymode;
5551
5552 qca_phymode = get_qca_vendor_phymode(val);
5553 if (qca_phymode == -1) {
5554 sigma_dut_print(dut, DUT_MSG_DEBUG,
5555 "Ignoring mode change for mode: %s",
5556 val);
5557 return;
5558 }
5559
5560 if (nlvendor_sta_set_phymode(dut, intf, qca_phymode) == 0)
5561 return;
5562#endif /* NL80211_SUPPORT */
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05305563
5564 phymode = get_phymode(val);
5565 if (phymode == -1) {
5566 sigma_dut_print(dut, DUT_MSG_DEBUG,
5567 "Ignoring mode change for mode: %s",
5568 val);
5569 return;
5570 }
5571
5572 len = snprintf(buf, sizeof(buf), "iwpriv %s setphymode %d", intf,
5573 phymode);
5574 if (len < 0 || len >= sizeof(buf)) {
5575 sigma_dut_print(dut, DUT_MSG_ERROR,
5576 "Failed to set phymode");
5577 return;
5578 }
5579
5580 if (system(buf) != 0)
5581 sigma_dut_print(dut, DUT_MSG_ERROR,
5582 "iwpriv setting of phymode failed");
5583}
5584
5585
Jouni Malinenf7222712019-06-13 01:50:21 +03005586static enum sigma_cmd_result
5587cmd_sta_preset_testparameters(struct sigma_dut *dut, struct sigma_conn *conn,
5588 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005589{
5590 const char *intf = get_param(cmd, "Interface");
5591 const char *val;
5592
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03005593 val = get_param(cmd, "FT_DS");
5594 if (val) {
5595 if (strcasecmp(val, "Enable") == 0) {
5596 dut->sta_ft_ds = 1;
5597 } else if (strcasecmp(val, "Disable") == 0) {
5598 dut->sta_ft_ds = 0;
5599 } else {
5600 send_resp(dut, conn, SIGMA_ERROR,
5601 "errorCode,Unsupported value for FT_DS");
5602 return STATUS_SENT_ERROR;
5603 }
Shivani Baranwal7aa48602021-09-29 10:53:38 +05305604 if (get_driver_type(dut) == DRIVER_WCN &&
5605 sta_config_params(dut, intf, STA_SET_FT_DS,
5606 dut->sta_ft_ds) != 0) {
5607 send_resp(dut, conn, SIGMA_ERROR,
5608 "errorCode,Failed to enable/disable FT_DS");
5609 return STATUS_SENT_ERROR;
5610 }
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03005611 }
5612
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005613 val = get_param(cmd, "Program");
Jouni Malinen1f6ae642018-06-07 23:56:13 +03005614 if (val && (strcasecmp(val, "HS2-R2") == 0 ||
5615 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005616 return cmd_sta_preset_testparameters_hs2_r2(dut, conn, intf,
5617 cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005618
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07005619 if (val && strcasecmp(val, "LOC") == 0)
5620 return loc_cmd_sta_preset_testparameters(dut, conn, cmd);
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02005621 if (val && strcasecmp(val, "60GHZ") == 0) {
5622 val = get_param(cmd, "WPS");
5623 if (val && strcasecmp(val, "disable") == 0) {
5624 dut->wps_disable = 1;
5625 sigma_dut_print(dut, DUT_MSG_INFO, "WPS disabled");
5626 } else {
5627 /* wps_disable can have other value from the previous
5628 * test, so make sure it has the correct value.
5629 */
5630 dut->wps_disable = 0;
5631 }
5632
5633 val = get_param(cmd, "P2P");
5634 if (val && strcasecmp(val, "disable") == 0)
5635 sigma_dut_print(dut, DUT_MSG_INFO, "P2P disabled");
5636 }
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07005637
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02005638 if (dut->program == PROGRAM_WPS && dut->band == WPS_BAND_60G)
5639 return cmd_sta_preset_testparameters_60ghz(dut, conn, cmd);
5640
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005641#ifdef ANDROID_NAN
5642 if (val && strcasecmp(val, "NAN") == 0)
5643 return nan_cmd_sta_preset_testparameters(dut, conn, cmd);
5644#endif /* ANDROID_NAN */
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07005645#ifdef MIRACAST
5646 if (val && (strcasecmp(val, "WFD") == 0 ||
5647 strcasecmp(val, "DisplayR2") == 0))
5648 return miracast_preset_testparameters(dut, conn, cmd);
5649#endif /* MIRACAST */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005650
Kiran Kumar Lokeredd086642020-06-04 00:29:26 -07005651 if (val &&
5652 (strcasecmp(val, "MBO") == 0 || strcasecmp(val, "HE") == 0)) {
Ashwini Patil68d02cd2017-01-10 15:39:16 +05305653 val = get_param(cmd, "Cellular_Data_Cap");
5654 if (val &&
5655 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
5656 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +05305657
5658 val = get_param(cmd, "Ch_Pref");
5659 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
5660 return 0;
5661
Ashwini Patilc63161e2017-04-13 16:30:23 +05305662 val = get_param(cmd, "BSS_Transition");
5663 if (val && mbo_set_bss_trans_req(dut, conn, intf, val) == 0)
5664 return 0;
5665
Ashwini Patila75de5a2017-04-13 16:35:05 +05305666 val = get_param(cmd, "Assoc_Disallow");
5667 if (val && mbo_set_assoc_disallow(dut, conn, intf, val) == 0)
5668 return 0;
5669
Ashwini Patil9183fdb2017-04-13 16:58:25 +05305670 val = get_param(cmd, "Roaming");
5671 if (val && mbo_set_roaming(dut, conn, intf, val) == 0)
5672 return 0;
5673
Ashwini Patil68d02cd2017-01-10 15:39:16 +05305674 return 1;
5675 }
5676
Ankita Bajaja2cb5672017-10-25 16:08:28 +05305677 if (val && strcasecmp(val, "OCE") == 0)
5678 return cmd_sta_preset_testparameters_oce(dut, conn, intf, cmd);
5679
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005680#if 0
5681 val = get_param(cmd, "Supplicant");
5682 if (val && strcasecmp(val, "Default") != 0) {
5683 send_resp(dut, conn, SIGMA_ERROR,
5684 "ErrorCode,Only default(Vendor) supplicant "
5685 "supported");
5686 return 0;
5687 }
5688#endif
5689
5690 val = get_param(cmd, "RTS");
5691 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005692 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005693 case DRIVER_ATHEROS:
5694 ath_sta_set_rts(dut, intf, val);
5695 break;
5696 default:
5697#if 0
5698 send_resp(dut, conn, SIGMA_ERROR,
5699 "ErrorCode,Setting RTS not supported");
5700 return 0;
5701#else
5702 sigma_dut_print(dut, DUT_MSG_DEBUG,
5703 "Setting RTS not supported");
5704 break;
5705#endif
5706 }
5707 }
5708
5709#if 0
5710 val = get_param(cmd, "FRGMNT");
5711 if (val) {
5712 /* TODO */
5713 send_resp(dut, conn, SIGMA_ERROR,
5714 "ErrorCode,Setting FRGMNT not supported");
5715 return 0;
5716 }
5717#endif
5718
5719#if 0
5720 val = get_param(cmd, "Preamble");
5721 if (val) {
5722 /* TODO: Long/Short */
5723 send_resp(dut, conn, SIGMA_ERROR,
5724 "ErrorCode,Setting Preamble not supported");
5725 return 0;
5726 }
5727#endif
5728
5729 val = get_param(cmd, "Mode");
5730 if (val) {
5731 if (strcmp(val, "11b") == 0 ||
5732 strcmp(val, "11g") == 0 ||
5733 strcmp(val, "11a") == 0 ||
5734 strcmp(val, "11n") == 0 ||
5735 strcmp(val, "11ng") == 0 ||
5736 strcmp(val, "11nl") == 0 ||
5737 strcmp(val, "11nl(nabg)") == 0 ||
5738 strcmp(val, "AC") == 0 ||
5739 strcmp(val, "11AC") == 0 ||
5740 strcmp(val, "11ac") == 0 ||
5741 strcmp(val, "11na") == 0 ||
Amarnath Hullur Subramanyamb0db2712018-01-30 19:40:35 -08005742 strcmp(val, "11an") == 0 ||
5743 strcmp(val, "11ax") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005744 /* STA supports all modes by default */
5745 } else {
5746 send_resp(dut, conn, SIGMA_ERROR,
5747 "ErrorCode,Setting Mode not supported");
5748 return 0;
5749 }
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08005750
5751 /* Change the mode only in case of testbed for HE program
5752 * and for 11a and 11g modes only. */
5753 if (dut->program == PROGRAM_HE &&
5754 dut->device_type == STA_testbed) {
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05305755 sta_set_phymode(dut, intf, val);
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08005756 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005757 }
5758
5759 val = get_param(cmd, "wmm");
5760 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005761 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005762 case DRIVER_ATHEROS:
5763 ath_sta_set_wmm(dut, intf, val);
5764 break;
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08005765 case DRIVER_WCN:
5766 wcn_sta_set_wmm(dut, intf, val);
5767 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005768 default:
5769 sigma_dut_print(dut, DUT_MSG_DEBUG,
5770 "Setting wmm not supported");
5771 break;
5772 }
5773 }
5774
5775 val = get_param(cmd, "Powersave");
5776 if (val) {
5777 if (strcmp(val, "0") == 0 || strcasecmp(val, "off") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005778 if (get_driver_type(dut) == DRIVER_WCN) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +05305779 if (set_power_save_wcn(dut, intf, 2) < 0)
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005780 return 0;
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005781 }
5782
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005783 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005784 "P2P_SET ps 0") < 0)
5785 return -2;
5786 /* Make sure test modes are disabled */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005787 wpa_command(get_station_ifname(dut), "P2P_SET ps 98");
5788 wpa_command(get_station_ifname(dut), "P2P_SET ps 96");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005789 } else if (strcmp(val, "1") == 0 ||
5790 strcasecmp(val, "PSPoll") == 0 ||
5791 strcasecmp(val, "on") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005792 if (get_driver_type(dut) == DRIVER_WCN) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +05305793 if (set_power_save_wcn(dut, intf, 1) < 0)
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005794 return 0;
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005795 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005796 /* Disable default power save mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005797 wpa_command(get_station_ifname(dut), "P2P_SET ps 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005798 /* Enable PS-Poll test mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005799 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005800 "P2P_SET ps 97") < 0 ||
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005801 wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005802 "P2P_SET ps 99") < 0)
5803 return -2;
5804 } else if (strcmp(val, "2") == 0 ||
5805 strcasecmp(val, "Fast") == 0) {
5806 /* TODO */
5807 send_resp(dut, conn, SIGMA_ERROR,
5808 "ErrorCode,Powersave=Fast not supported");
5809 return 0;
5810 } else if (strcmp(val, "3") == 0 ||
5811 strcasecmp(val, "PSNonPoll") == 0) {
5812 /* Make sure test modes are disabled */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005813 wpa_command(get_station_ifname(dut), "P2P_SET ps 98");
5814 wpa_command(get_station_ifname(dut), "P2P_SET ps 96");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005815
5816 /* Enable default power save mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005817 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005818 "P2P_SET ps 1") < 0)
5819 return -2;
5820 } else
5821 return -1;
5822 }
5823
5824 val = get_param(cmd, "NoAck");
5825 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005826 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005827 case DRIVER_ATHEROS:
5828 ath_sta_set_noack(dut, intf, val);
5829 break;
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08005830#ifdef NL80211_SUPPORT
5831 case DRIVER_WCN:
5832 wcn_sta_set_noack(dut, intf, val);
5833 break;
5834#endif /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005835 default:
5836 send_resp(dut, conn, SIGMA_ERROR,
5837 "ErrorCode,Setting NoAck not supported");
5838 return 0;
5839 }
5840 }
5841
5842 val = get_param(cmd, "IgnoreChswitchProhibit");
5843 if (val) {
5844 /* TODO: Enabled/disabled */
5845 if (strcasecmp(val, "Enabled") == 0) {
5846 send_resp(dut, conn, SIGMA_ERROR,
5847 "ErrorCode,Enabling IgnoreChswitchProhibit "
5848 "not supported");
5849 return 0;
5850 }
5851 }
5852
5853 val = get_param(cmd, "TDLS");
5854 if (val) {
5855 if (strcasecmp(val, "Disabled") == 0) {
5856 if (wpa_command(intf, "SET tdls_disabled 1")) {
5857 send_resp(dut, conn, SIGMA_ERROR,
5858 "ErrorCode,Failed to disable TDLS");
5859 return 0;
5860 }
5861 } else if (strcasecmp(val, "Enabled") == 0) {
5862 if (wpa_command(intf, "SET tdls_disabled 0")) {
5863 send_resp(dut, conn, SIGMA_ERROR,
5864 "ErrorCode,Failed to enable TDLS");
5865 return 0;
5866 }
5867 } else {
5868 send_resp(dut, conn, SIGMA_ERROR,
5869 "ErrorCode,Unsupported TDLS value");
5870 return 0;
5871 }
5872 }
5873
5874 val = get_param(cmd, "TDLSmode");
5875 if (val) {
5876 if (strcasecmp(val, "Default") == 0) {
5877 wpa_command(intf, "SET tdls_testing 0");
5878 } else if (strcasecmp(val, "APProhibit") == 0) {
5879 if (wpa_command(intf, "SET tdls_testing 0x400")) {
5880 send_resp(dut, conn, SIGMA_ERROR,
5881 "ErrorCode,Failed to enable ignore "
5882 "APProhibit TDLS mode");
5883 return 0;
5884 }
5885 } else if (strcasecmp(val, "HiLoMac") == 0) {
5886 /* STA should respond with TDLS setup req for a TDLS
5887 * setup req */
5888 if (wpa_command(intf, "SET tdls_testing 0x80")) {
5889 send_resp(dut, conn, SIGMA_ERROR,
5890 "ErrorCode,Failed to enable HiLoMac "
5891 "TDLS mode");
5892 return 0;
5893 }
5894 } else if (strcasecmp(val, "WeakSecurity") == 0) {
5895 /*
5896 * Since all security modes are enabled by default when
5897 * Sigma control is used, there is no need to do
5898 * anything here.
5899 */
5900 } else if (strcasecmp(val, "ExistLink") == 0) {
5901 /*
5902 * Since we allow new TDLS Setup Request even if there
5903 * is an existing link, nothing needs to be done for
5904 * this.
5905 */
5906 } else {
5907 /* TODO:
5908 * ExistLink: STA should send TDLS setup req even if
5909 * direct link already exists
5910 */
5911 send_resp(dut, conn, SIGMA_ERROR,
5912 "ErrorCode,Unsupported TDLSmode value");
5913 return 0;
5914 }
5915 }
5916
5917 val = get_param(cmd, "FakePubKey");
5918 if (val && atoi(val) && wpa_command(intf, "SET wps_corrupt_pkhash 1")) {
5919 send_resp(dut, conn, SIGMA_ERROR,
5920 "ErrorCode,Failed to enable FakePubKey");
5921 return 0;
5922 }
5923
Amarnath Hullur Subramanyamae1042b2018-02-22 21:52:52 -08005924#ifdef NL80211_SUPPORT
5925 val = get_param(cmd, "FrgmntSupport");
5926 if (val) {
5927 if (strcasecmp(val, "Enable") == 0) {
5928 if (sta_set_he_fragmentation(dut, intf,
5929 HE_FRAG_LEVEL1)) {
5930 send_resp(dut, conn, SIGMA_ERROR,
5931 "ErrorCode,Failed to enable HE Fragmentation");
5932 return 0;
5933 }
5934 } else if (strcasecmp(val, "Disable") == 0) {
5935 if (sta_set_he_fragmentation(dut, intf,
5936 HE_FRAG_DISABLE)) {
5937 send_resp(dut, conn, SIGMA_ERROR,
5938 "ErrorCode,Failed to disable HE Fragmentation");
5939 return 0;
5940 }
5941 }
5942 }
5943#endif /* NL80211_SUPPORT */
5944
Vinita S. Maloo8a4779c2020-06-22 19:32:37 +05305945 val = get_param(cmd, "IncludeMSCSDescriptor");
5946 if (val && strcasecmp(val, "1") == 0) {
5947 char buf[128];
5948 int len;
5949
5950 len = snprintf(buf, sizeof(buf),
Veerendranath Jakkam62cde372020-08-19 18:03:06 +05305951 "MSCS add up_bitmap=F0 up_limit=7 stream_timeout=60000 frame_classifier=045F%032x",
Vinita S. Maloo8a4779c2020-06-22 19:32:37 +05305952 0);
5953
5954 if (len < 0 || len >= sizeof(buf)) {
5955 sigma_dut_print(dut, DUT_MSG_ERROR,
5956 "Failed to build MSCS Descriptor IE");
5957 return ERROR_SEND_STATUS;
5958 }
5959
5960 if (wpa_command(intf, buf) != 0) {
5961 send_resp(dut, conn, SIGMA_ERROR,
5962 "ErrorCode,Failed to include MSCS descriptor");
5963 return STATUS_SENT_ERROR;
5964 }
5965 }
5966
Vinita S. Maloo2287f142021-02-01 16:17:09 +05305967 val = get_param(cmd, "SCSSupport");
5968 if (val) {
5969 char buf[30];
5970 int disable_scs, len;
5971
5972 if (strcasecmp(val, "Enable") == 0) {
5973 disable_scs = 0;
5974 } else if (strcasecmp(val, "Disable") == 0) {
5975 disable_scs = 1;
5976 } else {
5977 sigma_dut_print(dut, DUT_MSG_ERROR,
5978 "Invalid SCSsupport parameter");
5979 return INVALID_SEND_STATUS;
5980 }
5981
5982 len = snprintf(buf, sizeof(buf), "SET disable_scs_support %d",
5983 disable_scs);
5984 if (len < 0 || len >= sizeof(buf) ||
5985 wpa_command(intf, buf) != 0) {
5986 send_resp(dut, conn, SIGMA_ERROR,
5987 "ErrorCode,Failed to update SCS support");
5988 return STATUS_SENT_ERROR;
5989 }
5990 }
5991
Vinita S. Maloo83dee552021-04-12 16:47:47 +05305992 val = get_param(cmd, "MSCSSupport");
5993 if (val) {
5994 char buf[30];
5995 int disable_mscs, len;
5996
5997 if (strcasecmp(val, "Enable") == 0) {
5998 disable_mscs = 0;
5999 } else if (strcasecmp(val, "Disable") == 0) {
6000 disable_mscs = 1;
6001 } else {
6002 sigma_dut_print(dut, DUT_MSG_ERROR,
6003 "Invalid MSCSsupport parameter");
6004 return INVALID_SEND_STATUS;
6005 }
6006
6007 len = snprintf(buf, sizeof(buf), "SET disable_mscs_support %d",
6008 disable_mscs);
6009 if (len < 0 || len >= sizeof(buf) ||
6010 wpa_command(intf, buf) != 0) {
6011 send_resp(dut, conn, SIGMA_ERROR,
6012 "ErrorCode,Failed to update MSCS support");
6013 return STATUS_SENT_ERROR;
6014 }
6015 }
6016
Veerendranath Jakkama16cdc82021-09-12 16:44:22 +05306017 val = get_param(cmd, "DSCPPolicyCapability");
6018 if (val) {
6019 char buf[35];
6020 int len;
6021
6022 if (strcasecmp(val, "Enable") == 0) {
6023 len = snprintf(buf, sizeof(buf),
6024 "SET enable_dscp_policy_capa 1");
6025 } else if (strcasecmp(val, "Disable") == 0) {
6026 len = snprintf(buf, sizeof(buf),
6027 "SET enable_dscp_policy_capa 0");
6028 } else {
6029 sigma_dut_print(dut, DUT_MSG_ERROR,
6030 "Invalid DSCP policy parameter");
6031 return INVALID_SEND_STATUS;
6032 }
6033
6034 if (len < 0 || len >= sizeof(buf) ||
6035 wpa_command(intf, buf) != 0) {
6036 send_resp(dut, conn, SIGMA_ERROR,
6037 "ErrorCode,Failed to update DSCP policy capability");
6038 return STATUS_SENT_ERROR;
6039 }
6040 }
6041
6042 val = get_param(cmd, "DSCPPolicyRespParams");
6043 if (val) {
6044 if (strcasecmp(val, "RejectAll") == 0) {
6045 dut->reject_dscp_policies = 1;
6046 dut->dscp_reject_resp_code = DSCP_POLICY_REJECT;
6047 } else if (strcasecmp(val, "AcceptAll") == 0) {
6048 dut->reject_dscp_policies = 0;
6049 }
6050 }
6051
6052 val = get_param(cmd, "DSCPPolicyResp_StatusCode");
6053 if (val)
6054 dut->dscp_reject_resp_code = atoi(val);
6055
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006056 return 1;
6057}
6058
6059
6060static const char * ath_get_radio_name(const char *radio_name)
6061{
6062 if (radio_name == NULL)
6063 return "wifi0";
6064 if (strcmp(radio_name, "wifi1") == 0)
6065 return "wifi1";
6066 if (strcmp(radio_name, "wifi2") == 0)
6067 return "wifi2";
6068 return "wifi0";
6069}
6070
6071
6072static void ath_sta_set_txsp_stream(struct sigma_dut *dut, const char *intf,
6073 const char *val)
6074{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006075 unsigned int vht_mcsmap = 0;
6076 int txchainmask = 0;
6077 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
6078
6079 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
6080 if (dut->testbed_flag_txsp == 1) {
6081 vht_mcsmap = 0xfffc;
6082 dut->testbed_flag_txsp = 0;
6083 } else {
6084 vht_mcsmap = 0xfffe;
6085 }
6086 txchainmask = 1;
6087 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
6088 if (dut->testbed_flag_txsp == 1) {
6089 vht_mcsmap = 0xfff0;
6090 dut->testbed_flag_txsp = 0;
6091 } else {
6092 vht_mcsmap = 0xfffa;
6093 }
6094 txchainmask = 3;
6095 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
6096 if (dut->testbed_flag_txsp == 1) {
6097 vht_mcsmap = 0xffc0;
6098 dut->testbed_flag_txsp = 0;
6099 } else {
6100 vht_mcsmap = 0xffea;
6101 }
6102 txchainmask = 7;
6103 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
6104 if (dut->testbed_flag_txsp == 1) {
6105 vht_mcsmap = 0xff00;
6106 dut->testbed_flag_txsp = 0;
6107 } else {
6108 vht_mcsmap = 0xffaa;
6109 }
6110 txchainmask = 15;
6111 } else {
6112 if (dut->testbed_flag_txsp == 1) {
6113 vht_mcsmap = 0xffc0;
6114 dut->testbed_flag_txsp = 0;
6115 } else {
6116 vht_mcsmap = 0xffea;
6117 }
6118 }
6119
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006120 if (txchainmask)
6121 run_iwpriv(dut, basedev, "txchainmask %d", txchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006122
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006123 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006124}
6125
6126
6127static void ath_sta_set_rxsp_stream(struct sigma_dut *dut, const char *intf,
6128 const char *val)
6129{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006130 unsigned int vht_mcsmap = 0;
6131 int rxchainmask = 0;
6132 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
6133
6134 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
6135 if (dut->testbed_flag_rxsp == 1) {
6136 vht_mcsmap = 0xfffc;
6137 dut->testbed_flag_rxsp = 0;
6138 } else {
6139 vht_mcsmap = 0xfffe;
6140 }
6141 rxchainmask = 1;
6142 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
6143 if (dut->testbed_flag_rxsp == 1) {
6144 vht_mcsmap = 0xfff0;
6145 dut->testbed_flag_rxsp = 0;
6146 } else {
6147 vht_mcsmap = 0xfffa;
6148 }
6149 rxchainmask = 3;
6150 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
6151 if (dut->testbed_flag_rxsp == 1) {
6152 vht_mcsmap = 0xffc0;
6153 dut->testbed_flag_rxsp = 0;
6154 } else {
6155 vht_mcsmap = 0xffea;
6156 }
6157 rxchainmask = 7;
6158 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
6159 if (dut->testbed_flag_rxsp == 1) {
6160 vht_mcsmap = 0xff00;
6161 dut->testbed_flag_rxsp = 0;
6162 } else {
6163 vht_mcsmap = 0xffaa;
6164 }
6165 rxchainmask = 15;
6166 } else {
6167 if (dut->testbed_flag_rxsp == 1) {
6168 vht_mcsmap = 0xffc0;
6169 dut->testbed_flag_rxsp = 0;
6170 } else {
6171 vht_mcsmap = 0xffea;
6172 }
6173 }
6174
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006175 if (rxchainmask)
6176 run_iwpriv(dut, basedev, "rxchainmask %d", rxchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006177
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006178 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006179}
6180
6181
6182void ath_set_zero_crc(struct sigma_dut *dut, const char *val)
6183{
6184 if (strcasecmp(val, "enable") == 0) {
6185 if (system("athdiag --set --address=0x2a204 --and=0xbfffffff")
6186 != 0) {
6187 sigma_dut_print(dut, DUT_MSG_ERROR,
6188 "Disable BB_VHTSIGB_CRC_CALC failed");
6189 }
6190
6191 if (system("athdiag --set --address=0x2a204 --or=0x80000000")
6192 != 0) {
6193 sigma_dut_print(dut, DUT_MSG_ERROR,
6194 "Enable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
6195 }
6196 } else {
6197 if (system("athdiag --set --address=0x2a204 --and=0x7fffffff")
6198 != 0) {
6199 sigma_dut_print(dut, DUT_MSG_ERROR,
6200 "Disable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
6201 }
6202
6203 if (system("athdiag --set --address=0x2a204 --or=0x40000000")
6204 != 0) {
6205 sigma_dut_print(dut, DUT_MSG_ERROR,
6206 "Enable BB_VHTSIGB_CRC_CALC failed");
6207 }
6208 }
6209}
6210
6211
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08006212static int wcn_sta_set_width(struct sigma_dut *dut, const char *intf,
6213 const char *val)
6214{
6215 char buf[60];
6216
Shivani Baranwal2a572842021-09-16 12:27:15 +05306217#ifdef NL80211_SUPPORT
6218 enum nl80211_chan_width qca_channel_width;
6219
6220 if (strcmp(val, "20") == 0) {
6221 qca_channel_width = NL80211_CHAN_WIDTH_20;
6222 dut->chwidth = 0;
6223 } else if (strcmp(val, "40") == 0) {
6224 qca_channel_width = NL80211_CHAN_WIDTH_40;
6225 dut->chwidth = 1;
6226 } else if (strcmp(val, "80") == 0) {
6227 qca_channel_width = NL80211_CHAN_WIDTH_80;
6228 dut->chwidth = 2;
6229 } else if (strcmp(val, "160") == 0) {
6230 qca_channel_width = NL80211_CHAN_WIDTH_160;
6231 dut->chwidth = 3;
6232 } else if (strcasecmp(val, "Auto") == 0) {
6233 return 0;
6234 } else {
6235 sigma_dut_print(dut, DUT_MSG_ERROR, "WIDTH %s not supported",
6236 val);
6237 return -1;
6238 }
6239 if (sta_config_params(dut, intf, STA_SET_CHAN_WIDTH,
6240 qca_channel_width) == 0)
6241 return 0;
6242#endif /* NL80211_SUPPORT */
6243
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08006244 if (strcmp(val, "20") == 0) {
6245 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
6246 dut->chwidth = 0;
6247 } else if (strcmp(val, "40") == 0) {
6248 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 1", intf);
6249 dut->chwidth = 1;
6250 } else if (strcmp(val, "80") == 0) {
6251 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
6252 dut->chwidth = 2;
Sunil Duttb1cccac2018-05-22 21:03:12 +05306253 } else if (strcasecmp(val, "Auto") == 0) {
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08006254 buf[0] = '\0';
6255 } else {
6256 sigma_dut_print(dut, DUT_MSG_ERROR, "WIDTH %s not supported",
6257 val);
6258 return -1;
6259 }
6260
6261 if (buf[0] != '\0' && system(buf) != 0) {
6262 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv chwidth failed");
6263 return -1;
6264 }
6265
6266 return 0;
6267}
6268
6269
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08006270static int nlvendor_sta_set_addba_reject(struct sigma_dut *dut,
6271 const char *intf, int addbareject)
6272{
6273#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05306274 return wcn_wifi_test_config_set_u8(
6275 dut, intf,
6276 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ACCEPT_ADDBA_REQ,
6277 !addbareject);
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08006278#else /* NL80211_SUPPORT */
6279 sigma_dut_print(dut, DUT_MSG_ERROR,
6280 "ADDBA_REJECT cannot be set without NL80211_SUPPORT defined");
6281 return -1;
6282#endif /* NL80211_SUPPORT */
6283}
6284
6285
6286static int sta_set_addba_reject(struct sigma_dut *dut, const char *intf,
6287 int addbareject)
6288{
6289 int ret;
6290
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006291 switch (get_driver_type(dut)) {
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08006292 case DRIVER_WCN:
6293 ret = nlvendor_sta_set_addba_reject(dut, intf, addbareject);
6294 if (ret) {
6295 sigma_dut_print(dut, DUT_MSG_ERROR,
6296 "nlvendor_sta_set_addba_reject failed, ret:%d",
6297 ret);
6298 return ret;
6299 }
6300 break;
6301 default:
6302 sigma_dut_print(dut, DUT_MSG_ERROR,
6303 "errorCode,Unsupported ADDBA_REJECT with the current driver");
6304 ret = -1;
6305 break;
6306 }
6307
6308 return ret;
6309}
6310
6311
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08006312static int nlvendor_config_send_addba(struct sigma_dut *dut, const char *intf,
6313 int enable)
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08006314{
6315#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05306316 return wcn_wifi_test_config_set_u8(
6317 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SEND_ADDBA_REQ,
6318 enable);
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08006319#else /* NL80211_SUPPORT */
6320 sigma_dut_print(dut, DUT_MSG_ERROR,
6321 "Disable addba not possible without NL80211_SUPPORT defined");
6322 return -1;
6323#endif /* NL80211_SUPPORT */
6324}
6325
6326
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05306327#ifdef NL80211_SUPPORT
6328static int nl80211_sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
6329{
6330 struct nl_msg *msg;
6331 int ret = 0;
6332 int ifindex;
6333
6334 ifindex = if_nametoindex(intf);
6335 if (ifindex == 0) {
6336 sigma_dut_print(dut, DUT_MSG_ERROR,
6337 "%s: Index for interface %s failed",
6338 __func__, intf);
6339 return -1;
6340 }
6341
6342 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6343 NL80211_CMD_SET_WIPHY)) ||
6344 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) {
6345 sigma_dut_print(dut, DUT_MSG_ERROR,
6346 "%s: err in adding RTS threshold",
6347 __func__);
6348 nlmsg_free(msg);
6349 return -1;
6350 }
6351
6352 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6353 if (ret) {
6354 sigma_dut_print(dut, DUT_MSG_ERROR,
6355 "%s: err in send_and_recv_msgs, ret=%d",
6356 __func__, ret);
6357 }
6358 return ret;
6359}
6360#endif /* NL80211_SUPPORT */
6361
6362
6363static int sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
6364{
6365 char buf[100];
6366
6367#ifdef NL80211_SUPPORT
6368 if (nl80211_sta_set_rts(dut, intf, val) == 0)
6369 return 0;
6370 sigma_dut_print(dut, DUT_MSG_DEBUG,
6371 "Fall back to using iwconfig for setting RTS threshold");
6372#endif /* NL80211_SUPPORT */
6373
6374 snprintf(buf, sizeof(buf), "iwconfig %s rts %d", intf, val);
6375 if (system(buf) != 0) {
6376 sigma_dut_print(dut, DUT_MSG_ERROR,
6377 "Failed to set RTS threshold %d", val);
6378 return -1;
6379 }
6380 return 0;
6381}
6382
6383
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006384static enum sigma_cmd_result
6385cmd_sta_set_wireless_common(const char *intf, struct sigma_dut *dut,
6386 struct sigma_conn *conn, struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006387{
6388 const char *val;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08006389 int ampdu = -1, addbareject = -1;
Jouni Malinen3aa72862019-05-29 23:14:51 +03006390 char buf[128];
6391 int res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006392
6393 val = get_param(cmd, "40_INTOLERANT");
6394 if (val) {
6395 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
6396 /* TODO: iwpriv ht40intol through wpa_supplicant */
6397 send_resp(dut, conn, SIGMA_ERROR,
6398 "ErrorCode,40_INTOLERANT not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006399 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006400 }
6401 }
6402
6403 val = get_param(cmd, "ADDBA_REJECT");
6404 if (val) {
6405 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
6406 /* reject any ADDBA with status "decline" */
6407 ampdu = 0;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08006408 addbareject = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006409 } else {
6410 /* accept ADDBA */
6411 ampdu = 1;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08006412 addbareject = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006413 }
6414 }
6415
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08006416 if (addbareject >= 0 &&
6417 sta_set_addba_reject(dut, intf, addbareject) < 0) {
6418 send_resp(dut, conn, SIGMA_ERROR,
6419 "ErrorCode,set addba_reject failed");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006420 return STATUS_SENT_ERROR;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08006421 }
6422
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006423 val = get_param(cmd, "AMPDU");
6424 if (val) {
6425 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
6426 /* enable AMPDU Aggregation */
6427 if (ampdu == 0) {
6428 send_resp(dut, conn, SIGMA_ERROR,
6429 "ErrorCode,Mismatch in "
6430 "addba_reject/ampdu - "
6431 "not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006432 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006433 }
6434 ampdu = 1;
6435 } else {
6436 /* disable AMPDU Aggregation */
6437 if (ampdu == 1) {
6438 send_resp(dut, conn, SIGMA_ERROR,
6439 "ErrorCode,Mismatch in "
6440 "addba_reject/ampdu - "
6441 "not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006442 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006443 }
6444 ampdu = 0;
6445 }
6446 }
6447
6448 if (ampdu >= 0) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08006449 int ret;
6450
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006451 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s A-MPDU aggregation",
6452 ampdu ? "Enabling" : "Disabling");
6453 snprintf(buf, sizeof(buf), "SET ampdu %d", ampdu);
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07006454 if (wpa_command(intf, buf) < 0 &&
6455 iwpriv_sta_set_ampdu(dut, intf, ampdu) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006456 send_resp(dut, conn, SIGMA_ERROR,
6457 "ErrorCode,set aggr failed");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006458 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006459 }
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08006460
6461 if (ampdu == 0) {
6462 /* Disable sending of addba using nl vendor command */
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08006463 ret = nlvendor_config_send_addba(dut, intf, 0);
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08006464 if (ret) {
6465 sigma_dut_print(dut, DUT_MSG_ERROR,
6466 "Failed to disable addba, ret:%d",
6467 ret);
6468 }
6469 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006470 }
6471
6472 val = get_param(cmd, "AMSDU");
6473 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006474 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006475 case DRIVER_ATHEROS:
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08006476 case DRIVER_WCN:
6477 iwpriv_sta_set_amsdu(dut, intf, val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006478 break;
6479 default:
6480 if (strcmp(val, "1") == 0 ||
6481 strcasecmp(val, "Enable") == 0) {
6482 /* Enable AMSDU Aggregation */
6483 send_resp(dut, conn, SIGMA_ERROR,
6484 "ErrorCode,AMSDU aggregation not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006485 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006486 }
6487 break;
6488 }
6489 }
6490
6491 val = get_param(cmd, "STBC_RX");
6492 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006493 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006494 case DRIVER_ATHEROS:
6495 ath_sta_set_stbc(dut, intf, val);
6496 break;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05306497 case DRIVER_WCN:
6498 wcn_sta_set_stbc(dut, intf, val);
6499 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006500 default:
6501 send_resp(dut, conn, SIGMA_ERROR,
6502 "ErrorCode,STBC_RX not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006503 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006504 }
6505 }
6506
6507 val = get_param(cmd, "WIDTH");
6508 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006509 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006510 case DRIVER_WCN:
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08006511 if (wcn_sta_set_width(dut, intf, val) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006512 send_resp(dut, conn, SIGMA_ERROR,
6513 "ErrorCode,Failed to set WIDTH");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006514 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006515 }
6516 break;
6517 case DRIVER_ATHEROS:
6518 if (ath_set_width(dut, conn, intf, val) < 0)
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006519 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006520 break;
6521 default:
6522 sigma_dut_print(dut, DUT_MSG_ERROR,
6523 "Setting WIDTH not supported");
6524 break;
6525 }
6526 }
6527
6528 val = get_param(cmd, "SMPS");
6529 if (val) {
6530 /* TODO: Dynamic/0, Static/1, No Limit/2 */
6531 send_resp(dut, conn, SIGMA_ERROR,
6532 "ErrorCode,SMPS not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006533 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006534 }
6535
6536 val = get_param(cmd, "TXSP_STREAM");
6537 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006538 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006539 case DRIVER_WCN:
6540 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
6541 send_resp(dut, conn, SIGMA_ERROR,
6542 "ErrorCode,Failed to set TXSP_STREAM");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006543 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006544 }
6545 break;
6546 case DRIVER_ATHEROS:
6547 ath_sta_set_txsp_stream(dut, intf, val);
6548 break;
6549 default:
6550 sigma_dut_print(dut, DUT_MSG_ERROR,
6551 "Setting TXSP_STREAM not supported");
6552 break;
6553 }
6554 }
6555
6556 val = get_param(cmd, "RXSP_STREAM");
6557 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006558 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006559 case DRIVER_WCN:
6560 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
6561 send_resp(dut, conn, SIGMA_ERROR,
6562 "ErrorCode,Failed to set RXSP_STREAM");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006563 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006564 }
6565 break;
6566 case DRIVER_ATHEROS:
6567 ath_sta_set_rxsp_stream(dut, intf, val);
6568 break;
6569 default:
6570 sigma_dut_print(dut, DUT_MSG_ERROR,
6571 "Setting RXSP_STREAM not supported");
6572 break;
6573 }
6574 }
6575
6576 val = get_param(cmd, "DYN_BW_SGNL");
6577 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006578 switch (get_driver_type(dut)) {
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08006579 case DRIVER_WCN:
Peng Xuc59afd32016-11-21 15:01:11 -08006580 if (strcasecmp(val, "enable") == 0) {
6581 snprintf(buf, sizeof(buf),
6582 "iwpriv %s cwmenable 1", intf);
6583 if (system(buf) != 0) {
6584 sigma_dut_print(dut, DUT_MSG_ERROR,
6585 "iwpriv cwmenable 1 failed");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006586 return ERROR_SEND_STATUS;
Peng Xuc59afd32016-11-21 15:01:11 -08006587 }
6588 } else if (strcasecmp(val, "disable") == 0) {
6589 snprintf(buf, sizeof(buf),
6590 "iwpriv %s cwmenable 0", intf);
6591 if (system(buf) != 0) {
6592 sigma_dut_print(dut, DUT_MSG_ERROR,
6593 "iwpriv cwmenable 0 failed");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006594 return ERROR_SEND_STATUS;
Peng Xuc59afd32016-11-21 15:01:11 -08006595 }
6596 } else {
6597 sigma_dut_print(dut, DUT_MSG_ERROR,
6598 "Unsupported DYN_BW_SGL");
6599 }
6600
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006601 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
6602 if (system(buf) != 0) {
6603 sigma_dut_print(dut, DUT_MSG_ERROR,
6604 "Failed to set cts_cbw in DYN_BW_SGNL");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006605 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006606 }
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08006607 break;
6608 case DRIVER_ATHEROS:
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07006609 novap_reset(dut, intf, 1);
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08006610 ath_config_dyn_bw_sig(dut, intf, val);
6611 break;
6612 default:
6613 sigma_dut_print(dut, DUT_MSG_ERROR,
6614 "Failed to set DYN_BW_SGNL");
6615 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006616 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006617 }
6618
6619 val = get_param(cmd, "RTS_FORCE");
6620 if (val) {
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07006621 novap_reset(dut, intf, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006622 if (strcasecmp(val, "Enable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05306623 if (sta_set_rts(dut, intf, 64) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02006624 sigma_dut_print(dut, DUT_MSG_ERROR,
6625 "Failed to set RTS_FORCE 64");
6626 }
Jouni Malinen3aa72862019-05-29 23:14:51 +03006627 res = snprintf(buf, sizeof(buf),
6628 "wifitool %s beeliner_fw_test 100 1",
6629 intf);
6630 if (res < 0 || res >= sizeof(buf) || system(buf) != 0) {
priyadharshini gowthaman270870e2015-12-09 10:10:23 -08006631 sigma_dut_print(dut, DUT_MSG_ERROR,
6632 "wifitool beeliner_fw_test 100 1 failed");
6633 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006634 } else if (strcasecmp(val, "Disable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05306635 if (sta_set_rts(dut, intf, 2347) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02006636 sigma_dut_print(dut, DUT_MSG_ERROR,
6637 "Failed to set RTS_FORCE 2347");
6638 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006639 } else {
6640 send_resp(dut, conn, SIGMA_ERROR,
6641 "ErrorCode,RTS_FORCE value not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006642 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006643 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006644 }
6645
6646 val = get_param(cmd, "CTS_WIDTH");
6647 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006648 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006649 case DRIVER_WCN:
6650 if (wcn_sta_set_cts_width(dut, intf, val) < 0) {
6651 send_resp(dut, conn, SIGMA_ERROR,
6652 "ErrorCode,Failed to set CTS_WIDTH");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006653 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006654 }
6655 break;
6656 case DRIVER_ATHEROS:
6657 ath_set_cts_width(dut, intf, val);
6658 break;
6659 default:
6660 sigma_dut_print(dut, DUT_MSG_ERROR,
6661 "Setting CTS_WIDTH not supported");
6662 break;
6663 }
6664 }
6665
6666 val = get_param(cmd, "BW_SGNL");
6667 if (val) {
6668 if (strcasecmp(val, "Enable") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006669 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006670 } else if (strcasecmp(val, "Disable") == 0) {
6671 /* TODO: Disable */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006672 } else {
6673 send_resp(dut, conn, SIGMA_ERROR,
6674 "ErrorCode,BW_SGNL value not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006675 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006676 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006677 }
6678
6679 val = get_param(cmd, "Band");
6680 if (val) {
6681 if (strcmp(val, "2.4") == 0 || strcmp(val, "5") == 0) {
6682 /* STA supports all bands by default */
6683 } else {
6684 send_resp(dut, conn, SIGMA_ERROR,
6685 "ErrorCode,Unsupported Band");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006686 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006687 }
6688 }
6689
6690 val = get_param(cmd, "zero_crc");
6691 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006692 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006693 case DRIVER_ATHEROS:
6694 ath_set_zero_crc(dut, val);
6695 break;
6696 default:
6697 break;
6698 }
6699 }
6700
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006701 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006702}
6703
6704
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006705static int sta_set_force_mcs(struct sigma_dut *dut, int force, int mcs)
6706{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006707 switch (get_driver_type(dut)) {
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006708#ifdef __linux__
6709 case DRIVER_WIL6210:
6710 return wil6210_set_force_mcs(dut, force, mcs);
6711#endif /* __linux__ */
6712 default:
6713 sigma_dut_print(dut, DUT_MSG_ERROR,
6714 "Unsupported sta_set_force_mcs with the current driver");
6715 return -1;
6716 }
6717}
6718
6719
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02006720static int sta_60g_force_rsn_ie(struct sigma_dut *dut, int state)
6721{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006722 switch (get_driver_type(dut)) {
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02006723#ifdef __linux__
6724 case DRIVER_WIL6210:
6725 return wil6210_force_rsn_ie(dut, state);
6726#endif /* __linux__ */
6727 default:
6728 sigma_dut_print(dut, DUT_MSG_ERROR,
6729 "Unsupported sta_60g_force_rsn_ie with the current driver");
6730 return -1;
6731 }
6732}
6733
6734
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006735static int sta_set_60g_common(struct sigma_dut *dut, struct sigma_conn *conn,
6736 struct sigma_cmd *cmd)
6737{
6738 const char *val;
6739 char buf[100];
6740
6741 val = get_param(cmd, "MSDUSize");
6742 if (val) {
6743 int mtu;
6744
6745 dut->amsdu_size = atoi(val);
6746 if (dut->amsdu_size > IEEE80211_MAX_DATA_LEN_DMG ||
6747 dut->amsdu_size < IEEE80211_SNAP_LEN_DMG) {
6748 sigma_dut_print(dut, DUT_MSG_ERROR,
6749 "MSDUSize %d is above max %d or below min %d",
6750 dut->amsdu_size,
6751 IEEE80211_MAX_DATA_LEN_DMG,
6752 IEEE80211_SNAP_LEN_DMG);
6753 dut->amsdu_size = 0;
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006754 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006755 }
6756
6757 mtu = dut->amsdu_size - IEEE80211_SNAP_LEN_DMG;
6758 sigma_dut_print(dut, DUT_MSG_DEBUG,
6759 "Setting amsdu_size to %d", mtu);
6760 snprintf(buf, sizeof(buf), "ifconfig %s mtu %d",
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006761 get_station_ifname(dut), mtu);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006762
6763 if (system(buf) != 0) {
6764 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
6765 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006766 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006767 }
6768 }
6769
6770 val = get_param(cmd, "BAckRcvBuf");
6771 if (val) {
6772 dut->back_rcv_buf = atoi(val);
6773 if (dut->back_rcv_buf == 0) {
6774 sigma_dut_print(dut, DUT_MSG_ERROR,
6775 "Failed to convert %s or value is 0",
6776 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006777 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006778 }
6779
6780 sigma_dut_print(dut, DUT_MSG_DEBUG,
6781 "Setting BAckRcvBuf to %s", val);
6782 }
6783
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006784 val = get_param(cmd, "MCS_FixedRate");
6785 if (val) {
6786 if (sta_set_force_mcs(dut, 1, atoi(val))) {
6787 sigma_dut_print(dut, DUT_MSG_ERROR,
6788 "Failed to force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006789 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006790 }
6791 }
6792
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006793 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006794}
6795
6796
6797static int sta_pcp_start(struct sigma_dut *dut, struct sigma_conn *conn,
6798 struct sigma_cmd *cmd)
6799{
6800 int net_id;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006801 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006802 const char *val;
6803 char buf[100];
6804
6805 dut->mode = SIGMA_MODE_STATION;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006806 ifname = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006807 if (wpa_command(ifname, "PING") != 0) {
6808 sigma_dut_print(dut, DUT_MSG_ERROR, "Supplicant not running");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006809 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006810 }
6811
6812 wpa_command(ifname, "FLUSH");
6813 net_id = add_network_common(dut, conn, ifname, cmd);
6814 if (net_id < 0) {
6815 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add network");
6816 return net_id;
6817 }
6818
6819 /* TODO: mode=2 for the AP; in the future, replace for mode PCP */
6820 if (set_network(ifname, net_id, "mode", "2") < 0) {
6821 sigma_dut_print(dut, DUT_MSG_ERROR,
6822 "Failed to set supplicant network mode");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006823 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006824 }
6825
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02006826 if (set_network(ifname, net_id, "pbss", "1") < 0)
6827 return -2;
6828
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006829 sigma_dut_print(dut, DUT_MSG_DEBUG,
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02006830 "Supplicant set network with mode 2. network_id %d",
6831 net_id);
6832
6833 if (set_network(ifname, net_id, "wps_disabled", "0") < 0) {
6834 sigma_dut_print(dut, DUT_MSG_INFO,
6835 "Failed to set supplicant to WPS ENABLE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006836 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02006837 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006838
6839 val = get_param(cmd, "Security");
6840 if (val && strcasecmp(val, "OPEN") == 0) {
6841 dut->ap_key_mgmt = AP_OPEN;
6842 if (set_network(ifname, net_id, "key_mgmt", "NONE") < 0) {
6843 sigma_dut_print(dut, DUT_MSG_ERROR,
6844 "Failed to set supplicant to %s security",
6845 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006846 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006847 }
6848 } else if (val && strcasecmp(val, "WPA2-PSK") == 0) {
6849 dut->ap_key_mgmt = AP_WPA2_PSK;
6850 if (set_network(ifname, net_id, "key_mgmt", "WPA-PSK") < 0) {
6851 sigma_dut_print(dut, DUT_MSG_ERROR,
6852 "Failed to set supplicant to %s security",
6853 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006854 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006855 }
6856
6857 if (set_network(ifname, net_id, "proto", "RSN") < 0) {
6858 sigma_dut_print(dut, DUT_MSG_ERROR,
6859 "Failed to set supplicant to proto RSN");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006860 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006861 }
6862 } else if (val) {
6863 sigma_dut_print(dut, DUT_MSG_ERROR,
6864 "Requested Security %s is not supported on 60GHz",
6865 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006866 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006867 }
6868
6869 val = get_param(cmd, "Encrypt");
6870 if (val && strcasecmp(val, "AES-GCMP") == 0) {
6871 if (set_network(ifname, net_id, "pairwise", "GCMP") < 0) {
6872 sigma_dut_print(dut, DUT_MSG_ERROR,
6873 "Failed to set supplicant to pairwise GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006874 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006875 }
6876 if (set_network(ifname, net_id, "group", "GCMP") < 0) {
6877 sigma_dut_print(dut, DUT_MSG_ERROR,
6878 "Failed to set supplicant to group GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006879 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006880 }
6881 } else if (val) {
6882 sigma_dut_print(dut, DUT_MSG_ERROR,
6883 "Requested Encrypt %s is not supported on 60 GHz",
6884 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006885 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006886 }
6887
6888 val = get_param(cmd, "PSK");
6889 if (val && set_network_quoted(ifname, net_id, "psk", val) < 0) {
6890 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set psk %s",
6891 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006892 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006893 }
6894
6895 /* Convert 60G channel to freq */
6896 switch (dut->ap_channel) {
6897 case 1:
6898 val = "58320";
6899 break;
6900 case 2:
6901 val = "60480";
6902 break;
6903 case 3:
6904 val = "62640";
6905 break;
6906 default:
6907 sigma_dut_print(dut, DUT_MSG_ERROR,
6908 "Failed to configure channel %d. Not supported",
6909 dut->ap_channel);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006910 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006911 }
6912
6913 if (set_network(ifname, net_id, "frequency", val) < 0) {
6914 sigma_dut_print(dut, DUT_MSG_ERROR,
6915 "Failed to set supplicant network frequency");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006916 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006917 }
6918
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02006919 if (dut->eap_fragment) {
6920 sigma_dut_print(dut, DUT_MSG_DEBUG,
6921 "Set EAP fragment size to 128 bytes.");
6922 if (set_network(ifname, net_id, "fragment_size", "128") < 0)
6923 return ERROR_SEND_STATUS;
6924 }
6925
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006926 sigma_dut_print(dut, DUT_MSG_DEBUG,
6927 "Supplicant set network with frequency");
6928
6929 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d", net_id);
6930 if (wpa_command(ifname, buf) < 0) {
6931 sigma_dut_print(dut, DUT_MSG_INFO,
6932 "Failed to select network id %d on %s",
6933 net_id, ifname);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006934 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006935 }
6936
6937 sigma_dut_print(dut, DUT_MSG_DEBUG, "Selected network");
6938
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006939 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006940}
6941
6942
Lior David67543f52017-01-03 19:04:22 +02006943static int wil6210_set_abft_len(struct sigma_dut *dut, int abft_len)
6944{
6945 char buf[128], fname[128];
6946 FILE *f;
Jouni Malinen3aa72862019-05-29 23:14:51 +03006947 int res;
Lior David67543f52017-01-03 19:04:22 +02006948
6949 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
6950 sigma_dut_print(dut, DUT_MSG_ERROR,
6951 "failed to get wil6210 debugfs dir");
6952 return -1;
6953 }
6954
Jouni Malinen3aa72862019-05-29 23:14:51 +03006955 res = snprintf(fname, sizeof(fname), "%s/abft_len", buf);
6956 if (res < 0 || res >= sizeof(fname))
6957 return -1;
Lior David67543f52017-01-03 19:04:22 +02006958 f = fopen(fname, "w");
6959 if (!f) {
6960 sigma_dut_print(dut, DUT_MSG_ERROR,
6961 "failed to open: %s", fname);
6962 return -1;
6963 }
6964
6965 fprintf(f, "%d\n", abft_len);
6966 fclose(f);
6967
6968 return 0;
6969}
6970
6971
Alexei Avshalom Lazar49498b82019-01-31 15:16:32 +02006972int sta_set_60g_abft_len(struct sigma_dut *dut, struct sigma_conn *conn,
6973 int abft_len)
Lior David67543f52017-01-03 19:04:22 +02006974{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006975 switch (get_driver_type(dut)) {
Lior David67543f52017-01-03 19:04:22 +02006976 case DRIVER_WIL6210:
6977 return wil6210_set_abft_len(dut, abft_len);
6978 default:
6979 sigma_dut_print(dut, DUT_MSG_ERROR,
6980 "set abft_len not supported");
6981 return -1;
6982 }
6983}
6984
6985
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006986static int sta_set_60g_pcp(struct sigma_dut *dut, struct sigma_conn *conn,
6987 struct sigma_cmd *cmd)
6988{
6989 const char *val;
Lior David67543f52017-01-03 19:04:22 +02006990 unsigned int abft_len = 1; /* default is one slot */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006991
6992 if (dut->dev_role != DEVROLE_PCP) {
6993 send_resp(dut, conn, SIGMA_INVALID,
6994 "ErrorCode,Invalid DevRole");
6995 return 0;
6996 }
6997
6998 val = get_param(cmd, "SSID");
6999 if (val) {
7000 if (strlen(val) > sizeof(dut->ap_ssid) - 1) {
7001 send_resp(dut, conn, SIGMA_INVALID,
7002 "ErrorCode,Invalid SSID");
7003 return -1;
7004 }
7005
Peng Xub8fc5cc2017-05-10 17:27:28 -07007006 strlcpy(dut->ap_ssid, val, sizeof(dut->ap_ssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007007 }
7008
7009 val = get_param(cmd, "CHANNEL");
7010 if (val) {
7011 const char *pos;
7012
7013 dut->ap_channel = atoi(val);
7014 pos = strchr(val, ';');
7015 if (pos) {
7016 pos++;
7017 dut->ap_channel_1 = atoi(pos);
7018 }
7019 }
7020
7021 switch (dut->ap_channel) {
7022 case 1:
7023 case 2:
7024 case 3:
7025 break;
7026 default:
7027 sigma_dut_print(dut, DUT_MSG_ERROR,
7028 "Channel %d is not supported", dut->ap_channel);
7029 send_resp(dut, conn, SIGMA_ERROR,
7030 "Requested channel is not supported");
7031 return -1;
7032 }
7033
7034 val = get_param(cmd, "BCNINT");
7035 if (val)
7036 dut->ap_bcnint = atoi(val);
7037
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007038 val = get_param(cmd, "AllocType");
7039 if (val) {
7040 send_resp(dut, conn, SIGMA_ERROR,
7041 "ErrorCode,AllocType is not supported yet");
7042 return -1;
7043 }
7044
7045 val = get_param(cmd, "PercentBI");
7046 if (val) {
7047 send_resp(dut, conn, SIGMA_ERROR,
7048 "ErrorCode,PercentBI is not supported yet");
7049 return -1;
7050 }
7051
7052 val = get_param(cmd, "CBAPOnly");
7053 if (val) {
7054 send_resp(dut, conn, SIGMA_ERROR,
7055 "ErrorCode,CBAPOnly is not supported yet");
7056 return -1;
7057 }
7058
7059 val = get_param(cmd, "AMPDU");
7060 if (val) {
7061 if (strcasecmp(val, "Enable") == 0)
7062 dut->ap_ampdu = 1;
7063 else if (strcasecmp(val, "Disable") == 0)
7064 dut->ap_ampdu = 2;
7065 else {
7066 send_resp(dut, conn, SIGMA_ERROR,
7067 "ErrorCode,AMPDU value is not Enable nor Disabled");
7068 return -1;
7069 }
7070 }
7071
7072 val = get_param(cmd, "AMSDU");
7073 if (val) {
7074 if (strcasecmp(val, "Enable") == 0)
7075 dut->ap_amsdu = 1;
7076 else if (strcasecmp(val, "Disable") == 0)
7077 dut->ap_amsdu = 2;
7078 }
7079
7080 val = get_param(cmd, "NumMSDU");
7081 if (val) {
7082 send_resp(dut, conn, SIGMA_ERROR,
7083 "ErrorCode, NumMSDU is not supported yet");
7084 return -1;
7085 }
7086
7087 val = get_param(cmd, "ABFTLRang");
7088 if (val) {
7089 sigma_dut_print(dut, DUT_MSG_DEBUG,
Lior David67543f52017-01-03 19:04:22 +02007090 "ABFTLRang parameter %s", val);
7091 if (strcmp(val, "Gt1") == 0)
7092 abft_len = 2; /* 2 slots in this case */
7093 }
7094
7095 if (sta_set_60g_abft_len(dut, conn, abft_len)) {
7096 send_resp(dut, conn, SIGMA_ERROR,
7097 "ErrorCode, Can't set ABFT length");
7098 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007099 }
7100
7101 if (sta_pcp_start(dut, conn, cmd) < 0) {
7102 send_resp(dut, conn, SIGMA_ERROR,
7103 "ErrorCode, Can't start PCP role");
7104 return -1;
7105 }
7106
7107 return sta_set_60g_common(dut, conn, cmd);
7108}
7109
7110
7111static int sta_set_60g_sta(struct sigma_dut *dut, struct sigma_conn *conn,
7112 struct sigma_cmd *cmd)
7113{
7114 const char *val = get_param(cmd, "DiscoveryMode");
7115
7116 if (dut->dev_role != DEVROLE_STA) {
7117 send_resp(dut, conn, SIGMA_INVALID,
7118 "ErrorCode,Invalid DevRole");
7119 return 0;
7120 }
7121
7122 if (val) {
7123 sigma_dut_print(dut, DUT_MSG_DEBUG, "Discovery: %s", val);
7124 /* Ignore Discovery mode till Driver expose API. */
7125#if 0
7126 if (strcasecmp(val, "1") == 0) {
7127 send_resp(dut, conn, SIGMA_INVALID,
7128 "ErrorCode,DiscoveryMode 1 not supported");
7129 return 0;
7130 }
7131
7132 if (strcasecmp(val, "0") == 0) {
7133 /* OK */
7134 } else {
7135 send_resp(dut, conn, SIGMA_INVALID,
7136 "ErrorCode,DiscoveryMode not supported");
7137 return 0;
7138 }
7139#endif
7140 }
7141
7142 if (start_sta_mode(dut) != 0)
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007143 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007144 return sta_set_60g_common(dut, conn, cmd);
7145}
7146
7147
Jouni Malinenf7222712019-06-13 01:50:21 +03007148static enum sigma_cmd_result cmd_sta_disconnect(struct sigma_dut *dut,
7149 struct sigma_conn *conn,
7150 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007151{
7152 const char *intf = get_param(cmd, "Interface");
Jouni Malinened77e672018-01-10 16:45:13 +02007153 const char *val = get_param(cmd, "maintain_profile");
vamsi krishnad605c422017-09-20 14:56:31 +05307154
Jouni Malinened77e672018-01-10 16:45:13 +02007155 if (dut->program == PROGRAM_OCE ||
Amarnath Hullur Subramanyamebeda9e2018-01-31 03:21:48 -08007156 dut->program == PROGRAM_HE ||
Jouni Malinened77e672018-01-10 16:45:13 +02007157 (val && atoi(val) == 1)) {
vamsi krishnad605c422017-09-20 14:56:31 +05307158 wpa_command(intf, "DISCONNECT");
7159 return 1;
7160 }
7161
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007162 disconnect_station(dut);
7163 /* Try to ignore old scan results to avoid HS 2.0R2 test case failures
7164 * due to cached results. */
7165 wpa_command(intf, "SET ignore_old_scan_res 1");
7166 wpa_command(intf, "BSS_FLUSH");
7167 return 1;
7168}
7169
7170
Jouni Malinenf7222712019-06-13 01:50:21 +03007171static enum sigma_cmd_result cmd_sta_reassoc(struct sigma_dut *dut,
7172 struct sigma_conn *conn,
7173 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007174{
7175 const char *intf = get_param(cmd, "Interface");
7176 const char *bssid = get_param(cmd, "bssid");
7177 const char *val = get_param(cmd, "CHANNEL");
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07007178 const char *freq_val = get_param(cmd, "ChnlFreq");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007179 struct wpa_ctrl *ctrl;
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05307180 char buf[1000];
Sunil Duttd30ce092018-01-11 23:56:29 +05307181 char result[32];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007182 int res;
7183 int chan = 0;
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07007184 int freq = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007185 enum sigma_cmd_result status = STATUS_SENT;
Sunil Duttd30ce092018-01-11 23:56:29 +05307186 int fastreassoc = 1;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007187 int ft_ds = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007188
7189 if (bssid == NULL) {
7190 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing bssid "
7191 "argument");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007192 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007193 }
7194
7195 if (val)
7196 chan = atoi(val);
7197
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07007198 if (freq_val)
7199 freq = atoi(freq_val);
7200
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007201 if (wifi_chip_type != DRIVER_WCN && wifi_chip_type != DRIVER_AR6003) {
7202 /* The current network may be from sta_associate or
7203 * sta_hs2_associate
7204 */
7205 if (set_network(intf, dut->infra_network_id, "bssid", bssid) <
7206 0 ||
7207 set_network(intf, 0, "bssid", bssid) < 0)
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007208 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007209 }
7210
7211 ctrl = open_wpa_mon(intf);
7212 if (ctrl == NULL) {
7213 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
7214 "wpa_supplicant monitor connection");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007215 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007216 }
7217
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007218 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Sunil Duttd30ce092018-01-11 23:56:29 +05307219 sizeof(result)) < 0 ||
7220 strncmp(result, "COMPLETED", 9) != 0) {
7221 sigma_dut_print(dut, DUT_MSG_DEBUG,
7222 "sta_reassoc: Not connected");
7223 fastreassoc = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007224 } else if (dut->sta_ft_ds) {
7225 sigma_dut_print(dut, DUT_MSG_DEBUG,
7226 "sta_reassoc: Use FT-over-DS");
7227 ft_ds = 1;
Sunil Duttd30ce092018-01-11 23:56:29 +05307228 }
7229
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05307230 if (dut->rsne_override) {
7231#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007232 if (get_driver_type(dut) == DRIVER_WCN &&
7233 dut->config_rsnie == 0) {
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05307234 sta_config_params(dut, intf, STA_SET_RSNIE, 1);
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05307235 dut->config_rsnie = 1;
7236 }
7237#endif /* NL80211_SUPPORT */
7238 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
7239 dut->rsne_override);
7240 if (wpa_command(intf, buf) < 0) {
7241 send_resp(dut, conn, SIGMA_ERROR,
7242 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
7243 return 0;
7244 }
7245 }
7246
Shivani Baranwal7aa48602021-09-29 10:53:38 +05307247 if (ft_ds && get_driver_type(dut) != DRIVER_WCN) {
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07007248 if (chan || freq) {
7249 if (!freq)
7250 freq = channel_to_freq(dut, chan);
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007251 if (!freq) {
7252 sigma_dut_print(dut, DUT_MSG_ERROR,
7253 "Invalid channel number provided: %d",
7254 chan);
7255 send_resp(dut, conn, SIGMA_INVALID,
7256 "ErrorCode,Invalid channel number");
7257 goto close_mon_conn;
7258 }
7259 res = snprintf(buf, sizeof(buf),
7260 "SCAN TYPE=ONLY freq=%d", freq);
7261 } else {
7262 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
7263 }
7264 if (res < 0 || res >= (int) sizeof(buf)) {
7265 send_resp(dut, conn, SIGMA_ERROR,
7266 "ErrorCode,snprintf failed");
7267 goto close_mon_conn;
7268 }
7269 if (wpa_command(intf, buf) < 0) {
7270 sigma_dut_print(dut, DUT_MSG_INFO,
7271 "Failed to start scan");
7272 send_resp(dut, conn, SIGMA_ERROR,
7273 "ErrorCode,scan failed");
7274 goto close_mon_conn;
7275 }
7276
7277 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
7278 buf, sizeof(buf));
7279 if (res < 0) {
7280 sigma_dut_print(dut, DUT_MSG_INFO,
7281 "Scan did not complete");
7282 send_resp(dut, conn, SIGMA_ERROR,
7283 "ErrorCode,scan did not complete");
7284 goto close_mon_conn;
7285 }
7286
7287 res = snprintf(buf, sizeof(buf), "FT_DS %s", bssid);
7288 if (res > 0 && res < (int) sizeof(buf))
7289 res = wpa_command(intf, buf);
7290
7291 if (res < 0 || res >= (int) sizeof(buf)) {
7292 send_resp(dut, conn, SIGMA_ERROR,
7293 "errorCode,FT_DS command failed");
7294 status = STATUS_SENT_ERROR;
7295 goto close_mon_conn;
7296 }
7297 } else if (wifi_chip_type == DRIVER_WCN && fastreassoc) {
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07007298 if (chan || freq) {
7299 if (!freq)
7300 freq = channel_to_freq(dut, chan);
Ashwini Patil4c8158f2017-05-25 12:49:21 +05307301 if (!freq) {
7302 sigma_dut_print(dut, DUT_MSG_ERROR,
7303 "Invalid channel number provided: %d",
7304 chan);
7305 send_resp(dut, conn, SIGMA_INVALID,
7306 "ErrorCode,Invalid channel number");
7307 goto close_mon_conn;
7308 }
7309 res = snprintf(buf, sizeof(buf),
7310 "SCAN TYPE=ONLY freq=%d", freq);
7311 } else {
7312 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
7313 }
7314 if (res < 0 || res >= (int) sizeof(buf)) {
7315 send_resp(dut, conn, SIGMA_ERROR,
7316 "ErrorCode,snprintf failed");
7317 goto close_mon_conn;
7318 }
7319 if (wpa_command(intf, buf) < 0) {
7320 sigma_dut_print(dut, DUT_MSG_INFO,
7321 "Failed to start scan");
7322 send_resp(dut, conn, SIGMA_ERROR,
7323 "ErrorCode,scan failed");
7324 goto close_mon_conn;
7325 }
7326
7327 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
7328 buf, sizeof(buf));
7329 if (res < 0) {
7330 sigma_dut_print(dut, DUT_MSG_INFO,
7331 "Scan did not complete");
7332 send_resp(dut, conn, SIGMA_ERROR,
7333 "ErrorCode,scan did not complete");
7334 goto close_mon_conn;
7335 }
7336
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007337 if (set_network(intf, dut->infra_network_id, "bssid", "any")
7338 < 0) {
7339 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
7340 "bssid to any during FASTREASSOC");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007341 status = ERROR_SEND_STATUS;
Ashwini Patil467efef2017-05-25 12:18:27 +05307342 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007343 }
Vinita Maloo54b78cf2020-03-30 12:18:19 +05307344 res = snprintf(buf, sizeof(buf), "FASTREASSOC %s %d",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007345 bssid, chan);
Vinita Maloo54b78cf2020-03-30 12:18:19 +05307346 if (res < 0 || res >= (int) sizeof(buf) ||
7347 wcn_driver_cmd(intf, buf) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007348 send_resp(dut, conn, SIGMA_ERROR,
Vinita Maloo54b78cf2020-03-30 12:18:19 +05307349 "errorCode,Failed to run FASTREASSOC");
Ashwini Patil467efef2017-05-25 12:18:27 +05307350 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007351 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007352 sigma_dut_print(dut, DUT_MSG_INFO,
7353 "sta_reassoc: Run %s successful", buf);
7354 } else if (wpa_command(intf, "REASSOCIATE")) {
7355 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
7356 "request reassociation");
Ashwini Patil467efef2017-05-25 12:18:27 +05307357 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007358 }
7359
7360 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
7361 buf, sizeof(buf));
Ashwini Patil467efef2017-05-25 12:18:27 +05307362 if (res < 0) {
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007363 send_resp(dut, conn, SIGMA_ERROR,
7364 "errorCode,Connection did not complete");
7365 status = STATUS_SENT_ERROR;
Ashwini Patil467efef2017-05-25 12:18:27 +05307366 goto close_mon_conn;
7367 }
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007368 status = SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007369
Ashwini Patil467efef2017-05-25 12:18:27 +05307370close_mon_conn:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007371 wpa_ctrl_detach(ctrl);
7372 wpa_ctrl_close(ctrl);
Ashwini Patil467efef2017-05-25 12:18:27 +05307373 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007374}
7375
7376
7377static void hs2_clear_credentials(const char *intf)
7378{
7379 wpa_command(intf, "REMOVE_CRED all");
7380}
7381
7382
Lior Davidcc88b562017-01-03 18:52:09 +02007383#ifdef __linux__
7384static int wil6210_get_aid(struct sigma_dut *dut, const char *bssid,
7385 unsigned int *aid)
7386{
Lior David0fe101e2017-03-09 16:09:50 +02007387 const char *pattern = "AID[ \t]+([0-9]+)";
Lior Davidcc88b562017-01-03 18:52:09 +02007388
Lior David0fe101e2017-03-09 16:09:50 +02007389 return wil6210_get_sta_info_field(dut, bssid, pattern, aid);
Lior Davidcc88b562017-01-03 18:52:09 +02007390}
7391#endif /* __linux__ */
7392
7393
7394static int sta_get_aid_60g(struct sigma_dut *dut, const char *bssid,
7395 unsigned int *aid)
7396{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007397 switch (get_driver_type(dut)) {
Lior Davidcc88b562017-01-03 18:52:09 +02007398#ifdef __linux__
7399 case DRIVER_WIL6210:
7400 return wil6210_get_aid(dut, bssid, aid);
7401#endif /* __linux__ */
7402 default:
7403 sigma_dut_print(dut, DUT_MSG_ERROR, "get AID not supported");
7404 return -1;
7405 }
7406}
7407
7408
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007409static int sta_get_parameter_60g(struct sigma_dut *dut, struct sigma_conn *conn,
7410 struct sigma_cmd *cmd)
7411{
7412 char buf[MAX_CMD_LEN];
7413 char bss_list[MAX_CMD_LEN];
7414 const char *parameter = get_param(cmd, "Parameter");
7415
7416 if (parameter == NULL)
7417 return -1;
7418
Lior Davidcc88b562017-01-03 18:52:09 +02007419 if (strcasecmp(parameter, "AID") == 0) {
7420 unsigned int aid = 0;
7421 char bssid[20];
7422
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007423 if (get_wpa_status(get_station_ifname(dut), "bssid",
Lior Davidcc88b562017-01-03 18:52:09 +02007424 bssid, sizeof(bssid)) < 0) {
7425 sigma_dut_print(dut, DUT_MSG_ERROR,
7426 "could not get bssid");
7427 return -2;
7428 }
7429
7430 if (sta_get_aid_60g(dut, bssid, &aid))
7431 return -2;
7432
7433 snprintf(buf, sizeof(buf), "aid,%d", aid);
7434 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
7435 send_resp(dut, conn, SIGMA_COMPLETE, buf);
7436 return 0;
7437 }
7438
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007439 if (strcasecmp(parameter, "DiscoveredDevList") == 0) {
7440 char *bss_line;
7441 char *bss_id = NULL;
7442 const char *ifname = get_param(cmd, "Interface");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05307443 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007444
7445 if (ifname == NULL) {
7446 sigma_dut_print(dut, DUT_MSG_INFO,
7447 "For get DiscoveredDevList need Interface name.");
7448 return -1;
7449 }
7450
7451 /*
7452 * Use "BSS RANGE=ALL MASK=0x2" which provides a list
7453 * of BSSIDs in "bssid=<BSSID>\n"
7454 */
7455 if (wpa_command_resp(ifname, "BSS RANGE=ALL MASK=0x2",
7456 bss_list,
7457 sizeof(bss_list)) < 0) {
7458 sigma_dut_print(dut, DUT_MSG_ERROR,
7459 "Failed to get bss list");
7460 return -1;
7461 }
7462
7463 sigma_dut_print(dut, DUT_MSG_DEBUG,
7464 "bss list for ifname:%s is:%s",
7465 ifname, bss_list);
7466
7467 snprintf(buf, sizeof(buf), "DeviceList");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05307468 bss_line = strtok_r(bss_list, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007469 while (bss_line) {
7470 if (sscanf(bss_line, "bssid=%ms", &bss_id) > 0 &&
7471 bss_id) {
7472 int len;
7473
7474 len = snprintf(buf + strlen(buf),
7475 sizeof(buf) - strlen(buf),
7476 ",%s", bss_id);
7477 free(bss_id);
7478 bss_id = NULL;
7479 if (len < 0) {
7480 sigma_dut_print(dut,
7481 DUT_MSG_ERROR,
7482 "Failed to read BSSID");
7483 send_resp(dut, conn, SIGMA_ERROR,
7484 "ErrorCode,Failed to read BSS ID");
7485 return 0;
7486 }
7487
7488 if ((size_t) len >= sizeof(buf) - strlen(buf)) {
7489 sigma_dut_print(dut,
7490 DUT_MSG_ERROR,
7491 "Response buf too small for list");
7492 send_resp(dut, conn,
7493 SIGMA_ERROR,
7494 "ErrorCode,Response buf too small for list");
7495 return 0;
7496 }
7497 }
7498
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05307499 bss_line = strtok_r(NULL, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007500 }
7501
7502 sigma_dut_print(dut, DUT_MSG_INFO, "DiscoveredDevList is %s",
7503 buf);
7504 send_resp(dut, conn, SIGMA_COMPLETE, buf);
7505 return 0;
7506 }
7507
7508 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7509 return 0;
7510}
7511
7512
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07007513static int sta_get_parameter_he(struct sigma_dut *dut, struct sigma_conn *conn,
7514 struct sigma_cmd *cmd)
7515{
7516 char buf[MAX_CMD_LEN];
7517 const char *parameter = get_param(cmd, "Parameter");
7518
7519 if (!parameter)
7520 return -1;
7521
7522 if (strcasecmp(parameter, "RSSI") == 0) {
7523 char rssi[10];
7524
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007525 if (get_wpa_signal_poll(dut, get_station_ifname(dut), "RSSI",
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07007526 rssi, sizeof(rssi)) < 0) {
7527 sigma_dut_print(dut, DUT_MSG_ERROR,
7528 "Could not get RSSI");
7529 return -2;
7530 }
7531
7532 snprintf(buf, sizeof(buf), "rssi,%s", rssi);
7533 sigma_dut_print(dut, DUT_MSG_INFO, "RSSI %s", buf);
7534 send_resp(dut, conn, SIGMA_COMPLETE, buf);
7535 return 0;
7536 }
7537
7538 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7539 return 0;
7540}
7541
7542
Veerendranath Jakkamd0ad6ef2020-05-21 17:09:26 +05307543#ifdef NL80211_SUPPORT
7544
7545struct station_info {
7546 uint64_t filled;
7547 uint32_t beacon_mic_error_count;
7548 uint32_t beacon_replay_count;
7549};
7550
7551
7552static int qca_get_sta_info_handler(struct nl_msg *msg, void *arg)
7553{
7554 struct nlattr *tb[NL80211_ATTR_MAX + 1];
7555 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
7556 struct station_info *data = arg;
7557 struct nlattr *info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_MAX + 1];
7558 static struct nla_policy info_policy[
7559 QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_MAX + 1] = {
7560 [QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT] = {
7561 .type = NLA_U32
7562 },
7563 [QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT] = {
7564 .type = NLA_U32
7565 },
7566 };
7567
7568 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
7569 genlmsg_attrlen(gnlh, 0), NULL);
7570
7571 if (!tb[NL80211_ATTR_VENDOR_DATA])
7572 return NL_SKIP;
7573
7574 if (nla_parse_nested(info, QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_MAX,
7575 tb[NL80211_ATTR_VENDOR_DATA], info_policy)) {
7576 return NL_SKIP;
7577 }
7578
7579 if (info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT]) {
7580 data->filled |=
7581 BIT_ULL(QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT);
7582 data->beacon_mic_error_count =
7583 nla_get_u32(info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT]);
7584 }
7585
7586 if (info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT]) {
7587 data->filled |=
7588 BIT_ULL(QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT);
7589 data->beacon_replay_count =
7590 nla_get_u32(info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT]);
7591 }
7592
7593 return NL_SKIP;
7594}
7595
7596
7597static int qca_nl80211_get_sta_info(struct sigma_dut *dut, const char *intf,
7598 struct station_info *sta_data)
7599{
7600 struct nl_msg *msg;
7601 int ifindex, ret;
7602
7603 ifindex = if_nametoindex(intf);
7604 if (ifindex == 0) {
7605 sigma_dut_print(dut, DUT_MSG_ERROR,
7606 "%s: Index for interface %s not found",
7607 __func__, intf);
7608 return -1;
7609 }
7610
7611 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7612 NL80211_CMD_VENDOR)) ||
7613 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7614 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7615 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7616 QCA_NL80211_VENDOR_SUBCMD_GET_STA_INFO)) {
7617 sigma_dut_print(dut, DUT_MSG_ERROR,
7618 "%s: err in adding vendor_cmd", __func__);
7619 nlmsg_free(msg);
7620 return -1;
7621 }
7622
7623 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg,
7624 qca_get_sta_info_handler, sta_data);
7625 if (ret) {
7626 sigma_dut_print(dut, DUT_MSG_ERROR,
7627 "%s: err in send_and_recv_msgs, ret=%d",
7628 __func__, ret);
7629 }
7630 return ret;
7631}
7632#endif /* NL80211_SUPPORT */
7633
7634
7635static int get_bip_mic_error_count(struct sigma_dut *dut,
7636 const char *ifname,
7637 unsigned int *count)
7638{
7639#ifdef NL80211_SUPPORT
7640 struct station_info sta_data;
7641#endif /* NL80211_SUPPORT */
7642
7643 if (get_driver_type(dut) != DRIVER_WCN) {
7644 sigma_dut_print(dut, DUT_MSG_ERROR,
7645 "BIP MIC error count not supported");
7646 return -1;
7647 }
7648
7649#ifdef NL80211_SUPPORT
7650 if (qca_nl80211_get_sta_info(dut, ifname, &sta_data) != 0 ||
7651 !(sta_data.filled &
7652 BIT_ULL(QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT))) {
7653 sigma_dut_print(dut, DUT_MSG_ERROR,
7654 "BIP MIC error count fetching failed");
7655 return -1;
7656 }
7657
7658 *count = sta_data.beacon_mic_error_count;
7659 return 0;
7660#else /* NL80211_SUPPORT */
7661 sigma_dut_print(dut, DUT_MSG_ERROR,
7662 "BIP MIC error count cannot be fetched without NL80211_SUPPORT defined");
7663 return -1;
7664#endif /* NL80211_SUPPORT */
7665}
7666
7667
7668static int get_cmac_replay_count(struct sigma_dut *dut, const char *ifname,
7669 unsigned int *count)
7670{
7671#ifdef NL80211_SUPPORT
7672 struct station_info sta_data;
7673#endif /* NL80211_SUPPORT */
7674
7675 if (get_driver_type(dut) != DRIVER_WCN) {
7676 sigma_dut_print(dut, DUT_MSG_ERROR,
7677 "CMAC reply count not supported");
7678 return -1;
7679 }
7680
7681#ifdef NL80211_SUPPORT
7682 if (qca_nl80211_get_sta_info(dut, ifname, &sta_data) != 0 ||
7683 !(sta_data.filled &
7684 BIT_ULL(QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT))) {
7685 sigma_dut_print(dut, DUT_MSG_ERROR,
7686 "CMAC replay count fetching failed");
7687 return -1;
7688 }
7689
7690 *count = sta_data.beacon_replay_count;
7691 return 0;
7692#else /* NL80211_SUPPORT */
7693 sigma_dut_print(dut, DUT_MSG_ERROR,
7694 "CMAC replay count cannot be fetched without NL80211_SUPPORT defined");
7695 return -1;
7696#endif /* NL80211_SUPPORT */
7697}
7698
7699
7700static enum sigma_cmd_result sta_get_parameter_wpa3(struct sigma_dut *dut,
7701 struct sigma_conn *conn,
7702 struct sigma_cmd *cmd)
7703{
7704 char buf[MAX_CMD_LEN];
7705 const char *ifname = get_param(cmd, "interface");
7706 const char *parameter = get_param(cmd, "Parameter");
7707 unsigned int val;
7708
7709 if (!ifname || !parameter)
7710 return INVALID_SEND_STATUS;
7711
7712 if (strcasecmp(parameter, "BIPMICErrors") == 0) {
7713 if (get_bip_mic_error_count(dut, ifname, &val)) {
7714 send_resp(dut, conn, SIGMA_ERROR,
7715 "ErrorCode,Failed to get BIPMICErrors");
7716 return STATUS_SENT_ERROR;
7717 }
7718 snprintf(buf, sizeof(buf), "BIPMICErrors,%d", val);
7719 sigma_dut_print(dut, DUT_MSG_INFO, "BIPMICErrors %s", buf);
7720 send_resp(dut, conn, SIGMA_COMPLETE, buf);
7721 return STATUS_SENT;
7722 }
7723
7724 if (strcasecmp(parameter, "CMACReplays") == 0) {
7725 if (get_cmac_replay_count(dut, ifname, &val)) {
7726 send_resp(dut, conn, SIGMA_ERROR,
7727 "ErrorCode,Failed to get CMACReplays");
7728 return STATUS_SENT_ERROR;
7729 }
7730 snprintf(buf, sizeof(buf), "CMACReplays,%d", val);
7731 sigma_dut_print(dut, DUT_MSG_INFO, "CMACReplays %s", buf);
7732 send_resp(dut, conn, SIGMA_COMPLETE, buf);
7733 return STATUS_SENT;
7734 }
7735
7736 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7737 return STATUS_SENT_ERROR;
7738}
7739
7740
Jouni Malinenca0abd32020-02-09 20:18:10 +02007741static enum sigma_cmd_result sta_get_pmk(struct sigma_dut *dut,
7742 struct sigma_conn *conn,
7743 struct sigma_cmd *cmd)
7744{
7745 const char *intf = get_param(cmd, "Interface");
7746 char buf[4096], bssid[20], resp[200], *pos, *tmp;
7747
7748 snprintf(buf, sizeof(buf), "PMKSA_GET %d", dut->infra_network_id);
7749 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
7750 strncmp(buf, "UNKNOWN COMMAND", 15) == 0) {
7751 send_resp(dut, conn, SIGMA_ERROR,
7752 "ErrorCode,PMKSA_GET not supported");
7753 return STATUS_SENT_ERROR;
7754 }
7755
7756 if (strncmp(buf, "FAIL", 4) == 0 ||
7757 get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
7758 send_resp(dut, conn, SIGMA_ERROR,
7759 "ErrorCode,Could not find current network");
7760 return STATUS_SENT_ERROR;
7761 }
7762
7763 pos = buf;
7764 while (pos) {
7765 if (strncmp(pos, bssid, 17) == 0) {
7766 pos = strchr(pos, ' ');
7767 if (!pos)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05307768 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02007769 pos++;
7770 pos = strchr(pos, ' ');
7771 if (!pos)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05307772 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02007773 pos++;
7774 tmp = strchr(pos, ' ');
7775 if (!tmp)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05307776 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02007777 *tmp = '\0';
7778 break;
7779 }
Jouni Malinenca0abd32020-02-09 20:18:10 +02007780 pos = strchr(pos, '\n');
7781 if (pos)
7782 pos++;
7783 }
7784
7785 if (!pos) {
7786 send_resp(dut, conn, SIGMA_ERROR,
7787 "ErrorCode,PMK not available");
7788 return STATUS_SENT_ERROR;
7789 }
7790
7791 snprintf(resp, sizeof(resp), "PMK,%s", pos);
7792 send_resp(dut, conn, SIGMA_COMPLETE, resp);
7793 return STATUS_SENT;
7794}
7795
7796
Jouni Malinenf7222712019-06-13 01:50:21 +03007797static enum sigma_cmd_result cmd_sta_get_parameter(struct sigma_dut *dut,
7798 struct sigma_conn *conn,
7799 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007800{
7801 const char *program = get_param(cmd, "Program");
Jouni Malinenca0abd32020-02-09 20:18:10 +02007802 const char *parameter = get_param(cmd, "Parameter");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007803
Jouni Malinenca0abd32020-02-09 20:18:10 +02007804 if (!parameter)
7805 return INVALID_SEND_STATUS;
7806
7807 if (strcasecmp(parameter, "PMK") == 0)
7808 return sta_get_pmk(dut, conn, cmd);
7809
7810 if (!program)
7811 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007812
7813 if (strcasecmp(program, "P2PNFC") == 0)
7814 return p2p_cmd_sta_get_parameter(dut, conn, cmd);
7815
7816 if (strcasecmp(program, "60ghz") == 0)
7817 return sta_get_parameter_60g(dut, conn, cmd);
7818
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07007819 if (strcasecmp(program, "he") == 0)
7820 return sta_get_parameter_he(dut, conn, cmd);
7821
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007822#ifdef ANDROID_NAN
7823 if (strcasecmp(program, "NAN") == 0)
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07007824 return nan_cmd_sta_get_parameter(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007825#endif /* ANDROID_NAN */
7826
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007827#ifdef MIRACAST
7828 if (strcasecmp(program, "WFD") == 0 ||
7829 strcasecmp(program, "DisplayR2") == 0)
7830 return miracast_cmd_sta_get_parameter(dut, conn, cmd);
7831#endif /* MIRACAST */
Veerendranath Jakkamd0ad6ef2020-05-21 17:09:26 +05307832 if (strcasecmp(program, "WPA3") == 0)
7833 return sta_get_parameter_wpa3(dut, conn, cmd);
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007834
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007835 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7836 return 0;
7837}
7838
7839
7840static void sta_reset_default_ath(struct sigma_dut *dut, const char *intf,
7841 const char *type)
7842{
7843 char buf[100];
7844
7845 if (dut->program == PROGRAM_VHT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007846 run_iwpriv(dut, intf, "chwidth 2");
7847 run_iwpriv(dut, intf, "mode 11ACVHT80");
7848 run_iwpriv(dut, intf, "vhtmcs -1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007849 }
7850
7851 if (dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007852 run_iwpriv(dut, intf, "chwidth 0");
7853 run_iwpriv(dut, intf, "mode 11naht40");
7854 run_iwpriv(dut, intf, "set11NRates 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007855 }
7856
7857 if (dut->program == PROGRAM_VHT || dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007858 run_iwpriv(dut, intf, "powersave 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007859
7860 /* Reset CTS width */
7861 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 54 0",
7862 intf);
7863 if (system(buf) != 0) {
7864 sigma_dut_print(dut, DUT_MSG_ERROR,
7865 "wifitool %s beeliner_fw_test 54 0 failed",
7866 intf);
7867 }
7868
7869 /* Enable Dynamic Bandwidth signalling by default */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007870 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007871
7872 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", intf);
7873 if (system(buf) != 0) {
7874 sigma_dut_print(dut, DUT_MSG_ERROR,
7875 "iwpriv rts failed");
7876 }
7877 }
7878
7879 if (type && strcasecmp(type, "Testbed") == 0) {
7880 dut->testbed_flag_txsp = 1;
7881 dut->testbed_flag_rxsp = 1;
7882 /* STA has to set spatial stream to 2 per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007883 run_iwpriv(dut, intf, "vht_mcsmap 0xfff0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007884
7885 /* Disable LDPC per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007886 run_iwpriv(dut, intf, "ldpc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007887
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007888 run_iwpriv(dut, intf, "amsdu 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007889
7890 /* TODO: Disable STBC 2x1 transmit and receive */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007891 run_iwpriv(dut, intf, "tx_stbc 0");
7892 run_iwpriv(dut, intf, "rx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007893
7894 /* STA has to disable Short GI per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007895 run_iwpriv(dut, intf, "shortgi 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007896 }
7897
7898 if (type && strcasecmp(type, "DUT") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007899 run_iwpriv(dut, intf, "nss 3");
Arif Hussainac6c5112018-05-25 17:34:00 -07007900 dut->sta_nss = 3;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007901
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007902 run_iwpriv(dut, intf, "shortgi 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007903 }
7904}
7905
7906
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007907#ifdef NL80211_SUPPORT
7908static int sta_set_he_mcs(struct sigma_dut *dut, const char *intf,
7909 enum he_mcs_config mcs)
7910{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307911 return wcn_wifi_test_config_set_u8(
7912 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MCS, mcs);
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007913}
7914#endif /* NL80211_SUPPORT */
7915
7916
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07007917static int sta_set_action_tx_in_he_tb_ppdu(struct sigma_dut *dut,
7918 const char *intf, int enable)
7919{
7920#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307921 return wcn_wifi_test_config_set_u8(
7922 dut, intf,
7923 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_ACTION_TX_TB_PPDU,
7924 enable);
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07007925#else /* NL80211_SUPPORT */
7926 sigma_dut_print(dut, DUT_MSG_ERROR,
7927 "HE action Tx TB PPDU cannot be set without NL80211_SUPPORT defined");
7928 return -1;
7929#endif /* NL80211_SUPPORT */
7930}
7931
7932
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08007933static int sta_set_heconfig_and_wep_tkip(struct sigma_dut *dut,
7934 const char *intf, int enable)
7935{
7936#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307937 return wcn_wifi_test_config_set_u8(
7938 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WEP_TKIP_IN_HE,
7939 enable);
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08007940#else /* NL80211_SUPPORT */
7941 sigma_dut_print(dut, DUT_MSG_ERROR,
7942 "HE config enablement cannot be changed without NL80211_SUPPORT defined");
7943 return -1;
7944#endif /* NL80211_SUPPORT */
7945}
7946
7947
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007948#ifdef NL80211_SUPPORT
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007949
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007950static int sta_set_he_testbed_def(struct sigma_dut *dut,
7951 const char *intf, int cfg)
7952{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307953 return wcn_wifi_test_config_set_u8(
7954 dut, intf,
7955 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SET_HE_TESTBED_DEFAULTS,
7956 cfg);
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007957}
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007958
7959
7960static int sta_set_2g_vht_supp(struct sigma_dut *dut, const char *intf, int cfg)
7961{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307962 return wcn_wifi_test_config_set_u8(
7963 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_2G_VHT,
7964 cfg);
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007965}
7966
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007967#endif /* NL80211_SUPPORT */
7968
7969
Qiwei Caib6806972020-01-15 13:52:11 +08007970int sta_set_addba_buf_size(struct sigma_dut *dut,
7971 const char *intf, int bufsize)
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007972{
7973#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307974 return wcn_wifi_test_config_set_u16(
7975 dut, intf,
7976 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE, bufsize);
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007977#else /* NL80211_SUPPORT */
7978 sigma_dut_print(dut, DUT_MSG_ERROR,
7979 "AddBA bufsize cannot be changed without NL80211_SUPPORT defined");
7980 return -1;
7981#endif /* NL80211_SUPPORT */
7982}
7983
7984
Kiran Kumar Lokere69d89952021-08-08 23:41:46 -07007985static int sta_set_scan_unicast_probe(struct sigma_dut *dut,
7986 const char *intf, int val)
7987{
7988#ifdef NL80211_SUPPORT
7989 return wcn_wifi_test_config_set_u8(
7990 dut, intf,
7991 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_USE_BSSID_IN_PROBE_REQ_RA,
7992 val);
7993#else /* NL80211_SUPPORT */
7994 sigma_dut_print(dut, DUT_MSG_ERROR,
7995 "Unicast RA in Probe Request frame cannot be set without NL80211_SUPPORT defined");
7996 return -1;
7997#endif /* NL80211_SUPPORT */
7998}
7999
8000
Kiran Kumar Lokere09dbcef2021-08-09 00:01:41 -07008001static int sta_set_rx_ctrl_multi_bss(struct sigma_dut *dut, const char *intf,
8002 int enable)
8003{
8004#ifdef NL80211_SUPPORT
8005 return wcn_wifi_test_config_set_u8(
8006 dut, intf,
8007 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_RX_CTRL_FRAME_TO_MBSS,
8008 enable);
8009#else /* NL80211_SUPPORT */
8010 sigma_dut_print(dut, DUT_MSG_ERROR,
8011 "Rx ctrl frame to Multi-BSS cannot be changed without NL80211_SUPPORT defined");
8012 return -1;
8013#endif /* NL80211_SUPPORT */
8014}
8015
8016
8017static int sta_set_bcast_twt_support(struct sigma_dut *dut, const char *intf,
8018 int enable)
8019{
8020#ifdef NL80211_SUPPORT
8021 return wcn_wifi_test_config_set_u8(
8022 dut, intf,
8023 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BCAST_TWT_SUPPORT,
8024 enable);
8025#else /* NL80211_SUPPORT */
8026 sigma_dut_print(dut, DUT_MSG_ERROR,
8027 "BCAST TWT cannot be changed without NL80211_SUPPORT defined");
8028 return -1;
8029#endif /* NL80211_SUPPORT */
8030}
8031
8032
Arif Hussain8d5b27b2018-05-14 14:31:03 -07008033static int sta_set_tx_beamformee(struct sigma_dut *dut, const char *intf,
8034 int enable)
8035{
8036#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05308037 return wcn_wifi_test_config_set_u8(
8038 dut, intf,
8039 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_TX_BEAMFORMEE,
8040 enable);
Arif Hussain8d5b27b2018-05-14 14:31:03 -07008041#else /* NL80211_SUPPORT */
8042 sigma_dut_print(dut, DUT_MSG_ERROR,
8043 "tx beamformee cannot be changed without NL80211_SUPPORT defined");
8044 return -1;
8045#endif /* NL80211_SUPPORT */
8046}
8047
8048
Arif Hussain9765f7d2018-07-03 08:28:26 -07008049static int sta_set_beamformee_sts(struct sigma_dut *dut, const char *intf,
8050 int val)
8051{
8052#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05308053 return wcn_wifi_test_config_set_u8(
8054 dut, intf,
8055 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_BEAMFORMEE_NSTS,
8056 val);
Arif Hussain9765f7d2018-07-03 08:28:26 -07008057#else /* NL80211_SUPPORT */
8058 sigma_dut_print(dut, DUT_MSG_ERROR,
8059 "beamformee sts cannot be changed without NL80211_SUPPORT defined");
8060 return -1;
8061#endif /* NL80211_SUPPORT */
8062}
8063
8064
Arif Hussain68d23f52018-07-11 13:39:08 -07008065#ifdef NL80211_SUPPORT
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07008066static int sta_set_mac_padding_duration(struct sigma_dut *dut, const char *intf,
8067 enum qca_wlan_he_mac_padding_dur val)
8068{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05308069 return wcn_wifi_test_config_set_u8(
8070 dut, intf,
8071 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MAC_PADDING_DUR, val);
Arif Hussain68d23f52018-07-11 13:39:08 -07008072}
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07008073#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07008074
8075
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07008076static int sta_set_tx_su_ppdu_cfg(struct sigma_dut *dut, const char *intf,
8077 int val)
8078{
8079#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05308080 return wcn_wifi_test_config_set_u8(
8081 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_SUPPDU,
8082 val);
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07008083#else /* NL80211_SUPPORT */
8084 sigma_dut_print(dut, DUT_MSG_ERROR,
8085 "Tx SU PPDU cannot be set without NL80211_SUPPORT defined");
8086 return -1;
8087#endif /* NL80211_SUPPORT */
8088}
8089
8090
Kiran Kumar Lokere54b72522021-04-01 00:22:44 -07008091static int sta_set_mgmt_data_tx_disable_cfg(struct sigma_dut *dut,
8092 const char *intf, int val)
8093{
8094#ifdef NL80211_SUPPORT
8095 return wcn_wifi_test_config_set_u8(
8096 dut, intf,
8097 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_DISABLE_DATA_MGMT_RSP_TX,
8098 val);
8099#else /* NL80211_SUPPORT */
8100 sigma_dut_print(dut, DUT_MSG_ERROR,
8101 "Tx disable config cannot be set without NL80211_SUPPORT defined");
8102 return -1;
8103#endif /* NL80211_SUPPORT */
8104}
8105
8106
Kiran Kumar Lokere1809da12021-06-24 00:45:38 -07008107static int sta_set_keep_alive_data_cfg(struct sigma_dut *dut, const char *intf,
8108 int val)
8109{
8110#ifdef NL80211_SUPPORT
8111 return wcn_wifi_test_config_set_u8(
8112 dut, intf,
8113 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_KEEP_ALIVE_FRAME_TYPE,
8114 val);
8115#else /* NL80211_SUPPORT */
8116 sigma_dut_print(dut, DUT_MSG_ERROR,
8117 "Keep alive data type cannot be set without NL80211_SUPPORT defined");
8118 return -1;
8119#endif /* NL80211_SUPPORT */
8120}
8121
8122
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07008123#ifdef NL80211_SUPPORT
8124static int sta_set_he_om_ctrl_reset(struct sigma_dut *dut, const char *intf)
8125{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05308126 return wcn_wifi_test_config_set_flag(
8127 dut, intf,
8128 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_CLEAR_HE_OM_CTRL_CONFIG);
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07008129}
8130#endif /* NL80211_SUPPORT */
8131
8132
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07008133static int sta_set_mu_edca_override(struct sigma_dut *dut, const char *intf,
8134 int val)
8135{
8136#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05308137 return wcn_wifi_test_config_set_u8(
8138 dut, intf,
8139 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_OVERRIDE_MU_EDCA, val);
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07008140#else /* NL80211_SUPPORT */
8141 sigma_dut_print(dut, DUT_MSG_ERROR,
8142 "MU EDCA override cannot be changed without NL80211_SUPPORT defined");
8143 return -1;
8144#endif /* NL80211_SUPPORT */
8145}
8146
8147
Kiran Kumar Lokerefa7c7b92021-08-09 00:50:55 -07008148static int sta_set_er_su_ppdu_type_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_ER_SU_PPDU_TYPE, val);
8155#else /* NL80211_SUPPORT */
8156 sigma_dut_print(dut, DUT_MSG_ERROR,
8157 "ER-SU PPDU type cannot be set without NL80211_SUPPORT defined");
8158 return -1;
8159#endif /* NL80211_SUPPORT */
8160}
8161
8162
8163static int sta_set_ru_242_tone_tx(struct sigma_dut *dut, const char *intf,
8164 int val)
8165{
8166#ifdef NL80211_SUPPORT
8167 return wcn_wifi_test_config_set_u8(
8168 dut, intf,
8169 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_RU_242_TONE_TX, val);
8170#else /* NL80211_SUPPORT */
8171 sigma_dut_print(dut, DUT_MSG_ERROR,
8172 "RU 242 tone cannot be set without NL80211_SUPPORT defined");
8173 return -1;
8174#endif /* NL80211_SUPPORT */
8175}
8176
8177
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07008178static int sta_set_om_ctrl_supp(struct sigma_dut *dut, const char *intf,
8179 int val)
8180{
8181#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05308182 return wcn_wifi_test_config_set_u8(
8183 dut, intf,
8184 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OM_CTRL_SUPP, val);
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07008185#else /* NL80211_SUPPORT */
8186 sigma_dut_print(dut, DUT_MSG_ERROR,
8187 "HE OM ctrl cannot be changed without NL80211_SUPPORT defined");
8188 return -1;
8189#endif /* NL80211_SUPPORT */
8190}
8191
8192
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07008193#ifdef NL80211_SUPPORT
8194
8195struct features_info {
8196 unsigned char flags[8];
8197 size_t flags_len;
8198};
8199
8200static int features_info_handler(struct nl_msg *msg, void *arg)
8201{
8202 struct nlattr *tb[NL80211_ATTR_MAX + 1];
8203 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
8204 struct features_info *info = arg;
8205 struct nlattr *nl_vend, *attr;
8206
8207 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
8208 genlmsg_attrlen(gnlh, 0), NULL);
8209
8210 nl_vend = tb[NL80211_ATTR_VENDOR_DATA];
8211 if (nl_vend) {
8212 struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1];
8213
8214 nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX,
8215 nla_data(nl_vend), nla_len(nl_vend), NULL);
8216
8217 attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_FEATURE_FLAGS];
8218 if (attr) {
8219 int len = nla_len(attr);
8220
Vamsi Krishna79a91132021-08-16 21:40:22 +05308221 if (info && len <= sizeof(info->flags)) {
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07008222 memcpy(info->flags, nla_data(attr), len);
8223 info->flags_len = len;
8224 }
8225 }
8226 }
8227
8228 return NL_SKIP;
8229}
8230
8231
8232static int check_feature(enum qca_wlan_vendor_features feature,
8233 struct features_info *info)
8234{
8235 size_t idx = feature / 8;
8236
Vamsi Krishna79a91132021-08-16 21:40:22 +05308237 if (!info)
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07008238 return 0;
8239
8240 return (idx < info->flags_len) &&
8241 (info->flags[idx] & BIT(feature % 8));
8242}
8243
8244#endif /* NL80211_SUPPORT */
8245
8246
8247static void sta_get_twt_feature_async_supp(struct sigma_dut *dut,
8248 const char *intf)
8249{
8250#ifdef NL80211_SUPPORT
8251 struct nl_msg *msg;
8252 struct features_info info = { 0 };
8253 int ifindex, ret;
8254
8255 ifindex = if_nametoindex(intf);
8256 if (ifindex == 0) {
8257 sigma_dut_print(dut, DUT_MSG_ERROR,
8258 "%s: Index for interface %s failed",
8259 __func__, intf);
8260 return;
8261 }
8262
8263 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8264 NL80211_CMD_VENDOR)) ||
8265 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8266 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8267 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8268 QCA_NL80211_VENDOR_SUBCMD_GET_FEATURES)) {
8269 sigma_dut_print(dut, DUT_MSG_ERROR,
8270 "%s: err in adding vendor_cmd and vendor_data",
8271 __func__);
8272 nlmsg_free(msg);
8273 return;
8274 }
8275
8276 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, features_info_handler,
8277 &info);
8278 if (ret) {
8279 sigma_dut_print(dut, DUT_MSG_ERROR,
8280 "%s: err in send_and_recv_msgs, ret=%d",
8281 __func__, ret);
8282 return;
8283 }
8284
8285 if (check_feature(QCA_WLAN_VENDOR_FEATURE_TWT_ASYNC_SUPPORT, &info))
8286 dut->sta_async_twt_supp = 1;
8287 else
8288 dut->sta_async_twt_supp = 0;
8289
8290 sigma_dut_print(dut, DUT_MSG_DEBUG,
8291 "%s: sta_async_twt_supp %d",
8292 __func__, dut->sta_async_twt_supp);
8293#else /* NL80211_SUPPORT */
8294 sigma_dut_print(dut, DUT_MSG_INFO,
8295 "TWT async supp get cannot be done without NL80211_SUPPORT defined");
8296 dut->sta_async_twt_supp = 0;
8297#endif /* NL80211_SUPPORT */
8298}
8299
8300
Arif Hussain480d5f42019-03-12 14:40:42 -07008301static int sta_set_twt_req_support(struct sigma_dut *dut, const char *intf,
8302 int val)
8303{
8304#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05308305 return wcn_wifi_test_config_set_u8(
8306 dut, intf,
8307 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TWT_REQ_SUPPORT, val);
Arif Hussain480d5f42019-03-12 14:40:42 -07008308#else /* NL80211_SUPPORT */
8309 sigma_dut_print(dut, DUT_MSG_ERROR,
8310 "TWT Request cannot be changed without NL80211_SUPPORT defined");
8311 return -1;
8312#endif /* NL80211_SUPPORT */
8313}
8314
8315
Kiran Kumar Lokere4f2d4b02021-04-01 00:07:39 -07008316static int sta_set_bss_max_idle_period(struct sigma_dut *dut, const char *intf,
8317 int val)
8318{
8319#ifdef NL80211_SUPPORT
8320 return wcn_wifi_test_config_set_u16(
8321 dut, intf,
8322 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BSS_MAX_IDLE_PERIOD, val);
8323#else /* NL80211_SUPPORT */
8324 sigma_dut_print(dut, DUT_MSG_ERROR,
8325 "BSS max idle period cannot be set without NL80211_SUPPORT defined");
8326 return -1;
8327#endif /* NL80211_SUPPORT */
8328}
8329
8330
Kiran Kumar Lokere07ad92b2021-08-09 00:27:14 -07008331static int sta_set_bss_max_idle_support(struct sigma_dut *dut, const char *intf,
8332 int val)
8333{
8334#ifdef NL80211_SUPPORT
8335 return wcn_wifi_test_config_set_u8(
8336 dut, intf,
8337 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BSS_MAX_IDLE_PERIOD_ENABLE,
8338 val);
8339#else /* NL80211_SUPPORT */
8340 sigma_dut_print(dut, DUT_MSG_ERROR,
8341 "BSS max idle support cannot be set without NL80211_SUPPORT defined");
8342 return -1;
8343#endif /* NL80211_SUPPORT */
8344}
8345
8346
Srinivas Girigowda0525e292020-11-12 13:28:21 -08008347static int sta_set_fullbw_ulmumimo(struct sigma_dut *dut, const char *intf,
8348 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_FULL_BW_UL_MU_MIMO, val);
8354#else /* NL80211_SUPPORT */
8355 sigma_dut_print(dut, DUT_MSG_ERROR,
8356 "Full BW UL MU MIMO cannot be changed without NL80211_SUPPORT defined");
8357 return -1;
8358#endif /* NL80211_SUPPORT */
8359}
8360
8361
Kiran Kumar Lokered0ec5ed2021-04-01 00:15:04 -07008362static int sta_set_punctured_preamble_rx(struct sigma_dut *dut,
8363 const char *intf, int val)
8364{
8365#ifdef NL80211_SUPPORT
8366 return wcn_wifi_test_config_set_u8(
8367 dut, intf,
8368 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_PUNCTURED_PREAMBLE_RX,
8369 val);
8370#else /* NL80211_SUPPORT */
8371 sigma_dut_print(dut, DUT_MSG_ERROR,
8372 "Punctured preamble Rx cannot be set without NL80211_SUPPORT defined");
8373 return -1;
8374#endif /* NL80211_SUPPORT */
8375}
8376
8377
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08008378static void sta_reset_default_wcn(struct sigma_dut *dut, const char *intf,
8379 const char *type)
8380{
8381 char buf[60];
8382
8383 if (dut->program == PROGRAM_HE) {
8384 /* resetting phymode to auto in case of HE program */
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05308385 sta_set_phymode(dut, intf, "auto");
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08008386
Amarnath Hullur Subramanyam9cecb502018-04-25 13:26:30 -07008387 /* reset the rate to Auto rate */
8388 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0xff",
8389 intf);
8390 if (system(buf) != 0) {
8391 sigma_dut_print(dut, DUT_MSG_ERROR,
8392 "iwpriv %s set_11ax_rate 0xff failed",
8393 intf);
8394 }
8395
Kiran Kumar Lokere86cfe3a2018-06-01 11:55:15 -07008396 /* reset the LDPC setting */
8397 snprintf(buf, sizeof(buf), "iwpriv %s ldpc 1", intf);
8398 if (system(buf) != 0) {
8399 sigma_dut_print(dut, DUT_MSG_ERROR,
8400 "iwpriv %s ldpc 1 failed", intf);
8401 }
8402
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08008403 /* reset the power save setting */
Vinita S. Malooa8b62722020-04-23 01:45:41 +05308404 set_power_save_wcn(dut, intf, 2);
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08008405
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08008406 /* remove all network profiles */
8407 remove_wpa_networks(intf);
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08008408
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08008409 /* Configure ADDBA Req/Rsp buffer size to be 64 */
8410 sta_set_addba_buf_size(dut, intf, 64);
8411
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07008412 if (dut->sta_async_twt_supp == -1)
8413 sta_get_twt_feature_async_supp(dut, intf);
8414
Kiran Kumar Lokere69d89952021-08-08 23:41:46 -07008415 sta_set_scan_unicast_probe(dut, intf, 0);
8416
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08008417#ifdef NL80211_SUPPORT
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08008418 /* Reset the device HE capabilities to its default supported
8419 * configuration. */
8420 sta_set_he_testbed_def(dut, intf, 0);
8421
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08008422 /* Disable noackpolicy for all AC */
8423 if (nlvendor_sta_set_noack(dut, intf, 0, QCA_WLAN_AC_ALL)) {
8424 sigma_dut_print(dut, DUT_MSG_ERROR,
8425 "Disable of noackpolicy for all AC failed");
8426 }
8427#endif /* NL80211_SUPPORT */
8428
Amarnath Hullur Subramanyamb1724a52018-03-07 14:31:46 -08008429 /* Enable WMM by default */
8430 if (wcn_sta_set_wmm(dut, intf, "on")) {
8431 sigma_dut_print(dut, DUT_MSG_ERROR,
8432 "Enable of WMM in sta_reset_default_wcn failed");
8433 }
8434
8435 /* Disable ADDBA_REJECT by default */
8436 if (nlvendor_sta_set_addba_reject(dut, intf, 0)) {
8437 sigma_dut_print(dut, DUT_MSG_ERROR,
8438 "Disable of addba_reject in sta_reset_default_wcn failed");
8439 }
8440
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08008441 /* Enable sending of ADDBA by default */
8442 if (nlvendor_config_send_addba(dut, intf, 1)) {
8443 sigma_dut_print(dut, DUT_MSG_ERROR,
8444 "Enable sending of ADDBA in sta_reset_default_wcn failed");
8445 }
8446
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08008447 /* Enable AMPDU by default */
8448 iwpriv_sta_set_ampdu(dut, intf, 1);
8449
Subhani Shaik8e7a3052018-04-24 14:03:00 -07008450#ifdef NL80211_SUPPORT
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -08008451 if (wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_AUTO)) {
Subhani Shaik8e7a3052018-04-24 14:03:00 -07008452 sigma_dut_print(dut, DUT_MSG_ERROR,
8453 "Set LTF config to default in sta_reset_default_wcn failed");
8454 }
Arif Hussain9765f7d2018-07-03 08:28:26 -07008455
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08008456 /* set the beamformee NSTS(maximum number of
8457 * space-time streams) to default DUT config
8458 */
8459 if (sta_set_beamformee_sts(dut, intf, 7)) {
Arif Hussain9765f7d2018-07-03 08:28:26 -07008460 sigma_dut_print(dut, DUT_MSG_ERROR,
8461 "Failed to set BeamformeeSTS");
8462 }
Arif Hussain68d23f52018-07-11 13:39:08 -07008463
Kiran Kumar Lokere54b72522021-04-01 00:22:44 -07008464 if (sta_set_mgmt_data_tx_disable_cfg(dut, intf, 0)) {
8465 sigma_dut_print(dut, DUT_MSG_ERROR,
8466 "Failed to reset mgmt/data Tx disable config");
8467 }
8468
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07008469 if (sta_set_mac_padding_duration(
8470 dut, intf,
8471 QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07008472 sigma_dut_print(dut, DUT_MSG_ERROR,
8473 "Failed to set MAC padding duration");
8474 }
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07008475
8476 if (sta_set_mu_edca_override(dut, intf, 0)) {
8477 sigma_dut_print(dut, DUT_MSG_ERROR,
8478 "ErrorCode,Failed to set MU EDCA override disable");
8479 }
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07008480
Kiran Kumar Lokerefa7c7b92021-08-09 00:50:55 -07008481 if (sta_set_ru_242_tone_tx(dut, intf, 0)) {
8482 sigma_dut_print(dut, DUT_MSG_ERROR,
8483 "Failed to set RU 242 tone Tx");
8484 }
8485
8486 if (sta_set_er_su_ppdu_type_tx(dut, intf, 0)) {
8487 sigma_dut_print(dut, DUT_MSG_ERROR,
8488 "Failed to set ER-SU PPDU type Tx");
8489 }
8490
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07008491 if (sta_set_om_ctrl_supp(dut, intf, 1)) {
8492 sigma_dut_print(dut, DUT_MSG_ERROR,
8493 "Failed to set OM ctrl supp");
8494 }
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07008495
8496 if (sta_set_tx_su_ppdu_cfg(dut, intf, 1)) {
8497 sigma_dut_print(dut, DUT_MSG_ERROR,
8498 "Failed to set Tx SU PPDU enable");
8499 }
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07008500
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07008501 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 0)) {
8502 sigma_dut_print(dut, DUT_MSG_ERROR,
8503 "failed to send TB PPDU Tx cfg");
8504 }
8505
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07008506 if (sta_set_he_om_ctrl_reset(dut, intf)) {
8507 sigma_dut_print(dut, DUT_MSG_ERROR,
8508 "Failed to set OM ctrl reset");
8509 }
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08008510
8511 /* +HTC-HE support default on */
8512 if (sta_set_he_htc_supp(dut, intf, 1)) {
8513 sigma_dut_print(dut, DUT_MSG_ERROR,
8514 "Setting of +HTC-HE support failed");
8515 }
Subhani Shaik8e7a3052018-04-24 14:03:00 -07008516#endif /* NL80211_SUPPORT */
8517
Arif Hussain8d5b27b2018-05-14 14:31:03 -07008518 if (sta_set_tx_beamformee(dut, intf, 1)) {
8519 sigma_dut_print(dut, DUT_MSG_ERROR,
8520 "Set tx beamformee enable by default in sta_reset_default_wcn failed");
8521 }
8522
Kiran Kumar Lokereb55ff442020-07-15 00:20:40 -07008523 wpa_command(intf, "SET oce 1");
8524
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08008525 /* Set nss to 1 and MCS 0-7 in case of testbed */
8526 if (type && strcasecmp(type, "Testbed") == 0) {
8527#ifdef NL80211_SUPPORT
8528 int ret;
8529#endif /* NL80211_SUPPORT */
8530
Kiran Kumar Lokereb55ff442020-07-15 00:20:40 -07008531 wpa_command(intf, "SET oce 0");
8532
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08008533 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
8534 if (system(buf) != 0) {
8535 sigma_dut_print(dut, DUT_MSG_ERROR,
8536 "iwpriv %s nss failed", intf);
8537 }
8538
8539#ifdef NL80211_SUPPORT
8540 ret = sta_set_he_mcs(dut, intf, HE_80_MCS0_7);
8541 if (ret) {
8542 sigma_dut_print(dut, DUT_MSG_ERROR,
8543 "Setting of MCS failed, ret:%d",
8544 ret);
8545 }
8546#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyamc67621d2018-02-04 23:18:01 -08008547
8548 /* Disable STBC as default */
8549 wcn_sta_set_stbc(dut, intf, "0");
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08008550
8551 /* Disable AMSDU as default */
8552 iwpriv_sta_set_amsdu(dut, intf, "0");
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08008553
8554#ifdef NL80211_SUPPORT
8555 /* HE fragmentation default off */
8556 if (sta_set_he_fragmentation(dut, intf,
8557 HE_FRAG_DISABLE)) {
8558 sigma_dut_print(dut, DUT_MSG_ERROR,
8559 "Setting of HE fragmentation failed");
8560 }
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08008561
8562 /* set the beamformee NSTS(maximum number of
8563 * space-time streams) to default testbed config
8564 */
8565 if (sta_set_beamformee_sts(dut, intf, 3)) {
8566 sigma_dut_print(dut, DUT_MSG_ERROR,
8567 "Failed to set BeamformeeSTS");
8568 }
8569
Kiran Kumar Lokered0ec5ed2021-04-01 00:15:04 -07008570 if (sta_set_punctured_preamble_rx(dut, intf, 0)) {
8571 sigma_dut_print(dut, DUT_MSG_ERROR,
8572 "Failed to reset PreamblePunctRx support");
8573 }
8574
Kiran Kumar Lokere727687f2021-06-24 00:35:49 -07008575 if (sta_set_bss_max_idle_period(dut, intf, 0)) {
8576 sigma_dut_print(dut, DUT_MSG_ERROR,
8577 "Failed to reset BSS max idle period");
8578 }
8579
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08008580 /* +HTC-HE support default off */
8581 if (sta_set_he_htc_supp(dut, intf, 0)) {
8582 sigma_dut_print(dut, DUT_MSG_ERROR,
8583 "Setting of +HTC-HE support failed");
8584 }
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08008585
8586 /* Set device HE capabilities to testbed default
8587 * configuration. */
8588 if (sta_set_he_testbed_def(dut, intf, 1)) {
8589 sigma_dut_print(dut, DUT_MSG_DEBUG,
8590 "Failed to set HE defaults");
8591 }
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08008592
8593 /* Disable VHT support in 2.4 GHz for testbed */
8594 sta_set_2g_vht_supp(dut, intf, 0);
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08008595#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08008596
8597 /* Enable WEP/TKIP with HE capability in testbed */
8598 if (sta_set_heconfig_and_wep_tkip(dut, intf, 1)) {
8599 sigma_dut_print(dut, DUT_MSG_ERROR,
8600 "Enabling HE config with WEP/TKIP failed");
8601 }
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08008602 }
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08008603
8604 /* Defaults in case of DUT */
8605 if (type && strcasecmp(type, "DUT") == 0) {
Arif Hussaind48fcc72018-05-01 18:34:18 -07008606 /* Enable STBC by default */
8607 wcn_sta_set_stbc(dut, intf, "1");
8608
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08008609 /* set nss to 2 */
8610 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
8611 if (system(buf) != 0) {
8612 sigma_dut_print(dut, DUT_MSG_ERROR,
8613 "iwpriv %s nss 2 failed", intf);
8614 }
Arif Hussainac6c5112018-05-25 17:34:00 -07008615 dut->sta_nss = 2;
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08008616
8617#ifdef NL80211_SUPPORT
Arif Hussainae239842018-05-01 18:20:05 -07008618 /* Set HE_MCS to 0-11 */
8619 if (sta_set_he_mcs(dut, intf, HE_80_MCS0_11)) {
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08008620 sigma_dut_print(dut, DUT_MSG_ERROR,
8621 "Setting of MCS failed");
8622 }
8623#endif /* NL80211_SUPPORT */
8624
8625 /* Disable WEP/TKIP with HE capability in DUT */
8626 if (sta_set_heconfig_and_wep_tkip(dut, intf, 0)) {
8627 sigma_dut_print(dut, DUT_MSG_ERROR,
8628 "Enabling HE config with WEP/TKIP failed");
8629 }
8630 }
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08008631 }
8632}
8633
8634
Veerendranath Jakkam47867202020-12-21 01:53:52 +05308635static int sta_set_client_privacy(struct sigma_dut *dut,
8636 struct sigma_conn *conn, const char *intf,
8637 int enable)
8638{
8639 if (enable &&
8640 (wpa_command(intf, "SET mac_addr 1") < 0 ||
8641 wpa_command(intf, "SET rand_addr_lifetime 1") < 0 ||
Veerendranath Jakkam39fd5c42020-12-21 02:02:21 +05308642 (wpa_command(intf, "MAC_RAND_SCAN enable=1 all") < 0 &&
8643 wpa_command(intf, "SET preassoc_mac_addr 1") < 0) ||
Veerendranath Jakkam47867202020-12-21 01:53:52 +05308644 wpa_command(intf, "SET gas_rand_mac_addr 1") < 0 ||
8645 wpa_command(intf, "SET gas_rand_addr_lifetime 1") < 0))
8646 return -1;
8647
8648 if (!enable &&
8649 (wpa_command(intf, "SET mac_addr 0") < 0 ||
Veerendranath Jakkam39fd5c42020-12-21 02:02:21 +05308650 (wpa_command(intf, "MAC_RAND_SCAN enable=0 all") < 0 &&
8651 wpa_command(intf, "SET preassoc_mac_addr 0") < 0) ||
Veerendranath Jakkam47867202020-12-21 01:53:52 +05308652 wpa_command(intf, "SET gas_rand_mac_addr 0") < 0))
8653 return -1;
8654
8655 dut->client_privacy = enable;
8656 return 0;
8657}
8658
8659
Jouni Malinenf7222712019-06-13 01:50:21 +03008660static enum sigma_cmd_result cmd_sta_reset_default(struct sigma_dut *dut,
8661 struct sigma_conn *conn,
8662 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008663{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008664 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008665 const char *band = get_param(cmd, "band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008666 const char *type;
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07008667 const char *program = get_param(cmd, "program");
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05308668 const char *dev_role = get_param(cmd, "DevRole");
Veerendranath Jakkamc1f71b62021-01-23 03:09:51 +05308669 char resp[20];
Veerendranath Jakkamea7f0692021-08-11 19:13:12 +05308670 char buf[100];
Veerendranath Jakkamc1f71b62021-01-23 03:09:51 +05308671 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008672
Jouni Malinenb21f0542019-11-04 17:53:38 +02008673 if (dut->station_ifname_2g &&
8674 strcmp(dut->station_ifname_2g, intf) == 0)
8675 dut->use_5g = 0;
8676 else if (dut->station_ifname_5g &&
8677 strcmp(dut->station_ifname_5g, intf) == 0)
8678 dut->use_5g = 1;
8679
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07008680 if (!program)
8681 program = get_param(cmd, "prog");
8682 dut->program = sigma_program_to_enum(program);
Vinita S. Maloof7a2cbf2020-11-18 19:29:44 +05308683
8684 if (dut->program == PROGRAM_WFD && dut->user_config_timeout)
8685 dut->default_timeout = dut->user_config_timeout;
8686
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008687 dut->device_type = STA_unknown;
8688 type = get_param(cmd, "type");
8689 if (type && strcasecmp(type, "Testbed") == 0)
8690 dut->device_type = STA_testbed;
8691 if (type && strcasecmp(type, "DUT") == 0)
8692 dut->device_type = STA_dut;
8693
8694 if (dut->program == PROGRAM_TDLS) {
8695 /* Clear TDLS testing mode */
8696 wpa_command(intf, "SET tdls_disabled 0");
8697 wpa_command(intf, "SET tdls_testing 0");
8698 dut->no_tpk_expiration = 0;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008699 if (get_driver_type(dut) == DRIVER_WCN) {
Pradeep Reddy POTTETI8ce2a232016-10-28 12:17:32 +05308700 /* Enable the WCN driver in TDLS Explicit trigger mode
8701 */
8702 wpa_command(intf, "SET tdls_external_control 0");
8703 wpa_command(intf, "SET tdls_trigger_control 0");
8704 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008705 }
8706
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07008707#ifdef MIRACAST
8708 if (dut->program == PROGRAM_WFD ||
8709 dut->program == PROGRAM_DISPLAYR2)
8710 miracast_sta_reset_default(dut, conn, cmd);
8711#endif /* MIRACAST */
8712
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008713 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008714 case DRIVER_ATHEROS:
8715 sta_reset_default_ath(dut, intf, type);
8716 break;
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08008717 case DRIVER_WCN:
8718 sta_reset_default_wcn(dut, intf, type);
8719 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008720 default:
8721 break;
8722 }
8723
8724#ifdef ANDROID_NAN
8725 if (dut->program == PROGRAM_NAN)
8726 nan_cmd_sta_reset_default(dut, conn, cmd);
8727#endif /* ANDROID_NAN */
8728
Vinay Gannevaram3b9fdd32019-06-14 17:55:44 +05308729 if (dut->program == PROGRAM_LOC &&
8730 lowi_cmd_sta_reset_default(dut, conn, cmd) < 0)
8731 return ERROR_SEND_STATUS;
8732
Jouni Malinenba630452018-06-22 11:49:59 +03008733 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008734 unlink("SP/wi-fi.org/pps.xml");
8735 if (system("rm -r SP/*") != 0) {
8736 }
8737 unlink("next-client-cert.pem");
8738 unlink("next-client-key.pem");
8739 }
8740
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008741 /* For WPS program of the 60 GHz band the band type needs to be saved */
8742 if (dut->program == PROGRAM_WPS) {
8743 if (band && strcasecmp(band, "60GHz") == 0) {
8744 dut->band = WPS_BAND_60G;
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02008745 /* For 60 GHz enable WPS for WPS TCs */
8746 dut->wps_disable = 0;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008747 } else {
8748 dut->band = WPS_BAND_NON_60G;
8749 }
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02008750 } else if (dut->program == PROGRAM_60GHZ) {
8751 /* For 60 GHz MAC/PHY TCs WPS must be disabled */
8752 dut->wps_disable = 1;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008753 }
8754
Alexei Avshalom Lazar157ba062018-12-23 16:15:26 +02008755 if (is_60g_sigma_dut(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008756 const char *dev_role = get_param(cmd, "DevRole");
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02008757 char buf[256];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008758
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02008759 sigma_dut_print(dut, DUT_MSG_INFO,
8760 "WPS 60 GHz program, wps_disable = %d",
8761 dut->wps_disable);
8762
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008763 if (!dev_role) {
8764 send_resp(dut, conn, SIGMA_ERROR,
8765 "errorCode,Missing DevRole argument");
8766 return 0;
8767 }
8768
8769 if (strcasecmp(dev_role, "STA") == 0)
8770 dut->dev_role = DEVROLE_STA;
8771 else if (strcasecmp(dev_role, "PCP") == 0)
8772 dut->dev_role = DEVROLE_PCP;
8773 else {
8774 send_resp(dut, conn, SIGMA_ERROR,
8775 "errorCode,Unknown DevRole");
8776 return 0;
8777 }
8778
8779 if (dut->device_type == STA_unknown) {
8780 sigma_dut_print(dut, DUT_MSG_ERROR,
8781 "Device type is not STA testbed or DUT");
8782 send_resp(dut, conn, SIGMA_ERROR,
8783 "errorCode,Unknown device type");
8784 return 0;
8785 }
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02008786
8787 sigma_dut_print(dut, DUT_MSG_DEBUG,
8788 "Setting msdu_size to MAX: 7912");
8789 snprintf(buf, sizeof(buf), "ifconfig %s mtu 7912",
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008790 get_station_ifname(dut));
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02008791
8792 if (system(buf) != 0) {
8793 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
8794 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02008795 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02008796 }
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02008797
8798 if (sta_set_force_mcs(dut, 0, 1)) {
8799 sigma_dut_print(dut, DUT_MSG_ERROR,
8800 "Failed to reset force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02008801 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02008802 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008803 }
8804
8805 wpa_command(intf, "WPS_ER_STOP");
8806 wpa_command(intf, "FLUSH");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05308807 wpa_command(intf, "ERP_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008808 wpa_command(intf, "SET radio_disabled 0");
8809
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02008810 dut->wps_forced_version = 0;
8811
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008812 if (dut->wsc_fragment) {
8813 dut->wsc_fragment = 0;
8814 wpa_command(intf, "SET device_name Test client");
8815 wpa_command(intf, "SET manufacturer ");
8816 wpa_command(intf, "SET model_name ");
8817 wpa_command(intf, "SET model_number ");
8818 wpa_command(intf, "SET serial_number ");
8819 }
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02008820 if (is_60g_sigma_dut(dut) && dut->force_rsn_ie) {
8821 dut->force_rsn_ie = FORCE_RSN_IE_NONE;
8822 sta_60g_force_rsn_ie(dut, FORCE_RSN_IE_NONE);
8823 }
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008824
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008825 if (dut->tmp_mac_addr && dut->set_macaddr) {
8826 dut->tmp_mac_addr = 0;
8827 if (system(dut->set_macaddr) != 0) {
8828 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to clear "
8829 "temporary MAC address");
8830 }
8831 }
8832
8833 set_ps(intf, dut, 0);
8834
Jouni Malinenba630452018-06-22 11:49:59 +03008835 if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2 ||
8836 dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008837 wpa_command(intf, "SET interworking 1");
8838 wpa_command(intf, "SET hs20 1");
8839 }
8840
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08008841 if (dut->program == PROGRAM_HS2_R2 ||
Jouni Malinenba630452018-06-22 11:49:59 +03008842 dut->program == PROGRAM_HS2_R3 ||
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08008843 dut->program == PROGRAM_OCE) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008844 wpa_command(intf, "SET pmf 1");
8845 } else {
8846 wpa_command(intf, "SET pmf 0");
8847 }
8848
8849 hs2_clear_credentials(intf);
8850 wpa_command(intf, "SET hessid 00:00:00:00:00:00");
8851 wpa_command(intf, "SET access_network_type 15");
8852
8853 static_ip_file(0, NULL, NULL, NULL);
8854 kill_dhcp_client(dut, intf);
8855 clear_ip_addr(dut, intf);
8856
8857 dut->er_oper_performed = 0;
8858 dut->er_oper_bssid[0] = '\0';
8859
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07008860 if (dut->program == PROGRAM_LOC) {
8861 /* Disable Interworking by default */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008862 wpa_command(get_station_ifname(dut), "SET interworking 0");
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07008863 }
8864
Kiran Kumar Lokeredd086642020-06-04 00:29:26 -07008865 if (dut->program == PROGRAM_MBO || dut->program == PROGRAM_HE) {
Ashwini Patil00402582017-04-13 12:29:39 +05308866 free(dut->non_pref_ch_list);
8867 dut->non_pref_ch_list = NULL;
Ashwini Patil5acd7382017-04-13 15:55:04 +05308868 free(dut->btm_query_cand_list);
8869 dut->btm_query_cand_list = NULL;
Ashwini Patilc63161e2017-04-13 16:30:23 +05308870 wpa_command(intf, "SET reject_btm_req_reason 0");
Ashwini Patila75de5a2017-04-13 16:35:05 +05308871 wpa_command(intf, "SET ignore_assoc_disallow 0");
Ashwini Patild174f2c2017-04-13 16:49:46 +05308872 wpa_command(intf, "SET gas_address3 0");
Ashwini Patil9183fdb2017-04-13 16:58:25 +05308873 wpa_command(intf, "SET roaming 1");
Ankita Bajaj1d974552018-09-18 16:56:44 +05308874 wpa_command(intf, "SET interworking 1");
Ashwini Patil00402582017-04-13 12:29:39 +05308875 }
8876
Jouni Malinen3c367e82017-06-23 17:01:47 +03008877 free(dut->rsne_override);
8878 dut->rsne_override = NULL;
8879
Jouni Malinen68143132017-09-02 02:34:08 +03008880 free(dut->sae_commit_override);
8881 dut->sae_commit_override = NULL;
Jouni Malinen4b3769d2019-10-10 16:20:29 +03008882 wpa_command(intf, "SET sae_pmkid_in_assoc 0");
Jouni Malinen11e55212019-11-22 21:46:59 +02008883 dut->sae_pwe = SAE_PWE_DEFAULT;
Jouni Malinen68143132017-09-02 02:34:08 +03008884
Jouni Malinen134fe3c2019-06-12 04:16:49 +03008885 dut->sta_associate_wait_connect = 0;
8886 dut->server_cert_hash[0] = '\0';
Jouni Malinen37d5c692019-08-19 16:56:55 +03008887 dut->server_cert_tod = 0;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03008888 dut->sta_tod_policy = 0;
8889
Jouni Malinend86e5822017-08-29 03:55:32 +03008890 dut->dpp_conf_id = -1;
Jouni Malinenb1dd21f2017-11-13 19:14:29 +02008891 free(dut->dpp_peer_uri);
8892 dut->dpp_peer_uri = NULL;
Jouni Malinen63d50412017-11-24 11:55:38 +02008893 dut->dpp_local_bootstrap = -1;
Jouni Malinen5011fb52017-12-05 21:00:15 +02008894 wpa_command(intf, "SET dpp_config_processing 2");
Jouni Malinen90776b12020-05-04 15:34:46 +03008895 wpa_command(intf, "SET dpp_mud_url ");
Jouni Malinend86e5822017-08-29 03:55:32 +03008896
Jouni Malinenfac9cad2017-10-10 18:35:55 +03008897 wpa_command(intf, "VENDOR_ELEM_REMOVE 13 *");
8898
vamsi krishnaa2799492017-12-05 14:28:01 +05308899 if (dut->program == PROGRAM_OCE) {
Ankita Bajaja2cb5672017-10-25 16:08:28 +05308900 wpa_command(intf, "SET oce 1");
vamsi krishnaa2799492017-12-05 14:28:01 +05308901 wpa_command(intf, "SET disable_fils 0");
Ankita Bajaj1bde7942018-01-09 19:15:01 +05308902 wpa_command(intf, "FILS_HLP_REQ_FLUSH");
8903 dut->fils_hlp = 0;
8904#ifdef ANDROID
8905 hlp_thread_cleanup(dut);
8906#endif /* ANDROID */
vamsi krishnaa2799492017-12-05 14:28:01 +05308907 }
Ankita Bajaja2cb5672017-10-25 16:08:28 +05308908
Veerendranath Jakkamea7f0692021-08-11 19:13:12 +05308909 if (dut->program == PROGRAM_QM) {
Vamsi Krishnaf642d6a2020-03-27 12:33:14 +05308910 wpa_command(intf, "SET interworking 1");
Vinita S. Maloo2287f142021-02-01 16:17:09 +05308911 wpa_command(intf, "SET disable_scs_support 0");
Vinita S. Maloo83dee552021-04-12 16:47:47 +05308912 wpa_command(intf, "SET disable_mscs_support 0");
Veerendranath Jakkama16cdc82021-09-12 16:44:22 +05308913 wpa_command(intf, "SET enable_dscp_policy_capa 1");
Veerendranath Jakkam329a3cd2021-09-11 18:10:13 +05308914 dut->qm_domain_name[0] = '\0';
Veerendranath Jakkama16cdc82021-09-12 16:44:22 +05308915 dut->reject_dscp_policies = 0;
Veerendranath Jakkamea7f0692021-08-11 19:13:12 +05308916 snprintf(buf, sizeof(buf),
8917 "ip -6 route replace fe80::/64 dev %s table local",
8918 intf);
8919 if (system(buf) != 0)
8920 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run: %s",
8921 buf);
Veerendranath Jakkam9ceb3b12021-09-10 03:18:17 +05308922
8923 stop_dscp_policy_mon_thread(dut);
8924 clear_all_dscp_policies(dut);
Veerendranath Jakkamea7f0692021-08-11 19:13:12 +05308925 }
Vamsi Krishnaf642d6a2020-03-27 12:33:14 +05308926
Jouni Malinen8179fee2019-03-28 03:19:47 +02008927 dut->akm_values = 0;
Shivani Baranwal7aa48602021-09-29 10:53:38 +05308928
8929#ifdef NL80211_SUPPORT
8930 if (get_driver_type(dut) == DRIVER_WCN)
8931 sta_config_params(dut, intf, STA_SET_FT_DS, 0);
8932#endif /* NL80211_SUPPORT */
8933
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03008934 dut->sta_ft_ds = 0;
Jouni Malinen8179fee2019-03-28 03:19:47 +02008935
Sunil Dutt076081f2018-02-05 19:45:50 +05308936#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008937 if (get_driver_type(dut) == DRIVER_WCN &&
Sunil Dutt44595082018-02-12 19:41:45 +05308938 dut->config_rsnie == 1) {
8939 dut->config_rsnie = 0;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05308940 sta_config_params(dut, intf, STA_SET_RSNIE, 0);
Sunil Dutt076081f2018-02-05 19:45:50 +05308941 }
8942#endif /* NL80211_SUPPORT */
8943
Sunil Duttfebf8a82018-02-09 18:50:13 +05308944 if (dev_role && strcasecmp(dev_role, "STA-CFON") == 0) {
8945 dut->dev_role = DEVROLE_STA_CFON;
8946 return sta_cfon_reset_default(dut, conn, cmd);
8947 }
8948
Jouni Malinen439352d2018-09-13 03:42:23 +03008949 wpa_command(intf, "SET setband AUTO");
8950
Veerendranath Jakkamc1f71b62021-01-23 03:09:51 +05308951 ret = wpa_command_resp(intf, "GET_CAPABILITY ocv", resp, sizeof(resp));
8952 dut->ocvc = ret == 0 && strncmp(resp, "supported", 9) == 0;
8953
8954 ret = wpa_command_resp(intf, "GET_CAPABILITY beacon_prot", resp,
8955 sizeof(resp));
8956 dut->beacon_prot = ret == 0 && strncmp(resp, "supported", 9) == 0;
8957
Veerendranath Jakkam47867202020-12-21 01:53:52 +05308958 if (sta_set_client_privacy(dut, conn, intf,
8959 dut->program == PROGRAM_WPA3 &&
8960 dut->device_type == STA_dut &&
8961 dut->client_privacy_default)) {
8962 sigma_dut_print(dut, DUT_MSG_ERROR,
8963 "Failed to set client privacy functionality");
8964 /* sta_reset_default command is not really supposed to fail,
8965 * so allow this to continue. */
8966 }
8967
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +05308968 dut->saquery_oci_freq = 0;
Vamsi Krishnac1633d22020-05-06 18:31:21 +05308969
Sunil Duttfebf8a82018-02-09 18:50:13 +05308970 if (dut->program != PROGRAM_VHT)
8971 return cmd_sta_p2p_reset(dut, conn, cmd);
8972
Priyadharshini Gowthamana7dfd492015-11-09 14:34:08 -08008973 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008974}
8975
8976
Jouni Malinenf7222712019-06-13 01:50:21 +03008977static enum sigma_cmd_result cmd_sta_get_events(struct sigma_dut *dut,
8978 struct sigma_conn *conn,
8979 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008980{
8981 const char *program = get_param(cmd, "Program");
8982
8983 if (program == NULL)
8984 return -1;
8985#ifdef ANDROID_NAN
8986 if (strcasecmp(program, "NAN") == 0)
8987 return nan_cmd_sta_get_events(dut, conn, cmd);
8988#endif /* ANDROID_NAN */
8989 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
8990 return 0;
8991}
8992
8993
Jouni Malinen82905202018-04-29 17:20:10 +03008994static int sta_exec_action_url(struct sigma_dut *dut, struct sigma_conn *conn,
8995 struct sigma_cmd *cmd)
8996{
8997 const char *url = get_param(cmd, "url");
8998 const char *method = get_param(cmd, "method");
8999 pid_t pid;
9000 int status;
9001
9002 if (!url || !method)
9003 return -1;
9004
9005 /* TODO: Add support for method,post */
9006 if (strcasecmp(method, "get") != 0) {
9007 send_resp(dut, conn, SIGMA_ERROR,
9008 "ErrorCode,Unsupported method");
9009 return 0;
9010 }
9011
9012 pid = fork();
9013 if (pid < 0) {
9014 perror("fork");
9015 return -1;
9016 }
9017
9018 if (pid == 0) {
9019 char * argv[5] = { "wget", "-O", "/dev/null",
9020 (char *) url, NULL };
9021
9022 execv("/usr/bin/wget", argv);
9023 perror("execv");
9024 exit(0);
9025 return -1;
9026 }
9027
9028 if (waitpid(pid, &status, 0) < 0) {
9029 perror("waitpid");
9030 return -1;
9031 }
9032
9033 if (WIFEXITED(status)) {
9034 const char *errmsg;
9035
9036 if (WEXITSTATUS(status) == 0)
9037 return 1;
9038 sigma_dut_print(dut, DUT_MSG_INFO, "wget exit status %d",
9039 WEXITSTATUS(status));
9040 switch (WEXITSTATUS(status)) {
9041 case 4:
9042 errmsg = "errmsg,Network failure";
9043 break;
9044 case 8:
9045 errmsg = "errmsg,Server issued an error response";
9046 break;
9047 default:
9048 errmsg = "errmsg,Unknown failure from wget";
9049 break;
9050 }
9051 send_resp(dut, conn, SIGMA_ERROR, errmsg);
9052 return 0;
9053 }
9054
9055 send_resp(dut, conn, SIGMA_ERROR, "errmsg,Unknown failure");
9056 return 0;
9057}
9058
9059
Jouni Malinenf7222712019-06-13 01:50:21 +03009060static enum sigma_cmd_result cmd_sta_exec_action(struct sigma_dut *dut,
9061 struct sigma_conn *conn,
9062 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009063{
9064 const char *program = get_param(cmd, "Prog");
9065
Jouni Malinen82905202018-04-29 17:20:10 +03009066 if (program && !get_param(cmd, "interface"))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009067 return -1;
9068#ifdef ANDROID_NAN
Jouni Malinen82905202018-04-29 17:20:10 +03009069 if (program && strcasecmp(program, "NAN") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009070 return nan_cmd_sta_exec_action(dut, conn, cmd);
9071#endif /* ANDROID_NAN */
Jouni Malinen82905202018-04-29 17:20:10 +03009072
9073 if (program && strcasecmp(program, "Loc") == 0)
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07009074 return loc_cmd_sta_exec_action(dut, conn, cmd);
Jouni Malinen82905202018-04-29 17:20:10 +03009075
9076 if (get_param(cmd, "url"))
9077 return sta_exec_action_url(dut, conn, cmd);
9078
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009079 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
9080 return 0;
9081}
9082
9083
Jouni Malinenf7222712019-06-13 01:50:21 +03009084static enum sigma_cmd_result cmd_sta_set_11n(struct sigma_dut *dut,
9085 struct sigma_conn *conn,
9086 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009087{
9088 const char *intf = get_param(cmd, "Interface");
9089 const char *val, *mcs32, *rate;
9090
9091 val = get_param(cmd, "GREENFIELD");
9092 if (val) {
9093 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
9094 /* Enable GD */
9095 send_resp(dut, conn, SIGMA_ERROR,
9096 "ErrorCode,GF not supported");
9097 return 0;
9098 }
9099 }
9100
9101 val = get_param(cmd, "SGI20");
9102 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009103 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009104 case DRIVER_ATHEROS:
9105 ath_sta_set_sgi(dut, intf, val);
9106 break;
9107 default:
9108 send_resp(dut, conn, SIGMA_ERROR,
9109 "ErrorCode,SGI20 not supported");
9110 return 0;
9111 }
9112 }
9113
9114 mcs32 = get_param(cmd, "MCS32"); /* HT Duplicate Mode Enable/Disable */
9115 rate = get_param(cmd, "MCS_FIXEDRATE"); /* Fixed MCS rate (0..31) */
9116 if (mcs32 && rate) {
9117 /* TODO */
9118 send_resp(dut, conn, SIGMA_ERROR,
9119 "ErrorCode,MCS32,MCS_FIXEDRATE not supported");
9120 return 0;
9121 } else if (mcs32 && !rate) {
9122 /* TODO */
9123 send_resp(dut, conn, SIGMA_ERROR,
9124 "ErrorCode,MCS32 not supported");
9125 return 0;
9126 } else if (!mcs32 && rate) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009127 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009128 case DRIVER_ATHEROS:
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07009129 novap_reset(dut, intf, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009130 ath_sta_set_11nrates(dut, intf, rate);
9131 break;
9132 default:
9133 send_resp(dut, conn, SIGMA_ERROR,
9134 "ErrorCode,MCS32_FIXEDRATE not supported");
9135 return 0;
9136 }
9137 }
9138
9139 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
9140}
9141
9142
Arif Hussain7b47d2d2018-05-09 10:44:02 -07009143static void cmd_set_max_he_mcs(struct sigma_dut *dut, const char *intf,
9144 int mcs_config)
9145{
9146#ifdef NL80211_SUPPORT
9147 int ret;
9148
9149 switch (mcs_config) {
9150 case HE_80_MCS0_7:
9151 case HE_80_MCS0_9:
9152 case HE_80_MCS0_11:
9153 ret = sta_set_he_mcs(dut, intf, mcs_config);
9154 if (ret) {
9155 sigma_dut_print(dut, DUT_MSG_ERROR,
9156 "cmd_set_max_he_mcs: Setting of MCS:%d failed, ret:%d",
9157 mcs_config, ret);
9158 }
9159 break;
9160 default:
9161 sigma_dut_print(dut, DUT_MSG_ERROR,
9162 "cmd_set_max_he_mcs: Invalid mcs %d",
9163 mcs_config);
9164 break;
9165 }
9166#else /* NL80211_SUPPORT */
9167 sigma_dut_print(dut, DUT_MSG_ERROR,
9168 "max HE MCS cannot be changed without NL80211_SUPPORT defined");
9169#endif /* NL80211_SUPPORT */
9170}
9171
9172
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07009173struct wait_event {
9174 struct sigma_dut *dut;
9175 int cmd;
9176 unsigned int twt_op;
9177};
9178
9179#ifdef NL80211_SUPPORT
9180
9181static int twt_event_handler(struct nl_msg *msg, void *arg)
9182{
9183 struct wait_event *wait = arg;
9184 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
9185 struct nlattr *tb[NL80211_ATTR_MAX + 1];
9186 uint32_t subcmd;
9187 uint8_t *data = NULL;
9188 size_t len = 0;
9189 struct nlattr *twt_rsp[QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_MAX + 1];
9190 struct nlattr *twt_status[QCA_WLAN_VENDOR_ATTR_TWT_SETUP_MAX + 1];
9191 int cmd_id;
9192 unsigned char val;
9193
9194 if (!wait)
9195 return NL_SKIP;
9196
9197 if (gnlh->cmd != NL80211_CMD_VENDOR) {
9198 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9199 "%s: NL cmd is not vendor %d", __func__,
9200 gnlh->cmd);
9201 return NL_SKIP;
9202 }
9203
9204 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
9205 genlmsg_attrlen(gnlh, 0), NULL);
9206
9207 if (!tb[NL80211_ATTR_VENDOR_ID] || !tb[NL80211_ATTR_VENDOR_SUBCMD]) {
9208 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9209 "%s: vendor ID not found", __func__);
9210 return NL_SKIP;
9211 }
9212 subcmd = nla_get_u32(tb[NL80211_ATTR_VENDOR_SUBCMD]);
9213
9214 if (subcmd != QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) {
9215 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9216 "%s: Not a TWT_cmd %d", __func__, subcmd);
9217 return NL_SKIP;
9218 }
9219 if (tb[NL80211_ATTR_VENDOR_DATA]) {
9220 data = nla_data(tb[NL80211_ATTR_VENDOR_DATA]);
9221 len = nla_len(tb[NL80211_ATTR_VENDOR_DATA]);
9222 } else {
9223 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9224 "%s: vendor data not present", __func__);
9225 return NL_SKIP;
9226 }
9227 if (!data || !len) {
9228 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9229 "Invalid vendor data or len");
9230 return NL_SKIP;
9231 }
9232 sigma_dut_print(wait->dut, DUT_MSG_DEBUG,
9233 "event data len %ld", len);
9234 hex_dump(wait->dut, data, len);
9235 if (nla_parse(twt_rsp, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_MAX,
9236 (struct nlattr *) data, len, NULL)) {
9237 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9238 "vendor data parse error");
9239 return NL_SKIP;
9240 }
9241
9242 val = nla_get_u8(twt_rsp[QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION]);
9243 if (val != wait->twt_op) {
9244 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9245 "Invalid TWT operation, expected %d, rcvd %d",
9246 wait->twt_op, val);
9247 return NL_SKIP;
9248 }
9249 if (nla_parse_nested(twt_status, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_MAX,
9250 twt_rsp[QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS],
9251 NULL)) {
9252 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9253 "nla_parse failed for TWT event");
9254 return NL_SKIP;
9255 }
9256
9257 cmd_id = QCA_WLAN_VENDOR_ATTR_TWT_SETUP_STATUS;
9258 if (!twt_status[cmd_id]) {
9259 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9260 "%s TWT resp status missing", __func__);
9261 wait->cmd = -1;
9262 } else {
9263 val = nla_get_u8(twt_status[cmd_id]);
9264 if (val != QCA_WLAN_VENDOR_TWT_STATUS_OK) {
9265 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9266 "%s TWT resp status %d", __func__, val);
9267 wait->cmd = -1;
9268 } else {
9269 wait->cmd = 1;
9270 }
9271 }
9272
9273 return NL_SKIP;
9274}
9275
9276
9277static int wait_on_nl_socket(struct nl_sock *sock, struct sigma_dut *dut,
9278 unsigned int timeout)
9279{
9280 fd_set read_fd_set;
9281 int retval;
9282 int sock_fd;
9283 struct timeval time_out;
9284
9285 time_out.tv_sec = timeout;
9286 time_out.tv_usec = 0;
9287
9288 FD_ZERO(&read_fd_set);
9289
9290 if (!sock)
9291 return -1;
9292
9293 sock_fd = nl_socket_get_fd(sock);
9294 FD_SET(sock_fd, &read_fd_set);
9295
9296 retval = select(sock_fd + 1, &read_fd_set, NULL, NULL, &time_out);
9297
9298 if (retval == 0)
9299 sigma_dut_print(dut, DUT_MSG_ERROR,
9300 "%s: TWT event response timedout", __func__);
9301
9302 if (retval < 0)
9303 sigma_dut_print(dut, DUT_MSG_ERROR, "%s:no NL msgs, ret=%d",
9304 __func__, retval);
9305
9306 return retval;
9307}
9308
9309
9310#define TWT_ASYNC_EVENT_WAIT_TIME_SEC 6
9311
9312static int twt_async_event_wait(struct sigma_dut *dut, unsigned int twt_op)
9313{
9314 struct nl_cb *cb;
9315 int err_code = 0, select_retval = 0;
9316 struct wait_event wait_info;
9317
9318 cb = nl_socket_get_cb(dut->nl_ctx->event_sock);
9319 if (!cb) {
9320 sigma_dut_print(dut, DUT_MSG_ERROR,
9321 "event callback not found");
9322 return ERROR_SEND_STATUS;
9323 }
9324
9325 wait_info.cmd = 0;
9326 wait_info.dut = dut;
9327 wait_info.twt_op = twt_op;
9328
9329 nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, twt_event_handler, &wait_info);
9330
9331 while (!wait_info.cmd) {
9332 select_retval = wait_on_nl_socket(
9333 dut->nl_ctx->event_sock, dut,
9334 TWT_ASYNC_EVENT_WAIT_TIME_SEC);
9335
9336 if (select_retval > 0) {
9337 err_code = nl_recvmsgs(dut->nl_ctx->event_sock, cb);
9338 if (err_code < 0) {
9339 sigma_dut_print(dut, DUT_MSG_ERROR,
9340 "%s: nl rcv failed, err_code %d",
9341 __func__, err_code);
9342 break;
9343 }
9344 } else {
9345 sigma_dut_print(dut, DUT_MSG_ERROR,
9346 "%s: wait on socket failed %d",
9347 __func__, select_retval);
9348 err_code = 1;
9349 break;
9350 }
9351
9352 }
9353 nl_cb_put(cb);
9354
9355 if (wait_info.cmd < 0)
9356 err_code = 1;
9357
9358 sigma_dut_print(dut, DUT_MSG_DEBUG,
9359 "%s: rcvd cmd %d, err_code %d, s_ret %d",
9360 __func__, wait_info.cmd, err_code, select_retval);
9361
9362 return err_code;
9363}
9364
9365#endif /* NL80211_SUPPORT */
9366
9367
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009368static int sta_twt_send_suspend(struct sigma_dut *dut, struct sigma_conn *conn,
9369 struct sigma_cmd *cmd)
9370{
9371#ifdef NL80211_SUPPORT
9372 struct nlattr *attr, *attr1;
9373 struct nl_msg *msg;
9374 int ifindex, ret;
9375 const char *intf = get_param(cmd, "Interface");
9376
9377 ifindex = if_nametoindex(intf);
9378 if (ifindex == 0) {
9379 sigma_dut_print(dut, DUT_MSG_ERROR,
9380 "%s: Index for interface %s failed",
9381 __func__, intf);
9382 return ERROR_SEND_STATUS;
9383 }
9384
9385 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9386 NL80211_CMD_VENDOR)) ||
9387 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9388 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9389 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9390 QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) ||
9391 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9392 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION,
9393 QCA_WLAN_TWT_SUSPEND) ||
9394 !(attr1 = nla_nest_start(msg,
Kiran Kumar Lokere7ede00c2021-08-09 00:59:52 -07009395 QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS))) {
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009396 sigma_dut_print(dut, DUT_MSG_ERROR,
9397 "%s: err in adding vendor_cmd and vendor_data",
9398 __func__);
9399 nlmsg_free(msg);
9400 return ERROR_SEND_STATUS;
9401 }
9402 nla_nest_end(msg, attr1);
9403 nla_nest_end(msg, attr);
9404
9405 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9406 if (ret) {
9407 sigma_dut_print(dut, DUT_MSG_ERROR,
9408 "%s: err in send_and_recv_msgs, ret=%d",
9409 __func__, ret);
9410 }
9411
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07009412 if (!dut->sta_async_twt_supp)
9413 return ret;
9414
9415 return twt_async_event_wait(dut, QCA_WLAN_TWT_SUSPEND);
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009416#else /* NL80211_SUPPORT */
9417 sigma_dut_print(dut, DUT_MSG_ERROR,
9418 "TWT suspend cannot be done without NL80211_SUPPORT defined");
9419 return ERROR_SEND_STATUS;
9420#endif /* NL80211_SUPPORT */
9421}
9422
9423
9424static int sta_twt_send_nudge(struct sigma_dut *dut, struct sigma_conn *conn,
9425 struct sigma_cmd *cmd,
9426 unsigned int suspend_duration)
9427{
9428#ifdef NL80211_SUPPORT
9429 struct nlattr *attr, *attr1;
9430 struct nl_msg *msg;
9431 int ifindex, ret;
9432 const char *intf = get_param(cmd, "Interface");
9433 int next_twt_size = 1;
9434
9435 ifindex = if_nametoindex(intf);
9436 if (ifindex == 0) {
9437 sigma_dut_print(dut, DUT_MSG_ERROR,
9438 "%s: Index for interface %s failed",
9439 __func__, intf);
9440 return ERROR_SEND_STATUS;
9441 }
9442
9443 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9444 NL80211_CMD_VENDOR)) ||
9445 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9446 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9447 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9448 QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) ||
9449 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9450 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION,
9451 QCA_WLAN_TWT_NUDGE) ||
9452 !(attr1 = nla_nest_start(msg,
9453 QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS)) ||
9454 (suspend_duration &&
9455 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_NUDGE_WAKE_TIME,
9456 suspend_duration)) ||
9457 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_NUDGE_NEXT_TWT_SIZE,
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -07009458 next_twt_size) ||
9459 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_NUDGE_FLOW_ID, 0)) {
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009460 sigma_dut_print(dut, DUT_MSG_ERROR,
9461 "%s: err in adding vendor_cmd and vendor_data",
9462 __func__);
9463 nlmsg_free(msg);
9464 return ERROR_SEND_STATUS;
9465 }
9466 nla_nest_end(msg, attr1);
9467 nla_nest_end(msg, attr);
9468
9469 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9470 if (ret) {
9471 sigma_dut_print(dut, DUT_MSG_ERROR,
9472 "%s: err in send_and_recv_msgs, ret=%d",
9473 __func__, ret);
9474 }
9475
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07009476 if (!dut->sta_async_twt_supp)
9477 return ret;
9478
9479 return twt_async_event_wait(dut, QCA_WLAN_TWT_NUDGE);
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009480#else /* NL80211_SUPPORT */
9481 sigma_dut_print(dut, DUT_MSG_ERROR,
9482 "TWT suspend cannot be done without NL80211_SUPPORT defined");
9483 return ERROR_SEND_STATUS;
9484#endif /* NL80211_SUPPORT */
9485}
9486
9487
9488static int sta_twt_suspend_or_nudge(struct sigma_dut *dut,
9489 struct sigma_conn *conn,
9490 struct sigma_cmd *cmd)
9491{
9492 const char *val;
9493
9494 val = get_param(cmd, "TWT_SuspendDuration");
9495 if (val) {
9496 unsigned int suspend_duration;
9497
9498 suspend_duration = atoi(val);
9499 suspend_duration = suspend_duration * 1000 * 1000;
9500 return sta_twt_send_nudge(dut, conn, cmd, suspend_duration);
9501 }
9502
9503 return sta_twt_send_suspend(dut, conn, cmd);
9504}
9505
9506
9507static int sta_twt_resume(struct sigma_dut *dut, struct sigma_conn *conn,
9508 struct sigma_cmd *cmd)
9509{
9510#ifdef NL80211_SUPPORT
9511 struct nlattr *attr, *attr1;
9512 struct nl_msg *msg;
9513 int ifindex, ret;
9514 const char *intf = get_param(cmd, "Interface");
9515 int next2_twt_size = 1;
9516 unsigned int resume_duration = 0;
9517 const char *val;
9518
9519 ifindex = if_nametoindex(intf);
9520 if (ifindex == 0) {
9521 sigma_dut_print(dut, DUT_MSG_ERROR,
9522 "%s: Index for interface %s failed",
9523 __func__, intf);
9524 return ERROR_SEND_STATUS;
9525 }
9526
9527 val = get_param(cmd, "TWT_ResumeDuration");
9528 if (val) {
9529 resume_duration = atoi(val);
9530 resume_duration = resume_duration * 1000 * 1000;
9531 }
9532
9533 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9534 NL80211_CMD_VENDOR)) ||
9535 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9536 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9537 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9538 QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) ||
9539 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9540 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION,
9541 QCA_WLAN_TWT_RESUME) ||
9542 !(attr1 = nla_nest_start(msg,
9543 QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS)) ||
9544 (resume_duration &&
9545 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_RESUME_NEXT2_TWT,
9546 resume_duration)) ||
9547 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_RESUME_NEXT_TWT_SIZE,
9548 next2_twt_size)) {
9549 sigma_dut_print(dut, DUT_MSG_ERROR,
9550 "%s: err in adding vendor_cmd and vendor_data",
9551 __func__);
9552 nlmsg_free(msg);
9553 return ERROR_SEND_STATUS;
9554 }
9555 nla_nest_end(msg, attr1);
9556 nla_nest_end(msg, attr);
9557
9558 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9559 if (ret) {
9560 sigma_dut_print(dut, DUT_MSG_ERROR,
9561 "%s: err in send_and_recv_msgs, ret=%d",
9562 __func__, ret);
9563 }
9564
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07009565 if (!dut->sta_async_twt_supp)
9566 return ret;
9567
9568 return twt_async_event_wait(dut, QCA_WLAN_TWT_RESUME);
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009569#else /* NL80211_SUPPORT */
9570 sigma_dut_print(dut, DUT_MSG_ERROR,
9571 "TWT resume cannot be done without NL80211_SUPPORT defined");
9572 return ERROR_SEND_STATUS;
9573#endif /* NL80211_SUPPORT */
9574}
9575
9576
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07009577#define TWT_REQUEST_CMD 0
9578#define TWT_SUGGEST_CMD 1
9579#define TWT_DEMAND_CMD 2
9580
Arif Hussain480d5f42019-03-12 14:40:42 -07009581static int sta_twt_request(struct sigma_dut *dut, struct sigma_conn *conn,
9582 struct sigma_cmd *cmd)
9583{
9584#ifdef NL80211_SUPPORT
9585 struct nlattr *params;
9586 struct nlattr *attr;
Arif Hussain480d5f42019-03-12 14:40:42 -07009587 struct nl_msg *msg;
9588 int ifindex, ret;
9589 const char *val;
9590 const char *intf = get_param(cmd, "Interface");
9591 int wake_interval_exp = 10, nominal_min_wake_dur = 255,
9592 wake_interval_mantissa = 512;
9593 int flow_type = 0, twt_trigger = 0, target_wake_time = 0,
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07009594 protection = 0, cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_SUGGEST;
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -07009595 int bcast_twt = 0;
9596 int bcast_twt_id = 0, bcast_twt_recommdn = 0, bcast_twt_persis = 0;
Arif Hussain480d5f42019-03-12 14:40:42 -07009597
9598 ifindex = if_nametoindex(intf);
9599 if (ifindex == 0) {
9600 sigma_dut_print(dut, DUT_MSG_ERROR,
9601 "%s: Index for interface %s failed",
9602 __func__, intf);
9603 return -1;
9604 }
9605
9606 val = get_param(cmd, "FlowType");
9607 if (val) {
9608 flow_type = atoi(val);
9609 if (flow_type != 0 && flow_type != 1) {
9610 sigma_dut_print(dut, DUT_MSG_ERROR,
9611 "TWT: Invalid FlowType %d", flow_type);
9612 return -1;
9613 }
9614 }
9615
9616 val = get_param(cmd, "TWT_Trigger");
9617 if (val) {
9618 twt_trigger = atoi(val);
9619 if (twt_trigger != 0 && twt_trigger != 1) {
9620 sigma_dut_print(dut, DUT_MSG_ERROR,
9621 "TWT: Invalid TWT_Trigger %d",
9622 twt_trigger);
9623 return -1;
9624 }
9625 }
9626
9627 val = get_param(cmd, "Protection");
9628 if (val) {
9629 protection = atoi(val);
9630 if (protection != 0 && protection != 1) {
9631 sigma_dut_print(dut, DUT_MSG_ERROR,
9632 "TWT: Invalid Protection %d",
9633 protection);
9634 return -1;
9635 }
9636 }
9637
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07009638 val = get_param(cmd, "SetupCommand");
9639 if (val) {
9640 cmd_type = atoi(val);
9641 if (cmd_type == TWT_REQUEST_CMD)
9642 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_REQUEST;
9643 else if (cmd_type == TWT_SUGGEST_CMD)
9644 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_SUGGEST;
9645 else if (cmd_type == TWT_DEMAND_CMD)
9646 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_DEMAND;
9647 else
9648 sigma_dut_print(dut, DUT_MSG_ERROR,
9649 "Default suggest is used for cmd %d",
9650 cmd_type);
9651 }
9652
Arif Hussain480d5f42019-03-12 14:40:42 -07009653 val = get_param(cmd, "TargetWakeTime");
9654 if (val)
9655 target_wake_time = atoi(val);
9656
9657 val = get_param(cmd, "WakeIntervalMantissa");
9658 if (val)
9659 wake_interval_mantissa = atoi(val);
9660
9661 val = get_param(cmd, "WakeIntervalExp");
9662 if (val)
9663 wake_interval_exp = atoi(val);
9664
9665 val = get_param(cmd, "NominalMinWakeDur");
9666 if (val)
9667 nominal_min_wake_dur = atoi(val);
9668
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -07009669 val = get_param(cmd, "BTWT_ID");
9670 if (val) {
9671 bcast_twt_id = atoi(val);
9672 bcast_twt = 1;
9673 }
9674
9675 val = get_param(cmd, "BTWT_Persistence");
9676 if (val) {
9677 bcast_twt_persis = atoi(val);
9678 bcast_twt = 1;
9679 }
9680
9681 val = get_param(cmd, "BTWT_Recommendation");
9682 if (val) {
9683 bcast_twt_recommdn = atoi(val);
9684 bcast_twt = 1;
9685 }
9686
9687 if (bcast_twt)
9688 sigma_dut_print(dut, DUT_MSG_DEBUG,
9689 "BCAST_TWT: ID %d, RECOMM %d, PERSIS %d",
9690 bcast_twt_id, bcast_twt_recommdn,
9691 bcast_twt_persis);
9692
Arif Hussain480d5f42019-03-12 14:40:42 -07009693 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9694 NL80211_CMD_VENDOR)) ||
9695 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9696 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9697 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009698 QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07009699 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009700 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION,
9701 QCA_WLAN_TWT_SET) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07009702 !(params = nla_nest_start(
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009703 msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07009704 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_EXP,
9705 wake_interval_exp) ||
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07009706 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_REQ_TYPE, cmd_type) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -07009707 (twt_trigger &&
9708 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_TRIGGER)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07009709 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE,
9710 flow_type) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -07009711 (protection &&
9712 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_PROTECTION)) ||
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -07009713 (bcast_twt &&
9714 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_BCAST)) ||
9715 (bcast_twt &&
9716 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_BCAST_ID,
9717 bcast_twt_id)) ||
9718 (bcast_twt &&
9719 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_BCAST_PERSISTENCE,
9720 bcast_twt_persis)) ||
9721 (bcast_twt &&
9722 nla_put_u8(msg,
9723 QCA_WLAN_VENDOR_ATTR_TWT_SETUP_BCAST_RECOMMENDATION,
9724 bcast_twt_recommdn)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07009725 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_TIME,
9726 target_wake_time) ||
9727 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_DURATION,
9728 nominal_min_wake_dur) ||
9729 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_MANTISSA,
9730 wake_interval_mantissa)) {
9731 sigma_dut_print(dut, DUT_MSG_ERROR,
9732 "%s: err in adding vendor_cmd and vendor_data",
9733 __func__);
9734 nlmsg_free(msg);
9735 return -1;
9736 }
Arif Hussain480d5f42019-03-12 14:40:42 -07009737 nla_nest_end(msg, params);
9738 nla_nest_end(msg, attr);
9739
9740 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9741 if (ret) {
9742 sigma_dut_print(dut, DUT_MSG_ERROR,
9743 "%s: err in send_and_recv_msgs, ret=%d",
9744 __func__, ret);
9745 }
9746
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07009747 if (!dut->sta_async_twt_supp)
9748 return ret;
9749
9750 return twt_async_event_wait(dut, QCA_WLAN_TWT_SET);
Arif Hussain480d5f42019-03-12 14:40:42 -07009751#else /* NL80211_SUPPORT */
9752 sigma_dut_print(dut, DUT_MSG_ERROR,
9753 "TWT request cannot be done without NL80211_SUPPORT defined");
9754 return -1;
9755#endif /* NL80211_SUPPORT */
9756}
9757
9758
9759static int sta_twt_teardown(struct sigma_dut *dut, struct sigma_conn *conn,
9760 struct sigma_cmd *cmd)
9761{
9762 #ifdef NL80211_SUPPORT
9763 struct nlattr *params;
9764 struct nlattr *attr;
Arif Hussain480d5f42019-03-12 14:40:42 -07009765 int ifindex, ret;
9766 struct nl_msg *msg;
9767 const char *intf = get_param(cmd, "Interface");
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -07009768 int bcast_twt = 0;
9769 int bcast_twt_id = 0;
9770 const char *val;
Arif Hussain480d5f42019-03-12 14:40:42 -07009771
9772 ifindex = if_nametoindex(intf);
9773 if (ifindex == 0) {
9774 sigma_dut_print(dut, DUT_MSG_ERROR,
9775 "%s: Index for interface %s failed",
9776 __func__, intf);
9777 return -1;
9778 }
9779
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -07009780 val = get_param(cmd, "BTWT_ID");
9781 if (val) {
9782 bcast_twt_id = atoi(val);
9783 bcast_twt = 1;
9784 }
9785
Arif Hussain480d5f42019-03-12 14:40:42 -07009786 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9787 NL80211_CMD_VENDOR)) ||
9788 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9789 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9790 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009791 QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07009792 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009793 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION,
9794 QCA_WLAN_TWT_TERMINATE) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07009795 !(params = nla_nest_start(
9796 msg,
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009797 QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS)) ||
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -07009798 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE, 0) ||
9799 (bcast_twt &&
9800 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_BCAST)) ||
9801 (bcast_twt &&
9802 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_BCAST_ID,
9803 bcast_twt_id))) {
Arif Hussain480d5f42019-03-12 14:40:42 -07009804 sigma_dut_print(dut, DUT_MSG_ERROR,
9805 "%s: err in adding vendor_cmd and vendor_data",
9806 __func__);
9807 nlmsg_free(msg);
9808 return -1;
9809 }
Arif Hussain480d5f42019-03-12 14:40:42 -07009810 nla_nest_end(msg, params);
9811 nla_nest_end(msg, attr);
9812
9813 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9814 if (ret) {
9815 sigma_dut_print(dut, DUT_MSG_ERROR,
9816 "%s: err in send_and_recv_msgs, ret=%d",
9817 __func__, ret);
9818 }
9819
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07009820 if (!dut->sta_async_twt_supp)
9821 return ret;
9822
9823 return twt_async_event_wait(dut, QCA_WLAN_TWT_TERMINATE);
Arif Hussain480d5f42019-03-12 14:40:42 -07009824#else /* NL80211_SUPPORT */
9825 sigma_dut_print(dut, DUT_MSG_ERROR,
9826 "TWT teardown cannot be done without NL80211_SUPPORT defined");
9827 return -1;
9828#endif /* NL80211_SUPPORT */
9829}
9830
9831
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -08009832static int sta_transmit_omi(struct sigma_dut *dut, struct sigma_conn *conn,
9833 struct sigma_cmd *cmd)
9834{
9835#ifdef NL80211_SUPPORT
9836 struct nlattr *params;
9837 struct nlattr *attr;
9838 struct nlattr *attr1;
9839 struct nl_msg *msg;
9840 int ifindex, ret;
9841 const char *val;
9842 const char *intf = get_param(cmd, "Interface");
9843 uint8_t rx_nss = 0xFF, ch_bw = 0xFF, tx_nsts = 0xFF, ulmu_dis = 0,
9844 ulmu_data_dis = 0;
9845
9846 ifindex = if_nametoindex(intf);
9847 if (ifindex == 0) {
9848 sigma_dut_print(dut, DUT_MSG_ERROR,
9849 "%s: Index for interface %s failed",
9850 __func__, intf);
9851 return -1;
9852 }
9853 val = get_param(cmd, "OMCtrl_RxNSS");
9854 if (val)
9855 rx_nss = atoi(val);
9856
9857 val = get_param(cmd, "OMCtrl_ChnlWidth");
9858 if (val)
9859 ch_bw = atoi(val);
9860
9861 val = get_param(cmd, "OMCtrl_ULMUDisable");
9862 if (val)
9863 ulmu_dis = atoi(val);
9864
9865 val = get_param(cmd, "OMCtrl_TxNSTS");
9866 if (val)
9867 tx_nsts = atoi(val);
9868
9869 val = get_param(cmd, "OMCtrl_ULMUDataDisable");
9870 if (val)
9871 ulmu_data_dis = atoi(val);
9872
9873 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9874 NL80211_CMD_VENDOR)) ||
9875 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9876 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9877 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9878 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
9879 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9880 !(params = nla_nest_start(
9881 msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OMI_TX)) ||
9882 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9883 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_RX_NSS, rx_nss) ||
9884 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_CH_BW, ch_bw) ||
9885 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_TX_NSTS, tx_nsts) ||
9886 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DATA_DISABLE,
9887 ulmu_data_dis) ||
9888 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DISABLE,
9889 ulmu_dis)) {
9890 sigma_dut_print(dut, DUT_MSG_ERROR,
9891 "%s: err in adding vendor_cmd and vendor_data",
9892 __func__);
9893 nlmsg_free(msg);
9894 return -1;
9895 }
9896 nla_nest_end(msg, attr1);
9897 nla_nest_end(msg, params);
9898 nla_nest_end(msg, attr);
9899
9900 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9901 if (ret) {
9902 sigma_dut_print(dut, DUT_MSG_ERROR,
9903 "%s: err in send_and_recv_msgs, ret=%d",
9904 __func__, ret);
9905 }
9906
9907 return ret;
9908#else /* NL80211_SUPPORT */
9909 sigma_dut_print(dut, DUT_MSG_ERROR,
9910 "OMI TX cannot be processed without NL80211_SUPPORT defined");
9911 return -1;
9912#endif /* NL80211_SUPPORT */
9913}
9914
9915
Jouni Malinen224e3902021-06-09 16:41:27 +03009916static enum sigma_cmd_result
9917cmd_sta_set_wireless_vht(struct sigma_dut *dut, struct sigma_conn *conn,
9918 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009919{
9920 const char *intf = get_param(cmd, "Interface");
9921 const char *val;
Arif Hussaina37e9552018-06-20 17:05:59 -07009922 const char *program;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009923 int tkip = -1;
9924 int wep = -1;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05309925 int iwpriv_status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009926
Arif Hussaina37e9552018-06-20 17:05:59 -07009927 program = get_param(cmd, "Program");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009928 val = get_param(cmd, "SGI80");
9929 if (val) {
9930 int sgi80;
9931
9932 sgi80 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009933 run_iwpriv(dut, intf, "shortgi %d", sgi80);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009934 }
9935
9936 val = get_param(cmd, "TxBF");
9937 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009938 switch (get_driver_type(dut)) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009939 case DRIVER_WCN:
9940 if (sta_set_tx_beamformee(dut, intf, 1)) {
9941 send_resp(dut, conn, SIGMA_ERROR,
9942 "ErrorCode,Failed to set TX beamformee enable");
Jouni Malinen224e3902021-06-09 16:41:27 +03009943 return STATUS_SENT_ERROR;
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009944 }
9945 break;
9946 case DRIVER_ATHEROS:
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009947 if (run_iwpriv(dut, intf, "vhtsubfee 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009948 send_resp(dut, conn, SIGMA_ERROR,
9949 "ErrorCode,Setting vhtsubfee failed");
Jouni Malinen224e3902021-06-09 16:41:27 +03009950 return STATUS_SENT_ERROR;
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009951 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009952 if (run_iwpriv(dut, intf, "vhtsubfer 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009953 send_resp(dut, conn, SIGMA_ERROR,
9954 "ErrorCode,Setting vhtsubfer failed");
Jouni Malinen224e3902021-06-09 16:41:27 +03009955 return STATUS_SENT_ERROR;
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009956 }
9957 break;
9958 default:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009959 sigma_dut_print(dut, DUT_MSG_ERROR,
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009960 "Unsupported driver type");
9961 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009962 }
9963 }
9964
9965 val = get_param(cmd, "MU_TxBF");
9966 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009967 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009968 case DRIVER_ATHEROS:
9969 ath_sta_set_txsp_stream(dut, intf, "1SS");
9970 ath_sta_set_rxsp_stream(dut, intf, "1SS");
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009971 run_iwpriv(dut, intf, "vhtmubfee 1");
9972 run_iwpriv(dut, intf, "vhtmubfer 1");
Sunil Duttae9e5d12018-06-29 11:50:47 +05309973 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009974 case DRIVER_WCN:
9975 if (wcn_sta_set_sp_stream(dut, intf, "1SS") < 0) {
9976 send_resp(dut, conn, SIGMA_ERROR,
9977 "ErrorCode,Failed to set RX/TXSP_STREAM");
Jouni Malinen224e3902021-06-09 16:41:27 +03009978 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009979 }
Sunil Duttae9e5d12018-06-29 11:50:47 +05309980 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009981 default:
9982 sigma_dut_print(dut, DUT_MSG_ERROR,
9983 "Setting SP_STREAM not supported");
9984 break;
9985 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009986 }
9987
9988 val = get_param(cmd, "LDPC");
9989 if (val) {
9990 int ldpc;
9991
9992 ldpc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05309993 iwpriv_status = run_iwpriv(dut, intf, "ldpc %d", ldpc);
9994 if (iwpriv_status)
9995 sta_config_params(dut, intf, STA_SET_LDPC, ldpc);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009996 }
9997
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08009998 val = get_param(cmd, "BCC");
9999 if (val) {
10000 int bcc;
10001
10002 bcc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
10003 /* use LDPC iwpriv itself to set bcc coding, bcc coding
10004 * is mutually exclusive to bcc */
Mohammad Asaad Akram50848402020-05-28 14:10:24 +053010005 iwpriv_status = run_iwpriv(dut, intf, "ldpc %d", !bcc);
10006 if (iwpriv_status)
10007 sta_config_params(dut, intf, STA_SET_LDPC, !bcc);
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -080010008 }
10009
Arif Hussain7b47d2d2018-05-09 10:44:02 -070010010 val = get_param(cmd, "MaxHE-MCS_1SS_RxMapLTE80");
10011 if (val && dut->sta_nss == 1)
10012 cmd_set_max_he_mcs(dut, intf, atoi(val));
10013
10014 val = get_param(cmd, "MaxHE-MCS_2SS_RxMapLTE80");
10015 if (val && dut->sta_nss == 2)
10016 cmd_set_max_he_mcs(dut, intf, atoi(val));
10017
Arif Hussainac6c5112018-05-25 17:34:00 -070010018 val = get_param(cmd, "MCS_FixedRate");
10019 if (val) {
10020#ifdef NL80211_SUPPORT
10021 int mcs, ratecode = 0;
10022 enum he_mcs_config mcs_config;
10023 int ret;
Jouni Malinenb9b671d2019-04-26 13:23:17 +030010024 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -070010025
10026 ratecode = (0x07 & dut->sta_nss) << 5;
10027 mcs = atoi(val);
10028 /* Add the MCS to the ratecode */
10029 if (mcs >= 0 && mcs <= 11) {
10030 ratecode += mcs;
10031 if (dut->device_type == STA_testbed &&
10032 mcs > 7 && mcs <= 11) {
10033 if (mcs <= 9)
10034 mcs_config = HE_80_MCS0_9;
10035 else
10036 mcs_config = HE_80_MCS0_11;
10037 ret = sta_set_he_mcs(dut, intf, mcs_config);
10038 if (ret) {
10039 sigma_dut_print(dut, DUT_MSG_ERROR,
10040 "MCS_FixedRate: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
10041 mcs, mcs_config, ret);
10042 }
10043 }
10044 snprintf(buf, sizeof(buf),
10045 "iwpriv %s set_11ax_rate 0x%03x",
10046 intf, ratecode);
10047 if (system(buf) != 0) {
10048 sigma_dut_print(dut, DUT_MSG_ERROR,
10049 "MCS_FixedRate: iwpriv setting of 11ax rates 0x%03x failed",
10050 ratecode);
10051 }
10052 } else {
10053 sigma_dut_print(dut, DUT_MSG_ERROR,
10054 "MCS_FixedRate: HE MCS %d not supported",
10055 mcs);
10056 }
10057#else /* NL80211_SUPPORT */
10058 sigma_dut_print(dut, DUT_MSG_ERROR,
10059 "MCS_FixedRate cannot be changed without NL80211_SUPPORT defined");
10060#endif /* NL80211_SUPPORT */
10061 }
10062
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010063 val = get_param(cmd, "opt_md_notif_ie");
10064 if (val) {
10065 char *result = NULL;
10066 char delim[] = ";";
10067 char token[30];
10068 int value, config_val = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010069 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010070
Peng Xub8fc5cc2017-05-10 17:27:28 -070010071 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010072 result = strtok_r(token, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010073
10074 /* Extract the NSS information */
10075 if (result) {
10076 value = atoi(result);
10077 switch (value) {
10078 case 1:
10079 config_val = 1;
10080 break;
10081 case 2:
10082 config_val = 3;
10083 break;
10084 case 3:
10085 config_val = 7;
10086 break;
10087 case 4:
10088 config_val = 15;
10089 break;
10090 default:
10091 config_val = 3;
10092 break;
10093 }
10094
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010095 run_iwpriv(dut, intf, "rxchainmask %d", config_val);
10096 run_iwpriv(dut, intf, "txchainmask %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010097
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010098 }
10099
10100 /* Extract the channel width information */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010101 result = strtok_r(NULL, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010102 if (result) {
10103 value = atoi(result);
10104 switch (value) {
10105 case 20:
10106 config_val = 0;
10107 break;
10108 case 40:
10109 config_val = 1;
10110 break;
10111 case 80:
10112 config_val = 2;
10113 break;
10114 case 160:
10115 config_val = 3;
10116 break;
10117 default:
10118 config_val = 2;
10119 break;
10120 }
10121
10122 dut->chwidth = config_val;
10123
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010124 run_iwpriv(dut, intf, "chwidth %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010125 }
10126
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010127 run_iwpriv(dut, intf, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010128 }
10129
10130 val = get_param(cmd, "nss_mcs_cap");
10131 if (val) {
10132 int nss, mcs;
10133 char token[20];
10134 char *result = NULL;
10135 unsigned int vht_mcsmap = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010136 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010137
Peng Xub8fc5cc2017-05-10 17:27:28 -070010138 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010139 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +053010140 if (!result) {
10141 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -070010142 "NSS not specified");
10143 send_resp(dut, conn, SIGMA_ERROR,
10144 "errorCode,NSS not specified");
Jouni Malinen224e3902021-06-09 16:41:27 +030010145 return STATUS_SENT_ERROR;
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +053010146 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010147 nss = atoi(result);
10148
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010149 run_iwpriv(dut, intf, "nss %d", nss);
Arif Hussainac6c5112018-05-25 17:34:00 -070010150 dut->sta_nss = nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010151
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010152 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010153 if (result == NULL) {
10154 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -070010155 "MCS not specified");
10156 send_resp(dut, conn, SIGMA_ERROR,
10157 "errorCode,MCS not specified");
Jouni Malinen224e3902021-06-09 16:41:27 +030010158 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010159 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010160 result = strtok_r(result, "-", &saveptr);
10161 result = strtok_r(NULL, "-", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +053010162 if (!result) {
10163 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -070010164 "MCS not specified");
10165 send_resp(dut, conn, SIGMA_ERROR,
10166 "errorCode,MCS not specified");
Jouni Malinen224e3902021-06-09 16:41:27 +030010167 return STATUS_SENT_ERROR;
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +053010168 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010169 mcs = atoi(result);
10170
Arif Hussaina37e9552018-06-20 17:05:59 -070010171 if (program && strcasecmp(program, "HE") == 0) {
10172#ifdef NL80211_SUPPORT
10173 enum he_mcs_config mcs_config;
10174 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010175
Arif Hussaina37e9552018-06-20 17:05:59 -070010176 if (mcs >= 0 && mcs <= 7) {
10177 mcs_config = HE_80_MCS0_7;
10178 } else if (mcs > 7 && mcs <= 9) {
10179 mcs_config = HE_80_MCS0_9;
10180 } else if (mcs > 9 && mcs <= 11) {
10181 mcs_config = HE_80_MCS0_11;
10182 } else {
10183 sigma_dut_print(dut, DUT_MSG_ERROR,
10184 "nss_mcs_cap: HE: Invalid mcs: %d",
10185 mcs);
10186 send_resp(dut, conn, SIGMA_ERROR,
10187 "errorCode,Invalid MCS");
Jouni Malinen224e3902021-06-09 16:41:27 +030010188 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010189 }
Arif Hussaina37e9552018-06-20 17:05:59 -070010190
10191 ret = sta_set_he_mcs(dut, intf, mcs_config);
10192 if (ret) {
10193 sigma_dut_print(dut, DUT_MSG_ERROR,
10194 "nss_mcs_cap: HE: Setting of MCS failed, mcs_config: %d, ret: %d",
10195 mcs_config, ret);
10196 send_resp(dut, conn, SIGMA_ERROR,
10197 "errorCode,Failed to set MCS");
Jouni Malinen224e3902021-06-09 16:41:27 +030010198 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010199 }
Arif Hussaina37e9552018-06-20 17:05:59 -070010200#else /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010201 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -070010202 "nss_mcs_cap: HE: MCS cannot be changed without NL80211_SUPPORT defined");
10203#endif /* NL80211_SUPPORT */
10204 } else {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010205 run_iwpriv(dut, intf, "vhtmcs %d", mcs);
Arif Hussaina37e9552018-06-20 17:05:59 -070010206
10207 switch (nss) {
10208 case 1:
10209 switch (mcs) {
10210 case 7:
10211 vht_mcsmap = 0xfffc;
10212 break;
10213 case 8:
10214 vht_mcsmap = 0xfffd;
10215 break;
10216 case 9:
10217 vht_mcsmap = 0xfffe;
10218 break;
10219 default:
10220 vht_mcsmap = 0xfffe;
10221 break;
10222 }
10223 break;
10224 case 2:
10225 switch (mcs) {
10226 case 7:
10227 vht_mcsmap = 0xfff0;
10228 break;
10229 case 8:
10230 vht_mcsmap = 0xfff5;
10231 break;
10232 case 9:
10233 vht_mcsmap = 0xfffa;
10234 break;
10235 default:
10236 vht_mcsmap = 0xfffa;
10237 break;
10238 }
10239 break;
10240 case 3:
10241 switch (mcs) {
10242 case 7:
10243 vht_mcsmap = 0xffc0;
10244 break;
10245 case 8:
10246 vht_mcsmap = 0xffd5;
10247 break;
10248 case 9:
10249 vht_mcsmap = 0xffea;
10250 break;
10251 default:
10252 vht_mcsmap = 0xffea;
10253 break;
10254 }
10255 break;
10256 default:
10257 vht_mcsmap = 0xffea;
10258 break;
10259 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010260 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010261 }
10262 }
10263
10264 /* UNSUPPORTED: val = get_param(cmd, "Tx_lgi_rate"); */
10265
10266 val = get_param(cmd, "Vht_tkip");
10267 if (val)
10268 tkip = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
10269
10270 val = get_param(cmd, "Vht_wep");
10271 if (val)
10272 wep = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
10273
10274 if (tkip != -1 || wep != -1) {
10275 if ((tkip == 1 && wep != 0) || (wep == 1 && tkip != 0)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010276 run_iwpriv(dut, intf, "htweptkip 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010277 } else if ((tkip == 0 && wep != 1) || (wep == 0 && tkip != 1)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010278 run_iwpriv(dut, intf, "htweptkip 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010279 } else {
Jouni Malinen224e3902021-06-09 16:41:27 +030010280 send_resp(dut, conn, SIGMA_ERROR,
10281 "ErrorCode,mixed mode of VHT TKIP/WEP not supported");
10282 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010283 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010284 }
10285
Kiran Kumar Lokere09dbcef2021-08-09 00:01:41 -070010286 val = get_param(cmd, "TWTSchedSTASupport");
10287 if (val) {
10288 int set_val;
10289
10290 switch (get_driver_type(dut)) {
10291 case DRIVER_WCN:
10292 if (strcasecmp(val, "Enable") == 0) {
10293 set_val = 1;
10294 } else if (strcasecmp(val, "Disable") == 0) {
10295 set_val = 0;
10296 } else {
10297 send_resp(dut, conn, SIGMA_ERROR,
10298 "ErrorCode,Invalid TWTSchedSTASupport");
10299 return STATUS_SENT_ERROR;
10300 }
10301
10302 if (sta_set_bcast_twt_support(dut, intf, set_val)) {
10303 send_resp(dut, conn, SIGMA_ERROR,
10304 "ErrorCode,Failed to set TWTSchedSTASupport");
10305 return STATUS_SENT_ERROR;
10306 }
10307 break;
10308 default:
10309 sigma_dut_print(dut, DUT_MSG_ERROR,
10310 "Setting TWTSchedSTASupport not supported");
10311 break;
10312 }
10313 }
10314
10315 val = get_param(cmd, "MBSSID_RxCtrl");
10316 if (val) {
10317 int set_val;
10318
10319 switch (get_driver_type(dut)) {
10320 case DRIVER_WCN:
10321 if (strcasecmp(val, "Enable") == 0) {
10322 set_val = 1;
10323 } else if (strcasecmp(val, "Disable") == 0) {
10324 set_val = 0;
10325 } else {
10326 send_resp(dut, conn, SIGMA_ERROR,
10327 "ErrorCode,Invalid MBSSID_RxCtrl");
10328 return STATUS_SENT_ERROR;
10329 }
10330
10331 if (sta_set_rx_ctrl_multi_bss(dut, intf, set_val)) {
10332 send_resp(dut, conn, SIGMA_ERROR,
10333 "ErrorCode,Failed to set MBSSID_RxCtrl");
10334 return STATUS_SENT_ERROR;
10335 }
10336 break;
10337 default:
10338 sigma_dut_print(dut, DUT_MSG_ERROR,
10339 "Setting MBSSID_RxCtrl not supported");
10340 break;
10341 }
10342 }
10343
Arif Hussain55f00da2018-07-03 08:28:26 -070010344 val = get_param(cmd, "txBandwidth");
10345 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010346 switch (get_driver_type(dut)) {
Arif Hussain55f00da2018-07-03 08:28:26 -070010347 case DRIVER_WCN:
10348 if (wcn_sta_set_width(dut, intf, val) < 0) {
10349 send_resp(dut, conn, SIGMA_ERROR,
10350 "ErrorCode,Failed to set txBandwidth");
Jouni Malinen224e3902021-06-09 16:41:27 +030010351 return STATUS_SENT_ERROR;
Arif Hussain55f00da2018-07-03 08:28:26 -070010352 }
10353 break;
10354 case DRIVER_ATHEROS:
10355 if (ath_set_width(dut, conn, intf, val) < 0) {
10356 send_resp(dut, conn, SIGMA_ERROR,
10357 "ErrorCode,Failed to set txBandwidth");
Jouni Malinen224e3902021-06-09 16:41:27 +030010358 return STATUS_SENT_ERROR;
Arif Hussain55f00da2018-07-03 08:28:26 -070010359 }
10360 break;
10361 default:
10362 sigma_dut_print(dut, DUT_MSG_ERROR,
10363 "Setting txBandwidth not supported");
10364 break;
10365 }
10366 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010367
Arif Hussain9765f7d2018-07-03 08:28:26 -070010368 val = get_param(cmd, "BeamformeeSTS");
10369 if (val) {
Kiran Kumar Lokerebc89d432018-07-10 12:20:13 -070010370 if (sta_set_tx_beamformee(dut, intf, 1)) {
10371 send_resp(dut, conn, SIGMA_ERROR,
10372 "ErrorCode,Failed to set TX beamformee enable");
Jouni Malinen224e3902021-06-09 16:41:27 +030010373 return STATUS_SENT_ERROR;
Kiran Kumar Lokerebc89d432018-07-10 12:20:13 -070010374 }
10375
Arif Hussain9765f7d2018-07-03 08:28:26 -070010376 if (sta_set_beamformee_sts(dut, intf, atoi(val))) {
10377 send_resp(dut, conn, SIGMA_ERROR,
10378 "ErrorCode,Failed to set BeamformeeSTS");
Jouni Malinen224e3902021-06-09 16:41:27 +030010379 return STATUS_SENT_ERROR;
Arif Hussain9765f7d2018-07-03 08:28:26 -070010380 }
10381 }
10382
Arif Hussain68d23f52018-07-11 13:39:08 -070010383 val = get_param(cmd, "Trig_MAC_Padding_Dur");
10384 if (val) {
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -070010385#ifdef NL80211_SUPPORT
10386 enum qca_wlan_he_mac_padding_dur set_val;
10387
10388 switch (atoi(val)) {
10389 case 16:
10390 set_val = QCA_WLAN_HE_16US_OF_PROCESS_TIME;
10391 break;
10392 case 8:
10393 set_val = QCA_WLAN_HE_8US_OF_PROCESS_TIME;
10394 break;
10395 default:
10396 set_val = QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME;
10397 break;
10398 }
10399 if (sta_set_mac_padding_duration(dut, intf, set_val)) {
Arif Hussain68d23f52018-07-11 13:39:08 -070010400 send_resp(dut, conn, SIGMA_ERROR,
10401 "ErrorCode,Failed to set MAC padding duration");
Jouni Malinen224e3902021-06-09 16:41:27 +030010402 return STATUS_SENT_ERROR;
Arif Hussain68d23f52018-07-11 13:39:08 -070010403 }
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -070010404#else /* NL80211_SUPPORT */
10405 sigma_dut_print(dut, DUT_MSG_ERROR,
10406 "MAC padding duration cannot be changed without NL80211_SUPPORT defined");
10407#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -070010408 }
10409
Arif Hussain480d5f42019-03-12 14:40:42 -070010410 val = get_param(cmd, "TWT_ReqSupport");
10411 if (val) {
10412 int set_val;
10413
10414 if (strcasecmp(val, "Enable") == 0) {
10415 set_val = 1;
10416 } else if (strcasecmp(val, "Disable") == 0) {
10417 set_val = 0;
10418 } else {
10419 send_resp(dut, conn, SIGMA_ERROR,
10420 "ErrorCode,Invalid TWT_ReqSupport");
Jouni Malinen224e3902021-06-09 16:41:27 +030010421 return STATUS_SENT_ERROR;
Arif Hussain480d5f42019-03-12 14:40:42 -070010422 }
10423
10424 if (sta_set_twt_req_support(dut, intf, set_val)) {
10425 sigma_dut_print(dut, DUT_MSG_ERROR,
10426 "Failed to set TWT req support %d",
10427 set_val);
10428 send_resp(dut, conn, SIGMA_ERROR,
10429 "ErrorCode,Failed to set TWT_ReqSupport");
Jouni Malinen224e3902021-06-09 16:41:27 +030010430 return STATUS_SENT_ERROR;
Arif Hussain480d5f42019-03-12 14:40:42 -070010431 }
10432 }
10433
Kiran Kumar Lokered0ec5ed2021-04-01 00:15:04 -070010434 val = get_param(cmd, "PreamblePunctRx");
10435 if (val && get_driver_type(dut) == DRIVER_WCN) {
10436 int set_val;
10437
10438 if (strcasecmp(val, "Enable") == 0) {
10439 set_val = 1;
10440 } else if (strcasecmp(val, "Disable") == 0) {
10441 set_val = 0;
10442 } else {
10443 send_resp(dut, conn, SIGMA_ERROR,
10444 "ErrorCode,Invalid PreamblePunctRx");
10445 return STATUS_SENT_ERROR;
10446 }
10447
10448 if (sta_set_punctured_preamble_rx(dut, intf, set_val)) {
10449 sigma_dut_print(dut, DUT_MSG_ERROR,
10450 "Failed to set PreamblePunctRx support %d",
10451 set_val);
10452 send_resp(dut, conn, SIGMA_ERROR,
10453 "ErrorCode,Failed to set PreamblePunctRx");
10454 return STATUS_SENT_ERROR;
10455 }
10456 }
10457
Srinivas Girigowda0525e292020-11-12 13:28:21 -080010458 val = get_param(cmd, "FullBW_ULMUMIMO");
10459 if (val) {
10460 int set_val;
10461
10462 if (strcasecmp(val, "Enable") == 0) {
10463 set_val = 1;
10464 } else if (strcasecmp(val, "Disable") == 0) {
10465 set_val = 0;
10466 } else {
10467 send_resp(dut, conn, SIGMA_ERROR,
10468 "ErrorCode,Invalid FullBW_ULMUMIMO");
10469 return STATUS_SENT_ERROR;
10470 }
10471
10472 if (sta_set_fullbw_ulmumimo(dut, intf, set_val)) {
10473 sigma_dut_print(dut, DUT_MSG_ERROR,
10474 "Failed to set FullBW_ULMUMIMO %d",
10475 set_val);
10476 send_resp(dut, conn, SIGMA_ERROR,
10477 "ErrorCode,Failed to set FullBW_ULMUMIMO");
10478 return STATUS_SENT_ERROR;
10479 }
10480 }
10481
Srinivas Girigowda6707f032020-10-26 15:24:46 -070010482 val = get_param(cmd, "TWTInfoFrameTx");
10483 if (val) {
10484 if (strcasecmp(val, "Enable") == 0) {
10485 /* No-op */
10486 } else if (strcasecmp(val, "Disable") == 0) {
10487 /* No-op */
10488 } else {
10489 send_resp(dut, conn, SIGMA_ERROR,
10490 "ErrorCode,Invalid TWTInfoFrameTx");
10491 return STATUS_SENT_ERROR;
10492 }
10493 }
10494
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -070010495 val = get_param(cmd, "MU_EDCA");
10496 if (val && (strcasecmp(val, "Override") == 0)) {
10497 if (sta_set_mu_edca_override(dut, intf, 1)) {
10498 send_resp(dut, conn, SIGMA_ERROR,
10499 "ErrorCode,Failed to set MU EDCA override");
Jouni Malinen224e3902021-06-09 16:41:27 +030010500 return STATUS_SENT_ERROR;
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -070010501 }
10502 }
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -070010503
Kiran Kumar Lokerefa7c7b92021-08-09 00:50:55 -070010504 val = get_param(cmd, "PPDUTxType");
10505 if (val && strcasecmp(val, "ER-SU") == 0) {
10506 if (sta_set_er_su_ppdu_type_tx(dut, intf, 1)) {
10507 send_resp(dut, conn, SIGMA_ERROR,
10508 "ErrorCode,Failed to set ER-SU PPDU type Tx");
10509 return STATUS_SENT_ERROR;
10510 }
10511 }
10512
10513 val = get_param(cmd, "RUAllocTone");
10514 if (val && strcasecmp(val, "242") == 0) {
10515 if (sta_set_ru_242_tone_tx(dut, intf, 1)) {
10516 send_resp(dut, conn, SIGMA_ERROR,
10517 "ErrorCode,Failed to set RU 242 tone Tx");
10518 return STATUS_SENT_ERROR;
10519 }
10520 }
10521
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -070010522 val = get_param(cmd, "OMControl");
10523 if (val) {
10524 int set_val = 1;
10525
10526 if (strcasecmp(val, "Enable") == 0)
10527 set_val = 1;
10528 else if (strcasecmp(val, "Disable") == 0)
10529 set_val = 0;
10530
10531 if (sta_set_om_ctrl_supp(dut, intf, set_val)) {
10532 send_resp(dut, conn, SIGMA_ERROR,
10533 "ErrorCode,Failed to set OM ctrl supp");
Jouni Malinen224e3902021-06-09 16:41:27 +030010534 return STATUS_SENT_ERROR;
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -070010535 }
10536 }
10537
Kiran Kumar Lokere4f2d4b02021-04-01 00:07:39 -070010538 val = get_param(cmd, "BSSMaxIdlePeriod");
10539 if (val && sta_set_bss_max_idle_period(dut, intf, atoi(val))) {
10540 send_resp(dut, conn, SIGMA_ERROR,
10541 "ErrorCode,Failed to set BSS max idle period");
10542 return STATUS_SENT_ERROR;
10543 }
10544
Kiran Kumar Lokere07ad92b2021-08-09 00:27:14 -070010545 val = get_param(cmd, "BSS_max_idle");
10546 if (val) {
10547 int set_val = 0;
10548
10549 if (strcasecmp(val, "Enable") == 0)
10550 set_val = 1;
10551 else if (strcasecmp(val, "Disable") == 0)
10552 set_val = 0;
10553 if (sta_set_bss_max_idle_support(dut, intf, set_val)) {
10554 send_resp(dut, conn, SIGMA_ERROR,
10555 "ErrorCode,Failed to set BSS max idle support");
10556 return STATUS_SENT_ERROR;
10557 }
10558 }
10559
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -070010560 val = get_param(cmd, "ADDBAResp_BufSize");
10561 if (val) {
10562 int buf_size;
10563
10564 if (strcasecmp(val, "gt64") == 0)
10565 buf_size = 256;
10566 else
10567 buf_size = 64;
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010568 if (get_driver_type(dut) == DRIVER_WCN &&
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -070010569 sta_set_addba_buf_size(dut, intf, buf_size)) {
10570 send_resp(dut, conn, SIGMA_ERROR,
10571 "ErrorCode,set addbaresp_buff_size failed");
Jouni Malinen224e3902021-06-09 16:41:27 +030010572 return STATUS_SENT_ERROR;
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -070010573 }
10574 }
10575
10576 val = get_param(cmd, "ADDBAReq_BufSize");
10577 if (val) {
10578 int buf_size;
10579
10580 if (strcasecmp(val, "gt64") == 0)
10581 buf_size = 256;
10582 else
10583 buf_size = 64;
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010584 if (get_driver_type(dut) == DRIVER_WCN &&
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -070010585 sta_set_addba_buf_size(dut, intf, buf_size)) {
10586 send_resp(dut, conn, SIGMA_ERROR,
10587 "ErrorCode,set addbareq_buff_size failed");
Jouni Malinen224e3902021-06-09 16:41:27 +030010588 return STATUS_SENT_ERROR;
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -070010589 }
10590 }
10591
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010592 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
10593}
10594
10595
10596static int sta_set_wireless_60g(struct sigma_dut *dut,
10597 struct sigma_conn *conn,
10598 struct sigma_cmd *cmd)
10599{
10600 const char *dev_role = get_param(cmd, "DevRole");
10601
10602 if (!dev_role) {
10603 send_resp(dut, conn, SIGMA_INVALID,
10604 "ErrorCode,DevRole not specified");
10605 return 0;
10606 }
10607
10608 if (strcasecmp(dev_role, "PCP") == 0)
10609 return sta_set_60g_pcp(dut, conn, cmd);
10610 if (strcasecmp(dev_role, "STA") == 0)
10611 return sta_set_60g_sta(dut, conn, cmd);
10612 send_resp(dut, conn, SIGMA_INVALID,
10613 "ErrorCode,DevRole not supported");
10614 return 0;
10615}
10616
10617
Ankita Bajaj0d5825b2017-10-25 16:20:17 +053010618static int sta_set_wireless_oce(struct sigma_dut *dut, struct sigma_conn *conn,
10619 struct sigma_cmd *cmd)
10620{
10621 int status;
10622 const char *intf = get_param(cmd, "Interface");
10623 const char *val = get_param(cmd, "DevRole");
10624
10625 if (val && strcasecmp(val, "STA-CFON") == 0) {
10626 status = sta_cfon_set_wireless(dut, conn, cmd);
10627 if (status)
10628 return status;
10629 }
10630 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
10631}
10632
10633
Jouni Malinen67433fc2020-06-26 22:50:33 +030010634static enum sigma_cmd_result
10635sta_set_wireless_wpa3(struct sigma_dut *dut, struct sigma_conn *conn,
10636 struct sigma_cmd *cmd)
Vamsi Krishnac1633d22020-05-06 18:31:21 +053010637{
10638 const char *intf = get_param(cmd, "Interface");
10639 const char *val;
10640
10641 val = get_param(cmd, "ocvc");
10642 if (val)
10643 dut->ocvc = atoi(val);
10644
Jouni Malinen67433fc2020-06-26 22:50:33 +030010645 val = get_param(cmd, "ClientPrivacy");
Veerendranath Jakkam47867202020-12-21 01:53:52 +053010646 if (val && dut->client_privacy != atoi(val) &&
10647 sta_set_client_privacy(dut, conn, intf, atoi(val))) {
10648 send_resp(dut, conn, SIGMA_ERROR,
10649 "errorCode,Failed to configure random MAC address use");
10650 return STATUS_SENT_ERROR;
Jouni Malinen67433fc2020-06-26 22:50:33 +030010651 }
10652
Vamsi Krishnac1633d22020-05-06 18:31:21 +053010653 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
10654}
10655
10656
Jouni Malinenf7222712019-06-13 01:50:21 +030010657static enum sigma_cmd_result cmd_sta_set_wireless(struct sigma_dut *dut,
10658 struct sigma_conn *conn,
10659 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010660{
10661 const char *val;
10662
10663 val = get_param(cmd, "Program");
10664 if (val) {
10665 if (strcasecmp(val, "11n") == 0)
10666 return cmd_sta_set_11n(dut, conn, cmd);
Amarnath Hullur Subramanyam4f860292018-01-31 03:49:35 -080010667 if (strcasecmp(val, "VHT") == 0 || strcasecmp(val, "HE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010668 return cmd_sta_set_wireless_vht(dut, conn, cmd);
10669 if (strcasecmp(val, "60ghz") == 0)
10670 return sta_set_wireless_60g(dut, conn, cmd);
Ankita Bajaj0d5825b2017-10-25 16:20:17 +053010671 if (strcasecmp(val, "OCE") == 0)
10672 return sta_set_wireless_oce(dut, conn, cmd);
Alexei Avshalom Lazar66bb9972018-12-18 16:01:43 +020010673 /* sta_set_wireless in WPS program is only used for 60G */
10674 if (is_60g_sigma_dut(dut))
10675 return sta_set_wireless_60g(dut, conn, cmd);
Vamsi Krishnac1633d22020-05-06 18:31:21 +053010676 if (strcasecmp(val, "WPA3") == 0)
10677 return sta_set_wireless_wpa3(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010678 send_resp(dut, conn, SIGMA_ERROR,
10679 "ErrorCode,Program value not supported");
10680 } else {
10681 send_resp(dut, conn, SIGMA_ERROR,
10682 "ErrorCode,Program argument not available");
10683 }
10684
10685 return 0;
10686}
10687
10688
10689static void ath_sta_inject_frame(struct sigma_dut *dut, const char *intf,
10690 int tid)
10691{
10692 char buf[100];
10693 int tid_to_dscp [] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 };
10694
Pradeep Reddy POTTETId31d1322016-10-13 17:22:03 +053010695 if (tid < 0 ||
10696 tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) {
10697 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid);
10698 return;
10699 }
10700
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010701 /*
10702 * Two ways to ensure that addba request with a
10703 * non zero TID could be sent out. EV 117296
10704 */
10705 snprintf(buf, sizeof(buf),
10706 "ping -c 8 -Q %d `arp -a | grep wlan0 | awk '{print $2}' | tr -d '()'`",
10707 tid);
10708 if (system(buf) != 0) {
10709 sigma_dut_print(dut, DUT_MSG_ERROR,
10710 "Ping did not send out");
10711 }
10712
10713 snprintf(buf, sizeof(buf),
10714 "iwconfig %s | grep Access | awk '{print $6}' > %s",
10715 intf, VI_QOS_TMP_FILE);
10716 if (system(buf) != 0)
10717 return;
10718
10719 snprintf(buf, sizeof(buf),
10720 "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s",
10721 intf, VI_QOS_TMP_FILE);
10722 if (system(buf) != 0)
10723 sigma_dut_print(dut, DUT_MSG_ERROR, "HWaddr matching failed");
10724
10725 snprintf(buf,sizeof(buf), "sed -n '3,$p' %s >> %s",
10726 VI_QOS_REFFILE, VI_QOS_TMP_FILE);
10727 if (system(buf) != 0) {
10728 sigma_dut_print(dut, DUT_MSG_ERROR,
10729 "VI_QOS_TEMP_FILE generation error failed");
10730 }
10731 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
10732 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
10733 if (system(buf) != 0) {
10734 sigma_dut_print(dut, DUT_MSG_ERROR,
10735 "VI_QOS_FILE generation failed");
10736 }
10737
10738 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
10739 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
10740 if (system(buf) != 0) {
10741 sigma_dut_print(dut, DUT_MSG_ERROR,
10742 "VI_QOS_FILE generation failed");
10743 }
10744
10745 snprintf(buf, sizeof(buf), "ethinject %s %s", intf, VI_QOS_FILE);
10746 if (system(buf) != 0) {
10747 }
10748}
10749
10750
10751static int ath_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
10752 struct sigma_cmd *cmd)
10753{
10754 const char *intf = get_param(cmd, "Interface");
10755 const char *val;
10756 int tid = 0;
10757 char buf[100];
10758
10759 val = get_param(cmd, "TID");
10760 if (val) {
10761 tid = atoi(val);
10762 if (tid)
10763 ath_sta_inject_frame(dut, intf, tid);
10764 }
10765
10766 /* Command sequence for ADDBA request on Peregrine based devices */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010767 run_iwpriv(dut, intf, "setaddbaoper 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010768
10769 snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4", intf, tid);
10770 if (system(buf) != 0) {
10771 sigma_dut_print(dut, DUT_MSG_ERROR,
10772 "wifitool senddelba failed");
10773 }
10774
10775 snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64", intf, tid);
10776 if (system(buf) != 0) {
10777 sigma_dut_print(dut, DUT_MSG_ERROR,
10778 "wifitool sendaddba failed");
10779 }
10780
10781 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
10782
10783 return 1;
10784}
10785
10786
Lior David9981b512017-01-20 13:16:40 +020010787#ifdef __linux__
10788
10789static int wil6210_send_addba(struct sigma_dut *dut, const char *dest_mac,
10790 int agg_size)
10791{
10792 char dir[128], buf[128];
10793 FILE *f;
10794 regex_t re;
10795 regmatch_t m[2];
Jouni Malinen3aa72862019-05-29 23:14:51 +030010796 int rc, ret = -1, vring_id, found, res;
Lior David9981b512017-01-20 13:16:40 +020010797
10798 if (wil6210_get_debugfs_dir(dut, dir, sizeof(dir))) {
10799 sigma_dut_print(dut, DUT_MSG_ERROR,
10800 "failed to get wil6210 debugfs dir");
10801 return -1;
10802 }
10803
Jouni Malinen3aa72862019-05-29 23:14:51 +030010804 res = snprintf(buf, sizeof(buf), "%s/vrings", dir);
10805 if (res < 0 || res >= sizeof(buf))
10806 return -1;
Lior David9981b512017-01-20 13:16:40 +020010807 f = fopen(buf, "r");
10808 if (!f) {
10809 sigma_dut_print(dut, DUT_MSG_ERROR, "failed to open: %s", buf);
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +020010810 /* newer wil6210 driver renamed file to "rings" */
Jouni Malinen3aa72862019-05-29 23:14:51 +030010811 res = snprintf(buf, sizeof(buf), "%s/rings", dir);
10812 if (res < 0 || res >= sizeof(buf))
10813 return -1;
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +020010814 f = fopen(buf, "r");
10815 if (!f) {
10816 sigma_dut_print(dut, DUT_MSG_ERROR,
10817 "failed to open: %s", buf);
10818 return -1;
10819 }
Lior David9981b512017-01-20 13:16:40 +020010820 }
10821
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +020010822 /* can be either VRING tx... or RING... */
10823 if (regcomp(&re, "RING tx_[ \t]*([0-9]+)", REG_EXTENDED)) {
Lior David9981b512017-01-20 13:16:40 +020010824 sigma_dut_print(dut, DUT_MSG_ERROR, "regcomp failed");
10825 goto out;
10826 }
10827
10828 /* find TX VRING for the mac address */
10829 found = 0;
10830 while (fgets(buf, sizeof(buf), f)) {
10831 if (strcasestr(buf, dest_mac)) {
10832 found = 1;
10833 break;
10834 }
10835 }
10836
10837 if (!found) {
10838 sigma_dut_print(dut, DUT_MSG_ERROR,
10839 "no TX VRING for %s", dest_mac);
10840 goto out;
10841 }
10842
10843 /* extract VRING ID, "VRING tx_<id> = {" */
10844 if (!fgets(buf, sizeof(buf), f)) {
10845 sigma_dut_print(dut, DUT_MSG_ERROR,
10846 "no VRING start line for %s", dest_mac);
10847 goto out;
10848 }
10849
10850 rc = regexec(&re, buf, 2, m, 0);
10851 regfree(&re);
10852 if (rc || m[1].rm_so < 0) {
10853 sigma_dut_print(dut, DUT_MSG_ERROR,
10854 "no VRING TX ID for %s", dest_mac);
10855 goto out;
10856 }
10857 buf[m[1].rm_eo] = 0;
10858 vring_id = atoi(&buf[m[1].rm_so]);
10859
10860 /* send the addba command */
10861 fclose(f);
Jouni Malinen3aa72862019-05-29 23:14:51 +030010862 res = snprintf(buf, sizeof(buf), "%s/back", dir);
10863 if (res < 0 || res >= sizeof(buf))
10864 return -1;
Lior David9981b512017-01-20 13:16:40 +020010865 f = fopen(buf, "w");
10866 if (!f) {
10867 sigma_dut_print(dut, DUT_MSG_ERROR,
10868 "failed to open: %s", buf);
10869 return -1;
10870 }
10871
10872 fprintf(f, "add %d %d\n", vring_id, agg_size);
10873
10874 ret = 0;
10875
10876out:
10877 fclose(f);
10878
10879 return ret;
10880}
10881
10882
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +020010883int send_addba_60g(struct sigma_dut *dut, struct sigma_conn *conn,
10884 struct sigma_cmd *cmd, const char *mac_param)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010885{
10886 const char *val;
10887 int tid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010888
10889 val = get_param(cmd, "TID");
10890 if (val) {
10891 tid = atoi(val);
10892 if (tid != 0) {
10893 sigma_dut_print(dut, DUT_MSG_ERROR,
10894 "Ignore TID %d for send_addba use TID 0 for 60g since only 0 required on TX",
10895 tid);
10896 }
10897 }
10898
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +020010899 val = get_param(cmd, mac_param);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010900 if (!val) {
10901 sigma_dut_print(dut, DUT_MSG_ERROR,
10902 "Currently not supporting addba for 60G without Dest_mac");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020010903 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010904 }
10905
Lior David9981b512017-01-20 13:16:40 +020010906 if (wil6210_send_addba(dut, val, dut->back_rcv_buf))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010907 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010908
10909 return 1;
10910}
10911
Lior David9981b512017-01-20 13:16:40 +020010912#endif /* __linux__ */
10913
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010914
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080010915static int wcn_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
10916 struct sigma_cmd *cmd)
10917{
10918#ifdef NL80211_SUPPORT
10919 const char *intf = get_param(cmd, "Interface");
10920 const char *val;
10921 int tid = -1;
10922 int bufsize = 64;
10923 struct nl_msg *msg;
10924 int ret = 0;
10925 struct nlattr *params;
10926 int ifindex;
10927
10928 val = get_param(cmd, "TID");
10929 if (val)
10930 tid = atoi(val);
10931
10932 if (tid == -1) {
10933 send_resp(dut, conn, SIGMA_ERROR,
10934 "ErrorCode,sta_send_addba tid invalid");
10935 return 0;
10936 }
10937
10938 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
10939
10940 ifindex = if_nametoindex(intf);
10941 if (ifindex == 0) {
10942 sigma_dut_print(dut, DUT_MSG_ERROR,
10943 "%s: Index for interface %s failed",
10944 __func__, intf);
10945 send_resp(dut, conn, SIGMA_ERROR,
10946 "ErrorCode,sta_send_addba interface invalid");
10947 return 0;
10948 }
10949
10950 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
10951 NL80211_CMD_VENDOR)) ||
10952 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
10953 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
10954 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
10955 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
10956 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
10957 nla_put_u8(msg,
10958 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADD_DEL_BA_SESSION,
10959 QCA_WLAN_ADD_BA) ||
10960 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BA_TID,
10961 tid) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -070010962 nla_put_u16(msg,
10963 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
10964 bufsize)) {
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080010965 sigma_dut_print(dut, DUT_MSG_ERROR,
10966 "%s: err in adding vendor_cmd and vendor_data",
10967 __func__);
10968 nlmsg_free(msg);
10969 send_resp(dut, conn, SIGMA_ERROR,
10970 "ErrorCode,sta_send_addba err in adding vendor_cmd and vendor_data");
10971 return 0;
10972 }
10973 nla_nest_end(msg, params);
10974
10975 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
10976 if (ret) {
10977 sigma_dut_print(dut, DUT_MSG_ERROR,
10978 "%s: err in send_and_recv_msgs, ret=%d",
10979 __func__, ret);
Sunil Dutt30605592018-05-04 20:35:50 +053010980 if (ret == -EOPNOTSUPP)
10981 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080010982 send_resp(dut, conn, SIGMA_ERROR,
10983 "ErrorCode,sta_send_addba err in send_and_recv_msgs");
10984 return 0;
10985 }
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080010986#else /* NL80211_SUPPORT */
10987 sigma_dut_print(dut, DUT_MSG_ERROR,
10988 "sta_send_addba not supported without NL80211_SUPPORT defined");
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080010989#endif /* NL80211_SUPPORT */
Sunil Dutt30605592018-05-04 20:35:50 +053010990
10991 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080010992}
10993
10994
Jouni Malinenf7222712019-06-13 01:50:21 +030010995static enum sigma_cmd_result cmd_sta_send_addba(struct sigma_dut *dut,
10996 struct sigma_conn *conn,
10997 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010998{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010999 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011000 case DRIVER_ATHEROS:
11001 return ath_sta_send_addba(dut, conn, cmd);
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080011002 case DRIVER_WCN:
11003 return wcn_sta_send_addba(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +020011004#ifdef __linux__
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011005 case DRIVER_WIL6210:
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +020011006 return send_addba_60g(dut, conn, cmd, "Dest_mac");
Lior David9981b512017-01-20 13:16:40 +020011007#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011008 default:
11009 /*
11010 * There is no driver specific implementation for other drivers.
11011 * Ignore the command and report COMPLETE since the following
11012 * throughput test operation will end up sending ADDBA anyway.
11013 */
11014 return 1;
11015 }
11016}
11017
11018
11019int inject_eth_frame(int s, const void *data, size_t len,
11020 unsigned short ethtype, char *dst, char *src)
11021{
11022 struct iovec iov[4] = {
11023 {
11024 .iov_base = dst,
11025 .iov_len = ETH_ALEN,
11026 },
11027 {
11028 .iov_base = src,
11029 .iov_len = ETH_ALEN,
11030 },
11031 {
11032 .iov_base = &ethtype,
11033 .iov_len = sizeof(unsigned short),
11034 },
11035 {
11036 .iov_base = (void *) data,
11037 .iov_len = len,
11038 }
11039 };
11040 struct msghdr msg = {
11041 .msg_name = NULL,
11042 .msg_namelen = 0,
11043 .msg_iov = iov,
11044 .msg_iovlen = 4,
11045 .msg_control = NULL,
11046 .msg_controllen = 0,
11047 .msg_flags = 0,
11048 };
11049
11050 return sendmsg(s, &msg, 0);
11051}
11052
11053#if defined(__linux__) || defined(__QNXNTO__)
11054
11055int inject_frame(int s, const void *data, size_t len, int encrypt)
11056{
11057#define IEEE80211_RADIOTAP_F_WEP 0x04
11058#define IEEE80211_RADIOTAP_F_FRAG 0x08
11059 unsigned char rtap_hdr[] = {
11060 0x00, 0x00, /* radiotap version */
11061 0x0e, 0x00, /* radiotap length */
11062 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
11063 IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */
11064 0x00, /* padding */
11065 0x00, 0x00, /* RX and TX flags to indicate that */
11066 0x00, 0x00, /* this is the injected frame directly */
11067 };
11068 struct iovec iov[2] = {
11069 {
11070 .iov_base = &rtap_hdr,
11071 .iov_len = sizeof(rtap_hdr),
11072 },
11073 {
11074 .iov_base = (void *) data,
11075 .iov_len = len,
11076 }
11077 };
11078 struct msghdr msg = {
11079 .msg_name = NULL,
11080 .msg_namelen = 0,
11081 .msg_iov = iov,
11082 .msg_iovlen = 2,
11083 .msg_control = NULL,
11084 .msg_controllen = 0,
11085 .msg_flags = 0,
11086 };
11087
11088 if (encrypt)
11089 rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP;
11090
11091 return sendmsg(s, &msg, 0);
11092}
11093
11094
11095int open_monitor(const char *ifname)
11096{
11097#ifdef __QNXNTO__
11098 struct sockaddr_dl ll;
11099 int s;
11100
11101 memset(&ll, 0, sizeof(ll));
11102 ll.sdl_family = AF_LINK;
11103 ll.sdl_index = if_nametoindex(ifname);
11104 if (ll.sdl_index == 0) {
11105 perror("if_nametoindex");
11106 return -1;
11107 }
11108 s = socket(PF_INET, SOCK_RAW, 0);
11109#else /* __QNXNTO__ */
11110 struct sockaddr_ll ll;
11111 int s;
11112
11113 memset(&ll, 0, sizeof(ll));
11114 ll.sll_family = AF_PACKET;
11115 ll.sll_ifindex = if_nametoindex(ifname);
11116 if (ll.sll_ifindex == 0) {
11117 perror("if_nametoindex");
11118 return -1;
11119 }
11120 s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
11121#endif /* __QNXNTO__ */
11122 if (s < 0) {
11123 perror("socket[PF_PACKET,SOCK_RAW]");
11124 return -1;
11125 }
11126
11127 if (bind(s, (struct sockaddr *) &ll, sizeof(ll)) < 0) {
11128 perror("monitor socket bind");
11129 close(s);
11130 return -1;
11131 }
11132
11133 return s;
11134}
11135
11136
11137static int hex2num(char c)
11138{
11139 if (c >= '0' && c <= '9')
11140 return c - '0';
11141 if (c >= 'a' && c <= 'f')
11142 return c - 'a' + 10;
11143 if (c >= 'A' && c <= 'F')
11144 return c - 'A' + 10;
11145 return -1;
11146}
11147
11148
11149int hwaddr_aton(const char *txt, unsigned char *addr)
11150{
11151 int i;
11152
11153 for (i = 0; i < 6; i++) {
11154 int a, b;
11155
11156 a = hex2num(*txt++);
11157 if (a < 0)
11158 return -1;
11159 b = hex2num(*txt++);
11160 if (b < 0)
11161 return -1;
11162 *addr++ = (a << 4) | b;
11163 if (i < 5 && *txt++ != ':')
11164 return -1;
11165 }
11166
11167 return 0;
11168}
11169
11170#endif /* defined(__linux__) || defined(__QNXNTO__) */
11171
Veerendranath Jakkam49774122020-07-05 09:52:18 +053011172
11173#ifdef NL80211_SUPPORT
11174static int nl80211_send_frame_cmd(struct sigma_dut *dut, const char *intf,
11175 const u8 *data, size_t data_len, int freq)
11176{
11177 struct nl_msg *msg;
11178 int ret = 0;
11179 int ifindex;
11180
11181 ifindex = if_nametoindex(intf);
11182 if (ifindex == 0) {
11183 sigma_dut_print(dut, DUT_MSG_ERROR,
11184 "%s: Index for interface %s failed",
11185 __func__, intf);
11186 return -1;
11187 }
11188
11189 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
11190 NL80211_CMD_FRAME)) ||
11191 (freq && nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
11192 nla_put(msg, NL80211_ATTR_FRAME, data_len, data)) {
11193 sigma_dut_print(dut, DUT_MSG_ERROR,
11194 "%s: Error in adding NL80211_CMD_FRAME",
11195 __func__);
11196 nlmsg_free(msg);
11197 return -1;
11198 }
11199
11200 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
11201 if (ret) {
11202 sigma_dut_print(dut, DUT_MSG_ERROR,
11203 "nl80211: Frame command failed: ret=%d (%s) req=%u",
11204 ret, strerror(-ret), freq);
11205 return -1;
11206 }
11207
11208 return 0;
11209}
11210#endif /* NL80211_SUPPORT */
11211
11212
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011213enum send_frame_type {
11214 DISASSOC, DEAUTH, SAQUERY, AUTH, ASSOCREQ, REASSOCREQ, DLS_REQ
11215};
11216enum send_frame_protection {
11217 CORRECT_KEY, INCORRECT_KEY, UNPROTECTED
11218};
11219
11220
11221static int sta_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn,
Veerendranath Jakkam49774122020-07-05 09:52:18 +053011222 const char *intf, enum send_frame_type frame,
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011223 enum send_frame_protection protected,
Veerendranath Jakkam49774122020-07-05 09:52:18 +053011224 const char *dest, int use_monitor)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011225{
11226#ifdef __linux__
11227 unsigned char buf[1000], *pos;
11228 int s, res;
11229 char bssid[20], addr[20];
11230 char result[32], ssid[100];
11231 size_t ssid_len;
11232
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011233 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011234 sizeof(result)) < 0 ||
11235 strncmp(result, "COMPLETED", 9) != 0) {
11236 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Not connected");
11237 return 0;
11238 }
11239
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011240 if (get_wpa_status(get_station_ifname(dut), "bssid",
11241 bssid, sizeof(bssid)) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011242 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
11243 "current BSSID");
11244 return 0;
11245 }
11246
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011247 if (get_wpa_status(get_station_ifname(dut), "address",
11248 addr, sizeof(addr)) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011249 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
11250 "own MAC address");
11251 return 0;
11252 }
11253
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011254 if (get_wpa_status(get_station_ifname(dut), "ssid", ssid, sizeof(ssid))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011255 < 0) {
11256 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
11257 "current SSID");
11258 return 0;
11259 }
11260 ssid_len = strlen(ssid);
11261
11262 pos = buf;
11263
11264 /* Frame Control */
11265 switch (frame) {
11266 case DISASSOC:
11267 *pos++ = 0xa0;
11268 break;
11269 case DEAUTH:
11270 *pos++ = 0xc0;
11271 break;
11272 case SAQUERY:
11273 *pos++ = 0xd0;
11274 break;
11275 case AUTH:
11276 *pos++ = 0xb0;
11277 break;
11278 case ASSOCREQ:
11279 *pos++ = 0x00;
11280 break;
11281 case REASSOCREQ:
11282 *pos++ = 0x20;
11283 break;
11284 case DLS_REQ:
11285 *pos++ = 0xd0;
11286 break;
11287 }
11288
11289 if (protected == INCORRECT_KEY)
11290 *pos++ = 0x40; /* Set Protected field to 1 */
11291 else
11292 *pos++ = 0x00;
11293
11294 /* Duration */
11295 *pos++ = 0x00;
11296 *pos++ = 0x00;
11297
11298 /* addr1 = DA (current AP) */
11299 hwaddr_aton(bssid, pos);
11300 pos += 6;
11301 /* addr2 = SA (own address) */
11302 hwaddr_aton(addr, pos);
11303 pos += 6;
11304 /* addr3 = BSSID (current AP) */
11305 hwaddr_aton(bssid, pos);
11306 pos += 6;
11307
11308 /* Seq# (to be filled by driver/mac80211) */
11309 *pos++ = 0x00;
11310 *pos++ = 0x00;
11311
11312 if (protected == INCORRECT_KEY) {
11313 /* CCMP parameters */
11314 memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8);
11315 pos += 8;
11316 }
11317
11318 if (protected == INCORRECT_KEY) {
11319 switch (frame) {
11320 case DEAUTH:
11321 /* Reason code (encrypted) */
11322 memcpy(pos, "\xa7\x39", 2);
11323 pos += 2;
11324 break;
11325 case DISASSOC:
11326 /* Reason code (encrypted) */
11327 memcpy(pos, "\xa7\x39", 2);
11328 pos += 2;
11329 break;
11330 case SAQUERY:
11331 /* Category|Action|TransID (encrypted) */
11332 memcpy(pos, "\x6f\xbd\xe9\x4d", 4);
11333 pos += 4;
11334 break;
11335 default:
11336 return -1;
11337 }
11338
11339 /* CCMP MIC */
11340 memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8);
11341 pos += 8;
11342 } else {
11343 switch (frame) {
11344 case DEAUTH:
11345 /* reason code = 8 */
11346 *pos++ = 0x08;
11347 *pos++ = 0x00;
11348 break;
11349 case DISASSOC:
11350 /* reason code = 8 */
11351 *pos++ = 0x08;
11352 *pos++ = 0x00;
11353 break;
11354 case SAQUERY:
11355 /* Category - SA Query */
11356 *pos++ = 0x08;
11357 /* SA query Action - Request */
11358 *pos++ = 0x00;
11359 /* Transaction ID */
11360 *pos++ = 0x12;
11361 *pos++ = 0x34;
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053011362 if (dut->saquery_oci_freq) {
11363 /* OCI IE - Extended ID */
11364 *pos++ = 0xFF;
11365 *pos++ = 0x04;
11366 *pos++ = 0x36;
11367 /* Operating Class */
11368 *pos++ = 0x74;
11369 /* Primary Channel */
11370 *pos++ = freq_to_channel(dut->saquery_oci_freq);
11371 /* Frequency Segment 1 Channel Number */
11372 *pos++ = 0x00;
11373 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011374 break;
11375 case AUTH:
11376 /* Auth Alg (Open) */
11377 *pos++ = 0x00;
11378 *pos++ = 0x00;
11379 /* Seq# */
11380 *pos++ = 0x01;
11381 *pos++ = 0x00;
11382 /* Status code */
11383 *pos++ = 0x00;
11384 *pos++ = 0x00;
11385 break;
11386 case ASSOCREQ:
11387 /* Capability Information */
11388 *pos++ = 0x31;
11389 *pos++ = 0x04;
11390 /* Listen Interval */
11391 *pos++ = 0x0a;
11392 *pos++ = 0x00;
11393 /* SSID */
11394 *pos++ = 0x00;
11395 *pos++ = ssid_len;
11396 memcpy(pos, ssid, ssid_len);
11397 pos += ssid_len;
11398 /* Supported Rates */
11399 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
11400 10);
11401 pos += 10;
11402 /* Extended Supported Rates */
11403 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
11404 pos += 6;
11405 /* RSN */
11406 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
11407 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
11408 "\x00\x00\x00\x00\x0f\xac\x06", 28);
11409 pos += 28;
11410 break;
11411 case REASSOCREQ:
11412 /* Capability Information */
11413 *pos++ = 0x31;
11414 *pos++ = 0x04;
11415 /* Listen Interval */
11416 *pos++ = 0x0a;
11417 *pos++ = 0x00;
11418 /* Current AP */
11419 hwaddr_aton(bssid, pos);
11420 pos += 6;
11421 /* SSID */
11422 *pos++ = 0x00;
11423 *pos++ = ssid_len;
11424 memcpy(pos, ssid, ssid_len);
11425 pos += ssid_len;
11426 /* Supported Rates */
11427 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
11428 10);
11429 pos += 10;
11430 /* Extended Supported Rates */
11431 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
11432 pos += 6;
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053011433 /* RSNE - Group and Pairwise ciphers */
11434 memcpy(pos,
11435 "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x04",
11436 14);
11437 pos += 14;
11438 /* RSNE - AKM Suite count */
11439 *pos++ = 0x01;
11440 *pos++ = 0x00;
11441 /* RSNE - AKM Suites */
11442 if (dut->program == PROGRAM_WPA3)
11443 memcpy(pos, "\x00\x0f\xac\x08", 4);
11444 else
11445 memcpy(pos, "\x00\x0f\xac\x02", 4);
11446 pos += 4;
11447 /* RSNE - Capabilities */
11448 *pos++ = 0xc0;
11449 if (dut->ocvc)
11450 *pos++ = 0x40;
11451 else
11452 *pos++ = 0x00;
11453 /* RSNE - PMKID list and Group Management Ciphers */
11454 memcpy(pos, "\x00\x00\x00\x0f\xac\x06", 6);
11455 pos += 6;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011456 break;
11457 case DLS_REQ:
11458 /* Category - DLS */
11459 *pos++ = 0x02;
11460 /* DLS Action - Request */
11461 *pos++ = 0x00;
11462 /* Destination MACAddress */
11463 if (dest)
11464 hwaddr_aton(dest, pos);
11465 else
11466 memset(pos, 0, 6);
11467 pos += 6;
11468 /* Source MACAddress */
11469 hwaddr_aton(addr, pos);
11470 pos += 6;
11471 /* Capability Information */
11472 *pos++ = 0x10; /* Privacy */
11473 *pos++ = 0x06; /* QoS */
11474 /* DLS Timeout Value */
11475 *pos++ = 0x00;
11476 *pos++ = 0x01;
11477 /* Supported rates */
11478 *pos++ = 0x01;
11479 *pos++ = 0x08;
11480 *pos++ = 0x0c; /* 6 Mbps */
11481 *pos++ = 0x12; /* 9 Mbps */
11482 *pos++ = 0x18; /* 12 Mbps */
11483 *pos++ = 0x24; /* 18 Mbps */
11484 *pos++ = 0x30; /* 24 Mbps */
11485 *pos++ = 0x48; /* 36 Mbps */
11486 *pos++ = 0x60; /* 48 Mbps */
11487 *pos++ = 0x6c; /* 54 Mbps */
11488 /* TODO: Extended Supported Rates */
11489 /* TODO: HT Capabilities */
11490 break;
11491 }
11492 }
11493
Veerendranath Jakkam49774122020-07-05 09:52:18 +053011494 if (use_monitor) {
11495 s = open_monitor("sigmadut");
11496 if (s < 0) {
11497 send_resp(dut, conn, SIGMA_ERROR,
11498 "errorCode,Failed to open monitor socket");
11499 return 0;
11500 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011501
Veerendranath Jakkam49774122020-07-05 09:52:18 +053011502 res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY);
11503 if (res < 0) {
11504 send_resp(dut, conn, SIGMA_ERROR,
11505 "errorCode,Failed to inject frame");
11506 close(s);
11507 return 0;
11508 }
11509 if (res < pos - buf) {
11510 send_resp(dut, conn, SIGMA_ERROR,
11511 "errorCode,Only partial frame sent");
11512 close(s);
11513 return 0;
11514 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011515
Veerendranath Jakkam49774122020-07-05 09:52:18 +053011516 close(s);
11517 } else {
11518#ifdef NL80211_SUPPORT
11519 int freq;
11520 char freq_str[10];
11521
11522 if (get_wpa_status(get_station_ifname(dut), "freq",
11523 freq_str, sizeof(freq_str)) < 0) {
11524 send_resp(dut, conn, SIGMA_ERROR,
11525 "errorCode,Could not get current operating frequency");
11526 return 0;
11527 }
11528 freq = atoi(freq_str);
11529
11530 if (nl80211_send_frame_cmd(dut, intf, buf, pos - buf, freq)) {
11531 send_resp(dut, conn, SIGMA_ERROR,
11532 "errorCode,Failed to inject frame");
11533 return 0;
11534 }
11535#else /* NL80211_SUPPORT */
11536 send_resp(dut, conn, SIGMA_ERROR,
11537 "errorCode,Failed to inject frame (no NL80211_SUPPORT)");
11538 return 0;
11539#endif /* NL80211_SUPPORT */
11540 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011541
11542 return 1;
11543#else /* __linux__ */
11544 send_resp(dut, conn, SIGMA_ERROR, "errorCode,sta_send_frame not "
11545 "yet supported");
11546 return 0;
11547#endif /* __linux__ */
11548}
11549
11550
11551static int cmd_sta_send_frame_tdls(struct sigma_dut *dut,
11552 struct sigma_conn *conn,
11553 struct sigma_cmd *cmd)
11554{
11555 const char *intf = get_param(cmd, "Interface");
11556 const char *sta, *val;
11557 unsigned char addr[ETH_ALEN];
11558 char buf[100];
11559
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030011560 if (!intf)
11561 return -1;
11562
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011563 sta = get_param(cmd, "peer");
11564 if (sta == NULL)
11565 sta = get_param(cmd, "station");
11566 if (sta == NULL) {
11567 send_resp(dut, conn, SIGMA_ERROR,
11568 "ErrorCode,Missing peer address");
11569 return 0;
11570 }
11571 if (hwaddr_aton(sta, addr) < 0) {
11572 send_resp(dut, conn, SIGMA_ERROR,
11573 "ErrorCode,Invalid peer address");
11574 return 0;
11575 }
11576
11577 val = get_param(cmd, "type");
11578 if (val == NULL)
11579 return -1;
11580
11581 if (strcasecmp(val, "DISCOVERY") == 0) {
11582 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", sta);
11583 if (wpa_command(intf, buf) < 0) {
11584 send_resp(dut, conn, SIGMA_ERROR,
11585 "ErrorCode,Failed to send TDLS discovery");
11586 return 0;
11587 }
11588 return 1;
11589 }
11590
11591 if (strcasecmp(val, "SETUP") == 0) {
11592 int status = 0, timeout = 0;
11593
11594 val = get_param(cmd, "Status");
11595 if (val)
11596 status = atoi(val);
11597
11598 val = get_param(cmd, "Timeout");
11599 if (val)
11600 timeout = atoi(val);
11601
11602 if (status != 0 && status != 37) {
11603 send_resp(dut, conn, SIGMA_ERROR,
11604 "ErrorCode,Unsupported status value");
11605 return 0;
11606 }
11607
11608 if (timeout != 0 && timeout != 301) {
11609 send_resp(dut, conn, SIGMA_ERROR,
11610 "ErrorCode,Unsupported timeout value");
11611 return 0;
11612 }
11613
11614 if (status && timeout) {
11615 send_resp(dut, conn, SIGMA_ERROR,
11616 "ErrorCode,Unsupported timeout+status "
11617 "combination");
11618 return 0;
11619 }
11620
11621 if (status == 37 &&
11622 wpa_command(intf, "SET tdls_testing 0x200")) {
11623 send_resp(dut, conn, SIGMA_ERROR,
11624 "ErrorCode,Failed to enable "
11625 "decline setup response test mode");
11626 return 0;
11627 }
11628
11629 if (timeout == 301) {
11630 int res;
11631 if (dut->no_tpk_expiration)
11632 res = wpa_command(intf,
11633 "SET tdls_testing 0x108");
11634 else
11635 res = wpa_command(intf,
11636 "SET tdls_testing 0x8");
11637 if (res) {
11638 send_resp(dut, conn, SIGMA_ERROR,
11639 "ErrorCode,Failed to set short TPK "
11640 "lifetime");
11641 return 0;
11642 }
11643 }
11644
11645 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", sta);
11646 if (wpa_command(intf, buf) < 0) {
11647 send_resp(dut, conn, SIGMA_ERROR,
11648 "ErrorCode,Failed to send TDLS setup");
11649 return 0;
11650 }
11651 return 1;
11652 }
11653
11654 if (strcasecmp(val, "TEARDOWN") == 0) {
11655 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", sta);
11656 if (wpa_command(intf, buf) < 0) {
11657 send_resp(dut, conn, SIGMA_ERROR,
11658 "ErrorCode,Failed to send TDLS teardown");
11659 return 0;
11660 }
11661 return 1;
11662 }
11663
11664 send_resp(dut, conn, SIGMA_ERROR,
11665 "ErrorCode,Unsupported TDLS frame");
11666 return 0;
11667}
11668
11669
11670static int sta_ap_known(const char *ifname, const char *bssid)
11671{
11672 char buf[4096];
11673
Jouni Malinendd32f192018-09-15 02:55:19 +030011674 snprintf(buf, sizeof(buf), "BSS MASK=1 %s", bssid);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011675 if (wpa_command_resp(ifname, buf, buf, sizeof(buf)) < 0)
11676 return 0;
11677 if (strncmp(buf, "id=", 3) != 0)
11678 return 0;
11679 return 1;
11680}
11681
11682
11683static int sta_scan_ap(struct sigma_dut *dut, const char *ifname,
11684 const char *bssid)
11685{
11686 int res;
11687 struct wpa_ctrl *ctrl;
11688 char buf[256];
11689
11690 if (sta_ap_known(ifname, bssid))
11691 return 0;
11692 sigma_dut_print(dut, DUT_MSG_DEBUG,
11693 "AP not in BSS table - start scan");
11694
11695 ctrl = open_wpa_mon(ifname);
11696 if (ctrl == NULL) {
11697 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
11698 "wpa_supplicant monitor connection");
11699 return -1;
11700 }
11701
11702 if (wpa_command(ifname, "SCAN") < 0) {
11703 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to start scan");
11704 wpa_ctrl_detach(ctrl);
11705 wpa_ctrl_close(ctrl);
11706 return -1;
11707 }
11708
11709 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
11710 buf, sizeof(buf));
11711
11712 wpa_ctrl_detach(ctrl);
11713 wpa_ctrl_close(ctrl);
11714
11715 if (res < 0) {
11716 sigma_dut_print(dut, DUT_MSG_INFO, "Scan did not complete");
11717 return -1;
11718 }
11719
11720 if (sta_ap_known(ifname, bssid))
11721 return 0;
11722 sigma_dut_print(dut, DUT_MSG_INFO, "AP not in BSS table");
11723 return -1;
11724}
11725
11726
11727static int cmd_sta_send_frame_hs2_neighadv(struct sigma_dut *dut,
11728 struct sigma_conn *conn,
11729 struct sigma_cmd *cmd,
11730 const char *intf)
11731{
11732 char buf[200];
11733
11734 snprintf(buf, sizeof(buf), "ndsend 2001:DB8::1 %s", intf);
11735 if (system(buf) != 0) {
11736 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Failed to run "
11737 "ndsend");
11738 return 0;
11739 }
11740
11741 return 1;
11742}
11743
11744
11745static int cmd_sta_send_frame_hs2_neighsolreq(struct sigma_dut *dut,
11746 struct sigma_conn *conn,
11747 struct sigma_cmd *cmd,
11748 const char *intf)
11749{
11750 char buf[200];
11751 const char *ip = get_param(cmd, "SenderIP");
11752
Peng Xu26b356d2017-10-04 17:58:16 -070011753 if (!ip)
11754 return 0;
11755
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011756 snprintf(buf, sizeof(buf), "ndisc6 -nm %s %s -r 4", ip, intf);
11757 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11758 if (system(buf) == 0) {
11759 sigma_dut_print(dut, DUT_MSG_INFO,
11760 "Neighbor Solicitation got a response "
11761 "for %s@%s", ip, intf);
11762 }
11763
11764 return 1;
11765}
11766
11767
11768static int cmd_sta_send_frame_hs2_arpprobe(struct sigma_dut *dut,
11769 struct sigma_conn *conn,
11770 struct sigma_cmd *cmd,
11771 const char *ifname)
11772{
11773 char buf[200];
11774 const char *ip = get_param(cmd, "SenderIP");
11775
11776 if (ip == NULL) {
11777 send_resp(dut, conn, SIGMA_ERROR,
11778 "ErrorCode,Missing SenderIP parameter");
11779 return 0;
11780 }
11781 snprintf(buf, sizeof(buf), "arping -I %s -D %s -c 4", ifname, ip);
11782 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11783 if (system(buf) != 0) {
11784 sigma_dut_print(dut, DUT_MSG_INFO, "arping DAD got a response "
11785 "for %s@%s", ip, ifname);
11786 }
11787
11788 return 1;
11789}
11790
11791
11792static int cmd_sta_send_frame_hs2_arpannounce(struct sigma_dut *dut,
11793 struct sigma_conn *conn,
11794 struct sigma_cmd *cmd,
11795 const char *ifname)
11796{
11797 char buf[200];
11798 char ip[16];
11799 int s;
Peng Xub3756882017-10-04 14:39:09 -070011800 struct ifreq ifr;
11801 struct sockaddr_in saddr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011802
11803 s = socket(PF_INET, SOCK_DGRAM, 0);
Peng Xub3756882017-10-04 14:39:09 -070011804 if (s < 0) {
11805 perror("socket");
11806 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011807 }
11808
Peng Xub3756882017-10-04 14:39:09 -070011809 memset(&ifr, 0, sizeof(ifr));
11810 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
11811 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
11812 sigma_dut_print(dut, DUT_MSG_INFO,
11813 "Failed to get %s IP address: %s",
11814 ifname, strerror(errno));
11815 close(s);
11816 return -1;
11817 }
11818 close(s);
11819
11820 memcpy(&saddr, &ifr.ifr_addr, sizeof(struct sockaddr_in));
11821 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
11822
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011823 snprintf(buf, sizeof(buf), "arping -I %s -s %s %s -c 4", ifname, ip,
11824 ip);
11825 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11826 if (system(buf) != 0) {
11827 }
11828
11829 return 1;
11830}
11831
11832
11833static int cmd_sta_send_frame_hs2_arpreply(struct sigma_dut *dut,
11834 struct sigma_conn *conn,
11835 struct sigma_cmd *cmd,
11836 const char *ifname)
11837{
11838 char buf[200], addr[20];
11839 char dst[ETH_ALEN], src[ETH_ALEN];
11840 short ethtype = htons(ETH_P_ARP);
11841 char *pos;
11842 int s, res;
11843 const char *val;
11844 struct sockaddr_in taddr;
11845
11846 val = get_param(cmd, "dest");
11847 if (val)
11848 hwaddr_aton(val, (unsigned char *) dst);
11849
11850 val = get_param(cmd, "DestIP");
11851 if (val)
11852 inet_aton(val, &taddr.sin_addr);
Peng Xu151c9e12017-10-04 14:39:09 -070011853 else
11854 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011855
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011856 if (get_wpa_status(get_station_ifname(dut), "address", addr,
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011857 sizeof(addr)) < 0)
11858 return -2;
11859 hwaddr_aton(addr, (unsigned char *) src);
11860
11861 pos = buf;
11862 *pos++ = 0x00;
11863 *pos++ = 0x01;
11864 *pos++ = 0x08;
11865 *pos++ = 0x00;
11866 *pos++ = 0x06;
11867 *pos++ = 0x04;
11868 *pos++ = 0x00;
11869 *pos++ = 0x02;
11870 memcpy(pos, src, ETH_ALEN);
11871 pos += ETH_ALEN;
11872 memcpy(pos, &taddr.sin_addr, 4);
11873 pos += 4;
11874 memcpy(pos, dst, ETH_ALEN);
11875 pos += ETH_ALEN;
11876 memcpy(pos, &taddr.sin_addr, 4);
11877 pos += 4;
11878
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011879 s = open_monitor(get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011880 if (s < 0) {
11881 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
11882 "monitor socket");
11883 return 0;
11884 }
11885
11886 res = inject_eth_frame(s, buf, pos - buf, ethtype, dst, src);
11887 if (res < 0) {
11888 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
11889 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +053011890 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011891 return 0;
11892 }
11893
11894 close(s);
11895
11896 return 1;
11897}
11898
11899
11900static int cmd_sta_send_frame_hs2_dls_req(struct sigma_dut *dut,
11901 struct sigma_conn *conn,
11902 struct sigma_cmd *cmd,
11903 const char *intf, const char *dest)
11904{
11905 char buf[100];
11906
11907 if (if_nametoindex("sigmadut") == 0) {
11908 snprintf(buf, sizeof(buf),
11909 "iw dev %s interface add sigmadut type monitor",
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011910 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011911 if (system(buf) != 0 ||
11912 if_nametoindex("sigmadut") == 0) {
11913 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
11914 "monitor interface with '%s'", buf);
11915 return -2;
11916 }
11917 }
11918
11919 if (system("ifconfig sigmadut up") != 0) {
11920 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
11921 "monitor interface up");
11922 return -2;
11923 }
11924
Veerendranath Jakkam49774122020-07-05 09:52:18 +053011925 return sta_inject_frame(dut, conn, intf, DLS_REQ, UNPROTECTED, dest, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011926}
11927
11928
11929static int cmd_sta_send_frame_hs2(struct sigma_dut *dut,
11930 struct sigma_conn *conn,
11931 struct sigma_cmd *cmd)
11932{
11933 const char *intf = get_param(cmd, "Interface");
11934 const char *dest = get_param(cmd, "Dest");
11935 const char *type = get_param(cmd, "FrameName");
11936 const char *val;
11937 char buf[200], *pos, *end;
11938 int count, count2;
11939
11940 if (type == NULL)
11941 type = get_param(cmd, "Type");
11942
11943 if (intf == NULL || dest == NULL || type == NULL)
11944 return -1;
11945
11946 if (strcasecmp(type, "NeighAdv") == 0)
11947 return cmd_sta_send_frame_hs2_neighadv(dut, conn, cmd, intf);
11948
11949 if (strcasecmp(type, "NeighSolicitReq") == 0)
11950 return cmd_sta_send_frame_hs2_neighsolreq(dut, conn, cmd, intf);
11951
11952 if (strcasecmp(type, "ARPProbe") == 0)
11953 return cmd_sta_send_frame_hs2_arpprobe(dut, conn, cmd, intf);
11954
11955 if (strcasecmp(type, "ARPAnnounce") == 0)
11956 return cmd_sta_send_frame_hs2_arpannounce(dut, conn, cmd, intf);
11957
11958 if (strcasecmp(type, "ARPReply") == 0)
11959 return cmd_sta_send_frame_hs2_arpreply(dut, conn, cmd, intf);
11960
11961 if (strcasecmp(type, "DLS-request") == 0 ||
11962 strcasecmp(type, "DLSrequest") == 0)
11963 return cmd_sta_send_frame_hs2_dls_req(dut, conn, cmd, intf,
11964 dest);
11965
11966 if (strcasecmp(type, "ANQPQuery") != 0 &&
11967 strcasecmp(type, "Query") != 0) {
11968 send_resp(dut, conn, SIGMA_ERROR,
11969 "ErrorCode,Unsupported HS 2.0 send frame type");
11970 return 0;
11971 }
11972
11973 if (sta_scan_ap(dut, intf, dest) < 0) {
11974 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not find "
11975 "the requested AP");
11976 return 0;
11977 }
11978
11979 pos = buf;
11980 end = buf + sizeof(buf);
11981 count = 0;
11982 pos += snprintf(pos, end - pos, "ANQP_GET %s ", dest);
11983
11984 val = get_param(cmd, "ANQP_CAP_LIST");
11985 if (val && atoi(val)) {
11986 pos += snprintf(pos, end - pos, "%s257", count > 0 ? "," : "");
11987 count++;
11988 }
11989
11990 val = get_param(cmd, "VENUE_NAME");
11991 if (val && atoi(val)) {
11992 pos += snprintf(pos, end - pos, "%s258", count > 0 ? "," : "");
11993 count++;
11994 }
11995
11996 val = get_param(cmd, "NETWORK_AUTH_TYPE");
11997 if (val && atoi(val)) {
11998 pos += snprintf(pos, end - pos, "%s260", count > 0 ? "," : "");
11999 count++;
12000 }
12001
12002 val = get_param(cmd, "ROAMING_CONS");
12003 if (val && atoi(val)) {
12004 pos += snprintf(pos, end - pos, "%s261", count > 0 ? "," : "");
12005 count++;
12006 }
12007
12008 val = get_param(cmd, "IP_ADDR_TYPE_AVAILABILITY");
12009 if (val && atoi(val)) {
12010 pos += snprintf(pos, end - pos, "%s262", count > 0 ? "," : "");
12011 count++;
12012 }
12013
12014 val = get_param(cmd, "NAI_REALM_LIST");
12015 if (val && atoi(val)) {
12016 pos += snprintf(pos, end - pos, "%s263", count > 0 ? "," : "");
12017 count++;
12018 }
12019
12020 val = get_param(cmd, "3GPP_INFO");
12021 if (val && atoi(val)) {
12022 pos += snprintf(pos, end - pos, "%s264", count > 0 ? "," : "");
12023 count++;
12024 }
12025
12026 val = get_param(cmd, "DOMAIN_LIST");
12027 if (val && atoi(val)) {
12028 pos += snprintf(pos, end - pos, "%s268", count > 0 ? "," : "");
12029 count++;
12030 }
12031
Jouni Malinen34cf9532018-04-29 19:26:33 +030012032 val = get_param(cmd, "Venue_URL");
12033 if (val && atoi(val)) {
12034 pos += snprintf(pos, end - pos, "%s277", count > 0 ? "," : "");
12035 count++;
12036 }
12037
Jouni Malinend3bca5d2018-04-29 17:25:23 +030012038 val = get_param(cmd, "Advice_Of_Charge");
12039 if (val && atoi(val)) {
12040 pos += snprintf(pos, end - pos, "%s278", count > 0 ? "," : "");
12041 count++;
12042 }
12043
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012044 if (count && wpa_command(intf, buf)) {
12045 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,ANQP_GET failed");
12046 return 0;
12047 }
12048
12049 pos = buf;
12050 end = buf + sizeof(buf);
12051 count2 = 0;
12052 pos += snprintf(pos, end - pos, "HS20_ANQP_GET %s ", dest);
12053
12054 val = get_param(cmd, "HS_CAP_LIST");
12055 if (val && atoi(val)) {
12056 pos += snprintf(pos, end - pos, "%s2", count2 > 0 ? "," : "");
12057 count2++;
12058 }
12059
12060 val = get_param(cmd, "OPER_NAME");
12061 if (val && atoi(val)) {
12062 pos += snprintf(pos, end - pos, "%s3", count2 > 0 ? "," : "");
12063 count2++;
12064 }
12065
12066 val = get_param(cmd, "WAN_METRICS");
12067 if (!val)
12068 val = get_param(cmd, "WAN_MAT");
12069 if (!val)
12070 val = get_param(cmd, "WAN_MET");
12071 if (val && atoi(val)) {
12072 pos += snprintf(pos, end - pos, "%s4", count2 > 0 ? "," : "");
12073 count2++;
12074 }
12075
12076 val = get_param(cmd, "CONNECTION_CAPABILITY");
12077 if (val && atoi(val)) {
12078 pos += snprintf(pos, end - pos, "%s5", count2 > 0 ? "," : "");
12079 count2++;
12080 }
12081
12082 val = get_param(cmd, "OP_CLASS");
12083 if (val && atoi(val)) {
12084 pos += snprintf(pos, end - pos, "%s7", count2 > 0 ? "," : "");
12085 count2++;
12086 }
12087
12088 val = get_param(cmd, "OSU_PROVIDER_LIST");
12089 if (val && atoi(val)) {
12090 pos += snprintf(pos, end - pos, "%s8", count2 > 0 ? "," : "");
12091 count2++;
12092 }
12093
Jouni Malinenf67afec2018-04-29 19:24:58 +030012094 val = get_param(cmd, "OPER_ICON_METADATA");
12095 if (!val)
12096 val = get_param(cmd, "OPERATOR_ICON_METADATA");
12097 if (val && atoi(val)) {
12098 pos += snprintf(pos, end - pos, "%s12", count2 > 0 ? "," : "");
12099 count2++;
12100 }
12101
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012102 if (count && count2) {
12103 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before sending out "
12104 "second query");
12105 sleep(1);
12106 }
12107
12108 if (count2 && wpa_command(intf, buf)) {
12109 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,HS20_ANQP_GET "
12110 "failed");
12111 return 0;
12112 }
12113
12114 val = get_param(cmd, "NAI_HOME_REALM_LIST");
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 if (strcmp(val, "1") == 0)
12123 val = "mail.example.com";
12124 snprintf(buf, end - pos,
12125 "HS20_GET_NAI_HOME_REALM_LIST %s realm=%s",
12126 dest, val);
12127 if (wpa_command(intf, buf)) {
12128 send_resp(dut, conn, SIGMA_ERROR,
12129 "ErrorCode,HS20_GET_NAI_HOME_REALM_LIST "
12130 "failed");
12131 return 0;
12132 }
12133 }
12134
12135 val = get_param(cmd, "ICON_REQUEST");
12136 if (val) {
12137 if (count || count2) {
12138 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
12139 "sending out second query");
12140 sleep(1);
12141 }
12142
12143 snprintf(buf, end - pos,
12144 "HS20_ICON_REQUEST %s %s", dest, val);
12145 if (wpa_command(intf, buf)) {
12146 send_resp(dut, conn, SIGMA_ERROR,
12147 "ErrorCode,HS20_ICON_REQUEST failed");
12148 return 0;
12149 }
12150 }
12151
12152 return 1;
12153}
12154
12155
12156static int ath_sta_send_frame_vht(struct sigma_dut *dut,
12157 struct sigma_conn *conn,
12158 struct sigma_cmd *cmd)
12159{
12160 const char *val;
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012161 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012162 int chwidth, nss;
12163
12164 val = get_param(cmd, "framename");
12165 if (!val)
12166 return -1;
12167 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
12168
12169 /* Command sequence to generate Op mode notification */
12170 if (val && strcasecmp(val, "Op_md_notif_frm") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012171 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012172
12173 /* Disable STBC */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012174 run_iwpriv(dut, ifname, "tx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012175
12176 /* Extract Channel width */
12177 val = get_param(cmd, "Channel_width");
12178 if (val) {
12179 switch (atoi(val)) {
12180 case 20:
12181 chwidth = 0;
12182 break;
12183 case 40:
12184 chwidth = 1;
12185 break;
12186 case 80:
12187 chwidth = 2;
12188 break;
12189 case 160:
12190 chwidth = 3;
12191 break;
12192 default:
12193 chwidth = 2;
12194 break;
12195 }
12196
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012197 run_iwpriv(dut, ifname, "chwidth %d", chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012198 }
12199
12200 /* Extract NSS */
12201 val = get_param(cmd, "NSS");
12202 if (val) {
12203 switch (atoi(val)) {
12204 case 1:
12205 nss = 1;
12206 break;
12207 case 2:
12208 nss = 3;
12209 break;
12210 case 3:
12211 nss = 7;
12212 break;
12213 default:
12214 /* We do not support NSS > 3 */
12215 nss = 3;
12216 break;
12217 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012218 run_iwpriv(dut, ifname, "rxchainmask %d", nss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012219 }
12220
12221 /* Opmode notify */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012222 run_iwpriv(dut, ifname, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012223 }
12224
12225 return 1;
12226}
12227
12228
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070012229static int wcn_sta_set_pmf_config(struct sigma_dut *dut, const char *intf,
12230 enum send_frame_protection protected)
12231{
12232#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +053012233 return wcn_wifi_test_config_set_u8(
12234 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_PMF_PROTECTION,
12235 protected);
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070012236#else /* NL80211_SUPPORT */
12237 sigma_dut_print(dut, DUT_MSG_ERROR,
12238 "PMF config cannot be set without NL80211_SUPPORT defined");
12239 return -1;
12240#endif /* NL80211_SUPPORT */
12241}
12242
12243
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012244static int cmd_sta_send_frame_vht(struct sigma_dut *dut,
12245 struct sigma_conn *conn,
12246 struct sigma_cmd *cmd)
12247{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012248 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012249 case DRIVER_ATHEROS:
12250 return ath_sta_send_frame_vht(dut, conn, cmd);
12251 default:
12252 send_resp(dut, conn, SIGMA_ERROR,
12253 "errorCode,Unsupported sta_set_frame(VHT) with the current driver");
12254 return 0;
12255 }
12256}
12257
12258
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070012259static int wcn_sta_send_disassoc(struct sigma_dut *dut, const char *intf)
12260{
12261#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +053012262 return wcn_wifi_test_config_set_flag(
12263 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_DISASSOC_TX);
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070012264#else /* NL80211_SUPPORT */
12265 sigma_dut_print(dut, DUT_MSG_ERROR,
12266 "Disassoc Tx cannot be done without NL80211_SUPPORT defined");
12267 return -1;
12268#endif /* NL80211_SUPPORT */
12269}
12270
12271
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070012272static int wcn_sta_send_frame_he(struct sigma_dut *dut, struct sigma_conn *conn,
12273 struct sigma_cmd *cmd)
12274{
12275 const char *val;
12276 const char *intf = get_param(cmd, "Interface");
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070012277 enum send_frame_protection protected;
12278 const char *pmf;
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070012279
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030012280 if (!intf)
12281 return -1;
12282
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070012283 val = get_param(cmd, "framename");
12284 if (!val)
12285 return -1;
12286 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
12287
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070012288 pmf = get_param(cmd, "PMFProtected");
12289 if (!pmf)
12290 pmf = get_param(cmd, "Protected");
12291 if (pmf) {
12292 if (strcasecmp(pmf, "Correct-key") == 0 ||
12293 strcasecmp(pmf, "CorrectKey") == 0) {
12294 protected = CORRECT_KEY;
12295 } else if (strcasecmp(pmf, "IncorrectKey") == 0) {
12296 protected = INCORRECT_KEY;
12297 } else if (strcasecmp(pmf, "Unprotected") == 0) {
12298 protected = UNPROTECTED;
12299 } else {
12300 send_resp(dut, conn, SIGMA_ERROR,
12301 "errorCode,Unsupported PMFProtected");
12302 return STATUS_SENT_ERROR;
12303 }
12304 sigma_dut_print(dut, DUT_MSG_DEBUG, "Config PMF protection %d",
12305 protected);
12306 wcn_sta_set_pmf_config(dut, intf, protected);
12307 }
12308
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070012309 /* Command sequence to generate Op mode notification */
12310 if (val && strcasecmp(val, "action") == 0) {
12311 val = get_param(cmd, "PPDUTxType");
12312 if (val && strcasecmp(val, "TB") == 0) {
12313 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 1)) {
12314 sigma_dut_print(dut, DUT_MSG_ERROR,
12315 "failed to send TB PPDU Tx cfg");
12316 send_resp(dut, conn, SIGMA_ERROR,
12317 "ErrorCode,set TB PPDU Tx cfg failed");
12318 return 0;
12319 }
12320 return 1;
12321 }
12322
12323 sigma_dut_print(dut, DUT_MSG_ERROR,
12324 "Action Tx type is not defined");
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070012325
12326 return SUCCESS_SEND_STATUS;
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070012327 }
12328
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070012329 if (strcasecmp(val, "disassoc") == 0)
12330 wcn_sta_send_disassoc(dut, intf);
12331
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070012332 return 1;
12333}
12334
12335
12336static int cmd_sta_send_frame_he(struct sigma_dut *dut,
12337 struct sigma_conn *conn,
12338 struct sigma_cmd *cmd)
12339{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012340 switch (get_driver_type(dut)) {
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070012341 case DRIVER_WCN:
12342 return wcn_sta_send_frame_he(dut, conn, cmd);
12343 default:
12344 send_resp(dut, conn, SIGMA_ERROR,
12345 "errorCode,Unsupported sta_set_frame(HE) with the current driver");
12346 return 0;
12347 }
12348}
12349
12350
Lior David0fe101e2017-03-09 16:09:50 +020012351#ifdef __linux__
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030012352
12353static int
12354wil6210_send_p2p_frame_60g(struct sigma_dut *dut, struct sigma_cmd *cmd,
12355 const char *frame_name, const char *dest_mac)
12356{
12357 int isprobereq = strcasecmp(frame_name, "probereq") == 0;
12358 const char *ssid = get_param(cmd, "ssid");
12359 const char *countstr = get_param(cmd, "count");
12360 const char *channelstr = get_param(cmd, "channel");
12361 const char *group_id = get_param(cmd, "groupid");
12362 const char *client_id = get_param(cmd, "clientmac");
12363 int count, channel, freq, i;
12364 const char *fname;
12365 char frame[1024], src_mac[20], group_id_attr[25],
12366 device_macstr[3 * ETH_ALEN], client_mac[ETH_ALEN];
12367 const char *group_ssid;
12368 const int group_ssid_prefix_len = 9;
12369 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *) frame;
12370 size_t framelen = sizeof(frame);
12371 struct template_frame_tag tags[2];
12372 size_t tags_total = ARRAY_SIZE(tags);
12373 int tag_index, len, dst_len;
12374
12375 if (!countstr || !channelstr) {
12376 sigma_dut_print(dut, DUT_MSG_ERROR,
12377 "Missing argument: count, channel");
12378 return -1;
12379 }
12380 if (isprobereq && !ssid) {
12381 sigma_dut_print(dut, DUT_MSG_ERROR,
12382 "Missing argument: ssid");
12383 return -1;
12384 }
12385 if (!isprobereq && (!group_id || !client_id)) {
12386 sigma_dut_print(dut, DUT_MSG_ERROR,
12387 "Missing argument: group_id, client_id");
12388 return -1;
12389 }
12390
12391 count = atoi(countstr);
12392 channel = atoi(channelstr);
12393 freq = channel_to_freq(dut, channel);
12394
12395 if (!freq) {
12396 sigma_dut_print(dut, DUT_MSG_ERROR,
12397 "invalid channel: %s", channelstr);
12398 return -1;
12399 }
12400
12401 if (isprobereq) {
12402 if (strcasecmp(ssid, "wildcard") == 0) {
12403 fname = "probe_req_wildcard.txt";
12404 } else if (strcasecmp(ssid, "P2P_Wildcard") == 0) {
12405 fname = "probe_req_P2P_Wildcard.txt";
12406 } else {
12407 sigma_dut_print(dut, DUT_MSG_ERROR,
12408 "invalid probe request type");
12409 return -1;
12410 }
12411 } else {
12412 fname = "P2P_device_discovery_req.txt";
12413 }
12414
12415 if (parse_template_frame_file(dut, fname, frame, &framelen,
12416 tags, &tags_total)) {
12417 sigma_dut_print(dut, DUT_MSG_ERROR,
12418 "invalid frame template: %s", fname);
12419 return -1;
12420 }
12421
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012422 if (get_wpa_status(get_station_ifname(dut), "address",
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030012423 src_mac, sizeof(src_mac)) < 0 ||
12424 parse_mac_address(dut, src_mac, &hdr->addr2[0]) ||
12425 parse_mac_address(dut, dest_mac, &hdr->addr1[0]))
12426 return -1;
12427 /* Use wildcard BSSID, since we are in PBSS */
12428 memset(&hdr->addr3, 0xFF, ETH_ALEN);
12429
12430 if (!isprobereq) {
12431 tag_index = find_template_frame_tag(tags, tags_total, 1);
12432 if (tag_index < 0) {
12433 sigma_dut_print(dut, DUT_MSG_ERROR,
12434 "can't find device id attribute");
12435 return -1;
12436 }
12437 if (parse_mac_address(dut, client_id,
12438 (unsigned char *) client_mac)) {
12439 sigma_dut_print(dut, DUT_MSG_ERROR,
12440 "invalid client_id: %s", client_id);
12441 return -1;
12442 }
12443 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
12444 framelen - tags[tag_index].offset,
12445 IEEE80211_P2P_ATTR_DEVICE_ID,
12446 client_mac, ETH_ALEN)) {
12447 sigma_dut_print(dut, DUT_MSG_ERROR,
12448 "fail to replace device id attribute");
12449 return -1;
12450 }
12451
12452 /*
12453 * group_id arg contains device MAC address followed by
12454 * space and SSID (DIRECT-somessid).
12455 * group id attribute contains device address (6 bytes)
12456 * followed by SSID prefix DIRECT-XX (9 bytes)
12457 */
12458 if (strlen(group_id) < sizeof(device_macstr)) {
12459 sigma_dut_print(dut, DUT_MSG_ERROR,
12460 "group_id arg too short");
12461 return -1;
12462 }
12463 memcpy(device_macstr, group_id, sizeof(device_macstr));
12464 device_macstr[sizeof(device_macstr) - 1] = '\0';
12465 if (parse_mac_address(dut, device_macstr,
12466 (unsigned char *) group_id_attr)) {
12467 sigma_dut_print(dut, DUT_MSG_ERROR,
12468 "fail to parse device address from group_id");
12469 return -1;
12470 }
12471 group_ssid = strchr(group_id, ' ');
12472 if (!group_ssid) {
12473 sigma_dut_print(dut, DUT_MSG_ERROR,
12474 "invalid group_id arg, no ssid");
12475 return -1;
12476 }
12477 group_ssid++;
12478 len = strlen(group_ssid);
12479 if (len < group_ssid_prefix_len) {
12480 sigma_dut_print(dut, DUT_MSG_ERROR,
12481 "group_id SSID too short");
12482 return -1;
12483 }
12484 dst_len = sizeof(group_id_attr) - ETH_ALEN;
12485 if (len > dst_len) {
12486 sigma_dut_print(dut, DUT_MSG_ERROR,
12487 "group_id SSID (%s) too long",
12488 group_ssid);
12489 return -1;
12490 }
12491
12492 memcpy(group_id_attr + ETH_ALEN, group_ssid, len);
12493 tag_index = find_template_frame_tag(tags, tags_total, 2);
12494 if (tag_index < 0) {
12495 sigma_dut_print(dut, DUT_MSG_ERROR,
12496 "can't find group id attribute");
12497 return -1;
12498 }
12499 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
12500 framelen - tags[tag_index].offset,
12501 IEEE80211_P2P_ATTR_GROUP_ID,
12502 group_id_attr,
12503 sizeof(group_id_attr))) {
12504 sigma_dut_print(dut, DUT_MSG_ERROR,
12505 "fail to replace group id attribute");
12506 return -1;
12507 }
12508 }
12509
12510 for (i = 0; i < count; i++) {
12511 if (wil6210_transmit_frame(dut, freq,
12512 WIL_TRANSMIT_FRAME_DEFAULT_ROC,
12513 frame, framelen)) {
12514 sigma_dut_print(dut, DUT_MSG_ERROR,
12515 "fail to transmit probe request frame");
12516 return -1;
12517 }
12518 }
12519
12520 return 0;
12521}
12522
12523
Lior David0fe101e2017-03-09 16:09:50 +020012524int wil6210_send_frame_60g(struct sigma_dut *dut, struct sigma_conn *conn,
12525 struct sigma_cmd *cmd)
12526{
12527 const char *frame_name = get_param(cmd, "framename");
12528 const char *mac = get_param(cmd, "dest_mac");
12529
12530 if (!frame_name || !mac) {
12531 sigma_dut_print(dut, DUT_MSG_ERROR,
12532 "framename and dest_mac must be provided");
12533 return -1;
12534 }
12535
12536 if (strcasecmp(frame_name, "brp") == 0) {
12537 const char *l_rx = get_param(cmd, "L-RX");
12538 int l_rx_i;
12539
12540 if (!l_rx) {
12541 sigma_dut_print(dut, DUT_MSG_ERROR,
12542 "L-RX must be provided");
12543 return -1;
12544 }
12545 l_rx_i = atoi(l_rx);
12546
12547 sigma_dut_print(dut, DUT_MSG_INFO,
12548 "dev_send_frame: BRP-RX, dest_mac %s, L-RX %s",
12549 mac, l_rx);
12550 if (l_rx_i != 16) {
12551 sigma_dut_print(dut, DUT_MSG_ERROR,
12552 "unsupported L-RX: %s", l_rx);
12553 return -1;
12554 }
12555
12556 if (wil6210_send_brp_rx(dut, mac, l_rx_i))
12557 return -1;
12558 } else if (strcasecmp(frame_name, "ssw") == 0) {
12559 sigma_dut_print(dut, DUT_MSG_INFO,
12560 "dev_send_frame: SLS, dest_mac %s", mac);
12561 if (wil6210_send_sls(dut, mac))
12562 return -1;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030012563 } else if ((strcasecmp(frame_name, "probereq") == 0) ||
12564 (strcasecmp(frame_name, "devdiscreq") == 0)) {
12565 sigma_dut_print(dut, DUT_MSG_INFO,
12566 "dev_send_frame: %s, dest_mac %s", frame_name,
12567 mac);
12568 if (wil6210_send_p2p_frame_60g(dut, cmd, frame_name, mac))
12569 return -1;
Lior David0fe101e2017-03-09 16:09:50 +020012570 } else {
12571 sigma_dut_print(dut, DUT_MSG_ERROR,
12572 "unsupported frame type: %s", frame_name);
12573 return -1;
12574 }
12575
12576 return 1;
12577}
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030012578
Lior David0fe101e2017-03-09 16:09:50 +020012579#endif /* __linux__ */
12580
12581
12582static int cmd_sta_send_frame_60g(struct sigma_dut *dut,
12583 struct sigma_conn *conn,
12584 struct sigma_cmd *cmd)
12585{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012586 switch (get_driver_type(dut)) {
Lior David0fe101e2017-03-09 16:09:50 +020012587#ifdef __linux__
12588 case DRIVER_WIL6210:
12589 return wil6210_send_frame_60g(dut, conn, cmd);
12590#endif /* __linux__ */
12591 default:
12592 send_resp(dut, conn, SIGMA_ERROR,
12593 "errorCode,Unsupported sta_set_frame(60G) with the current driver");
12594 return 0;
12595 }
12596}
12597
12598
Ashwini Patildb59b3c2017-04-13 15:19:23 +053012599static int mbo_send_anqp_query(struct sigma_dut *dut, struct sigma_conn *conn,
12600 const char *intf, struct sigma_cmd *cmd)
12601{
12602 const char *val, *addr;
12603 char buf[100];
12604
12605 addr = get_param(cmd, "DestMac");
12606 if (!addr) {
12607 send_resp(dut, conn, SIGMA_INVALID,
12608 "ErrorCode,AP MAC address is missing");
12609 return 0;
12610 }
12611
12612 val = get_param(cmd, "ANQPQuery_ID");
12613 if (!val) {
12614 send_resp(dut, conn, SIGMA_INVALID,
12615 "ErrorCode,Missing ANQPQuery_ID");
12616 return 0;
12617 }
12618
12619 if (strcasecmp(val, "NeighborReportReq") == 0) {
12620 snprintf(buf, sizeof(buf), "ANQP_GET %s 272", addr);
12621 } else if (strcasecmp(val, "QueryListWithCellPref") == 0) {
12622 snprintf(buf, sizeof(buf), "ANQP_GET %s 272,mbo:2", addr);
12623 } else {
12624 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid ANQPQuery_ID: %s",
12625 val);
12626 send_resp(dut, conn, SIGMA_INVALID,
12627 "ErrorCode,Invalid ANQPQuery_ID");
12628 return 0;
12629 }
12630
Ashwini Patild174f2c2017-04-13 16:49:46 +053012631 /* Set gas_address3 field to IEEE 802.11-2012 standard compliant form
12632 * (Address3 = Wildcard BSSID when sent to not-associated AP;
12633 * if associated, AP BSSID).
12634 */
12635 if (wpa_command(intf, "SET gas_address3 1") < 0) {
12636 send_resp(dut, conn, SIGMA_ERROR,
12637 "ErrorCode,Failed to set gas_address3");
12638 return 0;
12639 }
12640
Ashwini Patildb59b3c2017-04-13 15:19:23 +053012641 if (wpa_command(intf, buf) < 0) {
12642 send_resp(dut, conn, SIGMA_ERROR,
12643 "ErrorCode,Failed to send ANQP query");
12644 return 0;
12645 }
12646
12647 return 1;
12648}
12649
12650
12651static int mbo_cmd_sta_send_frame(struct sigma_dut *dut,
12652 struct sigma_conn *conn,
12653 const char *intf,
12654 struct sigma_cmd *cmd)
12655{
12656 const char *val = get_param(cmd, "FrameName");
12657
12658 if (val && strcasecmp(val, "ANQPQuery") == 0)
12659 return mbo_send_anqp_query(dut, conn, intf, cmd);
12660
12661 return 2;
12662}
12663
12664
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053012665static enum sigma_cmd_result cmd_sta_send_frame_wpa3(struct sigma_dut *dut,
12666 struct sigma_conn *conn,
12667 const char *intf,
12668 struct sigma_cmd *cmd)
12669{
12670 const char *val = get_param(cmd, "framename");
12671
12672 if (!val)
12673 return INVALID_SEND_STATUS;
12674
12675 if (strcasecmp(val, "SAQueryReq") == 0) {
12676 val = get_param(cmd, "OCIChannel");
12677
12678 if (!val) {
12679 send_resp(dut, conn, SIGMA_ERROR,
12680 "errorCode,OCIChannel not present");
12681 return STATUS_SENT_ERROR;
12682 }
12683
12684 dut->saquery_oci_freq = channel_to_freq(dut, atoi(val));
12685 if (!dut->saquery_oci_freq) {
12686 send_resp(dut, conn, SIGMA_ERROR,
12687 "errorCode,Invalid OCIChannel number");
12688 return STATUS_SENT_ERROR;
12689 }
12690
12691 return sta_inject_frame(dut, conn, intf, SAQUERY, CORRECT_KEY,
12692 NULL, 0);
12693 }
12694
12695 if (strcasecmp(val, "reassocreq") == 0)
12696 return sta_inject_frame(dut, conn, intf, REASSOCREQ,
12697 CORRECT_KEY, NULL, 0);
12698
Veerendranath9f81dfb2020-08-10 01:21:29 -070012699 if (strcasecmp(val, "ANQPQuery") == 0) {
12700 char buf[50];
12701 const char *dest = get_param(cmd, "DestMac");
12702 const char *chan = get_param(cmd, "channel");
Veerendranath Jakkam78862fc2020-11-19 21:23:27 +053012703 const char *freq_str = get_param(cmd, "ChnlFreq");
Veerendranath9f81dfb2020-08-10 01:21:29 -070012704 int len, freq;
12705
Veerendranath Jakkam78862fc2020-11-19 21:23:27 +053012706 if (freq_str)
12707 freq = atoi(freq_str);
12708 else
12709 freq = chan ? channel_to_freq(dut, atoi(chan)) : 0;
12710
Veerendranath9f81dfb2020-08-10 01:21:29 -070012711 if (!dest || !freq)
12712 return INVALID_SEND_STATUS;
12713
12714 len = snprintf(buf, sizeof(buf), "ANQP_GET %s freq=%d 257",
12715 dest, freq);
12716 if (len < 0 || len >= sizeof(buf)) {
12717 sigma_dut_print(dut, DUT_MSG_ERROR,
12718 "Failed to allocate buf");
12719 return ERROR_SEND_STATUS;
12720 }
12721
12722 if (wpa_command(intf, buf) != 0) {
12723 send_resp(dut, conn, SIGMA_ERROR,
12724 "ErrorCode,Failed to send ANQP Query frame");
12725 return STATUS_SENT_ERROR;
12726 }
12727
12728 sigma_dut_print(dut, DUT_MSG_DEBUG,
12729 "ANQP Query sent: %s", buf);
12730
12731 return SUCCESS_SEND_STATUS;
12732 }
12733
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053012734 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported framename");
12735 return STATUS_SENT_ERROR;
12736}
12737
12738
Vinita S. Malooca85fd22021-01-15 02:54:34 +053012739static int
12740get_type4_frame_classifier(struct sigma_dut *dut, struct sigma_cmd *cmd,
12741 char *pos, int rem_len, int num_of_scs_desc,
12742 int num_of_tclas_elem)
12743{
12744 const char *val;
12745 int ipv6;
12746 int len, total_len = 0;
12747
12748 val = get_param_fmt(cmd, "TCLASElem_Version_%d_%d", num_of_scs_desc,
12749 num_of_tclas_elem);
12750 if (!val) {
12751 sigma_dut_print(dut, DUT_MSG_ERROR, "%s: ip_version empty",
12752 __func__);
12753 return -1;
12754 }
12755
12756 if (strcmp(val, "6") == 0) {
12757 ipv6 = 1;
12758 } else if (strcmp(val, "4") == 0) {
12759 ipv6 = 0;
12760 } else {
12761 sigma_dut_print(dut, DUT_MSG_ERROR, "%s: ip_version invalid",
12762 __func__);
12763 return -1;
12764 }
12765
12766 len = snprintf(pos, rem_len, " ip_version=%s", ipv6 ? "ipv6" : "ipv4");
12767 if (len < 0 || len >= rem_len)
12768 return -1;
12769
12770 pos += len;
12771 rem_len -= len;
12772 total_len += len;
12773
12774 val = get_param_fmt(cmd, "TCLASElem_SourceIPAddr_%d_%d",
12775 num_of_scs_desc, num_of_tclas_elem);
12776 if (val) {
12777 len = snprintf(pos, rem_len, " src_ip=%s", val);
12778 if (len < 0 || len >= rem_len)
12779 return -1;
12780
12781 pos += len;
12782 rem_len -= len;
12783 total_len += len;
12784 }
12785
12786 val = get_param_fmt(cmd, "TCLASElem_DestinationIPAddr_%d_%d",
12787 num_of_scs_desc, num_of_tclas_elem);
12788 if (val) {
12789 len = snprintf(pos, rem_len, " dst_ip=%s", val);
12790 if (len < 0 || len >= rem_len)
12791 return -1;
12792
12793 pos += len;
12794 rem_len -= len;
12795 total_len += len;
12796 }
12797
12798 val = get_param_fmt(cmd, "TCLASElem_SourcePort_%d_%d", num_of_scs_desc,
12799 num_of_tclas_elem);
12800 if (val) {
12801 len = snprintf(pos, rem_len, " src_port=%s", val);
12802 if (len < 0 || len >= rem_len)
12803 return -1;
12804
12805 pos += len;
12806 rem_len -= len;
12807 total_len += len;
12808 }
12809
12810 val = get_param_fmt(cmd, "TCLASElem_DestinationPort_%d_%d",
12811 num_of_scs_desc, num_of_tclas_elem);
12812 if (val) {
12813 len = snprintf(pos, rem_len, " dst_port=%s", val);
12814 if (len < 0 || len >= rem_len)
12815 return -1;
12816
12817 pos += len;
12818 rem_len -= len;
12819 total_len += len;
12820 }
12821
12822 val = get_param_fmt(cmd, "TCLASElem_DSCP_%d_%d", num_of_scs_desc,
12823 num_of_tclas_elem);
12824 if (val) {
12825 len = snprintf(pos, rem_len, " dscp=%s", val);
12826 if (len < 0 || len >= rem_len)
12827 return -1;
12828
12829 pos += len;
12830 rem_len -= len;
12831 total_len += len;
12832 }
12833
12834 val = get_param_fmt(cmd, "TCLASElem_ProtocolNxtHeader_%d_%d",
12835 num_of_scs_desc, num_of_tclas_elem);
12836 if (val) {
12837 char *prot;
12838
12839 switch (atoi(val)) {
12840 case 17:
12841 prot = "udp";
12842 break;
12843 case 6:
12844 prot = "tcp";
12845 break;
12846 case 50:
12847 prot = "esp";
12848 break;
12849 default:
12850 sigma_dut_print(dut, DUT_MSG_ERROR,
12851 "Invalid protocol %d", atoi(val));
12852 return -1;
12853 }
12854
12855 if (ipv6)
12856 len = snprintf(pos, rem_len, " next_header=%s", prot);
12857 else
12858 len = snprintf(pos, rem_len, " protocol=%s", prot);
12859 if (len < 0 || len >= rem_len)
12860 return -1;
12861
12862 pos += len;
12863 rem_len -= len;
12864 total_len += len;
12865 }
12866
12867 return total_len;
12868}
12869
12870
12871static int
12872get_type10_frame_classifier(struct sigma_dut *dut, struct sigma_cmd *cmd,
12873 char *pos, int rem_len, int num_of_scs_desc,
12874 int num_of_tclas_elem)
12875{
12876 const char *val;
12877 int len, total_len = 0;
12878
12879 val = get_param_fmt(cmd, "TCLASElem_ProtoInstance_%d_%d",
12880 num_of_scs_desc, num_of_tclas_elem);
12881 if (val) {
12882 len = snprintf(pos, rem_len, " prot_instance=%s",
12883 val);
12884 if (len < 0 || len >= rem_len)
12885 return -1;
12886
12887 pos += len;
12888 rem_len -= len;
12889 total_len += len;
12890 }
12891
12892 val = get_param_fmt(cmd, "TCLASElem_ProtoNumNextHeader_%d_%d",
12893 num_of_scs_desc, num_of_tclas_elem);
12894 if (val) {
12895 char *prot;
12896
12897 switch (atoi(val)) {
12898 case 17:
12899 prot = "udp";
12900 break;
12901 case 6:
12902 prot = "tcp";
12903 break;
12904 case 50:
12905 prot = "esp";
12906 break;
12907 default:
12908 sigma_dut_print(dut, DUT_MSG_ERROR,
12909 "Invalid protocol %d",
12910 atoi(val));
12911 return -1;
12912 }
12913
12914 len = snprintf(pos, rem_len, " prot_number=%s", prot);
12915 if (len < 0 || len >= rem_len)
12916 return -1;
12917
12918 pos += len;
12919 rem_len -= len;
12920 total_len += len;
12921 }
12922
12923 val = get_param_fmt(cmd, "TCLASElem_FilterValue_%d_%d",
12924 num_of_scs_desc, num_of_tclas_elem);
12925 if (val) {
12926 len = snprintf(pos, rem_len, " filter_value=%s", (val + 2));
12927 if (len < 0 || len >= rem_len)
12928 return -1;
12929
12930 pos += len;
12931 rem_len -= len;
12932 total_len += len;
12933 }
12934
12935 val = get_param_fmt(cmd, "TCLASElem_FilterMask_%d_%d", num_of_scs_desc,
12936 num_of_tclas_elem);
12937 if (val && strlen(val) >= 2) {
12938 len = snprintf(pos, rem_len, " filter_mask=%s", val + 2);
12939 if (len < 0 || len >= rem_len)
12940 return -1;
12941
12942 pos += len;
12943 rem_len -= len;
12944 total_len += len;
12945 }
12946
12947 return total_len;
12948}
12949
12950
12951static enum sigma_cmd_result
12952cmd_sta_send_frame_scs(struct sigma_dut *dut, struct sigma_conn *conn,
12953 const char *intf, struct sigma_cmd *cmd)
12954{
12955 char buf[4096], *pos;
12956 const char *val, *scs_id, *classifier_type;
12957 int len, rem_len, total_bytes;
12958 int num_of_scs_desc = 0, num_of_tclas_elem = 0;
12959
12960 scs_id = get_param(cmd, "SCSDescrElem_SCSID_1");
12961 if (!scs_id) {
12962 sigma_dut_print(dut, DUT_MSG_ERROR, "SCS ID empty");
12963 return INVALID_SEND_STATUS;
12964 }
12965
12966 rem_len = sizeof(buf);
12967 pos = buf;
12968
12969 len = snprintf(buf, sizeof(buf), "SCS");
12970 if (len < 0 || len > rem_len)
12971 goto fail;
12972
12973 pos += len;
12974 rem_len -= len;
12975
12976 while (scs_id) {
12977 num_of_scs_desc++;
12978
12979 val = get_param_fmt(cmd, "SCSDescrElem_RequestType_%d",
12980 num_of_scs_desc);
12981 if (!val)
12982 return INVALID_SEND_STATUS;
12983
12984 if (strcasecmp(val, "Add") == 0) {
12985 len = snprintf(pos, rem_len, " scs_id=%s add",
12986 scs_id);
12987 } else if (strcasecmp(val, "Change") == 0) {
12988 len = snprintf(pos, rem_len, " scs_id=%s change",
12989 scs_id);
12990 } else if (strcasecmp(val, "Remove") == 0) {
12991 len = snprintf(pos, rem_len, " scs_id=%s remove",
12992 scs_id);
12993 if (len < 0 || len >= rem_len)
12994 goto fail;
12995
12996 pos += len;
12997 rem_len -= len;
12998 goto scs_desc_end;
12999 } else {
13000 sigma_dut_print(dut, DUT_MSG_ERROR,
13001 "%s: request type - %s is invalid",
13002 __func__, val);
13003 return INVALID_SEND_STATUS;
13004 }
13005
13006 if (len < 0 || len >= rem_len)
13007 goto fail;
13008
13009 pos += len;
13010 rem_len -= len;
13011
13012 val = get_param_fmt(cmd, "IntraAccessCatElem_UP_%d",
13013 num_of_scs_desc);
13014 if (!val) {
13015 sigma_dut_print(dut, DUT_MSG_ERROR,
13016 "IntraAccess Priority empty");
13017 return INVALID_SEND_STATUS;
13018 }
13019
13020 len = snprintf(pos, rem_len, " scs_up=%s", val);
13021 if (len < 0 || len >= rem_len)
13022 goto fail;
13023
13024 pos += len;
13025 rem_len -= len;
13026
13027 classifier_type = get_param_fmt(cmd,
13028 "TCLASElem_ClassifierType_%d_1",
13029 num_of_scs_desc);
13030 if (!classifier_type) {
13031 sigma_dut_print(dut, DUT_MSG_ERROR,
13032 "classifier type missing");
13033 return INVALID_SEND_STATUS;
13034 }
13035
13036 while (classifier_type) {
13037 num_of_tclas_elem++;
13038
13039 len = snprintf(pos, rem_len, " classifier_type=%s",
13040 classifier_type);
13041 if (len < 0 || len >= rem_len)
13042 goto fail;
13043
13044 pos += len;
13045 rem_len -= len;
13046
13047 if (strcmp(classifier_type, "10") == 0) {
13048 total_bytes = get_type10_frame_classifier(
13049 dut, cmd, pos, rem_len,
13050 num_of_scs_desc,
13051 num_of_tclas_elem);
13052 } else if (strcmp(classifier_type, "4") == 0) {
13053 total_bytes = get_type4_frame_classifier(
13054 dut, cmd, pos, rem_len,
13055 num_of_scs_desc,
13056 num_of_tclas_elem);
13057 } else {
13058 sigma_dut_print(dut, DUT_MSG_ERROR,
13059 "classifier_type invalid");
13060 goto fail;
13061 }
13062
13063 if (total_bytes < 0)
13064 goto fail;
13065
13066 pos += total_bytes;
13067 rem_len -= total_bytes;
13068
13069 classifier_type = get_param_fmt(
13070 cmd, "TCLASElem_ClassifierType_%d_%d",
13071 num_of_scs_desc, num_of_tclas_elem + 1);
13072 }
13073
13074 if (num_of_tclas_elem > 1) {
13075 val = get_param_fmt(cmd,
13076 "TCLASProcessingElem_Processing_%d",
13077 num_of_scs_desc);
13078 if (!val) {
13079 sigma_dut_print(dut, DUT_MSG_ERROR,
13080 "Tclas_processing element %d empty",
13081 num_of_scs_desc);
13082 goto fail;
13083 }
13084
13085 len = snprintf(pos, rem_len,
13086 " tclas_processing=%s", val);
13087 if (len < 0 || len >= rem_len)
13088 goto fail;
13089
13090 pos += len;
13091 rem_len -= len;
13092 }
13093scs_desc_end:
13094 num_of_tclas_elem = 0;
13095 scs_id = get_param_fmt(cmd, "SCSDescrElem_SCSID_%d",
13096 num_of_scs_desc + 1);
13097 }
13098
13099 if (wpa_command(intf, buf) != 0) {
13100 send_resp(dut, conn, SIGMA_ERROR,
13101 "ErrorCode,Failed to send SCS frame request");
13102 return STATUS_SENT_ERROR;
13103 }
13104
13105 sigma_dut_print(dut, DUT_MSG_DEBUG,
13106 "SCS frame request sent: %s", buf);
13107
13108 return SUCCESS_SEND_STATUS;
13109fail:
13110 sigma_dut_print(dut, DUT_MSG_ERROR,
13111 "Failed to create SCS frame request");
13112 return ERROR_SEND_STATUS;
13113}
13114
13115
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053013116static enum sigma_cmd_result
13117cmd_sta_send_frame_mscs(struct sigma_dut *dut, struct sigma_conn *conn,
13118 const char *intf, struct sigma_cmd *cmd)
13119{
13120 char buf[128], *pos;
13121 const char *val, *classifier_type = "04", *type;
13122 int len, rem_len;
13123 u8 up_bitmap;
13124
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053013125 type = get_param(cmd, "Request_Type");
Vinita S. Malooca85fd22021-01-15 02:54:34 +053013126 if (!type) {
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053013127 sigma_dut_print(dut, DUT_MSG_ERROR,
Vinita S. Malooca85fd22021-01-15 02:54:34 +053013128 "%s: type not valid", __func__);
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053013129 return INVALID_SEND_STATUS;
13130 }
13131
13132 rem_len = sizeof(buf);
13133 pos = buf;
13134 if (strcasecmp(type, "add") == 0) {
13135 len = snprintf(pos, rem_len, "MSCS add");
13136 } else if (strcasecmp(type, "update") == 0) {
13137 len = snprintf(pos, rem_len, "MSCS change");
13138 } else if (strcasecmp(type, "remove") == 0) {
13139 if (wpa_command(intf, "MSCS remove") != 0) {
13140 send_resp(dut, conn, SIGMA_ERROR,
13141 "ErrorCode,Failed to send MSCS frame req");
13142 return STATUS_SENT_ERROR;
13143 }
13144 return SUCCESS_SEND_STATUS;
13145 } else {
13146 sigma_dut_print(dut, DUT_MSG_ERROR,
13147 "%s: request type invalid", __func__);
13148 return INVALID_SEND_STATUS;
13149 }
13150
13151 if (len < 0 || len >= rem_len)
13152 goto fail;
13153
13154 pos += len;
13155 rem_len -= len;
13156
13157 val = get_param(cmd, "User_Priority_Bitmap");
13158 if (!val) {
13159 sigma_dut_print(dut, DUT_MSG_ERROR,
13160 "%s: user priority bitmap empty", __func__);
13161 return INVALID_SEND_STATUS;
13162 }
13163
13164 switch (atoi(val)) {
13165 case 0:
13166 up_bitmap = 0x00;
13167 break;
13168 case 1:
13169 up_bitmap = 0xF0;
13170 break;
13171 case 2:
13172 up_bitmap = 0xF6;
13173 break;
13174 default:
13175 sigma_dut_print(dut, DUT_MSG_ERROR,
13176 "%s: Unknown User_Priority_Bitmap value %d",
13177 __func__, atoi(val));
13178 return INVALID_SEND_STATUS;
13179 }
13180
13181 len = snprintf(pos, rem_len, " up_bitmap=%02x", up_bitmap);
13182 if (len < 0 || len >= rem_len)
13183 goto fail;
13184
13185 pos += len;
13186 rem_len -= len;
13187
13188 val = get_param(cmd, "User_Priority_Limit");
13189 if (!val) {
13190 sigma_dut_print(dut, DUT_MSG_ERROR,
13191 "%s: invalid user priority limit", __func__);
13192 return INVALID_SEND_STATUS;
13193 }
13194
13195 len = snprintf(pos, rem_len, " up_limit=%s", val);
13196 if (len < 0 || len >= rem_len)
13197 goto fail;
13198
13199 pos += len;
13200 rem_len -= len;
13201
13202 val = get_param(cmd, "Stream_Timeout");
13203 if (!val)
13204 val = get_param(cmd, "Stream_Timtout");
13205 if (!val) {
13206 sigma_dut_print(dut, DUT_MSG_ERROR,
13207 "%s: invalid stream timeout", __func__);
13208 return INVALID_SEND_STATUS;
13209 }
13210
13211 len = snprintf(pos, rem_len, " stream_timeout=%s", val);
13212 if (len < 0 || len >= rem_len)
13213 goto fail;
13214
13215 pos += len;
13216 rem_len -= len;
13217
13218 val = get_param(cmd, "TCLAS_Mask");
13219 if (!val) {
13220 sigma_dut_print(dut, DUT_MSG_ERROR,
13221 "%s: invalid tclas mask", __func__);
13222 return INVALID_SEND_STATUS;
13223 }
13224
13225 len = snprintf(pos, rem_len, " frame_classifier=%s%lx%032x",
13226 classifier_type, strtol(val, NULL, 2), 0);
13227 if (len < 0 || len >= rem_len)
13228 goto fail;
13229
13230 if (wpa_command(intf, buf) != 0) {
13231 send_resp(dut, conn, SIGMA_ERROR,
13232 "ErrorCode,Failed to send MSCS frame req");
13233 return STATUS_SENT_ERROR;
13234 }
13235
13236 sigma_dut_print(dut, DUT_MSG_DEBUG,
13237 "MSCS frame request sent: %s", buf);
13238
13239 return SUCCESS_SEND_STATUS;
13240fail:
13241 sigma_dut_print(dut, DUT_MSG_ERROR,
13242 "Failed to create MSCS frame req");
13243 return ERROR_SEND_STATUS;
13244}
13245
13246
Vinita S. Malooca85fd22021-01-15 02:54:34 +053013247static enum sigma_cmd_result
Veerendranath Jakkam329a3cd2021-09-11 18:10:13 +053013248cmd_sta_send_frame_dscp_query(struct sigma_dut *dut, struct sigma_conn *conn,
13249 const char *intf, struct sigma_cmd *cmd)
13250{
13251 char buf[150], *pos;
13252 const char *val;
13253 int len, rem_len;
13254
13255 rem_len = sizeof(buf);
13256 pos = buf;
13257
13258 len = snprintf(pos, rem_len, "DSCP_QUERY");
13259 if (len < 0 || len >= rem_len)
13260 goto fail;
13261
13262 pos += len;
13263 rem_len -= len;
13264
13265 val = get_param(cmd, "Wildcard");
13266 if (val && strcasecmp(val, "Yes") == 0) {
13267 len = snprintf(pos, rem_len, " wildcard");
13268 if (len < 0 || len >= rem_len)
13269 goto fail;
13270 } else if (strlen(dut->qm_domain_name)) {
13271 len = snprintf(pos, rem_len, " domain_name=%s",
13272 dut->qm_domain_name);
13273 if (len < 0 || len >= rem_len)
13274 goto fail;
13275 } else {
13276 sigma_dut_print(dut, DUT_MSG_ERROR,
13277 "Invalid DSCP Query configuration");
13278 return INVALID_SEND_STATUS;
13279 }
13280
13281 if (wpa_command(intf, buf) != 0) {
13282 send_resp(dut, conn, SIGMA_ERROR,
13283 "ErrorCode,Failed to send DSCP policy query frame");
13284 return STATUS_SENT_ERROR;
13285 }
13286
13287 sigma_dut_print(dut, DUT_MSG_DEBUG,
13288 "DSCP policy query frame sent: %s", buf);
13289 return SUCCESS_SEND_STATUS;
13290fail:
13291 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to send DSCP query");
13292 return ERROR_SEND_STATUS;
13293}
13294
13295
13296static enum sigma_cmd_result
Vinita S. Malooca85fd22021-01-15 02:54:34 +053013297cmd_sta_send_frame_qm(struct sigma_dut *dut, struct sigma_conn *conn,
13298 const char *intf, struct sigma_cmd *cmd)
13299{
13300 const char *val;
13301
13302 val = get_param(cmd, "FrameName");
13303 if (val) {
13304 if (strcasecmp(val, "MSCSReq") == 0)
13305 return cmd_sta_send_frame_mscs(dut, conn, intf, cmd);
13306 if (strcasecmp(val, "SCSReq") == 0)
13307 return cmd_sta_send_frame_scs(dut, conn, intf, cmd);
Veerendranath Jakkam329a3cd2021-09-11 18:10:13 +053013308 if (strcasecmp(val, "DSCPPolicyQuery") == 0)
13309 return cmd_sta_send_frame_dscp_query(dut, conn, intf,
13310 cmd);
Vinita S. Malooca85fd22021-01-15 02:54:34 +053013311
13312 sigma_dut_print(dut, DUT_MSG_ERROR,
13313 "%s: frame name - %s is invalid",
13314 __func__, val);
13315 }
13316
13317 return INVALID_SEND_STATUS;
13318}
13319
13320
Jouni Malinenf7222712019-06-13 01:50:21 +030013321enum sigma_cmd_result cmd_sta_send_frame(struct sigma_dut *dut,
13322 struct sigma_conn *conn,
13323 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013324{
13325 const char *intf = get_param(cmd, "Interface");
13326 const char *val;
13327 enum send_frame_type frame;
13328 enum send_frame_protection protected;
13329 char buf[100];
13330 unsigned char addr[ETH_ALEN];
13331 int res;
13332
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030013333 if (!intf)
13334 return -1;
13335
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013336 val = get_param(cmd, "program");
13337 if (val == NULL)
13338 val = get_param(cmd, "frame");
13339 if (val && strcasecmp(val, "TDLS") == 0)
13340 return cmd_sta_send_frame_tdls(dut, conn, cmd);
13341 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030013342 strcasecmp(val, "HS2-R2") == 0 ||
13343 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013344 return cmd_sta_send_frame_hs2(dut, conn, cmd);
13345 if (val && strcasecmp(val, "VHT") == 0)
13346 return cmd_sta_send_frame_vht(dut, conn, cmd);
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070013347 if (val && strcasecmp(val, "HE") == 0)
13348 return cmd_sta_send_frame_he(dut, conn, cmd);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -070013349 if (val && strcasecmp(val, "LOC") == 0)
13350 return loc_cmd_sta_send_frame(dut, conn, cmd);
Lior David0fe101e2017-03-09 16:09:50 +020013351 if (val && strcasecmp(val, "60GHz") == 0)
13352 return cmd_sta_send_frame_60g(dut, conn, cmd);
Ashwini Patildb59b3c2017-04-13 15:19:23 +053013353 if (val && strcasecmp(val, "MBO") == 0) {
13354 res = mbo_cmd_sta_send_frame(dut, conn, intf, cmd);
13355 if (res != 2)
13356 return res;
13357 }
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053013358 if (val && strcasecmp(val, "WPA3") == 0)
13359 return cmd_sta_send_frame_wpa3(dut, conn, intf, cmd);
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053013360 if (val && strcasecmp(val, "QM") == 0)
Vinita S. Malooca85fd22021-01-15 02:54:34 +053013361 return cmd_sta_send_frame_qm(dut, conn, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013362
13363 val = get_param(cmd, "TD_DISC");
13364 if (val) {
13365 if (hwaddr_aton(val, addr) < 0)
13366 return -1;
13367 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", val);
13368 if (wpa_command(intf, buf) < 0) {
13369 send_resp(dut, conn, SIGMA_ERROR,
13370 "ErrorCode,Failed to send TDLS discovery");
13371 return 0;
13372 }
13373 return 1;
13374 }
13375
13376 val = get_param(cmd, "TD_Setup");
13377 if (val) {
13378 if (hwaddr_aton(val, addr) < 0)
13379 return -1;
13380 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", val);
13381 if (wpa_command(intf, buf) < 0) {
13382 send_resp(dut, conn, SIGMA_ERROR,
13383 "ErrorCode,Failed to start TDLS setup");
13384 return 0;
13385 }
13386 return 1;
13387 }
13388
13389 val = get_param(cmd, "TD_TearDown");
13390 if (val) {
13391 if (hwaddr_aton(val, addr) < 0)
13392 return -1;
13393 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", val);
13394 if (wpa_command(intf, buf) < 0) {
13395 send_resp(dut, conn, SIGMA_ERROR,
13396 "ErrorCode,Failed to tear down TDLS link");
13397 return 0;
13398 }
13399 return 1;
13400 }
13401
13402 val = get_param(cmd, "TD_ChannelSwitch");
13403 if (val) {
13404 /* TODO */
13405 send_resp(dut, conn, SIGMA_ERROR,
13406 "ErrorCode,TD_ChannelSwitch not yet supported");
13407 return 0;
13408 }
13409
13410 val = get_param(cmd, "TD_NF");
13411 if (val) {
13412 /* TODO */
13413 send_resp(dut, conn, SIGMA_ERROR,
13414 "ErrorCode,TD_NF not yet supported");
13415 return 0;
13416 }
13417
13418 val = get_param(cmd, "PMFFrameType");
13419 if (val == NULL)
13420 val = get_param(cmd, "FrameName");
13421 if (val == NULL)
13422 val = get_param(cmd, "Type");
13423 if (val == NULL)
13424 return -1;
13425 if (strcasecmp(val, "disassoc") == 0)
13426 frame = DISASSOC;
13427 else if (strcasecmp(val, "deauth") == 0)
13428 frame = DEAUTH;
13429 else if (strcasecmp(val, "saquery") == 0)
13430 frame = SAQUERY;
13431 else if (strcasecmp(val, "auth") == 0)
13432 frame = AUTH;
13433 else if (strcasecmp(val, "assocreq") == 0)
13434 frame = ASSOCREQ;
13435 else if (strcasecmp(val, "reassocreq") == 0)
13436 frame = REASSOCREQ;
13437 else if (strcasecmp(val, "neigreq") == 0) {
13438 sigma_dut_print(dut, DUT_MSG_INFO, "Got neighbor request");
13439
13440 val = get_param(cmd, "ssid");
13441 if (val == NULL)
13442 return -1;
13443
13444 res = send_neighbor_request(dut, intf, val);
13445 if (res) {
13446 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
13447 "Failed to send neighbor report request");
13448 return 0;
13449 }
13450
13451 return 1;
Ashwini Patil5acd7382017-04-13 15:55:04 +053013452 } else if (strcasecmp(val, "transmgmtquery") == 0 ||
13453 strcasecmp(val, "BTMQuery") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013454 sigma_dut_print(dut, DUT_MSG_DEBUG,
13455 "Got Transition Management Query");
13456
Ashwini Patil5acd7382017-04-13 15:55:04 +053013457 res = send_trans_mgmt_query(dut, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013458 if (res) {
13459 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
13460 "Failed to send Transition Management Query");
13461 return 0;
13462 }
13463
13464 return 1;
13465 } else {
13466 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
13467 "PMFFrameType");
13468 return 0;
13469 }
13470
13471 val = get_param(cmd, "PMFProtected");
13472 if (val == NULL)
13473 val = get_param(cmd, "Protected");
13474 if (val == NULL)
13475 return -1;
13476 if (strcasecmp(val, "Correct-key") == 0 ||
13477 strcasecmp(val, "CorrectKey") == 0)
13478 protected = CORRECT_KEY;
13479 else if (strcasecmp(val, "IncorrectKey") == 0)
13480 protected = INCORRECT_KEY;
13481 else if (strcasecmp(val, "Unprotected") == 0)
13482 protected = UNPROTECTED;
13483 else {
13484 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
13485 "PMFProtected");
13486 return 0;
13487 }
13488
13489 if (protected != UNPROTECTED &&
13490 (frame == AUTH || frame == ASSOCREQ || frame == REASSOCREQ)) {
13491 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Impossible "
13492 "PMFProtected for auth/assocreq/reassocreq");
13493 return 0;
13494 }
13495
13496 if (if_nametoindex("sigmadut") == 0) {
13497 snprintf(buf, sizeof(buf),
13498 "iw dev %s interface add sigmadut type monitor",
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013499 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013500 if (system(buf) != 0 ||
13501 if_nametoindex("sigmadut") == 0) {
13502 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
13503 "monitor interface with '%s'", buf);
13504 return -2;
13505 }
13506 }
13507
13508 if (system("ifconfig sigmadut up") != 0) {
13509 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
13510 "monitor interface up");
13511 return -2;
13512 }
13513
Veerendranath Jakkam49774122020-07-05 09:52:18 +053013514 return sta_inject_frame(dut, conn, intf, frame, protected, NULL, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013515}
13516
13517
13518static int cmd_sta_set_parameter_hs2(struct sigma_dut *dut,
13519 struct sigma_conn *conn,
13520 struct sigma_cmd *cmd,
13521 const char *ifname)
13522{
13523 char buf[200];
13524 const char *val;
13525
13526 val = get_param(cmd, "ClearARP");
13527 if (val && atoi(val) == 1) {
13528 snprintf(buf, sizeof(buf), "ip neigh flush dev %s", ifname);
13529 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
13530 if (system(buf) != 0) {
13531 send_resp(dut, conn, SIGMA_ERROR,
13532 "errorCode,Failed to clear ARP cache");
13533 return 0;
13534 }
13535 }
13536
13537 return 1;
13538}
13539
13540
13541int cmd_sta_set_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
13542 struct sigma_cmd *cmd)
13543{
13544 const char *intf = get_param(cmd, "Interface");
13545 const char *val;
13546
13547 if (intf == NULL)
13548 return -1;
13549
13550 val = get_param(cmd, "program");
13551 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030013552 strcasecmp(val, "HS2-R2") == 0 ||
13553 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013554 return cmd_sta_set_parameter_hs2(dut, conn, cmd, intf);
13555
13556 return -1;
13557}
13558
13559
Jouni Malinenf7222712019-06-13 01:50:21 +030013560static enum sigma_cmd_result cmd_sta_set_macaddr(struct sigma_dut *dut,
13561 struct sigma_conn *conn,
13562 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013563{
13564 const char *intf = get_param(cmd, "Interface");
13565 const char *mac = get_param(cmd, "MAC");
13566
13567 if (intf == NULL || mac == NULL)
13568 return -1;
13569
13570 sigma_dut_print(dut, DUT_MSG_INFO, "Change local MAC address for "
13571 "interface %s to %s", intf, mac);
13572
13573 if (dut->set_macaddr) {
13574 char buf[128];
13575 int res;
13576 if (strcasecmp(mac, "default") == 0) {
13577 res = snprintf(buf, sizeof(buf), "%s",
13578 dut->set_macaddr);
13579 dut->tmp_mac_addr = 0;
13580 } else {
13581 res = snprintf(buf, sizeof(buf), "%s %s",
13582 dut->set_macaddr, mac);
13583 dut->tmp_mac_addr = 1;
13584 }
13585 if (res < 0 || res >= (int) sizeof(buf))
13586 return -1;
13587 if (system(buf) != 0) {
13588 send_resp(dut, conn, SIGMA_ERROR,
13589 "errorCode,Failed to set MAC "
13590 "address");
13591 return 0;
13592 }
13593 return 1;
13594 }
13595
13596 if (strcasecmp(mac, "default") == 0)
13597 return 1;
13598
13599 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
13600 "command");
13601 return 0;
13602}
13603
13604
13605static int iwpriv_tdlsoffchnmode(struct sigma_dut *dut,
13606 struct sigma_conn *conn, const char *intf,
13607 int val)
13608{
13609 char buf[200];
13610 int res;
13611
13612 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchnmode %d",
13613 intf, val);
13614 if (res < 0 || res >= (int) sizeof(buf))
13615 return -1;
13616 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
13617 if (system(buf) != 0) {
13618 send_resp(dut, conn, SIGMA_ERROR,
13619 "errorCode,Failed to configure offchannel mode");
13620 return 0;
13621 }
13622
13623 return 1;
13624}
13625
13626
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013627static int off_chan_val(enum sec_ch_offset off)
13628{
13629 switch (off) {
13630 case SEC_CH_NO:
13631 return 0;
13632 case SEC_CH_40ABOVE:
13633 return 40;
13634 case SEC_CH_40BELOW:
13635 return -40;
13636 }
13637
13638 return 0;
13639}
13640
13641
13642static int iwpriv_set_offchan(struct sigma_dut *dut, struct sigma_conn *conn,
13643 const char *intf, int off_ch_num,
13644 enum sec_ch_offset sec)
13645{
13646 char buf[200];
13647 int res;
13648
13649 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchan %d",
13650 intf, off_ch_num);
13651 if (res < 0 || res >= (int) sizeof(buf))
13652 return -1;
13653 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
13654 if (system(buf) != 0) {
13655 send_resp(dut, conn, SIGMA_ERROR,
13656 "errorCode,Failed to set offchan");
13657 return 0;
13658 }
13659
13660 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsecchnoffst %d",
13661 intf, off_chan_val(sec));
13662 if (res < 0 || res >= (int) sizeof(buf))
13663 return -1;
13664 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
13665 if (system(buf) != 0) {
13666 send_resp(dut, conn, SIGMA_ERROR,
13667 "errorCode,Failed to set sec chan offset");
13668 return 0;
13669 }
13670
13671 return 1;
13672}
13673
13674
13675static int tdls_set_offchannel_offset(struct sigma_dut *dut,
13676 struct sigma_conn *conn,
13677 const char *intf, int off_ch_num,
13678 enum sec_ch_offset sec)
13679{
13680 char buf[200];
13681 int res;
13682
13683 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNEL %d",
13684 off_ch_num);
13685 if (res < 0 || res >= (int) sizeof(buf))
13686 return -1;
13687 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
13688
13689 if (wpa_command(intf, buf) < 0) {
13690 send_resp(dut, conn, SIGMA_ERROR,
13691 "ErrorCode,Failed to set offchan");
13692 return 0;
13693 }
13694 res = snprintf(buf, sizeof(buf), "DRIVER TDLSSECONDARYCHANNELOFFSET %d",
13695 off_chan_val(sec));
13696 if (res < 0 || res >= (int) sizeof(buf))
13697 return -1;
13698
13699 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
13700
13701 if (wpa_command(intf, buf) < 0) {
13702 send_resp(dut, conn, SIGMA_ERROR,
13703 "ErrorCode,Failed to set sec chan offset");
13704 return 0;
13705 }
13706
13707 return 1;
13708}
13709
13710
13711static int tdls_set_offchannel_mode(struct sigma_dut *dut,
13712 struct sigma_conn *conn,
13713 const char *intf, int val)
13714{
13715 char buf[200];
13716 int res;
13717
13718 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNELMODE %d",
13719 val);
13720 if (res < 0 || res >= (int) sizeof(buf))
13721 return -1;
13722 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
13723
13724 if (wpa_command(intf, buf) < 0) {
13725 send_resp(dut, conn, SIGMA_ERROR,
13726 "ErrorCode,Failed to configure offchannel mode");
13727 return 0;
13728 }
13729
13730 return 1;
13731}
13732
13733
13734static int cmd_sta_set_rfeature_tdls(const char *intf, struct sigma_dut *dut,
13735 struct sigma_conn *conn,
13736 struct sigma_cmd *cmd)
13737{
13738 const char *val;
13739 enum {
13740 CHSM_NOT_SET,
13741 CHSM_ENABLE,
13742 CHSM_DISABLE,
13743 CHSM_REJREQ,
13744 CHSM_UNSOLRESP
13745 } chsm = CHSM_NOT_SET;
13746 int off_ch_num = -1;
13747 enum sec_ch_offset sec_ch = SEC_CH_NO;
13748 int res;
13749
13750 val = get_param(cmd, "Uapsd");
13751 if (val) {
13752 char buf[100];
13753 if (strcasecmp(val, "Enable") == 0)
13754 snprintf(buf, sizeof(buf), "SET ps 99");
13755 else if (strcasecmp(val, "Disable") == 0)
13756 snprintf(buf, sizeof(buf), "SET ps 98");
13757 else {
13758 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
13759 "Unsupported uapsd parameter value");
13760 return 0;
13761 }
13762 if (wpa_command(intf, buf)) {
13763 send_resp(dut, conn, SIGMA_ERROR,
13764 "ErrorCode,Failed to change U-APSD "
13765 "powersave mode");
13766 return 0;
13767 }
13768 }
13769
13770 val = get_param(cmd, "TPKTIMER");
13771 if (val && strcasecmp(val, "DISABLE") == 0) {
13772 if (wpa_command(intf, "SET tdls_testing 0x100")) {
13773 send_resp(dut, conn, SIGMA_ERROR,
13774 "ErrorCode,Failed to enable no TPK "
13775 "expiration test mode");
13776 return 0;
13777 }
13778 dut->no_tpk_expiration = 1;
13779 }
13780
13781 val = get_param(cmd, "ChSwitchMode");
13782 if (val) {
13783 if (strcasecmp(val, "Enable") == 0 ||
13784 strcasecmp(val, "Initiate") == 0)
13785 chsm = CHSM_ENABLE;
13786 else if (strcasecmp(val, "Disable") == 0 ||
13787 strcasecmp(val, "passive") == 0)
13788 chsm = CHSM_DISABLE;
13789 else if (strcasecmp(val, "RejReq") == 0)
13790 chsm = CHSM_REJREQ;
13791 else if (strcasecmp(val, "UnSolResp") == 0)
13792 chsm = CHSM_UNSOLRESP;
13793 else {
13794 send_resp(dut, conn, SIGMA_ERROR,
13795 "ErrorCode,Unknown ChSwitchMode value");
13796 return 0;
13797 }
13798 }
13799
13800 val = get_param(cmd, "OffChNum");
13801 if (val) {
13802 off_ch_num = atoi(val);
13803 if (off_ch_num == 0) {
13804 send_resp(dut, conn, SIGMA_ERROR,
13805 "ErrorCode,Invalid OffChNum");
13806 return 0;
13807 }
13808 }
13809
13810 val = get_param(cmd, "SecChOffset");
13811 if (val) {
13812 if (strcmp(val, "20") == 0)
13813 sec_ch = SEC_CH_NO;
13814 else if (strcasecmp(val, "40above") == 0)
13815 sec_ch = SEC_CH_40ABOVE;
13816 else if (strcasecmp(val, "40below") == 0)
13817 sec_ch = SEC_CH_40BELOW;
13818 else {
13819 send_resp(dut, conn, SIGMA_ERROR,
13820 "ErrorCode,Unknown SecChOffset value");
13821 return 0;
13822 }
13823 }
13824
13825 if (chsm == CHSM_NOT_SET) {
13826 /* no offchannel changes requested */
13827 return 1;
13828 }
13829
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013830 if (strcmp(intf, get_main_ifname(dut)) != 0 &&
13831 strcmp(intf, get_station_ifname(dut)) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013832 send_resp(dut, conn, SIGMA_ERROR,
13833 "ErrorCode,Unknown interface");
13834 return 0;
13835 }
13836
13837 switch (chsm) {
13838 case CHSM_NOT_SET:
Jouni Malinen280f5ba2016-08-29 21:33:10 +030013839 res = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013840 break;
13841 case CHSM_ENABLE:
13842 if (off_ch_num < 0) {
13843 send_resp(dut, conn, SIGMA_ERROR,
13844 "ErrorCode,Missing OffChNum argument");
13845 return 0;
13846 }
13847 if (wifi_chip_type == DRIVER_WCN) {
13848 res = tdls_set_offchannel_offset(dut, conn, intf,
13849 off_ch_num, sec_ch);
13850 } else {
13851 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
13852 sec_ch);
13853 }
13854 if (res != 1)
13855 return res;
13856 if (wifi_chip_type == DRIVER_WCN)
13857 res = tdls_set_offchannel_mode(dut, conn, intf, 1);
13858 else
13859 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 1);
13860 break;
13861 case CHSM_DISABLE:
13862 if (wifi_chip_type == DRIVER_WCN)
13863 res = tdls_set_offchannel_mode(dut, conn, intf, 2);
13864 else
13865 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 2);
13866 break;
13867 case CHSM_REJREQ:
13868 if (wifi_chip_type == DRIVER_WCN)
13869 res = tdls_set_offchannel_mode(dut, conn, intf, 3);
13870 else
13871 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 3);
13872 break;
13873 case CHSM_UNSOLRESP:
13874 if (off_ch_num < 0) {
13875 send_resp(dut, conn, SIGMA_ERROR,
13876 "ErrorCode,Missing OffChNum argument");
13877 return 0;
13878 }
13879 if (wifi_chip_type == DRIVER_WCN) {
13880 res = tdls_set_offchannel_offset(dut, conn, intf,
13881 off_ch_num, sec_ch);
13882 } else {
13883 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
13884 sec_ch);
13885 }
13886 if (res != 1)
13887 return res;
13888 if (wifi_chip_type == DRIVER_WCN)
13889 res = tdls_set_offchannel_mode(dut, conn, intf, 4);
13890 else
13891 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 4);
13892 break;
13893 }
13894
13895 return res;
13896}
13897
13898
13899static int ath_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
13900 struct sigma_conn *conn,
13901 struct sigma_cmd *cmd)
13902{
13903 const char *val;
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053013904 char *token = NULL, *result;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013905
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -070013906 novap_reset(dut, intf, 1);
priyadharshini gowthamane5e25172015-12-08 14:53:48 -080013907
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013908 val = get_param(cmd, "nss_mcs_opt");
13909 if (val) {
13910 /* String (nss_operating_mode; mcs_operating_mode) */
13911 int nss, mcs;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053013912 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013913
13914 token = strdup(val);
13915 if (!token)
13916 return 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053013917 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053013918 if (!result) {
13919 sigma_dut_print(dut, DUT_MSG_ERROR,
13920 "VHT NSS not specified");
13921 goto failed;
13922 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013923 if (strcasecmp(result, "def") != 0) {
13924 nss = atoi(result);
13925 if (nss == 4)
13926 ath_disable_txbf(dut, intf);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070013927 if (run_iwpriv(dut, intf, "nss %d", nss) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013928 goto failed;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070013929
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013930 }
13931
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053013932 result = strtok_r(NULL, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053013933 if (!result) {
13934 sigma_dut_print(dut, DUT_MSG_ERROR,
13935 "VHT MCS not specified");
13936 goto failed;
13937 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013938 if (strcasecmp(result, "def") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070013939 if (run_iwpriv(dut, intf, "set11NRates 0") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013940 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013941 } else {
13942 mcs = atoi(result);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070013943 if (run_iwpriv(dut, intf, "vhtmcs %d", mcs) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013944 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013945 }
13946 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070013947 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013948 }
13949
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053013950 free(token);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013951 return 1;
13952failed:
13953 free(token);
13954 return 0;
13955}
13956
13957
13958static int cmd_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
13959 struct sigma_conn *conn,
13960 struct sigma_cmd *cmd)
13961{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013962 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013963 case DRIVER_ATHEROS:
13964 return ath_sta_set_rfeature_vht(intf, dut, conn, cmd);
13965 default:
13966 send_resp(dut, conn, SIGMA_ERROR,
13967 "errorCode,Unsupported sta_set_rfeature(VHT) with the current driver");
13968 return 0;
13969 }
13970}
13971
13972
Jouni Malinen1702fe32021-06-08 19:08:01 +030013973static enum sigma_cmd_result
13974wcn_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
13975 struct sigma_conn *conn, struct sigma_cmd *cmd)
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080013976{
13977 const char *val;
13978 char *token = NULL, *result;
13979 char buf[60];
13980
13981 val = get_param(cmd, "nss_mcs_opt");
13982 if (val) {
13983 /* String (nss_operating_mode; mcs_operating_mode) */
13984 int nss, mcs, ratecode;
13985 char *saveptr;
13986
13987 token = strdup(val);
13988 if (!token)
Jouni Malinen1702fe32021-06-08 19:08:01 +030013989 return ERROR_SEND_STATUS;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080013990
13991 result = strtok_r(token, ";", &saveptr);
13992 if (!result) {
13993 sigma_dut_print(dut, DUT_MSG_ERROR,
13994 "HE NSS not specified");
13995 goto failed;
13996 }
13997 nss = 1;
13998 if (strcasecmp(result, "def") != 0)
13999 nss = atoi(result);
14000
14001 result = strtok_r(NULL, ";", &saveptr);
14002 if (!result) {
14003 sigma_dut_print(dut, DUT_MSG_ERROR,
14004 "HE MCS not specified");
14005 goto failed;
14006 }
14007 mcs = 7;
14008 if (strcasecmp(result, "def") != 0)
14009 mcs = atoi(result);
14010
Arif Hussain557bf412018-05-25 17:29:36 -070014011 ratecode = 0x20; /* for nss:1 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014012 if (nss == 2) {
Arif Hussain557bf412018-05-25 17:29:36 -070014013 ratecode = 0x40; /* for nss:2 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014014 } else if (nss > 2) {
14015 sigma_dut_print(dut, DUT_MSG_ERROR,
14016 "HE NSS %d not supported", nss);
14017 goto failed;
14018 }
14019
Arif Hussain557bf412018-05-25 17:29:36 -070014020 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss);
14021 if (system(buf) != 0) {
14022 sigma_dut_print(dut, DUT_MSG_ERROR,
14023 "nss_mcs_opt: iwpriv %s nss %d failed",
14024 intf, nss);
14025 goto failed;
14026 }
Arif Hussainac6c5112018-05-25 17:34:00 -070014027 dut->sta_nss = nss;
Arif Hussain557bf412018-05-25 17:29:36 -070014028
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014029 /* Add the MCS to the ratecode */
14030 if (mcs >= 0 && mcs <= 11) {
14031 ratecode += mcs;
Arif Hussain557bf412018-05-25 17:29:36 -070014032#ifdef NL80211_SUPPORT
14033 if (dut->device_type == STA_testbed) {
14034 enum he_mcs_config mcs_config;
14035 int ret;
14036
14037 if (mcs <= 7)
14038 mcs_config = HE_80_MCS0_7;
14039 else if (mcs <= 9)
14040 mcs_config = HE_80_MCS0_9;
14041 else
14042 mcs_config = HE_80_MCS0_11;
14043 ret = sta_set_he_mcs(dut, intf, mcs_config);
14044 if (ret) {
14045 sigma_dut_print(dut, DUT_MSG_ERROR,
14046 "nss_mcs_opt: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
14047 mcs, mcs_config, ret);
14048 goto failed;
14049 }
14050 }
14051#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014052 } else {
14053 sigma_dut_print(dut, DUT_MSG_ERROR,
14054 "HE MCS %d not supported", mcs);
14055 goto failed;
14056 }
14057 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0x%03x",
14058 intf, ratecode);
14059 if (system(buf) != 0) {
14060 sigma_dut_print(dut, DUT_MSG_ERROR,
14061 "iwpriv setting of 11ax rates failed");
14062 goto failed;
14063 }
14064 free(token);
14065 }
14066
14067 val = get_param(cmd, "GI");
14068 if (val) {
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080014069 int fix_rate_sgi;
14070
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014071 if (strcmp(val, "0.8") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070014072 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 9", intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080014073 fix_rate_sgi = 1;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014074 } else if (strcmp(val, "1.6") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070014075 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 10",
14076 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080014077 fix_rate_sgi = 2;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014078 } else if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070014079 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 11",
14080 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080014081 fix_rate_sgi = 3;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014082 } else {
14083 send_resp(dut, conn, SIGMA_ERROR,
14084 "errorCode,GI value not supported");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014085 return STATUS_SENT_ERROR;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014086 }
14087 if (system(buf) != 0) {
14088 send_resp(dut, conn, SIGMA_ERROR,
14089 "errorCode,Failed to set shortgi");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014090 return STATUS_SENT_ERROR;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014091 }
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080014092 snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d",
14093 intf, fix_rate_sgi);
14094 if (system(buf) != 0) {
14095 send_resp(dut, conn, SIGMA_ERROR,
14096 "errorCode,Failed to set fix rate shortgi");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014097 return STATUS_SENT_ERROR;
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080014098 }
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014099 }
14100
Subhani Shaik8e7a3052018-04-24 14:03:00 -070014101 val = get_param(cmd, "LTF");
14102 if (val) {
14103#ifdef NL80211_SUPPORT
14104 if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080014105 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_1X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070014106 } if (strcmp(val, "6.4") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080014107 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_2X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070014108 } else if (strcmp(val, "12.8") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080014109 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_4X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070014110 } else {
14111 send_resp(dut, conn, SIGMA_ERROR,
14112 "errorCode, LTF value not supported");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014113 return STATUS_SENT_ERROR;
Subhani Shaik8e7a3052018-04-24 14:03:00 -070014114 }
14115#else /* NL80211_SUPPORT */
14116 sigma_dut_print(dut, DUT_MSG_ERROR,
14117 "LTF cannot be set without NL80211_SUPPORT defined");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014118 return ERROR_SEND_STATUS;
Subhani Shaik8e7a3052018-04-24 14:03:00 -070014119#endif /* NL80211_SUPPORT */
14120 }
14121
Kiran Kumar Lokere1809da12021-06-24 00:45:38 -070014122 val = get_param(cmd, "KeepAlive");
14123 if (val) {
14124 int set_val = QCA_WLAN_KEEP_ALIVE_DEFAULT;
14125
14126 if (strcasecmp(val, "Data") == 0)
14127 set_val = QCA_WLAN_KEEP_ALIVE_DATA;
14128 else if (strcasecmp(val, "Mgmt") == 0)
14129 set_val = QCA_WLAN_KEEP_ALIVE_MGMT;
14130
14131 if (sta_set_keep_alive_data_cfg(dut, intf, set_val)) {
14132 send_resp(dut, conn, SIGMA_ERROR,
14133 "ErrorCode,Failed to set keep alive type config");
14134 return STATUS_SENT_ERROR;
14135 }
14136 }
14137
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -070014138 val = get_param(cmd, "TxSUPPDU");
14139 if (val) {
14140 int set_val = 1;
14141
14142 if (strcasecmp(val, "Enable") == 0)
14143 set_val = 1;
14144 else if (strcasecmp(val, "Disable") == 0)
14145 set_val = 0;
14146
14147 if (sta_set_tx_su_ppdu_cfg(dut, intf, set_val)) {
14148 send_resp(dut, conn, SIGMA_ERROR,
14149 "ErrorCode,Failed to set Tx SU PPDU config");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014150 return STATUS_SENT_ERROR;
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -070014151 }
14152 }
14153
Kiran Kumar Lokere54b72522021-04-01 00:22:44 -070014154 val = get_param(cmd, "Mgmt_Data_TX_Resp_Frame");
14155 if (val) {
14156 int set_val = 0;
14157
14158 if (strcasecmp(val, "Enable") == 0)
14159 set_val = 0;
14160 else if (strcasecmp(val, "Disable") == 0)
14161 set_val = 1;
14162
14163 if (sta_set_mgmt_data_tx_disable_cfg(dut, intf, set_val)) {
14164 send_resp(dut, conn, SIGMA_ERROR,
14165 "ErrorCode,Failed to set mgmt/data Tx disable config");
14166 return STATUS_SENT_ERROR;
14167 }
14168 }
14169
Arif Hussain480d5f42019-03-12 14:40:42 -070014170 val = get_param(cmd, "TWT_Setup");
14171 if (val) {
14172 if (strcasecmp(val, "Request") == 0) {
14173 if (sta_twt_request(dut, conn, cmd)) {
14174 send_resp(dut, conn, SIGMA_ERROR,
Srinivas Girigowda6707f032020-10-26 15:24:46 -070014175 "ErrorCode,TWT setup failed");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014176 return STATUS_SENT_ERROR;
Arif Hussain480d5f42019-03-12 14:40:42 -070014177 }
14178 } else if (strcasecmp(val, "Teardown") == 0) {
14179 if (sta_twt_teardown(dut, conn, cmd)) {
14180 send_resp(dut, conn, SIGMA_ERROR,
Srinivas Girigowda6707f032020-10-26 15:24:46 -070014181 "ErrorCode,TWT teardown failed");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014182 return STATUS_SENT_ERROR;
Arif Hussain480d5f42019-03-12 14:40:42 -070014183 }
14184 }
14185 }
14186
Srinivas Girigowda6707f032020-10-26 15:24:46 -070014187 val = get_param(cmd, "TWT_Operation");
14188 if (val) {
14189 if (strcasecmp(val, "Suspend") == 0) {
14190 if (sta_twt_suspend_or_nudge(dut, conn, cmd)) {
14191 send_resp(dut, conn, SIGMA_ERROR,
14192 "ErrorCode,TWT suspend failed");
14193 return STATUS_SENT_ERROR;
14194 }
14195 } else if (strcasecmp(val, "Resume") == 0) {
14196 if (sta_twt_resume(dut, conn, cmd)) {
14197 send_resp(dut, conn, SIGMA_ERROR,
14198 "ErrorCode,TWT resume failed");
14199 return STATUS_SENT_ERROR;
14200 }
14201 }
14202 }
14203
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -080014204 val = get_param(cmd, "transmitOMI");
14205 if (val && sta_transmit_omi(dut, conn, cmd)) {
14206 send_resp(dut, conn, SIGMA_ERROR,
14207 "ErrorCode,sta_transmit_omi failed");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014208 return STATUS_SENT_ERROR;
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -070014209 }
14210
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080014211 val = get_param(cmd, "Powersave");
14212 if (val) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053014213 int ps;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080014214
14215 if (strcasecmp(val, "off") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053014216 ps = 2;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080014217 } else if (strcasecmp(val, "on") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053014218 ps = 1;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080014219 } else {
14220 sigma_dut_print(dut, DUT_MSG_ERROR,
14221 "Unsupported Powersave value '%s'",
14222 val);
Jouni Malinen1702fe32021-06-08 19:08:01 +030014223 return INVALID_SEND_STATUS;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080014224 }
Vinita S. Malooa8b62722020-04-23 01:45:41 +053014225 if (set_power_save_wcn(dut, intf, ps) < 0)
Jouni Malinen1702fe32021-06-08 19:08:01 +030014226 return ERROR_SEND_STATUS;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080014227 }
14228
Kiran Kumar Lokere2c4b7ce2019-01-30 12:02:28 -080014229 val = get_param(cmd, "MU_EDCA");
14230 if (val) {
14231 if (strcasecmp(val, "Override") == 0) {
14232 if (sta_set_mu_edca_override(dut, intf, 1)) {
14233 send_resp(dut, conn, SIGMA_ERROR,
14234 "errorCode,MU EDCA override set failed");
14235 return STATUS_SENT;
14236 }
14237 } else if (strcasecmp(val, "Disable") == 0) {
14238 if (sta_set_mu_edca_override(dut, intf, 0)) {
14239 send_resp(dut, conn, SIGMA_ERROR,
14240 "errorCode,MU EDCA override disable failed");
14241 return STATUS_SENT;
14242 }
14243 }
14244 }
14245
Kiran Kumar Lokerefa7c7b92021-08-09 00:50:55 -070014246 val = get_param(cmd, "RUAllocTone");
14247 if (val && strcasecmp(val, "242") == 0) {
14248 if (sta_set_ru_242_tone_tx(dut, intf, 1)) {
14249 send_resp(dut, conn, SIGMA_ERROR,
14250 "ErrorCode,Failed to set RU 242 tone Tx");
14251 return STATUS_SENT_ERROR;
14252 }
14253 }
14254
14255 val = get_param(cmd, "PPDUTxType");
14256 if (val && strcasecmp(val, "ER-SU") == 0) {
14257 if (sta_set_er_su_ppdu_type_tx(dut, intf, 1)) {
14258 send_resp(dut, conn, SIGMA_ERROR,
14259 "ErrorCode,Failed to set ER-SU PPDU type Tx");
14260 return STATUS_SENT_ERROR;
14261 }
14262 }
14263
Kiran Kumar Lokeredd086642020-06-04 00:29:26 -070014264 val = get_param(cmd, "Ch_Pref");
14265 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
14266 return STATUS_SENT;
14267
14268 val = get_param(cmd, "Cellular_Data_Cap");
14269 if (val && mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
14270 return STATUS_SENT;
14271
Jouni Malinen1702fe32021-06-08 19:08:01 +030014272 return SUCCESS_SEND_STATUS;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014273
14274failed:
14275 free(token);
Jouni Malinen1702fe32021-06-08 19:08:01 +030014276 return ERROR_SEND_STATUS;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014277}
14278
14279
Jouni Malinen1702fe32021-06-08 19:08:01 +030014280static enum sigma_cmd_result
14281cmd_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
14282 struct sigma_conn *conn, struct sigma_cmd *cmd)
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014283{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020014284 switch (get_driver_type(dut)) {
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014285 case DRIVER_WCN:
14286 return wcn_sta_set_rfeature_he(intf, dut, conn, cmd);
14287 default:
14288 send_resp(dut, conn, SIGMA_ERROR,
14289 "errorCode,Unsupported sta_set_rfeature(HE) with the current driver");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014290 return STATUS_SENT_ERROR;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014291 }
14292}
14293
14294
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080014295static int cmd_sta_set_power_save_he(const char *intf, struct sigma_dut *dut,
14296 struct sigma_conn *conn,
14297 struct sigma_cmd *cmd)
14298{
14299 const char *val;
14300
14301 val = get_param(cmd, "powersave");
14302 if (val) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053014303 int ps;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080014304
14305 if (strcasecmp(val, "off") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053014306 ps = 2;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080014307 } else if (strcasecmp(val, "on") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053014308 ps = 1;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080014309 } else {
14310 sigma_dut_print(dut, DUT_MSG_ERROR,
14311 "Unsupported power save config");
14312 return -1;
14313 }
Vinita S. Malooa8b62722020-04-23 01:45:41 +053014314 if (set_power_save_wcn(dut, intf, ps) < 0)
14315 return 0;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080014316 return 1;
14317 }
14318
14319 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported command");
14320
14321 return 0;
14322}
14323
14324
Ashwini Patil5acd7382017-04-13 15:55:04 +053014325static int btm_query_candidate_list(struct sigma_dut *dut,
14326 struct sigma_conn *conn,
14327 struct sigma_cmd *cmd)
14328{
14329 const char *bssid, *info, *op_class, *ch, *phy_type, *pref;
14330 int len, ret;
14331 char buf[10];
14332
14333 /*
14334 * Neighbor Report elements format:
14335 * neighbor=<BSSID>,<BSSID Information>,<Operating Class>,
14336 * <Channel Number>,<PHY Type>[,<hexdump of Optional Subelements>]
14337 * eg: neighbor=aa:bb:cc:dd:ee:ff,17,81,6,1,030101
14338 */
14339
14340 bssid = get_param(cmd, "Nebor_BSSID");
14341 if (!bssid) {
14342 send_resp(dut, conn, SIGMA_INVALID,
14343 "errorCode,Nebor_BSSID is missing");
14344 return 0;
14345 }
14346
14347 info = get_param(cmd, "Nebor_Bssid_Info");
14348 if (!info) {
14349 sigma_dut_print(dut, DUT_MSG_INFO,
14350 "Using default value for Nebor_Bssid_Info: %s",
14351 DEFAULT_NEIGHBOR_BSSID_INFO);
14352 info = DEFAULT_NEIGHBOR_BSSID_INFO;
14353 }
14354
14355 op_class = get_param(cmd, "Nebor_Op_Class");
14356 if (!op_class) {
14357 send_resp(dut, conn, SIGMA_INVALID,
14358 "errorCode,Nebor_Op_Class is missing");
14359 return 0;
14360 }
14361
14362 ch = get_param(cmd, "Nebor_Op_Ch");
14363 if (!ch) {
14364 send_resp(dut, conn, SIGMA_INVALID,
14365 "errorCode,Nebor_Op_Ch is missing");
14366 return 0;
14367 }
14368
14369 phy_type = get_param(cmd, "Nebor_Phy_Type");
14370 if (!phy_type) {
14371 sigma_dut_print(dut, DUT_MSG_INFO,
14372 "Using default value for Nebor_Phy_Type: %s",
14373 DEFAULT_NEIGHBOR_PHY_TYPE);
14374 phy_type = DEFAULT_NEIGHBOR_PHY_TYPE;
14375 }
14376
14377 /* Parse optional subelements */
14378 buf[0] = '\0';
14379 pref = get_param(cmd, "Nebor_Pref");
14380 if (pref) {
14381 /* hexdump for preferrence subelement */
14382 ret = snprintf(buf, sizeof(buf), ",0301%02x", atoi(pref));
14383 if (ret < 0 || ret >= (int) sizeof(buf)) {
14384 sigma_dut_print(dut, DUT_MSG_ERROR,
14385 "snprintf failed for optional subelement ret: %d",
14386 ret);
14387 send_resp(dut, conn, SIGMA_ERROR,
14388 "errorCode,snprintf failed for subelement");
14389 return 0;
14390 }
14391 }
14392
14393 if (!dut->btm_query_cand_list) {
14394 dut->btm_query_cand_list = calloc(1, NEIGHBOR_REPORT_SIZE);
14395 if (!dut->btm_query_cand_list) {
14396 send_resp(dut, conn, SIGMA_ERROR,
14397 "errorCode,Failed to allocate memory for btm_query_cand_list");
14398 return 0;
14399 }
14400 }
14401
14402 len = strlen(dut->btm_query_cand_list);
14403 ret = snprintf(dut->btm_query_cand_list + len,
14404 NEIGHBOR_REPORT_SIZE - len, " neighbor=%s,%s,%s,%s,%s%s",
14405 bssid, info, op_class, ch, phy_type, buf);
14406 if (ret < 0 || ret >= NEIGHBOR_REPORT_SIZE - len) {
14407 sigma_dut_print(dut, DUT_MSG_ERROR,
14408 "snprintf failed for neighbor report list ret: %d",
14409 ret);
14410 send_resp(dut, conn, SIGMA_ERROR,
14411 "errorCode,snprintf failed for neighbor report");
14412 free(dut->btm_query_cand_list);
14413 dut->btm_query_cand_list = NULL;
14414 return 0;
14415 }
14416
14417 return 1;
14418}
14419
14420
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020014421int sta_extract_60g_ese(struct sigma_dut *dut, struct sigma_cmd *cmd,
14422 struct sigma_ese_alloc *allocs, int *allocs_size)
14423{
14424 int max_count = *allocs_size;
14425 int count = 0, i;
14426 const char *val;
14427
14428 do {
14429 val = get_param_indexed(cmd, "AllocID", count);
14430 if (val)
14431 count++;
14432 } while (val);
14433
14434 if (count == 0 || count > max_count) {
14435 sigma_dut_print(dut, DUT_MSG_ERROR,
14436 "Invalid number of allocations(%d)", count);
14437 return -1;
14438 }
14439
14440 for (i = 0; i < count; i++) {
14441 val = get_param_indexed(cmd, "PercentBI", i);
14442 if (!val) {
14443 sigma_dut_print(dut, DUT_MSG_ERROR,
14444 "Missing PercentBI parameter at index %d",
14445 i);
14446 return -1;
14447 }
14448 allocs[i].percent_bi = atoi(val);
14449
14450 val = get_param_indexed(cmd, "SrcAID", i);
14451 if (val)
14452 allocs[i].src_aid = strtol(val, NULL, 0);
14453 else
14454 allocs[i].src_aid = ESE_BCAST_AID;
14455
14456 val = get_param_indexed(cmd, "DestAID", i);
14457 if (val)
14458 allocs[i].dst_aid = strtol(val, NULL, 0);
14459 else
14460 allocs[i].dst_aid = ESE_BCAST_AID;
14461
14462 allocs[i].type = ESE_CBAP;
14463 sigma_dut_print(dut, DUT_MSG_INFO,
14464 "Alloc %d PercentBI %d SrcAID %d DstAID %d",
14465 i, allocs[i].percent_bi, allocs[i].src_aid,
14466 allocs[i].dst_aid);
14467 }
14468
14469 *allocs_size = count;
14470 return 0;
14471}
14472
14473
14474static int sta_set_60g_ese(struct sigma_dut *dut, int count,
14475 struct sigma_ese_alloc *allocs)
14476{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020014477 switch (get_driver_type(dut)) {
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020014478#ifdef __linux__
14479 case DRIVER_WIL6210:
14480 if (wil6210_set_ese(dut, count, allocs))
14481 return -1;
14482 return 1;
14483#endif /* __linux__ */
14484 default:
14485 sigma_dut_print(dut, DUT_MSG_ERROR,
14486 "Unsupported sta_set_60g_ese with the current driver");
14487 return -1;
14488 }
14489}
14490
14491
14492static int cmd_sta_set_rfeature_60g(const char *intf, struct sigma_dut *dut,
14493 struct sigma_conn *conn,
14494 struct sigma_cmd *cmd)
14495{
14496 const char *val;
14497
14498 val = get_param(cmd, "ExtSchIE");
14499 if (val && !strcasecmp(val, "Enable")) {
14500 struct sigma_ese_alloc allocs[MAX_ESE_ALLOCS];
14501 int count = MAX_ESE_ALLOCS;
14502
14503 if (sta_extract_60g_ese(dut, cmd, allocs, &count))
14504 return -1;
14505 return sta_set_60g_ese(dut, count, allocs);
14506 }
14507
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020014508 val = get_param(cmd, "MCS_FixedRate");
14509 if (val) {
14510 int sta_mcs = atoi(val);
14511
14512 sigma_dut_print(dut, DUT_MSG_INFO, "Force STA MCS to %d",
14513 sta_mcs);
14514 wil6210_set_force_mcs(dut, 1, sta_mcs);
14515
Jouni Malinen0e29cf22019-02-19 01:13:21 +020014516 return SUCCESS_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020014517 }
14518
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020014519 send_resp(dut, conn, SIGMA_ERROR,
14520 "errorCode,Invalid sta_set_rfeature(60G)");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020014521 return STATUS_SENT;
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020014522}
14523
14524
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053014525static int wcn_sta_override_oci(struct sigma_dut *dut, const char *intf,
14526 const char *oci_frametype, uint32_t oci_freq)
14527{
14528#ifdef NL80211_SUPPORT
14529 struct nl_msg *msg;
14530 int ret = 0;
14531 struct nlattr *params;
14532 struct nlattr *attr;
14533 int ifindex;
14534 u8 frame_type;
14535
14536 ifindex = if_nametoindex(intf);
14537 if (ifindex == 0) {
14538 sigma_dut_print(dut, DUT_MSG_ERROR,
14539 "%s: Index for interface %s failed",
14540 __func__, intf);
14541 return -1;
14542 }
14543
14544 if (strcasecmp(oci_frametype, "SAQueryReq") == 0) {
14545 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_SA_QUERY_REQ;
14546 } else if (strcasecmp(oci_frametype, "SAQueryResp") == 0) {
14547 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_SA_QUERY_RESP;
14548 } else if (strcasecmp(oci_frametype, "Reassocreq") == 0) {
14549 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_FT_REASSOC_REQ;
14550 } else {
14551 sigma_dut_print(dut, DUT_MSG_ERROR, "%s: Unknown frametype %s",
14552 __func__, oci_frametype);
14553 return -1;
14554 }
14555
14556
14557 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
14558 NL80211_CMD_VENDOR)) ||
14559 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
14560 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
14561 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
14562 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
14563 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
14564 !(params = nla_nest_start(
14565 msg,
14566 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_OCI_OVERRIDE)) ||
14567 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_OCI_OVERRIDE_FRAME_TYPE,
14568 frame_type) ||
14569 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_OCI_OVERRIDE_FREQUENCY,
14570 oci_freq)) {
14571 sigma_dut_print(dut, DUT_MSG_ERROR,
14572 "%s: err in adding vendor_cmd and vendor_data",
14573 __func__);
14574 nlmsg_free(msg);
14575 return -1;
14576 }
14577 nla_nest_end(msg, params);
14578 nla_nest_end(msg, attr);
14579
14580 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
14581 if (ret) {
14582 sigma_dut_print(dut, DUT_MSG_ERROR,
14583 "%s: err in send_and_recv_msgs, ret=%d",
14584 __func__, ret);
14585 }
14586 return ret;
14587#else /* NL80211_SUPPORT */
14588 sigma_dut_print(dut, DUT_MSG_ERROR,
14589 "OCI override not possible without NL80211_SUPPORT defined");
14590 return -1;
14591#endif /* NL80211_SUPPORT */
14592}
14593
14594
Veerendranath Jakkam50d5c782020-07-22 01:59:01 +053014595static int wcn_sta_ignore_csa(struct sigma_dut *dut, const char *intf,
14596 uint8_t ignore_csa)
14597{
14598#ifdef NL80211_SUPPORT
14599 return wcn_wifi_test_config_set_u8(
14600 dut, intf,
14601 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_IGNORE_CSA, ignore_csa);
14602#else /* NL80211_SUPPORT */
14603 sigma_dut_print(dut, DUT_MSG_ERROR,
14604 "IgnoreCSA can't be set without NL80211_SUPPORT defined");
14605 return -1;
14606#endif /* NL80211_SUPPORT */
14607}
14608
14609
Veerendranath Jakkamc771fac2020-07-22 01:32:56 +053014610static int wcn_sta_set_rsnxe_used(struct sigma_dut *dut, const char *intf,
14611 uint8_t rsnxe_used)
14612{
14613#ifdef NL80211_SUPPORT
14614 return wcn_wifi_test_config_set_u8(
14615 dut, intf,
14616 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_FT_REASSOCREQ_RSNXE_USED,
14617 rsnxe_used);
14618#else /* NL80211_SUPPORT */
14619 sigma_dut_print(dut, DUT_MSG_ERROR,
14620 "RSNXE_Used can't be set without NL80211_SUPPORT defined");
14621 return -1;
14622#endif /* NL80211_SUPPORT */
14623}
14624
14625
Veerendranath Jakkam1e1e5fd2020-09-10 07:12:37 +053014626static int wcn_sta_ignore_sa_query_timeout(struct sigma_dut *dut,
14627 const char *intf,
14628 uint8_t ignore_sa_query_timeout)
14629{
14630#ifdef NL80211_SUPPORT
14631 return wcn_wifi_test_config_set_u8(
14632 dut, intf,
14633 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_IGNORE_SA_QUERY_TIMEOUT,
14634 ignore_sa_query_timeout);
14635#else /* NL80211_SUPPORT */
14636 sigma_dut_print(dut, DUT_MSG_ERROR,
14637 "Ignore SA Query timeout can't be set without NL80211_SUPPORT defined");
14638 return -1;
14639#endif /* NL80211_SUPPORT */
14640}
14641
14642
Jouni Malinen6250cb02020-04-15 13:54:45 +030014643static enum sigma_cmd_result
14644cmd_sta_set_rfeature_wpa3(const char *intf, struct sigma_dut *dut,
14645 struct sigma_conn *conn,
14646 struct sigma_cmd *cmd)
14647{
Vamsi Krishnad29bc762020-05-08 23:23:30 +053014648 const char *val, *oci_chan, *oci_frametype;
Jouni Malinen6250cb02020-04-15 13:54:45 +030014649
Veerendranath Jakkam30bf9072020-04-16 14:37:57 +053014650 val = get_param(cmd, "ReassocReq_RSNXE_Used");
Jouni Malinen6250cb02020-04-15 13:54:45 +030014651 if (val && atoi(val) == 1) {
Veerendranath Jakkamc771fac2020-07-22 01:32:56 +053014652 if (wifi_chip_type == DRIVER_WCN) {
14653 if (wcn_sta_set_rsnxe_used(dut, intf, 1)) {
14654 send_resp(dut, conn, SIGMA_ERROR,
14655 "errorCode,Failed to set ft_rsnxe_used");
14656 return STATUS_SENT_ERROR;
14657 }
14658 return SUCCESS_SEND_STATUS;
14659 } else if (wpa_command(intf, "SET ft_rsnxe_used 1") < 0) {
Jouni Malinen6250cb02020-04-15 13:54:45 +030014660 send_resp(dut, conn, SIGMA_ERROR,
14661 "errorCode,Failed to set ft_rsnxe_used");
14662 return STATUS_SENT_ERROR;
14663 }
14664 return SUCCESS_SEND_STATUS;
14665 }
Vamsi Krishnad29bc762020-05-08 23:23:30 +053014666
14667 oci_chan = get_param(cmd, "OCIChannel");
14668 oci_frametype = get_param(cmd, "OCIFrameType");
14669 if (oci_chan && oci_frametype) {
14670 unsigned int oci_freq = channel_to_freq(dut, atoi(oci_chan));
14671 char buf[100];
14672
14673 if (!oci_freq) {
14674 send_resp(dut, conn, SIGMA_ERROR,
14675 "errorCode,Invalid OCIChannel number");
14676 return STATUS_SENT_ERROR;
14677 }
14678
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053014679 if (wifi_chip_type == DRIVER_WCN &&
14680 (strcasecmp(oci_frametype, "SAQueryReq") == 0 ||
14681 strcasecmp(oci_frametype, "SAQueryResp") == 0 ||
14682 strcasecmp(oci_frametype, "Reassocreq") == 0)) {
14683 if (wcn_sta_override_oci(dut, intf, oci_frametype,
14684 oci_freq)) {
14685 send_resp(dut, conn, SIGMA_ERROR,
14686 "errorCode,Failed to override OCI");
14687 return STATUS_SENT_ERROR;
14688 }
14689 return SUCCESS_SEND_STATUS;
14690 }
14691
Vamsi Krishnad29bc762020-05-08 23:23:30 +053014692 if (strcasecmp(oci_frametype, "eapolM2") == 0) {
14693 snprintf(buf, sizeof(buf),
14694 "SET oci_freq_override_eapol %d", oci_freq);
14695 } else if (strcasecmp(oci_frametype, "SAQueryReq") == 0) {
14696 snprintf(buf, sizeof(buf),
14697 "SET oci_freq_override_saquery_req %d",
14698 oci_freq);
14699 } else if (strcasecmp(oci_frametype, "SAQueryResp") == 0) {
14700 snprintf(buf, sizeof(buf),
14701 "SET oci_freq_override_saquery_resp %d",
14702 oci_freq);
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053014703 } else if (strcasecmp(oci_frametype, "GrpKeyM2") == 0) {
14704 snprintf(buf, sizeof(buf),
14705 "SET oci_freq_override_eapol_g2 %d",
14706 oci_freq);
14707 } else if (strcasecmp(oci_frametype, "Reassocreq") == 0) {
14708 snprintf(buf, sizeof(buf),
14709 "SET oci_freq_override_ft_assoc %d",
14710 oci_freq);
Vamsi Krishnad29bc762020-05-08 23:23:30 +053014711 } else {
14712 send_resp(dut, conn, SIGMA_ERROR,
14713 "errorCode,Unsupported OCIFrameType");
14714 return STATUS_SENT_ERROR;
14715 }
14716 if (wpa_command(intf, buf) < 0) {
14717 send_resp(dut, conn, SIGMA_ERROR,
14718 "errorCode,Failed to set oci_freq_override");
14719 return STATUS_SENT_ERROR;
14720 }
14721 return SUCCESS_SEND_STATUS;
14722 }
14723
Veerendranath Jakkam50d5c782020-07-22 01:59:01 +053014724 val = get_param(cmd, "IgnoreCSA");
14725 if (val && atoi(val) == 1) {
14726 if (wifi_chip_type == DRIVER_WCN) {
14727 if (wcn_sta_ignore_csa(dut, intf, 1)) {
14728 send_resp(dut, conn, SIGMA_ERROR,
14729 "errorCode,Failed to set ignore CSA");
14730 return STATUS_SENT_ERROR;
14731 }
14732 return SUCCESS_SEND_STATUS;
14733 }
14734 }
14735
Veerendranath Jakkam1e1e5fd2020-09-10 07:12:37 +053014736 val = get_param(cmd, "Deauth_Per_SAQueryResp");
14737 if (val && atoi(val) == 0) {
14738 if (wifi_chip_type == DRIVER_WCN) {
14739 if (wcn_sta_ignore_sa_query_timeout(dut, intf, 1)) {
14740 send_resp(dut, conn, SIGMA_ERROR,
14741 "errorCode,Failed to set ignore SA Query timeout");
14742 return STATUS_SENT_ERROR;
14743 }
14744 return SUCCESS_SEND_STATUS;
14745 }
14746 }
14747
Jouni Malinen6250cb02020-04-15 13:54:45 +030014748 send_resp(dut, conn, SIGMA_ERROR,
14749 "errorCode,Unsupported WPA3 rfeature");
14750 return STATUS_SENT_ERROR;
14751}
14752
14753
Veerendranath Jakkam329a3cd2021-09-11 18:10:13 +053014754static enum sigma_cmd_result
14755cmd_sta_set_rfeature_qm(const char *intf, struct sigma_dut *dut,
14756 struct sigma_conn *conn, struct sigma_cmd *cmd)
14757{
14758 const char *val;
14759
14760 val = get_param(cmd, "DomainName_Domain");
14761 if (val) {
14762 if (strlen(val) >= sizeof(dut->qm_domain_name))
14763 return ERROR_SEND_STATUS;
14764
14765 strlcpy(dut->qm_domain_name, val, sizeof(dut->qm_domain_name));
14766 return SUCCESS_SEND_STATUS;
14767 }
14768
14769 send_resp(dut, conn, SIGMA_ERROR,
14770 "errorCode,Unsupported QM rfeature");
14771 return STATUS_SENT_ERROR;
14772}
14773
14774
Jouni Malinenf7222712019-06-13 01:50:21 +030014775static enum sigma_cmd_result cmd_sta_set_rfeature(struct sigma_dut *dut,
14776 struct sigma_conn *conn,
14777 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014778{
14779 const char *intf = get_param(cmd, "Interface");
14780 const char *prog = get_param(cmd, "Prog");
Ashwini Patil68d02cd2017-01-10 15:39:16 +053014781 const char *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014782
Veerendranath Jakkam329a3cd2021-09-11 18:10:13 +053014783 if (!prog)
14784 prog = get_param(cmd, "Program");
14785
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014786 if (intf == NULL || prog == NULL)
14787 return -1;
14788
Ashwini Patil5acd7382017-04-13 15:55:04 +053014789 /* BSS Transition candidate list for BTM query */
14790 val = get_param(cmd, "Nebor_BSSID");
14791 if (val && btm_query_candidate_list(dut, conn, cmd) == 0)
14792 return 0;
14793
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014794 if (strcasecmp(prog, "TDLS") == 0)
14795 return cmd_sta_set_rfeature_tdls(intf, dut, conn, cmd);
14796
14797 if (strcasecmp(prog, "VHT") == 0)
14798 return cmd_sta_set_rfeature_vht(intf, dut, conn, cmd);
14799
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014800 if (strcasecmp(prog, "HE") == 0)
14801 return cmd_sta_set_rfeature_he(intf, dut, conn, cmd);
14802
Ashwini Patil68d02cd2017-01-10 15:39:16 +053014803 if (strcasecmp(prog, "MBO") == 0) {
14804 val = get_param(cmd, "Cellular_Data_Cap");
14805 if (val &&
14806 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
14807 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +053014808
14809 val = get_param(cmd, "Ch_Pref");
14810 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
14811 return 0;
14812
Ashwini Patil68d02cd2017-01-10 15:39:16 +053014813 return 1;
14814 }
14815
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020014816 if (strcasecmp(prog, "60GHz") == 0)
14817 return cmd_sta_set_rfeature_60g(intf, dut, conn, cmd);
14818
Jouni Malinen6250cb02020-04-15 13:54:45 +030014819 if (strcasecmp(prog, "WPA3") == 0)
14820 return cmd_sta_set_rfeature_wpa3(intf, dut, conn, cmd);
Veerendranath Jakkam329a3cd2021-09-11 18:10:13 +053014821 if (strcasecmp(prog, "QM") == 0)
14822 return cmd_sta_set_rfeature_qm(intf, dut, conn, cmd);
Jouni Malinen6250cb02020-04-15 13:54:45 +030014823
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014824 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported Prog");
14825 return 0;
14826}
14827
14828
Jouni Malinenf7222712019-06-13 01:50:21 +030014829static enum sigma_cmd_result cmd_sta_set_radio(struct sigma_dut *dut,
14830 struct sigma_conn *conn,
14831 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014832{
14833 const char *intf = get_param(cmd, "Interface");
14834 const char *mode = get_param(cmd, "Mode");
14835 int res;
14836
14837 if (intf == NULL || mode == NULL)
14838 return -1;
14839
14840 if (strcasecmp(mode, "On") == 0)
14841 res = wpa_command(intf, "SET radio_disabled 0");
14842 else if (strcasecmp(mode, "Off") == 0)
14843 res = wpa_command(intf, "SET radio_disabled 1");
14844 else
14845 return -1;
14846
14847 if (res) {
14848 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
14849 "radio mode");
14850 return 0;
14851 }
14852
14853 return 1;
14854}
14855
14856
Jouni Malinenf7222712019-06-13 01:50:21 +030014857static enum sigma_cmd_result cmd_sta_set_pwrsave(struct sigma_dut *dut,
14858 struct sigma_conn *conn,
14859 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014860{
14861 const char *intf = get_param(cmd, "Interface");
14862 const char *mode = get_param(cmd, "Mode");
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020014863 const char *prog = get_param(cmd, "program");
14864 const char *powersave = get_param(cmd, "powersave");
14865 int res = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014866
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020014867 if (intf == NULL)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014868 return -1;
14869
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020014870 if (prog && strcasecmp(prog, "60GHz") == 0) {
14871 /*
14872 * The CAPI mode parameter does not exist in 60G
14873 * unscheduled PS.
14874 */
Hu Wang5dc3ff12019-06-14 15:14:26 +080014875 if (powersave && strcasecmp(powersave, "unscheduled") == 0)
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020014876 res = set_ps(intf, dut, 1);
Jouni Malinen016ae6c2019-11-04 17:00:01 +020014877 } else if (prog && get_driver_type(dut) == DRIVER_WCN &&
Alexei Avshalom Lazar2f6fdb42019-02-04 14:16:08 +020014878 strcasecmp(prog, "HE") == 0) {
14879 return cmd_sta_set_power_save_he(intf, dut, conn, cmd);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020014880 } else {
14881 if (mode == NULL)
14882 return -1;
14883
14884 if (strcasecmp(mode, "On") == 0)
14885 res = set_ps(intf, dut, 1);
14886 else if (strcasecmp(mode, "Off") == 0)
14887 res = set_ps(intf, dut, 0);
14888 else
14889 return -1;
14890 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014891
14892 if (res) {
14893 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
14894 "power save mode");
14895 return 0;
14896 }
14897
14898 return 1;
14899}
14900
14901
Jouni Malinenf7222712019-06-13 01:50:21 +030014902static enum sigma_cmd_result cmd_sta_bssid_pool(struct sigma_dut *dut,
14903 struct sigma_conn *conn,
14904 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014905{
14906 const char *intf = get_param(cmd, "Interface");
14907 const char *val, *bssid;
14908 int res;
14909 char *buf;
14910 size_t buf_len;
14911
14912 val = get_param(cmd, "BSSID_FILTER");
14913 if (val == NULL)
14914 return -1;
14915
14916 bssid = get_param(cmd, "BSSID_List");
14917 if (atoi(val) == 0 || bssid == NULL) {
14918 /* Disable BSSID filter */
14919 if (wpa_command(intf, "SET bssid_filter ")) {
14920 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed "
14921 "to disable BSSID filter");
14922 return 0;
14923 }
14924
14925 return 1;
14926 }
14927
14928 buf_len = 100 + strlen(bssid);
14929 buf = malloc(buf_len);
14930 if (buf == NULL)
14931 return -1;
14932
14933 snprintf(buf, buf_len, "SET bssid_filter %s", bssid);
14934 res = wpa_command(intf, buf);
14935 free(buf);
14936 if (res) {
14937 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to enable "
14938 "BSSID filter");
14939 return 0;
14940 }
14941
14942 return 1;
14943}
14944
14945
Jouni Malinenf7222712019-06-13 01:50:21 +030014946static enum sigma_cmd_result cmd_sta_reset_parm(struct sigma_dut *dut,
14947 struct sigma_conn *conn,
14948 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014949{
14950 const char *intf = get_param(cmd, "Interface");
14951 const char *val;
14952
14953 /* TODO: ARP */
14954
14955 val = get_param(cmd, "HS2_CACHE_PROFILE");
14956 if (val && strcasecmp(val, "All") == 0)
14957 hs2_clear_credentials(intf);
14958
14959 return 1;
14960}
14961
14962
Jouni Malinenf7222712019-06-13 01:50:21 +030014963static enum sigma_cmd_result cmd_sta_get_key(struct sigma_dut *dut,
14964 struct sigma_conn *conn,
14965 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014966{
14967 const char *intf = get_param(cmd, "Interface");
14968 const char *key_type = get_param(cmd, "KeyType");
14969 char buf[100], resp[200];
14970
14971 if (key_type == NULL)
14972 return -1;
14973
14974 if (strcasecmp(key_type, "GTK") == 0) {
14975 if (wpa_command_resp(intf, "GET gtk", buf, sizeof(buf)) < 0 ||
14976 strncmp(buf, "FAIL", 4) == 0) {
14977 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
14978 "not fetch current GTK");
14979 return 0;
14980 }
14981 snprintf(resp, sizeof(resp), "KeyValue,%s", buf);
14982 send_resp(dut, conn, SIGMA_COMPLETE, resp);
14983 return 0;
14984 } else {
14985 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
14986 "KeyType");
14987 return 0;
14988 }
14989
14990 return 1;
14991}
14992
14993
14994static int hs2_set_policy(struct sigma_dut *dut)
14995{
14996#ifdef ANDROID
14997 system("ip rule del prio 23000");
14998 if (system("ip rule add from all lookup main prio 23000") != 0) {
14999 sigma_dut_print(dut, DUT_MSG_ERROR,
15000 "Failed to run:ip rule add from all lookup main prio");
15001 return -1;
15002 }
15003 if (system("ip route flush cache") != 0) {
15004 sigma_dut_print(dut, DUT_MSG_ERROR,
15005 "Failed to run ip route flush cache");
15006 return -1;
15007 }
15008 return 1;
15009#else /* ANDROID */
15010 return 0;
15011#endif /* ANDROID */
15012}
15013
15014
Jouni Malinenf7222712019-06-13 01:50:21 +030015015static enum sigma_cmd_result cmd_sta_hs2_associate(struct sigma_dut *dut,
15016 struct sigma_conn *conn,
15017 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015018{
15019 const char *intf = get_param(cmd, "Interface");
15020 const char *val = get_param(cmd, "Ignore_blacklist");
Jouni Malinen439352d2018-09-13 03:42:23 +030015021 const char *band = get_param(cmd, "Band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015022 struct wpa_ctrl *ctrl;
Jouni Malinen3aa72862019-05-29 23:14:51 +030015023 int res, r;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015024 char bssid[20], ssid[40], resp[100], buf[100], blacklisted[100];
15025 int tries = 0;
15026 int ignore_blacklist = 0;
15027 const char *events[] = {
15028 "CTRL-EVENT-CONNECTED",
15029 "INTERWORKING-BLACKLISTED",
15030 "INTERWORKING-NO-MATCH",
15031 NULL
15032 };
15033
15034 start_sta_mode(dut);
15035
Jouni Malinen439352d2018-09-13 03:42:23 +030015036 if (band) {
15037 if (strcmp(band, "2.4") == 0) {
15038 wpa_command(intf, "SET setband 2G");
15039 } else if (strcmp(band, "5") == 0) {
15040 wpa_command(intf, "SET setband 5G");
15041 } else {
15042 send_resp(dut, conn, SIGMA_ERROR,
15043 "errorCode,Unsupported band");
15044 return 0;
15045 }
15046 }
15047
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015048 blacklisted[0] = '\0';
15049 if (val && atoi(val))
15050 ignore_blacklist = 1;
15051
15052try_again:
15053 ctrl = open_wpa_mon(intf);
15054 if (ctrl == NULL) {
15055 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
15056 "wpa_supplicant monitor connection");
15057 return -2;
15058 }
15059
15060 tries++;
15061 if (wpa_command(intf, "INTERWORKING_SELECT auto")) {
15062 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start "
15063 "Interworking connection");
15064 wpa_ctrl_detach(ctrl);
15065 wpa_ctrl_close(ctrl);
15066 return 0;
15067 }
15068
15069 buf[0] = '\0';
15070 while (1) {
15071 char *pos;
15072 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
15073 pos = strstr(buf, "INTERWORKING-BLACKLISTED");
15074 if (!pos)
15075 break;
15076 pos += 25;
15077 sigma_dut_print(dut, DUT_MSG_DEBUG, "Found blacklisted AP: %s",
15078 pos);
15079 if (!blacklisted[0])
15080 memcpy(blacklisted, pos, strlen(pos) + 1);
15081 }
15082
15083 if (ignore_blacklist && blacklisted[0]) {
15084 char *end;
15085 end = strchr(blacklisted, ' ');
15086 if (end)
15087 *end = '\0';
15088 sigma_dut_print(dut, DUT_MSG_DEBUG, "Try to connect to a blacklisted network: %s",
15089 blacklisted);
Jouni Malinen3aa72862019-05-29 23:14:51 +030015090 r = snprintf(buf, sizeof(buf), "INTERWORKING_CONNECT %s",
15091 blacklisted);
15092 if (r < 0 || r >= sizeof(buf) || wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015093 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start Interworking connection to blacklisted network");
15094 wpa_ctrl_detach(ctrl);
15095 wpa_ctrl_close(ctrl);
15096 return 0;
15097 }
15098 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
15099 buf, sizeof(buf));
15100 }
15101
15102 wpa_ctrl_detach(ctrl);
15103 wpa_ctrl_close(ctrl);
15104
15105 if (res < 0) {
15106 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
15107 "connect");
15108 return 0;
15109 }
15110
15111 if (strstr(buf, "INTERWORKING-NO-MATCH") ||
15112 strstr(buf, "INTERWORKING-BLACKLISTED")) {
15113 if (tries < 2) {
15114 sigma_dut_print(dut, DUT_MSG_INFO, "No match found - try again to verify no APs were missed in the scan");
15115 goto try_again;
15116 }
15117 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,No network with "
15118 "matching credentials found");
15119 return 0;
15120 }
15121
15122 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
15123 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
15124 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
15125 "get current BSSID/SSID");
15126 return 0;
15127 }
15128
15129 snprintf(resp, sizeof(resp), "SSID,%s,BSSID,%s", ssid, bssid);
15130 send_resp(dut, conn, SIGMA_COMPLETE, resp);
15131 hs2_set_policy(dut);
15132 return 0;
15133}
15134
15135
Jouni Malinenf7222712019-06-13 01:50:21 +030015136static enum sigma_cmd_result cmd_sta_hs2_venue_info(struct sigma_dut *dut,
15137 struct sigma_conn *conn,
15138 struct sigma_cmd *cmd)
Jouni Malinenb639f1c2018-09-13 02:39:46 +030015139{
15140 const char *intf = get_param(cmd, "Interface");
15141 const char *display = get_param(cmd, "Display");
15142 struct wpa_ctrl *ctrl;
15143 char buf[300], params[400], *pos;
15144 char bssid[20];
15145 int info_avail = 0;
15146 unsigned int old_timeout;
15147 int res;
15148
15149 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
15150 send_resp(dut, conn, SIGMA_ERROR,
15151 "ErrorCode,Could not get current BSSID");
15152 return 0;
15153 }
15154 ctrl = open_wpa_mon(intf);
15155 if (!ctrl) {
15156 sigma_dut_print(dut, DUT_MSG_ERROR,
15157 "Failed to open wpa_supplicant monitor connection");
15158 return -2;
15159 }
15160
15161 snprintf(buf, sizeof(buf), "ANQP_GET %s 277", bssid);
15162 wpa_command(intf, buf);
15163
15164 res = get_wpa_cli_event(dut, ctrl, "GAS-QUERY-DONE", buf, sizeof(buf));
15165 if (res < 0) {
15166 send_resp(dut, conn, SIGMA_ERROR,
15167 "ErrorCode,Could not complete GAS query");
15168 goto fail;
15169 }
15170
15171 old_timeout = dut->default_timeout;
15172 dut->default_timeout = 2;
15173 res = get_wpa_cli_event(dut, ctrl, "RX-VENUE-URL", buf, sizeof(buf));
15174 dut->default_timeout = old_timeout;
15175 if (res < 0)
15176 goto done;
15177 pos = strchr(buf, ' ');
15178 if (!pos)
15179 goto done;
15180 pos++;
15181 pos = strchr(pos, ' ');
15182 if (!pos)
15183 goto done;
15184 pos++;
15185 info_avail = 1;
15186 snprintf(params, sizeof(params), "browser %s", pos);
15187
15188 if (display && strcasecmp(display, "Yes") == 0) {
15189 pid_t pid;
15190
15191 pid = fork();
15192 if (pid < 0) {
15193 perror("fork");
15194 return -1;
15195 }
15196
15197 if (pid == 0) {
15198 run_hs20_osu(dut, params);
15199 exit(0);
15200 }
15201 }
15202
15203done:
15204 snprintf(buf, sizeof(buf), "Info_available,%s",
15205 info_avail ? "Yes" : "No");
15206 send_resp(dut, conn, SIGMA_COMPLETE, buf);
15207fail:
15208 wpa_ctrl_detach(ctrl);
15209 wpa_ctrl_close(ctrl);
15210 return 0;
15211}
15212
15213
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015214static int sta_add_credential_uname_pwd(struct sigma_dut *dut,
15215 struct sigma_conn *conn,
15216 const char *ifname,
15217 struct sigma_cmd *cmd)
15218{
15219 const char *val;
15220 int id;
15221
15222 id = add_cred(ifname);
15223 if (id < 0)
15224 return -2;
15225 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
15226
15227 val = get_param(cmd, "prefer");
15228 if (val && atoi(val) > 0)
15229 set_cred(ifname, id, "priority", "1");
15230
15231 val = get_param(cmd, "REALM");
15232 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
15233 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
15234 "realm");
15235 return 0;
15236 }
15237
15238 val = get_param(cmd, "HOME_FQDN");
15239 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
15240 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
15241 "home_fqdn");
15242 return 0;
15243 }
15244
15245 val = get_param(cmd, "Username");
15246 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
15247 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
15248 "username");
15249 return 0;
15250 }
15251
15252 val = get_param(cmd, "Password");
15253 if (val && set_cred_quoted(ifname, id, "password", val) < 0) {
15254 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
15255 "password");
15256 return 0;
15257 }
15258
15259 val = get_param(cmd, "ROOT_CA");
15260 if (val) {
15261 char fname[200];
15262 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
15263#ifdef __linux__
15264 if (!file_exists(fname)) {
15265 char msg[300];
15266 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
15267 "file (%s) not found", fname);
15268 send_resp(dut, conn, SIGMA_ERROR, msg);
15269 return 0;
15270 }
15271#endif /* __linux__ */
15272 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
15273 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
15274 "not set root CA");
15275 return 0;
15276 }
15277 }
15278
15279 return 1;
15280}
15281
15282
15283static int update_devdetail_imsi(struct sigma_dut *dut, const char *imsi)
15284{
15285 FILE *in, *out;
15286 char buf[500];
15287 int found = 0;
15288
15289 in = fopen("devdetail.xml", "r");
15290 if (in == NULL)
15291 return -1;
15292 out = fopen("devdetail.xml.tmp", "w");
15293 if (out == NULL) {
15294 fclose(in);
15295 return -1;
15296 }
15297
15298 while (fgets(buf, sizeof(buf), in)) {
15299 char *pos = strstr(buf, "<IMSI>");
15300 if (pos) {
15301 sigma_dut_print(dut, DUT_MSG_INFO, "Updated DevDetail IMSI to %s",
15302 imsi);
15303 pos += 6;
15304 *pos = '\0';
15305 fprintf(out, "%s%s</IMSI>\n", buf, imsi);
15306 found++;
15307 } else {
15308 fprintf(out, "%s", buf);
15309 }
15310 }
15311
15312 fclose(out);
15313 fclose(in);
15314 if (found)
15315 rename("devdetail.xml.tmp", "devdetail.xml");
15316 else
15317 unlink("devdetail.xml.tmp");
15318
15319 return 0;
15320}
15321
15322
15323static int sta_add_credential_sim(struct sigma_dut *dut,
15324 struct sigma_conn *conn,
15325 const char *ifname, struct sigma_cmd *cmd)
15326{
15327 const char *val, *imsi = NULL;
15328 int id;
15329 char buf[200];
15330 int res;
15331 const char *pos;
15332 size_t mnc_len;
15333 char plmn_mcc[4];
15334 char plmn_mnc[4];
15335
15336 id = add_cred(ifname);
15337 if (id < 0)
15338 return -2;
15339 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
15340
15341 val = get_param(cmd, "prefer");
15342 if (val && atoi(val) > 0)
15343 set_cred(ifname, id, "priority", "1");
15344
15345 val = get_param(cmd, "PLMN_MCC");
15346 if (val == NULL) {
15347 send_resp(dut, conn, SIGMA_ERROR,
15348 "errorCode,Missing PLMN_MCC");
15349 return 0;
15350 }
15351 if (strlen(val) != 3) {
15352 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MCC");
15353 return 0;
15354 }
15355 snprintf(plmn_mcc, sizeof(plmn_mcc), "%s", val);
15356
15357 val = get_param(cmd, "PLMN_MNC");
15358 if (val == NULL) {
15359 send_resp(dut, conn, SIGMA_ERROR,
15360 "errorCode,Missing PLMN_MNC");
15361 return 0;
15362 }
15363 if (strlen(val) != 2 && strlen(val) != 3) {
15364 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MNC");
15365 return 0;
15366 }
15367 snprintf(plmn_mnc, sizeof(plmn_mnc), "%s", val);
15368
15369 val = get_param(cmd, "IMSI");
15370 if (val == NULL) {
15371 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing SIM "
15372 "IMSI");
15373 return 0;
15374 }
15375
15376 imsi = pos = val;
15377
15378 if (strncmp(plmn_mcc, pos, 3) != 0) {
15379 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MCC mismatch");
15380 return 0;
15381 }
15382 pos += 3;
15383
15384 mnc_len = strlen(plmn_mnc);
15385 if (mnc_len < 2) {
15386 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC not set");
15387 return 0;
15388 }
15389
15390 if (strncmp(plmn_mnc, pos, mnc_len) != 0) {
15391 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC mismatch");
15392 return 0;
15393 }
15394 pos += mnc_len;
15395
15396 res = snprintf(buf, sizeof(buf), "%s%s-%s",plmn_mcc, plmn_mnc, pos);
15397 if (res < 0 || res >= (int) sizeof(buf))
15398 return -1;
15399 if (set_cred_quoted(ifname, id, "imsi", buf) < 0) {
15400 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
15401 "not set IMSI");
15402 return 0;
15403 }
15404
15405 val = get_param(cmd, "Password");
15406 if (val && set_cred_quoted(ifname, id, "milenage", val) < 0) {
15407 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
15408 "not set password");
15409 return 0;
15410 }
15411
Jouni Malinenba630452018-06-22 11:49:59 +030015412 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015413 /*
15414 * Set provisioning_sp for the test cases where SIM/USIM
15415 * provisioning is used.
15416 */
15417 if (val && set_cred_quoted(ifname, id, "provisioning_sp",
15418 "wi-fi.org") < 0) {
15419 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
15420 "not set provisioning_sp");
15421 return 0;
15422 }
15423
15424 update_devdetail_imsi(dut, imsi);
15425 }
15426
15427 return 1;
15428}
15429
15430
15431static int sta_add_credential_cert(struct sigma_dut *dut,
15432 struct sigma_conn *conn,
15433 const char *ifname,
15434 struct sigma_cmd *cmd)
15435{
15436 const char *val;
15437 int id;
15438
15439 id = add_cred(ifname);
15440 if (id < 0)
15441 return -2;
15442 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
15443
15444 val = get_param(cmd, "prefer");
15445 if (val && atoi(val) > 0)
15446 set_cred(ifname, id, "priority", "1");
15447
15448 val = get_param(cmd, "REALM");
15449 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
15450 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
15451 "realm");
15452 return 0;
15453 }
15454
15455 val = get_param(cmd, "HOME_FQDN");
15456 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
15457 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
15458 "home_fqdn");
15459 return 0;
15460 }
15461
15462 val = get_param(cmd, "Username");
15463 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
15464 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
15465 "username");
15466 return 0;
15467 }
15468
15469 val = get_param(cmd, "clientCertificate");
15470 if (val) {
15471 char fname[200];
15472 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
15473#ifdef __linux__
15474 if (!file_exists(fname)) {
15475 char msg[300];
15476 snprintf(msg, sizeof(msg),
15477 "ErrorCode,clientCertificate "
15478 "file (%s) not found", fname);
15479 send_resp(dut, conn, SIGMA_ERROR, msg);
15480 return 0;
15481 }
15482#endif /* __linux__ */
15483 if (set_cred_quoted(ifname, id, "client_cert", fname) < 0) {
15484 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
15485 "not set client_cert");
15486 return 0;
15487 }
15488 if (set_cred_quoted(ifname, id, "private_key", fname) < 0) {
15489 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
15490 "not set private_key");
15491 return 0;
15492 }
15493 }
15494
15495 val = get_param(cmd, "ROOT_CA");
15496 if (val) {
15497 char fname[200];
15498 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
15499#ifdef __linux__
15500 if (!file_exists(fname)) {
15501 char msg[300];
15502 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
15503 "file (%s) not found", fname);
15504 send_resp(dut, conn, SIGMA_ERROR, msg);
15505 return 0;
15506 }
15507#endif /* __linux__ */
15508 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
15509 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
15510 "not set root CA");
15511 return 0;
15512 }
15513 }
15514
15515 return 1;
15516}
15517
15518
Jouni Malinenf7222712019-06-13 01:50:21 +030015519static enum sigma_cmd_result cmd_sta_add_credential(struct sigma_dut *dut,
15520 struct sigma_conn *conn,
15521 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015522{
15523 const char *intf = get_param(cmd, "Interface");
15524 const char *type;
15525
15526 start_sta_mode(dut);
15527
15528 type = get_param(cmd, "Type");
15529 if (!type)
15530 return -1;
15531
15532 if (strcasecmp(type, "uname_pwd") == 0)
15533 return sta_add_credential_uname_pwd(dut, conn, intf, cmd);
15534
15535 if (strcasecmp(type, "sim") == 0)
15536 return sta_add_credential_sim(dut, conn, intf, cmd);
15537
15538 if (strcasecmp(type, "cert") == 0)
15539 return sta_add_credential_cert(dut, conn, intf, cmd);
15540
15541 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported credential "
15542 "type");
15543 return 0;
15544}
15545
15546
Jouni Malinenf7222712019-06-13 01:50:21 +030015547static enum sigma_cmd_result cmd_sta_scan(struct sigma_dut *dut,
15548 struct sigma_conn *conn,
15549 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015550{
15551 const char *intf = get_param(cmd, "Interface");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080015552 const char *val, *bssid, *ssid, *scan_freq, *short_ssid;
Veerendranathdc581b52020-08-10 03:29:08 -070015553 char buf[4096], scan_res[20];
vamsi krishna89ad8c62017-09-19 12:51:18 +053015554 char ssid_hex[65];
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080015555 int wildcard_ssid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015556 int res;
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080015557 enum sigma_cmd_result status;
Jouni Malinen228a2fc2020-06-22 23:37:45 +030015558 struct wpa_ctrl *ctrl = NULL;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015559
Jouni Malinen8c1abeb2019-11-06 18:48:34 +020015560 start_sta_mode(dut);
15561
Arif Hussain66a4af02019-02-07 15:04:51 -080015562 val = get_param(cmd, "GetParameter");
15563 if (val && strcmp(val, "SSID_BSSID") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020015564 if (get_wpa_ssid_bssid(dut, get_station_ifname(dut),
Arif Hussain66a4af02019-02-07 15:04:51 -080015565 buf, sizeof(buf)) < 0) {
15566 sigma_dut_print(dut, DUT_MSG_ERROR,
15567 "Could not get ssid bssid");
15568 return ERROR_SEND_STATUS;
15569 }
15570
15571 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
15572 send_resp(dut, conn, SIGMA_COMPLETE, buf);
15573 return STATUS_SENT;
15574 }
15575
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015576 val = get_param(cmd, "HESSID");
15577 if (val) {
15578 res = snprintf(buf, sizeof(buf), "SET hessid %s", val);
15579 if (res < 0 || res >= (int) sizeof(buf))
15580 return -1;
15581 wpa_command(intf, buf);
15582 }
15583
15584 val = get_param(cmd, "ACCS_NET_TYPE");
15585 if (val) {
15586 res = snprintf(buf, sizeof(buf), "SET access_network_type %s",
15587 val);
15588 if (res < 0 || res >= (int) sizeof(buf))
15589 return -1;
15590 wpa_command(intf, buf);
15591 }
15592
Kiran Kumar Lokere69d89952021-08-08 23:41:46 -070015593 if (get_param(cmd, "RxMac"))
15594 sta_set_scan_unicast_probe(dut, intf, 1);
15595
vamsi krishna89ad8c62017-09-19 12:51:18 +053015596 bssid = get_param(cmd, "Bssid");
15597 ssid = get_param(cmd, "Ssid");
Kiran Kumar Lokere69d89952021-08-08 23:41:46 -070015598 if (!bssid)
15599 bssid = get_param(cmd, "RxMac");
vamsi krishna89ad8c62017-09-19 12:51:18 +053015600
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080015601 if (ssid && strcasecmp(ssid, "ZeroLength") == 0 &&
15602 dut->device_type == STA_testbed) {
15603 ssid = NULL;
15604 wildcard_ssid = 1;
15605 }
15606
vamsi krishna89ad8c62017-09-19 12:51:18 +053015607 if (ssid) {
15608 if (2 * strlen(ssid) >= sizeof(ssid_hex)) {
15609 send_resp(dut, conn, SIGMA_ERROR,
15610 "ErrorCode,Too long SSID");
15611 return 0;
15612 }
15613 ascii2hexstr(ssid, ssid_hex);
15614 }
15615
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080015616 short_ssid = get_param(cmd, "ShortSSID");
15617 if (short_ssid) {
15618 uint32_t short_ssid_hex;
15619
15620 short_ssid_hex = strtoul(short_ssid, NULL, 16);
15621 short_ssid_hex = ((short_ssid_hex & 0xFF) << 24) |
15622 (((short_ssid_hex >> 8) & 0xFF) << 16) |
15623 (((short_ssid_hex >> 16) & 0xFF) << 8) |
15624 ((short_ssid_hex >> 24) & 0xFF);
15625
15626 res = snprintf(buf, sizeof(buf),
15627 "VENDOR_ELEM_ADD 14 ff053a%08x",
15628 short_ssid_hex);
15629 if (res < 0 || res >= (int) sizeof(buf) ||
15630 wpa_command(intf, buf)) {
15631 send_resp(dut, conn, SIGMA_ERROR,
15632 "errorCode,Failed to add short SSID");
15633 return STATUS_SENT_ERROR;
15634 }
15635 }
15636
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080015637 scan_freq = get_param(cmd, "ChnlFreq");
Veerendranath Jakkam132c4b42020-08-10 00:29:03 +053015638 if (scan_freq) {
15639 if (strcasecmp(scan_freq, "2G") == 0)
15640 scan_freq = "2412-2462";
15641 else if (strcasecmp(scan_freq, "5G") == 0)
15642 scan_freq = "5180-5925";
15643 }
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080015644
Jouni Malinen228a2fc2020-06-22 23:37:45 +030015645 val = get_param(cmd, "WaitCompletion");
15646 if (val && atoi(val) == 1) {
15647 ctrl = open_wpa_mon(intf);
15648 if (!ctrl) {
15649 send_resp(dut, conn, SIGMA_ERROR,
15650 "errorCode,Failed to open monitor socket");
15651 return STATUS_SENT_ERROR;
15652 }
15653 }
15654
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080015655 res = snprintf(buf, sizeof(buf), "SCAN%s%s%s%s%s%s%s",
vamsi krishna89ad8c62017-09-19 12:51:18 +053015656 bssid ? " bssid=": "",
15657 bssid ? bssid : "",
15658 ssid ? " ssid " : "",
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080015659 ssid ? ssid_hex : "",
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080015660 wildcard_ssid ? " wildcard_ssid=1" : "",
15661 scan_freq ? " freq=" : "",
15662 scan_freq ? scan_freq : "");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080015663 if (res < 0 || res >= (int) sizeof(buf)) {
15664 send_resp(dut, conn, SIGMA_ERROR,
15665 "errorCode,Could not build scan command");
15666 status = STATUS_SENT_ERROR;
15667 goto remove_s_ssid;
15668 }
vamsi krishna89ad8c62017-09-19 12:51:18 +053015669
Veerendranathdc581b52020-08-10 03:29:08 -070015670 res = wpa_command_resp(intf, buf, scan_res, sizeof(scan_res));
15671 if (strncmp(scan_res, "FAIL-BUSY", 9) == 0) {
15672 sigma_dut_print(dut, DUT_MSG_DEBUG,
15673 "Scan request rejected with busy status, abort ongoing scan and try again");
15674 wpa_command(intf, "ABORT_SCAN");
15675 res = wpa_command(intf, buf);
15676 }
15677
15678 if (res < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015679 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not start "
15680 "scan");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080015681 status = STATUS_SENT_ERROR;
15682 } else {
15683 status = SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015684 }
15685
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080015686remove_s_ssid:
15687 if (short_ssid && wpa_command(intf, "VENDOR_ELEM_REMOVE 14 *"))
15688 sigma_dut_print(dut, DUT_MSG_ERROR,
15689 "Failed to delete vendor element");
15690
Jouni Malinen228a2fc2020-06-22 23:37:45 +030015691 if (ctrl) {
15692 if (status == SUCCESS_SEND_STATUS) {
15693 res = get_wpa_cli_event(dut, ctrl,
15694 "CTRL-EVENT-SCAN-RESULTS",
15695 buf, sizeof(buf));
15696 if (res < 0) {
15697 send_resp(dut, conn, SIGMA_ERROR,
15698 "ErrorCode,scan did not complete");
15699 status = STATUS_SENT_ERROR;
15700 }
15701 }
15702
15703 wpa_ctrl_detach(ctrl);
15704 wpa_ctrl_close(ctrl);
15705 }
15706
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080015707 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015708}
15709
15710
Jouni Malinenf7222712019-06-13 01:50:21 +030015711static enum sigma_cmd_result cmd_sta_scan_bss(struct sigma_dut *dut,
15712 struct sigma_conn *conn,
15713 struct sigma_cmd *cmd)
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020015714{
15715 const char *intf = get_param(cmd, "Interface");
15716 const char *bssid;
15717 char buf[4096], *pos;
15718 int freq, chan;
15719 char *ssid;
15720 char resp[100];
15721 int res;
15722 struct wpa_ctrl *ctrl;
15723
15724 bssid = get_param(cmd, "BSSID");
15725 if (!bssid) {
15726 send_resp(dut, conn, SIGMA_INVALID,
15727 "errorCode,BSSID argument is missing");
15728 return 0;
15729 }
15730
15731 ctrl = open_wpa_mon(intf);
15732 if (!ctrl) {
15733 sigma_dut_print(dut, DUT_MSG_ERROR,
15734 "Failed to open wpa_supplicant monitor connection");
15735 return -1;
15736 }
15737
15738 if (wpa_command(intf, "SCAN TYPE=ONLY")) {
15739 send_resp(dut, conn, SIGMA_ERROR,
15740 "errorCode,Could not start scan");
15741 wpa_ctrl_detach(ctrl);
15742 wpa_ctrl_close(ctrl);
15743 return 0;
15744 }
15745
15746 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
15747 buf, sizeof(buf));
15748
15749 wpa_ctrl_detach(ctrl);
15750 wpa_ctrl_close(ctrl);
15751
15752 if (res < 0) {
15753 send_resp(dut, conn, SIGMA_ERROR,
15754 "errorCode,Scan did not complete");
15755 return 0;
15756 }
15757
15758 snprintf(buf, sizeof(buf), "BSS %s", bssid);
15759 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
15760 strncmp(buf, "id=", 3) != 0) {
15761 send_resp(dut, conn, SIGMA_ERROR,
15762 "errorCode,Specified BSSID not found");
15763 return 0;
15764 }
15765
15766 pos = strstr(buf, "\nfreq=");
15767 if (!pos) {
15768 send_resp(dut, conn, SIGMA_ERROR,
15769 "errorCode,Channel not found");
15770 return 0;
15771 }
15772 freq = atoi(pos + 6);
15773 chan = freq_to_channel(freq);
15774
15775 pos = strstr(buf, "\nssid=");
15776 if (!pos) {
15777 send_resp(dut, conn, SIGMA_ERROR,
15778 "errorCode,SSID not found");
15779 return 0;
15780 }
15781 ssid = pos + 6;
15782 pos = strchr(ssid, '\n');
15783 if (pos)
15784 *pos = '\0';
15785 snprintf(resp, sizeof(resp), "ssid,%s,bsschannel,%d", ssid, chan);
15786 send_resp(dut, conn, SIGMA_COMPLETE, resp);
15787 return 0;
15788}
15789
15790
Jouni Malinenf7222712019-06-13 01:50:21 +030015791static enum sigma_cmd_result cmd_sta_set_systime(struct sigma_dut *dut,
15792 struct sigma_conn *conn,
15793 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015794{
15795#ifdef __linux__
15796 struct timeval tv;
15797 struct tm tm;
15798 time_t t;
15799 const char *val;
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053015800 int v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015801
Jouni Malinen016ae6c2019-11-04 17:00:01 +020015802 wpa_command(get_station_ifname(dut), "PMKSA_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015803
15804 memset(&tm, 0, sizeof(tm));
15805 val = get_param(cmd, "seconds");
15806 if (val)
15807 tm.tm_sec = atoi(val);
15808 val = get_param(cmd, "minutes");
15809 if (val)
15810 tm.tm_min = atoi(val);
15811 val = get_param(cmd, "hours");
15812 if (val)
15813 tm.tm_hour = atoi(val);
15814 val = get_param(cmd, "date");
15815 if (val)
15816 tm.tm_mday = atoi(val);
15817 val = get_param(cmd, "month");
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053015818 if (val) {
15819 v = atoi(val);
15820 if (v < 1 || v > 12) {
15821 send_resp(dut, conn, SIGMA_INVALID,
15822 "errorCode,Invalid month");
15823 return 0;
15824 }
15825 tm.tm_mon = v - 1;
15826 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015827 val = get_param(cmd, "year");
15828 if (val) {
15829 int year = atoi(val);
15830#ifdef ANDROID
15831 if (year > 2035)
15832 year = 2035; /* years beyond 2035 not supported */
15833#endif /* ANDROID */
15834 tm.tm_year = year - 1900;
15835 }
15836 t = mktime(&tm);
15837 if (t == (time_t) -1) {
15838 send_resp(dut, conn, SIGMA_ERROR,
15839 "errorCode,Invalid date or time");
15840 return 0;
15841 }
15842
15843 memset(&tv, 0, sizeof(tv));
15844 tv.tv_sec = t;
15845
15846 if (settimeofday(&tv, NULL) < 0) {
15847 sigma_dut_print(dut, DUT_MSG_INFO, "settimeofday failed: %s",
15848 strerror(errno));
15849 send_resp(dut, conn, SIGMA_ERROR,
15850 "errorCode,Failed to set time");
15851 return 0;
15852 }
15853
15854 return 1;
15855#endif /* __linux__ */
15856
15857 return -1;
15858}
15859
15860
Jouni Malinenf7222712019-06-13 01:50:21 +030015861static enum sigma_cmd_result cmd_sta_osu(struct sigma_dut *dut,
15862 struct sigma_conn *conn,
15863 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015864{
15865 const char *intf = get_param(cmd, "Interface");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030015866 const char *name, *osu_ssid, *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015867 int prod_ess_assoc = 1;
Jouni Malinen4c8681c2018-09-12 23:28:11 +030015868 char buf[300], bssid[100], ssid[100];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015869 int res;
15870 struct wpa_ctrl *ctrl;
15871
15872 name = get_param(cmd, "osuFriendlyName");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030015873 osu_ssid = get_param(cmd, "osu_ssid");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015874
15875 val = get_param(cmd, "ProdESSAssoc");
15876 if (val)
15877 prod_ess_assoc = atoi(val);
15878
15879 kill_dhcp_client(dut, intf);
15880 if (start_dhcp_client(dut, intf) < 0)
15881 return -2;
15882
15883 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger OSU");
15884 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
15885 res = snprintf(buf, sizeof(buf),
Jouni Malinen4c8681c2018-09-12 23:28:11 +030015886 "%s %s%s%s %s%s%s signup osu-ca.pem",
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015887 prod_ess_assoc ? "" : "-N",
15888 name ? "-O'" : "", name ? name : "",
Jouni Malinen4c8681c2018-09-12 23:28:11 +030015889 name ? "'" : "",
15890 osu_ssid ? "-o'" : "", osu_ssid ? osu_ssid : "",
15891 osu_ssid ? "'" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015892
Kanchanapally, Vidyullatha12b66762015-12-31 16:46:42 +053015893 hs2_set_policy(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015894 if (run_hs20_osu(dut, buf) < 0) {
15895 FILE *f;
15896
15897 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to complete OSU");
15898
15899 f = fopen("hs20-osu-client.res", "r");
15900 if (f) {
15901 char resp[400], res[300], *pos;
15902 if (!fgets(res, sizeof(res), f))
15903 res[0] = '\0';
15904 pos = strchr(res, '\n');
15905 if (pos)
15906 *pos = '\0';
15907 fclose(f);
15908 sigma_dut_summary(dut, "hs20-osu-client provisioning failed: %s",
15909 res);
15910 snprintf(resp, sizeof(resp), "notify-send '%s'", res);
15911 if (system(resp) != 0) {
15912 }
15913 snprintf(resp, sizeof(resp),
15914 "SSID,,BSSID,,failureReason,%s", res);
15915 send_resp(dut, conn, SIGMA_COMPLETE, resp);
15916 return 0;
15917 }
15918
15919 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
15920 return 0;
15921 }
15922
15923 if (!prod_ess_assoc)
15924 goto report;
15925
15926 ctrl = open_wpa_mon(intf);
15927 if (ctrl == NULL) {
15928 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
15929 "wpa_supplicant monitor connection");
15930 return -1;
15931 }
15932
15933 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
15934 buf, sizeof(buf));
15935
15936 wpa_ctrl_detach(ctrl);
15937 wpa_ctrl_close(ctrl);
15938
15939 if (res < 0) {
15940 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to connect to "
15941 "network after OSU");
15942 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
15943 return 0;
15944 }
15945
15946report:
15947 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
15948 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
15949 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get BSSID/SSID");
15950 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
15951 return 0;
15952 }
15953
15954 snprintf(buf, sizeof(buf), "SSID,%s,BSSID,%s", ssid, bssid);
15955 send_resp(dut, conn, SIGMA_COMPLETE, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015956 return 0;
15957}
15958
15959
Jouni Malinenf7222712019-06-13 01:50:21 +030015960static enum sigma_cmd_result cmd_sta_policy_update(struct sigma_dut *dut,
15961 struct sigma_conn *conn,
15962 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015963{
15964 const char *val;
15965 int timeout = 120;
15966
15967 val = get_param(cmd, "PolicyUpdate");
15968 if (val == NULL || atoi(val) == 0)
15969 return 1; /* No operation requested */
15970
15971 val = get_param(cmd, "Timeout");
15972 if (val)
15973 timeout = atoi(val);
15974
15975 if (timeout) {
15976 /* TODO: time out the command and return
15977 * PolicyUpdateStatus,TIMEOUT if needed. */
15978 }
15979
15980 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger policy update");
15981 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
15982 if (run_hs20_osu(dut, "pol_upd fqdn=wi-fi.org") < 0) {
15983 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,FAIL");
15984 return 0;
15985 }
15986
15987 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,SUCCESS");
15988 return 0;
15989}
15990
15991
Jouni Malinenf7222712019-06-13 01:50:21 +030015992static enum sigma_cmd_result cmd_sta_er_config(struct sigma_dut *dut,
15993 struct sigma_conn *conn,
15994 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015995{
15996 struct wpa_ctrl *ctrl;
15997 const char *intf = get_param(cmd, "Interface");
15998 const char *bssid = get_param(cmd, "Bssid");
15999 const char *ssid = get_param(cmd, "SSID");
16000 const char *security = get_param(cmd, "Security");
16001 const char *passphrase = get_param(cmd, "Passphrase");
16002 const char *pin = get_param(cmd, "PIN");
16003 char buf[1000];
16004 char ssid_hex[200], passphrase_hex[200];
16005 const char *keymgmt, *cipher;
16006
16007 if (intf == NULL)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020016008 intf = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016009
16010 if (!bssid) {
16011 send_resp(dut, conn, SIGMA_ERROR,
16012 "ErrorCode,Missing Bssid argument");
16013 return 0;
16014 }
16015
16016 if (!ssid) {
16017 send_resp(dut, conn, SIGMA_ERROR,
16018 "ErrorCode,Missing SSID argument");
16019 return 0;
16020 }
16021
16022 if (!security) {
16023 send_resp(dut, conn, SIGMA_ERROR,
16024 "ErrorCode,Missing Security argument");
16025 return 0;
16026 }
16027
16028 if (!passphrase) {
16029 send_resp(dut, conn, SIGMA_ERROR,
16030 "ErrorCode,Missing Passphrase argument");
16031 return 0;
16032 }
16033
16034 if (!pin) {
16035 send_resp(dut, conn, SIGMA_ERROR,
16036 "ErrorCode,Missing PIN argument");
16037 return 0;
16038 }
16039
vamsi krishna8c9c1562017-05-12 15:51:46 +053016040 if (2 * strlen(ssid) >= sizeof(ssid_hex) ||
16041 2 * strlen(passphrase) >= sizeof(passphrase_hex)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016042 send_resp(dut, conn, SIGMA_ERROR,
16043 "ErrorCode,Too long SSID/passphrase");
16044 return 0;
16045 }
16046
16047 ctrl = open_wpa_mon(intf);
16048 if (ctrl == NULL) {
16049 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
16050 "wpa_supplicant monitor connection");
16051 return -2;
16052 }
16053
16054 if (strcasecmp(security, "wpa2-psk") == 0) {
16055 keymgmt = "WPA2PSK";
16056 cipher = "CCMP";
16057 } else {
16058 wpa_ctrl_detach(ctrl);
16059 wpa_ctrl_close(ctrl);
16060 send_resp(dut, conn, SIGMA_ERROR,
16061 "ErrorCode,Unsupported Security value");
16062 return 0;
16063 }
16064
16065 ascii2hexstr(ssid, ssid_hex);
16066 ascii2hexstr(passphrase, passphrase_hex);
16067 snprintf(buf, sizeof(buf), "WPS_REG %s %s %s %s %s %s",
16068 bssid, pin, ssid_hex, keymgmt, cipher, passphrase_hex);
16069
16070 if (wpa_command(intf, buf) < 0) {
16071 wpa_ctrl_detach(ctrl);
16072 wpa_ctrl_close(ctrl);
16073 send_resp(dut, conn, SIGMA_ERROR,
16074 "ErrorCode,Failed to start registrar");
16075 return 0;
16076 }
16077
16078 snprintf(dut->er_oper_bssid, sizeof(dut->er_oper_bssid), "%s", bssid);
16079 dut->er_oper_performed = 1;
16080
16081 return wps_connection_event(dut, conn, ctrl, intf, 0);
16082}
16083
16084
Jouni Malinenf7222712019-06-13 01:50:21 +030016085static enum sigma_cmd_result
16086cmd_sta_wps_connect_pw_token(struct sigma_dut *dut, struct sigma_conn *conn,
16087 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016088{
16089 struct wpa_ctrl *ctrl;
16090 const char *intf = get_param(cmd, "Interface");
16091 const char *bssid = get_param(cmd, "Bssid");
16092 char buf[100];
16093
16094 if (!bssid) {
16095 send_resp(dut, conn, SIGMA_ERROR,
16096 "ErrorCode,Missing Bssid argument");
16097 return 0;
16098 }
16099
16100 ctrl = open_wpa_mon(intf);
16101 if (ctrl == NULL) {
16102 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
16103 "wpa_supplicant monitor connection");
16104 return -2;
16105 }
16106
16107 snprintf(buf, sizeof(buf), "WPS_NFC %s", bssid);
16108
16109 if (wpa_command(intf, buf) < 0) {
16110 wpa_ctrl_detach(ctrl);
16111 wpa_ctrl_close(ctrl);
16112 send_resp(dut, conn, SIGMA_ERROR,
16113 "ErrorCode,Failed to start registrar");
16114 return 0;
16115 }
16116
16117 return wps_connection_event(dut, conn, ctrl, intf, 0);
16118}
16119
16120
Jouni Malinenf7222712019-06-13 01:50:21 +030016121static enum sigma_cmd_result cmd_start_wps_registration(struct sigma_dut *dut,
16122 struct sigma_conn *conn,
16123 struct sigma_cmd *cmd)
vamsi krishna9b144002017-09-20 13:28:13 +053016124{
16125 struct wpa_ctrl *ctrl;
16126 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020016127 const char *network_mode = get_param(cmd, "network_mode");
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020016128 const char *config_method = get_param(cmd, "WPSConfigMethod");
16129 const char *role;
vamsi krishna9b144002017-09-20 13:28:13 +053016130 int res;
16131 char buf[256];
16132 const char *events[] = {
16133 "CTRL-EVENT-CONNECTED",
16134 "WPS-OVERLAP-DETECTED",
16135 "WPS-TIMEOUT",
16136 "WPS-FAIL",
16137 NULL
16138 };
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020016139 int id = 0;
vamsi krishna9b144002017-09-20 13:28:13 +053016140
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020016141 /* 60G WPS tests do not pass Interface parameter */
16142 if (!intf)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020016143 intf = get_main_ifname(dut);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020016144
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020016145 if (dut->mode == SIGMA_MODE_AP)
16146 return ap_wps_registration(dut, conn, cmd);
16147
16148 if (config_method) {
16149 /* WFA_CS_WPS_PIN_KEYPAD mode is set when using the
16150 * sta_wps_enter_pin before calling start_wps_registration. */
16151 if (strcasecmp(config_method, "PBC") == 0)
16152 dut->wps_method = WFA_CS_WPS_PBC;
16153 }
16154 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
16155 send_resp(dut, conn, SIGMA_ERROR,
16156 "ErrorCode,WPS parameters not yet set");
16157 return STATUS_SENT;
16158 }
16159
16160 /* Make sure WPS is enabled (also for STA mode) */
16161 dut->wps_disable = 0;
16162
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020016163 if (dut->band == WPS_BAND_60G && network_mode &&
16164 strcasecmp(network_mode, "PBSS") == 0) {
16165 sigma_dut_print(dut, DUT_MSG_DEBUG,
16166 "Set PBSS network mode, network id %d", id);
Jouni Malinen016ae6c2019-11-04 17:00:01 +020016167 if (set_network(get_station_ifname(dut), id, "pbss", "1") < 0)
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020016168 return -2;
16169 }
16170
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020016171 if (dut->force_rsn_ie) {
16172 sigma_dut_print(dut, DUT_MSG_DEBUG, "Force RSN_IE: %d",
16173 dut->force_rsn_ie);
16174 if (sta_60g_force_rsn_ie(dut, dut->force_rsn_ie) < 0) {
16175 sigma_dut_print(dut, DUT_MSG_INFO,
16176 "Failed to force RSN_IE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020016177 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020016178 }
16179 }
16180
vamsi krishna9b144002017-09-20 13:28:13 +053016181 ctrl = open_wpa_mon(intf);
16182 if (!ctrl) {
16183 sigma_dut_print(dut, DUT_MSG_ERROR,
16184 "Failed to open wpa_supplicant monitor connection");
16185 return -2;
16186 }
16187
16188 role = get_param(cmd, "WpsRole");
16189 if (!role) {
16190 send_resp(dut, conn, SIGMA_INVALID,
16191 "ErrorCode,WpsRole not provided");
16192 goto fail;
16193 }
16194
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020016195 if (strcasecmp(role, "Enrollee") != 0) {
16196 /* Registrar role for STA not supported */
16197 send_resp(dut, conn, SIGMA_ERROR,
16198 "ErrorCode,Unsupported WpsRole value");
16199 goto fail;
16200 }
16201
16202 if (is_60g_sigma_dut(dut)) {
16203 if (dut->wps_method == WFA_CS_WPS_PBC)
16204 snprintf(buf, sizeof(buf), "WPS_PBC");
16205 else /* WFA_CS_WPS_PIN_KEYPAD */
16206 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
16207 dut->wps_pin);
16208 if (wpa_command(intf, buf) < 0) {
16209 send_resp(dut, conn, SIGMA_ERROR,
16210 "ErrorCode,Failed to start WPS");
vamsi krishna9b144002017-09-20 13:28:13 +053016211 goto fail;
16212 }
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020016213 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
16214 if (res < 0) {
16215 send_resp(dut, conn, SIGMA_ERROR,
16216 "ErrorCode,WPS connection did not complete");
16217 goto fail;
16218 }
16219 if (strstr(buf, "WPS-TIMEOUT")) {
16220 send_resp(dut, conn, SIGMA_COMPLETE, "WpsState,NoPeer");
16221 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
16222 send_resp(dut, conn, SIGMA_COMPLETE,
16223 "WpsState,OverlapSession");
16224 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
16225 send_resp(dut, conn, SIGMA_COMPLETE,
16226 "WpsState,Successful");
16227 } else {
16228 send_resp(dut, conn, SIGMA_COMPLETE,
16229 "WpsState,Failure");
16230 }
16231 } else {
16232 if (dut->wps_method == WFA_CS_WPS_PBC) {
vamsi krishna9b144002017-09-20 13:28:13 +053016233 if (wpa_command(intf, "WPS_PBC") < 0) {
16234 send_resp(dut, conn, SIGMA_ERROR,
16235 "ErrorCode,Failed to enable PBC");
16236 goto fail;
16237 }
16238 } else {
16239 /* TODO: PIN method */
16240 send_resp(dut, conn, SIGMA_ERROR,
16241 "ErrorCode,Unsupported WpsConfigMethod value");
16242 goto fail;
16243 }
16244 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
16245 if (res < 0) {
16246 send_resp(dut, conn, SIGMA_ERROR,
16247 "ErrorCode,WPS connection did not complete");
16248 goto fail;
16249 }
16250 if (strstr(buf, "WPS-TIMEOUT")) {
16251 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,NoPeer");
16252 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
16253 send_resp(dut, conn, SIGMA_ERROR,
16254 "ErrorCode,OverlapSession");
16255 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
16256 send_resp(dut, conn, SIGMA_COMPLETE, "Successful");
16257 } else {
16258 send_resp(dut, conn, SIGMA_ERROR,
16259 "ErrorCode,WPS operation failed");
16260 }
vamsi krishna9b144002017-09-20 13:28:13 +053016261 }
16262
16263fail:
16264 wpa_ctrl_detach(ctrl);
16265 wpa_ctrl_close(ctrl);
16266 return 0;
16267}
16268
16269
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016270static int req_intf(struct sigma_cmd *cmd)
16271{
16272 return get_param(cmd, "interface") == NULL ? -1 : 0;
16273}
16274
16275
16276void sta_register_cmds(void)
16277{
16278 sigma_dut_reg_cmd("sta_get_ip_config", req_intf,
16279 cmd_sta_get_ip_config);
16280 sigma_dut_reg_cmd("sta_set_ip_config", req_intf,
16281 cmd_sta_set_ip_config);
16282 sigma_dut_reg_cmd("sta_get_info", req_intf, cmd_sta_get_info);
16283 sigma_dut_reg_cmd("sta_get_mac_address", req_intf,
16284 cmd_sta_get_mac_address);
16285 sigma_dut_reg_cmd("sta_is_connected", req_intf, cmd_sta_is_connected);
16286 sigma_dut_reg_cmd("sta_verify_ip_connection", req_intf,
16287 cmd_sta_verify_ip_connection);
16288 sigma_dut_reg_cmd("sta_get_bssid", req_intf, cmd_sta_get_bssid);
16289 sigma_dut_reg_cmd("sta_set_encryption", req_intf,
16290 cmd_sta_set_encryption);
16291 sigma_dut_reg_cmd("sta_set_psk", req_intf, cmd_sta_set_psk);
16292 sigma_dut_reg_cmd("sta_set_eaptls", req_intf, cmd_sta_set_eaptls);
16293 sigma_dut_reg_cmd("sta_set_eapttls", req_intf, cmd_sta_set_eapttls);
16294 sigma_dut_reg_cmd("sta_set_eapsim", req_intf, cmd_sta_set_eapsim);
16295 sigma_dut_reg_cmd("sta_set_peap", req_intf, cmd_sta_set_peap);
16296 sigma_dut_reg_cmd("sta_set_eapfast", req_intf, cmd_sta_set_eapfast);
16297 sigma_dut_reg_cmd("sta_set_eapaka", req_intf, cmd_sta_set_eapaka);
16298 sigma_dut_reg_cmd("sta_set_eapakaprime", req_intf,
16299 cmd_sta_set_eapakaprime);
16300 sigma_dut_reg_cmd("sta_set_security", req_intf, cmd_sta_set_security);
16301 sigma_dut_reg_cmd("sta_set_uapsd", req_intf, cmd_sta_set_uapsd);
16302 /* TODO: sta_set_ibss */
16303 /* TODO: sta_set_mode */
16304 sigma_dut_reg_cmd("sta_set_wmm", req_intf, cmd_sta_set_wmm);
16305 sigma_dut_reg_cmd("sta_associate", req_intf, cmd_sta_associate);
16306 /* TODO: sta_up_load */
16307 sigma_dut_reg_cmd("sta_preset_testparameters", req_intf,
16308 cmd_sta_preset_testparameters);
16309 /* TODO: sta_set_system */
16310 sigma_dut_reg_cmd("sta_set_11n", req_intf, cmd_sta_set_11n);
16311 /* TODO: sta_set_rifs_test */
16312 sigma_dut_reg_cmd("sta_set_wireless", req_intf, cmd_sta_set_wireless);
16313 sigma_dut_reg_cmd("sta_send_addba", req_intf, cmd_sta_send_addba);
16314 /* TODO: sta_send_coexist_mgmt */
16315 sigma_dut_reg_cmd("sta_disconnect", req_intf, cmd_sta_disconnect);
16316 sigma_dut_reg_cmd("sta_reassoc", req_intf, cmd_sta_reassoc);
16317 sigma_dut_reg_cmd("sta_reassociate", req_intf, cmd_sta_reassoc);
16318 sigma_dut_reg_cmd("sta_reset_default", req_intf,
16319 cmd_sta_reset_default);
16320 sigma_dut_reg_cmd("sta_send_frame", req_intf, cmd_sta_send_frame);
16321 sigma_dut_reg_cmd("sta_set_macaddr", req_intf, cmd_sta_set_macaddr);
16322 sigma_dut_reg_cmd("sta_set_rfeature", req_intf, cmd_sta_set_rfeature);
16323 sigma_dut_reg_cmd("sta_set_radio", req_intf, cmd_sta_set_radio);
16324 sigma_dut_reg_cmd("sta_set_pwrsave", req_intf, cmd_sta_set_pwrsave);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020016325 sigma_dut_reg_cmd("sta_set_power_save", req_intf, cmd_sta_set_pwrsave);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016326 sigma_dut_reg_cmd("sta_bssid_pool", req_intf, cmd_sta_bssid_pool);
16327 sigma_dut_reg_cmd("sta_reset_parm", req_intf, cmd_sta_reset_parm);
16328 sigma_dut_reg_cmd("sta_get_key", req_intf, cmd_sta_get_key);
16329 sigma_dut_reg_cmd("sta_hs2_associate", req_intf,
16330 cmd_sta_hs2_associate);
Jouni Malinenb639f1c2018-09-13 02:39:46 +030016331 sigma_dut_reg_cmd("sta_hs2_venue_info", req_intf,
16332 cmd_sta_hs2_venue_info);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016333 sigma_dut_reg_cmd("sta_add_credential", req_intf,
16334 cmd_sta_add_credential);
16335 sigma_dut_reg_cmd("sta_scan", req_intf, cmd_sta_scan);
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020016336 sigma_dut_reg_cmd("sta_scan_bss", req_intf, cmd_sta_scan_bss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016337 sigma_dut_reg_cmd("sta_set_systime", NULL, cmd_sta_set_systime);
16338 sigma_dut_reg_cmd("sta_osu", req_intf, cmd_sta_osu);
16339 sigma_dut_reg_cmd("sta_policy_update", req_intf, cmd_sta_policy_update);
16340 sigma_dut_reg_cmd("sta_er_config", NULL, cmd_sta_er_config);
16341 sigma_dut_reg_cmd("sta_wps_connect_pw_token", req_intf,
16342 cmd_sta_wps_connect_pw_token);
Jouni Malinen82905202018-04-29 17:20:10 +030016343 sigma_dut_reg_cmd("sta_exec_action", NULL, cmd_sta_exec_action);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016344 sigma_dut_reg_cmd("sta_get_events", req_intf, cmd_sta_get_events);
16345 sigma_dut_reg_cmd("sta_get_parameter", req_intf, cmd_sta_get_parameter);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020016346 sigma_dut_reg_cmd("start_wps_registration", NULL,
vamsi krishna9b144002017-09-20 13:28:13 +053016347 cmd_start_wps_registration);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016348}